@ember-data/legacy-compat 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 (25) hide show
  1. package/package.json +17 -16
  2. package/unstable-preview-types/-private.d.ts +15 -0
  3. package/unstable-preview-types/-private.d.ts.map +1 -0
  4. package/unstable-preview-types/index.d.ts +141 -0
  5. package/unstable-preview-types/index.d.ts.map +1 -0
  6. package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts +47 -0
  7. package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts.map +1 -0
  8. package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts +3 -0
  9. package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts.map +1 -0
  10. package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts +3 -0
  11. package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -0
  12. package/unstable-preview-types/legacy-network-handler/legacy-data-utils.d.ts +4 -0
  13. package/unstable-preview-types/legacy-network-handler/legacy-data-utils.d.ts.map +1 -0
  14. package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts +3 -0
  15. package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts.map +1 -0
  16. package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts +547 -0
  17. package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -0
  18. package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts +233 -0
  19. package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -0
  20. package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts +7 -0
  21. package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts.map +1 -0
  22. package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts +95 -0
  23. package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts.map +1 -0
  24. package/unstable-preview-types/legacy-network-handler/snapshot.d.ts +246 -0
  25. package/unstable-preview-types/legacy-network-handler/snapshot.d.ts.map +1 -0
