@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.
@@ -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 type { ManyArray } from 'ember-data/-private';
11
-
12
- import { DEPRECATE_PROMISE_MANY_ARRAY_BEHAVIORS } from '@ember-data/private-build-infra/deprecations';
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
- const meta = Ember.meta(this);
57
- meta.hasMixin = (mixin: Object) => {
58
- if (mixin === NativeArray || mixin === ArrayMixin) {
59
- return true;
60
- }
61
- return false;
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
- this['[]'];
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
- return this.content ? this.content['[]'] : this.content;
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
  }
@@ -0,0 +1,4 @@
1
+ import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
2
+ import ObjectProxy from '@ember/object/proxy';
3
+
4
+ export const PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
@@ -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
- // TODO @deprecate pushing unresolved payloads
389
- const jsonApiDoc = await resolve(data);
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
- const payload = await resolve(objectOrPromise);
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
@@ -20,6 +20,8 @@ module.exports = Object.assign({}, addonBaseConfig, {
20
20
  '@ember/string',
21
21
  '@embroider/macros/es-compat',
22
22
 
23
+ '@ember/object/proxy',
24
+ '@ember/object/promise-proxy-mixin',
23
25
  '@ember/application',
24
26
  '@ember/array',
25
27
  '@ember/array/mutable',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/model",
3
- "version": "4.8.0-alpha.5",
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.5",
26
- "@ember-data/private-build-infra": "4.8.0-alpha.5",
27
- "@ember-data/store": "4.8.0-alpha.5",
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.5",
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",