@warp-drive/core 5.6.0-alpha.5 → 5.6.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/cjs-dist/addon-shim.cjs +1 -0
- package/cjs-dist/cjs-set-config.cjs +1 -0
- package/declarations/build-config/babel-macros.d.ts +1 -0
- package/declarations/build-config/canary-features.d.ts +1 -0
- package/declarations/build-config/debugging.d.ts +1 -0
- package/declarations/build-config/deprecations.d.ts +1 -0
- package/declarations/build-config/env.d.ts +1 -0
- package/declarations/build-config/macros.d.ts +1 -0
- package/declarations/build-config.d.ts +1 -0
- package/declarations/configure.d.ts +7 -0
- package/declarations/graph/-private/-diff.d.ts +32 -0
- package/declarations/graph/-private/-edge-definition.d.ts +148 -0
- package/declarations/graph/-private/-state.d.ts +96 -0
- package/declarations/graph/-private/-utils.d.ts +31 -0
- package/declarations/graph/-private/coerce-id.d.ts +10 -0
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +18 -0
- package/declarations/graph/-private/edges/collection.d.ts +39 -0
- package/declarations/graph/-private/edges/implicit.d.ts +43 -0
- package/declarations/graph/-private/edges/resource.d.ts +24 -0
- package/declarations/graph/-private/graph.d.ts +90 -0
- package/declarations/graph/-private/normalize-link.d.ts +8 -0
- package/declarations/graph/-private/operations/add-to-related-records.d.ts +4 -0
- package/declarations/graph/-private/operations/merge-identifier.d.ts +3 -0
- package/declarations/graph/-private/operations/remove-from-related-records.d.ts +4 -0
- package/declarations/graph/-private/operations/replace-related-record.d.ts +3 -0
- package/declarations/graph/-private/operations/replace-related-records.d.ts +62 -0
- package/declarations/graph/-private/operations/update-relationship.d.ts +13 -0
- package/declarations/graph/-private.d.ts +13 -0
- package/declarations/index.d.ts +14 -3
- package/declarations/reactive/-private/document.d.ts +146 -0
- package/declarations/reactive/-private/fields/compute.d.ts +43 -0
- package/declarations/reactive/-private/fields/extension.d.ts +8 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts +22 -0
- package/declarations/reactive/-private/fields/managed-object.d.ts +21 -0
- package/declarations/reactive/-private/fields/many-array-manager.d.ts +19 -0
- package/declarations/reactive/-private/hooks.d.ts +5 -0
- package/declarations/reactive/-private/record.d.ts +64 -0
- package/declarations/reactive/-private/schema.d.ts +271 -0
- package/declarations/reactive/-private/symbols.d.ts +36 -0
- package/declarations/reactive/-private.d.ts +1 -0
- package/declarations/reactive.d.ts +4 -0
- package/declarations/request/-private/context.d.ts +34 -35
- package/declarations/request/-private/debug.d.ts +2 -3
- package/declarations/request/-private/fetch.d.ts +24 -36
- package/declarations/request/-private/future.d.ts +3 -4
- package/declarations/request/-private/manager.d.ts +159 -132
- package/declarations/request/-private/promise-cache.d.ts +21 -13
- package/declarations/request/-private/types.d.ts +124 -123
- package/declarations/request/-private/utils.d.ts +8 -9
- package/declarations/request.d.ts +5 -433
- package/declarations/store/-private/cache-handler/handler.d.ts +62 -0
- package/declarations/store/-private/cache-handler/types.d.ts +98 -0
- package/declarations/store/-private/cache-handler/utils.d.ts +32 -0
- package/declarations/store/-private/caches/cache-utils.d.ts +12 -0
- package/declarations/store/-private/caches/identifier-cache.d.ts +304 -0
- package/declarations/store/-private/caches/instance-cache.d.ts +65 -0
- package/declarations/store/-private/caches/resource-utils.d.ts +9 -0
- package/declarations/store/-private/debug/utils.d.ts +6 -0
- package/declarations/store/-private/default-cache-policy.d.ts +384 -0
- package/declarations/store/-private/legacy-model-support/record-reference.d.ts +159 -0
- package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +17 -0
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +25 -0
- package/declarations/store/-private/managers/cache-manager.d.ts +443 -0
- package/declarations/store/-private/managers/notification-manager.d.ts +98 -0
- package/declarations/store/-private/managers/record-array-manager.d.ts +97 -0
- package/declarations/store/-private/network/request-cache.d.ts +107 -0
- package/declarations/store/-private/new-core-tmp/promise-state.d.ts +263 -0
- package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +176 -0
- package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +169 -0
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +35 -0
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +277 -0
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +261 -0
- package/declarations/store/-private/record-arrays/identifier-array.d.ts +147 -0
- package/declarations/store/-private/record-arrays/many-array.d.ts +197 -0
- package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +126 -0
- package/declarations/store/-private/store-service.d.ts +1605 -0
- package/declarations/store/-private/utils/coerce-id.d.ts +10 -0
- package/declarations/store/-private/utils/construct-resource.d.ts +6 -0
- package/declarations/store/-private/utils/is-non-empty-string.d.ts +1 -0
- package/declarations/store/-private/utils/normalize-model-name.d.ts +1 -0
- package/declarations/store/-private/utils/uuid-polyfill.d.ts +1 -0
- package/declarations/store/-private.d.ts +31 -0
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +99 -0
- package/declarations/store/-types/q/ds-model.d.ts +21 -0
- package/declarations/store/-types/q/identifier.d.ts +20 -0
- package/declarations/store/-types/q/record-instance.d.ts +23 -0
- package/declarations/store/-types/q/schema-service.d.ts +354 -0
- package/declarations/store/-types/q/store.d.ts +32 -0
- package/declarations/store.d.ts +1 -0
- package/declarations/types/-private.d.ts +16 -8
- package/declarations/types/cache/aliases.d.ts +11 -1
- package/declarations/types/cache/change.d.ts +4 -5
- package/declarations/types/cache/mutations.d.ts +51 -28
- package/declarations/types/cache/operations.d.ts +60 -47
- package/declarations/types/cache/relationship.d.ts +11 -9
- package/declarations/types/cache.d.ts +495 -484
- package/declarations/types/graph.d.ts +31 -40
- package/declarations/types/identifier.d.ts +83 -82
- package/declarations/types/json/raw.d.ts +1 -2
- package/declarations/types/params.d.ts +4 -5
- package/declarations/types/record.d.ts +117 -76
- package/declarations/types/request.d.ts +289 -266
- package/declarations/types/runtime.d.ts +8 -9
- package/declarations/types/schema/concepts.d.ts +19 -13
- package/declarations/types/schema/fields.d.ts +1712 -1741
- package/declarations/types/schema/fields.type-test.d.ts +0 -1
- package/declarations/types/spec/document.d.ts +28 -22
- package/declarations/types/spec/error.d.ts +16 -17
- package/declarations/types/spec/json-api-raw.d.ts +102 -102
- package/declarations/types/symbols.d.ts +74 -75
- package/declarations/types/utils.d.ts +5 -5
- package/declarations/types.d.ts +10 -7
- package/declarations/utils/string.d.ts +48 -0
- package/dist/build-config/babel-macros.js +1 -0
- package/dist/build-config/canary-features.js +1 -0
- package/dist/build-config/debugging.js +1 -0
- package/dist/build-config/deprecations.js +1 -0
- package/dist/build-config/env.js +1 -0
- package/dist/build-config/macros.js +1 -0
- package/dist/build-config.js +1 -0
- package/dist/configure-B48bFHOl.js +181 -0
- package/dist/configure.js +1 -0
- package/dist/{context-DE5sFezZ.js → context-COmAnXUQ.js} +2 -2
- package/dist/graph/-private.js +3372 -0
- package/dist/handler-C2T-IyJK.js +339 -0
- package/dist/index.js +37 -104
- package/dist/reactive/-private.js +1 -0
- package/dist/reactive.js +1988 -0
- package/dist/request-state-CjLph1LP.js +8139 -0
- package/dist/request.js +1 -1
- package/dist/store/-private.js +3 -0
- package/dist/store.js +545 -0
- package/dist/symbols-SIstXMLI.js +44 -0
- package/dist/types/-private.js +3 -3
- package/dist/types/record.js +1 -1
- package/dist/types/request.js +2 -2
- package/dist/types/runtime.js +1 -1
- package/dist/types/schema/fields.js +8 -41
- package/dist/types/symbols.js +3 -3
- package/dist/utils/string.js +92 -0
- package/logos/NCC-1701-a-blue.svg +4 -0
- package/logos/NCC-1701-a-gold.svg +4 -0
- package/logos/NCC-1701-a-gold_100.svg +1 -0
- package/logos/NCC-1701-a-gold_base-64.txt +1 -0
- package/logos/NCC-1701-a.svg +4 -0
- package/logos/README.md +4 -0
- package/logos/docs-badge.svg +2 -0
- package/logos/ember-data-logo-dark.svg +12 -0
- package/logos/ember-data-logo-light.svg +12 -0
- package/logos/github-header.svg +444 -0
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +4 -0
- package/logos/warp-drive-logo-gold.svg +4 -0
- package/package.json +11 -8
- package/declarations/index.d.ts.map +0 -1
- package/declarations/request/-private/context.d.ts.map +0 -1
- package/declarations/request/-private/debug.d.ts.map +0 -1
- package/declarations/request/-private/fetch.d.ts.map +0 -1
- package/declarations/request/-private/future.d.ts.map +0 -1
- package/declarations/request/-private/manager.d.ts.map +0 -1
- package/declarations/request/-private/promise-cache.d.ts.map +0 -1
- package/declarations/request/-private/types.d.ts.map +0 -1
- package/declarations/request/-private/utils.d.ts.map +0 -1
- package/declarations/request.d.ts.map +0 -1
- package/declarations/types/-private.d.ts.map +0 -1
- package/declarations/types/cache/aliases.d.ts.map +0 -1
- package/declarations/types/cache/change.d.ts.map +0 -1
- package/declarations/types/cache/mutations.d.ts.map +0 -1
- package/declarations/types/cache/operations.d.ts.map +0 -1
- package/declarations/types/cache/relationship.d.ts.map +0 -1
- package/declarations/types/cache.d.ts.map +0 -1
- package/declarations/types/graph.d.ts.map +0 -1
- package/declarations/types/identifier.d.ts.map +0 -1
- package/declarations/types/json/raw.d.ts.map +0 -1
- package/declarations/types/params.d.ts.map +0 -1
- package/declarations/types/record.d.ts.map +0 -1
- package/declarations/types/record.type-test.d.ts +0 -2
- package/declarations/types/record.type-test.d.ts.map +0 -1
- package/declarations/types/request.d.ts.map +0 -1
- package/declarations/types/request.type-test.d.ts +0 -2
- package/declarations/types/request.type-test.d.ts.map +0 -1
- package/declarations/types/runtime.d.ts.map +0 -1
- package/declarations/types/schema/concepts.d.ts.map +0 -1
- package/declarations/types/schema/fields.d.ts.map +0 -1
- package/declarations/types/schema/fields.type-test.d.ts.map +0 -1
- package/declarations/types/spec/document.d.ts.map +0 -1
- package/declarations/types/spec/error.d.ts.map +0 -1
- package/declarations/types/spec/json-api-raw.d.ts.map +0 -1
- package/declarations/types/symbols.d.ts.map +0 -1
- package/declarations/types/utils.d.ts.map +0 -1
- package/declarations/types.d.ts.map +0 -1
- package/dist/context-DE5sFezZ.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/request.js.map +0 -1
- package/dist/types/-private.js.map +0 -1
- package/dist/types/cache/aliases.js.map +0 -1
- package/dist/types/cache/change.js.map +0 -1
- package/dist/types/cache/mutations.js.map +0 -1
- package/dist/types/cache/operations.js.map +0 -1
- package/dist/types/cache/relationship.js.map +0 -1
- package/dist/types/cache.js.map +0 -1
- package/dist/types/graph.js.map +0 -1
- package/dist/types/identifier.js.map +0 -1
- package/dist/types/json/raw.js.map +0 -1
- package/dist/types/params.js.map +0 -1
- package/dist/types/record.js.map +0 -1
- package/dist/types/request.js.map +0 -1
- package/dist/types/runtime.js.map +0 -1
- package/dist/types/schema/concepts.js.map +0 -1
- package/dist/types/schema/fields.js.map +0 -1
- package/dist/types/schema/fields.type-test.js.map +0 -1
- package/dist/types/spec/document.js.map +0 -1
- package/dist/types/spec/error.js.map +0 -1
- package/dist/types/spec/json-api-raw.js.map +0 -1
- package/dist/types/symbols.js.map +0 -1
- package/dist/types/utils.js.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import type { Cache, ChangedAttributesHash, RelationshipDiff } from "../../../types/cache.js";
|
|
2
|
+
import type { Change } from "../../../types/cache/change.js";
|
|
3
|
+
import type { MergeOperation } from "../../../types/cache/operations.js";
|
|
4
|
+
import type { CollectionRelationship, ResourceRelationship } from "../../../types/cache/relationship.js";
|
|
5
|
+
import type { LocalRelationshipOperation } from "../../../types/graph.js";
|
|
6
|
+
import type { StableDocumentIdentifier, StableRecordIdentifier } from "../../../types/identifier.js";
|
|
7
|
+
import type { Value } from "../../../types/json/raw.js";
|
|
8
|
+
import type { StructuredDataDocument, StructuredDocument } from "../../../types/request.js";
|
|
9
|
+
import type { ResourceDocument, SingleResourceDataDocument } from "../../../types/spec/document.js";
|
|
10
|
+
import type { ApiError } from "../../../types/spec/error.js";
|
|
11
|
+
import type { StoreRequestContext } from "../cache-handler/handler.js";
|
|
12
|
+
/**
|
|
13
|
+
* The CacheManager wraps a Cache enforcing that only
|
|
14
|
+
* the public API surface area is exposed.
|
|
15
|
+
*
|
|
16
|
+
* Hence, it is the value of `Store.cache`, wrapping
|
|
17
|
+
* the cache instance returned by `Store.createCache`.
|
|
18
|
+
*
|
|
19
|
+
* It handles translating between cache versions when
|
|
20
|
+
* necessary, for instance when a Store is configured
|
|
21
|
+
* to use both a v1 and a v2 cache depending on some
|
|
22
|
+
* heuristic.
|
|
23
|
+
*
|
|
24
|
+
* Starting with the v2 spec, the cache is designed such
|
|
25
|
+
* that it must be implemented as a singleton.
|
|
26
|
+
*
|
|
27
|
+
* @class CacheManager
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare class CacheManager implements Cache {
|
|
31
|
+
#private;
|
|
32
|
+
version: "2";
|
|
33
|
+
constructor(cache: Cache);
|
|
34
|
+
// Cache Management
|
|
35
|
+
// ================
|
|
36
|
+
/**
|
|
37
|
+
* Cache the response to a request
|
|
38
|
+
*
|
|
39
|
+
* Unlike `store.push` which has UPSERT
|
|
40
|
+
* semantics, `put` has `replace` semantics similar to
|
|
41
|
+
* the `http` method `PUT`
|
|
42
|
+
*
|
|
43
|
+
* the individually cacheable
|
|
44
|
+
* e resource data it may contain
|
|
45
|
+
* should upsert, but the document data surrounding it should
|
|
46
|
+
* fully replace any existing information
|
|
47
|
+
*
|
|
48
|
+
* Note that in order to support inserting arbitrary data
|
|
49
|
+
* to the cache that did not originate from a request `put`
|
|
50
|
+
* should expect to sometimes encounter a document with only
|
|
51
|
+
* a `content` member and therefor must not assume the existence
|
|
52
|
+
* of `request` and `response` on the document.
|
|
53
|
+
*
|
|
54
|
+
* @param {StructuredDocument} doc
|
|
55
|
+
* @return {ResourceDocument}
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
put<T>(doc: StructuredDocument<T> | {
|
|
59
|
+
content: T;
|
|
60
|
+
}): ResourceDocument;
|
|
61
|
+
/**
|
|
62
|
+
* Perform an operation on the cache to update the remote state.
|
|
63
|
+
*
|
|
64
|
+
* Note: currently the only valid operation is a MergeOperation
|
|
65
|
+
* which occurs when a collision of identifiers is detected.
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
* @param op the operation to perform
|
|
69
|
+
* @return {void}
|
|
70
|
+
*/
|
|
71
|
+
patch(op: MergeOperation): void;
|
|
72
|
+
/**
|
|
73
|
+
* Update resource data with a local mutation. Currently supports operations
|
|
74
|
+
* on relationships only.
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
77
|
+
* @param mutation
|
|
78
|
+
*/
|
|
79
|
+
mutate(mutation: LocalRelationshipOperation): void;
|
|
80
|
+
/**
|
|
81
|
+
* Peek resource data from the Cache.
|
|
82
|
+
*
|
|
83
|
+
* In development, if the return value
|
|
84
|
+
* is JSON the return value
|
|
85
|
+
* will be deep-cloned and deep-frozen
|
|
86
|
+
* to prevent mutation thereby enforcing cache
|
|
87
|
+
* Immutability.
|
|
88
|
+
*
|
|
89
|
+
* This form of peek is useful for implementations
|
|
90
|
+
* that want to feed raw-data from cache to the UI
|
|
91
|
+
* or which want to interact with a blob of data
|
|
92
|
+
* directly from the presentation cache.
|
|
93
|
+
*
|
|
94
|
+
* An implementation might want to do this because
|
|
95
|
+
* de-referencing records which read from their own
|
|
96
|
+
* blob is generally safer because the record does
|
|
97
|
+
* not require retaining connections to the Store
|
|
98
|
+
* and Cache to present data on a per-field basis.
|
|
99
|
+
*
|
|
100
|
+
* This generally takes the place of `getAttr` as
|
|
101
|
+
* an API and may even take the place of `getRelationship`
|
|
102
|
+
* depending on implementation specifics, though this
|
|
103
|
+
* latter usage is less recommended due to the advantages
|
|
104
|
+
* of the Graph handling necessary entanglements and
|
|
105
|
+
* notifications for relational data.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
* @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
|
|
109
|
+
* @return {ResourceDocument | ResourceBlob | null} the known resource data
|
|
110
|
+
*/
|
|
111
|
+
peek(identifier: StableRecordIdentifier): unknown;
|
|
112
|
+
peek(identifier: StableDocumentIdentifier): ResourceDocument | null;
|
|
113
|
+
peekRemoteState(identifier: StableRecordIdentifier): unknown;
|
|
114
|
+
peekRemoteState(identifier: StableDocumentIdentifier): ResourceDocument | null;
|
|
115
|
+
/**
|
|
116
|
+
* Peek the Cache for the existing request data associated with
|
|
117
|
+
* a cacheable request
|
|
118
|
+
*
|
|
119
|
+
* @param {StableDocumentIdentifier}
|
|
120
|
+
* @return {StableDocumentIdentifier | null}
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
peekRequest(identifier: StableDocumentIdentifier): StructuredDocument<ResourceDocument> | null;
|
|
124
|
+
/**
|
|
125
|
+
* Push resource data from a remote source into the cache for this identifier
|
|
126
|
+
*
|
|
127
|
+
* @public
|
|
128
|
+
* @param identifier
|
|
129
|
+
* @param data
|
|
130
|
+
* @param hasRecord
|
|
131
|
+
* @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned
|
|
132
|
+
*/
|
|
133
|
+
upsert(identifier: StableRecordIdentifier, data: unknown, hasRecord: boolean): void | string[];
|
|
134
|
+
// Cache Forking Support
|
|
135
|
+
// =====================
|
|
136
|
+
/**
|
|
137
|
+
* Create a fork of the cache from the current state.
|
|
138
|
+
*
|
|
139
|
+
* Applications should typically not call this method themselves,
|
|
140
|
+
* preferring instead to fork at the Store level, which will
|
|
141
|
+
* utilize this method to fork the cache.
|
|
142
|
+
*
|
|
143
|
+
* @public
|
|
144
|
+
* @return {Promise<Cache>}
|
|
145
|
+
*/
|
|
146
|
+
fork(): Promise<Cache>;
|
|
147
|
+
/**
|
|
148
|
+
* Merge a fork back into a parent Cache.
|
|
149
|
+
*
|
|
150
|
+
* Applications should typically not call this method themselves,
|
|
151
|
+
* preferring instead to merge at the Store level, which will
|
|
152
|
+
* utilize this method to merge the caches.
|
|
153
|
+
*
|
|
154
|
+
* @param {Cache} cache
|
|
155
|
+
* @public
|
|
156
|
+
* @return {Promise<void>}
|
|
157
|
+
*/
|
|
158
|
+
merge(cache: Cache): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Generate the list of changes applied to all
|
|
161
|
+
* record in the store.
|
|
162
|
+
*
|
|
163
|
+
* Each individual resource or document that has
|
|
164
|
+
* been mutated should be described as an individual
|
|
165
|
+
* `Change` entry in the returned array.
|
|
166
|
+
*
|
|
167
|
+
* A `Change` is described by an object containing up to
|
|
168
|
+
* three properties: (1) the `identifier` of the entity that
|
|
169
|
+
* changed; (2) the `op` code of that change being one of
|
|
170
|
+
* `upsert` or `remove`, and if the op is `upsert` a `patch`
|
|
171
|
+
* containing the data to merge into the cache for the given
|
|
172
|
+
* entity.
|
|
173
|
+
*
|
|
174
|
+
* This `patch` is opaque to the Store but should be understood
|
|
175
|
+
* by the Cache and may expect to be utilized by an Adapter
|
|
176
|
+
* when generating data during a `save` operation.
|
|
177
|
+
*
|
|
178
|
+
* It is generally recommended that the `patch` contain only
|
|
179
|
+
* the updated state, ignoring fields that are unchanged
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* interface Change {
|
|
183
|
+
* identifier: StableRecordIdentifier | StableDocumentIdentifier;
|
|
184
|
+
* op: 'upsert' | 'remove';
|
|
185
|
+
* patch?: unknown;
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @public
|
|
190
|
+
*/
|
|
191
|
+
diff(): Promise<Change[]>;
|
|
192
|
+
// SSR Support
|
|
193
|
+
// ===========
|
|
194
|
+
/**
|
|
195
|
+
* Serialize the entire contents of the Cache into a Stream
|
|
196
|
+
* which may be fed back into a new instance of the same Cache
|
|
197
|
+
* via `cache.hydrate`.
|
|
198
|
+
*
|
|
199
|
+
* @return {Promise<ReadableStream>}
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
dump(): Promise<ReadableStream<unknown>>;
|
|
203
|
+
/**
|
|
204
|
+
* hydrate a Cache from a Stream with content previously serialized
|
|
205
|
+
* from another instance of the same Cache, resolving when hydration
|
|
206
|
+
* is complete.
|
|
207
|
+
*
|
|
208
|
+
* This method should expect to be called both in the context of restoring
|
|
209
|
+
* the Cache during application rehydration after SSR **AND** at unknown
|
|
210
|
+
* times during the lifetime of an already booted application when it is
|
|
211
|
+
* desired to bulk-load additional information into the cache. This latter
|
|
212
|
+
* behavior supports optimizing pre/fetching of data for route transitions
|
|
213
|
+
* via data-only SSR modes.
|
|
214
|
+
*
|
|
215
|
+
* @param {ReadableStream} stream
|
|
216
|
+
* @return {Promise<void>}
|
|
217
|
+
* @public
|
|
218
|
+
*/
|
|
219
|
+
hydrate(stream: ReadableStream<unknown>): Promise<void>;
|
|
220
|
+
// Cache
|
|
221
|
+
// =====
|
|
222
|
+
// Resource Support
|
|
223
|
+
// ================
|
|
224
|
+
/**
|
|
225
|
+
* [LIFECYCLE] Signal to the cache that a new record has been instantiated on the client
|
|
226
|
+
*
|
|
227
|
+
* It returns properties from options that should be set on the record during the create
|
|
228
|
+
* process. This return value behavior is deprecated.
|
|
229
|
+
*
|
|
230
|
+
* @public
|
|
231
|
+
* @param identifier
|
|
232
|
+
* @param options
|
|
233
|
+
*/
|
|
234
|
+
clientDidCreate(identifier: StableRecordIdentifier, options?: Record<string, unknown>): Record<string, unknown>;
|
|
235
|
+
/**
|
|
236
|
+
* [LIFECYCLE] Signals to the cache that a resource
|
|
237
|
+
* will be part of a save transaction.
|
|
238
|
+
*
|
|
239
|
+
* @public
|
|
240
|
+
* @param identifier
|
|
241
|
+
*/
|
|
242
|
+
willCommit(identifier: StableRecordIdentifier, context: StoreRequestContext): void;
|
|
243
|
+
/**
|
|
244
|
+
* [LIFECYCLE] Signals to the cache that a resource
|
|
245
|
+
* was successfully updated as part of a save transaction.
|
|
246
|
+
*
|
|
247
|
+
* @public
|
|
248
|
+
* @param identifier
|
|
249
|
+
* @param data
|
|
250
|
+
*/
|
|
251
|
+
didCommit(identifier: StableRecordIdentifier, result: StructuredDataDocument<unknown>): SingleResourceDataDocument;
|
|
252
|
+
/**
|
|
253
|
+
* [LIFECYCLE] Signals to the cache that a resource
|
|
254
|
+
* was update via a save transaction failed.
|
|
255
|
+
*
|
|
256
|
+
* @public
|
|
257
|
+
* @param identifier
|
|
258
|
+
* @param errors
|
|
259
|
+
*/
|
|
260
|
+
commitWasRejected(identifier: StableRecordIdentifier, errors?: ApiError[]): void;
|
|
261
|
+
/**
|
|
262
|
+
* [LIFECYCLE] Signals to the cache that all data for a resource
|
|
263
|
+
* should be cleared.
|
|
264
|
+
*
|
|
265
|
+
* @public
|
|
266
|
+
* @param identifier
|
|
267
|
+
*/
|
|
268
|
+
unloadRecord(identifier: StableRecordIdentifier): void;
|
|
269
|
+
// Granular Resource Data APIs
|
|
270
|
+
// ===========================
|
|
271
|
+
/**
|
|
272
|
+
* Retrieve the data for an attribute from the cache
|
|
273
|
+
*
|
|
274
|
+
* @public
|
|
275
|
+
* @param identifier
|
|
276
|
+
* @param propertyName
|
|
277
|
+
* @return {unknown}
|
|
278
|
+
*/
|
|
279
|
+
getAttr(identifier: StableRecordIdentifier, propertyName: string): Value | undefined;
|
|
280
|
+
/**
|
|
281
|
+
* Retrieve the remote state for an attribute from the cache
|
|
282
|
+
*
|
|
283
|
+
* @public
|
|
284
|
+
* @param identifier
|
|
285
|
+
* @param propertyName
|
|
286
|
+
* @return {unknown}
|
|
287
|
+
*/
|
|
288
|
+
getRemoteAttr(identifier: StableRecordIdentifier, propertyName: string): Value | undefined;
|
|
289
|
+
/**
|
|
290
|
+
* Mutate the data for an attribute in the cache
|
|
291
|
+
*
|
|
292
|
+
* @public
|
|
293
|
+
* @param identifier
|
|
294
|
+
* @param propertyName
|
|
295
|
+
* @param value
|
|
296
|
+
*/
|
|
297
|
+
setAttr(identifier: StableRecordIdentifier, propertyName: string, value: Value): void;
|
|
298
|
+
/**
|
|
299
|
+
* Query the cache for the changed attributes of a resource.
|
|
300
|
+
*
|
|
301
|
+
* @public
|
|
302
|
+
* @param identifier
|
|
303
|
+
* @return
|
|
304
|
+
*/
|
|
305
|
+
changedAttrs(identifier: StableRecordIdentifier): ChangedAttributesHash;
|
|
306
|
+
/**
|
|
307
|
+
* Query the cache for whether any mutated attributes exist
|
|
308
|
+
*
|
|
309
|
+
* @public
|
|
310
|
+
* @param identifier
|
|
311
|
+
* @return {Boolean}
|
|
312
|
+
*/
|
|
313
|
+
hasChangedAttrs(identifier: StableRecordIdentifier): boolean;
|
|
314
|
+
/**
|
|
315
|
+
* Tell the cache to discard any uncommitted mutations to attributes
|
|
316
|
+
*
|
|
317
|
+
* @public
|
|
318
|
+
* @param identifier
|
|
319
|
+
* @return the names of attributes that were restored
|
|
320
|
+
*/
|
|
321
|
+
rollbackAttrs(identifier: StableRecordIdentifier): string[];
|
|
322
|
+
// Relationships
|
|
323
|
+
// =============
|
|
324
|
+
/**
|
|
325
|
+
* Query the cache for the changes to relationships of a resource.
|
|
326
|
+
*
|
|
327
|
+
* Returns a map of relationship names to RelationshipDiff objects.
|
|
328
|
+
*
|
|
329
|
+
* ```ts
|
|
330
|
+
* type RelationshipDiff =
|
|
331
|
+
| {
|
|
332
|
+
kind: 'collection';
|
|
333
|
+
remoteState: StableRecordIdentifier[];
|
|
334
|
+
additions: Set<StableRecordIdentifier>;
|
|
335
|
+
removals: Set<StableRecordIdentifier>;
|
|
336
|
+
localState: StableRecordIdentifier[];
|
|
337
|
+
reordered: boolean;
|
|
338
|
+
}
|
|
339
|
+
| {
|
|
340
|
+
kind: 'resource';
|
|
341
|
+
remoteState: StableRecordIdentifier | null;
|
|
342
|
+
localState: StableRecordIdentifier | null;
|
|
343
|
+
};
|
|
344
|
+
```
|
|
345
|
+
*
|
|
346
|
+
* @public
|
|
347
|
+
* @param {StableRecordIdentifier} identifier
|
|
348
|
+
* @return {Map<string, RelationshipDiff>}
|
|
349
|
+
*/
|
|
350
|
+
changedRelationships(identifier: StableRecordIdentifier): Map<string, RelationshipDiff>;
|
|
351
|
+
/**
|
|
352
|
+
* Query the cache for whether any mutated attributes exist
|
|
353
|
+
*
|
|
354
|
+
* @public
|
|
355
|
+
* @param {StableRecordIdentifier} identifier
|
|
356
|
+
* @return {Boolean}
|
|
357
|
+
*/
|
|
358
|
+
hasChangedRelationships(identifier: StableRecordIdentifier): boolean;
|
|
359
|
+
/**
|
|
360
|
+
* Tell the cache to discard any uncommitted mutations to relationships.
|
|
361
|
+
*
|
|
362
|
+
* This will also discard the change on any appropriate inverses.
|
|
363
|
+
*
|
|
364
|
+
* This method is a candidate to become a mutation
|
|
365
|
+
*
|
|
366
|
+
* @public
|
|
367
|
+
* @param {StableRecordIdentifier} identifier
|
|
368
|
+
* @return {String[]} the names of relationships that were restored
|
|
369
|
+
*/
|
|
370
|
+
rollbackRelationships(identifier: StableRecordIdentifier): string[];
|
|
371
|
+
/**
|
|
372
|
+
* Query the cache for the current state of a relationship property
|
|
373
|
+
*
|
|
374
|
+
* @public
|
|
375
|
+
* @param identifier
|
|
376
|
+
* @param propertyName
|
|
377
|
+
* @return resource relationship object
|
|
378
|
+
*/
|
|
379
|
+
getRelationship(identifier: StableRecordIdentifier, propertyName: string): ResourceRelationship | CollectionRelationship;
|
|
380
|
+
/**
|
|
381
|
+
* Query the cache for the remote state of a relationship property
|
|
382
|
+
*
|
|
383
|
+
* @public
|
|
384
|
+
* @param identifier
|
|
385
|
+
* @param propertyName
|
|
386
|
+
* @return resource relationship object
|
|
387
|
+
*/
|
|
388
|
+
getRemoteRelationship(identifier: StableRecordIdentifier, propertyName: string): ResourceRelationship | CollectionRelationship;
|
|
389
|
+
// Resource State
|
|
390
|
+
// ===============
|
|
391
|
+
/**
|
|
392
|
+
* Update the cache state for the given resource to be marked as locally deleted,
|
|
393
|
+
* or remove such a mark.
|
|
394
|
+
*
|
|
395
|
+
* @public
|
|
396
|
+
* @param identifier
|
|
397
|
+
* @param isDeleted
|
|
398
|
+
*/
|
|
399
|
+
setIsDeleted(identifier: StableRecordIdentifier, isDeleted: boolean): void;
|
|
400
|
+
/**
|
|
401
|
+
* Query the cache for any validation errors applicable to the given resource.
|
|
402
|
+
*
|
|
403
|
+
* @public
|
|
404
|
+
* @param identifier
|
|
405
|
+
* @return
|
|
406
|
+
*/
|
|
407
|
+
getErrors(identifier: StableRecordIdentifier): ApiError[];
|
|
408
|
+
/**
|
|
409
|
+
* Query the cache for whether a given resource has any available data
|
|
410
|
+
*
|
|
411
|
+
* @public
|
|
412
|
+
* @param identifier
|
|
413
|
+
* @return {Boolean}
|
|
414
|
+
*/
|
|
415
|
+
isEmpty(identifier: StableRecordIdentifier): boolean;
|
|
416
|
+
/**
|
|
417
|
+
* Query the cache for whether a given resource was created locally and not
|
|
418
|
+
* yet persisted.
|
|
419
|
+
*
|
|
420
|
+
* @public
|
|
421
|
+
* @param identifier
|
|
422
|
+
* @return {Boolean}
|
|
423
|
+
*/
|
|
424
|
+
isNew(identifier: StableRecordIdentifier): boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Query the cache for whether a given resource is marked as deleted (but not
|
|
427
|
+
* necessarily persisted yet).
|
|
428
|
+
*
|
|
429
|
+
* @public
|
|
430
|
+
* @param identifier
|
|
431
|
+
* @return {Boolean}
|
|
432
|
+
*/
|
|
433
|
+
isDeleted(identifier: StableRecordIdentifier): boolean;
|
|
434
|
+
/**
|
|
435
|
+
* Query the cache for whether a given resource has been deleted and that deletion
|
|
436
|
+
* has also been persisted.
|
|
437
|
+
*
|
|
438
|
+
* @public
|
|
439
|
+
* @param identifier
|
|
440
|
+
* @return {Boolean}
|
|
441
|
+
*/
|
|
442
|
+
isDeletionCommitted(identifier: StableRecordIdentifier): boolean;
|
|
443
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { StableDocumentIdentifier, StableRecordIdentifier } from "../../../types/identifier.js";
|
|
2
|
+
import type { Store } from "../store-service.js";
|
|
3
|
+
export type UnsubscribeToken = object;
|
|
4
|
+
export type CacheOperation = "added" | "removed" | "updated" | "state";
|
|
5
|
+
export type DocumentCacheOperation = "invalidated" | "added" | "removed" | "updated" | "state";
|
|
6
|
+
export type NotificationType = "attributes" | "relationships" | "identity" | "errors" | "meta" | CacheOperation;
|
|
7
|
+
export interface NotificationCallback {
|
|
8
|
+
(identifier: StableRecordIdentifier, notificationType: "attributes" | "relationships", key?: string): void;
|
|
9
|
+
(identifier: StableRecordIdentifier, notificationType: "errors" | "meta" | "identity" | "state"): void;
|
|
10
|
+
(identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
|
|
11
|
+
}
|
|
12
|
+
export interface ResourceOperationCallback {
|
|
13
|
+
// resource updates
|
|
14
|
+
(identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
|
|
15
|
+
}
|
|
16
|
+
export interface DocumentOperationCallback {
|
|
17
|
+
// document updates
|
|
18
|
+
(identifier: StableDocumentIdentifier, notificationType: DocumentCacheOperation): void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The NotificationManager provides the ability to subscribe to
|
|
22
|
+
* changes to Cache state.
|
|
23
|
+
*
|
|
24
|
+
* This Feature is what allows WarpDrive to create subscriptions that
|
|
25
|
+
* work with any framework or change-notification system.
|
|
26
|
+
*
|
|
27
|
+
* @hideconstructor
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export default class NotificationManager {
|
|
31
|
+
/** @internal */
|
|
32
|
+
private store;
|
|
33
|
+
/** @internal */
|
|
34
|
+
private isDestroyed;
|
|
35
|
+
/** @internal */
|
|
36
|
+
private _buffered;
|
|
37
|
+
/** @internal */
|
|
38
|
+
private _cache;
|
|
39
|
+
/** @internal */
|
|
40
|
+
private _hasFlush;
|
|
41
|
+
/** @internal */
|
|
42
|
+
private _onFlushCB?;
|
|
43
|
+
constructor(store: Store);
|
|
44
|
+
/**
|
|
45
|
+
* Subscribe to changes for a given resource identifier, resource addition/removal, or document addition/removal.
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* export type CacheOperation = 'added' | 'removed' | 'updated' | 'state';
|
|
49
|
+
*
|
|
50
|
+
* export interface NotificationCallback {
|
|
51
|
+
* (identifier: StableRecordIdentifier, notificationType: 'attributes' | 'relationships', key?: string): void;
|
|
52
|
+
* (identifier: StableRecordIdentifier, notificationType: 'errors' | 'meta' | 'identity' | 'state'): void;
|
|
53
|
+
* (identifier: StableRecordIdentifier, notificationType: NotificationType, key?: string): void;
|
|
54
|
+
* }
|
|
55
|
+
* export interface ResourceOperationCallback {
|
|
56
|
+
* // resource updates
|
|
57
|
+
* (identifier: StableRecordIdentifier, notificationType: CacheOperation): void;
|
|
58
|
+
* }
|
|
59
|
+
* export interface DocumentOperationCallback {
|
|
60
|
+
* // document updates
|
|
61
|
+
* (identifier: StableDocumentIdentifier, notificationType: CacheOperation): void;
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
* @param {StableDocumentIdentifier | StableRecordIdentifier | 'resource' | 'document'} identifier
|
|
67
|
+
* @param {NotificationCallback | ResourceOperationCallback | DocumentOperationCallback} callback
|
|
68
|
+
* @return {UnsubscribeToken} an opaque token to be used with unsubscribe
|
|
69
|
+
*/
|
|
70
|
+
subscribe(identifier: StableRecordIdentifier, callback: NotificationCallback): UnsubscribeToken;
|
|
71
|
+
subscribe(identifier: "resource", callback: ResourceOperationCallback): UnsubscribeToken;
|
|
72
|
+
subscribe(identifier: "document" | StableDocumentIdentifier, callback: DocumentOperationCallback): UnsubscribeToken;
|
|
73
|
+
/**
|
|
74
|
+
* remove a previous subscription
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
unsubscribe(token: UnsubscribeToken): void;
|
|
79
|
+
/**
|
|
80
|
+
* Custom Caches and Application Code should not call this method directly.
|
|
81
|
+
*
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
notify(identifier: StableRecordIdentifier, value: "attributes" | "relationships", key?: string): boolean;
|
|
85
|
+
notify(identifier: StableRecordIdentifier, value: "errors" | "meta" | "identity" | "state"): boolean;
|
|
86
|
+
notify(identifier: StableRecordIdentifier, value: CacheOperation): boolean;
|
|
87
|
+
notify(identifier: StableDocumentIdentifier, value: DocumentCacheOperation): boolean;
|
|
88
|
+
/** @internal */
|
|
89
|
+
_onNextFlush(cb: () => void): void;
|
|
90
|
+
private _scheduleNotify;
|
|
91
|
+
/** @internal */
|
|
92
|
+
_flush(): void;
|
|
93
|
+
private _flushNotification;
|
|
94
|
+
private _flushNotification;
|
|
95
|
+
private _flushNotification;
|
|
96
|
+
/** @internal */
|
|
97
|
+
destroy(): void;
|
|
98
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { LocalRelationshipOperation } from "../../../types/graph.js";
|
|
2
|
+
import type { StableDocumentIdentifier, StableRecordIdentifier } from "../../../types/identifier.js";
|
|
3
|
+
import type { ImmutableRequestInfo } from "../../../types/request.js";
|
|
4
|
+
import type { CollectionResourceDocument } from "../../../types/spec/json-api-raw.js";
|
|
5
|
+
import { Collection, IdentifierArray } from "../record-arrays/identifier-array.js";
|
|
6
|
+
import type { Store } from "../store-service.js";
|
|
7
|
+
import type { UnsubscribeToken } from "./notification-manager.js";
|
|
8
|
+
/**
|
|
9
|
+
* This is a clever optimization.
|
|
10
|
+
*
|
|
11
|
+
* clever optimizations rarely stand the test of time, so if you're
|
|
12
|
+
* ever curious or think something better is possible please benchmark
|
|
13
|
+
* and discuss. The benchmark for this at the time of writing is in
|
|
14
|
+
* `scripts/benchmark-push.js`
|
|
15
|
+
*
|
|
16
|
+
* This approach turns out to be 150x faster in Chrome and node than
|
|
17
|
+
* simply using push or concat. It's highly susceptible to the specifics
|
|
18
|
+
* of the batch size, and may require tuning.
|
|
19
|
+
*
|
|
20
|
+
* Clever optimizations should always come with a `why`. This optimization
|
|
21
|
+
* exists for two reasons.
|
|
22
|
+
*
|
|
23
|
+
* 1) array.push(...objects) and Array.prototype.push.apply(arr, objects)
|
|
24
|
+
* are susceptible to stack overflows. The size of objects at which this
|
|
25
|
+
* occurs varies by environment, browser, and current stack depth and memory
|
|
26
|
+
* pressure; however, it occurs in all browsers in fairly pristine conditions
|
|
27
|
+
* somewhere around 125k to 200k elements. Since WarpDrive regularly encounters
|
|
28
|
+
* arrays larger than this in size, we cannot use push.
|
|
29
|
+
*
|
|
30
|
+
* 2) `array.concat` or simply setting the array to a new reference is often an
|
|
31
|
+
* easier approach; however, native Proxy to an array cannot swap it's target array
|
|
32
|
+
* and attempts at juggling multiple array sources have proven to be victim to a number
|
|
33
|
+
* of browser implementation bugs. Should these bugs be addressed then we could
|
|
34
|
+
* simplify to using `concat`, however, do note this is currently 150x faster
|
|
35
|
+
* than concat, and due to the overloaded signature of concat will likely always
|
|
36
|
+
* be faster.
|
|
37
|
+
*
|
|
38
|
+
* Sincerely,
|
|
39
|
+
* - runspired (Chris Thoburn) 08/21/2022
|
|
40
|
+
*
|
|
41
|
+
* @function fastPush
|
|
42
|
+
* @internal
|
|
43
|
+
* @param target the array to push into
|
|
44
|
+
* @param source the items to push into target
|
|
45
|
+
*/
|
|
46
|
+
export declare function fastPush<T>(target: T[], source: T[]): void;
|
|
47
|
+
type ChangeSet = Map<StableRecordIdentifier, "add" | "del">;
|
|
48
|
+
/**
|
|
49
|
+
@class RecordArrayManager
|
|
50
|
+
@internal
|
|
51
|
+
*/
|
|
52
|
+
export declare class RecordArrayManager {
|
|
53
|
+
store: Store;
|
|
54
|
+
isDestroying: boolean;
|
|
55
|
+
isDestroyed: boolean;
|
|
56
|
+
_set: Map<IdentifierArray, Set<StableRecordIdentifier>>;
|
|
57
|
+
_live: Map<string, IdentifierArray>;
|
|
58
|
+
_managed: Set<IdentifierArray>;
|
|
59
|
+
_pending: Map<IdentifierArray, ChangeSet>;
|
|
60
|
+
_identifiers: Map<StableRecordIdentifier, Set<Collection>>;
|
|
61
|
+
_staged: Map<string, ChangeSet>;
|
|
62
|
+
_subscription: UnsubscribeToken;
|
|
63
|
+
_documentSubscription: UnsubscribeToken;
|
|
64
|
+
_keyedArrays: Map<string, Collection>;
|
|
65
|
+
_visibilitySet: Map<StableRecordIdentifier, boolean>;
|
|
66
|
+
constructor(options: {
|
|
67
|
+
store: Store;
|
|
68
|
+
});
|
|
69
|
+
_syncArray(array: IdentifierArray | Collection): void;
|
|
70
|
+
mutate(mutation: LocalRelationshipOperation): void;
|
|
71
|
+
/**
|
|
72
|
+
Get the `RecordArray` for a modelName, which contains all loaded records of
|
|
73
|
+
given modelName.
|
|
74
|
+
|
|
75
|
+
@internal
|
|
76
|
+
@param {String} modelName
|
|
77
|
+
@return {RecordArray}
|
|
78
|
+
*/
|
|
79
|
+
liveArrayFor(type: string): IdentifierArray;
|
|
80
|
+
getCollection(config: {
|
|
81
|
+
type?: string;
|
|
82
|
+
query?: ImmutableRequestInfo | Record<string, unknown>;
|
|
83
|
+
identifiers?: StableRecordIdentifier[];
|
|
84
|
+
doc?: CollectionResourceDocument;
|
|
85
|
+
identifier?: StableDocumentIdentifier | null;
|
|
86
|
+
}): Collection;
|
|
87
|
+
dirtyArray(array: IdentifierArray, delta: number, shouldSyncFromCache: boolean): void;
|
|
88
|
+
_getPendingFor(identifier: StableRecordIdentifier, includeManaged: boolean, isRemove?: boolean): Map<IdentifierArray, ChangeSet> | void;
|
|
89
|
+
populateManagedArray(array: Collection, identifiers: StableRecordIdentifier[], payload: CollectionResourceDocument | null): void;
|
|
90
|
+
identifierAdded(identifier: StableRecordIdentifier): void;
|
|
91
|
+
identifierRemoved(identifier: StableRecordIdentifier): void;
|
|
92
|
+
identifierChanged(identifier: StableRecordIdentifier): void;
|
|
93
|
+
clear(isClear?: boolean): void;
|
|
94
|
+
destroy(): void;
|
|
95
|
+
}
|
|
96
|
+
export declare function disassociateIdentifier(ArraysCache: Map<StableRecordIdentifier, Set<Collection>>, array: Collection, identifier: StableRecordIdentifier): void;
|
|
97
|
+
export {};
|