@fungi.computer/oyster 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/dist/app-test-copies.d.ts +87 -0
- package/dist/app-test-copies.js +170 -0
- package/dist/app-test-copy-page.d.ts +4 -0
- package/dist/app-test-copy-page.js +89 -0
- package/dist/browser/operations.d.ts +1 -1
- package/dist/cloudflare.d.ts +68 -3
- package/dist/cloudflare.js +214 -3
- package/dist/embed-metafiles.js +2 -2
- package/dist/host.d.ts +16 -0
- package/dist/host.js +309 -1
- package/dist/installation-operations.d.ts +247 -8
- package/dist/installation-operations.js +145 -7
- package/dist/installation-recovery-page.d.ts +24 -0
- package/dist/installation-recovery-page.js +168 -0
- package/dist/older-oyster-store.d.ts +1 -1
- package/dist/older-oyster-store.js +2 -4
- package/dist/page/mount.d.ts +2 -101
- package/dist/page/mount.js +1 -22
- package/dist/page-config.d.ts +102 -0
- package/dist/page-config.js +24 -0
- package/dist/page-script.js +1 -1
- package/dist/recovery-style.d.ts +5 -0
- package/dist/recovery-style.js +32 -0
- package/dist/standalone/agents.d.ts +1 -1
- package/dist/upgrade/old-worker-http.d.ts +2 -0
- package/dist/upgrade/old-worker-http.js +22 -0
- package/dist/upgrade/old-worker-readonly.d.ts +14 -0
- package/dist/upgrade/old-worker-readonly.js +22 -0
- package/dist/upgrade/old-worker-sql.d.ts +10 -0
- package/dist/upgrade/old-worker-sql.js +68 -0
- package/dist/upgrade/old-worker-stream.d.ts +12 -0
- package/dist/upgrade/old-worker-stream.js +54 -0
- package/dist/upgrade/private-stage.d.ts +23 -0
- package/dist/upgrade/private-stage.js +109 -0
- package/dist/upgrade/standalone-001.d.ts +16 -0
- package/dist/upgrade/standalone-001.js +31 -0
- package/dist/upgrade/standalone-01.d.ts +37 -0
- package/dist/upgrade/standalone-01.js +55 -0
- package/dist/upgrade/standalone-02.d.ts +37 -0
- package/dist/upgrade/standalone-02.js +55 -0
- package/dist/workers.d.ts +15 -1
- package/dist/workers.js +117 -7
- package/docs/api/README.md +8 -3
- package/docs/api/cloudflare.md +57 -0
- package/docs/api/host.md +223 -14
- package/docs/api/page/mount.md +10 -78
- package/docs/api/workers-git.md +246 -1
- package/docs/api/workers.md +352 -14
- package/package.json +23 -10
package/dist/cloudflare.js
CHANGED
|
@@ -1,4 +1,56 @@
|
|
|
1
|
-
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
import { appBackendComputerHeader, appMethodReplySchema, } from "@fungi.computer/agar/backend";
|
|
2
54
|
import { nativeGitFrameMethods } from "@fungi.computer/agar/git-rpc";
|
|
3
55
|
import { rpcHandleSchema, rpcMethod } from "@fungi.computer/agar/rpc";
|
|
4
56
|
import { facetInvocationModule, facetFrameBindingModule, } from "./facet-invocation.js";
|
|
@@ -10,13 +62,17 @@ import { WorkerEntrypoint } from "cloudflare:workers";
|
|
|
10
62
|
import { guestLimits } from "./guest-policy.js";
|
|
11
63
|
import { headContentObject } from "./build/content-objects.js";
|
|
12
64
|
import { appBackendBindingKinds, } from "@fungi.computer/puffball/app";
|
|
13
|
-
import { isAppApiMethodName } from "@fungi.computer/puffball/app-method-runtime";
|
|
65
|
+
import { isAppApiMethodName, parseAppMethodCallContext, } from "@fungi.computer/puffball/app-method-runtime";
|
|
66
|
+
import { appMethodSchemas } from "@fungi.computer/forage";
|
|
14
67
|
import { createInvocationGate, invocationFrameIdSchema, } from "./invocation.js";
|
|
15
68
|
import * as Effect from "effect/Effect";
|
|
69
|
+
import * as Exit from "effect/Exit";
|
|
16
70
|
import * as Schema from "effect/Schema";
|
|
17
71
|
import { z } from "zod";
|
|
18
72
|
import { BACKEND_CONSTRUCTION_FACET, checkBackendConstruction, } from "./boot-construction.js";
|
|
19
|
-
import { BootGateError } from "./boot-gate.js";
|
|
73
|
+
import { BOOT_DEADLINE_MS, BootGateError, } from "./boot-gate.js";
|
|
74
|
+
import { appFacetRequest, appFacetResponse } from "./backend-request.js";
|
|
75
|
+
import { createAppTestCopies, } from "./app-test-copies.js";
|
|
20
76
|
export { checkBackendConstruction } from "./boot-construction.js";
|
|
21
77
|
import { createAppInstance, AppInstanceError, instanceIdSchema, instanceSchema, appInstanceErrorCodeSchema, } from "./index.js";
|
|
22
78
|
const bindingWire = createFrameBindingWire(appInstanceErrorCodeSchema.literals);
|
|
@@ -270,6 +326,161 @@ const facetInvocationSchema = rpcHandleSchema({
|
|
|
270
326
|
invoke: rpcMethod(z.union([z.json(), z.undefined()])).input(z.tuple([z.string(), z.array(z.unknown()), z.unknown()])),
|
|
271
327
|
http: rpcMethod(facetHttpReplySchema).input(z.tuple([facetHttpInputSchema, z.unknown()])),
|
|
272
328
|
});
|
|
329
|
+
/**
|
|
330
|
+
* Disposable App-data siblings use the same native facade and wire decoder as
|
|
331
|
+
* live invocation, but no invocation frame, binding factory or live host env.
|
|
332
|
+
* The surrounding Instance owns current authority and shared alarm scheduling.
|
|
333
|
+
*/
|
|
334
|
+
export function createCloudflareAppTestCopies(ctx, loader, ports, limits) {
|
|
335
|
+
const name = "test-copy";
|
|
336
|
+
const instanceId = ctx.id.name;
|
|
337
|
+
if (!instanceId)
|
|
338
|
+
throw new Error("Named Instance required");
|
|
339
|
+
const copies = createAppTestCopies({
|
|
340
|
+
owner: ctx.storage,
|
|
341
|
+
now: Date.now,
|
|
342
|
+
source: () => ports
|
|
343
|
+
.source()
|
|
344
|
+
.pipe(Effect.flatMap((source) => source !== null && source.instance.instanceId !== instanceId
|
|
345
|
+
? Effect.fail(new AppInstanceError("instance_identity_mismatch"))
|
|
346
|
+
: Effect.succeed(source))),
|
|
347
|
+
wake: ports.wake,
|
|
348
|
+
clone: () => Effect.try({
|
|
349
|
+
try: () => {
|
|
350
|
+
if (loader === undefined)
|
|
351
|
+
throw new AppInstanceError("boot_runner_unavailable");
|
|
352
|
+
if (ctx.facets.clone === undefined)
|
|
353
|
+
throw new AppInstanceError("boot_clone_unavailable");
|
|
354
|
+
ctx.facets.clone("app", name);
|
|
355
|
+
},
|
|
356
|
+
catch: (cause) => cause instanceof AppInstanceError
|
|
357
|
+
? cause
|
|
358
|
+
: new AppInstanceError("boot_clone_unavailable", { cause }),
|
|
359
|
+
}),
|
|
360
|
+
purge: () => Effect.try({
|
|
361
|
+
try: () => {
|
|
362
|
+
try {
|
|
363
|
+
ctx.facets.abort(name, new AppInstanceError("revoked"));
|
|
364
|
+
}
|
|
365
|
+
finally {
|
|
366
|
+
ctx.facets.delete(name);
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
catch: (cause) => new AppInstanceError("boot_cleanup_failed", { cause }),
|
|
370
|
+
}),
|
|
371
|
+
});
|
|
372
|
+
const bounded = (program) => program.pipe(Effect.timeoutOrElse({
|
|
373
|
+
duration: BOOT_DEADLINE_MS,
|
|
374
|
+
orElse: () => Effect.fail(new AppInstanceError("expired")),
|
|
375
|
+
}));
|
|
376
|
+
const closeOnFailure = (authority, copyId, program) => bounded(program).pipe(Effect.onExit((exit) => Exit.isFailure(exit)
|
|
377
|
+
? copies.discard(authority, copyId).pipe(Effect.asVoid)
|
|
378
|
+
: Effect.void));
|
|
379
|
+
const execute = (authority, copyId, invoke) => closeOnFailure(authority, copyId, copies.withCopy(authority, copyId, (copy) => Effect.gen(function* () {
|
|
380
|
+
const artifact = yield* ports.resolve(copy.selection.releaseId);
|
|
381
|
+
const budget = guestLimits(ports.limits?.() ?? limits);
|
|
382
|
+
if (artifact.release.appId !== copy.selection.appId ||
|
|
383
|
+
artifact.release.releaseId !== copy.selection.releaseId)
|
|
384
|
+
return yield* Effect.fail(new AppInstanceError("instance_release_mismatch"));
|
|
385
|
+
return yield* Effect.tryPromise({
|
|
386
|
+
try: async () => {
|
|
387
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
388
|
+
try {
|
|
389
|
+
if (loader === undefined)
|
|
390
|
+
throw new AppInstanceError("boot_runner_unavailable");
|
|
391
|
+
// Native get also memoizes the child class. End prior execution
|
|
392
|
+
// before selecting the current budget; abort preserves copied SQLite.
|
|
393
|
+
ctx.facets.abort(name, new AppInstanceError("revoked"));
|
|
394
|
+
const stub = __addDisposableResource(env_1, facetInvocationSchema.parse(ctx.facets.get(name, () => ({
|
|
395
|
+
class: loader
|
|
396
|
+
.get(`copy:${instanceId}:${copy.copyId}:${artifact.digest}:${String(budget.cpuMs)}:${String(budget.subRequests)}`, () => ({
|
|
397
|
+
compatibilityDate: artifact.backend.compatibilityDate,
|
|
398
|
+
mainModule: "invocation.js",
|
|
399
|
+
modules: {
|
|
400
|
+
"backend.js": artifact.backend.code,
|
|
401
|
+
"invocation.js": facetInvocationModule(artifact.backend.exportName),
|
|
402
|
+
"frame-binding-wire.js": facetFrameBindingModule,
|
|
403
|
+
},
|
|
404
|
+
env: {},
|
|
405
|
+
globalOutbound: null,
|
|
406
|
+
limits: budget,
|
|
407
|
+
}))
|
|
408
|
+
.getDurableObjectClass("AppInvocation"),
|
|
409
|
+
}))), false);
|
|
410
|
+
return await invoke(stub, artifact);
|
|
411
|
+
}
|
|
412
|
+
catch (e_1) {
|
|
413
|
+
env_1.error = e_1;
|
|
414
|
+
env_1.hasError = true;
|
|
415
|
+
}
|
|
416
|
+
finally {
|
|
417
|
+
__disposeResources(env_1);
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
catch: (cause) => cause instanceof AppInstanceError
|
|
421
|
+
? cause
|
|
422
|
+
: cause instanceof Error
|
|
423
|
+
? guestFailure(cause)
|
|
424
|
+
: new Error("Test copy execution failed"),
|
|
425
|
+
});
|
|
426
|
+
})));
|
|
427
|
+
return {
|
|
428
|
+
/** Clone current App data once under the retained request and fixed deadline. */
|
|
429
|
+
open: (authority, requestId) => bounded(copies.open(authority, requestId)),
|
|
430
|
+
/** Observe the sibling, retiring expired or unavailable source selections. */
|
|
431
|
+
inspect: (authority) => bounded(copies.inspect(authority)),
|
|
432
|
+
/** Discard only this resource, retaining its latest request receipt. */
|
|
433
|
+
discard: copies.discard,
|
|
434
|
+
/** Shared native alarm cleanup; incomplete phases need no source service. */
|
|
435
|
+
expire: copies.expire,
|
|
436
|
+
/** Retire the sibling when its owning installation loses authority. */
|
|
437
|
+
revoke: copies.revoke,
|
|
438
|
+
/** Run ordinary backend HTTP with bounded bodies and no live bindings. */
|
|
439
|
+
fetch: (authority, copyId, request) => execute(authority, copyId, async (stub) => {
|
|
440
|
+
const safe = appFacetRequest(request);
|
|
441
|
+
safe.headers.delete(appBackendComputerHeader);
|
|
442
|
+
const reply = facetHttpReplySchema.parse(await stub.http({
|
|
443
|
+
url: safe.url,
|
|
444
|
+
method: safe.method,
|
|
445
|
+
headers: [...safe.headers],
|
|
446
|
+
body: await readHttpBody(safe.body, requestBodyCeiling),
|
|
447
|
+
}, {}));
|
|
448
|
+
const body = await readHttpBody(reply.body, replyBodyCeiling);
|
|
449
|
+
return appFacetResponse(new Response(body, {
|
|
450
|
+
status: reply.status,
|
|
451
|
+
statusText: reply.statusText,
|
|
452
|
+
headers: reply.headers,
|
|
453
|
+
}));
|
|
454
|
+
}),
|
|
455
|
+
/** Use the ordinary typed facade and verified method codecs, without live grants. */
|
|
456
|
+
call: (authority, copyId, method, input, caller) => execute(authority, copyId, async (stub, artifact) => {
|
|
457
|
+
const decoded = parseAppMethodCallContext(caller, true);
|
|
458
|
+
if (decoded.actor.kind !== "member" ||
|
|
459
|
+
decoded.role !== "owner" ||
|
|
460
|
+
artifact.api === null ||
|
|
461
|
+
!isAppApiMethodName(method) ||
|
|
462
|
+
!Object.hasOwn(artifact.api.methods, method))
|
|
463
|
+
throw new AppInstanceError("invalid_invocation_facts");
|
|
464
|
+
const codec = appMethodSchemas(artifact.api)[method];
|
|
465
|
+
if (codec === undefined)
|
|
466
|
+
throw new AppInstanceError("invalid_invocation_facts");
|
|
467
|
+
// Attribution is not a live call frame: no Computer, workflow or durable lane.
|
|
468
|
+
const context = parseAppMethodCallContext({
|
|
469
|
+
actor: decoded.actor,
|
|
470
|
+
role: "owner",
|
|
471
|
+
computerId: null,
|
|
472
|
+
}, true);
|
|
473
|
+
const reply = Schema.decodeUnknownSync(Schema.Json)(await stub.invoke(method, [codec.input.parse(input), context], {}));
|
|
474
|
+
if (new TextEncoder().encode(JSON.stringify(reply)).byteLength >
|
|
475
|
+
MAX_APP_REPLY_BYTES)
|
|
476
|
+
throw new Error("App result too large");
|
|
477
|
+
const parsed = appMethodReplySchema.parse(reply);
|
|
478
|
+
if (parsed.kind === "ok")
|
|
479
|
+
codec.output.parse(parsed.value);
|
|
480
|
+
return parsed;
|
|
481
|
+
}),
|
|
482
|
+
};
|
|
483
|
+
}
|
|
273
484
|
/** Stop the shared native App facet at cohort drain or revocation. */
|
|
274
485
|
export function createCloudflareInvocationGate(ctx, close) {
|
|
275
486
|
return createInvocationGate({
|