tsdf 16.0.3 → 17.0.0-alpha.1
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/README.md +2 -0
- package/dist/main.d.ts +2694 -366
- package/dist/main.js +18790 -2474
- package/docs/README.md +94 -0
- package/docs/batch-fetching.md +125 -0
- package/docs/browser-tabs-sync.md +59 -0
- package/docs/cache-limits.md +105 -0
- package/docs/collection-store.md +170 -0
- package/docs/document-store.md +147 -0
- package/docs/fetch-scheduling.md +93 -0
- package/docs/hooks.md +416 -0
- package/docs/invalidation.md +133 -0
- package/docs/list-query-store.md +348 -0
- package/docs/mutations.md +261 -0
- package/docs/offline.md +207 -0
- package/docs/offset-pagination.md +111 -0
- package/docs/optimistic-list-updates.md +180 -0
- package/docs/partial-resources.md +168 -0
- package/docs/persistent-storage.md +282 -0
- package/docs/real-time-updates.md +156 -0
- package/docs/shared-types.md +169 -0
- package/docs/store-manager.md +118 -0
- package/package.json +63 -46
- package/dist/main.cjs +0 -2511
- package/dist/main.d.cts +0 -400
package/dist/main.d.ts
CHANGED
|
@@ -1,400 +1,2728 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { __LEGIT_ANY__ } from "@ls-stack/utils/saferTyping";
|
|
2
|
+
import { Emitter } from "evtmitter";
|
|
3
|
+
import { Context } from "react";
|
|
4
|
+
import { Result } from "t-result";
|
|
5
|
+
import { Store } from "t-state";
|
|
6
|
+
import { RcType } from "runcheck";
|
|
7
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
8
|
|
|
9
|
+
//#region src/requestScheduler.d.ts
|
|
10
|
+
type RequestSchedulerEvents = 'scheduled-fetch-started' | 'rt-fetch-scheduled' | 'rt-fetch-cancelled' | 'scheduled-rt-fetch-started' | 'medium-priority-scheduled' | 'medium-priority-fetch-started' | 'medium-priority-cancelled' | 'batch-size-triggered';
|
|
11
|
+
type RequestSchedulerEventData = {
|
|
12
|
+
/** Delay in ms for scheduled events (medium-priority-scheduled, rt-fetch-scheduled) */delayMs?: number;
|
|
13
|
+
};
|
|
14
|
+
type ScheduleFetchResults = 'skipped' | 'started' | 'scheduled' | 'rt-scheduled' | 'triggered' | 'coalesced' | 'medium-scheduled' | 'added-to-batch' | 'batch-triggered';
|
|
15
|
+
type FetchType = 'lowPriority' | 'mediumPriority' | 'highPriority' | 'realtimeUpdate';
|
|
16
|
+
type ScheduleFetchOptions = {
|
|
17
|
+
mediumPriorityDelayMs?: number;
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/utils/storeShared.d.ts
|
|
6
21
|
type TSDFStatus = 'loading' | 'error' | 'refetching' | 'success';
|
|
7
22
|
type ValidPayload = number | string | Record<string, unknown>;
|
|
8
|
-
type ValidStoreState = Record<string, unknown> |
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
type ValidStoreState = Record<string, unknown> | unknown[];
|
|
24
|
+
/**
|
|
25
|
+
* Debounce settings for payload-driven automatic fetches in store hooks.
|
|
26
|
+
*
|
|
27
|
+
* The hook still reads data from state using the latest payload immediately.
|
|
28
|
+
* Only the automatic fetch side is delayed. Single hooks do not support
|
|
29
|
+
* combining this with `ensureIsLoaded`.
|
|
30
|
+
*/
|
|
31
|
+
type PayloadDebounce = {
|
|
32
|
+
/** Debounce window in milliseconds before the latest payload is fetched. */ms: number;
|
|
33
|
+
/**
|
|
34
|
+
* Maximum time a burst may stay deferred before the latest payload is
|
|
35
|
+
* fetched, even if changes keep happening within the debounce window.
|
|
36
|
+
*/
|
|
37
|
+
maxWait?: number;
|
|
38
|
+
/**
|
|
39
|
+
* When true, the first payload in a burst may fetch immediately, and later
|
|
40
|
+
* changes within the same burst stay debounced until the wait window ends.
|
|
41
|
+
*/
|
|
42
|
+
leading?: boolean;
|
|
22
43
|
};
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
type
|
|
61
|
-
|
|
44
|
+
type StoreError = {
|
|
45
|
+
code: number;
|
|
46
|
+
id: string;
|
|
47
|
+
message: string;
|
|
48
|
+
path?: string;
|
|
49
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
50
|
+
};
|
|
51
|
+
declare const fetchTypePriority: Record<FetchType, number>;
|
|
52
|
+
type MutationSkipped = {
|
|
53
|
+
kind: 'skipped';
|
|
54
|
+
};
|
|
55
|
+
declare const mutationSkipped: MutationSkipped;
|
|
56
|
+
declare class StoreMutationError extends Error {
|
|
57
|
+
readonly kind = "error";
|
|
58
|
+
code: number;
|
|
59
|
+
id: string;
|
|
60
|
+
path?: string;
|
|
61
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
62
|
+
constructor(error: StoreError, options?: ErrorOptions);
|
|
63
|
+
}
|
|
64
|
+
declare class StoreFetchError extends Error {
|
|
65
|
+
code: number;
|
|
66
|
+
id: string;
|
|
67
|
+
type: 'fetch' | 'aborted' | 'timeout';
|
|
68
|
+
path?: string;
|
|
69
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
70
|
+
constructor(error: StoreError, type: 'fetch' | 'aborted' | 'timeout');
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/persistentStorage/offlineUploadTypes.d.ts
|
|
74
|
+
type OfflineUploadState = 'pending' | 'uploading' | 'uploaded' | 'failed';
|
|
75
|
+
type OfflineUploadSource = 'manual' | 'mutation';
|
|
76
|
+
type OfflineUploadProgress = {
|
|
77
|
+
progress: number;
|
|
78
|
+
loadedBytes?: number;
|
|
79
|
+
totalBytes?: number;
|
|
80
|
+
};
|
|
81
|
+
type OfflineUpload<TResolvedRef extends ValidPayload = ValidPayload> = {
|
|
82
|
+
id: string;
|
|
83
|
+
sessionKey: string;
|
|
84
|
+
source: OfflineUploadSource;
|
|
85
|
+
state: OfflineUploadState;
|
|
86
|
+
fileName: string;
|
|
87
|
+
mimeType: string;
|
|
88
|
+
sizeBytes: number;
|
|
89
|
+
createdAt: number;
|
|
90
|
+
updatedAt: number;
|
|
91
|
+
resolvedRef?: TResolvedRef;
|
|
92
|
+
progress?: OfflineUploadProgress;
|
|
93
|
+
lastError?: {
|
|
94
|
+
message: string;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
type OfflineStoredUploadRecord<TResolvedRef extends ValidPayload = ValidPayload> = OfflineUpload<TResolvedRef> & {
|
|
98
|
+
file: File;
|
|
99
|
+
lastOnlineSessionStartedAt?: number;
|
|
100
|
+
lastModified: number;
|
|
101
|
+
};
|
|
102
|
+
type OfflineUploadAdapter = {
|
|
103
|
+
save<TResolvedRef extends ValidPayload>(sessionKey: string, id: string, record: OfflineStoredUploadRecord<TResolvedRef>): Promise<void>;
|
|
104
|
+
load<TResolvedRef extends ValidPayload>(sessionKey: string, id: string): Promise<OfflineStoredUploadRecord<TResolvedRef> | null>;
|
|
105
|
+
list<TResolvedRef extends ValidPayload>(sessionKey: string): Promise<OfflineStoredUploadRecord<TResolvedRef>[]>;
|
|
106
|
+
remove(sessionKey: string, id: string): Promise<void>;
|
|
107
|
+
clearSession(sessionKey: string): Promise<void>;
|
|
108
|
+
resetForTests?(): void;
|
|
109
|
+
};
|
|
110
|
+
type OfflineUploadTransportContext = {
|
|
111
|
+
id: string;
|
|
112
|
+
sessionKey: string;
|
|
113
|
+
file: File;
|
|
114
|
+
onProgress: (progress: OfflineUploadProgress) => void;
|
|
115
|
+
};
|
|
116
|
+
type OfflineSessionUploadsConfig<TResolvedRef extends ValidPayload = ValidPayload> = {
|
|
117
|
+
adapter: OfflineUploadAdapter;
|
|
118
|
+
upload: (ctx: OfflineUploadTransportContext) => Promise<TResolvedRef>;
|
|
119
|
+
concurrency?: number;
|
|
120
|
+
};
|
|
121
|
+
type OfflineMutationUploadsInput = Record<string, Blob | File>;
|
|
122
|
+
type OfflineAttachedUploadIds = Record<string, string>;
|
|
123
|
+
type OfflineOperationUploadsContext<TResolvedRef extends ValidPayload = ValidPayload> = {
|
|
124
|
+
filesById: Record<string, File>;
|
|
125
|
+
resolvedRefsById: Record<string, TResolvedRef>;
|
|
126
|
+
};
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/persistentStorage/types.d.ts
|
|
129
|
+
type AsyncStorageNamespaceKind = 'document' | 'collection.item' | 'listQuery.item' | 'listQuery.query' | 'offline.queue' | 'offline.conflict' | 'offline.entity' | '__internal.protected';
|
|
130
|
+
type AsyncStorageNamespaceScope = {
|
|
131
|
+
sessionKey: string;
|
|
132
|
+
storeName: string;
|
|
133
|
+
kind: AsyncStorageNamespaceKind;
|
|
134
|
+
};
|
|
135
|
+
type AsyncStorageTouchMode = 'never' | 'coarse' | 'force';
|
|
136
|
+
type AsyncStorageReadOptions = {
|
|
137
|
+
touch?: AsyncStorageTouchMode;
|
|
138
|
+
};
|
|
139
|
+
type AsyncStorageMetadataOrder = 'key' | 'lru-asc' | 'lru-desc';
|
|
140
|
+
type AsyncStorageEntryMetadataBase = {
|
|
141
|
+
key: string;
|
|
142
|
+
payloadRef: string;
|
|
143
|
+
writtenAt: number;
|
|
144
|
+
lastAccessAt: number; /** Serialized JSON size used for persistence budgeting for this entry. */
|
|
145
|
+
sizeBytes?: number;
|
|
146
|
+
version: number;
|
|
147
|
+
};
|
|
148
|
+
type AsyncStorageEntryMetadata<TCustomMetadata extends Record<string, unknown> = Record<string, unknown>> = AsyncStorageEntryMetadataBase & {
|
|
149
|
+
customMetadata: TCustomMetadata;
|
|
150
|
+
};
|
|
151
|
+
type AsyncStorageNamespaceGetResult<TValue, TCustomMetadata extends Record<string, unknown> = Record<string, unknown>> = {
|
|
152
|
+
value: TValue;
|
|
153
|
+
metadata: AsyncStorageEntryMetadata<TCustomMetadata>;
|
|
154
|
+
};
|
|
155
|
+
type AsyncStorageNamespaceCommitUpsert<TValue, TCustomMetadata extends Record<string, unknown> = Record<string, unknown>> = {
|
|
156
|
+
key: string;
|
|
157
|
+
value: TValue;
|
|
158
|
+
serializedValue?: string;
|
|
159
|
+
sizeBytes?: number;
|
|
160
|
+
version: number;
|
|
161
|
+
metadata?: TCustomMetadata;
|
|
162
|
+
};
|
|
163
|
+
type AsyncStorageNamespaceCommitTouch = {
|
|
164
|
+
key: string;
|
|
165
|
+
lastAccessAt?: number;
|
|
166
|
+
};
|
|
167
|
+
type AsyncStorageNamespaceStaticPolicy = {
|
|
168
|
+
maxBytes?: number;
|
|
169
|
+
pinnedKeys?: string[];
|
|
170
|
+
};
|
|
171
|
+
type AsyncStorageNamespaceCommitArgs<TValue, TCustomMetadata extends Record<string, unknown> = Record<string, unknown>> = {
|
|
172
|
+
upserts?: AsyncStorageNamespaceCommitUpsert<TValue, TCustomMetadata>[];
|
|
173
|
+
removes?: string[];
|
|
174
|
+
staticPolicy?: AsyncStorageNamespaceStaticPolicy | null;
|
|
175
|
+
touches?: AsyncStorageNamespaceCommitTouch[];
|
|
176
|
+
};
|
|
177
|
+
type AsyncStorageDriverSetEntry = {
|
|
178
|
+
key: string;
|
|
179
|
+
value: unknown;
|
|
180
|
+
serializedValue?: string;
|
|
181
|
+
sizeBytes?: number;
|
|
182
|
+
};
|
|
183
|
+
type AsyncStorageDiscoveredScope = {
|
|
184
|
+
/** Known raw record keys for this scope. `null` if keys were not enumerated during discovery. */knownRecordKeys: string[] | null;
|
|
185
|
+
scope: AsyncStorageNamespaceScope;
|
|
186
|
+
};
|
|
187
|
+
/** Low-level async backend contract implemented by custom storage drivers. */
|
|
188
|
+
type AsyncStorageDriver = {
|
|
189
|
+
/** Read a single raw record from a logical namespace. */get(scope: AsyncStorageNamespaceScope, key: string): Promise<unknown>; /** Write a single raw record to a logical namespace. */
|
|
190
|
+
set(scope: AsyncStorageNamespaceScope, key: string, value: unknown): Promise<void>; /** Remove a single raw record from a logical namespace. */
|
|
191
|
+
remove(scope: AsyncStorageNamespaceScope, key: string): Promise<void>; /** List raw record keys within a logical namespace. */
|
|
192
|
+
listKeys(scope: AsyncStorageNamespaceScope): Promise<string[]>; /** Remove every record from a logical namespace. */
|
|
193
|
+
clear(scope: AsyncStorageNamespaceScope): Promise<void>; /** Namespace discovery used for cold cleanup, protected-key restore, and session clearing. */
|
|
194
|
+
listScopes(sessionKey?: string): Promise<AsyncStorageNamespaceScope[]>; /** Returns discovered scopes together with known raw record keys. Used for cleanup. */
|
|
195
|
+
listScopesWithKnownRecordKeys(sessionKey?: string): Promise<AsyncStorageDiscoveredScope[]>; /** Bulk read for multiple keys in a single call. */
|
|
196
|
+
getMany(scope: AsyncStorageNamespaceScope, keys: string[]): Promise<unknown[]>; /** Bulk write for multiple entries in a single call. */
|
|
197
|
+
setMany(scope: AsyncStorageNamespaceScope, entries: AsyncStorageDriverSetEntry[]): Promise<void>; /** Bulk remove for multiple keys in a single call. */
|
|
198
|
+
removeMany(scope: AsyncStorageNamespaceScope, keys: string[]): Promise<void>;
|
|
199
|
+
};
|
|
200
|
+
type AsyncStorageNamespaceHandle<TValue, TCustomMetadata extends Record<string, unknown> = Record<string, unknown>> = {
|
|
201
|
+
get(key: string, options?: AsyncStorageReadOptions): Promise<AsyncStorageNamespaceGetResult<TValue, TCustomMetadata> | null>;
|
|
202
|
+
getMany(keys: string[], options?: AsyncStorageReadOptions): Promise<Array<AsyncStorageNamespaceGetResult<TValue, TCustomMetadata> | null>>;
|
|
203
|
+
listKeys(): Promise<string[]>;
|
|
204
|
+
commit(args: AsyncStorageNamespaceCommitArgs<TValue, TCustomMetadata>): Promise<void>;
|
|
205
|
+
listMetadata(args?: {
|
|
206
|
+
order?: AsyncStorageMetadataOrder;
|
|
207
|
+
}): Promise<AsyncStorageEntryMetadata<TCustomMetadata>[]>;
|
|
208
|
+
listMetadataByFilter?(args: {
|
|
209
|
+
filter: {
|
|
210
|
+
equals: unknown;
|
|
211
|
+
key: string;
|
|
212
|
+
};
|
|
213
|
+
order?: AsyncStorageMetadataOrder;
|
|
214
|
+
}): Promise<AsyncStorageEntryMetadata<TCustomMetadata>[]>;
|
|
215
|
+
clear(): Promise<void>;
|
|
216
|
+
};
|
|
217
|
+
/** Managed async adapter consumed by TSDF persistence internals. */
|
|
218
|
+
type AsyncStorageAdapter = {
|
|
219
|
+
/** Adapter mode marker used by persistence internals to pick async behavior. */kind: 'async'; /** Open a logical namespace with managed batching and touch guarantees. */
|
|
220
|
+
openNamespace<TValue, TCustomMetadata extends Record<string, unknown> = Record<string, unknown>>(scope: AsyncStorageNamespaceScope): AsyncStorageNamespaceHandle<TValue, TCustomMetadata>; /** Reconstruct offline-protected entry refs for a session from persisted metadata. */
|
|
221
|
+
readProtectedStorageKeys(sessionKey: string): Promise<Set<string>>; /** Eagerly sync offline protection changes into persisted metadata for already-cached entries. */
|
|
222
|
+
syncSessionProtectedKeys(sessionKey: string, protectedKeys: Iterable<string>, previousProtectedKeys?: Iterable<string>): Promise<void>; /** Remove all namespaces for a session key. */
|
|
223
|
+
clearSession(sessionKey: string): Promise<void>; /** Test-only reset hook used by TSDF internals. */
|
|
224
|
+
resetForTests?(): void;
|
|
225
|
+
};
|
|
226
|
+
/** Injected persistent storage adapter. */
|
|
227
|
+
type StorageAdapter = 'local-sync' | AsyncStorageAdapter;
|
|
228
|
+
/** Standard Schema v1 (zod, valibot, arktype, etc.). */
|
|
229
|
+
type StandardSchemaLike<T> = StandardSchemaV1<unknown, T>;
|
|
230
|
+
/** Union of supported schema types for persistent storage validation. */
|
|
231
|
+
type PersistentStorageSchema<T> = RcType<T> | StandardSchemaLike<T>;
|
|
232
|
+
/**
|
|
233
|
+
* Converts between the in-memory store data shape and the persisted storage shape.
|
|
234
|
+
* Use this when the cached representation should differ from the API store format.
|
|
235
|
+
*/
|
|
236
|
+
type ConvertedPersistentStorageDataSchema<TFinal, TStorage> = {
|
|
237
|
+
/** Schema for the final in-memory store data after hydration. */storeSchema: PersistentStorageSchema<TFinal>; /** Schema for the raw persisted storage representation. */
|
|
238
|
+
storageSchema: PersistentStorageSchema<TStorage>; /** Converts in-memory store data into the persisted storage representation. */
|
|
239
|
+
convertToStorage: (value: TFinal) => TStorage; /** Converts persisted storage data into the final in-memory store representation. */
|
|
240
|
+
convertFromStorage: (value: TStorage) => TFinal;
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Schema configuration for persisted store data.
|
|
244
|
+
* Accept either the final store schema directly or a converted storage format.
|
|
245
|
+
*/
|
|
246
|
+
type PersistentStorageDataSchema<TFinal, TStorage = unknown> = PersistentStorageSchema<TFinal> | ConvertedPersistentStorageDataSchema<TFinal, TStorage>;
|
|
247
|
+
/** Result entry returned by explicit persistent-storage preload APIs. */
|
|
248
|
+
type PersistentStoragePreloadResult<Payload extends ValidPayload = ValidPayload> = {
|
|
249
|
+
/** Payload loaded from storage or fresh store initialization result. */payload: Payload; /** `true` when payload came from storage cache, `false` when loaded from source. */
|
|
250
|
+
preloaded: boolean;
|
|
251
|
+
};
|
|
252
|
+
type PersistentStorageErrorHandler = (error: unknown) => void;
|
|
253
|
+
/** Base config shared by all store types. */
|
|
254
|
+
type PersistentStorageBaseConfig<TFinal, TStorage = unknown> = {
|
|
255
|
+
/** Unique storage namespace used internally for this store's persisted entries. Must not contain `.`. */storeName: string; /** Injected adapter used to save and restore persistent data. Use `'local-sync'` for built-in localStorage or provide a custom async adapter. */
|
|
256
|
+
adapter: StorageAdapter; /** Schema used to validate cached data on load and optionally convert persisted data. */
|
|
257
|
+
schema: PersistentStorageDataSchema<TFinal, TStorage>; /** Optional version number for cache invalidation. When omitted, no version is persisted or checked. */
|
|
258
|
+
version?: number;
|
|
259
|
+
/**
|
|
260
|
+
* Returns a session key scoping storage per org/tenant.
|
|
261
|
+
* Return `false` to indicate the session is not ready — all storage
|
|
262
|
+
* operations (load, save, clear) will be skipped until it returns a string.
|
|
263
|
+
*/
|
|
264
|
+
getSessionKey: () => string | false;
|
|
265
|
+
/**
|
|
266
|
+
* Called when a storage write operation fails (e.g. quota exceeded, OPFS write error).
|
|
267
|
+
* Use this to log or report persistence failures to your error tracking service.
|
|
268
|
+
*/
|
|
269
|
+
onPersistentStorageError?: PersistentStorageErrorHandler;
|
|
270
|
+
};
|
|
271
|
+
/** Store-level persistent storage config. Session scoping comes from the parent store. */
|
|
272
|
+
type StorePersistentStorageBaseConfig<TFinal, TStorage = unknown> = Omit<PersistentStorageBaseConfig<TFinal, TStorage>, 'getSessionKey' | 'storeName'>;
|
|
273
|
+
type InternalDocumentOfflineOperations$1<State extends ValidStoreState> = Record<string, AnyOfflineOperationDefinition<__LEGIT_ANY__>> & ([State] extends [never] ? never : unknown);
|
|
274
|
+
type DocumentOfflineOperationsConfig$1<State extends ValidStoreState> = InternalDocumentOfflineOperations$1<State> | null;
|
|
275
|
+
type PublicStoreOfflineConfig<TOperations extends Record<string, AnyOfflineOperationDefinition<__LEGIT_ANY__>> = Record<never, never>> = {
|
|
276
|
+
/** Store-local offline operation definitions. Optional when only session-level offline controls are used. */operations?: TOperations;
|
|
277
|
+
};
|
|
278
|
+
type PublicStoreOfflineConfigField<TOfflineOperations extends Record<string, AnyOfflineOperationDefinition<__LEGIT_ANY__>> | null> = {
|
|
279
|
+
/** Optional offline sync/replay configuration for mutations. */offline?: TOfflineOperations extends null ? PublicStoreOfflineConfig : PublicStoreOfflineConfig<Exclude<TOfflineOperations, null>>;
|
|
280
|
+
};
|
|
281
|
+
/** Persistent storage config for DocumentStore. */
|
|
282
|
+
type DocumentPersistentStorageConfig<State extends ValidStoreState, StorageState = unknown, TOfflineOperations extends DocumentOfflineOperationsConfig$1<State> = null> = StorePersistentStorageBaseConfig<State, StorageState> & PublicStoreOfflineConfigField<TOfflineOperations>;
|
|
283
|
+
type InternalCollectionOfflineOperations$1<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = Record<string, AnyOfflineOperationDefinition<__LEGIT_ANY__> & {
|
|
284
|
+
getEntityRefs: (ctx: {
|
|
285
|
+
input: __LEGIT_ANY__;
|
|
286
|
+
}) => CollectionOfflineEntityRef<ItemPayload>[];
|
|
287
|
+
dependsOn?: (ctx: {
|
|
288
|
+
input: __LEGIT_ANY__;
|
|
289
|
+
}) => CollectionOfflineEntityRef<ItemPayload>[];
|
|
290
|
+
}> & ([ItemState | ItemPayload] extends [never] ? never : unknown);
|
|
291
|
+
type CollectionOfflineOperationsConfig$1<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = InternalCollectionOfflineOperations$1<ItemState, ItemPayload> | null;
|
|
292
|
+
type CollectionPersistentStorageFields<ItemPayload extends ValidPayload> = {
|
|
293
|
+
/** Schema used to validate cached item payloads on load. */payloadSchema: PersistentStorageSchema<ItemPayload>;
|
|
294
|
+
/**
|
|
295
|
+
* Maximum serialized JSON size to persist for collection items. Budgeting
|
|
296
|
+
* uses the serialized string length, not browser quota bytes. Items are
|
|
297
|
+
* evicted via LRU. Defaults to 64 KB in `local-sync` and 128 KB in async
|
|
298
|
+
* adapters.
|
|
299
|
+
*/
|
|
300
|
+
maxBytes?: number; /** Item payloads that should never be evicted from storage. */
|
|
301
|
+
pinnedItems?: ItemPayload[];
|
|
302
|
+
/**
|
|
303
|
+
* Item payloads that should never be persisted or restored.
|
|
304
|
+
* Accepts either an explicit payload list or a predicate function.
|
|
305
|
+
* Takes precedence over `pinnedItems`.
|
|
306
|
+
*/
|
|
307
|
+
ignoreItems?: ItemPayload[] | ((payload: ItemPayload) => boolean);
|
|
308
|
+
};
|
|
309
|
+
/** Persistent storage config for CollectionStore. */
|
|
310
|
+
type CollectionPersistentStorageConfig<ItemState extends ValidStoreState, ItemPayload extends ValidPayload = ValidPayload, StorageState = unknown, TOfflineOperations extends CollectionOfflineOperationsConfig$1<ItemState, ItemPayload> = null> = StorePersistentStorageBaseConfig<ItemState, StorageState> & PublicStoreOfflineConfigField<TOfflineOperations> & CollectionPersistentStorageFields<ItemPayload>;
|
|
311
|
+
type InternalListQueryOfflineOperations<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = Record<string, AnyOfflineOperationDefinition<__LEGIT_ANY__> & {
|
|
312
|
+
getEntityRefs: (ctx: {
|
|
313
|
+
input: __LEGIT_ANY__;
|
|
314
|
+
}) => ListQueryOfflineEntityRef<ItemPayload>[];
|
|
315
|
+
dependsOn?: (ctx: {
|
|
316
|
+
input: __LEGIT_ANY__;
|
|
317
|
+
}) => ListQueryOfflineEntityRef<ItemPayload>[];
|
|
318
|
+
}> & ([ItemState | QueryPayload | ItemPayload] extends [never] ? never : unknown);
|
|
319
|
+
type ListQueryOfflineOperationsConfig<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = InternalListQueryOfflineOperations<ItemState, QueryPayload, ItemPayload> | null;
|
|
320
|
+
type ListQueryPersistentStorageFields<QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = {
|
|
321
|
+
/** Schema used to validate cached item payloads on load. */itemPayloadSchema: PersistentStorageSchema<ItemPayload>; /** Schema used to validate cached query payloads on load. */
|
|
322
|
+
queryPayloadSchema: PersistentStorageSchema<QueryPayload>;
|
|
323
|
+
/**
|
|
324
|
+
* Maximum serialized JSON size to persist for list items. Budgeting uses the
|
|
325
|
+
* serialized string length, not browser quota bytes. Defaults to 64 KB in
|
|
326
|
+
* `local-sync` and 128 KB in async adapters.
|
|
327
|
+
*/
|
|
328
|
+
maxItemBytes?: number;
|
|
329
|
+
/**
|
|
330
|
+
* Maximum serialized JSON size to persist for list queries. Budgeting uses
|
|
331
|
+
* the serialized string length, not browser quota bytes. Defaults to 32 KB
|
|
332
|
+
* in `local-sync` and 64 KB in async adapters.
|
|
333
|
+
*/
|
|
334
|
+
maxQueryBytes?: number; /** Maximum number of items per query to persist. Defaults to 100. */
|
|
335
|
+
maxQuerySize?: number; /** Item payloads that should never be evicted from storage. */
|
|
336
|
+
pinnedItems?: ItemPayload[]; /** Query payloads that should never be evicted from storage. */
|
|
337
|
+
pinnedQueries?: QueryPayload[];
|
|
338
|
+
/**
|
|
339
|
+
* Item payloads that should never be persisted or restored.
|
|
340
|
+
* Accepts either an explicit payload list or a predicate function.
|
|
341
|
+
* Takes precedence over `pinnedItems`.
|
|
342
|
+
*/
|
|
343
|
+
ignoreItems?: ItemPayload[] | ((payload: ItemPayload) => boolean);
|
|
344
|
+
};
|
|
345
|
+
/** Persistent storage config for ListQueryStore. */
|
|
346
|
+
type ListQueryPersistentStorageConfig<ItemState extends ValidStoreState, QueryPayload extends ValidPayload = ValidPayload, ItemPayload extends ValidPayload = ValidPayload, StorageState = unknown, TOfflineOperations extends ListQueryOfflineOperationsConfig<ItemState, QueryPayload, ItemPayload> = null> = StorePersistentStorageBaseConfig<ItemState, StorageState> & PublicStoreOfflineConfigField<TOfflineOperations> & ListQueryPersistentStorageFields<QueryPayload, ItemPayload>;
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/persistentStorage/validateWithSchema.d.ts
|
|
349
|
+
type SchemaValidationError = readonly string[] | StandardSchemaV1.FailureResult['issues'];
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/persistentStorage/offline/types.d.ts
|
|
352
|
+
/** Store kinds supported by offline replay and sync state tracking. */
|
|
353
|
+
type OfflineStoreType = 'document' | 'collection' | 'listQuery';
|
|
354
|
+
/** Phase where a failure occurred during offline-enabled operation flow. */
|
|
355
|
+
type OfflineFailurePhase = 'fetch' | 'mutation' | 'sync';
|
|
356
|
+
/** High-level classification used by outage detection. */
|
|
357
|
+
type OfflineFailureClassification = 'outage' | 'network' | 'ignore';
|
|
358
|
+
/** Kinds of entities participating in offline conflict/sync tracking. */
|
|
359
|
+
type OfflineEntityKind = 'document' | 'item' | 'query';
|
|
360
|
+
/** Lifecycle declared per offline operation definition. */
|
|
361
|
+
type OfflineOperationKind = 'create' | 'update' | 'delete';
|
|
362
|
+
/** Effective lifecycle derived for an offline entity across queued work. */
|
|
363
|
+
type OfflineEntityMutationKind = 'create' | 'createAndUpdate' | 'update' | 'delete';
|
|
364
|
+
/** Connectivity cause currently governing offline mutation queueing. */
|
|
365
|
+
type OfflineMutationQueueingCause = 'network' | 'outage';
|
|
366
|
+
/** Root policy value for whether offline-enabled mutations may queue. */
|
|
367
|
+
type OfflineMutationQueueingPolicy = 'allow' | 'disallow';
|
|
368
|
+
/** Root mutation queueing policy shared by all configured offline operations. */
|
|
369
|
+
type OfflineMutationQueueingConfig = {
|
|
370
|
+
/**
|
|
371
|
+
* Controls whether offline-enabled mutations may queue while network mode is
|
|
372
|
+
* active, including browser-detected offline and classified network failures.
|
|
373
|
+
* @default 'allow'
|
|
374
|
+
*/
|
|
375
|
+
network?: OfflineMutationQueueingPolicy;
|
|
376
|
+
/**
|
|
377
|
+
* Controls whether offline-enabled mutations may queue while outage mode is
|
|
378
|
+
* active.
|
|
379
|
+
* @default 'allow'
|
|
380
|
+
*/
|
|
381
|
+
outage?: OfflineMutationQueueingPolicy;
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* Effective runtime offline controls exposed through an offline session.
|
|
385
|
+
*
|
|
386
|
+
* All fields are session-scoped and affect every store attached to the same
|
|
387
|
+
* offline session.
|
|
388
|
+
*/
|
|
389
|
+
type OfflineRuntimeConfig = {
|
|
390
|
+
/** Whether future operations may enter network offline handling. */network: {
|
|
391
|
+
enabled: boolean;
|
|
392
|
+
}; /** Whether future operations may enter outage offline handling. */
|
|
393
|
+
outage: {
|
|
394
|
+
enabled: boolean;
|
|
395
|
+
}; /** Effective queue admission policy for offline-enabled mutations. */
|
|
396
|
+
mutationQueueing: {
|
|
397
|
+
network: OfflineMutationQueueingPolicy;
|
|
398
|
+
outage: OfflineMutationQueueingPolicy;
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
/** Default runtime config when offline is not configured or no session exists. */
|
|
402
|
+
declare const defaultOfflineRuntimeConfig: OfflineRuntimeConfig;
|
|
403
|
+
/**
|
|
404
|
+
* Partial runtime offline control update accepted by an offline session.
|
|
405
|
+
*
|
|
406
|
+
* Provided fields shallow-merge into the current runtime config.
|
|
407
|
+
*/
|
|
408
|
+
type OfflineRuntimeConfigUpdate = {
|
|
409
|
+
/** Optional session-scoped update for network mode enablement. */network?: {
|
|
410
|
+
enabled?: boolean;
|
|
411
|
+
}; /** Optional session-scoped update for outage mode enablement. */
|
|
412
|
+
outage?: {
|
|
413
|
+
enabled?: boolean;
|
|
414
|
+
}; /** Optional session-scoped update for offline mutation queue admission policy. */
|
|
415
|
+
mutationQueueing?: {
|
|
416
|
+
network?: OfflineMutationQueueingPolicy;
|
|
417
|
+
outage?: OfflineMutationQueueingPolicy;
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
/** Context passed into offline failure classification hooks. */
|
|
421
|
+
type OfflineFailureContext = {
|
|
422
|
+
/** Phase in which the failure was detected. */phase: OfflineFailurePhase; /** Store type affected by the failure. */
|
|
423
|
+
storeType: OfflineStoreType; /** Optional operation name associated with the failure. */
|
|
424
|
+
operationName?: string; /** Session key used by browser tab and persistence scoping. */
|
|
425
|
+
sessionKey: string;
|
|
426
|
+
};
|
|
427
|
+
/** Re-check strategy for recovery probing. Omitted fields use built-in defaults (which differ between network and outage modes). */
|
|
428
|
+
type OfflineRecoveryProbeConfig = {
|
|
429
|
+
/**
|
|
430
|
+
* Initial recovery check delay, in milliseconds.
|
|
431
|
+
* @default 5_000 (network) / 30_000 (outage)
|
|
432
|
+
*/
|
|
433
|
+
initialIntervalMs?: number;
|
|
434
|
+
/**
|
|
435
|
+
* Maximum recovery check delay, in milliseconds.
|
|
436
|
+
* @default 60_000 (network) / 300_000 (outage)
|
|
437
|
+
*/
|
|
438
|
+
maxIntervalMs?: number;
|
|
439
|
+
/**
|
|
440
|
+
* Multiplicative backoff between recovery probes.
|
|
441
|
+
* @default 2
|
|
442
|
+
*/
|
|
443
|
+
backoffMultiplier?: number;
|
|
444
|
+
/**
|
|
445
|
+
* Jitter ratio (0-1) applied to the recovery probe delay.
|
|
446
|
+
* @default 0.2
|
|
447
|
+
*/
|
|
448
|
+
jitterRatio?: number;
|
|
449
|
+
};
|
|
450
|
+
/** Network availability mode configuration for offline controls. */
|
|
451
|
+
type OfflineNetworkModeConfig = {
|
|
452
|
+
/** Enable network connectivity detection and tracking. */enabled: boolean;
|
|
453
|
+
/**
|
|
454
|
+
* If true, subscribe to browser `online` / `offline` events.
|
|
455
|
+
* @default true
|
|
456
|
+
*/
|
|
457
|
+
listenToBrowserEvents?: boolean;
|
|
458
|
+
/**
|
|
459
|
+
* Optional override for network connectivity checks.
|
|
460
|
+
* Return `true` when network should be considered offline.
|
|
461
|
+
*/
|
|
462
|
+
getIsOffline?: () => boolean | Promise<boolean>;
|
|
463
|
+
/**
|
|
464
|
+
* Probe whether classified network recovery has completed.
|
|
465
|
+
* Return `true` when the session should leave network offline mode.
|
|
466
|
+
*/
|
|
467
|
+
recoveryCheck?: (ctx: {
|
|
468
|
+
sessionKey: string;
|
|
469
|
+
}) => Promise<boolean> | boolean; /** Optional probe config to tune classified network recovery behavior. */
|
|
470
|
+
recoveryProbe?: OfflineRecoveryProbeConfig;
|
|
471
|
+
};
|
|
472
|
+
/** Server outage detection and recovery configuration. */
|
|
473
|
+
type OfflineOutageModeConfig = {
|
|
474
|
+
/** Enable outage mode logic and confirmation retry flow. */enabled: boolean; /** Probe the remote service to confirm outage recovery. */
|
|
475
|
+
recoveryCheck: (ctx: {
|
|
476
|
+
sessionKey: string;
|
|
477
|
+
}) => Promise<boolean> | boolean; /** Optional probe config to tune recovery behavior. */
|
|
478
|
+
recoveryProbe?: OfflineRecoveryProbeConfig;
|
|
479
|
+
};
|
|
480
|
+
/** Fixed replay retry policy for healthy online replay failures. Omitted fields use built-in defaults. */
|
|
481
|
+
type OfflineReplayRetryConfig = {
|
|
482
|
+
/**
|
|
483
|
+
* Max counted failures before manual resolution is required.
|
|
484
|
+
* @default 3
|
|
485
|
+
*/
|
|
486
|
+
maxFailures?: number;
|
|
487
|
+
/**
|
|
488
|
+
* Fixed delay between replay retries, in milliseconds.
|
|
489
|
+
* @default 5000
|
|
490
|
+
*/
|
|
491
|
+
intervalMs?: number;
|
|
492
|
+
};
|
|
493
|
+
/** Shared offline/session policy reused by every store in the same session. */
|
|
494
|
+
type OfflineSessionConfig<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
495
|
+
/**
|
|
496
|
+
* Classify a remote failure as `outage`, `network`, or `ignore`.
|
|
497
|
+
* `outage` activates outage recovery behavior.
|
|
498
|
+
* `network` activates network offline handling for future operations only
|
|
499
|
+
* when `network.enabled` is true. Existing offline recovery may keep using
|
|
500
|
+
* classifications until already-active work finishes recovering.
|
|
501
|
+
*/
|
|
502
|
+
classifyFailure?: (error: unknown, ctx: OfflineFailureContext) => Promise<OfflineFailureClassification> | OfflineFailureClassification;
|
|
503
|
+
/**
|
|
504
|
+
* Optional replay-only classifier for ambiguous sync failures that stayed
|
|
505
|
+
* online (`classifyFailure(...) === 'ignore'`).
|
|
506
|
+
*
|
|
507
|
+
* Return `true` only when automatically re-sending the replayed mutation is
|
|
508
|
+
* known to be safe. Return `false` to avoid auto-replay retries; in that
|
|
509
|
+
* case the entry still enters `needs-confirmation` so `shouldSkipSync` /
|
|
510
|
+
* conflict checks can run before the mutation is promoted to manual
|
|
511
|
+
* resolution.
|
|
512
|
+
*/
|
|
513
|
+
classifyRetryableFailure?: (error: unknown, ctx: OfflineFailureContext) => Promise<boolean> | boolean; /** Network detection strategy and browser integration. */
|
|
514
|
+
network?: OfflineNetworkModeConfig; /** Outage detection and recovery strategy for remote failures. */
|
|
515
|
+
outage?: OfflineOutageModeConfig; /** Fixed retry policy for healthy online replay failures. */
|
|
516
|
+
replayRetry?: OfflineReplayRetryConfig;
|
|
517
|
+
/**
|
|
518
|
+
* Root policy controlling whether offline-enabled mutations may enter the
|
|
519
|
+
* durable offline queue for each active offline cause.
|
|
520
|
+
* @default undefined
|
|
521
|
+
*/
|
|
522
|
+
mutationQueueing?: OfflineMutationQueueingConfig; /** Optional upload transport/storage config shared by the whole session. */
|
|
523
|
+
uploads?: OfflineSessionUploadsConfig<TUploadRef>;
|
|
524
|
+
};
|
|
525
|
+
/** Per-session offline status snapshot shared across tabs. */
|
|
526
|
+
type GlobalOfflineStatus = {
|
|
527
|
+
/** Session key for this status bucket. */sessionKey: string;
|
|
528
|
+
/**
|
|
529
|
+
* Network mode admission enablement plus the last observed network-offline
|
|
530
|
+
* state for this session. `active` is preserved even while new admission is
|
|
531
|
+
* disabled so existing offline work can recover and sync safely.
|
|
532
|
+
*/
|
|
533
|
+
network: {
|
|
534
|
+
enabled: boolean;
|
|
535
|
+
active: boolean;
|
|
536
|
+
};
|
|
537
|
+
/**
|
|
538
|
+
* Outage mode admission enablement plus the last observed outage-active
|
|
539
|
+
* state for this session. `active` is preserved even while new admission is
|
|
540
|
+
* disabled so existing offline work can recover and sync safely.
|
|
541
|
+
*/
|
|
542
|
+
outage: {
|
|
543
|
+
enabled: boolean;
|
|
544
|
+
active: boolean;
|
|
545
|
+
}; /** Whether the session currently has any active offline cause. */
|
|
546
|
+
isOfflineMode: boolean; /** Whether this tab currently acts as leader for this session. */
|
|
547
|
+
isLeader: boolean; /** Timestamp when this status entry was last updated. */
|
|
548
|
+
updatedAt: number; /** Timestamp of the last failure, if any. */
|
|
549
|
+
lastFailureAt: number | null; /** Timestamp of last recovery probe execution, if any. */
|
|
550
|
+
lastRecoveryCheckAt: number | null;
|
|
551
|
+
};
|
|
552
|
+
/** Queue state of an offline mutation entry. */
|
|
553
|
+
type OfflineSyncState = 'pending' | 'syncing' | 'needs-confirmation';
|
|
554
|
+
/** Aggregated offline status for a tracked document/item/query entity. */
|
|
555
|
+
type GlobalOfflineEntity = {
|
|
556
|
+
/** Internal entity identifier tracked by offline machinery. */id: string; /** Session key for this offline entity. */
|
|
557
|
+
sessionKey: string; /** Store name where the entity is defined. */
|
|
558
|
+
storeName: string; /** Store type this entity belongs to. */
|
|
559
|
+
storeType: OfflineStoreType; /** Entity key used for deduping and conflict scoping. */
|
|
560
|
+
entityKey: string; /** Entity kind used in queue partitioning. */
|
|
561
|
+
entityKind: OfflineEntityKind; /** Effective lifecycle derived from queued operations targeting this entity. */
|
|
562
|
+
kind: OfflineEntityMutationKind; /** Number of pending mutations waiting for sync. */
|
|
563
|
+
pendingMutations: number; /** Current sync state for the entity. */
|
|
564
|
+
syncState: OfflineSyncState | 'resolution-required'; /** Whether the entity currently requires manual resolution. */
|
|
565
|
+
requiresResolution: boolean; /** Resolution ids currently blocking this entity from being resolved/applied. */
|
|
566
|
+
blockedByResolutionIds: string[]; /** Child resolution ids currently derived from this entity's dependency chain. */
|
|
567
|
+
childResolutionIds: string[]; /** Number of blocking parent resolutions currently affecting this entity. */
|
|
568
|
+
blockedResolutionCount: number; /** Number of child resolutions currently derived from this entity's dependency chain. */
|
|
569
|
+
childResolutionCount: number; /** Creation timestamp for lifecycle bookkeeping. */
|
|
570
|
+
createdAt: number; /** Last mutation/update timestamp. */
|
|
571
|
+
updatedAt: number; /** Optional temporary ID for optimistic create flows. */
|
|
572
|
+
tempId?: ValidPayload;
|
|
573
|
+
};
|
|
574
|
+
/** Reference to an entity participating in offline sync tracking. */
|
|
575
|
+
type OfflineEntityRef = {
|
|
576
|
+
entityKey: string;
|
|
577
|
+
entityKind: OfflineEntityKind;
|
|
578
|
+
};
|
|
579
|
+
/**
|
|
580
|
+
* Persisted offline conflict payload.
|
|
581
|
+
*
|
|
582
|
+
* @typeParam TConflict - Conflict payload stored for later resolution.
|
|
583
|
+
* @typeParam TInput - Original mutation input associated with the conflict.
|
|
584
|
+
*/
|
|
585
|
+
type OfflineConflictResolutionRecordBase<TConflict = unknown, TInput = unknown> = {
|
|
586
|
+
/** Resolution record identifier. */id: string; /** Resolution kind. */
|
|
587
|
+
kind: 'conflict'; /** Queue entry identifier that produced this conflict. */
|
|
588
|
+
entryId: string; /** Session key that owns this conflict record. */
|
|
589
|
+
sessionKey: string; /** Store name associated with the conflict. */
|
|
590
|
+
storeName: string; /** Store type associated with the conflict. */
|
|
591
|
+
storeType: OfflineStoreType; /** Operation name linked to the conflict. */
|
|
592
|
+
operation: string; /** Input value that triggered the conflict. */
|
|
593
|
+
input: TInput; /** Conflict payload returned by the resolver. */
|
|
594
|
+
conflict: TConflict; /** Timestamp when the original queued mutation was enqueued. */
|
|
595
|
+
enqueuedAt: number; /** Entity references involved in the conflict. */
|
|
596
|
+
entityRefs: OfflineEntityRef[]; /** Conflict creation timestamp. */
|
|
597
|
+
createdAt: number; /** Conflict update timestamp. */
|
|
598
|
+
updatedAt: number; /** Optional temporary IDs associated with optimistic entity flow. */
|
|
599
|
+
tempIds?: ValidPayload[]; /** Maps original direct-upload keys to their persisted session upload ids. */
|
|
600
|
+
attachedUploadIds?: OfflineAttachedUploadIds; /** Session upload ids that must resolve before replaying the mutation. */
|
|
601
|
+
dependencyUploadIds?: string[];
|
|
602
|
+
};
|
|
603
|
+
/** Derived dependency metadata exposed for offline manual resolutions. */
|
|
604
|
+
type OfflineResolutionDependencyMetadata = {
|
|
605
|
+
/** Parent resolution ids that must be cleared before this resolution can be retried or discarded. */blockedByResolutionIds: string[]; /** Child manual resolutions currently derived from this resolution's dependency chain. */
|
|
606
|
+
childResolutionIds: string[]; /** Number of blocking parent resolutions affecting this resolution. */
|
|
607
|
+
blockedResolutionCount: number; /** Number of child manual resolutions currently derived from this resolution. */
|
|
608
|
+
childResolutionCount: number;
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* Persisted offline conflict payload with derived dependency metadata.
|
|
612
|
+
*
|
|
613
|
+
* @typeParam TConflict - Conflict payload stored for later resolution.
|
|
614
|
+
* @typeParam TInput - Original mutation input associated with the conflict.
|
|
615
|
+
*/
|
|
616
|
+
type OfflineConflictResolutionRecord<TConflict = unknown, TInput = unknown> = OfflineConflictResolutionRecordBase<TConflict, TInput> & OfflineResolutionDependencyMetadata;
|
|
617
|
+
/**
|
|
618
|
+
* Persisted resolution record created when replay retries are exhausted.
|
|
619
|
+
*
|
|
620
|
+
* @typeParam TInput - Original mutation input associated with the replay failure.
|
|
621
|
+
*/
|
|
622
|
+
type OfflineRetryExhaustedResolutionRecordBase<TInput = unknown> = {
|
|
623
|
+
/** Resolution record identifier. */id: string; /** Resolution kind. */
|
|
624
|
+
kind: 'retry-exhausted'; /** Queue entry identifier that exhausted replay retries. */
|
|
625
|
+
entryId: string; /** Session key that owns this resolution record. */
|
|
626
|
+
sessionKey: string; /** Store name associated with the resolution. */
|
|
627
|
+
storeName: string; /** Store type associated with the resolution. */
|
|
628
|
+
storeType: OfflineStoreType; /** Operation name linked to the replay failure. */
|
|
629
|
+
operation: string; /** Input value that exhausted replay retries. */
|
|
630
|
+
input: TInput; /** Timestamp when the original queued mutation was enqueued. */
|
|
631
|
+
enqueuedAt: number; /** Entity references involved in the resolution. */
|
|
632
|
+
entityRefs: OfflineEntityRef[]; /** Last replay error snapshot captured before exhaustion. */
|
|
633
|
+
lastReplayError: {
|
|
634
|
+
message: string;
|
|
635
|
+
}; /** Resolution creation timestamp. */
|
|
636
|
+
createdAt: number; /** Resolution update timestamp. */
|
|
637
|
+
updatedAt: number; /** Optional temporary IDs associated with optimistic entity flow. */
|
|
638
|
+
tempIds?: ValidPayload[]; /** Maps original direct-upload keys to their persisted session upload ids. */
|
|
639
|
+
attachedUploadIds?: OfflineAttachedUploadIds; /** Session upload ids that must resolve before replaying the mutation. */
|
|
640
|
+
dependencyUploadIds?: string[];
|
|
641
|
+
};
|
|
642
|
+
/**
|
|
643
|
+
* Persisted resolution record created when replay retries are exhausted, plus
|
|
644
|
+
* derived dependency metadata.
|
|
645
|
+
*
|
|
646
|
+
* @typeParam TInput - Original mutation input associated with the replay failure.
|
|
647
|
+
*/
|
|
648
|
+
type OfflineRetryExhaustedResolutionRecord<TInput = unknown> = OfflineRetryExhaustedResolutionRecordBase<TInput> & OfflineResolutionDependencyMetadata;
|
|
649
|
+
/**
|
|
650
|
+
* Persisted offline resolution payload.
|
|
651
|
+
*
|
|
652
|
+
* @typeParam TConflict - Conflict payload stored for later resolution.
|
|
653
|
+
* @typeParam TInput - Original mutation input associated with the resolution.
|
|
654
|
+
*/
|
|
655
|
+
type OfflineResolutionRecord<TConflict = unknown, TInput = unknown> = OfflineConflictResolutionRecord<TConflict, TInput> | OfflineRetryExhaustedResolutionRecord<TInput>;
|
|
656
|
+
/** Session-scoped offline controller shared across stores in the same session. */
|
|
657
|
+
type OfflineSession<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
658
|
+
/** Returns the active session key used to scope shared offline state. */getSessionKey: () => string | false; /** Shared static session configuration used by attached stores. */
|
|
659
|
+
getConfig: () => OfflineSessionConfig<TUploadRef>; /** Latest effective runtime config for this session. */
|
|
660
|
+
getOfflineRuntimeConfig: () => OfflineRuntimeConfig; /** Updates runtime controls for this session. */
|
|
661
|
+
setOfflineRuntimeConfig: (update: OfflineRuntimeConfigUpdate) => void; /** Resets runtime controls back to the static session config. */
|
|
662
|
+
resetOfflineRuntimeConfig: () => void; /** Returns the latest global offline status for the session. */
|
|
663
|
+
getOfflineStatus: () => GlobalOfflineStatus; /** Returns the latest aggregated offline entities for the session. */
|
|
664
|
+
getOfflineEntities: () => readonly GlobalOfflineEntity[]; /** Returns the latest aggregated conflict/retry resolutions for the session. */
|
|
665
|
+
getOfflineResolutions: () => readonly OfflineResolutionRecord[]; /** Returns the latest session-scoped offline uploads for the session. */
|
|
666
|
+
getOfflineUploads: () => readonly OfflineUpload<TUploadRef>[]; /** Resolves a staged upload id to its latest final ref, uploading first if needed. */
|
|
667
|
+
resolveOfflineUpload: (id: string) => Promise<TUploadRef>; /** Resolves multiple staged upload ids to their latest final refs. */
|
|
668
|
+
resolveOfflineUploads: (ids: readonly string[]) => Promise<Record<string, TUploadRef>>; /** Saves a session-scoped upload locally for later dependency resolution or ref usage. */
|
|
669
|
+
saveOfflineUpload: (args: {
|
|
670
|
+
id: string;
|
|
671
|
+
file: Blob | File;
|
|
672
|
+
}) => Promise<void>; /** Replaces a previously stored session-scoped upload. */
|
|
673
|
+
replaceOfflineUpload: (args: {
|
|
674
|
+
id: string;
|
|
675
|
+
file: Blob | File;
|
|
676
|
+
}) => Promise<void>; /** Loads a previously stored session-scoped upload. */
|
|
677
|
+
loadOfflineUpload: (id: string) => Promise<File | null>; /** Deletes a stored upload when it is no longer referenced. */
|
|
678
|
+
deleteOfflineUpload: (id: string) => Promise<void>; /** React hook subscribing to the session's global offline status. */
|
|
679
|
+
useOfflineStatus: () => GlobalOfflineStatus; /** React hook subscribing to the session's aggregated offline entities. */
|
|
680
|
+
useOfflineEntities: () => readonly GlobalOfflineEntity[]; /** React hook subscribing to the session's aggregated conflict/retry resolutions. */
|
|
681
|
+
useOfflineResolutions: () => readonly OfflineResolutionRecord[]; /** React hook subscribing to the session's upload list. */
|
|
682
|
+
useOfflineUploads: () => readonly OfflineUpload<TUploadRef>[];
|
|
683
|
+
};
|
|
684
|
+
/**
|
|
685
|
+
* Persisted offline mutation queue entry.
|
|
686
|
+
*
|
|
687
|
+
* @typeParam TInput - Serialized input payload for the queued mutation.
|
|
688
|
+
* @typeParam TConflict - Conflict payload that may be attached while waiting for confirmation or resolution.
|
|
689
|
+
*/
|
|
690
|
+
type OfflineQueueEntry<TInput = unknown, TConflict = unknown> = {
|
|
691
|
+
/** Queue entry identifier. */id: string; /** Session key for queue scoping. */
|
|
692
|
+
sessionKey: string; /** Store name where operation is defined. */
|
|
693
|
+
storeName: string; /** Store type for this queued operation. */
|
|
694
|
+
storeType: OfflineStoreType; /** Operation name registered in offline configuration. */
|
|
695
|
+
operation: string; /** Operation input payload persisted with the entry. */
|
|
696
|
+
input: TInput; /** Stable ordering key used to replay queued operations deterministically. */
|
|
697
|
+
queueOrder: number; /** Entity references tied to this mutation. */
|
|
698
|
+
entityRefs: OfflineEntityRef[]; /** Number of execution attempts so far. */
|
|
699
|
+
attempts: number; /** Queue entry creation timestamp. */
|
|
700
|
+
createdAt: number; /** Last entry update timestamp. */
|
|
701
|
+
updatedAt: number; /** Timestamp of last execution attempt, if any. */
|
|
702
|
+
lastAttemptAt: number | null; /** Synchronization state for this entry. */
|
|
703
|
+
syncState: OfflineSyncState; /** Optional temporary IDs for optimistic create operations. */
|
|
704
|
+
tempIds?: ValidPayload[]; /** Maps original direct-upload keys to their persisted session upload ids. */
|
|
705
|
+
attachedUploadIds?: OfflineAttachedUploadIds; /** Session upload ids that must resolve before replaying the mutation. */
|
|
706
|
+
dependencyUploadIds?: string[]; /** Last recorded sync error if replay failed. */
|
|
707
|
+
lastError?: {
|
|
708
|
+
message: string;
|
|
709
|
+
};
|
|
710
|
+
/**
|
|
711
|
+
* Whether a `needs-confirmation` entry may auto-resend during healthy replay
|
|
712
|
+
* retries after confirmation checks finish.
|
|
713
|
+
*/
|
|
714
|
+
allowReplayRetry?: boolean; /** Pending conflict payload when confirmation or resolution is required. */
|
|
715
|
+
pendingConflict?: TConflict;
|
|
716
|
+
};
|
|
717
|
+
/** Built-in resolution actions for retry exhaustion records. */
|
|
718
|
+
type OfflineRetryExhaustedResolutionAction = {
|
|
719
|
+
action: 'retry';
|
|
720
|
+
/**
|
|
721
|
+
* Controls whether retrying a resolution should also requeue retryable
|
|
722
|
+
* descendants from the same temp-lifecycle dependency chain.
|
|
723
|
+
* @default 'self-and-descendants'
|
|
724
|
+
*/
|
|
725
|
+
scope?: 'self' | 'self-and-descendants';
|
|
726
|
+
} | {
|
|
727
|
+
action: 'discard';
|
|
728
|
+
};
|
|
729
|
+
/**
|
|
730
|
+
* Built-in resolution actions for persisted conflict records.
|
|
731
|
+
*
|
|
732
|
+
* `commit` is intended for flows where the final API call has already been made
|
|
733
|
+
* externally and the store only needs to clear bookkeeping plus reconcile any
|
|
734
|
+
* temp-entity lifecycle using the accepted server result.
|
|
735
|
+
*
|
|
736
|
+
* @typeParam TInput - Input type expected when requeueing a replacement mutation.
|
|
737
|
+
* @typeParam TResult - Result shape returned by the external conflict resolution call.
|
|
738
|
+
*/
|
|
739
|
+
type OfflineConflictResolutionAction<TInput = unknown, TResult = unknown> = {
|
|
740
|
+
action: 'discard';
|
|
741
|
+
} | {
|
|
742
|
+
action: 'requeue';
|
|
743
|
+
input: TInput;
|
|
744
|
+
} | {
|
|
745
|
+
action: 'commit';
|
|
746
|
+
result?: TResult;
|
|
747
|
+
};
|
|
748
|
+
/**
|
|
749
|
+
* Built-in resolution actions accepted by `resolveOfflineResolution(...)`.
|
|
750
|
+
*
|
|
751
|
+
* @typeParam TInput - Input type expected when requeueing a replacement mutation.
|
|
752
|
+
* @typeParam TResult - Result shape returned by an externally completed conflict resolution call.
|
|
753
|
+
*/
|
|
754
|
+
type OfflineResolutionAction<TInput = unknown, TResult = unknown> = OfflineRetryExhaustedResolutionAction | OfflineConflictResolutionAction<TInput, TResult>;
|
|
755
|
+
/**
|
|
756
|
+
* Extracts operation input type from a schema map.
|
|
757
|
+
*
|
|
758
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
759
|
+
* @typeParam TName - Operation name whose input type should be extracted.
|
|
760
|
+
*/
|
|
761
|
+
type OperationInput<TOperations, TName extends keyof TOperations> = TOperations[TName] extends {
|
|
762
|
+
inputSchema: PersistentStorageSchema<infer TInput>;
|
|
763
|
+
} ? TInput : never;
|
|
764
|
+
/**
|
|
765
|
+
* A typed operation descriptor for an offline mutation queue entry.
|
|
766
|
+
*
|
|
767
|
+
* @typeParam TOperations - Operation registry that defines valid operation names and input schemas.
|
|
768
|
+
* @typeParam TName - Operation name to describe. Defaults to all operation names in the registry.
|
|
769
|
+
*/
|
|
770
|
+
type OfflineMutationDescriptor<TOperations extends Record<string, {
|
|
771
|
+
inputSchema: PersistentStorageSchema<__LEGIT_ANY__>;
|
|
772
|
+
}>, TName extends keyof TOperations & string = keyof TOperations & string> = { [K in TName]: {
|
|
773
|
+
/** Operation key from the offline operations registry. */operation: K; /** Input resolved from the registered operation schema. */
|
|
774
|
+
input: OperationInput<TOperations, K>;
|
|
775
|
+
} }[TName];
|
|
776
|
+
/**
|
|
777
|
+
* Public offline mutation input accepted by store mutation APIs.
|
|
778
|
+
*
|
|
779
|
+
* Callers queue exactly one descriptor per mutation fallback.
|
|
780
|
+
*/
|
|
781
|
+
type OfflineMutationInput<TOperations extends Record<string, {
|
|
782
|
+
inputSchema: PersistentStorageSchema<__LEGIT_ANY__>;
|
|
783
|
+
}>, TName extends keyof TOperations & string = keyof TOperations & string> = OfflineMutationDescriptor<TOperations, TName>;
|
|
784
|
+
/**
|
|
785
|
+
* Extracts operation result type from a registered operation map.
|
|
786
|
+
*
|
|
787
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
788
|
+
* @typeParam TName - Operation name whose result type should be extracted.
|
|
789
|
+
*/
|
|
790
|
+
type OperationResult<TOperations, TName extends keyof TOperations> = TOperations[TName] extends {
|
|
791
|
+
execute: (...args: __LEGIT_ANY__[]) => infer TResult;
|
|
792
|
+
} ? Awaited<TResult> : never;
|
|
793
|
+
/**
|
|
794
|
+
* Resolution action accepted for a specific registered offline operation.
|
|
795
|
+
*
|
|
796
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
797
|
+
* @typeParam TName - Operation name whose resolution payload should be extracted.
|
|
798
|
+
*/
|
|
799
|
+
type OfflineResolutionActionForOperation<TOperations, TName extends keyof TOperations> = OfflineResolutionAction<OperationInput<TOperations, TName>, OperationResult<TOperations, TName>>;
|
|
800
|
+
/**
|
|
801
|
+
* Context passed into offline mutation accumulation hooks.
|
|
802
|
+
*
|
|
803
|
+
* @typeParam TInput - Input type shared by the existing and incoming queued mutations.
|
|
804
|
+
*/
|
|
805
|
+
type OfflineAccumulationMergeContext<TInput> = {
|
|
806
|
+
/** Session key used to isolate queued mutations. */sessionKey: string; /** Existing input already present in queue. */
|
|
807
|
+
existingInput: TInput; /** Incoming input for merge attempt. */
|
|
808
|
+
incomingInput: TInput;
|
|
809
|
+
};
|
|
810
|
+
/**
|
|
811
|
+
* Optional in-memory accumulation strategy for queued offline mutations.
|
|
812
|
+
*
|
|
813
|
+
* @typeParam TInput - Input type that will be merged and revalidated before persisting.
|
|
814
|
+
*/
|
|
815
|
+
type OfflineAccumulationConfig<TInput> = {
|
|
816
|
+
/** Merge function for combining existing and incoming mutation inputs. */mergeInput: (ctx: OfflineAccumulationMergeContext<TInput>) => Promise<TInput> | TInput;
|
|
817
|
+
};
|
|
818
|
+
/**
|
|
819
|
+
* Optional queue-pruning strategy for queued offline mutations.
|
|
820
|
+
*
|
|
821
|
+
* `same-entity` only applies to operations that resolve exactly one entity ref.
|
|
822
|
+
* When enabled, the new operation may remove earlier unattempted pending entries
|
|
823
|
+
* targeting that same single entity before the new entry is persisted.
|
|
824
|
+
*/
|
|
825
|
+
type OfflineSupersedeConfig = {
|
|
826
|
+
/** Drop earlier unattempted pending entries for the same single entity. */scope: 'same-entity';
|
|
827
|
+
/**
|
|
828
|
+
* Limits which earlier operations may be pruned for that entity.
|
|
829
|
+
*
|
|
830
|
+
* Omit this to prune every earlier pending operation for the entity,
|
|
831
|
+
* use `'self'` to prune only earlier entries of the current operation,
|
|
832
|
+
* or provide explicit operation names to target a specific related set.
|
|
833
|
+
*/
|
|
834
|
+
operations?: 'self' | readonly string[];
|
|
835
|
+
/**
|
|
836
|
+
* When the pruned entries include a temp-entity lifecycle, drop the current
|
|
837
|
+
* operation itself instead of persisting a replacement entry.
|
|
838
|
+
*/
|
|
839
|
+
dropSelfIfTempLifecycleCancelled?: boolean;
|
|
840
|
+
};
|
|
841
|
+
/** Shared context passed to offline replay lifecycle hooks. */
|
|
842
|
+
type OperationBaseContext<TInput> = {
|
|
843
|
+
/** Input payload for the queued mutation currently being processed. */input: TInput; /** Timestamp when the operation was originally enqueued. */
|
|
844
|
+
enqueuedAt: number; /** Timestamp when the queued entry or conflict record was last updated. */
|
|
845
|
+
updatedAt: number;
|
|
846
|
+
/**
|
|
847
|
+
* Resolves a previously temp-backed entity ref to its latest known final ref
|
|
848
|
+
* when one has been reconciled.
|
|
849
|
+
*/
|
|
850
|
+
resolveEntityRef: <TEntityRef extends ValidPayload>(entityRef: TEntityRef) => TEntityRef;
|
|
851
|
+
};
|
|
852
|
+
type OperationExecuteContext<TInput, TUploadRef extends ValidPayload = ValidPayload> = OperationBaseContext<TInput> & {
|
|
853
|
+
uploads: OfflineOperationUploadsContext<TUploadRef>;
|
|
854
|
+
};
|
|
855
|
+
/** Context passed to the post-replay success hook after `execute(...)` settles. */
|
|
856
|
+
type OfflineOperationExecuteSuccessContext<TInput, TResult> = OperationBaseContext<TInput> & {
|
|
857
|
+
/** Replay result returned by `execute(...)`. */result: TResult;
|
|
858
|
+
};
|
|
859
|
+
/**
|
|
860
|
+
* Optional callback used to synchronize UI/cache state after a successful
|
|
861
|
+
* offline replay execute.
|
|
862
|
+
*/
|
|
863
|
+
type OfflineOperationExecuteSuccessHandler<TInput, TResult> = (ctx: OfflineOperationExecuteSuccessContext<TInput, TResult>) => Promise<void> | void;
|
|
864
|
+
type IsUnknown<T> = unknown extends T ? [keyof T] extends [never] ? true : false : false;
|
|
865
|
+
/** Context passed to replay checks that may use a fresh server snapshot. */
|
|
866
|
+
type OperationReplayCheckContext<TInput, TServerSnapshot> = OperationBaseContext<TInput> & {
|
|
867
|
+
/**
|
|
868
|
+
* Optional snapshot fetched immediately before `shouldSkipSync` and
|
|
869
|
+
* `detectConflict`.
|
|
870
|
+
*/
|
|
871
|
+
serverSnapshot: IsUnknown<TServerSnapshot> extends true ? undefined : TServerSnapshot;
|
|
872
|
+
};
|
|
873
|
+
/**
|
|
874
|
+
* Conflict hook configuration for a queued offline operation.
|
|
875
|
+
*
|
|
876
|
+
* @typeParam TInput - Input type of the queued operation being checked and potentially requeued.
|
|
877
|
+
* @typeParam TConflict - Conflict payload produced by detection and persisted for later external resolution.
|
|
878
|
+
*/
|
|
879
|
+
type OfflineConflictHandlingConfig<TInput, TConflict, TServerSnapshot = unknown> = {
|
|
880
|
+
/** Schema used to validate and sanitize persisted conflict payloads. */schema: PersistentStorageSchema<TConflict>;
|
|
881
|
+
/**
|
|
882
|
+
* Inspect remote state before replaying the mutation and return conflict payload
|
|
883
|
+
* when the queued mutation can no longer be applied safely.
|
|
884
|
+
*/
|
|
885
|
+
detectConflict: (ctx: OperationReplayCheckContext<TInput, TServerSnapshot>) => Promise<TConflict | false | null> | TConflict | false | null;
|
|
886
|
+
};
|
|
887
|
+
type ConflictHandlingField<TInput, TConflict, TServerSnapshot> = IsUnknown<TConflict> extends true ? {
|
|
888
|
+
/**
|
|
889
|
+
* Optional conflict strategy when a queued operation diverges from remote state.
|
|
890
|
+
*/
|
|
891
|
+
conflictHandling?: OfflineConflictHandlingConfig<TInput, TConflict, TServerSnapshot>;
|
|
892
|
+
} : {
|
|
893
|
+
/**
|
|
894
|
+
* Conflict strategy required when the operation declares a concrete
|
|
895
|
+
* conflict payload type.
|
|
896
|
+
*/
|
|
897
|
+
conflictHandling: OfflineConflictHandlingConfig<TInput, TConflict, TServerSnapshot>;
|
|
898
|
+
};
|
|
899
|
+
type ServerSnapshotField<TInput, TServerSnapshot> = IsUnknown<TServerSnapshot> extends true ? {
|
|
900
|
+
/**
|
|
901
|
+
* Optionally loads a fresh server-side snapshot before replay checks run.
|
|
902
|
+
* The result is passed to `shouldSkipSync` and `detectConflict` as
|
|
903
|
+
* `ctx.serverSnapshot`.
|
|
904
|
+
*/
|
|
905
|
+
getServerSnapshot?: (ctx: OperationBaseContext<TInput>) => Promise<TServerSnapshot> | TServerSnapshot;
|
|
906
|
+
} : {
|
|
907
|
+
/**
|
|
908
|
+
* Required when the operation declares a concrete server snapshot type.
|
|
909
|
+
* The result is passed to `shouldSkipSync` and `detectConflict` as
|
|
910
|
+
* `ctx.serverSnapshot`.
|
|
911
|
+
*/
|
|
912
|
+
getServerSnapshot: (ctx: OperationBaseContext<TInput>) => Promise<TServerSnapshot> | TServerSnapshot;
|
|
913
|
+
};
|
|
914
|
+
/**
|
|
915
|
+
* Replacement data returned by `tempEntity.reconcileServerEntity(...)`.
|
|
916
|
+
*
|
|
917
|
+
* @typeParam TFinalPayload - Final payload that should replace the temporary one.
|
|
918
|
+
* @typeParam TFinalData - Optional replacement entity data for the final payload.
|
|
919
|
+
*/
|
|
920
|
+
type OfflineTempEntityReconciliation<TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown> = {
|
|
921
|
+
/** Final payload that should replace the temporary optimistic one. */finalPayload: TFinalPayload;
|
|
922
|
+
/**
|
|
923
|
+
* Optional replacement data for the final payload.
|
|
924
|
+
* Omit this to keep the current optimistic entity data and only swap the
|
|
925
|
+
* payload/identity.
|
|
926
|
+
*/
|
|
927
|
+
finalData?: TFinalData;
|
|
928
|
+
};
|
|
929
|
+
/**
|
|
930
|
+
* Replacement data returned by `tempEntities.reconcileServerEntities(...)`.
|
|
931
|
+
*
|
|
932
|
+
* @typeParam TTempId - Temporary payload that should be reconciled.
|
|
933
|
+
* @typeParam TFinalPayload - Final payload that should replace the temporary one.
|
|
934
|
+
* @typeParam TFinalData - Optional replacement entity data for the final payload.
|
|
935
|
+
*/
|
|
936
|
+
type OfflineTempEntitiesReconciliation<TTempId extends ValidPayload = ValidPayload, TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown> = OfflineTempEntityReconciliation<TFinalPayload, TFinalData> & {
|
|
937
|
+
/** Temporary payload that should be reconciled. */tempId: TTempId;
|
|
938
|
+
};
|
|
939
|
+
/**
|
|
940
|
+
* Pending temp-entity returned by `tempEntities.buildPendingEntities(...)`.
|
|
941
|
+
*
|
|
942
|
+
* @typeParam TTempId - Temporary payload used to track the optimistic entity.
|
|
943
|
+
* @typeParam TPendingEntity - Pending entity snapshot to insert locally.
|
|
944
|
+
*/
|
|
945
|
+
type OfflineTempEntityPendingEntry<TTempId extends ValidPayload = ValidPayload, TPendingEntity = unknown> = {
|
|
946
|
+
/** Temporary payload that identifies the optimistic entity. */tempId: TTempId; /** Pending entity snapshot inserted while the mutation is queued. */
|
|
947
|
+
pendingEntity: TPendingEntity;
|
|
948
|
+
};
|
|
949
|
+
/**
|
|
950
|
+
* Optional temp-id lifecycle for optimistic offline create flows.
|
|
951
|
+
*
|
|
952
|
+
* @typeParam TInput - Input type used to derive the temporary entity and identifier.
|
|
953
|
+
* @typeParam TTempResult - Result returned by `execute`, used only by `tempEntity.reconcileServerEntity(...)`.
|
|
954
|
+
* @typeParam TTempId - Temporary payload used to track optimistic entities before reconciliation.
|
|
955
|
+
*/
|
|
956
|
+
type OfflineTempEntityConfig<TInput, TTempResult, TTempId extends ValidPayload = string, TPendingEntity = unknown, TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown> = {
|
|
957
|
+
/**
|
|
958
|
+
* Builds the optimistic entity inserted into local state while the mutation
|
|
959
|
+
* is queued offline.
|
|
960
|
+
*
|
|
961
|
+
* `tempId` is the temporary payload used to identify the optimistic entity
|
|
962
|
+
* until replay succeeds and the final server entity can replace it.
|
|
963
|
+
*/
|
|
964
|
+
buildPendingEntity: (input: TInput, tempId: TTempId) => TPendingEntity;
|
|
965
|
+
/**
|
|
966
|
+
* Reconciles the optimistic temp entity with the successful replay result.
|
|
967
|
+
*/
|
|
968
|
+
reconcileServerEntity: (result: TTempResult, tempId: TTempId) => OfflineTempEntityReconciliation<TFinalPayload, TFinalData>;
|
|
969
|
+
};
|
|
970
|
+
/**
|
|
971
|
+
* Optional temp-id lifecycle for optimistic offline batch-create flows.
|
|
972
|
+
*
|
|
973
|
+
* @typeParam TInput - Input type used to derive the temporary entities and identifiers.
|
|
974
|
+
* @typeParam TTempResult - Result returned by `execute`, used only by `tempEntities.reconcileServerEntities(...)`.
|
|
975
|
+
* @typeParam TTempId - Temporary payload used to track optimistic entities before reconciliation.
|
|
976
|
+
*/
|
|
977
|
+
type OfflineTempEntitiesConfig<TInput, TTempResult, TTempId extends ValidPayload = string, TPendingEntity = unknown, TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown> = {
|
|
978
|
+
/**
|
|
979
|
+
* Builds the optimistic entities inserted into local state while the mutation
|
|
980
|
+
* is queued offline.
|
|
981
|
+
*
|
|
982
|
+
* `tempIds` are the temporary payloads derived from the operation entity refs
|
|
983
|
+
* and used until replay succeeds and the final server entities can replace them.
|
|
984
|
+
*/
|
|
985
|
+
buildPendingEntities: (input: TInput, tempIds: readonly TTempId[]) => readonly OfflineTempEntityPendingEntry<TTempId, TPendingEntity>[];
|
|
986
|
+
/**
|
|
987
|
+
* Reconciles the optimistic temp entities with the successful replay result.
|
|
988
|
+
*/
|
|
989
|
+
reconcileServerEntities: (result: TTempResult, tempIds: readonly TTempId[]) => readonly OfflineTempEntitiesReconciliation<TTempId, TFinalPayload, TFinalData>[];
|
|
990
|
+
};
|
|
991
|
+
type NoTempEntityFields = {
|
|
992
|
+
tempEntity?: never;
|
|
993
|
+
tempEntities?: never;
|
|
994
|
+
};
|
|
995
|
+
type ConfiguredTempEntityFields<TInput, TTempResult, TTempId extends ValidPayload, TPendingEntity = unknown, TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown> = {
|
|
996
|
+
tempEntity: OfflineTempEntityConfig<TInput, TTempResult, TTempId, TPendingEntity, TFinalPayload, TFinalData>;
|
|
997
|
+
tempEntities?: never;
|
|
998
|
+
} | {
|
|
999
|
+
tempEntity?: never;
|
|
1000
|
+
tempEntities: OfflineTempEntitiesConfig<TInput, TTempResult, TTempId, TPendingEntity, TFinalPayload, TFinalData>;
|
|
1001
|
+
};
|
|
1002
|
+
/**
|
|
1003
|
+
* Shape used by `persistentStorage.offline.operations` for each operation name.
|
|
1004
|
+
*
|
|
1005
|
+
* @typeParam TInput - The persisted input payload for the queued offline operation.
|
|
1006
|
+
* @typeParam TConflict - The conflict payload produced by pre-execution conflict detection.
|
|
1007
|
+
* @typeParam TTempResult - Result returned by `execute`, used only when `tempEntity` or `tempEntities` needs to reconcile the final server entity. Defaults to `void`.
|
|
1008
|
+
*/
|
|
1009
|
+
type OfflineOperationDefinition<TInput, TConflict, TTempResult = void, TServerSnapshot = unknown, TTempId extends ValidPayload = string, TPendingEntity = unknown, TFinalPayload extends ValidPayload = ValidPayload, TFinalData = unknown, TUploadRef extends ValidPayload = ValidPayload> = {
|
|
1010
|
+
/** Schema used to validate incoming operation input. */inputSchema: PersistentStorageSchema<TInput>; /** Lifecycle classification for the queued operation. */
|
|
1011
|
+
kind: OfflineOperationKind;
|
|
1012
|
+
/**
|
|
1013
|
+
* Optional queue pruning for newer operations that supersede older queued work.
|
|
1014
|
+
*
|
|
1015
|
+
* This is mutually exclusive with `accumulation`.
|
|
1016
|
+
*/
|
|
1017
|
+
supersedes?: OfflineSupersedeConfig;
|
|
1018
|
+
/**
|
|
1019
|
+
* Executes the queued mutation against the remote source during replay.
|
|
1020
|
+
* This may run multiple times when transient failures occur.
|
|
1021
|
+
*/
|
|
1022
|
+
execute: (ctx: OperationExecuteContext<TInput, TUploadRef>) => Promise<TTempResult> | TTempResult;
|
|
1023
|
+
/**
|
|
1024
|
+
* Optional check executed before retrying a previously failed sync attempt.
|
|
1025
|
+
* Return `true` to drop the queued entry because the remote side already reflects it.
|
|
1026
|
+
* Return `false` to continue with normal replay.
|
|
1027
|
+
*/
|
|
1028
|
+
shouldSkipSync?: (ctx: OperationReplayCheckContext<TInput, TServerSnapshot>) => Promise<boolean> | boolean;
|
|
1029
|
+
} & ConflictHandlingField<TInput, TConflict, TServerSnapshot> & ServerSnapshotField<TInput, TServerSnapshot> & (({
|
|
1030
|
+
/**
|
|
1031
|
+
* Explicit store-sync step that runs after `execute(...)` succeeds during
|
|
1032
|
+
* offline replay.
|
|
1033
|
+
*
|
|
1034
|
+
* Provide a callback when replay should update the live store after the
|
|
1035
|
+
* server-side execute succeeds.
|
|
1036
|
+
*/
|
|
1037
|
+
onSuccessExecute: OfflineOperationExecuteSuccessHandler<TInput, TTempResult>;
|
|
1038
|
+
/**
|
|
1039
|
+
* Optional queue compaction for consecutive mutations with same refs.
|
|
1040
|
+
*/
|
|
1041
|
+
accumulation?: OfflineAccumulationConfig<TInput>;
|
|
1042
|
+
} & NoTempEntityFields) | ({
|
|
1043
|
+
/**
|
|
1044
|
+
* Temp-entity operations already reconcile the live store through
|
|
1045
|
+
* `tempEntity` / `tempEntities`, so they must not declare an extra
|
|
1046
|
+
* success sync callback.
|
|
1047
|
+
*/
|
|
1048
|
+
onSuccessExecute?: undefined; /** Temp-entity operations cannot compact multiple queued creates. */
|
|
1049
|
+
accumulation?: never;
|
|
1050
|
+
} & ConfiguredTempEntityFields<TInput, TTempResult, TTempId, TPendingEntity, TFinalPayload, TFinalData>));
|
|
1051
|
+
type WithoutTempEntity<T extends {
|
|
1052
|
+
tempEntity?: unknown;
|
|
1053
|
+
tempEntities?: unknown;
|
|
1054
|
+
}> = Omit<T, 'tempEntity' | 'tempEntities'> & {
|
|
1055
|
+
/** Document stores do not support optimistic temp entities. */tempEntity?: never; /** Document stores do not support optimistic batch temp entities. */
|
|
1056
|
+
tempEntities?: never;
|
|
1057
|
+
};
|
|
1058
|
+
/** Context used to resolve which entities a queued mutation affects. */
|
|
1059
|
+
type OperationEntityRefsContext<TInput> = {
|
|
1060
|
+
/** Input payload for the queued mutation. */input: TInput;
|
|
1061
|
+
};
|
|
1062
|
+
/** Non-store-specific offline operation definition alias. */
|
|
1063
|
+
type AnyOfflineOperationDefinition<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
1064
|
+
inputSchema: PersistentStorageSchema<__LEGIT_ANY__>;
|
|
1065
|
+
kind: OfflineOperationKind;
|
|
1066
|
+
conflictHandling?: {
|
|
1067
|
+
schema: PersistentStorageSchema<__LEGIT_ANY__>;
|
|
1068
|
+
detectConflict: (ctx: __LEGIT_ANY__) => unknown;
|
|
1069
|
+
};
|
|
1070
|
+
accumulation?: OfflineAccumulationConfig<__LEGIT_ANY__>;
|
|
1071
|
+
supersedes?: OfflineSupersedeConfig;
|
|
1072
|
+
tempEntity?: OfflineTempEntityConfig<__LEGIT_ANY__, __LEGIT_ANY__, __LEGIT_ANY__>;
|
|
1073
|
+
tempEntities?: OfflineTempEntitiesConfig<__LEGIT_ANY__, __LEGIT_ANY__, __LEGIT_ANY__>;
|
|
1074
|
+
getServerSnapshot?: (ctx: OperationBaseContext<__LEGIT_ANY__>) => unknown;
|
|
1075
|
+
execute: (ctx: OperationExecuteContext<__LEGIT_ANY__, TUploadRef>) => unknown;
|
|
1076
|
+
onSuccessExecute?: OfflineOperationExecuteSuccessHandler<__LEGIT_ANY__, __LEGIT_ANY__>;
|
|
1077
|
+
shouldSkipSync?: (ctx: OperationReplayCheckContext<__LEGIT_ANY__, __LEGIT_ANY__>) => Promise<boolean> | boolean;
|
|
1078
|
+
} & {
|
|
1079
|
+
getEntityRefs?: (ctx: OperationEntityRefsContext<__LEGIT_ANY__>) => unknown[];
|
|
1080
|
+
dependsOn?: (ctx: OperationEntityRefsContext<__LEGIT_ANY__>) => __LEGIT_ANY__[];
|
|
1081
|
+
dependsOnUploads?: (ctx: OperationEntityRefsContext<__LEGIT_ANY__>) => string[];
|
|
1082
|
+
};
|
|
1083
|
+
/**
|
|
1084
|
+
* Compact type-spec helper for a single offline operation.
|
|
1085
|
+
*
|
|
1086
|
+
* Use this helper with {@link DefineDocumentOfflineOperations} to describe each
|
|
1087
|
+
* operation using generic parameters instead of inline object literals.
|
|
1088
|
+
*
|
|
1089
|
+
* The generic order is `input`, `conflict`, `temp result`, then `server snapshot`.
|
|
1090
|
+
*
|
|
1091
|
+
* @typeParam TInput - Input payload accepted by the operation.
|
|
1092
|
+
* @typeParam TConflict - Conflict payload produced by optional conflict handling.
|
|
1093
|
+
* @typeParam TTempResult - Result returned by `execute`, also reused when externally committed conflict resolution needs temp-entity reconciliation.
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* ```ts
|
|
1097
|
+
* type UpdateName = DefineOfflineOperation<
|
|
1098
|
+
* { name: string },
|
|
1099
|
+
* { remoteName: string },
|
|
1100
|
+
* { name: string }
|
|
1101
|
+
* >;
|
|
1102
|
+
* ```
|
|
1103
|
+
*/
|
|
1104
|
+
type DefineOfflineOperation<TInput = unknown, TConflict = unknown, TTempResult = unknown, TServerSnapshot = unknown> = {
|
|
1105
|
+
/** Input type accepted by the operation. */input?: TInput; /** Conflict payload type produced by the optional conflict handler. */
|
|
1106
|
+
conflict?: TConflict; /** Result returned by `execute`, also reused by externally committed conflict resolution for temp-entity reconciliation. */
|
|
1107
|
+
result?: TTempResult; /** Snapshot type returned by `getServerSnapshot` and exposed to replay checks. */
|
|
1108
|
+
serverSnapshot?: TServerSnapshot;
|
|
1109
|
+
};
|
|
1110
|
+
type DocumentOperationInput<TOptions extends DefineOfflineOperation> = TOptions extends {
|
|
1111
|
+
input?: infer TInput;
|
|
1112
|
+
} ? TInput : unknown;
|
|
1113
|
+
type DocumentOperationConflict<TOptions extends DefineOfflineOperation> = TOptions extends {
|
|
1114
|
+
conflict?: infer TConflict;
|
|
1115
|
+
} ? TConflict : unknown;
|
|
1116
|
+
type DocumentOperationResult<TOptions extends DefineOfflineOperation> = TOptions extends {
|
|
1117
|
+
result?: infer TTempResult;
|
|
1118
|
+
} ? TTempResult : unknown;
|
|
1119
|
+
type DocumentOperationServerSnapshot<TOptions extends DefineOfflineOperation> = TOptions extends {
|
|
1120
|
+
serverSnapshot?: infer TServerSnapshot;
|
|
1121
|
+
} ? TServerSnapshot : unknown;
|
|
1122
|
+
/**
|
|
1123
|
+
* Document-store specific offline operation definition.
|
|
1124
|
+
*
|
|
1125
|
+
* Prefer this alias when manually typing a single operation inside
|
|
1126
|
+
* `persistentStorage.offline.operations` for a document store.
|
|
1127
|
+
*
|
|
1128
|
+
* `TOptions` is usually provided with {@link DefineOfflineOperation}, which lets
|
|
1129
|
+
* callers specify the queued `input`, replay `result`, and optional `conflict`
|
|
1130
|
+
* payload concisely. Document stores do not support `tempEntity`.
|
|
1131
|
+
*
|
|
1132
|
+
* Omitted properties default to `unknown`.
|
|
1133
|
+
*
|
|
1134
|
+
* @typeParam State - Document state type for the owning store.
|
|
1135
|
+
* @typeParam TOptions - Operation typing options, usually created with {@link DefineOfflineOperation}.
|
|
1136
|
+
*
|
|
1137
|
+
* @example
|
|
1138
|
+
* ```ts
|
|
1139
|
+
* type RenameOperation = DocumentOfflineOperationDefinition<
|
|
1140
|
+
* UserDoc,
|
|
1141
|
+
* DefineOfflineOperation<
|
|
1142
|
+
* { name: string },
|
|
1143
|
+
* { remoteName: string },
|
|
1144
|
+
* { name: string }
|
|
1145
|
+
* >
|
|
1146
|
+
* >;
|
|
1147
|
+
* ```
|
|
1148
|
+
*/
|
|
1149
|
+
type DocumentOfflineOperationDefinition<State extends ValidStoreState, TOptions extends DefineOfflineOperation = DefineOfflineOperation, TUploadRef extends ValidPayload = ValidPayload> = WithoutTempEntity<OfflineOperationDefinition<DocumentOperationInput<TOptions>, DocumentOperationConflict<TOptions>, DocumentOperationResult<TOptions>, DocumentOperationServerSnapshot<TOptions>, string, unknown, ValidPayload, unknown, TUploadRef>> & {
|
|
1150
|
+
/** Declares which upload ids must finish before replaying this operation. */dependsOnUploads?: (ctx: OperationEntityRefsContext<DocumentOperationInput<TOptions>>) => string[];
|
|
1151
|
+
} & ([State] extends [never] ? never : unknown);
|
|
1152
|
+
/**
|
|
1153
|
+
* Builds a document offline operations map from a compact operation spec.
|
|
1154
|
+
*
|
|
1155
|
+
* This is the recommended way to type a document store's full offline operation map.
|
|
1156
|
+
* Each operation key is typically described with {@link DefineOfflineOperation},
|
|
1157
|
+
* and this helper expands that into the full
|
|
1158
|
+
* {@link DocumentOfflineOperationDefinition} map expected by the store.
|
|
1159
|
+
*
|
|
1160
|
+
* @typeParam State - Document state type for the owning store.
|
|
1161
|
+
* @typeParam TOperations - Operation map where each key declares its input, replay result, and optional conflict payload.
|
|
1162
|
+
*
|
|
1163
|
+
* @example
|
|
1164
|
+
* ```ts
|
|
1165
|
+
* type Operations = DefineDocumentOfflineOperations<
|
|
1166
|
+
* UserDoc,
|
|
1167
|
+
* {
|
|
1168
|
+
* updateName: DefineOfflineOperation<
|
|
1169
|
+
* { name: string },
|
|
1170
|
+
* unknown,
|
|
1171
|
+
* { name: string }
|
|
1172
|
+
* >;
|
|
1173
|
+
* archive: DefineOfflineOperation<
|
|
1174
|
+
* { reason: string },
|
|
1175
|
+
* { code: string }
|
|
1176
|
+
* >;
|
|
1177
|
+
* }
|
|
1178
|
+
* >;
|
|
1179
|
+
* ```
|
|
1180
|
+
*
|
|
1181
|
+
* Then use the resulting type as the `operations` object contract:
|
|
1182
|
+
*
|
|
1183
|
+
* ```ts
|
|
1184
|
+
* const operations: Operations = {
|
|
1185
|
+
* updateName: {
|
|
1186
|
+
* inputSchema: z.object({ name: z.string() }),
|
|
1187
|
+
* kind: 'update',
|
|
1188
|
+
* execute: ({ input }) => ({ name: input.name }),
|
|
1189
|
+
* },
|
|
1190
|
+
* archive: {
|
|
1191
|
+
* inputSchema: z.object({ reason: z.string() }),
|
|
1192
|
+
* kind: 'delete',
|
|
1193
|
+
* conflictHandling: {
|
|
1194
|
+
* schema: z.object({ code: z.string() }),
|
|
1195
|
+
* detectConflict: () => false,
|
|
1196
|
+
* },
|
|
1197
|
+
* execute: () => undefined,
|
|
1198
|
+
* },
|
|
1199
|
+
* };
|
|
1200
|
+
* ```
|
|
1201
|
+
*/
|
|
1202
|
+
type DefineDocumentOfflineOperations<State extends ValidStoreState, TOperations extends Record<string, DefineOfflineOperation>, TUploadRef extends ValidPayload = ValidPayload> = { [TName in keyof TOperations]: DocumentOfflineOperationDefinition<State, TOperations[TName], TUploadRef> };
|
|
1203
|
+
/**
|
|
1204
|
+
* Collection offline entity reference.
|
|
1205
|
+
*
|
|
1206
|
+
* Collection operations return raw item payloads, which are normalized to the
|
|
1207
|
+
* internal item key by the store.
|
|
1208
|
+
*
|
|
1209
|
+
* @typeParam ItemPayload - Collection item payload type for the owning store.
|
|
1210
|
+
*/
|
|
1211
|
+
type CollectionOfflineEntityRef<ItemPayload extends ValidPayload> = ItemPayload;
|
|
1212
|
+
/**
|
|
1213
|
+
* Collection-store specific offline operation definition.
|
|
1214
|
+
*
|
|
1215
|
+
* @typeParam ItemState - Collection item state type for the owning store.
|
|
1216
|
+
* @typeParam ItemPayloadUnused - Collection payload type used to anchor the operation to the owning store type.
|
|
1217
|
+
* @typeParam TInput - Input type accepted by the offline operation.
|
|
1218
|
+
* @typeParam TConflict - Conflict payload type produced by the optional conflict handler.
|
|
1219
|
+
* @typeParam TTempResult - Result returned by `execute`.
|
|
1220
|
+
* When `tempEntity` or `tempEntities` is provided, the pending builders must
|
|
1221
|
+
* return `ItemState`, and the reconciliation hooks must return an
|
|
1222
|
+
* `ItemPayload` plus optional `ItemState` replacement data.
|
|
1223
|
+
*/
|
|
1224
|
+
type CollectionOfflineOperationDefinition<ItemState extends ValidStoreState, ItemPayloadUnused extends ValidPayload, TInput = unknown, TConflict = unknown, TTempResult = unknown, TServerSnapshot = unknown, TUploadRef extends ValidPayload = ValidPayload> = OfflineOperationDefinition<TInput, TConflict, TTempResult, TServerSnapshot, ItemPayloadUnused, ItemState, ItemPayloadUnused, ItemState, TUploadRef> & {
|
|
1225
|
+
/**
|
|
1226
|
+
* Declares which collection items are affected by this queued mutation.
|
|
1227
|
+
*
|
|
1228
|
+
* Return the raw collection payloads for the affected items. The store will
|
|
1229
|
+
* convert each payload with the configured item key logic.
|
|
1230
|
+
*/
|
|
1231
|
+
getEntityRefs: (ctx: OperationEntityRefsContext<TInput>) => CollectionOfflineEntityRef<ItemPayloadUnused>[];
|
|
1232
|
+
/**
|
|
1233
|
+
* Declares which collection item refs must resolve before replaying this
|
|
1234
|
+
* operation.
|
|
1235
|
+
*/
|
|
1236
|
+
dependsOn?: (ctx: OperationEntityRefsContext<TInput>) => CollectionOfflineEntityRef<ItemPayloadUnused>[]; /** Declares which upload ids must finish before replaying this operation. */
|
|
1237
|
+
dependsOnUploads?: (ctx: OperationEntityRefsContext<TInput>) => string[];
|
|
1238
|
+
} & ([ItemState | ItemPayloadUnused] extends [never] ? never : unknown);
|
|
1239
|
+
/**
|
|
1240
|
+
* Builds a collection offline operations map from a compact operation spec.
|
|
1241
|
+
*
|
|
1242
|
+
* Use this helper to define the full `persistentStorage.offline.operations` contract for a
|
|
1243
|
+
* collection store while keeping each operation's type declaration short.
|
|
1244
|
+
*
|
|
1245
|
+
* Each operation key is described with {@link DefineOfflineOperation}, and this
|
|
1246
|
+
* helper expands it into the corresponding
|
|
1247
|
+
* {@link CollectionOfflineOperationDefinition}. The runtime operation object
|
|
1248
|
+
* still needs to provide `getEntityRefs(...)`.
|
|
1249
|
+
*
|
|
1250
|
+
* @typeParam ItemState - Collection item state type for the owning store.
|
|
1251
|
+
* @typeParam ItemPayload - Collection payload type for the owning store.
|
|
1252
|
+
* @typeParam TOperations - Operation map where each key declares its input, optional conflict payload, and optional temp-result type.
|
|
1253
|
+
*
|
|
1254
|
+
* @example
|
|
1255
|
+
* ```ts
|
|
1256
|
+
* type Operations = DefineCollectionOfflineOperations<
|
|
1257
|
+
* TodoItem,
|
|
1258
|
+
* string,
|
|
1259
|
+
* {
|
|
1260
|
+
* renameTodo: DefineOfflineOperation<
|
|
1261
|
+
* { id: string; title: string }
|
|
1262
|
+
* >;
|
|
1263
|
+
* createTodo: DefineOfflineOperation<
|
|
1264
|
+
* { title: string },
|
|
1265
|
+
* unknown,
|
|
1266
|
+
* { id: string; title: string }
|
|
1267
|
+
* >;
|
|
1268
|
+
* }
|
|
1269
|
+
* >;
|
|
1270
|
+
* ```
|
|
1271
|
+
*/
|
|
1272
|
+
type DefineCollectionOfflineOperations<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, TOperations extends Record<string, DefineOfflineOperation>, TUploadRef extends ValidPayload = ValidPayload> = { [TName in keyof TOperations]: CollectionOfflineOperationDefinition<ItemState, ItemPayload, DocumentOperationInput<TOperations[TName]>, DocumentOperationConflict<TOperations[TName]>, DocumentOperationResult<TOperations[TName]>, DocumentOperationServerSnapshot<TOperations[TName]>, TUploadRef> };
|
|
1273
|
+
/**
|
|
1274
|
+
* List-query offline entity reference.
|
|
1275
|
+
*
|
|
1276
|
+
* List-query operations return raw item payloads, which are normalized to the
|
|
1277
|
+
* internal item key by the store.
|
|
1278
|
+
*
|
|
1279
|
+
* @typeParam ItemPayload - Item payload type for the owning list-query store.
|
|
1280
|
+
*/
|
|
1281
|
+
type ListQueryOfflineEntityRef<ItemPayload extends ValidPayload> = ItemPayload;
|
|
1282
|
+
/**
|
|
1283
|
+
* List-query-store specific offline operation definition.
|
|
1284
|
+
*
|
|
1285
|
+
* @typeParam ItemState - List item state type for the owning store.
|
|
1286
|
+
* @typeParam QueryPayload - Query payload type used by the list store.
|
|
1287
|
+
* @typeParam ItemPayloadUnused - Item payload type used to anchor the operation to the owning store type.
|
|
1288
|
+
* @typeParam TInput - Input type accepted by the offline operation.
|
|
1289
|
+
* @typeParam TConflict - Conflict payload type produced by the optional conflict handler.
|
|
1290
|
+
* @typeParam TTempResult - Result returned by `execute`.
|
|
1291
|
+
* When `tempEntity` or `tempEntities` is provided, the pending builders must
|
|
1292
|
+
* return `ItemState`, and the reconciliation hooks must return an
|
|
1293
|
+
* `ItemPayload` plus optional `ItemState` replacement data.
|
|
1294
|
+
*/
|
|
1295
|
+
type ListQueryOfflineOperationDefinition<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayloadUnused extends ValidPayload, TInput = unknown, TConflict = unknown, TTempResult = unknown, TServerSnapshot = unknown, TUploadRef extends ValidPayload = ValidPayload> = OfflineOperationDefinition<TInput, TConflict, TTempResult, TServerSnapshot, ItemPayloadUnused, ItemState, ItemPayloadUnused, ItemState, TUploadRef> & {
|
|
1296
|
+
/**
|
|
1297
|
+
* Declares which list-query entities are affected by this queued mutation.
|
|
1298
|
+
*
|
|
1299
|
+
* Return the raw item payloads for the affected items. The store will
|
|
1300
|
+
* convert each payload with the configured item key logic.
|
|
1301
|
+
*/
|
|
1302
|
+
getEntityRefs: (ctx: OperationEntityRefsContext<TInput>) => ListQueryOfflineEntityRef<ItemPayloadUnused>[];
|
|
1303
|
+
/**
|
|
1304
|
+
* Declares which list item refs must resolve before replaying this
|
|
1305
|
+
* operation.
|
|
1306
|
+
*/
|
|
1307
|
+
dependsOn?: (ctx: OperationEntityRefsContext<TInput>) => ListQueryOfflineEntityRef<ItemPayloadUnused>[]; /** Declares which upload ids must finish before replaying this operation. */
|
|
1308
|
+
dependsOnUploads?: (ctx: OperationEntityRefsContext<TInput>) => string[];
|
|
1309
|
+
} & ([ItemState | QueryPayload | ItemPayloadUnused] extends [never] ? never : unknown);
|
|
1310
|
+
/**
|
|
1311
|
+
* Builds a list-query offline operations map from a compact operation spec.
|
|
1312
|
+
*
|
|
1313
|
+
* Use this helper to define the full `persistentStorage.offline.operations` contract for a
|
|
1314
|
+
* list-query store while keeping each operation's type declaration short.
|
|
1315
|
+
*
|
|
1316
|
+
* Each operation key is described with {@link DefineOfflineOperation}, and this
|
|
1317
|
+
* helper expands it into the corresponding
|
|
1318
|
+
* {@link ListQueryOfflineOperationDefinition}. The runtime operation object
|
|
1319
|
+
* still needs to provide `getEntityRefs(...)`.
|
|
1320
|
+
*
|
|
1321
|
+
* @typeParam ItemState - List item state type for the owning store.
|
|
1322
|
+
* @typeParam QueryPayload - Query payload type used by the list store.
|
|
1323
|
+
* @typeParam ItemPayload - Item payload type used by the list store.
|
|
1324
|
+
* @typeParam TOperations - Operation map where each key declares its input, optional conflict payload, and optional temp-result type.
|
|
1325
|
+
*
|
|
1326
|
+
* @example
|
|
1327
|
+
* ```ts
|
|
1328
|
+
* type Operations = DefineListQueryOfflineOperations<
|
|
1329
|
+
* User,
|
|
1330
|
+
* { tableId: 'users' },
|
|
1331
|
+
* { tableId: 'users'; id: number } | string,
|
|
1332
|
+
* {
|
|
1333
|
+
* renameUser: DefineOfflineOperation<
|
|
1334
|
+
* { id: number; name: string }
|
|
1335
|
+
* >;
|
|
1336
|
+
* createUser: DefineOfflineOperation<
|
|
1337
|
+
* { name: string },
|
|
1338
|
+
* unknown,
|
|
1339
|
+
* { id: number; name: string }
|
|
1340
|
+
* >;
|
|
1341
|
+
* }
|
|
1342
|
+
* >;
|
|
1343
|
+
* ```
|
|
1344
|
+
*/
|
|
1345
|
+
type DefineListQueryOfflineOperations<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TOperations extends Record<string, DefineOfflineOperation>, TUploadRef extends ValidPayload = ValidPayload> = { [TName in keyof TOperations]: ListQueryOfflineOperationDefinition<ItemState, QueryPayload, ItemPayload, DocumentOperationInput<TOperations[TName]>, DocumentOperationConflict<TOperations[TName]>, DocumentOperationResult<TOperations[TName]>, DocumentOperationServerSnapshot<TOperations[TName]>, TUploadRef> };
|
|
1346
|
+
/**
|
|
1347
|
+
* Extracts operation conflict payload from a registered operation map.
|
|
1348
|
+
*
|
|
1349
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
1350
|
+
* @typeParam TName - Operation name whose conflict payload should be extracted.
|
|
1351
|
+
*/
|
|
1352
|
+
type OperationConflict<TOperations, TName extends keyof TOperations> = TOperations[TName] extends {
|
|
1353
|
+
conflictHandling?: OfflineConflictHandlingConfig<__LEGIT_ANY__, infer TConflict>;
|
|
1354
|
+
} ? TConflict : never;
|
|
1355
|
+
/**
|
|
1356
|
+
* Result returned when decoding a stored offline conflict payload.
|
|
1357
|
+
*
|
|
1358
|
+
* `ok: true` contains the typed conflict payload. `ok: false` contains a
|
|
1359
|
+
* machine-readable parse error describing why decoding was not possible.
|
|
1360
|
+
*/
|
|
1361
|
+
type ParsedOfflineResolutionConflictResultForOperation<TOperations, TName extends keyof TOperations & string> = Result<OperationConflict<TOperations, TName>, OfflineResolutionConflictParseError>;
|
|
1362
|
+
type ParsedOfflineResolutionConflictResultForStore<TOperations> = ParsedOfflineResolutionConflictResultForOperation<TOperations, keyof TOperations & string>;
|
|
1363
|
+
/**
|
|
1364
|
+
* Operation-aware offline resolution record for a specific registered operation.
|
|
1365
|
+
*
|
|
1366
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
1367
|
+
* @typeParam TName - Operation name whose stored resolution shape should be extracted.
|
|
1368
|
+
*/
|
|
1369
|
+
type OfflineResolutionRecordForOperation<TOperations, TName extends keyof TOperations & string> = (OfflineConflictResolutionRecord<OperationConflict<TOperations, TName>, OperationInput<TOperations, TName>> & {
|
|
1370
|
+
operation: TName;
|
|
1371
|
+
}) | (OfflineRetryExhaustedResolutionRecord<OperationInput<TOperations, TName>> & {
|
|
1372
|
+
operation: TName;
|
|
1373
|
+
});
|
|
1374
|
+
/**
|
|
1375
|
+
* Union of operation-aware offline resolution records for an operation registry.
|
|
1376
|
+
*
|
|
1377
|
+
* @typeParam TOperations - Operation registry to inspect.
|
|
1378
|
+
* @typeParam TName - Optional subset of operation names to include.
|
|
1379
|
+
*/
|
|
1380
|
+
type OfflineResolutionRecordForStore<TOperations, TName extends keyof TOperations & string = keyof TOperations & string> = { [K in TName]: OfflineResolutionRecordForOperation<TOperations, K> }[TName];
|
|
1381
|
+
type OfflineResolutionConflictParseErrorCode = 'not-conflict' | 'offline-not-configured' | 'operation-not-found' | 'conflict-handling-missing' | 'invalid-conflict-payload';
|
|
1382
|
+
/** Error returned when decoding a stored offline conflict payload fails. */
|
|
1383
|
+
declare class OfflineResolutionConflictParseError extends Error {
|
|
1384
|
+
code: OfflineResolutionConflictParseErrorCode;
|
|
1385
|
+
operation: string;
|
|
1386
|
+
kind?: OfflineResolutionRecord['kind'];
|
|
1387
|
+
rawValue?: unknown;
|
|
1388
|
+
validationError?: SchemaValidationError;
|
|
1389
|
+
constructor(args: {
|
|
1390
|
+
code: OfflineResolutionConflictParseErrorCode;
|
|
1391
|
+
operation: string;
|
|
1392
|
+
kind?: OfflineResolutionRecord['kind'];
|
|
1393
|
+
rawValue?: unknown;
|
|
1394
|
+
validationError?: SchemaValidationError;
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
//#endregion
|
|
1398
|
+
//#region src/persistentStorage/offline/mutationRuntime.d.ts
|
|
1399
|
+
/**
|
|
1400
|
+
* Successful result of an offline-enabled mutation attempt.
|
|
1401
|
+
*
|
|
1402
|
+
* `online` means the direct request completed and returned the server payload.
|
|
1403
|
+
* `queued` means the mutation was durably persisted for offline replay.
|
|
1404
|
+
*/
|
|
1405
|
+
type OfflineMutationResult<T> = {
|
|
1406
|
+
kind: 'online';
|
|
1407
|
+
data: Awaited<T>;
|
|
1408
|
+
} | {
|
|
1409
|
+
kind: 'queued';
|
|
1410
|
+
};
|
|
1411
|
+
//#endregion
|
|
1412
|
+
//#region src/utils/performMutation.d.ts
|
|
1413
|
+
type BlockWindowCloseHandler = () => {
|
|
1414
|
+
unblock: () => void;
|
|
1415
|
+
};
|
|
1416
|
+
type MutationDebounce = {
|
|
1417
|
+
context: string;
|
|
1418
|
+
payload: unknown;
|
|
1419
|
+
ms: number;
|
|
1420
|
+
};
|
|
1421
|
+
//#endregion
|
|
1422
|
+
//#region src/storeManager.d.ts
|
|
1423
|
+
type StoreManagerStoreDefaults = {
|
|
1424
|
+
/** Default minimum interval between low-priority fetches for attached stores. */readonly lowPriorityThrottleMs: number; /** Default coalescing window used by attached stores when they do not override it. */
|
|
1425
|
+
readonly baseCoalescingWindowMs: number; /** Shared window-close blocker used by mutations in attached stores. */
|
|
1426
|
+
readonly blockWindowClose: BlockWindowCloseHandler | null;
|
|
1427
|
+
};
|
|
1428
|
+
type StoreManagerOfflineApi<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
1429
|
+
/** Returns the shared offline config, when configured. */getOfflineConfig: () => OfflineSessionConfig<TUploadRef> | undefined; /** Latest effective runtime config for this manager's offline session. */
|
|
1430
|
+
getOfflineRuntimeConfig: () => OfflineRuntimeConfig; /** Updates runtime controls for this manager's offline session. */
|
|
1431
|
+
setOfflineRuntimeConfig: (update: OfflineRuntimeConfigUpdate) => Result<void, Error>; /** Resets runtime controls back to the static session config. */
|
|
1432
|
+
resetOfflineRuntimeConfig: () => void; /** Returns the latest aggregated offline status for this manager. */
|
|
1433
|
+
getOfflineStatus: () => GlobalOfflineStatus; /** Returns the latest aggregated offline entities for this manager. */
|
|
1434
|
+
getOfflineEntities: () => readonly GlobalOfflineEntity[]; /** Returns the latest aggregated offline resolutions for this manager. */
|
|
1435
|
+
getOfflineResolutions: () => readonly OfflineResolutionRecord[]; /** Returns the latest session-scoped offline uploads for this manager. */
|
|
1436
|
+
getOfflineUploads: () => readonly OfflineUpload<TUploadRef>[]; /** Resolves a staged upload id to its latest final ref, uploading first if needed. */
|
|
1437
|
+
resolveOfflineUpload: (id: string) => Promise<Result<TUploadRef, Error>>; /** Resolves multiple staged upload ids to their latest final refs. */
|
|
1438
|
+
resolveOfflineUploads: (ids: readonly string[]) => Promise<Result<Record<string, TUploadRef>, Error>>; /** Saves a session-scoped upload locally for later dependency resolution. */
|
|
1439
|
+
saveOfflineUpload: (args: {
|
|
1440
|
+
id: string;
|
|
1441
|
+
file: Blob | File;
|
|
1442
|
+
}) => Promise<Result<void, Error>>; /** Replaces a previously stored session-scoped upload. */
|
|
1443
|
+
replaceOfflineUpload: (args: {
|
|
1444
|
+
id: string;
|
|
1445
|
+
file: Blob | File;
|
|
1446
|
+
}) => Promise<Result<void, Error>>; /** Loads a previously stored session-scoped upload. */
|
|
1447
|
+
loadOfflineUpload: (id: string) => Promise<Result<File | null, Error>>; /** Deletes a stored upload when it is no longer referenced. */
|
|
1448
|
+
deleteOfflineUpload: (id: string) => Promise<Result<void, Error>>; /** React hook subscribing to the manager's aggregated offline status. */
|
|
1449
|
+
useOfflineStatus: () => GlobalOfflineStatus; /** React hook subscribing to the manager's aggregated offline entities. */
|
|
1450
|
+
useOfflineEntities: () => readonly GlobalOfflineEntity[]; /** React hook subscribing to the manager's aggregated offline resolutions. */
|
|
1451
|
+
useOfflineResolutions: () => readonly OfflineResolutionRecord[]; /** React hook subscribing to the manager's aggregated offline uploads. */
|
|
1452
|
+
useOfflineUploads: () => readonly OfflineUpload<TUploadRef>[];
|
|
1453
|
+
};
|
|
1454
|
+
type StoreManager<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
1455
|
+
/** Returns the active shared session / tenant key. */getSessionKey: () => string | false; /** Normalizes raw exceptions into the shared StoreError shape. */
|
|
1456
|
+
errorNormalizer: (exception: Error) => StoreError; /** Global fallback for persistent storage failures in attached stores. */
|
|
1457
|
+
onPersistentStorageError: PersistentStorageErrorHandler | undefined; /** Shared defaults used by attached stores unless a store-level override exists. */
|
|
1458
|
+
storeDefaults: StoreManagerStoreDefaults; /** Returns the unique ids of all currently registered store instances. */
|
|
1459
|
+
getAllStoreIds: () => string[]; /** Resets all registered stores except the ignored logical ids. */
|
|
1460
|
+
resetAll: (ignoreStores: string[]) => void;
|
|
1461
|
+
} & StoreManagerOfflineApi<TUploadRef>;
|
|
1462
|
+
type CreateStoreManagerOptions<TUploadRef extends ValidPayload = ValidPayload> = {
|
|
1463
|
+
/**
|
|
1464
|
+
* Returns the current authenticated session / tenant key shared by all
|
|
1465
|
+
* stores attached to this manager. Return `false` to disable session-scoped
|
|
1466
|
+
* behavior while no account is loaded.
|
|
1467
|
+
*/
|
|
1468
|
+
getSessionKey: () => string | false; /** Normalizes raw exceptions into the shared StoreError shape. */
|
|
1469
|
+
errorNormalizer: (exception: Error) => StoreError; /** Default minimum interval between low-priority fetches for attached stores. Defaults to 5ms. */
|
|
1470
|
+
lowPriorityThrottleMs?: number; /** Default coalescing window for attached stores. Defaults to 10ms. */
|
|
1471
|
+
baseCoalescingWindowMs?: number; /** Shared window-close blocker used by mutations in attached stores. Pass `null` to disable. */
|
|
1472
|
+
blockWindowClose?: BlockWindowCloseHandler | null; /** Global fallback for persistent storage failures when a store does not provide its own handler. */
|
|
1473
|
+
onPersistentStorageError?: PersistentStorageErrorHandler; /** Optional shared offline session config for every attached store. */
|
|
1474
|
+
offlineSession?: OfflineSessionConfig<TUploadRef>;
|
|
1475
|
+
};
|
|
1476
|
+
declare function createStoreManager<TUploadRef extends ValidPayload = ValidPayload>(options: CreateStoreManagerOptions<TUploadRef>): StoreManager<TUploadRef>;
|
|
1477
|
+
//#endregion
|
|
1478
|
+
//#region src/utils/browserTabsPriority.d.ts
|
|
1479
|
+
type BrowserTabsPriorityTimings = {
|
|
1480
|
+
heartbeatMs?: number;
|
|
1481
|
+
presenceTtlMs?: number;
|
|
1482
|
+
fetchLeaseMs?: number | ((lastFetchDuration: number) => number);
|
|
1483
|
+
};
|
|
1484
|
+
type BrowserTabsTabStatusMessage = {
|
|
1485
|
+
kind: 'tab-status';
|
|
1486
|
+
isFocused: boolean;
|
|
1487
|
+
lastFocusedAt: number;
|
|
1488
|
+
lastPresenceAt: number;
|
|
1489
|
+
};
|
|
1490
|
+
//#endregion
|
|
1491
|
+
//#region src/utils/browserTabsSync.d.ts
|
|
1492
|
+
type BrowserTabsStoreType = 'document' | 'collection' | 'listQuery' | 'offline';
|
|
1493
|
+
type BrowserTabsTransport = {
|
|
1494
|
+
postMessage: (message: unknown) => void;
|
|
1495
|
+
close: () => void;
|
|
1496
|
+
};
|
|
1497
|
+
type BrowserTabsTransportFactory = (options: {
|
|
1498
|
+
channelName: string;
|
|
1499
|
+
onMessage: (message: unknown) => void;
|
|
1500
|
+
}) => BrowserTabsTransport | null;
|
|
1501
|
+
type BrowserTabsMessageMeta = {
|
|
1502
|
+
protocolVersion: 1;
|
|
1503
|
+
messageId: string;
|
|
1504
|
+
storeType: BrowserTabsStoreType;
|
|
1505
|
+
sessionKey: string;
|
|
1506
|
+
tabId: string;
|
|
1507
|
+
seq: number;
|
|
1508
|
+
sentAt: number;
|
|
1509
|
+
};
|
|
1510
|
+
type SnapshotConsistency = 'optimistic' | 'confirmed';
|
|
1511
|
+
//#endregion
|
|
1512
|
+
//#region src/collectionStore/useMultipleItems.d.ts
|
|
1513
|
+
type UseMultipleItemsOptions$1<ItemState extends ValidStoreState, Selected> = {
|
|
1514
|
+
selector?: (data: ItemState | null) => Selected;
|
|
1515
|
+
returnIdleStatus?: boolean;
|
|
1516
|
+
returnRefetchingStatus?: boolean;
|
|
1517
|
+
omitPayload?: boolean; /** Only loads the data if it is not already loaded and skip any other refetches */
|
|
1518
|
+
disableRefetches?: boolean;
|
|
1519
|
+
disableRefetchOnMount?: boolean;
|
|
1520
|
+
isOffScreen?: boolean;
|
|
1521
|
+
/**
|
|
1522
|
+
* Debounces automatic fetches caused by payload changes, while selection
|
|
1523
|
+
* still reads from the latest payload. Supports trailing debounce via `ms`,
|
|
1524
|
+
* optional `leading`, and optional `maxWait`.
|
|
1525
|
+
*/
|
|
1526
|
+
debouncePayload?: PayloadDebounce;
|
|
1527
|
+
};
|
|
1528
|
+
//#endregion
|
|
1529
|
+
//#region src/collectionStore/useItem.d.ts
|
|
1530
|
+
type UseItemOptions$1<ItemState extends ValidStoreState, Selected> = UseMultipleItemsOptions$1<ItemState, Selected> & {
|
|
1531
|
+
/**
|
|
1532
|
+
* Forces a high-priority fetch on mount and keeps the hook in `loading`
|
|
1533
|
+
* until the current payload finishes loading. Cannot be combined with
|
|
1534
|
+
* `debouncePayload`.
|
|
1535
|
+
*/
|
|
1536
|
+
ensureIsLoaded?: boolean;
|
|
1537
|
+
};
|
|
1538
|
+
//#endregion
|
|
1539
|
+
//#region src/collectionStore/collectionStore.d.ts
|
|
62
1540
|
type CollectionItemStatus = TSDFStatus;
|
|
63
|
-
type TSFDCollectionItem<ItemState extends ValidStoreState, ItemPayload extends ValidPayload
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
1541
|
+
type TSFDCollectionItem<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = {
|
|
1542
|
+
data: ItemState | null;
|
|
1543
|
+
error: StoreError | null;
|
|
1544
|
+
status: CollectionItemStatus;
|
|
1545
|
+
payload: ItemPayload;
|
|
1546
|
+
refetchOnMount: false | FetchType;
|
|
1547
|
+
wasLoaded: boolean;
|
|
70
1548
|
};
|
|
71
|
-
type TSFDCollectionState<ItemState extends ValidStoreState, ItemPayload extends ValidPayload
|
|
72
|
-
type TSFDUseCollectionItemReturn<Selected, ItemPayload,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1549
|
+
type TSFDCollectionState<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = Record<string, TSFDCollectionItem<ItemState, ItemPayload> | null>;
|
|
1550
|
+
type TSFDUseCollectionItemReturn<Selected, ItemPayload, QueryMetadata extends undefined | Record<string, unknown> = undefined> = {
|
|
1551
|
+
data: Selected;
|
|
1552
|
+
status: CollectionItemStatus | 'idle' | 'deleted';
|
|
1553
|
+
payload: ItemPayload | undefined;
|
|
1554
|
+
error: StoreError | null;
|
|
1555
|
+
itemStateKey: string;
|
|
1556
|
+
isLoading: boolean; /** Whether this result has local offline changes that still need to sync to the server. */
|
|
1557
|
+
pendingSync: boolean;
|
|
1558
|
+
queryMetadata: QueryMetadata;
|
|
80
1559
|
};
|
|
81
|
-
type
|
|
82
|
-
|
|
83
|
-
|
|
1560
|
+
type CollectionUseMultipleItemsQuery<ItemPayload extends ValidPayload, QueryMetadata extends undefined | Record<string, unknown> = undefined> = {
|
|
1561
|
+
payload: ItemPayload;
|
|
1562
|
+
queryMetadata?: QueryMetadata;
|
|
1563
|
+
omitPayload?: boolean; /** Only loads the data if it is not already loaded and skip any other refetches */
|
|
1564
|
+
disableRefetches?: boolean;
|
|
1565
|
+
disableRefetchOnMount?: boolean;
|
|
1566
|
+
returnIdleStatus?: boolean;
|
|
1567
|
+
returnRefetchingStatus?: boolean;
|
|
1568
|
+
isOffScreen?: boolean;
|
|
84
1569
|
};
|
|
85
1570
|
type OnCollectionItemInvalidate<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = (props: {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
1571
|
+
itemState: ItemState;
|
|
1572
|
+
payload: ItemPayload;
|
|
1573
|
+
priority: FetchType;
|
|
89
1574
|
}) => void;
|
|
90
|
-
type
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
1575
|
+
type CollectionInitialStateItem<ItemPayload extends ValidPayload, ItemState extends ValidStoreState> = {
|
|
1576
|
+
payload: ItemPayload;
|
|
1577
|
+
data: ItemState;
|
|
1578
|
+
};
|
|
1579
|
+
type CollectionStoreStoreEvents<ItemPayload extends ValidPayload> = {
|
|
1580
|
+
/** Emitted when a mutation begins executing */mutationStart: {
|
|
1581
|
+
mutationId: number;
|
|
1582
|
+
items: ItemPayload[];
|
|
1583
|
+
}; /** Emitted when a mutation completes, fails, or is skipped */
|
|
1584
|
+
mutationEnd: {
|
|
1585
|
+
mutationId: number;
|
|
1586
|
+
items: ItemPayload[];
|
|
1587
|
+
status: 'success' | 'error' | 'skipped';
|
|
1588
|
+
}; /** Emitted when an offline temp item is reconciled to its final payload. */
|
|
1589
|
+
tempEntityReconciled: {
|
|
1590
|
+
tempId: ItemPayload;
|
|
1591
|
+
finalPayload: ItemPayload;
|
|
1592
|
+
};
|
|
1593
|
+
};
|
|
1594
|
+
type CollectionStateCleanup<ItemPayload extends ValidPayload> = {
|
|
1595
|
+
reason: 'cacheLimitEviction';
|
|
1596
|
+
itemKeys: string[];
|
|
1597
|
+
payloads: ItemPayload[];
|
|
1598
|
+
};
|
|
1599
|
+
type CollectionBrowserTabsMessage<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = (BrowserTabsMessageMeta & BrowserTabsTabStatusMessage) | (BrowserTabsMessageMeta & {
|
|
1600
|
+
kind: 'collection-item-snapshot';
|
|
1601
|
+
itemKey: string;
|
|
1602
|
+
consistency: SnapshotConsistency;
|
|
1603
|
+
item: TSFDCollectionItem<ItemState, ItemPayload> | null;
|
|
1604
|
+
}) | (BrowserTabsMessageMeta & {
|
|
1605
|
+
kind: 'fetch-start';
|
|
1606
|
+
targetKey: string;
|
|
1607
|
+
requestIds: string[];
|
|
1608
|
+
startedAt: number;
|
|
1609
|
+
}) | (BrowserTabsMessageMeta & {
|
|
1610
|
+
kind: 'fetch-success';
|
|
1611
|
+
targetKey: string;
|
|
1612
|
+
requestIds: string[];
|
|
1613
|
+
startedAt: number;
|
|
1614
|
+
duration: number;
|
|
1615
|
+
});
|
|
1616
|
+
type InternalCollectionOfflineOperations<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = Record<string, AnyOfflineOperationDefinition & {
|
|
1617
|
+
getEntityRefs: (ctx: {
|
|
1618
|
+
input: __LEGIT_ANY__;
|
|
1619
|
+
}) => CollectionOfflineEntityRef<ItemPayload>[];
|
|
1620
|
+
}> & ([ItemState | ItemPayload] extends [never] ? never : unknown);
|
|
1621
|
+
type CollectionOfflineOperationsConfig<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = InternalCollectionOfflineOperations<ItemState, ItemPayload> | null;
|
|
1622
|
+
type CollectionStoreOptions<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, TOfflineOperations extends CollectionOfflineOperationsConfig<ItemState, ItemPayload> = null, StorageState = unknown> = {
|
|
1623
|
+
debugName?: string; /** Stable id shared by the same logical collection store across browser tabs. */
|
|
1624
|
+
id: string; /** Shared global store manager providing session scoping and error normalization. */
|
|
1625
|
+
storeManager: StoreManager;
|
|
1626
|
+
fetchFn: (params: ItemPayload, signal: AbortSignal) => Promise<ItemState>; /** Optional batch fetch function for fetching multiple items at once */
|
|
1627
|
+
batchFetchFn?: (payloads: ItemPayload[], signal: AbortSignal, batchKey: string) => Promise<Map<ItemPayload, ItemState | Error>>; /** Optional function to group batch fetches by key. Return false to fall back to individual fetchFn */
|
|
1628
|
+
getItemsBatchKey?: (payload: ItemPayload) => string | false; /** Max items per batch - triggers immediate fetch when reached */
|
|
1629
|
+
maxBatchSize?: number; /** Maximum number of cached items kept in memory. Defaults to 5,000. Inactive items are evicted in LRU order, while mounted hook items stay protected. */
|
|
1630
|
+
maxItems?: number; /** Called when cache-limit eviction removes items from in-memory state. */
|
|
1631
|
+
onStateCleanup?: (cleanup: CollectionStateCleanup<ItemPayload>) => void;
|
|
1632
|
+
getCollectionItemKey?: (params: ItemPayload) => ValidPayload | unknown[]; /** Overrides the manager's default minimum interval between low-priority fetches for this store. */
|
|
1633
|
+
lowPriorityThrottleMs?: number; /** Overrides the manager's default coalescing window for this store. */
|
|
1634
|
+
baseCoalescingWindowMs?: number;
|
|
1635
|
+
mediumPriorityDelayMs?: number;
|
|
1636
|
+
dynamicRealtimeThrottleMs?: (params: {
|
|
1637
|
+
lastFetchDuration: number;
|
|
1638
|
+
windowIsNotFocused: boolean;
|
|
1639
|
+
}) => number;
|
|
1640
|
+
revalidateOnWindowFocus?: boolean | (() => boolean);
|
|
1641
|
+
/** Reconnect-specific cooldown. The first reconnect revalidates immediately;
|
|
1642
|
+
* additional reconnects within the cooldown are coalesced into one trailing
|
|
1643
|
+
* revalidation. Set to `0` to disable this cooldown. */
|
|
1644
|
+
transportReconnectCooldownMs?: number;
|
|
1645
|
+
onInvalidate?: OnCollectionItemInvalidate<ItemState, ItemPayload>;
|
|
1646
|
+
onSchedulerEvent?: (event: RequestSchedulerEvents, data?: RequestSchedulerEventData) => void;
|
|
1647
|
+
onMutationError?: (error: unknown, options: {
|
|
1648
|
+
silentErrors?: boolean;
|
|
1649
|
+
}) => void;
|
|
1650
|
+
usesRealTimeUpdates?: boolean;
|
|
1651
|
+
/** Opt-in persistent storage configuration. When provided, cached items are loaded
|
|
1652
|
+
* from storage on first read and saved back on successful fetches.
|
|
1653
|
+
* Session scoping always reuses this store manager's `getSessionKey`, and the
|
|
1654
|
+
* persisted namespace always reuses this store's `id`. */
|
|
1655
|
+
persistentStorage?: CollectionPersistentStorageConfig<ItemState, ItemPayload, StorageState, TOfflineOperations>;
|
|
1656
|
+
};
|
|
1657
|
+
type CollectionStoreEvents = {
|
|
1658
|
+
invalidateData: {
|
|
1659
|
+
priority: FetchType;
|
|
1660
|
+
itemKey: string;
|
|
1661
|
+
};
|
|
1662
|
+
};
|
|
1663
|
+
type CollectionFilterItemsFn<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = (params: ItemPayload, data: ItemState | null) => boolean;
|
|
1664
|
+
type ResolvedCollectionOfflineOperations<TOfflineOperations> = TOfflineOperations extends null ? Record<never, never> : Exclude<TOfflineOperations, null>;
|
|
1665
|
+
type CollectionMutationPayload<ItemPayload extends ValidPayload> = ItemPayload | ItemPayload[] | null;
|
|
1666
|
+
type CollectionMutationTarget<ItemPayload extends ValidPayload> = ItemPayload | ItemPayload[];
|
|
1667
|
+
type CollectionMutationPayloadToUse<ItemPayload extends ValidPayload> = CollectionMutationTarget<ItemPayload>;
|
|
1668
|
+
type CollectionMutationArgsBase<T, ItemPayload extends ValidPayload> = {
|
|
1669
|
+
optimisticUpdate?: (payload: CollectionMutationPayloadToUse<ItemPayload>) => void | boolean;
|
|
1670
|
+
mutation: (payload: CollectionMutationPayloadToUse<ItemPayload>) => Promise<T>;
|
|
1671
|
+
onSuccess?: (response: Awaited<T>, payload: CollectionMutationPayloadToUse<ItemPayload>) => void;
|
|
1672
|
+
revalidateOnSuccess?: boolean;
|
|
1673
|
+
silentErrors?: boolean;
|
|
1674
|
+
debounce?: {
|
|
1675
|
+
context: string;
|
|
1676
|
+
payload: __LEGIT_ANY__;
|
|
1677
|
+
ms: number;
|
|
1678
|
+
};
|
|
1679
|
+
};
|
|
1680
|
+
type CollectionOnlineMutationArgs<T, ItemPayload extends ValidPayload> = CollectionMutationArgsBase<T, ItemPayload> & {
|
|
1681
|
+
offline?: undefined;
|
|
1682
|
+
upload?: undefined;
|
|
1683
|
+
};
|
|
1684
|
+
type CollectionOfflineMutationArgs<T, ItemState extends ValidStoreState, ItemPayload extends ValidPayload, TOfflineOperations extends CollectionOfflineOperationsConfig<ItemState, ItemPayload>> = CollectionMutationArgsBase<T, ItemPayload> & {
|
|
1685
|
+
offline: TOfflineOperations extends null ? never : OfflineMutationInput<Exclude<TOfflineOperations, null>>;
|
|
1686
|
+
upload?: OfflineMutationUploadsInput;
|
|
1687
|
+
};
|
|
1688
|
+
type CollectionPerformMutation<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, TOfflineOperations extends CollectionOfflineOperationsConfig<ItemState, ItemPayload>> = {
|
|
1689
|
+
<T>(payload: CollectionMutationTarget<ItemPayload>, args: CollectionOnlineMutationArgs<T, ItemPayload>): Promise<Result<Awaited<T>, StoreMutationError | MutationSkipped>>;
|
|
1690
|
+
<T>(payload: CollectionMutationTarget<ItemPayload>, args: CollectionOfflineMutationArgs<T, ItemState, ItemPayload, TOfflineOperations>): Promise<Result<OfflineMutationResult<T>, StoreMutationError | MutationSkipped>>;
|
|
1691
|
+
<T>(payload: null, args: Omit<CollectionOnlineMutationArgs<T, ItemPayload>, 'optimisticUpdate'>): Promise<Result<Awaited<T>, StoreMutationError | MutationSkipped>>;
|
|
1692
|
+
<T>(payload: null, args: Omit<CollectionOfflineMutationArgs<T, ItemState, ItemPayload, TOfflineOperations>, 'optimisticUpdate'>): Promise<Result<OfflineMutationResult<T>, StoreMutationError | MutationSkipped>>;
|
|
1693
|
+
<T>(payload: CollectionMutationPayload<ItemPayload>, args: CollectionOnlineMutationArgs<T, ItemPayload> | CollectionOfflineMutationArgs<T, ItemState, ItemPayload, TOfflineOperations>): Promise<Result<Awaited<T> | OfflineMutationResult<T>, StoreMutationError | MutationSkipped>>;
|
|
1694
|
+
};
|
|
1695
|
+
type CollectionStore<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, TOfflineOperations extends CollectionOfflineOperationsConfig<ItemState, ItemPayload> = null> = {
|
|
1696
|
+
store: Store<TSFDCollectionState<ItemState, ItemPayload>>;
|
|
1697
|
+
events: Emitter<CollectionStoreEvents>;
|
|
1698
|
+
storeEvents: Emitter<CollectionStoreStoreEvents<ItemPayload>>;
|
|
1699
|
+
readonly invalidationWasTriggered: Set<string>;
|
|
1700
|
+
scheduleFetch: {
|
|
1701
|
+
(fetchType: FetchType, payload: ItemPayload, options?: ScheduleFetchOptions): ScheduleFetchResults;
|
|
1702
|
+
(fetchType: FetchType, payload: ItemPayload[], options?: ScheduleFetchOptions): ScheduleFetchResults[];
|
|
1703
|
+
};
|
|
1704
|
+
awaitFetch: (params: ItemPayload, options?: {
|
|
1705
|
+
timeoutMs?: number;
|
|
1706
|
+
}) => Promise<{
|
|
1707
|
+
data: ItemState;
|
|
1708
|
+
error: null;
|
|
1709
|
+
} | {
|
|
1710
|
+
data: null;
|
|
1711
|
+
error: StoreFetchError;
|
|
1712
|
+
}>;
|
|
1713
|
+
useMultipleItems: <Selected = ItemState | null, QueryMetadata extends undefined | Record<string, unknown> = undefined>(items: CollectionUseMultipleItemsQuery<ItemPayload, QueryMetadata>[], options?: UseMultipleItemsOptions$1<ItemState, Selected>) => readonly TSFDUseCollectionItemReturn<Selected, ItemPayload, QueryMetadata>[];
|
|
1714
|
+
useItem: <Selected = ItemState | null>(payload: ItemPayload | undefined | false | null, options?: UseItemOptions$1<ItemState, Selected>) => TSFDUseCollectionItemReturn<Selected, ItemPayload>;
|
|
1715
|
+
useListItemIsLoading: (payload: ItemPayload, args: {
|
|
1716
|
+
itemId: string;
|
|
1717
|
+
selector: (data: ItemState | null) => unknown;
|
|
1718
|
+
loadItemFallback?: () => void;
|
|
1719
|
+
ensureIsLoaded?: boolean;
|
|
1720
|
+
}) => boolean;
|
|
1721
|
+
useListItemIsDeleted: (payload: ItemPayload, args: {
|
|
1722
|
+
itemId: string;
|
|
1723
|
+
selector: (data: ItemState | null) => unknown;
|
|
1724
|
+
onDelete?: () => void;
|
|
1725
|
+
ensureIsLoaded?: boolean;
|
|
1726
|
+
}) => boolean;
|
|
1727
|
+
useListItem: <Selected>(payload: ItemPayload, args: {
|
|
1728
|
+
itemId: string;
|
|
1729
|
+
selector: (data: ItemState | null) => Selected;
|
|
1730
|
+
loadItemFallback?: () => void;
|
|
1731
|
+
onDelete?: () => void;
|
|
1732
|
+
ensureIsLoaded?: boolean;
|
|
1733
|
+
}) => {
|
|
1734
|
+
isLoading: boolean;
|
|
1735
|
+
isDeleted: boolean;
|
|
1736
|
+
data: Selected;
|
|
1737
|
+
};
|
|
1738
|
+
reset: () => void;
|
|
1739
|
+
dispose: () => void;
|
|
1740
|
+
preloadItemFromStorage: (params: ItemPayload | ItemPayload[]) => Promise<PersistentStoragePreloadResult<ItemPayload>[]>;
|
|
1741
|
+
getItemKey: (params: ItemPayload) => string;
|
|
1742
|
+
getItemState: {
|
|
1743
|
+
(params: ItemPayload): TSFDCollectionItem<ItemState, ItemPayload> | undefined | null;
|
|
1744
|
+
(params: ItemPayload[] | CollectionFilterItemsFn<ItemState, ItemPayload>): TSFDCollectionItem<ItemState, ItemPayload>[];
|
|
1745
|
+
};
|
|
1746
|
+
getOfflineEntities: () => GlobalOfflineEntity[];
|
|
1747
|
+
useOfflineEntities: () => readonly GlobalOfflineEntity[];
|
|
1748
|
+
useOfflineResolutions: () => readonly OfflineResolutionRecord[];
|
|
1749
|
+
getOfflineResolutions: () => OfflineResolutionRecord[];
|
|
1750
|
+
parseOfflineResolutionConflict: (resolution: OfflineResolutionRecord) => ParsedOfflineResolutionConflictResultForStore<ResolvedCollectionOfflineOperations<TOfflineOperations>>;
|
|
1751
|
+
resolveOfflineResolution: <TName extends keyof ResolvedCollectionOfflineOperations<TOfflineOperations> & string>(resolutionId: string, operationName: TName, resolution: OfflineResolutionActionForOperation<ResolvedCollectionOfflineOperations<TOfflineOperations>, TName>) => Promise<void> | void;
|
|
1752
|
+
startMutation: (fetchParams: ItemPayload | ItemPayload[] | CollectionFilterItemsFn<ItemState, ItemPayload>) => () => void;
|
|
1753
|
+
invalidateItem: (itemPayload: ItemPayload | ItemPayload[] | CollectionFilterItemsFn<ItemState, ItemPayload>, priority?: FetchType) => void;
|
|
1754
|
+
updateItemState: (fetchParams: ItemPayload | ItemPayload[] | CollectionFilterItemsFn<ItemState, ItemPayload>, produceNewData: (draftData: ItemState, collectionItem: TSFDCollectionItem<ItemState, ItemPayload>) => void | ItemState, options?: {
|
|
1755
|
+
ifNothingWasUpdated?: () => void;
|
|
1756
|
+
}) => boolean;
|
|
1757
|
+
addItemToState: (fetchParams: ItemPayload, data: ItemState) => void;
|
|
1758
|
+
deleteItemState: (fetchParams: ItemPayload | ItemPayload[] | CollectionFilterItemsFn<ItemState, ItemPayload>) => void;
|
|
1759
|
+
performMutation: CollectionPerformMutation<ItemState, ItemPayload, TOfflineOperations>;
|
|
1760
|
+
onTransportReconnect: () => void;
|
|
1761
|
+
};
|
|
1762
|
+
declare function createCollectionStore<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, TOfflineOperations extends CollectionOfflineOperationsConfig<ItemState, ItemPayload> = null, StorageState = unknown>({
|
|
1763
|
+
debugName,
|
|
1764
|
+
id,
|
|
1765
|
+
storeManager,
|
|
1766
|
+
fetchFn,
|
|
1767
|
+
batchFetchFn,
|
|
1768
|
+
getItemsBatchKey,
|
|
1769
|
+
maxBatchSize,
|
|
1770
|
+
maxItems,
|
|
1771
|
+
onStateCleanup,
|
|
1772
|
+
lowPriorityThrottleMs: storeLowPriorityThrottleMs,
|
|
1773
|
+
baseCoalescingWindowMs: storeBaseCoalescingWindowMs,
|
|
1774
|
+
mediumPriorityDelayMs,
|
|
1775
|
+
dynamicRealtimeThrottleMs,
|
|
1776
|
+
revalidateOnWindowFocus,
|
|
1777
|
+
transportReconnectCooldownMs,
|
|
1778
|
+
getCollectionItemKey: filterCollectionItemObjKey,
|
|
1779
|
+
onInvalidate,
|
|
1780
|
+
onSchedulerEvent,
|
|
1781
|
+
onMutationError,
|
|
1782
|
+
usesRealTimeUpdates,
|
|
1783
|
+
persistentStorage: persistentStorageConfig,
|
|
1784
|
+
'~test': testOptions
|
|
1785
|
+
}: CollectionStoreOptions<ItemState, ItemPayload, TOfflineOperations, StorageState>): CollectionStore<ItemState, ItemPayload, TOfflineOperations>;
|
|
1786
|
+
//#endregion
|
|
1787
|
+
//#region src/documentStore.d.ts
|
|
1788
|
+
type DocumentStatus = 'idle' | TSDFStatus;
|
|
1789
|
+
type TSDFUseDocumentReturn<Selected> = {
|
|
1790
|
+
status: DocumentStatus;
|
|
1791
|
+
data: Selected;
|
|
1792
|
+
error: StoreError | null;
|
|
1793
|
+
isLoading: boolean; /** Whether this result has local offline changes that still need to sync to the server. */
|
|
1794
|
+
pendingSync: boolean;
|
|
1795
|
+
};
|
|
1796
|
+
type DocumentStoreState<State extends ValidStoreState> = {
|
|
1797
|
+
data: State | null;
|
|
1798
|
+
error: StoreError | null;
|
|
1799
|
+
status: DocumentStatus;
|
|
1800
|
+
refetchOnMount: false | FetchType;
|
|
1801
|
+
};
|
|
1802
|
+
type DocumentStoreEvents = {
|
|
1803
|
+
invalidateData: FetchType;
|
|
1804
|
+
};
|
|
1805
|
+
type OnDocumentInvalidate = (priority: FetchType) => void;
|
|
1806
|
+
type DocumentStoreStoreEvents = {
|
|
1807
|
+
/** Emitted when a mutation begins executing */mutationStart: {
|
|
1808
|
+
mutationId: number;
|
|
1809
|
+
}; /** Emitted when a mutation completes, fails, or is skipped */
|
|
1810
|
+
mutationEnd: {
|
|
1811
|
+
mutationId: number;
|
|
1812
|
+
status: 'success' | 'error' | 'skipped';
|
|
1813
|
+
};
|
|
1814
|
+
};
|
|
1815
|
+
type DocumentBrowserTabsMessage<State extends ValidStoreState> = (BrowserTabsMessageMeta & BrowserTabsTabStatusMessage) | (BrowserTabsMessageMeta & {
|
|
1816
|
+
kind: 'document-snapshot';
|
|
1817
|
+
consistency: SnapshotConsistency;
|
|
1818
|
+
data: State | null;
|
|
1819
|
+
}) | (BrowserTabsMessageMeta & {
|
|
1820
|
+
kind: 'fetch-start';
|
|
1821
|
+
targetKey: 'document';
|
|
1822
|
+
requestIds: string[];
|
|
1823
|
+
startedAt: number;
|
|
1824
|
+
}) | (BrowserTabsMessageMeta & {
|
|
1825
|
+
kind: 'fetch-success';
|
|
1826
|
+
targetKey: 'document';
|
|
1827
|
+
requestIds: string[];
|
|
1828
|
+
startedAt: number;
|
|
1829
|
+
duration: number;
|
|
1830
|
+
});
|
|
1831
|
+
type InternalDocumentOfflineOperations<State extends ValidStoreState> = Record<string, AnyOfflineOperationDefinition<__LEGIT_ANY__>> & ([State] extends [never] ? never : unknown);
|
|
1832
|
+
type DocumentOfflineOperationsConfig<State extends ValidStoreState> = InternalDocumentOfflineOperations<State> | null;
|
|
1833
|
+
type DocumentStoreOptions<State extends ValidStoreState, TOfflineOperations extends DocumentOfflineOperationsConfig<State> = null, StorageState = unknown> = {
|
|
1834
|
+
debugName?: string; /** Stable id shared by the same logical document store across browser tabs. */
|
|
1835
|
+
id: string; /** Shared global store manager providing session scoping and error normalization. */
|
|
1836
|
+
storeManager: StoreManager;
|
|
1837
|
+
fetchFn: (signal: AbortSignal) => Promise<State>; /** Overrides the manager's default minimum interval between low-priority fetches for this store. */
|
|
1838
|
+
lowPriorityThrottleMs?: number; /** Overrides the manager's default coalescing window for this store. */
|
|
1839
|
+
baseCoalescingWindowMs?: number;
|
|
1840
|
+
dynamicRealtimeThrottleMs?: (params: {
|
|
1841
|
+
lastFetchDuration: number;
|
|
1842
|
+
windowIsNotFocused: boolean;
|
|
1843
|
+
}) => number;
|
|
1844
|
+
revalidateOnWindowFocus?: boolean | (() => boolean);
|
|
1845
|
+
/** Reconnect-specific cooldown. The first reconnect revalidates immediately;
|
|
1846
|
+
* additional reconnects within the cooldown are coalesced into one trailing
|
|
1847
|
+
* revalidation. Set to `0` to disable this cooldown. */
|
|
1848
|
+
transportReconnectCooldownMs?: number;
|
|
1849
|
+
mediumPriorityDelayMs?: number;
|
|
1850
|
+
onSchedulerEvent?: (event: RequestSchedulerEvents, data?: RequestSchedulerEventData) => void;
|
|
1851
|
+
onMutationError?: (error: unknown, options: {
|
|
1852
|
+
dontShowToast?: boolean;
|
|
1853
|
+
}) => void;
|
|
1854
|
+
usesRealTimeUpdates?: boolean;
|
|
1855
|
+
/** Opt-in persistent storage configuration. When provided, cached data is loaded
|
|
1856
|
+
* from storage on first read and saved back on successful fetches.
|
|
1857
|
+
* Session scoping always reuses this store manager's `getSessionKey`, and the
|
|
1858
|
+
* persisted namespace always reuses this store's `id`. */
|
|
1859
|
+
persistentStorage?: DocumentPersistentStorageConfig<State, StorageState, TOfflineOperations>;
|
|
1860
|
+
};
|
|
1861
|
+
type ResolvedDocumentOfflineOperations<TOfflineOperations> = TOfflineOperations extends null ? Record<never, never> : Exclude<TOfflineOperations, null>;
|
|
1862
|
+
type DocumentUpdateState<State extends ValidStoreState> = (produceNewData: (draftData: State) => State | void | undefined) => boolean;
|
|
1863
|
+
type DocumentMutationContext<State extends ValidStoreState> = {
|
|
1864
|
+
updateState: DocumentUpdateState<State>;
|
|
1865
|
+
currentState: State | null;
|
|
1866
|
+
};
|
|
1867
|
+
type DocumentMutationArgsBase<State extends ValidStoreState, T> = {
|
|
1868
|
+
optimisticUpdate?: (currentState: State | null) => void | boolean;
|
|
1869
|
+
mutation: (ctx: DocumentMutationContext<State>) => Promise<T>;
|
|
1870
|
+
debounce?: {
|
|
1871
|
+
context: string;
|
|
1872
|
+
payload: __LEGIT_ANY__;
|
|
1873
|
+
ms: number;
|
|
1874
|
+
};
|
|
1875
|
+
dontShowErrorToast?: boolean;
|
|
1876
|
+
revalidateOnSuccess?: boolean;
|
|
1877
|
+
};
|
|
1878
|
+
type DocumentOnlineMutationArgs<State extends ValidStoreState, T> = DocumentMutationArgsBase<State, T> & {
|
|
1879
|
+
offline?: undefined;
|
|
1880
|
+
upload?: undefined;
|
|
1881
|
+
};
|
|
1882
|
+
type DocumentOfflineMutationArgs<State extends ValidStoreState, T, TOfflineOperations extends DocumentOfflineOperationsConfig<State>> = DocumentMutationArgsBase<State, T> & {
|
|
1883
|
+
offline: TOfflineOperations extends null ? never : OfflineMutationInput<Exclude<TOfflineOperations, null>>;
|
|
1884
|
+
upload?: OfflineMutationUploadsInput;
|
|
1885
|
+
};
|
|
1886
|
+
type DocumentPerformMutation<State extends ValidStoreState, TOfflineOperations extends DocumentOfflineOperationsConfig<State>> = {
|
|
1887
|
+
<T>(args: DocumentOnlineMutationArgs<State, T>): Promise<Result<Awaited<T>, StoreMutationError | MutationSkipped>>;
|
|
1888
|
+
<T>(args: DocumentOfflineMutationArgs<State, T, TOfflineOperations>): Promise<Result<OfflineMutationResult<T>, StoreMutationError | MutationSkipped>>;
|
|
1889
|
+
<T>(args: DocumentOnlineMutationArgs<State, T> | DocumentOfflineMutationArgs<State, T, TOfflineOperations>): Promise<Result<Awaited<T> | OfflineMutationResult<T>, StoreMutationError | MutationSkipped>>;
|
|
1890
|
+
};
|
|
1891
|
+
type DocumentStore<State extends ValidStoreState, TOfflineOperations extends DocumentOfflineOperationsConfig<State> = null> = {
|
|
1892
|
+
store: Store<DocumentStoreState<State>>;
|
|
1893
|
+
events: Emitter<DocumentStoreEvents>;
|
|
1894
|
+
storeEvents: Emitter<DocumentStoreStoreEvents>;
|
|
1895
|
+
readonly invalidationWasTriggered: boolean;
|
|
1896
|
+
scheduleFetch: (fetchType: FetchType, options?: ScheduleFetchOptions) => ScheduleFetchResults;
|
|
1897
|
+
awaitFetch: (options?: {
|
|
1898
|
+
timeoutMs?: number;
|
|
1899
|
+
}) => Promise<{
|
|
1900
|
+
data: State;
|
|
1901
|
+
error: null;
|
|
1902
|
+
} | {
|
|
1903
|
+
data: null;
|
|
1904
|
+
error: StoreFetchError;
|
|
1905
|
+
}>;
|
|
1906
|
+
preloadPersistentStorage: () => Promise<void>;
|
|
1907
|
+
invalidateData: (priority?: FetchType) => void;
|
|
1908
|
+
updateState: DocumentUpdateState<State>;
|
|
1909
|
+
reset: () => void;
|
|
1910
|
+
dispose: () => void;
|
|
1911
|
+
startMutation: () => () => boolean;
|
|
1912
|
+
getOfflineEntities: () => GlobalOfflineEntity[];
|
|
1913
|
+
useOfflineEntities: () => readonly GlobalOfflineEntity[];
|
|
1914
|
+
useOfflineResolutions: () => readonly OfflineResolutionRecord[];
|
|
1915
|
+
getOfflineResolutions: () => OfflineResolutionRecord[];
|
|
1916
|
+
parseOfflineResolutionConflict: (resolution: OfflineResolutionRecord) => ParsedOfflineResolutionConflictResultForStore<ResolvedDocumentOfflineOperations<TOfflineOperations>>;
|
|
1917
|
+
resolveOfflineResolution: <TName extends keyof ResolvedDocumentOfflineOperations<TOfflineOperations> & string>(resolutionId: string, operationName: TName, resolution: OfflineResolutionActionForOperation<ResolvedDocumentOfflineOperations<TOfflineOperations>, TName>) => Promise<void> | void;
|
|
1918
|
+
useDocument: <Selected = State | null>(args?: {
|
|
1919
|
+
selector?: (data: State | null) => Selected;
|
|
1920
|
+
disabled?: boolean;
|
|
1921
|
+
isOffScreen?: boolean;
|
|
1922
|
+
disableRefetches?: boolean;
|
|
94
1923
|
disableRefetchOnMount?: boolean;
|
|
95
1924
|
returnIdleStatus?: boolean;
|
|
1925
|
+
ensureIsLoaded?: boolean;
|
|
96
1926
|
returnRefetchingStatus?: boolean;
|
|
97
|
-
|
|
1927
|
+
}) => TSDFUseDocumentReturn<Selected>;
|
|
1928
|
+
useListItemIsLoading: (args: {
|
|
1929
|
+
itemId: string;
|
|
1930
|
+
selector: (data: State | null) => unknown;
|
|
1931
|
+
loadItemFallback?: () => void;
|
|
1932
|
+
ensureIsLoaded?: boolean;
|
|
1933
|
+
}) => boolean;
|
|
1934
|
+
useListItemIsDeleted: (args: {
|
|
1935
|
+
itemId: string;
|
|
1936
|
+
selector: (data: State | null) => unknown;
|
|
1937
|
+
onDelete?: () => void;
|
|
1938
|
+
ensureIsLoaded?: boolean;
|
|
1939
|
+
}) => boolean;
|
|
1940
|
+
useListItem: <Selected>(args: {
|
|
1941
|
+
itemId: string;
|
|
1942
|
+
selector: (data: State | null) => Selected;
|
|
1943
|
+
loadItemFallback?: () => void;
|
|
1944
|
+
onDelete?: () => void;
|
|
1945
|
+
ensureIsLoaded?: boolean;
|
|
1946
|
+
}) => {
|
|
1947
|
+
isLoading: boolean;
|
|
1948
|
+
isDeleted: boolean;
|
|
1949
|
+
data: Selected;
|
|
1950
|
+
};
|
|
1951
|
+
performMutation: DocumentPerformMutation<State, TOfflineOperations>;
|
|
1952
|
+
onTransportReconnect: () => void;
|
|
98
1953
|
};
|
|
99
|
-
declare function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
error: null;
|
|
123
|
-
}>;
|
|
124
|
-
useMultipleItems: <Selected = ItemState | null, QueryMetadata extends Record<string, unknown> | undefined = undefined>(items: CollectionUseMultipleItemsQuery<ItemPayload, QueryMetadata>[], { selector, selectorUsesExternalDeps, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, omitPayload: allItemsOmitPayload, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, }?: {
|
|
125
|
-
selector?: (data: ItemState | null) => Selected;
|
|
126
|
-
selectorUsesExternalDeps?: boolean;
|
|
127
|
-
returnIdleStatus?: boolean;
|
|
128
|
-
returnRefetchingStatus?: boolean;
|
|
129
|
-
omitPayload?: boolean;
|
|
130
|
-
disableRefetchOnMount?: boolean;
|
|
131
|
-
isOffScreen?: boolean;
|
|
132
|
-
}) => readonly TSFDUseCollectionItemReturn<Selected, ItemPayload, NError, QueryMetadata>[];
|
|
133
|
-
useItem: <Selected_1 = ItemState | null>(payload: ItemPayload | undefined | false | null, { omitPayload, selector, selectorUsesExternalDeps, ensureIsLoaded, returnRefetchingStatus, disableRefetchOnMount, returnIdleStatus, isOffScreen, }?: {
|
|
134
|
-
selector?: ((data: ItemState | null) => Selected_1) | undefined;
|
|
135
|
-
selectorUsesExternalDeps?: boolean | undefined;
|
|
136
|
-
omitPayload?: boolean | undefined;
|
|
137
|
-
returnRefetchingStatus?: boolean | undefined;
|
|
138
|
-
disableRefetchOnMount?: boolean | undefined;
|
|
139
|
-
ensureIsLoaded?: boolean | undefined;
|
|
140
|
-
returnIdleStatus?: boolean | undefined;
|
|
141
|
-
isOffScreen?: boolean | undefined;
|
|
142
|
-
}) => TSFDUseCollectionItemReturn<Selected_1, ItemPayload, NError, undefined>;
|
|
143
|
-
reset: () => void;
|
|
144
|
-
getItemKey: (params: ItemPayload) => string;
|
|
145
|
-
getItemState: {
|
|
146
|
-
(fetchParam: ItemPayload): TSFDCollectionItem<ItemState, ItemPayload, NError> | null | undefined;
|
|
147
|
-
(fetchParams: ItemPayload[] | ((params: ItemPayload, data: ItemState | null) => boolean)): TSFDCollectionItem<ItemState, ItemPayload, NError>[];
|
|
148
|
-
};
|
|
149
|
-
startMutation: (fetchParams: ItemPayload | ItemPayload[] | ((params: ItemPayload, data: ItemState | null) => boolean)) => () => void;
|
|
150
|
-
invalidateItem: (itemPayload: ItemPayload | ItemPayload[] | ((params: ItemPayload, data: ItemState | null) => boolean), priority?: FetchType) => void;
|
|
151
|
-
updateItemState: (fetchParams: ItemPayload | ItemPayload[] | ((params: ItemPayload, data: ItemState | null) => boolean), produceNewData: (draftData: ItemState, collectionItem: TSFDCollectionItem<ItemState, ItemPayload, NError>) => void | ItemState, ifNothingWasUpdated?: () => void) => boolean;
|
|
152
|
-
addItemToState: (fetchParams: ItemPayload, data: ItemState) => void;
|
|
153
|
-
deleteItemState: (fetchParams: ItemPayload | ItemPayload[] | ((params: ItemPayload, data: ItemState | null) => boolean)) => void;
|
|
1954
|
+
declare function createDocumentStore<State extends ValidStoreState, TOfflineOperations extends DocumentOfflineOperationsConfig<State> = null, StorageState = unknown>({
|
|
1955
|
+
debugName,
|
|
1956
|
+
id,
|
|
1957
|
+
storeManager,
|
|
1958
|
+
fetchFn,
|
|
1959
|
+
lowPriorityThrottleMs: storeLowPriorityThrottleMs,
|
|
1960
|
+
baseCoalescingWindowMs: storeBaseCoalescingWindowMs,
|
|
1961
|
+
dynamicRealtimeThrottleMs,
|
|
1962
|
+
revalidateOnWindowFocus,
|
|
1963
|
+
transportReconnectCooldownMs,
|
|
1964
|
+
mediumPriorityDelayMs,
|
|
1965
|
+
onSchedulerEvent,
|
|
1966
|
+
onMutationError,
|
|
1967
|
+
usesRealTimeUpdates,
|
|
1968
|
+
persistentStorage: persistentStorageConfig,
|
|
1969
|
+
'~test': testOptions
|
|
1970
|
+
}: DocumentStoreOptions<State, TOfflineOperations, StorageState>): DocumentStore<State, TOfflineOperations>;
|
|
1971
|
+
//#endregion
|
|
1972
|
+
//#region src/internal/testTimelineTypes.d.ts
|
|
1973
|
+
type TestTimelineSessionKey = string | false;
|
|
1974
|
+
type TestSessionKeyChangedEvent = {
|
|
1975
|
+
previousSessionKey: TestTimelineSessionKey;
|
|
1976
|
+
sessionKey: TestTimelineSessionKey;
|
|
154
1977
|
};
|
|
155
|
-
type
|
|
156
|
-
|
|
1978
|
+
type TestOfflineTimelineEvent = {
|
|
1979
|
+
operation: string;
|
|
1980
|
+
phase: 'queued' | 'replay-started' | 'replay-finished' | 'replay-failed';
|
|
1981
|
+
};
|
|
1982
|
+
//#endregion
|
|
1983
|
+
//#region src/listQueryStore/types.d.ts
|
|
157
1984
|
type QueryStatus = TSDFStatus | 'loadingMore';
|
|
158
|
-
type TSFDListQuery<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
1985
|
+
type TSFDListQuery<QueryPayload extends ValidPayload> = {
|
|
1986
|
+
error: StoreError | null;
|
|
1987
|
+
status: QueryStatus;
|
|
1988
|
+
payload: QueryPayload;
|
|
1989
|
+
hasMore: boolean;
|
|
1990
|
+
wasLoaded: boolean;
|
|
1991
|
+
refetchOnMount: false | FetchType;
|
|
1992
|
+
items: string[];
|
|
166
1993
|
};
|
|
167
|
-
type TSDFItemQuery<
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
1994
|
+
type TSDFItemQuery<ItemPayload extends ValidPayload> = {
|
|
1995
|
+
error: StoreError | null;
|
|
1996
|
+
status: Exclude<QueryStatus, 'loadingMore'>;
|
|
1997
|
+
wasLoaded: boolean;
|
|
1998
|
+
refetchOnMount: false | FetchType;
|
|
1999
|
+
payload: ItemPayload;
|
|
173
2000
|
};
|
|
174
|
-
type TSFDListQueryState<ItemState extends ValidStoreState,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
2001
|
+
type TSFDListQueryState<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = {
|
|
2002
|
+
items: Record<string, ItemState | null>;
|
|
2003
|
+
queries: Record<string, TSFDListQuery<QueryPayload>>;
|
|
2004
|
+
itemQueries: Record<string, TSDFItemQuery<ItemPayload> | null>;
|
|
2005
|
+
itemLoadedFields: Record<string, string[]>;
|
|
2006
|
+
itemFieldInvalidationFields: Record<string, string[]>;
|
|
178
2007
|
};
|
|
179
|
-
type
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
2008
|
+
type FieldsInput = string[] | '*';
|
|
2009
|
+
type TSFDUseListQueryReturn<Selected, QueryPayload, QueryMetadata extends undefined | Record<string, unknown> = undefined, HasPartialResources extends boolean = false> = {
|
|
2010
|
+
items: Selected[];
|
|
2011
|
+
status: QueryStatus | 'idle';
|
|
2012
|
+
payload: QueryPayload | undefined;
|
|
2013
|
+
fields: HasPartialResources extends true ? FieldsInput : FieldsInput | undefined; /** Requested partial-resource fields that are still pending. */
|
|
2014
|
+
loadingFields?: string[];
|
|
2015
|
+
error: StoreError | null;
|
|
2016
|
+
queryKey: string;
|
|
2017
|
+
hasMore: boolean;
|
|
2018
|
+
isDerived: boolean;
|
|
2019
|
+
isLoading: boolean;
|
|
2020
|
+
isLoadingMore: boolean; /** Whether this result has local offline changes that still need to sync to the server. */
|
|
2021
|
+
pendingSync: boolean;
|
|
2022
|
+
queryMetadata: QueryMetadata;
|
|
189
2023
|
};
|
|
190
|
-
type TSFDUseListItemReturn<Selected,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
2024
|
+
type TSFDUseListItemReturn<Selected, ItemPayload, QueryMetadata extends undefined | Record<string, unknown> = undefined> = {
|
|
2025
|
+
data: Selected;
|
|
2026
|
+
status: QueryStatus | 'idle' | 'deleted';
|
|
2027
|
+
payload: ItemPayload | null; /** Requested partial-resource fields that are still pending. */
|
|
2028
|
+
loadingFields?: string[];
|
|
2029
|
+
error: StoreError | null;
|
|
2030
|
+
isLoading: boolean;
|
|
2031
|
+
itemStateKey: string; /** Whether this result has local offline changes that still need to sync to the server. */
|
|
2032
|
+
pendingSync: boolean;
|
|
2033
|
+
queryMetadata: QueryMetadata;
|
|
2034
|
+
};
|
|
2035
|
+
type TSFDUsePendingOfflineItemsReturn<Selected, ItemPayload extends ValidPayload> = {
|
|
2036
|
+
items: Selected[];
|
|
2037
|
+
deletedItems: ItemPayload[];
|
|
197
2038
|
};
|
|
198
2039
|
type FetchListFnReturnItem<ItemPayload extends ValidPayload, ItemState extends ValidStoreState> = {
|
|
199
|
-
|
|
200
|
-
|
|
2040
|
+
itemPayload: ItemPayload;
|
|
2041
|
+
data: ItemState;
|
|
201
2042
|
};
|
|
202
2043
|
type FetchListFnReturn<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = {
|
|
203
|
-
|
|
204
|
-
|
|
2044
|
+
items: FetchListFnReturnItem<ItemPayload, ItemState>[];
|
|
2045
|
+
hasMore: boolean;
|
|
205
2046
|
};
|
|
206
2047
|
type ListQueryStoreInitialData<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
2048
|
+
items: {
|
|
2049
|
+
payload: ItemPayload;
|
|
2050
|
+
data: ItemState;
|
|
2051
|
+
}[];
|
|
2052
|
+
queries: {
|
|
2053
|
+
payload: QueryPayload;
|
|
2054
|
+
items: string[];
|
|
2055
|
+
hasMore: boolean;
|
|
2056
|
+
}[];
|
|
2057
|
+
};
|
|
2058
|
+
type ListQueryUseMultipleItemsQuery<ItemPayload extends ValidPayload, QueryMetadata extends undefined | Record<string, unknown> = undefined> = {
|
|
2059
|
+
payload: ItemPayload;
|
|
2060
|
+
fields?: FieldsInput;
|
|
2061
|
+
queryMetadata?: QueryMetadata; /** Only loads the data if it is not already loaded and skip any other refetches */
|
|
2062
|
+
disableRefetches?: boolean;
|
|
2063
|
+
disableRefetchOnMount?: boolean;
|
|
2064
|
+
returnIdleStatus?: boolean;
|
|
2065
|
+
returnRefetchingStatus?: boolean;
|
|
2066
|
+
/**
|
|
2067
|
+
* When requested fields are missing but cached partial data exists, return
|
|
2068
|
+
* `refetching` instead of `loading`.
|
|
2069
|
+
*/
|
|
2070
|
+
showPartialAsRefetching?: boolean;
|
|
2071
|
+
isOffScreen?: boolean;
|
|
2072
|
+
};
|
|
2073
|
+
type ListQueryUseMultipleListQueriesQuery<QueryPayload extends ValidPayload, QueryMetadata extends undefined | Record<string, unknown> = undefined> = {
|
|
2074
|
+
payload: QueryPayload;
|
|
2075
|
+
fields?: FieldsInput;
|
|
2076
|
+
queryMetadata?: QueryMetadata;
|
|
2077
|
+
omitPayload?: boolean; /** Only loads the data if it is not already loaded and skip any other refetches */
|
|
2078
|
+
disableRefetches?: boolean;
|
|
2079
|
+
disableRefetchOnMount?: boolean;
|
|
2080
|
+
returnIdleStatus?: boolean;
|
|
2081
|
+
returnRefetchingStatus?: boolean;
|
|
2082
|
+
/**
|
|
2083
|
+
* When requested fields are missing but cached partial data exists, return
|
|
2084
|
+
* `refetching` instead of `loading`.
|
|
2085
|
+
*/
|
|
2086
|
+
showPartialAsRefetching?: boolean;
|
|
2087
|
+
isOffScreen?: boolean;
|
|
2088
|
+
loadSize?: number;
|
|
216
2089
|
};
|
|
217
2090
|
type OnListQueryInvalidate<QueryPayload extends ValidPayload> = (query: QueryPayload, priority: FetchType) => void;
|
|
218
2091
|
type OnListQueryItemInvalidate<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = (props: {
|
|
219
|
-
|
|
220
|
-
|
|
2092
|
+
itemState: ItemState;
|
|
2093
|
+
payload: ItemPayload;
|
|
2094
|
+
priority: FetchType;
|
|
2095
|
+
}) => void;
|
|
2096
|
+
type OptimisticListUpdate<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = {
|
|
2097
|
+
queries: QueryPayload | ((query: QueryPayload) => boolean) | QueryPayload[];
|
|
2098
|
+
filterItem?: (item: ItemState) => boolean | null;
|
|
2099
|
+
appendNewTo?: 'start' | 'end';
|
|
2100
|
+
invalidateQueries?: boolean;
|
|
2101
|
+
sort?: {
|
|
2102
|
+
sortBy: (item: ItemState, itemPayload: ItemPayload) => string | number | (string | number)[];
|
|
2103
|
+
order?: 'asc' | 'desc' | ('asc' | 'desc')[];
|
|
2104
|
+
};
|
|
2105
|
+
};
|
|
2106
|
+
type QueryFetchPayload<QueryPayload extends ValidPayload> = {
|
|
2107
|
+
type: 'load' | 'loadMore';
|
|
2108
|
+
payload: QueryPayload;
|
|
2109
|
+
offset: number;
|
|
2110
|
+
limit: number;
|
|
2111
|
+
fields?: string[];
|
|
2112
|
+
};
|
|
2113
|
+
type OffsetPaginationConfig = {
|
|
2114
|
+
maxInvalidationLimit: number; /** Max parallel chunk requests during chunked invalidation (default: 3) */
|
|
2115
|
+
maxParallel?: number;
|
|
2116
|
+
};
|
|
2117
|
+
type PartialResourcesConfig<ItemState extends ValidStoreState> = {
|
|
2118
|
+
mergeItems: (prev: ItemState | undefined, fetched: ItemState) => ItemState;
|
|
2119
|
+
selectFields: (fields: string[], item: ItemState) => ItemState;
|
|
2120
|
+
};
|
|
2121
|
+
type DerivedQuerySummary<QueryPayload extends ValidPayload> = {
|
|
2122
|
+
payload: QueryPayload;
|
|
2123
|
+
hasMore: boolean;
|
|
2124
|
+
itemCount: number;
|
|
2125
|
+
};
|
|
2126
|
+
type DerivedQueryItem<ItemState extends ValidStoreState> = {
|
|
2127
|
+
key: string;
|
|
2128
|
+
data: ItemState;
|
|
2129
|
+
};
|
|
2130
|
+
/** Why a derived query is currently being resolved. */
|
|
2131
|
+
type DerivedQuerySource = 'online' | 'offline' | 'sticky-offline';
|
|
2132
|
+
/** Runtime context passed to `derivedQueries.deriveQuery(...)`. */
|
|
2133
|
+
type DerivedQueryContext = {
|
|
2134
|
+
/** The requested hook fields for this query, when partial resources are enabled. */fields: FieldsInput | undefined; /** Whether the store is currently in offline mode. */
|
|
2135
|
+
isOfflineMode: boolean;
|
|
2136
|
+
/**
|
|
2137
|
+
* What caused derivation to run.
|
|
2138
|
+
* `sticky-offline` means a query that was derived offline is still sticking
|
|
2139
|
+
* to the local derived view after reconnect, until explicit invalidation.
|
|
2140
|
+
*/
|
|
2141
|
+
deriveSource: DerivedQuerySource;
|
|
2142
|
+
};
|
|
2143
|
+
type DerivedQueriesConfig<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = {
|
|
2144
|
+
/** Extracts the domain/group key for a query payload. */getQueryGroup: (queryPayload: QueryPayload) => string; /** Extracts the domain/group key for a materialized item. */
|
|
2145
|
+
getItemGroup: (item: ItemState, itemPayload: ItemPayload) => string;
|
|
2146
|
+
/**
|
|
2147
|
+
* Returns whether the local data for the query group is complete enough to
|
|
2148
|
+
* derive from while online.
|
|
2149
|
+
*/
|
|
2150
|
+
isComplete: (queryPayload: QueryPayload, context: {
|
|
2151
|
+
queries: DerivedQuerySummary<QueryPayload>[];
|
|
2152
|
+
}) => boolean;
|
|
2153
|
+
/**
|
|
2154
|
+
* Computes a derived ordered list of item keys for a query, or `false` to
|
|
2155
|
+
* fall back to the regular fetch/cache path. `context.fields` lets the
|
|
2156
|
+
* callback decide whether partial-resource queries should still derive.
|
|
2157
|
+
*/
|
|
2158
|
+
deriveQuery: (queryPayload: QueryPayload, items: DerivedQueryItem<ItemState>[], context: DerivedQueryContext) => string[] | false;
|
|
2159
|
+
};
|
|
2160
|
+
type FieldsOption<HasPartialResources extends boolean> = HasPartialResources extends true ? {
|
|
2161
|
+
fields: FieldsInput;
|
|
2162
|
+
} : {
|
|
2163
|
+
fields?: FieldsInput;
|
|
2164
|
+
};
|
|
2165
|
+
//#endregion
|
|
2166
|
+
//#region src/listQueryStore/useMultipleItems.d.ts
|
|
2167
|
+
type UseMultipleItemsOptions<ItemState extends ValidStoreState, Selected> = {
|
|
2168
|
+
selector?: (data: ItemState | null, payload: ValidPayload | null) => Selected;
|
|
2169
|
+
loadFromStateOnly?: boolean;
|
|
2170
|
+
returnIdleStatus?: boolean;
|
|
2171
|
+
returnRefetchingStatus?: boolean;
|
|
2172
|
+
/**
|
|
2173
|
+
* When requested fields are missing but cached partial data exists, return
|
|
2174
|
+
* `refetching` instead of `loading`.
|
|
2175
|
+
*/
|
|
2176
|
+
showPartialAsRefetching?: boolean; /** Only loads the data if it is not already loaded and skip any other refetches */
|
|
2177
|
+
disableRefetches?: boolean;
|
|
2178
|
+
disableRefetchOnMount?: boolean;
|
|
2179
|
+
isOffScreen?: boolean;
|
|
2180
|
+
/**
|
|
2181
|
+
* Debounces automatic fetches caused by payload changes, while selection
|
|
2182
|
+
* still reads from the latest payload. Supports trailing debounce via `ms`,
|
|
2183
|
+
* optional `leading`, and optional `maxWait`.
|
|
2184
|
+
*/
|
|
2185
|
+
debouncePayload?: PayloadDebounce;
|
|
2186
|
+
};
|
|
2187
|
+
//#endregion
|
|
2188
|
+
//#region src/listQueryStore/useItem.d.ts
|
|
2189
|
+
type UseItemOptions<ItemState extends ValidStoreState, Selected> = UseMultipleItemsOptions<ItemState, Selected> & {
|
|
2190
|
+
/**
|
|
2191
|
+
* Forces a high-priority fetch on mount and keeps the hook in `loading`
|
|
2192
|
+
* until the current payload finishes loading. Cannot be combined with
|
|
2193
|
+
* `debouncePayload`.
|
|
2194
|
+
*/
|
|
2195
|
+
ensureIsLoaded?: boolean;
|
|
2196
|
+
fields?: FieldsInput;
|
|
2197
|
+
/**
|
|
2198
|
+
* When requested fields are missing but cached partial data exists, return
|
|
2199
|
+
* `refetching` instead of `loading`.
|
|
2200
|
+
*/
|
|
2201
|
+
showPartialAsRefetching?: boolean;
|
|
2202
|
+
};
|
|
2203
|
+
//#endregion
|
|
2204
|
+
//#region src/listQueryStore/useMultipleListQueries.d.ts
|
|
2205
|
+
type UseMultipleListQueriesOptions<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, SelectedItem> = {
|
|
2206
|
+
itemSelector?: (data: ItemState, itemPayload: ItemPayload, itemKey: string) => SelectedItem;
|
|
2207
|
+
returnIdleStatus?: boolean;
|
|
2208
|
+
returnRefetchingStatus?: boolean;
|
|
2209
|
+
/**
|
|
2210
|
+
* When requested fields are missing but cached partial data exists, return
|
|
2211
|
+
* `refetching` instead of `loading`.
|
|
2212
|
+
*/
|
|
2213
|
+
showPartialAsRefetching?: boolean;
|
|
2214
|
+
omitPayload?: boolean; /** Only loads the data if it is not already loaded and skip any other refetches */
|
|
2215
|
+
disableRefetches?: boolean;
|
|
2216
|
+
disableRefetchOnMount?: boolean;
|
|
2217
|
+
isOffScreen?: boolean;
|
|
2218
|
+
loadSize?: number;
|
|
2219
|
+
/**
|
|
2220
|
+
* Debounces automatic fetches caused by payload changes, while selection
|
|
2221
|
+
* still reads from the latest payload. Supports trailing debounce via `ms`,
|
|
2222
|
+
* optional `leading`, and optional `maxWait`.
|
|
2223
|
+
*/
|
|
2224
|
+
debouncePayload?: PayloadDebounce;
|
|
2225
|
+
};
|
|
2226
|
+
//#endregion
|
|
2227
|
+
//#region src/listQueryStore/useListQuery.d.ts
|
|
2228
|
+
type UseListQueryOptions<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, SelectedItem> = UseMultipleListQueriesOptions<ItemState, ItemPayload, SelectedItem> & {
|
|
2229
|
+
/**
|
|
2230
|
+
* Forces a high-priority fetch on mount and keeps the hook in `loading`
|
|
2231
|
+
* until the current payload finishes loading. Cannot be combined with
|
|
2232
|
+
* `debouncePayload`.
|
|
2233
|
+
*/
|
|
2234
|
+
ensureIsLoaded?: boolean;
|
|
2235
|
+
fields?: FieldsInput;
|
|
2236
|
+
/**
|
|
2237
|
+
* When requested fields are missing but cached partial data exists, return
|
|
2238
|
+
* `refetching` instead of `loading`.
|
|
2239
|
+
*/
|
|
2240
|
+
showPartialAsRefetching?: boolean;
|
|
2241
|
+
};
|
|
2242
|
+
//#endregion
|
|
2243
|
+
//#region src/listQueryStore/usePendingOfflineItems.d.ts
|
|
2244
|
+
type UsePendingOfflineItemsOptions<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, SelectedItem> = {
|
|
2245
|
+
/** Maps each visible pending item before it is returned from the hook. */selector?: (data: ItemState, payload: ItemPayload) => SelectedItem; /** Narrows the hook output using the tracked item payload, before selection. */
|
|
2246
|
+
filterPayload?: (payload: ItemPayload) => boolean; /** Includes entities currently blocked in manual resolution. */
|
|
2247
|
+
includeResolutionRequired?: boolean;
|
|
2248
|
+
};
|
|
2249
|
+
//#endregion
|
|
2250
|
+
//#region src/listQueryStore/listQueryStore.d.ts
|
|
2251
|
+
type ListQueryStoreEvents = {
|
|
2252
|
+
invalidateQuery: {
|
|
221
2253
|
priority: FetchType;
|
|
2254
|
+
queryKey: string;
|
|
2255
|
+
};
|
|
2256
|
+
invalidateItem: {
|
|
2257
|
+
priority: FetchType;
|
|
2258
|
+
itemKey: string;
|
|
2259
|
+
invalidateFields?: string[];
|
|
2260
|
+
};
|
|
2261
|
+
};
|
|
2262
|
+
type ListQueryStoreStoreEvents<ItemPayload extends ValidPayload> = {
|
|
2263
|
+
mutationStart: {
|
|
2264
|
+
mutationId: number;
|
|
2265
|
+
items: ItemPayload[];
|
|
2266
|
+
};
|
|
2267
|
+
mutationEnd: {
|
|
2268
|
+
mutationId: number;
|
|
2269
|
+
items: ItemPayload[];
|
|
2270
|
+
status: 'success' | 'error' | 'skipped';
|
|
2271
|
+
};
|
|
2272
|
+
tempEntityReconciled: {
|
|
2273
|
+
tempId: ItemPayload;
|
|
2274
|
+
finalPayload: ItemPayload;
|
|
2275
|
+
};
|
|
2276
|
+
};
|
|
2277
|
+
type ResolvedListQueryOfflineOperations<TOfflineOperations> = TOfflineOperations extends null ? Record<never, never> : Exclude<TOfflineOperations, null>;
|
|
2278
|
+
type ListQueryHasPartialResources<TPartialResources extends boolean> = [TPartialResources] extends [true] ? true : false;
|
|
2279
|
+
type ListQueryFetchFieldsOption<TPartialResources extends boolean> = ListQueryHasPartialResources<TPartialResources> extends true ? {
|
|
2280
|
+
fields: FieldsInput;
|
|
2281
|
+
} : {
|
|
2282
|
+
fields?: FieldsInput;
|
|
2283
|
+
};
|
|
2284
|
+
type ListQueryScheduleFetchWithFieldsOption<TPartialResources extends boolean> = ScheduleFetchOptions & ListQueryFetchFieldsOption<TPartialResources>;
|
|
2285
|
+
type ListQueryScheduleListQueryFetchApi<QueryPayload extends ValidPayload, TPartialResources extends boolean> = {
|
|
2286
|
+
(fetchType: FetchType, payload: QueryPayload, ...args: ListQueryHasPartialResources<TPartialResources> extends true ? [size: number | undefined, options: ListQueryScheduleFetchWithFieldsOption<TPartialResources>] : [size?: number, options?: ListQueryScheduleFetchWithFieldsOption<TPartialResources>]): ScheduleFetchResults;
|
|
2287
|
+
(fetchType: FetchType, payload: QueryPayload[], ...args: ListQueryHasPartialResources<TPartialResources> extends true ? [size: number | undefined, options: ListQueryScheduleFetchWithFieldsOption<TPartialResources>] : [size?: number, options?: ListQueryScheduleFetchWithFieldsOption<TPartialResources>]): ScheduleFetchResults[];
|
|
2288
|
+
};
|
|
2289
|
+
type ListQueryScheduleItemFetchApi<ItemPayload extends ValidPayload, TPartialResources extends boolean> = {
|
|
2290
|
+
(fetchType: FetchType, itemPayload: ItemPayload, ...args: ListQueryHasPartialResources<TPartialResources> extends true ? [options: ListQueryScheduleFetchWithFieldsOption<TPartialResources>] : [options?: ListQueryScheduleFetchWithFieldsOption<TPartialResources>]): ScheduleFetchResults;
|
|
2291
|
+
(fetchType: FetchType, itemPayload: ItemPayload[], ...args: ListQueryHasPartialResources<TPartialResources> extends true ? [options: ListQueryScheduleFetchWithFieldsOption<TPartialResources>] : [options?: ListQueryScheduleFetchWithFieldsOption<TPartialResources>]): ScheduleFetchResults[];
|
|
2292
|
+
};
|
|
2293
|
+
type ListQueryLoadMoreWithFieldsOptions<TPartialResources extends boolean> = {
|
|
2294
|
+
size?: number;
|
|
2295
|
+
} & ListQueryFetchFieldsOption<TPartialResources>;
|
|
2296
|
+
type ListQueryLoadMoreApi<QueryPayload extends ValidPayload, TPartialResources extends boolean> = (params: QueryPayload, ...args: ListQueryHasPartialResources<TPartialResources> extends true ? [size: number, options: ListQueryFetchFieldsOption<TPartialResources>] | [options: ListQueryLoadMoreWithFieldsOptions<TPartialResources>] : [size?: number, options?: ListQueryFetchFieldsOption<TPartialResources>] | [options?: ListQueryLoadMoreWithFieldsOptions<TPartialResources>]) => ScheduleFetchResults;
|
|
2297
|
+
type ListQueryAwaitListQueryFetchOptions<TPartialResources extends boolean> = {
|
|
2298
|
+
size?: number;
|
|
2299
|
+
timeoutMs?: number;
|
|
2300
|
+
} & ListQueryFetchFieldsOption<TPartialResources>;
|
|
2301
|
+
type ListQueryAwaitListQueryFetchApi<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TPartialResources extends boolean> = (params: QueryPayload, ...args: ListQueryHasPartialResources<TPartialResources> extends true ? [options: ListQueryAwaitListQueryFetchOptions<TPartialResources>] : [options?: ListQueryAwaitListQueryFetchOptions<TPartialResources>]) => Promise<{
|
|
2302
|
+
items: [];
|
|
2303
|
+
error: StoreFetchError;
|
|
2304
|
+
hasMore: boolean;
|
|
2305
|
+
} | {
|
|
2306
|
+
items: {
|
|
2307
|
+
data: ItemState;
|
|
2308
|
+
itemPayload: ItemPayload;
|
|
2309
|
+
}[];
|
|
2310
|
+
error: null;
|
|
2311
|
+
hasMore: boolean;
|
|
2312
|
+
}>;
|
|
2313
|
+
type ListQueryAwaitItemFetchOptions<TPartialResources extends boolean> = {
|
|
2314
|
+
timeoutMs?: number;
|
|
2315
|
+
} & ListQueryFetchFieldsOption<TPartialResources>;
|
|
2316
|
+
type ListQueryAwaitItemFetchApi<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, TPartialResources extends boolean> = (itemPayload: ItemPayload, ...args: ListQueryHasPartialResources<TPartialResources> extends true ? [options: ListQueryAwaitItemFetchOptions<TPartialResources>] : [options?: ListQueryAwaitItemFetchOptions<TPartialResources>]) => Promise<{
|
|
2317
|
+
data: null;
|
|
2318
|
+
error: StoreFetchError;
|
|
2319
|
+
} | {
|
|
2320
|
+
data: ItemState;
|
|
2321
|
+
error: null;
|
|
2322
|
+
}>;
|
|
2323
|
+
type ListQueryUseMultipleListQueriesApi<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TPartialResources extends boolean> = {
|
|
2324
|
+
<SelectedItem = ItemState, QueryMetadata extends undefined | Record<string, unknown> = undefined>(queries: (ListQueryUseMultipleListQueriesQuery<QueryPayload, QueryMetadata> & FieldsOption<ListQueryHasPartialResources<TPartialResources>>)[], options?: UseMultipleListQueriesOptions<ItemState, ItemPayload, SelectedItem>): readonly TSFDUseListQueryReturn<SelectedItem, QueryPayload, QueryMetadata>[];
|
|
2325
|
+
<S = ItemState>(queries: ListQueryUseMultipleListQueriesQuery<QueryPayload, undefined>[], options: UseMultipleListQueriesOptions<ItemState, ItemPayload, S>): readonly TSFDUseListQueryReturn<S, QueryPayload, undefined>[];
|
|
2326
|
+
};
|
|
2327
|
+
type ListQueryUseListQueryApi<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TPartialResources extends boolean> = {
|
|
2328
|
+
<SelectedItem = ItemState>(payload: QueryPayload | false | null | undefined, ...args: ListQueryHasPartialResources<TPartialResources> extends true ? [options: UseListQueryOptions<ItemState, ItemPayload, SelectedItem> & {
|
|
2329
|
+
fields: FieldsInput;
|
|
2330
|
+
}] : [options?: UseListQueryOptions<ItemState, ItemPayload, SelectedItem>]): TSFDUseListQueryReturn<SelectedItem, QueryPayload, undefined>;
|
|
2331
|
+
};
|
|
2332
|
+
type ListQueryUseMultipleItemsApi<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, TPartialResources extends boolean> = {
|
|
2333
|
+
<Selected = ItemState | null, QueryMetadata extends undefined | Record<string, unknown> = undefined>(items: (ListQueryUseMultipleItemsQuery<ItemPayload, QueryMetadata> & FieldsOption<ListQueryHasPartialResources<TPartialResources>>)[], options?: UseMultipleItemsOptions<ItemState, Selected>): readonly TSFDUseListItemReturn<Selected, ItemPayload, QueryMetadata>[];
|
|
2334
|
+
<S = ItemState | null>(items: ListQueryUseMultipleItemsQuery<ItemPayload, undefined>[], options: UseMultipleItemsOptions<ItemState, S>): readonly TSFDUseListItemReturn<S, ItemPayload, undefined>[];
|
|
2335
|
+
};
|
|
2336
|
+
type ListQueryUseItemApi<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, TPartialResources extends boolean> = {
|
|
2337
|
+
<Selected = ItemState | null>(itemPayload: ItemPayload | false | null | undefined, ...args: ListQueryHasPartialResources<TPartialResources> extends true ? [options: UseItemOptions<ItemState, Selected> & {
|
|
2338
|
+
fields: FieldsInput;
|
|
2339
|
+
}] : [options?: UseItemOptions<ItemState, Selected>]): TSFDUseListItemReturn<Selected, ItemPayload>;
|
|
2340
|
+
};
|
|
2341
|
+
type ListQueryUsePendingOfflineItemsApi<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = {
|
|
2342
|
+
<SelectedItem = ItemState>(options?: UsePendingOfflineItemsOptions<ItemState, ItemPayload, SelectedItem>): TSFDUsePendingOfflineItemsReturn<SelectedItem, ItemPayload>;
|
|
2343
|
+
};
|
|
2344
|
+
type ListQueryFilterQuery<QueryPayload extends ValidPayload> = (params: QueryPayload, data: TSFDListQuery<QueryPayload>, queryKey: string) => boolean;
|
|
2345
|
+
type ListQueryRevalidateOnSuccessOption<QueryPayload extends ValidPayload> = boolean | 'queries' | ListQueryFilterQuery<QueryPayload> | {
|
|
2346
|
+
queries: ListQueryFilterQuery<QueryPayload>;
|
|
2347
|
+
items?: boolean;
|
|
2348
|
+
};
|
|
2349
|
+
type ListQueryFilterItem<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = (itemPayload: ItemPayload, itemState: ItemState) => boolean;
|
|
2350
|
+
type ListQueryMutationPayload<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload> | null;
|
|
2351
|
+
type ListQueryMutationPayloadToUse<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload>;
|
|
2352
|
+
type ListQueryMutationArgsBase<T, ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = {
|
|
2353
|
+
optimisticUpdate?: (payload: ListQueryMutationPayloadToUse<ItemState, ItemPayload>) => void | boolean;
|
|
2354
|
+
mutation: (payload: ListQueryMutationPayloadToUse<ItemState, ItemPayload>) => Promise<T>;
|
|
2355
|
+
revalidateOnSuccess?: ListQueryRevalidateOnSuccessOption<QueryPayload>;
|
|
2356
|
+
onSuccess?: (response: Awaited<T>, payload: ListQueryMutationPayloadToUse<ItemState, ItemPayload>) => void;
|
|
2357
|
+
onError?: (error: StoreMutationError | MutationSkipped) => void;
|
|
2358
|
+
silentErrors?: boolean;
|
|
2359
|
+
debounce?: {
|
|
2360
|
+
context: string;
|
|
2361
|
+
payload: unknown;
|
|
2362
|
+
ms: number;
|
|
2363
|
+
};
|
|
2364
|
+
};
|
|
2365
|
+
type ListQueryOnlineMutationArgs<T, ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = ListQueryMutationArgsBase<T, ItemState, QueryPayload, ItemPayload> & {
|
|
2366
|
+
offline?: undefined;
|
|
2367
|
+
upload?: undefined;
|
|
2368
|
+
};
|
|
2369
|
+
type ListQueryOfflineMutationArgs<T, ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TOfflineOperations extends ListQueryOfflineOperationsConfig<ItemState, QueryPayload, ItemPayload>> = ListQueryMutationArgsBase<T, ItemState, QueryPayload, ItemPayload> & {
|
|
2370
|
+
offline: TOfflineOperations extends null ? never : OfflineMutationInput<Exclude<TOfflineOperations, null>>;
|
|
2371
|
+
upload?: OfflineMutationUploadsInput;
|
|
2372
|
+
};
|
|
2373
|
+
type ListQueryPerformMutationApi<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TOfflineOperations extends ListQueryOfflineOperationsConfig<ItemState, QueryPayload, ItemPayload>> = {
|
|
2374
|
+
<T>(payload: ListQueryMutationPayloadToUse<ItemState, ItemPayload>, args: ListQueryOnlineMutationArgs<T, ItemState, QueryPayload, ItemPayload>): Promise<Result<Awaited<T>, StoreMutationError | MutationSkipped>>;
|
|
2375
|
+
<T>(payload: ListQueryMutationPayloadToUse<ItemState, ItemPayload>, args: ListQueryOfflineMutationArgs<T, ItemState, QueryPayload, ItemPayload, TOfflineOperations>): Promise<Result<OfflineMutationResult<T>, StoreMutationError | MutationSkipped>>;
|
|
2376
|
+
<T>(payload: null, args: Omit<ListQueryOnlineMutationArgs<T, ItemState, QueryPayload, ItemPayload>, 'optimisticUpdate'>): Promise<Result<Awaited<T>, StoreMutationError | MutationSkipped>>;
|
|
2377
|
+
<T>(payload: null, args: Omit<ListQueryOfflineMutationArgs<T, ItemState, QueryPayload, ItemPayload, TOfflineOperations>, 'optimisticUpdate'>): Promise<Result<OfflineMutationResult<T>, StoreMutationError | MutationSkipped>>;
|
|
2378
|
+
<T>(payload: ListQueryMutationPayload<ItemState, ItemPayload>, args: ListQueryOnlineMutationArgs<T, ItemState, QueryPayload, ItemPayload> | ListQueryOfflineMutationArgs<T, ItemState, QueryPayload, ItemPayload, TOfflineOperations>): Promise<Result<Awaited<T> | OfflineMutationResult<T>, StoreMutationError | MutationSkipped>>;
|
|
2379
|
+
};
|
|
2380
|
+
type ListQueryUpdateItemStateApi<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = (itemIds: ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload>, produceNewData: (draftData: ItemState, itemPayload: ItemPayload) => void | ItemState, options?: {
|
|
2381
|
+
ifNothingWasUpdated?: () => void;
|
|
2382
|
+
}) => boolean;
|
|
2383
|
+
type ListQueryAddItemToStateApi<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = (itemPayload: ItemPayload, data: ItemState, options?: {
|
|
2384
|
+
addItemToQueries?: {
|
|
2385
|
+
queries: QueryPayload[] | ListQueryFilterQuery<QueryPayload> | QueryPayload;
|
|
2386
|
+
appendTo: 'start' | 'end' | ((itemsPayload: ItemPayload[]) => number);
|
|
2387
|
+
};
|
|
222
2388
|
}) => void;
|
|
223
|
-
type
|
|
2389
|
+
type ListQueryDeleteItemStateApi<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = (itemId: ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload>) => void;
|
|
2390
|
+
type ListQueryStore<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TPartialResources extends boolean = false, TOfflineOperations extends ListQueryOfflineOperationsConfig<ItemState, QueryPayload, ItemPayload> = null> = {
|
|
2391
|
+
store: Store<TSFDListQueryState<ItemState, QueryPayload, ItemPayload>>;
|
|
2392
|
+
events: Emitter<ListQueryStoreEvents>;
|
|
2393
|
+
storeEvents: Emitter<ListQueryStoreStoreEvents<ItemPayload>>;
|
|
2394
|
+
readonly queryInvalidationWasTriggered: Set<string>;
|
|
2395
|
+
readonly itemInvalidationWasTriggered: Set<string>;
|
|
2396
|
+
reset: () => void;
|
|
2397
|
+
dispose: () => void;
|
|
2398
|
+
scheduleListQueryFetch: ListQueryScheduleListQueryFetchApi<QueryPayload, TPartialResources>;
|
|
2399
|
+
getQueryState: (params: QueryPayload) => TSFDListQuery<QueryPayload> | undefined;
|
|
2400
|
+
getQueryKey: (params: QueryPayload) => string;
|
|
2401
|
+
getQueriesState: (params: QueryPayload[] | ListQueryFilterQuery<QueryPayload>) => {
|
|
2402
|
+
query: TSFDListQuery<QueryPayload>;
|
|
2403
|
+
key: string;
|
|
2404
|
+
}[];
|
|
2405
|
+
getQueriesRelatedToItem: (itemPayload: ItemPayload) => {
|
|
2406
|
+
query: TSFDListQuery<QueryPayload>;
|
|
2407
|
+
key: string;
|
|
2408
|
+
}[];
|
|
2409
|
+
awaitListQueryFetch: ListQueryAwaitListQueryFetchApi<ItemState, QueryPayload, ItemPayload, TPartialResources>;
|
|
2410
|
+
preloadQueryFromStorage: (params: QueryPayload | QueryPayload[]) => Promise<PersistentStoragePreloadResult<QueryPayload>[]>;
|
|
2411
|
+
loadMore: ListQueryLoadMoreApi<QueryPayload, TPartialResources>;
|
|
2412
|
+
getItemKey: (params: ItemPayload) => string;
|
|
2413
|
+
getItemState: {
|
|
2414
|
+
(itemPayload: ItemPayload): ItemState | null | undefined;
|
|
2415
|
+
(itemPayload: ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload>): {
|
|
2416
|
+
payload: ItemPayload;
|
|
2417
|
+
data: ItemState;
|
|
2418
|
+
}[];
|
|
2419
|
+
};
|
|
2420
|
+
usePendingOfflineItems: ListQueryUsePendingOfflineItemsApi<ItemState, ItemPayload>;
|
|
2421
|
+
getOfflineEntities: () => GlobalOfflineEntity[];
|
|
2422
|
+
useOfflineEntities: () => readonly GlobalOfflineEntity[];
|
|
2423
|
+
useOfflineResolutions: () => readonly OfflineResolutionRecord[];
|
|
2424
|
+
getOfflineResolutions: () => OfflineResolutionRecord[];
|
|
2425
|
+
parseOfflineResolutionConflict: (resolution: OfflineResolutionRecord) => ParsedOfflineResolutionConflictResultForStore<ResolvedListQueryOfflineOperations<TOfflineOperations>>;
|
|
2426
|
+
resolveOfflineResolution: <TName extends keyof ResolvedListQueryOfflineOperations<TOfflineOperations> & string>(resolutionId: string, operationName: TName, resolution: OfflineResolutionActionForOperation<ResolvedListQueryOfflineOperations<TOfflineOperations>, TName>) => Promise<void> | void;
|
|
2427
|
+
preloadItemFromStorage: (params: ItemPayload | ItemPayload[]) => Promise<PersistentStoragePreloadResult<ItemPayload>[]>;
|
|
2428
|
+
scheduleItemFetch: ListQueryScheduleItemFetchApi<ItemPayload, TPartialResources>;
|
|
2429
|
+
awaitItemFetch: ListQueryAwaitItemFetchApi<ItemState, ItemPayload, TPartialResources>;
|
|
2430
|
+
invalidateQueryAndItems: (args: {
|
|
2431
|
+
itemPayload: ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload> | false;
|
|
2432
|
+
queryPayload: QueryPayload | QueryPayload[] | ListQueryFilterQuery<QueryPayload> | false;
|
|
2433
|
+
type?: FetchType;
|
|
2434
|
+
fields?: string[];
|
|
2435
|
+
}) => void;
|
|
2436
|
+
invalidateItem: (itemId: ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload>, priority?: FetchType) => void;
|
|
2437
|
+
startItemMutation: (itemId: ItemPayload | ItemPayload[] | ListQueryFilterItem<ItemState, ItemPayload>) => () => void;
|
|
2438
|
+
updateItemState: ListQueryUpdateItemStateApi<ItemState, ItemPayload>;
|
|
2439
|
+
addItemToState: ListQueryAddItemToStateApi<ItemState, QueryPayload, ItemPayload>;
|
|
2440
|
+
deleteItemState: ListQueryDeleteItemStateApi<ItemState, ItemPayload>;
|
|
2441
|
+
performMutation: ListQueryPerformMutationApi<ItemState, QueryPayload, ItemPayload, TOfflineOperations>;
|
|
2442
|
+
useMultipleListQueries: ListQueryUseMultipleListQueriesApi<ItemState, QueryPayload, ItemPayload, TPartialResources>;
|
|
2443
|
+
useListQuery: ListQueryUseListQueryApi<ItemState, QueryPayload, ItemPayload, TPartialResources>;
|
|
2444
|
+
useMultipleItems: ListQueryUseMultipleItemsApi<ItemState, ItemPayload, TPartialResources>;
|
|
2445
|
+
useItem: ListQueryUseItemApi<ItemState, ItemPayload, TPartialResources>;
|
|
2446
|
+
useFindItem: <SelectedItem = ItemState | null>(findItemFn: (item: ItemState, itemPayload: ItemPayload) => boolean, options?: {
|
|
2447
|
+
selector?: (data: ItemState, id: ItemPayload) => SelectedItem;
|
|
2448
|
+
}) => SelectedItem | null;
|
|
2449
|
+
onTransportReconnect: () => void;
|
|
2450
|
+
};
|
|
2451
|
+
type ListQueryStateCleanup<QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = {
|
|
2452
|
+
reason: 'cacheLimitEviction';
|
|
2453
|
+
itemKeys: string[];
|
|
2454
|
+
itemPayloads: ItemPayload[];
|
|
2455
|
+
queryKeys: string[];
|
|
2456
|
+
queryPayloads: QueryPayload[];
|
|
2457
|
+
};
|
|
2458
|
+
type FetchListFnSizeMode<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = (payload: QueryPayload, size: number, options: {
|
|
2459
|
+
signal: AbortSignal;
|
|
2460
|
+
fields?: string[];
|
|
2461
|
+
}) => Promise<FetchListFnReturn<ItemState, ItemPayload>>;
|
|
2462
|
+
type FetchListFnOffsetMode<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = (payload: QueryPayload, pagination: {
|
|
2463
|
+
offset: number;
|
|
2464
|
+
limit: number;
|
|
2465
|
+
}, options: {
|
|
2466
|
+
signal: AbortSignal;
|
|
2467
|
+
fields?: string[];
|
|
2468
|
+
}) => Promise<FetchListFnReturn<ItemState, ItemPayload>>;
|
|
2469
|
+
type ListQuerySnapshotItemEntry<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = {
|
|
2470
|
+
itemKey: string;
|
|
2471
|
+
item: ItemState | null;
|
|
2472
|
+
itemQuery: TSDFItemQuery<ItemPayload> | null;
|
|
2473
|
+
loadedFields: string[];
|
|
2474
|
+
};
|
|
2475
|
+
type ListQueryBrowserTabsMessage<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = (BrowserTabsMessageMeta & BrowserTabsTabStatusMessage) | (BrowserTabsMessageMeta & {
|
|
2476
|
+
kind: 'list-query-snapshot';
|
|
2477
|
+
queryKey: string;
|
|
2478
|
+
consistency: SnapshotConsistency;
|
|
2479
|
+
query: TSFDListQuery<QueryPayload>;
|
|
2480
|
+
items: ListQuerySnapshotItemEntry<ItemState, ItemPayload>[];
|
|
2481
|
+
}) | (BrowserTabsMessageMeta & {
|
|
2482
|
+
kind: 'list-item-snapshot';
|
|
2483
|
+
itemKey: string;
|
|
2484
|
+
consistency: SnapshotConsistency;
|
|
2485
|
+
item: ItemState | null;
|
|
2486
|
+
itemQuery: TSDFItemQuery<ItemPayload> | null;
|
|
2487
|
+
loadedFields: string[];
|
|
2488
|
+
}) | (BrowserTabsMessageMeta & {
|
|
2489
|
+
kind: 'fetch-start';
|
|
2490
|
+
targetKey: string;
|
|
2491
|
+
requestIds: string[];
|
|
2492
|
+
startedAt: number;
|
|
2493
|
+
}) | (BrowserTabsMessageMeta & {
|
|
2494
|
+
kind: 'fetch-success';
|
|
2495
|
+
targetKey: string;
|
|
2496
|
+
requestIds: string[];
|
|
2497
|
+
startedAt: number;
|
|
2498
|
+
duration: number;
|
|
2499
|
+
});
|
|
2500
|
+
type ListQueryStoreOptionsBase<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TPartialResources extends boolean = false, TOfflineOperations extends ListQueryOfflineOperationsConfig<ItemState, QueryPayload, ItemPayload> = null, StorageState = unknown> = {
|
|
2501
|
+
debugName?: string; /** Stable id shared by the same logical list-query store across browser tabs. */
|
|
2502
|
+
id: string; /** Shared global store manager providing session scoping and error normalization. */
|
|
2503
|
+
storeManager: StoreManager;
|
|
2504
|
+
fetchItemFn?: (payload: ItemPayload, options: {
|
|
2505
|
+
signal: AbortSignal;
|
|
2506
|
+
fields?: string[];
|
|
2507
|
+
}) => Promise<ItemState>;
|
|
2508
|
+
batchFetchItemFn?: (requests: {
|
|
224
2509
|
payload: ItemPayload;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
2510
|
+
fields?: string[];
|
|
2511
|
+
}[], options: {
|
|
2512
|
+
signal: AbortSignal;
|
|
2513
|
+
batchKey: string;
|
|
2514
|
+
}) => Promise<Map<ItemPayload, ItemState | Error>>;
|
|
2515
|
+
getItemsBatchKey?: (payload: ItemPayload) => string | false;
|
|
2516
|
+
defaultQuerySize?: number;
|
|
2517
|
+
maxItemBatchSize?: number; /** Maximum number of cached items kept in memory. Defaults to 5,000. Item pressure may evict whole inactive queries to avoid leaving cached queries partially loaded. */
|
|
2518
|
+
maxItems?: number; /** Maximum number of cached queries kept in memory. Defaults to 1,000. Inactive queries are evicted in LRU order while mounted hook queries stay protected. */
|
|
2519
|
+
maxQueries?: number; /** Called when cache-limit eviction removes items or queries from in-memory state. */
|
|
2520
|
+
onStateCleanup?: (cleanup: ListQueryStateCleanup<QueryPayload, ItemPayload>) => void;
|
|
2521
|
+
usesRealTimeUpdates?: boolean;
|
|
2522
|
+
'~test'?: {
|
|
2523
|
+
initialData?: ListQueryStoreInitialData<ItemState, QueryPayload, ItemPayload>;
|
|
2524
|
+
initialRefetchOnMount?: FetchType | false;
|
|
2525
|
+
initialLastFetchStartTime?: number;
|
|
2526
|
+
getWindowIsFocused?: () => boolean;
|
|
2527
|
+
onWindowFocus?: (handler: () => void) => () => void;
|
|
2528
|
+
onWindowFocusChange?: (handler: () => void) => () => void;
|
|
2529
|
+
browserTabsTransportFactory?: BrowserTabsTransportFactory;
|
|
2530
|
+
browserTabsPriorityTimings?: BrowserTabsPriorityTimings;
|
|
2531
|
+
browserTabsLeadershipTimings?: BrowserTabsPriorityTimings;
|
|
2532
|
+
onReceiveRemoteMsg?: (message: ListQueryBrowserTabsMessage<ItemState, QueryPayload, ItemPayload>) => void;
|
|
2533
|
+
onSessionKeyChanged?: (event: TestSessionKeyChangedEvent) => void;
|
|
2534
|
+
onOfflineTimelineEvent?: (event: TestOfflineTimelineEvent) => void;
|
|
2535
|
+
}; /** Overrides the manager's default minimum interval between low-priority fetches for this store. */
|
|
2536
|
+
lowPriorityThrottleMs?: number; /** Overrides the manager's default coalescing window for this store. */
|
|
2537
|
+
baseCoalescingWindowMs?: number;
|
|
2538
|
+
mediumPriorityDelayMs?: number;
|
|
2539
|
+
dynamicRealtimeThrottleMs?: (params: {
|
|
2540
|
+
lastFetchDuration: number;
|
|
2541
|
+
windowIsNotFocused: boolean;
|
|
2542
|
+
}) => number;
|
|
2543
|
+
revalidateOnWindowFocus?: boolean | (() => boolean);
|
|
2544
|
+
/** Reconnect-specific cooldown. The first reconnect revalidates immediately;
|
|
2545
|
+
* additional reconnects within the cooldown are coalesced into one trailing
|
|
2546
|
+
* revalidation. Set to `0` to disable this cooldown. */
|
|
2547
|
+
transportReconnectCooldownMs?: number;
|
|
2548
|
+
optimisticListUpdates?: OptimisticListUpdate<ItemState, QueryPayload, ItemPayload>[];
|
|
2549
|
+
onInvalidateQuery?: OnListQueryInvalidate<QueryPayload>;
|
|
2550
|
+
onInvalidateItem?: OnListQueryItemInvalidate<ItemState, ItemPayload>;
|
|
2551
|
+
onSchedulerEvent?: (event: RequestSchedulerEvents, data?: RequestSchedulerEventData) => void;
|
|
2552
|
+
onMutationError?: (error: unknown, options: {
|
|
2553
|
+
silentErrors?: boolean;
|
|
2554
|
+
}) => void; /** Opt-in hook-level query derivation from locally materialized items. */
|
|
2555
|
+
derivedQueries?: DerivedQueriesConfig<ItemState, QueryPayload, ItemPayload>;
|
|
2556
|
+
getQueryKey?: (params: QueryPayload) => ValidPayload | unknown[];
|
|
2557
|
+
getItemKey?: (params: ItemPayload) => ValidPayload | unknown[];
|
|
2558
|
+
/** Opt-in persistent storage configuration. When provided, cached items and queries
|
|
2559
|
+
* are loaded from storage on first read and saved back on successful fetches.
|
|
2560
|
+
* Session scoping always reuses this store manager's `getSessionKey`, and the
|
|
2561
|
+
* persisted namespace always reuses this store's `id`. */
|
|
2562
|
+
persistentStorage?: ListQueryPersistentStorageConfig<ItemState, QueryPayload, ItemPayload, StorageState, TOfflineOperations>;
|
|
2563
|
+
} & ([TPartialResources] extends [true] ? {
|
|
2564
|
+
partialResources: PartialResourcesConfig<ItemState>;
|
|
2565
|
+
} : {
|
|
2566
|
+
partialResources?: undefined;
|
|
2567
|
+
});
|
|
2568
|
+
type ListQueryStoreOptions<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TPartialResources extends boolean = false, TOffsetPagination extends boolean = false, TOfflineOperations extends ListQueryOfflineOperationsConfig<ItemState, QueryPayload, ItemPayload> = null, StorageState = unknown> = ListQueryStoreOptionsBase<ItemState, QueryPayload, ItemPayload, TPartialResources, TOfflineOperations, StorageState> & ([TOffsetPagination] extends [true] ? {
|
|
2569
|
+
fetchListFn: FetchListFnOffsetMode<ItemState, QueryPayload, ItemPayload>;
|
|
2570
|
+
offsetPagination: OffsetPaginationConfig;
|
|
2571
|
+
} : {
|
|
2572
|
+
fetchListFn: FetchListFnSizeMode<ItemState, QueryPayload, ItemPayload>;
|
|
2573
|
+
offsetPagination?: undefined;
|
|
2574
|
+
});
|
|
2575
|
+
declare function createListQueryStore<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload, TPartialResources extends boolean = false, TOffsetPagination extends boolean = false, TOfflineOperations extends ListQueryOfflineOperationsConfig<ItemState, QueryPayload, ItemPayload> = null, StorageState = unknown>(storeOptions: ListQueryStoreOptions<ItemState, QueryPayload, ItemPayload, TPartialResources, TOffsetPagination, TOfflineOperations, StorageState>): ListQueryStore<ItemState, QueryPayload, ItemPayload, TPartialResources, TOfflineOperations>;
|
|
2576
|
+
//#endregion
|
|
2577
|
+
//#region src/isOffScreenContext.d.ts
|
|
2578
|
+
/**
|
|
2579
|
+
* Context to set `isOffScreen` for all TSDF hooks within a subtree.
|
|
2580
|
+
*
|
|
2581
|
+
* When `true`, hooks wrapped by this context will not trigger data fetching or
|
|
2582
|
+
* respond to invalidation events, unless overridden by an explicit `isOffScreen`
|
|
2583
|
+
* option passed directly to the hook.
|
|
2584
|
+
*
|
|
2585
|
+
* @example
|
|
2586
|
+
* ```tsx
|
|
2587
|
+
* <IsOffScreenContext.Provider value={!isTabActive}>
|
|
2588
|
+
* <MyComponent />
|
|
2589
|
+
* </IsOffScreenContext.Provider>
|
|
2590
|
+
* ```
|
|
2591
|
+
*/
|
|
2592
|
+
declare const IsOffScreenContext: Context<boolean>;
|
|
2593
|
+
//#endregion
|
|
2594
|
+
//#region src/persistentStorage/offline/sessionCoordinator.d.ts
|
|
2595
|
+
/**
|
|
2596
|
+
* Returns the latest offline status for a session. If the session has not been
|
|
2597
|
+
* initialized yet, this returns a default "online" status with empty recovery data.
|
|
2598
|
+
*/
|
|
2599
|
+
declare function getGlobalOfflineStatus(sessionKey: string): GlobalOfflineStatus;
|
|
2600
|
+
/**
|
|
2601
|
+
* Returns the latest list of offline entities for a session.
|
|
2602
|
+
* Useful to render pending sync state badges or pending-item indicators.
|
|
2603
|
+
*/
|
|
2604
|
+
declare function getGlobalOfflineEntities(sessionKey: string): GlobalOfflineEntity[];
|
|
2605
|
+
/**
|
|
2606
|
+
* Returns the latest list of offline conflict/retry resolutions for a session.
|
|
2607
|
+
* Useful to render conflict-resolution trays or retry-required queues.
|
|
2608
|
+
*/
|
|
2609
|
+
declare function getGlobalOfflineResolutions(sessionKey: string): OfflineResolutionRecord[];
|
|
2610
|
+
/**
|
|
2611
|
+
* React hook that subscribes to the offline status stream for a session.
|
|
2612
|
+
*/
|
|
2613
|
+
declare function useGlobalOfflineStatus(sessionKey: string): GlobalOfflineStatus;
|
|
2614
|
+
/**
|
|
2615
|
+
* React hook that subscribes to the offline entities stream for a session.
|
|
2616
|
+
*/
|
|
2617
|
+
declare function useGlobalOfflineEntities(sessionKey: string): readonly GlobalOfflineEntity[];
|
|
2618
|
+
/**
|
|
2619
|
+
* React hook returning global offline conflict/retry resolutions for a session.
|
|
2620
|
+
*/
|
|
2621
|
+
declare function useGlobalOfflineResolutions(sessionKey: string): readonly OfflineResolutionRecord[];
|
|
2622
|
+
//#endregion
|
|
2623
|
+
//#region src/persistentStorage/asyncStorageAdapter.d.ts
|
|
2624
|
+
declare function createAsyncStorageAdapter(driver: AsyncStorageDriver): AsyncStorageAdapter;
|
|
2625
|
+
//#endregion
|
|
2626
|
+
//#region src/persistentStorage/indexedDbAsyncStorageAdapter.d.ts
|
|
2627
|
+
type IndexedDbPersistentStorageOptions$1 = {
|
|
2628
|
+
databaseName?: string;
|
|
230
2629
|
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
loadSize?: number;
|
|
240
|
-
};
|
|
241
|
-
declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload>({ debugName, fetchListFn, fetchItemFn, errorNormalizer, defaultQuerySize, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, disableInitialDataInvalidation, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, optimisticListUpdates, onInvalidateItem, onInvalidateQuery, }: {
|
|
242
|
-
debugName?: string;
|
|
243
|
-
fetchListFn: (payload: QueryPayload, size: number) => Promise<FetchListFnReturn<ItemState, ItemPayload>>;
|
|
244
|
-
fetchItemFn?: (itemId: ItemPayload) => Promise<ItemState>;
|
|
245
|
-
errorNormalizer: (exception: unknown) => NError;
|
|
246
|
-
defaultQuerySize?: number;
|
|
247
|
-
getInitialData?: () => ListQueryStoreInitialData<ItemState, QueryPayload, ItemPayload> | undefined;
|
|
248
|
-
disableInitialDataInvalidation?: boolean;
|
|
249
|
-
disableRefetchOnMount?: boolean;
|
|
250
|
-
lowPriorityThrottleMs?: number;
|
|
251
|
-
mediumPriorityThrottleMs?: number;
|
|
252
|
-
dynamicRealtimeThrottleMs?: (lastFetchDuration: number) => number;
|
|
253
|
-
optimisticListUpdates?: {
|
|
254
|
-
queries: QueryPayload | ((query: QueryPayload) => boolean) | QueryPayload[];
|
|
255
|
-
filterItem?: (item: ItemState) => boolean | null;
|
|
256
|
-
/** @default 'end' */
|
|
257
|
-
appendNewTo?: 'start' | 'end';
|
|
258
|
-
invalidateQueries?: boolean;
|
|
259
|
-
sort?: {
|
|
260
|
-
sortBy: (item: ItemState, itemPayload: ItemPayload) => string | number | (string | number)[];
|
|
261
|
-
/** @default 'asc' */
|
|
262
|
-
order?: 'asc' | 'desc' | ('asc' | 'desc')[];
|
|
263
|
-
};
|
|
264
|
-
}[];
|
|
265
|
-
onInvalidateQuery?: OnListQueryInvalidate<QueryPayload>;
|
|
266
|
-
onInvalidateItem?: OnListQueryItemInvalidate<ItemState, ItemPayload>;
|
|
267
|
-
}): {
|
|
268
|
-
store: Store<TSFDListQueryState<ItemState, NError, QueryPayload, ItemPayload>>;
|
|
269
|
-
reset: () => void;
|
|
270
|
-
scheduleListQueryFetch: {
|
|
271
|
-
(fetchType: FetchType, payload: QueryPayload, size?: number): ScheduleFetchResults;
|
|
272
|
-
(fetchType: FetchType, payload: QueryPayload[], size?: number): ScheduleFetchResults[];
|
|
273
|
-
};
|
|
274
|
-
getQueryState: (params: QueryPayload) => TSFDListQuery<NError, QueryPayload> | undefined;
|
|
275
|
-
getQueryKey: (params: QueryPayload) => string;
|
|
276
|
-
deleteItemState: (itemId: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[]) => void;
|
|
277
|
-
getItemState: {
|
|
278
|
-
(itemPayload: ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[]): {
|
|
279
|
-
payload: ItemPayload;
|
|
280
|
-
data: ItemState;
|
|
281
|
-
}[];
|
|
282
|
-
(itemPayload: ItemPayload): ItemState | null | undefined;
|
|
283
|
-
};
|
|
284
|
-
loadMore: (params: QueryPayload, size?: number) => ScheduleFetchResults;
|
|
285
|
-
invalidateQueryAndItems: ({ itemPayload, queryPayload, type: priority, }: {
|
|
286
|
-
itemPayload: false | ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[];
|
|
287
|
-
queryPayload: false | QueryPayload | QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean);
|
|
288
|
-
type?: FetchType | undefined;
|
|
289
|
-
}) => void;
|
|
290
|
-
scheduleItemFetch: {
|
|
291
|
-
(fetchType: FetchType, itemPayload: ItemPayload): ScheduleFetchResults;
|
|
292
|
-
(fetchType: FetchType, itemPayload: ItemPayload[]): ScheduleFetchResults[];
|
|
293
|
-
};
|
|
294
|
-
awaitItemFetch: (itemPayload: ItemPayload) => Promise<{
|
|
295
|
-
data: null;
|
|
296
|
-
error: NError;
|
|
297
|
-
} | {
|
|
298
|
-
data: ItemState;
|
|
299
|
-
error: null;
|
|
300
|
-
}>;
|
|
301
|
-
awaitListQueryFetch: (params: QueryPayload, size?: number) => Promise<{
|
|
302
|
-
items: [
|
|
303
|
-
];
|
|
304
|
-
error: NError;
|
|
305
|
-
hasMore: boolean;
|
|
306
|
-
} | {
|
|
307
|
-
items: {
|
|
308
|
-
data: ItemState;
|
|
309
|
-
itemPayload: ItemPayload;
|
|
310
|
-
}[];
|
|
311
|
-
error: null;
|
|
312
|
-
hasMore: boolean;
|
|
313
|
-
}>;
|
|
314
|
-
useMultipleListQueries: <SelectedItem = ItemState, QueryMetadata extends Record<string, unknown> | undefined = undefined>(queries: ListQueryUseMultipleListQueriesQuery<QueryPayload, QueryMetadata>[], { itemSelector, selectorUsesExternalDeps, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, omitPayload: allItemsOmitPayload, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, loadSize: allItemsLoadSize, }?: {
|
|
315
|
-
itemSelector?: (data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem;
|
|
316
|
-
selectorUsesExternalDeps?: boolean;
|
|
317
|
-
returnIdleStatus?: boolean;
|
|
318
|
-
returnRefetchingStatus?: boolean;
|
|
319
|
-
omitPayload?: boolean;
|
|
320
|
-
disableRefetchOnMount?: boolean;
|
|
321
|
-
isOffScreen?: boolean;
|
|
322
|
-
loadSize?: number;
|
|
323
|
-
}) => readonly TSFDUseListQueryReturn<SelectedItem, QueryPayload, NError, QueryMetadata>[];
|
|
324
|
-
useListQuery: <SelectedItem_1 = ItemState>(payload: QueryPayload | false | null | undefined, { isOffScreen, itemSelector, disableRefetchOnMount, returnIdleStatus, returnRefetchingStatus, loadSize, omitPayload, ensureIsLoaded, selectorUsesExternalDeps, }?: {
|
|
325
|
-
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem_1) | undefined;
|
|
326
|
-
omitPayload?: boolean | undefined;
|
|
327
|
-
disableRefetchOnMount?: boolean | undefined;
|
|
328
|
-
returnIdleStatus?: boolean | undefined;
|
|
329
|
-
returnRefetchingStatus?: boolean | undefined;
|
|
330
|
-
ensureIsLoaded?: boolean | undefined;
|
|
331
|
-
loadSize?: number | undefined;
|
|
332
|
-
isOffScreen?: boolean | undefined;
|
|
333
|
-
selectorUsesExternalDeps?: boolean | undefined;
|
|
334
|
-
}) => TSFDUseListQueryReturn<SelectedItem_1, QueryPayload, NError, undefined>;
|
|
335
|
-
getItemKey: (params: ItemPayload) => string;
|
|
336
|
-
useItem: <SelectedItem_2 = ItemState | null>(itemPayload: ItemPayload | false | null | undefined, { selector, selectorUsesExternalDeps, disableRefetchOnMount, returnIdleStatus, returnRefetchingStatus, ensureIsLoaded, loadFromStateOnly, isOffScreen, }?: {
|
|
337
|
-
selector?: ((data: ItemState | null, id: ItemPayload | null) => SelectedItem_2) | undefined;
|
|
338
|
-
selectorUsesExternalDeps?: boolean | undefined;
|
|
339
|
-
disableRefetchOnMount?: boolean | undefined;
|
|
340
|
-
returnIdleStatus?: boolean | undefined;
|
|
341
|
-
returnRefetchingStatus?: boolean | undefined;
|
|
342
|
-
ensureIsLoaded?: boolean | undefined;
|
|
343
|
-
loadFromStateOnly?: boolean | undefined;
|
|
344
|
-
isOffScreen?: boolean | undefined;
|
|
345
|
-
}) => TSFDUseListItemReturn<SelectedItem_2, NError, ItemPayload, undefined>;
|
|
346
|
-
useMultipleItems: <SelectedItem_3 = ItemState | null, QueryMetadata_1 extends Record<string, unknown> | undefined = undefined>(items: ListQueryUseMultipleItemsQuery<ItemPayload, QueryMetadata_1>[], { selector, loadFromStateOnly, selectorUsesExternalDeps, returnIdleStatus: allItemsReturnIdleStatus, returnRefetchingStatus: allItemsReturnRefetchingStatus, disableRefetchOnMount: allItemsDisableRefetchOnMount, isOffScreen: allItemsIsOffScreen, }?: {
|
|
347
|
-
loadFromStateOnly?: boolean | undefined;
|
|
348
|
-
selector?: ((data: ItemState | null, id: ItemPayload | null) => SelectedItem_3) | undefined;
|
|
349
|
-
selectorUsesExternalDeps?: boolean | undefined;
|
|
350
|
-
returnIdleStatus?: boolean | undefined;
|
|
351
|
-
returnRefetchingStatus?: boolean | undefined;
|
|
352
|
-
disableRefetchOnMount?: boolean | undefined;
|
|
353
|
-
isOffScreen?: boolean | undefined;
|
|
354
|
-
}) => readonly TSFDUseListItemReturn<SelectedItem_3, NError, ItemPayload, QueryMetadata_1>[];
|
|
355
|
-
addItemToState: (itemPayload: ItemPayload, data: ItemState, { addItemToQueries, }?: {
|
|
356
|
-
addItemToQueries?: {
|
|
357
|
-
queries: QueryPayload | QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean);
|
|
358
|
-
appendTo: 'start' | 'end' | ((itemsPayload: ItemPayload[]) => number);
|
|
359
|
-
} | undefined;
|
|
360
|
-
}) => void;
|
|
361
|
-
updateItemState: (itemIds: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[], produceNewData: (draftData: ItemState, itemPayload: ItemPayload) => void | ItemState, { ifNothingWasUpdated, }?: {
|
|
362
|
-
ifNothingWasUpdated?: () => void;
|
|
363
|
-
}) => boolean;
|
|
364
|
-
startItemMutation: (itemId: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[]) => () => void;
|
|
365
|
-
getQueriesState: (params: QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean)) => {
|
|
366
|
-
query: TSFDListQuery<NError, QueryPayload>;
|
|
367
|
-
key: string;
|
|
368
|
-
}[];
|
|
369
|
-
getQueriesRelatedToItem: (itemPayload: ItemPayload) => {
|
|
370
|
-
query: TSFDListQuery<NError, QueryPayload>;
|
|
371
|
-
key: string;
|
|
372
|
-
}[];
|
|
373
|
-
useFindItem: <SelectedItem_4 = ItemState | null>(findItem: (item: ItemState, itemPayload: ItemPayload) => boolean, { selector, }?: {
|
|
374
|
-
selector?: ((data: ItemState, id: ItemPayload) => SelectedItem_4) | undefined;
|
|
375
|
-
}) => Readonly<SelectedItem_4 | null>;
|
|
2630
|
+
//#endregion
|
|
2631
|
+
//#region src/persistentStorage/localStorageMetadata.d.ts
|
|
2632
|
+
type ManagedLocalStorageIo = {
|
|
2633
|
+
getItem(key: string): string | null;
|
|
2634
|
+
setItem(key: string, value: string): void;
|
|
2635
|
+
removeItem(key: string): void;
|
|
2636
|
+
listKeys(): string[];
|
|
2637
|
+
queueManifestWrite?(key: string, value: string | null): void;
|
|
376
2638
|
};
|
|
377
|
-
type
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
2639
|
+
type StoredManagedLocalStorageManifestEntry = {
|
|
2640
|
+
entryKey: string | undefined;
|
|
2641
|
+
lastAccessAt: number;
|
|
2642
|
+
sizeBytes?: number;
|
|
2643
|
+
meta?: unknown;
|
|
2644
|
+
};
|
|
2645
|
+
type ManagedLocalStorageManifestEntry<TMeta = unknown> = {
|
|
2646
|
+
entryKey: string | undefined;
|
|
2647
|
+
payloadKey: string;
|
|
2648
|
+
lastAccessAt: number;
|
|
2649
|
+
sizeBytes?: number;
|
|
2650
|
+
meta?: TMeta;
|
|
2651
|
+
};
|
|
2652
|
+
type ManagedLocalStorageNamespaceManifestEntry<TMeta = unknown> = ManagedLocalStorageManifestEntry<TMeta> & {
|
|
2653
|
+
entryKey: string;
|
|
2654
|
+
};
|
|
2655
|
+
declare function readManagedLocalStorageManifestEntriesByPrefix(prefix: string, io?: ManagedLocalStorageIo): ManagedLocalStorageNamespaceManifestEntry[];
|
|
2656
|
+
declare function readManagedLocalStorageSingleEntryByPayload(payloadKey: string, io?: ManagedLocalStorageIo): ManagedLocalStorageManifestEntry | null;
|
|
2657
|
+
declare function readManagedLocalStorageNamespaceEntryByPayload(payloadKey: string, storagePrefix: string, io?: ManagedLocalStorageIo): ManagedLocalStorageManifestEntry | null;
|
|
2658
|
+
type UpsertSingleEntryParams = {
|
|
2659
|
+
storageKey: string;
|
|
2660
|
+
lastAccessAt?: number;
|
|
2661
|
+
clearSizeBytes?: boolean;
|
|
2662
|
+
sizeBytes?: number;
|
|
2663
|
+
mergeMeta?: (currentMeta: StoredManagedLocalStorageManifestEntry['meta']) => unknown;
|
|
2664
|
+
meta?: unknown;
|
|
2665
|
+
};
|
|
2666
|
+
declare function upsertManagedLocalStorageSingleEntry(params: UpsertSingleEntryParams, io?: ManagedLocalStorageIo): string;
|
|
2667
|
+
type UpsertNamespaceEntryParams = {
|
|
2668
|
+
storagePrefix: string;
|
|
2669
|
+
entryKey: string;
|
|
2670
|
+
lastAccessAt?: number;
|
|
2671
|
+
sizeBytes?: number;
|
|
2672
|
+
mergeMeta?: (currentMeta: StoredManagedLocalStorageManifestEntry['meta']) => unknown;
|
|
2673
|
+
meta?: unknown;
|
|
2674
|
+
};
|
|
2675
|
+
declare function upsertManagedLocalStorageNamespaceEntry(params: UpsertNamespaceEntryParams, io?: ManagedLocalStorageIo): string;
|
|
2676
|
+
//#endregion
|
|
2677
|
+
//#region src/persistentStorage/storageAdapter.d.ts
|
|
2678
|
+
type LocalStorageMetadataOptions = {
|
|
2679
|
+
metadata: 'single';
|
|
2680
|
+
} | {
|
|
2681
|
+
metadata: 'namespace';
|
|
2682
|
+
namespacePrefix: string;
|
|
2683
|
+
};
|
|
2684
|
+
type LocalPersistentStorage = {
|
|
2685
|
+
kind: 'local-sync';
|
|
2686
|
+
runLocked<T>(callback: () => T | Promise<T>): Promise<T>;
|
|
2687
|
+
readRaw(key: string): string | null;
|
|
2688
|
+
write<T>(key: string, value: T): {
|
|
2689
|
+
rawValue: string;
|
|
2690
|
+
sizeBytes: number;
|
|
2691
|
+
};
|
|
2692
|
+
remove(key: string, options?: LocalStorageMetadataOptions): void;
|
|
2693
|
+
removeByPrefix(prefix: string): void;
|
|
2694
|
+
listKeys(prefix: string): string[];
|
|
2695
|
+
listRawKeys(prefix: string): string[];
|
|
2696
|
+
getManifestKeyForSingle(storageKey: string): string;
|
|
2697
|
+
getManifestKeyForPrefix(storagePrefix: string): string;
|
|
2698
|
+
readSingleEntryMetadataByPayload(payloadKey: string): ReturnType<typeof readManagedLocalStorageSingleEntryByPayload>;
|
|
2699
|
+
readNamespaceEntryMetadataByPayload(payloadKey: string, namespacePrefix: string): ReturnType<typeof readManagedLocalStorageNamespaceEntryByPayload>;
|
|
2700
|
+
listManifestEntries(prefix: string): ReturnType<typeof readManagedLocalStorageManifestEntriesByPrefix>;
|
|
2701
|
+
upsertSingleEntry(args: Parameters<typeof upsertManagedLocalStorageSingleEntry>[0]): string;
|
|
2702
|
+
upsertNamespaceEntry(args: Parameters<typeof upsertManagedLocalStorageNamespaceEntry>[0]): string;
|
|
2703
|
+
touchSingleEntry(payloadKey: string): boolean;
|
|
2704
|
+
touchNamespaceEntry(payloadKey: string, namespacePrefix: string): boolean;
|
|
2705
|
+
clearManifest(manifestKey: string): void;
|
|
2706
|
+
clearSession(sessionKey: string): void;
|
|
2707
|
+
registerMaintenanceCallback(manifestKey: string, callback: () => Promise<void>): void;
|
|
2708
|
+
unregisterMaintenanceCallback(manifestKey: string): void;
|
|
2709
|
+
runMaintenance(forceManifestKeys?: Iterable<string>): Promise<void>;
|
|
2710
|
+
readProtectedStorageKeys(sessionKey: string): Set<string>;
|
|
2711
|
+
syncSessionProtectedKeys(sessionKey: string, protectedKeys: Iterable<string>): void;
|
|
2712
|
+
};
|
|
2713
|
+
declare const localPersistentStorage: LocalPersistentStorage;
|
|
2714
|
+
declare const opfsPersistentStorage: AsyncStorageAdapter;
|
|
2715
|
+
declare const indexedDbPersistentStorage: AsyncStorageAdapter;
|
|
2716
|
+
type IndexedDbPersistentStorageOptions = IndexedDbPersistentStorageOptions$1;
|
|
2717
|
+
declare function createIndexedDbPersistentStorage(options?: IndexedDbPersistentStorageOptions): AsyncStorageAdapter;
|
|
2718
|
+
//#endregion
|
|
2719
|
+
//#region src/persistentStorage/persistentStorageManager.d.ts
|
|
2720
|
+
/** Clears all persistent storage entries for a given session key and adapter. */
|
|
2721
|
+
declare function clearSessionStorage(sessionKey: string, adapter: StorageAdapter): Promise<void>;
|
|
2722
|
+
/** Clears all persistent storage entries for a given session key across built-in adapters. */
|
|
2723
|
+
declare function clearAllSessionStorage(sessionKey: string): Promise<void>;
|
|
2724
|
+
//#endregion
|
|
2725
|
+
//#region src/persistentStorage/opfsOfflineUploadAdapter.d.ts
|
|
2726
|
+
declare const opfsOfflineUploadAdapter: OfflineUploadAdapter;
|
|
2727
|
+
//#endregion
|
|
2728
|
+
export { type AsyncStorageAdapter, type AsyncStorageDiscoveredScope, type AsyncStorageDriver, type AsyncStorageDriverSetEntry, type AsyncStorageMetadataOrder, type AsyncStorageNamespaceCommitArgs, type AsyncStorageNamespaceCommitTouch, type AsyncStorageNamespaceCommitUpsert, type AsyncStorageNamespaceGetResult, type AsyncStorageNamespaceHandle, type AsyncStorageNamespaceKind, type AsyncStorageNamespaceScope, type AsyncStorageReadOptions, type BlockWindowCloseHandler, CollectionBrowserTabsMessage, CollectionInitialStateItem, CollectionItemStatus, type CollectionOfflineEntityRef, type CollectionOfflineOperationDefinition, type CollectionPersistentStorageConfig, CollectionStateCleanup, CollectionStore, CollectionStoreEvents, CollectionStoreOptions, CollectionStoreStoreEvents, CollectionUseMultipleItemsQuery, type ConvertedPersistentStorageDataSchema, type CreateStoreManagerOptions, type DefineCollectionOfflineOperations, type DefineDocumentOfflineOperations, type DefineListQueryOfflineOperations, type DefineOfflineOperation, type DerivedQueriesConfig, type DerivedQueryContext, type DerivedQuerySource, DocumentBrowserTabsMessage, type DocumentOfflineOperationDefinition, type DocumentPersistentStorageConfig, DocumentStatus, DocumentStore, DocumentStoreOptions, DocumentStoreState, DocumentStoreStoreEvents, type FetchListFnReturn, type FetchListFnReturnItem, type FieldsInput, type FieldsOption, type GlobalOfflineEntity, type GlobalOfflineStatus, type IndexedDbPersistentStorageOptions, IsOffScreenContext, type ListQueryOfflineEntityRef, type ListQueryOfflineOperationDefinition, type ListQueryPersistentStorageConfig, type ListQueryStore, type ListQueryStoreEvents, type ListQueryStoreInitialData, type ListQueryStoreOptions, type ListQueryUseMultipleItemsQuery, type ListQueryUseMultipleListQueriesQuery, type MutationDebounce, type MutationSkipped, type OfflineAccumulationConfig, type OfflineAccumulationMergeContext, type OfflineConflictResolutionAction, type OfflineEntityMutationKind, type OfflineMutationDescriptor, type OfflineMutationInput, type OfflineMutationQueueingCause, type OfflineMutationQueueingConfig, type OfflineMutationQueueingPolicy, type OfflineMutationResult, type OfflineMutationUploadsInput, type OfflineOperationKind, type OfflineOperationUploadsContext, type OfflineQueueEntry, type OfflineReplayRetryConfig, type OfflineResolutionAction, type OfflineResolutionActionForOperation, type OfflineResolutionConflictParseError, type OfflineResolutionConflictParseErrorCode, type OfflineResolutionRecord, type OfflineResolutionRecordForOperation, type OfflineResolutionRecordForStore, type OfflineRetryExhaustedResolutionAction, type OfflineRuntimeConfig, type OfflineRuntimeConfigUpdate, type OfflineSession, type OfflineSessionConfig, type OfflineSessionUploadsConfig, type OfflineStoredUploadRecord, type OfflineSupersedeConfig, type OfflineSyncState, type OfflineTempEntitiesConfig, type OfflineTempEntitiesReconciliation, type OfflineTempEntityConfig, type OfflineTempEntityPendingEntry, type OfflineUpload, type OfflineUploadAdapter, type OfflineUploadProgress, type OfflineUploadSource, type OfflineUploadState, type OfflineUploadTransportContext, type OffsetPaginationConfig, OnCollectionItemInvalidate, OnDocumentInvalidate, type OnListQueryInvalidate, type OnListQueryItemInvalidate, type OperationConflict, type OperationResult, type OptimisticListUpdate, type ParsedOfflineResolutionConflictResultForOperation, type PartialResourcesConfig, type PayloadDebounce, type PersistentStorageBaseConfig, type PersistentStorageDataSchema, type PersistentStoragePreloadResult, type PersistentStorageSchema, type QueryFetchPayload, type QueryStatus, type StorageAdapter, type StoreError, StoreFetchError, type StoreManager, StoreMutationError, type TSDFItemQuery, type TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, type TSFDListQuery, type TSFDListQueryState, TSFDUseCollectionItemReturn, type TSFDUseListItemReturn, type TSFDUseListQueryReturn, type TSFDUsePendingOfflineItemsReturn, type ValidPayload, type ValidStoreState, clearAllSessionStorage, clearSessionStorage, createAsyncStorageAdapter, createCollectionStore, createDocumentStore, createIndexedDbPersistentStorage, createListQueryStore, createStoreManager, defaultOfflineRuntimeConfig, fetchTypePriority, getGlobalOfflineEntities, getGlobalOfflineResolutions, getGlobalOfflineStatus, indexedDbPersistentStorage, localPersistentStorage, mutationSkipped, opfsOfflineUploadAdapter, opfsPersistentStorage, useGlobalOfflineEntities, useGlobalOfflineResolutions, useGlobalOfflineStatus };
|