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

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
@@ -710,7 +710,7 @@ const JSONAPISerializer = JSONSerializer.extend({
710
710
  }
711
711
 
712
712
  // only serialize has many relationships that are not new
713
- let nonNewHasMany = hasMany.filter((item) => item.record && !item.record.get('isNew'));
713
+ let nonNewHasMany = hasMany.filter((item) => item.record && !item.record.isNew);
714
714
  let data = new Array(nonNewHasMany.length);
715
715
 
716
716
  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) {
@@ -576,7 +573,7 @@ const JSONSerializer = Serializer.extend({
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
  },
@@ -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
 
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
  }
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/serializer",
3
- "version": "4.8.0-alpha.2",
3
+ "version": "4.8.0-alpha.3",
4
4
  "description": "The default blueprint for ember-cli addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -18,15 +18,15 @@
18
18
  "test:node": "mocha"
19
19
  },
20
20
  "dependencies": {
21
- "@ember-data/private-build-infra": "4.8.0-alpha.2",
22
- "@ember-data/store": "4.8.0-alpha.2",
21
+ "@ember-data/private-build-infra": "4.8.0-alpha.3",
22
+ "@ember-data/store": "4.8.0-alpha.3",
23
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
26
  "ember-cli-typescript": "^5.1.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@ember-data/unpublished-test-infra": "4.8.0-alpha.2",
29
+ "@ember-data/unpublished-test-infra": "4.8.0-alpha.3",
30
30
  "@ember/optional-features": "^2.0.0",
31
31
  "@ember/string": "^3.0.0",
32
32
  "@ember/test-helpers": "~2.7.0",
@@ -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 };