@@ -0,0 +1,233 @@
1
+ /**
2
+ @module @ember-data/experimental-preview-types
3
+ */
4
+ import type Store from '@ember-data/store';
5
+ import type { ModelSchema } from '@ember-data/store/-types/q/ds-model';
6
+ import type { ObjectValue } from '@warp-drive/core-types/json/raw';
7
+ import type { JsonApiDocument, SingleResourceDocument } from '@warp-drive/core-types/spec/raw';
8
+ import type { AdapterPayload } from './minimum-adapter-interface';
9
+ import type Snapshot from './snapshot';
10
+ export type SerializerOptions = {
11
+ includeId?: boolean;
12
+ };
13
+ export type RequestType = 'findRecord' | 'queryRecord' | 'findAll' | 'findBelongsTo' | 'findHasMany' | 'findMany' | 'query' | 'createRecord' | 'deleteRecord' | 'updateRecord';
14
+ /**
15
+ * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
16
+ <p>
17
+ ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
18
+ If starting a new app or thinking of implementing a new adapter, consider writing a
19
+ <a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
20
+ </p>
21
+ </blockquote>
22
+
23
+ The following documentation describes the methods an application
24
+ serializer should implement with descriptions around when an
25
+ application might expect these methods to be called.
26
+
27
+ Methods that are not required are marked as **optional**.
28
+
29
+ @class <Interface> Serializer
30
+ @public
31
+ */
32
+ export interface MinimumSerializerInterface {
33
+ /**
34
+ * This method is responsible for normalizing the value resolved from the promise returned
35
+ * by an Adapter request into the format expected by the `Store`.
36
+ *
37
+ * The output should be a [JSON:API Document](https://jsonapi.org/format/#document-structure)
38
+ * with the following additional restrictions:
39
+ *
40
+ * - `type` should be formatted in the `singular` `dasherized` `lowercase` form
41
+ * - `members` (the property names of attributes and relationships) should be formatted
42
+ * to match their definition in the corresponding `Model` definition. Typically this
43
+ * will be `camelCase`.
44
+ * - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
45
+ * a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
46
+ * and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
47
+ *
48
+ * @method normalizeResponse
49
+ * @public
50
+ * @param {Store} store The store service that initiated the request being normalized
51
+ * @param {ModelSchema} schema An object with methods for accessing information about
52
+ * the type, attributes and relationships of the primary type associated with the request.
53
+ * @param {JSONObject} rawPayload The raw JSON response data returned from an API request.
54
+ * This correlates to the value the promise returned by the adapter method that performed
55
+ * the request resolved to.
56
+ * @param {string|null} id For a findRecord request, this is the id initially provided
57
+ * in the call to store.findRecord. Else this value is null.
58
+ * @param {'findRecord' | 'queryRecord' | 'findAll' | 'findBelongsTo' | 'findHasMany' | 'findMany' | 'query' | 'createRecord' | 'deleteRecord' | 'updateRecord'} requestType The
59
+ * type of request the Adapter had been asked to perform.
60
+ *
61
+ * @return {JsonApiDocument} a document following the structure of a JSON:API Document.
62
+ */
63
+ normalizeResponse(store: Store, schema: ModelSchema, rawPayload: AdapterPayload, id: string | null, requestType: 'findRecord' | 'queryRecord' | 'findAll' | 'findBelongsTo' | 'findHasMany' | 'findMany' | 'query' | 'createRecord' | 'deleteRecord' | 'updateRecord'): JsonApiDocument;
64
+ /**
65
+ * This method is responsible for serializing an individual record
66
+ * via a [Snapshot](Snapshot) into the format expected by the API.
67
+ *
68
+ * This method is called by `snapshot.serialize()`.
69
+ *
70
+ * When using `Model`, this method is called by `record.serialize()`.
71
+ *
72
+ * When using `JSONAPIAdapter` or `RESTAdapter` this method is called
73
+ * by `updateRecord` and `createRecord` if `Serializer.serializeIntoHash`
74
+ * is not implemented.
75
+ *
76
+ * @method serialize
77
+ * @public
78
+ * @param {Snapshot} snapshot A Snapshot for the record to serialize
79
+ * @param {object} [options]
80
+ */
81
+ serialize(snapshot: Snapshot, options?: SerializerOptions): ObjectValue;
82
+ /**
83
+ * This method is intended to normalize data into a [JSON:API Document](https://jsonapi.org/format/#document-structure)
84
+ * with a data member containing a single [Resource](https://jsonapi.org/format/#document-resource-objects).
85
+ *
86
+ * - `type` should be formatted in the singular, dasherized and lowercase form
87
+ * - `members` (the property names of attributes and relationships) should be formatted
88
+ * to match their definition in the corresponding `Model` definition. Typically this
89
+ * will be `camelCase`.
90
+ * - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
91
+ * a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
92
+ * and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
93
+ *
94
+ * This method is called by the `Store` when `store.normalize(modelName, payload)` is
95
+ * called. It is recommended to use `store.serializerFor(modelName).normalizeResponse`
96
+ * over `store.normalize`.
97
+ *
98
+ * This method may be called when also using the `RESTSerializer`
99
+ * when `serializer.pushPayload` is called by `store.pushPayload`.
100
+ * However, it is recommended to use `store.push` over `store.pushPayload` after normalizing
101
+ * the payload directly.
102
+ *
103
+ * Example:
104
+ * ```js
105
+ * function pushPayload(store, modelName, rawPayload) {
106
+ * const ModelClass = store.modelFor(modelName);
107
+ * const serializer = store.serializerFor(modelName);
108
+ * const jsonApiPayload = serializer.normalizeResponse(store, ModelClass, rawPayload, null, 'query');
109
+ *
110
+ * return store.push(jsonApiPayload);
111
+ * }
112
+ * ```
113
+ *
114
+ * This method may be called when also using the `JSONAPISerializer`
115
+ * when normalizing included records. If mixing serializer usage in this way
116
+ * we recommend implementing this method, but caution that it may lead
117
+ * to unexpected mixing of formats.
118
+ *
119
+ * This method may also be called when normalizing embedded relationships when
120
+ * using the `EmbeddedRecordsMixin`. If using this mixin in a serializer in
121
+ * your application we recommend implementing this method, but caution that
122
+ * it may lead to unexpected mixing of formats.
123
+ *
124
+ * @method normalize [OPTIONAL]
125
+ * @public
126
+ * @optional
127
+ * @param {ModelSchema} schema An object with methods for accessing information about
128
+ * the type, attributes and relationships of the primary type associated with the request.
129
+ * @param {JSONObject} rawPayload Some raw JSON data to be normalized into a JSON:API Resource.
130
+ * @param {string} [prop] When called by the EmbeddedRecordsMixin this param will be the
131
+ * property at which the object provided as rawPayload was found.
132
+ * @return {SingleResourceDocument} A JSON:API Document
133
+ * containing a single JSON:API Resource
134
+ * as its primary data.
135
+ */
136
+ normalize?(schema: ModelSchema, rawPayload: ObjectValue, prop?: string): SingleResourceDocument;
137
+ /**
138
+ * When using `JSONAPIAdapter` or `RESTAdapter` this method is called
139
+ * by `adapter.updateRecord` and `adapter.createRecord` if `serializer.serializeIntoHash`
140
+ * is implemented. If this method is not implemented, `serializer.serialize`
141
+ * will be called in this case.
142
+ *
143
+ * You can use this method to customize the root keys serialized into the payload.
144
+ * The hash property should be modified by reference.
145
+ *
146
+ * For instance, your API may expect resources to be keyed by underscored type in the payload:
147
+ *
148
+ * ```js
149
+ * {
150
+ * _user: {
151
+ * type: 'user',
152
+ * id: '1'
153
+ * }
154
+ * }
155
+ * ```
156
+ *
157
+ * Which when using these adapters can be achieved by implementing this method similar
158
+ * to the following:
159
+ *
160
+ * ```js
161
+ * serializeIntoHash(hash, ModelClass, snapshot, options) {
162
+ * hash[`_${snapshot.modelName}`] = this.serialize(snapshot, options).data;
163
+ * }
164
+ * ```
165
+ *
166
+ * @method serializeIntoHash [OPTIONAL]
167
+ * @public
168
+ * @optional
169
+ * @param hash A top most object of the request payload onto
170
+ * which to append the serialized record
171
+ * @param {ModelSchema} schema An object with methods for accessing information about
172
+ * the type, attributes and relationships of the primary type associated with the request.
173
+ * @param {Snapshot} snapshot A Snapshot for the record to serialize
174
+ * @param [options]
175
+ * @return {void}
176
+ */
177
+ serializeIntoHash?(hash: object, schema: ModelSchema, snapshot: Snapshot, options?: SerializerOptions): void;
178
+ /**
179
+ * This method allows for normalization of data when `store.pushPayload` is called
180
+ * and should be implemented if you want to use that method.
181
+ *
182
+ * The method is responsible for pushing new data to the store using `store.push`
183
+ * once any necessary normalization has occurred, and no data in the store will be
184
+ * updated unless it does so.
185
+ *
186
+ * The normalized form pushed to the store should be a [JSON:API Document](https://jsonapi.org/format/#document-structure)
187
+ * with the following additional restrictions:
188
+ *
189
+ * - `type` should be formatted in the singular, dasherized and lowercase form
190
+ * - `members` (the property names of attributes and relationships) should be formatted
191
+ * to match their definition in the corresponding `Model` definition. Typically this
192
+ * will be `camelCase`.
193
+ * - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
194
+ * a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
195
+ * and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
196
+ *
197
+ * If you need better control over normalization or want access to the records being added or updated
198
+ * in the store, we recommended using `store.push` over `store.pushPayload` after normalizing
199
+ * the payload directly. This can even take advantage of an existing serializer for the format
200
+ * the data is in, for example:
201
+ *
202
+ * ```js
203
+ * function pushPayload(store, modelName, rawPayload) {
204
+ * const ModelClass = store.modelFor(modelName);
205
+ * const serializer = store.serializerFor(modelName);
206
+ * const jsonApiPayload = serializer.normalizeResponse(store, ModelClass, rawPayload, null, 'query');
207
+ *
208
+ * return store.push(jsonApiPayload);
209
+ * }
210
+ * ```
211
+ *
212
+ * @method pushPayload [OPTIONAL]
213
+ * @public
214
+ * @optional
215
+ * @param {Store} store The store service that initiated the request being normalized
216
+ * @param {object} rawPayload The raw JSON response data returned from an API request.
217
+ * This JSON should be in the API format expected by the serializer.
218
+ * @return {void}
219
+ */
220
+ pushPayload?(store: Store, rawPayload: ObjectValue): void;
221
+ /**
222
+ * In some situations the serializer may need to perform cleanup when destroyed,
223
+ * that cleanup can be done in `destroy`.
224
+ *
225
+ * If not implemented, the store does not inform the serializer of destruction.
226
+ *
227
+ * @method destroy [OPTIONAL]
228
+ * @public
229
+ * @optional
230
+ */
231
+ destroy?(): void;
232
+ }
233
+ //# sourceMappingURL=minimum-serializer-interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minimum-serializer-interface.d.ts","sourceRoot":"","sources":["../../src/legacy-network-handler/minimum-serializer-interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE/F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AAEvC,MAAM,MAAM,iBAAiB,GAAG;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AACxD,MAAM,MAAM,WAAW,GACnB,YAAY,GACZ,aAAa,GACb,SAAS,GACT,eAAe,GACf,aAAa,GACb,UAAU,GACV,OAAO,GACP,cAAc,GACd,cAAc,GACd,cAAc,CAAC;AAEnB;;;;;;;;;;;;;;;;;EAiBE;AACF,MAAM,WAAW,0BAA0B;IACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,iBAAiB,CACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,cAAc,EAC1B,EAAE,EAAE,MAAM,GAAG,IAAI,EACjB,WAAW,EACP,YAAY,GACZ,aAAa,GACb,SAAS,GACT,eAAe,GACf,aAAa,GACb,UAAU,GACV,OAAO,GACP,cAAc,GACd,cAAc,GACd,cAAc,GACjB,eAAe,CAAC;IAEnB;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,WAAW,CAAC;IAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqDG;IACH,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,sBAAsB,CAAC;IAEhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCG;IACH,iBAAiB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAE7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACH,WAAW,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;IAE1D;;;;;;;;;OASG;IACH,OAAO,CAAC,IAAI,IAAI,CAAC;CAClB"}
@@ -0,0 +1,7 @@
1
+ import type Store from '@ember-data/store';
2
+ import type { ModelSchema } from '@ember-data/store/-types/q/ds-model';
3
+ import type { JsonApiDocument } from '@warp-drive/core-types/spec/raw';
4
+ import type { AdapterPayload } from './minimum-adapter-interface';
5
+ import type { MinimumSerializerInterface, RequestType } from './minimum-serializer-interface';
6
+ export declare function normalizeResponseHelper(serializer: MinimumSerializerInterface | null, store: Store, modelClass: ModelSchema, payload: AdapterPayload, id: string | null, requestType: RequestType): JsonApiDocument;
7
+ //# sourceMappingURL=serializer-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializer-response.d.ts","sourceRoot":"","sources":["../../src/legacy-network-handler/serializer-response.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AA8D9F,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,0BAA0B,GAAG,IAAI,EAC7C,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,cAAc,EACvB,EAAE,EAAE,MAAM,GAAG,IAAI,EACjB,WAAW,EAAE,WAAW,GACvB,eAAe,CAQjB"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ @module @ember-data/legacy-compat
3
+ */
4
+ import type Store from '@ember-data/store';
5
+ import type IdentifierArray from '@ember-data/store/-private/record-arrays/identifier-array';
6
+ import type { ModelSchema } from '@ember-data/store/-types/q/ds-model';
7
+ import type { FindAllOptions } from '@ember-data/store/-types/q/store';
8
+ import type Snapshot from './snapshot';
9
+ /**
10
+ SnapshotRecordArray is not directly instantiable.
11
+ Instances are provided to consuming application's
12
+ adapters for certain `findAll` requests.
13
+
14
+ @class SnapshotRecordArray
15
+ @public
16
+ */
17
+ export default class SnapshotRecordArray {
18
+ _snapshots: Snapshot[] | null;
19
+ _type: ModelSchema | null;
20
+ modelName: string;
21
+ __store: Store;
22
+ adapterOptions?: Record<string, unknown>;
23
+ include?: string | string[];
24
+ /**
25
+ SnapshotRecordArray is not directly instantiable.
26
+ Instances are provided to consuming application's
27
+ adapters and serializers for certain requests.
28
+
29
+ @method constructor
30
+ @private
31
+ @constructor
32
+ @param {Store} store
33
+ @param {string} type
34
+ @param options
35
+ */
36
+ constructor(store: Store, type: string, options?: FindAllOptions);
37
+ /**
38
+ An array of records
39
+
40
+ @property _recordArray
41
+ @private
42
+ @type {Array}
43
+ */
44
+ get _recordArray(): IdentifierArray;
45
+ /**
46
+ Number of records in the array
47
+
48
+ Example
49
+
50
+ ```app/adapters/post.js
51
+ import JSONAPIAdapter from '@ember-data/adapter/json-api';
52
+
53
+ export default class PostAdapter extends JSONAPIAdapter {
54
+ shouldReloadAll(store, snapshotRecordArray) {
55
+ return !snapshotRecordArray.length;
56
+ }
57
+ });
58
+ ```
59
+
60
+ @property length
61
+ @public
62
+ @type {Number}
63
+ */
64
+ get length(): number;
65
+ /**
66
+ Get snapshots of the underlying record array
67
+
68
+ Example
69
+
70
+ ```app/adapters/post.js
71
+ import JSONAPIAdapter from '@ember-data/adapter/json-api';
72
+
73
+ export default class PostAdapter extends JSONAPIAdapter {
74
+ shouldReloadAll(store, snapshotArray) {
75
+ let snapshots = snapshotArray.snapshots();
76
+
77
+ return snapshots.any(function(ticketSnapshot) {
78
+ let timeDiff = moment().diff(ticketSnapshot.attr('lastAccessedAt'), 'minutes');
79
+ if (timeDiff > 20) {
80
+ return true;
81
+ } else {
82
+ return false;
83
+ }
84
+ });
85
+ }
86
+ }
87
+ ```
88
+
89
+ @method snapshots
90
+ @public
91
+ @return {Array} Array of snapshots
92
+ */
93
+ snapshots(): Snapshot<unknown>[];
94
+ }
95
+ //# sourceMappingURL=snapshot-record-array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-record-array.d.ts","sourceRoot":"","sources":["../../src/legacy-network-handler/snapshot-record-array.ts"],"names":[],"mappings":"AAAA;;EAEE;AACF,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,KAAK,eAAe,MAAM,2DAA2D,CAAC;AAC7F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAIvE,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC;;;;;;;EAOE;AACF,MAAM,CAAC,OAAO,OAAO,mBAAmB;IAC9B,UAAU,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC9B,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,KAAK,CAAC;IAEf,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEpC;;;;;;;;;;;OAWG;gBACS,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAkEpE;;;;;;MAME;IACF,IAAI,YAAY,IAAI,eAAe,CAElC;IAED;;;;;;;;;;;;;;;;;;QAkBI;IACJ,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;MA2BE;IACF,SAAS;CAaV"}
@@ -0,0 +1,246 @@
1
+ import type Store from '@ember-data/store';
2
+ import type { FindRecordOptions } from '@ember-data/store/-types/q/store';
3
+ import type { StableRecordIdentifier } from '@warp-drive/core-types';
4
+ import type { ChangedAttributesHash } from '@warp-drive/core-types/cache';
5
+ import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
6
+ import type { AttributeSchema, RelationshipSchema } from '@warp-drive/core-types/schema';
7
+ import type { SerializerOptions } from './minimum-serializer-interface';
8
+ type RecordId = string | null;
9
+ /**
10
+ Snapshot is not directly instantiable.
11
+ Instances are provided to a consuming application's
12
+ adapters and serializers for certain requests.
13
+
14
+ Snapshots are only available when using `@ember-data/legacy-compat`
15
+ for legacy compatibility with adapters and serializers.
16
+
17
+ @class Snapshot
18
+ @public
19
+ */
20
+ export default class Snapshot<R = unknown> {
21
+ __attributes: Record<keyof R & string, unknown> | null;
22
+ _belongsToRelationships: Record<string, Snapshot>;
23
+ _belongsToIds: Record<string, RecordId>;
24
+ _hasManyRelationships: Record<string, Snapshot[]>;
25
+ _hasManyIds: Record<string, RecordId[]>;
26
+ _changedAttributes: ChangedAttributesHash;
27
+ identifier: StableRecordIdentifier<R extends TypedRecordInstance ? TypeFromInstance<R> : string>;
28
+ modelName: R extends TypedRecordInstance ? TypeFromInstance<R> : string;
29
+ id: string | null;
30
+ include?: string | string[];
31
+ adapterOptions?: Record<string, unknown>;
32
+ _store: Store;
33
+ /**
34
+ * @method constructor
35
+ * @constructor
36
+ * @private
37
+ * @param options
38
+ * @param identifier
39
+ * @param _store
40
+ */
41
+ constructor(options: FindRecordOptions, identifier: StableRecordIdentifier<R extends TypedRecordInstance ? TypeFromInstance<R> : string>, store: Store);
42
+ /**
43
+ The underlying record for this snapshot. Can be used to access methods and
44
+ properties defined on the record.
45
+
46
+ Example
47
+
48
+ ```javascript
49
+ let json = snapshot.record.toJSON();
50
+ ```
51
+
52
+ @property record
53
+ @type {Model}
54
+ @public
55
+ */
56
+ get record(): R | null;
57
+ get _attributes(): Record<keyof R & string, unknown>;
58
+ get isNew(): boolean;
59
+ /**
60
+ Returns the value of an attribute.
61
+
62
+ Example
63
+
64
+ ```javascript
65
+ // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
66
+ postSnapshot.attr('author'); // => 'Tomster'
67
+ postSnapshot.attr('title'); // => 'Ember.js rocks'
68
+ ```
69
+
70
+ Note: Values are loaded eagerly and cached when the snapshot is created.
71
+
72
+ @method attr
73
+ @param {String} keyName
74
+ @return {Object} The attribute value or undefined
75
+ @public
76
+ */
77
+ attr(keyName: keyof R & string): unknown;
78
+ /**
79
+ Returns all attributes and their corresponding values.
80
+
81
+ Example
82
+
83
+ ```javascript
84
+ // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
85
+ postSnapshot.attributes(); // => { author: 'Tomster', title: 'Ember.js rocks' }
86
+ ```
87
+
88
+ @method attributes
89
+ @return {Object} All attributes of the current snapshot
90
+ @public
91
+ */
92
+ attributes(): Record<keyof R & string, unknown>;
93
+ /**
94
+ Returns all changed attributes and their old and new values.
95
+
96
+ Example
97
+
98
+ ```javascript
99
+ // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
100
+ postModel.set('title', 'Ember.js rocks!');
101
+ postSnapshot.changedAttributes(); // => { title: ['Ember.js rocks', 'Ember.js rocks!'] }
102
+ ```
103
+
104
+ @method changedAttributes
105
+ @return {Object} All changed attributes of the current snapshot
106
+ @public
107
+ */
108
+ changedAttributes(): ChangedAttributesHash;
109
+ /**
110
+ Returns the current value of a belongsTo relationship.
111
+
112
+ `belongsTo` takes an optional hash of options as a second parameter,
113
+ currently supported options are:
114
+
115
+ - `id`: set to `true` if you only want the ID of the related record to be
116
+ returned.
117
+
118
+ Example
119
+
120
+ ```javascript
121
+ // store.push('post', { id: 1, title: 'Hello World' });
122
+ // store.createRecord('comment', { body: 'Lorem ipsum', post: post });
123
+ commentSnapshot.belongsTo('post'); // => Snapshot
124
+ commentSnapshot.belongsTo('post', { id: true }); // => '1'
125
+
126
+ // store.push('comment', { id: 1, body: 'Lorem ipsum' });
127
+ commentSnapshot.belongsTo('post'); // => undefined
128
+ ```
129
+
130
+ Calling `belongsTo` will return a new Snapshot as long as there's any known
131
+ data for the relationship available, such as an ID. If the relationship is
132
+ known but unset, `belongsTo` will return `null`. If the contents of the
133
+ relationship is unknown `belongsTo` will return `undefined`.
134
+
135
+ Note: Relationships are loaded lazily and cached upon first access.
136
+
137
+ @method belongsTo
138
+ @param {String} keyName
139
+ @param {Object} [options]
140
+ @public
141
+ @return {(Snapshot|String|null|undefined)} A snapshot or ID of a known
142
+ relationship or null if the relationship is known but unset. undefined
143
+ will be returned if the contents of the relationship is unknown.
144
+ */
145
+ belongsTo(keyName: string, options?: {
146
+ id?: boolean;
147
+ }): Snapshot | RecordId | undefined;
148
+ /**
149
+ Returns the current value of a hasMany relationship.
150
+
151
+ `hasMany` takes an optional hash of options as a second parameter,
152
+ currently supported options are:
153
+
154
+ - `ids`: set to `true` if you only want the IDs of the related records to be
155
+ returned.
156
+
157
+ Example
158
+
159
+ ```javascript
160
+ // store.push('post', { id: 1, title: 'Hello World', comments: [2, 3] });
161
+ postSnapshot.hasMany('comments'); // => [Snapshot, Snapshot]
162
+ postSnapshot.hasMany('comments', { ids: true }); // => ['2', '3']
163
+
164
+ // store.push('post', { id: 1, title: 'Hello World' });
165
+ postSnapshot.hasMany('comments'); // => undefined
166
+ ```
167
+
168
+ Note: Relationships are loaded lazily and cached upon first access.
169
+
170
+ @method hasMany
171
+ @param {String} keyName
172
+ @param {Object} [options]
173
+ @public
174
+ @return {(Array|undefined)} An array of snapshots or IDs of a known
175
+ relationship or an empty array if the relationship is known but unset.
176
+ undefined will be returned if the contents of the relationship is unknown.
177
+ */
178
+ hasMany(keyName: string, options?: {
179
+ ids?: boolean;
180
+ }): RecordId[] | Snapshot[] | undefined;
181
+ /**
182
+ Iterates through all the attributes of the model, calling the passed
183
+ function on each attribute.
184
+
185
+ Example
186
+
187
+ ```javascript
188
+ snapshot.eachAttribute(function(name, meta) {
189
+ // ...
190
+ });
191
+ ```
192
+
193
+ @method eachAttribute
194
+ @param {Function} callback the callback to execute
195
+ @param {Object} [binding] the value to which the callback's `this` should be bound
196
+ @public
197
+ */
198
+ eachAttribute(callback: (key: string, meta: AttributeSchema) => void, binding?: unknown): void;
199
+ /**
200
+ Iterates through all the relationships of the model, calling the passed
201
+ function on each relationship.
202
+
203
+ Example
204
+
205
+ ```javascript
206
+ snapshot.eachRelationship(function(name, relationship) {
207
+ // ...
208
+ });
209
+ ```
210
+
211
+ @method eachRelationship
212
+ @param {Function} callback the callback to execute
213
+ @param {Object} [binding] the value to which the callback's `this` should be bound
214
+ @public
215
+ */
216
+ eachRelationship(callback: (key: string, meta: RelationshipSchema) => void, binding?: unknown): void;
217
+ /**
218
+ Serializes the snapshot using the serializer for the model.
219
+
220
+ Example
221
+
222
+ ```app/adapters/application.js
223
+ import Adapter from '@ember-data/adapter';
224
+
225
+ export default Adapter.extend({
226
+ createRecord(store, type, snapshot) {
227
+ let data = snapshot.serialize({ includeId: true });
228
+ let url = `/${type.modelName}`;
229
+
230
+ return fetch(url, {
231
+ method: 'POST',
232
+ body: data,
233
+ }).then((response) => response.json())
234
+ }
235
+ });
236
+ ```
237
+
238
+ @method serialize
239
+ @param {Object} options
240
+ @return {Object} an object whose values are primitive JSON values only
241
+ @public
242
+ */
243
+ serialize(options?: SerializerOptions): unknown;
244
+ }
245
+ export {};
246
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/legacy-network-handler/snapshot.ts"],"names":[],"mappings":"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"}