@guren/server 1.4.0 → 2.0.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 (56) hide show
  1. package/dist/{AuthManager-C84xF5ks.d.ts → AuthManager-DBP4KYsx.d.ts} +1 -1
  2. package/dist/ConsoleKernel-DlK9j2Lu.d.ts +101 -0
  3. package/dist/DocsViewerServiceProvider-D7RGJPGM.js +75 -0
  4. package/dist/{I18nManager-CmUqj6bU.d.ts → I18nManager-BiSoczfV.d.ts} +1 -1
  5. package/dist/McpServiceProvider-7BB5FPF3.js +8 -0
  6. package/dist/auth/index.d.ts +39 -29
  7. package/dist/auth/index.js +2 -2
  8. package/dist/broadcasting/index.js +2 -2
  9. package/dist/cache/index.js +2 -2
  10. package/dist/chunk-2V3YID4H.js +20 -0
  11. package/dist/{chunk-JIT7QVMJ.js → chunk-4DW4GRWF.js} +3 -3
  12. package/dist/{chunk-R2TCP7D7.js → chunk-6J6B5KOB.js} +18 -2
  13. package/dist/chunk-AZOYI43J.js +18 -0
  14. package/dist/{chunk-DCYKSYAT.js → chunk-B5E5VBDI.js} +54 -2
  15. package/dist/{chunk-NYQGAWDN.js → chunk-BZMZEFRG.js} +7 -11
  16. package/dist/{chunk-4SBGSJNT.js → chunk-CWI4AJ47.js} +2 -1
  17. package/dist/{chunk-NQCZQAJL.js → chunk-DSDX3ASM.js} +21 -2
  18. package/dist/{chunk-MC752CQT.js → chunk-EI5GYMAT.js} +2 -1
  19. package/dist/{chunk-AUXQISW5.js → chunk-HONCNQXZ.js} +38 -5
  20. package/dist/{chunk-CSRQTEQA.js → chunk-HWEWL6TE.js} +6 -1
  21. package/dist/chunk-JBG4AR24.js +18 -0
  22. package/dist/{chunk-EDRGAM6G.js → chunk-K6CUBJX6.js} +11 -16
  23. package/dist/{chunk-WJJ5CTNI.js → chunk-KTNJG7R7.js} +6 -2
  24. package/dist/{chunk-74HTZG3V.js → chunk-LAJQCSSF.js} +24 -0
  25. package/dist/{chunk-H32L2NE3.js → chunk-LVJCZCAV.js} +20 -13
  26. package/dist/{chunk-CSDKWLFD.js → chunk-N7PLD7MB.js} +120 -43
  27. package/dist/{chunk-ONSDE37A.js → chunk-SFQP6O52.js} +1 -0
  28. package/dist/{chunk-XMQZENBP.js → chunk-TVY72CLV.js} +3 -1
  29. package/dist/chunk-WIXGT4TN.js +18 -0
  30. package/dist/{email-verification-H_WlpsVH.d.ts → email-verification-D8N7P6Pu.d.ts} +1 -1
  31. package/dist/encryption/index.js +2 -2
  32. package/dist/events/index.js +1 -1
  33. package/dist/i18n/index.d.ts +2 -2
  34. package/dist/index.d.ts +348 -330
  35. package/dist/index.js +332 -110
  36. package/dist/lambda/index.d.ts +5 -5
  37. package/dist/lambda/index.js +1 -1
  38. package/dist/mail/index.js +4 -3
  39. package/dist/mcp/index.d.ts +14 -4
  40. package/dist/mcp/index.js +3 -2
  41. package/dist/notifications/index.d.ts +55 -6
  42. package/dist/notifications/index.js +12 -3
  43. package/dist/queue/index.d.ts +5 -5
  44. package/dist/queue/index.js +4 -2
  45. package/dist/redis/index.d.ts +4 -4
  46. package/dist/redis/index.js +7 -0
  47. package/dist/runtime/index.d.ts +5 -5
  48. package/dist/runtime/index.js +24 -9
  49. package/dist/scheduling/index.js +2 -2
  50. package/dist/storage/index.js +2 -1
  51. package/dist/{Application-BvBqgc2k.d.ts → validation-CDR7lRE8.d.ts} +873 -654
  52. package/package.json +3 -3
  53. package/dist/ConsoleKernel-Dw9X9qZY.d.ts +0 -207
  54. package/dist/McpServiceProvider-TZWQWXCT.js +0 -7
  55. package/dist/{api-token-COQHXyM_.d.ts → api-token-D24VPr_E.d.ts} +101 -101
  56. package/dist/{client-BQwF2b9Y.d.ts → rate-limit-D9J2b4S1.d.ts} +36 -36
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  logDevServerBanner,
3
3
  parseImportMap,
4
4
  startViteDevServer
