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
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cryptographically secure randomness: random bytes, uniform integers,
|
|
3
|
+
* shuffles, UUIDv4, UUIDv7, and ULIDs.
|
|
4
|
+
*
|
|
5
|
+
* The {@link SecureRandom} service is built from one `randomBytes` primitive
|
|
6
|
+
* with {@link make}. {@link layerWebCrypto} draws from `getRandomValues` on
|
|
7
|
+
* the `WebCrypto` reference. The `*Unsafe` functions draw synchronously from
|
|
8
|
+
* `globalThis.crypto` for code that cannot use a service, such as constructors
|
|
9
|
+
* and model defaults.
|
|
10
|
+
*
|
|
11
|
+
* Every operation has a `never` error channel. A bad size or an empty range is
|
|
12
|
+
* a defect.
|
|
13
|
+
*
|
|
14
|
+
* **Gotchas**
|
|
15
|
+
*
|
|
16
|
+
* There are no float, boolean, or full-range integer helpers. Insecure random
|
|
17
|
+
* numbers belong to `effect/Random`, and a secure bit is `randomBytes(1)`.
|
|
18
|
+
*
|
|
19
|
+
* @stability unstable
|
|
20
|
+
* @since 4.0.0
|
|
21
|
+
*/
|
|
22
|
+
import * as Context from "../Context.ts"
|
|
23
|
+
import * as Effect from "../Effect.ts"
|
|
24
|
+
import * as Ulid from "../internal/ulid.ts"
|
|
25
|
+
import * as Uuid from "../internal/uuid.ts"
|
|
26
|
+
import * as Layer from "../Layer.ts"
|
|
27
|
+
import { WebCrypto } from "./WebCrypto.ts"
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Generates a UUID as a lowercase, hyphenated string or, with
|
|
31
|
+
* `format: "bytes"`, the 16 UUID bytes.
|
|
32
|
+
*
|
|
33
|
+
* @stability unstable
|
|
34
|
+
* @category models
|
|
35
|
+
* @since 4.0.0
|
|
36
|
+
*/
|
|
37
|
+
export interface UuidGenerator {
|
|
38
|
+
(options?: { readonly format?: "string" | undefined }): Effect.Effect<string>
|
|
39
|
+
<Format extends "string" | "bytes">(options: {
|
|
40
|
+
readonly format: Format
|
|
41
|
+
}): Effect.Effect<Format extends "bytes" ? Uint8Array : string>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Service that generates cryptographically secure random values.
|
|
46
|
+
*
|
|
47
|
+
* **Details**
|
|
48
|
+
*
|
|
49
|
+
* Every operation is derived from `randomBytes`. See {@link make}.
|
|
50
|
+
*
|
|
51
|
+
* @stability unstable
|
|
52
|
+
* @category services
|
|
53
|
+
* @since 4.0.0
|
|
54
|
+
*/
|
|
55
|
+
export class SecureRandom extends Context.Service<SecureRandom, {
|
|
56
|
+
/**
|
|
57
|
+
* Generates `size` cryptographically secure random bytes.
|
|
58
|
+
*
|
|
59
|
+
* A negative or non-integer size dies with a `RangeError`.
|
|
60
|
+
*/
|
|
61
|
+
readonly randomBytes: (size: number) => Effect.Effect<Uint8Array>
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Generates an integer between `min` and `max`, both inclusive unless
|
|
65
|
+
* `halfOpen` excludes `max`.
|
|
66
|
+
*
|
|
67
|
+
* **Details**
|
|
68
|
+
*
|
|
69
|
+
* The result is exactly uniform: draws that would bias it are rejected.
|
|
70
|
+
* `min` is rounded up and `max` down. An empty range, or bounds that do not
|
|
71
|
+
* round to safe integers, die with a `RangeError`.
|
|
72
|
+
*/
|
|
73
|
+
readonly intBetween: (min: number, max: number, options?: {
|
|
74
|
+
readonly halfOpen?: boolean | undefined
|
|
75
|
+
}) => Effect.Effect<number>
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns a uniformly shuffled copy of the elements, using Fisher-Yates over
|
|
79
|
+
* `intBetween`.
|
|
80
|
+
*/
|
|
81
|
+
readonly shuffle: <A>(elements: Iterable<A>) => Effect.Effect<Array<A>>
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Generates a UUIDv4, as a lowercase hyphenated string or, with
|
|
85
|
+
* `format: "bytes"`, the 16 UUID bytes.
|
|
86
|
+
*/
|
|
87
|
+
readonly uuidV4: UuidGenerator
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Generates a UUIDv7 from the `Clock` timestamp, as a lowercase hyphenated
|
|
91
|
+
* string or, with `format: "bytes"`, the 16 UUID bytes.
|
|
92
|
+
*
|
|
93
|
+
* Every UUIDv7 from this service sorts after the previous one, as a string
|
|
94
|
+
* and as bytes. Within a millisecond, a 42-bit counter seeded from random
|
|
95
|
+
* bytes orders them. If the `Clock` moves back, the last timestamp is kept,
|
|
96
|
+
* and if the counter overflows, the timestamp advances by 1 ms, so a
|
|
97
|
+
* timestamp can run slightly ahead of the `Clock`. The ordering ends at the
|
|
98
|
+
* maximum timestamp, 2^48 − 1 ms (in the year 10889), which overflow cannot
|
|
99
|
+
* advance. There is no ordering between separate services, processes or
|
|
100
|
+
* workers.
|
|
101
|
+
*
|
|
102
|
+
* Consecutive UUIDv7s reveal their generation order, so never use them as
|
|
103
|
+
* secrets. Uniqueness between generators is probabilistic: each UUID has 32
|
|
104
|
+
* fresh random bits, on top of a counter seeded from 41 random bits each
|
|
105
|
+
* millisecond.
|
|
106
|
+
*/
|
|
107
|
+
readonly uuidV7: UuidGenerator
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Generates a ULID from the `Clock` timestamp: 26 uppercase Crockford
|
|
111
|
+
* base32 characters.
|
|
112
|
+
*
|
|
113
|
+
* Every ULID from this service sorts after the previous one, using the ULID
|
|
114
|
+
* spec's monotonic mode: within a millisecond, the 80-bit random part is
|
|
115
|
+
* incremented. If the `Clock` moves back, the last timestamp is kept, and if
|
|
116
|
+
* the random part overflows, the timestamp advances by 1 ms. The ordering
|
|
117
|
+
* ends at the maximum timestamp, 2^48 − 1 ms (in the year 10889), which
|
|
118
|
+
* overflow cannot advance. There is no ordering between separate services,
|
|
119
|
+
* processes or workers. Consecutive ULIDs reveal their generation order, so
|
|
120
|
+
* never use them as secrets.
|
|
121
|
+
*/
|
|
122
|
+
readonly ulid: Effect.Effect<string>
|
|
123
|
+
}>()("effect/crypto/SecureRandom") {}
|
|
124
|
+
|
|
125
|
+
const checkSize = (size: number): void => {
|
|
126
|
+
if (!Number.isSafeInteger(size) || size < 0) {
|
|
127
|
+
throw new RangeError("size must be a non-negative safe integer")
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const readUint53 = (bytes: Uint8Array): number =>
|
|
132
|
+
((bytes[0] & 0x1f) * 2 ** 48) + (bytes[1] * 2 ** 40) + (bytes[2] * 2 ** 32) +
|
|
133
|
+
(bytes[3] * 2 ** 24) + (bytes[4] * 2 ** 16) + (bytes[5] * 2 ** 8) + bytes[6]
|
|
134
|
+
|
|
135
|
+
// Draws an integer by rejection sampling over 53-bit (or, for ranges wider than
|
|
136
|
+
// 2^53, 54-bit) draws, so every integer in the range has the same probability.
|
|
137
|
+
const intBetweenUnsafe = (
|
|
138
|
+
min: number,
|
|
139
|
+
max: number,
|
|
140
|
+
halfOpen: boolean,
|
|
141
|
+
draw: () => Uint8Array
|
|
142
|
+
): number => {
|
|
143
|
+
const minInt = Math.ceil(min)
|
|
144
|
+
const maxInt = Math.floor(max)
|
|
145
|
+
if (!Number.isSafeInteger(minInt) || !Number.isSafeInteger(maxInt)) {
|
|
146
|
+
throw new RangeError("bounds must round to safe integers")
|
|
147
|
+
}
|
|
148
|
+
if (maxInt - minInt < Number.MAX_SAFE_INTEGER) {
|
|
149
|
+
// Every intermediate stays below 2^53, and `%` is exact, so the divisions
|
|
150
|
+
// below are exact without BigInt.
|
|
151
|
+
const count = maxInt - minInt + (halfOpen ? 0 : 1)
|
|
152
|
+
if (count <= 0) {
|
|
153
|
+
throw new RangeError("range must contain at least one integer")
|
|
154
|
+
}
|
|
155
|
+
// `+ 0` turns `Math.ceil` of a value in (-1, 0) into 0 instead of -0.
|
|
156
|
+
if (count === 1) return minInt + 0
|
|
157
|
+
const bucketSize = (2 ** 53 - (2 ** 53 % count)) / count
|
|
158
|
+
const limit = bucketSize * count
|
|
159
|
+
while (true) {
|
|
160
|
+
const value = readUint53(draw())
|
|
161
|
+
if (value < limit) return minInt + (value - (value % bucketSize)) / bucketSize
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// BigInt keeps every integer distinct when the range is wider than 2^53.
|
|
165
|
+
const lower = BigInt(minInt)
|
|
166
|
+
const count = BigInt(maxInt) - lower + (halfOpen ? BigInt(0) : BigInt(1))
|
|
167
|
+
const wide = count > BigInt(1) << BigInt(53)
|
|
168
|
+
const bucketSize = (wide ? BigInt(1) << BigInt(54) : BigInt(1) << BigInt(53)) / count
|
|
169
|
+
const limit = bucketSize * count
|
|
170
|
+
while (true) {
|
|
171
|
+
const bytes = draw()
|
|
172
|
+
const value = BigInt(readUint53(bytes)) + (wide && (bytes[0] & 0x20) !== 0 ? BigInt(1) << BigInt(53) : BigInt(0))
|
|
173
|
+
if (value < limit) return Number(lower + value / bucketSize)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const makeUuid = (
|
|
178
|
+
bytes: (randomBytes: Uint8Array) => Uint8Array,
|
|
179
|
+
randomBytes: (size: number) => Uint8Array,
|
|
180
|
+
format: "string" | "bytes" | undefined
|
|
181
|
+
): string | Uint8Array => {
|
|
182
|
+
const uuid = bytes(randomBytes(16))
|
|
183
|
+
return format === "bytes" ? uuid : Uuid.stringify(uuid)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Creates a `SecureRandom` service from a secure byte source.
|
|
188
|
+
*
|
|
189
|
+
* **When to use**
|
|
190
|
+
*
|
|
191
|
+
* Use to build the service for a platform integration, a custom runtime, or a
|
|
192
|
+
* seeded test double.
|
|
193
|
+
*
|
|
194
|
+
* **Details**
|
|
195
|
+
*
|
|
196
|
+
* Every operation is derived from `randomBytes`. Sizes are checked before it
|
|
197
|
+
* is called, and an exception it throws is a defect. Each service orders its
|
|
198
|
+
* own UUIDv7s and ULIDs, independently of other services and of the
|
|
199
|
+
* `*Unsafe` functions.
|
|
200
|
+
*
|
|
201
|
+
* **Gotchas**
|
|
202
|
+
*
|
|
203
|
+
* `randomBytes` must return a fresh array of exactly `size` secure random
|
|
204
|
+
* bytes. UUID formatting mutates the returned array.
|
|
205
|
+
*
|
|
206
|
+
* **Example** (Creating a SecureRandom service)
|
|
207
|
+
*
|
|
208
|
+
* ```ts import.meta.vitest
|
|
209
|
+
* import { Effect } from "effect"
|
|
210
|
+
* import { SecureRandom } from "effect/crypto"
|
|
211
|
+
*
|
|
212
|
+
* const random = SecureRandom.make((size) => globalThis.crypto.getRandomValues(new Uint8Array(size)))
|
|
213
|
+
*
|
|
214
|
+
* const bytes = await Effect.runPromise(random.randomBytes(4))
|
|
215
|
+
* bytes.length // => 4
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* @stability unstable
|
|
219
|
+
* @category constructors
|
|
220
|
+
* @since 4.0.0
|
|
221
|
+
*/
|
|
222
|
+
export const make = (randomBytes: (size: number) => Uint8Array): SecureRandom["Service"] => {
|
|
223
|
+
const randomBytesChecked = (size: number): Uint8Array => {
|
|
224
|
+
checkSize(size)
|
|
225
|
+
return randomBytes(size)
|
|
226
|
+
}
|
|
227
|
+
const draw = () => randomBytes(7)
|
|
228
|
+
const uuidV7 = Uuid.makeV7Monotonic()
|
|
229
|
+
const ulid = Ulid.makeMonotonic()
|
|
230
|
+
const ulidRandomBytes = () => randomBytes(10)
|
|
231
|
+
return {
|
|
232
|
+
randomBytes: (size) => Effect.sync(() => randomBytesChecked(size)),
|
|
233
|
+
intBetween: (min, max, options) => Effect.sync(() => intBetweenUnsafe(min, max, options?.halfOpen ?? false, draw)),
|
|
234
|
+
shuffle: <A>(elements: Iterable<A>) =>
|
|
235
|
+
Effect.sync(() => {
|
|
236
|
+
const buffer = Array.from(elements)
|
|
237
|
+
for (let i = buffer.length - 1; i >= 1; i--) {
|
|
238
|
+
const index = intBetweenUnsafe(0, i, false, draw)
|
|
239
|
+
const value = buffer[i]!
|
|
240
|
+
buffer[i] = buffer[index]!
|
|
241
|
+
buffer[index] = value
|
|
242
|
+
}
|
|
243
|
+
return buffer
|
|
244
|
+
}),
|
|
245
|
+
uuidV4:
|
|
246
|
+
((options?: { readonly format?: "string" | "bytes" | undefined }) =>
|
|
247
|
+
Effect.sync(() => makeUuid(Uuid.v4Bytes, randomBytes, options?.format))) as UuidGenerator,
|
|
248
|
+
uuidV7:
|
|
249
|
+
((options?: { readonly format?: "string" | "bytes" | undefined }) =>
|
|
250
|
+
Effect.clockWith((clock) =>
|
|
251
|
+
Effect.sync(() =>
|
|
252
|
+
makeUuid((bytes) => uuidV7(clock.currentTimeMillisUnsafe(), bytes), randomBytes, options?.format)
|
|
253
|
+
)
|
|
254
|
+
)) as UuidGenerator,
|
|
255
|
+
ulid: Effect.clockWith((clock) => Effect.sync(() => ulid(clock.currentTimeMillisUnsafe(), ulidRandomBytes)))
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// `getRandomValues` throws a `QuotaExceededError` above 65,536 bytes.
|
|
260
|
+
const fillRandom = (crypto: Crypto, size: number): Uint8Array => {
|
|
261
|
+
const bytes = new Uint8Array(size)
|
|
262
|
+
for (let offset = 0; offset < size; offset += 65_536) {
|
|
263
|
+
crypto.getRandomValues(bytes.subarray(offset, offset + 65_536))
|
|
264
|
+
}
|
|
265
|
+
return bytes
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Layer that provides `SecureRandom` from `getRandomValues` on the `WebCrypto`
|
|
270
|
+
* reference.
|
|
271
|
+
*
|
|
272
|
+
* **Details**
|
|
273
|
+
*
|
|
274
|
+
* Requests above the 65,536-byte `getRandomValues` limit are filled in chunks.
|
|
275
|
+
* Only `getRandomValues` is needed, so the layer also works in insecure browser
|
|
276
|
+
* contexts, which have no `crypto.subtle`.
|
|
277
|
+
*
|
|
278
|
+
* @stability unstable
|
|
279
|
+
* @category layers
|
|
280
|
+
* @since 4.0.0
|
|
281
|
+
*/
|
|
282
|
+
export const layerWebCrypto: Layer.Layer<SecureRandom> = Layer.effect(
|
|
283
|
+
SecureRandom,
|
|
284
|
+
WebCrypto.use((crypto) => Effect.succeed(make((size) => fillRandom(crypto, size))))
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Synchronously generates `size` cryptographically secure random bytes from
|
|
289
|
+
* `globalThis.crypto`.
|
|
290
|
+
*
|
|
291
|
+
* **When to use**
|
|
292
|
+
*
|
|
293
|
+
* Use when a service cannot be read, as in constructors and model defaults.
|
|
294
|
+
* Elsewhere, use the `SecureRandom` service.
|
|
295
|
+
*
|
|
296
|
+
* **Gotchas**
|
|
297
|
+
*
|
|
298
|
+
* Reads `globalThis.crypto` directly, so neither the `WebCrypto` reference nor
|
|
299
|
+
* a mocked `SecureRandom` service affects it. A negative or non-integer size
|
|
300
|
+
* throws a `RangeError`.
|
|
301
|
+
*
|
|
302
|
+
* @stability unstable
|
|
303
|
+
* @category unsafe
|
|
304
|
+
* @since 4.0.0
|
|
305
|
+
*/
|
|
306
|
+
export const randomBytesUnsafe = (size: number): Uint8Array => {
|
|
307
|
+
checkSize(size)
|
|
308
|
+
return fillRandom(globalThis.crypto, size)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Synchronously generates a UUIDv4 from `globalThis.crypto`, as a lowercase
|
|
313
|
+
* hyphenated string or, with `format: "bytes"`, the 16 UUID bytes.
|
|
314
|
+
*
|
|
315
|
+
* **Gotchas**
|
|
316
|
+
*
|
|
317
|
+
* Reads `globalThis.crypto` directly, so neither the `WebCrypto` reference nor
|
|
318
|
+
* a mocked `SecureRandom` service affects it.
|
|
319
|
+
*
|
|
320
|
+
* @stability unstable
|
|
321
|
+
* @category unsafe
|
|
322
|
+
* @since 4.0.0
|
|
323
|
+
*/
|
|
324
|
+
export const uuidV4Unsafe: {
|
|
325
|
+
/**
|
|
326
|
+
* Synchronously generates a UUIDv4 from `globalThis.crypto`, as a lowercase
|
|
327
|
+
* hyphenated string or, with `format: "bytes"`, the 16 UUID bytes.
|
|
328
|
+
*
|
|
329
|
+
* **Gotchas**
|
|
330
|
+
*
|
|
331
|
+
* Reads `globalThis.crypto` directly, so neither the `WebCrypto` reference nor
|
|
332
|
+
* a mocked `SecureRandom` service affects it.
|
|
333
|
+
*
|
|
334
|
+
* @stability unstable
|
|
335
|
+
* @category unsafe
|
|
336
|
+
* @since 4.0.0
|
|
337
|
+
*/
|
|
338
|
+
(options?: { readonly format?: "string" | undefined }): string
|
|
339
|
+
/**
|
|
340
|
+
* Synchronously generates a UUIDv4 from `globalThis.crypto`, as a lowercase
|
|
341
|
+
* hyphenated string or, with `format: "bytes"`, the 16 UUID bytes.
|
|
342
|
+
*
|
|
343
|
+
* **Gotchas**
|
|
344
|
+
*
|
|
345
|
+
* Reads `globalThis.crypto` directly, so neither the `WebCrypto` reference nor
|
|
346
|
+
* a mocked `SecureRandom` service affects it.
|
|
347
|
+
*
|
|
348
|
+
* @stability unstable
|
|
349
|
+
* @category unsafe
|
|
350
|
+
* @since 4.0.0
|
|
351
|
+
*/
|
|
352
|
+
<Format extends "string" | "bytes">(options: { readonly format: Format }): Format extends "bytes" ? Uint8Array : string
|
|
353
|
+
} =
|
|
354
|
+
((options?: { readonly format?: "string" | "bytes" | undefined }) =>
|
|
355
|
+
makeUuid(Uuid.v4Bytes, randomBytesUnsafe, options?.format)) as any
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Synchronously generates a UUIDv7 from `Date.now()` and `globalThis.crypto`,
|
|
359
|
+
* as a lowercase hyphenated string or, with `format: "bytes"`, the 16 UUID
|
|
360
|
+
* bytes.
|
|
361
|
+
*
|
|
362
|
+
* **Details**
|
|
363
|
+
*
|
|
364
|
+
* Below the maximum timestamp, every UUIDv7 generated in this JS realm
|
|
365
|
+
* (process or worker) sorts after the previous one, as a string and as bytes,
|
|
366
|
+
* using the counter described on the `SecureRandom` service's `uuidV7`. The
|
|
367
|
+
* ordering is shared with `Model.UuidV7WithGenerate`, and does not hold across
|
|
368
|
+
* processes or workers. Consecutive UUIDv7s reveal their
|
|
369
|
+
* generation order, so never use them as secrets.
|
|
370
|
+
*
|
|
371
|
+
* **Gotchas**
|
|
372
|
+
*
|
|
373
|
+
* Reads `Date.now()` rather than the `Clock`, and `globalThis.crypto` rather
|
|
374
|
+
* than the `WebCrypto` reference. A timestamp can run slightly ahead of
|
|
375
|
+
* `Date.now()` when the clock moves back or the counter overflows.
|
|
376
|
+
*
|
|
377
|
+
* @stability unstable
|
|
378
|
+
* @category unsafe
|
|
379
|
+
* @since 4.0.0
|
|
380
|
+
*/
|
|
381
|
+
export const uuidV7Unsafe: {
|
|
382
|
+
/**
|
|
383
|
+
* Synchronously generates a UUIDv7 from `Date.now()` and `globalThis.crypto`,
|
|
384
|
+
* as a lowercase hyphenated string or, with `format: "bytes"`, the 16 UUID
|
|
385
|
+
* bytes.
|
|
386
|
+
*
|
|
387
|
+
* **Details**
|
|
388
|
+
*
|
|
389
|
+
* Below the maximum timestamp, every UUIDv7 generated in this JS realm
|
|
390
|
+
* (process or worker) sorts after the previous one, as a string and as bytes,
|
|
391
|
+
* using the counter described on the `SecureRandom` service's `uuidV7`. The
|
|
392
|
+
* ordering is shared with `Model.UuidV7WithGenerate`, and does not hold across
|
|
393
|
+
* processes or workers. Consecutive UUIDv7s reveal their
|
|
394
|
+
* generation order, so never use them as secrets.
|
|
395
|
+
*
|
|
396
|
+
* **Gotchas**
|
|
397
|
+
*
|
|
398
|
+
* Reads `Date.now()` rather than the `Clock`, and `globalThis.crypto` rather
|
|
399
|
+
* than the `WebCrypto` reference. A timestamp can run slightly ahead of
|
|
400
|
+
* `Date.now()` when the clock moves back or the counter overflows.
|
|
401
|
+
*
|
|
402
|
+
* @stability unstable
|
|
403
|
+
* @category unsafe
|
|
404
|
+
* @since 4.0.0
|
|
405
|
+
*/
|
|
406
|
+
(options?: { readonly format?: "string" | undefined }): string
|
|
407
|
+
/**
|
|
408
|
+
* Synchronously generates a UUIDv7 from `Date.now()` and `globalThis.crypto`,
|
|
409
|
+
* as a lowercase hyphenated string or, with `format: "bytes"`, the 16 UUID
|
|
410
|
+
* bytes.
|
|
411
|
+
*
|
|
412
|
+
* **Details**
|
|
413
|
+
*
|
|
414
|
+
* Below the maximum timestamp, every UUIDv7 generated in this JS realm
|
|
415
|
+
* (process or worker) sorts after the previous one, as a string and as bytes,
|
|
416
|
+
* using the counter described on the `SecureRandom` service's `uuidV7`. The
|
|
417
|
+
* ordering is shared with `Model.UuidV7WithGenerate`, and does not hold across
|
|
418
|
+
* processes or workers. Consecutive UUIDv7s reveal their
|
|
419
|
+
* generation order, so never use them as secrets.
|
|
420
|
+
*
|
|
421
|
+
* **Gotchas**
|
|
422
|
+
*
|
|
423
|
+
* Reads `Date.now()` rather than the `Clock`, and `globalThis.crypto` rather
|
|
424
|
+
* than the `WebCrypto` reference. A timestamp can run slightly ahead of
|
|
425
|
+
* `Date.now()` when the clock moves back or the counter overflows.
|
|
426
|
+
*
|
|
427
|
+
* @stability unstable
|
|
428
|
+
* @category unsafe
|
|
429
|
+
* @since 4.0.0
|
|
430
|
+
*/
|
|
431
|
+
<Format extends "string" | "bytes">(options: { readonly format: Format }): Format extends "bytes" ? Uint8Array : string
|
|
432
|
+
} =
|
|
433
|
+
((options?: { readonly format?: "string" | "bytes" | undefined }) =>
|
|
434
|
+
makeUuid((bytes) => Uuid.v7Monotonic(Date.now(), bytes), randomBytesUnsafe, options?.format)) as any
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Synchronously generates a ULID from `Date.now()` and `globalThis.crypto`.
|
|
438
|
+
*
|
|
439
|
+
* **Details**
|
|
440
|
+
*
|
|
441
|
+
* Below the maximum timestamp, every ULID generated in this JS realm (process
|
|
442
|
+
* or worker) sorts after the previous one, using the monotonic mode described
|
|
443
|
+
* on the `SecureRandom` service's `ulid`. The ordering does not hold across
|
|
444
|
+
* processes or workers. Consecutive ULIDs reveal their generation order, so
|
|
445
|
+
* never use them as secrets.
|
|
446
|
+
*
|
|
447
|
+
* **Gotchas**
|
|
448
|
+
*
|
|
449
|
+
* Reads `Date.now()` rather than the `Clock`, and `globalThis.crypto` rather
|
|
450
|
+
* than the `WebCrypto` reference. A timestamp can run slightly ahead of
|
|
451
|
+
* `Date.now()` when the clock moves back or the random part overflows.
|
|
452
|
+
*
|
|
453
|
+
* @stability unstable
|
|
454
|
+
* @category unsafe
|
|
455
|
+
* @since 4.0.0
|
|
456
|
+
*/
|
|
457
|
+
export const ulidUnsafe = (): string => Ulid.monotonic(Date.now(), ulidRandomBytesUnsafe)
|
|
458
|
+
|
|
459
|
+
const ulidRandomBytesUnsafe = () => randomBytesUnsafe(10)
|