@astrale-os/kernel-dsl 1.0.0-beta.3 → 1.0.0-beta.30

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 (413) hide show
  1. package/dist/v1/addressing/class-key.js +3 -3
  2. package/dist/v1/addressing/definition-ref.js +21 -37
  3. package/dist/v1/addressing/domain-dependency.d.ts +0 -6
  4. package/dist/v1/addressing/domain-dependency.js +1 -6
  5. package/dist/v1/addressing/key.d.ts +4 -1
  6. package/dist/v1/addressing/key.js +23 -3
  7. package/dist/v1/addressing/ordering.d.ts +2 -0
  8. package/dist/v1/addressing/ordering.js +2 -0
  9. package/dist/v1/addressing/patterns.d.ts +1 -1
  10. package/dist/v1/addressing/patterns.js +2 -6
  11. package/dist/v1/builder/callable/authoring.d.ts +11 -5
  12. package/dist/v1/builder/callable/authoring.js +2 -0
  13. package/dist/v1/builder/class/authoring.d.ts +94 -224
  14. package/dist/v1/builder/class/authoring.js +30 -35
  15. package/dist/v1/builder/class/handle.d.ts +27 -0
  16. package/dist/v1/builder/class/handle.js +1 -0
  17. package/dist/v1/builder/class/input.d.ts +159 -0
  18. package/dist/v1/builder/class/projection.d.ts +129 -0
  19. package/dist/v1/builder/class/projection.js +1 -0
  20. package/dist/v1/builder/class/property.d.ts +3 -9
  21. package/dist/v1/builder/class/property.js +1 -0
  22. package/dist/v1/builder/core/authoring.d.ts +1 -1
  23. package/dist/v1/builder/index.d.ts +10 -2
  24. package/dist/v1/builder/index.js +2 -0
  25. package/dist/v1/builder/lowering/callable.js +1 -0
  26. package/dist/v1/builder/lowering/class.d.ts +9 -1
  27. package/dist/v1/builder/lowering/class.js +62 -17
  28. package/dist/v1/builder/lowering/policy.js +6 -24
  29. package/dist/v1/builder/lowering/property-keys.d.ts +27 -0
  30. package/dist/v1/builder/lowering/property-keys.js +108 -0
  31. package/dist/v1/builder/lowering/schema/compile.js +13 -6
  32. package/dist/v1/builder/lowering/schema/context.d.ts +9 -1
  33. package/dist/v1/builder/lowering/schema/context.js +36 -7
  34. package/dist/v1/builder/lowering/schema/lifetime.d.ts +11 -0
  35. package/dist/v1/builder/lowering/schema/lifetime.js +55 -0
  36. package/dist/v1/builder/lowering/value/compile.js +29 -22
  37. package/dist/v1/builder/lowering/value/file.d.ts +7 -0
  38. package/dist/v1/builder/lowering/value/file.js +14 -0
  39. package/dist/v1/builder/lowering/value/path.d.ts +1 -1
  40. package/dist/v1/builder/lowering/value/path.js +2 -4
  41. package/dist/v1/builder/lowering/value/zod.js +41 -7
  42. package/dist/v1/builder/policy/authoring.d.ts +80 -9
  43. package/dist/v1/builder/policy/authoring.js +99 -68
  44. package/dist/v1/builder/policy/legacy/edge.d.ts +28 -0
  45. package/dist/v1/builder/policy/legacy/edge.js +16 -0
  46. package/dist/v1/builder/schema/define.d.ts +0 -1
  47. package/dist/v1/builder/schema/diagnostic.d.ts +3 -2
  48. package/dist/v1/builder/schema/diagnostic.js +5 -10
  49. package/dist/v1/builder/schema/input.d.ts +4 -1
  50. package/dist/v1/builder/schema/projection/callable.d.ts +7 -5
  51. package/dist/v1/builder/schema/projection/class.d.ts +78 -16
  52. package/dist/v1/builder/schema/projection/core-input.d.ts +2 -1
  53. package/dist/v1/builder/schema/projection/domain.d.ts +13 -2
  54. package/dist/v1/builder/schema/projection/identity.d.ts +74 -9
  55. package/dist/v1/builder/schema/projection/model.d.ts +4 -2
  56. package/dist/v1/builder/schema/projection/property.d.ts +38 -4
  57. package/dist/v1/builder/schema/projection/resolved-class.d.ts +5 -4
  58. package/dist/v1/builder/schema/projection.d.ts +1 -1
  59. package/dist/v1/builder/schema/rule.d.ts +316 -0
  60. package/dist/v1/builder/schema/rule.js +192 -0
  61. package/dist/v1/builder/value/file.d.ts +34 -0
  62. package/dist/v1/builder/value/file.js +77 -0
  63. package/dist/v1/builder/value/full-match.d.ts +0 -1
  64. package/dist/v1/builder/value/full-match.js +0 -1
  65. package/dist/v1/builder/value/path-metadata.d.ts +1 -1
  66. package/dist/v1/builder/value/path.d.ts +1 -1
  67. package/dist/v1/bundle/codec.js +55 -74
  68. package/dist/v1/bundle/diagnostic.d.ts +3 -1
  69. package/dist/v1/bundle/diagnostic.js +9 -7
  70. package/dist/v1/bundle/index.d.ts +2 -0
  71. package/dist/v1/bundle/index.js +1 -0
  72. package/dist/v1/bundle/model.js +1 -1
  73. package/dist/v1/bundle/rule.d.ts +14 -0
  74. package/dist/v1/bundle/rule.js +41 -0
  75. package/dist/v1/bundle/structure.js +6 -8
  76. package/dist/v1/compiled/admission/accept.js +9 -15
  77. package/dist/v1/compiled/admission/closure.js +17 -34
  78. package/dist/v1/compiled/admission/diagnostic.d.ts +23 -1
  79. package/dist/v1/compiled/admission/diagnostic.js +40 -3
  80. package/dist/v1/compiled/admission/revision.d.ts +9 -1
  81. package/dist/v1/compiled/admission/revision.js +7 -3
  82. package/dist/v1/compiled/admission/semantics/class.d.ts +4 -1
  83. package/dist/v1/compiled/admission/semantics/class.js +48 -19
  84. package/dist/v1/compiled/admission/semantics/core.d.ts +1 -24
  85. package/dist/v1/compiled/admission/semantics/core.js +56 -24
  86. package/dist/v1/compiled/admission/semantics/edge.d.ts +2 -4
  87. package/dist/v1/compiled/admission/semantics/edge.js +6 -65
  88. package/dist/v1/compiled/admission/semantics/policy/admit.js +4 -19
  89. package/dist/v1/compiled/admission/semantics/policy/callable.js +2 -5
  90. package/dist/v1/compiled/admission/semantics/policy/contracts.d.ts +5 -20
  91. package/dist/v1/compiled/admission/semantics/policy/contracts.js +8 -21
  92. package/dist/v1/compiled/admission/semantics/policy/parity.js +44 -53
  93. package/dist/v1/compiled/admission/semantics/policy/pattern.d.ts +4 -1
  94. package/dist/v1/compiled/admission/semantics/policy/pattern.js +7 -21
  95. package/dist/v1/compiled/admission/semantics/policy/typing.d.ts +2 -24
  96. package/dist/v1/compiled/admission/semantics/policy/typing.js +19 -201
  97. package/dist/v1/compiled/admission/wire/callable.d.ts +5 -2
  98. package/dist/v1/compiled/admission/wire/callable.js +24 -20
  99. package/dist/v1/compiled/admission/wire/class.js +79 -30
  100. package/dist/v1/compiled/admission/wire/entry.d.ts +1 -1
  101. package/dist/v1/compiled/admission/wire/entry.js +36 -13
  102. package/dist/v1/compiled/admission/wire/policy.d.ts +4 -3
  103. package/dist/v1/compiled/admission/wire/policy.js +27 -20
  104. package/dist/v1/compiled/admission/wire/program.d.ts +13 -3
  105. package/dist/v1/compiled/admission/wire/program.js +39 -44
  106. package/dist/v1/compiled/admission/wire/property.d.ts +4 -1
  107. package/dist/v1/compiled/admission/wire/property.js +8 -5
  108. package/dist/v1/compiled/admission/wire/value.d.ts +0 -2
  109. package/dist/v1/compiled/admission/wire/value.js +0 -7
  110. package/dist/v1/compiled/codec/json.js +4 -3
  111. package/dist/v1/compiled/compiler/compile.js +15 -33
  112. package/dist/v1/compiled/diagnostic.d.ts +1 -1
  113. package/dist/v1/compiled/diagnostic.js +2 -3
  114. package/dist/v1/compiled/index.d.ts +2 -0
  115. package/dist/v1/compiled/index.js +1 -0
  116. package/dist/v1/compiled/loader/load.d.ts +3 -2
  117. package/dist/v1/compiled/loader/load.js +12 -51
  118. package/dist/v1/compiled/model/schema.d.ts +3 -0
  119. package/dist/v1/compiled/rule.d.ts +49 -0
  120. package/dist/v1/compiled/rule.js +169 -0
  121. package/dist/v1/domain/create.js +9 -10
  122. package/dist/v1/domain/model/domain.d.ts +2 -7
  123. package/dist/v1/domain/model/input.d.ts +15 -10
  124. package/dist/v1/domain/namespace/member-collection.js +8 -7
  125. package/dist/v1/domain/projection/classes.js +11 -8
  126. package/dist/v1/domain/validation/create.d.ts +7 -16
  127. package/dist/v1/domain/validation/create.js +35 -81
  128. package/dist/v1/index.d.ts +5 -3
  129. package/dist/v1/index.js +1 -1
  130. package/dist/v1/language/.spec/schemas/draft-2020-12.schema.json +462 -0
  131. package/dist/v1/language/.spec/schemas/value-schema.schema.json +23 -0
  132. package/dist/v1/language/callable/admission.d.ts +15 -0
  133. package/dist/v1/language/callable/admission.js +44 -0
  134. package/dist/v1/language/callable/model/callable.d.ts +10 -0
  135. package/dist/v1/language/callable/resolved.d.ts +16 -3
  136. package/dist/v1/language/chain.d.ts +7 -0
  137. package/dist/v1/language/chain.js +24 -0
  138. package/dist/v1/language/class/inheritance.d.ts +36 -5
  139. package/dist/v1/language/class/inheritance.js +85 -1
  140. package/dist/v1/language/class/lifetime.d.ts +50 -11
  141. package/dist/v1/language/class/lifetime.js +89 -20
  142. package/dist/v1/language/class/model/class.d.ts +45 -9
  143. package/dist/v1/language/class/model/edge.d.ts +31 -2
  144. package/dist/v1/language/class/model/property.d.ts +16 -7
  145. package/dist/v1/language/class/property-values.js +2 -4
  146. package/dist/v1/language/class/resolved.d.ts +9 -4
  147. package/dist/v1/language/class/unique.d.ts +143 -0
  148. package/dist/v1/language/class/unique.js +264 -0
  149. package/dist/v1/language/core/facts.d.ts +85 -0
  150. package/dist/v1/language/core/facts.js +116 -0
  151. package/dist/v1/language/cycle.d.ts +10 -0
  152. package/dist/v1/language/cycle.js +30 -0
  153. package/dist/v1/language/definition/metadata.d.ts +38 -0
  154. package/dist/v1/language/definition/metadata.js +51 -0
  155. package/dist/v1/language/freeze.d.ts +5 -0
  156. package/dist/v1/{schema/canonical → language}/freeze.js +4 -0
  157. package/dist/v1/language/index.d.ts +7 -2
  158. package/dist/v1/language/index.js +5 -1
  159. package/dist/v1/language/limits.d.ts +83 -0
  160. package/dist/v1/language/limits.js +77 -0
  161. package/dist/v1/language/policy/analysis/branches.d.ts +8 -0
  162. package/dist/v1/language/policy/analysis/branches.js +8 -8
  163. package/dist/v1/language/policy/analysis/budgets.d.ts +45 -12
  164. package/dist/v1/language/policy/analysis/budgets.js +140 -20
  165. package/dist/v1/language/policy/analysis/checks.js +8 -6
  166. package/dist/v1/language/policy/analysis/composition.d.ts +4 -0
  167. package/dist/v1/language/policy/analysis/composition.js +11 -0
  168. package/dist/v1/language/policy/analysis/typing.d.ts +51 -0
  169. package/dist/v1/language/policy/analysis/typing.js +456 -0
  170. package/dist/v1/language/policy/model/policy.d.ts +71 -9
  171. package/dist/v1/language/policy/model/policy.js +42 -4
  172. package/dist/v1/language/policy/normalization/normalize.d.ts +6 -6
  173. package/dist/v1/language/policy/normalization/normalize.js +46 -68
  174. package/dist/v1/language/suspended.d.ts +7 -0
  175. package/dist/v1/language/suspended.js +23 -0
  176. package/dist/v1/language/validation/diagnostic.d.ts +15 -1
  177. package/dist/v1/language/validation/diagnostic.js +21 -0
  178. package/dist/v1/language/validation/rule.d.ts +45 -0
  179. package/dist/v1/language/validation/rule.js +109 -0
  180. package/dist/v1/language/value/compile/fields.js +16 -16
  181. package/dist/v1/language/value/compile/load.d.ts +5 -0
  182. package/dist/v1/language/value/compile/load.js +13 -0
  183. package/dist/v1/language/value/evaluate/assertions.d.ts +5 -1
  184. package/dist/v1/language/value/evaluate/assertions.js +19 -8
  185. package/dist/v1/language/value/evaluate/evaluator.js +117 -120
  186. package/dist/v1/language/value/evaluate/preparation.d.ts +16 -0
  187. package/dist/v1/language/value/evaluate/preparation.js +100 -47
  188. package/dist/v1/language/value/evaluate/program.d.ts +2 -1
  189. package/dist/v1/language/value/evaluate/program.js +6 -6
  190. package/dist/v1/language/value/evaluate/validate.d.ts +3 -3
  191. package/dist/v1/language/value/evaluate/validate.js +14 -10
  192. package/dist/v1/language/value/evaluate/validity.optimization.d.ts +14 -0
  193. package/dist/v1/language/value/evaluate/validity.optimization.js +338 -0
  194. package/dist/v1/language/value/files.d.ts +44 -0
  195. package/dist/v1/language/value/files.js +151 -0
  196. package/dist/v1/language/value/inclusion/arrays.d.ts +3 -0
  197. package/dist/v1/language/value/inclusion/arrays.js +85 -0
  198. package/dist/v1/language/value/inclusion/assertions.d.ts +18 -0
  199. package/dist/v1/language/value/inclusion/assertions.js +28 -0
  200. package/dist/v1/language/value/inclusion/combinators.d.ts +3 -0
  201. package/dist/v1/language/value/inclusion/combinators.js +67 -0
  202. package/dist/v1/language/value/inclusion/equivalence.d.ts +4 -0
  203. package/dist/v1/language/value/inclusion/equivalence.js +76 -0
  204. package/dist/v1/language/value/inclusion/evidence.d.ts +34 -0
  205. package/dist/v1/language/value/inclusion/evidence.js +140 -0
  206. package/dist/v1/language/value/inclusion/includes.d.ts +29 -3
  207. package/dist/v1/language/value/inclusion/includes.js +58 -723
  208. package/dist/v1/language/value/inclusion/keywords.d.ts +5 -0
  209. package/dist/v1/language/value/inclusion/keywords.js +31 -0
  210. package/dist/v1/language/value/inclusion/kinds.d.ts +17 -0
  211. package/dist/v1/language/value/inclusion/kinds.js +57 -0
  212. package/dist/v1/language/value/inclusion/location.d.ts +24 -0
  213. package/dist/v1/language/value/inclusion/location.js +66 -0
  214. package/dist/v1/language/value/inclusion/numbers.d.ts +3 -0
  215. package/dist/v1/language/value/inclusion/numbers.js +41 -0
  216. package/dist/v1/language/value/inclusion/objects.d.ts +3 -0
  217. package/dist/v1/language/value/inclusion/objects.js +190 -0
  218. package/dist/v1/language/value/inclusion/strings.d.ts +3 -0
  219. package/dist/v1/language/value/inclusion/strings.js +29 -0
  220. package/dist/v1/language/value/inclusion/types.d.ts +3 -0
  221. package/dist/v1/language/value/inclusion/types.js +34 -0
  222. package/dist/v1/language/value/model/blob.d.ts +6 -0
  223. package/dist/v1/language/value/model/blob.js +8 -0
  224. package/dist/v1/language/value/model/file.d.ts +41 -0
  225. package/dist/v1/language/value/model/file.js +122 -0
  226. package/dist/v1/language/value/ordering.d.ts +14 -0
  227. package/dist/v1/language/value/ordering.js +144 -77
  228. package/dist/v1/language/value/profile/canonicalize.d.ts +6 -1
  229. package/dist/v1/language/value/profile/canonicalize.js +67 -87
  230. package/dist/v1/language/value/profile/json.validate.d.ts +12 -0
  231. package/dist/v1/language/value/profile/json.validate.js +18 -5
  232. package/dist/v1/language/value/profile/meta-schema.compiled.d.ts +1 -0
  233. package/dist/v1/language/value/profile/meta-schema.compiled.js +21 -5
  234. package/dist/v1/language/value/profile/rules.js +27 -44
  235. package/dist/v1/language/value/profile/validate.js +1 -10
  236. package/dist/v1/language/value/profile/vocabulary.d.ts +36 -2
  237. package/dist/v1/language/value/profile/vocabulary.js +58 -5
  238. package/dist/v1/language/value/reference/closure.js +6 -6
  239. package/dist/v1/language/value/reference/recursion.js +9 -48
  240. package/dist/v1/language/value/reference/references.d.ts +3 -1
  241. package/dist/v1/language/value/reference/references.js +7 -7
  242. package/dist/v1/language/value/reference/registry.index.d.ts +2 -0
  243. package/dist/v1/language/value/reference/registry.index.js +33 -16
  244. package/dist/v1/language/value/regexp/ast.js +6 -7
  245. package/dist/v1/language/value/regexp/compile.d.ts +5 -11
  246. package/dist/v1/language/value/regexp/compile.js +14 -12
  247. package/dist/v1/language/value/regexp/syntax.js +3 -2
  248. package/dist/v1/language/value/regexp/unicode.d.ts +1 -1
  249. package/dist/v1/language/value/regexp/unicode.js +1 -1
  250. package/dist/v1/language/value/syntax/keywords.d.ts +3 -3
  251. package/dist/v1/language/value/syntax/keywords.js +4 -20
  252. package/dist/v1/language/value/syntax/node-path/validate.js +2 -3
  253. package/dist/v1/language/value/syntax/pointer.d.ts +2 -0
  254. package/dist/v1/language/value/syntax/pointer.js +5 -2
  255. package/dist/v1/language/value/syntax/walk.d.ts +9 -0
  256. package/dist/v1/language/value/syntax/walk.js +37 -20
  257. package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +2596 -0
  258. package/dist/v1/schema/admission/accept.d.ts +3 -1
  259. package/dist/v1/schema/admission/accept.js +6 -14
  260. package/dist/v1/schema/admission/callable.d.ts +21 -0
  261. package/dist/v1/schema/admission/callable.js +96 -0
  262. package/dist/v1/schema/analysis/class.d.ts +4 -0
  263. package/dist/v1/schema/analysis/class.js +57 -17
  264. package/dist/v1/schema/canonical/revision.d.ts +4 -1
  265. package/dist/v1/schema/canonical/revision.js +8 -5
  266. package/dist/v1/schema/compatibility/api.d.ts +4 -1
  267. package/dist/v1/schema/compatibility/api.js +2 -0
  268. package/dist/v1/schema/compatibility/comparators/callables.js +1 -1
  269. package/dist/v1/schema/compatibility/comparators/classes.d.ts +9 -4
  270. package/dist/v1/schema/compatibility/comparators/classes.js +50 -29
  271. package/dist/v1/schema/compatibility/comparators/index.d.ts +1 -1
  272. package/dist/v1/schema/compatibility/comparators/members.js +1 -1
  273. package/dist/v1/schema/compatibility/comparators/values.js +2 -2
  274. package/dist/v1/schema/compatibility/context.d.ts +5 -2
  275. package/dist/v1/schema/compatibility/context.js +8 -6
  276. package/dist/v1/schema/compatibility/coordinate.js +3 -3
  277. package/dist/v1/schema/compatibility/diff.js +2 -4
  278. package/dist/v1/schema/compatibility/extension.d.ts +11 -0
  279. package/dist/v1/schema/compatibility/extension.js +22 -0
  280. package/dist/v1/schema/compatibility/fields.d.ts +20 -4
  281. package/dist/v1/schema/compatibility/fields.js +13 -3
  282. package/dist/v1/schema/compatibility/meaning/footprint.js +16 -51
  283. package/dist/v1/schema/compatibility/model.d.ts +17 -5
  284. package/dist/v1/schema/compatibility/references.d.ts +0 -3
  285. package/dist/v1/schema/compatibility/references.js +1 -9
  286. package/dist/v1/schema/compatibility/report.js +1 -1
  287. package/dist/v1/schema/compatibility/rule.d.ts +13 -0
  288. package/dist/v1/schema/compatibility/rule.js +23 -0
  289. package/dist/v1/schema/compatibility/scope.d.ts +2 -0
  290. package/dist/v1/schema/compatibility/scope.js +4 -1
  291. package/dist/v1/schema/compatibility/structure/index.js +6 -4
  292. package/dist/v1/schema/compatibility/structure/requirements.js +58 -61
  293. package/dist/v1/schema/compatibility/versioning/index.js +1 -1
  294. package/dist/v1/schema/compatibility/versioning/surface.d.ts +1 -1
  295. package/dist/v1/schema/compatibility/versioning/surface.js +30 -2
  296. package/dist/v1/schema/compatibility/walk.d.ts +17 -0
  297. package/dist/v1/schema/compatibility/walk.js +41 -0
  298. package/dist/v1/schema/diagnostic.d.ts +17 -3
  299. package/dist/v1/schema/diagnostic.js +14 -11
  300. package/dist/v1/schema/enforcement/changes.d.ts +590 -0
  301. package/dist/v1/schema/enforcement/changes.js +566 -0
  302. package/dist/v1/schema/enforcement/derived.d.ts +236 -0
  303. package/dist/v1/schema/enforcement/derived.js +243 -0
  304. package/dist/v1/schema/enforcement/dispose.d.ts +308 -0
  305. package/dist/v1/schema/enforcement/dispose.js +275 -0
  306. package/dist/v1/schema/enforcement/facts.d.ts +89 -0
  307. package/dist/v1/schema/enforcement/facts.js +70 -0
  308. package/dist/v1/schema/enforcement/fields.d.ts +65 -0
  309. package/dist/v1/schema/enforcement/fields.js +36 -0
  310. package/dist/v1/schema/enforcement/index.d.ts +39 -0
  311. package/dist/v1/schema/enforcement/index.js +10 -0
  312. package/dist/v1/schema/enforcement/install.d.ts +1634 -0
  313. package/dist/v1/schema/enforcement/install.js +1223 -0
  314. package/dist/v1/schema/enforcement/lifecycle.d.ts +87 -0
  315. package/dist/v1/schema/enforcement/lifecycle.js +91 -0
  316. package/dist/v1/schema/enforcement/model.d.ts +253 -0
  317. package/dist/v1/schema/enforcement/model.js +1 -0
  318. package/dist/v1/schema/enforcement/obligations.d.ts +248 -0
  319. package/dist/v1/schema/enforcement/obligations.js +240 -0
  320. package/dist/v1/schema/enforcement/write.d.ts +1314 -0
  321. package/dist/v1/schema/enforcement/write.js +1017 -0
  322. package/dist/v1/schema/index.d.ts +11 -1
  323. package/dist/v1/schema/index.js +5 -0
  324. package/dist/v1/schema/model/schema.d.ts +23 -1
  325. package/dist/v1/schema/model/schema.js +1 -1
  326. package/dist/v1/schema/normalization/domain.d.ts +2 -0
  327. package/dist/v1/schema/normalization/domain.js +50 -13
  328. package/dist/v1/schema/resolution/closure.js +2 -1
  329. package/dist/v1/schema/resolution/context.js +17 -18
  330. package/dist/v1/schema/resolution/domain.d.ts +5 -0
  331. package/dist/v1/schema/resolution/domain.js +5 -13
  332. package/dist/v1/schema/resolution/origins.js +6 -8
  333. package/dist/v1/schema/rule.d.ts +25 -0
  334. package/dist/v1/schema/rule.js +459 -0
  335. package/dist/v1/schema/validation/callable.d.ts +35 -2
  336. package/dist/v1/schema/validation/callable.js +65 -9
  337. package/dist/v1/schema/validation/class.d.ts +6 -2
  338. package/dist/v1/schema/validation/class.js +128 -105
  339. package/dist/v1/schema/validation/core.js +103 -173
  340. package/dist/v1/schema/validation/domain.js +25 -15
  341. package/dist/v1/schema/validation/domain.json-schema.d.ts +15 -0
  342. package/dist/v1/schema/validation/domain.json-schema.js +222 -0
  343. package/dist/v1/schema/validation/domain.route.d.ts +6 -1
  344. package/dist/v1/schema/validation/domain.route.js +18 -0
  345. package/dist/v1/schema/validation/domain.structure.d.ts +7797 -0
  346. package/dist/v1/schema/validation/domain.structure.js +516 -160
  347. package/dist/v1/schema/validation/icon.d.ts +4 -0
  348. package/dist/v1/schema/validation/icon.js +29 -0
  349. package/dist/v1/schema/validation/json.json-schema.d.ts +40 -0
  350. package/dist/v1/schema/validation/json.json-schema.js +46 -0
  351. package/dist/v1/schema/validation/policy/budgets.d.ts +37 -2
  352. package/dist/v1/schema/validation/policy/budgets.js +94 -121
  353. package/dist/v1/schema/validation/policy/context.d.ts +6 -5
  354. package/dist/v1/schema/validation/policy/context.js +7 -10
  355. package/dist/v1/schema/validation/policy/objects.d.ts +1 -1
  356. package/dist/v1/schema/validation/policy/objects.js +6 -14
  357. package/dist/v1/schema/validation/policy/references.js +20 -62
  358. package/dist/v1/schema/validation/policy/typing.d.ts +3 -18
  359. package/dist/v1/schema/validation/policy/typing.js +22 -356
  360. package/dist/v1/schema/validation/policy/uses.d.ts +40 -3
  361. package/dist/v1/schema/validation/policy/uses.js +63 -91
  362. package/dist/v1/schema/validation/policy/validate.js +5 -5
  363. package/dist/v1/schema/validation/value-api.d.ts +27 -1
  364. package/dist/v1/schema/validation/value-api.js +37 -2
  365. package/dist/v1/schema/validation/value.d.ts +3 -0
  366. package/dist/v1/schema/validation/value.js +9 -17
  367. package/dist/v1/schema/validation/value.json-schema.d.ts +54 -0
  368. package/dist/v1/schema/validation/value.json-schema.js +163 -0
  369. package/dist/v1/schema/validation/view.js +4 -8
  370. package/dist/value/accept.d.ts +9 -3
  371. package/dist/value/accept.js +25 -1
  372. package/dist/value/canonical.d.ts +22 -1
  373. package/dist/value/canonical.js +114 -21
  374. package/dist/value/decode.d.ts +7 -0
  375. package/dist/value/decode.js +159 -9
  376. package/dist/value/equal.d.ts +9 -1
  377. package/dist/value/equal.js +37 -3
  378. package/dist/value/immutable.optimization.d.ts +2 -0
  379. package/dist/value/immutable.optimization.js +4 -0
  380. package/dist/value/index.d.ts +5 -3
  381. package/dist/value/index.js +2 -1
  382. package/dist/value/json.d.ts +2 -2
  383. package/dist/value/json.js +2 -2
  384. package/dist/value/limits.d.ts +11 -0
  385. package/dist/value/rule.d.ts +12 -0
  386. package/dist/value/rule.js +50 -0
  387. package/dist/value/types.d.ts +6 -0
  388. package/dist/value/unicode.d.ts +2 -1
  389. package/dist/value/unicode.js +2 -0
  390. package/package.json +15 -4
  391. package/dist/v1/builder/lowering/core-properties.d.ts +0 -10
  392. package/dist/v1/builder/lowering/core-properties.js +0 -76
  393. package/dist/v1/compiled/admission/semantics/cardinality.d.ts +0 -5
  394. package/dist/v1/compiled/admission/semantics/cardinality.js +0 -113
  395. package/dist/v1/compiled/admission/semantics/policy/equality.d.ts +0 -8
  396. package/dist/v1/compiled/admission/semantics/policy/equality.js +0 -27
  397. package/dist/v1/compiled/admission/semantics/policy/measure.d.ts +0 -9
  398. package/dist/v1/compiled/admission/semantics/policy/measure.js +0 -81
  399. package/dist/v1/compiled/admission/semantics/policy/variants.d.ts +0 -10
  400. package/dist/v1/compiled/admission/semantics/policy/variants.js +0 -65
  401. package/dist/v1/compiled/admission/wire/pattern.d.ts +0 -12
  402. package/dist/v1/compiled/admission/wire/pattern.js +0 -111
  403. package/dist/v1/language/class/index.d.ts +0 -8
  404. package/dist/v1/language/class/index.js +0 -1
  405. package/dist/v1/language/core/index.d.ts +0 -2
  406. package/dist/v1/language/value/index.d.ts +0 -11
  407. package/dist/v1/language/value/index.js +0 -8
  408. package/dist/v1/schema/canonical/domain.d.ts +0 -3
  409. package/dist/v1/schema/canonical/domain.digest.d.ts +0 -3
  410. package/dist/v1/schema/canonical/domain.digest.js +0 -5
  411. package/dist/v1/schema/canonical/domain.js +0 -5
  412. package/dist/v1/schema/canonical/freeze.d.ts +0 -1
  413. /package/dist/v1/{language/core/index.js → builder/class/input.js} +0 -0
