@warp-drive/core-types 0.0.0-alpha.15 → 0.0.0-alpha.17

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 (39) hide show
  1. package/addon/symbols.js +20 -1
  2. package/addon/symbols.js.map +1 -1
  3. package/package.json +5 -4
  4. package/unstable-preview-types/cache/aliases.d.ts +2 -0
  5. package/unstable-preview-types/cache/aliases.d.ts.map +1 -0
  6. package/unstable-preview-types/cache/change.d.ts +7 -0
  7. package/unstable-preview-types/cache/change.d.ts.map +1 -0
  8. package/unstable-preview-types/cache/mutations.d.ts +39 -0
  9. package/unstable-preview-types/cache/mutations.d.ts.map +1 -0
  10. package/unstable-preview-types/cache/operations.d.ts +15 -0
  11. package/unstable-preview-types/cache/operations.d.ts.map +1 -0
  12. package/unstable-preview-types/cache/relationship.d.ts +14 -0
  13. package/unstable-preview-types/cache/relationship.d.ts.map +1 -0
  14. package/unstable-preview-types/cache.d.ts +475 -0
  15. package/unstable-preview-types/cache.d.ts.map +1 -0
  16. package/unstable-preview-types/graph.d.ts +68 -0
  17. package/unstable-preview-types/graph.d.ts.map +1 -0
  18. package/unstable-preview-types/identifier.d.ts +109 -0
  19. package/unstable-preview-types/identifier.d.ts.map +1 -0
  20. package/unstable-preview-types/index.d.ts +2 -0
  21. package/unstable-preview-types/index.d.ts.map +1 -0
  22. package/unstable-preview-types/json/raw.d.ts +7 -0
  23. package/unstable-preview-types/json/raw.d.ts.map +1 -0
  24. package/unstable-preview-types/params.d.ts +7 -0
  25. package/unstable-preview-types/params.d.ts.map +1 -0
  26. package/unstable-preview-types/record.d.ts +46 -0
  27. package/unstable-preview-types/record.d.ts.map +1 -0
  28. package/unstable-preview-types/request.d.ts +307 -0
  29. package/unstable-preview-types/request.d.ts.map +1 -0
  30. package/unstable-preview-types/schema.d.ts +24 -0
  31. package/unstable-preview-types/schema.d.ts.map +1 -0
  32. package/unstable-preview-types/spec/document.d.ts +31 -0
  33. package/unstable-preview-types/spec/document.d.ts.map +1 -0
  34. package/unstable-preview-types/spec/error.d.ts +19 -0
  35. package/unstable-preview-types/spec/error.d.ts.map +1 -0
  36. package/unstable-preview-types/spec/raw.d.ts +133 -0
  37. package/unstable-preview-types/spec/raw.d.ts.map +1 -0
  38. package/unstable-preview-types/symbols.d.ts +35 -0
  39. package/unstable-preview-types/symbols.d.ts.map +1 -0
package/addon/symbols.js CHANGED
@@ -18,4 +18,23 @@ const RecordStore = Symbol('Store');
18
18
  * @typedoc
19
19
  */
20
20
  const ResourceType = Symbol('$type');
