@api-client/core 0.11.2 → 0.11.3

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.
@@ -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 association.
222
+ * Removes a target entity from the targets list.
223
223
  *
224
- * @param entity - The `DataEntity` or `IDataEntity` instance to remove.
224
+ * @param init The key of an entity, its instance, or schema.
225
225
  */
226
- removeTarget(entity: DataEntity | IDataEntity): void;
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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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;IA0FjB;IAzFT,IAAI,GAAG,mBAAmB,CAAA;IAE1B,GAAG,GAAG,EAAE,CAAA;IAER;;OAEG;IACH,IAAI,GAAU,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAEhC;;OAEG;IACH,QAAQ,CAAU;IAElB;;OAEG;IACH,QAAQ,CAAU;IAElB;;;;OAIG;IACH,OAAO,GAAwB,EAAE,CAAA;IAEjC;;;;;;OAMG;IACH,MAAM,CAAuB;IAE7B;;;;;;OAMG;IACH,QAAQ,GAAyB,EAAE,CAAA;IAEnC;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,OAA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AAC;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,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;IA0FjB;IAzFT,IAAI,GAAG,mBAAmB,CAAA;IAE1B,GAAG,GAAG,EAAE,CAAA;IAER;;OAEG;IACH,IAAI,GAAU,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAEhC;;OAEG;IACH,QAAQ,CAAU;IAElB;;OAEG;IACH,QA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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"]}
@@ -35,7 +35,7 @@ interface DataDefinitions {
35
35
  }
36
36
  /**
37
37
  * Data definition for a foreign namespace.
38
- * Each foreigh namespace is resolved to a specific version.
38
+ * Each foreign namespace is resolved to a specific version.
39
39
  * This makes sure that the local data are always referencing an existing
40
40
  * entity as breaking changes should be resolved when upgrading a version.
41
41
  */
@@ -167,6 +167,11 @@ export declare class DataNamespace extends DataNamespaceParent {
167
167
  constructor(input?: string | IDataNamespace, root?: DataNamespace);
168
168
  new(init: IDataNamespace): void;
169
169
  toJSON(): IDataNamespace;
170
+ /**
171
+ * Checks if this is the root namespace.
172
+ * @returns True if this is the root namespace.
173
+ */
174
+ isRoot(): boolean;
170
175
  /**
171
176
  * Finds a parent namespace for the given namespace.
172
177
  * @param key The namespace key to find the parent for.
@@ -259,6 +264,17 @@ export declare class DataNamespace extends DataNamespaceParent {
259
264
  * @returns A list of entities. An `undefined` is put at the index where an entity cannot be found
260
265
  */
261
266
  findAssociatedEntities(targets: AssociationTarget[]): (DataEntity | undefined)[];
267
+ /**
268
+ * Finds an associated entity in the current or foreign namespace.
269
+ * This is a helper function to discover entities in the current and foreign namespaces.
270
+ *
271
+ * @param key The key of the entity to find.
272
+ * @param namespace The optional namespace to search in.
273
+ * If not set, the current namespace is used.
274
+ * This is used to find entities in foreign namespaces.
275
+ * @returns The entity or undefined if not found.
276
+ */
277
+ findAssociatedEntity(key: string, namespace?: string): DataEntity | undefined;
262
278
  addForeign(ns: DataNamespace): void;
263
279
  removeForeign(ns: DataNamespace): void;
264
280
  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,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,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.
@@ -597,6 +604,29 @@ export class DataNamespace extends DataNamespaceParent {
597
604
  });
598
605
  return result;
599
606
  }
