@peers-app/peers-sdk 0.27.2 → 0.27.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -131,11 +131,13 @@ interface IPersistentVarOptionsWithoutDefault<T> extends IPersistentVarOptionsBa
|
|
|
131
131
|
* A persistent variable that is stored only on this device, in the user's personal db
|
|
132
132
|
*/
|
|
133
133
|
export declare function deviceVar<T = string>(name: string, opts: Omit<IPersistentVarOptionsWithDefault<T>, "scope" | "dataContext">): PersistentVar<T>;
|
|
134
|
+
/** Create or reuse a {@link deviceVar} observable for this name and context. */
|
|
134
135
|
export declare function deviceVar<T = string>(name: string, opts?: Omit<IPersistentVarOptionsWithoutDefault<T>, "scope" | "dataContext">): PersistentVar<T | undefined>;
|
|
135
136
|
/**
|
|
136
137
|
* A persistent variable that is stored in the user's personal db and synced across all their devices
|
|
137
138
|
*/
|
|
138
139
|
export declare function userVar<T = string>(name: string, opts: Omit<IPersistentVarOptionsWithDefault<T>, "scope" | "dataContext">): PersistentVar<T>;
|
|
140
|
+
/** Create or reuse a {@link userVar} observable for this name and context. */
|
|
139
141
|
export declare function userVar<T = string>(name: string, opts?: Omit<IPersistentVarOptionsWithoutDefault<T>, "scope" | "dataContext">): PersistentVar<T | undefined>;
|
|
140
142
|
/**
|
|
141
143
|
* A persistent variable that is shared by all users in a group. It is stored in the group's db and synced across all users and devices in the group.
|
|
@@ -143,6 +145,7 @@ export declare function userVar<T = string>(name: string, opts?: Omit<IPersisten
|
|
|
143
145
|
* If secret=true, it is encrypted with the group's secret key
|
|
144
146
|
*/
|
|
145
147
|
export declare function groupVar<T = string>(name: string, opts: Omit<IPersistentVarOptionsWithDefault<T>, "scope">): PersistentVar<T>;
|
|
148
|
+
/** Create or reuse a {@link groupVar} observable for this name and context. */
|
|
146
149
|
export declare function groupVar<T = string>(name: string, opts?: Omit<IPersistentVarOptionsWithoutDefault<T>, "scope">): PersistentVar<T | undefined>;
|
|
147
150
|
/**
|
|
148
151
|
* A persistent variable that is stored only on this device, in the user's personal db.
|
|
@@ -154,6 +157,7 @@ export declare function groupVar<T = string>(name: string, opts?: Omit<IPersiste
|
|
|
154
157
|
* renderer callers that follow the default group share one row.
|
|
155
158
|
*/
|
|
156
159
|
export declare function groupDeviceVar<T = string>(name: string, opts: Omit<IPersistentVarOptionsWithDefault<T>, "scope">): PersistentVar<T>;
|
|
160
|
+
/** Create or reuse a {@link groupDeviceVar} observable for this name and context. */
|
|
157
161
|
export declare function groupDeviceVar<T = string>(name: string, opts?: Omit<IPersistentVarOptionsWithoutDefault<T>, "scope">): PersistentVar<T | undefined>;
|
|
158
162
|
/**
|
|
159
163
|
* A persistent variable that is stored in the user's personal db and synced across all their devices in the group.
|
|
@@ -163,4 +167,5 @@ export declare function groupDeviceVar<T = string>(name: string, opts?: Omit<IPe
|
|
|
163
167
|
* only selects the group whose value is addressed.
|
|
164
168
|
*/
|
|
165
169
|
export declare function groupUserVar<T = string>(name: string, opts: Omit<IPersistentVarOptionsWithDefault<T>, "scope">): PersistentVar<T>;
|
|
170
|
+
/** Create or reuse a {@link groupUserVar} observable for this name and context. */
|
|
166
171
|
export declare function groupUserVar<T = string>(name: string, opts?: Omit<IPersistentVarOptionsWithoutDefault<T>, "scope">): PersistentVar<T | undefined>;
|
|
@@ -278,6 +278,7 @@ function userContextCacheId(userContext) {
|
|
|
278
278
|
}
|
|
279
279
|
return String(id);
|
|
280
280
|
}
|
|
281
|
+
/** Create or reuse a {@link deviceVar} observable for this name and context. */
|
|
281
282
|
function deviceVar(name, opts) {
|
|
282
283
|
const fullOpts = { ...opts, scope: "device" };
|
|
283
284
|
if (opts?.defaultValue !== undefined) {
|
|
@@ -287,6 +288,7 @@ function deviceVar(name, opts) {
|
|
|
287
288
|
return persistentVarFactory(name, fullOpts);
|
|
288
289
|
}
|
|
289
290
|
}
|
|
291
|
+
/** Create or reuse a {@link userVar} observable for this name and context. */
|
|
290
292
|
function userVar(name, opts) {
|
|
291
293
|
const fullOpts = { ...opts, scope: "user" };
|
|
292
294
|
if (opts?.defaultValue !== undefined) {
|
|
@@ -296,6 +298,7 @@ function userVar(name, opts) {
|
|
|
296
298
|
return persistentVarFactory(name, fullOpts);
|
|
297
299
|
}
|
|
298
300
|
}
|
|
301
|
+
/** Create or reuse a {@link groupVar} observable for this name and context. */
|
|
299
302
|
function groupVar(name, opts) {
|
|
300
303
|
const fullOpts = { ...opts, scope: "group" };
|
|
301
304
|
if (opts?.defaultValue !== undefined) {
|
|
@@ -305,6 +308,7 @@ function groupVar(name, opts) {
|
|
|
305
308
|
return persistentVarFactory(name, fullOpts);
|
|
306
309
|
}
|
|
307
310
|
}
|
|
311
|
+
/** Create or reuse a {@link groupDeviceVar} observable for this name and context. */
|
|
308
312
|
function groupDeviceVar(name, opts) {
|
|
309
313
|
const fullOpts = { ...opts, scope: "groupDevice" };
|
|
310
314
|
if (opts?.defaultValue !== undefined) {
|
|
@@ -314,6 +318,7 @@ function groupDeviceVar(name, opts) {
|
|
|
314
318
|
return persistentVarFactory(name, fullOpts);
|
|
315
319
|
}
|
|
316
320
|
}
|
|
321
|
+
/** Create or reuse a {@link groupUserVar} observable for this name and context. */
|
|
317
322
|
function groupUserVar(name, opts) {
|
|
318
323
|
const fullOpts = { ...opts, scope: "groupUser" };
|
|
319
324
|
if (opts?.defaultValue !== undefined) {
|
|
@@ -416,12 +421,21 @@ function persistentVarFactory(name, opts) {
|
|
|
416
421
|
if (!dbRec) {
|
|
417
422
|
dbRec = await migrateLegacyRec(table, name);
|
|
418
423
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
}
|
|
424
|
+
// Preserve an existing secret unless the caller explicitly changes that setting.
|
|
425
|
+
if (dbRec?.isSecret !== undefined && opts.isSecret === undefined) {
|
|
426
|
+
isSecret = dbRec.isSecret;
|
|
427
|
+
}
|
|
428
|
+
if (dbRec && dbRec.scope !== scope) {
|
|
429
|
+
console.warn(`${name}: resetting the persistent var to its default under scope ${scope} (it was stored as ${dbRec.scope}). If this is unexpected there could be two different persistent variables using the same name`);
|
|
430
|
+
// Re-save under the new scope rather than deleting: names share one ID across scopes,
|
|
431
|
+
// and change tracking turns the move into a tombstone (to a device scope, which isn't
|
|
432
|
+
// tracked) or a fresh root snapshot (back to a synced scope) that peers apply.
|
|
433
|
+
dbRec = await table.save({
|
|
434
|
+
...dbRec,
|
|
435
|
+
scope,
|
|
436
|
+
isSecret,
|
|
437
|
+
value: { value: defaultValue },
|
|
438
|
+
});
|
|
425
439
|
}
|
|
426
440
|
if (dbRec && !(0, utils_1.isDeterministicPvarId)(dbRec.persistentVarId)) {
|
|
427
441
|
dbRec = await table.migrateLegacyId(dbRec);
|
|
@@ -503,6 +517,10 @@ function persistentVarFactory(name, opts) {
|
|
|
503
517
|
rec = dbRec;
|
|
504
518
|
}
|
|
505
519
|
if (dbRec.persistentVarId === rec?.persistentVarId) {
|
|
520
|
+
// A later declaration of this scope must reload and perform its own transition.
|
|
521
|
+
if (dbRec.scope !== scope && pvarCache.get(cacheKey) === persistentVar) {
|
|
522
|
+
pvarCache.delete(cacheKey);
|
|
523
|
+
}
|
|
506
524
|
if (evt.data.op === "delete") {
|
|
507
525
|
rec = undefined;
|
|
508
526
|
if (defaultValue !== undefined) {
|