@api-client/core 0.11.3 → 0.11.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/modeling/DataAssociation.d.ts +5 -1
- package/build/src/modeling/DataAssociation.d.ts.map +1 -1
- package/build/src/modeling/DataAssociation.js +10 -4
- package/build/src/modeling/DataAssociation.js.map +1 -1
- package/build/src/modeling/DataEntity.d.ts +5 -1
- package/build/src/modeling/DataEntity.d.ts.map +1 -1
- package/build/src/modeling/DataEntity.js +15 -8
- package/build/src/modeling/DataEntity.js.map +1 -1
- package/build/src/modeling/DataModel.d.ts +15 -2
- package/build/src/modeling/DataModel.d.ts.map +1 -1
- package/build/src/modeling/DataModel.js +47 -4
- package/build/src/modeling/DataModel.js.map +1 -1
- package/build/src/modeling/DataNamespace.d.ts +26 -1
- package/build/src/modeling/DataNamespace.d.ts.map +1 -1
- package/build/src/modeling/DataNamespace.js +89 -1
- package/build/src/modeling/DataNamespace.js.map +1 -1
- package/build/src/modeling/DataProperty.js +2 -2
- package/build/src/modeling/DataProperty.js.map +1 -1
- package/data/models/example-generator-api.json +6 -6
- package/data/models/multiple-servers.json +16 -0
- package/data/models/petstore.json +92 -7
- package/package.json +1 -1
- package/src/modeling/DataAssociation.ts +11 -4
- package/src/modeling/DataEntity.ts +16 -8
- package/src/modeling/DataModel.ts +49 -5
- package/src/modeling/DataNamespace.ts +97 -1
- package/src/modeling/DataProperty.ts +2 -2
- package/tests/unit/modeling/data_association.spec.ts +2 -2
- package/tests/unit/modeling/data_entity.spec.ts +3 -3
- package/tests/unit/modeling/data_model.spec.ts +57 -3
- package/tests/unit/modeling/data_namespace.spec.ts +210 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataProperty.js","sourceRoot":"","sources":["../../../src/modeling/DataProperty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAU,KAAK,EAAE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;YAClD,OAAO,IAAI,CAAA;QACb,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;QAClB,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAgC,CAAA;QACvF,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAqB,CAAA;YACvD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC,MAA6B,CAAA;IAC7C,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,IAAwB;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAoB,CAAA;QAC1E,OAAO,IAAI,EAAE,MAAM,CAAA;IACrB,CAAC;CACF","sourcesContent":["import { Json } from '@api-client/json'\nimport { IThing, Thing } from '../models/Thing.js'\nimport v4 from '../lib/uuid.js'\nimport { DataNamespace } from './DataNamespace.js'\nimport { IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport { AmfShapeGenerator } from '../amf/AmfShapeGenerator.js'\nimport { PropertyBinding, PropertyBindings, PropertyWebBindings } from './Bindings.js'\nimport { DataPropertyKind } from '../models/kinds.js'\nimport {\n type BinaryFormat,\n BinaryFormats,\n type DataPropertyAttribute,\n DataPropertyAttributes,\n type DataPropertyFormat,\n DataPropertyList,\n type DataPropertyType,\n DataPropertyTypes,\n type NumberFormat,\n NumberFormats,\n} from './DataFormat.js'\n\n/**\n * Describes the default value set on a property schema.\n */\nexport interface SchemaDefaultValue {\n /**\n * The type of the default value.\n *\n * - `literal` The `value` should be used as-is.\n * - `function` The value represents the name of the function to be used.\n */\n type: 'literal' | 'function'\n /**\n * The actual value type depends on the `type`.\n * It is always a string and it has to be casted to the property's data type.\n */\n value: string\n}\n\n/**\n * A general schema definition for a property.\n * This is propagated to all bindings (when they support these properties).\n */\nexport interface DataPropertySchema {\n /**\n * The minimum value of the property.\n *\n * By default it is inclusive value. Use the `exclusiveMinimum` property to make it exclusive.\n *\n * Used with:\n * - string\n * - number\n * - date\n * - time\n * - datetime\n */\n minimum?: number\n /**\n * The maximum value of the property.\n *\n * By default it is inclusive value. Use the `exclusiveMaximum` property to make it exclusive.\n *\n * Used with:\n * - string\n * - number\n * - date\n * - time\n * - datetime\n */\n maximum?: number\n /**\n * When set, the minimum value is exclusive.\n *\n * - When `false`: value ≥ minimum.\n * - When `true`: value > minimum.\n */\n exclusiveMinimum?: boolean\n /**\n * When set, the exclusiveMaximum value is exclusive.\n *\n * - When `false`: value ≤ maximum.\n * - When `true`: value < minimum.\n */\n exclusiveMaximum?: boolean\n /**\n * The multiplier value for a number scalar.\n *\n * Examples:\n * - if `1` then every integer is allowed\n * - if `2` than every even number is allowed\n * - if `0.5` than every number difidable by `0.5` is allowed\n */\n multipleOf?: number\n /**\n * The enum values for the property.\n * They are always encoded as strings. The actual type is defined in the `dataType` property.\n */\n enum?: string[]\n /**\n * The default value for the property.\n * This is always encoded as a string. The actual type is defined in the `dataType` property.\n */\n defaultValue?: SchemaDefaultValue\n /**\n * The example values for the property.\n * They are always encoded as strings. The actual type is defined in the `dataType` property.\n */\n examples?: string[]\n}\n\nexport interface IDataProperty {\n kind: typeof DataPropertyKind\n /**\n * The key of the namespace.\n */\n key: string\n /**\n * The data property description.\n */\n info: IThing\n /**\n * Wether the data property is required.\n */\n required?: boolean\n /**\n * Whether the data property allows multiple items.\n */\n multiple?: boolean\n /**\n * Whether this property describes a primary key of the entity.\n */\n primary?: boolean\n /**\n * Whether this property describes an indexed property of the entity.\n */\n index?: boolean\n /**\n * Whether the property is read only in the schema.\n */\n readOnly?: boolean\n /**\n * Whether the property is write only in the schema.\n */\n writeOnly?: boolean\n /**\n * Whether this property is deprecated.\n */\n deprecated?: boolean\n /**\n * Optional general purpose tags for the UI.\n */\n tags?: string[]\n /**\n * For future use.\n *\n * The keys of the taxonomy items associated with the property.\n */\n taxonomy?: string[]\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers, but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n type: DataPropertyType\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n schema?: DataPropertySchema\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n bindings?: PropertyBinding[]\n}\n\nexport class DataProperty {\n kind = DataPropertyKind\n\n key = ''\n\n /**\n * The description of the data namespace.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * Wether the data property is required.\n */\n required?: boolean\n\n /**\n * Whether the data property allows multiple items.\n */\n multiple?: boolean\n\n /**\n * Whether this property describes a primary key of the entity.\n */\n primary?: boolean\n\n /**\n * Whether this property describes an indexed property of the entity.\n */\n index?: boolean\n\n /**\n * Whether the property is read only in the schema.\n */\n readOnly?: boolean\n\n /**\n * Whether the property is write only in the schema.\n */\n writeOnly?: boolean\n\n /**\n * Whether this property is deprecated.\n */\n deprecated?: boolean\n\n /**\n * Optional general purpose tags for the UI.\n *\n * Note to implementations, use the `addTag()` method as it propagates the \"tag\" value in the namespace.\n */\n tags: string[] = []\n\n /**\n * Reserved for future use.\n *\n * The keys of the taxonomy items associated with the property.\n */\n taxonomy: string[] = []\n\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n type: DataPropertyType = 'string'\n\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n schema?: DataPropertySchema\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n bindings: PropertyBinding[] = []\n\n /**\n * @deprecated Use the direct import of types.\n */\n static get supportedTypes(): DataPropertyType[] {\n return [...DataPropertyTypes]\n }\n\n static fromName(root: DataNamespace, name: string): DataProperty {\n const property = new DataProperty(root)\n property.info = Thing.fromName(name)\n return property\n }\n\n static fromType(root: DataNamespace, type: DataPropertyType): DataProperty {\n const result = new DataProperty(root)\n result.type = type\n return result\n }\n\n /**\n * @param input The data property definition to restore.\n */\n constructor(\n public root: DataNamespace,\n input?: string | IDataProperty\n ) {\n let init: IDataProperty\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: DataPropertyKind,\n key: v4(),\n info: Thing.fromName('').toJSON(),\n type: 'string',\n }\n }\n this.new(init)\n }\n\n new(init: IDataProperty): void {\n if (!DataProperty.isDataProperty(init)) {\n throw new Error(`Not a data property.`)\n }\n const {\n info,\n key = v4(),\n kind = DataPropertyKind,\n multiple,\n required,\n type = DataPropertyList.string,\n index,\n primary,\n readOnly,\n writeOnly,\n tags,\n taxonomy,\n deprecated,\n schema,\n bindings,\n } = init\n this.kind = kind\n this.key = key\n this.type = type\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n if (typeof multiple === 'boolean') {\n this.multiple = multiple\n } else {\n this.multiple = undefined\n }\n if (typeof required === 'boolean') {\n this.required = required\n } else {\n this.required = undefined\n }\n if (typeof index === 'boolean') {\n this.index = index\n } else {\n this.index = undefined\n }\n if (typeof deprecated === 'boolean') {\n this.deprecated = deprecated\n } else {\n this.deprecated = undefined\n }\n if (typeof primary === 'boolean') {\n this.primary = primary\n } else {\n this.primary = undefined\n }\n if (typeof readOnly === 'boolean') {\n this.readOnly = readOnly\n } else {\n this.readOnly = undefined\n }\n if (typeof writeOnly === 'boolean') {\n this.writeOnly = writeOnly\n } else {\n this.writeOnly = undefined\n }\n if (Array.isArray(tags)) {\n this.tags = [...tags]\n } else {\n this.tags = []\n }\n if (Array.isArray(taxonomy)) {\n this.taxonomy = [...taxonomy]\n } else {\n this.taxonomy = []\n }\n if (schema) {\n this.schema = Json.clone(schema)\n } else {\n this.schema = undefined\n }\n if (Array.isArray(bindings)) {\n this.bindings = bindings.map((i) => Json.clone(i))\n } else {\n this.bindings = []\n }\n }\n\n static isDataProperty(input: unknown): boolean {\n const typed = input as IDataProperty\n if (!input || typed.kind !== DataPropertyKind) {\n return false\n }\n return true\n }\n\n toJSON(): IDataProperty {\n const result: IDataProperty = {\n kind: DataPropertyKind,\n info: this.info.toJSON(),\n key: this.key,\n type: this.type || DataPropertyList.string,\n }\n if (typeof this.index === 'boolean') {\n result.index = this.index\n }\n if (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n if (typeof this.primary === 'boolean') {\n result.primary = this.primary\n }\n if (typeof this.multiple === 'boolean') {\n result.multiple = this.multiple\n }\n if (typeof this.required === 'boolean') {\n result.required = this.required\n }\n if (typeof this.readOnly === 'boolean') {\n result.readOnly = this.readOnly\n }\n if (typeof this.writeOnly === 'boolean') {\n result.writeOnly = this.writeOnly\n }\n if (Array.isArray(this.tags) && this.tags.length) {\n result.tags = [...this.tags]\n }\n if (Array.isArray(this.taxonomy) && this.taxonomy.length) {\n result.taxonomy = [...this.taxonomy]\n }\n if (this.schema) {\n result.schema = Json.clone(this.schema)\n }\n if (Array.isArray(this.bindings) && this.bindings.length) {\n result.bindings = this.bindings.map((i) => Json.clone(i))\n }\n return result\n }\n\n /**\n * Removes self from the parent entity and the namespace definition.\n */\n remove(): void {\n const { root } = this\n const entity = root.definitions.entities.find((i) => i.properties.some((j) => j === this))\n if (entity) {\n const assocIndex = entity.properties.findIndex((i) => i === this)\n entity.properties.splice(assocIndex, 1)\n }\n const defIndex = this.root.definitions.properties.findIndex((i) => i.key === this.key)\n if (defIndex >= 0) {\n this.root.definitions.properties.splice(defIndex, 1)\n }\n }\n\n /**\n * Adds a new tag to the property. It also populates the root namespace's tags when tag is new.\n *\n * Note, it does nothing when the tag is already defined.\n *\n * @param tag The tag to add.\n */\n addTag(tag: string): void {\n if (!tag) {\n return\n }\n const lower = tag.toLowerCase()\n const { tags } = this\n if (tags.some((t) => t.toLowerCase() === lower)) {\n return\n }\n tags.push(tag)\n const { definitions } = this.root\n if (!definitions.tags.some((t) => t.toLowerCase() === lower)) {\n definitions.tags.push(tag)\n }\n }\n\n /**\n * Removes a tag from the property. Unlike the `addTag()` this won't remove a `tag` from the root namespace.\n *\n * @param tag The tag to remove.\n */\n removeTag(tag: string): void {\n if (!tag) {\n return\n }\n const lower = tag.toLowerCase()\n const { tags } = this\n const index = tags.findIndex((t) => t.toLowerCase() === lower)\n if (index >= 0) {\n tags.splice(index, 1)\n }\n }\n\n /**\n * Creates a Property Shape of AMF.\n * The property itself is auto-generated. If the `schema` is defined then it is used\n * as the `range` of the property. Otherwise basic shape is generated for the range.\n *\n * This is a preferred way of reading the AMF shape as this synchronizes changed\n * data properties with the shape definition.\n *\n * @returns AMF property shape definition.\n */\n toApiShape(): IApiPropertyShape {\n const serializer = new AmfShapeGenerator()\n return serializer.property(this)\n }\n\n /**\n * Checks whether the passed value is one of the supported data types.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data types.\n */\n static isValidType(value: unknown): value is DataPropertyType {\n if (typeof value !== 'string') {\n return false\n }\n return DataPropertyTypes.includes(value as DataPropertyType)\n }\n\n /**\n * Checks whether the passed value is one of the supported data proprty attributes.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data proprty attributes.\n */\n static isValidAttribute(value: unknown): value is DataPropertyAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DataPropertyAttributes.includes(value as DataPropertyAttribute)\n }\n\n /**\n * Checks whether the passed value of one of the supported `format` values.\n *\n * @param value The value to test\n * @returns `true` when the value is one of the supported `format` values.\n */\n static isValidFormat(value: unknown): value is DataPropertyFormat {\n if (value === undefined) {\n // It is the valid value.\n return true\n }\n if (typeof value !== 'string') {\n return false\n }\n if (NumberFormats.includes(value as NumberFormat)) {\n return true\n }\n if (BinaryFormats.includes(value as BinaryFormat)) {\n return true\n }\n return false\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n * @returns The schema object.\n */\n ensureSchema(): DataPropertySchema {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\n }\n\n /**\n * Creates if not existing and returns web bindings definition.\n * @returns The web binding definition\n */\n getWebBinding(): PropertyWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as PropertyBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as PropertyBinding\n this.bindings.push(object)\n }\n return object.schema as PropertyWebBindings\n }\n\n /**\n * Returns the schema value of the binding, if any was created.\n * @param type The type of the binding to read.\n * @returns The binding schema, if any\n */\n readBinding(type: 'web' | 'protobuf'): PropertyBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as PropertyBinding\n return item?.schema\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DataProperty.js","sourceRoot":"","sources":["../../../src/modeling/DataProperty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAU,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAG/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OA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AAE,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;QAClB,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAgC,CAAA;QACvF,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAqB,CAAA;YACvD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC,MAA6B,CAAA;IAC7C,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,IAAwB;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAoB,CAAA;QAC1E,OAAO,IAAI,EAAE,MAAM,CAAA;IACrB,CAAC;CACF","sourcesContent":["import { Json } from '@api-client/json'\nimport { IThing, Thing } from '../models/Thing.js'\nimport v4 from '../lib/uuid.js'\nimport { DataNamespace } from './DataNamespace.js'\nimport { IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport { AmfShapeGenerator } from '../amf/AmfShapeGenerator.js'\nimport { PropertyBinding, PropertyBindings, PropertyWebBindings } from './Bindings.js'\nimport { DataPropertyKind } from '../models/kinds.js'\nimport {\n type BinaryFormat,\n BinaryFormats,\n type DataPropertyAttribute,\n DataPropertyAttributes,\n type DataPropertyFormat,\n DataPropertyList,\n type DataPropertyType,\n DataPropertyTypes,\n type NumberFormat,\n NumberFormats,\n} from './DataFormat.js'\n\n/**\n * Describes the default value set on a property schema.\n */\nexport interface SchemaDefaultValue {\n /**\n * The type of the default value.\n *\n * - `literal` The `value` should be used as-is.\n * - `function` The value represents the name of the function to be used.\n */\n type: 'literal' | 'function'\n /**\n * The actual value type depends on the `type`.\n * It is always a string and it has to be casted to the property's data type.\n */\n value: string\n}\n\n/**\n * A general schema definition for a property.\n * This is propagated to all bindings (when they support these properties).\n */\nexport interface DataPropertySchema {\n /**\n * The minimum value of the property.\n *\n * By default it is inclusive value. Use the `exclusiveMinimum` property to make it exclusive.\n *\n * Used with:\n * - string\n * - number\n * - date\n * - time\n * - datetime\n */\n minimum?: number\n /**\n * The maximum value of the property.\n *\n * By default it is inclusive value. Use the `exclusiveMaximum` property to make it exclusive.\n *\n * Used with:\n * - string\n * - number\n * - date\n * - time\n * - datetime\n */\n maximum?: number\n /**\n * When set, the minimum value is exclusive.\n *\n * - When `false`: value ≥ minimum.\n * - When `true`: value > minimum.\n */\n exclusiveMinimum?: boolean\n /**\n * When set, the exclusiveMaximum value is exclusive.\n *\n * - When `false`: value ≤ maximum.\n * - When `true`: value < minimum.\n */\n exclusiveMaximum?: boolean\n /**\n * The multiplier value for a number scalar.\n *\n * Examples:\n * - if `1` then every integer is allowed\n * - if `2` than every even number is allowed\n * - if `0.5` than every number difidable by `0.5` is allowed\n */\n multipleOf?: number\n /**\n * The enum values for the property.\n * They are always encoded as strings. The actual type is defined in the `dataType` property.\n */\n enum?: string[]\n /**\n * The default value for the property.\n * This is always encoded as a string. The actual type is defined in the `dataType` property.\n */\n defaultValue?: SchemaDefaultValue\n /**\n * The example values for the property.\n * They are always encoded as strings. The actual type is defined in the `dataType` property.\n */\n examples?: string[]\n}\n\nexport interface IDataProperty {\n kind: typeof DataPropertyKind\n /**\n * The key of the namespace.\n */\n key: string\n /**\n * The data property description.\n */\n info: IThing\n /**\n * Wether the data property is required.\n */\n required?: boolean\n /**\n * Whether the data property allows multiple items.\n */\n multiple?: boolean\n /**\n * Whether this property describes a primary key of the entity.\n */\n primary?: boolean\n /**\n * Whether this property describes an indexed property of the entity.\n */\n index?: boolean\n /**\n * Whether the property is read only in the schema.\n */\n readOnly?: boolean\n /**\n * Whether the property is write only in the schema.\n */\n writeOnly?: boolean\n /**\n * Whether this property is deprecated.\n */\n deprecated?: boolean\n /**\n * Optional general purpose tags for the UI.\n */\n tags?: string[]\n /**\n * For future use.\n *\n * The keys of the taxonomy items associated with the property.\n */\n taxonomy?: string[]\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers, but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n type: DataPropertyType\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n schema?: DataPropertySchema\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n bindings?: PropertyBinding[]\n}\n\nexport class DataProperty {\n kind = DataPropertyKind\n\n key = ''\n\n /**\n * The description of the data namespace.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * Wether the data property is required.\n */\n required?: boolean\n\n /**\n * Whether the data property allows multiple items.\n */\n multiple?: boolean\n\n /**\n * Whether this property describes a primary key of the entity.\n */\n primary?: boolean\n\n /**\n * Whether this property describes an indexed property of the entity.\n */\n index?: boolean\n\n /**\n * Whether the property is read only in the schema.\n */\n readOnly?: boolean\n\n /**\n * Whether the property is write only in the schema.\n */\n writeOnly?: boolean\n\n /**\n * Whether this property is deprecated.\n */\n deprecated?: boolean\n\n /**\n * Optional general purpose tags for the UI.\n *\n * Note to implementations, use the `addTag()` method as it propagates the \"tag\" value in the namespace.\n */\n tags: string[] = []\n\n /**\n * Reserved for future use.\n *\n * The keys of the taxonomy items associated with the property.\n */\n taxonomy: string[] = []\n\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n type: DataPropertyType = 'string'\n\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n schema?: DataPropertySchema\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n bindings: PropertyBinding[] = []\n\n /**\n * @deprecated Use the direct import of types.\n */\n static get supportedTypes(): DataPropertyType[] {\n return [...DataPropertyTypes]\n }\n\n static fromName(root: DataNamespace, name: string): DataProperty {\n const property = new DataProperty(root)\n property.info = Thing.fromName(name)\n return property\n }\n\n static fromType(root: DataNamespace, type: DataPropertyType): DataProperty {\n const result = new DataProperty(root)\n result.type = type\n return result\n }\n\n /**\n * @param input The data property definition to restore.\n */\n constructor(\n public root: DataNamespace,\n input?: string | IDataProperty\n ) {\n let init: IDataProperty\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: DataPropertyKind,\n key: v4(),\n info: Thing.fromName('').toJSON(),\n type: 'string',\n }\n }\n this.new(init)\n }\n\n new(init: IDataProperty): void {\n if (!DataProperty.isDataProperty(init)) {\n throw new Error(`Not a data property.`)\n }\n const {\n info,\n key = v4(),\n kind = DataPropertyKind,\n multiple,\n required,\n type = DataPropertyList.string,\n index,\n primary,\n readOnly,\n writeOnly,\n tags,\n taxonomy,\n deprecated,\n schema,\n bindings,\n } = init\n this.kind = kind\n this.key = key\n this.type = type\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n if (typeof multiple === 'boolean') {\n this.multiple = multiple\n } else {\n this.multiple = undefined\n }\n if (typeof required === 'boolean') {\n this.required = required\n } else {\n this.required = undefined\n }\n if (typeof index === 'boolean') {\n this.index = index\n } else {\n this.index = undefined\n }\n if (typeof deprecated === 'boolean') {\n this.deprecated = deprecated\n } else {\n this.deprecated = undefined\n }\n if (typeof primary === 'boolean') {\n this.primary = primary\n } else {\n this.primary = undefined\n }\n if (typeof readOnly === 'boolean') {\n this.readOnly = readOnly\n } else {\n this.readOnly = undefined\n }\n if (typeof writeOnly === 'boolean') {\n this.writeOnly = writeOnly\n } else {\n this.writeOnly = undefined\n }\n if (Array.isArray(tags)) {\n this.tags = [...tags]\n } else {\n this.tags = []\n }\n if (Array.isArray(taxonomy)) {\n this.taxonomy = [...taxonomy]\n } else {\n this.taxonomy = []\n }\n if (schema) {\n this.schema = Json.clone(schema)\n } else {\n this.schema = undefined\n }\n if (Array.isArray(bindings)) {\n this.bindings = bindings.map((i) => Json.clone(i))\n } else {\n this.bindings = []\n }\n }\n\n static isDataProperty(input: unknown): boolean {\n const typed = input as IDataProperty\n if (!input || typed.kind !== DataPropertyKind) {\n return false\n }\n return true\n }\n\n toJSON(): IDataProperty {\n const result: IDataProperty = {\n kind: DataPropertyKind,\n info: this.info.toJSON(),\n key: this.key,\n type: this.type || DataPropertyList.string,\n }\n if (typeof this.index === 'boolean') {\n result.index = this.index\n }\n if (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n if (typeof this.primary === 'boolean') {\n result.primary = this.primary\n }\n if (typeof this.multiple === 'boolean') {\n result.multiple = this.multiple\n }\n if (typeof this.required === 'boolean') {\n result.required = this.required\n }\n if (typeof this.readOnly === 'boolean') {\n result.readOnly = this.readOnly\n }\n if (typeof this.writeOnly === 'boolean') {\n result.writeOnly = this.writeOnly\n }\n if (Array.isArray(this.tags) && this.tags.length) {\n result.tags = [...this.tags]\n }\n if (Array.isArray(this.taxonomy) && this.taxonomy.length) {\n result.taxonomy = [...this.taxonomy]\n }\n if (this.schema) {\n result.schema = Json.clone(this.schema)\n }\n if (Array.isArray(this.bindings) && this.bindings.length) {\n result.bindings = this.bindings.map((i) => Json.clone(i))\n }\n return result\n }\n\n /**\n * Removes self from the parent entity and the namespace definition.\n */\n remove(): void {\n const { root } = this\n const entity = root.definitions.entities.find((i) => i.properties.some((j) => j.key === this.key))\n if (entity) {\n const assocIndex = entity.properties.findIndex((i) => i.key === this.key)\n entity.properties.splice(assocIndex, 1)\n }\n const defIndex = this.root.definitions.properties.findIndex((i) => i.key === this.key)\n if (defIndex >= 0) {\n this.root.definitions.properties.splice(defIndex, 1)\n }\n }\n\n /**\n * Adds a new tag to the property. It also populates the root namespace's tags when tag is new.\n *\n * Note, it does nothing when the tag is already defined.\n *\n * @param tag The tag to add.\n */\n addTag(tag: string): void {\n if (!tag) {\n return\n }\n const lower = tag.toLowerCase()\n const { tags } = this\n if (tags.some((t) => t.toLowerCase() === lower)) {\n return\n }\n tags.push(tag)\n const { definitions } = this.root\n if (!definitions.tags.some((t) => t.toLowerCase() === lower)) {\n definitions.tags.push(tag)\n }\n }\n\n /**\n * Removes a tag from the property. Unlike the `addTag()` this won't remove a `tag` from the root namespace.\n *\n * @param tag The tag to remove.\n */\n removeTag(tag: string): void {\n if (!tag) {\n return\n }\n const lower = tag.toLowerCase()\n const { tags } = this\n const index = tags.findIndex((t) => t.toLowerCase() === lower)\n if (index >= 0) {\n tags.splice(index, 1)\n }\n }\n\n /**\n * Creates a Property Shape of AMF.\n * The property itself is auto-generated. If the `schema` is defined then it is used\n * as the `range` of the property. Otherwise basic shape is generated for the range.\n *\n * This is a preferred way of reading the AMF shape as this synchronizes changed\n * data properties with the shape definition.\n *\n * @returns AMF property shape definition.\n */\n toApiShape(): IApiPropertyShape {\n const serializer = new AmfShapeGenerator()\n return serializer.property(this)\n }\n\n /**\n * Checks whether the passed value is one of the supported data types.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data types.\n */\n static isValidType(value: unknown): value is DataPropertyType {\n if (typeof value !== 'string') {\n return false\n }\n return DataPropertyTypes.includes(value as DataPropertyType)\n }\n\n /**\n * Checks whether the passed value is one of the supported data proprty attributes.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data proprty attributes.\n */\n static isValidAttribute(value: unknown): value is DataPropertyAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DataPropertyAttributes.includes(value as DataPropertyAttribute)\n }\n\n /**\n * Checks whether the passed value of one of the supported `format` values.\n *\n * @param value The value to test\n * @returns `true` when the value is one of the supported `format` values.\n */\n static isValidFormat(value: unknown): value is DataPropertyFormat {\n if (value === undefined) {\n // It is the valid value.\n return true\n }\n if (typeof value !== 'string') {\n return false\n }\n if (NumberFormats.includes(value as NumberFormat)) {\n return true\n }\n if (BinaryFormats.includes(value as BinaryFormat)) {\n return true\n }\n return false\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n * @returns The schema object.\n */\n ensureSchema(): DataPropertySchema {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\n }\n\n /**\n * Creates if not existing and returns web bindings definition.\n * @returns The web binding definition\n */\n getWebBinding(): PropertyWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as PropertyBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as PropertyBinding\n this.bindings.push(object)\n }\n return object.schema as PropertyWebBindings\n }\n\n /**\n * Returns the schema value of the binding, if any was created.\n * @param type The type of the binding to read.\n * @returns The binding schema, if any\n */\n readBinding(type: 'web' | 'protobuf'): PropertyBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as PropertyBinding\n return item?.schema\n }\n}\n"]}
|
|
@@ -42476,10 +42476,10 @@
|
|
|
42476
42476
|
"@id": "#219"
|
|
42477
42477
|
},
|
|
42478
42478
|
{
|
|
42479
|
-
"@id": "#
|
|
42479
|
+
"@id": "#213"
|
|
42480
42480
|
},
|
|
42481
42481
|
{
|
|
42482
|
-
"@id": "#
|
|
42482
|
+
"@id": "#216"
|
|
42483
42483
|
}
|
|
42484
42484
|
],
|
|
42485
42485
|
"doc:root": false,
|
|
@@ -43913,7 +43913,7 @@
|
|
|
43913
43913
|
"doc:ExternalDomainElement",
|
|
43914
43914
|
"doc:DomainElement"
|
|
43915
43915
|
],
|
|
43916
|
-
"doc:raw": "type:
|
|
43916
|
+
"doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
|
|
43917
43917
|
"core:mediaType": "application/yaml",
|
|
43918
43918
|
"sourcemaps:sources": [
|
|
43919
43919
|
{
|
|
@@ -43934,7 +43934,7 @@
|
|
|
43934
43934
|
"doc:ExternalDomainElement",
|
|
43935
43935
|
"doc:DomainElement"
|
|
43936
43936
|
],
|
|
43937
|
-
"doc:raw": "
|
|
43937
|
+
"doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
|
|
43938
43938
|
"core:mediaType": "application/yaml",
|
|
43939
43939
|
"sourcemaps:sources": [
|
|
43940
43940
|
{
|
|
@@ -44781,12 +44781,12 @@
|
|
|
44781
44781
|
{
|
|
44782
44782
|
"@id": "#215/source-map/lexical/element_0",
|
|
44783
44783
|
"sourcemaps:element": "amf://id#215",
|
|
44784
|
-
"sourcemaps:value": "[(1,0)-(
|
|
44784
|
+
"sourcemaps:value": "[(1,0)-(7,0)]"
|
|
44785
44785
|
},
|
|
44786
44786
|
{
|
|
44787
44787
|
"@id": "#218/source-map/lexical/element_0",
|
|
44788
44788
|
"sourcemaps:element": "amf://id#218",
|
|
44789
|
-
"sourcemaps:value": "[(1,0)-(
|
|
44789
|
+
"sourcemaps:value": "[(1,0)-(3,0)]"
|
|
44790
44790
|
},
|
|
44791
44791
|
{
|
|
44792
44792
|
"@id": "#221/source-map/lexical/element_0",
|
|
@@ -741,6 +741,9 @@
|
|
|
741
741
|
],
|
|
742
742
|
"sourcemaps:lexical": [
|
|
743
743
|
{
|
|
744
|
+
"@id": "#34/source-map/lexical/element_1"
|
|
745
|
+
},
|
|
746
|
+
{
|
|
744
747
|
"@id": "#34/source-map/lexical/element_0"
|
|
745
748
|
}
|
|
746
749
|
]
|
|
@@ -1009,6 +1012,9 @@
|
|
|
1009
1012
|
],
|
|
1010
1013
|
"sourcemaps:lexical": [
|
|
1011
1014
|
{
|
|
1015
|
+
"@id": "#49/source-map/lexical/element_1"
|
|
1016
|
+
},
|
|
1017
|
+
{
|
|
1012
1018
|
"@id": "#49/source-map/lexical/element_0"
|
|
1013
1019
|
}
|
|
1014
1020
|
]
|
|
@@ -1188,6 +1194,11 @@
|
|
|
1188
1194
|
]
|
|
1189
1195
|
},
|
|
1190
1196
|
{
|
|
1197
|
+
"@id": "#34/source-map/lexical/element_1",
|
|
1198
|
+
"sourcemaps:element": "amf://id#34",
|
|
1199
|
+
"sourcemaps:value": "[(17,6)-(25,0)]"
|
|
1200
|
+
},
|
|
1201
|
+
{
|
|
1191
1202
|
"@id": "#34/source-map/lexical/element_0",
|
|
1192
1203
|
"sourcemaps:element": "apiContract:parameter",
|
|
1193
1204
|
"sourcemaps:value": "[(17,6)-(25,0)]"
|
|
@@ -1487,6 +1498,11 @@
|
|
|
1487
1498
|
]
|
|
1488
1499
|
},
|
|
1489
1500
|
{
|
|
1501
|
+
"@id": "#49/source-map/lexical/element_1",
|
|
1502
|
+
"sourcemaps:element": "amf://id#49",
|
|
1503
|
+
"sourcemaps:value": "[(63,6)-(70,0)]"
|
|
1504
|
+
},
|
|
1505
|
+
{
|
|
1490
1506
|
"@id": "#49/source-map/lexical/element_0",
|
|
1491
1507
|
"sourcemaps:element": "apiContract:uriParameter",
|
|
1492
1508
|
"sourcemaps:value": "[(63,6)-(70,0)]"
|
|
@@ -4447,6 +4447,11 @@
|
|
|
4447
4447
|
{
|
|
4448
4448
|
"@id": "#547"
|
|
4449
4449
|
}
|
|
4450
|
+
],
|
|
4451
|
+
"sourcemaps:sources": [
|
|
4452
|
+
{
|
|
4453
|
+
"@id": "#546/source-map"
|
|
4454
|
+
}
|
|
4450
4455
|
]
|
|
4451
4456
|
},
|
|
4452
4457
|
{
|
|
@@ -5259,6 +5264,9 @@
|
|
|
5259
5264
|
],
|
|
5260
5265
|
"sourcemaps:lexical": [
|
|
5261
5266
|
{
|
|
5267
|
+
"@id": "#295/source-map/lexical/element_1"
|
|
5268
|
+
},
|
|
5269
|
+
{
|
|
5262
5270
|
"@id": "#295/source-map/lexical/element_0"
|
|
5263
5271
|
}
|
|
5264
5272
|
]
|
|
@@ -5442,6 +5450,9 @@
|
|
|
5442
5450
|
],
|
|
5443
5451
|
"sourcemaps:lexical": [
|
|
5444
5452
|
{
|
|
5453
|
+
"@id": "#319/source-map/lexical/element_1"
|
|
5454
|
+
},
|
|
5455
|
+
{
|
|
5445
5456
|
"@id": "#319/source-map/lexical/element_0"
|
|
5446
5457
|
}
|
|
5447
5458
|
]
|
|
@@ -5623,6 +5634,9 @@
|
|
|
5623
5634
|
],
|
|
5624
5635
|
"sourcemaps:lexical": [
|
|
5625
5636
|
{
|
|
5637
|
+
"@id": "#337/source-map/lexical/element_1"
|
|
5638
|
+
},
|
|
5639
|
+
{
|
|
5626
5640
|
"@id": "#337/source-map/lexical/element_0"
|
|
5627
5641
|
}
|
|
5628
5642
|
]
|
|
@@ -5948,13 +5962,16 @@
|
|
|
5948
5962
|
],
|
|
5949
5963
|
"sourcemaps:lexical": [
|
|
5950
5964
|
{
|
|
5951
|
-
"@id": "#351/source-map/lexical/
|
|
5965
|
+
"@id": "#351/source-map/lexical/element_3"
|
|
5966
|
+
},
|
|
5967
|
+
{
|
|
5968
|
+
"@id": "#351/source-map/lexical/element_1"
|
|
5952
5969
|
},
|
|
5953
5970
|
{
|
|
5954
5971
|
"@id": "#351/source-map/lexical/element_0"
|
|
5955
5972
|
},
|
|
5956
5973
|
{
|
|
5957
|
-
"@id": "#351/source-map/lexical/
|
|
5974
|
+
"@id": "#351/source-map/lexical/element_2"
|
|
5958
5975
|
}
|
|
5959
5976
|
]
|
|
5960
5977
|
},
|
|
@@ -6104,10 +6121,13 @@
|
|
|
6104
6121
|
],
|
|
6105
6122
|
"sourcemaps:lexical": [
|
|
6106
6123
|
{
|
|
6107
|
-
"@id": "#378/source-map/lexical/
|
|
6124
|
+
"@id": "#378/source-map/lexical/element_2"
|
|
6108
6125
|
},
|
|
6109
6126
|
{
|
|
6110
6127
|
"@id": "#378/source-map/lexical/element_0"
|
|
6128
|
+
},
|
|
6129
|
+
{
|
|
6130
|
+
"@id": "#378/source-map/lexical/element_1"
|
|
6111
6131
|
}
|
|
6112
6132
|
]
|
|
6113
6133
|
},
|
|
@@ -6921,6 +6941,9 @@
|
|
|
6921
6941
|
],
|
|
6922
6942
|
"sourcemaps:lexical": [
|
|
6923
6943
|
{
|
|
6944
|
+
"@id": "#456/source-map/lexical/element_1"
|
|
6945
|
+
},
|
|
6946
|
+
{
|
|
6924
6947
|
"@id": "#456/source-map/lexical/element_0"
|
|
6925
6948
|
}
|
|
6926
6949
|
]
|
|
@@ -7108,6 +7131,9 @@
|
|
|
7108
7131
|
],
|
|
7109
7132
|
"sourcemaps:lexical": [
|
|
7110
7133
|
{
|
|
7134
|
+
"@id": "#466/source-map/lexical/element_1"
|
|
7135
|
+
},
|
|
7136
|
+
{
|
|
7111
7137
|
"@id": "#466/source-map/lexical/element_0"
|
|
7112
7138
|
}
|
|
7113
7139
|
]
|
|
@@ -7655,6 +7681,9 @@
|
|
|
7655
7681
|
],
|
|
7656
7682
|
"sourcemaps:lexical": [
|
|
7657
7683
|
{
|
|
7684
|
+
"@id": "#509/source-map/lexical/element_1"
|
|
7685
|
+
},
|
|
7686
|
+
{
|
|
7658
7687
|
"@id": "#509/source-map/lexical/element_0"
|
|
7659
7688
|
}
|
|
7660
7689
|
]
|
|
@@ -8243,6 +8272,17 @@
|
|
|
8243
8272
|
]
|
|
8244
8273
|
},
|
|
8245
8274
|
{
|
|
8275
|
+
"@id": "#546/source-map",
|
|
8276
|
+
"@type": [
|
|
8277
|
+
"sourcemaps:SourceMap"
|
|
8278
|
+
],
|
|
8279
|
+
"sourcemaps:lexical": [
|
|
8280
|
+
{
|
|
8281
|
+
"@id": "#546/source-map/lexical/element_0"
|
|
8282
|
+
}
|
|
8283
|
+
]
|
|
8284
|
+
},
|
|
8285
|
+
{
|
|
8246
8286
|
"@id": "#544/source-map",
|
|
8247
8287
|
"@type": [
|
|
8248
8288
|
"sourcemaps:SourceMap"
|
|
@@ -9027,6 +9067,11 @@
|
|
|
9027
9067
|
]
|
|
9028
9068
|
},
|
|
9029
9069
|
{
|
|
9070
|
+
"@id": "#295/source-map/lexical/element_1",
|
|
9071
|
+
"sourcemaps:element": "amf://id#295",
|
|
9072
|
+
"sourcemaps:value": "[(121,6)-(135,0)]"
|
|
9073
|
+
},
|
|
9074
|
+
{
|
|
9030
9075
|
"@id": "#295/source-map/lexical/element_0",
|
|
9031
9076
|
"sourcemaps:element": "apiContract:parameter",
|
|
9032
9077
|
"sourcemaps:value": "[(121,6)-(135,0)]"
|
|
@@ -9234,6 +9279,11 @@
|
|
|
9234
9279
|
]
|
|
9235
9280
|
},
|
|
9236
9281
|
{
|
|
9282
|
+
"@id": "#319/source-map/lexical/element_1",
|
|
9283
|
+
"sourcemaps:element": "amf://id#319",
|
|
9284
|
+
"sourcemaps:value": "[(164,6)-(174,0)]"
|
|
9285
|
+
},
|
|
9286
|
+
{
|
|
9237
9287
|
"@id": "#319/source-map/lexical/element_0",
|
|
9238
9288
|
"sourcemaps:element": "apiContract:parameter",
|
|
9239
9289
|
"sourcemaps:value": "[(164,6)-(174,0)]"
|
|
@@ -9444,6 +9494,11 @@
|
|
|
9444
9494
|
]
|
|
9445
9495
|
},
|
|
9446
9496
|
{
|
|
9497
|
+
"@id": "#337/source-map/lexical/element_1",
|
|
9498
|
+
"sourcemaps:element": "amf://id#337",
|
|
9499
|
+
"sourcemaps:value": "[(201,6)-(209,0)]"
|
|
9500
|
+
},
|
|
9501
|
+
{
|
|
9447
9502
|
"@id": "#337/source-map/lexical/element_0",
|
|
9448
9503
|
"sourcemaps:element": "apiContract:uriParameter",
|
|
9449
9504
|
"sourcemaps:value": "[(201,6)-(209,0)]"
|
|
@@ -9901,18 +9956,23 @@
|
|
|
9901
9956
|
]
|
|
9902
9957
|
},
|
|
9903
9958
|
{
|
|
9904
|
-
"@id": "#351/source-map/lexical/
|
|
9959
|
+
"@id": "#351/source-map/lexical/element_3",
|
|
9905
9960
|
"sourcemaps:element": "apiContract:uriParameter",
|
|
9906
9961
|
"sourcemaps:value": "[(234,6)-(275,0)]"
|
|
9907
9962
|
},
|
|
9908
9963
|
{
|
|
9964
|
+
"@id": "#351/source-map/lexical/element_1",
|
|
9965
|
+
"sourcemaps:element": "apiContract:parameter",
|
|
9966
|
+
"sourcemaps:value": "[(234,6)-(275,0)]"
|
|
9967
|
+
},
|
|
9968
|
+
{
|
|
9909
9969
|
"@id": "#351/source-map/lexical/element_0",
|
|
9910
9970
|
"sourcemaps:element": "apiContract:cookieParameter",
|
|
9911
9971
|
"sourcemaps:value": "[(234,6)-(275,0)]"
|
|
9912
9972
|
},
|
|
9913
9973
|
{
|
|
9914
|
-
"@id": "#351/source-map/lexical/
|
|
9915
|
-
"sourcemaps:element": "
|
|
9974
|
+
"@id": "#351/source-map/lexical/element_2",
|
|
9975
|
+
"sourcemaps:element": "amf://id#351",
|
|
9916
9976
|
"sourcemaps:value": "[(234,6)-(275,0)]"
|
|
9917
9977
|
},
|
|
9918
9978
|
{
|
|
@@ -10087,7 +10147,7 @@
|
|
|
10087
10147
|
]
|
|
10088
10148
|
},
|
|
10089
10149
|
{
|
|
10090
|
-
"@id": "#378/source-map/lexical/
|
|
10150
|
+
"@id": "#378/source-map/lexical/element_2",
|
|
10091
10151
|
"sourcemaps:element": "apiContract:uriParameter",
|
|
10092
10152
|
"sourcemaps:value": "[(288,6)-(302,0)]"
|
|
10093
10153
|
},
|
|
@@ -10097,6 +10157,11 @@
|
|
|
10097
10157
|
"sourcemaps:value": "[(288,6)-(302,0)]"
|
|
10098
10158
|
},
|
|
10099
10159
|
{
|
|
10160
|
+
"@id": "#378/source-map/lexical/element_1",
|
|
10161
|
+
"sourcemaps:element": "amf://id#378",
|
|
10162
|
+
"sourcemaps:value": "[(288,6)-(302,0)]"
|
|
10163
|
+
},
|
|
10164
|
+
{
|
|
10100
10165
|
"@id": "#377/source-map/lexical/element_2",
|
|
10101
10166
|
"sourcemaps:element": "core:name",
|
|
10102
10167
|
"sourcemaps:value": "[(303,8)-(303,13)]"
|
|
@@ -10901,6 +10966,11 @@
|
|
|
10901
10966
|
]
|
|
10902
10967
|
},
|
|
10903
10968
|
{
|
|
10969
|
+
"@id": "#456/source-map/lexical/element_1",
|
|
10970
|
+
"sourcemaps:element": "amf://id#456",
|
|
10971
|
+
"sourcemaps:value": "[(443,6)-(451,0)]"
|
|
10972
|
+
},
|
|
10973
|
+
{
|
|
10904
10974
|
"@id": "#456/source-map/lexical/element_0",
|
|
10905
10975
|
"sourcemaps:element": "apiContract:uriParameter",
|
|
10906
10976
|
"sourcemaps:value": "[(443,6)-(451,0)]"
|
|
@@ -11069,6 +11139,11 @@
|
|
|
11069
11139
|
]
|
|
11070
11140
|
},
|
|
11071
11141
|
{
|
|
11142
|
+
"@id": "#466/source-map/lexical/element_1",
|
|
11143
|
+
"sourcemaps:element": "amf://id#466",
|
|
11144
|
+
"sourcemaps:value": "[(474,6)-(482,0)]"
|
|
11145
|
+
},
|
|
11146
|
+
{
|
|
11072
11147
|
"@id": "#466/source-map/lexical/element_0",
|
|
11073
11148
|
"sourcemaps:element": "apiContract:uriParameter",
|
|
11074
11149
|
"sourcemaps:value": "[(474,6)-(482,0)]"
|
|
@@ -11641,6 +11716,11 @@
|
|
|
11641
11716
|
]
|
|
11642
11717
|
},
|
|
11643
11718
|
{
|
|
11719
|
+
"@id": "#509/source-map/lexical/element_1",
|
|
11720
|
+
"sourcemaps:element": "amf://id#509",
|
|
11721
|
+
"sourcemaps:value": "[(564,6)-(577,0)]"
|
|
11722
|
+
},
|
|
11723
|
+
{
|
|
11644
11724
|
"@id": "#509/source-map/lexical/element_0",
|
|
11645
11725
|
"sourcemaps:element": "apiContract:parameter",
|
|
11646
11726
|
"sourcemaps:value": "[(564,6)-(577,0)]"
|
|
@@ -12256,6 +12336,11 @@
|
|
|
12256
12336
|
]
|
|
12257
12337
|
},
|
|
12258
12338
|
{
|
|
12339
|
+
"@id": "#546/source-map/lexical/element_0",
|
|
12340
|
+
"sourcemaps:element": "amf://id#546",
|
|
12341
|
+
"sourcemaps:value": "[(678,6)-(685,0)]"
|
|
12342
|
+
},
|
|
12343
|
+
{
|
|
12259
12344
|
"@id": "#544/source-map/lexical/element_2",
|
|
12260
12345
|
"sourcemaps:element": "core:name",
|
|
12261
12346
|
"sourcemaps:value": "[(686,8)-(686,13)]"
|
package/package.json
CHANGED
|
@@ -358,9 +358,9 @@ export class DataAssociation {
|
|
|
358
358
|
*/
|
|
359
359
|
remove(): void {
|
|
360
360
|
const { root } = this
|
|
361
|
-
const entity = root.definitions.entities.find((i) => i.associations.some((j) => j === this))
|
|
361
|
+
const entity = root.definitions.entities.find((i) => i.associations.some((j) => j.key === this.key))
|
|
362
362
|
if (entity) {
|
|
363
|
-
const assocIndex = entity.associations.findIndex((i) => i === this)
|
|
363
|
+
const assocIndex = entity.associations.findIndex((i) => i.key === this.key)
|
|
364
364
|
entity.associations.splice(assocIndex, 1)
|
|
365
365
|
}
|
|
366
366
|
const defIndex = this.root.definitions.associations.findIndex((i) => i.key === this.key)
|
|
@@ -450,15 +450,22 @@ export class DataAssociation {
|
|
|
450
450
|
return serializer.associationProperty(this)
|
|
451
451
|
}
|
|
452
452
|
|
|
453
|
+
/**
|
|
454
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
455
|
+
*/
|
|
456
|
+
getParent(): DataEntity {
|
|
457
|
+
return this.getParentInstance()
|
|
458
|
+
}
|
|
459
|
+
|
|
453
460
|
/**
|
|
454
461
|
* Retrieves the parent entity of this association.
|
|
455
462
|
*
|
|
456
463
|
* @returns The `DataEntity` instance that contains this association.
|
|
457
464
|
*/
|
|
458
|
-
|
|
465
|
+
getParentInstance(): DataEntity {
|
|
459
466
|
// this is forced as an association is only created when an entity is created
|
|
460
467
|
// so it has to be defined.
|
|
461
|
-
return this.root.definitions.entities.find((i) => i.associations.
|
|
468
|
+
return this.root.definitions.entities.find((i) => i.associations.some((a) => a.key === this.key)) as DataEntity
|
|
462
469
|
}
|
|
463
470
|
|
|
464
471
|
/**
|
|
@@ -585,7 +585,7 @@ export class DataEntity {
|
|
|
585
585
|
)
|
|
586
586
|
if (associationsToEntity.length > 0) {
|
|
587
587
|
const entitiesNames = associationsToEntity.reduce<string[]>((acc, association) => {
|
|
588
|
-
const entity = root.definitions.entities.find((e) => e.associations.
|
|
588
|
+
const entity = root.definitions.entities.find((e) => e.associations.some((a) => a.key === association.key))
|
|
589
589
|
if (entity) {
|
|
590
590
|
acc.push(entity.info.name as string)
|
|
591
591
|
}
|
|
@@ -605,18 +605,26 @@ export class DataEntity {
|
|
|
605
605
|
root.definitions.entities.splice(index, 1)
|
|
606
606
|
}
|
|
607
607
|
// remove from the parent
|
|
608
|
-
const model = this.
|
|
608
|
+
const model = this.getParentInstance()
|
|
609
609
|
if (model) {
|
|
610
|
-
const entityIndex = model.entities.findIndex((e) => e === this)
|
|
610
|
+
const entityIndex = model.entities.findIndex((e) => e.key === this.key)
|
|
611
611
|
model.entities.splice(entityIndex, 1)
|
|
612
612
|
}
|
|
613
613
|
}
|
|
614
614
|
|
|
615
615
|
/**
|
|
616
|
-
*
|
|
616
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
617
617
|
*/
|
|
618
|
+
// This method name colides with the `getParents()` method.
|
|
618
619
|
getParent(): DataModel | undefined {
|
|
619
|
-
return this.
|
|
620
|
+
return this.getParentInstance()
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Returns a parent data model where this entity exist.
|
|
625
|
+
*/
|
|
626
|
+
getParentInstance(): DataModel | undefined {
|
|
627
|
+
return this.root.definitions.models.find((m) => m.entities.some((e) => e.key === this.key))
|
|
620
628
|
}
|
|
621
629
|
|
|
622
630
|
/**
|
|
@@ -808,21 +816,21 @@ export class DataEntity {
|
|
|
808
816
|
name: this.info.name || 'Unnamed entity',
|
|
809
817
|
kind: DataEntityKind,
|
|
810
818
|
})
|
|
811
|
-
const model = this.
|
|
819
|
+
const model = this.getParentInstance()
|
|
812
820
|
if (model) {
|
|
813
821
|
result.push({
|
|
814
822
|
key: model.key,
|
|
815
823
|
kind: model.kind,
|
|
816
824
|
name: model.info.name || 'Unnamed data model',
|
|
817
825
|
})
|
|
818
|
-
let parent = model.
|
|
826
|
+
let parent = model.getParentInstance()
|
|
819
827
|
while (parent && parent !== this.root) {
|
|
820
828
|
result.push({
|
|
821
829
|
key: parent.key,
|
|
822
830
|
kind: parent.kind,
|
|
823
831
|
name: parent.info.name || 'Unnamed namespace',
|
|
824
832
|
})
|
|
825
|
-
parent = parent.
|
|
833
|
+
parent = parent.getParentInstance()
|
|
826
834
|
}
|
|
827
835
|
}
|
|
828
836
|
result.push({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IThing, Thing } from '../models/Thing.js'
|
|
2
2
|
import v4 from '../lib/uuid.js'
|
|
3
3
|
import { DataEntity, IDataEntity } from './DataEntity.js'
|
|
4
|
-
import { DataNamespace } from './DataNamespace.js'
|
|
4
|
+
import type { DataItemAdaptingOptions, DataNamespace } from './DataNamespace.js'
|
|
5
5
|
import { FileBreadcrumb } from '../models/store/File.js'
|
|
6
6
|
import { DataModelKind } from '../models/kinds.js'
|
|
7
7
|
|
|
@@ -135,7 +135,7 @@ export class DataModel {
|
|
|
135
135
|
entities.forEach((e) => e.remove())
|
|
136
136
|
|
|
137
137
|
// remove self from the parent
|
|
138
|
-
const parent = this.
|
|
138
|
+
const parent = this.getParentInstance()
|
|
139
139
|
if (parent) {
|
|
140
140
|
const itemIndex = parent.items.findIndex((i) => i.key === key)
|
|
141
141
|
if (itemIndex >= 0) {
|
|
@@ -149,6 +149,43 @@ export class DataModel {
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Adapts an entity to this data model.
|
|
154
|
+
* The entity must already be added to another data model within this namespace for it to be
|
|
155
|
+
* adapted to this data model.
|
|
156
|
+
* This method is used to change the data model of an entity.
|
|
157
|
+
* It will remove the entity from the previous data model and add it to this one.
|
|
158
|
+
* @param entity The entity to adapt.
|
|
159
|
+
*/
|
|
160
|
+
adaptEntity(entity: DataEntity, opts: DataItemAdaptingOptions = {}): void {
|
|
161
|
+
if (opts.index !== undefined) {
|
|
162
|
+
if (opts.index < 0) {
|
|
163
|
+
throw new Error(`The index ${opts.index} cannot be below 0.`)
|
|
164
|
+
}
|
|
165
|
+
if (opts.index >= this.entities.length) {
|
|
166
|
+
throw new Error(`The index ${opts.index} is not valid.`)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (entity.root !== this.root) {
|
|
170
|
+
throw new Error(`The entity ${entity.key} is not in the same namespace as this data model.`)
|
|
171
|
+
}
|
|
172
|
+
const parent = entity.getParentInstance()
|
|
173
|
+
if (!parent) {
|
|
174
|
+
throw new Error(`The entity ${entity.key} has no parent.`)
|
|
175
|
+
}
|
|
176
|
+
if (parent.key === this.key) {
|
|
177
|
+
throw new Error(`The entity ${entity.key} is already adapted by this data model.`)
|
|
178
|
+
}
|
|
179
|
+
// it has a parent (above check) so it has the index.
|
|
180
|
+
const index = parent.entities.findIndex((i) => i.key === entity.key)
|
|
181
|
+
parent.entities.splice(index, 1)
|
|
182
|
+
if (opts.index !== undefined) {
|
|
183
|
+
this.entities.splice(opts.index, 0, entity)
|
|
184
|
+
} else {
|
|
185
|
+
this.entities.push(entity)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
152
189
|
/**
|
|
153
190
|
* Adds an entity to this data model.
|
|
154
191
|
*
|
|
@@ -170,9 +207,16 @@ export class DataModel {
|
|
|
170
207
|
}
|
|
171
208
|
|
|
172
209
|
/**
|
|
173
|
-
*
|
|
210
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
174
211
|
*/
|
|
175
212
|
getParent(): DataNamespace | undefined {
|
|
213
|
+
return this.getParentInstance()
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Returns the parent namespace where this data model exist.
|
|
218
|
+
*/
|
|
219
|
+
getParentInstance(): DataNamespace | undefined {
|
|
176
220
|
if (this.root.items.some((e) => e.key === this.key)) {
|
|
177
221
|
return this.root
|
|
178
222
|
}
|
|
@@ -189,14 +233,14 @@ export class DataModel {
|
|
|
189
233
|
name: this.info.name || 'Unnamed data model',
|
|
190
234
|
kind: DataModelKind,
|
|
191
235
|
})
|
|
192
|
-
let parent = this.
|
|
236
|
+
let parent = this.getParentInstance()
|
|
193
237
|
while (parent && parent !== this.root) {
|
|
194
238
|
result.push({
|
|
195
239
|
key: parent.key,
|
|
196
240
|
kind: parent.kind,
|
|
197
241
|
name: parent.info.name || 'Unnamed namespace',
|
|
198
242
|
})
|
|
199
|
-
parent = parent.
|
|
243
|
+
parent = parent.getParentInstance()
|
|
200
244
|
}
|
|
201
245
|
result.push({
|
|
202
246
|
key: this.root.key,
|