@warp-drive/legacy 5.7.0-alpha.12 → 5.7.0-alpha.14

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.
@@ -1,5 +1,5 @@
1
1
  import type { Store } from "@warp-drive/core";
2
- import type { CollectionRecordArray } from "@warp-drive/core/store/-private";
2
+ import type { LegacyQueryArray } from "@warp-drive/core/store/-private";
3
3
  import type { ModelSchema } from "@warp-drive/core/types";
4
4
  import type { LegacyRelationshipField as RelationshipSchema } from "@warp-drive/core/types/schema/fields";
5
5
  import type { Snapshot } from "./snapshot.js";
@@ -113,11 +113,11 @@ export interface MinimumAdapterInterface {
113
113
  * @param {ModelSchema} schema An object with methods for accessing information about
114
114
  * the type, attributes and relationships of the primary type associated with the request.
115
115
  * @param {Object} query
116
- * @param {CollectionRecordArray} recordArray
116
+ * @param {LegacyQueryArray} recordArray
117
117
  * @param {Object} options
118
118
  * @return {Promise} a promise resolving with resource data to feed to the associated serializer
119
119
  */
120
- query(store: Store, schema: ModelSchema, query: Record<string, unknown>, recordArray: CollectionRecordArray, options: {
120
+ query(store: Store, schema: ModelSchema, query: Record<string, unknown>, recordArray: LegacyQueryArray, options: {
121
121
  adapterOptions?: unknown;
122
122
  }): Promise<AdapterPayload>;
123
123
  /**
@@ -1,5 +1,5 @@
1
1
  import type { Store } from "@warp-drive/core";
2
- import type { LiveArray } from "@warp-drive/core/store/-private";
2
+ import type { LegacyLiveArray } from "@warp-drive/core/store/-private";
3
3
  import type { FindAllOptions, ModelSchema } from "@warp-drive/core/types";
4
4
  import type { Snapshot } from "./snapshot.js";
5
5
  /**
@@ -36,7 +36,7 @@ export declare class SnapshotRecordArray {
36
36
  @private
37
37
  @type {Array}
38
38
  */
39
- get _recordArray(): LiveArray;
39
+ get _recordArray(): LegacyLiveArray;
40
40
  /**
41
41
  Number of records in the array
42
42
 
@@ -14,46 +14,73 @@ adapters and serializers for certain requests.
14
14
  Snapshots are only available when using `@ember-data/legacy-compat`
15
15
  for legacy compatibility with adapters and serializers.
16
16
 
17
- @class Snapshot
17
+ For serialization of records in modern paradigms, request data from
18
+ the cache or off the record directly.
19
+
20
+ @hideconstructor
18
21
  @public
19
22
  */
20
23
  export declare class Snapshot<R = unknown> {
21
- __attributes: Record<keyof R & string, unknown> | null;
22
- _belongsToRelationships: Record<string, Snapshot>;
23
- _belongsToIds: Record<string, RecordId>;
24
- _hasManyRelationships: Record<string, Snapshot[]>;
25
- _hasManyIds: Record<string, RecordId[]>;
26
- _changedAttributes: ChangedAttributesHash;
24
+ private __attributes;
25
+ private _belongsToRelationships;
26
+ private _belongsToIds;
27
+ private _hasManyRelationships;
28
+ private _hasManyIds;
29
+ private _changedAttributes;
30
+ private _store;
31
+ /**
32
+ The unique RecordIdentifier associated with this Snapshot.
33
+
34
+ @public
35
+ */
27
36
  identifier: StableRecordIdentifier<R extends TypedRecordInstance ? TypeFromInstance<R> : string>;
37
+ /**
38
+ The ResourceType of the underlying record for this Snapshot, as a string.
39
+
40
+ @public
41
+ */
28
42
  modelName: R extends TypedRecordInstance ? TypeFromInstance<R> : string;
43
+ /**
44
+ The id of the snapshot's underlying record
45
+
46
+ Example
47
+
48
+ ```js
49
+ // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
50
+ postSnapshot.id; // => '1'
51
+ ```
52
+
53
+ @public
54
+ */
29
55
  id: string | null;
56
+ /**
57
+ If `include` was passed to the options for the request, the value
58
+ would be available here.
59
+
60
+ @public
61
+ */
30
62
  include?: string | string[];
31
- adapterOptions?: Record<string, unknown>;
32
- _store: Store;
33
63
  /**
34
- * @constructor
35
- * @private
36
- * @param options
37
- * @param identifier
38
- * @param _store
64
+ The adapterOptions passed to the request which generated this Snapshot, if any
65
+
66
+ @public
39
67
  */
68
+ adapterOptions?: Record<string, unknown>;
40
69
  constructor(options: FindRecordOptions, identifier: StableRecordIdentifier<R extends TypedRecordInstance ? TypeFromInstance<R> : string>, store: Store);
41
70
  /**
42
71
  The underlying record for this snapshot. Can be used to access methods and
43
72
  properties defined on the record.
44
73
 
45
- Example
46
-
47
- ```javascript
48
- let json = snapshot.record.toJSON();
74
+ ```js
75
+ const someValue = snapshot.record.someProp;
49
76
  ```
50
77
 
51
78
  @property record
52
- @type {Model}
53
79
  @public
54
80
  */
55
81
  get record(): R | null;
56
- get _attributes(): Record<keyof R & string, unknown>;
82
+ /** @internal */
83
+ private get _attributes();
57
84
  get isNew(): boolean;
58
85
  /**
59
86
  Returns the value of an attribute.
@@ -68,22 +95,28 @@ export declare class Snapshot<R = unknown> {
68
95
 
69
96
  Note: Values are loaded eagerly and cached when the snapshot is created.
70
97
 
71
- @param {String} keyName
72
- @return {Object} The attribute value or undefined
98
+ @return The attribute value or undefined
73
99
  @public
74
100
  */
75
101
  attr(keyName: keyof R & string): unknown;
76
102
  /**
77
103
  Returns all attributes and their corresponding values.
78
104
 
105
+ ::: warning ⚠️ WARNING
106
+ Attributes are SHALLOW copied from the cache.
107
+ Because they are NOT deep copied from the cache, mutating
108
+ any object or array fields will cause unintended side-effects
109
+ and bugs.
110
+ :::
111
+
79
112
  Example
80
113
 
81
- ```javascript
114
+ ```js
82
115
  // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
83
116
  postSnapshot.attributes(); // => { author: 'Tomster', title: 'Ember.js rocks' }
84
117
  ```
85
118
 
86
- @return {Object} All attributes of the current snapshot
119
+ @return All attributes of the current snapshot
87
120
  @public
88
121
  */
89
122
  attributes(): Record<keyof R & string, unknown>;
@@ -92,13 +125,13 @@ export declare class Snapshot<R = unknown> {
92
125
 
93
126
  Example
94
127
 
95
- ```javascript
128
+ ```js
96
129
  // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
97
130
  postModel.set('title', 'Ember.js rocks!');
98
131
  postSnapshot.changedAttributes(); // => { title: ['Ember.js rocks', 'Ember.js rocks!'] }
99
132
  ```
100
133
 
101
- @return {Object} All changed attributes of the current snapshot
134
+ @return All changed attributes of the current snapshot
102
135
  @public
103
136
  */
104
137
  changedAttributes(): ChangedAttributesHash;
@@ -113,7 +146,7 @@ export declare class Snapshot<R = unknown> {
113
146
 
114
147
  Example
115
148
 
116
- ```javascript
149
+ ```js
117
150
  // store.push('post', { id: 1, title: 'Hello World' });
118
151
  // store.createRecord('comment', { body: 'Lorem ipsum', post: post });
119
152
  commentSnapshot.belongsTo('post'); // => Snapshot
@@ -130,12 +163,10 @@ export declare class Snapshot<R = unknown> {
130
163
 
131
164
  Note: Relationships are loaded lazily and cached upon first access.
132
165
 
133
- @param {String} keyName
134
- @param {Object} [options]
135
166
  @public
136
- @return {(Snapshot|String|null|undefined)} A snapshot or ID of a known
137
- relationship or null if the relationship is known but unset. undefined
138
- will be returned if the contents of the relationship is unknown.
167
+ @return A snapshot or ID of a known relationship or null if the
168
+ relationship is known but unset. undefined will be returned if the
169
+ contents of the relationship are unknown.
139
170
  */
140
171
  belongsTo(keyName: string, options?: {
141
172
  id?: boolean;
@@ -162,10 +193,8 @@ export declare class Snapshot<R = unknown> {
162
193
 
163
194
  Note: Relationships are loaded lazily and cached upon first access.
164
195
 
165
- @param {String} keyName
166
- @param {Object} [options]
167
196
  @public
168
- @return {(Array|undefined)} An array of snapshots or IDs of a known
197
+ @return An array of snapshots or IDs of a known
169
198
  relationship or an empty array if the relationship is known but unset.
170
199
  undefined will be returned if the contents of the relationship is unknown.
171
200
  */
@@ -184,8 +213,8 @@ export declare class Snapshot<R = unknown> {
184
213
  });
185
214
  ```
186
215
 
187
- @param {Function} callback the callback to execute
188
- @param {Object} [binding] the value to which the callback's `this` should be bound
216
+ @param callback the callback to execute
217
+ @param binding the optional value to which the callback's `this` should be bound
189
218
  @public
190
219
  */
191
220
  eachAttribute(callback: (key: string, meta: LegacyAttributeField) => void, binding?: unknown): void;
@@ -201,8 +230,8 @@ export declare class Snapshot<R = unknown> {
201
230
  });
202
231
  ```
203
232
 
204
- @param {Function} callback the callback to execute
205
- @param {Object} [binding] the value to which the callback's `this` should be bound
233
+ @param callback the callback to execute
234
+ @param binding the optional value to which the callback's `this` should be bound
206
235
  @public
207
236
  */
208
237
  eachRelationship(callback: (key: string, meta: LegacyRelationshipField) => void, binding?: unknown): void;
@@ -227,8 +256,7 @@ export declare class Snapshot<R = unknown> {
227
256
  });
228
257
  ```
229
258
 
230
- @param {Object} options
231
- @return {Object} an object whose values are primitive JSON values only
259
+ @return an object whose values are primitive JSON values only
232
260
  @public
233
261
  */
234
262
  serialize(options?: SerializerOptions): unknown;
@@ -1,7 +1,6 @@
1
1
  import type { Store } from "@warp-drive/core";
2
2
  import type { CollectionEdge, Graph, ResourceEdge, UpgradedMeta } from "@warp-drive/core/graph/-private";
3
- import type { LiveArray } from "@warp-drive/core/store/-private";
4
- import { RelatedCollection as ManyArray } from "@warp-drive/core/store/-private";
3
+ import type { LegacyManyArray } from "@warp-drive/core/store/-private";
5
4
  import type { BaseFinderOptions, StableRecordIdentifier } from "@warp-drive/core/types";
6
5
  import type { Cache } from "@warp-drive/core/types/cache";
7
6
  import type { CollectionRelationship } from "@warp-drive/core/types/cache/relationship";
@@ -24,24 +23,24 @@ export declare class LegacySupport {
24
23
  cache: Cache;
25
24
  references: Record<string, BelongsToReference | HasManyReference>;
26
25
  identifier: StableRecordIdentifier;
27
- _manyArrayCache: Record<string, ManyArray>;
28
- _relationshipPromisesCache: Record<string, Promise<ManyArray | OpaqueRecordInstance>>;
26
+ _manyArrayCache: Record<string, LegacyManyArray>;
27
+ _relationshipPromisesCache: Record<string, Promise<LegacyManyArray | OpaqueRecordInstance>>;
29
28
  _relationshipProxyCache: Record<string, PromiseManyArray | PromiseBelongsTo | undefined>;
30
29
  _pending: Record<string, Promise<StableRecordIdentifier | null> | undefined>;
31
30
  isDestroying: boolean;
32
31
  isDestroyed: boolean;
33
- constructor(record: MinimalLegacyRecord);
34
- _syncArray(array: LiveArray): void;
32
+ constructor(record: MinimalLegacyRecord, identifier: StableRecordIdentifier);
33
+ _syncArray(array: LegacyManyArray): void;
35
34
  mutate(mutation: LocalRelationshipOperation): void;
36
35
  _findBelongsTo(key: string, resource: SingleResourceRelationship, relationship: ResourceEdge, options?: BaseFinderOptions): Promise<OpaqueRecordInstance | null>;
37
36
  reloadBelongsTo(key: string, options?: BaseFinderOptions): Promise<OpaqueRecordInstance | null>;
38
37
  getBelongsTo(key: string, options?: BaseFinderOptions): PromiseBelongsTo | OpaqueRecordInstance | null;
39
38
  setDirtyBelongsTo(key: string, value: OpaqueRecordInstance | null): void;
40
39
  _getCurrentState<T>(identifier: StableRecordIdentifier, field: string): [StableRecordIdentifier<TypeFromInstanceOrString<T>>[], CollectionRelationship];
41
- getManyArray<T>(key: string, definition?: UpgradedMeta): ManyArray<T>;
42
- fetchAsyncHasMany(key: string, relationship: CollectionEdge, manyArray: ManyArray, options?: BaseFinderOptions): Promise<ManyArray>;
43
- reloadHasMany<T>(key: string, options?: BaseFinderOptions): Promise<ManyArray<T>> | PromiseManyArray<T>;
44
- getHasMany(key: string, options?: BaseFinderOptions): PromiseManyArray | ManyArray;
40
+ getManyArray<T>(key: string, definition?: UpgradedMeta): LegacyManyArray<T>;
41
+ fetchAsyncHasMany(key: string, relationship: CollectionEdge, manyArray: LegacyManyArray, options?: BaseFinderOptions): Promise<LegacyManyArray>;
42
+ reloadHasMany<T>(key: string, options?: BaseFinderOptions): Promise<LegacyManyArray<T>> | PromiseManyArray<T>;
43
+ getHasMany(key: string, options?: BaseFinderOptions): PromiseManyArray | LegacyManyArray;
45
44
  _updatePromiseProxyFor(kind: "hasMany", key: string, args: HasManyProxyCreateArgs): PromiseManyArray;
46
45
  _updatePromiseProxyFor(kind: "belongsTo", key: string, args: BelongsToProxyCreateArgs): PromiseBelongsTo;
47
46
  _updatePromiseProxyFor(kind: "belongsTo", key: string, args: {
@@ -1,7 +1,7 @@
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
@@ -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 RecordIdentifier 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);
@@ -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
  */
@@ -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-BJjGi7jB.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-BJjGi7jB.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-BJjGi7jB.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-DGArz5W5.js";
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-DGArz5W5.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(() => {
@@ -1,7 +1,8 @@
1
- import { memoized, defineSignal, defineNonEnumerableSignal, isStableIdentifier, recordIdentifierFor, storeFor, SOURCE, fastPush, RelatedCollection, notifyInternalSignal, ARRAY_SIGNAL } from '@warp-drive/core/store/-private';
1
+ import { Context } from '@warp-drive/core/reactive/-private';
2
+ import { memoized, defineSignal, defineNonEnumerableSignal, isStableIdentifier, recordIdentifierFor, storeFor, fastPush, createLegacyManyArray, notifyInternalSignal } from '@warp-drive/core/store/-private';
2
3
  import { getOrSetGlobal } from '@warp-drive/core/types/-private';
3
4
  import { EnableHydration } from '@warp-drive/core/types/request';
4
- import { u as upgradeStore } from "./-private-CKrP0ogQ.js";
5
+ import { u as upgradeStore } from "./-private-DGArz5W5.js";
5
6
  import { computed, get } from '@ember/object';
6
7
  import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
7
8
  import ObjectProxy from '@ember/object/proxy';
@@ -1508,17 +1509,16 @@ function lookupLegacySupport(record) {
1508
1509
  throw new Error(`Memory Leak Detected`);
1509
1510
  }
1510
1511
  })(!record.isDestroyed && !record.isDestroying) : {};
1511
- support = new LegacySupport(record);
1512
+ support = new LegacySupport(record, identifier);
1512
1513
  LEGACY_SUPPORT.set(identifier, support);
1513
- LEGACY_SUPPORT.set(record, support);
1514
1514
  }
1515
1515
  return support;
1516
1516
  }
1517
1517
  class LegacySupport {
1518
- constructor(record) {
1518
+ constructor(record, identifier) {
1519
1519
  this.record = record;
1520
1520
  this.store = storeFor(record, false);
1521
- this.identifier = recordIdentifierFor(record);
1521
+ this.identifier = identifier;
1522
1522
  this.cache = this.store.cache;
1523
1523
  if (this.store._graph) {
1524
1524
  this.graph = this.store._graph;
@@ -1534,7 +1534,7 @@ class LegacySupport {
1534
1534
  if (this.isDestroyed || this.isDestroying) {
1535
1535
  return;
1536
1536
  }
1537
- const currentState = array[SOURCE];
1537
+ const currentState = array[Context].source;
1538
1538
  const identifier = this.identifier;
1539
1539
  const [identifiers, jsonApi] = this._getCurrentState(identifier, array.key);
1540
1540
  if (jsonApi.meta) {
@@ -1664,23 +1664,20 @@ class LegacySupport {
1664
1664
  }
1665
1665
  if (!manyArray) {
1666
1666
  const [identifiers, doc] = this._getCurrentState(this.identifier, key);
1667
- manyArray = new RelatedCollection({
1667
+ manyArray = createLegacyManyArray({
1668
1668
  store: this.store,
1669
- type: definition.type,
1670
- identifier: this.identifier,
1671
- cache: this.cache,
1672
- field: this.store.schema.fields(this.identifier).get(key),
1673
- identifiers,
1674
- key,
1675
- meta: doc.meta || null,
1676
- links: doc.links || null,
1677
- isPolymorphic: definition.isPolymorphic,
1678
- isAsync: definition.isAsync,
1679
- _inverseIsAsync: definition.inverseIsAsync,
1680
1669
  // @ts-expect-error Typescript doesn't have a way for us to thread the generic backwards so it infers unknown instead of T
1681
1670
  manager: this,
1671
+ source: identifiers,
1672
+ type: definition.type,
1682
1673
  isLoaded: !definition.isAsync,
1683
- allowMutation: true
1674
+ editable: true,
1675
+ isAsync: definition.isAsync,
1676
+ isPolymorphic: definition.isPolymorphic,
1677
+ field: this.store.schema.fields(this.identifier).get(key),
1678
+ identifier: this.identifier,
1679
+ links: doc.links || null,
1680
+ meta: doc.meta || null
1684
1681
  });
1685
1682
  this._manyArrayCache[key] = manyArray;
1686
1683
  }
@@ -2104,7 +2101,7 @@ function handleCompletedRelationshipRequest(recordExt, key, relationship, value,
2104
2101
  if (isHasMany) {
2105
2102
  // we don't notify the record property here to avoid refetch
2106
2103
  // only the many array
2107
- notifyInternalSignal(value[ARRAY_SIGNAL]);
2104
+ notifyInternalSignal(value[Context].signal);
2108
2105
  }
2109
2106
  if (error) {
2110
2107
  relationship.state.hasFailedLoadAttempt = true;
@@ -1,2 +1 @@
1
- export { E as Errors, L as LEGACY_SUPPORT, P as PromiseBelongsTo, a as PromiseManyArray, l as lookupLegacySupport } from "../errors-DK6DtmZN.js";
2
- export { RelatedCollection as ManyArray } from '@warp-drive/core/store/-private';
1
+ export { E as Errors, L as LEGACY_SUPPORT, P as PromiseBelongsTo, a as PromiseManyArray, l as lookupLegacySupport } from "../errors-CI53ie90.js";
@@ -1,10 +1,11 @@
1
1
  import { deprecate } from '@ember/debug';
2
2
  import { recordIdentifierFor } from '@warp-drive/core';
3
- import { notifyInternalSignal, ARRAY_SIGNAL } from '@warp-drive/core/store/-private';
3
+ import { Context } from '@warp-drive/core/reactive/-private';
4
+ import { notifyInternalSignal } from '@warp-drive/core/store/-private';
4
5
  import { getOrSetGlobal } from '@warp-drive/core/types/-private';
5
6
  import { Type } from '@warp-drive/core/types/symbols';
6
- import { l as lookupLegacySupport, E as Errors } from "../errors-DK6DtmZN.js";
7
- import { b as buildSchema, u as unloadRecord, s as serialize, _ as _save, a as save, r as rollbackAttributes, c as _reload, d as reload, h as hasMany, e as _destroyRecord, f as destroyRecord, g as deleteRecord, R as RecordState, i as changedAttributes, j as belongsTo, k as createSnapshot } from "../schema-provider-DXczOefH.js";
7
+ import { l as lookupLegacySupport, E as Errors } from "../errors-CI53ie90.js";
8
+ import { b as buildSchema, u as unloadRecord, s as serialize, _ as _save, a as save, r as rollbackAttributes, c as _reload, d as reload, h as hasMany, e as _destroyRecord, f as destroyRecord, g as deleteRecord, R as RecordState, i as changedAttributes, j as belongsTo, k as createSnapshot } from "../schema-provider-keKLiu7p.js";
8
9
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
9
10
 
10
11
  /**
@@ -344,7 +345,7 @@ function registerDerivations(schema) {
344
345
  return false;
345
346
  }
346
347
  if (manyArray) {
347
- notifyInternalSignal(manyArray[ARRAY_SIGNAL]);
348
+ notifyInternalSignal(manyArray[Context].signal);
348
349
  return true;
349
350
  }
350
351
  return false;
package/dist/model.js CHANGED
@@ -4,10 +4,10 @@ import { RecordStore } from '@warp-drive/core/types/symbols';
4
4
  import { i as isElementDescriptor, n as normalizeModelName } from "./util-Dul6TZts.js";
5
5
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
6
  import { warn, deprecate } from '@ember/debug';
7
- import { l as lookupLegacySupport } from "./errors-DK6DtmZN.js";
7
+ import { l as lookupLegacySupport } from "./errors-CI53ie90.js";
8
8
  import { singularize, dasherize } from '@warp-drive/utilities/string';
9
- import { l as getModelFactory } from "./schema-provider-DXczOefH.js";
10
- export { M as Model, b as buildSchema, M as default, m as restoreDeprecatedModelRequestBehaviors } from "./schema-provider-DXczOefH.js";
9
+ import { l as getModelFactory } from "./schema-provider-keKLiu7p.js";
10
+ export { M as Model, b as buildSchema, M as default, m as restoreDeprecatedModelRequestBehaviors } from "./schema-provider-keKLiu7p.js";
11
11
  import { setOwner, getOwner } from '@ember/application';
12
12
  import { setRecordIdentifier, StoreMap } from '@warp-drive/core/store/-private';
13
13
  function _attr(type, options) {
@@ -2,12 +2,13 @@ import { getOwner } from '@ember/application';
2
2
  import { deprecate } from '@ember/debug';
3
3
  import EmberObject from '@ember/object';
4
4
  import { recordIdentifierFor, storeFor } from '@warp-drive/core';
5
- import { notifyInternalSignal, peekInternalSignal, withSignalStore, ARRAY_SIGNAL, recordIdentifierFor as recordIdentifierFor$1, gate, memoized, defineSignal, coerceId, entangleSignal, defineGate } from '@warp-drive/core/store/-private';
5
+ import { notifyInternalSignal, peekInternalSignal, withSignalStore, recordIdentifierFor as recordIdentifierFor$1, gate, memoized, defineSignal, coerceId, entangleSignal, defineGate } from '@warp-drive/core/store/-private';
6
6
  import { RecordStore } from '@warp-drive/core/types/symbols';
7
- import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-DK6DtmZN.js";
8
- import { u as upgradeStore, F as FetchManager } from "./-private-CKrP0ogQ.js";
7
+ import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-CI53ie90.js";
8
+ import { u as upgradeStore, F as FetchManager } from "./-private-DGArz5W5.js";
9
9
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
10
10
  import { cacheFor } from '@ember/object/internals';
11
+ import { Context } from '@warp-drive/core/reactive/-private';
11
12
  import { d as decorateMethodV2 } from "./runtime-BPCpkOf1-BKOwiRJp.js";
12
13
  import { n as normalizeModelName } from "./util-Dul6TZts.js";
13
14
  function rollbackAttributes() {
@@ -216,7 +217,7 @@ function notifyRelationship(identifier, key, record, meta) {
216
217
  return;
217
218
  }
218
219
  if (manyArray) {
219
- notifyInternalSignal(manyArray[ARRAY_SIGNAL]);
220
+ notifyInternalSignal(manyArray[Context].signal);
220
221
 
221
222
  //We need to notifyPropertyChange in the adding case because we need to make sure
222
223
  //we fetch the newly added record in case it is unloaded
@@ -736,9 +737,11 @@ class Model extends EmberObject {
736
737
  this.___recordState?.destroy();
737
738
  const store = storeFor(this, false);
738
739
  store.notifications.unsubscribe(this.___private_notifications);
739
- LEGACY_SUPPORT.get(this)?.destroy();
740
- LEGACY_SUPPORT.delete(this);
741
- LEGACY_SUPPORT.delete(identifier);
740
+ const support = LEGACY_SUPPORT.get(identifier);
741
+ if (support) {
742
+ support.destroy();
743
+ LEGACY_SUPPORT.delete(identifier);
744
+ }
742
745
  super.destroy();
743
746
  }
744
747
 
@@ -1035,7 +1038,7 @@ class Model extends EmberObject {
1035
1038
  })(!didChange || identifier.id === null) : {};
1036
1039
  if (normalizedId !== null && didChange) {
1037
1040
  this.store._instanceCache.setRecordId(identifier, normalizedId);
1038
- this.store.notifications.notify(identifier, 'identity');
1041
+ this.store.notifications.notify(identifier, 'identity', null);
1039
1042
  }
1040
1043
  }
1041
1044
  toString() {
@@ -1,7 +1,7 @@
1
1
  import { warn } from '@ember/debug';
2
2
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
3
- import '@warp-drive/core/store/-private';
4
- import "./-private-CKrP0ogQ.js";
3
+ import '@warp-drive/core/reactive/-private';
4
+ import "./-private-DGArz5W5.js";
5
5
  const newline = /\r?\n/;
6
6
  function parseResponseHeaders(headersString) {
7
7
  const headers = Object.create(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warp-drive/legacy",
3
- "version": "5.7.0-alpha.12",
3
+ "version": "5.7.0-alpha.14",
4
4
  "description": "Decommissioned Packages for WarpDrive | Things your app might still want to maintain use of for a little longer.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -32,8 +32,8 @@
32
32
  }
33
33
  },
34
34
  "peerDependencies": {
35
- "@warp-drive/core": "5.7.0-alpha.12",
36
- "@warp-drive/utilities": "5.7.0-alpha.12"
35
+ "@warp-drive/core": "5.7.0-alpha.14",
36
+ "@warp-drive/utilities": "5.7.0-alpha.14"
37
37
  },
38
38
  "dependencies": {
39
39
  "@embroider/macros": "^1.16.12"
@@ -43,9 +43,9 @@
43
43
  "@babel/plugin-transform-typescript": "^7.27.0",
44
44
  "@babel/preset-typescript": "^7.27.0",
45
45
  "@types/jquery": "^3.5.32",
46
- "@warp-drive/internal-config": "5.7.0-alpha.12",
47
- "@warp-drive/core": "5.7.0-alpha.12",
48
- "@warp-drive/utilities": "5.7.0-alpha.12",
46
+ "@warp-drive/internal-config": "5.7.0-alpha.14",
47
+ "@warp-drive/core": "5.7.0-alpha.14",
48
+ "@warp-drive/utilities": "5.7.0-alpha.14",
49
49
  "ember-source": "~6.3.0",
50
50
  "decorator-transforms": "^2.3.0",
51
51
  "expect-type": "^1.2.1",