effect 4.0.7 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/BigDecimal.d.ts.map +1 -1
- package/dist/BigDecimal.js +3 -0
- package/dist/BigDecimal.js.map +1 -1
- package/dist/Channel.d.ts +12 -6
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +9 -3
- package/dist/Channel.js.map +1 -1
- package/dist/Config.d.ts +7 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js.map +1 -1
- package/dist/Context.d.ts +18 -1
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +27 -8
- package/dist/Context.js.map +1 -1
- package/dist/Cron.d.ts +81 -11
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +101 -26
- package/dist/Cron.js.map +1 -1
- package/dist/Duration.d.ts +78 -0
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +123 -0
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +164 -7
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +11 -1
- package/dist/Effect.js.map +1 -1
- package/dist/FileSystem.d.ts +59 -4
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +9 -2
- package/dist/FileSystem.js.map +1 -1
- package/dist/Glob.d.ts +165 -0
- package/dist/Glob.d.ts.map +1 -0
- package/dist/Glob.js +127 -0
- package/dist/Glob.js.map +1 -0
- package/dist/Match.d.ts +86 -0
- package/dist/Match.d.ts.map +1 -1
- package/dist/Match.js +72 -0
- package/dist/Match.js.map +1 -1
- package/dist/Pool.d.ts +51 -0
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +59 -9
- package/dist/Pool.js.map +1 -1
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +3 -3
- package/dist/Random.js.map +1 -1
- package/dist/RcMap.d.ts.map +1 -1
- package/dist/RcMap.js +8 -2
- package/dist/RcMap.js.map +1 -1
- package/dist/Schedule.d.ts +18 -1
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +7 -2
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +666 -41
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +650 -0
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaGetter.d.ts +6 -1
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +22 -11
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +14 -0
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +16 -0
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +8 -3
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +6 -3
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +5 -7
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Semaphore.d.ts +130 -0
- package/dist/Semaphore.d.ts.map +1 -1
- package/dist/Semaphore.js +40 -0
- package/dist/Semaphore.js.map +1 -1
- package/dist/Stream.d.ts +13 -4
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +9 -0
- package/dist/Stream.js.map +1 -1
- package/dist/Terminal.d.ts +18 -1
- package/dist/Terminal.d.ts.map +1 -1
- package/dist/Terminal.js +1 -1
- package/dist/Terminal.js.map +1 -1
- package/dist/ai/AiError.d.ts +43 -116
- package/dist/ai/AiError.d.ts.map +1 -1
- package/dist/ai/AiError.js +53 -72
- package/dist/ai/AiError.js.map +1 -1
- package/dist/ai/Decision.d.ts +196 -15
- package/dist/ai/Decision.d.ts.map +1 -1
- package/dist/ai/Decision.js +130 -0
- package/dist/ai/Decision.js.map +1 -1
- package/dist/ai/DecisionModel.d.ts +54 -13
- package/dist/ai/DecisionModel.d.ts.map +1 -1
- package/dist/ai/DecisionModel.js +123 -12
- package/dist/ai/DecisionModel.js.map +1 -1
- package/dist/ai/McpServer.d.ts +630 -29
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +562 -116
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/McpTest.d.ts +130 -0
- package/dist/ai/McpTest.d.ts.map +1 -0
- package/dist/ai/McpTest.js +237 -0
- package/dist/ai/McpTest.js.map +1 -0
- package/dist/ai/Response.d.ts +1 -25
- package/dist/ai/Response.d.ts.map +1 -1
- package/dist/ai/Response.js +1 -10
- package/dist/ai/Response.js.map +1 -1
- package/dist/ai/Tool.d.ts +19 -1
- package/dist/ai/Tool.d.ts.map +1 -1
- package/dist/ai/Tool.js.map +1 -1
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/internal/mcpCore.js +17 -12
- package/dist/ai/internal/mcpCore.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js +4 -5
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js +4 -5
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js +4 -5
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js +4 -5
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2026_07_28.js +18 -10
- package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
- package/dist/ai/internal/mcpProtocol.js +13 -0
- package/dist/ai/internal/mcpProtocol.js.map +1 -1
- package/dist/ai/internal/mcpRuntime.js +5 -3
- package/dist/ai/internal/mcpRuntime.js.map +1 -1
- package/dist/ai/internal/mcpStatefulRuntime.js +6 -1
- package/dist/ai/internal/mcpStatefulRuntime.js.map +1 -1
- package/dist/cli/Argument.d.ts +6 -0
- package/dist/cli/Argument.d.ts.map +1 -1
- package/dist/cli/Argument.js +2 -0
- package/dist/cli/Argument.js.map +1 -1
- package/dist/cli/CliOutput.d.ts +65 -1
- package/dist/cli/CliOutput.d.ts.map +1 -1
- package/dist/cli/CliOutput.js +94 -37
- package/dist/cli/CliOutput.js.map +1 -1
- package/dist/cli/Command.d.ts +23 -0
- package/dist/cli/Command.d.ts.map +1 -1
- package/dist/cli/Command.js +8 -0
- package/dist/cli/Command.js.map +1 -1
- package/dist/cli/Flag.d.ts +107 -0
- package/dist/cli/Flag.d.ts.map +1 -1
- package/dist/cli/Flag.js +37 -0
- package/dist/cli/Flag.js.map +1 -1
- package/dist/cli/HelpDoc.d.ts +15 -1
- package/dist/cli/HelpDoc.d.ts.map +1 -1
- package/dist/cli/Param.d.ts +6 -0
- package/dist/cli/Param.d.ts.map +1 -1
- package/dist/cli/Param.js +2 -0
- package/dist/cli/Param.js.map +1 -1
- package/dist/cli/Primitive.d.ts +14 -0
- package/dist/cli/Primitive.d.ts.map +1 -1
- package/dist/cli/Primitive.js +15 -1
- package/dist/cli/Primitive.js.map +1 -1
- package/dist/cli/Prompt.d.ts +1 -0
- package/dist/cli/Prompt.d.ts.map +1 -1
- package/dist/cli/Prompt.js +1 -0
- package/dist/cli/Prompt.js.map +1 -1
- package/dist/cli/internal/help.d.ts.map +1 -1
- package/dist/cli/internal/help.js +17 -10
- package/dist/cli/internal/help.js.map +1 -1
- package/dist/cluster/Sharding.d.ts.map +1 -1
- package/dist/cluster/Sharding.js +90 -28
- package/dist/cluster/Sharding.js.map +1 -1
- package/dist/cluster/ShardingConfig.d.ts +72 -6
- package/dist/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/cluster/ShardingConfig.js +4 -0
- package/dist/cluster/ShardingConfig.js.map +1 -1
- package/dist/cluster/SingleRunner.d.ts +3 -3
- package/dist/cluster/SingleRunner.d.ts.map +1 -1
- package/dist/cluster/SingleRunner.js +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts +37 -6
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +34 -7
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
- package/dist/cluster/SqlRunnerStorage.js +23 -8
- package/dist/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/crypto/Aead.d.ts +322 -0
- package/dist/crypto/Aead.d.ts.map +1 -0
- package/dist/crypto/Aead.js +331 -0
- package/dist/crypto/Aead.js.map +1 -0
- package/dist/crypto/Cipher.d.ts +235 -0
- package/dist/crypto/Cipher.d.ts.map +1 -0
- package/dist/crypto/Cipher.js +233 -0
- package/dist/crypto/Cipher.js.map +1 -0
- package/dist/crypto/CryptoError.d.ts +212 -0
- package/dist/crypto/CryptoError.d.ts.map +1 -0
- package/dist/crypto/CryptoError.js +202 -0
- package/dist/crypto/CryptoError.js.map +1 -0
- package/dist/crypto/Digest.d.ts +143 -0
- package/dist/crypto/Digest.d.ts.map +1 -0
- package/dist/crypto/Digest.js +146 -0
- package/dist/crypto/Digest.js.map +1 -0
- package/dist/crypto/Kdf.d.ts +220 -0
- package/dist/crypto/Kdf.d.ts.map +1 -0
- package/dist/crypto/Kdf.js +212 -0
- package/dist/crypto/Kdf.js.map +1 -0
- package/dist/crypto/KeyAgreement.d.ts +323 -0
- package/dist/crypto/KeyAgreement.d.ts.map +1 -0
- package/dist/crypto/KeyAgreement.js +303 -0
- package/dist/crypto/KeyAgreement.js.map +1 -0
- package/dist/crypto/KeyFormat.d.ts +309 -0
- package/dist/crypto/KeyFormat.d.ts.map +1 -0
- package/dist/crypto/KeyFormat.js +556 -0
- package/dist/crypto/KeyFormat.js.map +1 -0
- package/dist/crypto/KeyWrap.d.ts +389 -0
- package/dist/crypto/KeyWrap.d.ts.map +1 -0
- package/dist/crypto/KeyWrap.js +381 -0
- package/dist/crypto/KeyWrap.js.map +1 -0
- package/dist/crypto/Mac.d.ts +277 -0
- package/dist/crypto/Mac.d.ts.map +1 -0
- package/dist/crypto/Mac.js +288 -0
- package/dist/crypto/Mac.js.map +1 -0
- package/dist/crypto/SecureRandom.d.ts +340 -0
- package/dist/crypto/SecureRandom.d.ts.map +1 -0
- package/dist/crypto/SecureRandom.js +257 -0
- package/dist/crypto/SecureRandom.js.map +1 -0
- package/dist/crypto/Signature.d.ts +448 -0
- package/dist/crypto/Signature.d.ts.map +1 -0
- package/dist/crypto/Signature.js +484 -0
- package/dist/crypto/Signature.js.map +1 -0
- package/dist/crypto/WebCrypto.d.ts +61 -0
- package/dist/crypto/WebCrypto.d.ts.map +1 -0
- package/dist/crypto/WebCrypto.js +63 -0
- package/dist/crypto/WebCrypto.js.map +1 -0
- package/dist/crypto/index.d.ts +65 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +66 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/internal/asymmetric.d.ts +2 -0
- package/dist/crypto/internal/asymmetric.d.ts.map +1 -0
- package/dist/crypto/internal/asymmetric.js +210 -0
- package/dist/crypto/internal/asymmetric.js.map +1 -0
- package/dist/crypto/internal/chacha.d.ts +46 -0
- package/dist/crypto/internal/chacha.d.ts.map +1 -0
- package/dist/crypto/internal/chacha.js +885 -0
- package/dist/crypto/internal/chacha.js.map +1 -0
- package/dist/crypto/internal/der.d.ts +6 -0
- package/dist/crypto/internal/der.d.ts.map +1 -0
- package/dist/crypto/internal/der.js +86 -0
- package/dist/crypto/internal/der.js.map +1 -0
- package/dist/crypto/internal/digest.d.ts +2 -0
- package/dist/crypto/internal/digest.d.ts.map +1 -0
- package/dist/crypto/internal/digest.js +15 -0
- package/dist/crypto/internal/digest.js.map +1 -0
- package/dist/crypto/internal/key.d.ts +2 -0
- package/dist/crypto/internal/key.d.ts.map +1 -0
- package/dist/crypto/internal/key.js +170 -0
- package/dist/crypto/internal/key.js.map +1 -0
- package/dist/crypto/internal/md5.d.ts +39 -0
- package/dist/crypto/internal/md5.d.ts.map +1 -0
- package/dist/crypto/internal/md5.js +179 -0
- package/dist/crypto/internal/md5.js.map +1 -0
- package/dist/crypto/internal/webCrypto.d.ts +2 -0
- package/dist/crypto/internal/webCrypto.d.ts.map +1 -0
- package/dist/crypto/internal/webCrypto.js +111 -0
- package/dist/crypto/internal/webCrypto.js.map +1 -0
- package/dist/encoding/Base64Url.d.ts.map +1 -1
- package/dist/encoding/Base64Url.js +3 -2
- package/dist/encoding/Base64Url.js.map +1 -1
- package/dist/encoding/Csv.d.ts +608 -0
- package/dist/encoding/Csv.d.ts.map +1 -0
- package/dist/encoding/Csv.js +718 -0
- package/dist/encoding/Csv.js.map +1 -0
- package/dist/encoding/Hex.d.ts +3 -2
- package/dist/encoding/Hex.d.ts.map +1 -1
- package/dist/encoding/Hex.js +3 -2
- package/dist/encoding/Hex.js.map +1 -1
- package/dist/encoding/SchemaBinary.d.ts.map +1 -1
- package/dist/encoding/SchemaBinary.js +42 -4
- package/dist/encoding/SchemaBinary.js.map +1 -1
- package/dist/encoding/Toml.d.ts +17 -3
- package/dist/encoding/Toml.d.ts.map +1 -1
- package/dist/encoding/Toml.js +104 -16
- package/dist/encoding/Toml.js.map +1 -1
- package/dist/encoding/Yaml.d.ts +8 -1
- package/dist/encoding/Yaml.d.ts.map +1 -1
- package/dist/encoding/Yaml.js +54 -18
- package/dist/encoding/Yaml.js.map +1 -1
- package/dist/encoding/index.d.ts +5 -0
- package/dist/encoding/index.d.ts.map +1 -1
- package/dist/encoding/index.js +5 -0
- package/dist/encoding/index.js.map +1 -1
- package/dist/eventlog/EventJournal.d.ts.map +1 -1
- package/dist/eventlog/EventJournal.js +6 -3
- package/dist/eventlog/EventJournal.js.map +1 -1
- package/dist/eventlog/EventLog.d.ts +119 -4
- package/dist/eventlog/EventLog.d.ts.map +1 -1
- package/dist/eventlog/EventLog.js +200 -12
- package/dist/eventlog/EventLog.js.map +1 -1
- package/dist/eventlog/EventLogEncryption.d.ts +41 -4
- package/dist/eventlog/EventLogEncryption.d.ts.map +1 -1
- package/dist/eventlog/EventLogEncryption.js +83 -64
- package/dist/eventlog/EventLogEncryption.js.map +1 -1
- package/dist/eventlog/EventLogMessage.d.ts +279 -0
- package/dist/eventlog/EventLogMessage.d.ts.map +1 -1
- package/dist/eventlog/EventLogMessage.js +217 -1
- package/dist/eventlog/EventLogMessage.js.map +1 -1
- package/dist/eventlog/EventLogRemote.d.ts +200 -28
- package/dist/eventlog/EventLogRemote.d.ts.map +1 -1
- package/dist/eventlog/EventLogRemote.js +186 -16
- package/dist/eventlog/EventLogRemote.js.map +1 -1
- package/dist/eventlog/EventLogServer.d.ts +3 -0
- package/dist/eventlog/EventLogServer.d.ts.map +1 -1
- package/dist/eventlog/EventLogServer.js +18 -10
- package/dist/eventlog/EventLogServer.js.map +1 -1
- package/dist/eventlog/EventLogServerEncrypted.d.ts +326 -5
- package/dist/eventlog/EventLogServerEncrypted.d.ts.map +1 -1
- package/dist/eventlog/EventLogServerEncrypted.js +769 -14
- package/dist/eventlog/EventLogServerEncrypted.js.map +1 -1
- package/dist/eventlog/EventLogSessionAuth.d.ts +5 -3
- package/dist/eventlog/EventLogSessionAuth.d.ts.map +1 -1
- package/dist/eventlog/EventLogSessionAuth.js +41 -64
- package/dist/eventlog/EventLogSessionAuth.js.map +1 -1
- package/dist/eventlog/EventRow.d.ts +4 -0
- package/dist/eventlog/EventRow.d.ts.map +1 -1
- package/dist/eventlog/EventRow.js +12 -2
- package/dist/eventlog/EventRow.js.map +1 -1
- package/dist/eventlog/SqlEventJournal.js +2 -2
- package/dist/eventlog/SqlEventJournal.js.map +1 -1
- package/dist/eventlog/SqlEventLogServerEncrypted.d.ts +21 -5
- package/dist/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
- package/dist/eventlog/SqlEventLogServerEncrypted.js +1048 -113
- package/dist/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
- package/dist/eventlog/SqlEventLogServerUnencrypted.js +2 -2
- package/dist/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
- package/dist/eventlog/internal/batches.d.ts +12 -0
- package/dist/eventlog/internal/batches.d.ts.map +1 -0
- package/dist/eventlog/internal/batches.js +26 -0
- package/dist/eventlog/internal/batches.js.map +1 -0
- package/dist/eventlog/internal/compaction.d.ts +38 -0
- package/dist/eventlog/internal/compaction.d.ts.map +1 -0
- package/dist/eventlog/internal/compaction.js +33 -0
- package/dist/eventlog/internal/compaction.js.map +1 -0
- package/dist/eventlog/internal/identityRootSecretDerivation.js +66 -67
- package/dist/eventlog/internal/identityRootSecretDerivation.js.map +1 -1
- package/dist/eventlog/internal/remoteCompaction.d.ts +31 -0
- package/dist/eventlog/internal/remoteCompaction.d.ts.map +1 -0
- package/dist/eventlog/internal/remoteCompaction.js +76 -0
- package/dist/eventlog/internal/remoteCompaction.js.map +1 -0
- package/dist/http/Cookies.d.ts +172 -0
- package/dist/http/Cookies.d.ts.map +1 -1
- package/dist/http/Cookies.js +143 -1
- package/dist/http/Cookies.js.map +1 -1
- package/dist/http/FetchHttpClient.d.ts +26 -2
- package/dist/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/http/FetchHttpClient.js +78 -15
- package/dist/http/FetchHttpClient.js.map +1 -1
- package/dist/http/HttpClient.d.ts +79 -8
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpClient.js +65 -5
- package/dist/http/HttpClient.js.map +1 -1
- package/dist/http/HttpClientRequest.d.ts +9 -5
- package/dist/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/http/HttpClientRequest.js +2 -3
- package/dist/http/HttpClientRequest.js.map +1 -1
- package/dist/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/http/HttpClientResponse.js +3 -2
- package/dist/http/HttpClientResponse.js.map +1 -1
- package/dist/http/HttpMethod.d.ts +7 -1
- package/dist/http/HttpMethod.d.ts.map +1 -1
- package/dist/http/HttpMethod.js +3 -8
- package/dist/http/HttpMethod.js.map +1 -1
- package/dist/http/HttpServerRequest.d.ts +5 -2
- package/dist/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/http/HttpServerRequest.js +6 -17
- package/dist/http/HttpServerRequest.js.map +1 -1
- package/dist/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/http/HttpServerResponse.js +3 -2
- package/dist/http/HttpServerResponse.js.map +1 -1
- package/dist/http/HttpTraceContext.d.ts +2 -1
- package/dist/http/HttpTraceContext.d.ts.map +1 -1
- package/dist/http/HttpTraceContext.js +7 -5
- package/dist/http/HttpTraceContext.js.map +1 -1
- package/dist/http/ProblemDetails.d.ts +96 -0
- package/dist/http/ProblemDetails.d.ts.map +1 -0
- package/dist/http/ProblemDetails.js +98 -0
- package/dist/http/ProblemDetails.js.map +1 -0
- package/dist/http/index.d.ts +5 -0
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +5 -0
- package/dist/http/index.js.map +1 -1
- package/dist/http/internal/decompression.js +3 -2
- package/dist/http/internal/decompression.js.map +1 -1
- package/dist/http/internal/urlParams.js +8 -0
- package/dist/http/internal/urlParams.js.map +1 -1
- package/dist/http-api/HttpApiBuilder.js +19 -5
- package/dist/http-api/HttpApiBuilder.js.map +1 -1
- package/dist/http-api/HttpApiClient.d.ts +63 -0
- package/dist/http-api/HttpApiClient.d.ts.map +1 -1
- package/dist/http-api/HttpApiClient.js +51 -0
- package/dist/http-api/HttpApiClient.js.map +1 -1
- package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/http-api/HttpApiEndpoint.js +14 -5
- package/dist/http-api/HttpApiEndpoint.js.map +1 -1
- package/dist/http-api/HttpApiError.d.ts +185 -13
- package/dist/http-api/HttpApiError.d.ts.map +1 -1
- package/dist/http-api/HttpApiError.js +128 -0
- package/dist/http-api/HttpApiError.js.map +1 -1
- package/dist/http-api/HttpApiMiddleware.d.ts +64 -17
- package/dist/http-api/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/http-api/HttpApiMiddleware.js +85 -1
- package/dist/http-api/HttpApiMiddleware.js.map +1 -1
- package/dist/http-api/HttpApiSchema.d.ts +76 -14
- package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
- package/dist/http-api/HttpApiSchema.js +53 -0
- package/dist/http-api/HttpApiSchema.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +25 -14
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/glob.d.ts +2 -0
- package/dist/internal/glob.d.ts.map +1 -0
- package/dist/internal/glob.js +630 -0
- package/dist/internal/glob.js.map +1 -0
- package/dist/internal/matcher.js +10 -0
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/persistence.js +9 -0
- package/dist/internal/persistence.js.map +1 -1
- package/dist/internal/rcRef.js +4 -1
- package/dist/internal/rcRef.js.map +1 -1
- package/dist/internal/schema/toCodeDocument.js +6 -3
- package/dist/internal/schema/toCodeDocument.js.map +1 -1
- package/dist/internal/trie.js +42 -13
- package/dist/internal/trie.js.map +1 -1
- package/dist/internal/ulid.js +41 -0
- package/dist/internal/ulid.js.map +1 -1
- package/dist/internal/uuid.js +52 -8
- package/dist/internal/uuid.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/observability/Otlp.d.ts +15 -4
- package/dist/observability/Otlp.d.ts.map +1 -1
- package/dist/observability/Otlp.js +10 -0
- package/dist/observability/Otlp.js.map +1 -1
- package/dist/observability/OtlpResource.d.ts +7 -0
- package/dist/observability/OtlpResource.d.ts.map +1 -1
- package/dist/observability/OtlpResource.js +11 -1
- package/dist/observability/OtlpResource.js.map +1 -1
- package/dist/persistence/KeyValueStore.d.ts +47 -2
- package/dist/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/persistence/KeyValueStore.js +129 -18
- package/dist/persistence/KeyValueStore.js.map +1 -1
- package/dist/persistence/PersistedQueue.d.ts +9 -0
- package/dist/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/persistence/PersistedQueue.js +94 -52
- package/dist/persistence/PersistedQueue.js.map +1 -1
- package/dist/persistence/Persistence.d.ts +10 -4
- package/dist/persistence/Persistence.d.ts.map +1 -1
- package/dist/persistence/Persistence.js +18 -11
- package/dist/persistence/Persistence.js.map +1 -1
- package/dist/process/ChildProcess.d.ts +207 -67
- package/dist/process/ChildProcess.d.ts.map +1 -1
- package/dist/process/ChildProcess.js +56 -158
- package/dist/process/ChildProcess.js.map +1 -1
- package/dist/process/ChildProcessSpawner.d.ts +5 -0
- package/dist/process/ChildProcessSpawner.d.ts.map +1 -1
- package/dist/process/ChildProcessSpawner.js.map +1 -1
- package/dist/process/CommandLine.d.ts +294 -0
- package/dist/process/CommandLine.d.ts.map +1 -0
- package/dist/process/CommandLine.js +481 -0
- package/dist/process/CommandLine.js.map +1 -0
- package/dist/process/index.d.ts +5 -0
- package/dist/process/index.d.ts.map +1 -1
- package/dist/process/index.js +5 -0
- package/dist/process/index.js.map +1 -1
- package/dist/reactivity/Atom.d.ts +2 -1
- package/dist/reactivity/Atom.d.ts.map +1 -1
- package/dist/reactivity/Atom.js +3 -4
- package/dist/reactivity/Atom.js.map +1 -1
- package/dist/reactivity/AtomRegistry.js.map +1 -1
- package/dist/rpc/RpcClient.d.ts +16 -1
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js +50 -16
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcMessage.d.ts +10 -1
- package/dist/rpc/RpcMessage.d.ts.map +1 -1
- package/dist/rpc/RpcMessage.js +1 -0
- package/dist/rpc/RpcMessage.js.map +1 -1
- package/dist/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/rpc/RpcSerialization.js +6 -0
- package/dist/rpc/RpcSerialization.js.map +1 -1
- package/dist/rpc/RpcServer.d.ts +31 -0
- package/dist/rpc/RpcServer.d.ts.map +1 -1
- package/dist/rpc/RpcServer.js +139 -66
- package/dist/rpc/RpcServer.js.map +1 -1
- package/dist/schema/Model.d.ts +14 -0
- package/dist/schema/Model.d.ts.map +1 -1
- package/dist/schema/Model.js +18 -3
- package/dist/schema/Model.js.map +1 -1
- package/dist/sql/Migrator.d.ts +0 -19
- package/dist/sql/Migrator.d.ts.map +1 -1
- package/dist/sql/Migrator.js +3 -48
- package/dist/sql/Migrator.js.map +1 -1
- package/dist/sql/MigratorFileSystem.d.ts +21 -0
- package/dist/sql/MigratorFileSystem.d.ts.map +1 -0
- package/dist/sql/MigratorFileSystem.js +57 -0
- package/dist/sql/MigratorFileSystem.js.map +1 -0
- package/dist/sql/SqlClient.d.ts.map +1 -1
- package/dist/sql/SqlClient.js +5 -9
- package/dist/sql/SqlClient.js.map +1 -1
- package/dist/sql/Statement.d.ts +20 -6
- package/dist/sql/Statement.d.ts.map +1 -1
- package/dist/sql/Statement.js +0 -13
- package/dist/sql/Statement.js.map +1 -1
- package/dist/sql/index.js +1 -1
- package/dist/testing/index.d.ts +0 -5
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +0 -5
- package/dist/testing/index.js.map +1 -1
- package/dist/workflow/internal/crypto.js +9 -8
- package/dist/workflow/internal/crypto.js.map +1 -1
- package/package.json +3 -1
- package/src/BigDecimal.ts +3 -0
- package/src/Channel.ts +17 -11
- package/src/Config.ts +7 -1
- package/src/Context.ts +34 -10
- package/src/Cron.ts +178 -29
- package/src/Duration.ts +140 -0
- package/src/Effect.ts +914 -85
- package/src/FileSystem.ts +65 -4
- package/src/Glob.ts +205 -0
- package/src/Match.ts +127 -0
- package/src/Pool.ts +73 -15
- package/src/Random.ts +3 -3
- package/src/RcMap.ts +5 -1
- package/src/Schedule.ts +26 -3
- package/src/Schema.ts +1189 -62
- package/src/SchemaGetter.ts +27 -11
- package/src/SchemaRepresentation.ts +19 -0
- package/src/SchemaTransformation.ts +8 -3
- package/src/ScopedCache.ts +5 -9
- package/src/Semaphore.ts +141 -0
- package/src/Stream.ts +15 -6
- package/src/Terminal.ts +19 -1
- package/src/ai/AiError.ts +56 -80
- package/src/ai/Decision.ts +257 -6
- package/src/ai/DecisionModel.ts +171 -28
- package/src/ai/McpServer.ts +1269 -286
- package/src/ai/McpTest.ts +380 -0
- package/src/ai/Response.ts +2 -22
- package/src/ai/Tool.ts +27 -8
- package/src/ai/index.ts +6 -0
- package/src/ai/internal/mcpCore.ts +78 -44
- package/src/ai/internal/mcpProtocol/v2024_11_05.ts +4 -7
- package/src/ai/internal/mcpProtocol/v2025_03_26.ts +4 -7
- package/src/ai/internal/mcpProtocol/v2025_06_18.ts +4 -7
- package/src/ai/internal/mcpProtocol/v2025_11_25.ts +4 -7
- package/src/ai/internal/mcpProtocol/v2026_07_28.ts +15 -10
- package/src/ai/internal/mcpProtocol.ts +29 -0
- package/src/ai/internal/mcpRuntime.ts +9 -5
- package/src/ai/internal/mcpStatefulRuntime.ts +14 -2
- package/src/cli/Argument.ts +6 -0
- package/src/cli/CliOutput.ts +117 -49
- package/src/cli/Command.ts +23 -0
- package/src/cli/Flag.ts +107 -0
- package/src/cli/HelpDoc.ts +18 -1
- package/src/cli/Param.ts +6 -0
- package/src/cli/Primitive.ts +16 -1
- package/src/cli/Prompt.ts +1 -0
- package/src/cli/internal/help.ts +21 -9
- package/src/cluster/Sharding.ts +93 -26
- package/src/cluster/ShardingConfig.ts +41 -3
- package/src/cluster/SingleRunner.ts +3 -3
- package/src/cluster/SqlMessageStorage.ts +49 -17
- package/src/cluster/SqlRunnerStorage.ts +37 -27
- package/src/crypto/Aead.ts +517 -0
- package/src/crypto/Cipher.ts +326 -0
- package/src/crypto/CryptoError.ts +242 -0
- package/src/crypto/Digest.ts +167 -0
- package/src/crypto/Kdf.ts +315 -0
- package/src/crypto/KeyAgreement.ts +489 -0
- package/src/crypto/KeyFormat.ts +712 -0
- package/src/crypto/KeyWrap.ts +639 -0
- package/src/crypto/Mac.ts +386 -0
- package/src/crypto/SecureRandom.ts +459 -0
- package/src/crypto/Signature.ts +673 -0
- package/src/crypto/WebCrypto.ts +64 -0
- package/src/crypto/index.ts +78 -0
- package/src/crypto/internal/asymmetric.ts +329 -0
- package/src/crypto/internal/chacha.ts +1088 -0
- package/src/crypto/internal/der.ts +110 -0
- package/src/crypto/internal/digest.ts +16 -0
- package/src/crypto/internal/key.ts +235 -0
- package/src/crypto/internal/md5.ts +170 -0
- package/src/crypto/internal/webCrypto.ts +150 -0
- package/src/encoding/Base64Url.ts +5 -2
- package/src/encoding/Csv.ts +1298 -0
- package/src/encoding/Hex.ts +3 -2
- package/src/encoding/SchemaBinary.ts +40 -4
- package/src/encoding/Toml.ts +85 -20
- package/src/encoding/Yaml.ts +61 -18
- package/src/encoding/index.ts +6 -0
- package/src/eventlog/EventJournal.ts +4 -3
- package/src/eventlog/EventLog.ts +340 -15
- package/src/eventlog/EventLogEncryption.ts +118 -110
- package/src/eventlog/EventLogMessage.ts +273 -1
- package/src/eventlog/EventLogRemote.ts +367 -23
- package/src/eventlog/EventLogServer.ts +23 -8
- package/src/eventlog/EventLogServerEncrypted.ts +1130 -67
- package/src/eventlog/EventLogSessionAuth.ts +56 -70
- package/src/eventlog/EventRow.ts +12 -3
- package/src/eventlog/SqlEventJournal.ts +2 -2
- package/src/eventlog/SqlEventLogServerEncrypted.ts +1244 -136
- package/src/eventlog/SqlEventLogServerUnencrypted.ts +2 -2
- package/src/eventlog/internal/batches.ts +30 -0
- package/src/eventlog/internal/compaction.ts +64 -0
- package/src/eventlog/internal/identityRootSecretDerivation.ts +93 -123
- package/src/eventlog/internal/remoteCompaction.ts +92 -0
- package/src/http/Cookies.ts +281 -1
- package/src/http/FetchHttpClient.ts +88 -16
- package/src/http/HttpClient.ts +89 -22
- package/src/http/HttpClientRequest.ts +12 -9
- package/src/http/HttpClientResponse.ts +3 -2
- package/src/http/HttpMethod.ts +10 -2
- package/src/http/HttpServerRequest.ts +15 -30
- package/src/http/HttpServerResponse.ts +3 -2
- package/src/http/HttpTraceContext.ts +7 -4
- package/src/http/ProblemDetails.ts +149 -0
- package/src/http/index.ts +6 -0
- package/src/http/internal/decompression.ts +4 -4
- package/src/http/internal/urlParams.ts +8 -0
- package/src/http-api/HttpApiBuilder.ts +24 -12
- package/src/http-api/HttpApiClient.ts +67 -1
- package/src/http-api/HttpApiEndpoint.ts +14 -5
- package/src/http-api/HttpApiError.ts +250 -0
- package/src/http-api/HttpApiMiddleware.ts +95 -1
- package/src/http-api/HttpApiSchema.ts +105 -14
- package/src/index.ts +6 -6
- package/src/internal/effect.ts +34 -18
- package/src/internal/glob.ts +736 -0
- package/src/internal/matcher.ts +17 -0
- package/src/internal/persistence.ts +11 -0
- package/src/internal/rcRef.ts +4 -1
- package/src/internal/schema/toCodeDocument.ts +7 -3
- package/src/internal/trie.ts +43 -14
- package/src/internal/ulid.ts +44 -0
- package/src/internal/uuid.ts +57 -16
- package/src/internal/version.ts +1 -1
- package/src/observability/Otlp.ts +21 -4
- package/src/observability/OtlpResource.ts +9 -1
- package/src/persistence/KeyValueStore.ts +219 -22
- package/src/persistence/PersistedQueue.ts +128 -59
- package/src/persistence/Persistence.ts +20 -13
- package/src/process/ChildProcess.ts +255 -260
- package/src/process/ChildProcessSpawner.ts +5 -0
- package/src/process/CommandLine.ts +630 -0
- package/src/process/index.ts +6 -0
- package/src/reactivity/Atom.ts +5 -5
- package/src/reactivity/AtomRegistry.ts +1 -1
- package/src/rpc/RpcClient.ts +62 -26
- package/src/rpc/RpcMessage.ts +10 -1
- package/src/rpc/RpcSerialization.ts +3 -0
- package/src/rpc/RpcServer.ts +176 -78
- package/src/schema/Model.ts +26 -3
- package/src/sql/Migrator.ts +4 -63
- package/src/sql/MigratorFileSystem.ts +71 -0
- package/src/sql/SqlClient.ts +2 -16
- package/src/sql/Statement.ts +8 -7
- package/src/sql/index.ts +1 -1
- package/src/testing/index.ts +0 -6
- package/src/workflow/internal/crypto.ts +15 -11
- package/dist/Crypto.d.ts +0 -244
- package/dist/Crypto.d.ts.map +0 -1
- package/dist/Crypto.js +0 -139
- package/dist/Crypto.js.map +0 -1
- package/dist/testing/TestCrypto.d.ts +0 -73
- package/dist/testing/TestCrypto.d.ts.map +0 -1
- package/dist/testing/TestCrypto.js +0 -87
- package/dist/testing/TestCrypto.js.map +0 -1
- package/src/Crypto.ts +0 -347
- package/src/testing/TestCrypto.ts +0 -94
package/src/rpc/RpcServer.ts
CHANGED
|
@@ -89,6 +89,15 @@ export interface RpcServer<A extends Rpc.Any> {
|
|
|
89
89
|
* the request fails with that cause. `onFromServer` is assumed to have already
|
|
90
90
|
* answered the client and reported it, so nothing else is sent or reported.
|
|
91
91
|
*
|
|
92
|
+
* A request with `isNotification` set runs like any other, but no `Exit`,
|
|
93
|
+
* `Chunk` or `Defect` is sent for it. Its failures are still reported.
|
|
94
|
+
*
|
|
95
|
+
* A request with `discard` set is acknowledged with a successful `Exit` once
|
|
96
|
+
* its handler starts, after the concurrency permit is taken and the
|
|
97
|
+
* middleware has run. Nothing else is sent for it after that, and its
|
|
98
|
+
* failures are only reported. A failure before the acknowledgement is sent as
|
|
99
|
+
* a failed `Exit` for that request.
|
|
100
|
+
*
|
|
92
101
|
* @stability unstable
|
|
93
102
|
* @category constructors
|
|
94
103
|
* @since 4.0.0
|
|
@@ -255,16 +264,23 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
255
264
|
if (client.fibers.has(request.id)) {
|
|
256
265
|
return Effect.interrupt
|
|
257
266
|
}
|
|
267
|
+
const isNotification = request.isNotification === true
|
|
268
|
+
const isDiscard = !isNotification && request.discard === true
|
|
269
|
+
let acknowledged = false
|
|
270
|
+
// a notification, or a discarded call once it has been acknowledged, gets
|
|
271
|
+
// no reply of any kind
|
|
272
|
+
const respond = (exit: Exit.Exit<any, any>): Effect.Effect<void> =>
|
|
273
|
+
isNotification || acknowledged ? Effect.void : options.onFromServer({
|
|
274
|
+
_tag: "Exit",
|
|
275
|
+
clientId: client.id,
|
|
276
|
+
requestId: request.id,
|
|
277
|
+
exit
|
|
278
|
+
})
|
|
258
279
|
const rpc = group.requests.get(request.tag) as any as Rpc.AnyWithProps
|
|
259
280
|
const entry = Context.getOrUndefinedUnsafe(services, rpc?.key) as Rpc.Handler<Rpcs["_tag"]>
|
|
260
281
|
if (!rpc || !entry) {
|
|
261
282
|
const write = Effect.catchDefect(
|
|
262
|
-
|
|
263
|
-
_tag: "Exit",
|
|
264
|
-
clientId: client.id,
|
|
265
|
-
requestId: request.id,
|
|
266
|
-
exit: Exit.die(`Unknown request tag: ${request.tag}`)
|
|
267
|
-
}),
|
|
283
|
+
respond(Exit.die(`Unknown request tag: ${request.tag}`)),
|
|
268
284
|
(defect) => sendDefect(client, defect)
|
|
269
285
|
)
|
|
270
286
|
if (!client.ended || client.fibers.size > 0) return write
|
|
@@ -278,7 +294,18 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
278
294
|
headers: request.headers,
|
|
279
295
|
payload: request.payload
|
|
280
296
|
}
|
|
281
|
-
|
|
297
|
+
let handlerResult: ReturnType<typeof entry.handler>
|
|
298
|
+
// a handler that throws while being constructed never starts, so it is
|
|
299
|
+
// neither streamed nor acknowledged
|
|
300
|
+
let constructionFailed = false
|
|
301
|
+
try {
|
|
302
|
+
handlerResult = entry.handler(request.payload, metadata)
|
|
303
|
+
} catch (defect) {
|
|
304
|
+
handlerResult = Effect.die(defect)
|
|
305
|
+
constructionFailed = true
|
|
306
|
+
}
|
|
307
|
+
// a const, so that the narrowing below can be aliased
|
|
308
|
+
const result = handlerResult
|
|
282
309
|
|
|
283
310
|
// if the handler requested forking, then we skip the concurrency control
|
|
284
311
|
const isWrapper = Rpc.isWrapper(result)
|
|
@@ -288,11 +315,23 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
288
315
|
const streamOrEffect = isWrapper ? result.value : result
|
|
289
316
|
// set when a chunk could not be written; the writer has already responded
|
|
290
317
|
let writeFailure: Cause.Cause<never> | undefined
|
|
291
|
-
|
|
318
|
+
let handler = isStream && !constructionFailed
|
|
292
319
|
? (streamEffect(client, request, streamOrEffect, (cause) => {
|
|
293
320
|
writeFailure = cause
|
|
294
321
|
}) as Effect.Effect<{} | Deferred.Deferred<any, any>>)
|
|
295
322
|
: (streamOrEffect as Effect.Effect<{} | Deferred.Deferred<any, any>>)
|
|
323
|
+
if (isDiscard && !constructionFailed) {
|
|
324
|
+
// the acknowledgement runs inside the middleware, so it is only sent
|
|
325
|
+
// once the permit is held and the middleware has started the handler
|
|
326
|
+
handler = Effect.andThen(
|
|
327
|
+
Effect.suspend(() => {
|
|
328
|
+
const ack = respond(Exit.void)
|
|
329
|
+
acknowledged = true
|
|
330
|
+
return ack
|
|
331
|
+
}),
|
|
332
|
+
handler
|
|
333
|
+
)
|
|
334
|
+
}
|
|
296
335
|
|
|
297
336
|
const withMiddleware = rpc.middlewares.size === 0
|
|
298
337
|
? handler
|
|
@@ -314,29 +353,22 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
314
353
|
deferred = exit.value
|
|
315
354
|
write = Effect.void
|
|
316
355
|
} else {
|
|
317
|
-
write =
|
|
318
|
-
_tag: "Exit",
|
|
319
|
-
clientId: client.id,
|
|
320
|
-
requestId: request.id,
|
|
321
|
-
exit: exit as any
|
|
322
|
-
})
|
|
356
|
+
write = respond(exit)
|
|
323
357
|
}
|
|
324
358
|
} else if (writeFailure) {
|
|
325
359
|
// onFromServer has already answered the client and reported the failure
|
|
326
360
|
return Scope.closeUnsafe(scope, exit) ?? Effect.void
|
|
327
361
|
} else if (
|
|
328
362
|
!disableFatalDefects &&
|
|
363
|
+
// a notification or a discarded call only ever fails itself
|
|
364
|
+
!isNotification &&
|
|
365
|
+
!isDiscard &&
|
|
329
366
|
Cause.hasDies(exit.cause) &&
|
|
330
367
|
!Cause.hasInterrupts(exit.cause)
|
|
331
368
|
) {
|
|
332
369
|
write = sendDefect(client, Cause.squash(exit.cause))
|
|
333
370
|
} else {
|
|
334
|
-
write =
|
|
335
|
-
_tag: "Exit",
|
|
336
|
-
clientId: client.id,
|
|
337
|
-
requestId: request.id,
|
|
338
|
-
exit: exit as any
|
|
339
|
-
})
|
|
371
|
+
write = respond(exit)
|
|
340
372
|
}
|
|
341
373
|
const close = Scope.closeUnsafe(scope, exit)
|
|
342
374
|
if (exit._tag === "Failure") {
|
|
@@ -391,29 +423,24 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
391
423
|
)
|
|
392
424
|
fiber.addObserver(function onExit(exit: Exit.Exit<any, any>): void {
|
|
393
425
|
if (deferred) {
|
|
394
|
-
const fiber = trackFiber(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
426
|
+
const fiber = trackFiber(
|
|
427
|
+
runFork(
|
|
428
|
+
Effect.onExit(Deferred.await(deferred), (exit) => {
|
|
429
|
+
// a failure with no reply to carry it is only reported
|
|
430
|
+
if (exit._tag === "Failure" && (isNotification || acknowledged)) {
|
|
431
|
+
reportCauseUnsafe(Fiber.getCurrent()!, exit.cause)
|
|
432
|
+
}
|
|
433
|
+
return respond(exit)
|
|
434
|
+
})
|
|
435
|
+
)
|
|
436
|
+
)
|
|
401
437
|
client.fibers.set(request.id, fiber)
|
|
402
438
|
deferred = undefined
|
|
403
439
|
fiber.addObserver(onExit)
|
|
404
440
|
return
|
|
405
441
|
}
|
|
406
|
-
if (!responded && exit._tag === "Failure") {
|
|
407
|
-
trackFiber(
|
|
408
|
-
runFork(
|
|
409
|
-
options.onFromServer({
|
|
410
|
-
_tag: "Exit",
|
|
411
|
-
clientId: client.id,
|
|
412
|
-
requestId: request.id,
|
|
413
|
-
exit: Exit.interrupt()
|
|
414
|
-
})
|
|
415
|
-
)
|
|
416
|
-
)
|
|
442
|
+
if (!responded && !isNotification && !acknowledged && exit._tag === "Failure") {
|
|
443
|
+
trackFiber(runFork(respond(Exit.interrupt())))
|
|
417
444
|
}
|
|
418
445
|
client.fibers.delete(request.id)
|
|
419
446
|
client.latches?.delete(request.id)
|
|
@@ -432,8 +459,11 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
432
459
|
| Effect.Effect<Queue.Dequeue<any, any>, any, Scope.Scope>,
|
|
433
460
|
onWriteFailure: (cause: Cause.Cause<never>) => void
|
|
434
461
|
) => {
|
|
462
|
+
// the chunks of a notification or a discarded call have no reader, so they
|
|
463
|
+
// are neither sent nor acknowledged
|
|
464
|
+
const silent = request.isNotification === true || request.discard === true
|
|
435
465
|
const writeChunk = (values: NonEmptyReadonlyArray<any>) =>
|
|
436
|
-
Effect.onError(
|
|
466
|
+
silent ? Effect.void : Effect.onError(
|
|
437
467
|
options.onFromServer({ _tag: "Chunk", clientId: client.id, requestId: request.id, values }),
|
|
438
468
|
(cause) => {
|
|
439
469
|
if (!Cause.hasInterruptsOnly(cause)) onWriteFailure(cause)
|
|
@@ -441,7 +471,7 @@ export const makeNoSerialization: <Rpcs extends Rpc.Any>(
|
|
|
441
471
|
}
|
|
442
472
|
)
|
|
443
473
|
let latch: Latch.Latch | undefined
|
|
444
|
-
if (supportsAck) {
|
|
474
|
+
if (supportsAck && !silent) {
|
|
445
475
|
client.latches ??= new Map()
|
|
446
476
|
latch = client.latches.get(request.id)
|
|
447
477
|
if (!latch) {
|
|
@@ -574,21 +604,6 @@ const handlerContext = (
|
|
|
574
604
|
return merged
|
|
575
605
|
}
|
|
576
606
|
|
|
577
|
-
// a synchronous throw is handled like a returned `Effect.die`, so it goes
|
|
578
|
-
// through the request exit handling. Stream handlers may also return an
|
|
579
|
-
// Effect, so a single `Effect.die` covers both kinds of rpc.
|
|
580
|
-
const runHandler = (
|
|
581
|
-
entry: Rpc.Handler<string>,
|
|
582
|
-
payload: unknown,
|
|
583
|
-
metadata: Parameters<Rpc.Handler<string>["handler"]>[1]
|
|
584
|
-
) => {
|
|
585
|
-
try {
|
|
586
|
-
return entry.handler(payload, metadata)
|
|
587
|
-
} catch (defect) {
|
|
588
|
-
return Effect.die(defect)
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
607
|
const applyMiddleware = <A, E, R>(
|
|
593
608
|
context: Context.Context<never>,
|
|
594
609
|
handler: Effect.Effect<A, E, R>,
|
|
@@ -613,6 +628,23 @@ const applyMiddleware = <A, E, R>(
|
|
|
613
628
|
* requests, invoking handlers, encoding responses, and managing in-flight
|
|
614
629
|
* request lifetime.
|
|
615
630
|
*
|
|
631
|
+
* **Details**
|
|
632
|
+
*
|
|
633
|
+
* The server consumes `Protocol.disconnects` to interrupt a disconnected
|
|
634
|
+
* client's requests, so use the `onDisconnect` option to observe disconnects
|
|
635
|
+
* instead of taking from that queue.
|
|
636
|
+
*
|
|
637
|
+
* `onDisconnect` is called for each disconnect reported by the `Protocol`,
|
|
638
|
+
* after the server has requested interruption of that client's in-flight
|
|
639
|
+
* requests. It does not wait for those requests to finish. It is not called
|
|
640
|
+
* when a client ends its input normally, or for clients still connected when
|
|
641
|
+
* the server stops.
|
|
642
|
+
*
|
|
643
|
+
* Each callback runs in its own fiber, so a slow callback does not delay
|
|
644
|
+
* cleanup for other clients, and callbacks may run concurrently. Pending
|
|
645
|
+
* callbacks are interrupted when the server stops. Failures are ignored and
|
|
646
|
+
* logged at `References.UnhandledLogLevel`.
|
|
647
|
+
*
|
|
616
648
|
* @stability unstable
|
|
617
649
|
* @category running
|
|
618
650
|
* @since 4.0.0
|
|
@@ -626,6 +658,7 @@ export const make: <Rpcs extends Rpc.Any>(
|
|
|
626
658
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
627
659
|
readonly concurrency?: number | "unbounded" | undefined
|
|
628
660
|
readonly disableFatalDefects?: boolean | undefined
|
|
661
|
+
readonly onDisconnect?: ((clientId: number) => Effect.Effect<void>) | undefined
|
|
629
662
|
}
|
|
630
663
|
| undefined
|
|
631
664
|
) => Effect.Effect<
|
|
@@ -643,6 +676,7 @@ export const make: <Rpcs extends Rpc.Any>(
|
|
|
643
676
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
644
677
|
readonly concurrency?: number | "unbounded" | undefined
|
|
645
678
|
readonly disableFatalDefects?: boolean | undefined
|
|
679
|
+
readonly onDisconnect?: ((clientId: number) => Effect.Effect<void>) | undefined
|
|
646
680
|
}
|
|
647
681
|
) {
|
|
648
682
|
const {
|
|
@@ -702,13 +736,24 @@ export const make: <Rpcs extends Rpc.Any>(
|
|
|
702
736
|
}).pipe(Scope.provide(scope))
|
|
703
737
|
|
|
704
738
|
// handle disconnects
|
|
739
|
+
const onDisconnect = options?.onDisconnect
|
|
740
|
+
const handleDisconnect = onDisconnect
|
|
741
|
+
? (clientId: number) =>
|
|
742
|
+
Effect.andThen(
|
|
743
|
+
server.disconnect(clientId),
|
|
744
|
+
Effect.ignoreCause(Effect.suspend(() => onDisconnect(clientId)), {
|
|
745
|
+
log: "Unhandled",
|
|
746
|
+
message: "RpcServer onDisconnect hook failed"
|
|
747
|
+
}).pipe(Effect.forkIn(scope))
|
|
748
|
+
)
|
|
749
|
+
: server.disconnect
|
|
705
750
|
yield* Effect.forkChild(
|
|
706
751
|
Effect.whileLoop({
|
|
707
752
|
while: constTrue,
|
|
708
753
|
body: constant(
|
|
709
754
|
Effect.flatMap(Queue.take(disconnects), (clientId) => {
|
|
710
755
|
clients.delete(clientId)
|
|
711
|
-
return
|
|
756
|
+
return handleDisconnect(clientId)
|
|
712
757
|
})
|
|
713
758
|
),
|
|
714
759
|
step: constVoid
|
|
@@ -741,6 +786,25 @@ export const make: <Rpcs extends Rpc.Any>(
|
|
|
741
786
|
return schemas
|
|
742
787
|
}
|
|
743
788
|
|
|
789
|
+
// The only successful Exit sent for a discarded call is its acknowledgement,
|
|
790
|
+
// which carries no value, so its Exits are encoded with a void success.
|
|
791
|
+
const discardSchemasCache = new WeakMap<any, Schemas>()
|
|
792
|
+
const getDiscardSchemas = (rpc: Rpc.AnyWithProps, schemas: Schemas) => {
|
|
793
|
+
let discardSchemas = discardSchemasCache.get(rpc)
|
|
794
|
+
if (!discardSchemas) {
|
|
795
|
+
const exitSchema = Rpc.exitSchema(rpc as any)
|
|
796
|
+
discardSchemas = {
|
|
797
|
+
...schemas,
|
|
798
|
+
encodeExit: Schema.encodeUnknownEffect(
|
|
799
|
+
codecFor(Schema.Exit(Schema.Void, exitSchema.error, exitSchema.defect)),
|
|
800
|
+
Context.get(rpc.annotations, Rpc.ParseOptions)
|
|
801
|
+
) as any
|
|
802
|
+
}
|
|
803
|
+
discardSchemasCache.set(rpc, discardSchemas)
|
|
804
|
+
}
|
|
805
|
+
return discardSchemas
|
|
806
|
+
}
|
|
807
|
+
|
|
744
808
|
type Client = {
|
|
745
809
|
readonly id: number
|
|
746
810
|
readonly schemas: Map<RequestId, Schemas>
|
|
@@ -824,6 +888,13 @@ export const make: <Rpcs extends Rpc.Any>(
|
|
|
824
888
|
})
|
|
825
889
|
)
|
|
826
890
|
|
|
891
|
+
// a notification has no reply to carry the error, so it is only logged
|
|
892
|
+
const dropNotification = (reason: string) =>
|
|
893
|
+
Effect.annotateLogs(Effect.logDebug(`Dropped RPC notification: ${reason}`), {
|
|
894
|
+
module: "RpcServer",
|
|
895
|
+
method: "dropNotification"
|
|
896
|
+
})
|
|
897
|
+
|
|
827
898
|
const writeDecodedRequest = (
|
|
828
899
|
client: Client,
|
|
829
900
|
requestId: RequestId,
|
|
@@ -831,15 +902,18 @@ export const make: <Rpcs extends Rpc.Any>(
|
|
|
831
902
|
request: RequestEncoded,
|
|
832
903
|
payload: unknown
|
|
833
904
|
) => {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
905
|
+
// nothing is encoded for a notification, and only a reply would remove its schemas
|
|
906
|
+
if (request.isNotification !== true) {
|
|
907
|
+
client.schemas.set(
|
|
908
|
+
requestId,
|
|
909
|
+
supportsTransferables
|
|
910
|
+
? {
|
|
911
|
+
...schemas,
|
|
912
|
+
collector: Transferable.makeCollectorUnsafe()
|
|
913
|
+
}
|
|
914
|
+
: schemas
|
|
915
|
+
)
|
|
916
|
+
}
|
|
843
917
|
// the envelope is owned by this protocol loop, so it is decoded in place
|
|
844
918
|
// instead of copied for every request
|
|
845
919
|
const decoded = request as Types.Mutable<RequestEncoded>
|
|
@@ -849,6 +923,8 @@ export const make: <Rpcs extends Rpc.Any>(
|
|
|
849
923
|
return server.write(client.id, decoded as any)
|
|
850
924
|
}
|
|
851
925
|
|
|
926
|
+
let notificationCount = 0
|
|
927
|
+
|
|
852
928
|
// main server loop
|
|
853
929
|
return yield* run((clientId, request) => {
|
|
854
930
|
let client = clients.get(clientId)
|
|
@@ -863,35 +939,51 @@ export const make: <Rpcs extends Rpc.Any>(
|
|
|
863
939
|
switch (request._tag) {
|
|
864
940
|
case "Request": {
|
|
865
941
|
const tag = Object.hasOwn(request, "tag") ? (request.tag as string) : ""
|
|
942
|
+
const isNotification = request.isNotification === true
|
|
866
943
|
let requestId: RequestId
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
944
|
+
if (isNotification) {
|
|
945
|
+
// JSON-RPC notifications share an empty id, and no reply ever names one
|
|
946
|
+
requestId = RequestId(`@effect/rpc/notification/${notificationCount++}`)
|
|
947
|
+
} else {
|
|
948
|
+
switch (typeof request.id) {
|
|
949
|
+
case "number":
|
|
950
|
+
case "string": {
|
|
951
|
+
requestId = RequestId(request.id)
|
|
952
|
+
break
|
|
953
|
+
}
|
|
954
|
+
default: {
|
|
955
|
+
return sendDefect(client, `Invalid request id: ${request.id}`)
|
|
956
|
+
}
|
|
875
957
|
}
|
|
876
958
|
}
|
|
877
959
|
const rpc = group.requests.get(tag)
|
|
878
960
|
if (!rpc) {
|
|
879
|
-
|
|
961
|
+
const reason = `Unknown request tag: ${tag}`
|
|
962
|
+
return isNotification
|
|
963
|
+
? dropNotification(reason)
|
|
964
|
+
: sendRequestDefect(client, requestId, encodeUnknownRequestExit, reason)
|
|
880
965
|
}
|
|
881
966
|
const schemas = getSchemas(rpc as any)
|
|
967
|
+
const replySchemas = !isNotification && request.discard === true
|
|
968
|
+
? getDiscardSchemas(rpc as any, schemas)
|
|
969
|
+
: schemas
|
|
882
970
|
const decoded = schemas.decode(request.payload)
|
|
883
971
|
// The schema decoders evaluate eagerly, so a decode that needs no
|
|
884
972
|
// services is already a resolved success and can skip the effect
|
|
885
973
|
// wrappers.
|
|
886
974
|
if (Exit.isExit(decoded) && Exit.isSuccess(decoded)) {
|
|
887
|
-
return writeDecodedRequest(client, requestId,
|
|
975
|
+
return writeDecodedRequest(client, requestId, replySchemas, request, decoded.value)
|
|
888
976
|
}
|
|
889
977
|
return Effect.matchEffect(
|
|
890
978
|
Effect.provideContext(decoded, schemas.context),
|
|
891
979
|
{
|
|
892
|
-
onFailure: (error) =>
|
|
893
|
-
|
|
894
|
-
|
|
980
|
+
onFailure: (error) => {
|
|
981
|
+
const reason = SchemaIssue.defaultFormatter(error.issue)
|
|
982
|
+
return isNotification
|
|
983
|
+
? dropNotification(reason)
|
|
984
|
+
: sendRequestDefect(client, requestId, replySchemas.encodeExit, reason)
|
|
985
|
+
},
|
|
986
|
+
onSuccess: (payload) => writeDecodedRequest(client, requestId, replySchemas, request, payload)
|
|
895
987
|
}
|
|
896
988
|
)
|
|
897
989
|
}
|
|
@@ -939,6 +1031,7 @@ export const layer = <Rpcs extends Rpc.Any>(
|
|
|
939
1031
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
940
1032
|
readonly concurrency?: number | "unbounded" | undefined
|
|
941
1033
|
readonly disableFatalDefects?: boolean | undefined
|
|
1034
|
+
readonly onDisconnect?: ((clientId: number) => Effect.Effect<void>) | undefined
|
|
942
1035
|
}
|
|
943
1036
|
): Layer.Layer<
|
|
944
1037
|
never,
|
|
@@ -970,6 +1063,7 @@ export const layerHttp = <Rpcs extends Rpc.Any>(options: {
|
|
|
970
1063
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
971
1064
|
readonly concurrency?: number | "unbounded" | undefined
|
|
972
1065
|
readonly disableFatalDefects?: boolean | undefined
|
|
1066
|
+
readonly onDisconnect?: ((clientId: number) => Effect.Effect<void>) | undefined
|
|
973
1067
|
readonly streamBufferSize?: number | "unbounded" | undefined
|
|
974
1068
|
}): Layer.Layer<
|
|
975
1069
|
never,
|
|
@@ -1373,6 +1467,7 @@ export const toHttpEffect: <Rpcs extends Rpc.Any>(
|
|
|
1373
1467
|
readonly spanPrefix?: string | undefined
|
|
1374
1468
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
1375
1469
|
readonly disableFatalDefects?: boolean | undefined
|
|
1470
|
+
readonly onDisconnect?: ((clientId: number) => Effect.Effect<void>) | undefined
|
|
1376
1471
|
readonly streamBufferSize?: number | "unbounded" | undefined
|
|
1377
1472
|
} | undefined
|
|
1378
1473
|
) => Effect.Effect<
|
|
@@ -1390,6 +1485,7 @@ export const toHttpEffect: <Rpcs extends Rpc.Any>(
|
|
|
1390
1485
|
readonly spanPrefix?: string | undefined
|
|
1391
1486
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
1392
1487
|
readonly disableFatalDefects?: boolean | undefined
|
|
1488
|
+
readonly onDisconnect?: ((clientId: number) => Effect.Effect<void>) | undefined
|
|
1393
1489
|
readonly streamBufferSize?: number | "unbounded" | undefined
|
|
1394
1490
|
}
|
|
1395
1491
|
) {
|
|
@@ -1417,6 +1513,7 @@ export const toHttpEffectWebsocket: <Rpcs extends Rpc.Any>(
|
|
|
1417
1513
|
readonly spanPrefix?: string | undefined
|
|
1418
1514
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
1419
1515
|
readonly disableFatalDefects?: boolean | undefined
|
|
1516
|
+
readonly onDisconnect?: ((clientId: number) => Effect.Effect<void>) | undefined
|
|
1420
1517
|
} | undefined
|
|
1421
1518
|
) => Effect.Effect<
|
|
1422
1519
|
Effect.Effect<HttpServerResponse.HttpServerResponse, never, Scope.Scope | HttpServerRequest.HttpServerRequest>,
|
|
@@ -1433,6 +1530,7 @@ export const toHttpEffectWebsocket: <Rpcs extends Rpc.Any>(
|
|
|
1433
1530
|
readonly spanPrefix?: string | undefined
|
|
1434
1531
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
1435
1532
|
readonly disableFatalDefects?: boolean | undefined
|
|
1533
|
+
readonly onDisconnect?: ((clientId: number) => Effect.Effect<void>) | undefined
|
|
1436
1534
|
}
|
|
1437
1535
|
) {
|
|
1438
1536
|
const { httpEffect, protocol } = yield* makeProtocolWithHttpEffectWebsocket
|
package/src/schema/Model.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* @since 4.0.0
|
|
14
14
|
*/
|
|
15
15
|
import type { Brand } from "../Brand.ts"
|
|
16
|
+
import * as SecureRandom from "../crypto/SecureRandom.ts"
|
|
16
17
|
import * as DateTime from "../DateTime.ts"
|
|
17
18
|
import * as Effect from "../Effect.ts"
|
|
18
19
|
import * as Uuid from "../internal/uuid.ts"
|
|
@@ -808,7 +809,11 @@ export const Uint8Array: Schema.instanceOf<Uint8Array<ArrayBuffer>> = Schema.Uin
|
|
|
808
809
|
export const UuidV4BytesWithGenerate = <B extends string>(
|
|
809
810
|
schema: Schema.brand<Schema.instanceOf<Uint8Array<ArrayBuffer>>, B>
|
|
810
811
|
): Schema.withConstructorDefault<Schema.brand<Schema.instanceOf<Uint8Array<ArrayBuffer>>, B>> =>
|
|
811
|
-
schema.pipe(
|
|
812
|
+
schema.pipe(
|
|
813
|
+
Schema.withConstructorDefault(
|
|
814
|
+
Effect.sync(() => Uuid.v4Bytes(SecureRandom.randomBytesUnsafe(16) as Uint8Array<ArrayBuffer>))
|
|
815
|
+
)
|
|
816
|
+
)
|
|
812
817
|
|
|
813
818
|
/**
|
|
814
819
|
* A field that represents a binary UUID v4 that is generated on inserts.
|
|
@@ -854,7 +859,7 @@ export interface UuidV4Insert<B extends string> extends
|
|
|
854
859
|
export const UuidV4WithGenerate = <B extends string>(
|
|
855
860
|
schema: Schema.brand<Schema.String, B>
|
|
856
861
|
): Schema.withConstructorDefault<Schema.brand<Schema.String, B>> =>
|
|
857
|
-
schema.pipe(Schema.withConstructorDefault(Effect.sync(Uuid.v4String)))
|
|
862
|
+
schema.pipe(Schema.withConstructorDefault(Effect.sync(() => Uuid.v4String(SecureRandom.randomBytesUnsafe(16)))))
|
|
858
863
|
|
|
859
864
|
/**
|
|
860
865
|
* A field that represents a string UUID v4 that is generated on inserts.
|
|
@@ -893,6 +898,20 @@ export interface UuidV7Insert<B extends string> extends
|
|
|
893
898
|
/**
|
|
894
899
|
* Adds a constructor default that generates a string UUID v7.
|
|
895
900
|
*
|
|
901
|
+
* **Details**
|
|
902
|
+
*
|
|
903
|
+
* The UUID takes its timestamp from the `Clock`, and shares its ordering with
|
|
904
|
+
* `SecureRandom.uuidV7Unsafe` and every other `Model.UuidV7WithGenerate` in the
|
|
905
|
+
* JS realm, so below the maximum timestamp each UUID sorts after the previous
|
|
906
|
+
* one.
|
|
907
|
+
*
|
|
908
|
+
* **Gotchas**
|
|
909
|
+
*
|
|
910
|
+
* The shared ordering never moves the timestamp back, so a `Clock` behind the
|
|
911
|
+
* realm's latest timestamp, such as a `TestClock` after `Date.now()`-based
|
|
912
|
+
* UUIDs were generated, produces UUIDs with that latest timestamp rather than
|
|
913
|
+
* the `Clock` time.
|
|
914
|
+
*
|
|
896
915
|
* @stability unstable
|
|
897
916
|
* @category schemas
|
|
898
917
|
* @since 4.0.0
|
|
@@ -902,7 +921,11 @@ export const UuidV7WithGenerate = <B extends string>(
|
|
|
902
921
|
): Schema.withConstructorDefault<Schema.brand<Schema.String, B>> =>
|
|
903
922
|
schema.pipe(
|
|
904
923
|
Schema.withConstructorDefault(
|
|
905
|
-
Effect.clockWith((clock) =>
|
|
924
|
+
Effect.clockWith((clock) =>
|
|
925
|
+
Effect.succeed(
|
|
926
|
+
Uuid.stringify(Uuid.v7Monotonic(clock.currentTimeMillisUnsafe(), SecureRandom.randomBytesUnsafe(16)))
|
|
927
|
+
)
|
|
928
|
+
)
|
|
906
929
|
)
|
|
907
930
|
)
|
|
908
931
|
|
package/src/sql/Migrator.ts
CHANGED
|
@@ -12,11 +12,9 @@
|
|
|
12
12
|
import * as Arr from "../Array.ts"
|
|
13
13
|
import * as Data from "../Data.ts"
|
|
14
14
|
import * as Effect from "../Effect.ts"
|
|
15
|
-
import { FileSystem } from "../FileSystem.ts"
|
|
16
15
|
import { pipe } from "../Function.ts"
|
|
17
16
|
import * as Option from "../Option.ts"
|
|
18
17
|
import * as Order from "../Order.ts"
|
|
19
|
-
import { Path } from "../Path.ts"
|
|
20
18
|
import * as Client from "./SqlClient.ts"
|
|
21
19
|
import type { SqlError } from "./SqlError.ts"
|
|
22
20
|
|
|
@@ -174,11 +172,11 @@ ORDER BY migration_id`,
|
|
|
174
172
|
})
|
|
175
173
|
|
|
176
174
|
const insertMigrations = (
|
|
177
|
-
rows:
|
|
175
|
+
rows: Arr.NonEmptyReadonlyArray<[id: number, name: string]>
|
|
178
176
|
) =>
|
|
179
177
|
sql`INSERT INTO ${sql(table)} ${
|
|
180
178
|
sql.insert(
|
|
181
|
-
|
|
179
|
+
Arr.map(rows, ([migration_id, name]) => ({ migration_id, name }))
|
|
182
180
|
)
|
|
183
181
|
}`.withoutTransform
|
|
184
182
|
|
|
@@ -287,9 +285,9 @@ ORDER BY migration_id`,
|
|
|
287
285
|
}
|
|
288
286
|
|
|
289
287
|
// rows recorded up front are only rolled back inside a transaction
|
|
290
|
-
if (transactional && required
|
|
288
|
+
if (transactional && Arr.isArrayNonEmpty(required)) {
|
|
291
289
|
yield* pipe(
|
|
292
|
-
insertMigrations(
|
|
290
|
+
insertMigrations(Arr.map(required, ([id, name]) => [id, name])),
|
|
293
291
|
Effect.mapError((error): MigrationError | SqlError =>
|
|
294
292
|
isConstraintConflict(error)
|
|
295
293
|
? new MigrationError({
|
|
@@ -436,60 +434,3 @@ export const fromRecord = (migrations: Record<string, Effect.Effect<void, unknow
|
|
|
436
434
|
Arr.sort(migrationOrder),
|
|
437
435
|
Effect.succeed
|
|
438
436
|
)
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Creates a migration loader that reads a directory with `FileSystem`, imports
|
|
442
|
-
* files named `<id>_<name>.js`, `<id>_<name>.ts`,
|
|
443
|
-
* `<id>_<name>.mjs`, or `<id>_<name>.mts`, and sorts migrations by id.
|
|
444
|
-
*
|
|
445
|
-
* **Details**
|
|
446
|
-
*
|
|
447
|
-
* Requires a `Path` service appropriate for the migration directory's path
|
|
448
|
-
* syntax. On Windows, prefer a platform-aware implementation such as
|
|
449
|
-
* `NodePath.layer`; the core `Path.layer` uses POSIX semantics and does not
|
|
450
|
-
* preserve Windows drive-letter paths.
|
|
451
|
-
*
|
|
452
|
-
* @stability unstable
|
|
453
|
-
* @category loaders
|
|
454
|
-
* @since 4.0.0
|
|
455
|
-
*/
|
|
456
|
-
export const fromFileSystem: (directory: string) => Loader<FileSystem | Path> = Effect.fnUntraced(function*(directory) {
|
|
457
|
-
const Fs = yield* FileSystem
|
|
458
|
-
const path = yield* Path
|
|
459
|
-
const files = yield* Effect.mapError(
|
|
460
|
-
Fs.readDirectory(directory),
|
|
461
|
-
(cause) =>
|
|
462
|
-
new MigrationError({
|
|
463
|
-
kind: "Failed",
|
|
464
|
-
cause,
|
|
465
|
-
message: "Failed to read migrations directory"
|
|
466
|
-
})
|
|
467
|
-
)
|
|
468
|
-
return files
|
|
469
|
-
.map((file) => Option.fromNullishOr(file.match(/^(?:.*\/)?(\d+)_([^.]+)\.(js|ts|mjs|mts)$/)))
|
|
470
|
-
.flatMap(
|
|
471
|
-
Option.match({
|
|
472
|
-
onNone: () => [],
|
|
473
|
-
onSome: ([basename, id, name]): ReadonlyArray<ResolvedMigration> =>
|
|
474
|
-
[
|
|
475
|
-
[
|
|
476
|
-
Number(id),
|
|
477
|
-
name,
|
|
478
|
-
// `import` needs a file URL: on Windows an absolute path such as
|
|
479
|
-
// `D:\migrations\1_init.ts` is rejected by the ESM loader. `orDie` keeps the
|
|
480
|
-
// failure a defect so `loadMigration` reports it as an import error.
|
|
481
|
-
Effect.flatMap(Effect.orDie(path.toFileUrl(path.join(directory, basename))), (url) =>
|
|
482
|
-
Effect.promise(
|
|
483
|
-
() =>
|
|
484
|
-
import(
|
|
485
|
-
/* @vite-ignore */
|
|
486
|
-
/* webpackIgnore: true */
|
|
487
|
-
url.href
|
|
488
|
-
)
|
|
489
|
-
))
|
|
490
|
-
]
|
|
491
|
-
] as const
|
|
492
|
-
})
|
|
493
|
-
)
|
|
494
|
-
.sort(([a], [b]) => a - b);
|
|
495
|
-
})
|