effect-cf 0.48.0 → 0.50.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 +20 -0
- package/README.md +4 -2
- package/dist/ContainerFiles.d.mts +66 -0
- package/dist/ContainerFiles.mjs +66 -0
- package/dist/ContainerNamespace.d.mts +3 -1
- package/dist/DurableObjectContainer.d.mts +133 -0
- package/dist/DurableObjectContainer.mjs +179 -0
- package/dist/Sandbox.d.mts +1 -1
- package/dist/Sandbox.mjs +68 -64
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +3 -1
- package/package.json +4 -3
- package/src/ContainerFiles.ts +162 -0
- package/src/ContainerNamespace.ts +3 -1
- package/src/DurableObjectContainer.ts +388 -0
- package/src/Sandbox.ts +152 -98
- package/src/index.ts +2 -0
package/dist/Sandbox.mjs
CHANGED
|
@@ -146,147 +146,146 @@ const makeTerminalHandle = (definition, instance, terminal, target) => {
|
|
|
146
146
|
})
|
|
147
147
|
};
|
|
148
148
|
};
|
|
149
|
-
const fromSandboxClient = (client, definition, instance) => makeSandboxClient(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
const fromSandboxClient = (client, definition, instance) => makeSandboxClient(Effect.succeed({
|
|
150
|
+
client,
|
|
151
|
+
target: client
|
|
152
|
+
}), definition, instance);
|
|
153
|
+
const makeSandboxClient = (resolve, definition, instance) => {
|
|
154
|
+
const attempt = (operation, evaluate) => Effect.flatMap(resolve, ({ client, target }) => trySandboxPromise(definition, instance, operation, (signal) => evaluate(client, signal, target), target));
|
|
155
|
+
const stream = (operation, acquire) => Stream.unwrap(Effect.map(resolve, ({ client, target }) => sandboxStream(definition, instance, operation, (signal) => acquire(client, signal), target)));
|
|
153
156
|
const spanOptions = (operation) => ({ attributes: {
|
|
154
157
|
binding: definition.binding,
|
|
155
158
|
instance,
|
|
156
159
|
operation
|
|
157
160
|
} });
|
|
158
161
|
return {
|
|
159
|
-
rawUnsafe: Effect.
|
|
162
|
+
rawUnsafe: Effect.map(resolve, ({ client }) => client),
|
|
160
163
|
exec: Effect.fn("Sandbox.exec", spanOptions("exec"))(function* (command, options) {
|
|
161
|
-
|
|
162
|
-
return makeProcessHandle(definition, instance, process, target);
|
|
164
|
+
return yield* attempt("exec", (client, _signal, target) => client.exec(command, options).then((process) => makeProcessHandle(definition, instance, process, target)));
|
|
163
165
|
}),
|
|
164
166
|
getProcess: Effect.fn("Sandbox.getProcess", spanOptions("getProcess"))(function* (id) {
|
|
165
|
-
|
|
166
|
-
return Option.map(Option.fromNullishOr(process), (found) => makeProcessHandle(definition, instance, found, target));
|
|
167
|
+
return yield* attempt("getProcess", (client, _signal, target) => client.getProcess(id).then((process) => Option.map(Option.fromNullishOr(process), (found) => makeProcessHandle(definition, instance, found, target))));
|
|
167
168
|
}),
|
|
168
|
-
listProcesses: attempt("listProcesses", () => client.listProcesses()).pipe(Effect.withSpan("Sandbox.listProcesses", spanOptions("listProcesses"))),
|
|
169
|
+
listProcesses: attempt("listProcesses", (client) => client.listProcesses()).pipe(Effect.withSpan("Sandbox.listProcesses", spanOptions("listProcesses"))),
|
|
169
170
|
writeFile: Effect.fn("Sandbox.writeFile", spanOptions("writeFile"))(function* (path, content, options) {
|
|
170
171
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
171
|
-
return yield* attempt("writeFile", () => client.writeFile(path, content, options));
|
|
172
|
+
return yield* attempt("writeFile", (client) => client.writeFile(path, content, options));
|
|
172
173
|
}),
|
|
173
174
|
readFile: Effect.fn("Sandbox.readFile", spanOptions("readFile"))(function* (path, options) {
|
|
174
175
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
175
|
-
return yield* attempt("readFile", () => client.readFile(path, options));
|
|
176
|
+
return yield* attempt("readFile", (client) => client.readFile(path, options));
|
|
176
177
|
}),
|
|
177
|
-
readFileStream: (path) => stream("readFileStream", () => client.readFileStream(path)),
|
|
178
|
+
readFileStream: (path) => stream("readFileStream", (client) => client.readFileStream(path)),
|
|
178
179
|
mkdir: Effect.fn("Sandbox.mkdir", spanOptions("mkdir"))(function* (path, options) {
|
|
179
180
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
180
|
-
return yield* attempt("mkdir", () => client.mkdir(path, options));
|
|
181
|
+
return yield* attempt("mkdir", (client) => client.mkdir(path, options));
|
|
181
182
|
}),
|
|
182
183
|
deleteFile: Effect.fn("Sandbox.deleteFile", spanOptions("deleteFile"))(function* (path) {
|
|
183
184
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
184
|
-
return yield* attempt("deleteFile", () => client.deleteFile(path));
|
|
185
|
+
return yield* attempt("deleteFile", (client) => client.deleteFile(path));
|
|
185
186
|
}),
|
|
186
187
|
renameFile: Effect.fn("Sandbox.renameFile", spanOptions("renameFile"))(function* (oldPath, newPath) {
|
|
187
188
|
yield* Effect.annotateCurrentSpan({
|
|
188
189
|
oldPath,
|
|
189
190
|
newPath
|
|
190
191
|
});
|
|
191
|
-
return yield* attempt("renameFile", () => client.renameFile(oldPath, newPath));
|
|
192
|
+
return yield* attempt("renameFile", (client) => client.renameFile(oldPath, newPath));
|
|
192
193
|
}),
|
|
193
194
|
moveFile: Effect.fn("Sandbox.moveFile", spanOptions("moveFile"))(function* (sourcePath, destinationPath) {
|
|
194
195
|
yield* Effect.annotateCurrentSpan({
|
|
195
196
|
sourcePath,
|
|
196
197
|
destinationPath
|
|
197
198
|
});
|
|
198
|
-
return yield* attempt("moveFile", () => client.moveFile(sourcePath, destinationPath));
|
|
199
|
+
return yield* attempt("moveFile", (client) => client.moveFile(sourcePath, destinationPath));
|
|
199
200
|
}),
|
|
200
201
|
listFiles: Effect.fn("Sandbox.listFiles", spanOptions("listFiles"))(function* (path, options) {
|
|
201
202
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
202
|
-
return yield* attempt("listFiles", () => client.listFiles(path, options));
|
|
203
|
+
return yield* attempt("listFiles", (client) => client.listFiles(path, options));
|
|
203
204
|
}),
|
|
204
205
|
exists: Effect.fn("Sandbox.exists", spanOptions("exists"))(function* (path) {
|
|
205
206
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
206
|
-
return yield* attempt("exists", () => client.exists(path));
|
|
207
|
+
return yield* attempt("exists", (client) => client.exists(path));
|
|
207
208
|
}),
|
|
208
|
-
watch: (path, options) => decodeSseEvents(stream("watch", () => client.watch(path, options))),
|
|
209
|
+
watch: (path, options) => decodeSseEvents(stream("watch", (client) => client.watch(path, options))),
|
|
209
210
|
checkChanges: Effect.fn("Sandbox.checkChanges", spanOptions("checkChanges"))(function* (path, options) {
|
|
210
211
|
yield* Effect.annotateCurrentSpan("path", path);
|
|
211
|
-
return yield* attempt("checkChanges", () => client.checkChanges(path, options));
|
|
212
|
+
return yield* attempt("checkChanges", (client) => client.checkChanges(path, options));
|
|
212
213
|
}),
|
|
213
214
|
setEnvVars: Effect.fn("Sandbox.setEnvVars", spanOptions("setEnvVars"))(function* (envVars) {
|
|
214
|
-
return yield* attempt("setEnvVars", () => client.setEnvVars(envVars));
|
|
215
|
+
return yield* attempt("setEnvVars", (client) => client.setEnvVars(envVars));
|
|
215
216
|
}),
|
|
216
217
|
exposePort: Effect.fn("Sandbox.exposePort", spanOptions("exposePort"))(function* (port, options) {
|
|
217
218
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
218
|
-
return yield* attempt("exposePort", () => client.exposePort(port, options));
|
|
219
|
+
return yield* attempt("exposePort", (client) => client.exposePort(port, options));
|
|
219
220
|
}),
|
|
220
221
|
unexposePort: Effect.fn("Sandbox.unexposePort", spanOptions("unexposePort"))(function* (port) {
|
|
221
222
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
222
|
-
return yield* attempt("unexposePort", () => client.unexposePort(port));
|
|
223
|
+
return yield* attempt("unexposePort", (client) => client.unexposePort(port));
|
|
223
224
|
}),
|
|
224
225
|
getExposedPorts: Effect.fn("Sandbox.getExposedPorts", spanOptions("getExposedPorts"))(function* (hostname) {
|
|
225
|
-
return yield* attempt("getExposedPorts", () => client.getExposedPorts(hostname));
|
|
226
|
+
return yield* attempt("getExposedPorts", (client) => client.getExposedPorts(hostname));
|
|
226
227
|
}),
|
|
227
228
|
isPortExposed: Effect.fn("Sandbox.isPortExposed", spanOptions("isPortExposed"))(function* (port) {
|
|
228
229
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
229
|
-
return yield* attempt("isPortExposed", () => client.isPortExposed(port));
|
|
230
|
+
return yield* attempt("isPortExposed", (client) => client.isPortExposed(port));
|
|
230
231
|
}),
|
|
231
232
|
validatePortToken: Effect.fn("Sandbox.validatePortToken", spanOptions("validatePortToken"))(function* (port, token) {
|
|
232
233
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
233
|
-
return yield* attempt("validatePortToken", () => client.validatePortToken(port, token));
|
|
234
|
+
return yield* attempt("validatePortToken", (client) => client.validatePortToken(port, token));
|
|
234
235
|
}),
|
|
235
236
|
containerFetch: Effect.fn("Sandbox.containerFetch", spanOptions("containerFetch"))(function* (requestOrUrl, port) {
|
|
236
|
-
return yield* attempt("containerFetch", () => client.containerFetch(requestOrUrl, port));
|
|
237
|
+
return yield* attempt("containerFetch", (client) => client.containerFetch(requestOrUrl, port));
|
|
237
238
|
}),
|
|
238
239
|
wsConnect: Effect.fn("Sandbox.wsConnect", spanOptions("wsConnect"))(function* (request, port) {
|
|
239
240
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
240
|
-
return yield* attempt("wsConnect", () => client.wsConnect(request, port));
|
|
241
|
+
return yield* attempt("wsConnect", (client) => client.wsConnect(request, port));
|
|
241
242
|
}),
|
|
242
243
|
mountBucket: Effect.fn("Sandbox.mountBucket", spanOptions("mountBucket"))(function* (bucket, mountPath, options) {
|
|
243
244
|
yield* Effect.annotateCurrentSpan({
|
|
244
245
|
bucket,
|
|
245
246
|
mountPath
|
|
246
247
|
});
|
|
247
|
-
return yield* attempt("mountBucket", () => client.mountBucket(bucket, mountPath, options));
|
|
248
|
+
return yield* attempt("mountBucket", (client) => client.mountBucket(bucket, mountPath, options));
|
|
248
249
|
}),
|
|
249
250
|
unmountBucket: Effect.fn("Sandbox.unmountBucket", spanOptions("unmountBucket"))(function* (mountPath) {
|
|
250
251
|
yield* Effect.annotateCurrentSpan("mountPath", mountPath);
|
|
251
|
-
return yield* attempt("unmountBucket", () => client.unmountBucket(mountPath));
|
|
252
|
+
return yield* attempt("unmountBucket", (client) => client.unmountBucket(mountPath));
|
|
252
253
|
}),
|
|
253
254
|
createBackup: Effect.fn("Sandbox.createBackup", spanOptions("createBackup"))(function* (options) {
|
|
254
255
|
yield* Effect.annotateCurrentSpan("dir", options.dir);
|
|
255
|
-
return yield* attempt("createBackup", () => client.createBackup(options));
|
|
256
|
+
return yield* attempt("createBackup", (client) => client.createBackup(options));
|
|
256
257
|
}),
|
|
257
258
|
restoreBackup: Effect.fn("Sandbox.restoreBackup", spanOptions("restoreBackup"))(function* (backup) {
|
|
258
259
|
yield* Effect.annotateCurrentSpan({
|
|
259
260
|
backupId: backup.id,
|
|
260
261
|
dir: backup.dir
|
|
261
262
|
});
|
|
262
|
-
return yield* attempt("restoreBackup", () => client.restoreBackup(backup));
|
|
263
|
+
return yield* attempt("restoreBackup", (client) => client.restoreBackup(backup));
|
|
263
264
|
}),
|
|
264
265
|
createTerminal: Effect.fn("Sandbox.createTerminal", spanOptions("createTerminal"))(function* (options) {
|
|
265
|
-
|
|
266
|
-
return makeTerminalHandle(definition, instance, terminal, target);
|
|
266
|
+
return yield* attempt("createTerminal", (client, _signal, target) => client.createTerminal(options).then((terminal) => makeTerminalHandle(definition, instance, terminal, target)));
|
|
267
267
|
}),
|
|
268
268
|
getTerminal: Effect.fn("Sandbox.getTerminal", spanOptions("getTerminal"))(function* (id) {
|
|
269
|
-
|
|
270
|
-
return Option.map(Option.fromNullishOr(terminal), (found) => makeTerminalHandle(definition, instance, found, target));
|
|
269
|
+
return yield* attempt("getTerminal", (client, _signal, target) => client.getTerminal(id).then((terminal) => Option.map(Option.fromNullishOr(terminal), (found) => makeTerminalHandle(definition, instance, found, target))));
|
|
271
270
|
}),
|
|
272
|
-
listTerminals: attempt("listTerminals", () => client.listTerminals()
|
|
271
|
+
listTerminals: attempt("listTerminals", (client, _signal, target) => client.listTerminals().then((terminals) => terminals.map((terminal) => makeTerminalHandle(definition, instance, terminal, target)))).pipe(Effect.withSpan("Sandbox.listTerminals", spanOptions("listTerminals"))),
|
|
273
272
|
tunnels: {
|
|
274
273
|
get: Effect.fn("Sandbox.tunnels.get", spanOptions("tunnels.get"))(function* (port, options) {
|
|
275
274
|
yield* Effect.annotateCurrentSpan("port", port);
|
|
276
|
-
return yield* attempt("tunnels.get", () => client.tunnels.get(port, options));
|
|
275
|
+
return yield* attempt("tunnels.get", (client) => client.tunnels.get(port, options));
|
|
277
276
|
}),
|
|
278
|
-
list: attempt("tunnels.list", () => client.tunnels.list()).pipe(Effect.withSpan("Sandbox.tunnels.list", spanOptions("tunnels.list"))),
|
|
277
|
+
list: attempt("tunnels.list", (client) => client.tunnels.list()).pipe(Effect.withSpan("Sandbox.tunnels.list", spanOptions("tunnels.list"))),
|
|
279
278
|
destroy: Effect.fn("Sandbox.tunnels.destroy", spanOptions("tunnels.destroy"))(function* (portOrInfo) {
|
|
280
|
-
return yield* attempt("tunnels.destroy", () => client.tunnels.destroy(portOrInfo));
|
|
279
|
+
return yield* attempt("tunnels.destroy", (client) => client.tunnels.destroy(portOrInfo));
|
|
281
280
|
})
|
|
282
281
|
},
|
|
283
282
|
start: Effect.fn("Sandbox.start", spanOptions("start"))(function* (options) {
|
|
284
|
-
return yield* attempt("start", () => client.start(options));
|
|
283
|
+
return yield* attempt("start", (client) => client.start(options));
|
|
285
284
|
}),
|
|
286
285
|
stop: Effect.fn("Sandbox.stop", spanOptions("stop"))(function* (signal) {
|
|
287
|
-
return yield* attempt("stop", () => client.stop(signal));
|
|
286
|
+
return yield* attempt("stop", (client) => client.stop(signal));
|
|
288
287
|
}),
|
|
289
|
-
destroy: attempt("destroy", () => client.destroy()).pipe(Effect.withSpan("Sandbox.destroy", spanOptions("destroy")))
|
|
288
|
+
destroy: attempt("destroy", (client) => client.destroy()).pipe(Effect.withSpan("Sandbox.destroy", spanOptions("destroy")))
|
|
290
289
|
};
|
|
291
290
|
};
|
|
292
291
|
/**
|
|
@@ -315,30 +314,35 @@ const makeClient = (definition) => (namespace) => {
|
|
|
315
314
|
} })(function* (name, options) {
|
|
316
315
|
yield* Effect.annotateCurrentSpan("instance", name);
|
|
317
316
|
const sandboxModule = yield* importSandboxModule(definition, name);
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
instance: name,
|
|
328
|
-
operation: "get",
|
|
329
|
-
cause: error.cause
|
|
330
|
-
})));
|
|
331
|
-
const nativeNamespace = scopedNamespace;
|
|
332
|
-
const client = yield* Effect.try({
|
|
333
|
-
try: () => sandboxModule.getSandbox(nativeNamespace, name, options),
|
|
334
|
-
catch: (cause) => new SandboxOperationError({
|
|
317
|
+
const resolve = Effect.gen(function* () {
|
|
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({
|
|
335
326
|
binding: definition.binding,
|
|
336
327
|
instance: name,
|
|
337
328
|
operation: "get",
|
|
338
|
-
cause
|
|
339
|
-
})
|
|
329
|
+
cause: error.cause
|
|
330
|
+
})));
|
|
331
|
+
const nativeNamespace = scopedNamespace;
|
|
332
|
+
return {
|
|
333
|
+
client: yield* Effect.try({
|
|
334
|
+
try: () => sandboxModule.getSandbox(nativeNamespace, name, options),
|
|
335
|
+
catch: (cause) => new SandboxOperationError({
|
|
336
|
+
binding: definition.binding,
|
|
337
|
+
instance: name,
|
|
338
|
+
operation: "get",
|
|
339
|
+
cause
|
|
340
|
+
})
|
|
341
|
+
}),
|
|
342
|
+
target: scopedNamespace
|
|
343
|
+
};
|
|
340
344
|
});
|
|
341
|
-
return makeSandboxClient(
|
|
345
|
+
return makeSandboxClient(resolve, definition, name);
|
|
342
346
|
}),
|
|
343
347
|
rawUnsafe: Effect.succeed(namespace)
|
|
344
348
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -24,6 +24,8 @@ import { BrowserRendering_d_exports } from "./BrowserRendering.mjs";
|
|
|
24
24
|
import { Cache_d_exports } from "./Cache.mjs";
|
|
25
25
|
import { CloudflareOtlp_d_exports } from "./CloudflareOtlp.mjs";
|
|
26
26
|
import { CloudflareTracer_d_exports } from "./CloudflareTracer.mjs";
|
|
27
|
+
import { DurableObjectContainer_d_exports } from "./DurableObjectContainer.mjs";
|
|
28
|
+
import { ContainerFiles_d_exports } from "./ContainerFiles.mjs";
|
|
27
29
|
import { D1_d_exports } from "./D1.mjs";
|
|
28
30
|
import { DurableObjectAlarm_d_exports } from "./DurableObjectAlarm.mjs";
|
|
29
31
|
import { DurableObjectDefinition_d_exports } from "./DurableObjectDefinition.mjs";
|
|
@@ -40,4 +42,4 @@ import { Vectorize_d_exports } from "./Vectorize.mjs";
|
|
|
40
42
|
import { WebTransport_d_exports } from "./WebTransport.mjs";
|
|
41
43
|
import { WorkflowDefinition_d_exports } from "./WorkflowDefinition.mjs";
|
|
42
44
|
import { Workflow_d_exports } from "./Workflow.mjs";
|
|
43
|
-
export { AiGateway_d_exports as AiGateway, AnalyticsEngine_d_exports as AnalyticsEngine, Artifacts_d_exports as Artifacts, Binding_d_exports as Binding, BrowserRendering_d_exports as BrowserRendering, Cache_d_exports as Cache, CloudflareOtlp_d_exports as CloudflareOtlp, CloudflareTracer_d_exports as CloudflareTracer, ContainerNamespace_d_exports as ContainerNamespace, D1_d_exports as D1, DurableObject_d_exports as DurableObject, DurableObjectAlarm_d_exports as DurableObjectAlarm, DurableObjectDefinition_d_exports as DurableObjectDefinition, DurableObjectNamespace_d_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_d_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_d_exports as DurableObjectSqlite, DurableObjectState_d_exports as DurableObjectState, DurableObjectStorage_d_exports as DurableObjectStorage, DurableObjectWebSocket_d_exports as DurableObjectWebSocket, Email_d_exports as Email, Environment_d_exports as Environment, Hyperdrive_d_exports as Hyperdrive, Images_d_exports as Images, Kv_d_exports as Kv, Queue_d_exports as Queue, QueueBinding_d_exports as QueueBinding, QueueDefinition_d_exports as QueueDefinition, R2_d_exports as R2, Rpc_d_exports as Rpc, RpcDefinition_d_exports as RpcDefinition, RpcTargets_d_exports as RpcTargets, RpcTracing_d_exports as RpcTracing, RpcWebSocketClient_d_exports as RpcWebSocketClient, ServiceBinding_d_exports as ServiceBinding, Vectorize_d_exports as Vectorize, WebTransport_d_exports as WebTransport, Worker_d_exports as Worker, WorkerConfig, WorkerDefinition_d_exports as WorkerDefinition, type WorkerEnv, WorkerEnvironment, WorkersAi_d_exports as WorkersAi, Workflow_d_exports as Workflow, WorkflowBinding_d_exports as WorkflowBinding, WorkflowDefinition_d_exports as WorkflowDefinition };
|
|
45
|
+
export { AiGateway_d_exports as AiGateway, AnalyticsEngine_d_exports as AnalyticsEngine, Artifacts_d_exports as Artifacts, Binding_d_exports as Binding, BrowserRendering_d_exports as BrowserRendering, Cache_d_exports as Cache, CloudflareOtlp_d_exports as CloudflareOtlp, CloudflareTracer_d_exports as CloudflareTracer, ContainerFiles_d_exports as ContainerFiles, ContainerNamespace_d_exports as ContainerNamespace, D1_d_exports as D1, DurableObject_d_exports as DurableObject, DurableObjectAlarm_d_exports as DurableObjectAlarm, DurableObjectContainer_d_exports as DurableObjectContainer, DurableObjectDefinition_d_exports as DurableObjectDefinition, DurableObjectNamespace_d_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_d_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_d_exports as DurableObjectSqlite, DurableObjectState_d_exports as DurableObjectState, DurableObjectStorage_d_exports as DurableObjectStorage, DurableObjectWebSocket_d_exports as DurableObjectWebSocket, Email_d_exports as Email, Environment_d_exports as Environment, Hyperdrive_d_exports as Hyperdrive, Images_d_exports as Images, Kv_d_exports as Kv, Queue_d_exports as Queue, QueueBinding_d_exports as QueueBinding, QueueDefinition_d_exports as QueueDefinition, R2_d_exports as R2, Rpc_d_exports as Rpc, RpcDefinition_d_exports as RpcDefinition, RpcTargets_d_exports as RpcTargets, RpcTracing_d_exports as RpcTracing, RpcWebSocketClient_d_exports as RpcWebSocketClient, ServiceBinding_d_exports as ServiceBinding, Vectorize_d_exports as Vectorize, WebTransport_d_exports as WebTransport, Worker_d_exports as Worker, WorkerConfig, WorkerDefinition_d_exports as WorkerDefinition, type WorkerEnv, WorkerEnvironment, WorkersAi_d_exports as WorkersAi, Workflow_d_exports as Workflow, WorkflowBinding_d_exports as WorkflowBinding, WorkflowDefinition_d_exports as WorkflowDefinition };
|
package/dist/index.mjs
CHANGED
|
@@ -11,6 +11,8 @@ import { DurableObjectWebSocket_exports } from "./DurableObjectWebSocket.mjs";
|
|
|
11
11
|
import { DurableObjectState_exports } from "./DurableObjectState.mjs";
|
|
12
12
|
import { CloudflareOtlp_exports } from "./CloudflareOtlp.mjs";
|
|
13
13
|
import { CloudflareTracer_exports } from "./CloudflareTracer.mjs";
|
|
14
|
+
import { DurableObjectContainer_exports } from "./DurableObjectContainer.mjs";
|
|
15
|
+
import { ContainerFiles_exports } from "./ContainerFiles.mjs";
|
|
14
16
|
import { RpcTargets_exports } from "./RpcTargets.mjs";
|
|
15
17
|
import { ContainerNamespace_exports } from "./ContainerNamespace.mjs";
|
|
16
18
|
import { D1_exports } from "./D1.mjs";
|
|
@@ -40,4 +42,4 @@ import { WebTransport_exports } from "./WebTransport.mjs";
|
|
|
40
42
|
import { WorkflowBinding_exports } from "./WorkflowBinding.mjs";
|
|
41
43
|
import { WorkflowDefinition_exports } from "./WorkflowDefinition.mjs";
|
|
42
44
|
import { Workflow_exports } from "./Workflow.mjs";
|
|
43
|
-
export { AiGateway_exports as AiGateway, AnalyticsEngine_exports as AnalyticsEngine, Artifacts_exports as Artifacts, Binding_exports as Binding, BrowserRendering_exports as BrowserRendering, Cache_exports as Cache, CloudflareOtlp_exports as CloudflareOtlp, CloudflareTracer_exports as CloudflareTracer, ContainerNamespace_exports as ContainerNamespace, D1_exports as D1, DurableObject_exports as DurableObject, DurableObjectAlarm_exports as DurableObjectAlarm, DurableObjectDefinition_exports as DurableObjectDefinition, DurableObjectNamespace_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_exports as DurableObjectSqlite, DurableObjectState_exports as DurableObjectState, DurableObjectStorage_exports as DurableObjectStorage, DurableObjectWebSocket_exports as DurableObjectWebSocket, Email_exports as Email, Environment_exports as Environment, Hyperdrive_exports as Hyperdrive, Images_exports as Images, Kv_exports as Kv, Queue_exports as Queue, QueueBinding_exports as QueueBinding, QueueDefinition_exports as QueueDefinition, R2_exports as R2, Rpc_exports as Rpc, RpcDefinition_exports as RpcDefinition, RpcTargets_exports as RpcTargets, RpcTracing_exports as RpcTracing, RpcWebSocketClient_exports as RpcWebSocketClient, ServiceBinding_exports as ServiceBinding, Vectorize_exports as Vectorize, WebTransport_exports as WebTransport, Worker_exports as Worker, WorkerConfig, WorkerDefinition_exports as WorkerDefinition, WorkerEnvironment, WorkersAi_exports as WorkersAi, Workflow_exports as Workflow, WorkflowBinding_exports as WorkflowBinding, WorkflowDefinition_exports as WorkflowDefinition };
|
|
45
|
+
export { AiGateway_exports as AiGateway, AnalyticsEngine_exports as AnalyticsEngine, Artifacts_exports as Artifacts, Binding_exports as Binding, BrowserRendering_exports as BrowserRendering, Cache_exports as Cache, CloudflareOtlp_exports as CloudflareOtlp, CloudflareTracer_exports as CloudflareTracer, ContainerFiles_exports as ContainerFiles, ContainerNamespace_exports as ContainerNamespace, D1_exports as D1, DurableObject_exports as DurableObject, DurableObjectAlarm_exports as DurableObjectAlarm, DurableObjectContainer_exports as DurableObjectContainer, DurableObjectDefinition_exports as DurableObjectDefinition, DurableObjectNamespace_exports as DurableObjectNamespace, DurableObjectRpcWebSocket_exports as DurableObjectRpcWebSocket, DurableObjectSqlite_exports as DurableObjectSqlite, DurableObjectState_exports as DurableObjectState, DurableObjectStorage_exports as DurableObjectStorage, DurableObjectWebSocket_exports as DurableObjectWebSocket, Email_exports as Email, Environment_exports as Environment, Hyperdrive_exports as Hyperdrive, Images_exports as Images, Kv_exports as Kv, Queue_exports as Queue, QueueBinding_exports as QueueBinding, QueueDefinition_exports as QueueDefinition, R2_exports as R2, Rpc_exports as Rpc, RpcDefinition_exports as RpcDefinition, RpcTargets_exports as RpcTargets, RpcTracing_exports as RpcTracing, RpcWebSocketClient_exports as RpcWebSocketClient, ServiceBinding_exports as ServiceBinding, Vectorize_exports as Vectorize, WebTransport_exports as WebTransport, Worker_exports as Worker, WorkerConfig, WorkerDefinition_exports as WorkerDefinition, WorkerEnvironment, WorkersAi_exports as WorkersAi, Workflow_exports as Workflow, WorkflowBinding_exports as WorkflowBinding, WorkflowDefinition_exports as WorkflowDefinition };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-cf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"description": "Effect-native primitives for Cloudflare Workers and bindings.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"@cloudflare/computer": "0.2.0",
|
|
79
79
|
"@cloudflare/containers": "catalog:",
|
|
80
80
|
"@cloudflare/sandbox": "0.13.0-next.738.2",
|
|
81
|
+
"@cloudflare/sandbox-v1": "npm:@cloudflare/sandbox@1.0.0",
|
|
81
82
|
"@cloudflare/vitest-plugin": "catalog:",
|
|
82
83
|
"@cloudflare/workers-types": "catalog:",
|
|
83
84
|
"@effect/platform-node": "catalog:",
|
|
@@ -96,9 +97,9 @@
|
|
|
96
97
|
},
|
|
97
98
|
"peerDependencies": {
|
|
98
99
|
"@cloudflare/computer": "^0.2.0",
|
|
99
|
-
"@cloudflare/sandbox": "^0.13.0-next.738.2",
|
|
100
|
+
"@cloudflare/sandbox": "^0.13.0-next.738.2 || ^1.0.0",
|
|
100
101
|
"@cloudflare/vitest-plugin": "^1.0.0",
|
|
101
|
-
"@cloudflare/workers-types": "^5.
|
|
102
|
+
"@cloudflare/workers-types": "^5.20260926.1",
|
|
102
103
|
"@effect/sql-d1": "^4.0.0-rc.115",
|
|
103
104
|
"@effect/sql-pg": "^4.0.0-rc.115",
|
|
104
105
|
"@effect/sql-sqlite-do": "^4.0.0-rc.115",
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Stream from "effect/Stream";
|
|
3
|
+
|
|
4
|
+
import { ContainerError } from "./DurableObjectContainer";
|
|
5
|
+
|
|
6
|
+
export type FileContent =
|
|
7
|
+
| string
|
|
8
|
+
| ArrayBuffer
|
|
9
|
+
| ArrayBufferView
|
|
10
|
+
| Blob
|
|
11
|
+
| ReadableStream<Uint8Array>;
|
|
12
|
+
export type FileType =
|
|
13
|
+
| "file"
|
|
14
|
+
| "directory"
|
|
15
|
+
| "symlink"
|
|
16
|
+
| "blockDevice"
|
|
17
|
+
| "characterDevice"
|
|
18
|
+
| "fifo"
|
|
19
|
+
| "socket";
|
|
20
|
+
|
|
21
|
+
export interface FileOperationOptions {
|
|
22
|
+
readonly cwd?: string;
|
|
23
|
+
readonly user?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface MkdirOptions extends FileOperationOptions {
|
|
27
|
+
readonly recursive?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RemoveOptions extends FileOperationOptions {
|
|
31
|
+
readonly recursive?: boolean;
|
|
32
|
+
readonly force?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface FileStat {
|
|
36
|
+
readonly type: FileType;
|
|
37
|
+
readonly size: bigint;
|
|
38
|
+
readonly mode: number;
|
|
39
|
+
readonly uid: number;
|
|
40
|
+
readonly gid: number;
|
|
41
|
+
readonly accessedAt: Date;
|
|
42
|
+
readonly modifiedAt: Date;
|
|
43
|
+
readonly changedAt: Date;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface DirectoryEntry {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly type: FileType;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type WithSignal<A> = A & { readonly signal?: AbortSignal };
|
|
52
|
+
|
|
53
|
+
/** Structural contract of Sandbox SDK 1.x `Files`, without loading an SDK version. */
|
|
54
|
+
export interface FilesResource {
|
|
55
|
+
readFile(path: string, options?: WithSignal<FileOperationOptions>): Promise<Response>;
|
|
56
|
+
writeFile(
|
|
57
|
+
path: string,
|
|
58
|
+
content: FileContent,
|
|
59
|
+
options?: WithSignal<FileOperationOptions>,
|
|
60
|
+
): Promise<void>;
|
|
61
|
+
stat(path: string, options?: WithSignal<FileOperationOptions>): Promise<FileStat>;
|
|
62
|
+
lstat(path: string, options?: WithSignal<FileOperationOptions>): Promise<FileStat>;
|
|
63
|
+
readDirectory(
|
|
64
|
+
path: string,
|
|
65
|
+
options?: WithSignal<FileOperationOptions>,
|
|
66
|
+
): Promise<ReadonlyArray<DirectoryEntry>>;
|
|
67
|
+
mkdir(path: string, options?: WithSignal<MkdirOptions>): Promise<void>;
|
|
68
|
+
rename(
|
|
69
|
+
source: string,
|
|
70
|
+
destination: string,
|
|
71
|
+
options?: WithSignal<FileOperationOptions>,
|
|
72
|
+
): Promise<void>;
|
|
73
|
+
remove(path: string, options?: WithSignal<RemoveOptions>): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface ContainerFiles {
|
|
77
|
+
readonly raw: FilesResource;
|
|
78
|
+
/** The caller consumes or cancels the response body. Late failures retain native SDK errors. */
|
|
79
|
+
readonly readFile: (
|
|
80
|
+
path: string,
|
|
81
|
+
options?: FileOperationOptions,
|
|
82
|
+
) => Effect.Effect<Response, ContainerError>;
|
|
83
|
+
/** Includes failures that arrive while reading the response body. */
|
|
84
|
+
readonly readFileStream: (
|
|
85
|
+
path: string,
|
|
86
|
+
options?: FileOperationOptions,
|
|
87
|
+
) => Stream.Stream<Uint8Array, ContainerError>;
|
|
88
|
+
readonly readFileString: (
|
|
89
|
+
path: string,
|
|
90
|
+
options?: FileOperationOptions,
|
|
91
|
+
) => Effect.Effect<string, ContainerError>;
|
|
92
|
+
readonly writeFile: (
|
|
93
|
+
path: string,
|
|
94
|
+
content: FileContent,
|
|
95
|
+
options?: FileOperationOptions,
|
|
96
|
+
) => Effect.Effect<void, ContainerError>;
|
|
97
|
+
readonly stat: (
|
|
98
|
+
path: string,
|
|
99
|
+
options?: FileOperationOptions,
|
|
100
|
+
) => Effect.Effect<FileStat, ContainerError>;
|
|
101
|
+
readonly lstat: (
|
|
102
|
+
path: string,
|
|
103
|
+
options?: FileOperationOptions,
|
|
104
|
+
) => Effect.Effect<FileStat, ContainerError>;
|
|
105
|
+
readonly readDirectory: (
|
|
106
|
+
path: string,
|
|
107
|
+
options?: FileOperationOptions,
|
|
108
|
+
) => Effect.Effect<ReadonlyArray<DirectoryEntry>, ContainerError>;
|
|
109
|
+
readonly mkdir: (path: string, options?: MkdirOptions) => Effect.Effect<void, ContainerError>;
|
|
110
|
+
readonly rename: (
|
|
111
|
+
source: string,
|
|
112
|
+
destination: string,
|
|
113
|
+
options?: FileOperationOptions,
|
|
114
|
+
) => Effect.Effect<void, ContainerError>;
|
|
115
|
+
readonly remove: (path: string, options?: RemoveOptions) => Effect.Effect<void, ContainerError>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const attempt = <A>(operation: string, evaluate: (signal: AbortSignal) => Promise<A>) =>
|
|
119
|
+
Effect.tryPromise({
|
|
120
|
+
try: evaluate,
|
|
121
|
+
catch: (cause) => new ContainerError({ operation: `files.${operation}`, cause }),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/** Pass `new Files(container.raw)` from SDK 1.x. The image must supply its matching sandbox-shim. */
|
|
125
|
+
export const fromFiles = (files: FilesResource): ContainerFiles => {
|
|
126
|
+
const readFile = (path: string, options?: FileOperationOptions) =>
|
|
127
|
+
attempt("readFile", (signal) => files.readFile(path, { ...options, signal }));
|
|
128
|
+
const readFileStream = (path: string, options?: FileOperationOptions) =>
|
|
129
|
+
Stream.unwrap(
|
|
130
|
+
Effect.map(readFile(path, options), (response) => {
|
|
131
|
+
const body = response.body;
|
|
132
|
+
|
|
133
|
+
return body === null
|
|
134
|
+
? Stream.empty
|
|
135
|
+
: Stream.fromReadableStream({
|
|
136
|
+
evaluate: () => body,
|
|
137
|
+
onError: (cause) => new ContainerError({ operation: "files.readFile", cause }),
|
|
138
|
+
});
|
|
139
|
+
}),
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
raw: files,
|
|
144
|
+
readFile,
|
|
145
|
+
readFileStream,
|
|
146
|
+
readFileString: (path, options) =>
|
|
147
|
+
readFileStream(path, options).pipe(Stream.decodeText(), Stream.mkString),
|
|
148
|
+
writeFile: (path, content, options) =>
|
|
149
|
+
attempt("writeFile", (signal) => files.writeFile(path, content, { ...options, signal })),
|
|
150
|
+
stat: (path, options) => attempt("stat", (signal) => files.stat(path, { ...options, signal })),
|
|
151
|
+
lstat: (path, options) =>
|
|
152
|
+
attempt("lstat", (signal) => files.lstat(path, { ...options, signal })),
|
|
153
|
+
readDirectory: (path, options) =>
|
|
154
|
+
attempt("readDirectory", (signal) => files.readDirectory(path, { ...options, signal })),
|
|
155
|
+
mkdir: (path, options) =>
|
|
156
|
+
attempt("mkdir", (signal) => files.mkdir(path, { ...options, signal })),
|
|
157
|
+
rename: (source, destination, options) =>
|
|
158
|
+
attempt("rename", (signal) => files.rename(source, destination, { ...options, signal })),
|
|
159
|
+
remove: (path, options) =>
|
|
160
|
+
attempt("remove", (signal) => files.remove(path, { ...options, signal })),
|
|
161
|
+
};
|
|
162
|
+
};
|
|
@@ -60,10 +60,12 @@ export const ContainerState = S.Union([
|
|
|
60
60
|
export type ContainerState = typeof ContainerState.Type;
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* RPC stub exposed by the legacy `@cloudflare/containers` Container class.
|
|
64
64
|
*
|
|
65
65
|
* This is structural so using Container bindings does not make
|
|
66
66
|
* `@cloudflare/containers` a runtime dependency of effect-cf.
|
|
67
|
+
* Use `DurableObjectContainer` inside a Durable Object for the native
|
|
68
|
+
* `ctx.container` API and the `durable_object` scheduling policy.
|
|
67
69
|
*/
|
|
68
70
|
export interface ContainerStub {
|
|
69
71
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|