@fluojs/platform-cloudflare-workers 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ko.md CHANGED
@@ -29,7 +29,7 @@ fluo 애플리케이션을 [Cloudflare Workers](https://workers.cloudflare.com/)
29
29
 
30
30
  이 어댑터는 각 요청 수명주기를 `executionContext.waitUntil(...)`에 연결하고, `close()` 중에도 진행 중인 디스패치를 유지하여 Worker 종료 도중 활성 작업이 중간에 잘리지 않도록 보장합니다.
31
31
 
32
- 애플리케이션 종료 중에는 즉시 새 ingress 수락을 중단하고, 활성 HTTP 핸들러가 정리될 수 있도록 최대 10초의 bounded drain window를 제공합니다. 이 시간을 넘기면 `close()`는 무기한 대기하지 않고 timeout 오류로 종료됩니다.
32
+ 애플리케이션 종료 중에는 즉시 새 ingress 수락을 중단하고, 활성 HTTP 핸들러가 정리될 수 있도록 최대 10초의 bounded drain window를 제공합니다. 이 시간을 넘기면 `close()`는 무기한 대기하지 않고 timeout 오류로 종료됩니다. 해당 drain이 아직 진행 중일 때 동시에 `listen()`을 호출하면 Worker를 다시 열지 않고 `Cloudflare Workers adapter cannot listen while shutdown is still draining.` 오류로 reject됩니다. 닫힌 뒤에는 어댑터가 명시적으로 다시 `listen()`될 때까지 후속 HTTP 및 WebSocket upgrade request가 동일한 JSON `503` shutdown response를 받습니다.
33
33
 
34
34
  ## 빠른 시작
35
35
 
@@ -87,14 +87,15 @@ const adapter = createCloudflareWorkerAdapter({
87
87
 
88
88
  ### 동작 참고
89
89
 
90
- - `fetch()`는 active work를 `executionContext.waitUntil(...)`에 등록합니다.
91
- - `close()`는 shutdown 요청에 JSON `503` response를 반환하고, active request 끝나지 않으면 10초 뒤 timeout됩니다.
90
+ - `fetch()`는 `listen()`이 dispatcher를 binding한 뒤 active work를 `executionContext.waitUntil(...)`에 등록합니다.
91
+ - WebSocket upgrade는 HTTP dispatch와 같은 listen boundary가 소유합니다. `listen()` 전의 upgrade request 설정된 binding에 도달하지 않습니다.
92
+ - `close()`는 shutdown 중 및 shutdown 이후 새 요청에 JSON `503` response를 반환하고, active request가 끝나지 않으면 10초 뒤 timeout됩니다. 해당 close drain이 아직 활성 상태일 때 `listen()`을 호출하면 Cloudflare Workers adapter shutdown-draining 오류로 reject됩니다.
92
93
  - Multipart request는 `rawBody`를 보존하지 않습니다.
93
94
  - Worker `env` 객체는 fetch entrypoint boundary를 통과하며, package-level config resolution은 application이 소유합니다.
94
95
 
95
96
  ## Conformance 커버리지
96
97
 
97
- `packages/platform-cloudflare-workers/src/adapter.test.ts`는 문서화된 Worker 계약을 검증하는 package-local regression 대상입니다. 이 파일은 shared Web dispatch delegation, `executionContext.waitUntil(...)` 등록, websocket upgrade binding, lazy entrypoint 재사용, shutdown gating, close 중 JSON `503` response, bounded 10초 close timeout을 검증합니다.
98
+ `packages/platform-cloudflare-workers/src/adapter.test.ts`는 문서화된 Worker 계약을 검증하는 package-local regression 대상입니다. 이 파일은 shared Web dispatch delegation, `executionContext.waitUntil(...)` 등록, websocket upgrade binding, listen-bound upgrade ownership, lazy entrypoint 재사용, shutdown gating, drain 중 `listen()` rejection, close 중 및 close 이후 JSON `503` response, bounded 10초 close timeout을 검증합니다.
98
99
 
99
100
  공유 edge portability suite인 `packages/testing/src/portability/web-runtime-adapter-portability.test.ts`는 Cloudflare Workers를 Bun 및 Deno와 함께 실행해 malformed cookie 보존, query decoding, JSON/text raw-body capture, multipart raw-body 제외, SSE framing을 검증합니다. 패키지 테스트의 README parity assertion은 이 edge-runtime 커버리지 문서가 한국어 mirror와 계속 동기화되도록 확인합니다.
100
101
 
@@ -104,6 +105,8 @@ const adapter = createCloudflareWorkerAdapter({
104
105
  - `createCloudflareWorkerEntrypoint(module, options)`: 지연 부트스트랩 방식의 Worker 엔트리포인트를 생성합니다.
105
106
  - `bootstrapCloudflareWorkerApplication(module, options)`: Worker를 위한 비동기 부트스트랩 헬퍼입니다.
106
107
  - `CloudflareWorkerHttpApplicationAdapter`: 핵심 어댑터 구현 클래스입니다.
108
+ - `CloudflareWorkerHandler`: Worker application wrapper와 lazy entrypoint가 공유하는 fetch handler interface입니다.
109
+ - `CloudflareWorkerApplication`: `adapter`, `app`, `fetch(...)`, `close(...)`를 제공하는 fully bootstrapped Worker application wrapper입니다.
107
110
  - `CloudflareWorkerEntrypoint`: `fetch`, `ready()`, `close()` lifecycle method를 제공하는 lazy entrypoint입니다.
108
111
  - Option 및 type: `CloudflareWorkerAdapterOptions`, `BootstrapCloudflareWorkerApplicationOptions`, `CloudflareWorkerExecutionContext`, `CloudflareWorkerWebSocketBinding`, Worker websocket pair/upgrade type.
109
112
 
package/README.md CHANGED
@@ -29,7 +29,7 @@ Use this package when deploying fluo applications to [Cloudflare Workers](https:
29
29
 
30
30
  The adapter binds each request lifecycle to `executionContext.waitUntil(...)` and keeps in-flight dispatches alive during `close()` so Worker shutdown does not drop active work mid-request.
31
31
 
32
- During application shutdown, the adapter stops accepting new ingress immediately and gives active HTTP handlers a bounded 10-second drain window before `close()` fails with a timeout instead of hanging indefinitely.
32
+ During application shutdown, the adapter stops accepting new ingress immediately and gives active HTTP handlers a bounded 10-second drain window before `close()` fails with a timeout instead of hanging indefinitely. While that drain is still in progress, a concurrent `listen()` call rejects with `Cloudflare Workers adapter cannot listen while shutdown is still draining.` instead of reopening the Worker. Once closed, follow-up HTTP and WebSocket upgrade requests receive the same JSON `503` shutdown response until the adapter is explicitly listened again.
33
33
 
34
34
  ## Quick Start
35
35
 
@@ -87,14 +87,15 @@ const adapter = createCloudflareWorkerAdapter({
87
87
 
88
88
  ### Behavior Notes
89
89
 
90
- - `fetch()` registers active work with `executionContext.waitUntil(...)`.
91
- - `close()` returns JSON `503` responses for new requests during shutdown and times out after 10 seconds if active requests never settle.
90
+ - `fetch()` registers active work with `executionContext.waitUntil(...)` after `listen()` binds the dispatcher.
91
+ - WebSocket upgrades are owned by the same listen boundary as HTTP dispatch; upgrade requests before `listen()` do not reach the configured binding.
92
+ - `close()` returns JSON `503` responses for new requests during and after shutdown and times out after 10 seconds if active requests never settle. Calling `listen()` while that close drain is still active rejects with the Cloudflare Workers adapter shutdown-draining error.
92
93
  - Multipart requests do not preserve `rawBody`.
93
94
  - The Worker `env` object is passed through the fetch entrypoint boundary; package-level config resolution remains application-owned.
94
95
 
95
96
  ## Conformance Coverage
96
97
 
97
- `packages/platform-cloudflare-workers/src/adapter.test.ts` is the package-local regression target for the documented Worker contract. It covers shared Web dispatch delegation, `executionContext.waitUntil(...)` registration, websocket upgrade binding, lazy entrypoint reuse, shutdown gating, JSON `503` responses while closing, and the bounded 10-second close timeout.
98
+ `packages/platform-cloudflare-workers/src/adapter.test.ts` is the package-local regression target for the documented Worker contract. It covers shared Web dispatch delegation, `executionContext.waitUntil(...)` registration, websocket upgrade binding, listen-bound upgrade ownership, lazy entrypoint reuse, shutdown gating, drain-time `listen()` rejection, JSON `503` responses while closing and after close, and the bounded 10-second close timeout.
98
99
 
99
100
  The shared edge portability suite in `packages/testing/src/portability/web-runtime-adapter-portability.test.ts` exercises Cloudflare Workers beside Bun and Deno for malformed cookie preservation, query decoding, JSON/text raw-body capture, multipart raw-body exclusion, and SSE framing. The README parity assertion in the package test keeps these documented edge-runtime coverage claims synchronized with the Korean mirror.
100
101
 
@@ -104,6 +105,8 @@ The shared edge portability suite in `packages/testing/src/portability/web-runti
104
105
  - `createCloudflareWorkerEntrypoint(module, options)`: Creates a lazy-bootstrapping Worker entrypoint.
105
106
  - `bootstrapCloudflareWorkerApplication(module, options)`: Async bootstrap helper for Workers.
106
107
  - `CloudflareWorkerHttpApplicationAdapter`: The core adapter implementation.
108
+ - `CloudflareWorkerHandler`: Fetch handler interface shared by Worker application wrappers and lazy entrypoints.
109
+ - `CloudflareWorkerApplication`: Fully bootstrapped Worker application wrapper with `adapter`, `app`, `fetch(...)`, and `close(...)`.
107
110
  - `CloudflareWorkerEntrypoint`: Lazy entrypoint with `fetch`, `ready()`, and `close()` lifecycle methods.
108
111
  - Options and types: `CloudflareWorkerAdapterOptions`, `BootstrapCloudflareWorkerApplicationOptions`, `CloudflareWorkerExecutionContext`, `CloudflareWorkerWebSocketBinding`, and Worker websocket pair/upgrade types.
109
112
 
package/dist/adapter.d.ts CHANGED
@@ -74,6 +74,7 @@ export declare class CloudflareWorkerHttpApplicationAdapter implements HttpAppli
74
74
  private dispatcher?;
75
75
  private inFlightDrain?;
76
76
  private inFlightRequestCount;
77
+ private isClosed;
77
78
  private websocketBinding?;
78
79
  private readonly options;
79
80
  private readonly webRequestResponseFactory;
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,sBAAsB,EAC5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,KAAK,sCAAsC,EAC5C,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAGL,KAAK,sCAAsC,EAC5C,MAAM,qBAAqB,CAAC;AAE7B,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,gBAAgB;QACxB,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;QACvB,OAAO,CAAC,EAAE,UAAU,CAAC;KACtB;CACF;AAMD,oEAAoE;AACpE,MAAM,WAAW,gCAAgC;IAC/C,sBAAsB,CAAC,IAAI,IAAI,CAAC;IAChC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5C;AAED,iEAAiE;AACjE,MAAM,MAAM,gCAAgC,GAAG,WAAW,GAAG,eAAe,GAAG,IAAI,GAAG,MAAM,CAAC;AAE7F,kFAAkF;AAClF,MAAM,WAAW,yBACf,SAAQ,IAAI,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,GAAG,qBAAqB,GAAG,MAAM,CAAC;IACtF,QAAQ,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AAG,EACV,gBAAgB,CAAC,EAAE,gCAAgC,GAClD,OAAO,CAAC,QAAQ,CAAC;IAgCd,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IASnD,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,oBAAoB;YAqBd,uBAAuB;CAOtC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,8BAAmC,GAC3C,sCAAsC,CAExC;AAED;;;;;;GAMG;AACH,wBAAsB,oCAAoC,CAAC,GAAG,GAAG,OAAO,EACtE,UAAU,EAAE,UAAU,EACtB,OAAO,GAAE,2CAAgD,GACxD,OAAO,CAAC,2BAA2B,CAAC,GAAG,CAAC,CAAC,CAe3C;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,GAAG,GAAG,OAAO,EAC5D,UAAU,EAAE,UAAU,EACtB,OAAO,GAAE,2CAAgD,GACxD,0BAA0B,CAAC,GAAG,CAAC,CA6DjC;AAmGD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,YAAY;QACpB,SAAS,CAAC,EAAE,yBAAyB,CAAC;KACvC;IAED,UAAU,UAAU;QAClB,aAAa,CAAC,EAAE,UAAU,6BAA6B,CAAC;KACzD;CACF"}
package/dist/adapter.js CHANGED
@@ -40,6 +40,7 @@ export class CloudflareWorkerHttpApplicationAdapter {
40
40
  dispatcher;
41
41
  inFlightDrain;
42
42
  inFlightRequestCount = 0;
43
+ isClosed = false;
43
44
  websocketBinding;
44
45
  options;
45
46
  webRequestResponseFactory;
@@ -53,8 +54,10 @@ export class CloudflareWorkerHttpApplicationAdapter {
53
54
  return;
54
55
  }
55
56
  if (!this.dispatcher) {
57
+ this.isClosed = true;
56
58
  return;
57
59
  }
60
+ this.isClosed = true;
58
61
  const closeInFlight = this.waitForInFlightRequests().finally(() => {
59
62
  this.closeInFlight = undefined;
60
63
  this.dispatcher = undefined;
@@ -72,19 +75,20 @@ export class CloudflareWorkerHttpApplicationAdapter {
72
75
  this.websocketBinding = binding;
73
76
  }
74
77
  async fetch(request, _env, executionContext) {
75
- if (this.closeInFlight) {
78
+ if (this.closeInFlight || this.isClosed) {
76
79
  return createShutdownResponse();
77
80
  }
78
81
  const release = this.trackInFlightRequest();
79
82
  const responsePromise = (async () => {
80
83
  try {
81
- if (this.websocketBinding && isWebSocketUpgradeRequest(request)) {
84
+ const dispatcher = this.dispatcher;
85
+ if (dispatcher && this.websocketBinding && isWebSocketUpgradeRequest(request)) {
82
86
  return await this.websocketBinding.fetch(request, {
83
87
  upgrade: upgradeRequest => this.upgradeWebSocket(upgradeRequest)
84
88
  });
85
89
  }
86
90
  return await dispatchWebRequest({
87
- dispatcher: this.dispatcher,
91
+ dispatcher,
88
92
  dispatcherNotReadyMessage: WORKER_DISPATCHER_NOT_READY_MESSAGE,
89
93
  factory: this.webRequestResponseFactory,
90
94
  request
@@ -97,6 +101,10 @@ export class CloudflareWorkerHttpApplicationAdapter {
97
101
  return await responsePromise;
98
102
  }
99
103
  async listen(dispatcher) {
104
+ if (this.closeInFlight) {
105
+ throw new Error('Cloudflare Workers adapter cannot listen while shutdown is still draining.');
106
+ }
107
+ this.isClosed = false;
100
108
  this.dispatcher = dispatcher;
101
109
  }
102
110
  upgradeWebSocket(_request) {
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "platform",
10
10
  "fetch"
11
11
  ],
12
- "version": "1.0.0",
12
+ "version": "1.0.2",
13
13
  "private": false,
14
14
  "license": "MIT",
15
15
  "repository": {
@@ -34,7 +34,7 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@fluojs/http": "^1.0.0",
37
- "@fluojs/runtime": "^1.0.0"
37
+ "@fluojs/runtime": "^1.1.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "vitest": "^3.2.4"