@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,122 @@
1
+ import { json } from '@astrale-os/kernel-dsl/value';
2
+ import { canonicalMediaType, isBlobValueSchema } from './blob.js';
3
+ import { isValueObject as isJsonObject } from './object.js';
4
+ export const FILE_VALUE_KIND = 'file';
5
+ /** The keyword that carries a file field's constraints, beside `x-astrale-value-kind: file`. */
6
+ export const FILE_KEYWORD = 'x-astrale-file';
7
+ /** Annotation keywords a file field may carry beside its canonical shape. */
8
+ const FILE_ANNOTATIONS = new Set([
9
+ '$comment',
10
+ 'deprecated',
11
+ 'description',
12
+ 'title',
13
+ ]);
14
+ /**
15
+ * The one canonical V1 schema of a file field: an upload receipt on the wire, with the constraints
16
+ * of the file it names under `x-astrale-file` when there are any.
17
+ */
18
+ export function file(options = {}) {
19
+ const constraints = acceptFileOptions(options);
20
+ return Object.freeze({
21
+ type: 'string',
22
+ 'x-astrale-value-kind': FILE_VALUE_KIND,
23
+ ...(Object.keys(constraints).length === 0 ? {} : { [FILE_KEYWORD]: constraints }),
24
+ });
25
+ }
26
+ /** Marker recognition on an already admitted V1 value schema. */
27
+ export function isFileValueSchema(input) {
28
+ return isJsonObject(input) && input['x-astrale-value-kind'] === FILE_VALUE_KIND;
29
+ }
30
+ /** The constraints a file field states. */
31
+ export function fileOptionsOf(schema) {
32
+ const constraints = schema[FILE_KEYWORD];
33
+ if (!isJsonObject(constraints))
34
+ return Object.freeze({});
35
+ return Object.freeze({
36
+ ...(typeof constraints.maxBytes === 'number' ? { maxBytes: constraints.maxBytes } : {}),
37
+ ...(Array.isArray(constraints.mediaTypes)
38
+ ? { mediaTypes: Object.freeze(constraints.mediaTypes.filter(isString)) }
39
+ : {}),
40
+ });
41
+ }
42
+ /** The constraints of a blob Property, as a file field that feeds it states them. */
43
+ export function blobFileOptions(schema) {
44
+ if (!isBlobValueSchema(schema))
45
+ throw new TypeError('File source is not a blob schema.');
46
+ const properties = isJsonObject(schema.properties) ? schema.properties : {};
47
+ const size = isJsonObject(properties.size) ? properties.size : {};
48
+ const mediaType = isJsonObject(properties.mediaType) ? properties.mediaType : {};
49
+ return acceptFileOptions({
50
+ ...(typeof size.maximum === 'number' ? { maxBytes: size.maximum } : {}),
51
+ ...(Array.isArray(mediaType.enum) ? { mediaTypes: mediaType.enum.filter(isString) } : {}),
52
+ });
53
+ }
54
+ /**
55
+ * `base` tightened by `tighter`: a lower `maxBytes`, a subset of `mediaTypes`. A constraint
56
+ * `tighter` would loosen is refused.
57
+ */
58
+ export function tightenFileOptions(base, tighter) {
59
+ const from = acceptFileOptions(base);
60
+ const next = acceptFileOptions(tighter);
61
+ if (next.maxBytes !== undefined && from.maxBytes !== undefined && next.maxBytes > from.maxBytes) {
62
+ throw new TypeError('A file field cannot raise the maxBytes of its source.');
63
+ }
64
+ if (next.mediaTypes !== undefined &&
65
+ from.mediaTypes !== undefined &&
66
+ !next.mediaTypes.every((mediaType) => from.mediaTypes.includes(mediaType))) {
67
+ throw new TypeError('A file field cannot admit a media type its source refuses.');
68
+ }
69
+ const maxBytes = next.maxBytes ?? from.maxBytes;
70
+ const mediaTypes = next.mediaTypes ?? from.mediaTypes;
71
+ return Object.freeze({
72
+ ...(maxBytes === undefined ? {} : { maxBytes }),
73
+ ...(mediaTypes === undefined ? {} : { mediaTypes }),
74
+ });
75
+ }
76
+ /** Whether `schema` is exactly one `file(...)` output, plus annotation keywords. */
77
+ export function isCanonicalFileSchema(schema) {
78
+ const shape = {};
79
+ for (const [keyword, value] of Object.entries(schema)) {
80
+ if (!FILE_ANNOTATIONS.has(keyword))
81
+ shape[keyword] = value;
82
+ }
83
+ const constraints = shape[FILE_KEYWORD];
84
+ if (constraints !== undefined && !isJsonObject(constraints))
85
+ return false;
86
+ try {
87
+ const options = constraints === undefined ? {} : constraints;
88
+ return json.serialize(shape) === json.serialize(file(options));
89
+ }
90
+ catch {
91
+ return false;
92
+ }
93
+ }
94
+ /** Canonical file options: positive safe-integer bound, sorted unique canonical media types. */
95
+ export function acceptFileOptions(options) {
96
+ if (options === null || typeof options !== 'object' || Array.isArray(options)) {
97
+ throw new TypeError('File options are invalid.');
98
+ }
99
+ for (const key of Object.keys(options)) {
100
+ if (key !== 'maxBytes' && key !== 'mediaTypes') {
101
+ throw new TypeError(`File option ${key} is unknown.`);
102
+ }
103
+ }
104
+ const { maxBytes, mediaTypes } = options;
105
+ if (maxBytes !== undefined && (!Number.isSafeInteger(maxBytes) || maxBytes < 1)) {
106
+ throw new TypeError('File maxBytes must be a positive safe integer.');
107
+ }
108
+ let canonical;
109
+ if (mediaTypes !== undefined) {
110
+ if (!Array.isArray(mediaTypes) || mediaTypes.length === 0) {
111
+ throw new TypeError('File mediaTypes must be a non-empty list.');
112
+ }
113
+ canonical = Object.freeze([...new Set(mediaTypes.map(canonicalMediaType))].sort());
114
+ }
115
+ return Object.freeze({
116
+ ...(maxBytes === undefined ? {} : { maxBytes }),
117
+ ...(canonical === undefined ? {} : { mediaTypes: canonical }),
118
+ });
119
+ }
120
+ function isString(input) {
121
+ return typeof input === 'string';
122
+ }
@@ -1,3 +1,4 @@
1
+ import type { ValueKind } from '@astrale-os/kernel-dsl/value';
1
2
  import type { ValueProgram } from './compile/model.js';
