effect-cf 0.41.0 → 0.42.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/CHANGELOG.md +22 -0
- package/README.md +28 -0
- package/dist/AiGateway.d.mts +2 -2
- package/dist/AnalyticsEngine.d.mts +2 -2
- package/dist/Artifacts.d.mts +2 -2
- package/dist/BrowserRendering.d.mts +2 -2
- package/dist/ContainerNamespace.d.mts +2 -2
- package/dist/ContainerNamespace.mjs +23 -20
- package/dist/D1.d.mts +9 -12
- package/dist/DurableObject.d.mts +5 -3
- package/dist/DurableObject.mjs +4 -3
- package/dist/DurableObjectDefinition.d.mts +15 -12
- package/dist/DurableObjectDefinition.mjs +5 -3
- package/dist/DurableObjectNamespace.d.mts +10 -8
- package/dist/DurableObjectNamespace.mjs +1 -1
- package/dist/Email.d.mts +2 -2
- package/dist/Hyperdrive.d.mts +2 -2
- package/dist/Images.d.mts +2 -2
- package/dist/Kv.d.mts +2 -2
- package/dist/Queue.d.mts +5 -4
- package/dist/QueueDefinition.d.mts +4 -4
- package/dist/R2.d.mts +2 -2
- package/dist/RpcDefinition.d.mts +26 -12
- package/dist/RpcDefinition.mjs +22 -5
- package/dist/RpcTargets.mjs +1 -2
- package/dist/Sandbox.d.mts +1 -1
- package/dist/Sandbox.mjs +87 -65
- package/dist/ServiceBinding.d.mts +17 -18
- package/dist/Vectorize.d.mts +2 -2
- package/dist/Worker.d.mts +5 -3
- package/dist/Worker.mjs +5 -4
- package/dist/WorkerDefinition.d.mts +15 -11
- package/dist/WorkerDefinition.mjs +5 -3
- package/dist/WorkersAi.d.mts +2 -2
- package/dist/Workflow.d.mts +5 -4
- package/dist/WorkflowDefinition.d.mts +4 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/internal/RpcTargets.mjs +5 -0
- package/package.json +1 -1
- package/src/AiGateway.ts +2 -0
- package/src/AnalyticsEngine.ts +2 -0
- package/src/Artifacts.ts +2 -0
- package/src/BrowserRendering.ts +2 -0
- package/src/ContainerNamespace.ts +34 -39
- package/src/D1.ts +16 -8
- package/src/DurableObject.ts +14 -1
- package/src/DurableObjectDefinition.ts +33 -17
- package/src/DurableObjectNamespace.ts +19 -35
- package/src/Email.ts +2 -0
- package/src/Hyperdrive.ts +2 -0
- package/src/Images.ts +2 -0
- package/src/Kv.ts +2 -0
- package/src/Queue.ts +4 -7
- package/src/QueueDefinition.ts +7 -4
- package/src/R2.ts +2 -0
- package/src/RpcDefinition.ts +64 -25
- package/src/RpcTargets.ts +2 -8
- package/src/Sandbox.ts +133 -146
- package/src/ServiceBinding.ts +39 -34
- package/src/Vectorize.ts +2 -0
- package/src/Worker.ts +12 -1
- package/src/WorkerDefinition.ts +28 -17
- package/src/WorkersAi.ts +2 -0
- package/src/Workflow.ts +9 -8
- package/src/WorkflowDefinition.ts +12 -4
- package/src/internal/RpcTargets.ts +10 -0
package/dist/Sandbox.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { WorkerEnvironment } from "./Environment.mjs";
|
|
2
2
|
import { layer as layer$1 } from "./Binding.mjs";
|
|
3
3
|
import { causeMessage } from "./internal/ErrorMessage.mjs";
|
|
4
|
+
import { CurrentTargets } from "./internal/RpcTargets.mjs";
|
|
5
|
+
import { get, invalidate } from "./RpcTargets.mjs";
|
|
4
6
|
import * as Context from "effect/Context";
|
|
5
7
|
import * as Data from "effect/Data";
|
|
6
8
|
import * as Effect from "effect/Effect";
|
|
@@ -14,7 +16,7 @@ var SandboxOperationError = class extends Data.TaggedError("SandboxOperationErro
|
|
|
14
16
|
return `Sandbox ${this.operation} failed for binding "${this.binding}" instance "${this.instance}": ${causeMessage(this.cause)}`;
|
|
15
17
|
}
|
|
16
18
|
};
|
|
17
|
-
const trySandboxPromise = (definition, instance, operation, evaluate) => Effect.tryPromise({
|
|
19
|
+
const trySandboxPromise = (definition, instance, operation, evaluate, target) => Effect.tryPromise({
|
|
18
20
|
try: evaluate,
|
|
19
21
|
catch: (cause) => new SandboxOperationError({
|
|
20
22
|
binding: definition.binding,
|
|
@@ -22,8 +24,8 @@ const trySandboxPromise = (definition, instance, operation, evaluate) => Effect.
|
|
|
22
24
|
operation,
|
|
23
25
|
cause
|
|
24
26
|
})
|
|
25
|
-
});
|
|
26
|
-
const sandboxStream = (definition, instance, operation, acquire) => Stream.unwrap(Effect.map(trySandboxPromise(definition, instance, operation, acquire), (readable) => Stream.fromReadableStream({
|
|
27
|
+
}).pipe(Effect.tapCause(() => target === void 0 ? Effect.void : invalidate(target)));
|
|
28
|
+
const sandboxStream = (definition, instance, operation, acquire, target) => Stream.unwrap(Effect.map(trySandboxPromise(definition, instance, operation, acquire, target), (readable) => Stream.fromReadableStream({
|
|
27
29
|
evaluate: () => readable,
|
|
28
30
|
onError: (cause) => new SandboxOperationError({
|
|
29
31
|
binding: definition.binding,
|
|
@@ -31,7 +33,7 @@ const sandboxStream = (definition, instance, operation, acquire) => Stream.unwra
|
|
|
31
33
|
operation,
|
|
32
34
|
cause
|
|
33
35
|
})
|
|
34
|
-
})));
|
|
36
|
+
}))).pipe(Stream.tapCause(() => invalidate(target)));
|
|
35
37
|
const decodeSseData = (payload) => {
|
|
36
38
|
if (payload === "[DONE]" || payload.trim() === "") return [];
|
|
37
39
|
try {
|
|
@@ -53,7 +55,9 @@ const decodeSseEvents = (bytes) => bytes.pipe(Stream.decodeText(), Stream.splitL
|
|
|
53
55
|
}
|
|
54
56
|
return [pending, []];
|
|
55
57
|
}, { onHalt: (pending) => pending.length > 0 ? decodeSseData(pending.join("\n")) : [] }));
|
|
56
|
-
const makeProcessHandle = (definition, instance, process) => {
|
|
58
|
+
const makeProcessHandle = (definition, instance, process, target) => {
|
|
59
|
+
const attempt = (operation, evaluate) => trySandboxPromise(definition, instance, operation, evaluate, target);
|
|
60
|
+
const stream = (operation, acquire) => sandboxStream(definition, instance, operation, acquire, target);
|
|
57
61
|
const spanOptions = (operation) => ({ attributes: {
|
|
58
62
|
binding: definition.binding,
|
|
59
63
|
instance,
|
|
@@ -64,49 +68,51 @@ const makeProcessHandle = (definition, instance, process) => {
|
|
|
64
68
|
id: process.id,
|
|
65
69
|
pid: process.pid,
|
|
66
70
|
rawUnsafe: Effect.succeed(process),
|
|
67
|
-
status:
|
|
68
|
-
exitCode:
|
|
69
|
-
logs: (options) =>
|
|
71
|
+
status: attempt("process.status", () => process.status()).pipe(Effect.withSpan("Sandbox.process.status", spanOptions("process.status"))),
|
|
72
|
+
exitCode: attempt("process.exitCode", () => process.exitCode).pipe(Effect.withSpan("Sandbox.process.exitCode", spanOptions("process.exitCode"))),
|
|
73
|
+
logs: (options) => stream("process.logs", (signal) => process.logs({
|
|
70
74
|
...options,
|
|
71
75
|
signal
|
|
72
76
|
})),
|
|
73
77
|
waitForLog: Effect.fn("Sandbox.process.waitForLog", spanOptions("process.waitForLog"))(function* (pattern, options) {
|
|
74
|
-
return yield*
|
|
78
|
+
return yield* attempt("process.waitForLog", (signal) => process.waitForLog(pattern, {
|
|
75
79
|
...options,
|
|
76
80
|
signal
|
|
77
81
|
}));
|
|
78
82
|
}),
|
|
79
83
|
waitForExit: Effect.fn("Sandbox.process.waitForExit", spanOptions("process.waitForExit"))(function* (options) {
|
|
80
|
-
return yield*
|
|
84
|
+
return yield* attempt("process.waitForExit", (signal) => process.waitForExit({
|
|
81
85
|
...options,
|
|
82
86
|
signal
|
|
83
87
|
}));
|
|
84
88
|
}),
|
|
85
89
|
output: Effect.fn("Sandbox.process.output", spanOptions("process.output"))(function* (options) {
|
|
86
|
-
return yield*
|
|
90
|
+
return yield* attempt("process.output", (signal) => process.output({
|
|
87
91
|
...options,
|
|
88
92
|
signal
|
|
89
93
|
}));
|
|
90
94
|
}),
|
|
91
95
|
outputText: Effect.fn("Sandbox.process.outputText", spanOptions("process.outputText"))(function* (options) {
|
|
92
|
-
return yield*
|
|
96
|
+
return yield* attempt("process.outputText", (signal) => process.output({
|
|
93
97
|
...options,
|
|
94
98
|
encoding: "utf8",
|
|
95
99
|
signal
|
|
96
100
|
}));
|
|
97
101
|
}),
|
|
98
102
|
waitForPort: Effect.fn("Sandbox.process.waitForPort", spanOptions("process.waitForPort"))(function* (port, options) {
|
|
99
|
-
return yield*
|
|
103
|
+
return yield* attempt("process.waitForPort", (signal) => process.waitForPort(port, {
|
|
100
104
|
...options,
|
|
101
105
|
signal
|
|
102
106
|
}));
|
|
103
107
|
}),
|
|
104
108
|
kill: Effect.fn("Sandbox.process.kill", spanOptions("process.kill"))(function* (signal) {
|
|
105
|
-
return yield*
|
|
109
|
+
return yield* attempt("process.kill", () => process.kill(signal));
|
|
106
110
|
})
|
|
107
111
|
};
|
|
108
112
|
};
|
|
109
|
-
const makeTerminalHandle = (definition, instance, terminal) => {
|
|
113
|
+
const makeTerminalHandle = (definition, instance, terminal, target) => {
|
|
114
|
+
const attempt = (operation, evaluate) => trySandboxPromise(definition, instance, operation, evaluate, target);
|
|
115
|
+
const stream = (operation, acquire) => sandboxStream(definition, instance, operation, acquire, target);
|
|
110
116
|
const spanOptions = (operation) => ({ attributes: {
|
|
111
117
|
binding: definition.binding,
|
|
112
118
|
instance,
|
|
@@ -116,31 +122,34 @@ const makeTerminalHandle = (definition, instance, terminal) => {
|
|
|
116
122
|
return {
|
|
117
123
|
id: terminal.id,
|
|
118
124
|
rawUnsafe: Effect.succeed(terminal),
|
|
119
|
-
snapshot:
|
|
125
|
+
snapshot: attempt("terminal.snapshot", () => terminal.getSnapshot()).pipe(Effect.withSpan("Sandbox.terminal.snapshot", spanOptions("terminal.snapshot"))),
|
|
120
126
|
write: Effect.fn("Sandbox.terminal.write", spanOptions("terminal.write"))(function* (data) {
|
|
121
|
-
return yield*
|
|
127
|
+
return yield* attempt("terminal.write", () => terminal.write(data));
|
|
122
128
|
}),
|
|
123
129
|
resize: Effect.fn("Sandbox.terminal.resize", spanOptions("terminal.resize"))(function* (cols, rows) {
|
|
124
|
-
return yield*
|
|
130
|
+
return yield* attempt("terminal.resize", () => terminal.resize(cols, rows));
|
|
125
131
|
}),
|
|
126
|
-
output: (options) =>
|
|
132
|
+
output: (options) => stream("terminal.output", (signal) => terminal.output({
|
|
127
133
|
...options,
|
|
128
134
|
signal
|
|
129
135
|
})),
|
|
130
136
|
waitForExit: Effect.fn("Sandbox.terminal.waitForExit", spanOptions("terminal.waitForExit"))(function* (options) {
|
|
131
|
-
return yield*
|
|
137
|
+
return yield* attempt("terminal.waitForExit", (signal) => terminal.waitForExit({
|
|
132
138
|
...options,
|
|
133
139
|
signal
|
|
134
140
|
}));
|
|
135
141
|
}),
|
|
136
|
-
interrupt:
|
|
137
|
-
terminate:
|
|
142
|
+
interrupt: attempt("terminal.interrupt", () => terminal.interrupt()).pipe(Effect.withSpan("Sandbox.terminal.interrupt", spanOptions("terminal.interrupt"))),
|
|
143
|
+
terminate: attempt("terminal.terminate", () => terminal.terminate()).pipe(Effect.withSpan("Sandbox.terminal.terminate", spanOptions("terminal.terminate"))),
|
|
138
144
|
connect: Effect.fn("Sandbox.terminal.connect", spanOptions("terminal.connect"))(function* (request, options) {
|
|
139
|
-
return yield*
|
|
145
|
+
return yield* attempt("terminal.connect", () => terminal.connect(request, options));
|
|
140
146
|
})
|
|
141
147
|
};
|
|
142
148
|
};
|
|
143
|
-
const fromSandboxClient = (client, definition, instance) =>
|
|
149
|
+
const fromSandboxClient = (client, definition, instance) => makeSandboxClient(client, definition, instance, client);
|
|
150
|
+
const makeSandboxClient = (client, definition, instance, target) => {
|
|
151
|
+
const attempt = (operation, evaluate) => trySandboxPromise(definition, instance, operation, evaluate, target);
|
|
152
|
+
const stream = (operation, acquire) => sandboxStream(definition, instance, operation, acquire, target);
|
|
144
153
|
const spanOptions = (operation) => ({ attributes: {
|
|
145
154
|
binding: definition.binding,
|
|
146
155
|
instance,
|
|
@@ -149,135 +158,135 @@ const fromSandboxClient = (client, definition, instance) => {
|
|
|
149
158
|
return {
|
|
150
159
|
rawUnsafe: Effect.succeed(client),
|
|
151
160
|
exec: Effect.fn("Sandbox.exec", spanOptions("exec"))(function* (command, options) {
|
|
152
|
-
const process = yield*
|
|
153
|
-
return makeProcessHandle(definition, instance, process);
|
|
161
|
+
const process = yield* attempt("exec", () => client.exec(command, options));
|
|
162
|
+
return makeProcessHandle(definition, instance, process, target);
|
|
154
163
|
}),
|
|
155
164
|
getProcess: Effect.fn("Sandbox.getProcess", spanOptions("getProcess"))(function* (id) {
|
|
156
|
-
const process = yield*
|
|
157
|
-
return Option.map(Option.fromNullishOr(process), (found) => makeProcessHandle(definition, instance, found));
|
|
165
|
+
const process = yield* attempt("getProcess", () => client.getProcess(id));
|
|
166
|
+
return Option.map(Option.fromNullishOr(process), (found) => makeProcessHandle(definition, instance, found, target));
|
|
158
167
|
}),
|
|
159
|
-
listProcesses:
|
|
168
|
+
listProcesses: attempt("listProcesses", () => client.listProcesses()).pipe(Effect.withSpan("Sandbox.listProcesses", spanOptions("listProcesses"))),
|
|
160
169
|
writeFile: Effect.fn("Sandbox.writeFile", spanOptions("writeFile"))(function* (path, content, options) {
|
|
161
170
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
162
|
-
return yield*
|
|
171
|
+
return yield* attempt("writeFile", () => client.writeFile(path, content, options));
|
|
163
172
|
}),
|
|
164
173
|
readFile: Effect.fn("Sandbox.readFile", spanOptions("readFile"))(function* (path, options) {
|
|
165
174
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
166
|
-
return yield*
|
|
175
|
+
return yield* attempt("readFile", () => client.readFile(path, options));
|
|
167
176
|
}),
|
|
168
|
-
readFileStream: (path) =>
|
|
177
|
+
readFileStream: (path) => stream("readFileStream", () => client.readFileStream(path)),
|
|
169
178
|
mkdir: Effect.fn("Sandbox.mkdir", spanOptions("mkdir"))(function* (path, options) {
|
|
170
179
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
171
|
-
return yield*
|
|
180
|
+
return yield* attempt("mkdir", () => client.mkdir(path, options));
|
|
172
181
|
}),
|
|
173
182
|
deleteFile: Effect.fn("Sandbox.deleteFile", spanOptions("deleteFile"))(function* (path) {
|
|
174
183
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
175
|
-
return yield*
|
|
184
|
+
return yield* attempt("deleteFile", () => client.deleteFile(path));
|
|
176
185
|
}),
|
|
177
186
|
renameFile: Effect.fn("Sandbox.renameFile", spanOptions("renameFile"))(function* (oldPath, newPath) {
|
|
178
187
|
yield* Effect.annotateCurrentSpan({
|
|
179
188
|
oldPath,
|
|
180
189
|
newPath
|
|
181
190
|
});
|
|
182
|
-
return yield*
|
|
191
|
+
return yield* attempt("renameFile", () => client.renameFile(oldPath, newPath));
|
|
183
192
|
}),
|
|
184
193
|
moveFile: Effect.fn("Sandbox.moveFile", spanOptions("moveFile"))(function* (sourcePath, destinationPath) {
|
|
185
194
|
yield* Effect.annotateCurrentSpan({
|
|
186
195
|
sourcePath,
|
|
187
196
|
destinationPath
|
|
188
197
|
});
|
|
189
|
-
return yield*
|
|
198
|
+
return yield* attempt("moveFile", () => client.moveFile(sourcePath, destinationPath));
|
|
190
199
|
}),
|
|
191
200
|
listFiles: Effect.fn("Sandbox.listFiles", spanOptions("listFiles"))(function* (path, options) {
|
|
192
201
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
193
|
-
return yield*
|
|
202
|
+
return yield* attempt("listFiles", () => client.listFiles(path, options));
|
|
194
203
|
}),
|
|
195
204
|
exists: Effect.fn("Sandbox.exists", spanOptions("exists"))(function* (path) {
|
|
196
205
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
197
|
-
return yield*
|
|
206
|
+
return yield* attempt("exists", () => client.exists(path));
|
|
198
207
|
}),
|
|
199
|
-
watch: (path, options) => decodeSseEvents(
|
|
208
|
+
watch: (path, options) => decodeSseEvents(stream("watch", () => client.watch(path, options))),
|
|
200
209
|
checkChanges: Effect.fn("Sandbox.checkChanges", spanOptions("checkChanges"))(function* (path, options) {
|
|
201
210
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
202
|
-
return yield*
|
|
211
|
+
return yield* attempt("checkChanges", () => client.checkChanges(path, options));
|
|
203
212
|
}),
|
|
204
213
|
setEnvVars: Effect.fn("Sandbox.setEnvVars", spanOptions("setEnvVars"))(function* (envVars) {
|
|
205
|
-
return yield*
|
|
214
|
+
return yield* attempt("setEnvVars", () => client.setEnvVars(envVars));
|
|
206
215
|
}),
|
|
207
216
|
exposePort: Effect.fn("Sandbox.exposePort", spanOptions("exposePort"))(function* (port, options) {
|
|
208
217
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
209
|
-
return yield*
|
|
218
|
+
return yield* attempt("exposePort", () => client.exposePort(port, options));
|
|
210
219
|
}),
|
|
211
220
|
unexposePort: Effect.fn("Sandbox.unexposePort", spanOptions("unexposePort"))(function* (port) {
|
|
212
221
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
213
|
-
return yield*
|
|
222
|
+
return yield* attempt("unexposePort", () => client.unexposePort(port));
|
|
214
223
|
}),
|
|
215
224
|
getExposedPorts: Effect.fn("Sandbox.getExposedPorts", spanOptions("getExposedPorts"))(function* (hostname) {
|
|
216
|
-
return yield*
|
|
225
|
+
return yield* attempt("getExposedPorts", () => client.getExposedPorts(hostname));
|
|
217
226
|
}),
|
|
218
227
|
isPortExposed: Effect.fn("Sandbox.isPortExposed", spanOptions("isPortExposed"))(function* (port) {
|
|
219
228
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
220
|
-
return yield*
|
|
229
|
+
return yield* attempt("isPortExposed", () => client.isPortExposed(port));
|
|
221
230
|
}),
|
|
222
231
|
validatePortToken: Effect.fn("Sandbox.validatePortToken", spanOptions("validatePortToken"))(function* (port, token) {
|
|
223
232
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
224
|
-
return yield*
|
|
233
|
+
return yield* attempt("validatePortToken", () => client.validatePortToken(port, token));
|
|
225
234
|
}),
|
|
226
235
|
containerFetch: Effect.fn("Sandbox.containerFetch", spanOptions("containerFetch"))(function* (requestOrUrl, port) {
|
|
227
|
-
return yield*
|
|
236
|
+
return yield* attempt("containerFetch", () => client.containerFetch(requestOrUrl, port));
|
|
228
237
|
}),
|
|
229
238
|
wsConnect: Effect.fn("Sandbox.wsConnect", spanOptions("wsConnect"))(function* (request, port) {
|
|
230
239
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
231
|
-
return yield*
|
|
240
|
+
return yield* attempt("wsConnect", () => client.wsConnect(request, port));
|
|
232
241
|
}),
|
|
233
242
|
mountBucket: Effect.fn("Sandbox.mountBucket", spanOptions("mountBucket"))(function* (bucket, mountPath, options) {
|
|
234
243
|
yield* Effect.annotateCurrentSpan({
|
|
235
244
|
bucket,
|
|
236
245
|
mountPath
|
|
237
246
|
});
|
|
238
|
-
return yield*
|
|
247
|
+
return yield* attempt("mountBucket", () => client.mountBucket(bucket, mountPath, options));
|
|
239
248
|
}),
|
|
240
249
|
unmountBucket: Effect.fn("Sandbox.unmountBucket", spanOptions("unmountBucket"))(function* (mountPath) {
|
|
241
250
|
yield* Effect.annotateCurrentSpan("mountPath", mountPath);
|
|
242
|
-
return yield*
|
|
251
|
+
return yield* attempt("unmountBucket", () => client.unmountBucket(mountPath));
|
|
243
252
|
}),
|
|
244
253
|
createBackup: Effect.fn("Sandbox.createBackup", spanOptions("createBackup"))(function* (options) {
|
|
245
254
|
yield* Effect.annotateCurrentSpan("dir", options.dir);
|
|
246
|
-
return yield*
|
|
255
|
+
return yield* attempt("createBackup", () => client.createBackup(options));
|
|
247
256
|
}),
|
|
248
257
|
restoreBackup: Effect.fn("Sandbox.restoreBackup", spanOptions("restoreBackup"))(function* (backup) {
|
|
249
258
|
yield* Effect.annotateCurrentSpan({
|
|
250
259
|
backupId: backup.id,
|
|
251
260
|
dir: backup.dir
|
|
252
261
|
});
|
|
253
|
-
return yield*
|
|
262
|
+
return yield* attempt("restoreBackup", () => client.restoreBackup(backup));
|
|
254
263
|
}),
|
|
255
264
|
createTerminal: Effect.fn("Sandbox.createTerminal", spanOptions("createTerminal"))(function* (options) {
|
|
256
|
-
const terminal = yield*
|
|
257
|
-
return makeTerminalHandle(definition, instance, terminal);
|
|
265
|
+
const terminal = yield* attempt("createTerminal", () => client.createTerminal(options));
|
|
266
|
+
return makeTerminalHandle(definition, instance, terminal, target);
|
|
258
267
|
}),
|
|
259
268
|
getTerminal: Effect.fn("Sandbox.getTerminal", spanOptions("getTerminal"))(function* (id) {
|
|
260
|
-
const terminal = yield*
|
|
261
|
-
return Option.map(Option.fromNullishOr(terminal), (found) => makeTerminalHandle(definition, instance, found));
|
|
269
|
+
const terminal = yield* attempt("getTerminal", () => client.getTerminal(id));
|
|
270
|
+
return Option.map(Option.fromNullishOr(terminal), (found) => makeTerminalHandle(definition, instance, found, target));
|
|
262
271
|
}),
|
|
263
|
-
listTerminals:
|
|
272
|
+
listTerminals: attempt("listTerminals", () => client.listTerminals()).pipe(Effect.map((terminals) => terminals.map((terminal) => makeTerminalHandle(definition, instance, terminal, target))), Effect.withSpan("Sandbox.listTerminals", spanOptions("listTerminals"))),
|
|
264
273
|
tunnels: {
|
|
265
274
|
get: Effect.fn("Sandbox.tunnels.get", spanOptions("tunnels.get"))(function* (port, options) {
|
|
266
275
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
267
|
-
return yield*
|
|
276
|
+
return yield* attempt("tunnels.get", () => client.tunnels.get(port, options));
|
|
268
277
|
}),
|
|
269
|
-
list:
|
|
278
|
+
list: attempt("tunnels.list", () => client.tunnels.list()).pipe(Effect.withSpan("Sandbox.tunnels.list", spanOptions("tunnels.list"))),
|
|
270
279
|
destroy: Effect.fn("Sandbox.tunnels.destroy", spanOptions("tunnels.destroy"))(function* (portOrInfo) {
|
|
271
|
-
return yield*
|
|
280
|
+
return yield* attempt("tunnels.destroy", () => client.tunnels.destroy(portOrInfo));
|
|
272
281
|
})
|
|
273
282
|
},
|
|
274
283
|
start: Effect.fn("Sandbox.start", spanOptions("start"))(function* (options) {
|
|
275
|
-
return yield*
|
|
284
|
+
return yield* attempt("start", () => client.start(options));
|
|
276
285
|
}),
|
|
277
286
|
stop: Effect.fn("Sandbox.stop", spanOptions("stop"))(function* (signal) {
|
|
278
|
-
return yield*
|
|
287
|
+
return yield* attempt("stop", () => client.stop(signal));
|
|
279
288
|
}),
|
|
280
|
-
destroy:
|
|
289
|
+
destroy: attempt("destroy", () => client.destroy()).pipe(Effect.withSpan("Sandbox.destroy", spanOptions("destroy")))
|
|
281
290
|
};
|
|
282
291
|
};
|
|
283
292
|
/**
|
|
@@ -306,7 +315,20 @@ const makeClient = (definition) => (namespace) => {
|
|
|
306
315
|
} })(function* (name, options) {
|
|
307
316
|
yield* Effect.annotateCurrentSpan("instance", name);
|
|
308
317
|
const sandboxModule = yield* importSandboxModule(definition, name);
|
|
309
|
-
const
|
|
318
|
+
const targets = yield* Effect.serviceOption(CurrentTargets);
|
|
319
|
+
const scopedNamespace = yield* get(namespace, "sandbox-namespace", () => {
|
|
320
|
+
const adapter = {
|
|
321
|
+
idFromName: (name) => namespace.idFromName(name),
|
|
322
|
+
get: (id, options) => Option.isSome(targets) ? targets.value.get(adapter, JSON.stringify([id.toString(), options]), () => namespace.get(id, options)) : namespace.get(id, options)
|
|
323
|
+
};
|
|
324
|
+
return adapter;
|
|
325
|
+
}).pipe(Effect.mapError((error) => new SandboxOperationError({
|
|
326
|
+
binding: definition.binding,
|
|
327
|
+
instance: name,
|
|
328
|
+
operation: "get",
|
|
329
|
+
cause: error.cause
|
|
330
|
+
})));
|
|
331
|
+
const nativeNamespace = scopedNamespace;
|
|
310
332
|
const client = yield* Effect.try({
|
|
311
333
|
try: () => sandboxModule.getSandbox(nativeNamespace, name, options),
|
|
312
334
|
catch: (cause) => new SandboxOperationError({
|
|
@@ -316,7 +338,7 @@ const makeClient = (definition) => (namespace) => {
|
|
|
316
338
|
cause
|
|
317
339
|
})
|
|
318
340
|
});
|
|
319
|
-
return
|
|
341
|
+
return makeSandboxClient(client, definition, name, scopedNamespace);
|
|
320
342
|
}),
|
|
321
343
|
rawUnsafe: Effect.succeed(namespace)
|
|
322
344
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { WorkerEnvironment } from "./Environment.mjs";
|
|
2
2
|
import { BindingNotFoundError, BindingService, BindingValidationError } from "./Binding.mjs";
|
|
3
|
-
import { Provider
|
|
3
|
+
import { Provider } from "./Rpc.mjs";
|
|
4
4
|
import { Definition, Method as Method$1 } from "./RpcDefinition.mjs";
|
|
5
|
-
import { AsyncMethodArgs, AsyncMethodCloudflareReturn, AsyncMethodKey, AsyncMethodSuccess } from "./internal/RpcInvocation.mjs";
|
|
6
5
|
import { Definition as Definition$1, ReservedMethodName as ReservedMethodName$1, ServerApi } from "./WorkerDefinition.mjs";
|
|
6
|
+
import { AsyncMethodArgs, AsyncMethodCloudflareReturn, AsyncMethodKey, AsyncMethodSuccess } from "./internal/RpcInvocation.mjs";
|
|
7
7
|
import * as Effect from "effect/Effect";
|
|
8
8
|
import * as Schema$1 from "effect/Schema";
|
|
9
9
|
import { Context, Scope } from "effect";
|
|
10
10
|
declare namespace ServiceBinding_d_exports {
|
|
11
|
-
export { Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceFetcher, isServiceBindingClient, layer, makeClient, makeDirectMethods };
|
|
11
|
+
export { BindingNotFoundError, BindingValidationError, Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceCall, ServiceClass, ServiceFetcher, ServiceRpc, ServiceScopedCall, isServiceBindingClient, layer, makeClient, makeDirectMethods };
|
|
12
12
|
}
|
|
13
13
|
declare const TypeId: "effect-cf/ServiceBinding";
|
|
14
14
|
interface ServiceFetcher {
|
|
@@ -58,6 +58,8 @@ type ServiceMethodArgs<Api, Method extends keyof Api> = AsyncMethodArgs<Api, Met
|
|
|
58
58
|
type ServiceMethodSuccess<Api, Method extends keyof Api> = AsyncMethodSuccess<Api, Method>;
|
|
59
59
|
type ServiceMethodCloudflareReturn<Api, Method extends keyof Api> = AsyncMethodCloudflareReturn<Api, Method>;
|
|
60
60
|
type ServiceCall<R, Api> = <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodSuccess<Api, Method>, ServiceBindingRpcError, R>;
|
|
61
|
+
type ServiceRpc<R, Api> = <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<ServiceMethodCloudflareReturn<Api, Method>, ServiceBindingRpcError, R>;
|
|
62
|
+
type ServiceScopedCall<R, Api> = <Method extends ServiceMethodKey<Api>>(method: Method, ...args: ServiceMethodArgs<Api, Method>) => Effect.Effect<Awaited<ServiceMethodSuccess<Api, Method>>, ServiceBindingRpcError, Scope.Scope | R>;
|
|
61
63
|
type DefinitionDirectMethods<R, Definition$2 extends Definition$1.Any> = { readonly [Method in Definition.MethodNames<Definition$2>]: (...args: Method$1.Args<Definition$2["methods"][Method]>) => Effect.Effect<Method$1.Success<Definition$2["methods"][Method]>, ServiceBindingRpcError, R>; };
|
|
62
64
|
type DirectMethods<R, Definition> = Definition extends Definition$1.Any ? DefinitionDirectMethods<R, Definition> : {};
|
|
63
65
|
type ServiceBindingEffectClient<Api extends object, Definition extends Definition$1.Any | undefined = undefined> = DirectMethods<never, Definition> & {
|
|
@@ -71,14 +73,14 @@ type ServiceBindingEffectClient<Api extends object, Definition extends Definitio
|
|
|
71
73
|
*
|
|
72
74
|
* Most application code should use {@link call} instead.
|
|
73
75
|
*/
|
|
74
|
-
readonly rpc: <
|
|
76
|
+
readonly rpc: ServiceRpc<never, Api>;
|
|
75
77
|
/**
|
|
76
78
|
* Invokes a Worker RPC method, resolves Cloudflare's RPC result, and decodes
|
|
77
79
|
* the success value when the binding was created from a definition.
|
|
78
80
|
*
|
|
79
81
|
* This is the normal choice when application code wants the final typed value.
|
|
80
82
|
*/
|
|
81
|
-
readonly call: <
|
|
83
|
+
readonly call: ServiceCall<never, Api>;
|
|
82
84
|
/**
|
|
83
85
|
* Invokes a Worker RPC method in the current `Scope`, resolves Cloudflare's RPC
|
|
84
86
|
* result, decodes definition-backed success values, and disposes the resolved
|
|
@@ -87,26 +89,23 @@ type ServiceBindingEffectClient<Api extends object, Definition extends Definitio
|
|
|
87
89
|
* Use this for RPC methods that return Cloudflare RPC resources or other
|
|
88
90
|
* disposable objects whose lifetime should be tied to an Effect scope.
|
|
89
91
|
*/
|
|
90
|
-
readonly scopedCall: <
|
|
92
|
+
readonly scopedCall: ServiceScopedCall<never, Api>;
|
|
91
93
|
};
|
|
92
94
|
type ServiceBindingStaticClient<R, Api extends object, Definition extends Definition$1.Any | undefined = undefined> = DirectMethods<R, Definition> & {
|
|
93
95
|
readonly fetch: (input: RequestInfo | URL, init?: RequestInit) => Effect.Effect<globalThis.Response, ServiceBindingFetchError, R>;
|
|
94
|
-
readonly rpc: <
|
|
95
|
-
readonly call: <
|
|
96
|
-
readonly scopedCall: <
|
|
96
|
+
readonly rpc: ServiceRpc<R, Api>;
|
|
97
|
+
readonly call: ServiceCall<R, Api>;
|
|
98
|
+
readonly scopedCall: ServiceScopedCall<R, Api>;
|
|
99
|
+
};
|
|
100
|
+
type ServiceClass<Self, Id extends string, Api extends object = never, Definition extends Definition$1.Any | undefined = undefined> = BindingService<Self, Id, ServiceBindingEffectClient<ApiOrDefinition<Api, Definition>, Definition>> & ServiceBindingStaticClient<Self, ApiOrDefinition<Api, Definition>, Definition> & {
|
|
101
|
+
readonly [TypeId]: typeof TypeId;
|
|
102
|
+
readonly definition: ServiceBindingDefinition<Definition>;
|
|
97
103
|
};
|
|
98
104
|
type ServiceBindingValue = Schema$1.Schema.Type<typeof Schema$1.Unknown>;
|
|
99
105
|
declare const isServiceBindingClient: <Api extends object>(value: ServiceBindingValue) => value is ServiceBindingClient<Api>;
|
|
100
106
|
declare const makeClient: <Api extends object, const Definition extends Definition$1.Any | undefined = undefined>(definition: ServiceBindingDefinition<Definition>) => ((service: ServiceBindingClient<Api>) => ServiceBindingEffectClient<Api, Definition>);
|
|
101
107
|
declare const layer: <Self, Api extends object, const Definition extends Definition$1.Any | undefined = undefined>(tag: Context.Service<Self, ServiceBindingEffectClient<Api, Definition>>, definition: ServiceBindingDefinition<Definition>) => import("effect/Layer").Layer<Self, BindingNotFoundError | BindingValidationError, WorkerEnvironment>;
|
|
102
|
-
declare const Service: <Self, Api extends object = never>() => <Id extends string, const Definition extends Definition$1.Any | undefined = undefined>(id: Id, definition: ServiceBindingDefinition<Definition>) =>
|
|
103
|
-
readonly [TypeId]: typeof TypeId;
|
|
104
|
-
readonly definition: ServiceBindingDefinition<Definition>;
|
|
105
|
-
readonly fetch: (input: URL | RequestInfo<unknown, CfProperties<unknown>>, init?: RequestInit<CfProperties<unknown>> | undefined) => Effect.Effect<Response, ServiceBindingFetchError, Self>;
|
|
106
|
-
readonly rpc: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Result<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, ServiceBindingRpcError, Self>;
|
|
107
|
-
readonly call: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>, ServiceBindingRpcError, Self>;
|
|
108
|
-
readonly scopedCall: <Method extends ServiceMethodKey<ApiOrDefinition<Api, Definition>>>(method: Method, ...args: AsyncMethodArgs<ApiOrDefinition<Api, Definition>, Method>) => Effect.Effect<Awaited<AsyncMethodSuccess<ApiOrDefinition<Api, Definition>, Method>>, ServiceBindingRpcError, Self | Scope.Scope>;
|
|
109
|
-
};
|
|
108
|
+
declare const Service: <Self, Api extends object = never>() => <Id extends string, const Definition extends Definition$1.Any | undefined = undefined>(id: Id, definition: ServiceBindingDefinition<Definition>) => ServiceClass<Self, Id, Api, Definition>;
|
|
110
109
|
declare const makeDirectMethods: <R, Api, Definition extends Definition$1.Any | undefined>(rpcDefinition: Definition | undefined, call: ServiceCall<R, Api>) => DirectMethods<R, Definition>;
|
|
111
110
|
//#endregion
|
|
112
|
-
export { Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceBinding_d_exports, ServiceFetcher, isServiceBindingClient, layer, makeClient, makeDirectMethods };
|
|
111
|
+
export { type BindingNotFoundError, type BindingValidationError, Service, ServiceBindingClient, ServiceBindingDefinition, ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceBinding_d_exports, ServiceCall, ServiceClass, ServiceFetcher, ServiceRpc, ServiceScopedCall, isServiceBindingClient, layer, makeClient, makeDirectMethods };
|
package/dist/Vectorize.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ import * as Effect from "effect/Effect";
|
|
|
5
5
|
import * as Schema$1 from "effect/Schema";
|
|
6
6
|
import { Layer } from "effect";
|
|
7
7
|
declare namespace Vectorize_d_exports {
|
|
8
|
-
export { LayerOptions, Tag, TagClass, VectorizeBinding, VectorizeClient, VectorizeDefinition, VectorizeIndexDetails, VectorizeIndexInfo, VectorizeMatch, VectorizeMatches, VectorizeMutation, VectorizeOperation, VectorizeOperationError, VectorizeQueryOptions, VectorizeService, VectorizeValues, VectorizeVector, VectorizeVectorMetadata, VectorizeVectorMetadataFilter, VectorizeVectorMetadataValue, isVectorizeBinding, layer, make, makeClient };
|
|
8
|
+
export { BindingNotFoundError, BindingValidationError, LayerOptions, Tag, TagClass, VectorizeBinding, VectorizeClient, VectorizeDefinition, VectorizeIndexDetails, VectorizeIndexInfo, VectorizeMatch, VectorizeMatches, VectorizeMutation, VectorizeOperation, VectorizeOperationError, VectorizeQueryOptions, VectorizeService, VectorizeValues, VectorizeVector, VectorizeVectorMetadata, VectorizeVectorMetadataFilter, VectorizeVectorMetadataValue, isVectorizeBinding, layer, make, makeClient };
|
|
9
9
|
}
|
|
10
10
|
type VectorizeOperation = "describe" | "query" | "queryById" | "insert" | "upsert" | "deleteByIds" | "getByIds";
|
|
11
11
|
declare const VectorizeOperationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
@@ -65,4 +65,4 @@ declare const layer: <Self>(tag: Context$1.Service<Self, VectorizeClient>, defin
|
|
|
65
65
|
declare const make: <Id extends string>(id: Id) => TagClass<VectorizeService<Id>, Id>;
|
|
66
66
|
declare const Tag: <Self>() => <Id extends string>(id: Id) => TagClass<Self, Id>;
|
|
67
67
|
//#endregion
|
|
68
|
-
export { LayerOptions, Tag, TagClass, VectorizeBinding, VectorizeClient, VectorizeDefinition, VectorizeIndexDetails, VectorizeIndexInfo, VectorizeMatch, VectorizeMatches, VectorizeMutation, VectorizeOperation, VectorizeOperationError, VectorizeQueryOptions, VectorizeService, VectorizeValues, VectorizeVector, VectorizeVectorMetadata, VectorizeVectorMetadataFilter, VectorizeVectorMetadataValue, Vectorize_d_exports, isVectorizeBinding, layer, make, makeClient };
|
|
68
|
+
export { type BindingNotFoundError, type BindingValidationError, LayerOptions, Tag, TagClass, VectorizeBinding, VectorizeClient, VectorizeDefinition, VectorizeIndexDetails, VectorizeIndexInfo, VectorizeMatch, VectorizeMatches, VectorizeMutation, VectorizeOperation, VectorizeOperationError, VectorizeQueryOptions, VectorizeService, VectorizeValues, VectorizeVector, VectorizeVectorMetadata, VectorizeVectorMetadataFilter, VectorizeVectorMetadataValue, Vectorize_d_exports, isVectorizeBinding, layer, make, makeClient };
|
package/dist/Worker.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { WorkerEnv, WorkerEnvironment } from "./Environment.mjs";
|
|
2
|
+
import { BindingNotFoundError, BindingValidationError } from "./Binding.mjs";
|
|
2
3
|
import { ReservedMethodName as ReservedMethodName$1 } from "./RpcDefinition.mjs";
|
|
3
4
|
import { QueueHandler } from "./Queue.mjs";
|
|
4
5
|
import { ReceiverOptions, RpcInvocationInfo } from "./RpcTracing.mjs";
|
|
5
|
-
import { Api, Definition, HandlerEffect, Handlers, LayerOptions, Method, Methods, NoReservedMethods, Options, ServerApi, ServiceFreeSchema, Tag, TagClass, implement, method } from "./WorkerDefinition.mjs";
|
|
6
|
+
import { Api, Definition, HandlerEffect, Handlers, LayerOptions, Method, Methods, NativeSchema, NoReservedMethods, Options, RpcSchema, ServerApi, ServiceFreeSchema, Tag, TagClass, implement, method, native } from "./WorkerDefinition.mjs";
|
|
7
|
+
import { ServiceBindingFetchError, ServiceBindingRpcError, ServiceCall, ServiceRpc, ServiceScopedCall } from "./ServiceBinding.mjs";
|
|
6
8
|
import * as Context$1 from "effect/Context";
|
|
7
9
|
import * as Effect from "effect/Effect";
|
|
8
10
|
import * as Layer$1 from "effect/Layer";
|
|
@@ -11,7 +13,7 @@ import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
|
|
|
11
13
|
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
|
12
14
|
import { Cause, Scope } from "effect";
|
|
13
15
|
declare namespace Worker_d_exports {
|
|
14
|
-
export { Api, Definition, ExecutionContext, FetchHandler, FetchWorkerOptions, HandlerEffect, Handlers, LayerOptions, Method, Methods, NativeRequest, NoReservedMethods, Options, ReservedMethodName, RpcHandlers, RunOptions, RunSymbol, ServerApi, ServiceFreeSchema, Tag, TagClass, WorkerClass, WorkerContext, WorkerContextService, WorkerContextWaitUntilOptions, WorkerFetchSuccess, WorkerHandler, WorkerOptions, WorkerRpc, WorkerRpcContract, WorkerRpcHandler, WorkerRpcContract as WorkerRpcShape, implement, isWebSocketUpgrade, make, makeFetchHandler, method };
|
|
16
|
+
export { Api, BindingNotFoundError, BindingValidationError, Definition, ExecutionContext, FetchHandler, FetchWorkerOptions, HandlerEffect, Handlers, LayerOptions, Method, Methods, NativeRequest, NativeSchema, NoReservedMethods, Options, ReservedMethodName, RpcHandlers, RpcSchema, RunOptions, RunSymbol, ServerApi, ServiceBindingFetchError, ServiceBindingRpcError, ServiceCall, ServiceFreeSchema, ServiceRpc, ServiceScopedCall, Tag, TagClass, WorkerClass, WorkerContext, WorkerContextService, WorkerContextWaitUntilOptions, WorkerFetchSuccess, WorkerHandler, WorkerOptions, WorkerRpc, WorkerRpcContract, WorkerRpcHandler, WorkerRpcContract as WorkerRpcShape, implement, isWebSocketUpgrade, make, makeFetchHandler, method, native };
|
|
15
17
|
}
|
|
16
18
|
declare const ExecutionContext_base: Context$1.ServiceClass<ExecutionContext, "effect-cf/ExecutionContext", globalThis.ExecutionContext<unknown>>;
|
|
17
19
|
declare class ExecutionContext extends ExecutionContext_base {}
|
|
@@ -136,4 +138,4 @@ declare function make<ROut, LayerError, REvent extends never = never, EventLayer
|
|
|
136
138
|
declare function makeFetchHandler<ROut, LayerError, REvent, EventLayerError = never, Env extends WorkerEnv = WorkerEnv>(layer: Layer$1.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: FetchWorkerOptionsWithEventLayer<ROut, REvent, EventLayerError>): FetchHandler<Env>;
|
|
137
139
|
declare function makeFetchHandler<ROut, LayerError, REvent extends never = never, EventLayerError = never, Env extends WorkerEnv = WorkerEnv>(layer: Layer$1.Layer<ROut, LayerError, ExecutionContext | WorkerContext | WorkerEnvironment>, options: FetchWorkerOptions<ROut, REvent, EventLayerError>): FetchHandler<Env>;
|
|
138
140
|
//#endregion
|
|
139
|
-
export { type Api, type Definition, ExecutionContext, FetchHandler, FetchWorkerOptions, type HandlerEffect, type Handlers, type LayerOptions, type Method, type Methods, NativeRequest, type NoReservedMethods, type Options, ReservedMethodName, RpcHandlers, RunOptions, RunSymbol, type ServerApi, type ServiceFreeSchema, Tag, type TagClass, WorkerClass, WorkerContext, WorkerContextService, WorkerContextWaitUntilOptions, WorkerFetchSuccess, WorkerHandler, WorkerOptions, WorkerRpc, WorkerRpcContract, type WorkerRpcContract as WorkerRpcShape, WorkerRpcHandler, Worker_d_exports, implement, isWebSocketUpgrade, make, makeFetchHandler, method };
|
|
141
|
+
export { type Api, type BindingNotFoundError, type BindingValidationError, type Definition, ExecutionContext, FetchHandler, FetchWorkerOptions, type HandlerEffect, type Handlers, type LayerOptions, type Method, type Methods, NativeRequest, type NativeSchema, type NoReservedMethods, type Options, ReservedMethodName, RpcHandlers, type RpcSchema, RunOptions, RunSymbol, type ServerApi, type ServiceBindingFetchError, type ServiceBindingRpcError, type ServiceCall, type ServiceFreeSchema, type ServiceRpc, type ServiceScopedCall, Tag, type TagClass, WorkerClass, WorkerContext, WorkerContextService, WorkerContextWaitUntilOptions, WorkerFetchSuccess, WorkerHandler, WorkerOptions, WorkerRpc, WorkerRpcContract, type WorkerRpcContract as WorkerRpcShape, WorkerRpcHandler, Worker_d_exports, implement, isWebSocketUpgrade, make, makeFetchHandler, method, native };
|
package/dist/Worker.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
2
|
import { fromExecutionContext } from "./internal/WorkerContext.mjs";
|
|
3
|
+
import { withScope } from "./RpcTargets.mjs";
|
|
3
4
|
import { fromMessage, fromMessageBatch } from "./Queue.mjs";
|
|
4
5
|
import { reservedMethodNames as reservedMethodNames$1 } from "./RpcDefinition.mjs";
|
|
5
|
-
import { withScope } from "./RpcTargets.mjs";
|
|
6
6
|
import { assumeEntrypointClass, defineEntrypointRpcMethods } from "./internal/Entrypoint.mjs";
|
|
7
7
|
import { makeEntrypointRuntime, runEventPromise } from "./internal/Runtime.mjs";
|
|
8
8
|
import { scheduleTelemetryFlush as scheduleTelemetryFlush$1 } from "./internal/Telemetry.mjs";
|
|
9
|
-
import { Tag, implement, method } from "./WorkerDefinition.mjs";
|
|
9
|
+
import { Tag, implement, method, native } from "./WorkerDefinition.mjs";
|
|
10
10
|
import * as Context from "effect/Context";
|
|
11
11
|
import * as Effect from "effect/Effect";
|
|
12
12
|
import * as Layer from "effect/Layer";
|
|
@@ -28,7 +28,8 @@ var Worker_exports = /* @__PURE__ */ __exportAll({
|
|
|
28
28
|
isWebSocketUpgrade: () => isWebSocketUpgrade,
|
|
29
29
|
make: () => make,
|
|
30
30
|
makeFetchHandler: () => makeFetchHandler,
|
|
31
|
-
method: () => method
|
|
31
|
+
method: () => method,
|
|
32
|
+
native: () => native
|
|
32
33
|
});
|
|
33
34
|
var ExecutionContext = class extends Context.Service()("effect-cf/ExecutionContext") {};
|
|
34
35
|
var WorkerContext = class extends Context.Service()("effect-cf/WorkerContext") {};
|
|
@@ -139,4 +140,4 @@ function makeFetchHandler(layer, options) {
|
|
|
139
140
|
} };
|
|
140
141
|
}
|
|
141
142
|
//#endregion
|
|
142
|
-
export { ExecutionContext, NativeRequest, RunSymbol, Tag, WorkerContext, Worker_exports, implement, isWebSocketUpgrade, make, makeFetchHandler, method };
|
|
143
|
+
export { ExecutionContext, NativeRequest, RunSymbol, Tag, WorkerContext, Worker_exports, implement, isWebSocketUpgrade, make, makeFetchHandler, method, native };
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { WorkerEnvironment } from "./Environment.mjs";
|
|
2
2
|
import { BindingNotFoundError, BindingValidationError } from "./Binding.mjs";
|
|
3
3
|
import { Provider } from "./Rpc.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { NativeSchema as NativeSchema$1, RpcSchema as RpcSchema$1, SchemaType, WireEncoded, native as native$1 } from "./RpcDefinition.mjs";
|
|
5
|
+
import { ServiceBindingEffectClient, ServiceBindingFetchError, ServiceBindingRpcError, ServiceBindingStaticClient, ServiceCall, ServiceRpc, ServiceScopedCall } from "./ServiceBinding.mjs";
|
|
5
6
|
import { ExecutionContext, ReservedMethodName as ReservedMethodName$1, WorkerClass, WorkerContext, WorkerOptions, WorkerRpcHandler } from "./Worker.mjs";
|
|
6
7
|
import * as Context$1 from "effect/Context";
|
|
7
8
|
import { Layer, Schema } from "effect";
|
|
8
9
|
declare namespace WorkerDefinition_d_exports {
|
|
9
|
-
export { Api, Definition, HandlerEffect, Handlers, LayerOptions, Method, Methods, NoReservedMethods, Options, ReservedMethodName, ServerApi, ServiceFreeSchema, Tag, TagClass, Worker, implement, make, method };
|
|
10
|
+
export { Api, BindingNotFoundError, BindingValidationError, Definition, HandlerEffect, Handlers, LayerOptions, Method, Methods, NativeSchema, NoReservedMethods, Options, ReservedMethodName, RpcSchema, ServerApi, ServiceBindingFetchError, ServiceBindingRpcError, ServiceCall, ServiceFreeSchema, ServiceRpc, ServiceScopedCall, Tag, TagClass, Worker, implement, make, method, native };
|
|
10
11
|
}
|
|
11
12
|
type ServiceFreeSchema = Schema.Codec<any, any, never, never>;
|
|
12
|
-
|
|
13
|
+
type NativeSchema<Schema extends ServiceFreeSchema = ServiceFreeSchema> = NativeSchema$1<Schema>;
|
|
14
|
+
type RpcSchema = RpcSchema$1;
|
|
15
|
+
interface Method<Args extends ReadonlyArray<RpcSchema> = ReadonlyArray<RpcSchema>, Success extends RpcSchema = RpcSchema> {
|
|
13
16
|
readonly args: Args;
|
|
14
17
|
readonly success: Success;
|
|
15
18
|
}
|
|
16
19
|
declare namespace Method {
|
|
17
|
-
export type Any = Method<ReadonlyArray<
|
|
18
|
-
type ArgsFromSchemas<Args extends ReadonlyArray<
|
|
19
|
-
type EncodedArgsFromSchemas<Args extends ReadonlyArray<
|
|
20
|
+
export type Any = Method<ReadonlyArray<RpcSchema>, RpcSchema>;
|
|
21
|
+
type ArgsFromSchemas<Args extends ReadonlyArray<RpcSchema>> = Args extends readonly [] ? [] : Args extends readonly [infer Head extends RpcSchema, ...infer Tail extends ReadonlyArray<RpcSchema>] ? [SchemaType<Head>, ...ArgsFromSchemas<Tail>] : Array<SchemaType<Args[number]>>;
|
|
22
|
+
type EncodedArgsFromSchemas<Args extends ReadonlyArray<RpcSchema>> = { [Index in keyof Args]: WireEncoded<Args[Index]>; };
|
|
20
23
|
export type Args<Self extends Any> = ArgsFromSchemas<Self["args"]>;
|
|
21
24
|
export type EncodedArgs<Self extends Any> = EncodedArgsFromSchemas<Self["args"]>;
|
|
22
|
-
export type Success<Self extends Any> =
|
|
23
|
-
export type EncodedSuccess<
|
|
25
|
+
export type Success<Self extends Any> = SchemaType<Self["success"]>;
|
|
26
|
+
export type EncodedSuccess<Self extends Any> = WireEncoded<Self["success"]>;
|
|
24
27
|
export {};
|
|
25
28
|
}
|
|
26
29
|
type Methods = Record<string, Method.Any>;
|
|
@@ -77,14 +80,15 @@ type TagClass<Self, Id extends string, MethodDefinitions extends Methods> = Cont
|
|
|
77
80
|
* Defines a single RPC method schema in a worker definition.
|
|
78
81
|
*/
|
|
79
82
|
declare const method: {
|
|
80
|
-
<Success extends
|
|
83
|
+
<Success extends RpcSchema>(definition: {
|
|
81
84
|
readonly success: Success;
|
|
82
85
|
}): Method<readonly [], Success>;
|
|
83
|
-
<const Args extends ReadonlyArray<
|
|
86
|
+
<const Args extends ReadonlyArray<RpcSchema>, Success extends RpcSchema>(definition: {
|
|
84
87
|
readonly args: Args;
|
|
85
88
|
readonly success: Success;
|
|
86
89
|
}): Method<Args, Success>;
|
|
87
90
|
};
|
|
91
|
+
declare const native: typeof native$1;
|
|
88
92
|
declare const make: <Id extends string, const MethodDefinitions extends Methods>(id: Id, methods: MethodDefinitions & NoReservedMethods<MethodDefinitions>) => TagClass<Definition<Id, MethodDefinitions>, Id, MethodDefinitions>;
|
|
89
93
|
declare const Tag: <Self>() => <Id extends string, const MethodDefinitions extends Methods>(id: Id, methods: MethodDefinitions & NoReservedMethods<MethodDefinitions>) => TagClass<Self, Id, MethodDefinitions>;
|
|
90
94
|
declare const Worker: typeof Tag;
|
|
@@ -97,4 +101,4 @@ declare const implement: <ROut, const Self extends Definition.Any>(_definition:
|
|
|
97
101
|
*/
|
|
98
102
|
type HandlerEffect<ROut, Self extends Definition.Any, Key extends keyof Self["methods"]> = WorkerRpcHandler<ROut, Method.Success<Self["methods"][Key]>>;
|
|
99
103
|
//#endregion
|
|
100
|
-
export { Api, Definition, HandlerEffect, Handlers, LayerOptions, Method, Methods, NoReservedMethods, Options, ReservedMethodName, ServerApi, ServiceFreeSchema, Tag, TagClass, Worker, WorkerDefinition_d_exports, implement, make, method };
|
|
104
|
+
export { Api, type BindingNotFoundError, type BindingValidationError, Definition, HandlerEffect, Handlers, LayerOptions, Method, Methods, NativeSchema, NoReservedMethods, Options, ReservedMethodName, RpcSchema, ServerApi, type ServiceBindingFetchError, type ServiceBindingRpcError, type ServiceCall, ServiceFreeSchema, type ServiceRpc, type ServiceScopedCall, Tag, TagClass, Worker, WorkerDefinition_d_exports, implement, make, method, native };
|