@ember-data/model 5.4.0-alpha.138 → 5.4.0-alpha.139
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/dist/-private.js +3 -2
- package/dist/-private.js.map +1 -1
- package/dist/{has-many-7ie8Yz_T.js → has-many-CrrHwnrk.js} +1 -1
- package/dist/{has-many-7ie8Yz_T.js.map → has-many-CrrHwnrk.js.map} +1 -1
- package/dist/{hooks-BUEKTpYx.js → hooks-39rPlxYo.js} +2 -2
- package/dist/{hooks-BUEKTpYx.js.map → hooks-39rPlxYo.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/migration-support.js +2 -2
- package/dist/{model-BPFclP95.js → model-MT77KzYm.js} +12 -474
- package/dist/model-MT77KzYm.js.map +1 -0
- package/dist/{schema-provider-dkaVYK5r.js → schema-provider-CVlMpPY1.js} +1 -1
- package/dist/{schema-provider-dkaVYK5r.js.map → schema-provider-CVlMpPY1.js.map} +1 -1
- package/package.json +18 -18
- 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 +9 -11
- package/unstable-preview-types/-private/model.d.ts.map +1 -1
- package/unstable-preview-types/-private/promise-many-array.d.ts +1 -1
- package/unstable-preview-types/-private/promise-many-array.d.ts.map +1 -1
- 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/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 +2 -3
- package/unstable-preview-types/index.d.ts.map +1 -1
- package/dist/model-BPFclP95.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
|
@@ -3,9 +3,9 @@ import { dasherize } from '@ember-data/request-utils/string';
|
|
|
3
3
|
import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
|
|
4
4
|
import EmberObject, { computed, get } from '@ember/object';
|
|
5
5
|
import { recordIdentifierFor as recordIdentifierFor$1, storeFor as storeFor$1 } from '@ember-data/store';
|
|
6
|
-
import {
|
|
6
|
+
import { isStableIdentifier, recordIdentifierFor, storeFor, peekCache, SOURCE, fastPush, RelatedCollection, coerceId } from '@ember-data/store/-private';
|
|
7
7
|
import { cached, compat } from '@ember-data/tracking';
|
|
8
|
-
import {
|
|
8
|
+
import { defineSignal, peekSignal, addToTransaction, getSignal, subscribe } from '@ember-data/tracking/-private';
|
|
9
9
|
import { RecordStore } from '@warp-drive/core-types/symbols';
|
|
10
10
|
import { A } from '@ember/array';
|
|
11
11
|
import ArrayProxy from '@ember/array/proxy';
|
|
@@ -47,466 +47,6 @@ function normalizeModelName(type) {
|
|
|
47
47
|
}
|
|
48
48
|
return type;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
@module @ember-data/store
|
|
53
|
-
*/
|
|
54
|
-
/**
|
|
55
|
-
A `ManyArray` is a `MutableArray` that represents the contents of a has-many
|
|
56
|
-
relationship.
|
|
57
|
-
|
|
58
|
-
The `ManyArray` is instantiated lazily the first time the relationship is
|
|
59
|
-
requested.
|
|
60
|
-
|
|
61
|
-
This class is not intended to be directly instantiated by consuming applications.
|
|
62
|
-
|
|
63
|
-
### Inverses
|
|
64
|
-
|
|
65
|
-
Often, the relationships in Ember Data applications will have
|
|
66
|
-
an inverse. For example, imagine the following models are
|
|
67
|
-
defined:
|
|
68
|
-
|
|
69
|
-
```app/models/post.js
|
|
70
|
-
import Model, { hasMany } from '@ember-data/model';
|
|
71
|
-
|
|
72
|
-
export default class PostModel extends Model {
|
|
73
|
-
@hasMany('comment') comments;
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
```app/models/comment.js
|
|
78
|
-
import Model, { belongsTo } from '@ember-data/model';
|
|
79
|
-
|
|
80
|
-
export default class CommentModel extends Model {
|
|
81
|
-
@belongsTo('post') post;
|
|
82
|
-
}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
If you created a new instance of `Post` and added
|
|
86
|
-
a `Comment` record to its `comments` has-many
|
|
87
|
-
relationship, you would expect the comment's `post`
|
|
88
|
-
property to be set to the post that contained
|
|
89
|
-
the has-many.
|
|
90
|
-
|
|
91
|
-
We call the record to which a relationship belongs-to the
|
|
92
|
-
relationship's _owner_.
|
|
93
|
-
|
|
94
|
-
@class ManyArray
|
|
95
|
-
@public
|
|
96
|
-
*/
|
|
97
|
-
class RelatedCollection extends LiveArray {
|
|
98
|
-
/**
|
|
99
|
-
The loading state of this array
|
|
100
|
-
@property {Boolean} isLoaded
|
|
101
|
-
@public
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
`true` if the relationship is polymorphic, `false` otherwise.
|
|
106
|
-
@property {Boolean} isPolymorphic
|
|
107
|
-
@private
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
Metadata associated with the request for async hasMany relationships.
|
|
112
|
-
Example
|
|
113
|
-
Given that the server returns the following JSON payload when fetching a
|
|
114
|
-
hasMany relationship:
|
|
115
|
-
```js
|
|
116
|
-
{
|
|
117
|
-
"comments": [{
|
|
118
|
-
"id": 1,
|
|
119
|
-
"comment": "This is the first comment",
|
|
120
|
-
}, {
|
|
121
|
-
// ...
|
|
122
|
-
}],
|
|
123
|
-
"meta": {
|
|
124
|
-
"page": 1,
|
|
125
|
-
"total": 5
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
```
|
|
129
|
-
You can then access the meta data via the `meta` property:
|
|
130
|
-
```js
|
|
131
|
-
let comments = await post.comments;
|
|
132
|
-
let meta = comments.meta;
|
|
133
|
-
// meta.page => 1
|
|
134
|
-
// meta.total => 5
|
|
135
|
-
```
|
|
136
|
-
@property {Object | null} meta
|
|
137
|
-
@public
|
|
138
|
-
*/
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Retrieve the links for this relationship
|
|
142
|
-
*
|
|
143
|
-
@property {Object | null} links
|
|
144
|
-
@public
|
|
145
|
-
*/
|
|
146
|
-
|
|
147
|
-
constructor(options) {
|
|
148
|
-
super(options);
|
|
149
|
-
this.isLoaded = options.isLoaded || false;
|
|
150
|
-
this.isAsync = options.isAsync || false;
|
|
151
|
-
this.isPolymorphic = options.isPolymorphic || false;
|
|
152
|
-
this.identifier = options.identifier;
|
|
153
|
-
this.key = options.key;
|
|
154
|
-
}
|
|
155
|
-
[MUTATE](target, receiver, prop, args, _SIGNAL) {
|
|
156
|
-
switch (prop) {
|
|
157
|
-
case 'length 0':
|
|
158
|
-
{
|
|
159
|
-
Reflect.set(target, 'length', 0);
|
|
160
|
-
mutateReplaceRelatedRecords(this, [], _SIGNAL);
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
case 'replace cell':
|
|
164
|
-
{
|
|
165
|
-
const [index, prior, value] = args;
|
|
166
|
-
target[index] = value;
|
|
167
|
-
mutateReplaceRelatedRecord(this, {
|
|
168
|
-
value,
|
|
169
|
-
prior,
|
|
170
|
-
index
|
|
171
|
-
}, _SIGNAL);
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
case 'push':
|
|
175
|
-
{
|
|
176
|
-
const newValues = extractIdentifiersFromRecords(args);
|
|
177
|
-
assertNoDuplicates(this, target, currentState => currentState.push(...newValues), `Cannot push duplicates to a hasMany's state.`);
|
|
178
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
179
|
-
// dedupe
|
|
180
|
-
const seen = new Set(target);
|
|
181
|
-
const unique = new Set();
|
|
182
|
-
args.forEach(item => {
|
|
183
|
-
const identifier = recordIdentifierFor(item);
|
|
184
|
-
if (!seen.has(identifier)) {
|
|
185
|
-
seen.add(identifier);
|
|
186
|
-
unique.add(item);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
const newArgs = Array.from(unique);
|
|
190
|
-
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
191
|
-
if (newArgs.length) {
|
|
192
|
-
mutateAddToRelatedRecords(this, {
|
|
193
|
-
value: extractIdentifiersFromRecords(newArgs)
|
|
194
|
-
}, _SIGNAL);
|
|
195
|
-
}
|
|
196
|
-
return result;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// else, no dedupe, error on duplicates
|
|
200
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
201
|
-
if (newValues.length) {
|
|
202
|
-
mutateAddToRelatedRecords(this, {
|
|
203
|
-
value: newValues
|
|
204
|
-
}, _SIGNAL);
|
|
205
|
-
}
|
|
206
|
-
return result;
|
|
207
|
-
}
|
|
208
|
-
case 'pop':
|
|
209
|
-
{
|
|
210
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
211
|
-
if (result) {
|
|
212
|
-
mutateRemoveFromRelatedRecords(this, {
|
|
213
|
-
value: recordIdentifierFor(result)
|
|
214
|
-
}, _SIGNAL);
|
|
215
|
-
}
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
|
-
case 'unshift':
|
|
219
|
-
{
|
|
220
|
-
const newValues = extractIdentifiersFromRecords(args);
|
|
221
|
-
assertNoDuplicates(this, target, currentState => currentState.unshift(...newValues), `Cannot unshift duplicates to a hasMany's state.`);
|
|
222
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
223
|
-
// dedupe
|
|
224
|
-
const seen = new Set(target);
|
|
225
|
-
const unique = new Set();
|
|
226
|
-
args.forEach(item => {
|
|
227
|
-
const identifier = recordIdentifierFor(item);
|
|
228
|
-
if (!seen.has(identifier)) {
|
|
229
|
-
seen.add(identifier);
|
|
230
|
-
unique.add(item);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
const newArgs = Array.from(unique);
|
|
234
|
-
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
235
|
-
if (newArgs.length) {
|
|
236
|
-
mutateAddToRelatedRecords(this, {
|
|
237
|
-
value: extractIdentifiersFromRecords(newArgs),
|
|
238
|
-
index: 0
|
|
239
|
-
}, _SIGNAL);
|
|
240
|
-
}
|
|
241
|
-
return result;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// else, no dedupe, error on duplicates
|
|
245
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
246
|
-
if (newValues.length) {
|
|
247
|
-
mutateAddToRelatedRecords(this, {
|
|
248
|
-
value: newValues,
|
|
249
|
-
index: 0
|
|
250
|
-
}, _SIGNAL);
|
|
251
|
-
}
|
|
252
|
-
return result;
|
|
253
|
-
}
|
|
254
|
-
case 'shift':
|
|
255
|
-
{
|
|
256
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
257
|
-
if (result) {
|
|
258
|
-
mutateRemoveFromRelatedRecords(this, {
|
|
259
|
-
value: recordIdentifierFor(result),
|
|
260
|
-
index: 0
|
|
261
|
-
}, _SIGNAL);
|
|
262
|
-
}
|
|
263
|
-
return result;
|
|
264
|
-
}
|
|
265
|
-
case 'sort':
|
|
266
|
-
{
|
|
267
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
268
|
-
mutateSortRelatedRecords(this, result.map(recordIdentifierFor), _SIGNAL);
|
|
269
|
-
return result;
|
|
270
|
-
}
|
|
271
|
-
case 'splice':
|
|
272
|
-
{
|
|
273
|
-
const [start, deleteCount, ...adds] = args;
|
|
274
|
-
|
|
275
|
-
// detect a full replace
|
|
276
|
-
if (start === 0 && deleteCount === this[SOURCE].length) {
|
|
277
|
-
const newValues = extractIdentifiersFromRecords(adds);
|
|
278
|
-
assertNoDuplicates(this, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot replace a hasMany's state with a new state that contains duplicates.`);
|
|
279
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
280
|
-
// dedupe
|
|
281
|
-
const current = new Set(adds);
|
|
282
|
-
const unique = Array.from(current);
|
|
283
|
-
const newArgs = [start, deleteCount].concat(unique);
|
|
284
|
-
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
285
|
-
mutateReplaceRelatedRecords(this, extractIdentifiersFromRecords(unique), _SIGNAL);
|
|
286
|
-
return result;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// else, no dedupe, error on duplicates
|
|
290
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
291
|
-
mutateReplaceRelatedRecords(this, newValues, _SIGNAL);
|
|
292
|
-
return result;
|
|
293
|
-
}
|
|
294
|
-
const newValues = extractIdentifiersFromRecords(adds);
|
|
295
|
-
assertNoDuplicates(this, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot splice a hasMany's state with a new state that contains duplicates.`);
|
|
296
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
297
|
-
// dedupe
|
|
298
|
-
const currentState = target.slice();
|
|
299
|
-
currentState.splice(start, deleteCount);
|
|
300
|
-
const seen = new Set(currentState);
|
|
301
|
-
const unique = [];
|
|
302
|
-
adds.forEach(item => {
|
|
303
|
-
const identifier = recordIdentifierFor(item);
|
|
304
|
-
if (!seen.has(identifier)) {
|
|
305
|
-
seen.add(identifier);
|
|
306
|
-
unique.push(item);
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
const newArgs = [start, deleteCount, ...unique];
|
|
310
|
-
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
311
|
-
if (deleteCount > 0) {
|
|
312
|
-
mutateRemoveFromRelatedRecords(this, {
|
|
313
|
-
value: result.map(recordIdentifierFor),
|
|
314
|
-
index: start
|
|
315
|
-
}, _SIGNAL);
|
|
316
|
-
}
|
|
317
|
-
if (unique.length > 0) {
|
|
318
|
-
mutateAddToRelatedRecords(this, {
|
|
319
|
-
value: extractIdentifiersFromRecords(unique),
|
|
320
|
-
index: start
|
|
321
|
-
}, _SIGNAL);
|
|
322
|
-
}
|
|
323
|
-
return result;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// else, no dedupe, error on duplicates
|
|
327
|
-
const result = Reflect.apply(target[prop], receiver, args);
|
|
328
|
-
if (deleteCount > 0) {
|
|
329
|
-
mutateRemoveFromRelatedRecords(this, {
|
|
330
|
-
value: result.map(recordIdentifierFor),
|
|
331
|
-
index: start
|
|
332
|
-
}, _SIGNAL);
|
|
333
|
-
}
|
|
334
|
-
if (newValues.length > 0) {
|
|
335
|
-
mutateAddToRelatedRecords(this, {
|
|
336
|
-
value: newValues,
|
|
337
|
-
index: start
|
|
338
|
-
}, _SIGNAL);
|
|
339
|
-
}
|
|
340
|
-
return result;
|
|
341
|
-
}
|
|
342
|
-
default:
|
|
343
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
344
|
-
{
|
|
345
|
-
throw new Error(`unable to convert ${prop} into a transaction that updates the cache state for this record array`);
|
|
346
|
-
}
|
|
347
|
-
})() : {};
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
notify() {
|
|
351
|
-
const signal = this[ARRAY_SIGNAL];
|
|
352
|
-
signal.shouldReset = true;
|
|
353
|
-
notifyArray(this);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
Reloads all of the records in the manyArray. If the manyArray
|
|
358
|
-
holds a relationship that was originally fetched using a links url
|
|
359
|
-
EmberData will revisit the original links url to repopulate the
|
|
360
|
-
relationship.
|
|
361
|
-
If the ManyArray holds the result of a `store.query()` reload will
|
|
362
|
-
re-run the original query.
|
|
363
|
-
Example
|
|
364
|
-
```javascript
|
|
365
|
-
let user = store.peekRecord('user', '1')
|
|
366
|
-
await login(user);
|
|
367
|
-
let permissions = await user.permissions;
|
|
368
|
-
await permissions.reload();
|
|
369
|
-
```
|
|
370
|
-
@method reload
|
|
371
|
-
@public
|
|
372
|
-
*/
|
|
373
|
-
reload(options) {
|
|
374
|
-
// TODO this is odd, we don't ask the store for anything else like this?
|
|
375
|
-
return this._manager.reloadHasMany(this.key, options);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
Saves all of the records in the `ManyArray`.
|
|
380
|
-
Example
|
|
381
|
-
```javascript
|
|
382
|
-
let inbox = await store.findRecord('inbox', '1');
|
|
383
|
-
let messages = await inbox.messages;
|
|
384
|
-
messages.forEach((message) => {
|
|
385
|
-
message.isRead = true;
|
|
386
|
-
});
|
|
387
|
-
messages.save();
|
|
388
|
-
```
|
|
389
|
-
@method save
|
|
390
|
-
@public
|
|
391
|
-
@return {PromiseArray} promise
|
|
392
|
-
*/
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
Create a child record within the owner
|
|
396
|
-
@method createRecord
|
|
397
|
-
@public
|
|
398
|
-
@param {Object} hash
|
|
399
|
-
@return {Model} record
|
|
400
|
-
*/
|
|
401
|
-
createRecord(hash) {
|
|
402
|
-
const {
|
|
403
|
-
store
|
|
404
|
-
} = this;
|
|
405
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
406
|
-
if (!test) {
|
|
407
|
-
throw new Error(`Expected modelName to be set`);
|
|
408
|
-
}
|
|
409
|
-
})(this.modelName) : {};
|
|
410
|
-
const record = store.createRecord(this.modelName, hash);
|
|
411
|
-
this.push(record);
|
|
412
|
-
return record;
|
|
413
|
-
}
|
|
414
|
-
destroy() {
|
|
415
|
-
super.destroy(false);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
RelatedCollection.prototype.isAsync = false;
|
|
419
|
-
RelatedCollection.prototype.isPolymorphic = false;
|
|
420
|
-
RelatedCollection.prototype.identifier = null;
|
|
421
|
-
RelatedCollection.prototype.cache = null;
|
|
422
|
-
RelatedCollection.prototype._inverseIsAsync = false;
|
|
423
|
-
RelatedCollection.prototype.key = '';
|
|
424
|
-
RelatedCollection.prototype.DEPRECATED_CLASS_NAME = 'ManyArray';
|
|
425
|
-
function assertRecordPassedToHasMany(record) {
|
|
426
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
427
|
-
if (!test) {
|
|
428
|
-
throw new Error(`All elements of a hasMany relationship must be instances of Model, you passed ${typeof record}`);
|
|
429
|
-
}
|
|
430
|
-
})(function () {
|
|
431
|
-
try {
|
|
432
|
-
recordIdentifierFor(record);
|
|
433
|
-
return true;
|
|
434
|
-
} catch {
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
}()) : {};
|
|
438
|
-
}
|
|
439
|
-
function extractIdentifiersFromRecords(records) {
|
|
440
|
-
return records.map(extractIdentifierFromRecord$1);
|
|
441
|
-
}
|
|
442
|
-
function extractIdentifierFromRecord$1(recordOrPromiseRecord) {
|
|
443
|
-
assertRecordPassedToHasMany(recordOrPromiseRecord);
|
|
444
|
-
return recordIdentifierFor(recordOrPromiseRecord);
|
|
445
|
-
}
|
|
446
|
-
function assertNoDuplicates(collection, target, callback, reason) {
|
|
447
|
-
const state = target.slice();
|
|
448
|
-
callback(state);
|
|
449
|
-
if (state.length !== new Set(state).size) {
|
|
450
|
-
const duplicates = state.filter((currentValue, currentIndex) => state.indexOf(currentValue) !== currentIndex);
|
|
451
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
452
|
-
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- ')}`, false, {
|
|
453
|
-
id: 'ember-data:deprecate-many-array-duplicates',
|
|
454
|
-
for: 'ember-data',
|
|
455
|
-
until: '6.0',
|
|
456
|
-
since: {
|
|
457
|
-
enabled: '5.3',
|
|
458
|
-
available: '4.13'
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
} else {
|
|
462
|
-
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- ')}`);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
function mutateAddToRelatedRecords(collection, operationInfo, _SIGNAL) {
|
|
467
|
-
mutate(collection, {
|
|
468
|
-
op: 'addToRelatedRecords',
|
|
469
|
-
record: collection.identifier,
|
|
470
|
-
field: collection.key,
|
|
471
|
-
...operationInfo
|
|
472
|
-
}, _SIGNAL);
|
|
473
|
-
}
|
|
474
|
-
function mutateRemoveFromRelatedRecords(collection, operationInfo, _SIGNAL) {
|
|
475
|
-
mutate(collection, {
|
|
476
|
-
op: 'removeFromRelatedRecords',
|
|
477
|
-
record: collection.identifier,
|
|
478
|
-
field: collection.key,
|
|
479
|
-
...operationInfo
|
|
480
|
-
}, _SIGNAL);
|
|
481
|
-
}
|
|
482
|
-
function mutateReplaceRelatedRecord(collection, operationInfo, _SIGNAL) {
|
|
483
|
-
mutate(collection, {
|
|
484
|
-
op: 'replaceRelatedRecord',
|
|
485
|
-
record: collection.identifier,
|
|
486
|
-
field: collection.key,
|
|
487
|
-
...operationInfo
|
|
488
|
-
}, _SIGNAL);
|
|
489
|
-
}
|
|
490
|
-
function mutateReplaceRelatedRecords(collection, value, _SIGNAL) {
|
|
491
|
-
mutate(collection, {
|
|
492
|
-
op: 'replaceRelatedRecords',
|
|
493
|
-
record: collection.identifier,
|
|
494
|
-
field: collection.key,
|
|
495
|
-
value
|
|
496
|
-
}, _SIGNAL);
|
|
497
|
-
}
|
|
498
|
-
function mutateSortRelatedRecords(collection, value, _SIGNAL) {
|
|
499
|
-
mutate(collection, {
|
|
500
|
-
op: 'sortRelatedRecords',
|
|
501
|
-
record: collection.identifier,
|
|
502
|
-
field: collection.key,
|
|
503
|
-
value
|
|
504
|
-
}, _SIGNAL);
|
|
505
|
-
}
|
|
506
|
-
function mutate(collection, mutation, _SIGNAL) {
|
|
507
|
-
collection._manager.mutate(mutation);
|
|
508
|
-
addToTransaction(_SIGNAL);
|
|
509
|
-
}
|
|
510
50
|
const PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
|
|
511
51
|
const deferred = /* @__PURE__ */new WeakMap();
|
|
512
52
|
function deferDecorator(proto, prop, desc) {
|
|
@@ -2263,6 +1803,7 @@ class LegacySupport {
|
|
|
2263
1803
|
isPolymorphic: definition.isPolymorphic,
|
|
2264
1804
|
isAsync: definition.isAsync,
|
|
2265
1805
|
_inverseIsAsync: definition.inverseIsAsync,
|
|
1806
|
+
// @ts-expect-error Typescript doesn't have a way for us to thread the generic backwards so it infers unknown instead of T
|
|
2266
1807
|
manager: this,
|
|
2267
1808
|
isLoaded: !definition.isAsync,
|
|
2268
1809
|
allowMutation: true
|
|
@@ -3860,9 +3401,8 @@ class Model extends EmberObject {
|
|
|
3860
3401
|
```javascript
|
|
3861
3402
|
let record = store.createRecord('model');
|
|
3862
3403
|
record.isLoaded; // true
|
|
3863
|
-
store.findRecord('model', 1)
|
|
3864
|
-
|
|
3865
|
-
});
|
|
3404
|
+
const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
|
|
3405
|
+
model.isLoaded;
|
|
3866
3406
|
```
|
|
3867
3407
|
@property isLoaded
|
|
3868
3408
|
@public
|
|
@@ -3885,11 +3425,10 @@ class Model extends EmberObject {
|
|
|
3885
3425
|
```javascript
|
|
3886
3426
|
let record = store.createRecord('model');
|
|
3887
3427
|
record.hasDirtyAttributes; // true
|
|
3888
|
-
store.findRecord('model', 1)
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
});
|
|
3428
|
+
const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
|
|
3429
|
+
model.hasDirtyAttributes; // false
|
|
3430
|
+
model.foo = 'some value';
|
|
3431
|
+
model.hasDirtyAttributes; // true
|
|
3893
3432
|
```
|
|
3894
3433
|
@since 1.13.0
|
|
3895
3434
|
@property hasDirtyAttributes
|
|
@@ -4090,9 +3629,8 @@ class Model extends EmberObject {
|
|
|
4090
3629
|
```javascript
|
|
4091
3630
|
let record = store.createRecord('model');
|
|
4092
3631
|
record.id; // null
|
|
4093
|
-
store.findRecord('model', 1)
|
|
4094
|
-
|
|
4095
|
-
});
|
|
3632
|
+
const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
|
|
3633
|
+
model.id; // '1'
|
|
4096
3634
|
```
|
|
4097
3635
|
@property id
|
|
4098
3636
|
@public
|
|
@@ -5400,4 +4938,4 @@ function isRelationshipSchema(meta) {
|
|
|
5400
4938
|
function isAttributeSchema(meta) {
|
|
5401
4939
|
return typeof meta === 'object' && meta !== null && 'kind' in meta && meta.kind === 'attribute';
|
|
5402
4940
|
}
|
|
5403
|
-
export { Errors as E, LEGACY_SUPPORT as L, Model as M, PromiseBelongsTo as P,
|
|
4941
|
+
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 };
|