@ember-data/model 4.13.0-alpha.4 → 4.13.0-alpha.6
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/LICENSE.md +19 -7
- package/README.md +2 -2
- package/dist/-private.js +3 -2
- package/dist/-private.js.map +1 -1
- package/dist/{has-many-DthR7vrt.js → has-many-BXrgfjkF.js} +1 -1
- package/dist/{has-many-DthR7vrt.js.map → has-many-BXrgfjkF.js.map} +1 -1
- package/dist/{hooks-DUvkuuiF.js → hooks-B9jnkwUK.js} +2 -2
- package/dist/{hooks-DUvkuuiF.js.map → hooks-B9jnkwUK.js.map} +1 -1
- package/dist/hooks.js +2 -2
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/{legacy-relationships-support-BcuRwRWg.js → legacy-relationships-support-hCIAg9d-.js} +39 -514
- package/dist/legacy-relationships-support-hCIAg9d-.js.map +1 -0
- package/dist/migration-support.js +2 -2
- package/dist/migration-support.js.map +1 -1
- package/dist/{schema-provider-DIrad3-Y.js → schema-provider-BB1z1Wrn.js} +1 -1
- package/dist/schema-provider-BB1z1Wrn.js.map +1 -0
- package/logos/NCC-1701-a-gold.svg +4 -0
- package/logos/NCC-1701-a-gold_100.svg +1 -0
- package/logos/NCC-1701-a-gold_base-64.txt +1 -0
- package/logos/README.md +4 -0
- package/logos/docs-badge.svg +2 -0
- package/logos/github-header.svg +444 -0
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +4 -0
- package/logos/warp-drive-logo-gold.svg +4 -0
- package/package.json +31 -62
- package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts.map +1 -1
- package/unstable-preview-types/-private/legacy-relationships-support.d.ts +1 -1
- package/unstable-preview-types/-private/legacy-relationships-support.d.ts.map +1 -1
- package/unstable-preview-types/-private/model.d.ts +21 -23
- package/unstable-preview-types/-private/model.d.ts.map +1 -1
- package/unstable-preview-types/-private/promise-many-array.d.ts +1 -2
- package/unstable-preview-types/-private/promise-many-array.d.ts.map +1 -1
- package/unstable-preview-types/-private/promise-proxy-base.d.ts +5 -0
- package/unstable-preview-types/-private/promise-proxy-base.d.ts.map +1 -0
- package/unstable-preview-types/-private/references/has-many.d.ts +1 -1
- package/unstable-preview-types/-private/references/has-many.d.ts.map +1 -1
- package/unstable-preview-types/-private/relationship-meta.d.ts +18 -4
- package/unstable-preview-types/-private/relationship-meta.d.ts.map +1 -1
- package/unstable-preview-types/-private/schema-provider.d.ts +7 -7
- package/unstable-preview-types/-private/schema-provider.d.ts.map +1 -1
- package/unstable-preview-types/-private/type-utils.d.ts +1 -1
- package/unstable-preview-types/-private/type-utils.d.ts.map +1 -1
- package/unstable-preview-types/-private.d.ts +1 -1
- package/unstable-preview-types/-private.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +21 -21
- package/unstable-preview-types/index.d.ts.map +1 -1
- package/unstable-preview-types/migration-support.d.ts +4 -4
- package/unstable-preview-types/migration-support.d.ts.map +1 -1
- package/dist/legacy-relationships-support-BcuRwRWg.js.map +0 -1
- package/dist/schema-provider-DIrad3-Y.js.map +0 -1
- package/unstable-preview-types/-private/many-array.d.ts +0 -196
- package/unstable-preview-types/-private/many-array.d.ts.map +0 -1
- /package/{ember-data-logo-dark.svg → logos/ember-data-logo-dark.svg} +0 -0
- /package/{ember-data-logo-light.svg → logos/ember-data-logo-light.svg} +0 -0
package/dist/{legacy-relationships-support-BcuRwRWg.js → legacy-relationships-support-hCIAg9d-.js}
RENAMED
|
@@ -2,17 +2,17 @@ import { deprecate, warn } from '@ember/debug';
|
|
|
2
2
|
import { dasherize, singularize } from '@ember-data/request-utils/string';
|
|
3
3
|
import { macroCondition, getGlobalConfig, importSync, dependencySatisfies } from '@embroider/macros';
|
|
4
4
|
import { upgradeStore } from '@ember-data/legacy-compat/-private';
|
|
5
|
-
import {
|
|
5
|
+
import { peekCache, recordIdentifierFor as recordIdentifierFor$1, coerceId, storeFor as storeFor$1, SOURCE, fastPush, isStableIdentifier, RelatedCollection } from '@ember-data/store/-private';
|
|
6
6
|
import { getOrSetGlobal } from '@warp-drive/core-types/-private';
|
|
7
7
|
import { EnableHydration } from '@warp-drive/core-types/request';
|
|
8
|
-
import { addToTransaction, defineSignal, peekSignal, getSignal, subscribe } from '@ember-data/tracking/-private';
|
|
9
8
|
import EmberObject, { computed, get } from '@ember/object';
|
|
10
9
|
import { cached, compat } from '@ember-data/tracking';
|
|
11
10
|
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
|
|
12
11
|
import ObjectProxy from '@ember/object/proxy';
|
|
13
12
|
import ArrayMixin, { NativeArray, A } from '@ember/array';
|
|
14
13
|
import Ember from 'ember';
|
|
15
|
-
import {
|
|
14
|
+
import { defineSignal, peekSignal, addToTransaction, getSignal, subscribe } from '@ember-data/tracking/-private';
|
|
15
|
+
import { recordIdentifierFor, storeFor } from '@ember-data/store';
|
|
16
16
|
import { RecordStore } from '@warp-drive/core-types/symbols';
|
|
17
17
|
import ArrayProxy from '@ember/array/proxy';
|
|
18
18
|
import { mapBy, not } from '@ember/object/computed';
|
|
@@ -48,491 +48,6 @@ function normalizeModelName(type) {
|
|
|
48
48
|
}
|
|
49
49
|
return type;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
@module @ember-data/store
|
|
54
|
-
*/
|
|
55
|
-
/**
|
|
56
|
-
A `ManyArray` is a `MutableArray` that represents the contents of a has-many
|
|
57
|
-
relationship.
|
|
58
|
-
|
|
59
|
-
The `ManyArray` is instantiated lazily the first time the relationship is
|
|
60
|
-
requested.
|
|
61
|
-
|
|
62
|
-
This class is not intended to be directly instantiated by consuming applications.
|
|
63
|
-
|
|
64
|
-
### Inverses
|
|
65
|
-
|
|
66
|
-
Often, the relationships in Ember Data applications will have
|
|
67
|
-
an inverse. For example, imagine the following models are
|
|
68
|
-
defined:
|
|
69
|
-
|
|
70
|
-
```app/models/post.js
|
|
71
|
-
import Model, { hasMany } from '@ember-data/model';
|
|
72
|
-
|
|
73
|
-
export default class PostModel extends Model {
|
|
74
|
-
@hasMany('comment') comments;
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
```app/models/comment.js
|
|
79
|
-
import Model, { belongsTo } from '@ember-data/model';
|
|
80
|
-
|
|
81
|
-
export default class CommentModel extends Model {
|
|
82
|
-
@belongsTo('post') post;
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
If you created a new instance of `Post` and added
|
|
87
|
-
a `Comment` record to its `comments` has-many
|
|
88
|
-
relationship, you would expect the comment's `post`
|
|
89
|
-
property to be set to the post that contained
|
|
90
|
-
the has-many.
|
|
91
|
-
|
|
92
|
-
We call the record to which a relationship belongs-to the
|
|
93
|
-
relationship's _owner_.
|
|
94
|
-
|
|
95
|
-
@class ManyArray
|
|
96
|
-
@public
|
|
97
|
-
*/
|
|
98
|
-
class RelatedCollection extends LiveArray {
|
|
99
|
-
/**
|
|
100
|
-
The loading state of this array
|
|
101
|
-
@property {Boolean} isLoaded
|
|
102
|
-
@public
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
`true` if the relationship is polymorphic, `false` otherwise.
|
|
107
|
-
@property {Boolean} isPolymorphic
|
|
108
|
-
@private
|
|
109
|
-
*/
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
Metadata associated with the request for async hasMany relationships.
|
|
113
|
-
Example
|
|
114
|
-
Given that the server returns the following JSON payload when fetching a
|
|
115
|
-
hasMany relationship:
|
|
116
|
-
```js
|
|
117
|
-
{
|
|
118
|
-
"comments": [{
|
|
119
|
-
"id": 1,
|
|
120
|
-
"comment": "This is the first comment",
|
|
121
|
-
}, {
|
|
122
|
-
// ...
|
|
123
|
-
}],
|
|
124
|
-
"meta": {
|
|
125
|
-
"page": 1,
|
|
126
|
-
"total": 5
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
You can then access the meta data via the `meta` property:
|
|
131
|
-
```js
|
|
132
|
-
let comments = await post.comments;
|
|
133
|
-
let meta = comments.meta;
|
|
134
|
-
// meta.page => 1
|
|
135
|
-
// meta.total => 5
|
|
136
|
-
```
|
|
137
|
-
@property {Object | null} meta
|
|
138
|
-
@public
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Retrieve the links for this relationship
|
|
143
|
-
*
|
|
144
|
-
@property {Object | null} links
|
|
145
|
-
@public
|
|
146
|
-
*/
|
|
147
|
-
|
|
148
|
-
constructor(options) {
|
|
149
|
-
super(options);
|
|
150
|
-
this.isLoaded = options.isLoaded || false;
|
|
151
|
-
this.isAsync = options.isAsync || false;
|
|
152
|
-
this.isPolymorphic = options.isPolymorphic || false;
|
|
153
|
-
this.identifier = options.identifier;
|
|
154
|
-
this.key = options.key;
|
|
155
|
-
}
|
|
156
|
-
[MUTATE](target, receiver, prop, args, _SIGNAL) {
|
|
157
|
-
switch (prop) {
|
|
158
|
-
case 'length 0':
|
|
159
|
-
{
|
|
160
|
-
Reflect.set(target, 'length', 0);
|
|
161
|
-
mutateReplaceRelatedRecords(this, [], _SIGNAL);
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
case 'replace cell':
|
|
165
|
-
{
|
|
166
|
-
const [index, prior, value] = args;
|
|
167
|
-
target[index] = value;
|
|
168
|
-
mutateReplaceRelatedRecord(this, {
|
|
169
|
-
value,
|
|
170
|
-
prior,
|
|
171
|
-
index
|
|
172
|
-
}, _SIGNAL);
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
case 'push':
|
|
176
|
-
{
|
|
177
|
-
const newValues = extractIdentifiersFromRecords(args);
|
|
178
|
-
assertNoDuplicates(this, target, currentState => currentState.push(...newValues), `Cannot push duplicates to a hasMany's state.`);
|
|
179
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
180
|
-
// dedupe
|
|
181
|
-
const seen = new Set(target);
|
|
182
|
-
const unique = new Set();
|
|
183
|
-
args.forEach(item => {
|
|
184
|
-
const identifier = recordIdentifierFor(item);
|
|
185
|
-
if (!seen.has(identifier)) {
|
|
186
|
-
seen.add(identifier);
|
|
187
|
-
unique.add(item);
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
const newArgs = Array.from(unique);
|
|
191
|
-
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
192
|
-
if (newArgs.length) {
|
|
193
|
-
mutateAddToRelatedRecords(this, {
|
|
194
|
-
value: extractIdentifiersFromRecords(newArgs)
|
|
195
|
-
}, _SIGNAL);
|
|
196
|
-
}
|
|
197
|
-
return result;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// else, no dedupe, error on duplicates
|
|
201
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
202
|
-
if (newValues.length) {
|
|
203
|
-
mutateAddToRelatedRecords(this, {
|
|
204
|
-
value: newValues
|
|
205
|
-
}, _SIGNAL);
|
|
206
|
-
}
|
|
207
|
-
return result;
|
|
208
|
-
}
|
|
209
|
-
case 'pop':
|
|
210
|
-
{
|
|
211
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
212
|
-
if (result) {
|
|
213
|
-
mutateRemoveFromRelatedRecords(this, {
|
|
214
|
-
value: recordIdentifierFor(result)
|
|
215
|
-
}, _SIGNAL);
|
|
216
|
-
}
|
|
217
|
-
return result;
|
|
218
|
-
}
|
|
219
|
-
case 'unshift':
|
|
220
|
-
{
|
|
221
|
-
const newValues = extractIdentifiersFromRecords(args);
|
|
222
|
-
assertNoDuplicates(this, target, currentState => currentState.unshift(...newValues), `Cannot unshift duplicates to a hasMany's state.`);
|
|
223
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
224
|
-
// dedupe
|
|
225
|
-
const seen = new Set(target);
|
|
226
|
-
const unique = new Set();
|
|
227
|
-
args.forEach(item => {
|
|
228
|
-
const identifier = recordIdentifierFor(item);
|
|
229
|
-
if (!seen.has(identifier)) {
|
|
230
|
-
seen.add(identifier);
|
|
231
|
-
unique.add(item);
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
const newArgs = Array.from(unique);
|
|
235
|
-
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
236
|
-
if (newArgs.length) {
|
|
237
|
-
mutateAddToRelatedRecords(this, {
|
|
238
|
-
value: extractIdentifiersFromRecords(newArgs),
|
|
239
|
-
index: 0
|
|
240
|
-
}, _SIGNAL);
|
|
241
|
-
}
|
|
242
|
-
return result;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// else, no dedupe, error on duplicates
|
|
246
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
247
|
-
if (newValues.length) {
|
|
248
|
-
mutateAddToRelatedRecords(this, {
|
|
249
|
-
value: newValues,
|
|
250
|
-
index: 0
|
|
251
|
-
}, _SIGNAL);
|
|
252
|
-
}
|
|
253
|
-
return result;
|
|
254
|
-
}
|
|
255
|
-
case 'shift':
|
|
256
|
-
{
|
|
257
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
258
|
-
if (result) {
|
|
259
|
-
mutateRemoveFromRelatedRecords(this, {
|
|
260
|
-
value: recordIdentifierFor(result),
|
|
261
|
-
index: 0
|
|
262
|
-
}, _SIGNAL);
|
|
263
|
-
}
|
|
264
|
-
return result;
|
|
265
|
-
}
|
|
266
|
-
case 'sort':
|
|
267
|
-
{
|
|
268
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
269
|
-
mutateSortRelatedRecords(this, result.map(recordIdentifierFor), _SIGNAL);
|
|
270
|
-
return result;
|
|
271
|
-
}
|
|
272
|
-
case 'splice':
|
|
273
|
-
{
|
|
274
|
-
const [start, deleteCount, ...adds] = args;
|
|
275
|
-
|
|
276
|
-
// detect a full replace
|
|
277
|
-
if (start === 0 && deleteCount === this[SOURCE].length) {
|
|
278
|
-
const newValues = extractIdentifiersFromRecords(adds);
|
|
279
|
-
assertNoDuplicates(this, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot replace a hasMany's state with a new state that contains duplicates.`);
|
|
280
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
281
|
-
// dedupe
|
|
282
|
-
const current = new Set(adds);
|
|
283
|
-
const unique = Array.from(current);
|
|
284
|
-
const uniqueIdentifiers = Array.from(new Set(newValues));
|
|
285
|
-
const newArgs = [start, deleteCount].concat(unique);
|
|
286
|
-
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
287
|
-
mutateReplaceRelatedRecords(this, uniqueIdentifiers, _SIGNAL);
|
|
288
|
-
return result;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// else, no dedupe, error on duplicates
|
|
292
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
293
|
-
mutateReplaceRelatedRecords(this, newValues, _SIGNAL);
|
|
294
|
-
return result;
|
|
295
|
-
}
|
|
296
|
-
const newValues = extractIdentifiersFromRecords(adds);
|
|
297
|
-
assertNoDuplicates(this, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot splice a hasMany's state with a new state that contains duplicates.`);
|
|
298
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
299
|
-
// dedupe
|
|
300
|
-
const currentState = target.slice();
|
|
301
|
-
currentState.splice(start, deleteCount);
|
|
302
|
-
const seen = new Set(currentState);
|
|
303
|
-
const unique = [];
|
|
304
|
-
adds.forEach(item => {
|
|
305
|
-
const identifier = recordIdentifierFor(item);
|
|
306
|
-
if (!seen.has(identifier)) {
|
|
307
|
-
seen.add(identifier);
|
|
308
|
-
unique.push(item);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
const newArgs = [start, deleteCount, ...unique];
|
|
312
|
-
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
313
|
-
if (deleteCount > 0) {
|
|
314
|
-
mutateRemoveFromRelatedRecords(this, {
|
|
315
|
-
value: result.map(recordIdentifierFor),
|
|
316
|
-
index: start
|
|
317
|
-
}, _SIGNAL);
|
|
318
|
-
}
|
|
319
|
-
if (unique.length > 0) {
|
|
320
|
-
mutateAddToRelatedRecords(this, {
|
|
321
|
-
value: extractIdentifiersFromRecords(unique),
|
|
322
|
-
index: start
|
|
323
|
-
}, _SIGNAL);
|
|
324
|
-
}
|
|
325
|
-
return result;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// else, no dedupe, error on duplicates
|
|
329
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
330
|
-
if (deleteCount > 0) {
|
|
331
|
-
mutateRemoveFromRelatedRecords(this, {
|
|
332
|
-
value: result.map(recordIdentifierFor),
|
|
333
|
-
index: start
|
|
334
|
-
}, _SIGNAL);
|
|
335
|
-
}
|
|
336
|
-
if (newValues.length > 0) {
|
|
337
|
-
mutateAddToRelatedRecords(this, {
|
|
338
|
-
value: newValues,
|
|
339
|
-
index: start
|
|
340
|
-
}, _SIGNAL);
|
|
341
|
-
}
|
|
342
|
-
return result;
|
|
343
|
-
}
|
|
344
|
-
default:
|
|
345
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
346
|
-
{
|
|
347
|
-
throw new Error(`unable to convert ${prop} into a transaction that updates the cache state for this record array`);
|
|
348
|
-
}
|
|
349
|
-
})() : {};
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
notify() {
|
|
353
|
-
const signal = this[ARRAY_SIGNAL];
|
|
354
|
-
signal.shouldReset = true;
|
|
355
|
-
notifyArray(this);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
Reloads all of the records in the manyArray. If the manyArray
|
|
360
|
-
holds a relationship that was originally fetched using a links url
|
|
361
|
-
EmberData will revisit the original links url to repopulate the
|
|
362
|
-
relationship.
|
|
363
|
-
If the ManyArray holds the result of a `store.query()` reload will
|
|
364
|
-
re-run the original query.
|
|
365
|
-
Example
|
|
366
|
-
```javascript
|
|
367
|
-
let user = store.peekRecord('user', '1')
|
|
368
|
-
await login(user);
|
|
369
|
-
let permissions = await user.permissions;
|
|
370
|
-
await permissions.reload();
|
|
371
|
-
```
|
|
372
|
-
@method reload
|
|
373
|
-
@public
|
|
374
|
-
*/
|
|
375
|
-
reload(options) {
|
|
376
|
-
// TODO this is odd, we don't ask the store for anything else like this?
|
|
377
|
-
return this._manager.reloadHasMany(this.key, options);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
Saves all of the records in the `ManyArray`.
|
|
382
|
-
Example
|
|
383
|
-
```javascript
|
|
384
|
-
let inbox = await store.findRecord('inbox', '1');
|
|
385
|
-
let messages = await inbox.messages;
|
|
386
|
-
messages.forEach((message) => {
|
|
387
|
-
message.isRead = true;
|
|
388
|
-
});
|
|
389
|
-
messages.save();
|
|
390
|
-
```
|
|
391
|
-
@method save
|
|
392
|
-
@public
|
|
393
|
-
@return {PromiseArray} promise
|
|
394
|
-
*/
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
Create a child record within the owner
|
|
398
|
-
@method createRecord
|
|
399
|
-
@public
|
|
400
|
-
@param {Object} hash
|
|
401
|
-
@return {Model} record
|
|
402
|
-
*/
|
|
403
|
-
createRecord(hash) {
|
|
404
|
-
const {
|
|
405
|
-
store
|
|
406
|
-
} = this;
|
|
407
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
408
|
-
if (!test) {
|
|
409
|
-
throw new Error(`Expected modelName to be set`);
|
|
410
|
-
}
|
|
411
|
-
})(this.modelName) : {};
|
|
412
|
-
const record = store.createRecord(this.modelName, hash);
|
|
413
|
-
this.push(record);
|
|
414
|
-
return record;
|
|
415
|
-
}
|
|
416
|
-
destroy() {
|
|
417
|
-
super.destroy(false);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
RelatedCollection.prototype.isAsync = false;
|
|
421
|
-
RelatedCollection.prototype.isPolymorphic = false;
|
|
422
|
-
RelatedCollection.prototype.identifier = null;
|
|
423
|
-
RelatedCollection.prototype.cache = null;
|
|
424
|
-
RelatedCollection.prototype._inverseIsAsync = false;
|
|
425
|
-
RelatedCollection.prototype.key = '';
|
|
426
|
-
RelatedCollection.prototype.DEPRECATED_CLASS_NAME = 'ManyArray';
|
|
427
|
-
function assertRecordPassedToHasMany(record) {
|
|
428
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
429
|
-
if (!test) {
|
|
430
|
-
throw new Error(`All elements of a hasMany relationship must be instances of Model, you passed ${typeof record}`);
|
|
431
|
-
}
|
|
432
|
-
})(function () {
|
|
433
|
-
try {
|
|
434
|
-
recordIdentifierFor(record);
|
|
435
|
-
return true;
|
|
436
|
-
} catch {
|
|
437
|
-
return false;
|
|
438
|
-
}
|
|
439
|
-
}()) : {};
|
|
440
|
-
}
|
|
441
|
-
function extractIdentifiersFromRecords(records) {
|
|
442
|
-
return records.map(extractIdentifierFromRecord$1);
|
|
443
|
-
}
|
|
444
|
-
function extractIdentifierFromRecord$1(recordOrPromiseRecord) {
|
|
445
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_PROMISE_PROXIES)) {
|
|
446
|
-
if (isPromiseRecord$1(recordOrPromiseRecord)) {
|
|
447
|
-
const content = recordOrPromiseRecord.content;
|
|
448
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
449
|
-
if (!test) {
|
|
450
|
-
throw new Error('You passed in a promise that did not originate from an EmberData relationship. You can only pass promises that come from a belongsTo relationship.');
|
|
451
|
-
}
|
|
452
|
-
})(content !== undefined && content !== null) : {};
|
|
453
|
-
deprecate(`You passed in a PromiseProxy to a Relationship API that now expects a resolved value. await the value before setting it.`, false, {
|
|
454
|
-
id: 'ember-data:deprecate-promise-proxies',
|
|
455
|
-
until: '5.0',
|
|
456
|
-
since: {
|
|
457
|
-
enabled: '4.7',
|
|
458
|
-
available: '4.7'
|
|
459
|
-
},
|
|
460
|
-
for: 'ember-data'
|
|
461
|
-
});
|
|
462
|
-
assertRecordPassedToHasMany(content);
|
|
463
|
-
return recordIdentifierFor(content);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
assertRecordPassedToHasMany(recordOrPromiseRecord);
|
|
467
|
-
return recordIdentifierFor(recordOrPromiseRecord);
|
|
468
|
-
}
|
|
469
|
-
function isPromiseRecord$1(record) {
|
|
470
|
-
return Boolean(typeof record === 'object' && record && 'then' in record);
|
|
471
|
-
}
|
|
472
|
-
function assertNoDuplicates(collection, target, callback, reason) {
|
|
473
|
-
const state = target.slice();
|
|
474
|
-
callback(state);
|
|
475
|
-
if (state.length !== new Set(state).size) {
|
|
476
|
-
const duplicates = state.filter((currentValue, currentIndex) => state.indexOf(currentValue) !== currentIndex);
|
|
477
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
478
|
-
deprecate(`${reason} This behavior is deprecated. Found duplicates for the following records within the new state provided to \`<${collection.identifier.type}:${collection.identifier.id || collection.identifier.lid}>.${collection.key}\`\n\t- ${Array.from(new Set(duplicates)).map(r => isStableIdentifier(r) ? r.lid : recordIdentifierFor(r).lid).sort((a, b) => a.localeCompare(b)).join('\n\t- ')}`, /* inline-macro-config */getGlobalConfig().WarpDrive.deprecations.DISABLE_6X_DEPRECATIONS, {
|
|
479
|
-
id: 'ember-data:deprecate-many-array-duplicates',
|
|
480
|
-
for: 'ember-data',
|
|
481
|
-
until: '6.0',
|
|
482
|
-
since: {
|
|
483
|
-
enabled: '5.3',
|
|
484
|
-
available: '4.13'
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
} else {
|
|
488
|
-
throw new Error(`${reason} Found duplicates for the following records within the new state provided to \`<${collection.identifier.type}:${collection.identifier.id || collection.identifier.lid}>.${collection.key}\`\n\t- ${Array.from(new Set(duplicates)).map(r => isStableIdentifier(r) ? r.lid : recordIdentifierFor(r).lid).sort((a, b) => a.localeCompare(b)).join('\n\t- ')}`);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
function mutateAddToRelatedRecords(collection, operationInfo, _SIGNAL) {
|
|
493
|
-
mutate(collection, {
|
|
494
|
-
op: 'addToRelatedRecords',
|
|
495
|
-
record: collection.identifier,
|
|
496
|
-
field: collection.key,
|
|
497
|
-
...operationInfo
|
|
498
|
-
}, _SIGNAL);
|
|
499
|
-
}
|
|
500
|
-
function mutateRemoveFromRelatedRecords(collection, operationInfo, _SIGNAL) {
|
|
501
|
-
mutate(collection, {
|
|
502
|
-
op: 'removeFromRelatedRecords',
|
|
503
|
-
record: collection.identifier,
|
|
504
|
-
field: collection.key,
|
|
505
|
-
...operationInfo
|
|
506
|
-
}, _SIGNAL);
|
|
507
|
-
}
|
|
508
|
-
function mutateReplaceRelatedRecord(collection, operationInfo, _SIGNAL) {
|
|
509
|
-
mutate(collection, {
|
|
510
|
-
op: 'replaceRelatedRecord',
|
|
511
|
-
record: collection.identifier,
|
|
512
|
-
field: collection.key,
|
|
513
|
-
...operationInfo
|
|
514
|
-
}, _SIGNAL);
|
|
515
|
-
}
|
|
516
|
-
function mutateReplaceRelatedRecords(collection, value, _SIGNAL) {
|
|
517
|
-
mutate(collection, {
|
|
518
|
-
op: 'replaceRelatedRecords',
|
|
519
|
-
record: collection.identifier,
|
|
520
|
-
field: collection.key,
|
|
521
|
-
value
|
|
522
|
-
}, _SIGNAL);
|
|
523
|
-
}
|
|
524
|
-
function mutateSortRelatedRecords(collection, value, _SIGNAL) {
|
|
525
|
-
mutate(collection, {
|
|
526
|
-
op: 'sortRelatedRecords',
|
|
527
|
-
record: collection.identifier,
|
|
528
|
-
field: collection.key,
|
|
529
|
-
value
|
|
530
|
-
}, _SIGNAL);
|
|
531
|
-
}
|
|
532
|
-
function mutate(collection, mutation, _SIGNAL) {
|
|
533
|
-
collection._manager.mutate(mutation);
|
|
534
|
-
addToTransaction(_SIGNAL);
|
|
535
|
-
}
|
|
536
51
|
const PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
|
|
537
52
|
const deferred = /* @__PURE__ */new WeakMap();
|
|
538
53
|
function deferDecorator(proto, prop, desc) {
|
|
@@ -1434,7 +949,7 @@ function rollbackAttributes() {
|
|
|
1434
949
|
isNew
|
|
1435
950
|
} = currentState;
|
|
1436
951
|
this[RecordStore]._join(() => {
|
|
1437
|
-
peekCache(this).rollbackAttrs(recordIdentifierFor
|
|
952
|
+
peekCache(this).rollbackAttrs(recordIdentifierFor(this));
|
|
1438
953
|
this.errors.clear();
|
|
1439
954
|
currentState.cleanErrorRequests();
|
|
1440
955
|
if (isNew) {
|
|
@@ -1457,7 +972,7 @@ function hasMany(prop) {
|
|
|
1457
972
|
function reload(options = {}) {
|
|
1458
973
|
options.isReloading = true;
|
|
1459
974
|
options.reload = true;
|
|
1460
|
-
const identifier = recordIdentifierFor
|
|
975
|
+
const identifier = recordIdentifierFor(this);
|
|
1461
976
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1462
977
|
if (!test) {
|
|
1463
978
|
throw new Error(`You cannot reload a record without an ID`);
|
|
@@ -1482,7 +997,7 @@ function reload(options = {}) {
|
|
|
1482
997
|
return promise;
|
|
1483
998
|
}
|
|
1484
999
|
function changedAttributes() {
|
|
1485
|
-
return peekCache(this).changedAttrs(recordIdentifierFor
|
|
1000
|
+
return peekCache(this).changedAttrs(recordIdentifierFor(this));
|
|
1486
1001
|
}
|
|
1487
1002
|
function serialize(options) {
|
|
1488
1003
|
upgradeStore(this[RecordStore]);
|
|
@@ -1531,7 +1046,7 @@ function createSnapshot() {
|
|
|
1531
1046
|
}
|
|
1532
1047
|
|
|
1533
1048
|
// @ts-expect-error Typescript isn't able to curry narrowed args that are divorced from each other.
|
|
1534
|
-
return store._fetchManager.createSnapshot(recordIdentifierFor
|
|
1049
|
+
return store._fetchManager.createSnapshot(recordIdentifierFor(this));
|
|
1535
1050
|
}
|
|
1536
1051
|
function notifyChanges(identifier, value, key, record, store) {
|
|
1537
1052
|
switch (value) {
|
|
@@ -1693,7 +1208,7 @@ root
|
|
|
1693
1208
|
class RecordState {
|
|
1694
1209
|
constructor(record) {
|
|
1695
1210
|
const store = storeFor(record);
|
|
1696
|
-
const identity = recordIdentifierFor(record);
|
|
1211
|
+
const identity = recordIdentifierFor$1(record);
|
|
1697
1212
|
this.identifier = identity;
|
|
1698
1213
|
this.record = record;
|
|
1699
1214
|
this.cache = store.cache;
|
|
@@ -2161,7 +1676,7 @@ class Model extends EmberObject {
|
|
|
2161
1676
|
|
|
2162
1677
|
// @ts-expect-error destroy should not return a value, but ember's types force it to
|
|
2163
1678
|
destroy() {
|
|
2164
|
-
const identifier = recordIdentifierFor
|
|
1679
|
+
const identifier = recordIdentifierFor(this);
|
|
2165
1680
|
this.___recordState?.destroy();
|
|
2166
1681
|
const store = storeFor(this);
|
|
2167
1682
|
store.notifications.unsubscribe(this.___private_notifications);
|
|
@@ -2226,9 +1741,8 @@ class Model extends EmberObject {
|
|
|
2226
1741
|
```javascript
|
|
2227
1742
|
let record = store.createRecord('model');
|
|
2228
1743
|
record.isLoaded; // true
|
|
2229
|
-
store.findRecord('model', 1)
|
|
2230
|
-
|
|
2231
|
-
});
|
|
1744
|
+
const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
|
|
1745
|
+
model.isLoaded;
|
|
2232
1746
|
```
|
|
2233
1747
|
@property isLoaded
|
|
2234
1748
|
@public
|
|
@@ -2251,11 +1765,10 @@ class Model extends EmberObject {
|
|
|
2251
1765
|
```javascript
|
|
2252
1766
|
let record = store.createRecord('model');
|
|
2253
1767
|
record.hasDirtyAttributes; // true
|
|
2254
|
-
store.findRecord('model', 1)
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
});
|
|
1768
|
+
const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
|
|
1769
|
+
model.hasDirtyAttributes; // false
|
|
1770
|
+
model.foo = 'some value';
|
|
1771
|
+
model.hasDirtyAttributes; // true
|
|
2259
1772
|
```
|
|
2260
1773
|
@since 1.13.0
|
|
2261
1774
|
@property hasDirtyAttributes
|
|
@@ -2456,9 +1969,8 @@ class Model extends EmberObject {
|
|
|
2456
1969
|
```javascript
|
|
2457
1970
|
let record = store.createRecord('model');
|
|
2458
1971
|
record.id; // null
|
|
2459
|
-
store.findRecord('model', 1)
|
|
2460
|
-
|
|
2461
|
-
});
|
|
1972
|
+
const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
|
|
1973
|
+
model.id; // '1'
|
|
2462
1974
|
```
|
|
2463
1975
|
@property id
|
|
2464
1976
|
@public
|
|
@@ -2470,19 +1982,19 @@ class Model extends EmberObject {
|
|
|
2470
1982
|
// object is real.
|
|
2471
1983
|
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
2472
1984
|
try {
|
|
2473
|
-
return recordIdentifierFor
|
|
1985
|
+
return recordIdentifierFor(this).id;
|
|
2474
1986
|
} catch {
|
|
2475
1987
|
return null;
|
|
2476
1988
|
}
|
|
2477
1989
|
}
|
|
2478
|
-
return recordIdentifierFor
|
|
1990
|
+
return recordIdentifierFor(this).id;
|
|
2479
1991
|
}
|
|
2480
1992
|
static {
|
|
2481
1993
|
decorateMethodV2(this.prototype, "id", [tagged]);
|
|
2482
1994
|
}
|
|
2483
1995
|
set id(id) {
|
|
2484
1996
|
const normalizedId = coerceId(id);
|
|
2485
|
-
const identifier = recordIdentifierFor
|
|
1997
|
+
const identifier = recordIdentifierFor(this);
|
|
2486
1998
|
const didChange = normalizedId !== identifier.id;
|
|
2487
1999
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2488
2000
|
if (!test) {
|
|
@@ -3704,7 +3216,7 @@ class Model extends EmberObject {
|
|
|
3704
3216
|
if (isAttributeSchema(meta)) {
|
|
3705
3217
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
3706
3218
|
if (!test) {
|
|
3707
|
-
throw new Error("You may not set
|
|
3219
|
+
throw new Error("You may not set 'id' as an attribute on your model. Please remove any lines that look like: `id: attr('<type>')` from " + this.toString());
|
|
3708
3220
|
}
|
|
3709
3221
|
})(name !== 'id') : {};
|
|
3710
3222
|
|
|
@@ -4291,6 +3803,18 @@ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
|
4291
3803
|
})(isPolymorphic) : {};
|
|
4292
3804
|
}
|
|
4293
3805
|
}
|
|
3806
|
+
if (meta) {
|
|
3807
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
3808
|
+
if (!test) {
|
|
3809
|
+
throw new Error(`Expected the schema for the field ${parentDefinition.inverseKey} on ${addedIdentifier.type} to be for a legacy relationship`);
|
|
3810
|
+
}
|
|
3811
|
+
})(meta.kind === 'belongsTo' || meta.kind === 'hasMany') : {};
|
|
3812
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
3813
|
+
if (!test) {
|
|
3814
|
+
throw new Error(`The schema for the relationship '${parentDefinition.inverseKey}' on '${addedIdentifier.type}' type does not implement '${parentDefinition.type}' and thus cannot be assigned to the '${parentDefinition.key}' relationship in '${parentIdentifier.type}'. The definition should specify 'as: "${parentDefinition.type}"' in options.`);
|
|
3815
|
+
}
|
|
3816
|
+
})(meta?.options?.as === parentDefinition.type) : {};
|
|
3817
|
+
}
|
|
4294
3818
|
}
|
|
4295
3819
|
};
|
|
4296
3820
|
}
|
|
@@ -5500,7 +5024,7 @@ class BelongsToReference {
|
|
|
5500
5024
|
defineSignal(BelongsToReference.prototype, '_ref', 0);
|
|
5501
5025
|
const LEGACY_SUPPORT = getOrSetGlobal('LEGACY_SUPPORT', new Map());
|
|
5502
5026
|
function lookupLegacySupport(record) {
|
|
5503
|
-
const identifier = recordIdentifierFor(record);
|
|
5027
|
+
const identifier = recordIdentifierFor$1(record);
|
|
5504
5028
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
5505
5029
|
if (!test) {
|
|
5506
5030
|
throw new Error(`Expected a record`);
|
|
@@ -5523,7 +5047,7 @@ class LegacySupport {
|
|
|
5523
5047
|
constructor(record) {
|
|
5524
5048
|
this.record = record;
|
|
5525
5049
|
this.store = storeFor$1(record);
|
|
5526
|
-
this.identifier = recordIdentifierFor(record);
|
|
5050
|
+
this.identifier = recordIdentifierFor$1(record);
|
|
5527
5051
|
this.cache = peekCache(record);
|
|
5528
5052
|
if (macroCondition(dependencySatisfies('@ember-data/graph', '*'))) {
|
|
5529
5053
|
const graphFor = importSync('@ember-data/graph/-private').graphFor;
|
|
@@ -5682,6 +5206,7 @@ class LegacySupport {
|
|
|
5682
5206
|
isPolymorphic: definition.isPolymorphic,
|
|
5683
5207
|
isAsync: definition.isAsync,
|
|
5684
5208
|
_inverseIsAsync: definition.inverseIsAsync,
|
|
5209
|
+
// @ts-expect-error Typescript doesn't have a way for us to thread the generic backwards so it infers unknown instead of T
|
|
5685
5210
|
manager: this,
|
|
5686
5211
|
isLoaded: !definition.isAsync,
|
|
5687
5212
|
allowMutation: true
|
|
@@ -6160,10 +5685,10 @@ function extractIdentifierFromRecord(record) {
|
|
|
6160
5685
|
},
|
|
6161
5686
|
for: 'ember-data'
|
|
6162
5687
|
});
|
|
6163
|
-
return content ? recordIdentifierFor(content) : null;
|
|
5688
|
+
return content ? recordIdentifierFor$1(content) : null;
|
|
6164
5689
|
}
|
|
6165
5690
|
}
|
|
6166
|
-
return recordIdentifierFor(record);
|
|
5691
|
+
return recordIdentifierFor$1(record);
|
|
6167
5692
|
}
|
|
6168
5693
|
function anyUnloaded(store, relationship) {
|
|
6169
5694
|
const graph = store._graph;
|
|
@@ -6210,4 +5735,4 @@ function isBelongsTo(relationship) {
|
|
|
6210
5735
|
function isPromiseRecord(record) {
|
|
6211
5736
|
return typeof record === 'object' && !!record && 'then' in record;
|
|
6212
5737
|
}
|
|
6213
|
-
export { Errors as E, LEGACY_SUPPORT as L, Model as M, PromiseBelongsTo as P,
|
|
5738
|
+
export { Errors as E, LEGACY_SUPPORT as L, Model as M, PromiseBelongsTo as P, RecordState as R, PromiseManyArray as a, save as b, reload as c, destroyRecord as d, deleteRecord as e, changedAttributes as f, belongsTo as g, hasMany as h, createSnapshot as i, isElementDescriptor as j, lookupLegacySupport as l, normalizeModelName as n, rollbackAttributes as r, serialize as s, unloadRecord as u };
|