@astrale-os/kernel-dsl 1.0.0-beta.2 → 1.0.0-beta.20

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 (307) 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 +4 -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 +31 -33
  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 +5 -2
  24. package/dist/v1/builder/lowering/callable.js +1 -0
  25. package/dist/v1/builder/lowering/class.d.ts +9 -1
  26. package/dist/v1/builder/lowering/class.js +62 -17
  27. package/dist/v1/builder/lowering/policy.js +2 -0
  28. package/dist/v1/builder/lowering/property-keys.d.ts +27 -0
  29. package/dist/v1/builder/lowering/property-keys.js +108 -0
  30. package/dist/v1/builder/lowering/schema/compile.js +11 -6
  31. package/dist/v1/builder/lowering/schema/context.d.ts +9 -1
  32. package/dist/v1/builder/lowering/schema/context.js +36 -4
  33. package/dist/v1/builder/lowering/schema/lifetime.d.ts +11 -0
  34. package/dist/v1/builder/lowering/schema/lifetime.js +55 -0
  35. package/dist/v1/builder/lowering/value/path.d.ts +1 -1
  36. package/dist/v1/builder/lowering/value/path.js +2 -4
  37. package/dist/v1/builder/lowering/value/zod.js +1 -3
  38. package/dist/v1/builder/policy/authoring.d.ts +85 -5
  39. package/dist/v1/builder/policy/authoring.js +107 -68
  40. package/dist/v1/builder/schema/define.d.ts +0 -1
  41. package/dist/v1/builder/schema/diagnostic.d.ts +3 -2
  42. package/dist/v1/builder/schema/diagnostic.js +5 -10
  43. package/dist/v1/builder/schema/input.d.ts +1 -1
  44. package/dist/v1/builder/schema/projection/callable.d.ts +7 -5
  45. package/dist/v1/builder/schema/projection/class.d.ts +118 -15
  46. package/dist/v1/builder/schema/projection/core-input.d.ts +2 -1
  47. package/dist/v1/builder/schema/projection/identity.d.ts +2 -1
  48. package/dist/v1/builder/schema/projection/model.d.ts +4 -2
  49. package/dist/v1/builder/schema/projection/property.d.ts +1 -1
  50. package/dist/v1/builder/schema/projection/resolved-class.d.ts +2 -1
  51. package/dist/v1/builder/schema/projection.d.ts +1 -1
  52. package/dist/v1/builder/value/full-match.d.ts +0 -1
  53. package/dist/v1/builder/value/full-match.js +0 -1
  54. package/dist/v1/builder/value/path-metadata.d.ts +1 -1
  55. package/dist/v1/builder/value/path.d.ts +1 -1
  56. package/dist/v1/bundle/codec.js +11 -13
  57. package/dist/v1/bundle/diagnostic.d.ts +2 -0
  58. package/dist/v1/bundle/diagnostic.js +9 -7
  59. package/dist/v1/bundle/model.js +1 -1
  60. package/dist/v1/bundle/structure.js +4 -6
  61. package/dist/v1/compiled/admission/accept.js +4 -10
  62. package/dist/v1/compiled/admission/closure.js +2 -2
  63. package/dist/v1/compiled/admission/diagnostic.d.ts +1 -1
  64. package/dist/v1/compiled/admission/diagnostic.js +1 -3
  65. package/dist/v1/compiled/admission/revision.d.ts +9 -1
  66. package/dist/v1/compiled/admission/revision.js +6 -3
  67. package/dist/v1/compiled/admission/semantics/class.d.ts +4 -1
  68. package/dist/v1/compiled/admission/semantics/class.js +37 -12
  69. package/dist/v1/compiled/admission/semantics/core.d.ts +1 -24
  70. package/dist/v1/compiled/admission/semantics/core.js +56 -24
  71. package/dist/v1/compiled/admission/semantics/edge.d.ts +2 -4
  72. package/dist/v1/compiled/admission/semantics/edge.js +6 -65
  73. package/dist/v1/compiled/admission/semantics/policy/callable.js +0 -2
  74. package/dist/v1/compiled/admission/semantics/policy/contracts.d.ts +5 -20
  75. package/dist/v1/compiled/admission/semantics/policy/contracts.js +8 -21
  76. package/dist/v1/compiled/admission/semantics/policy/parity.js +40 -43
  77. package/dist/v1/compiled/admission/semantics/policy/pattern.d.ts +4 -1
  78. package/dist/v1/compiled/admission/semantics/policy/pattern.js +4 -16
  79. package/dist/v1/compiled/admission/semantics/policy/typing.d.ts +2 -24
  80. package/dist/v1/compiled/admission/semantics/policy/typing.js +19 -201
  81. package/dist/v1/compiled/admission/wire/callable.js +11 -1
  82. package/dist/v1/compiled/admission/wire/class.js +73 -21
  83. package/dist/v1/compiled/admission/wire/policy.d.ts +4 -3
  84. package/dist/v1/compiled/admission/wire/policy.js +8 -7
  85. package/dist/v1/compiled/compiler/compile.js +8 -8
  86. package/dist/v1/compiled/diagnostic.js +2 -3
  87. package/dist/v1/compiled/loader/load.d.ts +3 -2
  88. package/dist/v1/compiled/loader/load.js +11 -45
  89. package/dist/v1/domain/create.js +5 -6
  90. package/dist/v1/domain/model/domain.d.ts +2 -7
  91. package/dist/v1/domain/model/input.d.ts +2 -1
  92. package/dist/v1/domain/namespace/member-collection.js +4 -6
  93. package/dist/v1/domain/projection/classes.js +4 -1
  94. package/dist/v1/domain/validation/create.d.ts +6 -3
  95. package/dist/v1/domain/validation/create.js +21 -69
  96. package/dist/v1/index.d.ts +2 -1
  97. package/dist/v1/language/.spec/schemas/draft-2020-12.schema.json +462 -0
  98. package/dist/v1/language/.spec/schemas/value-schema.schema.json +22 -0
  99. package/dist/v1/language/callable/admission.d.ts +15 -0
  100. package/dist/v1/language/callable/admission.js +43 -0
  101. package/dist/v1/language/callable/model/callable.d.ts +10 -0
  102. package/dist/v1/language/callable/resolved.d.ts +16 -3
  103. package/dist/v1/language/class/inheritance.d.ts +36 -5
  104. package/dist/v1/language/class/inheritance.js +87 -1
  105. package/dist/v1/language/class/lifetime.d.ts +50 -11
  106. package/dist/v1/language/class/lifetime.js +89 -20
  107. package/dist/v1/language/class/model/class.d.ts +45 -9
  108. package/dist/v1/language/class/model/edge.d.ts +31 -2
  109. package/dist/v1/language/class/model/property.d.ts +16 -7
  110. package/dist/v1/language/class/property-values.js +2 -4
  111. package/dist/v1/language/class/unique.d.ts +143 -0
  112. package/dist/v1/language/class/unique.js +264 -0
  113. package/dist/v1/language/core/facts.d.ts +85 -0
  114. package/dist/v1/language/core/facts.js +116 -0
  115. package/dist/v1/language/definition/metadata.d.ts +5 -0
  116. package/dist/v1/language/definition/metadata.js +7 -0
  117. package/dist/v1/language/freeze.d.ts +5 -0
  118. package/dist/v1/{schema/canonical → language}/freeze.js +4 -0
  119. package/dist/v1/language/index.d.ts +7 -2
  120. package/dist/v1/language/index.js +5 -1
  121. package/dist/v1/language/limits.d.ts +64 -0
  122. package/dist/v1/language/limits.js +60 -0
  123. package/dist/v1/language/policy/analysis/branches.d.ts +8 -0
  124. package/dist/v1/language/policy/analysis/branches.js +2 -1
  125. package/dist/v1/language/policy/analysis/budgets.d.ts +45 -12
  126. package/dist/v1/language/policy/analysis/budgets.js +133 -19
  127. package/dist/v1/language/policy/analysis/checks.js +3 -2
  128. package/dist/v1/language/policy/analysis/typing.d.ts +51 -0
  129. package/dist/v1/language/policy/analysis/typing.js +455 -0
  130. package/dist/v1/language/policy/model/policy.d.ts +49 -9
  131. package/dist/v1/language/policy/model/policy.js +14 -0
  132. package/dist/v1/language/policy/normalization/normalize.d.ts +6 -6
  133. package/dist/v1/language/policy/normalization/normalize.js +22 -21
  134. package/dist/v1/language/validation/diagnostic.d.ts +15 -1
  135. package/dist/v1/language/validation/diagnostic.js +21 -0
  136. package/dist/v1/language/validation/rule.d.ts +45 -0
  137. package/dist/v1/language/validation/rule.js +109 -0
  138. package/dist/v1/language/value/compile/fields.js +4 -8
  139. package/dist/v1/language/value/evaluate/program.d.ts +2 -1
  140. package/dist/v1/language/value/evaluate/program.js +2 -2
  141. package/dist/v1/language/value/evaluate/validate.d.ts +2 -2
  142. package/dist/v1/language/value/evaluate/validate.js +6 -2
  143. package/dist/v1/language/value/evaluate/validity.optimization.d.ts +14 -0
  144. package/dist/v1/language/value/evaluate/validity.optimization.js +342 -0
  145. package/dist/v1/language/value/inclusion/arrays.d.ts +3 -0
  146. package/dist/v1/language/value/inclusion/arrays.js +85 -0
  147. package/dist/v1/language/value/inclusion/assertions.d.ts +18 -0
  148. package/dist/v1/language/value/inclusion/assertions.js +29 -0
  149. package/dist/v1/language/value/inclusion/combinators.d.ts +3 -0
  150. package/dist/v1/language/value/inclusion/combinators.js +67 -0
  151. package/dist/v1/language/value/inclusion/equivalence.d.ts +4 -0
  152. package/dist/v1/language/value/inclusion/equivalence.js +74 -0
  153. package/dist/v1/language/value/inclusion/evidence.d.ts +34 -0
  154. package/dist/v1/language/value/inclusion/evidence.js +138 -0
  155. package/dist/v1/language/value/inclusion/includes.d.ts +17 -0
  156. package/dist/v1/language/value/inclusion/includes.js +25 -719
  157. package/dist/v1/language/value/inclusion/keywords.d.ts +5 -0
  158. package/dist/v1/language/value/inclusion/keywords.js +31 -0
  159. package/dist/v1/language/value/inclusion/kinds.d.ts +17 -0
  160. package/dist/v1/language/value/inclusion/kinds.js +57 -0
  161. package/dist/v1/language/value/inclusion/location.d.ts +24 -0
  162. package/dist/v1/language/value/inclusion/location.js +63 -0
  163. package/dist/v1/language/value/inclusion/numbers.d.ts +3 -0
  164. package/dist/v1/language/value/inclusion/numbers.js +41 -0
  165. package/dist/v1/language/value/inclusion/objects.d.ts +3 -0
  166. package/dist/v1/language/value/inclusion/objects.js +190 -0
  167. package/dist/v1/language/value/inclusion/strings.d.ts +3 -0
  168. package/dist/v1/language/value/inclusion/strings.js +29 -0
  169. package/dist/v1/language/value/inclusion/types.d.ts +3 -0
  170. package/dist/v1/language/value/inclusion/types.js +11 -0
  171. package/dist/v1/language/value/ordering.d.ts +14 -0
  172. package/dist/v1/language/value/ordering.js +86 -9
  173. package/dist/v1/language/value/profile/canonicalize.js +6 -5
  174. package/dist/v1/language/value/profile/json.validate.d.ts +3 -1
  175. package/dist/v1/language/value/profile/json.validate.js +3 -2
  176. package/dist/v1/language/value/profile/meta-schema.compiled.js +4 -1
  177. package/dist/v1/language/value/profile/rules.js +17 -43
  178. package/dist/v1/language/value/profile/validate.js +1 -10
  179. package/dist/v1/language/value/profile/vocabulary.d.ts +35 -2
  180. package/dist/v1/language/value/profile/vocabulary.js +52 -5
  181. package/dist/v1/language/value/reference/closure.js +3 -4
  182. package/dist/v1/language/value/reference/recursion.js +2 -22
  183. package/dist/v1/language/value/reference/registry.index.d.ts +2 -0
  184. package/dist/v1/language/value/reference/registry.index.js +33 -16
  185. package/dist/v1/language/value/regexp/ast.js +6 -7
  186. package/dist/v1/language/value/regexp/compile.d.ts +5 -11
  187. package/dist/v1/language/value/regexp/compile.js +14 -12
  188. package/dist/v1/language/value/regexp/syntax.js +3 -2
  189. package/dist/v1/language/value/syntax/keywords.d.ts +3 -3
  190. package/dist/v1/language/value/syntax/keywords.js +4 -20
  191. package/dist/v1/language/value/syntax/node-path/validate.js +2 -3
  192. package/dist/v1/language/value/syntax/pointer.d.ts +2 -0
  193. package/dist/v1/language/value/syntax/pointer.js +5 -2
  194. package/dist/v1/language/value/syntax/walk.d.ts +2 -0
  195. package/dist/v1/language/value/syntax/walk.js +19 -20
  196. package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +2519 -0
  197. package/dist/v1/schema/admission/accept.js +3 -14
  198. package/dist/v1/schema/admission/callable.d.ts +21 -0
  199. package/dist/v1/schema/admission/callable.js +96 -0
  200. package/dist/v1/schema/analysis/class.js +33 -15
  201. package/dist/v1/schema/canonical/revision.js +4 -4
  202. package/dist/v1/schema/compatibility/api.d.ts +2 -1
  203. package/dist/v1/schema/compatibility/api.js +1 -0
  204. package/dist/v1/schema/compatibility/comparators/callables.js +1 -1
  205. package/dist/v1/schema/compatibility/comparators/classes.d.ts +9 -4
  206. package/dist/v1/schema/compatibility/comparators/classes.js +29 -8
  207. package/dist/v1/schema/compatibility/comparators/index.d.ts +1 -1
  208. package/dist/v1/schema/compatibility/comparators/members.js +1 -1
  209. package/dist/v1/schema/compatibility/comparators/values.js +2 -2
  210. package/dist/v1/schema/compatibility/coordinate.js +3 -3
  211. package/dist/v1/schema/compatibility/diff.js +2 -4
  212. package/dist/v1/schema/compatibility/extension.d.ts +11 -0
  213. package/dist/v1/schema/compatibility/extension.js +22 -0
  214. package/dist/v1/schema/compatibility/fields.d.ts +20 -4
  215. package/dist/v1/schema/compatibility/fields.js +13 -3
  216. package/dist/v1/schema/compatibility/meaning/footprint.js +16 -50
  217. package/dist/v1/schema/compatibility/model.d.ts +17 -5
  218. package/dist/v1/schema/compatibility/report.js +1 -1
  219. package/dist/v1/schema/compatibility/scope.d.ts +2 -0
  220. package/dist/v1/schema/compatibility/scope.js +4 -1
  221. package/dist/v1/schema/compatibility/structure/index.js +6 -4
  222. package/dist/v1/schema/compatibility/structure/requirements.js +57 -58
  223. package/dist/v1/schema/compatibility/versioning/index.js +1 -1
  224. package/dist/v1/schema/compatibility/versioning/surface.d.ts +1 -1
  225. package/dist/v1/schema/compatibility/versioning/surface.js +30 -2
  226. package/dist/v1/schema/compatibility/walk.d.ts +17 -0
  227. package/dist/v1/schema/compatibility/walk.js +41 -0
  228. package/dist/v1/schema/diagnostic.d.ts +17 -3
  229. package/dist/v1/schema/diagnostic.js +14 -11
  230. package/dist/v1/schema/index.d.ts +10 -1
  231. package/dist/v1/schema/index.js +4 -0
  232. package/dist/v1/schema/model/schema.d.ts +20 -1
  233. package/dist/v1/schema/model/schema.js +1 -1
  234. package/dist/v1/schema/normalization/domain.d.ts +2 -0
  235. package/dist/v1/schema/normalization/domain.js +29 -9
  236. package/dist/v1/schema/resolution/closure.js +2 -1
  237. package/dist/v1/schema/resolution/context.js +13 -13
  238. package/dist/v1/schema/resolution/domain.d.ts +5 -0
  239. package/dist/v1/schema/resolution/domain.js +2 -2
  240. package/dist/v1/schema/resolution/origins.js +3 -2
  241. package/dist/v1/schema/rule.d.ts +26 -0
  242. package/dist/v1/schema/rule.js +440 -0
  243. package/dist/v1/schema/validation/callable.d.ts +35 -2
  244. package/dist/v1/schema/validation/callable.js +65 -9
  245. package/dist/v1/schema/validation/class.d.ts +6 -2
  246. package/dist/v1/schema/validation/class.js +127 -104
  247. package/dist/v1/schema/validation/core.js +90 -168
  248. package/dist/v1/schema/validation/domain.js +4 -13
  249. package/dist/v1/schema/validation/domain.json-schema.d.ts +15 -0
  250. package/dist/v1/schema/validation/domain.json-schema.js +197 -0
  251. package/dist/v1/schema/validation/domain.route.d.ts +6 -1
  252. package/dist/v1/schema/validation/domain.route.js +18 -0
  253. package/dist/v1/schema/validation/domain.structure.d.ts +7780 -0
  254. package/dist/v1/schema/validation/domain.structure.js +398 -147
  255. package/dist/v1/schema/validation/json.json-schema.d.ts +40 -0
  256. package/dist/v1/schema/validation/json.json-schema.js +46 -0
  257. package/dist/v1/schema/validation/policy/budgets.d.ts +33 -2
  258. package/dist/v1/schema/validation/policy/budgets.js +87 -121
  259. package/dist/v1/schema/validation/policy/context.d.ts +6 -5
  260. package/dist/v1/schema/validation/policy/context.js +7 -10
  261. package/dist/v1/schema/validation/policy/objects.d.ts +1 -1
  262. package/dist/v1/schema/validation/policy/objects.js +6 -14
  263. package/dist/v1/schema/validation/policy/references.js +11 -27
  264. package/dist/v1/schema/validation/policy/typing.d.ts +3 -18
  265. package/dist/v1/schema/validation/policy/typing.js +22 -356
  266. package/dist/v1/schema/validation/policy/uses.d.ts +40 -3
  267. package/dist/v1/schema/validation/policy/uses.js +66 -89
  268. package/dist/v1/schema/validation/policy/validate.js +5 -5
  269. package/dist/v1/schema/validation/value-api.d.ts +22 -0
  270. package/dist/v1/schema/validation/value-api.js +34 -1
  271. package/dist/v1/schema/validation/value.d.ts +3 -0
  272. package/dist/v1/schema/validation/value.js +9 -17
  273. package/dist/v1/schema/validation/value.json-schema.d.ts +49 -0
  274. package/dist/v1/schema/validation/value.json-schema.js +137 -0
  275. package/dist/v1/schema/validation/view.js +4 -8
  276. package/dist/value/canonical.d.ts +6 -0
  277. package/dist/value/canonical.js +36 -0
  278. package/dist/value/decode.d.ts +7 -0
  279. package/dist/value/decode.js +159 -9
  280. package/dist/value/index.d.ts +1 -1
  281. package/dist/value/json.d.ts +2 -2
  282. package/dist/value/json.js +2 -2
  283. package/dist/value/types.d.ts +6 -0
  284. package/dist/value/unicode.d.ts +2 -1
  285. package/dist/value/unicode.js +2 -0
  286. package/package.json +8 -1
  287. package/dist/v1/builder/lowering/core-properties.d.ts +0 -10
  288. package/dist/v1/builder/lowering/core-properties.js +0 -76
  289. package/dist/v1/compiled/admission/semantics/cardinality.d.ts +0 -5
  290. package/dist/v1/compiled/admission/semantics/cardinality.js +0 -113
  291. package/dist/v1/compiled/admission/semantics/policy/equality.d.ts +0 -8
  292. package/dist/v1/compiled/admission/semantics/policy/equality.js +0 -27
  293. package/dist/v1/compiled/admission/semantics/policy/measure.d.ts +0 -9
  294. package/dist/v1/compiled/admission/semantics/policy/measure.js +0 -81
  295. package/dist/v1/compiled/admission/semantics/policy/variants.d.ts +0 -10
  296. package/dist/v1/compiled/admission/semantics/policy/variants.js +0 -65
  297. package/dist/v1/language/class/index.d.ts +0 -8
  298. package/dist/v1/language/class/index.js +0 -1
  299. package/dist/v1/language/core/index.d.ts +0 -2
  300. package/dist/v1/language/value/index.d.ts +0 -11
  301. package/dist/v1/language/value/index.js +0 -8
  302. package/dist/v1/schema/canonical/domain.d.ts +0 -3
  303. package/dist/v1/schema/canonical/domain.digest.d.ts +0 -3
  304. package/dist/v1/schema/canonical/domain.digest.js +0 -5
  305. package/dist/v1/schema/canonical/domain.js +0 -5
  306. package/dist/v1/schema/canonical/freeze.d.ts +0 -1
  307. /package/dist/v1/{language/core/index.js → builder/class/input.js} +0 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The limits of the V1 language, each defined once: every check of a source Schema, a Bundle or a
