rename createOrLoad to newOrExisting

pull/1860/head
Lucas Nogueira 8 months ago
parent 028d6661ca
commit 8a8bdcac23
No known key found for this signature in database
GPG Key ID: 7C32FCA95C8C95D7

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_PLUGIN_STORE__=function(t){"use strict";var e,a;function r(t,e=!1){return window.__TAURI_INTERNALS__.transformCallback(t,e)}async function s(t,e={},a){return window.__TAURI_INTERNALS__.invoke(t,e,a)}"function"==typeof SuppressedError&&SuppressedError;class i{get rid(){return function(t,e,a,r){if("a"===a&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===a?r:"a"===a?r.call(t):r?r.value:e.get(t)}(this,e,"f")}constructor(t){e.set(this,void 0),function(t,e,a,r,s){if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");e.set(t,a)}(this,e,t)}async close(){return s("plugin:resources|close",{rid:this.rid})}}async function n(t,e,a){const i={kind:"Any"};return s("plugin:event|listen",{event:t,target:i,handler:r(e)}).then((e=>async()=>async function(t,e){await s("plugin:event|unlisten",{event:t,eventId:e})}(t,e)))}async function o(t,e){return await c.createOrLoad(t,e)}e=new WeakMap,function(t){t.WINDOW_RESIZED="tauri://resize",t.WINDOW_MOVED="tauri://move",t.WINDOW_CLOSE_REQUESTED="tauri://close-requested",t.WINDOW_DESTROYED="tauri://destroyed",t.WINDOW_FOCUS="tauri://focus",t.WINDOW_BLUR="tauri://blur",t.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",t.WINDOW_THEME_CHANGED="tauri://theme-changed",t.WINDOW_CREATED="tauri://window-created",t.WEBVIEW_CREATED="tauri://webview-created",t.DRAG_ENTER="tauri://drag-enter",t.DRAG_OVER="tauri://drag-over",t.DRAG_DROP="tauri://drag-drop",t.DRAG_LEAVE="tauri://drag-leave"}(a||(a={}));class c extends i{constructor(t){super(t)}static async create(t,e){const a=await s("plugin:store|create_store",{path:t,...e});return new c(a)}static async createOrLoad(t,e){const a=await s("plugin:store|create_or_load",{path:t,...e});return new c(a)}static async get(t){return await s("plugin:store|get_store",{path:t}).then((t=>t?new c(t):null))}async set(t,e){await s("plugin:store|set",{rid:this.rid,key:t,value:e})}async get(t){const[e,a]=await s("plugin:store|get",{rid:this.rid,key:t});return a?e:void 0}async has(t){return await s("plugin:store|has",{rid:this.rid,key:t})}async delete(t){return await s("plugin:store|delete",{rid:this.rid,key:t})}async clear(){await s("plugin:store|clear",{rid:this.rid})}async reset(){await s("plugin:store|reset",{rid:this.rid})}async keys(){return await s("plugin:store|keys",{rid:this.rid})}async values(){return await s("plugin:store|values",{rid:this.rid})}async entries(){return await s("plugin:store|entries",{rid:this.rid})}async length(){return await s("plugin:store|length",{rid:this.rid})}async load(){await s("plugin:store|load",{rid:this.rid})}async save(){await s("plugin:store|save",{rid:this.rid})}async onKeyChange(t,e){return await n("store://change",(a=>{a.payload.resourceId===this.rid&&a.payload.key===t&&e(a.payload.exists?a.payload.value:void 0)}))}async onChange(t){return await n("store://change",(e=>{e.payload.resourceId===this.rid&&t(e.payload.key,e.payload.exists?e.payload.value:void 0)}))}async close(){await s("plugin:store|close_store",{rid:this.rid})}}return t.LazyStore=class{get store(){return this._store||(this._store=o(this.path,this.options)),this._store}constructor(t,e){this.path=t,this.options=e}async init(){await this.store}async set(t,e){return(await this.store).set(t,e)}async get(t){return(await this.store).get(t)}async has(t){return(await this.store).has(t)}async delete(t){return(await this.store).delete(t)}async clear(){await(await this.store).clear()}async reset(){await(await this.store).reset()}async keys(){return(await this.store).keys()}async values(){return(await this.store).values()}async entries(){return(await this.store).entries()}async length(){return(await this.store).length()}async load(){await(await this.store).load()}async save(){await(await this.store).save()}async onKeyChange(t,e){return(await this.store).onKeyChange(t,e)}async onChange(t){return(await this.store).onChange(t)}async close(){this._store&&await(await this._store).close()}},t.Store=c,t.create=async function(t,e){return await c.create(t,e)},t.createOrLoad=o,t.getStore=async function(t){return await c.get(t)},t}({});Object.defineProperty(window.__TAURI__,"store",{value:__TAURI_PLUGIN_STORE__})}
if("__TAURI__"in window){var __TAURI_PLUGIN_STORE__=function(t){"use strict";var e,a;function r(t,e=!1){return window.__TAURI_INTERNALS__.transformCallback(t,e)}async function s(t,e={},a){return window.__TAURI_INTERNALS__.invoke(t,e,a)}"function"==typeof SuppressedError&&SuppressedError;class i{get rid(){return function(t,e,a,r){if("a"===a&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===a?r:"a"===a?r.call(t):r?r.value:e.get(t)}(this,e,"f")}constructor(t){e.set(this,void 0),function(t,e,a,r,s){if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");e.set(t,a)}(this,e,t)}async close(){return s("plugin:resources|close",{rid:this.rid})}}async function n(t,e,a){const i={kind:"Any"};return s("plugin:event|listen",{event:t,target:i,handler:r(e)}).then((e=>async()=>async function(t,e){await s("plugin:event|unlisten",{event:t,eventId:e})}(t,e)))}async function o(t,e){return await c.newOrExisting(t,e)}e=new WeakMap,function(t){t.WINDOW_RESIZED="tauri://resize",t.WINDOW_MOVED="tauri://move",t.WINDOW_CLOSE_REQUESTED="tauri://close-requested",t.WINDOW_DESTROYED="tauri://destroyed",t.WINDOW_FOCUS="tauri://focus",t.WINDOW_BLUR="tauri://blur",t.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",t.WINDOW_THEME_CHANGED="tauri://theme-changed",t.WINDOW_CREATED="tauri://window-created",t.WEBVIEW_CREATED="tauri://webview-created",t.DRAG_ENTER="tauri://drag-enter",t.DRAG_OVER="tauri://drag-over",t.DRAG_DROP="tauri://drag-drop",t.DRAG_LEAVE="tauri://drag-leave"}(a||(a={}));class c extends i{constructor(t){super(t)}static async create(t,e){const a=await s("plugin:store|create_store",{path:t,...e});return new c(a)}static async newOrExisting(t,e){const a=await s("plugin:store|new_or_existing",{path:t,...e});return new c(a)}static async get(t){return await s("plugin:store|get_store",{path:t}).then((t=>t?new c(t):null))}async set(t,e){await s("plugin:store|set",{rid:this.rid,key:t,value:e})}async get(t){const[e,a]=await s("plugin:store|get",{rid:this.rid,key:t});return a?e:void 0}async has(t){return await s("plugin:store|has",{rid:this.rid,key:t})}async delete(t){return await s("plugin:store|delete",{rid:this.rid,key:t})}async clear(){await s("plugin:store|clear",{rid:this.rid})}async reset(){await s("plugin:store|reset",{rid:this.rid})}async keys(){return await s("plugin:store|keys",{rid:this.rid})}async values(){return await s("plugin:store|values",{rid:this.rid})}async entries(){return await s("plugin:store|entries",{rid:this.rid})}async length(){return await s("plugin:store|length",{rid:this.rid})}async load(){await s("plugin:store|load",{rid:this.rid})}async save(){await s("plugin:store|save",{rid:this.rid})}async onKeyChange(t,e){return await n("store://change",(a=>{a.payload.resourceId===this.rid&&a.payload.key===t&&e(a.payload.exists?a.payload.value:void 0)}))}async onChange(t){return await n("store://change",(e=>{e.payload.resourceId===this.rid&&t(e.payload.key,e.payload.exists?e.payload.value:void 0)}))}async close(){await s("plugin:store|close_store",{rid:this.rid})}}return t.LazyStore=class{get store(){return this._store||(this._store=o(this.path,this.options)),this._store}constructor(t,e){this.path=t,this.options=e}async init(){await this.store}async set(t,e){return(await this.store).set(t,e)}async get(t){return(await this.store).get(t)}async has(t){return(await this.store).has(t)}async delete(t){return(await this.store).delete(t)}async clear(){await(await this.store).clear()}async reset(){await(await this.store).reset()}async keys(){return(await this.store).keys()}async values(){return(await this.store).values()}async entries(){return(await this.store).entries()}async length(){return(await this.store).length()}async load(){await(await this.store).load()}async save(){await(await this.store).save()}async onKeyChange(t,e){return(await this.store).onKeyChange(t,e)}async onChange(t){return(await this.store).onChange(t)}async close(){this._store&&await(await this._store).close()}},t.Store=c,t.create=async function(t,e){return await c.create(t,e)},t.getStore=async function(t){return await c.get(t)},t.newOrExisting=o,t}({});Object.defineProperty(window.__TAURI__,"store",{value:__TAURI_PLUGIN_STORE__})}

@ -4,7 +4,7 @@
const COMMANDS: &[&str] = &[
"create_store",
"create_or_load",
"new_or_existing",
"get_store",
"close_store",
"set",

@ -55,11 +55,11 @@ export async function create(
* @param path Path to save the store in `app_data_dir`
* @param options Store configuration options
*/
export async function createOrLoad(
export async function newOrExisting(
path: string,
options?: StoreOptions
): Promise<Store> {
return await Store.createOrLoad(path, options)
return await Store.newOrExisting(path, options)
}
/**
@ -77,7 +77,7 @@ export class LazyStore implements IStore {
private get store(): Promise<Store> {
if (!this._store) {
this._store = createOrLoad(this.path, this.options)
this._store = newOrExisting(this.path, this.options)
}
return this._store
}
@ -211,18 +211,18 @@ export class Store extends Resource implements IStore {
* import { Store } from '@tauri-apps/api/store';
* let store = await Store.get('store.json');
* if (!store) {
* store = await Store.createOrLoad('store.json');
* store = await Store.newOrExisting('store.json');
* }
* ```
*
* @param path Path to save the store in `app_data_dir`
* @param options Store configuration options
*/
static async createOrLoad(
static async newOrExisting(
path: string,
options?: StoreOptions
): Promise<Store> {
const rid = await invoke<number>('plugin:store|create_or_load', {
const rid = await invoke<number>('plugin:store|new_or_existing', {
path,
...options
})
@ -233,14 +233,14 @@ export class Store extends Resource implements IStore {
* Gets an already loaded store.
*
* If the store is not loaded, returns `null`. In this case,
* you must either {@link Store.create | create} it or {@link Store.createOrLoad createOrLoad} it.
* you must either {@link Store.create | create} it or {@link Store.newOrExisting newOrExisting} it.
*
* @example
* ```typescript
* import { Store } from '@tauri-apps/api/store';
* let store = await Store.get('store.json');
* if (!store) {
* store = await Store.createOrLoad('store.json');
* store = await Store.newOrExisting('store.json');
* }
* ```
*

@ -1,13 +0,0 @@
# Automatically generated - DO NOT EDIT!
"$schema" = "../../schemas/schema.json"
[[permission]]
identifier = "allow-create-or-load"
description = "Enables the create_or_load command without any pre-configured scope."
commands.allow = ["create_or_load"]
[[permission]]
identifier = "deny-create-or-load"
description = "Denies the create_or_load command without any pre-configured scope."
commands.deny = ["create_or_load"]

@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!
"$schema" = "../../schemas/schema.json"
[[permission]]
identifier = "allow-new-or-existing"
description = "Enables the new_or_existing command without any pre-configured scope."
commands.allow = ["new_or_existing"]
[[permission]]
identifier = "deny-new-or-existing"
description = "Denies the new_or_existing command without any pre-configured scope."
commands.deny = ["new_or_existing"]

@ -10,7 +10,7 @@ All operations are enabled by default.
- `allow-create-store`
- `allow-create-or-load`
- `allow-new-or-existing`
- `allow-get-store`
- `allow-close-store`
- `allow-set`
@ -90,32 +90,6 @@ Denies the close_store command without any pre-configured scope.
<tr>
<td>
`store:allow-create-or-load`
</td>
<td>
Enables the create_or_load command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`store:deny-create-or-load`
</td>
<td>
Denies the create_or_load command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`store:allow-create-store`
</td>
@ -350,6 +324,32 @@ Denies the load command without any pre-configured scope.
<tr>
<td>
`store:allow-new-or-existing`
</td>
<td>
Enables the new_or_existing command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`store:deny-new-or-existing`
</td>
<td>
Denies the new_or_existing command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`store:allow-reset`
</td>

@ -12,7 +12,7 @@ All operations are enabled by default.
"""
permissions = [
"allow-create-store",
"allow-create-or-load",
"allow-new-or-existing",
"allow-get-store",
"allow-close-store",
"allow-set",

@ -314,16 +314,6 @@
"type": "string",
"const": "deny-close-store"
},
{
"description": "Enables the create_or_load command without any pre-configured scope.",
"type": "string",
"const": "allow-create-or-load"
},
{
"description": "Denies the create_or_load command without any pre-configured scope.",
"type": "string",
"const": "deny-create-or-load"
},
{
"description": "Enables the create_store command without any pre-configured scope.",
"type": "string",
@ -414,6 +404,16 @@
"type": "string",
"const": "deny-load"
},
{
"description": "Enables the new_or_existing command without any pre-configured scope.",
"type": "string",
"const": "allow-new-or-existing"
},
{
"description": "Denies the new_or_existing command without any pre-configured scope.",
"type": "string",
"const": "deny-new-or-existing"
},
{
"description": "Enables the reset command without any pre-configured scope.",
"type": "string",

@ -117,7 +117,7 @@ async fn create_store<R: Runtime>(
}
#[tauri::command]
async fn create_or_load<R: Runtime>(
async fn new_or_existing<R: Runtime>(
app: AppHandle<R>,
store_state: State<'_, StoreState>,
path: PathBuf,
@ -133,7 +133,7 @@ async fn create_or_load<R: Runtime>(
serialize_fn_name,
deserialize_fn_name,
)?;
let (_, rid) = builder.create_or_load_inner()?;
let (_, rid) = builder.new_or_existing_inner()?;
Ok(rid)
}
@ -291,7 +291,7 @@ pub trait StoreExt<R: Runtime> {
/// tauri::Builder::default()
/// .plugin(tauri_plugin_store::Builder::default().build())
/// .setup(|app| {
/// let store = app.store_builder("users.json").auto_save(Duration::from_secs(1)).create_or_load()?;
/// let store = app.store_builder("users.json").auto_save(Duration::from_secs(1)).new_or_existing()?;
/// Ok(())
/// });
/// ```
@ -328,7 +328,7 @@ pub trait StoreExt<R: Runtime> {
impl<R: Runtime, T: Manager<R>> StoreExt<R> for T {
fn store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
let path = path.as_ref();
StoreBuilder::new(self.app_handle(), path).create_or_load()
StoreBuilder::new(self.app_handle(), path).new_or_existing()
}
fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
@ -451,7 +451,7 @@ impl<R: Runtime> Builder<R> {
/// tauri::Builder::default()
/// .plugin(tauri_plugin_store::Builder::default().build())
/// .setup(|app| {
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin").create_or_load()?;
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin").new_or_existing()?;
/// Ok(())
/// });
/// ```
@ -459,7 +459,7 @@ impl<R: Runtime> Builder<R> {
plugin::Builder::new("store")
.invoke_handler(tauri::generate_handler![
create_store,
create_or_load,
new_or_existing,
get_store,
close_store,
set,

@ -79,7 +79,7 @@ impl<R: Runtime> StoreBuilder<R> {
///
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin")
/// .defaults(defaults)
/// .create_or_load()?;
/// .new_or_existing()?;
/// Ok(())
/// });
/// ```
@ -97,7 +97,7 @@ impl<R: Runtime> StoreBuilder<R> {
/// .setup(|app| {
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin")
/// .default("foo".to_string(), "bar")
/// .create_or_load()?;
/// .new_or_existing()?;
/// Ok(())
/// });
/// ```
@ -119,7 +119,7 @@ impl<R: Runtime> StoreBuilder<R> {
/// .setup(|app| {
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
/// .serialize(|cache| serde_json::to_vec(&cache).map_err(Into::into))
/// .create_or_load()?;
/// .new_or_existing()?;
/// Ok(())
/// });
/// ```
@ -137,7 +137,7 @@ impl<R: Runtime> StoreBuilder<R> {
/// .setup(|app| {
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
/// .deserialize(|bytes| serde_json::from_slice(&bytes).map_err(Into::into))
/// .create_or_load()?;
/// .new_or_existing()?;
/// Ok(())
/// });
/// ```
@ -155,7 +155,7 @@ impl<R: Runtime> StoreBuilder<R> {
/// .setup(|app| {
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
/// .auto_save(std::time::Duration::from_millis(100))
/// .create_or_load()?;
/// .new_or_existing()?;
/// Ok(())
/// });
/// ```
@ -217,7 +217,7 @@ impl<R: Runtime> StoreBuilder<R> {
/// tauri::Builder::default()
/// .plugin(tauri_plugin_store::Builder::default().build())
/// .setup(|app| {
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").create_or_load()?;
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").new_or_existing()?;
/// Ok(())
/// });
/// ```
@ -241,16 +241,16 @@ impl<R: Runtime> StoreBuilder<R> {
/// tauri::Builder::default()
/// .plugin(tauri_plugin_store::Builder::default().build())
/// .setup(|app| {
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").create_or_load();
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").new_or_existing();
/// Ok(())
/// });
/// ```
pub fn create_or_load(self) -> crate::Result<Arc<Store<R>>> {
let (store, _) = self.create_or_load_inner()?;
pub fn new_or_existing(self) -> crate::Result<Arc<Store<R>>> {
let (store, _) = self.new_or_existing_inner()?;
Ok(store)
}
pub(crate) fn create_or_load_inner(self) -> crate::Result<(Arc<Store<R>>, ResourceId)> {
pub(crate) fn new_or_existing_inner(self) -> crate::Result<(Arc<Store<R>>, ResourceId)> {
{
let state = self.app.state::<StoreState>();
let stores = state.stores.lock().unwrap();

Loading…
Cancel
Save