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
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provides a deterministic implementation of the Effect `Crypto` service for
|
|
3
|
-
* tests.
|
|
4
|
-
*
|
|
5
|
-
* Random bytes, numbers, shuffles, UUIDs, and ULIDs are derived from a seeded
|
|
6
|
-
* pseudo-random generator. Digest operations are delegated to an underlying
|
|
7
|
-
* platform `Crypto` service.
|
|
8
|
-
*
|
|
9
|
-
* @stability unstable
|
|
10
|
-
* @since 4.0.0
|
|
11
|
-
*/
|
|
12
|
-
import * as Crypto from "../Crypto.ts";
|
|
13
|
-
import * as Effect from "../Effect.ts";
|
|
14
|
-
import * as Layer from "../Layer.ts";
|
|
15
|
-
/**
|
|
16
|
-
* Creates a deterministic `Crypto` service using a seeded pseudo-random
|
|
17
|
-
* generator.
|
|
18
|
-
*
|
|
19
|
-
* **When to use**
|
|
20
|
-
*
|
|
21
|
-
* Use to construct a `Crypto` service whose random operations are reproducible
|
|
22
|
-
* in tests while preserving the digest implementation of a platform `Crypto`
|
|
23
|
-
* service.
|
|
24
|
-
*
|
|
25
|
-
* **Details**
|
|
26
|
-
*
|
|
27
|
-
* The effect requires an existing `Crypto` service and delegates digest
|
|
28
|
-
* operations to it. Each evaluation starts a new random sequence from `seed`;
|
|
29
|
-
* every other random operation is derived from that sequence.
|
|
30
|
-
*
|
|
31
|
-
* **Gotchas**
|
|
32
|
-
*
|
|
33
|
-
* The generated values are deterministic and must not be used for
|
|
34
|
-
* security-sensitive purposes. The sequence depends on the order in which
|
|
35
|
-
* random operations are evaluated. UUIDv7 and ULID values also include the
|
|
36
|
-
* current `Clock` time, which must be controlled separately when their complete
|
|
37
|
-
* output needs to be reproducible.
|
|
38
|
-
*
|
|
39
|
-
* @see {@link layer} for providing the service as a layer
|
|
40
|
-
*
|
|
41
|
-
* @stability unstable
|
|
42
|
-
* @category constructors
|
|
43
|
-
* @since 4.0.0
|
|
44
|
-
*/
|
|
45
|
-
export declare const make: (seed: string | number) => Effect.Effect<Crypto.Crypto, never, Crypto.Crypto>;
|
|
46
|
-
/**
|
|
47
|
-
* Creates a layer that provides deterministic `Crypto` random operations from
|
|
48
|
-
* a seed.
|
|
49
|
-
*
|
|
50
|
-
* **When to use**
|
|
51
|
-
*
|
|
52
|
-
* Use to provide reproducible random bytes, numbers, shuffles, UUIDs, and ULIDs
|
|
53
|
-
* to an Effect program under test.
|
|
54
|
-
*
|
|
55
|
-
* **Details**
|
|
56
|
-
*
|
|
57
|
-
* The layer requires an existing platform `Crypto` service whose digest
|
|
58
|
-
* implementation is retained. Each layer build starts the random sequence from
|
|
59
|
-
* `seed`.
|
|
60
|
-
*
|
|
61
|
-
* **Gotchas**
|
|
62
|
-
*
|
|
63
|
-
* UUIDv7 and ULID values also depend on the current `Clock`. Provide a test
|
|
64
|
-
* clock when their complete output needs to be reproducible.
|
|
65
|
-
*
|
|
66
|
-
* @see {@link make} for constructing the service directly
|
|
67
|
-
*
|
|
68
|
-
* @stability unstable
|
|
69
|
-
* @category layers
|
|
70
|
-
* @since 4.0.0
|
|
71
|
-
*/
|
|
72
|
-
export declare const layer: (seed: string | number) => Layer.Layer<Crypto.Crypto, never, Crypto.Crypto>;
|
|
73
|
-
//# sourceMappingURL=TestCrypto.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TestCrypto.d.ts","sourceRoot":"","sources":["../../src/testing/TestCrypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,KAAK,MAAM,aAAa,CAAA;AAGpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,IAAI,EAAE,CACjB,IAAI,EAAE,MAAM,GAAG,MAAM,KAClB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAgBrD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,KAAK,SAAU,MAAM,GAAG,MAAM,KAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CACpD,CAAA"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provides a deterministic implementation of the Effect `Crypto` service for
|
|
3
|
-
* tests.
|
|
4
|
-
*
|
|
5
|
-
* Random bytes, numbers, shuffles, UUIDs, and ULIDs are derived from a seeded
|
|
6
|
-
* pseudo-random generator. Digest operations are delegated to an underlying
|
|
7
|
-
* platform `Crypto` service.
|
|
8
|
-
*
|
|
9
|
-
* @stability unstable
|
|
10
|
-
* @since 4.0.0
|
|
11
|
-
*/
|
|
12
|
-
import * as Crypto from "../Crypto.js";
|
|
13
|
-
import * as Effect from "../Effect.js";
|
|
14
|
-
import * as Layer from "../Layer.js";
|
|
15
|
-
import * as Random from "../Random.js";
|
|
16
|
-
/**
|
|
17
|
-
* Creates a deterministic `Crypto` service using a seeded pseudo-random
|
|
18
|
-
* generator.
|
|
19
|
-
*
|
|
20
|
-
* **When to use**
|
|
21
|
-
*
|
|
22
|
-
* Use to construct a `Crypto` service whose random operations are reproducible
|
|
23
|
-
* in tests while preserving the digest implementation of a platform `Crypto`
|
|
24
|
-
* service.
|
|
25
|
-
*
|
|
26
|
-
* **Details**
|
|
27
|
-
*
|
|
28
|
-
* The effect requires an existing `Crypto` service and delegates digest
|
|
29
|
-
* operations to it. Each evaluation starts a new random sequence from `seed`;
|
|
30
|
-
* every other random operation is derived from that sequence.
|
|
31
|
-
*
|
|
32
|
-
* **Gotchas**
|
|
33
|
-
*
|
|
34
|
-
* The generated values are deterministic and must not be used for
|
|
35
|
-
* security-sensitive purposes. The sequence depends on the order in which
|
|
36
|
-
* random operations are evaluated. UUIDv7 and ULID values also include the
|
|
37
|
-
* current `Clock` time, which must be controlled separately when their complete
|
|
38
|
-
* output needs to be reproducible.
|
|
39
|
-
*
|
|
40
|
-
* @see {@link layer} for providing the service as a layer
|
|
41
|
-
*
|
|
42
|
-
* @stability unstable
|
|
43
|
-
* @category constructors
|
|
44
|
-
* @since 4.0.0
|
|
45
|
-
*/
|
|
46
|
-
export const make = /*#__PURE__*/Effect.fnUntraced(function* (_seed) {
|
|
47
|
-
const crypto = yield* Crypto.Crypto;
|
|
48
|
-
const seededRandom = yield* Random.Random;
|
|
49
|
-
return Crypto.make({
|
|
50
|
-
randomBytes: size => {
|
|
51
|
-
const bytes = new Uint8Array(size);
|
|
52
|
-
for (let i = 0; i < size; i++) {
|
|
53
|
-
bytes[i] = Math.floor(seededRandom.nextDoubleUnsafe() * 256);
|
|
54
|
-
}
|
|
55
|
-
return bytes;
|
|
56
|
-
},
|
|
57
|
-
digest: crypto.digest
|
|
58
|
-
});
|
|
59
|
-
}, (effect, seed) => Random.withSeed(effect, seed));
|
|
60
|
-
/**
|
|
61
|
-
* Creates a layer that provides deterministic `Crypto` random operations from
|
|
62
|
-
* a seed.
|
|
63
|
-
*
|
|
64
|
-
* **When to use**
|
|
65
|
-
*
|
|
66
|
-
* Use to provide reproducible random bytes, numbers, shuffles, UUIDs, and ULIDs
|
|
67
|
-
* to an Effect program under test.
|
|
68
|
-
*
|
|
69
|
-
* **Details**
|
|
70
|
-
*
|
|
71
|
-
* The layer requires an existing platform `Crypto` service whose digest
|
|
72
|
-
* implementation is retained. Each layer build starts the random sequence from
|
|
73
|
-
* `seed`.
|
|
74
|
-
*
|
|
75
|
-
* **Gotchas**
|
|
76
|
-
*
|
|
77
|
-
* UUIDv7 and ULID values also depend on the current `Clock`. Provide a test
|
|
78
|
-
* clock when their complete output needs to be reproducible.
|
|
79
|
-
*
|
|
80
|
-
* @see {@link make} for constructing the service directly
|
|
81
|
-
*
|
|
82
|
-
* @stability unstable
|
|
83
|
-
* @category layers
|
|
84
|
-
* @since 4.0.0
|
|
85
|
-
*/
|
|
86
|
-
export const layer = seed => Layer.effect(Crypto.Crypto, make(seed));
|
|
87
|
-
//# sourceMappingURL=TestCrypto.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TestCrypto.js","names":[],"sources":["../../src/testing/TestCrypto.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;AAWA,OAAO,KAAK,MAAM,MAAM,cAAc;AACtC,OAAO,KAAK,MAAM,MAAM,cAAc;AACtC,OAAO,KAAK,KAAK,MAAM,aAAa;AACpC,OAAO,KAAK,MAAM,MAAM,cAAc;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,OAAO,MAAM,IAAI,gBAEyC,MAAM,CAAC,UAAU,CACzE,WAAU,KAAsB;EAC9B,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,MAAM;EACnC,MAAM,YAAY,GAAG,OAAO,MAAM,CAAC,MAAM;EACzC,OAAO,MAAM,CAAC,IAAI,CAAC;IACjB,WAAW,EAAG,IAAI,IAAI;MACpB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC;MAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE;QAC7B,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,gBAAgB,EAAE,GAAG,GAAG,CAAC;MAC9D;MACA,OAAO,KAAK;IACd,CAAC;IACD,MAAM,EAAE,MAAM,CAAC;GAChB,CAAC;AACJ,CAAC,EACD,CAAC,MAAM,EAAE,IAAI,KAAK,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,OAAO,MAAM,KAAK,GAAI,IAAqB,IACzC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC","ignoreList":[]}
|
package/src/Crypto.ts
DELETED
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defines a platform-independent service for cryptographic operations.
|
|
3
|
-
*
|
|
4
|
-
* Runtime packages provide concrete implementations backed by the host
|
|
5
|
-
* platform's cryptography APIs. This module defines the service interface and a
|
|
6
|
-
* constructor from random-byte and digest primitives. The service provides
|
|
7
|
-
* secure random bytes and numbers, UUIDv4 and UUIDv7 generation, shuffling, and
|
|
8
|
-
* SHA message digests.
|
|
9
|
-
*
|
|
10
|
-
* @stability unstable
|
|
11
|
-
* @since 4.0.0
|
|
12
|
-
*/
|
|
13
|
-
import * as Context from "./Context.ts"
|
|
14
|
-
import * as Effect from "./Effect.ts"
|
|
15
|
-
import * as random from "./internal/random.ts"
|
|
16
|
-
import * as Ulid from "./internal/ulid.ts"
|
|
17
|
-
import * as Uuid from "./internal/uuid.ts"
|
|
18
|
-
import * as PlatformError from "./PlatformError.ts"
|
|
19
|
-
|
|
20
|
-
const TypeId = "~effect/Crypto"
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Digest algorithms supported by the platform `Crypto` service.
|
|
24
|
-
*
|
|
25
|
-
* **Gotchas**
|
|
26
|
-
*
|
|
27
|
-
* SHA-1 is included for interoperability with existing protocols. Do not use
|
|
28
|
-
* SHA-1 for new security-sensitive designs.
|
|
29
|
-
*
|
|
30
|
-
* **Example** (Using a digest algorithm)
|
|
31
|
-
*
|
|
32
|
-
* ```ts import.meta.vitest
|
|
33
|
-
* import { Crypto } from "effect"
|
|
34
|
-
*
|
|
35
|
-
* const algorithm: Crypto.DigestAlgorithm = "SHA-256"
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @stability unstable
|
|
39
|
-
* @category models
|
|
40
|
-
* @since 4.0.0
|
|
41
|
-
*/
|
|
42
|
-
export type DigestAlgorithm = "SHA-1" | "SHA-256" | "SHA-384" | "SHA-512"
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Platform-agnostic cryptographic operations.
|
|
46
|
-
*
|
|
47
|
-
* **Details**
|
|
48
|
-
*
|
|
49
|
-
* `Crypto` implementations must use cryptographically secure platform APIs.
|
|
50
|
-
* The random generator helpers are derived by the `make` constructor from
|
|
51
|
-
* the random methods on this service.
|
|
52
|
-
*
|
|
53
|
-
* **Example** (Using cryptographic operations)
|
|
54
|
-
*
|
|
55
|
-
* ```ts import.meta.vitest
|
|
56
|
-
* import { Crypto, Effect, Layer } from "effect"
|
|
57
|
-
*
|
|
58
|
-
* const TestCrypto = Layer.succeed(
|
|
59
|
-
* Crypto.Crypto,
|
|
60
|
-
* Crypto.make({
|
|
61
|
-
* randomBytes: (size) => new Uint8Array(size),
|
|
62
|
-
* digest: (_algorithm, data) => Effect.succeed(data)
|
|
63
|
-
* })
|
|
64
|
-
* )
|
|
65
|
-
*
|
|
66
|
-
* const program = Effect.gen(function*() {
|
|
67
|
-
* const crypto = yield* Crypto.Crypto
|
|
68
|
-
* const bytes = yield* crypto.randomBytes(16)
|
|
69
|
-
* const uuidv4 = yield* crypto.randomUUIDv4()
|
|
70
|
-
* const hash = yield* crypto.digest("SHA-256", bytes)
|
|
71
|
-
* return [bytes.length, uuidv4.length, hash.length]
|
|
72
|
-
* })
|
|
73
|
-
*
|
|
74
|
-
* await Effect.runPromise(Effect.provide(program, TestCrypto)) // => [16, 36, 16]
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @stability unstable
|
|
78
|
-
* @category services
|
|
79
|
-
* @since 4.0.0
|
|
80
|
-
*/
|
|
81
|
-
export interface Crypto {
|
|
82
|
-
readonly [TypeId]: typeof TypeId
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Generates a random integer in the range Number.MIN_SAFE_INTEGER to
|
|
86
|
-
* Number.MAX_SAFE_INTEGER (both inclusive).
|
|
87
|
-
*/
|
|
88
|
-
nextIntUnsafe(): number
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Generates a random number in the range 0 (inclusive) to 1 (exclusive).
|
|
92
|
-
*/
|
|
93
|
-
nextDoubleUnsafe(): number
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Generates cryptographically secure random bytes.
|
|
97
|
-
*/
|
|
98
|
-
randomBytes(size: number): Effect.Effect<Uint8Array, PlatformError.PlatformError>
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Computes a cryptographic digest for the supplied data.
|
|
102
|
-
*/
|
|
103
|
-
digest(
|
|
104
|
-
algorithm: DigestAlgorithm,
|
|
105
|
-
data: Uint8Array
|
|
106
|
-
): Effect.Effect<Uint8Array, PlatformError.PlatformError>
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Generates a cryptographically secure random number between 0 (inclusive)
|
|
110
|
-
* and 1 (exclusive).
|
|
111
|
-
*/
|
|
112
|
-
readonly random: Effect.Effect<number>
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Generates a cryptographically secure random boolean.
|
|
116
|
-
*/
|
|
117
|
-
readonly randomBoolean: Effect.Effect<boolean>
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Generates a cryptographically secure random integer between
|
|
121
|
-
* `Number.MIN_SAFE_INTEGER` and `Number.MAX_SAFE_INTEGER` (both inclusive).
|
|
122
|
-
*/
|
|
123
|
-
readonly randomInt: Effect.Effect<number>
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Generates a cryptographically secure random number between `min`
|
|
127
|
-
* (inclusive) and `max` (exclusive).
|
|
128
|
-
*/
|
|
129
|
-
randomBetween(min: number, max: number): Effect.Effect<number>
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Generates a cryptographically secure random integer between `min` and `max`.
|
|
133
|
-
*
|
|
134
|
-
* **Details**
|
|
135
|
-
*
|
|
136
|
-
* The lower bound is rounded up with `Math.ceil` and the upper bound is
|
|
137
|
-
* rounded down with `Math.floor`. By default the range is inclusive; set
|
|
138
|
-
* `options.halfOpen: true` to exclude the upper bound.
|
|
139
|
-
*/
|
|
140
|
-
randomIntBetween(min: number, max: number, options?: {
|
|
141
|
-
readonly halfOpen?: boolean | undefined
|
|
142
|
-
}): Effect.Effect<number>
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Uses the cryptographically secure random generator to shuffle the supplied
|
|
146
|
-
* iterable.
|
|
147
|
-
*/
|
|
148
|
-
randomShuffle<A>(elements: Iterable<A>): Effect.Effect<Array<A>>
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Generates a cryptographically secure UUIDv4.
|
|
152
|
-
*
|
|
153
|
-
* **Details**
|
|
154
|
-
*
|
|
155
|
-
* The default `"hex"` format returns a lowercase, hyphenated UUID string
|
|
156
|
-
* (36 characters), not a bare hexadecimal string. The `"bytes"` format
|
|
157
|
-
* returns the 16 UUID bytes, including the version and variant bits.
|
|
158
|
-
*/
|
|
159
|
-
randomUUIDv4(options?: {
|
|
160
|
-
readonly format?: "hex" | undefined
|
|
161
|
-
}): Effect.Effect<string, PlatformError.PlatformError>
|
|
162
|
-
randomUUIDv4<Format extends "hex" | "bytes">(options: {
|
|
163
|
-
readonly format: Format
|
|
164
|
-
}): Effect.Effect<Format extends "bytes" ? Uint8Array : string, PlatformError.PlatformError>
|
|
165
|
-
randomUUIDv4(options?: {
|
|
166
|
-
readonly format?: "hex" | "bytes" | undefined
|
|
167
|
-
}): Effect.Effect<string | Uint8Array, PlatformError.PlatformError>
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Generates a cryptographically secure UUIDv7 using the `Clock` timestamp.
|
|
171
|
-
*
|
|
172
|
-
* **Details**
|
|
173
|
-
*
|
|
174
|
-
* The default `"hex"` format returns a lowercase, hyphenated UUID string
|
|
175
|
-
* (36 characters), not a bare hexadecimal string. The `"bytes"` format
|
|
176
|
-
* returns the 16 UUID bytes, including the timestamp, version and variant bits.
|
|
177
|
-
*/
|
|
178
|
-
randomUUIDv7(options?: {
|
|
179
|
-
readonly format?: "hex" | undefined
|
|
180
|
-
}): Effect.Effect<string, PlatformError.PlatformError>
|
|
181
|
-
randomUUIDv7<Format extends "hex" | "bytes">(options: {
|
|
182
|
-
readonly format: Format
|
|
183
|
-
}): Effect.Effect<Format extends "bytes" ? Uint8Array : string, PlatformError.PlatformError>
|
|
184
|
-
randomUUIDv7(options?: {
|
|
185
|
-
readonly format?: "hex" | "bytes" | undefined
|
|
186
|
-
}): Effect.Effect<string | Uint8Array, PlatformError.PlatformError>
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Generates a cryptographically secure ULID string.
|
|
190
|
-
*
|
|
191
|
-
* **Details**
|
|
192
|
-
*
|
|
193
|
-
* ULIDs contain 26 uppercase Crockford base32 characters. The first 10 encode
|
|
194
|
-
* the `Clock` timestamp in milliseconds; the remaining 16 encode 80 random
|
|
195
|
-
* bits. ULIDs sort by timestamp, with no ordering guarantee within the same
|
|
196
|
-
* millisecond.
|
|
197
|
-
*
|
|
198
|
-
* Timestamp normalization matches UUIDv7: fractions are truncated, values are
|
|
199
|
-
* clamped to the 48-bit range, and `NaN` encodes as zero.
|
|
200
|
-
*/
|
|
201
|
-
readonly randomULID: Effect.Effect<string, PlatformError.PlatformError>
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Service tag for platform cryptography.
|
|
206
|
-
*
|
|
207
|
-
* **When to use**
|
|
208
|
-
*
|
|
209
|
-
* Use when you need to provide or retrieve the full platform cryptography
|
|
210
|
-
* service from an effect's context.
|
|
211
|
-
*
|
|
212
|
-
* **Details**
|
|
213
|
-
*
|
|
214
|
-
* Providing this service supplies platform-agnostic cryptographic operations
|
|
215
|
-
* such as hashing, UUID generation, and secure random values.
|
|
216
|
-
*
|
|
217
|
-
* @see {@link make} for constructing a Crypto service from primitive operations
|
|
218
|
-
*
|
|
219
|
-
* @stability unstable
|
|
220
|
-
* @category services
|
|
221
|
-
* @since 4.0.0
|
|
222
|
-
*/
|
|
223
|
-
export const Crypto: Context.Service<Crypto, Crypto> = Context.Service("effect/Crypto")
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Creates a `Crypto` service from the primitive implementation, deriving the
|
|
227
|
-
* random generator helpers and UUID generation from those primitives.
|
|
228
|
-
*
|
|
229
|
-
* **When to use**
|
|
230
|
-
*
|
|
231
|
-
* Use to build a Crypto service for a platform integration, test layer, or
|
|
232
|
-
* custom runtime from primitive random-byte and digest operations.
|
|
233
|
-
*
|
|
234
|
-
* **Details**
|
|
235
|
-
*
|
|
236
|
-
* The constructor derives random numbers, booleans, integer ranges, shuffling,
|
|
237
|
-
* and UUID generation from `impl.randomBytes`. Digest operations delegate to
|
|
238
|
-
* `impl.digest`.
|
|
239
|
-
*
|
|
240
|
-
* **Gotchas**
|
|
241
|
-
*
|
|
242
|
-
* `impl.randomBytes` must return cryptographically secure bytes of the
|
|
243
|
-
* requested length. UUID formatting mutates the byte array returned for UUID
|
|
244
|
-
* generation, so the implementation should return a fresh array for each call.
|
|
245
|
-
*
|
|
246
|
-
* **Example** (Creating a Crypto service)
|
|
247
|
-
*
|
|
248
|
-
* ```ts import.meta.vitest
|
|
249
|
-
* import { Crypto, Effect } from "effect"
|
|
250
|
-
*
|
|
251
|
-
* const testCrypto = Crypto.make({
|
|
252
|
-
* randomBytes: (size) => new Uint8Array(size),
|
|
253
|
-
* digest: (_algorithm, data) => Effect.succeed(data)
|
|
254
|
-
* })
|
|
255
|
-
*
|
|
256
|
-
* await Effect.runPromise(testCrypto.randomBytes(4)) // => new Uint8Array([0, 0, 0, 0])
|
|
257
|
-
* ```
|
|
258
|
-
*
|
|
259
|
-
* @stability unstable
|
|
260
|
-
* @category constructors
|
|
261
|
-
* @since 4.0.0
|
|
262
|
-
*/
|
|
263
|
-
export const make = (
|
|
264
|
-
impl: {
|
|
265
|
-
readonly randomBytes: (size: number) => Uint8Array
|
|
266
|
-
readonly digest: (
|
|
267
|
-
algorithm: DigestAlgorithm,
|
|
268
|
-
data: Uint8Array
|
|
269
|
-
) => Effect.Effect<Uint8Array, PlatformError.PlatformError>
|
|
270
|
-
}
|
|
271
|
-
): Crypto => {
|
|
272
|
-
const randomBytesUnsafe = impl.randomBytes
|
|
273
|
-
|
|
274
|
-
const randomBytes: Crypto["randomBytes"] = (size) => Effect.map(validateSize("randomBytes", size), randomBytesUnsafe)
|
|
275
|
-
|
|
276
|
-
const readUint53 = (bytes: Uint8Array): number =>
|
|
277
|
-
((bytes[0] & 0x1f) * 2 ** 48) + (bytes[1] * 2 ** 40) + (bytes[2] * 2 ** 32) +
|
|
278
|
-
(bytes[3] * 2 ** 24) + (bytes[4] * 2 ** 16) + (bytes[5] * 2 ** 8) + bytes[6]
|
|
279
|
-
|
|
280
|
-
const nextDoubleUnsafe = (): number => readUint53(randomBytesUnsafe(7)) / 2 ** 53
|
|
281
|
-
|
|
282
|
-
const nextIntUnsafe = (): number => {
|
|
283
|
-
while (true) {
|
|
284
|
-
const bytes = randomBytesUnsafe(7)
|
|
285
|
-
const value = readUint53(bytes)
|
|
286
|
-
if ((bytes[0] & 0x20) === 0) {
|
|
287
|
-
return value + Number.MIN_SAFE_INTEGER
|
|
288
|
-
}
|
|
289
|
-
if (value < Number.MAX_SAFE_INTEGER) {
|
|
290
|
-
return value + 1
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
return Crypto.of({
|
|
296
|
-
[TypeId]: TypeId,
|
|
297
|
-
randomBytes,
|
|
298
|
-
nextDoubleUnsafe,
|
|
299
|
-
nextIntUnsafe,
|
|
300
|
-
digest: impl.digest,
|
|
301
|
-
random: Effect.sync(() => nextDoubleUnsafe()),
|
|
302
|
-
randomBoolean: Effect.sync(() => nextDoubleUnsafe() > 0.5),
|
|
303
|
-
randomInt: Effect.sync(() => nextIntUnsafe()),
|
|
304
|
-
randomBetween: (min, max) => Effect.sync(() => random.nextBetween(min, max, nextDoubleUnsafe())),
|
|
305
|
-
randomIntBetween(min, max, options) {
|
|
306
|
-
const extra = options?.halfOpen === true ? 0 : 1
|
|
307
|
-
return Effect.sync(() => {
|
|
308
|
-
const minInt = Math.ceil(min)
|
|
309
|
-
const maxInt = Math.floor(max)
|
|
310
|
-
return Math.floor(nextDoubleUnsafe() * (maxInt - minInt + extra)) + minInt
|
|
311
|
-
})
|
|
312
|
-
},
|
|
313
|
-
randomShuffle: (elements) =>
|
|
314
|
-
Effect.sync(() => {
|
|
315
|
-
const buffer = Array.from(elements)
|
|
316
|
-
for (let i = buffer.length - 1; i >= 1; i = i - 1) {
|
|
317
|
-
const index = Math.min(i, Math.floor(nextDoubleUnsafe() * (i + 1)))
|
|
318
|
-
const value = buffer[i]!
|
|
319
|
-
buffer[i] = buffer[index]!
|
|
320
|
-
buffer[index] = value
|
|
321
|
-
}
|
|
322
|
-
return buffer
|
|
323
|
-
}),
|
|
324
|
-
randomUUIDv4: ((options?: { readonly format?: "hex" | "bytes" | undefined }) =>
|
|
325
|
-
Effect.sync(() => {
|
|
326
|
-
const bytes = Uuid.v4Bytes(randomBytesUnsafe(16))
|
|
327
|
-
return options?.format === "bytes" ? bytes : Uuid.stringify(bytes)
|
|
328
|
-
})) as Crypto["randomUUIDv4"],
|
|
329
|
-
randomUUIDv7: ((options?: { readonly format?: "hex" | "bytes" | undefined }) =>
|
|
330
|
-
Effect.clockWith((clock) => {
|
|
331
|
-
const bytes = Uuid.v7Bytes(clock.currentTimeMillisUnsafe(), randomBytesUnsafe(16))
|
|
332
|
-
return Effect.succeed(options?.format === "bytes" ? bytes : Uuid.stringify(bytes))
|
|
333
|
-
})) as Crypto["randomUUIDv7"],
|
|
334
|
-
randomULID: Effect.clockWith((clock) =>
|
|
335
|
-
Effect.succeed(Ulid.ulidString(clock.currentTimeMillisUnsafe(), randomBytesUnsafe(10)))
|
|
336
|
-
)
|
|
337
|
-
})
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const validateSize = (method: string, size: number): Effect.Effect<number, PlatformError.PlatformError> =>
|
|
341
|
-
Number.isSafeInteger(size) && size >= 0
|
|
342
|
-
? Effect.succeed(size)
|
|
343
|
-
: Effect.fail(PlatformError.badArgument({
|
|
344
|
-
module: "Crypto",
|
|
345
|
-
method,
|
|
346
|
-
description: "size must be a non-negative safe integer"
|
|
347
|
-
}))
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provides a deterministic implementation of the Effect `Crypto` service for
|
|
3
|
-
* tests.
|
|
4
|
-
*
|
|
5
|
-
* Random bytes, numbers, shuffles, UUIDs, and ULIDs are derived from a seeded
|
|
6
|
-
* pseudo-random generator. Digest operations are delegated to an underlying
|
|
7
|
-
* platform `Crypto` service.
|
|
8
|
-
*
|
|
9
|
-
* @stability unstable
|
|
10
|
-
* @since 4.0.0
|
|
11
|
-
*/
|
|
12
|
-
import * as Crypto from "../Crypto.ts"
|
|
13
|
-
import * as Effect from "../Effect.ts"
|
|
14
|
-
import * as Layer from "../Layer.ts"
|
|
15
|
-
import * as Random from "../Random.ts"
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Creates a deterministic `Crypto` service using a seeded pseudo-random
|
|
19
|
-
* generator.
|
|
20
|
-
*
|
|
21
|
-
* **When to use**
|
|
22
|
-
*
|
|
23
|
-
* Use to construct a `Crypto` service whose random operations are reproducible
|
|
24
|
-
* in tests while preserving the digest implementation of a platform `Crypto`
|
|
25
|
-
* service.
|
|
26
|
-
*
|
|
27
|
-
* **Details**
|
|
28
|
-
*
|
|
29
|
-
* The effect requires an existing `Crypto` service and delegates digest
|
|
30
|
-
* operations to it. Each evaluation starts a new random sequence from `seed`;
|
|
31
|
-
* every other random operation is derived from that sequence.
|
|
32
|
-
*
|
|
33
|
-
* **Gotchas**
|
|
34
|
-
*
|
|
35
|
-
* The generated values are deterministic and must not be used for
|
|
36
|
-
* security-sensitive purposes. The sequence depends on the order in which
|
|
37
|
-
* random operations are evaluated. UUIDv7 and ULID values also include the
|
|
38
|
-
* current `Clock` time, which must be controlled separately when their complete
|
|
39
|
-
* output needs to be reproducible.
|
|
40
|
-
*
|
|
41
|
-
* @see {@link layer} for providing the service as a layer
|
|
42
|
-
*
|
|
43
|
-
* @stability unstable
|
|
44
|
-
* @category constructors
|
|
45
|
-
* @since 4.0.0
|
|
46
|
-
*/
|
|
47
|
-
export const make: (
|
|
48
|
-
seed: string | number
|
|
49
|
-
) => Effect.Effect<Crypto.Crypto, never, Crypto.Crypto> = Effect.fnUntraced(
|
|
50
|
-
function*(_seed: string | number) {
|
|
51
|
-
const crypto = yield* Crypto.Crypto
|
|
52
|
-
const seededRandom = yield* Random.Random
|
|
53
|
-
return Crypto.make({
|
|
54
|
-
randomBytes: (size) => {
|
|
55
|
-
const bytes = new Uint8Array(size)
|
|
56
|
-
for (let i = 0; i < size; i++) {
|
|
57
|
-
bytes[i] = Math.floor(seededRandom.nextDoubleUnsafe() * 256)
|
|
58
|
-
}
|
|
59
|
-
return bytes
|
|
60
|
-
},
|
|
61
|
-
digest: crypto.digest
|
|
62
|
-
})
|
|
63
|
-
},
|
|
64
|
-
(effect, seed) => Random.withSeed(effect, seed)
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Creates a layer that provides deterministic `Crypto` random operations from
|
|
69
|
-
* a seed.
|
|
70
|
-
*
|
|
71
|
-
* **When to use**
|
|
72
|
-
*
|
|
73
|
-
* Use to provide reproducible random bytes, numbers, shuffles, UUIDs, and ULIDs
|
|
74
|
-
* to an Effect program under test.
|
|
75
|
-
*
|
|
76
|
-
* **Details**
|
|
77
|
-
*
|
|
78
|
-
* The layer requires an existing platform `Crypto` service whose digest
|
|
79
|
-
* implementation is retained. Each layer build starts the random sequence from
|
|
80
|
-
* `seed`.
|
|
81
|
-
*
|
|
82
|
-
* **Gotchas**
|
|
83
|
-
*
|
|
84
|
-
* UUIDv7 and ULID values also depend on the current `Clock`. Provide a test
|
|
85
|
-
* clock when their complete output needs to be reproducible.
|
|
86
|
-
*
|
|
87
|
-
* @see {@link make} for constructing the service directly
|
|
88
|
-
*
|
|
89
|
-
* @stability unstable
|
|
90
|
-
* @category layers
|
|
91
|
-
* @since 4.0.0
|
|
92
|
-
*/
|
|
93
|
-
export const layer = (seed: string | number): Layer.Layer<Crypto.Crypto, never, Crypto.Crypto> =>
|
|
94
|
-
Layer.effect(Crypto.Crypto, make(seed))
|