@ember-data/model 5.5.0-alpha.0 → 5.5.0-alpha.10
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/addon/-private.js +2 -2
- package/addon/{has-many-774c4c4b.js → has-many-7b6b78ec.js} +11 -195
- package/addon/has-many-7b6b78ec.js.map +1 -0
- package/addon/{hooks-6d5c2fc2.js → hooks-cf42b319.js} +1 -1
- package/addon/{hooks-6d5c2fc2.js.map → hooks-cf42b319.js.map} +1 -1
- package/addon/hooks.js +1 -1
- package/addon/index.js +3 -3
- package/addon/{model-b638e17c.js → model-b8502183.js} +41 -63
- package/addon/model-b8502183.js.map +1 -0
- package/package.json +20 -20
- package/addon/has-many-774c4c4b.js.map +0 -1
- package/addon/model-b638e17c.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { macroCondition, getOwnConfig, importSync } from '@embroider/macros';
|
|
2
1
|
import { deprecate, assert, warn } from '@ember/debug';
|
|
3
2
|
import { dasherize } from '@ember/string';
|
|
3
|
+
import { macroCondition, getOwnConfig, importSync } from '@embroider/macros';
|
|
4
4
|
import EmberObject, { computed, get } from '@ember/object';
|
|
5
5
|
import { dependentKeyCompat } from '@ember/object/compat';
|
|
6
6
|
import { cached, tracked } from '@glimmer/tracking';
|
|
@@ -1051,19 +1051,6 @@ function tapPromise(proxy, promise) {
|
|
|
1051
1051
|
throw error;
|
|
1052
1052
|
});
|
|
1053
1053
|
}
|
|
1054
|
-
|
|
1055
|
-
/*
|
|
1056
|
-
Assert that `addedRecord` has a valid type so it can be added to the
|
|
1057
|
-
relationship of the `record`.
|
|
1058
|
-
|
|
1059
|
-
The assert basically checks if the `addedRecord` can be added to the
|
|
1060
|
-
relationship (specified via `relationshipMeta`) of the `record`.
|
|
1061
|
-
|
|
1062
|
-
This utility should only be used internally, as both record parameters must
|
|
1063
|
-
be stable record identifiers and the `relationshipMeta` needs to be the meta
|
|
1064
|
-
information about the relationship, retrieved via
|
|
1065
|
-
`record.relationshipFor(key)`.
|
|
1066
|
-
*/
|
|
1067
1054
|
let assertPolymorphicType;
|
|
1068
1055
|
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
1069
1056
|
assertPolymorphicType = function assertPolymorphicType(parentIdentifier, parentDefinition, addedIdentifier, store) {
|
|
@@ -1077,11 +1064,6 @@ if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
|
1077
1064
|
};
|
|
1078
1065
|
}
|
|
1079
1066
|
var _class$3, _descriptor$3;
|
|
1080
|
-
|
|
1081
|
-
/**
|
|
1082
|
-
@module @ember-data/model
|
|
1083
|
-
*/
|
|
1084
|
-
|
|
1085
1067
|
function isResourceIdentiferWithRelatedLinks$1(value) {
|
|
1086
1068
|
return Boolean(value && value.links && value.links.related);
|
|
1087
1069
|
}
|
|
@@ -1555,11 +1537,6 @@ let BelongsToReference = (_class$3 = class BelongsToReference {
|
|
|
1555
1537
|
}
|
|
1556
1538
|
}), _applyDecoratedDescriptor(_class$3.prototype, "identifier", [cached, dependentKeyCompat], Object.getOwnPropertyDescriptor(_class$3.prototype, "identifier"), _class$3.prototype)), _class$3);
|
|
1557
1539
|
var _class$2, _descriptor$2;
|
|
1558
|
-
|
|
1559
|
-
/**
|
|
1560
|
-
@module @ember-data/model
|
|
1561
|
-
*/
|
|
1562
|
-
|
|
1563
1540
|
function isResourceIdentiferWithRelatedLinks(value) {
|
|
1564
1541
|
return Boolean(value && value.links && value.links.related);
|
|
1565
1542
|
}
|
|
@@ -2854,11 +2831,9 @@ let RecordState = (_class3 = class RecordState {
|
|
|
2854
2831
|
|
|
2855
2832
|
// we instantiate lazily
|
|
2856
2833
|
// so we grab anything we don't have yet
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
handleRequest(lastRequest);
|
|
2861
|
-
}
|
|
2834
|
+
const lastRequest = requests.getLastRequestForRecord(identity);
|
|
2835
|
+
if (lastRequest) {
|
|
2836
|
+
handleRequest(lastRequest);
|
|
2862
2837
|
}
|
|
2863
2838
|
this.handler = notifications.subscribe(identity, (identifier, type, key) => {
|
|
2864
2839
|
switch (type) {
|
|
@@ -3103,7 +3078,7 @@ function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
|
|
|
3103
3078
|
* an expensive getter on first-access and thereafter
|
|
3104
3079
|
* never recompute it.
|
|
3105
3080
|
*/
|
|
3106
|
-
function computeOnce(target,
|
|
3081
|
+
function computeOnce(target, propertyName, desc) {
|
|
3107
3082
|
const cache = new WeakMap();
|
|
3108
3083
|
let getter = desc.get;
|
|
3109
3084
|
desc.get = function () {
|
|
@@ -3175,8 +3150,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3175
3150
|
this.___recordState = macroCondition(getOwnConfig().env.DEBUG) ? new RecordState(this) : null;
|
|
3176
3151
|
this.setProperties(createProps);
|
|
3177
3152
|
let notifications = store.notifications;
|
|
3178
|
-
this.___private_notifications = notifications.subscribe(identity, (identifier, type,
|
|
3179
|
-
notifyChanges(identifier, type,
|
|
3153
|
+
this.___private_notifications = notifications.subscribe(identity, (identifier, type, field) => {
|
|
3154
|
+
notifyChanges(identifier, type, field, this, store);
|
|
3180
3155
|
});
|
|
3181
3156
|
}
|
|
3182
3157
|
destroy() {
|
|
@@ -3191,9 +3166,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3191
3166
|
// notify individual changes once the delete has been signaled,
|
|
3192
3167
|
// this decision is left to model instances.
|
|
3193
3168
|
|
|
3194
|
-
this.eachRelationship((
|
|
3169
|
+
this.eachRelationship((name, meta) => {
|
|
3195
3170
|
if (meta.kind === 'belongsTo') {
|
|
3196
|
-
this.notifyPropertyChange(
|
|
3171
|
+
this.notifyPropertyChange(name);
|
|
3197
3172
|
}
|
|
3198
3173
|
});
|
|
3199
3174
|
LEGACY_SUPPORT.get(this)?.destroy();
|
|
@@ -3584,12 +3559,12 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3584
3559
|
to trigger their flush. We wouldn't need to
|
|
3585
3560
|
super in 4.0+ where sync observers are removed.
|
|
3586
3561
|
*/
|
|
3587
|
-
notifyPropertyChange(
|
|
3588
|
-
let tag = peekTag(this,
|
|
3562
|
+
notifyPropertyChange(prop) {
|
|
3563
|
+
let tag = peekTag(this, prop);
|
|
3589
3564
|
if (tag) {
|
|
3590
3565
|
tag.notify();
|
|
3591
3566
|
}
|
|
3592
|
-
super.notifyPropertyChange(
|
|
3567
|
+
super.notifyPropertyChange(prop);
|
|
3593
3568
|
}
|
|
3594
3569
|
|
|
3595
3570
|
/**
|
|
@@ -3699,10 +3674,10 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
3699
3674
|
// and protects with a try...finally block
|
|
3700
3675
|
// previously used begin...endPropertyChanges but this is private API
|
|
3701
3676
|
changeProperties(() => {
|
|
3702
|
-
let
|
|
3677
|
+
let prop;
|
|
3703
3678
|
for (let i = 0, length = keys.length; i < length; i++) {
|
|
3704
|
-
|
|
3705
|
-
this.notifyPropertyChange(
|
|
3679
|
+
prop = keys[i];
|
|
3680
|
+
this.notifyPropertyChange(prop);
|
|
3706
3681
|
}
|
|
3707
3682
|
});
|
|
3708
3683
|
}
|
|
@@ -4005,7 +3980,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4005
3980
|
- `name` the name of the current property in the iteration
|
|
4006
3981
|
- `descriptor` the meta object that describes this relationship
|
|
4007
3982
|
The relationship descriptor argument is an object with the following properties.
|
|
4008
|
-
- **
|
|
3983
|
+
- **name** <span class="type">String</span> the name of this relationship on the Model
|
|
4009
3984
|
- **kind** <span class="type">String</span> "hasMany" or "belongsTo"
|
|
4010
3985
|
- **options** <span class="type">Object</span> the original options hash passed when the relationship was declared
|
|
4011
3986
|
- **parentType** <span class="type">Model</span> the type of the Model that owns this relationship
|
|
@@ -4039,8 +4014,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4039
4014
|
relationshipFor(name) {
|
|
4040
4015
|
return this.constructor.relationshipsByName.get(name);
|
|
4041
4016
|
}
|
|
4042
|
-
inverseFor(
|
|
4043
|
-
return this.constructor.inverseFor(
|
|
4017
|
+
inverseFor(name) {
|
|
4018
|
+
return this.constructor.inverseFor(name, storeFor$1(this));
|
|
4044
4019
|
}
|
|
4045
4020
|
eachAttribute(callback, binding) {
|
|
4046
4021
|
this.constructor.eachAttribute(callback, binding);
|
|
@@ -4292,7 +4267,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4292
4267
|
belongsTo: []
|
|
4293
4268
|
};
|
|
4294
4269
|
this.eachComputedProperty((name, meta) => {
|
|
4295
|
-
if (meta.
|
|
4270
|
+
if (meta.kind === 'hasMany' || meta.kind === 'belongsTo') {
|
|
4296
4271
|
names[meta.kind].push(name);
|
|
4297
4272
|
}
|
|
4298
4273
|
});
|
|
@@ -4363,9 +4338,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4363
4338
|
import Blog from 'app/models/blog';
|
|
4364
4339
|
let relationshipsByName = Blog.relationshipsByName;
|
|
4365
4340
|
relationshipsByName.users;
|
|
4366
|
-
//=> {
|
|
4341
|
+
//=> { name: 'users', kind: 'hasMany', type: 'user', options: Object }
|
|
4367
4342
|
relationshipsByName.owner;
|
|
4368
|
-
//=> {
|
|
4343
|
+
//=> { name: 'owner', kind: 'belongsTo', type: 'user', options: Object }
|
|
4369
4344
|
```
|
|
4370
4345
|
@property relationshipsByName
|
|
4371
4346
|
@public
|
|
@@ -4379,9 +4354,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4379
4354
|
let rels = this.relationshipsObject;
|
|
4380
4355
|
let relationships = Object.keys(rels);
|
|
4381
4356
|
for (let i = 0; i < relationships.length; i++) {
|
|
4382
|
-
let
|
|
4383
|
-
let value = rels[
|
|
4384
|
-
map.set(value.name
|
|
4357
|
+
let name = relationships[i];
|
|
4358
|
+
let value = rels[name];
|
|
4359
|
+
map.set(value.name, value);
|
|
4385
4360
|
}
|
|
4386
4361
|
return map;
|
|
4387
4362
|
}
|
|
@@ -4390,7 +4365,8 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4390
4365
|
let relationships = Object.create(null);
|
|
4391
4366
|
let modelName = this.modelName;
|
|
4392
4367
|
this.eachComputedProperty((name, meta) => {
|
|
4393
|
-
if (meta.
|
|
4368
|
+
if (meta.kind === 'hasMany' || meta.kind === 'belongsTo') {
|
|
4369
|
+
// TODO deprecate key being here
|
|
4394
4370
|
meta.key = name;
|
|
4395
4371
|
meta.name = name;
|
|
4396
4372
|
meta.parentModelName = modelName;
|
|
@@ -4438,10 +4414,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4438
4414
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4439
4415
|
let map = new Map();
|
|
4440
4416
|
this.eachComputedProperty((name, meta) => {
|
|
4441
|
-
|
|
4442
|
-
if (meta.isRelationship) {
|
|
4417
|
+
if (meta.kind === 'hasMany' || meta.kind === 'belongsTo') {
|
|
4443
4418
|
map.set(name, meta.kind);
|
|
4444
|
-
} else if (meta.
|
|
4419
|
+
} else if (meta.kind === 'attribute') {
|
|
4445
4420
|
map.set(name, 'attribute');
|
|
4446
4421
|
}
|
|
4447
4422
|
});
|
|
@@ -4486,7 +4461,7 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4486
4461
|
}
|
|
4487
4462
|
static determineRelationshipType(knownSide, store) {
|
|
4488
4463
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4489
|
-
let knownKey = knownSide.
|
|
4464
|
+
let knownKey = knownSide.name;
|
|
4490
4465
|
let knownKind = knownSide.kind;
|
|
4491
4466
|
let inverse = this.inverseFor(knownKey, store);
|
|
4492
4467
|
// let key;
|
|
@@ -4525,9 +4500,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4525
4500
|
// do thing
|
|
4526
4501
|
});
|
|
4527
4502
|
// prints:
|
|
4528
|
-
// firstName {type: "string",
|
|
4529
|
-
// lastName {type: "string",
|
|
4530
|
-
// birthday {type: "date",
|
|
4503
|
+
// firstName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "firstName"}
|
|
4504
|
+
// lastName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "lastName"}
|
|
4505
|
+
// birthday {type: "date", kind: 'attribute', options: Object, parentType: function, name: "birthday"}
|
|
4531
4506
|
```
|
|
4532
4507
|
@property attributes
|
|
4533
4508
|
@public
|
|
@@ -4539,8 +4514,11 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4539
4514
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4540
4515
|
let map = new Map();
|
|
4541
4516
|
this.eachComputedProperty((name, meta) => {
|
|
4542
|
-
if (meta.
|
|
4517
|
+
if (meta.kind === 'attribute') {
|
|
4543
4518
|
assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: attr('<type>')` from " + this.toString(), name !== 'id');
|
|
4519
|
+
|
|
4520
|
+
// TODO deprecate key being here
|
|
4521
|
+
meta.key = name;
|
|
4544
4522
|
meta.name = name;
|
|
4545
4523
|
map.set(name, meta);
|
|
4546
4524
|
}
|
|
@@ -4582,9 +4560,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4582
4560
|
static get transformedAttributes() {
|
|
4583
4561
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4584
4562
|
let map = new Map();
|
|
4585
|
-
this.eachAttribute((
|
|
4563
|
+
this.eachAttribute((name, meta) => {
|
|
4586
4564
|
if (meta.type) {
|
|
4587
|
-
map.set(
|
|
4565
|
+
map.set(name, meta.type);
|
|
4588
4566
|
}
|
|
4589
4567
|
});
|
|
4590
4568
|
return map;
|
|
@@ -4614,9 +4592,9 @@ let Model = (_class = (_class2 = class Model extends EmberObject {
|
|
|
4614
4592
|
// do thing
|
|
4615
4593
|
});
|
|
4616
4594
|
// prints:
|
|
4617
|
-
// firstName {type: "string",
|
|
4618
|
-
// lastName {type: "string",
|
|
4619
|
-
// birthday {type: "date",
|
|
4595
|
+
// firstName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "firstName"}
|
|
4596
|
+
// lastName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "lastName"}
|
|
4597
|
+
// birthday {type: "date", kind: 'attribute', options: Object, parentType: function, name: "birthday"}
|
|
4620
4598
|
```
|
|
4621
4599
|
@method eachAttribute
|
|
4622
4600
|
@public
|