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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (413) hide show
  1. package/dist/v1/addressing/class-key.js +3 -3
  2. package/dist/v1/addressing/definition-ref.js +21 -37
  3. package/dist/v1/addressing/domain-dependency.d.ts +0 -6
  4. package/dist/v1/addressing/domain-dependency.js +1 -6
  5. package/dist/v1/addressing/key.d.ts +4 -1
  6. package/dist/v1/addressing/key.js +23 -3
  7. package/dist/v1/addressing/ordering.d.ts +2 -0
  8. package/dist/v1/addressing/ordering.js +2 -0
  9. package/dist/v1/addressing/patterns.d.ts +1 -1
  10. package/dist/v1/addressing/patterns.js +2 -6
  11. package/dist/v1/builder/callable/authoring.d.ts +11 -5
  12. package/dist/v1/builder/callable/authoring.js +2 -0
  13. package/dist/v1/builder/class/authoring.d.ts +94 -224
  14. package/dist/v1/builder/class/authoring.js +30 -35
  15. package/dist/v1/builder/class/handle.d.ts +27 -0
  16. package/dist/v1/builder/class/handle.js +1 -0
  17. package/dist/v1/builder/class/input.d.ts +159 -0
  18. package/dist/v1/builder/class/projection.d.ts +129 -0
  19. package/dist/v1/builder/class/projection.js +1 -0
  20. package/dist/v1/builder/class/property.d.ts +3 -9
  21. package/dist/v1/builder/class/property.js +1 -0
  22. package/dist/v1/builder/core/authoring.d.ts +1 -1
  23. package/dist/v1/builder/index.d.ts +10 -2
  24. package/dist/v1/builder/index.js +2 -0
  25. package/dist/v1/builder/lowering/callable.js +1 -0
  26. package/dist/v1/builder/lowering/class.d.ts +9 -1
  27. package/dist/v1/builder/lowering/class.js +62 -17
  28. package/dist/v1/builder/lowering/policy.js +6 -24
  29. package/dist/v1/builder/lowering/property-keys.d.ts +27 -0
  30. package/dist/v1/builder/lowering/property-keys.js +108 -0
  31. package/dist/v1/builder/lowering/schema/compile.js +13 -6
  32. package/dist/v1/builder/lowering/schema/context.d.ts +9 -1
  33. package/dist/v1/builder/lowering/schema/context.js +36 -7
  34. package/dist/v1/builder/lowering/schema/lifetime.d.ts +11 -0
  35. package/dist/v1/builder/lowering/schema/lifetime.js +55 -0
  36. package/dist/v1/builder/lowering/value/compile.js +29 -22
  37. package/dist/v1/builder/lowering/value/file.d.ts +7 -0
  38. package/dist/v1/builder/lowering/value/file.js +14 -0
  39. package/dist/v1/builder/lowering/value/path.d.ts +1 -1
  40. package/dist/v1/builder/lowering/value/path.js +2 -4
  41. package/dist/v1/builder/lowering/value/zod.js +41 -7
  42. package/dist/v1/builder/policy/authoring.d.ts +80 -9
  43. package/dist/v1/builder/policy/authoring.js +99 -68
  44. package/dist/v1/builder/policy/legacy/edge.d.ts +28 -0
  45. package/dist/v1/builder/policy/legacy/edge.js +16 -0
  46. package/dist/v1/builder/schema/define.d.ts +0 -1
  47. package/dist/v1/builder/schema/diagnostic.d.ts +3 -2
  48. package/dist/v1/builder/schema/diagnostic.js +5 -10
  49. package/dist/v1/builder/schema/input.d.ts +4 -1
  50. package/dist/v1/builder/schema/projection/callable.d.ts +7 -5
  51. package/dist/v1/builder/schema/projection/class.d.ts +78 -16
  52. package/dist/v1/builder/schema/projection/core-input.d.ts +2 -1
  53. package/dist/v1/builder/schema/projection/domain.d.ts +13 -2
  54. package/dist/v1/builder/schema/projection/identity.d.ts +74 -9
  55. package/dist/v1/builder/schema/projection/model.d.ts +4 -2
  56. package/dist/v1/builder/schema/projection/property.d.ts +38 -4
  57. package/dist/v1/builder/schema/projection/resolved-class.d.ts +5 -4
  58. package/dist/v1/builder/schema/projection.d.ts +1 -1
  59. package/dist/v1/builder/schema/rule.d.ts +316 -0
  60. package/dist/v1/builder/schema/rule.js +192 -0
  61. package/dist/v1/builder/value/file.d.ts +34 -0
  62. package/dist/v1/builder/value/file.js +77 -0
  63. package/dist/v1/builder/value/full-match.d.ts +0 -1
  64. package/dist/v1/builder/value/full-match.js +0 -1
  65. package/dist/v1/builder/value/path-metadata.d.ts +1 -1
  66. package/dist/v1/builder/value/path.d.ts +1 -1
  67. package/dist/v1/bundle/codec.js +55 -74
  68. package/dist/v1/bundle/diagnostic.d.ts +3 -1
  69. package/dist/v1/bundle/diagnostic.js +9 -7
  70. package/dist/v1/bundle/index.d.ts +2 -0
  71. package/dist/v1/bundle/index.js +1 -0
  72. package/dist/v1/bundle/model.js +1 -1
  73. package/dist/v1/bundle/rule.d.ts +14 -0
  74. package/dist/v1/bundle/rule.js +41 -0
  75. package/dist/v1/bundle/structure.js +6 -8
  76. package/dist/v1/compiled/admission/accept.js +9 -15
  77. package/dist/v1/compiled/admission/closure.js +17 -34
  78. package/dist/v1/compiled/admission/diagnostic.d.ts +23 -1
  79. package/dist/v1/compiled/admission/diagnostic.js +40 -3
  80. package/dist/v1/compiled/admission/revision.d.ts +9 -1
  81. package/dist/v1/compiled/admission/revision.js +7 -3
  82. package/dist/v1/compiled/admission/semantics/class.d.ts +4 -1
  83. package/dist/v1/compiled/admission/semantics/class.js +48 -19
  84. package/dist/v1/compiled/admission/semantics/core.d.ts +1 -24
  85. package/dist/v1/compiled/admission/semantics/core.js +56 -24
  86. package/dist/v1/compiled/admission/semantics/edge.d.ts +2 -4
  87. package/dist/v1/compiled/admission/semantics/edge.js +6 -65
  88. package/dist/v1/compiled/admission/semantics/policy/admit.js +4 -19
  89. package/dist/v1/compiled/admission/semantics/policy/callable.js +2 -5
  90. package/dist/v1/compiled/admission/semantics/policy/contracts.d.ts +5 -20
  91. package/dist/v1/compiled/admission/semantics/policy/contracts.js +8 -21
  92. package/dist/v1/compiled/admission/semantics/policy/parity.js +44 -53
  93. package/dist/v1/compiled/admission/semantics/policy/pattern.d.ts +4 -1
  94. package/dist/v1/compiled/admission/semantics/policy/pattern.js +7 -21
  95. package/dist/v1/compiled/admission/semantics/policy/typing.d.ts +2 -24
  96. package/dist/v1/compiled/admission/semantics/policy/typing.js +19 -201
  97. package/dist/v1/compiled/admission/wire/callable.d.ts +5 -2
  98. package/dist/v1/compiled/admission/wire/callable.js +24 -20
  99. package/dist/v1/compiled/admission/wire/class.js +79 -30
  100. package/dist/v1/compiled/admission/wire/entry.d.ts +1 -1
  101. package/dist/v1/compiled/admission/wire/entry.js +36 -13
  102. package/dist/v1/compiled/admission/wire/policy.d.ts +4 -3
  103. package/dist/v1/compiled/admission/wire/policy.js +27 -20
  104. package/dist/v1/compiled/admission/wire/program.d.ts +13 -3
  105. package/dist/v1/compiled/admission/wire/program.js +39 -44
  106. package/dist/v1/compiled/admission/wire/property.d.ts +4 -1
  107. package/dist/v1/compiled/admission/wire/property.js +8 -5
  108. package/dist/v1/compiled/admission/wire/value.d.ts +0 -2
  109. package/dist/v1/compiled/admission/wire/value.js +0 -7
  110. package/dist/v1/compiled/codec/json.js +4 -3
  111. package/dist/v1/compiled/compiler/compile.js +15 -33
  112. package/dist/v1/compiled/diagnostic.d.ts +1 -1
  113. package/dist/v1/compiled/diagnostic.js +2 -3
  114. package/dist/v1/compiled/index.d.ts +2 -0
  115. package/dist/v1/compiled/index.js +1 -0
  116. package/dist/v1/compiled/loader/load.d.ts +3 -2
  117. package/dist/v1/compiled/loader/load.js +12 -51
  118. package/dist/v1/compiled/model/schema.d.ts +3 -0
  119. package/dist/v1/compiled/rule.d.ts +49 -0
  120. package/dist/v1/compiled/rule.js +169 -0
  121. package/dist/v1/domain/create.js +9 -10
  122. package/dist/v1/domain/model/domain.d.ts +2 -7
  123. package/dist/v1/domain/model/input.d.ts +15 -10
  124. package/dist/v1/domain/namespace/member-collection.js +8 -7
  125. package/dist/v1/domain/projection/classes.js +11 -8
  126. package/dist/v1/domain/validation/create.d.ts +7 -16
  127. package/dist/v1/domain/validation/create.js +35 -81
  128. package/dist/v1/index.d.ts +5 -3
  129. package/dist/v1/index.js +1 -1
  130. package/dist/v1/language/.spec/schemas/draft-2020-12.schema.json +462 -0
  131. package/dist/v1/language/.spec/schemas/value-schema.schema.json +23 -0
  132. package/dist/v1/language/callable/admission.d.ts +15 -0
  133. package/dist/v1/language/callable/admission.js +44 -0
  134. package/dist/v1/language/callable/model/callable.d.ts +10 -0
  135. package/dist/v1/language/callable/resolved.d.ts +16 -3
  136. package/dist/v1/language/chain.d.ts +7 -0
  137. package/dist/v1/language/chain.js +24 -0
  138. package/dist/v1/language/class/inheritance.d.ts +36 -5
  139. package/dist/v1/language/class/inheritance.js +85 -1
  140. package/dist/v1/language/class/lifetime.d.ts +50 -11
  141. package/dist/v1/language/class/lifetime.js +89 -20
  142. package/dist/v1/language/class/model/class.d.ts +45 -9
  143. package/dist/v1/language/class/model/edge.d.ts +31 -2
  144. package/dist/v1/language/class/model/property.d.ts +16 -7
  145. package/dist/v1/language/class/property-values.js +2 -4
  146. package/dist/v1/language/class/resolved.d.ts +9 -4
  147. package/dist/v1/language/class/unique.d.ts +143 -0
  148. package/dist/v1/language/class/unique.js +264 -0
  149. package/dist/v1/language/core/facts.d.ts +85 -0
  150. package/dist/v1/language/core/facts.js +116 -0
  151. package/dist/v1/language/cycle.d.ts +10 -0
  152. package/dist/v1/language/cycle.js +30 -0
  153. package/dist/v1/language/definition/metadata.d.ts +38 -0
  154. package/dist/v1/language/definition/metadata.js +51 -0
  155. package/dist/v1/language/freeze.d.ts +5 -0
  156. package/dist/v1/{schema/canonical → language}/freeze.js +4 -0
  157. package/dist/v1/language/index.d.ts +7 -2
  158. package/dist/v1/language/index.js +5 -1
  159. package/dist/v1/language/limits.d.ts +83 -0
  160. package/dist/v1/language/limits.js +77 -0
  161. package/dist/v1/language/policy/analysis/branches.d.ts +8 -0
  162. package/dist/v1/language/policy/analysis/branches.js +8 -8
  163. package/dist/v1/language/policy/analysis/budgets.d.ts +45 -12
  164. package/dist/v1/language/policy/analysis/budgets.js +140 -20
  165. package/dist/v1/language/policy/analysis/checks.js +8 -6
  166. package/dist/v1/language/policy/analysis/composition.d.ts +4 -0
  167. package/dist/v1/language/policy/analysis/composition.js +11 -0
  168. package/dist/v1/language/policy/analysis/typing.d.ts +51 -0
  169. package/dist/v1/language/policy/analysis/typing.js +456 -0
  170. package/dist/v1/language/policy/model/policy.d.ts +71 -9
  171. package/dist/v1/language/policy/model/policy.js +42 -4
  172. package/dist/v1/language/policy/normalization/normalize.d.ts +6 -6
  173. package/dist/v1/language/policy/normalization/normalize.js +46 -68
  174. package/dist/v1/language/suspended.d.ts +7 -0
  175. package/dist/v1/language/suspended.js +23 -0
  176. package/dist/v1/language/validation/diagnostic.d.ts +15 -1
  177. package/dist/v1/language/validation/diagnostic.js +21 -0
  178. package/dist/v1/language/validation/rule.d.ts +45 -0
  179. package/dist/v1/language/validation/rule.js +109 -0
  180. package/dist/v1/language/value/compile/fields.js +16 -16
  181. package/dist/v1/language/value/compile/load.d.ts +5 -0
  182. package/dist/v1/language/value/compile/load.js +13 -0
  183. package/dist/v1/language/value/evaluate/assertions.d.ts +5 -1
  184. package/dist/v1/language/value/evaluate/assertions.js +19 -8
  185. package/dist/v1/language/value/evaluate/evaluator.js +117 -120
  186. package/dist/v1/language/value/evaluate/preparation.d.ts +16 -0
  187. package/dist/v1/language/value/evaluate/preparation.js +100 -47
  188. package/dist/v1/language/value/evaluate/program.d.ts +2 -1
  189. package/dist/v1/language/value/evaluate/program.js +6 -6
  190. package/dist/v1/language/value/evaluate/validate.d.ts +3 -3
  191. package/dist/v1/language/value/evaluate/validate.js +14 -10
  192. package/dist/v1/language/value/evaluate/validity.optimization.d.ts +14 -0
  193. package/dist/v1/language/value/evaluate/validity.optimization.js +338 -0
  194. package/dist/v1/language/value/files.d.ts +44 -0
  195. package/dist/v1/language/value/files.js +151 -0
  196. package/dist/v1/language/value/inclusion/arrays.d.ts +3 -0
  197. package/dist/v1/language/value/inclusion/arrays.js +85 -0
  198. package/dist/v1/language/value/inclusion/assertions.d.ts +18 -0
  199. package/dist/v1/language/value/inclusion/assertions.js +28 -0
  200. package/dist/v1/language/value/inclusion/combinators.d.ts +3 -0
  201. package/dist/v1/language/value/inclusion/combinators.js +67 -0
  202. package/dist/v1/language/value/inclusion/equivalence.d.ts +4 -0
  203. package/dist/v1/language/value/inclusion/equivalence.js +76 -0
  204. package/dist/v1/language/value/inclusion/evidence.d.ts +34 -0
  205. package/dist/v1/language/value/inclusion/evidence.js +140 -0
  206. package/dist/v1/language/value/inclusion/includes.d.ts +29 -3
  207. package/dist/v1/language/value/inclusion/includes.js +58 -723
  208. package/dist/v1/language/value/inclusion/keywords.d.ts +5 -0
  209. package/dist/v1/language/value/inclusion/keywords.js +31 -0
  210. package/dist/v1/language/value/inclusion/kinds.d.ts +17 -0
  211. package/dist/v1/language/value/inclusion/kinds.js +57 -0
  212. package/dist/v1/language/value/inclusion/location.d.ts +24 -0
  213. package/dist/v1/language/value/inclusion/location.js +66 -0
  214. package/dist/v1/language/value/inclusion/numbers.d.ts +3 -0
  215. package/dist/v1/language/value/inclusion/numbers.js +41 -0
  216. package/dist/v1/language/value/inclusion/objects.d.ts +3 -0
  217. package/dist/v1/language/value/inclusion/objects.js +190 -0
  218. package/dist/v1/language/value/inclusion/strings.d.ts +3 -0
  219. package/dist/v1/language/value/inclusion/strings.js +29 -0
  220. package/dist/v1/language/value/inclusion/types.d.ts +3 -0
  221. package/dist/v1/language/value/inclusion/types.js +34 -0
  222. package/dist/v1/language/value/model/blob.d.ts +6 -0
  223. package/dist/v1/language/value/model/blob.js +8 -0
  224. package/dist/v1/language/value/model/file.d.ts +41 -0
  225. package/dist/v1/language/value/model/file.js +122 -0
  226. package/dist/v1/language/value/ordering.d.ts +14 -0
  227. package/dist/v1/language/value/ordering.js +144 -77
  228. package/dist/v1/language/value/profile/canonicalize.d.ts +6 -1
  229. package/dist/v1/language/value/profile/canonicalize.js +67 -87
  230. package/dist/v1/language/value/profile/json.validate.d.ts +12 -0
  231. package/dist/v1/language/value/profile/json.validate.js +18 -5
  232. package/dist/v1/language/value/profile/meta-schema.compiled.d.ts +1 -0
  233. package/dist/v1/language/value/profile/meta-schema.compiled.js +21 -5
  234. package/dist/v1/language/value/profile/rules.js +27 -44
  235. package/dist/v1/language/value/profile/validate.js +1 -10
  236. package/dist/v1/language/value/profile/vocabulary.d.ts +36 -2
  237. package/dist/v1/language/value/profile/vocabulary.js +58 -5
  238. package/dist/v1/language/value/reference/closure.js +6 -6
  239. package/dist/v1/language/value/reference/recursion.js +9 -48
  240. package/dist/v1/language/value/reference/references.d.ts +3 -1
  241. package/dist/v1/language/value/reference/references.js +7 -7
  242. package/dist/v1/language/value/reference/registry.index.d.ts +2 -0
  243. package/dist/v1/language/value/reference/registry.index.js +33 -16
  244. package/dist/v1/language/value/regexp/ast.js +6 -7
  245. package/dist/v1/language/value/regexp/compile.d.ts +5 -11
  246. package/dist/v1/language/value/regexp/compile.js +14 -12
  247. package/dist/v1/language/value/regexp/syntax.js +3 -2
  248. package/dist/v1/language/value/regexp/unicode.d.ts +1 -1
  249. package/dist/v1/language/value/regexp/unicode.js +1 -1
  250. package/dist/v1/language/value/syntax/keywords.d.ts +3 -3
  251. package/dist/v1/language/value/syntax/keywords.js +4 -20
  252. package/dist/v1/language/value/syntax/node-path/validate.js +2 -3
  253. package/dist/v1/language/value/syntax/pointer.d.ts +2 -0
  254. package/dist/v1/language/value/syntax/pointer.js +5 -2
  255. package/dist/v1/language/value/syntax/walk.d.ts +9 -0
  256. package/dist/v1/language/value/syntax/walk.js +37 -20
  257. package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +2596 -0
  258. package/dist/v1/schema/admission/accept.d.ts +3 -1
  259. package/dist/v1/schema/admission/accept.js +6 -14
  260. package/dist/v1/schema/admission/callable.d.ts +21 -0
  261. package/dist/v1/schema/admission/callable.js +96 -0
  262. package/dist/v1/schema/analysis/class.d.ts +4 -0
  263. package/dist/v1/schema/analysis/class.js +57 -17
  264. package/dist/v1/schema/canonical/revision.d.ts +4 -1
  265. package/dist/v1/schema/canonical/revision.js +8 -5
  266. package/dist/v1/schema/compatibility/api.d.ts +4 -1
  267. package/dist/v1/schema/compatibility/api.js +2 -0
  268. package/dist/v1/schema/compatibility/comparators/callables.js +1 -1
  269. package/dist/v1/schema/compatibility/comparators/classes.d.ts +9 -4
  270. package/dist/v1/schema/compatibility/comparators/classes.js +50 -29
  271. package/dist/v1/schema/compatibility/comparators/index.d.ts +1 -1
  272. package/dist/v1/schema/compatibility/comparators/members.js +1 -1
  273. package/dist/v1/schema/compatibility/comparators/values.js +2 -2
  274. package/dist/v1/schema/compatibility/context.d.ts +5 -2
  275. package/dist/v1/schema/compatibility/context.js +8 -6
  276. package/dist/v1/schema/compatibility/coordinate.js +3 -3
  277. package/dist/v1/schema/compatibility/diff.js +2 -4
  278. package/dist/v1/schema/compatibility/extension.d.ts +11 -0
  279. package/dist/v1/schema/compatibility/extension.js +22 -0
  280. package/dist/v1/schema/compatibility/fields.d.ts +20 -4
  281. package/dist/v1/schema/compatibility/fields.js +13 -3
  282. package/dist/v1/schema/compatibility/meaning/footprint.js +16 -51
  283. package/dist/v1/schema/compatibility/model.d.ts +17 -5
  284. package/dist/v1/schema/compatibility/references.d.ts +0 -3
  285. package/dist/v1/schema/compatibility/references.js +1 -9
  286. package/dist/v1/schema/compatibility/report.js +1 -1
  287. package/dist/v1/schema/compatibility/rule.d.ts +13 -0
  288. package/dist/v1/schema/compatibility/rule.js +23 -0
  289. package/dist/v1/schema/compatibility/scope.d.ts +2 -0
  290. package/dist/v1/schema/compatibility/scope.js +4 -1
  291. package/dist/v1/schema/compatibility/structure/index.js +6 -4
  292. package/dist/v1/schema/compatibility/structure/requirements.js +58 -61
  293. package/dist/v1/schema/compatibility/versioning/index.js +1 -1
  294. package/dist/v1/schema/compatibility/versioning/surface.d.ts +1 -1
  295. package/dist/v1/schema/compatibility/versioning/surface.js +30 -2
  296. package/dist/v1/schema/compatibility/walk.d.ts +17 -0
  297. package/dist/v1/schema/compatibility/walk.js +41 -0
  298. package/dist/v1/schema/diagnostic.d.ts +17 -3
  299. package/dist/v1/schema/diagnostic.js +14 -11
  300. package/dist/v1/schema/enforcement/changes.d.ts +590 -0
  301. package/dist/v1/schema/enforcement/changes.js +566 -0
  302. package/dist/v1/schema/enforcement/derived.d.ts +236 -0
  303. package/dist/v1/schema/enforcement/derived.js +243 -0
  304. package/dist/v1/schema/enforcement/dispose.d.ts +308 -0
  305. package/dist/v1/schema/enforcement/dispose.js +275 -0
  306. package/dist/v1/schema/enforcement/facts.d.ts +89 -0
  307. package/dist/v1/schema/enforcement/facts.js +70 -0
  308. package/dist/v1/schema/enforcement/fields.d.ts +65 -0
  309. package/dist/v1/schema/enforcement/fields.js +36 -0
  310. package/dist/v1/schema/enforcement/index.d.ts +39 -0
  311. package/dist/v1/schema/enforcement/index.js +10 -0
  312. package/dist/v1/schema/enforcement/install.d.ts +1634 -0
  313. package/dist/v1/schema/enforcement/install.js +1223 -0
  314. package/dist/v1/schema/enforcement/lifecycle.d.ts +87 -0
  315. package/dist/v1/schema/enforcement/lifecycle.js +91 -0
  316. package/dist/v1/schema/enforcement/model.d.ts +253 -0
  317. package/dist/v1/schema/enforcement/model.js +1 -0
  318. package/dist/v1/schema/enforcement/obligations.d.ts +248 -0
  319. package/dist/v1/schema/enforcement/obligations.js +240 -0
  320. package/dist/v1/schema/enforcement/write.d.ts +1314 -0
  321. package/dist/v1/schema/enforcement/write.js +1017 -0
  322. package/dist/v1/schema/index.d.ts +11 -1
  323. package/dist/v1/schema/index.js +5 -0
  324. package/dist/v1/schema/model/schema.d.ts +23 -1
  325. package/dist/v1/schema/model/schema.js +1 -1
  326. package/dist/v1/schema/normalization/domain.d.ts +2 -0
  327. package/dist/v1/schema/normalization/domain.js +50 -13
  328. package/dist/v1/schema/resolution/closure.js +2 -1
  329. package/dist/v1/schema/resolution/context.js +17 -18
  330. package/dist/v1/schema/resolution/domain.d.ts +5 -0
  331. package/dist/v1/schema/resolution/domain.js +5 -13
  332. package/dist/v1/schema/resolution/origins.js +6 -8
  333. package/dist/v1/schema/rule.d.ts +25 -0
  334. package/dist/v1/schema/rule.js +459 -0
  335. package/dist/v1/schema/validation/callable.d.ts +35 -2
  336. package/dist/v1/schema/validation/callable.js +65 -9
  337. package/dist/v1/schema/validation/class.d.ts +6 -2
  338. package/dist/v1/schema/validation/class.js +128 -105
  339. package/dist/v1/schema/validation/core.js +103 -173
  340. package/dist/v1/schema/validation/domain.js +25 -15
  341. package/dist/v1/schema/validation/domain.json-schema.d.ts +15 -0
  342. package/dist/v1/schema/validation/domain.json-schema.js +222 -0
  343. package/dist/v1/schema/validation/domain.route.d.ts +6 -1
  344. package/dist/v1/schema/validation/domain.route.js +18 -0
  345. package/dist/v1/schema/validation/domain.structure.d.ts +7797 -0
  346. package/dist/v1/schema/validation/domain.structure.js +516 -160
  347. package/dist/v1/schema/validation/icon.d.ts +4 -0
  348. package/dist/v1/schema/validation/icon.js +29 -0
  349. package/dist/v1/schema/validation/json.json-schema.d.ts +40 -0
  350. package/dist/v1/schema/validation/json.json-schema.js +46 -0
  351. package/dist/v1/schema/validation/policy/budgets.d.ts +37 -2
  352. package/dist/v1/schema/validation/policy/budgets.js +94 -121
  353. package/dist/v1/schema/validation/policy/context.d.ts +6 -5
  354. package/dist/v1/schema/validation/policy/context.js +7 -10
  355. package/dist/v1/schema/validation/policy/objects.d.ts +1 -1
  356. package/dist/v1/schema/validation/policy/objects.js +6 -14
  357. package/dist/v1/schema/validation/policy/references.js +20 -62
  358. package/dist/v1/schema/validation/policy/typing.d.ts +3 -18
  359. package/dist/v1/schema/validation/policy/typing.js +22 -356
  360. package/dist/v1/schema/validation/policy/uses.d.ts +40 -3
  361. package/dist/v1/schema/validation/policy/uses.js +63 -91
  362. package/dist/v1/schema/validation/policy/validate.js +5 -5
  363. package/dist/v1/schema/validation/value-api.d.ts +27 -1
  364. package/dist/v1/schema/validation/value-api.js +37 -2
  365. package/dist/v1/schema/validation/value.d.ts +3 -0
  366. package/dist/v1/schema/validation/value.js +9 -17
  367. package/dist/v1/schema/validation/value.json-schema.d.ts +54 -0
  368. package/dist/v1/schema/validation/value.json-schema.js +163 -0
  369. package/dist/v1/schema/validation/view.js +4 -8
  370. package/dist/value/accept.d.ts +9 -3
  371. package/dist/value/accept.js +25 -1
  372. package/dist/value/canonical.d.ts +22 -1
  373. package/dist/value/canonical.js +114 -21
  374. package/dist/value/decode.d.ts +7 -0
  375. package/dist/value/decode.js +159 -9
  376. package/dist/value/equal.d.ts +9 -1
  377. package/dist/value/equal.js +37 -3
  378. package/dist/value/immutable.optimization.d.ts +2 -0
  379. package/dist/value/immutable.optimization.js +4 -0
  380. package/dist/value/index.d.ts +5 -3
  381. package/dist/value/index.js +2 -1
  382. package/dist/value/json.d.ts +2 -2
  383. package/dist/value/json.js +2 -2
  384. package/dist/value/limits.d.ts +11 -0
  385. package/dist/value/rule.d.ts +12 -0
  386. package/dist/value/rule.js +50 -0
  387. package/dist/value/types.d.ts +6 -0
  388. package/dist/value/unicode.d.ts +2 -1
  389. package/dist/value/unicode.js +2 -0
  390. package/package.json +15 -4
  391. package/dist/v1/builder/lowering/core-properties.d.ts +0 -10
  392. package/dist/v1/builder/lowering/core-properties.js +0 -76
  393. package/dist/v1/compiled/admission/semantics/cardinality.d.ts +0 -5
  394. package/dist/v1/compiled/admission/semantics/cardinality.js +0 -113
  395. package/dist/v1/compiled/admission/semantics/policy/equality.d.ts +0 -8
  396. package/dist/v1/compiled/admission/semantics/policy/equality.js +0 -27
  397. package/dist/v1/compiled/admission/semantics/policy/measure.d.ts +0 -9
  398. package/dist/v1/compiled/admission/semantics/policy/measure.js +0 -81
  399. package/dist/v1/compiled/admission/semantics/policy/variants.d.ts +0 -10
  400. package/dist/v1/compiled/admission/semantics/policy/variants.js +0 -65
  401. package/dist/v1/compiled/admission/wire/pattern.d.ts +0 -12
  402. package/dist/v1/compiled/admission/wire/pattern.js +0 -111
  403. package/dist/v1/language/class/index.d.ts +0 -8
  404. package/dist/v1/language/class/index.js +0 -1
  405. package/dist/v1/language/core/index.d.ts +0 -2
  406. package/dist/v1/language/value/index.d.ts +0 -11
  407. package/dist/v1/language/value/index.js +0 -8
  408. package/dist/v1/schema/canonical/domain.d.ts +0 -3
  409. package/dist/v1/schema/canonical/domain.digest.d.ts +0 -3
  410. package/dist/v1/schema/canonical/domain.digest.js +0 -5
  411. package/dist/v1/schema/canonical/domain.js +0 -5
  412. package/dist/v1/schema/canonical/freeze.d.ts +0 -1
  413. /package/dist/v1/{language/core/index.js → builder/class/input.js} +0 -0
