@ember-data/legacy-compat 5.5.0-alpha.2 → 5.5.0-alpha.21

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 (71) hide show
  1. package/LICENSE.md +19 -7
  2. package/README.md +10 -2
  3. package/addon-main.cjs +5 -0
  4. package/{addon/fetch-manager-0744e8e9.js → dist/-private-Dlia0pw1.js} +252 -125
  5. package/dist/-private-Dlia0pw1.js.map +1 -0
  6. package/dist/-private.js +1 -0
  7. package/dist/builders.js +323 -0
  8. package/dist/builders.js.map +1 -0
  9. package/dist/index.js +1011 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/utils.js +246 -0
  12. package/dist/utils.js.map +1 -0
  13. package/logos/NCC-1701-a-blue.svg +4 -0
  14. package/logos/NCC-1701-a-gold.svg +4 -0
  15. package/logos/NCC-1701-a-gold_100.svg +1 -0
  16. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  17. package/logos/NCC-1701-a.svg +4 -0
  18. package/logos/README.md +4 -0
  19. package/logos/docs-badge.svg +2 -0
  20. package/logos/github-header.svg +444 -0
  21. package/logos/social1.png +0 -0
  22. package/logos/social2.png +0 -0
  23. package/logos/warp-drive-logo-dark.svg +4 -0
  24. package/logos/warp-drive-logo-gold.svg +4 -0
  25. package/package.json +58 -49
  26. package/unstable-preview-types/-private.d.ts +17 -0
  27. package/unstable-preview-types/-private.d.ts.map +1 -0
  28. package/unstable-preview-types/builders/find-all.d.ts +41 -0
  29. package/unstable-preview-types/builders/find-all.d.ts.map +1 -0
  30. package/unstable-preview-types/builders/find-record.d.ts +62 -0
  31. package/unstable-preview-types/builders/find-record.d.ts.map +1 -0
  32. package/unstable-preview-types/builders/query.d.ts +72 -0
  33. package/unstable-preview-types/builders/query.d.ts.map +1 -0
  34. package/unstable-preview-types/builders/save-record.d.ts +40 -0
  35. package/unstable-preview-types/builders/save-record.d.ts.map +1 -0
  36. package/unstable-preview-types/builders/utils.d.ts +6 -0
  37. package/unstable-preview-types/builders/utils.d.ts.map +1 -0
  38. package/unstable-preview-types/builders.d.ts +18 -0
  39. package/unstable-preview-types/builders.d.ts.map +1 -0
  40. package/unstable-preview-types/index.d.ts +162 -0
  41. package/unstable-preview-types/index.d.ts.map +1 -0
  42. package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts +49 -0
  43. package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts.map +1 -0
  44. package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts +5 -0
  45. package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts.map +1 -0
  46. package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts +14 -0
  47. package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -0
  48. package/unstable-preview-types/legacy-network-handler/legacy-data-utils.d.ts +8 -0
  49. package/unstable-preview-types/legacy-network-handler/legacy-data-utils.d.ts.map +1 -0
  50. package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts +5 -0
  51. package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts.map +1 -0
  52. package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts +549 -0
  53. package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -0
  54. package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts +235 -0
  55. package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -0
  56. package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts +9 -0
  57. package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts.map +1 -0
  58. package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts +96 -0
  59. package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts.map +1 -0
  60. package/unstable-preview-types/legacy-network-handler/snapshot.d.ts +248 -0
  61. package/unstable-preview-types/legacy-network-handler/snapshot.d.ts.map +1 -0
  62. package/unstable-preview-types/utils.d.ts +161 -0
  63. package/unstable-preview-types/utils.d.ts.map +1 -0
  64. package/addon/-private.js +0 -1
  65. package/addon/fetch-manager-0744e8e9.js.map +0 -1
  66. package/addon/index.js +0 -617
  67. package/addon/index.js.map +0 -1
  68. package/addon-main.js +0 -93
  69. /package/{addon → dist}/-private.js.map +0 -0
  70. /package/{ember-data-logo-dark.svg → logos/ember-data-logo-dark.svg} +0 -0
  71. /package/{ember-data-logo-light.svg → logos/ember-data-logo-light.svg} +0 -0
