@sap_oss/odata-library
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,1 +0,1 @@ | ||
{"processes":{"d03d2cd4-5ec8-415c-acb0-68243579478d":{"parent":null,"children":[]}},"files":{"/home/i332698/www/odata-library/lib/agent/batch/Batch.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/batch/Base.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/batch/Request.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/batch/Response.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/parsers.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/batch/ChangeSet.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/url.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/log.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/authentication/basic.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/authentication/none.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/authentication/samlSap.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/engine/EntitySet.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/engine/QueryableResource.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/engine/Resource.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/engine/RequestDefinition.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/engine/entitySet/Filter.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/engine/entitySet/Sorter.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/engine/NavigationProperty.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/EdmxModel.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/CsdlSchema.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/schema/Association.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/schema/AssociationEnd.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/schema/CollectionType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/schema/ComplexType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/annotations/AnnotationTarget.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/annotations/ExpressionBuilder.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/annotations/Annotation.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/annotations/Collection.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/annotations/PropertyValue.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/annotations/Record.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/schema/ComplexType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/aggregate.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/schema/Property.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/schema/EntityType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/schema/NavigationProperty.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/schema/EdmSimpleType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/dataSource/EntityContainer.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/dataSource/AssociationSet.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/dataSource/AssociationSetEnd.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/dataSource/EntitySet.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/dataSource/FunctionImport.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/dataSource/FunctionImportParameter.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/extensions/Extender.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/extensions/sap/ExtenderBase.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/extensions/sap/EntityTypeExtender.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/extensions/sap/common/SideEffectsType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/extensions/sap/common/ValueListType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/extensions/sap/ui/DataField.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/nw/extensions/sap/EntityContainerExtender.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/CsdlSchema.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/Action.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/Parameter.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/ReturnType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/ComplexType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/NavigationProperty.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/CollectionType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/OnDeleteAction.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/ReferentialConstraint.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/Property.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/EdmSimpleType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/EntityType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/Function.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/dataSource/EntityContainer.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/dataSource/ActionImport.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/dataSource/EntitySet.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/NavigationPropertyBinding.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/dataSource/FunctionImport.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/dataSource/Singleton.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/EnumType.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/EnumTypeMemeber.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/schema/TypeDefinition.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/oasis/extensions/Extender.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/model/Metadata.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/Service.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/engine/FunctionImport.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/Agent.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/batch/Manager.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"],"/home/i332698/www/odata-library/lib/agent/settings.js":["d03d2cd4-5ec8-415c-acb0-68243579478d"]},"externalIds":{}} | ||
{"processes":{"bc303ab1-f2eb-4915-8026-3851023d827a":{"parent":null,"children":[]}},"files":{"/home/i332698/www/odata-library/lib/agent/batch/Batch.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/agent/batch/Base.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/agent/batch/Request.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/agent/batch/Response.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/agent/parsers.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/engine/responseType.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/agent/batch/ChangeSet.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/agent/url.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/agent/log.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/agent/authentication/basic.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/agent/authentication/none.js":["bc303ab1-f2eb-4915-8026-3851023d827a"],"/home/i332698/www/odata-library/lib/agent/authentication/samlSap.js":["bc303ab1-f2eb-4915-8026-3851023d827a"]},"externalIds":{}} |
# Changelog | ||
# 1.0.1 | ||
- c660f58 - [FEATURE] Resolve deep property - Norbert Volf | ||
- daee07d - [FEATURE] Add $filter to entity set count request - Norbert Volf | ||
# 1.0.0 | ||
@@ -4,0 +9,0 @@ |
@@ -585,16 +585,5 @@ "use strict"; | ||
.concat(...requestsResponses) | ||
.map((response) => { | ||
let oDataContent = _.get( | ||
response, | ||
`body.${this._instanceResultPath}`, | ||
null | ||
); | ||
let oDataContentArray = _.get( | ||
response, | ||
`body.${this._listResultPath}` | ||
); | ||
return _.isArray(oDataContentArray) | ||
? oDataContentArray | ||
: oDataContent || response; | ||
}) | ||
.map((response) => | ||
response.plain(this._listResultPath, this._instanceResultPath) | ||
) | ||
.value(); | ||
@@ -601,0 +590,0 @@ } |
@@ -7,2 +7,3 @@ "use strict"; | ||
const _ = require("lodash"); | ||
const responseType = require("../../engine/responseType"); | ||
@@ -226,2 +227,4 @@ /** | ||
* @param {batch/ChangeSet} changeSet which contains newly created request | ||
* @param {Number} useResponseType requested type of response constant defined | ||
* in lib/engine/responseType | ||
* | ||
@@ -232,4 +235,13 @@ * @returns {batch/Request} instance of batch Request | ||
*/ | ||
get(inputUrl, headers, changeSet) { | ||
return this.addRequest("GET", inputUrl, headers, undefined, changeSet); | ||
get(inputUrl, headers, changeSet, useResponseType) { | ||
const batchRequest = this.addRequest( | ||
"GET", | ||
inputUrl, | ||
headers, | ||
undefined, | ||
changeSet | ||
); | ||
batchRequest.responseType = useResponseType; | ||
return batchRequest; | ||
} | ||
@@ -251,3 +263,6 @@ | ||
post(...args) { | ||
return this.addRequestWithPayload("POST", ...args); | ||
const batchRequest = this.addRequestWithPayload("POST", ...args); | ||
batchRequest.responseType = responseType.ENTITY; | ||
return batchRequest; | ||
} | ||
@@ -254,0 +269,0 @@ |
@@ -65,2 +65,4 @@ "use strict"; | ||
}); | ||
this.responseType = null; | ||
} | ||
@@ -67,0 +69,0 @@ |
@@ -7,2 +7,3 @@ "use strict"; | ||
const parsers = require("../parsers"); | ||
const responseType = require("../../engine/responseType"); | ||
@@ -320,4 +321,33 @@ /** | ||
} | ||
/** | ||
* Read plain OData response as javascript object from | ||
* Batch response | ||
* | ||
* @public | ||
* | ||
* @param {String} listResultPath path to list result (depends on OData version) | ||
* @param {String} instanceResultPath path to entity result (depends on OData version) | ||
* | ||
* @returns {Array|Object} parsed list or entity | ||
* | ||
* @memberof agent/batch/Response | ||
*/ | ||
plain(listResultPath, instanceResultPath) { | ||
let result; | ||
switch (this.request.responseType) { | ||
case responseType.COUNT: | ||
result = parsers.count(_.get(this, "body")); | ||
break; | ||
case responseType.LIST: | ||
result = _.get(this, `body.${listResultPath}`); | ||
break; | ||
case responseType.ENTITY: | ||
result = _.get(this, `body.${instanceResultPath}`, null); | ||
break; | ||
} | ||
return result || this; | ||
} | ||
} | ||
module.exports = Response; |
@@ -124,2 +124,22 @@ "use strict"; | ||
/** | ||
* Parse response from count. Raises error for invalid | ||
* number in body | ||
* | ||
* @param {String} responseText response | ||
* | ||
* @return {Number} returns | ||
* | ||
* @memberof QueryableResource | ||
*/ | ||
parsers.count = function (responseText) { | ||
const count = parseInt(responseText, 10); | ||
if (isNaN(count)) { | ||
throw new Error("Backend returns invalid count value."); | ||
} | ||
return count; | ||
}; | ||
module.exports = parsers; |
@@ -5,2 +5,4 @@ "use strict"; | ||
const Resource = require("./Resource"); | ||
const responseType = require("./responseType"); | ||
const parsers = require("../agent/parsers"); | ||
@@ -90,61 +92,13 @@ /** | ||
* | ||
* @param {RequestDefinition} request optional request definition (default entity set request is used as default) | ||
* @param {RequestDefinition} [request] optional request definition (default entity set request is used as default) | ||
* | ||
* @return {Promise} returned promise is resolved when request is finished | ||
* | ||
* @memberof QueryableResource | ||
*/ | ||
count(request = this.defaultRequest) { | ||
this.reset(); | ||
return new Promise((resolve, reject) => { | ||
if (!this.entitySetModel.sap.countable) { | ||
reject( | ||
new Error( | ||
`The EntitySet ${this.entitySetModel.name} is not countable.` | ||
) | ||
); | ||
} else { | ||
this.agent | ||
.get( | ||
`/${this.entitySetModel.name}/$count`, | ||
request._headers, | ||
undefined, | ||
true | ||
) | ||
.then((res) => { | ||
let count; | ||
if (request._isRaw) { | ||
resolve(res); | ||
} else { | ||
count = this.parseCount(res); | ||
if (isNaN(count)) { | ||
reject(new Error("Backend returns invalid count value.")); | ||
} | ||
resolve(count); | ||
} | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
} | ||
}); | ||
return request.count(); | ||
} | ||
/** | ||
* Parse response from count with workaround for superagent which returns | ||
* invalid parsed body in newer versions | ||
* | ||
* @param {Response} res SuperAgent response object | ||
* @return {Number} returns NaN for invalid number or valid count | ||
* @memberof QueryableResource | ||
*/ | ||
parseCount(res) { | ||
let count = parseInt(_.get(res, "body"), 10); | ||
if (isNaN(count)) { | ||
count = parseInt(_.get(res, "res.text"), 10); | ||
} | ||
return count; | ||
} | ||
/** | ||
* Sends GET request to the entity set. | ||
@@ -393,13 +347,8 @@ * | ||
request._headers, | ||
defaultChangeSet | ||
defaultChangeSet, | ||
responseType.determine(request, this) | ||
); | ||
}, defaultBatch) | ||
: this._handleAgentCall( | ||
() => | ||
this.agent.get( | ||
request._path, | ||
request._headers, | ||
undefined, | ||
request._resource.entityTypeModel.hasStream | ||
), | ||
() => this.agent.get(request._path, request._headers), | ||
request | ||
@@ -559,3 +508,2 @@ ); | ||
let assoociationEnd = entityTypeModelStart.navigationPropertyAssociationTo( | ||
this.metadata.model, | ||
navigationProperty.name | ||
@@ -653,3 +601,3 @@ ); | ||
if (!hasStream) { | ||
if (!hasStream && !request._isCount) { | ||
request.header("Accept", "application/json"); | ||
@@ -683,2 +631,4 @@ } | ||
promise = Promise.resolve(null); | ||
} else if (request._isCount === true) { | ||
promise = response.text().then((text) => parsers.count(text)); | ||
} else { | ||
@@ -685,0 +635,0 @@ promise = response.json().then((json) => { |
@@ -7,2 +7,3 @@ "use strict"; | ||
const Sorter = require("./entitySet/Sorter"); | ||
const responseType = require("./responseType"); | ||
@@ -66,6 +67,16 @@ /** | ||
* @return {Promise} returned promise is resolved when request is finished | ||
* | ||
* @memberof QueryableResource | ||
*/ | ||
count() { | ||
return this._resource.count(this); | ||
if (!this._resource.entitySetModel.sap.countable) { | ||
throw new Error( | ||
`The EntitySet ${this._resource.entitySetModel.name} is not countable.` | ||
); | ||
} | ||
this._isCount = true; | ||
this.calculatePath(); | ||
return this._resource.executeGet(this); | ||
} | ||
@@ -470,22 +481,32 @@ | ||
* Caculate path for GET request. | ||
* | ||
* @private | ||
* | ||
* @memberof RequestDefinition | ||
*/ | ||
calculatePath() { | ||
if (this._isList) { | ||
let urlQuery = this._resource.urlQuery({ | ||
$top: 100, | ||
$skip: 0, | ||
$format: "json", | ||
}); | ||
this._path = `/${this._resource.getListResourcePath()}?${urlQuery}`; | ||
} else if (this._resource.entityTypeModel.hasStream && this._isEntity) { | ||
this._path = `/${this._resource.getSingleResourcePath()}/\$value`; | ||
} else if (this._resource.entityTypeModel.hasStream) { | ||
this._path = `/${this._resource.getListResourcePath()}/\$value`; | ||
} else { | ||
let urlQuery = this._resource.urlQuery({ | ||
$format: "json", | ||
}); | ||
this._path = `/${this._resource.getSingleResourcePath()}?${urlQuery}`; | ||
let urlQuery; | ||
switch (responseType.determine(this, this._resource)) { | ||
case responseType.COUNT: | ||
this._path = `/${this._resource.getListResourcePath()}/\$count?${this._resource.urlQuery()}`; | ||
break; | ||
case responseType.LIST: | ||
urlQuery = this._resource.urlQuery({ | ||
$top: 100, | ||
$skip: 0, | ||
$format: "json", | ||
}); | ||
this._path = `/${this._resource.getListResourcePath()}?${urlQuery}`; | ||
break; | ||
case responseType.ENTITY_STREAM: | ||
this._path = `/${this._resource.getSingleResourcePath()}/\$value`; | ||
break; | ||
case responseType.LIST_STREAM: | ||
this._path = `/${this._resource.getListResourcePath()}/\$value`; | ||
break; | ||
default: | ||
urlQuery = this._resource.urlQuery({ | ||
$format: "json", | ||
}); | ||
this._path = `/${this._resource.getSingleResourcePath()}?${urlQuery}`; | ||
} | ||
@@ -492,0 +513,0 @@ } |
@@ -40,3 +40,3 @@ "use strict"; | ||
let child = _.get(schema.raw, collection.sourceElement, []).map( | ||
(t) => new collection.Class(t) | ||
(t) => new collection.Class(t, schema.model) | ||
); | ||
@@ -110,7 +110,10 @@ Object.defineProperty(schema, collection.name, { | ||
* Creates an instance of CsdlSchema. | ||
* | ||
* @param {Object} rawMetadata raw metadata object for schema | ||
* @param {Object} [settings] (normalized) settings for the metadata, e.g. { strict: false } to ignore non critical errors | ||
* @param {Object} model reference to model which owns the schema | ||
* | ||
* @memberof CsdlSchema | ||
*/ | ||
constructor(rawMetadata, settings) { | ||
constructor(rawMetadata, settings, model) { | ||
Object.defineProperty(this, "raw", { | ||
@@ -137,2 +140,6 @@ get: () => rawMetadata, | ||
Object.defineProperty(this, "model", { | ||
get: () => model, | ||
}); | ||
initChildProperties(this); | ||
@@ -139,0 +146,0 @@ initSchemaDependentProperties(this); |
@@ -21,7 +21,10 @@ "use strict"; | ||
* Creates an instance of ComplexType. | ||
* | ||
* @param {Object} rawMetadata raw metadata object for complex type | ||
* @param {Object} model reference to model which owns the schema | ||
* | ||
* @memberof ComplexType | ||
*/ | ||
constructor(rawMetadata) { | ||
super(rawMetadata); | ||
constructor(rawMetadata, model) { | ||
super(rawMetadata, model); | ||
let properties = _.get(this.raw, "Property", []).map( | ||
@@ -61,8 +64,30 @@ (p) => new Property(p) | ||
getProperty(name) { | ||
let prop = this.properties.find((p) => p.name === name); | ||
if (!prop) { | ||
let property; | ||
let properties; | ||
const propertyNameParts = name.split("/"); | ||
const propertyName = propertyNameParts[propertyNameParts.length - 1]; | ||
const navigationPropertyName = propertyNameParts[0]; | ||
if (propertyNameParts.length === 1) { | ||
properties = this.properties; | ||
} else { | ||
properties = _.chain(this.navigationProperties) | ||
.filter((np) => navigationPropertyName === np.name) | ||
.map((navigationProperty) => { | ||
const associationEnd = this.model.resolveModelPath( | ||
navigationProperty.relationship | ||
); | ||
return _.get(associationEnd, "ends.1.type.properties", []); | ||
}) | ||
.get(0, []) | ||
.value(); | ||
} | ||
property = properties.find((p) => p.name === propertyName); | ||
if (!property) { | ||
throw new Error(`Property '${name}' not found in type ${this.name}.`); | ||
} | ||
return prop; | ||
return property; | ||
} | ||
@@ -69,0 +94,0 @@ |
@@ -19,7 +19,10 @@ "use strict"; | ||
* Creates an instance of EntityType. | ||
* | ||
* @param {Object} rawMetadata raw metadata object for complex type | ||
* @param {Object} model reference to model which owns the entity type | ||
* | ||
* @memberof EntityType | ||
*/ | ||
constructor(rawMetadata) { | ||
super(rawMetadata); | ||
constructor(rawMetadata, model) { | ||
super(rawMetadata, model); | ||
@@ -151,3 +154,2 @@ let key = this._createKey(); | ||
* | ||
* @param {EdmxModel} metaModel which contains all metadata informations | ||
* @param {String} navigationPropertyName name of the navigation property | ||
@@ -161,3 +163,3 @@ * | ||
*/ | ||
navigationPropertyAssociationTo(metaModel, navigationPropertyName) { | ||
navigationPropertyAssociationTo(navigationPropertyName) { | ||
let association; | ||
@@ -176,3 +178,3 @@ let associationEnd; | ||
association = metaModel.resolveModelPath( | ||
association = this.model.resolveModelPath( | ||
navigationPropertyDefinition.relationship | ||
@@ -179,0 +181,0 @@ ); |
@@ -15,6 +15,9 @@ "use strict"; | ||
* Creates an instance of AnnotationTarget. | ||
* | ||
* @param {Object} rawMetadata raw metadata object for annotation target object | ||
* @param {Object} model reference to model which owns the annotation target | ||
* | ||
* @memberof AnnotationTarget | ||
*/ | ||
constructor(rawMetadata) { | ||
constructor(rawMetadata, model) { | ||
this.annotations = []; | ||
@@ -38,2 +41,6 @@ | ||
}); | ||
Object.defineProperty(this, "model", { | ||
get: () => model, | ||
}); | ||
} | ||
@@ -40,0 +47,0 @@ |
@@ -33,8 +33,5 @@ "use strict"; | ||
let navigationProperties = _.get(this.raw, "NavigationProperty", []).map( | ||
this.navigationProperties = _.get(this.raw, "NavigationProperty", []).map( | ||
(p) => new NavigationProperty(p) | ||
); | ||
Object.defineProperty(this, "navigationProperties", { | ||
get: () => navigationProperties, | ||
}); | ||
} | ||
@@ -41,0 +38,0 @@ |
{ | ||
"name": "@sap_oss/odata-library", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "OData client for testing Netweawer OData services.", | ||
@@ -23,3 +23,3 @@ "main": "index.js", | ||
"validate:eslint": "eslint \"lib/**/*.js\" \"test/**/*.js\"", | ||
"validate:test": "mocha -R progress ./test/unit/**/*.js ./test/func/**/*.js", | ||
"validate:test": "mocha -R progress --recursive ./test/unit/ ./test/func/", | ||
"watch": "nodemon -e js,xml -x \"npm run validate\"" | ||
@@ -26,0 +26,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
226
10265
2523054