@open-nest/workers 0.0.0-stage → 0.1.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/dist/index.d.mts +38 -0
- package/dist/index.mjs +28 -0
- package/package.json +41 -4
- package/readme.md +11 -0
- package/README.md +0 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CreateHandlerOptions, Fetcher } from "open-nest";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The `ctx` argument from a Worker `fetch` handler.
|
|
5
|
+
*/
|
|
6
|
+
export interface WorkerExecutionContext {
|
|
7
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
8
|
+
passThroughOnException(): void;
|
|
9
|
+
readonly props?: unknown;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Bindings and the raw execution context for the request in flight.
|
|
13
|
+
*/
|
|
14
|
+
export interface WorkerContext<Env> {
|
|
15
|
+
env: Env;
|
|
16
|
+
ctx: WorkerExecutionContext;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Bindings and execution context for the current Worker request.
|
|
20
|
+
*/
|
|
21
|
+
export declare function workerContext<Env>(): WorkerContext<Env>;
|
|
22
|
+
export interface WorkerFetcher<Env> {
|
|
23
|
+
(request: Request, env: Env, ctx: WorkerExecutionContext): Promise<Response>;
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the underlying Nest app instance.
|
|
26
|
+
*/
|
|
27
|
+
app: Fetcher["app"];
|
|
28
|
+
/**
|
|
29
|
+
* Closes the underlying Nest app.
|
|
30
|
+
*/
|
|
31
|
+
close: Fetcher["close"];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `createFetcher` whose handler also receives Worker bindings and `ctx`.
|
|
35
|
+
* `workerContext()` reads them for the duration of the request.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createWorkerFetcher<Env>(options: CreateHandlerOptions): WorkerFetcher<Env>;
|
|
38
|
+
//#endregion
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { createFetcher } from "open-nest";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const storage = new AsyncLocalStorage();
|
|
5
|
+
/**
|
|
6
|
+
* Bindings and execution context for the current Worker request.
|
|
7
|
+
*/
|
|
8
|
+
function workerContext() {
|
|
9
|
+
const context = storage.getStore();
|
|
10
|
+
if (!context) throw new Error("Called outside a worker request.");
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* `createFetcher` whose handler also receives Worker bindings and `ctx`.
|
|
15
|
+
* `workerContext()` reads them for the duration of the request.
|
|
16
|
+
*/
|
|
17
|
+
function createWorkerFetcher(options) {
|
|
18
|
+
const fetcher = createFetcher(options);
|
|
19
|
+
const handler = (async (request, env, ctx) => storage.run({
|
|
20
|
+
env,
|
|
21
|
+
ctx
|
|
22
|
+
}, () => fetcher(request)));
|
|
23
|
+
handler.app = () => fetcher.app();
|
|
24
|
+
handler.close = () => fetcher.close();
|
|
25
|
+
return handler;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { createWorkerFetcher, workerContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-nest/workers",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Run an open-nest application on Cloudflare Workers.",
|
|
5
|
+
"files": [
|
|
6
|
+
"package.json",
|
|
7
|
+
"readme.md",
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"bun": "./src/index.ts",
|
|
15
|
+
"types": "./dist/index.d.mts",
|
|
16
|
+
"import": "./dist/index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsdown --clean",
|
|
22
|
+
"dev": "tsdown --watch",
|
|
23
|
+
"typecheck": "bun check",
|
|
24
|
+
"test": "bun test"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@nats-io/transport-node": "3.4.0",
|
|
28
|
+
"@nestjs/microservices": "12.1.3",
|
|
29
|
+
"@nestjs/platform-express": "12.1.3",
|
|
30
|
+
"@nestjs/platform-socket.io": "12.1.3",
|
|
31
|
+
"@nestjs/websockets": "12.1.3",
|
|
32
|
+
"amqp-connection-manager": "5.0.0",
|
|
33
|
+
"class-transformer": "0.5.1",
|
|
34
|
+
"class-validator": "0.15.1",
|
|
35
|
+
"ioredis": "6.0.0",
|
|
36
|
+
"kafkajs": "2.2.4",
|
|
37
|
+
"mqtt": "5.16.0",
|
|
38
|
+
"open-nest": "0.1.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@nestjs/common": "^12.0.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# `@open-nest/workers`
|
|
2
|
+
|
|
3
|
+
Serve an [`open-nest`](https://github.com/juriadams/open-nest) handler on Cloudflare Workers.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
bun add @open-nest/workers
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
`createWorkerFetcher` returns `(request, env, ctx)`. `workerContext()` reads those bindings for the request in flight. The Worker needs `nodejs_compat`.
|
|
10
|
+
|
|
11
|
+
- [KV bindings](../../../examples/workers)
|
package/README.md
DELETED