@moinulmoin/eden-runtime-cloudflare 0.6.0 → 0.7.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/dist/eden-eve-host-worker.mjs +305 -120
- package/dist/eve-host-runtime.d.ts +49 -11
- package/dist/eve-host-runtime.js +301 -88
- package/dist/eve-host.d.ts +16 -26
- package/dist/eve-host.js +44 -70
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/eve-host.js
CHANGED
|
@@ -3,8 +3,42 @@ export const EVE_HOST_DEFAULTS = {
|
|
|
3
3
|
healthPath: "/eve/v1/health",
|
|
4
4
|
internalPort: 8080,
|
|
5
5
|
instance: "standard-1",
|
|
6
|
-
sleepAfter: "
|
|
6
|
+
sleepAfter: "1h",
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Cloudflare stops a container at most 6 hours after its Durable Object goes
|
|
10
|
+
* inactive (`setInactivityTimeout` rejects longer values). The idle-sleep
|
|
11
|
+
* alarm must fire before that so it can snapshot first, and the inactivity
|
|
12
|
+
* timeout is `sleepAfter` plus this margin.
|
|
13
|
+
*/
|
|
14
|
+
export const EVE_HOST_SLEEP_SNAPSHOT_MARGIN_MS = 15 * 60_000;
|
|
15
|
+
export const EVE_HOST_MAX_SLEEP_AFTER_MS = 6 * 3_600_000 - EVE_HOST_SLEEP_SNAPSHOT_MARGIN_MS;
|
|
16
|
+
/**
|
|
17
|
+
* Parses a `sleepAfter` duration ("300ms", "30s", "15m", "1h", or a bare
|
|
18
|
+
* number of seconds) and enforces Cloudflare's inactivity ceiling.
|
|
19
|
+
*/
|
|
20
|
+
export function parseEveSleepAfterMs(value) {
|
|
21
|
+
const match = /^([0-9]+)(ms|s|m|h|d)?$/u.exec(value.trim());
|
|
22
|
+
if (match === null) {
|
|
23
|
+
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container sleepAfter override is not a parseable duration.");
|
|
24
|
+
}
|
|
25
|
+
const amount = Number.parseInt(match[1] ?? "", 10);
|
|
26
|
+
const unit = match[2] ?? "s";
|
|
27
|
+
const factor = unit === "ms"
|
|
28
|
+
? 1
|
|
29
|
+
: unit === "s"
|
|
30
|
+
? 1_000
|
|
31
|
+
: unit === "m"
|
|
32
|
+
? 60_000
|
|
33
|
+
: unit === "h"
|
|
34
|
+
? 3_600_000
|
|
35
|
+
: 86_400_000;
|
|
36
|
+
const ms = amount * factor;
|
|
37
|
+
if (ms > EVE_HOST_MAX_SLEEP_AFTER_MS) {
|
|
38
|
+
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container sleepAfter override exceeds 345m (5 h 45 min); Cloudflare stops a container within 6 hours of its Durable Object going idle, so Eden must snapshot before then.");
|
|
39
|
+
}
|
|
40
|
+
return ms;
|
|
41
|
+
}
|
|
8
42
|
export const EVE_SCHEDULE_WAKE_TRIGGER_CRON = "* * * * *";
|
|
9
43
|
/**
|
|
10
44
|
* How far ahead of a tick the every-minute wake trigger starts the Container.
|
|
@@ -167,15 +201,7 @@ export function isEveWorkflowInternalRoute(pathname) {
|
|
|
167
201
|
}
|
|
168
202
|
export const EVE_HOST_OWNED_HEADERS = [
|
|
169
203
|
"forwarded",
|
|
170
|
-
"x-forwarded-for",
|
|
171
|
-
"x-forwarded-host",
|
|
172
|
-
"x-forwarded-port",
|
|
173
|
-
"x-forwarded-proto",
|
|
174
|
-
"x-forwarded-server",
|
|
175
|
-
"x-forwarded-scheme",
|
|
176
204
|
"x-real-ip",
|
|
177
|
-
"cf-connecting-ip",
|
|
178
|
-
"cf-visitor",
|
|
179
205
|
"true-client-ip",
|
|
180
206
|
"x-original-host",
|
|
181
207
|
"x-original-proto",
|
|
@@ -185,22 +211,10 @@ export const EVE_HOST_OWNED_HEADERS = [
|
|
|
185
211
|
"x-host",
|
|
186
212
|
"x-eve-public-origin",
|
|
187
213
|
"x-workflow-local-base-url",
|
|
188
|
-
"x-eden-eve-callback-base",
|
|
189
|
-
"x-eden-eve-deployment-id",
|
|
190
|
-
"x-eden-eve-generation-id",
|
|
191
|
-
"x-eden-eve-started-deployment",
|
|
192
|
-
"x-eden-eve-public-origin",
|
|
193
|
-
"x-eden-eve-correlation-id",
|
|
194
|
-
"x-eden-eve-container-name",
|
|
195
|
-
"x-eden-eve-container-id",
|
|
196
|
-
"x-eden-eve-runtime-revision",
|
|
197
|
-
"x-eden-container-name",
|
|
198
|
-
"x-eden-container-id",
|
|
199
|
-
"cf-container-target-port",
|
|
200
214
|
];
|
|
201
215
|
const EVE_HOST_OWNED_HEADER_SET = new Set(EVE_HOST_OWNED_HEADERS);
|
|
202
216
|
export const WORKER_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u;
|
|
203
|
-
const SUBDOMAIN_PATTERN =
|
|
217
|
+
const SUBDOMAIN_PATTERN = WORKER_NAME_PATTERN;
|
|
204
218
|
export const IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/u;
|
|
205
219
|
const INSTANCE_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9._-]{0,125}[a-z0-9])?$/u;
|
|
206
220
|
const SHA256_IMAGE_PATTERN = /^(?:[a-z0-9.-]+\/)?[a-z0-9._/-]+@sha256:[0-9a-f]{64}$/u;
|
|
@@ -265,13 +279,9 @@ export function createEveHostConfig(request) {
|
|
|
265
279
|
if (!WORKER_NAME_PATTERN.test(request.workerName)) {
|
|
266
280
|
throw new EveHostError("HOST_ORIGIN_UNAVAILABLE", "The exact Worker name is not valid.");
|
|
267
281
|
}
|
|
268
|
-
if (!WORKER_NAME_PATTERN.test(request.containerApplicationName)
|
|
269
|
-
!IDENTIFIER_PATTERN.test(request.containerClassName)) {
|
|
282
|
+
if (!WORKER_NAME_PATTERN.test(request.containerApplicationName)) {
|
|
270
283
|
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container application and class names must be stable safe identifiers.");
|
|
271
284
|
}
|
|
272
|
-
if (!IDENTIFIER_PATTERN.test(request.containerBindingName)) {
|
|
273
|
-
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container binding name must be a valid Worker environment identifier.");
|
|
274
|
-
}
|
|
275
285
|
if (!INSTANCE_NAME_PATTERN.test(request.stableContainerInstanceName)) {
|
|
276
286
|
throw new EveHostError("HOST_READINESS_UNPROVEN", "The stable Container instance name must be a bounded logical identifier.");
|
|
277
287
|
}
|
|
@@ -291,13 +301,11 @@ export function createEveHostConfig(request) {
|
|
|
291
301
|
}
|
|
292
302
|
}
|
|
293
303
|
if (request.containerSleepAfter !== undefined) {
|
|
294
|
-
|
|
295
|
-
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container sleepAfter override is not a parseable duration.");
|
|
296
|
-
}
|
|
304
|
+
parseEveSleepAfterMs(request.containerSleepAfter);
|
|
297
305
|
}
|
|
298
306
|
const container = {
|
|
299
307
|
name: request.containerApplicationName,
|
|
300
|
-
class_name:
|
|
308
|
+
class_name: "EveHostDurableContainer",
|
|
301
309
|
scheduling_policy: "durable_object",
|
|
302
310
|
images: { eve: { image: request.containerImage } },
|
|
303
311
|
};
|
|
@@ -316,8 +324,8 @@ export function createEveHostConfig(request) {
|
|
|
316
324
|
}
|
|
317
325
|
const bindings = [
|
|
318
326
|
{
|
|
319
|
-
name:
|
|
320
|
-
class_name:
|
|
327
|
+
name: "EVE_CONTAINER",
|
|
328
|
+
class_name: "EveHostDurableContainer",
|
|
321
329
|
},
|
|
322
330
|
...(worldCloudflare
|
|
323
331
|
? [{ name: "EDEN_WORLD", class_name: "EdenWorldDurableObject" }]
|
|
@@ -368,7 +376,6 @@ export function createEveHostConfig(request) {
|
|
|
368
376
|
vars: {
|
|
369
377
|
EVE_PUBLIC_ORIGIN: request.stableWorkersDevOrigin,
|
|
370
378
|
EVE_CONTAINER_INSTANCE_NAME: request.stableContainerInstanceName,
|
|
371
|
-
EVE_CONTAINER_BINDING_NAME: request.containerBindingName,
|
|
372
379
|
EDEN_EVE_DEPLOYMENT_ID: request.deploymentId,
|
|
373
380
|
EDEN_EVE_GENERATION_ID: request.generationId,
|
|
374
381
|
EVE_RUNTIME_VARIABLE_NAMES: request.runtimeVariableNames ?? [],
|
|
@@ -391,9 +398,9 @@ export function createEveHostConfig(request) {
|
|
|
391
398
|
},
|
|
392
399
|
container: {
|
|
393
400
|
applicationName: request.containerApplicationName,
|
|
394
|
-
className:
|
|
401
|
+
className: "EveHostDurableContainer",
|
|
395
402
|
instanceName: request.stableContainerInstanceName,
|
|
396
|
-
bindingName:
|
|
403
|
+
bindingName: "EVE_CONTAINER",
|
|
397
404
|
port: EVE_HOST_DEFAULTS.internalPort,
|
|
398
405
|
publicOrigin: request.stableWorkersDevOrigin,
|
|
399
406
|
deploymentId: request.deploymentId,
|
|
@@ -410,7 +417,6 @@ export function generateEveHostWorkerSource(request) {
|
|
|
410
417
|
const workerOptions = {
|
|
411
418
|
publicOrigin: request.config.container.publicOrigin,
|
|
412
419
|
workerName: request.config.worker.name,
|
|
413
|
-
containerBindingName: request.config.container.bindingName,
|
|
414
420
|
deploymentId: request.config.container.deploymentId,
|
|
415
421
|
generationId: request.config.container.generationId,
|
|
416
422
|
stableContainerInstanceName: request.config.container.instanceName,
|
|
@@ -423,13 +429,10 @@ export function generateEveHostWorkerSource(request) {
|
|
|
423
429
|
? {}
|
|
424
430
|
: { schedules: request.config.container.schedules }),
|
|
425
431
|
};
|
|
426
|
-
const exportContainerClass = request.config.container.className === "EveHostDurableContainer"
|
|
427
|
-
? "export { EveHostDurableContainer };"
|
|
428
|
-
: `export { EveHostDurableContainer as ${request.config.container.className} };`;
|
|
429
432
|
return [
|
|
430
433
|
`import { EdenWorldDurableObject, EveHostDurableContainer, EveHostLoopback, createEveHostWorker } from ${JSON.stringify(moduleSpecifier)};`,
|
|
431
434
|
`export { EveHostLoopback };`,
|
|
432
|
-
|
|
435
|
+
"export { EveHostDurableContainer };",
|
|
433
436
|
"",
|
|
434
437
|
...(request.config.worker.vars.EDEN_EVE_WORLD_CLOUDFLARE === true ||
|
|
435
438
|
request.config.worker.durable_objects.bindings.some((binding) => binding.class_name === "EdenWorldDurableObject") ||
|
|
@@ -504,40 +507,11 @@ export function createTrustedEveRequest(request, metadata) {
|
|
|
504
507
|
};
|
|
505
508
|
return new Request(targetUrl, init);
|
|
506
509
|
}
|
|
507
|
-
function isWebSocketUpgrade(request) {
|
|
508
|
-
return request.headers.get("upgrade")?.toLowerCase() === "websocket";
|
|
509
|
-
}
|
|
510
510
|
function throwIfAborted(signal) {
|
|
511
511
|
if (signal.aborted) {
|
|
512
512
|
throw new EveHostError("HOST_REQUEST_ABORTED", "The client request was cancelled before Eve became ready.");
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
|
-
export function createEveHostProxy(options) {
|
|
516
|
-
return async (request) => {
|
|
517
|
-
throwIfAborted(request.signal);
|
|
518
|
-
await options.ensureReady(request.signal);
|
|
519
|
-
throwIfAborted(request.signal);
|
|
520
|
-
const forwarded = createTrustedEveRequest(request, options);
|
|
521
|
-
return isWebSocketUpgrade(request)
|
|
522
|
-
? options.transport.fetch(forwarded)
|
|
523
|
-
: options.transport.containerFetch(forwarded);
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
export function createEveHostLifecycleObserver(now = Date.now) {
|
|
527
|
-
const events = [];
|
|
528
|
-
return {
|
|
529
|
-
events,
|
|
530
|
-
record(type, safeStatus) {
|
|
531
|
-
const event = {
|
|
532
|
-
type,
|
|
533
|
-
at: now(),
|
|
534
|
-
...(safeStatus === undefined ? {} : { safeStatus }),
|
|
535
|
-
};
|
|
536
|
-
events.push(event);
|
|
537
|
-
return event;
|
|
538
|
-
},
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
515
|
function responseBodyIsReady(value) {
|
|
542
516
|
if (typeof value !== "object" || value === null)
|
|
543
517
|
return false;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { EveDurableBinding, EveDurableMigration,
|
|
1
|
+
export { createEveHostConfig, generateEveHostWorkerSource, parseEveScheduleCron, resolveStableWorkersDevOrigin, } from "./eve-host.js";
|
|
2
|
+
export type { EveDurableBinding, EveDurableMigration, EveHostConfig, EveScheduleCronEntry, } from "./eve-host.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createEveHostConfig, generateEveHostWorkerSource, parseEveScheduleCron, 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.7.0",
|
|
4
4
|
"description": "Cloudflare Worker/Container host runtime for Eden's Eve deployments.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"NOTICE"
|
|
21
21
|
],
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@moinulmoin/eden-world-cloudflare": "0.
|
|
23
|
+
"@moinulmoin/eden-world-cloudflare": "0.7.0",
|
|
24
24
|
"@cloudflare/workers-types": "5.20261006.1"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|