@warp-drive/legacy 5.7.0-alpha.2 → 5.7.0-alpha.20

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 (37) hide show
  1. package/declarations/compat/builders/find-all.d.ts +2 -2
  2. package/declarations/compat/builders/query.d.ts +2 -2
  3. package/declarations/compat/builders/save-record.d.ts +3 -3
  4. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +10 -10
  5. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -2
  6. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +5 -5
  7. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +3 -3
  8. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +2 -2
  9. package/declarations/compat/legacy-network-handler/snapshot.d.ts +72 -44
  10. package/declarations/model/-private/attr.d.ts +1 -1
  11. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +2 -2
  12. package/declarations/model/-private/hooks.d.ts +2 -2
  13. package/declarations/model/-private/legacy-relationships-support.d.ts +16 -17
  14. package/declarations/model/-private/model.d.ts +4 -5
  15. package/declarations/model/-private/notify-changes.d.ts +2 -2
  16. package/declarations/model/-private/record-state.d.ts +2 -2
  17. package/declarations/model/-private/references/belongs-to.d.ts +6 -6
  18. package/declarations/model/-private/references/has-many.d.ts +6 -6
  19. package/declarations/model/-private/schema-provider.d.ts +6 -6
  20. package/declarations/model/-private.d.ts +2 -1
  21. package/declarations/model/migration-support.d.ts +10 -10
  22. package/declarations/store/-private.d.ts +12 -12
  23. package/dist/{-private-CKrP0ogQ.js → -private-CVsFOW1k.js} +94 -96
  24. package/dist/adapter/-private.js +1 -1
  25. package/dist/adapter/json-api.js +1 -1
  26. package/dist/adapter/rest.js +1 -1
  27. package/dist/compat/-private.js +1 -1
  28. package/dist/compat/builders.js +1 -1
  29. package/dist/compat.js +2 -1
  30. package/dist/{errors-BX5wowuz.js → errors-VSxXZooE.js} +33 -36
  31. package/dist/model/-private.js +1 -2
  32. package/dist/model/migration-support.js +12 -6
  33. package/dist/model.js +10 -11
  34. package/dist/{schema-provider-Cbnf6sKm.js → schema-provider-BgBPZFfc.js} +20 -16
  35. package/dist/{serialize-into-hash-Bp58npke.js → serialize-into-hash-B59laYa4.js} +2 -2
  36. package/dist/store.js +3 -3
  37. package/package.json +6 -6
@@ -1,6 +1,6 @@
1
1
  import type { Store } from "@warp-drive/core";
2
2
  import type { SchemaService } from "@warp-drive/core/types";
3
- import type { RecordIdentifier, StableRecordIdentifier } from "@warp-drive/core/types/identifier";
3
+ import type { ResourceKey } from "@warp-drive/core/types/identifier";
4
4
  import type { ObjectValue } from "@warp-drive/core/types/json/raw";
5
5
  import type { Derivation, HashFn, Transformation } from "@warp-drive/core/types/schema/concepts";
6
6
  import type { ArrayField, DerivedField, GenericField, HashField, LegacyField, ObjectField, ObjectSchema, ResourceSchema } from "@warp-drive/core/types/schema/fields";
@@ -8,10 +8,10 @@ import type { ModelFactory, ModelStore } from "./model.js";
8
8
  type AttributesSchema = ReturnType<Exclude<SchemaService["attributesDefinitionFor"], undefined>>;
9
9
  type RelationshipsSchema = ReturnType<Exclude<SchemaService["relationshipsDefinitionFor"], undefined>>;
