@api-client/core 0.18.9 → 0.18.11

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":"DomainSerialization.d.ts","sourceRoot":"","sources":["../../../src/modeling/DomainSerialization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAwC,eAAe,EAAE,MAAM,YAAY,CAAA;AASxG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAMjD,UAAU,gBAAgB;IACxB;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAClB;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACnB;AAsDD,wBAAgB,SAAS,CAAC,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,GAAG,eAAe,CAWhF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,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,CA8DlH"}
1
+ {"version":3,"file":"DomainSerialization.d.ts","sourceRoot":"","sources":["../../../src/modeling/DomainSerialization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAwC,eAAe,EAAE,MAAM,YAAY,CAAA;AASxG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAMjD,UAAU,gBAAgB;IACxB;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAClB;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACnB;AAsDD,wBAAgB,SAAS,CAAC,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,GAAG,eAAe,CAWhF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,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,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,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;QACjC,MAAM,IAAI,GAAiB,EAAE,CAAC,EAAE,CAAA;QAChC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,EAAE,CAAA;QAC/B,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACxB,CAAC;QACD,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AC,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,S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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 // 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":[""]}