@zeltjs/adapter-cloudflare-workers 0.10.0 → 0.10.1-canary.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 +12 -0
- package/dist/index.cjs +26 -5
- package/dist/index.d.cts +12 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,6 +12,14 @@ 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`:
|
|
18
|
+
|
|
19
|
+
```toml
|
|
20
|
+
compatibility_flags = ["nodejs_compat"]
|
|
21
|
+
```
|
|
22
|
+
|
|
15
23
|
## Usage
|
|
16
24
|
|
|
17
25
|
```typescript
|
|
@@ -106,3 +114,7 @@ export default { fetch: workers.fetch };
|
|
|
106
114
|
`bindings.get('DB')` is typed from the augmented global `Env`, so no manual typing is needed.
|
|
107
115
|
|
|
108
116
|
**Important:** `CloudflareBindings.get()` reads from request-scoped storage populated by `onCloudflareWorkers()`, so it only works during request handling — calling it outside a request (e.g. at module load time) throws.
|
|
117
|
+
|
|
118
|
+
## Background Tasks
|
|
119
|
+
|
|
120
|
+
`onCloudflareWorkers()` automatically registers `CloudflareWorkersWaitUntilAdaptor`, which extends `TaskService`'s after-response and fire-and-forget tasks through `ctx.waitUntil`, so the Workers runtime keeps the isolate alive until they finish.
|
package/dist/index.cjs
CHANGED
|
@@ -13,9 +13,10 @@ const storage = new node_async_hooks.AsyncLocalStorage();
|
|
|
13
13
|
return context;
|
|
14
14
|
};
|
|
15
15
|
const runWithCloudflareRuntimeContext = (context, fn) => storage.run(context, fn);
|
|
16
|
+
const tryGetCloudflareRuntimeContext = () => storage.getStore();
|
|
16
17
|
//#endregion
|
|
17
18
|
//#region src/cloudflare-bindings.service.ts
|
|
18
|
-
function _ts_decorate$
|
|
19
|
+
function _ts_decorate$2(decorators, target, key, desc) {
|
|
19
20
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
21
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
22
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
@@ -26,10 +27,10 @@ var CloudflareBindingsService = class {
|
|
|
26
27
|
return getCloudflareRuntimeContext().env[key];
|
|
27
28
|
}
|
|
28
29
|
};
|
|
29
|
-
CloudflareBindingsService = _ts_decorate$
|
|
30
|
+
CloudflareBindingsService = _ts_decorate$2([(0, _zeltjs_core.Injectable)()], CloudflareBindingsService);
|
|
30
31
|
//#endregion
|
|
31
32
|
//#region src/cloudflare-workers-env.adaptor.ts
|
|
32
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
33
|
+
function _ts_decorate$1(decorators, target, key, desc) {
|
|
33
34
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
34
35
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
35
36
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
@@ -41,13 +42,27 @@ var CloudflareWorkersEnvAdaptor = class extends _zeltjs_core.EnvAdaptor {
|
|
|
41
42
|
return typeof value === "string" ? value : void 0;
|
|
42
43
|
}
|
|
43
44
|
};
|
|
44
|
-
CloudflareWorkersEnvAdaptor = _ts_decorate([_zeltjs_core.Config], CloudflareWorkersEnvAdaptor);
|
|
45
|
+
CloudflareWorkersEnvAdaptor = _ts_decorate$1([_zeltjs_core.Config], CloudflareWorkersEnvAdaptor);
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/cloudflare-workers-wait-until.adaptor.ts
|
|
48
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
49
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
50
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
51
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
52
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
53
|
+
}
|
|
54
|
+
var CloudflareWorkersWaitUntilAdaptor = class extends _zeltjs_core.WaitUntilAdaptor {
|
|
55
|
+
waitUntil(promise) {
|
|
56
|
+
tryGetCloudflareRuntimeContext()?.ctx.waitUntil(promise);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
CloudflareWorkersWaitUntilAdaptor = _ts_decorate([_zeltjs_core.Config], CloudflareWorkersWaitUntilAdaptor);
|
|
45
60
|
//#endregion
|
|
46
61
|
//#region src/on-cloudflare-workers.ts
|
|
47
62
|
const onCloudflareWorkers = async (app, options = {}) => {
|
|
48
63
|
const readyApp = await app.createRuntime({
|
|
49
64
|
...options.configs === void 0 ? {} : { configs: options.configs },
|
|
50
|
-
fallbackConfigs: [CloudflareWorkersEnvAdaptor],
|
|
65
|
+
fallbackConfigs: [CloudflareWorkersEnvAdaptor, CloudflareWorkersWaitUntilAdaptor],
|
|
51
66
|
warmup: options.warmup ?? false
|
|
52
67
|
});
|
|
53
68
|
const fetch = async (request, env, ctx) => {
|
|
@@ -77,4 +92,10 @@ Object.defineProperty(exports, "CloudflareWorkersEnvAdaptor", {
|
|
|
77
92
|
return CloudflareWorkersEnvAdaptor;
|
|
78
93
|
}
|
|
79
94
|
});
|
|
95
|
+
Object.defineProperty(exports, "CloudflareWorkersWaitUntilAdaptor", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function() {
|
|
98
|
+
return CloudflareWorkersWaitUntilAdaptor;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
80
101
|
exports.onCloudflareWorkers = onCloudflareWorkers;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigClass, ConfiguredFeature, CreateRuntimeOptions, EnvAdaptor, HttpCapabilities, RuntimeApp } from "@zeltjs/core";
|
|
1
|
+
import { ConfigClass, ConfiguredFeature, CreateRuntimeOptions, EnvAdaptor, HttpCapabilities, RuntimeApp, WaitUntilAdaptor } from "@zeltjs/core";
|
|
2
2
|
|
|
3
3
|
//#region src/cloudflare-bindings.service.d.ts
|
|
4
4
|
declare class CloudflareBindingsService {
|
|
@@ -11,6 +11,16 @@ declare class CloudflareWorkersEnvAdaptor extends EnvAdaptor {
|
|
|
11
11
|
get(key: string): string | undefined;
|
|
12
12
|
}
|
|
13
13
|
//#endregion
|
|
14
|
+
//#region src/cloudflare-workers-wait-until.adaptor.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Only extends execution while inside a request handled via onCloudflareWorkers'
|
|
17
|
+
* fetch (the ALS scope); outside it (future cron/queue/DO entry points) this is
|
|
18
|
+
* a silent no-op and tasks may be killed when the event settles.
|
|
19
|
+
*/
|
|
20
|
+
declare class CloudflareWorkersWaitUntilAdaptor extends WaitUntilAdaptor {
|
|
21
|
+
waitUntil(promise: Promise<void>): void;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
14
24
|
//#region src/on-cloudflare-workers.d.ts
|
|
15
25
|
type CloudflareWorkersOptions = {
|
|
16
26
|
readonly configs?: readonly ConfigClass<object>[];
|
|
@@ -29,5 +39,5 @@ type CloudflareWorkersApp = {
|
|
|
29
39
|
};
|
|
30
40
|
declare const onCloudflareWorkers: (app: HttpApp, options?: CloudflareWorkersOptions) => Promise<CloudflareWorkersApp>;
|
|
31
41
|
//#endregion
|
|
32
|
-
export { CloudflareBindingsService as CloudflareBindings, type CloudflareWorkersApp, CloudflareWorkersEnvAdaptor, type CloudflareWorkersOptions, onCloudflareWorkers };
|
|
42
|
+
export { CloudflareBindingsService as CloudflareBindings, type CloudflareWorkersApp, CloudflareWorkersEnvAdaptor, type CloudflareWorkersOptions, CloudflareWorkersWaitUntilAdaptor, onCloudflareWorkers };
|
|
33
43
|
//# sourceMappingURL=index.d.cts.map
|
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/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;;;
|
|
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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigClass, ConfiguredFeature, CreateRuntimeOptions, EnvAdaptor, HttpCapabilities, RuntimeApp } from "@zeltjs/core";
|
|
1
|
+
import { ConfigClass, ConfiguredFeature, CreateRuntimeOptions, EnvAdaptor, HttpCapabilities, RuntimeApp, WaitUntilAdaptor } from "@zeltjs/core";
|
|
2
2
|
|
|
3
3
|
//#region src/cloudflare-bindings.service.d.ts
|
|
4
4
|
declare class CloudflareBindingsService {
|
|
@@ -11,6 +11,16 @@ declare class CloudflareWorkersEnvAdaptor extends EnvAdaptor {
|
|
|
11
11
|
get(key: string): string | undefined;
|
|
12
12
|
}
|
|
13
13
|
//#endregion
|
|
14
|
+
//#region src/cloudflare-workers-wait-until.adaptor.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Only extends execution while inside a request handled via onCloudflareWorkers'
|
|
17
|
+
* fetch (the ALS scope); outside it (future cron/queue/DO entry points) this is
|
|
18
|
+
* a silent no-op and tasks may be killed when the event settles.
|
|
19
|
+
*/
|
|
20
|
+
declare class CloudflareWorkersWaitUntilAdaptor extends WaitUntilAdaptor {
|
|
21
|
+
waitUntil(promise: Promise<void>): void;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
14
24
|
//#region src/on-cloudflare-workers.d.ts
|
|
15
25
|
type CloudflareWorkersOptions = {
|
|
16
26
|
readonly configs?: readonly ConfigClass<object>[];
|
|
@@ -29,5 +39,5 @@ type CloudflareWorkersApp = {
|
|
|
29
39
|
};
|
|
30
40
|
declare const onCloudflareWorkers: (app: HttpApp, options?: CloudflareWorkersOptions) => Promise<CloudflareWorkersApp>;
|
|
31
41
|
//#endregion
|
|
32
|
-
export { CloudflareBindingsService as CloudflareBindings, type CloudflareWorkersApp, CloudflareWorkersEnvAdaptor, type CloudflareWorkersOptions, onCloudflareWorkers };
|
|
42
|
+
export { CloudflareBindingsService as CloudflareBindings, type CloudflareWorkersApp, CloudflareWorkersEnvAdaptor, type CloudflareWorkersOptions, CloudflareWorkersWaitUntilAdaptor, onCloudflareWorkers };
|
|
33
43
|
//# sourceMappingURL=index.d.ts.map
|
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/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;;;
|
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config, EnvAdaptor, Injectable, ZeltContextNotAvailableError } from "@zeltjs/core";
|
|
1
|
+
import { Config, EnvAdaptor, Injectable, WaitUntilAdaptor, ZeltContextNotAvailableError } from "@zeltjs/core";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
import { env } from "cloudflare:workers";
|
|
4
4
|
//#region src/cloudflare-runtime-context.lib.ts
|
|
@@ -12,9 +12,10 @@ const storage = new AsyncLocalStorage();
|
|
|
12
12
|
return context;
|
|
13
13
|
};
|
|
14
14
|
const runWithCloudflareRuntimeContext = (context, fn) => storage.run(context, fn);
|
|
15
|
+
const tryGetCloudflareRuntimeContext = () => storage.getStore();
|
|
15
16
|
//#endregion
|
|
16
17
|
//#region src/cloudflare-bindings.service.ts
|
|
17
|
-
function _ts_decorate$
|
|
18
|
+
function _ts_decorate$2(decorators, target, key, desc) {
|
|
18
19
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
20
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
21
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
@@ -25,10 +26,10 @@ var CloudflareBindingsService = class {
|
|
|
25
26
|
return getCloudflareRuntimeContext().env[key];
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
|
-
CloudflareBindingsService = _ts_decorate$
|
|
29
|
+
CloudflareBindingsService = _ts_decorate$2([Injectable()], CloudflareBindingsService);
|
|
29
30
|
//#endregion
|
|
30
31
|
//#region src/cloudflare-workers-env.adaptor.ts
|
|
31
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
32
|
+
function _ts_decorate$1(decorators, target, key, desc) {
|
|
32
33
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
33
34
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
34
35
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
@@ -40,13 +41,27 @@ var CloudflareWorkersEnvAdaptor = class extends EnvAdaptor {
|
|
|
40
41
|
return typeof value === "string" ? value : void 0;
|
|
41
42
|
}
|
|
42
43
|
};
|
|
43
|
-
CloudflareWorkersEnvAdaptor = _ts_decorate([Config], CloudflareWorkersEnvAdaptor);
|
|
44
|
+
CloudflareWorkersEnvAdaptor = _ts_decorate$1([Config], CloudflareWorkersEnvAdaptor);
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/cloudflare-workers-wait-until.adaptor.ts
|
|
47
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
48
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
49
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
50
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
51
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
52
|
+
}
|
|
53
|
+
var CloudflareWorkersWaitUntilAdaptor = class extends WaitUntilAdaptor {
|
|
54
|
+
waitUntil(promise) {
|
|
55
|
+
tryGetCloudflareRuntimeContext()?.ctx.waitUntil(promise);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
CloudflareWorkersWaitUntilAdaptor = _ts_decorate([Config], CloudflareWorkersWaitUntilAdaptor);
|
|
44
59
|
//#endregion
|
|
45
60
|
//#region src/on-cloudflare-workers.ts
|
|
46
61
|
const onCloudflareWorkers = async (app, options = {}) => {
|
|
47
62
|
const readyApp = await app.createRuntime({
|
|
48
63
|
...options.configs === void 0 ? {} : { configs: options.configs },
|
|
49
|
-
fallbackConfigs: [CloudflareWorkersEnvAdaptor],
|
|
64
|
+
fallbackConfigs: [CloudflareWorkersEnvAdaptor, CloudflareWorkersWaitUntilAdaptor],
|
|
50
65
|
warmup: options.warmup ?? false
|
|
51
66
|
});
|
|
52
67
|
const fetch = async (request, env, ctx) => {
|
|
@@ -64,6 +79,6 @@ const onCloudflareWorkers = async (app, options = {}) => {
|
|
|
64
79
|
};
|
|
65
80
|
};
|
|
66
81
|
//#endregion
|
|
67
|
-
export { CloudflareBindingsService as CloudflareBindings, CloudflareWorkersEnvAdaptor, onCloudflareWorkers };
|
|
82
|
+
export { CloudflareBindingsService as CloudflareBindings, CloudflareWorkersEnvAdaptor, CloudflareWorkersWaitUntilAdaptor, onCloudflareWorkers };
|
|
68
83
|
|
|
69
84
|
//# sourceMappingURL=index.js.map
|
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","Injectable","getCloudflareRuntimeContext","CloudflareBindingsService","get","key","env","env","Config","EnvAdaptor","CloudflareWorkersEnvAdaptor","get","key","value","Reflect","undefined","runWithCloudflareRuntimeContext","CloudflareWorkersEnvAdaptor","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/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\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 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';\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],\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;;;;;;;;;
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeltjs/adapter-cloudflare-workers",
|
|
3
|
-
"version": "0.10.0",
|
|
3
|
+
"version": "0.10.1-canary.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zeltjs/core": "0.10.0"
|
|
30
|
+
"@zeltjs/core": "0.10.1-canary.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "22.19.17",
|