@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
@@ -0,0 +1,11 @@
1
+ import { cycleEdges } from '../../cycle.js';
2
+ import { PolicyComposition } from '../model/policy.js';
3
+ /** Each edge closing a cycle among the named Policies of `origin`, walking from `names` in order. */
4
+ export function compositionCycles(names, expressionOf, origin) {
5
+ return cycleEdges(names, (name) => {
6
+ const expression = expressionOf(name);
7
+ if (expression === undefined || 'match' in expression)
8
+ return [];
9
+ return PolicyComposition.of(expression).operands.flatMap((ref) => ref.origin === origin ? [ref.name] : []);
10
+ });
11
+ }
@@ -0,0 +1,51 @@
1
+ import type { ClassRef, PolicyRef } from '../../../addressing/index.js';
2
+ import type { EdgeContract } from '../../class/model/edge.js';
3
+ import type { PolicyExpression, PolicyObjectRef } from '../model/policy.js';
4
+ import type { CheckLeafClasses } from './checks.js';
5
+ import { type ClassAncestry } from '../../class/inheritance.js';
6
+ import { type PatternBranch } from './branches.js';
7
+ export type ObjectContract = {
8
+ readonly kind: 'default';
9
+ } | {
10
+ readonly kind: 'exact';
11
+ readonly ref: ClassRef;
12
+ };
13
+ export type PolicyUseContract = {
14
+ readonly kind: 'object';
15
+ readonly object: ObjectContract;
16
+ } | {
17
+ readonly kind: 'edge';
18
+ readonly source: ObjectContract;
19
+ readonly target: ObjectContract;
20
+ };
21
+ /** What Policy typing reads of the closure it types against: source or compiled admission. */
22
+ export interface PolicyTypingScope {
23
+ readonly normalized: ReadonlyMap<string, PolicyExpression>;
24
+ /** Each resolves, through `resolveClass`, to a Node Class. */
25
+ readonly allNodeClasses: readonly ClassRef[];
26
+ /** The concrete Classes of `allNodeClasses`, in its order. */
27
+ readonly concreteNodeClasses: readonly ClassRef[];
28
+ isLocalPolicy(ref: PolicyRef): boolean;
29
+ /** The Class a ref names in the closure, as satisfaction reads it. */
30
+ resolveClass(ref: ClassRef): ClassAncestry | undefined;
31
+ edgeDeclaration(ref: ClassRef): EdgeContract | undefined;
32
+ /** The contract of a Node a Policy pattern references, `undefined` when it has none. */
33
+ referenceContract(ref: PolicyObjectRef): ObjectContract | undefined;
34
+ }
35
+ export declare class PolicyTyping {
36
+ #private;
37
+ readonly scope: PolicyTypingScope;
38
+ constructor(scope: PolicyTypingScope);
39
+ /** The normalized branches of a named Policy, `undefined` when it does not expand. */
40
+ expandedBranches(name: string, namespace: string): readonly PatternBranch[] | undefined;
41
+ policyAccepts(name: string, object: ObjectContract): boolean;
42
+ /** Whether the Policy accepts every concrete source and target pair the Edge Class accepts. */
43
+ policyAcceptsEdgeClass(name: string, declaration: EdgeContract): boolean;
44
+ /**
45
+ * How a check of the Policy types against each contract of its object, `undefined` when the
46
+ * Policy does not expand or one of its branches is typed for no contract.
47
+ */
48
+ checkLeafClasses(name: string, contracts: readonly ObjectContract[]): CheckLeafClasses | undefined;
49
+ endpointsOverlap(left: readonly ClassRef[], right: readonly ClassRef[]): boolean;
50
+ branchIsTyped(branch: PatternBranch, use: PolicyUseContract): boolean;
51
+ }
@@ -0,0 +1,456 @@
1
+ import { Key } from '../../../addressing/index.js';
2
+ import { definitionRefIndex } from '../../../addressing/ordering.js';
3
+ import { classSatisfies, isGraphRoot } from '../../class/inheritance.js';
4
+ import { limits } from '../../limits.js';
5
+ import { PolicyComposition } from '../model/policy.js';
6
+ import { branchesOf, branchProduct, capBranches, targetMode, termKey, UnionFind, } from './branches.js';
7
+ import { admittedCheckClasses } from './checks.js';
8
+ export class PolicyTyping {
9
+ scope;
10
+ // Expanded branches of each named Policy, cached by node identity. A Policy's expansion is reused
11
+ // across every composition path that reaches it (and across every use site and object contract,
12
+ // none of which the expansion depends on), so a shared-child composition DAG is expanded in work
13
+ // linear in the number of Policies instead of enumerating every path. The expansion result is
14
+ // independent of the reaching path up to the opaque term-namespace labels, which only ever
15
+ // disambiguate variables within one branch and leave targetMode and branch typing unchanged.
16
+ // Two occurrences of one Policy in a branch share labels only when a Policy reaches it by two
17
+ // paths; for that to merge distinct variables, the Policy expands deeper than
18
+ // `limits.policy.patternDepth`.
19
+ #expansions = new Map();
20
+ #index;
21
+ constructor(scope) {
22
+ this.scope = scope;
23
+ }
24
+ /** The normalized branches of a named Policy, `undefined` when it does not expand. */
25
+ expandedBranches(name, namespace) {
26
+ return this.#expandedBranches(name, new Set(), namespace);
27
+ }
28
+ policyAccepts(name, object) {
29
+ return this.#policyBranchTyping(name, object)?.every(Boolean) ?? false;
30
+ }
31
+ /** Whether the Policy accepts every concrete source and target pair the Edge Class accepts. */
32
+ policyAcceptsEdgeClass(name, declaration) {
33
+ const endpoints = endpointPair(declaration);
34
+ const sources = this.#concreteEndpointClasses(endpoints[0].accepts);
35
+ const targets = this.#concreteEndpointClasses(endpoints[1].accepts);
36
+ return sources.every((source) => targets.every((target) => this.#policyAcceptsEdge(name, { kind: 'exact', ref: source }, { kind: 'exact', ref: target })));
37
+ }
38
+ /**
39
+ * How a check of the Policy types against each contract of its object, `undefined` when the
40
+ * Policy does not expand or one of its branches is typed for no contract.
41
+ */
42
+ checkLeafClasses(name, contracts) {
43
+ const typings = new Map(contracts.map((contract) => [
44
+ contract.kind === 'exact' ? Key.of(contract.ref) : 'default',
45
+ this.#policyBranchTyping(name, contract),
46
+ ]));
47
+ const admitted = admittedCheckClasses(typings);
48
+ return admitted === undefined ? undefined : { accepted: [...typings.keys()], admitted };
49
+ }
50
+ endpointsOverlap(left, right) {
51
+ const seed = [{ kind: 'open', requirements: [] }];
52
+ const afterLeft = this.#applyEndpoint(seed, left);
53
+ return this.#applyEndpoint(afterLeft, right).length > 0;
54
+ }
55
+ branchIsTyped(branch, use) {
56
+ if (targetMode(branch) !== use.kind)
57
+ return false;
58
+ const alternatives = edgeAlternatives(branch.edges, this);
59
+ return alternatives.some((variants) => this.#constraintsAreSatisfiable(branch, variants, use));
60
+ }
61
+ /** Whether each normalized branch of the Policy is typed for an object of this contract. */
62
+ #policyBranchTyping(name, object) {
63
+ const branches = this.#expandedBranches(name, new Set(), `$use:${name}`);
64
+ const use = { kind: 'object', object };
65
+ return branches?.map((branch) => this.branchIsTyped(branch, use));
66
+ }
67
+ #policyAcceptsEdge(name, source, target) {
68
+ const branches = this.#expandedBranches(name, new Set(), `$edge-use:${name}`);
69
+ const use = { kind: 'edge', source, target };
70
+ return branches !== undefined && branches.every((branch) => this.branchIsTyped(branch, use));
71
+ }
72
+ #concreteEndpointClasses(accepts) {
73
+ const { concrete } = this.#nodeClassIndex();
74
+ return this.#satisfyingOneOf(accepts).filter((ref) => concrete.has(definitionRefIndex(ref)));
75
+ }
76
+ #nodeClassIndex() {
77
+ this.#index ??= nodeClassIndex(this.scope);
78
+ return this.#index;
79
+ }
80
+ #expandedBranches(name, visiting, namespace) {
81
+ if (visiting.has(name))
82
+ return undefined;
83
+ const cached = this.#expansions.get(name);
84
+ if (cached !== undefined || this.#expansions.has(name))
85
+ return cached;
86
+ const expanded = this.#expandDeclaration(name, visiting, namespace);
87
+ this.#expansions.set(name, expanded);
88
+ return expanded;
89
+ }
90
+ #expandDeclaration(name, visiting, namespace) {
91
+ const declaration = this.scope.normalized.get(name);
92
+ if (declaration === undefined)
93
+ return undefined;
94
+ if ('match' in declaration)
95
+ return branchesOf(declaration.match, namespace);
96
+ const nested = new Set(visiting);
97
+ nested.add(name);
98
+ const { operator, operands: refs } = PolicyComposition.of(declaration);
99
+ const children = [];
100
+ for (const [index, ref] of refs.entries()) {
101
+ if (!this.scope.isLocalPolicy(ref))
102
+ return undefined;
103
+ const expanded = this.#expandedBranches(ref.name, nested, `${namespace}/${index}:${ref.name}`);
104
+ if (expanded === undefined)
105
+ return undefined;
106
+ children.push(expanded);
107
+ }
108
+ return operator === 'allOf' ? branchProduct(children) : capBranches(children.flat());
109
+ }
110
+ #constraintsAreSatisfiable(branch, variants, use) {
111
+ const terms = new Set(use.kind === 'object' ? ['subject', 'object'] : ['subject', 'source', 'target']);
112
+ for (const key of branch.variables.keys())
113
+ terms.add(key);
114
+ for (const key of branch.terms.keys())
115
+ terms.add(key);
116
+ for (const edge of branch.edges) {
117
+ terms.add(termKey(edge.pattern.source, edge.namespace));
118
+ terms.add(termKey(edge.pattern.target, edge.namespace));
119
+ }
120
+ const union = new UnionFind(terms);
121
+ for (const [left, right] of branch.equalities)
122
+ union.join(left, right);
123
+ for (const variant of variants) {
124
+ for (const [left, right] of variant.equalities)
125
+ union.join(left, right);
126
+ }
127
+ const constraints = new Map();
128
+ for (const variant of variants) {
129
+ for (const [term, accepts] of variant.constraints) {
130
+ const root = union.find(term);
131
+ const values = constraints.get(root) ?? [];
132
+ values.push(accepts);
133
+ constraints.set(root, values);
134
+ }
135
+ }
136
+ const groups = new Map();
137
+ for (const term of terms) {
138
+ const root = union.find(term);
139
+ const members = groups.get(root) ?? [];
140
+ members.push(term);
141
+ groups.set(root, members);
142
+ }
143
+ for (const [root, members] of groups) {
144
+ const endpointConstraints = constraints.get(root) ?? [];
145
+ let candidates = [{ kind: 'open', requirements: [] }];
146
+ for (const member of members) {
147
+ candidates = this.#applyInitial(candidates, member, branch, use);
148
+ if (candidates.length === 0)
149
+ return false;
150
+ }
151
+ for (const endpoint of endpointConstraints) {
152
+ candidates = this.#applyEndpoint(candidates, endpoint);
153
+ if (candidates.length === 0)
154
+ return false;
155
+ }
156
+ }
157
+ return true;
158
+ }
159
+ #applyInitial(candidates, term, branch, use) {
160
+ if (term === 'subject')
161
+ return this.#applyAnyNodeClass(candidates);
162
+ const contract = targetContract(term, use);
163
+ if (contract !== undefined) {
164
+ if (contract.kind === 'exact')
165
+ return this.#applyExact(candidates, contract.ref);
166
+ if (contract.kind === 'default') {
167
+ return this.#applyAnyNodeClass(candidates).filter((candidate) => candidate.kind !== 'exact' || this.#isNodeClass(candidate.ref));
168
+ }
169
+ return candidates;
170
+ }
171
+ const referenced = branch.terms.get(term);
172
+ if (referenced?.kind === 'ref') {
173
+ const contract = this.scope.referenceContract(referenced.ref);
174
+ return contract?.kind === 'exact' ? this.#applyExact(candidates, contract.ref) : [];
175
+ }
176
+ const selector = branch.variables.get(term);
177
+ if (selector === undefined)
178
+ return [];
179
+ if (selector.kind === 'exact')
180
+ return this.#applyExact(candidates, selector.class);
181
+ if (selector.kind === 'any')
182
+ return candidates;
183
+ return this.#applyRequirement(candidates, selector.class);
184
+ }
185
+ #applyExact(candidates, exact) {
186
+ const result = [];
187
+ for (const candidate of candidates) {
188
+ if (candidate.kind === 'exact') {
189
+ if (definitionRefIndex(candidate.ref) === definitionRefIndex(exact))
190
+ result.push(candidate);
191
+ }
192
+ else if (candidate.kind === 'node') {
193
+ if (this.#isNodeClass(exact) && this.#satisfiesLists(exact, candidate.lists)) {
194
+ result.push({ kind: 'exact', ref: exact });
195
+ }
196
+ }
197
+ else if (candidate.requirements.every((required) => this.#classExtends(exact, required))) {
198
+ result.push({ kind: 'exact', ref: exact });
199
+ }
200
+ }
201
+ return uniqueBy(result, candidateKey);
202
+ }
203
+ #applyAnyNodeClass(candidates) {
204
+ return uniqueBy(candidates.flatMap((candidate) => candidate.kind === 'exact' ? [candidate] : this.#nodeCandidates(candidate)), candidateKey);
205
+ }
206
+ #applyRequirement(candidates, required) {
207
+ const result = [];
208
+ for (const candidate of candidates) {
209
+ if (candidate.kind === 'exact') {
210
+ if (this.#classExtends(candidate.ref, required))
211
+ result.push(candidate);
212
+ }
213
+ else if (candidate.kind === 'node') {
214
+ result.push(...this.#inhabited([...candidate.lists, [required]]));
215
+ }
216
+ else {
217
+ result.push({
218
+ kind: 'open',
219
+ requirements: uniqueBy([...candidate.requirements, required], definitionRefIndex),
220
+ });
221
+ }
222
+ }
223
+ return uniqueBy(result, candidateKey);
224
+ }
225
+ #applyEndpoint(candidates, accepts) {
226
+ const result = [];
227
+ for (const candidate of candidates) {
228
+ if (candidate.kind === 'exact') {
229
+ if (this.#classSatisfiesEndpoint(candidate.ref, accepts))
230
+ result.push(candidate);
231
+ continue;
232
+ }
233
+ if (candidate.kind === 'node') {
234
+ if (accepts.length > 0)
235
+ result.push(...this.#inhabited([...candidate.lists, accepts]));
236
+ continue;
237
+ }
238
+ for (const accept of accepts) {
239
+ result.push({
240
+ kind: 'open',
241
+ requirements: uniqueBy([...candidate.requirements, accept], definitionRefIndex),
242
+ });
243
+ }
244
+ }
245
+ return uniqueBy(result, candidateKey);
246
+ }
247
+ #classSatisfiesEndpoint(candidate, accepts) {
248
+ return accepts.some((accept) => this.#classExtends(candidate, accept));
249
+ }
250
+ /** Whether `candidate` is the `required` Class or a same-kind descendant. */
251
+ #classExtends(candidate, required) {
252
+ const resolve = (ref) => this.scope.resolveClass(ref);
253
+ const actual = resolve(candidate);
254
+ const target = resolve(required);
255
+ return actual !== undefined && target !== undefined && classSatisfies(actual, target, resolve);
256
+ }
257
+ /**
258
+ * The Node Classes of the closure that satisfy one Class of `accepts`, in closure order: those
259
+ * `#classSatisfiesEndpoint` accepts, read from the index rather than tested one by one.
260
+ */
261
+ #satisfyingOneOf(accepts) {
262
+ const index = this.#nodeClassIndex();
263
+ const positions = new Set();
264
+ for (const accept of accepts) {
265
+ const required = this.scope.resolveClass(accept);
266
+ if (required?.kind !== 'node')
267
+ continue;
268
+ if (isGraphRoot(required))
269
+ return index.nodeClasses;
270
+ for (const position of index.satisfying.get(definitionRefIndex(required.ref)) ?? []) {
271
+ positions.add(position);
272
+ }
273
+ }
274
+ return [...positions].sort((left, right) => left - right).map((at) => index.nodeClasses[at]);
275
+ }
276
+ #satisfiesLists(ref, lists) {
277
+ return lists.every((accepts) => this.#classSatisfiesEndpoint(ref, accepts));
278
+ }
279
+ #isNodeClass(ref) {
280
+ return this.#nodeClassIndex().nodes.has(definitionRefIndex(ref));
281
+ }
282
+ /** The Node Classes an open or `node` candidate can be. */
283
+ #nodeCandidates(candidate) {
284
+ return candidate.kind === 'node'
285
+ ? [candidate]
286
+ : this.#inhabited(candidate.requirements.map((required) => [required]));
287
+ }
288
+ /**
289
+ * The `node` candidate of these lists when some Node Class of the closure satisfies them, so that
290
+ * an empty one is dropped where its expansion would have been empty. A witness is almost always a
291
+ * Class the lists name; only when none is does the search read the Classes that satisfy the
292
+ * narrowest list, every witness being one of them.
293
+ */
294
+ #inhabited(lists) {
295
+ const fits = (ref) => this.#isNodeClass(ref) && this.#satisfiesLists(ref, lists);
296
+ const inhabited = lists.some((accepts) => accepts.some(fits)) ||
297
+ (lists.length === 0
298
+ ? this.scope.allNodeClasses
299
+ : lists
300
+ .map((accepts) => this.#satisfyingOneOf(accepts))
301
+ .reduce((narrowest, next) => (next.length < narrowest.length ? next : narrowest))).some(fits);
302
+ return inhabited ? [{ kind: 'node', lists }] : [];
303
+ }
304
+ }
305
+ /**
306
+ * Index each Node Class of the closure under every Class its ancestry reaches, walked as
307
+ * `classSatisfies` walks it: the Class itself, then each declared parent that resolves to a Node
308
+ * Class. A Class then satisfies a non-root Node Class exactly when it is indexed under it.
309
+ * `classSatisfies` compares origin and name; every ClassRef has kind `class`, so the definition
310
+ * index of a ref keys it as that comparison does.
311
+ */
312
+ function nodeClassIndex(scope) {
313
+ const nodeClasses = [];
314
+ const satisfying = new Map();
315
+ for (const ref of scope.allNodeClasses) {
316
+ const actual = scope.resolveClass(ref);
317
+ if (actual?.kind !== 'node')
318
+ continue;
319
+ const position = nodeClasses.push(ref) - 1;
320
+ for (const key of ancestryKeys(actual, scope)) {
321
+ const positions = satisfying.get(key);
322
+ if (positions === undefined)
323
+ satisfying.set(key, [position]);
324
+ else
325
+ positions.push(position);
326
+ }
327
+ }
328
+ return {
329
+ nodeClasses,
330
+ nodes: new Set(nodeClasses.map(definitionRefIndex)),
331
+ concrete: new Set(scope.concreteNodeClasses.map(definitionRefIndex)),
332
+ satisfying,
333
+ };
334
+ }
335
+ /** The keys of the Node Classes a Node Class's ancestry reaches, itself included. */
336
+ function ancestryKeys(actual, scope) {
337
+ const seen = new Set();
338
+ const keys = new Set();
339
+ const pending = [actual];
340
+ for (let value = pending.pop(); value !== undefined; value = pending.pop()) {
341
+ if (seen.has(value))
342
+ continue;
343
+ seen.add(value);
344
+ keys.add(definitionRefIndex(value.ref));
345
+ for (const parent of value.extends) {
346
+ const resolved = scope.resolveClass(parent);
347
+ if (resolved?.kind === 'node')
348
+ pending.push(resolved);
349
+ }
350
+ }
351
+ return keys;
352
+ }
353
+ function targetContract(term, use) {
354
+ if (use.kind === 'object')
355
+ return term === 'object' ? use.object : undefined;
356
+ if (term === 'source')
357
+ return use.source;
358
+ if (term === 'target')
359
+ return use.target;
360
+ return undefined;
361
+ }
362
+ function edgeAlternatives(edges, typing) {
363
+ let result = [[]];
364
+ for (const edge of edges) {
365
+ const variants = variantsForEdge(edge, typing);
366
+ if (variants.length === 0)
367
+ return [];
368
+ const next = [];
369
+ for (const prefix of result) {
370
+ for (const variant of variants)
371
+ next.push([...prefix, variant]);
372
+ }
373
+ result = next;
374
+ }
375
+ return result;
376
+ }
377
+ function variantsForEdge(use, typing) {
378
+ const edge = use.pattern;
379
+ const declaration = typing.scope.edgeDeclaration(edge.class);
380
+ if (declaration === undefined)
381
+ return [];
382
+ const endpoints = endpointPair(declaration);
383
+ const bounds = edge.repeat ?? { min: 1, max: 1 };
384
+ if (!Number.isInteger(bounds.min) ||
385
+ !Number.isInteger(bounds.max) ||
386
+ bounds.min < 0 ||
387
+ bounds.max < bounds.min ||
388
+ bounds.max > limits.policy.repetition) {
389
+ return [];
390
+ }
391
+ const sourceKey = termKey(edge.source, use.namespace);
392
+ const targetKey = termKey(edge.target, use.namespace);
393
+ const variants = [];
394
+ for (let length = bounds.min; length <= bounds.max; length++) {
395
+ if (length === 0) {
396
+ variants.push({ constraints: [], equalities: [[sourceKey, targetKey]] });
397
+ continue;
398
+ }
399
+ const orientationCount = declaration.orientation === 'undirected' ? 2 ** length : 1;
400
+ for (let mask = 0; mask < orientationCount; mask++) {
401
+ const orientations = Array.from({ length }, (_, index) => declaration.orientation === 'undirected' && (mask & (1 << index)) !== 0);
402
+ let transitionsValid = true;
403
+ for (let index = 0; index + 1 < length; index++) {
404
+ const incoming = endEndpoint(endpoints, orientations[index] ?? false);
405
+ const outgoing = startEndpoint(endpoints, orientations[index + 1] ?? false);
406
+ if (!typing.endpointsOverlap(incoming.accepts, outgoing.accepts)) {
407
+ transitionsValid = false;
408
+ break;
409
+ }
410
+ }
411
+ if (!transitionsValid)
412
+ continue;
413
+ const first = startEndpoint(endpoints, orientations[0] ?? false);
414
+ const last = endEndpoint(endpoints, orientations[length - 1] ?? false);
415
+ variants.push({
416
+ constraints: [
417
+ [sourceKey, first.accepts],
418
+ [targetKey, last.accepts],
419
+ ],
420
+ equalities: [],
421
+ });
422
+ }
423
+ }
424
+ return uniqueBy(variants, edgeVariantKey);
425
+ }
426
+ /** The two endpoints of an Edge Class, a directed one's as source then target. */
427
+ function endpointPair(declaration) {
428
+ return declaration.orientation === 'directed'
429
+ ? [declaration.endpoints.source, declaration.endpoints.target]
430
+ : declaration.endpoints;
431
+ }
432
+ function startEndpoint(endpoints, reversed) {
433
+ return reversed ? endpoints[1] : endpoints[0];
434
+ }
435
+ function endEndpoint(endpoints, reversed) {
436
+ return reversed ? endpoints[0] : endpoints[1];
437
+ }
438
+ /** The values with distinct keys, each at its key's first position and holding its last value. */
439
+ function uniqueBy(values, key) {
440
+ return [...new Map(values.map((value) => [key(value), value])).values()];
441
+ }
442
+ function edgeVariantKey(variant) {
443
+ const constraints = variant.constraints.map(([term, accepts]) => `${term}:${classSetKey(accepts)}`);
444
+ const equalities = variant.equalities.map(([left, right]) => `${left}:${right}`);
445
+ return `${constraints.join('|')}=${equalities.join('|')}`;
446
+ }
447
+ function candidateKey(candidate) {
448
+ if (candidate.kind === 'exact')
449
+ return `exact:${definitionRefIndex(candidate.ref)}`;
450
+ if (candidate.kind === 'open')
451
+ return `open:${classSetKey(candidate.requirements)}`;
452
+ return `node:${candidate.lists.map(classSetKey).sort().join('|')}`;
453
+ }
454
+ function classSetKey(refs) {
455
+ return refs.map(definitionRefIndex).sort().join(',');
456
+ }
@@ -65,20 +65,42 @@ export interface PolicyEdgePattern {
65
65
  }
