@ember-data/serializer 4.5.0-beta.0 → 4.7.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.
@@ -212,7 +212,8 @@ export default Mixin.create({
212
212
  let includeRecords = this.hasSerializeRecordsOption(attr);
213
213
  let embeddedSnapshot = snapshot.belongsTo(attr);
214
214
  if (includeIds) {
215
- let serializedKey = this._getMappedKey(relationship.key, snapshot.type);
215
+ let schema = this.store.modelFor(snapshot.modelName);
216
+ let serializedKey = this._getMappedKey(relationship.key, schema);
216
217
  if (serializedKey === relationship.key && this.keyForRelationship) {
217
218
  serializedKey = this.keyForRelationship(relationship.key, relationship.kind, 'serialize');
218
219
  }
@@ -233,7 +234,8 @@ export default Mixin.create({
233
234
 
234
235
  _serializeEmbeddedBelongsTo(snapshot, json, relationship) {
235
236
  let embeddedSnapshot = snapshot.belongsTo(relationship.key);
236
- let serializedKey = this._getMappedKey(relationship.key, snapshot.type);
237
+ let schema = this.store.modelFor(snapshot.modelName);
238
+ let serializedKey = this._getMappedKey(relationship.key, schema);
237
239
  if (serializedKey === relationship.key && this.keyForRelationship) {
238
240
  serializedKey = this.keyForRelationship(relationship.key, relationship.kind, 'serialize');
239
241
  }
@@ -396,7 +398,8 @@ export default Mixin.create({
396
398
  }
397
399
 
398
400
  if (this.hasSerializeIdsOption(attr)) {
399
- let serializedKey = this._getMappedKey(relationship.key, snapshot.type);
401
+ let schema = this.store.modelFor(snapshot.modelName);
402
+ let serializedKey = this._getMappedKey(relationship.key, schema);
400
403
  if (serializedKey === relationship.key && this.keyForRelationship) {
401
404
  serializedKey = this.keyForRelationship(relationship.key, relationship.kind, 'serialize');
402
405
  }
@@ -433,7 +436,8 @@ export default Mixin.create({
433
436
  },
434
437
 
435
438
  _serializeEmbeddedHasMany(snapshot, json, relationship) {
436
- let serializedKey = this._getMappedKey(relationship.key, snapshot.type);
439
+ let schema = this.store.modelFor(snapshot.modelName);
440
+ let serializedKey = this._getMappedKey(relationship.key, schema);
437
441
  if (serializedKey === relationship.key && this.keyForRelationship) {
438
442
  serializedKey = this.keyForRelationship(relationship.key, relationship.kind, 'serialize');
439
443
  }
@@ -484,7 +488,8 @@ export default Mixin.create({
484
488
  */
485
489
  removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json) {
486
490
  if (relationship.kind === 'belongsTo') {
487
- let parentRecord = snapshot.type.inverseFor(relationship.key, this.store);
491
+ let schema = this.store.modelFor(snapshot.modelName);
492
+ let parentRecord = schema.inverseFor(relationship.key, this.store);
488
493
  if (parentRecord) {
489
494
  let name = parentRecord.name;
490
495
  let embeddedSerializer = this.store.serializerFor(embeddedSnapshot.modelName);
package/addon/index.ts CHANGED
@@ -100,6 +100,9 @@
100
100
  */
101
101
 
102
102
  import EmberObject from '@ember/object';
103
+ import { inject as service } from '@ember/service';
104
+
105
+ import type Store from '@ember-data/store';
103
106
 
104
107
  /**
105
108
  `Serializer` is an abstract base class that you should override in your
@@ -121,7 +124,8 @@ import EmberObject from '@ember/object';
121
124
  @extends Ember.EmberObject
122
125
  */
123
126
 
124
- export default EmberObject.extend({
127
+ export default class extends EmberObject {
128
+ @service declare store: Store;
125
129
  /**
126
130
  The `store` property is the application's `store` that contains
127
131
  all records. It can be used to look up serializers for other model
@@ -179,7 +183,6 @@ export default EmberObject.extend({
179
183
  @param {String} requestType
180
184
  @return {Object} JSON-API Document
181
185
  */
182
- normalizeResponse: null,
183
186
 
184
187
  /**
185
188
  The `serialize` method is used when a record is saved in order to convert
@@ -222,7 +225,6 @@ export default EmberObject.extend({
222
225
  @param {Object} [options]
223
226
  @return {Object}
224
227
  */
225
- serialize: null,
226
228
 
227
229
  /**
228
230
  The `normalize` method is used to convert a payload received from your
@@ -253,5 +255,5 @@ export default EmberObject.extend({
253
255
  */
254
256
  normalize(typeClass, hash) {
255
257
  return hash;
256
- },
257
- });
258
+ }
259
+ }
package/addon/json-api.js CHANGED
@@ -187,16 +187,14 @@ const JSONAPISerializer = JSONSerializer.extend({
187
187
  @private
188
188
  */
189
189
  _normalizeResourceHelper(resourceHash) {
190
- assert(this.warnMessageForUndefinedType(), !isNone(resourceHash.type), {
191
- id: 'ds.serializer.type-is-undefined',
192
- });
190
+ assert(this.warnMessageForUndefinedType(), !isNone(resourceHash.type));
193
191
 
194
192
  let modelName, usedLookup;
195
193
 
196
194
  modelName = this.modelNameFromPayloadKey(resourceHash.type);
197
195
  usedLookup = 'modelNameFromPayloadKey';
198
196
 
199
- if (!this.store._hasModelFor(modelName)) {
197
+ if (!this.store.getSchemaDefinitionService().doesTypeExist(modelName)) {
200
198
  warn(this.warnMessageNoModelForType(modelName, resourceHash.type, usedLookup), false, {
201
199
  id: 'ds.serializer.model-for-type-missing',
202
200
  });
@@ -243,10 +241,7 @@ const JSONAPISerializer = JSONSerializer.extend({
243
241
 
244
242
  assert(
245
243
  'Expected the primary data returned by the serializer for a `queryRecord` response to be a single object but instead it was an array.',
246
- !Array.isArray(normalized.data),
247
- {
248
- id: 'ds.serializer.json-api.queryRecord-array-response',
249
- }
244
+ !Array.isArray(normalized.data)
250
245
  );
251
246
 
252
247
  return normalized;
@@ -536,7 +531,7 @@ const JSONAPISerializer = JSONSerializer.extend({
536
531
  return data formatted to match your API's expectations, or override
537
532
  the invoked adapter method and do the serialization in the adapter directly
538
533
  by using the provided snapshot.
539
-
534
+
540
535
  If your API's format differs greatly from the JSON:API spec, you should
541
536
  consider authoring your own adapter and serializer instead of extending
542
537
  this class.
@@ -659,7 +654,8 @@ const JSONAPISerializer = JSONSerializer.extend({
659
654
  value = transform.serialize(value, attribute.options);
660
655
  }
661
656
 
662
- let payloadKey = this._getMappedKey(key, snapshot.type);
657
+ let schema = this.store.modelFor(snapshot.modelName);
658
+ let payloadKey = this._getMappedKey(key, schema);
663
659
 
664
660
  if (payloadKey === key) {
665
661
  payloadKey = this.keyForAttribute(key, 'serialize');
@@ -679,7 +675,8 @@ const JSONAPISerializer = JSONSerializer.extend({
679
675
  if (belongsTo === null || belongsToIsNotNew) {
680
676
  json.relationships = json.relationships || {};
681
677
 
682
- let payloadKey = this._getMappedKey(key, snapshot.type);
678
+ let schema = this.store.modelFor(snapshot.modelName);
679
+ let payloadKey = this._getMappedKey(key, schema);
683
680
  if (payloadKey === key) {
684
681
  payloadKey = this.keyForRelationship(key, 'belongsTo', 'serialize');
685
682
  }
@@ -707,7 +704,8 @@ const JSONAPISerializer = JSONSerializer.extend({
707
704
  if (hasMany !== undefined) {
708
705
  json.relationships = json.relationships || {};
709
706
 
710
- let payloadKey = this._getMappedKey(key, snapshot.type);
707
+ let schema = this.store.modelFor(snapshot.modelName);
708
+ let payloadKey = this._getMappedKey(key, schema);
711
709
  if (payloadKey === key && this.keyForRelationship) {
712
710
  payloadKey = this.keyForRelationship(key, 'hasMany', 'serialize');
713
711
  }
@@ -739,10 +737,7 @@ if (DEBUG) {
739
737
 
740
738
  assert(
741
739
  `You've used the EmbeddedRecordsMixin in ${this.toString()} which is not fully compatible with the JSON:API specification. Please confirm that this works for your specific API and add \`this.isEmbeddedRecordsMixinCompatible = true\` to your serializer.`,
742
- !this.isEmbeddedRecordsMixin || this.isEmbeddedRecordsMixinCompatible === true,
743
- {
744
- id: 'ds.serializer.embedded-records-mixin-not-supported',
745
- }
740
+ !this.isEmbeddedRecordsMixin || this.isEmbeddedRecordsMixinCompatible === true
746
741
  );
747
742
 
748
743
  let constructor = this.constructor;
package/addon/json.js CHANGED
@@ -938,7 +938,8 @@ const JSONSerializer = Serializer.extend({
938
938
  @return {boolean} true if the hasMany relationship should be serialized
939
939
  */
940
940
  shouldSerializeHasMany(snapshot, key, relationship) {
941
- let relationshipType = snapshot.type.determineRelationshipType(relationship, this.store);
941
+ const schema = this.store.modelFor(snapshot.modelName);
942
+ let relationshipType = schema.determineRelationshipType(relationship, this.store);
942
943
  if (this._mustSerialize(key)) {
943
944
  return true;
944
945
  }
@@ -1194,7 +1195,8 @@ const JSONSerializer = Serializer.extend({
1194
1195
 
1195
1196
  // if provided, use the mapping provided by `attrs` in
1196
1197
  // the serializer
1197
- let payloadKey = this._getMappedKey(key, snapshot.type);
1198
+ let schema = this.store.modelFor(snapshot.modelName);
1199
+ let payloadKey = this._getMappedKey(key, schema);
1198
1200
 
1199
1201
  if (payloadKey === key && this.keyForAttribute) {
1200
1202
  payloadKey = this.keyForAttribute(key, 'serialize');
@@ -1240,7 +1242,8 @@ const JSONSerializer = Serializer.extend({
1240
1242
 
1241
1243
  // if provided, use the mapping provided by `attrs` in
1242
1244
  // the serializer
1243
- let payloadKey = this._getMappedKey(key, snapshot.type);
1245
+ let schema = this.store.modelFor(snapshot.modelName);
1246
+ let payloadKey = this._getMappedKey(key, schema);
1244
1247
  if (payloadKey === key && this.keyForRelationship) {
1245
1248
  payloadKey = this.keyForRelationship(key, 'belongsTo', 'serialize');
1246
1249
  }
@@ -1293,7 +1296,8 @@ const JSONSerializer = Serializer.extend({
1293
1296
  if (hasMany !== undefined) {
1294
1297
  // if provided, use the mapping provided by `attrs` in
1295
1298
  // the serializer
1296
- let payloadKey = this._getMappedKey(key, snapshot.type);
1299
+ let schema = this.store.modelFor(snapshot.modelName);
1300
+ let payloadKey = this._getMappedKey(key, schema);
1297
1301
  if (payloadKey === key && this.keyForRelationship) {
1298
1302
  payloadKey = this.keyForRelationship(key, 'hasMany', 'serialize');
1299
1303
  }
package/addon/rest.js CHANGED
@@ -202,7 +202,7 @@ const RESTSerializer = JSONSerializer.extend({
202
202
  // Support polymorphic records in async relationships
203
203
  let modelName = this.modelNameFromPayloadKey(hash.type);
204
204
 
205
- if (store._hasModelFor(modelName)) {
205
+ if (store.getSchemaDefinitionService().doesTypeExist(modelName)) {
206
206
  serializer = store.serializerFor(modelName);
207
207
  modelClass = store.modelFor(modelName);
208
208
  }
@@ -270,7 +270,7 @@ const RESTSerializer = JSONSerializer.extend({
270
270
  }
271
271
 
272
272
  var typeName = this.modelNameFromPayloadKey(modelName);
273
- if (!store._hasModelFor(typeName)) {
273
+ if (!store.getSchemaDefinitionService().doesTypeExist(typeName)) {
274
274
  warn(this.warnMessageNoModelForKey(modelName, typeName), false, {
275
275
  id: 'ds.serializer.model-for-key-missing',
276
276
  });
@@ -393,7 +393,7 @@ const RESTSerializer = JSONSerializer.extend({
393
393
 
394
394
  for (var prop in payload) {
395
395
  var modelName = this.modelNameFromPayloadKey(prop);
396
- if (!store._hasModelFor(modelName)) {
396
+ if (!store.getSchemaDefinitionService().doesTypeExist(modelName)) {
397
397
  warn(this.warnMessageNoModelForKey(prop, modelName), false, {
398
398
  id: 'ds.serializer.model-for-key-missing',
399
399
  });
@@ -2,6 +2,7 @@ const path = require('path');
2
2
 
3
3
  const testInfo = require('ember-cli-test-info');
4
4
  const useTestFrameworkDetector = require('@ember-data/private-build-infra/src/utilities/test-framework-detector');
5
+ const modulePrefixForProject = require('@ember-data/private-build-infra/src/utilities/module-prefix-for-project');
5
6
 
6
7
  module.exports = useTestFrameworkDetector({
7
8
  description: 'Generates a serializer unit test.',
@@ -22,6 +23,7 @@ module.exports = useTestFrameworkDetector({
22
23
  locals(options) {
23
24
  return {
24
25
  friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Serializer'),
26
+ modulePrefix: modulePrefixForProject(options.project),
25
27
  };
26
28
  },
27
29
  });
@@ -1,6 +1,6 @@
1
1
  import { expect } from 'chai';
2
2
  import { describe, it } from 'mocha';
3
- import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
3
+ import { setupTest } from '<%= modulePrefix %>/tests/helpers';
4
4
 
5
5
  describe('<%= friendlyTestDescription %>', function() {
6
6
  setupTest();
@@ -1,5 +1,5 @@
1
1
  import { module, test } from 'qunit';
2
- import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
2
+ import { setupTest } from '<%= modulePrefix %>/tests/helpers';
3
3
 
4
4
  module('<%= friendlyTestDescription %>', function(hooks) {
5
5
  setupTest(hooks);
@@ -2,6 +2,7 @@ const path = require('path');
2
2
 
3
3
  const testInfo = require('ember-cli-test-info');
4
4
  const useTestFrameworkDetector = require('@ember-data/private-build-infra/src/utilities/test-framework-detector');
5
+ const modulePrefixForProject = require('@ember-data/private-build-infra/src/utilities/module-prefix-for-project');
5
6
 
6
7
  module.exports = useTestFrameworkDetector({
7
8
  description: 'Generates a transform unit test.',
@@ -22,6 +23,7 @@ module.exports = useTestFrameworkDetector({
22
23
  locals(options) {
23
24
  return {
24
25
  friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Transform'),
26
+ modulePrefix: modulePrefixForProject(options.project),
25
27
  };
26
28
  },
27
29
  });
@@ -1,6 +1,6 @@
1
1
  import { expect } from 'chai';
2
2
  import { describe, it } from 'mocha';
3
- import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
3
+ import { setupTest } from '<%= modulePrefix %>/tests/helpers';
4
4
 
5
5
  describe('<%= friendlyTestDescription %>', function() {
6
6
  setupTest();
@@ -1,5 +1,5 @@
1
1
  import { module, test } from 'qunit';
2
- import { setupTest } from '<%= dasherizedPackageName %>/tests/helpers';
2
+ import { setupTest } from '<%= modulePrefix %>/tests/helpers';
3
3
 
4
4
  module('<%= friendlyTestDescription %>', function(hooks) {
5
5
  setupTest(hooks);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/serializer",
3
- "version": "4.5.0-beta.0",
3
+ "version": "4.7.0-beta.0",
4
4
  "description": "The default blueprint for ember-cli addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -18,49 +18,50 @@
18
18
  "test:node": "mocha"
19
19
  },
20
20
  "dependencies": {
21
- "@ember-data/private-build-infra": "4.5.0-beta.0",
22
- "@ember-data/store": "4.5.0-beta.0",
23
- "ember-auto-import": "^2.2.4",
21
+ "@ember-data/private-build-infra": "4.7.0-beta.0",
22
+ "@ember-data/store": "4.7.0-beta.0",
23
+ "ember-auto-import": "^2.4.2",
24
24
  "ember-cli-babel": "^7.26.11",
25
25
  "ember-cli-test-info": "^1.0.0",
26
- "ember-cli-typescript": "^5.0.0"
26
+ "ember-cli-typescript": "^5.1.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@ember-data/unpublished-test-infra": "4.5.0-beta.0",
29
+ "@ember-data/unpublished-test-infra": "4.7.0-beta.0",
30
30
  "@ember/optional-features": "^2.0.0",
31
31
  "@ember/string": "^3.0.0",
32
- "@ember/test-helpers": "^2.6.0",
32
+ "@ember/test-helpers": "~2.7.0",
33
33
  "broccoli-asset-rev": "^3.0.0",
34
- "ember-cli": "~4.3.0",
35
- "ember-cli-blueprint-test-helpers": "^0.19.1",
34
+ "ember-cli": "~4.6.0",
35
+ "ember-cli-blueprint-test-helpers": "^0.19.2",
36
36
  "ember-cli-dependency-checker": "^3.3.1",
37
- "ember-cli-htmlbars": "^6.0.1",
38
- "ember-cli-inject-live-reload": "^2.0.2",
37
+ "ember-cli-htmlbars": "^6.1.0",
38
+ "ember-cli-inject-live-reload": "^2.1.0",
39
39
  "ember-cli-sri": "^2.1.1",
40
- "ember-cli-terser": "~4.0.1",
40
+ "ember-cli-terser": "~4.0.2",
41
41
  "ember-disable-prototype-extensions": "^1.1.3",
42
42
  "ember-export-application-global": "^2.0.1",
43
- "ember-load-initializers": "^2.1.1",
43
+ "ember-load-initializers": "^2.1.2",
44
44
  "ember-maybe-import-regenerator": "^1.0.0",
45
45
  "ember-qunit": "^5.1.5",
46
46
  "ember-resolver": "^8.0.3",
47
- "ember-source": "~4.3.0",
47
+ "ember-source": "~4.6.0",
48
48
  "ember-source-channel-url": "^3.0.0",
49
49
  "ember-try": "^2.0.0",
50
50
  "loader.js": "^4.7.0",
51
- "qunit": "^2.17.0",
51
+ "qunit": "^2.19.1",
52
52
  "qunit-dom": "^2.0.0",
53
53
  "silent-error": "^1.1.1",
54
- "webpack": "^5.37.1"
54
+ "webpack": "^5.74.0"
55
55
  },
56
56
  "engines": {
57
- "node": "12.* || >= 14.*"
57
+ "node": "^14.8.0 || 16.* || >= 18.*",
58
+ "yarn": "1.22.19"
58
59
  },
59
60
  "ember-addon": {
60
61
  "configPath": "tests/dummy/config"
61
62
  },
62
63
  "volta": {
63
- "node": "14.17.0",
64
- "yarn": "1.22.4"
64
+ "node": "16.16.0",
65
+ "yarn": "1.22.19"
65
66
  }
66
67
  }