@astrale-os/kernel-dsl 0.2.0-beta.8 → 0.2.0

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 (321) hide show
  1. package/dist/v1/addressing/class-key.js +5 -4
  2. package/dist/v1/addressing/method-key.js +3 -2
  3. package/dist/v1/addressing/patterns.d.ts +0 -5
  4. package/dist/v1/addressing/patterns.js +5 -5
  5. package/dist/v1/builder/callable/authoring.d.ts +87 -41
  6. package/dist/v1/builder/callable/authoring.js +29 -14
  7. package/dist/v1/builder/class/authoring.d.ts +311 -36
  8. package/dist/v1/builder/class/authoring.js +3 -4
  9. package/dist/v1/builder/class/property.d.ts +16 -8
  10. package/dist/v1/builder/class/property.js +21 -5
  11. package/dist/v1/builder/core/authoring.d.ts +28 -13
  12. package/dist/v1/builder/core/authoring.js +22 -2
  13. package/dist/v1/builder/index.d.ts +9 -8
  14. package/dist/v1/builder/index.js +2 -2
  15. package/dist/v1/builder/lowering/callable.d.ts +3 -1
  16. package/dist/v1/builder/lowering/callable.js +43 -51
  17. package/dist/v1/builder/lowering/class.d.ts +7 -0
  18. package/dist/v1/builder/lowering/class.js +79 -29
  19. package/dist/v1/builder/lowering/core.d.ts +3 -2
  20. package/dist/v1/builder/lowering/core.js +9 -6
  21. package/dist/v1/builder/lowering/policy.d.ts +8 -1
  22. package/dist/v1/builder/lowering/policy.js +35 -0
  23. package/dist/v1/builder/lowering/schema/capture.js +9 -4
  24. package/dist/v1/builder/lowering/schema/compile.d.ts +2 -2
  25. package/dist/v1/builder/lowering/schema/compile.js +15 -2
  26. package/dist/v1/builder/lowering/schema/context.d.ts +11 -8
  27. package/dist/v1/builder/lowering/schema/context.js +59 -29
  28. package/dist/v1/builder/lowering/schema/ownership.d.ts +3 -3
  29. package/dist/v1/builder/lowering/schema/ownership.js +2 -1
  30. package/dist/v1/builder/lowering/value/compile.js +14 -4
  31. package/dist/v1/builder/lowering/value/zod.d.ts +7 -6
  32. package/dist/v1/builder/lowering/value/zod.js +16 -7
  33. package/dist/v1/builder/lowering/view.d.ts +4 -3
  34. package/dist/v1/builder/lowering/view.js +2 -14
  35. package/dist/v1/builder/policy/authoring.d.ts +23 -6
  36. package/dist/v1/builder/policy/authoring.js +35 -8
  37. package/dist/v1/builder/schema/define.d.ts +8 -5
  38. package/dist/v1/builder/schema/diagnostic.d.ts +1 -1
  39. package/dist/v1/builder/schema/handle.d.ts +2 -1
  40. package/dist/v1/builder/schema/input.d.ts +9 -1
  41. package/dist/v1/builder/schema/projection/callable.d.ts +51 -0
  42. package/dist/v1/builder/schema/projection/callable.js +1 -0
  43. package/dist/v1/builder/schema/projection/class.d.ts +89 -0
  44. package/dist/v1/builder/schema/projection/class.js +1 -0
  45. package/dist/v1/builder/schema/projection/core-input.d.ts +32 -0
  46. package/dist/v1/builder/schema/projection/core-input.js +1 -0
  47. package/dist/v1/builder/schema/projection/domain.d.ts +59 -0
  48. package/dist/v1/builder/schema/projection/domain.js +1 -0
  49. package/dist/v1/builder/schema/projection/identity.d.ts +39 -0
  50. package/dist/v1/builder/schema/projection/identity.js +1 -0
  51. package/dist/v1/builder/schema/projection/model.d.ts +59 -0
  52. package/dist/v1/builder/schema/projection/model.js +1 -0
  53. package/dist/v1/builder/schema/projection/property.d.ts +32 -0
  54. package/dist/v1/builder/schema/projection/property.js +1 -0
  55. package/dist/v1/builder/schema/projection/resolved-class.d.ts +76 -0
  56. package/dist/v1/builder/schema/projection/resolved-class.js +1 -0
  57. package/dist/v1/builder/schema/projection.d.ts +4 -258
  58. package/dist/v1/builder/value/full-match.js +6 -3
  59. package/dist/v1/builder/value/path.d.ts +2 -2
  60. package/dist/v1/builder/value/path.js +2 -2
  61. package/dist/v1/builder/view/authoring.d.ts +6 -14
  62. package/dist/v1/builder/view/authoring.js +13 -5
  63. package/dist/v1/bundle/structure.d.ts +2 -1
  64. package/dist/v1/compiled/admission/accept.d.ts +1 -1
  65. package/dist/v1/compiled/admission/accept.js +11 -814
  66. package/dist/v1/compiled/admission/closure.d.ts +3 -0
  67. package/dist/v1/compiled/admission/closure.js +173 -0
  68. package/dist/v1/compiled/admission/diagnostic.d.ts +7 -0
  69. package/dist/v1/compiled/admission/diagnostic.js +13 -0
  70. package/dist/v1/compiled/admission/revision.js +9 -1
  71. package/dist/v1/compiled/admission/semantics/cardinality.d.ts +5 -0
  72. package/dist/v1/compiled/admission/semantics/cardinality.js +113 -0
  73. package/dist/v1/compiled/admission/semantics/class.d.ts +5 -0
  74. package/dist/v1/compiled/admission/semantics/class.js +125 -0
  75. package/dist/v1/compiled/admission/semantics/context.d.ts +60 -0
  76. package/dist/v1/compiled/admission/semantics/context.js +81 -0
  77. package/dist/v1/compiled/admission/semantics/core.d.ts +35 -0
  78. package/dist/v1/compiled/admission/semantics/core.js +123 -0
  79. package/dist/v1/compiled/admission/semantics/edge.d.ts +8 -0
  80. package/dist/v1/compiled/admission/semantics/edge.js +89 -0
  81. package/dist/v1/compiled/admission/semantics/policy/admit.d.ts +4 -0
  82. package/dist/v1/compiled/admission/semantics/policy/admit.js +63 -0
  83. package/dist/v1/compiled/admission/semantics/policy/callable.d.ts +5 -0
  84. package/dist/v1/compiled/admission/semantics/policy/callable.js +72 -0
  85. package/dist/v1/compiled/admission/semantics/policy/contracts.d.ts +24 -0
  86. package/dist/v1/compiled/admission/semantics/policy/contracts.js +45 -0
  87. package/dist/v1/compiled/admission/semantics/policy/equality.d.ts +8 -0
  88. package/dist/v1/compiled/admission/semantics/policy/equality.js +27 -0
  89. package/dist/v1/compiled/admission/semantics/policy/measure.d.ts +9 -0
  90. package/dist/v1/compiled/admission/semantics/policy/measure.js +81 -0
  91. package/dist/v1/compiled/admission/semantics/policy/parity.d.ts +4 -0
  92. package/dist/v1/compiled/admission/semantics/policy/parity.js +139 -0
  93. package/dist/v1/compiled/admission/semantics/policy/pattern.d.ts +8 -0
  94. package/dist/v1/compiled/admission/semantics/policy/pattern.js +78 -0
  95. package/dist/v1/compiled/admission/semantics/policy/typing.d.ts +28 -0
  96. package/dist/v1/compiled/admission/semantics/policy/typing.js +206 -0
  97. package/dist/v1/compiled/admission/semantics/policy/variants.d.ts +10 -0
  98. package/dist/v1/compiled/admission/semantics/policy/variants.js +65 -0
  99. package/dist/v1/compiled/admission/semantics.d.ts +1 -1
  100. package/dist/v1/compiled/admission/semantics.js +8 -1078
  101. package/dist/v1/compiled/admission/wire/callable.d.ts +6 -0
  102. package/dist/v1/compiled/admission/wire/callable.js +90 -0
  103. package/dist/v1/compiled/admission/wire/class.d.ts +4 -0
  104. package/dist/v1/compiled/admission/wire/class.js +133 -0
  105. package/dist/v1/compiled/admission/wire/core.d.ts +5 -0
  106. package/dist/v1/compiled/admission/wire/core.js +32 -0
  107. package/dist/v1/compiled/admission/wire/dependency.d.ts +14 -0
  108. package/dist/v1/compiled/admission/wire/dependency.js +43 -0
  109. package/dist/v1/compiled/admission/wire/entry.d.ts +5 -0
  110. package/dist/v1/compiled/admission/wire/entry.js +100 -0
  111. package/dist/v1/compiled/admission/wire/pattern.d.ts +12 -0
  112. package/dist/v1/compiled/admission/wire/pattern.js +111 -0
  113. package/dist/v1/compiled/admission/wire/policy.d.ts +10 -0
  114. package/dist/v1/compiled/admission/wire/policy.js +189 -0
  115. package/dist/v1/compiled/admission/wire/program.d.ts +4 -0
  116. package/dist/v1/compiled/admission/wire/program.js +52 -0
  117. package/dist/v1/compiled/admission/wire/property.d.ts +4 -0
  118. package/dist/v1/compiled/admission/wire/property.js +74 -0
  119. package/dist/v1/compiled/admission/wire/reference.d.ts +8 -0
  120. package/dist/v1/compiled/admission/wire/reference.js +33 -0
  121. package/dist/v1/compiled/admission/wire/value.d.ts +29 -0
  122. package/dist/v1/compiled/admission/wire/value.js +98 -0
  123. package/dist/v1/compiled/admission/wire/view.d.ts +3 -0
  124. package/dist/v1/compiled/admission/wire/view.js +17 -0
  125. package/dist/v1/compiled/compiler/compile.js +43 -11
  126. package/dist/v1/compiled/generated.d.ts +10 -0
  127. package/dist/v1/compiled/generated.js +15 -0
  128. package/dist/v1/compiled/loader/load.d.ts +5 -0
  129. package/dist/v1/compiled/loader/load.js +18 -4
  130. package/dist/v1/compiled/model/schema.d.ts +16 -7
  131. package/dist/v1/domain/create.js +18 -28
  132. package/dist/v1/domain/model/domain.d.ts +0 -1
  133. package/dist/v1/domain/model/input.d.ts +3 -0
  134. package/dist/v1/domain/projection/classes.js +13 -41
  135. package/dist/v1/domain/validation/create.d.ts +2 -0
  136. package/dist/v1/domain/validation/create.js +12 -0
  137. package/dist/v1/index.d.ts +5 -2
  138. package/dist/v1/index.js +3 -1
  139. package/dist/v1/language/callable/composition.d.ts +27 -0
  140. package/dist/v1/language/callable/composition.js +52 -0
  141. package/dist/v1/language/callable/executable.d.ts +6 -0
  142. package/dist/v1/language/callable/executable.js +4 -0
  143. package/dist/v1/language/callable/model/callable.d.ts +34 -9
  144. package/dist/v1/language/callable/model/callable.js +3 -1
  145. package/dist/v1/language/callable/resolved.d.ts +23 -8
  146. package/dist/v1/language/class/facets.d.ts +5 -2
  147. package/dist/v1/language/class/inheritance.d.ts +12 -0
  148. package/dist/v1/language/class/inheritance.js +25 -0
  149. package/dist/v1/language/class/lifetime.d.ts +17 -0
  150. package/dist/v1/language/class/lifetime.js +26 -0
  151. package/dist/v1/language/class/model/class.d.ts +8 -4
  152. package/dist/v1/language/class/model/property.d.ts +4 -2
  153. package/dist/v1/language/class/property-values.js +5 -2
  154. package/dist/v1/language/class/resolved.d.ts +25 -15
  155. package/dist/v1/language/core/model/core.d.ts +7 -1
  156. package/dist/v1/language/core/resolved.d.ts +6 -2
  157. package/dist/v1/language/definition/metadata.d.ts +8 -0
  158. package/dist/v1/language/definition/metadata.js +12 -0
  159. package/dist/v1/language/index.d.ts +9 -0
  160. package/dist/v1/language/index.js +6 -0
  161. package/dist/v1/language/policy/analysis/branches.d.ts +4 -3
  162. package/dist/v1/language/policy/analysis/branches.js +54 -12
  163. package/dist/v1/language/policy/analysis/budgets.js +1 -1
  164. package/dist/v1/language/policy/analysis/checks.d.ts +28 -0
  165. package/dist/v1/language/policy/analysis/checks.js +80 -0
  166. package/dist/v1/language/policy/index.d.ts +1 -0
  167. package/dist/v1/language/policy/index.js +1 -0
  168. package/dist/v1/language/policy/model/policy.d.ts +71 -5
  169. package/dist/v1/language/policy/model/policy.js +52 -1
  170. package/dist/v1/language/policy/normalization/normalize.d.ts +12 -1
  171. package/dist/v1/language/policy/normalization/normalize.js +178 -44
  172. package/dist/v1/language/state/index.d.ts +3 -0
  173. package/dist/v1/language/state/index.js +1 -0
  174. package/dist/v1/language/state/machine.d.ts +28 -0
  175. package/dist/v1/language/state/machine.js +40 -0
  176. package/dist/v1/language/state/topology.d.ts +14 -0
  177. package/dist/v1/language/state/topology.js +69 -0
  178. package/dist/v1/language/value/compile/fields.d.ts +1 -1
  179. package/dist/v1/language/value/compile/load.d.ts +4 -2
  180. package/dist/v1/language/value/compile/load.js +22 -1
  181. package/dist/v1/language/value/compile/model.d.ts +16 -1
  182. package/dist/v1/language/value/evaluate/assertions.d.ts +2 -0
  183. package/dist/v1/language/value/evaluate/assertions.js +13 -0
  184. package/dist/v1/language/value/evaluate/evaluator.js +111 -28
  185. package/dist/v1/language/value/evaluate/preparation.d.ts +10 -1
  186. package/dist/v1/language/value/evaluate/preparation.js +17 -26
  187. package/dist/v1/language/value/evaluate/program.js +1 -1
  188. package/dist/v1/language/value/evaluate/validate.d.ts +6 -2
  189. package/dist/v1/language/value/evaluate/validate.js +18 -11
  190. package/dist/v1/language/value/inclusion/includes.d.ts +9 -0
  191. package/dist/v1/language/value/inclusion/includes.js +777 -0
  192. package/dist/v1/language/value/model/blob.d.ts +31 -0
  193. package/dist/v1/language/value/model/blob.js +90 -0
  194. package/dist/v1/language/value/model/instant.d.ts +0 -2
  195. package/dist/v1/language/value/model/instant.js +1 -1
  196. package/dist/v1/language/value/model/schema.d.ts +2 -1
  197. package/dist/v1/language/value/model/schema.js +1 -5
  198. package/dist/v1/language/value/ordering.d.ts +2 -0
  199. package/dist/v1/language/value/ordering.js +4 -8
  200. package/dist/v1/language/value/profile/json.validate.js +1 -1
  201. package/dist/v1/language/value/profile/rules.js +48 -12
  202. package/dist/v1/language/value/reference/registry.d.ts +2 -1
  203. package/dist/v1/language/value/regexp/ast.js +3 -64
  204. package/dist/v1/language/value/regexp/compile.d.ts +32 -3
  205. package/dist/v1/language/value/regexp/compile.js +117 -21
  206. package/dist/v1/language/value/regexp/matcher.d.ts +6 -3
  207. package/dist/v1/language/value/regexp/matcher.js +185 -28
  208. package/dist/v1/language/value/regexp/syntax.d.ts +12 -1
  209. package/dist/v1/language/value/regexp/syntax.js +14 -2
  210. package/dist/v1/language/value/regexp/unicode.d.ts +32 -0
  211. package/dist/v1/language/value/regexp/unicode.js +139 -0
  212. package/dist/v1/language/value/syntax/full-match.js +8 -5
  213. package/dist/v1/language/value/syntax/node-path/validate.js +4 -6
  214. package/dist/v1/language/view/model/view.d.ts +2 -4
  215. package/dist/v1/language/view/resolved.d.ts +2 -2
  216. package/dist/v1/schema/analysis/class.d.ts +36 -6
  217. package/dist/v1/schema/analysis/class.js +31 -66
  218. package/dist/v1/schema/canonical/revision.d.ts +2 -1
  219. package/dist/v1/schema/canonical/revision.js +4 -1
  220. package/dist/v1/schema/compatibility/api.d.ts +3 -0
  221. package/dist/v1/schema/compatibility/api.js +2 -0
  222. package/dist/v1/schema/compatibility/comparators/callables.d.ts +39 -0
  223. package/dist/v1/schema/compatibility/comparators/callables.js +101 -0
  224. package/dist/v1/schema/compatibility/comparators/classes.d.ts +47 -0
  225. package/dist/v1/schema/compatibility/comparators/classes.js +160 -0
  226. package/dist/v1/schema/compatibility/comparators/index.d.ts +12 -0
  227. package/dist/v1/schema/compatibility/comparators/index.js +53 -0
  228. package/dist/v1/schema/compatibility/comparators/members.d.ts +4 -0
  229. package/dist/v1/schema/compatibility/comparators/members.js +49 -0
  230. package/dist/v1/schema/compatibility/comparators/values.d.ts +5 -0
  231. package/dist/v1/schema/compatibility/comparators/values.js +37 -0
  232. package/dist/v1/schema/compatibility/compare.d.ts +5 -0
  233. package/dist/v1/schema/compatibility/compare.js +23 -0
  234. package/dist/v1/schema/compatibility/context.d.ts +19 -0
  235. package/dist/v1/schema/compatibility/context.js +49 -0
  236. package/dist/v1/schema/compatibility/coordinate.d.ts +40 -0
  237. package/dist/v1/schema/compatibility/coordinate.js +38 -0
  238. package/dist/v1/schema/compatibility/diff.d.ts +12 -0
  239. package/dist/v1/schema/compatibility/diff.js +39 -0
  240. package/dist/v1/schema/compatibility/evidence.d.ts +16 -0
  241. package/dist/v1/schema/compatibility/evidence.js +62 -0
  242. package/dist/v1/schema/compatibility/fields.d.ts +194 -0
  243. package/dist/v1/schema/compatibility/fields.js +94 -0
  244. package/dist/v1/schema/compatibility/index.d.ts +6 -0
  245. package/dist/v1/schema/compatibility/index.js +3 -0
  246. package/dist/v1/schema/compatibility/meaning/footprint.d.ts +7 -0
  247. package/dist/v1/schema/compatibility/meaning/footprint.js +59 -0
  248. package/dist/v1/schema/compatibility/meaning/index.d.ts +3 -0
  249. package/dist/v1/schema/compatibility/meaning/index.js +16 -0
  250. package/dist/v1/schema/compatibility/model.d.ts +131 -0
  251. package/dist/v1/schema/compatibility/model.js +1 -0
  252. package/dist/v1/schema/compatibility/references.d.ts +38 -0
  253. package/dist/v1/schema/compatibility/references.js +149 -0
  254. package/dist/v1/schema/compatibility/report.d.ts +27 -0
  255. package/dist/v1/schema/compatibility/report.js +100 -0
  256. package/dist/v1/schema/compatibility/scope.d.ts +36 -0
  257. package/dist/v1/schema/compatibility/scope.js +110 -0
  258. package/dist/v1/schema/compatibility/structure/index.d.ts +3 -0
  259. package/dist/v1/schema/compatibility/structure/index.js +40 -0
  260. package/dist/v1/schema/compatibility/structure/inheritance.d.ts +7 -0
  261. package/dist/v1/schema/compatibility/structure/inheritance.js +68 -0
  262. package/dist/v1/schema/compatibility/structure/requirements.d.ts +7 -0
  263. package/dist/v1/schema/compatibility/structure/requirements.js +97 -0
  264. package/dist/v1/schema/compatibility/subjects.d.ts +39 -0
  265. package/dist/v1/schema/compatibility/subjects.js +143 -0
  266. package/dist/v1/schema/compatibility/versioning/index.d.ts +8 -0
  267. package/dist/v1/schema/compatibility/versioning/index.js +50 -0
  268. package/dist/v1/schema/compatibility/versioning/members.d.ts +12 -0
  269. package/dist/v1/schema/compatibility/versioning/members.js +47 -0
  270. package/dist/v1/schema/compatibility/versioning/surface.d.ts +11 -0
  271. package/dist/v1/schema/compatibility/versioning/surface.js +61 -0
  272. package/dist/v1/schema/diagnostic.d.ts +1 -1
  273. package/dist/v1/schema/fingerprint.d.ts +2 -0
  274. package/dist/v1/schema/fingerprint.js +1 -0
  275. package/dist/v1/schema/index.d.ts +4 -3
  276. package/dist/v1/schema/index.js +2 -1
  277. package/dist/v1/schema/model/schema.d.ts +8 -11
  278. package/dist/v1/schema/normalization/domain.js +57 -13
  279. package/dist/v1/schema/resolution/definition.index.d.ts +1 -2
  280. package/dist/v1/schema/resolution/definition.index.js +0 -3
  281. package/dist/v1/schema/resolution/domain.d.ts +4 -1
  282. package/dist/v1/schema/resolution/domain.js +26 -18
  283. package/dist/v1/schema/resolution/origins.d.ts +28 -5
  284. package/dist/v1/schema/resolution/origins.js +68 -31
  285. package/dist/v1/schema/validation/callable.d.ts +4 -0
  286. package/dist/v1/schema/validation/callable.js +39 -0
  287. package/dist/v1/schema/validation/class.d.ts +10 -0
  288. package/dist/v1/schema/validation/class.js +79 -60
  289. package/dist/v1/schema/validation/core.js +83 -55
  290. package/dist/v1/schema/validation/domain.d.ts +2 -1
  291. package/dist/v1/schema/validation/domain.js +2 -0
  292. package/dist/v1/schema/validation/domain.structure.d.ts +0 -2
  293. package/dist/v1/schema/validation/domain.structure.js +214 -171
  294. package/dist/v1/schema/validation/policy/budgets.js +36 -6
  295. package/dist/v1/schema/validation/policy/context.js +5 -16
  296. package/dist/v1/schema/validation/policy/objects.d.ts +4 -0
  297. package/dist/v1/schema/validation/policy/objects.js +71 -0
  298. package/dist/v1/schema/validation/policy/references.js +16 -4
  299. package/dist/v1/schema/validation/policy/typing.d.ts +2 -0
  300. package/dist/v1/schema/validation/policy/typing.js +55 -7
  301. package/dist/v1/schema/validation/policy/uses.js +73 -99
  302. package/dist/v1/schema/validation/value-api.d.ts +2 -0
  303. package/dist/v1/schema/validation/value-api.js +1 -0
  304. package/dist/v1/schema/validation/value.js +7 -1
  305. package/dist/v1/schema/validation/view.js +14 -9
  306. package/dist/value/accept.d.ts +9 -0
  307. package/dist/value/accept.js +106 -7
  308. package/dist/value/canonical.d.ts +3 -0
  309. package/dist/value/canonical.js +22 -6
  310. package/dist/value/immutable.optimization.d.ts +15 -0
  311. package/dist/value/immutable.optimization.js +34 -0
  312. package/dist/value/index.d.ts +1 -1
  313. package/dist/value/index.js +1 -1
  314. package/dist/value/json.d.ts +1 -1
  315. package/dist/value/json.js +1 -1
  316. package/dist/value/limits.d.ts +1 -1
  317. package/dist/value/unicode.d.ts +4 -1
  318. package/dist/value/unicode.js +28 -0
  319. package/package.json +20 -5
  320. package/dist/v1/schema/compatibility/meaning.d.ts +0 -29
  321. package/dist/v1/schema/compatibility/meaning.js +0 -605
