@ember-data/model 4.8.0-alpha.6 → 4.8.0

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.
@@ -1,15 +1,15 @@
1
1
  import { deprecate } from '@ember/debug';
2
2
  import { dependentKeyCompat } from '@ember/object/compat';
3
+ import { DEBUG } from '@glimmer/env';
3
4
  import { cached, tracked } from '@glimmer/tracking';
4
5
 
5
6
  import type { Object as JSONObject, Value as JSONValue } from 'json-typescript';
6
7
  import { resolve } from 'rsvp';
7
8
 
8
9
  import { DEPRECATE_PROMISE_PROXIES } from '@ember-data/private-build-infra/deprecations';
9
- import type { Graph } from '@ember-data/record-data/-private/graph';
10
+ import type { Graph } from '@ember-data/record-data/-private/graph/graph';
10
11
  import type BelongsToRelationship from '@ember-data/record-data/-private/relationships/state/belongs-to';
11
12
  import type Store from '@ember-data/store';
12
- import { assertPolymorphicType } from '@ember-data/store/-debug';
13
13
  import { recordIdentifierFor } from '@ember-data/store/-private';
14
14
  import type { NotificationType } from '@ember-data/store/-private/managers/record-notification-manager';
15
15
  import type {
@@ -22,6 +22,7 @@ import type { StableRecordIdentifier } from '@ember-data/types/q/identifier';
22
22
  import type { RecordInstance } from '@ember-data/types/q/record-instance';
23
23
  import type { Dict } from '@ember-data/types/q/utils';
24
24
 
25
+ import { assertPolymorphicType } from '../debug/assert-polymorphic-type';
25
26
  import type { LegacySupport } from '../legacy-relationships-support';
26
27
  import { LEGACY_SUPPORT } from '../model';
27
28
 
@@ -101,9 +102,16 @@ export default class BelongsToReference {
101
102
  }
102
103
  }
103
104
 
105
+ /**
106
+ * The identifier of the record that this reference refers to.
107
+ * `null` if no related record is known.
108
+ *
109
+ * @property {StableRecordIdentifier | null} identifier
110
+ * @public
111
+ */
104
112
  @cached
105
113
  @dependentKeyCompat