21
- export { RecordStore, ResourceType };
21
+
22
+ /**
23
+ * Symbol for the name of a transform.
24
+ *
25
+ * This is an optional feature that can be used by
26
+ * transform implementations to provide a typescript
27
+ * hint for the name of the transform.
28
+ *
29
+ * If not used, `attr<Transform>('name')` will
30
+ * allow any string name. `attr('name')` will always
31
+ * allow any string name.
32
+ *
33
+ * If used, `attr<Transform>('name')` will enforce
34
+ * that the name is the same as the transform name.
35
+ *
36
+ * @type {Symbol}
37
+ * @typedoc
38
+ */
39
+ const TransformName = Symbol('$TransformName');
40
+ export { RecordStore, ResourceType, TransformName };
@@ -1 +1 @@
1
- {"version":3,"file":"symbols.js","sources":["../src/symbols.ts"],"sourcesContent":["/*\n * @module @warp-drive/core-types\n */\nexport const RecordStore = Symbol('Store');\n\n/**\n * Symbol for the type of a resource.\n *\n * This is an optional feature that can be used by\n * record implementations to provide a typescript\n * hint for the type of the resource.\n *\n * When used, EmberData and WarpDrive APIs can\n * take advantage of this to provide better type\n * safety and intellisense.\n *\n * @type {Symbol}\n * @typedoc\n */\nexport const ResourceType = Symbol('$type');\n"],"names":["RecordStore","Symbol","ResourceType"],"mappings":"AAAA;AACA;AACA;MACaA,WAAW,GAAGC,MAAM,CAAC,OAAO,EAAC;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaC,YAAY,GAAGD,MAAM,CAAC,OAAO;;;;"}
1
+ {"version":3,"file":"symbols.js","sources":["../src/symbols.ts"],"sourcesContent":["/*\n * @module @warp-drive/core-types\n */\nexport const RecordStore = Symbol('Store');\n\n/**\n * Symbol for the type of a resource.\n *\n * This is an optional feature that can be used by\n * record implementations to provide a typescript\n * hint for the type of the resource.\n *\n * When used, EmberData and WarpDrive APIs can\n * take advantage of this to provide better type\n * safety and intellisense.\n *\n * @type {Symbol}\n * @typedoc\n */\nexport const ResourceType = Symbol('$type');\n\n/**\n * Symbol for the name of a transform.\n *\n * This is an optional feature that can be used by\n * transform implementations to provide a typescript\n * hint for the name of the transform.\n *\n * If not used, `attr<Transform>('name')` will\n * allow any string name. `attr('name')` will always\n * allow any string name.\n *\n * If used, `attr<Transform>('name')` will enforce\n * that the name is the same as the transform name.\n *\n * @type {Symbol}\n * @typedoc\n */\nexport const TransformName = Symbol('$TransformName');\n"],"names":["RecordStore","Symbol","ResourceType","TransformName"],"mappings":"AAAA;AACA;AACA;MACaA,WAAW,GAAGC,MAAM,CAAC,OAAO,EAAC;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaC,YAAY,GAAGD,MAAM,CAAC,OAAO,EAAC;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaE,aAAa,GAAGF,MAAM,CAAC,gBAAgB;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warp-drive/core-types",
3
- "version": "0.0.0-alpha.15",
3
+ "version": "0.0.0-alpha.17",
4
4
  "description": "Provides core logic, utils and types for WarpDrive and EmberData",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -15,13 +15,14 @@
15
15
  "files": [
16
16
  "addon",
17
17
  "addon-main.cjs",
18
+ "unstable-preview-types",
18
19
  "README.md",
19
20
  "LICENSE.md",
20
21
  "NCC-1701-a.svg",
21
22
  "NCC-1701-a-blue.svg"
22
23
  ],
23
24
  "dependencies": {
24
- "@ember-data/private-build-infra": "5.4.0-alpha.29",
25
+ "@ember-data/private-build-infra": "5.4.0-alpha.31",
25
26
  "ember-cli-babel": "^8.2.0",
26
27
  "pnpm-sync-dependencies-meta-injected": "0.0.10"
27
28
  },
@@ -45,7 +46,7 @@
45
46
  "@glimmer/component": "^1.1.2",
46
47
  "@rollup/plugin-babel": "^6.0.4",
47
48
  "@rollup/plugin-node-resolve": "^15.2.3",
48
- "@warp-drive/internal-config": "5.4.0-alpha.29",
49
+ "@warp-drive/internal-config": "5.4.0-alpha.31",
49
50
  "ember-source": "~5.6.0",
50
51
  "rollup": "^4.9.6",
51
52
  "typescript": "^5.3.3",
@@ -69,7 +70,7 @@
69
70
  },
