@api-client/core 0.18.10 → 0.18.12

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.
@@ -1 +1 @@
1
- {"version":3,"file":"DomainModel.d.ts","sourceRoot":"","sources":["../../../src/modeling/DomainModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAoB,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAEvE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAEvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAMzE,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAA;IAEd;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,iBAAkB,SAAQ,mBAAmB;IAC5D,IAAI,EAAE,OAAO,eAAe,CAAA;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAE3B;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,WAAY,SAAQ,aAAa;IACnC,IAAI,EAAE,OAAO,eAAe,CAAA;IAErC;;OAEG;IACe,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;IAEtC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAA;IACnC;;O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AG,UAAU;IAQjD;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,YAAY;IAe5D;;;;;;;;;OASG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAgB/B;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAgC/B;;;;;;;;OAQG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAiB/B;;;;;;;;;;;;;OAaG;IACF,YAAY,IAAI,SAAS,CAAC,YAAY,CAAC;IAaxC;;;;;;;;;;OAUG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,WAAW,IAAI,cAAc,EAAE;IAyB/B;;;;;;;;;;OAUG;IACH,SAAS,IAAI,OAAO;IAIpB,OAAO,CAAC,WAAW;IAInB;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAgBhC"}
@@ -255,11 +255,18 @@ let DomainModel = (() => {
255
255
  throw new AttachException(`Trying to attach the ${key} entity, but it is already a child of this model`);
256
256
  }
257
257
  parent.detachEntity(key);
258
- this.fields.push({
259
- type: 'entity',
260
- key: key,
261
- });
258
+ if (!this.fields.some((item) => item.key === key)) {
259
+ this.fields.push({
260
+ type: 'entity',
261
+ key: key,
262
+ });
263
+ }
262
264
  this.root.graph.setParent(key, this.key);
265
+ // verify that the entity is moved to the current model
266
+ const graphParent = this.root.graph.parent(key);
267
+ if (graphParent !== this.key) {
268
+ throw new AttachException(`Trying to attach the ${key} entity, but it is not a child of this model`);
269
+ }
263
270
  this.root.notifyChange();
264
271
  return this;
265
272
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DomainModel.js","sourceRoot":"","sources":["../../../src/modeling/DomainModel.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAA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AI,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;gBACrB,OAAO,KAAK,CAAA;YACd,CAAC;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAA;YACvC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,KAAK,CAAA;YACd,CAAC;YACD,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;gBACvB,OAAO,IAAI,CAAA;YACb,CAAC;YACD,IAAI,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAA;YACd,CAAC;YACD,OAAQ,MAA0B,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QACnD,CAAC;;;SAxVU,WAAW","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainEntityKind, DomainModelKind } from '../models/kinds.js'\nimport { DomainElement, DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { observed, retargetChange } from './observed.js'\nimport type { DomainNamespace } from './DomainNamespace.js'\nimport type { FileBreadcrumb } from '../models/store/File.js'\nimport { DomainEntity, type DomainEntitySchema } from './DomainEntity.js'\nimport { RemoveEntityException } from '../exceptions/remove_entity_exception.js'\nimport { removeGraphNode } from './GraphUtils.js'\nimport { AttachException } from '../exceptions/attach_exception.js'\nimport { DetachException } from '../exceptions/detach_exception.js'\n\nexport interface ModelOrderedItem {\n /**\n * The type of the ordered item.\n */\n type: 'entity'\n\n /**\n * The key of the ordered item.\n */\n key: string\n}\n\nexport interface DomainModelSchema extends DomainElementSchema {\n kind: typeof DomainModelKind\n /**\n * The data model description.\n */\n info: IThing\n /**\n * The ordered list of entities in the schema.\n */\n fields?: ModelOrderedItem[]\n\n /**\n * Whether this model is deprecated.\n */\n deprecated?: boolean\n}\n\n/**\n * Represents a data model within a data domain.\n *\n * A `DomainModel` groups related `DomainEntity` instances, providing a logical structure for organizing\n * data. It acts as a container for entities that share a common purpose or context.\n *\n * **Key Features:**\n *\n * - **Entity Container:** Holds a collection of `DomainEntity` instances.\n * - **Logical Grouping:** Organizes entities into meaningful groups.\n * - **Metadata:** Supports a description for the data model.\n * - **Namespace Integration:** Belongs to a `DomainNamespace`, creating a hierarchical structure.\n *\n * **Usage:**\n *\n * The preferred way to create a `DomainModel` is through\n * the `DomainNamespace.addModel()` or\n * `DataDomain.addModel()` method.\n *\n * **Example:**\n *\n * ```typescript\n * const dataDomain = new DataDomain();\n * const ns = dataDomain.addNamespace({\n * key: 'myNamespace',\n * });\n * const userModel = ns.addModel({\n * key: 'userModel',\n * info: { name: 'User Model' },\n * });\n * ```\n */\nexport class DomainModel extends DomainElement {\n override kind: typeof DomainModelKind\n\n /**\n * The description of the domain model.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * The ordered list of entities in the schema.\n */\n accessor fields: ModelOrderedItem[]\n /**\n * Whether this model is deprecated.\n */\n @observed() accessor deprecated: boolean | undefined\n\n /**\n * Creates a full data model schema with defaults.\n * @param input The partial data model schema.\n * @returns The data model schema.\n */\n static createSchema(input: Partial<DomainModelSchema> = {}): DomainModelSchema {\n const { key = nanoid(), fields, deprecated } = input\n const info = Thing.fromJSON(input.info, { name: 'New model' }).toJSON()\n const result: DomainModelSchema = {\n kind: DomainModelKind,\n key,\n info,\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 model instance.\n *\n * You should use the `DomainNamespace.addModel()` or\n * `DataDomain.addModel()` method instead.\n *\n * @param root A reference to the root DataDomain instance.\n * @param input The partial model schema.\n */\n constructor(root: DataDomain, input?: Partial<DomainModelSchema>) {\n const init = DomainModel.createSchema(input)\n super(root, init.key)\n this.kind = DomainModelKind\n this.info = new Thing(init.info)\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 } else {\n this.deprecated = undefined\n }\n }\n\n /**\n * Generates a JSON representation of the data model.\n *\n * @returns A plain object representation of the\n * `DomainModel`.\n * @example\n * ```typescript\n * const json = userModel.toJSON();\n * console.log(json);\n * ```\n */\n toJSON(): DomainModelSchema {\n const result: DomainModelSchema = {\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 (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n return result\n }\n\n /**\n * Returns the parent namespace where this data model\n * exists.\n *\n * @returns The parent `DomainNamespace`.\n * @throws Error When no parent is found.\n * @example\n * ```typescript\n * const parent = userModel.getParentInstance();\n * console.log(parent.key);\n * ```\n */\n getParentInstance(): DomainNamespace | DataDomain {\n const parentKey = this.root.graph.parent(this.key)\n if (!parentKey) {\n return this.root\n }\n return this.root.graph.node(parentKey) as DomainNamespace\n }\n\n /**\n * Adds a child entity to the current model.\n *\n * @param value The partial entity schema.\n * @returns The created entity instance.\n * @example\n * ```typescript\n * const entity = model.addEntity({\n * key: 'address',\n * info: { name: 'Address' },\n * })\n * ```\n */\n addEntity(input?: Partial<DomainEntitySchema>): DomainEntity {\n if (input && input.key && this.root.graph.hasNode(input.key)) {\n throw new Error(`Entity with key ${input?.key} already exists`)\n }\n const item = new DomainEntity(this.root, input)\n this.root.graph.setNode(item.key, item)\n this.root.graph.setParent(item.key, this.key)\n this.fields.push({\n key: item.key,\n type: 'entity',\n })\n this.root.notifyChange()\n return item\n }\n\n /**\n * Removes an entity from the current model.\n *\n * @param key The key of the model to remove.\n * @throws {RemoveEntityException} If the model does not exist.\n * @example\n * ```typescript\n * model.removeEntity('address')\n * ```\n */\n removeEntity(key: string): void {\n if (!this.root.graph.hasNode(key)) {\n throw new RemoveEntityException(`Trying to remove the ${key} entity, but it doesn't exist`)\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainEntityKind) {\n throw new RemoveEntityException(`Trying to remove the ${key} entity, but it is not an entity`)\n }\n if (node.getParentInstance() !== this) {\n throw new RemoveEntityException(`Trying to remove the ${key} entity, but it is not a child of this model`)\n }\n removeGraphNode(this.root.graph, key)\n this.removeField(key)\n this.root.notifyChange()\n }\n\n /**\n * Attaches an entity to the current model. It changes the parent of the entity\n * to the current model in the graph.\n *\n * The attached entity must be already a child of another model. It detaches the entity\n * from the previous model.\n *\n * @param key The key of the entity to attach.\n * @throws {AttachException} If the entity does not exist.\n * @throws {AttachException} If passed key doesn't belong to an entity.\n * @throws {AttachException} When the entity is already a child of the current model.\n * @throws {AttachException} If the entity is not in the same domain.\n * @example\n * ```typescript\n * model.attachEntity('address')\n * ```\n */\n attachEntity(key: string): this {\n if (!this.root.graph.hasNode(key)) {\n throw new AttachException(`Trying to attach the ${key} entity, but it doesn't exist`)\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainEntityKind) {\n throw new AttachException(`Trying to attach the ${key} entity, but it is not a entity`)\n }\n if (node.domain.key !== this.root.key) {\n throw new AttachException(`Trying to attach the ${key} entity, but it is not in the same domain`)\n }\n const parent = node.getParentInstance() as DomainModel\n if (parent === this) {\n throw new AttachException(`Trying to attach the ${key} entity, but it is already a child of this model`)\n }\n parent.detachEntity(key)\n this.fields.push({\n type: 'entity',\n key: key,\n })\n this.root.graph.setParent(key, this.key)\n this.root.notifyChange()\n return this\n }\n\n /**\n * Detaches an entity from the current model. It changes the parent of the entity\n * to the root graph.\n * Unlike remove, it doesn't remove the entity from the graph nor notifies the change.\n * @param key The key of the entity to detach.\n * @throws {DetachException} If the entity does not exist.\n * @throws {DetachException} If passed key doesn't belong to an entity.\n * @throws {DetachException} When the entity is not a child of the current model.\n */\n detachEntity(key: string): this {\n const index = this.fields.findIndex((item) => item.key === key)\n if (index === -1) {\n throw new DetachException(`Trying to detach the ${key} entity, but it doesn't exist`)\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainEntityKind) {\n throw new DetachException(`Trying to detach the ${key} entity, but it is not an entity`)\n }\n if (node.getParentInstance() !== this) {\n throw new DetachException(`Trying to detach the ${key} entity, but it is not a child of this model`)\n }\n this.fields.splice(index, 1)\n this.root.graph.setParent(key)\n return this\n }\n\n /**\n * Lists all entities.\n *\n * Note, it accounts for the order of the entities as\n * defined in the `fields` array.\n *\n * @returns A generator that yields each `DomainEntity`.\n * @example\n * ```typescript\n * for (const entity of model.listEntities()) {\n * console.log(entity.key);\n * }\n * ```\n */\n *listEntities(): Generator<DomainEntity> {\n for (const { key, type } of this.fields) {\n if (type !== 'entity') {\n continue\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainEntityKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this model has any entities.\n *\n * @returns True if the model has entities.\n * @example\n * ```typescript\n * if (model.hasEntities()) {\n * // ...\n * }\n * ```\n */\n hasEntities(): boolean {\n return this.fields.some((item) => item.type === 'entity')\n }\n\n /**\n * Creates breadcrumbs from this data model to the root namespace.\n */\n breadcrumbs(): FileBreadcrumb[] {\n const result: FileBreadcrumb[] = []\n result.push({\n key: this.key,\n name: this.info.getLabel('Unnamed model'),\n kind: DomainModelKind,\n })\n let parent: DomainNamespace | DataDomain = this.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 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 * Checks if this model has any fields (entities).\n *\n * @returns True if the model has fields.\n * @example\n * ```typescript\n * if (model.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 * Checks whether the data model is a child of the given namespace.\n * The relationship doesn't have to be direct, as long as the data model is in the hierarchy it will return true.\n *\n * @param key The key of the parent namespace to check.\n * @returns True if this data model is a child of the given namespace.\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 if (parent === this.root) {\n return false\n }\n return (parent as DomainNamespace).isChildOf(key)\n }\n}\n"]}
1
+ {"version":3,"file":"DomainModel.js","sourceRoot":"","sources":["../../../src/modeling/DomainModel.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAE,aAAa,EAAuB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAGxD,OAAO,EAAE,YAAY,EAA2B,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AA+BnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;IACU,WAAW;sBAAS,aAAa;;;;;;;iBAAjC,WAAY,SAAQ,WAAa;;;gCAM3C,cAAc,EAAE;sCAShB,QAAQ,EAAE;YATO,iKAAS,IAAI,6BAAJ,IAAI,mFAAO;YAS1B,mLAAS,UAAU,6BAAV,UAAU,+FAAqB;;;QAd3C,IAAI,CAAwB;QAKnB,6EAAoB;QAHtC;;WAEG;QACe,IAAS,IAAI,0CAAO;QAApB,IAAS,IAAI,gDAAO;QAKtC,4EAAmC;QAHnC;;WAEG;QACH,IAAS,MAAM,4CAAoB;QA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ent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainEntityKind, DomainModelKind } from '../models/kinds.js'\nimport { DomainElement, DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { observed, retargetChange } from './observed.js'\nimport type { DomainNamespace } from './DomainNamespace.js'\nimport type { FileBreadcrumb } from '../models/store/File.js'\nimport { DomainEntity, type DomainEntitySchema } from './DomainEntity.js'\nimport { RemoveEntityException } from '../exceptions/remove_entity_exception.js'\nimport { removeGraphNode } from './GraphUtils.js'\nimport { AttachException } from '../exceptions/attach_exception.js'\nimport { DetachException } from '../exceptions/detach_exception.js'\n\nexport interface ModelOrderedItem {\n /**\n * The type of the ordered item.\n */\n type: 'entity'\n\n /**\n * The key of the ordered item.\n */\n key: string\n}\n\nexport interface DomainModelSchema extends DomainElementSchema {\n kind: typeof DomainModelKind\n /**\n * The data model description.\n */\n info: IThing\n /**\n * The ordered list of entities in the schema.\n */\n fields?: ModelOrderedItem[]\n\n /**\n * Whether this model is deprecated.\n */\n deprecated?: boolean\n}\n\n/**\n * Represents a data model within a data domain.\n *\n * A `DomainModel` groups related `DomainEntity` instances, providing a logical structure for organizing\n * data. It acts as a container for entities that share a common purpose or context.\n *\n * **Key Features:**\n *\n * - **Entity Container:** Holds a collection of `DomainEntity` instances.\n * - **Logical Grouping:** Organizes entities into meaningful groups.\n * - **Metadata:** Supports a description for the data model.\n * - **Namespace Integration:** Belongs to a `DomainNamespace`, creating a hierarchical structure.\n *\n * **Usage:**\n *\n * The preferred way to create a `DomainModel` is through\n * the `DomainNamespace.addModel()` or\n * `DataDomain.addModel()` method.\n *\n * **Example:**\n *\n * ```typescript\n * const dataDomain = new DataDomain();\n * const ns = dataDomain.addNamespace({\n * key: 'myNamespace',\n * });\n * const userModel = ns.addModel({\n * key: 'userModel',\n * info: { name: 'User Model' },\n * });\n * ```\n */\nexport class DomainModel extends DomainElement {\n override kind: typeof DomainModelKind\n\n /**\n * The description of the domain model.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * The ordered list of entities in the schema.\n */\n accessor fields: ModelOrderedItem[]\n /**\n * Whether this model is deprecated.\n */\n @observed() accessor deprecated: boolean | undefined\n\n /**\n * Creates a full data model schema with defaults.\n * @param input The partial data model schema.\n * @returns The data model schema.\n */\n static createSchema(input: Partial<DomainModelSchema> = {}): DomainModelSchema {\n const { key = nanoid(), fields, deprecated } = input\n const info = Thing.fromJSON(input.info, { name: 'New model' }).toJSON()\n const result: DomainModelSchema = {\n kind: DomainModelKind,\n key,\n info,\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 model instance.\n *\n * You should use the `DomainNamespace.addModel()` or\n * `DataDomain.addModel()` method instead.\n *\n * @param root A reference to the root DataDomain instance.\n * @param input The partial model schema.\n */\n constructor(root: DataDomain, input?: Partial<DomainModelSchema>) {\n const init = DomainModel.createSchema(input)\n super(root, init.key)\n this.kind = DomainModelKind\n this.info = new Thing(init.info)\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 } else {\n this.deprecated = undefined\n }\n }\n\n /**\n * Generates a JSON representation of the data model.\n *\n * @returns A plain object representation of the\n * `DomainModel`.\n * @example\n * ```typescript\n * const json = userModel.toJSON();\n * console.log(json);\n * ```\n */\n toJSON(): DomainModelSchema {\n const result: DomainModelSchema = {\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 (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n return result\n }\n\n /**\n * Returns the parent namespace where this data model\n * exists.\n *\n * @returns The parent `DomainNamespace`.\n * @throws Error When no parent is found.\n * @example\n * ```typescript\n * const parent = userModel.getParentInstance();\n * console.log(parent.key);\n * ```\n */\n getParentInstance(): DomainNamespace | DataDomain {\n const parentKey = this.root.graph.parent(this.key)\n if (!parentKey) {\n return this.root\n }\n return this.root.graph.node(parentKey) as DomainNamespace\n }\n\n /**\n * Adds a child entity to the current model.\n *\n * @param value The partial entity schema.\n * @returns The created entity instance.\n * @example\n * ```typescript\n * const entity = model.addEntity({\n * key: 'address',\n * info: { name: 'Address' },\n * })\n * ```\n */\n addEntity(input?: Partial<DomainEntitySchema>): DomainEntity {\n if (input && input.key && this.root.graph.hasNode(input.key)) {\n throw new Error(`Entity with key ${input?.key} already exists`)\n }\n const item = new DomainEntity(this.root, input)\n this.root.graph.setNode(item.key, item)\n this.root.graph.setParent(item.key, this.key)\n this.fields.push({\n key: item.key,\n type: 'entity',\n })\n this.root.notifyChange()\n return item\n }\n\n /**\n * Removes an entity from the current model.\n *\n * @param key The key of the model to remove.\n * @throws {RemoveEntityException} If the model does not exist.\n * @example\n * ```typescript\n * model.removeEntity('address')\n * ```\n */\n removeEntity(key: string): void {\n if (!this.root.graph.hasNode(key)) {\n throw new RemoveEntityException(`Trying to remove the ${key} entity, but it doesn't exist`)\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainEntityKind) {\n throw new RemoveEntityException(`Trying to remove the ${key} entity, but it is not an entity`)\n }\n if (node.getParentInstance() !== this) {\n throw new RemoveEntityException(`Trying to remove the ${key} entity, but it is not a child of this model`)\n }\n removeGraphNode(this.root.graph, key)\n this.removeField(key)\n this.root.notifyChange()\n }\n\n /**\n * Attaches an entity to the current model. It changes the parent of the entity\n * to the current model in the graph.\n *\n * The attached entity must be already a child of another model. It detaches the entity\n * from the previous model.\n *\n * @param key The key of the entity to attach.\n * @throws {AttachException} If the entity does not exist.\n * @throws {AttachException} If passed key doesn't belong to an entity.\n * @throws {AttachException} When the entity is already a child of the current model.\n * @throws {AttachException} If the entity is not in the same domain.\n * @example\n * ```typescript\n * model.attachEntity('address')\n * ```\n */\n attachEntity(key: string): this {\n if (!this.root.graph.hasNode(key)) {\n throw new AttachException(`Trying to attach the ${key} entity, but it doesn't exist`)\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainEntityKind) {\n throw new AttachException(`Trying to attach the ${key} entity, but it is not a entity`)\n }\n if (node.domain.key !== this.root.key) {\n throw new AttachException(`Trying to attach the ${key} entity, but it is not in the same domain`)\n }\n const parent = node.getParentInstance() as DomainModel\n if (parent === this) {\n throw new AttachException(`Trying to attach the ${key} entity, but it is already a child of this model`)\n }\n parent.detachEntity(key)\n if (!this.fields.some((item) => item.key === key)) {\n this.fields.push({\n type: 'entity',\n key: key,\n })\n }\n this.root.graph.setParent(key, this.key)\n // verify that the entity is moved to the current model\n const graphParent = this.root.graph.parent(key)\n if (graphParent !== this.key) {\n throw new AttachException(`Trying to attach the ${key} entity, but it is not a child of this model`)\n }\n this.root.notifyChange()\n return this\n }\n\n /**\n * Detaches an entity from the current model. It changes the parent of the entity\n * to the root graph.\n * Unlike remove, it doesn't remove the entity from the graph nor notifies the change.\n * @param key The key of the entity to detach.\n * @throws {DetachException} If the entity does not exist.\n * @throws {DetachException} If passed key doesn't belong to an entity.\n * @throws {DetachException} When the entity is not a child of the current model.\n */\n detachEntity(key: string): this {\n const index = this.fields.findIndex((item) => item.key === key)\n if (index === -1) {\n throw new DetachException(`Trying to detach the ${key} entity, but it doesn't exist`)\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainEntityKind) {\n throw new DetachException(`Trying to detach the ${key} entity, but it is not an entity`)\n }\n if (node.getParentInstance() !== this) {\n throw new DetachException(`Trying to detach the ${key} entity, but it is not a child of this model`)\n }\n this.fields.splice(index, 1)\n this.root.graph.setParent(key)\n return this\n }\n\n /**\n * Lists all entities.\n *\n * Note, it accounts for the order of the entities as\n * defined in the `fields` array.\n *\n * @returns A generator that yields each `DomainEntity`.\n * @example\n * ```typescript\n * for (const entity of model.listEntities()) {\n * console.log(entity.key);\n * }\n * ```\n */\n *listEntities(): Generator<DomainEntity> {\n for (const { key, type } of this.fields) {\n if (type !== 'entity') {\n continue\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainEntityKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this model has any entities.\n *\n * @returns True if the model has entities.\n * @example\n * ```typescript\n * if (model.hasEntities()) {\n * // ...\n * }\n * ```\n */\n hasEntities(): boolean {\n return this.fields.some((item) => item.type === 'entity')\n }\n\n /**\n * Creates breadcrumbs from this data model to the root namespace.\n */\n breadcrumbs(): FileBreadcrumb[] {\n const result: FileBreadcrumb[] = []\n result.push({\n key: this.key,\n name: this.info.getLabel('Unnamed model'),\n kind: DomainModelKind,\n })\n let parent: DomainNamespace | DataDomain = this.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 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 * Checks if this model has any fields (entities).\n *\n * @returns True if the model has fields.\n * @example\n * ```typescript\n * if (model.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 * Checks whether the data model is a child of the given namespace.\n * The relationship doesn't have to be direct, as long as the data model is in the hierarchy it will return true.\n *\n * @param key The key of the parent namespace to check.\n * @returns True if this data model is a child of the given namespace.\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 if (parent === this.root) {\n return false\n }\n return (parent as DomainNamespace).isChildOf(key)\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"DomainSerialization.d.ts","sourceRoot":"","sources":["../../../src/modeling/DomainSerialization.ts"],"names":[],"mappings":"AAEA,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C,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAa9E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAyD3G;AA+DD;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,eAAe,EAAE,YAAY,CAAC,EAAE,UAAU,EAAE,GAAG,eAAe,CAoElH"}
@@ -246,19 +246,25 @@ export function deserialize(root, json, dependencies) {
246
246
  return g;
247
247
  }
248
248
  if (Array.isArray(json.nodes)) {
249
+ // 1st pass - set up nodes
250
+ const parentInfo = new Map();
249
251
  for (const entry of json.nodes) {
250
252
  g.setNode(entry.v, prepareNode(root, entry.value, json.edges));
251
253
  if (entry.parents) {
252
- for (const parent of entry.parents) {
253
- // In data domain graph, all nodes that can have parents can only have a single parent.
254
- // It's the business logic of the library.
255
- // Parent-child relationships:
256
- // - Namespace -> Namespace
257
- // - Namespace -> Model
258
- // - Model -> Entity
259
- // Entities and Association are associated with the parent entity through edges.
260
- g.setParent(entry.v, parent);
261
- }
254
+ parentInfo.set(entry.v, entry.parents);
255
+ }
256
+ }
257
+ // 2nd pass - set up parents
258
+ for (const [key, parents] of parentInfo) {
259
+ // In data domain graph, all nodes that can have parents can only have a single parent.
260
+ // It's the business logic of the library.
261
+ // Parent-child relationships:
262
+ // - Namespace -> Namespace
263
+ // - Namespace -> Model
264
+ // - Model -> Entity
265
+ // Entities and Association are associated with the parent entity through edges.
266
+ for (const parent of parents) {
267
+ g.setParent(key, parent);
262
268
  }
263
269
  }
264
270
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DomainSerialization.js","sourceRoot":"","sources":["../../../src/modeling/DomainSerialization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAA;AAExD,OAAO,EACL,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C,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC/B,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;YAC9E,CAAC;YACD,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBACxB,iEAAiE;gBACjE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC/B,mEAAmE;oBACnE,SAAQ;gBACV,CAAC;YACH,CAAC;YACD,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC3D,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC/C,iFAAiF;oBACjF,SAAQ;gBACV,CAAC;YACH,CAAC;YACD,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;QACtE,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC","sourcesContent":["import type { JsonEdge, Node } from '@api-client/graph/graph/types.js'\nimport { Graph } from '@api-client/graph/graph/Graph.js'\nimport type { DataDomainGraph, DomainGraphEdge, DomainGraphNodeType, SerializedGraph } from './types.js'\nimport {\n DomainAssociationKind,\n DomainEntityKind,\n DomainModelKind,\n DomainNamespaceKind,\n DomainPropertyKind,\n} from '../models/kinds.js'\nimport { DomainNamespace, type DomainNamespaceSchema } from './DomainNamespace.js'\nimport type { DataDomain } from './DataDomain.js'\nimport { DomainModel, type DomainModelSchema } from './DomainModel.js'\nimport { DomainEntity, DomainEntitySchema } from './DomainEntity.js'\nimport { DomainProperty, DomainPropertySchema } from './DomainProperty.js'\nimport { DomainAssociation, DomainAssociationSchema } from './DomainAssociation.js'\n\ninterface GraphMergeResult {\n /**\n * The set of node ids generated for the foreign nodes.\n */\n nodes: Set<string>\n /**\n * The set of edge ids generated for the foreign edges.\n */\n edges: Set<string>\n}\n\nfunction writeNodes(g: DataDomainGraph, domainKey: string): Node<object>[] {\n const result: Node<object>[] = []\n for (const v of g.nodes()) {\n const nodeValue = g.node(v)\n if (!nodeValue || nodeValue.domain.key !== domainKey) {\n // Filter out foreign nodes\n continue\n }\n // We do only use single parent for the graph. Potentially this could be\n // replaced with the `g.parent(v)` method.\n const parents = [...g.parents(v)]\n const node: Node<object> = { v }\n node.value = nodeValue.toJSON()\n if (parents.length) {\n node.parents = parents\n }\n result.push(node)\n }\n return result\n}\n\nfunction writeEdges(g: DataDomainGraph, domainKey: string): JsonEdge<DomainGraphEdge>[] {\n const result: JsonEdge<DomainGraphEdge>[] = []\n for (const e of g.edges()) {\n const edgeValue = g.edge(e)\n if (!edgeValue) {\n continue\n }\n const sourceNode = g.node(e.v)\n const targetNode = g.node(e.w)\n if (!sourceNode || !targetNode) {\n continue\n }\n if (sourceNode.domain.key !== domainKey) {\n // Filter out edges starting from foreign nodes. These are foreign associations\n // that have nothing to do with the current domain.\n continue\n }\n if (targetNode.domain.key !== domainKey && edgeValue.type !== 'association' && edgeValue.type !== 'parent') {\n // Filter out edges to foreign nodes except for associations and parent-child relations\n continue\n }\n const edge: JsonEdge<DomainGraphEdge> = { v: e.v, w: e.w }\n if (e.name) {\n edge.name = e.name\n }\n edge.value = structuredClone(edgeValue)\n result.push(edge)\n }\n return result\n}\n\nexport function serialize(g: DataDomainGraph, domainKey: string): SerializedGraph {\n const json: SerializedGraph = {\n options: {\n directed: g.isDirected(),\n multigraph: g.isMultigraph(),\n compound: g.isCompound(),\n },\n nodes: writeNodes(g, domainKey),\n edges: writeEdges(g, domainKey),\n }\n return json\n}\n\n/**\n * Removes all foreign nodes, edges, and parents from the graph.\n * @param g The graph to remove the foreign nodes from\n * @param domainKey The key of the domain to remove\n */\nexport function removeForeignGraph(g: DataDomainGraph, domainKey: string): void {\n for (const node of g.nodes()) {\n const nodeValue = g.node(node)\n if (!nodeValue) {\n continue\n }\n if (nodeValue.domain.key === domainKey) {\n // This is a foreign node, remove it from the graph.\n g.removeNode(node)\n // When a node is removed, all edges and parents are removed as well.\n // No need to iterate over them.\n }\n }\n}\n\n/**\n * Merges a foreign domain graph into the current domain graph.\n * @param own Our domain graph\n * @param foreign The foreign domain graph\n * @param domain The key of the foreign domain\n */\nexport function mergeGraph(own: DataDomainGraph, foreign: DataDomainGraph, domain: string): GraphMergeResult {\n const nodes = new Set<string>()\n const edges = new Set<string>()\n // Copy nodes\n for (const node of foreign.nodes()) {\n const foreignNode = foreign.node(node)\n if (!foreignNode) {\n continue\n }\n const foreignKey = `${domain}:${node}`\n own.setNode(foreignKey, foreignNode)\n nodes.add(foreignKey)\n }\n // Copy edges\n for (const edge of foreign.edges()) {\n const label = foreign.edge(edge)\n if (!label) {\n continue\n }\n const foreignSource = `${domain}:${edge.v}`\n const foreignTarget = `${domain}:${edge.w}`\n // const foreignEdge = foreign.edge(edge)\n own.setEdge(foreignSource, foreignTarget, {\n foreign: true,\n domain,\n ...label,\n })\n edges.add(`${foreignSource}|${foreignTarget}`)\n }\n const notRootEntities = new Set<string>()\n // Copy parent-child relationships\n for (const node of foreign.nodes()) {\n const foreignNodeKey = `${domain}:${node}`\n for (const parent of foreign.parents(node)) {\n const foreignParentKey = `${domain}:${parent}`\n const srcNode = own.node(foreignNodeKey) as DomainGraphNodeType\n const targetNode = own.node(foreignParentKey) as DomainGraphNodeType\n if (srcNode.kind === DomainEntityKind && targetNode.kind === DomainEntityKind) {\n // entities can have multiple parents between them. We need to respect that.\n if (!notRootEntities.has(foreignNodeKey)) {\n // We use `setParent` in the first run to remove the entity from the root\n // of the graph.\n notRootEntities.add(foreignNodeKey)\n own.setParent(foreignNodeKey, foreignParentKey)\n } else {\n own.addParent(foreignNodeKey, foreignParentKey)\n }\n } else {\n // other nodes can only have a single parent.\n own.setParent(foreignNodeKey, foreignParentKey)\n }\n }\n }\n return {\n nodes,\n edges,\n }\n}\n\n/**\n * Properties and associations are stored as nodes with edges to the parent entity in the graph.\n * At the time of restoring these nodes, the graph has no edges yet.\n * This function finds the parent of the child node in the edges list.\n * @param child The DomainProperty or DomainAssociation key\n * @param edges The list of serialized graph edges\n * @returns The parent key of the child or undefined if not found\n */\nfunction findEdgeParent(child: string, edges: JsonEdge<DomainGraphEdge>[]): string | undefined {\n for (const edge of edges) {\n if (edge.w === child) {\n return edge.v\n }\n }\n return undefined\n}\n\n/**\n * Restores the previously serialized node entry.\n * @param root The DataDomain instance to use as the root for the graph\n * @param entry The node entry to restore\n * @param edges The list of serialized graph edges\n * @returns The restored node instance\n * @throws Error if the entry is malformed or the kind is unknown\n */\nfunction prepareNode(root: DataDomain, entry: unknown, edges: JsonEdge<DomainGraphEdge>[]): DomainGraphNodeType {\n if (!entry) {\n throw new Error(`Unable to restore data domain graph. Malformed node entry`)\n }\n const domainElement = entry as { kind?: string }\n if (!domainElement.kind) {\n throw new Error(`Unable to restore data domain graph. Malformed node entry`)\n }\n if (domainElement.kind === DomainNamespaceKind) {\n return new DomainNamespace(root, domainElement as DomainNamespaceSchema)\n }\n if (domainElement.kind === DomainModelKind) {\n return new DomainModel(root, domainElement as DomainModelSchema)\n }\n if (domainElement.kind === DomainEntityKind) {\n return new DomainEntity(root, domainElement as DomainEntitySchema)\n }\n if (domainElement.kind === DomainPropertyKind) {\n const typed = domainElement as DomainPropertySchema\n const parent = findEdgeParent(typed.key, edges)\n if (!parent) {\n throw new Error(`Unable to restore data domain graph. Malformed node entry`)\n }\n return new DomainProperty(root, parent, typed)\n }\n if (domainElement.kind === DomainAssociationKind) {\n const typed = domainElement as DomainAssociationSchema\n const parent = findEdgeParent(typed.key, edges)\n if (!parent) {\n throw new Error(`Unable to restore data domain graph. Malformed node entry`)\n }\n return new DomainAssociation(root, parent, typed)\n }\n throw new Error(`Unable to restore data domain graph. Unknown node kind ${domainElement.kind}`)\n}\n\n/**\n * To deserialize a graph:\n *\n * - Create a new DataDomain instance\n * - Restore all foreign nodes and edges\n * - Call the deserialize function\n *\n * @param root The DataDomain instance to use as the root for the graph\n * @param json The previously serialized graph\n * @returns Deserialized graph instance\n */\nexport function deserialize(root: DataDomain, json?: SerializedGraph, dependencies?: DataDomain[]): DataDomainGraph {\n const g = new Graph<unknown, DomainGraphNodeType, DomainGraphEdge>({\n compound: true,\n multigraph: true,\n directed: true,\n })\n let foreignNodes = new Set<string>()\n let foreignEdges = new Set<string>()\n if (dependencies) {\n for (const dependency of dependencies) {\n const result = mergeGraph(g, dependency.graph, dependency.key)\n if (result.edges.size) {\n foreignEdges = new Set([...foreignEdges, ...result.edges])\n }\n if (result.nodes.size) {\n foreignNodes = new Set([...foreignNodes, ...result.nodes])\n }\n root.dependencies.set(dependency.key, dependency)\n }\n }\n if (!json) {\n return g\n }\n if (Array.isArray(json.nodes)) {\n for (const entry of json.nodes) {\n g.setNode(entry.v, prepareNode(root, entry.value, json.edges))\n if (entry.parents) {\n for (const parent of entry.parents) {\n // In data domain graph, all nodes that can have parents can only have a single parent.\n // It's the business logic of the library.\n // Parent-child relationships:\n // - Namespace -> Namespace\n // - Namespace -> Model\n // - Model -> Entity\n // Entities and Association are associated with the parent entity through edges.\n g.setParent(entry.v, parent)\n }\n }\n }\n }\n if (Array.isArray(json.edges)) {\n for (const entry of json.edges) {\n if (!entry.value) {\n throw new Error(`Unable to restore data domain graph. Malformed edge entry`)\n }\n if (entry.value.foreign) {\n // The `v` has to be local to the graph. The `w` must be foreign.\n if (!foreignNodes.has(entry.w)) {\n // console.warn(`Missing foreign node: ${entry.w}. Skipping edge.`)\n continue\n }\n }\n if (foreignNodes.has(entry.v) || foreignNodes.has(entry.w)) {\n if (!g.hasNode(entry.v) || !g.hasNode(entry.w)) {\n // console.warn(`Missing foreign node: ${entry.v} or ${entry.w}. Skipping edge.`)\n continue\n }\n }\n g.setEdge({ v: entry.v, w: entry.w, name: entry.name }, entry.value)\n }\n }\n return g\n}\n"]}
1
+ {"version":3,"file":"DomainSerialization.js","sourceRoot":"","sources":["../../../src/modeling/DomainSerialization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAA;AAExD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,eAAe,EAA8B,MAAM,sBAAsB,CAAA;AAElF,OAAO,EAAE,WAAW,EAA0B,MAAM,kBAAkB,CAAA;AACtE,OAAO,EAAE,YAAY,EAAsB,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAA;AAanF,SAAS,UAAU,CAAC,CAAkB,EAAE,SAAiB;IACvD,MAAM,MAAM,GAAmB,EAAE,CAAA;IACjC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QAC1B,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAC3B,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,MAAM,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YACrD,2BAA2B;YAC3B,SAAQ;QACV,CAAC;QACD,wEAAwE;QACxE,0CAA0C;QAC1C,M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AQ;gBACV,CAAC;YACH,CAAC;YACD,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC3D,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC/C,iFAAiF;oBACjF,SAAQ;gBACV,CAAC;YACH,CAAC;YACD,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;QACtE,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC","sourcesContent":["import type { JsonEdge, Node } from '@api-client/graph/graph/types.js'\nimport { Graph } from '@api-client/graph/graph/Graph.js'\nimport type { DataDomainGraph, DomainGraphEdge, DomainGraphNodeType, SerializedGraph } from './types.js'\nimport {\n DomainAssociationKind,\n DomainEntityKind,\n DomainModelKind,\n DomainNamespaceKind,\n DomainPropertyKind,\n} from '../models/kinds.js'\nimport { DomainNamespace, type DomainNamespaceSchema } from './DomainNamespace.js'\nimport type { DataDomain } from './DataDomain.js'\nimport { DomainModel, type DomainModelSchema } from './DomainModel.js'\nimport { DomainEntity, DomainEntitySchema } from './DomainEntity.js'\nimport { DomainProperty, DomainPropertySchema } from './DomainProperty.js'\nimport { DomainAssociation, DomainAssociationSchema } from './DomainAssociation.js'\n\ninterface GraphMergeResult {\n /**\n * The set of node ids generated for the foreign nodes.\n */\n nodes: Set<string>\n /**\n * The set of edge ids generated for the foreign edges.\n */\n edges: Set<string>\n}\n\nfunction writeNodes(g: DataDomainGraph, domainKey: string): Node<object>[] {\n const result: Node<object>[] = []\n for (const v of g.nodes()) {\n const nodeValue = g.node(v)\n if (!nodeValue || nodeValue.domain.key !== domainKey) {\n // Filter out foreign nodes\n continue\n }\n // We do only use single parent for the graph. Potentially this could be\n // replaced with the `g.parent(v)` method.\n const parents = [...g.parents(v)]\n const node: Node<object> = { v }\n node.value = nodeValue.toJSON()\n if (parents.length) {\n node.parents = parents\n }\n result.push(node)\n }\n return result\n}\n\nfunction writeEdges(g: DataDomainGraph, domainKey: string): JsonEdge<DomainGraphEdge>[] {\n const result: JsonEdge<DomainGraphEdge>[] = []\n for (const e of g.edges()) {\n const edgeValue = g.edge(e)\n if (!edgeValue) {\n continue\n }\n const sourceNode = g.node(e.v)\n const targetNode = g.node(e.w)\n if (!sourceNode || !targetNode) {\n continue\n }\n if (sourceNode.domain.key !== domainKey) {\n // Filter out edges starting from foreign nodes. These are foreign associations\n // that have nothing to do with the current domain.\n continue\n }\n if (targetNode.domain.key !== domainKey && edgeValue.type !== 'association' && edgeValue.type !== 'parent') {\n // Filter out edges to foreign nodes except for associations and parent-child relations\n continue\n }\n const edge: JsonEdge<DomainGraphEdge> = { v: e.v, w: e.w }\n if (e.name) {\n edge.name = e.name\n }\n edge.value = structuredClone(edgeValue)\n result.push(edge)\n }\n return result\n}\n\nexport function serialize(g: DataDomainGraph, domainKey: string): SerializedGraph {\n const json: SerializedGraph = {\n options: {\n directed: g.isDirected(),\n multigraph: g.isMultigraph(),\n compound: g.isCompound(),\n },\n nodes: writeNodes(g, domainKey),\n edges: writeEdges(g, domainKey),\n }\n return json\n}\n\n/**\n * Removes all foreign nodes, edges, and parents from the graph.\n * @param g The graph to remove the foreign nodes from\n * @param domainKey The key of the domain to remove\n */\nexport function removeForeignGraph(g: DataDomainGraph, domainKey: string): void {\n for (const node of g.nodes()) {\n const nodeValue = g.node(node)\n if (!nodeValue) {\n continue\n }\n if (nodeValue.domain.key === domainKey) {\n // This is a foreign node, remove it from the graph.\n g.removeNode(node)\n // When a node is removed, all edges and parents are removed as well.\n // No need to iterate over them.\n }\n }\n}\n\n/**\n * Merges a foreign domain graph into the current domain graph.\n * @param own Our domain graph\n * @param foreign The foreign domain graph\n * @param domain The key of the foreign domain\n */\nexport function mergeGraph(own: DataDomainGraph, foreign: DataDomainGraph, domain: string): GraphMergeResult {\n const nodes = new Set<string>()\n const edges = new Set<string>()\n // Copy nodes\n for (const node of foreign.nodes()) {\n const foreignNode = foreign.node(node)\n if (!foreignNode) {\n continue\n }\n const foreignKey = `${domain}:${node}`\n own.setNode(foreignKey, foreignNode)\n nodes.add(foreignKey)\n }\n // Copy edges\n for (const edge of foreign.edges()) {\n const label = foreign.edge(edge)\n if (!label) {\n continue\n }\n const foreignSource = `${domain}:${edge.v}`\n const foreignTarget = `${domain}:${edge.w}`\n // const foreignEdge = foreign.edge(edge)\n own.setEdge(foreignSource, foreignTarget, {\n foreign: true,\n domain,\n ...label,\n })\n edges.add(`${foreignSource}|${foreignTarget}`)\n }\n const notRootEntities = new Set<string>()\n // Copy parent-child relationships\n for (const node of foreign.nodes()) {\n const foreignNodeKey = `${domain}:${node}`\n for (const parent of foreign.parents(node)) {\n const foreignParentKey = `${domain}:${parent}`\n const srcNode = own.node(foreignNodeKey) as DomainGraphNodeType\n const targetNode = own.node(foreignParentKey) as DomainGraphNodeType\n if (srcNode.kind === DomainEntityKind && targetNode.kind === DomainEntityKind) {\n // entities can have multiple parents between them. We need to respect that.\n if (!notRootEntities.has(foreignNodeKey)) {\n // We use `setParent` in the first run to remove the entity from the root\n // of the graph.\n notRootEntities.add(foreignNodeKey)\n own.setParent(foreignNodeKey, foreignParentKey)\n } else {\n own.addParent(foreignNodeKey, foreignParentKey)\n }\n } else {\n // other nodes can only have a single parent.\n own.setParent(foreignNodeKey, foreignParentKey)\n }\n }\n }\n return {\n nodes,\n edges,\n }\n}\n\n/**\n * Properties and associations are stored as nodes with edges to the parent entity in the graph.\n * At the time of restoring these nodes, the graph has no edges yet.\n * This function finds the parent of the child node in the edges list.\n * @param child The DomainProperty or DomainAssociation key\n * @param edges The list of serialized graph edges\n * @returns The parent key of the child or undefined if not found\n */\nfunction findEdgeParent(child: string, edges: JsonEdge<DomainGraphEdge>[]): string | undefined {\n for (const edge of edges) {\n if (edge.w === child) {\n return edge.v\n }\n }\n return undefined\n}\n\n/**\n * Restores the previously serialized node entry.\n * @param root The DataDomain instance to use as the root for the graph\n * @param entry The node entry to restore\n * @param edges The list of serialized graph edges\n * @returns The restored node instance\n * @throws Error if the entry is malformed or the kind is unknown\n */\nfunction prepareNode(root: DataDomain, entry: unknown, edges: JsonEdge<DomainGraphEdge>[]): DomainGraphNodeType {\n if (!entry) {\n throw new Error(`Unable to restore data domain graph. Malformed node entry`)\n }\n const domainElement = entry as { kind?: string }\n if (!domainElement.kind) {\n throw new Error(`Unable to restore data domain graph. Malformed node entry`)\n }\n if (domainElement.kind === DomainNamespaceKind) {\n return new DomainNamespace(root, domainElement as DomainNamespaceSchema)\n }\n if (domainElement.kind === DomainModelKind) {\n return new DomainModel(root, domainElement as DomainModelSchema)\n }\n if (domainElement.kind === DomainEntityKind) {\n return new DomainEntity(root, domainElement as DomainEntitySchema)\n }\n if (domainElement.kind === DomainPropertyKind) {\n const typed = domainElement as DomainPropertySchema\n const parent = findEdgeParent(typed.key, edges)\n if (!parent) {\n throw new Error(`Unable to restore data domain graph. Malformed node entry`)\n }\n return new DomainProperty(root, parent, typed)\n }\n if (domainElement.kind === DomainAssociationKind) {\n const typed = domainElement as DomainAssociationSchema\n const parent = findEdgeParent(typed.key, edges)\n if (!parent) {\n throw new Error(`Unable to restore data domain graph. Malformed node entry`)\n }\n return new DomainAssociation(root, parent, typed)\n }\n throw new Error(`Unable to restore data domain graph. Unknown node kind ${domainElement.kind}`)\n}\n\n/**\n * To deserialize a graph:\n *\n * - Create a new DataDomain instance\n * - Restore all foreign nodes and edges\n * - Call the deserialize function\n *\n * @param root The DataDomain instance to use as the root for the graph\n * @param json The previously serialized graph\n * @returns Deserialized graph instance\n */\nexport function deserialize(root: DataDomain, json?: SerializedGraph, dependencies?: DataDomain[]): DataDomainGraph {\n const g = new Graph<unknown, DomainGraphNodeType, DomainGraphEdge>({\n compound: true,\n multigraph: true,\n directed: true,\n })\n let foreignNodes = new Set<string>()\n let foreignEdges = new Set<string>()\n if (dependencies) {\n for (const dependency of dependencies) {\n const result = mergeGraph(g, dependency.graph, dependency.key)\n if (result.edges.size) {\n foreignEdges = new Set([...foreignEdges, ...result.edges])\n }\n if (result.nodes.size) {\n foreignNodes = new Set([...foreignNodes, ...result.nodes])\n }\n root.dependencies.set(dependency.key, dependency)\n }\n }\n if (!json) {\n return g\n }\n if (Array.isArray(json.nodes)) {\n // 1st pass - set up nodes\n const parentInfo = new Map<string, string[]>()\n for (const entry of json.nodes) {\n g.setNode(entry.v, prepareNode(root, entry.value, json.edges))\n if (entry.parents) {\n parentInfo.set(entry.v, entry.parents)\n }\n }\n // 2nd pass - set up parents\n for (const [key, parents] of parentInfo) {\n // In data domain graph, all nodes that can have parents can only have a single parent.\n // It's the business logic of the library.\n // Parent-child relationships:\n // - Namespace -> Namespace\n // - Namespace -> Model\n // - Model -> Entity\n // Entities and Association are associated with the parent entity through edges.\n for (const parent of parents) {\n g.setParent(key, parent)\n }\n }\n }\n if (Array.isArray(json.edges)) {\n for (const entry of json.edges) {\n if (!entry.value) {\n throw new Error(`Unable to restore data domain graph. Malformed edge entry`)\n }\n if (entry.value.foreign) {\n // The `v` has to be local to the graph. The `w` must be foreign.\n if (!foreignNodes.has(entry.w)) {\n // console.warn(`Missing foreign node: ${entry.w}. Skipping edge.`)\n continue\n }\n }\n if (foreignNodes.has(entry.v) || foreignNodes.has(entry.w)) {\n if (!g.hasNode(entry.v) || !g.hasNode(entry.w)) {\n // console.warn(`Missing foreign node: ${entry.v} or ${entry.w}. Skipping edge.`)\n continue\n }\n }\n g.setEdge({ v: entry.v, w: entry.w, name: entry.name }, entry.value)\n }\n }\n return g\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CoreEngine2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoreEngine2.d.ts","sourceRoot":"","sources":["../../../../src/runtime/http-engine/CoreEngine2.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CoreEngine2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoreEngine2.js","sourceRoot":"","sources":["../../../../src/runtime/http-engine/CoreEngine2.ts"],"names":[],"mappings":"","sourcesContent":[""]}