@warp-drive/experiments 0.2.7-alpha.19 → 0.2.7-alpha.20

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.
Files changed (97) hide show
  1. package/README.md +1 -1
  2. package/declarations/data-worker.d.ts +35 -2
  3. package/declarations/data-worker.d.ts.map +1 -0
  4. package/declarations/document-storage-CwwTQ49-.d.ts +91 -0
  5. package/declarations/document-storage-CwwTQ49-.d.ts.map +1 -0
  6. package/declarations/document-storage.d.ts +2 -1
  7. package/declarations/image-fetch.d.ts +60 -1
  8. package/declarations/image-fetch.d.ts.map +1 -0
  9. package/declarations/image-worker.d.ts +40 -1
  10. package/declarations/image-worker.d.ts.map +1 -0
  11. package/declarations/storage.d.ts +359 -7
  12. package/declarations/storage.d.ts.map +1 -0
  13. package/declarations/types-CRs-Qww6.d.ts +17 -0
  14. package/declarations/types-CRs-Qww6.d.ts.map +1 -0
  15. package/declarations/worker-fetch.d.ts +23 -1
  16. package/declarations/worker-fetch.d.ts.map +1 -0
  17. package/dist/data-worker.js +235 -339
  18. package/dist/data-worker.js.map +1 -0
  19. package/dist/document-storage-LM925Stz.js +270 -0
  20. package/dist/document-storage-LM925Stz.js.map +1 -0
  21. package/dist/document-storage.js +3 -1
  22. package/dist/image-fetch.js +108 -79
  23. package/dist/image-fetch.js.map +1 -0
  24. package/dist/image-worker.js +95 -95
  25. package/dist/image-worker.js.map +1 -0
  26. package/dist/storage.js +825 -1055
  27. package/dist/storage.js.map +1 -0
  28. package/dist/unpkg/dev/data-worker.js +231 -338
  29. package/dist/unpkg/dev/data-worker.js.map +1 -0
  30. package/dist/unpkg/dev/document-storage-DkiEg9rY.js +268 -0
  31. package/dist/unpkg/dev/document-storage-DkiEg9rY.js.map +1 -0
  32. package/dist/unpkg/dev/document-storage.js +2 -348
  33. package/dist/unpkg/dev/image-fetch.js +104 -71
  34. package/dist/unpkg/dev/image-fetch.js.map +1 -0
  35. package/dist/unpkg/dev/image-worker.js +93 -94
  36. package/dist/unpkg/dev/image-worker.js.map +1 -0
  37. package/dist/unpkg/dev/storage.js +819 -1075
  38. package/dist/unpkg/dev/storage.js.map +1 -0
  39. package/dist/unpkg/dev/worker-fetch.js +112 -145
  40. package/dist/unpkg/dev/worker-fetch.js.map +1 -0
  41. package/dist/unpkg/dev-deprecated/data-worker.js +231 -338
  42. package/dist/unpkg/dev-deprecated/data-worker.js.map +1 -0
  43. package/dist/unpkg/dev-deprecated/document-storage-DkiEg9rY.js +268 -0
  44. package/dist/unpkg/dev-deprecated/document-storage-DkiEg9rY.js.map +1 -0
  45. package/dist/unpkg/dev-deprecated/document-storage.js +2 -348
  46. package/dist/unpkg/dev-deprecated/image-fetch.js +104 -71
  47. package/dist/unpkg/dev-deprecated/image-fetch.js.map +1 -0
  48. package/dist/unpkg/dev-deprecated/image-worker.js +93 -94
  49. package/dist/unpkg/dev-deprecated/image-worker.js.map +1 -0
  50. package/dist/unpkg/dev-deprecated/storage.js +819 -1075
  51. package/dist/unpkg/dev-deprecated/storage.js.map +1 -0
  52. package/dist/unpkg/dev-deprecated/worker-fetch.js +112 -145
  53. package/dist/unpkg/dev-deprecated/worker-fetch.js.map +1 -0
  54. package/dist/unpkg/prod/data-worker.js +224 -324
  55. package/dist/unpkg/prod/data-worker.js.map +1 -0
  56. package/dist/unpkg/prod/document-storage-D0k_6GM9.js +262 -0
  57. package/dist/unpkg/prod/document-storage-D0k_6GM9.js.map +1 -0
  58. package/dist/unpkg/prod/document-storage.js +2 -338
  59. package/dist/unpkg/prod/image-fetch.js +101 -71
  60. package/dist/unpkg/prod/image-fetch.js.map +1 -0
  61. package/dist/unpkg/prod/image-worker.js +93 -94
  62. package/dist/unpkg/prod/image-worker.js.map +1 -0
  63. package/dist/unpkg/prod/storage.js +750 -979
  64. package/dist/unpkg/prod/storage.js.map +1 -0
  65. package/dist/unpkg/prod/worker-fetch.js +109 -145
  66. package/dist/unpkg/prod/worker-fetch.js.map +1 -0
  67. package/dist/unpkg/prod-deprecated/data-worker.js +224 -324
  68. package/dist/unpkg/prod-deprecated/data-worker.js.map +1 -0
  69. package/dist/unpkg/prod-deprecated/document-storage-D0k_6GM9.js +262 -0
  70. package/dist/unpkg/prod-deprecated/document-storage-D0k_6GM9.js.map +1 -0
  71. package/dist/unpkg/prod-deprecated/document-storage.js +2 -338
  72. package/dist/unpkg/prod-deprecated/image-fetch.js +101 -71
  73. package/dist/unpkg/prod-deprecated/image-fetch.js.map +1 -0
  74. package/dist/unpkg/prod-deprecated/image-worker.js +93 -94
  75. package/dist/unpkg/prod-deprecated/image-worker.js.map +1 -0
  76. package/dist/unpkg/prod-deprecated/storage.js +750 -979
  77. package/dist/unpkg/prod-deprecated/storage.js.map +1 -0
  78. package/dist/unpkg/prod-deprecated/worker-fetch.js +109 -145
  79. package/dist/unpkg/prod-deprecated/worker-fetch.js.map +1 -0
  80. package/dist/worker-fetch.js +116 -153
  81. package/dist/worker-fetch.js.map +1 -0
  82. package/package.json +9 -9
  83. package/declarations/data-worker/cache-handler.d.ts +0 -7
  84. package/declarations/data-worker/fetch.d.ts +0 -21
  85. package/declarations/data-worker/types.d.ts +0 -31
  86. package/declarations/data-worker/utils.d.ts +0 -12
  87. package/declarations/data-worker/worker.d.ts +0 -23
  88. package/declarations/document-storage/index.d.ts +0 -90
  89. package/declarations/image-worker/fetch.d.ts +0 -18
  90. package/declarations/image-worker/types.d.ts +0 -21
  91. package/declarations/image-worker/worker.d.ts +0 -14
  92. package/declarations/storage/-private/reactive-map.d.ts +0 -13
  93. package/declarations/storage/-private/storage-infra.d.ts +0 -104
  94. package/declarations/storage/cache.d.ts +0 -43
  95. package/declarations/storage/storage-resource.d.ts +0 -137
  96. package/declarations/storage/storage.d.ts +0 -88
  97. package/dist/index-CGCX7hY2.js +0 -349