10
10
  export interface ModelSchemaProvider {
11
- attributesDefinitionFor(resource: RecordIdentifier | {
11
+ attributesDefinitionFor(resource: ResourceKey | {
12
12
  type: string;
13
13
  }): AttributesSchema;
14
- relationshipsDefinitionFor(resource: RecordIdentifier | {
14
+ relationshipsDefinitionFor(resource: ResourceKey | {
15
15
  type: string;
16
16
  }): RelationshipsSchema;
17
17
  doesTypeExist(type: string): boolean;
@@ -23,7 +23,7 @@ export declare class ModelSchemaProvider implements SchemaService {
23
23
  constructor(store: ModelStore);
24
24
  resourceTypes(): Readonly<string[]>;
25
25
  hasTrait(type: string): boolean;
26
- resourceHasTrait(resource: StableRecordIdentifier | {
26
+ resourceHasTrait(resource: ResourceKey | {
27
27
  type: string;
28
28
  }, trait: string): boolean;
29
29
  transformation(field: GenericField | ObjectField | ArrayField | {
@@ -35,7 +35,7 @@ export declare class ModelSchemaProvider implements SchemaService {
35
35
  hashFn(field: HashField | {
36
36
  type: string;
37
37
  }): HashFn;
38
- resource(resource: StableRecordIdentifier | {
38
+ resource(resource: ResourceKey | {
39
39
  type: string;
40
40
  }): ResourceSchema | ObjectSchema;
41
41
  registerResources(schemas: Array<ResourceSchema | ObjectSchema>): void;
@@ -48,7 +48,7 @@ export declare class ModelSchemaProvider implements SchemaService {
48
48
  >(derivation: Derivation<R, T, FM>): void;
49
49
  registerHashFn(hashFn: HashFn): void;
50
50
  private _loadModelSchema;
51
- fields(resource: RecordIdentifier | {
51
+ fields(resource: ResourceKey | {
52
52
  type: string;
53
53
  }): Map<string, LegacyField>;
54
54
  hasResource(resource: {
@@ -1,8 +1,9 @@
1
1
  export { type MinimalLegacyRecord } from "./-private/model-methods.js";
2
2
  export type { ModelStore } from "./-private/model.js";
3
3
  export { Errors } from "./-private/errors.js";
4
- export { RelatedCollection as ManyArray } from "@warp-drive/core/store/-private";
4
+ export type { LegacyManyArray as ManyArray } from "@warp-drive/core/store/-private";
5
5
  export { PromiseBelongsTo } from "./-private/promise-belongs-to.js";
6
6
  export { PromiseManyArray } from "./-private/promise-many-array.js";
7
7
  // // Used by tests, migration support
8
8
  export { lookupLegacySupport, LEGACY_SUPPORT } from "./-private/legacy-relationships-support.js";
9
+ export type { MaybeHasManyFields, MaybeBelongsToFields, MaybeRelationshipFields } from "./-private/type-utils.js";
@@ -3,7 +3,7 @@ import type { CAUTION_MEGA_DANGER_ZONE_Extension, ProcessedExtension } from "@wa
3
3
  import type { ExtensibleField } from "@warp-drive/core/reactive/-private/schema";
4
4
  import type { SchemaService } from "@warp-drive/core/types";
5
5
  import type { ChangedAttributesHash } from "@warp-drive/core/types/cache";
6
- import type { StableRecordIdentifier } from "@warp-drive/core/types/identifier";
6
+ import type { ResourceKey } from "@warp-drive/core/types/identifier";
7
7
  import type { ObjectValue } from "@warp-drive/core/types/json/raw";
8
8
  import type { TypedRecordInstance, TypeFromInstance } from "@warp-drive/core/types/record";
9
9
  import type { Derivation, HashFn, Transformation } from "@warp-drive/core/types/schema/concepts";
@@ -198,10 +198,10 @@ export declare function registerDerivations(schema: SchemaService): void;
198
198
  * @public
199
199
  */
200
200
  export interface DelegatingSchemaService {
201
- attributesDefinitionFor?(resource: StableRecordIdentifier | {
201
+ attributesDefinitionFor?(resource: ResourceKey | {
202
202
  type: string;
203
203
  }): AttributesSchema;
204
- relationshipsDefinitionFor?(resource: StableRecordIdentifier | {
204
+ relationshipsDefinitionFor?(resource: ResourceKey | {
205
205
  type: string;
206
206
  }): RelationshipsSchema;
207
207
  doesTypeExist?(type: string): boolean;
@@ -210,18 +210,18 @@ export declare class DelegatingSchemaService implements SchemaService {
210
210
  _preferred: SchemaService;
211
211
  _secondary: SchemaService;
212
212
  constructor(store: Store, schema: SchemaService);
213
- isDelegated(resource: StableRecordIdentifier | {
213
+ isDelegated(resource: ResourceKey | {
214
214
  type: string;
215
215
  }): boolean;
216
216
  resourceTypes(): Readonly<string[]>;
217
- hasResource(resource: StableRecordIdentifier | {
217
+ hasResource(resource: ResourceKey | {
218
218
  type: string;
219
219
  }): boolean;
220
220
  hasTrait(type: string): boolean;
221
- resourceHasTrait(resource: StableRecordIdentifier | {
221
+ resourceHasTrait(resource: ResourceKey | {
222
222
  type: string;
223
223
  }, trait: string): boolean;
224
- fields(resource: StableRecordIdentifier | {
224
+ fields(resource: ResourceKey | {
225
225
  type: string;
226
226
  }): Map<string, FieldSchema>;
227
227
  transformation(field: GenericField | ObjectField | ArrayField | {
@@ -233,7 +233,7 @@ export declare class DelegatingSchemaService implements SchemaService {
233
233
  derivation(field: DerivedField | {
234
234
  type: string;
235
235
  }): Derivation;
236
- resource(resource: StableRecordIdentifier | {
236
+ resource(resource: ResourceKey | {
237
237
  type: string;
238
238
  }): ResourceSchema | ObjectSchema;
239
239
  registerResources(schemas: Array<ResourceSchema | ObjectSchema>): void;
@@ -246,10 +246,10 @@ export declare class DelegatingSchemaService implements SchemaService {
246
246
  >(derivation: Derivation<R, T, FM>): void;
247
247
  registerHashFn(hashFn: HashFn): void;
248
248
  CAUTION_MEGA_DANGER_ZONE_registerExtension(extension: CAUTION_MEGA_DANGER_ZONE_Extension): void;
249
- CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource: StableRecordIdentifier | {
249
+ CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource: ResourceKey | {
250
250
  type: string;
251
251
  }): null | ProcessedExtension["features"];
252
- CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
252
+ CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField, resolvedType: string | null): null | ProcessedExtension["features"];
253
253
  CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
254
254
  /**
255
255
  * This is an internal method used to register behaviors for legacy mode.
@@ -1,18 +1,18 @@
1
1
  import { type InstanceCache } from "@warp-drive/core/store/-private";
2
- import type { StableNewRecordIdentifier, StableRecordIdentifier } from "@warp-drive/core/types/identifier";
2
+ import type { NewResourceKey, ResourceKey } from "@warp-drive/core/types/identifier";
3
3
  import type { Value } from "@warp-drive/core/types/json/raw";
4
- import type { Includes, OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from "@warp-drive/core/types/record";
4
+ import type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from "@warp-drive/core/types/record";
5
5
  import type { LegacyAttributeField, LegacyRelationshipField } from "@warp-drive/core/types/schema/fields";
6
6
  import type { SingleResourceDocument } from "@warp-drive/core/types/spec/json-api-raw";
7
7
  import type { Store } from "../store.js";
8
- export declare function preloadData(store: Store, identifier: StableNewRecordIdentifier, preload: Record<string, Value>): void;
9
- export interface BaseFinderOptions<T = unknown> {
8
+ export declare function preloadData(store: Store, identifier: NewResourceKey, preload: Record<string, Value>): void;
9
+ export interface BaseFinderOptions {
10
10
  reload?: boolean;
11
11
  backgroundReload?: boolean;
12
- include?: T extends TypedRecordInstance ? Includes<T>[] : string | string[];
12
+ include?: string | string[];
13
13
  adapterOptions?: Record<string, unknown>;
14
14
  }
15
- export interface FindRecordOptions<T = unknown> extends BaseFinderOptions<T> {
15
+ export interface FindRecordOptions extends BaseFinderOptions {
16
16
  /**
17
17
  * Data to preload into the store before the request is made.
18
18
  * This feature is *highly* discouraged and has no corresponding
@@ -31,9 +31,9 @@ export interface FindRecordOptions<T = unknown> extends BaseFinderOptions<T> {
31
31
  preload?: Record<string, Value>;
32
32
  }
33
33
  export type QueryOptions = { [K in string | "adapterOptions"]? : K extends "adapterOptions" ? Record<string, unknown> : unknown };
34
- export type FindAllOptions<T = unknown> = BaseFinderOptions<T>;
35
- export type LegacyResourceQuery<T = unknown> = {
36
- include?: T extends TypedRecordInstance ? Includes<T>[] : string | string[];
34
+ export type FindAllOptions = BaseFinderOptions;
35
+ export type LegacyResourceQuery = {
36
+ include?: string | string[];
37
37
  [key: string]: Value | undefined;
38
38
  };
39
39
  export type KeyOrString<T> = keyof T & string extends never ? string : keyof T & string;
@@ -55,7 +55,7 @@ export interface ModelSchema<T = unknown> {
55
55
  eachRelationship<K extends KeyOrString<T>>(callback: (this: ModelSchema<T>, key: K, relationship: LegacyRelationshipField) => void, binding?: T): void;
56
56
  eachTransformedAttribute<K extends KeyOrString<T>>(callback: (this: ModelSchema<T>, key: K, type: string | null) => void, binding?: T): void;
57
57
  }
58
- export declare function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: StableRecordIdentifier): boolean;
58
+ export declare function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: ResourceKey): boolean;
59
59
  /**
60
60
  A `RecordReference` is a low-level API that allows users and
61
61
  addon authors to perform meta-operations on a record.
@@ -73,7 +73,7 @@ export declare class RecordReference {
73
73
  private ___identifier;
74
74
  /** @internal */
75
75
  private _ref;
76
- constructor(store: Store, identifier: StableRecordIdentifier);
76
+ constructor(store: Store, identifier: ResourceKey);
77
77
  /** @internal */
78
78
  destroy(): void;
79
79
  get type(): string;
@@ -112,7 +112,7 @@ export declare class RecordReference {
112
112
  @public
113
113
  @return The identifier of the record.
114
114
  */
115
- identifier(): StableRecordIdentifier;
115
+ identifier(): ResourceKey;
116
116
  /**
117
117
  How the reference will be looked up when it is loaded. Currently
118
118
  this always returns `identity` to signify that a record will be
@@ -1,6 +1,7 @@
1
- import { SOURCE, waitFor, coerceId } from '@warp-drive/core/store/-private';
1
+ import { Context } from '@warp-drive/core/reactive/-private';
2
2
  import { warn } from '@ember/debug';
3
3
  import { createDeferred } from '@warp-drive/core/request';
4
+ import { waitFor, coerceId } from '@warp-drive/core/store/-private';
4
5
  import { getOrSetGlobal } from '@warp-drive/core/types/-private';
5
6
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
7
 
@@ -139,7 +140,7 @@ class SnapshotRecordArray {
139
140
  const {
140
141
  _fetchManager
141
142
  } = this.__store;
142
- this._snapshots = this._recordArray[SOURCE].map(identifier => _fetchManager.createSnapshot(identifier));
143
+ this._snapshots = this._recordArray[Context].source.map(identifier => _fetchManager.createSnapshot(identifier));
143
144
  return this._snapshots;
144
145
  }
145
146
  }
@@ -238,17 +239,44 @@ function normalizeResponseHelper(serializer, store, modelClass, payload, id, req
238
239
  Snapshots are only available when using `@ember-data/legacy-compat`
239
240
  for legacy compatibility with adapters and serializers.
240
241
 
241
- @class Snapshot
242
+ For serialization of records in modern paradigms, request data from
243
+ the cache or off the record directly.
244
+
245
+ @hideconstructor
242
246
  @public
243
247
  */
244
248
  class Snapshot {
245
249
  /**
246
- * @constructor
247
- * @private
248
- * @param options
249
- * @param identifier
250
- * @param _store
251
- */
250
+ The unique ResourceKey associated with this Snapshot.
251
+ @public
252
+ */
253
+
254
+ /**
255
+ The ResourceType of the underlying record for this Snapshot, as a string.
256
+ @public
257
+ */
258
+
259
+ /**
260
+ The id of the snapshot's underlying record
261
+ Example
262
+ ```js
263
+ // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
264
+ postSnapshot.id; // => '1'
265
+ ```
266
+ @public
267
+ */
268
+
269
+ /**
270
+ If `include` was passed to the options for the request, the value
271
+ would be available here.
272
+ @public
273
+ */
274
+
275
+ /**
276
+ The adapterOptions passed to the request which generated this Snapshot, if any
277
+ @public
278
+ */
279
+
252
280
  constructor(options, identifier, store) {
253
281
  this._store = store;
254
282
  this.__attributes = null;
@@ -258,13 +286,6 @@ class Snapshot {
258
286
  this._hasManyIds = Object.create(null);
259
287
  const hasRecord = !!store._instanceCache.peek(identifier);
260
288
  this.modelName = identifier.type;
261
-
262
- /**
263
- The unique RecordIdentifier associated with this Snapshot.
264
- @property identifier
265
- @public
266
- @type {StableRecordIdentifier}
267
- */
268
289
  this.identifier = identifier;
269
290
 
270
291
  /*
@@ -278,43 +299,9 @@ class Snapshot {
278
299
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
279
300
  this._attributes;
280
301
  }
281
-
282
- /**
283
- The id of the snapshot's underlying record
284
- Example
285
- ```javascript
286
- // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
287
- postSnapshot.id; // => '1'
288
- ```
289
- @property id
290
- @type {String}
291
- @public
292
- */
293
302
  this.id = identifier.id;
294
-
295
- /**
296
- A hash of adapter options
297
- @property adapterOptions
298
- @type {Object}
299
- @public
300
- */
301
303
  this.adapterOptions = options.adapterOptions;
302
-
303
- /**
304
- If `include` was passed to the options hash for the request, the value
305
- would be available here.
306
- @property include
307
- @type {String|Array}
308
- @public
309
- */
310
304
  this.include = options.include;
311
-
312
- /**
313
- The name of the type of the underlying record for this snapshot, as a string.
314
- @property modelName
315
- @type {String}
316
- @public
317
- */
318
305
  this.modelName = identifier.type;
319
306
  if (hasRecord) {
320
307
  const cache = this._store.cache;
@@ -325,12 +312,10 @@ class Snapshot {
325
312
  /**
326
313
  The underlying record for this snapshot. Can be used to access methods and
327
314
  properties defined on the record.
328
- Example
329
- ```javascript
330
- let json = snapshot.record.toJSON();
315
+ ```js
316
+ const someValue = snapshot.record.someProp;
331
317
  ```
332
318
  @property record
333
- @type {Model}
334
319
  @public
335
320
  */
336
321
  get record() {
@@ -342,6 +327,8 @@ class Snapshot {
342
327
  })(record !== null) : {};
343
328
  return record;
344
329
  }
330
+
331
+ /** @internal */
345
332
  get _attributes() {
346
333
  if (this.__attributes !== null) {
347
334
  return this.__attributes;
@@ -350,12 +337,9 @@ class Snapshot {
350
337
  const {
351
338
  identifier
352
339
  } = this;
353
- const attrs = this._store.schema.fields(identifier);
354
340
  const cache = this._store.cache;
355
- attrs.forEach((field, keyName) => {
356
- if (field.kind === 'attribute') {
357
- attributes[keyName] = cache.getAttr(identifier, keyName);
358
- }
341
+ this.eachAttribute((key, meta) => {
342
+ attributes[key] = cache.getAttr(identifier, key);
359
343
  });
360
344
  return attributes;
361
345
  }
@@ -373,8 +357,7 @@ class Snapshot {
373
357
  postSnapshot.attr('title'); // => 'Ember.js rocks'
374
358
  ```
375
359
  Note: Values are loaded eagerly and cached when the snapshot is created.
376
- @param {String} keyName
377
- @return {Object} The attribute value or undefined
360
+ @return The attribute value or undefined
378
361
  @public
379
362
  */
380
363
  attr(keyName) {
@@ -390,12 +373,18 @@ class Snapshot {
390
373
 
391
374
  /**
392
375
  Returns all attributes and their corresponding values.
376
+ ::: warning ⚠️ WARNING
377
+ Attributes are SHALLOW copied from the cache.
378
+ Because they are NOT deep copied from the cache, mutating
379
+ any object or array fields will cause unintended side-effects
380
+ and bugs.
381
+ :::
393
382
  Example
394
- ```javascript
383
+ ```js
395
384
  // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
396
385
  postSnapshot.attributes(); // => { author: 'Tomster', title: 'Ember.js rocks' }
397
386
  ```
398
- @return {Object} All attributes of the current snapshot
387
+ @return All attributes of the current snapshot
399
388
  @public
400
389
  */
401
390
  attributes() {
@@ -407,12 +396,12 @@ class Snapshot {
407
396
  /**
408
397
  Returns all changed attributes and their old and new values.
409
398
  Example
410
- ```javascript
399
+ ```js
411
400
  // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
412
401
  postModel.set('title', 'Ember.js rocks!');
413
402
  postSnapshot.changedAttributes(); // => { title: ['Ember.js rocks', 'Ember.js rocks!'] }
414
403
  ```
415
- @return {Object} All changed attributes of the current snapshot
404
+ @return All changed attributes of the current snapshot
416
405
  @public
417
406
  */
418
407
  changedAttributes() {
@@ -435,7 +424,7 @@ class Snapshot {
435
424
  - `id`: set to `true` if you only want the ID of the related record to be
436
425
  returned.
437
426
  Example
438
- ```javascript
427
+ ```js
439
428
  // store.push('post', { id: 1, title: 'Hello World' });
440
429
  // store.createRecord('comment', { body: 'Lorem ipsum', post: post });
441
430
  commentSnapshot.belongsTo('post'); // => Snapshot
@@ -448,12 +437,10 @@ class Snapshot {
448
437
  known but unset, `belongsTo` will return `null`. If the contents of the
449
438
  relationship is unknown `belongsTo` will return `undefined`.
450
439
  Note: Relationships are loaded lazily and cached upon first access.
451
- @param {String} keyName
452
- @param {Object} [options]
453
- @public
454
- @return {(Snapshot|String|null|undefined)} A snapshot or ID of a known
455
- relationship or null if the relationship is known but unset. undefined
456
- will be returned if the contents of the relationship is unknown.
440
+ @public
441
+ @return A snapshot or ID of a known relationship or null if the
442
+ relationship is known but unset. undefined will be returned if the
443
+ contents of the relationship are unknown.
457
444
  */
458
445
  belongsTo(keyName, options) {
459
446
  const returnModeIsId = !!(options && options.id);
@@ -496,7 +483,7 @@ class Snapshot {
496
483
  }
497
484
  const value = this._store.cache.getRelationship(identifier, keyName);
498
485
  const data = value && value.data;
499
- const inverseIdentifier = data ? store.identifierCache.getOrCreateRecordIdentifier(data) : null;
486
+ const inverseIdentifier = data ? store.cacheKeyManager.getOrCreateRecordIdentifier(data) : null;
500
487
  if (value && value.data !== undefined) {
501
488
  const cache = store.cache;
502
489
  if (inverseIdentifier && !cache.isDeleted(inverseIdentifier)) {
@@ -532,10 +519,8 @@ class Snapshot {
532
519
  postSnapshot.hasMany('comments'); // => undefined
533
520
  ```
534
521
  Note: Relationships are loaded lazily and cached upon first access.
535
- @param {String} keyName
536
- @param {Object} [options]
537
- @public
538
- @return {(Array|undefined)} An array of snapshots or IDs of a known
522
+ @public
523
+ @return An array of snapshots or IDs of a known
539
524
  relationship or an empty array if the relationship is known but unset.
540
525
  undefined will be returned if the contents of the relationship is unknown.
541
526
  */
@@ -590,7 +575,7 @@ class Snapshot {
590
575
  if (value.data) {
591
576
  results = [];
592
577
  value.data.forEach(member => {
593
- const inverseIdentifier = store.identifierCache.getOrCreateRecordIdentifier(member);
578
+ const inverseIdentifier = store.cacheKeyManager.getOrCreateRecordIdentifier(member);
594
579
  const cache = store.cache;
595
580
  if (!cache.isDeleted(inverseIdentifier)) {
596
581
  if (returnModeIsIds) {
@@ -621,17 +606,24 @@ class Snapshot {
621
606
  // ...
622
607
  });
623
608
  ```
624
- @param {Function} callback the callback to execute
625
- @param {Object} [binding] the value to which the callback's `this` should be bound
609
+ @param callback the callback to execute
610
+ @param binding the optional value to which the callback's `this` should be bound
626
611
  @public
627
612
  */
628
613
  eachAttribute(callback, binding) {
629
- const fields = this._store.schema.fields(this.identifier);
630
- fields.forEach((field, key) => {
631
- if (field.kind === 'attribute') {
632
- callback.call(binding, key, field);
633
- }
634
- });
614
+ // if the store has a modelFor implementation, we use it to iterate attributes. This allows
615
+ // a custom "ModelSchema" class for legacy serializers to adapt to new fields if desired.
616
+ if (typeof this._store.modelFor === 'function') {
617
+ const modelSchema = this._store.modelFor(this.identifier.type);
618
+ modelSchema.eachAttribute(callback, binding);
619
+ } else {
620
+ const fields = this._store.schema.fields(this.identifier);
621
+ fields.forEach((field, key) => {
622
+ if (field.kind === 'attribute') {
623
+ callback.call(binding, key, field);
624
+ }
625
+ });
626
+ }
635
627
  }
636
628
 
637
629
  /**
@@ -643,17 +635,24 @@ class Snapshot {
643
635
  // ...
644
636
  });
645
637
  ```
646
- @param {Function} callback the callback to execute
647
- @param {Object} [binding] the value to which the callback's `this` should be bound
638
+ @param callback the callback to execute
639
+ @param binding the optional value to which the callback's `this` should be bound
648
640
  @public
649
641
  */
650
642
  eachRelationship(callback, binding) {
651
- const fields = this._store.schema.fields(this.identifier);
652
- fields.forEach((field, key) => {
653
- if (field.kind === 'belongsTo' || field.kind === 'hasMany') {
654
- callback.call(binding, key, field);
655
- }
656
- });
643
+ // if the store has a modelFor implementation, we use it to iterate relationships. This allows
644
+ // a custom "ModelSchema" class for legacy serializers to adapt to new fields if desired.
645
+ if (typeof this._store.modelFor === 'function') {
646
+ const modelSchema = this._store.modelFor(this.identifier.type);
647
+ modelSchema.eachRelationship(callback, binding);
648
+ } else {
649
+ const fields = this._store.schema.fields(this.identifier);
650
+ fields.forEach((field, key) => {
651
+ if (field.kind === 'belongsTo' || field.kind === 'hasMany') {
652
+ callback.call(binding, key, field);
653
+ }
654
+ });
655
+ }
657
656
  }
658
657
 
659
658
  /**
@@ -672,8 +671,7 @@ class Snapshot {
672
671
  }
673
672
  });
674
673
  ```
675
- @param {Object} options
676
- @return {Object} an object whose values are primitive JSON values only
674
+ @return an object whose values are primitive JSON values only
677
675
  @public
678
676
  */
679
677
  serialize(options) {
@@ -1 +1 @@
1
- export { d as determineBodyPromise, g as fetch, p as parseResponseHeaders, b as serializeIntoHash, s as serializeQueryParams, a as setupFastboot } from "../serialize-into-hash-Bp58npke.js";
1
+ export { d as determineBodyPromise, g as fetch, p as parseResponseHeaders, b as serializeIntoHash, s as serializeQueryParams, a as setupFastboot } from "../serialize-into-hash-B59laYa4.js";
@@ -1,7 +1,7 @@
1
1
  import { dasherize, pluralize } from '@warp-drive/utilities/string';
2
2
  import '@ember/debug';
3
3
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
- import { b as serializeIntoHash } from "../serialize-into-hash-Bp58npke.js";
4
+ import { b as serializeIntoHash } from "../serialize-into-hash-B59laYa4.js";
5
5
  import { RESTAdapter } from './rest.js';
6
6
  class JSONAPIAdapter extends RESTAdapter {
7
7
  _defaultContentType = 'application/vnd.api+json';
@@ -2,7 +2,7 @@ import { getOwner } from '@ember/application';
2
2
  import { warn } from '@ember/debug';
3
3
  import { computed } from '@ember/object';
4
4
  import { Adapter, BuildURLMixin } from '../adapter.js';
5
- import { b as serializeIntoHash, d as determineBodyPromise, g as getFetchFunction, s as serializeQueryParams, p as parseResponseHeaders } from "../serialize-into-hash-Bp58npke.js";
5
+ import { b as serializeIntoHash, d as determineBodyPromise, g as getFetchFunction, s as serializeQueryParams, p as parseResponseHeaders } from "../serialize-into-hash-B59laYa4.js";
6
6
  import { InvalidError, ServerError, ConflictError, NotFoundError, ForbiddenError, UnauthorizedError, AdapterError, TimeoutError, AbortError } from './error.js';
7
7
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
8
8
  import { d as decorateMethodV2 } from "../runtime-BPCpkOf1-BKOwiRJp.js";
@@ -1 +1 @@
1
- export { F as FetchManager, S as SaveOp, c as Snapshot, b as SnapshotRecordArray, u as upgradeStore } from "../-private-CKrP0ogQ.js";
1
+ export { F as FetchManager, S as SaveOp, c as Snapshot, b as SnapshotRecordArray, u as upgradeStore } from "../-private-CVsFOW1k.js";
@@ -227,7 +227,7 @@ function resourceIsFullyDeleted(instanceCache, identifier) {
227
227
  @return {SaveRecordRequestInput} request config
228
228
  */
229
229
  function saveRecordBuilder(record, options = {}) {
230
- const store = storeFor(record);
230
+ const store = storeFor(record, true);
231
231
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
232
232
  if (!test) {
233
233
  throw new Error(`Unable to initiate save for a record in a disconnected state`);
package/dist/compat.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { getOwner } from '@ember/application';
2
2
  import { recordIdentifierFor } from '@warp-drive/core';
3
3
  import { waitFor, _deprecatingNormalize } from '@warp-drive/core/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-CKrP0ogQ.js";
4
+ import '@warp-drive/core/reactive/-private';
5
+ import { p as payloadIsNotBlank, n as normalizeResponseHelper, i as iterateData, F as FetchManager, S as SaveOp, a as assertIdentifierHasId, b as SnapshotRecordArray } from "./-private-CVsFOW1k.js";
5
6
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
7
  function _findHasMany(adapter, store, identifier, link, relationship, options) {
7
8
  const promise = Promise.resolve().then(() => {