@halonicjs/testing 0.0.0-stage → 0.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/LICENSE +202 -0
- package/NOTICE +1 -0
- package/README.md +40 -2
- package/dist/adapters/http-kit/src/address-class.d.ts +34 -0
- package/dist/adapters/http-kit/src/address-class.js +109 -0
- package/dist/adapters/http-kit/src/index.d.ts +2 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ip-address.d.ts +23 -0
- package/dist/adapters/http-kit/src/ip-address.js +89 -0
- package/dist/adapters/integration-kit/src/declaration.d.ts +14 -0
- package/dist/adapters/integration-kit/src/declaration.js +77 -0
- package/dist/adapters/integration-kit/src/host.d.ts +28 -0
- package/dist/adapters/integration-kit/src/host.js +30 -0
- package/dist/adapters/integration-kit/src/index.d.ts +14 -0
- package/dist/adapters/integration-kit/src/index.js +21 -0
- package/dist/adapters/integration-kit/src/leak-attempt.d.ts +14 -0
- package/dist/adapters/integration-kit/src/leak-attempt.js +16 -0
- package/dist/adapters/integration-kit/src/limited-http.d.ts +49 -0
- package/dist/adapters/integration-kit/src/limited-http.js +182 -0
- package/dist/adapters/integration-kit/src/load-problem.d.ts +20 -0
- package/dist/adapters/integration-kit/src/load-problem.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +104 -0
- package/dist/adapters/integration-kit/src/loader.js +219 -0
- package/dist/adapters/integration-kit/src/local-address.d.ts +15 -0
- package/dist/adapters/integration-kit/src/local-address.js +25 -0
- package/dist/adapters/integration-kit/src/own-request.d.ts +33 -0
- package/dist/adapters/integration-kit/src/own-request.js +36 -0
- package/dist/adapters/integration-kit/src/plugin-load.d.ts +14 -0
- package/dist/adapters/integration-kit/src/plugin-load.js +58 -0
- package/dist/adapters/integration-kit/src/policy.d.ts +55 -0
- package/dist/adapters/integration-kit/src/policy.js +37 -0
- package/dist/adapters/integration-kit/src/request-body.d.ts +38 -0
- package/dist/adapters/integration-kit/src/request-body.js +68 -0
- package/dist/adapters/integration-kit/src/request-log.d.ts +25 -0
- package/dist/adapters/integration-kit/src/request-log.js +17 -0
- package/dist/adapters/integration-kit/src/response-body.d.ts +23 -0
- package/dist/adapters/integration-kit/src/response-body.js +117 -0
- package/dist/adapters/integration-kit/src/scoped-tokens.d.ts +14 -0
- package/dist/adapters/integration-kit/src/scoped-tokens.js +27 -0
- package/dist/adapters/integration-kit/src/secret-filter.d.ts +84 -0
- package/dist/adapters/integration-kit/src/secret-filter.js +205 -0
- package/dist/adapters/integration-kit/src/secret-in-request.d.ts +59 -0
- package/dist/adapters/integration-kit/src/secret-in-request.js +133 -0
- package/dist/adapters/integration-kit/src/secret-placement.d.ts +36 -0
- package/dist/adapters/integration-kit/src/secret-placement.js +190 -0
- package/dist/adapters/integration-kit/src/wait.d.ts +16 -0
- package/dist/adapters/integration-kit/src/wait.js +35 -0
- package/dist/core/events/src/add-usage.d.ts +10 -0
- package/dist/core/events/src/add-usage.js +27 -0
- package/dist/core/events/src/agent-resume.d.ts +24 -0
- package/dist/core/events/src/agent-resume.js +1 -0
- package/dist/core/events/src/home-path.d.ts +13 -0
- package/dist/core/events/src/home-path.js +26 -0
- package/dist/core/events/src/index.d.ts +13 -0
- package/dist/core/events/src/index.js +7 -0
- package/dist/core/events/src/run-basics.d.ts +205 -0
- package/dist/core/events/src/run-basics.js +1 -0
- package/dist/core/events/src/run-event.d.ts +434 -0
- package/dist/core/events/src/run-event.js +1 -0
- package/dist/core/events/src/run-summary.d.ts +108 -0
- package/dist/core/events/src/run-summary.js +1 -0
- package/dist/core/events/src/sandbox-blocked.d.ts +42 -0
- package/dist/core/events/src/sandbox-blocked.js +26 -0
- package/dist/core/events/src/sandbox-opened-read.d.ts +17 -0
- package/dist/core/events/src/sandbox-opened-read.js +63 -0
- package/dist/core/events/src/sandbox-opened.d.ts +94 -0
- package/dist/core/events/src/sandbox-opened.js +52 -0
- package/dist/core/events/src/summarize.d.ts +14 -0
- package/dist/core/events/src/summarize.js +188 -0
- package/dist/core/events/src/timeline-entry.d.ts +21 -0
- package/dist/core/events/src/timeline-entry.js +105 -0
- package/dist/core/events/src/upgrade.d.ts +23 -0
- package/dist/core/events/src/upgrade.js +49 -0
- package/dist/core/format/src/compact.d.ts +30 -0
- package/dist/core/format/src/compact.js +72 -0
- package/dist/core/format/src/index.d.ts +37 -0
- package/dist/core/format/src/index.js +23 -0
- package/dist/core/format/src/integration/index.d.ts +6 -0
- package/dist/core/format/src/integration/index.js +9 -0
- package/dist/core/format/src/json-schema.d.ts +26 -0
- package/dist/core/format/src/json-schema.js +48 -0
- package/dist/core/format/src/kind.d.ts +65 -0
- package/dist/core/format/src/kind.js +1 -0
- package/dist/core/format/src/kinds/agent/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/agent/kind.js +10 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +89 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.js +197 -0
- package/dist/core/format/src/kinds/agent/schema.d.ts +147 -0
- package/dist/core/format/src/kinds/agent/schema.js +107 -0
- package/dist/core/format/src/kinds/agent/working-folder-start.d.ts +74 -0
- package/dist/core/format/src/kinds/agent/working-folder-start.js +312 -0
- package/dist/core/format/src/kinds/collection/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/collection/kind.js +14 -0
- package/dist/core/format/src/kinds/collection/schema.d.ts +89 -0
- package/dist/core/format/src/kinds/collection/schema.js +90 -0
- package/dist/core/format/src/kinds/connector/is-local.d.ts +10 -0
- package/dist/core/format/src/kinds/connector/is-local.js +43 -0
- package/dist/core/format/src/kinds/connector/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/connector/kind.js +119 -0
- package/dist/core/format/src/kinds/connector/schema.d.ts +50 -0
- package/dist/core/format/src/kinds/connector/schema.js +92 -0
- package/dist/core/format/src/kinds/deployments/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/deployments/kind.js +25 -0
- package/dist/core/format/src/kinds/deployments/schema.d.ts +37 -0
- package/dist/core/format/src/kinds/deployments/schema.js +42 -0
- package/dist/core/format/src/kinds/hub/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/hub/kind.js +10 -0
- package/dist/core/format/src/kinds/hub/schema.d.ts +54 -0
- package/dist/core/format/src/kinds/hub/schema.js +34 -0
- package/dist/core/format/src/kinds/integration/kind.d.ts +16 -0
- package/dist/core/format/src/kinds/integration/kind.js +138 -0
- package/dist/core/format/src/kinds/integration/parse-sheet.d.ts +19 -0
- package/dist/core/format/src/kinds/integration/parse-sheet.js +24 -0
- package/dist/core/format/src/kinds/integration/policy.d.ts +67 -0
- package/dist/core/format/src/kinds/integration/policy.js +268 -0
- package/dist/core/format/src/kinds/integration/schema.d.ts +233 -0
- package/dist/core/format/src/kinds/integration/schema.js +233 -0
- package/dist/core/format/src/kinds/knowledge/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/knowledge/kind.js +13 -0
- package/dist/core/format/src/kinds/knowledge/schema.d.ts +18 -0
- package/dist/core/format/src/kinds/knowledge/schema.js +25 -0
- package/dist/core/format/src/kinds/models/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/models/kind.js +10 -0
- package/dist/core/format/src/kinds/models/schema.d.ts +92 -0
- package/dist/core/format/src/kinds/models/schema.js +38 -0
- package/dist/core/format/src/kinds/plugin/backend.d.ts +22 -0
- package/dist/core/format/src/kinds/plugin/backend.js +31 -0
- package/dist/core/format/src/kinds/plugin/checks.d.ts +13 -0
- package/dist/core/format/src/kinds/plugin/checks.js +131 -0
- package/dist/core/format/src/kinds/plugin/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/plugin/kind.js +16 -0
- package/dist/core/format/src/kinds/plugin/problems.d.ts +24 -0
- package/dist/core/format/src/kinds/plugin/problems.js +65 -0
- package/dist/core/format/src/kinds/plugin/schema.d.ts +542 -0
- package/dist/core/format/src/kinds/plugin/schema.js +261 -0
- package/dist/core/format/src/kinds/plugin/setting-values.d.ts +17 -0
- package/dist/core/format/src/kinds/plugin/setting-values.js +38 -0
- package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +8 -0
- package/dist/core/format/src/kinds/plugin/ui-checks.js +94 -0
- package/dist/core/format/src/kinds/provider/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/provider/kind.js +24 -0
- package/dist/core/format/src/kinds/provider/schema.d.ts +17 -0
- package/dist/core/format/src/kinds/provider/schema.js +22 -0
- package/dist/core/format/src/kinds/routine/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/routine/kind.js +25 -0
- package/dist/core/format/src/kinds/routine/schema.d.ts +84 -0
- package/dist/core/format/src/kinds/routine/schema.js +93 -0
- package/dist/core/format/src/kinds/runtime/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/runtime/kind.js +13 -0
- package/dist/core/format/src/kinds/runtime/schema.d.ts +10 -0
- package/dist/core/format/src/kinds/runtime/schema.js +12 -0
- package/dist/core/format/src/kinds/skill/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/skill/kind.js +10 -0
- package/dist/core/format/src/kinds/skill/schema.d.ts +17 -0
- package/dist/core/format/src/kinds/skill/schema.js +17 -0
- package/dist/core/format/src/kinds/skill/scripts-folder.d.ts +27 -0
- package/dist/core/format/src/kinds/skill/scripts-folder.js +37 -0
- package/dist/core/format/src/kinds/workflow/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/workflow/kind.js +14 -0
- package/dist/core/format/src/kinds/workflow/schema.d.ts +162 -0
- package/dist/core/format/src/kinds/workflow/schema.js +106 -0
- package/dist/core/format/src/kinds/workflow-test/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/workflow-test/kind.js +14 -0
- package/dist/core/format/src/kinds/workflow-test/schema.d.ts +67 -0
- package/dist/core/format/src/kinds/workflow-test/schema.js +59 -0
- package/dist/core/format/src/kinds/workspace/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/workspace/kind.js +10 -0
- package/dist/core/format/src/kinds/workspace/schema.d.ts +72 -0
- package/dist/core/format/src/kinds/workspace/schema.js +66 -0
- package/dist/core/format/src/parse-file.d.ts +69 -0
- package/dist/core/format/src/parse-file.js +105 -0
- package/dist/core/format/src/recording/format.d.ts +81 -0
- package/dist/core/format/src/recording/format.js +102 -0
- package/dist/core/format/src/recording/index.d.ts +1 -0
- package/dist/core/format/src/recording/index.js +3 -0
- package/dist/core/format/src/registry.d.ts +64 -0
- package/dist/core/format/src/registry.js +61 -0
- package/dist/core/format/src/reserved.d.ts +20 -0
- package/dist/core/format/src/reserved.js +30 -0
- package/dist/core/format/src/shared/fields.d.ts +37 -0
- package/dist/core/format/src/shared/fields.js +54 -0
- package/dist/core/format/src/shared/guard.d.ts +32 -0
- package/dist/core/format/src/shared/guard.js +16 -0
- package/dist/core/format/src/shared/key-in-value.d.ts +28 -0
- package/dist/core/format/src/shared/key-in-value.js +82 -0
- package/dist/core/format/src/shared/legacy-keys.d.ts +8 -0
- package/dist/core/format/src/shared/legacy-keys.js +17 -0
- package/dist/core/format/src/shared/program-start.d.ts +60 -0
- package/dist/core/format/src/shared/program-start.js +99 -0
- package/dist/core/format/src/shared/relative-path.d.ts +29 -0
- package/dist/core/format/src/shared/relative-path.js +50 -0
- package/dist/core/format/src/shared/secret-name.d.ts +24 -0
- package/dist/core/format/src/shared/secret-name.js +107 -0
- package/dist/core/format/src/source.d.ts +16 -0
- package/dist/core/format/src/source.js +73 -0
- package/dist/core/ports/src/agent-placement-store.d.ts +74 -0
- package/dist/core/ports/src/agent-placement-store.js +27 -0
- package/dist/core/ports/src/blob-store.d.ts +33 -0
- package/dist/core/ports/src/blob-store.js +2 -0
- package/dist/core/ports/src/cant-try-error.d.ts +35 -0
- package/dist/core/ports/src/cant-try-error.js +44 -0
- package/dist/core/ports/src/chat.d.ts +127 -0
- package/dist/core/ports/src/chat.js +1 -0
- package/dist/core/ports/src/clock.d.ts +7 -0
- package/dist/core/ports/src/clock.js +2 -0
- package/dist/core/ports/src/connection-settings-store.d.ts +57 -0
- package/dist/core/ports/src/connection-settings-store.js +2 -0
- package/dist/core/ports/src/connector-client.d.ts +259 -0
- package/dist/core/ports/src/connector-client.js +2 -0
- package/dist/core/ports/src/coordination.d.ts +84 -0
- package/dist/core/ports/src/coordination.js +2 -0
- package/dist/core/ports/src/definition-store.d.ts +208 -0
- package/dist/core/ports/src/definition-store.js +122 -0
- package/dist/core/ports/src/digest.d.ts +14 -0
- package/dist/core/ports/src/digest.js +2 -0
- package/dist/core/ports/src/folder-reader.d.ts +89 -0
- package/dist/core/ports/src/folder-reader.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +189 -0
- package/dist/core/ports/src/harness-bridge-server.js +37 -0
- package/dist/core/ports/src/harness.d.ts +250 -0
- package/dist/core/ports/src/harness.js +45 -0
- package/dist/core/ports/src/http-client.d.ts +27 -0
- package/dist/core/ports/src/http-client.js +2 -0
- package/dist/core/ports/src/id-generator.d.ts +14 -0
- package/dist/core/ports/src/id-generator.js +2 -0
- package/dist/core/ports/src/index.d.ts +37 -0
- package/dist/core/ports/src/index.js +36 -0
- package/dist/core/ports/src/integration.d.ts +178 -0
- package/dist/core/ports/src/integration.js +13 -0
- package/dist/core/ports/src/knowledge-provider.d.ts +65 -0
- package/dist/core/ports/src/knowledge-provider.js +2 -0
- package/dist/core/ports/src/llm-cache.d.ts +13 -0
- package/dist/core/ports/src/llm-cache.js +2 -0
- package/dist/core/ports/src/llm-provider.d.ts +184 -0
- package/dist/core/ports/src/llm-provider.js +136 -0
- package/dist/core/ports/src/model-price.d.ts +34 -0
- package/dist/core/ports/src/model-price.js +25 -0
- package/dist/core/ports/src/password-hasher.d.ts +47 -0
- package/dist/core/ports/src/password-hasher.js +2 -0
- package/dist/core/ports/src/plugin-folder-writer.d.ts +104 -0
- package/dist/core/ports/src/plugin-folder-writer.js +95 -0
- package/dist/core/ports/src/port-versions.d.ts +44 -0
- package/dist/core/ports/src/port-versions.js +74 -0
- package/dist/core/ports/src/program-probe.d.ts +46 -0
- package/dist/core/ports/src/program-probe.js +2 -0
- package/dist/core/ports/src/record-store.d.ts +62 -0
- package/dist/core/ports/src/record-store.js +38 -0
- package/dist/core/ports/src/resource-probe.d.ts +59 -0
- package/dist/core/ports/src/resource-probe.js +2 -0
- package/dist/core/ports/src/run-executor.d.ts +302 -0
- package/dist/core/ports/src/run-executor.js +2 -0
- package/dist/core/ports/src/run-failure-error.d.ts +49 -0
- package/dist/core/ports/src/run-failure-error.js +47 -0
- package/dist/core/ports/src/run-store.d.ts +194 -0
- package/dist/core/ports/src/run-store.js +131 -0
- package/dist/core/ports/src/sandbox.d.ts +247 -0
- package/dist/core/ports/src/sandbox.js +34 -0
- package/dist/core/ports/src/scheduler.d.ts +85 -0
- package/dist/core/ports/src/scheduler.js +2 -0
- package/dist/core/ports/src/secrets.d.ts +128 -0
- package/dist/core/ports/src/secrets.js +144 -0
- package/dist/core/ports/src/token-store.d.ts +19 -0
- package/dist/core/ports/src/token-store.js +2 -0
- package/dist/core/ports/src/tool-approval-store.d.ts +211 -0
- package/dist/core/ports/src/tool-approval-store.js +57 -0
- package/dist/core/ports/src/trust-store.d.ts +72 -0
- package/dist/core/ports/src/trust-store.js +2 -0
- package/dist/core/ports/src/unfenced-run-consent-store.d.ts +43 -0
- package/dist/core/ports/src/unfenced-run-consent-store.js +2 -0
- package/dist/core/ports/src/vcs.d.ts +394 -0
- package/dist/core/ports/src/vcs.js +48 -0
- package/dist/core/schema-kit/src/builders.d.ts +50 -0
- package/dist/core/schema-kit/src/builders.js +72 -0
- package/dist/core/schema-kit/src/depth.d.ts +15 -0
- package/dist/core/schema-kit/src/depth.js +37 -0
- package/dist/core/schema-kit/src/index.d.ts +6 -0
- package/dist/core/schema-kit/src/index.js +6 -0
- package/dist/core/schema-kit/src/issue.d.ts +22 -0
- package/dist/core/schema-kit/src/issue.js +23 -0
- package/dist/core/schema-kit/src/json-schema.d.ts +23 -0
- package/dist/core/schema-kit/src/json-schema.js +22 -0
- package/dist/core/schema-kit/src/parse.d.ts +17 -0
- package/dist/core/schema-kit/src/parse.js +25 -0
- package/dist/core/schema-kit/src/schema.d.ts +12 -0
- package/dist/core/schema-kit/src/schema.js +1 -0
- package/dist/core/std/src/ascii-host.d.ts +18 -0
- package/dist/core/std/src/ascii-host.js +110 -0
- package/dist/core/std/src/assert.d.ts +39 -0
- package/dist/core/std/src/assert.js +59 -0
- package/dist/core/std/src/base64url.d.ts +23 -0
- package/dist/core/std/src/base64url.js +65 -0
- package/dist/core/std/src/canonical-json.d.ts +18 -0
- package/dist/core/std/src/canonical-json.js +56 -0
- package/dist/core/std/src/clock.d.ts +27 -0
- package/dist/core/std/src/clock.js +33 -0
- package/dist/core/std/src/constant-time.d.ts +16 -0
- package/dist/core/std/src/constant-time.js +26 -0
- package/dist/core/std/src/content-digest.d.ts +24 -0
- package/dist/core/std/src/content-digest.js +28 -0
- package/dist/core/std/src/deep-clone.d.ts +15 -0
- package/dist/core/std/src/deep-clone.js +59 -0
- package/dist/core/std/src/deep-equal.d.ts +23 -0
- package/dist/core/std/src/deep-equal.js +64 -0
- package/dist/core/std/src/emitter.d.ts +42 -0
- package/dist/core/std/src/emitter.js +74 -0
- package/dist/core/std/src/error-kind.d.ts +88 -0
- package/dist/core/std/src/error-kind.js +98 -0
- package/dist/core/std/src/hex.d.ts +10 -0
- package/dist/core/std/src/hex.js +16 -0
- package/dist/core/std/src/ids.d.ts +45 -0
- package/dist/core/std/src/ids.js +49 -0
- package/dist/core/std/src/index.d.ts +25 -0
- package/dist/core/std/src/index.js +26 -0
- package/dist/core/std/src/keyed-queue.d.ts +18 -0
- package/dist/core/std/src/keyed-queue.js +32 -0
- package/dist/core/std/src/line-diff.d.ts +83 -0
- package/dist/core/std/src/line-diff.js +179 -0
- package/dist/core/std/src/line-merge.d.ts +63 -0
- package/dist/core/std/src/line-merge.js +138 -0
- package/dist/core/std/src/plain-data.d.ts +32 -0
- package/dist/core/std/src/plain-data.js +57 -0
- package/dist/core/std/src/posix-path.d.ts +61 -0
- package/dist/core/std/src/posix-path.js +121 -0
- package/dist/core/std/src/result.d.ts +55 -0
- package/dist/core/std/src/result.js +52 -0
- package/dist/core/std/src/secret-scrubber.d.ts +54 -0
- package/dist/core/std/src/secret-scrubber.js +124 -0
- package/dist/core/std/src/secret-shape.d.ts +20 -0
- package/dist/core/std/src/secret-shape.js +53 -0
- package/dist/core/std/src/stop-signal.d.ts +44 -0
- package/dist/core/std/src/stop-signal.js +77 -0
- package/dist/core/std/src/text.d.ts +28 -0
- package/dist/core/std/src/text.js +54 -0
- package/dist/core/std/src/utf8.d.ts +23 -0
- package/dist/core/std/src/utf8.js +110 -0
- package/dist/core/std/src/version.d.ts +48 -0
- package/dist/core/std/src/version.js +103 -0
- package/dist/core/yaml/src/depth.d.ts +14 -0
- package/dist/core/yaml/src/depth.js +140 -0
- package/dist/core/yaml/src/edit-data.d.ts +47 -0
- package/dist/core/yaml/src/edit-data.js +286 -0
- package/dist/core/yaml/src/edit-text.d.ts +92 -0
- package/dist/core/yaml/src/edit-text.js +267 -0
- package/dist/core/yaml/src/edit.d.ts +47 -0
- package/dist/core/yaml/src/edit.js +198 -0
- package/dist/core/yaml/src/index.d.ts +5 -0
- package/dist/core/yaml/src/index.js +4 -0
- package/dist/core/yaml/src/problem.d.ts +20 -0
- package/dist/core/yaml/src/problem.js +1 -0
- package/dist/core/yaml/src/read.d.ts +47 -0
- package/dist/core/yaml/src/read.js +130 -0
- package/dist/core/yaml/src/splice-node.d.ts +47 -0
- package/dist/core/yaml/src/splice-node.js +333 -0
- package/dist/core/yaml/src/splice.d.ts +13 -0
- package/dist/core/yaml/src/splice.js +174 -0
- package/dist/core/yaml/src/unsupported.d.ts +26 -0
- package/dist/core/yaml/src/unsupported.js +70 -0
- package/dist/core/yaml/src/write.d.ts +35 -0
- package/dist/core/yaml/src/write.js +44 -0
- package/dist/testing/integration/src/canaries.d.ts +14 -0
- package/dist/testing/integration/src/canaries.js +17 -0
- package/dist/testing/integration/src/checks.d.ts +37 -0
- package/dist/testing/integration/src/checks.js +195 -0
- package/dist/testing/integration/src/describe.d.ts +35 -0
- package/dist/testing/integration/src/describe.js +74 -0
- package/dist/testing/integration/src/failure.d.ts +6 -0
- package/dist/testing/integration/src/failure.js +8 -0
- package/dist/testing/integration/src/fake-wait.d.ts +18 -0
- package/dist/testing/integration/src/fake-wait.js +21 -0
- package/dist/testing/integration/src/index.d.ts +10 -0
- package/dist/testing/integration/src/index.js +11 -0
- package/dist/testing/integration/src/load.d.ts +14 -0
- package/dist/testing/integration/src/load.js +45 -0
- package/dist/testing/integration/src/plugin-folder.d.ts +23 -0
- package/dist/testing/integration/src/plugin-folder.js +59 -0
- package/dist/testing/integration/src/plugin.d.ts +32 -0
- package/dist/testing/integration/src/plugin.js +57 -0
- package/dist/testing/integration/src/recording.d.ts +84 -0
- package/dist/testing/integration/src/recording.js +164 -0
- package/dist/testing/integration/src/run.d.ts +60 -0
- package/dist/testing/integration/src/run.js +81 -0
- package/dist/testing/integration/src/source-scan.d.ts +16 -0
- package/dist/testing/integration/src/source-scan.js +40 -0
- package/package.json +35 -4
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** An IPv4 octet as `URL` writes it: 0 to 255, without leading zeros. */
|
|
3
|
+
const ipv4Octet = String.raw `(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)`;
|
|
4
|
+
/** One lower-case name label. */
|
|
5
|
+
const nameLabel = String.raw `[a-z0-9](?:[a-z0-9-]*[a-z0-9])?`;
|
|
6
|
+
/**
|
|
7
|
+
* A host as `URL` writes it: a dotted IPv4 address, lower-case name labels or a
|
|
8
|
+
* bracketed IPv6 address. `URL` reads a name whose last label is a number, such
|
|
9
|
+
* as `999.999.999.999` or `1.2.3`, as an IPv4 address and refuses or rewrites
|
|
10
|
+
* it, so a name's last label may not be digits or `0x` with hex digits.
|
|
11
|
+
*/
|
|
12
|
+
const urlHost = String.raw `(?:${ipv4Octet}(?:\.${ipv4Octet}){3}|(?:${nameLabel}\.)*(?!(?:\d+|0x[0-9a-f]*)(?![a-z0-9-]))${nameLabel}|\[[0-9a-f:.]+\])`;
|
|
13
|
+
/** A port as `URL` writes it: 0 to 65535, without leading zeros. */
|
|
14
|
+
const urlPort = String.raw `(?:6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]\d{4}|[1-9]\d{0,3}|0)`;
|
|
15
|
+
/** What may follow the host: RFC 3986's unreserved and reserved characters and `%` with two hex digits. */
|
|
16
|
+
const urlRest = String.raw `(?:[A-Za-z0-9\-._~:/?#\[\]@!$&'()*+,;=]|%[0-9A-Fa-f]{2})*`;
|
|
17
|
+
/**
|
|
18
|
+
* An absolute `http` or `https` URL as `URL` writes it. The core has no `URL`
|
|
19
|
+
* class (plan 4.1), so this is a pattern, and stricter than Zod's `z.url()`:
|
|
20
|
+
* lower-case scheme and host, no user or password, no spaces or other
|
|
21
|
+
* characters `URL` would escape. Anything else, such as `mailto:` or `file:`, is refused.
|
|
22
|
+
*/
|
|
23
|
+
const URL_PATTERN = new RegExp(String.raw `^https?://${urlHost}(?::${urlPort})?(?:[/?#]${urlRest})?$`);
|
|
24
|
+
/**
|
|
25
|
+
* Builds schemas. These are Zod's own builders, limited to the ones the file
|
|
26
|
+
* format uses, so the rest of the code never imports Zod. The
|
|
27
|
+
* schemas they return have Zod's methods, such as `.min()`, `.optional()`,
|
|
28
|
+
* `.default()`, `.strict()`, `.extend()` and `.superRefine()`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const Deployment = s.object({
|
|
32
|
+
* name: s.string().min(1),
|
|
33
|
+
* host: s.enum(["local", "cloudflare"]).default("local"),
|
|
34
|
+
* }).strict();
|
|
35
|
+
* type Deployment = Infer<typeof Deployment>;
|
|
36
|
+
*/
|
|
37
|
+
export const s = {
|
|
38
|
+
/** Text. Add `.min()`, `.max()`, `.regex()`, `.email()` or `.url()`. */
|
|
39
|
+
string: z.string,
|
|
40
|
+
/** A finite number. Add `.min()`, `.max()`, `.positive()` or `.int()`. */
|
|
41
|
+
number: z.number,
|
|
42
|
+
/** `true` or `false`. */
|
|
43
|
+
boolean: z.boolean,
|
|
44
|
+
/** Only `null`. */
|
|
45
|
+
null: z.null,
|
|
46
|
+
/** Anything. In an object the key must still be there unless you add `.optional()`. */
|
|
47
|
+
unknown: z.unknown,
|
|
48
|
+
/** Exactly one value, such as `s.literal(1)` or `s.literal("text")`. */
|
|
49
|
+
literal: z.literal,
|
|
50
|
+
/** One of a fixed list of texts, such as `s.enum(["low", "medium", "high"])`. */
|
|
51
|
+
enum: z.enum,
|
|
52
|
+
/** A map with these keys. Unknown keys are dropped; add `.strict()` to refuse or `.passthrough()` to keep them. */
|
|
53
|
+
object: z.object,
|
|
54
|
+
/** A list whose items all match one schema. Add `.min()` or `.max()` for its length. */
|
|
55
|
+
array: z.array,
|
|
56
|
+
/** A list with one schema per position. */
|
|
57
|
+
tuple: z.tuple,
|
|
58
|
+
/** A map with any keys: every key matches the key schema and every value the value schema. */
|
|
59
|
+
record: z.record,
|
|
60
|
+
/** A value that matches any of the options. */
|
|
61
|
+
union: z.union,
|
|
62
|
+
/** A map whose value at one key picks one of the object schemas. */
|
|
63
|
+
discriminatedUnion: z.discriminatedUnion,
|
|
64
|
+
/** A value that matches both schemas; maps are merged. */
|
|
65
|
+
intersection: z.intersection,
|
|
66
|
+
/** A schema that refers to itself. */
|
|
67
|
+
lazy: z.lazy,
|
|
68
|
+
/** Any JSON value: null, a boolean, a finite number, text, or a list or map of JSON values. */
|
|
69
|
+
json: z.json,
|
|
70
|
+
/** An absolute `http` or `https` URL as `URL` writes it; see `URL_PATTERN`. */
|
|
71
|
+
url: () => z.string().regex(URL_PATTERN, "must be an http or https URL as URL writes it"),
|
|
72
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Issue } from "./issue.js";
|
|
2
|
+
/**
|
|
3
|
+
* How many keys and indexes deep an input may go. Workspace files are
|
|
4
|
+
* nowhere near it. Deeper input, or a value that contains itself, would
|
|
5
|
+
* otherwise overflow the call stack inside Zod.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MAX_DEPTH = 256;
|
|
8
|
+
/**
|
|
9
|
+
* Finds the first value nested deeper than `MAX_DEPTH`, without recursion,
|
|
10
|
+
* and describes it as a `too_deep` issue at its path.
|
|
11
|
+
*
|
|
12
|
+
* It walks shared sub-objects once per reference, so `core/yaml` must keep
|
|
13
|
+
* its alias limit on: YAML aliases are the only way a file can share them.
|
|
14
|
+
*/
|
|
15
|
+
export declare function findTooDeep(input: unknown): Issue | undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many keys and indexes deep an input may go. Workspace files are
|
|
3
|
+
* nowhere near it. Deeper input, or a value that contains itself, would
|
|
4
|
+
* otherwise overflow the call stack inside Zod.
|
|
5
|
+
*/
|
|
6
|
+
export const MAX_DEPTH = 256;
|
|
7
|
+
/**
|
|
8
|
+
* Finds the first value nested deeper than `MAX_DEPTH`, without recursion,
|
|
9
|
+
* and describes it as a `too_deep` issue at its path.
|
|
10
|
+
*
|
|
11
|
+
* It walks shared sub-objects once per reference, so `core/yaml` must keep
|
|
12
|
+
* its alias limit on: YAML aliases are the only way a file can share them.
|
|
13
|
+
*/
|
|
14
|
+
export function findTooDeep(input) {
|
|
15
|
+
const pending = [{ value: input, path: [] }];
|
|
16
|
+
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
|
|
17
|
+
if (next.path.length > MAX_DEPTH) {
|
|
18
|
+
return {
|
|
19
|
+
code: "too_deep",
|
|
20
|
+
path: next.path,
|
|
21
|
+
message: `Nested more than ${MAX_DEPTH} levels deep`,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
for (const [key, child] of childrenOf(next.value)) {
|
|
25
|
+
pending.push({ value: child, path: [...next.path, key] });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
function childrenOf(value) {
|
|
31
|
+
// Array.from, unlike map, also visits the holes of a sparse list.
|
|
32
|
+
if (Array.isArray(value))
|
|
33
|
+
return Array.from(value, (item, index) => [index, item]);
|
|
34
|
+
if (typeof value === "object" && value !== null)
|
|
35
|
+
return Object.entries(value);
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { s } from "./builders.js";
|
|
2
|
+
export { MAX_DEPTH } from "./depth.js";
|
|
3
|
+
export { formatPath, type Issue, type IssueCode, type Path, type PathSegment } from "./issue.js";
|
|
4
|
+
export { JSON_SCHEMA_DRAFT, type JsonSchema, type JsonValue, toJsonSchema } from "./json-schema.js";
|
|
5
|
+
export { parse } from "./parse.js";
|
|
6
|
+
export type { Infer, InferInput, Schema } from "./schema.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The public API of @halonicjs/schema-kit. Internal code imports by relative path.
|
|
2
|
+
export { s } from "./builders.js";
|
|
3
|
+
export { MAX_DEPTH } from "./depth.js";
|
|
4
|
+
export { formatPath } from "./issue.js";
|
|
5
|
+
export { JSON_SCHEMA_DRAFT, toJsonSchema } from "./json-schema.js";
|
|
6
|
+
export { parse } from "./parse.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
/** One step in the path to a value: an object key or a list index. */
|
|
3
|
+
export type PathSegment = string | number;
|
|
4
|
+
/** Where a value sits inside the parsed input, from the root down. `[]` is the root itself. */
|
|
5
|
+
export type Path = readonly PathSegment[];
|
|
6
|
+
/**
|
|
7
|
+
* What kind of problem an issue reports. All but `too_deep` are Zod's codes.
|
|
8
|
+
* The codes are stable; the messages are for people and may be reworded.
|
|
9
|
+
*/
|
|
10
|
+
export type IssueCode = "invalid_type" | "too_big" | "too_small" | "invalid_format" | "not_multiple_of" | "unrecognized_keys" | "invalid_union" | "invalid_key" | "invalid_element" | "invalid_value" | "custom" | "too_deep";
|
|
11
|
+
/** One problem found while parsing. The YAML layer turns `path` into a line and column. */
|
|
12
|
+
export interface Issue {
|
|
13
|
+
readonly code: IssueCode;
|
|
14
|
+
readonly path: Path;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
/** For `unrecognized_keys`: the keys the object doesn't allow. The path is the object's. */
|
|
17
|
+
readonly keys?: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
/** Formats a path for messages: `deployments.prod.name`, `cases[0].events[2]`. */
|
|
20
|
+
export declare function formatPath(path: Path): string;
|
|
21
|
+
/** Turns one of Zod's issues into ours. */
|
|
22
|
+
export declare function fromZodIssue(issue: z.core.$ZodIssue): Issue;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Formats a path for messages: `deployments.prod.name`, `cases[0].events[2]`. */
|
|
2
|
+
export function formatPath(path) {
|
|
3
|
+
let text = "";
|
|
4
|
+
for (const segment of path) {
|
|
5
|
+
if (typeof segment === "number")
|
|
6
|
+
text += `[${segment}]`;
|
|
7
|
+
else
|
|
8
|
+
text += text === "" ? segment : `.${segment}`;
|
|
9
|
+
}
|
|
10
|
+
return text;
|
|
11
|
+
}
|
|
12
|
+
/** Turns one of Zod's issues into ours. */
|
|
13
|
+
export function fromZodIssue(issue) {
|
|
14
|
+
const path = issue.path.map(toPathSegment);
|
|
15
|
+
if (issue.code === "unrecognized_keys") {
|
|
16
|
+
return { code: issue.code, path, message: issue.message, keys: [...issue.keys] };
|
|
17
|
+
}
|
|
18
|
+
return { code: issue.code, path, message: issue.message };
|
|
19
|
+
}
|
|
20
|
+
// Parsed files only have text keys; a symbol can only come from code.
|
|
21
|
+
function toPathSegment(segment) {
|
|
22
|
+
return typeof segment === "symbol" ? String(segment) : segment;
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Schema } from "./schema.js";
|
|
2
|
+
/** A JSON value: what a JSON Schema document is made of. */
|
|
3
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
};
|
|
6
|
+
/** A JSON Schema document. */
|
|
7
|
+
export type JsonSchema = {
|
|
8
|
+
[key: string]: JsonValue;
|
|
9
|
+
};
|
|
10
|
+
/** The JSON Schema version `toJsonSchema` writes. */
|
|
11
|
+
export declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
|
|
12
|
+
/**
|
|
13
|
+
* Describes a schema as a JSON Schema 2020-12 document, for editors, docs and
|
|
14
|
+
* other engines. It describes the **input**: a key with a default may be left
|
|
15
|
+
* out, so it isn't `required`. Refinements can't be expressed and are left
|
|
16
|
+
* out. Recursive schemas become `$defs` entries referenced with `$ref`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* toJsonSchema(s.object({ name: s.string().min(1) }).strict());
|
|
20
|
+
* // { $schema: "…/2020-12/schema", type: "object", properties: { name: { type: "string", minLength: 1 } },
|
|
21
|
+
* // required: ["name"], additionalProperties: false }
|
|
22
|
+
*/
|
|
23
|
+
export declare function toJsonSchema(schema: Schema): JsonSchema;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The JSON Schema version `toJsonSchema` writes. */
|
|
3
|
+
export const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
|
|
4
|
+
/**
|
|
5
|
+
* Describes a schema as a JSON Schema 2020-12 document, for editors, docs and
|
|
6
|
+
* other engines. It describes the **input**: a key with a default may be left
|
|
7
|
+
* out, so it isn't `required`. Refinements can't be expressed and are left
|
|
8
|
+
* out. Recursive schemas become `$defs` entries referenced with `$ref`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* toJsonSchema(s.object({ name: s.string().min(1) }).strict());
|
|
12
|
+
* // { $schema: "…/2020-12/schema", type: "object", properties: { name: { type: "string", minLength: 1 } },
|
|
13
|
+
* // required: ["name"], additionalProperties: false }
|
|
14
|
+
*/
|
|
15
|
+
export function toJsonSchema(schema) {
|
|
16
|
+
const document = z.toJSONSchema(schema, {
|
|
17
|
+
target: "draft-2020-12",
|
|
18
|
+
io: "input",
|
|
19
|
+
unrepresentable: "any",
|
|
20
|
+
});
|
|
21
|
+
return document;
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Result } from "../../std/src/index.js";
|
|
2
|
+
import { type Issue } from "./issue.js";
|
|
3
|
+
import type { Infer, Schema } from "./schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* Checks an input against a schema. Never throws for a bad input: it returns
|
|
6
|
+
* the parsed value, with defaults filled in, or every issue with its path.
|
|
7
|
+
*
|
|
8
|
+
* @param schema - the schema to check against
|
|
9
|
+
* @param input - anything, usually a parsed YAML or JSON file
|
|
10
|
+
* @returns `ok(value)`, or `err(issues)` with at least one issue
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const parsed = parse(Deployment, { name: "prod" });
|
|
14
|
+
* if (!parsed.ok) return reportAt(parsed.error[0].path);
|
|
15
|
+
* deploy(parsed.value);
|
|
16
|
+
*/
|
|
17
|
+
export declare function parse<S extends Schema>(schema: S, input: unknown): Result<Infer<S>, Issue[]>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { err, ok } from "../../std/src/index.js";
|
|
2
|
+
import { findTooDeep } from "./depth.js";
|
|
3
|
+
import { fromZodIssue } from "./issue.js";
|
|
4
|
+
/**
|
|
5
|
+
* Checks an input against a schema. Never throws for a bad input: it returns
|
|
6
|
+
* the parsed value, with defaults filled in, or every issue with its path.
|
|
7
|
+
*
|
|
8
|
+
* @param schema - the schema to check against
|
|
9
|
+
* @param input - anything, usually a parsed YAML or JSON file
|
|
10
|
+
* @returns `ok(value)`, or `err(issues)` with at least one issue
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const parsed = parse(Deployment, { name: "prod" });
|
|
14
|
+
* if (!parsed.ok) return reportAt(parsed.error[0].path);
|
|
15
|
+
* deploy(parsed.value);
|
|
16
|
+
*/
|
|
17
|
+
export function parse(schema, input) {
|
|
18
|
+
const tooDeep = findTooDeep(input);
|
|
19
|
+
if (tooDeep !== undefined)
|
|
20
|
+
return err([tooDeep]);
|
|
21
|
+
const result = schema.safeParse(input);
|
|
22
|
+
if (result.success)
|
|
23
|
+
return ok(result.data);
|
|
24
|
+
return err(result.error.issues.map(fromZodIssue));
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* A schema that checks an input and produces a value of type `Output`.
|
|
4
|
+
* `Input` is what a file may contain: keys with a default may be left out.
|
|
5
|
+
* Build one with `s`; give a recursive schema this type explicitly:
|
|
6
|
+
* `const Guard: Schema<Guard> = s.lazy(() => …)`.
|
|
7
|
+
*/
|
|
8
|
+
export type Schema<Output = unknown, Input = Output> = z.ZodType<Output, Input>;
|
|
9
|
+
/** The value a schema produces, with defaults filled in. Like `z.infer`. */
|
|
10
|
+
export type Infer<S extends Schema> = z.output<S>;
|
|
11
|
+
/** What a schema accepts: keys with a default are optional here. Like `z.input`. */
|
|
12
|
+
export type InferInput<S extends Schema> = z.input<S>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes a host name in its ASCII form: lowercase, and each label with a
|
|
3
|
+
* non-ASCII character as `xn--` plus its Punycode. A host that is already
|
|
4
|
+
* ASCII only becomes lowercase, so `Mcp.Acme.test`, `mcp.acme.test` and
|
|
5
|
+
* `MCP.ACME.TEST` are the same host.
|
|
6
|
+
*
|
|
7
|
+
* It applies Unicode NFC and lowercasing before encoding, which covers the
|
|
8
|
+
* forms a person types. It doesn't apply the full IDNA mapping table, so it
|
|
9
|
+
* never treats two different hosts as one; at worst a rare spelling of the
|
|
10
|
+
* same host gets a different ASCII form.
|
|
11
|
+
*
|
|
12
|
+
* @param host - the host name, without port or brackets
|
|
13
|
+
* @returns the host in ASCII
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* asciiHost("Bücher.example"); // "xn--bcher-kva.example"
|
|
17
|
+
*/
|
|
18
|
+
export declare function asciiHost(host: string): string;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// A host name in its ASCII form, the way the trust prompt shows and hashes it.
|
|
2
|
+
// The core has no `URL` class (plan 4.1), so the Punycode encoding of
|
|
3
|
+
// RFC 3492 is written out here.
|
|
4
|
+
const base = 36;
|
|
5
|
+
const tMin = 1;
|
|
6
|
+
const tMax = 26;
|
|
7
|
+
const skew = 38;
|
|
8
|
+
const damp = 700;
|
|
9
|
+
const initialBias = 72;
|
|
10
|
+
const initialN = 128;
|
|
11
|
+
/**
|
|
12
|
+
* Writes a host name in its ASCII form: lowercase, and each label with a
|
|
13
|
+
* non-ASCII character as `xn--` plus its Punycode. A host that is already
|
|
14
|
+
* ASCII only becomes lowercase, so `Mcp.Acme.test`, `mcp.acme.test` and
|
|
15
|
+
* `MCP.ACME.TEST` are the same host.
|
|
16
|
+
*
|
|
17
|
+
* It applies Unicode NFC and lowercasing before encoding, which covers the
|
|
18
|
+
* forms a person types. It doesn't apply the full IDNA mapping table, so it
|
|
19
|
+
* never treats two different hosts as one; at worst a rare spelling of the
|
|
20
|
+
* same host gets a different ASCII form.
|
|
21
|
+
*
|
|
22
|
+
* @param host - the host name, without port or brackets
|
|
23
|
+
* @returns the host in ASCII
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* asciiHost("Bücher.example"); // "xn--bcher-kva.example"
|
|
27
|
+
*/
|
|
28
|
+
export function asciiHost(host) {
|
|
29
|
+
return host
|
|
30
|
+
.normalize("NFC")
|
|
31
|
+
.toLowerCase()
|
|
32
|
+
.split(".")
|
|
33
|
+
.map((label) => (isAscii(label) ? label : `xn--${punycode(label)}`))
|
|
34
|
+
.join(".");
|
|
35
|
+
}
|
|
36
|
+
function isAscii(text) {
|
|
37
|
+
for (const character of text) {
|
|
38
|
+
if (codePointOf(character) >= initialN) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
function codePointOf(character) {
|
|
45
|
+
// A character from `for…of` over a string always has a code point.
|
|
46
|
+
return character.codePointAt(0) ?? 0;
|
|
47
|
+
}
|
|
48
|
+
/** RFC 3492 section 6.3: encodes one label's code points as Punycode. */
|
|
49
|
+
function punycode(label) {
|
|
50
|
+
const codePoints = Array.from(label, codePointOf);
|
|
51
|
+
let output = codePoints
|
|
52
|
+
.filter((codePoint) => codePoint < initialN)
|
|
53
|
+
.map((codePoint) => String.fromCodePoint(codePoint))
|
|
54
|
+
.join("");
|
|
55
|
+
const basicCount = output.length;
|
|
56
|
+
if (basicCount > 0) {
|
|
57
|
+
output += "-";
|
|
58
|
+
}
|
|
59
|
+
let n = initialN;
|
|
60
|
+
let delta = 0;
|
|
61
|
+
let bias = initialBias;
|
|
62
|
+
let handled = basicCount;
|
|
63
|
+
while (handled < codePoints.length) {
|
|
64
|
+
const next = Math.min(...codePoints.filter((codePoint) => codePoint >= n));
|
|
65
|
+
delta += (next - n) * (handled + 1);
|
|
66
|
+
n = next;
|
|
67
|
+
for (const codePoint of codePoints) {
|
|
68
|
+
if (codePoint < n) {
|
|
69
|
+
delta += 1;
|
|
70
|
+
}
|
|
71
|
+
if (codePoint === n) {
|
|
72
|
+
output += encodeDelta(delta, bias);
|
|
73
|
+
bias = adapt(delta, handled + 1, handled === basicCount);
|
|
74
|
+
delta = 0;
|
|
75
|
+
handled += 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
delta += 1;
|
|
79
|
+
n += 1;
|
|
80
|
+
}
|
|
81
|
+
return output;
|
|
82
|
+
}
|
|
83
|
+
/** Writes one delta as a generalized variable-length integer (RFC 3492 section 3.3). */
|
|
84
|
+
function encodeDelta(delta, bias) {
|
|
85
|
+
let output = "";
|
|
86
|
+
let rest = delta;
|
|
87
|
+
for (let k = base;; k += base) {
|
|
88
|
+
const threshold = Math.min(Math.max(k - bias, tMin), tMax);
|
|
89
|
+
if (rest < threshold) {
|
|
90
|
+
return output + digit(rest);
|
|
91
|
+
}
|
|
92
|
+
output += digit(threshold + ((rest - threshold) % (base - threshold)));
|
|
93
|
+
rest = Math.floor((rest - threshold) / (base - threshold));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** RFC 3492 section 6.1: the bias for the next delta. */
|
|
97
|
+
function adapt(delta, pointCount, first) {
|
|
98
|
+
let scaled = first ? Math.floor(delta / damp) : Math.floor(delta / 2);
|
|
99
|
+
scaled += Math.floor(scaled / pointCount);
|
|
100
|
+
let k = 0;
|
|
101
|
+
while (scaled > ((base - tMin) * tMax) >> 1) {
|
|
102
|
+
scaled = Math.floor(scaled / (base - tMin));
|
|
103
|
+
k += base;
|
|
104
|
+
}
|
|
105
|
+
return k + Math.floor(((base - tMin + 1) * scaled) / (scaled + skew));
|
|
106
|
+
}
|
|
107
|
+
/** The Punycode digit for 0–35: `a`–`z`, then `0`–`9`. */
|
|
108
|
+
function digit(value) {
|
|
109
|
+
return String.fromCharCode(value < 26 ? 97 + value : 22 + value);
|
|
110
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Thrown when an assertion fails. It always means a bug, never bad user input. */
|
|
2
|
+
export declare class AssertionError extends Error {
|
|
3
|
+
readonly name = "AssertionError";
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Throws an `AssertionError` with `message` when `condition` is false.
|
|
7
|
+
* TypeScript treats the condition as true after the call.
|
|
8
|
+
*
|
|
9
|
+
* @param condition - what must hold here
|
|
10
|
+
* @param message - says what was expected, so the failure explains itself
|
|
11
|
+
* @throws AssertionError when `condition` is false
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* assert(stepMs > 0, `stepMs must be positive, got ${stepMs}`);
|
|
15
|
+
*/
|
|
16
|
+
export declare function assert(condition: boolean, message: string): asserts condition;
|
|
17
|
+
/**
|
|
18
|
+
* Returns `value` when it is neither `undefined` nor `null`, and throws
|
|
19
|
+
* otherwise. Use it instead of the non-null `!` operator.
|
|
20
|
+
*
|
|
21
|
+
* @param value - the value that must be present
|
|
22
|
+
* @param what - names the value in the error, such as `"the run's first event"`
|
|
23
|
+
* @returns the value, with `undefined` and `null` removed from its type
|
|
24
|
+
* @throws AssertionError when the value is missing
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const first = assertDefined(events[0], "the run's first event");
|
|
28
|
+
*/
|
|
29
|
+
export declare function assertDefined<T>(value: T, what: string): NonNullable<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Marks a branch that the type system says can't be reached, such as the
|
|
32
|
+
* `default` of a `switch` over every member of a union. It fails to compile
|
|
33
|
+
* when a member is missing, and throws if the code runs anyway.
|
|
34
|
+
*
|
|
35
|
+
* @param value - the value that should have type `never` here
|
|
36
|
+
* @param what - names the value in the error, such as `"state type"`
|
|
37
|
+
* @throws AssertionError always
|
|
38
|
+
*/
|
|
39
|
+
export declare function assertNever(value: never, what: string): never;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Thrown when an assertion fails. It always means a bug, never bad user input. */
|
|
2
|
+
export class AssertionError extends Error {
|
|
3
|
+
name = "AssertionError";
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Throws an `AssertionError` with `message` when `condition` is false.
|
|
7
|
+
* TypeScript treats the condition as true after the call.
|
|
8
|
+
*
|
|
9
|
+
* @param condition - what must hold here
|
|
10
|
+
* @param message - says what was expected, so the failure explains itself
|
|
11
|
+
* @throws AssertionError when `condition` is false
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* assert(stepMs > 0, `stepMs must be positive, got ${stepMs}`);
|
|
15
|
+
*/
|
|
16
|
+
export function assert(condition, message) {
|
|
17
|
+
if (!condition) {
|
|
18
|
+
throw new AssertionError(message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns `value` when it is neither `undefined` nor `null`, and throws
|
|
23
|
+
* otherwise. Use it instead of the non-null `!` operator.
|
|
24
|
+
*
|
|
25
|
+
* @param value - the value that must be present
|
|
26
|
+
* @param what - names the value in the error, such as `"the run's first event"`
|
|
27
|
+
* @returns the value, with `undefined` and `null` removed from its type
|
|
28
|
+
* @throws AssertionError when the value is missing
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const first = assertDefined(events[0], "the run's first event");
|
|
32
|
+
*/
|
|
33
|
+
export function assertDefined(value, what) {
|
|
34
|
+
if (value === undefined || value === null) {
|
|
35
|
+
throw new AssertionError(`Expected ${what} to be defined, but it was ${String(value)}.`);
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Marks a branch that the type system says can't be reached, such as the
|
|
41
|
+
* `default` of a `switch` over every member of a union. It fails to compile
|
|
42
|
+
* when a member is missing, and throws if the code runs anyway.
|
|
43
|
+
*
|
|
44
|
+
* @param value - the value that should have type `never` here
|
|
45
|
+
* @param what - names the value in the error, such as `"state type"`
|
|
46
|
+
* @throws AssertionError always
|
|
47
|
+
*/
|
|
48
|
+
export function assertNever(value, what) {
|
|
49
|
+
throw new AssertionError(`Unexpected ${what}: ${describeValue(value)}.`);
|
|
50
|
+
}
|
|
51
|
+
/** JSON where possible, so a string shows its quotes; `String()` for what JSON can't write. */
|
|
52
|
+
function describeValue(value) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.stringify(value) ?? String(value);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return String(value);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes bytes as base64url, without padding.
|
|
3
|
+
*
|
|
4
|
+
* @param bytes - the bytes to encode
|
|
5
|
+
* @returns the text, using only `A-Z`, `a-z`, `0-9`, `-` and `_`
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* encodeBase64url(new Uint8Array([0xfb, 0xff])); // "-_8"
|
|
9
|
+
*/
|
|
10
|
+
export declare function encodeBase64url(bytes: Uint8Array): string;
|
|
11
|
+
/**
|
|
12
|
+
* Reads strict base64url text back into bytes: no padding, no other
|
|
13
|
+
* characters, and no stray bits after the last byte. So each byte string has
|
|
14
|
+
* exactly one text that reads as it.
|
|
15
|
+
*
|
|
16
|
+
* @param text - the text to decode
|
|
17
|
+
* @returns the bytes, or `undefined` when the text isn't strict base64url
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* decodeBase64url("-_8"); // Uint8Array [0xfb, 0xff]
|
|
21
|
+
* decodeBase64url("-_9"); // undefined: the last character has stray bits
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeBase64url(text: string): Uint8Array<ArrayBuffer> | undefined;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Base64url without padding (RFC 4648, section 5), as PKCE and JSON Web Tokens
|
|
2
|
+
// use it. Written out because `Buffer` doesn't exist in workerd and
|
|
3
|
+
// `Uint8Array.toBase64` and `Uint8Array.fromBase64` aren't everywhere yet.
|
|
4
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
5
|
+
/** Base64url characters only; padding is never used. */
|
|
6
|
+
const base64urlPattern = /^[A-Za-z0-9_-]*$/;
|
|
7
|
+
/**
|
|
8
|
+
* Writes bytes as base64url, without padding.
|
|
9
|
+
*
|
|
10
|
+
* @param bytes - the bytes to encode
|
|
11
|
+
* @returns the text, using only `A-Z`, `a-z`, `0-9`, `-` and `_`
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* encodeBase64url(new Uint8Array([0xfb, 0xff])); // "-_8"
|
|
15
|
+
*/
|
|
16
|
+
export function encodeBase64url(bytes) {
|
|
17
|
+
let text = "";
|
|
18
|
+
for (let start = 0; start < bytes.length; start += 3) {
|
|
19
|
+
const chunk = bytes.subarray(start, start + 3);
|
|
20
|
+
const bits = ((chunk[0] ?? 0) << 16) | ((chunk[1] ?? 0) << 8) | (chunk[2] ?? 0);
|
|
21
|
+
// Three bytes give four characters; a shorter last chunk gives one fewer per missing byte.
|
|
22
|
+
const characters = chunk.length + 1;
|
|
23
|
+
for (let index = 0; index < characters; index += 1) {
|
|
24
|
+
text += alphabet[(bits >> (18 - 6 * index)) & 63];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return text;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reads strict base64url text back into bytes: no padding, no other
|
|
31
|
+
* characters, and no stray bits after the last byte. So each byte string has
|
|
32
|
+
* exactly one text that reads as it.
|
|
33
|
+
*
|
|
34
|
+
* @param text - the text to decode
|
|
35
|
+
* @returns the bytes, or `undefined` when the text isn't strict base64url
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* decodeBase64url("-_8"); // Uint8Array [0xfb, 0xff]
|
|
39
|
+
* decodeBase64url("-_9"); // undefined: the last character has stray bits
|
|
40
|
+
*/
|
|
41
|
+
export function decodeBase64url(text) {
|
|
42
|
+
if (!base64urlPattern.test(text) || text.length % 4 === 1) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const bytes = new Uint8Array(Math.floor((text.length * 3) / 4));
|
|
46
|
+
let written = 0;
|
|
47
|
+
for (let start = 0; start < text.length; start += 4) {
|
|
48
|
+
const chunk = text.slice(start, start + 4);
|
|
49
|
+
let bits = 0;
|
|
50
|
+
for (let index = 0; index < 4; index += 1) {
|
|
51
|
+
bits = (bits << 6) | (index < chunk.length ? alphabet.indexOf(chunk.charAt(index)) : 0);
|
|
52
|
+
}
|
|
53
|
+
// Four characters give three bytes; a shorter last chunk gives one fewer per missing character.
|
|
54
|
+
const byteCount = chunk.length - 1;
|
|
55
|
+
const strayBits = bits & ((1 << (8 * (3 - byteCount))) - 1);
|
|
56
|
+
if (strayBits !== 0) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
for (let index = 0; index < byteCount; index += 1) {
|
|
60
|
+
bytes[written] = (bits >> (16 - 8 * index)) & 0xff;
|
|
61
|
+
written += 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return bytes;
|
|
65
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes plain data as JSON in one canonical form, so equal data always
|
|
3
|
+
* gives the same text and can be hashed: object keys sorted by code unit,
|
|
4
|
+
* arrays kept in order, no spaces. As with `JSON.stringify`, an object key
|
|
5
|
+
* whose value is `undefined` is left out.
|
|
6
|
+
*
|
|
7
|
+
* It throws instead of writing something lossy: a number that isn't finite,
|
|
8
|
+
* `undefined` in an array, or a value JSON can't hold, such as a `Map`, a
|
|
9
|
+
* `Date`, a function or a bigint.
|
|
10
|
+
*
|
|
11
|
+
* @param value - plain data: objects, arrays, strings, finite numbers, booleans and `null`
|
|
12
|
+
* @returns the canonical JSON text
|
|
13
|
+
* @throws when the data isn't plain JSON data, saying where
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* canonicalJson({ b: [2, 1], a: "x" }); // '{"a":"x","b":[2,1]}'
|
|
17
|
+
*/
|
|
18
|
+
export declare function canonicalJson(value: unknown): string;
|