@api-client/core 0.11.2 → 0.11.4
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/Local.session.sql +0 -0
- package/build/src/modeling/DataAssociation.d.ts +3 -9
- package/build/src/modeling/DataAssociation.d.ts.map +1 -1
- package/build/src/modeling/DataAssociation.js +2 -0
- package/build/src/modeling/DataAssociation.js.map +1 -1
- package/build/src/modeling/DataModel.d.ts +10 -1
- package/build/src/modeling/DataModel.d.ts.map +1 -1
- package/build/src/modeling/DataModel.js +39 -0
- package/build/src/modeling/DataModel.js.map +1 -1
- package/build/src/modeling/DataNamespace.d.ts +31 -1
- package/build/src/modeling/DataNamespace.d.ts.map +1 -1
- package/build/src/modeling/DataNamespace.js +79 -0
- package/build/src/modeling/DataNamespace.js.map +1 -1
- package/data/models/example-generator-api.json +26 -26
- 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 +2 -15
- package/src/modeling/DataModel.ts +40 -1
- package/src/modeling/DataNamespace.ts +88 -1
- package/src/modeling/readme.md +134 -0
- package/tests/unit/modeling/data_model.spec.ts +54 -0
- package/tests/unit/modeling/data_namespace.spec.ts +383 -1
- package/build/oauth-popup.html +0 -33
|
File without changes
|
|
@@ -219,17 +219,11 @@ export declare class DataAssociation {
|
|
|
219
219
|
*/
|
|
220
220
|
addTarget(entity: IDataEntity | string, namespace?: string): void;
|
|
221
221
|
/**
|
|
222
|
-
* Removes a target entity from the
|
|
222
|
+
* Removes a target entity from the targets list.
|
|
223
223
|
*
|
|
224
|
-
* @param
|
|
224
|
+
* @param init The key of an entity, its instance, or schema.
|
|
225
225
|
*/
|
|
226
|
-
removeTarget(
|
|
227
|
-
/**
|
|
228
|
-
* Removes a target entity from the association.
|
|
229
|
-
*
|
|
230
|
-
* @param key - The key of the target entity to remove.
|
|
231
|
-
*/
|
|
232
|
-
removeTarget(key: string): void;
|
|
226
|
+
removeTarget(init: string | DataEntity | IDataEntity): void;
|
|
233
227
|
/**
|
|
234
228
|
* Creates a Property Shape of AMF.
|
|
235
229
|
* The property itself is auto-generated. If the `schema` is defined then it is used
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataAssociation.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataAssociation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAEtF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACpG,OAAO,EAA2B,KAAK,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAEtF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,mBAAmB,CAAA;IAChC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAA;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,oBAAoB,CAAA;IAC7B;;;;;;OAMG;IACH,QAAQ,CAAC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AiCjE;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI;IAa3D;;;;;;;;;OASG;IACH,UAAU,IAAI,iBAAiB;IAK/B;;;;OAIG;IACH,SAAS,IAAI,UAAU;IAMvB;;;OAGG;IACH,YAAY,IAAI,oBAAoB;IAOpC;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB;IAOxE;;;OAGG;IACH,aAAa,IAAI,sBAAsB;IASvC;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,UAAU,GAAG,mBAAmB,GAAG,SAAS;CAIvE"}
|
|
@@ -288,6 +288,8 @@ export class DataAssociation {
|
|
|
288
288
|
}
|
|
289
289
|
/**
|
|
290
290
|
* @param init The key of an entity, its instance, or schema.
|
|
291
|
+
* @param namespace - The key of the foreign namespace this entity belongs to.
|
|
292
|
+
* Do not set this value for local entities.
|
|
291
293
|
*/
|
|
292
294
|
addTarget(init, namespace) {
|
|
293
295
|
let key;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataAssociation.js","sourceRoot":"","sources":["../../../src/modeling/DataAssociation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAE/D,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC/B,OAAO,EAAU,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAGlD,OAAO,EAA+B,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAChG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,EAAE,uBAAuB,EAA+B,MAAM,iBAAiB,CAAA;AAuEtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,OAAO,eAAe;IA0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IAED;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAc;QACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAA;QACd,CAAC;QACD,OAAO,uBAAuB,CAAC,QAAQ,CAAC,KAA+B,CAAC,CAAA;IAC1E,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,CAAmC,CAAA;QAC1F,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAwB,CAAA;YAC1D,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC,MAAgC,CAAA;IAChD,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,CAAuB,CAAA;QAC7E,OAAO,IAAI,EAAE,MAAM,CAAA;IACrB,CAAC;CACF","sourcesContent":["import { Json } from '@api-client/json'\nimport { AmfShapeGenerator } from '../amf/AmfShapeGenerator.js'\nimport { IApiAssociationShape, IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport v4 from '../lib/uuid.js'\nimport { IThing, Thing } from '../models/Thing.js'\nimport { DataEntity, IDataEntity } from './DataEntity.js'\nimport { DataNamespace } from './DataNamespace.js'\nimport { type FieldValidationMessage, ValidationError } from '../exceptions/validation_error.js'\nimport { DataAssociationKind } from '../models/kinds.js'\nimport type { AssociationBinding, AssociationBindings, AssociationWebBindings } from './Bindings.js'\nimport { DataAttributeAttributes, type DataAttributeAttribute } from './DataFormat.js'\n\n/**\n * Describes association target of an entity\n */\nexport interface AssociationTarget {\n /**\n * The key of the associated entity.\n */\n key: string\n /**\n * The key of the namespace to look for entities.\n * By default it is the current (root) namespace. When this is set the program\n * will look into `foreign` of the root namespace for the definition\n * of the entity.\n */\n namespace?: string\n}\n\n/**\n * Describes an association between entities. An association is another property of an entity.\n * The `name` is the name of the property and the value is the associated target or targets.\n *\n * An association can have multiple targets to allow describing the model as `allOf`, `anyOf` and `oneOf` schemas.\n * When the association has only one target, then generated schema cannot have union types.\n *\n * Depending on the schema translation an association can be embedded as a sub-object in the generated schema\n * or can be references via a primary key.\n */\nexport interface IDataAssociation {\n kind: typeof DataAssociationKind\n /**\n * The key of the association.\n */\n key: string\n /**\n * The data association description.\n */\n info: IThing\n /**\n * Wether the data association is required.\n */\n required?: boolean\n /**\n * Whether the data association allows multiple items.\n */\n multiple?: boolean\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n targets?: AssociationTarget[]\n /**\n * The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)\n *\n * When this is defined then it is used as the schema. When this is not defined it uses\n * referenced entities schemas. Note, changes in the referenced entities may not be propagated\n * to schemas altered by the user.\n */\n schema?: IApiAssociationShape\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?: AssociationBinding[]\n}\n\n/**\n * Describes an association between entities. An association is a relationship defined on an entity\n * that links it to one or more other entities. The association has a `name` which is used as the\n * property name in the context of the parent entity, and it connects to a set of `targets`\n * representing the associated entities.\n *\n * An association can have multiple targets to allow describing the model as `allOf`, `anyOf`, or `oneOf`\n * schemas. When the association has only one target, then the generated schema cannot have union types.\n *\n * Depending on the schema translation, an association can be embedded as a sub-object in the generated\n * schema, or it can be referenced via a primary key.\n *\n * ## Key Concepts\n *\n * - **Targets**: An association's `targets` specify the entities that this association points to.\n * Each target is defined by:\n * - `key`: The key of the target entity.\n * - `namespace` (optional): The key of the namespace where the target entity is defined.\n * If not specified, it defaults to the current namespace.\n *\n * - **Cardinality**:\n * - `multiple` (boolean): Indicates whether the association allows multiple target entities.\n * If `true`, it's a to-many relationship; otherwise, it's a to-one relationship.\n *\n * - **Schema**:\n * - `schema` (optional): A custom schema for the association, allowing manual definition of the\n * association's structure in specific formats (e.g., JSON, RAML, XML).\n * When provided, this schema overrides the automatically generated schema based on the\n * target entities.\n * - **Important**: If a custom schema is defined and changes are made to the referenced\n * entities, those changes **will not** be automatically propagated to the custom schema.\n * This means the custom schema may become outdated and no longer accurately reflect the\n * structure of the target entities.\n *\n * - **Hidden**:\n * - `hidden`: (boolean) Defines if this association is a part of the schema or not.\n */\nexport class DataAssociation {\n kind = DataAssociationKind\n\n key = ''\n\n /**\n * The description of the data association.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * Wether the data association is required.\n */\n required?: boolean\n\n /**\n * Whether the data association allows multiple items.\n */\n multiple?: boolean\n\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n targets: AssociationTarget[] = []\n\n /**\n * The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)\n *\n * When this is defined then it is used as the schema. When this is not defined it uses\n * referenced entities schemas. Note, changes in the referenced entities may not be propagated\n * to schemas altered by the user.\n */\n schema?: IApiAssociationShape\n\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: AssociationBinding[] = []\n\n /**\n * Returns true when the association has 0 or 1 targets.\n */\n get isSingle(): boolean {\n return this.targets.length < 2\n }\n\n /**\n * Creates an instance of DataAssociation from a target entity key.\n * Note, this entity will have no name. The default name is used instead.\n *\n * @param root The namespace root.\n * @param target The target entity key.\n * @param namespace The optional key of the target association when different to the current one.\n * @returns A new `DataAssociation` instance.\n */\n static fromTarget(root: DataNamespace, target: string, namespace?: string): DataAssociation {\n const assoc = new DataAssociation(root)\n const info: AssociationTarget = {\n key: target,\n }\n if (namespace) {\n info.namespace = namespace\n }\n assoc.targets = [info]\n return assoc\n }\n\n /**\n * Creates an instance of DataAssociation from a name, without defining a target.\n *\n * @param root The namespace root.\n * @param name The name of the association.\n * @returns A new `DataAssociation` instance.\n */\n static fromName(root: DataNamespace, name: string): DataAssociation {\n const assoc = new DataAssociation(root)\n assoc.info = Thing.fromName(name)\n return assoc\n }\n\n /**\n * @param input The data association definition to restore.\n */\n constructor(\n public root: DataNamespace,\n input?: string | IDataAssociation\n ) {\n let init: IDataAssociation\n if (typeof input === 'string') {\n try {\n init = JSON.parse(input)\n } catch {\n throw new ValidationError([\n {\n field: '',\n message: 'Unable to parse the data association input as JSON.',\n rule: 'object_required',\n },\n ])\n }\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: DataAssociationKind,\n key: v4(),\n info: Thing.fromName('Unnamed association').toJSON(),\n }\n }\n this.new(init)\n }\n\n /**\n * Initializes the association using provided data.\n *\n * @param init - The data association definition to restore.\n */\n new(init: IDataAssociation): this {\n DataAssociation.validate(init)\n const { info, key = v4(), kind = DataAssociationKind, schema, multiple, required, targets, bindings } = init\n this.kind = kind\n this.key = key\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n if (schema) {\n this.schema = Json.clone(schema)\n } else {\n this.schema = undefined\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 (Array.isArray(targets)) {\n this.targets = targets.map((i) => ({ ...i }))\n } else {\n this.targets = []\n }\n if (Array.isArray(bindings)) {\n this.bindings = bindings.map((i) => Json.clone(i))\n } else {\n this.bindings = []\n }\n return this\n }\n\n /**\n * Validates if the input object is a valid `DataAssociation` definition.\n * Throws a `ValidationError` if the input is invalid.\n *\n * @param input The object to validate.\n * @throws {ValidationError} When the validation fails.\n */\n static validate(input: unknown): void {\n const typed = input as IDataAssociation\n const messages: FieldValidationMessage[] = []\n if (!typed) {\n messages.push({\n field: '',\n message: 'The input is required. None given',\n rule: 'required',\n })\n throw new ValidationError(messages)\n }\n if (typed.kind !== DataAssociationKind) {\n messages.push({\n field: 'kind',\n message: `The kind property must be ${DataAssociationKind}`,\n rule: 'invalid',\n })\n }\n if (typed.info && typeof typed.info !== 'object') {\n messages.push({\n field: 'info',\n message: 'The info property must be an object',\n rule: 'invalid',\n })\n }\n if (messages.length) {\n throw new ValidationError(messages)\n }\n }\n\n /**\n * Generates an object representing the association, suitable for serialization.\n *\n * @returns A plain object representation of the `DataAssociation`.\n */\n toJSON(): IDataAssociation {\n const result: IDataAssociation = {\n kind: DataAssociationKind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (this.schema) {\n result.schema = Json.clone(this.schema)\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 (Array.isArray(this.targets) && this.targets.length) {\n result.targets = this.targets.map((i) => ({ ...i }))\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 * Retrieves the list of target entities.\n *\n * @returns An array of `DataEntity` instances representing the targets of this association.\n */\n getTargets(): DataEntity[] {\n const { targets } = this\n return this.root.findAssociatedEntities(targets).filter((i) => !!i) as DataEntity[]\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.associations.some((j) => j === this))\n if (entity) {\n const assocIndex = entity.associations.findIndex((i) => i === this)\n entity.associations.splice(assocIndex, 1)\n }\n const defIndex = this.root.definitions.associations.findIndex((i) => i.key === this.key)\n if (defIndex >= 0) {\n this.root.definitions.associations.splice(defIndex, 1)\n }\n }\n\n /**\n * Adds a target entity to the association.\n * If the entity comes from another namespace then it is set as a foreign entity.\n *\n * @param entity - The `DataEntity` instance to add.\n */\n addTarget(entity: DataEntity): void\n\n /**\n * Adds a target entity to the association.\n *\n * @param entity - The `IDataEntity` definition or just its key.\n * @param namespace - The key of the foreign namespace this entity belongs to.\n * Do not set this value for local entities.\n */\n addTarget(entity: IDataEntity | string, namespace?: string): void\n\n /**\n * @param init The key of an entity, its instance, or schema.\n */\n addTarget(init: string | DataEntity | IDataEntity, namespace?: string): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n const typed = init as IDataEntity & { root?: DataNamespace }\n if (!namespace && typed.root && typed.root !== this.root) {\n namespace = typed.root.key\n }\n }\n if (namespace && namespace !== this.root.key) {\n const foreignNamespace = this.root.foreign.find((ns) => ns.key === namespace)\n if (!foreignNamespace) {\n throw new Error(`Foreign namespace \"${namespace}\" does not exist.`)\n }\n }\n const info: AssociationTarget = {\n key,\n }\n if (namespace) {\n info.namespace = namespace\n }\n this.targets.push(info)\n }\n\n /**\n * Removes a target entity from the association.\n *\n * @param entity - The `DataEntity` or `IDataEntity` instance to remove.\n */\n removeTarget(entity: DataEntity | IDataEntity): void\n\n /**\n * Removes a target entity from the association.\n *\n * @param key - The key of the target entity to remove.\n */\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n removeTarget(key: string): void\n\n /**\n * Removes a target entity from the targets list.\n *\n * @param init The key of an entity, its instance, or schema.\n */\n removeTarget(init: string | DataEntity | IDataEntity): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n }\n const index = this.targets.findIndex((i) => i.key === key)\n if (index >= 0) {\n this.targets.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.associationProperty(this)\n }\n\n /**\n * Retrieves the parent entity of this association.\n *\n * @returns The `DataEntity` instance that contains this association.\n */\n getParent(): DataEntity {\n // this is forced as an association is only created when an entity is created\n // so it has to be defined.\n return this.root.definitions.entities.find((i) => i.associations.includes(this)) as DataEntity\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n * @returns The schema object.\n */\n ensureSchema(): IApiAssociationShape {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\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 DataAttributeAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DataAttributeAttributes.includes(value as DataAttributeAttribute)\n }\n\n /**\n * Creates if not existing and returns web bindings definition.\n * @returns The web binding definition\n */\n getWebBinding(): AssociationWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as AssociationBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as AssociationBinding\n this.bindings.push(object)\n }\n return object.schema as AssociationWebBindings\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'): AssociationBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as AssociationBinding\n return item?.schema\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DataAssociation.js","sourceRoot":"","sources":["../../../src/modeling/DataAssociation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAE/D,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC/B,OAAO,EAAU,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAGlD,OAAO,EAA+B,eAAe,EAAE,M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C,IAAI,CAAC,CAAe,CAAA;IAChG,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;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAc;QACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAA;QACd,CAAC;QACD,OAAO,uBAAuB,CAAC,QAAQ,CAAC,KAA+B,CAAC,CAAA;IAC1E,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,CAAmC,CAAA;QAC1F,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAwB,CAAA;YAC1D,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC,MAAgC,CAAA;IAChD,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,CAAuB,CAAA;QAC7E,OAAO,IAAI,EAAE,MAAM,CAAA;IACrB,CAAC;CACF","sourcesContent":["import { Json } from '@api-client/json'\nimport { AmfShapeGenerator } from '../amf/AmfShapeGenerator.js'\nimport { IApiAssociationShape, IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport v4 from '../lib/uuid.js'\nimport { IThing, Thing } from '../models/Thing.js'\nimport { DataEntity, IDataEntity } from './DataEntity.js'\nimport { DataNamespace } from './DataNamespace.js'\nimport { type FieldValidationMessage, ValidationError } from '../exceptions/validation_error.js'\nimport { DataAssociationKind } from '../models/kinds.js'\nimport type { AssociationBinding, AssociationBindings, AssociationWebBindings } from './Bindings.js'\nimport { DataAttributeAttributes, type DataAttributeAttribute } from './DataFormat.js'\n\n/**\n * Describes association target of an entity\n */\nexport interface AssociationTarget {\n /**\n * The key of the associated entity.\n */\n key: string\n /**\n * The key of the namespace to look for entities.\n * By default it is the current (root) namespace. When this is set the program\n * will look into `foreign` of the root namespace for the definition\n * of the entity.\n */\n namespace?: string\n}\n\n/**\n * Describes an association between entities. An association is another property of an entity.\n * The `name` is the name of the property and the value is the associated target or targets.\n *\n * An association can have multiple targets to allow describing the model as `allOf`, `anyOf` and `oneOf` schemas.\n * When the association has only one target, then generated schema cannot have union types.\n *\n * Depending on the schema translation an association can be embedded as a sub-object in the generated schema\n * or can be references via a primary key.\n */\nexport interface IDataAssociation {\n kind: typeof DataAssociationKind\n /**\n * The key of the association.\n */\n key: string\n /**\n * The data association description.\n */\n info: IThing\n /**\n * Wether the data association is required.\n */\n required?: boolean\n /**\n * Whether the data association allows multiple items.\n */\n multiple?: boolean\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n targets?: AssociationTarget[]\n /**\n * The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)\n *\n * When this is defined then it is used as the schema. When this is not defined it uses\n * referenced entities schemas. Note, changes in the referenced entities may not be propagated\n * to schemas altered by the user.\n */\n schema?: IApiAssociationShape\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?: AssociationBinding[]\n}\n\n/**\n * Describes an association between entities. An association is a relationship defined on an entity\n * that links it to one or more other entities. The association has a `name` which is used as the\n * property name in the context of the parent entity, and it connects to a set of `targets`\n * representing the associated entities.\n *\n * An association can have multiple targets to allow describing the model as `allOf`, `anyOf`, or `oneOf`\n * schemas. When the association has only one target, then the generated schema cannot have union types.\n *\n * Depending on the schema translation, an association can be embedded as a sub-object in the generated\n * schema, or it can be referenced via a primary key.\n *\n * ## Key Concepts\n *\n * - **Targets**: An association's `targets` specify the entities that this association points to.\n * Each target is defined by:\n * - `key`: The key of the target entity.\n * - `namespace` (optional): The key of the namespace where the target entity is defined.\n * If not specified, it defaults to the current namespace.\n *\n * - **Cardinality**:\n * - `multiple` (boolean): Indicates whether the association allows multiple target entities.\n * If `true`, it's a to-many relationship; otherwise, it's a to-one relationship.\n *\n * - **Schema**:\n * - `schema` (optional): A custom schema for the association, allowing manual definition of the\n * association's structure in specific formats (e.g., JSON, RAML, XML).\n * When provided, this schema overrides the automatically generated schema based on the\n * target entities.\n * - **Important**: If a custom schema is defined and changes are made to the referenced\n * entities, those changes **will not** be automatically propagated to the custom schema.\n * This means the custom schema may become outdated and no longer accurately reflect the\n * structure of the target entities.\n *\n * - **Hidden**:\n * - `hidden`: (boolean) Defines if this association is a part of the schema or not.\n */\nexport class DataAssociation {\n kind = DataAssociationKind\n\n key = ''\n\n /**\n * The description of the data association.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * Wether the data association is required.\n */\n required?: boolean\n\n /**\n * Whether the data association allows multiple items.\n */\n multiple?: boolean\n\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n targets: AssociationTarget[] = []\n\n /**\n * The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)\n *\n * When this is defined then it is used as the schema. When this is not defined it uses\n * referenced entities schemas. Note, changes in the referenced entities may not be propagated\n * to schemas altered by the user.\n */\n schema?: IApiAssociationShape\n\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: AssociationBinding[] = []\n\n /**\n * Returns true when the association has 0 or 1 targets.\n */\n get isSingle(): boolean {\n return this.targets.length < 2\n }\n\n /**\n * Creates an instance of DataAssociation from a target entity key.\n * Note, this entity will have no name. The default name is used instead.\n *\n * @param root The namespace root.\n * @param target The target entity key.\n * @param namespace The optional key of the target association when different to the current one.\n * @returns A new `DataAssociation` instance.\n */\n static fromTarget(root: DataNamespace, target: string, namespace?: string): DataAssociation {\n const assoc = new DataAssociation(root)\n const info: AssociationTarget = {\n key: target,\n }\n if (namespace) {\n info.namespace = namespace\n }\n assoc.targets = [info]\n return assoc\n }\n\n /**\n * Creates an instance of DataAssociation from a name, without defining a target.\n *\n * @param root The namespace root.\n * @param name The name of the association.\n * @returns A new `DataAssociation` instance.\n */\n static fromName(root: DataNamespace, name: string): DataAssociation {\n const assoc = new DataAssociation(root)\n assoc.info = Thing.fromName(name)\n return assoc\n }\n\n /**\n * @param input The data association definition to restore.\n */\n constructor(\n public root: DataNamespace,\n input?: string | IDataAssociation\n ) {\n let init: IDataAssociation\n if (typeof input === 'string') {\n try {\n init = JSON.parse(input)\n } catch {\n throw new ValidationError([\n {\n field: '',\n message: 'Unable to parse the data association input as JSON.',\n rule: 'object_required',\n },\n ])\n }\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: DataAssociationKind,\n key: v4(),\n info: Thing.fromName('Unnamed association').toJSON(),\n }\n }\n this.new(init)\n }\n\n /**\n * Initializes the association using provided data.\n *\n * @param init - The data association definition to restore.\n */\n new(init: IDataAssociation): this {\n DataAssociation.validate(init)\n const { info, key = v4(), kind = DataAssociationKind, schema, multiple, required, targets, bindings } = init\n this.kind = kind\n this.key = key\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n if (schema) {\n this.schema = Json.clone(schema)\n } else {\n this.schema = undefined\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 (Array.isArray(targets)) {\n this.targets = targets.map((i) => ({ ...i }))\n } else {\n this.targets = []\n }\n if (Array.isArray(bindings)) {\n this.bindings = bindings.map((i) => Json.clone(i))\n } else {\n this.bindings = []\n }\n return this\n }\n\n /**\n * Validates if the input object is a valid `DataAssociation` definition.\n * Throws a `ValidationError` if the input is invalid.\n *\n * @param input The object to validate.\n * @throws {ValidationError} When the validation fails.\n */\n static validate(input: unknown): void {\n const typed = input as IDataAssociation\n const messages: FieldValidationMessage[] = []\n if (!typed) {\n messages.push({\n field: '',\n message: 'The input is required. None given',\n rule: 'required',\n })\n throw new ValidationError(messages)\n }\n if (typed.kind !== DataAssociationKind) {\n messages.push({\n field: 'kind',\n message: `The kind property must be ${DataAssociationKind}`,\n rule: 'invalid',\n })\n }\n if (typed.info && typeof typed.info !== 'object') {\n messages.push({\n field: 'info',\n message: 'The info property must be an object',\n rule: 'invalid',\n })\n }\n if (messages.length) {\n throw new ValidationError(messages)\n }\n }\n\n /**\n * Generates an object representing the association, suitable for serialization.\n *\n * @returns A plain object representation of the `DataAssociation`.\n */\n toJSON(): IDataAssociation {\n const result: IDataAssociation = {\n kind: DataAssociationKind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (this.schema) {\n result.schema = Json.clone(this.schema)\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 (Array.isArray(this.targets) && this.targets.length) {\n result.targets = this.targets.map((i) => ({ ...i }))\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 * Retrieves the list of target entities.\n *\n * @returns An array of `DataEntity` instances representing the targets of this association.\n */\n getTargets(): DataEntity[] {\n const { targets } = this\n return this.root.findAssociatedEntities(targets).filter((i) => !!i) as DataEntity[]\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.associations.some((j) => j === this))\n if (entity) {\n const assocIndex = entity.associations.findIndex((i) => i === this)\n entity.associations.splice(assocIndex, 1)\n }\n const defIndex = this.root.definitions.associations.findIndex((i) => i.key === this.key)\n if (defIndex >= 0) {\n this.root.definitions.associations.splice(defIndex, 1)\n }\n }\n\n /**\n * Adds a target entity to the association.\n * If the entity comes from another namespace then it is set as a foreign entity.\n *\n * @param entity - The `DataEntity` instance to add.\n */\n addTarget(entity: DataEntity): void\n\n /**\n * Adds a target entity to the association.\n *\n * @param entity - The `IDataEntity` definition or just its key.\n * @param namespace - The key of the foreign namespace this entity belongs to.\n * Do not set this value for local entities.\n */\n addTarget(entity: IDataEntity | string, namespace?: string): void\n\n /**\n * @param init The key of an entity, its instance, or schema.\n * @param namespace - The key of the foreign namespace this entity belongs to.\n * Do not set this value for local entities.\n */\n addTarget(init: string | DataEntity | IDataEntity, namespace?: string): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n const typed = init as IDataEntity & { root?: DataNamespace }\n if (!namespace && typed.root && typed.root !== this.root) {\n namespace = typed.root.key\n }\n }\n if (namespace && namespace !== this.root.key) {\n const foreignNamespace = this.root.foreign.find((ns) => ns.key === namespace)\n if (!foreignNamespace) {\n throw new Error(`Foreign namespace \"${namespace}\" does not exist.`)\n }\n }\n const info: AssociationTarget = {\n key,\n }\n if (namespace) {\n info.namespace = namespace\n }\n this.targets.push(info)\n }\n\n /**\n * Removes a target entity from the targets list.\n *\n * @param init The key of an entity, its instance, or schema.\n */\n removeTarget(init: string | DataEntity | IDataEntity): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n }\n const index = this.targets.findIndex((i) => i.key === key)\n if (index >= 0) {\n this.targets.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.associationProperty(this)\n }\n\n /**\n * Retrieves the parent entity of this association.\n *\n * @returns The `DataEntity` instance that contains this association.\n */\n getParent(): DataEntity {\n // this is forced as an association is only created when an entity is created\n // so it has to be defined.\n return this.root.definitions.entities.find((i) => i.associations.includes(this)) as DataEntity\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n * @returns The schema object.\n */\n ensureSchema(): IApiAssociationShape {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\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 DataAttributeAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DataAttributeAttributes.includes(value as DataAttributeAttribute)\n }\n\n /**\n * Creates if not existing and returns web bindings definition.\n * @returns The web binding definition\n */\n getWebBinding(): AssociationWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as AssociationBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as AssociationBinding\n this.bindings.push(object)\n }\n return object.schema as AssociationWebBindings\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'): AssociationBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as AssociationBinding\n return item?.schema\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IThing, Thing } from '../models/Thing.js';
|
|
2
2
|
import { DataEntity, IDataEntity } from './DataEntity.js';
|
|
3
|
-
import { DataNamespace } from './DataNamespace.js';
|
|
3
|
+
import type { DataItemAdaptingOptions, DataNamespace } from './DataNamespace.js';
|
|
4
4
|
import { FileBreadcrumb } from '../models/store/File.js';
|
|
5
5
|
import { DataModelKind } from '../models/kinds.js';
|
|
6
6
|
/**
|
|
@@ -56,6 +56,15 @@ export declare class DataModel {
|
|
|
56
56
|
* Removes self from the namespace with all entities.
|
|
57
57
|
*/
|
|
58
58
|
remove(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Adapts an entity to this data model.
|
|
61
|
+
* The entity must already be added to another data model within this namespace for it to be
|
|
62
|
+
* adapted to this data model.
|
|
63
|
+
* This method is used to change the data model of an entity.
|
|
64
|
+
* It will remove the entity from the previous data model and add it to this one.
|
|
65
|
+
* @param entity The entity to adapt.
|
|
66
|
+
*/
|
|
67
|
+
adaptEntity(entity: DataEntity, opts?: DataItemAdaptingOptions): void;
|
|
59
68
|
/**
|
|
60
69
|
* Adds an entity to this data model.
|
|
61
70
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataModel.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"DataModel.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,aAAa,CAAA;IAC1B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AAED;;;;;GAKG;AACH,qBAAa,SAAS;IA0BX,IAAI,EAAE,aAAa;IAzB5B,IAAI,SAAgB;IAEpB,GAAG,SAAK;IAER;;OAEG;IACH,IAAI,EAAE,KAAK,CAAqB;IAEhC;;OAEG;IACH,QAAQ,EAAE,UAAU,EAAE,CAAK;IAE3B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS;IAM7D;;;OAGG;gBAEM,IAAI,EAAE,aAAa,EAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU;IAkB7B,GAAG,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAwB3B,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAQ3C,MAAM,IAAI,UAAU;IAYpB,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI1D;;OAEG;IACH,MAAM,IAAI,IAAI;IAoBd;;;;;;;OAOG;IACH,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,GAAE,uBAA4B,GAAG,IAAI;IA+BzE;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU;IAc9D;;OAEG;IACH,SAAS,IAAI,aAAa,GAAG,SAAS;IAOtC;;OAEG;IACH,WAAW,IAAI,cAAc,EAAE;CAuBhC"}
|
|
@@ -113,6 +113,45 @@ export class DataModel {
|
|
|
113
113
|
root.definitions.models.splice(index, 1);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Adapts an entity to this data model.
|
|
118
|
+
* The entity must already be added to another data model within this namespace for it to be
|
|
119
|
+
* adapted to this data model.
|
|
120
|
+
* This method is used to change the data model of an entity.
|
|
121
|
+
* It will remove the entity from the previous data model and add it to this one.
|
|
122
|
+
* @param entity The entity to adapt.
|
|
123
|
+
*/
|
|
124
|
+
adaptEntity(entity, opts = {}) {
|
|
125
|
+
if (opts.index !== undefined) {
|
|
126
|
+
if (opts.index < 0) {
|
|
127
|
+
throw new Error(`The index ${opts.index} cannot be below 0.`);
|
|
128
|
+
}
|
|
129
|
+
if (opts.index >= this.entities.length) {
|
|
130
|
+
throw new Error(`The index ${opts.index} is not valid.`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (entity.root !== this.root) {
|
|
134
|
+
throw new Error(`The entity ${entity.key} is not in the same namespace as this data model.`);
|
|
135
|
+
}
|
|
136
|
+
if (entity.getParent() === this) {
|
|
137
|
+
throw new Error(`The entity ${entity.key} is already adapted by this data model.`);
|
|
138
|
+
}
|
|
139
|
+
const parent = entity.getParent();
|
|
140
|
+
if (!parent) {
|
|
141
|
+
throw new Error(`The entity ${entity.key} has no parent.`);
|
|
142
|
+
}
|
|
143
|
+
const index = parent.entities.findIndex((i) => i.key === entity.key);
|
|
144
|
+
if (index < 0) {
|
|
145
|
+
throw new Error(`The entity ${entity.key} is not in the parent data model.`);
|
|
146
|
+
}
|
|
147
|
+
parent.entities.splice(index, 1);
|
|
148
|
+
if (opts.index !== undefined) {
|
|
149
|
+
this.entities.splice(opts.index, 0, entity);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
this.entities.push(entity);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
116
155
|
/**
|
|
117
156
|
* Adds an entity to this data model.
|
|
118
157
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../../src/modeling/DataModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC/B,O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YACV,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,oBAAoB;YAC5C,IAAI,EAAE,aAAa;SACpB,CAAC,CAAA;QACF,IAAI,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;QAC7B,OAAO,MAAM,IAAI,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACtC,MAAM,CAAC,IAAI,CAAC;gBACV,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,mBAAmB;aAC9C,CAAC,CAAA;YACF,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;QAC7B,CAAC;QACD,MAAM,CAAC,IAAI,CAAC;YACV,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG;YAClB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,mBAAmB;YAChD,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;SACrB,CAAC,CAAA;QACF,OAAO,MAAM,CAAC,OAAO,EAAE,CAAA;IACzB,CAAC;CACF","sourcesContent":["import { IThing, Thing } from '../models/Thing.js'\nimport v4 from '../lib/uuid.js'\nimport { DataEntity, IDataEntity } from './DataEntity.js'\nimport { DataNamespace } from './DataNamespace.js'\nimport { FileBreadcrumb } from '../models/store/File.js'\nimport { DataModelKind } from '../models/kinds.js'\n\n/**\n * Data model creates a logical structure around data entities.\n * It groups entities that represents a whole schema, like a Product data model\n * can have entities that describe: the product entity, price history entity,\n * product location, etc.\n */\nexport interface IDataModel {\n kind: typeof DataModelKind\n /**\n * The key of the namespace.\n */\n key: string\n /**\n * The data model description.\n */\n info: IThing\n /**\n * The list of keys of entities that this data model contain.\n */\n entities?: string[]\n}\n\n/**\n * Data model creates a logical structure around data entities.\n * It groups entities that represents a whole schema, like a Product data model\n * can have entities that describe: the product entity, price history entity,\n * product location, etc.\n */\nexport class DataModel {\n kind = DataModelKind\n\n key = ''\n\n /**\n * The description of the data namespace.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * The list of entities that this data model has.\n */\n entities: DataEntity[] = []\n\n static fromName(root: DataNamespace, name: string): DataModel {\n const entity = new DataModel(root)\n entity.info = Thing.fromName(name)\n return entity\n }\n\n /**\n * @param root the root namespace.\n * @param input The data model definition to restore.\n */\n constructor(\n public root: DataNamespace,\n input?: string | IDataModel\n ) {\n let init: IDataModel\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: DataModelKind,\n key: v4(),\n info: Thing.fromName('').toJSON(),\n entities: [],\n }\n }\n this.new(init)\n }\n\n new(init: IDataModel): void {\n if (!DataModel.isDataModel(init)) {\n throw new Error(`Not a data model.`)\n }\n const { info, key = v4(), kind = DataModelKind, entities } = init\n this.kind = kind\n this.key = key\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n\n this.entities = []\n if (Array.isArray(entities)) {\n entities.forEach((key) => {\n const value = this._readEntity(key)\n if (value) {\n this.entities.push(value)\n }\n })\n }\n }\n\n static isDataModel(input: unknown): boolean {\n const typed = input as IDataModel\n if (!input || typed.kind !== DataModelKind) {\n return false\n }\n return true\n }\n\n toJSON(): IDataModel {\n const result: IDataModel = {\n kind: DataModelKind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (Array.isArray(this.entities) && this.entities.length) {\n result.entities = this.entities.map((i) => i.key)\n }\n return result\n }\n\n protected _readEntity(key: string): DataEntity | undefined {\n return this.root.definitions.entities.find((i) => i.key === key)\n }\n\n /**\n * Removes self from the namespace with all entities.\n */\n remove(): void {\n const { key, entities, root } = this\n // remove children\n entities.forEach((e) => e.remove())\n\n // remove self from the parent\n const parent = this.getParent()\n if (parent) {\n const itemIndex = parent.items.findIndex((i) => i.key === key)\n if (itemIndex >= 0) {\n parent.items.splice(itemIndex, 1)\n }\n }\n // remove self from definitions\n const index = root.definitions.models.findIndex((i) => i.key === key)\n if (index >= 0) {\n root.definitions.models.splice(index, 1)\n }\n }\n\n /**\n * Adds an entity to this data model.\n *\n * @param init The name of the entity to create, the instance of the entity or its schema\n * @returns A reference to the created entity.\n */\n addEntity(init: string | DataEntity | IDataEntity): DataEntity {\n let definition: DataEntity\n if (typeof init === 'string') {\n definition = DataEntity.fromName(this.root, init)\n } else if (init instanceof DataEntity) {\n definition = init\n } else {\n definition = new DataEntity(this.root, init)\n }\n this.root.definitions.entities.push(definition)\n this.entities.push(definition)\n return definition\n }\n\n /**\n * Returns the parent namespace where this data model exist.\n */\n getParent(): DataNamespace | undefined {\n if (this.root.items.some((e) => e.key === this.key)) {\n return this.root\n }\n return this.root.definitions.namespaces.find((n) => n.items.some((e) => e.key === this.key))\n }\n\n /**\n * Creates breadcrumbs from this data model to the root namespace.\n */\n breadcrumbs(): FileBreadcrumb[] {\n const result: FileBreadcrumb[] = []\n result.push({\n key: this.key,\n name: this.info.name || 'Unnamed data model',\n kind: DataModelKind,\n })\n let parent = this.getParent()\n while (parent && parent !== this.root) {\n result.push({\n key: parent.key,\n kind: parent.kind,\n name: parent.info.name || 'Unnamed namespace',\n })\n parent = parent.getParent()\n }\n result.push({\n key: this.root.key,\n name: this.root.info.name || 'Unnamed namespace',\n kind: this.root.kind,\n })\n return result.reverse()\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../../src/modeling/DataModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAe,MAAM,iBAAiB,CAAA;AAGzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAwBlD;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IA0BX;IAzBT,IAAI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,CAAC,GAAG,CAAC,CAAC,CAAA;IAC9F,CAAC;IAED;;OAEG;IACH,WAAW;QACT,MAAM,MAAM,GAAqB,EAAE,CAAA;QACnC,MAAM,CAAC,IAAI,CAAC;YACV,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,oBAAoB;YAC5C,IAAI,EAAE,aAAa;SACpB,CAAC,CAAA;QACF,IAAI,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;QAC7B,OAAO,MAAM,IAAI,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACtC,MAAM,CAAC,IAAI,CAAC;gBACV,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,mBAAmB;aAC9C,CAAC,CAAA;YACF,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;QAC7B,CAAC;QACD,MAAM,CAAC,IAAI,CAAC;YACV,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG;YAClB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,mBAAmB;YAChD,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;SACrB,CAAC,CAAA;QACF,OAAO,MAAM,CAAC,OAAO,EAAE,CAAA;IACzB,CAAC;CACF","sourcesContent":["import { IThing, Thing } from '../models/Thing.js'\nimport v4 from '../lib/uuid.js'\nimport { DataEntity, IDataEntity } from './DataEntity.js'\nimport type { DataItemAdaptingOptions, DataNamespace } from './DataNamespace.js'\nimport { FileBreadcrumb } from '../models/store/File.js'\nimport { DataModelKind } from '../models/kinds.js'\n\n/**\n * Data model creates a logical structure around data entities.\n * It groups entities that represents a whole schema, like a Product data model\n * can have entities that describe: the product entity, price history entity,\n * product location, etc.\n */\nexport interface IDataModel {\n kind: typeof DataModelKind\n /**\n * The key of the namespace.\n */\n key: string\n /**\n * The data model description.\n */\n info: IThing\n /**\n * The list of keys of entities that this data model contain.\n */\n entities?: string[]\n}\n\n/**\n * Data model creates a logical structure around data entities.\n * It groups entities that represents a whole schema, like a Product data model\n * can have entities that describe: the product entity, price history entity,\n * product location, etc.\n */\nexport class DataModel {\n kind = DataModelKind\n\n key = ''\n\n /**\n * The description of the data namespace.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * The list of entities that this data model has.\n */\n entities: DataEntity[] = []\n\n static fromName(root: DataNamespace, name: string): DataModel {\n const entity = new DataModel(root)\n entity.info = Thing.fromName(name)\n return entity\n }\n\n /**\n * @param root the root namespace.\n * @param input The data model definition to restore.\n */\n constructor(\n public root: DataNamespace,\n input?: string | IDataModel\n ) {\n let init: IDataModel\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: DataModelKind,\n key: v4(),\n info: Thing.fromName('').toJSON(),\n entities: [],\n }\n }\n this.new(init)\n }\n\n new(init: IDataModel): void {\n if (!DataModel.isDataModel(init)) {\n throw new Error(`Not a data model.`)\n }\n const { info, key = v4(), kind = DataModelKind, entities } = init\n this.kind = kind\n this.key = key\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n\n this.entities = []\n if (Array.isArray(entities)) {\n entities.forEach((key) => {\n const value = this._readEntity(key)\n if (value) {\n this.entities.push(value)\n }\n })\n }\n }\n\n static isDataModel(input: unknown): boolean {\n const typed = input as IDataModel\n if (!input || typed.kind !== DataModelKind) {\n return false\n }\n return true\n }\n\n toJSON(): IDataModel {\n const result: IDataModel = {\n kind: DataModelKind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (Array.isArray(this.entities) && this.entities.length) {\n result.entities = this.entities.map((i) => i.key)\n }\n return result\n }\n\n protected _readEntity(key: string): DataEntity | undefined {\n return this.root.definitions.entities.find((i) => i.key === key)\n }\n\n /**\n * Removes self from the namespace with all entities.\n */\n remove(): void {\n const { key, entities, root } = this\n // remove children\n entities.forEach((e) => e.remove())\n\n // remove self from the parent\n const parent = this.getParent()\n if (parent) {\n const itemIndex = parent.items.findIndex((i) => i.key === key)\n if (itemIndex >= 0) {\n parent.items.splice(itemIndex, 1)\n }\n }\n // remove self from definitions\n const index = root.definitions.models.findIndex((i) => i.key === key)\n if (index >= 0) {\n root.definitions.models.splice(index, 1)\n }\n }\n\n /**\n * Adapts an entity to this data model.\n * The entity must already be added to another data model within this namespace for it to be\n * adapted to this data model.\n * This method is used to change the data model of an entity.\n * It will remove the entity from the previous data model and add it to this one.\n * @param entity The entity to adapt.\n */\n adaptEntity(entity: DataEntity, opts: DataItemAdaptingOptions = {}): void {\n if (opts.index !== undefined) {\n if (opts.index < 0) {\n throw new Error(`The index ${opts.index} cannot be below 0.`)\n }\n if (opts.index >= this.entities.length) {\n throw new Error(`The index ${opts.index} is not valid.`)\n }\n }\n if (entity.root !== this.root) {\n throw new Error(`The entity ${entity.key} is not in the same namespace as this data model.`)\n }\n if (entity.getParent() === this) {\n throw new Error(`The entity ${entity.key} is already adapted by this data model.`)\n }\n const parent = entity.getParent()\n if (!parent) {\n throw new Error(`The entity ${entity.key} has no parent.`)\n }\n const index = parent.entities.findIndex((i) => i.key === entity.key)\n if (index < 0) {\n throw new Error(`The entity ${entity.key} is not in the parent data model.`)\n }\n parent.entities.splice(index, 1)\n if (opts.index !== undefined) {\n this.entities.splice(opts.index, 0, entity)\n } else {\n this.entities.push(entity)\n }\n }\n\n /**\n * Adds an entity to this data model.\n *\n * @param init The name of the entity to create, the instance of the entity or its schema\n * @returns A reference to the created entity.\n */\n addEntity(init: string | DataEntity | IDataEntity): DataEntity {\n let definition: DataEntity\n if (typeof init === 'string') {\n definition = DataEntity.fromName(this.root, init)\n } else if (init instanceof DataEntity) {\n definition = init\n } else {\n definition = new DataEntity(this.root, init)\n }\n this.root.definitions.entities.push(definition)\n this.entities.push(definition)\n return definition\n }\n\n /**\n * Returns the parent namespace where this data model exist.\n */\n getParent(): DataNamespace | undefined {\n if (this.root.items.some((e) => e.key === this.key)) {\n return this.root\n }\n return this.root.definitions.namespaces.find((n) => n.items.some((e) => e.key === this.key))\n }\n\n /**\n * Creates breadcrumbs from this data model to the root namespace.\n */\n breadcrumbs(): FileBreadcrumb[] {\n const result: FileBreadcrumb[] = []\n result.push({\n key: this.key,\n name: this.info.name || 'Unnamed data model',\n kind: DataModelKind,\n })\n let parent = this.getParent()\n while (parent && parent !== this.root) {\n result.push({\n key: parent.key,\n kind: parent.kind,\n name: parent.info.name || 'Unnamed namespace',\n })\n parent = parent.getParent()\n }\n result.push({\n key: this.root.key,\n name: this.root.info.name || 'Unnamed namespace',\n kind: this.root.kind,\n })\n return result.reverse()\n }\n}\n"]}
|
|
@@ -5,6 +5,12 @@ import { IDataModel, DataModel } from './DataModel.js';
|
|
|
5
5
|
import { IDataProperty, DataProperty } from './DataProperty.js';
|
|
6
6
|
import { DataNamespaceKind, DataModelKind } from '../models/kinds.js';
|
|
7
7
|
type ItemKind = typeof DataNamespaceKind | typeof DataModelKind;
|
|
8
|
+
export interface DataItemAdaptingOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The index at which to adapt the item.
|
|
11
|
+
*/
|
|
12
|
+
index?: number;
|
|
13
|
+
}
|
|
8
14
|
interface IDataDefinitions {
|
|
9
15
|
models?: IDataModel[];
|
|
10
16
|
entities?: IDataEntity[];
|
|
@@ -35,7 +41,7 @@ interface DataDefinitions {
|
|
|
35
41
|
}
|
|
36
42
|
/**
|
|
37
43
|
* Data definition for a foreign namespace.
|
|
38
|
-
* Each
|
|
44
|
+
* Each foreign namespace is resolved to a specific version.
|
|
39
45
|
* This makes sure that the local data are always referencing an existing
|
|
40
46
|
* entity as breaking changes should be resolved when upgrading a version.
|
|
41
47
|
*/
|
|
@@ -167,6 +173,11 @@ export declare class DataNamespace extends DataNamespaceParent {
|
|
|
167
173
|
constructor(input?: string | IDataNamespace, root?: DataNamespace);
|
|
168
174
|
new(init: IDataNamespace): void;
|
|
169
175
|
toJSON(): IDataNamespace;
|
|
176
|
+
/**
|
|
177
|
+
* Checks if this is the root namespace.
|
|
178
|
+
* @returns True if this is the root namespace.
|
|
179
|
+
*/
|
|
180
|
+
isRoot(): boolean;
|
|
170
181
|
/**
|
|
171
182
|
* Finds a parent namespace for the given namespace.
|
|
172
183
|
* @param key The namespace key to find the parent for.
|
|
@@ -179,6 +190,14 @@ export declare class DataNamespace extends DataNamespaceParent {
|
|
|
179
190
|
* @param parent The optional key of the parent namespace to add the new namespace to.
|
|
180
191
|
*/
|
|
181
192
|
addNamespace(init: string | IDataNamespace | DataNamespace, parent?: string): DataNamespace;
|
|
193
|
+
/**
|
|
194
|
+
* Adapts an existing namespace to this namespace.
|
|
195
|
+
* This will remove the namespace from the parent namespace and add it to this one.
|
|
196
|
+
*
|
|
197
|
+
* @param ns The namespace to adapt.
|
|
198
|
+
* @param opts Adapting options.
|
|
199
|
+
*/
|
|
200
|
+
adaptNamespace(ns: DataNamespace, opts?: DataItemAdaptingOptions): void;
|
|
182
201
|
/**
|
|
183
202
|
* Finds a namespace in the definitions.
|
|
184
203
|
* @param key The key of the namespace to find.
|
|
@@ -259,6 +278,17 @@ export declare class DataNamespace extends DataNamespaceParent {
|
|
|
259
278
|
* @returns A list of entities. An `undefined` is put at the index where an entity cannot be found
|
|
260
279
|
*/
|
|
261
280
|
findAssociatedEntities(targets: AssociationTarget[]): (DataEntity | undefined)[];
|
|
281
|
+
/**
|
|
282
|
+
* Finds an associated entity in the current or foreign namespace.
|
|
283
|
+
* This is a helper function to discover entities in the current and foreign namespaces.
|
|
284
|
+
*
|
|
285
|
+
* @param key The key of the entity to find.
|
|
286
|
+
* @param namespace The optional namespace to search in.
|
|
287
|
+
* If not set, the current namespace is used.
|
|
288
|
+
* This is used to find entities in foreign namespaces.
|
|
289
|
+
* @returns The entity or undefined if not found.
|
|
290
|
+
*/
|
|
291
|
+
findAssociatedEntity(key: string, namespace?: string): DataEntity | undefined;
|
|
262
292
|
addForeign(ns: DataNamespace): void;
|
|
263
293
|
removeForeign(ns: DataNamespace): void;
|
|
264
294
|
hasForeignNamespace(key: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataNamespace.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataNamespace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC3F,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGrE,KAAK,QAAQ,GAAG,OAAO,iBAAiB,GAAG,OAAO,aAAa,CAAA;AAE/D,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,UAAU,EAAE,CAAA;IACrB,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,aAAa,EAAE,CAAA;IAC5B,YAAY,CAAC,EAAE,gBAAgB,EAAE,CAAA;IACjC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAA;IAC7B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAC7B;AAED,UAAU,eAAe;IACvB,MAAM,EAAE,SAAS,EAAE,CAAA;IAEnB,QAAQ,EAAE,UAAU,EAAE,CAAA;IAEtB,UAAU,EAAE,YAAY,EAAE,CAAA;IAE1B,YAAY,EAAE,eAAe,EAAE,CAAA;IAC/B,UAAU,EAAE,aAAa,EAAE,CAA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M,GAAG,OAAO;CAG1C"}
|
|
@@ -329,6 +329,13 @@ export class DataNamespace extends DataNamespaceParent {
|
|
|
329
329
|
}
|
|
330
330
|
return result;
|
|
331
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Checks if this is the root namespace.
|
|
334
|
+
* @returns True if this is the root namespace.
|
|
335
|
+
*/
|
|
336
|
+
isRoot() {
|
|
337
|
+
return this.root === undefined;
|
|
338
|
+
}
|
|
332
339
|
/**
|
|
333
340
|
* Finds a parent namespace for the given namespace.
|
|
334
341
|
* @param key The namespace key to find the parent for.
|
|
@@ -382,6 +389,55 @@ export class DataNamespace extends DataNamespaceParent {
|
|
|
382
389
|
root.items.push(item);
|
|
383
390
|
return definition;
|
|
384
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Adapts an existing namespace to this namespace.
|
|
394
|
+
* This will remove the namespace from the parent namespace and add it to this one.
|
|
395
|
+
*
|
|
396
|
+
* @param ns The namespace to adapt.
|
|
397
|
+
* @param opts Adapting options.
|
|
398
|
+
*/
|
|
399
|
+
adaptNamespace(ns, opts = {}) {
|
|
400
|
+
if (opts.index !== undefined) {
|
|
401
|
+
if (opts.index < 0) {
|
|
402
|
+
throw new Error(`The index ${opts.index} cannot be below 0.`);
|
|
403
|
+
}
|
|
404
|
+
if (opts.index >= this.items.length) {
|
|
405
|
+
throw new Error(`The index ${opts.index} is not valid.`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (ns === this) {
|
|
409
|
+
throw new Error(`Unable to adapt a namespace that is self.`);
|
|
410
|
+
}
|
|
411
|
+
if (ns.root !== this.root) {
|
|
412
|
+
throw new Error(`The namespace ${ns.key} is not in the same namespace as this data namespace.`);
|
|
413
|
+
}
|
|
414
|
+
if (ns.getParent() === this) {
|
|
415
|
+
throw new Error(`The namespace ${ns.key} is already adapted by this data namespace.`);
|
|
416
|
+
}
|
|
417
|
+
// Check for circular dependency
|
|
418
|
+
let current = this;
|
|
419
|
+
while (current) {
|
|
420
|
+
if (current === ns) {
|
|
421
|
+
throw new Error(`Unable to adapt namespace ${ns.key} under itself or one of its children.`);
|
|
422
|
+
}
|
|
423
|
+
current = current.getParent();
|
|
424
|
+
}
|
|
425
|
+
const parent = ns.getParent() || this.root;
|
|
426
|
+
if (!parent) {
|
|
427
|
+
throw new Error(`The namespace ${ns.key} has no parent.`);
|
|
428
|
+
}
|
|
429
|
+
const index = parent.items.findIndex((i) => i.key === ns.key);
|
|
430
|
+
if (index < 0) {
|
|
431
|
+
throw new Error(`The namespace ${ns.key} is not in the parent data namespace.`);
|
|
432
|
+
}
|
|
433
|
+
const [item] = parent.items.splice(index, 1);
|
|
434
|
+
if (opts.index !== undefined) {
|
|
435
|
+
this.items.splice(opts.index, 0, item);
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
this.items.push(item);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
385
441
|
/**
|
|
386
442
|
* Finds a namespace in the definitions.
|
|
387
443
|
* @param key The key of the namespace to find.
|
|
@@ -597,6 +653,29 @@ export class DataNamespace extends DataNamespaceParent {
|
|
|
597
653
|
});
|
|
598
654
|
return result;
|
|
599
655
|
}
|
|
656
|
+
/**
|
|
657
|
+
* Finds an associated entity in the current or foreign namespace.
|
|
658
|
+
* This is a helper function to discover entities in the current and foreign namespaces.
|
|
659
|
+
*
|
|
660
|
+
* @param key The key of the entity to find.
|
|
661
|
+
* @param namespace The optional namespace to search in.
|
|
662
|
+
* If not set, the current namespace is used.
|
|
663
|
+
* This is used to find entities in foreign namespaces.
|
|
664
|
+
* @returns The entity or undefined if not found.
|
|
665
|
+
*/
|
|
666
|
+
findAssociatedEntity(key, namespace) {
|
|
667
|
+
let ns;
|
|
668
|
+
if (namespace) {
|
|
669
|
+
ns = this.foreign.find((i) => i.key === namespace);
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
ns = this;
|
|
673
|
+
}
|
|
674
|
+
if (!ns) {
|
|
675
|
+
return undefined;
|
|
676
|
+
}
|
|
677
|
+
return ns.findEntity(key);
|
|
678
|
+
}
|
|
600
679
|
addForeign(ns) {
|
|
601
680
|
const exists = this.foreign.some((i) => i.key === ns.key);
|
|
602
681
|
if (exists) {
|