@ember-data/serializer 4.8.0-alpha.2 → 4.8.0-alpha.5

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,6 +1,5 @@
1
1
  import { A } from '@ember/array';
2
2
  import { warn } from '@ember/debug';
3
- import { get, set } from '@ember/object';
4
3
  import Mixin from '@ember/object/mixin';
5
4
  import { camelize } from '@ember/string';
6
5
  import { typeOf } from '@ember/utils';
@@ -544,7 +543,7 @@ export default Mixin.create({
544
543
  },
545
544
 
546
545
  attrsOption(attr) {
547
- let attrs = this.get('attrs');
546
+ let attrs = this.attrs;
548
547
  return attrs && (attrs[camelize(attr)] || attrs[attr]);
549
548
  },
550
549
 
@@ -571,7 +570,7 @@ export default Mixin.create({
571
570
  @private
572
571
  */
573
572
  _extractEmbeddedHasMany(store, key, hash, relationshipMeta) {
574
- let relationshipHash = get(hash, `data.relationships.${key}.data`);
573
+ let relationshipHash = hash.data?.relationships?.[key]?.data;
575
574
 
576
575
  if (!relationshipHash) {
577
576
  return;
@@ -592,7 +591,7 @@ export default Mixin.create({
592
591
  }
593
592
 
594
593
  let relationship = { data: hasMany };
595
- set(hash, `data.relationships.${key}`, relationship);
594
+ hash.data.relationships[key] = relationship;
596
595
  },
597
596
 
598
597
  /**
@@ -600,7 +599,7 @@ export default Mixin.create({
600
599
  @private
601
600
  */
602
601
  _extractEmbeddedBelongsTo(store, key, hash, relationshipMeta) {
603
- let relationshipHash = get(hash, `data.relationships.${key}.data`);
602
+ let relationshipHash = hash.data?.relationships?.[key]?.data;
604
603
  if (!relationshipHash) {
605
604
  return;
606
605
  }
@@ -615,7 +614,7 @@ export default Mixin.create({
615
614
  let belongsTo = { id: data.id, type: data.type };
616
615
  let relationship = { data: belongsTo };
617
616
 
618
- set(hash, `data.relationships.${key}`, relationship);
617
+ hash.data.relationships[key] = relationship;
619
618
  },
620
619
 
621
620
  /**
@@ -3,7 +3,6 @@
3
3
  */
4
4
 
5
5
  export { default as EmbeddedRecordsMixin } from './embedded-records-mixin';
6
- export { modelHasAttributeOrRelationshipNamedType } from './utils';
7
6
 
8
7
  export { default as Transform } from './transforms/transform';
9
8
  export { default as BooleanTransform } from './transforms/boolean';
package/addon/json-api.js CHANGED
@@ -374,7 +374,6 @@ const JSONAPISerializer = JSONSerializer.extend({
374
374
  @param {String} modelName
375
375
  @return {String}
376
376
  */
377
- // TODO @deprecated Use payloadTypeFromModelName instead
378
377
  payloadKeyFromModelName(modelName) {
379
378
  return pluralize(modelName);
380
379
  },
@@ -413,7 +412,7 @@ const JSONAPISerializer = JSONSerializer.extend({
413
412
 
414
413
  ```app/serializers/application.js
415
414
  import JSONAPISerializer from '@ember-data/serializer/json-api';
416
- import { dasherize } from '@ember/string';
415
+ import { dasherize } from '<app-name>/utils/string-utils';
417
416
 
418
417
  export default class ApplicationSerializer extends JSONAPISerializer {
419
418
  keyForAttribute(attr, method) {
@@ -445,7 +444,7 @@ const JSONAPISerializer = JSONSerializer.extend({
445
444
 
446
445
  ```app/serializers/post.js
447
446
  import JSONAPISerializer from '@ember-data/serializer/json-api';
448
- import { underscore } from '@ember/string';
447
+ import { underscore } from '<app-name>/utils/string-utils';
449
448
 
450
449
  export default class ApplicationSerializer extends JSONAPISerializer {
451
450
  keyForRelationship(key, relationship, method) {
@@ -563,8 +562,7 @@ const JSONAPISerializer = JSONSerializer.extend({
563
562
 
564
563
  ```app/serializers/application.js
565
564
  import JSONAPISerializer from '@ember-data/serializer/json-api';
566
- import { singularize } from 'ember-inflector';
567
- import { underscore } from '@ember/string';
565
+ import { underscore, singularize } from '<app-name>/utils/string-utils';
568
566
 
569
567
  export default class ApplicationSerializer extends JSONAPISerializer {
570
568
  serialize(snapshot, options) {
@@ -710,7 +708,7 @@ const JSONAPISerializer = JSONSerializer.extend({
710
708
  }
711
709
 
712
710
  // only serialize has many relationships that are not new
713
- let nonNewHasMany = hasMany.filter((item) => item.record && !item.record.get('isNew'));
711
+ let nonNewHasMany = hasMany.filter((item) => item.record && !item.record.isNew);
714
712
  let data = new Array(nonNewHasMany.length);
715
713
 
716
714
  for (let i = 0; i < nonNewHasMany.length; i++) {
package/addon/json.js CHANGED
@@ -3,15 +3,12 @@
3
3
  */
4
4
  import { getOwner } from '@ember/application';
5
5
  import { assert, warn } from '@ember/debug';
6
- import { get } from '@ember/object';
7
6
  import { dasherize } from '@ember/string';
8
7
  import { isNone, typeOf } from '@ember/utils';
9
8
 
10
9
  import Serializer from '@ember-data/serializer';
11
10
  import { coerceId } from '@ember-data/store/-private';
12
11
 
13
- import { modelHasAttributeOrRelationshipNamedType } from './-private';
14
-
15
12
  const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
16
13
  const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
17
14
  const PRIMARY_ATTRIBUTE_KEY = 'base';
@@ -196,7 +193,7 @@ const JSONSerializer = Serializer.extend({
196
193
  @return {Object} data The transformed data object
197
194
  */
198
195
  applyTransforms(typeClass, data) {
199
- let attributes = get(typeClass, 'attributes');
196
+ let attributes = typeClass.attributes;
200
197
 
201
198
  typeClass.eachTransformedAttribute((key, typeClass) => {
202
199
  if (data[key] === undefined) {
@@ -571,12 +568,12 @@ const JSONSerializer = Serializer.extend({
571
568
 
572
569
  ```app/serializers/application.js
573
570
  import JSONSerializer from '@ember-data/serializer/json';
574
- import { underscore } from '@ember/string';
571
+ import { underscore } from '<app-name>/utils/string-utils';
575
572
  import { get } from '@ember/object';
576
573
 
577
574
  export default class ApplicationSerializer extends JSONSerializer {
578
575
  normalize(typeClass, hash) {
579
- let fields = get(typeClass, 'fields');
576
+ let fields = typeClass.fields;
580
577
 
581
578
  fields.forEach(function(type, field) {
582
579
  let payloadField = underscore(field);
@@ -629,7 +626,7 @@ const JSONSerializer = Serializer.extend({
629
626
  @return {String}
630
627
  */
631
628
  extractId(modelClass, resourceHash) {
632
- let primaryKey = get(this, 'primaryKey');
629
+ let primaryKey = this.primaryKey;
633
630
  let id = resourceHash[primaryKey];
634
631
  return coerceId(id);
635
632
  },
@@ -685,7 +682,7 @@ const JSONSerializer = Serializer.extend({
685
682
  }
686
683
 
687
684
  let modelClass = this.store.modelFor(relationshipModelName);
688
- if (relationshipHash.type && !modelHasAttributeOrRelationshipNamedType(modelClass)) {
685
+ if (relationshipHash.type && !modelClass.fields.has('type')) {
689
686
  relationshipHash.type = this.modelNameFromPayloadKey(relationshipHash.type);
690
687
  }
691
688
 
@@ -830,7 +827,7 @@ const JSONSerializer = Serializer.extend({
830
827
  @private
831
828
  */
832
829
  normalizeUsingDeclaredMapping(modelClass, hash) {
833
- let attrs = get(this, 'attrs');
830
+ let attrs = this.attrs;
834
831
  let normalizedKey;
835
832
  let payloadKey;
836
833
 
@@ -842,11 +839,11 @@ const JSONSerializer = Serializer.extend({
842
839
  continue;
843
840
  }
844
841
 
845
- if (get(modelClass, 'attributes').has(key)) {
842
+ if (modelClass.attributes.has(key)) {
846
843
  normalizedKey = this.keyForAttribute(key, 'deserialize');
847
844
  }
848
845
 
849
- if (get(modelClass, 'relationshipsByName').has(key)) {
846
+ if (modelClass.relationshipsByName.has(key)) {
850
847
  normalizedKey = this.keyForRelationship(key, modelClass, 'deserialize');
851
848
  }
852
849
 
@@ -874,13 +871,13 @@ const JSONSerializer = Serializer.extend({
874
871
  '` on `' +
875
872
  modelClass.modelName +
876
873
  '`. Check your serializers attrs hash.',
877
- get(modelClass, 'attributes').has(key) || get(modelClass, 'relationshipsByName').has(key),
874
+ modelClass.attributes.has(key) || modelClass.relationshipsByName.has(key),
878
875
  {
879
876
  id: 'ds.serializer.no-mapped-attrs-key',
880
877
  }
881
878
  );
882
879
 
883
- let attrs = get(this, 'attrs');
880
+ let attrs = this.attrs;
884
881
  let mappedKey;
885
882
  if (attrs && attrs[key]) {
886
883
  mappedKey = attrs[key];
@@ -907,7 +904,7 @@ const JSONSerializer = Serializer.extend({
907
904
  @return {boolean} true if the key can be serialized
908
905
  */
909
906
  _canSerialize(key) {
910
- let attrs = get(this, 'attrs');
907
+ let attrs = this.attrs;
911
908
 
912
909
  return !attrs || !attrs[key] || attrs[key].serialize !== false;
913
910
  },
@@ -923,7 +920,7 @@ const JSONSerializer = Serializer.extend({
923
920
  @return {boolean} true if the key must be serialized
924
921
  */
925
922
  _mustSerialize(key) {
926
- let attrs = get(this, 'attrs');
923
+ let attrs = this.attrs;
927
924
 
928
925
  return attrs && attrs[key] && attrs[key].serialize === true;
929
926
  },
@@ -1034,7 +1031,7 @@ const JSONSerializer = Serializer.extend({
1034
1031
 
1035
1032
  ```app/serializers/application.js
1036
1033
  import JSONSerializer from '@ember-data/serializer/json';
1037
- import { singularize } from 'ember-inflector';
1034
+ import { singularize } from '<app-name>/utils/string-utils';
1038
1035
 
1039
1036
  export default class ApplicationSerializer extends JSONSerializer {
1040
1037
  serialize(snapshot, options) {
@@ -1110,7 +1107,7 @@ const JSONSerializer = Serializer.extend({
1110
1107
  if (options && options.includeId) {
1111
1108
  const id = snapshot.id;
1112
1109
  if (id) {
1113
- json[get(this, 'primaryKey')] = id;
1110
+ json[this.primaryKey] = id;
1114
1111
  }
1115
1112
  }
1116
1113
 
@@ -1141,7 +1138,7 @@ const JSONSerializer = Serializer.extend({
1141
1138
 
1142
1139
  ```app/serializers/application.js
1143
1140
  import RESTSerializer from '@ember-data/serializer/rest';
1144
- import { decamelize } from '@ember/string';
1141
+ import { decamelize } from '<app-name>/utils/string-utils';
1145
1142
 
1146
1143
  export default class ApplicationSerializer extends RESTSerializer {
1147
1144
  serializeIntoHash(data, type, snapshot, options) {
@@ -1526,7 +1523,7 @@ const JSONSerializer = Serializer.extend({
1526
1523
 
1527
1524
  ```app/serializers/application.js
1528
1525
  import JSONSerializer from '@ember-data/serializer/json';
1529
- import { underscore } from '@ember/string';
1526
+ import { underscore } from '<app-name>/utils/string-utils';
1530
1527
 
1531
1528
  export default class ApplicationSerializer extends JSONSerializer {
1532
1529
  keyForAttribute(attr, method) {
@@ -1554,7 +1551,7 @@ const JSONSerializer = Serializer.extend({
1554
1551
 
1555
1552
  ```app/serializers/post.js
1556
1553
  import JSONSerializer from '@ember-data/serializer/json';
1557
- import { underscore } from '@ember/string';
1554
+ import { underscore } from '<app-name>/utils/string-utils';
1558
1555
 
1559
1556
  export default class PostSerializer extends JSONSerializer {
1560
1557
  keyForRelationship(key, relationship, method) {
package/addon/rest.js CHANGED
@@ -11,8 +11,6 @@ import { singularize } from 'ember-inflector';
11
11
  import JSONSerializer from '@ember-data/serializer/json';
12
12
  import { coerceId } from '@ember-data/store/-private';
13
13
 
14
- import { modelHasAttributeOrRelationshipNamedType } from './-private';
15
-
16
14
  function makeArray(value) {
17
15
  return Array.isArray(value) ? value : [value];
18
16
  }
@@ -42,7 +40,7 @@ function makeArray(value) {
42
40
 
43
41
  ```app/serializers/application.js
44
42
  import RESTSerializer from '@ember-data/serializer/rest';
45
- import { underscore } from '@ember/string';
43
+ import { underscore } from '<app-name>/utils/string-utils';
46
44
 
47
45
  export default class ApplicationSerializer extends RESTSerializer {
48
46
  keyForAttribute(attr, method) {
@@ -198,7 +196,7 @@ const RESTSerializer = JSONSerializer.extend({
198
196
  let serializer = primarySerializer;
199
197
  let modelClass = primaryModelClass;
200
198
 
201
- let primaryHasTypeAttribute = modelHasAttributeOrRelationshipNamedType(primaryModelClass);
199
+ let primaryHasTypeAttribute = primaryModelClass.fields.has('type');
202
200
 
203
201
  if (!primaryHasTypeAttribute && hash.type) {
204
202
  // Support polymorphic records in async relationships
@@ -563,7 +561,7 @@ const RESTSerializer = JSONSerializer.extend({
563
561
 
564
562
  ```app/serializers/application.js
565
563
  import RESTSerializer from '@ember-data/serializer/rest';
566
- import { pluralize } from 'ember-inflector';
564
+ import { pluralize } from '<app-name>/utils/string-utils';
567
565
 
568
566
  export default class ApplicationSerializer extends RESTSerializer {
569
567
  serialize(snapshot, options) {
@@ -647,7 +645,7 @@ const RESTSerializer = JSONSerializer.extend({
647
645
 
648
646
  ```app/serializers/application.js
649
647
  import RESTSerializer from '@ember-data/serializer/rest';
650
- import { decamelize } from '@ember/string';
648
+ import { decamelize } from '<app-name>/utils/string-utils';
651
649
 
652
650
  export default class ApplicationSerializer extends RESTSerializer {
653
651
  serializeIntoHash(data, type, record, options) {
@@ -690,7 +688,7 @@ const RESTSerializer = JSONSerializer.extend({
690
688
 
691
689
  ```app/serializers/application.js
692
690
  import RESTSerializer from '@ember-data/serializer/rest';
693
- import { dasherize } from '@ember/string';
691
+ import { dasherize } from '<app-name>/utils/string-utils';
694
692
 
695
693
  export default class ApplicationSerializer extends RESTSerializer {
696
694
  payloadKeyFromModelName(modelName) {
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@ember-data/serializer",
3
- "version": "4.8.0-alpha.2",
4
- "description": "The default blueprint for ember-cli addons.",
3
+ "version": "4.8.0-alpha.5",
4
+ "description": "Provides reference Serializer implementations for use with @ember-data/store",
5
5
  "keywords": [
6
6
  "ember-addon"
7
7
  ],
8
- "repository": "https://github.com/emberjs/data/tree/master/packages/serializer",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+ssh://git@github.com:emberjs/data.git",
11
+ "directory": "packages/serializer"
12
+ },
9
13
  "license": "MIT",
10
14
  "author": "",
11
15
  "directories": {
@@ -18,15 +22,15 @@
18
22
  "test:node": "mocha"
19
23
  },
20
24
  "dependencies": {
21
- "@ember-data/private-build-infra": "4.8.0-alpha.2",
22
- "@ember-data/store": "4.8.0-alpha.2",
25
+ "@ember-data/private-build-infra": "4.8.0-alpha.5",
26
+ "@ember-data/store": "4.8.0-alpha.5",
23
27
  "ember-auto-import": "^2.4.2",
24
28
  "ember-cli-babel": "^7.26.11",
25
29
  "ember-cli-test-info": "^1.0.0",
26
30
  "ember-cli-typescript": "^5.1.0"
27
31
  },
28
32
  "devDependencies": {
29
- "@ember-data/unpublished-test-infra": "4.8.0-alpha.2",
33
+ "@ember-data/unpublished-test-infra": "4.8.0-alpha.5",
30
34
  "@ember/optional-features": "^2.0.0",
31
35
  "@ember/string": "^3.0.0",
32
36
  "@ember/test-helpers": "~2.7.0",
@@ -60,7 +64,7 @@
60
64
  "configPath": "tests/dummy/config"
61
65
  },
62
66
  "volta": {
63
- "node": "16.16.0",
67
+ "node": "16.17.0",
64
68
  "yarn": "1.22.19"
65
69
  }
66
70
  }
@@ -1,10 +0,0 @@
1
- import { get } from '@ember/object';
2
-
3
- /*
4
- Check if the passed model has a `type` attribute or a relationship named `type`.
5
- */
6
- function modelHasAttributeOrRelationshipNamedType(modelClass) {
7
- return get(modelClass, 'attributes').has('type') || get(modelClass, 'relationshipsByName').has('type');
8
- }
9
-
10
- export { modelHasAttributeOrRelationshipNamedType };