5
- } from "./chunk-JIT7QVMJ.js";
5
+ } from "./chunk-4DW4GRWF.js";
6
6
  import {
7
7
  PendingSchedule,
8
8
  Schedule,
@@ -16,14 +16,20 @@ import {
16
16
  matchesCron,
17
17
  parseCron,
18
18
  toTimezone
19
- } from "./chunk-MC752CQT.js";
19
+ } from "./chunk-EI5GYMAT.js";
20
20
  import {
21
21
  LocalDriver,
22
22
  MemoryDriver as MemoryDriver3,
23
23
  S3Driver,
24
24
  StorageManager,
25
25
  createStorageManager
26
- } from "./chunk-CSRQTEQA.js";
26
+ } from "./chunk-HWEWL6TE.js";
27
+ import {
28
+ trimSlashes
29
+ } from "./chunk-AZOYI43J.js";
30
+ import {
31
+ isDocsViewerEnabled
32
+ } from "./chunk-WIXGT4TN.js";
27
33
  import {
28
34
  I18nManager,
29
35
  JsonLoader,
@@ -61,13 +67,15 @@ import {
61
67
  getMailManager,
62
68
  mail,
63
69
  setMailManager
64
- } from "./chunk-EDRGAM6G.js";
70
+ } from "./chunk-K6CUBJX6.js";
65
71
  import {
66
72
  MCP_ENDPOINT_PATH,
67
- ProviderManager,
68
- ServiceProvider,
69
73
  isMcpEndpointEnabled
70
- } from "./chunk-NYQGAWDN.js";
74
+ } from "./chunk-JBG4AR24.js";
75
+ import {
76
+ ProviderManager,
77
+ ServiceProvider
78
+ } from "./chunk-BZMZEFRG.js";
71
79
  import {
72
80
  DatabaseChannel,
73
81
  MailChannel,
@@ -75,10 +83,15 @@ import {
75
83
  Notification,
76
84
  NotificationManager,
77
85
  SlackChannel,
86
+ clearNotificationRegistry,
78
87
  createNotificationManager,
88
+ getNotification,
79
89
  getNotificationManager,
90
+ registerNotification,
91
+ resolveNotifiableType,
80
92
  setNotificationManager
81
- } from "./chunk-CSDKWLFD.js";
93
+ } from "./chunk-N7PLD7MB.js";
94
+ import "./chunk-2V3YID4H.js";
82
95
  import {
83
96
  FailedJobReporter,
84
97
  MemoryDriver,
@@ -90,7 +103,7 @@ import {
90
103
  createQueueManager,
91
104
  createSqsAdapter,
92
105
  processJob
93
- } from "./chunk-WJJ5CTNI.js";
106
+ } from "./chunk-KTNJG7R7.js";
94
107
  import {
95
108
  Container,
96
109
  Job,
@@ -102,9 +115,10 @@ import {
102
115
  getRegisteredJobs,
103
116
  registerJob,
104
117
  resolve,
118
+ resolveJobName,
105
119
  setContainer,
106
120
  setQueueDriver
107
- } from "./chunk-R2TCP7D7.js";
121
+ } from "./chunk-6J6B5KOB.js";
108
122
  import {
109
123
  createRedisClient
110
124
  } from "./chunk-UY3AZSYL.js";
