@zeltjs/adapter-cloudflare-workers 0.12.0-canary.1 → 0.12.0-canary.3
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.md +8 -7
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -12,13 +12,14 @@ Cloudflare Workers adapter for Zelt.
|
|
|
12
12
|
pnpm add @zeltjs/adapter-cloudflare-workers
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Zelt's core context
|
|
16
|
-
`nodejs_compat`
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
Zelt's core uses portable synchronous context by default and does not require
|
|
16
|
+
`nodejs_compat` or `nodejs_als`. Capture request accessors and middleware values
|
|
17
|
+
in method parameter defaults; the captured values remain usable after `await`.
|
|
18
|
+
Other application dependencies may still require Node compatibility flags.
|
|
19
|
+
|
|
20
|
+
To opt into ambient context reads after `await`, enable
|
|
21
|
+
`@zeltjs/core/async-context` before creating the runtime and enable `nodejs_als`
|
|
22
|
+
or `nodejs_compat` in Wrangler. See [Execution Context](https://zeltjs.com/docs/async-context).
|
|
22
23
|
|
|
23
24
|
## Usage
|
|
24
25
|
|
package/dist/index.cjs
CHANGED
|
@@ -60,6 +60,7 @@ CloudflareWorkersWaitUntilAdaptor = _ts_decorate([_zeltjs_core.Config], Cloudfla
|
|
|
60
60
|
//#region src/on-cloudflare-workers.ts
|
|
61
61
|
const onCloudflareWorkers = async (app, options = {}) => {
|
|
62
62
|
const readyApp = await app.createRuntime({
|
|
63
|
+
...options.contextMode === void 0 ? {} : { contextMode: options.contextMode },
|
|
63
64
|
...options.configs === void 0 ? {} : { configs: options.configs },
|
|
64
65
|
...options.prebuilt === void 0 ? {} : { prebuilt: options.prebuilt },
|
|
65
66
|
fallbackConfigs: [CloudflareWorkersEnvAdaptor, CloudflareWorkersWaitUntilAdaptor],
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigClass, ConfiguredFeature, CreateRuntimeOptions, EnvAdaptor, HttpCapabilities, RuntimeApp, WaitUntilAdaptor, ZeltPrebuilt } from "@zeltjs/core";
|
|
1
|
+
import { ConfigClass, ConfiguredFeature, ContextMode, CreateRuntimeOptions, EnvAdaptor, HttpCapabilities, RuntimeApp, WaitUntilAdaptor, ZeltPrebuilt } from "@zeltjs/core";
|
|
2
2
|
|
|
3
3
|
//#region src/cloudflare-bindings.service.d.ts
|
|
4
4
|
declare class CloudflareBindingsService {
|
|
@@ -23,6 +23,7 @@ declare class CloudflareWorkersWaitUntilAdaptor extends WaitUntilAdaptor {
|
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region src/on-cloudflare-workers.d.ts
|
|
25
25
|
type CloudflareWorkersOptions = {
|
|
26
|
+
readonly contextMode?: ContextMode;
|
|
26
27
|
readonly configs?: readonly ConfigClass<object>[];
|
|
27
28
|
readonly warmup?: boolean;
|
|
28
29
|
readonly prebuilt?: ZeltPrebuilt;
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/cloudflare-bindings.service.ts","../src/cloudflare-workers-env.adaptor.ts","../src/cloudflare-workers-wait-until.adaptor.ts","../src/on-cloudflare-workers.ts"],"mappings":";;;cAKa,yBAAA;;EAEX,GAAA,iBAAoB,GAAA,CAAA,CAAK,GAAA,EAAK,CAAA,GAAI,GAAA,CAAI,CAAA;AAAA;;;cCH3B,2BAAA,SAAoC,UAAA;EACtC,GAAA,CAAI,GAAA;AAAA;;;;;ADDf;;;cEKa,iCAAA,SAA0C,gBAAA;EAC5C,SAAA,CAAU,OAAA,EAAS,OAAA;AAAA;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/cloudflare-bindings.service.ts","../src/cloudflare-workers-env.adaptor.ts","../src/cloudflare-workers-wait-until.adaptor.ts","../src/on-cloudflare-workers.ts"],"mappings":";;;cAKa,yBAAA;;EAEX,GAAA,iBAAoB,GAAA,CAAA,CAAK,GAAA,EAAK,CAAA,GAAI,GAAA,CAAI,CAAA;AAAA;;;cCH3B,2BAAA,SAAoC,UAAA;EACtC,GAAA,CAAI,GAAA;AAAA;;;;;ADDf;;;cEKa,iCAAA,SAA0C,gBAAA;EAC5C,SAAA,CAAU,OAAA,EAAS,OAAA;AAAA;;;KCGlB,wBAAA;EAAA,SACD,WAAA,GAAc,WAAA;EAAA,SACd,OAAA,YAAmB,WAAA;EAAA,SACnB,MAAA;EAAA,SACA,QAAA,GAAW,YAAA;AAAA;AAAA,KAGjB,cAAA,GAAiB,UAAA,UAAoB,iBAAA;EAAA,SAC/B,IAAA,EAAM,gBAAA;AAAA;AAAA,KAGZ,OAAA;EAAA,SACM,aAAA,GAAgB,OAAA,GAAU,oBAAA,KAAyB,OAAA,CAAQ,cAAA;AAAA;AAAA,KAG1D,oBAAA;EAAA,SACD,GAAA,EAAK,cAAA;EAAA,SACL,KAAA,GAAQ,OAAA,EAAS,OAAA,EAAS,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,gBAAA,KAAqB,OAAA,CAAQ,QAAA;EAAA,SACtE,QAAA,QAAgB,OAAA;AAAA;AAAA,cAGd,mBAAA,GACX,GAAA,EAAK,OAAA,EACL,OAAA,GAAS,wBAAA,KACR,OAAA,CAAQ,oBAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigClass, ConfiguredFeature, CreateRuntimeOptions, EnvAdaptor, HttpCapabilities, RuntimeApp, WaitUntilAdaptor, ZeltPrebuilt } from "@zeltjs/core";
|
|
1
|
+
import { ConfigClass, ConfiguredFeature, ContextMode, CreateRuntimeOptions, EnvAdaptor, HttpCapabilities, RuntimeApp, WaitUntilAdaptor, ZeltPrebuilt } from "@zeltjs/core";
|
|
2
2
|
|
|
3
3
|
//#region src/cloudflare-bindings.service.d.ts
|
|
4
4
|
declare class CloudflareBindingsService {
|
|
@@ -23,6 +23,7 @@ declare class CloudflareWorkersWaitUntilAdaptor extends WaitUntilAdaptor {
|
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region src/on-cloudflare-workers.d.ts
|
|
25
25
|
type CloudflareWorkersOptions = {
|
|
26
|
+
readonly contextMode?: ContextMode;
|
|
26
27
|
readonly configs?: readonly ConfigClass<object>[];
|
|
27
28
|
readonly warmup?: boolean;
|
|
28
29
|
readonly prebuilt?: ZeltPrebuilt;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/cloudflare-bindings.service.ts","../src/cloudflare-workers-env.adaptor.ts","../src/cloudflare-workers-wait-until.adaptor.ts","../src/on-cloudflare-workers.ts"],"mappings":";;;cAKa,yBAAA;;EAEX,GAAA,iBAAoB,GAAA,CAAA,CAAK,GAAA,EAAK,CAAA,GAAI,GAAA,CAAI,CAAA;AAAA;;;cCH3B,2BAAA,SAAoC,UAAA;EACtC,GAAA,CAAI,GAAA;AAAA;;;;;ADDf;;;cEKa,iCAAA,SAA0C,gBAAA;EAC5C,SAAA,CAAU,OAAA,EAAS,OAAA;AAAA;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/cloudflare-bindings.service.ts","../src/cloudflare-workers-env.adaptor.ts","../src/cloudflare-workers-wait-until.adaptor.ts","../src/on-cloudflare-workers.ts"],"mappings":";;;cAKa,yBAAA;;EAEX,GAAA,iBAAoB,GAAA,CAAA,CAAK,GAAA,EAAK,CAAA,GAAI,GAAA,CAAI,CAAA;AAAA;;;cCH3B,2BAAA,SAAoC,UAAA;EACtC,GAAA,CAAI,GAAA;AAAA;;;;;ADDf;;;cEKa,iCAAA,SAA0C,gBAAA;EAC5C,SAAA,CAAU,OAAA,EAAS,OAAA;AAAA;;;KCGlB,wBAAA;EAAA,SACD,WAAA,GAAc,WAAA;EAAA,SACd,OAAA,YAAmB,WAAA;EAAA,SACnB,MAAA;EAAA,SACA,QAAA,GAAW,YAAA;AAAA;AAAA,KAGjB,cAAA,GAAiB,UAAA,UAAoB,iBAAA;EAAA,SAC/B,IAAA,EAAM,gBAAA;AAAA;AAAA,KAGZ,OAAA;EAAA,SACM,aAAA,GAAgB,OAAA,GAAU,oBAAA,KAAyB,OAAA,CAAQ,cAAA;AAAA;AAAA,KAG1D,oBAAA;EAAA,SACD,GAAA,EAAK,cAAA;EAAA,SACL,KAAA,GAAQ,OAAA,EAAS,OAAA,EAAS,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,gBAAA,KAAqB,OAAA,CAAQ,QAAA;EAAA,SACtE,QAAA,QAAgB,OAAA;AAAA;AAAA,cAGd,mBAAA,GACX,GAAA,EAAK,OAAA,EACL,OAAA,GAAS,wBAAA,KACR,OAAA,CAAQ,oBAAA"}
|
package/dist/index.js
CHANGED
|
@@ -59,6 +59,7 @@ CloudflareWorkersWaitUntilAdaptor = _ts_decorate([Config], CloudflareWorkersWait
|
|
|
59
59
|
//#region src/on-cloudflare-workers.ts
|
|
60
60
|
const onCloudflareWorkers = async (app, options = {}) => {
|
|
61
61
|
const readyApp = await app.createRuntime({
|
|
62
|
+
...options.contextMode === void 0 ? {} : { contextMode: options.contextMode },
|
|
62
63
|
...options.configs === void 0 ? {} : { configs: options.configs },
|
|
63
64
|
...options.prebuilt === void 0 ? {} : { prebuilt: options.prebuilt },
|
|
64
65
|
fallbackConfigs: [CloudflareWorkersEnvAdaptor, CloudflareWorkersWaitUntilAdaptor],
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createContextStorage","ZeltContextNotAvailableError","storage","getCloudflareRuntimeContext","context","get","primitive","requiredContext","runWithCloudflareRuntimeContext","fn","run","tryGetCloudflareRuntimeContext","Injectable","getCloudflareRuntimeContext","CloudflareBindingsService","get","key","env","env","Config","EnvAdaptor","CloudflareWorkersEnvAdaptor","get","key","value","Reflect","undefined","Config","WaitUntilAdaptor","tryGetCloudflareRuntimeContext","CloudflareWorkersWaitUntilAdaptor","waitUntil","promise","ctx","runWithCloudflareRuntimeContext","CloudflareWorkersEnvAdaptor","CloudflareWorkersWaitUntilAdaptor","onCloudflareWorkers","app","options","readyApp","createRuntime","
|
|
1
|
+
{"version":3,"file":"index.js","names":["createContextStorage","ZeltContextNotAvailableError","storage","getCloudflareRuntimeContext","context","get","primitive","requiredContext","runWithCloudflareRuntimeContext","fn","run","tryGetCloudflareRuntimeContext","Injectable","getCloudflareRuntimeContext","CloudflareBindingsService","get","key","env","env","Config","EnvAdaptor","CloudflareWorkersEnvAdaptor","get","key","value","Reflect","undefined","Config","WaitUntilAdaptor","tryGetCloudflareRuntimeContext","CloudflareWorkersWaitUntilAdaptor","waitUntil","promise","ctx","runWithCloudflareRuntimeContext","CloudflareWorkersEnvAdaptor","CloudflareWorkersWaitUntilAdaptor","onCloudflareWorkers","app","options","readyApp","createRuntime","contextMode","undefined","configs","prebuilt","fallbackConfigs","warmup","fetch","request","env","ctx","response","http","waitUntil","then","get","shutdown"],"sources":["../src/cloudflare-runtime-context.lib.ts","../src/cloudflare-bindings.service.ts","../src/cloudflare-workers-env.adaptor.ts","../src/cloudflare-workers-wait-until.adaptor.ts","../src/on-cloudflare-workers.ts"],"sourcesContent":["import { createContextStorage, ZeltContextNotAvailableError } from '@zeltjs/core';\n\nexport type CloudflareRuntimeContext = {\n readonly env: Env;\n readonly ctx: ExecutionContext;\n};\n\nconst storage = createContextStorage<CloudflareRuntimeContext>('zelt:cloudflare-runtime');\n\n/** @throws {ZeltContextNotAvailableError} */\nexport const getCloudflareRuntimeContext = (): CloudflareRuntimeContext => {\n const context = storage.get();\n if (!context) {\n throw new ZeltContextNotAvailableError({\n primitive: 'CloudflareBindings.get',\n requiredContext: 'entry',\n });\n }\n return context;\n};\n\nexport const runWithCloudflareRuntimeContext = <T>(\n context: CloudflareRuntimeContext,\n fn: () => T,\n): T => storage.run(context, fn);\n\nexport const tryGetCloudflareRuntimeContext = (): CloudflareRuntimeContext | undefined =>\n storage.get();\n\ndeclare global {\n interface Env {}\n}\n","import { Injectable } from '@zeltjs/core';\n\nimport { getCloudflareRuntimeContext } from './cloudflare-runtime-context.lib';\n\n@Injectable()\nexport class CloudflareBindingsService {\n /** @throws {ZeltContextNotAvailableError} */\n get<K extends keyof Env>(key: K): Env[K] {\n return getCloudflareRuntimeContext().env[key];\n }\n}\n","import { env } from 'cloudflare:workers';\nimport { Config, EnvAdaptor } from '@zeltjs/core';\n\n@Config\nexport class CloudflareWorkersEnvAdaptor extends EnvAdaptor {\n override get(key: string): string | undefined {\n const value: unknown = Reflect.get(env, key);\n return typeof value === 'string' ? value : undefined;\n }\n}\n","import { Config, WaitUntilAdaptor } from '@zeltjs/core';\nimport { tryGetCloudflareRuntimeContext } from './cloudflare-runtime-context.lib';\n\n/**\n * Only extends execution while inside a request handled via onCloudflareWorkers'\n * fetch (the ALS scope); outside it (future cron/queue/DO entry points) this is\n * a silent no-op and tasks may be killed when the event settles.\n */\n@Config\nexport class CloudflareWorkersWaitUntilAdaptor extends WaitUntilAdaptor {\n override waitUntil(promise: Promise<void>): void {\n tryGetCloudflareRuntimeContext()?.ctx.waitUntil(promise);\n }\n}\n","import type {\n ConfigClass,\n ConfiguredFeature,\n ContextMode,\n CreateRuntimeOptions,\n HttpCapabilities,\n RuntimeApp,\n ZeltPrebuilt,\n} from '@zeltjs/core';\nimport { runWithCloudflareRuntimeContext } from './cloudflare-runtime-context.lib';\nimport { CloudflareWorkersEnvAdaptor } from './cloudflare-workers-env.adaptor';\nimport { CloudflareWorkersWaitUntilAdaptor } from './cloudflare-workers-wait-until.adaptor';\n\nexport type CloudflareWorkersOptions = {\n readonly contextMode?: ContextMode;\n readonly configs?: readonly ConfigClass<object>[];\n readonly warmup?: boolean;\n readonly prebuilt?: ZeltPrebuilt;\n};\n\ntype HttpRuntimeApp = RuntimeApp<readonly ConfiguredFeature[]> & {\n readonly http: HttpCapabilities;\n};\n\ntype HttpApp = {\n readonly createRuntime: (options?: CreateRuntimeOptions) => Promise<HttpRuntimeApp>;\n};\n\nexport type CloudflareWorkersApp = {\n readonly get: HttpRuntimeApp['get'];\n readonly fetch: (request: Request, env: Env, ctx: ExecutionContext) => Promise<Response>;\n readonly shutdown: () => Promise<void>;\n};\n\nexport const onCloudflareWorkers = async (\n app: HttpApp,\n options: CloudflareWorkersOptions = {},\n): Promise<CloudflareWorkersApp> => {\n const readyApp = await app.createRuntime({\n ...(options.contextMode === undefined ? {} : { contextMode: options.contextMode }),\n ...(options.configs === undefined ? {} : { configs: options.configs }),\n ...(options.prebuilt === undefined ? {} : { prebuilt: options.prebuilt }),\n fallbackConfigs: [CloudflareWorkersEnvAdaptor, CloudflareWorkersWaitUntilAdaptor],\n warmup: options.warmup ?? false,\n });\n\n const fetch = async (request: Request, env: Env, ctx: ExecutionContext): Promise<Response> => {\n const response = runWithCloudflareRuntimeContext({ env, ctx }, () =>\n readyApp.http.fetch(request),\n );\n ctx.waitUntil(response.then(() => {}));\n return response;\n };\n\n return { get: readyApp.get, fetch, shutdown: readyApp.shutdown };\n};\n"],"mappings":";;;AAOA,MAAME,UAAUF,qBAA+C,0BAAA;8CAG/D,MAAaG,oCAA8B;CACzC,MAAMC,UAAUF,QAAQG,KAAG;AAC3B,KAAI,CAACD,QACH,OAAM,IAAIH,6BAA6B;EACrCK,WAAW;EACXC,iBAAiB;EACnB,CAAA;AAEF,QAAOH;;AAGT,MAAaI,mCACXJ,SACAK,OACMP,QAAQQ,IAAIN,SAASK,GAAAA;AAE7B,MAAaE,uCACXT,QAAQG,KAAG;;;;;;;;;ACtBb,IAAaS,4BAAb,MAAaA;+CAEXC,IAAyBC,KAAgB;AACvC,SAAOH,6BAAAA,CAA8BI,IAAID;;;;;;;;;;;;ACJ7C,IAAaK,8BAAb,cAAiDD,WAAAA;CACtCE,IAAIC,KAAiC;EAC5C,MAAMC,QAAiBC,QAAQH,IAAIJ,KAAKK,IAAAA;AACxC,SAAO,OAAOC,UAAU,WAAWA,QAAQE,KAAAA;;;;;;;;;;;;ACE/C,IAAaI,oCAAb,cAAuDF,iBAAAA;CAC5CG,UAAUC,SAA8B;AAC/CH,kCAAAA,EAAkCI,IAAIF,UAAUC,QAAAA;;;;;;ACuBpD,MAAaK,sBAAsB,OACjCC,KACAC,UAAoC,EAAE,KAAA;CAEtC,MAAMC,WAAW,MAAMF,IAAIG,cAAc;EACvC,GAAIF,QAAQG,gBAAgBC,KAAAA,IAAY,EAAC,GAAI,EAAED,aAAaH,QAAQG,aAAa;EACjF,GAAIH,QAAQK,YAAYD,KAAAA,IAAY,EAAC,GAAI,EAAEC,SAASL,QAAQK,SAAS;EACrE,GAAIL,QAAQM,aAAaF,KAAAA,IAAY,EAAC,GAAI,EAAEE,UAAUN,QAAQM,UAAU;EACxEC,iBAAiB,CAACX,6BAA6BC,kCAAkC;EACjFW,QAAQR,QAAQQ,UAAU;EAC5B,CAAA;CAEA,MAAMC,QAAQ,OAAOC,SAAkBC,KAAUC,QAAAA;EAC/C,MAAMC,WAAWlB,gCAAgC;GAAEgB;GAAKC;GAAI,QAC1DX,SAASa,KAAKL,MAAMC,QAAAA,CAAAA;AAEtBE,MAAIG,UAAUF,SAASG,WAAK,GAAO,CAAA;AACnC,SAAOH;;AAGT,QAAO;EAAEI,KAAKhB,SAASgB;EAAKR;EAAOS,UAAUjB,SAASiB;EAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeltjs/adapter-cloudflare-workers",
|
|
3
|
-
"version": "0.12.0-canary.
|
|
3
|
+
"version": "0.12.0-canary.3",
|
|
4
4
|
"description": "Cloudflare Workers adapter for the Zelt framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@zeltjs/core": "0.12.0-canary.
|
|
31
|
+
"@zeltjs/core": "0.12.0-canary.3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "22.19.17",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"main": "./dist/index.cjs",
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "tsdown",
|
|
43
|
-
"test": "vitest run",
|
|
43
|
+
"test": "pnpm -w run test:prepare && vitest run",
|
|
44
44
|
"typecheck": "tsc -b"
|
|
45
45
|
}
|
|
46
46
|
}
|