@warp-drive/legacy 5.7.0-alpha.9 → 5.7.0-beta.0
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.
- package/declarations/adapter/-private/build-url-mixin.d.ts +0 -13
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -7
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts +0 -4
- package/declarations/adapter/error.d.ts +0 -1
- package/declarations/adapter/rest.d.ts +0 -2
- package/declarations/adapter.d.ts +0 -5
- package/declarations/compat/builders/find-all.d.ts +2 -2
- package/declarations/compat/builders/query.d.ts +2 -2
- package/declarations/compat/builders/save-record.d.ts +3 -3
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +24 -17
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -2
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +5 -5
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +3 -8
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +40 -18
- package/declarations/compat/legacy-network-handler/snapshot.d.ts +63 -44
- package/declarations/compat.d.ts +3 -6
- package/declarations/model/-private/attr.d.ts +1 -14
- package/declarations/model/-private/belongs-to.d.ts +0 -11
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +2 -14
- package/declarations/model/-private/errors.d.ts +0 -6
- package/declarations/model/-private/has-many.d.ts +0 -4
- package/declarations/model/-private/hooks.d.ts +2 -2
- package/declarations/model/-private/legacy-relationships-support.d.ts +18 -27
- package/declarations/model/-private/model-for-mixin.d.ts +0 -16
- package/declarations/model/-private/model-methods.d.ts +0 -4
- package/declarations/model/-private/model.d.ts +13 -69
- package/declarations/model/-private/notify-changes.d.ts +2 -2
- package/declarations/model/-private/promise-belongs-to.d.ts +0 -6
- package/declarations/model/-private/promise-many-array.d.ts +0 -11
- package/declarations/model/-private/record-state.d.ts +2 -25
- package/declarations/model/-private/references/belongs-to.d.ts +6 -7
- package/declarations/model/-private/references/has-many.d.ts +6 -13
- package/declarations/model/-private/schema-provider.d.ts +6 -10
- package/declarations/model/-private.d.ts +1 -2
- package/declarations/model/migration-support.d.ts +9 -33
- package/declarations/serializer/json-api.d.ts +0 -1
- package/declarations/serializer/json.d.ts +0 -1
- package/declarations/serializer/rest.d.ts +0 -1
- package/declarations/store/-private.d.ts +12 -24
- package/dist/{-private-CKrP0ogQ.js → -private-8UmnAf9J.js} +169 -141
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/json-api.js +1 -1
- package/dist/adapter/rest.js +1 -1
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.js +3 -2
- package/dist/compat.js +7 -2
- package/dist/{errors-BX5wowuz.js → errors-8kD2mSe_.js} +66 -36
- package/dist/model/-private.js +1 -2
- package/dist/model/migration-support.js +7 -4
- package/dist/model.js +13 -11
- package/dist/{schema-provider-Cbnf6sKm.js → schema-provider-DQu4Rjco.js} +62 -26
- package/dist/{serialize-into-hash-Bp58npke.js → serialize-into-hash-CS0MIv4F.js} +2 -1
- package/dist/store.js +8 -6
- package/package.json +15 -15
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
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 { assertPrivateStore, 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
|
|
|
@@ -9,40 +10,26 @@ import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
|
9
10
|
Instances are provided to consuming application's
|
|
10
11
|
adapters for certain `findAll` requests.
|
|
11
12
|
|
|
12
|
-
@
|
|
13
|
+
@hideconstructor
|
|
13
14
|
@public
|
|
14
15
|
*/
|
|
15
16
|
class SnapshotRecordArray {
|
|
16
17
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@private
|
|
21
|
-
@constructor
|
|
22
|
-
@param {Store} store
|
|
23
|
-
@param {String} type
|
|
24
|
-
@param options
|
|
18
|
+
* An array of snapshots
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
25
21
|
*/
|
|
26
|
-
constructor(store, type, options = {}) {
|
|
27
|
-
this.__store = store;
|
|
28
|
-
/**
|
|
29
|
-
An array of snapshots
|
|
30
|
-
@private
|
|
31
|
-
@property _snapshots
|
|
32
|
-
@type {Array}
|
|
33
|
-
*/
|
|
34
|
-
this._snapshots = null;
|
|
35
22
|
|
|
36
|
-
|
|
37
|
-
The modelName of the underlying records for the snapshots in the array, as a Model
|
|
38
|
-
@property modelName
|
|
39
|
-
@public
|
|
40
|
-
@type {Model}
|
|
41
|
-
*/
|
|
42
|
-
this.modelName = type;
|
|
23
|
+
/** @internal */
|
|
43
24
|
|
|
44
|
-
|
|
45
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The ResourceType of the underlying records for the {@link Snapshot | Snapshots} in the array
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** @internal */
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A hash of adapter options passed into the store method for this request.
|
|
46
33
|
Example
|
|
47
34
|
```js [app/adapters/post.js]
|
|
48
35
|
import MyCustomAdapter from './custom-adapter';
|
|
@@ -55,14 +42,10 @@ class SnapshotRecordArray {
|
|
|
55
42
|
}
|
|
56
43
|
}
|
|
57
44
|
```
|
|
58
|
-
|
|
59
|
-
@public
|
|
60
|
-
@type {Object}
|
|
61
|
-
*/
|
|
62
|
-
this.adapterOptions = options.adapterOptions;
|
|
45
|
+
*/
|
|
63
46
|
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
/**
|
|
48
|
+
* The relationships to include for this request.
|
|
66
49
|
Example
|
|
67
50
|
```js [app/adapters/application.js]
|
|
68
51
|
import Adapter from '@ember-data/adapter';
|
|
@@ -73,18 +56,29 @@ class SnapshotRecordArray {
|
|
|
73
56
|
}
|
|
74
57
|
}
|
|
75
58
|
```
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
SnapshotRecordArray is not directly instantiable.
|
|
63
|
+
Instances are provided to consuming application's
|
|
64
|
+
adapters and serializers for certain requests.
|
|
65
|
+
@private
|
|
66
|
+
@constructor
|
|
67
|
+
@param {Store} store
|
|
68
|
+
@param {String} type
|
|
69
|
+
@param options
|
|
70
|
+
*/
|
|
71
|
+
constructor(store, type, options = {}) {
|
|
72
|
+
this.__store = store;
|
|
73
|
+
this._snapshots = null;
|
|
74
|
+
this.modelName = type;
|
|
75
|
+
this.adapterOptions = options.adapterOptions;
|
|
80
76
|
this.include = options.include;
|
|
81
77
|
}
|
|
82
78
|
|
|
83
79
|
/**
|
|
84
80
|
An array of records
|
|
85
|
-
@
|
|
86
|
-
@private
|
|
87
|
-
@type {Array}
|
|
81
|
+
@internal
|
|
88
82
|
*/
|
|
89
83
|
get _recordArray() {
|
|
90
84
|
return this.__store.peekAll(this.modelName);
|
|
@@ -101,9 +95,6 @@ class SnapshotRecordArray {
|
|
|
101
95
|
}
|
|
102
96
|
});
|
|
103
97
|
```
|
|
104
|
-
@property length
|
|
105
|
-
@public
|
|
106
|
-
@type {Number}
|
|
107
98
|
*/
|
|
108
99
|
get length() {
|
|
109
100
|
return this._recordArray.length;
|
|
@@ -139,7 +130,8 @@ class SnapshotRecordArray {
|
|
|
139
130
|
const {
|
|
140
131
|
_fetchManager
|
|
141
132
|
} = this.__store;
|
|
142
|
-
|
|
133
|
+
const LiveArrayContext = this._recordArray[Context];
|
|
134
|
+
this._snapshots = LiveArrayContext.source.map(identifier => _fetchManager.createSnapshot(identifier));
|
|
143
135
|
return this._snapshots;
|
|
144
136
|
}
|
|
145
137
|
}
|
|
@@ -238,17 +230,58 @@ function normalizeResponseHelper(serializer, store, modelClass, payload, id, req
|
|
|
238
230
|
Snapshots are only available when using `@ember-data/legacy-compat`
|
|
239
231
|
for legacy compatibility with adapters and serializers.
|
|
240
232
|
|
|
241
|
-
|
|
233
|
+
For serialization of records in modern paradigms, request data from
|
|
234
|
+
the cache or off the record directly.
|
|
235
|
+
|
|
236
|
+
@hideconstructor
|
|
242
237
|
@public
|
|
243
238
|
*/
|
|
244
239
|
class Snapshot {
|
|
240
|
+
/** @internal */
|
|
241
|
+
|
|
242
|
+
/** @internal */
|
|
243
|
+
|
|
244
|
+
/** @internal */
|
|
245
|
+
|
|
246
|
+
/** @internal */
|
|
247
|
+
|
|
248
|
+
/** @internal */
|
|
249
|
+
|
|
250
|
+
/** @internal */
|
|
251
|
+
|
|
252
|
+
/** @internal */
|
|
253
|
+
|
|
245
254
|
/**
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
255
|
+
The unique ResourceKey associated with this Snapshot.
|
|
256
|
+
@public
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
The ResourceType of the underlying record for this Snapshot, as a string.
|
|
261
|
+
@public
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
The id of the snapshot's underlying record
|
|
266
|
+
Example
|
|
267
|
+
```js
|
|
268
|
+
// store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
|
|
269
|
+
postSnapshot.id; // => '1'
|
|
270
|
+
```
|
|
271
|
+
@public
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
If `include` was passed to the options for the request, the value
|
|
276
|
+
would be available here.
|
|
277
|
+
@public
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
The adapterOptions passed to the request which generated this Snapshot, if any
|
|
282
|
+
@public
|
|
283
|
+
*/
|
|
284
|
+
|
|
252
285
|
constructor(options, identifier, store) {
|
|
253
286
|
this._store = store;
|
|
254
287
|
this.__attributes = null;
|
|
@@ -256,15 +289,9 @@ class Snapshot {
|
|
|
256
289
|
this._belongsToIds = Object.create(null);
|
|
257
290
|
this._hasManyRelationships = Object.create(null);
|
|
258
291
|
this._hasManyIds = Object.create(null);
|
|
292
|
+
assertPrivateStore(store);
|
|
259
293
|
const hasRecord = !!store._instanceCache.peek(identifier);
|
|
260
294
|
this.modelName = identifier.type;
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
The unique RecordIdentifier associated with this Snapshot.
|
|
264
|
-
@property identifier
|
|
265
|
-
@public
|
|
266
|
-
@type {StableRecordIdentifier}
|
|
267
|
-
*/
|
|
268
295
|
this.identifier = identifier;
|
|
269
296
|
|
|
270
297
|
/*
|
|
@@ -278,43 +305,9 @@ class Snapshot {
|
|
|
278
305
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
279
306
|
this._attributes;
|
|
280
307
|
}
|
|
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
308
|
this.id = identifier.id;
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
A hash of adapter options
|
|
297
|
-
@property adapterOptions
|
|
298
|
-
@type {Object}
|
|
299
|
-
@public
|
|
300
|
-
*/
|
|
301
309
|
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
310
|
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
311
|
this.modelName = identifier.type;
|
|
319
312
|
if (hasRecord) {
|
|
320
313
|
const cache = this._store.cache;
|
|
@@ -325,12 +318,10 @@ class Snapshot {
|
|
|
325
318
|
/**
|
|
326
319
|
The underlying record for this snapshot. Can be used to access methods and
|
|
327
320
|
properties defined on the record.
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
let json = snapshot.record.toJSON();
|
|
321
|
+
```js
|
|
322
|
+
const someValue = snapshot.record.someProp;
|
|
331
323
|
```
|
|
332
324
|
@property record
|
|
333
|
-
@type {Model}
|
|
334
325
|
@public
|
|
335
326
|
*/
|
|
336
327
|
get record() {
|
|
@@ -342,6 +333,8 @@ class Snapshot {
|
|
|
342
333
|
})(record !== null) : {};
|
|
343
334
|
return record;
|
|
344
335
|
}
|
|
336
|
+
|
|
337
|
+
/** @internal */
|
|
345
338
|
get _attributes() {
|
|
346
339
|
if (this.__attributes !== null) {
|
|
347
340
|
return this.__attributes;
|
|
@@ -350,12 +343,9 @@ class Snapshot {
|
|
|
350
343
|
const {
|
|
351
344
|
identifier
|
|
352
345
|
} = this;
|
|
353
|
-
const attrs = this._store.schema.fields(identifier);
|
|
354
346
|
const cache = this._store.cache;
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
attributes[keyName] = cache.getAttr(identifier, keyName);
|
|
358
|
-
}
|
|
347
|
+
this.eachAttribute((key, meta) => {
|
|
348
|
+
attributes[key] = cache.getAttr(identifier, key);
|
|
359
349
|
});
|
|
360
350
|
return attributes;
|
|
361
351
|
}
|
|
@@ -373,8 +363,7 @@ class Snapshot {
|
|
|
373
363
|
postSnapshot.attr('title'); // => 'Ember.js rocks'
|
|
374
364
|
```
|
|
375
365
|
Note: Values are loaded eagerly and cached when the snapshot is created.
|
|
376
|
-
@
|
|
377
|
-
@return {Object} The attribute value or undefined
|
|
366
|
+
@return The attribute value or undefined
|
|
378
367
|
@public
|
|
379
368
|
*/
|
|
380
369
|
attr(keyName) {
|
|
@@ -390,12 +379,18 @@ class Snapshot {
|
|
|
390
379
|
|
|
391
380
|
/**
|
|
392
381
|
Returns all attributes and their corresponding values.
|
|
382
|
+
::: warning ⚠️ WARNING
|
|
383
|
+
Attributes are SHALLOW copied from the cache.
|
|
384
|
+
Because they are NOT deep copied from the cache, mutating
|
|
385
|
+
any object or array fields will cause unintended side-effects
|
|
386
|
+
and bugs.
|
|
387
|
+
:::
|
|
393
388
|
Example
|
|
394
|
-
```
|
|
389
|
+
```js
|
|
395
390
|
// store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
|
|
396
391
|
postSnapshot.attributes(); // => { author: 'Tomster', title: 'Ember.js rocks' }
|
|
397
392
|
```
|
|
398
|
-
@return
|
|
393
|
+
@return All attributes of the current snapshot
|
|
399
394
|
@public
|
|
400
395
|
*/
|
|
401
396
|
attributes() {
|
|
@@ -407,12 +402,12 @@ class Snapshot {
|
|
|
407
402
|
/**
|
|
408
403
|
Returns all changed attributes and their old and new values.
|
|
409
404
|
Example
|
|
410
|
-
```
|
|
405
|
+
```js
|
|
411
406
|
// store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
|
|
412
407
|
postModel.set('title', 'Ember.js rocks!');
|
|
413
408
|
postSnapshot.changedAttributes(); // => { title: ['Ember.js rocks', 'Ember.js rocks!'] }
|
|
414
409
|
```
|
|
415
|
-
@return
|
|
410
|
+
@return All changed attributes of the current snapshot
|
|
416
411
|
@public
|
|
417
412
|
*/
|
|
418
413
|
changedAttributes() {
|
|
@@ -435,7 +430,7 @@ class Snapshot {
|
|
|
435
430
|
- `id`: set to `true` if you only want the ID of the related record to be
|
|
436
431
|
returned.
|
|
437
432
|
Example
|
|
438
|
-
```
|
|
433
|
+
```js
|
|
439
434
|
// store.push('post', { id: 1, title: 'Hello World' });
|
|
440
435
|
// store.createRecord('comment', { body: 'Lorem ipsum', post: post });
|
|
441
436
|
commentSnapshot.belongsTo('post'); // => Snapshot
|
|
@@ -448,12 +443,10 @@ class Snapshot {
|
|
|
448
443
|
known but unset, `belongsTo` will return `null`. If the contents of the
|
|
449
444
|
relationship is unknown `belongsTo` will return `undefined`.
|
|
450
445
|
Note: Relationships are loaded lazily and cached upon first access.
|
|
451
|
-
@
|
|
452
|
-
@
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
relationship or null if the relationship is known but unset. undefined
|
|
456
|
-
will be returned if the contents of the relationship is unknown.
|
|
446
|
+
@public
|
|
447
|
+
@return A snapshot or ID of a known relationship or null if the
|
|
448
|
+
relationship is known but unset. undefined will be returned if the
|
|
449
|
+
contents of the relationship are unknown.
|
|
457
450
|
*/
|
|
458
451
|
belongsTo(keyName, options) {
|
|
459
452
|
const returnModeIsId = !!(options && options.id);
|
|
@@ -496,7 +489,7 @@ class Snapshot {
|
|
|
496
489
|
}
|
|
497
490
|
const value = this._store.cache.getRelationship(identifier, keyName);
|
|
498
491
|
const data = value && value.data;
|
|
499
|
-
const inverseIdentifier = data ? store.
|
|
492
|
+
const inverseIdentifier = data ? store.cacheKeyManager.getOrCreateRecordIdentifier(data) : null;
|
|
500
493
|
if (value && value.data !== undefined) {
|
|
501
494
|
const cache = store.cache;
|
|
502
495
|
if (inverseIdentifier && !cache.isDeleted(inverseIdentifier)) {
|
|
@@ -532,10 +525,8 @@ class Snapshot {
|
|
|
532
525
|
postSnapshot.hasMany('comments'); // => undefined
|
|
533
526
|
```
|
|
534
527
|
Note: Relationships are loaded lazily and cached upon first access.
|
|
535
|
-
@
|
|
536
|
-
@
|
|
537
|
-
@public
|
|
538
|
-
@return {(Array|undefined)} An array of snapshots or IDs of a known
|
|
528
|
+
@public
|
|
529
|
+
@return An array of snapshots or IDs of a known
|
|
539
530
|
relationship or an empty array if the relationship is known but unset.
|
|
540
531
|
undefined will be returned if the contents of the relationship is unknown.
|
|
541
532
|
*/
|
|
@@ -590,7 +581,7 @@ class Snapshot {
|
|
|
590
581
|
if (value.data) {
|
|
591
582
|
results = [];
|
|
592
583
|
value.data.forEach(member => {
|
|
593
|
-
const inverseIdentifier = store.
|
|
584
|
+
const inverseIdentifier = store.cacheKeyManager.getOrCreateRecordIdentifier(member);
|
|
594
585
|
const cache = store.cache;
|
|
595
586
|
if (!cache.isDeleted(inverseIdentifier)) {
|
|
596
587
|
if (returnModeIsIds) {
|
|
@@ -621,17 +612,24 @@ class Snapshot {
|
|
|
621
612
|
// ...
|
|
622
613
|
});
|
|
623
614
|
```
|
|
624
|
-
@param
|
|
625
|
-
@param
|
|
615
|
+
@param callback the callback to execute
|
|
616
|
+
@param binding the optional value to which the callback's `this` should be bound
|
|
626
617
|
@public
|
|
627
618
|
*/
|
|
628
619
|
eachAttribute(callback, binding) {
|
|
629
|
-
|
|
630
|
-
fields
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
620
|
+
// if the store has a modelFor implementation, we use it to iterate attributes. This allows
|
|
621
|
+
// a custom "ModelSchema" class for legacy serializers to adapt to new fields if desired.
|
|
622
|
+
if (typeof this._store.modelFor === 'function') {
|
|
623
|
+
const modelSchema = this._store.modelFor(this.identifier.type);
|
|
624
|
+
modelSchema.eachAttribute(callback, binding);
|
|
625
|
+
} else {
|
|
626
|
+
const fields = this._store.schema.fields(this.identifier);
|
|
627
|
+
fields.forEach((field, key) => {
|
|
628
|
+
if (field.kind === 'attribute') {
|
|
629
|
+
callback.call(binding, key, field);
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
}
|
|
635
633
|
}
|
|
636
634
|
|
|
637
635
|
/**
|
|
@@ -643,17 +641,24 @@ class Snapshot {
|
|
|
643
641
|
// ...
|
|
644
642
|
});
|
|
645
643
|
```
|
|
646
|
-
@param
|
|
647
|
-
@param
|
|
644
|
+
@param callback the callback to execute
|
|
645
|
+
@param binding the optional value to which the callback's `this` should be bound
|
|
648
646
|
@public
|
|
649
647
|
*/
|
|
650
648
|
eachRelationship(callback, binding) {
|
|
651
|
-
|
|
652
|
-
fields
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
649
|
+
// if the store has a modelFor implementation, we use it to iterate relationships. This allows
|
|
650
|
+
// a custom "ModelSchema" class for legacy serializers to adapt to new fields if desired.
|
|
651
|
+
if (typeof this._store.modelFor === 'function') {
|
|
652
|
+
const modelSchema = this._store.modelFor(this.identifier.type);
|
|
653
|
+
modelSchema.eachRelationship(callback, binding);
|
|
654
|
+
} else {
|
|
655
|
+
const fields = this._store.schema.fields(this.identifier);
|
|
656
|
+
fields.forEach((field, key) => {
|
|
657
|
+
if (field.kind === 'belongsTo' || field.kind === 'hasMany') {
|
|
658
|
+
callback.call(binding, key, field);
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
}
|
|
657
662
|
}
|
|
658
663
|
|
|
659
664
|
/**
|
|
@@ -672,8 +677,7 @@ class Snapshot {
|
|
|
672
677
|
}
|
|
673
678
|
});
|
|
674
679
|
```
|
|
675
|
-
@
|
|
676
|
-
@return {Object} an object whose values are primitive JSON values only
|
|
680
|
+
@return an object whose values are primitive JSON values only
|
|
677
681
|
@public
|
|
678
682
|
*/
|
|
679
683
|
serialize(options) {
|
|
@@ -688,10 +692,25 @@ class Snapshot {
|
|
|
688
692
|
}
|
|
689
693
|
}
|
|
690
694
|
const SaveOp = getOrSetGlobal('SaveOp', Symbol('SaveOp'));
|
|
695
|
+
/**
|
|
696
|
+
* @private
|
|
697
|
+
*/
|
|
691
698
|
class FetchManager {
|
|
699
|
+
/**
|
|
700
|
+
* @internal
|
|
701
|
+
*/
|
|
702
|
+
|
|
703
|
+
/** @internal */
|
|
704
|
+
|
|
692
705
|
// fetches pending in the runloop, waiting to be coalesced
|
|
706
|
+
/**
|
|
707
|
+
* @internal
|
|
708
|
+
*/
|
|
709
|
+
|
|
710
|
+
/** @internal */
|
|
693
711
|
|
|
694
712
|
constructor(store) {
|
|
713
|
+
assertPrivateStore(store);
|
|
695
714
|
this._store = store;
|
|
696
715
|
// used to keep track of all the find requests that need to be coalesced
|
|
697
716
|
this._pendingFetch = new Map();
|
|
@@ -706,7 +725,7 @@ class FetchManager {
|
|
|
706
725
|
This method is called by `record.save`, and gets passed a
|
|
707
726
|
resolver for the promise that `record.save` returns.
|
|
708
727
|
It schedules saving to happen at the end of the run loop.
|
|
709
|
-
@
|
|
728
|
+
@private
|
|
710
729
|
*/
|
|
711
730
|
scheduleSave(identifier, options) {
|
|
712
731
|
const resolver = createDeferred();
|
|
@@ -870,6 +889,15 @@ class FetchManager {
|
|
|
870
889
|
this.isDestroyed = true;
|
|
871
890
|
}
|
|
872
891
|
}
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* This type exists for internal use only for
|
|
895
|
+
* where intimate contracts still exist either for
|
|
896
|
+
* the Test Suite or for Legacy code.
|
|
897
|
+
*
|
|
898
|
+
* @private
|
|
899
|
+
*/
|
|
900
|
+
|
|
873
901
|
function _isEmpty(instanceCache, identifier) {
|
|
874
902
|
const cache = instanceCache.cache;
|
|
875
903
|
if (!cache) {
|
package/dist/adapter/-private.js
CHANGED
|
@@ -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-
|
|
1
|
+
export { d as determineBodyPromise, g as fetch, p as parseResponseHeaders, b as serializeIntoHash, s as serializeQueryParams, a as setupFastboot } from "../serialize-into-hash-CS0MIv4F.js";
|
package/dist/adapter/json-api.js
CHANGED
|
@@ -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-
|
|
4
|
+
import { b as serializeIntoHash } from "../serialize-into-hash-CS0MIv4F.js";
|
|
5
5
|
import { RESTAdapter } from './rest.js';
|
|
6
6
|
class JSONAPIAdapter extends RESTAdapter {
|
|
7
7
|
_defaultContentType = 'application/vnd.api+json';
|
package/dist/adapter/rest.js
CHANGED
|
@@ -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-
|
|
5
|
+
import { b as serializeIntoHash, d as determineBodyPromise, g as getFetchFunction, s as serializeQueryParams, p as parseResponseHeaders } from "../serialize-into-hash-CS0MIv4F.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";
|
package/dist/compat/-private.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { F as FetchManager, S as SaveOp, c as Snapshot, b as SnapshotRecordArray, u as upgradeStore } from "../-private-
|
|
1
|
+
export { F as FetchManager, S as SaveOp, c as Snapshot, b as SnapshotRecordArray, u as upgradeStore } from "../-private-8UmnAf9J.js";
|
package/dist/compat/builders.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SkipCache } from '@warp-drive/core/types/request';
|
|
2
2
|
import { n as normalizeModelName, i as isMaybeIdentifier } from "../utils-Cqw9eRj5.js";
|
|
3
3
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
4
|
-
import { ensureStringId, constructResource } from '@warp-drive/core/store/-private';
|
|
4
|
+
import { ensureStringId, constructResource, assertPrivateStore } from '@warp-drive/core/store/-private';
|
|
5
5
|
import { storeFor, recordIdentifierFor } from '@warp-drive/core';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -227,7 +227,8 @@ 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
|
+
assertPrivateStore(store);
|
|
231
232
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
232
233
|
if (!test) {
|
|
233
234
|
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
|
-
import { waitFor, _deprecatingNormalize } from '@warp-drive/core/store/-private';
|
|
4
|
-
import
|
|
3
|
+
import { assertPrivateStore, waitFor, _deprecatingNormalize } from '@warp-drive/core/store/-private';
|
|
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-8UmnAf9J.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(() => {
|
|
@@ -424,6 +425,7 @@ function saveRecord(context) {
|
|
|
424
425
|
options,
|
|
425
426
|
record: identifier
|
|
426
427
|
} = data;
|
|
428
|
+
assertPrivateStore(store);
|
|
427
429
|
store.cache.willCommit(identifier, context);
|
|
428
430
|
const saveOptions = Object.assign({
|
|
429
431
|
[SaveOp]: operation
|
|
@@ -529,6 +531,7 @@ function findRecord(context) {
|
|
|
529
531
|
record: identifier,
|
|
530
532
|
options
|
|
531
533
|
} = data;
|
|
534
|
+
assertPrivateStore(store);
|
|
532
535
|
let promise;
|
|
533
536
|
|
|
534
537
|
// if not loaded start loading
|
|
@@ -583,6 +586,7 @@ function findAll(context) {
|
|
|
583
586
|
type,
|
|
584
587
|
options
|
|
585
588
|
} = data;
|
|
589
|
+
assertPrivateStore(store);
|
|
586
590
|
const adapter = store.adapterFor(type);
|
|
587
591
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
588
592
|
if (!test) {
|
|
@@ -647,6 +651,7 @@ function query(context) {
|
|
|
647
651
|
store,
|
|
648
652
|
data
|
|
649
653
|
} = context.request;
|
|
654
|
+
assertPrivateStore(store);
|
|
650
655
|
let {
|
|
651
656
|
options
|
|
652
657
|
} = data;
|