@lunora/container 1.0.0-alpha.4 → 1.0.0-alpha.5

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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as ContainerConfig, C as ContainerDefinition, b as ContainerImageSource, N as NormalizedContainerImage } from "./packem_shared/types.d-DAOLRiZQ.mjs";
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/types.d-DAOLRiZQ.mjs";
1
+ import { C as ContainerConfig, a as ContainerDefinition, b as ContainerImageSource, N as NormalizedContainerImage } from "./packem_shared/types.d-BlNwNY44.mjs";
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/types.d-BlNwNY44.mjs";
3
3
  /**
4
4
  * The `ctx.containers` action surface: typed handles over the `CONTAINER_*`
5
5
  * Durable Object namespace bindings the config layer reconciles.
@@ -101,9 +101,12 @@ interface ContainerInstanceHandle extends ContainerHandle {
101
101
  getState: () => Promise<ContainerInstanceState>;
102
102
  /**
103
103
  * Reset the instance's `sleepAfter` idle timer. The platform renews it on
104
- * each request automatically, but WebSocket message activity does not yet
105
- * renew it (cloudflare/containers#147) call this on inbound WS traffic to
106
- * keep a busy socket's container awake.
104
+ * each proxied request, and because `@lunora/container` proxies WebSocket
105
+ * frames through the Durable Object, message traffic on an open socket
106
+ * renews it too (the WebSocket-keepalive gap of cloudflare/containers#147 is
107
+ * closed in the bundled base). This manual control is the escape hatch for
108
+ * keeping a container awake during activity that is neither an HTTP request
109
+ * nor a WS message — e.g. a long out-of-band job running inside it.
107
110
  */
108
111
  renewActivityTimeout: () => Promise<void>;
109
112
  /** Explicitly start the instance, optionally with per-instance env/entrypoint. */