2
3
  import type { CompiledInstanceSchema } from './evaluate/types.js';
3
4
  import type { JsonSchema } from './model/schema.js';
@@ -13,3 +14,16 @@ export declare function classifyOrdering(contract: JsonSchema, registry: ValueSc
13
14
  /** Recompute the scalar ordering classification from one admitted portable value program. */
14
15
  export declare function classifyValueProgramOrdering(program: ValueProgram): OrderingKind | undefined;
15
16
  export declare function classifyPreparedOrdering(compiled: CompiledInstanceSchema): OrderingKind | undefined;
17
+ /**
18
+ * Every value kind `classifyValueKind` returns, frozen, in the order `ValueKind` names them. A kind
19
+ * added to `ValueKind` does not compile until it is listed here.
20
+ */
21
+ export declare const VALUE_KINDS: readonly ValueKind[];
22
+ /**
23
+ * The value kind of a property schema (page "Fondations Query v7", § Atoms et value kinds, Y4):
24
+ * the one kind its non-null values admit, `null` being a point of every kind. An annotated
25
+ * instant is `instant`, a finite set of strings `enum`, an array of unique items `set`; an
26
+ * ambiguous union, an object, an array with repetitions or a domain without values is `json`.
27
+ */
28
+ export declare function classifyValueKind(contract: JsonSchema, registry: ValueSchemaRegistry): ValueKind;
29
+ export declare function classifyPreparedValueKind(compiled: CompiledInstanceSchema): ValueKind;
@@ -1,5 +1,7 @@
1
+ import { runSuspended } from '../suspended.js';
1
2
  import { loadValueProgram } from './compile/load.js';
2
3
  import { prepareValueSchema } from './evaluate/preparation.js';
4
+ import { schemaList } from './syntax/walk.js';
3
5
  const ALL_JSON_KINDS = new Set([
4
6
  'null',
5
7
  'boolean',
@@ -25,7 +27,8 @@ export function classifyValueProgramOrdering(program) {
25
27
  return classifyPreparedOrdering(loadValueProgram(program));
26
28
  }
27
29
  export function classifyPreparedOrdering(compiled) {
28
- const candidates = new OrderingClassifier(compiled).classify(compiled.root);
30
+ // An enum orders as the strings it lists; a set is an array.
31
+ const candidates = new Set([...candidatesOf(compiled)].map((kind) => kind === 'enum' ? 'string' : kind === 'set' ? 'array' : kind));
29
32
  if (candidates.size !== 1)
30
33
  return undefined;
31
34
  const [kind] = candidates;
@@ -33,78 +36,117 @@ export function classifyPreparedOrdering(compiled) {
33
36
  ? kind
34
37
  : undefined;
35
38
  }
36
- class OrderingClassifier {
37
- compiled;
38
- active = new Set();
39
- cache = new Map();
40
- constructor(compiled) {
41
- this.compiled = compiled;
39
+ const valueKinds = {
40
+ text: true,
41
+ number: true,
42
+ instant: true,
43
+ enum: true,
44
+ boolean: true,
45
+ set: true,
46
+ json: true,
47
+ };
48
+ /**
49
+ * Every value kind `classifyValueKind` returns, frozen, in the order `ValueKind` names them. A kind
50
+ * added to `ValueKind` does not compile until it is listed here.
51
+ */
52
+ export const VALUE_KINDS = Object.freeze(Object.keys(valueKinds));
53
+ /**
54
+ * The value kind of a property schema (page "Fondations Query v7", § Atoms et value kinds, Y4):
55
+ * the one kind its non-null values admit, `null` being a point of every kind. An annotated
56
+ * instant is `instant`, a finite set of strings `enum`, an array of unique items `set`; an
57
+ * ambiguous union, an object, an array with repetitions or a domain without values is `json`.
58
+ */
59
+ export function classifyValueKind(contract, registry) {
60
+ const prepared = prepareValueSchema(contract, registry, '');
61
+ if (!prepared.compiled)
62
+ return 'json';
63
+ return classifyPreparedValueKind(prepared.value);
64
+ }
65
+ export function classifyPreparedValueKind(compiled) {
66
+ const candidates = new Set(candidatesOf(compiled));
67
+ candidates.delete('null');
68
+ if (candidates.size !== 1)
69
+ return 'json';
70
+ const [kind] = candidates;
71
+ switch (kind) {
72
+ case 'string':
73
+ return 'text';
74
+ case 'number':
75
+ case 'boolean':
76
+ case 'instant':
77
+ case 'enum':
78
+ case 'set':
79
+ return kind;
80
+ default:
81
+ return 'json';
42
82
  }
43
- classify(location) {
44
- const cached = this.cache.get(location.key);
45
- if (cached !== undefined)
46
- return cached;
47
- if (this.active.has(location.key))
48
- return ALL_JSON_KINDS;
49
- this.active.add(location.key);
50
- try {
51
- const result = this.classifySchema(location);
52
- this.cache.set(location.key, result);
53
- return result;
54
- }
55
- finally {
56
- this.active.delete(location.key);
57
- }
83
+ }
84
+ /**
85
+ * The candidates at a program's root. References chain to any length, so the classifications waiting
86
+ * on one another run on a stack of their own, never on the call stack.
87
+ */
88
+ function candidatesOf(compiled) {
89
+ const known = new Map();
90
+ function* read(location) {
91
+ const candidates = known.get(location.key);
92
+ if (candidates !== undefined)
93
+ return candidates;
94
+ // A location read again before its classification ends sits on a cycle: it admits anything.
95
+ known.set(location.key, ALL_JSON_KINDS);
96
+ const classified = yield* classifySchema(compiled, location, read);
97
+ known.set(location.key, classified);
98
+ return classified;
58
99
  }
59
- classifySchema(location) {
60
- if (location.schema === false)
100
+ return runSuspended(read(compiled.root));
101
+ }
102
+ function* classifySchema(compiled, location, read) {
103
+ if (location.schema === false)
104
+ return new Set();
105
+ if (location.schema === true)
106
+ return ALL_JSON_KINDS;
107
+ const schema = location.schema;
108
+ let candidates = ALL_JSON_KINDS;
109
+ if (Object.hasOwn(schema, 'x-astrale-value-kind')) {
110
+ if (schema['x-astrale-value-kind'] !== 'instant' || schema.type !== 'string') {
61
111
  return new Set();
62
- if (location.schema === true)
63
- return ALL_JSON_KINDS;
64
- const schema = location.schema;
65
- let candidates = ALL_JSON_KINDS;
66
- if (Object.hasOwn(schema, 'x-astrale-value-kind')) {
67
- if (schema['x-astrale-value-kind'] !== 'instant' || schema.type !== 'string') {
68
- return new Set();
69
- }
70
- candidates = intersect(candidates, new Set(['instant']));
71
- }
72
- const declaredTypes = typesOf(schema.type);
73
- if (declaredTypes !== undefined)
74
- candidates = intersect(candidates, declaredTypes);
75
- if (Object.hasOwn(schema, 'const')) {
76
- candidates = intersect(candidates, new Set([kindOfValue(schema.const)]));
77
- }
78
- if (Array.isArray(schema.enum)) {
79
- candidates = intersect(candidates, normalize(new Set(schema.enum.map(kindOfValue))));
80
- }
81
- if (Object.hasOwn(schema, '$ref')) {
82
- const target = this.compiled.reference(location);
83
- if (target === undefined)
84
- return new Set();
85
- candidates = intersect(candidates, this.classify(target));
86
112
  }
87
- const allOf = schemaList(schema.allOf);
88
- if (allOf !== undefined) {
89
- for (let index = 0; index < allOf.length; index += 1) {
90
- candidates = intersect(candidates, this.classify(this.child(location, 'allOf', index)));
91
- }
92
- }
93
- for (const keyword of ['anyOf', 'oneOf']) {
94
- const branches = schemaList(schema[keyword]);
95
- if (branches === undefined)
96
- continue;
97
- let admitted = new Set();
98
- for (let index = 0; index < branches.length; index += 1) {
99
- admitted = union(admitted, this.classify(this.child(location, keyword, index)));
100
- }
101
- candidates = intersect(candidates, admitted);
113
+ candidates = intersect(candidates, new Set(['instant']));
114
+ }
115
+ const declaredTypes = typesOf(schema.type);
116
+ if (declaredTypes !== undefined)
117
+ candidates = intersect(candidates, declaredTypes);
118
+ if (schema.uniqueItems === true) {
119
+ candidates = new Set([...candidates].map((kind) => (kind === 'array' ? 'set' : kind)));
120
+ }
121
+ if (Object.hasOwn(schema, 'const')) {
122
+ candidates = intersect(candidates, new Set([kindOfValue(schema.const)]));
123
+ }
124
+ if (Array.isArray(schema.enum)) {
125
+ candidates = intersect(candidates, normalize(new Set(schema.enum.map(kindOfValue))));
126
+ }
127
+ if (Object.hasOwn(schema, '$ref')) {
128
+ const target = compiled.reference(location);
129
+ if (target === undefined)
130
+ return new Set();
131
+ candidates = intersect(candidates, yield read(target));
132
+ }
133
+ const allOf = schemaList(schema.allOf);
134
+ if (allOf !== undefined) {
135
+ for (let index = 0; index < allOf.length; index += 1) {
136
+ candidates = intersect(candidates, yield read(compiled.child(location, 'allOf', index)));
102
137
  }
103
- return candidates;
104
138
  }
105
- child(location, keyword, index) {
106
- return this.compiled.child(location, keyword, index);
139
+ for (const keyword of ['anyOf', 'oneOf']) {
140
+ const branches = schemaList(schema[keyword]);
141
+ if (branches === undefined)
142
+ continue;
143
+ let admitted = new Set();
144
+ for (let index = 0; index < branches.length; index += 1) {
145
+ admitted = union(admitted, yield read(compiled.child(location, keyword, index)));
146
+ }
147
+ candidates = intersect(candidates, admitted);
107
148
  }
149
+ return candidates;
108
150
  }
109
151
  function typesOf(input) {
110
152
  if (typeof input === 'string')
@@ -130,6 +172,7 @@ function typeSet(types) {
130
172
  }
131
173
  return result;
132
174
  }
175
+ /** The kind of one listed value: a listed string belongs to a finite set of strings. */
133
176
  function kindOfValue(value) {
134
177
  if (value === null)
135
178
  return 'null';
@@ -141,18 +184,35 @@ function kindOfValue(value) {
141
184
  return 'boolean';
142
185
  if (typeof value === 'number')
143
186
  return 'number';
144
- return 'string';
187
+ return 'enum';
145
188
  }
189
+ /** The kind both admit: equal kinds, or the narrower of a kind and one of its subsets. */
190
+ function meet(left, right) {
191
+ if (left === right)
192
+ return left;
193
+ for (const [narrow, wide] of NARROWER) {
194
+ if ((left === narrow && right === wide) || (left === wide && right === narrow))
195
+ return narrow;
196
+ }
197
+ return undefined;
198
+ }
199
+ /**
200
+ * The narrower kind of two that meet: a subset and its kind, and an enum of instants, which
201
+ * orders as instants.
202
+ */
203
+ const NARROWER = [
204
+ ['instant', 'string'],
205
+ ['enum', 'string'],
206
+ ['instant', 'enum'],
207
+ ['set', 'array'],
208
+ ];
146
209
  function intersect(left, right) {
147
210
  const result = new Set();
148
211
  for (const leftKind of left) {
149
212
  for (const rightKind of right) {
150
- if (leftKind === rightKind)
151
- result.add(leftKind);
152
- else if ((leftKind === 'string' && rightKind === 'instant') ||
153
- (leftKind === 'instant' && rightKind === 'string')) {
154
- result.add('instant');
155
- }
213
+ const kind = meet(leftKind, rightKind);
214
+ if (kind !== undefined)
215
+ result.add(kind);
156
216
  }
157
217
  }
158
218
  return normalize(result);
@@ -160,11 +220,18 @@ function intersect(left, right) {
160
220
  function union(left, right) {
161
221
  return normalize(new Set([...left, ...right]));
162
222
  }
223
+ /** A kind absorbs its subsets; strings of two subsets are strings. */
163
224
  function normalize(input) {
164
- if (input.has('string'))
225
+ if (input.has('enum') && input.has('instant')) {
226
+ input.delete('enum');
165
227
  input.delete('instant');
228
+ input.add('string');
229
+ }
230
+ if (input.has('string')) {
231
+ input.delete('instant');
232
+ input.delete('enum');
233
+ }
234
+ if (input.has('array'))
235
+ input.delete('set');
166
236
  return input;
167
237
  }
168
- function schemaList(input) {
169
- return Array.isArray(input) ? input : undefined;
170
- }
@@ -1,4 +1,9 @@
1
1
  import type { JsonSchema, ValueSchemaContext } from '../model/schema.js';
2
2
  import type { ValueSchemaRegistry } from '../reference/registry.js';
3
- /** Canonicalizes syntax without rewriting the schema's algebra. Validate first. */
3
+ /**
4
+ * Canonicalizes syntax without rewriting the schema's algebra, and judges nothing: a set repeating a
5
+ * value or naming something else than it declares keeps its members, for validation to refuse.
6
+ */
4
7
  export declare function canonicalizeValueSchema(schema: JsonSchema, context?: ValueSchemaContext, registry?: ValueSchemaRegistry): JsonSchema;
8
+ /** A schema with its members in canonical order at every depth. Arrays keep theirs: it is their meaning. */
9
+ export declare function canonicalizeSchemaMembers(schema: JsonSchema): JsonSchema;
@@ -2,90 +2,76 @@ import { json } from '@astrale-os/kernel-dsl/value';
2
2
  import { compareDefinitionRefs, compareUnicode } from '../../../addressing/ordering.js';
3
3
  import { isValueObject as isJsonObject } from '../model/object.js';
4
4
  import { SCHEMA_ARRAY_KEYWORDS, SCHEMA_MAP_KEYWORDS, SCHEMA_SINGLE_KEYWORDS, } from '../syntax/keywords.js';
5
+ import { isJsonSchema } from '../syntax/walk.js';
5
6
  const TYPE_ORDER = ['null', 'boolean', 'integer', 'number', 'string', 'array', 'object'];
6
7
  const TYPE_RANK = new Map(TYPE_ORDER.map((name, index) => [name, index]));
7
8
  const encoder = new TextEncoder();
8
- /** Canonicalizes syntax without rewriting the schema's algebra. Validate first. */
9
+ /**
10
+ * Canonicalizes syntax without rewriting the schema's algebra, and judges nothing: a set repeating a
11
+ * value or naming something else than it declares keeps its members, for validation to refuse.
12
+ */
9
13
  export function canonicalizeValueSchema(schema, context, registry) {
14
+ void context;
10
15
  void registry;
11
- return canonicalizeSchema(schema, true, context);
16
+ return canonicalizeSchema(schema, true);
12
17
  }
13
- function canonicalizeSchema(schema, root, context) {
18
+ /** A schema with its members in canonical order at every depth. Arrays keep theirs: it is their meaning. */
19
+ export function canonicalizeSchemaMembers(schema) {
20
+ return canonicalizeJson(schema);
21
+ }
22
+ function canonicalizeSchema(schema, root) {
14
23
  if (typeof schema === 'boolean')
15
24
  return schema;
16
- const result = {};
17
- for (const keyword of Object.keys(schema).sort()) {
18
- if (root && keyword === '$schema')
19
- continue;
20
- const value = schema[keyword];
21
- if (keyword === 'required' && Array.isArray(value)) {
22
- assertUnique(value, String, 'required');
23
- result[keyword] = [...value].sort((left, right) => compareUnicode(String(left), String(right)));
24
- }
25
- else if (keyword === 'type' && Array.isArray(value)) {
26
- assertUnique(value, String, 'type');
27
- result[keyword] = [...value].sort((left, right) => (TYPE_RANK.get(String(left)) ?? Number.MAX_SAFE_INTEGER) -
28
- (TYPE_RANK.get(String(right)) ?? Number.MAX_SAFE_INTEGER));
29
- }
30
- else if (keyword === 'enum' && Array.isArray(value)) {
31
- const entries = value.map(canonicalizeJson);
32
- assertUnique(entries, json.serialize, 'enum');
33
- result[keyword] = entries.sort(compareCanonicalBytes);
34
- }
35
- else if (keyword === 'dependentRequired' && isJsonObject(value)) {
36
- result[keyword] = canonicalizeDependentRequired(value);
37
- }
38
- else if (keyword === 'x-astrale-path' && isJsonObject(value)) {
39
- result[keyword] = canonicalizePathAnnotation(value);
40
- }
41
- else if (SCHEMA_SINGLE_KEYWORDS.has(keyword) && isJsonSchema(value)) {
42
- result[keyword] = canonicalizeSchema(value, false, context);
43
- }
44
- else if (SCHEMA_ARRAY_KEYWORDS.has(keyword) && Array.isArray(value)) {
45
- result[keyword] = value.map((entry) => isJsonSchema(entry) ? canonicalizeSchema(entry, false, context) : canonicalizeJson(entry));
46
- }
47
- else if (SCHEMA_MAP_KEYWORDS.has(keyword) && isJsonObject(value)) {
48
- const schemas = {};
49
- for (const name of Object.keys(value).sort()) {
50
- const entry = value[name];
51
- schemas[name] = isJsonSchema(entry)
52
- ? canonicalizeSchema(entry, false, context)
53
- : canonicalizeJson(entry);
54
- }
55
- result[keyword] = schemas;
56
- }
57
- else {
58
- result[keyword] = canonicalizeJson(value);
59
- }
60
- }
61
- return result;
25
+ if (!root)
26
+ return mapMembers(schema, canonicalizeKeyword);
27
+ const { $schema: _dialect, ...members } = schema;
28
+ return mapMembers(members, canonicalizeKeyword);
62
29
  }
63
- function canonicalizeDependentRequired(value) {
64
- const result = {};
65
- for (const name of Object.keys(value).sort()) {
66
- const dependencies = value[name];
67
- if (!Array.isArray(dependencies)) {
68
- result[name] = canonicalizeJson(dependencies);
69
- continue;
70
- }
71
- assertUnique(dependencies, String, `dependentRequired.${name}`);
72
- result[name] = [...dependencies].sort((left, right) => compareUnicode(String(left), String(right)));
73
- }
74
- return result;
30
+ /**
31
+ * The members of an object in canonical order, each value mapped. A name is data: `__proto__` stays
32
+ * a member, for validation to judge, where an assignment would have set the prototype.
33
+ */
34
+ function mapMembers(value, map) {
35
+ return Object.fromEntries(Object.keys(value)
36
+ .sort()
37
+ .map((name) => [name, map(name, value[name])]));
75
38
  }
76
- function canonicalizePathAnnotation(value) {
77
- const result = {};
78
- for (const key of Object.keys(value).sort()) {
79
- const entry = value[key];
80
- if (key === 'accepts' && Array.isArray(entry)) {
81
- const accepts = entry.map(canonicalizeJson);
82
- assertUnique(accepts, json.serialize, 'x-astrale-path.accepts');
83
- result[key] = accepts.sort((left, right) => compareDefinitionRefs(left, right));
84
- }
85
- else
86
- result[key] = canonicalizeJson(entry);
39
+ function canonicalizeKeyword(keyword, value) {
40
+ if (keyword === 'required' && isStringList(value))
41
+ return [...value].sort(compareUnicode);
42
+ if (keyword === 'type' && isStringList(value)) {
43
+ return [...value].sort((left, right) => (TYPE_RANK.get(left) ?? Number.MAX_SAFE_INTEGER) -
44
+ (TYPE_RANK.get(right) ?? Number.MAX_SAFE_INTEGER));
45
+ }
46
+ if (keyword === 'enum' && Array.isArray(value)) {
47
+ return value.map(canonicalizeJson).sort(compareCanonicalBytes);
48
+ }
49
+ if (keyword === 'dependentRequired' && isJsonObject(value)) {
50
+ return mapMembers(value, (_, dependencies) => isStringList(dependencies)
51
+ ? [...dependencies].sort(compareUnicode)
52
+ : canonicalizeJson(dependencies));
53
+ }
54
+ if (keyword === 'x-astrale-path' && isJsonObject(value)) {
55
+ return mapMembers(value, canonicalizePathMember);
87
56
  }
88
- return result;
57
+ if (SCHEMA_SINGLE_KEYWORDS.has(keyword))
58
+ return canonicalizeNested(value);
59
+ if (SCHEMA_ARRAY_KEYWORDS.has(keyword) && Array.isArray(value)) {
60
+ return value.map(canonicalizeNested);
61
+ }
62
+ if (SCHEMA_MAP_KEYWORDS.has(keyword) && isJsonObject(value)) {
63
+ return mapMembers(value, (_, entry) => canonicalizeNested(entry));
64
+ }
65
+ return canonicalizeJson(value);
66
+ }
67
+ function canonicalizeNested(entry) {
68
+ return isJsonSchema(entry) ? canonicalizeSchema(entry, false) : canonicalizeJson(entry);
69
+ }
70
+ function canonicalizePathMember(name, member) {
71
+ const canonical = canonicalizeJson(member);
72
+ return name === 'accepts' && Array.isArray(canonical) && canonical.every(isComparableRef)
73
+ ? canonical.sort(compareDefinitionRefs)
74
+ : canonical;
89
75
  }
90
76
  function canonicalizeJson(value) {
91
77
  if (value === null || typeof value === 'boolean' || typeof value === 'string')
@@ -101,10 +87,7 @@ function canonicalizeJson(value) {
101
87
  return value.map(canonicalizeJson);
102
88
  if (!isJsonObject(value))
103
89
  throw new TypeError('Cannot canonicalize a non-JSON value.');
104
- const result = {};
105
- for (const key of Object.keys(value).sort())
106
- result[key] = canonicalizeJson(value[key]);
107
- return result;
90
+ return mapMembers(value, (_, member) => canonicalizeJson(member));
108
91
  }
109
92
  function compareCanonicalBytes(left, right) {
110
93
  const a = encoder.encode(json.serialize(left));
@@ -116,15 +99,12 @@ function compareCanonicalBytes(left, right) {
116
99
  }
117
100
  return a.length - b.length;
118
101
  }
119
- function assertUnique(values, keyOf, name) {
120
- const keys = new Set();
121
- for (const value of values) {
122
- const key = keyOf(value);
123
- if (keys.has(key))
124
- throw new TypeError(`${name} contains a duplicate value.`);
125
- keys.add(key);
126
- }
102
+ function isStringList(value) {
103
+ return Array.isArray(value) && value.every((entry) => typeof entry === 'string');
127
104
  }
128
- function isJsonSchema(value) {
129
- return typeof value === 'boolean' || isJsonObject(value);
105
+ function isComparableRef(value) {
106
+ return (isJsonObject(value) &&
107
+ typeof value.origin === 'string' &&
108
+ typeof value.kind === 'string' &&
109
+ typeof value.name === 'string');
130
110
  }
@@ -1,2 +1,14 @@
1
+ import { type StructuralOptions, type Value as JsonValue } from '@astrale-os/kernel-dsl/value';
1
2
  import type { Diagnostic } from '../../validation/diagnostic.js';
3
+ /**
4
+ * The snapshot of `value` as a portable JSON Value, within the portable limits `options` overrides,
5
+ * or why it is none. What evaluates an instance reads this snapshot and never `value` again: what
6
+ * admission bounded is what is read, under the limits it was bounded by.
7
+ */
8
+ export declare function acceptInstance(value: unknown, pointer: string, options?: StructuralOptions): {
9
+ readonly value: JsonValue;
10
+ } | {
11
+ readonly refusal: Diagnostic;
12
+ };
13
+ /** Whether `value` is a portable JSON Value. */
2
14
  export declare function validateCanonicalJsonDomain(value: unknown, pointer: string): readonly Diagnostic[];
@@ -1,14 +1,27 @@
1
1
  import { acceptForRead as acceptJsonValue, BoundaryError as JsonBoundaryError, } from '@astrale-os/kernel-dsl/value';
2
2
  import { diagnostic } from '../../validation/diagnostic.js';
3
- export function validateCanonicalJsonDomain(value, pointer) {
3
+ /**
4
+ * The snapshot of `value` as a portable JSON Value, within the portable limits `options` overrides,
5
+ * or why it is none. What evaluates an instance reads this snapshot and never `value` again: what
6
+ * admission bounded is what is read, under the limits it was bounded by.
7
+ */
8
+ export function acceptInstance(value, pointer, options) {
4
9
  try {
5
- acceptJsonValue(value);
6
- return [];
10
+ return { value: acceptJsonValue(value, options) };
7
11
  }
8
12
  catch (error) {
9
13
  if (error instanceof JsonBoundaryError) {
10
- return [diagnostic('VS_NUMBER_DOMAIN', `${pointer}${error.pointer}`, error.message)];
14
+ return {
15
+ refusal: diagnostic('VS_NUMBER_DOMAIN', `${pointer}${error.pointer}`, error.message),
16
+ };
11
17
  }
12
- return [diagnostic('VS_META_SCHEMA', pointer, 'Value is outside the JSON data model.')];
18
+ return {
19
+ refusal: diagnostic('VS_META_SCHEMA', pointer, 'Value is outside the JSON data model.'),
20
+ };
13
21
  }
14
22
  }
23
+ /** Whether `value` is a portable JSON Value. */
24
+ export function validateCanonicalJsonDomain(value, pointer) {
25
+ const accepted = acceptInstance(value, pointer);
26
+ return 'refusal' in accepted ? [accepted.refusal] : [];
27
+ }