@warp-drive/core 5.6.0-alpha.17 → 5.6.0-alpha.5

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 (219) hide show
  1. package/README.md +7 -8
  2. package/declarations/index.d.ts +3 -14
  3. package/declarations/index.d.ts.map +1 -0
  4. package/declarations/request/-private/context.d.ts +35 -34
  5. package/declarations/request/-private/context.d.ts.map +1 -0
  6. package/declarations/request/-private/debug.d.ts +3 -2
  7. package/declarations/request/-private/debug.d.ts.map +1 -0
  8. package/declarations/request/-private/fetch.d.ts +36 -24
  9. package/declarations/request/-private/fetch.d.ts.map +1 -0
  10. package/declarations/request/-private/future.d.ts +4 -3
  11. package/declarations/request/-private/future.d.ts.map +1 -0
  12. package/declarations/request/-private/manager.d.ts +132 -159
  13. package/declarations/request/-private/manager.d.ts.map +1 -0
  14. package/declarations/request/-private/promise-cache.d.ts +13 -21
  15. package/declarations/request/-private/promise-cache.d.ts.map +1 -0
  16. package/declarations/request/-private/types.d.ts +123 -124
  17. package/declarations/request/-private/types.d.ts.map +1 -0
  18. package/declarations/request/-private/utils.d.ts +9 -8
  19. package/declarations/request/-private/utils.d.ts.map +1 -0
  20. package/declarations/request.d.ts +433 -5
  21. package/declarations/request.d.ts.map +1 -0
  22. package/declarations/types/-private.d.ts +8 -16
  23. package/declarations/types/-private.d.ts.map +1 -0
  24. package/declarations/types/cache/aliases.d.ts +1 -11
  25. package/declarations/types/cache/aliases.d.ts.map +1 -0
  26. package/declarations/types/cache/change.d.ts +5 -4
  27. package/declarations/types/cache/change.d.ts.map +1 -0
  28. package/declarations/types/cache/mutations.d.ts +28 -51
  29. package/declarations/types/cache/mutations.d.ts.map +1 -0
  30. package/declarations/types/cache/operations.d.ts +47 -60
  31. package/declarations/types/cache/operations.d.ts.map +1 -0
  32. package/declarations/types/cache/relationship.d.ts +9 -11
  33. package/declarations/types/cache/relationship.d.ts.map +1 -0
  34. package/declarations/types/cache.d.ts +484 -495
  35. package/declarations/types/cache.d.ts.map +1 -0
  36. package/declarations/types/graph.d.ts +40 -31
  37. package/declarations/types/graph.d.ts.map +1 -0
  38. package/declarations/types/identifier.d.ts +82 -83
  39. package/declarations/types/identifier.d.ts.map +1 -0
  40. package/declarations/types/json/raw.d.ts +2 -1
  41. package/declarations/types/json/raw.d.ts.map +1 -0
  42. package/declarations/types/params.d.ts +5 -4
  43. package/declarations/types/params.d.ts.map +1 -0
  44. package/declarations/types/record.d.ts +76 -117
  45. package/declarations/types/record.d.ts.map +1 -0
  46. package/declarations/types/record.type-test.d.ts +2 -0
  47. package/declarations/types/record.type-test.d.ts.map +1 -0
  48. package/declarations/types/request.d.ts +266 -289
  49. package/declarations/types/request.d.ts.map +1 -0
  50. package/declarations/types/request.type-test.d.ts +2 -0
  51. package/declarations/types/request.type-test.d.ts.map +1 -0
  52. package/declarations/types/runtime.d.ts +9 -8
  53. package/declarations/types/runtime.d.ts.map +1 -0
  54. package/declarations/types/schema/concepts.d.ts +13 -19
  55. package/declarations/types/schema/concepts.d.ts.map +1 -0
  56. package/declarations/types/schema/fields.d.ts +1741 -1712
  57. package/declarations/types/schema/fields.d.ts.map +1 -0
  58. package/declarations/types/schema/fields.type-test.d.ts +1 -0
  59. package/declarations/types/schema/fields.type-test.d.ts.map +1 -0
  60. package/declarations/types/spec/document.d.ts +22 -28
  61. package/declarations/types/spec/document.d.ts.map +1 -0
  62. package/declarations/types/spec/error.d.ts +17 -16
  63. package/declarations/types/spec/error.d.ts.map +1 -0
  64. package/declarations/types/spec/json-api-raw.d.ts +102 -102
  65. package/declarations/types/spec/json-api-raw.d.ts.map +1 -0
  66. package/declarations/types/symbols.d.ts +75 -74
  67. package/declarations/types/symbols.d.ts.map +1 -0
  68. package/declarations/types/utils.d.ts +5 -5
  69. package/declarations/types/utils.d.ts.map +1 -0
  70. package/declarations/types.d.ts +7 -10
  71. package/declarations/types.d.ts.map +1 -0
  72. package/dist/{context-COmAnXUQ.js → context-DE5sFezZ.js} +2 -2
  73. package/dist/context-DE5sFezZ.js.map +1 -0
  74. package/dist/index.js +104 -37
  75. package/dist/index.js.map +1 -0
  76. package/dist/request.js +1 -1
  77. package/dist/request.js.map +1 -0
  78. package/dist/types/-private.js +3 -3
  79. package/dist/types/-private.js.map +1 -0
  80. package/dist/types/cache/aliases.js.map +1 -0
  81. package/dist/types/cache/change.js.map +1 -0
  82. package/dist/types/cache/mutations.js.map +1 -0
  83. package/dist/types/cache/operations.js.map +1 -0
  84. package/dist/types/cache/relationship.js.map +1 -0
  85. package/dist/types/cache.js.map +1 -0
  86. package/dist/types/graph.js.map +1 -0
  87. package/dist/types/identifier.js.map +1 -0
  88. package/dist/types/json/raw.js.map +1 -0
  89. package/dist/types/params.js.map +1 -0
  90. package/dist/types/record.js +1 -1
  91. package/dist/types/record.js.map +1 -0
  92. package/dist/types/request.js +2 -2
  93. package/dist/types/request.js.map +1 -0
  94. package/dist/types/runtime.js +1 -1
  95. package/dist/types/runtime.js.map +1 -0
  96. package/dist/types/schema/concepts.js.map +1 -0
  97. package/dist/types/schema/fields.js +41 -8
  98. package/dist/types/schema/fields.js.map +1 -0
  99. package/dist/types/schema/fields.type-test.js.map +1 -0
  100. package/dist/types/spec/document.js.map +1 -0
  101. package/dist/types/spec/error.js.map +1 -0
  102. package/dist/types/spec/json-api-raw.js.map +1 -0
  103. package/dist/types/symbols.js +3 -3
  104. package/dist/types/symbols.js.map +1 -0
  105. package/dist/types/utils.js.map +1 -0
  106. package/dist/types.js.map +1 -0
  107. package/package.json +8 -11
  108. package/cjs-dist/addon-shim.cjs +0 -1
  109. package/cjs-dist/cjs-set-config.cjs +0 -1
  110. package/declarations/build-config/babel-macros.d.ts +0 -1
  111. package/declarations/build-config/canary-features.d.ts +0 -1
  112. package/declarations/build-config/debugging.d.ts +0 -1
  113. package/declarations/build-config/deprecations.d.ts +0 -1
  114. package/declarations/build-config/env.d.ts +0 -1
  115. package/declarations/build-config/macros.d.ts +0 -1
  116. package/declarations/build-config.d.ts +0 -1
  117. package/declarations/configure.d.ts +0 -7
  118. package/declarations/graph/-private/-diff.d.ts +0 -32
  119. package/declarations/graph/-private/-edge-definition.d.ts +0 -148
  120. package/declarations/graph/-private/-state.d.ts +0 -96
  121. package/declarations/graph/-private/-utils.d.ts +0 -31
  122. package/declarations/graph/-private/coerce-id.d.ts +0 -10
  123. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +0 -18
  124. package/declarations/graph/-private/edges/collection.d.ts +0 -39
  125. package/declarations/graph/-private/edges/implicit.d.ts +0 -43
  126. package/declarations/graph/-private/edges/resource.d.ts +0 -24
  127. package/declarations/graph/-private/graph.d.ts +0 -90
  128. package/declarations/graph/-private/normalize-link.d.ts +0 -8
  129. package/declarations/graph/-private/operations/add-to-related-records.d.ts +0 -4
  130. package/declarations/graph/-private/operations/merge-identifier.d.ts +0 -3
  131. package/declarations/graph/-private/operations/remove-from-related-records.d.ts +0 -4
  132. package/declarations/graph/-private/operations/replace-related-record.d.ts +0 -3
  133. package/declarations/graph/-private/operations/replace-related-records.d.ts +0 -62
  134. package/declarations/graph/-private/operations/update-relationship.d.ts +0 -13
  135. package/declarations/graph/-private.d.ts +0 -13
  136. package/declarations/reactive/-private/document.d.ts +0 -146
  137. package/declarations/reactive/-private/fields/compute.d.ts +0 -43
  138. package/declarations/reactive/-private/fields/extension.d.ts +0 -8
  139. package/declarations/reactive/-private/fields/managed-array.d.ts +0 -22
  140. package/declarations/reactive/-private/fields/managed-object.d.ts +0 -21
  141. package/declarations/reactive/-private/fields/many-array-manager.d.ts +0 -19
  142. package/declarations/reactive/-private/hooks.d.ts +0 -5
  143. package/declarations/reactive/-private/record.d.ts +0 -64
  144. package/declarations/reactive/-private/schema.d.ts +0 -271
  145. package/declarations/reactive/-private/symbols.d.ts +0 -36
  146. package/declarations/reactive/-private.d.ts +0 -1
  147. package/declarations/reactive.d.ts +0 -4
  148. package/declarations/store/-private/cache-handler/handler.d.ts +0 -62
  149. package/declarations/store/-private/cache-handler/types.d.ts +0 -98
  150. package/declarations/store/-private/cache-handler/utils.d.ts +0 -32
  151. package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
  152. package/declarations/store/-private/caches/identifier-cache.d.ts +0 -304
  153. package/declarations/store/-private/caches/instance-cache.d.ts +0 -65
  154. package/declarations/store/-private/caches/resource-utils.d.ts +0 -9
  155. package/declarations/store/-private/debug/utils.d.ts +0 -6
  156. package/declarations/store/-private/default-cache-policy.d.ts +0 -384
  157. package/declarations/store/-private/legacy-model-support/record-reference.d.ts +0 -159
  158. package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +0 -17
  159. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +0 -25
  160. package/declarations/store/-private/managers/cache-manager.d.ts +0 -443
  161. package/declarations/store/-private/managers/notification-manager.d.ts +0 -98
  162. package/declarations/store/-private/managers/record-array-manager.d.ts +0 -97
  163. package/declarations/store/-private/network/request-cache.d.ts +0 -107
  164. package/declarations/store/-private/new-core-tmp/promise-state.d.ts +0 -263
  165. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +0 -176
  166. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +0 -169
  167. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +0 -35
  168. package/declarations/store/-private/new-core-tmp/request-state.d.ts +0 -277
  169. package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +0 -261
  170. package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
  171. package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
  172. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +0 -126
  173. package/declarations/store/-private/store-service.d.ts +0 -1605
  174. package/declarations/store/-private/utils/coerce-id.d.ts +0 -10
  175. package/declarations/store/-private/utils/construct-resource.d.ts +0 -6
  176. package/declarations/store/-private/utils/is-non-empty-string.d.ts +0 -1
  177. package/declarations/store/-private/utils/normalize-model-name.d.ts +0 -1
  178. package/declarations/store/-private/utils/uuid-polyfill.d.ts +0 -1
  179. package/declarations/store/-private.d.ts +0 -31
  180. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +0 -99
  181. package/declarations/store/-types/q/ds-model.d.ts +0 -21
  182. package/declarations/store/-types/q/identifier.d.ts +0 -20
  183. package/declarations/store/-types/q/record-instance.d.ts +0 -23
  184. package/declarations/store/-types/q/schema-service.d.ts +0 -354
  185. package/declarations/store/-types/q/store.d.ts +0 -32
  186. package/declarations/store.d.ts +0 -1
  187. package/declarations/utils/string.d.ts +0 -48
  188. package/dist/build-config/babel-macros.js +0 -1
  189. package/dist/build-config/canary-features.js +0 -1
  190. package/dist/build-config/debugging.js +0 -1
  191. package/dist/build-config/deprecations.js +0 -1
  192. package/dist/build-config/env.js +0 -1
  193. package/dist/build-config/macros.js +0 -1
  194. package/dist/build-config.js +0 -1
  195. package/dist/configure-B48bFHOl.js +0 -181
  196. package/dist/configure.js +0 -1
  197. package/dist/graph/-private.js +0 -3372
  198. package/dist/handler-C2T-IyJK.js +0 -339
  199. package/dist/reactive/-private.js +0 -1
  200. package/dist/reactive.js +0 -1988
  201. package/dist/request-state-CjLph1LP.js +0 -8139
  202. package/dist/store/-private.js +0 -3
  203. package/dist/store.js +0 -545
  204. package/dist/symbols-SIstXMLI.js +0 -44
  205. package/dist/utils/string.js +0 -92
  206. package/logos/NCC-1701-a-blue.svg +0 -4
  207. package/logos/NCC-1701-a-gold.svg +0 -4
  208. package/logos/NCC-1701-a-gold_100.svg +0 -1
  209. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  210. package/logos/NCC-1701-a.svg +0 -4
  211. package/logos/README.md +0 -4
  212. package/logos/docs-badge.svg +0 -2
  213. package/logos/ember-data-logo-dark.svg +0 -12
  214. package/logos/ember-data-logo-light.svg +0 -12
  215. package/logos/github-header.svg +0 -444
  216. package/logos/social1.png +0 -0
  217. package/logos/social2.png +0 -0
  218. package/logos/warp-drive-logo-dark.svg +0 -4
  219. package/logos/warp-drive-logo-gold.svg +0 -4
@@ -1,443 +0,0 @@
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
- }
@@ -1,98 +0,0 @@
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
- }
@@ -1,97 +0,0 @@
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 {};