@legendapp/state 0.22.4 → 0.23.0
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/CHANGELOG.md +41 -0
- package/history.js +1 -16
- package/history.js.map +1 -1
- package/history.mjs +1 -16
- package/history.mjs.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +53 -46
- package/index.js.map +1 -1
- package/index.mjs +48 -47
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/persist-plugins/indexeddb-preloader.d.ts +4 -1
- package/persist-plugins/indexeddb-preloader.js +122 -26
- package/persist-plugins/indexeddb-preloader.js.map +1 -1
- package/persist-plugins/indexeddb-preloader.mjs +122 -26
- package/persist-plugins/indexeddb-preloader.mjs.map +1 -1
- package/persist-plugins/indexeddb.d.ts +8 -5
- package/persist-plugins/indexeddb.js +171 -78
- package/persist-plugins/indexeddb.js.map +1 -1
- package/persist-plugins/indexeddb.mjs +172 -79
- package/persist-plugins/indexeddb.mjs.map +1 -1
- package/persist-plugins/mmkv.js +2 -2
- package/persist-plugins/mmkv.js.map +1 -1
- package/persist-plugins/mmkv.mjs +2 -2
- package/persist-plugins/mmkv.mjs.map +1 -1
- package/persist.d.ts +2 -0
- package/persist.js +147 -17
- package/persist.js.map +1 -1
- package/persist.mjs +148 -22
- package/persist.mjs.map +1 -1
- package/src/globals.d.ts +0 -1
- package/src/helpers.d.ts +3 -0
- package/src/is.d.ts +8 -0
- package/src/observableInterfaces.d.ts +44 -44
- package/src/persist/fieldTransformer.d.ts +3 -0
- package/src/persist-plugins/indexeddb-preloader.d.ts +4 -1
- package/src/persist-plugins/indexeddb.d.ts +8 -5
package/src/helpers.d.ts
CHANGED
|
@@ -6,3 +6,6 @@ export declare function getObservableIndex(obs: ObservableReadable): number;
|
|
|
6
6
|
export declare function opaqueObject<T extends object>(value: T): OpaqueObject<T>;
|
|
7
7
|
export declare function lockObservable(obs: ObservableReadable, value: boolean): void;
|
|
8
8
|
export declare function mergeIntoObservable<T extends ObservableObject | object>(target: T, ...sources: any[]): T;
|
|
9
|
+
export declare function constructObject(path: (string | number)[], value: any): object;
|
|
10
|
+
export declare function deconstructObject(path: (string | number)[], value: any): object;
|
|
11
|
+
export declare function clone(obj: any): any;
|
package/src/is.d.ts
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
+
export declare function isArray(obj: unknown): obj is Array<any>;
|
|
2
|
+
export declare function isString(obj: unknown): obj is string;
|
|
3
|
+
export declare function isObject(obj: unknown): obj is Record<any, any>;
|
|
4
|
+
export declare function isFunction(obj: unknown): obj is Function;
|
|
5
|
+
export declare function isPrimitive(arg: unknown): arg is string | number | bigint | boolean | symbol;
|
|
6
|
+
export declare function isSymbol(obj: unknown): obj is symbol;
|
|
7
|
+
export declare function isBoolean(obj: unknown): obj is boolean;
|
|
8
|
+
export declare function isPromise<T>(obj: unknown): obj is Promise<T>;
|
|
1
9
|
export declare function isEmpty(obj: object): boolean;
|
|
@@ -102,9 +102,7 @@ export interface ObservableEvent {
|
|
|
102
102
|
on(eventType: 'change', cb?: () => void): ObservableListenerDispose;
|
|
103
103
|
get(): void;
|
|
104
104
|
}
|
|
105
|
-
export declare type QueryByModified<T> = boolean |
|
|
106
|
-
'*': '*' | true;
|
|
107
|
-
} | {
|
|
105
|
+
export declare type QueryByModified<T> = boolean | {
|
|
108
106
|
[K in keyof T]?: QueryByModified<T[K]>;
|
|
109
107
|
};
|
|
110
108
|
export interface Change {
|
|
@@ -112,29 +110,40 @@ export interface Change {
|
|
|
112
110
|
valueAtPath: any;
|
|
113
111
|
prevAtPath: any;
|
|
114
112
|
}
|
|
115
|
-
export interface PersistOptionsLocal {
|
|
113
|
+
export interface PersistOptionsLocal<T = any> {
|
|
116
114
|
name: string;
|
|
115
|
+
adjustData?: {
|
|
116
|
+
load?: (value: T) => T | Promise<T>;
|
|
117
|
+
save?: (value: T) => T | Promise<T>;
|
|
118
|
+
};
|
|
119
|
+
fieldTransforms?: FieldTransforms<T>;
|
|
117
120
|
mmkv?: MMKVConfiguration;
|
|
121
|
+
indexedDB?: {
|
|
122
|
+
prefixID?: string;
|
|
123
|
+
itemID?: string;
|
|
124
|
+
};
|
|
118
125
|
}
|
|
119
126
|
export interface PersistOptionsRemote<T = any> {
|
|
120
127
|
readonly?: boolean;
|
|
121
128
|
once?: boolean;
|
|
122
129
|
requireAuth?: boolean;
|
|
123
130
|
saveTimeout?: number;
|
|
131
|
+
waitForLoad?: Promise<any>;
|
|
132
|
+
waitForSave?: Promise<any> | ((value: T) => Promise<any>);
|
|
124
133
|
manual?: boolean;
|
|
125
134
|
adjustData?: {
|
|
126
|
-
load
|
|
127
|
-
save
|
|
135
|
+
load?: (value: T, basePath: string) => T | Promise<T>;
|
|
136
|
+
save?: (value: T, basePath: string, path: string[]) => T | Promise<T>;
|
|
128
137
|
};
|
|
129
138
|
firebase?: {
|
|
130
139
|
syncPath: (uid: string) => `/${string}/`;
|
|
131
|
-
fieldTransforms?:
|
|
140
|
+
fieldTransforms?: FieldTransforms<T>;
|
|
132
141
|
queryByModified?: QueryByModified<T>;
|
|
133
|
-
ignoreKeys?:
|
|
142
|
+
ignoreKeys?: string[];
|
|
134
143
|
};
|
|
135
144
|
}
|
|
136
145
|
export interface PersistOptions<T = any> {
|
|
137
|
-
local?: string | PersistOptionsLocal
|
|
146
|
+
local?: string | PersistOptionsLocal<T>;
|
|
138
147
|
remote?: PersistOptionsRemote<T>;
|
|
139
148
|
persistLocal?: ClassConstructor<ObservablePersistLocal>;
|
|
140
149
|
persistRemote?: ClassConstructor<ObservablePersistRemote>;
|
|
@@ -144,16 +153,16 @@ export interface PersistMetadata {
|
|
|
144
153
|
id?: '__legend_metadata';
|
|
145
154
|
modified?: number;
|
|
146
155
|
pending?: any;
|
|
147
|
-
array?: boolean;
|
|
148
156
|
}
|
|
149
157
|
export interface ObservablePersistLocal {
|
|
150
158
|
initialize?(config: ObservablePersistenceConfig['persistLocalOptions']): Promise<void>;
|
|
151
|
-
getTable<T = any>(table: string, config: PersistOptionsLocal
|
|
152
|
-
|
|
159
|
+
getTable<T = any>(table: string, config: PersistOptionsLocal): T;
|
|
160
|
+
getTableTransformed?<T = any>(table: string, config: PersistOptionsLocal): T;
|
|
161
|
+
getMetadata(table: string, config: PersistOptionsLocal): PersistMetadata;
|
|
153
162
|
set(table: string, value: any, changes: Change[], config: PersistOptionsLocal): Promise<void>;
|
|
154
|
-
updateMetadata(table: string, metadata: PersistMetadata, config: PersistOptionsLocal
|
|
155
|
-
deleteTable(table: string, config: PersistOptionsLocal
|
|
156
|
-
loadTable?(table: string, config: PersistOptionsLocal |
|
|
163
|
+
updateMetadata(table: string, metadata: PersistMetadata, config: PersistOptionsLocal): Promise<void>;
|
|
164
|
+
deleteTable(table: string, config: PersistOptionsLocal): Promise<void>;
|
|
165
|
+
loadTable?(table: string, config: PersistOptionsLocal): void | Promise<void>;
|
|
157
166
|
}
|
|
158
167
|
export interface ObservablePersistLocalAsync extends ObservablePersistLocal {
|
|
159
168
|
preload(path: string): Promise<void>;
|
|
@@ -172,36 +181,27 @@ export interface ObservablePersistState {
|
|
|
172
181
|
}
|
|
173
182
|
export declare type RecordValue<T> = T extends Record<string, infer t> ? t : never;
|
|
174
183
|
export declare type ArrayValue<T> = T extends Array<infer t> ? t : never;
|
|
175
|
-
|
|
176
|
-
[K in keyof T]-?: string
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
_: string;
|
|
196
|
-
__dict: SameShapeWithStrings<T[K]>;
|
|
197
|
-
}) | string : string | {
|
|
198
|
-
_: string;
|
|
199
|
-
__val: Record<string, string>;
|
|
200
|
-
};
|
|
184
|
+
declare type ObjectKeys<T> = Pick<T, {
|
|
185
|
+
[K in keyof T]-?: K extends string ? T[K] extends Record<string, any> ? T[K] extends any[] ? never : K : never : never;
|
|
186
|
+
}[keyof T]>;
|
|
187
|
+
declare type DictKeys<T> = Pick<T, {
|
|
188
|
+
[K in keyof T]-?: K extends string ? (T[K] extends Record<string, Record<string, any>> ? K : never) : never;
|
|
189
|
+
}[keyof T]>;
|
|
190
|
+
declare type ArrayKeys<T> = Pick<T, {
|
|
191
|
+
[K in keyof T]-?: K extends string | number ? (T[K] extends any[] ? K : never) : never;
|
|
192
|
+
}[keyof T]>;
|
|
193
|
+
export declare type FieldTransforms<T> = (T extends Record<string, Record<string, any>> ? {
|
|
194
|
+
_dict: FieldTransformsInner<RecordValue<T>>;
|
|
195
|
+
} : never) | FieldTransformsInner<T>;
|
|
196
|
+
export declare type FieldTransformsInner<T> = {
|
|
197
|
+
[K in keyof T]: string;
|
|
198
|
+
} & ({
|
|
199
|
+
[K in keyof ObjectKeys<T> as `${K}_obj`]?: FieldTransforms<T[K]>;
|
|
200
|
+
} | {
|
|
201
|
+
[K in keyof DictKeys<T> as `${K}_dict`]?: FieldTransforms<RecordValue<T[K]>>;
|
|
202
|
+
}) & {
|
|
203
|
+
[K in keyof ArrayKeys<T> as `${K}_arr`]?: FieldTransforms<ArrayValue<T[K]>>;
|
|
201
204
|
};
|
|
202
|
-
export declare type SameShapeWithStrings<T> = T extends Record<string, Record<string, any>> ? {
|
|
203
|
-
__dict: SameShapeWithStrings<RecordValue<T>>;
|
|
204
|
-
} | SameShapeWithStringsRecord<T> : SameShapeWithStringsRecord<T>;
|
|
205
205
|
export declare type Selector<T> = ObservableReadable<T> | (() => T) | T;
|
|
206
206
|
export declare type ClassConstructor<I, Args extends any[] = any[]> = new (...args: Args) => I;
|
|
207
207
|
export declare type ObservableListenerDispose = () => void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function transformPath(path: string[], map: Record<string, any>, passThroughKeys: string[], ignoreKeys?: string[]): string[];
|
|
2
|
+
export declare function transformObject(dataIn: Record<string, any>, map: Record<string, any>, passThroughKeys: string[], ignoreKeys?: string[]): Record<string, any>;
|
|
3
|
+
export declare function invertMap(obj: Record<string, any>): any;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import type { FieldTransforms } from '../observableInterfaces';
|
|
2
|
+
export declare function preloadIndexedDB({ databaseName, tableNames, version, loadTables, processTables, fieldTransforms, }: {
|
|
2
3
|
databaseName: string;
|
|
3
4
|
tableNames: string[];
|
|
4
5
|
version: number;
|
|
5
6
|
loadTables?: string[];
|
|
7
|
+
processTables?: (tableData: Record<string, any>) => void;
|
|
8
|
+
fieldTransforms?: Record<string, FieldTransforms<any>>;
|
|
6
9
|
}): void;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import type { Change, ObservablePersistenceConfig, ObservablePersistLocal, PersistMetadata } from '../observableInterfaces';
|
|
1
|
+
import type { Change, ObservablePersistenceConfig, ObservablePersistLocal, PersistMetadata, PersistOptionsLocal } from '../observableInterfaces';
|
|
2
2
|
export declare class ObservablePersistIndexedDB implements ObservablePersistLocal {
|
|
3
3
|
private tableData;
|
|
4
4
|
private tableMetadata;
|
|
5
|
+
private tablesAdjusted;
|
|
5
6
|
private db;
|
|
6
7
|
initialize(config: ObservablePersistenceConfig['persistLocalOptions']): Promise<void>;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
loadTable(table: string, config: PersistOptionsLocal): void | Promise<void>;
|
|
9
|
+
getTable(table: string, config: PersistOptionsLocal): any;
|
|
10
|
+
getTableTransformed<T = any>(table: string, config: PersistOptionsLocal<any>): T;
|
|
11
|
+
getMetadata(table: string, config: PersistOptionsLocal): any;
|
|
12
|
+
updateMetadata(table: string, metadata: PersistMetadata, config: PersistOptionsLocal): Promise<void>;
|
|
13
|
+
set(table: string, tableValue: Record<string, any>, changes: Change[], config: PersistOptionsLocal): Promise<void>;
|
|
11
14
|
deleteTable(table: string): Promise<void>;
|
|
12
15
|
private initTable;
|
|
13
16
|
private transactionStore;
|