package/dist/index.js ADDED
@@ -0,0 +1,1011 @@
1
+ import { getOwner } from '@ember/application';
2
+ import { recordIdentifierFor } from '@ember-data/store';
3
+ import { _deprecatingNormalize } from '@ember-data/store/-private';
4
+ import { p as payloadIsNotBlank, n as normalizeResponseHelper, i as iterateData, F as FetchManager, S as SaveOp, a as assertIdentifierHasId, b as SnapshotRecordArray } from "./-private-Dlia0pw1.js";
5
+ import { macroCondition, getGlobalConfig, importSync } from '@embroider/macros';
6
+ function _findHasMany(adapter, store, identifier, link, relationship, options) {
7
+ const promise = Promise.resolve().then(() => {
8
+ const snapshot = store._fetchManager.createSnapshot(identifier, options);
9
+ const useLink = !link || typeof link === 'string';
10
+ const relatedLink = useLink ? link : link.href;
11
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
12
+ if (!test) {
13
+ throw new Error(`Attempted to load a hasMany relationship from a specified 'link' in the original payload, but the specified link is empty. You must provide a valid 'link' in the original payload to use 'findHasMany'`);
14
+ }
15
+ })(relatedLink) : {};
16
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
17
+ if (!test) {
18
+ throw new Error(`Expected the adapter to implement 'findHasMany' but it does not`);
19
+ }
20
+ })(typeof adapter.findHasMany === 'function') : {};
21
+ return adapter.findHasMany(store, snapshot, relatedLink, relationship);
22
+ });
23
+ return promise.then(adapterPayload => {
24
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
25
+ if (!test) {
26
+ throw new Error(`You made a 'findHasMany' request for a ${identifier.type}'s '${relationship.name}' relationship, using link '${JSON.stringify(link)}' , but the adapter's response did not have any data`);
27
+ }
28
+ })(payloadIsNotBlank(adapterPayload)) : {};
29
+ const modelClass = store.modelFor(relationship.type);
30
+ const serializer = store.serializerFor(relationship.type);
31
+ let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findHasMany');
32
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
33
+ if (!test) {
34
+ throw new Error(`fetched the hasMany relationship '${relationship.name}' for ${identifier.type}:${identifier.id} with link '${JSON.stringify(link)}', but no data member is present in the response. If no data exists, the response should set { data: [] }`);
35
+ }
36
+ })('data' in payload && Array.isArray(payload.data)) : {};
37
+ payload = syncRelationshipDataFromLink(store, payload, identifier, relationship);
38
+ return store._push(payload, true);
39
+ }, null);
40
+ }
41
+ function _findBelongsTo(store, identifier, link, relationship, options) {
42
+ const promise = Promise.resolve().then(() => {
43
+ const adapter = store.adapterFor(identifier.type);
44
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
45
+ if (!test) {
46
+ throw new Error(`You tried to load a belongsTo relationship but you have no adapter (for ${identifier.type})`);
47
+ }
48
+ })(adapter) : {};
49
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
50
+ if (!test) {
51
+ throw new Error(`You tried to load a belongsTo relationship from a specified 'link' in the original payload but your adapter does not implement 'findBelongsTo'`);
52
+ }
53
+ })(typeof adapter.findBelongsTo === 'function') : {};
54
+ const snapshot = store._fetchManager.createSnapshot(identifier, options);
55
+ const useLink = !link || typeof link === 'string';
56
+ const relatedLink = useLink ? link : link.href;
57
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
58
+ if (!test) {
59
+ throw new Error(`Attempted to load a belongsTo relationship from a specified 'link' in the original payload, but the specified link is empty. You must provide a valid 'link' in the original payload to use 'findBelongsTo'`);
60
+ }
61
+ })(relatedLink) : {};
62
+ return adapter.findBelongsTo(store, snapshot, relatedLink, relationship);
63
+ });
64
+ return promise.then(adapterPayload => {
65
+ const modelClass = store.modelFor(relationship.type);
66
+ const serializer = store.serializerFor(relationship.type);
67
+ let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findBelongsTo');
68
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
69
+ if (!test) {
70
+ throw new Error(`fetched the belongsTo relationship '${relationship.name}' for ${identifier.type}:${identifier.id} with link '${JSON.stringify(link)}', but no data member is present in the response. If no data exists, the response should set { data: null }`);
71
+ }
72
+ })('data' in payload && (payload.data === null || typeof payload.data === 'object' && !Array.isArray(payload.data))) : {};
73
+ if (!payload.data && !payload.links && !payload.meta) {
74
+ return null;
75
+ }
76
+ payload = syncRelationshipDataFromLink(store, payload, identifier, relationship);
77
+ return store._push(payload, true);
78
+ }, null);
79
+ }
80
+
81
+ // sync
82
+ // iterate over records in payload.data
83
+ // for each record
84
+ // assert that record.relationships[inverse] is either undefined (so we can fix it)
85
+ // or provide a data: {id, type} that matches the record that requested it
86
+ // return the relationship data for the parent
87
+ function syncRelationshipDataFromLink(store, payload, parentIdentifier, relationship) {
88
+ // ensure the right hand side (incoming payload) points to the parent record that
89
+ // requested this relationship
90
+ const relationshipData = payload.data ? iterateData(payload.data, (data, index) => {
91
+ const {
92
+ id,
93
+ type
94
+ } = data;
95
+ ensureRelationshipIsSetToParent(data, parentIdentifier, store, relationship, index);
96
+ return {
97
+ id,
98
+ type
99
+ };
100
+ }) : null;
101
+ const relatedDataHash = {};
102
+ if ('meta' in payload) {
103
+ relatedDataHash.meta = payload.meta;
104
+ }
105
+ if ('links' in payload) {
106
+ relatedDataHash.links = payload.links;
107
+ }
108
+ if ('data' in payload) {
109
+ relatedDataHash.data = relationshipData;
110
+ }
111
+
112
+ // now, push the left hand side (the parent record) to ensure things are in sync, since
113
+ // the payload will be pushed with store._push
114
+ const parentPayload = {
115
+ id: parentIdentifier.id,
116
+ type: parentIdentifier.type,
117
+ relationships: {
118
+ [relationship.name]: relatedDataHash
119
+ }
120
+ };
121
+ if (!Array.isArray(payload.included)) {
122
+ payload.included = [];
123
+ }
124
+ payload.included.push(parentPayload);
125
+ return payload;
126
+ }
127
+ function ensureRelationshipIsSetToParent(payload, parentIdentifier, store, parentRelationship, index) {
128
+ const {
129
+ id,
130
+ type
131
+ } = payload;
132
+ if (!payload.relationships) {
133
+ payload.relationships = {};
134
+ }
135
+ const {
136
+ relationships
137
+ } = payload;
138
+ const inverse = getInverse(store, parentIdentifier, parentRelationship, type);
139
+ if (inverse) {
140
+ const {
141
+ inverseKey,
142
+ kind
143
+ } = inverse;
144
+ const relationshipData = relationships[inverseKey]?.data;
145
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
146
+ if (typeof relationshipData !== 'undefined' && !relationshipDataPointsToParent(relationshipData, parentIdentifier)) {
147
+ const inspect = function inspect(thing) {
148
+ return `'${JSON.stringify(thing)}'`;
149
+ };
150
+ const quotedType = inspect(type);
151
+ const quotedInverse = inspect(inverseKey);
152
+ const expected = inspect({
153
+ id: parentIdentifier.id,
154
+ type: parentIdentifier.type
155
+ });
156
+ const expectedModel = `${parentIdentifier.type}:${parentIdentifier.id}`;
157
+ const got = inspect(relationshipData);
158
+ const prefix = typeof index === 'number' ? `data[${index}]` : `data`;
159
+ const path = `${prefix}.relationships.${inverseKey}.data`;
160
+ const data = Array.isArray(relationshipData) ? relationshipData[0] : relationshipData;
161
+ const other = data ? `<${data.type}:${data.id}>` : null;
162
+ const relationshipFetched = `${expectedModel}.${parentRelationship.kind}("${parentRelationship.name}")`;
163
+ const includedRecord = `<${type}:${id}>`;
164
+ const message = [`Encountered mismatched relationship: Ember Data expected ${path} in the payload from ${relationshipFetched} to include ${expected} but got ${got} instead.\n`, `The ${includedRecord} record loaded at ${prefix} in the payload specified ${other} as its ${quotedInverse}, but should have specified ${expectedModel} (the record the relationship is being loaded from) as its ${quotedInverse} instead.`, `This could mean that the response for ${relationshipFetched} may have accidentally returned ${quotedType} records that aren't related to ${expectedModel} and could be related to a different ${parentIdentifier.type} record instead.`, `Ember Data has corrected the ${includedRecord} record's ${quotedInverse} relationship to ${expectedModel} so that ${relationshipFetched} will include ${includedRecord}.`, `Please update the response from the server or change your serializer to either ensure that the response for only includes ${quotedType} records that specify ${expectedModel} as their ${quotedInverse}, or omit the ${quotedInverse} relationship from the response.`].join('\n');
165
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
166
+ {
167
+ throw new Error(message);
168
+ }
169
+ })() : {};
170
+ }
171
+ }
172
+ if (kind !== 'hasMany' || typeof relationshipData !== 'undefined') {
173
+ relationships[inverseKey] = relationships[inverseKey] || {};
174
+ relationships[inverseKey].data = fixRelationshipData(relationshipData ?? null, kind, parentIdentifier);
175
+ }
176
+ }
177
+ }
178
+ function inverseForRelationship(store, identifier, key) {
179
+ const definition = store.schema.fields(identifier).get(key);
180
+ if (!definition) {
181
+ return null;
182
+ }
183
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
184
+ if (!test) {
185
+ throw new Error(`Expected the field definition to be a relationship`);
186
+ }
187
+ })(definition.kind === 'hasMany' || definition.kind === 'belongsTo') : {};
188
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
189
+ if (!test) {
190
+ throw new Error(`Expected the relationship defintion to specify the inverse type or null.`);
191
+ }
192
+ })(definition.options?.inverse === null || typeof definition.options?.inverse === 'string' && definition.options.inverse.length > 0) : {};
193
+ return definition.options.inverse;
194
+ }
195
+ function getInverse(store, parentIdentifier, parentRelationship, type) {
196
+ const {
197
+ name: lhs_relationshipName
198
+ } = parentRelationship;
199
+ const {
200
+ type: parentType
201
+ } = parentIdentifier;
202
+ const inverseKey = inverseForRelationship(store, {
203
+ type: parentType
204
+ }, lhs_relationshipName);
205
+ if (inverseKey) {
206
+ const definition = store.schema.fields({
207
+ type
208
+ }).get(inverseKey);
209
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
210
+ if (!test) {
211
+ throw new Error(`Expected the field definition to be a relationship`);
212
+ }
213
+ })(definition && (definition.kind === 'hasMany' || definition.kind === 'belongsTo')) : {};
214
+ return {
215
+ inverseKey,
216
+ kind: definition.kind
217
+ };
218
+ }
219
+ }
220
+ function relationshipDataPointsToParent(relationshipData, identifier) {
221
+ if (relationshipData === null) {
222
+ return false;
223
+ }
224
+ if (Array.isArray(relationshipData)) {
225
+ if (relationshipData.length === 0) {
226
+ return false;
227
+ }
228
+ for (let i = 0; i < relationshipData.length; i++) {
229
+ const entry = relationshipData[i];
230
+ if (validateRelationshipEntry(entry, identifier)) {
231
+ return true;
232
+ }
233
+ }
234
+ } else {
235
+ return validateRelationshipEntry(relationshipData, identifier);
236
+ }
237
+ return false;
238
+ }
239
+ function fixRelationshipData(relationshipData, relationshipKind, {
240
+ id,
241
+ type
242
+ }) {
243
+ const parentRelationshipData = {
244
+ id,
245
+ type
246
+ };
247
+ let payload = null;
248
+ if (relationshipKind === 'hasMany') {
249
+ const relData = relationshipData || [];
250
+ if (relationshipData) {
251
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
252
+ if (!test) {
253
+ throw new Error('expected the relationship data to be an array');
254
+ }
255
+ })(Array.isArray(relationshipData)) : {};
256
+ // these arrays could be massive so this is better than filter
257
+ // Note: this is potentially problematic if type/id are not in the
258
+ // same state of normalization.
259
+ const found = relationshipData.find(v => {
260
+ return v.type === parentRelationshipData.type && v.id === parentRelationshipData.id;
261
+ });
262
+ if (!found) {
263
+ relData.push(parentRelationshipData);
264
+ }
265
+ } else {
266
+ relData.push(parentRelationshipData);
267
+ }
268
+ payload = relData;
269
+ } else {
270
+ const relData = relationshipData || {};
271
+ Object.assign(relData, parentRelationshipData);
272
+ payload = relData;
273
+ }
274
+ return payload;
275
+ }
276
+ function validateRelationshipEntry({
277
+ id
278
+ }, {
279
+ id: parentModelID
280
+ }) {
281
+ return !!id && id.toString() === parentModelID;
282
+ }
283
+ const PotentialLegacyOperations = new Set(['findRecord', 'findAll', 'query', 'queryRecord', 'findBelongsTo', 'findHasMany', 'updateRecord', 'createRecord', 'deleteRecord']);
284
+ const LegacyNetworkHandler = {
285
+ request(context, next) {
286
+ // if we are not a legacy request, move on
287
+ if (context.request.url || !context.request.op || !PotentialLegacyOperations.has(context.request.op)) {
288
+ return next(context.request);
289
+ }
290
+ const {
291
+ store
292
+ } = context.request;
293
+ if (!store._fetchManager) {
294
+ store._fetchManager = new FetchManager(store);
295
+ }
296
+ switch (context.request.op) {
297
+ case 'findRecord':
298
+ return findRecord(context);
299
+ case 'findAll':
300
+ return findAll(context);
301
+ case 'query':
302
+ return query(context);
303
+ case 'queryRecord':
304
+ return queryRecord(context);
305
+ case 'findBelongsTo':
306
+ return findBelongsTo(context);
307
+ case 'findHasMany':
308
+ return findHasMany(context);
309
+ case 'updateRecord':
310
+ return saveRecord(context);
311
+ case 'createRecord':
312
+ return saveRecord(context);
313
+ case 'deleteRecord':
314
+ return saveRecord(context);
315
+ default:
316
+ return next(context.request);
317
+ }
318
+ }
319
+ };
320
+ function findBelongsTo(context) {
321
+ const {
322
+ store,
323
+ data,
324
+ records: identifiers
325
+ } = context.request;
326
+ const {
327
+ options,
328
+ record,
329
+ links,
330
+ useLink,
331
+ field
332
+ } = data;
333
+ const identifier = identifiers?.[0];
334
+
335
+ // short circuit if we are already loading
336
+ const pendingRequest = identifier && store._fetchManager.getPendingFetch(identifier, options);
337
+ if (pendingRequest) {
338
+ return pendingRequest;
339
+ }
340
+ if (useLink) {
341
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
342
+ if (!test) {
343
+ throw new Error(`Expected a related link when calling store.findBelongsTo, found ${String(links)}`);
344
+ }
345
+ })(links && links.related) : {};
346
+ return _findBelongsTo(store, record, links.related, field, options);
347
+ }
348
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
349
+ if (!test) {
350
+ throw new Error(`Expected an identifier`);
351
+ }
352
+ })(Array.isArray(identifiers) && identifiers.length === 1) : {};
353
+ const manager = store._fetchManager;
354
+ assertIdentifierHasId(identifier);
355
+ return options.reload ? manager.scheduleFetch(identifier, options, context.request) : manager.fetchDataIfNeededForIdentifier(identifier, options, context.request);
356
+ }
357
+ function findHasMany(context) {
358
+ const {
359
+ store,
360
+ data,
361
+ records: identifiers
362
+ } = context.request;
363
+ const {
364
+ options,
365
+ record,
366
+ links,
367
+ useLink,
368
+ field
369
+ } = data;
370
+
371
+ // link case
372
+ if (useLink) {
373
+ const adapter = store.adapterFor(record.type);
374
+ /*
375
+ If a relationship was originally populated by the adapter as a link
376
+ (as opposed to a list of IDs), this method is called when the
377
+ relationship is fetched.
378
+ The link (which is usually a URL) is passed through unchanged, so the
379
+ adapter can make whatever request it wants.
380
+ The usual use-case is for the server to register a URL as a link, and
381
+ then use that URL in the future to make a request for the relationship.
382
+ */
383
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
384
+ if (!test) {
385
+ throw new Error(`You tried to load a hasMany relationship but you have no adapter (for ${record.type})`);
386
+ }
387
+ })(adapter) : {};
388
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
389
+ if (!test) {
390
+ throw new Error(`You tried to load a hasMany relationship from a specified 'link' in the original payload but your adapter does not implement 'findHasMany'`);
391
+ }
392
+ })(typeof adapter.findHasMany === 'function') : {};
393
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
394
+ if (!test) {
395
+ throw new Error(`Expected a related link when calling store.findHasMany, found ${String(links)}`);
396
+ }
397
+ })(links && links.related) : {};
398
+ return _findHasMany(adapter, store, record, links.related, field, options);
399
+ }
400
+
401
+ // identifiers case
402
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
403
+ if (!test) {
404
+ throw new Error(`Expected an array of identifiers to fetch`);
405
+ }
406
+ })(Array.isArray(identifiers)) : {};
407
+ const fetches = new Array(identifiers.length);
408
+ const manager = store._fetchManager;
409
+ for (let i = 0; i < identifiers.length; i++) {
410
+ const identifier = identifiers[i];
411
+ // TODO we probably can be lenient here and return from cache for the isNew case
412
+ assertIdentifierHasId(identifier);
413
+ fetches[i] = options.reload ? manager.scheduleFetch(identifier, options, context.request) : manager.fetchDataIfNeededForIdentifier(identifier, options, context.request);
414
+ }
415
+ return Promise.all(fetches);
416
+ }
417
+ function saveRecord(context) {
418
+ const {
419
+ store,
420
+ data,
421
+ op: operation
422
+ } = context.request;
423
+ const {
424
+ options,
425
+ record: identifier
426
+ } = data;
427
+ store.cache.willCommit(identifier, context);
428
+ const saveOptions = Object.assign({
429
+ [SaveOp]: operation
430
+ }, options);
431
+ const fetchManagerPromise = store._fetchManager.scheduleSave(identifier, saveOptions);
432
+ return fetchManagerPromise.then(payload => {
433
+ let result;
434
+ store._join(() => {
435
+ // @ts-expect-error we don't have access to a response in legacy
436
+ result = store.cache.didCommit(identifier, {
437
+ request: context.request,
438
+ content: payload
439
+ });
440
+ });
441
+
442
+ // blatantly lie if we were a createRecord request
443
+ // to give some semblance of cache-control to the
444
+ // CachePolicy while legacy is still around
445
+ if (store.lifetimes?.didRequest && operation === 'createRecord') {
446
+ store.lifetimes.didRequest(context.request, {
447
+ status: 201
448
+ }, null, store);
449
+ }
450
+ return store.peekRecord(result.data);
451
+ }).catch(e => {
452
+ let err = e;
453
+ if (!e) {
454
+ err = new Error(`Unknown Error Occurred During Request`);
455
+ } else if (typeof e === 'string') {
456
+ err = new Error(e);
457
+ }
458
+ adapterDidInvalidate(store, identifier, err);
459
+ throw err;
460
+ });
461
+ }
462
+ function adapterDidInvalidate(store, identifier, error) {
463
+ if (error && error.isAdapterError === true && error.code === 'InvalidError') {
464
+ const serializer = store.serializerFor(identifier.type);
465
+
466
+ // TODO @deprecate extractErrors being called
467
+ // TODO remove extractErrors from the default serializers.
468
+ if (serializer && typeof serializer.extractErrors === 'function') {
469
+ const errorsHash = serializer.extractErrors(store, store.modelFor(identifier.type), error, identifier.id);
470
+ error.errors = errorsHashToArray(errorsHash);
471
+ }
472
+ }
473
+ const cache = store.cache;
474
+ if (error.errors) {
475
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
476
+ if (!test) {
477
+ throw new Error(`Expected the cache in use by resource ${String(identifier)} to have a getErrors(identifier) method for retrieving errors.`);
478
+ }
479
+ })(typeof cache.getErrors === 'function') : {};
480
+ let jsonApiErrors = error.errors;
481
+ if (jsonApiErrors.length === 0) {
482
+ jsonApiErrors = [{
483
+ title: 'Invalid Error',
484
+ detail: '',
485
+ source: {
486
+ pointer: '/data'
487
+ }
488
+ }];
489
+ }
490
+ cache.commitWasRejected(identifier, jsonApiErrors);
491
+ } else {
492
+ cache.commitWasRejected(identifier);
493
+ }
494
+ }
495
+ function makeArray(value) {
496
+ return Array.isArray(value) ? value : [value];
497
+ }
498
+ const PRIMARY_ATTRIBUTE_KEY = 'base';
499
+ function errorsHashToArray(errors) {
500
+ const out = [];
501
+ if (errors) {
502
+ Object.keys(errors).forEach(key => {
503
+ const messages = makeArray(errors[key]);
504
+ for (let i = 0; i < messages.length; i++) {
505
+ let title = 'Invalid Attribute';
506
+ let pointer = `/data/attributes/${key}`;
507
+ if (key === PRIMARY_ATTRIBUTE_KEY) {
508
+ title = 'Invalid Document';
509
+ pointer = `/data`;
510
+ }
511
+ out.push({
512
+ title: title,
513
+ detail: messages[i],
514
+ source: {
515
+ pointer: pointer
516
+ }
517
+ });
518
+ }
519
+ });
520
+ }
521
+ return out;
522
+ }
523
+ function findRecord(context) {
524
+ const {
525
+ store,
526
+ data
527
+ } = context.request;
528
+ const {
529
+ record: identifier,
530
+ options
531
+ } = data;
532
+ let promise;
533
+
534
+ // if not loaded start loading
535
+ if (!store._instanceCache.recordIsLoaded(identifier)) {
536
+ promise = store._fetchManager.fetchDataIfNeededForIdentifier(identifier, options, context.request);
537
+
538
+ // Refetch if the reload option is passed
539
+ } else if (options.reload) {
540
+ assertIdentifierHasId(identifier);
541
+ promise = store._fetchManager.scheduleFetch(identifier, options, context.request);
542
+ } else {
543
+ let snapshot = null;
544
+ const adapter = store.adapterFor(identifier.type);
545
+
546
+ // Refetch the record if the adapter thinks the record is stale
547
+ if (typeof options.reload === 'undefined' && adapter.shouldReloadRecord && adapter.shouldReloadRecord(store, snapshot = store._fetchManager.createSnapshot(identifier, options))) {
548
+ assertIdentifierHasId(identifier);
549
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
550
+ promise = store._fetchManager.scheduleFetch(identifier, Object.assign({}, options, {
551
+ reload: true
552
+ }), context.request);
553
+ } else {
554
+ options.reload = true;
555
+ promise = store._fetchManager.scheduleFetch(identifier, options, context.request);
556
+ }
557
+ } else {
558
+ // Trigger the background refetch if backgroundReload option is passed
559
+ if (options.backgroundReload !== false && (options.backgroundReload || !adapter.shouldBackgroundReloadRecord || adapter.shouldBackgroundReloadRecord(store, snapshot = snapshot || store._fetchManager.createSnapshot(identifier, options)))) {
560
+ assertIdentifierHasId(identifier);
561
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
562
+ void store._fetchManager.scheduleFetch(identifier, Object.assign({}, options, {
563
+ backgroundReload: true
564
+ }), context.request);
565
+ } else {
566
+ options.backgroundReload = true;
567
+ void store._fetchManager.scheduleFetch(identifier, options, context.request);
568
+ }
569
+ }
570
+
571
+ // Return the cached record
572
+ promise = Promise.resolve(identifier);
573
+ }
574
+ }
575
+ return promise.then(i => store.peekRecord(i));
576
+ }
577
+ function findAll(context) {
578
+ const {
579
+ store,
580
+ data
581
+ } = context.request;
582
+ const {
583
+ type,
584
+ options
585
+ } = data;
586
+ const adapter = store.adapterFor(type);
587
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
588
+ if (!test) {
589
+ throw new Error(`You tried to load all records but you have no adapter (for ${type})`);
590
+ }
591
+ })(adapter) : {};
592
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
593
+ if (!test) {
594
+ throw new Error(`You tried to load all records but your adapter does not implement 'findAll'`);
595
+ }
596
+ })(typeof adapter.findAll === 'function') : {};
597
+
598
+ // avoid initializing the liveArray just to set `isUpdating`
599
+ const maybeRecordArray = store.recordArrayManager._live.get(type);
600
+ const snapshotArray = new SnapshotRecordArray(store, type, options);
601
+ const shouldReload = options.reload || options.reload !== false && (adapter.shouldReloadAll && adapter.shouldReloadAll(store, snapshotArray) || !adapter.shouldReloadAll && snapshotArray.length === 0);
602
+ let fetch;
603
+ if (shouldReload) {
604
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
605
+ maybeRecordArray && (maybeRecordArray.isUpdating = true);
606
+ fetch = _findAll(adapter, store, type, snapshotArray, context.request, true);
607
+ } else {
608
+ fetch = Promise.resolve(store.peekAll(type));
609
+ if (options.backgroundReload || options.backgroundReload !== false && (!adapter.shouldBackgroundReloadAll || adapter.shouldBackgroundReloadAll(store, snapshotArray))) {
610
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
611
+ maybeRecordArray && (maybeRecordArray.isUpdating = true);
612
+ void _findAll(adapter, store, type, snapshotArray, context.request, false);
613
+ }
614
+ }
615
+ return fetch;
616
+ }
617
+ function _findAll(adapter, store, type, snapshotArray, request, isAsyncFlush) {
618
+ const schema = store.modelFor(type);
619
+ let promise = Promise.resolve().then(() => adapter.findAll(store, schema, null, snapshotArray));
620
+ promise = promise.then(adapterPayload => {
621
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
622
+ if (!test) {
623
+ throw new Error(`You made a 'findAll' request for '${type}' records, but the adapter's response did not have any data`);
624
+ }
625
+ })(payloadIsNotBlank(adapterPayload)) : {};
626
+ const serializer = store.serializerFor(type);
627
+ const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'findAll');
628
+ store._push(payload, isAsyncFlush);
629
+ snapshotArray._recordArray.isUpdating = false;
630
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REQUESTS)) {
631
+ if (getGlobalConfig().WarpDrive.debug.LOG_REQUESTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REQUESTS) {
632
+ // eslint-disable-next-line no-console
633
+ console.log(`request: findAll<${type}> background reload complete`);
634
+ }
635
+ }
636
+ return snapshotArray._recordArray;
637
+ });
638
+ if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
639
+ if (!request.disableTestWaiter) {
640
+ const {
641
+ waitForPromise
642
+ } = importSync('@ember/test-waiters');
643
+ promise = waitForPromise(promise);
644
+ }
645
+ }
646
+ return promise;
647
+ }
648
+ function query(context) {
649
+ const {
650
+ store,
651
+ data
652
+ } = context.request;
653
+ let {
654
+ options
655
+ } = data;
656
+ // eslint-disable-next-line @typescript-eslint/no-shadow
657
+ const {
658
+ type,
659
+ query
660
+ } = data;
661
+ const adapter = store.adapterFor(type);
662
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
663
+ if (!test) {
664
+ throw new Error(`You tried to make a query but you have no adapter (for ${type})`);
665
+ }
666
+ })(adapter) : {};
667
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
668
+ if (!test) {
669
+ throw new Error(`You tried to make a query but your adapter does not implement 'query'`);
670
+ }
671
+ })(typeof adapter.query === 'function') : {};
672
+ const recordArray = options._recordArray || store.recordArrayManager.getCollection({
673
+ type,
674
+ query
675
+ });
676
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
677
+ options = Object.assign({}, options);
678
+ delete options._recordArray;
679
+ } else {
680
+ delete options._recordArray;
681
+ }
682
+ const schema = store.modelFor(type);
683
+ const promise = Promise.resolve().then(() => adapter.query(store, schema, query, recordArray, options));
684
+ return promise.then(adapterPayload => {
685
+ const serializer = store.serializerFor(type);
686
+ const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'query');
687
+ const identifiers = store._push(payload, true);
688
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
689
+ if (!test) {
690
+ throw new Error('The response to store.query is expected to be an array but it was a single record. Please wrap your response in an array or use `store.queryRecord` to query for a single record.');
691
+ }
692
+ })(Array.isArray(identifiers)) : {};
693
+ store.recordArrayManager.populateManagedArray(recordArray, identifiers, payload);
694
+ return recordArray;
695
+ });
696
+ }
697
+ function assertSingleResourceDocument(payload) {
698
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
699
+ if (!test) {
700
+ throw new Error(`Expected the primary data returned by the serializer for a 'queryRecord' response to be a single object or null but instead it was an array.`);
701
+ }
702
+ })(!Array.isArray(payload.data)) : {};
703
+ }
704
+ function queryRecord(context) {
705
+ const {
706
+ store,
707
+ data
708
+ } = context.request;
709
+ // eslint-disable-next-line @typescript-eslint/no-shadow
710
+ const {
711
+ type,
712
+ query,
713
+ options
714
+ } = data;
715
+ const adapter = store.adapterFor(type);
716
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
717
+ if (!test) {
718
+ throw new Error(`You tried to make a query but you have no adapter (for ${type})`);
719
+ }
720
+ })(adapter) : {};
721
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
722
+ if (!test) {
723
+ throw new Error(`You tried to make a query but your adapter does not implement 'queryRecord'`);
724
+ }
725
+ })(typeof adapter.queryRecord === 'function') : {};
726
+ const schema = store.modelFor(type);
727
+ const promise = Promise.resolve().then(() => adapter.queryRecord(store, schema, query, options));
728
+ return promise.then(adapterPayload => {
729
+ const serializer = store.serializerFor(type);
730
+ const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'queryRecord');
731
+ assertSingleResourceDocument(payload);
732
+ const identifier = store._push(payload, true);
733
+ return identifier ? store.peekRecord(identifier) : null;
734
+ });
735
+ }
736
+
737
+ /**
738
+ * @module @ember-data/store
739
+ * @class Store
740
+ */
741
+
742
+ /**
743
+ Returns an instance of the adapter for a given type. For
744
+ example, `adapterFor('person')` will return an instance of
745
+ the adapter located at `app/adapters/person.js`
746
+
747
+ If no `person` adapter is found, this method will look
748
+ for an `application` adapter (the default adapter for
749
+ your entire application).
750
+
751
+ @method adapterFor
752
+ @public
753
+ @param {String} modelName
754
+ @return Adapter
755
+ */
756
+
757
+ function adapterFor(modelName, _allowMissing) {
758
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
759
+ if (!test) {
760
+ throw new Error(`Attempted to call store.adapterFor(), but the store instance has already been destroyed.`);
761
+ }
762
+ })(!(this.isDestroying || this.isDestroyed)) : {};
763
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
764
+ if (!test) {
765
+ throw new Error(`You need to pass a model name to the store's adapterFor method`);
766
+ }
767
+ })(modelName) : {};
768
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
769
+ if (!test) {
770
+ throw new Error(`Passing classes to store.adapterFor has been removed. Please pass a dasherized string instead of ${modelName}`);
771
+ }
772
+ })(typeof modelName === 'string') : {};
773
+ this._adapterCache = this._adapterCache || Object.create(null);
774
+ const normalizedModelName = _deprecatingNormalize(modelName);
775
+ const {
776
+ _adapterCache
777
+ } = this;
778
+ let adapter = _adapterCache[normalizedModelName];
779
+ if (adapter) {
780
+ return adapter;
781
+ }
782
+ const owner = getOwner(this);
783
+
784
+ // name specific adapter
785
+ adapter = owner.lookup(`adapter:${normalizedModelName}`);
786
+ if (adapter !== undefined) {
787
+ _adapterCache[normalizedModelName] = adapter;
788
+ return adapter;
789
+ }
790
+
791
+ // no adapter found for the specific name, fallback and check for application adapter
792
+ adapter = _adapterCache.application || owner.lookup('adapter:application');
793
+ if (adapter !== undefined) {
794
+ _adapterCache[normalizedModelName] = adapter;
795
+ _adapterCache.application = adapter;
796
+ return adapter;
797
+ }
798
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
799
+ if (!test) {
800
+ throw new Error(`No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`);
801
+ }
802
+ })(_allowMissing) : {};
803
+ }
804
+
805
+ /**
806
+ Returns an instance of the serializer for a given type. For
807
+ example, `serializerFor('person')` will return an instance of
808
+ `App.PersonSerializer`.
809
+
810
+ If no `App.PersonSerializer` is found, this method will look
811
+ for an `App.ApplicationSerializer` (the default serializer for
812
+ your entire application).
813
+
814
+ If a serializer cannot be found on the adapter, it will fall back
815
+ to an instance of `JSONSerializer`.
816
+
817
+ @method serializerFor
818
+ @public
819
+ @param {String} modelName the record to serialize
820
+ @return {Serializer}
821
+ */
822
+ function serializerFor(modelName) {
823
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
824
+ if (!test) {
825
+ throw new Error(`Attempted to call store.serializerFor(), but the store instance has already been destroyed.`);
826
+ }
827
+ })(!(this.isDestroying || this.isDestroyed)) : {};
828
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
829
+ if (!test) {
830
+ throw new Error(`You need to pass a model name to the store's serializerFor method`);
831
+ }
832
+ })(modelName) : {};
833
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
834
+ if (!test) {
835
+ throw new Error(`Passing classes to store.serializerFor has been removed. Please pass a dasherized string instead of ${modelName}`);
836
+ }
837
+ })(typeof modelName === 'string') : {};
838
+ this._serializerCache = this._serializerCache || Object.create(null);
839
+ const normalizedModelName = _deprecatingNormalize(modelName);
840
+ const {
841
+ _serializerCache
842
+ } = this;
843
+ let serializer = _serializerCache[normalizedModelName];
844
+ if (serializer) {
845
+ return serializer;
846
+ }
847
+
848
+ // by name
849
+ const owner = getOwner(this);
850
+ serializer = owner.lookup(`serializer:${normalizedModelName}`);
851
+ if (serializer !== undefined) {
852
+ _serializerCache[normalizedModelName] = serializer;
853
+ return serializer;
854
+ }
855
+
856
+ // no serializer found for the specific model, fallback and check for application serializer
857
+ serializer = _serializerCache.application || owner.lookup('serializer:application');
858
+ if (serializer !== undefined) {
859
+ _serializerCache[normalizedModelName] = serializer;
860
+ _serializerCache.application = serializer;
861
+ return serializer;
862
+ }
863
+ return null;
864
+ }
865
+
866
+ /**
867
+ `normalize` converts a json payload into the normalized form that
868
+ [push](../methods/push?anchor=push) expects.
869
+
870
+ Example
871
+
872
+ ```js
873
+ socket.on('message', function(message) {
874
+ let modelName = message.model;
875
+ let data = message.data;
876
+ store.push(store.normalize(modelName, data));
877
+ });
878
+ ```
879
+
880
+ @method normalize
881
+ @public
882
+ @param {String} modelName The name of the model type for this payload
883
+ @param {Object} payload
884
+ @return {Object} The normalized payload
885
+ */
886
+ // TODO @runspired @deprecate users should call normalize on the associated serializer directly
887
+ function normalize(modelName, payload) {
888
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
889
+ if (!test) {
890
+ throw new Error(`Attempted to call store.normalize(), but the store instance has already been destroyed.`);
891
+ }
892
+ })(!(this.isDestroying || this.isDestroyed)) : {};
893
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
894
+ if (!test) {
895
+ throw new Error(`You need to pass a model name to the store's normalize method`);
896
+ }
897
+ })(modelName) : {};
898
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
899
+ if (!test) {
900
+ throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${typeof modelName}`);
901
+ }
902
+ })(typeof modelName === 'string') : {};
903
+ const normalizedModelName = _deprecatingNormalize(modelName);
904
+ const serializer = this.serializerFor(normalizedModelName);
905
+ const schema = this.modelFor(normalizedModelName);
906
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
907
+ if (!test) {
908
+ throw new Error(`You must define a normalize method in your serializer in order to call store.normalize`);
909
+ }
910
+ })(typeof serializer?.normalize === 'function') : {};
911
+ return serializer.normalize(schema, payload);
912
+ }
913
+
914
+ /**
915
+ Push some raw data into the store.
916
+
917
+ This method can be used both to push in brand new
918
+ records, as well as to update existing records. You
919
+ can push in more than one type of object at once.
920
+ All objects should be in the format expected by the
921
+ serializer.
922
+
923
+ ```app/serializers/application.js
924
+ import RESTSerializer from '@ember-data/serializer/rest';
925
+
926
+ export default class ApplicationSerializer extends RESTSerializer;
927
+ ```
928
+
929
+ ```js
930
+ let pushData = {
931
+ posts: [
932
+ { id: 1, postTitle: "Great post", commentIds: [2] }
933
+ ],
934
+ comments: [
935
+ { id: 2, commentBody: "Insightful comment" }
936
+ ]
937
+ }
938
+
939
+ store.pushPayload(pushData);
940
+ ```
941
+
942
+ By default, the data will be deserialized using a default
943
+ serializer (the application serializer if it exists).
944
+
945
+ Alternatively, `pushPayload` will accept a model type which
946
+ will determine which serializer will process the payload.
947
+
948
+ ```app/serializers/application.js
949
+ import RESTSerializer from '@ember-data/serializer/rest';
950
+
951
+ export default class ApplicationSerializer extends RESTSerializer;
952
+ ```
953
+
954
+ ```app/serializers/post.js
955
+ import JSONSerializer from '@ember-data/serializer/json';
956
+
957
+ export default JSONSerializer;
958
+ ```
959
+
960
+ ```js
961
+ store.pushPayload(pushData); // Will use the application serializer
962
+ store.pushPayload('post', pushData); // Will use the post serializer
963
+ ```
964
+
965
+ @method pushPayload
966
+ @public
967
+ @param {String} modelName Optionally, a model type used to determine which serializer will be used
968
+ @param {Object} inputPayload
969
+ */
970
+ // TODO @runspired @deprecate pushPayload in favor of looking up the serializer
971
+ function pushPayload(modelName, inputPayload) {
972
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
973
+ if (!test) {
974
+ throw new Error(`Attempted to call store.pushPayload(), but the store instance has already been destroyed.`);
975
+ }
976
+ })(!(this.isDestroying || this.isDestroyed)) : {};
977
+ const payload = inputPayload || modelName;
978
+ const normalizedModelName = inputPayload ? _deprecatingNormalize(modelName) : 'application';
979
+ const serializer = this.serializerFor(normalizedModelName);
980
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
981
+ if (!test) {
982
+ throw new Error(`You cannot use 'store.pushPayload(<type>, <payload>)' unless the serializer for '${normalizedModelName}' defines 'pushPayload'`);
983
+ }
984
+ })(serializer && typeof serializer.pushPayload === 'function') : {};
985
+ serializer.pushPayload(this, payload);
986
+ }
987
+
988
+ // TODO @runspired @deprecate records should implement their own serialization if desired
989
+ function serializeRecord(record, options) {
990
+ // TODO we used to check if the record was destroyed here
991
+ if (!this._fetchManager) {
992
+ this._fetchManager = new FetchManager(this);
993
+ }
994
+ return this._fetchManager.createSnapshot(recordIdentifierFor(record)).serialize(options);
995
+ }
996
+ function cleanup() {
997
+ // enqueue destruction of any adapters/serializers we have created
998
+ for (const adapterName in this._adapterCache) {
999
+ const adapter = this._adapterCache[adapterName];
1000
+ if (typeof adapter.destroy === 'function') {
1001
+ adapter.destroy();
1002
+ }
1003
+ }
1004
+ for (const serializerName in this._serializerCache) {
1005
+ const serializer = this._serializerCache[serializerName];
1006
+ if (typeof serializer.destroy === 'function') {
1007
+ serializer.destroy();
1008
+ }
1009
+ }
1010
+ }
1011
+ export { LegacyNetworkHandler, adapterFor, cleanup, normalize, pushPayload, serializeRecord, serializerFor };