@api-client/core 0.14.2 → 0.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/browser.d.ts +1 -1
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +1 -0
- package/build/src/browser.js.map +1 -1
- package/build/src/events/BaseEvents.d.ts +4 -0
- package/build/src/events/BaseEvents.d.ts.map +1 -1
- package/build/src/events/BaseEvents.js.map +1 -1
- package/build/src/index.d.ts +2 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +2 -0
- package/build/src/index.js.map +1 -1
- package/build/src/modeling/ApiFile.d.ts +23 -0
- package/build/src/modeling/ApiFile.d.ts.map +1 -0
- package/build/src/modeling/ApiFile.js +44 -0
- package/build/src/modeling/ApiFile.js.map +1 -0
- package/build/src/modeling/ApiModel.d.ts +159 -0
- package/build/src/modeling/ApiModel.d.ts.map +1 -0
- package/build/src/modeling/ApiModel.js +237 -0
- package/build/src/modeling/ApiModel.js.map +1 -0
- package/build/src/modeling/DataDomain.d.ts +1 -1
- package/build/src/modeling/DataDomain.d.ts.map +1 -1
- package/build/src/modeling/DataDomain.js +1 -3
- package/build/src/modeling/DataDomain.js.map +1 -1
- package/build/src/modeling/DomainEntity.js +1 -1
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/DomainFile.d.ts +1 -2
- package/build/src/modeling/DomainFile.d.ts.map +1 -1
- package/build/src/modeling/DomainFile.js +3 -41
- package/build/src/modeling/DomainFile.js.map +1 -1
- package/build/src/modeling/Semantics.d.ts +55 -8
- package/build/src/modeling/Semantics.d.ts.map +1 -1
- package/build/src/modeling/Semantics.js +62 -8
- package/build/src/modeling/Semantics.js.map +1 -1
- package/build/src/modeling/amf/ShapeGenerator.d.ts.map +1 -1
- package/build/src/modeling/amf/ShapeGenerator.js.map +1 -1
- package/build/src/modeling/types.d.ts +491 -0
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/src/models/kinds.d.ts +3 -0
- package/build/src/models/kinds.d.ts.map +1 -1
- package/build/src/models/kinds.js +3 -0
- package/build/src/models/kinds.js.map +1 -1
- package/build/src/models/store/File.d.ts +19 -2
- package/build/src/models/store/File.d.ts.map +1 -1
- package/build/src/models/store/File.js +100 -13
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/Group.d.ts +76 -2
- package/build/src/models/store/Group.d.ts.map +1 -1
- package/build/src/models/store/Group.js +84 -1
- package/build/src/models/store/Group.js.map +1 -1
- package/build/src/sdk/GroupsSdk.d.ts +41 -0
- package/build/src/sdk/GroupsSdk.d.ts.map +1 -0
- package/build/src/sdk/GroupsSdk.js +135 -0
- package/build/src/sdk/GroupsSdk.js.map +1 -0
- package/build/src/sdk/RouteBuilder.d.ts +2 -0
- package/build/src/sdk/RouteBuilder.d.ts.map +1 -1
- package/build/src/sdk/RouteBuilder.js +6 -0
- package/build/src/sdk/RouteBuilder.js.map +1 -1
- package/build/src/sdk/Sdk.d.ts +2 -0
- package/build/src/sdk/Sdk.d.ts.map +1 -1
- package/build/src/sdk/Sdk.js +5 -0
- package/build/src/sdk/Sdk.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/src/events/BaseEvents.ts +4 -0
- package/src/modeling/ApiFile.ts +53 -0
- package/src/modeling/ApiModel.ts +327 -0
- package/src/modeling/DataDomain.ts +1 -1
- package/src/modeling/DomainEntity.ts +1 -1
- package/src/modeling/DomainFile.ts +3 -40
- package/src/modeling/Semantics.ts +63 -8
- package/src/modeling/amf/ShapeGenerator.ts +1 -1
- package/src/modeling/types.ts +545 -0
- package/src/models/kinds.ts +3 -0
- package/src/models/store/File.ts +100 -13
- package/src/models/store/Group.ts +148 -2
- package/src/sdk/GroupsSdk.ts +150 -0
- package/src/sdk/RouteBuilder.ts +8 -0
- package/src/sdk/Sdk.ts +6 -0
- package/tests/unit/modeling/api_model.spec.ts +291 -0
- package/tests/unit/modeling/domain_entity.spec.ts +15 -15
- package/tests/unit/modeling/domain_file.spec.ts +1 -11
- package/tests/unit/modeling/domain_model_entities.spec.ts +2 -2
- package/tests/unit/modeling/semantics.spec.ts +8 -11
- package/tests/unit/models/File/constructor.spec.ts +3 -2
- package/tests/unit/models/File/shortcutTo.spec.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataDomain.js","sourceRoot":"","sources":["../../../src/modeling/DataDomain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,oBAAoB,CAAA;AAQ3B,OAAO,EAA8B,eAAe,EAA6B,MAAM,sBAAsB,CAAA;AAC7G,OAAO,EAA0B,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAItE,OAAO,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAgBjG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,MAAM,OAAO,UAAW,SAAQ,WAAW;IACzC;;OAEG;IACH,IAAI,CAAuB;IAC3B;;OAEG;IACH,GAAG,CAAQ;IAEX;;OAEG;IACH,KAAK,CAAsD;IAE3D;;;;OAIG;IACH,YAAY,GAA4B,IAAI,GAAG,EAAsB,CAAA;IAErE;;OAEG;IACH,cAAc,GAA8B,EAAE,CAAA;IAK9C,uBAAoB;IAHpB;;OAEG;IACH,IAAS,IAAI,0CAAO;IAApB,IAAS,IAAI,gDAAO;IAEpB;;;OAGG;IACH,aAAa,GAAG,IAAI,CAAA;IAEp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QAClB,CAAC;QACD,MAAM,UAAU,GAAG,GAAG,SAAS,IAAI,SAAS,EAAE,CAAA;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACxC,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAC3C,OAAO,IAAoB,CAAA;QAC7B,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,mBAAmB,CAAC,GAAW,EAAE,IAAY;QAC3C,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,mBAAmB;gBACtB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;gBACzB,MAAK;YACP,KAAK,eAAe;gBAClB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;gBACrB,MAAK;YACP,KAAK,gBAAgB;gBACnB,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;gBACtB,MAAK;YACP,KAAK,kBAAkB;gBACrB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;gBACxB,MAAK;YACP,KAAK,qBAAqB;gBACxB,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAA;gBAC3B,MAAK;YACP;gBACE,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,mBAAmB,GAAG,EAAE,CAAC,CAAA;QACjE,CAAC;IACH,CAAC;CACF","sourcesContent":["import { nanoid } from '../nanoid.js'\nimport { Graph } from '@api-client/graph/graph/Graph.js'\nimport {\n DomainAssociationKind,\n DataDomainKind,\n DomainEntityKind,\n DomainModelKind,\n DomainNamespaceKind,\n DomainPropertyKind,\n} from '../models/kinds.js'\nimport type {\n AssociationAddOptions,\n DomainGraphEdge,\n DomainGraphNodeType,\n ForeignDomainDependency,\n SerializedGraph,\n} from './types.js'\nimport { type DomainNamespaceSchema, DomainNamespace, type NamespaceOrderedItem } from './DomainNamespace.js'\nimport { type DomainModelSchema, DomainModel } from './DomainModel.js'\nimport { type DomainEntitySchema, DomainEntity } from './DomainEntity.js'\nimport { DomainAssociation } from './DomainAssociation.js'\nimport { DomainProperty, DomainPropertySchema } from './DomainProperty.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { removeGraphNode } from './GraphUtils.js'\nimport { serialize, deserialize, mergeGraph, removeForeignGraph } from './DomainSerialization.js'\n\nexport interface DataDomainSchema {\n info: IThing\n kind: typeof DataDomainKind\n key: string\n graph?: SerializedGraph\n dependencyList?: ForeignDomainDependency[]\n /**\n * The ordered list of fields (namespace and models) in the schema.\n * These only keep references to define the order of these properties\n * in the schema as graph won't do it.\n */\n fields?: NamespaceOrderedItem[]\n}\n\n/**\n * Represents the root of a data domain model.\n *\n * The `DataDomain` class serves as the top-level container\n * for a collection of data models, namespaces, entities,\n * properties, and associations. It provides methods for\n * managing and manipulating these data elements, enabling\n * the creation of complex and interconnected data\n * structures.\n *\n * **Key Features:**\n *\n * - **Root Container:** Holds all data elements within a domain.\n * - **Graph-Based Structure:** Uses a graph to represent relationships between data elements.\n * - **Namespace Management:** Supports creating and managing namespaces to organize data models.\n * - **Data Model Management:** Supports creating and managing data models to group entities.\n * - **Entity Management:** Supports creating and managing entities, which define the structure of data.\n * - **Property Management:** Supports creating and managing properties, which define the data elements\n * within entities.\n * - **Association Management:** Supports creating and managing associations, which define relationships\n * between entities.\n * - **Foreign Domain Support:** Allows registering and integrating data from external domains.\n * - **Change Notification:** Notifies listeners when changes occur within the data domain.\n *\n * **Usage:**\n *\n * 1. Create an instance of the `DataDomain`.\n * 2. Use methods like `addNamespace()`, `addModel()`,\n * `addEntity()`, `addProperty()`, and `addAssociation()`\n * to build the data domain structure.\n * 3. Use methods like `findNamespace()`, `findModel()`,\n * `findEntity()`, `findProperty()`, and\n * `findAssociation()` to retrieve data elements.\n * 4. Use methods like `listNamespaces()`, `listGraphNamespaces()`, `listModels()`,\n * and `listEntities()` to iterate over collections of\n * data elements.\n * 5. Use `registerForeignDomain()` to integrate data from\n * external domains.\n * 6. Listen for the `change` event to be notified of\n * changes within the data domain.\n *\n * **Example:**\n *\n * ```typescript\n * const dataDomain = new DataDomain();\n * const userNamespace = dataDomain.addNamespace({\n * key: 'userNamespace',\n * });\n * const userModel = userNamespace.addModel({\n * key: 'userModel',\n * });\n * const userEntity = userModel.addEntity({\n * key: 'user',\n * });\n * const nameProperty = userEntity.addProperty({\n * key: 'name',\n * type: 'string',\n * });\n * ```\n *\n * @fires DataDomain#change {Event} - Fired when the data\n * domain changes.\n *\n * @todo: Implement a mechanism to move an entity to a new\n * parent model.\n */\nexport class DataDomain extends EventTarget {\n /**\n * The kind of the domain element.\n */\n kind: typeof DataDomainKind\n /**\n * The unique key of the domain element.\n */\n key: string\n\n /**\n * The graph used to store the data domain structure.\n */\n graph: Graph<unknown, DomainGraphNodeType, DomainGraphEdge>\n\n /**\n * A map of foreign data domains.\n * Key: The unique identifier of the foreign domain.\n * Value: The foreign DataDomain instance.\n */\n dependencies: Map<string, DataDomain> = new Map<string, DataDomain>()\n\n /**\n * The list of foreign domain dependencies.\n */\n dependencyList: ForeignDomainDependency[] = []\n\n /**\n * The description of the domain property.\n */\n accessor info: Thing\n\n /**\n * When the initializing flag is set to true,\n * the domain is not notified of changes.\n */\n #initializing = true\n\n /**\n * When the notifying flag is set to true,\n * the domain is pending a notification.\n * No other notifications will be sent until\n * the current notification is sent.\n */\n #notifying = false\n\n /**\n * This is to keep it consistent with the domain elements.\n */\n get domain(): DataDomain {\n return this\n }\n\n /**\n * The ordered list of fields (namespace and models) in the schema.\n * These only keep references to define the order of these properties\n * in the schema as graph won't do it.\n */\n accessor fields: NamespaceOrderedItem[]\n\n static createSchema(input: Partial<DataDomainSchema> = {}): DataDomainSchema {\n const { key = nanoid(), fields } = input\n const info = Thing.fromJSON(input.info, { name: 'Unnamed domain' }).toJSON()\n const result: DataDomainSchema = {\n kind: DataDomainKind,\n key,\n info,\n }\n if (input.dependencyList) {\n result.dependencyList = structuredClone(input.dependencyList)\n }\n if (input.graph) {\n result.graph = input.graph\n }\n if (Array.isArray(fields)) {\n result.fields = [...fields]\n }\n return result\n }\n\n /**\n * Creates a new instance of the `DataDomain` class.\n *\n * When creating a new Data Domain arguments should not be set.\n * When restoring a Data Domain from a previous state, you should provide\n * the serialized graph state as well as the same list of dependencies\n * used when the graph was deserialized. Edges to missing dependency nodes\n * will be ignored.\n *\n * @param state The previously serialized state of the graph.\n * @param dependencies An array of foreign data domains to register with this domain.\n */\n constructor(state?: Partial<DataDomainSchema>, dependencies?: DataDomain[]) {\n super()\n const init = DataDomain.createSchema(state)\n this.kind = init.kind\n this.key = init.key\n this.info = new Thing(init.info)\n this.graph = deserialize(this, init.graph, dependencies)\n if (Array.isArray(init.fields)) {\n this.fields = [...init.fields]\n } else {\n this.fields = []\n }\n if (Array.isArray(init.dependencyList)) {\n this.dependencyList = [...init.dependencyList]\n } else {\n this.dependencyList = []\n }\n this.#initializing = false\n this.info.addEventListener('change', () => {\n this.notifyChange()\n })\n }\n\n /**\n * Serializes the DataDomain instance to a JSON object.\n * It does not serialize the foreign domain dependencies. The serialized nodes\n * are the ones that are local to this data domain.\n * @returns The serialized data domain ready for storage or transport.\n */\n toJSON(): DataDomainSchema {\n const result: DataDomainSchema = {\n info: this.info.toJSON(),\n kind: this.kind,\n key: this.key,\n graph: serialize(this.graph, this.key),\n }\n if (this.dependencyList.length > 0) {\n result.dependencyList = structuredClone(this.dependencyList)\n }\n if (Array.isArray(this.fields) && this.fields.length) {\n result.fields = [...this.fields]\n }\n return result\n }\n\n /**\n * This function is used internally by all domain elements to notify that something has changed.\n * Since we want to notify listeners after the operation commits, we use microtask\n * to ensure that the event is dispatched after the current operation.\n */\n notifyChange() {\n if (this.#notifying || this.#initializing) {\n return\n }\n this.#notifying = true\n queueMicrotask(() => {\n this.#notifying = false\n const event = new Event('change')\n this.dispatchEvent(event)\n })\n }\n\n private removeField(key: string): void {\n this.fields = this.fields.filter((item) => item.key !== key)\n }\n\n /**\n * Checks if this data domain has any fields (namespace and models).\n *\n * @returns True if the data domain has fields.\n * @example\n * ```typescript\n * if (domain.hasFields()) {\n * // ...\n * }\n * ```\n */\n hasFields(): boolean {\n return this.fields.length > 0\n }\n\n /**\n * Lists all fields (namespace and models) of this namespace.\n *\n * @returns A generator that yields each `DomainAssociation` or `DomainProperty`.\n * @example\n * ```typescript\n * for (const field of namespace.listFields()) {\n * console.log(field.key);\n * }\n * ```\n */\n *listFields(): Generator<DomainNamespace | DomainModel> {\n for (const { key } of this.fields) {\n const node = this.graph.node(key)\n if (!node) {\n continue\n }\n if (node.kind === DomainNamespaceKind || node.kind === DomainModelKind) {\n yield node\n }\n }\n }\n\n /**\n * Adds a new data domain instance to the graph.\n *\n * @param value The partial namespace schema. All missing\n * values will be filled with default values.\n * @param parent The parent namespace key. If not provided,\n * the new namespace will be added to the root of the\n * graph.\n * @returns The created namespace instance.\n * @throws Error When the parent does not exist or is not\n * a namespace.\n * @example\n * ```typescript\n * const newNamespace = dataDomain.addNamespace({\n * key: 'newNamespace',\n * });\n * ```\n */\n addNamespace(value?: Partial<DomainNamespaceSchema>, parent?: string): DomainNamespace {\n if (parent) {\n if (!this.graph.hasNode(parent)) {\n throw new Error(`Parent namespace ${parent} does not exist`)\n }\n const instance = this.graph.node(parent) as DomainNamespace\n if (!instance || instance.kind !== DomainNamespaceKind) {\n throw new Error(`Parent namespace ${parent} is not a valid namespace`)\n }\n if (instance.domain.key !== this.key) {\n throw new Error(`Cannot add a namespace to a foreign domain`)\n }\n return instance.addNamespace(value)\n }\n const item = new DomainNamespace(this, value)\n this.graph.setNode(item.key, item)\n this.fields.push({\n type: 'namespace',\n key: item.key,\n })\n this.notifyChange()\n return item\n }\n\n /**\n * Removes a namespace from the graph.\n *\n * @param key The key of the namespace to remove.\n * @returns The current DataDomain instance.\n * @throws Error When the namespace does not exist.\n * @example\n * ```typescript\n * dataDomain.removeNamespace('userNamespace');\n * ```\n */\n removeNamespace(key: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Namespace ${key} does not exist`)\n }\n const ns = this.graph.node(key) as DomainNamespace\n if (!ns || ns.kind !== DomainNamespaceKind) {\n throw new Error(`Namespace ${key} not found`)\n }\n if (ns.domain.key !== this.key) {\n throw new Error(`Cannot remove a namespace from a foreign domain`)\n }\n const parent = ns.getParentInstance()\n if (parent === this) {\n removeGraphNode(this.graph, key)\n this.removeField(key)\n this.notifyChange()\n } else {\n parent.removeNamespace(key)\n }\n return this\n }\n\n /**\n * Lists all namespaces of this data domain that are direct children of it.\n *\n * Note, it accounts for the order of the namespaces as defined in the `fields` array.\n *\n * @returns A generator that yields each `DomainNamespace`.\n * @example\n * ```typescript\n * for (const ns of domain.listNamespaces()) {\n * console.log(ns.key);\n * }\n * ```\n */\n *listNamespaces(): Generator<DomainNamespace> {\n for (const { key, type } of this.fields) {\n if (type !== 'namespace') {\n continue\n }\n const node = this.graph.node(key)\n if (!node || node.kind !== DomainNamespaceKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this data domain has any namespaces.\n *\n * @returns True if the data domain has namespaces.\n * @example\n * ```typescript\n * if (domain.hasNamespaces()) {\n * // ...\n * }\n * ```\n */\n hasNamespaces(): boolean {\n return this.fields.some((item) => item.type === 'namespace')\n }\n\n /**\n * Lists all namespaces in the graph.\n *\n * @param parent The key of the parent namespace. If not\n * provided, all root namespaces will be listed.\n * @returns A generator that yields each `DomainNamespace`.\n * @example\n * ```typescript\n * for (const ns of dataDomain.listGraphNamespaces()) {\n * console.log(ns.key);\n * }\n * ```\n */\n *listGraphNamespaces(parent?: string): Generator<DomainNamespace> {\n for (const node of this.graph.children(parent)) {\n const value = this.graph.node(node) as DomainGraphNodeType\n if (value.kind === DomainNamespaceKind && value.domain.key === this.key) {\n yield value\n }\n }\n }\n\n /**\n * Finds a namespace by its key.\n *\n * @param key The key of the namespace to find.\n * @returns The namespace instance or undefined if not\n * found.\n * @example\n * ```typescript\n * const ns = dataDomain.findNamespace('userNamespace');\n * if (ns) {\n * console.log(ns.key);\n * }\n * ```\n */\n findNamespace(key: string): DomainNamespace | undefined {\n const result = this.graph.node(key) as DomainNamespace | undefined\n if (result && result.kind === DomainNamespaceKind) {\n return result\n }\n }\n\n /**\n * Moves a namespace to a new parent.\n *\n * @param key The key of the namespace to move.\n * @param parent The new parent namespace key. If\n * undefined, the namespace will be moved to the root.\n * @returns The current DataDomain instance.\n * @throws Error When the namespace or parent does not\n * exist, or when a namespace is moved to itself or\n * its own child.\n * @example\n * ```typescript\n * dataDomain.moveNamespace('userNamespace', 'root');\n * ```\n */\n moveNamespace(key: string, parent?: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Namespace ${key} does not exist`)\n }\n\n const namespace = this.findNamespace(key)\n if (!namespace) {\n throw new Error(`Namespace ${key} not found in the graph`)\n }\n\n if (parent) {\n const instance = this.findNamespace(parent)\n if (instance && instance.domain.key !== this.key) {\n throw new Error(`Cannot move a namespace to a foreign domain`)\n }\n if (!instance) {\n throw new Error(`Parent namespace ${parent} does not exist`)\n }\n }\n\n if (key === parent) {\n throw new Error(`Cannot move a namespace to itself`)\n }\n\n if (namespace.domain.key !== this.key) {\n throw new Error(`Cannot move a namespace from a foreign domain`)\n }\n let parentNamespace: DomainNamespace | undefined\n if (parent) {\n parentNamespace = this.findNamespace(parent)\n if (!parentNamespace) {\n throw new Error(`Parent namespace ${parent} not found`)\n }\n if (this.isChildOf(parent, key)) {\n throw new Error(`Cannot move a namespace to its own child`)\n }\n }\n\n // namespaces can only have one parent\n const currentParentKey = this.graph.parent(key)\n if (currentParentKey && !parent) {\n // The new parent namespace will detach the namespace when attaching to self.\n const currentParent = this.graph.node(currentParentKey) as DomainNamespace\n currentParent.detachNamespace(key)\n } else if (!currentParentKey) {\n // The namespace is a root namespace.\n this.removeField(key)\n }\n // Add to new parent\n if (parent && parentNamespace) {\n parentNamespace.attachNamespace(key)\n } else {\n // The namespace is a root namespace.\n this.fields.push({\n type: 'namespace',\n key,\n })\n }\n this.notifyChange()\n return this\n }\n\n /**\n * Checks if a namespace is a child of another namespace.\n * @param parentKey The key of the parent namespace.\n * @param childKey The key of the child namespace.\n * @returns True if the namespace is a child of another namespace.\n */\n private isChildOf(parentKey: string, childKey: string): boolean {\n const children = this.graph.children(childKey)\n for (const child of children) {\n if (child === parentKey) {\n return true\n }\n if (this.isChildOf(parentKey, child)) {\n return true\n }\n }\n return false\n }\n\n /**\n * Adds a data model to the graph.\n *\n * @param input The partial data model schema.\n * @param parent The parent namespace key. If not\n * provided, the new data model will be added to the\n * root of the graph.\n * @returns The created data model instance.\n * @throws Error When the parent does not exist or is not\n * a namespace.\n * @example\n * ```typescript\n * const newModel = dataDomain.addModel({\n * key: 'newModel',\n * });\n * ```\n */\n addModel(input?: Partial<DomainModelSchema>, parent?: string): DomainModel {\n if (parent) {\n if (!this.graph.hasNode(parent)) {\n throw new Error(`Parent ${parent} does not exist`)\n }\n const instance = this.findNamespace(parent)\n if (!instance) {\n throw new Error(`Parent namespace ${parent} is not a valid namespace`)\n }\n if (instance.domain.key !== this.key) {\n throw new Error(`Cannot add a model to a foreign domain`)\n }\n return instance.addModel(input)\n }\n const item = new DomainModel(this, input)\n this.graph.setNode(item.key, item)\n this.fields.push({\n type: 'model',\n key: item.key,\n })\n return item\n }\n\n /**\n * Removes a data model from the graph.\n *\n * @param key The key of the data model to remove.\n * @returns The current DataDomain instance.\n * @throws Error When the data model does not exist.\n * @example\n * ```typescript\n * dataDomain.removeModel('userModel');\n * ```\n */\n removeModel(key: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Data model ${key} does not exist`)\n }\n const model = this.graph.node(key) as DomainModel\n if (!model || model.kind !== DomainModelKind) {\n throw new Error(`Data model ${key} not found`)\n }\n if (model.domain.key !== this.key) {\n throw new Error(`Cannot remove a model from a foreign domain`)\n }\n const parent = model.getParentInstance()\n if (parent === this) {\n removeGraphNode(this.graph, key)\n this.removeField(key)\n this.notifyChange()\n } else {\n parent.removeModel(key)\n }\n return this\n }\n\n /**\n * Lists all models of this data domain that are direct children of it.\n *\n * Note, it accounts for the order of the models as\n * defined in the `fields` array.\n *\n * @returns A generator that yields each `DomainModel`.\n * @example\n * ```typescript\n * for (const ns of namespace.listModels()) {\n * console.log(ns.key);\n * }\n * ```\n */\n *listModels(): Generator<DomainModel> {\n for (const { key, type } of this.fields) {\n if (type !== 'model') {\n continue\n }\n const node = this.graph.node(key)\n if (!node || node.kind !== DomainModelKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this data domain has any direct models.\n *\n * @returns True if the data domain has models.\n * @example\n * ```typescript\n * if (domain.hasModels()) {\n * // ...\n * }\n * ```\n */\n hasModels(): boolean {\n return this.fields.some((item) => item.type === 'model')\n }\n\n /**\n * Lists all data models in the graph.\n *\n * @param parent The key of the parent namespace. If not\n * provided, all root data models will be listed.\n * @returns A generator that yields each `DomainModel`.\n * @example\n * ```typescript\n * for (const model of dataDomain.listGraphModels()) {\n * console.log(model.key);\n * }\n * ```\n */\n *listGraphModels(parent?: string): Generator<DomainModel> {\n for (const node of this.graph.children(parent)) {\n const value = this.graph.node(node) as DomainGraphNodeType\n if (value.kind === DomainModelKind && value.domain.key === this.key) {\n yield value\n }\n }\n }\n\n /**\n * Finds a data model by its key.\n *\n * @param key The key of the data model to find.\n * @returns The data model instance or undefined if not\n * found.\n * @example\n * ```typescript\n * const model = dataDomain.findModel('userModel');\n * if (model) {\n * console.log(model.key);\n * }\n * ```\n */\n findModel(key: string): DomainModel | undefined {\n const value = this.graph.node(key) as DomainModel | undefined\n if (value && value.kind === DomainModelKind) {\n return value\n }\n return undefined\n }\n\n /**\n * Moves a data model to a new parent.\n *\n * @param key The key of the data model to move.\n * @param parent The new parent namespace key. If\n * undefined, the data model will be moved to the root.\n * @returns The current DataDomain instance.\n * @throws Error When the data model or parent does not\n * exist, or when a data model is moved to a foreign\n * domain.\n * @example\n * ```typescript\n * dataDomain.moveModel('userModel', 'newNamespace');\n * ```\n */\n moveModel(key: string, parent?: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Data model ${key} does not exist`)\n }\n\n const model = this.findModel(key)\n if (!model) {\n throw new Error(`Data model ${key} not found in the graph`)\n }\n\n if (parent) {\n const instance = this.findNamespace(parent)\n if (instance && instance.domain.key !== this.key) {\n throw new Error(`Cannot move a model to a foreign domain`)\n }\n if (!instance) {\n throw new Error(`Parent namespace ${parent} does not exist`)\n }\n }\n\n if (model.domain.key !== this.key) {\n throw new Error(`Cannot move a data model to a foreign domain`)\n }\n\n // namespaces can only have one parent\n const currentParentKey = this.graph.parent(key)\n // Remove from current parent\n if (currentParentKey && !parent) {\n // The new parent namespace will detach the model when attaching to self.\n const currentParent = this.findNamespace(currentParentKey)\n if (!currentParent) {\n throw new Error(`The parent namespace ${currentParentKey} not found`)\n }\n currentParent.detachModel(key)\n } else if (!currentParentKey) {\n // The model is a root model.\n this.removeField(key)\n }\n\n // Add to new parent\n if (parent) {\n const parentNamespace = this.findNamespace(parent) as DomainNamespace\n parentNamespace.attachModel(key)\n } else {\n // The model is becoming a root model.\n this.fields.push({\n type: 'model',\n key,\n })\n }\n\n this.notifyChange()\n return this\n }\n\n /**\n * Adds an entity to a data model.\n *\n * @param input The partial entity schema.\n * @param parent The key of the parent data model.\n * @returns The created entity instance.\n * @throws {Error} When the parent does not exist or is not a data model.\n * @example\n * ```typescript\n * const userEntity = dataDomain.addEntity({\n * key: 'user',\n * }, 'userModel');\n * ```\n */\n addEntity(parent: string, input?: Partial<DomainEntitySchema>): DomainEntity {\n if (!parent) {\n throw new Error(`An entity expects a DomainModel parent`)\n }\n if (!this.graph.hasNode(parent)) {\n throw new Error(`The parent ${parent} does not exist`)\n }\n const instance = this.findModel(parent)\n if (!instance) {\n throw new Error(`Parent model ${parent} is not a valid model`)\n }\n if (instance.domain.key !== this.key) {\n throw new Error(`Cannot add an entity to a foreign domain`)\n }\n return instance.addEntity(input)\n }\n\n /**\n * Removes an entity from the graph.\n *\n * @param key The key of the entity to remove.\n * @returns The current DataDomain instance.\n * @throws Error When the entity does not exist.\n * @example\n * ```typescript\n * dataDomain.removeEntity('user');\n * ```\n */\n removeEntity(key: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Entity ${key} does not exist`)\n }\n const parentKey = this.graph.parent(key)\n if (!parentKey) {\n throw new Error(`Parent model not found for entity ${key}`)\n }\n const parent = this.findModel(parentKey)\n if (!parent) {\n throw new Error(`Parent model ${parentKey} not found`)\n }\n if (parent.domain.key !== this.key) {\n throw new Error(`Cannot remove an entity from a foreign domain`)\n }\n parent.removeEntity(key)\n return this\n }\n\n /**\n * Lists all entities in a data model, or, if the model key is not provided,\n * all entities in the domain.\n *\n * @param parent The key of the parent data model.\n * @returns A generator that yields each `DomainEntity`.\n * @example\n * ```typescript\n * for (const entity of dataDomain.listEntities('userModel')) {\n * console.log(entity.key);\n * }\n * ```\n */\n *listEntities(parent?: string): Generator<DomainEntity> {\n const iterator = parent ? this.graph.children(parent) : this.graph.nodes()\n for (const node of iterator) {\n const value = this.graph.node(node) as DomainGraphNodeType\n if (value.kind === DomainEntityKind && value.domain.key === this.key) {\n yield value\n }\n }\n }\n\n /**\n * Lists all entities in the graph that are not part of this domain.\n */\n *listForeignEntities(): Generator<DomainEntity> {\n for (const node of this.graph.nodes()) {\n const value = this.graph.node(node) as DomainGraphNodeType\n if (value.kind === DomainEntityKind && value.domain.key !== this.key) {\n yield value\n }\n }\n }\n\n /**\n * Finds an entity by its key.\n *\n * @param key The key of the entity to find.\n * @returns The entity instance or undefined if not found.\n * @example\n * ```typescript\n * const entity = dataDomain.findEntity('user');\n * if (entity) {\n * console.log(entity.key);\n * }\n * ```\n */\n findEntity(key: string): DomainEntity | undefined {\n const node = this.graph.node(key) as DomainEntity | undefined\n if (node && node.kind === DomainEntityKind) {\n return node\n }\n return undefined\n }\n\n /**\n * Moves an entity from one model to another.\n *\n * @param entityKey The key of the entity to move.\n * @param sourceModelKey The key of the source model.\n * @param targetModelKey The key of the target model.\n * @throws Error When the entity, source model, or target model does not exist.\n * @throws Error When the entity is not in the same domain.\n * @throws Error When the source and target models are the same.\n * @throws Error When moving to an unsupported object.\n */\n moveEntity(entityKey: string, sourceModelKey: string, targetModelKey: string): void {\n if (sourceModelKey === targetModelKey) {\n throw new Error(`Cannot move an entity to the same model`)\n }\n if (!this.graph.hasNode(entityKey)) {\n throw new Error(`Entity ${entityKey} does not exist`)\n }\n if (!this.graph.hasNode(sourceModelKey)) {\n throw new Error(`Source model ${sourceModelKey} does not exist`)\n }\n if (!this.graph.hasNode(targetModelKey)) {\n throw new Error(`Target model ${targetModelKey} does not exist`)\n }\n\n const entity = this.findEntity(entityKey)\n const sourceModel = this.findModel(sourceModelKey)\n const targetModel = this.findModel(targetModelKey)\n\n if (!entity || !sourceModel || !targetModel) {\n throw new Error(`Entity or models not found in the graph`)\n }\n\n if (entity.domain.key !== this.key) {\n // this also applied to the parent model.\n throw new Error(`Cannot move an entity from a foreign domain`)\n }\n if (targetModel.domain.key !== this.key) {\n throw new Error(`Cannot move an entity to a foreign domain`)\n }\n // The target model detaches the entity when attaching to self.\n targetModel.attachEntity(entityKey)\n this.notifyChange()\n }\n\n /**\n * Adds an association between two entities.\n *\n * This function is a shortcut that finds the entity and\n * calls the `addAssociation` method on it.\n *\n * @param source The key of the source entity.\n * @param init The association options.\n * @returns The created association.\n * @throws Error When the source entity does not exist.\n * @example\n * ```typescript\n * const addressAssociation = dataDomain.addAssociation(\n * 'user', { key: 'address' }\n * );\n * ```\n */\n addAssociation(source: string, init?: AssociationAddOptions): DomainAssociation {\n if (!this.graph.hasNode(source)) {\n throw new Error(`Source entity ${source} not found`)\n }\n const entity = this.findEntity(source)\n if (!entity) {\n throw new Error(`Source entity ${source} not found`)\n }\n if (entity.domain.key !== this.key) {\n throw new Error(`Cannot add an association to a foreign domain`)\n }\n return entity.addAssociation(init)\n }\n\n /**\n * Removes an association from the graph.\n *\n * @param key The key of the association to remove.\n * @returns The current DataDomain instance.\n * @throws Error When the association does not exist or\n * when the parent entity is not found.\n * @example\n * ```typescript\n * dataDomain.removeAssociation('address');\n * ```\n */\n removeAssociation(key: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Association ${key} does not exist`)\n }\n const instance = this.graph.node(key) as DomainAssociation\n if (!instance || instance.kind !== DomainAssociationKind) {\n throw new Error(`Association ${key} not found`)\n }\n const entity = instance.getParentInstance()\n if (!entity) {\n throw new Error(`Parent entity not found for association ${key}`)\n }\n if (entity.domain.key !== this.key) {\n throw new Error(`Cannot remove an association from a foreign domain`)\n }\n entity.removeAssociation(key)\n return this\n }\n\n /**\n * Finds an association by its key.\n *\n * @param key The key of the association to find.\n * @returns The association instance or undefined if not\n * found.\n * @example\n * ```typescript\n * const assoc = dataDomain.findAssociation('address');\n * if (assoc) {\n * console.log(assoc.key);\n * }\n * ```\n */\n findAssociation(key: string): DomainAssociation | undefined {\n const node = this.graph.node(key) as DomainAssociation | undefined\n if (node && node.kind === DomainAssociationKind) {\n return node\n }\n return undefined\n }\n\n /**\n * Adds a property to an entity.\n *\n * @param parent The key of the parent entity.\n * @param property The partial property schema.\n * @returns The created property instance.\n * @throws Error When the parent does not exist or is not\n * an entity.\n * @example\n * ```typescript\n * const nameProperty = dataDomain.addProperty(\n * 'user', { key: 'name', type: 'string' }\n * );\n * ```\n */\n addProperty(parent: string, property?: Partial<DomainPropertySchema>): DomainProperty {\n if (!parent) {\n throw new Error(`A property expects a DomainEntity parent`)\n }\n if (!this.graph.hasNode(parent)) {\n throw new Error(`Parent entity ${parent} does not exist`)\n }\n const entity = this.findEntity(parent)\n if (!entity) {\n throw new Error(`Parent entity ${parent} not found`)\n }\n if (entity.domain.key !== this.key) {\n throw new Error(`Cannot add a property to a foreign domain`)\n }\n return entity.addProperty(property)\n }\n\n /**\n * Removes a property from the graph.\n *\n * @param key The key of the property to remove.\n * @returns The current DataDomain instance.\n * @throws Error When the property does not exist or when\n * the parent entity is not found.\n * @example\n * ```typescript\n * dataDomain.removeProperty('name');\n * ```\n */\n removeProperty(key: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Property ${key} does not exist`)\n }\n const instance = this.graph.node(key) as DomainProperty\n if (!instance || instance.kind !== DomainPropertyKind) {\n throw new Error(`Property ${key} not found`)\n }\n const entity = instance.getParentInstance()\n if (!entity) {\n throw new Error(`Parent entity not found for property ${key}`)\n }\n if (entity.domain.key !== this.key) {\n throw new Error(`Cannot remove a property from a foreign domain`)\n }\n entity.removeProperty(key)\n return this\n }\n\n /**\n * Finds a property by its key.\n *\n * @param key The key of the property to find.\n * @returns The property instance or undefined if not\n * found.\n * @example\n * ```typescript\n * const prop = dataDomain.findProperty('name');\n * if (prop) {\n * console.log(prop.key);\n * }\n * ```\n */\n findProperty(key: string): DomainProperty | undefined {\n const node = this.graph.node(key) as DomainProperty | undefined\n if (node && node.kind === DomainPropertyKind) {\n return node\n }\n return undefined\n }\n\n /**\n * Registers a foreign DataDomain.\n *\n * @param domain The foreign DataDomain instance.\n * @param key The unique identifier for the foreign\n * domain.\n * @param version The version of the foreign domain.\n * @throws Error When a foreign domain with the same key is already registered.\n * @example\n * ```typescript\n * dataDomain.registerForeignDomain(\n * foreignDomain, 'foreignDomain', '1.0.0'\n * );\n * ```\n */\n registerForeignDomain(domain: DataDomain): void {\n const { info, key } = domain\n if (!info.version) {\n // @TODO: make the data domain immutable after a version is set.\n // This will prevent the user from changing the version\n // after the domain is registered.\n throw new Error(`Foreign domain ${key} does not have a version set`)\n }\n if (this.dependencies.has(key)) {\n throw new Error(`Foreign domain with key ${key} already registered`)\n }\n this.dependencies.set(key, domain)\n this.dependencyList.push({ key, version: info.version })\n // Copy the relevant parts of the foreign domain's graph into the local graph.\n // this.copyForeignDomainGraph(domain)\n mergeGraph(this.graph, domain.graph, domain.key)\n this.notifyChange()\n }\n\n /**\n * Un-registers a foreign DataDomain. It removes all defined by the foreign domain\n * information from the graph.\n * @param key The key of the foreign domain to unregister.\n */\n unregisterForeignDomain(key: string): void {\n const foreignDomain = this.dependencies.get(key)\n if (!foreignDomain) {\n throw new Error(`Foreign domain with key ${key} not found`)\n }\n this.dependencies.delete(key)\n this.dependencyList = this.dependencyList.filter((dependency) => dependency.key !== key)\n // Remove the foreign domain's nodes from the local graph.\n removeForeignGraph(this.graph, foreignDomain.key)\n this.notifyChange()\n }\n\n /**\n * Finds an entity in a foreign domain.\n *\n * @param entityKey The key of the entity to find.\n * @param domainKey The key of the foreign domain.\n * @returns The entity instance or undefined if not\n * found.\n * @example\n * ```typescript\n * const foreignUser = dataDomain.findForeignEntity(\n * 'user', 'foreignDomain'\n * );\n * if (foreignUser) {\n * console.log(foreignUser.key);\n * }\n * ```\n */\n findForeignEntity(entityKey: string, domainKey: string): DomainEntity | undefined {\n const foreignDomain = this.dependencies.get(domainKey)\n if (!foreignDomain) {\n return undefined\n }\n const foreignKey = `${domainKey}:${entityKey}`\n const node = this.graph.node(foreignKey)\n if (node && node.kind === DomainEntityKind) {\n return node as DomainEntity\n }\n return undefined\n }\n\n /**\n * A convenience function to remove an object from the\n * namespace.\n *\n * @param key The key of the object to remove.\n * @param kind The kind of the object to remove.\n * @throws Error when the kind is not known.\n * @example\n * ```typescript\n * dataDomain.removeDomainElement('user', DomainEntityKind);\n * ```\n */\n removeDomainElement(key: string, kind: string): void {\n switch (kind) {\n case DomainNamespaceKind:\n this.removeNamespace(key)\n break\n case DomainModelKind:\n this.removeModel(key)\n break\n case DomainEntityKind:\n this.removeEntity(key)\n break\n case DomainPropertyKind:\n this.removeProperty(key)\n break\n case DomainAssociationKind:\n this.removeAssociation(key)\n break\n default:\n throw new Error(`Unknown kind ${kind} for the object ${key}`)\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DataDomain.js","sourceRoot":"","sources":["../../../src/modeling/DataDomain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,kBA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I,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;gBACrB,MAAK;YACP,KAAK,gBAAgB;gBACnB,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;gBACtB,MAAK;YACP,KAAK,kBAAkB;gBACrB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;gBACxB,MAAK;YACP,KAAK,qBAAqB;gBACxB,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAA;gBAC3B,MAAK;YACP;gBACE,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,mBAAmB,GAAG,EAAE,CAAC,CAAA;QACjE,CAAC;IACH,CAAC;CACF","sourcesContent":["import { nanoid } from '../nanoid.js'\nimport { Graph } from '@api-client/graph/graph/Graph.js'\nimport {\n DomainAssociationKind,\n DataDomainKind,\n DomainEntityKind,\n DomainModelKind,\n DomainNamespaceKind,\n DomainPropertyKind,\n} from '../models/kinds.js'\nimport type {\n AssociationAddOptions,\n DomainGraphEdge,\n DomainGraphNodeType,\n ForeignDomainDependency,\n SerializedGraph,\n} from './types.js'\nimport { type DomainNamespaceSchema, DomainNamespace, type NamespaceOrderedItem } from './DomainNamespace.js'\nimport { type DomainModelSchema, DomainModel } from './DomainModel.js'\nimport { type DomainEntitySchema, DomainEntity } from './DomainEntity.js'\nimport { DomainAssociation } from './DomainAssociation.js'\nimport { DomainProperty, DomainPropertySchema } from './DomainProperty.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { removeGraphNode } from './GraphUtils.js'\nimport { serialize, deserialize, mergeGraph, removeForeignGraph } from './DomainSerialization.js'\n\nexport interface DataDomainSchema {\n info: IThing\n kind: typeof DataDomainKind\n key: string\n graph?: SerializedGraph\n dependencyList?: ForeignDomainDependency[]\n /**\n * The ordered list of fields (namespace and models) in the schema.\n * These only keep references to define the order of these properties\n * in the schema as graph won't do it.\n */\n fields?: NamespaceOrderedItem[]\n}\n\n/**\n * Represents the root of a data domain model.\n *\n * The `DataDomain` class serves as the top-level container\n * for a collection of data models, namespaces, entities,\n * properties, and associations. It provides methods for\n * managing and manipulating these data elements, enabling\n * the creation of complex and interconnected data\n * structures.\n *\n * **Key Features:**\n *\n * - **Root Container:** Holds all data elements within a domain.\n * - **Graph-Based Structure:** Uses a graph to represent relationships between data elements.\n * - **Namespace Management:** Supports creating and managing namespaces to organize data models.\n * - **Data Model Management:** Supports creating and managing data models to group entities.\n * - **Entity Management:** Supports creating and managing entities, which define the structure of data.\n * - **Property Management:** Supports creating and managing properties, which define the data elements\n * within entities.\n * - **Association Management:** Supports creating and managing associations, which define relationships\n * between entities.\n * - **Foreign Domain Support:** Allows registering and integrating data from external domains.\n * - **Change Notification:** Notifies listeners when changes occur within the data domain.\n *\n * **Usage:**\n *\n * 1. Create an instance of the `DataDomain`.\n * 2. Use methods like `addNamespace()`, `addModel()`,\n * `addEntity()`, `addProperty()`, and `addAssociation()`\n * to build the data domain structure.\n * 3. Use methods like `findNamespace()`, `findModel()`,\n * `findEntity()`, `findProperty()`, and\n * `findAssociation()` to retrieve data elements.\n * 4. Use methods like `listNamespaces()`, `listGraphNamespaces()`, `listModels()`,\n * and `listEntities()` to iterate over collections of\n * data elements.\n * 5. Use `registerForeignDomain()` to integrate data from\n * external domains.\n * 6. Listen for the `change` event to be notified of\n * changes within the data domain.\n *\n * **Example:**\n *\n * ```typescript\n * const dataDomain = new DataDomain();\n * const userNamespace = dataDomain.addNamespace({\n * key: 'userNamespace',\n * });\n * const userModel = userNamespace.addModel({\n * key: 'userModel',\n * });\n * const userEntity = userModel.addEntity({\n * key: 'user',\n * });\n * const nameProperty = userEntity.addProperty({\n * key: 'name',\n * type: 'string',\n * });\n * ```\n *\n * @fires DataDomain#change {Event} - Fired when the data\n * domain changes.\n *\n * @todo: Implement a mechanism to move an entity to a new\n * parent model.\n */\nexport class DataDomain extends EventTarget {\n /**\n * The kind of the domain element.\n */\n kind: typeof DataDomainKind\n /**\n * The unique key of the domain element.\n */\n key: string\n\n /**\n * The graph used to store the data domain structure.\n */\n graph: Graph<unknown, DomainGraphNodeType, DomainGraphEdge>\n\n /**\n * A map of foreign data domains.\n * Key: The unique identifier of the foreign domain.\n * Value: The foreign DataDomain instance.\n */\n dependencies: Map<string, DataDomain> = new Map<string, DataDomain>()\n\n /**\n * The list of foreign domain dependencies.\n */\n dependencyList: ForeignDomainDependency[] = []\n\n /**\n * The description of the domain property.\n */\n info: Thing\n\n /**\n * When the initializing flag is set to true,\n * the domain is not notified of changes.\n */\n #initializing = true\n\n /**\n * When the notifying flag is set to true,\n * the domain is pending a notification.\n * No other notifications will be sent until\n * the current notification is sent.\n */\n #notifying = false\n\n /**\n * This is to keep it consistent with the domain elements.\n */\n get domain(): DataDomain {\n return this\n }\n\n /**\n * The ordered list of fields (namespace and models) in the schema.\n * These only keep references to define the order of these properties\n * in the schema as graph won't do it.\n */\n accessor fields: NamespaceOrderedItem[]\n\n static createSchema(input: Partial<DataDomainSchema> = {}): DataDomainSchema {\n const { key = nanoid(), fields } = input\n const info = Thing.fromJSON(input.info, { name: 'Unnamed domain' }).toJSON()\n const result: DataDomainSchema = {\n kind: DataDomainKind,\n key,\n info,\n }\n if (input.dependencyList) {\n result.dependencyList = structuredClone(input.dependencyList)\n }\n if (input.graph) {\n result.graph = input.graph\n }\n if (Array.isArray(fields)) {\n result.fields = [...fields]\n }\n return result\n }\n\n /**\n * Creates a new instance of the `DataDomain` class.\n *\n * When creating a new Data Domain arguments should not be set.\n * When restoring a Data Domain from a previous state, you should provide\n * the serialized graph state as well as the same list of dependencies\n * used when the graph was deserialized. Edges to missing dependency nodes\n * will be ignored.\n *\n * @param state The previously serialized state of the graph.\n * @param dependencies An array of foreign data domains to register with this domain.\n */\n constructor(state?: Partial<DataDomainSchema>, dependencies?: DataDomain[]) {\n super()\n const init = DataDomain.createSchema(state)\n this.kind = init.kind\n this.key = init.key\n this.info = new Thing(init.info)\n this.graph = deserialize(this, init.graph, dependencies)\n if (Array.isArray(init.fields)) {\n this.fields = [...init.fields]\n } else {\n this.fields = []\n }\n if (Array.isArray(init.dependencyList)) {\n this.dependencyList = [...init.dependencyList]\n } else {\n this.dependencyList = []\n }\n this.#initializing = false\n this.info.addEventListener('change', () => {\n this.notifyChange()\n })\n }\n\n /**\n * Serializes the DataDomain instance to a JSON object.\n * It does not serialize the foreign domain dependencies. The serialized nodes\n * are the ones that are local to this data domain.\n * @returns The serialized data domain ready for storage or transport.\n */\n toJSON(): DataDomainSchema {\n const result: DataDomainSchema = {\n info: this.info.toJSON(),\n kind: this.kind,\n key: this.key,\n graph: serialize(this.graph, this.key),\n }\n if (this.dependencyList.length > 0) {\n result.dependencyList = structuredClone(this.dependencyList)\n }\n if (Array.isArray(this.fields) && this.fields.length) {\n result.fields = [...this.fields]\n }\n return result\n }\n\n /**\n * This function is used internally by all domain elements to notify that something has changed.\n * Since we want to notify listeners after the operation commits, we use microtask\n * to ensure that the event is dispatched after the current operation.\n */\n notifyChange() {\n if (this.#notifying || this.#initializing) {\n return\n }\n this.#notifying = true\n queueMicrotask(() => {\n this.#notifying = false\n const event = new Event('change')\n this.dispatchEvent(event)\n })\n }\n\n private removeField(key: string): void {\n this.fields = this.fields.filter((item) => item.key !== key)\n }\n\n /**\n * Checks if this data domain has any fields (namespace and models).\n *\n * @returns True if the data domain has fields.\n * @example\n * ```typescript\n * if (domain.hasFields()) {\n * // ...\n * }\n * ```\n */\n hasFields(): boolean {\n return this.fields.length > 0\n }\n\n /**\n * Lists all fields (namespace and models) of this namespace.\n *\n * @returns A generator that yields each `DomainAssociation` or `DomainProperty`.\n * @example\n * ```typescript\n * for (const field of namespace.listFields()) {\n * console.log(field.key);\n * }\n * ```\n */\n *listFields(): Generator<DomainNamespace | DomainModel> {\n for (const { key } of this.fields) {\n const node = this.graph.node(key)\n if (!node) {\n continue\n }\n if (node.kind === DomainNamespaceKind || node.kind === DomainModelKind) {\n yield node\n }\n }\n }\n\n /**\n * Adds a new data domain instance to the graph.\n *\n * @param value The partial namespace schema. All missing\n * values will be filled with default values.\n * @param parent The parent namespace key. If not provided,\n * the new namespace will be added to the root of the\n * graph.\n * @returns The created namespace instance.\n * @throws Error When the parent does not exist or is not\n * a namespace.\n * @example\n * ```typescript\n * const newNamespace = dataDomain.addNamespace({\n * key: 'newNamespace',\n * });\n * ```\n */\n addNamespace(value?: Partial<DomainNamespaceSchema>, parent?: string): DomainNamespace {\n if (parent) {\n if (!this.graph.hasNode(parent)) {\n throw new Error(`Parent namespace ${parent} does not exist`)\n }\n const instance = this.graph.node(parent) as DomainNamespace\n if (!instance || instance.kind !== DomainNamespaceKind) {\n throw new Error(`Parent namespace ${parent} is not a valid namespace`)\n }\n if (instance.domain.key !== this.key) {\n throw new Error(`Cannot add a namespace to a foreign domain`)\n }\n return instance.addNamespace(value)\n }\n const item = new DomainNamespace(this, value)\n this.graph.setNode(item.key, item)\n this.fields.push({\n type: 'namespace',\n key: item.key,\n })\n this.notifyChange()\n return item\n }\n\n /**\n * Removes a namespace from the graph.\n *\n * @param key The key of the namespace to remove.\n * @returns The current DataDomain instance.\n * @throws Error When the namespace does not exist.\n * @example\n * ```typescript\n * dataDomain.removeNamespace('userNamespace');\n * ```\n */\n removeNamespace(key: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Namespace ${key} does not exist`)\n }\n const ns = this.graph.node(key) as DomainNamespace\n if (!ns || ns.kind !== DomainNamespaceKind) {\n throw new Error(`Namespace ${key} not found`)\n }\n if (ns.domain.key !== this.key) {\n throw new Error(`Cannot remove a namespace from a foreign domain`)\n }\n const parent = ns.getParentInstance()\n if (parent === this) {\n removeGraphNode(this.graph, key)\n this.removeField(key)\n this.notifyChange()\n } else {\n parent.removeNamespace(key)\n }\n return this\n }\n\n /**\n * Lists all namespaces of this data domain that are direct children of it.\n *\n * Note, it accounts for the order of the namespaces as defined in the `fields` array.\n *\n * @returns A generator that yields each `DomainNamespace`.\n * @example\n * ```typescript\n * for (const ns of domain.listNamespaces()) {\n * console.log(ns.key);\n * }\n * ```\n */\n *listNamespaces(): Generator<DomainNamespace> {\n for (const { key, type } of this.fields) {\n if (type !== 'namespace') {\n continue\n }\n const node = this.graph.node(key)\n if (!node || node.kind !== DomainNamespaceKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this data domain has any namespaces.\n *\n * @returns True if the data domain has namespaces.\n * @example\n * ```typescript\n * if (domain.hasNamespaces()) {\n * // ...\n * }\n * ```\n */\n hasNamespaces(): boolean {\n return this.fields.some((item) => item.type === 'namespace')\n }\n\n /**\n * Lists all namespaces in the graph.\n *\n * @param parent The key of the parent namespace. If not\n * provided, all root namespaces will be listed.\n * @returns A generator that yields each `DomainNamespace`.\n * @example\n * ```typescript\n * for (const ns of dataDomain.listGraphNamespaces()) {\n * console.log(ns.key);\n * }\n * ```\n */\n *listGraphNamespaces(parent?: string): Generator<DomainNamespace> {\n for (const node of this.graph.children(parent)) {\n const value = this.graph.node(node) as DomainGraphNodeType\n if (value.kind === DomainNamespaceKind && value.domain.key === this.key) {\n yield value\n }\n }\n }\n\n /**\n * Finds a namespace by its key.\n *\n * @param key The key of the namespace to find.\n * @returns The namespace instance or undefined if not\n * found.\n * @example\n * ```typescript\n * const ns = dataDomain.findNamespace('userNamespace');\n * if (ns) {\n * console.log(ns.key);\n * }\n * ```\n */\n findNamespace(key: string): DomainNamespace | undefined {\n const result = this.graph.node(key) as DomainNamespace | undefined\n if (result && result.kind === DomainNamespaceKind) {\n return result\n }\n }\n\n /**\n * Moves a namespace to a new parent.\n *\n * @param key The key of the namespace to move.\n * @param parent The new parent namespace key. If\n * undefined, the namespace will be moved to the root.\n * @returns The current DataDomain instance.\n * @throws Error When the namespace or parent does not\n * exist, or when a namespace is moved to itself or\n * its own child.\n * @example\n * ```typescript\n * dataDomain.moveNamespace('userNamespace', 'root');\n * ```\n */\n moveNamespace(key: string, parent?: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Namespace ${key} does not exist`)\n }\n\n const namespace = this.findNamespace(key)\n if (!namespace) {\n throw new Error(`Namespace ${key} not found in the graph`)\n }\n\n if (parent) {\n const instance = this.findNamespace(parent)\n if (instance && instance.domain.key !== this.key) {\n throw new Error(`Cannot move a namespace to a foreign domain`)\n }\n if (!instance) {\n throw new Error(`Parent namespace ${parent} does not exist`)\n }\n }\n\n if (key === parent) {\n throw new Error(`Cannot move a namespace to itself`)\n }\n\n if (namespace.domain.key !== this.key) {\n throw new Error(`Cannot move a namespace from a foreign domain`)\n }\n let parentNamespace: DomainNamespace | undefined\n if (parent) {\n parentNamespace = this.findNamespace(parent)\n if (!parentNamespace) {\n throw new Error(`Parent namespace ${parent} not found`)\n }\n if (this.isChildOf(parent, key)) {\n throw new Error(`Cannot move a namespace to its own child`)\n }\n }\n\n // namespaces can only have one parent\n const currentParentKey = this.graph.parent(key)\n if (currentParentKey && !parent) {\n // The new parent namespace will detach the namespace when attaching to self.\n const currentParent = this.graph.node(currentParentKey) as DomainNamespace\n currentParent.detachNamespace(key)\n } else if (!currentParentKey) {\n // The namespace is a root namespace.\n this.removeField(key)\n }\n // Add to new parent\n if (parent && parentNamespace) {\n parentNamespace.attachNamespace(key)\n } else {\n // The namespace is a root namespace.\n this.fields.push({\n type: 'namespace',\n key,\n })\n }\n this.notifyChange()\n return this\n }\n\n /**\n * Checks if a namespace is a child of another namespace.\n * @param parentKey The key of the parent namespace.\n * @param childKey The key of the child namespace.\n * @returns True if the namespace is a child of another namespace.\n */\n private isChildOf(parentKey: string, childKey: string): boolean {\n const children = this.graph.children(childKey)\n for (const child of children) {\n if (child === parentKey) {\n return true\n }\n if (this.isChildOf(parentKey, child)) {\n return true\n }\n }\n return false\n }\n\n /**\n * Adds a data model to the graph.\n *\n * @param input The partial data model schema.\n * @param parent The parent namespace key. If not\n * provided, the new data model will be added to the\n * root of the graph.\n * @returns The created data model instance.\n * @throws Error When the parent does not exist or is not\n * a namespace.\n * @example\n * ```typescript\n * const newModel = dataDomain.addModel({\n * key: 'newModel',\n * });\n * ```\n */\n addModel(input?: Partial<DomainModelSchema>, parent?: string): DomainModel {\n if (parent) {\n if (!this.graph.hasNode(parent)) {\n throw new Error(`Parent ${parent} does not exist`)\n }\n const instance = this.findNamespace(parent)\n if (!instance) {\n throw new Error(`Parent namespace ${parent} is not a valid namespace`)\n }\n if (instance.domain.key !== this.key) {\n throw new Error(`Cannot add a model to a foreign domain`)\n }\n return instance.addModel(input)\n }\n const item = new DomainModel(this, input)\n this.graph.setNode(item.key, item)\n this.fields.push({\n type: 'model',\n key: item.key,\n })\n return item\n }\n\n /**\n * Removes a data model from the graph.\n *\n * @param key The key of the data model to remove.\n * @returns The current DataDomain instance.\n * @throws Error When the data model does not exist.\n * @example\n * ```typescript\n * dataDomain.removeModel('userModel');\n * ```\n */\n removeModel(key: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Data model ${key} does not exist`)\n }\n const model = this.graph.node(key) as DomainModel\n if (!model || model.kind !== DomainModelKind) {\n throw new Error(`Data model ${key} not found`)\n }\n if (model.domain.key !== this.key) {\n throw new Error(`Cannot remove a model from a foreign domain`)\n }\n const parent = model.getParentInstance()\n if (parent === this) {\n removeGraphNode(this.graph, key)\n this.removeField(key)\n this.notifyChange()\n } else {\n parent.removeModel(key)\n }\n return this\n }\n\n /**\n * Lists all models of this data domain that are direct children of it.\n *\n * Note, it accounts for the order of the models as\n * defined in the `fields` array.\n *\n * @returns A generator that yields each `DomainModel`.\n * @example\n * ```typescript\n * for (const ns of namespace.listModels()) {\n * console.log(ns.key);\n * }\n * ```\n */\n *listModels(): Generator<DomainModel> {\n for (const { key, type } of this.fields) {\n if (type !== 'model') {\n continue\n }\n const node = this.graph.node(key)\n if (!node || node.kind !== DomainModelKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this data domain has any direct models.\n *\n * @returns True if the data domain has models.\n * @example\n * ```typescript\n * if (domain.hasModels()) {\n * // ...\n * }\n * ```\n */\n hasModels(): boolean {\n return this.fields.some((item) => item.type === 'model')\n }\n\n /**\n * Lists all data models in the graph.\n *\n * @param parent The key of the parent namespace. If not\n * provided, all root data models will be listed.\n * @returns A generator that yields each `DomainModel`.\n * @example\n * ```typescript\n * for (const model of dataDomain.listGraphModels()) {\n * console.log(model.key);\n * }\n * ```\n */\n *listGraphModels(parent?: string): Generator<DomainModel> {\n for (const node of this.graph.children(parent)) {\n const value = this.graph.node(node) as DomainGraphNodeType\n if (value.kind === DomainModelKind && value.domain.key === this.key) {\n yield value\n }\n }\n }\n\n /**\n * Finds a data model by its key.\n *\n * @param key The key of the data model to find.\n * @returns The data model instance or undefined if not\n * found.\n * @example\n * ```typescript\n * const model = dataDomain.findModel('userModel');\n * if (model) {\n * console.log(model.key);\n * }\n * ```\n */\n findModel(key: string): DomainModel | undefined {\n const value = this.graph.node(key) as DomainModel | undefined\n if (value && value.kind === DomainModelKind) {\n return value\n }\n return undefined\n }\n\n /**\n * Moves a data model to a new parent.\n *\n * @param key The key of the data model to move.\n * @param parent The new parent namespace key. If\n * undefined, the data model will be moved to the root.\n * @returns The current DataDomain instance.\n * @throws Error When the data model or parent does not\n * exist, or when a data model is moved to a foreign\n * domain.\n * @example\n * ```typescript\n * dataDomain.moveModel('userModel', 'newNamespace');\n * ```\n */\n moveModel(key: string, parent?: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Data model ${key} does not exist`)\n }\n\n const model = this.findModel(key)\n if (!model) {\n throw new Error(`Data model ${key} not found in the graph`)\n }\n\n if (parent) {\n const instance = this.findNamespace(parent)\n if (instance && instance.domain.key !== this.key) {\n throw new Error(`Cannot move a model to a foreign domain`)\n }\n if (!instance) {\n throw new Error(`Parent namespace ${parent} does not exist`)\n }\n }\n\n if (model.domain.key !== this.key) {\n throw new Error(`Cannot move a data model to a foreign domain`)\n }\n\n // namespaces can only have one parent\n const currentParentKey = this.graph.parent(key)\n // Remove from current parent\n if (currentParentKey && !parent) {\n // The new parent namespace will detach the model when attaching to self.\n const currentParent = this.findNamespace(currentParentKey)\n if (!currentParent) {\n throw new Error(`The parent namespace ${currentParentKey} not found`)\n }\n currentParent.detachModel(key)\n } else if (!currentParentKey) {\n // The model is a root model.\n this.removeField(key)\n }\n\n // Add to new parent\n if (parent) {\n const parentNamespace = this.findNamespace(parent) as DomainNamespace\n parentNamespace.attachModel(key)\n } else {\n // The model is becoming a root model.\n this.fields.push({\n type: 'model',\n key,\n })\n }\n\n this.notifyChange()\n return this\n }\n\n /**\n * Adds an entity to a data model.\n *\n * @param input The partial entity schema.\n * @param parent The key of the parent data model.\n * @returns The created entity instance.\n * @throws {Error} When the parent does not exist or is not a data model.\n * @example\n * ```typescript\n * const userEntity = dataDomain.addEntity({\n * key: 'user',\n * }, 'userModel');\n * ```\n */\n addEntity(parent: string, input?: Partial<DomainEntitySchema>): DomainEntity {\n if (!parent) {\n throw new Error(`An entity expects a DomainModel parent`)\n }\n if (!this.graph.hasNode(parent)) {\n throw new Error(`The parent ${parent} does not exist`)\n }\n const instance = this.findModel(parent)\n if (!instance) {\n throw new Error(`Parent model ${parent} is not a valid model`)\n }\n if (instance.domain.key !== this.key) {\n throw new Error(`Cannot add an entity to a foreign domain`)\n }\n return instance.addEntity(input)\n }\n\n /**\n * Removes an entity from the graph.\n *\n * @param key The key of the entity to remove.\n * @returns The current DataDomain instance.\n * @throws Error When the entity does not exist.\n * @example\n * ```typescript\n * dataDomain.removeEntity('user');\n * ```\n */\n removeEntity(key: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Entity ${key} does not exist`)\n }\n const parentKey = this.graph.parent(key)\n if (!parentKey) {\n throw new Error(`Parent model not found for entity ${key}`)\n }\n const parent = this.findModel(parentKey)\n if (!parent) {\n throw new Error(`Parent model ${parentKey} not found`)\n }\n if (parent.domain.key !== this.key) {\n throw new Error(`Cannot remove an entity from a foreign domain`)\n }\n parent.removeEntity(key)\n return this\n }\n\n /**\n * Lists all entities in a data model, or, if the model key is not provided,\n * all entities in the domain.\n *\n * @param parent The key of the parent data model.\n * @returns A generator that yields each `DomainEntity`.\n * @example\n * ```typescript\n * for (const entity of dataDomain.listEntities('userModel')) {\n * console.log(entity.key);\n * }\n * ```\n */\n *listEntities(parent?: string): Generator<DomainEntity> {\n const iterator = parent ? this.graph.children(parent) : this.graph.nodes()\n for (const node of iterator) {\n const value = this.graph.node(node) as DomainGraphNodeType\n if (value.kind === DomainEntityKind && value.domain.key === this.key) {\n yield value\n }\n }\n }\n\n /**\n * Lists all entities in the graph that are not part of this domain.\n */\n *listForeignEntities(): Generator<DomainEntity> {\n for (const node of this.graph.nodes()) {\n const value = this.graph.node(node) as DomainGraphNodeType\n if (value.kind === DomainEntityKind && value.domain.key !== this.key) {\n yield value\n }\n }\n }\n\n /**\n * Finds an entity by its key.\n *\n * @param key The key of the entity to find.\n * @returns The entity instance or undefined if not found.\n * @example\n * ```typescript\n * const entity = dataDomain.findEntity('user');\n * if (entity) {\n * console.log(entity.key);\n * }\n * ```\n */\n findEntity(key: string): DomainEntity | undefined {\n const node = this.graph.node(key) as DomainEntity | undefined\n if (node && node.kind === DomainEntityKind) {\n return node\n }\n return undefined\n }\n\n /**\n * Moves an entity from one model to another.\n *\n * @param entityKey The key of the entity to move.\n * @param sourceModelKey The key of the source model.\n * @param targetModelKey The key of the target model.\n * @throws Error When the entity, source model, or target model does not exist.\n * @throws Error When the entity is not in the same domain.\n * @throws Error When the source and target models are the same.\n * @throws Error When moving to an unsupported object.\n */\n moveEntity(entityKey: string, sourceModelKey: string, targetModelKey: string): void {\n if (sourceModelKey === targetModelKey) {\n throw new Error(`Cannot move an entity to the same model`)\n }\n if (!this.graph.hasNode(entityKey)) {\n throw new Error(`Entity ${entityKey} does not exist`)\n }\n if (!this.graph.hasNode(sourceModelKey)) {\n throw new Error(`Source model ${sourceModelKey} does not exist`)\n }\n if (!this.graph.hasNode(targetModelKey)) {\n throw new Error(`Target model ${targetModelKey} does not exist`)\n }\n\n const entity = this.findEntity(entityKey)\n const sourceModel = this.findModel(sourceModelKey)\n const targetModel = this.findModel(targetModelKey)\n\n if (!entity || !sourceModel || !targetModel) {\n throw new Error(`Entity or models not found in the graph`)\n }\n\n if (entity.domain.key !== this.key) {\n // this also applied to the parent model.\n throw new Error(`Cannot move an entity from a foreign domain`)\n }\n if (targetModel.domain.key !== this.key) {\n throw new Error(`Cannot move an entity to a foreign domain`)\n }\n // The target model detaches the entity when attaching to self.\n targetModel.attachEntity(entityKey)\n this.notifyChange()\n }\n\n /**\n * Adds an association between two entities.\n *\n * This function is a shortcut that finds the entity and\n * calls the `addAssociation` method on it.\n *\n * @param source The key of the source entity.\n * @param init The association options.\n * @returns The created association.\n * @throws Error When the source entity does not exist.\n * @example\n * ```typescript\n * const addressAssociation = dataDomain.addAssociation(\n * 'user', { key: 'address' }\n * );\n * ```\n */\n addAssociation(source: string, init?: AssociationAddOptions): DomainAssociation {\n if (!this.graph.hasNode(source)) {\n throw new Error(`Source entity ${source} not found`)\n }\n const entity = this.findEntity(source)\n if (!entity) {\n throw new Error(`Source entity ${source} not found`)\n }\n if (entity.domain.key !== this.key) {\n throw new Error(`Cannot add an association to a foreign domain`)\n }\n return entity.addAssociation(init)\n }\n\n /**\n * Removes an association from the graph.\n *\n * @param key The key of the association to remove.\n * @returns The current DataDomain instance.\n * @throws Error When the association does not exist or\n * when the parent entity is not found.\n * @example\n * ```typescript\n * dataDomain.removeAssociation('address');\n * ```\n */\n removeAssociation(key: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Association ${key} does not exist`)\n }\n const instance = this.graph.node(key) as DomainAssociation\n if (!instance || instance.kind !== DomainAssociationKind) {\n throw new Error(`Association ${key} not found`)\n }\n const entity = instance.getParentInstance()\n if (!entity) {\n throw new Error(`Parent entity not found for association ${key}`)\n }\n if (entity.domain.key !== this.key) {\n throw new Error(`Cannot remove an association from a foreign domain`)\n }\n entity.removeAssociation(key)\n return this\n }\n\n /**\n * Finds an association by its key.\n *\n * @param key The key of the association to find.\n * @returns The association instance or undefined if not\n * found.\n * @example\n * ```typescript\n * const assoc = dataDomain.findAssociation('address');\n * if (assoc) {\n * console.log(assoc.key);\n * }\n * ```\n */\n findAssociation(key: string): DomainAssociation | undefined {\n const node = this.graph.node(key) as DomainAssociation | undefined\n if (node && node.kind === DomainAssociationKind) {\n return node\n }\n return undefined\n }\n\n /**\n * Adds a property to an entity.\n *\n * @param parent The key of the parent entity.\n * @param property The partial property schema.\n * @returns The created property instance.\n * @throws Error When the parent does not exist or is not\n * an entity.\n * @example\n * ```typescript\n * const nameProperty = dataDomain.addProperty(\n * 'user', { key: 'name', type: 'string' }\n * );\n * ```\n */\n addProperty(parent: string, property?: Partial<DomainPropertySchema>): DomainProperty {\n if (!parent) {\n throw new Error(`A property expects a DomainEntity parent`)\n }\n if (!this.graph.hasNode(parent)) {\n throw new Error(`Parent entity ${parent} does not exist`)\n }\n const entity = this.findEntity(parent)\n if (!entity) {\n throw new Error(`Parent entity ${parent} not found`)\n }\n if (entity.domain.key !== this.key) {\n throw new Error(`Cannot add a property to a foreign domain`)\n }\n return entity.addProperty(property)\n }\n\n /**\n * Removes a property from the graph.\n *\n * @param key The key of the property to remove.\n * @returns The current DataDomain instance.\n * @throws Error When the property does not exist or when\n * the parent entity is not found.\n * @example\n * ```typescript\n * dataDomain.removeProperty('name');\n * ```\n */\n removeProperty(key: string): this {\n if (!this.graph.hasNode(key)) {\n throw new Error(`Property ${key} does not exist`)\n }\n const instance = this.graph.node(key) as DomainProperty\n if (!instance || instance.kind !== DomainPropertyKind) {\n throw new Error(`Property ${key} not found`)\n }\n const entity = instance.getParentInstance()\n if (!entity) {\n throw new Error(`Parent entity not found for property ${key}`)\n }\n if (entity.domain.key !== this.key) {\n throw new Error(`Cannot remove a property from a foreign domain`)\n }\n entity.removeProperty(key)\n return this\n }\n\n /**\n * Finds a property by its key.\n *\n * @param key The key of the property to find.\n * @returns The property instance or undefined if not\n * found.\n * @example\n * ```typescript\n * const prop = dataDomain.findProperty('name');\n * if (prop) {\n * console.log(prop.key);\n * }\n * ```\n */\n findProperty(key: string): DomainProperty | undefined {\n const node = this.graph.node(key) as DomainProperty | undefined\n if (node && node.kind === DomainPropertyKind) {\n return node\n }\n return undefined\n }\n\n /**\n * Registers a foreign DataDomain.\n *\n * @param domain The foreign DataDomain instance.\n * @param key The unique identifier for the foreign\n * domain.\n * @param version The version of the foreign domain.\n * @throws Error When a foreign domain with the same key is already registered.\n * @example\n * ```typescript\n * dataDomain.registerForeignDomain(\n * foreignDomain, 'foreignDomain', '1.0.0'\n * );\n * ```\n */\n registerForeignDomain(domain: DataDomain): void {\n const { info, key } = domain\n if (!info.version) {\n // @TODO: make the data domain immutable after a version is set.\n // This will prevent the user from changing the version\n // after the domain is registered.\n throw new Error(`Foreign domain ${key} does not have a version set`)\n }\n if (this.dependencies.has(key)) {\n throw new Error(`Foreign domain with key ${key} already registered`)\n }\n this.dependencies.set(key, domain)\n this.dependencyList.push({ key, version: info.version })\n // Copy the relevant parts of the foreign domain's graph into the local graph.\n // this.copyForeignDomainGraph(domain)\n mergeGraph(this.graph, domain.graph, domain.key)\n this.notifyChange()\n }\n\n /**\n * Un-registers a foreign DataDomain. It removes all defined by the foreign domain\n * information from the graph.\n * @param key The key of the foreign domain to unregister.\n */\n unregisterForeignDomain(key: string): void {\n const foreignDomain = this.dependencies.get(key)\n if (!foreignDomain) {\n throw new Error(`Foreign domain with key ${key} not found`)\n }\n this.dependencies.delete(key)\n this.dependencyList = this.dependencyList.filter((dependency) => dependency.key !== key)\n // Remove the foreign domain's nodes from the local graph.\n removeForeignGraph(this.graph, foreignDomain.key)\n this.notifyChange()\n }\n\n /**\n * Finds an entity in a foreign domain.\n *\n * @param entityKey The key of the entity to find.\n * @param domainKey The key of the foreign domain.\n * @returns The entity instance or undefined if not\n * found.\n * @example\n * ```typescript\n * const foreignUser = dataDomain.findForeignEntity(\n * 'user', 'foreignDomain'\n * );\n * if (foreignUser) {\n * console.log(foreignUser.key);\n * }\n * ```\n */\n findForeignEntity(entityKey: string, domainKey: string): DomainEntity | undefined {\n const foreignDomain = this.dependencies.get(domainKey)\n if (!foreignDomain) {\n return undefined\n }\n const foreignKey = `${domainKey}:${entityKey}`\n const node = this.graph.node(foreignKey)\n if (node && node.kind === DomainEntityKind) {\n return node as DomainEntity\n }\n return undefined\n }\n\n /**\n * A convenience function to remove an object from the\n * namespace.\n *\n * @param key The key of the object to remove.\n * @param kind The kind of the object to remove.\n * @throws Error when the kind is not known.\n * @example\n * ```typescript\n * dataDomain.removeDomainElement('user', DomainEntityKind);\n * ```\n */\n removeDomainElement(key: string, kind: string): void {\n switch (kind) {\n case DomainNamespaceKind:\n this.removeNamespace(key)\n break\n case DomainModelKind:\n this.removeModel(key)\n break\n case DomainEntityKind:\n this.removeEntity(key)\n break\n case DomainPropertyKind:\n this.removeProperty(key)\n break\n case DomainAssociationKind:\n this.removeAssociation(key)\n break\n default:\n throw new Error(`Unknown kind ${kind} for the object ${key}`)\n }\n }\n}\n"]}
|
|
@@ -150,7 +150,7 @@ let DomainEntity = (() => {
|
|
|
150
150
|
*/
|
|
151
151
|
static createSchema(input = {}) {
|
|
152
152
|
const { key = nanoid(), tags, semantics, fields, deprecated } = input;
|
|
153
|
-
const info = Thing.fromJSON(input.info, { name: '
|
|
153
|
+
const info = Thing.fromJSON(input.info, { name: 'new_entity' }).toJSON();
|
|
154
154
|
const result = {
|
|
155
155
|
kind: DomainEntityKind,
|
|
156
156
|
key,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomainEntity.js","sourceRoot":"","sources":["../../../src/modeling/DomainEntity.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAChG,OAAO,EAAE,aAAa,EAA4B,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,EAA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,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;YAC5B,CAAC;QACH,CAAC;QAED;;;;WAIG;QACH,WAAW,CAAC,UAAwB;YAClC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAA;QACxD,CAAC;;;SApvBU,YAAY","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainAssociationKind, DomainEntityKind, DomainPropertyKind } from '../models/kinds.js'\nimport { DomainElement, type DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { observed, retargetChange, toRaw } from './observed.js'\nimport type { IShapeUnion } from '../amf/definitions/Shapes.js'\nimport { DomainProperty, type DomainPropertySchema } from './DomainProperty.js'\nimport { RemovePropertyException } from '../exceptions/remove_property_exception.js'\nimport { DomainAssociation, DomainAssociationSchema } from './DomainAssociation.js'\nimport type { AssociationAddOptions } from './types.js'\nimport type { FileBreadcrumb } from '../models/store/File.js'\nimport type { DomainModel } from './DomainModel.js'\nimport type { DomainNamespace } from './DomainNamespace.js'\nimport { ValidationError } from '../exceptions/validation_error.js'\nimport { ShapeGenerator } from './amf/ShapeGenerator.js'\nimport type { IShapeRenderOptions } from '../amf/shape/ShapeBase.js'\nimport { ApiSchemaGenerator } from '../amf/ApiSchemaGenerator.js'\nimport { removeGraphNode } from './GraphUtils.js'\nimport { DataSemantics, isEntitySemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'\n\nexport interface EntityOrderedItem {\n /**\n * The type of the ordered item.\n */\n type: 'property' | 'association'\n\n /**\n * The key of the ordered item.\n */\n key: string\n}\n\nexport interface DomainEntitySchema extends DomainElementSchema {\n kind: typeof DomainEntityKind\n /**\n * The domain entity description.\n */\n info: IThing\n\n /**\n * Optional general purpose tags for the UI.\n */\n tags?: string[]\n\n /**\n * The semantics applied to this entity.\n * This is a list of applied semantics that can be used to\n * describe the entity in more detail.\n */\n semantics?: AppliedDataSemantic[]\n\n /**\n * The ordered list of fields (properties and associations) in the schema.\n * These only keep references to the properties and associations.\n * The order of the fields is important as it defines the order of the\n * properties in the schema.\n */\n fields?: EntityOrderedItem[]\n\n /**\n * Whether this entity is deprecated.\n */\n deprecated?: boolean\n}\n\n/**\n * Represents an entity within a data domain model.\n *\n * A `DomainEntity` defines a structured data type,\n * containing properties and associations. It's a\n * fundamental building block for modeling complex data\n * structures.\n *\n * **Key Features:**\n *\n * - **Properties:** Defines the data elements (fields) within the entity.\n * - **Associations:** Defines relationships to other entities.\n * - **Inheritance:** Supports inheriting properties and associations from parent entities.\n * - **Metadata:** Supports tags, semantics, and deprecation status.\n * - **AMF Shape Generation:** Can be serialized to an AMF (API Modeling Framework) shape.\n * - **Example Generation:** Can generate example databased on its schema.\n *\n * **Usage:**\n *\n * The preferred way to create a `DomainEntity` is through\n * the `DomainModel.addEntity()` method.\n *\n * **Example:**\n *\n * ```typescript\n * const dataDomain = new DataDomain();\n * const userModel = dataDomain.addModel({ key: 'userModel' });\n * const userEntity = userModel.addEntity({ key: 'user' });\n * ```\n *\n * Entity Validation Rules:\n *\n * - **Primary Key:** An entity must have a primary key selected. This can come from a parent\n * entity or be defined in the current entity.\n * - **Parent Entity:** The parent entity must exist in the graph.\n * - **Circular Dependency:** Adding a parent entity that creates a circular dependency is not allowed.\n * - **Unique Parent:** An entity cannot have the same parent more than once.\n * - **Property Shadowing:** A property can shadow a parent property. This means that if a property\n * with the same key exists in both the parent and child entity, the child property will take precedence.\n * - **Association Shadowing:** An association can shadow a parent association. This means that if an\n * association with the same key exists in both the parent and child entity,\n * the child association will take precedence.\n * - **Property Resolution:** When the same property exists more than one parent and the child entity,\n * doesn't explicitly define the property, then:\n * - The last parent entity (iterating from the first entity to the last) that has the property\n * will be used as the source of the property.\n * - **Association Resolution:** When the same association exists more than one parent and the child entity,\n * doesn't explicitly define the association, then:\n * - The last parent entity (iterating from the first entity to the last) that has the association\n * will be used as the source of the association.\n * - **Minimum Required Properties:** An entity must have at least one property defined. Entities without properties\n * are ignored in the system.\n * - **Entity Name**:\n * - An entity must have a name defined.\n * - The name has to follow the same rules as the names in a SQL database. This means that the name must be unique\n * within the data domain and cannot contain special characters.\n * - **Association Targets:** An association must have a target entity defined.\n * This means that the association must point to at least one entity.\n */\nexport class DomainEntity extends DomainElement {\n /**\n * The kind of the domain element.\n */\n override kind: typeof DomainEntityKind\n\n /**\n * The description of the domain entity.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * Optional general purpose tags for the UI.\n */\n @observed({ deep: true }) accessor tags: string[]\n\n /**\n * Semantics applied to this property.\n */\n @observed({ deep: true }) accessor semantics: AppliedDataSemantic[] = []\n\n /**\n * The ordered list of fields (properties and associations) in the schema.\n * These only keep references to the properties and associations.\n * The order of the fields is important as it defines the order of the\n * properties in the schema.\n */\n accessor fields: EntityOrderedItem[]\n\n /**\n * Whether this entity is deprecated.\n */\n @observed() accessor deprecated: boolean | undefined\n\n /**\n * Creates a full data entity schema with defaults.\n *\n * @param input The partial data entity schema.\n * @returns The data entity schema.\n */\n static createSchema(input: Partial<DomainEntitySchema> = {}): DomainEntitySchema {\n const { key = nanoid(), tags, semantics, fields, deprecated } = input\n const info = Thing.fromJSON(input.info, { name: 'New entity' }).toJSON()\n const result: DomainEntitySchema = {\n kind: DomainEntityKind,\n key,\n info,\n }\n if (Array.isArray(tags)) {\n result.tags = [...tags]\n }\n if (Array.isArray(semantics)) {\n result.semantics = [...semantics]\n }\n if (Array.isArray(fields)) {\n result.fields = [...fields]\n }\n if (typeof deprecated === 'boolean') {\n result.deprecated = deprecated\n }\n return result\n }\n\n /**\n * Creates a new domain entity instance.\n *\n * You probably want to use the `DomainModel.addEntity()`\n * method instead.\n *\n * @param root A reference to the root DataDomain instance.\n * @param input The partial domain entity schema.\n */\n constructor(root: DataDomain, input?: Partial<DomainEntitySchema>) {\n const init = DomainEntity.createSchema(input)\n super(root, init.key)\n this.kind = DomainEntityKind\n this.info = new Thing(init.info)\n if (Array.isArray(init.tags)) {\n this.tags = [...init.tags]\n } else {\n this.tags = []\n }\n if (Array.isArray(init.semantics)) {\n this.semantics = init.semantics.map((item) => structuredClone(item))\n } else {\n this.semantics = []\n }\n if (Array.isArray(init.fields)) {\n this.fields = [...init.fields]\n } else {\n this.fields = []\n }\n if (typeof init.deprecated === 'boolean') {\n this.deprecated = init.deprecated\n }\n }\n\n /**\n * Generates a JSON representation of the entity.\n *\n * @returns A plain object representation of the `DomainEntity`.\n */\n toJSON(): DomainEntitySchema {\n const result: DomainEntitySchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (Array.isArray(this.fields) && this.fields.length) {\n result.fields = [...this.fields]\n }\n if (Array.isArray(this.semantics) && this.semantics.length) {\n result.semantics = toRaw(this, this.semantics)?.map((i) => structuredClone(i))\n }\n if (Array.isArray(this.tags) && this.tags.length) {\n result.tags = [...(toRaw(this, this.tags) as string[])]\n }\n if (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n return result\n }\n\n /**\n * Returns a parent data entity where this data property\n * exist.\n *\n * @returns The parent `DomainModel` or undefined if not found.\n * @example\n * ```typescript\n * const parent = entity.getParentInstance();\n * if (parent) {\n * console.log(parent.key);\n * }\n * ```\n */\n getParentInstance(): DomainModel | undefined {\n const parentKey = this.root.graph.parent(this.key)\n if (!parentKey) {\n return undefined\n }\n return this.root.graph.node(parentKey) as DomainModel | undefined\n }\n\n /**\n * Adds a property to this entity.\n *\n * @param property The partial property schema.\n * @returns The created `DomainProperty` instance.\n * @example\n * ```typescript\n * const property = entity.addProperty({\n * key: 'name',\n * type: 'string',\n * required: true,\n * })\n * ```\n */\n addProperty(property?: Partial<DomainPropertySchema>): DomainProperty {\n if (property && property.key && this.root.graph.hasNode(property.key)) {\n throw new Error(`Trying to add a property ${property.key}, but it already exists`)\n }\n const instance = new DomainProperty(this.root, this.key, property)\n this.root.graph.setNode(instance.key, instance)\n this.root.graph.setEdge(this.key, instance.key, { type: 'property' })\n this.fields.push({\n type: 'property',\n key: instance.key,\n })\n this.root.notifyChange()\n return instance\n }\n\n /**\n * Removes a property from this entity.\n *\n * @param key The key of the property to remove.\n * @throws {RemovePropertyException} When the property does not exist.\n * @example\n * ```typescript\n * entity.removeProperty('name')\n * ```\n */\n removeProperty(key: string): void {\n if (!this.root.graph.hasNode(key)) {\n throw new RemovePropertyException(`Trying to remove the ${key} property, but it doesn't exist`)\n }\n const prop = this.root.graph.node(key) as DomainProperty\n if (prop.getParentInstance() !== this) {\n throw new RemovePropertyException(`Trying to remove the ${key} property, but it doesn't belong to this entity`)\n }\n removeGraphNode(this.root.graph, key)\n this.removeField(key)\n this.root.notifyChange()\n }\n\n /**\n * A shortcut to `listProperties()`.\n */\n get properties(): Generator<DomainProperty> {\n return this.listProperties()\n }\n\n /**\n * Lists all properties of this entity.\n *\n * Note, it accounts for the order of the properties as\n * defined in the `fields` array.\n *\n * @returns A generator that yields each `DomainProperty`.\n * @example\n * ```typescript\n * for (const property of entity.listProperties()) {\n * console.log(property.key);\n * }\n * ```\n */\n *listProperties(): Generator<DomainProperty> {\n for (const { key, type } of this.fields) {\n if (type !== 'property') {\n continue\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainPropertyKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this entity has any properties.\n *\n * @returns True if the entity has properties.\n * @example\n * ```typescript\n * if (entity.hasProperties()) {\n * // ...\n * }\n * ```\n */\n hasProperties(): boolean {\n return this.fields.some((item) => item.type === 'property')\n }\n\n /**\n * A shortcut to `listParents()`.\n */\n get parents(): Generator<DomainEntity> {\n return this.listParents()\n }\n\n /**\n * Lists all parent entities of this entity.\n *\n * @returns A generator that yields each parent `DomainEntity`.\n * @example\n * ```typescript\n * for (const parent of entity.listParents()) {\n * console.log(parent.key);\n * }\n * ```\n */\n *listParents(): Generator<DomainEntity> {\n for (const edge of this.root.graph.outEdges(this.key)) {\n const value = this.root.graph.edge(edge)\n if (!value || value.type !== 'parent') {\n continue\n }\n const parent = this.root.graph.node(edge.w) as DomainEntity\n if (parent) {\n yield parent\n }\n }\n }\n\n /**\n * Adds a parent to this entity.\n *\n * @param key The key of the parent entity.\n * @param domain The key of the foreign domain the parent belongs to.\n * @returns `this` for chaining.\n * @throws ValidationError When the parent does not exist or a circular dependency is detected.\n * @example\n * ```typescript\n * entity.addParent('baseEntity');\n * ```\n */\n addParent(key: string, domain?: string): this {\n const effectiveKey = domain ? `${domain}:${key}` : key\n // Prevent adding self as parent\n if (effectiveKey === this.key) {\n const message = 'Entity cannot be a parent of itself'\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'circular',\n },\n ],\n { message }\n )\n }\n const { graph } = this.root\n if (!graph.hasNode(effectiveKey)) {\n let message = `Entity with key \"${key}\" not found`\n if (domain) {\n message += ` in domain \"${domain}\"`\n }\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'required',\n },\n ],\n { message }\n )\n }\n // Check for circular inheritance\n if (this.hasCircularParent(effectiveKey)) {\n const message = `Circular inheritance detected. Cannot add ${key} as a parent`\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'circular',\n },\n ],\n { message }\n )\n }\n if (graph.outEdges(this.key, effectiveKey).next().value) {\n const message = `Parent ${key} already exists`\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'unique',\n },\n ],\n { message }\n )\n }\n // Parents are associated through graph edges.\n // Otherwise it would collide with the parent model.\n if (domain) {\n graph.setEdge(this.key, effectiveKey, { type: 'parent', domain, foreign: true })\n } else {\n graph.setEdge(this.key, effectiveKey, { type: 'parent' })\n }\n this.root.notifyChange()\n return this\n }\n\n /**\n * Removes a parent from this entity.\n *\n * @param key The key of the parent entity to remove.\n * @returns `this` for chaining.\n * @throws Error When the parent does not exist.\n * @example\n * ```typescript\n * entity.removeParent('baseEntity');\n * ```\n */\n removeParent(key: string): this {\n const { graph } = this.root\n if (!graph.hasEdge(this.key, key)) {\n throw new Error(`Trying to remove a parent ${key} from ${this.key}, but it doesn't exist`)\n }\n graph.removeEdge(this.key, key)\n this.root.notifyChange()\n return this\n }\n\n /**\n * Checks if this entity has any parents.\n *\n * @returns True if the entity has parents.\n * @example\n * ```typescript\n * if (entity.hasParents()) {\n * // ...\n * }\n * ```\n */\n hasParents(): boolean {\n for (const edge of this.root.graph.outEdges(this.key)) {\n if (this.root.graph.edge(edge)?.type === 'parent') {\n return true\n }\n }\n return false\n }\n\n /**\n * Checks if the passed entity has a circular parent\n * relationship when attempting to add a new parent.\n *\n * @param key The key of the parent being added.\n * @returns True if adding this parent would create a\n * circular relationship.\n */\n hasCircularParent(key: string): boolean {\n const { graph } = this.root\n\n // Check if new parent is one of the children.\n for (const edge of graph.outEdges(key, this.key)) {\n if (graph.edge(edge)?.type === 'parent') {\n return true\n }\n }\n\n // check if this entity is in parents chain.\n let current: DomainEntity | undefined = graph.node(key) as DomainEntity | undefined\n while (current) {\n if (current.key === this.key) {\n return true\n }\n const parents = [...current.listParents()]\n if (parents.length === 0) {\n break\n }\n // Assuming single inheritance\n // TODO: Update this to check for multiple parents.\n current = parents[0]\n }\n\n return false\n }\n\n /**\n * Creates breadcrumbs from this entity to the root\n * namespace.\n *\n * @returns An array of `FileBreadcrumb` instances.\n * @example\n * ```typescript\n * const breadcrumbs = entity.breadcrumbs();\n * console.log(breadcrumbs);\n * ```\n */\n breadcrumbs(): FileBreadcrumb[] {\n const result: FileBreadcrumb[] = []\n result.push({\n key: this.key,\n name: this.info.getLabel('Unnamed entity'),\n kind: DomainEntityKind,\n })\n const model = this.getParentInstance()\n if (model) {\n result.push({\n key: model.key,\n kind: model.kind,\n name: model.info.getLabel('Unnamed model'),\n })\n let parent: DataDomain | DomainNamespace = model.getParentInstance()\n while (parent && parent !== this.root) {\n result.push({\n key: parent.key,\n kind: parent.kind,\n name: parent.info.getLabel('Unnamed namespace'),\n })\n const typed = parent as DomainNamespace\n parent = typed.getParentInstance()\n }\n }\n result.push({\n key: this.root.key,\n name: this.root.info.getLabel('Unnamed data domain'),\n kind: this.root.kind,\n })\n return result.reverse()\n }\n\n /**\n * Adds an association to this entity.\n *\n * @param init The association options.\n * @param input The partial association schema.\n * @returns The created `DomainAssociation` instance.\n * @throws Error When the target entity does not exist.\n * @example\n * ```typescript\n * const association = entity.addAssociation({\n * key: 'address',\n * });\n * ```\n */\n addAssociation(init: AssociationAddOptions = {}, input?: Partial<DomainAssociationSchema>): DomainAssociation {\n const { graph } = this.root\n if (init.domain && init.key) {\n // target is foreign\n const foreignKey = `${init.domain}:${init.key}`\n if (!graph.hasNode(foreignKey)) {\n throw new Error(`Foreign entity ${foreignKey} not found`)\n }\n } else if (init.key) {\n if (!graph.hasNode(init.key)) {\n throw new Error(`Target entity ${init.key} not found`)\n }\n }\n const item = new DomainAssociation(this.root, this.key, input)\n graph.setNode(item.key, item)\n graph.setEdge(this.key, item.key, { type: 'association' })\n if (init.key) {\n item.addTarget(init.key, init.domain)\n }\n this.fields.push({ type: 'association', key: item.key })\n this.root.notifyChange()\n return item\n }\n\n /**\n * Removes an association from this entity.\n *\n * @param key The key of the association to remove.\n * @throws Error When the association does not exist.\n * @example\n * ```typescript\n * entity.removeAssociation('address');\n * ```\n */\n removeAssociation(key: string): void {\n if (!this.root.graph.hasEdge(this.key, key)) {\n throw new Error(`Unable to find a connection between this entity and the ${key} association`)\n }\n const edge = this.root.graph.edge(this.key, key)\n if (!edge || edge.type !== 'association') {\n throw new Error(`Association ${key} does not exist`)\n }\n removeGraphNode(this.root.graph, key)\n this.removeField(key)\n this.root.notifyChange()\n }\n\n /**\n * A shortcut to `listAssociations()`.\n */\n get associations(): Generator<DomainAssociation> {\n return this.listAssociations()\n }\n\n /**\n * Lists all associations of this entity.\n *\n * The order of the associations is defined in the `fields` array.\n *\n * @returns A generator that yields each\n * `DomainAssociation`.\n * @example\n * ```typescript\n * for (const association of entity.listAssociations()) {\n * console.log(association.key);\n * }\n * ```\n */\n *listAssociations(): Generator<DomainAssociation> {\n for (const { key, type } of this.fields) {\n if (type !== 'association') {\n continue\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainAssociationKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this entity has any associations.\n *\n * @returns True if the entity has associations.\n * @example\n * ```typescript\n * if (entity.hasAssociations()) {\n * // ...\n * }\n * ```\n */\n hasAssociations(): boolean {\n return this.fields.some((item) => item.type === 'association')\n }\n\n /**\n * Lists all fields (properties and associations) of this entity.\n *\n * @returns A generator that yields each `DomainAssociation` or `DomainProperty`.\n * @example\n * ```typescript\n * for (const field of entity.listFields()) {\n * console.log(field.key);\n * }\n * ```\n */\n *listFields(): Generator<DomainAssociation | DomainProperty> {\n for (const { key } of this.fields) {\n const node = this.root.graph.node(key)\n if (!node) {\n continue\n }\n if (node.kind === DomainAssociationKind || node.kind === DomainPropertyKind) {\n yield node\n }\n }\n }\n\n /**\n * Checks if this entity has any fields (properties or associations).\n *\n * @returns True if the entity has fields.\n * @example\n * ```typescript\n * if (entity.hasFields()) {\n * // ...\n * }\n * ```\n */\n hasFields(): boolean {\n return this.fields.length > 0\n }\n\n private removeField(key: string): void {\n this.fields = this.fields.filter((item) => item.key !== key)\n }\n\n /**\n * Creates an AMF's data Shape.\n *\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(): IShapeUnion {\n const serializer = new ShapeGenerator()\n return serializer.entity(this)\n }\n\n /**\n * Reads the schema of the Entity and generates an example for it.\n *\n * @param mime The mime type of the example.\n * @param opts The example generation options.\n * @returns The generated example.\n * @example\n * ```typescript\n * const example = entity.toExample('application/json');\n * console.log(example);\n * ```\n */\n toExample(mime: string, opts: IShapeRenderOptions = {}): string | number | boolean | null | undefined {\n const shape = this.toApiShape()\n const generator = new ApiSchemaGenerator(mime, {\n renderExamples: typeof opts.renderExamples === 'boolean' ? opts.renderExamples : true,\n renderMocked: typeof opts.renderMocked === 'boolean' ? opts.renderMocked : true,\n renderOptional: typeof opts.renderOptional === 'boolean' ? opts.renderOptional : true,\n selectedUnions: opts.selectedUnions,\n })\n return generator.generate(shape)\n }\n\n /**\n * Checks whether the entity is a child of the given namespace or data model.\n * The relationship doesn't have to be direct, as long as the entity\n * is in the hierarchy it will return true.\n *\n * @param key The key of the parent to check.\n * @returns True if this entity is a child of the given namespace or data model.\n */\n isChildOf(key: string): boolean {\n if (this.key === key) {\n return false\n }\n const parent = this.getParentInstance()\n if (!parent) {\n return false\n }\n if (parent.key === key) {\n return true\n }\n return parent.isChildOf(key)\n }\n\n /**\n * Finds the primary key property of this entity.\n * @returns The primary key property of this entity or undefined if not found.\n */\n primaryKey(): DomainProperty | undefined {\n for (const property of this.properties) {\n if (property.primary) {\n return property\n }\n }\n let property: DomainProperty | undefined\n for (const parent of this.listParents()) {\n const prop = parent.primaryKey()\n if (prop) {\n // According to the validation rules, the last parent\n // that has the property will be used as the source of\n // the property.\n // In the future, we may add a schema definition to the entity that\n // will explicitly define which property to use.\n property = prop\n }\n }\n return property\n }\n\n /**\n * Adds or updates a semantic to the entity.\n * @param semantic The semantic to add to the entity.\n * @throws Error if the semantic is not an entity semantic.\n */\n addSemantic(semantic: AppliedDataSemantic): void {\n const sem = DataSemantics[semantic.id]\n if (!isEntitySemantic(sem)) {\n throw new Error(`Invalid semantic type: ${semantic.id}. Expected an entity semantic.`)\n }\n const index = this.semantics.findIndex((s) => s.id === semantic.id)\n if (index >= 0) {\n this.semantics[index] = semantic\n } else {\n this.semantics.push(semantic)\n }\n this.domain.notifyChange()\n }\n\n /**\n * Removes a semantic from the entity.\n * @param semanticId The ID of the semantic to remove.\n */\n removeSemantic(semanticId: SemanticType): void {\n const index = this.semantics.findIndex((s) => s.id === semanticId)\n if (index >= 0) {\n this.semantics.splice(index, 1)\n this.domain.notifyChange()\n }\n }\n\n /**\n * Checks if the entity has a specific semantic.\n * @param semanticId The ID of the semantic to check.\n * @returns True if the semantic is present, false otherwise.\n */\n hasSemantic(semanticId: SemanticType): boolean {\n return this.semantics.some((s) => s.id === semanticId)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DomainEntity.js","sourceRoot":"","sources":["../../../src/modeling/DomainEntity.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAChG,OAAO,EAAE,aAAa,EAA4B,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,EAAE,cAAc,EAA6B,MAAM,qBAAqB,CAAA;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAA;AACpF,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAA;AAKnF,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAExD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAA+C,MAAM,gBAAgB,CAAA;AA+C7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;IACU,YAAY;sBAAS,aAAa;;;;;;;;;;;;;iBAAlC,YAAa,SAAQ,WAAa;;;gCAS5C,cAAc,EAAE;gCAKhB,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;qCAKxB,QAAQ,CAAC,EAA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ACnE,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAA;YAClC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YAC/B,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;QAC5B,CAAC;QAED;;;WAGG;QACH,cAAc,CAAC,UAAwB;YACrC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAA;YAClE,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBAC/B,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;YAC5B,CAAC;QACH,CAAC;QAED;;;;WAIG;QACH,WAAW,CAAC,UAAwB;YAClC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAA;QACxD,CAAC;;;SApvBU,YAAY","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainAssociationKind, DomainEntityKind, DomainPropertyKind } from '../models/kinds.js'\nimport { DomainElement, type DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { observed, retargetChange, toRaw } from './observed.js'\nimport type { IShapeUnion } from '../amf/definitions/Shapes.js'\nimport { DomainProperty, type DomainPropertySchema } from './DomainProperty.js'\nimport { RemovePropertyException } from '../exceptions/remove_property_exception.js'\nimport { DomainAssociation, DomainAssociationSchema } from './DomainAssociation.js'\nimport type { AssociationAddOptions } from './types.js'\nimport type { FileBreadcrumb } from '../models/store/File.js'\nimport type { DomainModel } from './DomainModel.js'\nimport type { DomainNamespace } from './DomainNamespace.js'\nimport { ValidationError } from '../exceptions/validation_error.js'\nimport { ShapeGenerator } from './amf/ShapeGenerator.js'\nimport type { IShapeRenderOptions } from '../amf/shape/ShapeBase.js'\nimport { ApiSchemaGenerator } from '../amf/ApiSchemaGenerator.js'\nimport { removeGraphNode } from './GraphUtils.js'\nimport { DataSemantics, isEntitySemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'\n\nexport interface EntityOrderedItem {\n /**\n * The type of the ordered item.\n */\n type: 'property' | 'association'\n\n /**\n * The key of the ordered item.\n */\n key: string\n}\n\nexport interface DomainEntitySchema extends DomainElementSchema {\n kind: typeof DomainEntityKind\n /**\n * The domain entity description.\n */\n info: IThing\n\n /**\n * Optional general purpose tags for the UI.\n */\n tags?: string[]\n\n /**\n * The semantics applied to this entity.\n * This is a list of applied semantics that can be used to\n * describe the entity in more detail.\n */\n semantics?: AppliedDataSemantic[]\n\n /**\n * The ordered list of fields (properties and associations) in the schema.\n * These only keep references to the properties and associations.\n * The order of the fields is important as it defines the order of the\n * properties in the schema.\n */\n fields?: EntityOrderedItem[]\n\n /**\n * Whether this entity is deprecated.\n */\n deprecated?: boolean\n}\n\n/**\n * Represents an entity within a data domain model.\n *\n * A `DomainEntity` defines a structured data type,\n * containing properties and associations. It's a\n * fundamental building block for modeling complex data\n * structures.\n *\n * **Key Features:**\n *\n * - **Properties:** Defines the data elements (fields) within the entity.\n * - **Associations:** Defines relationships to other entities.\n * - **Inheritance:** Supports inheriting properties and associations from parent entities.\n * - **Metadata:** Supports tags, semantics, and deprecation status.\n * - **AMF Shape Generation:** Can be serialized to an AMF (API Modeling Framework) shape.\n * - **Example Generation:** Can generate example databased on its schema.\n *\n * **Usage:**\n *\n * The preferred way to create a `DomainEntity` is through\n * the `DomainModel.addEntity()` method.\n *\n * **Example:**\n *\n * ```typescript\n * const dataDomain = new DataDomain();\n * const userModel = dataDomain.addModel({ key: 'userModel' });\n * const userEntity = userModel.addEntity({ key: 'user' });\n * ```\n *\n * Entity Validation Rules:\n *\n * - **Primary Key:** An entity must have a primary key selected. This can come from a parent\n * entity or be defined in the current entity.\n * - **Parent Entity:** The parent entity must exist in the graph.\n * - **Circular Dependency:** Adding a parent entity that creates a circular dependency is not allowed.\n * - **Unique Parent:** An entity cannot have the same parent more than once.\n * - **Property Shadowing:** A property can shadow a parent property. This means that if a property\n * with the same key exists in both the parent and child entity, the child property will take precedence.\n * - **Association Shadowing:** An association can shadow a parent association. This means that if an\n * association with the same key exists in both the parent and child entity,\n * the child association will take precedence.\n * - **Property Resolution:** When the same property exists more than one parent and the child entity,\n * doesn't explicitly define the property, then:\n * - The last parent entity (iterating from the first entity to the last) that has the property\n * will be used as the source of the property.\n * - **Association Resolution:** When the same association exists more than one parent and the child entity,\n * doesn't explicitly define the association, then:\n * - The last parent entity (iterating from the first entity to the last) that has the association\n * will be used as the source of the association.\n * - **Minimum Required Properties:** An entity must have at least one property defined. Entities without properties\n * are ignored in the system.\n * - **Entity Name**:\n * - An entity must have a name defined.\n * - The name has to follow the same rules as the names in a SQL database. This means that the name must be unique\n * within the data domain and cannot contain special characters.\n * - **Association Targets:** An association must have a target entity defined.\n * This means that the association must point to at least one entity.\n */\nexport class DomainEntity extends DomainElement {\n /**\n * The kind of the domain element.\n */\n override kind: typeof DomainEntityKind\n\n /**\n * The description of the domain entity.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * Optional general purpose tags for the UI.\n */\n @observed({ deep: true }) accessor tags: string[]\n\n /**\n * Semantics applied to this property.\n */\n @observed({ deep: true }) accessor semantics: AppliedDataSemantic[] = []\n\n /**\n * The ordered list of fields (properties and associations) in the schema.\n * These only keep references to the properties and associations.\n * The order of the fields is important as it defines the order of the\n * properties in the schema.\n */\n accessor fields: EntityOrderedItem[]\n\n /**\n * Whether this entity is deprecated.\n */\n @observed() accessor deprecated: boolean | undefined\n\n /**\n * Creates a full data entity schema with defaults.\n *\n * @param input The partial data entity schema.\n * @returns The data entity schema.\n */\n static createSchema(input: Partial<DomainEntitySchema> = {}): DomainEntitySchema {\n const { key = nanoid(), tags, semantics, fields, deprecated } = input\n const info = Thing.fromJSON(input.info, { name: 'new_entity' }).toJSON()\n const result: DomainEntitySchema = {\n kind: DomainEntityKind,\n key,\n info,\n }\n if (Array.isArray(tags)) {\n result.tags = [...tags]\n }\n if (Array.isArray(semantics)) {\n result.semantics = [...semantics]\n }\n if (Array.isArray(fields)) {\n result.fields = [...fields]\n }\n if (typeof deprecated === 'boolean') {\n result.deprecated = deprecated\n }\n return result\n }\n\n /**\n * Creates a new domain entity instance.\n *\n * You probably want to use the `DomainModel.addEntity()`\n * method instead.\n *\n * @param root A reference to the root DataDomain instance.\n * @param input The partial domain entity schema.\n */\n constructor(root: DataDomain, input?: Partial<DomainEntitySchema>) {\n const init = DomainEntity.createSchema(input)\n super(root, init.key)\n this.kind = DomainEntityKind\n this.info = new Thing(init.info)\n if (Array.isArray(init.tags)) {\n this.tags = [...init.tags]\n } else {\n this.tags = []\n }\n if (Array.isArray(init.semantics)) {\n this.semantics = init.semantics.map((item) => structuredClone(item))\n } else {\n this.semantics = []\n }\n if (Array.isArray(init.fields)) {\n this.fields = [...init.fields]\n } else {\n this.fields = []\n }\n if (typeof init.deprecated === 'boolean') {\n this.deprecated = init.deprecated\n }\n }\n\n /**\n * Generates a JSON representation of the entity.\n *\n * @returns A plain object representation of the `DomainEntity`.\n */\n toJSON(): DomainEntitySchema {\n const result: DomainEntitySchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (Array.isArray(this.fields) && this.fields.length) {\n result.fields = [...this.fields]\n }\n if (Array.isArray(this.semantics) && this.semantics.length) {\n result.semantics = toRaw(this, this.semantics)?.map((i) => structuredClone(i))\n }\n if (Array.isArray(this.tags) && this.tags.length) {\n result.tags = [...(toRaw(this, this.tags) as string[])]\n }\n if (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n return result\n }\n\n /**\n * Returns a parent data entity where this data property\n * exist.\n *\n * @returns The parent `DomainModel` or undefined if not found.\n * @example\n * ```typescript\n * const parent = entity.getParentInstance();\n * if (parent) {\n * console.log(parent.key);\n * }\n * ```\n */\n getParentInstance(): DomainModel | undefined {\n const parentKey = this.root.graph.parent(this.key)\n if (!parentKey) {\n return undefined\n }\n return this.root.graph.node(parentKey) as DomainModel | undefined\n }\n\n /**\n * Adds a property to this entity.\n *\n * @param property The partial property schema.\n * @returns The created `DomainProperty` instance.\n * @example\n * ```typescript\n * const property = entity.addProperty({\n * key: 'name',\n * type: 'string',\n * required: true,\n * })\n * ```\n */\n addProperty(property?: Partial<DomainPropertySchema>): DomainProperty {\n if (property && property.key && this.root.graph.hasNode(property.key)) {\n throw new Error(`Trying to add a property ${property.key}, but it already exists`)\n }\n const instance = new DomainProperty(this.root, this.key, property)\n this.root.graph.setNode(instance.key, instance)\n this.root.graph.setEdge(this.key, instance.key, { type: 'property' })\n this.fields.push({\n type: 'property',\n key: instance.key,\n })\n this.root.notifyChange()\n return instance\n }\n\n /**\n * Removes a property from this entity.\n *\n * @param key The key of the property to remove.\n * @throws {RemovePropertyException} When the property does not exist.\n * @example\n * ```typescript\n * entity.removeProperty('name')\n * ```\n */\n removeProperty(key: string): void {\n if (!this.root.graph.hasNode(key)) {\n throw new RemovePropertyException(`Trying to remove the ${key} property, but it doesn't exist`)\n }\n const prop = this.root.graph.node(key) as DomainProperty\n if (prop.getParentInstance() !== this) {\n throw new RemovePropertyException(`Trying to remove the ${key} property, but it doesn't belong to this entity`)\n }\n removeGraphNode(this.root.graph, key)\n this.removeField(key)\n this.root.notifyChange()\n }\n\n /**\n * A shortcut to `listProperties()`.\n */\n get properties(): Generator<DomainProperty> {\n return this.listProperties()\n }\n\n /**\n * Lists all properties of this entity.\n *\n * Note, it accounts for the order of the properties as\n * defined in the `fields` array.\n *\n * @returns A generator that yields each `DomainProperty`.\n * @example\n * ```typescript\n * for (const property of entity.listProperties()) {\n * console.log(property.key);\n * }\n * ```\n */\n *listProperties(): Generator<DomainProperty> {\n for (const { key, type } of this.fields) {\n if (type !== 'property') {\n continue\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainPropertyKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this entity has any properties.\n *\n * @returns True if the entity has properties.\n * @example\n * ```typescript\n * if (entity.hasProperties()) {\n * // ...\n * }\n * ```\n */\n hasProperties(): boolean {\n return this.fields.some((item) => item.type === 'property')\n }\n\n /**\n * A shortcut to `listParents()`.\n */\n get parents(): Generator<DomainEntity> {\n return this.listParents()\n }\n\n /**\n * Lists all parent entities of this entity.\n *\n * @returns A generator that yields each parent `DomainEntity`.\n * @example\n * ```typescript\n * for (const parent of entity.listParents()) {\n * console.log(parent.key);\n * }\n * ```\n */\n *listParents(): Generator<DomainEntity> {\n for (const edge of this.root.graph.outEdges(this.key)) {\n const value = this.root.graph.edge(edge)\n if (!value || value.type !== 'parent') {\n continue\n }\n const parent = this.root.graph.node(edge.w) as DomainEntity\n if (parent) {\n yield parent\n }\n }\n }\n\n /**\n * Adds a parent to this entity.\n *\n * @param key The key of the parent entity.\n * @param domain The key of the foreign domain the parent belongs to.\n * @returns `this` for chaining.\n * @throws ValidationError When the parent does not exist or a circular dependency is detected.\n * @example\n * ```typescript\n * entity.addParent('baseEntity');\n * ```\n */\n addParent(key: string, domain?: string): this {\n const effectiveKey = domain ? `${domain}:${key}` : key\n // Prevent adding self as parent\n if (effectiveKey === this.key) {\n const message = 'Entity cannot be a parent of itself'\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'circular',\n },\n ],\n { message }\n )\n }\n const { graph } = this.root\n if (!graph.hasNode(effectiveKey)) {\n let message = `Entity with key \"${key}\" not found`\n if (domain) {\n message += ` in domain \"${domain}\"`\n }\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'required',\n },\n ],\n { message }\n )\n }\n // Check for circular inheritance\n if (this.hasCircularParent(effectiveKey)) {\n const message = `Circular inheritance detected. Cannot add ${key} as a parent`\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'circular',\n },\n ],\n { message }\n )\n }\n if (graph.outEdges(this.key, effectiveKey).next().value) {\n const message = `Parent ${key} already exists`\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'unique',\n },\n ],\n { message }\n )\n }\n // Parents are associated through graph edges.\n // Otherwise it would collide with the parent model.\n if (domain) {\n graph.setEdge(this.key, effectiveKey, { type: 'parent', domain, foreign: true })\n } else {\n graph.setEdge(this.key, effectiveKey, { type: 'parent' })\n }\n this.root.notifyChange()\n return this\n }\n\n /**\n * Removes a parent from this entity.\n *\n * @param key The key of the parent entity to remove.\n * @returns `this` for chaining.\n * @throws Error When the parent does not exist.\n * @example\n * ```typescript\n * entity.removeParent('baseEntity');\n * ```\n */\n removeParent(key: string): this {\n const { graph } = this.root\n if (!graph.hasEdge(this.key, key)) {\n throw new Error(`Trying to remove a parent ${key} from ${this.key}, but it doesn't exist`)\n }\n graph.removeEdge(this.key, key)\n this.root.notifyChange()\n return this\n }\n\n /**\n * Checks if this entity has any parents.\n *\n * @returns True if the entity has parents.\n * @example\n * ```typescript\n * if (entity.hasParents()) {\n * // ...\n * }\n * ```\n */\n hasParents(): boolean {\n for (const edge of this.root.graph.outEdges(this.key)) {\n if (this.root.graph.edge(edge)?.type === 'parent') {\n return true\n }\n }\n return false\n }\n\n /**\n * Checks if the passed entity has a circular parent\n * relationship when attempting to add a new parent.\n *\n * @param key The key of the parent being added.\n * @returns True if adding this parent would create a\n * circular relationship.\n */\n hasCircularParent(key: string): boolean {\n const { graph } = this.root\n\n // Check if new parent is one of the children.\n for (const edge of graph.outEdges(key, this.key)) {\n if (graph.edge(edge)?.type === 'parent') {\n return true\n }\n }\n\n // check if this entity is in parents chain.\n let current: DomainEntity | undefined = graph.node(key) as DomainEntity | undefined\n while (current) {\n if (current.key === this.key) {\n return true\n }\n const parents = [...current.listParents()]\n if (parents.length === 0) {\n break\n }\n // Assuming single inheritance\n // TODO: Update this to check for multiple parents.\n current = parents[0]\n }\n\n return false\n }\n\n /**\n * Creates breadcrumbs from this entity to the root\n * namespace.\n *\n * @returns An array of `FileBreadcrumb` instances.\n * @example\n * ```typescript\n * const breadcrumbs = entity.breadcrumbs();\n * console.log(breadcrumbs);\n * ```\n */\n breadcrumbs(): FileBreadcrumb[] {\n const result: FileBreadcrumb[] = []\n result.push({\n key: this.key,\n name: this.info.getLabel('Unnamed entity'),\n kind: DomainEntityKind,\n })\n const model = this.getParentInstance()\n if (model) {\n result.push({\n key: model.key,\n kind: model.kind,\n name: model.info.getLabel('Unnamed model'),\n })\n let parent: DataDomain | DomainNamespace = model.getParentInstance()\n while (parent && parent !== this.root) {\n result.push({\n key: parent.key,\n kind: parent.kind,\n name: parent.info.getLabel('Unnamed namespace'),\n })\n const typed = parent as DomainNamespace\n parent = typed.getParentInstance()\n }\n }\n result.push({\n key: this.root.key,\n name: this.root.info.getLabel('Unnamed data domain'),\n kind: this.root.kind,\n })\n return result.reverse()\n }\n\n /**\n * Adds an association to this entity.\n *\n * @param init The association options.\n * @param input The partial association schema.\n * @returns The created `DomainAssociation` instance.\n * @throws Error When the target entity does not exist.\n * @example\n * ```typescript\n * const association = entity.addAssociation({\n * key: 'address',\n * });\n * ```\n */\n addAssociation(init: AssociationAddOptions = {}, input?: Partial<DomainAssociationSchema>): DomainAssociation {\n const { graph } = this.root\n if (init.domain && init.key) {\n // target is foreign\n const foreignKey = `${init.domain}:${init.key}`\n if (!graph.hasNode(foreignKey)) {\n throw new Error(`Foreign entity ${foreignKey} not found`)\n }\n } else if (init.key) {\n if (!graph.hasNode(init.key)) {\n throw new Error(`Target entity ${init.key} not found`)\n }\n }\n const item = new DomainAssociation(this.root, this.key, input)\n graph.setNode(item.key, item)\n graph.setEdge(this.key, item.key, { type: 'association' })\n if (init.key) {\n item.addTarget(init.key, init.domain)\n }\n this.fields.push({ type: 'association', key: item.key })\n this.root.notifyChange()\n return item\n }\n\n /**\n * Removes an association from this entity.\n *\n * @param key The key of the association to remove.\n * @throws Error When the association does not exist.\n * @example\n * ```typescript\n * entity.removeAssociation('address');\n * ```\n */\n removeAssociation(key: string): void {\n if (!this.root.graph.hasEdge(this.key, key)) {\n throw new Error(`Unable to find a connection between this entity and the ${key} association`)\n }\n const edge = this.root.graph.edge(this.key, key)\n if (!edge || edge.type !== 'association') {\n throw new Error(`Association ${key} does not exist`)\n }\n removeGraphNode(this.root.graph, key)\n this.removeField(key)\n this.root.notifyChange()\n }\n\n /**\n * A shortcut to `listAssociations()`.\n */\n get associations(): Generator<DomainAssociation> {\n return this.listAssociations()\n }\n\n /**\n * Lists all associations of this entity.\n *\n * The order of the associations is defined in the `fields` array.\n *\n * @returns A generator that yields each\n * `DomainAssociation`.\n * @example\n * ```typescript\n * for (const association of entity.listAssociations()) {\n * console.log(association.key);\n * }\n * ```\n */\n *listAssociations(): Generator<DomainAssociation> {\n for (const { key, type } of this.fields) {\n if (type !== 'association') {\n continue\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainAssociationKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this entity has any associations.\n *\n * @returns True if the entity has associations.\n * @example\n * ```typescript\n * if (entity.hasAssociations()) {\n * // ...\n * }\n * ```\n */\n hasAssociations(): boolean {\n return this.fields.some((item) => item.type === 'association')\n }\n\n /**\n * Lists all fields (properties and associations) of this entity.\n *\n * @returns A generator that yields each `DomainAssociation` or `DomainProperty`.\n * @example\n * ```typescript\n * for (const field of entity.listFields()) {\n * console.log(field.key);\n * }\n * ```\n */\n *listFields(): Generator<DomainAssociation | DomainProperty> {\n for (const { key } of this.fields) {\n const node = this.root.graph.node(key)\n if (!node) {\n continue\n }\n if (node.kind === DomainAssociationKind || node.kind === DomainPropertyKind) {\n yield node\n }\n }\n }\n\n /**\n * Checks if this entity has any fields (properties or associations).\n *\n * @returns True if the entity has fields.\n * @example\n * ```typescript\n * if (entity.hasFields()) {\n * // ...\n * }\n * ```\n */\n hasFields(): boolean {\n return this.fields.length > 0\n }\n\n private removeField(key: string): void {\n this.fields = this.fields.filter((item) => item.key !== key)\n }\n\n /**\n * Creates an AMF's data Shape.\n *\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(): IShapeUnion {\n const serializer = new ShapeGenerator()\n return serializer.entity(this)\n }\n\n /**\n * Reads the schema of the Entity and generates an example for it.\n *\n * @param mime The mime type of the example.\n * @param opts The example generation options.\n * @returns The generated example.\n * @example\n * ```typescript\n * const example = entity.toExample('application/json');\n * console.log(example);\n * ```\n */\n toExample(mime: string, opts: IShapeRenderOptions = {}): string | number | boolean | null | undefined {\n const shape = this.toApiShape()\n const generator = new ApiSchemaGenerator(mime, {\n renderExamples: typeof opts.renderExamples === 'boolean' ? opts.renderExamples : true,\n renderMocked: typeof opts.renderMocked === 'boolean' ? opts.renderMocked : true,\n renderOptional: typeof opts.renderOptional === 'boolean' ? opts.renderOptional : true,\n selectedUnions: opts.selectedUnions,\n })\n return generator.generate(shape)\n }\n\n /**\n * Checks whether the entity is a child of the given namespace or data model.\n * The relationship doesn't have to be direct, as long as the entity\n * is in the hierarchy it will return true.\n *\n * @param key The key of the parent to check.\n * @returns True if this entity is a child of the given namespace or data model.\n */\n isChildOf(key: string): boolean {\n if (this.key === key) {\n return false\n }\n const parent = this.getParentInstance()\n if (!parent) {\n return false\n }\n if (parent.key === key) {\n return true\n }\n return parent.isChildOf(key)\n }\n\n /**\n * Finds the primary key property of this entity.\n * @returns The primary key property of this entity or undefined if not found.\n */\n primaryKey(): DomainProperty | undefined {\n for (const property of this.properties) {\n if (property.primary) {\n return property\n }\n }\n let property: DomainProperty | undefined\n for (const parent of this.listParents()) {\n const prop = parent.primaryKey()\n if (prop) {\n // According to the validation rules, the last parent\n // that has the property will be used as the source of\n // the property.\n // In the future, we may add a schema definition to the entity that\n // will explicitly define which property to use.\n property = prop\n }\n }\n return property\n }\n\n /**\n * Adds or updates a semantic to the entity.\n * @param semantic The semantic to add to the entity.\n * @throws Error if the semantic is not an entity semantic.\n */\n addSemantic(semantic: AppliedDataSemantic): void {\n const sem = DataSemantics[semantic.id]\n if (!isEntitySemantic(sem)) {\n throw new Error(`Invalid semantic type: ${semantic.id}. Expected an entity semantic.`)\n }\n const index = this.semantics.findIndex((s) => s.id === semantic.id)\n if (index >= 0) {\n this.semantics[index] = semantic\n } else {\n this.semantics.push(semantic)\n }\n this.domain.notifyChange()\n }\n\n /**\n * Removes a semantic from the entity.\n * @param semanticId The ID of the semantic to remove.\n */\n removeSemantic(semanticId: SemanticType): void {\n const index = this.semantics.findIndex((s) => s.id === semanticId)\n if (index >= 0) {\n this.semantics.splice(index, 1)\n this.domain.notifyChange()\n }\n }\n\n /**\n * Checks if the entity has a specific semantic.\n * @param semanticId The ID of the semantic to check.\n * @returns True if the semantic is present, false otherwise.\n */\n hasSemantic(semanticId: SemanticType): boolean {\n return this.semantics.some((s) => s.id === semanticId)\n }\n}\n"]}
|
|
@@ -16,8 +16,7 @@ export declare class DomainFile extends File {
|
|
|
16
16
|
* @param input The data namespace instance or schema.
|
|
17
17
|
*/
|
|
18
18
|
static fromDataDomain(input: DataDomain | DataDomainSchema): DomainFile;
|
|
19
|
-
constructor(
|
|
20
|
-
new(init: IDomainFile): this;
|
|
19
|
+
constructor(state?: Partial<IDomainFile>);
|
|
21
20
|
static isDomainFile(input: unknown): boolean;
|
|
22
21
|
toJSON(): IDomainFile;
|
|
23
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomainFile.d.ts","sourceRoot":"","sources":["../../../src/modeling/DomainFile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DomainFile.d.ts","sourceRoot":"","sources":["../../../src/modeling/DomainFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEnD,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,IAAI,EAAE,OAAO,cAAc,CAAA;CAC5B;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,IAAI;IACzB,IAAI,SAAiB;WAEd,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAIlD;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,gBAAgB,GAAG,UAAU;gBAU3D,KAAK,GAAE,OAAO,CAAC,WAAW,CAAM;IAI5C,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAQnC,MAAM,IAAI,WAAW;CAO/B"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { nanoid } from '../nanoid.js';
|
|
2
1
|
import { File } from '../models/store/File.js';
|
|
3
|
-
import { Thing } from '../models/Thing.js';
|
|
4
2
|
import { DomainFileKind } from '../models/kinds.js';
|
|
5
3
|
/**
|
|
6
4
|
* Used by the store. A file definition for the DataDomain
|
|
@@ -23,46 +21,10 @@ export class DomainFile extends File {
|
|
|
23
21
|
else {
|
|
24
22
|
final = input;
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
kind: DomainFileKind,
|
|
28
|
-
key: final.key,
|
|
29
|
-
info: { ...final.info },
|
|
30
|
-
lastModified: { user: '', time: 0, byMe: false },
|
|
31
|
-
parents: [],
|
|
32
|
-
permissionIds: [],
|
|
33
|
-
permissions: [],
|
|
34
|
-
};
|
|
35
|
-
return new DomainFile(init);
|
|
36
|
-
}
|
|
37
|
-
constructor(input) {
|
|
38
|
-
super();
|
|
39
|
-
let init;
|
|
40
|
-
if (typeof input === 'string') {
|
|
41
|
-
init = JSON.parse(input);
|
|
42
|
-
}
|
|
43
|
-
else if (typeof input === 'object') {
|
|
44
|
-
init = input;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
init = {
|
|
48
|
-
kind: DomainFileKind,
|
|
49
|
-
key: nanoid(),
|
|
50
|
-
info: Thing.fromName('').toJSON(),
|
|
51
|
-
parents: [],
|
|
52
|
-
permissionIds: [],
|
|
53
|
-
permissions: [],
|
|
54
|
-
lastModified: { user: '', time: 0, byMe: false },
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
this.new(init);
|
|
24
|
+
return new DomainFile({ key: final.key, info: final.info });
|
|
58
25
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
throw new Error(`Not a data file.`);
|
|
62
|
-
}
|
|
63
|
-
super.new(init);
|
|
64
|
-
this.kind = DomainFileKind;
|
|
65
|
-
return this;
|
|
26
|
+
constructor(state = {}) {
|
|
27
|
+
super({ ...state, kind: DomainFileKind });
|
|
66
28
|
}
|
|
67
29
|
static isDomainFile(input) {
|
|
68
30
|
const typed = input;
|