607
+ /**
608
+ * Finds an associated entity in the current or foreign namespace.
609
+ * This is a helper function to discover entities in the current and foreign namespaces.
610
+ *
611
+ * @param key The key of the entity to find.
612
+ * @param namespace The optional namespace to search in.
613
+ * If not set, the current namespace is used.
614
+ * This is used to find entities in foreign namespaces.
615
+ * @returns The entity or undefined if not found.
616
+ */
617
+ findAssociatedEntity(key, namespace) {
618
+ let ns;
619
+ if (namespace) {
620
+ ns = this.foreign.find((i) => i.key === namespace);
621
+ }
622
+ else {
623
+ ns = this;
624
+ }
625
+ if (!ns) {
626
+ return undefined;
627
+ }
628
+ return ns.findEntity(key);
629
+ }
600
630
  addForeign(ns) {
601
631
  const exists = this.foreign.some((i) => i.key === ns.key);
602
632
  if (exists) {
@@ -1 +1 @@
1
- {"version":3,"file":"DataNamespace.js","sourceRoot":"","sources":["../../../src/modeling/DataNamespace.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,OAAO,EAAU,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAoB,eAAe,EAAqB,MAAM,sBAAsB,CAAA;AAC3F,OAAO,EAAe,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,EAAc,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAiB,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAE,MAAM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AAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAA;QACrD,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACf,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,GAAW;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAA;IAChD,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-this-alias */\nimport { IThing, Thing } from '../models/Thing.js'\nimport { IDataAssociation, DataAssociation, AssociationTarget } from './DataAssociation.js'\nimport { IDataEntity, DataEntity } from './DataEntity.js'\nimport { IDataModel, DataModel } from './DataModel.js'\nimport { IDataProperty, DataProperty } from './DataProperty.js'\nimport { DataNamespaceKind, DataModelKind } from '../models/kinds.js'\nimport v4 from '../lib/uuid.js'\n\ntype ItemKind = typeof DataNamespaceKind | typeof DataModelKind\n\ninterface IDataDefinitions {\n models?: IDataModel[]\n entities?: IDataEntity[]\n properties?: IDataProperty[]\n associations?: IDataAssociation[]\n namespaces?: IDataNamespace[]\n tags?: string[]\n /**\n * The list of foreign namespaces associated with this namespace.\n */\n foreign?: ForeignNamespace[]\n}\n\ninterface DataDefinitions {\n models: DataModel[]\n // @todo: This should be a map of entities with a key of the entity key.\n entities: DataEntity[]\n // @todo: This should be a map of properties with a key of the property key.\n properties: DataProperty[]\n // @todo: This should be a map of associations with a key of the association key.\n associations: DataAssociation[]\n namespaces: DataNamespace[]\n /**\n * Common for the entire root namespace tags.\n * These are kept separately so the UI can generate autocomplete for tags.\n */\n tags: string[]\n /**\n * The list of foreign namespaces associated with this namespace.\n */\n foreign?: ForeignNamespace[]\n}\n\n/**\n * Data definition for a foreign namespace.\n * Each foreigh namespace is resolved to a specific version.\n * This makes sure that the local data are always referencing an existing\n * entity as breaking changes should be resolved when upgrading a version.\n */\ninterface ForeignNamespace {\n key: string\n version: string\n}\n\ninterface IDataNamespaceParent {\n kind: typeof DataNamespaceKind\n /**\n * The key of the namespace.\n */\n key: string\n /**\n * The ordered list of items in this namespace.\n */\n items: IDataItem[]\n /**\n * The data namespace description.\n */\n info: IThing\n}\n\n/**\n * Data namespace is a logical description of the hierarchy in the data.\n */\nexport interface IDataNamespace extends IDataNamespaceParent {\n /**\n * The list of definitions used in the namespace.\n */\n definitions: IDataDefinitions\n}\n\n/**\n * Data item is a reference to an object in the top namespace definitions\n * to the namespace items.\n */\nexport interface IDataItem {\n /**\n * The kind of the item.\n */\n kind: ItemKind\n /**\n * The identifier in the `definitions` array of the namespace.\n */\n key: string\n}\n\nclass DataNamespaceParent {\n kind = DataNamespaceKind\n\n key = ''\n\n /**\n * The ordered list of items in this namespace.\n */\n items: DataItem[] = []\n\n /**\n * The description of the data namespace.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * When a namespace is a sub-namespace this is the reference to the\n * root namespace with all definitions.\n */\n root?: DataNamespace\n\n constructor(root?: DataNamespace) {\n this.root = root\n }\n\n /**\n * @returns The parent namespace of this namespace. It returns `undefined` when this is the root namespace.\n */\n getParent(): DataNamespace | undefined {\n const { root, key } = this\n if (root) {\n const result = (root as DataNamespace).findParent(key)\n if (result === this.root) {\n return undefined\n }\n return result\n }\n // we are the root namespace.\n return undefined\n }\n\n /**\n * Adds a data namespace to the structure.\n * @param init The name of the namespace to add, namespace's schema, or instance.\n */\n addNamespace(init: string | IDataNamespace | DataNamespace): DataNamespace {\n return (this.root as DataNamespace).addNamespace(init, this.key)\n }\n\n /**\n * Lists namespaces that are in this namespace items.\n */\n listNamespaces(): DataNamespace[] {\n const result: DataNamespace[] = []\n const { items } = this\n const root = this.getRoot()\n const { namespaces } = root.definitions\n items.forEach((i) => {\n if (i.kind !== DataNamespaceKind) {\n return\n }\n const def = namespaces.find((j) => j.key === i.key)\n if (def) {\n result.push(def)\n }\n })\n return result\n }\n\n /**\n * Lists namespaces that are in this namespace items.\n */\n listDataModels(): DataModel[] {\n const result: DataModel[] = []\n const { items } = this\n const root = this.getRoot()\n const { models } = root.definitions\n items.forEach((i) => {\n if (i.kind !== DataModelKind) {\n return\n }\n const def = models.find((j) => j.key === i.key)\n if (def) {\n result.push(def)\n }\n })\n return result\n }\n\n /**\n * @returns The root of the namespaces tree. It might be the same object.\n */\n getRoot(): DataNamespace {\n if (this.root) {\n return this.root\n }\n return this as unknown as DataNamespace\n }\n\n /**\n * Removes self from the parent namespace with all data models.\n * This does noting for the root namespace.\n */\n remove(): void {\n const { root } = this\n if (!root) {\n throw new Error(`Unable to remove the root namespace this way.`)\n }\n const models = this.listDataModels()\n const children = this.listNamespaces()\n models.forEach((m) => m.remove())\n children.forEach((c) => c.remove())\n const index = root.definitions.namespaces.findIndex((i) => i.key === this.key)\n if (index >= 0) {\n root.definitions.namespaces.splice(index, 1)\n }\n }\n}\n\nexport class DataItem implements IDataItem {\n kind: ItemKind = DataModelKind\n\n key = ''\n\n /**\n * A reference to the top level namespace.\n */\n private root: DataNamespace\n\n static isDataItem(input: unknown): boolean {\n const typed = input as IDataItem\n if (!input || ![DataModelKind, DataNamespaceKind].includes(typed.kind)) {\n return false\n }\n return true\n }\n\n static dataNamespace(root: DataNamespace, key: string): DataItem {\n const item = new DataItem(root, {\n kind: DataNamespaceKind,\n key,\n })\n return item\n }\n\n static dataModel(root: DataNamespace, key: string): DataItem {\n const item = new DataItem(root, {\n kind: DataModelKind,\n key,\n })\n return item\n }\n\n /**\n * @param root The top-most data namespace.\n * @param input The project item definition used to restore the state.\n */\n constructor(root: DataNamespace, input: string | IDataItem) {\n this.root = root\n let init: IDataItem\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n throw new Error('Specify the type of the item.')\n }\n this.new(init)\n }\n\n new(init: IDataItem): void {\n if (!DataItem.isDataItem(init)) {\n throw new Error(`Not a data item.`)\n }\n const { kind, key } = init\n this.kind = kind\n this.key = key\n }\n\n toJSON(): IDataItem {\n const result: IDataItem = {\n kind: this.kind,\n key: this.key,\n }\n return result\n }\n\n getItem(): DataNamespace | DataModel | undefined {\n const { root, key, kind } = this\n const { definitions } = root\n if (kind === DataModelKind) {\n return definitions.models.find((i) => i.key === key)\n }\n if (kind === kind) {\n return definitions.namespaces.find((i) => i.key === key)\n }\n }\n}\n\n/**\n * Data namespace is a logical description of the hierarchy in the data.\n */\nexport class DataNamespace extends DataNamespaceParent {\n definitions: DataDefinitions\n\n /**\n * The list of foreign namespaces.\n * This is used to find entities from foreign namespaces.\n * Values here are treated as read only (objects can be frozen).\n *\n * This should be set by the application and the namespace will do\n * nothing to populate this value.\n */\n foreign: DataNamespace[] = []\n\n /**\n * Creates a new data namespace from a name.\n * @param name The name to set.\n */\n static fromName(name: string, root?: DataNamespace): DataNamespace {\n const ns = new DataNamespace(undefined, root)\n const info = Thing.fromName(name)\n ns.info = info\n return ns\n }\n\n static definitions(): DataDefinitions {\n return {\n models: [],\n associations: [],\n entities: [],\n properties: [],\n namespaces: [],\n tags: [],\n }\n }\n\n constructor(input?: string | IDataNamespace, root?: DataNamespace) {\n super(root)\n this.definitions = DataNamespace.definitions()\n\n let init: IDataNamespace\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n if (!init.kind) {\n init.kind = DataNamespaceKind\n }\n } else {\n init = {\n kind: DataNamespaceKind,\n key: v4(),\n definitions: {},\n items: [],\n info: Thing.fromName('').toJSON(),\n }\n }\n this.new(init)\n }\n\n new(init: IDataNamespace): void {\n if (!init || !init.definitions || !init.items) {\n throw new Error(`Not a data namespace.`)\n }\n const { key = v4(), definitions = {}, items, info } = init\n this.key = key\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n if (Array.isArray(items)) {\n this.items = items.map((i) => new DataItem(this, i))\n } else {\n this.items = []\n }\n if (Array.isArray(definitions.associations)) {\n this.definitions.associations = definitions.associations.map((i) => new DataAssociation(this, i))\n } else {\n this.definitions.associations = []\n }\n if (Array.isArray(definitions.properties)) {\n this.definitions.properties = definitions.properties.map((i) => new DataProperty(this, i))\n } else {\n this.definitions.properties = []\n }\n // note, entities must be restored after properties / associations\n if (Array.isArray(definitions.entities)) {\n this.definitions.entities = definitions.entities.map((i) => new DataEntity(this, i))\n } else {\n this.definitions.entities = []\n }\n // must be set after entities.\n if (Array.isArray(definitions.models)) {\n this.definitions.models = definitions.models.map((i) => new DataModel(this, i))\n } else {\n this.definitions.models = []\n }\n if (Array.isArray(definitions.namespaces)) {\n this.definitions.namespaces = definitions.namespaces.map((i) => new DataNamespace(i, this))\n } else {\n this.definitions.namespaces = []\n }\n if (Array.isArray(definitions.tags)) {\n this.definitions.tags = [...definitions.tags]\n } else {\n this.definitions.tags = []\n }\n }\n\n toJSON(): IDataNamespace {\n const result: IDataNamespace = {\n key: this.key,\n kind: DataNamespaceKind,\n info: this.info.toJSON(),\n items: this.items.map((i) => i.toJSON()),\n definitions: {},\n }\n const { associations, entities, models, namespaces, properties, tags } = this.definitions\n if (Array.isArray(associations) && associations.length) {\n result.definitions.associations = associations.map((i) => i.toJSON())\n }\n if (Array.isArray(entities) && entities.length) {\n result.definitions.entities = entities.map((i) => i.toJSON())\n }\n if (Array.isArray(models) && models.length) {\n result.definitions.models = models.map((i) => i.toJSON())\n }\n if (Array.isArray(namespaces) && namespaces.length) {\n result.definitions.namespaces = namespaces.map((i) => i.toJSON())\n }\n if (Array.isArray(properties) && properties.length) {\n result.definitions.properties = properties.map((i) => i.toJSON())\n }\n if (Array.isArray(tags) && tags.length) {\n result.definitions.tags = [...tags]\n }\n return result\n }\n\n /**\n * Finds a parent namespace for the given namespace.\n * @param key The namespace key to find the parent for.\n * @returns The parent namespace or undefined when the namespace does not exist. It may return the root namespace.\n */\n findParent(key: string): DataNamespace | undefined {\n const { definitions, items = [] } = this\n const rootIndex = items.findIndex((i) => i.key === key)\n if (rootIndex >= 0) {\n return this\n }\n const definition = definitions.namespaces.find((i) => i.items.some((item) => item.key === key))\n if (definition) {\n return definition\n }\n return undefined\n }\n\n /**\n * Adds a data namespace to the structure.\n * @param init The name of the namespace to add, namespace's schema, or instance.\n * @param parent The optional key of the parent namespace to add the new namespace to.\n */\n override addNamespace(init: string | IDataNamespace | DataNamespace, parent?: string): DataNamespace {\n let root: DataNamespace\n if (parent) {\n const rootCandidate = this.findParent(parent)\n if (!rootCandidate) {\n throw new Error(`Unable to find the parent namespace ${parent}`)\n }\n root = rootCandidate\n } else {\n root = this\n }\n let definition: DataNamespace\n if (typeof init === 'string') {\n definition = DataNamespace.fromName(init, this.root || this)\n } else if (init instanceof DataNamespace) {\n definition = init\n } else {\n definition = new DataNamespace(init, this.root || this)\n }\n ;(this.root || this).definitions.namespaces.push(definition)\n const item = DataItem.dataNamespace(this.root || this, definition.key)\n if (!Array.isArray(root.items)) {\n root.items = []\n }\n root.items.push(item)\n return definition\n }\n\n /**\n * Finds a namespace in the definitions.\n * @param key The key of the namespace to find.\n * @returns The namespace definition or undefined when not found.\n */\n findNamespace(key: string): DataNamespace | undefined {\n const { definitions } = this.root || this\n return definitions.namespaces.find((i) => i.key === key)\n }\n\n /**\n * Finds a namespace and calls the `remove()` on it.\n * @param key The key of the namespace to find.\n */\n removeNamespace(key: string): void {\n const root = this.root || this\n if (root.key === key) {\n throw new Error(`Unable to remove the root namespace this way.`)\n }\n const { definitions } = root\n const ns = definitions.namespaces.find((i) => i.key === key)\n if (ns) {\n ns.remove()\n }\n }\n\n /**\n * Adds a data model to a namespace.\n * @param init The name of the data model to add, data model's schema, or its instance.\n * @param parent The optional key of the parent namespace to add the new data model to.\n */\n addDataModel(init: string | IDataModel | DataModel, parent?: string): DataModel {\n let root: DataNamespace\n if (parent) {\n const rootCandidate = this.findNamespace(parent)\n if (!rootCandidate) {\n throw new Error(`Unable to find the parent namespace ${parent}`)\n }\n root = rootCandidate\n } else {\n root = this\n }\n let definition: DataModel\n if (typeof init === 'string') {\n definition = DataModel.fromName(this.root || this, init)\n } else if (init instanceof DataModel) {\n definition = init\n } else {\n definition = new DataModel(this.root || this, init)\n }\n ;(this.root || this).definitions.models.push(definition)\n const item = DataItem.dataModel(this.root || this, definition.key)\n if (!Array.isArray(root.items)) {\n root.items = []\n }\n root.items.push(item)\n return definition\n }\n\n /**\n * Finds a data model in the definitions.\n * @param key The key of the data model to find.\n * @returns The data model definition or undefined when not found.\n */\n findDataModel(key: string): DataModel | undefined {\n const { definitions } = this.root || this\n return definitions.models.find((i) => i.key === key)\n }\n\n /**\n * Finds a data model and calls the `remove()` on it.\n * @param key The key of the data model to find.\n */\n removeDataModel(key: string): void {\n const { definitions } = this.root || this\n const model = definitions.models.find((i) => i.key === key)\n if (model) {\n model.remove()\n }\n }\n\n /**\n * @returns The graph of associations where keys are the source\n * entities and the value is the list of all target entities.\n */\n associationGraph(): Record<string, string[]> {\n const graph: Record<string, string[]> = {}\n const { definitions } = this.root || this\n const { associations, entities } = definitions\n for (const assoc of associations) {\n if (!assoc.targets.length) {\n continue\n }\n const srcEntity = entities.find((i) => i.associations.some((a) => a === assoc))\n if (!srcEntity) {\n continue\n }\n if (!graph[srcEntity.key]) {\n graph[srcEntity.key] = []\n }\n const targetIds = assoc.targets.map((i) => i.key)\n graph[srcEntity.key].splice(0, 0, ...targetIds)\n }\n return graph\n }\n\n /**\n * Prints out all associations from one entity to another through all entities that may be in between.\n *\n * @param from The key of the from entity\n * @param to The key of the target entity\n * @param g The graph generated with `associationGraph()`\n * @param path The current list of entity ids. Do not set this, it is for the recursive processing of the graph.\n * @param visited The list of visited paths to avoid cycles.\n * Do not set this, it is for the recursive processing of the graph.\n */\n *associationPath(\n from: string,\n to: string,\n g: Record<string, string[]>,\n path: string[] = [],\n visited = new Set<string>()\n ): Generator<string[]> {\n if (from === to) {\n yield path.concat(to)\n return\n }\n if (visited.has(from)) {\n // it's a cycle\n return\n }\n if (g[from]) {\n visited.add(from)\n path.push(from)\n\n for (const neighbor of g[from]) {\n yield* this.associationPath(neighbor, to, g, path, visited)\n }\n\n visited.delete(from)\n path.pop()\n }\n }\n\n /**\n * Scans all associations for foreign namespaces and returns\n * the list of all namespaces used in the association graph.\n * This will never add this namespace's key.\n *\n * This function should be used to read keys for all related\n * namespaces through associations.\n *\n * @returns All keys of foreign namespaces.\n */\n computeForeignNamespaceKeys(): string[] {\n const result: string[] = []\n const { associations = [] } = this.definitions\n associations.forEach((association) => {\n const { targets = [] } = association\n targets.forEach((target) => {\n const { namespace } = target\n if (!namespace || namespace === this.key) {\n return\n }\n result.push(namespace)\n })\n })\n return result\n }\n\n /**\n * Finds an entity in this namespace.\n * @param key The key of the entity to find.\n */\n findEntity(key: string): DataEntity | undefined {\n const { definitions } = this.root || this\n return definitions.entities.find((i) => i.key === key)\n }\n\n /**\n * Finds a property by its key.\n * @param key The key of the property to find\n * @returns The property or undefined if not found.\n */\n findProperty(key: string): DataProperty | undefined {\n const { definitions } = this.root || this\n return definitions.properties.find((i) => i.key === key)\n }\n\n /**\n * Finds an association by its key.\n * @param key The key of the property to find\n * @returns The property or undefined if not found.\n */\n findAssociation(key: string): DataAssociation | undefined {\n const { definitions } = this.root || this\n return definitions.associations.find((i) => i.key === key)\n }\n\n /**\n * Searches for entities for association targets.\n * This is a helper function to discover entities in the current and foreign namespaces.\n *\n * @param targets The list of targets\n * @returns A list of entities. An `undefined` is put at the index where an entity cannot be found\n */\n findAssociatedEntities(targets: AssociationTarget[]): (DataEntity | undefined)[] {\n const result: (DataEntity | undefined)[] = []\n targets.forEach((target) => {\n let ns: DataNamespace | undefined\n if (target.namespace) {\n ns = this.foreign.find((i) => i.key === target.namespace)\n } else {\n ns = this\n }\n if (!ns) {\n result.push(undefined)\n return\n }\n const entity = ns.findEntity(target.key)\n if (entity) {\n result.push(entity)\n } else {\n result.push(undefined)\n }\n })\n return result\n }\n\n addForeign(ns: DataNamespace): void {\n const exists = this.foreign.some((i) => i.key === ns.key)\n if (exists) {\n return\n }\n this.foreign.push(ns)\n }\n\n removeForeign(ns: DataNamespace): void {\n const index = this.foreign.findIndex((i) => i === ns)\n if (index >= 0) {\n this.foreign.splice(index, 1)\n }\n }\n\n hasForeignNamespace(key: string): boolean {\n return this.foreign.some((i) => i.key === key)\n }\n}\n"]}
1
+ {"version":3,"file":"DataNamespace.js","sourceRoot":"","sources":["../../../src/modeling/DataNamespace.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,OAAO,EAAU,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAoB,eAAe,EAAqB,MAAM,sBAAsB,CAAA;AAC3F,OAAO,EAAe,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,EAAc,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAiB,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAyF/B,MAAM,mBAAmB;IACvB,IAAI,GAAG,iBAAiB,CAAA;IAExB,GAAG,GAAG,EAAE,CAAA;IAER;;OAEG;IACH,KAAK,GAAe,EAAE,CAAA;IAEtB;;OAEG;IACH,IAAI,GAAU,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAEhC;;;OAGG;IACH,IAAI,CAAgB;IAEpB,YAAY,IAAoB;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED;;OAEG;IACH,SAAS;QACP,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;QAC1B,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,MAAM,GAAI,IAAsB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;YACtD,IAAI,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;gBACzB,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,OAAO,MAAM,CA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,EAAE,CAAC;YACf,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,GAAW;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAA;IAChD,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-this-alias */\nimport { IThing, Thing } from '../models/Thing.js'\nimport { IDataAssociation, DataAssociation, AssociationTarget } from './DataAssociation.js'\nimport { IDataEntity, DataEntity } from './DataEntity.js'\nimport { IDataModel, DataModel } from './DataModel.js'\nimport { IDataProperty, DataProperty } from './DataProperty.js'\nimport { DataNamespaceKind, DataModelKind } from '../models/kinds.js'\nimport v4 from '../lib/uuid.js'\n\ntype ItemKind = typeof DataNamespaceKind | typeof DataModelKind\n\ninterface IDataDefinitions {\n models?: IDataModel[]\n entities?: IDataEntity[]\n properties?: IDataProperty[]\n associations?: IDataAssociation[]\n namespaces?: IDataNamespace[]\n tags?: string[]\n /**\n * The list of foreign namespaces associated with this namespace.\n */\n foreign?: ForeignNamespace[]\n}\n\ninterface DataDefinitions {\n models: DataModel[]\n // @todo: This should be a map of entities with a key of the entity key.\n entities: DataEntity[]\n // @todo: This should be a map of properties with a key of the property key.\n properties: DataProperty[]\n // @todo: This should be a map of associations with a key of the association key.\n associations: DataAssociation[]\n namespaces: DataNamespace[]\n /**\n * Common for the entire root namespace tags.\n * These are kept separately so the UI can generate autocomplete for tags.\n */\n tags: string[]\n /**\n * The list of foreign namespaces associated with this namespace.\n */\n foreign?: ForeignNamespace[]\n}\n\n/**\n * Data definition for a foreign namespace.\n * Each foreign namespace is resolved to a specific version.\n * This makes sure that the local data are always referencing an existing\n * entity as breaking changes should be resolved when upgrading a version.\n */\ninterface ForeignNamespace {\n key: string\n version: string\n}\n\ninterface IDataNamespaceParent {\n kind: typeof DataNamespaceKind\n /**\n * The key of the namespace.\n */\n key: string\n /**\n * The ordered list of items in this namespace.\n */\n items: IDataItem[]\n /**\n * The data namespace description.\n */\n info: IThing\n}\n\n/**\n * Data namespace is a logical description of the hierarchy in the data.\n */\nexport interface IDataNamespace extends IDataNamespaceParent {\n /**\n * The list of definitions used in the namespace.\n */\n definitions: IDataDefinitions\n}\n\n/**\n * Data item is a reference to an object in the top namespace definitions\n * to the namespace items.\n */\nexport interface IDataItem {\n /**\n * The kind of the item.\n */\n kind: ItemKind\n /**\n * The identifier in the `definitions` array of the namespace.\n */\n key: string\n}\n\nclass DataNamespaceParent {\n kind = DataNamespaceKind\n\n key = ''\n\n /**\n * The ordered list of items in this namespace.\n */\n items: DataItem[] = []\n\n /**\n * The description of the data namespace.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * When a namespace is a sub-namespace this is the reference to the\n * root namespace with all definitions.\n */\n root?: DataNamespace\n\n constructor(root?: DataNamespace) {\n this.root = root\n }\n\n /**\n * @returns The parent namespace of this namespace. It returns `undefined` when this is the root namespace.\n */\n getParent(): DataNamespace | undefined {\n const { root, key } = this\n if (root) {\n const result = (root as DataNamespace).findParent(key)\n if (result === this.root) {\n return undefined\n }\n return result\n }\n // we are the root namespace.\n return undefined\n }\n\n /**\n * Adds a data namespace to the structure.\n * @param init The name of the namespace to add, namespace's schema, or instance.\n */\n addNamespace(init: string | IDataNamespace | DataNamespace): DataNamespace {\n return (this.root as DataNamespace).addNamespace(init, this.key)\n }\n\n /**\n * Lists namespaces that are in this namespace items.\n */\n listNamespaces(): DataNamespace[] {\n const result: DataNamespace[] = []\n const { items } = this\n const root = this.getRoot()\n const { namespaces } = root.definitions\n items.forEach((i) => {\n if (i.kind !== DataNamespaceKind) {\n return\n }\n const def = namespaces.find((j) => j.key === i.key)\n if (def) {\n result.push(def)\n }\n })\n return result\n }\n\n /**\n * Lists namespaces that are in this namespace items.\n */\n listDataModels(): DataModel[] {\n const result: DataModel[] = []\n const { items } = this\n const root = this.getRoot()\n const { models } = root.definitions\n items.forEach((i) => {\n if (i.kind !== DataModelKind) {\n return\n }\n const def = models.find((j) => j.key === i.key)\n if (def) {\n result.push(def)\n }\n })\n return result\n }\n\n /**\n * @returns The root of the namespaces tree. It might be the same object.\n */\n getRoot(): DataNamespace {\n if (this.root) {\n return this.root\n }\n return this as unknown as DataNamespace\n }\n\n /**\n * Removes self from the parent namespace with all data models.\n * This does noting for the root namespace.\n */\n remove(): void {\n const { root } = this\n if (!root) {\n throw new Error(`Unable to remove the root namespace this way.`)\n }\n const models = this.listDataModels()\n const children = this.listNamespaces()\n models.forEach((m) => m.remove())\n children.forEach((c) => c.remove())\n const index = root.definitions.namespaces.findIndex((i) => i.key === this.key)\n if (index >= 0) {\n root.definitions.namespaces.splice(index, 1)\n }\n }\n}\n\nexport class DataItem implements IDataItem {\n kind: ItemKind = DataModelKind\n\n key = ''\n\n /**\n * A reference to the top level namespace.\n */\n private root: DataNamespace\n\n static isDataItem(input: unknown): boolean {\n const typed = input as IDataItem\n if (!input || ![DataModelKind, DataNamespaceKind].includes(typed.kind)) {\n return false\n }\n return true\n }\n\n static dataNamespace(root: DataNamespace, key: string): DataItem {\n const item = new DataItem(root, {\n kind: DataNamespaceKind,\n key,\n })\n return item\n }\n\n static dataModel(root: DataNamespace, key: string): DataItem {\n const item = new DataItem(root, {\n kind: DataModelKind,\n key,\n })\n return item\n }\n\n /**\n * @param root The top-most data namespace.\n * @param input The project item definition used to restore the state.\n */\n constructor(root: DataNamespace, input: string | IDataItem) {\n this.root = root\n let init: IDataItem\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n throw new Error('Specify the type of the item.')\n }\n this.new(init)\n }\n\n new(init: IDataItem): void {\n if (!DataItem.isDataItem(init)) {\n throw new Error(`Not a data item.`)\n }\n const { kind, key } = init\n this.kind = kind\n this.key = key\n }\n\n toJSON(): IDataItem {\n const result: IDataItem = {\n kind: this.kind,\n key: this.key,\n }\n return result\n }\n\n getItem(): DataNamespace | DataModel | undefined {\n const { root, key, kind } = this\n const { definitions } = root\n if (kind === DataModelKind) {\n return definitions.models.find((i) => i.key === key)\n }\n if (kind === kind) {\n return definitions.namespaces.find((i) => i.key === key)\n }\n }\n}\n\n/**\n * Data namespace is a logical description of the hierarchy in the data.\n */\nexport class DataNamespace extends DataNamespaceParent {\n definitions: DataDefinitions\n\n /**\n * The list of foreign namespaces.\n * This is used to find entities from foreign namespaces.\n * Values here are treated as read only (objects can be frozen).\n *\n * This should be set by the application and the namespace will do\n * nothing to populate this value.\n */\n foreign: DataNamespace[] = []\n\n /**\n * Creates a new data namespace from a name.\n * @param name The name to set.\n */\n static fromName(name: string, root?: DataNamespace): DataNamespace {\n const ns = new DataNamespace(undefined, root)\n const info = Thing.fromName(name)\n ns.info = info\n return ns\n }\n\n static definitions(): DataDefinitions {\n return {\n models: [],\n associations: [],\n entities: [],\n properties: [],\n namespaces: [],\n tags: [],\n }\n }\n\n constructor(input?: string | IDataNamespace, root?: DataNamespace) {\n super(root)\n this.definitions = DataNamespace.definitions()\n\n let init: IDataNamespace\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n if (!init.kind) {\n init.kind = DataNamespaceKind\n }\n } else {\n init = {\n kind: DataNamespaceKind,\n key: v4(),\n definitions: {},\n items: [],\n info: Thing.fromName('').toJSON(),\n }\n }\n this.new(init)\n }\n\n new(init: IDataNamespace): void {\n if (!init || !init.definitions || !init.items) {\n throw new Error(`Not a data namespace.`)\n }\n const { key = v4(), definitions = {}, items, info } = init\n this.key = key\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n if (Array.isArray(items)) {\n this.items = items.map((i) => new DataItem(this, i))\n } else {\n this.items = []\n }\n if (Array.isArray(definitions.associations)) {\n this.definitions.associations = definitions.associations.map((i) => new DataAssociation(this, i))\n } else {\n this.definitions.associations = []\n }\n if (Array.isArray(definitions.properties)) {\n this.definitions.properties = definitions.properties.map((i) => new DataProperty(this, i))\n } else {\n this.definitions.properties = []\n }\n // note, entities must be restored after properties / associations\n if (Array.isArray(definitions.entities)) {\n this.definitions.entities = definitions.entities.map((i) => new DataEntity(this, i))\n } else {\n this.definitions.entities = []\n }\n // must be set after entities.\n if (Array.isArray(definitions.models)) {\n this.definitions.models = definitions.models.map((i) => new DataModel(this, i))\n } else {\n this.definitions.models = []\n }\n if (Array.isArray(definitions.namespaces)) {\n this.definitions.namespaces = definitions.namespaces.map((i) => new DataNamespace(i, this))\n } else {\n this.definitions.namespaces = []\n }\n if (Array.isArray(definitions.tags)) {\n this.definitions.tags = [...definitions.tags]\n } else {\n this.definitions.tags = []\n }\n }\n\n toJSON(): IDataNamespace {\n const result: IDataNamespace = {\n key: this.key,\n kind: DataNamespaceKind,\n info: this.info.toJSON(),\n items: this.items.map((i) => i.toJSON()),\n definitions: {},\n }\n const { associations, entities, models, namespaces, properties, tags } = this.definitions\n if (Array.isArray(associations) && associations.length) {\n result.definitions.associations = associations.map((i) => i.toJSON())\n }\n if (Array.isArray(entities) && entities.length) {\n result.definitions.entities = entities.map((i) => i.toJSON())\n }\n if (Array.isArray(models) && models.length) {\n result.definitions.models = models.map((i) => i.toJSON())\n }\n if (Array.isArray(namespaces) && namespaces.length) {\n result.definitions.namespaces = namespaces.map((i) => i.toJSON())\n }\n if (Array.isArray(properties) && properties.length) {\n result.definitions.properties = properties.map((i) => i.toJSON())\n }\n if (Array.isArray(tags) && tags.length) {\n result.definitions.tags = [...tags]\n }\n return result\n }\n\n /**\n * Checks if this is the root namespace.\n * @returns True if this is the root namespace.\n */\n isRoot(): boolean {\n return this.root === undefined\n }\n\n /**\n * Finds a parent namespace for the given namespace.\n * @param key The namespace key to find the parent for.\n * @returns The parent namespace or undefined when the namespace does not exist. It may return the root namespace.\n */\n findParent(key: string): DataNamespace | undefined {\n const { definitions, items = [] } = this\n const rootIndex = items.findIndex((i) => i.key === key)\n if (rootIndex >= 0) {\n return this\n }\n const definition = definitions.namespaces.find((i) => i.items.some((item) => item.key === key))\n if (definition) {\n return definition\n }\n return undefined\n }\n\n /**\n * Adds a data namespace to the structure.\n * @param init The name of the namespace to add, namespace's schema, or instance.\n * @param parent The optional key of the parent namespace to add the new namespace to.\n */\n override addNamespace(init: string | IDataNamespace | DataNamespace, parent?: string): DataNamespace {\n let root: DataNamespace\n if (parent) {\n const rootCandidate = this.findParent(parent)\n if (!rootCandidate) {\n throw new Error(`Unable to find the parent namespace ${parent}`)\n }\n root = rootCandidate\n } else {\n root = this\n }\n let definition: DataNamespace\n if (typeof init === 'string') {\n definition = DataNamespace.fromName(init, this.root || this)\n } else if (init instanceof DataNamespace) {\n definition = init\n } else {\n definition = new DataNamespace(init, this.root || this)\n }\n ;(this.root || this).definitions.namespaces.push(definition)\n const item = DataItem.dataNamespace(this.root || this, definition.key)\n if (!Array.isArray(root.items)) {\n root.items = []\n }\n root.items.push(item)\n return definition\n }\n\n /**\n * Finds a namespace in the definitions.\n * @param key The key of the namespace to find.\n * @returns The namespace definition or undefined when not found.\n */\n findNamespace(key: string): DataNamespace | undefined {\n const { definitions } = this.root || this\n return definitions.namespaces.find((i) => i.key === key)\n }\n\n /**\n * Finds a namespace and calls the `remove()` on it.\n * @param key The key of the namespace to find.\n */\n removeNamespace(key: string): void {\n const root = this.root || this\n if (root.key === key) {\n throw new Error(`Unable to remove the root namespace this way.`)\n }\n const { definitions } = root\n const ns = definitions.namespaces.find((i) => i.key === key)\n if (ns) {\n ns.remove()\n }\n }\n\n /**\n * Adds a data model to a namespace.\n * @param init The name of the data model to add, data model's schema, or its instance.\n * @param parent The optional key of the parent namespace to add the new data model to.\n */\n addDataModel(init: string | IDataModel | DataModel, parent?: string): DataModel {\n let root: DataNamespace\n if (parent) {\n const rootCandidate = this.findNamespace(parent)\n if (!rootCandidate) {\n throw new Error(`Unable to find the parent namespace ${parent}`)\n }\n root = rootCandidate\n } else {\n root = this\n }\n let definition: DataModel\n if (typeof init === 'string') {\n definition = DataModel.fromName(this.root || this, init)\n } else if (init instanceof DataModel) {\n definition = init\n } else {\n definition = new DataModel(this.root || this, init)\n }\n ;(this.root || this).definitions.models.push(definition)\n const item = DataItem.dataModel(this.root || this, definition.key)\n if (!Array.isArray(root.items)) {\n root.items = []\n }\n root.items.push(item)\n return definition\n }\n\n /**\n * Finds a data model in the definitions.\n * @param key The key of the data model to find.\n * @returns The data model definition or undefined when not found.\n */\n findDataModel(key: string): DataModel | undefined {\n const { definitions } = this.root || this\n return definitions.models.find((i) => i.key === key)\n }\n\n /**\n * Finds a data model and calls the `remove()` on it.\n * @param key The key of the data model to find.\n */\n removeDataModel(key: string): void {\n const { definitions } = this.root || this\n const model = definitions.models.find((i) => i.key === key)\n if (model) {\n model.remove()\n }\n }\n\n /**\n * @returns The graph of associations where keys are the source\n * entities and the value is the list of all target entities.\n */\n associationGraph(): Record<string, string[]> {\n const graph: Record<string, string[]> = {}\n const { definitions } = this.root || this\n const { associations, entities } = definitions\n for (const assoc of associations) {\n if (!assoc.targets.length) {\n continue\n }\n const srcEntity = entities.find((i) => i.associations.some((a) => a === assoc))\n if (!srcEntity) {\n continue\n }\n if (!graph[srcEntity.key]) {\n graph[srcEntity.key] = []\n }\n const targetIds = assoc.targets.map((i) => i.key)\n graph[srcEntity.key].splice(0, 0, ...targetIds)\n }\n return graph\n }\n\n /**\n * Prints out all associations from one entity to another through all entities that may be in between.\n *\n * @param from The key of the from entity\n * @param to The key of the target entity\n * @param g The graph generated with `associationGraph()`\n * @param path The current list of entity ids. Do not set this, it is for the recursive processing of the graph.\n * @param visited The list of visited paths to avoid cycles.\n * Do not set this, it is for the recursive processing of the graph.\n */\n *associationPath(\n from: string,\n to: string,\n g: Record<string, string[]>,\n path: string[] = [],\n visited = new Set<string>()\n ): Generator<string[]> {\n if (from === to) {\n yield path.concat(to)\n return\n }\n if (visited.has(from)) {\n // it's a cycle\n return\n }\n if (g[from]) {\n visited.add(from)\n path.push(from)\n\n for (const neighbor of g[from]) {\n yield* this.associationPath(neighbor, to, g, path, visited)\n }\n\n visited.delete(from)\n path.pop()\n }\n }\n\n /**\n * Scans all associations for foreign namespaces and returns\n * the list of all namespaces used in the association graph.\n * This will never add this namespace's key.\n *\n * This function should be used to read keys for all related\n * namespaces through associations.\n *\n * @returns All keys of foreign namespaces.\n */\n computeForeignNamespaceKeys(): string[] {\n const result: string[] = []\n const { associations = [] } = this.definitions\n associations.forEach((association) => {\n const { targets = [] } = association\n targets.forEach((target) => {\n const { namespace } = target\n if (!namespace || namespace === this.key) {\n return\n }\n result.push(namespace)\n })\n })\n return result\n }\n\n /**\n * Finds an entity in this namespace.\n * @param key The key of the entity to find.\n */\n findEntity(key: string): DataEntity | undefined {\n const { definitions } = this.root || this\n return definitions.entities.find((i) => i.key === key)\n }\n\n /**\n * Finds a property by its key.\n * @param key The key of the property to find\n * @returns The property or undefined if not found.\n */\n findProperty(key: string): DataProperty | undefined {\n const { definitions } = this.root || this\n return definitions.properties.find((i) => i.key === key)\n }\n\n /**\n * Finds an association by its key.\n * @param key The key of the property to find\n * @returns The property or undefined if not found.\n */\n findAssociation(key: string): DataAssociation | undefined {\n const { definitions } = this.root || this\n return definitions.associations.find((i) => i.key === key)\n }\n\n /**\n * Searches for entities for association targets.\n * This is a helper function to discover entities in the current and foreign namespaces.\n *\n * @param targets The list of targets\n * @returns A list of entities. An `undefined` is put at the index where an entity cannot be found\n */\n findAssociatedEntities(targets: AssociationTarget[]): (DataEntity | undefined)[] {\n const result: (DataEntity | undefined)[] = []\n targets.forEach((target) => {\n let ns: DataNamespace | undefined\n if (target.namespace) {\n ns = this.foreign.find((i) => i.key === target.namespace)\n } else {\n ns = this\n }\n if (!ns) {\n result.push(undefined)\n return\n }\n const entity = ns.findEntity(target.key)\n if (entity) {\n result.push(entity)\n } else {\n result.push(undefined)\n }\n })\n return result\n }\n\n /**\n * Finds an associated entity in the current or foreign namespace.\n * This is a helper function to discover entities in the current and foreign namespaces.\n *\n * @param key The key of the entity to find.\n * @param namespace The optional namespace to search in.\n * If not set, the current namespace is used.\n * This is used to find entities in foreign namespaces.\n * @returns The entity or undefined if not found.\n */\n findAssociatedEntity(key: string, namespace?: string): DataEntity | undefined {\n let ns: DataNamespace | undefined\n if (namespace) {\n ns = this.foreign.find((i) => i.key === namespace)\n } else {\n ns = this\n }\n if (!ns) {\n return undefined\n }\n return ns.findEntity(key)\n }\n\n addForeign(ns: DataNamespace): void {\n const exists = this.foreign.some((i) => i.key === ns.key)\n if (exists) {\n return\n }\n this.foreign.push(ns)\n }\n\n removeForeign(ns: DataNamespace): void {\n const index = this.foreign.findIndex((i) => i === ns)\n if (index >= 0) {\n this.foreign.splice(index, 1)\n }\n }\n\n hasForeignNamespace(key: string): boolean {\n return this.foreign.some((i) => i.key === key)\n }\n}\n"]}
@@ -42470,9 +42470,6 @@
42470
42470
  "@id": "#219"
42471
42471
  },
42472
42472
  {
42473
- "@id": "#213"
42474
- },
42475
- {
42476
42473
  "@id": "#210"
42477
42474
  },
42478
42475
  {
@@ -42480,6 +42477,9 @@
42480
42477
  },
42481
42478
  {
42482
42479
  "@id": "#216"
42480
+ },
42481
+ {
42482
+ "@id": "#213"
42483
42483
  }
42484
42484
  ],