3
+ * compiled closure reads its bound here. Every limit is inclusive: a count equal to it is
4
+ * accepted, one more is refused. `schema.limits` publishes this object, and each rule of
5
+ * `schema.RULES` and `schema.values.RULES` that enforces some of them names them in `limits`.
6
+ */
7
+ export const limits = Object.freeze({
8
+ /** Bounds of the dependency graph of one Domain (`DV_DEPENDENCY_LIMITS`). */
9
+ dependency: Object.freeze({
10
+ /** Direct dependencies one Domain declares. */
11
+ direct: 32,
12
+ /** Domains of a dependency closure, the Domain itself included. */
13
+ closure: 256,
14
+ /** Dependencies on the longest chain from a Domain: a direct dependency is at depth 1. */
15
+ depth: 32,
16
+ }),
17
+ /** Bounds of one I-Regexp in a value schema (`VS_REGEX_PORTABLE`), as RFC 9485 §8 allows. */
18
+ regexp: Object.freeze({
19
+ /** Code points of one source. */
20
+ maxCodePoints: 4096,
21
+ /** Groups nested in one another in one source. */
22
+ maxNesting: 32,
23
+ /** The greatest bound of a counted repetition `{n}` or `{n,m}`. */
24
+ maxRepeat: 1000,
25
+ /** States of one compiled machine; the counted-run form never expands and is not bounded. */
26
+ maxStates: 10_000,
27
+ }),
28
+ /**
29
+ * Bounds of the Policy language. A named Policy is measured once normalized and once each
30
+ * composition is expanded into the Policies it names; a check tree, the checks of a callable or
31
+ * of a Node Class rule, once normalized (`PL_BUDGET`). The structure bounds the others
32
+ * (`STRUCTURE_MAXIMUM`).
33
+ */
34
+ policy: Object.freeze({
35
+ /**
36
+ * Levels of a Policy pattern: an Edge or sameNode is one, and each allOf, anyOf, exists and
37
+ * composition adds one.
38
+ */
39
+ patternDepth: 4,
40
+ /**
41
+ * Branches of a Policy's normal form: an anyOf adds those of its operands, an allOf multiplies
42
+ * them.
43
+ */
44
+ normalizedBranches: 8,
45
+ /** Nodes one exists declares. */
46
+ variablesPerExists: 4,
47
+ /** Graph predicates, Edges and sameNode equalities, of one normalized branch. */
48
+ edgePredicates: 6,
49
+ /** The greatest bound of a repeated Edge. */
50
+ repetition: 3,
51
+ /** Domains a Policy names: its own, and the origin of every Class and object it references. */
52
+ referencedDomains: 4,
53
+ /** Levels of a check tree: a check or sameNode is one, and each allOf and anyOf adds one. */
54
+ checkDepth: 4,
55
+ /** Branches of a check tree: an anyOf adds those of its operands, an allOf multiplies them. */
56
+ checkBranches: 8,
57
+ /** Checks and sameNode equalities of a check tree. */
58
+ checkLeaves: 8,
59
+ }),
60
+ });
@@ -18,3 +18,11 @@ export declare function capBranches(values: readonly PatternBranch[]): readonly
18
18
  export declare function isConnected(branch: PatternBranch): boolean;
