pailingual-odata
Version:
TypeScript client for OData v4 services
78 lines • 3.35 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "./collectionSource", "./executable", "./utils"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const collectionSource_1 = require("./collectionSource");
const executable_1 = require("./executable");
const helpers = require("./utils");
class SingleSource extends executable_1.Executable {
constructor(__metadata, __apiMetadata, query) {
super(query);
this.__metadata = __metadata;
this.__apiMetadata = __apiMetadata;
this.generatePropertyImplementation();
}
generatePropertyImplementation() {
const query = this.query;
for (let p in this.__metadata.navProperties) {
let propMD = this.__metadata.navProperties[p];
Object.defineProperty(this, p, {
get() {
let q = query.navigate(p, propMD.type);
if (propMD.collection)
return new collectionSource_1.CollectionSource(propMD.type, this.__apiMetadata, q);
else
return new SingleSource(propMD.type, this.__apiMetadata, q);
}
});
}
for (let p in this.__metadata.properties) {
let propMD = this.__metadata.properties[p];
Object.defineProperty(this, p, {
get() {
let query = this.query.navigate(p);
return new SingleSource(propMD.type, this.__apiMetadata, query);
}
});
}
helpers.generateOperations(this, () => query, this.__apiMetadata, this.__metadata);
}
$cast(fullTypeName) {
const metadata = this.__apiMetadata.getEdmTypeMetadata(fullTypeName);
if (!metadata)
throw new Error(`EntitType '${fullTypeName}' not found.`);
const q = this.query.cast(fullTypeName);
return new SingleSource(metadata, this.__apiMetadata, q);
}
$select(...fields) {
const q = this.query.select(fields);
return new SingleSource(this.__metadata, this.__apiMetadata, q);
}
$expand(prop, exp) {
return new SingleSource(this.__metadata, this.__apiMetadata, this.query.expand(prop, exp));
}
$delete() {
const q = this.query.delete();
return new executable_1.Executable(q);
}
$patch(obj) {
return this.$update(obj, false);
}
$unsafeExpand(exp) {
return this.$expand(exp);
}
$update(obj, put = true) {
const q = this.query.update(obj, put);
return new executable_1.Executable(q);
}
}
exports.SingleSource = SingleSource;
});
//# sourceMappingURL=singleSource.js.map