UNPKG

pailingual-odata

Version:

TypeScript client for OData v4 services

95 lines (94 loc) 3.94 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { CollectionSource } from "./collectionSource"; import { Executable } from "./executable"; import * as helpers from "./utils"; var SingleSource = /** @class */ (function (_super) { __extends(SingleSource, _super); function SingleSource(__metadata, __apiMetadata, query) { var _this = _super.call(this, query) || this; _this.__metadata = __metadata; _this.__apiMetadata = __apiMetadata; _this.generatePropertyImplementation(); return _this; } SingleSource.prototype.generatePropertyImplementation = function () { var query = this.query; var _loop_1 = function (p) { var propMD = this_1.__metadata.navProperties[p]; Object.defineProperty(this_1, p, { get: function () { var q = query.navigate(p, propMD.type); if (propMD.collection) return new CollectionSource(propMD.type, this.__apiMetadata, q); else return new SingleSource(propMD.type, this.__apiMetadata, q); } }); }; var this_1 = this; for (var p in this.__metadata.navProperties) { _loop_1(p); } var _loop_2 = function (p) { var propMD = this_2.__metadata.properties[p]; Object.defineProperty(this_2, p, { get: function () { var query = this.query.navigate(p); return new SingleSource(propMD.type, this.__apiMetadata, query); } }); }; var this_2 = this; for (var p in this.__metadata.properties) { _loop_2(p); } helpers.generateOperations(this, function () { return query; }, this.__apiMetadata, this.__metadata); }; SingleSource.prototype.$cast = function (fullTypeName) { var metadata = this.__apiMetadata.getEdmTypeMetadata(fullTypeName); if (!metadata) throw new Error("EntitType '" + fullTypeName + "' not found."); var q = this.query.cast(fullTypeName); return new SingleSource(metadata, this.__apiMetadata, q); }; SingleSource.prototype.$select = function () { var fields = []; for (var _i = 0; _i < arguments.length; _i++) { fields[_i] = arguments[_i]; } var q = this.query.select(fields); return new SingleSource(this.__metadata, this.__apiMetadata, q); }; SingleSource.prototype.$expand = function (prop, exp) { return new SingleSource(this.__metadata, this.__apiMetadata, this.query.expand(prop, exp)); }; SingleSource.prototype.$delete = function () { var q = this.query.delete(); return new Executable(q); }; SingleSource.prototype.$patch = function (obj) { return this.$update(obj, false); }; SingleSource.prototype.$unsafeExpand = function (exp) { return this.$expand(exp); }; SingleSource.prototype.$update = function (obj, put) { if (put === void 0) { put = true; } var q = this.query.update(obj, put); return new Executable(q); }; return SingleSource; }(Executable)); export { SingleSource };