UNPKG

breeze2-odata4

Version:

Library to allow OData 4 support for breezejs 2

117 lines 4.55 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var 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 function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var breeze_client_1 = require("breeze-client"); var ts_odatajs_1 = require("ts-odatajs"); var OData4DataType = (function (_super) { __extends(OData4DataType, _super); function OData4DataType() { return _super !== null && _super.apply(this, arguments) || this; } return OData4DataType; }(breeze_client_1.DataType)); exports.OData4DataType = OData4DataType; var dataTypeMap = { binary: breeze_client_1.DataType.Binary, bool: breeze_client_1.DataType.Boolean, date: breeze_client_1.DataType.DateTimeOffset, datetimeoffset: breeze_client_1.DataType.DateTimeOffset, decimal: breeze_client_1.DataType.Decimal, duration: OData4DataType.Duration, float: breeze_client_1.DataType.Double, guid: breeze_client_1.DataType.Guid, int: breeze_client_1.DataType.Int64, string: breeze_client_1.DataType.String, single: breeze_client_1.DataType.Single, timeofday: OData4DataType.TimeOfDay }; function getDataType(key) { var dataType = dataTypeMap[key] || dataTypeMap.string; return dataType; } exports.getDataType = getDataType; function getEdmTypeFromTypeName(metadata, typeName) { var bindingTypeName = ts_odatajs_1.oData.utils.getCollectionType(typeName) || typeName; var entityType = ts_odatajs_1.oData.utils.lookupEntityType(bindingTypeName, metadata); var complexType = ts_odatajs_1.oData.utils.lookupComplexType(bindingTypeName, metadata); return entityType || complexType; } exports.getEdmTypeFromTypeName = getEdmTypeFromTypeName; function adaptComplexType(metadataStore, complexType) { return adaptStructuralType(metadataStore, complexType); } exports.adaptComplexType = adaptComplexType; function adaptEntityType(metadataStore, entityType) { return adaptStructuralType(metadataStore, entityType); } exports.adaptEntityType = adaptEntityType; function adaptStructuralType(metadataStore, structuralType) { var result = metadataStore.getEntityType(structuralType.name, true); return result; } exports.adaptStructuralType = adaptStructuralType; function getFunctions(metadata, metadataStore) { var result = []; metadata.dataServices.schema.forEach(function (s) { var namespace = s.namespace; if (!s.function) { return; } var entries = s.function.map(function (c) { var entry = { config: c, namespace: namespace, url: getInvokableUrl(metadata, metadataStore, c, namespace) }; return entry; }); result = result.concat(entries); }); return result; } exports.getFunctions = getFunctions; function getActions(metadata, metadataStore) { var result = []; metadata.dataServices.schema.forEach(function (s) { var namespace = s.namespace; if (!s.action) { return; } var entries = s.action.map(function (c) { var entry = { config: c, namespace: namespace, url: getInvokableUrl(metadata, metadataStore, c, namespace) }; return entry; }); result = result.concat(entries); }); return result; } exports.getActions = getActions; function getInvokableUrl(metadata, metadataStore, config, namespace) { var isBound = Boolean(config.isBound); var boundPart = ''; if (isBound) { var bindingParameter = config.parameter[0]; var bindingEdmType = getEdmTypeFromTypeName(metadata, bindingParameter.type); var breezeType = adaptEntityType(metadataStore, bindingEdmType); if (breezeType) { boundPart = breezeType.defaultResourceName + "/"; } } var url = "" + boundPart + namespace + "." + config.name; return url; } exports.getInvokableUrl = getInvokableUrl; //# sourceMappingURL=utilities.js.map