UNPKG

4.52 kBJavaScriptView Raw
1"use strict";
2/* eslint-disable max-classes-per-file */
3Object.defineProperty(exports, "__esModule", { value: true });
4exports.FieldBuilder = void 0;
5var edm_types_1 = require("../edm-types");
6var complex_type_field_1 = require("./complex-type-field");
7var edm_type_field_1 = require("./edm-type-field");
8var orderable_edm_type_field_1 = require("./orderable-edm-type-field");
9var collection_field_1 = require("./collection-field");
10var enum_field_1 = require("./enum-field");
11/**
12 * Field builder to orchestrate the creation of the different kinds of fields.
13 * @typeparam FieldOfT - Type of the entity or complex type field this field belongs to.
14 */
15var FieldBuilder = /** @class */ (function () {
16 /**
17 * Creates an instance of `FieldBuilder`.
18 * @param fieldOf - Entity or complex type field, for which the field builder shall create fields.
19 */
20 function FieldBuilder(fieldOf) {
21 this.fieldOf = fieldOf;
22 }
23 /**
24 * Build a field for a property with an EDM type.
25 * For `[[OrderableEdmType]]` fields, the returned fields are of type `OrderableEdmTypeField`.
26 * All other EDM types yield `EdmTypeField`s.
27 * Fields of entities are selectable; fields of complex types are not selectable.
28 * @param fieldName - Name of the field.
29 * @param edmType - EDM type of the field.
30 * @param isNullable - Whether the field is nullable.
31 * @returns An EDM type field.
32 */
33 FieldBuilder.prototype.buildEdmTypeField = function (fieldName, edmType, isNullable) {
34 var isSelectable = (this.fieldOf instanceof
35 complex_type_field_1.ComplexTypeField);
36 // The type assertion is necessary because the signatures of the two constructors differ (TS design limitation)
37 var ctor = (edm_types_1.isOrderableEdmType(edmType) ? orderable_edm_type_field_1.OrderableEdmTypeField : edm_type_field_1.EdmTypeField);
38 return new ctor(fieldName, this.fieldOf, edmType, {
39 isNullable: isNullable,
40 isSelectable: isSelectable
41 });
42 };
43 /**
44 * Build a field for a property with a complex type.
45 * Fields of entities are selectable; fields of complex types are not selectable.
46 * @param fieldName - Name of the field.
47 * @param complexTypeFieldCtor - Constructor of the complex type field.
48 * @param isNullable - Whether the field is nullable.
49 * @returns A complex type field of the given type.
50 */
51 FieldBuilder.prototype.buildComplexTypeField = function (fieldName, complexTypeFieldCtor, isNullable) {
52 var isSelectable = (this.fieldOf instanceof
53 complex_type_field_1.ComplexTypeField);
54 return new complexTypeFieldCtor(fieldName, this.fieldOf, {
55 isNullable: isNullable,
56 isSelectable: isSelectable
57 });
58 };
59 /**
60 * Build a field for a property with a collection type.
61 * The type of the field can either be an EDM type or a complex type.
62 * Fields of entities are selectable; fields of complex types are not selectable.
63 * @param fieldName - Name of the field.
64 * @param collectionFieldType - Type of the collection. Can either be an EDM type or complex type (not complex type field).
65 * @param isNullable - Whether the field is nullable.
66 * @returns A collection field with the given collection type.
67 */
68 FieldBuilder.prototype.buildCollectionField = function (fieldName, collectionFieldType, isNullable) {
69 var isSelectable = (this.fieldOf instanceof
70 complex_type_field_1.ComplexTypeField);
71 return new collection_field_1.CollectionField(fieldName, this.fieldOf, collectionFieldType, {
72 isNullable: isNullable,
73 isSelectable: isSelectable
74 });
75 };
76 /**
77 * Build a field for a property with a enum type.
78 * @param fieldName - Name of the field.
79 * @param enumType - Enum type of this field.
80 * @param isNullable - Whether the field is nullable.
81 * @returns A collection field with the given collection type.
82 */
83 FieldBuilder.prototype.buildEnumField = function (fieldName, enumType, isNullable) {
84 var isSelectable = (this.fieldOf instanceof
85 complex_type_field_1.ComplexTypeField);
86 return new enum_field_1.EnumField(fieldName, this.fieldOf, enumType, {
87 isNullable: isNullable,
88 isSelectable: isSelectable
89 });
90 };
91 return FieldBuilder;
92}());
93exports.FieldBuilder = FieldBuilder;
94//# sourceMappingURL=field-builder.js.map
\No newline at end of file