@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,44 @@
1
+ import type { FileOptions } from './model/file.js';
2
+ import type { JsonSchema } from './model/schema.js';
3
+ /**
4
+ * One step from a value to a value it holds: a named member, an item of an array (every item, or
5
+ * the one at `index`), or an entry of an object that its declared members do not name (every such
6
+ * entry, or those whose name `pattern` matches as a JSON Schema `patternProperties` name does).
7
+ */
8
+ export type FileSegment = {
9
+ readonly kind: 'property';
10
+ readonly name: string;
11
+ } | {
12
+ readonly kind: 'item';
13
+ readonly index?: number;
14
+ } | {
15
+ readonly kind: 'entry';
16
+ /** Member names the entry is not: the declared members beside it. */
17
+ readonly except?: readonly string[];
18
+ /** For an additional member: the `patternProperties` names it does not match. */
19
+ readonly exceptPatterns?: readonly string[];
20
+ /** For a pattern member: the `patternProperties` name it matches. */
21
+ readonly pattern?: string;
22
+ };
23
+ /** Where a callable input holds a file field, and what that field states about its file. */
24
+ export interface FilePosition extends FileOptions {
25
+ readonly path: readonly FileSegment[];
26
+ }
27
+ /** One file field of a concrete input value: where it is, which position it fills, its value. */
28
+ export interface LocatedFile {
29
+ /** RFC 6901 JSON Pointer of the value inside the input. */
30
+ readonly pointer: string;
31
+ readonly position: FilePosition;
32
+ readonly value: unknown;
33
+ }
34
+ /**
35
+ * Every position at which a value admitted by `schema` may hold a file field, in schema order and
36
+ * without duplicates. Local `$ref`s are followed once per path: a file below a recursive reference
37
+ * is listed where the recursion first reaches it. Pure and total on an admitted value schema.
38
+ */
39
+ export declare function filePositions(schema: JsonSchema): readonly FilePosition[];
40
+ /**
41
+ * The values of `input` that fill one of `positions`, in position order, each with its JSON
42
+ * Pointer. A position the input does not reach yields nothing; nothing is validated.
43
+ */
44
+ export declare function locateFiles(positions: readonly FilePosition[], input: unknown): readonly LocatedFile[];
@@ -0,0 +1,151 @@
1
+ import { fileOptionsOf, isFileValueSchema } from './model/file.js';
2
+ import { isValueObject as isJsonObject } from './model/object.js';
3
+ import { escapePointerToken, parseJsonPointerFragment, resolvePointer } from './syntax/pointer.js';
4
+ import { isJsonSchema } from './syntax/walk.js';
5
+ const SAME_VALUE = ['allOf', 'anyOf', 'oneOf'];
6
+ // `not` admits no value through its subschema, so no file field lies below it.
7
+ const SAME_VALUE_SINGLE = ['if', 'then', 'else'];
8
+ /**
9
+ * Every position at which a value admitted by `schema` may hold a file field, in schema order and
10
+ * without duplicates. Local `$ref`s are followed once per path: a file below a recursive reference
11
+ * is listed where the recursion first reaches it. Pure and total on an admitted value schema.
12
+ */
13
+ export function filePositions(schema) {
14
+ const positions = [];
15
+ const seen = new Set();
16
+ const visit = (location, path, references) => {
17
+ if (!isJsonObject(location))
18
+ return;
19
+ if (isFileValueSchema(location)) {
20
+ const position = Object.freeze({ path: Object.freeze([...path]), ...fileOptionsOf(location) });
21
+ const key = JSON.stringify(position);
22
+ if (!seen.has(key)) {
23
+ seen.add(key);
24
+ positions.push(position);
25
+ }
26
+ return;
27
+ }
28
+ const reference = location.$ref;
29
+ if (typeof reference === 'string' && reference.startsWith('#') && !references.has(reference)) {
30
+ const target = resolveLocal(schema, reference);
31
+ if (target !== undefined)
32
+ visit(target, path, new Set([...references, reference]));
33
+ }
34
+ for (const keyword of SAME_VALUE) {
35
+ const branches = location[keyword];
36
+ if (Array.isArray(branches)) {
37
+ for (const branch of branches)
38
+ visit(branch, path, references);
39
+ }
40
+ }
41
+ for (const keyword of SAME_VALUE_SINGLE) {
42
+ if (Object.hasOwn(location, keyword)) {
43
+ visit(location[keyword], path, references);
44
+ }
45
+ }
46
+ if (isJsonObject(location.dependentSchemas)) {
47
+ for (const entry of Object.values(location.dependentSchemas)) {
48
+ visit(entry, path, references);
49
+ }
50
+ }
51
+ const declared = isJsonObject(location.properties) ? Object.keys(location.properties) : [];
52
+ if (isJsonObject(location.properties)) {
53
+ for (const [name, member] of Object.entries(location.properties)) {
54
+ visit(member, [...path, { kind: 'property', name }], references);
55
+ }
56
+ }
57
+ const patterns = isJsonObject(location.patternProperties)
58
+ ? Object.keys(location.patternProperties)
59
+ : [];
60
+ if (isJsonObject(location.patternProperties)) {
61
+ for (const [pattern, member] of Object.entries(location.patternProperties)) {
62
+ visit(member, [
63
+ ...path,
64
+ { kind: 'entry', ...(declared.length === 0 ? {} : { except: declared }), pattern },
65
+ ], references);
66
+ }
67
+ }
68
+ for (const keyword of ['additionalProperties', 'unevaluatedProperties']) {
69
+ if (!Object.hasOwn(location, keyword))
70
+ continue;
71
+ // An additional member is named neither by a declared member nor by a pattern.
72
+ const entry = {
73
+ kind: 'entry',
74
+ ...(declared.length === 0 ? {} : { except: declared }),
75
+ ...(patterns.length === 0 ? {} : { exceptPatterns: patterns }),
76
+ };
77
+ visit(location[keyword], [...path, entry], references);
78
+ }
79
+ if (Array.isArray(location.prefixItems)) {
80
+ location.prefixItems.forEach((item, index) => visit(item, [...path, { kind: 'item', index }], references));
81
+ }
82
+ for (const keyword of ['items', 'unevaluatedItems', 'contains']) {
83
+ if (Object.hasOwn(location, keyword)) {
84
+ visit(location[keyword], [...path, { kind: 'item' }], references);
85
+ }
86
+ }
87
+ };
88
+ visit(schema, [], new Set());
89
+ return Object.freeze(positions);
90
+ }
91
+ /**
92
+ * The values of `input` that fill one of `positions`, in position order, each with its JSON
93
+ * Pointer. A position the input does not reach yields nothing; nothing is validated.
94
+ */
95
+ export function locateFiles(positions, input) {
96
+ const located = [];
97
+ const seen = new Set();
98
+ for (const position of positions) {
99
+ const walk = (value, depth, pointer) => {
100
+ if (depth === position.path.length) {
101
+ if (!seen.has(pointer)) {
102
+ seen.add(pointer);
103
+ located.push(Object.freeze({ pointer, position, value }));
104
+ }
105
+ return;
106
+ }
107
+ const segment = position.path[depth];
108
+ if (segment.kind === 'property') {
109
+ if (isPlainObject(value) && Object.hasOwn(value, segment.name)) {
110
+ walk(value[segment.name], depth + 1, `${pointer}/${escapePointerToken(segment.name)}`);
111
+ }
112
+ return;
113
+ }
114
+ if (segment.kind === 'item') {
115
+ if (!Array.isArray(value))
116
+ return;
117
+ if (segment.index !== undefined) {
118
+ if (segment.index < value.length) {
119
+ walk(value[segment.index], depth + 1, `${pointer}/${segment.index}`);
120
+ }
121
+ return;
122
+ }
123
+ value.forEach((item, index) => walk(item, depth + 1, `${pointer}/${index}`));
124
+ return;
125
+ }
126
+ if (!isPlainObject(value))
127
+ return;
128
+ const matcher = segment.pattern === undefined ? undefined : new RegExp(segment.pattern, 'u');
129
+ const excluded = (segment.exceptPatterns ?? []).map((pattern) => new RegExp(pattern, 'u'));
130
+ for (const [name, member] of Object.entries(value)) {
131
+ if (segment.except?.includes(name))
132
+ continue;
133
+ if (matcher !== undefined && !matcher.test(name))
134
+ continue;
135
+ if (excluded.some((pattern) => pattern.test(name)))
136
+ continue;
137
+ walk(member, depth + 1, `${pointer}/${escapePointerToken(name)}`);
138
+ }
139
+ };
140
+ walk(input, 0, '');
141
+ }
142
+ return Object.freeze(located);
143
+ }
144
+ function resolveLocal(root, reference) {
145
+ const tokens = parseJsonPointerFragment(reference);
146
+ const target = tokens === undefined ? undefined : resolvePointer(root, tokens);
147
+ return isJsonSchema(target) ? target : undefined;
148
+ }
149
+ function isPlainObject(value) {
150
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
151
+ }
@@ -0,0 +1,3 @@
1
+ import type { Rule } from './assertions.js';
2
+ /** Rules for the array size, uniqueness, item and `contains` keywords. */
3
+ export declare const arrayRules: ReadonlyMap<string, Rule>;
@@ -0,0 +1,85 @@
1
+ import { has } from './evidence.js';
2
+ import { isTop } from './keywords.js';
3
+ import { ARRAY } from './kinds.js';
4
+ import { childOf, childrenOf, schemaOf } from './location.js';
5
+ /** Rules for the array size, uniqueness, item and `contains` keywords. */
6
+ export const arrayRules = new Map([
7
+ [
8
+ 'maxItems',
9
+ ({ value, evidence }) => typeof value !== 'number' ||
10
+ !has(evidence, ARRAY) ||
11
+ (evidence.maxItems !== undefined && evidence.maxItems <= value),
12
+ ],
13
+ [
14
+ 'minItems',
15
+ ({ value, evidence }) => typeof value !== 'number' ||
16
+ !has(evidence, ARRAY) ||
17
+ value <= 0 ||
18
+ evidence.minItems >= value,
19
+ ],
20
+ [
21
+ 'uniqueItems',
22
+ ({ value, evidence }) => value !== true ||
23
+ !has(evidence, ARRAY) ||
24
+ evidence.uniqueItems ||
25
+ (evidence.maxItems !== undefined && evidence.maxItems <= 1),
26
+ ],
27
+ ['prefixItems', itemsHold],
28
+ ['items', itemsHold],
29
+ ['contains', containsHolds],
30
+ ['minContains', containsHolds],
31
+ ['maxContains', containsHolds],
32
+ ]);
33
+ function itemsHold({ inclusion, outer, schema, evidence }) {
34
+ if (!has(evidence, ARRAY))
35
+ return true;
36
+ const prefix = childrenOf(outer, 'prefixItems');
37
+ const rest = Object.hasOwn(schema, 'items') ? childOf(outer, 'items') : undefined;
38
+ const width = Math.max(prefix.length, ...evidence.conjuncts.map((conjunct) => childrenOf(conjunct, 'prefixItems').length));
39
+ // Every index at or beyond `width` meets `items` on both sides.
40
+ for (let index = 0; index <= width; index++) {
41
+ const required = index < prefix.length ? prefix[index] : rest;
42
+ if (required === undefined || isTop(schemaOf(required)))
43
+ continue;
44
+ if (evidence.maxItems !== undefined && evidence.maxItems <= index)
45
+ continue;
46
+ const admitted = evidence.conjuncts.flatMap((conjunct) => {
47
+ const own = childrenOf(conjunct, 'prefixItems');
48
+ if (index < own.length)
49
+ return [own[index]];
50
+ const items = childOf(conjunct, 'items');
51
+ return items === undefined ? [] : [items];
52
+ });
53
+ if (!admitted.some((constraint) => inclusion.includes(required, constraint)))
54
+ return false;
55
+ }
56
+ return true;
57
+ }
58
+ function containsHolds({ inclusion, outer, schema, evidence }) {
59
+ const contains = childOf(outer, 'contains');
60
+ if (contains === undefined || !has(evidence, ARRAY))
61
+ return true;
62
+ const { minimum, maximum } = containsCounts(schema);
63
+ const ownContains = evidence.conjuncts.flatMap((conjunct) => {
64
+ const own = childOf(conjunct, 'contains');
65
+ if (own === undefined)
66
+ return [];
67
+ const conjunctSchema = schemaOf(conjunct);
68
+ return [{ at: own, ...containsCounts(conjunctSchema) }];
69
+ });
70
+ // Every inner match is an outer match, so outer counts at least as many.
71
+ const atLeast = minimum <= 0 ||
72
+ ownContains.some((own) => own.minimum >= minimum && inclusion.includes(contains, own.at));
73
+ // Every outer match is an inner match, so outer counts at most as many.
74
+ const atMost = maximum === Number.POSITIVE_INFINITY ||
75
+ (evidence.maxItems !== undefined && evidence.maxItems <= maximum) ||
76
+ ownContains.some((own) => own.maximum <= maximum && inclusion.includes(own.at, contains));
77
+ return atLeast && atMost;
78
+ }
79
+ /** The match counts `contains` requires, with the evaluator's defaults. */
80
+ function containsCounts(schema) {
81
+ return {
82
+ minimum: typeof schema.minContains === 'number' ? schema.minContains : 1,
83
+ maximum: typeof schema.maxContains === 'number' ? schema.maxContains : Number.POSITIVE_INFINITY,
84
+ };
85
+ }
@@ -0,0 +1,18 @@
1
+ import type { Value as JsonValue } from '@astrale-os/kernel-dsl/value';
2
+ import type { Evidence } from './evidence.js';
3
+ import type { Inclusion } from './includes.js';
4
+ import type { At } from './location.js';
5
+ /** One keyword of `outer`, to be proved from the evidence of `inner`. */
6
+ export interface Assertion {
7
+ readonly inclusion: Inclusion;
8
+ readonly keyword: string;
9
+ readonly value: JsonValue | undefined;
10
+ readonly outer: At;
11
+ readonly schema: Readonly<Record<string, JsonValue>>;
12
+ readonly inner: At;
13
+ readonly evidence: Evidence;
14
+ }
15
+ /** Whether one outer keyword holds for every value the inner evidence admits. */
16
+ export type Rule = (assertion: Assertion) => boolean;
17
+ /** Whether every keyword of the outer `schema` holds for the values `inner` admits. */
18
+ export declare function assertionsHold(inclusion: Inclusion, outer: At, schema: Readonly<Record<string, JsonValue>>, inner: At, evidence: Evidence): boolean;
@@ -0,0 +1,28 @@
1
+ import { arrayRules } from './arrays.js';
2
+ import { combinatorRules } from './combinators.js';
3
+ import { INERT } from './keywords.js';
4
+ import { numberRules } from './numbers.js';
5
+ import { objectRules } from './objects.js';
6
+ import { stringRules } from './strings.js';
7
+ import { typeRules } from './types.js';
8
+ const RULES = new Map([
9
+ ...combinatorRules,
10
+ ...typeRules,
11
+ ...numberRules,
12
+ ...stringRules,
13
+ ...arrayRules,
14
+ ...objectRules,
15
+ ]);
16
+ /** Whether every keyword of the outer `schema` holds for the values `inner` admits. */
17
+ export function assertionsHold(inclusion, outer, schema, inner, evidence) {
18
+ // A keyword with no rule holds only when it asserts nothing. The annotation-dependent keywords,
19
+ // `unevaluatedProperties` and `unevaluatedItems`, have none: only equivalence decides them.
20
+ const keywords = Object.keys(schema);
21
+ if (!keywords.every((keyword) => RULES.has(keyword) || INERT.has(keyword)))
22
+ return false;
23
+ return keywords.every((keyword) => {
24
+ const rule = RULES.get(keyword);
25
+ return (rule === undefined ||
26
+ rule({ inclusion, keyword, value: schema[keyword], outer, schema, inner, evidence }));
27
+ });
28
+ }
@@ -0,0 +1,3 @@
1
+ import type { Rule } from './assertions.js';
2
+ /** Rules for `$ref`, the boolean combinators and the conditional keywords. */
3
+ export declare const combinatorRules: ReadonlyMap<string, Rule>;
@@ -0,0 +1,67 @@
1
+ import { equivalent } from './equivalence.js';
2
+ import { childOf, childrenOf, referenceOf } from './location.js';
3
+ /** Rules for `$ref`, the boolean combinators and the conditional keywords. */
4
+ export const combinatorRules = new Map([
5
+ [
6
+ '$ref',
7
+ ({ inclusion, outer, inner }) => {
8
+ const target = referenceOf(outer);
9
+ return target !== undefined && inclusion.includes(target, inner);
10
+ },
11
+ ],
12
+ [
13
+ 'allOf',
14
+ ({ inclusion, outer, inner }) => childrenOf(outer, 'allOf').every((branch) => inclusion.includes(branch, inner)),
15
+ ],
16
+ [
17
+ 'anyOf',
18
+ ({ inclusion, outer, inner }) => childrenOf(outer, 'anyOf').some((branch) => inclusion.includes(branch, inner)),
19
+ ],
20
+ ['oneOf', () => false],
21
+ [
22
+ 'not',
23
+ ({ inclusion, outer, evidence }) => {
24
+ const negated = childOf(outer, 'not');
25
+ return negated !== undefined && excludes(inclusion, negated, evidence);
26
+ },
27
+ ],
28
+ ['if', conditionalHolds],
29
+ ['then', conditionalHolds],
30
+ ['else', conditionalHolds],
31
+ ]);
32
+ /** Whether no value admitted by `evidence` satisfies `negated`. */
33
+ function excludes(inclusion, negated, evidence) {
34
+ if ((inclusion.evidence(negated).kinds & evidence.kinds) === 0)
35
+ return true;
36
+ return evidence.conjuncts.some((conjunct) => {
37
+ const own = childOf(conjunct, 'not');
38
+ return own !== undefined && inclusion.includes(own, negated);
39
+ });
40
+ }
41
+ function conditionalHolds({ inclusion, outer, inner, evidence }) {
42
+ const condition = childOf(outer, 'if');
43
+ if (condition === undefined)
44
+ return true;
45
+ const then = childOf(outer, 'then');
46
+ const otherwise = childOf(outer, 'else');
47
+ const thenHolds = (fallback) => then === undefined ||
48
+ inclusion.includes(then, inner) ||
49
+ (fallback !== undefined && inclusion.includes(then, fallback));
50
+ const elseHolds = (fallback) => otherwise === undefined ||
51
+ inclusion.includes(otherwise, inner) ||
52
+ (fallback !== undefined && inclusion.includes(otherwise, fallback));
53
+ if (thenHolds() && elseHolds())
54
+ return true;
55
+ for (const conjunct of evidence.conjuncts) {
56
+ const own = childOf(conjunct, 'if');
57
+ if (own === undefined || !equivalent(inclusion, own, condition))
58
+ continue;
59
+ if (thenHolds(childOf(conjunct, 'then')) && elseHolds(childOf(conjunct, 'else')))
60
+ return true;
61
+ }
62
+ if (inclusion.includes(condition, inner))
63
+ return thenHolds();
64
+ if (excludes(inclusion, condition, evidence))
65
+ return elseHolds();
66
+ return false;
67
+ }
@@ -0,0 +1,4 @@
1
+ import type { Inclusion } from './includes.js';
2
+ import type { At } from './location.js';
3
+ /** Whether the two locations are bisimilar: equal assertions over paired subschemas. */
4
+ export declare function equivalent(inclusion: Inclusion, left: At, right: At): boolean;
@@ -0,0 +1,76 @@
1
+ import { equal } from '@astrale-os/kernel-dsl/value';
2
+ import { INERT } from './keywords.js';
3
+ import { at, referenceOf, schemaOf } from './location.js';
4
+ /** Keywords whose subschemas the equivalence check compares positionally. */
5
+ const SUBSCHEMA_KEYWORDS = new Set([
6
+ 'additionalProperties',
7
+ 'allOf',
8
+ 'anyOf',
9
+ 'contains',
10
+ 'dependentSchemas',
11
+ 'else',
12
+ 'if',
13
+ 'items',
14
+ 'not',
15
+ 'oneOf',
16
+ 'patternProperties',
17
+ 'prefixItems',
18
+ 'properties',
19
+ 'propertyNames',
20
+ 'then',
21
+ 'unevaluatedItems',
22
+ 'unevaluatedProperties',
23
+ ]);
24
+ /** Whether the two locations are bisimilar: equal assertions over paired subschemas. */
25
+ export function equivalent(inclusion, left, right) {
26
+ const pending = [[left, right]];
27
+ const seen = new Set();
28
+ while (pending.length > 0) {
29
+ if (!inclusion.spend(1))
30
+ return false;
31
+ const [first, second] = pending.pop();
32
+ const key = inclusion.pair(first, second);
33
+ if (seen.has(key))
34
+ continue;
35
+ seen.add(key);
36
+ const a = schemaOf(first);
37
+ const b = schemaOf(second);
38
+ if (typeof a === 'boolean' || typeof b === 'boolean') {
39
+ if (a !== b)
40
+ return false;
41
+ continue;
42
+ }
43
+ const assertions = assertionKeys(a);
44
+ if (assertions.length !== assertionKeys(b).length)
45
+ return false;
46
+ for (const keyword of assertions) {
47
+ if (!Object.hasOwn(b, keyword) || !equal(a[keyword], b[keyword]))
48
+ return false;
49
+ }
50
+ const firstChildren = subschemaChildren(first);
51
+ const secondChildren = subschemaChildren(second);
52
+ if (firstChildren.size !== secondChildren.size)
53
+ return false;
54
+ for (const [path, index] of firstChildren) {
55
+ const other = secondChildren.get(path);
56
+ if (other === undefined)
57
+ return false;
58
+ pending.push([at(first.program, index), at(second.program, other)]);
59
+ }
60
+ const firstReference = referenceOf(first);
61
+ const secondReference = referenceOf(second);
62
+ if ((firstReference === undefined) !== (secondReference === undefined))
63
+ return false;
64
+ if (firstReference !== undefined)
65
+ pending.push([firstReference, secondReference]);
66
+ }
67
+ return true;
68
+ }
69
+ function assertionKeys(schema) {
70
+ return Object.keys(schema).filter((keyword) => !INERT.has(keyword) && !SUBSCHEMA_KEYWORDS.has(keyword) && keyword !== '$ref');
71
+ }
72
+ /** Subschema children keyed by their keyword path, without `$defs` or inert annotations. */
73
+ function subschemaChildren(location) {
74
+ const children = location.program.nodes[location.index]?.children ?? {};
75
+ return new Map(Object.entries(children).filter(([path]) => SUBSCHEMA_KEYWORDS.has(path.split('/', 1)[0].replaceAll('~1', '/').replaceAll('~0', '~'))));
76
+ }
@@ -0,0 +1,34 @@
1
+ import type { Value as JsonValue } from '@astrale-os/kernel-dsl/value';
2
+ import type { At } from './location.js';
3
+ /** One numeric bound, inclusive unless `exclusive`. */
4
+ export interface Bound {
5
+ readonly value: number;
6
+ readonly exclusive: boolean;
7
+ }
8
+ /** Over-approximation of the values one location admits, collected from its conjuncts. */
9
+ export interface Evidence {
10
+ /** The location, its `$ref` targets and its `allOf` branches, transitively. */
11
+ readonly conjuncts: readonly At[];
12
+ readonly kinds: number;
13
+ /** A finite superset of the admitted values, when one is known. */
14
+ readonly values?: readonly JsonValue[];
15
+ readonly upper?: Bound;
16
+ readonly lower?: Bound;
17
+ readonly multipleOf: readonly number[];
18
+ readonly maxLength?: number;
19
+ readonly minLength: number;
20
+ readonly patterns: ReadonlySet<string>;
21
+ readonly fullMatches: ReadonlySet<string>;
22
+ readonly maxItems?: number;
23
+ readonly minItems: number;
24
+ readonly uniqueItems: boolean;
25
+ readonly maxProperties?: number;
26
+ readonly minProperties: number;
27
+ readonly required: ReadonlySet<string>;
28
+ readonly dependentRequired: ReadonlyMap<string, ReadonlySet<string>>;
29
+ readonly valueKinds: ReadonlySet<string>;
30
+ }
31
+ /** Whether `evidence` may admit a value of one of `kinds`. */
32
+ export declare function has(evidence: Evidence, kinds: number): boolean;
33
+ /** The evidence the conjuncts of `location` carry together. */
34
+ export declare function evidenceOf(location: At): Evidence;
@@ -0,0 +1,140 @@
1
+ import { equal } from '@astrale-os/kernel-dsl/value';
2
+ import { isValueObject as isJsonObject } from '../model/object.js';
3
+ import { ANY, OBJECT, STRING, finiteKinds, kindOf, typeMask } from './kinds.js';
4
+ import { conjunctsOf, schemaOf } from './location.js';
5
+ /** Whether `evidence` may admit a value of one of `kinds`. */
6
+ export function has(evidence, kinds) {
7
+ return (evidence.kinds & kinds) !== 0;
8
+ }
9
+ /** The evidence the conjuncts of `location` carry together. */
10
+ export function evidenceOf(location) {
11
+ const conjuncts = conjunctsOf(location);
12
+ let kinds = ANY;
13
+ let values;
14
+ let upper;
15
+ let lower;
16
+ const multipleOf = [];
17
+ let maxLength;
18
+ let minLength = 0;
19
+ const patterns = new Set();
20
+ const fullMatches = new Set();
21
+ let maxItems;
22
+ let minItems = 0;
23
+ let uniqueItems = false;
24
+ let maxProperties;
25
+ let minProperties = 0;
26
+ const required = new Set();
27
+ const dependentRequired = new Map();
28
+ const valueKinds = new Set();
29
+ const narrow = (candidates) => {
30
+ values =
31
+ values === undefined
32
+ ? [...candidates]
33
+ : values.filter((value) => candidates.some((candidate) => equal(value, candidate)));
34
+ };
35
+ for (const conjunct of conjuncts) {
36
+ const schema = schemaOf(conjunct);
37
+ if (schema === false)
38
+ kinds = 0;
39
+ if (!isJsonObject(schema))
40
+ continue;
41
+ kinds &= typeMask(schema.type);
42
+ if (Object.hasOwn(schema, 'const')) {
43
+ narrow([schema.const]);
44
+ kinds &= kindOf(schema.const);
45
+ }
46
+ if (Array.isArray(schema.enum)) {
47
+ narrow(schema.enum);
48
+ kinds &= schema.enum.reduce((mask, value) => mask | kindOf(value), 0);
49
+ }
50
+ const valueKind = schema['x-astrale-value-kind'];
51
+ if (typeof valueKind === 'string') {
52
+ valueKinds.add(valueKind);
53
+ if (valueKind === 'instant')
54
+ kinds &= STRING;
55
+ if (valueKind === 'blob')
56
+ kinds &= OBJECT;
57
+ if (valueKind === 'file')
58
+ kinds &= STRING;
59
+ }
60
+ upper = tighter(upper, schema.maximum, false, (a, b) => a < b);
61
+ upper = tighter(upper, schema.exclusiveMaximum, true, (a, b) => a < b);
62
+ lower = tighter(lower, schema.minimum, false, (a, b) => a > b);
63
+ lower = tighter(lower, schema.exclusiveMinimum, true, (a, b) => a > b);
64
+ if (typeof schema.multipleOf === 'number')
65
+ multipleOf.push(schema.multipleOf);
66
+ if (typeof schema.maxLength === 'number')
67
+ maxLength = min(maxLength, schema.maxLength);
68
+ if (typeof schema.minLength === 'number')
69
+ minLength = Math.max(minLength, schema.minLength);
70
+ if (typeof schema.pattern === 'string')
71
+ patterns.add(schema.pattern);
72
+ if (typeof schema.fullMatch === 'string')
73
+ fullMatches.add(schema.fullMatch);
74
+ if (typeof schema.maxItems === 'number')
75
+ maxItems = min(maxItems, schema.maxItems);
76
+ if (typeof schema.minItems === 'number')
77
+ minItems = Math.max(minItems, schema.minItems);
78
+ if (schema.uniqueItems === true)
79
+ uniqueItems = true;
80
+ if (typeof schema.maxProperties === 'number') {
81
+ maxProperties = min(maxProperties, schema.maxProperties);
82
+ }
83
+ if (typeof schema.minProperties === 'number') {
84
+ minProperties = Math.max(minProperties, schema.minProperties);
85
+ }
86
+ if (Array.isArray(schema.required)) {
87
+ for (const name of schema.required)
88
+ if (typeof name === 'string')
89
+ required.add(name);
90
+ }
91
+ if (isJsonObject(schema.dependentRequired)) {
92
+ for (const [name, dependencies] of Object.entries(schema.dependentRequired)) {
93
+ if (!Array.isArray(dependencies))
94
+ continue;
95
+ const known = dependentRequired.get(name) ?? new Set();
96
+ for (const dependency of dependencies) {
97
+ if (typeof dependency === 'string')
98
+ known.add(dependency);
99
+ }
100
+ dependentRequired.set(name, known);
101
+ }
102
+ }
103
+ }
104
+ const finite = values === undefined
105
+ ? finiteKinds(kinds)
106
+ : values.filter((value) => (kindOf(value) & kinds) !== 0);
107
+ return Object.freeze({
108
+ conjuncts,
109
+ kinds,
110
+ ...(finite === undefined ? {} : { values: finite }),
111
+ ...(upper === undefined ? {} : { upper }),
112
+ ...(lower === undefined ? {} : { lower }),
113
+ multipleOf,
114
+ ...(maxLength === undefined ? {} : { maxLength }),
115
+ minLength,
116
+ patterns,
117
+ fullMatches,
118
+ ...(maxItems === undefined ? {} : { maxItems }),
119
+ minItems,
120
+ uniqueItems,
121
+ ...(maxProperties === undefined ? {} : { maxProperties }),
122
+ minProperties,
123
+ required,
124
+ dependentRequired,
125
+ valueKinds,
126
+ });
127
+ }
128
+ function tighter(current, value, exclusive, stricter) {
129
+ if (typeof value !== 'number')
130
+ return current;
131
+ if (current === undefined ||
132
+ stricter(value, current.value) ||
133
+ (value === current.value && exclusive)) {
134
+ return { value, exclusive };
135
+ }
136
+ return current;
137
+ }
138
+ function min(current, value) {
139
+ return current === undefined ? value : Math.min(current, value);
140
+ }