@effect/platform-deno 4.0.1 → 4.0.3
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/ai-docs/package.json +2 -2
- package/ai-docs/tsconfig.json +2 -1
- package/dist/DenoAddressResolver.d.ts +13 -0
- package/dist/DenoAddressResolver.d.ts.map +1 -0
- package/dist/DenoAddressResolver.js +32 -0
- package/dist/DenoAddressResolver.js.map +1 -0
- package/dist/DenoChildProcessSpawner.d.ts +4 -0
- package/dist/DenoChildProcessSpawner.d.ts.map +1 -1
- package/dist/DenoChildProcessSpawner.js +2 -0
- package/dist/DenoChildProcessSpawner.js.map +1 -1
- package/dist/DenoClusterHttp.d.ts +3 -0
- package/dist/DenoClusterHttp.d.ts.map +1 -1
- package/dist/DenoClusterHttp.js +4 -0
- package/dist/DenoClusterHttp.js.map +1 -1
- package/dist/DenoClusterSocket.d.ts +5 -0
- package/dist/DenoClusterSocket.d.ts.map +1 -1
- package/dist/DenoClusterSocket.js +5 -0
- package/dist/DenoClusterSocket.js.map +1 -1
- package/dist/DenoCrypto.d.ts +3 -0
- package/dist/DenoCrypto.d.ts.map +1 -1
- package/dist/DenoCrypto.js +3 -0
- package/dist/DenoCrypto.js.map +1 -1
- package/dist/DenoDatagramSocket.d.ts +208 -0
- package/dist/DenoDatagramSocket.d.ts.map +1 -0
- package/dist/DenoDatagramSocket.js +423 -0
- package/dist/DenoDatagramSocket.js.map +1 -0
- package/dist/DenoDns.d.ts +62 -0
- package/dist/DenoDns.d.ts.map +1 -0
- package/dist/DenoDns.js +144 -0
- package/dist/DenoDns.js.map +1 -0
- package/dist/DenoFileSystem.d.ts +1 -0
- package/dist/DenoFileSystem.d.ts.map +1 -1
- package/dist/DenoFileSystem.js +50 -19
- package/dist/DenoFileSystem.js.map +1 -1
- package/dist/DenoHttpClient.d.ts +1 -0
- package/dist/DenoHttpClient.d.ts.map +1 -1
- package/dist/DenoHttpClient.js +1 -0
- package/dist/DenoHttpClient.js.map +1 -1
- package/dist/DenoHttpPlatform.d.ts +2 -0
- package/dist/DenoHttpPlatform.d.ts.map +1 -1
- package/dist/DenoHttpPlatform.js +3 -0
- package/dist/DenoHttpPlatform.js.map +1 -1
- package/dist/DenoHttpServer.d.ts +9 -1
- package/dist/DenoHttpServer.d.ts.map +1 -1
- package/dist/DenoHttpServer.js +15 -4
- package/dist/DenoHttpServer.js.map +1 -1
- package/dist/DenoHttpServerRequest.d.ts +2 -0
- package/dist/DenoHttpServerRequest.d.ts.map +1 -1
- package/dist/DenoHttpServerRequest.js +1 -0
- package/dist/DenoHttpServerRequest.js.map +1 -1
- package/dist/DenoKeyValueStore.d.ts +3 -0
- package/dist/DenoKeyValueStore.d.ts.map +1 -1
- package/dist/DenoKeyValueStore.js +3 -0
- package/dist/DenoKeyValueStore.js.map +1 -1
- package/dist/DenoMultipart.d.ts +3 -0
- package/dist/DenoMultipart.d.ts.map +1 -1
- package/dist/DenoMultipart.js +2 -0
- package/dist/DenoMultipart.js.map +1 -1
- package/dist/DenoPath.d.ts +4 -0
- package/dist/DenoPath.d.ts.map +1 -1
- package/dist/DenoPath.js +4 -0
- package/dist/DenoPath.js.map +1 -1
- package/dist/DenoRuntime.d.ts +4 -0
- package/dist/DenoRuntime.d.ts.map +1 -1
- package/dist/DenoRuntime.js +2 -0
- package/dist/DenoRuntime.js.map +1 -1
- package/dist/DenoServices.d.ts +3 -0
- package/dist/DenoServices.d.ts.map +1 -1
- package/dist/DenoServices.js +1 -0
- package/dist/DenoServices.js.map +1 -1
- package/dist/DenoSocket.d.ts +10 -0
- package/dist/DenoSocket.d.ts.map +1 -1
- package/dist/DenoSocket.js +8 -0
- package/dist/DenoSocket.js.map +1 -1
- package/dist/DenoSocketServer.d.ts +1 -0
- package/dist/DenoSocketServer.d.ts.map +1 -1
- package/dist/DenoSocketServer.js +1 -0
- package/dist/DenoSocketServer.js.map +1 -1
- package/dist/DenoStdio.d.ts +1 -0
- package/dist/DenoStdio.d.ts.map +1 -1
- package/dist/DenoStdio.js +3 -0
- package/dist/DenoStdio.js.map +1 -1
- package/dist/DenoTerminal.d.ts +6 -3
- package/dist/DenoTerminal.d.ts.map +1 -1
- package/dist/DenoTerminal.js +7 -3
- package/dist/DenoTerminal.js.map +1 -1
- package/dist/DenoWorker.d.ts +2 -0
- package/dist/DenoWorker.d.ts.map +1 -1
- package/dist/DenoWorker.js +3 -0
- package/dist/DenoWorker.js.map +1 -1
- package/dist/DenoWorkerRunner.d.ts +3 -0
- package/dist/DenoWorkerRunner.d.ts.map +1 -1
- package/dist/DenoWorkerRunner.js +4 -0
- package/dist/DenoWorkerRunner.js.map +1 -1
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
- package/src/DenoAddressResolver.ts +36 -0
- package/src/DenoChildProcessSpawner.ts +4 -0
- package/src/DenoClusterHttp.ts +4 -0
- package/src/DenoClusterSocket.ts +5 -0
- package/src/DenoCrypto.ts +3 -0
- package/src/DenoDatagramSocket.ts +571 -0
- package/src/DenoDns.ts +196 -0
- package/src/DenoFileSystem.ts +62 -27
- package/src/DenoHttpClient.ts +1 -0
- package/src/DenoHttpPlatform.ts +3 -0
- package/src/DenoHttpServer.ts +18 -3
- package/src/DenoHttpServerRequest.ts +2 -0
- package/src/DenoKeyValueStore.ts +3 -0
- package/src/DenoMultipart.ts +3 -0
- package/src/DenoPath.ts +4 -0
- package/src/DenoRuntime.ts +4 -0
- package/src/DenoServices.ts +3 -0
- package/src/DenoSocket.ts +10 -0
- package/src/DenoSocketServer.ts +1 -0
- package/src/DenoStdio.ts +3 -0
- package/src/DenoTerminal.ts +7 -3
- package/src/DenoWorker.ts +3 -0
- package/src/DenoWorkerRunner.ts +4 -0
- package/src/index.ts +39 -0
package/src/DenoDns.ts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deno-backed implementation of Effect's `Dns` service.
|
|
3
|
+
*
|
|
4
|
+
* Address lookups use the operating system resolver through Deno's `node:dns`
|
|
5
|
+
* compatibility layer, so they also read the hosts file. Record queries and
|
|
6
|
+
* reverse lookups use `Deno.resolveDns` and can be cancelled by interruption.
|
|
7
|
+
* Records whose data cannot be represented, such as names that are not valid
|
|
8
|
+
* `Host.DomainName` values, are skipped, and a query fails with
|
|
9
|
+
* `InvalidResponse` when every record is skipped.
|
|
10
|
+
*
|
|
11
|
+
* **Gotchas**
|
|
12
|
+
*
|
|
13
|
+
* `Deno.resolveDns` reports every error response from the name server with the
|
|
14
|
+
* same error as a missing name, so refused queries and server failures
|
|
15
|
+
* (`REFUSED`, `SERVFAIL`, `FORMERR`, `NOTIMP`) fail with `NotFound` instead of
|
|
16
|
+
* `Refused`, `ServerFailure`, `InvalidResponse`, or `Unsupported`. Server
|
|
17
|
+
* failures are therefore not reported as temporary. `Deno.resolveDns` cannot
|
|
18
|
+
* query TLSA records, so TLSA queries fail with `Unsupported`. Queries require
|
|
19
|
+
* the `--allow-net` permission.
|
|
20
|
+
*
|
|
21
|
+
* @stability experimental
|
|
22
|
+
* @since 4.0.0
|
|
23
|
+
*/
|
|
24
|
+
import * as NodeDns from "@effect/platform-node-shared/NodeDns"
|
|
25
|
+
import type * as Arr from "effect/Array"
|
|
26
|
+
import * as Config from "effect/Config"
|
|
27
|
+
import * as Duration from "effect/Duration"
|
|
28
|
+
import * as Effect from "effect/Effect"
|
|
29
|
+
import * as Layer from "effect/Layer"
|
|
30
|
+
import * as Dns from "effect/net/Dns"
|
|
31
|
+
import * as NetAddress from "effect/net/NetAddress"
|
|
32
|
+
import * as Result from "effect/Result"
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Options for the Deno `Dns` service.
|
|
36
|
+
*
|
|
37
|
+
* **Details**
|
|
38
|
+
*
|
|
39
|
+
* `nameServer` replaces the system name server for record queries and reverse
|
|
40
|
+
* lookups and is converted like `Dns.nameServerFromInput`. Address
|
|
41
|
+
* lookups always use the operating system resolver.
|
|
42
|
+
*
|
|
43
|
+
* **Gotchas**
|
|
44
|
+
*
|
|
45
|
+
* Invalid name servers fail with a `NetAddress.NetAddressError` when the
|
|
46
|
+
* service is created, and so do IPv6 name servers with a scope ID, such as
|
|
47
|
+
* link-local addresses.
|
|
48
|
+
*
|
|
49
|
+
* @stability experimental
|
|
50
|
+
* @category models
|
|
51
|
+
* @since 4.0.0
|
|
52
|
+
*/
|
|
53
|
+
export interface Options {
|
|
54
|
+
readonly nameServer?: NetAddress.IpAddressInput | NetAddress.InetAddressInput | undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const reasons: Record<string, Dns.DnsErrorReason> = {
|
|
58
|
+
NotFound: "NotFound",
|
|
59
|
+
TimedOut: "Timeout",
|
|
60
|
+
ConnectionRefused: "Refused",
|
|
61
|
+
InvalidData: "InvalidResponse",
|
|
62
|
+
NotSupported: "Unsupported"
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const toDnsError = (cause: unknown, name: string, type: Dns.RecordType): Dns.DnsError =>
|
|
66
|
+
new Dns.DnsError({
|
|
67
|
+
reason: (cause instanceof Error ? reasons[cause.name] : undefined) ?? "Unknown",
|
|
68
|
+
method: "resolve",
|
|
69
|
+
hostname: name,
|
|
70
|
+
recordType: type,
|
|
71
|
+
cause
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const queries: {
|
|
75
|
+
readonly [K in Dns.RecordType]: (
|
|
76
|
+
name: string,
|
|
77
|
+
options: Deno.ResolveDnsOptions
|
|
78
|
+
) => Promise<Result.Result<Array<Dns.DnsRecord>, Dns.DnsError>>
|
|
79
|
+
} = {
|
|
80
|
+
A: async (name, options) =>
|
|
81
|
+
NodeDns.recordsFromResolver(name, "A", await Deno.resolveDns(name, "A", options), (address) => ({
|
|
82
|
+
address: NetAddress.ipFromStringUnsafe(address) as NetAddress.Ipv4Address
|
|
83
|
+
})),
|
|
84
|
+
AAAA: async (name, options) =>
|
|
85
|
+
NodeDns.recordsFromResolver(name, "AAAA", await Deno.resolveDns(name, "AAAA", options), (address) => ({
|
|
86
|
+
address: NetAddress.ipFromStringUnsafe(address) as NetAddress.Ipv6Address
|
|
87
|
+
})),
|
|
88
|
+
CAA: async (name, options) =>
|
|
89
|
+
NodeDns.recordsFromResolver(name, "CAA", await Deno.resolveDns(name, "CAA", options), (caa) => ({
|
|
90
|
+
critical: caa.critical,
|
|
91
|
+
tag: caa.tag,
|
|
92
|
+
value: caa.value
|
|
93
|
+
})),
|
|
94
|
+
CNAME: async (name, options) =>
|
|
95
|
+
NodeDns.recordsFromResolver(name, "CNAME", await Deno.resolveDns(name, "CNAME", options), (target) => ({
|
|
96
|
+
target: NodeDns.domainNameFromResolverUnsafe(target)
|
|
97
|
+
})),
|
|
98
|
+
MX: async (name, options) =>
|
|
99
|
+
NodeDns.recordsFromResolver(name, "MX", await Deno.resolveDns(name, "MX", options), (mx) => ({
|
|
100
|
+
exchange: NodeDns.domainNameFromResolverUnsafe(mx.exchange),
|
|
101
|
+
priority: mx.preference
|
|
102
|
+
})),
|
|
103
|
+
NAPTR: async (name, options) =>
|
|
104
|
+
NodeDns.recordsFromResolver(name, "NAPTR", await Deno.resolveDns(name, "NAPTR", options), (naptr) => ({
|
|
105
|
+
order: naptr.order,
|
|
106
|
+
preference: naptr.preference,
|
|
107
|
+
flags: naptr.flags,
|
|
108
|
+
service: naptr.services,
|
|
109
|
+
regexp: naptr.regexp,
|
|
110
|
+
replacement: NodeDns.domainNameFromResolverUnsafe(naptr.replacement)
|
|
111
|
+
})),
|
|
112
|
+
NS: async (name, options) =>
|
|
113
|
+
NodeDns.recordsFromResolver(name, "NS", await Deno.resolveDns(name, "NS", options), (host) => ({
|
|
114
|
+
host: NodeDns.domainNameFromResolverUnsafe(host)
|
|
115
|
+
})),
|
|
116
|
+
PTR: async (name, options) =>
|
|
117
|
+
NodeDns.recordsFromResolver(name, "PTR", await Deno.resolveDns(name, "PTR", options), (host) => ({
|
|
118
|
+
host: NodeDns.nameTextFromResolver(host, 8)
|
|
119
|
+
})),
|
|
120
|
+
SOA: async (name, options) =>
|
|
121
|
+
NodeDns.recordsFromResolver(name, "SOA", await Deno.resolveDns(name, "SOA", options), (soa) => ({
|
|
122
|
+
primary: NodeDns.domainNameFromResolverUnsafe(soa.mname),
|
|
123
|
+
admin: NodeDns.nameTextFromResolver(soa.rname, 8),
|
|
124
|
+
serial: soa.serial,
|
|
125
|
+
refresh: NodeDns.secondsFromInt32(soa.refresh),
|
|
126
|
+
retry: NodeDns.secondsFromInt32(soa.retry),
|
|
127
|
+
expire: NodeDns.secondsFromInt32(soa.expire),
|
|
128
|
+
minimum: Duration.seconds(soa.minimum)
|
|
129
|
+
})),
|
|
130
|
+
SRV: async (name, options) =>
|
|
131
|
+
NodeDns.recordsFromResolver(name, "SRV", await Deno.resolveDns(name, "SRV", options), (srv) => ({
|
|
132
|
+
target: NodeDns.domainNameFromResolverUnsafe(srv.target),
|
|
133
|
+
port: srv.port,
|
|
134
|
+
priority: srv.priority,
|
|
135
|
+
weight: srv.weight
|
|
136
|
+
})),
|
|
137
|
+
TLSA: async (name) =>
|
|
138
|
+
Result.fail(new Dns.DnsError({ reason: "Unsupported", method: "resolve", hostname: name, recordType: "TLSA" })),
|
|
139
|
+
TXT: async (name, options) =>
|
|
140
|
+
NodeDns.recordsFromResolver(name, "TXT", await Deno.resolveDns(name, "TXT", options), (chunks) => ({
|
|
141
|
+
chunks: chunks.map(NodeDns.utf8FromLatin1) as unknown as Arr.NonEmptyReadonlyArray<string>
|
|
142
|
+
}))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Creates a Deno `Dns` service.
|
|
147
|
+
*
|
|
148
|
+
* @stability experimental
|
|
149
|
+
* @category constructors
|
|
150
|
+
* @since 4.0.0
|
|
151
|
+
*/
|
|
152
|
+
export const make = Effect.fnUntraced(function*(options?: Options) {
|
|
153
|
+
const input = options?.nameServer
|
|
154
|
+
const server = input === undefined ? undefined : yield* Effect.fromResult(Dns.nameServerFromInput(input))
|
|
155
|
+
if (server !== undefined && NetAddress.isInetAddressV6(server) && server.scopeId !== 0) {
|
|
156
|
+
return yield* new NetAddress.NetAddressError({
|
|
157
|
+
input: input!,
|
|
158
|
+
message: "IPv6 name servers with a scope ID are not supported"
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
const nameServer: Deno.ResolveDnsOptions["nameServer"] = server === undefined
|
|
162
|
+
? undefined
|
|
163
|
+
: { ipAddr: NetAddress.formatHost(server), port: server.port }
|
|
164
|
+
|
|
165
|
+
return Dns.make({
|
|
166
|
+
lookup: NodeDns.lookup,
|
|
167
|
+
resolve: (name, type) =>
|
|
168
|
+
Effect.tryPromise({
|
|
169
|
+
try: (signal) => queries[type](name, nameServer === undefined ? { signal } : { nameServer, signal }),
|
|
170
|
+
catch: (cause) => toDnsError(cause, name, type)
|
|
171
|
+
}).pipe(Effect.flatMap(Effect.fromResult))
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Layer that provides the Deno `Dns` service using the system resolver
|
|
177
|
+
* configuration.
|
|
178
|
+
*
|
|
179
|
+
* @stability experimental
|
|
180
|
+
* @category layers
|
|
181
|
+
* @since 4.0.0
|
|
182
|
+
*/
|
|
183
|
+
export const layer: Layer.Layer<Dns.Dns> = Layer.effect(Dns.Dns, Effect.orDie(make()))
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Creates a layer that provides the Deno `Dns` service with options read
|
|
187
|
+
* from configuration.
|
|
188
|
+
*
|
|
189
|
+
* @stability experimental
|
|
190
|
+
* @category layers
|
|
191
|
+
* @since 4.0.0
|
|
192
|
+
*/
|
|
193
|
+
export const layerConfig = (
|
|
194
|
+
options: Config.Wrap<Options>
|
|
195
|
+
): Layer.Layer<Dns.Dns, Config.ConfigError | NetAddress.NetAddressError> =>
|
|
196
|
+
Layer.effect(Dns.Dns, Effect.flatMap(Config.unwrap(options), make))
|
package/src/DenoFileSystem.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Deno implementation of Effect's `FileSystem` service.
|
|
3
3
|
*
|
|
4
|
+
* @stability unstable
|
|
4
5
|
* @since 4.0.0
|
|
5
6
|
*/
|
|
6
7
|
import { copy as denoCopy, expandGlob, walk } from "@std/fs"
|
|
@@ -181,13 +182,18 @@ const makeFileInfo = (info: Deno.FileInfo): FileSystem.File.Info => ({
|
|
|
181
182
|
blocks: Option.fromNullishOr(info.blocks)
|
|
182
183
|
})
|
|
183
184
|
|
|
184
|
-
/**
|
|
185
|
+
/**
|
|
186
|
+
* Deno lacks positional reads, so `native` serializes seek + I/O. Cancelled
|
|
187
|
+
* entries are skipped; started I/O holds the queue until it settles, even
|
|
188
|
+
* after interruption. Cursor operations must not run concurrently.
|
|
189
|
+
*/
|
|
185
190
|
class FileImpl implements FileSystem.File {
|
|
186
191
|
readonly [FileSystem.FileTypeId]: typeof FileSystem.FileTypeId = FileSystem.FileTypeId
|
|
187
192
|
private readonly file: Deno.FsFile
|
|
188
193
|
private readonly append: boolean
|
|
189
194
|
private position = BigInt(0)
|
|
190
195
|
private nativePosition: bigint | undefined = undefined
|
|
196
|
+
private nativeQueue: Promise<unknown> = Promise.resolve()
|
|
191
197
|
|
|
192
198
|
constructor(
|
|
193
199
|
file: Deno.FsFile,
|
|
@@ -223,41 +229,59 @@ class FileImpl implements FileSystem.File {
|
|
|
223
229
|
})
|
|
224
230
|
}
|
|
225
231
|
|
|
226
|
-
private
|
|
232
|
+
private native<A>(signal: AbortSignal, evaluate: () => Promise<A>): Promise<A> {
|
|
233
|
+
const result = this.nativeQueue.then(() => signal.aborted ? Promise.reject(signal.reason) : evaluate())
|
|
234
|
+
this.nativeQueue = result.catch(() => undefined)
|
|
235
|
+
return result
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private readChunk(method: string, buffer: Uint8Array, explicit: bigint | undefined) {
|
|
227
239
|
return Effect.suspend(() => {
|
|
228
|
-
|
|
240
|
+
if (explicit !== undefined && explicit < BigInt(0)) {
|
|
241
|
+
return Effect.fail(PlatformError.badArgument({
|
|
242
|
+
module: "FileSystem",
|
|
243
|
+
method,
|
|
244
|
+
description: "Cannot read before the start of the file"
|
|
245
|
+
}))
|
|
246
|
+
}
|
|
247
|
+
const position = explicit ?? this.position
|
|
229
248
|
return Effect.map(
|
|
230
249
|
tryPromise(
|
|
231
250
|
method,
|
|
232
251
|
undefined,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
this.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
252
|
+
(signal) =>
|
|
253
|
+
this.native(signal, async () => {
|
|
254
|
+
if (this.nativePosition !== position) {
|
|
255
|
+
this.file.seekSync(position, Deno.SeekMode.Start)
|
|
256
|
+
}
|
|
257
|
+
this.nativePosition = undefined
|
|
258
|
+
const bytesRead = (await this.file.read(buffer)) ?? 0
|
|
259
|
+
this.nativePosition = position + BigInt(bytesRead)
|
|
260
|
+
return bytesRead
|
|
261
|
+
})
|
|
240
262
|
),
|
|
241
263
|
(bytesRead) => {
|
|
242
|
-
|
|
243
|
-
|
|
264
|
+
if (explicit === undefined) {
|
|
265
|
+
this.position = position + BigInt(bytesRead)
|
|
266
|
+
}
|
|
267
|
+
return bytesRead
|
|
244
268
|
}
|
|
245
269
|
)
|
|
246
270
|
})
|
|
247
271
|
}
|
|
248
272
|
|
|
249
|
-
read(buffer: Uint8Array) {
|
|
250
|
-
return this.readChunk("read", buffer)
|
|
273
|
+
read(buffer: Uint8Array, options?: FileSystem.File.ReadOptions) {
|
|
274
|
+
return this.readChunk("read", buffer, options?.position)
|
|
251
275
|
}
|
|
252
276
|
|
|
253
|
-
readAlloc(size: number) {
|
|
277
|
+
readAlloc(size: number, options?: FileSystem.File.ReadOptions) {
|
|
254
278
|
return Effect.suspend(() => {
|
|
255
279
|
try {
|
|
256
280
|
if (!Number.isInteger(size) || size < 0) {
|
|
257
281
|
throw new RangeError("size must be a non-negative integer")
|
|
258
282
|
}
|
|
259
283
|
const buffer = new Uint8Array(size)
|
|
260
|
-
return Effect.map(this.readChunk("readAlloc", buffer), (bytesRead) => {
|
|
284
|
+
return Effect.map(this.readChunk("readAlloc", buffer, options?.position), (bytesRead) => {
|
|
261
285
|
if (bytesRead === 0) {
|
|
262
286
|
return Option.none()
|
|
263
287
|
}
|
|
@@ -293,19 +317,22 @@ class FileImpl implements FileSystem.File {
|
|
|
293
317
|
tryPromise(
|
|
294
318
|
method,
|
|
295
319
|
undefined,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
this.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
320
|
+
(signal) =>
|
|
321
|
+
this.native(signal, async () => {
|
|
322
|
+
if (!this.append && this.nativePosition !== position) {
|
|
323
|
+
this.file.seekSync(position, Deno.SeekMode.Start)
|
|
324
|
+
}
|
|
325
|
+
this.nativePosition = undefined
|
|
326
|
+
const bytesWritten = await this.file.write(buffer)
|
|
327
|
+
if (!this.append) {
|
|
328
|
+
this.nativePosition = position + BigInt(bytesWritten)
|
|
329
|
+
}
|
|
330
|
+
return bytesWritten
|
|
331
|
+
})
|
|
303
332
|
),
|
|
304
333
|
(bytesWritten) => {
|
|
305
|
-
if (this.append) {
|
|
306
|
-
this.
|
|
307
|
-
} else {
|
|
308
|
-
this.position = this.nativePosition = position + BigInt(bytesWritten)
|
|
334
|
+
if (!this.append) {
|
|
335
|
+
this.position = position + BigInt(bytesWritten)
|
|
309
336
|
}
|
|
310
337
|
return bytesWritten
|
|
311
338
|
}
|
|
@@ -339,6 +366,13 @@ class FileImpl implements FileSystem.File {
|
|
|
339
366
|
}
|
|
340
367
|
|
|
341
368
|
const open: FileSystem.FileSystem["open"] = (path, options) => {
|
|
369
|
+
if (options?.noFollow === true) {
|
|
370
|
+
return Effect.fail(PlatformError.badArgument({
|
|
371
|
+
module: "FileSystem",
|
|
372
|
+
method: "open",
|
|
373
|
+
description: "noFollow is not supported by Deno"
|
|
374
|
+
}))
|
|
375
|
+
}
|
|
342
376
|
const append = options?.flag?.startsWith("a") ?? false
|
|
343
377
|
return Effect.map(
|
|
344
378
|
Effect.acquireRelease(
|
|
@@ -510,6 +544,7 @@ const makeFileSystem = Effect.map(Effect.serviceOption(FileSystem.WatchBackend),
|
|
|
510
544
|
/**
|
|
511
545
|
* Provides the `FileSystem` service backed by Deno filesystem APIs.
|
|
512
546
|
*
|
|
547
|
+
* @stability unstable
|
|
513
548
|
* @category layers
|
|
514
549
|
* @since 4.0.0
|
|
515
550
|
*/
|
package/src/DenoHttpClient.ts
CHANGED
package/src/DenoHttpPlatform.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* The provided layer uses strong ETags, unlike the portable `HttpPlatform`
|
|
10
10
|
* layer, which uses weak ETags.
|
|
11
11
|
*
|
|
12
|
+
* @stability unstable
|
|
12
13
|
* @since 4.0.0
|
|
13
14
|
*/
|
|
14
15
|
import * as NodeHttpCompression from "@effect/platform-node-shared/NodeHttpCompression"
|
|
@@ -36,6 +37,7 @@ const compression = NodeHttpCompression.make(Platform.makeCompressionWeb({
|
|
|
36
37
|
* Creates the Deno `HttpPlatform`, serving file responses from resource-backed
|
|
37
38
|
* readable streams and adding content type and content length headers.
|
|
38
39
|
*
|
|
40
|
+
* @stability unstable
|
|
39
41
|
* @category constructors
|
|
40
42
|
* @since 4.0.0
|
|
41
43
|
*/
|
|
@@ -102,6 +104,7 @@ export const make = Platform.make({
|
|
|
102
104
|
* Provides the Deno `HttpPlatform` together with its filesystem and strong ETag
|
|
103
105
|
* services.
|
|
104
106
|
*
|
|
107
|
+
* @stability unstable
|
|
105
108
|
* @category layers
|
|
106
109
|
* @since 4.0.0
|
|
107
110
|
*/
|
package/src/DenoHttpServer.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Native Deno implementation of the Effect `HttpServer`.
|
|
3
3
|
*
|
|
4
|
+
* @stability unstable
|
|
4
5
|
* @since 4.0.0
|
|
5
6
|
*/
|
|
6
7
|
import * as Config from "effect/Config"
|
|
@@ -51,6 +52,7 @@ import * as DenoServices from "./DenoServices.ts"
|
|
|
51
52
|
* WebSocket settings that apply to every upgrade; `protocol` therefore cannot
|
|
52
53
|
* vary per request.
|
|
53
54
|
*
|
|
55
|
+
* @stability unstable
|
|
54
56
|
* @category options
|
|
55
57
|
* @since 4.0.0
|
|
56
58
|
*/
|
|
@@ -61,6 +63,7 @@ export type ServeOptions =
|
|
|
61
63
|
/**
|
|
62
64
|
* Creates a scoped native Deno HTTP server.
|
|
63
65
|
*
|
|
66
|
+
* @stability unstable
|
|
64
67
|
* @category constructors
|
|
65
68
|
* @since 4.0.0
|
|
66
69
|
*/
|
|
@@ -113,7 +116,9 @@ export const make = Effect.fnUntraced(function*(
|
|
|
113
116
|
|
|
114
117
|
const httpEffect = HttpEffect.toHandled(httpApp, (request, response) => {
|
|
115
118
|
const denoRequest = request as DenoServerRequest
|
|
116
|
-
if (denoRequest.
|
|
119
|
+
if (upgradedSources.has(denoRequest.source)) {
|
|
120
|
+
return Effect.as(cancelResponseBody(response.body), upgradedResponse)
|
|
121
|
+
}
|
|
117
122
|
return Effect.flatMap(
|
|
118
123
|
makeResponse(request, response, services, scope),
|
|
119
124
|
(response) => Effect.sync(() => denoRequest.resolve(response))
|
|
@@ -207,6 +212,7 @@ const makeResponse = Effect.fnUntraced(function*(
|
|
|
207
212
|
/**
|
|
208
213
|
* Provides only the native Deno HTTP server.
|
|
209
214
|
*
|
|
215
|
+
* @stability unstable
|
|
210
216
|
* @category layers
|
|
211
217
|
* @since 4.0.0
|
|
212
218
|
*/
|
|
@@ -224,6 +230,7 @@ export const layerServer: (
|
|
|
224
230
|
/**
|
|
225
231
|
* Provides Deno HTTP platform services and the standard Deno service set.
|
|
226
232
|
*
|
|
233
|
+
* @stability unstable
|
|
227
234
|
* @category layers
|
|
228
235
|
* @since 4.0.0
|
|
229
236
|
*/
|
|
@@ -236,6 +243,7 @@ export const layerHttpServices: Layer.Layer<HttpPlatform | Etag.Generator | Deno
|
|
|
236
243
|
/**
|
|
237
244
|
* Provides a native Deno HTTP server together with Deno HTTP services.
|
|
238
245
|
*
|
|
246
|
+
* @stability unstable
|
|
239
247
|
* @category layers
|
|
240
248
|
* @since 4.0.0
|
|
241
249
|
*/
|
|
@@ -251,6 +259,7 @@ export const layer = (
|
|
|
251
259
|
/**
|
|
252
260
|
* Starts a Deno HTTP server on an ephemeral loopback port for tests.
|
|
253
261
|
*
|
|
262
|
+
* @stability unstable
|
|
254
263
|
* @category testing
|
|
255
264
|
* @since 4.0.0
|
|
256
265
|
*/
|
|
@@ -266,6 +275,7 @@ export const layerTest: Layer.Layer<
|
|
|
266
275
|
/**
|
|
267
276
|
* Creates the Deno HTTP server and support-services layer from configurable options.
|
|
268
277
|
*
|
|
278
|
+
* @stability unstable
|
|
269
279
|
* @category layers
|
|
270
280
|
* @since 4.0.0
|
|
271
281
|
*/
|
|
@@ -294,7 +304,6 @@ class DenoServerRequest extends Inspectable.Class implements ServerRequest.HttpS
|
|
|
294
304
|
readonly url: string
|
|
295
305
|
readonly websocketOptions: Deno.UpgradeWebSocketOptions | undefined
|
|
296
306
|
public resolve: (response: Response) => void
|
|
297
|
-
public upgraded = false
|
|
298
307
|
public headersOverride?: Headers.Headers | undefined
|
|
299
308
|
private remoteAddressOverride?: Option.Option<string> | undefined
|
|
300
309
|
|
|
@@ -458,7 +467,7 @@ class DenoServerRequest extends Inspectable.Class implements ServerRequest.HttpS
|
|
|
458
467
|
}),
|
|
459
468
|
(upgrade) => {
|
|
460
469
|
const ws = bufferedWebSocket(upgrade.socket)
|
|
461
|
-
this.
|
|
470
|
+
upgradedSources.add(this.source)
|
|
462
471
|
this.resolve(upgrade.response)
|
|
463
472
|
return Socket.fromWebSocket(
|
|
464
473
|
Effect.acquireRelease(
|
|
@@ -551,6 +560,12 @@ const bufferedWebSocket = (ws: WebSocket): Socket.WebSocketLike => {
|
|
|
551
560
|
}
|
|
552
561
|
}
|
|
553
562
|
|
|
563
|
+
// Reported to middleware in place of the handler's discarded response.
|
|
564
|
+
const upgradedResponse = ServerResponse.empty({ status: 101 })
|
|
565
|
+
|
|
566
|
+
// Keyed by source so request copies from `modify` share the upgrade state.
|
|
567
|
+
const upgradedSources = new WeakSet<Request>()
|
|
568
|
+
|
|
554
569
|
const cancelResponseBody = (body: HttpBody.HttpBody): Effect.Effect<void> => {
|
|
555
570
|
if (body._tag === "Raw" && typeof ReadableStream !== "undefined" && body.body instanceof ReadableStream) {
|
|
556
571
|
const stream = body.body
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* `Deno.serve` always receives a standard `Request`. Connection information is
|
|
6
6
|
* intentionally kept internal to `DenoHttpServer`.
|
|
7
7
|
*
|
|
8
|
+
* @stability unstable
|
|
8
9
|
* @since 4.0.0
|
|
9
10
|
*/
|
|
10
11
|
import type { HttpServerRequest } from "effect/http/HttpServerRequest"
|
|
@@ -12,6 +13,7 @@ import type { HttpServerRequest } from "effect/http/HttpServerRequest"
|
|
|
12
13
|
/**
|
|
13
14
|
* Returns the underlying web-standard `Request` from an Effect `HttpServerRequest`.
|
|
14
15
|
*
|
|
16
|
+
* @stability unstable
|
|
15
17
|
* @category accessors
|
|
16
18
|
* @since 4.0.0
|
|
17
19
|
*/
|
package/src/DenoKeyValueStore.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Deno-backed `KeyValueStore` layers using Web Storage APIs.
|
|
3
3
|
*
|
|
4
|
+
* @stability unstable
|
|
4
5
|
* @since 4.0.0
|
|
5
6
|
*/
|
|
6
7
|
|
|
@@ -10,6 +11,7 @@ import * as KeyValueStore from "effect/persistence/KeyValueStore"
|
|
|
10
11
|
/**
|
|
11
12
|
* Creates a `KeyValueStore` layer backed by `localStorage`, with values stored between sessions.
|
|
12
13
|
*
|
|
14
|
+
* @stability unstable
|
|
13
15
|
* @category layers
|
|
14
16
|
* @since 4.0.0
|
|
15
17
|
*/
|
|
@@ -20,6 +22,7 @@ export const layerLocalStorage: Layer.Layer<KeyValueStore.KeyValueStore> = KeyVa
|
|
|
20
22
|
/**
|
|
21
23
|
* Creates a `KeyValueStore` layer backed by `sessionStorage`, with values stored only for the current session.
|
|
22
24
|
*
|
|
25
|
+
* @stability unstable
|
|
23
26
|
* @category layers
|
|
24
27
|
* @since 4.0.0
|
|
25
28
|
*/
|
package/src/DenoMultipart.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* temporary files through the current `FileSystem`, `Path`, and `Scope`
|
|
8
8
|
* services.
|
|
9
9
|
*
|
|
10
|
+
* @stability unstable
|
|
10
11
|
* @since 4.0.0
|
|
11
12
|
*/
|
|
12
13
|
import type * as Effect from "effect/Effect"
|
|
@@ -19,6 +20,7 @@ import * as Stream from "effect/Stream"
|
|
|
19
20
|
/**
|
|
20
21
|
* Parses a web `Request` body as multipart data and returns a stream of multipart parts.
|
|
21
22
|
*
|
|
23
|
+
* @stability unstable
|
|
22
24
|
* @category constructors
|
|
23
25
|
* @since 4.0.0
|
|
24
26
|
*/
|
|
@@ -39,6 +41,7 @@ export const stream = (source: Request): Stream.Stream<Multipart.Part, Multipart
|
|
|
39
41
|
/**
|
|
40
42
|
* Parses and persists multipart data from a web `Request`, requiring file-system, path, and scope services.
|
|
41
43
|
*
|
|
44
|
+
* @stability unstable
|
|
42
45
|
* @category constructors
|
|
43
46
|
* @since 4.0.0
|
|
44
47
|
*/
|
package/src/DenoPath.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* Effect.runSync(program) // => ".txt"
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
|
+
* @stability unstable
|
|
18
19
|
* @since 4.0.0
|
|
19
20
|
*/
|
|
20
21
|
|
|
@@ -55,6 +56,7 @@ const fileUrlOps = (impl: {
|
|
|
55
56
|
/**
|
|
56
57
|
* A {@linkplain Layer.Layer | layer} that provides POSIX path operations.
|
|
57
58
|
*
|
|
59
|
+
* @stability unstable
|
|
58
60
|
* @category layers
|
|
59
61
|
* @since 4.0.0
|
|
60
62
|
*/
|
|
@@ -70,6 +72,7 @@ export const layerPosix: Layer.Layer<Path.Path> = Layer.succeed(Path.Path)(
|
|
|
70
72
|
/**
|
|
71
73
|
* A {@linkplain Layer.Layer | layer} that provides Windows path operations.
|
|
72
74
|
*
|
|
75
|
+
* @stability unstable
|
|
73
76
|
* @category layers
|
|
74
77
|
* @since 4.0.0
|
|
75
78
|
*/
|
|
@@ -87,6 +90,7 @@ export const layerWin32: Layer.Layer<Path.Path> = Layer.succeed(
|
|
|
87
90
|
/**
|
|
88
91
|
* A {@linkplain Layer.Layer | layer} that provides OS-agnostic path operations.
|
|
89
92
|
*
|
|
93
|
+
* @stability unstable
|
|
90
94
|
* @category layers
|
|
91
95
|
* @since 4.0.0
|
|
92
96
|
*/
|
package/src/DenoRuntime.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Deno helper for running a root Effect program.
|
|
3
3
|
*
|
|
4
|
+
* @stability unstable
|
|
4
5
|
* @since 4.0.0
|
|
5
6
|
*/
|
|
6
7
|
|
|
@@ -10,6 +11,7 @@ import * as Runtime from "effect/Runtime"
|
|
|
10
11
|
/**
|
|
11
12
|
* Run an Effect as the entrypoint to a Deno application.
|
|
12
13
|
*
|
|
14
|
+
* @stability unstable
|
|
13
15
|
* @category running
|
|
14
16
|
* @since 4.0.0
|
|
15
17
|
*/
|
|
@@ -18,6 +20,7 @@ export const runMain: {
|
|
|
18
20
|
/**
|
|
19
21
|
* Run an Effect as the entrypoint to a Deno application.
|
|
20
22
|
*
|
|
23
|
+
* @stability unstable
|
|
21
24
|
* @category running
|
|
22
25
|
* @since 4.0.0
|
|
23
26
|
*/
|
|
@@ -31,6 +34,7 @@ export const runMain: {
|
|
|
31
34
|
/**
|
|
32
35
|
* Run an Effect as the entrypoint to a Deno application.
|
|
33
36
|
*
|
|
37
|
+
* @stability unstable
|
|
34
38
|
* @category running
|
|
35
39
|
* @since 4.0.0
|
|
36
40
|
*/
|
package/src/DenoServices.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* and terminal services. Use the layer when a Deno program wants the standard
|
|
7
7
|
* platform services from one place.
|
|
8
8
|
*
|
|
9
|
+
* @stability unstable
|
|
9
10
|
* @since 4.0.0
|
|
10
11
|
*/
|
|
11
12
|
import type { Crypto } from "effect/Crypto"
|
|
@@ -26,6 +27,7 @@ import * as DenoTerminal from "./DenoTerminal.ts"
|
|
|
26
27
|
* The union of core services provided by the Deno platform layer, including
|
|
27
28
|
* child process spawning, crypto, filesystem, path, stdio, and terminal services.
|
|
28
29
|
*
|
|
30
|
+
* @stability unstable
|
|
29
31
|
* @category models
|
|
30
32
|
* @since 4.0.0
|
|
31
33
|
*/
|
|
@@ -35,6 +37,7 @@ export type DenoServices = ChildProcessSpawner | Crypto | FileSystem | Path | Te
|
|
|
35
37
|
* Provides the default Deno implementations for child process spawning,
|
|
36
38
|
* crypto, filesystem, path, stdio, and terminal services.
|
|
37
39
|
*
|
|
40
|
+
* @stability unstable
|
|
38
41
|
* @category layers
|
|
39
42
|
* @since 4.0.0
|
|
40
43
|
*/
|