66
66
  export type PolicyPatternExpression = PolicyEdgePattern | PolicySameNode<PolicyPatternTerm> | {
67
67
  readonly exists: {
68
- readonly nodes: readonly PolicyVariable[];
68
+ readonly nodes: readonly [PolicyVariable, ...PolicyVariable[]];
69
69
  readonly where: PolicyPatternExpression;
70
70
  };
71
71
  } | {
72
- readonly allOf: readonly PolicyPatternExpression[];
72
+ readonly allOf: readonly [PolicyPatternExpression, ...PolicyPatternExpression[]];
73
73
  } | {
74
- readonly anyOf: readonly PolicyPatternExpression[];
74
+ readonly anyOf: readonly [PolicyPatternExpression, ...PolicyPatternExpression[]];
75
75
  };
76
+ /**
77
+ * A composition of a Pattern, a named Policy or Policy checks, read through its operator: `allOf`
78
+ * holds where every operand holds, `anyOf` where one does. It is stored under the one key its
79
+ * operator names; every reader takes the operator and the operands from here.
80
+ */
81
+ export declare namespace PolicyComposition {
82
+ type Operator = 'allOf' | 'anyOf';
83
+ type Operands<Operand> = readonly [Operand, ...Operand[]];
84
+ /** The stored form: the operands under the key their operator names. */
85
+ type Stored<Operand> = {
86
+ readonly allOf: Operands<Operand>;
87
+ } | {
88
+ readonly anyOf: Operands<Operand>;
89
+ };
90
+ function is<Value extends object>(value: Value): value is Extract<Value, Stored<unknown>>;
91
+ function of<Operand>(composition: Stored<Operand>): {
92
+ readonly operator: Operator;
93
+ readonly operands: Operands<Operand>;
94
+ };
95
+ /** Store `operands` under the key `operator` names. */
96
+ function from<Operand>(operator: Operator, operands: Operands<Operand>): Stored<Operand>;
97
+ }
76
98
  export type PolicyExpression = {
77
99
  readonly match: PolicyPatternExpression;
78
100
  } | {
79
- readonly allOf: readonly PolicyRef[];
101
+ readonly allOf: readonly [PolicyRef, ...PolicyRef[]];
80
102
  } | {
81
- readonly anyOf: readonly PolicyRef[];
103
+ readonly anyOf: readonly [PolicyRef, ...PolicyRef[]];
82
104
  };
