@ember-data/legacy-compat 5.4.0-alpha.13 → 5.4.0-alpha.131

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 (56) hide show
  1. package/README.md +8 -0
  2. package/addon-main.cjs +5 -0
  3. package/{addon/fetch-manager-0744e8e9.js → dist/-private-Dlia0pw1.js} +252 -125
  4. package/dist/-private-Dlia0pw1.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/dist/index.js +1019 -0
  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 +65 -38
  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.js +0 -1
  52. package/addon/fetch-manager-0744e8e9.js.map +0 -1
  53. package/addon/index.js +0 -617
  54. package/addon/index.js.map +0 -1
  55. package/addon-main.js +0 -93
  56. /package/{addon → dist}/-private.js.map +0 -0
package/dist/index.js ADDED
@@ -0,0 +1,1019 @@
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, a as assertIdentifierHasId, S as SaveOp, 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
+ if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_PAYLOADS)) {
434
+ try {
435
+ const payloadCopy = payload ? JSON.parse(JSON.stringify(payload)) : payload;
436
+ // eslint-disable-next-line no-console
437
+ console.log(`EmberData | Payload - ${operation}`, payloadCopy);
438
+ } catch {
439
+ // eslint-disable-next-line no-console
440
+ console.log(`EmberData | Payload - ${operation}`, payload);
441
+ }
442
+ }
443
+ let result;
444
+ store._join(() => {
445
+ // @ts-expect-error we don't have access to a response in legacy
446
+ result = store.cache.didCommit(identifier, {
447
+ request: context.request,
448
+ content: payload
449
+ });
450
+ });
451
+
452
+ // blatantly lie if we were a createRecord request
453
+ // to give some semblance of cache-control to the
454
+ // CachePolicy while legacy is still around
455
+ if (store.lifetimes?.didRequest && operation === 'createRecord') {
456
+ store.lifetimes.didRequest(context.request, {
457
+ status: 201
458
+ }, null, store);
459
+ }
460
+ return store.peekRecord(result.data);
461
+ }).catch(e => {
462
+ let err = e;
463
+ if (!e) {
464
+ err = new Error(`Unknown Error Occurred During Request`);
465
+ } else if (typeof e === 'string') {
466
+ err = new Error(e);
467
+ }
468
+ adapterDidInvalidate(store, identifier, err);
469
+ throw err;
470
+ });
471
+ }
472
+ function adapterDidInvalidate(store, identifier, error) {
473
+ if (error && error.isAdapterError === true && error.code === 'InvalidError') {
474
+ const serializer = store.serializerFor(identifier.type);
475
+
476
+ // TODO @deprecate extractErrors being called
477
+ // TODO remove extractErrors from the default serializers.
478
+ if (serializer && typeof serializer.extractErrors === 'function') {
479
+ const errorsHash = serializer.extractErrors(store, store.modelFor(identifier.type), error, identifier.id);
480
+ error.errors = errorsHashToArray(errorsHash);
481
+ }
482
+ }
483
+ const cache = store.cache;
484
+ if (error.errors) {
485
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
486
+ if (!test) {
487
+ throw new Error(`Expected the cache in use by resource ${String(identifier)} to have a getErrors(identifier) method for retrieving errors.`);
488
+ }
489
+ })(typeof cache.getErrors === 'function') : {};
490
+ let jsonApiErrors = error.errors;
491
+ if (jsonApiErrors.length === 0) {
492
+ jsonApiErrors = [{
493
+ title: 'Invalid Error',
494
+ detail: '',
495
+ source: {
496
+ pointer: '/data'
497
+ }
498
+ }];
499
+ }
500
+ cache.commitWasRejected(identifier, jsonApiErrors);
501
+ } else {
502
+ cache.commitWasRejected(identifier);
503
+ }
504
+ }
505
+ function makeArray(value) {
506
+ return Array.isArray(value) ? value : [value];
507
+ }
508
+ const PRIMARY_ATTRIBUTE_KEY = 'base';
509
+ function errorsHashToArray(errors) {
510
+ const out = [];
511
+ if (errors) {
512
+ Object.keys(errors).forEach(key => {
513
+ const messages = makeArray(errors[key]);
514
+ for (let i = 0; i < messages.length; i++) {
515
+ let title = 'Invalid Attribute';
516
+ let pointer = `/data/attributes/${key}`;
517
+ if (key === PRIMARY_ATTRIBUTE_KEY) {
518
+ title = 'Invalid Document';
519
+ pointer = `/data`;
520
+ }
521
+ out.push({
522
+ title: title,
523
+ detail: messages[i],
524
+ source: {
525
+ pointer: pointer
526
+ }
527
+ });
528
+ }
529
+ });
530
+ }
531
+ return out;
532
+ }
533
+ function findRecord(context) {
534
+ const {
535
+ store,
536
+ data
537
+ } = context.request;
538
+ const {
539
+ record: identifier,
540
+ options
541
+ } = data;
542
+ let promise;
543
+
544
+ // if not loaded start loading
545
+ if (!store._instanceCache.recordIsLoaded(identifier)) {
546
+ promise = store._fetchManager.fetchDataIfNeededForIdentifier(identifier, options, context.request);
547
+
548
+ // Refetch if the reload option is passed
549
+ } else if (options.reload) {
550
+ assertIdentifierHasId(identifier);
551
+ promise = store._fetchManager.scheduleFetch(identifier, options, context.request);
552
+ } else {
553
+ let snapshot = null;
554
+ const adapter = store.adapterFor(identifier.type);
555
+
556
+ // Refetch the record if the adapter thinks the record is stale
557
+ if (typeof options.reload === 'undefined' && adapter.shouldReloadRecord && adapter.shouldReloadRecord(store, snapshot = store._fetchManager.createSnapshot(identifier, options))) {
558
+ assertIdentifierHasId(identifier);
559
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
560
+ promise = store._fetchManager.scheduleFetch(identifier, Object.assign({}, options, {
561
+ reload: true
562
+ }), context.request);
563
+ } else {
564
+ options.reload = true;
565
+ promise = store._fetchManager.scheduleFetch(identifier, options, context.request);
566
+ }
567
+ } else {
568
+ // Trigger the background refetch if backgroundReload option is passed
569
+ if (options.backgroundReload !== false && (options.backgroundReload || !adapter.shouldBackgroundReloadRecord || adapter.shouldBackgroundReloadRecord(store, snapshot = snapshot || store._fetchManager.createSnapshot(identifier, options)))) {
570
+ assertIdentifierHasId(identifier);
571
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
572
+ void store._fetchManager.scheduleFetch(identifier, Object.assign({}, options, {
573
+ backgroundReload: true
574
+ }), context.request);
575
+ } else {
576
+ options.backgroundReload = true;
577
+ void store._fetchManager.scheduleFetch(identifier, options, context.request);
578
+ }
579
+ }
580
+
581
+ // Return the cached record
582
+ promise = Promise.resolve(identifier);
583
+ }
584
+ }
585
+ return promise.then(i => store.peekRecord(i));
586
+ }
587
+ function findAll(context) {
588
+ const {
589
+ store,
590
+ data
591
+ } = context.request;
592
+ const {
593
+ type,
594
+ options
595
+ } = data;
596
+ const adapter = store.adapterFor(type);
597
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
598
+ if (!test) {
599
+ throw new Error(`You tried to load all records but you have no adapter (for ${type})`);
600
+ }
601
+ })(adapter) : {};
602
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
603
+ if (!test) {
604
+ throw new Error(`You tried to load all records but your adapter does not implement 'findAll'`);
605
+ }
606
+ })(typeof adapter.findAll === 'function') : {};
607
+
608
+ // avoid initializing the liveArray just to set `isUpdating`
609
+ const maybeRecordArray = store.recordArrayManager._live.get(type);
610
+ const snapshotArray = new SnapshotRecordArray(store, type, options);
611
+ const shouldReload = options.reload || options.reload !== false && (adapter.shouldReloadAll && adapter.shouldReloadAll(store, snapshotArray) || !adapter.shouldReloadAll && snapshotArray.length === 0);
612
+ let fetch;
613
+ if (shouldReload) {
614
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
615
+ maybeRecordArray && (maybeRecordArray.isUpdating = true);
616
+ fetch = _findAll(adapter, store, type, snapshotArray, context.request, true);
617
+ } else {
618
+ fetch = Promise.resolve(store.peekAll(type));
619
+ if (options.backgroundReload || options.backgroundReload !== false && (!adapter.shouldBackgroundReloadAll || adapter.shouldBackgroundReloadAll(store, snapshotArray))) {
620
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
621
+ maybeRecordArray && (maybeRecordArray.isUpdating = true);
622
+ void _findAll(adapter, store, type, snapshotArray, context.request, false);
623
+ }
624
+ }
625
+ return fetch;
626
+ }
627
+ function _findAll(adapter, store, type, snapshotArray, request, isAsyncFlush) {
628
+ const schema = store.modelFor(type);
629
+ let promise = Promise.resolve().then(() => adapter.findAll(store, schema, null, snapshotArray));
630
+ promise = promise.then(adapterPayload => {
631
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
632
+ if (!test) {
633
+ throw new Error(`You made a 'findAll' request for '${type}' records, but the adapter's response did not have any data`);
634
+ }
635
+ })(payloadIsNotBlank(adapterPayload)) : {};
636
+ const serializer = store.serializerFor(type);
637
+ const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'findAll');
638
+ store._push(payload, isAsyncFlush);
639
+ snapshotArray._recordArray.isUpdating = false;
640
+ if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_PAYLOADS)) {
641
+ // eslint-disable-next-line no-console
642
+ console.log(`request: findAll<${type}> background reload complete`);
643
+ }
644
+ return snapshotArray._recordArray;
645
+ });
646
+ if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
647
+ if (!request.disableTestWaiter) {
648
+ const {
649
+ waitForPromise
650
+ } = importSync('@ember/test-waiters');
651
+ promise = waitForPromise(promise);
652
+ }
653
+ }
654
+ return promise;
655
+ }
656
+ function query(context) {
657
+ const {
658
+ store,
659
+ data
660
+ } = context.request;
661
+ let {
662
+ options
663
+ } = data;
664
+ // eslint-disable-next-line @typescript-eslint/no-shadow
665
+ const {
666
+ type,
667
+ query
668
+ } = data;
669
+ const adapter = store.adapterFor(type);
670
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
671
+ if (!test) {
672
+ throw new Error(`You tried to make a query but you have no adapter (for ${type})`);
673
+ }
674
+ })(adapter) : {};
675
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
676
+ if (!test) {
677
+ throw new Error(`You tried to make a query but your adapter does not implement 'query'`);
678
+ }
679
+ })(typeof adapter.query === 'function') : {};
680
+ const recordArray = options._recordArray || store.recordArrayManager.createArray({
681
+ type,
682
+ query
683
+ });
684
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
685
+ options = Object.assign({}, options);
686
+ delete options._recordArray;
687
+ } else {
688
+ delete options._recordArray;
689
+ }
690
+ const schema = store.modelFor(type);
691
+ const promise = Promise.resolve().then(() => adapter.query(store, schema, query, recordArray, options));
692
+ return promise.then(adapterPayload => {
693
+ const serializer = store.serializerFor(type);
694
+ const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'query');
695
+ const identifiers = store._push(payload, true);
696
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
697
+ if (!test) {
698
+ 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.');
699
+ }
700
+ })(Array.isArray(identifiers)) : {};
701
+ store.recordArrayManager.populateManagedArray(recordArray, identifiers, payload);
702
+ return recordArray;
703
+ });
704
+ }
705
+ function assertSingleResourceDocument(payload) {
706
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
707
+ if (!test) {
708
+ 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.`);
709
+ }
710
+ })(!Array.isArray(payload.data)) : {};
711
+ }
712
+ function queryRecord(context) {
713
+ const {
714
+ store,
715
+ data
716
+ } = context.request;
717
+ // eslint-disable-next-line @typescript-eslint/no-shadow
718
+ const {
719
+ type,
720
+ query,
721
+ options
722
+ } = data;
723
+ const adapter = store.adapterFor(type);
724
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
725
+ if (!test) {
726
+ throw new Error(`You tried to make a query but you have no adapter (for ${type})`);
727
+ }
728
+ })(adapter) : {};
729
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
730
+ if (!test) {
731
+ throw new Error(`You tried to make a query but your adapter does not implement 'queryRecord'`);
732
+ }
733
+ })(typeof adapter.queryRecord === 'function') : {};
734
+ const schema = store.modelFor(type);
735
+ const promise = Promise.resolve().then(() => adapter.queryRecord(store, schema, query, options));
736
+ return promise.then(adapterPayload => {
737
+ const serializer = store.serializerFor(type);
738
+ const payload = normalizeResponseHelper(serializer, store, schema, adapterPayload, null, 'queryRecord');
739
+ assertSingleResourceDocument(payload);
740
+ const identifier = store._push(payload, true);
741
+ return identifier ? store.peekRecord(identifier) : null;
742
+ });
743
+ }
744
+
745
+ /**
746
+ * @module @ember-data/store
747
+ * @class Store
748
+ */
749
+
750
+ /**
751
+ Returns an instance of the adapter for a given type. For
752
+ example, `adapterFor('person')` will return an instance of
753
+ the adapter located at `app/adapters/person.js`
754
+
755
+ If no `person` adapter is found, this method will look
756
+ for an `application` adapter (the default adapter for
757
+ your entire application).
758
+
759
+ @method adapterFor
760
+ @public
761
+ @param {String} modelName
762
+ @return Adapter
763
+ */
764
+
765
+ function adapterFor(modelName, _allowMissing) {
766
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
767
+ if (!test) {
768
+ throw new Error(`Attempted to call store.adapterFor(), but the store instance has already been destroyed.`);
769
+ }
770
+ })(!(this.isDestroying || this.isDestroyed)) : {};
771
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
772
+ if (!test) {
773
+ throw new Error(`You need to pass a model name to the store's adapterFor method`);
774
+ }
775
+ })(modelName) : {};
776
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
777
+ if (!test) {
778
+ throw new Error(`Passing classes to store.adapterFor has been removed. Please pass a dasherized string instead of ${modelName}`);
779
+ }
780
+ })(typeof modelName === 'string') : {};
781
+ this._adapterCache = this._adapterCache || Object.create(null);
782
+ const normalizedModelName = _deprecatingNormalize(modelName);
783
+ const {
784
+ _adapterCache
785
+ } = this;
786
+ let adapter = _adapterCache[normalizedModelName];
787
+ if (adapter) {
788
+ return adapter;
789
+ }
790
+ const owner = getOwner(this);
791
+
792
+ // name specific adapter
793
+ adapter = owner.lookup(`adapter:${normalizedModelName}`);
794
+ if (adapter !== undefined) {
795
+ _adapterCache[normalizedModelName] = adapter;
796
+ return adapter;
797
+ }
798
+
799
+ // no adapter found for the specific name, fallback and check for application adapter
800
+ adapter = _adapterCache.application || owner.lookup('adapter:application');
801
+ if (adapter !== undefined) {
802
+ _adapterCache[normalizedModelName] = adapter;
803
+ _adapterCache.application = adapter;
804
+ return adapter;
805
+ }
806
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
807
+ if (!test) {
808
+ throw new Error(`No adapter was found for '${modelName}' and no 'application' adapter was found as a fallback.`);
809
+ }
810
+ })(_allowMissing) : {};
811
+ }
812
+
813
+ /**
814
+ Returns an instance of the serializer for a given type. For
815
+ example, `serializerFor('person')` will return an instance of
816
+ `App.PersonSerializer`.
817
+
818
+ If no `App.PersonSerializer` is found, this method will look
819
+ for an `App.ApplicationSerializer` (the default serializer for
820
+ your entire application).
821
+
822
+ If a serializer cannot be found on the adapter, it will fall back
823
+ to an instance of `JSONSerializer`.
824
+
825
+ @method serializerFor
826
+ @public
827
+ @param {String} modelName the record to serialize
828
+ @return {Serializer}
829
+ */
830
+ function serializerFor(modelName) {
831
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
832
+ if (!test) {
833
+ throw new Error(`Attempted to call store.serializerFor(), but the store instance has already been destroyed.`);
834
+ }
835
+ })(!(this.isDestroying || this.isDestroyed)) : {};
836
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
837
+ if (!test) {
838
+ throw new Error(`You need to pass a model name to the store's serializerFor method`);
839
+ }
840
+ })(modelName) : {};
841
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
842
+ if (!test) {
843
+ throw new Error(`Passing classes to store.serializerFor has been removed. Please pass a dasherized string instead of ${modelName}`);
844
+ }
845
+ })(typeof modelName === 'string') : {};
846
+ this._serializerCache = this._serializerCache || Object.create(null);
847
+ const normalizedModelName = _deprecatingNormalize(modelName);
848
+ const {
849
+ _serializerCache
850
+ } = this;
851
+ let serializer = _serializerCache[normalizedModelName];
852
+ if (serializer) {
853
+ return serializer;
854
+ }
855
+
856
+ // by name
857
+ const owner = getOwner(this);
858
+ serializer = owner.lookup(`serializer:${normalizedModelName}`);
859
+ if (serializer !== undefined) {
860
+ _serializerCache[normalizedModelName] = serializer;
861
+ return serializer;
862
+ }
863
+
864
+ // no serializer found for the specific model, fallback and check for application serializer
865
+ serializer = _serializerCache.application || owner.lookup('serializer:application');
866
+ if (serializer !== undefined) {
867
+ _serializerCache[normalizedModelName] = serializer;
868
+ _serializerCache.application = serializer;
869
+ return serializer;
870
+ }
871
+ return null;
872
+ }
873
+
874
+ /**
875
+ `normalize` converts a json payload into the normalized form that
876
+ [push](../methods/push?anchor=push) expects.
877
+
878
+ Example
879
+
880
+ ```js
881
+ socket.on('message', function(message) {
882
+ let modelName = message.model;
883
+ let data = message.data;
884
+ store.push(store.normalize(modelName, data));
885
+ });
886
+ ```
887
+
888
+ @method normalize
889
+ @public
890
+ @param {String} modelName The name of the model type for this payload
891
+ @param {Object} payload
892
+ @return {Object} The normalized payload
893
+ */
894
+ // TODO @runspired @deprecate users should call normalize on the associated serializer directly
895
+ function normalize(modelName, payload) {
896
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
897
+ if (!test) {
898
+ throw new Error(`Attempted to call store.normalize(), but the store instance has already been destroyed.`);
899
+ }
900
+ })(!(this.isDestroying || this.isDestroyed)) : {};
901
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
902
+ if (!test) {
903
+ throw new Error(`You need to pass a model name to the store's normalize method`);
904
+ }
905
+ })(modelName) : {};
906
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
907
+ if (!test) {
908
+ throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${typeof modelName}`);
909
+ }
910
+ })(typeof modelName === 'string') : {};
911
+ const normalizedModelName = _deprecatingNormalize(modelName);
912
+ const serializer = this.serializerFor(normalizedModelName);
913
+ const schema = this.modelFor(normalizedModelName);
914
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
915
+ if (!test) {
916
+ throw new Error(`You must define a normalize method in your serializer in order to call store.normalize`);
917
+ }
918
+ })(typeof serializer?.normalize === 'function') : {};
919
+ return serializer.normalize(schema, payload);
920
+ }
921
+
922
+ /**
923
+ Push some raw data into the store.
924
+
925
+ This method can be used both to push in brand new
926
+ records, as well as to update existing records. You
927
+ can push in more than one type of object at once.
928
+ All objects should be in the format expected by the
929
+ serializer.
930
+
931
+ ```app/serializers/application.js
932
+ import RESTSerializer from '@ember-data/serializer/rest';
933
+
934
+ export default class ApplicationSerializer extends RESTSerializer;
935
+ ```
936
+
937
+ ```js
938
+ let pushData = {
939
+ posts: [
940
+ { id: 1, postTitle: "Great post", commentIds: [2] }
941
+ ],
942
+ comments: [
943
+ { id: 2, commentBody: "Insightful comment" }
944
+ ]
945
+ }
946
+
947
+ store.pushPayload(pushData);
948
+ ```
949
+
950
+ By default, the data will be deserialized using a default
951
+ serializer (the application serializer if it exists).
952
+
953
+ Alternatively, `pushPayload` will accept a model type which
954
+ will determine which serializer will process the payload.
955
+
956
+ ```app/serializers/application.js
957
+ import RESTSerializer from '@ember-data/serializer/rest';
958
+
959
+ export default class ApplicationSerializer extends RESTSerializer;
960
+ ```
961
+
962
+ ```app/serializers/post.js
963
+ import JSONSerializer from '@ember-data/serializer/json';
964
+
965
+ export default JSONSerializer;
966
+ ```
967
+
968
+ ```js
969
+ store.pushPayload(pushData); // Will use the application serializer
970
+ store.pushPayload('post', pushData); // Will use the post serializer
971
+ ```
972
+
973
+ @method pushPayload
974
+ @public
975
+ @param {String} modelName Optionally, a model type used to determine which serializer will be used
976
+ @param {Object} inputPayload
977
+ */
978
+ // TODO @runspired @deprecate pushPayload in favor of looking up the serializer
979
+ function pushPayload(modelName, inputPayload) {
980
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
981
+ if (!test) {
982
+ throw new Error(`Attempted to call store.pushPayload(), but the store instance has already been destroyed.`);
983
+ }
984
+ })(!(this.isDestroying || this.isDestroyed)) : {};
985
+ const payload = inputPayload || modelName;
986
+ const normalizedModelName = inputPayload ? _deprecatingNormalize(modelName) : 'application';
987
+ const serializer = this.serializerFor(normalizedModelName);
988
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
989
+ if (!test) {
990
+ throw new Error(`You cannot use 'store.pushPayload(<type>, <payload>)' unless the serializer for '${normalizedModelName}' defines 'pushPayload'`);
991
+ }
992
+ })(serializer && typeof serializer.pushPayload === 'function') : {};
993
+ serializer.pushPayload(this, payload);
994
+ }
995
+
996
+ // TODO @runspired @deprecate records should implement their own serialization if desired
997
+ function serializeRecord(record, options) {
998
+ // TODO we used to check if the record was destroyed here
999
+ if (!this._fetchManager) {
1000
+ this._fetchManager = new FetchManager(this);
1001
+ }
1002
+ return this._fetchManager.createSnapshot(recordIdentifierFor(record)).serialize(options);
1003
+ }
1004
+ function cleanup() {
1005
+ // enqueue destruction of any adapters/serializers we have created
1006
+ for (const adapterName in this._adapterCache) {
1007
+ const adapter = this._adapterCache[adapterName];
1008
+ if (typeof adapter.destroy === 'function') {
1009
+ adapter.destroy();
1010
+ }
1011
+ }
1012
+ for (const serializerName in this._serializerCache) {
1013
+ const serializer = this._serializerCache[serializerName];
1014
+ if (typeof serializer.destroy === 'function') {
1015
+ serializer.destroy();
1016
+ }
1017
+ }
1018
+ }
1019
+ export { LegacyNetworkHandler, adapterFor, cleanup, normalize, pushPayload, serializeRecord, serializerFor };