@@ -1,26 +1,44 @@
1
+ import { equalDefinitionRefs } from '../../addressing/definition-ref.js';
1
2
  import { Key } from '../../addressing/key.js';
2
3
  import { compareUnicode, definitionRefIndex } from '../../addressing/ordering.js';
3
4
  import { isMethodExecutable } from '../../language/callable/executable.js';
5
+ import { coveringEdgeUniqueTuples, coveringNodeUniqueTuples, edgeUniqueKeys, nodeUniqueKeys, } from '../../language/class/unique.js';
6
+ import { checkCoreEdgeSet, checkHeldKeys, coreEndpointsSatisfy, DOMAIN_ENDPOINT_CLASS, } from '../../language/core/facts.js';
4
7
  import { policyObjectKey, policyObjectOrigin, projectedMemberClass, } from '../../language/policy/model/policy.js';
5
8
  import { validateJsonInstance } from '../../language/value/evaluate/validate.js';
6
- import { diagnostic } from '../diagnostic.js';
9
+ import { appendPointer, escapePointerToken } from '../../language/value/syntax/pointer.js';
10
+ import { diagnostic, valueDiagnostic } from '../diagnostic.js';
7
11
  import { classSatisfies } from './class.js';
8
12
  const formatDefinitionRef = Key.of;
