@singularsystems/neo-core 0.10.50 → 0.10.51

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.
@@ -3,6 +3,7 @@ import { Deserialiser } from './Deserialiser';
3
3
  import ValueObject from '../Model/ValueObject';
4
4
  import DateUtils from '../Dates/DateUtils';
5
5
  import Globals from '../Globals';
6
+ var referenceIdKey = Symbol("referenceId");
6
7
  var JSFormatter = /** @class */ (function () {
7
8
  function JSFormatter() {
8
9
  }
@@ -41,6 +42,7 @@ var Serialiser = /** @class */ (function () {
41
42
  if (options === void 0) { options = {}; }
42
43
  this.options = options;
43
44
  var to;
45
+ this.currentID = 1;
44
46
  if (fromObject instanceof Array) {
45
47
  to = [];
46
48
  this.serialiseArray(fromObject, to);
@@ -57,25 +59,33 @@ var Serialiser = /** @class */ (function () {
57
59
  */
58
60
  Serialiser.prototype.cleanUpObjects = function () {
59
61
  for (var id in this.objectRefs) {
60
- delete this.objectRefs[id].from.__id;
62
+ var refInfo = this.objectRefs[id];
63
+ delete refInfo.from[referenceIdKey];
64
+ // Remove $id property if object is not referenced by anything.
65
+ if (!refInfo.isReferenced) {
66
+ delete refInfo.to.$id;
67
+ }
61
68
  }
69
+ this.objectRefs = {};
62
70
  };
63
71
  Serialiser.prototype.serialiseObject = function (from, to, isDictionary) {
64
72
  if (isDictionary === void 0) { isDictionary = false; }
65
73
  //check that this object hasnt already been serialised.
66
- if (!from.__id) {
67
- from.__id = this.currentID++;
74
+ var referenceId = from[referenceIdKey];
75
+ if (!referenceId) {
76
+ referenceId = this.currentID++;
77
+ from[referenceIdKey] = referenceId;
68
78
  }
69
- var sid = (from.__id).toString();
70
- var toReference = this.objectRefs[sid];
71
- if (toReference) {
79
+ var referenceInfo = this.objectRefs[referenceId];
80
+ if (referenceInfo) {
72
81
  //already serialised this object
73
- to.$ref = sid;
74
- toReference.to.$id = sid;
82
+ referenceInfo.isReferenced = true;
83
+ to.$ref = referenceInfo.to.$id;
75
84
  return;
76
85
  }
77
86
  else {
78
- this.objectRefs[from.__id] = { from: from, to: to };
87
+ this.objectRefs[referenceId] = { from: from, to: to };
88
+ to.$id = referenceId.toString();
79
89
  }
80
90
  //Set tracking state
81
91
  if (!this.options.suppressTrackingState && !isDictionary) {
@@ -115,7 +125,7 @@ var Serialiser = /** @class */ (function () {
115
125
  }
116
126
  }
117
127
  else if (isChildObject && !propertyInfo.assignOnDeserialise) {
118
- if (!fromValue || (propertyInfo.relationType === RelationType.Parent && !fromValue.__id)) {
128
+ if (!fromValue || (propertyInfo.relationType === RelationType.Parent && !fromValue[referenceIdKey])) {
119
129
  // Parents must only be included if they reference an already serialised object.
120
130
  // Otherwise serialising a leaf node will serialise up the tree and the entire graph will be serialised.
121
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-core",
3
- "version": "0.10.50",
3
+ "version": "0.10.51",
4
4
  "description": "Core functionality for the Neo client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",