@api-client/core 0.11.11 → 0.12.1

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.
Files changed (338) hide show
  1. package/Testing.md +1 -1
  2. package/bin/plugins/events/EventPlugin.ts +61 -0
  3. package/bin/plugins/events/assert.ts +193 -0
  4. package/bin/plugins/events/types.ts +6 -0
  5. package/bin/test.ts +8 -1
  6. package/build/src/amf/AmfShapeGenerator.d.ts +6 -3
  7. package/build/src/amf/AmfShapeGenerator.d.ts.map +1 -1
  8. package/build/src/amf/AmfShapeGenerator.js +7 -4
  9. package/build/src/amf/AmfShapeGenerator.js.map +1 -1
  10. package/build/src/amf/AmfTypes.d.ts +2 -2
  11. package/build/src/amf/AmfTypes.d.ts.map +1 -1
  12. package/build/src/amf/AmfTypes.js.map +1 -1
  13. package/build/src/amf/DataValueGenerator.d.ts +15 -15
  14. package/build/src/amf/DataValueGenerator.d.ts.map +1 -1
  15. package/build/src/amf/DataValueGenerator.js +17 -16
  16. package/build/src/amf/DataValueGenerator.js.map +1 -1
  17. package/build/src/amf/models/AmfDataNode.d.ts.map +1 -1
  18. package/build/src/amf/models/AmfDataNode.js +2 -2
  19. package/build/src/amf/models/AmfDataNode.js.map +1 -1
  20. package/build/src/browser.d.ts +12 -9
  21. package/build/src/browser.d.ts.map +1 -1
  22. package/build/src/browser.js +11 -8
  23. package/build/src/browser.js.map +1 -1
  24. package/build/src/exceptions/attach_exception.d.ts +11 -0
  25. package/build/src/exceptions/attach_exception.d.ts.map +1 -0
  26. package/build/src/exceptions/attach_exception.js +11 -0
  27. package/build/src/exceptions/attach_exception.js.map +1 -0
  28. package/build/src/exceptions/detach_exception.d.ts +11 -0
  29. package/build/src/exceptions/detach_exception.d.ts.map +1 -0
  30. package/build/src/exceptions/detach_exception.js +11 -0
  31. package/build/src/exceptions/detach_exception.js.map +1 -0
  32. package/build/src/exceptions/remove_model_exception.d.ts +8 -0
  33. package/build/src/exceptions/remove_model_exception.d.ts.map +1 -0
  34. package/build/src/exceptions/remove_model_exception.js +8 -0
  35. package/build/src/exceptions/remove_model_exception.js.map +1 -0
  36. package/build/src/exceptions/remove_namespace_exception.d.ts +8 -0
  37. package/build/src/exceptions/remove_namespace_exception.d.ts.map +1 -0
  38. package/build/src/exceptions/remove_namespace_exception.js +8 -0
  39. package/build/src/exceptions/remove_namespace_exception.js.map +1 -0
  40. package/build/src/index.d.ts +12 -9
  41. package/build/src/index.d.ts.map +1 -1
  42. package/build/src/index.js +11 -8
  43. package/build/src/index.js.map +1 -1
  44. package/build/src/legacy.d.ts +8 -0
  45. package/build/src/legacy.d.ts.map +1 -1
  46. package/build/src/legacy.js +9 -0
  47. package/build/src/legacy.js.map +1 -1
  48. package/build/src/lib/uuid.d.ts +1 -1
  49. package/build/src/lib/uuid.js +1 -1
  50. package/build/src/lib/uuid.js.map +1 -1
  51. package/build/src/mocking/lib/History.js +8 -8
  52. package/build/src/mocking/lib/History.js.map +1 -1
  53. package/build/src/mocking/lib/HostRules.js +1 -1
  54. package/build/src/mocking/lib/HostRules.js.map +1 -1
  55. package/build/src/mocking/lib/User.js +2 -2
  56. package/build/src/mocking/lib/User.js.map +1 -1
  57. package/build/src/modeling/Bindings.d.ts +2 -2
  58. package/build/src/modeling/Bindings.d.ts.map +1 -1
  59. package/build/src/modeling/Bindings.js.map +1 -1
  60. package/build/src/modeling/DataDomain.d.ts +601 -0
  61. package/build/src/modeling/DataDomain.d.ts.map +1 -0
  62. package/build/src/modeling/DataDomain.js +1141 -0
  63. package/build/src/modeling/DataDomain.js.map +1 -0
  64. package/build/src/modeling/DataFormat.d.ts +42 -41
  65. package/build/src/modeling/DataFormat.d.ts.map +1 -1
  66. package/build/src/modeling/DataFormat.js +30 -131
  67. package/build/src/modeling/DataFormat.js.map +1 -1
  68. package/build/src/modeling/DomainAssociation.d.ts +281 -0
  69. package/build/src/modeling/DomainAssociation.d.ts.map +1 -0
  70. package/build/src/modeling/DomainAssociation.js +440 -0
  71. package/build/src/modeling/DomainAssociation.js.map +1 -0
  72. package/build/src/modeling/DomainElement.d.ts +33 -0
  73. package/build/src/modeling/DomainElement.d.ts.map +1 -0
  74. package/build/src/modeling/DomainElement.js +32 -0
  75. package/build/src/modeling/DomainElement.js.map +1 -0
  76. package/build/src/modeling/DomainEntity.d.ts +383 -0
  77. package/build/src/modeling/DomainEntity.d.ts.map +1 -0
  78. package/build/src/modeling/DomainEntity.js +718 -0
  79. package/build/src/modeling/DomainEntity.js.map +1 -0
  80. package/build/src/modeling/DomainFile.d.ts +25 -0
  81. package/build/src/modeling/DomainFile.d.ts.map +1 -0
  82. package/build/src/modeling/DomainFile.js +86 -0
  83. package/build/src/modeling/DomainFile.js.map +1 -0
  84. package/build/src/modeling/DomainImpactAnalysis.d.ts +60 -47
  85. package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
  86. package/build/src/modeling/DomainImpactAnalysis.js +201 -132
  87. package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
  88. package/build/src/modeling/DomainModel.d.ts +226 -0
  89. package/build/src/modeling/DomainModel.d.ts.map +1 -0
  90. package/build/src/modeling/DomainModel.js +401 -0
  91. package/build/src/modeling/DomainModel.js.map +1 -0
  92. package/build/src/modeling/DomainNamespace.d.ts +268 -0
  93. package/build/src/modeling/DomainNamespace.d.ts.map +1 -0
  94. package/build/src/modeling/DomainNamespace.js +512 -0
  95. package/build/src/modeling/DomainNamespace.js.map +1 -0
  96. package/build/src/modeling/DomainProperty.d.ts +281 -0
  97. package/build/src/modeling/DomainProperty.d.ts.map +1 -0
  98. package/build/src/modeling/DomainProperty.js +560 -0
  99. package/build/src/modeling/DomainProperty.js.map +1 -0
  100. package/build/src/modeling/DomainSerialization.d.ts +40 -0
  101. package/build/src/modeling/DomainSerialization.d.ts.map +1 -0
  102. package/build/src/modeling/DomainSerialization.js +288 -0
  103. package/build/src/modeling/DomainSerialization.js.map +1 -0
  104. package/build/src/modeling/DomainVersioning.d.ts +17 -0
  105. package/build/src/modeling/DomainVersioning.d.ts.map +1 -0
  106. package/build/src/modeling/DomainVersioning.js +124 -0
  107. package/build/src/modeling/DomainVersioning.js.map +1 -0
  108. package/build/src/modeling/GraphUtils.d.ts +8 -0
  109. package/build/src/modeling/GraphUtils.d.ts.map +1 -0
  110. package/build/src/modeling/GraphUtils.js +26 -0
  111. package/build/src/modeling/GraphUtils.js.map +1 -0
  112. package/build/src/modeling/amf/ShapeGenerator.d.ts +164 -0
  113. package/build/src/modeling/amf/ShapeGenerator.d.ts.map +1 -0
  114. package/build/src/modeling/amf/ShapeGenerator.js +492 -0
  115. package/build/src/modeling/amf/ShapeGenerator.js.map +1 -0
  116. package/build/src/modeling/{DataAssociation.d.ts → legacy/DataAssociation.d.ts} +10 -5
  117. package/build/src/modeling/legacy/DataAssociation.d.ts.map +1 -0
  118. package/build/src/modeling/{DataAssociation.js → legacy/DataAssociation.js} +11 -8
  119. package/build/src/modeling/legacy/DataAssociation.js.map +1 -0
  120. package/build/src/modeling/{DataEntity.d.ts → legacy/DataEntity.d.ts} +12 -7
  121. package/build/src/modeling/legacy/DataEntity.d.ts.map +1 -0
  122. package/build/src/modeling/{DataEntity.js → legacy/DataEntity.js} +21 -20
  123. package/build/src/modeling/legacy/DataEntity.js.map +1 -0
  124. package/build/src/modeling/{DataEntityBuilder.d.ts → legacy/DataEntityBuilder.d.ts} +3 -2
  125. package/build/src/modeling/legacy/DataEntityBuilder.d.ts.map +1 -0
  126. package/build/src/modeling/{DataEntityBuilder.js → legacy/DataEntityBuilder.js} +4 -3
  127. package/build/src/modeling/legacy/DataEntityBuilder.js.map +1 -0
  128. package/build/src/modeling/legacy/DataImpactAnalysis.d.ts +298 -0
  129. package/build/src/modeling/legacy/DataImpactAnalysis.d.ts.map +1 -0
  130. package/build/src/modeling/legacy/DataImpactAnalysis.js +441 -0
  131. package/build/src/modeling/legacy/DataImpactAnalysis.js.map +1 -0
  132. package/build/src/modeling/{DataModel.d.ts → legacy/DataModel.d.ts} +6 -4
  133. package/build/src/modeling/legacy/DataModel.d.ts.map +1 -0
  134. package/build/src/modeling/{DataModel.js → legacy/DataModel.js} +9 -8
  135. package/build/src/modeling/legacy/DataModel.js.map +1 -0
  136. package/build/src/modeling/{DataNamespace.d.ts → legacy/DataNamespace.d.ts} +22 -3
  137. package/build/src/modeling/legacy/DataNamespace.d.ts.map +1 -0
  138. package/build/src/modeling/{DataNamespace.js → legacy/DataNamespace.js} +9 -5
  139. package/build/src/modeling/legacy/DataNamespace.js.map +1 -0
  140. package/build/src/modeling/{DataProperty.d.ts → legacy/DataProperty.d.ts} +13 -5
  141. package/build/src/modeling/legacy/DataProperty.d.ts.map +1 -0
  142. package/build/src/modeling/{DataProperty.js → legacy/DataProperty.js} +10 -7
  143. package/build/src/modeling/legacy/DataProperty.js.map +1 -0
  144. package/build/src/modeling/observed.d.ts +67 -0
  145. package/build/src/modeling/observed.d.ts.map +1 -0
  146. package/build/src/modeling/observed.js +230 -0
  147. package/build/src/modeling/observed.js.map +1 -0
  148. package/build/src/modeling/types.d.ts +165 -1
  149. package/build/src/modeling/types.d.ts.map +1 -1
  150. package/build/src/modeling/types.js.map +1 -1
  151. package/build/src/models/AuthorizationData.js +3 -3
  152. package/build/src/models/AuthorizationData.js.map +1 -1
  153. package/build/src/models/CertificateFile.js +2 -2
  154. package/build/src/models/CertificateFile.js.map +1 -1
  155. package/build/src/models/ClientCertificate.js +5 -5
  156. package/build/src/models/ClientCertificate.js.map +1 -1
  157. package/build/src/models/Environment.js +6 -6
  158. package/build/src/models/Environment.js.map +1 -1
  159. package/build/src/models/Folder.js +2 -2
  160. package/build/src/models/Folder.js.map +1 -1
  161. package/build/src/models/HostRule.js +4 -4
  162. package/build/src/models/HostRule.js.map +1 -1
  163. package/build/src/models/HttpProject.js +12 -12
  164. package/build/src/models/HttpProject.js.map +1 -1
  165. package/build/src/models/Project.d.ts.map +1 -1
  166. package/build/src/models/Project.js +2 -2
  167. package/build/src/models/Project.js.map +1 -1
  168. package/build/src/models/ProjectFolder.d.ts.map +1 -1
  169. package/build/src/models/ProjectFolder.js +6 -6
  170. package/build/src/models/ProjectFolder.js.map +1 -1
  171. package/build/src/models/ProjectRequest.d.ts.map +1 -1
  172. package/build/src/models/ProjectRequest.js +8 -8
  173. package/build/src/models/ProjectRequest.js.map +1 -1
  174. package/build/src/models/ProjectSchema.js +6 -6
  175. package/build/src/models/ProjectSchema.js.map +1 -1
  176. package/build/src/models/Thing.d.ts +26 -5
  177. package/build/src/models/Thing.d.ts.map +1 -1
  178. package/build/src/models/Thing.js +193 -91
  179. package/build/src/models/Thing.js.map +1 -1
  180. package/build/src/models/kinds.d.ts +31 -6
  181. package/build/src/models/kinds.d.ts.map +1 -1
  182. package/build/src/models/kinds.js +31 -6
  183. package/build/src/models/kinds.js.map +1 -1
  184. package/build/src/models/store/DataFile.d.ts +3 -1
  185. package/build/src/models/store/DataFile.d.ts.map +1 -1
  186. package/build/src/models/store/DataFile.js +4 -2
  187. package/build/src/models/store/DataFile.js.map +1 -1
  188. package/build/src/models/store/File.d.ts.map +1 -1
  189. package/build/src/models/store/File.js +3 -3
  190. package/build/src/models/store/File.js.map +1 -1
  191. package/build/src/models/store/Organization.js +3 -3
  192. package/build/src/models/store/Organization.js.map +1 -1
  193. package/build/src/models/store/Permission.js +7 -7
  194. package/build/src/models/store/Permission.js.map +1 -1
  195. package/build/src/models/store/UserIdentity.js +3 -3
  196. package/build/src/models/store/UserIdentity.js.map +1 -1
  197. package/build/src/models/transformers/ArcDexieTransformer.js +4 -4
  198. package/build/src/models/transformers/ArcDexieTransformer.js.map +1 -1
  199. package/build/src/models/transformers/ArcLegacyTransformer.js +3 -3
  200. package/build/src/models/transformers/ArcLegacyTransformer.js.map +1 -1
  201. package/build/src/models/transformers/ArcPouchTransformer.js +2 -2
  202. package/build/src/models/transformers/ArcPouchTransformer.js.map +1 -1
  203. package/build/src/models/transformers/PostmanV21Transformer.js +2 -2
  204. package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
  205. package/build/src/models/transformers/PostmanV2Transformer.js +2 -2
  206. package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
  207. package/build/src/models/types.d.ts +12 -0
  208. package/build/src/models/types.d.ts.map +1 -0
  209. package/build/src/models/types.js +2 -0
  210. package/build/src/models/types.js.map +1 -0
  211. package/build/src/patch/PatchClient.js +2 -2
  212. package/build/src/patch/PatchClient.js.map +1 -1
  213. package/build/src/runtime/store/FilesSdk.d.ts +2 -2
  214. package/build/src/runtime/store/FilesSdk.d.ts.map +1 -1
  215. package/build/src/runtime/store/FilesSdk.js +3 -3
  216. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  217. package/data/models/example-generator-api.json +8 -8
  218. package/package.json +20 -6
  219. package/readme.md +1 -1
  220. package/src/amf/AmfShapeGenerator.ts +10 -7
  221. package/src/amf/AmfTypes.ts +2 -2
  222. package/src/amf/DataValueGenerator.ts +24 -23
  223. package/src/amf/models/AmfDataNode.ts +2 -2
  224. package/src/exceptions/attach_exception.ts +11 -0
  225. package/src/exceptions/detach_exception.ts +11 -0
  226. package/src/exceptions/remove_model_exception.ts +8 -0
  227. package/src/exceptions/remove_namespace_exception.ts +8 -0
  228. package/src/lib/uuid.ts +1 -1
  229. package/src/mocking/lib/History.ts +8 -8
  230. package/src/mocking/lib/HostRules.ts +1 -1
  231. package/src/mocking/lib/User.ts +2 -2
  232. package/src/modeling/Bindings.ts +2 -2
  233. package/src/modeling/DataDomain.ts +1220 -0
  234. package/src/modeling/DataFormat.ts +54 -163
  235. package/src/modeling/DomainAssociation.ts +476 -0
  236. package/src/modeling/DomainElement.ts +50 -0
  237. package/src/modeling/DomainEntity.ts +769 -0
  238. package/src/modeling/DomainFile.ts +94 -0
  239. package/src/modeling/DomainImpactAnalysis.ts +218 -144
  240. package/src/modeling/DomainModel.ts +421 -0
  241. package/src/modeling/DomainNamespace.ts +537 -0
  242. package/src/modeling/DomainProperty.ts +548 -0
  243. package/src/modeling/DomainSerialization.ts +312 -0
  244. package/src/modeling/DomainVersioning.ts +144 -0
  245. package/src/modeling/GraphUtils.ts +28 -0
  246. package/src/modeling/amf/ShapeGenerator.ts +552 -0
  247. package/src/modeling/graph.md +115 -0
  248. package/src/modeling/{DataAssociation.ts → legacy/DataAssociation.ts} +15 -10
  249. package/src/modeling/{DataEntity.ts → legacy/DataEntity.ts} +30 -25
  250. package/src/modeling/{DataEntityBuilder.ts → legacy/DataEntityBuilder.ts} +5 -4
  251. package/src/modeling/legacy/DataImpactAnalysis.ts +530 -0
  252. package/src/modeling/{DataModel.ts → legacy/DataModel.ts} +12 -10
  253. package/src/modeling/{DataNamespace.ts → legacy/DataNamespace.ts} +25 -7
  254. package/src/modeling/{DataProperty.ts → legacy/DataProperty.ts} +17 -9
  255. package/src/modeling/observed.ts +267 -0
  256. package/src/modeling/types.ts +174 -1
  257. package/src/models/AuthorizationData.ts +3 -3
  258. package/src/models/CertificateFile.ts +2 -2
  259. package/src/models/ClientCertificate.ts +5 -5
  260. package/src/models/Environment.ts +6 -6
  261. package/src/models/Folder.ts +2 -2
  262. package/src/models/HostRule.ts +4 -4
  263. package/src/models/HttpProject.ts +12 -12
  264. package/src/models/Project.ts +2 -2
  265. package/src/models/ProjectFolder.ts +6 -6
  266. package/src/models/ProjectRequest.ts +8 -8
  267. package/src/models/ProjectSchema.ts +6 -6
  268. package/src/models/Thing.ts +70 -5
  269. package/src/models/kinds.ts +32 -6
  270. package/src/models/store/DataFile.ts +5 -3
  271. package/src/models/store/File.ts +3 -3
  272. package/src/models/store/Organization.ts +3 -3
  273. package/src/models/store/Permission.ts +7 -7
  274. package/src/models/store/UserIdentity.ts +3 -3
  275. package/src/models/transformers/ArcDexieTransformer.ts +4 -4
  276. package/src/models/transformers/ArcLegacyTransformer.ts +3 -3
  277. package/src/models/transformers/ArcPouchTransformer.ts +2 -2
  278. package/src/models/transformers/PostmanV21Transformer.ts +2 -2
  279. package/src/models/transformers/PostmanV2Transformer.ts +2 -2
  280. package/src/models/types.ts +11 -0
  281. package/src/patch/PatchClient.ts +2 -2
  282. package/src/runtime/store/FilesSdk.ts +5 -5
  283. package/tests/unit/amf/data_value_generator.spec.ts +15 -15
  284. package/tests/unit/legacy-transformers/ARC-legacy-import.spec.ts +1 -1
  285. package/tests/unit/modeling/amf/shape_generator.spec.ts +1174 -0
  286. package/tests/unit/modeling/data_domain.spec.ts +444 -0
  287. package/tests/unit/modeling/data_domain_associations.spec.ts +279 -0
  288. package/tests/unit/modeling/data_domain_change_observers.spec.ts +681 -0
  289. package/tests/unit/modeling/data_domain_entities.spec.ts +449 -0
  290. package/tests/unit/modeling/data_domain_foreign.spec.ts +355 -0
  291. package/tests/unit/modeling/data_domain_models.spec.ts +658 -0
  292. package/tests/unit/modeling/data_domain_namespaces.spec.ts +668 -0
  293. package/tests/unit/modeling/data_domain_property.spec.ts +264 -0
  294. package/tests/unit/modeling/data_domain_serialization.spec.ts +294 -0
  295. package/tests/unit/modeling/domain.property.spec.ts +822 -0
  296. package/tests/unit/modeling/domain_asociation.spec.ts +643 -0
  297. package/tests/unit/modeling/domain_asociation_targets.spec.ts +350 -0
  298. package/tests/unit/modeling/domain_entity.spec.ts +730 -0
  299. package/tests/unit/modeling/domain_entity_associations.spec.ts +330 -0
  300. package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +988 -0
  301. package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +1451 -0
  302. package/tests/unit/modeling/domain_entity_fields.spec.ts +113 -0
  303. package/tests/unit/modeling/domain_entity_generators.spec.ts +20 -0
  304. package/tests/unit/modeling/domain_entity_parents.spec.ts +291 -0
  305. package/tests/unit/modeling/domain_entity_properties.spec.ts +305 -0
  306. package/tests/unit/modeling/{data_file.spec.ts → domain_file.spec.ts} +29 -85
  307. package/tests/unit/modeling/domain_impact_analysis.spec.ts +452 -0
  308. package/tests/unit/modeling/domain_model.spec.ts +568 -0
  309. package/tests/unit/modeling/domain_model_entities.spec.ts +408 -0
  310. package/tests/unit/modeling/domain_namespace.spec.ts +514 -0
  311. package/tests/unit/modeling/domain_namespace_models.spec.ts +324 -0
  312. package/tests/unit/modeling/domain_namespace_namespaces.spec.ts +404 -0
  313. package/tests/unit/modeling/domain_versioning.spec.ts +140 -0
  314. package/tests/unit/{amf → modeling/legacy}/amf_shape_generator.spec.ts +11 -11
  315. package/tests/unit/modeling/{data_association.spec.ts → legacy/data_association.spec.ts} +3 -11
  316. package/tests/unit/modeling/{data_entity.spec.ts → legacy/data_entity.spec.ts} +10 -8
  317. package/tests/unit/modeling/{data_entity_generator_json.spec.ts → legacy/data_entity_generator_json.spec.ts} +1 -1
  318. package/tests/unit/modeling/{data_entity_generator_xml.spec.ts → legacy/data_entity_generator_xml.spec.ts} +1 -1
  319. package/tests/unit/modeling/{data_model.spec.ts → legacy/data_model.spec.ts} +3 -3
  320. package/tests/unit/modeling/{data_namespace.spec.ts → legacy/data_namespace.spec.ts} +3 -10
  321. package/tests/unit/modeling/{data_property.spec.ts → legacy/data_property.spec.ts} +3 -6
  322. package/tests/unit/modeling/{impact_analysis.spec.ts → legacy/impact_analysis.spec.ts} +9 -9
  323. package/tests/unit/models/File/new.spec.ts +1 -1
  324. package/tests/unit/models/HttpProject.spec.ts +3 -3
  325. package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +8 -8
  326. package/tsconfig.node.json +35 -0
  327. package/build/src/modeling/DataAssociation.d.ts.map +0 -1
  328. package/build/src/modeling/DataAssociation.js.map +0 -1
  329. package/build/src/modeling/DataEntity.d.ts.map +0 -1
  330. package/build/src/modeling/DataEntity.js.map +0 -1
  331. package/build/src/modeling/DataEntityBuilder.d.ts.map +0 -1
  332. package/build/src/modeling/DataEntityBuilder.js.map +0 -1
  333. package/build/src/modeling/DataModel.d.ts.map +0 -1
  334. package/build/src/modeling/DataModel.js.map +0 -1
  335. package/build/src/modeling/DataNamespace.d.ts.map +0 -1
  336. package/build/src/modeling/DataNamespace.js.map +0 -1
  337. package/build/src/modeling/DataProperty.d.ts.map +0 -1
  338. package/build/src/modeling/DataProperty.js.map +0 -1