106
- get _relatedIdentifier(): StableRecordIdentifier | null {
114
+ get identifier(): StableRecordIdentifier | null {
107
115
  this._ref; // consume the tracked prop
108
116
  if (this.___relatedToken) {
109
117
  this.store._notificationManager.unsubscribe(this.___relatedToken);
@@ -165,11 +173,11 @@ export default class BelongsToReference {
165
173
  ```
166
174
 
167
175
  @method id
168
- @public
176
+ @public
169
177
  @return {String} The id of the record in this belongsTo relationship.
170
178
  */
171
179
  id(): string | null {
172
- return this._relatedIdentifier?.id || null;
180
+ return this.identifier?.id || null;
173
181
  }
174
182
 
175
183
  /**
@@ -388,33 +396,37 @@ export default class BelongsToReference {
388
396
  */
389
397
  async push(data: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<RecordInstance> {
390
398
  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
- );
399
+ if (DEPRECATE_PROMISE_PROXIES) {
400
+ if ((data as { then: unknown }).then) {
401
+ jsonApiDoc = await resolve(data);
402
+ if (jsonApiDoc !== data) {
403
+ deprecate(
404
+ `You passed in a Promise to a Reference API that now expects a resolved value. await the value before setting it.`,
405
+ false,
406
+ {
407
+ id: 'ember-data:deprecate-promise-proxies',
408
+ until: '5.0',
409
+ since: {
410
+ enabled: '4.7',
411
+ available: '4.7',
412
+ },
413
+ for: 'ember-data',
414
+ }
415
+ );
416
+ }
407
417
  }
408
418
  }
409
419
  let record = this.store.push(jsonApiDoc);
410
420
 
411
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
412
- assertPolymorphicType(
413
- this.belongsToRelationship.identifier,
414
- this.belongsToRelationship.definition,
415
- recordIdentifierFor(record),
416
- this.store
417
- );
421
+ if (DEBUG) {
422
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
423
+ assertPolymorphicType(
424
+ this.belongsToRelationship.identifier,
425
+ this.belongsToRelationship.definition,
426
+ recordIdentifierFor(record),
427
+ this.store
428
+ );
429
+ }
418
430
 
419
431
  const { identifier } = this.belongsToRelationship;
420
432
  this.store._join(() => {
@@ -9,11 +9,10 @@ import { resolve } from 'rsvp';
9
9
  import { ManyArray } from 'ember-data/-private';
10
10
 
11
11
  import { DEPRECATE_PROMISE_PROXIES } from '@ember-data/private-build-infra/deprecations';
12
- import type { Graph } from '@ember-data/record-data/-private/graph';
12
+ import type { Graph } from '@ember-data/record-data/-private/graph/graph';
13
13
  import type ManyRelationship from '@ember-data/record-data/-private/relationships/state/has-many';
14
14
  import type Store from '@ember-data/store';
15
15
  import { recordIdentifierFor } from '@ember-data/store';
16
- import { assertPolymorphicType } from '@ember-data/store/-debug';
17
16
  import type { NotificationType } from '@ember-data/store/-private/managers/record-notification-manager';
18
17
  import type {
19
18
  CollectionResourceDocument,
@@ -28,6 +27,7 @@ import type { RecordInstance } from '@ember-data/types/q/record-instance';
28
27
  import type { FindOptions } from '@ember-data/types/q/store';
29
28
  import type { Dict } from '@ember-data/types/q/utils';
30
29
 
30
+ import { assertPolymorphicType } from '../debug/assert-polymorphic-type';
31
31
  import type { LegacySupport } from '../legacy-relationships-support';
32
32
  import { LEGACY_SUPPORT } from '../model';
33
33
 
@@ -102,9 +102,15 @@ export default class HasManyReference {
102
102
  this.___relatedTokenMap.clear();
103
103
  }
104
104
 
105
+ /**
106
+ * An array of identifiers for the records that this reference refers to.
107
+ *
108
+ * @property {StableRecordIdentifier[]} identifiers
109
+ * @public
110
+ */
105
111
  @cached
106
112
  @dependentKeyCompat
107
- get _relatedIdentifiers(): StableRecordIdentifier[] {
113
+ get identifiers(): StableRecordIdentifier[] {
108
114
  this._ref; // consume the tracked prop
109
115
 
110
116
  let resource = this._resource();
@@ -236,7 +242,7 @@ export default class HasManyReference {
236
242
  @return {Array} The ids in this has-many relationship
237
243
  */
238
244
  ids(): Array<string | null> {
239
- return this._relatedIdentifiers.map((identifier) => identifier.id);
245
+ return this.identifiers.map((identifier) => identifier.id);
240
246
  }
241
247
 
242
248
  /**
@@ -400,22 +406,24 @@ export default class HasManyReference {
400
406
  objectOrPromise: ExistingResourceObject[] | CollectionResourceDocument | { data: SingleResourceDocument[] }
401
407
  ): Promise<ManyArray> {
402
408
  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
- );
409
+ if (DEPRECATE_PROMISE_PROXIES) {
410
+ if ((objectOrPromise as unknown as { then: unknown }).then) {
411
+ payload = await resolve(objectOrPromise);
412
+ if (payload !== objectOrPromise) {
413
+ deprecate(
414
+ `You passed in a Promise to a Reference API that now expects a resolved value. await the value before setting it.`,
415
+ false,
416
+ {
417
+ id: 'ember-data:deprecate-promise-proxies',
418
+ until: '5.0',
419
+ since: {
420
+ enabled: '4.7',
421
+ available: '4.7',
422
+ },
423
+ for: 'ember-data',
424
+ }
425
+ );
426
+ }
419
427
  }
420
428
  }
421
429
  let array: Array<ExistingResourceObject | SingleResourceDocument>;
@@ -519,7 +527,16 @@ export default class HasManyReference {
519
527
  this.___identifier
520
528
  )!;
521
529
 
522
- return this._isLoaded() ? support.getManyArray(this.key) : null;
530
+ const loaded = this._isLoaded();
531
+
532
+ if (!loaded) {
533
+ // subscribe to changes
534
+ // for when we are not loaded yet
535
+ this._ref;
536
+ return null;
537
+ }
538
+
539
+ return support.getManyArray(this.key);
523
540
  }
524
541
 
525
542
  /**
@@ -75,8 +75,12 @@ class RelationshipDefinition implements RelationshipSchema {
75
75
 
76
76
  if (shouldFindInverse(this.meta)) {
77
77
  inverse = modelClass.inverseFor(this.key, store);
78
- } else if (DEBUG) {
79
- modelClass.typeForRelationship(this.key, store);
78
+ }
79
+ // TODO make this error again for the non-polymorphic case
80
+ if (DEBUG) {
81
+ if (!this.options.polymorphic) {
82
+ modelClass.typeForRelationship(this.key, store);
83
+ }
80
84
  }
81
85
 
82
86
  if (inverse) {
package/addon/index.ts CHANGED
@@ -36,5 +36,4 @@
36
36
  @module @ember-data/model
37
37
  @main @ember-data/model
38
38
  */
39
-
40
39
  export { Model as default, attr, belongsTo, hasMany } from './-private';
@@ -1,15 +1,16 @@
1
1
  import { expect } from 'chai';
2
2
  import { describe, it } from 'mocha';
3
+
3
4
  import { setupModelTest } from 'ember-mocha';
4
5
 
5
- describe('<%= friendlyTestDescription %>', function() {
6
+ describe('<%= friendlyTestDescription %>', function () {
6
7
  setupModelTest('<%= dasherizedModuleName %>', {
7
8
  // Specify the other units that are required for this test.
8
- <%= typeof needs !== 'undefined' ? needs : '' %>
9
+ <%= typeof needs !== 'undefined' ? needs : '' %>,
9
10
  });
10
11
 
11
12
  // Replace this with your real tests.
12
- it('exists', function() {
13
+ it('exists', function () {
13
14
  let model = this.subject();
14
15
  // var store = this.store();
15
16
  expect(model).to.be.ok;
@@ -1,12 +1,13 @@
1
1
  import { expect } from 'chai';
2
2
  import { describe, it } from 'mocha';
3
+
3
4
  import { setupTest } from '<%= modulePrefix %>/tests/helpers';
4
5
 
5
- describe('<%= friendlyTestDescription %>', function() {
6
+ describe('<%= friendlyTestDescription %>', function () {
6
7
  setupTest();
7
8
 
8
9
  // Replace this with your real tests.
9
- it('exists', function() {
10
+ it('exists', function () {
10
11
  let store = this.owner.lookup('service:store');
11
12
  let model = store.createRecord('<%= dasherizedModuleName %>', {});
12
13
  expect(model).to.be.ok;
@@ -1,11 +1,12 @@
1
1
  import { module, test } from 'qunit';
2
+
2
3
  import { setupTest } from '<%= modulePrefix %>/tests/helpers';
3
4
 
4
- module('<%= friendlyTestDescription %>', function(hooks) {
5
+ module('<%= friendlyTestDescription %>', function (hooks) {
5
6
  setupTest(hooks);
6
7
 
7
8
  // Replace this with your real tests.
8
- test('it exists', function(assert) {
9
+ test('it exists', function (assert) {
9
10
  let store = this.owner.lookup('service:store');
10
11
  let model = store.createRecord('<%= dasherizedModuleName %>', {});
11
12
  assert.ok(model);
package/index.js CHANGED
@@ -15,10 +15,10 @@ module.exports = Object.assign({}, addonBaseConfig, {
15
15
  '@ember-data/canary-features',
16
16
  '@ember-data/store',
17
17
  '@ember-data/store/-private',
18
- '@ember-data/store/-debug',
19
18
  '@embroider/macros',
20
19
  '@ember/string',
21
20
  '@embroider/macros/es-compat',
21
+ '@ember-data/tracking/-private',
22
22
 
23
23
  '@ember/object/proxy',
24
24
  '@ember/object/promise-proxy-mixin',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/model",
3
- "version": "4.8.0-alpha.6",
3
+ "version": "4.8.0",
4
4
  "description": "A presentation layer for apps built with @ember-data/store",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -12,66 +12,53 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "author": "",
15
- "directories": {
16
- "doc": "doc",
17
- "test": "tests"
15
+ "directories": {},
16
+ "scripts": {},
17
+ "peerDependencies": {
18
+ "@ember-data/record-data": "workspace:4.9.0-alpha.6",
19
+ "@ember-data/store": "workspace:4.9.0-alpha.6",
20
+ "@ember-data/tracking": "workspace:4.9.0-alpha.6",
21
+ "@ember/string": "^3.0.0",
22
+ "ember-inflector": "^4.0.2"
23
+ },
24
+ "peerDependenciesMeta": {
25
+ "@ember-data/record-data": {
26
+ "optional": true
27
+ }
18
28
  },
19
- "scripts": {
20
- "build": "ember build",
21
- "start": "ember serve",
22
- "test:node": "mocha"
29
+ "dependenciesMeta": {
30
+ "@ember-data/canary-features": {
31
+ "injected": true
32
+ },
33
+ "@ember-data/private-build-infra": {
34
+ "injected": true
35
+ }
23
36
  },
24
37
  "dependencies": {
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",
38
+ "@ember-data/canary-features": "workspace:4.8.0",
39
+ "@ember-data/private-build-infra": "workspace:4.8.0",
28
40
  "@ember/edition-utils": "^1.2.0",
29
- "@ember/string": "^3.0.0",
30
- "@embroider/macros": "^1.8.3",
31
- "ember-auto-import": "^2.4.2",
32
- "ember-cached-decorator-polyfill": "^0.1.4",
41
+ "@embroider/macros": "^1.9.0",
42
+ "ember-auto-import": "^2.4.3",
43
+ "ember-cached-decorator-polyfill": "^1.0.1",
33
44
  "ember-cli-babel": "^7.26.11",
34
45
  "ember-cli-string-utils": "^1.1.0",
35
46
  "ember-cli-test-info": "^1.0.0",
36
- "ember-cli-typescript": "^5.1.0",
37
47
  "ember-compatibility-helpers": "^1.2.6",
38
- "inflection": "~1.13.2"
48
+ "inflection": "~1.13.4"
39
49
  },
40
50
  "devDependencies": {
41
- "@ember-data/unpublished-test-infra": "4.8.0-alpha.6",
42
- "@ember/optional-features": "^2.0.0",
43
- "@ember/test-helpers": "~2.7.0",
44
- "broccoli-asset-rev": "^3.0.0",
45
- "ember-cli": "~4.6.0",
46
- "ember-cli-blueprint-test-helpers": "^0.19.2",
47
- "ember-cli-dependency-checker": "^3.3.1",
48
- "ember-cli-htmlbars": "^6.1.0",
49
- "ember-cli-inject-live-reload": "^2.1.0",
50
- "ember-cli-sri": "^2.1.1",
51
- "ember-cli-terser": "~4.0.2",
52
- "ember-disable-prototype-extensions": "^1.1.3",
53
- "ember-export-application-global": "^2.0.1",
54
- "ember-load-initializers": "^2.1.2",
55
- "ember-maybe-import-regenerator": "^1.0.0",
56
- "ember-qunit": "^5.1.5",
57
- "ember-resolver": "^8.0.3",
58
- "ember-source": "~4.6.0",
59
- "ember-source-channel-url": "^3.0.0",
60
- "ember-try": "^2.0.0",
61
- "loader.js": "^4.7.0",
62
- "qunit": "^2.19.1",
63
- "qunit-dom": "^2.0.0",
64
- "silent-error": "^1.1.1",
51
+ "@babel/core": "^7.19.6",
52
+ "@glimmer/component": "^1.1.2",
53
+ "ember-source": "~4.8.0",
65
54
  "webpack": "^5.74.0"
66
55
  },
67
56
  "engines": {
68
57
  "node": "^14.8.0 || 16.* || >= 18.*"
69
58
  },
70
- "ember-addon": {
71
- "configPath": "tests/dummy/config"
72
- },
59
+ "ember-addon": {},
73
60
  "volta": {
74
- "node": "16.17.0",
75
- "yarn": "1.22.19"
76
- }
61
+ "extends": "../../package.json"
62
+ },
63
+ "packageManager": "pnpm@7.14.1"
77
64
  }
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = function (/* environment, appConfig */) {
4
- return {};
5
- };