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

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 +13 -52
  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 +19 -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 +26 -5
  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 +15 -11
  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 +6 -12
  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
@@ -0,0 +1,143 @@
1
+ import type { Value as PortableValue } from '@astrale-os/kernel-dsl/value';
2
+ import type { ClassRef } from '../../addressing/index.js';
3
+ import type { OrderingKind } from '../value/ordering.js';
4
+ import type { ClassAncestry } from './inheritance.js';
5
+ import type { NodeUniqueForm, NodeUniqueTuple } from './model/class.js';
6
+ import type { EdgeUniqueField, EdgeUniqueForm, EdgeUniqueTuple } from './model/edge.js';
7
+ import { ClassKey } from '../../addressing/class-key.js';
8
+ /**
9
+ * Every form a key tuple may take, in canonical order: each nonempty set of field kinds. A Property
10
+ * kind stands for one Property or more, whatever their keys.
11
+ */
12
+ export declare const EDGE_UNIQUE_FORMS: readonly EdgeUniqueForm[];
13
+ /** The one form a Node key tuple takes: its fields are Properties, whatever their keys. */
14
+ export declare const NODE_UNIQUE_FORMS: readonly NodeUniqueForm[];
15
+ /**
16
+ * The forms of key tuples a backend enforces, by the kind of the Classes they constrain: a Node key
17
+ * reads Node Properties and an Edge key the fields of an Edge, so announcing one says nothing of
18
+ * the other.
19
+ */
20
+ export interface UniqueForms {
21
+ readonly edge: readonly EdgeUniqueForm[];
22
+ readonly node: readonly NodeUniqueForm[];
23
+ }
24
+ /** Every form of every kind, which a backend enforcing any key tuple announces. */
25
+ export declare const UNIQUE_FORMS: UniqueForms;
26
+ /** No form of either kind: a backend that announces none enforces no key tuple. */
27
+ export declare const NO_UNIQUE_FORMS: UniqueForms;
28
+ /** The fields of an Edge a key tuple reads; the slug is absent from an Edge without one. */
29
+ export interface EdgeUniqueFacts {
30
+ readonly source: string;
31
+ readonly target: string;
32
+ readonly slug?: string;
33
+ /** Its Property values by key; a Property it lacks is absent. */
34
+ readonly props: Readonly<Record<string, PortableValue>>;
35
+ }
36
+ /** The Properties of a Node a key tuple reads by key; a Property it lacks is absent. */
37
+ export interface NodeUniqueFacts {
38
+ readonly props: Readonly<Record<string, PortableValue>>;
39
+ }
40
+ /** The canonical order of fields: source, target, slug, then Properties by key. */
41
+ export declare function compareEdgeUniqueFields(left: EdgeUniqueField, right: EdgeUniqueField): number;
42
+ /** The canonical order of tuples: field by field, a tuple before every tuple it prefixes. */
43
+ export declare const compareEdgeUniqueTuples: (left: EdgeUniqueTuple, right: EdgeUniqueTuple) => number;
44
+ /**
45
+ * The tuple `value` spells, detached, or undefined when it spells none: a nonempty list of fields,
46
+ * distinct and in canonical order, so one set of fields has one spelling.
47
+ */
48
+ export declare function edgeUniqueTuple(value: unknown): EdgeUniqueTuple | undefined;
49
+ /**
50
+ * The tuple the endpoints and slug `named` holds spell, in canonical order, or undefined when it
51
+ * holds none: the key a selector names an Edge by. A selector names no Property.
52
+ */
53
+ export declare function namedEdgeUniqueTuple(named: {
54
+ readonly source?: unknown;
55
+ readonly target?: unknown;
56
+ readonly slug?: unknown;
57
+ }): EdgeUniqueTuple | undefined;
58
+ /** The canonical order of Node tuples: Property by Property, a tuple before every one it prefixes. */
59
+ export declare const compareNodeUniqueTuples: (left: NodeUniqueTuple, right: NodeUniqueTuple) => number;
60
+ /**
61
+ * The Node tuple `value` spells, detached, or undefined when it spells none: a nonempty list of
62
+ * Property keys, distinct and in code-point order, so one set of Properties has one spelling.
63
+ */
64
+ export declare function nodeUniqueTuple(value: unknown): NodeUniqueTuple | undefined;
65
+ /** The form of `NODE_UNIQUE_FORMS` that `value` spells, or undefined when it spells none. */
66
+ export declare function nodeUniqueForm(value: unknown): NodeUniqueForm | undefined;
67
+ /**
68
+ * Whether a backend announcing `forms` for Nodes enforces the Node tuple `value` spells: every
69
+ * Node tuple has the one Node form. False when `value` spells no tuple.
70
+ */
71
+ export declare function enforcesNodeUniqueTuple(forms: readonly NodeUniqueForm[], value: unknown): boolean;
72
+ /** The form of `tuple`: the kinds of its fields, each once. */
73
+ export declare function edgeUniqueFormOf(tuple: EdgeUniqueTuple): EdgeUniqueForm;
74
+ /** The form of `EDGE_UNIQUE_FORMS` that `value` spells, or undefined when it spells none. */
75
+ export declare function edgeUniqueForm(value: unknown): EdgeUniqueForm | undefined;
76
+ /**
77
+ * Whether a backend announcing `forms` enforces the tuple `value` spells: its form is one of them.
78
+ * False when `value` spells no tuple, so a tuple is never taken as enforced by mistake.
79
+ */
80
+ export declare function enforcesEdgeUniqueTuple(forms: readonly EdgeUniqueForm[], value: unknown): boolean;
81
+ /**
82
+ * Whether a Property may be a key field (D-S1): a single-kind scalar by its ordering facet, a
83
+ * string, number, boolean or instant, that no automatic program writes.
84
+ */
85
+ export declare function keyableProperty(ordering: OrderingKind | undefined, auto: unknown): boolean;
86
+ /**
87
+ * The values of the fields of `tuple` on `edge`, in order, or undefined when one of them is absent,
88
+ * so that an Edge without a slug or without a Property never collides.
89
+ */
90
+ export declare function edgeUniqueValues(tuple: EdgeUniqueTuple, edge: EdgeUniqueFacts): readonly PortableValue[] | undefined;
91
+ /**
92
+ * The value `edge` takes under `tuple`, the canonical JSON of the values of its fields, or
93
+ * undefined when one of them is absent: two distinct Edges of the Classes a tuple covers collide
94
+ * exactly when they take one value. Endpoints compare by NodeId, slugs by exact text and
95
+ * Properties by canonical Value.
96
+ */
97
+ export declare function edgeUniqueValue(tuple: EdgeUniqueTuple, edge: EdgeUniqueFacts): string | undefined;
98
+ /**
99
+ * The values of the Properties of `tuple` on `node`, in order, or undefined when one of them is
100
+ * absent, so that a Node without one of them never collides, like NULL in an SQL UNIQUE.
101
+ */
102
+ export declare function nodeUniqueValues(tuple: NodeUniqueTuple, node: NodeUniqueFacts): readonly PortableValue[] | undefined;
103
+ /**
104
+ * The value `node` takes under `tuple`, the canonical JSON of the values of its Properties, or
105
+ * undefined when one of them is absent: two distinct Nodes of the Classes a tuple covers collide
106
+ * exactly when they take one value. Properties compare by canonical Value, nothing normalized.
107
+ */
108
+ export declare function nodeUniqueValue(tuple: NodeUniqueTuple, node: NodeUniqueFacts): string | undefined;
109
+ /** A Class with the key tuples it declares, an Edge Class or a Node Class. */
110
+ type KeyedClass = ClassAncestry & {
111
+ readonly unique?: readonly (EdgeUniqueTuple | NodeUniqueTuple)[];
112
+ };
113
+ /** A key tuple together with the Class declaring it, whose descendants it covers. */
114
+ export interface DeclaredEdgeUniqueTuple {
115
+ readonly class: ClassKey;
116
+ readonly fields: EdgeUniqueTuple;
117
+ }
118
+ /** A Node key tuple together with the Class declaring it, whose descendants it covers. */
119
+ export interface DeclaredNodeUniqueTuple {
120
+ readonly class: ClassKey;
121
+ readonly fields: NodeUniqueTuple;
122
+ }
123
+ /**
124
+ * The tuples covering `candidate`: those it and each of its ancestors declare, each with the Class
125
+ * declaring it, ancestors found by `resolve`. A descendant never restates them.
126
+ */
127
+ export declare function coveringEdgeUniqueTuples<Declaration extends KeyedClass>(candidate: Declaration, resolve: (ref: ClassRef) => Declaration | undefined): readonly DeclaredEdgeUniqueTuple[];
128
+ /**
129
+ * The Node tuples covering `candidate`: those it and each of its ancestors declare, each with the
130
+ * Class declaring it, ancestors found by `resolve`. A descendant never restates them.
131
+ */
132
+ export declare function coveringNodeUniqueTuples<Declaration extends KeyedClass>(candidate: Declaration, resolve: (ref: ClassRef) => Declaration | undefined): readonly DeclaredNodeUniqueTuple[];
133
+ /**
134
+ * The keys `edge` holds: its value under each tuple of `tuples`, tagged by the Class declaring the
135
+ * tuple, so two Edges collide exactly when they hold one key.
136
+ */
137
+ export declare function edgeUniqueKeys(tuples: readonly DeclaredEdgeUniqueTuple[], edge: EdgeUniqueFacts): readonly string[];
138
+ /**
139
+ * The keys `node` holds: its value under each tuple of `tuples`, tagged by the Class declaring the
140
+ * tuple, so two Nodes collide exactly when they hold one key.
141
+ */
142
+ export declare function nodeUniqueKeys(tuples: readonly DeclaredNodeUniqueTuple[], node: NodeUniqueFacts): readonly string[];
143
+ export {};
@@ -0,0 +1,264 @@
1
+ import { json } from '@astrale-os/kernel-dsl/value';
2
+ import { ClassKey } from '../../addressing/class-key.js';
3
+ import { compareUnicode } from '../../addressing/ordering.js';
4
+ import { PropertyKey } from '../../addressing/property-key.js';
5
+ /** The kinds of key fields, in canonical order: the endpoints, the slug, then the Properties. */
6
+ const KINDS = Object.freeze([
7
+ 'source',
8
+ 'target',
9
+ 'slug',
10
+ 'property',
11
+ ]);
12
+ /** The canonical order of forms: kind by kind, a form before every form it prefixes. */
13
+ const compareForms = compareSequences(compareKinds);
14
+ /**
15
+ * Every form a key tuple may take, in canonical order: each nonempty set of field kinds. A Property
16
+ * kind stands for one Property or more, whatever their keys.
17
+ */
18
+ export const EDGE_UNIQUE_FORMS = Object.freeze(Array.from({ length: (1 << KINDS.length) - 1 }, (_, index) => Object.freeze(KINDS.filter((_, kind) => ((index + 1) & (1 << kind)) !== 0))).sort(compareForms));
19
+ /** The one form a Node key tuple takes: its fields are Properties, whatever their keys. */
20
+ export const NODE_UNIQUE_FORMS = Object.freeze([
21
+ Object.freeze(['property']),
22
+ ]);
23
+ /** Every form of every kind, which a backend enforcing any key tuple announces. */
24
+ export const UNIQUE_FORMS = Object.freeze({
25
+ edge: EDGE_UNIQUE_FORMS,
26
+ node: NODE_UNIQUE_FORMS,
27
+ });
28
+ /** No form of either kind: a backend that announces none enforces no key tuple. */
29
+ export const NO_UNIQUE_FORMS = Object.freeze({
30
+ edge: Object.freeze([]),
31
+ node: Object.freeze([]),
32
+ });
33
+ /** The kind of `field`. */
34
+ function kindOf(field) {
35
+ return typeof field === 'string' ? field : 'property';
36
+ }
37
+ function compareKinds(left, right) {
38
+ return KINDS.indexOf(left) - KINDS.indexOf(right);
39
+ }
40
+ /** The canonical order of fields: source, target, slug, then Properties by key. */
41
+ export function compareEdgeUniqueFields(left, right) {
42
+ return (compareKinds(kindOf(left), kindOf(right)) ||
43
+ (typeof left === 'string' || typeof right === 'string'
44
+ ? 0
45
+ : compareUnicode(left.property, right.property)));
46
+ }
47
+ /** The canonical order of tuples: field by field, a tuple before every tuple it prefixes. */
48
+ export const compareEdgeUniqueTuples = compareSequences(compareEdgeUniqueFields);
49
+ /** The field `value` spells, detached, or undefined when it spells none. */
50
+ function edgeUniqueField(value) {
51
+ if (value === 'source' || value === 'target' || value === 'slug')
52
+ return value;
53
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
54
+ return undefined;
55
+ const keys = Object.keys(value);
56
+ const property = value.property;
57
+ return keys.length === 1 && keys[0] === 'property' && PropertyKey.is(property)
58
+ ? Object.freeze({ property })
59
+ : undefined;
60
+ }
61
+ /**
62
+ * The tuple `value` spells, detached, or undefined when it spells none: a nonempty list of fields,
63
+ * distinct and in canonical order, so one set of fields has one spelling.
64
+ */
65
+ export function edgeUniqueTuple(value) {
66
+ if (!Array.isArray(value) || value.length === 0)
67
+ return undefined;
68
+ const fields = [];
69
+ for (const item of value) {
70
+ const field = edgeUniqueField(item);
71
+ if (field === undefined)
72
+ return undefined;
73
+ if (fields.length > 0 && compareEdgeUniqueFields(fields.at(-1), field) >= 0)
74
+ return undefined;
75
+ fields.push(field);
76
+ }
77
+ return Object.freeze(fields);
78
+ }
79
+ /**
80
+ * The tuple the endpoints and slug `named` holds spell, in canonical order, or undefined when it
81
+ * holds none: the key a selector names an Edge by. A selector names no Property.
82
+ */
83
+ export function namedEdgeUniqueTuple(named) {
84
+ return edgeUniqueTuple(['source', 'target', 'slug'].filter((field) => named[field] !== undefined));
85
+ }
86
+ /** The canonical order of Node tuples: Property by Property, a tuple before every one it prefixes. */
87
+ export const compareNodeUniqueTuples = compareSequences(compareUnicode);
88
+ /**
89
+ * The Node tuple `value` spells, detached, or undefined when it spells none: a nonempty list of
90
+ * Property keys, distinct and in code-point order, so one set of Properties has one spelling.
91
+ */
92
+ export function nodeUniqueTuple(value) {
93
+ if (!Array.isArray(value) || value.length === 0)
94
+ return undefined;
95
+ const keys = [];
96
+ for (const key of value) {
97
+ if (!PropertyKey.is(key))
98
+ return undefined;
99
+ if (keys.length > 0 && compareUnicode(keys.at(-1), key) >= 0)
100
+ return undefined;
101
+ keys.push(key);
102
+ }
103
+ return Object.freeze(keys);
104
+ }
105
+ /** The form of `NODE_UNIQUE_FORMS` that `value` spells, or undefined when it spells none. */
106
+ export function nodeUniqueForm(value) {
107
+ return Array.isArray(value) && value.length === 1 && value[0] === 'property'
108
+ ? NODE_UNIQUE_FORMS[0]
109
+ : undefined;
110
+ }
111
+ /**
112
+ * Whether a backend announcing `forms` for Nodes enforces the Node tuple `value` spells: every
113
+ * Node tuple has the one Node form. False when `value` spells no tuple.
114
+ */
115
+ export function enforcesNodeUniqueTuple(forms, value) {
116
+ return forms.length > 0 && nodeUniqueTuple(value) !== undefined;
117
+ }
118
+ /** The form of `tuple`: the kinds of its fields, each once. */
119
+ export function edgeUniqueFormOf(tuple) {
120
+ const kinds = new Set(tuple.map(kindOf));
121
+ return EDGE_UNIQUE_FORMS.find((form) => form.length === kinds.size && form.every((kind) => kinds.has(kind)));
122
+ }
123
+ /** The form of `EDGE_UNIQUE_FORMS` that `value` spells, or undefined when it spells none. */
124
+ export function edgeUniqueForm(value) {
125
+ if (!Array.isArray(value))
126
+ return undefined;
127
+ return EDGE_UNIQUE_FORMS.find((form) => form.length === value.length && form.every((kind, index) => kind === value[index]));
128
+ }
129
+ /**
130
+ * Whether a backend announcing `forms` enforces the tuple `value` spells: its form is one of them.
131
+ * False when `value` spells no tuple, so a tuple is never taken as enforced by mistake.
132
+ */
133
+ export function enforcesEdgeUniqueTuple(forms, value) {
134
+ const tuple = edgeUniqueTuple(value);
135
+ if (tuple === undefined)
136
+ return false;
137
+ const form = edgeUniqueFormOf(tuple);
138
+ return forms.some((candidate) => compareForms(candidate, form) === 0);
139
+ }
140
+ /**
141
+ * Whether a Property may be a key field (D-S1): a single-kind scalar by its ordering facet, a
142
+ * string, number, boolean or instant, that no automatic program writes.
143
+ */
144
+ export function keyableProperty(ordering, auto) {
145
+ return ordering !== undefined && auto === undefined;
146
+ }
147
+ /**
148
+ * The values of the fields of `tuple` on `edge`, in order, or undefined when one of them is absent,
149
+ * so that an Edge without a slug or without a Property never collides.
150
+ */
151
+ export function edgeUniqueValues(tuple, edge) {
152
+ return keyValues(tuple, (field) => typeof field === 'string' ? edge[field] : propertyOf(edge.props, field.property));
153
+ }
154
+ /**
155
+ * The value `edge` takes under `tuple`, the canonical JSON of the values of its fields, or
156
+ * undefined when one of them is absent: two distinct Edges of the Classes a tuple covers collide
157
+ * exactly when they take one value. Endpoints compare by NodeId, slugs by exact text and
158
+ * Properties by canonical Value.
159
+ */
160
+ export function edgeUniqueValue(tuple, edge) {
161
+ return serialized(edgeUniqueValues(tuple, edge));
162
+ }
163
+ /**
164
+ * The values of the Properties of `tuple` on `node`, in order, or undefined when one of them is
165
+ * absent, so that a Node without one of them never collides, like NULL in an SQL UNIQUE.
166
+ */
167
+ export function nodeUniqueValues(tuple, node) {
168
+ return keyValues(tuple, (key) => propertyOf(node.props, key));
169
+ }
170
+ /**
171
+ * The value `node` takes under `tuple`, the canonical JSON of the values of its Properties, or
172
+ * undefined when one of them is absent: two distinct Nodes of the Classes a tuple covers collide
173
+ * exactly when they take one value. Properties compare by canonical Value, nothing normalized.
174
+ */
175
+ export function nodeUniqueValue(tuple, node) {
176
+ return serialized(nodeUniqueValues(tuple, node));
177
+ }
178
+ /**
179
+ * The tuples covering `candidate`: those it and each of its ancestors declare, each with the Class
180
+ * declaring it, ancestors found by `resolve`. A descendant never restates them.
181
+ */
182
+ export function coveringEdgeUniqueTuples(candidate, resolve) {
183
+ return coveringTuples(candidate, resolve);
184
+ }
185
+ /**
186
+ * The Node tuples covering `candidate`: those it and each of its ancestors declare, each with the
187
+ * Class declaring it, ancestors found by `resolve`. A descendant never restates them.
188
+ */
189
+ export function coveringNodeUniqueTuples(candidate, resolve) {
190
+ return coveringTuples(candidate, resolve);
191
+ }
192
+ /**
193
+ * The keys `edge` holds: its value under each tuple of `tuples`, tagged by the Class declaring the
194
+ * tuple, so two Edges collide exactly when they hold one key.
195
+ */
196
+ export function edgeUniqueKeys(tuples, edge) {
197
+ return heldKeys(tuples, (fields) => edgeUniqueValue(fields, edge));
198
+ }
199
+ /**
200
+ * The keys `node` holds: its value under each tuple of `tuples`, tagged by the Class declaring the
201
+ * tuple, so two Nodes collide exactly when they hold one key.
202
+ */
203
+ export function nodeUniqueKeys(tuples, node) {
204
+ return heldKeys(tuples, (fields) => nodeUniqueValue(fields, node));
205
+ }
206
+ /** The values `read` gives the fields of `tuple`, in order, or undefined when one is absent. */
207
+ function keyValues(tuple, read) {
208
+ const values = [];
209
+ for (const field of tuple) {
210
+ const value = read(field);
211
+ if (value === undefined)
212
+ return undefined;
213
+ values.push(value);
214
+ }
215
+ return Object.freeze(values);
216
+ }
217
+ /** The value of the Property `key` in `props`, or undefined when it is absent. */
218
+ function propertyOf(props, key) {
219
+ return Object.hasOwn(props, key) ? props[key] : undefined;
220
+ }
221
+ /** The canonical JSON of a key's values, or undefined when it has none. */
222
+ function serialized(values) {
223
+ return values === undefined ? undefined : json.serializeAdmitted(values);
224
+ }
225
+ /**
226
+ * The tuples `candidate` and its ancestors declare, each with its declarer. Only ancestors of the
227
+ * candidate's kind are visited, so every tuple is of that kind.
228
+ */
229
+ function coveringTuples(candidate, resolve) {
230
+ const tuples = [];
231
+ const seen = new Set();
232
+ const visit = (value) => {
233
+ if (seen.has(value) || value.kind !== candidate.kind)
234
+ return;
235
+ seen.add(value);
236
+ for (const fields of value.unique ?? [])
237
+ tuples.push(Object.freeze({ class: ClassKey.of(value.ref), fields }));
238
+ for (const ref of value.extends) {
239
+ const parent = resolve(ref);
240
+ if (parent !== undefined)
241
+ visit(parent);
242
+ }
243
+ };
244
+ visit(candidate);
245
+ return Object.freeze(tuples);
246
+ }
247
+ /** The keys a fact holds under `tuples`, its value under each tagged by the declaring Class. */
248
+ function heldKeys(tuples, valueOf) {
249
+ return tuples.flatMap(({ class: declaring, fields }) => {
250
+ const value = valueOf(fields);
251
+ return value === undefined ? [] : [JSON.stringify([declaring, fields, value])];
252
+ });
253
+ }
254
+ /** The lexicographic order of sequences by `compare`, a sequence before every one it prefixes. */
255
+ function compareSequences(compare) {
256
+ return (left, right) => {
257
+ for (let index = 0; index < Math.min(left.length, right.length); index += 1) {
258
+ const order = compare(left[index], right[index]);
259
+ if (order !== 0)
260
+ return order;
261
+ }
262
+ return left.length - right.length;
263
+ };
264
+ }
@@ -0,0 +1,85 @@
1
+ import type { ClassRef } from '../../addressing/index.js';
2
+ import type { EdgeContract, EdgeCount, EdgeEndpointBase, IncidentEndpoint } from '../class/model/edge.js';
3
+ /**
4
+ * The Class of the owning Domain's Node: every Domain principal is a Node of the final Kernel
5
+ * `Domain` Class, so a Core Edge that names the Domain must accept that Class at that endpoint.
6
+ */
7
+ export declare const DOMAIN_ENDPOINT_CLASS: ClassRef;
8
+ /** One endpoint of a Core Edge: a Core Node, a projected member or the owning Domain. */
9
+ export interface CoreFactEndpoint {
10
+ readonly key: string;
11
+ /**
12
+ * Set on a projected member and on the owning Domain: the Kernel Class it is a Node of, and where
13
+ * a breach of its degree is reported.
14
+ */
15
+ readonly member?: {
16
+ readonly class: ClassRef;
17
+ readonly pointer: string;
18
+ };
19
+ }
20
+ /** One Core Edge whose endpoints satisfy its exact Class. */
21
+ export interface CoreFactEdge<Edge> {
22
+ readonly edge: Edge;
23
+ /** The exact Class's key, as `CoreEdgeSet.classes` names it. */
24
+ readonly class: string;
25
+ readonly contract: EdgeContract;
26
+ readonly source: CoreFactEndpoint;
27
+ readonly target: CoreFactEndpoint;
28
+ }
29
+ /** One declared Core Node. It proves its own complete degree, so both bounds hold. */
30
+ export interface CoreDegreeSubject {
31
+ readonly key: string;
32
+ readonly class: ClassRef;
33
+ readonly pointer: string;
34
+ }
35
+ export interface CoreEdgeSet<Edge> {
36
+ readonly edges: readonly CoreFactEdge<Edge>[];
37
+ /** The local Edge Classes, in the order their slices are checked. */
38
+ readonly classes: readonly {
39
+ readonly key: string;
40
+ readonly contract: EdgeContract & {
41
+ readonly abstract: boolean;
42
+ };
43
+ }[];
44
+ readonly nodes: readonly CoreDegreeSubject[];
45
+ readonly satisfies: (ref: ClassRef, accepts: readonly ClassRef[]) => boolean;
46
+ /** The keys an Edge holds under the tuples covering its Class. */
47
+ readonly keys: (edge: CoreFactEdge<Edge>) => readonly string[];
48
+ /** Whether an undirected Edge's two endpoints state one contract, counted once. */
49
+ readonly sameIncident: (left: IncidentEndpoint, right: IncidentEndpoint) => boolean;
50
+ readonly report: (issue: CoreEdgeIssue<Edge>) => void;
51
+ }
52
+ export type CoreEdgeIssue<Edge> = {
53
+ readonly kind: 'identity';
54
+ readonly edge: Edge;
55
+ readonly previous: Edge;
56
+ } | {
57
+ readonly kind: 'no-self';
58
+ readonly edge: Edge;
59
+ } | {
60
+ readonly kind: 'key';
61
+ readonly edge: Edge;
62
+ readonly previous: Edge;
63
+ } | {
64
+ readonly kind: 'acyclic';
65
+ readonly class: string;
66
+ } | {
67
+ readonly kind: 'degree';
68
+ readonly pointer: string;
69
+ readonly endpoint: EdgeEndpointBase;
70
+ readonly count: EdgeCount;
71
+ readonly degree: number;
72
+ };
73
+ /** Whether the endpoints satisfy the contract: in order when directed, in either order when not. */
74
+ export declare function coreEndpointsSatisfy<Endpoint>(contract: EdgeContract, source: Endpoint, target: Endpoint, satisfies: (endpoint: Endpoint, accepts: readonly ClassRef[]) => boolean): boolean;
75
+ /**
76
+ * Report each fact that holds a key an earlier fact holds, with the first holder of that key. Core
77
+ * facts have no slug, so only tuples of endpoints and Properties bind them (DV-NODE-UNIQUE,
78
+ * DV-EDGE-UNIQUE); Activation checks them against stored data.
79
+ */
80
+ export declare function checkHeldKeys<Fact>(facts: Iterable<Fact>, keys: (fact: Fact) => readonly string[], report: (fact: Fact, previous: Fact) => void): void;
81
+ /**
82
+ * Check normalized Edge identity, noSelf, keys, and the acyclicity and Core degrees of each exact
83
+ * concrete Edge Class over its own Edges.
84
+ */
85
+ export declare function checkCoreEdgeSet<Edge>(set: CoreEdgeSet<Edge>): void;
@@ -0,0 +1,116 @@
1
+ import { compareUnicode } from '../../addressing/ordering.js';
2
+ import { countBounds, hasDirectedCycle, KERNEL_ORIGIN } from '../class/inheritance.js';
3
+ /*
4
+ * The Core fact rules that authored and compiled admission share. Each admission resolves its own
5
+ * Core Nodes and Edges, then reports every issue under its own codes, messages and pointers.
6
+ */
7
+ /**
8
+ * The Class of the owning Domain's Node: every Domain principal is a Node of the final Kernel
9
+ * `Domain` Class, so a Core Edge that names the Domain must accept that Class at that endpoint.
10
+ */
11
+ export const DOMAIN_ENDPOINT_CLASS = Object.freeze({
12
+ origin: KERNEL_ORIGIN,
13
+ kind: 'class',
14
+ name: 'Domain',
15
+ });
16
+ /** Whether the endpoints satisfy the contract: in order when directed, in either order when not. */
17
+ export function coreEndpointsSatisfy(contract, source, target, satisfies) {
18
+ if (contract.orientation === 'directed') {
19
+ const { endpoints } = contract;
20
+ return (satisfies(source, endpoints.source.accepts) && satisfies(target, endpoints.target.accepts));
21
+ }
22
+ const [first, second] = contract.endpoints;
23
+ return ((satisfies(source, first.accepts) && satisfies(target, second.accepts)) ||
24
+ (satisfies(source, second.accepts) && satisfies(target, first.accepts)));
25
+ }
26
+ /**
27
+ * Report each fact that holds a key an earlier fact holds, with the first holder of that key. Core
28
+ * facts have no slug, so only tuples of endpoints and Properties bind them (DV-NODE-UNIQUE,
29
+ * DV-EDGE-UNIQUE); Activation checks them against stored data.
30
+ */
31
+ export function checkHeldKeys(facts, keys, report) {
32
+ const holders = new Map();
33
+ for (const fact of facts) {
34
+ const held = keys(fact);
35
+ const holder = held.find((key) => holders.has(key));
36
+ if (holder !== undefined)
37
+ report(fact, holders.get(holder));
38
+ for (const key of held)
39
+ if (!holders.has(key))
40
+ holders.set(key, fact);
41
+ }
42
+ }
43
+ /**
44
+ * Check normalized Edge identity, noSelf, keys, and the acyclicity and Core degrees of each exact
45
+ * concrete Edge Class over its own Edges.
46
+ */
47
+ export function checkCoreEdgeSet(set) {
48
+ const identities = new Map();
49
+ const slices = new Map(set.classes.map(({ key }) => [key, []]));
50
+ for (const fact of set.edges) {
51
+ const [source, target] = fact.contract.orientation === 'undirected' &&
52
+ compareUnicode(fact.source.key, fact.target.key) > 0
53
+ ? [fact.target.key, fact.source.key]
54
+ : [fact.source.key, fact.target.key];
55
+ const identity = `${fact.class}\u0000${source}\u0000${target}`;
56
+ const previous = identities.get(identity);
57
+ if (previous !== undefined)
58
+ set.report({ kind: 'identity', edge: fact.edge, previous });
59
+ else
60
+ identities.set(identity, fact.edge);
61
+ slices.get(fact.class)?.push(fact);
62
+ if (fact.contract.constraints.noSelf === true && fact.source.key === fact.target.key)
63
+ set.report({ kind: 'no-self', edge: fact.edge });
64
+ }
65
+ checkHeldKeys(set.edges, set.keys, (fact, previous) => set.report({ kind: 'key', edge: fact.edge, previous: previous.edge }));
66
+ for (const { key, contract } of set.classes) {
67
+ // No Edge is of an abstract Class exactly, so it bounds no degree and closes no cycle of its
68
+ // own: each concrete descendant carries the counts it refines, over its own Edges.
69
+ if (contract.abstract)
70
+ continue;
71
+ const slice = slices.get(key);
72
+ if (contract.constraints.acyclic === true && hasDirectedCycle(slice))
73
+ set.report({ kind: 'acyclic', class: key });
74
+ checkDegrees(set, contract, slice);
75
+ }
76
+ }
77
+ function checkDegrees(set, contract, slice) {
78
+ for (const subject of degreeSubjects(set.nodes, slice)) {
79
+ const check = (endpoint, count, degree) => {
80
+ const [minimum, maximum] = countBounds(count);
81
+ if (degree > maximum || (degree < minimum && subject.minimum))
82
+ set.report({ kind: 'degree', pointer: subject.pointer, endpoint, count, degree });
83
+ };
84
+ if (contract.orientation === 'directed') {
85
+ const { source, target } = contract.endpoints;
86
+ if (set.satisfies(subject.class, source.accepts))
87
+ check(source, source.outgoing, slice.filter((edge) => edge.source.key === subject.key).length);
88
+ if (set.satisfies(subject.class, target.accepts))
89
+ check(target, target.incoming, slice.filter((edge) => edge.target.key === subject.key).length);
90
+ continue;
91
+ }
92
+ const [first, second] = contract.endpoints;
93
+ const degree = slice.filter((edge) => edge.source.key === subject.key || edge.target.key === subject.key).length;
94
+ if (set.satisfies(subject.class, first.accepts))
95
+ check(first, first.incident, degree);
96
+ if (!set.sameIncident(first, second) && set.satisfies(subject.class, second.accepts))
97
+ check(second, second.incident, degree);
98
+ }
99
+ }
100
+ /**
101
+ * Every declared Core Node proves its own complete degree, so both bounds hold. A projected member,
102
+ * and the owning Domain, is only named by the Edges that reach it: the Domain may also create
103
+ * ordinary Edges of the same Class against it, so a minimum is unprovable here and only the maximum
104
+ * is enforced.
105
+ */
106
+ function degreeSubjects(nodes, slice) {
107
+ const subjects = new Map(nodes.map((node) => [node.key, { ...node, minimum: true }]));
108
+ for (const edge of slice) {
109
+ for (const { key, member } of [edge.source, edge.target]) {
110
+ if (member === undefined || subjects.has(key))
111
+ continue;
112
+ subjects.set(key, { key, class: member.class, pointer: member.pointer, minimum: false });
113
+ }
114
+ }
115
+ return subjects.values();
116
+ }
@@ -0,0 +1,10 @@
1
+ /** An edge a depth-first walk took back to a node it has not finished, and the path that reached it. */
2
+ export interface CycleEdge<Node> {
3
+ readonly path: readonly Node[];
4
+ readonly target: Node;
5
+ }
6
+ /**
7
+ * Each edge closing a cycle in a depth-first walk from `roots`, as the walk meets it. A chain can be
8
+ * as long as a document allows, so the walk holds its own stack, and it enters each node once.
9
+ */
10
+ export declare function cycleEdges<Node>(roots: Iterable<Node>, targetsOf: (node: Node) => Iterable<Node>): Generator<CycleEdge<Node>, void, undefined>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Each edge closing a cycle in a depth-first walk from `roots`, as the walk meets it. A chain can be
3
+ * as long as a document allows, so the walk holds its own stack, and it enters each node once.
4
+ */
5
+ export function* cycleEdges(roots, targetsOf) {
6
+ const finished = new Set();
7
+ for (const root of roots) {
8
+ if (finished.has(root))
9
+ continue;
10
+ // Only the last node leaves it, so a Set's order is the path.
11
+ const walking = new Set([root]);
12
+ const stack = [{ node: root, targets: targetsOf(root)[Symbol.iterator]() }];
13
+ while (stack.length > 0) {
14
+ const { node, targets } = stack.at(-1);
15
+ const { done, value: target } = targets.next();
16
+ if (done === true) {
17
+ walking.delete(node);
18
+ finished.add(node);
19
+ stack.pop();
20
+ }
21
+ else if (walking.has(target)) {
22
+ yield { path: [...walking], target };
23
+ }
24
+ else if (!finished.has(target)) {
25
+ walking.add(target);
26
+ stack.push({ node: target, targets: targetsOf(target)[Symbol.iterator]() });
27
+ }
28
+ }
29
+ }
30
+ }