@zeltjs/adapter-cloudflare-workers 0.10.1-canary.0 → 0.11.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/README.md CHANGED
@@ -12,9 +12,9 @@ Cloudflare Workers adapter for Zelt.
12
12
  pnpm add @zeltjs/adapter-cloudflare-workers
13
13
  ```
14
14
 
15
- This adapter uses `AsyncLocalStorage` from `node:async_hooks`, so the
16
- `nodejs_compat` compatibility flag (or the narrower `nodejs_als`) must be
17
- enabled in your `wrangler.toml` / `wrangler.jsonc`:
15
+ Zelt's core context propagation uses `AsyncLocalStorage`, so the
16
+ `nodejs_compat` compatibility flag (or the narrower `nodejs_als`) must still
17
+ be enabled in your `wrangler.toml` / `wrangler.jsonc`:
18
18
 
19
19
  ```toml
20
20
  compatibility_flags = ["nodejs_compat"]
package/dist/index.cjs CHANGED
@@ -1,11 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _zeltjs_core = require("@zeltjs/core");
3
- let node_async_hooks = require("node:async_hooks");
4
3
  let cloudflare_workers = require("cloudflare:workers");
5
4
  //#region src/cloudflare-runtime-context.lib.ts
6
- const storage = new node_async_hooks.AsyncLocalStorage();
5
+ const storage = (0, _zeltjs_core.createContextStorage)("zelt:cloudflare-runtime");
7
6
  /** @throws {ZeltContextNotAvailableError} */ const getCloudflareRuntimeContext = () => {
8
- const context = storage.getStore();
7
+ const context = storage.get();
9
8
  if (!context) throw new _zeltjs_core.ZeltContextNotAvailableError({
10
9
  primitive: "CloudflareBindings.get",
11
10
  requiredContext: "entry"
@@ -13,7 +12,7 @@ const storage = new node_async_hooks.AsyncLocalStorage();
13
12
  return context;
14
13
  };
15
14
  const runWithCloudflareRuntimeContext = (context, fn) => storage.run(context, fn);
16
- const tryGetCloudflareRuntimeContext = () => storage.getStore();
15
+ const tryGetCloudflareRuntimeContext = () => storage.get();
17
16
  //#endregion
18
17
  //#region src/cloudflare-bindings.service.ts
19
18
  function _ts_decorate$2(decorators, target, key, desc) {
@@ -62,6 +61,7 @@ CloudflareWorkersWaitUntilAdaptor = _ts_decorate([_zeltjs_core.Config], Cloudfla
62
61
  const onCloudflareWorkers = async (app, options = {}) => {
63
62
  const readyApp = await app.createRuntime({
64
63
  ...options.configs === void 0 ? {} : { configs: options.configs },
64
+ ...options.prebuilt === void 0 ? {} : { prebuilt: options.prebuilt },
65
65
  fallbackConfigs: [CloudflareWorkersEnvAdaptor, CloudflareWorkersWaitUntilAdaptor],
66
66
  warmup: options.warmup ?? false
67
67
  });
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { ConfigClass, ConfiguredFeature, CreateRuntimeOptions, EnvAdaptor, HttpCapabilities, RuntimeApp, WaitUntilAdaptor } from "@zeltjs/core";
1
+ import { ConfigClass, ConfiguredFeature, 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 {
@@ -25,6 +25,7 @@ declare class CloudflareWorkersWaitUntilAdaptor extends WaitUntilAdaptor {
25
25
  type CloudflareWorkersOptions = {
26
26
  readonly configs?: readonly ConfigClass<object>[];
27
27
  readonly warmup?: boolean;
28
+ readonly prebuilt?: ZeltPrebuilt;
28
29
  };
29
30
  type HttpRuntimeApp = RuntimeApp<readonly ConfiguredFeature[]> & {
30
31
  readonly http: HttpCapabilities;
@@ -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;;;KCClB,wBAAA;EAAA,SACD,OAAA,YAAmB,WAAA;EAAA,SACnB,MAAA;AAAA;AAAA,KAGN,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"}
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;;;KCElB,wBAAA;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 } from "@zeltjs/core";
1
+ import { ConfigClass, ConfiguredFeature, 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 {
@@ -25,6 +25,7 @@ declare class CloudflareWorkersWaitUntilAdaptor extends WaitUntilAdaptor {
25
25
  type CloudflareWorkersOptions = {
26
26
  readonly configs?: readonly ConfigClass<object>[];
27
27
  readonly warmup?: boolean;
28
+ readonly prebuilt?: ZeltPrebuilt;
28
29
  };
29
30
  type HttpRuntimeApp = RuntimeApp<readonly ConfiguredFeature[]> & {
30
31
  readonly http: HttpCapabilities;
@@ -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;;;KCClB,wBAAA;EAAA,SACD,OAAA,YAAmB,WAAA;EAAA,SACnB,MAAA;AAAA;AAAA,KAGN,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"}
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;;;KCElB,wBAAA;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
@@ -1,10 +1,9 @@
1
- import { Config, EnvAdaptor, Injectable, WaitUntilAdaptor, ZeltContextNotAvailableError } from "@zeltjs/core";
2
- import { AsyncLocalStorage } from "node:async_hooks";
1
+ import { Config, EnvAdaptor, Injectable, WaitUntilAdaptor, ZeltContextNotAvailableError, createContextStorage } from "@zeltjs/core";
3
2
  import { env } from "cloudflare:workers";
4
3
  //#region src/cloudflare-runtime-context.lib.ts
5
- const storage = new AsyncLocalStorage();
4
+ const storage = createContextStorage("zelt:cloudflare-runtime");
6
5
  /** @throws {ZeltContextNotAvailableError} */ const getCloudflareRuntimeContext = () => {
7
- const context = storage.getStore();
6
+ const context = storage.get();
8
7
  if (!context) throw new ZeltContextNotAvailableError({
9
8
  primitive: "CloudflareBindings.get",
10
9
  requiredContext: "entry"
@@ -12,7 +11,7 @@ const storage = new AsyncLocalStorage();
12
11
  return context;
13
12
  };
14
13
  const runWithCloudflareRuntimeContext = (context, fn) => storage.run(context, fn);
15
- const tryGetCloudflareRuntimeContext = () => storage.getStore();
14
+ const tryGetCloudflareRuntimeContext = () => storage.get();
16
15
  //#endregion
17
16
  //#region src/cloudflare-bindings.service.ts
18
17
  function _ts_decorate$2(decorators, target, key, desc) {
@@ -61,6 +60,7 @@ CloudflareWorkersWaitUntilAdaptor = _ts_decorate([Config], CloudflareWorkersWait
61
60
  const onCloudflareWorkers = async (app, options = {}) => {
62
61
  const readyApp = await app.createRuntime({
63
62
  ...options.configs === void 0 ? {} : { configs: options.configs },
63
+ ...options.prebuilt === void 0 ? {} : { prebuilt: options.prebuilt },
64
64
  fallbackConfigs: [CloudflareWorkersEnvAdaptor, CloudflareWorkersWaitUntilAdaptor],
65
65
  warmup: options.warmup ?? false
66
66
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["AsyncLocalStorage","ZeltContextNotAvailableError","storage","getCloudflareRuntimeContext","context","getStore","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","configs","undefined","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 { AsyncLocalStorage } from 'node:async_hooks';\nimport { ZeltContextNotAvailableError } from '@zeltjs/core';\n\nexport type CloudflareRuntimeContext = {\n readonly env: Env;\n readonly ctx: ExecutionContext;\n};\n\nconst storage = new AsyncLocalStorage<CloudflareRuntimeContext>();\n\n/** @throws {ZeltContextNotAvailableError} */\nexport const getCloudflareRuntimeContext = (): CloudflareRuntimeContext => {\n const context = storage.getStore();\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.getStore();\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 CreateRuntimeOptions,\n HttpCapabilities,\n RuntimeApp,\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 configs?: readonly ConfigClass<object>[];\n readonly warmup?: boolean;\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.configs === undefined ? {} : { configs: options.configs }),\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":";;;;AAQA,MAAME,UAAU,IAAIF,mBAAAA;8CAGpB,MAAaG,oCAA8B;CACzC,MAAMC,UAAUF,QAAQG,UAAQ;AAChC,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,UAAQ;;;;;;;;;ACvBlB,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;;;;;;ACmBpD,MAAaK,sBAAsB,OACjCC,KACAC,UAAoC,EAAE,KAAA;CAEtC,MAAMC,WAAW,MAAMF,IAAIG,cAAc;EACvC,GAAIF,QAAQG,YAAYC,KAAAA,IAAY,EAAC,GAAI,EAAED,SAASH,QAAQG,SAAS;EACrEE,iBAAiB,CAACT,6BAA6BC,kCAAkC;EACjFS,QAAQN,QAAQM,UAAU;EAC5B,CAAA;CAEA,MAAMC,QAAQ,OAAOC,SAAkBC,KAAUC,QAAAA;EAC/C,MAAMC,WAAWhB,gCAAgC;GAAEc;GAAKC;GAAI,QAC1DT,SAASW,KAAKL,MAAMC,QAAAA,CAAAA;AAEtBE,MAAIG,UAAUF,SAASG,WAAK,GAAO,CAAA;AACnC,SAAOH;;AAGT,QAAO;EAAEI,KAAKd,SAASc;EAAKR;EAAOS,UAAUf,SAASe;EAAS"}
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","configs","undefined","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 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 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.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;;;;;;ACqBpD,MAAaK,sBAAsB,OACjCC,KACAC,UAAoC,EAAE,KAAA;CAEtC,MAAMC,WAAW,MAAMF,IAAIG,cAAc;EACvC,GAAIF,QAAQG,YAAYC,KAAAA,IAAY,EAAC,GAAI,EAAED,SAASH,QAAQG,SAAS;EACrE,GAAIH,QAAQK,aAAaD,KAAAA,IAAY,EAAC,GAAI,EAAEC,UAAUL,QAAQK,UAAU;EACxEC,iBAAiB,CAACV,6BAA6BC,kCAAkC;EACjFU,QAAQP,QAAQO,UAAU;EAC5B,CAAA;CAEA,MAAMC,QAAQ,OAAOC,SAAkBC,KAAUC,QAAAA;EAC/C,MAAMC,WAAWjB,gCAAgC;GAAEe;GAAKC;GAAI,QAC1DV,SAASY,KAAKL,MAAMC,QAAAA,CAAAA;AAEtBE,MAAIG,UAAUF,SAASG,WAAK,GAAO,CAAA;AACnC,SAAOH;;AAGT,QAAO;EAAEI,KAAKf,SAASe;EAAKR;EAAOS,UAAUhB,SAASgB;EAAS"}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@zeltjs/adapter-cloudflare-workers",
3
- "version": "0.10.1-canary.0",
3
+ "version": "0.11.0",
4
+ "description": "Cloudflare Workers adapter for the Zelt framework",
4
5
  "type": "module",
5
6
  "license": "MIT",
6
7
  "repository": {
@@ -27,7 +28,7 @@
27
28
  "dist"
28
29
  ],
29
30
  "dependencies": {
30
- "@zeltjs/core": "0.10.1-canary.0"
31
+ "@zeltjs/core": "0.11.0"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@types/node": "22.19.17",