@ember-data/store 5.4.0-alpha.30 → 5.4.0-alpha.32

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 (70) hide show
  1. package/addon/cache-handler-oB00-31L.js.map +1 -1
  2. package/package.json +11 -10
  3. package/unstable-preview-types/-private/cache-handler.d.ts +99 -0
  4. package/unstable-preview-types/-private/cache-handler.d.ts.map +1 -0
  5. package/unstable-preview-types/-private/caches/cache-utils.d.ts +9 -0
  6. package/unstable-preview-types/-private/caches/cache-utils.d.ts.map +1 -0
  7. package/unstable-preview-types/-private/caches/identifier-cache.d.ts +180 -0
  8. package/unstable-preview-types/-private/caches/identifier-cache.d.ts.map +1 -0
  9. package/unstable-preview-types/-private/caches/instance-cache.d.ts +61 -0
  10. package/unstable-preview-types/-private/caches/instance-cache.d.ts.map +1 -0
  11. package/unstable-preview-types/-private/caches/resource-utils.d.ts +10 -0
  12. package/unstable-preview-types/-private/caches/resource-utils.d.ts.map +1 -0
  13. package/unstable-preview-types/-private/document.d.ts +144 -0
  14. package/unstable-preview-types/-private/document.d.ts.map +1 -0
  15. package/unstable-preview-types/-private/index.d.ts +16 -0
  16. package/unstable-preview-types/-private/index.d.ts.map +1 -0
  17. package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts +177 -0
  18. package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts.map +1 -0
  19. package/unstable-preview-types/-private/legacy-model-support/shim-model-class.d.ts +17 -0
  20. package/unstable-preview-types/-private/legacy-model-support/shim-model-class.d.ts.map +1 -0
  21. package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts +27 -0
  22. package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts.map +1 -0
  23. package/unstable-preview-types/-private/managers/cache-manager.d.ts +440 -0
  24. package/unstable-preview-types/-private/managers/cache-manager.d.ts.map +1 -0
  25. package/unstable-preview-types/-private/managers/notification-manager.d.ts +96 -0
  26. package/unstable-preview-types/-private/managers/notification-manager.d.ts.map +1 -0
  27. package/unstable-preview-types/-private/managers/record-array-manager.d.ts +95 -0
  28. package/unstable-preview-types/-private/managers/record-array-manager.d.ts.map +1 -0
  29. package/unstable-preview-types/-private/network/request-cache.d.ts +107 -0
  30. package/unstable-preview-types/-private/network/request-cache.d.ts.map +1 -0
  31. package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts +135 -0
  32. package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts.map +1 -0
  33. package/unstable-preview-types/-private/store-service.d.ts +1552 -0
  34. package/unstable-preview-types/-private/store-service.d.ts.map +1 -0
  35. package/unstable-preview-types/-private/utils/coerce-id.d.ts +8 -0
  36. package/unstable-preview-types/-private/utils/coerce-id.d.ts.map +1 -0
  37. package/unstable-preview-types/-private/utils/construct-resource.d.ts +8 -0
  38. package/unstable-preview-types/-private/utils/construct-resource.d.ts.map +1 -0
  39. package/unstable-preview-types/-private/utils/identifier-debug-consts.d.ts +5 -0
  40. package/unstable-preview-types/-private/utils/identifier-debug-consts.d.ts.map +1 -0
  41. package/unstable-preview-types/-private/utils/is-non-empty-string.d.ts +2 -0
  42. package/unstable-preview-types/-private/utils/is-non-empty-string.d.ts.map +1 -0
  43. package/unstable-preview-types/-private/utils/normalize-model-name.d.ts +2 -0
  44. package/unstable-preview-types/-private/utils/normalize-model-name.d.ts.map +1 -0
  45. package/unstable-preview-types/-private/utils/uuid-polyfill.d.ts +2 -0
  46. package/unstable-preview-types/-private/utils/uuid-polyfill.d.ts.map +1 -0
  47. package/unstable-preview-types/-private.d.ts +2 -0
  48. package/unstable-preview-types/-private.d.ts.map +1 -0
  49. package/unstable-preview-types/-types/overview.d.ts +19 -0
  50. package/unstable-preview-types/-types/overview.d.ts.map +1 -0
  51. package/unstable-preview-types/-types/q/cache-store-wrapper.d.ts +105 -0
  52. package/unstable-preview-types/-types/q/cache-store-wrapper.d.ts.map +1 -0
  53. package/unstable-preview-types/-types/q/cache.d.ts +45 -0
  54. package/unstable-preview-types/-types/q/cache.d.ts.map +1 -0
  55. package/unstable-preview-types/-types/q/ds-model.d.ts +13 -0
  56. package/unstable-preview-types/-types/q/ds-model.d.ts.map +1 -0
  57. package/unstable-preview-types/-types/q/identifier.d.ts +169 -0
  58. package/unstable-preview-types/-types/q/identifier.d.ts.map +1 -0
  59. package/unstable-preview-types/-types/q/promise-proxies.d.ts +2 -0
  60. package/unstable-preview-types/-types/q/promise-proxies.d.ts.map +1 -0
  61. package/unstable-preview-types/-types/q/record-data-json-api.d.ts +34 -0
  62. package/unstable-preview-types/-types/q/record-data-json-api.d.ts.map +1 -0
  63. package/unstable-preview-types/-types/q/record-instance.d.ts +27 -0
  64. package/unstable-preview-types/-types/q/record-instance.d.ts.map +1 -0
  65. package/unstable-preview-types/-types/q/schema-service.d.ts +212 -0
  66. package/unstable-preview-types/-types/q/schema-service.d.ts.map +1 -0
  67. package/unstable-preview-types/-types/q/store.d.ts +15 -0
  68. package/unstable-preview-types/-types/q/store.d.ts.map +1 -0
  69. package/unstable-preview-types/index.d.ts +185 -0
  70. package/unstable-preview-types/index.d.ts.map +1 -0
