effect 4.0.0-beta.100 → 4.0.0-beta.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +81 -5
- package/dist/Array.js.map +1 -1
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +27 -9
- package/dist/Channel.js.map +1 -1
- package/dist/Config.d.ts +1 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +6 -5
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.js +7 -7
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js +2 -1
- package/dist/Data.js.map +1 -1
- package/dist/Effect.d.ts +61 -100
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +66 -39
- package/dist/Effect.js.map +1 -1
- package/dist/FiberHandle.d.ts.map +1 -1
- package/dist/FiberHandle.js +3 -2
- package/dist/FiberHandle.js.map +1 -1
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +2 -1
- package/dist/Iterable.js.map +1 -1
- package/dist/JsonPatch.d.ts.map +1 -1
- package/dist/JsonPatch.js +4 -3
- package/dist/JsonPatch.js.map +1 -1
- package/dist/JsonSchema.d.ts.map +1 -1
- package/dist/JsonSchema.js +9 -11
- package/dist/JsonSchema.js.map +1 -1
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +3 -2
- package/dist/Logger.js.map +1 -1
- package/dist/ManagedRuntime.d.ts +9 -0
- package/dist/ManagedRuntime.d.ts.map +1 -1
- package/dist/ManagedRuntime.js +3 -0
- package/dist/ManagedRuntime.js.map +1 -1
- package/dist/Metric.d.ts.map +1 -1
- package/dist/Metric.js +4 -3
- package/dist/Metric.js.map +1 -1
- package/dist/MutableList.d.ts.map +1 -1
- package/dist/MutableList.js +4 -0
- package/dist/MutableList.js.map +1 -1
- package/dist/Optic.d.ts.map +1 -1
- package/dist/Optic.js +5 -4
- package/dist/Optic.js.map +1 -1
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +2 -1
- package/dist/Option.js.map +1 -1
- package/dist/PartitionedSemaphore.d.ts.map +1 -1
- package/dist/PartitionedSemaphore.js +1 -4
- package/dist/PartitionedSemaphore.js.map +1 -1
- package/dist/Record.d.ts +93 -1
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js +57 -19
- package/dist/Record.js.map +1 -1
- package/dist/References.d.ts +0 -45
- package/dist/References.d.ts.map +1 -1
- package/dist/References.js +0 -45
- package/dist/References.js.map +1 -1
- package/dist/Request.d.ts.map +1 -1
- package/dist/Request.js +9 -6
- package/dist/Request.js.map +1 -1
- package/dist/Result.d.ts.map +1 -1
- package/dist/Result.js +2 -1
- package/dist/Result.js.map +1 -1
- package/dist/Schema.d.ts +1269 -496
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +2308 -614
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +2 -2
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +189 -130
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaError.js +1 -1
- package/dist/SchemaError.js.map +1 -1
- package/dist/SchemaGetter.d.ts +13 -11
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +34 -24
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaIssue.js +1 -1
- package/dist/SchemaIssue.js.map +1 -1
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +1 -12
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +403 -1504
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +294 -2852
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +2 -2
- package/dist/SchemaTransformation.js +3 -3
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/Semaphore.d.ts +5 -3
- package/dist/Semaphore.d.ts.map +1 -1
- package/dist/Semaphore.js.map +1 -1
- package/dist/Stream.d.ts +15 -9
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +46 -16
- package/dist/Stream.js.map +1 -1
- package/dist/Struct.d.ts.map +1 -1
- package/dist/Struct.js +5 -4
- package/dist/Struct.js.map +1 -1
- package/dist/Types.d.ts +1 -3
- package/dist/Types.d.ts.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/core.js +3 -2
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/effect.js +119 -53
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/matcher.js +1 -1
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/record.d.ts +0 -3
- package/dist/internal/record.d.ts.map +1 -1
- package/dist/internal/record.js +10 -5
- package/dist/internal/record.js.map +1 -1
- package/dist/internal/references.js +0 -4
- package/dist/internal/references.js.map +1 -1
- package/dist/internal/schema/annotations.js +12 -0
- package/dist/internal/schema/annotations.js.map +1 -1
- package/dist/internal/schema/fromJsonSchemaDocument.d.ts +2 -0
- package/dist/internal/schema/fromJsonSchemaDocument.d.ts.map +1 -0
- package/dist/internal/schema/fromJsonSchemaDocument.js +743 -0
- package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -0
- package/dist/internal/schema/fromRepresentation.d.ts +2 -0
- package/dist/internal/schema/fromRepresentation.d.ts.map +1 -0
- package/dist/internal/schema/fromRepresentation.js +252 -0
- package/dist/internal/schema/fromRepresentation.js.map +1 -0
- package/dist/internal/schema/schema.js +28 -40
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/internal/schema/{arbitrary.d.ts → toArbitrary.d.ts} +1 -1
- package/dist/internal/schema/toArbitrary.d.ts.map +1 -0
- package/dist/internal/schema/{arbitrary.js → toArbitrary.js} +8 -9
- package/dist/internal/schema/toArbitrary.js.map +1 -0
- package/dist/internal/schema/toCodeDocument.d.ts +2 -0
- package/dist/internal/schema/toCodeDocument.d.ts.map +1 -0
- package/dist/internal/schema/toCodeDocument.js +438 -0
- package/dist/internal/schema/toCodeDocument.js.map +1 -0
- package/dist/internal/schema/toEquivalence.d.ts +2 -0
- package/dist/internal/schema/toEquivalence.d.ts.map +1 -0
- package/dist/internal/schema/{equivalence.js → toEquivalence.js} +15 -13
- package/dist/internal/schema/toEquivalence.js.map +1 -0
- package/dist/internal/schema/toJsonSchemaDocument.d.ts +2 -0
- package/dist/internal/schema/toJsonSchemaDocument.d.ts.map +1 -0
- package/dist/internal/schema/toJsonSchemaDocument.js +466 -0
- package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -0
- package/dist/internal/schema/toRepresentation.d.ts +2 -0
- package/dist/internal/schema/toRepresentation.d.ts.map +1 -0
- package/dist/internal/schema/toRepresentation.js +369 -0
- package/dist/internal/schema/toRepresentation.js.map +1 -0
- package/dist/internal/stackTraceLimit.js +3 -6
- package/dist/internal/stackTraceLimit.js.map +1 -1
- package/dist/testing/TestClock.js +4 -1
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/unstable/ai/AiError.d.ts +26 -26
- package/dist/unstable/ai/AiError.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.js +5 -4
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +21 -6
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.js +86 -316
- package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/EmbeddingModel.d.ts +1 -1
- package/dist/unstable/ai/EmbeddingModel.js +1 -1
- package/dist/unstable/ai/EmbeddingModel.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +4 -1
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +19 -17
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +197 -197
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +13 -13
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +4 -4
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +116 -49
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +32 -10
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js +193 -377
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Response.d.ts +19 -19
- package/dist/unstable/ai/Response.d.ts.map +1 -1
- package/dist/unstable/ai/Response.js +14 -14
- package/dist/unstable/ai/Response.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +4 -0
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +11 -3
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +9 -1
- package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
- package/dist/unstable/ai/Toolkit.js +14 -10
- package/dist/unstable/ai/Toolkit.js.map +1 -1
- package/dist/unstable/ai/internal/codec-transformer.js +15 -12
- package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
- package/dist/unstable/ai/internal/structured-output.d.ts +2 -0
- package/dist/unstable/ai/internal/structured-output.d.ts.map +1 -0
- package/dist/unstable/ai/internal/structured-output.js +316 -0
- package/dist/unstable/ai/internal/structured-output.js.map +1 -0
- package/dist/unstable/cli/CliError.d.ts +40 -2
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +45 -6
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.js +14 -5
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/Param.js +3 -3
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.js +1 -1
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +3 -1
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +11 -4
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cli/internal/config.d.ts +0 -48
- package/dist/unstable/cli/internal/config.d.ts.map +1 -1
- package/dist/unstable/cli/internal/config.js +8 -10
- package/dist/unstable/cli/internal/config.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/Entity.js +1 -1
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/Envelope.d.ts.map +1 -1
- package/dist/unstable/cluster/Envelope.js +2 -1
- package/dist/unstable/cluster/Envelope.js.map +1 -1
- package/dist/unstable/cluster/Reply.js +1 -1
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/cluster/Runner.d.ts +1 -1
- package/dist/unstable/cluster/Runner.js +1 -1
- package/dist/unstable/cluster/Runner.js.map +1 -1
- package/dist/unstable/cluster/RunnerAddress.d.ts +1 -1
- package/dist/unstable/cluster/RunnerAddress.js +1 -1
- package/dist/unstable/cluster/RunnerAddress.js.map +1 -1
- package/dist/unstable/cluster/ShardId.js +1 -1
- package/dist/unstable/cluster/ShardId.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +125 -24
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.d.ts +10 -2
- package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
- package/dist/unstable/cluster/SingleRunner.d.ts +4 -2
- package/dist/unstable/cluster/SingleRunner.d.ts.map +1 -1
- package/dist/unstable/cluster/SingleRunner.js +2 -1
- package/dist/unstable/cluster/SingleRunner.js.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.d.ts +7 -4
- package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.js +55 -24
- package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js +109 -62
- package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +19 -7
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/cluster/internal/shardLock.d.ts +2 -0
- package/dist/unstable/cluster/internal/shardLock.d.ts.map +1 -0
- package/dist/unstable/cluster/internal/shardLock.js +4 -0
- package/dist/unstable/cluster/internal/shardLock.js.map +1 -0
- package/dist/unstable/devtools/DevToolsSchema.d.ts +20 -20
- package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.js +8 -5
- package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
- package/dist/unstable/eventlog/EventJournal.js +1 -1
- package/dist/unstable/eventlog/EventJournal.js.map +1 -1
- package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLog.js +15 -11
- package/dist/unstable/eventlog/EventLog.js.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.d.ts +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.js +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +26 -26
- package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.js +8 -3
- package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +1 -1
- package/dist/unstable/eventlog/SqlEventJournal.js +2 -2
- package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +3 -3
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +24 -22
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/Headers.js +8 -8
- package/dist/unstable/http/Headers.js.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts +44 -0
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +14 -0
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpRouter.d.ts +2 -2
- package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
- package/dist/unstable/http/HttpRouter.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +5 -4
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/Multipart.d.ts.map +1 -1
- package/dist/unstable/http/Multipart.js +17 -15
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/http/Template.js +1 -1
- package/dist/unstable/http/Template.js.map +1 -1
- package/dist/unstable/http/UrlParams.d.ts.map +1 -1
- package/dist/unstable/http/UrlParams.js +17 -14
- package/dist/unstable/http/UrlParams.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +3 -3
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +5 -5
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +37 -24
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts +72 -1
- package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.js +69 -4
- package/dist/unstable/observability/OtlpExporter.js.map +1 -1
- package/dist/unstable/observability/OtlpLogger.d.ts +4 -3
- package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpLogger.js +2 -2
- package/dist/unstable/observability/OtlpLogger.js.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.d.ts +7 -3
- package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.js +5 -2
- package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
- package/dist/unstable/observability/OtlpTracer.d.ts +4 -3
- package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpTracer.js +2 -2
- package/dist/unstable/observability/OtlpTracer.js.map +1 -1
- package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistable.js +2 -1
- package/dist/unstable/persistence/Persistable.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.d.ts +2 -2
- package/dist/unstable/persistence/RateLimiter.js +2 -2
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/persistence/Redis.d.ts.map +1 -1
- package/dist/unstable/persistence/Redis.js +2 -2
- package/dist/unstable/persistence/Redis.js.map +1 -1
- package/dist/unstable/process/ChildProcessSpawner.js +3 -1
- package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.js +4 -3
- package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +83 -0
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +31 -0
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +2 -1
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +1 -2
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +13 -10
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts +1 -1
- package/dist/unstable/socket/Socket.js +1 -1
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/dist/unstable/sql/SqlError.d.ts +2 -2
- package/dist/unstable/sql/SqlError.js +2 -2
- package/dist/unstable/sql/SqlError.js.map +1 -1
- package/dist/unstable/sql/Statement.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.js +7 -6
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +86 -25
- package/src/Channel.ts +32 -14
- package/src/Config.ts +6 -5
- package/src/ConfigProvider.ts +7 -7
- package/src/Data.ts +3 -2
- package/src/Effect.ts +70 -116
- package/src/FiberHandle.ts +3 -2
- package/src/Iterable.ts +2 -1
- package/src/JsonPatch.ts +4 -3
- package/src/JsonSchema.ts +9 -11
- package/src/Logger.ts +3 -2
- package/src/ManagedRuntime.ts +13 -0
- package/src/Metric.ts +4 -3
- package/src/MutableList.ts +4 -0
- package/src/Optic.ts +5 -4
- package/src/Option.ts +2 -1
- package/src/PartitionedSemaphore.ts +1 -4
- package/src/Record.ts +119 -22
- package/src/References.ts +0 -46
- package/src/Request.ts +5 -7
- package/src/Result.ts +2 -1
- package/src/Schema.ts +2538 -987
- package/src/SchemaAST.ts +228 -149
- package/src/SchemaError.ts +1 -1
- package/src/SchemaGetter.ts +36 -29
- package/src/SchemaIssue.ts +1 -1
- package/src/SchemaParser.ts +1 -25
- package/src/SchemaRepresentation.ts +697 -3398
- package/src/SchemaTransformation.ts +3 -3
- package/src/Semaphore.ts +5 -3
- package/src/Stream.ts +63 -19
- package/src/Struct.ts +5 -4
- package/src/Types.ts +1 -3
- package/src/index.ts +0 -5
- package/src/internal/core.ts +4 -3
- package/src/internal/effect.ts +132 -70
- package/src/internal/matcher.ts +1 -1
- package/src/internal/record.ts +11 -7
- package/src/internal/references.ts +0 -5
- package/src/internal/schema/annotations.ts +44 -0
- package/src/internal/schema/fromJsonSchemaDocument.ts +957 -0
- package/src/internal/schema/fromRepresentation.ts +345 -0
- package/src/internal/schema/schema.ts +45 -46
- package/src/internal/schema/{arbitrary.ts → toArbitrary.ts} +8 -10
- package/src/internal/schema/toCodeDocument.ts +572 -0
- package/src/internal/schema/{equivalence.ts → toEquivalence.ts} +12 -7
- package/src/internal/schema/toJsonSchemaDocument.ts +475 -0
- package/src/internal/schema/toRepresentation.ts +401 -0
- package/src/internal/stackTraceLimit.ts +3 -7
- package/src/testing/TestClock.ts +1 -1
- package/src/unstable/ai/AiError.ts +5 -4
- package/src/unstable/ai/AnthropicStructuredOutput.ts +102 -333
- package/src/unstable/ai/EmbeddingModel.ts +1 -1
- package/src/unstable/ai/LanguageModel.ts +30 -28
- package/src/unstable/ai/McpSchema.ts +15 -15
- package/src/unstable/ai/McpServer.ts +172 -56
- package/src/unstable/ai/OpenAiStructuredOutput.ts +230 -395
- package/src/unstable/ai/Response.ts +24 -24
- package/src/unstable/ai/Tool.ts +22 -4
- package/src/unstable/ai/Toolkit.ts +19 -7
- package/src/unstable/ai/internal/codec-transformer.ts +13 -7
- package/src/unstable/ai/internal/structured-output.ts +458 -0
- package/src/unstable/cli/CliError.ts +51 -5
- package/src/unstable/cli/Command.ts +4 -4
- package/src/unstable/cli/Param.ts +3 -3
- package/src/unstable/cli/Primitive.ts +1 -1
- package/src/unstable/cli/internal/command.ts +13 -5
- package/src/unstable/cli/internal/config.ts +8 -10
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +3 -3
- package/src/unstable/cluster/Entity.ts +1 -1
- package/src/unstable/cluster/Envelope.ts +2 -1
- package/src/unstable/cluster/Reply.ts +1 -1
- package/src/unstable/cluster/Runner.ts +1 -1
- package/src/unstable/cluster/RunnerAddress.ts +1 -1
- package/src/unstable/cluster/ShardId.ts +1 -1
- package/src/unstable/cluster/Sharding.ts +161 -34
- package/src/unstable/cluster/ShardingConfig.ts +5 -1
- package/src/unstable/cluster/SingleRunner.ts +4 -2
- package/src/unstable/cluster/SqlMessageStorage.ts +83 -35
- package/src/unstable/cluster/SqlRunnerStorage.ts +186 -116
- package/src/unstable/cluster/internal/entityManager.ts +31 -10
- package/src/unstable/cluster/internal/shardLock.ts +9 -0
- package/src/unstable/devtools/DevToolsSchema.ts +10 -5
- package/src/unstable/eventlog/EventJournal.ts +1 -1
- package/src/unstable/eventlog/EventLog.ts +21 -11
- package/src/unstable/eventlog/EventLogEncryption.ts +1 -1
- package/src/unstable/eventlog/EventLogMessage.ts +10 -3
- package/src/unstable/eventlog/SqlEventJournal.ts +2 -2
- package/src/unstable/eventlog/SqlEventLogServerEncrypted.ts +1 -1
- package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +6 -3
- package/src/unstable/http/Cookies.ts +29 -24
- package/src/unstable/http/Headers.ts +8 -8
- package/src/unstable/http/HttpClientRequest.ts +57 -0
- package/src/unstable/http/HttpRouter.ts +6 -3
- package/src/unstable/http/HttpServerRequest.ts +5 -4
- package/src/unstable/http/Multipart.ts +16 -13
- package/src/unstable/http/Template.ts +1 -1
- package/src/unstable/http/UrlParams.ts +17 -14
- package/src/unstable/httpapi/HttpApi.ts +3 -3
- package/src/unstable/httpapi/HttpApiClient.ts +5 -5
- package/src/unstable/httpapi/HttpApiGroup.ts +1 -1
- package/src/unstable/httpapi/OpenApi.ts +52 -28
- package/src/unstable/observability/OtlpExporter.ts +109 -5
- package/src/unstable/observability/OtlpLogger.ts +5 -5
- package/src/unstable/observability/OtlpMetrics.ts +8 -4
- package/src/unstable/observability/OtlpTracer.ts +8 -4
- package/src/unstable/persistence/Persistable.ts +3 -2
- package/src/unstable/persistence/RateLimiter.ts +2 -2
- package/src/unstable/persistence/Redis.ts +2 -2
- package/src/unstable/process/ChildProcessSpawner.ts +1 -1
- package/src/unstable/reactivity/AsyncResult.ts +4 -3
- package/src/unstable/reactivity/Atom.ts +92 -0
- package/src/unstable/reactivity/AtomRegistry.ts +1 -1
- package/src/unstable/rpc/RpcClient.ts +2 -1
- package/src/unstable/schema/VariantSchema.ts +14 -24
- package/src/unstable/socket/Socket.ts +1 -1
- package/src/unstable/sql/SqlError.ts +2 -2
- package/src/unstable/sql/Statement.ts +7 -6
- package/dist/SchemaUtils.d.ts +0 -28
- package/dist/SchemaUtils.d.ts.map +0 -1
- package/dist/SchemaUtils.js +0 -45
- package/dist/SchemaUtils.js.map +0 -1
- package/dist/internal/schema/arbitrary.d.ts.map +0 -1
- package/dist/internal/schema/arbitrary.js.map +0 -1
- package/dist/internal/schema/equivalence.d.ts +0 -2
- package/dist/internal/schema/equivalence.d.ts.map +0 -1
- package/dist/internal/schema/equivalence.js.map +0 -1
- package/dist/internal/schema/representation.d.ts +0 -2
- package/dist/internal/schema/representation.d.ts.map +0 -1
- package/dist/internal/schema/representation.js +0 -865
- package/dist/internal/schema/representation.js.map +0 -1
- package/src/SchemaUtils.ts +0 -51
- package/src/internal/schema/representation.ts +0 -795
|
@@ -1,795 +0,0 @@
|
|
|
1
|
-
import * as Arr from "../../Array.ts"
|
|
2
|
-
import * as Equal from "../../Equal.ts"
|
|
3
|
-
import { format } from "../../Formatter.ts"
|
|
4
|
-
import { escapeToken } from "../../JsonPointer.ts"
|
|
5
|
-
import type * as JsonSchema from "../../JsonSchema.ts"
|
|
6
|
-
import * as Predicate from "../../Predicate.ts"
|
|
7
|
-
import * as Rec from "../../Record.ts"
|
|
8
|
-
import * as RegEx from "../../RegExp.ts"
|
|
9
|
-
import type * as Schema from "../../Schema.ts"
|
|
10
|
-
import * as SchemaAST from "../../SchemaAST.ts"
|
|
11
|
-
import type * as SchemaRepresentation from "../../SchemaRepresentation.ts"
|
|
12
|
-
import * as InternalAnnotations from "./annotations.ts"
|
|
13
|
-
import * as InternalSchema from "./schema.ts"
|
|
14
|
-
|
|
15
|
-
/** @internal */
|
|
16
|
-
export function fromAST(ast: SchemaAST.AST): SchemaRepresentation.Document {
|
|
17
|
-
const { references, representations: schemas } = fromASTs([ast])
|
|
18
|
-
return { representation: schemas[0], references }
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** @internal */
|
|
22
|
-
export function fromASTs(asts: readonly [SchemaAST.AST, ...Array<SchemaAST.AST>]): SchemaRepresentation.MultiDocument {
|
|
23
|
-
const references: Record<string, SchemaRepresentation.Representation> = {}
|
|
24
|
-
|
|
25
|
-
const referenceMap = new Map<SchemaAST.AST, string>()
|
|
26
|
-
const uniqueReferences = new Set<string>()
|
|
27
|
-
const visiting = new Set<SchemaAST.AST>()
|
|
28
|
-
|
|
29
|
-
const schemas = Arr.map(asts, (ast) => recur(ast))
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
representations: schemas,
|
|
33
|
-
references
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function gen(prefix: string): string {
|
|
37
|
-
let candidate = prefix
|
|
38
|
-
let suffix = 0
|
|
39
|
-
|
|
40
|
-
while (uniqueReferences.has(candidate)) {
|
|
41
|
-
candidate = `${prefix}${++suffix}`
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
uniqueReferences.add(candidate)
|
|
45
|
-
return candidate
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function recur(ast: SchemaAST.AST, prefix?: string): SchemaRepresentation.Representation {
|
|
49
|
-
const found = referenceMap.get(ast)
|
|
50
|
-
if (found !== undefined) {
|
|
51
|
-
return { _tag: "Reference", $ref: found }
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const last = SchemaAST.getLastEncoding(ast)
|
|
55
|
-
const identifier = InternalAnnotations.resolveIdentifier(ast) ?? prefix
|
|
56
|
-
|
|
57
|
-
if (ast !== last) {
|
|
58
|
-
return recur(last, identifier)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Has identifier → always create reference
|
|
62
|
-
if (identifier !== undefined) {
|
|
63
|
-
const reference = gen(identifier)
|
|
64
|
-
referenceMap.set(ast, reference)
|
|
65
|
-
const out = on(ast)
|
|
66
|
-
const found = references[identifier]
|
|
67
|
-
// Reuse existing references when duplicate identifiers have the same representation
|
|
68
|
-
if (found !== undefined && Equal.equals(out, found)) {
|
|
69
|
-
referenceMap.set(ast, identifier)
|
|
70
|
-
return { _tag: "Reference", $ref: identifier }
|
|
71
|
-
}
|
|
72
|
-
references[reference] = out
|
|
73
|
-
return { _tag: "Reference", $ref: reference }
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Recursion detected → create reference
|
|
77
|
-
if (visiting.has(ast)) {
|
|
78
|
-
const reference = gen(`${ast._tag}_`)
|
|
79
|
-
referenceMap.set(ast, reference)
|
|
80
|
-
return { _tag: "Reference", $ref: reference }
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Normal case → inline
|
|
84
|
-
visiting.add(ast)
|
|
85
|
-
const out = on(ast)
|
|
86
|
-
visiting.delete(ast)
|
|
87
|
-
|
|
88
|
-
// A descendant triggered reference creation (recursion)
|
|
89
|
-
const ref = referenceMap.get(ast)
|
|
90
|
-
if (ref !== undefined) {
|
|
91
|
-
references[ref] = out
|
|
92
|
-
return { _tag: "Reference", $ref: ref }
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return out
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function getEncodedSchema(last: SchemaAST.Declaration): SchemaAST.Declaration | SchemaAST.Null {
|
|
99
|
-
const getLink = last.annotations?.toCodecJson ?? last.annotations?.toCodec
|
|
100
|
-
if (Predicate.isFunction(getLink)) {
|
|
101
|
-
return SchemaAST.replaceEncoding(last, [
|
|
102
|
-
getLink(last.typeParameters.map((tp) => InternalSchema.make(SchemaAST.toEncoded(tp))))
|
|
103
|
-
])
|
|
104
|
-
}
|
|
105
|
-
return SchemaAST.null
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function on(last: SchemaAST.AST): SchemaRepresentation.Representation {
|
|
109
|
-
const annotations = fromASTAnnotations(last.annotations)
|
|
110
|
-
switch (last._tag) {
|
|
111
|
-
case "Declaration": {
|
|
112
|
-
// this must be executed before transforming the type parameters
|
|
113
|
-
const encodedSchema = recur(getEncodedSchema(last))
|
|
114
|
-
return {
|
|
115
|
-
_tag: "Declaration",
|
|
116
|
-
typeParameters: last.typeParameters.map((ast) => recur(ast)),
|
|
117
|
-
encodedSchema,
|
|
118
|
-
checks: fromASTChecks(last.checks),
|
|
119
|
-
...annotations
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
case "Null":
|
|
123
|
-
case "Undefined":
|
|
124
|
-
case "Void":
|
|
125
|
-
case "Never":
|
|
126
|
-
case "Unknown":
|
|
127
|
-
case "Any":
|
|
128
|
-
case "Boolean":
|
|
129
|
-
case "Symbol":
|
|
130
|
-
case "ObjectKeyword":
|
|
131
|
-
return { _tag: last._tag, ...annotations }
|
|
132
|
-
case "String": {
|
|
133
|
-
const contentMediaType = last.annotations?.contentMediaType
|
|
134
|
-
const contentSchema = last.annotations?.contentSchema
|
|
135
|
-
return {
|
|
136
|
-
_tag: last._tag,
|
|
137
|
-
checks: fromASTChecks(last.checks),
|
|
138
|
-
...annotations,
|
|
139
|
-
...(typeof contentMediaType === "string" && SchemaAST.isAST(contentSchema)
|
|
140
|
-
? { contentSchema: recur(contentSchema) }
|
|
141
|
-
: undefined)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
case "Number":
|
|
145
|
-
case "BigInt":
|
|
146
|
-
return {
|
|
147
|
-
_tag: last._tag,
|
|
148
|
-
checks: fromASTChecks(last.checks),
|
|
149
|
-
...annotations
|
|
150
|
-
}
|
|
151
|
-
case "Literal":
|
|
152
|
-
return {
|
|
153
|
-
_tag: last._tag,
|
|
154
|
-
literal: last.literal,
|
|
155
|
-
...annotations
|
|
156
|
-
}
|
|
157
|
-
case "UniqueSymbol":
|
|
158
|
-
return {
|
|
159
|
-
_tag: last._tag,
|
|
160
|
-
symbol: last.symbol,
|
|
161
|
-
...annotations
|
|
162
|
-
}
|
|
163
|
-
case "Enum":
|
|
164
|
-
return {
|
|
165
|
-
_tag: last._tag,
|
|
166
|
-
enums: last.enums,
|
|
167
|
-
...annotations
|
|
168
|
-
}
|
|
169
|
-
case "TemplateLiteral":
|
|
170
|
-
return {
|
|
171
|
-
_tag: last._tag,
|
|
172
|
-
parts: last.parts.map((ast) => recur(ast)),
|
|
173
|
-
...annotations
|
|
174
|
-
}
|
|
175
|
-
case "Arrays":
|
|
176
|
-
return {
|
|
177
|
-
_tag: last._tag,
|
|
178
|
-
elements: last.elements.map((e) => {
|
|
179
|
-
const last = SchemaAST.getLastEncoding(e)
|
|
180
|
-
return {
|
|
181
|
-
isOptional: SchemaAST.isOptional(last),
|
|
182
|
-
type: recur(e),
|
|
183
|
-
...fromASTAnnotations(last.context?.annotations)
|
|
184
|
-
}
|
|
185
|
-
}),
|
|
186
|
-
rest: last.rest.map((ast) => recur(ast)),
|
|
187
|
-
checks: fromASTChecks(last.checks),
|
|
188
|
-
...annotations
|
|
189
|
-
}
|
|
190
|
-
case "Objects":
|
|
191
|
-
return {
|
|
192
|
-
_tag: last._tag,
|
|
193
|
-
propertySignatures: last.propertySignatures.map((ps) => {
|
|
194
|
-
const last = SchemaAST.getLastEncoding(ps.type)
|
|
195
|
-
return {
|
|
196
|
-
name: ps.name,
|
|
197
|
-
type: recur(ps.type),
|
|
198
|
-
isOptional: SchemaAST.isOptional(last),
|
|
199
|
-
isMutable: SchemaAST.isMutable(last),
|
|
200
|
-
...fromASTAnnotations(last.context?.annotations)
|
|
201
|
-
}
|
|
202
|
-
}),
|
|
203
|
-
indexSignatures: last.indexSignatures.map((is) => ({
|
|
204
|
-
parameter: recur(is.parameter),
|
|
205
|
-
type: recur(is.type)
|
|
206
|
-
})),
|
|
207
|
-
checks: fromASTChecks(last.checks),
|
|
208
|
-
...annotations
|
|
209
|
-
}
|
|
210
|
-
case "Union": {
|
|
211
|
-
const types = InternalSchema.jsonReorder(last.types)
|
|
212
|
-
return {
|
|
213
|
-
_tag: last._tag,
|
|
214
|
-
types: types.map((ast) => recur(ast)),
|
|
215
|
-
mode: last.mode,
|
|
216
|
-
...annotations
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
case "Suspend": {
|
|
220
|
-
return {
|
|
221
|
-
_tag: "Suspend",
|
|
222
|
-
checks: [],
|
|
223
|
-
thunk: recur(last.thunk()),
|
|
224
|
-
...annotations
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function fromASTChecks(
|
|
231
|
-
checks: readonly [SchemaAST.Check<any>, ...Array<SchemaAST.Check<any>>] | undefined
|
|
232
|
-
): Array<SchemaRepresentation.Check<any>> {
|
|
233
|
-
if (!checks) return []
|
|
234
|
-
return checks.map(getCheck).filter((c) => c !== undefined)
|
|
235
|
-
|
|
236
|
-
function getCheck(c: SchemaAST.Check<any>): SchemaRepresentation.Check<any> | undefined {
|
|
237
|
-
switch (c._tag) {
|
|
238
|
-
case "Filter": {
|
|
239
|
-
const meta = c.annotations?.meta
|
|
240
|
-
if (meta) {
|
|
241
|
-
return {
|
|
242
|
-
_tag: "Filter",
|
|
243
|
-
meta: meta._tag === "isPropertyNames"
|
|
244
|
-
? {
|
|
245
|
-
_tag: "isPropertyNames",
|
|
246
|
-
propertyNames: recur(meta.propertyNames)
|
|
247
|
-
}
|
|
248
|
-
: meta,
|
|
249
|
-
...fromASTAnnotations(c.annotations)
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return undefined
|
|
253
|
-
}
|
|
254
|
-
case "FilterGroup": {
|
|
255
|
-
const checks = fromASTChecks(c.checks)
|
|
256
|
-
if (Arr.isArrayNonEmpty(checks)) {
|
|
257
|
-
return {
|
|
258
|
-
_tag: "FilterGroup",
|
|
259
|
-
checks,
|
|
260
|
-
...fromASTAnnotations(c.annotations)
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/** @internal */
|
|
270
|
-
export const fromASTBlacklist: Set<string> = new Set([
|
|
271
|
-
// `expected` is preserved because is useful to generate descriptions in JSON Schemas
|
|
272
|
-
"~structural",
|
|
273
|
-
"~sentinels",
|
|
274
|
-
"meta",
|
|
275
|
-
"arbitrary",
|
|
276
|
-
"toArbitrary",
|
|
277
|
-
"toEquivalence",
|
|
278
|
-
"toFormatter",
|
|
279
|
-
"toCodec",
|
|
280
|
-
"toCodecJson",
|
|
281
|
-
"toCodecIso",
|
|
282
|
-
SchemaAST.ClassTypeId
|
|
283
|
-
])
|
|
284
|
-
|
|
285
|
-
const standardJsonSchemaAnnotationKeys: ReadonlySet<string> = new Set([
|
|
286
|
-
"title",
|
|
287
|
-
"description",
|
|
288
|
-
"default",
|
|
289
|
-
"examples",
|
|
290
|
-
"readOnly",
|
|
291
|
-
"writeOnly",
|
|
292
|
-
"format",
|
|
293
|
-
"contentEncoding",
|
|
294
|
-
"contentMediaType",
|
|
295
|
-
"contentSchema"
|
|
296
|
-
])
|
|
297
|
-
|
|
298
|
-
function fromASTAnnotations(
|
|
299
|
-
annotations: Schema.Annotations.Annotations | undefined
|
|
300
|
-
): { annotations: Schema.Annotations.Annotations } | undefined {
|
|
301
|
-
if (annotations !== undefined) {
|
|
302
|
-
const filtered = Rec.filter(annotations, (_, k) => !fromASTBlacklist.has(k))
|
|
303
|
-
if (!Rec.isEmptyRecord(filtered)) {
|
|
304
|
-
return { annotations: filtered }
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return undefined
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/** @internal */
|
|
311
|
-
export function toJsonSchemaDocument(
|
|
312
|
-
document: SchemaRepresentation.Document,
|
|
313
|
-
options?: Schema.ToJsonSchemaOptions
|
|
314
|
-
): JsonSchema.Document<"draft-2020-12"> {
|
|
315
|
-
const { definitions, dialect: source, schemas } = toJsonSchemaMultiDocument({
|
|
316
|
-
representations: [document.representation],
|
|
317
|
-
references: document.references
|
|
318
|
-
}, options)
|
|
319
|
-
const schema = schemas[0]
|
|
320
|
-
return { dialect: source, schema, definitions }
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/** @internal */
|
|
324
|
-
export function toJsonSchemaMultiDocument(
|
|
325
|
-
multiDocument: SchemaRepresentation.MultiDocument,
|
|
326
|
-
options?: Schema.ToJsonSchemaOptions
|
|
327
|
-
): JsonSchema.MultiDocument<"draft-2020-12"> {
|
|
328
|
-
const generateDescriptions = options?.generateDescriptions ?? false
|
|
329
|
-
const additionalProperties = options?.additionalProperties ?? false
|
|
330
|
-
const includeAnnotationKey = options?.includeAnnotationKey
|
|
331
|
-
|
|
332
|
-
const definitions = Rec.map(multiDocument.references, (d) => recur(d))
|
|
333
|
-
|
|
334
|
-
return {
|
|
335
|
-
dialect: "draft-2020-12",
|
|
336
|
-
schemas: Arr.map(multiDocument.representations, (s) => recur(s)),
|
|
337
|
-
definitions
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function recur(s: SchemaRepresentation.Representation): JsonSchema.JsonSchema {
|
|
341
|
-
let js: JsonSchema.JsonSchema = on(s)
|
|
342
|
-
if ("annotations" in s) {
|
|
343
|
-
const a = collectJsonSchemaAnnotations(s.annotations)
|
|
344
|
-
if (a) {
|
|
345
|
-
js = { ...js, ...a }
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
if ("checks" in s) {
|
|
349
|
-
const checks = collectJsonSchemaChecks<SchemaRepresentation.Meta>(s.checks, js.type)
|
|
350
|
-
for (const check of checks) {
|
|
351
|
-
js = appendJsonSchema(js, check)
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return js
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
function on(schema: SchemaRepresentation.Representation): JsonSchema.JsonSchema {
|
|
358
|
-
switch (schema._tag) {
|
|
359
|
-
case "Any":
|
|
360
|
-
case "Unknown":
|
|
361
|
-
return {}
|
|
362
|
-
case "ObjectKeyword":
|
|
363
|
-
return { anyOf: [{ type: "object" }, { type: "array" }] }
|
|
364
|
-
case "Void":
|
|
365
|
-
case "Undefined":
|
|
366
|
-
return { type: "null" }
|
|
367
|
-
case "BigInt":
|
|
368
|
-
return {
|
|
369
|
-
"type": "string",
|
|
370
|
-
"allOf": [
|
|
371
|
-
{ "pattern": "^-?\\d+$" }
|
|
372
|
-
]
|
|
373
|
-
}
|
|
374
|
-
case "Symbol":
|
|
375
|
-
case "UniqueSymbol":
|
|
376
|
-
return {
|
|
377
|
-
"type": "string",
|
|
378
|
-
"allOf": [
|
|
379
|
-
{ "pattern": "^Symbol\\((.*)\\)$" }
|
|
380
|
-
]
|
|
381
|
-
}
|
|
382
|
-
case "Declaration":
|
|
383
|
-
return recur(schema.encodedSchema)
|
|
384
|
-
case "Suspend":
|
|
385
|
-
return recur(schema.thunk)
|
|
386
|
-
case "Reference":
|
|
387
|
-
return { $ref: `#/$defs/${escapeToken(schema.$ref)}` }
|
|
388
|
-
case "Null":
|
|
389
|
-
return { type: "null" }
|
|
390
|
-
case "Never":
|
|
391
|
-
return { not: {} }
|
|
392
|
-
case "String": {
|
|
393
|
-
const out: JsonSchema.JsonSchema = { type: "string" }
|
|
394
|
-
if (schema.contentMediaType !== undefined) {
|
|
395
|
-
out.contentMediaType = schema.contentMediaType
|
|
396
|
-
}
|
|
397
|
-
if (schema.contentSchema !== undefined) {
|
|
398
|
-
out.contentSchema = recur(schema.contentSchema)
|
|
399
|
-
}
|
|
400
|
-
return out
|
|
401
|
-
}
|
|
402
|
-
case "Number":
|
|
403
|
-
return hasCheck(schema.checks, "isInt") ?
|
|
404
|
-
{ type: "integer" } :
|
|
405
|
-
hasCheck(schema.checks, "isFinite") ?
|
|
406
|
-
{ type: "number" } :
|
|
407
|
-
{
|
|
408
|
-
"anyOf": [
|
|
409
|
-
{ type: "number" },
|
|
410
|
-
{ type: "string", enum: ["NaN"] },
|
|
411
|
-
{ type: "string", enum: ["Infinity"] },
|
|
412
|
-
{ type: "string", enum: ["-Infinity"] }
|
|
413
|
-
]
|
|
414
|
-
}
|
|
415
|
-
case "Boolean":
|
|
416
|
-
return { type: "boolean" }
|
|
417
|
-
case "Literal": {
|
|
418
|
-
const literal = schema.literal
|
|
419
|
-
if (typeof literal === "string") {
|
|
420
|
-
return { type: "string", enum: [literal] }
|
|
421
|
-
}
|
|
422
|
-
if (typeof literal === "number") {
|
|
423
|
-
return { type: "number", enum: [literal] }
|
|
424
|
-
}
|
|
425
|
-
if (typeof literal === "boolean") {
|
|
426
|
-
return { type: "boolean", enum: [literal] }
|
|
427
|
-
}
|
|
428
|
-
// bigint literals are not supported
|
|
429
|
-
return { type: "string", enum: [String(literal)] }
|
|
430
|
-
}
|
|
431
|
-
case "Enum": {
|
|
432
|
-
return recur({
|
|
433
|
-
_tag: "Union",
|
|
434
|
-
types: schema.enums.map(([title, value]) => ({
|
|
435
|
-
_tag: "Literal",
|
|
436
|
-
literal: value,
|
|
437
|
-
annotations: { title }
|
|
438
|
-
})),
|
|
439
|
-
mode: "anyOf",
|
|
440
|
-
annotations: schema.annotations
|
|
441
|
-
})
|
|
442
|
-
}
|
|
443
|
-
case "TemplateLiteral": {
|
|
444
|
-
const pattern = schema.parts.map(getPartPattern).join("")
|
|
445
|
-
return { type: "string", pattern: `^${pattern}$` }
|
|
446
|
-
}
|
|
447
|
-
case "Arrays": {
|
|
448
|
-
// ---------------------------------------------
|
|
449
|
-
// handle post rest elements
|
|
450
|
-
// ---------------------------------------------
|
|
451
|
-
if (schema.rest.length > 1) {
|
|
452
|
-
throw new globalThis.Error("Generating a JSON Schema for post-rest elements is not supported")
|
|
453
|
-
}
|
|
454
|
-
const out: JsonSchema.JsonSchema = { type: "array" }
|
|
455
|
-
let minItems = schema.elements.length
|
|
456
|
-
const prefixItems: Array<JsonSchema.JsonSchema> = schema.elements.map((e) => {
|
|
457
|
-
if (e.isOptional) {
|
|
458
|
-
minItems--
|
|
459
|
-
}
|
|
460
|
-
const v = recur(e.type)
|
|
461
|
-
const a = collectJsonSchemaAnnotations(e.annotations)
|
|
462
|
-
return a ? appendJsonSchema(v, a) : v
|
|
463
|
-
})
|
|
464
|
-
if (prefixItems.length > 0) {
|
|
465
|
-
out.prefixItems = prefixItems
|
|
466
|
-
out.maxItems = schema.elements.length
|
|
467
|
-
if (minItems > 0) {
|
|
468
|
-
out.minItems = minItems
|
|
469
|
-
}
|
|
470
|
-
} else {
|
|
471
|
-
out.items = false
|
|
472
|
-
}
|
|
473
|
-
if (schema.rest.length > 0) {
|
|
474
|
-
delete out.maxItems
|
|
475
|
-
const rest = recur(schema.rest[0])
|
|
476
|
-
if (Object.keys(rest).length > 0) {
|
|
477
|
-
out.items = rest
|
|
478
|
-
} else {
|
|
479
|
-
delete out.items
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return out
|
|
483
|
-
}
|
|
484
|
-
case "Objects": {
|
|
485
|
-
if (schema.propertySignatures.length === 0 && schema.indexSignatures.length === 0) {
|
|
486
|
-
return { anyOf: [{ type: "object" }, { type: "array" }] }
|
|
487
|
-
}
|
|
488
|
-
const out: JsonSchema.JsonSchema = { type: "object" }
|
|
489
|
-
const properties: Record<string, JsonSchema.JsonSchema> = {}
|
|
490
|
-
const required: Array<string> = []
|
|
491
|
-
|
|
492
|
-
for (const ps of schema.propertySignatures) {
|
|
493
|
-
const name = ps.name
|
|
494
|
-
if (typeof name !== "string") {
|
|
495
|
-
throw new globalThis.Error(`Unsupported property signature name: ${format(name)}`)
|
|
496
|
-
}
|
|
497
|
-
const v = recur(ps.type)
|
|
498
|
-
const a = collectJsonSchemaAnnotations(ps.annotations)
|
|
499
|
-
properties[name] = a ? appendJsonSchema(v, a) : v
|
|
500
|
-
// Property is required only if it's not explicitly optional AND doesn't contain Undefined
|
|
501
|
-
if (!ps.isOptional) {
|
|
502
|
-
required.push(name)
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
if (Object.keys(properties).length > 0) {
|
|
507
|
-
out.properties = properties
|
|
508
|
-
}
|
|
509
|
-
if (required.length > 0) {
|
|
510
|
-
out.required = required
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
out.additionalProperties = additionalProperties
|
|
514
|
-
const patternProperties: Record<string, JsonSchema.JsonSchema | false> = {}
|
|
515
|
-
// Handle index signatures
|
|
516
|
-
for (const is of schema.indexSignatures) {
|
|
517
|
-
let type: JsonSchema.JsonSchema | false = recur(is.type)
|
|
518
|
-
// Collapse unannotated Never ({ not: {} }) to false, but keep annotated schemas as objects.
|
|
519
|
-
if (Object.keys(type).length === 1 && "not" in type) {
|
|
520
|
-
type = false
|
|
521
|
-
}
|
|
522
|
-
const patterns = getParameterPatterns(is.parameter)
|
|
523
|
-
if (patterns.length > 0) {
|
|
524
|
-
for (const pattern of patterns) {
|
|
525
|
-
patternProperties[pattern] = type
|
|
526
|
-
}
|
|
527
|
-
} else {
|
|
528
|
-
out.additionalProperties = type
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
if (Object.keys(patternProperties).length > 0) {
|
|
532
|
-
out.patternProperties = patternProperties
|
|
533
|
-
delete out.additionalProperties
|
|
534
|
-
}
|
|
535
|
-
if (Predicate.isObject(out.additionalProperties) && Rec.isEmptyRecord(out.additionalProperties)) {
|
|
536
|
-
delete out.additionalProperties
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
return out
|
|
540
|
-
}
|
|
541
|
-
case "Union": {
|
|
542
|
-
const types = schema.types.map(recur)
|
|
543
|
-
if (types.length === 0) {
|
|
544
|
-
// anyOf MUST be a non-empty array
|
|
545
|
-
return { not: {} }
|
|
546
|
-
}
|
|
547
|
-
if (types.length > 1) {
|
|
548
|
-
const compacted = compactEnums(types)
|
|
549
|
-
if (compacted) return compacted
|
|
550
|
-
}
|
|
551
|
-
return schema.mode === "anyOf" ? { anyOf: types } : { oneOf: types }
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
// Collapses [{type:"string",enum:["a"]},{type:"string",enum:["b"]}] into {type:"string",enum:["a","b"]}.
|
|
557
|
-
// Returns undefined if members have different types, extra keys (e.g. title), or empty enums.
|
|
558
|
-
function compactEnums(
|
|
559
|
-
types: ReadonlyArray<JsonSchema.JsonSchema>
|
|
560
|
-
): JsonSchema.JsonSchema | undefined {
|
|
561
|
-
let sharedType: string | undefined
|
|
562
|
-
const values: Array<unknown> = []
|
|
563
|
-
for (const t of types) {
|
|
564
|
-
const keys = Object.keys(t)
|
|
565
|
-
if (keys.length !== 2 || t.type === undefined || !Array.isArray(t.enum) || t.enum.length === 0) {
|
|
566
|
-
return undefined
|
|
567
|
-
}
|
|
568
|
-
if (sharedType === undefined) {
|
|
569
|
-
sharedType = t.type as string
|
|
570
|
-
} else if (t.type !== sharedType) {
|
|
571
|
-
return undefined
|
|
572
|
-
}
|
|
573
|
-
for (const v of t.enum) {
|
|
574
|
-
values.push(v)
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
return { type: sharedType, enum: values }
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
function collectJsonSchemaAnnotations(
|
|
581
|
-
annotations: Schema.Annotations.Annotations | undefined
|
|
582
|
-
): JsonSchema.JsonSchema | undefined {
|
|
583
|
-
if (annotations === undefined) return undefined
|
|
584
|
-
|
|
585
|
-
const out: JsonSchema.JsonSchema = {}
|
|
586
|
-
if (typeof annotations.title === "string") out.title = annotations.title
|
|
587
|
-
if (typeof annotations.description === "string") out.description = annotations.description
|
|
588
|
-
else if (generateDescriptions && typeof annotations.expected === "string") out.description = annotations.expected
|
|
589
|
-
if (annotations.default !== undefined) out.default = annotations.default
|
|
590
|
-
if (Array.isArray(annotations.examples)) out.examples = annotations.examples
|
|
591
|
-
if (typeof annotations.readOnly === "boolean") out.readOnly = annotations.readOnly
|
|
592
|
-
if (typeof annotations.writeOnly === "boolean") out.writeOnly = annotations.writeOnly
|
|
593
|
-
if (typeof annotations.format === "string") out.format = annotations.format
|
|
594
|
-
if (typeof annotations.contentEncoding === "string") out.contentEncoding = annotations.contentEncoding
|
|
595
|
-
if (typeof annotations.contentMediaType === "string") out.contentMediaType = annotations.contentMediaType
|
|
596
|
-
|
|
597
|
-
if (includeAnnotationKey) {
|
|
598
|
-
for (const [key, value] of Object.entries(annotations)) {
|
|
599
|
-
if (value === undefined) continue
|
|
600
|
-
if (standardJsonSchemaAnnotationKeys.has(key)) continue
|
|
601
|
-
if (!includeAnnotationKey(key)) continue
|
|
602
|
-
out[key] = value
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
if (Object.keys(out).length > 0) return out
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
function collectJsonSchemaChecks<M>(
|
|
610
|
-
checks: ReadonlyArray<SchemaRepresentation.Check<M>>,
|
|
611
|
-
type: unknown
|
|
612
|
-
): Array<JsonSchema.JsonSchema> {
|
|
613
|
-
return checks.map(collectJsonSchemaCheck).filter((c) => c !== undefined)
|
|
614
|
-
|
|
615
|
-
function collectJsonSchemaCheck<M>(check: SchemaRepresentation.Check<M>): JsonSchema.JsonSchema | undefined {
|
|
616
|
-
switch (check._tag) {
|
|
617
|
-
case "Filter":
|
|
618
|
-
return filterToJsonSchema(check, type)
|
|
619
|
-
case "FilterGroup": {
|
|
620
|
-
const checks = check.checks.map(collectJsonSchemaCheck).filter((c) => c !== undefined)
|
|
621
|
-
if (checks.length === 0) return undefined
|
|
622
|
-
let out = { allOf: checks }
|
|
623
|
-
const a = collectJsonSchemaAnnotations(check.annotations)
|
|
624
|
-
if (a) {
|
|
625
|
-
out = { ...out, ...a }
|
|
626
|
-
}
|
|
627
|
-
return out
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
function filterToJsonSchema(
|
|
634
|
-
filter: SchemaRepresentation.Filter<any>,
|
|
635
|
-
type: unknown
|
|
636
|
-
): JsonSchema.JsonSchema | undefined {
|
|
637
|
-
const meta = filter.meta as SchemaRepresentation.Meta
|
|
638
|
-
if (!meta) return undefined
|
|
639
|
-
|
|
640
|
-
let out = on(meta)
|
|
641
|
-
const a = collectJsonSchemaAnnotations(filter.annotations)
|
|
642
|
-
if (a) {
|
|
643
|
-
out = { ...out, ...a }
|
|
644
|
-
}
|
|
645
|
-
return out
|
|
646
|
-
|
|
647
|
-
function on(
|
|
648
|
-
meta: SchemaRepresentation.Meta
|
|
649
|
-
): JsonSchema.JsonSchema | undefined {
|
|
650
|
-
switch (meta._tag) {
|
|
651
|
-
case "isMinLength":
|
|
652
|
-
return type === "array" ? { minItems: meta.minLength } : { minLength: meta.minLength }
|
|
653
|
-
case "isMaxLength":
|
|
654
|
-
return type === "array" ? { maxItems: meta.maxLength } : { maxLength: meta.maxLength }
|
|
655
|
-
case "isLengthBetween":
|
|
656
|
-
return type === "array"
|
|
657
|
-
? { allOf: [{ minItems: meta.minimum }, { maxItems: meta.maximum }] }
|
|
658
|
-
: { allOf: [{ minLength: meta.minimum }, { maxLength: meta.maximum }] }
|
|
659
|
-
case "isPattern":
|
|
660
|
-
case "isGUID":
|
|
661
|
-
case "isULID":
|
|
662
|
-
case "isBase64":
|
|
663
|
-
case "isBase64Url":
|
|
664
|
-
case "isStartsWith":
|
|
665
|
-
case "isEndsWith":
|
|
666
|
-
case "isIncludes":
|
|
667
|
-
case "isUppercased":
|
|
668
|
-
case "isLowercased":
|
|
669
|
-
case "isCapitalized":
|
|
670
|
-
case "isUncapitalized":
|
|
671
|
-
case "isTrimmed":
|
|
672
|
-
case "isStringFinite":
|
|
673
|
-
case "isStringBigInt":
|
|
674
|
-
case "isStringSymbol":
|
|
675
|
-
return { pattern: meta.regExp.source }
|
|
676
|
-
case "isUUID":
|
|
677
|
-
return { pattern: meta.regExp.source, format: "uuid" }
|
|
678
|
-
|
|
679
|
-
case "isFinite":
|
|
680
|
-
case "isInt":
|
|
681
|
-
return undefined
|
|
682
|
-
case "isMultipleOf":
|
|
683
|
-
return { multipleOf: meta.divisor }
|
|
684
|
-
case "isGreaterThanOrEqualTo":
|
|
685
|
-
return { minimum: meta.minimum }
|
|
686
|
-
case "isLessThanOrEqualTo":
|
|
687
|
-
return { maximum: meta.maximum }
|
|
688
|
-
case "isGreaterThan":
|
|
689
|
-
return { exclusiveMinimum: meta.exclusiveMinimum }
|
|
690
|
-
case "isLessThan":
|
|
691
|
-
return { exclusiveMaximum: meta.exclusiveMaximum }
|
|
692
|
-
case "isBetween": {
|
|
693
|
-
return {
|
|
694
|
-
[meta.exclusiveMinimum ? "exclusiveMinimum" : "minimum"]: meta.minimum,
|
|
695
|
-
[meta.exclusiveMaximum ? "exclusiveMaximum" : "maximum"]: meta.maximum
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
case "isUnique":
|
|
700
|
-
return { uniqueItems: true }
|
|
701
|
-
|
|
702
|
-
case "isMinProperties":
|
|
703
|
-
return { minProperties: meta.minProperties }
|
|
704
|
-
case "isMaxProperties":
|
|
705
|
-
return { maxProperties: meta.maxProperties }
|
|
706
|
-
case "isPropertiesLengthBetween":
|
|
707
|
-
return { minProperties: meta.minimum, maxProperties: meta.maximum }
|
|
708
|
-
case "isPropertyNames":
|
|
709
|
-
return { propertyNames: recur(meta.propertyNames) }
|
|
710
|
-
|
|
711
|
-
case "isDateValid":
|
|
712
|
-
return { format: "date-time" }
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
function getParameterPatterns(parameter: SchemaRepresentation.Representation): Array<string> {
|
|
718
|
-
switch (parameter._tag) {
|
|
719
|
-
default:
|
|
720
|
-
throw new globalThis.Error(`Unsupported index signature parameter: ${parameter._tag}`)
|
|
721
|
-
case "Reference":
|
|
722
|
-
return getParameterPatterns(multiDocument.references[parameter.$ref])
|
|
723
|
-
case "String":
|
|
724
|
-
return getPatterns(parameter)
|
|
725
|
-
case "TemplateLiteral":
|
|
726
|
-
return [`^${parameter.parts.map(getPartPattern).join("")}$`]
|
|
727
|
-
case "Union":
|
|
728
|
-
return parameter.types.flatMap(getParameterPatterns)
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
function getPatterns(s: SchemaRepresentation.String): Array<string> {
|
|
734
|
-
return recur(s.checks)
|
|
735
|
-
|
|
736
|
-
function recur(checks: ReadonlyArray<SchemaRepresentation.Check<SchemaRepresentation.StringMeta>>): Array<string> {
|
|
737
|
-
return checks.flatMap((c) => {
|
|
738
|
-
switch (c._tag) {
|
|
739
|
-
case "Filter": {
|
|
740
|
-
if ("regExp" in c.meta) {
|
|
741
|
-
return [c.meta.regExp.source]
|
|
742
|
-
}
|
|
743
|
-
return []
|
|
744
|
-
}
|
|
745
|
-
case "FilterGroup":
|
|
746
|
-
return recur(c.checks)
|
|
747
|
-
}
|
|
748
|
-
})
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
function hasCheck(checks: ReadonlyArray<SchemaRepresentation.Check<SchemaRepresentation.Meta>>, tag: string): boolean {
|
|
753
|
-
return checks.some((c) => {
|
|
754
|
-
switch (c._tag) {
|
|
755
|
-
case "Filter":
|
|
756
|
-
return c.meta._tag === tag
|
|
757
|
-
case "FilterGroup":
|
|
758
|
-
return hasCheck(c.checks, tag)
|
|
759
|
-
}
|
|
760
|
-
})
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
function appendJsonSchema(a: JsonSchema.JsonSchema, b: JsonSchema.JsonSchema): JsonSchema.JsonSchema {
|
|
764
|
-
if (Object.keys(a).length === 0) return b
|
|
765
|
-
const len = Object.keys(b).length
|
|
766
|
-
if (len === 0) return a
|
|
767
|
-
const members = Array.isArray(b.allOf) && len === 1 ? b.allOf : [b]
|
|
768
|
-
|
|
769
|
-
if (Array.isArray(a.allOf)) {
|
|
770
|
-
return { ...a, allOf: [...a.allOf, ...members] }
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
if (typeof a.$ref === "string") {
|
|
774
|
-
return { allOf: [a, ...members] }
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
return { ...a, allOf: members }
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
function getPartPattern(part: SchemaRepresentation.Representation): string {
|
|
781
|
-
switch (part._tag) {
|
|
782
|
-
case "Literal":
|
|
783
|
-
return RegEx.escape(globalThis.String(part.literal))
|
|
784
|
-
case "String":
|
|
785
|
-
return SchemaAST.STRING_PATTERN
|
|
786
|
-
case "Number":
|
|
787
|
-
return SchemaAST.FINITE_PATTERN
|
|
788
|
-
case "TemplateLiteral":
|
|
789
|
-
return part.parts.map(getPartPattern).join("")
|
|
790
|
-
case "Union":
|
|
791
|
-
return part.types.map(getPartPattern).join("|")
|
|
792
|
-
default:
|
|
793
|
-
throw new globalThis.Error("Unsupported part", { cause: part })
|
|
794
|
-
}
|
|
795
|
-
}
|