@@ -137,10 +140,25 @@ interface ContainerAccessor {
137
140
  * A random instance from a fixed pool of `count` (defaults to the
138
141
  * definition's `maxInstances`, else 3 — mirroring `getRandom` from
139
142
  * `@cloudflare/containers`). For stateless, interchangeable workloads.
143
+ *
144
+ * Like `.get()`, a path/URL-string fetch transparently retries the
145
+ * cold-start "instance is provisioning" transients (cloudflare/containers#45,
146
+ * #139); pass {@link InstanceRetryOptions} to tune or disable it.
147
+ */
148
+ any: (count?: number, options?: InstanceRetryOptions) => ContainerHandle;
149
+ /**
150
+ * The instance for `name` — one container per entity (user, room, job…),
151
+ * with lifecycle control.
152
+ *
153
+ * A path/URL-string fetch transparently retries the platform's cold-start
154
+ * transients — "there is no Container instance available" / "container is
155
+ * not listening" while an instance is still provisioning
156
+ * (cloudflare/containers#45, #139) — on the *same* instance with backoff,
157
+ * since the request never reached the app. Pass {@link InstanceRetryOptions}
158
+ * to tune attempts/backoff or disable it (`{ attempts: 1 }`). A pre-built
159
+ * `Request` (possibly a one-shot stream body) is sent once, never retried.
140
160
  */
141
- any: (count?: number) => ContainerHandle;
142
- /** The instance for `name` — one container per entity (user, room, job…), with lifecycle control. */
143
- get: (name: string) => ContainerInstanceHandle;
161
+ get: (name: string, options?: InstanceRetryOptions) => ContainerInstanceHandle;
144
162
  /**
145
163
  * A resilient handle over the pool: each `fetch` picks a random instance and,
146
164
  * on a thrown error or a retryable response (5xx by default), retries on a
@@ -177,6 +195,24 @@ interface PoolOptions {
177
195
  /** Pool size to spread picks across. Defaults to the definition's `maxInstances`, else 3. */
178
196
  size?: number;
179
197
  }
198
+ /**
199
+ * Tuning for the cold-start retry on a `.get()`/`.any()` handle. The retry fires
200
+ * only on the platform's provisioning transients (no-instance / not-listening /
201
+ * rate-limited — see {@link isColdStartTransient}), which is why it's safe by
202
+ * default: those responses mean the request never reached the container.
203
+ */
204
+ interface InstanceRetryOptions {
205
+ /**
206
+ * Total attempts on a cold-start transient before the last outcome is
207
+ * surfaced as-is. `1` disables the retry. Default
208
+ * {@link DEFAULT_COLD_START_ATTEMPTS}.
209
+ */
210
+ attempts?: number;
211
+ /** Base backoff in ms between attempts; doubles each retry (0 disables the wait). Default {@link DEFAULT_COLD_START_BACKOFF_MS}. */
212
+ backoffMs?: number;
213
+ /** Upper bound on a single backoff sleep, in ms. Default {@link DEFAULT_MAX_BACKOFF_MS} (30s). */
214
+ maxBackoffMs?: number;
215
+ }
180
216
  /** Wiring info for one definition, emitted by codegen into the generated DO. */
181
217
  interface ContainerBindingSpec {
182
218
  /** Durable Object binding name, e.g. `CONTAINER_TRANSCODER`. */
@@ -253,4 +289,4 @@ declare const isContainerDefinition: (value: unknown) => value is ContainerDefin
253
289
  * credential it was promised yields far worse errors downstream.
254
290
  */
255
291
  declare const resolveContainerEnvVariables: (definition: ContainerDefinition, workerEnv: Record<string, unknown>, exportName?: string) => Record<string, string>;
256
- 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 NormalizedContainerImage, type PoolOptions, containerBindingName, containerBuildTag, containerClassName, createContainerContext, createContainerTestContext, defineContainer, isContainerDefinition, normalizeContainerImage, resolveContainerEnvVariables as resolveContainerEnvVars };
292
+ 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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as ContainerConfig, C as ContainerDefinition, b as ContainerImageSource, N as NormalizedContainerImage } from "./packem_shared/types.d-DAOLRiZQ.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/types.d-DAOLRiZQ.js";
1
+ import { C as ContainerConfig, a as ContainerDefinition, b as ContainerImageSource, N as NormalizedContainerImage } from "./packem_shared/types.d-BlNwNY44.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/types.d-BlNwNY44.js";
3
3
  /**
4
4
  * The `ctx.containers` action surface: typed handles over the `CONTAINER_*`
5
5
  * Durable Object namespace bindings the config layer reconciles.
@@ -101,9 +101,12 @@ interface ContainerInstanceHandle extends ContainerHandle {
101
101
  getState: () => Promise<ContainerInstanceState>;
102
102
  /**
103
103
  * Reset the instance's `sleepAfter` idle timer. The platform renews it on
104
- * each request automatically, but WebSocket message activity does not yet
105
- * renew it (cloudflare/containers#147) call this on inbound WS traffic to
106
- * keep a busy socket's container awake.
104
+ * each proxied request, and because `@lunora/container` proxies WebSocket
105
+ * frames through the Durable Object, message traffic on an open socket
106
+ * renews it too (the WebSocket-keepalive gap of cloudflare/containers#147 is
107
+ * closed in the bundled base). This manual control is the escape hatch for
108
+ * keeping a container awake during activity that is neither an HTTP request
109
+ * nor a WS message — e.g. a long out-of-band job running inside it.
107
110
  */
108
111
  renewActivityTimeout: () => Promise<void>;
109
112
  /** Explicitly start the instance, optionally with per-instance env/entrypoint. */
