Skip to content

Commit 8a8bdca

Browse files
committed
rename createOrLoad to newOrExisting
1 parent 028d666 commit 8a8bdca

File tree

10 files changed

+77
-77
lines changed

10 files changed

+77
-77
lines changed

plugins/store/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/store/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
const COMMANDS: &[&str] = &[
66
"create_store",
7-
"create_or_load",
7+
"new_or_existing",
88
"get_store",
99
"close_store",
1010
"set",

plugins/store/guest-js/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ export async function create(
5555
* @param path Path to save the store in `app_data_dir`
5656
* @param options Store configuration options
5757
*/
58-
export async function createOrLoad(
58+
export async function newOrExisting(
5959
path: string,
6060
options?: StoreOptions
6161
): Promise<Store> {
62-
return await Store.createOrLoad(path, options)
62+
return await Store.newOrExisting(path, options)
6363
}
6464

6565
/**
@@ -77,7 +77,7 @@ export class LazyStore implements IStore {
7777

7878
private get store(): Promise<Store> {
7979
if (!this._store) {
80-
this._store = createOrLoad(this.path, this.options)
80+
this._store = newOrExisting(this.path, this.options)
8181
}
8282
return this._store
8383
}
@@ -211,18 +211,18 @@ export class Store extends Resource implements IStore {
211211
* import { Store } from '@tauri-apps/api/store';
212212
* let store = await Store.get('store.json');
213213
* if (!store) {
214-
* store = await Store.createOrLoad('store.json');
214+
* store = await Store.newOrExisting('store.json');
215215
* }
216216
* ```
217217
*
218218
* @param path Path to save the store in `app_data_dir`
219219
* @param options Store configuration options
220220
*/
221-
static async createOrLoad(
221+
static async newOrExisting(
222222
path: string,
223223
options?: StoreOptions
224224
): Promise<Store> {
225-
const rid = await invoke<number>('plugin:store|create_or_load', {
225+
const rid = await invoke<number>('plugin:store|new_or_existing', {
226226
path,
227227
...options
228228
})
@@ -233,14 +233,14 @@ export class Store extends Resource implements IStore {
233233
* Gets an already loaded store.
234234
*
235235
* If the store is not loaded, returns `null`. In this case,
236-
* you must either {@link Store.create | create} it or {@link Store.createOrLoad createOrLoad} it.
236+
* you must either {@link Store.create | create} it or {@link Store.newOrExisting newOrExisting} it.
237237
*
238238
* @example
239239
* ```typescript
240240
* import { Store } from '@tauri-apps/api/store';
241241
* let store = await Store.get('store.json');
242242
* if (!store) {
243-
* store = await Store.createOrLoad('store.json');
243+
* store = await Store.newOrExisting('store.json');
244244
* }
245245
* ```
246246
*

plugins/store/permissions/autogenerated/commands/create_or_load.toml

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Automatically generated - DO NOT EDIT!
2+
3+
"$schema" = "../../schemas/schema.json"
4+
5+
[[permission]]
6+
identifier = "allow-new-or-existing"
7+
description = "Enables the new_or_existing command without any pre-configured scope."
8+
commands.allow = ["new_or_existing"]
9+
10+
[[permission]]
11+
identifier = "deny-new-or-existing"
12+
description = "Denies the new_or_existing command without any pre-configured scope."
13+
commands.deny = ["new_or_existing"]

plugins/store/permissions/autogenerated/reference.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ All operations are enabled by default.
1010

1111

1212
- `allow-create-store`
13-
- `allow-create-or-load`
13+
- `allow-new-or-existing`
1414
- `allow-get-store`
1515
- `allow-close-store`
1616
- `allow-set`
@@ -90,32 +90,6 @@ Denies the close_store command without any pre-configured scope.
9090
<tr>
9191
<td>
9292

93-
`store:allow-create-or-load`
94-
95-
</td>
96-
<td>
97-
98-
Enables the create_or_load command without any pre-configured scope.
99-
100-
</td>
101-
</tr>
102-
103-
<tr>
104-
<td>
105-
106-
`store:deny-create-or-load`
107-
108-
</td>
109-
<td>
110-
111-
Denies the create_or_load command without any pre-configured scope.
112-
113-
</td>
114-
</tr>
115-
116-
<tr>
117-
<td>
118-
11993
`store:allow-create-store`
12094

12195
</td>
@@ -350,6 +324,32 @@ Denies the load command without any pre-configured scope.
350324
<tr>
351325
<td>
352326

327+
`store:allow-new-or-existing`
328+
329+
</td>
330+
<td>
331+
332+
Enables the new_or_existing command without any pre-configured scope.
333+
334+
</td>
335+
</tr>
336+
337+
<tr>
338+
<td>
339+
340+
`store:deny-new-or-existing`
341+
342+
</td>
343+
<td>
344+
345+
Denies the new_or_existing command without any pre-configured scope.
346+
347+
</td>
348+
</tr>
349+
350+
<tr>
351+
<td>
352+
353353
`store:allow-reset`
354354

355355
</td>

plugins/store/permissions/default.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ All operations are enabled by default.
1212
"""
1313
permissions = [
1414
"allow-create-store",
15-
"allow-create-or-load",
15+
"allow-new-or-existing",
1616
"allow-get-store",
1717
"allow-close-store",
1818
"allow-set",

plugins/store/permissions/schemas/schema.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,6 @@
314314
"type": "string",
315315
"const": "deny-close-store"
316316
},
317-
{
318-
"description": "Enables the create_or_load command without any pre-configured scope.",
319-
"type": "string",
320-
"const": "allow-create-or-load"
321-
},
322-
{
323-
"description": "Denies the create_or_load command without any pre-configured scope.",
324-
"type": "string",
325-
"const": "deny-create-or-load"
326-
},
327317
{
328318
"description": "Enables the create_store command without any pre-configured scope.",
329319
"type": "string",
@@ -414,6 +404,16 @@
414404
"type": "string",
415405
"const": "deny-load"
416406
},
407+
{
408+
"description": "Enables the new_or_existing command without any pre-configured scope.",
409+
"type": "string",
410+
"const": "allow-new-or-existing"
411+
},
412+
{
413+
"description": "Denies the new_or_existing command without any pre-configured scope.",
414+
"type": "string",
415+
"const": "deny-new-or-existing"
416+
},
417417
{
418418
"description": "Enables the reset command without any pre-configured scope.",
419419
"type": "string",

plugins/store/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async fn create_store<R: Runtime>(
117117
}
118118

119119
#[tauri::command]
120-
async fn create_or_load<R: Runtime>(
120+
async fn new_or_existing<R: Runtime>(
121121
app: AppHandle<R>,
122122
store_state: State<'_, StoreState>,
123123
path: PathBuf,
@@ -133,7 +133,7 @@ async fn create_or_load<R: Runtime>(
133133
serialize_fn_name,
134134
deserialize_fn_name,
135135
)?;
136-
let (_, rid) = builder.create_or_load_inner()?;
136+
let (_, rid) = builder.new_or_existing_inner()?;
137137
Ok(rid)
138138
}
139139

@@ -291,7 +291,7 @@ pub trait StoreExt<R: Runtime> {
291291
/// tauri::Builder::default()
292292
/// .plugin(tauri_plugin_store::Builder::default().build())
293293
/// .setup(|app| {
294-
/// let store = app.store_builder("users.json").auto_save(Duration::from_secs(1)).create_or_load()?;
294+
/// let store = app.store_builder("users.json").auto_save(Duration::from_secs(1)).new_or_existing()?;
295295
/// Ok(())
296296
/// });
297297
/// ```
@@ -328,7 +328,7 @@ pub trait StoreExt<R: Runtime> {
328328
impl<R: Runtime, T: Manager<R>> StoreExt<R> for T {
329329
fn store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
330330
let path = path.as_ref();
331-
StoreBuilder::new(self.app_handle(), path).create_or_load()
331+
StoreBuilder::new(self.app_handle(), path).new_or_existing()
332332
}
333333

334334
fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
@@ -451,15 +451,15 @@ impl<R: Runtime> Builder<R> {
451451
/// tauri::Builder::default()
452452
/// .plugin(tauri_plugin_store::Builder::default().build())
453453
/// .setup(|app| {
454-
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin").create_or_load()?;
454+
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin").new_or_existing()?;
455455
/// Ok(())
456456
/// });
457457
/// ```
458458
pub fn build(self) -> TauriPlugin<R> {
459459
plugin::Builder::new("store")
460460
.invoke_handler(tauri::generate_handler![
461461
create_store,
462-
create_or_load,
462+
new_or_existing,
463463
get_store,
464464
close_store,
465465
set,

plugins/store/src/store.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<R: Runtime> StoreBuilder<R> {
7979
///
8080
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin")
8181
/// .defaults(defaults)
82-
/// .create_or_load()?;
82+
/// .new_or_existing()?;
8383
/// Ok(())
8484
/// });
8585
/// ```
@@ -97,7 +97,7 @@ impl<R: Runtime> StoreBuilder<R> {
9797
/// .setup(|app| {
9898
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin")
9999
/// .default("foo".to_string(), "bar")
100-
/// .create_or_load()?;
100+
/// .new_or_existing()?;
101101
/// Ok(())
102102
/// });
103103
/// ```
@@ -119,7 +119,7 @@ impl<R: Runtime> StoreBuilder<R> {
119119
/// .setup(|app| {
120120
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
121121
/// .serialize(|cache| serde_json::to_vec(&cache).map_err(Into::into))
122-
/// .create_or_load()?;
122+
/// .new_or_existing()?;
123123
/// Ok(())
124124
/// });
125125
/// ```
@@ -137,7 +137,7 @@ impl<R: Runtime> StoreBuilder<R> {
137137
/// .setup(|app| {
138138
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
139139
/// .deserialize(|bytes| serde_json::from_slice(&bytes).map_err(Into::into))
140-
/// .create_or_load()?;
140+
/// .new_or_existing()?;
141141
/// Ok(())
142142
/// });
143143
/// ```
@@ -155,7 +155,7 @@ impl<R: Runtime> StoreBuilder<R> {
155155
/// .setup(|app| {
156156
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
157157
/// .auto_save(std::time::Duration::from_millis(100))
158-
/// .create_or_load()?;
158+
/// .new_or_existing()?;
159159
/// Ok(())
160160
/// });
161161
/// ```
@@ -217,7 +217,7 @@ impl<R: Runtime> StoreBuilder<R> {
217217
/// tauri::Builder::default()
218218
/// .plugin(tauri_plugin_store::Builder::default().build())
219219
/// .setup(|app| {
220-
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").create_or_load()?;
220+
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").new_or_existing()?;
221221
/// Ok(())
222222
/// });
223223
/// ```
@@ -241,16 +241,16 @@ impl<R: Runtime> StoreBuilder<R> {
241241
/// tauri::Builder::default()
242242
/// .plugin(tauri_plugin_store::Builder::default().build())
243243
/// .setup(|app| {
244-
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").create_or_load();
244+
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").new_or_existing();
245245
/// Ok(())
246246
/// });
247247
/// ```
248-
pub fn create_or_load(self) -> crate::Result<Arc<Store<R>>> {
249-
let (store, _) = self.create_or_load_inner()?;
248+
pub fn new_or_existing(self) -> crate::Result<Arc<Store<R>>> {
249+
let (store, _) = self.new_or_existing_inner()?;
250250
Ok(store)
251251
}
252252

253-
pub(crate) fn create_or_load_inner(self) -> crate::Result<(Arc<Store<R>>, ResourceId)> {
253+
pub(crate) fn new_or_existing_inner(self) -> crate::Result<(Arc<Store<R>>, ResourceId)> {
254254
{
255255
let state = self.app.state::<StoreState>();
256256
let stores = state.stores.lock().unwrap();

0 commit comments

Comments
 (0)