70
71
  "scripts": {
71
72
  "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives",
72
- "build:types": "echo \"Types are private\" && exit 0",
73
+ "build:types": "tsc --build",
73
74
  "build:client": "rollup --config && babel ./addon --out-dir addon --plugins=../private-build-infra/src/transforms/babel-plugin-transform-ext.js",
74
75
  "_build": "bun run build:client && bun run build:types",
75
76
  "_syncPnpm": "bun run sync-dependencies-meta-injected"
@@ -0,0 +1,2 @@
1
+ export type ResourceBlob = unknown;
2
+ //# sourceMappingURL=aliases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../../src/cache/aliases.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { StableDocumentIdentifier, StableRecordIdentifier } from '../identifier';
2
+ export interface Change {
3
+ identifier: StableRecordIdentifier | StableDocumentIdentifier;
4
+ op: 'upsert' | 'remove';
5
+ patch?: unknown;
6
+ }
7
+ //# sourceMappingURL=change.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"change.d.ts","sourceRoot":"","sources":["../../src/cache/change.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEtF,MAAM,WAAW,MAAM;IACrB,UAAU,EAAE,sBAAsB,GAAG,wBAAwB,CAAC;IAC9D,EAAE,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
@@ -0,0 +1,39 @@
1
+ import type { StableRecordIdentifier } from '../identifier';
2
+ export interface AddToRelatedRecordsMutation {
3
+ op: 'addToRelatedRecords';
4
+ record: StableRecordIdentifier;
5
+ field: string;
6
+ value: StableRecordIdentifier | StableRecordIdentifier[];
7
+ index?: number;
8
+ }
9
+ export interface RemoveFromRelatedRecordsMutation {
10
+ op: 'removeFromRelatedRecords';
11
+ record: StableRecordIdentifier;
12
+ field: string;
13
+ value: StableRecordIdentifier | StableRecordIdentifier[];
14
+ index?: number;
15
+ }
16
+ export interface ReplaceRelatedRecordMutation {
17
+ op: 'replaceRelatedRecord';
18
+ record: StableRecordIdentifier;
19
+ field: string;
20
+ value: StableRecordIdentifier | null;
21
+ prior?: StableRecordIdentifier;
22
+ index?: number;
23
+ }
24
+ export interface ReplaceRelatedRecordsMutation {
25
+ op: 'replaceRelatedRecords';
26
+ record: StableRecordIdentifier;
27
+ field: string;
28
+ value: StableRecordIdentifier[];
29
+ prior?: StableRecordIdentifier[];
30
+ index?: number;
31
+ }
32
+ export interface SortRelatedRecordsMutation {
33
+ op: 'sortRelatedRecords';
34
+ record: StableRecordIdentifier;
35
+ field: string;
36
+ value: StableRecordIdentifier[];
37
+ }
38
+ export type Mutation = ReplaceRelatedRecordsMutation | ReplaceRelatedRecordMutation | RemoveFromRelatedRecordsMutation | AddToRelatedRecordsMutation | SortRelatedRecordsMutation;
39
+ //# sourceMappingURL=mutations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/cache/mutations.ts"],"names":[],"mappings":"AAAA,OA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2BAA2B,GAC3B,0BAA0B,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { StableRecordIdentifier } from '../identifier';
2
+ export interface Op {
3
+ op: string;
4
+ }
5
+ export interface MergeOperation extends Op {
6
+ op: 'mergeIdentifiers';
7
+ record: StableRecordIdentifier;
8
+ value: StableRecordIdentifier;
9
+ }
10
+ export interface RemoveOperation extends Op {
11
+ op: 'removeIdentifier';
12
+ record: StableRecordIdentifier;
13
+ }
14
+ export type Operation = MergeOperation | RemoveOperation;
15
+ //# sourceMappingURL=operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/cache/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE5D,MAAM,WAAW,EAAE;IACjB,EAAE,EAAE,MAAM,CAAC;CACZ;AAUD,MAAM,WAAW,cAAe,SAAQ,EAAE;IACxC,EAAE,EAAE,kBAAkB,CAAC;IAEvB,MAAM,EAAE,sBAAsB,CAAC;IAE/B,KAAK,EAAE,sBAAsB,CAAC;CAC/B;AAED,MAAM,WAAW,eAAgB,SAAQ,EAAE;IACzC,EAAE,EAAE,kBAAkB,CAAC;IACvB,MAAM,EAAE,sBAAsB,CAAC;CAChC;AAMD,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,eAAe,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { StableRecordIdentifier } from '../identifier';
2
+ import type { Links, Meta, PaginationLinks } from '../spec/raw';
3
+ export interface ResourceRelationship {
4
+ data?: StableRecordIdentifier | null;
5
+ meta?: Meta;
6
+ links?: Links;
7
+ }
8
+ export interface CollectionRelationship {
9
+ data?: StableRecordIdentifier[];
10
+ meta?: Meta;
11
+ links?: PaginationLinks;
12
+ }
13
+ export type Relationship = ResourceRelationship | CollectionRelationship;
14
+ //# sourceMappingURL=relationship.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relationship.d.ts","sourceRoot":"","sources":["../../src/cache/relationship.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGhE,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAC;IACrC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAID,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAChC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,KAAK,CAAC,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,MAAM,YAAY,GAAG,oBAAoB,GAAG,sBAAsB,CAAC"}
@@ -0,0 +1,475 @@
1
+ /**
2
+ * @module @ember-data/experimental-preview-types
3
+ */
4
+ import type { ResourceBlob } from './cache/aliases';
5
+ import type { Change } from './cache/change';
6
+ import type { Mutation } from './cache/mutations';
7
+ import type { Operation } from './cache/operations';
8
+ import type { CollectionRelationship, ResourceRelationship } from './cache/relationship';
9
+ import type { StableDocumentIdentifier, StableRecordIdentifier } from './identifier';
10
+ import type { Value } from './json/raw';
11
+ import type { RequestContext, StructuredDataDocument, StructuredDocument } from './request';
12
+ import type { ResourceDocument, SingleResourceDataDocument } from './spec/document';
13
+ import type { ApiError } from './spec/error';
14
+ /**
15
+ * A hash of changed attributes with the key being the attribute name and the value being an
16
+ * array of `[oldValue, newValue]`.
17
+ *
18
+ * @internal
19
+ */
20
+ export type ChangedAttributesHash = Record<string, [Value | undefined, Value]>;
21
+ export type RelationshipDiff = {
22
+ kind: 'collection';
23
+ remoteState: StableRecordIdentifier[];
24
+ additions: Set<StableRecordIdentifier>;
25
+ removals: Set<StableRecordIdentifier>;
26
+ localState: StableRecordIdentifier[];
27
+ reordered: boolean;
28
+ } | {
29
+ kind: 'resource';
30
+ remoteState: StableRecordIdentifier | null;
31
+ localState: StableRecordIdentifier | null;
32
+ };
33
+ /**
34
+ * The interface for EmberData Caches.
35
+ *
36
+ * A Cache handles in-memory storage of Document and Resource
37
+ * data.
38
+ *
39
+ * @class <Interface> Cache
40
+ * @public
41
+ */
42
+ export interface Cache {
43
+ /**
44
+ * The Cache Version that this implementation implements.
45
+ *
46
+ * @type {'2'}
47
+ * @public
48
+ * @property version
49
+ */
50
+ version: '2';
51
+ /**
52
+ * Cache the response to a request
53
+ *
54
+ * Unlike `store.push` which has UPSERT
55
+ * semantics, `put` has `replace` semantics similar to
56
+ * the `http` method `PUT`
57
+ *
58
+ * the individually cacheable resource data it may contain
59
+ * should upsert, but the document data surrounding it should
60
+ * fully replace any existing information
61
+ *
62
+ * Note that in order to support inserting arbitrary data
63
+ * to the cache that did not originate from a request `put`
64
+ * should expect to sometimes encounter a document with only
65
+ * a `content` member and therefor must not assume the existence
66
+ * of `request` and `response` on the document.
67
+ *
68
+ * @method put
69
+ * @param {StructuredDocument} doc
70
+ * @return {ResourceDocument}
71
+ * @public
72
+ */
73
+ put<T>(doc: StructuredDocument<T> | {
74
+ content: T;
75
+ }): ResourceDocument;
76
+ /**
77
+ * Update the "remote" or "canonical" (persisted) state of the Cache
78
+ * by merging new information into the existing state.
79
+ *
80
+ * Note: currently the only valid resource operation is a MergeOperation
81
+ * which occurs when a collision of identifiers is detected.
82
+ *
83
+ * @method patch
84
+ * @public
85
+ * @param {Operation} op the operation to perform
86
+ * @return {void}
87
+ */
88
+ patch(op: Operation): void;
89
+ /**
90
+ * Update the "local" or "current" (unpersisted) state of the Cache
91
+ *
92
+ * @method mutate
93
+ * @param {Mutation} mutation
94
+ * @return {void}
95
+ * @public
96
+ */
97
+ mutate(mutation: Mutation): void;
98
+ /**
99
+ * Peek resource data from the Cache.
100
+ *
101
+ * In development, if the return value
102
+ * is JSON the return value
103
+ * will be deep-cloned and deep-frozen
104
+ * to prevent mutation thereby enforcing cache
105
+ * Immutability.
106
+ *
107
+ * This form of peek is useful for implementations
108
+ * that want to feed raw-data from cache to the UI
109
+ * or which want to interact with a blob of data
110
+ * directly from the presentation cache.
111
+ *
112
+ * An implementation might want to do this because
113
+ * de-referencing records which read from their own
114
+ * blob is generally safer because the record does
115
+ * not require retainining connections to the Store
116
+ * and Cache to present data on a per-field basis.
117
+ *
118
+ * This generally takes the place of `getAttr` as
119
+ * an API and may even take the place of `getRelationship`
120
+ * depending on implementation specifics, though this
121
+ * latter usage is less recommended due to the advantages
122
+ * of the Graph handling necessary entanglements and
123
+ * notifications for relational data.
124
+ *
125
+ * @method peek
126
+ * @public
127
+ * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
128
+ * @return {ResourceDocument | ResourceBlob | null} the known resource data
129
+ */
130
+ peek(identifier: StableRecordIdentifier): ResourceBlob | null;
131
+ peek(identifier: StableDocumentIdentifier): ResourceDocument | null;
132
+ /**
133
+ * Peek the Cache for the existing request data associated with
134
+ * a cacheable request
135
+ *
136
+ * This is effectively the reverse of `put` for a request in
137
+ * that it will return the the request, response, and content
138
+ * whereas `peek` will return just the `content`.
139
+ *
140
+ * @method peekRequest
141
+ * @param {StableDocumentIdentifier}
142
+ * @return {StructuredDocument<ResourceDocument> | null}
143
+ * @public
144
+ */
145
+ peekRequest(identifier: StableDocumentIdentifier): StructuredDocument<ResourceDocument> | null;
146
+ /**
147
+ * Push resource data from a remote source into the cache for this identifier
148
+ *
149
+ * @method upsert
150
+ * @public
151
+ * @param identifier
152
+ * @param data
153
+ * @param hasRecord
154
+ * @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned
155
+ */
156
+ upsert(identifier: StableRecordIdentifier, data: ResourceBlob, hasRecord: boolean): void | string[];
157
+ /**
158
+ * Create a fork of the cache from the current state.
159
+ *
160
+ * Applications should typically not call this method themselves,
161
+ * preferring instead to fork at the Store level, which will
162
+ * utilize this method to fork the cache.
163
+ *
164
+ * @method fork
165
+ * @public
166
+ * @return Promise<Cache>
167
+ */
168
+ fork(): Promise<Cache>;
169
+ /**
170
+ * Merge a fork back into a parent Cache.
171
+ *
172
+ * Applications should typically not call this method themselves,
173
+ * preferring instead to merge at the Store level, which will
174
+ * utilize this method to merge the caches.
175
+ *
176
+ * @method merge
177
+ * @param {Cache} cache
178
+ * @public
179
+ * @return Promise<void>
180
+ */
181
+ merge(cache: Cache): Promise<void>;
182
+ /**
183
+ * Generate the list of changes applied to all
184
+ * record in the store.
185
+ *
186
+ * Each individual resource or document that has
187
+ * been mutated should be described as an individual
188
+ * `Change` entry in the returned array.
189
+ *
190
+ * A `Change` is described by an object containing up to
191
+ * three properties: (1) the `identifier` of the entity that
192
+ * changed; (2) the `op` code of that change being one of
193
+ * `upsert` or `remove`, and if the op is `upsert` a `patch`
194
+ * containing the data to merge into the cache for the given
195
+ * entity.
196
+ *
197
+ * This `patch` is opaque to the Store but should be understood
198
+ * by the Cache and may expect to be utilized by an Adapter
199
+ * when generating data during a `save` operation.
200
+ *
201
+ * It is generally recommended that the `patch` contain only
202
+ * the updated state, ignoring fields that are unchanged
203
+ *
204
+ * ```ts
205
+ * interface Change {
206
+ * identifier: StableRecordIdentifier | StableDocumentIdentifier;
207
+ * op: 'upsert' | 'remove';
208
+ * patch?: unknown;
209
+ * }
210
+ * ```
211
+ *
212
+ * @method diff
213
+ * @public
214
+ */
215
+ diff(): Promise<Change[]>;
216
+ /**
217
+ * Serialize the entire contents of the Cache into a Stream
218
+ * which may be fed back into a new instance of the same Cache
219
+ * via `cache.hydrate`.
220
+ *
221
+ * @method dump
222
+ * @return {Promise<ReadableStream>}
223
+ * @public
224
+ */
225
+ dump(): Promise<ReadableStream<unknown>>;
226
+ /**
227
+ * hydrate a Cache from a Stream with content previously serialized
228
+ * from another instance of the same Cache, resolving when hydration
229
+ * is complete.
230
+ *
231
+ * This method should expect to be called both in the context of restoring
232
+ * the Cache during application rehydration after SSR **AND** at unknown
233
+ * times during the lifetime of an already booted application when it is
234
+ * desired to bulk-load additional information into the cache. This latter
235
+ * behavior supports optimizing pre/fetching of data for route transitions
236
+ * via data-only SSR modes.
237
+ *
238
+ * @method hydrate
239
+ * @param {ReadableStream} stream
240
+ * @return {Promise<void>}
241
+ * @public
242
+ */
243
+ hydrate(stream: ReadableStream<unknown>): Promise<void>;
244
+ /**
245
+ * [LIFECYCLE] Signal to the cache that a new record has been instantiated on the client
246
+ *
247
+ * It returns properties from options that should be set on the record during the create
248
+ * process. This return value behavior is deprecated.
249
+ *
250
+ * @method clientDidCreate
251
+ * @public
252
+ * @param identifier
253
+ * @param createArgs
254
+ */
255
+ clientDidCreate(identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>): Record<string, unknown>;
256
+ /**
257
+ * [LIFECYCLE] Signals to the cache that a resource
258
+ * will be part of a save transaction.
259
+ *
260
+ * @method willCommit
261
+ * @public
262
+ * @param identifier
263
+ */
264
+ willCommit(identifier: StableRecordIdentifier, context: RequestContext): void;
265
+ /**
266
+ * [LIFECYCLE] Signals to the cache that a resource
267
+ * was successfully updated as part of a save transaction.
268
+ *
269
+ * @method didCommit
270
+ * @public
271
+ * @param identifier - the primary identifier that was operated on
272
+ * @param data - a document in the cache format containing any updated data
273
+ * @return {SingleResourceDataDocument}
274
+ */
275
+ didCommit(identifier: StableRecordIdentifier, result: StructuredDataDocument<unknown>): SingleResourceDataDocument;
276
+ /**
277
+ * [LIFECYCLE] Signals to the cache that a resource
278
+ * was update via a save transaction failed.
279
+ *
280
+ * @method commitWasRejected
281
+ * @public
282
+ * @param identifier
283
+ * @param errors
284
+ */
285
+ commitWasRejected(identifier: StableRecordIdentifier, errors?: ApiError[]): void;
286
+ /**
287
+ * [LIFECYCLE] Signals to the cache that all data for a resource
288
+ * should be cleared.
289
+ *
290
+ * This method is a candidate to become a mutation
291
+ *
292
+ * @method unloadRecord
293
+ * @public
294
+ * @param identifier
295
+ */
296
+ unloadRecord(identifier: StableRecordIdentifier): void;
297
+ /**
298
+ * Retrieve the data for an attribute from the cache
299
+ *
300
+ * @method getAttr
301
+ * @public
302
+ * @param identifier
303
+ * @param field
304
+ * @return {unknown}
305
+ */
306
+ getAttr(identifier: StableRecordIdentifier, field: string): Value | undefined;
307
+ /**
308
+ * Mutate the data for an attribute in the cache
309
+ *
310
+ * This method is a candidate to become a mutation
311
+ *
312
+ * @method setAttr
313
+ * @public
314
+ * @param identifier
315
+ * @param field
316
+ * @param value
317
+ */
318
+ setAttr(identifier: StableRecordIdentifier, field: string, value: Value): void;
319
+ /**
320
+ * Query the cache for the changed attributes of a resource.
321
+ *
322
+ * Returns a map of field names to tuples of [old, new] values
323
+ *
324
+ * ```
325
+ * { <field>: [<old>, <new>] }
326
+ * ```
327
+ *
328
+ * @method changedAttrs
329
+ * @public
330
+ * @param identifier
331
+ * @return {Record<string, [unknown, unknown]>} { <field>: [<old>, <new>] }
332
+ */
333
+ changedAttrs(identifier: StableRecordIdentifier): ChangedAttributesHash;
334
+ /**
335
+ * Query the cache for whether any mutated attributes exist
336
+ *
337
+ * @method hasChangedAttrs
338
+ * @public
339
+ * @param identifier
340
+ * @return {boolean}
341
+ */
342
+ hasChangedAttrs(identifier: StableRecordIdentifier): boolean;
343
+ /**
344
+ * Tell the cache to discard any uncommitted mutations to attributes
345
+ *
346
+ * This method is a candidate to become a mutation
347
+ *
348
+ * @method rollbackAttrs
349
+ * @public
350
+ * @param identifier
351
+ * @return {string[]} the names of fields that were restored
352
+ */
353
+ rollbackAttrs(identifier: StableRecordIdentifier): string[];
354
+ /**
355
+ * Query the cache for the changes to relationships of a resource.
356
+ *
357
+ * Returns a map of relationship names to RelationshipDiff objects.
358
+ *
359
+ * ```ts
360
+ * type RelationshipDiff =
361
+ | {
362
+ kind: 'collection';
363
+ remoteState: StableRecordIdentifier[];
364
+ additions: Set<StableRecordIdentifier>;
365
+ removals: Set<StableRecordIdentifier>;
366
+ localState: StableRecordIdentifier[];
367
+ reordered: boolean;
368
+ }
369
+ | {
370
+ kind: 'resource';
371
+ remoteState: StableRecordIdentifier | null;
372
+ localState: StableRecordIdentifier | null;
373
+ };
374
+ ```
375
+ *
376
+ * @method changedRelationships
377
+ * @public
378
+ * @param {StableRecordIdentifier} identifier
379
+ * @return {Map<string, RelationshipDiff>}
380
+ */
381
+ changedRelationships(identifier: StableRecordIdentifier): Map<string, RelationshipDiff>;
382
+ /**
383
+ * Query the cache for whether any mutated attributes exist
384
+ *
385
+ * @method hasChangedRelationships
386
+ * @public
387
+ * @param {StableRecordIdentifier} identifier
388
+ * @return {boolean}
389
+ */
390
+ hasChangedRelationships(identifier: StableRecordIdentifier): boolean;
391
+ /**
392
+ * Tell the cache to discard any uncommitted mutations to relationships.
393
+ *
394
+ * This will also discard the change on any appropriate inverses.
395
+ *
396
+ * This method is a candidate to become a mutation
397
+ *
398
+ * @method rollbackRelationships
399
+ * @public
400
+ * @param {StableRecordIdentifier} identifier
401
+ * @return {string[]} the names of relationships that were restored
402
+ */
403
+ rollbackRelationships(identifier: StableRecordIdentifier): string[];
404
+ /**
405
+ * Query the cache for the current state of a relationship property
406
+ *
407
+ * @method getRelationship
408
+ * @public
409
+ * @param {StableRecordIdentifier} identifier
410
+ * @param {string} field
411
+ * @return resource relationship object
412
+ */
413
+ getRelationship(identifier: StableRecordIdentifier, field: string, isCollection?: boolean): ResourceRelationship | CollectionRelationship;
414
+ /**
415
+ * Update the cache state for the given resource to be marked
416
+ * as locally deleted, or remove such a mark.
417
+ *
418
+ * This method is a candidate to become a mutation
419
+ *
420
+ * @method setIsDeleted
421
+ * @public
422
+ * @param identifier
423
+ * @param isDeleted {boolean}
424
+ */
425
+ setIsDeleted(identifier: StableRecordIdentifier, isDeleted: boolean): void;
426
+ /**
427
+ * Query the cache for any validation errors applicable to the given resource.
428
+ *
429
+ * @method getErrors
430
+ * @public
431
+ * @param identifier
432
+ * @return {JsonApiError[]}
433
+ */
434
+ getErrors(identifier: StableRecordIdentifier): ApiError[];
435
+ /**
436
+ * Query the cache for whether a given resource has any available data
437
+ *
438
+ * @method isEmpty
439
+ * @public
440
+ * @param identifier
441
+ * @return {boolean}
442
+ */
443
+ isEmpty(identifier: StableRecordIdentifier): boolean;
444
+ /**
445
+ * Query the cache for whether a given resource was created locally and not
446
+ * yet persisted.
447
+ *
448
+ * @method isNew
449
+ * @public
450
+ * @param identifier
451
+ * @return {boolean}
452
+ */
453
+ isNew(identifier: StableRecordIdentifier): boolean;
454
+ /**
455
+ * Query the cache for whether a given resource is marked as deleted (but not
456
+ * necessarily persisted yet).
457
+ *
458
+ * @method isDeleted
459
+ * @public
460
+ * @param identifier
461
+ * @return {boolean}
462
+ */
463
+ isDeleted(identifier: StableRecordIdentifier): boolean;
464
+ /**
465
+ * Query the cache for whether a given resource has been deleted and that deletion
466
+ * has also been persisted.
467
+ *
468
+ * @method isDeletionCommitted
469
+ * @public
470
+ * @param identifier
471
+ * @return {boolean}
472
+ */
473
+ isDeletionCommitted(identifier: StableRecordIdentifier): boolean;
474
+ }
475
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,KAAK,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC5F,OAAO,KAAK,EAAE,gB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