@@ -137,10 +140,25 @@ interface ContainerAccessor {
137
140
  * A random instance from a fixed pool of `count` (defaults to the
138
141
  * definition's `maxInstances`, else 3 — mirroring `getRandom` from
139
142
  * `@cloudflare/containers`). For stateless, interchangeable workloads.
143
+ *
144
+ * Like `.get()`, a path/URL-string fetch transparently retries the
145
+ * cold-start "instance is provisioning" transients (cloudflare/containers#45,
146
+ * #139); pass {@link InstanceRetryOptions} to tune or disable it.
147
+ */
148
+ any: (count?: number, options?: InstanceRetryOptions) => ContainerHandle;
149
+ /**
150
+ * The instance for `name` — one container per entity (user, room, job…),
151
+ * with lifecycle control.
152
+ *
153
+ * A path/URL-string fetch transparently retries the platform's cold-start
154
+ * transients — "there is no Container instance available" / "container is
155
+ * not listening" while an instance is still provisioning
156
+ * (cloudflare/containers#45, #139) — on the *same* instance with backoff,
157
+ * since the request never reached the app. Pass {@link InstanceRetryOptions}
158
+ * to tune attempts/backoff or disable it (`{ attempts: 1 }`). A pre-built
159
+ * `Request` (possibly a one-shot stream body) is sent once, never retried.
140
160
  */
141
- any: (count?: number) => ContainerHandle;
142
- /** The instance for `name` — one container per entity (user, room, job…), with lifecycle control. */
143
- get: (name: string) => ContainerInstanceHandle;
161
+ get: (name: string, options?: InstanceRetryOptions) => ContainerInstanceHandle;
144
162
  /**
145
163
  * A resilient handle over the pool: each `fetch` picks a random instance and,
146
164
  * on a thrown error or a retryable response (5xx by default), retries on a
@@ -177,6 +195,24 @@ interface PoolOptions {
177
195
  /** Pool size to spread picks across. Defaults to the definition's `maxInstances`, else 3. */
178
196
  size?: number;
179
197
  }
198
+ /**
199
+ * Tuning for the cold-start retry on a `.get()`/`.any()` handle. The retry fires
200
+ * only on the platform's provisioning transients (no-instance / not-listening /
201
+ * rate-limited — see {@link isColdStartTransient}), which is why it's safe by
202
+ * default: those responses mean the request never reached the container.
203
+ */
204
+ interface InstanceRetryOptions {
205
+ /**
206
+ * Total attempts on a cold-start transient before the last outcome is
207
+ * surfaced as-is. `1` disables the retry. Default
208
+ * {@link DEFAULT_COLD_START_ATTEMPTS}.
209
+ */
210
+ attempts?: number;
211
+ /** Base backoff in ms between attempts; doubles each retry (0 disables the wait). Default {@link DEFAULT_COLD_START_BACKOFF_MS}. */
212
+ backoffMs?: number;
213
+ /** Upper bound on a single backoff sleep, in ms. Default {@link DEFAULT_MAX_BACKOFF_MS} (30s). */
214
+ maxBackoffMs?: number;
215
+ }
180
216
  /** Wiring info for one definition, emitted by codegen into the generated DO. */
181
217
  interface ContainerBindingSpec {
182
218
  /** Durable Object binding name, e.g. `CONTAINER_TRANSCODER`. */
@@ -253,4 +289,4 @@ declare const isContainerDefinition: (value: unknown) => value is ContainerDefin
253
289
  * credential it was promised yields far worse errors downstream.
254
290
  */
255
291
  declare const resolveContainerEnvVariables: (definition: ContainerDefinition, workerEnv: Record<string, unknown>, exportName?: string) => Record<string, string>;
256
- 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 NormalizedContainerImage, type PoolOptions, containerBindingName, containerBuildTag, containerClassName, createContainerContext, createContainerTestContext, defineContainer, isContainerDefinition, normalizeContainerImage, resolveContainerEnvVariables as resolveContainerEnvVars };
292
+ 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,2 @@
1
- export { createContainerContext, createContainerTestContext } from './packem_shared/createContainerContext-DBp8oJOr.mjs';
2
- export { containerBindingName, containerBuildTag, containerClassName, defineContainer, isContainerDefinition, normalizeContainerImage, resolveContainerEnvVars } from './packem_shared/containerBindingName-C7Lic2ET.mjs';
1
+ export { createContainerContext, createContainerTestContext } from './packem_shared/createContainerContext-BtzK5gJL.mjs';
2
+ export { containerBindingName, containerBuildTag, containerClassName, defineContainer, isContainerDefinition, normalizeContainerImage, resolveContainerEnvVars } from './packem_shared/containerBindingName-CWmEE_3Y.mjs';