@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.
- package/dist/v1/addressing/class-key.js +3 -3
- package/dist/v1/addressing/definition-ref.js +21 -37
- package/dist/v1/addressing/domain-dependency.d.ts +0 -6
- package/dist/v1/addressing/domain-dependency.js +1 -6
- package/dist/v1/addressing/key.d.ts +4 -1
- package/dist/v1/addressing/key.js +23 -3
- package/dist/v1/addressing/ordering.d.ts +2 -0
- package/dist/v1/addressing/ordering.js +2 -0
- package/dist/v1/addressing/patterns.d.ts +1 -1
- package/dist/v1/addressing/patterns.js +2 -6
- package/dist/v1/builder/callable/authoring.d.ts +11 -5
- package/dist/v1/builder/callable/authoring.js +2 -0
- package/dist/v1/builder/class/authoring.d.ts +94 -224
- package/dist/v1/builder/class/authoring.js +30 -35
- package/dist/v1/builder/class/handle.d.ts +27 -0
- package/dist/v1/builder/class/handle.js +1 -0
- package/dist/v1/builder/class/input.d.ts +159 -0
- package/dist/v1/builder/class/projection.d.ts +129 -0
- package/dist/v1/builder/class/projection.js +1 -0
- package/dist/v1/builder/class/property.d.ts +3 -9
- package/dist/v1/builder/class/property.js +1 -0
- package/dist/v1/builder/core/authoring.d.ts +1 -1
- package/dist/v1/builder/index.d.ts +10 -2
- package/dist/v1/builder/index.js +2 -0
- package/dist/v1/builder/lowering/callable.js +1 -0
- package/dist/v1/builder/lowering/class.d.ts +9 -1
- package/dist/v1/builder/lowering/class.js +62 -17
- package/dist/v1/builder/lowering/policy.js +6 -24
- package/dist/v1/builder/lowering/property-keys.d.ts +27 -0
- package/dist/v1/builder/lowering/property-keys.js +108 -0
- package/dist/v1/builder/lowering/schema/compile.js +13 -6
- package/dist/v1/builder/lowering/schema/context.d.ts +9 -1
- package/dist/v1/builder/lowering/schema/context.js +36 -7
- package/dist/v1/builder/lowering/schema/lifetime.d.ts +11 -0
- package/dist/v1/builder/lowering/schema/lifetime.js +55 -0
- package/dist/v1/builder/lowering/value/compile.js +29 -22
- package/dist/v1/builder/lowering/value/file.d.ts +7 -0
- package/dist/v1/builder/lowering/value/file.js +14 -0
- package/dist/v1/builder/lowering/value/path.d.ts +1 -1
- package/dist/v1/builder/lowering/value/path.js +2 -4
- package/dist/v1/builder/lowering/value/zod.js +41 -7
- package/dist/v1/builder/policy/authoring.d.ts +80 -9
- package/dist/v1/builder/policy/authoring.js +99 -68
- package/dist/v1/builder/policy/legacy/edge.d.ts +28 -0
- package/dist/v1/builder/policy/legacy/edge.js +16 -0
- package/dist/v1/builder/schema/define.d.ts +0 -1
- package/dist/v1/builder/schema/diagnostic.d.ts +3 -2
- package/dist/v1/builder/schema/diagnostic.js +5 -10
- package/dist/v1/builder/schema/input.d.ts +4 -1
- package/dist/v1/builder/schema/projection/callable.d.ts +7 -5
- package/dist/v1/builder/schema/projection/class.d.ts +78 -16
- package/dist/v1/builder/schema/projection/core-input.d.ts +2 -1
- package/dist/v1/builder/schema/projection/domain.d.ts +13 -2
- package/dist/v1/builder/schema/projection/identity.d.ts +74 -9
- package/dist/v1/builder/schema/projection/model.d.ts +4 -2
- package/dist/v1/builder/schema/projection/property.d.ts +38 -4
- package/dist/v1/builder/schema/projection/resolved-class.d.ts +5 -4
- package/dist/v1/builder/schema/projection.d.ts +1 -1
- package/dist/v1/builder/schema/rule.d.ts +316 -0
- package/dist/v1/builder/schema/rule.js +192 -0
- package/dist/v1/builder/value/file.d.ts +34 -0
- package/dist/v1/builder/value/file.js +77 -0
- package/dist/v1/builder/value/full-match.d.ts +0 -1
- package/dist/v1/builder/value/full-match.js +0 -1
- package/dist/v1/builder/value/path-metadata.d.ts +1 -1
- package/dist/v1/builder/value/path.d.ts +1 -1
- package/dist/v1/bundle/codec.js +55 -74
- package/dist/v1/bundle/diagnostic.d.ts +3 -1
- package/dist/v1/bundle/diagnostic.js +9 -7
- package/dist/v1/bundle/index.d.ts +2 -0
- package/dist/v1/bundle/index.js +1 -0
- package/dist/v1/bundle/model.js +1 -1
- package/dist/v1/bundle/rule.d.ts +14 -0
- package/dist/v1/bundle/rule.js +41 -0
- package/dist/v1/bundle/structure.js +6 -8
- package/dist/v1/compiled/admission/accept.js +9 -15
- package/dist/v1/compiled/admission/closure.js +17 -34
- package/dist/v1/compiled/admission/diagnostic.d.ts +23 -1
- package/dist/v1/compiled/admission/diagnostic.js +40 -3
- package/dist/v1/compiled/admission/revision.d.ts +9 -1
- package/dist/v1/compiled/admission/revision.js +7 -3
- package/dist/v1/compiled/admission/semantics/class.d.ts +4 -1
- package/dist/v1/compiled/admission/semantics/class.js +48 -19
- package/dist/v1/compiled/admission/semantics/core.d.ts +1 -24
- package/dist/v1/compiled/admission/semantics/core.js +56 -24
- package/dist/v1/compiled/admission/semantics/edge.d.ts +2 -4
- package/dist/v1/compiled/admission/semantics/edge.js +6 -65
- package/dist/v1/compiled/admission/semantics/policy/admit.js +4 -19
- package/dist/v1/compiled/admission/semantics/policy/callable.js +2 -5
- package/dist/v1/compiled/admission/semantics/policy/contracts.d.ts +5 -20
- package/dist/v1/compiled/admission/semantics/policy/contracts.js +8 -21
- package/dist/v1/compiled/admission/semantics/policy/parity.js +44 -53
- package/dist/v1/compiled/admission/semantics/policy/pattern.d.ts +4 -1
- package/dist/v1/compiled/admission/semantics/policy/pattern.js +7 -21
- package/dist/v1/compiled/admission/semantics/policy/typing.d.ts +2 -24
- package/dist/v1/compiled/admission/semantics/policy/typing.js +19 -201
- package/dist/v1/compiled/admission/wire/callable.d.ts +5 -2
- package/dist/v1/compiled/admission/wire/callable.js +24 -20
- package/dist/v1/compiled/admission/wire/class.js +79 -30
- package/dist/v1/compiled/admission/wire/entry.d.ts +1 -1
- package/dist/v1/compiled/admission/wire/entry.js +36 -13
- package/dist/v1/compiled/admission/wire/policy.d.ts +4 -3
- package/dist/v1/compiled/admission/wire/policy.js +27 -20
- package/dist/v1/compiled/admission/wire/program.d.ts +13 -3
- package/dist/v1/compiled/admission/wire/program.js +39 -44
- package/dist/v1/compiled/admission/wire/property.d.ts +4 -1
- package/dist/v1/compiled/admission/wire/property.js +8 -5
- package/dist/v1/compiled/admission/wire/value.d.ts +0 -2
- package/dist/v1/compiled/admission/wire/value.js +0 -7
- package/dist/v1/compiled/codec/json.js +4 -3
- package/dist/v1/compiled/compiler/compile.js +15 -33
- package/dist/v1/compiled/diagnostic.d.ts +1 -1
- package/dist/v1/compiled/diagnostic.js +2 -3
- package/dist/v1/compiled/index.d.ts +2 -0
- package/dist/v1/compiled/index.js +1 -0
- package/dist/v1/compiled/loader/load.d.ts +3 -2
- package/dist/v1/compiled/loader/load.js +12 -51
- package/dist/v1/compiled/model/schema.d.ts +3 -0
- package/dist/v1/compiled/rule.d.ts +49 -0
- package/dist/v1/compiled/rule.js +169 -0
- package/dist/v1/domain/create.js +9 -10
- package/dist/v1/domain/model/domain.d.ts +2 -7
- package/dist/v1/domain/model/input.d.ts +15 -10
- package/dist/v1/domain/namespace/member-collection.js +8 -7
- package/dist/v1/domain/projection/classes.js +11 -8
- package/dist/v1/domain/validation/create.d.ts +7 -16
- package/dist/v1/domain/validation/create.js +35 -81
- package/dist/v1/index.d.ts +5 -3
- package/dist/v1/index.js +1 -1
- package/dist/v1/language/.spec/schemas/draft-2020-12.schema.json +462 -0
- package/dist/v1/language/.spec/schemas/value-schema.schema.json +23 -0
- package/dist/v1/language/callable/admission.d.ts +15 -0
- package/dist/v1/language/callable/admission.js +44 -0
- package/dist/v1/language/callable/model/callable.d.ts +10 -0
- package/dist/v1/language/callable/resolved.d.ts +16 -3
- package/dist/v1/language/chain.d.ts +7 -0
- package/dist/v1/language/chain.js +24 -0
- package/dist/v1/language/class/inheritance.d.ts +36 -5
- package/dist/v1/language/class/inheritance.js +85 -1
- package/dist/v1/language/class/lifetime.d.ts +50 -11
- package/dist/v1/language/class/lifetime.js +89 -20
- package/dist/v1/language/class/model/class.d.ts +45 -9
- package/dist/v1/language/class/model/edge.d.ts +31 -2
- package/dist/v1/language/class/model/property.d.ts +16 -7
- package/dist/v1/language/class/property-values.js +2 -4
- package/dist/v1/language/class/resolved.d.ts +9 -4
- package/dist/v1/language/class/unique.d.ts +143 -0
- package/dist/v1/language/class/unique.js +264 -0
- package/dist/v1/language/core/facts.d.ts +85 -0
- package/dist/v1/language/core/facts.js +116 -0
- package/dist/v1/language/cycle.d.ts +10 -0
- package/dist/v1/language/cycle.js +30 -0
- package/dist/v1/language/definition/metadata.d.ts +38 -0
- package/dist/v1/language/definition/metadata.js +51 -0
- package/dist/v1/language/freeze.d.ts +5 -0
- package/dist/v1/{schema/canonical → language}/freeze.js +4 -0
- package/dist/v1/language/index.d.ts +7 -2
- package/dist/v1/language/index.js +5 -1
- package/dist/v1/language/limits.d.ts +83 -0
- package/dist/v1/language/limits.js +77 -0
- package/dist/v1/language/policy/analysis/branches.d.ts +8 -0
- package/dist/v1/language/policy/analysis/branches.js +8 -8
- package/dist/v1/language/policy/analysis/budgets.d.ts +45 -12
- package/dist/v1/language/policy/analysis/budgets.js +140 -20
- package/dist/v1/language/policy/analysis/checks.js +8 -6
- package/dist/v1/language/policy/analysis/composition.d.ts +4 -0
- package/dist/v1/language/policy/analysis/composition.js +11 -0
- package/dist/v1/language/policy/analysis/typing.d.ts +51 -0
- package/dist/v1/language/policy/analysis/typing.js +456 -0
- package/dist/v1/language/policy/model/policy.d.ts +71 -9
- package/dist/v1/language/policy/model/policy.js +42 -4
- package/dist/v1/language/policy/normalization/normalize.d.ts +6 -6
- package/dist/v1/language/policy/normalization/normalize.js +46 -68
- package/dist/v1/language/suspended.d.ts +7 -0
- package/dist/v1/language/suspended.js +23 -0
- package/dist/v1/language/validation/diagnostic.d.ts +15 -1
- package/dist/v1/language/validation/diagnostic.js +21 -0
- package/dist/v1/language/validation/rule.d.ts +45 -0
- package/dist/v1/language/validation/rule.js +109 -0
- package/dist/v1/language/value/compile/fields.js +16 -16
- package/dist/v1/language/value/compile/load.d.ts +5 -0
- package/dist/v1/language/value/compile/load.js +13 -0
- package/dist/v1/language/value/evaluate/assertions.d.ts +5 -1
- package/dist/v1/language/value/evaluate/assertions.js +19 -8
- package/dist/v1/language/value/evaluate/evaluator.js +117 -120
- package/dist/v1/language/value/evaluate/preparation.d.ts +16 -0
- package/dist/v1/language/value/evaluate/preparation.js +100 -47
- package/dist/v1/language/value/evaluate/program.d.ts +2 -1
- package/dist/v1/language/value/evaluate/program.js +6 -6
- package/dist/v1/language/value/evaluate/validate.d.ts +3 -3
- package/dist/v1/language/value/evaluate/validate.js +14 -10
- package/dist/v1/language/value/evaluate/validity.optimization.d.ts +14 -0
- package/dist/v1/language/value/evaluate/validity.optimization.js +338 -0
- package/dist/v1/language/value/files.d.ts +44 -0
- package/dist/v1/language/value/files.js +151 -0
- package/dist/v1/language/value/inclusion/arrays.d.ts +3 -0
- package/dist/v1/language/value/inclusion/arrays.js +85 -0
- package/dist/v1/language/value/inclusion/assertions.d.ts +18 -0
- package/dist/v1/language/value/inclusion/assertions.js +28 -0
- package/dist/v1/language/value/inclusion/combinators.d.ts +3 -0
- package/dist/v1/language/value/inclusion/combinators.js +67 -0
- package/dist/v1/language/value/inclusion/equivalence.d.ts +4 -0
- package/dist/v1/language/value/inclusion/equivalence.js +76 -0
- package/dist/v1/language/value/inclusion/evidence.d.ts +34 -0
- package/dist/v1/language/value/inclusion/evidence.js +140 -0
- package/dist/v1/language/value/inclusion/includes.d.ts +29 -3
- package/dist/v1/language/value/inclusion/includes.js +58 -723
- package/dist/v1/language/value/inclusion/keywords.d.ts +5 -0
- package/dist/v1/language/value/inclusion/keywords.js +31 -0
- package/dist/v1/language/value/inclusion/kinds.d.ts +17 -0
- package/dist/v1/language/value/inclusion/kinds.js +57 -0
- package/dist/v1/language/value/inclusion/location.d.ts +24 -0
- package/dist/v1/language/value/inclusion/location.js +66 -0
- package/dist/v1/language/value/inclusion/numbers.d.ts +3 -0
- package/dist/v1/language/value/inclusion/numbers.js +41 -0
- package/dist/v1/language/value/inclusion/objects.d.ts +3 -0
- package/dist/v1/language/value/inclusion/objects.js +190 -0
- package/dist/v1/language/value/inclusion/strings.d.ts +3 -0
- package/dist/v1/language/value/inclusion/strings.js +29 -0
- package/dist/v1/language/value/inclusion/types.d.ts +3 -0
- package/dist/v1/language/value/inclusion/types.js +34 -0
- package/dist/v1/language/value/model/blob.d.ts +6 -0
- package/dist/v1/language/value/model/blob.js +8 -0
- package/dist/v1/language/value/model/file.d.ts +41 -0
- package/dist/v1/language/value/model/file.js +122 -0
- package/dist/v1/language/value/ordering.d.ts +14 -0
- package/dist/v1/language/value/ordering.js +144 -77
- package/dist/v1/language/value/profile/canonicalize.d.ts +6 -1
- package/dist/v1/language/value/profile/canonicalize.js +67 -87
- package/dist/v1/language/value/profile/json.validate.d.ts +12 -0
- package/dist/v1/language/value/profile/json.validate.js +18 -5
- package/dist/v1/language/value/profile/meta-schema.compiled.d.ts +1 -0
- package/dist/v1/language/value/profile/meta-schema.compiled.js +21 -5
- package/dist/v1/language/value/profile/rules.js +27 -44
- package/dist/v1/language/value/profile/validate.js +1 -10
- package/dist/v1/language/value/profile/vocabulary.d.ts +36 -2
- package/dist/v1/language/value/profile/vocabulary.js +58 -5
- package/dist/v1/language/value/reference/closure.js +6 -6
- package/dist/v1/language/value/reference/recursion.js +9 -48
- package/dist/v1/language/value/reference/references.d.ts +3 -1
- package/dist/v1/language/value/reference/references.js +7 -7
- package/dist/v1/language/value/reference/registry.index.d.ts +2 -0
- package/dist/v1/language/value/reference/registry.index.js +33 -16
- package/dist/v1/language/value/regexp/ast.js +6 -7
- package/dist/v1/language/value/regexp/compile.d.ts +5 -11
- package/dist/v1/language/value/regexp/compile.js +14 -12
- package/dist/v1/language/value/regexp/syntax.js +3 -2
- package/dist/v1/language/value/regexp/unicode.d.ts +1 -1
- package/dist/v1/language/value/regexp/unicode.js +1 -1
- package/dist/v1/language/value/syntax/keywords.d.ts +3 -3
- package/dist/v1/language/value/syntax/keywords.js +4 -20
- package/dist/v1/language/value/syntax/node-path/validate.js +2 -3
- package/dist/v1/language/value/syntax/pointer.d.ts +2 -0
- package/dist/v1/language/value/syntax/pointer.js +5 -2
- package/dist/v1/language/value/syntax/walk.d.ts +9 -0
- package/dist/v1/language/value/syntax/walk.js +37 -20
- package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +2596 -0
- package/dist/v1/schema/admission/accept.d.ts +3 -1
- package/dist/v1/schema/admission/accept.js +6 -14
- package/dist/v1/schema/admission/callable.d.ts +21 -0
- package/dist/v1/schema/admission/callable.js +96 -0
- package/dist/v1/schema/analysis/class.d.ts +4 -0
- package/dist/v1/schema/analysis/class.js +57 -17
- package/dist/v1/schema/canonical/revision.d.ts +4 -1
- package/dist/v1/schema/canonical/revision.js +8 -5
- package/dist/v1/schema/compatibility/api.d.ts +4 -1
- package/dist/v1/schema/compatibility/api.js +2 -0
- package/dist/v1/schema/compatibility/comparators/callables.js +1 -1
- package/dist/v1/schema/compatibility/comparators/classes.d.ts +9 -4
- package/dist/v1/schema/compatibility/comparators/classes.js +50 -29
- package/dist/v1/schema/compatibility/comparators/index.d.ts +1 -1
- package/dist/v1/schema/compatibility/comparators/members.js +1 -1
- package/dist/v1/schema/compatibility/comparators/values.js +2 -2
- package/dist/v1/schema/compatibility/context.d.ts +5 -2
- package/dist/v1/schema/compatibility/context.js +8 -6
- package/dist/v1/schema/compatibility/coordinate.js +3 -3
- package/dist/v1/schema/compatibility/diff.js +2 -4
- package/dist/v1/schema/compatibility/extension.d.ts +11 -0
- package/dist/v1/schema/compatibility/extension.js +22 -0
- package/dist/v1/schema/compatibility/fields.d.ts +20 -4
- package/dist/v1/schema/compatibility/fields.js +13 -3
- package/dist/v1/schema/compatibility/meaning/footprint.js +16 -51
- package/dist/v1/schema/compatibility/model.d.ts +17 -5
- package/dist/v1/schema/compatibility/references.d.ts +0 -3
- package/dist/v1/schema/compatibility/references.js +1 -9
- package/dist/v1/schema/compatibility/report.js +1 -1
- package/dist/v1/schema/compatibility/rule.d.ts +13 -0
- package/dist/v1/schema/compatibility/rule.js +23 -0
- package/dist/v1/schema/compatibility/scope.d.ts +2 -0
- package/dist/v1/schema/compatibility/scope.js +4 -1
- package/dist/v1/schema/compatibility/structure/index.js +6 -4
- package/dist/v1/schema/compatibility/structure/requirements.js +58 -61
- package/dist/v1/schema/compatibility/versioning/index.js +1 -1
- package/dist/v1/schema/compatibility/versioning/surface.d.ts +1 -1
- package/dist/v1/schema/compatibility/versioning/surface.js +30 -2
- package/dist/v1/schema/compatibility/walk.d.ts +17 -0
- package/dist/v1/schema/compatibility/walk.js +41 -0
- package/dist/v1/schema/diagnostic.d.ts +17 -3
- package/dist/v1/schema/diagnostic.js +14 -11
- package/dist/v1/schema/enforcement/changes.d.ts +590 -0
- package/dist/v1/schema/enforcement/changes.js +566 -0
- package/dist/v1/schema/enforcement/derived.d.ts +236 -0
- package/dist/v1/schema/enforcement/derived.js +243 -0
- package/dist/v1/schema/enforcement/dispose.d.ts +308 -0
- package/dist/v1/schema/enforcement/dispose.js +275 -0
- package/dist/v1/schema/enforcement/facts.d.ts +89 -0
- package/dist/v1/schema/enforcement/facts.js +70 -0
- package/dist/v1/schema/enforcement/fields.d.ts +65 -0
- package/dist/v1/schema/enforcement/fields.js +36 -0
- package/dist/v1/schema/enforcement/index.d.ts +39 -0
- package/dist/v1/schema/enforcement/index.js +10 -0
- package/dist/v1/schema/enforcement/install.d.ts +1634 -0
- package/dist/v1/schema/enforcement/install.js +1223 -0
- package/dist/v1/schema/enforcement/lifecycle.d.ts +87 -0
- package/dist/v1/schema/enforcement/lifecycle.js +91 -0
- package/dist/v1/schema/enforcement/model.d.ts +253 -0
- package/dist/v1/schema/enforcement/model.js +1 -0
- package/dist/v1/schema/enforcement/obligations.d.ts +248 -0
- package/dist/v1/schema/enforcement/obligations.js +240 -0
- package/dist/v1/schema/enforcement/write.d.ts +1314 -0
- package/dist/v1/schema/enforcement/write.js +1017 -0
- package/dist/v1/schema/index.d.ts +11 -1
- package/dist/v1/schema/index.js +5 -0
- package/dist/v1/schema/model/schema.d.ts +23 -1
- package/dist/v1/schema/model/schema.js +1 -1
- package/dist/v1/schema/normalization/domain.d.ts +2 -0
- package/dist/v1/schema/normalization/domain.js +50 -13
- package/dist/v1/schema/resolution/closure.js +2 -1
- package/dist/v1/schema/resolution/context.js +17 -18
- package/dist/v1/schema/resolution/domain.d.ts +5 -0
- package/dist/v1/schema/resolution/domain.js +5 -13
- package/dist/v1/schema/resolution/origins.js +6 -8
- package/dist/v1/schema/rule.d.ts +25 -0
- package/dist/v1/schema/rule.js +459 -0
- package/dist/v1/schema/validation/callable.d.ts +35 -2
- package/dist/v1/schema/validation/callable.js +65 -9
- package/dist/v1/schema/validation/class.d.ts +6 -2
- package/dist/v1/schema/validation/class.js +128 -105
- package/dist/v1/schema/validation/core.js +103 -173
- package/dist/v1/schema/validation/domain.js +25 -15
- package/dist/v1/schema/validation/domain.json-schema.d.ts +15 -0
- package/dist/v1/schema/validation/domain.json-schema.js +222 -0
- package/dist/v1/schema/validation/domain.route.d.ts +6 -1
- package/dist/v1/schema/validation/domain.route.js +18 -0
- package/dist/v1/schema/validation/domain.structure.d.ts +7797 -0
- package/dist/v1/schema/validation/domain.structure.js +516 -160
- package/dist/v1/schema/validation/icon.d.ts +4 -0
- package/dist/v1/schema/validation/icon.js +29 -0
- package/dist/v1/schema/validation/json.json-schema.d.ts +40 -0
- package/dist/v1/schema/validation/json.json-schema.js +46 -0
- package/dist/v1/schema/validation/policy/budgets.d.ts +37 -2
- package/dist/v1/schema/validation/policy/budgets.js +94 -121
- package/dist/v1/schema/validation/policy/context.d.ts +6 -5
- package/dist/v1/schema/validation/policy/context.js +7 -10
- package/dist/v1/schema/validation/policy/objects.d.ts +1 -1
- package/dist/v1/schema/validation/policy/objects.js +6 -14
- package/dist/v1/schema/validation/policy/references.js +20 -62
- package/dist/v1/schema/validation/policy/typing.d.ts +3 -18
- package/dist/v1/schema/validation/policy/typing.js +22 -356
- package/dist/v1/schema/validation/policy/uses.d.ts +40 -3
- package/dist/v1/schema/validation/policy/uses.js +63 -91
- package/dist/v1/schema/validation/policy/validate.js +5 -5
- package/dist/v1/schema/validation/value-api.d.ts +27 -1
- package/dist/v1/schema/validation/value-api.js +37 -2
- package/dist/v1/schema/validation/value.d.ts +3 -0
- package/dist/v1/schema/validation/value.js +9 -17
- package/dist/v1/schema/validation/value.json-schema.d.ts +54 -0
- package/dist/v1/schema/validation/value.json-schema.js +163 -0
- package/dist/v1/schema/validation/view.js +4 -8
- package/dist/value/accept.d.ts +9 -3
- package/dist/value/accept.js +25 -1
- package/dist/value/canonical.d.ts +22 -1
- package/dist/value/canonical.js +114 -21
- package/dist/value/decode.d.ts +7 -0
- package/dist/value/decode.js +159 -9
- package/dist/value/equal.d.ts +9 -1
- package/dist/value/equal.js +37 -3
- package/dist/value/immutable.optimization.d.ts +2 -0
- package/dist/value/immutable.optimization.js +4 -0
- package/dist/value/index.d.ts +5 -3
- package/dist/value/index.js +2 -1
- package/dist/value/json.d.ts +2 -2
- package/dist/value/json.js +2 -2
- package/dist/value/limits.d.ts +11 -0
- package/dist/value/rule.d.ts +12 -0
- package/dist/value/rule.js +50 -0
- package/dist/value/types.d.ts +6 -0
- package/dist/value/unicode.d.ts +2 -1
- package/dist/value/unicode.js +2 -0
- package/package.json +15 -4
- package/dist/v1/builder/lowering/core-properties.d.ts +0 -10
- package/dist/v1/builder/lowering/core-properties.js +0 -76
- package/dist/v1/compiled/admission/semantics/cardinality.d.ts +0 -5
- package/dist/v1/compiled/admission/semantics/cardinality.js +0 -113
- package/dist/v1/compiled/admission/semantics/policy/equality.d.ts +0 -8
- package/dist/v1/compiled/admission/semantics/policy/equality.js +0 -27
- package/dist/v1/compiled/admission/semantics/policy/measure.d.ts +0 -9
- package/dist/v1/compiled/admission/semantics/policy/measure.js +0 -81
- package/dist/v1/compiled/admission/semantics/policy/variants.d.ts +0 -10
- package/dist/v1/compiled/admission/semantics/policy/variants.js +0 -65
- package/dist/v1/compiled/admission/wire/pattern.d.ts +0 -12
- package/dist/v1/compiled/admission/wire/pattern.js +0 -111
- package/dist/v1/language/class/index.d.ts +0 -8
- package/dist/v1/language/class/index.js +0 -1
- package/dist/v1/language/core/index.d.ts +0 -2
- package/dist/v1/language/value/index.d.ts +0 -11
- package/dist/v1/language/value/index.js +0 -8
- package/dist/v1/schema/canonical/domain.d.ts +0 -3
- package/dist/v1/schema/canonical/domain.digest.d.ts +0 -3
- package/dist/v1/schema/canonical/domain.digest.js +0 -5
- package/dist/v1/schema/canonical/domain.js +0 -5
- package/dist/v1/schema/canonical/freeze.d.ts +0 -1
- /package/dist/v1/{language/core/index.js → builder/class/input.js} +0 -0
|
@@ -1,61 +1,172 @@
|
|
|
1
|
-
import { array, boolean, custom, discriminatedUnion, enum as enumeration, lazy, literal, null as nullSchema, number, record, strictObject, string, tuple,
|
|
1
|
+
import { array, boolean, custom, discriminatedUnion, enum as enumeration, lazy, literal, null as nullSchema, number, record, registry, strictObject, string, tuple, xor, } from 'zod';
|
|
2
2
|
import { PropertyKey as SemanticPropertyKey } from '../../addressing/index.js';
|
|
3
|
-
import { CORE_SLUG_PATTERN, DEPENDENCY_ALIAS_PATTERN, DOMAIN_ORIGIN_PATTERN, DOMAIN_REVISION_PATTERN, MEMBER_NAME_PATTERN, } from '../../addressing/patterns.js';
|
|
3
|
+
import { CORE_SLUG_PATTERN, DEPENDENCY_ALIAS_PATTERN, DOMAIN_ORIGIN_PATTERN, DOMAIN_REVISION_PATTERN, MEMBER_NAME_PATTERN, PROPERTY_KEY_PATTERN, } from '../../addressing/patterns.js';
|
|
4
4
|
import { MEDIA_TYPE_PATTERN } from '../../language/class/model/data.js';
|
|
5
5
|
import * as metadata from '../../language/definition/metadata.js';
|
|
6
|
-
import {
|
|
6
|
+
import { limits } from '../../language/limits.js';
|
|
7
|
+
import { BLOB_VALUE_KIND, isBlobValueSchema } from '../../language/value/model/blob.js';
|
|
8
|
+
import { escapePointerToken } from '../../language/value/syntax/pointer.js';
|
|
9
|
+
import { SchemaError, diagnostic, } from '../diagnostic.js';
|
|
7
10
|
import { DOMAIN_FORMAT, DOMAIN_VERSION } from '../model/format.js';
|
|
8
|
-
const
|
|
9
|
-
|
|
11
|
+
export const documentJsonSchema = registry();
|
|
12
|
+
/** The marker of a union of `variants`, which `domain.json-schema.ts` states by `anyOf`. */
|
|
13
|
+
export const VARIANTS = 'x-astrale-variants';
|
|
14
|
+
/**
|
|
15
|
+
* A union of disjoint variants. It is exclusive (`xor`) so that zod reports the issues of every
|
|
16
|
+
* variant, from which `matchedVariant` decides what a refused value reports. Its variants never
|
|
17
|
+
* overlap, so JSON Schema states it as any union, by `anyOf`.
|
|
18
|
+
*/
|
|
19
|
+
function variants(options, annotation = {}) {
|
|
20
|
+
const union = xor(options);
|
|
21
|
+
documentJsonSchema.add(union, { ...annotation, [VARIANTS]: true });
|
|
22
|
+
return union;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The checks of the structure JSON Schema cannot state. The published document names each with the
|
|
26
|
+
* positions it constrains, so that a validator of the document knows what it leaves to the Kernel.
|
|
27
|
+
*/
|
|
28
|
+
export const structureRules = {
|
|
29
|
+
'unique-tuple-set': {
|
|
30
|
+
code: 'STRUCTURE_DUPLICATE_ITEM',
|
|
31
|
+
statement: 'A unique tuple is a set of fields: two tuples naming the same fields in another order are one tuple, repeated.',
|
|
32
|
+
},
|
|
33
|
+
'length-in-utf16-code-units': {
|
|
34
|
+
code: 'STRUCTURE_MAXIMUM',
|
|
35
|
+
statement: 'A maxLength counts UTF-16 code units, where JSON Schema counts code points: a string within the bound in code points and beyond it in code units is refused.',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
// The pattern refuses `__proto__`, which zod skips before any key check (`lostProtoKeys`).
|
|
39
|
+
const RESERVED_DEPENDENCY_ALIASES = ['prototype', 'constructor'];
|
|
40
|
+
const originSchema = boundedString(3, 253)
|
|
41
|
+
.regex(DOMAIN_ORIGIN_PATTERN)
|
|
42
|
+
.register(documentJsonSchema, { id: 'origin' });
|
|
43
|
+
const memberNameSchema = string()
|
|
44
|
+
.regex(MEMBER_NAME_PATTERN)
|
|
45
|
+
.register(documentJsonSchema, { id: 'name' });
|
|
10
46
|
const dependencyAliasSchema = string()
|
|
11
47
|
.regex(DEPENDENCY_ALIAS_PATTERN)
|
|
12
|
-
.refine((value) => value
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
.
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
48
|
+
.refine((value) => !RESERVED_DEPENDENCY_ALIASES.includes(value), {
|
|
49
|
+
message: 'Expected a non-reserved dependency alias.',
|
|
50
|
+
params: { structureCode: 'STRUCTURE_DEPENDENCY_ALIAS' },
|
|
51
|
+
})
|
|
52
|
+
.register(documentJsonSchema, {
|
|
53
|
+
id: 'dependency-alias',
|
|
54
|
+
not: { enum: [...RESERVED_DEPENDENCY_ALIASES] },
|
|
55
|
+
});
|
|
56
|
+
const propertyKeySchema = string()
|
|
57
|
+
.refine(SemanticPropertyKey.is, {
|
|
58
|
+
message: 'Expected a canonical PropertyKey.',
|
|
59
|
+
params: { structureCode: 'STRUCTURE_PROPERTY_KEY' },
|
|
60
|
+
})
|
|
61
|
+
.register(documentJsonSchema, { id: 'property-key', pattern: PROPERTY_KEY_PATTERN.source });
|
|
62
|
+
const coreSlugSchema = boundedString(1, 100)
|
|
63
|
+
.regex(CORE_SLUG_PATTERN)
|
|
64
|
+
.register(documentJsonSchema, { id: 'core-slug' });
|
|
65
|
+
const revisionSchema = string()
|
|
66
|
+
.regex(DOMAIN_REVISION_PATTERN)
|
|
67
|
+
.register(documentJsonSchema, { id: 'revision' });
|
|
68
|
+
const descriptionSchema = boundedString(metadata.description.minLength, metadata.description.maxLength, 'description');
|
|
69
|
+
const iconSchema = boundedString(metadata.icon.minLength, metadata.icon.maxLength, 'icon');
|
|
70
|
+
const domainNameSchema = boundedString(metadata.name.minLength, metadata.name.maxLength)
|
|
71
|
+
.refine(metadata.isDomainNameText, {
|
|
72
|
+
message: 'Expected one trimmed line of text.',
|
|
73
|
+
params: { structureCode: 'STRUCTURE_DOMAIN_NAME' },
|
|
74
|
+
})
|
|
75
|
+
.register(documentJsonSchema, {
|
|
76
|
+
id: 'domain-name',
|
|
77
|
+
description: 'The display name of the Domain: one trimmed line of text.',
|
|
78
|
+
pattern: metadata.DOMAIN_NAME_TEXT_PATTERN.source,
|
|
79
|
+
});
|
|
80
|
+
// The shape of a Domain icon. Its UTF-8 bounds, its SVG grammar and that it draws at least one size
|
|
81
|
+
// are the rule DV_DOMAIN_ICON, which reads each text whole.
|
|
82
|
+
const domainIconArtSchema = strictObject({
|
|
83
|
+
svg: boundedString(1),
|
|
84
|
+
dark: boundedString(1).optional(),
|
|
85
|
+
}).register(documentJsonSchema, { id: 'domain-icon-art' });
|
|
86
|
+
const domainIconSchema = strictObject({
|
|
87
|
+
small: domainIconArtSchema.optional(),
|
|
88
|
+
medium: domainIconArtSchema.optional(),
|
|
89
|
+
large: domainIconArtSchema.optional(),
|
|
90
|
+
}).register(documentJsonSchema, {
|
|
91
|
+
id: 'domain-icon',
|
|
92
|
+
description: 'The presentation icon of the Domain: up to three hand-drawn sizes of inline SVG.',
|
|
93
|
+
});
|
|
94
|
+
// The parsed document cannot keep a `__proto__` member, which the structure therefore refuses: a
|
|
95
|
+
// closed object reports it as an unknown key, and a record, which skips it, by `lostProtoKeys`. The
|
|
96
|
+
// JSON Schema refuses it by the fields of a closed object and the pattern of a record's names; a
|
|
97
|
+
// record of any string states it here, by its property names.
|
|
98
|
+
const PROTO_KEY = '__proto__';
|
|
99
|
+
const PROTO_KEY_MESSAGE = 'A member named __proto__ is refused: the parsed document cannot keep it.';
|
|
100
|
+
const anyKeyRecord = { propertyNames: { not: { const: PROTO_KEY } } };
|
|
101
|
+
const jsonValueSchema = lazy(() => variants([
|
|
25
102
|
nullSchema(),
|
|
26
103
|
boolean(),
|
|
27
104
|
number(),
|
|
28
105
|
string(),
|
|
29
106
|
array(jsonValueSchema),
|
|
30
|
-
record(string(), jsonValueSchema),
|
|
31
|
-
]));
|
|
32
|
-
const jsonObjectSchema = record(string(), jsonValueSchema);
|
|
33
|
-
const jsonSchemaSchema =
|
|
107
|
+
record(string(), jsonValueSchema).register(documentJsonSchema, anyKeyRecord),
|
|
108
|
+
])).register(documentJsonSchema, { id: 'json-value' });
|
|
109
|
+
const jsonObjectSchema = record(string(), jsonValueSchema).register(documentJsonSchema, anyKeyRecord);
|
|
110
|
+
const jsonSchemaSchema = variants([boolean(), jsonObjectSchema], {
|
|
111
|
+
id: 'value-schema',
|
|
112
|
+
description: 'A value schema of the dialect https://schemas.astrale.ai/dsl/v1/value-schema. The structure admits any boolean or object; the language admits its keywords.',
|
|
113
|
+
});
|
|
34
114
|
const dataDeclarationSchema = strictObject({
|
|
35
|
-
mediaType: string().regex(MEDIA_TYPE_PATTERN),
|
|
115
|
+
mediaType: string().regex(MEDIA_TYPE_PATTERN).register(documentJsonSchema, { id: 'media-type' }),
|
|
116
|
+
});
|
|
117
|
+
const stateNameSchema = boundedString(1);
|
|
118
|
+
// A custom check reads the relation in place: a record would copy it and drop a `__proto__` state.
|
|
119
|
+
const stateTransitionsSchema = custom(isStateTransitions, {
|
|
120
|
+
message: 'Expected each non-empty state to map non-empty events to non-empty states.',
|
|
121
|
+
params: { structureCode: 'STRUCTURE_STATE_TRANSITIONS' },
|
|
122
|
+
}).register(documentJsonSchema, {
|
|
123
|
+
type: 'object',
|
|
124
|
+
propertyNames: { type: 'string', minLength: 1 },
|
|
125
|
+
additionalProperties: {
|
|
126
|
+
type: 'object',
|
|
127
|
+
propertyNames: { type: 'string', minLength: 1 },
|
|
128
|
+
additionalProperties: { type: 'string', minLength: 1 },
|
|
129
|
+
},
|
|
36
130
|
});
|
|
37
|
-
const stateNameSchema = string().min(1);
|
|
38
|
-
const stateTransitionsSchema = custom(isStateTransitions);
|
|
39
131
|
const stateTopologySchema = strictObject({
|
|
40
132
|
initial: stateNameSchema,
|
|
41
133
|
transitions: stateTransitionsSchema,
|
|
42
|
-
});
|
|
43
|
-
const
|
|
134
|
+
}).register(documentJsonSchema, { id: 'state-topology' });
|
|
135
|
+
const propertyShape = {
|
|
44
136
|
schema: jsonSchemaSchema,
|
|
45
137
|
required: boolean(),
|
|
46
138
|
auto: strictObject({
|
|
47
|
-
on: uniqueArray(enumeration(['create', 'update']))
|
|
139
|
+
on: nonEmpty(uniqueArray(enumeration(['create', 'update']))),
|
|
48
140
|
set: literal('instant'),
|
|
49
|
-
})
|
|
141
|
+
})
|
|
142
|
+
.register(documentJsonSchema, { id: 'auto' })
|
|
143
|
+
.optional(),
|
|
50
144
|
immutable: enumeration(['create', 'once']).optional(),
|
|
51
145
|
description: descriptionSchema.optional(),
|
|
52
|
-
|
|
146
|
+
};
|
|
147
|
+
const nodePropertyRecordSchema = record(memberNameSchema, strictObject({ ...propertyShape, state: stateTopologySchema.optional() }).register(documentJsonSchema, { id: 'node-property-definition' })).register(documentJsonSchema, { id: 'node-property-record' });
|
|
148
|
+
// An Edge has no State Property, and only a Node holds Blob contents.
|
|
149
|
+
const BLOB_KIND_KEYWORD = 'x-astrale-value-kind';
|
|
150
|
+
const edgePropertySchema = jsonSchemaSchema
|
|
151
|
+
.refine((value) => !isBlobValueSchema(value), {
|
|
152
|
+
message: 'Blob values are held only by Node Properties.',
|
|
153
|
+
path: [BLOB_KIND_KEYWORD],
|
|
154
|
+
params: { structureCode: 'STRUCTURE_EDGE_BLOB' },
|
|
155
|
+
})
|
|
156
|
+
.register(documentJsonSchema, {
|
|
157
|
+
not: {
|
|
158
|
+
type: 'object',
|
|
159
|
+
required: [BLOB_KIND_KEYWORD],
|
|
160
|
+
properties: { [BLOB_KIND_KEYWORD]: { const: BLOB_VALUE_KIND } },
|
|
161
|
+
},
|
|
53
162
|
});
|
|
54
|
-
const
|
|
163
|
+
const edgePropertyRecordSchema = record(memberNameSchema, strictObject({ ...propertyShape, schema: edgePropertySchema }).register(documentJsonSchema, {
|
|
164
|
+
id: 'edge-property-definition',
|
|
165
|
+
})).register(documentJsonSchema, { id: 'edge-property-record' });
|
|
55
166
|
const domainDependencySchema = strictObject({
|
|
56
167
|
origin: originSchema,
|
|
57
168
|
revision: revisionSchema,
|
|
58
|
-
});
|
|
169
|
+
}).register(documentJsonSchema, { id: 'dependency' });
|
|
59
170
|
const classRefSchema = absoluteRefSchema('class');
|
|
60
171
|
const functionRefSchema = absoluteRefSchema('function');
|
|
61
172
|
const policyRefSchema = absoluteRefSchema('policy');
|
|
@@ -64,40 +175,67 @@ const coreRefSchema = strictObject({
|
|
|
64
175
|
origin: originSchema,
|
|
65
176
|
kind: literal('core'),
|
|
66
177
|
name: coreSlugSchema,
|
|
178
|
+
}).register(documentJsonSchema, { id: 'core-ref' });
|
|
179
|
+
const domainRefSchema = strictObject({ kind: literal('domain') }).register(documentJsonSchema, {
|
|
180
|
+
id: 'domain-endpoint',
|
|
67
181
|
});
|
|
68
|
-
const domainRefSchema = strictObject({ kind: literal('domain') });
|
|
69
182
|
/** Every Definition whose installed projection resolves through one exact member Path. */
|
|
70
183
|
const projectedMemberRefOptions = [
|
|
71
|
-
strictObject({
|
|
184
|
+
strictObject({
|
|
185
|
+
kind: literal('method'),
|
|
186
|
+
owner: classRefSchema,
|
|
187
|
+
name: memberNameSchema,
|
|
188
|
+
}).register(documentJsonSchema, { id: 'method-address' }),
|
|
72
189
|
classRefSchema,
|
|
73
190
|
functionRefSchema,
|
|
74
191
|
policyRefSchema,
|
|
75
192
|
viewRefSchema,
|
|
76
193
|
coreRefSchema,
|
|
77
194
|
];
|
|
78
|
-
const policyObjectRefSchema = discriminatedUnion('kind', projectedMemberRefOptions);
|
|
195
|
+
const policyObjectRefSchema = discriminatedUnion('kind', projectedMemberRefOptions).register(documentJsonSchema, { id: 'projected-member-ref' });
|
|
79
196
|
const coreEndpointRefSchema = discriminatedUnion('kind', [
|
|
80
197
|
...projectedMemberRefOptions,
|
|
81
198
|
domainRefSchema,
|
|
82
|
-
]);
|
|
199
|
+
]).register(documentJsonSchema, { id: 'core-endpoint' });
|
|
83
200
|
const edgeEndpointBaseShape = {
|
|
84
201
|
role: memberNameSchema,
|
|
85
|
-
accepts: uniqueArray(classRefSchema)
|
|
202
|
+
accepts: nonEmpty(uniqueArray(classRefSchema)),
|
|
203
|
+
onDelete: enumeration(['restrict', 'detach'])
|
|
204
|
+
.register(documentJsonSchema, { id: 'edge-lifetime' })
|
|
205
|
+
.optional(),
|
|
86
206
|
};
|
|
87
|
-
const edgeCountSchema = enumeration(['0..*', '1..*', '0..1', '1'])
|
|
88
|
-
|
|
89
|
-
source: strictObject({ ...edgeEndpointBaseShape, outgoing: edgeCountSchema }),
|
|
90
|
-
target: strictObject({ ...edgeEndpointBaseShape, incoming: edgeCountSchema }),
|
|
207
|
+
const edgeCountSchema = enumeration(['0..*', '1..*', '0..1', '1']).register(documentJsonSchema, {
|
|
208
|
+
id: 'edge-count',
|
|
91
209
|
});
|
|
210
|
+
const directedEdgeEndpointsSchema = strictObject({
|
|
211
|
+
source: strictObject({ ...edgeEndpointBaseShape, outgoing: edgeCountSchema }).register(documentJsonSchema, { id: 'directed-source-endpoint' }),
|
|
212
|
+
target: strictObject({ ...edgeEndpointBaseShape, incoming: edgeCountSchema }).register(documentJsonSchema, { id: 'directed-target-endpoint' }),
|
|
213
|
+
}).register(documentJsonSchema, { id: 'directed-endpoints' });
|
|
92
214
|
const incidentEndpointSchema = strictObject({
|
|
93
215
|
...edgeEndpointBaseShape,
|
|
94
216
|
incident: edgeCountSchema,
|
|
95
|
-
});
|
|
96
|
-
const undirectedEdgeEndpointsSchema = tuple([
|
|
217
|
+
}).register(documentJsonSchema, { id: 'incident-endpoint' });
|
|
218
|
+
const undirectedEdgeEndpointsSchema = tuple([
|
|
219
|
+
incidentEndpointSchema,
|
|
220
|
+
incidentEndpointSchema,
|
|
221
|
+
]).register(documentJsonSchema, { id: 'undirected-endpoints' });
|
|
97
222
|
const edgeConstraintsSchema = strictObject({
|
|
98
223
|
noSelf: literal(true).optional(),
|
|
99
224
|
acyclic: literal(true).optional(),
|
|
100
|
-
});
|
|
225
|
+
}).register(documentJsonSchema, { id: 'edge-constraints' });
|
|
226
|
+
// A tuple names distinct fields: endpoints, the slug and Properties by key. Normalization puts
|
|
227
|
+
// them, and the tuples, in canonical order (`compareEdgeUniqueFields`). No tuple is spelled by the
|
|
228
|
+
// absence of the field, never by an empty list: one spelling per meaning, one revision.
|
|
229
|
+
const edgeUniqueFieldSchema = variants([
|
|
230
|
+
literal('source'),
|
|
231
|
+
literal('target'),
|
|
232
|
+
literal('slug'),
|
|
233
|
+
strictObject({ property: propertyKeySchema }),
|
|
234
|
+
], { id: 'edge-unique-field' });
|
|
235
|
+
const edgeUniqueSchema = nonEmpty(uniqueTupleSet(nonEmpty(uniqueArray(edgeUniqueFieldSchema))));
|
|
236
|
+
// A Node tuple names distinct Properties by key, which normalization puts in code-point order, as
|
|
237
|
+
// it does the tuples (`compareNodeUniqueTuples`). Two orders of one set of keys are one tuple.
|
|
238
|
+
const nodeUniqueSchema = nonEmpty(uniqueTupleSet(nonEmpty(uniqueArray(propertyKeySchema))));
|
|
101
239
|
const policyPatternSubjectSchema = strictObject({ kind: literal('subject') });
|
|
102
240
|
const policyPatternObjectSchema = strictObject({ kind: literal('object') });
|
|
103
241
|
const policyPatternSourceSchema = strictObject({ kind: literal('source') });
|
|
@@ -105,7 +243,7 @@ const policyPatternTargetSchema = strictObject({ kind: literal('target') });
|
|
|
105
243
|
const policyPatternVariableSchema = strictObject({
|
|
106
244
|
kind: literal('variable'),
|
|
107
245
|
id: number().int().min(0),
|
|
108
|
-
});
|
|
246
|
+
}).register(documentJsonSchema, { id: 'policy-pattern-variable' });
|
|
109
247
|
const policyPatternNodeSchema = discriminatedUnion('kind', [
|
|
110
248
|
policyPatternSubjectSchema,
|
|
111
249
|
policyPatternObjectSchema,
|
|
@@ -113,20 +251,20 @@ const policyPatternNodeSchema = discriminatedUnion('kind', [
|
|
|
113
251
|
policyPatternTargetSchema,
|
|
114
252
|
policyPatternVariableSchema,
|
|
115
253
|
strictObject({ kind: literal('ref'), ref: policyObjectRefSchema }),
|
|
116
|
-
]);
|
|
254
|
+
]).register(documentJsonSchema, { id: 'policy-pattern-node' });
|
|
117
255
|
const policyVariableSelectorSchema = discriminatedUnion('kind', [
|
|
118
256
|
strictObject({ kind: literal('any') }),
|
|
119
257
|
strictObject({ kind: literal('satisfies'), class: classRefSchema }),
|
|
120
|
-
]);
|
|
121
|
-
const policyVariableSchema =
|
|
258
|
+
]).register(documentJsonSchema, { id: 'policy-variable-selector' });
|
|
259
|
+
const policyVariableSchema = variants([
|
|
122
260
|
strictObject({ variable: policyPatternVariableSchema, class: classRefSchema }),
|
|
123
261
|
strictObject({ variable: policyPatternVariableSchema, selector: policyVariableSelectorSchema }),
|
|
124
|
-
]);
|
|
262
|
+
], { id: 'policy-variable' });
|
|
125
263
|
const policyRepeatSchema = strictObject({
|
|
126
|
-
min: number().int().min(0).max(
|
|
127
|
-
max: number().int().min(0).max(
|
|
128
|
-
});
|
|
129
|
-
const policyPatternExpressionSchema = lazy(() =>
|
|
264
|
+
min: number().int().min(0).max(limits.policy.repetition),
|
|
265
|
+
max: number().int().min(0).max(limits.policy.repetition),
|
|
266
|
+
}).register(documentJsonSchema, { id: 'policy-repeat' });
|
|
267
|
+
const policyPatternExpressionSchema = lazy(() => variants([
|
|
130
268
|
strictObject({
|
|
131
269
|
sameNode: strictObject({ left: policyPatternNodeSchema, right: policyPatternNodeSchema }),
|
|
132
270
|
}),
|
|
@@ -138,17 +276,13 @@ const policyPatternExpressionSchema = lazy(() => union([
|
|
|
138
276
|
}),
|
|
139
277
|
strictObject({
|
|
140
278
|
exists: strictObject({
|
|
141
|
-
nodes: array(policyVariableSchema).
|
|
279
|
+
nodes: nonEmpty(array(policyVariableSchema).max(limits.policy.variablesPerExists)),
|
|
142
280
|
where: policyPatternExpressionSchema,
|
|
143
281
|
}),
|
|
144
282
|
}),
|
|
145
|
-
strictObject({
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
strictObject({
|
|
149
|
-
anyOf: array(policyPatternExpressionSchema).min(1),
|
|
150
|
-
}),
|
|
151
|
-
]));
|
|
283
|
+
strictObject({ allOf: nonEmpty(array(policyPatternExpressionSchema)) }),
|
|
284
|
+
strictObject({ anyOf: nonEmpty(array(policyPatternExpressionSchema)) }),
|
|
285
|
+
])).register(documentJsonSchema, { id: 'policy-pattern-expr' });
|
|
152
286
|
const selfObjectSchema = strictObject({ kind: literal('self') });
|
|
153
287
|
const refObjectSchema = strictObject({ kind: literal('ref'), ref: policyObjectRefSchema });
|
|
154
288
|
const policyCheckObjectSchema = discriminatedUnion('kind', [
|
|
@@ -158,21 +292,26 @@ const policyCheckObjectSchema = discriminatedUnion('kind', [
|
|
|
158
292
|
field: memberNameSchema,
|
|
159
293
|
}),
|
|
160
294
|
refObjectSchema,
|
|
161
|
-
]);
|
|
162
|
-
/** A
|
|
163
|
-
const classRuleObjectSchema = discriminatedUnion('kind', [
|
|
295
|
+
]).register(documentJsonSchema, { id: 'policy-check-object' });
|
|
296
|
+
/** A Class rule checks the observed or written instance or one exact member: it has no input. */
|
|
297
|
+
const classRuleObjectSchema = discriminatedUnion('kind', [
|
|
298
|
+
selfObjectSchema,
|
|
299
|
+
refObjectSchema,
|
|
300
|
+
]).register(documentJsonSchema, { id: 'class-rule-object' });
|
|
164
301
|
/** The recursive Policy check grammar, over the objects one use site admits. */
|
|
165
|
-
function policyChecksSchema(objectSchema) {
|
|
166
|
-
const checks = lazy(() =>
|
|
302
|
+
function policyChecksSchema(objectSchema, id) {
|
|
303
|
+
const checks = lazy(() => variants([
|
|
167
304
|
strictObject({ sameNode: strictObject({ left: objectSchema, right: objectSchema }) }),
|
|
168
305
|
strictObject({ check: policyRefSchema, object: objectSchema }),
|
|
169
|
-
strictObject({ allOf: array(checks)
|
|
170
|
-
strictObject({ anyOf: array(checks)
|
|
171
|
-
]));
|
|
306
|
+
strictObject({ allOf: nonEmpty(array(checks)) }),
|
|
307
|
+
strictObject({ anyOf: nonEmpty(array(checks)) }),
|
|
308
|
+
])).register(documentJsonSchema, { id });
|
|
172
309
|
return checks;
|
|
173
310
|
}
|
|
174
|
-
const policyCheckExpressionSchema = policyChecksSchema(policyCheckObjectSchema);
|
|
175
|
-
const classRuleChecksSchema = policyChecksSchema(classRuleObjectSchema);
|
|
311
|
+
const policyCheckExpressionSchema = policyChecksSchema(policyCheckObjectSchema, 'policy-check-expr');
|
|
312
|
+
const classRuleChecksSchema = policyChecksSchema(classRuleObjectSchema, 'class-rule-check-expr');
|
|
313
|
+
/** A Node create rule has no Node to check yet: its objects are exact members only. */
|
|
314
|
+
const createRuleChecksSchema = policyChecksSchema(refObjectSchema, 'create-rule-check-expr');
|
|
176
315
|
const callableOutputSchema = discriminatedUnion('mode', [
|
|
177
316
|
strictObject({
|
|
178
317
|
mode: literal('value'),
|
|
@@ -185,143 +324,198 @@ const callableOutputSchema = discriminatedUnion('mode', [
|
|
|
185
324
|
strictObject({
|
|
186
325
|
mode: literal('binary'),
|
|
187
326
|
}),
|
|
188
|
-
]);
|
|
327
|
+
]).register(documentJsonSchema, { id: 'callable-output' });
|
|
189
328
|
const binaryInputSchema = strictObject({
|
|
190
329
|
mode: literal('binary'),
|
|
191
330
|
metadata: jsonSchemaSchema,
|
|
192
331
|
maximumBytes: number().int().min(1).max(Number.MAX_SAFE_INTEGER),
|
|
332
|
+
}).register(documentJsonSchema, { id: 'binary-input' });
|
|
333
|
+
const valueFunctionInputSchema = jsonSchemaSchema
|
|
334
|
+
.refine((value) => typeof value !== 'object' || value === null || value.mode !== 'binary', {
|
|
335
|
+
message: 'Binary input must declare metadata and maximumBytes.',
|
|
336
|
+
params: { structureCode: 'STRUCTURE_BINARY_INPUT' },
|
|
337
|
+
})
|
|
338
|
+
.register(documentJsonSchema, {
|
|
339
|
+
not: { type: 'object', required: ['mode'], properties: { mode: { const: 'binary' } } },
|
|
193
340
|
});
|
|
194
|
-
const valueFunctionInputSchema = jsonSchemaSchema.refine((value) => typeof value !== 'object' || value === null || value.mode !== 'binary', 'Binary input must declare metadata and maximumBytes.');
|
|
195
341
|
const callableExecutionSchema = strictObject({
|
|
196
342
|
durable: boolean(),
|
|
197
|
-
});
|
|
343
|
+
}).register(documentJsonSchema, { id: 'callable-execution' });
|
|
344
|
+
// Its range is language meaning, refused by callable validation with DV_CALLABLE_ADMISSION.
|
|
345
|
+
const callableAdmissionSchema = strictObject({
|
|
346
|
+
maxAge: number(),
|
|
347
|
+
}).register(documentJsonSchema, { id: 'callable-admission' });
|
|
198
348
|
const callableShape = {
|
|
199
349
|
description: descriptionSchema.optional(),
|
|
200
350
|
input: jsonSchemaSchema,
|
|
201
351
|
output: callableOutputSchema,
|
|
202
352
|
execution: callableExecutionSchema.optional(),
|
|
353
|
+
admission: callableAdmissionSchema.optional(),
|
|
203
354
|
auth: enumeration(['anonymous', 'authenticated', 'authorized']),
|
|
204
|
-
policy:
|
|
355
|
+
policy: variants([literal(true), policyCheckExpressionSchema], {
|
|
356
|
+
id: 'callable-policy',
|
|
357
|
+
}).optional(),
|
|
358
|
+
};
|
|
359
|
+
const authorizedPolicy = {
|
|
360
|
+
if: { properties: { auth: { enum: ['anonymous', 'authenticated'] } }, required: ['auth'] },
|
|
361
|
+
// oxlint-disable-next-line unicorn/no-thenable -- the JSON Schema keyword
|
|
362
|
+
then: { properties: { policy: false } },
|
|
205
363
|
};
|
|
206
364
|
const methodDeclarationSchema = strictObject({
|
|
207
365
|
...callableShape,
|
|
208
366
|
static: boolean(),
|
|
209
367
|
abstract: boolean(),
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
368
|
+
})
|
|
369
|
+
.refine((method) => method.auth === 'authorized' || method.policy === undefined, callablePolicyIssue('method'))
|
|
370
|
+
.register(documentJsonSchema, { id: 'method-definition', ...authorizedPolicy });
|
|
371
|
+
const methodRecordSchema = record(memberNameSchema, methodDeclarationSchema).register(documentJsonSchema, {
|
|
372
|
+
id: 'method-record',
|
|
373
|
+
});
|
|
374
|
+
// Each slot spells one constant: the other one is what its absence already means.
|
|
375
|
+
const observationPolicySchema = variants([literal(false), policyRefSchema, classRuleChecksSchema], {
|
|
376
|
+
id: 'observation-policy',
|
|
377
|
+
});
|
|
378
|
+
const writePolicySchema = variants([literal(true), policyRefSchema, classRuleChecksSchema], {
|
|
379
|
+
id: 'write-policy',
|
|
380
|
+
});
|
|
381
|
+
const createPolicySchema = variants([literal(true), createRuleChecksSchema], {
|
|
382
|
+
id: 'create-policy',
|
|
219
383
|
});
|
|
220
|
-
const methodRecordSchema = record(memberNameSchema, methodDeclarationSchema);
|
|
221
|
-
const classPolicySchema = union([literal(false), policyRefSchema]);
|
|
222
|
-
const nodeClassPolicySchema = union([classPolicySchema, classRuleChecksSchema]);
|
|
223
384
|
const nodeClassPoliciesSchema = strictObject({
|
|
224
|
-
read:
|
|
225
|
-
traverse:
|
|
385
|
+
read: observationPolicySchema.optional(),
|
|
386
|
+
traverse: observationPolicySchema.optional(),
|
|
387
|
+
create: createPolicySchema.optional(),
|
|
388
|
+
update: writePolicySchema.optional(),
|
|
389
|
+
delete: writePolicySchema.optional(),
|
|
226
390
|
});
|
|
227
391
|
const edgeClassPoliciesSchema = strictObject({
|
|
228
|
-
read:
|
|
229
|
-
traverse:
|
|
392
|
+
read: observationPolicySchema.optional(),
|
|
393
|
+
traverse: observationPolicySchema.optional(),
|
|
394
|
+
create: writePolicySchema.optional(),
|
|
395
|
+
update: writePolicySchema.optional(),
|
|
396
|
+
delete: writePolicySchema.optional(),
|
|
230
397
|
});
|
|
398
|
+
// The default `'internal'` is the absence of the field: one spelling per meaning, one revision.
|
|
399
|
+
const inheritanceSchema = enumeration(['open', 'final']);
|
|
231
400
|
const nodeClassSchema = strictObject({
|
|
232
401
|
ref: classRefSchema,
|
|
233
402
|
kind: literal('node'),
|
|
234
403
|
abstract: boolean(),
|
|
404
|
+
inheritance: inheritanceSchema.optional(),
|
|
235
405
|
description: descriptionSchema.optional(),
|
|
236
406
|
extends: uniqueArray(classRefSchema),
|
|
237
|
-
properties:
|
|
407
|
+
properties: nodePropertyRecordSchema,
|
|
238
408
|
methods: methodRecordSchema,
|
|
239
409
|
data: dataDeclarationSchema.optional(),
|
|
240
410
|
icon: iconSchema.optional(),
|
|
241
411
|
policies: nodeClassPoliciesSchema,
|
|
242
|
-
|
|
243
|
-
|
|
412
|
+
unique: nodeUniqueSchema.optional(),
|
|
413
|
+
}).register(documentJsonSchema, { id: 'node-class' });
|
|
414
|
+
const orientationIssue = { params: { structureCode: 'STRUCTURE_EDGE_ORIENTATION' } };
|
|
415
|
+
const edgeClassSchema = strictObject({
|
|
244
416
|
ref: classRefSchema,
|
|
245
417
|
kind: literal('edge'),
|
|
246
418
|
abstract: boolean(),
|
|
419
|
+
inheritance: inheritanceSchema.optional(),
|
|
247
420
|
description: descriptionSchema.optional(),
|
|
248
421
|
extends: uniqueArray(classRefSchema),
|
|
249
|
-
properties:
|
|
422
|
+
properties: edgePropertyRecordSchema,
|
|
250
423
|
constraints: edgeConstraintsSchema,
|
|
251
|
-
|
|
252
|
-
const edgeClassSchema = strictObject({
|
|
253
|
-
...edgeClassShape,
|
|
424
|
+
unique: edgeUniqueSchema.optional(),
|
|
254
425
|
orientation: enumeration(['directed', 'undirected']),
|
|
255
|
-
endpoints:
|
|
426
|
+
endpoints: variants([directedEdgeEndpointsSchema, undirectedEdgeEndpointsSchema]),
|
|
256
427
|
policies: edgeClassPoliciesSchema,
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
428
|
+
})
|
|
429
|
+
.refine((edge) => (edge.orientation === 'undirected') === Array.isArray(edge.endpoints), {
|
|
430
|
+
...orientationIssue,
|
|
431
|
+
path: ['endpoints'],
|
|
432
|
+
error: 'Edge endpoints do not have the structural shape of its orientation.',
|
|
433
|
+
})
|
|
434
|
+
.refine((edge) => edge.orientation === 'directed' || edge.unique === undefined, {
|
|
435
|
+
...orientationIssue,
|
|
436
|
+
path: ['unique'],
|
|
437
|
+
error: 'Only a directed Edge Class declares unique tuples.',
|
|
438
|
+
})
|
|
439
|
+
.refine((edge) => edge.orientation === 'directed' || edge.constraints.acyclic === undefined, {
|
|
440
|
+
...orientationIssue,
|
|
441
|
+
path: ['constraints', 'acyclic'],
|
|
442
|
+
error: 'Only a directed Edge Class is acyclic.',
|
|
443
|
+
})
|
|
444
|
+
.register(documentJsonSchema, {
|
|
445
|
+
id: 'edge-class',
|
|
446
|
+
if: { properties: { orientation: { const: 'undirected' } }, required: ['orientation'] },
|
|
447
|
+
// oxlint-disable-next-line unicorn/no-thenable -- the JSON Schema keyword
|
|
448
|
+
then: {
|
|
449
|
+
properties: {
|
|
450
|
+
endpoints: { type: 'array' },
|
|
451
|
+
unique: false,
|
|
452
|
+
constraints: { type: 'object', properties: { acyclic: false } },
|
|
453
|
+
},
|
|
454
|
+
},
|
|
455
|
+
else: { properties: { endpoints: { type: 'object' } } },
|
|
456
|
+
});
|
|
457
|
+
const classDeclarationSchema = discriminatedUnion('kind', [
|
|
458
|
+
nodeClassSchema,
|
|
459
|
+
edgeClassSchema,
|
|
460
|
+
]).register(documentJsonSchema, { id: 'class-definition' });
|
|
461
|
+
const functionContractShape = {
|
|
462
|
+
...callableShape,
|
|
463
|
+
input: variants([binaryInputSchema, valueFunctionInputSchema]),
|
|
464
|
+
};
|
|
269
465
|
const functionDefinitionSchema = strictObject({
|
|
270
466
|
ref: functionRefSchema,
|
|
271
|
-
...
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
message: 'Only an authorized function may declare a policy.',
|
|
279
|
-
params: { structureCode: 'STRUCTURE_CALLABLE_POLICY_AUTH' },
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
const policyExpressionSchema = union([
|
|
467
|
+
...functionContractShape,
|
|
468
|
+
})
|
|
469
|
+
.refine((callable) => callable.auth === 'authorized' || callable.policy === undefined, callablePolicyIssue('function'))
|
|
470
|
+
.register(documentJsonSchema, { id: 'function-definition', ...authorizedPolicy });
|
|
471
|
+
// A callable contract has the structure of a Function declaration without its ref, wherever it is.
|
|
472
|
+
const callableContractSchema = strictObject(functionContractShape).refine((callable) => callable.auth === 'authorized' || callable.policy === undefined, callablePolicyIssue('function'));
|
|
473
|
+
const policyExpressionSchema = variants([
|
|
284
474
|
strictObject({
|
|
285
475
|
match: policyPatternExpressionSchema,
|
|
286
476
|
}),
|
|
287
|
-
strictObject({
|
|
288
|
-
|
|
289
|
-
}),
|
|
290
|
-
strictObject({
|
|
291
|
-
anyOf: array(policyRefSchema).min(1),
|
|
292
|
-
}),
|
|
477
|
+
strictObject({ allOf: nonEmpty(array(policyRefSchema)) }),
|
|
478
|
+
strictObject({ anyOf: nonEmpty(array(policyRefSchema)) }),
|
|
293
479
|
]);
|
|
294
480
|
const policyDefinitionSchema = strictObject({
|
|
295
481
|
ref: policyRefSchema,
|
|
296
482
|
expression: policyExpressionSchema,
|
|
297
483
|
description: descriptionSchema.optional(),
|
|
484
|
+
}).register(documentJsonSchema, { id: 'policy-definition' });
|
|
485
|
+
const viewTargetSchema = strictObject({ kind: literal('domain') }).register(documentJsonSchema, {
|
|
486
|
+
id: 'view-target',
|
|
487
|
+
description: 'Every View targets its owning Domain.',
|
|
298
488
|
});
|
|
299
|
-
const viewTargetSchema = strictObject({ kind: literal('domain') });
|
|
300
489
|
const viewDefinitionSchema = strictObject({
|
|
301
490
|
ref: viewRefSchema,
|
|
302
491
|
description: descriptionSchema.optional(),
|
|
303
492
|
target: viewTargetSchema,
|
|
493
|
+
}).register(documentJsonSchema, { id: 'view-definition' });
|
|
494
|
+
const propertyValuesSchema = record(propertyKeySchema, jsonValueSchema).register(documentJsonSchema, {
|
|
495
|
+
id: 'property-values',
|
|
304
496
|
});
|
|
305
497
|
const coreNodeSchema = strictObject({
|
|
306
498
|
ref: coreRefSchema,
|
|
307
499
|
class: classRefSchema,
|
|
308
|
-
properties:
|
|
309
|
-
});
|
|
500
|
+
properties: propertyValuesSchema,
|
|
501
|
+
}).register(documentJsonSchema, { id: 'core-definition' });
|
|
310
502
|
const coreEdgeSchema = strictObject({
|
|
311
503
|
class: classRefSchema,
|
|
312
504
|
source: coreEndpointRefSchema,
|
|
313
505
|
target: coreEndpointRefSchema,
|
|
314
|
-
properties:
|
|
315
|
-
});
|
|
506
|
+
properties: propertyValuesSchema,
|
|
507
|
+
}).register(documentJsonSchema, { id: 'core-edge' });
|
|
316
508
|
const coreSchema = strictObject({
|
|
317
509
|
nodes: record(coreSlugSchema, coreNodeSchema),
|
|
318
510
|
edges: array(coreEdgeSchema),
|
|
319
|
-
});
|
|
320
|
-
|
|
511
|
+
}).register(documentJsonSchema, { id: 'core' });
|
|
512
|
+
/** The structure of an authored Domain schema document, the single source of its JSON Schema. */
|
|
513
|
+
export const domainSchemaStructure = strictObject({
|
|
321
514
|
format: literal(DOMAIN_FORMAT),
|
|
322
515
|
version: literal(DOMAIN_VERSION),
|
|
323
516
|
origin: originSchema,
|
|
324
517
|
name: domainNameSchema,
|
|
518
|
+
icon: domainIconSchema.optional(),
|
|
325
519
|
entrypoint: viewRefSchema.optional(),
|
|
326
520
|
dependencies: record(dependencyAliasSchema, domainDependencySchema),
|
|
327
521
|
classes: record(memberNameSchema, classDeclarationSchema),
|
|
@@ -330,19 +524,64 @@ const structuralSchema = strictObject({
|
|
|
330
524
|
views: record(memberNameSchema, viewDefinitionSchema),
|
|
331
525
|
core: coreSchema,
|
|
332
526
|
});
|
|
333
|
-
const domainSchemaStructuralSchema = structuralSchema;
|
|
334
527
|
export function parseDomainSchemaStructure(input) {
|
|
335
|
-
const result =
|
|
336
|
-
if (result.success)
|
|
337
|
-
|
|
338
|
-
|
|
528
|
+
const result = domainSchemaStructure.safeParse(input);
|
|
529
|
+
if (!result.success) {
|
|
530
|
+
throw new SchemaError(result.error.issues.flatMap((issue) => diagnosticsForIssue(issue, input)));
|
|
531
|
+
}
|
|
532
|
+
const lost = lostProtoKeys(input, result.data, []);
|
|
533
|
+
if (lost.length > 0)
|
|
534
|
+
throw new SchemaError(lost);
|
|
535
|
+
return modelOf(result.data);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Each `__proto__` member of the input that the parsed document lost. Zod skips that member in a
|
|
539
|
+
* record, so the structure would accept the document without it; it refuses the document instead.
|
|
540
|
+
* A closed object reports the member itself, as an unknown key. A State's transitions are read in
|
|
541
|
+
* place and keep the member.
|
|
542
|
+
*/
|
|
543
|
+
function lostProtoKeys(input, parsed, path) {
|
|
544
|
+
if (!isObject(input) || !isObject(parsed))
|
|
545
|
+
return [];
|
|
546
|
+
const lost = Object.hasOwn(input, PROTO_KEY) && !Object.hasOwn(parsed, PROTO_KEY)
|
|
547
|
+
? [diagnostic('STRUCTURE_PROTO_KEY', pointer([...path, PROTO_KEY]), PROTO_KEY_MESSAGE)]
|
|
548
|
+
: [];
|
|
549
|
+
return [
|
|
550
|
+
...lost,
|
|
551
|
+
...Object.keys(parsed).flatMap((key) => lostProtoKeys(Reflect.get(input, key), Reflect.get(parsed, key), [...path, key])),
|
|
552
|
+
];
|
|
553
|
+
}
|
|
554
|
+
/** Parse the structure of one callable contract: a Function declaration without its ref. */
|
|
555
|
+
export function parseCallableContract(input) {
|
|
556
|
+
const result = callableContractSchema.safeParse(input);
|
|
557
|
+
if (!result.success) {
|
|
558
|
+
throw new SchemaError(result.error.issues.flatMap((issue) => diagnosticsForIssue(issue, input)));
|
|
559
|
+
}
|
|
560
|
+
const lost = lostProtoKeys(input, result.data, []);
|
|
561
|
+
if (lost.length > 0)
|
|
562
|
+
throw new SchemaError(lost);
|
|
563
|
+
return result.data;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* The structure admits the document the model types: this parameter checks one direction, and
|
|
567
|
+
* `domain.structure.typecheck.ts` both. The brands are the model's own proofs from here on.
|
|
568
|
+
*/
|
|
569
|
+
function modelOf(document) {
|
|
570
|
+
return document;
|
|
339
571
|
}
|
|
340
572
|
function absoluteRefSchema(kind) {
|
|
341
573
|
return strictObject({
|
|
342
574
|
origin: originSchema,
|
|
343
575
|
kind: literal(kind),
|
|
344
576
|
name: memberNameSchema,
|
|
345
|
-
});
|
|
577
|
+
}).register(documentJsonSchema, { id: `${kind}-ref` });
|
|
578
|
+
}
|
|
579
|
+
function callablePolicyIssue(owner) {
|
|
580
|
+
return {
|
|
581
|
+
path: ['policy'],
|
|
582
|
+
params: { structureCode: 'STRUCTURE_CALLABLE_POLICY_AUTH' },
|
|
583
|
+
error: `Only an authorized ${owner} may declare a policy.`,
|
|
584
|
+
};
|
|
346
585
|
}
|
|
347
586
|
function isStateTransitions(input) {
|
|
348
587
|
if (!isRecord(input))
|
|
@@ -366,13 +605,69 @@ function isStateTransitions(input) {
|
|
|
366
605
|
return true;
|
|
367
606
|
}
|
|
368
607
|
function isRecord(input) {
|
|
369
|
-
return input
|
|
608
|
+
return isObject(input) && !Array.isArray(input);
|
|
370
609
|
}
|
|
610
|
+
function isObject(input) {
|
|
611
|
+
return input !== null && typeof input === 'object';
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* A string of `minimum` to `maximum` UTF-16 code units, the length the language measures, stated in
|
|
615
|
+
* JSON Schema as `minLength` and `maxLength` under the rule `length-in-utf16-code-units`. Zod's own
|
|
616
|
+
* string bounds count code points, which would admit twice the code units of the bound.
|
|
617
|
+
*/
|
|
618
|
+
function boundedString(minimum, maximum, id) {
|
|
619
|
+
return string()
|
|
620
|
+
.check((payload) => {
|
|
621
|
+
const length = payload.value.length;
|
|
622
|
+
if (length < minimum) {
|
|
623
|
+
payload.issues.push({
|
|
624
|
+
code: 'too_small',
|
|
625
|
+
origin: 'string',
|
|
626
|
+
minimum,
|
|
627
|
+
inclusive: true,
|
|
628
|
+
input: payload.value,
|
|
629
|
+
continue: true,
|
|
630
|
+
message: `Expected at least ${minimum} UTF-16 code units.`,
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
else if (maximum !== undefined && length > maximum) {
|
|
634
|
+
payload.issues.push({
|
|
635
|
+
code: 'too_big',
|
|
636
|
+
origin: 'string',
|
|
637
|
+
maximum,
|
|
638
|
+
inclusive: true,
|
|
639
|
+
input: payload.value,
|
|
640
|
+
continue: true,
|
|
641
|
+
message: `Expected at most ${maximum} UTF-16 code units.`,
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
})
|
|
645
|
+
.register(documentJsonSchema, {
|
|
646
|
+
...(id === undefined ? {} : { id }),
|
|
647
|
+
minLength: minimum,
|
|
648
|
+
...(maximum === undefined ? {} : { maxLength: maximum }),
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
/** At least one item, which `min(1)` proves: the output is typed as the non-empty tuple it is. */
|
|
652
|
+
function nonEmpty(list) {
|
|
653
|
+
return list.min(1);
|
|
654
|
+
}
|
|
655
|
+
/** Items distinct by JSON equality, which JSON Schema states as `uniqueItems`. */
|
|
371
656
|
function uniqueArray(element) {
|
|
657
|
+
return distinctArray(element, canonicalJson).register(documentJsonSchema, { uniqueItems: true });
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Tuples distinct as sets of fields. JSON Schema states their JSON equality, `uniqueItems`; the
|
|
661
|
+
* rule `unique-tuple-set` names the rest.
|
|
662
|
+
*/
|
|
663
|
+
function uniqueTupleSet(tuple) {
|
|
664
|
+
return distinctArray(tuple, (fields) => JSON.stringify(fields.map(canonicalJson).sort())).register(documentJsonSchema, { uniqueItems: true, 'x-astrale-rule': 'unique-tuple-set' });
|
|
665
|
+
}
|
|
666
|
+
function distinctArray(element, keyOf) {
|
|
372
667
|
return array(element).superRefine((values, context) => {
|
|
373
668
|
const firstIndexByValue = new Map();
|
|
374
669
|
values.forEach((value, index) => {
|
|
375
|
-
const key =
|
|
670
|
+
const key = keyOf(value);
|
|
376
671
|
const firstIndex = firstIndexByValue.get(key);
|
|
377
672
|
if (firstIndex === undefined) {
|
|
378
673
|
firstIndexByValue.set(key, index);
|
|
@@ -399,26 +694,91 @@ function canonicalJson(value) {
|
|
|
399
694
|
}
|
|
400
695
|
function diagnosticsForIssue(issue, input) {
|
|
401
696
|
if (issue.code === 'unrecognized_keys') {
|
|
402
|
-
return issue.keys.map((key) =>
|
|
697
|
+
return issue.keys.map((key) => key === PROTO_KEY
|
|
698
|
+
? diagnostic('STRUCTURE_PROTO_KEY', pointer([...issue.path, key]), PROTO_KEY_MESSAGE)
|
|
699
|
+
: diagnostic('STRUCTURE_UNKNOWN_FIELD', pointer([...issue.path, key]), `Unknown field ${JSON.stringify(key)}.`));
|
|
700
|
+
}
|
|
701
|
+
if (issue.code === 'invalid_union') {
|
|
702
|
+
const matched = matchedVariant(issue);
|
|
703
|
+
if (matched !== undefined)
|
|
704
|
+
return matched.flatMap((inner) => diagnosticsForIssue(inner, input));
|
|
705
|
+
}
|
|
706
|
+
// A record key refused by a refinement reports that refinement, at the key.
|
|
707
|
+
const refinement = issue.code === 'invalid_key' ? issue.issues.find(isRefinement) : undefined;
|
|
708
|
+
if (refinement !== undefined) {
|
|
709
|
+
return [diagnostic(refinementCode(refinement), pointer(issue.path), refinement.message)];
|
|
403
710
|
}
|
|
404
|
-
const customCode = issue.code === 'custom' ? customStructureCode(issue.params?.structureCode) : undefined;
|
|
405
711
|
return [
|
|
406
|
-
diagnostic(
|
|
712
|
+
diagnostic(structureCode(issue, input), pointer(issue.path), structureMessage(issue, input)),
|
|
407
713
|
];
|
|
408
714
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
715
|
+
/**
|
|
716
|
+
* The issues of the one variant a refused union value has the shape of, or none: a union reports
|
|
717
|
+
* `STRUCTURE_UNION` unless exactly one variant refuses the value only by checks (bounds, formats,
|
|
718
|
+
* refinements, or a `__proto__` member). A refused union in a variant counts as checks when it
|
|
719
|
+
* resolves to one variant itself. The structure's unions are exclusive (`xor`), so zod reports each
|
|
720
|
+
* variant's issues and this rule, not zod's choice among them, decides what is reported.
|
|
721
|
+
*/
|
|
722
|
+
function matchedVariant(issue) {
|
|
723
|
+
const candidates = issue.errors.flatMap((variant) => {
|
|
724
|
+
const checks = checksOnly(variant);
|
|
725
|
+
return checks === undefined ? [] : [checks];
|
|
726
|
+
});
|
|
727
|
+
const [only] = candidates;
|
|
728
|
+
if (candidates.length !== 1 || only === undefined)
|
|
729
|
+
return undefined;
|
|
730
|
+
return only.map((inner) => ({ ...inner, path: [...issue.path, ...inner.path] }));
|
|
731
|
+
}
|
|
732
|
+
function checksOnly(issues) {
|
|
733
|
+
const checks = [];
|
|
734
|
+
for (const issue of issues) {
|
|
735
|
+
if (issue.code === 'invalid_union') {
|
|
736
|
+
const matched = matchedVariant(issue);
|
|
737
|
+
if (matched === undefined)
|
|
738
|
+
return undefined;
|
|
739
|
+
checks.push(...matched);
|
|
740
|
+
}
|
|
741
|
+
else if (CHECK_CODES.has(issue.code) ||
|
|
742
|
+
(issue.code === 'unrecognized_keys' && issue.keys.every((key) => key === PROTO_KEY))) {
|
|
743
|
+
checks.push(issue);
|
|
744
|
+
}
|
|
745
|
+
else {
|
|
746
|
+
return undefined;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return checks;
|
|
750
|
+
}
|
|
751
|
+
const CHECK_CODES = new Set([
|
|
752
|
+
'custom',
|
|
753
|
+
'invalid_format',
|
|
754
|
+
'too_big',
|
|
755
|
+
'too_small',
|
|
756
|
+
]);
|
|
757
|
+
function isRefinement(issue) {
|
|
758
|
+
return issue.code === 'custom';
|
|
759
|
+
}
|
|
760
|
+
/** Every refinement of the structure names its own code. */
|
|
761
|
+
function refinementCode(issue) {
|
|
762
|
+
const code = issue.params?.structureCode;
|
|
763
|
+
switch (code) {
|
|
764
|
+
case 'STRUCTURE_BINARY_INPUT':
|
|
412
765
|
case 'STRUCTURE_CALLABLE_POLICY_AUTH':
|
|
766
|
+
case 'STRUCTURE_DEPENDENCY_ALIAS':
|
|
767
|
+
case 'STRUCTURE_DOMAIN_NAME':
|
|
413
768
|
case 'STRUCTURE_DUPLICATE_ITEM':
|
|
769
|
+
case 'STRUCTURE_EDGE_BLOB':
|
|
414
770
|
case 'STRUCTURE_EDGE_ORIENTATION':
|
|
415
|
-
|
|
771
|
+
case 'STRUCTURE_PROPERTY_KEY':
|
|
772
|
+
case 'STRUCTURE_STATE_TRANSITIONS':
|
|
773
|
+
return code;
|
|
416
774
|
default:
|
|
417
|
-
|
|
775
|
+
throw new TypeError(`A structure refinement names no Schema code: ${String(code)}.`);
|
|
418
776
|
}
|
|
419
777
|
}
|
|
420
778
|
function structureCode(issue, input) {
|
|
421
779
|
switch (issue.code) {
|
|
780
|
+
case 'custom':
|
|
781
|
+
return refinementCode(issue);
|
|
422
782
|
case 'invalid_type':
|
|
423
783
|
return valueAtPath(input, issue.path) === undefined ? 'STRUCTURE_REQUIRED' : 'STRUCTURE_TYPE';
|
|
424
784
|
case 'invalid_value':
|
|
@@ -433,10 +793,9 @@ function structureCode(issue, input) {
|
|
|
433
793
|
return 'STRUCTURE_MINIMUM';
|
|
434
794
|
case 'too_big':
|
|
435
795
|
return 'STRUCTURE_MAXIMUM';
|
|
436
|
-
case 'not_multiple_of':
|
|
437
|
-
return 'STRUCTURE_MULTIPLE';
|
|
438
796
|
default:
|
|
439
|
-
|
|
797
|
+
// The structure declares no multipleOf, Map or Set.
|
|
798
|
+
throw new TypeError(`The structure raised a ${issue.code} issue it declares no check for.`);
|
|
440
799
|
}
|
|
441
800
|
}
|
|
442
801
|
function structureMessage(issue, input) {
|
|
@@ -463,8 +822,5 @@ function valueAtPath(input, path) {
|
|
|
463
822
|
function pointer(path) {
|
|
464
823
|
if (path.length === 0)
|
|
465
824
|
return '';
|
|
466
|
-
return `/${path.map((segment) =>
|
|
467
|
-
}
|
|
468
|
-
function escapePointerSegment(segment) {
|
|
469
|
-
return segment.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
825
|
+
return `/${path.map((segment) => escapePointerToken(String(segment))).join('/')}`;
|
|
470
826
|
}
|