Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | 1x 1x 1x 16x 16x 16x 16x 1x 1x 1x 1x 2x 1x 1x 1x 2x 1x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x | "use strict";
const _ = require("lodash");
const QueryableResource = require("./QueryableResource");
const NavigationProperty = require("./NavigationProperty");
/**
* Envelope GET/POST/PUT/DELETE methods for particular EntitySet
*
* @class EntitySet
* @extends {QueryableResource}
*/
class EntitySet extends QueryableResource {
/**
* Creates an instance of <code>EntitySet</code>.
* @param {Agent} agent instance of the Agent class @see Agent.js
* @param {Metadata} metadata instance of the metadata object that keeps service metadata
* @param {Object} entitySetModel information about EntitySet parsed from Metadata
* @memberof EntitySet
*/
constructor(agent, metadata, entitySetModel) {
let entityType = entitySetModel.entityType;
super(agent, metadata, entitySetModel, entityType);
let parameterizationInfo = entitySetModel.getParameterizationInfo(
metadata.model.getSchema()
);
if (parameterizationInfo.isParameterized) {
this.isParameterized = true;
this.valuesAssociation = parameterizationInfo.valuesAssociation;
this._defaults._parameters = {};
}
}
/**
* Creates a new NavigationProperty
* @param {Metadata} metadata instance of the metadata object that keeps service metadata
* @param {Object} navigationProperty navigation property parsed from metadata
* @returns {Association} association instance @see NavigationProperty.js
* @memberof EntitySet
*/
createNavigationProperty(metadata, navigationProperty) {
return new NavigationProperty(this, navigationProperty, metadata);
}
/**
* Gets path to the list of resources
* @returns {string} path to the list of resources
* @memberof EntitySet
*/
getListResourcePath() {
return this.isParameterized
? this._getParametrizedListPath()
: super.getListResourcePath();
}
/**
* Gets navigation properties for current entity.
*
* @readonly
* @memberof EntitySet
*/
get navigationProperties() {
return this.defaultRequest.navigationProperties;
}
/**
* Gets parameter definition.
*
* @protected
* @param {string} parameterName name of the parameter
* @returns {object} parameter definition, containing at least 'type'
* @memberof EntitySet
*/
getParameterDefinition(parameterName) {
return this.entityTypeModel.getProperty(parameterName);
}
/**
* Gets path for parametrized entity set definition.
*
* @private
* @returns {string} resource path
* @memberof EntitySet
*/
_getParametrizedListPath() {
let predicate = _.toPairs(this.defaultRequest._parameters)
.map((p) => `${p[0]}=${p[1]}`)
.join(",");
return `${this.entitySetModel.name}(${predicate})/${this.valuesAssociation.name}`;
}
/**
* Send request to bound ODataV4 action
*
* @public
* @param {engine.RequestDefinition} request odata definition
* @return {Promise} promise resolved when call is finished
* @memberof engine.EntitySet
*/
callAction(request) {
let defaultBatch = this.agent.batchManager.defaultBatch;
let defaultChangeSet = this.agent.batchManager.defaultChangeSet;
let payload = JSON.stringify(request._payload);
return defaultBatch
? this._handleBatchCall(() => {
request.header("Accept", "application/json");
return defaultBatch.post(
request._path,
request._headers,
payload,
defaultChangeSet
);
}, defaultBatch)
: this._handleAgentCall(() =>
this.agent.post(request._path, request._headers, payload)
);
}
/**
* Mark request definition as request for raw value ($value keyword)
*
* @param {String} [propertyName] name of property which is asked (if
* parameter is not set $value keyword will be use for whole
* entity}
*
* @return {EntitySet} itself for the chaining
*
* @memberof EntitySet
*/
value(...args) {
this.defaultRequest.value(...args);
return this;
}
}
module.exports = EntitySet;
|