@ember-data/model 4.8.0-alpha.5 → 4.8.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/addon/-private/deprecated-promise-proxy.ts +54 -0
- package/addon/-private/has-many.js +3 -1
- package/addon/-private/legacy-relationships-support.ts +145 -92
- package/addon/-private/many-array.ts +211 -249
- package/addon/-private/model.js +18 -9
- package/addon/-private/promise-belongs-to.ts +1 -1
- package/addon/-private/promise-many-array.ts +35 -13
- package/addon/-private/promise-proxy-base.js +4 -0
- package/addon/-private/references/belongs-to.ts +21 -2
- package/addon/-private/references/has-many.ts +21 -1
- package/index.js +2 -0
- package/package.json +5 -5
|
@@ -2,18 +2,23 @@ import ArrayMixin, { NativeArray } from '@ember/array';
|
|
|
2
2
|
import type ArrayProxy from '@ember/array/proxy';
|
|
3
3
|
import { assert, deprecate } from '@ember/debug';
|
|
4
4
|
import { dependentKeyCompat } from '@ember/object/compat';
|
|
5
|
+
import { DEBUG } from '@glimmer/env';
|
|
5
6
|
import { tracked } from '@glimmer/tracking';
|
|
6
7
|
import Ember from 'ember';
|
|
7
8
|
|
|
8
9
|
import { resolve } from 'rsvp';
|
|
9
10
|
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
import {
|
|
12
|
+
DEPRECATE_A_USAGE,
|
|
13
|
+
DEPRECATE_COMPUTED_CHAINS,
|
|
14
|
+
DEPRECATE_PROMISE_MANY_ARRAY_BEHAVIORS,
|
|
15
|
+
} from '@ember-data/private-build-infra/deprecations';
|
|
13
16
|
import { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
14
17
|
import type { RecordInstance } from '@ember-data/types/q/record-instance';
|
|
15
18
|
import { FindOptions } from '@ember-data/types/q/store';
|
|
16
19
|
|
|
20
|
+
import type ManyArray from './many-array';
|
|
21
|
+
|
|
17
22
|
export interface HasManyProxyCreateArgs {
|
|
18
23
|
promise: Promise<ManyArray>;
|
|
19
24
|
content?: ManyArray;
|
|
@@ -53,13 +58,27 @@ export default class PromiseManyArray {
|
|
|
53
58
|
this.isDestroyed = false;
|
|
54
59
|
this.isDestroying = false;
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
if (DEPRECATE_A_USAGE) {
|
|
62
|
+
const meta = Ember.meta(this);
|
|
63
|
+
meta.hasMixin = (mixin: Object) => {
|
|
64
|
+
deprecate(`Do not use A() on an EmberData PromiseManyArray`, false, {
|
|
65
|
+
id: 'ember-data:no-a-with-array-like',
|
|
66
|
+
until: '5.0',
|
|
67
|
+
since: { enabled: '4.8', available: '4.8' },
|
|
68
|
+
for: 'ember-data',
|
|
69
|
+
});
|
|
70
|
+
// @ts-expect-error ArrayMixin is more than a type
|
|
71
|
+
if (mixin === NativeArray || mixin === ArrayMixin) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
};
|
|
76
|
+
} else if (DEBUG) {
|
|
77
|
+
const meta = Ember.meta(this);
|
|
78
|
+
meta.hasMixin = (mixin: Object) => {
|
|
79
|
+
assert(`Do not use A() on an EmberData PromiseManyArray`);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
63
82
|
}
|
|
64
83
|
|
|
65
84
|
//---- Methods/Properties on ArrayProxy that we will keep as our API
|
|
@@ -75,7 +94,9 @@ export default class PromiseManyArray {
|
|
|
75
94
|
get length(): number {
|
|
76
95
|
// shouldn't be needed, but ends up being needed
|
|
77
96
|
// for computed chains even in 4.x
|
|
78
|
-
|
|
97
|
+
if (DEPRECATE_COMPUTED_CHAINS) {
|
|
98
|
+
this['[]'];
|
|
99
|
+
}
|
|
79
100
|
return this.content ? this.content.length : 0;
|
|
80
101
|
}
|
|
81
102
|
|
|
@@ -85,7 +106,9 @@ export default class PromiseManyArray {
|
|
|
85
106
|
// to recompute. We entangle the '[]' tag from
|
|
86
107
|
@dependentKeyCompat
|
|
87
108
|
get '[]'() {
|
|
88
|
-
|
|
109
|
+
if (DEPRECATE_COMPUTED_CHAINS) {
|
|
110
|
+
return this.content?.length && this.content;
|
|
111
|
+
}
|
|
89
112
|
}
|
|
90
113
|
|
|
91
114
|
/**
|
|
@@ -99,7 +122,6 @@ export default class PromiseManyArray {
|
|
|
99
122
|
* @private
|
|
100
123
|
*/
|
|
101
124
|
forEach(cb) {
|
|
102
|
-
this['[]']; // needed for < 3.23 support e.g. 3.20 lts
|
|
103
125
|
if (this.content && this.length) {
|
|
104
126
|
this.content.forEach(cb);
|
|
105
127
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { deprecate } from '@ember/debug';
|
|
1
2
|
import { dependentKeyCompat } from '@ember/object/compat';
|
|
2
3
|
import { cached, tracked } from '@glimmer/tracking';
|
|
3
4
|
|
|
4
5
|
import type { Object as JSONObject, Value as JSONValue } from 'json-typescript';
|
|
5
6
|
import { resolve } from 'rsvp';
|
|
6
7
|
|
|
8
|
+
import { DEPRECATE_PROMISE_PROXIES } from '@ember-data/private-build-infra/deprecations';
|
|
7
9
|
import type { Graph } from '@ember-data/record-data/-private/graph';
|
|
8
10
|
import type BelongsToRelationship from '@ember-data/record-data/-private/relationships/state/belongs-to';
|
|
9
11
|
import type Store from '@ember-data/store';
|
|
@@ -385,8 +387,25 @@ export default class BelongsToReference {
|
|
|
385
387
|
@return {Promise<record>} A promise that resolves with the new value in this belongs-to relationship.
|
|
386
388
|
*/
|
|
387
389
|
async push(data: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<RecordInstance> {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
+
let jsonApiDoc: SingleResourceDocument = data as SingleResourceDocument;
|
|
391
|
+
if (DEPRECATE_PROMISE_PROXIES && (data as { then: unknown }).then) {
|
|
392
|
+
jsonApiDoc = await resolve(data);
|
|
393
|
+
if (jsonApiDoc !== data) {
|
|
394
|
+
deprecate(
|
|
395
|
+
`You passed in a Promise to a Reference API that now expects a resolved value. await the value before setting it.`,
|
|
396
|
+
false,
|
|
397
|
+
{
|
|
398
|
+
id: 'ember-data:deprecate-promise-proxies',
|
|
399
|
+
until: '5.0',
|
|
400
|
+
since: {
|
|
401
|
+
enabled: '4.8',
|
|
402
|
+
available: '4.8',
|
|
403
|
+
},
|
|
404
|
+
for: 'ember-data',
|
|
405
|
+
}
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
390
409
|
let record = this.store.push(jsonApiDoc);
|
|
391
410
|
|
|
392
411
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deprecate } from '@ember/debug';
|
|
1
2
|
import { dependentKeyCompat } from '@ember/object/compat';
|
|
2
3
|
import { DEBUG } from '@glimmer/env';
|
|
3
4
|
import { cached, tracked } from '@glimmer/tracking';
|
|
@@ -7,6 +8,7 @@ import { resolve } from 'rsvp';
|
|
|
7
8
|
|
|
8
9
|
import { ManyArray } from 'ember-data/-private';
|
|
9
10
|
|
|
11
|
+
import { DEPRECATE_PROMISE_PROXIES } from '@ember-data/private-build-infra/deprecations';
|
|
10
12
|
import type { Graph } from '@ember-data/record-data/-private/graph';
|
|
11
13
|
import type ManyRelationship from '@ember-data/record-data/-private/relationships/state/has-many';
|
|
12
14
|
import type Store from '@ember-data/store';
|
|
@@ -397,7 +399,25 @@ export default class HasManyReference {
|
|
|
397
399
|
async push(
|
|
398
400
|
objectOrPromise: ExistingResourceObject[] | CollectionResourceDocument | { data: SingleResourceDocument[] }
|
|
399
401
|
): Promise<ManyArray> {
|
|
400
|
-
|
|
402
|
+
let payload = objectOrPromise;
|
|
403
|
+
if (DEPRECATE_PROMISE_PROXIES && (objectOrPromise as unknown as { then: unknown }).then) {
|
|
404
|
+
payload = await resolve(objectOrPromise);
|
|
405
|
+
if (payload !== objectOrPromise) {
|
|
406
|
+
deprecate(
|
|
407
|
+
`You passed in a Promise to a Reference API that now expects a resolved value. await the value before setting it.`,
|
|
408
|
+
false,
|
|
409
|
+
{
|
|
410
|
+
id: 'ember-data:deprecate-promise-proxies',
|
|
411
|
+
until: '5.0',
|
|
412
|
+
since: {
|
|
413
|
+
enabled: '4.8',
|
|
414
|
+
available: '4.8',
|
|
415
|
+
},
|
|
416
|
+
for: 'ember-data',
|
|
417
|
+
}
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
401
421
|
let array: Array<ExistingResourceObject | SingleResourceDocument>;
|
|
402
422
|
|
|
403
423
|
if (!Array.isArray(payload) && typeof payload === 'object' && Array.isArray(payload.data)) {
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-data/model",
|
|
3
|
-
"version": "4.8.0-alpha.
|
|
3
|
+
"version": "4.8.0-alpha.6",
|
|
4
4
|
"description": "A presentation layer for apps built with @ember-data/store",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"test:node": "mocha"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@ember-data/canary-features": "4.8.0-alpha.
|
|
26
|
-
"@ember-data/private-build-infra": "4.8.0-alpha.
|
|
27
|
-
"@ember-data/store": "4.8.0-alpha.
|
|
25
|
+
"@ember-data/canary-features": "4.8.0-alpha.6",
|
|
26
|
+
"@ember-data/private-build-infra": "4.8.0-alpha.6",
|
|
27
|
+
"@ember-data/store": "4.8.0-alpha.6",
|
|
28
28
|
"@ember/edition-utils": "^1.2.0",
|
|
29
29
|
"@ember/string": "^3.0.0",
|
|
30
30
|
"@embroider/macros": "^1.8.3",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"inflection": "~1.13.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@ember-data/unpublished-test-infra": "4.8.0-alpha.
|
|
41
|
+
"@ember-data/unpublished-test-infra": "4.8.0-alpha.6",
|
|
42
42
|
"@ember/optional-features": "^2.0.0",
|
|
43
43
|
"@ember/test-helpers": "~2.7.0",
|
|
44
44
|
"broccoli-asset-rev": "^3.0.0",
|