9
13
  export function validateCore(environment, analysis, registry) {
10
14
  const diagnostics = [];
11
15
  const nodesByRef = resolveCoreNodes(environment, analysis, registry, diagnostics);
12
16
  const edges = resolveCoreEdges(environment, analysis, registry, nodesByRef, diagnostics);
17
+ validateCoreNodeKeys(environment, nodesByRef, diagnostics);
13
18
  validateCoreEdgeSet(environment, edges, nodesByRef, diagnostics);
14
19
  return Object.freeze(diagnostics);
15
20
  }
21
+ /** No two Core Nodes hold one key under a tuple covering their Classes, whichever declares it. */
22
+ function validateCoreNodeKeys(environment, nodesByRef, diagnostics) {
23
+ const resolve = (ref) => environment.resolveAny(ref)?.declaration;
24
+ checkHeldKeys(nodesByRef.values(), (node) => {
25
+ const declaration = resolve(node.classRef);
26
+ if (declaration === undefined)
27
+ return [];
28
+ return nodeUniqueKeys(coveringNodeUniqueTuples(declaration, resolve), {
29
+ props: environment.candidate.core.nodes[node.slug].properties,
30
+ });
31
+ }, (node, previous) => diagnostics.push(diagnostic('DV_CORE_NODE_UNIQUE', nodePointer(node), `Core Node holds a key the Core Node at ${nodePointer(previous)} holds.`)));
32
+ }
33
+ function nodePointer(node) {
34
+ return `/core/nodes/${escapePointerToken(node.slug)}`;
35
+ }
16
36
  function resolveCoreNodes(environment, analysis, registry, diagnostics) {
17
37
  const nodes = new Map();
18
38
  for (const [slug, node] of Object.entries(environment.candidate.core.nodes)) {
19
- const pointer = `/core/nodes/${escapePointer(slug)}`;
39
+ const pointer = `/core/nodes/${escapePointerToken(slug)}`;
20
40
  const ref = { origin: environment.candidate.origin, kind: 'core', name: slug };
21
- if (node.ref.origin !== ref.origin ||
22
- node.ref.kind !== ref.kind ||
23
- node.ref.name !== ref.name) {
41
+ if (!equalDefinitionRefs(node.ref, ref)) {
24
42
  diagnostics.push(diagnostic('DV_REF_RESOLVES', `${pointer}/ref`, `Core ref must be exactly ${formatDefinitionRef(ref)}.`, formatDefinitionRef(node.ref)));
25
43
  }
26
44
  const resolved = environment.resolve(node.class);
@@ -63,15 +81,11 @@ function resolveCoreEdges(environment, analysis, registry, nodesByRef, diagnosti
63
81
  const declaration = resolved.declaration;
64
82
  if (source === undefined || target === undefined)
65
83
  continue;
66
- const endpointsSatisfy = declaration.orientation === 'directed'
67
- ? endpointSatisfies(environment, source, declaration.endpoints.source.accepts) &&
68
- endpointSatisfies(environment, target, declaration.endpoints.target.accepts)
69
- : (endpointSatisfies(environment, source, declaration.endpoints[0].accepts) &&
70
- endpointSatisfies(environment, target, declaration.endpoints[1].accepts)) ||
71
- (endpointSatisfies(environment, source, declaration.endpoints[1].accepts) &&
72
- endpointSatisfies(environment, target, declaration.endpoints[0].accepts));
84
+ const endpointsSatisfy = coreEndpointsSatisfy(declaration, source, target, (endpoint, accepts) => endpointSatisfies(environment, endpoint, accepts));
73
85
  if (!endpointsSatisfy) {
74
- diagnostics.push(diagnostic('DV_CORE_EDGE_CLASS', pointer, `Core Edge endpoints do not satisfy ${formatDefinitionRef(edge.class)}.`, formatDefinitionRef(edge.class)));
86
+ diagnostics.push(diagnostic('DV_CORE_EDGE_CLASS', pointer, `Core Edge endpoints do not satisfy ${formatDefinitionRef(edge.class)}.${source.kind === 'domain' || target.kind === 'domain'
87
+ ? ` The owning Domain is a ${formatDefinitionRef(DOMAIN_ENDPOINT_CLASS)} Node: the endpoint that names it must accept that Class or one it extends.`
88
+ : ''}`, formatDefinitionRef(edge.class)));
75
89
  continue;
76
90
  }
77
91
  edges.push({ source, target, declaration, value: edge, pointer });
@@ -80,7 +94,7 @@ function resolveCoreEdges(environment, analysis, registry, nodesByRef, diagnosti
80
94
  }
81
95
  function resolveCoreEndpoint(environment, ref, pointer, nodesByRef, diagnostics) {
82
96
  if (ref.kind === 'domain')
83
- return { kind: 'domain', ref, key: 'domain' };
97
+ return { kind: 'domain', ref, key: 'domain', classRef: DOMAIN_ENDPOINT_CLASS };
84
98
  const undeclared = () => {
85
99
  const key = policyObjectKey(ref);
86
100
  diagnostics.push(diagnostic('DV_CORE_REF', pointer, `Core endpoint ${key} does not name a declared local Definition.`, key));
@@ -110,183 +124,99 @@ function declaresProjectedMember(environment, ref) {
110
124
  return Object.hasOwn(candidate.policies, ref.name);
111
125
  return Object.hasOwn(candidate.views, ref.name);
112
126
  }
127
+ /**
128
+ * A Core Node is admitted by its own authored Class, a projected member by the Kernel declaration
129
+ * Class it projects as, and the owning Domain by the Kernel `Domain` Class of its Node: the write
130
+ * that projects the Edge binds exactly that Node, so an Edge Class that does not accept it can
131
+ * never be installed (DV-CORE-EDGE-CLASS).
132
+ */
113
133
  function endpointSatisfies(environment, endpoint, accepts) {
114
- // The owning Domain is a graph-projection identity, not a Definition declared by this DSL.
115
- // Its concrete Class contract is therefore admitted by the projection compiler.
116
- return endpoint.kind === 'domain' || classSatisfies(environment, endpoint.classRef, accepts);
134
+ return classSatisfies(environment, endpoint.classRef, accepts);
117
135
  }
118
136
  function validateCreationProperties(definition, properties, registry, code, pointer, diagnostics) {
119
- const schema = {
137
+ const fields = [...definition.properties].filter(([, field]) => field.auto === undefined);
138
+ // Which Properties the fact holds is judged apart from their values: a Property's schema is the
139
+ // root of its own local references, here as at a write, so it is never nested in another schema.
140
+ const held = {
120
141
  type: 'object',
121
- properties: Object.fromEntries([...definition.properties]
122
- .filter(([, field]) => field.auto === undefined)
123
- .map(([name, field]) => [name, field.schema])),
124
- required: [...definition.properties]
125
- .filter(([, field]) => field.required && field.auto === undefined)
142
+ properties: Object.fromEntries(fields.map(([name]) => [name, true])),
143
+ required: fields
144
+ .filter(([, field]) => field.required)
126
145
  .map(([name]) => name)
127
146
  .sort(compareUnicode),
128
147
  additionalProperties: false,
129
148
  };
130
- for (const failure of validateJsonInstance(schema, properties, registry, pointer)) {
131
- diagnostics.push(diagnostic(code, failure.pointer, failure.message, failure.ref));
132
- }
133
- }
134
- function validateCoreEdgeSet(environment, edges, nodesByRef, diagnostics) {
135
- const seen = new Map();
136
- const edgeSlices = new Map();
137
- for (const [name, candidate] of Object.entries(environment.candidate.classes)) {
138
- if (candidate.kind !== 'edge')
149
+ const refusals = validateJsonInstance(held, properties, registry, pointer);
150
+ for (const [name, field] of fields) {
151
+ if (!Object.hasOwn(properties, name))
139
152
  continue;
140
- const ref = {
141
- origin: environment.candidate.origin,
142
- kind: 'class',
143
- name,
144
- };
145
- const resolved = environment.resolve(ref);
146
- if (resolved === undefined || resolved.ref.kind !== 'class' || resolved.kind !== 'edge') {
147
- continue;
148
- }
149
- edgeSlices.set(definitionRefIndex(ref), {
150
- declaration: resolved.declaration,
151
- edges: [],
152
- });
153
+ const at = appendPointer(pointer, name);
154
+ refusals.push(...validateJsonInstance(field.schema, properties[name], registry, at));
153
155
  }
154
- for (const edge of edges) {
155
- const classKey = definitionRefIndex(edge.value.class);
156
- const [source, target] = edge.declaration.orientation === 'undirected' &&
157
- compareUnicode(edge.source.key, edge.target.key) > 0
158
- ? [edge.target.key, edge.source.key]
159
- : [edge.source.key, edge.target.key];
160
- const key = `${classKey}\u0000${source}\u0000${target}`;
161
- const previous = seen.get(key);
162
- if (previous !== undefined) {
163
- diagnostics.push(diagnostic('DV_CORE_EDGE_KEY', edge.pointer, `Core Edge duplicates the normalized EdgeKey declared at ${previous}.`));
164
- }
165
- else {
166
- seen.set(key, edge.pointer);
167
- }
168
- const slice = edgeSlices.get(classKey) ?? {
169
- declaration: edge.declaration,
170
- edges: [],
171
- };
172
- slice.edges.push(edge);
173
- edgeSlices.set(classKey, slice);
174
- if (edge.declaration.constraints.noSelf === true && edge.source.key === edge.target.key) {
175
- diagnostics.push(diagnostic('DV_CORE_EDGE_CONSTRAINTS', edge.pointer, 'Core Edge violates noSelf.'));
176
- }
177
- }
178
- for (const { declaration, edges: classEdges } of edgeSlices.values()) {
179
- if (declaration.constraints.acyclic === true && hasDirectedCycle(classEdges)) {
180
- diagnostics.push(diagnostic('DV_CORE_EDGE_CONSTRAINTS', '/core/edges', 'Core Edge set violates exact-Class acyclicity.'));
181
- }
182
- validateCardinality(environment, declaration, classEdges, nodesByRef, diagnostics);
156
+ for (const refusal of refusals) {
157
+ diagnostics.push(valueDiagnostic(code, refusal));
183
158
  }
184
159
  }
185
- function validateCardinality(environment, declaration, edges, nodesByRef, diagnostics) {
186
- const subjects = cardinalitySubjects(edges, nodesByRef);
187
- if (declaration.orientation === 'undirected') {
188
- const [first, second] = declaration.endpoints;
189
- for (const subject of subjects) {
190
- const matchesFirst = classSatisfies(environment, subject.classRef, first.accepts);
191
- const matchesSecond = classSatisfies(environment, subject.classRef, second.accepts);
192
- if (!matchesFirst && !matchesSecond)
193
- continue;
194
- const degree = edges.filter((edge) => edge.source.key === subject.key || edge.target.key === subject.key).length;
195
- if (matchesFirst)
196
- checkBound(first, first.incident, degree, subject, diagnostics);
197
- if (matchesSecond && !sameIncidentEndpointContract(first, second)) {
198
- checkBound(second, second.incident, degree, subject, diagnostics);
160
+ function validateCoreEdgeSet(environment, edges, nodesByRef, diagnostics) {
161
+ const { candidate } = environment;
162
+ const resolve = (ref) => environment.resolveAny(ref)?.declaration;
163
+ checkCoreEdgeSet({
164
+ edges: edges.map((edge) => ({
165
+ edge,
166
+ class: definitionRefIndex(edge.value.class),
167
+ contract: edge.declaration,
168
+ source: factEndpoint(edge.source, edge.pointer),
169
+ target: factEndpoint(edge.target, edge.pointer),
170
+ })),
171
+ classes: Object.entries(candidate.classes).flatMap(([name, declaration]) => {
172
+ if (declaration.kind !== 'edge')
173
+ return [];
174
+ const ref = { origin: candidate.origin, kind: 'class', name };
175
+ const resolved = environment.resolve(ref);
176
+ if (resolved === undefined || resolved.ref.kind !== 'class' || resolved.kind !== 'edge') {
177
+ return [];
199
178
  }
200
- }
201
- return;
202
- }
203
- for (const subject of subjects) {
204
- if (classSatisfies(environment, subject.classRef, declaration.endpoints.source.accepts)) {
205
- const degree = edges.filter((edge) => edge.source.key === subject.key).length;
206
- checkBound(declaration.endpoints.source, declaration.endpoints.source.outgoing, degree, subject, diagnostics);
207
- }
208
- if (classSatisfies(environment, subject.classRef, declaration.endpoints.target.accepts)) {
209
- const degree = edges.filter((edge) => edge.target.key === subject.key).length;
210
- checkBound(declaration.endpoints.target, declaration.endpoints.target.incoming, degree, subject, diagnostics);
211
- }
212
- }
213
- }
214
- /**
215
- * Every declared Core Node proves its own complete degree, so both bounds hold. A Definition
216
- * endpoint is only named by the Edges that reach it: the Domain may also create ordinary Edges of
217
- * the same Class against it, so a minimum is unprovable here and only the maximum is enforced.
218
- */
219
- function cardinalitySubjects(edges, nodesByRef) {
220
- const subjects = new Map();
221
- for (const node of nodesByRef.values()) {
222
- subjects.set(node.key, {
179
+ return [
180
+ { key: definitionRefIndex(ref), contract: resolved.declaration },
181
+ ];
182
+ }),
183
+ nodes: [...nodesByRef.values()].map((node) => ({
223
184
  key: node.key,
224
- classRef: node.classRef,
225
- pointer: `/core/nodes/${escapePointer(node.slug)}`,
226
- minimum: true,
227
- });
228
- }
229
- for (const edge of edges) {
230
- for (const endpoint of [edge.source, edge.target]) {
231
- if (endpoint.kind !== 'member' || subjects.has(endpoint.key))
232
- continue;
233
- subjects.set(endpoint.key, {
234
- key: endpoint.key,
235
- classRef: endpoint.classRef,
236
- pointer: edge.pointer,
237
- minimum: false,
238
- });
239
- }
240
- }
241
- return Object.freeze([...subjects.values()]);
185
+ class: node.classRef,
186
+ pointer: nodePointer(node),
187
+ })),
188
+ satisfies: (ref, accepts) => classSatisfies(environment, ref, accepts),
189
+ keys: ({ edge }) => edgeUniqueKeys(coveringEdgeUniqueTuples(edge.declaration, resolve), {
190
+ source: edge.source.key,
191
+ target: edge.target.key,
192
+ props: edge.value.properties,
193
+ }),
194
+ sameIncident: sameIncidentEndpointContract,
195
+ report: (issue) => diagnostics.push(coreEdgeDiagnostic(issue)),
196
+ });
197
+ }
198
+ /** A projected member's degree, and the owning Domain's, is reported at the Edge that names it. */
199
+ function factEndpoint(endpoint, pointer) {
200
+ return endpoint.kind === 'core'
201
+ ? endpoint
202
+ : { key: endpoint.key, member: { class: endpoint.classRef, pointer } };
242
203
  }
243
- function checkBound(endpoint, count, degree, subject, diagnostics) {
244
- const [minimum, maximum] = countBounds(count);
245
- if (degree <= maximum && (degree >= minimum || !subject.minimum))
246
- return;
247
- diagnostics.push(diagnostic('DV_CORE_EDGE_CONSTRAINTS', subject.pointer, `Core degree ${degree} violates ${endpoint.role} Edge count ${count}.`));
204
+ function coreEdgeDiagnostic(issue) {
205
+ switch (issue.kind) {
206
+ case 'identity':
207
+ return diagnostic('DV_CORE_EDGE_KEY', issue.edge.pointer, `Core Edge duplicates the normalized EdgeKey declared at ${issue.previous.pointer}.`);
208
+ case 'no-self':
209
+ return diagnostic('DV_CORE_EDGE_CONSTRAINTS', issue.edge.pointer, 'Core Edge violates noSelf.');
210
+ case 'key':
211
+ return diagnostic('DV_CORE_EDGE_UNIQUE', issue.edge.pointer, `Core Edge holds a key the Core Edge at ${issue.previous.pointer} holds.`);
212
+ case 'acyclic':
213
+ return diagnostic('DV_CORE_EDGE_CONSTRAINTS', '/core/edges', 'Core Edge set violates exact-Class acyclicity.');
214
+ case 'degree':
215
+ return diagnostic('DV_CORE_EDGE_CONSTRAINTS', issue.pointer, `Core degree ${issue.degree} violates ${issue.endpoint.role} Edge count ${issue.count}.`);
216
+ }
248
217
  }
249
218
  function sameIncidentEndpointContract(left, right) {
250
219
  return (left.incident === right.incident &&
251
220
  left.accepts.length === right.accepts.length &&
252
221
  left.accepts.every((ref, index) => definitionRefIndex(ref) === definitionRefIndex(right.accepts[index])));
253
222
  }
254
- function countBounds(value) {
255
- switch (value) {
256
- case '0..*':
257
- return [0, Number.POSITIVE_INFINITY];
258
- case '1..*':
259
- return [1, Number.POSITIVE_INFINITY];
260
- case '0..1':
261
- return [0, 1];
262
- case '1':
263
- return [1, 1];
264
- }
265
- }
266
- function hasDirectedCycle(edges) {
267
- const outgoing = new Map();
268
- for (const edge of edges) {
269
- const targets = outgoing.get(edge.source.key) ?? [];
270
- targets.push(edge.target.key);
271
- outgoing.set(edge.source.key, targets);
272
- }
273
- const visiting = new Set();
274
- const visited = new Set();
275
- const visit = (key) => {
276
- if (visiting.has(key))
277
- return true;
278
- if (visited.has(key))
279
- return false;
280
- visiting.add(key);
281
- for (const target of outgoing.get(key) ?? [])
282
- if (visit(target))
283
- return true;
284
- visiting.delete(key);
285
- visited.add(key);
286
- return false;
287
- };
288
- return [...outgoing.keys()].some(visit);
289
- }
290
- function escapePointer(value) {
291
- return value.replaceAll('~', '~0').replaceAll('/', '~1');
292
- }
@@ -1,25 +1,44 @@
1
- import { compareUnicode } from '../../addressing/ordering.js';
1
+ import { orderAndDeduplicate } from '../../language/validation/diagnostic.js';
2
2
  import { analyzeDefinitions } from '../analysis/class.js';
3
3
  import { buildDomainResolutionContext } from '../resolution/context.js';
4
4
  import { createValueSchemaRegistry } from '../resolution/value.registry.js';
5
- import { validateCallables } from './callable.js';
5
+ import { validateContracts } from './callable.js';
6
6
  import { validateDefinitions } from './class.js';
7
7
  import { validateCore } from './core.js';
8
+ import { validateDomainIcon } from './icon.js';
8
9
  import { validatePolicies } from './policy/validate.js';
9
10
  import { validateEmbeddedValueSchemas } from './value.js';
10
11
  import { validateViews } from './view.js';
11
12
  export function validateDomainSchemaSemantics(schema, lookup) {
12
13
  const context = buildDomainResolutionContext(schema, lookup);
13
14
  const analysis = analyzeDefinitions(context);
15
+ // Past the inheritance limit no Class is composed, and the rules below read the composition.
16
+ if (analysis.diagnostics.some(({ code }) => code === 'DV_INHERITANCE_LIMITS')) {
17
+ return Object.freeze({
18
+ context,
19
+ analysis,
20
+ diagnostics: Object.freeze(orderAndDeduplicate([...context.diagnostics, ...analysis.diagnostics])),
21
+ });
22
+ }
14
23
  const registry = createValueSchemaRegistry(context);
24
+ const valueRefusals = validateEmbeddedValueSchemas(schema, registry);
25
+ // The Class and Core rules read every Property value schema as admitted. A reference with no
26
+ // target is the one refusal they can read, and it may only mean a dependency this context lacks.
27
+ const readable = valueRefusals.every(({ valueCode }) => valueCode === 'VS_REFERENCE_RESOLUTION');
15
28
  const diagnostics = [
16
29
  ...context.diagnostics,
17
- ...validateEmbeddedValueSchemas(schema, registry),
18
- ...validateDefinitions(context, analysis),
19
- ...validateCallables(schema),
30
+ ...analysis.diagnostics,
31
+ ...valueRefusals,
32
+ ...validateContracts(schema, registry),
20
33
  ...validatePolicies(context, analysis),
21
34
  ...validateViews(context),
22
- ...validateCore(context, analysis, registry),
35
+ ...validateDomainIcon(schema),
36
+ ...(readable
37
+ ? [
38
+ ...validateDefinitions(context, analysis, registry),
39
+ ...validateCore(context, analysis, registry),
40
+ ]
41
+ : []),
23
42
  ];
24
43
  return Object.freeze({
25
44
  context,
@@ -27,12 +46,3 @@ export function validateDomainSchemaSemantics(schema, lookup) {
27
46
  diagnostics: Object.freeze(orderAndDeduplicate(diagnostics)),
28
47
  });
29
48
  }
30
- function orderAndDeduplicate(diagnostics) {
31
- const unique = new Map();
32
- for (const value of diagnostics) {
33
- unique.set(`${value.pointer}\u0000${value.code}\u0000${value.ref ?? ''}\u0000${value.message}`, value);
34
- }
35
- return [...unique.values()].sort((left, right) => compareUnicode(left.pointer, right.pointer) ||
36
- compareUnicode(left.code, right.code) ||
37
- compareUnicode(left.message, right.message));
38
- }
@@ -0,0 +1,15 @@
1
+ import { type core as zodCore } from 'zod';
2
+ import { type JsonSchema } from './json.json-schema.js';
3
+ /**
4
+ * The JSON Schema of an authored Domain schema document, rendered from the structure the Kernel
5
+ * enforces. Zod derives what it reads; `documentJsonSchema` states each refinement it cannot read,
6
+ * or names the rule JSON Schema cannot state. A refinement neither stated nor named fails the
7
+ * rendering, so that no check of the structure is dropped silently. Every value schema is in the
8
+ * published dialect and states the profile rules JSON Schema can state; the others are named.
9
+ */
10
+ export declare function domainSchemaJsonSchema(): JsonSchema;
11
+ /**
12
+ * Every refinement and custom part of the structure carries its statement in `documentJsonSchema`:
13
+ * the keywords that state it, or its named rule. Only parts zod renders take part.
14
+ */
15
+ export declare function assertChecksStated(schema: zodCore.$ZodType, visited?: Set<zodCore.$ZodType<unknown, unknown, zodCore.$ZodTypeInternals<unknown, unknown>>>): void;
@@ -0,0 +1,222 @@
1
+ import { toJSONSchema } from 'zod';
2
+ import { VALUE_RULES } from '../../language/validation/rule.js';
3
+ import { escapePointerToken } from '../../language/value/syntax/pointer.js';
4
+ import { RULES } from '../rule.js';
5
+ import { domainSchemaStructure, documentJsonSchema, structureRules, VARIANTS, } from './domain.structure.js';
6
+ import { jsonValueJsonSchema, jsonValueRules, } from './json.json-schema.js';
7
+ import { valueSchemaJsonSchema, valueSchemaRules, } from './value.json-schema.js';
8
+ /** The checks the published document names, each with its stage and the positions it constrains. */
9
+ const namedRules = {
10
+ ...structureRules,
11
+ ...jsonValueRules,
12
+ ...valueSchemaRules,
13
+ };
14
+ /**
15
+ * The JSON Schema of an authored Domain schema document, rendered from the structure the Kernel
16
+ * enforces. Zod derives what it reads; `documentJsonSchema` states each refinement it cannot read,
17
+ * or names the rule JSON Schema cannot state. A refinement neither stated nor named fails the
18
+ * rendering, so that no check of the structure is dropped silently. Every value schema is in the
19
+ * published dialect and states the profile rules JSON Schema can state; the others are named.
20
+ */
21
+ export function domainSchemaJsonSchema() {
22
+ assertChecksStated(domainSchemaStructure);
23
+ const { $schema, $defs = {}, ...root } = toJSONSchema(domainSchemaStructure, {
24
+ metadata: documentJsonSchema,
25
+ io: 'input',
26
+ // Every opaque part is stated or named, as `assertChecksStated` proved.
27
+ unrepresentable: 'any',
28
+ override: ({ zodSchema, jsonSchema: rendered }) => {
29
+ // Zod states the items of a tuple but not its length.
30
+ const def = zodSchema._zod.def;
31
+ if (def.type !== 'tuple')
32
+ return;
33
+ if (def.rest !== null || def.items.some((item) => item._zod.optin === 'optional')) {
34
+ throw new Error('A tuple of the structure has a fixed length.');
35
+ }
36
+ rendered.minItems = def.items.length;
37
+ rendered.maxItems = def.items.length;
38
+ },
39
+ });
40
+ stateVariantsByAnyOf(root);
41
+ stateVariantsByAnyOf($defs);
42
+ const unnamed = Object.keys($defs).filter((name) => name.startsWith('__schema'));
43
+ if (unnamed.length > 0) {
44
+ throw new Error(`Every shared part of the structure is named: ${unnamed.join(', ')} is not.`);
45
+ }
46
+ const json = jsonValueJsonSchema();
47
+ const values = valueSchemaJsonSchema();
48
+ const valueSchema = $defs['value-schema'];
49
+ const nodeProperty = $defs['node-property-definition'];
50
+ if (root.allOf !== undefined ||
51
+ valueSchema === undefined ||
52
+ nodeProperty === undefined ||
53
+ valueSchema.allOf !== undefined ||
54
+ nodeProperty.allOf !== undefined ||
55
+ [...Object.keys(json.definitions), ...Object.keys(values.definitions)].some((name) => name in $defs)) {
56
+ throw new Error('Portable JSON extends the root, and the value language the value-schema and Node Property definitions.');
57
+ }
58
+ const definitions = Object.fromEntries(Object.entries({
59
+ ...$defs,
60
+ 'value-schema': { ...valueSchema, allOf: [...values.root] },
61
+ 'node-property-definition': { ...nodeProperty, allOf: [values.nodeProperty] },
62
+ ...json.definitions,
63
+ ...values.definitions,
64
+ }).sort(byName));
65
+ const document = { ...root, allOf: [json.root] };
66
+ const positions = rulePositions({ ...document, $defs: definitions });
67
+ return {
68
+ $schema,
69
+ $id: 'https://schemas.astrale.ai/dsl/v1/domain-schema',
70
+ title: 'V1 DomainSchema',
71
+ $comment: 'Generated from the structure the Kernel enforces; value schemas are in the dialect https://schemas.astrale.ai/dsl/v1/value-schema. Each check JSON Schema cannot state is named under x-astrale-rules, with its stage and the positions it constrains.',
72
+ 'x-astrale-rules': Object.fromEntries(Object.entries(namedRules)
73
+ .sort(byName)
74
+ .map(([name, { statement, ...rule }]) => {
75
+ const named = { ...rule, stage: stageOf(rule), statement };
76
+ return [name, { ...named, positions: positions.get(name) ?? [] }];
77
+ })),
78
+ ...document,
79
+ $defs: definitions,
80
+ };
81
+ }
82
+ /**
83
+ * What a named rule reads, in the stages of `schema.RULES`: its code's, or for a value code the
84
+ * value rule's own, which reads the document alone unless it reads the context.
85
+ */
86
+ function stageOf(rule) {
87
+ if (rule.valueCode === undefined)
88
+ return RULES[rule.code].stage;
89
+ return VALUE_RULES[rule.valueCode].stage === 'context' ? 'context' : 'rule';
90
+ }
91
+ /**
92
+ * Every refinement and custom part of the structure carries its statement in `documentJsonSchema`:
93
+ * the keywords that state it, or its named rule. Only parts zod renders take part.
94
+ */
95
+ export function assertChecksStated(schema, visited = new Set()) {
96
+ if (visited.has(schema))
97
+ return;
98
+ visited.add(schema);
99
+ const part = schema;
100
+ const def = part._zod.def;
101
+ for (const check of def.checks ?? []) {
102
+ if (check._zod.def.check === 'custom' && !isStated(schema, check)) {
103
+ throw new Error('A refinement of the structure is neither stated nor named.');
104
+ }
105
+ }
106
+ switch (def.type) {
107
+ case 'boolean':
108
+ case 'enum':
109
+ case 'literal':
110
+ case 'null':
111
+ case 'number':
112
+ case 'string':
113
+ return;
114
+ case 'custom':
115
+ if (statementOf(schema) === undefined) {
116
+ throw new Error('A custom part of the structure is neither stated nor named.');
117
+ }
118
+ return;
119
+ case 'array':
120
+ return assertChecksStated(def.element, visited);
121
+ case 'lazy':
122
+ return assertChecksStated(part._zod.innerType, visited);
123
+ case 'object':
124
+ for (const field of Object.values(def.shape))
125
+ assertChecksStated(field, visited);
126
+ return;
127
+ case 'optional':
128
+ return assertChecksStated(def.innerType, visited);
129
+ case 'record':
130
+ assertChecksStated(def.keyType, visited);
131
+ return assertChecksStated(def.valueType, visited);
132
+ case 'tuple':
133
+ for (const item of def.items)
134
+ assertChecksStated(item, visited);
135
+ return;
136
+ case 'union':
137
+ for (const option of def.options)
138
+ assertChecksStated(option, visited);
139
+ return;
140
+ default:
141
+ throw new Error(`The structure has a ${def.type} part, which this rendering does not read.`);
142
+ }
143
+ }
144
+ /** A check is stated where it was added, or on a refinement of that schema. */
145
+ function isStated(schema, check) {
146
+ for (let current = schema; current !== undefined;) {
147
+ if (statementOf(current) !== undefined)
148
+ return true;
149
+ const parent = current._zod.parent;
150
+ if (parent?._zod.def.checks?.includes(check) !== true)
151
+ return false;
152
+ current = parent;
153
+ }
154
+ return false;
155
+ }
156
+ /** The keywords or rule registered on this very schema, which `get` would inherit from a parent. */
157
+ function statementOf(schema) {
158
+ const { id: _id, description: _description, [VARIANTS]: _variants, ...statement } = documentJsonSchema._map.get(schema) ?? {};
159
+ return Object.keys(statement).length > 0 ? statement : undefined;
160
+ }
161
+ /**
162
+ * Zod renders an exclusive union by `oneOf`. The structure's `variants` are exclusive only for their
163
+ * diagnostics: they never overlap, so the document states them by `anyOf`, in place, as any union.
164
+ */
165
+ function stateVariantsByAnyOf(value) {
166
+ if (Array.isArray(value)) {
167
+ for (const item of value)
168
+ stateVariantsByAnyOf(item);
169
+ return;
170
+ }
171
+ if (value === null || typeof value !== 'object')
172
+ return;
173
+ const schema = value;
174
+ if (schema[VARIANTS] !== undefined) {
175
+ const entries = Object.entries(schema).filter(([key]) => key !== VARIANTS);
176
+ for (const key of Object.keys(schema))
177
+ delete schema[key];
178
+ for (const [key, entry] of entries)
179
+ schema[key === 'oneOf' ? 'anyOf' : key] = entry;
180
+ }
181
+ for (const entry of Object.values(schema))
182
+ stateVariantsByAnyOf(entry);
183
+ }
184
+ /**
185
+ * Where each rule applies, as JSON Pointers into the document. The marker a named check leaves is
186
+ * removed; every `maxLength` counts UTF-16 code units, the length the structure measures.
187
+ */
188
+ function rulePositions(document) {
189
+ const positions = new Map();
190
+ const note = (rule, pointer) => positions.set(rule, [...(positions.get(rule) ?? []), `#${pointer}`]);
191
+ const visit = (value, pointer) => {
192
+ if (Array.isArray(value)) {
193
+ value.forEach((item, index) => visit(item, `${pointer}/${index}`));
194
+ return;
195
+ }
196
+ if (value === null || typeof value !== 'object')
197
+ return;
198
+ const schema = value;
199
+ const rules = schema['x-astrale-rule'];
200
+ if (rules !== undefined) {
201
+ for (const rule of [rules].flat()) {
202
+ if (!isNamedRule(rule))
203
+ throw new Error(`The marker ${String(rule)} names no rule.`);
204
+ note(rule, pointer);
205
+ }
206
+ delete schema['x-astrale-rule'];
207
+ }
208
+ if (typeof schema.maxLength === 'number')
209
+ note('length-in-utf16-code-units', pointer);
210
+ for (const [key, entry] of Object.entries(schema)) {
211
+ visit(entry, `${pointer}/${escapePointerToken(key)}`);
212
+ }
213
+ };
214
+ visit(document, '');
215
+ return positions;
216
+ }
217
+ function isNamedRule(rule) {
218
+ return typeof rule === 'string' && Object.hasOwn(namedRules, rule);
219
+ }
220
+ function byName([left], [right]) {
221
+ return left < right ? -1 : left > right ? 1 : 0;
222
+ }
@@ -1,4 +1,9 @@
1
- import type { Value as JsonValue } from '@astrale-os/kernel-dsl/value';
1
+ import { type Value as JsonValue } from '@astrale-os/kernel-dsl/value';
2
2
  import type { DomainSchemaIR } from '../model/schema.js';
3
+ /**
4
+ * Read an unknown value as a Domain Schema document of its exact language contract: portable JSON
5
+ * (`DV_JSON_VALUE`), then the structure of its format and version. Throws `SchemaError`.
6
+ */
7
+ export declare function structureDomainSchema(input: unknown): DomainSchemaIR;
3
8
  /** Select the exact Domain language contract before entering its structural grammar. */
4
9
  export declare function routeDomainSchema(input: JsonValue): DomainSchemaIR;