@legendapp/state 3.0.0-beta.37 → 3.0.0-beta.38
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.
- package/index.js +15 -9
- package/index.mjs +15 -9
- package/package.json +1 -1
- package/persist-plugins/indexeddb.js +13 -3
- package/persist-plugins/indexeddb.mjs +13 -3
- package/react-web.d.mts +1 -0
- package/react-web.d.ts +1 -0
- package/sync-plugins/supabase.d.mts +3 -2
- package/sync-plugins/supabase.d.ts +3 -2
package/index.js
CHANGED
|
@@ -146,6 +146,16 @@ function isEvent(value$) {
|
|
|
146
146
|
var _a;
|
|
147
147
|
return value$ && ((_a = value$[symbolGetNode]) == null ? void 0 : _a.isEvent);
|
|
148
148
|
}
|
|
149
|
+
function setNewValue(parentValue, key, newValue, useSetFn, useMapFn) {
|
|
150
|
+
if (useSetFn) {
|
|
151
|
+
parentValue.add(newValue);
|
|
152
|
+
} else if (useMapFn) {
|
|
153
|
+
parentValue.set(key, newValue);
|
|
154
|
+
} else {
|
|
155
|
+
parentValue[key] = newValue;
|
|
156
|
+
}
|
|
157
|
+
return newValue;
|
|
158
|
+
}
|
|
149
159
|
function setNodeValue(node, newValue) {
|
|
150
160
|
var _a;
|
|
151
161
|
const parentNode = (_a = node.parent) != null ? _a : node;
|
|
@@ -169,13 +179,7 @@ function setNodeValue(node, newValue) {
|
|
|
169
179
|
delete parentValue[key];
|
|
170
180
|
}
|
|
171
181
|
} else {
|
|
172
|
-
|
|
173
|
-
parentValue.add(newValue);
|
|
174
|
-
} else if (useMapFn) {
|
|
175
|
-
parentValue.set(key, newValue);
|
|
176
|
-
} else {
|
|
177
|
-
parentValue[key] = newValue;
|
|
178
|
-
}
|
|
182
|
+
setNewValue(parentValue, key, newValue, useSetFn, useMapFn);
|
|
179
183
|
}
|
|
180
184
|
} finally {
|
|
181
185
|
parentNode.isSetting--;
|
|
@@ -194,7 +198,7 @@ function getNodeValue(node) {
|
|
|
194
198
|
let child = node.root._;
|
|
195
199
|
for (let i = count - 1; child && i >= 0; i--) {
|
|
196
200
|
const key = arrNodeKeys[i];
|
|
197
|
-
child = key !== "size" &&
|
|
201
|
+
child = key !== "size" && isMap(child) ? child.get(key) : child[key];
|
|
198
202
|
}
|
|
199
203
|
return child;
|
|
200
204
|
}
|
|
@@ -229,7 +233,9 @@ function ensureNodeValue(node) {
|
|
|
229
233
|
if (!value || isFunction(value)) {
|
|
230
234
|
if (isChildNode(node)) {
|
|
231
235
|
const parent = ensureNodeValue(node.parent);
|
|
232
|
-
|
|
236
|
+
const useSetFn = isSet(parent);
|
|
237
|
+
const useMapFn = isMap(parent);
|
|
238
|
+
value = setNewValue(parent, node.key, {}, useSetFn, useMapFn);
|
|
233
239
|
} else {
|
|
234
240
|
value = node.root._ = {};
|
|
235
241
|
}
|
package/index.mjs
CHANGED
|
@@ -144,6 +144,16 @@ function isEvent(value$) {
|
|
|
144
144
|
var _a;
|
|
145
145
|
return value$ && ((_a = value$[symbolGetNode]) == null ? void 0 : _a.isEvent);
|
|
146
146
|
}
|
|
147
|
+
function setNewValue(parentValue, key, newValue, useSetFn, useMapFn) {
|
|
148
|
+
if (useSetFn) {
|
|
149
|
+
parentValue.add(newValue);
|
|
150
|
+
} else if (useMapFn) {
|
|
151
|
+
parentValue.set(key, newValue);
|
|
152
|
+
} else {
|
|
153
|
+
parentValue[key] = newValue;
|
|
154
|
+
}
|
|
155
|
+
return newValue;
|
|
156
|
+
}
|
|
147
157
|
function setNodeValue(node, newValue) {
|
|
148
158
|
var _a;
|
|
149
159
|
const parentNode = (_a = node.parent) != null ? _a : node;
|
|
@@ -167,13 +177,7 @@ function setNodeValue(node, newValue) {
|
|
|
167
177
|
delete parentValue[key];
|
|
168
178
|
}
|
|
169
179
|
} else {
|
|
170
|
-
|
|
171
|
-
parentValue.add(newValue);
|
|
172
|
-
} else if (useMapFn) {
|
|
173
|
-
parentValue.set(key, newValue);
|
|
174
|
-
} else {
|
|
175
|
-
parentValue[key] = newValue;
|
|
176
|
-
}
|
|
180
|
+
setNewValue(parentValue, key, newValue, useSetFn, useMapFn);
|
|
177
181
|
}
|
|
178
182
|
} finally {
|
|
179
183
|
parentNode.isSetting--;
|
|
@@ -192,7 +196,7 @@ function getNodeValue(node) {
|
|
|
192
196
|
let child = node.root._;
|
|
193
197
|
for (let i = count - 1; child && i >= 0; i--) {
|
|
194
198
|
const key = arrNodeKeys[i];
|
|
195
|
-
child = key !== "size" &&
|
|
199
|
+
child = key !== "size" && isMap(child) ? child.get(key) : child[key];
|
|
196
200
|
}
|
|
197
201
|
return child;
|
|
198
202
|
}
|
|
@@ -227,7 +231,9 @@ function ensureNodeValue(node) {
|
|
|
227
231
|
if (!value || isFunction(value)) {
|
|
228
232
|
if (isChildNode(node)) {
|
|
229
233
|
const parent = ensureNodeValue(node.parent);
|
|
230
|
-
|
|
234
|
+
const useSetFn = isSet(parent);
|
|
235
|
+
const useMapFn = isMap(parent);
|
|
236
|
+
value = setNewValue(parent, node.key, {}, useSetFn, useMapFn);
|
|
231
237
|
} else {
|
|
232
238
|
value = node.root._ = {};
|
|
233
239
|
}
|
package/package.json
CHANGED
|
@@ -5,6 +5,12 @@ var state = require('@legendapp/state');
|
|
|
5
5
|
// src/persist-plugins/indexeddb.ts
|
|
6
6
|
var MetadataSuffix = "__legend_metadata";
|
|
7
7
|
var PrimitiveName = "__legend_primitive";
|
|
8
|
+
function getIndexedDB() {
|
|
9
|
+
if (typeof globalThis === "undefined") {
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
return globalThis.indexedDB;
|
|
13
|
+
}
|
|
8
14
|
function requestToPromise(request) {
|
|
9
15
|
return new Promise((resolve) => request.onsuccess = () => resolve());
|
|
10
16
|
}
|
|
@@ -21,8 +27,9 @@ var ObservablePersistIndexedDB = class {
|
|
|
21
27
|
}
|
|
22
28
|
async initialize(configOptions) {
|
|
23
29
|
const config = this.configuration || configOptions.indexedDB;
|
|
24
|
-
if (
|
|
30
|
+
if (!getIndexedDB()) {
|
|
25
31
|
return;
|
|
32
|
+
}
|
|
26
33
|
if (process.env.NODE_ENV === "development" && !config) {
|
|
27
34
|
console.error("[legend-state] Must configure ObservablePersistIndexedDB");
|
|
28
35
|
}
|
|
@@ -69,6 +76,9 @@ var ObservablePersistIndexedDB = class {
|
|
|
69
76
|
loadTable(table, config) {
|
|
70
77
|
var _a;
|
|
71
78
|
if (!this.db) {
|
|
79
|
+
if (!getIndexedDB()) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
72
82
|
throw new Error(
|
|
73
83
|
"[legend-state] ObservablePersistIndexedDB loading without being initialized. This may happen when running outside of a browser."
|
|
74
84
|
);
|
|
@@ -147,7 +157,7 @@ var ObservablePersistIndexedDB = class {
|
|
|
147
157
|
}
|
|
148
158
|
async set(table, changes, config) {
|
|
149
159
|
var _a, _b;
|
|
150
|
-
if (
|
|
160
|
+
if (!getIndexedDB())
|
|
151
161
|
return;
|
|
152
162
|
if (!this.pendingSaves.has(config)) {
|
|
153
163
|
this.pendingSaves.set(config, {});
|
|
@@ -238,7 +248,7 @@ var ObservablePersistIndexedDB = class {
|
|
|
238
248
|
delete this.tableData[tableName];
|
|
239
249
|
delete this.tableData[tableName + "_transformed"];
|
|
240
250
|
}
|
|
241
|
-
if (
|
|
251
|
+
if (!getIndexedDB())
|
|
242
252
|
return;
|
|
243
253
|
this.deleteMetadata(table, config);
|
|
244
254
|
if (data) {
|
|
@@ -3,6 +3,12 @@ import { when, isPromise, observable, setAtPath, isPrimitive } from '@legendapp/
|
|
|
3
3
|
// src/persist-plugins/indexeddb.ts
|
|
4
4
|
var MetadataSuffix = "__legend_metadata";
|
|
5
5
|
var PrimitiveName = "__legend_primitive";
|
|
6
|
+
function getIndexedDB() {
|
|
7
|
+
if (typeof globalThis === "undefined") {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
return globalThis.indexedDB;
|
|
11
|
+
}
|
|
6
12
|
function requestToPromise(request) {
|
|
7
13
|
return new Promise((resolve) => request.onsuccess = () => resolve());
|
|
8
14
|
}
|
|
@@ -19,8 +25,9 @@ var ObservablePersistIndexedDB = class {
|
|
|
19
25
|
}
|
|
20
26
|
async initialize(configOptions) {
|
|
21
27
|
const config = this.configuration || configOptions.indexedDB;
|
|
22
|
-
if (
|
|
28
|
+
if (!getIndexedDB()) {
|
|
23
29
|
return;
|
|
30
|
+
}
|
|
24
31
|
if (process.env.NODE_ENV === "development" && !config) {
|
|
25
32
|
console.error("[legend-state] Must configure ObservablePersistIndexedDB");
|
|
26
33
|
}
|
|
@@ -67,6 +74,9 @@ var ObservablePersistIndexedDB = class {
|
|
|
67
74
|
loadTable(table, config) {
|
|
68
75
|
var _a;
|
|
69
76
|
if (!this.db) {
|
|
77
|
+
if (!getIndexedDB()) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
70
80
|
throw new Error(
|
|
71
81
|
"[legend-state] ObservablePersistIndexedDB loading without being initialized. This may happen when running outside of a browser."
|
|
72
82
|
);
|
|
@@ -145,7 +155,7 @@ var ObservablePersistIndexedDB = class {
|
|
|
145
155
|
}
|
|
146
156
|
async set(table, changes, config) {
|
|
147
157
|
var _a, _b;
|
|
148
|
-
if (
|
|
158
|
+
if (!getIndexedDB())
|
|
149
159
|
return;
|
|
150
160
|
if (!this.pendingSaves.has(config)) {
|
|
151
161
|
this.pendingSaves.set(config, {});
|
|
@@ -236,7 +246,7 @@ var ObservablePersistIndexedDB = class {
|
|
|
236
246
|
delete this.tableData[tableName];
|
|
237
247
|
delete this.tableData[tableName + "_transformed"];
|
|
238
248
|
}
|
|
239
|
-
if (
|
|
249
|
+
if (!getIndexedDB())
|
|
240
250
|
return;
|
|
241
251
|
this.deleteMetadata(table, config);
|
|
242
252
|
if (data) {
|
package/react-web.d.mts
CHANGED
package/react-web.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
11
11
|
type IsUnionOfStrings<T> = [T] extends [string] ? ([T] extends [UnionToIntersection<T>] ? false : true) : false;
|
|
12
12
|
type SupabaseSchemaOf<Client extends SupabaseClient> = Client extends SupabaseClient<infer _, infer __, infer Schema> ? Schema : never;
|
|
13
13
|
type SupabaseTableOf<Client extends SupabaseClient, SchemaName extends SchemaNameOf<Client>> = DatabaseOf<Client>[SchemaName]['Tables'];
|
|
14
|
-
type
|
|
14
|
+
type SupabaseViewOf<Client extends SupabaseClient, SchemaName extends SchemaNameOf<Client>> = DatabaseOf<Client>[SchemaName]['Views'];
|
|
15
|
+
type SupabaseCollectionOf<Client extends SupabaseClient, SchemaName extends SchemaNameOf<Client>> = keyof SupabaseTableOf<Client, IsUnionOfStrings<SchemaName> extends true ? 'public' : SchemaName> | keyof SupabaseViewOf<Client, IsUnionOfStrings<SchemaName> extends true ? 'public' : SchemaName>;
|
|
15
16
|
type SupabaseRowOf<Client extends SupabaseClient, Collection extends SupabaseCollectionOf<Client, SchemaName>, SchemaName extends SchemaNameOf<Client>> = SupabaseTableOf<Client, SchemaName>[Collection]['Row'];
|
|
16
17
|
type SyncedSupabaseConfig<TRemote extends {
|
|
17
18
|
id: string | number;
|
|
@@ -50,4 +51,4 @@ declare function configureSyncedSupabase(config: SyncedSupabaseConfiguration): v
|
|
|
50
51
|
declare function syncedSupabase<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName> & string, SchemaName extends SchemaNameOf<Client> = 'public', AsOption extends CrudAsOption = 'object', TRemote = SupabaseRowOf<Client, Collection, SchemaName>, TLocal = TRemote>(props: SyncedSupabasePropsWithSelect<Client, Collection, SchemaName, AsOption, TRemote, TLocal>): SyncedCrudReturnType<TLocal, AsOption>;
|
|
51
52
|
declare function syncedSupabase<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName> & string, SchemaName extends SchemaNameOf<Client> = 'public', AsOption extends CrudAsOption = 'object', TRemote extends SupabaseRowOf<Client, Collection, SchemaName> = SupabaseRowOf<Client, Collection, SchemaName>, TLocal = TRemote>(props: SyncedSupabaseProps<Client, Collection, SchemaName, AsOption, TRemote, TLocal>): SyncedCrudReturnType<TLocal, AsOption>;
|
|
52
53
|
|
|
53
|
-
export { type SupabaseCollectionOf, type SupabaseRowOf, type SupabaseSchemaOf, type SupabaseTableOf, type SyncedSupabaseConfig, type SyncedSupabaseConfiguration, configureSyncedSupabase, getSyncedSupabaseConfiguration, syncedSupabase };
|
|
54
|
+
export { type SupabaseCollectionOf, type SupabaseRowOf, type SupabaseSchemaOf, type SupabaseTableOf, type SupabaseViewOf, type SyncedSupabaseConfig, type SyncedSupabaseConfiguration, configureSyncedSupabase, getSyncedSupabaseConfiguration, syncedSupabase };
|
|
@@ -11,7 +11,8 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
11
11
|
type IsUnionOfStrings<T> = [T] extends [string] ? ([T] extends [UnionToIntersection<T>] ? false : true) : false;
|
|
12
12
|
type SupabaseSchemaOf<Client extends SupabaseClient> = Client extends SupabaseClient<infer _, infer __, infer Schema> ? Schema : never;
|
|
13
13
|
type SupabaseTableOf<Client extends SupabaseClient, SchemaName extends SchemaNameOf<Client>> = DatabaseOf<Client>[SchemaName]['Tables'];
|
|
14
|
-
type
|
|
14
|
+
type SupabaseViewOf<Client extends SupabaseClient, SchemaName extends SchemaNameOf<Client>> = DatabaseOf<Client>[SchemaName]['Views'];
|
|
15
|
+
type SupabaseCollectionOf<Client extends SupabaseClient, SchemaName extends SchemaNameOf<Client>> = keyof SupabaseTableOf<Client, IsUnionOfStrings<SchemaName> extends true ? 'public' : SchemaName> | keyof SupabaseViewOf<Client, IsUnionOfStrings<SchemaName> extends true ? 'public' : SchemaName>;
|
|
15
16
|
type SupabaseRowOf<Client extends SupabaseClient, Collection extends SupabaseCollectionOf<Client, SchemaName>, SchemaName extends SchemaNameOf<Client>> = SupabaseTableOf<Client, SchemaName>[Collection]['Row'];
|
|
16
17
|
type SyncedSupabaseConfig<TRemote extends {
|
|
17
18
|
id: string | number;
|
|
@@ -50,4 +51,4 @@ declare function configureSyncedSupabase(config: SyncedSupabaseConfiguration): v
|
|
|
50
51
|
declare function syncedSupabase<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName> & string, SchemaName extends SchemaNameOf<Client> = 'public', AsOption extends CrudAsOption = 'object', TRemote = SupabaseRowOf<Client, Collection, SchemaName>, TLocal = TRemote>(props: SyncedSupabasePropsWithSelect<Client, Collection, SchemaName, AsOption, TRemote, TLocal>): SyncedCrudReturnType<TLocal, AsOption>;
|
|
51
52
|
declare function syncedSupabase<Client extends SupabaseClient<any, any>, Collection extends SupabaseCollectionOf<Client, SchemaName> & string, SchemaName extends SchemaNameOf<Client> = 'public', AsOption extends CrudAsOption = 'object', TRemote extends SupabaseRowOf<Client, Collection, SchemaName> = SupabaseRowOf<Client, Collection, SchemaName>, TLocal = TRemote>(props: SyncedSupabaseProps<Client, Collection, SchemaName, AsOption, TRemote, TLocal>): SyncedCrudReturnType<TLocal, AsOption>;
|
|
52
53
|
|
|
53
|
-
export { type SupabaseCollectionOf, type SupabaseRowOf, type SupabaseSchemaOf, type SupabaseTableOf, type SyncedSupabaseConfig, type SyncedSupabaseConfiguration, configureSyncedSupabase, getSyncedSupabaseConfiguration, syncedSupabase };
|
|
54
|
+
export { type SupabaseCollectionOf, type SupabaseRowOf, type SupabaseSchemaOf, type SupabaseTableOf, type SupabaseViewOf, type SyncedSupabaseConfig, type SyncedSupabaseConfiguration, configureSyncedSupabase, getSyncedSupabaseConfiguration, syncedSupabase };
|