package/README.md CHANGED
@@ -27,5 +27,5 @@
27
27
 
28
28
  - [DataWorker](./src/data-worker/README.md)
29
29
  - [DocumentStorage](./src/document-storage/README.md)
30
- - [ImageWorker](./src/image-worker/README.md)
30
+ - [ImageWorker](./src/image-worker.md)
31
31
  - ReactiveStorage
@@ -1,2 +1,35 @@
1
- export { DataWorker } from "./data-worker/worker.js";
2
- export { CacheHandler } from "./data-worker/cache-handler.js";
1
+ import { t as DocumentStorage } from "./document-storage-CwwTQ49-.js";
2
+ import { n as RequestEventData, t as AbortEventData } from "./types-CRs-Qww6.js";
3
+ import { CacheHandler as CacheHandler$1, Future } from "@warp-drive/core/request";
4
+ import { Store } from "@warp-drive/core";
5
+ //#region src/data-worker/worker.d.ts
6
+ declare class DataWorker {
7
+ store: Store;
8
+ threads: Map<string, MessagePort>;
9
+ pending: Map<string, Map<number, Future<unknown>>>;
10
+ isSharedWorker: boolean;
11
+ options: {
12
+ persisted: boolean;
13
+ scope?: string;
14
+ };
15
+ storage: DocumentStorage;
16
+ constructor(UserStore: typeof Store, options?: {
17
+ persisted: boolean;
18
+ scope?: string;
19
+ });
20
+ initialize(): void;
21
+ setupThread(thread: string, port: MessagePort): void;
22
+ abortRequest(event: AbortEventData): void;
23
+ request(event: RequestEventData): Promise<void>;
24
+ }
25
+ //#endregion
26
+ //#region src/data-worker/cache-handler.d.ts
27
+ /**
28
+ * A simplified CacheHandler that hydrates ResourceDataDocuments from the cache
29
+ * with their referenced resources.
30
+ *
31
+ */
32
+ declare const CacheHandler: CacheHandler$1;
33
+ //#endregion
34
+ export { CacheHandler, DataWorker };
35
+ //# sourceMappingURL=data-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-worker.d.ts","names":[],"sources":["../src/data-worker/worker.ts","../src/data-worker/cache-handler.ts"],"mappings":";;;;;cASa;EACX,OAAe;EACf,SAAiB,YAAY;EAC7B,SAAiB,YAAY,YAAY;EACzC;EACA;IAAmB;IAAoB;;EACvC,SAAiB;EAEjB,YAAY,kBAAkB,OAAO;IAAY;IAAoB;;EAarE;EAkCA,YAAY,gBAAgB,MAAM;EAqBlC,aAAa,OAAO;EAUpB,QAAc,OAAO,mBAAmB;;;;;;;;;cCnE7B,cAAc"}
@@ -0,0 +1,91 @@
1
+ import { StructuredDocument } from "@warp-drive/core/types/request";
2
+ import { PersistedResourceKey } from "@warp-drive/core/types/identifier";
3
+ import { ResourceDataDocument, ResourceDocument } from "@warp-drive/core/types/spec/document";
4
+ import { ExistingResourceObject } from "@warp-drive/core/types/spec/json-api-raw";
5
+ //#region src/document-storage/index.d.ts
6
+ type DocumentStorageOptions = {
7
+ /**
8
+ * The scope of the storage. This is used to enable multiple distinct
9
+ * storage areas within the same origin.
10
+ *
11
+ * One use case for this is to have a separate storage area for each
12
+ * user credential. So for instance, in applications that allow a single
13
+ * user to have multiple accounts, each account can have its own storage!
14
+ */
15
+ scope: string;
16
+ /**
17
+ * When set to true, if other instances of the storage are created with
18
+ * the same scope, they will not share the same in-memory cache and BroadcastChannel.
19
+ *
20
+ * This is mostly useful for testing purposes to replicate the behavior of
21
+ * multiple tabs or workers.
22
+ */
23
+ isolated: boolean;
24
+ };
25
+ /**
26
+ * DocumentStorage is specifically designed around WarpDrive Cache and Request concepts.
27
+ *
28
+ * CacheFileDocument is a StructuredDocument (request response) whose `content` is
29
+ * the ResourceDocument returned by inserting the request into a Store's Cache.
30
+ */
31
+ type CacheFileDocument = StructuredDocument<ResourceDocument>;
32
+ /**
33
+ * A CacheDocument is a reconstructed request response that rehydrates ResourceDocument
34
+ * with the associated resources based on their identifiers.
35
+ */
36
+ type CacheDocument = StructuredDocument<ResourceDocument<ExistingResourceObject>>;
37
+ type DocumentIdentifier = {
38
+ lid: string;
39
+ };
40
+ type MemCache = {
41
+ documents: Map<string, CacheFileDocument>;
42
+ resources: Map<string, ExistingResourceObject>;
43
+ };
44
+ declare class InternalDocumentStorage {
45
+ readonly options: DocumentStorageOptions;
46
+ _fileHandle: Promise<FileSystemFileHandle>;
47
+ _channel: BroadcastChannel;
48
+ _invalidated: boolean;
49
+ _lastModified: number;
50
+ _cache: MemCache | null;
51
+ _filePromise: Promise<MemCache> | null;
52
+ constructor(options: DocumentStorageOptions);
53
+ _onMessage(_event: MessageEvent): void;
54
+ _open(scope: string): Promise<FileSystemFileHandle>;
55
+ _read(): Promise<MemCache>;
56
+ _patch(documentKey: string, document: CacheFileDocument, updatedResources: Map<string, ExistingResourceObject>): Promise<void>;
57
+ getDocument(key: DocumentIdentifier): Promise<CacheDocument | null>;
58
+ putDocument(document: CacheFileDocument, resourceCollector: (resourceIdentifier: PersistedResourceKey) => ExistingResourceObject): Promise<void>;
59
+ _getResources(document: ResourceDataDocument, resourceCollector: (resourceIdentifier: PersistedResourceKey) => ExistingResourceObject, resources?: Map<string, ExistingResourceObject>): Map<string, ExistingResourceObject>;
60
+ putResources(document: ResourceDataDocument, resourceCollector: (resourceIdentifier: PersistedResourceKey) => ExistingResourceObject): Promise<void>;
61
+ clear(reset?: boolean): Promise<void>;
62
+ }
63
+ /**
64
+ * DocumentStorage is a wrapper around the StorageManager API that provides
65
+ * a simple interface for reading and updating documents and requests.
66
+ *
67
+ * Some goals for this experiment:
68
+ *
69
+ * - optimize for storing requests/documents
70
+ * - optimize for storing resources
71
+ * - optimize for looking up resources associated to a document
72
+ * - optimize for notifying cross-tab when data is updated
73
+ *
74
+ * optional features:
75
+ *
76
+ * - support for offline mode
77
+ * - ?? support for relationship based cache traversal
78
+ * - a way to index records by type + another field (e.g updatedAt/createAt/name)
79
+ * such that simple queries can be done without having to scan all records
80
+ */
81
+ declare class DocumentStorage {
82
+ readonly _storage: InternalDocumentStorage;
83
+ constructor(options?: Partial<DocumentStorageOptions>);
84
+ getDocument(key: DocumentIdentifier): Promise<CacheDocument | null>;
85
+ putDocument(document: CacheFileDocument, resourceCollector: (resourceIdentifier: PersistedResourceKey) => ExistingResourceObject): Promise<void>;
86
+ putResources(document: ResourceDataDocument, resourceCollector: (resourceIdentifier: PersistedResourceKey) => ExistingResourceObject): Promise<void>;
87
+ clear(reset?: boolean): Promise<void>;
88
+ }
89
+ //#endregion
90
+ export { DocumentStorage as t };
91
+ //# sourceMappingURL=document-storage-CwwTQ49-.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-storage-CwwTQ49-.d.ts","names":[],"sources":["../src/document-storage/index.ts"],"mappings":";;;;;KAUY;;;;;;;;;EASV;;;;;;;;EAQA;;;;;;;;KAQG,oBAAoB,mBAAmB;;;;;KAKvC,gBAAgB,mBAAmB,iBAAiB;KAMpD;EAAuB;;KAEvB;EACH,WAAW,YAAY;EACvB,WAAW,YAAY;;cAGnB;WACa,SAAS;EAC1B,aAAqB,QAAQ;EAC7B,UAAkB;EAClB;EACA;EACA,QAAgB;EAChB,cAAsB,QAAQ;EAE9B,YAAY,SAAS;EAWrB,WAAW,QAAQ;EAInB,MAAY,gBAAgB,QAAQ;EAMpC,SAAe,QAAQ;EAmCvB,OACE,qBACA,UAAU,mBACV,kBAAkB,YAAY,0BAC7B;EAuBH,YAAkB,KAAK,qBAAqB,QAAQ;EAqDpD,YACE,UAAU,mBACV,oBAAoB,oBAAoB,yBAAyB,yBAChE;EAkBH,cACE,UAAU,sBACV,oBAAoB,oBAAoB,yBAAyB,wBACjE,YAAW,YAAY,0BACtB,YAAY;EAqBf,aACE,UAAU,sBACV,oBAAoB,oBAAoB,yBAAyB,yBAChE;EAwBH,MAAY,kBAAkB;;;;;;;;;;;;;;;;;;;;cAuInB;WACM,UAAU;EAE3B,YAAY,UAAS,QAAQ;EAoB7B,YAAY,KAAK,qBAAqB,QAAQ;EAI9C,YACE,UAAU,mBACV,oBAAoB,oBAAoB,yBAAyB,yBAChE;EAIH,aACE,UAAU,sBACV,oBAAoB,oBAAoB,yBAAyB,yBAChE;EAIH,MAAM,kBAAkB"}
@@ -1 +1,2 @@
1
- export { DocumentStorage } from "./document-storage/index.js";
1
+ import { t as DocumentStorage } from "./document-storage-CwwTQ49-.js";
2
+ export { DocumentStorage };
@@ -1 +1,60 @@
1
- export { ImageFetch } from "./image-worker/fetch.js";
1
+ import { Deferred } from "@warp-drive/core/request";
2
+ //#region src/image-worker/types.d.ts
3
+ /** Sent by {@link ImageFetch} to request that an image url be loaded. */
4
+ type RequestEventData = {
5
+ type: "load";
6
+ thread: string;
7
+ url: string;
8
+ };
9
+ //#endregion
10
+ //#region src/image-worker/fetch.d.ts
11
+ /**
12
+ * Main-thread client for an {@link ImageWorker}. Sends image `load`
13
+ * requests to a `Worker` or `SharedWorker` running an `ImageWorker`.
14
+ *
15
+ * In FastBoot/SSR, or when constructed with a `null` worker, `ImageFetch`
16
+ * skips worker communication entirely: {@link ImageFetch.load} resolves
17
+ * immediately with the given url.
18
+ *
19
+ * A plain `Worker` is only accepted when running in a `TESTING` build;
20
+ * production usage requires a `SharedWorker`.
21
+ *
22
+ * @public
23
+ */
24
+ declare class ImageFetch {
25
+ worker: Worker | SharedWorker;
26
+ threadId: string;
27
+ pending: Map<string, Deferred<string>>;
28
+ channel: MessageChannel;
29
+ cache: Map<string, string>;
30
+ /**
31
+ * @param worker - the `Worker` or `SharedWorker` running an
32
+ * {@link ImageWorker}, or `null` to disable worker communication (e.g.
33
+ * in FastBoot/SSR).
34
+ */
35
+ constructor(worker: Worker | SharedWorker | null);
36
+ cleanupRequest(url: string): Deferred<string> | undefined;
37
+ _send(event: RequestEventData): void;
38
+ /**
39
+ * Requests that the given image url be loaded by the connected
40
+ * {@link ImageWorker}, resolving with an object url for the fetched
41
+ * image's blob once the worker responds (or immediately with the
42
+ * original `url`, in SSR/FastBoot or when this instance was constructed
43
+ * with a `null` worker).
44
+ *
45
+ * The resolved object url is cached in-memory by source url on this
46
+ * instance, so subsequent calls for the same url resolve immediately
47
+ * without another round-trip to the worker.
48
+ *
49
+ * Calling `load` again for a url that is already in-flight (not yet
50
+ * cached) on this instance replaces the pending request rather than
51
+ * joining it — only the most recently issued call for a given url will
52
+ * resolve.
53
+ *
54
+ * @public
55
+ */
56
+ load(url: string): Promise<string>;
57
+ }
58
+ //#endregion
59
+ export { ImageFetch };
60
+ //# sourceMappingURL=image-fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-fetch.d.ts","names":[],"sources":["../src/image-worker/types.ts","../src/image-worker/fetch.ts"],"mappings":";;;KA8BY;EACV;EACA;EACA;;;;;;;;;;;;;;;;;cCFW;EACX,QAAgB,SAAS;EACzB;EACA,SAAiB,YAAY;EAC7B,SAAiB;EACjB,OAAe;;;;;;EAOf,YAAY,QAAQ,SAAS;EA0C7B,eAAe,cAAc;EAO7B,MAAM,OAAO;;;;;;;;;;;;;;;;;;;EAuBb,KAAK,cAAc"}
@@ -1 +1,40 @@
1
- export { ImageWorker } from "./image-worker/worker.js";
1
+ //#region src/image-worker/worker.d.ts
2
+ /**
3
+ * Runs inside a `Worker` or `SharedWorker` to fetch images on behalf of
4
+ * one or more {@link ImageFetch} instances running on the main thread(s)
5
+ * that connect to it.
6
+ *
7
+ * Each connecting thread registers itself by sending a `connect` message
8
+ * along with a {@link MessagePort}. When a thread sends a `load` request
9
+ * for a url, the worker fetches the image via `fetch`, converts the
10
+ * response into a `Blob`, and creates an object url for it via
11
+ * `URL.createObjectURL`. The fetch for a given url is deduped and cached
12
+ * in-memory for the lifetime of the worker, so repeat `load` requests for
13
+ * the same url — whether from the same or a different connected thread —
14
+ * do not trigger another network request.
15
+ *
16
+ * Only intended for use inside a Worker context: constructing an
17
+ * `ImageWorker` on the main thread is a no-op.
18
+ *
19
+ * @public
20
+ */
21
+ declare class ImageWorker {
22
+ private threads;
23
+ private pendingImages;
24
+ private options;
25
+ private isSharedWorker;
26
+ private cache;
27
+ /**
28
+ * @param options.persisted - reserved for a future on-disk cache; currently unused.
29
+ */
30
+ constructor(options?: {
31
+ persisted: boolean;
32
+ });
33
+ private fetch;
34
+ private initialize;
35
+ private setupThread;
36
+ private request;
37
+ }
38
+ //#endregion
39
+ export { ImageWorker };
40
+ //# sourceMappingURL=image-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-worker.d.ts","names":[],"sources":["../src/image-worker/worker.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;cA+Ba;UACK;UACA;UACA;UACA;UACA;;;;EAKhB,YAAY;IAAY;;UAahB;UAsBA;UA4BA;UAiBM"}
@@ -1,7 +1,359 @@
1
- export * from "./storage/storage.js";
2
- export type * from "./storage/storage.js";
3
- export * from "./storage/storage-resource.js";
4
- export type * from "./storage/storage-resource.js";
5
- export * from "./storage/cache.js";
6
- export type * from "./storage/cache.js";
7
- export { initMeta as _initMeta, getParamCompanion as _getParamCompanion } from "./storage/-private/storage-infra.js";
1
+ //#region src/storage/cache.d.ts
2
+ declare const DEFAULT_CACHE_ID = "reactive-cache";
3
+ interface InternalCacheStorageEvent {
4
+ storageArea: string;
5
+ key: string | null;
6
+ oldValue: string | null;
7
+ newValue: string | null;
8
+ }
9
+ interface CacheStorageEvent {
10
+ storageArea: CacheStorage;
11
+ key: string | null;
12
+ oldValue: string | null;
13
+ newValue: string | null;
14
+ }
15
+ /**
16
+ * A reactive interface for json stored in the browser [Cache](https://developer.mozilla.org/en-US/docs/Web/API/Cache) API.
17
+ *
18
+ * This is a good option for larger data sets than can be efficiently stored in localStorage
19
+ * but should not be used as a permanent DB or storage solution.
20
+ */
21
+ declare class CacheStorage implements Storage {
22
+ #private;
23
+ _data: Map<string, string | null>;
24
+ _nextUpdate: number | null;
25
+ _bufferedEvents: InternalCacheStorageEvent[];
26
+ constructor(cacheId: string);
27
+ get length(): number;
28
+ clear(): void;
29
+ getItem(key: string): string | null;
30
+ key(index: number): string | null;
31
+ removeItem(key: string): void;
32
+ setItem(key: string, value: string): void;
33
+ /**
34
+ * Get the singleton CacheStorage instance.
35
+ *
36
+ */
37
+ static get(cacheId?: string): Promise<CacheStorage>;
38
+ static expectCache(cacheId?: string): CacheStorage;
39
+ /**
40
+ * Returns the IDs of all {@link CacheStorage} instances that have been
41
+ * opened in this context via {@link CacheStorage.get}.
42
+ */
43
+ static getAllCacheIds(): string[];
44
+ }
45
+ //#endregion
46
+ //#region src/storage/storage.d.ts
47
+ interface ReactiveStorageOptions {
48
+ /**
49
+ * If true, falls back to in-memory storage when the underlying
50
+ * storage is unavailable (e.g., private browsing mode).
51
+ */
52
+ fallbackToMemory?: boolean;
53
+ /**
54
+ * If true, updates signal state even when writes fail due to quota.
55
+ * The onQuotaExceeded callback will be invoked before retrying.
56
+ */
57
+ updateOnQuotaExceeded?: boolean;
58
+ /**
59
+ * Called when a write fails due to quota exceeded.
60
+ * Return true to retry the write after freeing space.
61
+ */
62
+ onQuotaExceeded?: (key: string, value: string) => boolean | Promise<boolean>;
63
+ }
64
+ /**
65
+ * Retrieves the singleton instance of the LocalStorage service.
66
+ *
67
+ * If the instance does not already exist, it is created.
68
+ */
69
+ declare function getLocalStorage(): ReactiveStorage;
70
+ declare function getSessionStorage(): ReactiveStorage;
71
+ declare function getCacheStorage(namespace?: string | null): ReactiveStorage;
72
+ /**
73
+ * Configure options for the localStorage singleton.
74
+ * Must be called before getLocalStorage() is first invoked.
75
+ */
76
+ declare function configureLocalStorage(options: ReactiveStorageOptions): void;
77
+ /**
78
+ * Configure options for the sessionStorage singleton.
79
+ * Must be called before getSessionStorage() is first invoked.
80
+ */
81
+ declare function configureSessionStorage(options: ReactiveStorageOptions): void;
82
+ type EffectStorageEvent = CacheStorageEvent | StorageEvent;
83
+ declare global {
84
+ interface WindowEventMap {
85
+ storage: CustomEvent<CacheStorageEvent> | StorageEvent;
86
+ }
87
+ }
88
+ /**
89
+ * A reactive wrapper around the Web Storage API (localStorage/sessionStorage)
90
+ * that provides signal-based access to storage items and length.
91
+ *
92
+ * Will automatically update when storage events occur in other tabs/windows.
93
+ */
94
+ declare class ReactiveStorage implements Storage {
95
+ private _storage;
96
+ private _options;
97
+ private _memoryOnly;
98
+ private _values;
99
+ private _signals;
100
+ private _length;
101
+ private _effects;
102
+ setEffect(key: string, fn: (value: EffectStorageEvent) => void): void;
103
+ constructor(storage: Storage, options?: ReactiveStorageOptions);
104
+ /**
105
+ * Reactive access to the number of keys in Storage
106
+ */
107
+ get length(): number;
108
+ /**
109
+ * Non-reactive way to peek the current value of a key in Storage
110
+ */
111
+ peekItem(key: string): string | null;
112
+ /**
113
+ * Reactive access to Storage contents
114
+ */
115
+ getItem(key: string): string | null;
116
+ /**
117
+ * Set a value in Storage, triggering reactivity
118
+ */
119
+ setItem(key: string, value: string): void;
120
+ /**
121
+ * Remove a value from Storage, triggering reactivity
122
+ */
123
+ removeItem(key: string): void;
124
+ /**
125
+ * Clears all keys from Storage, triggering reactivity
126
+ */
127
+ clear(): void;
128
+ /**
129
+ * Reactive access to the key at the given index
130
+ */
131
+ key(index: number): string | null;
132
+ }
133
+ //#endregion
134
+ //#region src/storage/-private/storage-infra.d.ts
135
+ /**
136
+ * Configuration options for fields that are also query parameters
137
+ */
138
+ interface ParamConfig {
139
+ /**
140
+ * Convert a value into a string for storage in the URL.
141
+ * `null` indicates the value should be omitted from the URL.
142
+ */
143
+ serialize: (value: unknown, instance: any) => string | null;
144
+ /**
145
+ * Convert a string value from the URL back into
146
+ * its original type
147
+ */
148
+ deserialize: (urlValue: string, instance: any) => unknown;
149
+ /**
150
+ * Get the default value for this param from the given instance.
151
+ *
152
+ * If not present, the value passed to the field initializer
153
+ * will be used as the default.
154
+ *
155
+ * This should return the value in the field's native type,
156
+ * not the serialized URL form.
157
+ */
158
+ getDefault?: (instance: any) => unknown;
159
+ }
160
+ interface InternalParamConfig extends ParamConfig {
161
+ initialized?: boolean;
162
+ }
163
+ interface ValueTransition<T = unknown> {
164
+ key: string;
165
+ from: T;
166
+ to: T;
167
+ }
168
+ /**
169
+ * Metadata attached to persisted resource classes
170
+ */
171
+ interface StorageResourceMeta {
172
+ id: string;
173
+ namespace: string | null;
174
+ pkFn: KeyFn | null;
175
+ type: "local-resource" | "session-resource" | "cache-resource";
176
+ typeOverrides: Map<string, "local-storage" | "session-storage" | "cache-storage"> | null;
177
+ fields: Map<string, null | ((update: ValueTransition<string>) => void)>;
178
+ initializers: Map<string, (() => unknown) | null>;
179
+ paramConfigs: Map<string, InternalParamConfig> | null;
180
+ paramCompanion: object | null;
181
+ instances: WeakMap<object, StorageResourceMeta> | null;
182
+ }
183
+ /**
184
+ * A function which generates a unique primary-key
185
+ * string for a given LocalResource or SessionResource
186
+ * instance.
187
+ *
188
+ * Use functions when you want to create more than
189
+ * one instance of a resource type, each with its own
190
+ * persisted data.
191
+ */
192
+ type KeyFn = (obj: any) => string;
193
+ /**
194
+ * Setup persisted resource metadata on target
195
+ * if not already present
196
+ *
197
+ * @private
198
+ */
199
+ declare function initMeta(target: object): StorageResourceMeta;
200
+ /**
201
+ * Get or create the param companion object for a StorageResource instance.
202
+ *
203
+ * The companion object contains URL-serialized versions of all @param decorated fields.
204
+ * Each param field gets a corresponding property on the companion that:
205
+ * - Reads: Serializes the storage value to a URL string (returns null if not active)
206
+ * - Writes: Deserializes the URL string and updates the storage value
207
+ *
208
+ * The companion object is reactive using trackedObject, ensuring that changes
209
+ * to the underlying storage fields trigger updates in the query param system.
210
+ *
211
+ * This companion object is what QPRoute will bind to for URL query params.
212
+ *
213
+ * @private
214
+ * @param instance - The StorageResource instance
215
+ * @param groupControlMap - Optional map of fieldName -> controlFieldName for grouped params
216
+ * @returns The companion object with serialized param properties
217
+ */
218
+ declare function getParamCompanion(instance: object, groupControlMap?: Record<string, string>): object;
219
+ //#endregion
220
+ //#region src/storage/storage-resource.d.ts
221
+ /**
222
+ * Decorator which transforms a class into a StorageResource
223
+ * persisted in localStorage.
224
+ *
225
+ * LocalResources must either be singletons or expect all instances
226
+ * to share state unless a primary key function is provided.
227
+ *
228
+ * When a primary key function is provided, each instance
229
+ * will have its own persisted data based on the key generated
230
+ * by the function.
231
+ *
232
+ * The function will be called once per instance during
233
+ * initialization to determine the unique ID for that instance.
234
+ */
235
+ declare function LocalResource(id: string | KeyFn): ClassDecorator;
236
+ /**
237
+ * Decorator which transforms a class into a StorageResource
238
+ * persisted in sessionStorage.
239
+ *
240
+ * SessionResources must either be singletons or expect all instances
241
+ * to share state unless a primary key function is provided.
242
+ *
243
+ * When a primary key function is provided, each instance
244
+ * will have its own persisted data based on the key generated
245
+ * by the function.
246
+ *
247
+ * The function will be called once per instance during
248
+ * initialization to determine the unique ID for that instance.
249
+ */
250
+ declare function SessionResource(id: string | KeyFn): ClassDecorator;
251
+ /**
252
+ * Decorator which transforms a class into a StorageResource
253
+ * persisted via the [Cache API](https://developer.mozilla.org/en-US/docs/Web/API/Cache).
254
+ * api and shared across all tabs/windows under the same origin.
255
+ *
256
+ * CacheResources must either be singletons or expect all instances
257
+ * to share state unless a primary key function is provided.
258
+ *
259
+ * When a primary key function is provided, each instance
260
+ * will have its own persisted data based on the key generated
261
+ * by the function.
262
+ *
263
+ * The function will be called once per instance during
264
+ * initialization to determine the unique ID for that instance.
265
+ *
266
+ * All object cached in the same `namespace` share the namespace's storage context,
267
+ * so partitioning can be achieved by using different namespaces for different groups
268
+ * of data.
269
+ */
270
+ declare function CacheResource(id: string | KeyFn, namespace?: string | null): ClassDecorator;
271
+ /**
272
+ * Decorator which marks a property as a field on
273
+ * a LocalResource or SessionResource
274
+ *
275
+ * The field's value will be initialized from the persisted resource data
276
+ * if available, falling back to the property's default value otherwise.
277
+ *
278
+ * Fields can be of any type that is serializable to and restorable from JSON,
279
+ * but complex types (like objects or arrays) should be handled with care to avoid
280
+ * unintended mutations or reactivity issues.
281
+ *
282
+ * By default, fields are persisted in the storage type defined by the resource decorator
283
+ * (@LocalResource or @SessionResource). However, you can override this behavior
284
+ * by passing 'local' or 'session' as an argument to the decorator.
285
+ *
286
+ * ---
287
+ *
288
+ * **Example:**
289
+ *
290
+ * ```ts
291
+ * @LocalResource('user-settings')
292
+ * class UserSettings {
293
+ * @field
294
+ * theme: 'light' | 'dark' = 'light';
295
+ *
296
+ * @field('session')
297
+ * sessionToken: string | null = null;
298
+ * }
299
+ * ```
300
+ *
301
+ */
302
+ declare function field(type: "local" | "session" | "cache"): PropertyDecorator;
303
+ declare function field(target: object, key: string, descriptor?: PropertyDescriptor): void;
304
+ declare function input(type: "number" | "boolean" | "float"): PropertyDecorator;
305
+ /**
306
+ * Effects are fields that run a side-effecting function.
307
+ *
308
+ * Effects are intended to enable synchronizing get states between
309
+ * tabs or windows that result in needing to synchronize other
310
+ * non-reactive state.
311
+ *
312
+ * For example, when a user selects a light/dark mode theme preference
313
+ * that differs from the system preference, effects can be used to trigger
314
+ * DOM updates on the documentElement necessary to ensure its state is
315
+ * consistent with the persisted resource state and reactive application state.
316
+ *
317
+ * To do this without an effect would require either setting up your own
318
+ * storage event listeners or consuming the reactive state of the property
319
+ * in another effect-like API such as an Ember modifier or React useEffect,
320
+ *
321
+ * Effects *only* run when the stored value changes due to storage events
322
+ * emitted from other tabs or windows. They do not run when the property
323
+ * is updated in the same context.
324
+ *
325
+ * ---
326
+ *
327
+ * **Example:**
328
+ *
329
+ * ```ts
330
+ * @LocalResource('user-preferences')
331
+ * class UserPreferences {
332
+ * @effect(syncThemeToDOM)
333
+ * explicitThemePreference: 'light' | 'dark' | null = null;
334
+ *
335
+ * @matchMedia('(prefers-color-scheme: dark)')
336
+ * systemPrefersDarkMode: boolean = false;
337
+ * }
338
+ *
339
+ * function syncThemeToDOM(update: ValueTransition<'light' | 'dark' | null>): void {
340
+ * const newTheme = update.to;
341
+ * document.documentElement.style.colorScheme = newTheme ?? 'light dark';
342
+ *
343
+ * if (newTheme === 'dark') {
344
+ * document.documentElement.classList.add('dark-theme');
345
+ * document.documentElement.classList.remove('light-theme');
346
+ * } else if (newTheme === 'light') {
347
+ * document.documentElement.classList.add('light-theme');
348
+ * document.documentElement.classList.remove('dark-theme');
349
+ * } else {
350
+ * document.documentElement.classList.remove('light-theme');
351
+ * document.documentElement.classList.remove('dark-theme');
352
+ * }
353
+ * }
354
+ * ```
355
+ */
356
+ declare function effect(fn: <K>(update: ValueTransition<K>) => void, type?: "local" | "session"): PropertyDecorator;
357
+ //#endregion
358
+ export { CacheResource, CacheStorage, CacheStorageEvent, DEFAULT_CACHE_ID, EffectStorageEvent, InternalCacheStorageEvent, LocalResource, type ReactiveStorage, ReactiveStorageOptions, SessionResource, getParamCompanion as _getParamCompanion, initMeta as _initMeta, configureLocalStorage, configureSessionStorage, effect, field, getCacheStorage, getLocalStorage, getSessionStorage, input };
359
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","names":[],"sources":["../src/storage/cache.ts","../src/storage/storage.ts","../src/storage/-private/storage-infra.ts","../src/storage/storage-resource.ts"],"mappings":";cAEa;UAKI;EACf;EACA;EACA;EACA;;UAEe;EACf,aAAa;EACb;EACA;EACA;;;;;;;;cAkEW,wBAAwB;;EAInC,OAAO;EACP;EACA,iBAAiB;EAYjB,YAAY;MAMR;EA4BJ;EAKA,QAAQ;EAIR,IAAI;EAgBJ,WAAW;EAQX,QAAQ,aAAa;;;;;SAed,IAAI,mBAAqC,QAAQ;SASjD,YAAY,mBAAqC;;;;;SAYjD;;;;UCtMQ;;;;;EAKf;;;;;EAMA;;;;;EAMA,mBAAmB,aAAa,4BAA4B;;;;;;;iBAgB9C,mBAAmB;iBAOnB,qBAAqB;iBAQrB,gBAAgB,4BAAkC;;;;;iBAelD,sBAAsB,SAAS;;;;;iBAQ/B,wBAAwB,SAAS;KA8BrC,qBAAqB,oBAAoB;QAEtC;YACH;IACR,SAAS,YAAY,qBAAqB;;;;;;;;;cAUxC,2BAA2B;UACvB;UACA;UACA;UACA;UAEQ;UACA;UAER;EACR,UAAU,aAAa,KAAK,OAAO;EAKnC,YAAY,SAAS,SAAS,UAAS;;;;MA2CnC;;;;EAOJ,SAAS;;;;EAsBT,QAAQ;;;;EAyBR,QAAQ,aAAa;;;;EA2DrB,WAAW;;;;EAsBX;;;;EAeA,IAAI;;;;;;;UCjUW;;;;;EAMf,YAAY,gBAAgB;;;;;EAM5B,cAAc,kBAAkB;;;;;;;;;;EAWhC,cAAc;;UAGN,4BAA4B;EACpC;;UAGe,gBAAgB;EAC/B;EACA,MAAM;EACN,IAAI;;;;;UAMW;EACf;EACA;EACA,MAAM;EACN;EACA,eAAe;EACf,QAAQ,qBAAqB,QAAQ;EACrC,cAAc;EACd,cAAc,YAAY;EAC1B;EACA,WAAW,gBAAgB;;;;;;;;;;;KAajB,SAAS;;;;;;;iBAaL,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;iBAiT1B,kBAAkB,kBAAkB,kBAAkB;;;;;;;;;;;;;;;;;iBCxWtD,cAAc,aAAa,QAAQ;;;;;;;;;;;;;;;iBAkBnC,gBAAgB,aAAa,QAAQ;;;;;;;;;;;;;;;;;;;;iBAuBrC,cAAc,aAAa,OAAO,4BAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmCpE,MAAM,sCAAsC;iBAC5C,MAAM,gBAAgB,aAAa,aAAa;iBAgBhD,MAAM,uCAAuC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoF7C,OAAO,KAAK,GAAG,QAAQ,gBAAgB,aAAa,6BAA6B"}
@@ -0,0 +1,17 @@
1
+ import { RequestInfo } from "@warp-drive/core/types/request";
2
+ //#region src/data-worker/types.d.ts
3
+ type RequestEventData = {
4
+ type: "request";
5
+ thread: string;
6
+ id: number;
7
+ data: RequestInfo;
8
+ };
9
+ type AbortEventData = {
10
+ type: "abort";
11
+ thread: string;
12
+ id: number;
13
+ data: string;
14
+ };
15
+ //#endregion
16
+ export { RequestEventData as n, AbortEventData as t };
17
+ //# sourceMappingURL=types-CRs-Qww6.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-CRs-Qww6.d.ts","names":[],"sources":["../src/data-worker/types.ts"],"mappings":";;KAeY;EACV;EACA;EACA;EACA,MAAM;;KAGI;EACV;EACA;EACA;EACA"}