@ember-data/store 4.2.0-alpha.0 → 4.2.0-alpha.4

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.
@@ -4,7 +4,6 @@
4
4
  import { assert } from '@ember/debug';
5
5
  import { get } from '@ember/object';
6
6
 
7
- import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
8
7
  import { HAS_RECORD_DATA_PACKAGE } from '@ember-data/private-build-infra';
9
8
 
10
9
  import type { DSModel, DSModelSchema, ModelSchema } from '../ts-interfaces/ds-model';
@@ -65,10 +64,9 @@ export default class Snapshot implements Snapshot {
65
64
  let internalModel = (this._internalModel = _store._internalModelForResource(identifier));
66
65
  this.modelName = identifier.type;
67
66
 
68
- if (CUSTOM_MODEL_CLASS) {
69
- // TODO add public docs once this FF is on
70
- this.identifier = identifier;
71
- }
67
+ // TODO add public docs once this FF is on
68
+ this.identifier = identifier;
69
+
72
70
  /*
73
71
  If the internalModel does not yet have a record, then we are
74
72
  likely a snapshot being provided to a find request, so we
@@ -151,26 +149,15 @@ export default class Snapshot implements Snapshot {
151
149
  }
152
150
  let record = this.record;
153
151
  let attributes = (this.__attributes = Object.create(null));
154
- let attrs: string[];
155
-
156
- if (CUSTOM_MODEL_CLASS) {
157
- attrs = Object.keys(this._store._attributesDefinitionFor(this.modelName, this.identifier));
158
- } else {
159
- attrs = Object.keys(this._store._attributesDefinitionFor(this.modelName));
160
- }
161
- if (CUSTOM_MODEL_CLASS) {
162
- attrs.forEach((keyName) => {
163
- if (schemaIsDSModel(this.type)) {
164
- // if the schema is for a DSModel then the instance is too
165
- attributes[keyName] = get(record as DSModel, keyName);
166
- } else {
167
- attributes[keyName] = recordDataFor(this._internalModel).getAttr(keyName);
168
- }
169
- });
170
- } else {
171
- // When CUSTOM_MODEL_CLASS is false `record` must be DSModel
172
- (record as DSModel).eachAttribute((keyName) => (attributes[keyName] = get(record as DSModel, keyName)));
173
- }
152
+ let attrs = Object.keys(this._store._attributesDefinitionFor(this.modelName, this.identifier));
153
+ attrs.forEach((keyName) => {
154
+ if (schemaIsDSModel(this.type)) {
155
+ // if the schema is for a DSModel then the instance is too
156
+ attributes[keyName] = get(record as DSModel, keyName);
157
+ } else {
158
+ attributes[keyName] = recordDataFor(this._internalModel).getAttr(keyName);
159
+ }
160
+ });
174
161
 
175
162
  return attributes;
176
163
  }
@@ -187,9 +174,6 @@ export default class Snapshot implements Snapshot {
187
174
  }
188
175
 
189
176
  get isNew(): boolean {
190
- if (!CUSTOM_MODEL_CLASS) {
191
- throw new Error('isNew is only available when custom model class ff is on');
192
- }
193
177
  return this._internalModel.isNew();
194
178
  }
195
179
 
@@ -333,7 +317,7 @@ export default class Snapshot implements Snapshot {
333
317
  }
334
318
 
335
319
  const graphFor = require('@ember-data/record-data/-private').graphFor;
336
- const { identifier } = CUSTOM_MODEL_CLASS ? this : this._internalModel;
320
+ const { identifier } = this;
337
321
  const relationship = graphFor(this._store._storeWrapper).get(identifier, keyName);
338
322
 
339
323
  assert(
@@ -432,7 +416,7 @@ export default class Snapshot implements Snapshot {
432
416
  }
433
417
 
434
418
  const graphFor = require('@ember-data/record-data/-private').graphFor;
435
- const { identifier } = CUSTOM_MODEL_CLASS ? this : this._internalModel;
419
+ const { identifier } = this;
436
420
  const relationship = graphFor(this._store._storeWrapper).get(identifier, keyName);
437
421
  assert(
438
422
  `You looked up the ${keyName} hasMany relationship for { type: ${identifier.type}, id: ${identifier.id}, lid: ${identifier.lid} but no such relationship was found.`,
@@ -488,15 +472,10 @@ export default class Snapshot implements Snapshot {
488
472
  @public
489
473
  */
490
474
  eachAttribute(callback: (key: string, meta: AttributeSchema) => void, binding?: unknown): void {
491
- if (CUSTOM_MODEL_CLASS) {
492
- let attrDefs = this._store._attributesDefinitionFor(this.modelName, this.identifier);
493
- Object.keys(attrDefs).forEach((key) => {
494
- callback.call(binding, key, attrDefs[key] as AttributeSchema);
495
- });
496
- } else {
497
- // in the non CUSTOM_MODEL_CLASS world we only have DSModel instances
498
- (this.record as DSModel).eachAttribute(callback, binding);
499
- }
475
+ let attrDefs = this._store._attributesDefinitionFor(this.modelName, this.identifier);
476
+ Object.keys(attrDefs).forEach((key) => {
477
+ callback.call(binding, key, attrDefs[key] as AttributeSchema);
478
+ });
500
479
  }
501
480
 
502
481
  /**
@@ -517,15 +496,10 @@ export default class Snapshot implements Snapshot {
517
496
  @public
518
497
  */
519
498
  eachRelationship(callback: (key: string, meta: RelationshipSchema) => void, binding?: unknown): void {
520
- if (CUSTOM_MODEL_CLASS) {
521
- let relationshipDefs = this._store._relationshipsDefinitionFor(this.modelName, this.identifier);
522
- Object.keys(relationshipDefs).forEach((key) => {
523
- callback.call(binding, key, relationshipDefs[key] as RelationshipSchema);
524
- });
525
- } else {
526
- // in the non CUSTOM_MODEL_CLASS world we only have DSModel instances
527
- (this.record as DSModel).eachRelationship(callback, binding);
528
- }
499
+ let relationshipDefs = this._store._relationshipsDefinitionFor(this.modelName, this.identifier);
500
+ Object.keys(relationshipDefs).forEach((key) => {
501
+ callback.call(binding, key, relationshipDefs[key] as RelationshipSchema);
502
+ });
529
503
  }
530
504
 
531
505
  /**
@@ -1,11 +1,8 @@
1
- import { assert, deprecate, warn } from '@ember/debug';
1
+ import { assert, deprecate } from '@ember/debug';
2
2
  import { DEBUG } from '@glimmer/env';
3
3
 
4
4
  import { Promise } from 'rsvp';
5
5
 
6
- import { REQUEST_SERVICE } from '@ember-data/canary-features';
7
-
8
- import coerceId from '../coerce-id';
9
6
  import { _bind, _guard, _objectIsAlive, guardDestroyedStore } from './common';
10
7
  import { normalizeResponseHelper } from './serializer-response';
11
8
 
@@ -21,60 +18,7 @@ function payloadIsNotBlank(adapterPayload) {
21
18
  }
22
19
  }
23
20
 
24
- export function _find(adapter, store, modelClass, id, internalModel, options) {
25
- if (REQUEST_SERVICE) {
26
- assert(`Requests made when REQUEST_SERVICE=true should not use the legacy finders`);
27
- }
28
- let snapshot = internalModel.createSnapshot(options);
29
- let { modelName } = internalModel;
30
- let promise = Promise.resolve().then(() => {
31
- return adapter.findRecord(store, modelClass, id, snapshot);
32
- });
33
- let label = `DS: Handle Adapter#findRecord of '${modelName}' with id: '${id}'`;
34
- const { identifier } = internalModel;
35
-
36
- promise = guardDestroyedStore(promise, store, label);
37
-
38
- return promise.then(
39
- (adapterPayload) => {
40
- assert(
41
- `You made a 'findRecord' request for a '${modelName}' with id '${id}', but the adapter's response did not have any data`,
42
- payloadIsNotBlank(adapterPayload)
43
- );
44
- let serializer = store.serializerFor(modelName);
45
- let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, id, 'findRecord');
46
- assert(
47
- `Ember Data expected the primary data returned from a 'findRecord' response to be an object but instead it found an array.`,
48
- !Array.isArray(payload.data)
49
- );
50
- assert(
51
- `The 'findRecord' request for ${modelName}:${id} resolved indicating success but contained no primary data. To indicate a 404 not found you should either reject the promise returned by the adapter's findRecord method or throw a NotFoundError.`,
52
- 'data' in payload && payload.data !== null && typeof payload.data === 'object'
53
- );
54
- warn(
55
- `You requested a record of type '${modelName}' with id '${id}' but the adapter returned a payload with primary data having an id of '${payload.data.id}'. Use 'store.findRecord()' when the requested id is the same as the one returned by the adapter. In other cases use 'store.queryRecord()' instead.`,
56
- coerceId(payload.data.id) === coerceId(id),
57
- {
58
- id: 'ds.store.findRecord.id-mismatch',
59
- }
60
- );
61
-
62
- // ensure that regardless of id returned we assign to the correct record
63
- payload.data.lid = identifier.lid;
64
-
65
- return store._push(payload);
66
- },
67
- (error) => {
68
- internalModel.send('notFound');
69
- if (internalModel.currentState.isEmpty) {
70
- internalModel.unloadRecord();
71
- }
72
-
73
- throw error;
74
- },
75
- `DS: Extract payload of '${modelName}'`
76
- );
77
- }
21
+ export function _find() {}
78
22
 
79
23
  export function _findMany(adapter, store, modelName, ids, internalModels, optionsMap) {
80
24
  let snapshots = internalModels.map((internalModel) => internalModel.createSnapshot(optionsMap.get(internalModel)));
@@ -1,4 +1,3 @@
1
- import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
2
1
  import type { RelationshipDefinition } from '@ember-data/model/-private/system/relationships/relationship-meta';
3
2
  import { HAS_RECORD_DATA_PACKAGE } from '@ember-data/private-build-infra';
4
3
 
@@ -118,16 +117,13 @@ export default class RecordDataStoreWrapper implements StoreWrapper {
118
117
  if (!definition) {
119
118
  return null;
120
119
  }
121
- if (CUSTOM_MODEL_CLASS) {
122
- if (metaIsRelationshipDefinition(definition)) {
123
- return definition._inverseKey(this._store, modelClass);
124
- } else if (definition.options && definition.options.inverse !== undefined) {
125
- return definition.options.inverse;
126
- } else {
127
- return null;
128
- }
120
+
121
+ if (metaIsRelationshipDefinition(definition)) {
122
+ return definition._inverseKey(this._store, modelClass);
123
+ } else if (definition.options && definition.options.inverse !== undefined) {
124
+ return definition.options.inverse;
129
125
  } else {
130
- return (definition as RelationshipDefinition)._inverseKey(this._store, modelClass);
126
+ return null;
131
127
  }
132
128
  }
133
129
 
@@ -137,21 +133,18 @@ export default class RecordDataStoreWrapper implements StoreWrapper {
137
133
  if (!definition) {
138
134
  return false;
139
135
  }
140
- if (CUSTOM_MODEL_CLASS) {
141
- if (definition.options && definition.options.inverse === null) {
142
- return false;
143
- }
144
- if ((definition as unknown as { inverseIsAsync?: boolean }).inverseIsAsync !== undefined) {
145
- // TODO do we need to amend the RFC for this prop?
146
- // else we should add it to the TS interface and document.
147
- return !!(definition as unknown as { inverseIsAsync: boolean }).inverseIsAsync;
148
- } else if (metaIsRelationshipDefinition(definition)) {
149
- return definition._inverseIsAsync(this._store, modelClass);
150
- } else {
151
- return false;
152
- }
136
+
137
+ if (definition.options && definition.options.inverse === null) {
138
+ return false;
139
+ }
140
+ if ((definition as unknown as { inverseIsAsync?: boolean }).inverseIsAsync !== undefined) {
141
+ // TODO do we need to amend the RFC for this prop?
142
+ // else we should add it to the TS interface and document.
143
+ return !!(definition as unknown as { inverseIsAsync: boolean }).inverseIsAsync;
144
+ } else if (metaIsRelationshipDefinition(definition)) {
145
+ return definition._inverseIsAsync(this._store, modelClass);
153
146
  } else {
154
- return (definition as RelationshipDefinition)._inverseIsAsync(this._store, modelClass);
147
+ return false;
155
148
  }
156
149
  }
157
150
 
@@ -17,6 +17,7 @@ export interface DSModel extends RecordInstance, EmberObject {
17
17
  isDeleted: boolean;
18
18
  deleteRecord(): void;
19
19
  unloadRecord(): void;
20
+ errors: any;
20
21
  }
21
22
 
22
23
  // Implemented by both ShimModelClass and DSModel
@@ -1,7 +1,11 @@
1
+ import type { Dict } from '@ember-data/store/-private/ts-interfaces/utils';
2
+
1
3
  import type { RecordIdentifier } from './identifier';
2
4
 
3
5
  export interface Operation {
4
6
  op: string;
7
+ options: Dict<unknown> | undefined;
8
+ recordIdentifier: RecordIdentifier;
5
9
  }
6
10
 
7
11
  export interface FindRecordQuery extends Operation {
package/index.js CHANGED
@@ -10,6 +10,8 @@ module.exports = Object.assign({}, addonBaseConfig, {
10
10
  shouldRollupPrivate: true,
11
11
  externalDependenciesForPrivateModule() {
12
12
  return [
13
+ 'ember-cached-decorator-polyfill',
14
+
13
15
  '@ember-data/canary-features',
14
16
  '@ember-data/store/-debug',
15
17
 
@@ -23,6 +25,7 @@ module.exports = Object.assign({}, addonBaseConfig, {
23
25
  '@ember/object/evented',
24
26
  '@ember/object/internals',
25
27
  '@ember/object/mixin',
28
+ '@ember/object/compat',
26
29
  '@ember/object/promise-proxy-mixin',
27
30
  '@ember/object/proxy',
28
31
  '@ember/polyfills',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/store",
3
- "version": "4.2.0-alpha.0",
3
+ "version": "4.2.0-alpha.4",
4
4
  "description": "The default blueprint for ember-cli addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -17,35 +17,36 @@
17
17
  "start": "ember serve"
18
18
  },
19
19
  "dependencies": {
20
- "@ember-data/canary-features": "4.2.0-alpha.0",
21
- "@ember-data/private-build-infra": "4.2.0-alpha.0",
20
+ "@ember-data/canary-features": "4.2.0-alpha.4",
21
+ "@ember-data/private-build-infra": "4.2.0-alpha.4",
22
22
  "@ember/string": "^3.0.0",
23
23
  "@glimmer/tracking": "^1.0.4",
24
24
  "ember-auto-import": "^2.2.4",
25
+ "ember-cached-decorator-polyfill": "^0.1.4",
25
26
  "ember-cli-babel": "^7.26.6",
26
27
  "ember-cli-path-utils": "^1.0.0",
27
28
  "ember-cli-typescript": "^4.1.0"
28
29
  },
29
30
  "devDependencies": {
30
- "@ember-data/unpublished-test-infra": "4.2.0-alpha.0",
31
+ "@ember-data/unpublished-test-infra": "4.2.0-alpha.4",
31
32
  "@ember/optional-features": "^2.0.0",
32
33
  "@ember/test-helpers": "^2.6.0",
33
34
  "@types/ember": "^3.16.5",
34
35
  "@types/rsvp": "^4.0.3",
35
36
  "broccoli-asset-rev": "^3.0.0",
36
- "ember-cli": "~3.26.1",
37
+ "ember-cli": "~4.0.1",
37
38
  "ember-cli-dependency-checker": "^3.2.0",
38
- "ember-cli-htmlbars": "^5.1.2",
39
+ "ember-cli-htmlbars": "^6.0.1",
39
40
  "ember-cli-inject-live-reload": "^2.0.2",
40
41
  "ember-cli-sri": "^2.1.1",
41
42
  "ember-cli-terser": "~4.0.1",
42
43
  "ember-disable-prototype-extensions": "^1.1.3",
43
44
  "ember-export-application-global": "^2.0.1",
44
45
  "ember-load-initializers": "^2.1.1",
45
- "ember-maybe-import-regenerator": "^0.1.6",
46
+ "ember-maybe-import-regenerator": "^1.0.0",
46
47
  "ember-qunit": "^5.1.5",
47
- "ember-resolver": "^8.0.0",
48
- "ember-source": "~3.28.6",
48
+ "ember-resolver": "^8.0.3",
49
+ "ember-source": "~4.0.0",
49
50
  "ember-source-channel-url": "^3.0.0",
50
51
  "ember-try": "^1.4.0",
51
52
  "loader.js": "^4.7.0",