@@ -1,27 +1,25 @@
1
1
  import { accept as acceptPortable } from '@astrale-os/kernel-dsl/value';
2
2
  import { dependencyLimits } from '../../addressing/domain-dependency.js';
3
- import { isDefinitionRef, Key } from '../../addressing/index.js';
4
- import { DEPENDENCY_ALIAS_PATTERN, DOMAIN_ORIGIN_PATTERN, DOMAIN_REVISION_PATTERN, MEMBER_NAME_PATTERN, } from '../../addressing/patterns.js';
5
- import { MEDIA_TYPE_PATTERN } from '../../language/class/model/data.js';
6
- import { PropertyValues } from '../../language/class/property-values.js';
7
- import { classifyValueProgramOrdering } from '../../language/value/ordering.js';
8
- import { invalidCompiled } from '../diagnostic.js';
9
- import { revisionOfCompiledEntry } from './revision.js';
3
+ import {} from '../model/schema.js';
4
+ import { validateClosure } from './closure.js';
5
+ import { invalid, pointer } from './diagnostic.js';
10
6
  import { validateCompiledSemantics } from './semantics.js';
7
+ import { dependency } from './wire/dependency.js';
8
+ import { entry } from './wire/entry.js';
9
+ import {} from './wire/pattern.js';
10
+ import { object, exact, array } from './wire/value.js';
11
11
  const MAXIMUM_COMPILED_SCHEMA_MEMBERS = 1_000_000;