19
19
  export declare function targetMode(branch: PatternBranch): PolicyTargetMode | undefined;
20
20
  export declare function termKey(term: PolicyPatternTerm, namespace: string): string;
21
+ /** Disjoint sets of term keys, merged by the equalities of one Policy branch. */
22
+ export declare class UnionFind {
23
+ #private;
24
+ constructor(values: Iterable<string>);
25
+ add(value: string): void;
26
+ find(value: string): string;
27
+ join(left: string, right: string): void;
28
+ }
@@ -146,7 +146,8 @@ function collectVariableClasses(pattern, namespace) {
146
146
  function variableKey(namespace, id) {
147
147
  return `variable:${namespace}:${id}`;
148
148
  }
149
- class UnionFind {
149
+ /** Disjoint sets of term keys, merged by the equalities of one Policy branch. */
150
+ export class UnionFind {
150
151
  #parents = new Map();
151
152
  constructor(values) {
152
153
  for (const value of values)
@@ -1,16 +1,49 @@
1
- import type { PolicyCheckExpression } from '../model/policy.js';
2
- export declare const MAX_PATTERN_DEPTH = 4;
3
- export declare const MAX_BRANCHES = 8;
4
- export declare const MAX_VARIABLES = 4;
5
- export declare const MAX_EDGES = 6;
6
- export declare const MAX_REPEAT = 3;
7
- export declare const MAX_DOMAINS = 4;
8
- export declare const MAX_CHECK_DEPTH = 4;
9
- export declare const MAX_CHECK_LEAVES = 8;
1
+ import type { PolicyRef } from '../../../addressing/index.js';
2
+ import type { PolicyCheckExpression, PolicyExpression } from '../model/policy.js';
3
+ import { limits } from '../../limits.js';
4
+ /** A key of `limits.policy`. */
5
+ export type PolicyLimit = keyof typeof limits.policy;
6
+ /**
7
+ * Where a count of Policy branches stops: one past its limit. Each branch count is exact up to its
8
+ * limit plus one and reads as that once it is over, so expansion stays bounded.
9
+ */
10
10
  export declare const BRANCH_OVERFLOW: number;
11
+ /**
12
+ * What `PL_BUDGET` compares with `limits.policy` for one named Policy once normalized and each of
13
+ * its compositions expanded, every count under the key of its limit. The branch count stops one
14
+ * past its limit: it is exact up to that, and once it is over, `edgePredicates` reads the branches
15
+ * it counted only. The other counts are exact.
16
+ */
17
+ export interface PolicyMeasure {
18
+ /** Levels of the expanded pattern. */
19
+ readonly patternDepth: number;
20
+ /** Branches of its normal form, at most `limits.policy.normalizedBranches + 1`. */
21
+ readonly normalizedBranches: number;
22
+ /** The most graph predicates, Edges and sameNode equalities, of one branch. */
23
+ readonly edgePredicates: number;
24
+ /** Domains the expanded pattern names, its own included. */
25
+ readonly referencedDomains: number;
26
+ }
27
+ /**
28
+ * What `PL_BUDGET` compares with `limits.policy` for one check tree once normalized, every count
29
+ * under the key of its limit. The branch count stops one past its limit; the other counts are
30
+ * exact.
31
+ */
11
32
  export interface CheckMeasure {
12
- readonly depth: number;
13
- readonly branches: number;
14
- readonly leaves: number;
33
+ /** Levels of the tree. */
34
+ readonly checkDepth: number;
35
+ /** Branches of its normal form, at most `limits.policy.checkBranches + 1`. */
36
+ readonly checkBranches: number;
37
+ /** Checks and sameNode equalities of the tree. */
38
+ readonly checkLeaves: number;
15
39
  }
40
+ /** The limits of `limits.policy` a measure exceeds, in the order the measure lists them. */
41
+ export declare function exceededLimits<Measure extends PolicyMeasure | CheckMeasure>(measure: Measure): readonly (keyof Measure & PolicyLimit)[];
42
+ /**
43
+ * Measure named Policies by their expanded branches, depth and referenced Domains. A Policy has no
44
+ * measure when it is not normalized, when its expansion reaches itself, or when a composition names
45
+ * a Policy `isLocal` refuses or one without a measure.
46
+ */
47
+ export declare function policyMeasurer(origin: string, normalized: ReadonlyMap<string, PolicyExpression>, isLocal: (ref: PolicyRef) => boolean): (name: string) => PolicyMeasure | undefined;
48
+ /** Measure one normalized check tree. */
16
49
  export declare function measureChecks(expression: PolicyCheckExpression): CheckMeasure;
@@ -1,25 +1,139 @@
1
- export const MAX_PATTERN_DEPTH = 4;
2
- export const MAX_BRANCHES = 8;
3
- export const MAX_VARIABLES = 4;
4
- export const MAX_EDGES = 6;
5
- export const MAX_REPEAT = 3;
6
- export const MAX_DOMAINS = 4;
7
- export const MAX_CHECK_DEPTH = 4;
8
- export const MAX_CHECK_LEAVES = 8;
9
- export const BRANCH_OVERFLOW = MAX_BRANCHES + 1;
1
+ import { limits } from '../../limits.js';
2
+ import { policyObjectOrigin, policyVariableClass } from '../model/policy.js';
3
+ /**
4
+ * Where a count of Policy branches stops: one past its limit. Each branch count is exact up to its
5
+ * limit plus one and reads as that once it is over, so expansion stays bounded.
6
+ */
7
+ export const BRANCH_OVERFLOW = limits.policy.normalizedBranches + 1;
8
+ const CHECK_BRANCH_OVERFLOW = limits.policy.checkBranches + 1;
9
+ /** The limits of `limits.policy` a measure exceeds, in the order the measure lists them. */
10
+ export function exceededLimits(measure) {
11
+ return Object.keys(measure).filter((limit) => measure[limit] > limits.policy[limit]);
12
+ }
13
+ /**
14
+ * Measure named Policies by their expanded branches, depth and referenced Domains. A Policy has no
15
+ * measure when it is not normalized, when its expansion reaches itself, or when a composition names
16
+ * a Policy `isLocal` refuses or one without a measure.
17
+ */
18
+ export function policyMeasurer(origin, normalized, isLocal) {
19
+ // Measure every distinct composition node once. A node's expanded measure is independent of the
20
+ // path that reaches it (the only path-sensitive outcome, the back-edge `undefined`, already holds
21
+ // for every node on or reaching a composition cycle, regardless of entry), so caching the
22
+ // completed result by node identity turns path enumeration over the composition DAG into work
23
+ // linear in the number of nodes while preserving the exact measure.
24
+ const measures = new Map();
25
+ const measurePolicy = (name, visiting) => {
26
+ if (visiting.has(name))
27
+ return undefined;
28
+ if (measures.has(name))
29
+ return measures.get(name);
30
+ const declaration = normalized.get(name);
31
+ if (declaration === undefined)
32
+ return undefined;
33
+ const nested = new Set(visiting);
34
+ nested.add(name);
35
+ const measure = measureDeclaration(declaration, nested);
36
+ measures.set(name, measure);
37
+ return measure;
38
+ };
39
+ const measureDeclaration = (declaration, nested) => {
40
+ if ('match' in declaration)
41
+ return measurePattern(declaration.match, origin);
42
+ const refs = 'allOf' in declaration ? declaration.allOf : declaration.anyOf;
43
+ const children = refs.flatMap((ref) => {
44
+ if (!isLocal(ref))
45
+ return [];
46
+ const value = measurePolicy(ref.name, nested);
47
+ return value === undefined ? [] : [value];
48
+ });
49
+ if (children.length !== refs.length || children.length === 0)
50
+ return undefined;
51
+ return combineMeasures('allOf' in declaration ? 'allOf' : 'anyOf', children);
52
+ };
53
+ return (name) => {
54
+ const measure = measurePolicy(name, new Set());
55
+ return measure === undefined
56
+ ? undefined
57
+ : {
58
+ patternDepth: measure.depth,
59
+ normalizedBranches: measure.edgeCounts.length,
60
+ edgePredicates: Math.max(0, ...measure.edgeCounts),
61
+ referencedDomains: measure.domains.size,
62
+ };
63
+ };
64
+ }
65
+ function measurePattern(pattern, origin) {
66
+ if ('sameNode' in pattern)
67
+ return {
68
+ depth: 1,
69
+ edgeCounts: [1],
70
+ domains: new Set([
71
+ origin,
72
+ ...[pattern.sameNode.left, pattern.sameNode.right].flatMap((term) => term.kind === 'ref' ? [policyObjectOrigin(term.ref)] : []),
73
+ ]),
74
+ };
75
+ if ('source' in pattern)
76
+ return {
77
+ depth: 1,
78
+ edgeCounts: [1],
79
+ domains: new Set([
80
+ origin,
81
+ pattern.class.origin,
82
+ ...[pattern.source, pattern.target].flatMap((term) => term.kind === 'ref' ? [policyObjectOrigin(term.ref)] : []),
83
+ ]),
84
+ };
85
+ if ('exists' in pattern) {
86
+ const child = measurePattern(pattern.exists.where, origin);
87
+ return {
88
+ depth: child.depth + 1,
89
+ edgeCounts: child.edgeCounts,
90
+ domains: new Set([
91
+ ...child.domains,
92
+ ...pattern.exists.nodes.flatMap((node) => {
93
+ const ref = policyVariableClass(node);
94
+ return ref === undefined ? [] : [ref.origin];
95
+ }),
96
+ ]),
97
+ };
98
+ }
99
+ return combineMeasures('allOf' in pattern ? 'allOf' : 'anyOf', ('allOf' in pattern ? pattern.allOf : pattern.anyOf).map((child) => measurePattern(child, origin)));
100
+ }
101
+ function combineMeasures(kind, children) {
102
+ const depth = 1 + Math.max(0, ...children.map((child) => child.depth));
103
+ const domains = new Set(children.flatMap((child) => [...child.domains]));
104
+ if (kind === 'anyOf')
105
+ return {
106
+ depth,
107
+ edgeCounts: children.flatMap((child) => child.edgeCounts).slice(0, BRANCH_OVERFLOW),
108
+ domains,
109
+ };
110
+ let edgeCounts = [0];
111
+ for (const child of children) {
112
+ const next = [];
113
+ for (const left of edgeCounts) {
114
+ for (const right of child.edgeCounts) {
115
+ next.push(left + right);
116
+ if (next.length >= BRANCH_OVERFLOW)
117
+ break;
118
+ }
119
+ if (next.length >= BRANCH_OVERFLOW)
120
+ break;
121
+ }
122
+ edgeCounts = next;
123
+ }
124
+ return { depth, edgeCounts, domains };
125
+ }
126
+ /** Measure one normalized check tree. */
10
127
  export function measureChecks(expression) {
11
128
  if ('check' in expression || 'sameNode' in expression)
12
- return { depth: 1, branches: 1, leaves: 1 };
129
+ return { checkDepth: 1, checkBranches: 1, checkLeaves: 1 };
13
130
  const children = ('allOf' in expression ? expression.allOf : expression.anyOf).map(measureChecks);
14
- const branches = 'allOf' in expression
15
- ? children.reduce((value, child) => saturatingProduct(value, child.branches), 1)
16
- : children.reduce((value, child) => Math.min(BRANCH_OVERFLOW, value + child.branches), 0);
131
+ const checkBranches = 'allOf' in expression
132
+ ? children.reduce((value, child) => Math.min(CHECK_BRANCH_OVERFLOW, value * child.checkBranches), 1)
133
+ : children.reduce((value, child) => Math.min(CHECK_BRANCH_OVERFLOW, value + child.checkBranches), 0);
17
134
  return {
18
- depth: 1 + Math.max(0, ...children.map((child) => child.depth)),
19
- branches,
20
- leaves: children.reduce((value, child) => value + child.leaves, 0),
135
+ checkDepth: 1 + Math.max(0, ...children.map((child) => child.checkDepth)),
136
+ checkBranches,
137
+ checkLeaves: children.reduce((value, child) => value + child.checkLeaves, 0),
21
138
  };
22
139
  }
23
- function saturatingProduct(left, right) {
24
- return Math.min(BRANCH_OVERFLOW, left * right);
25
- }
@@ -1,5 +1,6 @@
1
+ import { limits } from '../../limits.js';
1
2
  import { policyObjectKey } from '../model/policy.js';
2
- import { MAX_BRANCHES, measureChecks } from './budgets.js';
3
+ import { measureChecks } from './budgets.js';
3
4
  /** Names a callable check object. Every leaf over one object sees the same Node at runtime. */
4
5
  function checkObjectName(object) {
5
6
  if (object.kind === 'self')
@@ -36,7 +37,7 @@ export function admittedCheckClasses(typing) {
36
37
  * check budget is already refused, so it is not expanded.
37
38
  */
38
39
  export function neverAdmittedClasses(expression, leaves) {
39
- if (measureChecks(expression).branches > MAX_BRANCHES)
40
+ if (measureChecks(expression).checkBranches > limits.policy.checkBranches)
40
41
  return [];
41
42
  const accepted = new Map();
42
43
  for (const [leaf, classes] of leaves)
@@ -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
+ }