Comparing version 1.1.9 to 1.1.10
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createEntityKey(data) { | ||
if (data.type && data.id) { | ||
return data.type + "-" + data.id; | ||
} | ||
return ''; | ||
} | ||
var JsonDeserializer = /** @class */ (function () { | ||
@@ -35,24 +41,30 @@ function JsonDeserializer(propertiesMapper) { | ||
JsonDeserializer.prototype.buildModelByData = function (data) { | ||
// checks for built model in cachedModels is a protection from creating models on recursive relationships | ||
var entityKey = data.type + "-" + data.id; | ||
var model = this.cachedModels[entityKey]; | ||
if (!model) { | ||
model = this.pm.createModel(data.type); | ||
var entityKey = createEntityKey(data); | ||
var model; | ||
if (entityKey) { | ||
// checks for built model in cachedModels is a protection from creating models on recursive relationships | ||
model = this.cachedModels[entityKey]; | ||
if (model) { | ||
return model; | ||
} | ||
} | ||
model = this.pm.createModel(data.type); | ||
if (model) { | ||
if (entityKey) { | ||
this.cachedModels[entityKey] = model; | ||
this.pm.setId(model, data.id); | ||
if (data.attributes) { | ||
this.pm.setAttributes(model, data.attributes); | ||
} | ||
if (data.meta && this.pm.setMeta) { | ||
this.pm.setMeta(model, data.meta); | ||
} | ||
if (data.links && this.pm.setLinks) { | ||
this.pm.setLinks(model, data.links); | ||
} | ||
var relationships = this.buildRelationsByData(data, model); | ||
if (relationships) { | ||
this.pm.setRelationships(model, relationships); | ||
} | ||
} | ||
this.pm.setId(model, data.id); | ||
if (data.attributes) { | ||
this.pm.setAttributes(model, data.attributes); | ||
} | ||
if (data.meta && this.pm.setMeta) { | ||
this.pm.setMeta(model, data.meta); | ||
} | ||
if (data.links && this.pm.setLinks) { | ||
this.pm.setLinks(model, data.links); | ||
} | ||
var relationships = this.buildRelationsByData(data, model); | ||
if (relationships) { | ||
this.pm.setRelationships(model, relationships); | ||
} | ||
} | ||
@@ -59,0 +71,0 @@ return model; |
{ | ||
"name": "jsona", | ||
"description": "Provide data formatters (data model builder & json builder) to work with JSON API specification v1.0 in your JavaScript / TypeScript code", | ||
"version": "1.1.9", | ||
"version": "1.1.10", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "json-api", |
@@ -10,2 +10,10 @@ import { | ||
function createEntityKey(data: TJsonApiData) { | ||
if (data.type && data.id) { | ||
return `${data.type}-${data.id}`; | ||
} | ||
return ''; | ||
} | ||
class JsonDeserializer implements IJsonaModelBuilder { | ||
@@ -56,32 +64,40 @@ | ||
// checks for built model in cachedModels is a protection from creating models on recursive relationships | ||
const entityKey = `${data.type}-${data.id}`; | ||
let model = this.cachedModels[entityKey]; | ||
const entityKey = createEntityKey(data); | ||
if (!model) { | ||
model = this.pm.createModel(data.type); | ||
let model; | ||
if (entityKey) { | ||
// checks for built model in cachedModels is a protection from creating models on recursive relationships | ||
model = this.cachedModels[entityKey]; | ||
if (model) { | ||
return model; | ||
} | ||
} | ||
model = this.pm.createModel(data.type); | ||
if (model) { | ||
if (entityKey) { | ||
this.cachedModels[entityKey] = model; | ||
} | ||
this.pm.setId(model, data.id); | ||
this.pm.setId(model, data.id); | ||
if (data.attributes) { | ||
this.pm.setAttributes(model, data.attributes); | ||
} | ||
if (data.attributes) { | ||
this.pm.setAttributes(model, data.attributes); | ||
} | ||
if (data.meta && this.pm.setMeta) { | ||
this.pm.setMeta(model, data.meta); | ||
} | ||
if (data.meta && this.pm.setMeta) { | ||
this.pm.setMeta(model, data.meta); | ||
} | ||
if (data.links && this.pm.setLinks) { | ||
this.pm.setLinks(model, data.links); | ||
} | ||
if (data.links && this.pm.setLinks) { | ||
this.pm.setLinks(model, data.links); | ||
} | ||
const relationships: null | TJsonaRelationships = this.buildRelationsByData(data, model); | ||
const relationships: null | TJsonaRelationships = this.buildRelationsByData(data, model); | ||
if (relationships) { | ||
this.pm.setRelationships(model, relationships); | ||
} | ||
if (relationships) { | ||
this.pm.setRelationships(model, relationships); | ||
} | ||
@@ -88,0 +104,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116662
1974