effect 4.0.0-beta.101 → 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/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 +1268 -495
- 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 +2 -1
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/effect.js +64 -21
- 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 +4 -4
- 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/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/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 +2537 -986
- 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 +3 -2
- package/src/internal/effect.ts +67 -31
- 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/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,572 @@
|
|
|
1
|
+
import * as Arr from "../../Array.ts"
|
|
2
|
+
import { format, formatPropertyKey } from "../../Formatter.ts"
|
|
3
|
+
import type * as Schema from "../../Schema.ts"
|
|
4
|
+
import type * as SchemaRepresentation from "../../SchemaRepresentation.ts"
|
|
5
|
+
import { errorWithPath } from "../errors.ts"
|
|
6
|
+
import * as InternalRecord from "../record.ts"
|
|
7
|
+
import * as InternalAnnotations from "./annotations.ts"
|
|
8
|
+
|
|
9
|
+
type Path = ReadonlyArray<string | number>
|
|
10
|
+
type CheckRepresentationAnnotation = SchemaRepresentation.CheckRepresentationAnnotation<
|
|
11
|
+
SchemaRepresentation.Representation
|
|
12
|
+
>
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
export function makeCode(runtime: string, Type: string): SchemaRepresentation.Code {
|
|
16
|
+
return { runtime, Type }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function renderEmittableAnnotation(input: unknown): string | undefined {
|
|
20
|
+
if (
|
|
21
|
+
input === null ||
|
|
22
|
+
typeof input === "string" ||
|
|
23
|
+
typeof input === "boolean" ||
|
|
24
|
+
typeof input === "number" ||
|
|
25
|
+
typeof input === "bigint"
|
|
26
|
+
) return format(input)
|
|
27
|
+
if (typeof input === "symbol") {
|
|
28
|
+
const key = globalThis.Symbol.keyFor(input)
|
|
29
|
+
return key === undefined ? undefined : `Symbol.for(${format(key)})`
|
|
30
|
+
}
|
|
31
|
+
if (typeof input !== "object") return undefined
|
|
32
|
+
if (Array.isArray(input)) {
|
|
33
|
+
const values: Array<string> = []
|
|
34
|
+
for (const value of input) {
|
|
35
|
+
const rendered = renderEmittableAnnotation(value)
|
|
36
|
+
if (rendered === undefined) return undefined
|
|
37
|
+
values.push(rendered)
|
|
38
|
+
}
|
|
39
|
+
return `[${values.join(", ")}]`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const entries: Array<string> = []
|
|
43
|
+
for (const [key, value] of Object.entries(input)) {
|
|
44
|
+
const rendered = renderEmittableAnnotation(value)
|
|
45
|
+
if (rendered === undefined) return undefined
|
|
46
|
+
entries.push(`${formatPropertyKey(key)}: ${rendered}`)
|
|
47
|
+
}
|
|
48
|
+
return `{ ${entries.join(", ")} }`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function renderAnnotations(
|
|
52
|
+
annotations: Schema.Annotations.Annotations | undefined
|
|
53
|
+
): string | undefined {
|
|
54
|
+
if (annotations === undefined) return undefined
|
|
55
|
+
const entries: Array<string> = []
|
|
56
|
+
for (const [key, value] of Object.entries(annotations)) {
|
|
57
|
+
if (InternalAnnotations.annotationExcludedKeys.has(key)) continue
|
|
58
|
+
const rendered = renderEmittableAnnotation(value)
|
|
59
|
+
if (rendered !== undefined) entries.push(`${formatPropertyKey(key)}: ${rendered}`)
|
|
60
|
+
}
|
|
61
|
+
return entries.length === 0 ? undefined : `{ ${entries.join(", ")} }`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** @internal */
|
|
65
|
+
export function sanitizeJavaScriptIdentifier(input: string): string {
|
|
66
|
+
if (input.length === 0) return "_"
|
|
67
|
+
const out = input.replace(/[^A-Za-z0-9_$]/gu, "_")
|
|
68
|
+
const first = out[0]
|
|
69
|
+
return first >= "a" && first <= "z"
|
|
70
|
+
? first.toUpperCase() + out.slice(1)
|
|
71
|
+
: first >= "0" && first <= "9"
|
|
72
|
+
? `_${out}`
|
|
73
|
+
: out
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isSimpleLiveLiteral(
|
|
77
|
+
representation: SchemaRepresentation.Representation
|
|
78
|
+
): representation is SchemaRepresentation.Literal {
|
|
79
|
+
return representation._tag === "Literal" && representation.checks.length === 0 &&
|
|
80
|
+
representation.annotations === undefined
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** @internal */
|
|
84
|
+
export interface TopologicalSort {
|
|
85
|
+
readonly nonRecursives: ReadonlyArray<{
|
|
86
|
+
readonly $ref: string
|
|
87
|
+
readonly representation: SchemaRepresentation.Representation
|
|
88
|
+
}>
|
|
89
|
+
readonly recursives: Readonly<Record<string, SchemaRepresentation.Representation>>
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** @internal */
|
|
93
|
+
export function topologicalSort(
|
|
94
|
+
references: SchemaRepresentation.References
|
|
95
|
+
): TopologicalSort {
|
|
96
|
+
const identifiers = Object.keys(references)
|
|
97
|
+
const identifierSet = new Set(identifiers)
|
|
98
|
+
|
|
99
|
+
function collectRefs(root: SchemaRepresentation.Representation): ReadonlySet<string> {
|
|
100
|
+
const refs = new Set<string>()
|
|
101
|
+
const visited = new WeakSet<object>()
|
|
102
|
+
const stack: Array<SchemaRepresentation.Representation> = [root]
|
|
103
|
+
|
|
104
|
+
function pushRepresentationSchemas(representation: CheckRepresentationAnnotation | undefined): void {
|
|
105
|
+
if (representation?.schemas !== undefined) stack.push(...representation.schemas)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function pushChecks(
|
|
109
|
+
checks: ReadonlyArray<SchemaRepresentation.Check>
|
|
110
|
+
): void {
|
|
111
|
+
for (const check of checks) {
|
|
112
|
+
pushRepresentationSchemas(check.representation)
|
|
113
|
+
if (check._tag === "FilterGroup") pushChecks(check.checks)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
while (stack.length > 0) {
|
|
118
|
+
const representation = stack.pop()!
|
|
119
|
+
if (visited.has(representation)) continue
|
|
120
|
+
visited.add(representation)
|
|
121
|
+
if (representation._tag === "Reference") {
|
|
122
|
+
if (identifierSet.has(representation.$ref)) refs.add(representation.$ref)
|
|
123
|
+
continue
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
pushChecks(representation.checks)
|
|
127
|
+
switch (representation._tag) {
|
|
128
|
+
case "Declaration":
|
|
129
|
+
pushRepresentationSchemas(representation.representation)
|
|
130
|
+
stack.push(...representation.typeParameters)
|
|
131
|
+
break
|
|
132
|
+
case "Suspend":
|
|
133
|
+
stack.push(representation.thunk)
|
|
134
|
+
break
|
|
135
|
+
case "TemplateLiteral":
|
|
136
|
+
stack.push(...representation.parts)
|
|
137
|
+
break
|
|
138
|
+
case "Arrays":
|
|
139
|
+
for (const element of representation.elements) stack.push(element.type)
|
|
140
|
+
stack.push(...representation.rest)
|
|
141
|
+
break
|
|
142
|
+
case "Objects":
|
|
143
|
+
for (const property of representation.propertySignatures) stack.push(property.type)
|
|
144
|
+
for (const signature of representation.indexSignatures) {
|
|
145
|
+
stack.push(signature.parameter, signature.type)
|
|
146
|
+
}
|
|
147
|
+
break
|
|
148
|
+
case "Union":
|
|
149
|
+
stack.push(...representation.types)
|
|
150
|
+
break
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return refs
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const dependencies = new Map<string, ReadonlySet<string>>(
|
|
157
|
+
identifiers.map((identifier) => [identifier, collectRefs(references[identifier])])
|
|
158
|
+
)
|
|
159
|
+
const recursive = new Set<string>()
|
|
160
|
+
const state = new Map<string, 0 | 1 | 2>()
|
|
161
|
+
const stack: Array<string> = []
|
|
162
|
+
|
|
163
|
+
function visit(identifier: string): void {
|
|
164
|
+
const current = state.get(identifier) ?? 0
|
|
165
|
+
if (current === 1) {
|
|
166
|
+
const start = stack.indexOf(identifier)
|
|
167
|
+
for (let index = start; index < stack.length; index++) recursive.add(stack[index])
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
if (current === 2) return
|
|
171
|
+
state.set(identifier, 1)
|
|
172
|
+
stack.push(identifier)
|
|
173
|
+
for (const dependency of dependencies.get(identifier)!) visit(dependency)
|
|
174
|
+
stack.pop()
|
|
175
|
+
state.set(identifier, 2)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
for (const identifier of identifiers) visit(identifier)
|
|
179
|
+
|
|
180
|
+
const inDegree = new Map<string, number>()
|
|
181
|
+
const dependents = new Map<string, Set<string>>()
|
|
182
|
+
for (const identifier of identifiers) {
|
|
183
|
+
if (!recursive.has(identifier)) {
|
|
184
|
+
inDegree.set(identifier, 0)
|
|
185
|
+
dependents.set(identifier, new Set())
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
for (const [identifier, internalDependencies] of dependencies) {
|
|
189
|
+
if (recursive.has(identifier)) continue
|
|
190
|
+
for (const dependency of internalDependencies) {
|
|
191
|
+
if (recursive.has(dependency)) continue
|
|
192
|
+
inDegree.set(identifier, inDegree.get(identifier)! + 1)
|
|
193
|
+
dependents.get(dependency)!.add(identifier)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const queue: Array<string> = []
|
|
198
|
+
for (const [identifier, degree] of inDegree) {
|
|
199
|
+
if (degree === 0) queue.push(identifier)
|
|
200
|
+
}
|
|
201
|
+
const nonRecursives: Array<{
|
|
202
|
+
readonly $ref: string
|
|
203
|
+
readonly representation: SchemaRepresentation.Representation
|
|
204
|
+
}> = []
|
|
205
|
+
for (let index = 0; index < queue.length; index++) {
|
|
206
|
+
const $ref = queue[index]
|
|
207
|
+
nonRecursives.push({ $ref, representation: references[$ref] })
|
|
208
|
+
for (const dependent of dependents.get($ref)!) {
|
|
209
|
+
const degree = inDegree.get(dependent)! - 1
|
|
210
|
+
inDegree.set(dependent, degree)
|
|
211
|
+
if (degree === 0) queue.push(dependent)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const recursives: Record<string, SchemaRepresentation.Representation> = {}
|
|
215
|
+
for (const identifier of recursive) InternalRecord.assignProperty(recursives, identifier, references[identifier])
|
|
216
|
+
return { nonRecursives, recursives }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** @internal */
|
|
220
|
+
export function toCodeDocument(
|
|
221
|
+
document: SchemaRepresentation.MultiDocument
|
|
222
|
+
): SchemaRepresentation.CodeDocument {
|
|
223
|
+
const artifacts: Array<SchemaRepresentation.Artifact> = []
|
|
224
|
+
const sorted = topologicalSort(document.references)
|
|
225
|
+
const sanitizedReferences = new Map<string, string>()
|
|
226
|
+
const uniqueIdentifiers = new Set<string>()
|
|
227
|
+
let compilingRecursiveDefinition = false
|
|
228
|
+
let explicitSuspendDepth = 0
|
|
229
|
+
|
|
230
|
+
for (const { $ref } of sorted.nonRecursives) ensureUniqueIdentifier($ref)
|
|
231
|
+
for (const $ref of Object.keys(sorted.recursives)) ensureUniqueIdentifier($ref)
|
|
232
|
+
|
|
233
|
+
const nonRecursives = sorted.nonRecursives.map(({ $ref, representation }) => ({
|
|
234
|
+
$ref: ensureUniqueIdentifier($ref),
|
|
235
|
+
code: recur(representation, ["references", $ref])
|
|
236
|
+
}))
|
|
237
|
+
const recursives: Record<string, SchemaRepresentation.Code> = {}
|
|
238
|
+
for (const [$ref, representation] of Object.entries(sorted.recursives)) {
|
|
239
|
+
compilingRecursiveDefinition = true
|
|
240
|
+
InternalRecord.assignProperty(recursives, ensureUniqueIdentifier($ref), recur(representation, ["references", $ref]))
|
|
241
|
+
compilingRecursiveDefinition = false
|
|
242
|
+
}
|
|
243
|
+
const codes = document.representations.map((representation, index) =>
|
|
244
|
+
recur(representation, ["representations", index])
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
codes,
|
|
249
|
+
references: { nonRecursives, recursives },
|
|
250
|
+
artifacts
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function ensureUniqueIdentifier(original: string): string {
|
|
254
|
+
const existing = sanitizedReferences.get(original)
|
|
255
|
+
if (existing !== undefined) return existing
|
|
256
|
+
const candidate = freshIdentifier(original)
|
|
257
|
+
sanitizedReferences.set(original, candidate)
|
|
258
|
+
return candidate
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function freshIdentifier(seed: string): string {
|
|
262
|
+
const sanitized = sanitizeJavaScriptIdentifier(seed)
|
|
263
|
+
let candidate = sanitized
|
|
264
|
+
let suffix = 0
|
|
265
|
+
while (uniqueIdentifiers.has(candidate)) candidate = `${sanitized}${++suffix}`
|
|
266
|
+
uniqueIdentifiers.add(candidate)
|
|
267
|
+
return candidate
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function addImport(importDeclaration: string): void {
|
|
271
|
+
if (!artifacts.some((artifact) => artifact._tag === "Import" && artifact.importDeclaration === importDeclaration)) {
|
|
272
|
+
artifacts.push({ _tag: "Import", importDeclaration })
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function addSymbol(symbol: symbol): string {
|
|
277
|
+
const identifier = freshIdentifier("_symbol")
|
|
278
|
+
const key = globalThis.Symbol.keyFor(symbol)
|
|
279
|
+
const description = symbol.description
|
|
280
|
+
artifacts.push({
|
|
281
|
+
_tag: "Symbol",
|
|
282
|
+
identifier,
|
|
283
|
+
code: makeCode(
|
|
284
|
+
key === undefined
|
|
285
|
+
? `Symbol(${description === undefined ? "" : format(description)})`
|
|
286
|
+
: `Symbol.for(${format(key)})`,
|
|
287
|
+
`typeof ${identifier}`
|
|
288
|
+
)
|
|
289
|
+
})
|
|
290
|
+
return identifier
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function annotationSchemas(
|
|
294
|
+
representation: CheckRepresentationAnnotation | undefined,
|
|
295
|
+
path: Path
|
|
296
|
+
): ReadonlyArray<SchemaRepresentation.Code> {
|
|
297
|
+
return representation?.schemas?.map((schema, index) => recur(schema, [...path, "schemas", index])) ?? []
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function checkBrands(
|
|
301
|
+
check: SchemaRepresentation.Check
|
|
302
|
+
): ReadonlyArray<string> {
|
|
303
|
+
const own = InternalAnnotations.collectBrands(check.annotations)
|
|
304
|
+
if (
|
|
305
|
+
check._tag === "FilterGroup" &&
|
|
306
|
+
check.annotations?.toCode === undefined
|
|
307
|
+
) {
|
|
308
|
+
return [...own, ...check.checks.flatMap(checkBrands)]
|
|
309
|
+
}
|
|
310
|
+
return own
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function runtimeBrands(brands: ReadonlyArray<string>): string {
|
|
314
|
+
return brands.length === 0
|
|
315
|
+
? ""
|
|
316
|
+
: `.pipe(${brands.map((brand) => `Schema.brand(${format(brand)})`).join(", ")})`
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function typeBrands(brands: ReadonlyArray<string>): string {
|
|
320
|
+
if (brands.length === 0) return ""
|
|
321
|
+
addImport(`import type * as Brand from "effect/Brand"`)
|
|
322
|
+
return brands.map((brand) => ` & Brand.Brand<${format(brand)}>`).join("")
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function runtimeAnnotate(
|
|
326
|
+
annotations: Schema.Annotations.Annotations | undefined,
|
|
327
|
+
method: "annotate" | "annotateKey" = "annotate"
|
|
328
|
+
): string {
|
|
329
|
+
const rendered = renderAnnotations(annotations)
|
|
330
|
+
return rendered === undefined ? "" : `.${method}(${rendered})`
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function compileCheck(
|
|
334
|
+
check: SchemaRepresentation.Check,
|
|
335
|
+
path: Path
|
|
336
|
+
): string {
|
|
337
|
+
const callback = check.annotations?.toCode
|
|
338
|
+
let runtime: string
|
|
339
|
+
if (callback !== undefined) {
|
|
340
|
+
const schemas = annotationSchemas(check.representation, [...path, "representation"])
|
|
341
|
+
const output = (callback as SchemaRepresentation.Generation.Check)({ schemas })
|
|
342
|
+
for (const importDeclaration of output.importDeclarations ?? []) addImport(importDeclaration)
|
|
343
|
+
runtime = output.runtime
|
|
344
|
+
} else if (check._tag === "Filter") {
|
|
345
|
+
throw errorWithPath("Missing toCode callback", [...path, "annotations", "toCode"])
|
|
346
|
+
} else {
|
|
347
|
+
runtime = `Schema.makeFilterGroup([${
|
|
348
|
+
check.checks.map((child, index) => compileCheck(child, [...path, "checks", index])).join(", ")
|
|
349
|
+
}])`
|
|
350
|
+
}
|
|
351
|
+
runtime += runtimeAnnotate(check.annotations)
|
|
352
|
+
if (check._tag === "Filter" && check.aborted) runtime += ".abort()"
|
|
353
|
+
return runtime
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function applyNode(
|
|
357
|
+
base: SchemaRepresentation.Code,
|
|
358
|
+
representation: Exclude<SchemaRepresentation.Representation, SchemaRepresentation.Reference>,
|
|
359
|
+
path: Path,
|
|
360
|
+
includeTypeBrands: boolean = true
|
|
361
|
+
): SchemaRepresentation.Code {
|
|
362
|
+
const nodeBrands = InternalAnnotations.collectBrands(representation.annotations)
|
|
363
|
+
let runtime = base.runtime + runtimeAnnotate(representation.annotations) + runtimeBrands(nodeBrands)
|
|
364
|
+
let Type = base.Type + (includeTypeBrands ? typeBrands(nodeBrands) : "")
|
|
365
|
+
for (let index = 0; index < representation.checks.length; index++) {
|
|
366
|
+
const check = representation.checks[index]
|
|
367
|
+
const brands = checkBrands(check)
|
|
368
|
+
runtime += `.check(${compileCheck(check, [...path, "checks", index])})${runtimeBrands(brands)}`
|
|
369
|
+
if (includeTypeBrands) Type += typeBrands(brands)
|
|
370
|
+
}
|
|
371
|
+
return makeCode(runtime, Type)
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function recur(
|
|
375
|
+
representation: SchemaRepresentation.Representation,
|
|
376
|
+
path: Path,
|
|
377
|
+
includeTypeBrands: boolean = true
|
|
378
|
+
): SchemaRepresentation.Code {
|
|
379
|
+
if (representation._tag === "Reference") {
|
|
380
|
+
if (!Object.hasOwn(document.references, representation.$ref)) {
|
|
381
|
+
throw errorWithPath(`Invalid reference ${representation.$ref}`, [...path, "$ref"])
|
|
382
|
+
}
|
|
383
|
+
const identifier = ensureUniqueIdentifier(representation.$ref)
|
|
384
|
+
if (
|
|
385
|
+
compilingRecursiveDefinition && explicitSuspendDepth === 0 &&
|
|
386
|
+
Object.hasOwn(sorted.recursives, representation.$ref)
|
|
387
|
+
) {
|
|
388
|
+
return makeCode(`Schema.suspend((): Schema.Codec<${identifier}> => ${identifier})`, identifier)
|
|
389
|
+
}
|
|
390
|
+
const Type = includeTypeBrands
|
|
391
|
+
? identifier
|
|
392
|
+
: recur(document.references[representation.$ref], ["references", representation.$ref], false).Type
|
|
393
|
+
return makeCode(identifier, Type)
|
|
394
|
+
}
|
|
395
|
+
return applyNode(on(representation, path, includeTypeBrands), representation, path, includeTypeBrands)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function on(
|
|
399
|
+
representation: Exclude<SchemaRepresentation.Representation, SchemaRepresentation.Reference>,
|
|
400
|
+
path: Path,
|
|
401
|
+
includeTypeBrands: boolean
|
|
402
|
+
): SchemaRepresentation.Code {
|
|
403
|
+
switch (representation._tag) {
|
|
404
|
+
case "Declaration": {
|
|
405
|
+
const callback = representation.annotations?.toCode
|
|
406
|
+
if (callback === undefined) {
|
|
407
|
+
throw errorWithPath("Missing toCode callback", [...path, "annotations", "toCode"])
|
|
408
|
+
}
|
|
409
|
+
const typeParameters = representation.typeParameters.map((typeParameter, index) =>
|
|
410
|
+
recur(typeParameter, [...path, "typeParameters", index])
|
|
411
|
+
)
|
|
412
|
+
const output = (callback as SchemaRepresentation.Generation.Declaration)({ typeParameters })
|
|
413
|
+
for (const importDeclaration of output.importDeclarations ?? []) addImport(importDeclaration)
|
|
414
|
+
return makeCode(output.runtime, output.Type)
|
|
415
|
+
}
|
|
416
|
+
case "Suspend": {
|
|
417
|
+
explicitSuspendDepth++
|
|
418
|
+
const thunk = recur(representation.thunk, [...path, "thunk"])
|
|
419
|
+
explicitSuspendDepth--
|
|
420
|
+
return makeCode(`Schema.suspend((): Schema.Codec<${thunk.Type}> => ${thunk.runtime})`, thunk.Type)
|
|
421
|
+
}
|
|
422
|
+
case "Null":
|
|
423
|
+
return makeCode("Schema.Null", "null")
|
|
424
|
+
case "Undefined":
|
|
425
|
+
return makeCode("Schema.Undefined", "undefined")
|
|
426
|
+
case "Void":
|
|
427
|
+
return makeCode("Schema.Void", "void")
|
|
428
|
+
case "Never":
|
|
429
|
+
return makeCode("Schema.Never", "never")
|
|
430
|
+
case "Unknown":
|
|
431
|
+
return makeCode("Schema.Unknown", "unknown")
|
|
432
|
+
case "Any":
|
|
433
|
+
return makeCode("Schema.Any", "any")
|
|
434
|
+
case "String":
|
|
435
|
+
return makeCode("Schema.String", "string")
|
|
436
|
+
case "Number":
|
|
437
|
+
return makeCode("Schema.Number", "number")
|
|
438
|
+
case "Boolean":
|
|
439
|
+
return makeCode("Schema.Boolean", "boolean")
|
|
440
|
+
case "BigInt":
|
|
441
|
+
return makeCode("Schema.BigInt", "bigint")
|
|
442
|
+
case "Symbol":
|
|
443
|
+
return makeCode("Schema.Symbol", "symbol")
|
|
444
|
+
case "Literal": {
|
|
445
|
+
const literal = format(representation.literal)
|
|
446
|
+
return makeCode(`Schema.Literal(${literal})`, literal)
|
|
447
|
+
}
|
|
448
|
+
case "UniqueSymbol": {
|
|
449
|
+
const identifier = addSymbol(representation.symbol)
|
|
450
|
+
return makeCode(`Schema.UniqueSymbol(${identifier})`, `typeof ${identifier}`)
|
|
451
|
+
}
|
|
452
|
+
case "ObjectKeyword":
|
|
453
|
+
return makeCode("Schema.ObjectKeyword", "object")
|
|
454
|
+
case "Enum": {
|
|
455
|
+
const identifier = freshIdentifier("_Enum")
|
|
456
|
+
artifacts.push({
|
|
457
|
+
_tag: "Enum",
|
|
458
|
+
identifier,
|
|
459
|
+
code: makeCode(
|
|
460
|
+
`enum ${identifier} { ${
|
|
461
|
+
representation.enums.map(([name, value]) => `${format(name)} = ${format(value)}`).join(
|
|
462
|
+
", "
|
|
463
|
+
)
|
|
464
|
+
} }`,
|
|
465
|
+
`typeof ${identifier}`
|
|
466
|
+
)
|
|
467
|
+
})
|
|
468
|
+
return makeCode(`Schema.Enum(${identifier})`, identifier)
|
|
469
|
+
}
|
|
470
|
+
case "TemplateLiteral": {
|
|
471
|
+
const parts = representation.parts.map((part, index) => recur(part, [...path, "parts", index], false))
|
|
472
|
+
const Type = `\`${parts.map((part) => `\${${part.Type}}`).join("")}\``
|
|
473
|
+
return makeCode(`Schema.TemplateLiteral([${parts.map((part) => part.runtime).join(", ")}])`, Type)
|
|
474
|
+
}
|
|
475
|
+
case "Arrays": {
|
|
476
|
+
const elements = representation.elements.map((element, index) => {
|
|
477
|
+
const type = recur(element.type, [...path, "elements", index, "type"])
|
|
478
|
+
return makeCode(
|
|
479
|
+
`${element.isOptional ? "Schema.optionalKey(" : ""}${type.runtime}${element.isOptional ? ")" : ""}${
|
|
480
|
+
runtimeAnnotate(element.annotations, "annotateKey")
|
|
481
|
+
}`,
|
|
482
|
+
`${type.Type}${element.isOptional ? "?" : ""}`
|
|
483
|
+
)
|
|
484
|
+
})
|
|
485
|
+
const rest = representation.rest.map((item, index) => recur(item, [...path, "rest", index]))
|
|
486
|
+
if (Arr.isArrayNonEmpty(rest)) {
|
|
487
|
+
const item = rest[0]
|
|
488
|
+
if (elements.length === 0 && rest.length === 1) {
|
|
489
|
+
return makeCode(`Schema.Array(${item.runtime})`, `ReadonlyArray<${item.Type}>`)
|
|
490
|
+
}
|
|
491
|
+
const post = rest.slice(1)
|
|
492
|
+
return makeCode(
|
|
493
|
+
`Schema.TupleWithRest(Schema.Tuple([${elements.map((element) => element.runtime).join(", ")}]), [${
|
|
494
|
+
rest.map((item) => item.runtime).join(", ")
|
|
495
|
+
}])`,
|
|
496
|
+
`readonly [${elements.map((element) => element.Type).join(", ")}, ...Array<${item.Type}>${
|
|
497
|
+
post.length > 0 ? `, ${post.map((item) => item.Type).join(", ")}` : ""
|
|
498
|
+
}]`
|
|
499
|
+
)
|
|
500
|
+
}
|
|
501
|
+
return makeCode(
|
|
502
|
+
`Schema.Tuple([${elements.map((element) => element.runtime).join(", ")}])`,
|
|
503
|
+
`readonly [${elements.map((element) => element.Type).join(", ")}]`
|
|
504
|
+
)
|
|
505
|
+
}
|
|
506
|
+
case "Objects": {
|
|
507
|
+
const properties = representation.propertySignatures.map((property, index) => {
|
|
508
|
+
const isSymbol = typeof property.name === "symbol"
|
|
509
|
+
const name = isSymbol
|
|
510
|
+
? addSymbol(property.name)
|
|
511
|
+
: formatPropertyKey(property.name)
|
|
512
|
+
const type = recur(property.type, [...path, "propertySignatures", index, "type"])
|
|
513
|
+
let runtime = type.runtime
|
|
514
|
+
if (property.isMutable) runtime = `Schema.mutableKey(${runtime})`
|
|
515
|
+
if (property.isOptional) runtime = `Schema.optionalKey(${runtime})`
|
|
516
|
+
const runtimeName = isSymbol ? `[${name}]` : name
|
|
517
|
+
const typeName = `${property.isMutable ? "" : "readonly "}${runtimeName}${property.isOptional ? "?" : ""}`
|
|
518
|
+
return makeCode(
|
|
519
|
+
`${runtimeName}: ${runtime}${runtimeAnnotate(property.annotations, "annotateKey")}`,
|
|
520
|
+
`${typeName}: ${type.Type}`
|
|
521
|
+
)
|
|
522
|
+
})
|
|
523
|
+
const indexSignatures = representation.indexSignatures.map((signature, index) => ({
|
|
524
|
+
parameter: recur(signature.parameter, [...path, "indexSignatures", index, "parameter"]),
|
|
525
|
+
type: recur(signature.type, [...path, "indexSignatures", index, "type"])
|
|
526
|
+
}))
|
|
527
|
+
const propertyRuntimes = properties.map((property) => property.runtime).join(", ")
|
|
528
|
+
const propertyTypes = properties.map((property) => property.Type).join(", ")
|
|
529
|
+
if (indexSignatures.length === 0) {
|
|
530
|
+
return makeCode(
|
|
531
|
+
`Schema.Struct({ ${propertyRuntimes} })`,
|
|
532
|
+
`{ ${propertyTypes} }`
|
|
533
|
+
)
|
|
534
|
+
}
|
|
535
|
+
if (properties.length === 0 && indexSignatures.length === 1) {
|
|
536
|
+
const signature = indexSignatures[0]
|
|
537
|
+
return makeCode(
|
|
538
|
+
`Schema.Record(${signature.parameter.runtime}, ${signature.type.runtime})`,
|
|
539
|
+
`{ readonly [x: ${signature.parameter.Type}]: ${signature.type.Type} }`
|
|
540
|
+
)
|
|
541
|
+
}
|
|
542
|
+
const indexRuntimes = indexSignatures.map((signature) =>
|
|
543
|
+
`Schema.Record(${signature.parameter.runtime}, ${signature.type.runtime})`
|
|
544
|
+
).join(", ")
|
|
545
|
+
const indexTypes = indexSignatures.map((signature) =>
|
|
546
|
+
`readonly [x: ${signature.parameter.Type}]: ${signature.type.Type}`
|
|
547
|
+
).join(", ")
|
|
548
|
+
return makeCode(
|
|
549
|
+
`Schema.StructWithRest(Schema.Struct({ ${propertyRuntimes} }), [${indexRuntimes}])`,
|
|
550
|
+
`{ ${propertyTypes}${properties.length > 0 ? ", " : ""}${indexTypes} }`
|
|
551
|
+
)
|
|
552
|
+
}
|
|
553
|
+
case "Union": {
|
|
554
|
+
if (representation.types.length === 0) return makeCode("Schema.Never", "never")
|
|
555
|
+
if (representation.types.every(isSimpleLiveLiteral)) {
|
|
556
|
+
const literals = representation.types.map((literal) => format(literal.literal))
|
|
557
|
+
return literals.length === 1
|
|
558
|
+
? makeCode(`Schema.Literal(${literals[0]})`, literals[0])
|
|
559
|
+
: makeCode(`Schema.Literals([${literals.join(", ")}])`, literals.join(" | "))
|
|
560
|
+
}
|
|
561
|
+
const types = representation.types.map((type, index) =>
|
|
562
|
+
recur(type, [...path, "types", index], includeTypeBrands)
|
|
563
|
+
)
|
|
564
|
+
const mode = representation.mode === "anyOf" ? "" : `, { mode: "oneOf" }`
|
|
565
|
+
return makeCode(
|
|
566
|
+
`Schema.Union([${types.map((type) => type.runtime).join(", ")}]${mode})`,
|
|
567
|
+
types.map((type) => type.Type).join(" | ")
|
|
568
|
+
)
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
@@ -5,7 +5,6 @@ import * as Predicate from "../../Predicate.ts"
|
|
|
5
5
|
import type * as Schema from "../../Schema.ts"
|
|
6
6
|
import * as SchemaAST from "../../SchemaAST.ts"
|
|
7
7
|
import * as SchemaParser from "../../SchemaParser.ts"
|
|
8
|
-
import { errorWithPath } from "../errors.ts"
|
|
9
8
|
import * as InternalAnnotations from "./annotations.ts"
|
|
10
9
|
|
|
11
10
|
/** @internal */
|
|
@@ -25,7 +24,7 @@ function recur(ast: SchemaAST.AST, path: ReadonlyArray<PropertyKey>): Equivalenc
|
|
|
25
24
|
}
|
|
26
25
|
switch (ast._tag) {
|
|
27
26
|
case "Never":
|
|
28
|
-
|
|
27
|
+
return Equivalence.strictEqual()
|
|
29
28
|
case "Declaration":
|
|
30
29
|
case "Null":
|
|
31
30
|
case "Undefined":
|
|
@@ -133,18 +132,24 @@ function recur(ast: SchemaAST.AST, path: ReadonlyArray<PropertyKey>): Equivalenc
|
|
|
133
132
|
return true
|
|
134
133
|
})
|
|
135
134
|
}
|
|
136
|
-
case "Union":
|
|
135
|
+
case "Union": {
|
|
136
|
+
const types = SchemaAST.toType(ast).types
|
|
137
|
+
const compiled = new Map(
|
|
138
|
+
types.map((candidate, i) =>
|
|
139
|
+
[candidate, [SchemaParser._is(candidate), recur(ast.types[i], path)] as const] as const
|
|
140
|
+
)
|
|
141
|
+
)
|
|
137
142
|
return Equivalence.make((a, b) => {
|
|
138
|
-
const candidates = SchemaAST.getCandidates(a,
|
|
139
|
-
const types = candidates.map(SchemaParser._is)
|
|
143
|
+
const candidates = SchemaAST.getCandidates(a, types)
|
|
140
144
|
for (let i = 0; i < candidates.length; i++) {
|
|
141
|
-
const is =
|
|
145
|
+
const [is, equivalence] = compiled.get(candidates[i])!
|
|
142
146
|
if (is(a) && is(b)) {
|
|
143
|
-
return
|
|
147
|
+
return equivalence(a, b)
|
|
144
148
|
}
|
|
145
149
|
}
|
|
146
150
|
return false
|
|
147
151
|
})
|
|
152
|
+
}
|
|
148
153
|
case "Suspend": {
|
|
149
154
|
const get = SchemaAST.memoizeThunk(() => recur(ast.thunk(), path))
|
|
150
155
|
return Equivalence.make((a, b) => get()(a, b))
|