@iamjulianacosta/mobx-data 1.0.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/LICENSE +21 -0
- package/README.md +366 -0
- package/dist/CacheHandler-BTU_rYkv.js +208 -0
- package/dist/CacheHandler-BTU_rYkv.js.map +1 -0
- package/dist/CacheHandler-CXgY9IJo.cjs +2 -0
- package/dist/CacheHandler-CXgY9IJo.cjs.map +1 -0
- package/dist/EmbeddedRecordsMixin-CBvqNdgC.cjs +2 -0
- package/dist/EmbeddedRecordsMixin-CBvqNdgC.cjs.map +1 -0
- package/dist/EmbeddedRecordsMixin-VoHluHCT.js +261 -0
- package/dist/EmbeddedRecordsMixin-VoHluHCT.js.map +1 -0
- package/dist/JsonApiSerializer-CC5HXp4b.js +194 -0
- package/dist/JsonApiSerializer-CC5HXp4b.js.map +1 -0
- package/dist/JsonApiSerializer-CKB02AgP.cjs +2 -0
- package/dist/JsonApiSerializer-CKB02AgP.cjs.map +1 -0
- package/dist/MemoryAdapter-Bx1e7ndV.js +123 -0
- package/dist/MemoryAdapter-Bx1e7ndV.js.map +1 -0
- package/dist/MemoryAdapter-D1cTyydm.cjs +2 -0
- package/dist/MemoryAdapter-D1cTyydm.cjs.map +1 -0
- package/dist/ODataAdapter-C4IHK4BK.js +157 -0
- package/dist/ODataAdapter-C4IHK4BK.js.map +1 -0
- package/dist/ODataAdapter-DyyF1sdA.cjs +2 -0
- package/dist/ODataAdapter-DyyF1sdA.cjs.map +1 -0
- package/dist/RestAdapter-B4aRvs4m.js +355 -0
- package/dist/RestAdapter-B4aRvs4m.js.map +1 -0
- package/dist/RestAdapter-CJOwTsKK.cjs +2 -0
- package/dist/RestAdapter-CJOwTsKK.cjs.map +1 -0
- package/dist/SchemaService-DZwkFgZu.js +102 -0
- package/dist/SchemaService-DZwkFgZu.js.map +1 -0
- package/dist/SchemaService-Di_yjVzU.cjs +2 -0
- package/dist/SchemaService-Di_yjVzU.cjs.map +1 -0
- package/dist/Serializer-95gi5edy.cjs +2 -0
- package/dist/Serializer-95gi5edy.cjs.map +1 -0
- package/dist/Serializer-FxJbsZ50.js +139 -0
- package/dist/Serializer-FxJbsZ50.js.map +1 -0
- package/dist/Store-BdwMrbDi.cjs +2 -0
- package/dist/Store-BdwMrbDi.cjs.map +1 -0
- package/dist/Store-CZ7Z-Nme.js +912 -0
- package/dist/Store-CZ7Z-Nme.js.map +1 -0
- package/dist/adapter/Adapter.d.ts +146 -0
- package/dist/adapter/Adapter.d.ts.map +1 -0
- package/dist/adapter/MemoryAdapter.d.ts +44 -0
- package/dist/adapter/MemoryAdapter.d.ts.map +1 -0
- package/dist/adapter/RestAdapter.d.ts +57 -0
- package/dist/adapter/RestAdapter.d.ts.map +1 -0
- package/dist/adapter/index.cjs +2 -0
- package/dist/adapter/index.cjs.map +1 -0
- package/dist/adapter/index.d.ts +4 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/index.js +8 -0
- package/dist/adapter/index.js.map +1 -0
- package/dist/date-Bj4O2W1F.js +107 -0
- package/dist/date-Bj4O2W1F.js.map +1 -0
- package/dist/date-CRCe-9gf.cjs +2 -0
- package/dist/date-CRCe-9gf.cjs.map +1 -0
- package/dist/decorators-HQ1KnRdh.cjs +2 -0
- package/dist/decorators-HQ1KnRdh.cjs.map +1 -0
- package/dist/decorators-Zr35qr6A.js +50 -0
- package/dist/decorators-Zr35qr6A.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/json-api/JsonApiAdapter.d.ts +38 -0
- package/dist/json-api/JsonApiAdapter.d.ts.map +1 -0
- package/dist/json-api/JsonApiSerializer.d.ts +73 -0
- package/dist/json-api/JsonApiSerializer.d.ts.map +1 -0
- package/dist/json-api/index.cjs +2 -0
- package/dist/json-api/index.cjs.map +1 -0
- package/dist/json-api/index.d.ts +3 -0
- package/dist/json-api/index.d.ts.map +1 -0
- package/dist/json-api/index.js +6 -0
- package/dist/json-api/index.js.map +1 -0
- package/dist/model/Errors.d.ts +46 -0
- package/dist/model/Errors.d.ts.map +1 -0
- package/dist/model/Model.d.ts +226 -0
- package/dist/model/Model.d.ts.map +1 -0
- package/dist/model/Snapshot.d.ts +72 -0
- package/dist/model/Snapshot.d.ts.map +1 -0
- package/dist/model/StateMachine.d.ts +45 -0
- package/dist/model/StateMachine.d.ts.map +1 -0
- package/dist/model/index.cjs +2 -0
- package/dist/model/index.cjs.map +1 -0
- package/dist/model/index.d.ts +6 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +11 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/relationships.d.ts +182 -0
- package/dist/model/relationships.d.ts.map +1 -0
- package/dist/odata/ODataAdapter.d.ts +67 -0
- package/dist/odata/ODataAdapter.d.ts.map +1 -0
- package/dist/odata/index.cjs +2 -0
- package/dist/odata/index.cjs.map +1 -0
- package/dist/odata/index.d.ts +2 -0
- package/dist/odata/index.d.ts.map +1 -0
- package/dist/odata/index.js +5 -0
- package/dist/odata/index.js.map +1 -0
- package/dist/relationships-B55LBaCW.cjs +2 -0
- package/dist/relationships-B55LBaCW.cjs.map +1 -0
- package/dist/relationships-BEXANmWg.js +821 -0
- package/dist/relationships-BEXANmWg.js.map +1 -0
- package/dist/request/CacheHandler.d.ts +50 -0
- package/dist/request/CacheHandler.d.ts.map +1 -0
- package/dist/request/FetchHandler.d.ts +41 -0
- package/dist/request/FetchHandler.d.ts.map +1 -0
- package/dist/request/RequestManager.d.ts +52 -0
- package/dist/request/RequestManager.d.ts.map +1 -0
- package/dist/request/index.cjs +2 -0
- package/dist/request/index.cjs.map +1 -0
- package/dist/request/index.d.ts +5 -0
- package/dist/request/index.d.ts.map +1 -0
- package/dist/request/index.js +7 -0
- package/dist/request/index.js.map +1 -0
- package/dist/request/types.d.ts +111 -0
- package/dist/request/types.d.ts.map +1 -0
- package/dist/schema/SchemaService.d.ts +58 -0
- package/dist/schema/SchemaService.d.ts.map +1 -0
- package/dist/schema/decorators.d.ts +50 -0
- package/dist/schema/decorators.d.ts.map +1 -0
- package/dist/schema/index.cjs +2 -0
- package/dist/schema/index.cjs.map +1 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +13 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/types.d.ts +61 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/serializer/EmbeddedRecordsMixin.d.ts +80 -0
- package/dist/serializer/EmbeddedRecordsMixin.d.ts.map +1 -0
- package/dist/serializer/JsonSerializer.d.ts +52 -0
- package/dist/serializer/JsonSerializer.d.ts.map +1 -0
- package/dist/serializer/RestSerializer.d.ts +43 -0
- package/dist/serializer/RestSerializer.d.ts.map +1 -0
- package/dist/serializer/Serializer.d.ts +202 -0
- package/dist/serializer/Serializer.d.ts.map +1 -0
- package/dist/serializer/index.cjs +2 -0
- package/dist/serializer/index.cjs.map +1 -0
- package/dist/serializer/index.d.ts +5 -0
- package/dist/serializer/index.d.ts.map +1 -0
- package/dist/serializer/index.js +9 -0
- package/dist/serializer/index.js.map +1 -0
- package/dist/store/IdentityMap.d.ts +53 -0
- package/dist/store/IdentityMap.d.ts.map +1 -0
- package/dist/store/RecordArray.d.ts +114 -0
- package/dist/store/RecordArray.d.ts.map +1 -0
- package/dist/store/Store.d.ts +395 -0
- package/dist/store/Store.d.ts.map +1 -0
- package/dist/store/index.cjs +2 -0
- package/dist/store/index.cjs.map +1 -0
- package/dist/store/index.d.ts +5 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +8 -0
- package/dist/store/index.js.map +1 -0
- package/dist/transforms/Transform.d.ts +49 -0
- package/dist/transforms/Transform.d.ts.map +1 -0
- package/dist/transforms/boolean.d.ts +26 -0
- package/dist/transforms/boolean.d.ts.map +1 -0
- package/dist/transforms/date.d.ts +22 -0
- package/dist/transforms/date.d.ts.map +1 -0
- package/dist/transforms/index.cjs +2 -0
- package/dist/transforms/index.cjs.map +1 -0
- package/dist/transforms/index.d.ts +6 -0
- package/dist/transforms/index.d.ts.map +1 -0
- package/dist/transforms/index.js +9 -0
- package/dist/transforms/index.js.map +1 -0
- package/dist/transforms/number.d.ts +17 -0
- package/dist/transforms/number.d.ts.map +1 -0
- package/dist/transforms/string.d.ts +18 -0
- package/dist/transforms/string.d.ts.map +1 -0
- package/dist/types-C9NB2gRj.js +7 -0
- package/dist/types-C9NB2gRj.js.map +1 -0
- package/dist/types-uWOXMPWW.cjs +2 -0
- package/dist/types-uWOXMPWW.cjs.map +1 -0
- package/package.json +140 -0
- package/src/adapter/Adapter.ts +320 -0
- package/src/adapter/MemoryAdapter.ts +216 -0
- package/src/adapter/RestAdapter.ts +248 -0
- package/src/adapter/index.ts +7 -0
- package/src/index.ts +17 -0
- package/src/json-api/JsonApiAdapter.ts +93 -0
- package/src/json-api/JsonApiSerializer.ts +245 -0
- package/src/json-api/index.ts +2 -0
- package/src/model/Errors.ts +100 -0
- package/src/model/Model.ts +683 -0
- package/src/model/Snapshot.ts +162 -0
- package/src/model/StateMachine.ts +149 -0
- package/src/model/index.ts +20 -0
- package/src/model/relationships.ts +484 -0
- package/src/odata/ODataAdapter.ts +245 -0
- package/src/odata/index.ts +1 -0
- package/src/request/CacheHandler.ts +125 -0
- package/src/request/FetchHandler.ts +119 -0
- package/src/request/RequestManager.ts +112 -0
- package/src/request/index.ts +4 -0
- package/src/request/types.ts +139 -0
- package/src/schema/SchemaService.ts +161 -0
- package/src/schema/decorators.ts +162 -0
- package/src/schema/index.ts +3 -0
- package/src/schema/types.ts +66 -0
- package/src/serializer/EmbeddedRecordsMixin.ts +257 -0
- package/src/serializer/JsonSerializer.ts +173 -0
- package/src/serializer/RestSerializer.ts +138 -0
- package/src/serializer/Serializer.ts +397 -0
- package/src/serializer/index.ts +15 -0
- package/src/store/IdentityMap.ts +110 -0
- package/src/store/RecordArray.ts +210 -0
- package/src/store/Store.ts +1391 -0
- package/src/store/index.ts +11 -0
- package/src/transforms/Transform.ts +52 -0
- package/src/transforms/boolean.ts +57 -0
- package/src/transforms/date.ts +48 -0
- package/src/transforms/index.ts +5 -0
- package/src/transforms/number.ts +42 -0
- package/src/transforms/string.ts +35 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observable array proxies for store query results.
|
|
3
|
+
*
|
|
4
|
+
* Two classes are provided:
|
|
5
|
+
*
|
|
6
|
+
* ## `RecordArray<T>`
|
|
7
|
+
* A live, read-only view of all records of a given type in the store's
|
|
8
|
+
* identity map. The contents are derived via an injected `source` function
|
|
9
|
+
* so they stay in sync automatically with the identity map.
|
|
10
|
+
*
|
|
11
|
+
* Supports `update()` to trigger a background re-fetch if an `update` callback
|
|
12
|
+
* is provided.
|
|
13
|
+
*
|
|
14
|
+
* ## `AdapterPopulatedRecordArray<T>`
|
|
15
|
+
* A subclass used for the results of `store.query()`. Unlike `RecordArray`,
|
|
16
|
+
* its contents are determined by the last adapter response (order preserved,
|
|
17
|
+
* no auto-sync with new pushes).
|
|
18
|
+
*
|
|
19
|
+
* Adds `meta`, `links`, and `query` properties that are set by the store after
|
|
20
|
+
* each adapter call.
|
|
21
|
+
*/
|
|
22
|
+
import type { Model } from '@mobx-data/model';
|
|
23
|
+
/** Constructor options for `RecordArray`. */
|
|
24
|
+
export interface RecordArrayOptions<T extends Model> {
|
|
25
|
+
/** Registered model name. */
|
|
26
|
+
modelName: string;
|
|
27
|
+
/** Function that returns the current record list (called on each access). */
|
|
28
|
+
source: () => T[];
|
|
29
|
+
/** Optional async callback invoked by `update()`. */
|
|
30
|
+
update?: () => Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* When `true`, the internal MobX computed retains its cached value even when
|
|
33
|
+
* no observers are actively subscribed. Prevents expensive recomputation
|
|
34
|
+
* for long-lived filtered views (e.g. `liveQuery` results).
|
|
35
|
+
*/
|
|
36
|
+
keepAlive?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Live, read-only view of all records of a given type.
|
|
40
|
+
*
|
|
41
|
+
* The `source` function is called on each observable access so the array
|
|
42
|
+
* always reflects the current store state. MobX tracks the `source` call
|
|
43
|
+
* as part of `resolved`, so any computed prop that reads from this array
|
|
44
|
+
* will re-run when the underlying identity map changes.
|
|
45
|
+
*/
|
|
46
|
+
export declare class RecordArray<T extends Model = Model> implements Iterable<T> {
|
|
47
|
+
private readonly opts;
|
|
48
|
+
/** `true` while `update()` is in progress. */
|
|
49
|
+
protected updating: boolean;
|
|
50
|
+
constructor(opts: RecordArrayOptions<T>);
|
|
51
|
+
/** Current record list, derived from the injected `source` function. */
|
|
52
|
+
protected get resolved(): T[];
|
|
53
|
+
/** `true` while a background `update()` call is in progress. */
|
|
54
|
+
get isLoading(): boolean;
|
|
55
|
+
/** Alias for `isLoading`. */
|
|
56
|
+
get isUpdating(): boolean;
|
|
57
|
+
/** Number of records in the array. */
|
|
58
|
+
get length(): number;
|
|
59
|
+
/** The registered model name for the records in this array. */
|
|
60
|
+
get modelName(): string;
|
|
61
|
+
/** Returns the record at `index`, or `undefined`. */
|
|
62
|
+
at(index: number): T | undefined;
|
|
63
|
+
/** Returns a plain array snapshot of all records. */
|
|
64
|
+
toArray(): T[];
|
|
65
|
+
/** Maps over records. */
|
|
66
|
+
map<R>(callback: (record: T, i: number) => R): R[];
|
|
67
|
+
/** Filters records. */
|
|
68
|
+
filter(predicate: (record: T, i: number) => boolean): T[];
|
|
69
|
+
/** Iterates records. */
|
|
70
|
+
forEach(callback: (record: T, i: number) => void): void;
|
|
71
|
+
/** Returns `true` when `record` is in the array. */
|
|
72
|
+
includes(record: T): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Triggers the `update` callback (if any) to refresh the array from the
|
|
75
|
+
* adapter. Sets `isLoading` while the request is in flight.
|
|
76
|
+
*/
|
|
77
|
+
update(): Promise<this>;
|
|
78
|
+
[Symbol.iterator](): Iterator<T>;
|
|
79
|
+
}
|
|
80
|
+
/** Constructor options for `AdapterPopulatedRecordArray`. */
|
|
81
|
+
export interface AdapterPopulatedRecordArrayOptions<T extends Model> extends RecordArrayOptions<T> {
|
|
82
|
+
/** Query parameters that produced this result set. */
|
|
83
|
+
query: Record<string, unknown>;
|
|
84
|
+
/** Server-side metadata (pagination, total counts, etc.). */
|
|
85
|
+
meta?: Record<string, unknown>;
|
|
86
|
+
/** Pagination or related links. */
|
|
87
|
+
links?: Record<string, string>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Record array populated by an adapter query response.
|
|
91
|
+
*
|
|
92
|
+
* The store creates one of these for each `store.query()` call. Its contents
|
|
93
|
+
* are driven by the id list returned from the last adapter call, not by live
|
|
94
|
+
* identity map iteration.
|
|
95
|
+
*
|
|
96
|
+
* Call `.update()` to re-issue the original query and refresh the contents.
|
|
97
|
+
*/
|
|
98
|
+
export declare class AdapterPopulatedRecordArray<T extends Model = Model> extends RecordArray<T> {
|
|
99
|
+
private queryParams;
|
|
100
|
+
private metaData;
|
|
101
|
+
private linksData;
|
|
102
|
+
constructor(opts: AdapterPopulatedRecordArrayOptions<T>);
|
|
103
|
+
/** Server-side metadata attached to the last response (e.g. pagination). */
|
|
104
|
+
get meta(): Record<string, unknown>;
|
|
105
|
+
/** Links attached to the last response. */
|
|
106
|
+
get links(): Record<string, string>;
|
|
107
|
+
/** The query parameters that produced this array. */
|
|
108
|
+
get query(): Record<string, unknown>;
|
|
109
|
+
/** Called by the store to update `meta` after a successful query. */
|
|
110
|
+
_setMeta(meta: Record<string, unknown>): void;
|
|
111
|
+
/** Called by the store to update `links` after a successful query. */
|
|
112
|
+
_setLinks(links: Record<string, string>): void;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=RecordArray.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RecordArray.d.ts","sourceRoot":"","sources":["../../src/store/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AC,MAAM,EAAE,OAAO,CAAC,CAEnC;IAED,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI7C,sEAAsE;IACtE,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;CAG/C"}
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central store — the top-level coordinator for the mobx-data runtime.
|
|
3
|
+
*
|
|
4
|
+
* `Store` orchestrates every aspect of the data layer:
|
|
5
|
+
*
|
|
6
|
+
* - **Identity Map** — a two-level `IdentityMap` keyed by `modelName → id`.
|
|
7
|
+
* Records are merged in-place on repeated `push` calls so live references
|
|
8
|
+
* always reflect the latest server state.
|
|
9
|
+
*
|
|
10
|
+
* - **Finding records** — `findRecord`, `findAll`, `query`, `queryRecord`
|
|
11
|
+
* delegate to the registered adapter, then pass the raw response through the
|
|
12
|
+
* registered serializer before pushing normalized data into the identity map.
|
|
13
|
+
*
|
|
14
|
+
* - **Saving records** — `saveRecord` calls `adapter.createRecord` or
|
|
15
|
+
* `adapter.updateRecord` depending on `record.isNew`, then applies the
|
|
16
|
+
* server response back onto the record via `_applyServerData`.
|
|
17
|
+
*
|
|
18
|
+
* - **Relationships** — `resolveRelationship` returns sync (`ManyArray`) or
|
|
19
|
+
* async (`AsyncBelongsTo` / `AsyncHasMany`) proxy objects backed by the
|
|
20
|
+
* store. `setRelationshipValue` updates `belongsTo` refs and keeps their
|
|
21
|
+
* inverses in sync. `_hasManyAppend` / `_hasManyRemove` manage `hasMany`
|
|
22
|
+
* refs and their inverses.
|
|
23
|
+
*
|
|
24
|
+
* - **Inverse tracking** — `addInverse` / `removeInverse` keep both sides of
|
|
25
|
+
* a declared `inverse` relationship consistent when either side is mutated.
|
|
26
|
+
*
|
|
27
|
+
* ## Registration
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* store.registerAdapter('application', new RestAdapter());
|
|
31
|
+
* store.registerSerializer('application', new JsonSerializer());
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Adapters and serializers are looked up first by exact model name, then by
|
|
35
|
+
* the special `'application'` fallback.
|
|
36
|
+
*/
|
|
37
|
+
import { SchemaService, type RelationshipDef, type AttributeDef } from '@mobx-data/schema';
|
|
38
|
+
import { Model, type RelationshipRef, type ModelStoreLike, type SaveOptions } from '@mobx-data/model';
|
|
39
|
+
import { IdentityMap } from './IdentityMap.js';
|
|
40
|
+
import { RecordArray, AdapterPopulatedRecordArray } from './RecordArray.js';
|
|
41
|
+
/** Options forwarded from the Store to adapter fetch methods. */
|
|
42
|
+
export interface AdapterFetchOptions {
|
|
43
|
+
include?: string;
|
|
44
|
+
adapterOptions?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/** Minimal adapter interface the Store depends on. */
|
|
47
|
+
export interface AdapterLike {
|
|
48
|
+
findRecord(store: Store, modelName: string, id: string, snapshot: unknown, options?: AdapterFetchOptions): Promise<unknown>;
|
|
49
|
+
findAll(store: Store, modelName: string, sinceToken: string | null, snapshotArray: unknown, options?: AdapterFetchOptions): Promise<unknown>;
|
|
50
|
+
findMany?(store: Store, modelName: string, ids: string[], snapshots: unknown): Promise<unknown>;
|
|
51
|
+
query(store: Store, modelName: string, query: Record<string, unknown>, recordArray: AdapterPopulatedRecordArray): Promise<unknown>;
|
|
52
|
+
queryRecord(store: Store, modelName: string, query: Record<string, unknown>): Promise<unknown>;
|
|
53
|
+
createRecord(store: Store, modelName: string, snapshot: unknown): Promise<unknown>;
|
|
54
|
+
updateRecord(store: Store, modelName: string, snapshot: unknown): Promise<unknown>;
|
|
55
|
+
patchRecord?(store: Store, modelName: string, snapshot: unknown): Promise<unknown>;
|
|
56
|
+
deleteRecord(store: Store, modelName: string, snapshot: unknown): Promise<unknown>;
|
|
57
|
+
/** When `true` the store coalesces multiple `findRecord` calls into one `findMany`. */
|
|
58
|
+
coalesceFindRequests?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/** Minimal serializer interface the Store depends on. */
|
|
61
|
+
export interface SerializerLike {
|
|
62
|
+
normalize(store: Store, modelClass: unknown, payload: unknown, prop?: string): unknown;
|
|
63
|
+
normalizeResponse(store: Store, modelClass: unknown, payload: unknown, id: string | null, requestType: string): unknown;
|
|
64
|
+
serialize(snapshot: unknown, options?: Record<string, unknown>): unknown;
|
|
65
|
+
extractErrors?(store: Store, modelClass: unknown, payload: unknown, id: string | null): Record<string, string[]>;
|
|
66
|
+
}
|
|
67
|
+
/** Options for `findRecord` and `findAll`. */
|
|
68
|
+
export interface FindOptions {
|
|
69
|
+
/** When `true`, bypass the cache and always hit the network. */
|
|
70
|
+
reload?: boolean;
|
|
71
|
+
/** When `true`, return the cached value and refetch in the background. */
|
|
72
|
+
backgroundReload?: boolean;
|
|
73
|
+
/** Adapter-specific options forwarded to the adapter method. */
|
|
74
|
+
adapterOptions?: Record<string, unknown>;
|
|
75
|
+
/** Comma-separated relationship paths to include (e.g. `'author,comments'`). */
|
|
76
|
+
include?: string;
|
|
77
|
+
}
|
|
78
|
+
/** Normalized resource shape consumed internally by the store. */
|
|
79
|
+
export interface NormalizedResource {
|
|
80
|
+
type: string;
|
|
81
|
+
id: string | null;
|
|
82
|
+
attributes?: Record<string, unknown>;
|
|
83
|
+
relationships?: Record<string, RelationshipRef>;
|
|
84
|
+
}
|
|
85
|
+
/** Normalized document containing primary data and optional side-loaded records. */
|
|
86
|
+
export interface NormalizedDocument {
|
|
87
|
+
data: NormalizedResource | NormalizedResource[] | null;
|
|
88
|
+
included?: NormalizedResource[];
|
|
89
|
+
meta?: Record<string, unknown>;
|
|
90
|
+
links?: Record<string, string>;
|
|
91
|
+
}
|
|
92
|
+
/** Internal snapshot interface created and consumed by the store. */
|
|
93
|
+
interface Snapshot {
|
|
94
|
+
id: string | null;
|
|
95
|
+
modelName: string;
|
|
96
|
+
record: Model;
|
|
97
|
+
attr(key: string): unknown;
|
|
98
|
+
belongsTo(key: string, options?: {
|
|
99
|
+
id?: boolean;
|
|
100
|
+
}): unknown;
|
|
101
|
+
hasMany(key: string, options?: {
|
|
102
|
+
ids?: boolean;
|
|
103
|
+
}): unknown;
|
|
104
|
+
changedAttributes(): Record<string, [unknown, unknown]>;
|
|
105
|
+
eachAttribute(fn: (key: string, meta: AttributeDef) => void): void;
|
|
106
|
+
eachRelationship(fn: (key: string, meta: RelationshipDef) => void): void;
|
|
107
|
+
}
|
|
108
|
+
export declare class Store implements ModelStoreLike {
|
|
109
|
+
static refEquals(a: {
|
|
110
|
+
type: string;
|
|
111
|
+
id: string;
|
|
112
|
+
}, b: {
|
|
113
|
+
type: string;
|
|
114
|
+
id: string;
|
|
115
|
+
}): boolean;
|
|
116
|
+
/** Schema registry used to look up model classes and their metadata. */
|
|
117
|
+
readonly schema: SchemaService;
|
|
118
|
+
/** Two-level identity map: `modelName → id → record`. */
|
|
119
|
+
readonly identityMap: IdentityMap;
|
|
120
|
+
private adapters;
|
|
121
|
+
private serializers;
|
|
122
|
+
/** Tracks unsaved (new) records by model name. */
|
|
123
|
+
private newRecords;
|
|
124
|
+
/** Reverse index: record → modelName for O(1) untrackNewRecord. */
|
|
125
|
+
private newRecordTypes;
|
|
126
|
+
/** Per-record cache of relationship proxy objects (ManyArray / AsyncBelongsTo / AsyncHasMany). */
|
|
127
|
+
private relationshipCache;
|
|
128
|
+
/** Tracks new records that have been appended to a hasMany but not yet saved. */
|
|
129
|
+
private pendingMembers;
|
|
130
|
+
constructor(schema: SchemaService);
|
|
131
|
+
/** Registers an adapter for a given model name (or `'application'` as a fallback). */
|
|
132
|
+
registerAdapter(modelName: string, adapter: AdapterLike): void;
|
|
133
|
+
/** Registers a serializer for a given model name (or `'application'` as a fallback). */
|
|
134
|
+
registerSerializer(modelName: string, serializer: SerializerLike): void;
|
|
135
|
+
/**
|
|
136
|
+
* Returns the adapter for `modelName`, falling back to `'application'`.
|
|
137
|
+
* @throws when no adapter is registered.
|
|
138
|
+
*/
|
|
139
|
+
adapterFor(modelName: string): AdapterLike;
|
|
140
|
+
/**
|
|
141
|
+
* Returns the serializer for `modelName`, falling back to `'application'`.
|
|
142
|
+
* @throws when no serializer is registered.
|
|
143
|
+
*/
|
|
144
|
+
serializerFor(modelName: string): SerializerLike;
|
|
145
|
+
/**
|
|
146
|
+
* Creates a new (unsaved) record of the given type with optional initial data.
|
|
147
|
+
* The record is tracked in `newRecords` until it is saved or rolled back.
|
|
148
|
+
*
|
|
149
|
+
* @throws when `modelName` has not been registered with `SchemaService`.
|
|
150
|
+
*/
|
|
151
|
+
createRecord<T extends Model = Model>(modelName: string, data?: Record<string, unknown>): T;
|
|
152
|
+
private trackNewRecord;
|
|
153
|
+
private untrackNewRecord;
|
|
154
|
+
/**
|
|
155
|
+
* Synchronously returns a record from the identity map, or `null` when not
|
|
156
|
+
* found. Does not trigger a network request.
|
|
157
|
+
*/
|
|
158
|
+
peekRecord<T extends Model = Model>(modelName: string, id: string): T | null;
|
|
159
|
+
/**
|
|
160
|
+
* Returns a live `RecordArray` backed by the identity map for `modelName`.
|
|
161
|
+
* New (unsaved) records are included at the end.
|
|
162
|
+
* Does not trigger a network request.
|
|
163
|
+
*/
|
|
164
|
+
peekAll<T extends Model = Model>(modelName: string): RecordArray<T>;
|
|
165
|
+
/**
|
|
166
|
+
* Pushes a normalized document into the identity map.
|
|
167
|
+
* Side-loaded (`included`) records are pushed first.
|
|
168
|
+
*
|
|
169
|
+
* @returns The primary record(s), or `null` for empty payloads.
|
|
170
|
+
*/
|
|
171
|
+
push(doc: unknown): Model | Model[] | null;
|
|
172
|
+
/**
|
|
173
|
+
* Normalizes a raw payload via the registered serializer and pushes the
|
|
174
|
+
* result. `modelName` is optional; when omitted the payload is pushed
|
|
175
|
+
* directly without normalization.
|
|
176
|
+
*/
|
|
177
|
+
pushPayload(modelNameOrPayload: string | unknown, payload?: unknown): void;
|
|
178
|
+
/**
|
|
179
|
+
* Normalizes a raw payload for `modelName` via the registered serializer
|
|
180
|
+
* and returns the `NormalizedDocument` without pushing it.
|
|
181
|
+
*/
|
|
182
|
+
normalize(modelName: string, payload: unknown): NormalizedDocument;
|
|
183
|
+
/**
|
|
184
|
+
* Inserts or merges a single normalized resource into the identity map.
|
|
185
|
+
* - Existing record → calls `_applyServerData` to merge attributes and
|
|
186
|
+
* relationships in place (preserving the live reference).
|
|
187
|
+
* - New record → instantiates via `Model.push` and sets it in the map.
|
|
188
|
+
*
|
|
189
|
+
* @throws when `type` has not been registered or `id` is `null`.
|
|
190
|
+
*/
|
|
191
|
+
private pushResource;
|
|
192
|
+
/**
|
|
193
|
+
* After pushing a resource, updates the inverse side of every declared
|
|
194
|
+
* inverse relationship so both sides stay consistent.
|
|
195
|
+
*/
|
|
196
|
+
private trackInverseForResource;
|
|
197
|
+
/**
|
|
198
|
+
* Adds `inverseRecord` to the inverse relationship on `targetType:targetId`.
|
|
199
|
+
* No-ops when the target record is not in the identity map.
|
|
200
|
+
*/
|
|
201
|
+
private addInverse;
|
|
202
|
+
/**
|
|
203
|
+
* Removes `inverseRecord` from the inverse relationship on `targetType:targetId`.
|
|
204
|
+
* No-ops when the target record is not in the identity map.
|
|
205
|
+
*/
|
|
206
|
+
private removeInverse;
|
|
207
|
+
/**
|
|
208
|
+
* Removes a record from the identity map and clears its relationship cache.
|
|
209
|
+
* Called by `record.unloadRecord()` and internally after `deleteRecord`.
|
|
210
|
+
*/
|
|
211
|
+
unloadRecord(record: Model): void;
|
|
212
|
+
/**
|
|
213
|
+
* Unloads all records for `modelName`, or all records across all types when
|
|
214
|
+
* `modelName` is omitted.
|
|
215
|
+
*/
|
|
216
|
+
unloadAll(modelName?: string): void;
|
|
217
|
+
/**
|
|
218
|
+
* Finds a single record by id. Returns the cached record immediately when
|
|
219
|
+
* `options.reload` is not set; otherwise re-fetches.
|
|
220
|
+
*
|
|
221
|
+
* When the adapter has `coalesceFindRequests: true` and `findMany` is
|
|
222
|
+
* implemented, multiple concurrent `findRecord` calls for the same type
|
|
223
|
+
* are batched into a single `findMany` network request.
|
|
224
|
+
*/
|
|
225
|
+
findRecord<T extends Model = Model>(modelName: string, id: string, options?: FindOptions): Promise<T>;
|
|
226
|
+
/**
|
|
227
|
+
* Fetches all records of `modelName` from the server and returns a
|
|
228
|
+
* `RecordArray` backed by the identity map.
|
|
229
|
+
*/
|
|
230
|
+
findAll<T extends Model = Model>(modelName: string, options?: FindOptions): Promise<RecordArray<T>>;
|
|
231
|
+
/**
|
|
232
|
+
* Executes an adapter query and returns an `AdapterPopulatedRecordArray`
|
|
233
|
+
* whose `update()` method re-issues the same query.
|
|
234
|
+
*/
|
|
235
|
+
query<T extends Model = Model>(modelName: string, params: Record<string, unknown>): Promise<AdapterPopulatedRecordArray<T>>;
|
|
236
|
+
private runQuery;
|
|
237
|
+
/**
|
|
238
|
+
* Executes an adapter query that returns at most one record.
|
|
239
|
+
* Returns `null` when the adapter returns an empty payload.
|
|
240
|
+
*/
|
|
241
|
+
queryRecord<T extends Model = Model>(modelName: string, params: Record<string, unknown>): Promise<T | null>;
|
|
242
|
+
/**
|
|
243
|
+
* Persists a record to the server.
|
|
244
|
+
* - New records → `adapter.createRecord` (POST)
|
|
245
|
+
* - Existing dirty records → `adapter.updateRecord` (PUT) by default
|
|
246
|
+
* - With `{ patch: true }` → `adapter.patchRecord` (PATCH, partial payload)
|
|
247
|
+
*
|
|
248
|
+
* After the response is received the server data is applied back to the
|
|
249
|
+
* record via `_applyServerData` so it transitions to `saved`.
|
|
250
|
+
*/
|
|
251
|
+
saveRecord<T extends Model>(record: T, options?: SaveOptions): Promise<T>;
|
|
252
|
+
/**
|
|
253
|
+
* Issues a DELETE request and unloads the record from the identity map.
|
|
254
|
+
*/
|
|
255
|
+
deleteRecord<T extends Model>(record: T): Promise<T>;
|
|
256
|
+
/**
|
|
257
|
+
* Re-fetches a record from the server and merges the response into the
|
|
258
|
+
* existing instance.
|
|
259
|
+
*/
|
|
260
|
+
reloadRecord<T extends Model>(record: T): Promise<T>;
|
|
261
|
+
/**
|
|
262
|
+
* Creates a `Snapshot` for a live record.
|
|
263
|
+
* The snapshot reads directly from the record's internal state so it
|
|
264
|
+
* reflects the current (possibly dirty) values.
|
|
265
|
+
*/
|
|
266
|
+
createSnapshot(record: Model): Snapshot;
|
|
267
|
+
/**
|
|
268
|
+
* Creates a placeholder `Snapshot` for a record that is not yet in the
|
|
269
|
+
* identity map (used when fetching a record that isn't cached).
|
|
270
|
+
*/
|
|
271
|
+
private createEmptySnapshot;
|
|
272
|
+
private getRelationshipCache;
|
|
273
|
+
private setRelationshipCache;
|
|
274
|
+
/**
|
|
275
|
+
* Called by the `Model` relationship getter to resolve a relationship.
|
|
276
|
+
*
|
|
277
|
+
* - **Async** `belongsTo` → returns an `AsyncBelongsTo` wrapper.
|
|
278
|
+
* - **Async** `hasMany` → returns an `AsyncHasMany` wrapper.
|
|
279
|
+
* - **Sync** `belongsTo` → peeks the related record from the identity map.
|
|
280
|
+
* - **Sync** `hasMany` → returns a `ManyArray` backed by the store.
|
|
281
|
+
*
|
|
282
|
+
* Results are cached per record + name so the same proxy is returned on
|
|
283
|
+
* repeated accesses (important for MobX observability).
|
|
284
|
+
*/
|
|
285
|
+
resolveRelationship(record: Model, name: string, meta: RelationshipDef): unknown;
|
|
286
|
+
/**
|
|
287
|
+
* Called by the `Model` `belongsTo` setter to update a relationship ref
|
|
288
|
+
* and keep its inverse in sync.
|
|
289
|
+
*/
|
|
290
|
+
setRelationshipValue(record: Model, name: string, meta: RelationshipDef, value: unknown): void;
|
|
291
|
+
/** Returns the raw relationship ref stored on `record` for `name`. */
|
|
292
|
+
_getRelationshipRefFor(record: Model, name: string): RelationshipRef | null;
|
|
293
|
+
/** Returns any pending (unsaved) members for a `hasMany` relationship. */
|
|
294
|
+
_getPendingMembers(record: Model, name: string): Iterable<Model>;
|
|
295
|
+
private addPendingMember;
|
|
296
|
+
private removePendingMember;
|
|
297
|
+
/**
|
|
298
|
+
* Appends `value` to the `hasMany` relationship ref on `record` and syncs
|
|
299
|
+
* the inverse. Unsaved records (`value.id === null`) are tracked as
|
|
300
|
+
* "pending members" until they are persisted.
|
|
301
|
+
*/
|
|
302
|
+
_hasManyAppend(record: Model, name: string, meta: RelationshipDef, value: Model): void;
|
|
303
|
+
/**
|
|
304
|
+
* Removes `value` from the `hasMany` relationship ref on `record` and syncs
|
|
305
|
+
* the inverse. Pending members are removed from the pending set.
|
|
306
|
+
*/
|
|
307
|
+
_hasManyRemove(record: Model, name: string, meta: RelationshipDef, value: Model): void;
|
|
308
|
+
private coalescePending;
|
|
309
|
+
private coalesceScheduled;
|
|
310
|
+
private scheduleCoalescedFind;
|
|
311
|
+
private flushCoalescedFind;
|
|
312
|
+
/**
|
|
313
|
+
* Returns a reactive `RecordArray` that auto-updates whenever records matching
|
|
314
|
+
* the predicate are added, removed, or mutated in the identity map.
|
|
315
|
+
*
|
|
316
|
+
* The underlying computed uses `keepAlive: true` so it remains cached even
|
|
317
|
+
* without active MobX observers — useful for long-lived filtered views.
|
|
318
|
+
*
|
|
319
|
+
* @param modelName - The registered model type to query.
|
|
320
|
+
* @param predicate - Filter function applied to each record of `modelName`.
|
|
321
|
+
* @returns A live `RecordArray` containing only records that satisfy `predicate`.
|
|
322
|
+
*/
|
|
323
|
+
liveQuery<T extends Model = Model>(modelName: string, predicate: (record: T) => boolean): RecordArray<T>;
|
|
324
|
+
/**
|
|
325
|
+
* Applies attribute changes to a record immediately (optimistically), then
|
|
326
|
+
* executes `persistFn`. If `persistFn` throws, the record is automatically
|
|
327
|
+
* rolled back to its state before the optimistic update.
|
|
328
|
+
*
|
|
329
|
+
* @param record - The record to update optimistically.
|
|
330
|
+
* @param optimisticAttributes - Attributes to apply before persistence.
|
|
331
|
+
* @param persistFn - Async function that persists the change (e.g. `record.save()`).
|
|
332
|
+
* @returns The record on success.
|
|
333
|
+
* @throws Re-throws the error from `persistFn` after rollback.
|
|
334
|
+
*/
|
|
335
|
+
optimisticUpdate<T extends Model>(record: T, optimisticAttributes: Partial<Record<string, unknown>>, persistFn: () => Promise<unknown>): Promise<T>;
|
|
336
|
+
/**
|
|
337
|
+
* Executes multiple store mutations as a single MobX action, guaranteeing
|
|
338
|
+
* that observers (and therefore UI renders) react only once — after all
|
|
339
|
+
* mutations have been applied.
|
|
340
|
+
*
|
|
341
|
+
* @param callback - Synchronous function containing one or more store mutations.
|
|
342
|
+
*/
|
|
343
|
+
runInTransaction(callback: () => void): void;
|
|
344
|
+
/**
|
|
345
|
+
* Produces a JSON-serializable snapshot of all records in the identity map.
|
|
346
|
+
* Designed for server-side rendering: serialize on the server, transfer as
|
|
347
|
+
* JSON, then `hydrate()` on the client to restore the full store state
|
|
348
|
+
* without network requests.
|
|
349
|
+
*
|
|
350
|
+
* @param options.exclude - Per-model-type list of attribute keys to omit
|
|
351
|
+
* (e.g. `{ user: ['password', 'token'] }`) to prevent leaking sensitive
|
|
352
|
+
* data in SSR payloads.
|
|
353
|
+
* @returns A snapshot object safe to pass through `JSON.stringify`.
|
|
354
|
+
*/
|
|
355
|
+
serialize(options?: {
|
|
356
|
+
exclude?: Record<string, string[]>;
|
|
357
|
+
}): {
|
|
358
|
+
records: Record<string, Array<{
|
|
359
|
+
id: string;
|
|
360
|
+
attributes: Record<string, unknown>;
|
|
361
|
+
relationships?: Record<string, RelationshipRef>;
|
|
362
|
+
}>>;
|
|
363
|
+
};
|
|
364
|
+
/**
|
|
365
|
+
* Restores records from a snapshot produced by `serialize()` into this store
|
|
366
|
+
* instance. All records are pushed into the identity map in `loaded.saved`
|
|
367
|
+
* state — no network requests are issued.
|
|
368
|
+
*
|
|
369
|
+
* @param snapshot - A snapshot object previously returned by `serialize()`.
|
|
370
|
+
*/
|
|
371
|
+
hydrate(snapshot: {
|
|
372
|
+
records: Record<string, Array<{
|
|
373
|
+
id: string;
|
|
374
|
+
attributes: Record<string, unknown>;
|
|
375
|
+
relationships?: Record<string, RelationshipRef>;
|
|
376
|
+
}>>;
|
|
377
|
+
}): void;
|
|
378
|
+
/**
|
|
379
|
+
* Factory method that creates a new `Store` and immediately hydrates it from
|
|
380
|
+
* the given snapshot. Convenience for SSR client-side bootstrap.
|
|
381
|
+
*
|
|
382
|
+
* @param schema - SchemaService with all model types registered.
|
|
383
|
+
* @param snapshot - A snapshot object previously returned by `serialize()`.
|
|
384
|
+
* @returns A fully populated `Store` instance ready for use.
|
|
385
|
+
*/
|
|
386
|
+
static hydrate(schema: SchemaService, snapshot: {
|
|
387
|
+
records: Record<string, Array<{
|
|
388
|
+
id: string;
|
|
389
|
+
attributes: Record<string, unknown>;
|
|
390
|
+
relationships?: Record<string, RelationshipRef>;
|
|
391
|
+
}>>;
|
|
392
|
+
}): Store;
|
|
393
|
+
}
|
|
394
|
+
export {};
|
|
395
|
+
//# sourceMappingURL=Store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Store.d.ts","sourceRoot":"","sources":["../../src/store/Store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAMH,OAAO,EACL,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,EAIL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,2BAA2B,EAC5B,MAAM,kBAAkB,CAAC;AAE1B,iEAAiE;AACjE,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED,sDAAsD;AACtD,MAAM,WAAW,WAAW;IAC1B,UAAU,CACR,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,QAAQ,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AE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAAC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;SAAE,CAAC,CAAC,CAAA;KAAE,GAAG,IAAI;IAejK;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,CACZ,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAAC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;SAAE,CAAC,CAAC,CAAA;KAAE,GACjJ,KAAK;CAKT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../Store-BdwMrbDi.cjs");exports.AdapterPopulatedRecordArray=e.AdapterPopulatedRecordArray;exports.IdentityMap=e.IdentityMap;exports.RecordArray=e.RecordArray;Object.defineProperty(exports,"Store",{enumerable:!0,get:()=>e.Store});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Store } from './Store.js';
|
|
2
|
+
export type { AdapterLike, AdapterFetchOptions, SerializerLike, FindOptions, NormalizedDocument, NormalizedResource, } from './Store.js';
|
|
3
|
+
export { IdentityMap } from './IdentityMap.js';
|
|
4
|
+
export { RecordArray, AdapterPopulatedRecordArray } from './RecordArray.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface and abstract base class for data transforms.
|
|
3
|
+
*
|
|
4
|
+
* A transform converts attribute values between the wire format used by the
|
|
5
|
+
* server (External) and the in-memory format used by the application
|
|
6
|
+
* (Internal).
|
|
7
|
+
*
|
|
8
|
+
* - `deserialize` — called when the store receives data from the server
|
|
9
|
+
* (normalize direction, server → app).
|
|
10
|
+
* - `serialize` — called when the store sends data to the server
|
|
11
|
+
* (serialize direction, app → server).
|
|
12
|
+
*
|
|
13
|
+
* Built-in transforms: `StringTransform`, `NumberTransform`,
|
|
14
|
+
* `BooleanTransform`, `DateTransform`.
|
|
15
|
+
*
|
|
16
|
+
* Custom transforms can be implemented by extending `BaseTransform`:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* @injectable()
|
|
20
|
+
* class UpperCaseTransform extends BaseTransform<string, string> {
|
|
21
|
+
* deserialize(value: string) { return value.toUpperCase(); }
|
|
22
|
+
* serialize(value: string) { return value.toLowerCase(); }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
/** Bidirectional value converter for a single attribute type. */
|
|
27
|
+
export interface Transform<External = unknown, Internal = unknown> {
|
|
28
|
+
/**
|
|
29
|
+
* Converts a raw server value to the application-side type.
|
|
30
|
+
* @param serialized - Raw value as it arrived from the server.
|
|
31
|
+
* @param options - Extra options forwarded from the `@attr` decorator.
|
|
32
|
+
*/
|
|
33
|
+
deserialize(serialized: External, options?: Record<string, unknown>): Internal;
|
|
34
|
+
/**
|
|
35
|
+
* Converts an application-side value back to the wire format.
|
|
36
|
+
* @param deserialized - Current in-memory value.
|
|
37
|
+
* @param options - Extra options forwarded from the `@attr` decorator.
|
|
38
|
+
*/
|
|
39
|
+
serialize(deserialized: Internal, options?: Record<string, unknown>): External;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Convenience abstract class that implements `Transform` and can be extended
|
|
43
|
+
* to create custom transforms without repeating the interface declaration.
|
|
44
|
+
*/
|
|
45
|
+
export declare abstract class BaseTransform<External = unknown, Internal = unknown> implements Transform<External, Internal> {
|
|
46
|
+
abstract deserialize(serialized: External, options?: Record<string, unknown>): Internal;
|
|
47
|
+
abstract serialize(deserialized: Internal, options?: Record<string, unknown>): External;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=Transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transform.d.ts","sourceRoot":"","sources":["../../src/transforms/Transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,iEAAiE;AACjE,MAAM,WAAW,SAAS,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,GAAG,OAAO;IAC/D;;;;OAIG;IACH,WAAW,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC;IAE/E;;;;OAIG;IACH,SAAS,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC;CAChF;AAED;;;GAGG;AACH,8BAAsB,aAAa,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,GAAG,OAAO,CAC1E,YAAW,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACtC,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ;IACvF,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ;CACxF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform that converts between arbitrary wire values and booleans.
|
|
3
|
+
*
|
|
4
|
+
* Deserialization coercions:
|
|
5
|
+
* - `null` / `undefined` → `false` (or `null` when `allowNull: true`)
|
|
6
|
+
* - `boolean` → passed through
|
|
7
|
+
* - `number` → `true` only when the value is exactly `1`
|
|
8
|
+
* - `string` → `true` for `'true'`, `'t'`, or `'1'` (case-insensitive)
|
|
9
|
+
* - anything else → `Boolean(value)`
|
|
10
|
+
*
|
|
11
|
+
* Serialization: `Boolean(value)` (preserves `null` when `allowNull: true`).
|
|
12
|
+
*/
|
|
13
|
+
import { BaseTransform } from './Transform.js';
|
|
14
|
+
/** Options accepted by `BooleanTransform`. */
|
|
15
|
+
export interface BooleanTransformOptions {
|
|
16
|
+
/**
|
|
17
|
+
* When `true`, `null` / `undefined` input is preserved as `null` rather
|
|
18
|
+
* than coerced to `false`.
|
|
19
|
+
*/
|
|
20
|
+
allowNull?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare class BooleanTransform extends BaseTransform<unknown, boolean | null> {
|
|
23
|
+
deserialize(serialized: unknown, options?: BooleanTransformOptions): boolean | null;
|
|
24
|
+
serialize(deserialized: boolean | null, options?: BooleanTransformOptions): unknown;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=boolean.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../src/transforms/boolean.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,8CAA8C;AAC9C,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,qBACa,gBAAiB,SAAQ,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1E,WAAW,CACT,UAAU,EAAE,OAAO,EACnB,OAAO,GAAE,uBAA4B,GACpC,OAAO,GAAG,IAAI;IAiBjB,SAAS,CACP,YAAY,EAAE,OAAO,GAAG,IAAI,EAC5B,OAAO,GAAE,uBAA4B,GACpC,OAAO;CAMX"}
|