@effect/platform-deno 4.0.0-beta.104
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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/DenoChildProcessSpawner.d.ts +39 -0
- package/dist/DenoChildProcessSpawner.d.ts.map +1 -0
- package/dist/DenoChildProcessSpawner.js +311 -0
- package/dist/DenoChildProcessSpawner.js.map +1 -0
- package/dist/DenoClusterHttp.d.ts +60 -0
- package/dist/DenoClusterHttp.d.ts.map +1 -0
- package/dist/DenoClusterHttp.js +78 -0
- package/dist/DenoClusterHttp.js.map +1 -0
- package/dist/DenoClusterSocket.d.ts +65 -0
- package/dist/DenoClusterSocket.d.ts.map +1 -0
- package/dist/DenoClusterSocket.js +101 -0
- package/dist/DenoClusterSocket.js.map +1 -0
- package/dist/DenoCrypto.d.ts +25 -0
- package/dist/DenoCrypto.d.ts.map +1 -0
- package/dist/DenoCrypto.js +52 -0
- package/dist/DenoCrypto.js.map +1 -0
- package/dist/DenoFileSystem.d.ts +10 -0
- package/dist/DenoFileSystem.d.ts.map +1 -0
- package/dist/DenoFileSystem.js +331 -0
- package/dist/DenoFileSystem.js.map +1 -0
- package/dist/DenoHttpClient.d.ts +9 -0
- package/dist/DenoHttpClient.d.ts.map +1 -0
- package/dist/DenoHttpClient.js +9 -0
- package/dist/DenoHttpClient.js.map +1 -0
- package/dist/DenoHttpPlatform.d.ts +34 -0
- package/dist/DenoHttpPlatform.d.ts.map +1 -0
- package/dist/DenoHttpPlatform.js +88 -0
- package/dist/DenoHttpPlatform.js.map +1 -0
- package/dist/DenoHttpServer.d.ts +99 -0
- package/dist/DenoHttpServer.d.ts.map +1 -0
- package/dist/DenoHttpServer.js +353 -0
- package/dist/DenoHttpServer.js.map +1 -0
- package/dist/DenoHttpServerRequest.d.ts +18 -0
- package/dist/DenoHttpServerRequest.d.ts.map +1 -0
- package/dist/DenoHttpServerRequest.js +8 -0
- package/dist/DenoHttpServerRequest.js.map +1 -0
- package/dist/DenoKeyValueStore.d.ts +22 -0
- package/dist/DenoKeyValueStore.d.ts.map +1 -0
- package/dist/DenoKeyValueStore.js +21 -0
- package/dist/DenoKeyValueStore.js.map +1 -0
- package/dist/DenoMultipart.d.ts +32 -0
- package/dist/DenoMultipart.d.ts.map +1 -0
- package/dist/DenoMultipart.js +25 -0
- package/dist/DenoMultipart.js.map +1 -0
- package/dist/DenoPath.d.ts +43 -0
- package/dist/DenoPath.d.ts.map +1 -0
- package/dist/DenoPath.js +81 -0
- package/dist/DenoPath.js.map +1 -0
- package/dist/DenoRedis.d.ts +60 -0
- package/dist/DenoRedis.d.ts.map +1 -0
- package/dist/DenoRedis.js +76 -0
- package/dist/DenoRedis.js.map +1 -0
- package/dist/DenoRuntime.d.ts +36 -0
- package/dist/DenoRuntime.d.ts.map +1 -0
- package/dist/DenoRuntime.js +35 -0
- package/dist/DenoRuntime.js.map +1 -0
- package/dist/DenoServices.d.ts +34 -0
- package/dist/DenoServices.d.ts.map +1 -0
- package/dist/DenoServices.js +16 -0
- package/dist/DenoServices.js.map +1 -0
- package/dist/DenoSocket.d.ts +99 -0
- package/dist/DenoSocket.d.ts.map +1 -0
- package/dist/DenoSocket.js +192 -0
- package/dist/DenoSocket.js.map +1 -0
- package/dist/DenoSocketServer.d.ts +70 -0
- package/dist/DenoSocketServer.d.ts.map +1 -0
- package/dist/DenoSocketServer.js +68 -0
- package/dist/DenoSocketServer.js.map +1 -0
- package/dist/DenoStdio.d.ts +11 -0
- package/dist/DenoStdio.d.ts.map +1 -0
- package/dist/DenoStdio.js +39 -0
- package/dist/DenoStdio.js.map +1 -0
- package/dist/DenoTerminal.d.ts +21 -0
- package/dist/DenoTerminal.d.ts.map +1 -0
- package/dist/DenoTerminal.js +27 -0
- package/dist/DenoTerminal.js.map +1 -0
- package/dist/DenoWorker.d.ts +17 -0
- package/dist/DenoWorker.d.ts.map +1 -0
- package/dist/DenoWorker.js +54 -0
- package/dist/DenoWorker.js.map +1 -0
- package/dist/DenoWorkerRunner.d.ts +24 -0
- package/dist/DenoWorkerRunner.d.ts.map +1 -0
- package/dist/DenoWorkerRunner.js +150 -0
- package/dist/DenoWorkerRunner.js.map +1 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/denoSocketServer.d.ts +7 -0
- package/dist/internal/denoSocketServer.d.ts.map +1 -0
- package/dist/internal/denoSocketServer.js +55 -0
- package/dist/internal/denoSocketServer.js.map +1 -0
- package/dist/internal/error.d.ts +4 -0
- package/dist/internal/error.d.ts.map +1 -0
- package/dist/internal/error.js +46 -0
- package/dist/internal/error.js.map +1 -0
- package/package.json +72 -0
- package/src/DenoChildProcessSpawner.ts +439 -0
- package/src/DenoClusterHttp.ts +156 -0
- package/src/DenoClusterSocket.ts +197 -0
- package/src/DenoCrypto.ts +63 -0
- package/src/DenoFileSystem.ts +497 -0
- package/src/DenoHttpClient.ts +9 -0
- package/src/DenoHttpPlatform.ts +93 -0
- package/src/DenoHttpServer.ts +535 -0
- package/src/DenoHttpServerRequest.ts +18 -0
- package/src/DenoKeyValueStore.ts +28 -0
- package/src/DenoMultipart.ts +53 -0
- package/src/DenoPath.ts +102 -0
- package/src/DenoRedis.ts +113 -0
- package/src/DenoRuntime.ts +73 -0
- package/src/DenoServices.ts +49 -0
- package/src/DenoSocket.ts +318 -0
- package/src/DenoSocketServer.ts +120 -0
- package/src/DenoStdio.ts +51 -0
- package/src/DenoTerminal.ts +32 -0
- package/src/DenoWorker.ts +75 -0
- package/src/DenoWorkerRunner.ts +175 -0
- package/src/index.ts +110 -0
- package/src/internal/denoSocketServer.ts +89 -0
- package/src/internal/error.ts +63 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native Deno socket layers for Effect Cluster runners.
|
|
3
|
+
*
|
|
4
|
+
* The main `layer` builds a sharding layer for socket transport, choosing
|
|
5
|
+
* serialization, runner health checks, runner storage, message storage, and
|
|
6
|
+
* optional client-only mode from the supplied options. Unlike Node sockets,
|
|
7
|
+
* Deno connections have no native idle-timeout option, so peer connections use
|
|
8
|
+
* only the one-second open timeout.
|
|
9
|
+
*
|
|
10
|
+
* @since 4.0.0
|
|
11
|
+
*/
|
|
12
|
+
import type * as Config from "effect/Config"
|
|
13
|
+
import * as Effect from "effect/Effect"
|
|
14
|
+
import * as FileSystem from "effect/FileSystem"
|
|
15
|
+
import * as Layer from "effect/Layer"
|
|
16
|
+
import * as Option from "effect/Option"
|
|
17
|
+
import * as K8sHttpClient from "effect/unstable/cluster/K8sHttpClient"
|
|
18
|
+
import * as MessageStorage from "effect/unstable/cluster/MessageStorage"
|
|
19
|
+
import * as RunnerHealth from "effect/unstable/cluster/RunnerHealth"
|
|
20
|
+
import * as Runners from "effect/unstable/cluster/Runners"
|
|
21
|
+
import * as RunnerStorage from "effect/unstable/cluster/RunnerStorage"
|
|
22
|
+
import type { Sharding } from "effect/unstable/cluster/Sharding"
|
|
23
|
+
import * as ShardingConfig from "effect/unstable/cluster/ShardingConfig"
|
|
24
|
+
import * as SocketRunner from "effect/unstable/cluster/SocketRunner"
|
|
25
|
+
import * as SqlMessageStorage from "effect/unstable/cluster/SqlMessageStorage"
|
|
26
|
+
import * as SqlRunnerStorage from "effect/unstable/cluster/SqlRunnerStorage"
|
|
27
|
+
import * as RpcClient from "effect/unstable/rpc/RpcClient"
|
|
28
|
+
import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization"
|
|
29
|
+
import { Socket } from "effect/unstable/socket/Socket"
|
|
30
|
+
import type * as SocketServer from "effect/unstable/socket/SocketServer"
|
|
31
|
+
import type { SqlClient } from "effect/unstable/sql/SqlClient"
|
|
32
|
+
import * as DenoCrypto from "./DenoCrypto.ts"
|
|
33
|
+
import * as DenoFileSystem from "./DenoFileSystem.ts"
|
|
34
|
+
import * as DenoHttpClient from "./DenoHttpClient.ts"
|
|
35
|
+
import * as DenoSocket from "./DenoSocket.ts"
|
|
36
|
+
import * as DenoSocketServer from "./DenoSocketServer.ts"
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Provides the cluster `RpcClientProtocol` using native Deno TCP sockets.
|
|
40
|
+
*
|
|
41
|
+
* @category layers
|
|
42
|
+
* @since 4.0.0
|
|
43
|
+
*/
|
|
44
|
+
export const layerClientProtocol: Layer.Layer<
|
|
45
|
+
Runners.RpcClientProtocol,
|
|
46
|
+
never,
|
|
47
|
+
RpcSerialization.RpcSerialization
|
|
48
|
+
> = Layer.effect(Runners.RpcClientProtocol)(
|
|
49
|
+
Effect.gen(function*() {
|
|
50
|
+
const serialization = yield* RpcSerialization.RpcSerialization
|
|
51
|
+
return Effect.fnUntraced(function*(address) {
|
|
52
|
+
const socket = yield* DenoSocket.makeTcp({
|
|
53
|
+
openTimeout: 1000,
|
|
54
|
+
hostname: address.host,
|
|
55
|
+
port: address.port
|
|
56
|
+
})
|
|
57
|
+
return yield* RpcClient.makeProtocolSocket().pipe(
|
|
58
|
+
Effect.provideService(Socket, socket),
|
|
59
|
+
Effect.provideService(RpcSerialization.RpcSerialization, serialization)
|
|
60
|
+
)
|
|
61
|
+
}, Effect.orDie)
|
|
62
|
+
})
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Provides the native Deno socket server used by cluster runners, listening on
|
|
67
|
+
* `ShardingConfig.runnerListenAddress` or `runnerAddress`.
|
|
68
|
+
*
|
|
69
|
+
* @category layers
|
|
70
|
+
* @since 4.0.0
|
|
71
|
+
*/
|
|
72
|
+
export const layerSocketServer: Layer.Layer<
|
|
73
|
+
SocketServer.SocketServer,
|
|
74
|
+
SocketServer.SocketServerError,
|
|
75
|
+
ShardingConfig.ShardingConfig
|
|
76
|
+
> = Effect.gen(function*() {
|
|
77
|
+
const config = yield* ShardingConfig.ShardingConfig
|
|
78
|
+
const listenAddress = Option.orElse(config.runnerListenAddress, () => config.runnerAddress)
|
|
79
|
+
if (Option.isNone(listenAddress)) {
|
|
80
|
+
return yield* Effect.die("layerSocketServer: ShardingConfig.runnerListenAddress is None")
|
|
81
|
+
}
|
|
82
|
+
return DenoSocketServer.layer({
|
|
83
|
+
hostname: listenAddress.value.host,
|
|
84
|
+
port: listenAddress.value.port
|
|
85
|
+
})
|
|
86
|
+
}).pipe(Layer.unwrap)
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Creates Deno socket cluster layers, configuring serialization, storage,
|
|
90
|
+
* runner health, and optional client-only mode.
|
|
91
|
+
*
|
|
92
|
+
* @category layers
|
|
93
|
+
* @since 4.0.0
|
|
94
|
+
*/
|
|
95
|
+
export const layer = <
|
|
96
|
+
const ClientOnly extends boolean = false,
|
|
97
|
+
const Storage extends "local" | "sql" | "byo" = never
|
|
98
|
+
>(
|
|
99
|
+
options?: {
|
|
100
|
+
readonly serialization?: "msgpack" | "ndjson" | undefined
|
|
101
|
+
readonly serializationMaxBufferSize?: number | "unbounded" | undefined
|
|
102
|
+
readonly clientOnly?: ClientOnly | undefined
|
|
103
|
+
readonly storage?: Storage | undefined
|
|
104
|
+
readonly runnerHealth?: "ping" | "k8s" | undefined
|
|
105
|
+
readonly runnerHealthK8s?: {
|
|
106
|
+
readonly namespace?: string | undefined
|
|
107
|
+
readonly labelSelector?: string | undefined
|
|
108
|
+
} | undefined
|
|
109
|
+
readonly shardingConfig?: Partial<ShardingConfig.ShardingConfig["Service"]> | undefined
|
|
110
|
+
}
|
|
111
|
+
): ClientOnly extends true ? Layer.Layer<
|
|
112
|
+
Sharding | Runners.Runners | ("byo" extends Storage ? never : MessageStorage.MessageStorage),
|
|
113
|
+
Config.ConfigError,
|
|
114
|
+
"local" extends Storage ? never
|
|
115
|
+
: "byo" extends Storage ? (MessageStorage.MessageStorage | RunnerStorage.RunnerStorage)
|
|
116
|
+
: SqlClient
|
|
117
|
+
> :
|
|
118
|
+
Layer.Layer<
|
|
119
|
+
Sharding | Runners.Runners | ("byo" extends Storage ? never : MessageStorage.MessageStorage),
|
|
120
|
+
SocketServer.SocketServerError | Config.ConfigError,
|
|
121
|
+
"local" extends Storage ? never
|
|
122
|
+
: "byo" extends Storage ? (MessageStorage.MessageStorage | RunnerStorage.RunnerStorage)
|
|
123
|
+
: SqlClient
|
|
124
|
+
> =>
|
|
125
|
+
{
|
|
126
|
+
const layer: Layer.Layer<any, any, any> = options?.clientOnly
|
|
127
|
+
? Layer.provide(SocketRunner.layerClientOnly, layerClientProtocol)
|
|
128
|
+
: Layer.provide(SocketRunner.layer, [layerSocketServer, layerClientProtocol])
|
|
129
|
+
|
|
130
|
+
const runnerHealth: Layer.Layer<any, any, any> = options?.clientOnly
|
|
131
|
+
? Layer.empty as any
|
|
132
|
+
: options?.runnerHealth === "k8s"
|
|
133
|
+
? RunnerHealth.layerK8s(options.runnerHealthK8s).pipe(
|
|
134
|
+
Layer.provide(layerK8sHttpClient)
|
|
135
|
+
)
|
|
136
|
+
: RunnerHealth.layerPing.pipe(
|
|
137
|
+
Layer.provide(Runners.layerRpc),
|
|
138
|
+
Layer.provide(layerClientProtocol)
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
return layer.pipe(
|
|
142
|
+
Layer.provide(runnerHealth),
|
|
143
|
+
Layer.provideMerge(
|
|
144
|
+
options?.storage === "local"
|
|
145
|
+
? MessageStorage.layerNoop
|
|
146
|
+
: options?.storage === "byo"
|
|
147
|
+
? Layer.empty
|
|
148
|
+
: Layer.orDie(SqlMessageStorage.layer).pipe(Layer.provide(DenoCrypto.layer))
|
|
149
|
+
),
|
|
150
|
+
Layer.provide(
|
|
151
|
+
options?.storage === "local"
|
|
152
|
+
? RunnerStorage.layerMemory
|
|
153
|
+
: options?.storage === "byo"
|
|
154
|
+
? Layer.empty
|
|
155
|
+
: Layer.orDie(SqlRunnerStorage.layer)
|
|
156
|
+
),
|
|
157
|
+
Layer.provide(ShardingConfig.layerFromEnv(options?.shardingConfig)),
|
|
158
|
+
Layer.provide(
|
|
159
|
+
options?.serialization === "ndjson"
|
|
160
|
+
? RpcSerialization.layerNdjsonWith({ maxBufferSize: options?.serializationMaxBufferSize })
|
|
161
|
+
: RpcSerialization.layerMsgPackWith({ maxBufferSize: options?.serializationMaxBufferSize })
|
|
162
|
+
)
|
|
163
|
+
) as any
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Layer that provides `K8sHttpClient`, using a scoped native Deno HTTP client
|
|
168
|
+
* with the Kubernetes service-account CA certificate when it is available.
|
|
169
|
+
*
|
|
170
|
+
* @category layers
|
|
171
|
+
* @since 4.0.0
|
|
172
|
+
*/
|
|
173
|
+
export const layerK8sHttpClient: Layer.Layer<K8sHttpClient.K8sHttpClient> = K8sHttpClient.layer.pipe(
|
|
174
|
+
Layer.provide(
|
|
175
|
+
Layer.fresh(DenoHttpClient.layer).pipe(
|
|
176
|
+
Layer.provide(Layer.effect(
|
|
177
|
+
DenoHttpClient.Fetch,
|
|
178
|
+
Effect.gen(function*() {
|
|
179
|
+
const fs = yield* FileSystem.FileSystem
|
|
180
|
+
const caCertOption = yield* fs.readFileString("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt").pipe(
|
|
181
|
+
Effect.option
|
|
182
|
+
)
|
|
183
|
+
if (Option.isNone(caCertOption)) {
|
|
184
|
+
return globalThis.fetch
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const client = yield* Effect.acquireRelease(
|
|
188
|
+
Effect.sync(() => Deno.createHttpClient({ caCerts: [caCertOption.value] })),
|
|
189
|
+
(client) => Effect.sync(() => client.close())
|
|
190
|
+
)
|
|
191
|
+
return ((input, init) => globalThis.fetch(input, { ...init, client } as any)) as typeof globalThis.fetch
|
|
192
|
+
})
|
|
193
|
+
))
|
|
194
|
+
)
|
|
195
|
+
),
|
|
196
|
+
Layer.provide(DenoFileSystem.layer)
|
|
197
|
+
)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deno-backed implementation of Effect's Crypto service.
|
|
3
|
+
*
|
|
4
|
+
* This module uses Deno's global Web Crypto API.
|
|
5
|
+
*
|
|
6
|
+
* @since 4.0.0
|
|
7
|
+
*/
|
|
8
|
+
import * as Context from "effect/Context"
|
|
9
|
+
import * as EffectCrypto from "effect/Crypto"
|
|
10
|
+
import * as Effect from "effect/Effect"
|
|
11
|
+
import * as Layer from "effect/Layer"
|
|
12
|
+
import * as PlatformError from "effect/PlatformError"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Provides the Web Crypto API used by the Crypto service implementation.
|
|
16
|
+
*
|
|
17
|
+
* @category services
|
|
18
|
+
* @since 4.0.0
|
|
19
|
+
*/
|
|
20
|
+
export const WebCrypto = Context.Reference<Crypto>("@effect/platform-deno/Crypto/WebCrypto", {
|
|
21
|
+
defaultValue: () => globalThis.crypto
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A layer that provides Effect's Crypto service using Deno's Web Crypto API.
|
|
26
|
+
*
|
|
27
|
+
* @category layers
|
|
28
|
+
* @since 4.0.0
|
|
29
|
+
*/
|
|
30
|
+
export const layer: Layer.Layer<EffectCrypto.Crypto> = Layer.effect(
|
|
31
|
+
EffectCrypto.Crypto,
|
|
32
|
+
Effect.gen(function*() {
|
|
33
|
+
const crypto = yield* WebCrypto
|
|
34
|
+
const randomBytes = (size: number): Uint8Array => {
|
|
35
|
+
const bytes = new Uint8Array(size)
|
|
36
|
+
for (let offset = 0; offset < bytes.length; offset += 65_536) {
|
|
37
|
+
crypto.getRandomValues(bytes.subarray(offset, offset + 65_536))
|
|
38
|
+
}
|
|
39
|
+
return bytes
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const digest: EffectCrypto.Crypto["digest"] = (algorithm, data) =>
|
|
43
|
+
Effect.map(
|
|
44
|
+
Effect.tryPromise({
|
|
45
|
+
try: () => crypto.subtle.digest(algorithm, new Uint8Array(data)),
|
|
46
|
+
catch: (cause) =>
|
|
47
|
+
PlatformError.systemError({
|
|
48
|
+
module: "Crypto",
|
|
49
|
+
method: "digest",
|
|
50
|
+
_tag: "Unknown",
|
|
51
|
+
description: "Could not compute digest",
|
|
52
|
+
cause
|
|
53
|
+
})
|
|
54
|
+
}),
|
|
55
|
+
(buffer) => new Uint8Array(buffer)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
return EffectCrypto.make({
|
|
59
|
+
randomBytes,
|
|
60
|
+
digest
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
)
|