@guren/server 2.35.0 → 2.37.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.
Files changed (54) hide show
  1. package/dist/{DocsViewerServiceProvider-BVPZjwQp.js → DocsViewerServiceProvider-DzrxQoYh.js} +15 -4
  2. package/dist/Event-COT3f5Xd.js +28 -0
  3. package/dist/{McpServiceProvider-CXOokGax.js → McpServiceProvider-BOeQyt7u.js} +2 -0
  4. package/dist/PrivateChannel-1krGz028.js +187 -0
  5. package/dist/{Resource-y-7zzZSB.js → Resource-PhnO_wNO.js} +113 -12
  6. package/dist/agent/derive.d.ts +23 -1
  7. package/dist/agent/dispatch.d.ts +12 -1
  8. package/dist/agent/pipeline.d.ts +6 -0
  9. package/dist/agent/public.d.ts +1 -1
  10. package/dist/agent/public.js +1 -1
  11. package/dist/{api-token-1-INqeVU.js → api-token-Cs1myxf6.js} +15 -1
  12. package/dist/auth/SessionGuard.d.ts +20 -0
  13. package/dist/auth/index.js +2 -2
  14. package/dist/auth/providers/ModelUserProvider.d.ts +3 -0
  15. package/dist/auth/types.d.ts +7 -0
  16. package/dist/{auth-CO9MlQNE.js → auth-X27d4l78.js} +88 -6
  17. package/dist/broadcasting/BroadcastManager.d.ts +19 -5
  18. package/dist/broadcasting/event-target.d.ts +9 -0
  19. package/dist/broadcasting/index.d.ts +3 -1
  20. package/dist/broadcasting/index.js +3 -2
  21. package/dist/broadcasting/sender-envelope.d.ts +26 -0
  22. package/dist/broadcasting/types.d.ts +27 -2
  23. package/dist/{broadcasting-D04a3R02.js → broadcasting-Bh6QoMpy.js} +50 -95
  24. package/dist/{contained-path-BkNSBljW.js → contained-path-DOVauNQC.js} +1 -22
  25. package/dist/{dev-banner-BUrHz-LF.js → dev-banner-Uydpgbrm.js} +3 -3
  26. package/dist/{dispatch-ENWpBxbE.js → dispatch-CDNqcB3Q.js} +51 -12
  27. package/dist/events/index.js +2 -1
  28. package/dist/{events-B6gfJkCH.js → events-DW197Nur.js} +2 -28
  29. package/dist/http/vite-dev-server.d.ts +18 -1
  30. package/dist/http/vite-manifest.d.ts +4 -1
  31. package/dist/index.d.ts +7 -7
  32. package/dist/index.js +110 -23
  33. package/dist/internal/agent-principal.d.ts +8 -0
  34. package/dist/internal/testing.d.ts +1 -0
  35. package/dist/internal/testing.js +2 -2
  36. package/dist/mail/index.js +1 -1
  37. package/dist/mail/types.d.ts +9 -0
  38. package/dist/{mail-BQ2y2U5c.js → mail-D4AP4_Wd.js} +6 -1
  39. package/dist/mcp/index.js +1 -1
  40. package/dist/mvc/Router.d.ts +13 -0
  41. package/dist/mvc/inertia/InertiaEngine.d.ts +3 -0
  42. package/dist/mvc/inertia/props.d.ts +54 -3
  43. package/dist/runtime/index.js +5 -3
  44. package/dist/storage/index.js +1 -1
  45. package/dist/{storage-YPbsV9ju.js → storage-ziIKgHON.js} +2 -1
  46. package/dist/trim-slashes-BLY9hKAa.js +22 -0
  47. package/dist/vite/index.d.ts +2 -0
  48. package/dist/vite/index.js +283 -1
  49. package/dist/vite/mcp-app.d.ts +59 -0
  50. package/dist/vite/plugin.d.ts +12 -0
  51. package/dist/{vite-manifest-DO0pU1vm.js → vite-dev-server-Ag90otai.js} +25 -114
  52. package/dist/vite-manifest-BdXRybeq.js +129 -0
  53. package/package.json +2 -2
  54. package/dist/host-port-t6wQFaRu.js +0 -15