@@ -0,0 +1,177 @@
1
+ import type { StableRecordIdentifier } from '@warp-drive/core-types/identifier';
2
+ /**
3
+ @module @ember-data/store
4
+ */
5
+ import type { SingleResourceDocument } from '@warp-drive/core-types/spec/raw';
6
+ import type { OpaqueRecordInstance } from '../../-types/q/record-instance';
7
+ import type Store from '../store-service';
8
+ /**
9
+ @module @ember-data/store
10
+ */
11
+ /**
12
+ A `RecordReference` is a low-level API that allows users and
13
+ addon authors to perform meta-operations on a record.
14
+
15
+ @class RecordReference
16
+ @public
17
+ */
18
+ export default class RecordReference {
19
+ store: Store;
20
+ ___token: object;
21
+ ___identifier: StableRecordIdentifier;
22
+ _ref: number;
23
+ constructor(store: Store, identifier: StableRecordIdentifier);
24
+ destroy(): void;
25
+ get type(): string;
26
+ /**
27
+ The `id` of the record that this reference refers to.
28
+
29
+ Together, the `type` and `id` properties form a composite key for
30
+ the identity map.
31
+
32
+ Example
33
+
34
+ ```javascript
35
+ let userRef = store.getReference('user', 1);
36
+
37
+ userRef.id(); // '1'
38
+ ```
39
+
40
+ @method id
41
+ @public
42
+ @return {String} The id of the record.
43
+ */
44
+ id(): string | null;
45
+ /**
46
+ The `identifier` of the record that this reference refers to.
47
+
48
+ Together, the `type` and `id` properties form a composite key for
49
+ the identity map.
50
+
51
+ Example
52
+
53
+ ```javascript
54
+ let userRef = store.getReference('user', 1);
55
+
56
+ userRef.identifier(); // '1'
57
+ ```
58
+
59
+ @method identifier
60
+ @public
61
+ @return {String} The identifier of the record.
62
+ */
63
+ identifier(): StableRecordIdentifier;
64
+ /**
65
+ How the reference will be looked up when it is loaded. Currently
66
+ this always returns `identity` to signify that a record will be
67
+ loaded by its `type` and `id`.
68
+
69
+ Example
70
+
71
+ ```javascript
72
+ const userRef = store.getReference('user', 1);
73
+
74
+ userRef.remoteType(); // 'identity'
75
+ ```
76
+
77
+ @method remoteType
78
+ @public
79
+ @return {String} 'identity'
80
+ */
81
+ remoteType(): 'identity';
82
+ /**
83
+ This API allows you to provide a reference with new data. The
84
+ simplest usage of this API is similar to `store.push`: you provide a
85
+ normalized hash of data and the object represented by the reference
86
+ will update.
87
+
88
+ If you pass a promise to `push`, Ember Data will not ask the adapter
89
+ for the data if another attempt to fetch it is made in the
90
+ interim. When the promise resolves, the underlying object is updated
91
+ with the new data, and the promise returned by *this function* is resolved
92
+ with that object.
93
+
94
+ For example, `recordReference.push(promise)` will be resolved with a
95
+ record.
96
+
97
+ Example
98
+
99
+ ```javascript
100
+ let userRef = store.getReference('user', 1);
101
+
102
+ // provide data for reference
103
+ userRef.push({
104
+ data: {
105
+ id: "1",
106
+ type: "user",
107
+ attributes: {
108
+ username: "@user"
109
+ }
110
+ }
111
+ }).then(function(user) {
112
+ userRef.value() === user;
113
+ });
114
+ ```
115
+
116
+ @method push
117
+ @public
118
+ @param objectOrPromise a JSON:API ResourceDocument or a promise resolving to one
119
+ @return a promise for the value (record or relationship)
120
+ */
121
+ push(objectOrPromise: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<OpaqueRecordInstance>;
122
+ /**
123
+ If the entity referred to by the reference is already loaded, it is
124
+ present as `reference.value`. Otherwise the value returned by this function
125
+ is `null`.
126
+
127
+ Example
128
+
129
+ ```javascript
130
+ let userRef = store.getReference('user', 1);
131
+
132
+ userRef.value(); // user
133
+ ```
134
+
135
+ @method value
136
+ @public
137
+ @return {Model} the record for this RecordReference
138
+ */
139
+ value(): OpaqueRecordInstance | null;
140
+ /**
141
+ Triggers a fetch for the backing entity based on its `remoteType`
142
+ (see `remoteType` definitions per reference type).
143
+
144
+ Example
145
+
146
+ ```javascript
147
+ let userRef = store.getReference('user', 1);
148
+
149
+ // load user (via store.find)
150
+ userRef.load().then(...)
151
+ ```
152
+
153
+ @method load
154
+ @public
155
+ @return {Promise<record>} the record for this RecordReference
156
+ */
157
+ load(): Promise<unknown>;
158
+ /**
159
+ Reloads the record if it is already loaded. If the record is not
160
+ loaded it will load the record via `store.findRecord`
161
+
162
+ Example
163
+
164
+ ```javascript
165
+ let userRef = store.getReference('user', 1);
166
+
167
+ // or trigger a reload
168
+ userRef.reload().then(...)
169
+ ```
170
+
171
+ @method reload
172
+ @public
173
+ @return {Promise<record>} the record for this RecordReference
174
+ */
175
+ reload(): Promise<unknown>;
176
+ }
177
+ //# sourceMappingURL=record-reference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record-reference.d.ts","sourceRoot":"","sources":["../../../src/-private/legacy-model-support/record-reference.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAChF;;EAEE;AACF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAE1C;;EAEE;AAEF;;;;;;EAME;AACF,MAAM,CAAC,OAAO,OAAO,eAAe;IAC1B,KAAK,EAAE,KAAK,CAAC;IAErB,QAAQ,EAAG,MAAM,CAAC;IAClB,aAAa,EAAE,sBAAsB,CAAC;IAE9B,IAAI,EAAE,MAAM,CAAC;gBAET,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,sBAAsB;IAa5D,OAAO;IAIP,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;;;;;;;;;;;;;;MAiBE;IACF,EAAE;IAKF;;;;;;;;;;;;;;;;;MAiBE;IACF,UAAU,IAAI,sBAAsB;IAIpC;;;;;;;;;;;;;;;;MAgBE;IACF,UAAU,IAAI,UAAU;IAIxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAsCE;IACF,IAAI,CAAC,eAAe,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAO9G;;;;;;;;;;;;;;;;MAgBE;IACF,KAAK,IAAI,oBAAoB,GAAG,IAAI;IAIpC;;;;;;;;;;;;;;;;MAgBE;IACF,IAAI;IAQJ;;;;;;;;;;;;;;;;MAgBE;IACF,MAAM;CAOP"}
@@ -0,0 +1,17 @@
1
+ import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
2
+ import type { AttributeSchema, RelationshipSchema } from '@warp-drive/core-types/schema';
3
+ import type { KeyOrString, ModelSchema } from '../../-types/q/ds-model';
4
+ import type Store from '../store-service';
5
+ export declare function getShimClass<T>(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string): ShimModelClass<T>;
6
+ export default class ShimModelClass<T = unknown> implements ModelSchema<T> {
7
+ __store: Store;
8
+ modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;
9
+ constructor(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string);
10
+ get fields(): Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'>;
11
+ get attributes(): Map<KeyOrString<T>, AttributeSchema>;
12
+ get relationshipsByName(): Map<KeyOrString<T>, RelationshipSchema>;
13
+ eachAttribute<K extends KeyOrString<T>>(callback: (key: K, attribute: AttributeSchema) => void, binding?: T): void;
14
+ eachRelationship<K extends KeyOrString<T>>(callback: (key: K, relationship: RelationshipSchema) => void, binding?: T): void;
15
+ eachTransformedAttribute<K extends KeyOrString<T>>(callback: (key: K, type: string | null) => void, binding?: T): void;
16
+ }
17
+ //# sourceMappingURL=shim-model-class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shim-model-class.d.ts","sourceRoot":"","sources":["../../../src/-private/legacy-model-support/shim-model-class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEzF,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAM1C,wBAAgB,YAAY,CAAC,CAAC,EAC5B,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,CAAC,SAAS,mBAAmB,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM,GACtE,cAAc,CAAC,CAAC,CAAC,CAcnB;AAaD,MAAM,CAAC,OAAO,OAAO,cAAc,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAChE,OAAO,EAAE,KAAK,CAAC;IACf,SAAS,EAAE,CAAC,SAAS,mBAAmB,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;gBACpE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,SAAS,mBAAmB,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM;IAKjG,IAAI,MAAM,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAAC,CASvE;IAED,IAAI,UAAU,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,eAAe,CAAC,CAGrD;IAED,IAAI,mBAAmB,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAKjE;IAED,aAAa,CAAC,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,eAAe,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;IAO3G,gBAAgB,CAAC,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,EACvC,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,YAAY,EAAE,kBAAkB,KAAK,IAAI,EAC5D,OAAO,CAAC,EAAE,CAAC;IAUb,wBAAwB,CAAC,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;CAQhH"}
@@ -0,0 +1,27 @@
1
+ import type { StableDocumentIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier';
2
+ import type { CacheCapabilitiesManager as StoreWrapper } from '../../-types/q/cache-store-wrapper';
3
+ import type { SchemaService } from '../../-types/q/schema-service';
4
+ import type { IdentifierCache } from '../caches/identifier-cache';
5
+ import type Store from '../store-service';
6
+ import type { NotificationType } from './notification-manager';
7
+ /**
8
+ @module @ember-data/store
9
+ */
10
+ export declare class CacheCapabilitiesManager implements StoreWrapper {
11
+ _willNotify: boolean;
12
+ _pendingNotifies: Map<StableRecordIdentifier, Set<string>>;
13
+ _store: Store;
14
+ constructor(_store: Store);
15
+ get identifierCache(): IdentifierCache;
16
+ _scheduleNotification(identifier: StableRecordIdentifier, key: string): void;
17
+ _flushNotifications(): void;
18
+ notifyChange(identifier: StableRecordIdentifier, namespace: 'added' | 'removed'): void;
19
+ notifyChange(identifier: StableDocumentIdentifier, namespace: 'added' | 'updated' | 'removed'): void;
20
+ notifyChange(identifier: StableRecordIdentifier, namespace: NotificationType, key?: string): void;
21
+ getSchemaDefinitionService(): SchemaService;
22
+ get schema(): SchemaService;
23
+ setRecordId(identifier: StableRecordIdentifier, id: string): void;
24
+ hasRecord(identifier: StableRecordIdentifier): boolean;
25
+ disconnectRecord(identifier: StableRecordIdentifier): void;
26
+ }
27
+ //# sourceMappingURL=cache-capabilities-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-capabilities-manager.d.ts","sourceRoot":"","sources":["../../../src/-private/managers/cache-capabilities-manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE1G,OAAO,KAAK,EAAE,wBAAwB,IAAI,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACnG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D;;EAEE;AAEF,qBAAa,wBAAyB,YAAW,YAAY;IACnD,WAAW,EAAE,OAAO,CAAC;IACrB,gBAAgB,EAAE,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3D,MAAM,EAAE,KAAK,CAAC;gBAEV,MAAM,EAAE,KAAK;IAMzB,IAAI,eAAe,IAAI,eAAe,CAErC;IAED,qBAAqB,CAAC,UAAU,EAAE,sBAAsB,EAAE,GAAG,EAAE,MAAM;IAyBrE,mBAAmB,IAAI,IAAI;IAgB3B,YAAY,CAAC,UAAU,EAAE,sBAAsB,EAAE,SAAS,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI;IACtF,YAAY,CAAC,UAAU,EAAE,wBAAwB,EAAE,SAAS,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI;IACpG,YAAY,CAAC,UAAU,EAAE,sBAAsB,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAkBjG,0BAA0B,IAAI,aAAa;IAI3C,IAAI,MAAM,kBAET;IAED,WAAW,CAAC,UAAU,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM;IAK1D,SAAS,CAAC,UAAU,EAAE,sBAAsB,GAAG,OAAO;IAItD,gBAAgB,CAAC,UAAU,EAAE,sBAAsB,GAAG,IAAI;CAK3D"}
@@ -0,0 +1,440 @@
1
+ import type { Cache, ChangedAttributesHash, RelationshipDiff } from '@warp-drive/core-types/cache';
2
+ import type { Change } from '@warp-drive/core-types/cache/change';
3
+ import type { CollectionRelationship, ResourceRelationship } from '@warp-drive/core-types/cache/relationship';
4
+ import type { LocalRelationshipOperation } from '@warp-drive/core-types/graph';
5
+ import type { StableDocumentIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier';
6
+ import type { Value } from '@warp-drive/core-types/json/raw';
7
+ import type { StructuredDataDocument, StructuredDocument } from '@warp-drive/core-types/request';
8
+ import type { ResourceDocument, SingleResourceDataDocument } from '@warp-drive/core-types/spec/document';
9
+ import type { ApiError } from '@warp-drive/core-types/spec/error';
10
+ import type { MergeOperation } from '../../-types/q/cache';
11
+ import type { JsonApiResource } from '../../-types/q/record-data-json-api';
12
+ import type { StoreRequestContext } from '../cache-handler';
13
+ /**
14
+ * The CacheManager wraps a Cache enforcing that only
15
+ * the public API surface area is exposed.
16
+ *
17
+ * Hence, it is the value of `Store.cache`, wrapping
18
+ * the cache instance returned by `Store.createCache`.
19
+ *
20
+ * It handles translating between cache versions when
21
+ * necessary, for instance when a Store is configured
22
+ * to use both a v1 and a v2 cache depending on some
23
+ * heuristic.
24
+ *
25
+ * Starting with the v2 spec, the cache is designed such
26
+ * that it must be implemented as a singleton.
27
+ *
28
+ * @class CacheManager
29
+ * @public
30
+ */
31
+ export declare class CacheManager implements Cache {
32
+ #private;
33
+ version: "2";
34
+ constructor(cache: Cache);
35
+ /**
36
+ * Cache the response to a request
37
+ *
38
+ * Unlike `store.push` which has UPSERT
39
+ * semantics, `put` has `replace` semantics similar to
40
+ * the `http` method `PUT`
41
+ *
42
+ * the individually cacheable
43
+ * e resource data it may contain
44
+ * should upsert, but the document data surrounding it should
45
+ * fully replace any existing information
46
+ *
47
+ * Note that in order to support inserting arbitrary data
48
+ * to the cache that did not originate from a request `put`
49
+ * should expect to sometimes encounter a document with only
50
+ * a `content` member and therefor must not assume the existence
51
+ * of `request` and `response` on the document.
52
+ *
53
+ * @method put
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
+ * @method patch
68
+ * @public
69
+ * @param op the operation to perform
70
+ * @return {void}
71
+ */
72
+ patch(op: MergeOperation): void;
73
+ /**
74
+ * Update resource data with a local mutation. Currently supports operations
75
+ * on relationships only.
76
+ *
77
+ * @method mutate
78
+ * @public
79
+ * @param mutation
80
+ */
81
+ mutate(mutation: LocalRelationshipOperation): void;
82
+ /**
83
+ * Peek resource data from the Cache.
84
+ *
85
+ * In development, if the return value
86
+ * is JSON the return value
87
+ * will be deep-cloned and deep-frozen
88
+ * to prevent mutation thereby enforcing cache
89
+ * Immutability.
90
+ *
91
+ * This form of peek is useful for implementations
92
+ * that want to feed raw-data from cache to the UI
93
+ * or which want to interact with a blob of data
94
+ * directly from the presentation cache.
95
+ *
96
+ * An implementation might want to do this because
97
+ * de-referencing records which read from their own
98
+ * blob is generally safer because the record does
99
+ * not require retaining connections to the Store
100
+ * and Cache to present data on a per-field basis.
101
+ *
102
+ * This generally takes the place of `getAttr` as
103
+ * an API and may even take the place of `getRelationship`
104
+ * depending on implementation specifics, though this
105
+ * latter usage is less recommended due to the advantages
106
+ * of the Graph handling necessary entanglements and
107
+ * notifications for relational data.
108
+ *
109
+ * @method peek
110
+ * @public
111
+ * @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
112
+ * @return {ResourceDocument | ResourceBlob | null} the known resource data
113
+ */
114
+ peek(identifier: StableRecordIdentifier): unknown;
115
+ peek(identifier: StableDocumentIdentifier): ResourceDocument | null;
116
+ /**
117
+ * Peek the Cache for the existing request data associated with
118
+ * a cacheable request
119
+ *
120
+ * @method peekRequest
121
+ * @param {StableDocumentIdentifier}
122
+ * @return {StableDocumentIdentifier | null}
123
+ * @public
124
+ */
125
+ peekRequest(identifier: StableDocumentIdentifier): StructuredDocument<ResourceDocument> | null;
126
+ /**
127
+ * Push resource data from a remote source into the cache for this identifier
128
+ *
129
+ * @method upsert
130
+ * @public
131
+ * @param identifier
132
+ * @param data
133
+ * @param hasRecord
134
+ * @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned
135
+ */
136
+ upsert(identifier: StableRecordIdentifier, data: JsonApiResource, hasRecord: boolean): void | string[];
137
+ /**
138
+ * Create a fork of the cache from the current state.
139
+ *
140
+ * Applications should typically not call this method themselves,
141
+ * preferring instead to fork at the Store level, which will
142
+ * utilize this method to fork the cache.
143
+ *
144
+ * @method fork
145
+ * @public
146
+ * @return Promise<Cache>
147
+ */
148
+ fork(): Promise<Cache>;
149
+ /**
150
+ * Merge a fork back into a parent Cache.
151
+ *
152
+ * Applications should typically not call this method themselves,
153
+ * preferring instead to merge at the Store level, which will
154
+ * utilize this method to merge the caches.
155
+ *
156
+ * @method merge
157
+ * @param {Cache} cache
158
+ * @public
159
+ * @return Promise<void>
160
+ */
161
+ merge(cache: Cache): Promise<void>;
162
+ /**
163
+ * Generate the list of changes applied to all
164
+ * record in the store.
165
+ *
166
+ * Each individual resource or document that has
167
+ * been mutated should be described as an individual
168
+ * `Change` entry in the returned array.
169
+ *
170
+ * A `Change` is described by an object containing up to
171
+ * three properties: (1) the `identifier` of the entity that
172
+ * changed; (2) the `op` code of that change being one of
173
+ * `upsert` or `remove`, and if the op is `upsert` a `patch`
174
+ * containing the data to merge into the cache for the given
175
+ * entity.
176
+ *
177
+ * This `patch` is opaque to the Store but should be understood
178
+ * by the Cache and may expect to be utilized by an Adapter
179
+ * when generating data during a `save` operation.
180
+ *
181
+ * It is generally recommended that the `patch` contain only
182
+ * the updated state, ignoring fields that are unchanged
183
+ *
184
+ * ```ts
185
+ * interface Change {
186
+ * identifier: StableRecordIdentifier | StableDocumentIdentifier;
187
+ * op: 'upsert' | 'remove';
188
+ * patch?: unknown;
189
+ * }
190
+ * ```
191
+ *
192
+ * @method diff
193
+ * @public
194
+ */
195
+ diff(): Promise<Change[]>;
196
+ /**
197
+ * Serialize the entire contents of the Cache into a Stream
198
+ * which may be fed back into a new instance of the same Cache
199
+ * via `cache.hydrate`.
200
+ *
201
+ * @method dump
202
+ * @return {Promise<ReadableStream>}
203
+ * @public
204
+ */
205
+ dump(): Promise<ReadableStream<unknown>>;
206
+ /**
207
+ * hydrate a Cache from a Stream with content previously serialized
208
+ * from another instance of the same Cache, resolving when hydration
209
+ * is complete.
210
+ *
211
+ * This method should expect to be called both in the context of restoring
212
+ * the Cache during application rehydration after SSR **AND** at unknown
213
+ * times during the lifetime of an already booted application when it is
214
+ * desired to bulk-load additional information into the cache. This latter
215
+ * behavior supports optimizing pre/fetching of data for route transitions
216
+ * via data-only SSR modes.
217
+ *
218
+ * @method hydrate
219
+ * @param {ReadableStream} stream
220
+ * @return {Promise<void>}
221
+ * @public
222
+ */
223
+ hydrate(stream: ReadableStream<unknown>): Promise<void>;
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
+ * @method clientDidCreate
231
+ * @public
232
+ * @param identifier
233
+ * @param options
234
+ */
235
+ clientDidCreate(identifier: StableRecordIdentifier, options?: Record<string, unknown>): Record<string, unknown>;
236
+ /**
237
+ * [LIFECYCLE] Signals to the cache that a resource
238
+ * will be part of a save transaction.
239
+ *
240
+ * @method willCommit
241
+ * @public
242
+ * @param identifier
243
+ */
244
+ willCommit(identifier: StableRecordIdentifier, context: StoreRequestContext): void;
245
+ /**
246
+ * [LIFECYCLE] Signals to the cache that a resource
247
+ * was successfully updated as part of a save transaction.
248
+ *
249
+ * @method didCommit
250
+ * @public
251
+ * @param identifier
252
+ * @param data
253
+ */
254
+ didCommit(identifier: StableRecordIdentifier, result: StructuredDataDocument<unknown>): SingleResourceDataDocument;
255
+ /**
256
+ * [LIFECYCLE] Signals to the cache that a resource
257
+ * was update via a save transaction failed.
258
+ *
259
+ * @method commitWasRejected
260
+ * @public
261
+ * @param identifier
262
+ * @param errors
263
+ */
264
+ commitWasRejected(identifier: StableRecordIdentifier, errors?: ApiError[]): void;
265
+ /**
266
+ * [LIFECYCLE] Signals to the cache that all data for a resource
267
+ * should be cleared.
268
+ *
269
+ * @method unloadRecord
270
+ * @public
271
+ * @param identifier
272
+ */
273
+ unloadRecord(identifier: StableRecordIdentifier): void;
274
+ /**
275
+ * Retrieve the data for an attribute from the cache
276
+ *
277
+ * @method getAttr
278
+ * @public
279
+ * @param identifier
280
+ * @param propertyName
281
+ * @return {unknown}
282
+ */
283
+ getAttr(identifier: StableRecordIdentifier, propertyName: string): Value | undefined;
284
+ /**
285
+ * Mutate the data for an attribute in the cache
286
+ *
287
+ * @method setAttr
288
+ * @public
289
+ * @param identifier
290
+ * @param propertyName
291
+ * @param value
292
+ */
293
+ setAttr(identifier: StableRecordIdentifier, propertyName: string, value: Value): void;
294
+ /**
295
+ * Query the cache for the changed attributes of a resource.
296
+ *
297
+ * @method changedAttrs
298
+ * @public
299
+ * @param identifier
300
+ * @return
301
+ */
302
+ changedAttrs(identifier: StableRecordIdentifier): ChangedAttributesHash;
303
+ /**
304
+ * Query the cache for whether any mutated attributes exist
305
+ *
306
+ * @method hasChangedAttrs
307
+ * @public
308
+ * @param identifier
309
+ * @return {boolean}
310
+ */
311
+ hasChangedAttrs(identifier: StableRecordIdentifier): boolean;
312
+ /**
313
+ * Tell the cache to discard any uncommitted mutations to attributes
314
+ *
315
+ * @method rollbackAttrs
316
+ * @public
317
+ * @param identifier
318
+ * @return the names of attributes that were restored
319
+ */
320
+ rollbackAttrs(identifier: StableRecordIdentifier): string[];
321
+ /**
322
+ * Query the cache for the changes to relationships of a resource.
323
+ *
324
+ * Returns a map of relationship names to RelationshipDiff objects.
325
+ *
326
+ * ```ts
327
+ * type RelationshipDiff =
328
+ | {
329
+ kind: 'collection';
330
+ remoteState: StableRecordIdentifier[];
331
+ additions: Set<StableRecordIdentifier>;
332
+ removals: Set<StableRecordIdentifier>;
333
+ localState: StableRecordIdentifier[];
334
+ reordered: boolean;
335
+ }
336
+ | {
337
+ kind: 'resource';
338
+ remoteState: StableRecordIdentifier | null;
339
+ localState: StableRecordIdentifier | null;
340
+ };
341
+ ```
342
+ *
343
+ * @method changedRelationships
344
+ * @public
345
+ * @param {StableRecordIdentifier} identifier
346
+ * @return {Map<string, RelationshipDiff>}
347
+ */
348
+ changedRelationships(identifier: StableRecordIdentifier): Map<string, RelationshipDiff>;
349
+ /**
350
+ * Query the cache for whether any mutated attributes exist
351
+ *
352
+ * @method hasChangedRelationships
353
+ * @public
354
+ * @param {StableRecordIdentifier} identifier
355
+ * @return {boolean}
356
+ */
357
+ hasChangedRelationships(identifier: StableRecordIdentifier): boolean;
358
+ /**
359
+ * Tell the cache to discard any uncommitted mutations to relationships.
360
+ *
361
+ * This will also discard the change on any appropriate inverses.
362
+ *
363
+ * This method is a candidate to become a mutation
364
+ *
365
+ * @method rollbackRelationships
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
+ * @method getRelationship
375
+ * @public
376
+ * @param identifier
377
+ * @param propertyName
378
+ * @return resource relationship object
379
+ */
380
+ getRelationship(identifier: StableRecordIdentifier, propertyName: string): ResourceRelationship | CollectionRelationship;
381
+ /**
382
+ * Update the cache state for the given resource to be marked as locally deleted,
383
+ * or remove such a mark.
384
+ *
385
+ * @method setIsDeleted
386
+ * @public
387
+ * @param identifier
388
+ * @param isDeleted
389
+ */
390
+ setIsDeleted(identifier: StableRecordIdentifier, isDeleted: boolean): void;
391
+ /**
392
+ * Query the cache for any validation errors applicable to the given resource.
393
+ *
394
+ * @method getErrors
395
+ * @public
396
+ * @param identifier
397
+ * @return
398
+ */
399
+ getErrors(identifier: StableRecordIdentifier): ApiError[];
400
+ /**
401
+ * Query the cache for whether a given resource has any available data
402
+ *
403
+ * @method isEmpty
404
+ * @public
405
+ * @param identifier
406
+ * @return {boolean}
407
+ */
408
+ isEmpty(identifier: StableRecordIdentifier): boolean;
409
+ /**
410
+ * Query the cache for whether a given resource was created locally and not
411
+ * yet persisted.
412
+ *
413
+ * @method isNew
414
+ * @public
415
+ * @param identifier
416
+ * @return {boolean}
417
+ */
418
+ isNew(identifier: StableRecordIdentifier): boolean;
419
+ /**
420
+ * Query the cache for whether a given resource is marked as deleted (but not
421
+ * necessarily persisted yet).
422
+ *
423
+ * @method isDeleted
424
+ * @public
425
+ * @param identifier
426
+ * @return {boolean}
427
+ */
428
+ isDeleted(identifier: StableRecordIdentifier): boolean;
429
+ /**
430
+ * Query the cache for whether a given resource has been deleted and that deletion
431
+ * has also been persisted.
432
+ *
433
+ * @method isDeletionCommitted
434
+ * @public
435
+ * @param identifier
436
+ * @return {boolean}
437
+ */
438
+ isDeletionCommitted(identifier: StableRecordIdentifier): boolean;
439
+ }
440
+ //# sourceMappingURL=cache-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-manager.d.ts","sourceRoot":"","sources":["../../../src/-private/managers/cache-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACnG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAC9G,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,KAAK,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC1G,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACjG,OAAO,KAAK,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AACzG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAElE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,YAAa,YAAW,KAAK;;IACxC,OAAO,MAAgB;gBAIX,KAAK,EAAE,KAAK;IAOxB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC,CAAA;KAAE,GAAG,gBAAgB;IAIrE;;;;;;;;;;O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