@@ -164,7 +178,7 @@ import {
164
178
  verifyEmailToken,
165
179
  verifyOAuthState,
166
180
  verifyPasswordResetToken
167
- } from "./chunk-AUXQISW5.js";
181
+ } from "./chunk-HONCNQXZ.js";
168
182
  import {
169
183
  Gate,
170
184
  Policy,
@@ -214,7 +228,7 @@ import {
214
228
  getBroadcastManager,
215
229
  parseRequestPayload,
216
230
  setBroadcastManager
217
- } from "./chunk-XMQZENBP.js";
231
+ } from "./chunk-TVY72CLV.js";
218
232
  import {
219
233
  CacheManager,
220
234
  FileStore,
@@ -222,11 +236,12 @@ import {
222
236
  RedisStore,
223
237
  TaggedCache,
224
238
  createCacheManager
225
- } from "./chunk-4SBGSJNT.js";
239
+ } from "./chunk-CWI4AJ47.js";
226
240
  import {
227
241
  claimHotDisposable,
228
- isHotReloadRuntime
229
- } from "./chunk-DCYKSYAT.js";
242
+ isHotReloadRuntime,
243
+ matchingOpenParen
244
+ } from "./chunk-B5E5VBDI.js";
230
245
  import {
231
246
  Encrypter,
232
247
  createEncrypter,
@@ -251,7 +266,7 @@ import {
251
266
  urlSafeToken,
252
267
  uuid,
253
268
  verifySignedUrl
254
- } from "./chunk-H32L2NE3.js";
269
+ } from "./chunk-LVJCZCAV.js";
255
270
  import {
256
271
  MessageSigner,
257
272
  deriveAppKey,
@@ -262,7 +277,7 @@ import {
262
277
  normalizeAppKey,
263
278
  parseAppKey,
264
279
  parsePreviousAppKeys
265
- } from "./chunk-ONSDE37A.js";
280
+ } from "./chunk-SFQP6O52.js";
266
281
  import {
267
282
  check,
268
283
  hash,
@@ -289,7 +304,7 @@ import {
289
304
  UserAuthenticated,
290
305
  UserLoggedOut,
291
306
  createEventManager
292
- } from "./chunk-74HTZG3V.js";
307
+ } from "./chunk-LAJQCSSF.js";
293
308
  import {
294
309
  CacheCheck,
295
310
  CustomCheck,
@@ -373,6 +388,17 @@ function mountRoute(app, method, path, ...handlers) {
373
388
  app.on(method, path, ...handlers);
374
389
  }
375
390
 
391
+ // src/http/middleware/capabilities.ts
392
+ var CAPABILITIES = /* @__PURE__ */ Symbol.for("guren.capabilities");
393
+ function stampCapabilities(handler, capabilities) {
394
+ Object.defineProperty(handler, CAPABILITIES, { value: capabilities, enumerable: false });
395
+ return handler;
396
+ }
397
+ function capabilitiesOf(handler) {
398
+ if (typeof handler !== "function") return void 0;
399
+ return handler[CAPABILITIES];
400
+ }
401
+
376
402
  // src/mvc/Router.ts
377
403
  var RESOURCE_ACTIONS = [
378
404
  { method: "index", suffix: "", httpMethod: "get" },
@@ -499,6 +525,7 @@ var Router = class {
499
525
  schemas,
500
526
  middlewareNames: [...routeMiddlewareNames],
501
527
  hasInlineMiddleware: middlewares.length > 0,
528
+ capabilities: this.aggregateCapabilities(routeMiddlewareNames, middlewares),
502
529
  controller: isControllerAction(handler) ? { name: handler[0].name, action: String(handler[1]) } : void 0,
503
530
  bindings: serializeBindings(path, bindings, this.modelBindingNames),
504
531
  ...openapi
@@ -551,6 +578,37 @@ var Router = class {
551
578
  this.registry.push(route);
552
579
  return createRouteBuilder(route, this.namedRoutes);
553
580
  }
581
+ /**
582
+ * Security capabilities present on a route's middleware chain, aggregated
583
+ * across named aliases (group-expanded) and inline handlers. Unlike
584
+ * `resolveMiddlewareNames`, unregistered names are skipped rather than
585
+ * thrown: `definitions()` must stay side-effect-free for introspection of
586
+ * routers that never mount (audit, codegen), and an unresolvable alias
587
+ * simply contributes no capabilities.
588
+ */
589
+ aggregateCapabilities(names, inline, seen) {
590
+ const aggregated = {};
591
+ const visited = seen ?? /* @__PURE__ */ new Set();
592
+ const absorb = (capabilities) => {
593
+ const auth = capabilities?.authentication;
594
+ if (!auth) return;
595
+ if (!aggregated.authentication || auth.mode === "required") {
596
+ aggregated.authentication = auth;
597
+ }
598
+ };
599
+ for (const name of names) {
600
+ if (visited.has(name)) continue;
601
+ visited.add(name);
602
+ const groupNames = this.middlewareGroups.get(name);
603
+ if (groupNames) {
604
+ absorb(this.aggregateCapabilities(groupNames, [], visited));
605
+ continue;
606
+ }
607
+ absorb(capabilitiesOf(this.middlewareAliases.get(name)));
608
+ }
609
+ for (const handler of inline) absorb(capabilitiesOf(handler));
610
+ return aggregated;
611
+ }
554
612
  resolveMiddlewareNames(names, seen) {
555
613
  const handlers = [];
556
614
  const visited = seen ?? /* @__PURE__ */ new Set();
@@ -593,6 +651,8 @@ var RouterMiddlewareGroupBuilder = class {
593
651
  this.router = router;
594
652
  this.names = names;
595
653
  }
654
+ router;
655
+ names;
596
656
  group(callback) {
597
657
  return this.router.applyMiddlewareScope(this.names, () => {
598
658
  callback(this.router);
@@ -660,30 +720,41 @@ function createContractHandler(path, options, handler) {
660
720
  if (!options.output) {
661
721
  return result;
662
722
  }
723
+ let outputValue = result;
724
+ let sourceBody;
663
725
  if (result instanceof Response) {
664
726
  try {
665
- const cloned = result.clone();
666
- const body2 = await cloned.json();
667
- const output2 = options.output.safeParse(body2);
668
- if (!output2.success) {
669
- throw new Error(
670
- `Route output validation failed for ${options.name ?? path}: ${JSON.stringify(formatValidationErrors(output2.error))}`
671
- );
672
- }
673
- } catch (err) {
674
- if (err instanceof Error && err.message.includes("output validation failed")) throw err;
727
+ sourceBody = await result.clone().text();
728
+ outputValue = JSON.parse(sourceBody);
729
+ } catch {
730
+ return result;
675
731
  }
676
- return result;
677
732
  }
678
- const output = options.output.safeParse(result);
679
- if (output.success) {
733
+ const output = options.output.safeParse(outputValue);
734
+ if (!output.success) {
735
+ throw new Error(
736
+ `Route output validation failed for ${options.name ?? path}: ${JSON.stringify(formatValidationErrors(output.error))}`
737
+ );
738
+ }
739
+ if (!(result instanceof Response)) {
680
740
  return output.data;
681
741
  }
682
- throw new Error(
683
- `Route output validation failed for ${options.name ?? path}: ${JSON.stringify(formatValidationErrors(output.error))}`
684
- );
742
+ return rebuildJsonResponse(result, sourceBody, output.data) ?? result;
685
743
  };
686
744
  }
745
+ function rebuildJsonResponse(source, sourceBody, data) {
746
+ const body = JSON.stringify(data);
747
+ if (body === sourceBody) {
748
+ return null;
749
+ }
750
+ const headers = new Headers(source.headers);
751
+ dropStaleBodyHeaders(headers);
752
+ return new Response(body, { status: source.status, headers });
753
+ }
754
+ function dropStaleBodyHeaders(headers) {
755
+ headers.delete("content-length");
756
+ headers.delete("etag");
757
+ }
687
758
  function parseRouteSegment(schema, data, status) {
688
759
  if (!schema) {
689
760
  return data;
@@ -728,15 +799,24 @@ function createContractValidationMiddleware(route) {
728
799
  }
729
800
  await next();
730
801
  if (schemas.output && c.res) {
802
+ let sourceBody;
803
+ let parsedBody;
731
804
  try {
732
- const cloned = c.res.clone();
733
- const body = await cloned.json();
734
- const parsed = schemas.output.safeParse(body);
735
- if (!parsed.success) {
736
- const errors = "flatten" in parsed.error && typeof parsed.error.flatten === "function" ? parsed.error.flatten() : parsed.error;
737
- c.res = c.json({ message: "Response validation failed", errors }, 500);
738
- }
805
+ sourceBody = await c.res.clone().text();
806
+ parsedBody = JSON.parse(sourceBody);
739
807
  } catch {
808
+ return;
809
+ }
810
+ const parsed = schemas.output.safeParse(parsedBody);
811
+ if (!parsed.success) {
812
+ const errors = "flatten" in parsed.error && typeof parsed.error.flatten === "function" ? parsed.error.flatten() : parsed.error;
813
+ c.res = c.json({ message: "Response validation failed", errors }, 500);
814
+ return;
815
+ }
816
+ const rebuilt = rebuildJsonResponse(c.res, sourceBody, parsed.data);
817
+ if (rebuilt) {
818
+ c.res = rebuilt;
819
+ dropStaleBodyHeaders(c.res.headers);
740
820
  }
741
821
  }
742
822
  };
@@ -850,7 +930,7 @@ function isRouteContractOptions(value) {
850
930
  return "params" in value || "query" in value || "body" in value || "output" in value || "bind" in value || "name" in value || "middlewares" in value || "summary" in value || "description" in value || "tags" in value || "operationId" in value || "deprecated" in value;
851
931
  }
852
932
  function joinPaths(prefixStack, path) {
853
- const segments = [...prefixStack, path].filter(Boolean).map((segment) => segment.replace(/\/*$/u, "").replace(/^\/*/u, "")).filter(Boolean);
933
+ const segments = [...prefixStack, path].filter(Boolean).map(trimSlashes).filter(Boolean);
854
934
  if (segments.length === 0) {
855
935
  return "/";
856
936
  }
@@ -883,7 +963,8 @@ function defineModule(definition) {
883
963
  name: definition.name,
884
964
  prefix: definition.prefix,
885
965
  routes: definition.routes,
886
- providers: definition.providers ?? []
966
+ providers: definition.providers ?? [],
967
+ commands: definition.commands ?? []
887
968
  };
888
969
  }
889
970
  async function mountModuleRoutes(router, gurenModule) {
@@ -1794,7 +1875,7 @@ function resolveAuth(ctx) {
1794
1875
  }
1795
1876
  function requireAuthenticated(options = {}) {
1796
1877
  const { redirectTo, status = 401, responseFactory } = options;
1797
- return async (ctx, next) => {
1878
+ return stampCapabilities(async (ctx, next) => {
1798
1879
  const auth = resolveAuth(ctx);
1799
1880
  if (!auth) {
1800
1881
  throw new Error("Auth context has not been attached. Did you register the auth middleware?");
@@ -1809,11 +1890,11 @@ function requireAuthenticated(options = {}) {
1809
1890
  return jsonResponse({ message: "Unauthorized" }, status);
1810
1891
  }
1811
1892
  await next();
1812
- };
1893
+ }, { authentication: { mode: "required" } });
1813
1894
  }
1814
1895
  function requireGuest(options = {}) {
1815
1896
  const { redirectTo, status = 403, responseFactory } = options;
1816
- return async (ctx, next) => {
1897
+ return stampCapabilities(async (ctx, next) => {
1817
1898
  const auth = resolveAuth(ctx);
1818
1899
  if (!auth) {
1819
1900
  throw new Error("Auth context has not been attached. Did you register the auth middleware?");
@@ -1828,7 +1909,7 @@ function requireGuest(options = {}) {
1828
1909
  return jsonResponse({ message: "Already authenticated" }, status);
1829
1910
  }
1830
1911
  await next();
1831
- };
1912
+ }, { authentication: { mode: "guest-only" } });
1832
1913
  }
1833
1914
 
1834
1915
  // src/providers/AuthServiceProvider.ts
@@ -1991,6 +2072,7 @@ async function renderDocument(page, options) {
1991
2072
  options,
1992
2073
  page.component
1993
2074
  );
2075
+ const headMarkup = resolveDocumentValue("head", options, page.component);
1994
2076
  const ssrResult = await tryRenderSsr(page, options);
1995
2077
  const headElements = (ssrResult?.head ?? []).map(normalizeHeadElement);
1996
2078
  const hasCustomTitle = headElements.some(
@@ -2000,6 +2082,7 @@ async function renderDocument(page, options) {
2000
2082
  '<meta charset="utf-8" />',
2001
2083
  '<meta name="viewport" content="width=device-width, initial-scale=1" />',
2002
2084
  hasCustomTitle ? "" : `<title>${title}</title>`,
2085
+ headMarkup ?? "",
2003
2086
  // Both must precede the stylesheet links: they exist to settle the first
2004
2087
  // paint before the app's own CSS arrives.
2005
2088
  criticalCss ? `<style id="guren-critical">${criticalCss}</style>` : "",
@@ -2408,6 +2491,7 @@ var Application = class {
2408
2491
  this.providerManager.register(InertiaServiceProvider);
2409
2492
  }
2410
2493
  }
2494
+ options;
2411
2495
  hono;
2412
2496
  container;
2413
2497
  router;
@@ -2460,7 +2544,16 @@ var Application = class {
2460
2544
  await this.providerManager.registerAll();
2461
2545
  await this.options.boot?.(this.hono);
2462
2546
  await this.mountRoutes();
2463
- await this.mountMcpEndpoint();
2547
+ await this.mountDevEndpoint(
2548
+ isMcpEndpointEnabled(),
2549
+ async () => (await import("./McpServiceProvider-7BB5FPF3.js")).McpServiceProvider,
2550
+ "GUREN_MCP=1 but the MCP endpoint could not load \u2014 is @modelcontextprotocol/sdk installed?"
2551
+ );
2552
+ await this.mountDevEndpoint(
2553
+ isDocsViewerEnabled(),
2554
+ async () => (await import("./DocsViewerServiceProvider-D7RGJPGM.js")).DocsViewerServiceProvider,
2555
+ "GUREN_DOCS=1 but the docs viewer could not load \u2014 is @guren/cli resolvable from this app?"
2556
+ );
2464
2557
  await this.providerManager.bootAll();
2465
2558
  }
2466
2559
  /**
@@ -2479,20 +2572,27 @@ var Application = class {
2479
2572
  this.hono.use("*", createHostAuthorizationMiddleware(hostAuthorization));
2480
2573
  }
2481
2574
  /**
2482
- * Mounts the MCP endpoint at /_guren/mcp when enabled.
2483
- * This allows AI coding agents to introspect the project.
2484
- */
2485
- async mountMcpEndpoint() {
2486
- if (!isMcpEndpointEnabled()) {
2487
- return;
2488
- }
2575
+ * Mounts an opt-in, dev-only framework endpoint: the MCP endpoint
2576
+ * (/_guren/mcp) and the docs viewer (/_guren/docs) both work this way.
2577
+ *
2578
+ * Only the dynamic import is allowed to fail silently — these
2579
+ * providers reach optional dependencies (the MCP SDK, @guren/cli) that
2580
+ * an app need not have installed, and `missing` names that case. A
2581
+ * failure inside the provider's own boot is a real problem and is
2582
+ * rethrown, rather than leaving the developer with a silent 404.
2583
+ */
2584
+ async mountDevEndpoint(enabled, load, missing) {
2585
+ if (!enabled) return;
2586
+ let provider;
2489
2587
  try {
2490
- const { McpServiceProvider } = await import("./McpServiceProvider-TZWQWXCT.js");
2491
- const provider = new McpServiceProvider(this.container);
2492
- provider.register();
2493
- await provider.boot();
2588
+ const Provider = await load();
2589
+ provider = new Provider(this.container);
2494
2590
  } catch {
2591
+ console.warn(`[guren] ${missing}`);
2592
+ return;
2495
2593
  }
2594
+ provider.register?.();
2595
+ await provider.boot?.();
2496
2596
  }
2497
2597
  /**
2498
2598
  * Fetch handler to integrate with Bun.serve or any standard Fetch runtime.
@@ -3118,6 +3218,9 @@ var NotificationServiceProvider = class extends ServiceProvider {
3118
3218
  register() {
3119
3219
  this.container.singleton("notifications", () => createNotificationManager());
3120
3220
  }
3221
+ boot() {
3222
+ this.container.make("notifications").registerQueueJob();
3223
+ }
3121
3224
  };
3122
3225
 
3123
3226
  // src/providers/BroadcastServiceProvider.ts
@@ -3169,6 +3272,7 @@ var FieldValidator = class {
3169
3272
  constructor(field) {
3170
3273
  this.field = field;
3171
3274
  }
3275
+ field;
3172
3276
  _rules = [];
3173
3277
  isNullable = false;
3174
3278
  isSometimes = false;
@@ -3559,13 +3663,23 @@ function email() {
3559
3663
  if (typeof value !== "string") {
3560
3664
  return "The :attribute must be a valid email address.";
3561
3665
  }
3562
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
3563
- if (!emailRegex.test(value)) {
3666
+ if (!isPlausibleEmail(value)) {
3564
3667
  return "The :attribute must be a valid email address.";
3565
3668
  }
3566
3669
  return true;
3567
3670
  };
3568
3671
  }
3672
+ function isPlausibleEmail(value) {
3673
+ const at = value.indexOf("@");
3674
+ if (at <= 0 || value.indexOf("@", at + 1) !== -1) {
3675
+ return false;
3676
+ }
3677
+ if (/\s/u.test(value)) {
3678
+ return false;
3679
+ }
3680
+ const domain = value.slice(at + 1);
3681
+ return domain.slice(1, -1).includes(".");
3682
+ }
3569
3683
  function url() {
3570
3684
  return (value) => {
3571
3685
  if (value === void 0 || value === null || value === "") return true;
@@ -4932,26 +5046,84 @@ function cursorPaginate(items, perPage, hasMore, options) {
4932
5046
 
4933
5047
  // src/console/Input.ts
4934
5048
  function parseSignature(signature) {
4935
- const parts = signature.split(/\s+/);
4936
- const name = parts[0];
5049
+ const { name, tokens } = tokenizeSignature(signature);
4937
5050
  const args = [];
4938
5051
  const options = [];
4939
- for (let i = 1; i < parts.length; i++) {
4940
- const part = parts[i];
4941
- if (!part) continue;
4942
- if (!part.startsWith("{") || !part.endsWith("}")) {
4943
- continue;
4944
- }
4945
- const content = part.slice(1, -1).trim();
4946
- if (content.startsWith("--") || content.startsWith("-")) {
4947
- options.push(parseOption(content));
5052
+ for (const token of tokens) {
5053
+ const [content, description] = splitSpacedDescription(token);
5054
+ if (!content) continue;
5055
+ if (content.startsWith("-")) {
5056
+ options.push(parseOption(content, description));
4948
5057
  } else {
4949
- args.push(parseArgument(content));
5058
+ args.push(parseArgument(content, description));
4950
5059
  }
4951
5060
  }
4952
5061
  return { name, arguments: args, options };
4953
5062
  }
4954
- function parseArgument(content) {
5063
+ function tokenizeSignature(signature) {
5064
+ const firstBrace = signature.indexOf("{");
5065
+ const head = firstBrace === -1 ? signature : signature.slice(0, firstBrace);
5066
+ const name = head.trim().split(/\s+/)[0];
5067
+ if (firstBrace === -1) {
5068
+ return { name, tokens: [] };
5069
+ }
5070
+ const tokens = [];
5071
+ let depth = 0;
5072
+ let start = -1;
5073
+ for (let i = firstBrace; i < signature.length; i++) {
5074
+ const char = signature[i];
5075
+ if (char === "{") {
5076
+ if (depth === 0) start = i;
5077
+ depth++;
5078
+ } else if (char === "}" && depth > 0) {
5079
+ depth--;
5080
+ if (depth === 0) {
5081
+ tokens.push(signature.slice(start + 1, i));
5082
+ }
5083
+ }
5084
+ }
5085
+ return { name, tokens };
5086
+ }
5087
+ var DESCRIPTION_SEPARATOR = /\s+:\s*|:\s+/;
5088
+ function splitSpacedDescription(token) {
5089
+ const match = DESCRIPTION_SEPARATOR.exec(token);
5090
+ if (!match) {
5091
+ return [token.trim(), void 0];
5092
+ }
5093
+ const content = token.slice(0, match.index).trim();
5094
+ const description = token.slice(match.index + match[0].length).trim();
5095
+ return [content, description || void 0];
5096
+ }
5097
+ function resolveNameAndDescription(name, description) {
5098
+ if (description === void 0) {
5099
+ const colonIndex = name.indexOf(":");
5100
+ if (colonIndex !== -1) {
5101
+ description = name.slice(colonIndex + 1).trim() || void 0;
5102
+ name = name.slice(0, colonIndex);
5103
+ }
5104
+ }
5105
+ return { name: name.trim(), description };
5106
+ }
5107
+ function argumentLabel(arg) {
5108
+ return arg.array ? `${arg.name}...` : arg.name;
5109
+ }
5110
+ function optionLabel(opt) {
5111
+ if (opt.array) return `--${opt.name}=<value>...`;
5112
+ if (opt.requiresValue) return `--${opt.name}=<value>`;
5113
+ return `--${opt.name}`;
5114
+ }
5115
+ function formatUsage(parsed) {
5116
+ const parts = [parsed.name];
5117
+ if (parsed.options.length > 0) {
5118
+ parts.push("[options]");
5119
+ }
5120
+ for (const arg of parsed.arguments) {
5121
+ const label = argumentLabel(arg);
5122
+ parts.push(arg.required ? `<${label}>` : `[${label}]`);
5123
+ }
5124
+ return parts.join(" ");
5125
+ }
5126
+ function parseArgument(content, description) {
4955
5127
  let name = content;
4956
5128
  let required2 = true;
4957
5129
  let array2 = false;
@@ -4970,15 +5142,14 @@ function parseArgument(content) {
4970
5142
  name = name.slice(0, eqIndex);
4971
5143
  required2 = false;
4972
5144
  }
4973
- let description;
4974
- const colonIndex = name.indexOf(":");
4975
- if (colonIndex !== -1) {
4976
- description = name.slice(colonIndex + 1);
4977
- name = name.slice(0, colonIndex);
4978
- }
4979
- return { name, description, required: required2, array: array2, defaultValue };
5145
+ return {
5146
+ ...resolveNameAndDescription(name, description),
5147
+ required: required2,
5148
+ array: array2,
5149
+ defaultValue
5150
+ };
4980
5151
  }
4981
- function parseOption(content) {
5152
+ function parseOption(content, description) {
4982
5153
  let name = content;
4983
5154
  let shortcut;
4984
5155
  let requiresValue = false;
@@ -5005,16 +5176,16 @@ function parseOption(content) {
5005
5176
  requiresValue = true;
5006
5177
  }
5007
5178
  }
5008
- let description;
5009
- const colonIndex = name.indexOf(":");
5010
- if (colonIndex !== -1) {
5011
- description = name.slice(colonIndex + 1);
5012
- name = name.slice(0, colonIndex);
5013
- }
5014
5179
  if (!requiresValue && defaultValue === void 0) {
5015
5180
  defaultValue = false;
5016
5181
  }
5017
- return { name, shortcut, description, requiresValue, defaultValue, array: array2 };
5182
+ return {
5183
+ ...resolveNameAndDescription(name, description),
5184
+ shortcut,
5185
+ requiresValue,
5186
+ defaultValue,
5187
+ array: array2
5188
+ };
5018
5189
  }
5019
5190
  var Input = class {
5020
5191
  /**
@@ -5218,6 +5389,8 @@ var Command = class {
5218
5389
  /**
5219
5390
  * The command signature.
5220
5391
  * Format: 'command:name {arg} {--option}'
5392
+ * Tokens may carry a description: 'command:name {arg : What it is}'
5393
+ * See `parseSignature` for the full grammar.
5221
5394
  */
5222
5395
  static signature;
5223
5396
  /**
@@ -5746,6 +5919,13 @@ var BufferedOutput = class extends Output {
5746
5919
  };
5747
5920
 
5748
5921
  // src/console/ConsoleKernel.ts
5922
+ function helpColumn(labels, min2) {
5923
+ return Math.max(min2, ...labels.map((label) => label.length + 2));
5924
+ }
5925
+ function helpRow(output, indent, label, column, annotations) {
5926
+ const padding = " ".repeat(Math.max(2, column - label.length));
5927
+ output.line(`${indent}${label}${padding}${annotations.filter(Boolean).join(" ")}`);
5928
+ }
5749
5929
  var ConsoleKernel = class {
5750
5930
  /**
5751
5931
  * Registered commands.
@@ -5858,15 +6038,23 @@ var ConsoleKernel = class {
5858
6038
  this.output.line("");
5859
6039
  this.output.info("Available Commands:");
5860
6040
  this.output.line("");
5861
- const grouped = this.groupCommands();
5862
- for (const [namespace, commands] of grouped) {
5863
- if (namespace) {
5864
- this.output.line(` ${namespace}`);
6041
+ const groups = Array.from(this.groupCommands(), ([namespace, commands]) => ({
6042
+ namespace,
6043
+ entries: Array.from(commands, ([name, cmd]) => ({
6044
+ label: namespace ? name.slice(namespace.length + 1) : name,
6045
+ description: cmd.description
6046
+ }))
6047
+ }));
6048
+ const column = helpColumn(
6049
+ groups.flatMap((group) => group.entries.map((entry) => entry.label)),
6050
+ 20
6051
+ );
6052
+ for (const group of groups) {
6053
+ if (group.namespace) {
6054
+ this.output.line(` ${group.namespace}`);
5865
6055
  }
5866
- for (const [name, cmd] of commands) {
5867
- const displayName = namespace ? name.slice(namespace.length + 1) : name;
5868
- const padding = " ".repeat(Math.max(2, 20 - displayName.length));
5869
- this.output.line(` ${displayName}${padding}${cmd.description}`);
6056
+ for (const entry of group.entries) {
6057
+ helpRow(this.output, " ", entry.label, column, [entry.description]);
5870
6058
  }
5871
6059
  this.output.line("");
5872
6060
  }
@@ -5886,23 +6074,34 @@ var ConsoleKernel = class {
5886
6074
  this.output.line("");
5887
6075
  this.output.line(` ${CommandClass.description || "No description"}`);
5888
6076
  this.output.line("");
5889
- this.output.line(`Usage: ${CommandClass.signature}`);
6077
+ this.output.line(`Usage: ${formatUsage(parsed)}`);
6078
+ const optionShortcut = (opt) => opt.shortcut ? `-${opt.shortcut}, ` : " ";
6079
+ const column = helpColumn(
6080
+ [
6081
+ ...parsed.arguments.map(argumentLabel),
6082
+ ...parsed.options.map((opt) => optionShortcut(opt) + optionLabel(opt))
6083
+ ],
6084
+ 24
6085
+ );
5890
6086
  if (parsed.arguments.length > 0) {
5891
6087
  this.output.line("");
5892
6088
  this.output.line("Arguments:");
5893
6089
  for (const arg of parsed.arguments) {
5894
- const required2 = arg.required ? "(required)" : "(optional)";
5895
- const defaultVal = arg.defaultValue ? ` [default: ${arg.defaultValue}]` : "";
5896
- this.output.line(` ${arg.name} ${required2}${defaultVal}`);
6090
+ helpRow(this.output, " ", argumentLabel(arg), column, [
6091
+ arg.description,
6092
+ arg.required ? "(required)" : "(optional)",
6093
+ arg.defaultValue ? `[default: ${arg.defaultValue}]` : void 0
6094
+ ]);
5897
6095
  }
5898
6096
  }
5899
6097
  if (parsed.options.length > 0) {
5900
6098
  this.output.line("");
5901
6099
  this.output.line("Options:");
5902
6100
  for (const opt of parsed.options) {
5903
- const shortcut = opt.shortcut ? `-${opt.shortcut}, ` : " ";
5904
- const defaultVal = opt.defaultValue !== void 0 && opt.defaultValue !== false ? ` [default: ${opt.defaultValue}]` : "";
5905
- this.output.line(` ${shortcut}--${opt.name}${defaultVal}`);
6101
+ helpRow(this.output, " ", optionShortcut(opt) + optionLabel(opt), column, [
6102
+ opt.description,
6103
+ opt.defaultValue !== void 0 && opt.defaultValue !== false ? `[default: ${opt.defaultValue}]` : void 0
6104
+ ]);
5906
6105
  }
5907
6106
  }
5908
6107
  this.output.line("");
@@ -6356,16 +6555,34 @@ function debugErrorMiddleware() {
6356
6555
  }
6357
6556
  };
6358
6557
  }
6558
+ function splitLocation(location) {
6559
+ const lastColon = location.lastIndexOf(":");
6560
+ if (lastColon <= 0) return null;
6561
+ const prevColon = location.lastIndexOf(":", lastColon - 1);
6562
+ if (prevColon <= 0) return null;
6563
+ const line = location.slice(prevColon + 1, lastColon);
6564
+ const col = location.slice(lastColon + 1);
6565
+ if (!/^\d+$/.test(line) || !/^\d+$/.test(col)) return null;
6566
+ return { file: location.slice(0, prevColon), line, col };
6567
+ }
6359
6568
  function parseStackTrace(stack) {
6360
6569
  const lines = stack.split("\n").slice(1);
6361
6570
  return lines.map((line) => {
6362
- const match = line.match(/\s+at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)/);
6363
- if (match) {
6364
- return { func: match[1], file: match[2], line: match[3], col: match[4] };
6571
+ const trimmed = line.trim();
6572
+ if (!/^at\s/u.test(trimmed)) return null;
6573
+ const rest = trimmed.slice(2).trim();
6574
+ if (rest.endsWith(")")) {
6575
+ const open = matchingOpenParen(rest, rest.length - 1);
6576
+ if (open !== void 0 && open > 0) {
6577
+ const location2 = splitLocation(rest.slice(open + 1, -1));
6578
+ if (location2) {
6579
+ return { func: rest.slice(0, open).trim(), ...location2 };
6580
+ }
6581
+ }
6365
6582
  }
6366
- const match2 = line.match(/\s+at\s+(.+?):(\d+):(\d+)/);
6367
- if (match2) {
6368
- return { func: "<anonymous>", file: match2[1], line: match2[2], col: match2[3] };
6583
+ const location = splitLocation(rest);
6584
+ if (location) {
6585
+ return { func: "<anonymous>", ...location };
6369
6586
  }
6370
6587
  return null;
6371
6588
  }).filter((frame) => frame !== null);
@@ -6659,6 +6876,7 @@ export {
6659
6876
  cannot,
6660
6877
  check as checkHash,
6661
6878
  clearJobRegistry,
6879
+ clearNotificationRegistry,
6662
6880
  collect,
6663
6881
  completeEmailVerification,
6664
6882
  completePasswordReset,
@@ -6756,6 +6974,7 @@ export {
6756
6974
  getMailManager,
6757
6975
  getNextOccurrence,
6758
6976
  getNextOccurrences,
6977
+ getNotification,
6759
6978
  getNotificationManager,
6760
6979
  getPluralizationRule,
6761
6980
  getQueueDriver,
@@ -6818,6 +7037,7 @@ export {
6818
7037
  randomString,
6819
7038
  regex,
6820
7039
  registerJob,
7040
+ registerNotification,
6821
7041
  renderDebugPage,
6822
7042
  renderErrorPage,
6823
7043
  requestIdMiddleware,
@@ -6833,6 +7053,8 @@ export {
6833
7053
  resetCalledSeeders,
6834
7054
  resetRateLimit,
6835
7055
  resolve,
7056
+ resolveJobName,
7057
+ resolveNotifiableType,
6836
7058
  revokeAllApiTokens,
6837
7059
  revokeApiToken,
6838
7060
  same,