@@ -1,6 +1,3 @@
1
- import { a as trimTrailingSlashes } from "./contained-path-BkNSBljW.js";
2
- import { resolve } from "node:path";
3
- import { readFileSync } from "node:fs";
4
1
  //#region src/http/server-lifecycle.ts
5
2
  const MANAGED_VITE_ENV_FLAG = "GUREN_MANAGED_VITE_DEV_SERVER";
6
3
  const DEFAULT_DEV_ENTRY_PATH = "/resources/js/dev-entry.ts";
@@ -243,9 +240,26 @@ function adoptViteDevServer(owner, viteServer, localUrl) {
243
240
  //#endregion
244
241
  //#region src/http/vite-dev-server.ts
245
242
  /**
243
+ * The port `listen()` starts its managed Vite dev server on. `guren browser:serve`
244
+ * restates the name in packages/cli/src/browser-serve.ts; tests/browser-serve.test.ts pins the two.
245
+ */
246
+ const VITE_PORT_ENV = "GUREN_VITE_PORT";
247
+ /**
248
+ * `GUREN_VITE_PORT` as a port, or `undefined` when it is unset or blank, so the
249
+ * project's Vite config decides. Throws on anything else: a typo silently
250
+ * ignored would put two apps back on the same port.
251
+ */
252
+ function readViteDevServerPort(value = typeof process === "undefined" ? void 0 : process.env[VITE_PORT_ENV]) {
253
+ const trimmed = value?.trim();
254
+ if (!trimmed) return;
255
+ const port = /^\d{1,5}$/u.test(trimmed) ? Number(trimmed) : NaN;
256
+ if (!(port <= 65535)) throw new Error(`${VITE_PORT_ENV} must be a port number from 0 to 65535, got "${value}".`);
257
+ return port;
258
+ }
259
+ /**
246
260
  * Build the inline config the managed dev server starts with. `server.host` is
247
261
  * left undefined unless asked for, so Vite's config merge drops it and the
248
- * project's own `vite.config.ts` decides.
262
+ * project's own `vite.config.ts` decides; `server.port` likewise.
249
263
  */
250
264
  function resolveViteDevServerConfig(options = {}) {
251
265
  const { root = process.cwd(), config = {}, host, port } = options;
@@ -260,6 +274,11 @@ function resolveViteDevServerConfig(options = {}) {
260
274
  }
261
275
  };
262
276
  }
