@ember-data/legacy-compat 5.4.0-alpha.14 → 5.4.0-alpha.141

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