@@ -1,10 +1,13 @@
1
+ import { diagnostic } from '../../validation/diagnostic.js';
1
2
  import { isValueObject as isJsonObject } from '../model/object.js';
2
3
  import { collectResourceClosure, locationKey, } from '../reference/closure.js';
4
+ import { validateProductiveRecursion } from '../reference/recursion.js';
3
5
  import { indexRegistry } from '../reference/registry.index.js';
4
6
  import { compilePattern } from '../regexp/compile.js';
5
7
  import { loadPattern } from '../regexp/matcher.js';
8
+ import { graphNodePathSchema } from '../syntax/node-path/schema.js';
6
9
  import { appendPointer } from '../syntax/pointer.js';
7
- import { walkSchema } from '../syntax/walk.js';
10
+ import { forEachSubschema, holdsOnlySubschemas, walkSchema } from '../syntax/walk.js';
8
11
  /** Prepare reference and linear-regexp state without generating executable source. */
9
12
  export function prepareValueSchema(schema, registry, pointer, pool = new Map()) {
10
13
  const indexed = indexRegistry(registry, pointer);
@@ -13,30 +16,11 @@ export function prepareValueSchema(schema, registry, pointer, pool = new Map())
13
16
  const closure = collectResourceClosure(schema, 'callable-input', indexed.index, pointer);
14
17
  if (closure.diagnostics.length > 0)
15
18
  return failed(closure.diagnostics);
16
- const locations = new Map();
19
+ const locations = closureLocations(closure);
17
20
  const matchers = new Map();
18
- for (const resource of closure.resources.values()) {
19
- walkSchema(resource.schema, (location) => {
20
- const key = locationKey(resource.key, location.pointer);
21
- locations.set(key, {
22
- key,
23
- pointer: location.pointer,
24
- resource,
25
- schema: location.schema,
26
- });
27
- if (!isJsonObject(location.schema))
28
- return;
29
- rememberMatcher(matchers, pool, location.schema.pattern);
30
- rememberMatcher(matchers, pool, location.schema.fullMatch);
31
- if (isJsonObject(location.schema.patternProperties)) {
32
- for (const pattern of Object.keys(location.schema.patternProperties)) {
33
- rememberMatcher(matchers, pool, pattern);
34
- }
35
- }
36
- });
37
- }
38
- const initial = closure.resources.values().next().value;
39
- const root = initial === undefined ? undefined : locations.get(locationKey(initial.key, ''));
21
+ for (const source of patternSources(locations))
22
+ rememberMatcher(matchers, pool, source);
23
+ const root = closureRoot(closure, locations);
40
24
  if (root === undefined) {
41
25
  return { compiled: false, message: 'The root value schema is absent from its closure.' };
42
26
  }
@@ -47,7 +31,10 @@ export function prepareValueSchema(schema, registry, pointer, pool = new Map())
47
31
  root,
48
32
  locations,
49
33
  resolutions: closure.resolutions,
50
- program: () => (program ??= portableProgram(root, locations, closure.resolutions, matchers)),
34
+ program: () => (program ??= Object.freeze({
35
+ ...valueGraph(root, locations, closure.resolutions),
36
+ patterns: Object.freeze([...matchers.values()].map(({ pattern }) => pattern)),
37
+ })),
51
38
  child(location, keyword, member) {
52
39
  const keywordPointer = appendPointer(location.pointer, keyword);
53
40
  const pointer = member === undefined ? keywordPointer : appendPointer(keywordPointer, member);
@@ -73,18 +60,90 @@ export function prepareValueSchema(schema, registry, pointer, pool = new Map())
73
60
  },
74
61
  };
