@quadnix/octo 0.0.21 → 0.0.23

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 (352) hide show
  1. package/dist/app.type.d.ts +124 -27
  2. package/dist/app.type.js +77 -7
  3. package/dist/app.type.js.map +1 -1
  4. package/dist/decorators/action.decorator.d.ts +7 -8
  5. package/dist/decorators/action.decorator.js +45 -44
  6. package/dist/decorators/action.decorator.js.map +1 -1
  7. package/dist/decorators/anchor.decorator.d.ts +2 -2
  8. package/dist/decorators/anchor.decorator.js +16 -11
  9. package/dist/decorators/anchor.decorator.js.map +1 -1
  10. package/dist/decorators/enable-hook.decorator.js +2 -2
  11. package/dist/decorators/enable-hook.decorator.js.map +1 -1
  12. package/dist/decorators/event-source.decorator.d.ts +1 -1
  13. package/dist/decorators/event-source.decorator.js +7 -2
  14. package/dist/decorators/event-source.decorator.js.map +1 -1
  15. package/dist/decorators/factory.decorator.d.ts +32 -1
  16. package/dist/decorators/factory.decorator.js +35 -3
  17. package/dist/decorators/factory.decorator.js.map +1 -1
  18. package/dist/decorators/model.decorator.d.ts +3 -2
  19. package/dist/decorators/model.decorator.js +24 -11
  20. package/dist/decorators/model.decorator.js.map +1 -1
  21. package/dist/decorators/module.decorator.d.ts +4 -71
  22. package/dist/decorators/module.decorator.js +18 -58
  23. package/dist/decorators/module.decorator.js.map +1 -1
  24. package/dist/decorators/on-event.decorator.d.ts +1 -1
  25. package/dist/decorators/on-event.decorator.js +7 -2
  26. package/dist/decorators/on-event.decorator.js.map +1 -1
  27. package/dist/decorators/overlay.decorator.d.ts +3 -2
  28. package/dist/decorators/overlay.decorator.js +23 -11
  29. package/dist/decorators/overlay.decorator.js.map +1 -1
  30. package/dist/decorators/resource.decorator.d.ts +3 -2
  31. package/dist/decorators/resource.decorator.js +23 -11
  32. package/dist/decorators/resource.decorator.js.map +1 -1
  33. package/dist/decorators/validate.decorator.d.ts +4 -4
  34. package/dist/decorators/validate.decorator.js +16 -2
  35. package/dist/decorators/validate.decorator.js.map +1 -1
  36. package/dist/errors/container.error.d.ts +11 -0
  37. package/dist/errors/container.error.js +20 -0
  38. package/dist/errors/container.error.js.map +1 -0
  39. package/dist/errors/index.d.ts +6 -0
  40. package/dist/errors/index.js +7 -0
  41. package/dist/errors/index.js.map +1 -0
  42. package/dist/errors/input.error.d.ts +11 -0
  43. package/dist/errors/input.error.js +21 -0
  44. package/dist/errors/input.error.js.map +1 -0
  45. package/dist/errors/module.error.d.ts +4 -0
  46. package/dist/errors/module.error.js +8 -0
  47. package/dist/errors/module.error.js.map +1 -0
  48. package/dist/errors/node.error.d.ts +36 -0
  49. package/dist/errors/node.error.js +60 -0
  50. package/dist/errors/node.error.js.map +1 -0
  51. package/dist/errors/schema.error.d.ts +4 -0
  52. package/dist/errors/schema.error.js +8 -0
  53. package/dist/errors/schema.error.js.map +1 -0
  54. package/dist/errors/transaction.error.d.ts +35 -0
  55. package/dist/errors/transaction.error.js +58 -0
  56. package/dist/errors/transaction.error.js.map +1 -0
  57. package/dist/events/action.event.d.ts +13 -0
  58. package/dist/events/action.event.js +11 -0
  59. package/dist/events/action.event.js.map +1 -0
  60. package/dist/events/event.model.d.ts +6 -12
  61. package/dist/events/event.model.js +5 -11
  62. package/dist/events/event.model.js.map +1 -1
  63. package/dist/events/hook/commit.hook.event.d.ts +25 -0
  64. package/dist/events/hook/commit.hook.event.js +26 -0
  65. package/dist/events/hook/commit.hook.event.js.map +1 -0
  66. package/dist/events/hook/hook.event.d.ts +9 -0
  67. package/dist/events/hook/hook.event.js +10 -0
  68. package/dist/events/hook/hook.event.js.map +1 -0
  69. package/dist/events/hook/index.d.ts +4 -0
  70. package/dist/events/hook/index.js +5 -0
  71. package/dist/events/hook/index.js.map +1 -0
  72. package/dist/events/hook/model.hook.event.d.ts +25 -0
  73. package/dist/events/hook/model.hook.event.js +26 -0
  74. package/dist/events/hook/model.hook.event.js.map +1 -0
  75. package/dist/events/hook/resource.hook.event.d.ts +25 -0
  76. package/dist/events/hook/resource.hook.event.js +26 -0
  77. package/dist/events/hook/resource.hook.event.js.map +1 -0
  78. package/dist/events/index.d.ts +7 -0
  79. package/dist/events/index.js +8 -0
  80. package/dist/events/index.js.map +1 -0
  81. package/dist/events/module.event.d.ts +1 -6
  82. package/dist/events/module.event.js +0 -5
  83. package/dist/events/module.event.js.map +1 -1
  84. package/dist/events/registration.event.d.ts +9 -51
  85. package/dist/events/registration.event.js +16 -64
  86. package/dist/events/registration.event.js.map +1 -1
  87. package/dist/events/serialization.event.d.ts +24 -37
  88. package/dist/events/serialization.event.js +49 -33
  89. package/dist/events/serialization.event.js.map +1 -1
  90. package/dist/events/transaction.event.d.ts +45 -26
  91. package/dist/events/transaction.event.js +43 -25
  92. package/dist/events/transaction.event.js.map +1 -1
  93. package/dist/{decorators → functions/container}/container.d.ts +45 -31
  94. package/dist/{decorators → functions/container}/container.js +90 -58
  95. package/dist/functions/container/container.js.map +1 -0
  96. package/dist/{decorators → functions/container}/test-container.d.ts +5 -13
  97. package/dist/{decorators → functions/container}/test-container.js +31 -43
  98. package/dist/functions/container/test-container.js.map +1 -0
  99. package/dist/functions/dependency/dependency.d.ts +6 -6
  100. package/dist/functions/dependency/dependency.js +4 -3
  101. package/dist/functions/dependency/dependency.js.map +1 -1
  102. package/dist/functions/diff/diff-metadata.d.ts +4 -6
  103. package/dist/functions/diff/diff-metadata.js +4 -3
  104. package/dist/functions/diff/diff-metadata.js.map +1 -1
  105. package/dist/functions/diff/diff.d.ts +12 -7
  106. package/dist/functions/diff/diff.js +9 -12
  107. package/dist/functions/diff/diff.js.map +1 -1
  108. package/dist/functions/diff/diff.utility.d.ts +24 -24
  109. package/dist/functions/diff/diff.utility.js +46 -25
  110. package/dist/functions/diff/diff.utility.js.map +1 -1
  111. package/dist/functions/hook/commit.hook.d.ts +14 -3
  112. package/dist/functions/hook/commit.hook.js +16 -16
  113. package/dist/functions/hook/commit.hook.js.map +1 -1
  114. package/dist/functions/hook/hook.interface.d.ts +7 -6
  115. package/dist/functions/hook/model-action.hook.d.ts +17 -5
  116. package/dist/functions/hook/model-action.hook.js +20 -39
  117. package/dist/functions/hook/model-action.hook.js.map +1 -1
  118. package/dist/functions/hook/resource-action.hook.d.ts +17 -5
  119. package/dist/functions/hook/resource-action.hook.js +18 -18
  120. package/dist/functions/hook/resource-action.hook.js.map +1 -1
  121. package/dist/functions/node/node-action.abstract.d.ts +7 -0
  122. package/dist/functions/node/node-action.abstract.js +20 -0
  123. package/dist/functions/node/node-action.abstract.js.map +1 -0
  124. package/dist/functions/node/node.abstract.d.ts +93 -0
  125. package/dist/functions/node/node.abstract.js +342 -0
  126. package/dist/functions/node/node.abstract.js.map +1 -0
  127. package/dist/functions/node/node.interface.d.ts +176 -0
  128. package/dist/functions/node/node.interface.js +2 -0
  129. package/dist/functions/node/node.interface.js.map +1 -0
  130. package/dist/functions/schema/schema.d.ts +4 -0
  131. package/dist/functions/schema/schema.js +38 -0
  132. package/dist/functions/schema/schema.js.map +1 -0
  133. package/dist/index.d.ts +31 -33
  134. package/dist/index.js +32 -16
  135. package/dist/index.js.map +1 -1
  136. package/dist/main.d.ts +34 -22
  137. package/dist/main.js +92 -53
  138. package/dist/main.js.map +1 -1
  139. package/dist/models/account/account.model.d.ts +23 -0
  140. package/dist/models/account/account.model.js +67 -0
  141. package/dist/models/account/account.model.js.map +1 -0
  142. package/dist/models/account/account.schema.d.ts +7 -0
  143. package/dist/models/account/account.schema.js +12 -0
  144. package/dist/models/account/account.schema.js.map +1 -0
  145. package/dist/models/app/app.model.d.ts +6 -15
  146. package/dist/models/app/app.model.js +26 -31
  147. package/dist/models/app/app.model.js.map +1 -1
  148. package/dist/models/app/app.schema.d.ts +3 -0
  149. package/dist/models/app/app.schema.js +21 -0
  150. package/dist/models/app/app.schema.js.map +1 -0
  151. package/dist/models/deployment/deployment.model.d.ts +6 -13
  152. package/dist/models/deployment/deployment.model.js +11 -16
  153. package/dist/models/deployment/deployment.model.js.map +1 -1
  154. package/dist/models/deployment/deployment.schema.d.ts +7 -0
  155. package/dist/models/deployment/deployment.schema.js +25 -0
  156. package/dist/models/deployment/deployment.schema.js.map +1 -0
  157. package/dist/models/environment/environment.model.d.ts +5 -15
  158. package/dist/models/environment/environment.model.js +10 -28
  159. package/dist/models/environment/environment.model.js.map +1 -1
  160. package/dist/models/environment/environment.schema.d.ts +13 -0
  161. package/dist/models/environment/environment.schema.js +38 -0
  162. package/dist/models/environment/environment.schema.js.map +1 -0
  163. package/dist/models/execution/execution.model.d.ts +6 -14
  164. package/dist/models/execution/execution.model.js +15 -28
  165. package/dist/models/execution/execution.model.js.map +1 -1
  166. package/dist/models/execution/execution.schema.d.ts +14 -0
  167. package/dist/models/execution/execution.schema.js +34 -0
  168. package/dist/models/execution/execution.schema.js.map +1 -0
  169. package/dist/models/filesystem/filesystem.model.d.ts +10 -0
  170. package/dist/models/filesystem/filesystem.model.js +43 -0
  171. package/dist/models/filesystem/filesystem.model.js.map +1 -0
  172. package/dist/models/filesystem/filesystem.schema.d.ts +3 -0
  173. package/dist/models/filesystem/filesystem.schema.js +21 -0
  174. package/dist/models/filesystem/filesystem.schema.js.map +1 -0
  175. package/dist/models/image/image.model.d.ts +7 -41
  176. package/dist/models/image/image.model.js +17 -32
  177. package/dist/models/image/image.model.js.map +1 -1
  178. package/dist/models/image/image.schema.d.ts +9 -0
  179. package/dist/models/image/image.schema.js +31 -0
  180. package/dist/models/image/image.schema.js.map +1 -0
  181. package/dist/models/model-action.interface.d.ts +5 -19
  182. package/dist/models/model.abstract.d.ts +28 -316
  183. package/dist/models/model.abstract.js +180 -557
  184. package/dist/models/model.abstract.js.map +1 -1
  185. package/dist/models/model.interface.d.ts +42 -21
  186. package/dist/models/pipeline/pipeline.model.d.ts +5 -8
  187. package/dist/models/pipeline/pipeline.model.js +10 -16
  188. package/dist/models/pipeline/pipeline.model.js.map +1 -1
  189. package/dist/models/pipeline/pipeline.schema.d.ts +4 -0
  190. package/dist/models/pipeline/pipeline.schema.js +22 -0
  191. package/dist/models/pipeline/pipeline.schema.js.map +1 -0
  192. package/dist/models/region/region.model.d.ts +8 -9
  193. package/dist/models/region/region.model.js +25 -17
  194. package/dist/models/region/region.model.js.map +1 -1
  195. package/dist/models/region/region.schema.d.ts +3 -0
  196. package/dist/models/region/region.schema.js +21 -0
  197. package/dist/models/region/region.schema.js.map +1 -0
  198. package/dist/models/server/server.model.d.ts +5 -11
  199. package/dist/models/server/server.model.js +13 -16
  200. package/dist/models/server/server.model.js.map +1 -1
  201. package/dist/models/server/server.schema.d.ts +6 -0
  202. package/dist/models/server/server.schema.js +24 -0
  203. package/dist/models/server/server.schema.js.map +1 -0
  204. package/dist/models/service/service.model.d.ts +4 -10
  205. package/dist/models/service/service.model.js +12 -16
  206. package/dist/models/service/service.model.js.map +1 -1
  207. package/dist/models/service/service.schema.d.ts +6 -0
  208. package/dist/models/service/service.schema.js +24 -0
  209. package/dist/models/service/service.schema.js.map +1 -0
  210. package/dist/models/subnet/subnet.model.d.ts +10 -35
  211. package/dist/models/subnet/subnet.model.js +16 -47
  212. package/dist/models/subnet/subnet.model.js.map +1 -1
  213. package/dist/models/subnet/subnet.schema.d.ts +33 -0
  214. package/dist/models/subnet/subnet.schema.js +48 -0
  215. package/dist/models/subnet/subnet.schema.js.map +1 -0
  216. package/dist/modules/module.abstract.d.ts +21 -0
  217. package/dist/modules/module.abstract.js +14 -0
  218. package/dist/modules/module.abstract.js.map +1 -0
  219. package/dist/modules/module.container.d.ts +32 -18
  220. package/dist/modules/module.container.js +134 -81
  221. package/dist/modules/module.container.js.map +1 -1
  222. package/dist/modules/module.interface.d.ts +15 -2
  223. package/dist/modules/test-module.container.d.ts +33 -15
  224. package/dist/modules/test-module.container.js +264 -35
  225. package/dist/modules/test-module.container.js.map +1 -1
  226. package/dist/overlays/anchor.abstract.d.ts +13 -8
  227. package/dist/overlays/anchor.abstract.js.map +1 -1
  228. package/dist/overlays/anchor.interface.d.ts +5 -8
  229. package/dist/overlays/anchor.schema.d.ts +8 -0
  230. package/dist/overlays/anchor.schema.js +9 -0
  231. package/dist/overlays/anchor.schema.js.map +1 -0
  232. package/dist/overlays/overlay-data.repository.d.ts +3 -6
  233. package/dist/overlays/overlay-data.repository.js +17 -38
  234. package/dist/overlays/overlay-data.repository.js.map +1 -1
  235. package/dist/overlays/overlay.abstract.d.ts +15 -17
  236. package/dist/overlays/overlay.abstract.js +30 -44
  237. package/dist/overlays/overlay.abstract.js.map +1 -1
  238. package/dist/overlays/overlay.interface.d.ts +3 -7
  239. package/dist/overlays/overlay.schema.d.ts +8 -0
  240. package/dist/overlays/overlay.schema.js +9 -0
  241. package/dist/overlays/overlay.schema.js.map +1 -0
  242. package/dist/resources/resource-action.interface.d.ts +4 -3
  243. package/dist/resources/resource-data.repository.d.ts +16 -7
  244. package/dist/resources/resource-data.repository.js +118 -42
  245. package/dist/resources/resource-data.repository.js.map +1 -1
  246. package/dist/resources/resource.abstract.d.ts +56 -16
  247. package/dist/resources/resource.abstract.js +326 -19
  248. package/dist/resources/resource.abstract.js.map +1 -1
  249. package/dist/resources/resource.interface.d.ts +39 -8
  250. package/dist/resources/resource.schema.d.ts +14 -0
  251. package/dist/resources/resource.schema.js +11 -0
  252. package/dist/resources/resource.schema.js.map +1 -0
  253. package/dist/services/capture/capture.service.d.ts +6 -7
  254. package/dist/services/capture/capture.service.js +8 -5
  255. package/dist/services/capture/capture.service.js.map +1 -1
  256. package/dist/services/event/event.service.d.ts +3 -4
  257. package/dist/services/event/event.service.js +7 -9
  258. package/dist/services/event/event.service.js.map +1 -1
  259. package/dist/services/input/input.service.d.ts +62 -6
  260. package/dist/services/input/input.service.js +290 -14
  261. package/dist/services/input/input.service.js.map +1 -1
  262. package/dist/services/schema-translation/schema-translation.service.d.ts +13 -0
  263. package/dist/services/schema-translation/schema-translation.service.js +42 -0
  264. package/dist/services/schema-translation/schema-translation.service.js.map +1 -0
  265. package/dist/services/serialization/model/model-serialization.service.d.ts +1 -4
  266. package/dist/services/serialization/model/model-serialization.service.js +37 -33
  267. package/dist/services/serialization/model/model-serialization.service.js.map +1 -1
  268. package/dist/services/serialization/resource/resource-serialization.service.d.ts +5 -5
  269. package/dist/services/serialization/resource/resource-serialization.service.js +71 -96
  270. package/dist/services/serialization/resource/resource-serialization.service.js.map +1 -1
  271. package/dist/services/state-management/local.state-provider.d.ts +0 -1
  272. package/dist/services/state-management/local.state-provider.js +5 -7
  273. package/dist/services/state-management/local.state-provider.js.map +1 -1
  274. package/dist/services/state-management/state-management.service.d.ts +2 -3
  275. package/dist/services/state-management/state-management.service.js +19 -9
  276. package/dist/services/state-management/state-management.service.js.map +1 -1
  277. package/dist/services/state-management/state-provider.interface.d.ts +0 -1
  278. package/dist/services/state-management/test.state-provider.d.ts +0 -1
  279. package/dist/services/state-management/test.state-provider.js +2 -1
  280. package/dist/services/state-management/test.state-provider.js.map +1 -1
  281. package/dist/services/transaction/transaction.service.d.ts +18 -14
  282. package/dist/services/transaction/transaction.service.js +261 -132
  283. package/dist/services/transaction/transaction.service.js.map +1 -1
  284. package/dist/services/validation/validation.service.d.ts +2 -3
  285. package/dist/services/validation/validation.service.js +27 -12
  286. package/dist/services/validation/validation.service.js.map +1 -1
  287. package/dist/utilities/node/node.utility.d.ts +4 -0
  288. package/dist/utilities/node/node.utility.js +22 -0
  289. package/dist/utilities/node/node.utility.js.map +1 -0
  290. package/dist/utilities/object/object.utility.d.ts +3 -0
  291. package/dist/utilities/object/object.utility.js +33 -0
  292. package/dist/utilities/object/object.utility.js.map +1 -1
  293. package/dist/utilities/test-helpers/test-classes.d.ts +57 -0
  294. package/dist/utilities/test-helpers/test-classes.js +76 -0
  295. package/dist/utilities/test-helpers/test-classes.js.map +1 -0
  296. package/dist/utilities/test-helpers/test-models.d.ts +41 -0
  297. package/dist/utilities/test-helpers/test-models.js +224 -0
  298. package/dist/utilities/test-helpers/test-models.js.map +1 -0
  299. package/dist/utilities/test-helpers/test-overlays.d.ts +10 -0
  300. package/dist/utilities/test-helpers/test-overlays.js +53 -0
  301. package/dist/utilities/test-helpers/test-overlays.js.map +1 -0
  302. package/dist/utilities/test-helpers/test-resources.d.ts +22 -0
  303. package/dist/utilities/test-helpers/test-resources.js +162 -0
  304. package/dist/utilities/test-helpers/test-resources.js.map +1 -0
  305. package/dist/utilities/validation/validation.utility.d.ts +31 -3
  306. package/dist/utilities/validation/validation.utility.js +121 -2
  307. package/dist/utilities/validation/validation.utility.js.map +1 -1
  308. package/package.json +6 -6
  309. package/dist/decorators/container.js.map +0 -1
  310. package/dist/decorators/test-container.js.map +0 -1
  311. package/dist/events/error.event.d.ts +0 -35
  312. package/dist/events/error.event.js +0 -36
  313. package/dist/events/error.event.js.map +0 -1
  314. package/dist/events/hook.event.d.ts +0 -194
  315. package/dist/events/hook.event.js +0 -195
  316. package/dist/events/hook.event.js.map +0 -1
  317. package/dist/models/app/app.interface.d.ts +0 -9
  318. package/dist/models/app/app.interface.js +0 -2
  319. package/dist/models/app/app.interface.js.map +0 -1
  320. package/dist/models/deployment/deployment.interface.d.ts +0 -9
  321. package/dist/models/deployment/deployment.interface.js +0 -2
  322. package/dist/models/deployment/deployment.interface.js.map +0 -1
  323. package/dist/models/environment/environment.interface.d.ts +0 -12
  324. package/dist/models/environment/environment.interface.js +0 -2
  325. package/dist/models/environment/environment.interface.js.map +0 -1
  326. package/dist/models/execution/execution.interface.d.ts +0 -14
  327. package/dist/models/execution/execution.interface.js +0 -2
  328. package/dist/models/execution/execution.interface.js.map +0 -1
  329. package/dist/models/image/image.interface.d.ts +0 -12
  330. package/dist/models/image/image.interface.js +0 -2
  331. package/dist/models/image/image.interface.js.map +0 -1
  332. package/dist/models/pipeline/pipeline.interface.d.ts +0 -10
  333. package/dist/models/pipeline/pipeline.interface.js +0 -2
  334. package/dist/models/pipeline/pipeline.interface.js.map +0 -1
  335. package/dist/models/region/region.interface.d.ts +0 -9
  336. package/dist/models/region/region.interface.js +0 -2
  337. package/dist/models/region/region.interface.js.map +0 -1
  338. package/dist/models/server/server.interface.d.ts +0 -9
  339. package/dist/models/server/server.interface.js +0 -2
  340. package/dist/models/server/server.interface.js.map +0 -1
  341. package/dist/models/service/service.interface.d.ts +0 -9
  342. package/dist/models/service/service.interface.js +0 -2
  343. package/dist/models/service/service.interface.js.map +0 -1
  344. package/dist/models/subnet/subnet.interface.d.ts +0 -13
  345. package/dist/models/subnet/subnet.interface.js +0 -2
  346. package/dist/models/subnet/subnet.interface.js.map +0 -1
  347. package/dist/overlays/overlay.service.d.ts +0 -18
  348. package/dist/overlays/overlay.service.js +0 -45
  349. package/dist/overlays/overlay.service.js.map +0 -1
  350. package/dist/resources/shared-resource.abstract.d.ts +0 -13
  351. package/dist/resources/shared-resource.abstract.js +0 -47
  352. package/dist/resources/shared-resource.abstract.js.map +0 -1