42485
42485
  "doc:root": false,
@@ -43892,7 +43892,7 @@
43892
43892
  "doc:ExternalDomainElement",
43893
43893
  "doc:DomainElement"
43894
43894
  ],
43895
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
43895
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
43896
43896
  "core:mediaType": "application/yaml",
43897
43897
  "sourcemaps:sources": [
43898
43898
  {
@@ -43913,7 +43913,7 @@
43913
43913
  "doc:ExternalDomainElement",
43914
43914
  "doc:DomainElement"
43915
43915
  ],
43916
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
43916
+ "doc:raw": "type: \"GENERAL\"\nvalue: \"www.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": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
43937
+ "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
43938
43938
  "core:mediaType": "application/yaml",
43939
43939
  "sourcemaps:sources": [
43940
43940
  {
@@ -43955,7 +43955,7 @@
43955
43955
  "doc:ExternalDomainElement",
43956
43956
  "doc:DomainElement"
43957
43957
  ],
43958
- "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
43958
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
43959
43959
  "core:mediaType": "application/yaml",
43960
43960
  "sourcemaps:sources": [
43961
43961
  {
@@ -44781,17 +44781,17 @@
44781
44781
  {
44782
44782
  "@id": "#215/source-map/lexical/element_0",
44783
44783
  "sourcemaps:element": "amf://id#215",
44784
- "sourcemaps:value": "[(1,0)-(6,0)]"
44784
+ "sourcemaps:value": "[(1,0)-(3,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)-(3,0)]"
44789
+ "sourcemaps:value": "[(1,0)-(7,0)]"
44790
44790
  },
44791
44791
  {
44792
44792
  "@id": "#221/source-map/lexical/element_0",
44793
44793
  "sourcemaps:element": "amf://id#221",
44794
- "sourcemaps:value": "[(1,0)-(7,0)]"
44794
+ "sourcemaps:value": "[(1,0)-(6,0)]"
44795
44795
  },
44796
44796
  {
44797
44797
  "@id": "#338/source-map/synthesized-field/element_1",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.11.2",
4
+ "version": "0.11.3",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -388,6 +388,8 @@ export class DataAssociation {
388
388
 
389
389
  /**
390
390
  * @param init The key of an entity, its instance, or schema.
391
+ * @param namespace - The key of the foreign namespace this entity belongs to.
392
+ * Do not set this value for local entities.
391
393
  */
392
394
  addTarget(init: string | DataEntity | IDataEntity, namespace?: string): void {
393
395
  let key: string
@@ -415,21 +417,6 @@ export class DataAssociation {
415
417
  this.targets.push(info)
416
418
  }
417
419
 
418
- /**
419
- * Removes a target entity from the association.
420
- *
421
- * @param entity - The `DataEntity` or `IDataEntity` instance to remove.
422
- */
423
- removeTarget(entity: DataEntity | IDataEntity): void
424
-
425
- /**
426
- * Removes a target entity from the association.
427
- *
428
- * @param key - The key of the target entity to remove.
429
- */
430
- // eslint-disable-next-line @typescript-eslint/unified-signatures
431
- removeTarget(key: string): void
432
-
433
420
  /**
434
421
  * Removes a target entity from the targets list.
435
422
  *
@@ -44,7 +44,7 @@ interface DataDefinitions {
44
44
 
45
45
  /**
46
46
  * Data definition for a foreign namespace.
47
- * Each foreigh namespace is resolved to a specific version.
47
+ * Each foreign namespace is resolved to a specific version.
48
48
  * This makes sure that the local data are always referencing an existing
49
49
  * entity as breaking changes should be resolved when upgrading a version.
50
50
  */
@@ -435,6 +435,14 @@ export class DataNamespace extends DataNamespaceParent {
435
435
  return result
436
436
  }
437
437
 
438
+ /**
439
+ * Checks if this is the root namespace.
440
+ * @returns True if this is the root namespace.
441
+ */
442
+ isRoot(): boolean {
443
+ return this.root === undefined
444
+ }
445
+
438
446
  /**
439
447
  * Finds a parent namespace for the given namespace.
440
448
  * @param key The namespace key to find the parent for.
@@ -715,6 +723,29 @@ export class DataNamespace extends DataNamespaceParent {
715
723
  return result
716
724
  }
717
725
 
726
+ /**
727
+ * Finds an associated entity in the current or foreign namespace.
728
+ * This is a helper function to discover entities in the current and foreign namespaces.
729
+ *
730
+ * @param key The key of the entity to find.
731
+ * @param namespace The optional namespace to search in.
732
+ * If not set, the current namespace is used.
733
+ * This is used to find entities in foreign namespaces.
734
+ * @returns The entity or undefined if not found.
735
+ */
736
+ findAssociatedEntity(key: string, namespace?: string): DataEntity | undefined {
737
+ let ns: DataNamespace | undefined
738
+ if (namespace) {
739
+ ns = this.foreign.find((i) => i.key === namespace)
740
+ } else {
741
+ ns = this
742
+ }
743
+ if (!ns) {
744
+ return undefined
745
+ }
746
+ return ns.findEntity(key)
747
+ }
748
+
718
749
  addForeign(ns: DataNamespace): void {
719
750
  const exists = this.foreign.some((i) => i.key === ns.key)
720
751
  if (exists) {
@@ -0,0 +1,134 @@
1
+ # Data Modeling
2
+
3
+ ## Core Concepts
4
+
5
+ At the heart of this data modeling system are the following fundamental concepts.
6
+
7
+ ### DataNamespace
8
+
9
+ This is the top-level container, representing a logical grouping of data. Think of it as a "domain" or a "schema" in a database. It can contain:
10
+
11
+ - `DataModels`: Logical groupings of entities.
12
+ - `DataEntities`: The basic building blocks, representing individual data structures.
13
+ - `DataProperties`: Attributes of entities (e.g., name, age, address).
14
+ - `DataAssociations`: Relationships between entities (e.g., a user has an address).
15
+ - `Sub-namespaces`: Namespaces can be nested within each other, creating a hierarchical structure.
16
+ - `Foreign Namespaces`: References to external namespaces, enabling the use of entities defined elsewhere.
17
+ - `Tags`: Common tags for the entire namespace.
18
+
19
+ ### DataModel
20
+
21
+ A logical grouping of `DataEntity` instances. It represents a specific data structure, like a "Product" or "User" model. A `DataModel` can contain multiple `DataEntity` instances.
22
+
23
+ ### DataEntity
24
+
25
+ The fundamental building block of the data model. It represents a specific type of data, like a "User," "Product," or "Address."
26
+
27
+ - `Properties`: DataProperty instances that describe the attributes of the entity.
28
+ - `Associations`: DataAssociation instances that define relationships to other entities.
29
+ - `Parents`: An entity can inherit from other entities, creating a hierarchy.
30
+ - `Fields`: Ordered list of properties and associations.
31
+ - `Tags`: Optional tags for the UI.
32
+ - `Taxonomy`: Reserved for future use.
33
+ - `Deprecated`: Whether the entity is deprecated.
34
+ - `Schema`: The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)
35
+
36
+ ### DataProperty
37
+
38
+ Represents an attribute of a `DataEntity`. It has a name, a data type (e.g., string, number, boolean), and optional constraints (e.g., required, multiple, min/max values).
39
+
40
+ - `Type`: The data type of the property.
41
+ - `Schema`: The general schema definition of this property.
42
+ - `Bindings`: The list of bindings for this property.
43
+ - `Tags`: Optional tags for the UI.
44
+ - `Taxonomy`: Reserved for future use.
45
+ - `Deprecated`: Whether the property is deprecated.
46
+ - `Primary`: Whether this property describes a primary key of the entity.
47
+ - `Index`: Whether this property describes an indexed property of the entity.
48
+ - `ReadOnly`: Whether the property is read only in the schema.
49
+ - `WriteOnly`: Whether the property is write only in the schema.
50
+
51
+ ### DataAssociation
52
+
53
+ Defines a relationship between `DataEntity` instances. It specifies the target entities and the nature of the relationship (e.g., one-to-one, one-to-many).
54
+
55
+ - `Targets`: The list of target entities.
56
+ - `Multiple`: Whether the association allows multiple target entities.
57
+ - `Required`: Whether the association is required.
58
+ - `Schema`: The definition of the database/API schema
59
+ - `Bindings`: The list of bindings allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)
60
+ - `Hidden`: Defines if this association is a part of the schema or not.
61
+
62
+ ### Bindings
63
+
64
+ Defines a translation from a data model to a specific format (like JSON, RAML, XML, etc.)
65
+
66
+ ## How a Data Domain is Structured
67
+
68
+ Here's how these components work together to structure a data domain:
69
+
70
+ 1. **Root Namespace**: You start with a `DataNamespace`, which acts as the root of your data domain. This namespace is the top-level container for all other elements.
71
+
72
+ 1. **Sub-namespaces (Optional)**: You can create sub-namespaces within the root namespace to further organize your data. This is useful for large domains with many entities and relationships.
73
+
74
+ 1. **Data Models**: Within a namespace (or sub-namespace), you define `DataModel` instances. Each `DataModel` represents a specific area of your domain. For example, you might have a "User Management" `DataModel`, a "Product Catalog" `DataModel`, and an "Order Processing" `DataModel`.
75
+
76
+ 1. **Data Entities**: Inside each `DataModel`, you define `DataEntity` instances. These are the core data structures. For example, in the "User Management" `DataModel`, you might have `DataEntity` instances for "User," "Role," and "Permission."
77
+
78
+ 1. **Data Properties**: Each `DataEntity` has `DataProperty` instances that describe its attributes. For example, the "User" `DataEntity` might have `DataProperty` instances for "firstName" (string), "lastName" (string), "email" (string), "age" (number), etc.
79
+
80
+ 1. **Data Associations**: You use `DataAssociation` instances to define relationships between `DataEntity` instances. For example:
81
+
82
+ - A "User" has an "Address" (one-to-one).
83
+ - A "User" has multiple "Roles" (one-to-many).
84
+ - A "Product" belongs to a "Category" (many-to-one).
85
+ - An "Order" contains multiple "Order Items" (one-to-many).
86
+
87
+ 1. **Inheritance**: `DataEntity` instances can inherit from other `DataEntity` instances using the parents property. This allows you to create a hierarchy of entities and reuse common properties and associations.
88
+
89
+ 1. **Foreign Namespaces**: You can reference entities from other namespaces using the foreign property of the root namespace. This allows you to reuse data structures defined elsewhere.
90
+
91
+ 1. **Bindings**: You can define bindings for properties and associations to translate the data model into specific formats (e.g., JSON, RAML, XML, Protocol Buffers).
92
+
93
+ ## Example Scenario
94
+
95
+ Let's imagine a simple e-commerce domain:
96
+
97
+ - **Root Namespace**: `ECommerce`
98
+ - **Sub-namespace**: `Catalog`
99
+ - **Data Model**: `ProductCatalog`
100
+ - **Data Entity**: `Product`
101
+ - **Data Properties**: `name` (string), `description` (string), `price` (number), `sku` (string)
102
+ - **Data Association**: `category` (references `Category` entity)
103
+ - **Data Entity**: `Category`
104
+ - **Data Properties**: `name` (string), `description` (string)
105
+ - **Sub-namespace**: `UserManagement`
106
+ - **Data Model**: `UserManagement`
107
+ - **Data Entity**: `User`
108
+ - **Data Properties**: `firstName` (string), `lastName` (string), `email` (string), `password` (string)
109
+ - **Data Association**: `address` (references `Address` entity)
110
+ - **Data Entity**: `Address`
111
+ - **Data Properties**: `street` (string), `city` (string), `zipCode` (string), `country` (string)
112
+ - **Foreign Namespace**: `Taxonomy` (defined elsewhere)
113
+ - **Data Model**: `Taxonomy`
114
+ - **Data Entity**: `TaxonomyItem`
115
+
116
+ ### Key Relationships
117
+
118
+ - **Namespace-Model**: A `DataNamespace` contains `DataModel` instances.
119
+ - **Model-Entity**: A `DataModel` contains `DataEntity` instances.
120
+ - **Entity-Property**: A `DataEntity` has `DataProperty` instances.
121
+ - **Entity-Association**: A `DataEntity` has `DataAssociation` instances.
122
+ - **Entity-Parent**: A `DataEntity` can have `DataEntity` instances as parents.
123
+ - **Namespace-Foreign**: A `DataNamespace` can have references to `DataNamespace` instances.
124
+
125
+ ## Summary
126
+
127
+ This data modeling system provides a flexible and powerful way to define complex data domains. It allows you to:
128
+
129
+ - **Organize**: Group related data into namespaces and models.
130
+ - **Structure**: Define entities with properties and relationships.
131
+ - **Reuse**: Inherit from other entities and reference foreign namespaces.
132
+ - **Translate**: Define bindings to map the model to different formats.
133
+ - **Validate**: Validate the data model definition.
134
+ - **Generate**: Generate AMF shapes and examples.
@@ -821,3 +821,248 @@ test.group('computeForeignNamespaceKeys()', () => {
821
821
  assert.deepEqual(result, [n2.key])
822
822
  })
823
823
  })
824
+
825
+ test.group('findAssociatedEntity()', (group) => {
826
+ let root: DataNamespace
827
+ let foreign: DataNamespace
828
+ let e1: DataEntity
829
+ let e2: DataEntity
830
+
831
+ group.each.setup(() => {
832
+ root = new DataNamespace()
833
+ foreign = new DataNamespace()
834
+ root.addForeign(foreign)
835
+ const model1 = root.addDataModel('m1')
836
+ const model2 = foreign.addDataModel('m2')
837
+ e1 = model1.addEntity('e1')
838
+ e2 = model2.addEntity('e2')
839
+ })
840
+
841
+ test('finds an entity in the current namespace', ({ assert }) => {
842
+ const result = root.findAssociatedEntity(e1.key)
843
+ assert.deepEqual(result, e1)
844
+ })
845
+
846
+ test('finds an entity in a foreign namespace', ({ assert }) => {
847
+ const result = root.findAssociatedEntity(e2.key, foreign.key)
848
+ assert.deepEqual(result, e2)
849
+ })
850
+
851
+ test('returns undefined when the entity is not found in the current namespace', ({ assert }) => {
852
+ const result = root.findAssociatedEntity('non-existent-key')
853
+ assert.isUndefined(result)
854
+ })
855
+
856
+ test('returns undefined when the entity is not found in a foreign namespace', ({ assert }) => {
857
+ const result = root.findAssociatedEntity('non-existent-key', foreign.key)
858
+ assert.isUndefined(result)
859
+ })
860
+
861
+ test('returns undefined when the foreign namespace does not exist', ({ assert }) => {
862
+ const result = root.findAssociatedEntity(e2.key, 'non-existent-namespace')
863
+ assert.isUndefined(result)
864
+ })
865
+
866
+ test('returns undefined when no namespace is provided and the entity is in a foreign namespace', ({ assert }) => {
867
+ const result = root.findAssociatedEntity(e2.key)
868
+ assert.isUndefined(result)
869
+ })
870
+ })
871
+
872
+ test.group('addForeign()', (group) => {
873
+ let root: DataNamespace
874
+ let foreign: DataNamespace
875
+
876
+ group.each.setup(() => {
877
+ root = new DataNamespace()
878
+ foreign = new DataNamespace()
879
+ })
880
+
881
+ test('adds a foreign namespace', ({ assert }) => {
882
+ root.addForeign(foreign)
883
+ assert.deepEqual(root.foreign, [foreign])
884
+ })
885
+
886
+ test('does not add the same foreign namespace twice', ({ assert }) => {
887
+ root.addForeign(foreign)
888
+ root.addForeign(foreign)
889
+ assert.deepEqual(root.foreign, [foreign])
890
+ })
891
+ })
892
+
893
+ test.group('removeForeign()', (group) => {
894
+ let root: DataNamespace
895
+ let foreign: DataNamespace
896
+ let foreign2: DataNamespace
897
+
898
+ group.each.setup(() => {
899
+ root = new DataNamespace()
900
+ foreign = new DataNamespace()
901
+ foreign2 = new DataNamespace()
902
+ root.addForeign(foreign)
903
+ root.addForeign(foreign2)
904
+ })
905
+
906
+ test('removes a foreign namespace', ({ assert }) => {
907
+ root.removeForeign(foreign)
908
+ assert.deepEqual(root.foreign, [foreign2])
909
+ })
910
+
911
+ test('does nothing when the foreign namespace does not exist', ({ assert }) => {
912
+ const other = new DataNamespace()
913
+ root.removeForeign(other)
914
+ assert.deepEqual(root.foreign, [foreign, foreign2])
915
+ })
916
+ })
917
+
918
+ test.group('hasForeignNamespace()', (group) => {
919
+ let root: DataNamespace
920
+ let foreign: DataNamespace
921
+
922
+ group.each.setup(() => {
923
+ root = new DataNamespace()
924
+ foreign = new DataNamespace()
925
+ root.addForeign(foreign)
926
+ })
927
+
928
+ test('returns true when the foreign namespace exists', ({ assert }) => {
929
+ const result = root.hasForeignNamespace(foreign.key)
930
+ assert.isTrue(result)
931
+ })
932
+
933
+ test('returns false when the foreign namespace does not exist', ({ assert }) => {
934
+ const result = root.hasForeignNamespace('non-existent-key')
935
+ assert.isFalse(result)
936
+ })
937
+ })
938
+
939
+ test.group('listNamespaces()', (group) => {
940
+ let root: DataNamespace
941
+ let n1: DataNamespace
942
+ let n2: DataNamespace
943
+ let m1: DataModel
944
+
945
+ group.each.setup(() => {
946
+ root = new DataNamespace()
947
+ n1 = root.addNamespace('n1')
948
+ n2 = root.addNamespace('n2')
949
+ m1 = root.addDataModel('m1')
950
+ })
951
+
952
+ test('lists all namespaces', ({ assert }) => {
953
+ const result = root.listNamespaces()
954
+ assert.deepEqual(result, [n1, n2])
955
+ })
956
+
957
+ test('lists namespaces in a sub-namespace', ({ assert }) => {
958
+ const n3 = n1.addNamespace('n3')
959
+ const result = n1.listNamespaces()
960
+ assert.deepEqual(result, [n3])
961
+ })
962
+
963
+ test('does not list data models', ({ assert }) => {
964
+ const result = root.listNamespaces()
965
+ assert.notDeepInclude(result, m1)
966
+ })
967
+ })
968
+
969
+ test.group('listDataModels()', (group) => {
970
+ let root: DataNamespace
971
+ let n1: DataNamespace
972
+ let m1: DataModel
973
+ let m2: DataModel
974
+ let e1: DataEntity
975
+
976
+ group.each.setup(() => {
977
+ root = new DataNamespace()
978
+ n1 = root.addNamespace('n1')
979
+ m1 = root.addDataModel('m1')
980
+ m2 = n1.addDataModel('m2')
981
+ e1 = m2.addEntity('e1')
982
+ })
983
+
984
+ test('lists all data models', ({ assert }) => {
985
+ const result = root.listDataModels()
986
+ assert.deepEqual(result, [m1])
987
+ })
988
+
989
+ test('lists data models in a sub-namespace', ({ assert }) => {
990
+ const m3 = n1.addDataModel('m3')
991
+ const result = n1.listDataModels()
992
+ assert.deepEqual(result, [m2, m3])
993
+ })
994
+
995
+ test('does not list entities', ({ assert }) => {
996
+ const result = root.listDataModels()
997
+ assert.notDeepInclude(result, e1)
998
+ })
999
+ })
1000
+
1001
+ test.group('getRoot()', (group) => {
1002
+ let root: DataNamespace
1003
+ let n1: DataNamespace
1004
+ let n2: DataNamespace
1005
+
1006
+ group.each.setup(() => {
1007
+ root = new DataNamespace()
1008
+ n1 = root.addNamespace('n1')
1009
+ n2 = n1.addNamespace('n2')
1010
+ })
1011
+
1012
+ test('returns self when called on the root namespace', ({ assert }) => {
1013
+ const result = root.getRoot()
1014
+ assert.deepEqual(result, root)
1015
+ })
1016
+
1017
+ test('returns the root namespace when called on a sub-namespace', ({ assert }) => {
1018
+ const result = n1.getRoot()
1019
+ assert.deepEqual(result, root)
1020
+ })
1021
+
1022
+ test('returns the root namespace when called on a sub-sub-namespace', ({ assert }) => {
1023
+ const result = n2.getRoot()
1024
+ assert.deepEqual(result, root)
1025
+ })
1026
+ })
1027
+
1028
+ test.group('getParent()', (group) => {
1029
+ let root: DataNamespace
1030
+ let n1: DataNamespace
1031
+ let n2: DataNamespace
1032
+
1033
+ group.each.setup(() => {
1034
+ root = new DataNamespace()
1035
+ n1 = root.addNamespace('n1')
1036
+ n2 = n1.addNamespace('n2')
1037
+ })
1038
+
1039
+ test('returns undefined when called on the root namespace', ({ assert }) => {
1040
+ const result = root.getParent()
1041
+ assert.isUndefined(result)
1042
+ })
1043
+
1044
+ test('returns the parent namespace when called on a sub-namespace', ({ assert }) => {
1045
+ const result = n2.getParent()
1046
+ assert.deepEqual(result, n1)
1047
+ })
1048
+ })
1049
+
1050
+ test.group('isRoot()', (group) => {
1051
+ let root: DataNamespace
1052
+ let n1: DataNamespace
1053
+
1054
+ group.each.setup(() => {
1055
+ root = new DataNamespace()
1056
+ n1 = root.addNamespace('n1')
1057
+ })
1058
+
1059
+ test('returns true when called on the root namespace', ({ assert }) => {
1060
+ const result = root.isRoot()
1061
+ assert.isTrue(result)
1062
+ })
1063
+
1064
+ test('returns false when called on a sub-namespace', ({ assert }) => {
1065
+ const result = n1.isRoot()
1066
+ assert.isFalse(result)
1067
+ })
1068
+ })