83
105
  export interface PolicyDefinition extends DefinitionBase<PolicyRef> {
84
106
  readonly expression: PolicyExpression;
@@ -90,23 +112,63 @@ export type PolicyObjectRef = ClassRef | FunctionRef | PolicyRef | ViewRef | Cor
90
112
  export declare function policyObjectKey(ref: PolicyObjectRef): string;
91
113
  export declare function policyObjectOrigin(ref: PolicyObjectRef): string;
92
114
  export declare function projectedMemberClass(ref: Exclude<PolicyObjectRef, CoreRef>): ClassRef;
115
+ export type ClassObservation = 'read' | 'traverse';
116
+ export type ClassWrite = 'create' | 'update' | 'delete';
117
+ export type ClassOperation = ClassObservation | ClassWrite;
118
+ /**
119
+ * Every Class slot: the observations, which admit every caller when absent, then the writes, which
120
+ * admit only the Domain that declares the Class when absent.
121
+ */
122
+ export declare const CLASS_OPERATIONS: readonly ClassOperation[];
123
+ export declare function isClassObservation(operation: ClassOperation): operation is ClassObservation;
93
124
  /**
94
125
  * One Class observation slot: a named Policy, or `false`, the rule no caller satisfies. Its other
95
126
  * value has no spelling there: an absent observation Policy already means `true`.
96
127
  */
97
128
  export type ClassPolicy = PolicyRef | false;
98
- /** What a Node Class rule may check: the observed Node, or one exact projected member. */
129
+ /**
130
+ * One Class write slot: a named Policy, or `true`, the rule every Identity satisfies. Its other
131
+ * value has no spelling there: an absent write Policy already means the owning Domain only.
132
+ */
133
+ export type ClassWritePolicy = PolicyRef | true;
134
+ /** What a Class rule may check: the observed or written instance, or one exact projected member. */
99
135
  export type ClassRuleObject = Extract<PolicyCheckObject, {
100
136
  readonly kind: 'self' | 'ref';
101
137
  }>;
102
138
  /**
103
- * Policy checks deciding one Node Class observation. `self` is the observed Node; a `ref` object
104
- * is the same Node for every candidate. A lone check of `self` is spelled as its Policy reference.
139
+ * Policy checks deciding one Node Class slot. `self` is the observed or written Node; a `ref`
140
+ * object is the same Node for every candidate. A lone check of `self` is spelled as its Policy
141
+ * reference.
105
142
  */
106
143
  export type ClassRuleChecks = PolicyCheckExpression<PolicyRef, ClassRuleObject>;
144
+ /**
145
+ * Policy checks deciding one Edge Class slot. `self` is the observed or written Edge, checked by a
146
+ * Policy whose source and target are its endpoints; a `ref` object is one exact member, the same
147
+ * Node for every candidate. A lone check of `self` is spelled as its Policy reference.
148
+ */
149
+ export type EdgeRuleChecks = ClassRuleChecks;
150
+ /** What a Node create rule may check: one exact projected member, since the Node is not yet. */
151
+ export type CreateRuleObject = Extract<PolicyCheckObject, {
152
+ readonly kind: 'ref';
153
+ }>;
154
+ /** Policy checks deciding the creation of a Node: every object is a `ref` member. */
155
+ export type CreateRuleChecks = PolicyCheckExpression<PolicyRef, CreateRuleObject>;
107
156
  /** One Node Class observation slot: a Class Policy, or Policy checks over the observed Node. */
108
157
  export type NodeClassPolicy = ClassPolicy | ClassRuleChecks;
109
- export declare function isClassRuleChecks(value: ClassPolicy | ClassRuleChecks | undefined): value is ClassRuleChecks;
158
+ /** One Node Class update or delete slot: a write Policy, or Policy checks over the written Node. */
159
+ export type NodeClassWritePolicy = ClassWritePolicy | ClassRuleChecks;
160
+ /**
161
+ * The Node Class create slot: `true`, or Policy checks over members. A named Policy alone has no
162
+ * object there, so it has no spelling.
163
+ */
164
+ export type NodeClassCreatePolicy = true | CreateRuleChecks;
165
+ /** One Edge Class observation slot: a Class Policy, or Policy checks over the observed Edge. */
166
+ export type EdgeClassPolicy = ClassPolicy | EdgeRuleChecks;
167
+ /** One Edge Class write slot: a write Policy, or Policy checks over the written Edge. */
168
+ export type EdgeClassWritePolicy = ClassWritePolicy | EdgeRuleChecks;
169
+ /** The value of any Class slot. */
170
+ export type ClassSlotPolicy = PolicyRef | boolean | ClassRuleChecks;
171
+ export declare function isClassRuleChecks(value: ClassSlotPolicy | undefined): value is ClassRuleChecks;
110
172
  /**
111
173
  * Whether every way Policy checks can hold passes through a check, so that the caller decides each
112
174
  * admission. `sameNode` compares two objects and names no caller.