@guren/server 2.28.0 → 2.29.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/{DocsViewerServiceProvider-BMbcTYVw.js → DocsViewerServiceProvider-BVPZjwQp.js} +7 -1
- package/dist/{Gate-CYfoGQqh.js → Gate-DFiuutZm.js} +1 -25
- package/dist/{McpServiceProvider-PGFPlYTy.js → McpServiceProvider-CvFExxdJ.js} +45 -2
- package/dist/{Resource-BhOua2OB.js → Resource-ZMJH4lyD.js} +2 -1
- package/dist/authorization/index.js +2 -2
- package/dist/{authorization-CKOLYWvi.js → authorization-DUjeyGWh.js} +2 -1
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +2 -0
- package/dist/{cache-BlXopnH1.js → cache-C2Im3l7t.js} +27 -12
- package/dist/{dev-banner-bekDeLgL.js → dev-banner-BAXzolUl.js} +1 -1
- package/dist/http/Application.d.ts +10 -54
- package/dist/http/boot-sequence.d.ts +8 -0
- package/dist/http/server-lifecycle.d.ts +88 -0
- package/dist/index.js +97 -278
- package/dist/internal/testing.js +1 -1
- package/dist/introspection/types.d.ts +6 -0
- package/dist/mcp/McpServiceProvider.d.ts +7 -0
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/runtime-error-capture.d.ts +24 -0
- package/dist/mcp/runtime-errors.d.ts +59 -0
- package/dist/mvc/Router.d.ts +2 -0
- package/dist/request-container-BbuH0JJy.js +25 -0
- package/dist/runtime/index.js +2 -2
- package/dist/runtime-error-capture-BclelWhA.js +48 -0
- package/dist/runtime-errors-DOPBX0Ox.js +135 -0
- package/dist/vite-manifest-DO0pU1vm.js +391 -0
- package/package.json +3 -3
- package/dist/endpoint-Coq0K_6I.js +0 -26
- package/dist/vite-manifest-wPxfAzjW.js +0 -146
package/dist/{DocsViewerServiceProvider-BMbcTYVw.js → DocsViewerServiceProvider-BVPZjwQp.js}
RENAMED
|
@@ -27,7 +27,7 @@ var DocsViewerServiceProvider = class extends ServiceProvider {
|
|
|
27
27
|
hono.use(`${DOCS_VIEWER_PATH}/*`, guard);
|
|
28
28
|
let shell = null;
|
|
29
29
|
hono.get(DOCS_VIEWER_PATH, async (ctx) => {
|
|
30
|
-
shell ??= readFile(cli.docsViewerAssetPath(), "utf-8");
|
|
30
|
+
shell ??= cli.docsViewerShell ? Promise.resolve(cli.docsViewerShell()) : readFile(cli.docsViewerAssetPath(), "utf-8");
|
|
31
31
|
return ctx.html(await shell);
|
|
32
32
|
});
|
|
33
33
|
let cached = null;
|
|
@@ -52,6 +52,12 @@ var DocsViewerServiceProvider = class extends ServiceProvider {
|
|
|
52
52
|
ETag: etag
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
|
+
hono.get(`${DOCS_VIEWER_PATH}/plans/:slug`, async (ctx) => {
|
|
56
|
+
if (cli.docsViewerPlanPage === void 0) return ctx.json({ message: "This @guren/cli does not serve plan pages; upgrade it" }, 404);
|
|
57
|
+
const page = await cli.docsViewerPlanPage(cwd, ctx.req.param("slug"));
|
|
58
|
+
if (page === void 0) return ctx.json({ message: "No rendered page for this plan (bunx guren plan:render <plan>)" }, 404);
|
|
59
|
+
return ctx.html(page, 200, { "Cache-Control": "no-store" });
|
|
60
|
+
});
|
|
55
61
|
let mermaid = null;
|
|
56
62
|
hono.get(`${DOCS_VIEWER_PATH}/assets/mermaid.js`, async (ctx) => {
|
|
57
63
|
try {
|
|
@@ -1,30 +1,6 @@
|
|
|
1
1
|
import { t as HttpException } from "./HttpException-BlQ2yEmT.js";
|
|
2
2
|
import { h as warnDeprecatedSetter, i as bindAmbient, m as warnDeprecatedGetter, n as ambientBinding } from "./default-application-DWwscxfW.js";
|
|
3
3
|
import { r as getAuthContext } from "./context-af2n5abO.js";
|
|
4
|
-
//#region src/http/request-container.ts
|
|
5
|
-
/**
|
|
6
|
-
* Context variable the serving Application's container is stamped under
|
|
7
|
-
* (RFC 0023 §2). The stamp is the first middleware `Application` mounts, so
|
|
8
|
-
* nothing an app registers runs ahead of it. The one place a middleware
|
|
9
|
-
* reaches its app's container without holding the app.
|
|
10
|
-
*/
|
|
11
|
-
const CONTAINER_CONTEXT_KEY = "guren.container";
|
|
12
|
-
/**
|
|
13
|
-
* The container of the Application serving `ctx`, or undefined off an
|
|
14
|
-
* Application (bare Hono). Judged by shape rather than `instanceof`: a test
|
|
15
|
-
* double answering every key must not pass as a container.
|
|
16
|
-
*/
|
|
17
|
-
function tryGetRequestContainer(ctx) {
|
|
18
|
-
const container = ctx.get(CONTAINER_CONTEXT_KEY);
|
|
19
|
-
return typeof container?.makeOptional === "function" ? container : void 0;
|
|
20
|
-
}
|
|
21
|
-
/** The container of the Application serving `ctx`; throws off an Application (bare Hono). */
|
|
22
|
-
function getRequestContainer(ctx) {
|
|
23
|
-
const container = tryGetRequestContainer(ctx);
|
|
24
|
-
if (!container) throw new Error("No Application container on this request. The container is stamped by Application; a bare Hono app has none — pass the service explicitly there.");
|
|
25
|
-
return container;
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
4
|
//#region src/errors/exceptions/AuthorizationException.ts
|
|
29
5
|
/** 403: the user is authenticated but not allowed to perform the action. */
|
|
30
6
|
var AuthorizationException = class AuthorizationException extends HttpException {
|
|
@@ -291,4 +267,4 @@ async function authorize(ability, ...args) {
|
|
|
291
267
|
return resolveGate().authorize(ability, ...args);
|
|
292
268
|
}
|
|
293
269
|
//#endregion
|
|
294
|
-
export { cannot as a, denialToException as c, resolveGate as d, setGate as f,
|
|
270
|
+
export { cannot as a, denialToException as c, resolveGate as d, setGate as f, can as i, getGate as l, Response as n, createGate as o, AuthorizationException as p, authorize as r, defineGate as s, Gate as t, isAuthorizationResponse as u };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
|
|
2
2
|
import { n as ServiceProvider } from "./ServiceProvider-G0YclITd.js";
|
|
3
|
-
import { n as createMcpAccessGuard,
|
|
3
|
+
import { a as MCP_ENDPOINT_PATH, n as RUNTIME_ERRORS_PATH, o as createMcpAccessGuard, s as isMcpEndpointEnabled, t as RUNTIME_ERRORS_BINDING } from "./runtime-error-capture-BclelWhA.js";
|
|
4
4
|
//#region src/mcp/McpServiceProvider.ts
|
|
5
5
|
var McpServiceProvider_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
DEV_MCP_CLI_TOO_OLD: () => DEV_MCP_CLI_TOO_OLD,
|
|
@@ -34,7 +34,50 @@ var McpServiceProvider = class extends ServiceProvider {
|
|
|
34
34
|
console.warn(`[guren] ${DEV_MCP_CLI_TOO_OLD}`);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
if (cli.createDevCenterHandler) {
|
|
38
|
+
const center = cli.createDevCenterHandler({ cwd: process.cwd() });
|
|
39
|
+
for (const path of [
|
|
40
|
+
"/_guren",
|
|
41
|
+
"/_guren/",
|
|
42
|
+
"/_guren/graph.json"
|
|
43
|
+
]) {
|
|
44
|
+
hono.use(path, createMcpAccessGuard());
|
|
45
|
+
hono.get(path, (ctx) => isMcpEndpointEnabled() ? center.fetch(ctx.req.raw) : ctx.notFound());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const buffer = this.container.makeOptional(RUNTIME_ERRORS_BINDING);
|
|
49
|
+
const runtimeErrors = buffer ? (query) => isMcpEndpointEnabled() ? buffer.read(query) : {
|
|
50
|
+
schemaVersion: 1,
|
|
51
|
+
status: "unavailable",
|
|
52
|
+
reason: "Runtime collection is disabled."
|
|
53
|
+
} : void 0;
|
|
54
|
+
const handler = cli.createDevMcpHandler({
|
|
55
|
+
cwd: process.cwd(),
|
|
56
|
+
runtimeErrors
|
|
57
|
+
});
|
|
58
|
+
hono.use(RUNTIME_ERRORS_PATH, createMcpAccessGuard());
|
|
59
|
+
hono.get(RUNTIME_ERRORS_PATH, (ctx) => {
|
|
60
|
+
ctx.header("Cache-Control", "no-store");
|
|
61
|
+
if (!isMcpEndpointEnabled()) return ctx.notFound();
|
|
62
|
+
if (!runtimeErrors) return ctx.json({
|
|
63
|
+
schemaVersion: 1,
|
|
64
|
+
status: "unavailable",
|
|
65
|
+
reason: "Runtime collector is not available."
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
return ctx.json(runtimeErrors({
|
|
69
|
+
sessionId: ctx.req.query("sessionId"),
|
|
70
|
+
...ctx.req.query("after") !== void 0 ? { after: Number(ctx.req.query("after")) } : {},
|
|
71
|
+
...ctx.req.query("limit") !== void 0 ? { limit: Number(ctx.req.query("limit")) } : {}
|
|
72
|
+
}));
|
|
73
|
+
} catch {
|
|
74
|
+
return ctx.json({
|
|
75
|
+
schemaVersion: 1,
|
|
76
|
+
status: "unavailable",
|
|
77
|
+
reason: "Invalid runtime cursor or limit."
|
|
78
|
+
}, 400);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
38
81
|
hono.use(MCP_ENDPOINT_PATH, createMcpAccessGuard());
|
|
39
82
|
hono.all(MCP_ENDPOINT_PATH, (c) => handler.fetch(c.req.raw));
|
|
40
83
|
}
|
|
@@ -8,7 +8,8 @@ import { n as ServiceProvider } from "./ServiceProvider-G0YclITd.js";
|
|
|
8
8
|
import { r as getAuthContext } from "./context-af2n5abO.js";
|
|
9
9
|
import { o as getApiTokenOrFail } from "./api-token-BbgDEd6j.js";
|
|
10
10
|
import { a as resolveI18n } from "./i18n-DmMKcbqj.js";
|
|
11
|
-
import {
|
|
11
|
+
import { r as tryGetRequestContainer } from "./request-container-BbuH0JJy.js";
|
|
12
|
+
import { d as resolveGate } from "./Gate-DFiuutZm.js";
|
|
12
13
|
import { t as jsx_runtime_exports } from "./jsx-runtime.js";
|
|
13
14
|
import { getCookie } from "hono/cookie";
|
|
14
15
|
import { isAbsolute, resolve } from "node:path";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as withAuthorization, n as authorizeMiddleware, o as Policy, r as authorizeResourceMiddleware, s as definePolicy, t as authorizeAllMiddleware } from "../authorization-
|
|
2
|
-
import { a as cannot, f as setGate, i as can, l as getGate, n as Response, o as createGate, r as authorize, s as defineGate, t as Gate, u as isAuthorizationResponse } from "../Gate-
|
|
1
|
+
import { a as withAuthorization, n as authorizeMiddleware, o as Policy, r as authorizeResourceMiddleware, s as definePolicy, t as authorizeAllMiddleware } from "../authorization-DUjeyGWh.js";
|
|
2
|
+
import { a as cannot, f as setGate, i as can, l as getGate, n as Response, o as createGate, r as authorize, s as defineGate, t as Gate, u as isAuthorizationResponse } from "../Gate-DFiuutZm.js";
|
|
3
3
|
export { Gate, Policy, Response, authorize, authorizeAllMiddleware, authorizeMiddleware, authorizeResourceMiddleware, can, cannot, createGate, defineGate, definePolicy, getGate, isAuthorizationResponse, setGate, withAuthorization };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as tryGetRequestContainer } from "./request-container-BbuH0JJy.js";
|
|
2
|
+
import { c as denialToException, d as resolveGate, n as Response, p as AuthorizationException } from "./Gate-DFiuutZm.js";
|
|
2
3
|
//#region src/http/middleware/capabilities.ts
|
|
3
4
|
/**
|
|
4
5
|
* Internal security-capability marker (RFC 0007): built-in middleware
|
package/dist/cache/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RedisStore, i as FileStore, n as createCacheManager, o as MemoryStore, r as TaggedCache, t as CacheManager } from "../cache-
|
|
1
|
+
import { a as RedisStore, i as FileStore, n as createCacheManager, o as MemoryStore, r as TaggedCache, t as CacheManager } from "../cache-C2Im3l7t.js";
|
|
2
2
|
export { CacheManager, FileStore, MemoryStore, RedisStore, TaggedCache, createCacheManager };
|
|
@@ -28,5 +28,7 @@ export declare class FileStore implements CacheStore {
|
|
|
28
28
|
ttl(key: string): Promise<number>;
|
|
29
29
|
/** Delete expired cache files; call periodically to free disk space. */
|
|
30
30
|
cleanup(): Promise<number>;
|
|
31
|
+
private removeIfExpired;
|
|
32
|
+
private restore;
|
|
31
33
|
getBasePath(): string;
|
|
32
34
|
}
|
|
@@ -3,8 +3,8 @@ import { n as isHotReloadRuntime, t as claimHotDisposable } from "./hot-disposab
|
|
|
3
3
|
import { t as describeDriverMap } from "./driver-map-CkQc52j-.js";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
|
-
import { mkdir, readFile, readdir, rename, rm, rmdir, unlink, writeFile } from "node:fs/promises";
|
|
7
|
-
import { existsSync } from "node:fs";
|
|
6
|
+
import { copyFile, link, mkdir, readFile, readdir, rename, rm, rmdir, unlink, writeFile } from "node:fs/promises";
|
|
7
|
+
import { constants, existsSync } from "node:fs";
|
|
8
8
|
//#region src/redis/lazy-client.ts
|
|
9
9
|
/**
|
|
10
10
|
* The one rule for a `client` option that may be an ioredis instance or a
|
|
@@ -384,10 +384,7 @@ var FileStore = class {
|
|
|
384
384
|
const filePath = this.getFilePath(key);
|
|
385
385
|
const item = await this.readCacheFile(filePath);
|
|
386
386
|
if (!item) return null;
|
|
387
|
-
if (this.isExpired(item))
|
|
388
|
-
await this.deleteCacheFile(filePath);
|
|
389
|
-
return null;
|
|
390
|
-
}
|
|
387
|
+
if (this.isExpired(item)) return null;
|
|
391
388
|
return item.value;
|
|
392
389
|
}
|
|
393
390
|
async set(key, value, ttl) {
|
|
@@ -415,7 +412,7 @@ var FileStore = class {
|
|
|
415
412
|
}
|
|
416
413
|
async delete(key) {
|
|
417
414
|
const filePath = this.getFilePath(key);
|
|
418
|
-
return this.deleteCacheFile(filePath);
|
|
415
|
+
return this.locked(filePath, () => this.deleteCacheFile(filePath));
|
|
419
416
|
}
|
|
420
417
|
async clear() {
|
|
421
418
|
if (!existsSync(this.basePath)) return;
|
|
@@ -474,10 +471,7 @@ var FileStore = class {
|
|
|
474
471
|
const filePath = this.getFilePath(key);
|
|
475
472
|
const item = await this.readCacheFile(filePath);
|
|
476
473
|
if (!item) return -2;
|
|
477
|
-
if (this.isExpired(item))
|
|
478
|
-
await this.deleteCacheFile(filePath);
|
|
479
|
-
return -2;
|
|
480
|
-
}
|
|
474
|
+
if (this.isExpired(item)) return -2;
|
|
481
475
|
if (item.expiresAt === null) return -1;
|
|
482
476
|
return Math.max(0, Math.ceil((item.expiresAt - this.now()) / 1e3));
|
|
483
477
|
}
|
|
@@ -498,11 +492,32 @@ var FileStore = class {
|
|
|
498
492
|
if (!file.endsWith(this.extension)) continue;
|
|
499
493
|
const filePath = join(subdirPath, file);
|
|
500
494
|
const item = await this.readCacheFile(filePath);
|
|
501
|
-
if (item && this.isExpired(item) && await this.
|
|
495
|
+
if (item && this.isExpired(item) && await this.locked(filePath, () => this.removeIfExpired(filePath))) cleaned++;
|
|
502
496
|
}
|
|
503
497
|
}
|
|
504
498
|
return cleaned;
|
|
505
499
|
}
|
|
500
|
+
async removeIfExpired(filePath) {
|
|
501
|
+
const grave = `${filePath}.${randomUUID()}.grave`;
|
|
502
|
+
try {
|
|
503
|
+
await rename(filePath, grave);
|
|
504
|
+
} catch {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
const item = await this.readCacheFile(grave);
|
|
508
|
+
const expired = item !== null && this.isExpired(item);
|
|
509
|
+
if (expired || await this.restore(grave, filePath)) await unlink(grave).catch(() => void 0);
|
|
510
|
+
return expired;
|
|
511
|
+
}
|
|
512
|
+
async restore(grave, filePath) {
|
|
513
|
+
for (const put of [() => link(grave, filePath), () => copyFile(grave, filePath, constants.COPYFILE_EXCL)]) try {
|
|
514
|
+
await put();
|
|
515
|
+
return true;
|
|
516
|
+
} catch (error) {
|
|
517
|
+
if (error.code === "EEXIST") return true;
|
|
518
|
+
}
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
506
521
|
getBasePath() {
|
|
507
522
|
return this.basePath;
|
|
508
523
|
}
|
|
@@ -4,7 +4,7 @@ import chalk from "chalk";
|
|
|
4
4
|
import figlet from "figlet";
|
|
5
5
|
import standard from "figlet/importable-fonts/Standard.js";
|
|
6
6
|
//#region package.json
|
|
7
|
-
var version = "2.
|
|
7
|
+
var version = "2.29.0";
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/http/dev-banner.ts
|
|
10
10
|
var dev_banner_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -12,47 +12,13 @@ import type { TranslationLoader } from '../i18n/index.js';
|
|
|
12
12
|
import { type SecurityHeadersOptions } from './middleware/security-headers.js';
|
|
13
13
|
import { type HostAuthorizationOptions } from './middleware/host-authorization.js';
|
|
14
14
|
import type { DevBannerOptions } from './dev-banner.js';
|
|
15
|
-
import {
|
|
15
|
+
import { type StartViteDevServerOptions } from './vite-dev-server.js';
|
|
16
16
|
import type { InertiaDocumentOptions, InertiaSsrRenderer } from '../mvc/inertia/InertiaEngine.js';
|
|
17
17
|
import { type SharedInertiaPropsResolver } from '../mvc/inertia/shared.js';
|
|
18
18
|
import type { EnvSchema } from '../config/env.js';
|
|
19
19
|
import type { ConfigDefinition } from '../config/define.js';
|
|
20
20
|
import type { AppManifest } from '../introspection/types.js';
|
|
21
|
-
type
|
|
22
|
-
stop?: (closeConnections?: boolean) => void | Promise<void>;
|
|
23
|
-
requestIP?: (request: Request) => {
|
|
24
|
-
address?: string;
|
|
25
|
-
} | null;
|
|
26
|
-
port?: number;
|
|
27
|
-
hostname?: string;
|
|
28
|
-
};
|
|
29
|
-
type ViteServer = Awaited<ReturnType<typeof startViteDevServer>>['server'];
|
|
30
|
-
/**
|
|
31
|
-
* The one managed Vite dev server this process runs, and who owns it. A server
|
|
32
|
-
* outlives the `listen()` that started it — a `bun --hot` reload adopts it, so
|
|
33
|
-
* two applications hold the same object and instance identity cannot tell them
|
|
34
|
-
* apart. The slot names exactly one owner at a time instead.
|
|
35
|
-
*/
|
|
36
|
-
export interface ActiveViteDevServer {
|
|
37
|
-
readonly server: ViteServer;
|
|
38
|
-
readonly localUrl: string;
|
|
39
|
-
readonly owner: Application;
|
|
40
|
-
/**
|
|
41
|
-
* Detaches the owner's process teardown handlers. Whoever replaces this record
|
|
42
|
-
* calls it: the outgoing owner is only reachable from here, and handlers left
|
|
43
|
-
* attached would still close this server on the next signal.
|
|
44
|
-
*/
|
|
45
|
-
readonly disposeTeardown: () => void;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* The ambient slots `listen()` plants on `globalThis`, which a `bun --hot`
|
|
49
|
-
* reload keeps, so the next run can find what the previous one left running.
|
|
50
|
-
* Exported for the tests that plant stand-ins; not part of the public API.
|
|
51
|
-
*/
|
|
52
|
-
export interface GurenGlobalSlots {
|
|
53
|
-
__gurenActiveServer?: BunServer;
|
|
54
|
-
__gurenActiveViteDevServer?: ActiveViteDevServer;
|
|
55
|
-
}
|
|
21
|
+
export type { ActiveViteDevServer, GurenGlobalSlots } from './server-lifecycle.js';
|
|
56
22
|
export type BootCallback = (app: Hono) => void | Promise<void>;
|
|
57
23
|
export type { ServiceProviderConstructor } from '../container/ServiceProvider.js';
|
|
58
24
|
export type RouteRegistration = (router: Router) => void | Promise<void>;
|
|
@@ -194,10 +160,13 @@ export declare class Application {
|
|
|
194
160
|
private readonly cookielessAuthPaths;
|
|
195
161
|
/** {@link configDefinitions} with where each was listed, which ConfigServiceProvider's errors name. */
|
|
196
162
|
readonly configEntries: ReadonlyArray<ConfiguredDefinition>;
|
|
197
|
-
private
|
|
163
|
+
private routeRegistration?;
|
|
164
|
+
private bootSequence?;
|
|
198
165
|
private bootPromise?;
|
|
199
166
|
private manifestPromise?;
|
|
200
167
|
private bootAttempted;
|
|
168
|
+
/** Settles once the dev-only runtime error buffer is bound; boot waits for it so McpServiceProvider sees the binding. */
|
|
169
|
+
private runtimeErrorsLoaded?;
|
|
201
170
|
constructor(options?: ApplicationOptions);
|
|
202
171
|
get auth(): AuthManager;
|
|
203
172
|
get authOptions(): AuthPluginOptions | undefined;
|
|
@@ -234,9 +203,9 @@ export declare class Application {
|
|
|
234
203
|
/**
|
|
235
204
|
* Registers providers, runs the boot callback, mounts routes, boots providers.
|
|
236
205
|
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
206
|
+
* Concurrent callers share a boot. On failure, a later call resumes at the
|
|
207
|
+
* failed step; completed steps stay complete. A throwing hook must undo its
|
|
208
|
+
* own partial effects or be safe to retry; otherwise construct a fresh app.
|
|
240
209
|
*/
|
|
241
210
|
boot(): Promise<void>;
|
|
242
211
|
/**
|
|
@@ -293,7 +262,7 @@ export declare class Application {
|
|
|
293
262
|
* or when called twice. `closeActiveConnections` forces in-flight requests
|
|
294
263
|
* closed, matching Bun's own `stop()`. The managed Vite dev server goes too,
|
|
295
264
|
* unless a later `listen()` adopted it. Both closes are bounded
|
|
296
|
-
* (
|
|
265
|
+
* (GUREN_BUN_STOP_TIMEOUT_MS and GUREN_VITE_CLOSE_TIMEOUT_MS) and then abandoned.
|
|
297
266
|
*/
|
|
298
267
|
stop(closeActiveConnections?: boolean): Promise<void>;
|
|
299
268
|
register(provider: ServiceProviderConstructor): this;
|
|
@@ -305,19 +274,6 @@ export declare class Application {
|
|
|
305
274
|
* keeps it out of deploy bundles, so a call there prints nothing.
|
|
306
275
|
*/
|
|
307
276
|
logDevServerBanner(options: DevBannerOptions): void;
|
|
308
|
-
/**
|
|
309
|
-
* Closes the managed Vite dev server, but only while this application still
|
|
310
|
-
* owns it: another `listen()` may have adopted the same object, and closing it
|
|
311
|
-
* then would take the asset server out from under an app serving from it. The
|
|
312
|
-
* slot's record is the one place that distinction exists.
|
|
313
|
-
*/
|
|
314
|
-
private closeViteDevServer;
|
|
315
|
-
/**
|
|
316
|
-
* Attaches this application's Vite teardown handlers and returns the disposer.
|
|
317
|
-
* It is stored in the active-record slot, not on this instance, because
|
|
318
|
-
* whoever takes ownership next is the one that has to call it.
|
|
319
|
-
*/
|
|
320
|
-
private registerViteTeardown;
|
|
321
277
|
private registerBunTeardown;
|
|
322
278
|
}
|
|
323
279
|
export declare function createApp(options?: ApplicationOptions): Application;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Successful steps stay complete; a rejected step must be safe for its owner to retry. */
|
|
2
|
+
export declare class BootSequence {
|
|
3
|
+
private readonly steps;
|
|
4
|
+
private next;
|
|
5
|
+
private pending?;
|
|
6
|
+
constructor(steps: ReadonlyArray<() => void | Promise<void>>);
|
|
7
|
+
run(): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Application, ApplicationListenOptions } from './Application.js';
|
|
2
|
+
import type { startViteDevServer } from './vite-dev-server.js';
|
|
3
|
+
export type BunServer = {
|
|
4
|
+
stop?: (closeConnections?: boolean) => void | Promise<void>;
|
|
5
|
+
requestIP?: (request: Request) => {
|
|
6
|
+
address?: string;
|
|
7
|
+
} | null;
|
|
8
|
+
port?: number;
|
|
9
|
+
hostname?: string;
|
|
10
|
+
};
|
|
11
|
+
export type ViteServer = Awaited<ReturnType<typeof startViteDevServer>>['server'];
|
|
12
|
+
export declare const MANAGED_VITE_ENV_FLAG = "GUREN_MANAGED_VITE_DEV_SERVER";
|
|
13
|
+
/**
|
|
14
|
+
* The one managed Vite dev server this process runs, and who owns it. A server
|
|
15
|
+
* outlives the `listen()` that started it — a `bun --hot` reload adopts it, so
|
|
16
|
+
* two applications hold the same object and instance identity cannot tell them
|
|
17
|
+
* apart. The slot names exactly one owner at a time instead.
|
|
18
|
+
*/
|
|
19
|
+
export interface ActiveViteDevServer {
|
|
20
|
+
readonly server: ViteServer;
|
|
21
|
+
readonly localUrl: string;
|
|
22
|
+
readonly owner: Application;
|
|
23
|
+
/**
|
|
24
|
+
* Detaches the owner's process teardown handlers. Whoever replaces this record
|
|
25
|
+
* calls it: the outgoing owner is only reachable from here, and handlers left
|
|
26
|
+
* attached would still close this server on the next signal.
|
|
27
|
+
*/
|
|
28
|
+
readonly disposeTeardown: () => void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The ambient slots `listen()` plants on `globalThis`, which a `bun --hot`
|
|
32
|
+
* reload keeps, so the next run can find what the previous one left running.
|
|
33
|
+
* Exported for the tests that plant stand-ins; not part of the public API.
|
|
34
|
+
*/
|
|
35
|
+
export interface GurenGlobalSlots {
|
|
36
|
+
__gurenActiveServer?: BunServer;
|
|
37
|
+
__gurenActiveViteDevServer?: ActiveViteDevServer;
|
|
38
|
+
}
|
|
39
|
+
type GurenGlobal = typeof globalThis & GurenGlobalSlots;
|
|
40
|
+
export declare function getGlobalState(): GurenGlobal;
|
|
41
|
+
/** The bound on one server `stop()`, and whether hitting it is reported. */
|
|
42
|
+
interface StopBound {
|
|
43
|
+
timeoutMs: number;
|
|
44
|
+
warn: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Silent: on Bun 1.3.x it is hit on every reload, and there is nothing to
|
|
48
|
+
* report. `GUREN_BUN_STOP_TIMEOUT_MS` can only shorten it: it is set for a
|
|
49
|
+
* production drain, which a reload never is.
|
|
50
|
+
*/
|
|
51
|
+
export declare function hotReloadStopBound(): StopBound;
|
|
52
|
+
/** `stop()` bounded by `bound` ({@link bunStopTimeoutMs} by default), warning rather than throwing. */
|
|
53
|
+
export declare function stopBunServerBounded(server: BunServer, closeActiveConnections: boolean, bound?: StopBound): Promise<void>;
|
|
54
|
+
export declare function stopActiveBunServer(closeActiveConnections?: boolean, bound?: StopBound): Promise<void>;
|
|
55
|
+
export declare function setActiveBunServer(server?: BunServer): void;
|
|
56
|
+
/**
|
|
57
|
+
* Gives up the process-wide slot, but only while it still holds `server`: a
|
|
58
|
+
* `listen()` that completed inside the caller's await has repointed it at a
|
|
59
|
+
* live server, which clearing would strip of its exit teardown.
|
|
60
|
+
*/
|
|
61
|
+
export declare function releaseActiveBunServer(server: BunServer): void;
|
|
62
|
+
/**
|
|
63
|
+
* `close()` bounded by {@link viteCloseTimeoutMs}: resolves once the server
|
|
64
|
+
* closed, failed (warned), or ran out the clock (warned, abandoned).
|
|
65
|
+
*/
|
|
66
|
+
export declare function closeViteDevServerBounded(server: ViteServer): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Closes the managed Vite dev server whoever owns it. Only `listen()`'s restart
|
|
69
|
+
* path calls this — the one case where an owner's claim does not survive.
|
|
70
|
+
*/
|
|
71
|
+
export declare function stopActiveViteDevServer(): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* The managed Vite dev server a previous `listen()` left running. Reusing it
|
|
74
|
+
* keeps the browser's HMR socket connected and skips the
|
|
75
|
+
* {@link viteCloseTimeoutMs} wait. Explicit `vite` options veto reuse: the
|
|
76
|
+
* running server was built from the *previous* call's options.
|
|
77
|
+
*/
|
|
78
|
+
export declare function reusableActiveViteDevServer(viteOption: ApplicationListenOptions['vite']): ActiveViteDevServer | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Closes the managed Vite dev server, but only while this application still
|
|
81
|
+
* owns it: another `listen()` may have adopted the same object, and closing it
|
|
82
|
+
* then would take the asset server out from under an app serving from it. The
|
|
83
|
+
* slot's record is the one place that distinction exists.
|
|
84
|
+
*/
|
|
85
|
+
export declare function closeOwnedViteDevServer(owner: Application): Promise<void>;
|
|
86
|
+
export declare function registerBunTeardown(): () => void;
|
|
87
|
+
export declare function adoptViteDevServer(owner: Application, viteServer: ViteServer, localUrl: string): void;
|
|
88
|
+
export {};
|