@cossackframework/node-adapter 0.9.0 → 0.9.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.md +28 -22
- package/agent-docs.json +1 -1
- package/dist/adapter.d.ts +19 -1
- package/dist/application.d.ts +39 -0
- package/dist/index.d.ts +3 -57
- package/dist/index.js +333 -373
- package/dist/static-serve.d.ts +9 -0
- package/dist/storage.d.ts +3 -0
- package/dist/storage.js +16 -1
- package/dist/transport-routes-CjDWcC93.js +32 -0
- package/dist/vite.js +74 -68
- package/package.json +9 -9
- package/dist/runtime.d.ts +0 -7
package/dist/static-serve.d.ts
CHANGED
|
@@ -16,7 +16,16 @@ export interface StaticServeOptions {
|
|
|
16
16
|
* Create a middleware that serves static files from a directory.
|
|
17
17
|
* This is for Node.js runtime only - uses fs to read files.
|
|
18
18
|
*
|
|
19
|
+
* Files are streamed. Responses carry a weak `ETag`, `Last-Modified` and
|
|
20
|
+
* `Accept-Ranges: bytes`; `If-None-Match`/`If-Modified-Since` return 304, and a
|
|
21
|
+
* single `Range` on GET returns 206 (416 when unsatisfiable). Several ranges
|
|
22
|
+
* receive the whole file with 200.
|
|
23
|
+
*
|
|
19
24
|
* @param options - Static serving options
|
|
20
25
|
* @returns Hono middleware
|
|
21
26
|
*/
|
|
22
27
|
export declare function serveStatic(options: StaticServeOptions): (c: Context, next: Next) => Promise<void | Response>;
|
|
28
|
+
/** Filesystem-backed ASSETS binding for SSR manifest and CSS reads. */
|
|
29
|
+
export declare function createStaticAssets(options: StaticServeOptions): {
|
|
30
|
+
fetch(request: Request): Promise<Response>;
|
|
31
|
+
};
|
package/dist/storage.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export declare class LocalStorageProvider implements StorageProvider {
|
|
|
11
11
|
constructor(options: {
|
|
12
12
|
root: string;
|
|
13
13
|
});
|
|
14
|
+
/** Shared by concurrent callers; cleared on failure and when the root disappears. */
|
|
15
|
+
private initialized;
|
|
16
|
+
private ready;
|
|
14
17
|
private initialize;
|
|
15
18
|
private prefix;
|
|
16
19
|
private own;
|
package/dist/storage.js
CHANGED
|
@@ -76,6 +76,13 @@ var y = class {
|
|
|
76
76
|
if (!e?.root || typeof e.root != "string") throw new u();
|
|
77
77
|
this.root = o.resolve(e.root);
|
|
78
78
|
}
|
|
79
|
+
initialized;
|
|
80
|
+
ready() {
|
|
81
|
+
let e = this.initialized ??= this.initialize().catch((t) => {
|
|
82
|
+
throw this.initialized === e && (this.initialized = void 0), t;
|
|
83
|
+
});
|
|
84
|
+
return e;
|
|
85
|
+
}
|
|
79
86
|
async initialize() {
|
|
80
87
|
let e = this.root;
|
|
81
88
|
for (;;) try {
|
|
@@ -103,7 +110,15 @@ var y = class {
|
|
|
103
110
|
}), c = a.then(() => s);
|
|
104
111
|
d.set(i, c);
|
|
105
112
|
try {
|
|
106
|
-
|
|
113
|
+
await _(a, t), f(t);
|
|
114
|
+
let e = this.ready();
|
|
115
|
+
await e;
|
|
116
|
+
try {
|
|
117
|
+
return await n(r);
|
|
118
|
+
} catch (i) {
|
|
119
|
+
if (!h(i)) throw i;
|
|
120
|
+
return this.initialized === e && (this.initialized = void 0), f(t), await this.ready(), await n(r);
|
|
121
|
+
}
|
|
107
122
|
} catch (e) {
|
|
108
123
|
throw e?.name === "AbortError" || e instanceof u ? e : new u();
|
|
109
124
|
} finally {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region ../core/dist/shared/transport-routes.js
|
|
2
|
+
var e = Object.freeze({
|
|
3
|
+
rpc: "/crpc",
|
|
4
|
+
upload: "/upload",
|
|
5
|
+
sse: "/sse/:componentRouteId",
|
|
6
|
+
websocket: "/ws/:id"
|
|
7
|
+
}), t = {
|
|
8
|
+
rpc: "RPC calls",
|
|
9
|
+
upload: "RPC calls with file uploads",
|
|
10
|
+
sse: "server-sent event streams",
|
|
11
|
+
websocket: "component WebSocket connections"
|
|
12
|
+
};
|
|
13
|
+
function n(n) {
|
|
14
|
+
let r = e[n], i = r.split("/"), a = i.findIndex((e) => e.startsWith(":") || e.includes("*"));
|
|
15
|
+
return a === -1 ? {
|
|
16
|
+
path: r,
|
|
17
|
+
match: "exact",
|
|
18
|
+
route: r,
|
|
19
|
+
purpose: t[n]
|
|
20
|
+
} : {
|
|
21
|
+
path: i.slice(0, a).join("/"),
|
|
22
|
+
match: "namespace",
|
|
23
|
+
route: r,
|
|
24
|
+
purpose: t[n]
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var r = Object.freeze(Object.keys(e).map((e) => Object.freeze(n(e))));
|
|
28
|
+
function i(t, ...n) {
|
|
29
|
+
return (n.length ? r.filter((t) => n.some((n) => e[n] === t.route)) : r).some((e) => e.match === "exact" ? t === e.path : t.startsWith(`${e.path}/`));
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { i as t };
|
package/dist/vite.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { t as e } from "./transport-routes-CjDWcC93.js";
|
|
2
|
+
import { relative as t } from "node:path";
|
|
3
|
+
import { getRequestListener as n } from "@hono/node-server";
|
|
4
|
+
import { isRunnableDevEnvironment as r, loadEnv as i } from "vite";
|
|
5
|
+
import { EventEmitter as a } from "node:events";
|
|
5
6
|
//#region src/vite.ts
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
function o(e) {
|
|
8
|
+
if (r(e)) return !0;
|
|
9
|
+
let t = e.runner;
|
|
10
|
+
return typeof t?.import == "function" && typeof t.clearCache == "function" && typeof e.moduleGraph?.invalidateAll == "function";
|
|
11
|
+
}
|
|
12
|
+
function s(r = {}) {
|
|
13
|
+
let s = r.shutdownTimeoutMs ?? 5e3;
|
|
14
|
+
if (!Number.isFinite(s) || s <= 0) throw TypeError("shutdownTimeoutMs must be positive and finite");
|
|
15
|
+
let c, l;
|
|
10
16
|
return {
|
|
11
17
|
name: "cossack-node-development",
|
|
12
18
|
apply: "serve",
|
|
@@ -14,98 +20,98 @@ function a(a = {}) {
|
|
|
14
20
|
appType: "custom",
|
|
15
21
|
environments: { ssr: { resolve: { noExternal: ["@cossackframework/node-adapter", "@cossackframework/core"] } } }
|
|
16
22
|
}),
|
|
17
|
-
configureServer(
|
|
18
|
-
if (
|
|
19
|
-
let
|
|
20
|
-
if (!
|
|
21
|
-
let
|
|
22
|
-
...
|
|
23
|
+
configureServer(t) {
|
|
24
|
+
if (t.config.server.middlewareMode) return;
|
|
25
|
+
let u = t.environments.ssr;
|
|
26
|
+
if (!o(u)) throw Error("Cossack Node development requires a runnable Vite SSR environment");
|
|
27
|
+
let d = {
|
|
28
|
+
...i(t.config.mode, t.config.envDir, ""),
|
|
23
29
|
...process.env
|
|
24
|
-
},
|
|
25
|
-
if (!
|
|
26
|
-
|
|
27
|
-
let n = Promise.resolve().then(() =>
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
for (; !
|
|
33
|
-
let e =
|
|
34
|
-
|
|
35
|
-
let t = await
|
|
36
|
-
if (typeof t.app?.fetch != "function") throw
|
|
30
|
+
}, f, p = !1, m = 0, h = !1, g, _ = /* @__PURE__ */ new Set(), v = /* @__PURE__ */ new Set(), y = /* @__PURE__ */ new WeakSet(), b = (e) => {
|
|
31
|
+
if (!e.runtime || y.has(e.runtime)) return;
|
|
32
|
+
y.add(e.runtime);
|
|
33
|
+
let n = Promise.resolve().then(() => e.runtime?.dispose()).then(() => {});
|
|
34
|
+
v.add(n), n.catch((e) => t.config.logger.error(`[cossack node] cleanup failed: ${e}`)).finally(() => v.delete(n));
|
|
35
|
+
}, x = () => {
|
|
36
|
+
f &&= (f.detach?.(), b(f.entry), void 0);
|
|
37
|
+
}, S = () => p ? Promise.reject(/* @__PURE__ */ Error("Cossack Node development server is closing")) : f ? Promise.resolve(f) : g ??= (async () => {
|
|
38
|
+
for (; !p;) {
|
|
39
|
+
let e = m;
|
|
40
|
+
h &&= (u.moduleGraph.invalidateAll(), u.runner.clearCache(), !1);
|
|
41
|
+
let t = await u.runner.import(r.entry ?? "/src/index.ts");
|
|
42
|
+
if (typeof t.app?.fetch != "function") throw b(t), TypeError("Cossack Node entry must export app.fetch");
|
|
37
43
|
let n;
|
|
38
44
|
try {
|
|
39
|
-
n = t.createEnv ? await t.createEnv(
|
|
45
|
+
n = t.createEnv ? await t.createEnv(d) : t.env;
|
|
40
46
|
} catch (e) {
|
|
41
|
-
throw
|
|
47
|
+
throw b(t), e;
|
|
42
48
|
}
|
|
43
|
-
if (
|
|
44
|
-
|
|
49
|
+
if (p || e !== m) {
|
|
50
|
+
b(t);
|
|
45
51
|
continue;
|
|
46
52
|
}
|
|
47
|
-
let
|
|
53
|
+
let i = {
|
|
48
54
|
entry: t,
|
|
49
55
|
env: n,
|
|
50
|
-
upgrades: new
|
|
56
|
+
upgrades: new a()
|
|
51
57
|
};
|
|
52
58
|
try {
|
|
53
|
-
|
|
59
|
+
i.detach = t.runtime?.attach?.(i.upgrades, (e) => t.app.fetch(e, n));
|
|
54
60
|
} catch (e) {
|
|
55
|
-
throw
|
|
61
|
+
throw b(t), e;
|
|
56
62
|
}
|
|
57
|
-
return
|
|
63
|
+
return f = i, i;
|
|
58
64
|
}
|
|
59
65
|
throw Error("Cossack Node development server is closing");
|
|
60
66
|
})().catch((e) => {
|
|
61
|
-
throw
|
|
67
|
+
throw h = !0, e;
|
|
62
68
|
}).finally(() => {
|
|
63
|
-
|
|
69
|
+
g = void 0;
|
|
64
70
|
});
|
|
65
|
-
|
|
66
|
-
let
|
|
67
|
-
if (!
|
|
68
|
-
|
|
69
|
-
let
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}).catch((
|
|
73
|
-
|
|
71
|
+
l = () => (m++, h = !0, x(), S());
|
|
72
|
+
let C = (n, r, i) => {
|
|
73
|
+
if (!e(n.url?.split("?", 1)[0] ?? "", "websocket")) return;
|
|
74
|
+
_.add(r);
|
|
75
|
+
let a = () => _.delete(r);
|
|
76
|
+
r.once("close", a), r.on("error", () => r.destroy()), S().then((e) => {
|
|
77
|
+
p || r.destroyed || e.upgrades.emit("upgrade", n, r, i) || r.end("HTTP/1.1 503 Unavailable\r\nConnection: close\r\nContent-Length: 0\r\n\r\n");
|
|
78
|
+
}).catch((e) => {
|
|
79
|
+
t.config.logger.error(`[cossack node] upgrade failed: ${e}`), r.destroy();
|
|
74
80
|
}).finally(() => {
|
|
75
|
-
|
|
81
|
+
a(), r.off("close", a);
|
|
76
82
|
});
|
|
77
83
|
};
|
|
78
|
-
|
|
79
|
-
let
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
for (let e of
|
|
83
|
-
|
|
84
|
-
let
|
|
85
|
-
await
|
|
84
|
+
t.httpServer?.on("upgrade", C);
|
|
85
|
+
let w;
|
|
86
|
+
return c = () => w ??= (async () => {
|
|
87
|
+
p = !0, l = void 0, t.httpServer?.off("upgrade", C);
|
|
88
|
+
for (let e of _) e.destroy();
|
|
89
|
+
_.clear(), x();
|
|
90
|
+
let e = (async () => {
|
|
91
|
+
await g?.catch(() => {}), await Promise.allSettled([...v]);
|
|
86
92
|
})(), n;
|
|
87
93
|
try {
|
|
88
|
-
await Promise.race([
|
|
94
|
+
await Promise.race([e, new Promise((e) => {
|
|
89
95
|
n = setTimeout(() => {
|
|
90
|
-
|
|
91
|
-
},
|
|
96
|
+
t.config.logger.warn("[cossack node] application cleanup exceeded the shutdown deadline"), e();
|
|
97
|
+
}, s);
|
|
92
98
|
})]);
|
|
93
99
|
} finally {
|
|
94
100
|
clearTimeout(n);
|
|
95
101
|
}
|
|
96
|
-
})(), () =>
|
|
97
|
-
|
|
102
|
+
})(), () => t.middlewares.use((e, t, r) => {
|
|
103
|
+
S().then(({ entry: r, env: i }) => n((e) => r.app.fetch(e, i))(e, t)).catch(r);
|
|
98
104
|
});
|
|
99
105
|
},
|
|
100
106
|
hotUpdate: {
|
|
101
107
|
order: "post",
|
|
102
|
-
async handler({ file:
|
|
103
|
-
if (this.environment.name !== "ssr" || !
|
|
104
|
-
let o =
|
|
105
|
-
if (!(!n.length && !(o.startsWith("src/") && !o.startsWith("src/client/")
|
|
108
|
+
async handler({ file: e, modules: n, read: r, type: i, server: a }) {
|
|
109
|
+
if (this.environment.name !== "ssr" || !l) return;
|
|
110
|
+
let o = t(a.config.root, e).replaceAll("\\", "/"), s = /\.[cm]?[jt]sx?$|\.mdx?$/.test(o) && !o.includes("node_modules/"), c = o.startsWith("../") && i !== "update";
|
|
111
|
+
if (!(!n.length && !(s && (c || o.startsWith("src/") && !o.startsWith("src/client/"))))) {
|
|
106
112
|
i !== "delete" && await r();
|
|
107
113
|
try {
|
|
108
|
-
await
|
|
114
|
+
await l();
|
|
109
115
|
} catch (e) {
|
|
110
116
|
a.config.logger.error(`[cossack node] reload failed: ${e}`);
|
|
111
117
|
}
|
|
@@ -114,9 +120,9 @@ function a(a = {}) {
|
|
|
114
120
|
}
|
|
115
121
|
},
|
|
116
122
|
async closeBundle() {
|
|
117
|
-
await
|
|
123
|
+
await c?.();
|
|
118
124
|
}
|
|
119
125
|
};
|
|
120
126
|
}
|
|
121
127
|
//#endregion
|
|
122
|
-
export {
|
|
128
|
+
export { s as cossackNode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cossackframework/node-adapter",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Node.js runtime adapter for the Cossack Framework",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,22 +38,22 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"
|
|
41
|
+
"@hono/node-server": "^2.1.6",
|
|
42
|
+
"nodemailer": "^10.4.0",
|
|
42
43
|
"ws": ">=8.21.0",
|
|
43
|
-
"@
|
|
44
|
-
"@cossackframework/core": "0.9.0"
|
|
44
|
+
"@cossackframework/core": "0.9.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/nodemailer": "^8.0.1",
|
|
48
48
|
"@types/ws": "^8.18.0",
|
|
49
|
-
"hono": "^4.13.
|
|
49
|
+
"hono": "^4.13.18",
|
|
50
50
|
"typescript": "^7.0.2",
|
|
51
|
-
"vite": "^8.1.
|
|
52
|
-
"vitest": "^4.1.
|
|
51
|
+
"vite": "^8.1.6",
|
|
52
|
+
"vitest": "^4.1.12"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"hono": "^4.13.
|
|
56
|
-
"vite": "^8.1.
|
|
55
|
+
"hono": "^4.13.18",
|
|
56
|
+
"vite": "^8.1.6"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"vite": {
|
package/dist/runtime.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'ws';
|
|
2
|
-
import { InMemoryWebSocketRuntime, type Cossack } from '@cossackframework/core';
|
|
3
|
-
import type { Context } from 'hono';
|
|
4
|
-
export declare class NodeWebSocketRuntime extends InMemoryWebSocketRuntime<WebSocket> {
|
|
5
|
-
constructor(component: Cossack);
|
|
6
|
-
addClient(ws: WebSocket, user?: unknown, context?: Context, authorize?: (client: WebSocket, operation: (context: Context) => Promise<void>) => Promise<boolean>): void;
|
|
7
|
-
}
|