@@ -1,619 +1,242 @@
1
- import { ModelType } from '../app.type.js';
2
- import { Dependency } from '../functions/dependency/dependency.js';
1
+ import { MatchingAnchor, MatchingModel, MatchingResource, NodeType, } from '../app.type.js';
2
+ import { NodeError, SchemaError, ValidationTransactionError } from '../errors/index.js';
3
+ import { Container } from '../functions/container/container.js';
3
4
  import { Diff, DiffAction } from '../functions/diff/diff.js';
4
5
  import { DiffUtility } from '../functions/diff/diff.utility.js';
5
- /**
6
- * This is Octo's base class, and all other classes extend from it.
7
- * It helps provide a common set of methods and properties that is core to Octo.
8
- *
9
- * Octo is built as a graph, and this base class can be considered as a generic node.
10
- * Nodes can have children, and siblings, but only if connected via an edge, called {@link Dependency} here.
11
- *
12
- * From this base class, three more base classes are derived,
13
- * - [Models](/docs/fundamentals/models)
14
- * - [Resources](/docs/fundamentals/resources)
15
- * - [Overlays](/docs/fundamentals/overlay-and-anchor)
16
- *
17
- * Each of these derived base classes, using the base methods of this class,
18
- * define their own specific rules on how their graphs should be constructed.
19
- */
20
- export class AModel {
6
+ import { ANode } from '../functions/node/node.abstract.js';
7
+ import { getSchemaInstance } from '../functions/schema/schema.js';
8
+ import { InputService } from '../services/input/input.service.js';
9
+ import { SchemaTranslationService } from '../services/schema-translation/schema-translation.service.js';
10
+ export class AModel extends ANode {
21
11
  constructor() {
22
- this.MODEL_TYPE = ModelType.MODEL;
23
- this._deleteMarker = false;
12
+ super(...arguments);
24
13
  this.anchors = [];
25
- this.dependencies = [];
26
14
  }
27
- /**
28
- * To add an {@link Anchor}.
29
- *
30
- * Each node can store multiple anchors for reference.
31
- * These anchors don't necessarily need to be parented by self, but must be unique,
32
- * i.e. an anchor, identified by it's parent, cannot be added twice to self's list of anchors.
33
- */
34
15
  addAnchor(anchor) {
35
- const existingAnchor = this.getAnchor(anchor.anchorId, anchor.getParent());
36
- if (!existingAnchor) {
37
- this.anchors.push(anchor);
16
+ const existingAnchor = anchor instanceof MatchingAnchor
17
+ ? this.getAnchor(anchor.getActual().anchorId, anchor.getActual().getParent())
18
+ : this.getAnchor(anchor.anchorId, anchor.getParent());
19
+ if (existingAnchor) {
20
+ throw new NodeError('Anchor already exists!', this);
38
21
  }
39
- }
40
- /**
41
- * To add another node as a child of self.
42
- *
43
- * Every node must have a unique ID against other nodes of the same {@link MODEL_NAME}.
44
- * This ID is how Octo differentiates similar nodes, and keeps track of them.
45
- * But because each node is free to define their own fields,
46
- * the fields containing the ID are a necessary input to this method.
47
- *
48
- * @example
49
- * ```ts
50
- * const region = new Region('region');
51
- * const environment = new Environment('qa');
52
- * region.addChild('regionId', environment, 'environmentName');
53
- * ```
54
- * @param onField The field in self which contains the unique ID.
55
- * @param child The child node.
56
- * @param toField The field in child which contains the unique ID.
57
- * @returns
58
- * - childToParentDependency: The dependency edge from child to self.
59
- * - parentToChildDependency: The dependency edge from self to child.
60
- */
61
- addChild(onField, child, toField) {
62
- const cIndex = child.dependencies.findIndex((d) => Object.is(d.to, this));
63
- const pIndex = this.dependencies.findIndex((d) => Object.is(d.to, child));
64
- if (cIndex !== -1 || pIndex !== -1) {
65
- throw new Error('Dependency relationship already exists!');
22
+ else {
23
+ this.anchors.push(anchor);
66
24
  }
67
- const childToParentDependency = new Dependency(child, this);
68
- childToParentDependency.addBehavior(toField, DiffAction.ADD, onField, DiffAction.ADD);
69
- childToParentDependency.addBehavior(toField, DiffAction.ADD, onField, DiffAction.UPDATE);
70
- childToParentDependency.addChildRelationship(toField, onField);
71
- child.dependencies.push(childToParentDependency);
72
- const parentToChildDependency = new Dependency(this, child);
73
- parentToChildDependency.addBehavior(onField, DiffAction.DELETE, toField, DiffAction.DELETE);
74
- parentToChildDependency.addParentRelationship(onField, toField);
75
- this.dependencies.push(parentToChildDependency);
76
- return { childToParentDependency, parentToChildDependency };
77
- }
78
- /**
79
- * To add another node as a sibling of self.
80
- *
81
- * @example
82
- * ```ts
83
- * const region1 = new Region('region-1');
84
- * const region2 = new Region('region-2');
85
- * region1.addSibling(region2);
86
- * ```
87
- * @param to The sibling node.
88
- * @returns
89
- * - thatToThisDependency: The dependency edge from sibling to self.
90
- * - thisToThatDependency: The dependency edge from self to sibling.
91
- */
92
- addRelationship(to) {
93
- const thisToThatDependency = new Dependency(this, to);
94
- this.dependencies.push(thisToThatDependency);
95
- const thatToThisDependency = new Dependency(to, this);
96
- to.dependencies.push(thatToThisDependency);
97
- return { thatToThisDependency, thisToThatDependency };
98
25
  }
99
- /**
100
- * To derive the name of the field in self which contains the ID.
101
- *
102
- * @remarks This method does a best attempt search of the field name by traversing all dependencies of self.
103
- * But if the dependencies lack, or have not been added yet, this method might return `undefined`.
104
- * That does not mean that such a field does not exist,
105
- * but rather that it wasn't possible to derive the name at that point.
106
- * @returns The name of the field in self which contains the ID, or `undefined` if not found.
107
- */
108
26
  deriveDependencyField() {
109
- return this.dependencies.find((d) => d.getRelationship() !== undefined)?.getRelationship().onField;
27
+ if (this.getDependencies().length === 0 && this.constructor.NODE_NAME === 'app') {
28
+ return 'name';
29
+ }
30
+ else if (this.constructor.NODE_TYPE === NodeType.OVERLAY) {
31
+ return 'overlayId';
32
+ }
33
+ return this.getDependencies()
34
+ .find((d) => d.getRelationship() !== undefined)
35
+ ?.getRelationship().onField;
110
36
  }
111
- /**
112
- * Compares and calculates the difference between the current version of self node, and the previous version.
113
- * - Recursively compares self children too.
114
- *
115
- * @param previous The previous version of self.
116
- */
117
- async diff(previous) {
37
+ async diff() {
118
38
  const diffs = [];
119
- const previousChildrenByModels = previous?.getChildren() ?? {};
120
- const currentChildrenByModels = this.getChildren();
121
- // Compare previous children with current children.
122
- for (const modelName of Object.keys(previousChildrenByModels)) {
123
- const previousChildren = previousChildrenByModels[modelName].map((d) => d.to);
124
- const currentChildren = currentChildrenByModels[modelName]?.map((d) => d.to) || [];
125
- const field = previousChildrenByModels[modelName][0].getRelationship().toField;
126
- const childrenDiffs = await DiffUtility.diffModels(previousChildren, currentChildren, field);
127
- diffs.push(...childrenDiffs);
39
+ const field = this.deriveDependencyField();
40
+ if (!field) {
41
+ throw new NodeError('Cannot derive dependency field!', this);
128
42
  }
129
- // Add new children not in previous.
43
+ const currentChildrenByModels = this.getChildren();
130
44
  for (const modelName of Object.keys(currentChildrenByModels)) {
131
- if (previousChildrenByModels.hasOwnProperty(modelName)) {
132
- continue;
133
- }
134
45
  const previousChildren = [];
135
46
  const currentChildren = currentChildrenByModels[modelName].map((d) => d.to);
136
47
  const field = currentChildrenByModels[modelName][0].getRelationship().toField;
137
- const childrenDiffs = await DiffUtility.diffModels(previousChildren, currentChildren, field);
48
+ const childrenDiffs = await DiffUtility.diffNodes(previousChildren, currentChildren, field);
138
49
  diffs.push(...childrenDiffs);
139
50
  }
140
- const previousSiblingsByModels = previous?.getSiblings() ?? {};
141
51
  const currentSiblingsByModels = this.getSiblings();
142
- // Compare previous siblings with current siblings.
143
- for (const modelName of Object.keys(previousSiblingsByModels)) {
144
- const previousSiblings = previousSiblingsByModels[modelName];
145
- const currentSiblings = currentSiblingsByModels[modelName] || [];
146
- for (const pd of previousSiblings) {
147
- // Skip OVERLAY sibling, since overlays are diffed separately.
148
- if (pd.to.MODEL_TYPE === ModelType.OVERLAY) {
149
- continue;
150
- }
151
- if (!currentSiblings.find((cd) => cd.to.getContext() === pd.to.getContext())) {
152
- diffs.push(new Diff(this, DiffAction.DELETE, 'sibling', pd.to));
153
- }
154
- }
155
- for (const cd of currentSiblings) {
156
- // Skip OVERLAY sibling, since overlays are diffed separately.
157
- if (cd.to.MODEL_TYPE === ModelType.OVERLAY) {
158
- continue;
159
- }
160
- if (!previousSiblings.find((pd) => pd.to.getContext() === cd.to.getContext())) {
161
- diffs.push(new Diff(this, DiffAction.ADD, 'sibling', cd.to));
162
- }
163
- }
164
- }
165
- // Add new siblings not in previous.
166
52
  for (const modelName of Object.keys(currentSiblingsByModels)) {
167
- if (previousSiblingsByModels.hasOwnProperty(modelName)) {
168
- continue;
169
- }
170
53
  const currentSiblings = currentSiblingsByModels[modelName];
171
54
  for (const cd of currentSiblings) {
172
55
  // Skip OVERLAY sibling, since overlays are diffed separately.
173
- if (cd.to.MODEL_TYPE === ModelType.OVERLAY) {
56
+ if (cd.to.constructor.NODE_TYPE === NodeType.OVERLAY) {
174
57
  continue;
175
58
  }
176
59
  diffs.push(new Diff(this, DiffAction.ADD, 'sibling', cd.to));
177
60
  }
178
61
  }
179
- const field = this.deriveDependencyField() || '';
180
- const fieldValue = field ? this[field] : '';
181
- if (this.isMarkedDeleted()) {
182
- diffs.push(new Diff(this, DiffAction.DELETE, field, fieldValue));
183
- }
184
- else if (!previous) {
185
- diffs.push(new Diff(this, DiffAction.ADD, field, fieldValue));
186
- }
187
- else {
188
- const pDiffs = await this.diffProperties(previous);
189
- diffs.push(...pDiffs);
190
- }
62
+ // Add model.
63
+ diffs.push(new Diff(this, DiffAction.ADD, field, this[field]));
64
+ // Diff model properties.
65
+ const propertyDiffs = await this.diffProperties();
66
+ diffs.push(...propertyDiffs);
191
67
  return diffs;
192
68
  }
193
- /**
194
- * To get all ancestors of self.
195
- * - Includes parent nodes.
196
- * - Might include sibling nodes, if they are necessary for self node to exist.
197
- */
198
- getAncestors() {
199
- const members = [this];
200
- const membersProcessed = [];
201
- while (members.length > 0) {
202
- const member = members.pop();
203
- // Skip processing an already processed member.
204
- if (membersProcessed.some((m) => m.getContext() === member.getContext())) {
205
- continue;
206
- }
207
- for (const d of member.dependencies) {
208
- // If in dependency I am not declared a parent, then d.to is either my parent or has a relationship to me.
209
- // The behavior of that relationship should be that it must exist for me to exist.
210
- if (!d.isParentRelationship() &&
211
- d.hasMatchingBehavior(undefined, DiffAction.ADD, undefined, DiffAction.ADD) &&
212
- !membersProcessed.some((m) => m.getContext() === d.to.getContext())) {
213
- members.push(d.to);
214
- }
215
- }
216
- membersProcessed.push(member);
217
- }
218
- return membersProcessed;
69
+ async diffProperties() {
70
+ return [];
219
71
  }
220
- /**
221
- * To get an anchor with a given ID and parent.
222
- *
223
- * @param anchorId The ID of the anchor.
224
- * @param parent The parent of the anchor.
225
- * - If parent is not given, then self is considered the parent of this anchor.
226
- */
227
72
  getAnchor(anchorId, parent) {
228
73
  const index = this.getAnchorIndex(anchorId, parent);
229
- return index > -1 ? this.anchors[index] : undefined;
74
+ if (index === -1) {
75
+ return undefined;
76
+ }
77
+ const anchor = this.anchors[index];
78
+ if (anchor instanceof MatchingAnchor) {
79
+ return anchor.getActual();
80
+ }
81
+ else {
82
+ return anchor;
83
+ }
230
84
  }
231
- /**
232
- * To get the index of an anchor with a given ID and parent.
233
- *
234
- * @param anchorId The ID of the anchor.
235
- * @param parent The parent of the anchor.
236
- * - If parent is not given, then self is considered the parent of this anchor.
237
- */
238
85
  getAnchorIndex(anchorId, parent) {
239
- return this.anchors.findIndex((a) => a.anchorId === anchorId && a.getParent().getContext() === (parent || this).getContext());
240
- }
241
- /**
242
- * To get all anchors, filtered by anchor properties.
243
- *
244
- * @param filters A set of filters, where `key` is the property name and `value` is the value to filter by.
245
- */
246
- getAnchors(filters = []) {
247
- return this.anchors.filter((a) => filters.every((c) => a[c.key] === c.value));
86
+ return this.anchors.findIndex((a) => {
87
+ if (a instanceof MatchingAnchor) {
88
+ return (a.getActual().anchorId === anchorId &&
89
+ a.getActual().getParent().getContext() === (parent || this).getContext());
90
+ }
91
+ else {
92
+ return a.anchorId === anchorId && a.getParent().getContext() === (parent || this).getContext();
93
+ }
94
+ });
248
95
  }
249
- /**
250
- * To get a boundary (sub graph) of self.
251
- * A boundary is a group of nodes that must belong together.
252
- * The boundary consists of all nodes associated with self,
253
- * which includes parents, grand parents, children, grand children, and siblings.
254
- */
255
- getBoundaryMembers() {
256
- const extenders = [this];
257
- const members = [];
258
- const parentOf = {};
259
- const pushToExtenders = (models) => {
260
- models.forEach((model) => {
261
- if (!members.some((m) => m.getContext() === model.getContext())) {
262
- extenders.push(model);
96
+ getAnchors(filters = [], types = []) {
97
+ return this.anchors
98
+ .filter((a) => !types.length || types.some((t) => a instanceof t))
99
+ .filter((a) => filters.every((c) => {
100
+ if (a instanceof MatchingAnchor) {
101
+ return a.getSchemaInstance().properties[c.key] === c.value;
102
+ }
103
+ else {
104
+ return a.properties[c.key] === c.value;
105
+ }
106
+ }))
107
+ .map((a) => (a instanceof MatchingAnchor ? a.getActual() : a));
108
+ }
109
+ async getAnchorsMatchingSchema(from, propertyFilters = [], { searchBoundaryMembers = true } = {}) {
110
+ const matches = [];
111
+ const container = Container.getInstance();
112
+ const schemaTranslationService = await container.get(SchemaTranslationService);
113
+ const translatedSchema = schemaTranslationService.getTranslatedSchema(from);
114
+ if (translatedSchema) {
115
+ from = translatedSchema.schema;
116
+ }
117
+ const boundaryMembers = searchBoundaryMembers ? this.getBoundaryMembers() : [this];
118
+ const anchors = boundaryMembers.map((m) => m.getAnchors()).flat();
119
+ while (anchors.length > 0) {
120
+ const anchor = anchors.shift();
121
+ try {
122
+ const schemaInstance = getSchemaInstance(from, anchor.synth());
123
+ const matchingSchemaInstance = (translatedSchema ? translatedSchema.translator(schemaInstance) : anchor.synth());
124
+ if (propertyFilters.every((f) => matchingSchemaInstance.properties[f.key] === f.value)) {
125
+ matches.push([anchor, translatedSchema ? translatedSchema.translator : undefined]);
263
126
  }
264
- });
265
- };
266
- while (extenders.length > 0) {
267
- const model = extenders.pop();
268
- const ancestors = model.getAncestors();
269
- for (const ancestor of ancestors) {
270
- // Skip processing an already processed ancestor.
271
- if (members.some((m) => m.getContext() === ancestor.getContext())) {
272
- continue;
127
+ }
128
+ catch (error) {
129
+ if (!(error instanceof SchemaError) && !(error instanceof ValidationTransactionError)) {
130
+ throw error;
273
131
  }
274
- members.push(ancestor);
275
- // Check for circular dependencies on ancestor.
276
- for (const d of ancestor.dependencies) {
277
- let childContext;
278
- let parentContext;
279
- if (d.isParentRelationship()) {
280
- childContext = d.to.getContext();
281
- parentContext = d.from.getContext();
282
- }
283
- else if (d.isChildRelationship()) {
284
- childContext = d.from.getContext();
285
- parentContext = d.to.getContext();
286
- }
287
- else {
288
- // A relationship that is neither parent nor child, will not be reported in circular dependency!
289
- continue;
290
- }
291
- const seen = {};
292
- const toProcess = [parentContext];
293
- while (toProcess.length > 0) {
294
- const context = toProcess.pop();
295
- if (seen[context]) {
296
- throw new Error('Found circular dependencies!');
297
- }
298
- else {
299
- seen[context] = true;
300
- }
301
- toProcess.push(...(parentOf[context] || []));
302
- }
303
- if (!parentOf[childContext]) {
304
- parentOf[childContext] = [];
305
- parentOf[childContext].push(parentContext);
306
- }
307
- else if (!parentOf[childContext].some((p) => p === parentContext)) {
308
- parentOf[childContext].push(parentContext);
309
- }
132
+ }
133
+ }
134
+ return matches.map((m) => new MatchingAnchor(m[0], m[1]));
135
+ }
136
+ async getModelsMatchingSchema(schema, filters = [], { searchBoundaryMembers = true } = {}) {
137
+ const matches = [];
138
+ const container = Container.getInstance();
139
+ const schemaTranslationService = await container.get(SchemaTranslationService);
140
+ const translatedSchema = schemaTranslationService.getTranslatedSchema(schema);
141
+ if (translatedSchema) {
142
+ schema = translatedSchema.schema;
143
+ }
144
+ const models = searchBoundaryMembers ? this.getBoundaryMembers() : [this];
145
+ while (models.length > 0) {
146
+ const model = models.shift();
147
+ try {
148
+ const schemaInstance = getSchemaInstance(schema, model.synth());
149
+ const matchingSchemaInstance = (translatedSchema ? translatedSchema.translator(schemaInstance) : model.synth());
150
+ if (filters.every((f) => matchingSchemaInstance[f.key] === f.value)) {
151
+ matches.push([model, translatedSchema ? translatedSchema.translator : undefined]);
310
152
  }
311
153
  }
312
- const children = model.getChildren();
313
- for (const modelName in children) {
314
- pushToExtenders(children[modelName].map((d) => d.to));
154
+ catch (error) {
155
+ if (!(error instanceof SchemaError) && !(error instanceof ValidationTransactionError)) {
156
+ throw error;
157
+ }
315
158
  }
316
- const dependents = model.dependencies
317
- .filter((d) => !d.isParentRelationship() && !d.isChildRelationship())
318
- .map((d) => d.to);
319
- pushToExtenders(dependents);
320
159
  }
321
- return members;
322
- }
323
- /**
324
- * To get a child of self that matches the given filters.
325
- *
326
- * @param modelName The {@link MODEL_NAME} of the child.
327
- * @param filters A set of filters, to be applied on children,
328
- * where `key` is the property name and `value` is the value to filter by.
329
- * @throws {@link Error} If more than one child is found.
330
- */
331
- getChild(modelName, filters = []) {
332
- const dependencies = this.getChildren(modelName)[modelName]?.filter((d) => filters.every((c) => d.to[c.key] === c.value));
333
- if (!dependencies) {
334
- return undefined;
335
- }
336
- if (dependencies.length > 1) {
337
- throw new Error('More than one children found! Use getChildren() instead.');
338
- }
339
- return dependencies[0].to;
340
- }
341
- /**
342
- * To get all children of self.
343
- *
344
- * @example
345
- * ```ts
346
- * const children = region.getChildren('environment');
347
- * const environments = children['environment'].map((d) => d.to);
348
- * ```
349
- * @param modelName The {@link MODEL_NAME} of the children.
350
- * @returns All children as an object with the {@link MODEL_NAME} as the key,
351
- * and self's dependency to the child as the value.
352
- */
353
- getChildren(modelName) {
354
- return this.dependencies
355
- .filter((d) => d.isParentRelationship() && (modelName ? d.to.MODEL_NAME === modelName : true))
356
- .reduce((accumulator, currentValue) => {
357
- if (!(currentValue.to.MODEL_NAME in accumulator)) {
358
- accumulator[currentValue.to.MODEL_NAME] = [];
160
+ return matches.map((m) => new MatchingModel(m[0], m[1]));
161
+ }
162
+ async getOverlaysMatchingSchema(schema, propertyFilters = [], { searchBoundaryMembers = true } = {}) {
163
+ const matches = [];
164
+ const container = Container.getInstance();
165
+ const schemaTranslationService = await container.get(SchemaTranslationService);
166
+ const translatedSchema = schemaTranslationService.getTranslatedSchema(schema);
167
+ if (translatedSchema) {
168
+ schema = translatedSchema.schema;
169
+ }
170
+ const overlays = searchBoundaryMembers
171
+ ? this.getBoundaryMembers().filter((m) => m.constructor.NODE_TYPE === NodeType.OVERLAY)
172
+ : [this];
173
+ while (overlays.length > 0) {
174
+ const overlay = overlays.shift();
175
+ try {
176
+ const schemaInstance = getSchemaInstance(schema, overlay.synth());
177
+ const matchingSchemaInstance = (translatedSchema ? translatedSchema.translator(schemaInstance) : overlay.synth());
178
+ if (propertyFilters.every((f) => matchingSchemaInstance.properties[f.key] === f.value)) {
179
+ matches.push([overlay, translatedSchema ? translatedSchema.translator : undefined]);
180
+ }
181
+ }
182
+ catch (error) {
183
+ if (!(error instanceof SchemaError) && !(error instanceof ValidationTransactionError)) {
184
+ throw error;
185
+ }
359
186
  }
360
- accumulator[currentValue.to.MODEL_NAME].push(currentValue);
361
- return accumulator;
362
- }, {});
363
- }
364
- /**
365
- * To get the context of self.
366
- * A context is a string representation of self that uniquely identifies self in the graph.
367
- *
368
- * @example
369
- * ```ts
370
- * const app = new App('my-app');
371
- * const region = new Region('my-region');
372
- * app.addRegion(region);
373
- * const context = region.getContext(); // "region=my-region,app=my-app"
374
- * ```
375
- */
376
- getContext() {
377
- if (!this.context) {
378
- this.context = this.setContext();
379
- }
380
- return this.context;
381
- }
382
- /**
383
- * To get all dependencies of self.
384
- * - Can be filtered to just dependencies with a single node.
385
- *
386
- * @param to The other node. If present, will only return dependencies of self with this node.
387
- */
388
- getDependencies(to) {
389
- const filters = [];
390
- if (to) {
391
- filters.push({ key: 'to', value: to.getContext() });
392
187
  }
393
- return this.dependencies.filter((d) => {
394
- return filters.every((c) => {
395
- if (c.key === 'to') {
396
- return d.to.getContext() === c.value;
188
+ return matches.map((m) => new MatchingModel(m[0], m[1]));
189
+ }
190
+ async getResourcesMatchingSchema(schema, propertyFilters = [], responseFilters = [], { searchBoundaryMembers = true } = {}) {
191
+ const matches = [];
192
+ const container = Container.getInstance();
193
+ const [inputService, schemaTranslationService] = await Promise.all([
194
+ container.get(InputService),
195
+ container.get(SchemaTranslationService),
196
+ ]);
197
+ const translatedSchema = schemaTranslationService.getTranslatedSchema(schema);
198
+ if (translatedSchema) {
199
+ schema = translatedSchema.schema;
200
+ }
201
+ const models = searchBoundaryMembers ? this.getBoundaryMembers() : [this];
202
+ while (models.length > 0) {
203
+ const model = models.shift();
204
+ const moduleId = model.constructor.NODE_TYPE === NodeType.OVERLAY
205
+ ? inputService.getModuleIdFromOverlay(model)
206
+ : inputService.getModuleIdFromModel(model);
207
+ const moduleResources = inputService.getModuleResources(moduleId);
208
+ for (const r of moduleResources) {
209
+ try {
210
+ const schemaInstance = getSchemaInstance(schema, r.synth());
211
+ const matchingSchemaInstance = (translatedSchema ? translatedSchema.translator(schemaInstance) : r.synth());
212
+ if (propertyFilters.every((f) => matchingSchemaInstance.properties[f.key] === f.value) &&
213
+ responseFilters.every((f) => matchingSchemaInstance.response[f.key] === f.value)) {
214
+ matches.push([r, translatedSchema ? translatedSchema.translator : undefined]);
215
+ }
397
216
  }
398
- else {
399
- return true;
217
+ catch (error) {
218
+ if (!(error instanceof SchemaError) && !(error instanceof ValidationTransactionError)) {
219
+ throw error;
220
+ }
400
221
  }
401
- });
402
- });
403
- }
404
- /**
405
- * To get a dependency of self with another node.
406
- *
407
- * @param to The other node.
408
- * @param relationship The relationship between self and the other node.
409
- * @returns The dependency with the other node having the given relationship, or `undefined` if not found.
410
- */
411
- getDependency(to, relationship) {
412
- const index = this.getDependencyIndex(to, relationship);
413
- return index > -1 ? this.dependencies[index] : undefined;
414
- }
415
- /**
416
- * To get the index of a dependency of self with another node.
417
- *
418
- * @param to The other node.
419
- * @param relationship The relationship between self and the other node.
420
- * @returns The index of the dependency with the other node having the given relationship, or `-1` if not found.
421
- */
422
- getDependencyIndex(to, relationship) {
423
- return this.dependencies.findIndex((d) => d.from.getContext() === this.getContext() &&
424
- d.to.getContext() === to.getContext() &&
425
- d.getRelationship() !== undefined &&
426
- d.getRelationship().type === relationship);
427
- }
428
- /**
429
- * To get all parent of self.
430
- *
431
- * @example
432
- * ```ts
433
- * const parents = environment.getParents('region');
434
- * const regions = parents['region'].map((d) => d.to);
435
- * ```
436
- * @param modelName The {@link MODEL_NAME} of the parent.
437
- * @returns All parents as an object with the {@link MODEL_NAME} as the key,
438
- * and self's dependency to the parent as the value.
439
- */
440
- getParents(modelName) {
441
- return this.dependencies
442
- .filter((d) => d.isChildRelationship() && (modelName ? d.to.MODEL_NAME === modelName : true))
443
- .reduce((accumulator, currentValue) => {
444
- if (!(currentValue.to.MODEL_NAME in accumulator)) {
445
- accumulator[currentValue.to.MODEL_NAME] = [];
446
222
  }
447
- accumulator[currentValue.to.MODEL_NAME].push(currentValue);
448
- return accumulator;
449
- }, {});
450
- }
451
- /**
452
- * To get all siblings of self.
453
- *
454
- * :::note Note
455
- * Two environments, or two regions, etc. are not automatically considered siblings,
456
- * unless they have a dependency between them.
457
- *
458
- * ```ts
459
- * const environment1 = new Environment('qa');
460
- * const environment2 = new Environment('prod');
461
- * const region = new Region('region');
462
- * region.addEnvironment(environment1);
463
- * region.addEnvironment(environment2);
464
- * environment1.getSiblings('environment'); // This won't return a dependency to environment2.
465
- * ```
466
- * :::
467
- *
468
- * @example
469
- * ```ts
470
- * const siblings = environment.getSiblings('image');
471
- * const images = siblings['image'].map((d) => d.to);
472
- * ```
473
- * @param modelName The {@link MODEL_NAME} of the sibling.
474
- * @returns All siblings as an object with the {@link MODEL_NAME} as the key,
475
- * and self's dependency to the sibling as the value.
476
- */
477
- getSiblings(modelName) {
478
- return this.dependencies
479
- .filter((d) => !d.isChildRelationship() && !d.isParentRelationship() && (modelName ? d.to.MODEL_NAME === modelName : true))
480
- .reduce((accumulator, currentValue) => {
481
- if (!(currentValue.to.MODEL_NAME in accumulator)) {
482
- accumulator[currentValue.to.MODEL_NAME] = [];
483
- }
484
- accumulator[currentValue.to.MODEL_NAME].push(currentValue);
485
- return accumulator;
486
- }, {});
487
- }
488
- /**
489
- * To check if given node is an ancestor of self.
490
- *
491
- * @param model The other node.
492
- */
493
- hasAncestor(model) {
494
- const modelParts = model
495
- .getContext()
496
- .split(',')
497
- .map((p) => p.split('='));
498
- const ancestors = this.getAncestors();
499
- return ancestors.some((a) => {
500
- const ancestorParts = a
501
- .getContext()
502
- .split(',')
503
- .reduce((map, p) => {
504
- const parts = p.split('=');
505
- map[parts[0]] = parts[1];
506
- return map;
507
- }, {});
508
- return modelParts.every((p) => ancestorParts[p[0]] === p[1]);
509
- });
510
- }
511
- /**
512
- * To check if self is marked as deleted.
513
- * A deleted node will be removed from the graph after the transaction.
514
- */
515
- isMarkedDeleted() {
516
- return this._deleteMarker;
517
- }
518
- /**
519
- * To mark self as deleted.
520
- * A deleted node will be removed from the graph after the transaction.
521
- * - A node cannot be deleted if it has dependencies.
522
- * - Unless the dependency is a sibling dependency and `ignoreDirectRelationships` is `true`.
523
- *
524
- * @example
525
- * ```ts
526
- * const region1 = new Region('region-1');
527
- * const environment = new Environment('environment');
528
- * region1.addEnvironment(environment);
529
- * const region2 = new Region('region-2');
530
- * region1.addSibling(region2);
531
- *
532
- * // Cannot remove region1 because it has dependencies.
533
- * region1.remove(); // throws.
534
- *
535
- * // Still can't remove region1 because it has a sibling dependency.
536
- * environment.remove(); // ok.
537
- * region1.remove(); // throws.
538
- *
539
- * // But can remove region1 when sibling relationships are ignored.
540
- * region1.remove(true); // ok.
541
- * ```
542
- * @param ignoreDirectRelationships Whether to ignore sibling relationships.
543
- * @throws {@link Error} If node contains dependencies to other nodes.
544
- */
545
- remove(ignoreDirectRelationships = false) {
546
- // Verify model can be removed.
547
- for (const dependency of this.dependencies) {
548
- // When direct relationship is not ignored, this model can't be a parent or have direct relationships.
549
- // When direct relationship is ignored, this model can't be a parent.
550
- if ((!ignoreDirectRelationships && !dependency.isChildRelationship()) ||
551
- (ignoreDirectRelationships && dependency.isParentRelationship())) {
552
- throw new Error('Cannot remove model until dependent models exist!');
553
- }
554
- }
555
- // Removing all dependencies that points to this.
556
- for (const dependency of this.dependencies) {
557
- const index = dependency.to.dependencies.findIndex((d) => d.to.getContext() === this.getContext());
558
- dependency.to.dependencies.splice(index, 1);
559
223
  }
560
- this._deleteMarker = true;
224
+ return matches.map((m) => new MatchingResource(m[0], m[1]));
561
225
  }
562
- /**
563
- * To remove all anchors from self.
564
- */
565
226
  removeAllAnchors() {
566
- let anchors = this.getAnchors();
227
+ const anchors = this.getAnchors();
567
228
  while (anchors.length > 0) {
568
- this.removeAnchor(anchors[0]);
569
- anchors = this.getAnchors();
229
+ this.removeAnchor(anchors.shift());
570
230
  }
571
231
  }
572
- /**
573
- * To remove an anchor from self.
574
- *
575
- * @param anchor The anchor to remove.
576
- */
577
232
  removeAnchor(anchor) {
578
- const existingAnchorIndex = this.getAnchorIndex(anchor.anchorId, anchor.getParent());
233
+ const existingAnchorIndex = anchor instanceof MatchingAnchor
234
+ ? this.getAnchorIndex(anchor.getActual().anchorId, anchor.getActual().getParent())
235
+ : this.getAnchorIndex(anchor.anchorId, anchor.getParent());
579
236
  if (existingAnchorIndex !== -1) {
580
237
  this.anchors.splice(existingAnchorIndex, 1);
581
238
  }
582
239
  }
583
- /**
584
- * To remove a dependency from self.
585
- *
586
- * @param dependencyIndex The index of the dependency to remove.
587
- */
588
- removeDependency(dependencyIndex) {
589
- if (dependencyIndex > -1 && dependencyIndex < this.dependencies.length) {
590
- this.dependencies.splice(dependencyIndex, 1);
591
- }
592
- }
593
- /**
594
- * To remove ALL dependencies from self for the given node.
595
- *
596
- * @param model The other node.
597
- */
598
- removeRelationship(model) {
599
- for (let i = this.dependencies.length - 1; i >= 0; i--) {
600
- const dependency = this.dependencies[i];
601
- if (dependency.to.getContext() === model.getContext()) {
602
- this.dependencies.splice(i, 1);
603
- }
604
- }
605
- for (let i = model.dependencies.length - 1; i >= 0; i--) {
606
- const dependency = model.dependencies[i];
607
- if (dependency.to.getContext() === this.getContext()) {
608
- model.dependencies.splice(i, 1);
609
- }
610
- }
611
- }
612
- /**
613
- * To create self given its serialized representation.
614
- * - First argument is the serialized representation.
615
- * - Second argument is the `deReferenceContext()` function to resolve other nodes self depends on.
616
- */
617
240
  static async unSynth(...args) {
618
241
  if (args.length > 4) {
619
242
  throw new Error('Too many args in unSynth()');