soma-core 2.0.0 → 2.1.0
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/README.md +28 -19
- package/bin/codegen.cjs +191 -0
- package/bin/eject.cjs +25 -12
- package/bin/service-codegen.cjs +98 -0
- package/bin/soma-lsp.cjs +140 -23
- package/bin/soma-runtime.cjs +75 -0
- package/bin/soma-sync-runtime.cjs +130 -0
- package/bin/soma.cjs +200 -13
- package/bin/soma.ts +170 -0
- package/core/build/compiler/flat-page.ts +305 -0
- package/core/build/compiler/full-manifest-builder.ts +68 -27
- package/core/build/compiler/html-index.ts +169 -0
- package/core/build/compiler/page-assets.ts +30 -7
- package/core/build/compiler/page-base-resolver.ts +11 -0
- package/core/build/compiler/page-declaration-compiler.ts +264 -226
- package/core/build/compiler/rollup-plugin-soma.ts +7 -2
- package/core/build/compiler/soma-manifest-webpack-plugin.js +114 -229
- package/core/build/compiler/soma-precompile.js +3733 -1892
- package/core/build/compiler/soma-precompile.ts +15 -20
- package/core/build/compiler/soma-rspack-yaml-loader.js +4 -3
- package/core/build/compiler/soma-webpack-loader.js +8 -4
- package/core/build/compiler/vite-plugin-soma.ts +8 -8
- package/core/build/component/component-graph.ts +1 -1
- package/core/build/component-tree/artifact-codec.ts +9 -42
- package/core/build/component-tree/collection-binding-lowerer.ts +1 -1
- package/core/build/component-tree/definition-preparation.ts +4 -5
- package/core/build/component-tree/parser.ts +1 -1
- package/core/build/component-tree/registry-snapshot.ts +45 -10
- package/core/build/component-tree/source-preflight.ts +2 -90
- package/core/build/component-tree/structure-topology.ts +1 -1
- package/core/build/eject/plan-eject.ts +9 -11
- package/core/build/lsp/component-tree-service.ts +4 -1
- package/core/build/lsp/component-tree.cjs +1 -1
- package/core/build/lsp/cross-file-diagnostics.cjs +5 -21
- package/core/build/lsp/soma-declaration.cjs +45 -47
- package/core/build/lsp/std-completion.generated.json +26 -0
- package/core/build/lsp/ui-yaml-completion.cjs +25 -37
- package/core/client/a11y/a11y-config.ts +50 -0
- package/core/client/a11y/announcer.ts +140 -0
- package/core/client/a11y/dom-id.ts +31 -0
- package/core/client/a11y/index.ts +40 -0
- package/core/client/a11y/motion-hook.ts +48 -0
- package/core/client/a11y/motion.ts +95 -0
- package/core/client/base/SomaPageRootBase.ts +44 -2
- package/core/client/base/index.ts +10 -8
- package/core/client/behavior/adapter-collection.ts +65 -0
- package/core/client/behavior/adapter-popper.ts +60 -0
- package/core/client/behavior/aria-hide-outside.ts +144 -0
- package/core/client/behavior/css-escape.ts +51 -0
- package/core/client/behavior/focus-scope.ts +433 -0
- package/core/client/behavior/focus-traversal.ts +68 -0
- package/core/client/behavior/index.ts +109 -0
- package/core/client/behavior/layer-stack.ts +234 -0
- package/core/client/behavior/overlay-host/index.ts +192 -0
- package/core/client/behavior/overlay-host/port.ts +76 -0
- package/core/client/behavior/overlay-wiring.ts +186 -0
- package/core/client/behavior/port.ts +85 -0
- package/core/client/behavior/positioner.ts +32 -0
- package/core/client/behavior/presence.ts +197 -0
- package/core/client/behavior/zag/adapter-vanilla.ts +96 -0
- package/core/client/behavior/zag/layer-bridge.ts +51 -0
- package/core/client/behavior/zag/machine-host.ts +69 -0
- package/core/client/behavior/zag/machines.ts +52 -0
- package/core/client/compiler/manifest-compiler.ts +33 -70
- package/core/client/component/adapter/adapt.ts +79 -0
- package/core/client/component/adapter/index.ts +3 -0
- package/core/client/component/adapter/types.ts +37 -0
- package/core/client/component/adapter/web-component.ts +130 -0
- package/core/client/component/component-defaults.ts +1 -1
- package/core/client/component/component-definition.types.ts +27 -5
- package/core/client/component/component-expander.ts +24 -16
- package/core/client/component/component-manager.ts +245 -814
- package/core/client/component/component-pack.ts +58 -216
- package/core/client/component/component-registry.ts +53 -29
- package/core/client/component/projection-admission.ts +63 -0
- package/core/client/component/projection-registry.ts +653 -0
- package/core/client/component/projection.types.ts +48 -0
- package/core/client/component/region-unavailable.ts +37 -0
- package/core/client/component/scoped-adapter.ts +3 -3
- package/core/client/component/structure-adapter.ts +93 -8
- package/core/client/container/IContainerAdapter.ts +4 -3
- package/core/client/container/SomaContainerAdapter.ts +22 -123
- package/core/client/data/collection-payload.ts +2 -0
- package/core/client/data/data-object-resolver.ts +827 -330
- package/core/client/data/data-polling.ts +110 -0
- package/core/client/data/data-subscriptions.ts +98 -0
- package/core/client/data/data-write-actions.ts +118 -0
- package/core/client/data/envelope-failure.ts +48 -0
- package/core/client/data/format-config.ts +62 -0
- package/core/client/data/region-scope-port.ts +265 -0
- package/core/client/data/region-scope-views.ts +96 -0
- package/core/client/data/role-gate.ts +44 -0
- package/core/client/data/write-outcome-store.ts +101 -0
- package/core/client/data/write-outcome.ts +175 -0
- package/core/client/engine/asset-resolver.ts +12 -21
- package/core/client/engine/dom-renderer.ts +85 -460
- package/core/client/engine/event-engine.ts +349 -323
- package/core/client/engine/locale-text-binder.ts +168 -0
- package/core/client/engine/property-watcher.ts +18 -164
- package/core/client/engine/reactive-proxy.ts +23 -194
- package/core/client/engine/render-engine.ts +16 -118
- package/core/client/engine/row-range.ts +11 -0
- package/core/client/engine/runtime-builder.ts +10 -13
- package/core/client/engine/scope-resolver.ts +3 -3
- package/core/client/engine/soma-bootstrap.ts +1238 -323
- package/core/client/engine/step-runner.ts +90 -12
- package/core/client/engine/style-binder.ts +2 -162
- package/core/client/engine/timer-engine.ts +2 -1
- package/core/client/engines/chart/adapter-echarts.ts +144 -0
- package/core/client/engines/chart/echarts-subpaths.d.ts +3 -0
- package/core/client/engines/chart/index.ts +90 -0
- package/core/client/engines/chart/kind-modules.ts +74 -0
- package/core/client/engines/chart/port.ts +44 -0
- package/core/client/engines/diff/adapter-jsdiff.ts +35 -0
- package/core/client/engines/diff/index.ts +33 -0
- package/core/client/engines/diff/port.ts +26 -0
- package/core/client/engines/dnd/adapter-pragmatic.ts +159 -0
- package/core/client/engines/dnd/index.ts +67 -0
- package/core/client/engines/dnd/port.ts +45 -0
- package/core/client/engines/engine-adapters.ts +29 -0
- package/core/client/engines/load.ts +44 -0
- package/core/client/engines/qrcode/adapter-qrcode-generator.ts +52 -0
- package/core/client/engines/qrcode/index.ts +30 -0
- package/core/client/engines/qrcode/port.ts +27 -0
- package/core/client/engines/table/adapter-tanstack.ts +132 -0
- package/core/client/engines/table/index.ts +80 -0
- package/core/client/engines/table/port.ts +55 -0
- package/core/client/engines/temporal/adapter-polyfill.ts +158 -0
- package/core/client/engines/temporal/index.ts +84 -0
- package/core/client/engines/temporal/port.ts +53 -0
- package/core/client/engines/virtual/adapter-tanstack.ts +133 -0
- package/core/client/engines/virtual/index.ts +43 -0
- package/core/client/engines/virtual/port.ts +43 -0
- package/core/client/format/formatter.ts +32 -0
- package/core/client/format/index.ts +26 -0
- package/core/client/format/zoned.ts +10 -0
- package/core/client/host-bridge/index.ts +17 -0
- package/core/client/host-bridge/load-host-domain-class.ts +15 -4
- package/core/client/host-bridge/resolve-host-bootstrap.ts +63 -11
- package/core/client/host-bridge/soma-app-host.stub.ts +3 -0
- package/core/client/host-bridge/soma-bootstrap-from-app.ts +25 -0
- package/core/client/infra/auth/IAuthService.ts +18 -13
- package/core/client/infra/auth/TokenAuthService.ts +126 -112
- package/core/client/infra/config/SomaConfig.ts +16 -0
- package/core/client/infra/config/feature-flags.ts +28 -0
- package/core/client/infra/http/IHttpClient.ts +2 -0
- package/core/client/infra/http/SomaHttpService.ts +1 -0
- package/core/client/infra/i18n/II18n.ts +23 -6
- package/core/client/infra/i18n/builtin-locale.ts +31 -0
- package/core/client/infra/i18n/index.ts +4 -0
- package/core/client/infra/i18n/interpolate.ts +28 -0
- package/core/client/infra/i18n/locale-catalog.ts +233 -0
- package/core/client/infra/i18n/pack-locales.ts +117 -0
- package/core/client/infra/identity/identity-port.ts +178 -0
- package/core/client/infra/notify/DefaultNotifyService.ts +86 -31
- package/core/client/infra/notify/INotifyService.ts +2 -14
- package/core/client/infra/notify/notify-declaration.ts +37 -0
- package/core/client/infra/permission/SomaPermission.ts +58 -48
- package/core/client/infra/router/IRouter.ts +24 -19
- package/core/client/infra/router/SomaRouter.ts +78 -66
- package/core/client/keyboard/collection.ts +197 -0
- package/core/client/keyboard/compose-keys.ts +68 -0
- package/core/client/keyboard/cursor.ts +117 -0
- package/core/client/keyboard/delegate.ts +195 -0
- package/core/client/keyboard/ime.ts +8 -0
- package/core/client/keyboard/index.ts +73 -0
- package/core/client/keyboard/intents.ts +60 -0
- package/core/client/keyboard/matrix.ts +269 -0
- package/core/client/keyboard/submit.ts +30 -0
- package/core/client/keyboard/typeahead.ts +203 -0
- package/core/client/keyboard/wiring.ts +324 -0
- package/core/client/middleware/createPermissionMiddleware.ts +20 -11
- package/core/client/mount/domain-rule.ts +43 -0
- package/core/client/mount/index.ts +3 -0
- package/core/client/mount/mount-page.ts +163 -0
- package/core/client/mount/types.ts +93 -0
- package/core/client/observability/runtime-observer.ts +136 -0
- package/core/client/parser/annotation-extractor.ts +1 -1
- package/core/client/parser/confirm-spec.ts +139 -0
- package/core/client/parser/data-config-parser.ts +416 -217
- package/core/client/parser/duration.ts +2 -16
- package/core/client/parser/page-state-parser.ts +59 -64
- package/core/client/parser/pipeline-parser.ts +178 -236
- package/core/client/parser/style-config-parser.ts +15 -81
- package/core/client/parser/subscribe-parser.ts +83 -0
- package/core/client/parser/timer-parser.ts +1 -1
- package/core/client/parser/trigger-parser.ts +1 -1
- package/core/client/parser/ui-config-parser.ts +244 -243
- package/core/client/pipes/pipe-registry.ts +304 -76
- package/core/client/registry/declaration-renderer.ts +20 -8
- package/core/client/registry/page-lifecycle.ts +4 -4
- package/core/client/registry/remote-page.ts +4 -4
- package/core/client/render-ports/index.ts +18 -0
- package/core/client/render-ports/notify-renderer.ts +45 -0
- package/core/client/render-ports/region-fallback.ts +8 -0
- package/core/client/render-ports/scheduling/prompt-queue.ts +102 -0
- package/core/client/render-ports/scheduling/toast-scheduler.ts +253 -0
- package/core/client/runtime/SomaRuntimeServices.ts +180 -16
- package/core/client/runtime/SomaSnapshotStore.ts +100 -100
- package/core/client/runtime/nav-history.ts +147 -0
- package/core/client/runtime/nav-port.ts +68 -0
- package/core/client/runtime/shortcuts.ts +360 -0
- package/core/client/runtime/write-feedback.ts +71 -0
- package/core/client/runtime-entry.ts +29 -0
- package/core/client/scheduler/SomaScheduler.ts +13 -3
- package/core/client/scheduling/flush-scheduler.ts +100 -0
- package/core/client/scheduling/index.ts +22 -0
- package/core/client/scheduling/observer-pool.ts +109 -0
- package/core/client/security/attribute-presence.ts +1 -3
- package/core/client/security/html-sanitizer.ts +23 -1
- package/core/client/security/url-guard.ts +0 -0
- package/core/client/styles/compiled-styles.ts +47 -0
- package/core/client/styles/index.ts +10 -0
- package/core/client/styles/pack-styles.ts +169 -0
- package/core/client/styles/sheet-mount.ts +48 -0
- package/core/client/styles/style-features.ts +131 -0
- package/core/client/time/clock.ts +36 -0
- package/core/client/time/instant.ts +2 -0
- package/core/client/url-state/index.ts +15 -0
- package/core/client/url-state/page-tabs-controller.ts +47 -0
- package/core/client/url-state/state-query-binding.ts +114 -0
- package/core/client/url-state/url-state.ts +149 -0
- package/core/client/validation/async-check-registry.ts +129 -0
- package/core/client/validation/async-rules.ts +259 -0
- package/core/client/validation/contract-validator.ts +44 -5
- package/core/client/validation/field-rules.ts +49 -0
- package/core/client/validation/index.ts +53 -0
- package/core/client/validation/object-rules.ts +72 -0
- package/core/index.ts +290 -264
- package/core/inspect/check-product.ts +542 -0
- package/core/inspect/check-runtime.ts +865 -0
- package/core/inspect/runtime.ts +98 -0
- package/core/page-target/index.ts +9 -0
- package/core/page-target/provenance.ts +119 -0
- package/core/page-target/slug.ts +7 -0
- package/core/page-target/testing/index.ts +329 -0
- package/core/page-target/types.ts +279 -0
- package/core/predicates-entry.ts +43 -0
- package/core/server/api/load-host-service.ts +3 -0
- package/core/server/compile-port.ts +18 -0
- package/core/server/diagnostic-gate-entry.ts +14 -0
- package/core/server/engines/style/candidate-guard.ts +59 -0
- package/core/server/engines/style/index.ts +57 -0
- package/core/server/engines/style/port.ts +34 -0
- package/core/server/engines/style/tailwind-adapter.ts +68 -0
- package/core/server/host/content-security-policy.ts +3 -5
- package/core/server/host/host-assembly-entry.ts +24 -0
- package/core/server/host/host-assembly.ts +267 -0
- package/core/server/host/host-caller.ts +52 -0
- package/core/server/host/host-response-headers.ts +49 -0
- package/core/server/host/invoke-host-request-hook.ts +5 -0
- package/core/server/host/locale-yaml.ts +53 -0
- package/core/server/host/page-markup-config.ts +13 -0
- package/core/server/host/published-page-artifact-cache.ts +355 -124
- package/core/server/host/published-page-assets.ts +91 -46
- package/core/server/host/resolve-host-request-hook.ts +9 -10
- package/core/server/host/resolve-host-tree-context.ts +8 -28
- package/core/server/host/server-page-assets.ts +175 -57
- package/core/server/host/soma-page-compile.ts +57 -16
- package/core/server/host/source-packages.cjs +184 -0
- package/core/server/host/source-packages.ts +18 -126
- package/core/server/host/virtual-pages.ts +197 -0
- package/core/server/index.ts +12 -43
- package/core/server/node.ts +52 -0
- package/core/server/page-assets.ts +73 -0
- package/core/server/page-declaration.ts +83 -7
- package/core/server/registry/api-registry-store.ts +17 -28
- package/core/server/registry/asset-store.ts +17 -19
- package/core/server/registry/batch-publish.ts +38 -0
- package/core/server/registry/batch-stage.ts +130 -0
- package/core/server/registry/component-supply.ts +31 -0
- package/core/server/registry/declaration-precompiler.ts +48 -34
- package/core/server/registry/index.ts +78 -1
- package/core/server/registry/page-registry-repository.ts +484 -69
- package/core/server/registry/page-registry-store.ts +617 -108
- package/core/server/registry/publish-asset-pin.ts +22 -20
- package/core/server/registry/registry-file-lock.ts +16 -3
- package/core/server/registry/registry-subjects.ts +6 -6
- package/core/server/registry/registry-write-pipeline.ts +65 -1
- package/core/server/registry/request-body-limit.ts +3 -1
- package/core/server/registry/rollback-plan.ts +181 -0
- package/core/server/registry/services/index.ts +14 -1
- package/core/server/registry/services/pages/Get.ts +26 -4
- package/core/server/registry/services/pages/Register.ts +29 -7
- package/core/server/registry/services/pages/RegisterBatch.ts +68 -0
- package/core/server/registry/services/pages/Rollback.ts +14 -4
- package/core/server/registry/services/pages/Unregister.ts +2 -1
- package/core/server/registry/source/canonical.ts +57 -0
- package/core/server/registry/source/errors.ts +81 -0
- package/core/server/registry/source/index.ts +49 -0
- package/core/server/registry/source/ledger.ts +306 -0
- package/core/server/registry/source/snapshot.ts +29 -0
- package/core/server/registry/source/source-name.ts +48 -0
- package/core/server/registry/source/types.ts +106 -0
- package/core/server/registry/source/version-store.ts +349 -0
- package/core/server/registry/standard-product.ts +185 -0
- package/core/server/registry/validation/compile-gate.ts +39 -50
- package/core/server/registry/validation/cross-check.ts +18 -5
- package/core/server/registry/validation/declaration-safety-scan.ts +12 -10
- package/core/server/registry/validation/region-scopes.ts +50 -0
- package/core/server/runtime-space/access-gate.ts +206 -0
- package/core/server/runtime-space/advice-log.ts +67 -0
- package/core/server/runtime-space/artifact-evict.ts +15 -0
- package/core/server/runtime-space/bindings.ts +478 -0
- package/core/server/runtime-space/digest.ts +62 -0
- package/core/server/runtime-space/dynamic-pages.ts +379 -0
- package/core/server/runtime-space/errors.ts +96 -0
- package/core/server/runtime-space/gc.ts +116 -0
- package/core/server/runtime-space/index.ts +106 -0
- package/core/server/runtime-space/inject.ts +497 -0
- package/core/server/runtime-space/nav-catalog.ts +140 -0
- package/core/server/runtime-space/page-grants.ts +436 -0
- package/core/server/runtime-space/prewarm.ts +234 -0
- package/core/server/runtime-space/registry-cold-start.ts +69 -0
- package/core/server/runtime-space/resolve.ts +538 -0
- package/core/server/runtime-space/root.cjs +160 -0
- package/core/server/runtime-space/root.ts +26 -0
- package/core/server/runtime-space/static-source.ts +85 -0
- package/core/server/runtime-space/store.ts +253 -0
- package/core/server/runtime-space/submit-steps.ts +412 -0
- package/core/server/runtime-space/types.ts +314 -0
- package/core/shared/anchor-space.ts +48 -0
- package/core/shared/artifact-compatibility.ts +156 -0
- package/core/shared/behavior-machine-names.ts +8 -0
- package/core/shared/calc/coerce.ts +2 -29
- package/core/shared/calc/errors.ts +4 -7
- package/core/shared/calc/evaluator.ts +23 -11
- package/core/shared/calc/index.ts +3 -4
- package/core/shared/calc/lexer.ts +7 -12
- package/core/shared/calc/parser.ts +8 -19
- package/core/shared/calc/typer.ts +10 -23
- package/core/shared/component-tree-artifact.ts +81 -7
- package/core/shared/contract-a11y.ts +335 -0
- package/core/shared/contract-sections.ts +344 -0
- package/core/shared/core-diagnostic-codes.ts +208 -0
- package/core/shared/data-declaration-checks.ts +211 -0
- package/core/shared/date-parts.ts +2 -0
- package/core/shared/declaration-errors.ts +14 -0
- package/core/shared/declaration-keys.ts +36 -0
- package/core/shared/diagnostic-code-index-entry.ts +14 -0
- package/core/shared/diagnostic-gate.ts +139 -0
- package/core/shared/engines/engine-error.ts +33 -0
- package/core/shared/engines/style/style-engine.types.ts +28 -0
- package/core/shared/envelope-text-width.generated.d.mts +19 -0
- package/core/shared/envelope-text-width.generated.mjs +413 -0
- package/core/shared/fragments-section.ts +10 -0
- package/core/shared/generation-diagnostics.ts +58 -0
- package/core/shared/generation-error.ts +73 -0
- package/core/shared/hook-attributes.ts +159 -0
- package/core/shared/inert-data-element.ts +50 -0
- package/core/shared/nav-back.ts +120 -0
- package/core/shared/page-access-text.ts +7 -0
- package/core/shared/page-envelope-runtime.ts +88 -0
- package/core/shared/page-envelope.ts +618 -0
- package/core/shared/page-scopes.ts +83 -0
- package/core/shared/pipeline-error-codes-view.ts +30 -0
- package/core/shared/pipeline-limits-view.ts +27 -0
- package/core/shared/predicates/index.ts +85 -497
- package/core/shared/predicates/relative-window.ts +19 -0
- package/core/shared/published-page-route.ts +5 -14
- package/core/shared/region-scope-decl.ts +488 -0
- package/core/shared/registry-generated/compile-purposes.ts +53 -0
- package/core/shared/registry-generated/diagnostic-registry-index.ts +796 -0
- package/core/shared/registry-generated/diagnostic-registry.ts +5872 -0
- package/core/shared/registry-generated/error-codes.ts +137 -0
- package/core/shared/registry-generated/index.ts +13 -0
- package/core/shared/registry-generated/limits.ts +552 -0
- package/core/shared/registry-generated/platform-keys.ts +56 -0
- package/core/shared/registry-generated/region-scope.ts +823 -0
- package/core/shared/registry-generated/std-grammar-completion.ts +216 -0
- package/core/shared/registry-generated/std-grammar-views.ts +139 -0
- package/core/shared/registry-generated/std-grammar.ts +161 -0
- package/core/shared/rule-step.ts +2 -0
- package/core/shared/runtime-address.ts +244 -0
- package/core/shared/scope-decl.ts +77 -0
- package/core/shared/sha256.ts +108 -0
- package/core/shared/show-when.ts +77 -0
- package/core/shared/source-file-suffix.ts +8 -0
- package/core/shared/std-auth-scan.ts +158 -0
- package/core/shared/types/choice-confirm.types.ts +2 -0
- package/core/shared/types/compile-diagnostic.types.ts +42 -0
- package/core/shared/types/compile-port.types.ts +41 -0
- package/core/shared/types/component-contract.types.ts +145 -156
- package/core/shared/types/component-tree-artifact.types.ts +18 -2
- package/core/shared/types/component-tree.types.ts +17 -6
- package/core/shared/types/data-config.types.ts +182 -222
- package/core/shared/types/domain.types.ts +20 -5
- package/core/shared/types/engine.types.ts +2 -0
- package/core/shared/types/event.types.ts +78 -8
- package/core/shared/types/generation-error.types.ts +83 -0
- package/core/shared/types/host-assembly.types.ts +126 -0
- package/core/shared/types/locale.types.ts +46 -0
- package/core/shared/types/manifest.types.ts +2 -7
- package/core/shared/types/nav-context.types.ts +46 -0
- package/core/shared/types/nav.types.ts +57 -0
- package/core/shared/types/notify.types.ts +45 -0
- package/core/shared/types/observation.types.ts +76 -0
- package/core/shared/types/page-envelope.types.ts +125 -0
- package/core/shared/types/page-state.types.ts +21 -42
- package/core/shared/types/region-scope.types.ts +177 -0
- package/core/shared/types/registry-batch.types.ts +45 -0
- package/core/shared/types/shortcuts.types.ts +61 -0
- package/core/shared/types/source.types.ts +10 -0
- package/core/shared/types/style-config.types.ts +61 -82
- package/core/shared/types/temporal.types.ts +3 -0
- package/core/shared/types/ui-config.types.ts +80 -152
- package/core/shared/types/write-outcome-view.types.ts +24 -0
- package/core/shared/types/write-runtime.types.ts +10 -0
- package/core/shared/types/write.types.ts +86 -0
- package/dist/browser/runtime-bundle.manifest.json +938 -0
- package/dist/browser/soma-runtime.js +120260 -0
- package/dist/cli/soma.js +120 -456
- package/dist/core/adaptive-pure.cjs +41 -0
- package/dist/core/index.cjs +119695 -22484
- package/dist/core/theme-pure.cjs +38 -0
- package/dist/diagnostics/telemetry.cjs +2 -1
- package/dist/lsp/component-tree.cjs +6398 -8254
- package/dist/preview-export.cjs +3401 -0
- package/dist/types/build/compiler/flat-page.d.ts +52 -0
- package/dist/types/build/compiler/full-manifest-builder.d.ts +26 -1
- package/dist/types/build/compiler/html-index.d.ts +48 -0
- package/dist/types/build/compiler/page-assets.d.ts +11 -3
- package/dist/types/build/compiler/page-base-resolver.d.ts +5 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +97 -56
- package/dist/types/build/compiler/soma-precompile.d.ts +3 -3
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -2
- package/dist/types/build/component/component-graph.d.ts +1 -1
- package/dist/types/build/component-tree/artifact-codec.d.ts +5 -8
- package/dist/types/build/component-tree/registry-snapshot.d.ts +18 -0
- package/dist/types/build/component-tree/source-preflight.d.ts +4 -14
- package/dist/types/build/component-tree/structure-topology.d.ts +1 -1
- package/dist/types/build/eject/plan-eject.d.ts +0 -1
- package/dist/types/build/lsp/component-tree-service.d.ts +2 -0
- package/dist/types/client/a11y/a11y-config.d.ts +15 -0
- package/dist/types/client/a11y/announcer.d.ts +45 -0
- package/dist/types/client/a11y/dom-id.d.ts +4 -0
- package/dist/types/client/a11y/index.d.ts +5 -0
- package/dist/types/client/a11y/motion-hook.d.ts +13 -0
- package/dist/types/client/a11y/motion.d.ts +24 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +17 -2
- package/dist/types/client/base/index.d.ts +8 -8
- package/dist/types/client/behavior/adapter-collection.d.ts +39 -0
- package/dist/types/client/behavior/adapter-popper.d.ts +2 -0
- package/dist/types/client/behavior/aria-hide-outside.d.ts +13 -0
- package/dist/types/client/behavior/css-escape.d.ts +11 -0
- package/dist/types/client/behavior/focus-scope.d.ts +69 -0
- package/dist/types/client/behavior/focus-traversal.d.ts +3 -0
- package/dist/types/client/behavior/index.d.ts +17 -0
- package/dist/types/client/behavior/layer-stack.d.ts +39 -0
- package/dist/types/client/behavior/overlay-host/index.d.ts +5 -0
- package/dist/types/client/behavior/overlay-host/port.d.ts +55 -0
- package/dist/types/client/behavior/overlay-wiring.d.ts +59 -0
- package/dist/types/client/behavior/port.d.ts +79 -0
- package/dist/types/client/behavior/positioner.d.ts +2 -0
- package/dist/types/client/behavior/presence.d.ts +27 -0
- package/dist/types/client/behavior/zag/adapter-vanilla.d.ts +2 -0
- package/dist/types/client/behavior/zag/layer-bridge.d.ts +15 -0
- package/dist/types/client/behavior/zag/machine-host.d.ts +22 -0
- package/dist/types/client/behavior/zag/machines.d.ts +23 -0
- package/dist/types/client/compiler/manifest-compiler.d.ts +4 -14
- package/dist/types/client/component/adapter/adapt.d.ts +9 -0
- package/dist/types/client/component/adapter/index.d.ts +3 -0
- package/dist/types/client/component/adapter/types.d.ts +33 -0
- package/dist/types/client/component/adapter/web-component.d.ts +9 -0
- package/dist/types/client/component/component-definition.types.d.ts +23 -5
- package/dist/types/client/component/component-expander.d.ts +1 -12
- package/dist/types/client/component/component-manager.d.ts +39 -89
- package/dist/types/client/component/component-pack.d.ts +21 -54
- package/dist/types/client/component/component-registry.d.ts +5 -0
- package/dist/types/client/component/projection-admission.d.ts +5 -0
- package/dist/types/client/component/projection-registry.d.ts +6 -0
- package/dist/types/client/component/projection.types.d.ts +44 -0
- package/dist/types/client/component/region-unavailable.d.ts +10 -0
- package/dist/types/client/component/scoped-adapter.d.ts +2 -3
- package/dist/types/client/container/IContainerAdapter.d.ts +8 -3
- package/dist/types/client/container/SomaContainerAdapter.d.ts +7 -10
- package/dist/types/client/data/collection-payload.d.ts +1 -0
- package/dist/types/client/data/data-object-resolver.d.ts +231 -110
- package/dist/types/client/data/data-polling.d.ts +28 -0
- package/dist/types/client/data/data-subscriptions.d.ts +20 -0
- package/dist/types/client/data/data-write-actions.d.ts +9 -0
- package/dist/types/client/data/envelope-failure.d.ts +17 -0
- package/dist/types/client/data/format-config.d.ts +13 -0
- package/dist/types/client/data/region-scope-port.d.ts +34 -0
- package/dist/types/client/data/region-scope-views.d.ts +15 -0
- package/dist/types/client/data/role-gate.d.ts +10 -0
- package/dist/types/client/data/write-outcome-store.d.ts +23 -0
- package/dist/types/client/data/write-outcome.d.ts +48 -0
- package/dist/types/client/engine/asset-resolver.d.ts +2 -7
- package/dist/types/client/engine/dom-renderer.d.ts +5 -111
- package/dist/types/client/engine/event-engine.d.ts +52 -63
- package/dist/types/client/engine/locale-text-binder.d.ts +28 -0
- package/dist/types/client/engine/property-watcher.d.ts +1 -41
- package/dist/types/client/engine/reactive-proxy.d.ts +2 -42
- package/dist/types/client/engine/render-engine.d.ts +3 -54
- package/dist/types/client/engine/row-range.d.ts +1 -0
- package/dist/types/client/engine/runtime-builder.d.ts +7 -3
- package/dist/types/client/engine/soma-bootstrap.d.ts +314 -91
- package/dist/types/client/engine/step-runner.d.ts +20 -2
- package/dist/types/client/engine/style-binder.d.ts +2 -16
- package/dist/types/client/engines/chart/adapter-echarts.d.ts +6 -0
- package/dist/types/client/engines/chart/index.d.ts +8 -0
- package/dist/types/client/engines/chart/kind-modules.d.ts +8 -0
- package/dist/types/client/engines/chart/port.d.ts +46 -0
- package/dist/types/client/engines/diff/adapter-jsdiff.d.ts +6 -0
- package/dist/types/client/engines/diff/index.d.ts +8 -0
- package/dist/types/client/engines/diff/port.d.ts +16 -0
- package/dist/types/client/engines/dnd/adapter-pragmatic.d.ts +9 -0
- package/dist/types/client/engines/dnd/index.d.ts +6 -0
- package/dist/types/client/engines/dnd/port.d.ts +33 -0
- package/dist/types/client/engines/engine-adapters.d.ts +23 -0
- package/dist/types/client/engines/load.d.ts +11 -0
- package/dist/types/client/engines/qrcode/adapter-qrcode-generator.d.ts +6 -0
- package/dist/types/client/engines/qrcode/index.d.ts +8 -0
- package/dist/types/client/engines/qrcode/port.d.ts +16 -0
- package/dist/types/client/engines/table/adapter-tanstack.d.ts +6 -0
- package/dist/types/client/engines/table/index.d.ts +8 -0
- package/dist/types/client/engines/table/port.d.ts +51 -0
- package/dist/types/client/engines/temporal/adapter-polyfill.d.ts +6 -0
- package/dist/types/client/engines/temporal/index.d.ts +8 -0
- package/dist/types/client/engines/temporal/port.d.ts +41 -0
- package/dist/types/client/engines/virtual/adapter-tanstack.d.ts +9 -0
- package/dist/types/client/engines/virtual/index.d.ts +8 -0
- package/dist/types/client/engines/virtual/port.d.ts +33 -0
- package/dist/types/client/format/formatter.d.ts +3 -0
- package/dist/types/client/format/index.d.ts +2 -0
- package/dist/types/client/format/zoned.d.ts +1 -0
- package/dist/types/client/host-bridge/index.d.ts +3 -0
- package/dist/types/client/host-bridge/resolve-host-bootstrap.d.ts +7 -1
- package/dist/types/client/host-bridge/soma-app-host.stub.d.ts +3 -0
- package/dist/types/client/host-bridge/soma-bootstrap-from-app.d.ts +9 -0
- package/dist/types/client/infra/auth/IAuthService.d.ts +5 -0
- package/dist/types/client/infra/auth/TokenAuthService.d.ts +1 -0
- package/dist/types/client/infra/config/SomaConfig.d.ts +4 -0
- package/dist/types/client/infra/config/feature-flags.d.ts +10 -0
- package/dist/types/client/infra/http/IHttpClient.d.ts +4 -0
- package/dist/types/client/infra/i18n/II18n.d.ts +17 -1
- package/dist/types/client/infra/i18n/builtin-locale.d.ts +11 -0
- package/dist/types/client/infra/i18n/index.d.ts +1 -0
- package/dist/types/client/infra/i18n/interpolate.d.ts +12 -0
- package/dist/types/client/infra/i18n/locale-catalog.d.ts +71 -0
- package/dist/types/client/infra/i18n/pack-locales.d.ts +29 -0
- package/dist/types/client/infra/identity/identity-port.d.ts +54 -0
- package/dist/types/client/infra/notify/DefaultNotifyService.d.ts +29 -7
- package/dist/types/client/infra/notify/INotifyService.d.ts +1 -12
- package/dist/types/client/infra/notify/notify-declaration.d.ts +10 -0
- package/dist/types/client/infra/permission/SomaPermission.d.ts +7 -0
- package/dist/types/client/infra/router/IRouter.d.ts +5 -1
- package/dist/types/client/infra/router/SomaRouter.d.ts +6 -2
- package/dist/types/client/keyboard/collection.d.ts +58 -0
- package/dist/types/client/keyboard/compose-keys.d.ts +24 -0
- package/dist/types/client/keyboard/cursor.d.ts +48 -0
- package/dist/types/client/keyboard/delegate.d.ts +48 -0
- package/dist/types/client/keyboard/ime.d.ts +2 -0
- package/dist/types/client/keyboard/index.d.ts +10 -0
- package/dist/types/client/keyboard/intents.d.ts +35 -0
- package/dist/types/client/keyboard/matrix.d.ts +29 -0
- package/dist/types/client/keyboard/submit.d.ts +7 -0
- package/dist/types/client/keyboard/typeahead.d.ts +28 -0
- package/dist/types/client/keyboard/wiring.d.ts +85 -0
- package/dist/types/client/middleware/createPermissionMiddleware.d.ts +5 -0
- package/dist/types/client/mount/domain-rule.d.ts +17 -0
- package/dist/types/client/mount/index.d.ts +3 -0
- package/dist/types/client/mount/mount-page.d.ts +11 -0
- package/dist/types/client/mount/types.d.ts +100 -0
- package/dist/types/client/observability/runtime-observer.d.ts +24 -0
- package/dist/types/client/parser/confirm-spec.d.ts +37 -0
- package/dist/types/client/parser/data-config-parser.d.ts +23 -17
- package/dist/types/client/parser/duration.d.ts +1 -1
- package/dist/types/client/parser/page-state-parser.d.ts +1 -6
- package/dist/types/client/parser/pipeline-parser.d.ts +7 -12
- package/dist/types/client/parser/style-config-parser.d.ts +2 -1
- package/dist/types/client/parser/subscribe-parser.d.ts +5 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +26 -25
- package/dist/types/client/pipes/pipe-registry.d.ts +30 -40
- package/dist/types/client/registry/declaration-renderer.d.ts +11 -3
- package/dist/types/client/registry/page-lifecycle.d.ts +3 -3
- package/dist/types/client/registry/remote-page.d.ts +3 -3
- package/dist/types/client/render-ports/index.d.ts +15 -0
- package/dist/types/client/render-ports/notify-renderer.d.ts +55 -0
- package/dist/types/client/render-ports/region-fallback.d.ts +10 -0
- package/dist/types/client/render-ports/scheduling/prompt-queue.d.ts +19 -0
- package/dist/types/client/render-ports/scheduling/toast-scheduler.d.ts +60 -0
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +102 -5
- package/dist/types/client/runtime/nav-history.d.ts +31 -0
- package/dist/types/client/runtime/nav-port.d.ts +12 -0
- package/dist/types/client/runtime/shortcuts.d.ts +41 -0
- package/dist/types/client/runtime/write-feedback.d.ts +22 -0
- package/dist/types/client/runtime-entry.d.ts +13 -0
- package/dist/types/client/scheduler/SomaScheduler.d.ts +5 -0
- package/dist/types/client/scheduling/flush-scheduler.d.ts +13 -0
- package/dist/types/client/scheduling/index.d.ts +4 -0
- package/dist/types/client/scheduling/observer-pool.d.ts +15 -0
- package/dist/types/client/security/url-guard.d.ts +18 -0
- package/dist/types/client/styles/compiled-styles.d.ts +10 -0
- package/dist/types/client/styles/index.d.ts +3 -0
- package/dist/types/client/styles/pack-styles.d.ts +51 -0
- package/dist/types/client/styles/sheet-mount.d.ts +7 -0
- package/dist/types/client/styles/style-features.d.ts +26 -0
- package/dist/types/client/time/clock.d.ts +10 -0
- package/dist/types/client/time/instant.d.ts +1 -0
- package/dist/types/client/url-state/index.d.ts +6 -0
- package/dist/types/client/url-state/page-tabs-controller.d.ts +22 -0
- package/dist/types/client/url-state/state-query-binding.d.ts +22 -0
- package/dist/types/client/url-state/url-state.d.ts +47 -0
- package/dist/types/client/validation/async-check-registry.d.ts +41 -0
- package/dist/types/client/validation/async-rules.d.ts +81 -0
- package/dist/types/client/validation/contract-validator.d.ts +10 -0
- package/dist/types/client/validation/field-rules.d.ts +6 -0
- package/dist/types/client/validation/index.d.ts +5 -0
- package/dist/types/client/validation/object-rules.d.ts +22 -0
- package/dist/types/index.d.ts +97 -61
- package/dist/types/inspect/check-product.d.ts +123 -0
- package/dist/types/inspect/check-runtime.d.ts +19 -0
- package/dist/types/inspect/runtime.d.ts +39 -0
- package/dist/types/page-target/index.d.ts +3 -0
- package/dist/types/page-target/provenance.d.ts +20 -0
- package/dist/types/page-target/slug.d.ts +7 -0
- package/dist/types/page-target/testing/index.d.ts +55 -0
- package/dist/types/page-target/types.d.ts +260 -0
- package/dist/types/predicates-entry.d.ts +3 -0
- package/dist/types/server/compile-port.d.ts +13 -0
- package/dist/types/server/diagnostic-gate-entry.d.ts +3 -0
- package/dist/types/server/engines/style/candidate-guard.d.ts +14 -0
- package/dist/types/server/engines/style/index.d.ts +10 -0
- package/dist/types/server/engines/style/port.d.ts +8 -0
- package/dist/types/server/engines/style/tailwind-adapter.d.ts +6 -0
- package/dist/types/server/host/host-assembly-entry.d.ts +5 -0
- package/dist/types/server/host/host-assembly.d.ts +61 -0
- package/dist/types/server/host/host-caller.d.ts +10 -0
- package/dist/types/server/host/host-config-paths.d.cts +7 -0
- package/dist/types/server/host/host-response-headers.d.ts +16 -0
- package/dist/types/server/host/locale-yaml.d.ts +3 -0
- package/dist/types/server/host/page-markup-config.d.ts +6 -0
- package/dist/types/server/host/published-page-artifact-cache.d.ts +99 -22
- package/dist/types/server/host/published-page-assets.d.ts +75 -5
- package/dist/types/server/host/resolve-host-request-hook.d.ts +0 -4
- package/dist/types/server/host/resolve-host-tree-context.d.ts +1 -1
- package/dist/types/server/host/server-page-assets.d.ts +29 -3
- package/dist/types/server/host/soma-page-compile.d.ts +26 -4
- package/dist/types/server/host/source-packages.d.cts +23 -0
- package/dist/types/server/host/source-packages.d.ts +15 -2
- package/dist/types/server/host/virtual-pages.d.ts +33 -0
- package/dist/types/server/index.d.ts +7 -12
- package/dist/types/server/node.d.ts +16 -0
- package/dist/types/server/page-assets.d.ts +7 -0
- package/dist/types/server/page-declaration.d.ts +21 -6
- package/dist/types/server/registry/api-registry-store.d.ts +4 -7
- package/dist/types/server/registry/asset-store.d.ts +4 -7
- package/dist/types/server/registry/batch-publish.d.ts +12 -0
- package/dist/types/server/registry/batch-stage.d.ts +24 -0
- package/dist/types/server/registry/component-supply.d.ts +6 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +22 -8
- package/dist/types/server/registry/index.d.ts +12 -3
- package/dist/types/server/registry/page-registry-repository.d.ts +50 -4
- package/dist/types/server/registry/page-registry-store.d.ts +227 -33
- package/dist/types/server/registry/publish-asset-pin.d.ts +5 -4
- package/dist/types/server/registry/registry-file-lock.d.ts +5 -0
- package/dist/types/server/registry/registry-subjects.d.ts +2 -2
- package/dist/types/server/registry/registry-write-pipeline.d.ts +22 -0
- package/dist/types/server/registry/request-body-limit.d.ts +1 -1
- package/dist/types/server/registry/rollback-plan.d.ts +58 -0
- package/dist/types/server/registry/services/index.d.ts +5 -0
- package/dist/types/server/registry/services/pages/Register.d.ts +1 -1
- package/dist/types/server/registry/services/pages/RegisterBatch.d.ts +12 -0
- package/dist/types/server/registry/services/pages/Rollback.d.ts +4 -1
- package/dist/types/server/registry/source/canonical.d.ts +2 -0
- package/dist/types/server/registry/source/errors.d.ts +44 -0
- package/dist/types/server/registry/source/index.d.ts +7 -0
- package/dist/types/server/registry/source/ledger.d.ts +99 -0
- package/dist/types/server/registry/source/snapshot.d.ts +6 -0
- package/dist/types/server/registry/source/source-name.d.ts +20 -0
- package/dist/types/server/registry/source/types.d.ts +89 -0
- package/dist/types/server/registry/source/version-store.d.ts +58 -0
- package/dist/types/server/registry/standard-product.d.ts +78 -0
- package/dist/types/server/registry/validation/compile-gate.d.ts +12 -45
- package/dist/types/server/registry/validation/cross-check.d.ts +7 -0
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +0 -1
- package/dist/types/server/registry/validation/region-scopes.d.ts +10 -0
- package/dist/types/server/runtime-space/access-gate.d.ts +41 -0
- package/dist/types/server/runtime-space/advice-log.d.ts +18 -0
- package/dist/types/server/runtime-space/artifact-evict.d.ts +4 -0
- package/dist/types/server/runtime-space/bindings.d.ts +115 -0
- package/dist/types/server/runtime-space/digest.d.ts +19 -0
- package/dist/types/server/runtime-space/dynamic-pages.d.ts +120 -0
- package/dist/types/server/runtime-space/errors.d.ts +37 -0
- package/dist/types/server/runtime-space/gc.d.ts +6 -0
- package/dist/types/server/runtime-space/index.d.ts +19 -0
- package/dist/types/server/runtime-space/inject.d.ts +55 -0
- package/dist/types/server/runtime-space/nav-catalog.d.ts +33 -0
- package/dist/types/server/runtime-space/page-grants.d.ts +90 -0
- package/dist/types/server/runtime-space/prewarm.d.ts +60 -0
- package/dist/types/server/runtime-space/registry-cold-start.d.ts +4 -0
- package/dist/types/server/runtime-space/resolve.d.ts +35 -0
- package/dist/types/server/runtime-space/root.d.cts +65 -0
- package/dist/types/server/runtime-space/root.d.ts +16 -0
- package/dist/types/server/runtime-space/static-source.d.ts +8 -0
- package/dist/types/server/runtime-space/store.d.ts +63 -0
- package/dist/types/server/runtime-space/submit-steps.d.ts +116 -0
- package/dist/types/server/runtime-space/types.d.ts +255 -0
- package/dist/types/shared/anchor-space.d.ts +17 -0
- package/dist/types/shared/artifact-compatibility.d.ts +75 -0
- package/dist/types/shared/behavior-machine-names.d.ts +2 -0
- package/dist/types/shared/calc/coerce.d.ts +1 -4
- package/dist/types/shared/calc/lexer.d.ts +1 -2
- package/dist/types/shared/calc/parser.d.ts +1 -7
- package/dist/types/shared/calc/typer.d.ts +1 -6
- package/dist/types/shared/component-tree-artifact.d.ts +16 -2
- package/dist/types/shared/contract-a11y.d.ts +33 -0
- package/dist/types/shared/contract-sections.d.ts +50 -0
- package/dist/types/shared/core-diagnostic-codes.d.ts +28 -0
- package/dist/types/shared/data-declaration-checks.d.ts +71 -0
- package/dist/types/shared/date-parts.d.ts +1 -0
- package/dist/types/shared/declaration-errors.d.ts +12 -0
- package/dist/types/shared/declaration-keys.d.ts +9 -0
- package/dist/types/shared/diagnostic-code-index-entry.d.ts +5 -0
- package/dist/types/shared/diagnostic-gate.d.ts +60 -0
- package/dist/types/shared/engines/engine-error.d.ts +14 -0
- package/dist/types/shared/engines/style/style-engine.types.d.ts +22 -0
- package/dist/types/shared/fragments-section.d.ts +2 -0
- package/dist/types/shared/generation-diagnostics.d.ts +7 -0
- package/dist/types/shared/generation-error.d.ts +20 -0
- package/dist/types/shared/hook-attributes.d.ts +220 -0
- package/dist/types/shared/inert-data-element.d.ts +14 -0
- package/dist/types/shared/nav-back.d.ts +22 -0
- package/dist/types/shared/page-access-text.d.ts +4 -0
- package/dist/types/shared/page-envelope-runtime.d.ts +32 -0
- package/dist/types/shared/page-envelope.d.ts +61 -0
- package/dist/types/shared/page-scopes.d.ts +35 -0
- package/dist/types/shared/pipeline-error-codes-view.d.ts +11 -0
- package/dist/types/shared/pipeline-limits-view.d.ts +8 -0
- package/dist/types/shared/predicates/index.d.ts +24 -67
- package/dist/types/shared/predicates/relative-window.d.ts +1 -0
- package/dist/types/shared/published-page-route.d.ts +3 -5
- package/dist/types/shared/region-scope-decl.d.ts +121 -0
- package/dist/types/shared/registry-generated/compile-purposes.d.ts +37 -0
- package/dist/types/shared/registry-generated/diagnostic-registry-index.d.ts +2 -0
- package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +5011 -0
- package/dist/types/shared/registry-generated/error-codes.d.ts +115 -0
- package/dist/types/shared/registry-generated/index.d.ts +10 -0
- package/dist/types/shared/registry-generated/limits.d.ts +461 -0
- package/dist/types/shared/registry-generated/platform-keys.d.ts +42 -0
- package/dist/types/shared/registry-generated/region-scope.d.ts +511 -0
- package/dist/types/shared/registry-generated/std-grammar-completion.d.ts +773 -0
- package/dist/types/shared/registry-generated/std-grammar-views.d.ts +203 -0
- package/dist/types/shared/registry-generated/std-grammar.d.ts +3515 -0
- package/dist/types/shared/rule-step.d.ts +1 -0
- package/dist/types/shared/runtime-address.d.ts +70 -0
- package/dist/types/shared/scope-decl.d.ts +15 -0
- package/dist/types/shared/sha256.d.ts +4 -0
- package/dist/types/shared/show-when.d.ts +21 -0
- package/dist/types/shared/source-file-suffix.d.ts +2 -0
- package/dist/types/shared/std-auth-scan.d.ts +45 -0
- package/dist/types/shared/types/choice-confirm.types.d.ts +1 -0
- package/dist/types/shared/types/compile-diagnostic.types.d.ts +34 -0
- package/dist/types/shared/types/compile-port.types.d.ts +30 -0
- package/dist/types/shared/types/component-contract.types.d.ts +134 -129
- package/dist/types/shared/types/component-tree-artifact.types.d.ts +16 -2
- package/dist/types/shared/types/component-tree.types.d.ts +15 -6
- package/dist/types/shared/types/data-config.types.d.ts +175 -191
- package/dist/types/shared/types/domain.types.d.ts +20 -5
- package/dist/types/shared/types/engine.types.d.ts +2 -0
- package/dist/types/shared/types/event.types.d.ts +59 -9
- package/dist/types/shared/types/generation-error.types.d.ts +28 -0
- package/dist/types/shared/types/host-assembly.types.d.ts +121 -0
- package/dist/types/shared/types/locale.types.d.ts +17 -0
- package/dist/types/shared/types/manifest.types.d.ts +2 -7
- package/dist/types/shared/types/nav-context.types.d.ts +41 -0
- package/dist/types/shared/types/nav.types.d.ts +53 -0
- package/dist/types/shared/types/notify.types.d.ts +37 -0
- package/dist/types/shared/types/observation.types.d.ts +72 -0
- package/dist/types/shared/types/page-envelope.types.d.ts +98 -0
- package/dist/types/shared/types/page-state.types.d.ts +17 -33
- package/dist/types/shared/types/region-scope.types.d.ts +150 -0
- package/dist/types/shared/types/registry-batch.types.d.ts +48 -0
- package/dist/types/shared/types/shortcuts.types.d.ts +67 -0
- package/dist/types/shared/types/source.types.d.ts +10 -0
- package/dist/types/shared/types/style-config.types.d.ts +0 -19
- package/dist/types/shared/types/temporal.types.d.ts +1 -0
- package/dist/types/shared/types/ui-config.types.d.ts +77 -148
- package/dist/types/shared/types/write-outcome-view.types.d.ts +19 -0
- package/dist/types/shared/types/write-runtime.types.d.ts +1 -0
- package/dist/types/shared/types/write.types.d.ts +70 -0
- package/global.d.ts +2 -10
- package/host-next/app/SomaPageClient.tsx +359 -0
- package/host-next/app/api/[...path]/route.ts +98 -0
- package/host-next/app/api/soma-registry/[...path]/route.ts +79 -0
- package/host-next/app/components/SomaPageForbidden.tsx +19 -0
- package/host-next/app/globals.css +177 -0
- package/host-next/app/page-access.ts +47 -0
- package/host-next/app/router-bridge.ts +42 -0
- package/host-next/app/soma/_shared/host-prepare.ts +33 -0
- package/host-next/app/soma/_shared/page-http.ts +86 -0
- package/host-next/app/soma/manifest/route.ts +98 -0
- package/host-next/app/soma/page/route.ts +36 -0
- package/host-next/app/soma-runtime/[...file]/route.ts +21 -0
- package/host-next/app/soma-runtime/_shared/static-file.ts +89 -0
- package/host-next/bin/host-next.cjs +59 -0
- package/host-next/instrumentation.ts +13 -0
- package/host-next/next-env.d.ts +7 -0
- package/host-next/next.config.js +382 -0
- package/host-next/proxy.ts +43 -0
- package/host-next/src/shell-routes.cjs +51 -0
- package/host-next/src/workspace.ts +543 -0
- package/package.json +238 -59
- package/tsconfig.json +4 -11
- package/app/SomaPageClient.tsx +0 -313
- package/app/api/[...path]/route.ts +0 -86
- package/app/api/soma-registry/[...path]/route.ts +0 -67
- package/app/globals.css +0 -126
- package/app/soma/manifest/route.ts +0 -43
- package/app/soma/page/route.ts +0 -44
- package/app/soma/page-object/route.ts +0 -159
- package/bin/component.cjs +0 -240
- package/bin/migrate.cjs +0 -432
- package/bin/soma-db.cjs +0 -13
- package/bin/soma-mock.mjs +0 -38
- package/bin/soma-sync.cjs +0 -3
- package/core/build/blocks/block-compile.ts +0 -373
- package/core/build/blocks/block-container.ts +0 -207
- package/core/build/blocks/block-loader.ts +0 -33
- package/core/build/blocks/html-index.ts +0 -120
- package/core/build/blocks/migrate-flat.ts +0 -463
- package/core/build/compiler/precompiled-manifest-loader.ts +0 -41
- package/core/build/component/pack-from-dir.ts +0 -58
- package/core/build/component/package-loader.ts +0 -358
- package/core/build/component-tree/binding-bridge.ts +0 -272
- package/core/build/component-tree/migration-files.ts +0 -214
- package/core/build/component-tree/migration.ts +0 -170
- package/core/build/component-tree/validator.ts +0 -318
- package/core/build/db/cli.ts +0 -10
- package/core/build/db/emit-entities.ts +0 -45
- package/core/build/db/emit-mappers.ts +0 -175
- package/core/build/db/emit-prisma-schema.ts +0 -92
- package/core/build/db/generate.ts +0 -166
- package/core/build/db/ir.ts +0 -75
- package/core/build/db/load-db-yaml.ts +0 -241
- package/core/build/eject/component-eject.ts +0 -480
- package/core/build/eject/component-upgrade.ts +0 -359
- package/core/build/layout/constraint-solver.ts +0 -350
- package/core/build/layout/css-emitter.ts +0 -135
- package/core/build/layout/page-layout.ts +0 -85
- package/core/build/ooui/artifact/artifact.types.ts +0 -275
- package/core/build/ooui/artifact/emit-artifact.ts +0 -269
- package/core/build/ooui/artifact/emit-html.ts +0 -204
- package/core/build/ooui/artifact/index.ts +0 -53
- package/core/build/ooui/artifact/spatial-tree.ts +0 -268
- package/core/build/ooui/artifact/utility-class.ts +0 -83
- package/core/build/ooui/composition/candidate.types.ts +0 -323
- package/core/build/ooui/composition/control-model.ts +0 -114
- package/core/build/ooui/composition/registry.ts +0 -520
- package/core/build/ooui/composition/select.ts +0 -232
- package/core/build/ooui/diagnostics/codes.ts +0 -230
- package/core/build/ooui/diagnostics/error.ts +0 -235
- package/core/build/ooui/diagnostics/format.ts +0 -106
- package/core/build/ooui/diagnostics/index.ts +0 -62
- package/core/build/ooui/diagnostics/issue.types.ts +0 -112
- package/core/build/ooui/engine-slot.ts +0 -184
- package/core/build/ooui/index.ts +0 -1427
- package/core/build/ooui/intent/derive-intent.ts +0 -450
- package/core/build/ooui/intent/field-rules.ts +0 -330
- package/core/build/ooui/intent/intent.types.ts +0 -476
- package/core/build/ooui/intent/verb-events.ts +0 -285
- package/core/build/ooui/page/budget.ts +0 -503
- package/core/build/ooui/page/compose-page.ts +0 -736
- package/core/build/ooui/page/index.ts +0 -66
- package/core/build/ooui/page/page.types.ts +0 -402
- package/core/build/ooui/page/region-row.ts +0 -241
- package/core/build/ooui/semantic/expand-page-surface.ts +0 -180
- package/core/build/ooui/semantic/kernel.types.ts +0 -187
- package/core/build/ooui/semantic/normalize.ts +0 -784
- package/core/build/ooui/semantic/origin.types.ts +0 -211
- package/core/build/ooui/semantic/role-alias.ts +0 -154
- package/core/build/ooui/semantic/shorthand.ts +0 -233
- package/core/build/ooui/semantic/surface.types.ts +0 -78
- package/core/build/ooui/semantic/validate-request.ts +0 -267
- package/core/build/ooui/spatial/emit-utility.ts +0 -480
- package/core/build/ooui/spatial/ir.types.ts +0 -443
- package/core/build/ooui/spatial/registry.ts +0 -565
- package/core/build/ooui/spatial/solve.ts +0 -769
- package/core/build/ooui/spatial/utility.types.ts +0 -242
- package/core/build/ooui/trace/index.ts +0 -40
- package/core/build/ooui/trace/render.ts +0 -190
- package/core/build/ooui/trace/source.types.ts +0 -69
- package/core/build/ooui/trace/trace.types.ts +0 -326
- package/core/build/pack/pack-init.ts +0 -270
- package/core/client/adaptive/flush-scheduler.ts +0 -96
- package/core/client/adaptive/hysteresis.ts +0 -56
- package/core/client/adaptive/index.ts +0 -23
- package/core/client/adaptive/observer-pool.ts +0 -204
- package/core/client/compiler/adaptive-compile.ts +0 -136
- package/core/client/component/ai-catalog.ts +0 -432
- package/core/client/component/catalog-examples.ts +0 -60
- package/core/client/component/contract-compat.ts +0 -161
- package/core/client/component/example-blocks.ts +0 -126
- package/core/client/component/keyboard-matrix.ts +0 -144
- package/core/client/component/pack-styles.ts +0 -152
- package/core/client/component/style-features.ts +0 -131
- package/core/client/component/theme-component-tokens.ts +0 -80
- package/core/client/component/verify-pack.ts +0 -429
- package/core/client/container/MiniProgramContainerAdapter.ts +0 -204
- package/core/client/container/ReactNativeContainerAdapter.ts +0 -203
- package/core/client/data/reaction-engine.ts +0 -176
- package/core/client/data/window-engine.ts +0 -477
- package/core/client/infra/i18n/DefaultI18n.ts +0 -29
- package/core/client/infra/notify/DomNotifyService.ts +0 -99
- package/core/client/infra/notify/INotifyTheme.ts +0 -22
- package/core/client/parser/adaptive-parser.ts +0 -264
- package/core/client/parser/blocks/namespace.ts +0 -207
- package/core/client/parser/blocks/page-parser.ts +0 -466
- package/core/client/parser/blocks/use-parser.ts +0 -646
- package/core/client/parser/layout-parser.ts +0 -158
- package/core/client/parser/reaction-parser.ts +0 -458
- package/core/client/parser/reaction-sugar.ts +0 -47
- package/core/client/parser/window-parser.ts +0 -294
- package/core/client/quality/SomaQualityRegistry.ts +0 -71
- package/core/client/runtime/serialize-page-state.ts +0 -152
- package/core/client/theme/harmony.ts +0 -429
- package/core/client/theme/scene-tokens.ts +0 -155
- package/core/client/theme/theme-axes.ts +0 -323
- package/core/client/theme/theme-engine.ts +0 -2390
- package/core/client/theme/tone-solver.ts +0 -119
- package/core/client/typography/typography-base.ts +0 -34
- package/core/server/headless/soma-headless-page.ts +0 -103
- package/core/server/host/page-response-mode.cjs +0 -96
- package/core/server/host/page-response-request.ts +0 -33
- package/core/server/host/request-origin.ts +0 -18
- package/core/server/host/soma-request-hook-host.stub.ts +0 -4
- package/core/server/infra/db/errors.ts +0 -11
- package/core/server/infra/db/mapper/PrismaSomaMapper.ts +0 -313
- package/core/server/infra/db/mapper/SomaBaseMapper.ts +0 -23
- package/core/server/infra/db/mapper/SomaMapperHooks.ts +0 -13
- package/core/server/infra/db/query/SomaQuery.ts +0 -149
- package/core/server/infra/db/service/SomaDbService.ts +0 -64
- package/core/server/infra/db/soma-db.ts +0 -120
- package/core/server/infra/db/types.ts +0 -21
- package/core/server/mock/node/catch-all.mjs +0 -35
- package/core/server/mock/node/cli.d.mts +0 -58
- package/core/server/mock/node/cli.mjs +0 -244
- package/core/server/mock/node/context.mjs +0 -167
- package/core/server/mock/node/environment-policy.mjs +0 -52
- package/core/server/mock/node/plugin-loader.mjs +0 -212
- package/core/server/mock/node/preload.mjs +0 -91
- package/core/server/mock/node/process-lifecycle.mjs +0 -236
- package/core/server/mock/node/public.d.mts +0 -110
- package/core/server/mock/node/public.mjs +0 -4
- package/core/server/mock/node/registry.mjs +0 -336
- package/core/server/mock/node/schema-generator.mjs +0 -1309
- package/core/server/mock/testing/host-harness.d.mts +0 -66
- package/core/server/mock/testing/host-harness.mjs +0 -276
- package/core/server/mock/testing/host-runtime.mjs +0 -48
- package/core/server/ooui.ts +0 -34
- package/core/shared/block-errors.ts +0 -11
- package/core/shared/component/derive-sample.ts +0 -290
- package/core/shared/component/field-lines.ts +0 -563
- package/core/shared/container-breakpoints.ts +0 -46
- package/core/shared/object-semantics.ts +0 -240
- package/core/shared/ooui-declaration.ts +0 -235
- package/core/shared/path-algebra.ts +0 -169
- package/core/shared/types/adaptive.types.ts +0 -109
- package/core/shared/types/layout-constraint.types.ts +0 -89
- package/core/shared/types/reaction.types.ts +0 -144
- package/core/shared/types/window.types.ts +0 -177
- package/dist/types/build/blocks/block-compile.d.ts +0 -52
- package/dist/types/build/blocks/block-container.d.ts +0 -40
- package/dist/types/build/blocks/block-loader.d.ts +0 -9
- package/dist/types/build/blocks/html-index.d.ts +0 -37
- package/dist/types/build/blocks/migrate-flat.d.ts +0 -49
- package/dist/types/build/compiler/precompiled-manifest-loader.d.ts +0 -5
- package/dist/types/build/component/pack-from-dir.d.ts +0 -17
- package/dist/types/build/component/package-loader.d.ts +0 -50
- package/dist/types/build/component-tree/binding-bridge.d.ts +0 -19
- package/dist/types/build/component-tree/migration-files.d.ts +0 -35
- package/dist/types/build/component-tree/migration.d.ts +0 -28
- package/dist/types/build/component-tree/validator.d.ts +0 -9
- package/dist/types/build/db/cli.d.ts +0 -2
- package/dist/types/build/db/emit-entities.d.ts +0 -5
- package/dist/types/build/db/emit-mappers.d.ts +0 -15
- package/dist/types/build/db/emit-prisma-schema.d.ts +0 -2
- package/dist/types/build/db/generate.d.ts +0 -7
- package/dist/types/build/db/ir.d.ts +0 -58
- package/dist/types/build/db/load-db-yaml.d.ts +0 -14
- package/dist/types/build/eject/component-eject.d.ts +0 -121
- package/dist/types/build/eject/component-upgrade.d.ts +0 -43
- package/dist/types/build/layout/constraint-solver.d.ts +0 -78
- package/dist/types/build/layout/css-emitter.d.ts +0 -18
- package/dist/types/build/layout/page-layout.d.ts +0 -24
- package/dist/types/build/ooui/artifact/artifact.types.d.ts +0 -180
- package/dist/types/build/ooui/artifact/emit-artifact.d.ts +0 -58
- package/dist/types/build/ooui/artifact/emit-html.d.ts +0 -53
- package/dist/types/build/ooui/artifact/index.d.ts +0 -5
- package/dist/types/build/ooui/artifact/spatial-tree.d.ts +0 -48
- package/dist/types/build/ooui/artifact/utility-class.d.ts +0 -46
- package/dist/types/build/ooui/composition/candidate.types.d.ts +0 -206
- package/dist/types/build/ooui/composition/control-model.d.ts +0 -37
- package/dist/types/build/ooui/composition/registry.d.ts +0 -66
- package/dist/types/build/ooui/composition/select.d.ts +0 -63
- package/dist/types/build/ooui/diagnostics/codes.d.ts +0 -28
- package/dist/types/build/ooui/diagnostics/error.d.ts +0 -135
- package/dist/types/build/ooui/diagnostics/format.d.ts +0 -51
- package/dist/types/build/ooui/diagnostics/index.d.ts +0 -25
- package/dist/types/build/ooui/diagnostics/issue.types.d.ts +0 -56
- package/dist/types/build/ooui/engine-slot.d.ts +0 -41
- package/dist/types/build/ooui/index.d.ts +0 -286
- package/dist/types/build/ooui/intent/derive-intent.d.ts +0 -32
- package/dist/types/build/ooui/intent/field-rules.d.ts +0 -99
- package/dist/types/build/ooui/intent/intent.types.d.ts +0 -318
- package/dist/types/build/ooui/intent/verb-events.d.ts +0 -70
- package/dist/types/build/ooui/page/budget.d.ts +0 -28
- package/dist/types/build/ooui/page/compose-page.d.ts +0 -41
- package/dist/types/build/ooui/page/index.d.ts +0 -4
- package/dist/types/build/ooui/page/page.types.d.ts +0 -264
- package/dist/types/build/ooui/page/region-row.d.ts +0 -16
- package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +0 -33
- package/dist/types/build/ooui/semantic/kernel.types.d.ts +0 -125
- package/dist/types/build/ooui/semantic/normalize.d.ts +0 -45
- package/dist/types/build/ooui/semantic/origin.types.d.ts +0 -95
- package/dist/types/build/ooui/semantic/role-alias.d.ts +0 -35
- package/dist/types/build/ooui/semantic/shorthand.d.ts +0 -60
- package/dist/types/build/ooui/semantic/surface.types.d.ts +0 -16
- package/dist/types/build/ooui/semantic/validate-request.d.ts +0 -19
- package/dist/types/build/ooui/spatial/emit-utility.d.ts +0 -43
- package/dist/types/build/ooui/spatial/ir.types.d.ts +0 -280
- package/dist/types/build/ooui/spatial/registry.d.ts +0 -110
- package/dist/types/build/ooui/spatial/solve.d.ts +0 -42
- package/dist/types/build/ooui/spatial/utility.types.d.ts +0 -191
- package/dist/types/build/ooui/trace/index.d.ts +0 -3
- package/dist/types/build/ooui/trace/render.d.ts +0 -42
- package/dist/types/build/ooui/trace/source.types.d.ts +0 -25
- package/dist/types/build/ooui/trace/trace.types.d.ts +0 -143
- package/dist/types/build/pack/pack-init.d.ts +0 -8
- package/dist/types/client/adaptive/flush-scheduler.d.ts +0 -13
- package/dist/types/client/adaptive/hysteresis.d.ts +0 -16
- package/dist/types/client/adaptive/index.d.ts +0 -5
- package/dist/types/client/adaptive/observer-pool.d.ts +0 -22
- package/dist/types/client/compiler/adaptive-compile.d.ts +0 -26
- package/dist/types/client/component/ai-catalog.d.ts +0 -122
- package/dist/types/client/component/catalog-examples.d.ts +0 -18
- package/dist/types/client/component/contract-compat.d.ts +0 -16
- package/dist/types/client/component/example-blocks.d.ts +0 -7
- package/dist/types/client/component/keyboard-matrix.d.ts +0 -24
- package/dist/types/client/component/pack-styles.d.ts +0 -43
- package/dist/types/client/component/style-features.d.ts +0 -26
- package/dist/types/client/component/theme-component-tokens.d.ts +0 -17
- package/dist/types/client/component/verify-pack.d.ts +0 -24
- package/dist/types/client/container/MiniProgramContainerAdapter.d.ts +0 -52
- package/dist/types/client/container/ReactNativeContainerAdapter.d.ts +0 -47
- package/dist/types/client/data/reaction-engine.d.ts +0 -21
- package/dist/types/client/data/window-engine.d.ts +0 -27
- package/dist/types/client/infra/i18n/DefaultI18n.d.ts +0 -7
- package/dist/types/client/infra/notify/DomNotifyService.d.ts +0 -17
- package/dist/types/client/infra/notify/INotifyTheme.d.ts +0 -12
- package/dist/types/client/parser/adaptive-parser.d.ts +0 -28
- package/dist/types/client/parser/blocks/namespace.d.ts +0 -72
- package/dist/types/client/parser/blocks/page-parser.d.ts +0 -30
- package/dist/types/client/parser/blocks/use-parser.d.ts +0 -124
- package/dist/types/client/parser/layout-parser.d.ts +0 -9
- package/dist/types/client/parser/reaction-parser.d.ts +0 -16
- package/dist/types/client/parser/reaction-sugar.d.ts +0 -13
- package/dist/types/client/parser/window-parser.d.ts +0 -25
- package/dist/types/client/quality/SomaQualityRegistry.d.ts +0 -31
- package/dist/types/client/runtime/serialize-page-state.d.ts +0 -10
- package/dist/types/client/theme/harmony.d.ts +0 -119
- package/dist/types/client/theme/scene-tokens.d.ts +0 -41
- package/dist/types/client/theme/theme-axes.d.ts +0 -174
- package/dist/types/client/theme/theme-engine.d.ts +0 -119
- package/dist/types/client/theme/tone-solver.d.ts +0 -51
- package/dist/types/client/typography/typography-base.d.ts +0 -15
- package/dist/types/server/headless/soma-headless-page.d.ts +0 -12
- package/dist/types/server/host/page-response-request.d.ts +0 -8
- package/dist/types/server/host/request-origin.d.ts +0 -1
- package/dist/types/server/host/soma-request-hook-host.stub.d.ts +0 -2
- package/dist/types/server/infra/db/errors.d.ts +0 -5
- package/dist/types/server/infra/db/mapper/PrismaSomaMapper.d.ts +0 -77
- package/dist/types/server/infra/db/mapper/SomaBaseMapper.d.ts +0 -20
- package/dist/types/server/infra/db/mapper/SomaMapperHooks.d.ts +0 -12
- package/dist/types/server/infra/db/query/SomaQuery.d.ts +0 -42
- package/dist/types/server/infra/db/service/SomaDbService.d.ts +0 -24
- package/dist/types/server/infra/db/soma-db.d.ts +0 -45
- package/dist/types/server/infra/db/types.d.ts +0 -18
- package/dist/types/server/ooui.d.ts +0 -18
- package/dist/types/shared/block-errors.d.ts +0 -5
- package/dist/types/shared/component/derive-sample.d.ts +0 -37
- package/dist/types/shared/component/field-lines.d.ts +0 -19
- package/dist/types/shared/container-breakpoints.d.ts +0 -42
- package/dist/types/shared/object-semantics.d.ts +0 -42
- package/dist/types/shared/ooui-declaration.d.ts +0 -135
- package/dist/types/shared/path-algebra.d.ts +0 -56
- package/dist/types/shared/types/adaptive.types.d.ts +0 -88
- package/dist/types/shared/types/layout-constraint.types.d.ts +0 -53
- package/dist/types/shared/types/reaction.types.d.ts +0 -115
- package/dist/types/shared/types/window.types.d.ts +0 -171
- package/next.config.js +0 -387
- package/proxy.ts +0 -62
- /package/{app → host-next/app}/[...path]/page.tsx +0 -0
- /package/{app → host-next/app}/components/SomaHostPage.tsx +0 -0
- /package/{app → host-next/app}/components/SomaHydrationShell.tsx +0 -0
- /package/{app → host-next/app}/components/SomaPageClientBoundary.tsx +0 -0
- /package/{app → host-next/app}/favicon.ico/route.ts +0 -0
- /package/{app → host-next/app}/layout.tsx +0 -0
- /package/{app → host-next/app}/page.tsx +0 -0
- /package/{app → host-next/app}/soma/[...path]/route.ts +0 -0
- /package/{app → host-next/app}/soma/route.ts +0 -0
|
@@ -1,1309 +0,0 @@
|
|
|
1
|
-
import Ajv2020 from 'ajv/dist/2020.js';
|
|
2
|
-
import { isIP } from 'node:net';
|
|
3
|
-
|
|
4
|
-
const DEFAULT_ARRAY_LENGTH = 2;
|
|
5
|
-
const MAX_GENERATED_COLLECTION_SIZE = 100;
|
|
6
|
-
const MAX_SCHEMA_DEPTH = 32;
|
|
7
|
-
const SUPPORTED_STRING_FORMATS = new Set([
|
|
8
|
-
'date',
|
|
9
|
-
'date-time',
|
|
10
|
-
'email',
|
|
11
|
-
'hostname',
|
|
12
|
-
'ipv4',
|
|
13
|
-
'ipv6',
|
|
14
|
-
'time',
|
|
15
|
-
'uri',
|
|
16
|
-
'uri-reference',
|
|
17
|
-
'url',
|
|
18
|
-
'uuid',
|
|
19
|
-
]);
|
|
20
|
-
const SINGLE_SCHEMA_KEYWORDS = new Set([
|
|
21
|
-
'additionalProperties',
|
|
22
|
-
'contains',
|
|
23
|
-
'contentSchema',
|
|
24
|
-
'else',
|
|
25
|
-
'if',
|
|
26
|
-
'items',
|
|
27
|
-
'not',
|
|
28
|
-
'propertyNames',
|
|
29
|
-
'then',
|
|
30
|
-
'unevaluatedItems',
|
|
31
|
-
'unevaluatedProperties',
|
|
32
|
-
]);
|
|
33
|
-
const SCHEMA_ARRAY_KEYWORDS = new Set(['allOf', 'anyOf', 'oneOf', 'prefixItems']);
|
|
34
|
-
const SCHEMA_MAP_KEYWORDS = new Set([
|
|
35
|
-
'$defs',
|
|
36
|
-
'dependentSchemas',
|
|
37
|
-
'patternProperties',
|
|
38
|
-
'properties',
|
|
39
|
-
]);
|
|
40
|
-
const ANNOTATION_ONLY_KEYWORDS = new Set([
|
|
41
|
-
'$comment',
|
|
42
|
-
'$defs',
|
|
43
|
-
'$id',
|
|
44
|
-
'$schema',
|
|
45
|
-
'deprecated',
|
|
46
|
-
'description',
|
|
47
|
-
'readOnly',
|
|
48
|
-
'title',
|
|
49
|
-
'writeOnly',
|
|
50
|
-
]);
|
|
51
|
-
const UNSUPPORTED_CONSTRAINT_KEYWORDS = new Set([
|
|
52
|
-
'$dynamicRef',
|
|
53
|
-
'$recursiveRef',
|
|
54
|
-
'additionalItems',
|
|
55
|
-
'contains',
|
|
56
|
-
'contentEncoding',
|
|
57
|
-
'contentMediaType',
|
|
58
|
-
'contentSchema',
|
|
59
|
-
'dependentRequired',
|
|
60
|
-
'dependentSchemas',
|
|
61
|
-
'dependencies',
|
|
62
|
-
'definitions',
|
|
63
|
-
'if',
|
|
64
|
-
'maxContains',
|
|
65
|
-
'minContains',
|
|
66
|
-
'not',
|
|
67
|
-
'pattern',
|
|
68
|
-
'patternProperties',
|
|
69
|
-
'propertyNames',
|
|
70
|
-
'then',
|
|
71
|
-
'else',
|
|
72
|
-
'unevaluatedItems',
|
|
73
|
-
'unevaluatedProperties',
|
|
74
|
-
'uniqueItems',
|
|
75
|
-
]);
|
|
76
|
-
|
|
77
|
-
const schemaMetaValidator = new Ajv2020({
|
|
78
|
-
allErrors: true,
|
|
79
|
-
strict: false,
|
|
80
|
-
validateFormats: false,
|
|
81
|
-
});
|
|
82
|
-
function schemaTypeError(code, message, options) {
|
|
83
|
-
const error = new TypeError(message, options);
|
|
84
|
-
error.code = code;
|
|
85
|
-
return error;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function cloneJsonValue(value) {
|
|
89
|
-
if (value === undefined) return undefined;
|
|
90
|
-
return structuredClone(value);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function stableSerialize(value) {
|
|
94
|
-
const seen = new WeakSet();
|
|
95
|
-
|
|
96
|
-
function serialize(current) {
|
|
97
|
-
if (current === null) return 'null';
|
|
98
|
-
if (current === undefined) return 'undefined';
|
|
99
|
-
if (typeof current === 'number' && !Number.isFinite(current)) return JSON.stringify(String(current));
|
|
100
|
-
if (typeof current !== 'object') return JSON.stringify(current);
|
|
101
|
-
if (seen.has(current)) throw new TypeError('Cannot create a deterministic seed from a circular value');
|
|
102
|
-
|
|
103
|
-
seen.add(current);
|
|
104
|
-
const result = Array.isArray(current)
|
|
105
|
-
? `[${current.map((item) => serialize(item)).join(',')}]`
|
|
106
|
-
: `{${Object.keys(current).sort().map((key) => `${JSON.stringify(key)}:${serialize(current[key])}`).join(',')}}`;
|
|
107
|
-
seen.delete(current);
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return serialize(value);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function hashSeed(value) {
|
|
115
|
-
const input = String(value);
|
|
116
|
-
let hash = 0x811c9dc5;
|
|
117
|
-
for (let index = 0; index < input.length; index += 1) {
|
|
118
|
-
hash ^= input.charCodeAt(index);
|
|
119
|
-
hash = Math.imul(hash, 0x01000193);
|
|
120
|
-
}
|
|
121
|
-
return hash >>> 0;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function randomUnit(seed, pathValue) {
|
|
125
|
-
return hashSeed(`${seed}\u0000${pathValue}`) / 0x100000000;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function choose(values, seed, pathValue) {
|
|
129
|
-
if (!Array.isArray(values) || values.length === 0) return undefined;
|
|
130
|
-
return values[Math.floor(randomUnit(seed, pathValue) * values.length) % values.length];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function decodePointerPart(part) {
|
|
134
|
-
return part.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function resolveLocalReference(rootSchema, reference) {
|
|
138
|
-
if (reference === '#') return rootSchema;
|
|
139
|
-
if (!reference.startsWith('#/')) {
|
|
140
|
-
throw schemaTypeError(
|
|
141
|
-
'SCHEMA_REFERENCE_INVALID',
|
|
142
|
-
`Only local JSON Schema references are supported: ${reference}`,
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
let current = rootSchema;
|
|
146
|
-
for (const rawPart of reference.slice(2).split('/')) {
|
|
147
|
-
const part = decodePointerPart(rawPart);
|
|
148
|
-
if (
|
|
149
|
-
!current
|
|
150
|
-
|| typeof current !== 'object'
|
|
151
|
-
|| !Object.prototype.hasOwnProperty.call(current, part)
|
|
152
|
-
) {
|
|
153
|
-
throw schemaTypeError(
|
|
154
|
-
'SCHEMA_REFERENCE_INVALID',
|
|
155
|
-
`JSON Schema reference does not exist: ${reference}`,
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
current = current[part];
|
|
159
|
-
}
|
|
160
|
-
return current;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function assertSupportedSchemaKeywords(schema, pathValue) {
|
|
164
|
-
if (
|
|
165
|
-
Object.prototype.hasOwnProperty.call(schema, '$schema')
|
|
166
|
-
&& typeof schema.$schema !== 'string'
|
|
167
|
-
) {
|
|
168
|
-
throw schemaTypeError(
|
|
169
|
-
'SCHEMA_INVALID',
|
|
170
|
-
`JSON Schema $schema must be a string at ${pathValue}`,
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
if (
|
|
174
|
-
Object.prototype.hasOwnProperty.call(schema, '$schema')
|
|
175
|
-
&& !/^https:\/\/json-schema\.org\/draft\/2020-12\/schema#?$/u.test(schema.$schema)
|
|
176
|
-
) {
|
|
177
|
-
const error = new TypeError(`Unsupported JSON Schema dialect ${JSON.stringify(schema.$schema)} at ${pathValue}`);
|
|
178
|
-
error.code = 'SCHEMA_DIALECT_UNSUPPORTED';
|
|
179
|
-
throw error;
|
|
180
|
-
}
|
|
181
|
-
if (Array.isArray(schema.items)) {
|
|
182
|
-
const error = new TypeError(`Unsupported JSON Schema keyword "items" (array form) at ${pathValue}`);
|
|
183
|
-
error.code = 'SCHEMA_KEYWORD_UNSUPPORTED';
|
|
184
|
-
throw error;
|
|
185
|
-
}
|
|
186
|
-
for (const keyword of UNSUPPORTED_CONSTRAINT_KEYWORDS) {
|
|
187
|
-
if (!Object.prototype.hasOwnProperty.call(schema, keyword)) continue;
|
|
188
|
-
if (keyword === 'uniqueItems' && schema[keyword] === false) continue;
|
|
189
|
-
const error = new TypeError(`Unsupported JSON Schema keyword ${JSON.stringify(keyword)} at ${pathValue}`);
|
|
190
|
-
error.code = 'SCHEMA_KEYWORD_UNSUPPORTED';
|
|
191
|
-
throw error;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function metaValidationMessage(errors) {
|
|
196
|
-
if (!Array.isArray(errors) || errors.length === 0) return 'unknown meta-schema violation';
|
|
197
|
-
return errors.map((entry) => {
|
|
198
|
-
const location = entry.instancePath ? `$${entry.instancePath}` : '$';
|
|
199
|
-
return `${location} ${entry.message || `failed ${entry.keyword}`}`;
|
|
200
|
-
}).join('; ');
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function assertSchemaTreeSupported(schema, pathValue, visited = new WeakSet()) {
|
|
204
|
-
if (typeof schema === 'boolean') return;
|
|
205
|
-
if (!schema || typeof schema !== 'object' || Array.isArray(schema)) {
|
|
206
|
-
throw schemaTypeError(
|
|
207
|
-
'SCHEMA_INVALID',
|
|
208
|
-
`JSON Schema subschema must be an object or boolean at ${pathValue}`,
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
if (visited.has(schema)) return;
|
|
212
|
-
visited.add(schema);
|
|
213
|
-
|
|
214
|
-
assertSupportedSchemaKeywords(schema, pathValue);
|
|
215
|
-
if (schema.format !== undefined && !SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
216
|
-
throw schemaTypeError(
|
|
217
|
-
'SCHEMA_FORMAT_UNSUPPORTED',
|
|
218
|
-
`Unsupported JSON Schema format ${JSON.stringify(schema.format)} at ${pathValue}`,
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
for (const [keyword, value] of Object.entries(schema)) {
|
|
223
|
-
if (SINGLE_SCHEMA_KEYWORDS.has(keyword)) {
|
|
224
|
-
assertSchemaTreeSupported(value, `${pathValue}.${keyword}`, visited);
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (SCHEMA_ARRAY_KEYWORDS.has(keyword)) {
|
|
228
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
229
|
-
assertSchemaTreeSupported(value[index], `${pathValue}.${keyword}[${index}]`, visited);
|
|
230
|
-
}
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
if (SCHEMA_MAP_KEYWORDS.has(keyword)) {
|
|
234
|
-
for (const [name, childSchema] of Object.entries(value)) {
|
|
235
|
-
assertSchemaTreeSupported(childSchema, `${pathValue}.${keyword}.${name}`, visited);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function assertValidSchemaDocument(schema, pathValue) {
|
|
242
|
-
if (typeof schema !== 'boolean' && (!schema || typeof schema !== 'object' || Array.isArray(schema))) {
|
|
243
|
-
throw schemaTypeError(
|
|
244
|
-
'SCHEMA_INVALID',
|
|
245
|
-
`JSON Schema must be an object or boolean at ${pathValue}`,
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Preserve the existing, more specific dialect error before asking Ajv to
|
|
250
|
-
// select a meta-schema.
|
|
251
|
-
if (schema && typeof schema === 'object') assertSupportedSchemaKeywords(schema, pathValue);
|
|
252
|
-
|
|
253
|
-
let valid;
|
|
254
|
-
try {
|
|
255
|
-
valid = schemaMetaValidator.validateSchema(schema);
|
|
256
|
-
} catch (cause) {
|
|
257
|
-
throw schemaTypeError(
|
|
258
|
-
'SCHEMA_INVALID',
|
|
259
|
-
`Invalid JSON Schema 2020-12 at ${pathValue}: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
260
|
-
{ cause },
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
if (!valid) {
|
|
264
|
-
throw schemaTypeError(
|
|
265
|
-
'SCHEMA_INVALID',
|
|
266
|
-
`Invalid JSON Schema 2020-12 at ${pathValue}: ${metaValidationMessage(schemaMetaValidator.errors)}`,
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
assertSchemaTreeSupported(schema, pathValue);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function valueMatchesType(value, type) {
|
|
273
|
-
switch (type) {
|
|
274
|
-
case 'null': return value === null;
|
|
275
|
-
case 'boolean': return typeof value === 'boolean';
|
|
276
|
-
case 'integer': return typeof value === 'number' && Number.isInteger(value);
|
|
277
|
-
case 'number': return typeof value === 'number' && Number.isFinite(value);
|
|
278
|
-
case 'string': return typeof value === 'string';
|
|
279
|
-
case 'array': return Array.isArray(value);
|
|
280
|
-
case 'object': return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
281
|
-
default: return false;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function valueMatchesFormat(value, format) {
|
|
286
|
-
if (typeof value !== 'string' || !format) return true;
|
|
287
|
-
const validDate = (dateValue) => {
|
|
288
|
-
const match = /^(\d{4})-(\d{2})-(\d{2})$/u.exec(dateValue);
|
|
289
|
-
if (!match) return false;
|
|
290
|
-
const year = Number(match[1]);
|
|
291
|
-
const month = Number(match[2]);
|
|
292
|
-
const day = Number(match[3]);
|
|
293
|
-
const date = new Date(0);
|
|
294
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
295
|
-
date.setUTCFullYear(year, month - 1, day);
|
|
296
|
-
return date.getUTCFullYear() === year
|
|
297
|
-
&& date.getUTCMonth() === month - 1
|
|
298
|
-
&& date.getUTCDate() === day;
|
|
299
|
-
};
|
|
300
|
-
switch (format) {
|
|
301
|
-
case 'uuid':
|
|
302
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(value);
|
|
303
|
-
case 'date':
|
|
304
|
-
return validDate(value);
|
|
305
|
-
case 'date-time': {
|
|
306
|
-
const match = /^(\d{4}-\d{2}-\d{2})[Tt](?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:[Zz]|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/u.exec(value);
|
|
307
|
-
return Boolean(match && validDate(match[1]));
|
|
308
|
-
}
|
|
309
|
-
case 'time':
|
|
310
|
-
return /^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:[Zz]|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/u.test(value);
|
|
311
|
-
case 'email':
|
|
312
|
-
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/u.test(value);
|
|
313
|
-
case 'uri':
|
|
314
|
-
case 'url':
|
|
315
|
-
case 'uri-reference':
|
|
316
|
-
try {
|
|
317
|
-
return Boolean(new URL(value));
|
|
318
|
-
} catch {
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
case 'hostname':
|
|
322
|
-
return value.length <= 253 && /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\.(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?))*$/iu.test(value);
|
|
323
|
-
case 'ipv4': {
|
|
324
|
-
return isIP(value) === 4;
|
|
325
|
-
}
|
|
326
|
-
case 'ipv6':
|
|
327
|
-
return isIP(value) === 6;
|
|
328
|
-
default:
|
|
329
|
-
return true;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function valueMatchesSchema(value, schema, rootSchema, referenceStack = new Set(), pathValue = '$') {
|
|
334
|
-
if (schema === true || schema === undefined) return true;
|
|
335
|
-
if (schema === false || !schema || typeof schema !== 'object' || Array.isArray(schema)) return false;
|
|
336
|
-
assertSupportedSchemaKeywords(schema, pathValue);
|
|
337
|
-
|
|
338
|
-
if (typeof schema.$ref === 'string') {
|
|
339
|
-
if (referenceStack.has(schema.$ref)) return true;
|
|
340
|
-
const target = resolveLocalReference(rootSchema, schema.$ref);
|
|
341
|
-
const siblings = { ...schema };
|
|
342
|
-
delete siblings.$ref;
|
|
343
|
-
const nextStack = new Set(referenceStack).add(schema.$ref);
|
|
344
|
-
if (!valueMatchesSchema(value, target, rootSchema, nextStack, `${pathValue}:ref`)) return false;
|
|
345
|
-
if (!valueMatchesSchema(value, siblings, rootSchema, nextStack, pathValue)) return false;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
if (Object.prototype.hasOwnProperty.call(schema, 'const') && stableSerialize(value) !== stableSerialize(schema.const)) {
|
|
349
|
-
return false;
|
|
350
|
-
}
|
|
351
|
-
if (Array.isArray(schema.enum) && !schema.enum.some((candidate) => stableSerialize(value) === stableSerialize(candidate))) {
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
if (schema.type !== undefined) {
|
|
355
|
-
const allowedTypes = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
356
|
-
if (!allowedTypes.some((type) => valueMatchesType(value, type))) return false;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (Array.isArray(schema.allOf) && !schema.allOf.every((part, index) =>
|
|
360
|
-
valueMatchesSchema(value, part, rootSchema, referenceStack, `${pathValue}:allOf[${index}]`))) {
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
if (Array.isArray(schema.anyOf) && !schema.anyOf.some((part, index) =>
|
|
364
|
-
valueMatchesSchema(value, part, rootSchema, referenceStack, `${pathValue}:anyOf[${index}]`))) {
|
|
365
|
-
return false;
|
|
366
|
-
}
|
|
367
|
-
if (Array.isArray(schema.oneOf)) {
|
|
368
|
-
const matches = schema.oneOf.filter((part, index) =>
|
|
369
|
-
valueMatchesSchema(value, part, rootSchema, referenceStack, `${pathValue}:oneOf[${index}]`));
|
|
370
|
-
if (matches.length !== 1) return false;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
374
|
-
if (Number.isFinite(schema.minimum) && value < Number(schema.minimum)) return false;
|
|
375
|
-
if (Number.isFinite(schema.maximum) && value > Number(schema.maximum)) return false;
|
|
376
|
-
if (Number.isFinite(schema.exclusiveMinimum) && value <= Number(schema.exclusiveMinimum)) return false;
|
|
377
|
-
if (Number.isFinite(schema.exclusiveMaximum) && value >= Number(schema.exclusiveMaximum)) return false;
|
|
378
|
-
if (Number.isFinite(schema.multipleOf) && schema.multipleOf > 0) {
|
|
379
|
-
const quotient = value / Number(schema.multipleOf);
|
|
380
|
-
if (Math.abs(quotient - Math.round(quotient)) > Number.EPSILON * Math.max(1, Math.abs(quotient))) return false;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if (typeof value === 'string') {
|
|
385
|
-
if (Number.isInteger(schema.minLength) && value.length < schema.minLength) return false;
|
|
386
|
-
if (Number.isInteger(schema.maxLength) && value.length > schema.maxLength) return false;
|
|
387
|
-
if (!valueMatchesFormat(value, schema.format)) return false;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
if (Array.isArray(value)) {
|
|
391
|
-
if (Number.isInteger(schema.minItems) && value.length < schema.minItems) return false;
|
|
392
|
-
if (Number.isInteger(schema.maxItems) && value.length > schema.maxItems) return false;
|
|
393
|
-
const prefixItems = Array.isArray(schema.prefixItems) ? schema.prefixItems : [];
|
|
394
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
395
|
-
const itemSchema = prefixItems[index] ?? schema.items ?? true;
|
|
396
|
-
if (!valueMatchesSchema(value[index], itemSchema, rootSchema, referenceStack, `${pathValue}[${index}]`)) return false;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
401
|
-
const keys = Object.keys(value);
|
|
402
|
-
if (Number.isInteger(schema.minProperties) && keys.length < schema.minProperties) return false;
|
|
403
|
-
if (Number.isInteger(schema.maxProperties) && keys.length > schema.maxProperties) return false;
|
|
404
|
-
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
405
|
-
if (required.some((key) => !Object.prototype.hasOwnProperty.call(value, key))) return false;
|
|
406
|
-
const properties = schema.properties && typeof schema.properties === 'object' && !Array.isArray(schema.properties)
|
|
407
|
-
? schema.properties
|
|
408
|
-
: {};
|
|
409
|
-
for (const key of keys) {
|
|
410
|
-
const propertySchema = Object.prototype.hasOwnProperty.call(properties, key)
|
|
411
|
-
? properties[key]
|
|
412
|
-
: schema.additionalProperties ?? true;
|
|
413
|
-
if (!valueMatchesSchema(value[key], propertySchema, rootSchema, referenceStack, `${pathValue}.${key}`)) return false;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
return true;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
function schemaTypes(schema) {
|
|
421
|
-
if (schema.type === undefined) return null;
|
|
422
|
-
return Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
function intersectSchemaTypes(leftTypes, rightTypes) {
|
|
426
|
-
const intersection = [];
|
|
427
|
-
for (const left of leftTypes) {
|
|
428
|
-
for (const right of rightTypes) {
|
|
429
|
-
let matched = null;
|
|
430
|
-
if (left === right) matched = left;
|
|
431
|
-
else if (
|
|
432
|
-
(left === 'number' && right === 'integer')
|
|
433
|
-
|| (left === 'integer' && right === 'number')
|
|
434
|
-
) matched = 'integer';
|
|
435
|
-
if (matched && !intersection.includes(matched)) intersection.push(matched);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return intersection;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function decimalPlaces(value) {
|
|
442
|
-
const source = String(value).toLowerCase();
|
|
443
|
-
const [coefficient, exponentSource = '0'] = source.split('e');
|
|
444
|
-
const fractionLength = coefficient.includes('.') ? coefficient.split('.')[1].length : 0;
|
|
445
|
-
return Math.max(0, fractionLength - Number(exponentSource));
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
function greatestCommonDivisor(left, right) {
|
|
449
|
-
let a = Math.abs(left);
|
|
450
|
-
let b = Math.abs(right);
|
|
451
|
-
while (b !== 0) [a, b] = [b, a % b];
|
|
452
|
-
return a;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
function leastCommonMultipleOfPositiveNumbers(left, right, pathValue) {
|
|
456
|
-
const precision = Math.max(decimalPlaces(left), decimalPlaces(right));
|
|
457
|
-
if (precision > 12) {
|
|
458
|
-
throw new TypeError(`Cannot safely combine high-precision multipleOf constraints at ${pathValue}`);
|
|
459
|
-
}
|
|
460
|
-
const scale = 10 ** precision;
|
|
461
|
-
const leftScaled = Math.round(left * scale);
|
|
462
|
-
const rightScaled = Math.round(right * scale);
|
|
463
|
-
if (
|
|
464
|
-
!Number.isSafeInteger(leftScaled)
|
|
465
|
-
|| !Number.isSafeInteger(rightScaled)
|
|
466
|
-
|| leftScaled <= 0
|
|
467
|
-
|| rightScaled <= 0
|
|
468
|
-
) {
|
|
469
|
-
throw new TypeError(`Cannot safely combine multipleOf constraints at ${pathValue}`);
|
|
470
|
-
}
|
|
471
|
-
const divisor = greatestCommonDivisor(leftScaled, rightScaled);
|
|
472
|
-
const combinedScaled = (leftScaled / divisor) * rightScaled;
|
|
473
|
-
if (!Number.isSafeInteger(combinedScaled)) {
|
|
474
|
-
throw new TypeError(`Combined multipleOf constraint exceeds safe numeric range at ${pathValue}`);
|
|
475
|
-
}
|
|
476
|
-
return combinedScaled / scale;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
function mergeNestedSchemas(base, addition, pathValue) {
|
|
480
|
-
if (base === undefined || base === true) return cloneJsonValue(addition);
|
|
481
|
-
if (addition === undefined || addition === true) return cloneJsonValue(base);
|
|
482
|
-
if (base === false || addition === false) return false;
|
|
483
|
-
return mergeSchemaConstraints(base, addition, pathValue);
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
function mergeSchemaConstraints(base, addition, pathValue) {
|
|
487
|
-
if (base === true || base === undefined) return cloneJsonValue(addition);
|
|
488
|
-
if (addition === true || addition === undefined) return cloneJsonValue(base);
|
|
489
|
-
if (base === false || addition === false) return false;
|
|
490
|
-
if (!base || !addition || typeof base !== 'object' || typeof addition !== 'object') {
|
|
491
|
-
throw new TypeError(`Cannot combine JSON Schema constraints at ${pathValue}`);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
const output = { ...base, ...addition };
|
|
495
|
-
const baseTypes = schemaTypes(base);
|
|
496
|
-
const additionTypes = schemaTypes(addition);
|
|
497
|
-
if (baseTypes && additionTypes) {
|
|
498
|
-
const intersection = intersectSchemaTypes(baseTypes, additionTypes);
|
|
499
|
-
if (intersection.length === 0) throw new TypeError(`JSON Schema type intersection is empty at ${pathValue}`);
|
|
500
|
-
output.type = intersection.length === 1 ? intersection[0] : intersection;
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
for (const key of ['minimum', 'exclusiveMinimum', 'minLength', 'minItems', 'minProperties']) {
|
|
504
|
-
const values = [base[key], addition[key]].filter((value) => Number.isFinite(value));
|
|
505
|
-
if (values.length > 0) output[key] = Math.max(...values);
|
|
506
|
-
}
|
|
507
|
-
for (const key of ['maximum', 'exclusiveMaximum', 'maxLength', 'maxItems', 'maxProperties']) {
|
|
508
|
-
const values = [base[key], addition[key]].filter((value) => Number.isFinite(value));
|
|
509
|
-
if (values.length > 0) output[key] = Math.min(...values);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
if (base.format && addition.format && base.format !== addition.format) {
|
|
513
|
-
const uriFormats = new Set(['uri', 'url', 'uri-reference']);
|
|
514
|
-
if (uriFormats.has(base.format) && uriFormats.has(addition.format)) output.format = 'uri';
|
|
515
|
-
else throw new TypeError(`JSON Schema formats conflict at ${pathValue}`);
|
|
516
|
-
}
|
|
517
|
-
if (base.multipleOf !== undefined && addition.multipleOf !== undefined && base.multipleOf !== addition.multipleOf) {
|
|
518
|
-
if (
|
|
519
|
-
!Number.isFinite(base.multipleOf)
|
|
520
|
-
|| !Number.isFinite(addition.multipleOf)
|
|
521
|
-
|| base.multipleOf <= 0
|
|
522
|
-
|| addition.multipleOf <= 0
|
|
523
|
-
) throw new TypeError(`Invalid multipleOf constraint at ${pathValue}`);
|
|
524
|
-
output.multipleOf = leastCommonMultipleOfPositiveNumbers(
|
|
525
|
-
Number(base.multipleOf),
|
|
526
|
-
Number(addition.multipleOf),
|
|
527
|
-
pathValue,
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
if (Object.prototype.hasOwnProperty.call(base, 'const') && Object.prototype.hasOwnProperty.call(addition, 'const')) {
|
|
532
|
-
if (stableSerialize(base.const) !== stableSerialize(addition.const)) {
|
|
533
|
-
throw new TypeError(`JSON Schema const intersection is empty at ${pathValue}`);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
if (Array.isArray(base.enum) && Array.isArray(addition.enum)) {
|
|
537
|
-
output.enum = base.enum.filter((candidate) =>
|
|
538
|
-
addition.enum.some((value) => stableSerialize(candidate) === stableSerialize(value)));
|
|
539
|
-
if (output.enum.length === 0) throw new TypeError(`JSON Schema enum intersection is empty at ${pathValue}`);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
if (base.properties || addition.properties) {
|
|
543
|
-
const baseProperties = base.properties && typeof base.properties === 'object' ? base.properties : {};
|
|
544
|
-
const additionProperties = addition.properties && typeof addition.properties === 'object' ? addition.properties : {};
|
|
545
|
-
output.properties = {};
|
|
546
|
-
for (const key of new Set([...Object.keys(baseProperties), ...Object.keys(additionProperties)])) {
|
|
547
|
-
const basePropertySchema = Object.prototype.hasOwnProperty.call(baseProperties, key)
|
|
548
|
-
? baseProperties[key]
|
|
549
|
-
: base.additionalProperties ?? true;
|
|
550
|
-
const additionPropertySchema = Object.prototype.hasOwnProperty.call(additionProperties, key)
|
|
551
|
-
? additionProperties[key]
|
|
552
|
-
: addition.additionalProperties ?? true;
|
|
553
|
-
output.properties[key] = mergeNestedSchemas(
|
|
554
|
-
basePropertySchema,
|
|
555
|
-
additionPropertySchema,
|
|
556
|
-
`${pathValue}.properties.${key}`,
|
|
557
|
-
);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
if (base.required || addition.required) {
|
|
561
|
-
output.required = [...new Set([...(base.required || []), ...(addition.required || [])])];
|
|
562
|
-
}
|
|
563
|
-
if (base.items !== undefined || addition.items !== undefined) {
|
|
564
|
-
output.items = mergeNestedSchemas(base.items, addition.items, `${pathValue}.items`);
|
|
565
|
-
}
|
|
566
|
-
if (base.additionalProperties !== undefined || addition.additionalProperties !== undefined) {
|
|
567
|
-
output.additionalProperties = mergeNestedSchemas(
|
|
568
|
-
base.additionalProperties,
|
|
569
|
-
addition.additionalProperties,
|
|
570
|
-
`${pathValue}.additionalProperties`,
|
|
571
|
-
);
|
|
572
|
-
}
|
|
573
|
-
if (Array.isArray(base.prefixItems) || Array.isArray(addition.prefixItems)) {
|
|
574
|
-
const length = Math.max(base.prefixItems?.length || 0, addition.prefixItems?.length || 0);
|
|
575
|
-
output.prefixItems = Array.from({ length }, (_, index) => mergeNestedSchemas(
|
|
576
|
-
base.prefixItems?.[index],
|
|
577
|
-
addition.prefixItems?.[index],
|
|
578
|
-
`${pathValue}.prefixItems[${index}]`,
|
|
579
|
-
));
|
|
580
|
-
}
|
|
581
|
-
if (base.$defs || addition.$defs) output.$defs = { ...(base.$defs || {}), ...(addition.$defs || {}) };
|
|
582
|
-
delete output.$ref;
|
|
583
|
-
delete output.allOf;
|
|
584
|
-
return output;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
function expandIntersectionSchema(schema, rootSchema, pathValue, referenceStack) {
|
|
588
|
-
if (schema === true || schema === false) return schema;
|
|
589
|
-
if (!schema || typeof schema !== 'object' || Array.isArray(schema)) {
|
|
590
|
-
throw new TypeError(`JSON Schema must be an object or boolean at ${pathValue}`);
|
|
591
|
-
}
|
|
592
|
-
assertSupportedSchemaKeywords(schema, pathValue);
|
|
593
|
-
let expanded = { ...schema };
|
|
594
|
-
|
|
595
|
-
if (typeof expanded.$ref === 'string') {
|
|
596
|
-
if (referenceStack.has(expanded.$ref)) {
|
|
597
|
-
throw new TypeError(`Recursive JSON Schema reference cannot be generated at ${pathValue}: ${expanded.$ref}`);
|
|
598
|
-
}
|
|
599
|
-
const nextStack = new Set(referenceStack).add(expanded.$ref);
|
|
600
|
-
const target = expandIntersectionSchema(
|
|
601
|
-
resolveLocalReference(rootSchema, expanded.$ref),
|
|
602
|
-
rootSchema,
|
|
603
|
-
`${pathValue}:ref`,
|
|
604
|
-
nextStack,
|
|
605
|
-
);
|
|
606
|
-
const siblings = { ...expanded };
|
|
607
|
-
delete siblings.$ref;
|
|
608
|
-
expanded = mergeSchemaConstraints(
|
|
609
|
-
target,
|
|
610
|
-
expandIntersectionSchema(siblings, rootSchema, pathValue, nextStack),
|
|
611
|
-
pathValue,
|
|
612
|
-
);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
if (Array.isArray(expanded.allOf)) {
|
|
616
|
-
const parts = expanded.allOf;
|
|
617
|
-
const siblings = { ...expanded };
|
|
618
|
-
delete siblings.allOf;
|
|
619
|
-
expanded = expandIntersectionSchema(siblings, rootSchema, pathValue, referenceStack);
|
|
620
|
-
parts.forEach((part, index) => {
|
|
621
|
-
expanded = mergeSchemaConstraints(
|
|
622
|
-
expanded,
|
|
623
|
-
expandIntersectionSchema(part, rootSchema, `${pathValue}:allOf[${index}]`, referenceStack),
|
|
624
|
-
pathValue,
|
|
625
|
-
);
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
return expanded;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
function hasGenerationKeyword(schema) {
|
|
632
|
-
return Object.keys(schema).some((key) => !ANNOTATION_ONLY_KEYWORDS.has(key));
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
function inferType(schema) {
|
|
636
|
-
const declared = Array.isArray(schema.type)
|
|
637
|
-
? schema.type.find((typeValue) => typeValue !== 'null') || 'null'
|
|
638
|
-
: schema.type;
|
|
639
|
-
if (declared) return declared;
|
|
640
|
-
if (schema.properties || schema.additionalProperties) return 'object';
|
|
641
|
-
if (schema.items || schema.prefixItems) return 'array';
|
|
642
|
-
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
|
643
|
-
const sample = schema.enum[0];
|
|
644
|
-
if (sample === null) return 'null';
|
|
645
|
-
if (Array.isArray(sample)) return 'array';
|
|
646
|
-
return typeof sample;
|
|
647
|
-
}
|
|
648
|
-
return 'string';
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
function tokenFor(seed, pathValue, length = 10) {
|
|
652
|
-
let token = '';
|
|
653
|
-
let round = 0;
|
|
654
|
-
while (token.length < length) {
|
|
655
|
-
token += hashSeed(`${seed}:${pathValue}:${round}`).toString(16).padStart(8, '0');
|
|
656
|
-
round += 1;
|
|
657
|
-
}
|
|
658
|
-
return token.slice(0, length);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
function resolveStringBounds(schema, pathValue) {
|
|
662
|
-
const minLength = Number.isInteger(schema.minLength) && schema.minLength >= 0 ? schema.minLength : 0;
|
|
663
|
-
const maxLength = Number.isInteger(schema.maxLength) && schema.maxLength >= 0
|
|
664
|
-
? schema.maxLength
|
|
665
|
-
: Number.POSITIVE_INFINITY;
|
|
666
|
-
if (maxLength < minLength) throw new TypeError(`Invalid string bounds at ${pathValue}`);
|
|
667
|
-
return { minLength, maxLength };
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
function fitStringLength(value, schema, seed, pathValue) {
|
|
671
|
-
const { minLength, maxLength } = resolveStringBounds(schema, pathValue);
|
|
672
|
-
let output = String(value);
|
|
673
|
-
while (output.length < minLength) output += tokenFor(seed, `${pathValue}:padding`, minLength - output.length);
|
|
674
|
-
return output.slice(0, maxLength);
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
function fitFormattedString(value, schema, context, pathValue) {
|
|
678
|
-
const { minLength, maxLength } = resolveStringBounds(schema, pathValue);
|
|
679
|
-
if (
|
|
680
|
-
value.length >= minLength
|
|
681
|
-
&& value.length <= maxLength
|
|
682
|
-
&& valueMatchesFormat(value, schema.format)
|
|
683
|
-
) return value;
|
|
684
|
-
|
|
685
|
-
const candidates = [];
|
|
686
|
-
if (schema.format === 'email') {
|
|
687
|
-
const targetLength = Math.max(minLength, 5);
|
|
688
|
-
if (targetLength <= maxLength) {
|
|
689
|
-
const localLength = targetLength - 4;
|
|
690
|
-
candidates.push(`${tokenFor(context.seed, `${pathValue}:compact-email`, localLength)}@b.c`);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
if (['uri', 'url', 'uri-reference'].includes(schema.format)) {
|
|
695
|
-
const targetLength = Math.max(minLength, 3);
|
|
696
|
-
if (targetLength <= maxLength) {
|
|
697
|
-
candidates.push(`x:${tokenFor(context.seed, `${pathValue}:compact-uri`, targetLength - 2)}`);
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
if (schema.format === 'hostname') {
|
|
702
|
-
const targetLength = Math.max(minLength, 1);
|
|
703
|
-
if (targetLength <= Math.min(maxLength, 253)) {
|
|
704
|
-
const labelCount = Math.max(1, Math.ceil((targetLength + 1) / 64));
|
|
705
|
-
const characterCount = targetLength - (labelCount - 1);
|
|
706
|
-
if (characterCount >= labelCount && characterCount <= labelCount * 63) {
|
|
707
|
-
const lengths = Array(labelCount).fill(1);
|
|
708
|
-
let remaining = characterCount - labelCount;
|
|
709
|
-
for (let index = 0; index < lengths.length && remaining > 0; index += 1) {
|
|
710
|
-
const addition = Math.min(62, remaining);
|
|
711
|
-
lengths[index] += addition;
|
|
712
|
-
remaining -= addition;
|
|
713
|
-
}
|
|
714
|
-
candidates.push(lengths.map((length, index) =>
|
|
715
|
-
tokenFor(context.seed, `${pathValue}:hostname:${index}`, length)).join('.'));
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
if (schema.format === 'ipv4') {
|
|
721
|
-
const targetLength = Math.max(minLength, 7);
|
|
722
|
-
if (targetLength <= Math.min(maxLength, 15)) {
|
|
723
|
-
const lengths = [1, 1, 1, 1];
|
|
724
|
-
let remaining = targetLength - 7;
|
|
725
|
-
for (let index = 0; index < lengths.length && remaining > 0; index += 1) {
|
|
726
|
-
const addition = Math.min(2, remaining);
|
|
727
|
-
lengths[index] += addition;
|
|
728
|
-
remaining -= addition;
|
|
729
|
-
}
|
|
730
|
-
candidates.push(lengths.map((length) => '1'.repeat(length)).join('.'));
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
if (schema.format === 'ipv6') candidates.push('::');
|
|
735
|
-
if (schema.format === 'date') candidates.push('2020-01-01');
|
|
736
|
-
if (schema.format === 'date-time') {
|
|
737
|
-
candidates.push('2020-01-01T00:00:00Z');
|
|
738
|
-
for (let digits = 1; digits <= 32; digits += 1) {
|
|
739
|
-
candidates.push(`2020-01-01T00:00:00.${'0'.repeat(digits)}Z`);
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
if (schema.format === 'time') {
|
|
743
|
-
candidates.push('00:00:00Z');
|
|
744
|
-
for (let digits = 1; digits <= 32; digits += 1) {
|
|
745
|
-
candidates.push(`00:00:00.${'0'.repeat(digits)}Z`);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
for (const candidate of candidates) {
|
|
750
|
-
if (
|
|
751
|
-
candidate.length >= minLength
|
|
752
|
-
&& candidate.length <= maxLength
|
|
753
|
-
&& valueMatchesFormat(candidate, schema.format)
|
|
754
|
-
) return candidate;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
const fitted = fitStringLength(value, schema, context.seed, pathValue);
|
|
758
|
-
if (valueMatchesFormat(fitted, schema.format)) return fitted;
|
|
759
|
-
throw new TypeError(`Cannot satisfy string format and length constraints at ${pathValue}`);
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
function generateString(schema, context, pathValue) {
|
|
763
|
-
const token = tokenFor(context.seed, pathValue, 16);
|
|
764
|
-
const fieldName = pathValue.split('.').at(-1)?.replace(/\[\d+\]$/, '').toLowerCase() || 'value';
|
|
765
|
-
let value;
|
|
766
|
-
|
|
767
|
-
switch (schema.format) {
|
|
768
|
-
case 'uuid': {
|
|
769
|
-
const hex = tokenFor(context.seed, `${pathValue}:uuid`, 32);
|
|
770
|
-
value = `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-a${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
771
|
-
break;
|
|
772
|
-
}
|
|
773
|
-
case 'date': {
|
|
774
|
-
const dayOffset = hashSeed(`${context.seed}:${pathValue}:date`) % 3650;
|
|
775
|
-
value = new Date(Date.UTC(2020, 0, 1 + dayOffset)).toISOString().slice(0, 10);
|
|
776
|
-
break;
|
|
777
|
-
}
|
|
778
|
-
case 'date-time': {
|
|
779
|
-
const secondOffset = hashSeed(`${context.seed}:${pathValue}:date-time`) % (3650 * 24 * 60 * 60);
|
|
780
|
-
value = new Date(Date.UTC(2020, 0, 1) + secondOffset * 1000).toISOString();
|
|
781
|
-
break;
|
|
782
|
-
}
|
|
783
|
-
case 'time': {
|
|
784
|
-
const seconds = hashSeed(`${context.seed}:${pathValue}:time`) % 86400;
|
|
785
|
-
value = `${String(Math.floor(seconds / 3600)).padStart(2, '0')}:${String(Math.floor((seconds % 3600) / 60)).padStart(2, '0')}:${String(seconds % 60).padStart(2, '0')}Z`;
|
|
786
|
-
break;
|
|
787
|
-
}
|
|
788
|
-
case 'email':
|
|
789
|
-
value = `mock-${token.slice(0, 8)}@example.test`;
|
|
790
|
-
break;
|
|
791
|
-
case 'uri':
|
|
792
|
-
case 'url':
|
|
793
|
-
case 'uri-reference':
|
|
794
|
-
value = `https://mock.example.test/${token.slice(0, 10)}`;
|
|
795
|
-
break;
|
|
796
|
-
case 'hostname':
|
|
797
|
-
value = `mock-${token.slice(0, 8)}.example.test`;
|
|
798
|
-
break;
|
|
799
|
-
case 'ipv4':
|
|
800
|
-
value = `192.0.2.${1 + (hashSeed(`${context.seed}:${pathValue}:ipv4`) % 254)}`;
|
|
801
|
-
break;
|
|
802
|
-
case 'ipv6':
|
|
803
|
-
value = `2001:db8::${token.slice(0, 4)}`;
|
|
804
|
-
break;
|
|
805
|
-
default:
|
|
806
|
-
if (fieldName === 'id' || fieldName.endsWith('id')) value = `mock-${token.slice(0, 12)}`;
|
|
807
|
-
else if (fieldName.includes('email')) value = `mock-${token.slice(0, 8)}@example.test`;
|
|
808
|
-
else if (fieldName.includes('url') || fieldName.includes('uri')) value = `https://mock.example.test/${token.slice(0, 10)}`;
|
|
809
|
-
else if (fieldName.includes('status')) value = 'MOCKED';
|
|
810
|
-
else if (fieldName.includes('code')) value = `MOCK_${token.slice(0, 8).toUpperCase()}`;
|
|
811
|
-
else if (fieldName.includes('name')) value = `Mock ${token.slice(0, 8)}`;
|
|
812
|
-
else if (fieldName.includes('message') || fieldName.includes('description')) value = `Mock data ${token.slice(0, 8)}`;
|
|
813
|
-
else value = `mock-${token.slice(0, 12)}`;
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
return schema.format
|
|
817
|
-
? fitFormattedString(value, schema, context, pathValue)
|
|
818
|
-
: fitStringLength(value, schema, context.seed, pathValue);
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
function nextRepresentableNumber(value, direction) {
|
|
822
|
-
if (!Number.isFinite(value)) return value;
|
|
823
|
-
if (value === 0) return direction > 0 ? Number.MIN_VALUE : -Number.MIN_VALUE;
|
|
824
|
-
const buffer = new ArrayBuffer(8);
|
|
825
|
-
const view = new DataView(buffer);
|
|
826
|
-
view.setFloat64(0, value, false);
|
|
827
|
-
let bits = view.getBigUint64(0, false);
|
|
828
|
-
if ((value > 0) === (direction > 0)) bits += 1n;
|
|
829
|
-
else bits -= 1n;
|
|
830
|
-
view.setBigUint64(0, bits, false);
|
|
831
|
-
return view.getFloat64(0, false);
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
function generateNumber(schema, context, pathValue, integer) {
|
|
835
|
-
let minimum = null;
|
|
836
|
-
let minimumExclusive = false;
|
|
837
|
-
if (Number.isFinite(schema.minimum)) minimum = Number(schema.minimum);
|
|
838
|
-
if (Number.isFinite(schema.exclusiveMinimum)) {
|
|
839
|
-
const candidate = Number(schema.exclusiveMinimum);
|
|
840
|
-
if (minimum === null || candidate > minimum || candidate === minimum) {
|
|
841
|
-
minimum = candidate;
|
|
842
|
-
minimumExclusive = true;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
let maximum = null;
|
|
846
|
-
let maximumExclusive = false;
|
|
847
|
-
if (Number.isFinite(schema.maximum)) maximum = Number(schema.maximum);
|
|
848
|
-
if (Number.isFinite(schema.exclusiveMaximum)) {
|
|
849
|
-
const candidate = Number(schema.exclusiveMaximum);
|
|
850
|
-
if (maximum === null || candidate < maximum || candidate === maximum) {
|
|
851
|
-
maximum = candidate;
|
|
852
|
-
maximumExclusive = true;
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
if (minimum === null && maximum === null) {
|
|
856
|
-
minimum = 0;
|
|
857
|
-
maximum = 1000;
|
|
858
|
-
} else if (minimum === null) {
|
|
859
|
-
const candidate = maximum - 1000;
|
|
860
|
-
minimum = Number.isFinite(candidate) && candidate < maximum
|
|
861
|
-
? candidate
|
|
862
|
-
: (maximumExclusive ? nextRepresentableNumber(maximum, -1) : maximum);
|
|
863
|
-
} else if (maximum === null) {
|
|
864
|
-
const candidate = minimum + 1000;
|
|
865
|
-
maximum = Number.isFinite(candidate) && candidate > minimum
|
|
866
|
-
? candidate
|
|
867
|
-
: (minimumExclusive ? nextRepresentableNumber(minimum, 1) : minimum);
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
if (integer) {
|
|
871
|
-
minimum = minimumExclusive ? Math.floor(minimum) + 1 : Math.ceil(minimum);
|
|
872
|
-
maximum = maximumExclusive ? Math.ceil(maximum) - 1 : Math.floor(maximum);
|
|
873
|
-
minimumExclusive = false;
|
|
874
|
-
maximumExclusive = false;
|
|
875
|
-
}
|
|
876
|
-
if (maximum < minimum || (maximum === minimum && (minimumExclusive || maximumExclusive))) {
|
|
877
|
-
throw new TypeError(`Invalid numeric bounds at ${pathValue}`);
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
if (Number.isFinite(schema.multipleOf) && schema.multipleOf > 0) {
|
|
881
|
-
const multiple = Number(schema.multipleOf);
|
|
882
|
-
if (integer) {
|
|
883
|
-
const count = maximum - minimum + 1;
|
|
884
|
-
const start = Math.floor(randomUnit(context.seed, pathValue) * count);
|
|
885
|
-
for (let offset = 0; offset < Math.min(count, 10000); offset += 1) {
|
|
886
|
-
const candidate = minimum + ((start + offset) % count);
|
|
887
|
-
const quotient = candidate / multiple;
|
|
888
|
-
if (Math.abs(quotient - Math.round(quotient)) <= Number.EPSILON * Math.max(1, Math.abs(quotient))) {
|
|
889
|
-
return candidate;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
throw new TypeError(`No integer multipleOf value satisfies bounds at ${pathValue}`);
|
|
893
|
-
}
|
|
894
|
-
const firstFactor = minimumExclusive
|
|
895
|
-
? Math.floor(minimum / multiple) + 1
|
|
896
|
-
: Math.ceil(minimum / multiple);
|
|
897
|
-
const lastFactor = maximumExclusive
|
|
898
|
-
? Math.ceil(maximum / multiple) - 1
|
|
899
|
-
: Math.floor(maximum / multiple);
|
|
900
|
-
if (lastFactor < firstFactor) {
|
|
901
|
-
throw new TypeError(`No multipleOf value satisfies bounds at ${pathValue}`);
|
|
902
|
-
}
|
|
903
|
-
const factorCount = lastFactor - firstFactor + 1;
|
|
904
|
-
const factor = firstFactor + Math.floor(randomUnit(context.seed, pathValue) * factorCount);
|
|
905
|
-
return factor * multiple;
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
if (integer) {
|
|
909
|
-
return minimum + Math.floor(randomUnit(context.seed, pathValue) * (maximum - minimum + 1));
|
|
910
|
-
}
|
|
911
|
-
let value = minimum + randomUnit(context.seed, pathValue) * (maximum - minimum);
|
|
912
|
-
if (minimumExclusive && value <= minimum) value = nextRepresentableNumber(minimum, 1);
|
|
913
|
-
if (maximumExclusive && value >= maximum) value = nextRepresentableNumber(maximum, -1);
|
|
914
|
-
if (value < minimum || value > maximum || (minimumExclusive && value === minimum) || (maximumExclusive && value === maximum)) {
|
|
915
|
-
throw new TypeError(`No representable number satisfies bounds at ${pathValue}`);
|
|
916
|
-
}
|
|
917
|
-
return value;
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
function collectionBounds(schema, minimumKey, maximumKey) {
|
|
921
|
-
const minimum = Number.isInteger(schema[minimumKey]) && schema[minimumKey] >= 0 ? schema[minimumKey] : 0;
|
|
922
|
-
const maximum = Number.isInteger(schema[maximumKey]) && schema[maximumKey] >= 0
|
|
923
|
-
? schema[maximumKey]
|
|
924
|
-
: MAX_GENERATED_COLLECTION_SIZE;
|
|
925
|
-
if (minimum > MAX_GENERATED_COLLECTION_SIZE) {
|
|
926
|
-
throw new TypeError(`${minimumKey} exceeds safe generation limit ${MAX_GENERATED_COLLECTION_SIZE}`);
|
|
927
|
-
}
|
|
928
|
-
if (maximum < minimum) throw new TypeError(`Invalid collection bounds: ${minimumKey}/${maximumKey}`);
|
|
929
|
-
return {
|
|
930
|
-
minimum,
|
|
931
|
-
maximum: Math.min(maximum, MAX_GENERATED_COLLECTION_SIZE),
|
|
932
|
-
};
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
function boundedCollectionSize(schema, minimumKey, maximumKey, fallback) {
|
|
936
|
-
const bounds = collectionBounds(schema, minimumKey, maximumKey);
|
|
937
|
-
return Math.min(bounds.maximum, Math.max(bounds.minimum, fallback));
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
function requiredPropertyNames(schema, pathValue) {
|
|
941
|
-
if (schema.required === undefined) return [];
|
|
942
|
-
if (!Array.isArray(schema.required) || schema.required.some((value) => typeof value !== 'string')) {
|
|
943
|
-
throw new TypeError(`JSON Schema required must be an array of strings at ${pathValue}`);
|
|
944
|
-
}
|
|
945
|
-
return [...new Set(schema.required)];
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
function setGeneratedProperty(output, key, value) {
|
|
949
|
-
Object.defineProperty(output, key, {
|
|
950
|
-
configurable: true,
|
|
951
|
-
enumerable: true,
|
|
952
|
-
value,
|
|
953
|
-
writable: true,
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
const NO_SCHEMA_MISMATCH = Symbol('NO_SCHEMA_MISMATCH');
|
|
958
|
-
|
|
959
|
-
function createSchemaMismatchValue(schema, context, pathValue, referenceStack) {
|
|
960
|
-
const candidates = [
|
|
961
|
-
null,
|
|
962
|
-
false,
|
|
963
|
-
true,
|
|
964
|
-
0,
|
|
965
|
-
1,
|
|
966
|
-
'',
|
|
967
|
-
`mismatch-${tokenFor(context.seed, pathValue, 8)}`,
|
|
968
|
-
[],
|
|
969
|
-
{},
|
|
970
|
-
];
|
|
971
|
-
for (const candidate of candidates) {
|
|
972
|
-
if (!valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue)) {
|
|
973
|
-
return cloneJsonValue(candidate);
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
return NO_SCHEMA_MISMATCH;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
function createCompositionEdgeCandidates(schema, context, pathValue, referenceStack, depth) {
|
|
980
|
-
let expanded;
|
|
981
|
-
try {
|
|
982
|
-
expanded = expandIntersectionSchema(schema, context.rootSchema, pathValue, referenceStack);
|
|
983
|
-
} catch (error) {
|
|
984
|
-
if (error?.code === 'SCHEMA_KEYWORD_UNSUPPORTED') throw error;
|
|
985
|
-
return [];
|
|
986
|
-
}
|
|
987
|
-
if (!expanded || typeof expanded !== 'object' || Array.isArray(expanded)) return [];
|
|
988
|
-
if (Object.prototype.hasOwnProperty.call(expanded, 'const')) return [cloneJsonValue(expanded.const)];
|
|
989
|
-
if (Array.isArray(expanded.enum)) return expanded.enum.map((value) => cloneJsonValue(value));
|
|
990
|
-
|
|
991
|
-
const type = inferType(expanded);
|
|
992
|
-
if (type === 'array') {
|
|
993
|
-
const lengths = new Set([
|
|
994
|
-
Number.isInteger(expanded.minItems) && expanded.minItems >= 0 ? expanded.minItems : 0,
|
|
995
|
-
]);
|
|
996
|
-
if (Number.isInteger(expanded.maxItems) && expanded.maxItems >= 0) lengths.add(expanded.maxItems);
|
|
997
|
-
const candidates = [];
|
|
998
|
-
for (const length of lengths) {
|
|
999
|
-
try {
|
|
1000
|
-
candidates.push(generateInternal(
|
|
1001
|
-
{ ...expanded, minItems: length, maxItems: length },
|
|
1002
|
-
context,
|
|
1003
|
-
`${pathValue}:length-${length}`,
|
|
1004
|
-
depth + 1,
|
|
1005
|
-
referenceStack,
|
|
1006
|
-
));
|
|
1007
|
-
} catch (error) {
|
|
1008
|
-
if (error?.code === 'SCHEMA_KEYWORD_UNSUPPORTED') throw error;
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
return candidates;
|
|
1012
|
-
}
|
|
1013
|
-
if (type === 'string') {
|
|
1014
|
-
const lengths = new Set();
|
|
1015
|
-
if (Number.isInteger(expanded.minLength) && expanded.minLength >= 0) lengths.add(expanded.minLength);
|
|
1016
|
-
if (Number.isInteger(expanded.maxLength) && expanded.maxLength >= 0) lengths.add(expanded.maxLength);
|
|
1017
|
-
const candidates = [];
|
|
1018
|
-
for (const length of lengths) {
|
|
1019
|
-
try {
|
|
1020
|
-
candidates.push(generateInternal(
|
|
1021
|
-
{ ...expanded, minLength: length, maxLength: length },
|
|
1022
|
-
context,
|
|
1023
|
-
`${pathValue}:length-${length}`,
|
|
1024
|
-
depth + 1,
|
|
1025
|
-
referenceStack,
|
|
1026
|
-
));
|
|
1027
|
-
} catch (error) {
|
|
1028
|
-
if (error?.code === 'SCHEMA_KEYWORD_UNSUPPORTED') throw error;
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
return candidates;
|
|
1032
|
-
}
|
|
1033
|
-
if (type !== 'integer' && type !== 'number') return [];
|
|
1034
|
-
const integer = type === 'integer';
|
|
1035
|
-
const candidates = [];
|
|
1036
|
-
if (Number.isFinite(expanded.minimum)) {
|
|
1037
|
-
candidates.push(integer ? Math.ceil(expanded.minimum) : Number(expanded.minimum));
|
|
1038
|
-
}
|
|
1039
|
-
if (Number.isFinite(expanded.exclusiveMinimum)) {
|
|
1040
|
-
candidates.push(integer
|
|
1041
|
-
? Math.floor(expanded.exclusiveMinimum) + 1
|
|
1042
|
-
: nextRepresentableNumber(Number(expanded.exclusiveMinimum), 1));
|
|
1043
|
-
}
|
|
1044
|
-
if (Number.isFinite(expanded.maximum)) {
|
|
1045
|
-
candidates.push(integer ? Math.floor(expanded.maximum) : Number(expanded.maximum));
|
|
1046
|
-
}
|
|
1047
|
-
if (Number.isFinite(expanded.exclusiveMaximum)) {
|
|
1048
|
-
candidates.push(integer
|
|
1049
|
-
? Math.ceil(expanded.exclusiveMaximum) - 1
|
|
1050
|
-
: nextRepresentableNumber(Number(expanded.exclusiveMaximum), -1));
|
|
1051
|
-
}
|
|
1052
|
-
return candidates.filter((candidate) =>
|
|
1053
|
-
valueMatchesSchema(candidate, expanded, context.rootSchema, referenceStack, pathValue));
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
function generateInternal(schema, context, pathValue, depth, referenceStack) {
|
|
1057
|
-
if (schema === true || schema === undefined) return generateString({}, context, pathValue);
|
|
1058
|
-
if (schema === false) throw new TypeError(`Cannot generate data from a false JSON Schema at ${pathValue}`);
|
|
1059
|
-
if (!schema || typeof schema !== 'object' || Array.isArray(schema)) {
|
|
1060
|
-
throw new TypeError(`JSON Schema must be an object or boolean at ${pathValue}`);
|
|
1061
|
-
}
|
|
1062
|
-
if (depth > MAX_SCHEMA_DEPTH) throw new TypeError(`JSON Schema exceeds maximum depth at ${pathValue}`);
|
|
1063
|
-
assertSupportedSchemaKeywords(schema, pathValue);
|
|
1064
|
-
|
|
1065
|
-
if (typeof schema.$ref === 'string' || Array.isArray(schema.allOf)) {
|
|
1066
|
-
const expanded = expandIntersectionSchema(schema, context.rootSchema, pathValue, referenceStack);
|
|
1067
|
-
const nextReferenceStack = typeof schema.$ref === 'string'
|
|
1068
|
-
? new Set(referenceStack).add(schema.$ref)
|
|
1069
|
-
: referenceStack;
|
|
1070
|
-
return generateInternal(expanded, context, pathValue, depth + 1, nextReferenceStack);
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
if (Object.prototype.hasOwnProperty.call(schema, 'const')) {
|
|
1074
|
-
const candidate = cloneJsonValue(schema.const);
|
|
1075
|
-
if (!valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue)) {
|
|
1076
|
-
throw new TypeError(`JSON Schema const cannot satisfy sibling constraints at ${pathValue}`);
|
|
1077
|
-
}
|
|
1078
|
-
return candidate;
|
|
1079
|
-
}
|
|
1080
|
-
if (Object.prototype.hasOwnProperty.call(schema, 'default')) {
|
|
1081
|
-
const candidate = cloneJsonValue(schema.default);
|
|
1082
|
-
if (valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue)) return candidate;
|
|
1083
|
-
}
|
|
1084
|
-
if (Object.prototype.hasOwnProperty.call(schema, 'example')) {
|
|
1085
|
-
const candidate = cloneJsonValue(schema.example);
|
|
1086
|
-
if (valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue)) return candidate;
|
|
1087
|
-
}
|
|
1088
|
-
if (Array.isArray(schema.examples) && schema.examples.length > 0) {
|
|
1089
|
-
const candidates = schema.examples.filter((candidate) =>
|
|
1090
|
-
valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue));
|
|
1091
|
-
if (candidates.length > 0) {
|
|
1092
|
-
return cloneJsonValue(choose(candidates, context.seed, `${pathValue}:examples`));
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
|
1096
|
-
const candidates = schema.enum.filter((candidate) =>
|
|
1097
|
-
valueMatchesSchema(candidate, schema, context.rootSchema, referenceStack, pathValue));
|
|
1098
|
-
if (candidates.length === 0) throw new TypeError(`JSON Schema enum cannot satisfy sibling constraints at ${pathValue}`);
|
|
1099
|
-
return cloneJsonValue(choose(candidates, context.seed, `${pathValue}:enum`));
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
for (const keyword of ['oneOf', 'anyOf']) {
|
|
1103
|
-
if (Array.isArray(schema[keyword]) && schema[keyword].length > 0) {
|
|
1104
|
-
const siblings = { ...schema };
|
|
1105
|
-
delete siblings[keyword];
|
|
1106
|
-
const generatedCandidates = [];
|
|
1107
|
-
const branchCandidates = [];
|
|
1108
|
-
for (let index = 0; index < schema[keyword].length; index += 1) {
|
|
1109
|
-
const branch = schema[keyword][index];
|
|
1110
|
-
try {
|
|
1111
|
-
const candidateSchema = hasGenerationKeyword(siblings)
|
|
1112
|
-
? { allOf: [siblings, branch] }
|
|
1113
|
-
: branch;
|
|
1114
|
-
const candidate = generateInternal(
|
|
1115
|
-
candidateSchema,
|
|
1116
|
-
context,
|
|
1117
|
-
`${pathValue}:${keyword}[${index}]`,
|
|
1118
|
-
depth + 1,
|
|
1119
|
-
referenceStack,
|
|
1120
|
-
);
|
|
1121
|
-
const edgeCandidates = createCompositionEdgeCandidates(
|
|
1122
|
-
candidateSchema,
|
|
1123
|
-
context,
|
|
1124
|
-
`${pathValue}:${keyword}[${index}]:edges`,
|
|
1125
|
-
referenceStack,
|
|
1126
|
-
depth,
|
|
1127
|
-
);
|
|
1128
|
-
const currentBranchCandidates = [candidate, ...edgeCandidates];
|
|
1129
|
-
branchCandidates.push(...currentBranchCandidates);
|
|
1130
|
-
for (const branchCandidate of currentBranchCandidates) {
|
|
1131
|
-
if (valueMatchesSchema(branchCandidate, schema, context.rootSchema, referenceStack, pathValue)) {
|
|
1132
|
-
generatedCandidates.push(branchCandidate);
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
} catch (error) {
|
|
1136
|
-
if (error?.code === 'SCHEMA_KEYWORD_UNSUPPORTED') throw error;
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
if (keyword === 'oneOf' && generatedCandidates.length === 0) {
|
|
1140
|
-
for (const candidate of branchCandidates) {
|
|
1141
|
-
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) continue;
|
|
1142
|
-
for (let index = 0; index < schema.oneOf.length; index += 1) {
|
|
1143
|
-
let expandedBranch;
|
|
1144
|
-
try {
|
|
1145
|
-
expandedBranch = expandIntersectionSchema(
|
|
1146
|
-
schema.oneOf[index],
|
|
1147
|
-
context.rootSchema,
|
|
1148
|
-
`${pathValue}:oneOf[${index}]`,
|
|
1149
|
-
referenceStack,
|
|
1150
|
-
);
|
|
1151
|
-
} catch (error) {
|
|
1152
|
-
if (error?.code === 'SCHEMA_KEYWORD_UNSUPPORTED') throw error;
|
|
1153
|
-
continue;
|
|
1154
|
-
}
|
|
1155
|
-
const properties = expandedBranch?.properties;
|
|
1156
|
-
if (!properties || typeof properties !== 'object' || Array.isArray(properties)) continue;
|
|
1157
|
-
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
1158
|
-
const mismatch = createSchemaMismatchValue(
|
|
1159
|
-
propertySchema,
|
|
1160
|
-
context,
|
|
1161
|
-
`${pathValue}:oneOf-mismatch.${key}`,
|
|
1162
|
-
referenceStack,
|
|
1163
|
-
);
|
|
1164
|
-
if (mismatch === NO_SCHEMA_MISMATCH) continue;
|
|
1165
|
-
const variant = cloneJsonValue(candidate);
|
|
1166
|
-
setGeneratedProperty(variant, key, mismatch);
|
|
1167
|
-
if (valueMatchesSchema(variant, schema, context.rootSchema, referenceStack, pathValue)) {
|
|
1168
|
-
generatedCandidates.push(variant);
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
if (generatedCandidates.length === 0) {
|
|
1175
|
-
throw new TypeError(`No ${keyword} branch can satisfy sibling constraints at ${pathValue}`);
|
|
1176
|
-
}
|
|
1177
|
-
return cloneJsonValue(choose(generatedCandidates, context.seed, `${pathValue}:${keyword}`));
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
const type = inferType(schema);
|
|
1182
|
-
switch (type) {
|
|
1183
|
-
case 'null':
|
|
1184
|
-
return null;
|
|
1185
|
-
case 'boolean':
|
|
1186
|
-
return randomUnit(context.seed, pathValue) >= 0.5;
|
|
1187
|
-
case 'integer':
|
|
1188
|
-
return generateNumber(schema, context, pathValue, true);
|
|
1189
|
-
case 'number':
|
|
1190
|
-
return generateNumber(schema, context, pathValue, false);
|
|
1191
|
-
case 'array': {
|
|
1192
|
-
const prefixItems = Array.isArray(schema.prefixItems) ? schema.prefixItems : [];
|
|
1193
|
-
const itemSchema = schema.items === false ? null : (schema.items || {});
|
|
1194
|
-
const falsePrefixIndex = prefixItems.findIndex((entry) => entry === false);
|
|
1195
|
-
const maximumGeneratableLength = falsePrefixIndex >= 0
|
|
1196
|
-
? falsePrefixIndex
|
|
1197
|
-
: (itemSchema ? MAX_GENERATED_COLLECTION_SIZE : prefixItems.length);
|
|
1198
|
-
const fallbackLength = itemSchema
|
|
1199
|
-
? Math.min(DEFAULT_ARRAY_LENGTH, maximumGeneratableLength)
|
|
1200
|
-
: Math.min(DEFAULT_ARRAY_LENGTH, prefixItems.length);
|
|
1201
|
-
const length = boundedCollectionSize(schema, 'minItems', 'maxItems', fallbackLength);
|
|
1202
|
-
if (!itemSchema && length > prefixItems.length) {
|
|
1203
|
-
throw new TypeError(`Cannot satisfy minItems with items=false at ${pathValue}`);
|
|
1204
|
-
}
|
|
1205
|
-
if (length > maximumGeneratableLength) {
|
|
1206
|
-
throw new TypeError(`Cannot satisfy minItems with a false prefixItems schema at ${pathValue}`);
|
|
1207
|
-
}
|
|
1208
|
-
const output = [];
|
|
1209
|
-
for (let index = 0; index < length; index += 1) {
|
|
1210
|
-
const currentSchema = prefixItems[index] === undefined ? itemSchema : prefixItems[index];
|
|
1211
|
-
if (currentSchema === null) break;
|
|
1212
|
-
output.push(generateInternal(currentSchema, context, `${pathValue}[${index}]`, depth + 1, referenceStack));
|
|
1213
|
-
}
|
|
1214
|
-
return output;
|
|
1215
|
-
}
|
|
1216
|
-
case 'object': {
|
|
1217
|
-
const output = {};
|
|
1218
|
-
const properties = schema.properties && typeof schema.properties === 'object' && !Array.isArray(schema.properties)
|
|
1219
|
-
? schema.properties
|
|
1220
|
-
: {};
|
|
1221
|
-
const propertyNames = Object.keys(properties).sort();
|
|
1222
|
-
const generatablePropertyNames = propertyNames.filter((key) => properties[key] !== false);
|
|
1223
|
-
const requiredNames = requiredPropertyNames(schema, pathValue);
|
|
1224
|
-
const bounds = collectionBounds(schema, 'minProperties', 'maxProperties');
|
|
1225
|
-
if (requiredNames.length > bounds.maximum) {
|
|
1226
|
-
throw new TypeError(`Required properties exceed maxProperties at ${pathValue}`);
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
const additionalAllowed = schema.additionalProperties !== false;
|
|
1230
|
-
const additionalSchema = schema.additionalProperties && typeof schema.additionalProperties === 'object'
|
|
1231
|
-
? schema.additionalProperties
|
|
1232
|
-
: { type: 'string' };
|
|
1233
|
-
const targetSize = Math.min(
|
|
1234
|
-
bounds.maximum,
|
|
1235
|
-
Math.max(bounds.minimum, new Set([...generatablePropertyNames, ...requiredNames]).size),
|
|
1236
|
-
);
|
|
1237
|
-
|
|
1238
|
-
for (const key of requiredNames) {
|
|
1239
|
-
const declared = Object.prototype.hasOwnProperty.call(properties, key);
|
|
1240
|
-
if (declared && properties[key] === false) {
|
|
1241
|
-
throw new TypeError(`Required property ${JSON.stringify(key)} has a false schema at ${pathValue}`);
|
|
1242
|
-
}
|
|
1243
|
-
const propertySchema = declared ? properties[key] : additionalAllowed ? additionalSchema : null;
|
|
1244
|
-
if (propertySchema === null) {
|
|
1245
|
-
throw new TypeError(`Required property ${JSON.stringify(key)} is not allowed at ${pathValue}`);
|
|
1246
|
-
}
|
|
1247
|
-
setGeneratedProperty(
|
|
1248
|
-
output,
|
|
1249
|
-
key,
|
|
1250
|
-
generateInternal(propertySchema, context, `${pathValue}.${key}`, depth + 1, referenceStack),
|
|
1251
|
-
);
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
for (const key of generatablePropertyNames) {
|
|
1255
|
-
if (Object.keys(output).length >= targetSize) break;
|
|
1256
|
-
if (Object.prototype.hasOwnProperty.call(output, key)) continue;
|
|
1257
|
-
setGeneratedProperty(
|
|
1258
|
-
output,
|
|
1259
|
-
key,
|
|
1260
|
-
generateInternal(properties[key], context, `${pathValue}.${key}`, depth + 1, referenceStack),
|
|
1261
|
-
);
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
if (Object.keys(output).length < bounds.minimum && !additionalAllowed) {
|
|
1265
|
-
throw new TypeError(`Cannot satisfy minProperties with additionalProperties=false at ${pathValue}`);
|
|
1266
|
-
}
|
|
1267
|
-
let additionalIndex = 1;
|
|
1268
|
-
while (Object.keys(output).length < bounds.minimum) {
|
|
1269
|
-
let key = `additionalField${additionalIndex}`;
|
|
1270
|
-
additionalIndex += 1;
|
|
1271
|
-
while (Object.prototype.hasOwnProperty.call(output, key) || Object.prototype.hasOwnProperty.call(properties, key)) {
|
|
1272
|
-
key = `additionalField${additionalIndex}`;
|
|
1273
|
-
additionalIndex += 1;
|
|
1274
|
-
}
|
|
1275
|
-
setGeneratedProperty(
|
|
1276
|
-
output,
|
|
1277
|
-
key,
|
|
1278
|
-
generateInternal(additionalSchema, context, `${pathValue}.${key}`, depth + 1, referenceStack),
|
|
1279
|
-
);
|
|
1280
|
-
}
|
|
1281
|
-
return output;
|
|
1282
|
-
}
|
|
1283
|
-
case 'string':
|
|
1284
|
-
return generateString(schema, context, pathValue);
|
|
1285
|
-
default:
|
|
1286
|
-
throw new TypeError(`Unsupported JSON Schema type "${type}" at ${pathValue}`);
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
/**
|
|
1291
|
-
* Generate JSON-compatible mock data from a JSON Schema. The same schema, seed
|
|
1292
|
-
* and path always produce byte-for-byte equivalent data.
|
|
1293
|
-
*/
|
|
1294
|
-
export function generateFromSchema(schema, options = {}) {
|
|
1295
|
-
const seed = String(options.seed ?? 'soma-mock');
|
|
1296
|
-
const pathValue = String(options.path ?? '$');
|
|
1297
|
-
assertValidSchemaDocument(schema, pathValue);
|
|
1298
|
-
const value = generateInternal(
|
|
1299
|
-
schema,
|
|
1300
|
-
{ seed, rootSchema: schema },
|
|
1301
|
-
pathValue,
|
|
1302
|
-
0,
|
|
1303
|
-
new Set(),
|
|
1304
|
-
);
|
|
1305
|
-
if (!valueMatchesSchema(value, schema, schema)) {
|
|
1306
|
-
throw new TypeError('Generated value does not satisfy the supported JSON Schema constraints at $');
|
|
1307
|
-
}
|
|
1308
|
-
return value;
|
|
1309
|
-
}
|