UNPKG

5.51 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7 return extendStatics(d, b);
8 };
9 return function (d, b) {
10 if (typeof b !== "function" && b !== null)
11 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12 extendStatics(d, b);
13 function __() { this.constructor = d; }
14 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 };
16})();
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.getEdmType = exports.getEntityConstructor = exports.ComplexTypeField = void 0;
19var edm_types_1 = require("../edm-types");
20var field_1 = require("./field");
21var complex_type_namespace_1 = require("./complex-type-namespace");
22/**
23 * Represents a complex type property of an entity or a complex type.
24 *
25 * `ComplexTypeField`s are used as static properties of entities and are generated from the metadata, i.e. for each property of
26 * an OData entity, that has a complex type, there exists one static instance of `ComplexTypeField` (or rather one of its subclasses) in the corresponding generated class file.
27 * `ComplexTypeField`s are used to represent the domain of complex or custom structures that can be used in select, filter and order by functions.
28 * For example, when constructing a query on the TimeSheetEntry entity, an instance of `ComplexTypeField<TimeSheetEntry>`
29 * can be supplied as argument to the select function, e.g. `TimeSheetEntry.TIME_SHEET_DATA_FIELDS`.
30 * Moreover, classes implementing this abstract class will provide property fields, that can be used for filtering and ordering.
31 *
32 * See also: [[Selectable]]
33 * @typeparam EntityT - Type of the entity the field belongs to.
34 * @typeparam ComplexT - Type of complex type represented by this field.
35 * @typeparam NullableT - Boolean type that represents whether the field is nullable.
36 * @typeparam SelectableT - Boolean type that represents whether the field is selectable.
37 */
38var ComplexTypeField = /** @class */ (function (_super) {
39 __extends(ComplexTypeField, _super);
40 /**
41 * Creates an instance of ComplexTypeField.
42 * @param fieldName - Actual name of the field as used in the OData request.
43 * @param fieldOf - Either the parent entity constructor of the parent complex type this field belongs to.
44 * @param complexTypeOrName - The complex type of the complex type property represented by this or the name of the type of the field according to the metadata description. Using the name here is deprecated.
45 * @param fieldOptions - Optional settings for this field.
46 */
47 function ComplexTypeField(fieldName, fieldOf, complexTypeOrName, fieldOptions) {
48 var _this = _super.call(this, fieldName, getEntityConstructor(fieldOf), fieldOptions) || this;
49 _this.fieldOf = fieldOf;
50 if (typeof complexTypeOrName === 'string') {
51 _this.complexTypeName = complexTypeOrName;
52 }
53 else if (complex_type_namespace_1.isComplexTypeNameSpace(complexTypeOrName)) {
54 _this._complexType = complexTypeOrName;
55 }
56 return _this;
57 }
58 /**
59 * Gets the path to the complex type property represented by this.
60 * @returns The path to the complex type property.
61 */
62 ComplexTypeField.prototype.fieldPath = function () {
63 return this.fieldOf instanceof ComplexTypeField
64 ? this.fieldOf.fieldPath() + "/" + this._fieldName
65 : this._fieldName;
66 };
67 return ComplexTypeField;
68}(field_1.Field));
69exports.ComplexTypeField = ComplexTypeField;
70/**
71 * Convenience method to get the entity constructor of the parent of a complex type.
72 * @param fieldOf - Either an entity constructor or another complex type field.
73 * @returns The constructor of the transitive parent entity;
74 */
75function getEntityConstructor(fieldOf) {
76 return fieldOf instanceof ComplexTypeField
77 ? fieldOf._entityConstructor
78 : fieldOf;
79}
80exports.getEntityConstructor = getEntityConstructor;
81/**
82 * Convenience method to get the [[EdmTypeShared]] from the overloaded constructor.
83 * The two scenarios are:
84 * - `complexTypeNameOrEdmType` is of type `EdmTypeShared` and `edmTypeOrUndefined` is `undefined`
85 * - `complexTypeNameOrEdmType` is of type `string` and `edmTypeOrUndefined` is of type `EdmTypeShared`
86 * @param complexTypeNameOrEdmType - Either the name of the complex type or the EDM type.
87 * @param edmTypeOrUndefined - Either the EDM type or `undefined`.
88 * @returns The EDM type resolved for the two arguments.
89 */
90function getEdmType(complexTypeNameOrEdmType, edmTypeOrUndefined) {
91 if (edmTypeOrUndefined) {
92 if (typeof complexTypeNameOrEdmType === 'string' &&
93 !edm_types_1.isEdmType(complexTypeNameOrEdmType) &&
94 edm_types_1.isEdmType(edmTypeOrUndefined)) {
95 return edmTypeOrUndefined;
96 }
97 }
98 else if (edm_types_1.isEdmType(complexTypeNameOrEdmType)) {
99 return complexTypeNameOrEdmType;
100 }
101 throw new Error("Failed to get EDM type based on '" + complexTypeNameOrEdmType + "' and '" + edmTypeOrUndefined + "'.");
102}
103exports.getEdmType = getEdmType;
104//# sourceMappingURL=complex-type-field.js.map
\No newline at end of file