@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,548 @@
1
+ import type { DataDomain } from './DataDomain.js'
2
+ import { DomainPropertyKind } from '../models/kinds.js'
3
+ import { DomainElement, type DomainElementSchema } from './DomainElement.js'
4
+ import { nanoid } from 'nanoid'
5
+ import { type IThing, Thing } from '../models/Thing.js'
6
+ import { observed, retargetChange, toRaw } from './observed.js'
7
+ import {
8
+ type BinaryFormat,
9
+ BinaryFormats,
10
+ type DomainPropertyAttribute,
11
+ DomainPropertyAttributes,
12
+ type DomainPropertyFormat,
13
+ DomainPropertyList,
14
+ type DomainPropertyType,
15
+ DomainPropertyTypes,
16
+ type NumberFormat,
17
+ NumberFormats,
18
+ } from './DataFormat.js'
19
+ import type { PropertyBinding, PropertyBindings, PropertyWebBindings } from './Bindings.js'
20
+ import type { ModelValidationOptions } from '../models/types.js'
21
+ import type { DomainEntity } from './DomainEntity.js'
22
+ import type { IApiPropertyShape } from '../amf/definitions/Shapes.js'
23
+ import { ShapeGenerator } from './amf/ShapeGenerator.js'
24
+ import { PropertySchema } from './types.js'
25
+
26
+ export interface DomainPropertySchema extends DomainElementSchema {
27
+ kind: typeof DomainPropertyKind
28
+ /**
29
+ * The domain property description.
30
+ */
31
+ info: IThing
32
+ /**
33
+ * Wether the data property is required.
34
+ */
35
+ required?: boolean
36
+ /**
37
+ * Whether the data property allows multiple items.
38
+ */
39
+ multiple?: boolean
40
+ /**
41
+ * Whether this property describes a primary key of the entity.
42
+ */
43
+ primary?: boolean
44
+ /**
45
+ * Whether this property describes an indexed property of the entity.
46
+ */
47
+ index?: boolean
48
+ /**
49
+ * Whether the property is read only in the schema.
50
+ */
51
+ readOnly?: boolean
52
+ /**
53
+ * Whether the property is write only in the schema.
54
+ */
55
+ writeOnly?: boolean
56
+ /**
57
+ * Whether this property is deprecated.
58
+ */
59
+ deprecated?: boolean
60
+ /**
61
+ * Optional general purpose tags for the UI.
62
+ */
63
+ tags?: string[]
64
+ /**
65
+ * For future use.
66
+ *
67
+ * The keys of the taxonomy items associated with the property.
68
+ */
69
+ taxonomy?: string[]
70
+ /**
71
+ * The data type for this property.
72
+ * Note, not all schemas support the same type. For example, defining `sint32`
73
+ * works for protocol buffers, but does not for JSON. In such case we use default
74
+ * translation `sint32` -> `number`. Another way it to create
75
+ * a derivative entity for specific schema to describe specific schema case.
76
+ */
77
+ type: DomainPropertyType
78
+ /**
79
+ * The general schema definition of this property.
80
+ * This is propagated to all bindings (when they support these properties).
81
+ */
82
+ schema?: PropertySchema
83
+ /**
84
+ * The list of bindings for this property.
85
+ *
86
+ * A binding defines a translation from a data model to a specific format.
87
+ * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs
88
+ * or a protocol buffer schema.
89
+ */
90
+ bindings?: PropertyBinding[]
91
+ }
92
+
93
+ /**
94
+ * Represents a property within a data domain entity.
95
+ *
96
+ * A `DomainProperty` defines a single data element within a
97
+ * `DomainEntity`. It specifies the data type, constraints,
98
+ * and other metadata for a specific piece of information.
99
+ *
100
+ * **Key Features:**
101
+ *
102
+ * - **Data Type:** Defines the type of data the property
103
+ * holds (e.g., string, number, boolean, date).
104
+ * - **Constraints:** Supports defining constraints such as
105
+ * minimum/maximum values, enum values, and default values.
106
+ * - **Bindings:** Allows defining how the property is
107
+ * represented in different formats (e.g., web APIs,
108
+ * protocol buffers).
109
+ * - **Metadata:** Supports metadata such as tags, taxonomy,
110
+ * read-only/write-only status, and deprecation.
111
+ * - **Schema:** Allows defining a general schema for the
112
+ * property, which is propagated to all bindings.
113
+ *
114
+ * **Usage:**
115
+ *
116
+ * Use the `DataEntity.addProperty` method to add a new property to an
117
+ * entity. The property can be created using the constructor, but it
118
+ * won't be added to the graph until you call the `addProperty` method.
119
+ *
120
+ * **Example:**
121
+ *
122
+ * ```typescript
123
+ * const entity = dataModel.addEntity({ key: 'user' });
124
+ * const property = entity.addProperty({
125
+ * key: 'name',
126
+ * type: 'string',
127
+ * required: true,
128
+ * schema: {
129
+ * minimum: 3,
130
+ * maximum: 50,
131
+ * },
132
+ * });
133
+ * ```
134
+ */
135
+ export class DomainProperty extends DomainElement {
136
+ override kind: typeof DomainPropertyKind
137
+
138
+ /**
139
+ * The description of the domain property.
140
+ */
141
+ @retargetChange() accessor info: Thing
142
+
143
+ /**
144
+ * Wether the data property is required.
145
+ */
146
+ @observed() accessor required: boolean | undefined
147
+
148
+ /**
149
+ * Whether the data property allows multiple items.
150
+ */
151
+ @observed() accessor multiple: boolean | undefined
152
+
153
+ /**
154
+ * Whether this property describes a primary key of the entity.
155
+ */
156
+ @observed() accessor primary: boolean | undefined
157
+
158
+ /**
159
+ * Whether this property describes an indexed property of the entity.
160
+ */
161
+ @observed() accessor index: boolean | undefined
162
+
163
+ /**
164
+ * Whether the property is read only in the schema.
165
+ */
166
+ @observed() accessor readOnly: boolean | undefined
167
+
168
+ /**
169
+ * Whether the property is write only in the schema.
170
+ */
171
+ @observed() accessor writeOnly: boolean | undefined
172
+
173
+ /**
174
+ * Whether this property is deprecated.
175
+ */
176
+ @observed() accessor deprecated: boolean | undefined
177
+
178
+ /**
179
+ * Optional general purpose tags for the UI.
180
+ *
181
+ * Note to implementations, use the `addTag()` method as it propagates the "tag" value in the namespace.
182
+ * Also, the tags property is excluded from the observer properties.
183
+ * Changes to this property will not notify the observers.
184
+ */
185
+ @observed({ deep: true }) accessor tags: string[] = []
186
+
187
+ /**
188
+ * Reserved for future use.
189
+ *
190
+ * The keys of the taxonomy items associated with the property.
191
+ */
192
+ @observed({ deep: true }) accessor taxonomy: string[] = []
193
+
194
+ /**
195
+ * The data type for this property.
196
+ * Note, not all schemas support the same type. For example, defining `sint32`
197
+ * works for protocol buffers but does not for JSON. In such case we use default
198
+ * translation `sint32` -> `number`. Another way it to create
199
+ * a derivative entity for specific schema to describe specific schema case.
200
+ */
201
+ @observed() accessor type: DomainPropertyType = 'string'
202
+
203
+ /**
204
+ * The general schema definition of this property.
205
+ * This is propagated to all bindings (when they support these properties).
206
+ */
207
+ @observed({ deep: true }) accessor schema: PropertySchema | undefined
208
+
209
+ /**
210
+ * The list of bindings for this property.
211
+ *
212
+ * A binding defines a translation from a data model to a specific format.
213
+ * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs
214
+ * or a protocol buffer schema.
215
+ */
216
+ @observed({ deep: true }) accessor bindings: PropertyBinding[] = []
217
+
218
+ /**
219
+ * Creates a full data model schema with defaults.
220
+ *
221
+ * @param input The partial data model schema.
222
+ * @returns The data model schema.
223
+ */
224
+ static createSchema(input: Partial<DomainPropertySchema> = {}): DomainPropertySchema {
225
+ const {
226
+ key = nanoid(),
227
+ multiple,
228
+ required,
229
+ type = DomainPropertyList.string,
230
+ index,
231
+ primary,
232
+ readOnly,
233
+ writeOnly,
234
+ tags,
235
+ taxonomy,
236
+ deprecated,
237
+ schema,
238
+ bindings,
239
+ } = input
240
+ if (typeof type === 'string') {
241
+ if (!DomainPropertyTypes.includes(type as DomainPropertyType)) {
242
+ throw new Error(`Invalid data property type ${type}`)
243
+ }
244
+ }
245
+ const info = Thing.fromJSON(input.info, { name: 'New property' }).toJSON()
246
+ const result: DomainPropertySchema = {
247
+ kind: DomainPropertyKind,
248
+ key,
249
+ info,
250
+ type,
251
+ }
252
+ if (typeof multiple === 'boolean') {
253
+ result.multiple = multiple
254
+ }
255
+ if (typeof required === 'boolean') {
256
+ result.required = required
257
+ }
258
+ if (typeof index === 'boolean') {
259
+ result.index = index
260
+ }
261
+ if (typeof primary === 'boolean') {
262
+ result.primary = primary
263
+ }
264
+ if (typeof readOnly === 'boolean') {
265
+ result.readOnly = readOnly
266
+ }
267
+ if (typeof writeOnly === 'boolean') {
268
+ result.writeOnly = writeOnly
269
+ }
270
+ if (typeof deprecated === 'boolean') {
271
+ result.deprecated = deprecated
272
+ }
273
+ if (Array.isArray(tags)) {
274
+ result.tags = [...tags]
275
+ }
276
+ if (Array.isArray(taxonomy)) {
277
+ result.taxonomy = [...taxonomy]
278
+ }
279
+ if (schema) {
280
+ result.schema = structuredClone(schema)
281
+ }
282
+ if (Array.isArray(bindings)) {
283
+ result.bindings = bindings.map((i) => structuredClone(i))
284
+ } else {
285
+ result.bindings = []
286
+ }
287
+ return result
288
+ }
289
+
290
+ /**
291
+ * The key of the parent entity.
292
+ */
293
+ protected parent: string
294
+
295
+ /**
296
+ * Creates a new domain property instance.
297
+ * It does not add it to the graph.
298
+ * You need to call the `addProperty` method of the graph or a data model to add it.
299
+ *
300
+ * Domain objects constructors shouldn't be used directly. Use methods
301
+ * provided on the DataDomain class to create new objects.
302
+ *
303
+ * @param root A reference to the root DataDomain instance.
304
+ * @param parent The key of the parent entity.
305
+ * @param input The partial domain property schema.
306
+ * @returns Created domain property instance.
307
+ */
308
+ constructor(root: DataDomain, parent: string, input: Partial<DomainPropertySchema> = {}) {
309
+ const init = DomainProperty.createSchema(input)
310
+ super(root, init.key)
311
+ this.parent = parent
312
+ this.kind = DomainPropertyKind
313
+ this.info = new Thing(init.info)
314
+ this.type = init.type
315
+
316
+ if (typeof init.multiple === 'boolean') {
317
+ this.multiple = init.multiple
318
+ } else {
319
+ this.multiple = undefined
320
+ }
321
+ if (typeof init.required === 'boolean') {
322
+ this.required = init.required
323
+ } else {
324
+ this.required = undefined
325
+ }
326
+ if (typeof init.index === 'boolean') {
327
+ this.index = init.index
328
+ } else {
329
+ this.index = undefined
330
+ }
331
+ if (typeof init.deprecated === 'boolean') {
332
+ this.deprecated = init.deprecated
333
+ } else {
334
+ this.deprecated = undefined
335
+ }
336
+ if (typeof init.primary === 'boolean') {
337
+ this.primary = init.primary
338
+ } else {
339
+ this.primary = undefined
340
+ }
341
+ if (typeof init.readOnly === 'boolean') {
342
+ this.readOnly = init.readOnly
343
+ } else {
344
+ this.readOnly = undefined
345
+ }
346
+ if (typeof init.writeOnly === 'boolean') {
347
+ this.writeOnly = init.writeOnly
348
+ } else {
349
+ this.writeOnly = undefined
350
+ }
351
+ if (Array.isArray(init.tags)) {
352
+ this.tags = [...init.tags]
353
+ } else {
354
+ this.tags = []
355
+ }
356
+ if (Array.isArray(init.taxonomy)) {
357
+ this.taxonomy = [...init.taxonomy]
358
+ } else {
359
+ this.taxonomy = []
360
+ }
361
+ if (init.schema) {
362
+ this.schema = structuredClone(init.schema)
363
+ } else {
364
+ this.schema = undefined
365
+ }
366
+ if (Array.isArray(init.bindings)) {
367
+ this.bindings = init.bindings.map((i) => structuredClone(i))
368
+ } else {
369
+ this.bindings = []
370
+ }
371
+ }
372
+
373
+ /**
374
+ * Checks whether the input is a valid definition of a domain property.
375
+ *
376
+ * @param input The input to validate.
377
+ * @param options Validation options.
378
+ * @returns true when the passed input is a valid definition of a domain property.
379
+ */
380
+ static validate(input: unknown, options: ModelValidationOptions = {}): boolean {
381
+ if (!input || (typeof input !== 'object' && input !== null)) {
382
+ return false
383
+ }
384
+ const typed = input as DomainPropertySchema
385
+ if (options.strict && typed.kind !== DomainPropertyKind) {
386
+ return false
387
+ }
388
+ return true
389
+ }
390
+
391
+ toJSON(): DomainPropertySchema {
392
+ const result: DomainPropertySchema = {
393
+ kind: this.kind,
394
+ key: this.key,
395
+ info: this.info.toJSON(),
396
+ type: this.type || DomainPropertyList.string,
397
+ }
398
+ if (typeof this.index === 'boolean') {
399
+ result.index = this.index
400
+ }
401
+ if (typeof this.deprecated === 'boolean') {
402
+ result.deprecated = this.deprecated
403
+ }
404
+ if (typeof this.primary === 'boolean') {
405
+ result.primary = this.primary
406
+ }
407
+ if (typeof this.multiple === 'boolean') {
408
+ result.multiple = this.multiple
409
+ }
410
+ if (typeof this.required === 'boolean') {
411
+ result.required = this.required
412
+ }
413
+ if (typeof this.readOnly === 'boolean') {
414
+ result.readOnly = this.readOnly
415
+ }
416
+ if (typeof this.writeOnly === 'boolean') {
417
+ result.writeOnly = this.writeOnly
418
+ }
419
+ if (Array.isArray(this.tags) && this.tags.length) {
420
+ result.tags = [...this.tags]
421
+ }
422
+ if (Array.isArray(this.taxonomy) && this.taxonomy.length) {
423
+ result.taxonomy = [...this.taxonomy]
424
+ }
425
+ if (this.schema) {
426
+ result.schema = structuredClone(toRaw(this, this.schema))
427
+ }
428
+ if (Array.isArray(this.bindings) && this.bindings.length) {
429
+ result.bindings = toRaw(this, this.bindings)?.map((i) => structuredClone(i))
430
+ }
431
+ return result
432
+ }
433
+
434
+ /**
435
+ * Removes this property from the parent entity.
436
+ * It calls the `removeProperty()` method of the parent entity.
437
+ */
438
+ remove(): void {
439
+ const parent = this.getParentInstance()
440
+ parent?.removeProperty(this.key)
441
+ }
442
+
443
+ /**
444
+ * Returns a parent data entity where this data property exist.
445
+ */
446
+ getParentInstance(): DomainEntity | undefined {
447
+ return this.root.graph.node(this.parent) as DomainEntity | undefined
448
+ }
449
+
450
+ /**
451
+ * Checks whether the passed value is one of the supported data types.
452
+ * @param value The value to test
453
+ * @returns True when the passed value is one of the supported data types.
454
+ */
455
+ static isValidType(value: unknown): value is DomainPropertyType {
456
+ if (typeof value !== 'string') {
457
+ return false
458
+ }
459
+ return DomainPropertyTypes.includes(value as DomainPropertyType)
460
+ }
461
+
462
+ /**
463
+ * Checks whether the passed value is one of the supported data property attributes.
464
+ * @param value The value to test
465
+ * @returns True when the passed value is one of the supported data property attributes.
466
+ */
467
+ static isValidAttribute(value: unknown): value is DomainPropertyAttribute {
468
+ if (typeof value !== 'string') {
469
+ return false
470
+ }
471
+ return DomainPropertyAttributes.includes(value as DomainPropertyAttribute)
472
+ }
473
+
474
+ /**
475
+ * Checks whether the passed value of one of the supported `format` values.
476
+ *
477
+ * @param value The value to test
478
+ * @returns `true` when the value is one of the supported `format` values.
479
+ */
480
+ static isValidFormat(value: unknown): value is DomainPropertyFormat {
481
+ if (value === undefined) {
482
+ // It is the valid value.
483
+ return true
484
+ }
485
+ if (typeof value !== 'string') {
486
+ return false
487
+ }
488
+ if (NumberFormats.includes(value as NumberFormat)) {
489
+ return true
490
+ }
491
+ if (BinaryFormats.includes(value as BinaryFormat)) {
492
+ return true
493
+ }
494
+ return false
495
+ }
496
+
497
+ /**
498
+ * Creates the `schema` object if missing and returns it.
499
+ * @returns The schema object.
500
+ */
501
+ ensureSchema(): PropertySchema {
502
+ if (!this.schema) {
503
+ this.schema = {}
504
+ }
505
+ return this.schema
506
+ }
507
+
508
+ /**
509
+ * Creates if not existing and returns web bindings definition.
510
+ * @returns The web binding definition
511
+ */
512
+ getWebBinding(): PropertyWebBindings {
513
+ let object = this.bindings.find((i) => i.type === 'web') as PropertyBinding | undefined
514
+ if (!object) {
515
+ object = { type: 'web', schema: {} } as PropertyBinding
516
+ this.bindings.push(object)
517
+ }
518
+ return object.schema as PropertyWebBindings
519
+ }
520
+
521
+ /**
522
+ * Returns the schema value of the binding, if any was created.
523
+ * @param type The type of the binding to read.
524
+ * @returns The binding schema, if any
525
+ */
526
+ readBinding(type: 'web' | 'protobuf'): PropertyBindings | undefined {
527
+ const item = this.bindings.find((i) => i.type === type) as PropertyBinding
528
+ return item?.schema || undefined
529
+ }
530
+
531
+ /**
532
+ * Creates a Property Shape of AMF.
533
+ *
534
+ * The property itself is auto-generated. If the `schema` is
535
+ * defined then it is used as the `range` of the property.
536
+ * Otherwise basic shape is generated for the range.
537
+ *
538
+ * This is a preferred way of reading the AMF shape as this
539
+ * synchronizes changed data properties with the shape
540
+ * definition.
541
+ *
542
+ * @returns AMF property shape definition.
543
+ */
544
+ toApiShape(): IApiPropertyShape {
545
+ const serializer = new ShapeGenerator()
546
+ return serializer.property(this)
547
+ }
548
+ }