@ember-data/model 4.8.0-alpha.4 → 4.8.0-beta.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,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,12 +8,13 @@ import { resolve } from 'rsvp';
7
8
 
8
9
  import { ManyArray } from 'ember-data/-private';
9
10
 
10
- import type { ManyRelationship } from '@ember-data/record-data/-private';
11
+ import { DEPRECATE_PROMISE_PROXIES } from '@ember-data/private-build-infra/deprecations';
12
+ import type { Graph } from '@ember-data/record-data/-private/graph/graph';
13
+ import type ManyRelationship from '@ember-data/record-data/-private/relationships/state/has-many';
11
14
  import type Store from '@ember-data/store';
12
15
  import { recordIdentifierFor } from '@ember-data/store';
13
16
  import { assertPolymorphicType } from '@ember-data/store/-debug';
14
17
  import type { NotificationType } from '@ember-data/store/-private/managers/record-notification-manager';
15
- import type { DebugWeakCache } from '@ember-data/store/-private/utils/weak-cache';
16
18
  import type {
17
19
  CollectionResourceDocument,
18
20
  CollectionResourceRelationship,
@@ -53,6 +55,7 @@ function isResourceIdentiferWithRelatedLinks(
53
55
  @extends Reference
54
56
  */
55
57
  export default class HasManyReference {
58
+ declare graph: Graph;
56
59
  declare key: string;
57
60
  declare hasManyRelationship: ManyRelationship;
58
61
  declare type: string;
@@ -67,10 +70,12 @@ export default class HasManyReference {
67
70
 
68
71
  constructor(
69
72
  store: Store,
73
+ graph: Graph,
70
74
  parentIdentifier: StableRecordIdentifier,
71
75
  hasManyRelationship: ManyRelationship,
72
76
  key: string
73
77
  ) {
78
+ this.graph = graph;
74
79
  this.key = key;
75
80
  this.hasManyRelationship = hasManyRelationship;
76
81
  this.type = hasManyRelationship.definition.type;
@@ -394,7 +399,25 @@ export default class HasManyReference {
394
399
  async push(
395
400
  objectOrPromise: ExistingResourceObject[] | CollectionResourceDocument | { data: SingleResourceDocument[] }
396
401
  ): Promise<ManyArray> {
397
- 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
+ }
398
421
  let array: Array<ExistingResourceObject | SingleResourceDocument>;
399
422
 
400
423
  if (!Array.isArray(payload) && typeof payload === 'object' && Array.isArray(payload.data)) {
@@ -424,9 +447,9 @@ export default class HasManyReference {
424
447
  return recordIdentifierFor(record);
425
448
  });
426
449
 
427
- const { graph, identifier } = this.hasManyRelationship;
428
- store._backburner.join(() => {
429
- graph.push({
450
+ const { identifier } = this.hasManyRelationship;
451
+ store._join(() => {
452
+ this.graph.push({
430
453
  op: 'replaceRelatedRecords',
431
454
  record: identifier,
432
455
  field: this.key,
@@ -443,9 +466,9 @@ export default class HasManyReference {
443
466
  return false;
444
467
  }
445
468
 
446
- let members = this.hasManyRelationship.currentState;
469
+ let localState = this.hasManyRelationship.localState;
447
470
 
448
- return members.every((identifier) => {
471
+ return localState.every((identifier) => {
449
472
  return this.store._instanceCache.recordIsLoaded(identifier, true) === true;
450
473
  });
451
474
  }
@@ -492,9 +515,9 @@ export default class HasManyReference {
492
515
  @return {ManyArray}
493
516
  */
494
517
  value() {
495
- const support: LegacySupport = (
496
- LEGACY_SUPPORT as DebugWeakCache<StableRecordIdentifier, LegacySupport>
497
- ).getWithError(this.___identifier);
518
+ const support: LegacySupport = (LEGACY_SUPPORT as Map<StableRecordIdentifier, LegacySupport>).get(
519
+ this.___identifier
520
+ )!;
498
521
 
499
522
  return this._isLoaded() ? support.getManyArray(this.key) : null;
500
523
  }
@@ -564,9 +587,9 @@ export default class HasManyReference {
564
587
  this has-many relationship.
565
588
  */
566
589
  async load(options?: FindOptions): Promise<ManyArray> {
567
- const support: LegacySupport = (
568
- LEGACY_SUPPORT as DebugWeakCache<StableRecordIdentifier, LegacySupport>
569
- ).getWithError(this.___identifier);
590
+ const support: LegacySupport = (LEGACY_SUPPORT as Map<StableRecordIdentifier, LegacySupport>).get(
591
+ this.___identifier
592
+ )!;
570
593
  return support.getHasMany(this.key, options) as Promise<ManyArray> | ManyArray; // this cast is necessary because typescript does not work properly with custom thenables;
571
594
  }
572
595
 
@@ -621,9 +644,9 @@ export default class HasManyReference {
621
644
  @return {Promise} a promise that resolves with the ManyArray in this has-many relationship.
622
645
  */
623
646
  reload(options?: FindOptions) {
624
- const support: LegacySupport = (
625
- LEGACY_SUPPORT as DebugWeakCache<StableRecordIdentifier, LegacySupport>
626
- ).getWithError(this.___identifier);
647
+ const support: LegacySupport = (LEGACY_SUPPORT as Map<StableRecordIdentifier, LegacySupport>).get(
648
+ this.___identifier
649
+ )!;
627
650
  return support.reloadHasMany(this.key, options);
628
651
  }
629
652
  }
@@ -75,7 +75,9 @@ class RelationshipDefinition implements RelationshipSchema {
75
75
 
76
76
  if (shouldFindInverse(this.meta)) {
77
77
  inverse = modelClass.inverseFor(this.key, store);
78
- } else if (DEBUG) {
78
+ }
79
+ // TODO make this error again for the non-polymorphic case
80
+ if (DEBUG && !this.options.polymorphic) {
79
81
  modelClass.typeForRelationship(this.key, store);
80
82
  }
81
83
 
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.4",
3
+ "version": "4.8.0-beta.0",
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.4",
26
- "@ember-data/private-build-infra": "4.8.0-alpha.4",
27
- "@ember-data/store": "4.8.0-alpha.4",
25
+ "@ember-data/canary-features": "4.8.0-beta.0",
26
+ "@ember-data/private-build-infra": "4.8.0-beta.0",
27
+ "@ember-data/store": "4.8.0-beta.0",
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.4",
41
+ "@ember-data/unpublished-test-infra": "4.8.0-beta.0",
42
42
  "@ember/optional-features": "^2.0.0",
43
43
  "@ember/test-helpers": "~2.7.0",
44
44
  "broccoli-asset-rev": "^3.0.0",
@@ -71,7 +71,7 @@
71
71
  "configPath": "tests/dummy/config"
72
72
  },
73
73
  "volta": {
74
- "node": "16.16.0",
74
+ "node": "16.17.0",
75
75
  "yarn": "1.22.19"
76
76
  }
77
77
  }