@@ -0,0 +1,288 @@
1
+ import { Graph } from '@api-client/graph';
2
+ import { DomainAssociationKind, DomainEntityKind, DomainModelKind, DomainNamespaceKind, DomainPropertyKind, } from '../models/kinds.js';
3
+ import { DomainNamespace } from './DomainNamespace.js';
4
+ import { DomainModel } from './DomainModel.js';
5
+ import { DomainEntity } from './DomainEntity.js';
6
+ import { DomainProperty } from './DomainProperty.js';
7
+ import { DomainAssociation } from './DomainAssociation.js';
8
+ function writeNodes(g, domainKey) {
9
+ const result = [];
10
+ for (const v of g.nodes()) {
11
+ const nodeValue = g.node(v);
12
+ if (!nodeValue || nodeValue.domain.key !== domainKey) {
13
+ // Filter out foreign nodes
14
+ continue;
15
+ }
16
+ // We do only use single parent for the graph. Potentially this could be
17
+ // replaced with the `g.parent(v)` method.
18
+ const parents = [...g.parents(v)];
19
+ const node = { v };
20
+ node.value = nodeValue.toJSON();
21
+ if (parents.length) {
22
+ node.parents = parents;
23
+ }
24
+ result.push(node);
25
+ }
26
+ return result;
27
+ }
28
+ function writeEdges(g, domainKey) {
29
+ const result = [];
30
+ for (const e of g.edges()) {
31
+ const edgeValue = g.edge(e);
32
+ if (!edgeValue) {
33
+ continue;
34
+ }
35
+ const sourceNode = g.node(e.v);
36
+ const targetNode = g.node(e.w);
37
+ if (!sourceNode || !targetNode) {
38
+ continue;
39
+ }
40
+ if (sourceNode.domain.key !== domainKey) {
41
+ // Filter out edges starting from foreign nodes. These are foreign associations
42
+ // that have nothing to do with the current domain.
43
+ continue;
44
+ }
45
+ if (targetNode.domain.key !== domainKey && edgeValue.type !== 'association' && edgeValue.type !== 'parent') {
46
+ // Filter out edges to foreign nodes except for associations and parent-child relations
47
+ continue;
48
+ }
49
+ const edge = { v: e.v, w: e.w };
50
+ if (e.name) {
51
+ edge.name = e.name;
52
+ }
53
+ edge.value = structuredClone(edgeValue);
54
+ result.push(edge);
55
+ }
56
+ return result;
57
+ }
58
+ export function serialize(g, domainKey) {
59
+ const json = {
60
+ options: {
61
+ directed: g.isDirected(),
62
+ multigraph: g.isMultigraph(),
63
+ compound: g.isCompound(),
64
+ },
65
+ nodes: writeNodes(g, domainKey),
66
+ edges: writeEdges(g, domainKey),
67
+ };
68
+ return json;
69
+ }
70
+ /**
71
+ * Removes all foreign nodes, edges, and parents from the graph.
72
+ * @param g The graph to remove the foreign nodes from
73
+ * @param domainKey The key of the domain to remove
74
+ */
75
+ export function removeForeignGraph(g, domainKey) {
76
+ for (const node of g.nodes()) {
77
+ const nodeValue = g.node(node);
78
+ if (!nodeValue) {
79
+ continue;
80
+ }
81
+ if (nodeValue.domain.key === domainKey) {
82
+ // This is a foreign node, remove it from the graph.
83
+ g.removeNode(node);
84
+ // When a node is removed, all edges and parents are removed as well.
85
+ // No need to iterate over them.
86
+ }
87
+ }
88
+ }
89
+ /**
90
+ * Merges a foreign domain graph into the current domain graph.
91
+ * @param own Our domain graph
92
+ * @param foreign The foreign domain graph
93
+ * @param domain The key of the foreign domain
94
+ */
95
+ export function mergeGraph(own, foreign, domain) {
96
+ const nodes = new Set();
97
+ const edges = new Set();
98
+ // Copy nodes
99
+ for (const node of foreign.nodes()) {
100
+ const foreignNode = foreign.node(node);
101
+ if (!foreignNode) {
102
+ continue;
103
+ }
104
+ const foreignKey = `${domain}:${node}`;
105
+ own.setNode(foreignKey, foreignNode);
106
+ nodes.add(foreignKey);
107
+ }
108
+ // Copy edges
109
+ for (const edge of foreign.edges()) {
110
+ const label = foreign.edge(edge);
111
+ if (!label) {
112
+ continue;
113
+ }
114
+ const foreignSource = `${domain}:${edge.v}`;
115
+ const foreignTarget = `${domain}:${edge.w}`;
116
+ // const foreignEdge = foreign.edge(edge)
117
+ own.setEdge(foreignSource, foreignTarget, {
118
+ foreign: true,
119
+ domain,
120
+ ...label,
121
+ });
122
+ edges.add(`${foreignSource}|${foreignTarget}`);
123
+ }
124
+ const notRootEntities = new Set();
125
+ // Copy parent-child relationships
126
+ for (const node of foreign.nodes()) {
127
+ const foreignNodeKey = `${domain}:${node}`;
128
+ for (const parent of foreign.parents(node)) {
129
+ const foreignParentKey = `${domain}:${parent}`;
130
+ const srcNode = own.node(foreignNodeKey);
131
+ const targetNode = own.node(foreignParentKey);
132
+ if (srcNode.kind === DomainEntityKind && targetNode.kind === DomainEntityKind) {
133
+ // entities can have multiple parents between them. We need to respect that.
134
+ if (!notRootEntities.has(foreignNodeKey)) {
135
+ // We use `setParent` in the first run to remove the entity from the root
136
+ // of the graph.
137
+ notRootEntities.add(foreignNodeKey);
138
+ own.setParent(foreignNodeKey, foreignParentKey);
139
+ }
140
+ else {
141
+ own.addParent(foreignNodeKey, foreignParentKey);
142
+ }
143
+ }
144
+ else {
145
+ // other nodes can only have a single parent.
146
+ own.setParent(foreignNodeKey, foreignParentKey);
147
+ }
148
+ }
149
+ }
150
+ return {
151
+ nodes,
152
+ edges,
153
+ };
154
+ }
155
+ /**
156
+ * Properties and associations are stored as nodes with edges to the parent entity in the graph.
157
+ * At the time of restoring these nodes, the graph has no edges yet.
158
+ * This function finds the parent of the child node in the edges list.
159
+ * @param child The DomainProperty or DomainAssociation key
160
+ * @param edges The list of serialized graph edges
161
+ * @returns The parent key of the child or undefined if not found
162
+ */
163
+ function findEdgeParent(child, edges) {
164
+ for (const edge of edges) {
165
+ if (edge.w === child) {
166
+ return edge.v;
167
+ }
168
+ }
169
+ return undefined;
170
+ }
171
+ /**
172
+ * Restores the previously serialized node entry.
173
+ * @param root The DataDomain instance to use as the root for the graph
174
+ * @param entry The node entry to restore
175
+ * @param edges The list of serialized graph edges
176
+ * @returns The restored node instance
177
+ * @throws Error if the entry is malformed or the kind is unknown
178
+ */
179
+ function prepareNode(root, entry, edges) {
180
+ if (!entry) {
181
+ throw new Error(`Unable to restore data domain graph. Malformed node entry`);
182
+ }
183
+ const domainElement = entry;
184
+ if (!domainElement.kind) {
185
+ throw new Error(`Unable to restore data domain graph. Malformed node entry`);
186
+ }
187
+ if (domainElement.kind === DomainNamespaceKind) {
188
+ return new DomainNamespace(root, domainElement);
189
+ }
190
+ if (domainElement.kind === DomainModelKind) {
191
+ return new DomainModel(root, domainElement);
192
+ }
193
+ if (domainElement.kind === DomainEntityKind) {
194
+ return new DomainEntity(root, domainElement);
195
+ }
196
+ if (domainElement.kind === DomainPropertyKind) {
197
+ const typed = domainElement;
198
+ const parent = findEdgeParent(typed.key, edges);
199
+ if (!parent) {
200
+ throw new Error(`Unable to restore data domain graph. Malformed node entry`);
201
+ }
202
+ return new DomainProperty(root, parent, typed);
203
+ }
204
+ if (domainElement.kind === DomainAssociationKind) {
205
+ const typed = domainElement;
206
+ const parent = findEdgeParent(typed.key, edges);
207
+ if (!parent) {
208
+ throw new Error(`Unable to restore data domain graph. Malformed node entry`);
209
+ }
210
+ return new DomainAssociation(root, parent, typed);
211
+ }
212
+ throw new Error(`Unable to restore data domain graph. Unknown node kind ${domainElement.kind}`);
213
+ }
214
+ /**
215
+ * To deserialize a graph:
216
+ *
217
+ * - Create a new DataDomain instance
218
+ * - Restore all foreign nodes and edges
219
+ * - Call the deserialize function
220
+ *
221
+ * @param root The DataDomain instance to use as the root for the graph
222
+ * @param json The previously serialized graph
223
+ * @returns Deserialized graph instance
224
+ */
225
+ export function deserialize(root, json, dependencies) {
226
+ const g = new Graph({
227
+ compound: true,
228
+ multigraph: true,
229
+ directed: true,
230
+ });
231
+ let foreignNodes = new Set();
232
+ let foreignEdges = new Set();
233
+ if (dependencies) {
234
+ for (const dependency of dependencies) {
235
+ const result = mergeGraph(g, dependency.graph, dependency.key);
236
+ if (result.edges.size) {
237
+ foreignEdges = new Set([...foreignEdges, ...result.edges]);
238
+ }
239
+ if (result.nodes.size) {
240
+ foreignNodes = new Set([...foreignNodes, ...result.nodes]);
241
+ }
242
+ root.dependencies.set(dependency.key, dependency);
243
+ }
244
+ }
245
+ if (!json) {
246
+ return g;
247
+ }
248
+ if (Array.isArray(json.nodes)) {
249
+ for (const entry of json.nodes) {
250
+ g.setNode(entry.v, prepareNode(root, entry.value, json.edges));
251
+ 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
+ }
262
+ }
263
+ }
264
+ }
265
+ if (Array.isArray(json.edges)) {
266
+ for (const entry of json.edges) {
267
+ if (!entry.value) {
268
+ throw new Error(`Unable to restore data domain graph. Malformed edge entry`);
269
+ }
270
+ if (entry.value.foreign) {
271
+ // The `v` has to be local to the graph. The `w` must be foreign.
272
+ if (!foreignNodes.has(entry.w)) {
273
+ // console.warn(`Missing foreign node: ${entry.w}. Skipping edge.`)
274
+ continue;
275
+ }
276
+ }
277
+ if (foreignNodes.has(entry.v) || foreignNodes.has(entry.w)) {
278
+ if (!g.hasNode(entry.v) || !g.hasNode(entry.w)) {
279
+ // console.warn(`Missing foreign node: ${entry.v} or ${entry.w}. Skipping edge.`)
280
+ continue;
281
+ }
282
+ }
283
+ g.setEdge({ v: entry.v, w: entry.w, name: entry.name }, entry.value);
284
+ }
285
+ }
286
+ return g;
287
+ }
288
+ //# sourceMappingURL=DomainSerialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DomainSerialization.js","sourceRoot":"","sources":["../../../src/modeling/DomainSerialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,mBAAmB,CAAA;AAEzD,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,M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B,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 { Graph, JsonEdge, Node } from '@api-client/graph'\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"]}
@@ -0,0 +1,17 @@
1
+ import type { DataDomain } from './DataDomain.js';
2
+ import type { SerializedGraph } from './types.js';
3
+ /**
4
+ * Serializes a DataDomain for version release, including only relevant foreign nodes.
5
+ * @param root The DataDomain to serialize.
6
+ * @param version The version to set in the serialized graph. This mutates the DataDomain.
7
+ * @returns The serialized graph with the version set.
8
+ */
9
+ export declare function createGraphVersion(root: DataDomain, version: string): SerializedGraph;
10
+ /**
11
+ * Serializes a DataDomain for version release, including only relevant foreign nodes.
12
+ *
13
+ * @param dataDomain The DataDomain to serialize.
14
+ * @returns A SerializedGraph containing the versioned data.
15
+ */
16
+ export declare function serializeForVersionRelease(dataDomain: DataDomain): SerializedGraph;
17
+ //# sourceMappingURL=DomainVersioning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DomainVersioning.d.ts","sourceRoot":"","sources":["../../../src/modeling/DomainVersioning.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAoC,eAAe,EAAE,MAAM,YAAY,CAAA;AAEnF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,eAAe,CAGrF;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,UAAU,GAAG,eAAe,CAyElF"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Serializes a DataDomain for version release, including only relevant foreign nodes.
3
+ * @param root The DataDomain to serialize.
4
+ * @param version The version to set in the serialized graph. This mutates the DataDomain.
5
+ * @returns The serialized graph with the version set.
6
+ */
7
+ export function createGraphVersion(root, version) {
8
+ root.info.version = version;
9
+ return serializeForVersionRelease(root);
10
+ }
11
+ /**
12
+ * Serializes a DataDomain for version release, including only relevant foreign nodes.
13
+ *
14
+ * @param dataDomain The DataDomain to serialize.
15
+ * @returns A SerializedGraph containing the versioned data.
16
+ */
17
+ export function serializeForVersionRelease(dataDomain) {
18
+ const { graph, key: domainKey } = dataDomain;
19
+ const relevantForeignNodes = new Set();
20
+ // 1. Identify relevant foreign nodes: those connected to local entities.
21
+ for (const node of graph.nodes()) {
22
+ const nodeValue = graph.node(node);
23
+ if (!nodeValue) {
24
+ continue;
25
+ }
26
+ if (nodeValue.domain.key === domainKey) {
27
+ continue; // Skip local nodes
28
+ }
29
+ // Check if the foreign node is connected to a local node (directly or indirectly).
30
+ if (isConnectedToLocal(graph, node, domainKey)) {
31
+ relevantForeignNodes.add(node);
32
+ }
33
+ }
34
+ // 2. Filter nodes and edges based on relevance.
35
+ const nodes = [];
36
+ const edges = [];
37
+ for (const node of graph.nodes()) {
38
+ const nodeValue = graph.node(node);
39
+ if (!nodeValue) {
40
+ continue;
41
+ }
42
+ if (nodeValue.domain.key === domainKey || relevantForeignNodes.has(node)) {
43
+ const parents = [...graph.parents(node)];
44
+ const serializedNode = { v: node, value: nodeValue.toJSON() };
45
+ if (parents.length) {
46
+ serializedNode.parents = parents;
47
+ }
48
+ nodes.push(serializedNode);
49
+ }
50
+ }
51
+ for (const edge of graph.edges()) {
52
+ const edgeValue = graph.edge(edge);
53
+ if (!edgeValue)
54
+ continue;
55
+ const sourceNode = graph.node(edge.v);
56
+ const targetNode = graph.node(edge.w);
57
+ if (!sourceNode || !targetNode)
58
+ continue;
59
+ const isSourceRelevant = sourceNode.domain.key === domainKey || relevantForeignNodes.has(edge.v);
60
+ const isTargetRelevant = targetNode.domain.key === domainKey || relevantForeignNodes.has(edge.w);
61
+ if (isSourceRelevant && isTargetRelevant) {
62
+ const serializedEdge = { v: edge.v, w: edge.w, value: structuredClone(edgeValue) };
63
+ if (edge.name) {
64
+ serializedEdge.name = edge.name;
65
+ }
66
+ edges.push(serializedEdge);
67
+ }
68
+ }
69
+ // 3. Construct the SerializedGraph.
70
+ const json = {
71
+ options: {
72
+ directed: graph.isDirected(),
73
+ multigraph: graph.isMultigraph(),
74
+ compound: graph.isCompound(),
75
+ },
76
+ nodes,
77
+ edges,
78
+ };
79
+ return json;
80
+ }
81
+ /**
82
+ * Checks if a foreign node is connected to a local node (directly or indirectly).
83
+ *
84
+ * This function performs a breadth-first search (BFS) to determine if a foreign node
85
+ * is connected to any local node.
86
+ *
87
+ * @param g The DataDomain graph.
88
+ * @param node The key of the foreign node to check.
89
+ * @param domainKey The key of the local domain.
90
+ * @returns True if the foreign node is connected to a local node.
91
+ */
92
+ function isConnectedToLocal(g, node, domainKey) {
93
+ const visited = new Set();
94
+ const queue = [node];
95
+ while (queue.length > 0) {
96
+ const current = queue.shift();
97
+ if (visited.has(current)) {
98
+ continue;
99
+ }
100
+ visited.add(current);
101
+ const value = g.node(current);
102
+ if (!value) {
103
+ continue;
104
+ }
105
+ if (value.domain.key === domainKey) {
106
+ // It means the foreign node is connected to a local node.
107
+ return true;
108
+ }
109
+ // Explore adjacent nodes (both incoming and outgoing edges).
110
+ for (const edge of g.inEdges(current)) {
111
+ queue.push(edge.v);
112
+ }
113
+ for (const edge of g.outEdges(current)) {
114
+ const label = g.edge(edge);
115
+ let id = edge.w;
116
+ if (label?.foreign) {
117
+ id = `${label.domain}:${edge.w}`;
118
+ }
119
+ queue.push(id);
120
+ }
121
+ }
122
+ return false; // No connection to a local node found.
123
+ }
124
+ //# sourceMappingURL=DomainVersioning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DomainVersioning.js","sourceRoot":"","sources":["../../../src/modeling/DomainVersioning.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAgB,EAAE,OAAe;IAClE,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC3B,OAAO,0BAA0B,CAAC,IAAI,CAAC,CAAA;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,UAAsB;IAC/D,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,SA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,CAAC,CAAC,EAAE,CAAA;YAClC,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAChB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA,CAAC,uCAAuC;AACtD,CAAC","sourcesContent":["import type { JsonEdge, Node } from '@api-client/graph'\nimport type { DataDomain } from './DataDomain.js'\nimport type { DomainGraphEdge, DataDomainGraph, SerializedGraph } from './types.js'\n\n/**\n * Serializes a DataDomain for version release, including only relevant foreign nodes.\n * @param root The DataDomain to serialize.\n * @param version The version to set in the serialized graph. This mutates the DataDomain.\n * @returns The serialized graph with the version set.\n */\nexport function createGraphVersion(root: DataDomain, version: string): SerializedGraph {\n root.info.version = version\n return serializeForVersionRelease(root)\n}\n\n/**\n * Serializes a DataDomain for version release, including only relevant foreign nodes.\n *\n * @param dataDomain The DataDomain to serialize.\n * @returns A SerializedGraph containing the versioned data.\n */\nexport function serializeForVersionRelease(dataDomain: DataDomain): SerializedGraph {\n const { graph, key: domainKey } = dataDomain\n const relevantForeignNodes = new Set<string>()\n\n // 1. Identify relevant foreign nodes: those connected to local entities.\n for (const node of graph.nodes()) {\n const nodeValue = graph.node(node)\n if (!nodeValue) {\n continue\n }\n if (nodeValue.domain.key === domainKey) {\n continue // Skip local nodes\n }\n\n // Check if the foreign node is connected to a local node (directly or indirectly).\n if (isConnectedToLocal(graph, node, domainKey)) {\n relevantForeignNodes.add(node)\n }\n }\n\n // 2. Filter nodes and edges based on relevance.\n const nodes = []\n const edges = []\n\n for (const node of graph.nodes()) {\n const nodeValue = graph.node(node)\n if (!nodeValue) {\n continue\n }\n\n if (nodeValue.domain.key === domainKey || relevantForeignNodes.has(node)) {\n const parents = [...graph.parents(node)]\n const serializedNode: Node<object> = { v: node, value: nodeValue.toJSON() }\n if (parents.length) {\n serializedNode.parents = parents\n }\n nodes.push(serializedNode)\n }\n }\n\n for (const edge of graph.edges()) {\n const edgeValue = graph.edge(edge)\n if (!edgeValue) continue\n\n const sourceNode = graph.node(edge.v)\n const targetNode = graph.node(edge.w)\n\n if (!sourceNode || !targetNode) continue\n\n const isSourceRelevant = sourceNode.domain.key === domainKey || relevantForeignNodes.has(edge.v)\n const isTargetRelevant = targetNode.domain.key === domainKey || relevantForeignNodes.has(edge.w)\n\n if (isSourceRelevant && isTargetRelevant) {\n const serializedEdge: JsonEdge<DomainGraphEdge> = { v: edge.v, w: edge.w, value: structuredClone(edgeValue) }\n if (edge.name) {\n serializedEdge.name = edge.name\n }\n edges.push(serializedEdge)\n }\n }\n\n // 3. Construct the SerializedGraph.\n const json: SerializedGraph = {\n options: {\n directed: graph.isDirected(),\n multigraph: graph.isMultigraph(),\n compound: graph.isCompound(),\n },\n nodes,\n edges,\n }\n\n return json\n}\n\n/**\n * Checks if a foreign node is connected to a local node (directly or indirectly).\n *\n * This function performs a breadth-first search (BFS) to determine if a foreign node\n * is connected to any local node.\n *\n * @param g The DataDomain graph.\n * @param node The key of the foreign node to check.\n * @param domainKey The key of the local domain.\n * @returns True if the foreign node is connected to a local node.\n */\nfunction isConnectedToLocal(g: DataDomainGraph, node: string, domainKey: string): boolean {\n const visited = new Set<string>()\n const queue: string[] = [node]\n\n while (queue.length > 0) {\n const current = queue.shift() as string\n if (visited.has(current)) {\n continue\n }\n visited.add(current)\n\n const value = g.node(current)\n if (!value) {\n continue\n }\n\n if (value.domain.key === domainKey) {\n // It means the foreign node is connected to a local node.\n return true\n }\n\n // Explore adjacent nodes (both incoming and outgoing edges).\n for (const edge of g.inEdges(current)) {\n queue.push(edge.v)\n }\n for (const edge of g.outEdges(current)) {\n const label = g.edge(edge)\n let id = edge.w\n if (label?.foreign) {\n id = `${label.domain}:${edge.w}`\n }\n queue.push(id)\n }\n }\n\n return false // No connection to a local node found.\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { Graph } from '@api-client/graph';
2
+ import type { DomainGraphEdge, DomainGraphNodeType } from './types.js';
3
+ /**
4
+ * Recursively removes a node and all its children from the graph.
5
+ * @param key The key of the node to remove.
6
+ */
7
+ export declare function removeGraphNode(graph: Graph<unknown, DomainGraphNodeType, DomainGraphEdge>, key: string): void;
8
+ //# sourceMappingURL=GraphUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphUtils.d.ts","sourceRoot":"","sources":["../../../src/modeling/GraphUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAEtE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,mBAAmB,EAAE,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAoB9G"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Recursively removes a node and all its children from the graph.
3
+ * @param key The key of the node to remove.
4
+ */
5
+ export function removeGraphNode(graph, key) {
6
+ if (!graph.hasNode(key)) {
7
+ return;
8
+ }
9
+ for (const child of graph.children(key)) {
10
+ removeGraphNode(graph, child);
11
+ }
12
+ for (const edge of graph.outEdges(key)) {
13
+ const label = graph.edge(edge);
14
+ if (!label) {
15
+ continue;
16
+ }
17
+ // While associations should be associated with the entity through an edge,
18
+ // I am still on a fence about properties being the same...
19
+ // We won't be reusing properties within a domain model.
20
+ if (['property', 'association'].includes(label.type)) {
21
+ removeGraphNode(graph, edge.w);
22
+ }
23
+ }
24
+ graph.removeNode(key);
25
+ }
26
+ //# sourceMappingURL=GraphUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphUtils.js","sourceRoot":"","sources":["../../../src/modeling/GraphUtils.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAA2D,EAAE,GAAW;IACtG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,OAAM;IACR,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxC,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC/B,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,SAAQ;QACV,CAAC;QACD,2EAA2E;QAC3E,2DAA2D;QAC3D,wDAAwD;QACxD,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACrD,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;QAChC,CAAC;IACH,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC","sourcesContent":["import type { Graph } from '@api-client/graph'\nimport type { DomainGraphEdge, DomainGraphNodeType } from './types.js'\n\n/**\n * Recursively removes a node and all its children from the graph.\n * @param key The key of the node to remove.\n */\nexport function removeGraphNode(graph: Graph<unknown, DomainGraphNodeType, DomainGraphEdge>, key: string): void {\n if (!graph.hasNode(key)) {\n return\n }\n for (const child of graph.children(key)) {\n removeGraphNode(graph, child)\n }\n for (const edge of graph.outEdges(key)) {\n const label = graph.edge(edge)\n if (!label) {\n continue\n }\n // While associations should be associated with the entity through an edge,\n // I am still on a fence about properties being the same...\n // We won't be reusing properties within a domain model.\n if (['property', 'association'].includes(label.type)) {\n removeGraphNode(graph, edge.w)\n }\n }\n graph.removeNode(key)\n}\n"]}