75
62
  }
76
- function portableProgram(root, locations, resolutions, patterns) {
63
+ const NO_DOMAINS = {
64
+ registry: {
65
+ current: { origin: '', dependencies: [], nodeDefinitions: [] },
66
+ directDependencies: [],
67
+ transitiveDependencies: [],
68
+ graphNodePath: graphNodePathSchema,
69
+ },
70
+ domains: new Map(),
71
+ dependenciesByOwner: new Map(),
72
+ nodeDefinitions: new Set(),
73
+ };
74
+ /**
75
+ * Derive the graph of a schema no admission has seen and the pattern sources it uses, or the refusal
76
+ * of one with no graph to read: a reference with no target, a cycle consuming nothing, or a subschema
77
+ * slot holding anything else. Closed under the two reference forms, it needs no registry and compiles
78
+ * no pattern.
79
+ */
80
+ export function deriveValueGraph(schema, pointer) {
81
+ const closure = collectResourceClosure(schema, 'callable-input', NO_DOMAINS, pointer);
82
+ const refusal = closure.diagnostics[0] ?? validateProductiveRecursion(closure.resources, closure.resolutions)[0];
83
+ if (refusal !== undefined)
84
+ return { refusal };
85
+ const locations = closureLocations(closure);
86
+ for (const location of locations.values()) {
87
+ if (!isJsonObject(location.schema))
88
+ continue;
89
+ for (const [keyword, value] of Object.entries(location.schema)) {
90
+ if (holdsOnlySubschemas(keyword, value))
91
+ continue;
92
+ const at = appendPointer(`${pointer}${location.pointer}`, keyword);
93
+ return {
94
+ refusal: diagnostic('VS_META_SCHEMA', at, `${keyword} must hold only subschemas.`),
95
+ };
96
+ }
97
+ }
98
+ return {
99
+ graph: valueGraph(closureRoot(closure, locations), locations, closure.resolutions),
100
+ sources: patternSources(locations),
101
+ };
102
+ }
103
+ /** The I-Regexp sources the locations of a closure use, each once, in location order. */
104
+ function patternSources(locations) {
105
+ const sources = new Set();
106
+ const use = (source) => {
107
+ if (typeof source === 'string')
108
+ sources.add(source);
109
+ };
110
+ for (const { schema } of locations.values()) {
111
+ if (!isJsonObject(schema))
112
+ continue;
113
+ use(schema.pattern);
114
+ use(schema.fullMatch);
115
+ if (isJsonObject(schema.patternProperties)) {
116
+ Object.keys(schema.patternProperties).forEach(use);
117
+ }
118
+ }
119
+ return [...sources];
120
+ }
121
+ function closureLocations(closure) {
122
+ const locations = new Map();
123
+ for (const resource of closure.resources.values()) {
124
+ walkSchema(resource.schema, ({ pointer, schema }) => {
125
+ const key = locationKey(resource.key, pointer);
126
+ locations.set(key, { key, pointer, resource, schema });
127
+ });
128
+ }
129
+ return locations;
130
+ }
131
+ function closureRoot(closure, locations) {
132
+ const initial = closure.resources.values().next().value;
133
+ return initial === undefined ? undefined : locations.get(locationKey(initial.key, ''));
134
+ }
135
+ function valueGraph(root, locations, resolutions) {
77
136
  const ordered = [...locations.values()];
78
137
  const indices = new Map(ordered.map((location, index) => [location.key, index]));
79
138
  const nodes = ordered.map((location) => {
80
139
  const children = {};
81
- walkSchema(location.schema, (child) => {
82
- if (child.depth !== 1)
83
- return;
84
- const target = indices.get(locationKey(location.resource.key, `${location.pointer}${child.pointer}`));
85
- if (target !== undefined)
86
- children[childKey(child.pointer)] = target;
87
- });
140
+ for (const [keyword, value] of Object.entries(location.schema)) {
141
+ forEachSubschema(keyword, value, appendPointer('', keyword), (_, at) => {
142
+ const target = indices.get(locationKey(location.resource.key, `${location.pointer}${at}`));
143
+ if (target !== undefined)
144
+ children[childKey(at)] = target;
145
+ });
146
+ }
88
147
  const resolved = resolutions.get(location.key);
89
148
  const reference = resolved === undefined
90
149
  ? undefined
@@ -98,25 +157,19 @@ function portableProgram(root, locations, resolutions, patterns) {
98
157
  ...(reference === undefined ? {} : { reference }),
99
158
  });
100
159
  });
101
- return Object.freeze({
102
- root: indices.get(root.key),
103
- nodes: Object.freeze(nodes),
104
- patterns: Object.freeze([...patterns.values()].map(({ pattern }) => pattern)),
105
- });
160
+ return { root: indices.get(root.key), nodes: Object.freeze(nodes) };
106
161
  }
