From 8a8bdcac23bd77a4b2cabe0acbf45ae7fdff8a30 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 15 Oct 2024 10:22:55 -0300 Subject: [PATCH] rename createOrLoad to newOrExisting --- plugins/store/api-iife.js | 2 +- plugins/store/build.rs | 2 +- plugins/store/guest-js/index.ts | 16 +++--- .../commands/create_or_load.toml | 13 ----- .../commands/new_or_existing.toml | 13 +++++ .../permissions/autogenerated/reference.md | 54 +++++++++---------- plugins/store/permissions/default.toml | 2 +- plugins/store/permissions/schemas/schema.json | 20 +++---- plugins/store/src/lib.rs | 12 ++--- plugins/store/src/store.rs | 20 +++---- 10 files changed, 77 insertions(+), 77 deletions(-) delete mode 100644 plugins/store/permissions/autogenerated/commands/create_or_load.toml create mode 100644 plugins/store/permissions/autogenerated/commands/new_or_existing.toml diff --git a/plugins/store/api-iife.js b/plugins/store/api-iife.js index 66e5ffd1..01799640 100644 --- a/plugins/store/api-iife.js +++ b/plugins/store/api-iife.js @@ -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__})} diff --git a/plugins/store/build.rs b/plugins/store/build.rs index 174ee428..9024df23 100644 --- a/plugins/store/build.rs +++ b/plugins/store/build.rs @@ -4,7 +4,7 @@ const COMMANDS: &[&str] = &[ "create_store", - "create_or_load", + "new_or_existing", "get_store", "close_store", "set", diff --git a/plugins/store/guest-js/index.ts b/plugins/store/guest-js/index.ts index ae14ddc9..6a3227da 100644 --- a/plugins/store/guest-js/index.ts +++ b/plugins/store/guest-js/index.ts @@ -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 { - 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 { 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 { - const rid = await invoke('plugin:store|create_or_load', { + const rid = await invoke('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'); * } * ``` * diff --git a/plugins/store/permissions/autogenerated/commands/create_or_load.toml b/plugins/store/permissions/autogenerated/commands/create_or_load.toml deleted file mode 100644 index 8e821d7b..00000000 --- a/plugins/store/permissions/autogenerated/commands/create_or_load.toml +++ /dev/null @@ -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"] diff --git a/plugins/store/permissions/autogenerated/commands/new_or_existing.toml b/plugins/store/permissions/autogenerated/commands/new_or_existing.toml new file mode 100644 index 00000000..c430ecfb --- /dev/null +++ b/plugins/store/permissions/autogenerated/commands/new_or_existing.toml @@ -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"] diff --git a/plugins/store/permissions/autogenerated/reference.md b/plugins/store/permissions/autogenerated/reference.md index 51e5604f..804a77a0 100644 --- a/plugins/store/permissions/autogenerated/reference.md +++ b/plugins/store/permissions/autogenerated/reference.md @@ -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. -`store:allow-create-or-load` - - - - -Enables the create_or_load command without any pre-configured scope. - - - - - - - -`store:deny-create-or-load` - - - - -Denies the create_or_load command without any pre-configured scope. - - - - - - - `store:allow-create-store` @@ -350,6 +324,32 @@ Denies the load command without any pre-configured scope. +`store:allow-new-or-existing` + + + + +Enables the new_or_existing command without any pre-configured scope. + + + + + + + +`store:deny-new-or-existing` + + + + +Denies the new_or_existing command without any pre-configured scope. + + + + + + + `store:allow-reset` diff --git a/plugins/store/permissions/default.toml b/plugins/store/permissions/default.toml index 48b3a090..6aa688ae 100644 --- a/plugins/store/permissions/default.toml +++ b/plugins/store/permissions/default.toml @@ -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", diff --git a/plugins/store/permissions/schemas/schema.json b/plugins/store/permissions/schemas/schema.json index 89eeb0c0..01e465db 100644 --- a/plugins/store/permissions/schemas/schema.json +++ b/plugins/store/permissions/schemas/schema.json @@ -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", diff --git a/plugins/store/src/lib.rs b/plugins/store/src/lib.rs index 9251fa00..ae71b3c9 100644 --- a/plugins/store/src/lib.rs +++ b/plugins/store/src/lib.rs @@ -117,7 +117,7 @@ async fn create_store( } #[tauri::command] -async fn create_or_load( +async fn new_or_existing( app: AppHandle, store_state: State<'_, StoreState>, path: PathBuf, @@ -133,7 +133,7 @@ async fn create_or_load( 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 { /// 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 { impl> StoreExt for T { fn store(&self, path: impl AsRef) -> Result>> { 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) -> Result>> { @@ -451,7 +451,7 @@ impl Builder { /// 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 Builder { plugin::Builder::new("store") .invoke_handler(tauri::generate_handler![ create_store, - create_or_load, + new_or_existing, get_store, close_store, set, diff --git a/plugins/store/src/store.rs b/plugins/store/src/store.rs index 8091f132..42240cec 100644 --- a/plugins/store/src/store.rs +++ b/plugins/store/src/store.rs @@ -79,7 +79,7 @@ impl StoreBuilder { /// /// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin") /// .defaults(defaults) - /// .create_or_load()?; + /// .new_or_existing()?; /// Ok(()) /// }); /// ``` @@ -97,7 +97,7 @@ impl StoreBuilder { /// .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 StoreBuilder { /// .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 StoreBuilder { /// .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 StoreBuilder { /// .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 StoreBuilder { /// 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 StoreBuilder { /// 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>> { - let (store, _) = self.create_or_load_inner()?; + pub fn new_or_existing(self) -> crate::Result>> { + let (store, _) = self.new_or_existing_inner()?; Ok(store) } - pub(crate) fn create_or_load_inner(self) -> crate::Result<(Arc>, ResourceId)> { + pub(crate) fn new_or_existing_inner(self) -> crate::Result<(Arc>, ResourceId)> { { let state = self.app.state::(); let stores = state.stores.lock().unwrap();