277
+ /** The port the HTTP server is bound to; Vite keeps the requested one in `config.server.port`. */
278
+ function boundPort(server) {
279
+ const address = server.httpServer?.address();
280
+ return typeof address === "object" && address ? address.port : void 0;
281
+ }
263
282
  async function startViteDevServer(options = {}) {
264
283
  const { host, port } = options;
265
284
  const { createServer } = await import("vite");
@@ -267,7 +286,7 @@ async function startViteDevServer(options = {}) {
267
286
  try {
268
287
  await server.listen();
269
288
  const resolved = server.resolvedUrls;
270
- const localUrls = resolved?.local?.length ? resolved.local : [`http://${typeof host === "string" ? host : "localhost"}:${server.config.server.port ?? port ?? 5173}`];
289
+ const localUrls = resolved?.local?.length ? resolved.local : [`http://${typeof host === "string" ? host : "localhost"}:${boundPort(server) ?? server.config.server.port ?? port ?? 5173}`];
271
290
  const networkUrls = resolved?.network ?? [];
272
291
  return {
273
292
  server,
@@ -280,112 +299,4 @@ async function startViteDevServer(options = {}) {
280
299
  }
281
300
  }
282
301
  //#endregion
283
- //#region src/http/vite-manifest.ts
284
- /**
285
- * The one rule for how Vite build output is found and addressed, shared by the
286
- * Inertia asset wiring (`inertia-assets.ts`) and `viteAsset()` (`vite-assets.ts`,
287
- * RFC 0014) so the two cannot drift: what counts as a manifest, where one may
288
- * live, which URL prefix serves the hashed files, and what "the dev server is
289
- * on" means.
290
- */
291
- /**
292
- * Where `configureInertiaAssets` serves hashed build output from. The deploy
293
- * builds restate it as `CLIENT_ASSETS_URL_PREFIX` in @guren/core's
294
- * internal/deploy-build.ts; tests/http/vite-manifest.test.ts pins the two equal.
295
- */
296
- const PUBLIC_ASSETS_URL_PREFIX = "/public/assets/";
297
- /** The Vite default the framework assumes when no dev-server URL is set. */
298
- const DEFAULT_DEV_SERVER_URL = "http://localhost:5173";
299
- /**
300
- * Production for *asset* purposes: `NODE_ENV` says so and no dev server is
301
- * configured — a configured dev server means dev asset serving even when
302
- * `NODE_ENV` is `production` (E2E runs do exactly this).
303
- */
304
- function isViteProduction(devServerUrl = process.env.VITE_DEV_SERVER_URL) {
305
- return process.env.NODE_ENV === "production" && typeof devServerUrl !== "string";
306
- }
307
- function normalizeDevServerUrl(value) {
308
- if (!value) return value;
309
- const trimmed = value.trim();
310
- if (!trimmed) return trimmed;
311
- const stripped = trimTrailingSlashes(trimmed);
312
- return stripped.length > 0 ? stripped : "/";
313
- }
314
- /**
315
- * Candidate client-manifest locations, `.vite/manifest.json` first: Vite >= 5
316
- * writes it there, so a flat `manifest.json` is likely a stale leftover. The
317
- * deploy plugins order the same pair through `@guren/core`'s deploy-build
318
- * helpers and must agree, or an app with both layouts resolves different asset
319
- * versions after a serverless deploy; `tests/http/vite-manifest.test.ts` pins it.
320
- */
321
- function clientManifestCandidates(baseDir) {
322
- const root = baseDir ?? process.cwd();
323
- return [resolve(root, "public/assets/.vite/manifest.json"), resolve(root, "public/assets/manifest.json")];
324
- }
325
- /**
326
- * `__path__` label for an injected manifest, so "entry not in the manifest"
327
- * errors name the real source rather than a path that was never read.
328
- */
329
- const INJECTED_CLIENT_MANIFEST_SOURCE = "GUREN_VITE_MANIFEST (injected by the deploy build)";
330
- const INJECTED_MANIFEST_HINT = "It must hold the Vite client manifest text (deploy plugins inject it at build time), not a path.";
331
- /**
332
- * Attach one of the manifest's bookkeeping fields. `enumerable: false` is the
333
- * invariant: a stamped field must never leak into `Object.keys` or a
334
- * re-serialization of the manifest.
335
- */
336
- function defineHidden(manifest, key, value) {
337
- Object.defineProperty(manifest, key, {
338
- value,
339
- enumerable: false
340
- });
341
- }
342
- /**
343
- * The client manifest a deploy build injected for runtimes that do not ship
344
- * `public/assets/manifest.json`: `GUREN_VITE_MANIFEST` holds the manifest *JSON
345
- * text*, not a path. Fails loudly on a value that is set but not a manifest,
346
- * because falling through to the filesystem would end in "run `bunx vite build`"
347
- * — a diagnosis pointing away from the variable that is actually broken.
348
- */
349
- function injectedClientManifest() {
350
- const raw = process.env.GUREN_VITE_MANIFEST;
351
- if (typeof raw !== "string" || raw.length === 0) return;
352
- let parsed;
353
- try {
354
- parsed = JSON.parse(raw);
355
- } catch (error) {
356
- throw new Error(`GUREN_VITE_MANIFEST is set but is not valid JSON. ${INJECTED_MANIFEST_HINT}`, { cause: error });
357
- }
358
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`GUREN_VITE_MANIFEST is set but does not hold a manifest object. ${INJECTED_MANIFEST_HINT}`);
359
- const manifest = parsed;
360
- defineHidden(manifest, "__path__", INJECTED_CLIENT_MANIFEST_SOURCE);
361
- return manifest;
362
- }
363
- function loadViteManifest(candidatePaths, label, options = {}) {
364
- const warnOnMissing = options.warnOnMissing ?? true;
365
- const command = label === "SSR" ? "bunx vite build --ssr" : "bunx vite build";
366
- for (const manifestPath of candidatePaths) try {
367
- const raw = readFileSync(manifestPath, "utf8");
368
- const manifest = JSON.parse(raw);
369
- defineHidden(manifest, "__path__", manifestPath);
370
- if (options.includeRaw) defineHidden(manifest, "__raw__", raw);
371
- return manifest;
372
- } catch (error) {
373
- if (error.code !== "ENOENT") {
374
- console.warn(`Unable to load ${label} Vite manifest at ${manifestPath}.`, error);
375
- return;
376
- }
377
- }
378
- if (warnOnMissing && candidatePaths.length) console.warn(`Unable to load ${label} Vite manifest. Checked paths:\n${candidatePaths.map((p) => ` - ${p}`).join("\n")}\nRun \`${command}\` before starting in production.`);
379
- }
380
- function getManifestFile(entry) {
381
- if (!entry) return;
382
- if (Array.isArray(entry)) return entry[0];
383
- if (typeof entry === "string") return entry;
384
- if ("file" in entry && typeof entry.file === "string") return entry.file;
385
- }
386
- function getManifestCss(entry) {
387
- if (!entry || Array.isArray(entry) || typeof entry === "string") return;
388
- return entry.css;
389
- }
390
- //#endregion
391
- export { stopBunServerBounded as C, stopActiveViteDevServer as S, registerBunTeardown as _, getManifestCss as a, setActiveBunServer as b, isViteProduction as c, startViteDevServer as d, MANAGED_VITE_ENV_FLAG as f, hotReloadStopBound as g, getGlobalState as h, clientManifestCandidates as i, loadViteManifest as l, closeOwnedViteDevServer as m, INJECTED_CLIENT_MANIFEST_SOURCE as n, getManifestFile as o, adoptViteDevServer as p, PUBLIC_ASSETS_URL_PREFIX as r, injectedClientManifest as s, DEFAULT_DEV_SERVER_URL as t, normalizeDevServerUrl as u, releaseActiveBunServer as v, stopActiveBunServer as x, reusableActiveViteDevServer as y };
302
+ export { closeOwnedViteDevServer as a, registerBunTeardown as c, setActiveBunServer as d, stopActiveBunServer as f, adoptViteDevServer as i, releaseActiveBunServer as l, stopBunServerBounded as m, startViteDevServer as n, getGlobalState as o, stopActiveViteDevServer as p, MANAGED_VITE_ENV_FLAG as r, hotReloadStopBound as s, readViteDevServerPort as t, reusableActiveViteDevServer as u };
@@ -0,0 +1,129 @@
1
+ import { n as trimTrailingSlashes } from "./trim-slashes-BLY9hKAa.js";
2
+ import { resolve } from "node:path";
3
+ import { readFileSync } from "node:fs";
4
+ //#region src/http/host-port.ts
5
+ /**
6
+ * A wildcard bind answers on every interface but is not itself dialable on
7
+ * every platform. The dev banner and `Application.listen()`'s returned address
8
+ * both render this fact.
9
+ */
10
+ function isWildcardHost(hostname) {
11
+ return hostname === "0.0.0.0" || hostname === "::";
12
+ }
13
+ /** `host:port`, bracketing an IPv6 literal so the result is dialable. */
14
+ function formatHostPort(hostname, port) {
15
+ return `${hostname.includes(":") ? `[${hostname}]` : hostname}:${port}`;
16
+ }
17
+ //#endregion
18
+ //#region src/http/vite-manifest.ts
19
+ /**
20
+ * The one rule for how Vite build output is found and addressed, shared by the
21
+ * Inertia asset wiring (`inertia-assets.ts`) and `viteAsset()` (`vite-assets.ts`,
22
+ * RFC 0014) so the two cannot drift: what counts as a manifest, where one may
23
+ * live, which URL prefix serves the hashed files, and what "the dev server is
24
+ * on" means.
25
+ */
26
+ /**
27
+ * Where `configureInertiaAssets` serves hashed build output from. The deploy
28
+ * builds restate it as `CLIENT_ASSETS_URL_PREFIX` in @guren/core's
29
+ * internal/deploy-build.ts; tests/http/vite-manifest.test.ts pins the two equal.
30
+ */
31
+ const PUBLIC_ASSETS_URL_PREFIX = "/public/assets/";
32
+ /**
33
+ * The Vite default the framework assumes when no dev-server URL is set. Not
34
+ * `GUREN_VITE_PORT`: a managed start publishes the URL Vite bound instead.
35
+ */
36
+ const DEFAULT_DEV_SERVER_URL = "http://localhost:5173";
37
+ /**
38
+ * Production for *asset* purposes: `NODE_ENV` says so and no dev server is
39
+ * configured — a configured dev server means dev asset serving even when
40
+ * `NODE_ENV` is `production` (E2E runs do exactly this).
41
+ */
42
+ function isViteProduction(devServerUrl = process.env.VITE_DEV_SERVER_URL) {
43
+ return process.env.NODE_ENV === "production" && typeof devServerUrl !== "string";
44
+ }
45
+ function normalizeDevServerUrl(value) {
46
+ if (!value) return value;
47
+ const trimmed = value.trim();
48
+ if (!trimmed) return trimmed;
49
+ const stripped = trimTrailingSlashes(trimmed);
50
+ return stripped.length > 0 ? stripped : "/";
51
+ }
52
+ /**
53
+ * Candidate client-manifest locations, `.vite/manifest.json` first: Vite >= 5
54
+ * writes it there, so a flat `manifest.json` is likely a stale leftover. The
55
+ * deploy plugins order the same pair through `@guren/core`'s deploy-build
56
+ * helpers and must agree, or an app with both layouts resolves different asset
57
+ * versions after a serverless deploy; `tests/http/vite-manifest.test.ts` pins it.
58
+ */
59
+ function clientManifestCandidates(baseDir) {
60
+ const root = baseDir ?? process.cwd();
61
+ return [resolve(root, "public/assets/.vite/manifest.json"), resolve(root, "public/assets/manifest.json")];
62
+ }
63
+ /**
64
+ * `__path__` label for an injected manifest, so "entry not in the manifest"
65
+ * errors name the real source rather than a path that was never read.
66
+ */
67
+ const INJECTED_CLIENT_MANIFEST_SOURCE = "GUREN_VITE_MANIFEST (injected by the deploy build)";
68
+ const INJECTED_MANIFEST_HINT = "It must hold the Vite client manifest text (deploy plugins inject it at build time), not a path.";
69
+ /**
70
+ * Attach one of the manifest's bookkeeping fields. `enumerable: false` is the
71
+ * invariant: a stamped field must never leak into `Object.keys` or a
72
+ * re-serialization of the manifest.
73
+ */
74
+ function defineHidden(manifest, key, value) {
75
+ Object.defineProperty(manifest, key, {
76
+ value,
77
+ enumerable: false
78
+ });
79
+ }
80
+ /**
81
+ * The client manifest a deploy build injected for runtimes that do not ship
82
+ * `public/assets/manifest.json`: `GUREN_VITE_MANIFEST` holds the manifest *JSON
83
+ * text*, not a path. Fails loudly on a value that is set but not a manifest,
84
+ * because falling through to the filesystem would end in "run `bunx vite build`"
85
+ * — a diagnosis pointing away from the variable that is actually broken.
86
+ */
87
+ function injectedClientManifest() {
88
+ const raw = process.env.GUREN_VITE_MANIFEST;
89
+ if (typeof raw !== "string" || raw.length === 0) return;
90
+ let parsed;
91
+ try {
92
+ parsed = JSON.parse(raw);
93
+ } catch (error) {
94
+ throw new Error(`GUREN_VITE_MANIFEST is set but is not valid JSON. ${INJECTED_MANIFEST_HINT}`, { cause: error });
95
+ }
96
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`GUREN_VITE_MANIFEST is set but does not hold a manifest object. ${INJECTED_MANIFEST_HINT}`);
97
+ const manifest = parsed;
98
+ defineHidden(manifest, "__path__", INJECTED_CLIENT_MANIFEST_SOURCE);
99
+ return manifest;
100
+ }
101
+ function loadViteManifest(candidatePaths, label, options = {}) {
102
+ const warnOnMissing = options.warnOnMissing ?? true;
103
+ const command = label === "SSR" ? "bunx vite build --ssr" : "bunx vite build";
104
+ for (const manifestPath of candidatePaths) try {
105
+ const raw = readFileSync(manifestPath, "utf8");
106
+ const manifest = JSON.parse(raw);
107
+ defineHidden(manifest, "__path__", manifestPath);
108
+ if (options.includeRaw) defineHidden(manifest, "__raw__", raw);
109
+ return manifest;
110
+ } catch (error) {
111
+ if (error.code !== "ENOENT") {
112
+ console.warn(`Unable to load ${label} Vite manifest at ${manifestPath}.`, error);
113
+ return;
114
+ }
115
+ }
116
+ if (warnOnMissing && candidatePaths.length) console.warn(`Unable to load ${label} Vite manifest. Checked paths:\n${candidatePaths.map((p) => ` - ${p}`).join("\n")}\nRun \`${command}\` before starting in production.`);
117
+ }
118
+ function getManifestFile(entry) {
119
+ if (!entry) return;
120
+ if (Array.isArray(entry)) return entry[0];
121
+ if (typeof entry === "string") return entry;
122
+ if ("file" in entry && typeof entry.file === "string") return entry.file;
123
+ }
124
+ function getManifestCss(entry) {
125
+ if (!entry || Array.isArray(entry) || typeof entry === "string") return;
126
+ return entry.css;
127
+ }
128
+ //#endregion
129
+ export { getManifestCss as a, isViteProduction as c, formatHostPort as d, isWildcardHost as f, clientManifestCandidates as i, loadViteManifest as l, INJECTED_CLIENT_MANIFEST_SOURCE as n, getManifestFile as o, PUBLIC_ASSETS_URL_PREFIX as r, injectedClientManifest as s, DEFAULT_DEV_SERVER_URL as t, normalizeDevServerUrl as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/server",
3
- "version": "2.35.0",
3
+ "version": "2.37.0",
4
4
  "description": "HTTP layer of the Guren framework, on Hono: routing, controllers, middleware, auth, sessions, queues and the AWS Lambda adapter. Applications import it through @guren/core.",
5
5
  "keywords": [
6
6
  "guren",
@@ -172,7 +172,7 @@
172
172
  "test": "bun test"
173
173
  },
174
174
  "dependencies": {
175
- "@guren/orm": "^2.15.0",
175
+ "@guren/orm": "^2.15.1",
176
176
  "chalk": "^5.3.0",
177
177
  "consola": "^3.4.2",
178
178
  "figlet": "^1.7.0",
@@ -1,15 +0,0 @@
1
- //#region src/http/host-port.ts
2
- /**
3
- * A wildcard bind answers on every interface but is not itself dialable on
4
- * every platform. The dev banner and `Application.listen()`'s returned address
5
- * both render this fact.
6
- */
7
- function isWildcardHost(hostname) {
8
- return hostname === "0.0.0.0" || hostname === "::";
9
- }
10
- /** `host:port`, bracketing an IPv6 literal so the result is dialable. */
11
- function formatHostPort(hostname, port) {
12
- return `${hostname.includes(":") ? `[${hostname}]` : hostname}:${port}`;
13
- }
14
- //#endregion
15
- export { isWildcardHost as n, formatHostPort as t };