@lunora/container 1.0.0-alpha.2 → 1.0.0-alpha.21
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/LICENSE.md +26 -0
- package/README.md +99 -1
- package/dist/bridge.d.mts +51 -35
- package/dist/bridge.d.ts +51 -35
- package/dist/bridge.mjs +1 -76
- package/dist/do/index.d.mts +580 -45
- package/dist/do/index.d.ts +580 -45
- package/dist/do/index.mjs +1 -138
- package/dist/index.d.mts +235 -114
- package/dist/index.d.ts +235 -114
- package/dist/index.mjs +1 -2
- package/dist/otel.d.mts +161 -0
- package/dist/otel.d.ts +161 -0
- package/dist/otel.mjs +1 -0
- package/dist/packem_shared/ContainerProxy-BsQAwSNX.mjs +27 -0
- package/dist/packem_shared/containerBindingName-DP2NqQV-.mjs +1 -0
- package/dist/packem_shared/createContainerContext-Df9Ev-Fp.mjs +1 -0
- package/dist/packem_shared/jurisdiction-BKRNOTip.mjs +1 -0
- package/dist/packem_shared/jurisdiction.d-8oUUvrew.d.mts +281 -0
- package/dist/packem_shared/jurisdiction.d-8oUUvrew.d.ts +281 -0
- package/package.json +7 -3
- package/dist/packem_shared/containerBindingName-BGdSdFNA.mjs +0 -116
- package/dist/packem_shared/createContainerContext-CTpyUQ4J.mjs +0 -133
- package/dist/packem_shared/types.d-D2l2SYol.d.mts +0 -140
- package/dist/packem_shared/types.d-D2l2SYol.d.ts +0 -140
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type { B as BuildImageSource, c as ContainerInstanceType, d as
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
* Deliberately structural (no `@cloudflare/containers` import): a Durable
|
|
8
|
-
* Object namespace stub is all that is needed to route a request to a
|
|
9
|
-
* container-enabled DO, so this module stays Node-safe and the test double
|
|
10
|
-
* below can satisfy the exact same shape without a workerd runtime.
|
|
11
|
-
*/
|
|
12
|
-
/** Options for explicitly starting an instance (mirrors `@cloudflare/containers`). */
|
|
1
|
+
import { D as DurableObjectJurisdiction, C as ContainerConfig, a as ContainerDefinition, b as ContainerImageSource, N as NormalizedContainerImage } from "./packem_shared/jurisdiction.d-8oUUvrew.js";
|
|
2
|
+
export type { B as BuildImageSource, c as ContainerInstanceType, d as ContainerReadinessCheck, e as ContainerRollout, f as CustomContainerInstanceType, g as NamedContainerInstanceType, R as RegistryImageSource } from "./packem_shared/jurisdiction.d-8oUUvrew.js";
|
|
3
|
+
/**
|
|
4
|
+
* Options for explicitly starting an instance (mirrors `@cloudflare/containers`).
|
|
5
|
+
* @experimental
|
|
6
|
+
*/
|
|
13
7
|
interface ContainerStartOptions {
|
|
14
8
|
/** Override outbound internet access for this start. */
|
|
15
9
|
enableInternet?: boolean;
|
|
@@ -20,108 +14,215 @@ interface ContainerStartOptions {
|
|
|
20
14
|
/** Metadata labels attached for metrics/observability. */
|
|
21
15
|
labels?: Record<string, string>;
|
|
22
16
|
}
|
|
23
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* A container instance's runtime state, as returned by `getState()`. Structural — the platform adds fields over time.
|
|
19
|
+
* @experimental
|
|
20
|
+
*/
|
|
24
21
|
interface ContainerInstanceState {
|
|
25
22
|
[key: string]: unknown;
|
|
23
|
+
/** Process exit code, present once the instance has `stopped_with_code`. */
|
|
24
|
+
exitCode?: number;
|
|
25
|
+
/** Epoch-ms of the last state transition. */
|
|
26
26
|
lastChange?: number;
|
|
27
|
+
/** Lifecycle status. Widening union — Cloudflare adds values over time. */
|
|
28
|
+
status?: "healthy" | "running" | "stopped" | "stopped_with_code" | "stopping";
|
|
27
29
|
}
|
|
28
|
-
/** What a handle needs from a Durable Object stub — `fetch` plus the optional lifecycle RPCs the container DO exposes. */
|
|
30
|
+
/** What a handle needs from a Durable Object stub — `fetch` plus the optional lifecycle/egress RPCs the container DO exposes. */
|
|
29
31
|
interface ContainerStubLike {
|
|
32
|
+
allowHost?: (hostname: string) => Promise<void>;
|
|
33
|
+
denyHost?: (hostname: string) => Promise<void>;
|
|
30
34
|
destroy?: () => Promise<void>;
|
|
31
35
|
fetch: (input: Request) => Promise<Response>;
|
|
32
36
|
getState?: () => Promise<ContainerInstanceState>;
|
|
37
|
+
removeAllowedHost?: (hostname: string) => Promise<void>;
|
|
38
|
+
removeDeniedHost?: (hostname: string) => Promise<void>;
|
|
39
|
+
renewActivityTimeout?: () => Promise<void>;
|
|
40
|
+
setAllowedHosts?: (hosts: string[]) => Promise<void>;
|
|
41
|
+
setDeniedHosts?: (hosts: string[]) => Promise<void>;
|
|
33
42
|
start?: (options?: ContainerStartOptions) => Promise<void>;
|
|
34
43
|
stop?: (signal?: number | string) => Promise<void>;
|
|
35
44
|
}
|
|
36
45
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
*/
|
|
41
|
-
type DurableObjectJurisdiction = "eu" | "fedramp" | "us";
|
|
42
|
-
/** What the client needs from a Durable Object namespace binding. */
|
|
46
|
+
* What the client needs from a Durable Object namespace binding.
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
43
49
|
interface ContainerNamespaceLike {
|
|
44
50
|
get: (id: unknown) => ContainerStubLike;
|
|
45
51
|
idFromName: (name: string) => unknown;
|
|
46
52
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
* Derive a jurisdiction-restricted subnamespace. Optional because older
|
|
54
|
+
* workers-types releases (and test doubles) may not expose it.
|
|
55
|
+
*/
|
|
50
56
|
jurisdiction?: (jurisdiction: DurableObjectJurisdiction) => ContainerNamespaceLike;
|
|
51
57
|
}
|
|
52
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* A handle on one container instance (one Durable Object).
|
|
60
|
+
* @experimental
|
|
61
|
+
*/
|
|
53
62
|
interface ContainerHandle {
|
|
54
63
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
* Send an HTTP (or WebSocket-upgrade) request to the container. A path
|
|
65
|
+
* string (`"/transcode"`) is resolved against a synthetic origin; a full
|
|
66
|
+
* `Request`/URL passes through unchanged.
|
|
67
|
+
*/
|
|
59
68
|
fetch: (input: Request | string, init?: RequestInit) => Promise<Response>;
|
|
69
|
+
/**
|
|
70
|
+
* Return a handle that routes every request to `targetPort` on the
|
|
71
|
+
* container instead of the definition's `defaultPort` — for multi-port
|
|
72
|
+
* containers (declare the ports in `requiredPorts`). Sets the
|
|
73
|
+
* `cf-container-target-port` header the way `@cloudflare/containers`'
|
|
74
|
+
* `switchPort` does, so it composes with `.get()`, `.any()`, and `.pool()`:
|
|
75
|
+
* `ctx.containers.app.get("u1").port(9090).fetch("/admin")`.
|
|
76
|
+
*/
|
|
77
|
+
port: (targetPort: number) => ContainerHandle;
|
|
60
78
|
}
|
|
61
79
|
/**
|
|
62
|
-
* A handle on a *named* instance (from `.get(name)`) — `fetch` plus explicit
|
|
63
|
-
* lifecycle control. The per-entity pattern (a sandbox per user, a room per
|
|
64
|
-
* game, a job runner per id) often needs to tear down or inspect the instance
|
|
65
|
-
* rather than wait for `sleepAfter`, so these wrap the container DO's
|
|
66
|
-
* `start`/`stop`/`destroy`/`getState`.
|
|
67
|
-
|
|
80
|
+
* A handle on a *named* instance (from `.get(name)`) — `fetch` plus explicit
|
|
81
|
+
* lifecycle control. The per-entity pattern (a sandbox per user, a room per
|
|
82
|
+
* game, a job runner per id) often needs to tear down or inspect the instance
|
|
83
|
+
* rather than wait for `sleepAfter`, so these wrap the container DO's
|
|
84
|
+
* `start`/`stop`/`destroy`/`getState`.
|
|
85
|
+
* @experimental
|
|
86
|
+
*/
|
|
68
87
|
interface ContainerInstanceHandle extends ContainerHandle {
|
|
69
88
|
/** Stop and discard the instance (its ephemeral disk is lost). */
|
|
70
89
|
destroy: () => Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Adjust this instance's egress allow/deny lists at runtime — the dynamic
|
|
92
|
+
* counterpart to the static `allowedHosts`/`deniedHosts` config. Useful for
|
|
93
|
+
* per-tenant egress policy. Requires the worker to export `ContainerProxy`
|
|
94
|
+
* (codegen re-exports it from the generated container file whenever any
|
|
95
|
+
* container is defined, so the runtime controls always work).
|
|
96
|
+
*/
|
|
97
|
+
egress: ContainerEgressControls;
|
|
71
98
|
/** Read the instance's current runtime state. */
|
|
72
99
|
getState: () => Promise<ContainerInstanceState>;
|
|
100
|
+
/**
|
|
101
|
+
* Reset the instance's `sleepAfter` idle timer. The platform renews it on
|
|
102
|
+
* each proxied request, and because `@lunora/container` proxies WebSocket
|
|
103
|
+
* frames through the Durable Object, message traffic on an open socket
|
|
104
|
+
* renews it too (the WebSocket-keepalive gap of cloudflare/containers#147 is
|
|
105
|
+
* closed in the bundled base). This manual control is the escape hatch for
|
|
106
|
+
* keeping a container awake during activity that is neither an HTTP request
|
|
107
|
+
* nor a WS message — e.g. a long out-of-band job running inside it.
|
|
108
|
+
*/
|
|
109
|
+
renewActivityTimeout: () => Promise<void>;
|
|
73
110
|
/** Explicitly start the instance, optionally with per-instance env/entrypoint. */
|
|
74
111
|
start: (options?: ContainerStartOptions) => Promise<void>;
|
|
75
112
|
/** Stop the instance (optionally with a signal); it can start again on the next request. */
|
|
76
113
|
stop: (signal?: number | string) => Promise<void>;
|
|
77
114
|
}
|
|
78
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Runtime egress-firewall controls for a named instance (`handle.egress.*`).
|
|
117
|
+
* Each maps to the corresponding `@cloudflare/containers` `Container` RPC, so
|
|
118
|
+
* an app can tighten or relax a single instance's allowed/denied hosts after
|
|
119
|
+
* start without redeploying.
|
|
120
|
+
* @experimental
|
|
121
|
+
*/
|
|
122
|
+
interface ContainerEgressControls {
|
|
123
|
+
/** Add one hostname (or glob) to the allow-list. */
|
|
124
|
+
allow: (hostname: string) => Promise<void>;
|
|
125
|
+
/** Add one hostname (or glob) to the deny-list. */
|
|
126
|
+
deny: (hostname: string) => Promise<void>;
|
|
127
|
+
/** Remove one hostname from the allow-list. */
|
|
128
|
+
removeAllowed: (hostname: string) => Promise<void>;
|
|
129
|
+
/** Remove one hostname from the deny-list. */
|
|
130
|
+
removeDenied: (hostname: string) => Promise<void>;
|
|
131
|
+
/** Replace the entire allow-list. */
|
|
132
|
+
setAllowed: (hosts: ReadonlyArray<string>) => Promise<void>;
|
|
133
|
+
/** Replace the entire deny-list. */
|
|
134
|
+
setDenied: (hosts: ReadonlyArray<string>) => Promise<void>;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The per-definition accessor exposed as `ctx.containers.<exportName>`.
|
|
138
|
+
* @experimental
|
|
139
|
+
*/
|
|
79
140
|
interface ContainerAccessor {
|
|
80
141
|
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
142
|
+
* A random instance from a fixed pool of `count` (defaults to the
|
|
143
|
+
* definition's `maxInstances`, else 3 — mirroring `getRandom` from
|
|
144
|
+
* `@cloudflare/containers`). For stateless, interchangeable workloads.
|
|
145
|
+
*
|
|
146
|
+
* Like `.get()`, a path/URL-string fetch transparently retries the
|
|
147
|
+
* cold-start "instance is provisioning" transients (cloudflare/containers#45,
|
|
148
|
+
* #139); pass {@link InstanceRetryOptions} to tune or disable it.
|
|
149
|
+
*/
|
|
150
|
+
any: (count?: number, options?: InstanceRetryOptions) => ContainerHandle;
|
|
88
151
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
152
|
+
* The instance for `name` — one container per entity (user, room, job…),
|
|
153
|
+
* with lifecycle control.
|
|
154
|
+
*
|
|
155
|
+
* A path/URL-string fetch transparently retries the platform's cold-start
|
|
156
|
+
* transients — "there is no Container instance available" / "container is
|
|
157
|
+
* not listening" while an instance is still provisioning
|
|
158
|
+
* (cloudflare/containers#45, #139) — on the *same* instance with backoff,
|
|
159
|
+
* since the request never reached the app. Pass {@link InstanceRetryOptions}
|
|
160
|
+
* to tune attempts/backoff or disable it (`{ attempts: 1 }`). A pre-built
|
|
161
|
+
* `Request` (possibly a one-shot stream body) is sent once, never retried.
|
|
162
|
+
*/
|
|
163
|
+
get: (name: string, options?: InstanceRetryOptions) => ContainerInstanceHandle;
|
|
164
|
+
/**
|
|
165
|
+
* A resilient handle over the pool: each `fetch` picks a random instance and,
|
|
166
|
+
* on a thrown error or a retryable response (5xx by default), retries on a
|
|
167
|
+
* freshly-picked instance with exponential backoff. Until Cloudflare ships
|
|
168
|
+
* native autoscaling + health-aware routing this is the recommended way to
|
|
169
|
+
* call a stateless container pool — it rides over a single cold/unhealthy
|
|
170
|
+
* instance instead of failing the whole request.
|
|
171
|
+
*
|
|
172
|
+
* Because a retry re-issues the request, pass a **replayable** body — a path
|
|
173
|
+
* string plus an `init.body` string/`ArrayBuffer` (re-created each attempt).
|
|
174
|
+
* A pre-built `Request` carrying a stream body can only be sent once, so it
|
|
175
|
+
* is not retry-safe here; use `.get()`/`.any()` for those.
|
|
176
|
+
*/
|
|
101
177
|
pool: (options?: PoolOptions) => ContainerHandle;
|
|
102
178
|
}
|
|
103
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* Tuning for a pooled, retrying container handle. See {@link ContainerAccessor.pool}.
|
|
181
|
+
* @experimental
|
|
182
|
+
*/
|
|
104
183
|
interface PoolOptions {
|
|
105
184
|
/** Total attempts before giving up (each on a freshly-picked instance). Default 3. */
|
|
106
185
|
attempts?: number;
|
|
107
186
|
/** Base backoff in ms between attempts; doubles each retry (0 disables the wait). Default 100. */
|
|
108
187
|
backoffMs?: number;
|
|
109
188
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
189
|
+
* Upper bound on a single backoff sleep, in ms. The doubling delay is clamped
|
|
190
|
+
* to this ceiling so a large `attempts` count can't produce an unboundedly
|
|
191
|
+
* long wait. Default {@link DEFAULT_MAX_BACKOFF_MS} (30s).
|
|
192
|
+
*/
|
|
114
193
|
maxBackoffMs?: number;
|
|
115
194
|
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
195
|
+
* Whether a *returned* response should be retried on another instance.
|
|
196
|
+
* Defaults to retrying any `5xx`. A thrown error (network/start failure) is
|
|
197
|
+
* always retried regardless of this predicate.
|
|
198
|
+
*/
|
|
120
199
|
retryOn?: (response: Response) => boolean;
|
|
121
200
|
/** Pool size to spread picks across. Defaults to the definition's `maxInstances`, else 3. */
|
|
122
201
|
size?: number;
|
|
123
202
|
}
|
|
124
|
-
/**
|
|
203
|
+
/**
|
|
204
|
+
* Tuning for the cold-start retry on a `.get()`/`.any()` handle. The retry fires
|
|
205
|
+
* only on the platform's provisioning transients (no-instance / not-listening /
|
|
206
|
+
* rate-limited — see {@link isColdStartTransient}), which is why it's safe by
|
|
207
|
+
* default: those responses mean the request never reached the container.
|
|
208
|
+
* @experimental
|
|
209
|
+
*/
|
|
210
|
+
interface InstanceRetryOptions {
|
|
211
|
+
/**
|
|
212
|
+
* Total attempts on a cold-start transient before the last outcome is
|
|
213
|
+
* surfaced as-is. `1` disables the retry. Default
|
|
214
|
+
* {@link DEFAULT_COLD_START_ATTEMPTS}.
|
|
215
|
+
*/
|
|
216
|
+
attempts?: number;
|
|
217
|
+
/** Base backoff in ms between attempts; doubles each retry (0 disables the wait). Default {@link DEFAULT_COLD_START_BACKOFF_MS}. */
|
|
218
|
+
backoffMs?: number;
|
|
219
|
+
/** Upper bound on a single backoff sleep, in ms. Default {@link DEFAULT_MAX_BACKOFF_MS} (30s). */
|
|
220
|
+
maxBackoffMs?: number;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Wiring info for one definition, emitted by codegen into the generated DO.
|
|
224
|
+
* @experimental
|
|
225
|
+
*/
|
|
125
226
|
interface ContainerBindingSpec {
|
|
126
227
|
/** Durable Object binding name, e.g. `CONTAINER_TRANSCODER`. */
|
|
127
228
|
binding: string;
|
|
@@ -131,70 +232,90 @@ interface ContainerBindingSpec {
|
|
|
131
232
|
maxInstances?: number;
|
|
132
233
|
}
|
|
133
234
|
/**
|
|
134
|
-
* Build the `ctx.containers` record from the Worker `env`. Called by the
|
|
135
|
-
* generated ShardDO with the specs codegen derived from
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
235
|
+
* Build the `ctx.containers` record from the Worker `env`. Called by the
|
|
236
|
+
* generated ShardDO with the specs codegen derived from `lunora/containers.ts`.
|
|
237
|
+
* A missing binding doesn't throw here — only when the handle is actually used —
|
|
238
|
+
* so one unprovisioned container never breaks unrelated functions.
|
|
239
|
+
*
|
|
240
|
+
* `traceparent` (the inbound RPC's W3C trace context, forwarded by the runtime
|
|
241
|
+
* and read off the request by the DO) is stamped onto every outbound container
|
|
242
|
+
* `fetch`, so the container's own spans stitch under the Worker's trace.
|
|
243
|
+
* @experimental
|
|
244
|
+
*/
|
|
245
|
+
declare const createContainerContext: (env: Record<string, unknown>, specs: ReadonlyArray<ContainerBindingSpec>, jurisdiction?: DurableObjectJurisdiction, traceparent?: string) => Record<string, ContainerAccessor>;
|
|
246
|
+
/**
|
|
247
|
+
* A test handler: receives the request plus the targeted instance name.
|
|
248
|
+
* @experimental
|
|
249
|
+
*/
|
|
142
250
|
type ContainerTestHandler = (request: Request, instance: {
|
|
143
251
|
name: string;
|
|
144
252
|
}) => Promise<Response> | Response;
|
|
145
253
|
/**
|
|
146
|
-
* Docker-free test double for `ctx.containers`: each export name maps to a
|
|
147
|
-
* fetch handler that plays the container. Mirrors the real shape exactly, so
|
|
148
|
-
* action handlers under test can't tell the difference.
|
|
149
|
-
*
|
|
150
|
-
* ```ts
|
|
151
|
-
* const containers = createContainerTestContext({
|
|
152
|
-
* transcoder: (request) => new Response("ok"),
|
|
153
|
-
* });
|
|
154
|
-
* ```
|
|
155
|
-
|
|
254
|
+
* Docker-free test double for `ctx.containers`: each export name maps to a
|
|
255
|
+
* fetch handler that plays the container. Mirrors the real shape exactly, so
|
|
256
|
+
* action handlers under test can't tell the difference.
|
|
257
|
+
*
|
|
258
|
+
* ```ts
|
|
259
|
+
* const containers = createContainerTestContext({
|
|
260
|
+
* transcoder: (request) => new Response("ok"),
|
|
261
|
+
* });
|
|
262
|
+
* ```
|
|
263
|
+
* @experimental
|
|
264
|
+
*/
|
|
156
265
|
declare const createContainerTestContext: (handlers: Record<string, ContainerTestHandler>) => Record<string, ContainerAccessor>;
|
|
157
266
|
/**
|
|
158
|
-
* Normalize a `ContainerImageSource` into the shape wrangler wants: a
|
|
159
|
-
* Dockerfile path + build context for local builds, or a fully-qualified
|
|
160
|
-
* reference for pre-built images.
|
|
161
|
-
*
|
|
162
|
-
* A local-path string whose basename starts with `Dockerfile` (so
|
|
163
|
-
* `Dockerfile.dev` also counts) is used as-is with its directory as the build
|
|
164
|
-
* context; any other path is treated as the build-context directory and the
|
|
165
|
-
* Dockerfile is expected at `<dir>/Dockerfile`.
|
|
166
|
-
|
|
267
|
+
* Normalize a `ContainerImageSource` into the shape wrangler wants: a
|
|
268
|
+
* Dockerfile path + build context for local builds, or a fully-qualified
|
|
269
|
+
* reference for pre-built images.
|
|
270
|
+
*
|
|
271
|
+
* A local-path string whose basename starts with `Dockerfile` (so
|
|
272
|
+
* `Dockerfile.dev` also counts) is used as-is with its directory as the build
|
|
273
|
+
* context; any other path is treated as the build-context directory and the
|
|
274
|
+
* Dockerfile is expected at `<dir>/Dockerfile`.
|
|
275
|
+
* @experimental
|
|
276
|
+
*/
|
|
167
277
|
declare const normalizeContainerImage: (image: ContainerImageSource) => NormalizedContainerImage;
|
|
168
278
|
/**
|
|
169
|
-
* The generated Container DO class name for a `lunora/containers.ts` export:
|
|
170
|
-
* `transcoder` → `TranscoderContainer`. wrangler's `containers[].class_name`
|
|
171
|
-
* and the Durable Object binding's `class_name` both reference it, so codegen
|
|
172
|
-
* and the config layer MUST derive it identically — always via this helper.
|
|
173
|
-
|
|
279
|
+
* The generated Container DO class name for a `lunora/containers.ts` export:
|
|
280
|
+
* `transcoder` → `TranscoderContainer`. wrangler's `containers[].class_name`
|
|
281
|
+
* and the Durable Object binding's `class_name` both reference it, so codegen
|
|
282
|
+
* and the config layer MUST derive it identically — always via this helper.
|
|
283
|
+
* @experimental
|
|
284
|
+
*/
|
|
174
285
|
declare const containerClassName: (exportName: string) => string;
|
|
175
286
|
/**
|
|
176
|
-
* The Durable Object binding name for a container export: `transcoder` →
|
|
177
|
-
* `CONTAINER_TRANSCODER`, `imageResizer` → `CONTAINER_IMAGE_RESIZER`. The
|
|
178
|
-
* `CONTAINER_` prefix namespaces these away from `SHARD`/`SESSION`/`SCHEDULER`
|
|
179
|
-
* so a container export can never collide with the built-in bindings.
|
|
180
|
-
|
|
287
|
+
* The Durable Object binding name for a container export: `transcoder` →
|
|
288
|
+
* `CONTAINER_TRANSCODER`, `imageResizer` → `CONTAINER_IMAGE_RESIZER`. The
|
|
289
|
+
* `CONTAINER_` prefix namespaces these away from `SHARD`/`SESSION`/`SCHEDULER`
|
|
290
|
+
* so a container export can never collide with the built-in bindings.
|
|
291
|
+
* @experimental
|
|
292
|
+
*/
|
|
181
293
|
declare const containerBindingName: (exportName: string) => string;
|
|
182
294
|
/**
|
|
183
|
-
* The local image tag a Railpack `{ build }` container is built and pushed
|
|
184
|
-
* under: `transcoder` → `lunora-transcoder:build`. The config reconciler writes
|
|
185
|
-
* it as the wrangler `containers[].image`, and `lunora deploy` builds that tag
|
|
186
|
-
* with Railpack and `wrangler containers push`es it before deploying — so all
|
|
187
|
-
* three derive the tag from this one helper and can never disagree.
|
|
188
|
-
|
|
295
|
+
* The local image tag a Railpack `{ build }` container is built and pushed
|
|
296
|
+
* under: `transcoder` → `lunora-transcoder:build`. The config reconciler writes
|
|
297
|
+
* it as the wrangler `containers[].image`, and `lunora deploy` builds that tag
|
|
298
|
+
* with Railpack and `wrangler containers push`es it before deploying — so all
|
|
299
|
+
* three derive the tag from this one helper and can never disagree.
|
|
300
|
+
* @experimental
|
|
301
|
+
*/
|
|
189
302
|
declare const containerBuildTag: (exportName: string) => string;
|
|
303
|
+
/**
|
|
304
|
+
* `defineContainer` is part of the experimental `@lunora/container` API and may change without a major version bump.
|
|
305
|
+
* @experimental
|
|
306
|
+
*/
|
|
190
307
|
declare const defineContainer: (config: ContainerConfig) => ContainerDefinition;
|
|
191
|
-
/**
|
|
308
|
+
/**
|
|
309
|
+
* True when a value is a `defineContainer` result (the runtime brand check).
|
|
310
|
+
* @experimental
|
|
311
|
+
*/
|
|
192
312
|
declare const isContainerDefinition: (value: unknown) => value is ContainerDefinition;
|
|
193
313
|
/**
|
|
194
|
-
* The container's full environment at instance start: the static `env` block
|
|
195
|
-
* plus every declared secret resolved from the Worker `env`. A declared secret
|
|
196
|
-
* missing from the Worker env fails fast — starting the container without a
|
|
197
|
-
* credential it was promised yields far worse errors downstream.
|
|
198
|
-
|
|
314
|
+
* The container's full environment at instance start: the static `env` block
|
|
315
|
+
* plus every declared secret resolved from the Worker `env`. A declared secret
|
|
316
|
+
* missing from the Worker env fails fast — starting the container without a
|
|
317
|
+
* credential it was promised yields far worse errors downstream.
|
|
318
|
+
* @experimental
|
|
319
|
+
*/
|
|
199
320
|
declare const resolveContainerEnvVariables: (definition: ContainerDefinition, workerEnv: Record<string, unknown>, exportName?: string) => Record<string, string>;
|
|
200
|
-
export { type ContainerAccessor, type ContainerBindingSpec, type ContainerConfig, type ContainerDefinition, type ContainerHandle, type ContainerImageSource, type ContainerInstanceHandle, type ContainerInstanceState, type ContainerNamespaceLike, type ContainerStartOptions, type ContainerTestHandler, type DurableObjectJurisdiction, type NormalizedContainerImage, type PoolOptions, containerBindingName, containerBuildTag, containerClassName, createContainerContext, createContainerTestContext, defineContainer, isContainerDefinition, normalizeContainerImage, resolveContainerEnvVariables as resolveContainerEnvVars };
|
|
321
|
+
export { type ContainerAccessor, type ContainerBindingSpec, type ContainerConfig, type ContainerDefinition, type ContainerEgressControls, type ContainerHandle, type ContainerImageSource, type ContainerInstanceHandle, type ContainerInstanceState, type ContainerNamespaceLike, type ContainerStartOptions, type ContainerTestHandler, type DurableObjectJurisdiction, type InstanceRetryOptions, type NormalizedContainerImage, type PoolOptions, containerBindingName, containerBuildTag, containerClassName, createContainerContext, createContainerTestContext, defineContainer, isContainerDefinition, normalizeContainerImage, resolveContainerEnvVariables as resolveContainerEnvVars };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { containerBindingName, containerBuildTag, containerClassName, defineContainer, isContainerDefinition, normalizeContainerImage, resolveContainerEnvVars } from './packem_shared/containerBindingName-BGdSdFNA.mjs';
|
|
1
|
+
import{createContainerContext as t,createContainerTestContext as a}from"./packem_shared/createContainerContext-Df9Ev-Fp.mjs";import{containerBindingName as o,containerBuildTag as r,containerClassName as C,defineContainer as m,isContainerDefinition as s,normalizeContainerImage as c,resolveContainerEnvVars as f}from"./packem_shared/containerBindingName-DP2NqQV-.mjs";export{o as containerBindingName,r as containerBuildTag,C as containerClassName,t as createContainerContext,a as createContainerTestContext,m as defineContainer,s as isContainerDefinition,c as normalizeContainerImage,f as resolveContainerEnvVars};
|
package/dist/otel.d.mts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An attribute value carried on a span or log.
|
|
3
|
+
* @experimental
|
|
4
|
+
*/
|
|
5
|
+
type ContainerAttributeValue = boolean | number | string;
|
|
6
|
+
/**
|
|
7
|
+
* A `fetch` implementation — defaults to the runtime global. The exporter passes
|
|
8
|
+
* an abort `signal` (for the per-request timeout) and, once the promise settles,
|
|
9
|
+
* cancels the response `body` so Node/undici can release the socket for
|
|
10
|
+
* keep-alive reuse instead of leaving it occupied by an unread stream. It reads
|
|
11
|
+
* `ok`/`status` to detect a rejected export and nothing else from the response.
|
|
12
|
+
* @experimental
|
|
13
|
+
*/
|
|
14
|
+
type OtelFetchLike = (input: string, init: {
|
|
15
|
+
body: string;
|
|
16
|
+
headers: Record<string, string>;
|
|
17
|
+
method: string;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}) => Promise<{
|
|
20
|
+
body?: {
|
|
21
|
+
cancel: () => Promise<void>;
|
|
22
|
+
} | null;
|
|
23
|
+
ok: boolean;
|
|
24
|
+
status: number;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* A single span the container process asks the exporter to record.
|
|
28
|
+
* @experimental
|
|
29
|
+
*/
|
|
30
|
+
interface ContainerSpanInput {
|
|
31
|
+
/** Attributes attached to the span (rendered under the OTLP `attributes` list). */
|
|
32
|
+
attributes?: Record<string, ContainerAttributeValue>;
|
|
33
|
+
/** Wall-clock millis when the operation ended. */
|
|
34
|
+
endMs: number;
|
|
35
|
+
/** When set, the span is marked errored with this message (and optional `error.type`). */
|
|
36
|
+
error?: {
|
|
37
|
+
message: string;
|
|
38
|
+
type?: string;
|
|
39
|
+
};
|
|
40
|
+
/** Span name — the operation being timed, e.g. `"transcode"`. */
|
|
41
|
+
name: string;
|
|
42
|
+
/** Wall-clock millis when the operation started. */
|
|
43
|
+
startMs: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A single log line the container process asks the exporter to record.
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
49
|
+
interface ContainerLogInput {
|
|
50
|
+
/** Attributes attached to the log record. */
|
|
51
|
+
attributes?: Record<string, ContainerAttributeValue>;
|
|
52
|
+
/** Severity — defaults to `"info"`. */
|
|
53
|
+
level?: "debug" | "error" | "info" | "warn";
|
|
54
|
+
/** The log message body. */
|
|
55
|
+
message: string;
|
|
56
|
+
/** Wall-clock millis the line was emitted; defaults to now. */
|
|
57
|
+
ts?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Options for {@link createContainerTelemetry}.
|
|
61
|
+
* @experimental
|
|
62
|
+
*/
|
|
63
|
+
interface ContainerTelemetryOptions {
|
|
64
|
+
/**
|
|
65
|
+
* Value of the `deployment.environment` resource attribute. Falls back to
|
|
66
|
+
* the `DEPLOYMENT_ENVIRONMENT` / `ENVIRONMENT` / `NODE_ENV` env vars **only
|
|
67
|
+
* when {@link ContainerTelemetryOptions.detectResources} is `true`** —
|
|
68
|
+
* unlike `serviceName`, env detection here is opt-in so a stray `NODE_ENV`
|
|
69
|
+
* never silently labels a deployment.
|
|
70
|
+
*/
|
|
71
|
+
deploymentEnvironment?: string;
|
|
72
|
+
/**
|
|
73
|
+
* When `true`, auto-detect OTLP resource attributes from the container
|
|
74
|
+
* environment (`HOSTNAME`, `KUBERNETES_*`, `SERVICE_VERSION`, etc.).
|
|
75
|
+
* Explicit options and `resourceAttributes` win on collision.
|
|
76
|
+
*/
|
|
77
|
+
detectResources?: boolean;
|
|
78
|
+
/** Base OTLP collector endpoint; defaults to the `LUNORA_OTLP_ENDPOINT` env var. */
|
|
79
|
+
endpoint?: string;
|
|
80
|
+
/** Injectable `fetch` (tests / non-global runtimes). Defaults to `globalThis.fetch`. */
|
|
81
|
+
fetch?: OtelFetchLike;
|
|
82
|
+
/** Extra headers merged onto every POST — e.g. deployment/org correlation. `content-type` is set by default. */
|
|
83
|
+
headers?: Record<string, string>;
|
|
84
|
+
/** Called with any send failure so the caller can surface it; the export itself always swallows. */
|
|
85
|
+
onError?: (error: unknown) => void;
|
|
86
|
+
/** Additional resource attributes merged onto every signal. */
|
|
87
|
+
resourceAttributes?: Record<string, ContainerAttributeValue>;
|
|
88
|
+
/** `service.name` resource attribute; defaults to the `LUNORA_SERVICE_NAME` env var then `"lunora-container"`. */
|
|
89
|
+
serviceName?: string;
|
|
90
|
+
/**
|
|
91
|
+
* `service.version` resource attribute. Falls back to `SERVICE_VERSION` /
|
|
92
|
+
* `CF_VERSION_METADATA` / `VERCEL_GIT_COMMIT_SHA` / `GITHUB_SHA` /
|
|
93
|
+
* `COMMIT_SHA` env vars **only when
|
|
94
|
+
* {@link ContainerTelemetryOptions.detectResources} is `true`**.
|
|
95
|
+
*/
|
|
96
|
+
serviceVersion?: string;
|
|
97
|
+
/** Per-POST timeout in ms; a collector that never responds aborts after this so a stuck send can't stall `flush()`. Defaults to {@link DEFAULT_TIMEOUT_MS} (10s). */
|
|
98
|
+
timeoutMs?: number;
|
|
99
|
+
/** Bearer token sent as an `Authorization: Bearer` header; defaults to the `LUNORA_OTLP_TOKEN` env var. */
|
|
100
|
+
token?: string;
|
|
101
|
+
/**
|
|
102
|
+
* W3C `traceparent` of the Worker RPC that invoked this container; defaults to
|
|
103
|
+
* the `LUNORA_TRACEPARENT` env var. When present (and well-formed) every span
|
|
104
|
+
* inherits its trace id and hangs off its span id, so container spans stitch
|
|
105
|
+
* under the Worker's trace instead of forming a fresh, disconnected trace.
|
|
106
|
+
*
|
|
107
|
+
* `@lunora/container` stamps this trace context as the **`traceparent` request
|
|
108
|
+
* header** on every proxied fetch (`ctx.containers.<name>.…`), so a container
|
|
109
|
+
* that serves many requests should read it per request and create a telemetry
|
|
110
|
+
* instance scoped to that request — the trace context differs each call, so a
|
|
111
|
+
* single process-lifetime instance can't carry it:
|
|
112
|
+
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* // inside the container's request handler
|
|
115
|
+
* const telemetry = createContainerTelemetry({ traceparent: request.headers.get("traceparent") ?? undefined });
|
|
116
|
+
* await telemetry.trace("transcode", () => transcode(job));
|
|
117
|
+
* await telemetry.flush();
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* The `LUNORA_TRACEPARENT` env fallback fits a one-shot container that
|
|
121
|
+
* processes a single job per start (the value is fixed for the process).
|
|
122
|
+
*/
|
|
123
|
+
traceparent?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The exporter handle {@link createContainerTelemetry} returns.
|
|
127
|
+
* @experimental
|
|
128
|
+
*/
|
|
129
|
+
interface ContainerTelemetry {
|
|
130
|
+
/** Record one log line (no-op when disabled). */
|
|
131
|
+
emitLog: (log: ContainerLogInput) => void;
|
|
132
|
+
/** Record one span (no-op when disabled). */
|
|
133
|
+
emitSpan: (span: ContainerSpanInput) => void;
|
|
134
|
+
/** True when an endpoint resolved and exports are actually sent. */
|
|
135
|
+
readonly enabled: boolean;
|
|
136
|
+
/** Await all in-flight sends — call before the process exits. */
|
|
137
|
+
flush: () => Promise<void>;
|
|
138
|
+
/** Time `run()`, recording a span named `name` (ok, or errored if it throws). Always runs `run()`, even when disabled. */
|
|
139
|
+
trace: <T>(name: string, run: () => Promise<T>, attributes?: Record<string, ContainerAttributeValue>) => Promise<T>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Create a zero-config OTLP exporter for the container process.
|
|
143
|
+
*
|
|
144
|
+
* ```ts
|
|
145
|
+
* const telemetry = createContainerTelemetry(); // reads LUNORA_OTLP_ENDPOINT / _TOKEN
|
|
146
|
+
* await telemetry.trace("transcode", () => transcode(job), { jobId: job.id });
|
|
147
|
+
* telemetry.emitLog({ level: "info", message: "done", attributes: { jobId: job.id } });
|
|
148
|
+
* await telemetry.flush(); // before the process exits
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* With no endpoint resolvable the returned exporter is disabled (`enabled ===
|
|
152
|
+
* false`): `emitSpan`/`emitLog` no-op and `trace` still runs its work but records
|
|
153
|
+
* nothing — so the same code runs unchanged locally and in the cloud.
|
|
154
|
+
* @param options Exporter options. Connection fields (`endpoint`, `token`,
|
|
155
|
+
* `serviceName`, `traceparent`) always fall back to their `LUNORA_*` env var;
|
|
156
|
+
* resource fields (`serviceVersion`, `deploymentEnvironment`) only do so under
|
|
157
|
+
* `detectResources: true`.
|
|
158
|
+
* @experimental
|
|
159
|
+
*/
|
|
160
|
+
declare const createContainerTelemetry: (options?: ContainerTelemetryOptions) => ContainerTelemetry;
|
|
161
|
+
export { type ContainerAttributeValue, type ContainerLogInput, type ContainerSpanInput, type ContainerTelemetry, type ContainerTelemetryOptions, type OtelFetchLike, createContainerTelemetry };
|