107
162
  export function childKey(pointer) {
108
163
  return pointer.slice(1);
109
164
  }
110
- function rememberMatcher(matchers, pool, input) {
111
- if (typeof input === 'string' && !matchers.has(input)) {
112
- let prepared = pool.get(input);
113
- if (prepared === undefined) {
114
- const pattern = compilePattern(input);
115
- prepared = { pattern, matcher: loadPattern(pattern) };
116
- pool.set(input, prepared);
117
- }
118
- matchers.set(input, prepared);
165
+ function rememberMatcher(matchers, pool, source) {
166
+ let prepared = pool.get(source);
167
+ if (prepared === undefined) {
168
+ const pattern = compilePattern(source);
169
+ prepared = { pattern, matcher: loadPattern(pattern) };
170
+ pool.set(source, prepared);
119
171
  }
172
+ matchers.set(source, prepared);
120
173
  }
121
174
  function failed(diagnostics) {
122
175
  return {
@@ -1,3 +1,4 @@
1
+ import type { StructuralOptions } from '@astrale-os/kernel-dsl/value';
1
2
  import type { Diagnostic } from '../../validation/diagnostic.js';
2
3
  import type { ValueProgram } from '../compile/model.js';
3
- export declare function validateValueProgram(program: ValueProgram, input: unknown, roots?: readonly number[]): readonly Diagnostic[];
4
+ export declare function validateValueProgram(program: ValueProgram, input: unknown, roots?: readonly number[], options?: StructuralOptions): readonly Diagnostic[];
@@ -1,12 +1,12 @@
1
1
  import { loadValueProgram } from '../compile/load.js';
2
- import { validateCanonicalJsonDomain } from '../profile/json.validate.js';
2
+ import { acceptInstance } from '../profile/json.validate.js';
3
3
  import { evaluateInstance } from './evaluator.js';
4
- export function validateValueProgram(program, input, roots = [program.root]) {
5
- const canonical = validateCanonicalJsonDomain(input, '');
6
- if (canonical.length > 0)
7
- return canonical;
4
+ export function validateValueProgram(program, input, roots = [program.root], options) {
5
+ const accepted = acceptInstance(input, '', options);
6
+ if ('refusal' in accepted)
7
+ return [accepted.refusal];
8
8
  return roots.flatMap((root) => {
9
- const result = evaluateInstance(loadValueProgram(program, root), input);
9
+ const result = evaluateInstance(loadValueProgram(program, root), accepted.value);
10
10
  return result.failures.map((failure) => ({
11
11
  code: 'VALUE_SCHEMA_INSTANCE_INVALID',
12
12
  pointer: failure.instancePointer,
@@ -1,4 +1,4 @@
1
- import type { Value as JsonValue } from '@astrale-os/kernel-dsl/value';
1
+ import type { StructuralOptions } from '@astrale-os/kernel-dsl/value';
2
2
  import type { Diagnostic } from '../../validation/diagnostic.js';
3
3
  import type { JsonSchema } from '../model/schema.js';
4
4
  import type { ValueSchemaRegistry } from '../reference/registry.js';
@@ -11,6 +11,6 @@ import { type PatternPool } from './preparation.js';
11
11
  * resolution or dynamic source generation; patterns use the portable executor.
12
12
  * `format` remains annotation-only; the graph NodePath codec performs its separate locator check.
13
13
  */
14
- export declare function validateJsonInstance(schema: JsonSchema, value: JsonValue, registry: ValueSchemaRegistry, pointer?: string, patterns?: PatternPool): Diagnostic[];
14
+ export declare function validateJsonInstance(schema: JsonSchema, value: unknown, registry: ValueSchemaRegistry, pointer?: string, patterns?: PatternPool): Diagnostic[];
15
15
  /** Validate with the exact preparation already retained by a source-resolved Property or Callable. */
16
- export declare function validatePreparedInstance(compiled: CompiledInstanceSchema, value: unknown): Diagnostic[];
16
+ export declare function validatePreparedInstance(compiled: CompiledInstanceSchema, value: unknown, options?: StructuralOptions): Diagnostic[];
@@ -1,7 +1,8 @@
1
1
  import { diagnostic } from '../../validation/diagnostic.js';
2
- import { validateCanonicalJsonDomain } from '../profile/json.validate.js';
2
+ import { acceptInstance } from '../profile/json.validate.js';
3
3
  import { evaluateInstance } from './evaluator.js';
4
4
  import { prepareValueSchema, } from './preparation.js';
5
+ import { satisfies } from './validity.optimization.js';
5
6
  const validatorCache = new WeakMap();
6
7
  /**
7
8
  * Validate one complete portable value with the admitted V1 Draft 2020-12 profile.
@@ -11,25 +12,28 @@ const validatorCache = new WeakMap();
11
12
  * `format` remains annotation-only; the graph NodePath codec performs its separate locator check.
12
13
  */
13
14
  export function validateJsonInstance(schema, value, registry, pointer = '', patterns) {
14
- const diagnostics = [...validateCanonicalJsonDomain(value, pointer)];
15
- if (diagnostics.length > 0)
16
- return diagnostics;
15
+ const accepted = acceptInstance(value, pointer);
16
+ if ('refusal' in accepted)
17
+ return [accepted.refusal];
17
18
  const prepared = preparedInstanceValidator(schema, registry, pointer, patterns);
18
19
  if (!prepared.compiled) {
19
20
  return [
20
21
  diagnostic('VS_REFERENCE_RESOLUTION', pointer, `Value validation failed closed while preparing exact schema resources: ${prepared.message}.`),
21
22
  ];
22
23
  }
23
- return instanceDiagnostics(prepared.value, value, pointer);
24
+ return instanceDiagnostics(prepared.value, accepted.value, pointer);
24
25
  }
25
26
  /** Validate with the exact preparation already retained by a source-resolved Property or Callable. */
26
- export function validatePreparedInstance(compiled, value) {
27
- const diagnostics = [...validateCanonicalJsonDomain(value, '')];
28
- return diagnostics.length > 0
29
- ? diagnostics
30
- : instanceDiagnostics(compiled, value, '');
27
+ export function validatePreparedInstance(compiled, value, options) {
28
+ const accepted = acceptInstance(value, '', options);
29
+ return 'refusal' in accepted
30
+ ? [accepted.refusal]
31
+ : instanceDiagnostics(compiled, accepted.value, '');
31
32
  }
32
33
  function instanceDiagnostics(compiled, value, pointer) {
34
+ // A value the compiled check finds valid has nothing to report; any other is evaluated.
35
+ if (satisfies(compiled, value) === true)
36
+ return [];
33
37
  const result = evaluateInstance(compiled, value);
34
38
  if (result.valid)
35
39
  return [];
@@ -0,0 +1,14 @@
1
+ import type { Value as JsonValue } from '@astrale-os/kernel-dsl/value';
2
+ import type { CompiledInstanceSchema } from './types.js';
3
+ /**
4
+ * Whether a value satisfies its prepared schema, as the evaluator decides it, without building a
5
+ * failure, an instance pointer or an annotation: the evaluator's verdict, or undefined when this
6
+ * check cannot give it. Only the evaluator reports why a value fails, so a caller keeps it for
7
+ * every value this check does not find valid.
8
+ *
9
+ * Each schema location is compiled once into a closure over its keywords, retained with the
10
+ * prepared schema. A schema whose closure holds an annotation-dependent keyword
11
+ * (`unevaluatedItems`, `unevaluatedProperties`) is left to the evaluator, as is a value nested
12
+ * deeper than this check follows, and any value whose check throws.
13
+ */
14
+ export declare function satisfies(compiled: CompiledInstanceSchema, value: JsonValue): boolean | undefined;
@@ -0,0 +1,338 @@
1
+ import { equal } from '@astrale-os/kernel-dsl/value';
2
+ import { isCanonicalBlobRef } from '../model/blob.js';
3
+ import { isInstantValue } from '../model/instant.js';
4
+ import { isValueObject as isJsonObject } from '../model/object.js';
5
+ import { isJsonSchema, schemaList } from '../syntax/walk.js';
6
+ import { codePointLength, isMultipleOf, matchesType, unique } from './assertions.js';
7
+ /**
8
+ * Whether a value satisfies its prepared schema, as the evaluator decides it, without building a
9
+ * failure, an instance pointer or an annotation: the evaluator's verdict, or undefined when this
10
+ * check cannot give it. Only the evaluator reports why a value fails, so a caller keeps it for
11
+ * every value this check does not find valid.
12
+ *
13
+ * Each schema location is compiled once into a closure over its keywords, retained with the
14
+ * prepared schema. A schema whose closure holds an annotation-dependent keyword
15
+ * (`unevaluatedItems`, `unevaluatedProperties`) is left to the evaluator, as is a value nested
16
+ * deeper than this check follows, and any value whose check throws.
17
+ */
18
+ export function satisfies(compiled, value) {
19
+ let checks = compilations.get(compiled);
20
+ if (checks === undefined) {
21
+ checks = annotationFree(compiled) ? new Map() : null;
22
+ compilations.set(compiled, checks);
23
+ }
24
+ if (checks === null)
25
+ return undefined;
26
+ const outer = verdicts;
27
+ verdicts = new Map();
28
+ try {
29
+ return checkOf(compiled, checks, compiled.root)(value, 0);
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ finally {
35
+ verdicts = outer;
36
+ }
37
+ }
38
+ /** Per prepared schema: its checks by location, or null when its closure needs annotations. */
39
+ const compilations = new WeakMap();
40
+ /** Locations one evaluation follows before leaving the value to the evaluator. */
41
+ const MAXIMUM_DEPTH = 1_024;
42
+ const UNDECIDED = new Error('The value is left to the evaluator.');
43
+ /**
44
+ * The verdicts of the current evaluation by referenced location and value. Only a reference reaches
45
+ * one location from several places, so each referenced location is checked once per value, as the
46
+ * evaluator memoizes it, and a schema that references a location twice per level stays linear. A
47
+ * location entered again on the same value is a cycle, left to the evaluator.
48
+ */
49
+ let verdicts = new Map();
50
+ function annotationFree(compiled) {
51
+ for (const { schema } of compiled.locations.values()) {
52
+ if (isJsonObject(schema) &&
53
+ (Object.hasOwn(schema, 'unevaluatedItems') || Object.hasOwn(schema, 'unevaluatedProperties'))) {
54
+ return false;
55
+ }
56
+ }
57
+ return true;
58
+ }
59
+ /** The check of one location, compiled on its first use so that references may recur. */
60
+ function checkOf(compiled, checks, location) {
61
+ let check = checks.get(location);
62
+ if (check === undefined) {
63
+ let body;
64
+ check = (value, depth) => {
65
+ if (depth > MAXIMUM_DEPTH)
66
+ throw UNDECIDED;
67
+ body ??= compileLocation(compiled, checks, location);
68
+ return body(value, depth);
69
+ };
70
+ checks.set(location, check);
71
+ }
72
+ return check;
73
+ }
74
+ /**
75
+ * The conjunction of the location's keywords, each as the evaluator applies it: an applicator
76
+ * checks the same value at its child location, a keyword of one type passes every other type.
77
+ */
78
+ function compileLocation(compiled, checks, location) {
79
+ const schema = location.schema;
80
+ if (schema === true)
81
+ return () => true;
82
+ if (schema === false)
83
+ return () => false;
84
+ const child = (keyword, member) => checkOf(compiled, checks, compiled.child(location, keyword, member));
85
+ const parts = [];
86
+ if (Object.hasOwn(schema, '$ref')) {
87
+ const target = compiled.reference(location);
88
+ if (target === undefined)
89
+ throw UNDECIDED;
90
+ const check = checkOf(compiled, checks, target);
91
+ parts.push((value, depth) => {
92
+ let byValue = verdicts.get(target);
93
+ if (byValue === undefined)
94
+ verdicts.set(target, (byValue = new Map()));
95
+ const known = byValue.get(value);
96
+ if (known === null)
97
+ throw UNDECIDED;
98
+ if (known !== undefined)
99
+ return known;
100
+ byValue.set(value, null);
101
+ const verdict = check(value, depth + 1);
102
+ byValue.set(value, verdict);
103
+ return verdict;
104
+ });
105
+ }
106
+ compileCompositions(schema, child, parts);
107
+ compileCommon(schema, parts);
108
+ compileNumber(schema, parts);
109
+ compileString(compiled, schema, parts);
110
+ compileArray(schema, child, parts);
111
+ compileObject(compiled, schema, child, parts);
112
+ if (parts.length === 0)
113
+ return () => true;
114
+ if (parts.length === 1)
115
+ return parts[0];
116
+ return (value, depth) => {
117
+ for (const part of parts)
118
+ if (!part(value, depth))
119
+ return false;
120
+ return true;
121
+ };
122
+ }
123
+ function compileCompositions(schema, child, parts) {
124
+ const allOf = schemaList(schema.allOf)?.map((_, index) => child('allOf', index));
125
+ if (allOf !== undefined) {
126
+ parts.push((value, depth) => allOf.every((check) => check(value, depth + 1)));
127
+ }
128
+ const anyOf = schemaList(schema.anyOf)?.map((_, index) => child('anyOf', index));
129
+ if (anyOf !== undefined) {
130
+ parts.push((value, depth) => anyOf.some((check) => check(value, depth + 1)));
131
+ }
132
+ const oneOf = schemaList(schema.oneOf)?.map((_, index) => child('oneOf', index));
133
+ if (oneOf !== undefined) {
134
+ parts.push((value, depth) => {
135
+ let admitted = 0;
136
+ for (const check of oneOf)
137
+ if (check(value, depth + 1) && ++admitted > 1)
138
+ return false;
139
+ return admitted === 1;
140
+ });
141
+ }
142
+ if (isJsonSchema(schema.not)) {
143
+ const not = child('not');
144
+ parts.push((value, depth) => !not(value, depth + 1));
145
+ }
146
+ if (isJsonSchema(schema.if)) {
147
+ const condition = child('if');
148
+ const then = isJsonSchema(schema.then) ? child('then') : undefined;
149
+ const otherwise = isJsonSchema(schema.else) ? child('else') : undefined;
150
+ parts.push((value, depth) => {
151
+ const branch = condition(value, depth + 1) ? then : otherwise;
152
+ return branch === undefined || branch(value, depth + 1);
153
+ });
154
+ }
155
+ }
156
+ function compileCommon(schema, parts) {
157
+ const kind = schema['x-astrale-value-kind'];
158
+ if (kind === 'instant')
159
+ parts.push((value) => isInstantValue(value));
160
+ if (kind === 'blob')
161
+ parts.push((value) => isCanonicalBlobRef(value));
162
+ const type = schema.type;
163
+ if (typeof type === 'string')
164
+ parts.push((value) => matchesType(type, value));
165
+ else if (Array.isArray(type)) {
166
+ const types = type.filter((candidate) => typeof candidate === 'string');
167
+ parts.push((value) => types.some((candidate) => matchesType(candidate, value)));
168
+ }
169
+ if (Object.hasOwn(schema, 'const')) {
170
+ const expected = schema.const;
171
+ parts.push((value) => equal(value, expected));
172
+ }
173
+ const choices = schema.enum;
174
+ if (Array.isArray(choices)) {
175
+ parts.push((value) => choices.some((candidate) => equal(value, candidate)));
176
+ }
177
+ }
178
+ function compileNumber(schema, parts) {
179
+ const { multipleOf, maximum, exclusiveMaximum, minimum, exclusiveMinimum } = schema;
180
+ const bounded = typeof multipleOf === 'number' ||
181
+ typeof maximum === 'number' ||
182
+ typeof exclusiveMaximum === 'number' ||
183
+ typeof minimum === 'number' ||
184
+ typeof exclusiveMinimum === 'number';
185
+ if (!bounded)
186
+ return;
187
+ parts.push((value) => typeof value !== 'number' ||
188
+ ((typeof multipleOf !== 'number' || isMultipleOf(value, multipleOf)) &&
189
+ (typeof maximum !== 'number' || value <= maximum) &&
190
+ (typeof exclusiveMaximum !== 'number' || value < exclusiveMaximum) &&
191
+ (typeof minimum !== 'number' || value >= minimum) &&
192
+ (typeof exclusiveMinimum !== 'number' || value > exclusiveMinimum)));
193
+ }
194
+ function compileString(compiled, schema, parts) {
195
+ const { maxLength, minLength, pattern, fullMatch } = schema;
196
+ if (typeof maxLength === 'number' || typeof minLength === 'number') {
197
+ // For n UTF-16 units, ceil(n / 2) <= code points <= n: count only when the bounds cannot
198
+ // decide, as the evaluator does.
199
+ parts.push((value) => {
200
+ if (typeof value !== 'string')
201
+ return true;
202
+ if ((typeof maxLength !== 'number' || value.length <= maxLength) &&
203
+ (typeof minLength !== 'number' || Math.ceil(value.length / 2) >= minLength)) {
204
+ return true;
205
+ }
206
+ const length = codePointLength(value);
207
+ return ((typeof maxLength !== 'number' || length <= maxLength) &&
208
+ (typeof minLength !== 'number' || length >= minLength));
209
+ });
210
+ }
211
+ if (typeof pattern === 'string') {
212
+ const matcher = compiled.matcher(pattern);
213
+ parts.push((value) => typeof value !== 'string' || matcher.test(value));
214
+ }
215
+ if (typeof fullMatch === 'string') {
216
+ const matcher = compiled.matcher(fullMatch);
217
+ parts.push((value) => typeof value !== 'string' || matcher.matches(value));
218
+ }
219
+ }
220
+ function compileArray(schema, child, parts) {
221
+ const { maxItems, minItems } = schema;
222
+ if (typeof maxItems === 'number' || typeof minItems === 'number' || schema.uniqueItems === true) {
223
+ const distinct = schema.uniqueItems === true;
224
+ parts.push((value) => !Array.isArray(value) ||
225
+ ((typeof maxItems !== 'number' || value.length <= maxItems) &&
226
+ (typeof minItems !== 'number' || value.length >= minItems) &&
227
+ (!distinct || unique(value))));
228
+ }
229
+ const prefix = schemaList(schema.prefixItems)?.map((_, index) => child('prefixItems', index));
230
+ const items = isJsonSchema(schema.items) ? child('items') : undefined;
231
+ if (prefix !== undefined || items !== undefined) {
232
+ const leading = prefix ?? [];
233
+ parts.push((value, depth) => {
234
+ if (!Array.isArray(value))
235
+ return true;
236
+ for (let index = 0; index < value.length; index++) {
237
+ const check = index < leading.length ? leading[index] : items;
238
+ if (check !== undefined && !check(value[index], depth + 1))
239
+ return false;
240
+ }
241
+ return true;
242
+ });
243
+ }
244
+ if (isJsonSchema(schema.contains)) {
245
+ const contains = child('contains');
246
+ const least = typeof schema.minContains === 'number' ? schema.minContains : 1;
247
+ const most = typeof schema.maxContains === 'number' ? schema.maxContains : Number.POSITIVE_INFINITY;
248
+ parts.push((value, depth) => {
249
+ if (!Array.isArray(value))
250
+ return true;
251
+ let matches = 0;
252
+ for (const item of value)
253
+ if (contains(item, depth + 1))
254
+ matches++;
255
+ return matches >= least && matches <= most;
256
+ });
257
+ }
258
+ }
259
+ function compileObject(compiled, schema, child, parts) {
260
+ const { maxProperties, minProperties } = schema;
261
+ const required = Array.isArray(schema.required)
262
+ ? schema.required.filter((name) => typeof name === 'string')
263
+ : [];
264
+ const dependentRequired = isJsonObject(schema.dependentRequired)
265
+ ? Object.entries(schema.dependentRequired).flatMap(([name, names]) => Array.isArray(names)
266
+ ? [[name, names.filter((other) => typeof other === 'string')]]
267
+ : [])
268
+ : [];
269
+ if (typeof maxProperties === 'number' ||
270
+ typeof minProperties === 'number' ||
271
+ required.length > 0 ||
272
+ dependentRequired.length > 0) {
273
+ parts.push((value) => {
274
+ if (!isJsonObject(value))
275
+ return true;
276
+ if (typeof maxProperties === 'number' || typeof minProperties === 'number') {
277
+ const count = Object.keys(value).length;
278
+ if (typeof maxProperties === 'number' && count > maxProperties)
279
+ return false;
280
+ if (typeof minProperties === 'number' && count < minProperties)
281
+ return false;
282
+ }
283
+ for (const name of required)
284
+ if (!Object.hasOwn(value, name))
285
+ return false;
286
+ for (const [name, names] of dependentRequired) {
287
+ if (Object.hasOwn(value, name) && !names.every((other) => Object.hasOwn(value, other))) {
288
+ return false;
289
+ }
290
+ }
291
+ return true;
292
+ });
293
+ }
294
+ // Each member is checked by every pattern it matches, by its declared schema, and by the
295
+ // additional schema when neither declares it.
296
+ const declared = isJsonObject(schema.properties) ? schema.properties : {};
297
+ const properties = new Map(Object.keys(declared).map((name) => [name, child('properties', name)]));
298
+ const patterns = isJsonObject(schema.patternProperties)
299
+ ? Object.keys(schema.patternProperties).map((source) => [compiled.matcher(source), child('patternProperties', source)])
300
+ : [];
301
+ const additional = isJsonSchema(schema.additionalProperties)
302
+ ? child('additionalProperties')
303
+ : undefined;
304
+ const names = isJsonSchema(schema.propertyNames) ? child('propertyNames') : undefined;
305
+ if (properties.size > 0 || patterns.length > 0 || additional !== undefined || names) {
306
+ parts.push((value, depth) => {
307
+ if (!isJsonObject(value))
308
+ return true;
309
+ for (const name of Object.keys(value)) {
310
+ const member = value[name];
311
+ let matched = false;
312
+ for (const [matcher, check] of patterns) {
313
+ if (!matcher.test(name))
314
+ continue;
315
+ matched = true;
316
+ if (!check(member, depth + 1))
317
+ return false;
318
+ }
319
+ const check = Object.hasOwn(declared, name) ? properties.get(name) : undefined;
320
+ if (check !== undefined) {
321
+ if (!check(member, depth + 1))
322
+ return false;
323
+ }
324
+ else if (!matched && additional !== undefined && !additional(member, depth + 1)) {
325
+ return false;
326
+ }
327
+ if (names !== undefined && !names(name, depth + 1))
328
+ return false;
329
+ }
330
+ return true;
331
+ });
332
+ }
333
+ if (isJsonObject(schema.dependentSchemas)) {
334
+ const dependent = Object.keys(schema.dependentSchemas).map((name) => [name, child('dependentSchemas', name)]);
335
+ parts.push((value, depth) => !isJsonObject(value) ||
336
+ dependent.every(([name, check]) => !Object.hasOwn(value, name) || check(value, depth + 1)));
337
+ }
338
+ }