@moinulmoin/eden-runtime-cloudflare 0.2.2 → 0.4.1
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/NOTICE +8 -0
- package/dist/eden-eve-host-worker.mjs +24264 -246
- package/dist/eve-host-runtime.d.ts +16 -2
- package/dist/eve-host-runtime.js +117 -7
- package/dist/eve-host.d.ts +66 -8
- package/dist/eve-host.js +189 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +2 -1
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Container, ContainerProxy } from "@cloudflare/containers";
|
|
2
|
-
import { type EveHostContainerEnvironment, type EveHostForwardingMetadata, type EveHostReadinessEvidence } from "./eve-host.js";
|
|
2
|
+
import { type EveHostContainerEnvironment, type EveHostForwardingMetadata, type EveHostReadinessEvidence, type EveScheduleCronEntry } from "./eve-host.js";
|
|
3
3
|
export { ContainerProxy };
|
|
4
|
+
/** The deployment's single SQLite-backed Workflow World. */
|
|
5
|
+
export declare class EdenWorldDurableObject {
|
|
6
|
+
private readonly core;
|
|
7
|
+
constructor(ctx: DurableObjectState, env: EveHostContainerEnvironment);
|
|
8
|
+
fetch(request: Request): Promise<Response>;
|
|
9
|
+
alarm(): Promise<void>;
|
|
10
|
+
}
|
|
4
11
|
/**
|
|
5
12
|
* Delivers the container's own HTTPS requests to its public workers.dev origin
|
|
6
13
|
* back into the container over the internal port instead of the public edge.
|
|
@@ -20,8 +27,8 @@ export declare function routeEveOutboundRequest(request: Request, env: EveHostCo
|
|
|
20
27
|
type EveHostContainerContext = ConstructorParameters<typeof Container>[0];
|
|
21
28
|
export declare class EveHostContainer extends Container<EveHostContainerEnvironment> {
|
|
22
29
|
defaultPort: 8080;
|
|
30
|
+
sleepAfter: string | number;
|
|
23
31
|
requiredPorts: 8080[];
|
|
24
|
-
sleepAfter: "24h";
|
|
25
32
|
interceptHttps: boolean;
|
|
26
33
|
enableInternet: boolean;
|
|
27
34
|
pingEndpoint: string;
|
|
@@ -44,6 +51,7 @@ export interface EveHostWorkerOptions extends EveHostForwardingMetadata {
|
|
|
44
51
|
readonly workerName: string;
|
|
45
52
|
readonly containerBindingName: string;
|
|
46
53
|
readonly stableContainerInstanceName: string;
|
|
54
|
+
readonly schedules?: readonly EveScheduleCronEntry[];
|
|
47
55
|
}
|
|
48
56
|
/**
|
|
49
57
|
* Structural worker-handler shape. Declared locally so the emitted module
|
|
@@ -51,6 +59,12 @@ export interface EveHostWorkerOptions extends EveHostForwardingMetadata {
|
|
|
51
59
|
*/
|
|
52
60
|
export interface EveHostWorkerHandler {
|
|
53
61
|
fetch(request: Request, env: EveHostWorkerEnvironment): Promise<Response>;
|
|
62
|
+
scheduled?(event: {
|
|
63
|
+
readonly cron: string;
|
|
64
|
+
readonly scheduledTime: number;
|
|
65
|
+
}, env: EveHostWorkerEnvironment, ctx: {
|
|
66
|
+
waitUntil(task: Promise<unknown>): void;
|
|
67
|
+
}): void;
|
|
54
68
|
}
|
|
55
69
|
export declare function createEveHostWorker(options: EveHostWorkerOptions): EveHostWorkerHandler;
|
|
56
70
|
//# sourceMappingURL=eve-host-runtime.d.ts.map
|
package/dist/eve-host-runtime.js
CHANGED
|
@@ -1,7 +1,78 @@
|
|
|
1
1
|
import { Container, ContainerProxy } from "@cloudflare/containers";
|
|
2
|
-
import {
|
|
2
|
+
import { WorldCore } from "@moinulmoin/eden-world-cloudflare/core";
|
|
3
|
+
import { EVE_HOST_DEFAULTS, EVE_SCHEDULE_WAKE_LEAD_MS, EveHostError, assertNonEmpty, assertStableOrigin, createEveHostLifecycleObserver, createEveReadinessGate, createTrustedEveRequest, eveScheduleCronFiresWithin, IDENTIFIER_PATTERN, readProtectedRuntimeVariables, WORKER_NAME_PATTERN, isEveWorkflowInternalRoute, } from "./eve-host.js";
|
|
3
4
|
export { ContainerProxy };
|
|
4
5
|
const EVE_CLOUDFLARE_CONTAINERS_CA_PATH = "/etc/cloudflare/certs/cloudflare-containers-ca.crt";
|
|
6
|
+
/** The deployment's single SQLite-backed Workflow World. */
|
|
7
|
+
export class EdenWorldDurableObject {
|
|
8
|
+
core;
|
|
9
|
+
constructor(ctx, env) {
|
|
10
|
+
this.core = new WorldCore({
|
|
11
|
+
sql: {
|
|
12
|
+
exec: ctx.storage.sql.exec.bind(ctx.storage.sql),
|
|
13
|
+
transactionSync: ctx.storage.transactionSync.bind(ctx.storage),
|
|
14
|
+
},
|
|
15
|
+
scheduleAlarm: async (atMs) => {
|
|
16
|
+
if (atMs === null)
|
|
17
|
+
await ctx.storage.deleteAlarm();
|
|
18
|
+
else
|
|
19
|
+
await ctx.storage.setAlarm(atMs);
|
|
20
|
+
},
|
|
21
|
+
delivery: {
|
|
22
|
+
deliver: async (message) => {
|
|
23
|
+
const origin = env.EVE_PUBLIC_ORIGIN;
|
|
24
|
+
const binding = env.EVE_CONTAINER_BINDING_NAME;
|
|
25
|
+
const instance = env.EVE_CONTAINER_INSTANCE_NAME;
|
|
26
|
+
if (typeof origin !== "string" || typeof binding !== "string" ||
|
|
27
|
+
typeof instance !== "string") {
|
|
28
|
+
throw new Error("The World queue Container identity is unavailable.");
|
|
29
|
+
}
|
|
30
|
+
const namespace = env[binding];
|
|
31
|
+
const response = await namespace.getByName(instance).containerFetch(new Request(new URL(`/.well-known/workflow/v1/${message.path}`, origin), {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: {
|
|
34
|
+
...message.headers,
|
|
35
|
+
"content-type": "application/json",
|
|
36
|
+
"x-vqs-queue-name": message.queueName,
|
|
37
|
+
"x-vqs-message-id": message.messageId,
|
|
38
|
+
"x-vqs-message-attempt": String(message.attempt),
|
|
39
|
+
},
|
|
40
|
+
body: message.body,
|
|
41
|
+
}), EVE_HOST_DEFAULTS.internalPort);
|
|
42
|
+
// Body transport errors must remain retryable; an HTTP status alone
|
|
43
|
+
// is not an acknowledgement of a streamed Container response.
|
|
44
|
+
const body = await response.text();
|
|
45
|
+
let result = null;
|
|
46
|
+
try {
|
|
47
|
+
result = JSON.parse(body);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// World-local also accepts successful non-JSON responses.
|
|
51
|
+
}
|
|
52
|
+
const timeout = result?.timeoutSeconds;
|
|
53
|
+
return {
|
|
54
|
+
ok: response.ok && timeout === undefined,
|
|
55
|
+
...(typeof timeout === "number" && timeout >= 0
|
|
56
|
+
? { retryAfterMs: timeout * 1_000 }
|
|
57
|
+
: {}),
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
void ctx.blockConcurrencyWhile(async () => this.core.migrate());
|
|
63
|
+
}
|
|
64
|
+
async fetch(request) {
|
|
65
|
+
if (request.method !== "POST")
|
|
66
|
+
return new Response(null, { status: 405 });
|
|
67
|
+
const result = await this.core.handleRpc(new Uint8Array(await request.arrayBuffer()));
|
|
68
|
+
return new Response(result, {
|
|
69
|
+
headers: { "content-type": "application/cbor" },
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async alarm() {
|
|
73
|
+
await this.core.runAlarm();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
5
76
|
/**
|
|
6
77
|
* Delivers the container's own HTTPS requests to its public workers.dev origin
|
|
7
78
|
* back into the container over the internal port instead of the public edge.
|
|
@@ -27,6 +98,12 @@ export async function routeEveOutboundRequest(request, env) {
|
|
|
27
98
|
if (hostname !== new URL(publicOrigin).hostname) {
|
|
28
99
|
return fetch(request);
|
|
29
100
|
}
|
|
101
|
+
if (new URL(request.url).pathname === "/__eden/world/rpc") {
|
|
102
|
+
const world = env.EDEN_WORLD;
|
|
103
|
+
if (world === undefined)
|
|
104
|
+
return new Response(null, { status: 404 });
|
|
105
|
+
return world.get(world.idFromName("world")).fetch(request);
|
|
106
|
+
}
|
|
30
107
|
const namespace = env[bindingName];
|
|
31
108
|
if (namespace === undefined) {
|
|
32
109
|
throw new EveHostError("HOST_READINESS_UNPROVEN", "The configured Container binding is unavailable to the outbound handler.");
|
|
@@ -37,8 +114,8 @@ export async function routeEveOutboundRequest(request, env) {
|
|
|
37
114
|
}
|
|
38
115
|
export class EveHostContainer extends Container {
|
|
39
116
|
defaultPort = EVE_HOST_DEFAULTS.internalPort;
|
|
40
|
-
requiredPorts = [EVE_HOST_DEFAULTS.internalPort];
|
|
41
117
|
sleepAfter = EVE_HOST_DEFAULTS.sleepAfter;
|
|
118
|
+
requiredPorts = [EVE_HOST_DEFAULTS.internalPort];
|
|
42
119
|
interceptHttps = true;
|
|
43
120
|
enableInternet = true;
|
|
44
121
|
pingEndpoint = "localhost/eve/v1/health";
|
|
@@ -69,6 +146,12 @@ export class EveHostContainer extends Container {
|
|
|
69
146
|
NODE_ENV: "production",
|
|
70
147
|
WORKFLOW_LOCAL_BASE_URL: publicOrigin,
|
|
71
148
|
EDEN_EVE_DEPLOYMENT_ID: deploymentId,
|
|
149
|
+
...(env.EDEN_EVE_WORLD_CLOUDFLARE
|
|
150
|
+
? {
|
|
151
|
+
EDEN_WORLD_URL: `${publicOrigin}/__eden/world/rpc`,
|
|
152
|
+
CBOR_NATIVE_ACCELERATION_DISABLED: "true",
|
|
153
|
+
}
|
|
154
|
+
: {}),
|
|
72
155
|
EDEN_EVE_GENERATION_ID: generationId,
|
|
73
156
|
// Trust the runtime-mounted Cloudflare Containers CA so the intercepted
|
|
74
157
|
// HTTPS deliveries to the public origin below complete TLS.
|
|
@@ -77,6 +160,13 @@ export class EveHostContainer extends Container {
|
|
|
77
160
|
? {}
|
|
78
161
|
: { EDEN_EVE_RUNTIME_REVISION: env.EDEN_EVE_RUNTIME_REVISION }),
|
|
79
162
|
};
|
|
163
|
+
const sleepAfterOverride = env.EDEN_EVE_CONTAINER_SLEEP_AFTER;
|
|
164
|
+
if (sleepAfterOverride !== undefined) {
|
|
165
|
+
// `env` is only readable after `super()`, so the override is applied in
|
|
166
|
+
// the constructor body; the base class reads `this.sleepAfter` again on
|
|
167
|
+
// every subsequent activity renewal.
|
|
168
|
+
this.sleepAfter = sleepAfterOverride;
|
|
169
|
+
}
|
|
80
170
|
this.readiness = createEveReadinessGate({
|
|
81
171
|
startAndWaitForPorts: (options) => this.startAndWaitForPorts(options),
|
|
82
172
|
healthFetch: (request) => this.containerFetch(request, EVE_HOST_DEFAULTS.internalPort),
|
|
@@ -128,6 +218,14 @@ export function createEveHostWorker(options) {
|
|
|
128
218
|
if (!IDENTIFIER_PATTERN.test(options.containerBindingName)) {
|
|
129
219
|
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container binding name is not valid.");
|
|
130
220
|
}
|
|
221
|
+
const schedules = options.schedules ?? [];
|
|
222
|
+
const resolveContainer = (env) => {
|
|
223
|
+
const namespace = env[options.containerBindingName];
|
|
224
|
+
if (namespace === undefined) {
|
|
225
|
+
throw new EveHostError("HOST_READINESS_UNPROVEN", "The configured Container binding is unavailable.");
|
|
226
|
+
}
|
|
227
|
+
return namespace.getByName(options.stableContainerInstanceName);
|
|
228
|
+
};
|
|
131
229
|
return {
|
|
132
230
|
async fetch(request, env) {
|
|
133
231
|
// Queue deliveries to these endpoints arrive through the container's
|
|
@@ -136,11 +234,7 @@ export function createEveHostWorker(options) {
|
|
|
136
234
|
if (isEveWorkflowInternalRoute(new URL(request.url).pathname)) {
|
|
137
235
|
return new Response(null, { status: 404 });
|
|
138
236
|
}
|
|
139
|
-
const
|
|
140
|
-
if (namespace === undefined) {
|
|
141
|
-
throw new EveHostError("HOST_READINESS_UNPROVEN", "The configured Container binding is unavailable.");
|
|
142
|
-
}
|
|
143
|
-
const container = namespace.getByName(options.stableContainerInstanceName);
|
|
237
|
+
const container = resolveContainer(env);
|
|
144
238
|
const forwarded = createTrustedEveRequest(request, {
|
|
145
239
|
publicOrigin: options.publicOrigin,
|
|
146
240
|
deploymentId: options.deploymentId,
|
|
@@ -166,6 +260,22 @@ export function createEveHostWorker(options) {
|
|
|
166
260
|
headers,
|
|
167
261
|
});
|
|
168
262
|
},
|
|
263
|
+
...(schedules.length === 0
|
|
264
|
+
? {}
|
|
265
|
+
: {
|
|
266
|
+
scheduled(event, env, ctx) {
|
|
267
|
+
const due = schedules.some((schedule) => eveScheduleCronFiresWithin(schedule.cron, event.scheduledTime, EVE_SCHEDULE_WAKE_LEAD_MS));
|
|
268
|
+
if (!due)
|
|
269
|
+
return;
|
|
270
|
+
// Wake only: the in-process Nitro runner inside the container
|
|
271
|
+
// fires the tick itself, so the schedule runs exactly once.
|
|
272
|
+
ctx.waitUntil(resolveContainer(env)
|
|
273
|
+
.fetch(new Request(new URL(EVE_HOST_DEFAULTS.healthPath, options.publicOrigin)))
|
|
274
|
+
.catch((error) => {
|
|
275
|
+
console.error("The scheduled wake request failed:", error instanceof Error ? error.message : "unknown");
|
|
276
|
+
}));
|
|
277
|
+
},
|
|
278
|
+
}),
|
|
169
279
|
};
|
|
170
280
|
}
|
|
171
281
|
//# sourceMappingURL=eve-host-runtime.js.map
|
package/dist/eve-host.d.ts
CHANGED
|
@@ -6,7 +6,50 @@ export declare const EVE_HOST_DEFAULTS: {
|
|
|
6
6
|
readonly instanceType: "basic";
|
|
7
7
|
readonly sleepAfter: "24h";
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
export declare const EVE_SCHEDULE_WAKE_TRIGGER_CRON = "* * * * *";
|
|
10
|
+
/**
|
|
11
|
+
* How far ahead of a tick the every-minute wake trigger starts the Container.
|
|
12
|
+
* A sleeping Container cold-starts in well under a minute on a warm image; the
|
|
13
|
+
* wider window absorbs slow starts without missing the tick.
|
|
14
|
+
*/
|
|
15
|
+
export declare const EVE_SCHEDULE_WAKE_LEAD_MS = 240000;
|
|
16
|
+
/**
|
|
17
|
+
* One authored Eve schedule reduced to the fields the host needs. `cron` is the
|
|
18
|
+
* 5-field expression from the compiled manifest.
|
|
19
|
+
*/
|
|
20
|
+
export interface EveScheduleCronEntry {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly cron: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Expands one cron field (`*`, `*\/n`, `a-b/n`, `a,b,...`) into the set of
|
|
26
|
+
* matching unit values. Returns undefined when the field uses syntax outside
|
|
27
|
+
* the standard 5-field subset Eve documents (e.g. `?`, `L`, `W`, `#`).
|
|
28
|
+
*/
|
|
29
|
+
export declare function expandEveCronField(field: string, fieldIndex: number): ReadonlySet<number> | undefined;
|
|
30
|
+
interface ParsedEveCron {
|
|
31
|
+
readonly minute: ReadonlySet<number>;
|
|
32
|
+
readonly hour: ReadonlySet<number>;
|
|
33
|
+
readonly dayOfMonth: ReadonlySet<number>;
|
|
34
|
+
readonly month: ReadonlySet<number>;
|
|
35
|
+
readonly dayOfWeek: ReadonlySet<number>;
|
|
36
|
+
readonly domRestricted: boolean;
|
|
37
|
+
readonly dowRestricted: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Parses a standard 5-field cron expression (minute granularity, UTC, Vixie
|
|
41
|
+
* day-of-month/day-of-week OR semantics — the same evaluation Vercel and
|
|
42
|
+
* croner use for Eve schedules). Returns undefined for anything else: named
|
|
43
|
+
* `@` schedules, seconds-prefixed 6-field expressions, or unsupported syntax.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseEveScheduleCron(cron: string): ParsedEveCron | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* True when the schedule's next tick lands inside the wake window: at or just
|
|
48
|
+
* after `nowMs` through `nowMs + leadMs` (Cloudflare Cron Triggers are
|
|
49
|
+
* minute-aligned UTC, matching Eve's minute-granularity schedules).
|
|
50
|
+
*/
|
|
51
|
+
export declare function eveScheduleCronFiresWithin(cron: string, nowMs: number, leadMs?: number): boolean;
|
|
52
|
+
/** Queue and World RPC routes are private; webhooks and manifests stay forwarded. */
|
|
10
53
|
export declare function isEveWorkflowInternalRoute(pathname: string): boolean;
|
|
11
54
|
export declare const EVE_HOST_OWNED_HEADERS: readonly ["forwarded", "x-forwarded-for", "x-forwarded-host", "x-forwarded-port", "x-forwarded-proto", "x-forwarded-server", "x-forwarded-scheme", "x-real-ip", "cf-connecting-ip", "cf-visitor", "true-client-ip", "x-original-host", "x-original-proto", "x-envoy-original-host", "x-envoy-original-proto", "x-proxy-host", "x-host", "x-eve-public-origin", "x-workflow-local-base-url", "x-eden-eve-callback-base", "x-eden-eve-deployment-id", "x-eden-eve-generation-id", "x-eden-eve-public-origin", "x-eden-eve-correlation-id", "x-eden-eve-container-name", "x-eden-eve-container-id", "x-eden-eve-runtime-revision", "x-eden-deployment-id", "x-eden-generation-id", "x-eden-container-name", "x-eden-container-id", "cf-container-target-port"];
|
|
12
55
|
export declare const WORKER_NAME_PATTERN: RegExp;
|
|
@@ -37,6 +80,14 @@ export interface EveHostConfigRequest extends EveHostIdentity {
|
|
|
37
80
|
readonly containerImageBuildContext?: string;
|
|
38
81
|
readonly runtimeVariableNames?: readonly string[];
|
|
39
82
|
readonly runtimeRevisionHandle?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Compiled authored schedules. Entries whose cron cannot be expressed are
|
|
85
|
+
* rejected here; the caller reports that as a deploy warning.
|
|
86
|
+
*/
|
|
87
|
+
readonly schedules?: readonly EveScheduleCronEntry[];
|
|
88
|
+
/** Overrides the Container `sleepAfter` (e.g. "30s") for testing. */
|
|
89
|
+
readonly containerSleepAfter?: string;
|
|
90
|
+
readonly workflowWorld?: string;
|
|
40
91
|
}
|
|
41
92
|
export interface EveHostWranglerConfig {
|
|
42
93
|
readonly account_id?: string;
|
|
@@ -52,6 +103,11 @@ export interface EveHostWranglerConfig {
|
|
|
52
103
|
readonly EDEN_EVE_GENERATION_ID: string;
|
|
53
104
|
readonly EVE_RUNTIME_VARIABLE_NAMES: readonly string[];
|
|
54
105
|
readonly EDEN_EVE_RUNTIME_REVISION?: string;
|
|
106
|
+
readonly EDEN_EVE_CONTAINER_SLEEP_AFTER?: string;
|
|
107
|
+
readonly EDEN_EVE_WORLD_CLOUDFLARE?: true;
|
|
108
|
+
};
|
|
109
|
+
readonly triggers?: {
|
|
110
|
+
readonly crons: readonly string[];
|
|
55
111
|
};
|
|
56
112
|
readonly containers: readonly [
|
|
57
113
|
{
|
|
@@ -64,17 +120,15 @@ export interface EveHostWranglerConfig {
|
|
|
64
120
|
}
|
|
65
121
|
];
|
|
66
122
|
readonly durable_objects: {
|
|
67
|
-
readonly bindings: readonly
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
];
|
|
123
|
+
readonly bindings: readonly {
|
|
124
|
+
readonly name: string;
|
|
125
|
+
readonly class_name: string;
|
|
126
|
+
}[];
|
|
73
127
|
};
|
|
74
128
|
readonly migrations: readonly [
|
|
75
129
|
{
|
|
76
130
|
readonly tag: "v1";
|
|
77
|
-
readonly new_sqlite_classes: readonly [
|
|
131
|
+
readonly new_sqlite_classes: readonly string[];
|
|
78
132
|
}
|
|
79
133
|
];
|
|
80
134
|
}
|
|
@@ -88,6 +142,7 @@ export interface EveHostContainerConfig {
|
|
|
88
142
|
readonly deploymentId: string;
|
|
89
143
|
readonly generationId: string;
|
|
90
144
|
readonly runtimeRevisionHandle?: string;
|
|
145
|
+
readonly schedules: readonly EveScheduleCronEntry[];
|
|
91
146
|
}
|
|
92
147
|
export interface EveHostConfig {
|
|
93
148
|
readonly worker: EveHostWranglerConfig;
|
|
@@ -136,6 +191,8 @@ export interface EveHostContainerEnvironment {
|
|
|
136
191
|
readonly EDEN_EVE_DEPLOYMENT_ID?: string;
|
|
137
192
|
readonly EDEN_EVE_GENERATION_ID?: string;
|
|
138
193
|
readonly EDEN_EVE_RUNTIME_REVISION?: string;
|
|
194
|
+
readonly EDEN_EVE_CONTAINER_SLEEP_AFTER?: string;
|
|
195
|
+
readonly EDEN_EVE_WORLD_CLOUDFLARE?: boolean;
|
|
139
196
|
}
|
|
140
197
|
export interface EveHostReadinessEvidence {
|
|
141
198
|
readonly healthPath: "/eve/v1/health";
|
|
@@ -168,4 +225,5 @@ export interface EveReadinessGate {
|
|
|
168
225
|
}
|
|
169
226
|
export declare function readProtectedRuntimeVariables(env: EveHostContainerEnvironment): Record<string, string>;
|
|
170
227
|
export declare function createEveReadinessGate(options: EveHostReadinessOptions): EveReadinessGate;
|
|
228
|
+
export {};
|
|
171
229
|
//# sourceMappingURL=eve-host.d.ts.map
|
package/dist/eve-host.js
CHANGED
|
@@ -6,16 +6,165 @@ export const EVE_HOST_DEFAULTS = {
|
|
|
6
6
|
instanceType: "basic",
|
|
7
7
|
sleepAfter: "24h",
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
export const EVE_SCHEDULE_WAKE_TRIGGER_CRON = "* * * * *";
|
|
10
|
+
/**
|
|
11
|
+
* How far ahead of a tick the every-minute wake trigger starts the Container.
|
|
12
|
+
* A sleeping Container cold-starts in well under a minute on a warm image; the
|
|
13
|
+
* wider window absorbs slow starts without missing the tick.
|
|
14
|
+
*/
|
|
15
|
+
export const EVE_SCHEDULE_WAKE_LEAD_MS = 240_000;
|
|
16
|
+
const EVE_SCHEDULE_WAKE_GRACE_MS = 60_000;
|
|
17
|
+
const MINUTE_MS = 60_000;
|
|
18
|
+
const EVE_CRON_FIELD_BOUNDS = [
|
|
19
|
+
{ min: 0, max: 59 }, // minute
|
|
20
|
+
{ min: 0, max: 23 }, // hour
|
|
21
|
+
{ min: 1, max: 31 }, // day of month
|
|
22
|
+
{ min: 1, max: 12 }, // month
|
|
23
|
+
{ min: 0, max: 7 }, // day of week (0 and 7 are Sunday)
|
|
24
|
+
];
|
|
25
|
+
const EVE_CRON_MONTH_NAMES = {
|
|
26
|
+
jan: 1, feb: 2, mar: 3, apr: 4, may: 5, jun: 6,
|
|
27
|
+
jul: 7, aug: 8, sep: 9, oct: 10, nov: 11, dec: 12,
|
|
28
|
+
};
|
|
29
|
+
const EVE_CRON_DAY_NAMES = {
|
|
30
|
+
sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6,
|
|
31
|
+
};
|
|
32
|
+
function parseCronValue(token, bounds, fieldIndex) {
|
|
33
|
+
const names = fieldIndex === 3
|
|
34
|
+
? EVE_CRON_MONTH_NAMES
|
|
35
|
+
: fieldIndex === 4
|
|
36
|
+
? EVE_CRON_DAY_NAMES
|
|
37
|
+
: undefined;
|
|
38
|
+
const named = names?.[token.toLowerCase()];
|
|
39
|
+
const value = named !== undefined
|
|
40
|
+
? named
|
|
41
|
+
: /^[0-9]+$/u.test(token)
|
|
42
|
+
? Number.parseInt(token, 10)
|
|
43
|
+
: Number.NaN;
|
|
44
|
+
if (!Number.isInteger(value) || value < bounds.min || value > bounds.max) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return fieldIndex === 4 && value === 7 ? 0 : value;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Expands one cron field (`*`, `*\/n`, `a-b/n`, `a,b,...`) into the set of
|
|
51
|
+
* matching unit values. Returns undefined when the field uses syntax outside
|
|
52
|
+
* the standard 5-field subset Eve documents (e.g. `?`, `L`, `W`, `#`).
|
|
53
|
+
*/
|
|
54
|
+
export function expandEveCronField(field, fieldIndex) {
|
|
55
|
+
const bounds = EVE_CRON_FIELD_BOUNDS[fieldIndex];
|
|
56
|
+
if (bounds === undefined)
|
|
57
|
+
return undefined;
|
|
58
|
+
const values = new Set();
|
|
59
|
+
for (const part of field.split(",")) {
|
|
60
|
+
const stepMatch = /^(.+)\/([0-9]+)$/u.exec(part);
|
|
61
|
+
const rangeText = stepMatch?.[1] ?? part;
|
|
62
|
+
const step = stepMatch === null ? 1 : Number.parseInt(stepMatch[2] ?? "", 10);
|
|
63
|
+
if (!Number.isInteger(step) || step < 1)
|
|
64
|
+
return undefined;
|
|
65
|
+
let low;
|
|
66
|
+
let high;
|
|
67
|
+
if (rangeText === "*" || rangeText === "?") {
|
|
68
|
+
low = bounds.min;
|
|
69
|
+
high = bounds.max;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const rangeMatch = /^([A-Za-z0-9]+)-([A-Za-z0-9]+)$/u.exec(rangeText);
|
|
73
|
+
const lowToken = rangeMatch === null ? rangeText : rangeMatch[1];
|
|
74
|
+
const lowValue = lowToken === undefined
|
|
75
|
+
? undefined
|
|
76
|
+
: parseCronValue(lowToken, bounds, fieldIndex);
|
|
77
|
+
if (lowValue === undefined)
|
|
78
|
+
return undefined;
|
|
79
|
+
low = lowValue;
|
|
80
|
+
const highToken = rangeMatch?.[2];
|
|
81
|
+
const highValue = highToken === undefined
|
|
82
|
+
? undefined
|
|
83
|
+
: parseCronValue(highToken, bounds, fieldIndex);
|
|
84
|
+
high = rangeMatch === null
|
|
85
|
+
? (stepMatch === null ? lowValue : bounds.max)
|
|
86
|
+
: highValue ?? -1;
|
|
87
|
+
if (high < low)
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
for (let value = low; value <= high; value += step) {
|
|
91
|
+
values.add(fieldIndex === 4 && value === 7 ? 0 : value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return values;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parses a standard 5-field cron expression (minute granularity, UTC, Vixie
|
|
98
|
+
* day-of-month/day-of-week OR semantics — the same evaluation Vercel and
|
|
99
|
+
* croner use for Eve schedules). Returns undefined for anything else: named
|
|
100
|
+
* `@` schedules, seconds-prefixed 6-field expressions, or unsupported syntax.
|
|
101
|
+
*/
|
|
102
|
+
export function parseEveScheduleCron(cron) {
|
|
103
|
+
const fields = cron.trim().split(/\s+/u);
|
|
104
|
+
const [minuteField, hourField, domField, monthField, dowField] = fields;
|
|
105
|
+
if (fields.length !== 5 || minuteField === undefined || hourField === undefined ||
|
|
106
|
+
domField === undefined || monthField === undefined || dowField === undefined)
|
|
107
|
+
return undefined;
|
|
108
|
+
const minute = expandEveCronField(minuteField, 0);
|
|
109
|
+
const hour = expandEveCronField(hourField, 1);
|
|
110
|
+
const dayOfMonth = expandEveCronField(domField, 2);
|
|
111
|
+
const month = expandEveCronField(monthField, 3);
|
|
112
|
+
const dayOfWeek = expandEveCronField(dowField, 4);
|
|
113
|
+
if (minute === undefined || hour === undefined || dayOfMonth === undefined ||
|
|
114
|
+
month === undefined || dayOfWeek === undefined) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
minute,
|
|
119
|
+
hour,
|
|
120
|
+
dayOfMonth,
|
|
121
|
+
month,
|
|
122
|
+
dayOfWeek,
|
|
123
|
+
domRestricted: domField !== "*",
|
|
124
|
+
dowRestricted: dowField !== "*",
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function cronMatches(parsed, atMs) {
|
|
128
|
+
const at = new Date(atMs);
|
|
129
|
+
if (!parsed.minute.has(at.getUTCMinutes()))
|
|
130
|
+
return false;
|
|
131
|
+
if (!parsed.hour.has(at.getUTCHours()))
|
|
132
|
+
return false;
|
|
133
|
+
if (!parsed.month.has(at.getUTCMonth() + 1))
|
|
134
|
+
return false;
|
|
135
|
+
const dom = parsed.dayOfMonth.has(at.getUTCDate());
|
|
136
|
+
const dow = parsed.dayOfWeek.has(at.getUTCDay());
|
|
137
|
+
if (parsed.domRestricted && parsed.dowRestricted)
|
|
138
|
+
return dom || dow;
|
|
139
|
+
return dom && dow;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* True when the schedule's next tick lands inside the wake window: at or just
|
|
143
|
+
* after `nowMs` through `nowMs + leadMs` (Cloudflare Cron Triggers are
|
|
144
|
+
* minute-aligned UTC, matching Eve's minute-granularity schedules).
|
|
145
|
+
*/
|
|
146
|
+
export function eveScheduleCronFiresWithin(cron, nowMs, leadMs = EVE_SCHEDULE_WAKE_LEAD_MS) {
|
|
147
|
+
const parsed = parseEveScheduleCron(cron);
|
|
148
|
+
if (parsed === undefined)
|
|
149
|
+
return false;
|
|
150
|
+
const firstCandidate = Math.floor((nowMs - EVE_SCHEDULE_WAKE_GRACE_MS) / MINUTE_MS) * MINUTE_MS;
|
|
151
|
+
const lastCandidate = Math.floor((nowMs + leadMs) / MINUTE_MS) * MINUTE_MS;
|
|
152
|
+
for (let candidate = firstCandidate; candidate <= lastCandidate; candidate += MINUTE_MS) {
|
|
153
|
+
if (cronMatches(parsed, candidate))
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
/** Queue and World RPC routes are private; webhooks and manifests stay forwarded. */
|
|
10
159
|
export function isEveWorkflowInternalRoute(pathname) {
|
|
11
160
|
let decodedPath = pathname;
|
|
12
161
|
try {
|
|
13
162
|
decodedPath = decodeURIComponent(pathname);
|
|
14
163
|
}
|
|
15
164
|
catch {
|
|
16
|
-
//
|
|
165
|
+
// A malformed escape cannot identify an internal route.
|
|
17
166
|
}
|
|
18
|
-
return
|
|
167
|
+
return /^\/(?:\.well-known\/workflow\/v1\/(?:flow|step)|__eden\/world)(?:\/|$)/iu.test(decodedPath.replace(/\/+/gu, "/"));
|
|
19
168
|
}
|
|
20
169
|
export const EVE_HOST_OWNED_HEADERS = [
|
|
21
170
|
"forwarded",
|
|
@@ -137,6 +286,17 @@ export function createEveHostConfig(request) {
|
|
|
137
286
|
throw new EveHostError("HOST_READINESS_UNPROVEN", `The protected runtime variable name ${name} is invalid or reserved.`);
|
|
138
287
|
}
|
|
139
288
|
}
|
|
289
|
+
const schedules = request.schedules ?? [];
|
|
290
|
+
for (const schedule of schedules) {
|
|
291
|
+
if (parseEveScheduleCron(schedule.cron) === undefined) {
|
|
292
|
+
throw new EveHostError("HOST_READINESS_UNPROVEN", `The schedule ${schedule.name} uses a cron expression the wake trigger cannot express.`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (request.containerSleepAfter !== undefined) {
|
|
296
|
+
if (!/^[0-9]+(?:ms|s|m|h|d)?$/u.test(request.containerSleepAfter)) {
|
|
297
|
+
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container sleepAfter override is not a parseable duration.");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
140
300
|
const container = {
|
|
141
301
|
name: request.containerApplicationName,
|
|
142
302
|
class_name: request.containerClassName,
|
|
@@ -166,7 +326,16 @@ export function createEveHostConfig(request) {
|
|
|
166
326
|
...(request.runtimeRevisionHandle === undefined
|
|
167
327
|
? {}
|
|
168
328
|
: { EDEN_EVE_RUNTIME_REVISION: request.runtimeRevisionHandle }),
|
|
329
|
+
...(request.containerSleepAfter === undefined
|
|
330
|
+
? {}
|
|
331
|
+
: { EDEN_EVE_CONTAINER_SLEEP_AFTER: request.containerSleepAfter }),
|
|
332
|
+
...(request.workflowWorld === "@moinulmoin/eden-world-cloudflare"
|
|
333
|
+
? { EDEN_EVE_WORLD_CLOUDFLARE: true }
|
|
334
|
+
: {}),
|
|
169
335
|
},
|
|
336
|
+
...(schedules.length === 0
|
|
337
|
+
? {}
|
|
338
|
+
: { triggers: { crons: [EVE_SCHEDULE_WAKE_TRIGGER_CRON] } }),
|
|
170
339
|
containers: [container],
|
|
171
340
|
durable_objects: {
|
|
172
341
|
bindings: [
|
|
@@ -174,12 +343,20 @@ export function createEveHostConfig(request) {
|
|
|
174
343
|
name: request.containerBindingName,
|
|
175
344
|
class_name: request.containerClassName,
|
|
176
345
|
},
|
|
346
|
+
...(request.workflowWorld === "@moinulmoin/eden-world-cloudflare"
|
|
347
|
+
? [{ name: "EDEN_WORLD", class_name: "EdenWorldDurableObject" }]
|
|
348
|
+
: []),
|
|
177
349
|
],
|
|
178
350
|
},
|
|
179
351
|
migrations: [
|
|
180
352
|
{
|
|
181
353
|
tag: "v1",
|
|
182
|
-
new_sqlite_classes: [
|
|
354
|
+
new_sqlite_classes: [
|
|
355
|
+
request.containerClassName,
|
|
356
|
+
...(request.workflowWorld === "@moinulmoin/eden-world-cloudflare"
|
|
357
|
+
? ["EdenWorldDurableObject"]
|
|
358
|
+
: []),
|
|
359
|
+
],
|
|
183
360
|
},
|
|
184
361
|
],
|
|
185
362
|
},
|
|
@@ -195,6 +372,7 @@ export function createEveHostConfig(request) {
|
|
|
195
372
|
...(request.runtimeRevisionHandle === undefined
|
|
196
373
|
? {}
|
|
197
374
|
: { runtimeRevisionHandle: request.runtimeRevisionHandle }),
|
|
375
|
+
schedules,
|
|
198
376
|
},
|
|
199
377
|
};
|
|
200
378
|
}
|
|
@@ -212,6 +390,9 @@ export function generateEveHostWorkerSource(request) {
|
|
|
212
390
|
: {
|
|
213
391
|
runtimeRevisionHandle: request.config.container.runtimeRevisionHandle,
|
|
214
392
|
}),
|
|
393
|
+
...(request.config.container.schedules.length === 0
|
|
394
|
+
? {}
|
|
395
|
+
: { schedules: request.config.container.schedules }),
|
|
215
396
|
};
|
|
216
397
|
return [
|
|
217
398
|
`import { ContainerProxy, EveHostContainer, createEveHostWorker, routeEveOutboundRequest } from ${JSON.stringify(moduleSpecifier)};`,
|
|
@@ -219,6 +400,9 @@ export function generateEveHostWorkerSource(request) {
|
|
|
219
400
|
? "export { ContainerProxy, EveHostContainer };"
|
|
220
401
|
: `export { ContainerProxy, EveHostContainer as ${request.config.container.className} };`,
|
|
221
402
|
"",
|
|
403
|
+
...(request.config.worker.vars.EDEN_EVE_WORLD_CLOUDFLARE
|
|
404
|
+
? [`export { EdenWorldDurableObject } from ${JSON.stringify(moduleSpecifier)};`]
|
|
405
|
+
: []),
|
|
222
406
|
`EveHostContainer.outboundByHost = { ${JSON.stringify(new URL(request.config.container.publicOrigin).hostname)}: routeEveOutboundRequest };`,
|
|
223
407
|
"",
|
|
224
408
|
`export default createEveHostWorker(${JSON.stringify(workerOptions)});`,
|
|
@@ -341,6 +525,7 @@ const RESERVED_EVE_HOST_VARIABLES = new Set([
|
|
|
341
525
|
"NODE_ENV",
|
|
342
526
|
"NODE_EXTRA_CA_CERTS",
|
|
343
527
|
"WORKFLOW_LOCAL_BASE_URL",
|
|
528
|
+
"EDEN_WORLD_URL",
|
|
344
529
|
"EDEN_EVE_DEPLOYMENT_ID",
|
|
345
530
|
"EDEN_EVE_GENERATION_ID",
|
|
346
531
|
"EDEN_EVE_RUNTIME_REVISION",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { EVE_HOST_DEFAULTS, EVE_HOST_OWNED_HEADERS, EveHostError, createEveHostConfig, createEveHostLifecycleObserver, createEveHostProxy, createEveReadinessGate, createTrustedEveRequest, generateEveHostWorkerSource, resolveStableWorkersDevOrigin, } from "./eve-host.js";
|
|
2
|
-
export type { EveContainerTransport, EveHostConfig, EveHostConfigRequest, EveHostContainerConfig, EveHostContainerEnvironment, EveHostErrorCode, EveHostForwardingMetadata, EveHostIdentity, EveHostLifecycleEvent, EveHostLifecycleObserver, EveHostProxyOptions, EveHostReadinessEvidence, EveHostReadinessOptions, EveReadinessGate, EveHostWranglerConfig, EveGeneratedWorkerSourceRequest, StableWorkersDevOriginRequest, } from "./eve-host.js";
|
|
1
|
+
export { EVE_HOST_DEFAULTS, EVE_SCHEDULE_WAKE_LEAD_MS, EVE_SCHEDULE_WAKE_TRIGGER_CRON, eveScheduleCronFiresWithin, expandEveCronField, parseEveScheduleCron, EVE_HOST_OWNED_HEADERS, EveHostError, createEveHostConfig, createEveHostLifecycleObserver, createEveHostProxy, createEveReadinessGate, createTrustedEveRequest, generateEveHostWorkerSource, resolveStableWorkersDevOrigin, } from "./eve-host.js";
|
|
2
|
+
export type { EveContainerTransport, EveHostConfig, EveHostConfigRequest, EveHostContainerConfig, EveHostContainerEnvironment, EveHostErrorCode, EveScheduleCronEntry, EveHostForwardingMetadata, EveHostIdentity, EveHostLifecycleEvent, EveHostLifecycleObserver, EveHostProxyOptions, EveHostReadinessEvidence, EveHostReadinessOptions, EveReadinessGate, EveHostWranglerConfig, EveGeneratedWorkerSourceRequest, StableWorkersDevOriginRequest, } from "./eve-host.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { EVE_HOST_DEFAULTS, EVE_HOST_OWNED_HEADERS, EveHostError, createEveHostConfig, createEveHostLifecycleObserver, createEveHostProxy, createEveReadinessGate, createTrustedEveRequest, generateEveHostWorkerSource, resolveStableWorkersDevOrigin, } from "./eve-host.js";
|
|
1
|
+
export { EVE_HOST_DEFAULTS, EVE_SCHEDULE_WAKE_LEAD_MS, EVE_SCHEDULE_WAKE_TRIGGER_CRON, eveScheduleCronFiresWithin, expandEveCronField, parseEveScheduleCron, EVE_HOST_OWNED_HEADERS, EveHostError, createEveHostConfig, createEveHostLifecycleObserver, createEveHostProxy, createEveReadinessGate, createTrustedEveRequest, generateEveHostWorkerSource, resolveStableWorkersDevOrigin, } from "./eve-host.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moinulmoin/eden-runtime-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Cloudflare Worker/Container host runtime for Eden's Eve deployments.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@cloudflare/containers": "0.3.7",
|
|
24
|
+
"@moinulmoin/eden-world-cloudflare": "0.4.1",
|
|
24
25
|
"@cloudflare/workers-types": "5.20260810.1"
|
|
25
26
|
},
|
|
26
27
|
"repository": {
|