12
- function pointer(parent, member) {
13
- return `${parent}/${String(member).replaceAll('~', '~0').replaceAll('/', '~1')}`;
14
- }
15
12
  /** Admit one detached compiled closure before indices and declarations become executable. */
16
13
  export function acceptCompiledSchema(input) {
17
14
  const root = object(acceptPortable(input, { limits: { maxMembers: MAXIMUM_COMPILED_SCHEMA_MEMBERS } }), 'CompiledSchema', '');
18
15
  exact(root, ['format', 'version', 'root', 'closure'], 'CompiledSchema', '');
19
16
  if (root.format !== 'astrale.dsl.compiled-schema')
20
17
  invalid('format', undefined, '/format');
21
- if (root.version !== 1)
18
+ if (root.version !== 2)
22
19
  invalid('version', undefined, '/version');
23
20
  const rootPin = dependency(root.root, 'root', '/root');
24
- const closure = array(root.closure, 'closure', '/closure').map((value, index) => entry(value, index, `/closure/${index}`));
21
+ const machines = new Map();
22
+ const closure = array(root.closure, 'closure', '/closure').map((value, index) => entry(value, index, `/closure/${index}`, machines));
25
23
  if (closure.length > dependencyLimits.closure) {
26
24
  invalid('dependency closure limit', 'COMPILED_DEPENDENCY_LIMITS', '/closure');
27
25
  }
@@ -63,7 +61,7 @@ export function acceptCompiledSchema(input) {
63
61
  }
64
62
  const candidate = {
65
63
  format: 'astrale.dsl.compiled-schema',
66
- version: 1,
64
+ version: 2,
67
65
  root: rootPin,
68
66
  closure,
69
67
  };
@@ -71,807 +69,6 @@ export function acceptCompiledSchema(input) {
71
69
  validateCompiledSemantics(candidate);
72
70
  return deepFreeze(candidate);
73
71
  }
74
- function entry(input, entryIndex, path) {
75
- const value = object(input, `closure[${entryIndex}]`, path);
76
- exact(value, ['origin', 'revision', 'dependencies', 'definitions', 'facts', 'values'], 'entry', path);
77
- const origin = originValue(value.origin, 'entry origin', `${path}/origin`);
78
- const revision = revisionValue(value.revision, 'entry revision', `${path}/revision`);
79
- const dependenciesPath = `${path}/dependencies`;
80
- const dependencies = dependencyMap(value.dependencies, dependenciesPath);
81
- const dependencyOrigins = new Set();
82
- for (const [alias, dependency] of Object.entries(dependencies)) {
83
- if (dependencyOrigins.has(dependency.origin))
84
- invalid('duplicate dependency', undefined, `${pointer(dependenciesPath, alias)}/origin`);
85
- dependencyOrigins.add(dependency.origin);
86
- }
87
- const valuesPath = `${path}/values`;
88
- const values = array(value.values, 'values', valuesPath).map((item, index) => program(item, index, `${valuesPath}/${index}`));
89
- const definitionsPath = `${path}/definitions`;
90
- const definitions = object(value.definitions, 'definitions', definitionsPath);
91
- exact(definitions, ['classes', 'functions', 'policies', 'views', 'core'], 'definitions', definitionsPath);
92
- const classesPath = `${definitionsPath}/classes`;
93
- const classes = array(definitions.classes, 'classes', classesPath).map((item, index) => compiledClass(item, values, `${classesPath}/${index}`));
94
- const functionsPath = `${definitionsPath}/functions`;
95
- const functions = array(definitions.functions, 'functions', functionsPath).map((item, index) => compiledFunction(item, values, `${functionsPath}/${index}`));
96
- const factsPath = `${path}/facts`;
97
- const facts = object(value.facts, 'facts', factsPath);
98
- exact(facts, ['core'], 'facts', factsPath);
99
- const policiesPath = `${definitionsPath}/policies`;
100
- const viewsPath = `${definitionsPath}/views`;
101
- const coreDefinitionsPath = `${definitionsPath}/core`;
102
- const coreFactsPath = `${factsPath}/core`;
103
- const accepted = {
104
- origin,
105
- revision,
106
- dependencies,
107
- definitions: {
108
- classes,
109
- functions,
110
- policies: array(definitions.policies, 'policies', policiesPath).map((item, index) => compiledPolicy(item, `${policiesPath}/${index}`)),
111
- views: array(definitions.views, 'views', viewsPath).map((item, index) => compiledView(item, `${viewsPath}/${index}`)),
112
- core: array(definitions.core, 'core definitions', coreDefinitionsPath).map((item, index) => compiledCoreDefinition(item, `${coreDefinitionsPath}/${index}`)),
113
- },
114
- facts: {
115
- core: array(facts.core, 'core facts', coreFactsPath).map((item, index) => compiledCoreEdge(item, `${coreFactsPath}/${index}`)),
116
- },
117
- values,
118
- };
119
- const collections = [
120
- ['classes', accepted.definitions.classes],
121
- ['functions', accepted.definitions.functions],
122
- ['policies', accepted.definitions.policies],
123
- ['views', accepted.definitions.views],
124
- ['core', accepted.definitions.core],
125
- ];
126
- for (const [collection, definitions] of collections) {
127
- for (const [index, definition] of definitions.entries()) {
128
- if (definition.ref.origin !== origin)
129
- invalid('Definition owner origin', undefined, `${definitionsPath}/${collection}/${index}/ref/origin`);
130
- }
131
- }
132
- if (revisionOfCompiledEntry(accepted) !== revision) {
133
- invalid('entry revision', 'COMPILED_CANONICAL_MISMATCH', `${path}/revision`);
134
- }
135
- return accepted;
136
- }
137
- function compiledClass(input, values, path) {
138
- const value = object(input, 'Compiled Class', path);
139
- if (value.kind !== 'node' && value.kind !== 'edge')
140
- invalid('Class kind', undefined, `${path}/kind`);
141
- exact(value, value.kind === 'node'
142
- ? ['ref', 'kind', 'abstract', 'extends', 'properties', 'methods', 'policies']
143
- : [
144
- 'ref',
145
- 'kind',
146
- 'abstract',
147
- 'extends',
148
- 'orientation',
149
- 'endpoints',
150
- 'constraints',
151
- 'properties',
152
- 'policies',
153
- ], 'Compiled Class', path, value.kind === 'node' ? ['data', 'description', 'icon'] : ['description']);
154
- definitionRef(value.ref, 'class', 'Class ref', `${path}/ref`);
155
- boolean(value.abstract, 'Class abstract', `${path}/abstract`);
156
- description(value.description, 'Class description', `${path}/description`);
157
- const extendsPath = `${path}/extends`;
158
- const parents = array(value.extends, 'Class extends', extendsPath).map((parent, index) => definitionRef(parent, 'class', 'Class parent', `${extendsPath}/${index}`));
159
- unique(parents.map(Key.of), 'Class parents', extendsPath);
160
- const propertiesPath = `${path}/properties`;
161
- const properties = array(value.properties, 'Class properties', propertiesPath);
162
- for (const [index, property] of properties.entries())
163
- compiledProperty(property, values, `${propertiesPath}/${index}`);
164
- unique(properties.map((property, index) => string(object(property, 'Compiled Property', `${propertiesPath}/${index}`).name, 'Property name', `${propertiesPath}/${index}/name`)), 'Class Properties', propertiesPath);
165
- if (value.kind === 'node') {
166
- if (value.data !== undefined)
167
- dataDefinition(value.data, `${path}/data`);
168
- boundedString(value.icon, 1, 8000, 'Class icon', `${path}/icon`);
169
- classPolicies(value.policies, true, `${path}/policies`);
170
- const methodsPath = `${path}/methods`;
171
- const methods = array(value.methods, 'Class methods', methodsPath);
172
- for (const [index, method] of methods.entries())
173
- compiledCallable(method, values, true, `${methodsPath}/${index}`);
174
- unique(methods.map((method, index) => string(object(method, 'Compiled Method', `${methodsPath}/${index}`).name, 'Method name', `${methodsPath}/${index}/name`)), 'Class Methods', methodsPath);
175
- }
176
- else {
177
- classPolicies(value.policies, false, `${path}/policies`);
178
- edgeContract(value, path);
179
- }
180
- return value;
181
- }
182
- function compiledFunction(input, values, path) {
183
- const value = object(input, 'Compiled Function', path);
184
- compiledCallable(value, values, false, path);
185
- definitionRef(value.ref, 'function', 'Function ref', `${path}/ref`);
186
- return value;
187
- }
188
- function compiledProperty(input, values, path) {
189
- const value = object(input, 'Compiled Property', path);
190
- exact(value, ['name', 'required', 'visibility', 'value'], 'Compiled Property', path, [
191
- 'auto',
192
- 'description',
193
- 'ordering',
194
- ]);
195
- memberName(value.name, 'Property name', `${path}/name`);
196
- boolean(value.required, 'Property required', `${path}/required`);
197
- if (value.visibility !== 'public' && value.visibility !== 'private') {
198
- invalid('Property visibility', undefined, `${path}/visibility`);
199
- }
200
- description(value.description, 'Property description', `${path}/description`);
201
- if (value.auto !== undefined)
202
- propertyAuto(value.auto, `${path}/auto`);
203
- const valueIndex = index(value.value, values.length, 'Property value', `${path}/value`);
204
- if (value.ordering !== classifyValueProgramOrdering(values[valueIndex])) {
205
- invalid('Property ordering', 'COMPILED_CANONICAL_MISMATCH', `${path}/ordering`);
206
- }
207
- }
208
- function compiledCallable(input, values, method, path) {
209
- const value = object(input, 'Compiled Callable', path);
210
- exact(value, method
211
- ? ['name', 'auth', 'static', 'inheritance', 'input', 'output']
212
- : ['ref', 'auth', 'input', 'output'], 'Compiled Callable', path, ['policy', 'description', 'fields']);
213
- if (method) {
214
- memberName(value.name, 'Method name', `${path}/name`);
215
- boolean(value.static, 'Method static', `${path}/static`);
216
- if (value.inheritance !== 'abstract' &&
217
- value.inheritance !== 'default' &&
218
- value.inheritance !== 'sealed') {
219
- invalid('Method inheritance', undefined, `${path}/inheritance`);
220
- }
221
- }
222
- if (value.auth !== 'anonymous' && value.auth !== 'authenticated' && value.auth !== 'authorized') {
223
- invalid('Callable auth', undefined, `${path}/auth`);
224
- }
225
- description(value.description, 'Callable description', `${path}/description`);
226
- if (value.policy !== undefined) {
227
- if (value.auth !== 'authorized' || (method && value.inheritance === 'abstract')) {
228
- invalid('Callable Policy placement', undefined, `${path}/policy`);
229
- }
230
- policyCheck(value.policy, 0, `${path}/policy`);
231
- }
232
- const inputIndex = index(value.input, values.length, 'Callable input', `${path}/input`);
233
- if (value.fields !== undefined) {
234
- const fieldsPath = `${path}/fields`;
235
- for (const [field, nodes] of Object.entries(object(value.fields, 'Callable fields', fieldsPath))) {
236
- const fieldPath = pointer(fieldsPath, field);
237
- const fieldNodes = array(nodes, 'Callable field nodes', fieldPath);
238
- if (fieldNodes.length === 0)
239
- invalid('Callable field nodes', undefined, fieldPath);
240
- for (const [indexValue, node] of fieldNodes.entries()) {
241
- index(node, values[inputIndex].nodes.length, 'Callable field', `${fieldPath}/${indexValue}`);
242
- }
243
- }
244
- }
245
- const outputPath = `${path}/output`;
246
- const output = object(value.output, 'Callable output', outputPath);
247
- if (output.mode === 'binary')
248
- exact(output, ['mode'], 'binary output', outputPath);
249
- else {
250
- if (output.mode !== 'value' && output.mode !== 'stream')
251
- invalid('Callable output mode', undefined, `${outputPath}/mode`);
252
- exact(output, ['mode', 'value'], 'Callable output', outputPath);
253
- index(output.value, values.length, 'Callable output value', `${outputPath}/value`);
254
- }
255
- }
256
- function compiledPolicy(input, path) {
257
- const value = object(input, 'Policy', path);
258
- exact(value, ['ref', 'expression'], 'Policy', path, ['description']);
259
- definitionRef(value.ref, 'policy', 'Policy ref', `${path}/ref`);
260
- description(value.description, 'Policy description', `${path}/description`);
261
- policyExpression(value.expression, 0, `${path}/expression`);
262
- return value;
263
- }
264
- function compiledView(input, path) {
265
- const value = object(input, 'View', path);
266
- exact(value, ['ref', 'target'], 'View', path, ['description']);
267
- definitionRef(value.ref, 'view', 'View ref', `${path}/ref`);
268
- description(value.description, 'View description', `${path}/description`);
269
- const targetPath = `${path}/target`;
270
- const target = object(value.target, 'View target', targetPath);
271
- if (target.kind === 'domain') {
272
- exact(target, ['kind'], 'Domain View target', targetPath);
273
- }
274
- else if (target.kind === 'definition') {
275
- exact(target, ['kind', 'definitions'], 'Definition View target', targetPath);
276
- const definitionsPath = `${targetPath}/definitions`;
277
- const definitions = array(target.definitions, 'View target definitions', definitionsPath).map((item, index) => definitionRef(item, 'class', 'View target Class', `${definitionsPath}/${index}`));
278
- if (definitions.length === 0)
279
- invalid('View target definitions', undefined, definitionsPath);
280
- unique(definitions.map(Key.of), 'View target definitions', definitionsPath);
281
- }
282
- else {
283
- invalid('View target', undefined, targetPath);
284
- }
285
- return value;
286
- }
287
- function compiledCoreDefinition(input, path) {
288
- const value = object(input, 'Core Definition', path);
289
- exact(value, ['ref', 'class', 'properties'], 'Core Definition', path);
290
- definitionRef(value.ref, 'core', 'Core ref', `${path}/ref`);
291
- definitionRef(value.class, 'class', 'Core Class', `${path}/class`);
292
- propertyValues(value.properties, 'Core Properties', `${path}/properties`);
293
- return value;
294
- }
295
- function compiledCoreEdge(input, path) {
296
- const value = object(input, 'Core Edge', path);
297
- exact(value, ['class', 'source', 'target', 'properties'], 'Core Edge', path);
298
- definitionRef(value.class, 'class', 'Core Edge Class', `${path}/class`);
299
- coreEndpoint(value.source, 'Core Edge source', `${path}/source`);
300
- coreEndpoint(value.target, 'Core Edge target', `${path}/target`);
301
- propertyValues(value.properties, 'Core Edge Properties', `${path}/properties`);
302
- return value;
303
- }
304
- function propertyAuto(input, path) {
305
- const value = object(input, 'Property auto', path);
306
- exact(value, ['on', 'set'], 'Property auto', path);
307
- const eventsPath = `${path}/on`;
308
- const events = array(value.on, 'Property auto events', eventsPath);
309
- if (events.length === 0 || events.some((event) => event !== 'create' && event !== 'update')) {
310
- invalid('Property auto events', undefined, eventsPath);
311
- }
312
- unique(events.map(String), 'Property auto events', eventsPath);
313
- if (value.set !== 'instant')
314
- invalid('Property auto setter', undefined, `${path}/set`);
315
- }
316
- function classPolicies(input, node, path) {
317
- const value = object(input, 'Class Policies', path);
318
- exact(value, [], 'Class Policies', path, node ? ['read', 'traverse'] : ['traverse']);
319
- if (value.read !== undefined)
320
- definitionRef(value.read, 'policy', 'Class read Policy', `${path}/read`);
321
- if (value.traverse !== undefined)
322
- definitionRef(value.traverse, 'policy', 'Class traverse Policy', `${path}/traverse`);
323
- }
324
- function edgeContract(value, path) {
325
- const constraintsPath = `${path}/constraints`;
326
- const constraints = object(value.constraints, 'Edge constraints', constraintsPath);
327
- exact(constraints, [], 'Edge constraints', constraintsPath, ['noSelf', 'acyclic']);
328
- if (constraints.noSelf !== undefined && constraints.noSelf !== true)
329
- invalid('Edge noSelf constraint', undefined, `${constraintsPath}/noSelf`);
330
- if (constraints.acyclic !== undefined && constraints.acyclic !== true)
331
- invalid('Edge acyclic constraint', undefined, `${constraintsPath}/acyclic`);
332
- if (value.orientation === 'directed') {
333
- const endpointsPath = `${path}/endpoints`;
334
- const endpoints = object(value.endpoints, 'directed Edge endpoints', endpointsPath);
335
- exact(endpoints, ['source', 'target'], 'directed Edge endpoints', endpointsPath);
336
- edgeEndpoint(endpoints.source, 'outgoing', 'directed Edge source', `${endpointsPath}/source`);
337
- edgeEndpoint(endpoints.target, 'incoming', 'directed Edge target', `${endpointsPath}/target`);
338
- if (object(endpoints.source, 'directed Edge source', `${endpointsPath}/source`).role ===
339
- object(endpoints.target, 'directed Edge target', `${endpointsPath}/target`).role) {
340
- invalid('Edge endpoint roles', undefined, endpointsPath);
341
- }
342
- return;
343
- }
344
- if (value.orientation !== 'undirected' || constraints.acyclic !== undefined) {
345
- invalid('Edge orientation', undefined, `${path}/orientation`);
346
- }
347
- const endpointsPath = `${path}/endpoints`;
348
- const endpoints = array(value.endpoints, 'undirected Edge endpoints', endpointsPath);
349
- if (endpoints.length !== 2)
350
- invalid('undirected Edge endpoints', undefined, endpointsPath);
351
- edgeEndpoint(endpoints[0], 'incident', 'undirected first endpoint', `${endpointsPath}/0`);
352
- edgeEndpoint(endpoints[1], 'incident', 'undirected second endpoint', `${endpointsPath}/1`);
353
- if (object(endpoints[0], 'undirected first endpoint', `${endpointsPath}/0`).role ===
354
- object(endpoints[1], 'undirected second endpoint', `${endpointsPath}/1`).role) {
355
- invalid('Edge endpoint roles', undefined, endpointsPath);
356
- }
357
- }
358
- function edgeEndpoint(input, count, label, path) {
359
- const value = object(input, label, path);
360
- exact(value, ['role', 'accepts', count], label, path);
361
- memberName(value.role, `${label} role`, `${path}/role`);
362
- const acceptsPath = `${path}/accepts`;
363
- const accepts = array(value.accepts, `${label} accepts`, acceptsPath).map((item, index) => definitionRef(item, 'class', `${label} accepted Class`, `${acceptsPath}/${index}`));
364
- if (accepts.length === 0)
365
- invalid(`${label} accepts`, undefined, acceptsPath);
366
- unique(accepts.map(Key.of), `${label} accepts`, acceptsPath);
367
- if (value[count] !== '0..*' &&
368
- value[count] !== '1..*' &&
369
- value[count] !== '0..1' &&
370
- value[count] !== '1') {
371
- invalid(`${label} ${count}`, undefined, `${path}/${count}`);
372
- }
373
- }
374
- function policyExpression(input, depth, path) {
375
- if (depth > 64)
376
- invalid('Policy expression depth', undefined, path);
377
- const value = object(input, 'Policy expression', path);
378
- if (Object.hasOwn(value, 'match')) {
379
- exact(value, ['match'], 'Policy expression', path);
380
- policyPattern(value.match, depth + 1, `${path}/match`);
381
- return;
382
- }
383
- const member = Object.hasOwn(value, 'allOf') ? 'allOf' : 'anyOf';
384
- exact(value, [member], 'Policy expression', path);
385
- const memberPath = pointer(path, member);
386
- const refs = array(value[member], `Policy ${member}`, memberPath).map((item, index) => definitionRef(item, 'policy', `Policy ${member} ref`, `${memberPath}/${index}`));
387
- if (refs.length === 0)
388
- invalid(`Policy ${member}`, undefined, memberPath);
389
- unique(refs.map(Key.of), `Policy ${member}`, memberPath);
390
- }
391
- function policyPattern(input, depth, path) {
392
- if (depth > 64)
393
- invalid('Policy pattern depth', undefined, path);
394
- const value = object(input, 'Policy pattern', path);
395
- if (Object.hasOwn(value, 'exists')) {
396
- exact(value, ['exists'], 'Policy exists', path);
397
- const existsPath = `${path}/exists`;
398
- const exists = object(value.exists, 'Policy exists', existsPath);
399
- exact(exists, ['nodes', 'where'], 'Policy exists', existsPath);
400
- const nodesPath = `${existsPath}/nodes`;
401
- const nodes = array(exists.nodes, 'Policy variables', nodesPath);
402
- if (nodes.length < 1 || nodes.length > 4)
403
- invalid('Policy variables', undefined, nodesPath);
404
- for (const [index, node] of nodes.entries()) {
405
- const variablePath = `${nodesPath}/${index}`;
406
- const variable = object(node, 'Policy variable', variablePath);
407
- exact(variable, ['variable', 'class'], 'Policy variable', variablePath);
408
- policyTerm(variable.variable, true, `${variablePath}/variable`);
409
- definitionRef(variable.class, 'class', 'Policy variable Class', `${variablePath}/class`);
410
- }
411
- policyPattern(exists.where, depth + 1, `${existsPath}/where`);
412
- return;
413
- }
414
- if (Object.hasOwn(value, 'allOf') || Object.hasOwn(value, 'anyOf')) {
415
- const member = Object.hasOwn(value, 'allOf') ? 'allOf' : 'anyOf';
416
- exact(value, [member], 'Policy pattern composition', path);
417
- const memberPath = pointer(path, member);
418
- const expressions = array(value[member], `Policy pattern ${member}`, memberPath);
419
- if (expressions.length === 0)
420
- invalid(`Policy pattern ${member}`, undefined, memberPath);
421
- for (const [index, expression] of expressions.entries())
422
- policyPattern(expression, depth + 1, `${memberPath}/${index}`);
423
- return;
424
- }
425
- exact(value, ['source', 'class', 'target'], 'Policy Edge pattern', path, ['repeat']);
426
- policyTerm(value.source, false, `${path}/source`);
427
- definitionRef(value.class, 'class', 'Policy Edge Class', `${path}/class`);
428
- policyTerm(value.target, false, `${path}/target`);
429
- if (value.repeat !== undefined) {
430
- const repeatPath = `${path}/repeat`;
431
- const repeat = object(value.repeat, 'Policy repeat', repeatPath);
432
- exact(repeat, ['min', 'max'], 'Policy repeat', repeatPath);
433
- const minimum = boundedInteger(repeat.min, 0, 3, 'Policy repeat minimum', `${repeatPath}/min`);
434
- const maximum = boundedInteger(repeat.max, 0, 3, 'Policy repeat maximum', `${repeatPath}/max`);
435
- if (minimum > maximum)
436
- invalid('Policy repeat order', undefined, repeatPath);
437
- }
438
- }
439
- function policyTerm(input, variableOnly, path) {
440
- const value = object(input, 'Policy pattern term', path);
441
- if (value.kind === 'variable') {
442
- exact(value, ['kind', 'id'], 'Policy variable term', path);
443
- integer(value.id, 'Policy variable id', `${path}/id`);
444
- return;
445
- }
446
- if (variableOnly ||
447
- (value.kind !== 'subject' &&
448
- value.kind !== 'object' &&
449
- value.kind !== 'source' &&
450
- value.kind !== 'target')) {
451
- invalid('Policy pattern term', undefined, `${path}/kind`);
452
- }
453
- exact(value, ['kind'], 'Policy pattern term', path);
454
- }
455
- function policyCheck(input, depth, path) {
456
- if (depth > 64)
457
- invalid('Callable Policy depth', undefined, path);
458
- const value = object(input, 'Callable Policy', path);
459
- if (Object.hasOwn(value, 'check')) {
460
- exact(value, ['check', 'object'], 'Callable Policy check', path);
461
- definitionRef(value.check, 'policy', 'Callable Policy ref', `${path}/check`);
462
- const objectPath = `${path}/object`;
463
- const target = object(value.object, 'Callable Policy object', objectPath);
464
- if (target.kind === 'self')
465
- exact(target, ['kind'], 'Callable Policy self', objectPath);
466
- else if (target.kind === 'input') {
467
- exact(target, ['kind', 'field'], 'Callable Policy input', objectPath);
468
- memberName(target.field, 'Callable Policy input field', `${objectPath}/field`);
469
- }
470
- else if (target.kind === 'ref') {
471
- exact(target, ['kind', 'ref'], 'Callable Policy object ref', objectPath);
472
- definitionRef(target.ref, undefined, 'Callable Policy object ref', `${objectPath}/ref`);
473
- }
474
- else
475
- invalid('Callable Policy object', undefined, `${objectPath}/kind`);
476
- return;
477
- }
478
- const member = Object.hasOwn(value, 'allOf') ? 'allOf' : 'anyOf';
479
- exact(value, [member], 'Callable Policy composition', path);
480
- const memberPath = pointer(path, member);
481
- const expressions = array(value[member], `Callable Policy ${member}`, memberPath);
482
- if (expressions.length === 0)
483
- invalid(`Callable Policy ${member}`, undefined, memberPath);
484
- for (const [index, expression] of expressions.entries())
485
- policyCheck(expression, depth + 1, `${memberPath}/${index}`);
486
- }
487
- function coreEndpoint(input, label, path) {
488
- const value = object(input, label, path);
489
- if (value.kind === 'domain')
490
- exact(value, ['kind'], label, path);
491
- else
492
- definitionRef(value, 'core', label, path);
493
- }
494
- function definitionRef(input, kind, label, path) {
495
- if (!isDefinitionRef(input) || (kind !== undefined && input.kind !== kind))
496
- invalid(label, undefined, path);
497
- return input;
498
- }
499
- function propertyValues(input, label, path) {
500
- try {
501
- PropertyValues.accept(input, path);
502
- }
503
- catch {
504
- invalid(label, undefined, path);
505
- }
506
- }
507
- function dataDefinition(input, path) {
508
- const value = object(input, 'Class data', path);
509
- exact(value, ['mediaType'], 'Class data', path);
510
- if (typeof value.mediaType !== 'string' || !MEDIA_TYPE_PATTERN.test(value.mediaType))
511
- invalid('Class data mediaType', undefined, `${path}/mediaType`);
512
- }
513
- function validateClosure(candidate) {
514
- validateDependencyCycles(candidate);
515
- const definitions = new Map();
516
- for (const [entryIndex, entry] of candidate.closure.entries()) {
517
- const collections = [
518
- ['classes', entry.definitions.classes],
519
- ['functions', entry.definitions.functions],
520
- ['policies', entry.definitions.policies],
521
- ['views', entry.definitions.views],
522
- ['core', entry.definitions.core],
523
- ];
524
- for (const [collection, values] of collections) {
525
- for (const [definitionIndex, definition] of values.entries()) {
526
- const path = `/closure/${entryIndex}/definitions/${collection}/${definitionIndex}`;
527
- const key = Key.of(definition.ref);
528
- if (definitions.has(key))
529
- invalid('duplicate Definition', undefined, `${path}/ref`);
530
- definitions.set(key, { value: definition, path });
531
- }
532
- }
533
- }
534
- const requireDefinition = (ref, label, path) => {
535
- const result = definitions.get(Key.of(ref));
536
- if (result === undefined)
537
- invalid(label, 'COMPILED_SOURCE_INVALID', path);
538
- return result.value;
539
- };
540
- for (const [entryIndex, entry] of candidate.closure.entries()) {
541
- const visibleOrigins = new Set([
542
- entry.origin,
543
- ...Object.values(entry.dependencies).map(({ origin }) => origin),
544
- ]);
545
- const collections = [
546
- ['definitions/classes', entry.definitions.classes],
547
- ['definitions/functions', entry.definitions.functions],
548
- ['definitions/policies', entry.definitions.policies],
549
- ['definitions/views', entry.definitions.views],
550
- ['definitions/core', entry.definitions.core],
551
- ['facts/core', entry.facts.core],
552
- ];
553
- for (const [collection, values] of collections) {
554
- for (const [definitionIndex, definition] of values.entries()) {
555
- walk(definition, `/closure/${entryIndex}/${collection}/${definitionIndex}`, (ref, path) => {
556
- const resolved = requireDefinition(ref, 'unresolved Definition ref', path);
557
- if (!visibleOrigins.has(ref.origin))
558
- invalid('non-direct dependency ref', 'COMPILED_SOURCE_INVALID', path);
559
- if (resolved.ref === undefined)
560
- invalid('resolved Definition', 'COMPILED_SOURCE_INVALID', path);
561
- });
562
- }
563
- }
564
- }
565
- const classes = new Map();
566
- for (const [entryIndex, entry] of candidate.closure.entries())
567
- for (const [classIndex, definition] of entry.definitions.classes.entries())
568
- classes.set(Key.of(definition.ref), {
569
- value: definition,
570
- path: `/closure/${entryIndex}/definitions/classes/${classIndex}`,
571
- });
572
- const visiting = new Set();
573
- const visited = new Set();
574
- const visitClass = (key) => {
575
- if (visited.has(key))
576
- return;
577
- if (visiting.has(key))
578
- invalid('Class inheritance cycle', 'COMPILED_SOURCE_INVALID', `${classes.get(key)?.path ?? ''}/extends`);
579
- const definition = classes.get(key);
580
- if (definition === undefined)
581
- invalid('Class inheritance ref', 'COMPILED_SOURCE_INVALID', '/closure');
582
- visiting.add(key);
583
- for (const [parentIndex, parentRef] of definition.value.extends.entries()) {
584
- const parent = classes.get(Key.of(parentRef));
585
- if (parent === undefined || parent.value.kind !== definition.value.kind) {
586
- invalid('Class inheritance kind', 'COMPILED_SOURCE_INVALID', `${definition.path}/extends/${parentIndex}`);
587
- }
588
- visitClass(Key.of(parentRef));
589
- }
590
- visiting.delete(key);
591
- visited.add(key);
592
- };
593
- for (const key of classes.keys())
594
- visitClass(key);
595
- for (const definition of classes.values()) {
596
- if (definition.value.kind !== 'edge')
597
- continue;
598
- const endpoints = definition.value.orientation === 'directed'
599
- ? [
600
- definition.value.endpoints.source,
601
- definition.value.endpoints.target,
602
- ]
603
- : definition.value.endpoints;
604
- for (const [endpointIndex, endpoint] of endpoints.entries()) {
605
- const endpointPath = definition.value.orientation === 'directed'
606
- ? `${definition.path}/endpoints/${endpointIndex === 0 ? 'source' : 'target'}`
607
- : `${definition.path}/endpoints/${endpointIndex}`;
608
- for (const [acceptedIndex, accepted] of endpoint.accepts.entries()) {
609
- if (classes.get(Key.of(accepted))?.value.kind !== 'node') {
610
- invalid('Edge endpoint Class', 'COMPILED_SOURCE_INVALID', `${endpointPath}/accepts/${acceptedIndex}`);
611
- }
612
- }
613
- }
614
- }
615
- for (const [entryIndex, entry] of candidate.closure.entries()) {
616
- for (const [definitionIndex, definition] of entry.definitions.core.entries()) {
617
- const owner = classes.get(Key.of(definition.class));
618
- if (owner?.value.kind !== 'node' || owner.value.abstract) {
619
- invalid('Core exact Class', 'COMPILED_SOURCE_INVALID', `/closure/${entryIndex}/definitions/core/${definitionIndex}/class`);
620
- }
621
- }
622
- for (const [edgeIndex, edge] of entry.facts.core.entries()) {
623
- const owner = classes.get(Key.of(edge.class));
624
- if (owner?.value.kind !== 'edge' || owner.value.abstract) {
625
- invalid('Core Edge exact Class', 'COMPILED_SOURCE_INVALID', `/closure/${entryIndex}/facts/core/${edgeIndex}/class`);
626
- }
627
- }
628
- }
629
- }
630
- function validateDependencyCycles(candidate) {
631
- const byOrigin = new Map(candidate.closure.map((entry, index) => [entry.origin, { entry, index }]));
632
- const active = new Set();
633
- const visited = new Set();
634
- const frames = [];
635
- const push = (origin, depth) => {
636
- if (depth > dependencyLimits.depth) {
637
- invalid('dependency depth limit', 'COMPILED_DEPENDENCY_LIMITS', `/closure/${byOrigin.get(origin)?.index ?? 0}/dependencies`);
638
- }
639
- active.add(origin);
640
- frames.push({
641
- origin,
642
- depth,
643
- dependencies: Object.values(byOrigin.get(origin)?.entry.dependencies ?? {}),
644
- index: 0,
645
- });
646
- };
647
- push(candidate.root.origin, 0);
648
- while (frames.length > 0) {
649
- const frame = frames.at(-1);
650
- const dependency = frame.dependencies[frame.index++];
651
- if (dependency === undefined) {
652
- frames.pop();
653
- active.delete(frame.origin);
654
- visited.add(frame.origin);
655
- continue;
656
- }
657
- if (active.has(dependency.origin)) {
658
- invalid('dependency cycle', 'COMPILED_DEPENDENCY_CYCLE', `/closure/${byOrigin.get(dependency.origin)?.index ?? 0}/dependencies`);
659
- }
660
- if (!visited.has(dependency.origin))
661
- push(dependency.origin, frame.depth + 1);
662
- }
663
- }
664
- function walk(input, path, visit) {
665
- if (isDefinitionRef(input)) {
666
- visit(input, path);
667
- return;
668
- }
669
- if (input === null || typeof input !== 'object')
670
- return;
671
- if (Array.isArray(input)) {
672
- for (const [index, value] of input.entries())
673
- walk(value, `${path}/${index}`, visit);
674
- return;
675
- }
676
- for (const [key, value] of Object.entries(input))
677
- walk(value, pointer(path, key), visit);
678
- }
679
- function program(input, programIndex, path) {
680
- const value = object(input, `values[${programIndex}]`, path);
681
- exact(value, ['root', 'nodes', 'patterns'], 'ValueProgram', path);
682
- const nodesPath = `${path}/nodes`;
683
- const nodes = array(value.nodes, 'ValueProgram nodes', nodesPath).map((node, index) => valueNode(node, index, `${nodesPath}/${index}`));
684
- const root = index(value.root, nodes.length, 'ValueProgram root', `${path}/root`);
685
- const patternsPath = `${path}/patterns`;
686
- const patterns = array(value.patterns, 'ValueProgram patterns', patternsPath).map((item, index) => pattern(item, index, `${patternsPath}/${index}`));
687
- unique(patterns.map(({ source }) => source), 'patterns', patternsPath);
688
- for (const [nodeIndex, node] of nodes.entries()) {
689
- for (const [name, child] of Object.entries(node.children))
690
- index(child, nodes.length, 'ValueNode child', pointer(`${nodesPath}/${nodeIndex}/children`, name));
691
- if (node.reference !== undefined)
692
- index(node.reference, nodes.length, 'ValueNode reference', `${nodesPath}/${nodeIndex}/reference`);
693
- }
694
- return { root, nodes, patterns };
695
- }
696
- function valueNode(input, nodeIndex, path) {
697
- const value = object(input, `nodes[${nodeIndex}]`, path);
698
- exact(value, ['schema', 'children'], 'ValueNode', path, ['reference']);
699
- const children = {};
700
- const childrenPath = `${path}/children`;
701
- for (const [name, child] of Object.entries(object(value.children, 'ValueNode children', childrenPath))) {
702
- children[name] = integer(child, 'ValueNode child', pointer(childrenPath, name));
703
- }
704
- return {
705
- schema: value.schema,
706
- children,
707
- ...(value.reference === undefined
708
- ? {}
709
- : { reference: integer(value.reference, 'reference', `${path}/reference`) }),
710
- };
711
- }
712
- function pattern(input, patternIndex, path) {
713
- const value = object(input, `patterns[${patternIndex}]`, path);
714
- exact(value, ['source', 'start', 'states'], 'Pattern', path);
715
- if (typeof value.source !== 'string')
716
- invalid('Pattern source', undefined, `${path}/source`);
717
- const statesPath = `${path}/states`;
718
- const states = array(value.states, 'Pattern states', statesPath).map((item, stateIndex) => {
719
- const statePath = `${statesPath}/${stateIndex}`;
720
- const state = object(item, 'Pattern state', statePath);
721
- exact(state, ['epsilon', 'transitions'], 'Pattern state', statePath, ['accepting']);
722
- if (state.accepting !== undefined && state.accepting !== true)
723
- invalid('accepting', undefined, `${statePath}/accepting`);
724
- const epsilonPath = `${statePath}/epsilon`;
725
- const transitionsPath = `${statePath}/transitions`;
726
- return {
727
- epsilon: array(state.epsilon, 'epsilon', epsilonPath).map((target, index) => integer(target, 'epsilon', `${epsilonPath}/${index}`)),
728
- transitions: array(state.transitions, 'transitions', transitionsPath).map((transitionValue, transitionIndex) => {
729
- const transitionPath = `${transitionsPath}/${transitionIndex}`;
730
- const transition = object(transitionValue, 'transition', transitionPath);
731
- exact(transition, ['to', 'ranges'], 'transition', transitionPath);
732
- const rangesPath = `${transitionPath}/ranges`;
733
- return {
734
- to: integer(transition.to, 'transition target', `${transitionPath}/to`),
735
- ranges: array(transition.ranges, 'ranges', rangesPath).map((rangeValue, rangeIndex) => {
736
- const rangePath = `${rangesPath}/${rangeIndex}`;
737
- const range = array(rangeValue, 'range', rangePath);
738
- if (range.length !== 2)
739
- invalid('range', undefined, rangePath);
740
- const minimum = scalar(range[0], 'range minimum', `${rangePath}/0`);
741
- const maximum = scalar(range[1], 'range maximum', `${rangePath}/1`);
742
- if (minimum > maximum)
743
- invalid('range order', undefined, rangePath);
744
- return [minimum, maximum];
745
- }),
746
- };
747
- }),
748
- ...(state.accepting === true ? { accepting: true } : {}),
749
- };
750
- });
751
- const start = index(value.start, states.length, 'Pattern start', `${path}/start`);
752
- for (const [stateIndex, state] of states.entries()) {
753
- state.epsilon.forEach((target, indexValue) => index(target, states.length, 'epsilon', `${statesPath}/${stateIndex}/epsilon/${indexValue}`));
754
- state.transitions.forEach(({ to }, transitionIndex) => index(to, states.length, 'transition', `${statesPath}/${stateIndex}/transitions/${transitionIndex}/to`));
755
- }
756
- return { source: value.source, start, states };
757
- }
758
- function dependency(input, label, path) {
759
- const value = object(input, label, path);
760
- exact(value, ['origin', 'revision'], label, path);
761
- return {
762
- origin: originValue(value.origin, label, `${path}/origin`),
763
- revision: revisionValue(value.revision, label, `${path}/revision`),
764
- };
765
- }
766
- function dependencyMap(input, path) {
767
- const value = object(input, 'dependencies', path);
768
- const accepted = Object.create(null);
769
- for (const [alias, inputDependency] of Object.entries(value).sort(([left], [right]) => compare(left, right))) {
770
- const aliasPath = pointer(path, alias);
771
- if (!DEPENDENCY_ALIAS_PATTERN.test(alias) ||
772
- alias === '__proto__' ||
773
- alias === 'prototype' ||
774
- alias === 'constructor') {
775
- invalid('dependency alias', undefined, aliasPath);
776
- }
777
- accepted[alias] = dependency(inputDependency, `dependency ${alias}`, aliasPath);
778
- }
779
- return accepted;
780
- }
781
- function originValue(input, label, path) {
782
- if (typeof input !== 'string' || !DOMAIN_ORIGIN_PATTERN.test(input))
783
- invalid(label, undefined, path);
784
- return input;
785
- }
786
- function revisionValue(input, label, path) {
787
- if (typeof input !== 'string' || !DOMAIN_REVISION_PATTERN.test(input))
788
- invalid(label, undefined, path);
789
- return input;
790
- }
791
- function object(input, label, path) {
792
- if (input === null || typeof input !== 'object' || Array.isArray(input))
793
- invalid(label, undefined, path);
794
- return input;
795
- }
796
- function array(input, label, path) {
797
- if (!Array.isArray(input))
798
- invalid(label, undefined, path);
799
- return input;
800
- }
801
- function exact(value, required, label, path, optional = []) {
802
- const allowed = new Set([...required, ...optional]);
803
- const unknown = Object.keys(value)
804
- .filter((key) => !allowed.has(key))
805
- .sort(compare)[0];
806
- if (unknown !== undefined)
807
- invalid(label, undefined, pointer(path, unknown));
808
- const missing = required.find((key) => !Object.hasOwn(value, key));
809
- if (missing !== undefined)
810
- invalid(label, undefined, pointer(path, missing));
811
- }
812
- function integer(input, label, path) {
813
- if (!Number.isSafeInteger(input) || input < 0)
814
- invalid(label, undefined, path);
815
- return input;
816
- }
817
- function boundedInteger(input, minimum, maximum, label, path) {
818
- const value = integer(input, label, path);
819
- if (value < minimum || value > maximum)
820
- invalid(label, undefined, path);
821
- return value;
822
- }
823
- function boolean(input, label, path) {
824
- if (typeof input !== 'boolean')
825
- invalid(label, undefined, path);
826
- return input;
827
- }
828
- function string(input, label, path) {
829
- if (typeof input !== 'string')
830
- invalid(label, undefined, path);
831
- return input;
832
- }
833
- function memberName(input, label, path) {
834
- const value = string(input, label, path);
835
- if (!MEMBER_NAME_PATTERN.test(value))
836
- invalid(label, undefined, path);
837
- return value;
838
- }
839
- function boundedString(input, minimum, maximum, label, path) {
840
- if (input === undefined)
841
- return;
842
- const value = string(input, label, path);
843
- if (value.length < minimum || value.length > maximum)
844
- invalid(label, undefined, path);
845
- }
846
- function description(input, label, path) {
847
- boundedString(input, 1, 1000, label, path);
848
- }
849
- function unique(values, label, path) {
850
- const seen = new Set();
851
- for (const [indexValue, value] of values.entries()) {
852
- if (seen.has(value))
853
- invalid(label, undefined, `${path}/${indexValue}`);
854
- seen.add(value);
855
- }
856
- }
857
- function index(input, length, label, path) {
858
- const value = integer(input, label, path);
859
- if (value >= length)
860
- invalid(label, undefined, path);
861
- return value;
862
- }
863
- function scalar(input, label, path) {
864
- const value = integer(input, label, path);
865
- if (value > 0x10ffff)
866
- invalid(label, undefined, path);
867
- return value;
868
- }
869
- function invalid(label, code = 'COMPILED_STRUCTURE_INVALID', path = '') {
870
- return invalidCompiled(code, `Invalid compiled Schema ${label}.`, path);
871
- }
872
- function compare(left, right) {
873
- return left < right ? -1 : left > right ? 1 : 0;
874
- }
875
72
  function deepFreeze(input) {
876
73
  if (input === null || typeof input !== 'object' || Object.isFrozen(input))
877
74
  return input;