@ember-data/legacy-compat 5.3.3 → 5.3.4

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