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
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import * as Arr from "../../../Array.ts"
|
|
2
|
+
import * as InternalRecord from "../../../internal/record.ts"
|
|
3
|
+
import type * as JsonSchema from "../../../JsonSchema.ts"
|
|
4
|
+
import * as Option from "../../../Option.ts"
|
|
5
|
+
import * as Predicate from "../../../Predicate.ts"
|
|
6
|
+
import * as Schema from "../../../Schema.ts"
|
|
7
|
+
import * as SchemaAST from "../../../SchemaAST.ts"
|
|
8
|
+
import * as SchemaTransformation from "../../../SchemaTransformation.ts"
|
|
9
|
+
import * as Tool from "../Tool.ts"
|
|
10
|
+
|
|
11
|
+
const REST_PROPERTY_NAME = "__rest__"
|
|
12
|
+
const TAIL_PROPERTY_PREFIX = "__tail_"
|
|
13
|
+
|
|
14
|
+
const RECORD_DESCRIPTION =
|
|
15
|
+
"Object encoded as array of [key, value] pairs. Apply object constraints to the decoded object"
|
|
16
|
+
|
|
17
|
+
const TUPLE_DESCRIPTION =
|
|
18
|
+
"Tuple encoded as an object with numeric string keys ('0', '1', ...). If present, '__rest__' contains remaining elements"
|
|
19
|
+
const TUPLE_TAIL_DESCRIPTION = `${TUPLE_DESCRIPTION}. Post-rest elements use '__tail_0__', '__tail_1__', and so on`
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
export function toCodec<T, E, RD, RE>(
|
|
23
|
+
schema: Schema.ConstraintCodec<T, E, RD, RE>
|
|
24
|
+
): Schema.ConstraintCodec<T, unknown, RD, RE> {
|
|
25
|
+
const jsonCodec = Schema.toCodecJson(schema)
|
|
26
|
+
const encoded = SchemaAST.toEncoded(jsonCodec.ast)
|
|
27
|
+
const from = transform(encoded)
|
|
28
|
+
if (from === encoded) {
|
|
29
|
+
return jsonCodec.ast === schema.ast ? schema : jsonCodec
|
|
30
|
+
}
|
|
31
|
+
return Schema.make<typeof schema>(
|
|
32
|
+
SchemaAST.decodeTo(from, jsonCodec.ast, SchemaTransformation.passthrough())
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function transform(root: SchemaAST.AST): SchemaAST.AST {
|
|
37
|
+
const cache = new Map<SchemaAST.AST, SchemaAST.AST>()
|
|
38
|
+
|
|
39
|
+
function recur(ast: SchemaAST.AST): SchemaAST.AST {
|
|
40
|
+
const cached = cache.get(ast)
|
|
41
|
+
if (cached !== undefined) return cached
|
|
42
|
+
|
|
43
|
+
switch (ast._tag) {
|
|
44
|
+
case "Union": {
|
|
45
|
+
const types = SchemaAST.mapOrSame(ast.types, recur)
|
|
46
|
+
const checks = prepareChecks(ast.checks)
|
|
47
|
+
const mode = ast.mode === "oneOf" ? "anyOf" : ast.mode
|
|
48
|
+
if (types === ast.types && checks === ast.checks && mode === ast.mode) return ast
|
|
49
|
+
return new SchemaAST.Union(
|
|
50
|
+
types,
|
|
51
|
+
mode,
|
|
52
|
+
ast.annotations,
|
|
53
|
+
checks,
|
|
54
|
+
ast.encoding,
|
|
55
|
+
ast.context,
|
|
56
|
+
ast.encodingChecks
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
case "Arrays": {
|
|
60
|
+
if (ast.elements.length > 0 || ast.rest.length > 1) {
|
|
61
|
+
return tupleToObject(ast, recur)
|
|
62
|
+
}
|
|
63
|
+
const elements = SchemaAST.mapOrSame(ast.elements, recur)
|
|
64
|
+
const rest = SchemaAST.mapOrSame(ast.rest, recur)
|
|
65
|
+
const checks = prepareChecks(ast.checks)
|
|
66
|
+
if (elements === ast.elements && rest === ast.rest && checks === ast.checks) return ast
|
|
67
|
+
return new SchemaAST.Arrays(
|
|
68
|
+
ast.isMutable,
|
|
69
|
+
elements,
|
|
70
|
+
rest,
|
|
71
|
+
ast.annotations,
|
|
72
|
+
checks,
|
|
73
|
+
ast.encoding,
|
|
74
|
+
ast.context,
|
|
75
|
+
ast.encodingChecks
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
case "Objects": {
|
|
79
|
+
if (ast.indexSignatures.length === 1 && ast.propertySignatures.length === 0) {
|
|
80
|
+
const indexSignature = ast.indexSignatures[0]
|
|
81
|
+
if (Tool.isEmptyParamsRecord(indexSignature)) return ast
|
|
82
|
+
}
|
|
83
|
+
if (ast.indexSignatures.length > 0) {
|
|
84
|
+
return objectToEntries(ast, recur)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const propertySignatures = SchemaAST.mapOrSame(ast.propertySignatures, (propertySignature) => {
|
|
88
|
+
let type = recur(propertySignature.type)
|
|
89
|
+
if (SchemaAST.isOptional(propertySignature.type)) {
|
|
90
|
+
type = optionalToNullable(type)
|
|
91
|
+
}
|
|
92
|
+
return type === propertySignature.type
|
|
93
|
+
? propertySignature
|
|
94
|
+
: new SchemaAST.PropertySignature(propertySignature.name, type)
|
|
95
|
+
})
|
|
96
|
+
const indexSignatures = SchemaAST.mapOrSame(ast.indexSignatures, (indexSignature) => {
|
|
97
|
+
const parameter = recur(indexSignature.parameter)
|
|
98
|
+
const type = recur(indexSignature.type)
|
|
99
|
+
return parameter === indexSignature.parameter && type === indexSignature.type
|
|
100
|
+
? indexSignature
|
|
101
|
+
: new SchemaAST.IndexSignature(parameter, type, indexSignature.merge)
|
|
102
|
+
})
|
|
103
|
+
const checks = prepareChecks(ast.checks)
|
|
104
|
+
if (
|
|
105
|
+
propertySignatures === ast.propertySignatures &&
|
|
106
|
+
indexSignatures === ast.indexSignatures &&
|
|
107
|
+
checks === ast.checks
|
|
108
|
+
) {
|
|
109
|
+
return ast
|
|
110
|
+
}
|
|
111
|
+
return new SchemaAST.Objects(
|
|
112
|
+
propertySignatures,
|
|
113
|
+
indexSignatures,
|
|
114
|
+
ast.annotations,
|
|
115
|
+
checks,
|
|
116
|
+
ast.encoding,
|
|
117
|
+
ast.context,
|
|
118
|
+
ast.encodingChecks
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
case "Suspend": {
|
|
122
|
+
const out = new SchemaAST.Suspend(
|
|
123
|
+
() => recur(ast.thunk()),
|
|
124
|
+
ast.annotations,
|
|
125
|
+
undefined,
|
|
126
|
+
ast.encoding,
|
|
127
|
+
ast.context
|
|
128
|
+
)
|
|
129
|
+
cache.set(ast, out)
|
|
130
|
+
return out
|
|
131
|
+
}
|
|
132
|
+
default: {
|
|
133
|
+
const checks = prepareChecks(ast.checks)
|
|
134
|
+
return checks === ast.checks ? ast : SchemaAST.replaceChecks(ast, checks)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return recur(root)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function tupleToObject(ast: SchemaAST.Arrays, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
|
|
143
|
+
const propertySignatures = ast.elements.map((element, index) =>
|
|
144
|
+
new SchemaAST.PropertySignature(String(index), element)
|
|
145
|
+
)
|
|
146
|
+
if (ast.rest.length === 1) {
|
|
147
|
+
propertySignatures.push(
|
|
148
|
+
new SchemaAST.PropertySignature(REST_PROPERTY_NAME, new SchemaAST.Arrays(false, [], ast.rest))
|
|
149
|
+
)
|
|
150
|
+
} else if (ast.rest.length > 1) {
|
|
151
|
+
propertySignatures.push(
|
|
152
|
+
new SchemaAST.PropertySignature(REST_PROPERTY_NAME, new SchemaAST.Arrays(false, [], [ast.rest[0]]))
|
|
153
|
+
)
|
|
154
|
+
for (let index = 1; index < ast.rest.length; index++) {
|
|
155
|
+
propertySignatures.push(
|
|
156
|
+
new SchemaAST.PropertySignature(`${TAIL_PROPERTY_PREFIX}${index - 1}__`, ast.rest[index])
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const from = recur(
|
|
161
|
+
new SchemaAST.Objects(
|
|
162
|
+
propertySignatures,
|
|
163
|
+
[],
|
|
164
|
+
structuralAnnotations(ast, ast.rest.length > 1 ? TUPLE_TAIL_DESCRIPTION : TUPLE_DESCRIPTION),
|
|
165
|
+
compilerChecks(ast.checks)
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
return SchemaAST.decodeTo(
|
|
169
|
+
from,
|
|
170
|
+
ast,
|
|
171
|
+
SchemaTransformation.transform({
|
|
172
|
+
decode: (object) => {
|
|
173
|
+
let tuple: Array<unknown> = []
|
|
174
|
+
for (let index = 0; index < ast.elements.length; index++) {
|
|
175
|
+
const key = String(index)
|
|
176
|
+
if (object[key] !== undefined) tuple.push(object[key])
|
|
177
|
+
}
|
|
178
|
+
if (REST_PROPERTY_NAME in object) {
|
|
179
|
+
tuple = [...tuple, ...object[REST_PROPERTY_NAME]]
|
|
180
|
+
}
|
|
181
|
+
for (let index = 1; index < ast.rest.length; index++) {
|
|
182
|
+
tuple.push(object[`${TAIL_PROPERTY_PREFIX}${index - 1}__`])
|
|
183
|
+
}
|
|
184
|
+
return tuple
|
|
185
|
+
},
|
|
186
|
+
encode: (tuple) => {
|
|
187
|
+
const object: Record<string, unknown> = {}
|
|
188
|
+
for (let index = 0; index < ast.elements.length; index++) {
|
|
189
|
+
if (index < tuple.length) object[String(index)] = tuple[index]
|
|
190
|
+
}
|
|
191
|
+
if (ast.rest.length >= 1) {
|
|
192
|
+
const tailLength = ast.rest.length - 1
|
|
193
|
+
const restEnd = Math.max(ast.elements.length, tuple.length - tailLength)
|
|
194
|
+
object[REST_PROPERTY_NAME] = tuple.slice(ast.elements.length, restEnd)
|
|
195
|
+
for (let index = 0; index < tailLength; index++) {
|
|
196
|
+
object[`${TAIL_PROPERTY_PREFIX}${index}__`] = tuple[restEnd + index]
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return object
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function objectToEntries(
|
|
206
|
+
ast: SchemaAST.Objects,
|
|
207
|
+
recur: (ast: SchemaAST.AST) => SchemaAST.AST
|
|
208
|
+
): SchemaAST.AST {
|
|
209
|
+
const checks = combineChecks(recordChecks(ast.checks), compilerChecks(ast.checks))
|
|
210
|
+
const key = unionOrSingle([
|
|
211
|
+
...ast.propertySignatures.map((propertySignature) => new SchemaAST.Literal(propertySignature.name as string)),
|
|
212
|
+
...ast.indexSignatures.map((indexSignature) => indexSignature.parameter)
|
|
213
|
+
])
|
|
214
|
+
const value = unionOrSingle([
|
|
215
|
+
...ast.propertySignatures.map((propertySignature) => propertySignature.type),
|
|
216
|
+
...ast.indexSignatures.map((indexSignature) => indexSignature.type)
|
|
217
|
+
])
|
|
218
|
+
const from = recur(
|
|
219
|
+
new SchemaAST.Arrays(
|
|
220
|
+
false,
|
|
221
|
+
[],
|
|
222
|
+
[new SchemaAST.Arrays(false, [key, value], [])],
|
|
223
|
+
structuralAnnotations(ast, RECORD_DESCRIPTION),
|
|
224
|
+
checks
|
|
225
|
+
)
|
|
226
|
+
)
|
|
227
|
+
return SchemaAST.decodeTo(
|
|
228
|
+
from,
|
|
229
|
+
ast,
|
|
230
|
+
SchemaTransformation.transform({
|
|
231
|
+
decode: Object.fromEntries,
|
|
232
|
+
encode: Object.entries
|
|
233
|
+
})
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function unionOrSingle(types: ReadonlyArray<SchemaAST.AST>): SchemaAST.AST {
|
|
238
|
+
const unique = Array.from(new Set(types))
|
|
239
|
+
return unique.length === 1 ? unique[0] : new SchemaAST.Union(unique, "anyOf")
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function combineChecks(
|
|
243
|
+
left: SchemaAST.Checks | undefined,
|
|
244
|
+
right: SchemaAST.Checks | undefined
|
|
245
|
+
): SchemaAST.Checks | undefined {
|
|
246
|
+
if (left === undefined) return right
|
|
247
|
+
if (right === undefined) return left
|
|
248
|
+
return [...left, ...right]
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function compilerChecks(checks: SchemaAST.Checks | undefined): SchemaAST.Checks | undefined {
|
|
252
|
+
if (checks === undefined) return undefined
|
|
253
|
+
const out = checks.flatMap(compilerCheck)
|
|
254
|
+
return Arr.isArrayNonEmpty(out) ? out : undefined
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function compilerCheck(check: SchemaAST.Check<any>): Array<SchemaAST.Check<any>> {
|
|
258
|
+
// Structural rewrites change the value seen by provider-side checks. A
|
|
259
|
+
// no-op proxy lets the generic compiler call `toJsonSchema` with the real
|
|
260
|
+
// provider type and dependency schemas without running the original filter
|
|
261
|
+
// against the wrong runtime shape.
|
|
262
|
+
const annotations = compilerAnnotations(check.annotations)
|
|
263
|
+
if (check._tag === "Filter") {
|
|
264
|
+
return annotations === undefined ? [] : [new SchemaAST.Filter(() => undefined, annotations)]
|
|
265
|
+
}
|
|
266
|
+
const checks = check.checks.flatMap(compilerCheck)
|
|
267
|
+
if (Arr.isArrayNonEmpty(checks)) {
|
|
268
|
+
return [new SchemaAST.FilterGroup(checks, annotations)]
|
|
269
|
+
}
|
|
270
|
+
return annotations === undefined ? [] : [new SchemaAST.Filter(() => undefined, annotations)]
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function compilerAnnotations(
|
|
274
|
+
annotations: Schema.Annotations.Filter | undefined
|
|
275
|
+
): Schema.Annotations.Filter | undefined {
|
|
276
|
+
if (annotations?.toJsonSchema === undefined) return undefined
|
|
277
|
+
return {
|
|
278
|
+
representation: annotations.representation,
|
|
279
|
+
toJsonSchema: annotations.toJsonSchema
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function optionalToNullable(type: SchemaAST.AST): SchemaAST.AST {
|
|
284
|
+
return SchemaAST.decodeTo(
|
|
285
|
+
new SchemaAST.Union([type, SchemaAST.null], "anyOf"),
|
|
286
|
+
SchemaAST.optionalKey(type),
|
|
287
|
+
SchemaTransformation.transformOptional({
|
|
288
|
+
decode: Option.filter(Predicate.isNotNull),
|
|
289
|
+
encode: Option.orElseSome(() => null)
|
|
290
|
+
})
|
|
291
|
+
)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function prepareChecks(checks: SchemaAST.Checks | undefined): SchemaAST.Checks | undefined {
|
|
295
|
+
if (checks === undefined) return undefined
|
|
296
|
+
const out = SchemaAST.mapOrSame(checks, prepareCheck)
|
|
297
|
+
return out as SchemaAST.Checks
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function prepareCheck(check: SchemaAST.Check<any>): SchemaAST.Check<any> {
|
|
301
|
+
switch (check._tag) {
|
|
302
|
+
case "Filter": {
|
|
303
|
+
const id = check.annotations?.representation?.id
|
|
304
|
+
return id === "effect/schema/isFinite" || id === "effect/schema/isInt"
|
|
305
|
+
? check.annotate({ expected: undefined })
|
|
306
|
+
: check
|
|
307
|
+
}
|
|
308
|
+
case "FilterGroup": {
|
|
309
|
+
const checks = SchemaAST.mapOrSame(check.checks, prepareCheck)
|
|
310
|
+
return checks === check.checks
|
|
311
|
+
? check
|
|
312
|
+
: new SchemaAST.FilterGroup(checks, check.annotations)
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function recordChecks(checks: SchemaAST.Checks | undefined): SchemaAST.Checks | undefined {
|
|
318
|
+
if (checks === undefined) return undefined
|
|
319
|
+
const out = checks.flatMap(recordCheck)
|
|
320
|
+
return Arr.isArrayNonEmpty(out) ? out : undefined
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function recordCheck(check: SchemaAST.Check<any>): Array<SchemaAST.Check<any>> {
|
|
324
|
+
if (check._tag === "FilterGroup") return check.checks.flatMap(recordCheck)
|
|
325
|
+
const representation = check.annotations?.representation
|
|
326
|
+
const payload = representation?.payload
|
|
327
|
+
if (!isJsonObject(payload)) return []
|
|
328
|
+
// A decoded record with at least N properties necessarily came from at least
|
|
329
|
+
// N entries. Upper bounds are not transported because duplicate provider
|
|
330
|
+
// keys can collapse during `Object.fromEntries`, so `maxItems` could reject
|
|
331
|
+
// an input that the returned codec accepts.
|
|
332
|
+
switch (representation?.id) {
|
|
333
|
+
case "effect/schema/isMinProperties":
|
|
334
|
+
return typeof payload.minProperties === "number"
|
|
335
|
+
? [withoutDescription(Schema.isMinLength(payload.minProperties))]
|
|
336
|
+
: []
|
|
337
|
+
case "effect/schema/isPropertiesLengthBetween":
|
|
338
|
+
return typeof payload.minimum === "number"
|
|
339
|
+
? [withoutDescription(Schema.isMinLength(payload.minimum))]
|
|
340
|
+
: []
|
|
341
|
+
default:
|
|
342
|
+
return []
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function isJsonObject(input: Schema.Json | undefined): input is Schema.JsonObject {
|
|
347
|
+
return typeof input === "object" && input !== null && !Array.isArray(input)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function withoutDescription(check: SchemaAST.Filter<any>): SchemaAST.Filter<any> {
|
|
351
|
+
return check.annotate({
|
|
352
|
+
description: undefined,
|
|
353
|
+
expected: undefined,
|
|
354
|
+
title: undefined
|
|
355
|
+
})
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function structuralAnnotations(
|
|
359
|
+
ast: SchemaAST.AST,
|
|
360
|
+
structuralDescription: string
|
|
361
|
+
): Schema.Annotations.Annotations {
|
|
362
|
+
const descriptions: Array<string> = []
|
|
363
|
+
appendAnnotationDescription(descriptions, ast.annotations)
|
|
364
|
+
if (ast.checks !== undefined) {
|
|
365
|
+
for (const check of ast.checks) appendCheckDescriptions(descriptions, check)
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
description: descriptions.length === 0
|
|
369
|
+
? structuralDescription
|
|
370
|
+
: `${structuralDescription}; ${descriptions.join(" and ")}`
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function appendCheckDescriptions(descriptions: Array<string>, check: SchemaAST.Check<any>): void {
|
|
375
|
+
appendAnnotationDescription(descriptions, check.annotations)
|
|
376
|
+
if (check._tag === "FilterGroup") {
|
|
377
|
+
for (const child of check.checks) appendCheckDescriptions(descriptions, child)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function appendAnnotationDescription(
|
|
382
|
+
descriptions: Array<string>,
|
|
383
|
+
annotations: Schema.Annotations.Annotations | undefined
|
|
384
|
+
): void {
|
|
385
|
+
const description = annotations?.description ?? annotations?.expected
|
|
386
|
+
if (typeof description === "string" && !descriptions.includes(description)) {
|
|
387
|
+
descriptions.push(description)
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
type JsonSchemaVisitor = (schema: JsonSchema.JsonSchema) => JsonSchema.JsonSchema
|
|
392
|
+
|
|
393
|
+
/** @internal */
|
|
394
|
+
export function walkJsonSchema(
|
|
395
|
+
schema: JsonSchema.JsonSchema,
|
|
396
|
+
visitor: JsonSchemaVisitor
|
|
397
|
+
): JsonSchema.JsonSchema {
|
|
398
|
+
const out: JsonSchema.JsonSchema = {}
|
|
399
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
400
|
+
switch (key) {
|
|
401
|
+
case "properties":
|
|
402
|
+
case "patternProperties": {
|
|
403
|
+
if (isJsonSchema(value)) {
|
|
404
|
+
const properties: Record<string, unknown> = {}
|
|
405
|
+
for (const [name, property] of Object.entries(value)) {
|
|
406
|
+
InternalRecord.assignProperty(
|
|
407
|
+
properties,
|
|
408
|
+
name,
|
|
409
|
+
isJsonSchema(property) ? walkJsonSchema(property, visitor) : property
|
|
410
|
+
)
|
|
411
|
+
}
|
|
412
|
+
InternalRecord.assignProperty(out, key, properties)
|
|
413
|
+
} else {
|
|
414
|
+
InternalRecord.assignProperty(out, key, value)
|
|
415
|
+
}
|
|
416
|
+
break
|
|
417
|
+
}
|
|
418
|
+
case "additionalProperties":
|
|
419
|
+
case "items":
|
|
420
|
+
case "propertyNames": {
|
|
421
|
+
InternalRecord.assignProperty(out, key, isJsonSchema(value) ? walkJsonSchema(value, visitor) : value)
|
|
422
|
+
break
|
|
423
|
+
}
|
|
424
|
+
case "prefixItems":
|
|
425
|
+
case "allOf":
|
|
426
|
+
case "anyOf":
|
|
427
|
+
case "oneOf": {
|
|
428
|
+
InternalRecord.assignProperty(
|
|
429
|
+
out,
|
|
430
|
+
key,
|
|
431
|
+
Array.isArray(value)
|
|
432
|
+
? value.map((member) => isJsonSchema(member) ? walkJsonSchema(member, visitor) : member)
|
|
433
|
+
: value
|
|
434
|
+
)
|
|
435
|
+
break
|
|
436
|
+
}
|
|
437
|
+
default:
|
|
438
|
+
InternalRecord.assignProperty(out, key, value)
|
|
439
|
+
break
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return visitor(out)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** @internal */
|
|
446
|
+
export function appendDescription(schema: JsonSchema.JsonSchema, description: string): void {
|
|
447
|
+
if (typeof schema.description === "string") {
|
|
448
|
+
const descriptions = schema.description.split(" and ")
|
|
449
|
+
if (!descriptions.includes(description)) schema.description += ` and ${description}`
|
|
450
|
+
} else {
|
|
451
|
+
schema.description = description
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** @internal */
|
|
456
|
+
export function isJsonSchema(input: unknown): input is JsonSchema.JsonSchema {
|
|
457
|
+
return typeof input === "object" && input !== null && !Array.isArray(input)
|
|
458
|
+
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Defines structured errors for the unstable CLI parser and runner.
|
|
3
3
|
*
|
|
4
4
|
* CLI errors describe problems such as unknown or duplicate flags, missing
|
|
5
|
-
* flags or arguments, invalid values, unknown
|
|
6
|
-
* failures, and requests to show command help. This
|
|
7
|
-
* `CliError` union, the `isCliError` guard, schema-backed
|
|
8
|
-
* display messages, and the `NonShowHelpErrors` union used
|
|
9
|
-
* validation errors should be shown with help output.
|
|
5
|
+
* flags or arguments, unexpected positional arguments, invalid values, unknown
|
|
6
|
+
* subcommands, user handler failures, and requests to show command help. This
|
|
7
|
+
* module includes the `CliError` union, the `isCliError` guard, schema-backed
|
|
8
|
+
* error classes with display messages, and the `NonShowHelpErrors` union used
|
|
9
|
+
* when parse or validation errors should be shown with help output.
|
|
10
10
|
*
|
|
11
11
|
* @since 4.0.0
|
|
12
12
|
*/
|
|
@@ -89,6 +89,7 @@ export type CliError =
|
|
|
89
89
|
| DuplicateOption
|
|
90
90
|
| MissingOption
|
|
91
91
|
| MissingArgument
|
|
92
|
+
| UnexpectedArgument
|
|
92
93
|
| InvalidValue
|
|
93
94
|
| UnknownSubcommand
|
|
94
95
|
| ShowHelp
|
|
@@ -307,6 +308,49 @@ export class MissingArgument extends Schema.TaggedErrorClass<MissingArgument>(
|
|
|
307
308
|
}
|
|
308
309
|
}
|
|
309
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Error thrown when positional arguments remain after a command has parsed all
|
|
313
|
+
* of its parameters.
|
|
314
|
+
*
|
|
315
|
+
* **Example** (Reporting unexpected arguments)
|
|
316
|
+
*
|
|
317
|
+
* ```ts
|
|
318
|
+
* import { CliError } from "effect/unstable/cli"
|
|
319
|
+
*
|
|
320
|
+
* const error = new CliError.UnexpectedArgument({
|
|
321
|
+
* arguments: ["extra.txt"]
|
|
322
|
+
* })
|
|
323
|
+
*
|
|
324
|
+
* console.log(error.message)
|
|
325
|
+
* // "Unexpected positional argument: \"extra.txt\""
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* @category models
|
|
329
|
+
* @since 4.0.0
|
|
330
|
+
*/
|
|
331
|
+
export class UnexpectedArgument extends Schema.TaggedErrorClass<UnexpectedArgument>(
|
|
332
|
+
`${TypeId}/UnexpectedArgument`
|
|
333
|
+
)("UnexpectedArgument", {
|
|
334
|
+
arguments: Schema.Array(Schema.String)
|
|
335
|
+
}) {
|
|
336
|
+
/**
|
|
337
|
+
* Marks this value as an unexpected CLI argument error for runtime guards.
|
|
338
|
+
*
|
|
339
|
+
* @since 4.0.0
|
|
340
|
+
*/
|
|
341
|
+
readonly [TypeId] = TypeId
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Formats the unexpected positional arguments for display.
|
|
345
|
+
*
|
|
346
|
+
* @since 4.0.0
|
|
347
|
+
*/
|
|
348
|
+
override get message() {
|
|
349
|
+
const label = this.arguments.length === 1 ? "argument" : "arguments"
|
|
350
|
+
return `Unexpected positional ${label}: ${this.arguments.map((value) => JSON.stringify(value)).join(", ")}`
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
310
354
|
/**
|
|
311
355
|
* Error thrown when an option or argument value is invalid.
|
|
312
356
|
*
|
|
@@ -506,6 +550,7 @@ export const NonShowHelpErrors: Schema.Union<
|
|
|
506
550
|
typeof DuplicateOption,
|
|
507
551
|
typeof MissingOption,
|
|
508
552
|
typeof MissingArgument,
|
|
553
|
+
typeof UnexpectedArgument,
|
|
509
554
|
typeof InvalidValue,
|
|
510
555
|
typeof UnknownSubcommand,
|
|
511
556
|
typeof UserError
|
|
@@ -515,6 +560,7 @@ export const NonShowHelpErrors: Schema.Union<
|
|
|
515
560
|
DuplicateOption,
|
|
516
561
|
MissingOption,
|
|
517
562
|
MissingArgument,
|
|
563
|
+
UnexpectedArgument,
|
|
518
564
|
InvalidValue,
|
|
519
565
|
UnknownSubcommand,
|
|
520
566
|
UserError
|
|
@@ -1068,7 +1068,7 @@ export const withSubcommands: {
|
|
|
1068
1068
|
|
|
1069
1069
|
const context = yield* impl.parseContext(raw)
|
|
1070
1070
|
const result = yield* sub.parse(raw.subcommand.value.parsedInput)
|
|
1071
|
-
return
|
|
1071
|
+
return { ...context, [SubcommandStateSymbol]: { name: sub.name, result } } as NextInput
|
|
1072
1072
|
})
|
|
1073
1073
|
|
|
1074
1074
|
const handle = Effect.fnUntraced(function*(input: NextInput, path: ReadonlyArray<string>) {
|
|
@@ -1184,20 +1184,20 @@ export const withSharedFlags: {
|
|
|
1184
1184
|
type NextInput = Simplify<Input & SharedInput>
|
|
1185
1185
|
type NextContextInput = Simplify<ContextInput & SharedInput>
|
|
1186
1186
|
|
|
1187
|
-
const parseShared = makeParser(sharedConfig) as (
|
|
1187
|
+
const parseShared = makeParser(sharedConfig, { allowLeftovers: true }) as (
|
|
1188
1188
|
input: ParsedTokens
|
|
1189
1189
|
) => Effect.Effect<SharedInput, CliError.CliError, Environment>
|
|
1190
1190
|
|
|
1191
1191
|
const parse = Effect.fnUntraced(function*(raw: ParsedTokens) {
|
|
1192
1192
|
const base = yield* impl.parse(raw)
|
|
1193
1193
|
const shared = yield* parseShared(raw)
|
|
1194
|
-
return
|
|
1194
|
+
return { ...(base as object), ...(shared as object) } as NextInput
|
|
1195
1195
|
})
|
|
1196
1196
|
|
|
1197
1197
|
const parseContext = Effect.fnUntraced(function*(raw: ParsedTokens) {
|
|
1198
1198
|
const base = yield* impl.parseContext(raw)
|
|
1199
1199
|
const shared = yield* parseShared(raw)
|
|
1200
|
-
return
|
|
1200
|
+
return { ...(base as object), ...(shared as object) } as NextContextInput
|
|
1201
1201
|
})
|
|
1202
1202
|
|
|
1203
1203
|
const handle = (
|
|
@@ -343,14 +343,14 @@ export const makeSingle = <const Kind extends ParamKind, A>(params: {
|
|
|
343
343
|
params.kind === argumentKind
|
|
344
344
|
? parsePositional(params.name, params.primitiveType, args)
|
|
345
345
|
: parseFlag(params.name, params.primitiveType, args)
|
|
346
|
-
return Object.
|
|
346
|
+
return Object.setPrototypeOf({
|
|
347
347
|
_tag: "Single",
|
|
348
348
|
...params,
|
|
349
349
|
description: params.description ?? Option.none(),
|
|
350
350
|
aliases: params.aliases ?? [],
|
|
351
351
|
hidden: params.hidden ?? false,
|
|
352
352
|
parse
|
|
353
|
-
})
|
|
353
|
+
}, Proto)
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
/**
|
|
@@ -865,7 +865,7 @@ export const keyValuePair = <Kind extends ParamKind>(
|
|
|
865
865
|
}),
|
|
866
866
|
{ min: 1 }
|
|
867
867
|
),
|
|
868
|
-
(objects) => Object.
|
|
868
|
+
(objects) => Object.fromEntries(objects.flatMap(Object.entries))
|
|
869
869
|
)
|
|
870
870
|
|
|
871
871
|
/**
|
|
@@ -125,7 +125,7 @@ export const makeCommand = <const Name extends string, Input, E, R, ContextInput
|
|
|
125
125
|
: Effect.fail(new CliError.ShowHelp({ commandPath, errors: [] }))
|
|
126
126
|
|
|
127
127
|
const parse = options.parse ?? makeParser(config) as any
|
|
128
|
-
const parseContext = options.parseContext ?? makeParser(contextConfig) as any
|
|
128
|
+
const parseContext = options.parseContext ?? makeParser(contextConfig, { allowLeftovers: true }) as any
|
|
129
129
|
|
|
130
130
|
const buildHelpDoc = (commandPath: ReadonlyArray<string>): HelpDoc => {
|
|
131
131
|
const args: Array<ArgDoc> = []
|
|
@@ -263,10 +263,18 @@ const appendChoiceKeys = (
|
|
|
263
263
|
* and `parseContext`, and also by `withSharedFlags` to avoid constructing a
|
|
264
264
|
* full throwaway command.
|
|
265
265
|
*/
|
|
266
|
-
export const makeParser = (
|
|
266
|
+
export const makeParser = (
|
|
267
|
+
cfg: ConfigInternal,
|
|
268
|
+
options?: {
|
|
269
|
+
readonly allowLeftovers?: boolean | undefined
|
|
270
|
+
} | undefined
|
|
271
|
+
) =>
|
|
267
272
|
Effect.fnUntraced(function*(input: ParsedTokens) {
|
|
268
273
|
const parsedArgs: Param.ParsedArgs = { flags: input.flags, arguments: input.arguments }
|
|
269
|
-
const values = yield* parseParams(parsedArgs, cfg.orderedParams)
|
|
274
|
+
const [remainingArguments, values] = yield* parseParams(parsedArgs, cfg.orderedParams)
|
|
275
|
+
if (options?.allowLeftovers !== true && remainingArguments.length > 0) {
|
|
276
|
+
return yield* new CliError.UnexpectedArgument({ arguments: remainingArguments })
|
|
277
|
+
}
|
|
270
278
|
return reconstructTree(cfg.tree, values)
|
|
271
279
|
})
|
|
272
280
|
|
|
@@ -275,7 +283,7 @@ export const makeParser = (cfg: ConfigInternal) =>
|
|
|
275
283
|
* representations.
|
|
276
284
|
*/
|
|
277
285
|
const parseParams: (parsedArgs: Param.ParsedArgs, params: ReadonlyArray<Param.Any>) => Effect.Effect<
|
|
278
|
-
ReadonlyArray<unknown
|
|
286
|
+
readonly [remainingArguments: ReadonlyArray<string>, values: ReadonlyArray<unknown>],
|
|
279
287
|
CliError.CliError,
|
|
280
288
|
Environment
|
|
281
289
|
> = Effect.fnUntraced(function*(parsedArgs, params) {
|
|
@@ -291,7 +299,7 @@ const parseParams: (parsedArgs: Param.ParsedArgs, params: ReadonlyArray<Param.An
|
|
|
291
299
|
currentArguments = remainingArguments
|
|
292
300
|
}
|
|
293
301
|
|
|
294
|
-
return results
|
|
302
|
+
return [currentArguments, results] as const
|
|
295
303
|
})
|
|
296
304
|
|
|
297
305
|
/**
|