@guren/server 2.25.1 → 2.27.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 (121) hide show
  1. package/dist/{DocsViewerServiceProvider-CIRNHQ2I.js → DocsViewerServiceProvider-BMbcTYVw.js} +1 -1
  2. package/dist/{Gate-YOt54xGF.js → Gate-BL_zW82W.js} +1 -1
  3. package/dist/{Job-COMzBNOL.js → Job-DsFMcXVk.js} +35 -3
  4. package/dist/{McpServiceProvider-B-LioPSz.js → McpServiceProvider-PGFPlYTy.js} +1 -1
  5. package/dist/{Resource-BdYd4J9a.js → Resource-q3tJpJ0K.js} +194 -54
  6. package/dist/{ServiceProvider-DDW3MqQJ.js → ServiceProvider-G0YclITd.js} +60 -8
  7. package/dist/agent/dispatch.d.ts +4 -4
  8. package/dist/agent/public.js +1 -1
  9. package/dist/agent/scopes.d.ts +1 -3
  10. package/dist/agent-request-Caj6bnbj.js +18 -0
  11. package/dist/auth/AuthManager.d.ts +4 -0
  12. package/dist/auth/email-verification.d.ts +8 -1
  13. package/dist/auth/index.js +1 -1
  14. package/dist/auth/password/describe-hasher.d.ts +11 -0
  15. package/dist/auth/password-reset.d.ts +8 -2
  16. package/dist/{auth-vFeem6uM.js → auth-DIugW0O-.js} +108 -13
  17. package/dist/authorization/index.js +2 -2
  18. package/dist/authorization/middleware.d.ts +8 -0
  19. package/dist/{authorization-BLhwA2Yh.js → authorization-Daa6CxCg.js} +17 -2
  20. package/dist/broadcasting/BroadcastManager.d.ts +23 -6
  21. package/dist/broadcasting/index.d.ts +1 -1
  22. package/dist/broadcasting/index.js +1 -1
  23. package/dist/broadcasting/types.d.ts +13 -1
  24. package/dist/{broadcasting-BUBCPCnu.js → broadcasting-N4cRV42s.js} +205 -34
  25. package/dist/cache/CacheManager.d.ts +5 -0
  26. package/dist/cache/TaggedCache.d.ts +2 -0
  27. package/dist/cache/index.js +1 -1
  28. package/dist/cache/pending-computations.d.ts +22 -0
  29. package/dist/cache/stores/FileStore.d.ts +2 -0
  30. package/dist/cache/stores/MemoryStore.d.ts +1 -0
  31. package/dist/cache/stores/RedisStore.d.ts +1 -0
  32. package/dist/cache/stores/file-lock.d.ts +1 -0
  33. package/dist/cache/types.d.ts +2 -0
  34. package/dist/{cache-93n2PCnB.js → cache-BlXopnH1.js} +247 -38
  35. package/dist/contained-path-BkNSBljW.js +78 -0
  36. package/dist/container/Container.d.ts +6 -2
  37. package/dist/container/ServiceProvider.d.ts +27 -2
  38. package/dist/container/defineModule.d.ts +14 -5
  39. package/dist/container/definePlugin.d.ts +2 -0
  40. package/dist/{default-application-D5ezhhiV.js → default-application-DWwscxfW.js} +14 -18
  41. package/dist/dev-banner-CfQDnkfQ.js +51 -0
  42. package/dist/{dispatch-BAwzftws.js → dispatch-ENWpBxbE.js} +26 -4
  43. package/dist/driver-map-CkQc52j-.js +12 -0
  44. package/dist/encryption/index.js +1 -1
  45. package/dist/{encryption-D1dxfMqD.js → encryption-CWK5l22W.js} +1 -1
  46. package/dist/events/EventManager.d.ts +2 -0
  47. package/dist/events/index.js +1 -1
  48. package/dist/{events-c94CdUFc.js → events-DQavGm8W.js} +20 -7
  49. package/dist/health/HealthManager.d.ts +0 -1
  50. package/dist/health/index.js +1 -1
  51. package/dist/{health-CB0oS_UE.js → health-Bg0Xj3aD.js} +8 -8
  52. package/dist/host-port-t6wQFaRu.js +15 -0
  53. package/dist/hot-reload/testing.d.ts +2 -1
  54. package/dist/http/Application.d.ts +31 -2
  55. package/dist/http/dev-banner.d.ts +0 -8
  56. package/dist/http/host-port.d.ts +8 -0
  57. package/dist/http/middleware/force-https.d.ts +2 -1
  58. package/dist/http/middleware/index.d.ts +1 -0
  59. package/dist/http/middleware/rate-limit.d.ts +1 -4
  60. package/dist/http/middleware/session-manager.d.ts +5 -0
  61. package/dist/http/middleware/websocket-origin.d.ts +22 -0
  62. package/dist/http/public-assets.d.ts +6 -1
  63. package/dist/i18n/index.js +1 -1
  64. package/dist/{i18n-DqcRD4qL.js → i18n-DmMKcbqj.js} +1 -1
  65. package/dist/index.d.ts +8 -4
  66. package/dist/index.js +744 -273
  67. package/dist/internal/agent-request.d.ts +18 -0
  68. package/dist/internal/app-conventions.d.ts +6 -0
  69. package/dist/internal/app-conventions.js +9 -0
  70. package/dist/internal/dispatched-request.d.ts +4 -0
  71. package/dist/internal/testing.d.ts +1 -1
  72. package/dist/internal/testing.js +3 -3
  73. package/dist/internal/zod-json-schema.js +1 -1
  74. package/dist/introspection/driver-map.d.ts +3 -0
  75. package/dist/introspection/flag.d.ts +12 -0
  76. package/dist/introspection/manifest.d.ts +17 -0
  77. package/dist/introspection/plain-json.d.ts +7 -0
  78. package/dist/introspection/types.d.ts +167 -0
  79. package/dist/lambda/index.js +66 -28
  80. package/dist/logging/index.js +1 -1
  81. package/dist/{logging-YbKmbAd7.js → logging-Ci0mBk5k.js} +1 -1
  82. package/dist/mail/index.js +1 -1
  83. package/dist/{mail-uRBrUl9q.js → mail-CI2Kfe8P.js} +2 -2
  84. package/dist/mcp/index.js +1 -1
  85. package/dist/mvc/Controller.d.ts +3 -2
  86. package/dist/mvc/Router.d.ts +33 -0
  87. package/dist/mvc/inertia/InertiaEngine.d.ts +31 -0
  88. package/dist/mvc/inertia/props.d.ts +71 -0
  89. package/dist/notifications/index.js +1 -1
  90. package/dist/notifications/registry.d.ts +2 -2
  91. package/dist/{notifications-LHuujttf.js → notifications-Bp2uamzD.js} +7 -5
  92. package/dist/providers/ConfigServiceProvider.d.ts +12 -5
  93. package/dist/queue/Job.d.ts +5 -0
  94. package/dist/queue/QueueManager.d.ts +3 -0
  95. package/dist/queue/Worker.d.ts +6 -1
  96. package/dist/queue/drivers/RedisDriver.d.ts +4 -2
  97. package/dist/queue/drivers/SqsDriver.d.ts +31 -2
  98. package/dist/queue/drivers/redis-queue-scripts.d.ts +83 -0
  99. package/dist/queue/index.js +2 -2
  100. package/dist/queue/serialize.d.ts +7 -0
  101. package/dist/queue/types.d.ts +13 -2
  102. package/dist/{queue-BiBn5Sff.js → queue-C8s3buYz.js} +299 -125
  103. package/dist/redis/RedisEmailVerificationStore.d.ts +2 -0
  104. package/dist/redis/RedisPasswordResetStore.d.ts +2 -0
  105. package/dist/redis/auth-token-scripts.d.ts +4 -0
  106. package/dist/redis/index.js +50 -0
  107. package/dist/runtime/index.js +17 -37
  108. package/dist/scheduling/ScheduledTask.d.ts +2 -1
  109. package/dist/scheduling/index.js +1 -1
  110. package/dist/{scheduling-DhYfbJFj.js → scheduling-DNV5tj44.js} +32 -38
  111. package/dist/serialize-CKXek0Tr.js +17 -0
  112. package/dist/storage/StorageManager.d.ts +5 -0
  113. package/dist/storage/drivers/LocalDriver.d.ts +15 -0
  114. package/dist/storage/index.js +1 -1
  115. package/dist/storage/url-path.d.ts +2 -0
  116. package/dist/{storage-6HLaUf9j.js → storage-IlUesK2t.js} +91 -29
  117. package/dist/support/contained-path.d.ts +8 -0
  118. package/dist/support/registry-collision.d.ts +12 -0
  119. package/dist/{vite-manifest-DK55BTLk.js → vite-manifest-wPxfAzjW.js} +2 -58
  120. package/package.json +6 -2
  121. package/dist/trim-slashes-BLY9hKAa.js +0 -22
@@ -1,45 +1,13 @@
1
- import { n as trimTrailingSlashes } from "../trim-slashes-BLY9hKAa.js";
1
+ import { a as trimTrailingSlashes, n as isRealPathWithin, t as isPathWithin } from "../contained-path-BkNSBljW.js";
2
2
  import { n as parseImportMap } from "../inertia-defaults-BjrcT7za.js";
3
3
  import { n as hash } from "../Hash-D2DFd8xX.js";
4
- import { a as getManifestCss, c as isViteProduction, d as startViteDevServer, f as GUREN_ASCII_ART, h as logDevServerBanner, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-DK55BTLk.js";
4
+ import { a as getManifestCss, c as isViteProduction, d as startViteDevServer, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-wPxfAzjW.js";
5
+ import { r as logDevServerBanner, t as GUREN_ASCII_ART } from "../dev-banner-CfQDnkfQ.js";
5
6
  import { createRequire } from "node:module";
6
- import { dirname, extname, join, resolve, sep } from "node:path";
7
+ import { dirname, extname, join, resolve } from "node:path";
7
8
  import { fileURLToPath } from "node:url";
8
- import { realpath } from "node:fs/promises";
9
9
  import { serveStatic } from "hono/bun";
10
10
  import { getMimeType } from "hono/utils/mime";
11
- //#region src/support/contained-path.ts
12
- /**
13
- * Lexical containment. The trailing separator keeps out a sibling whose name
14
- * merely extends the root's (`…/inertia` vs `…/inertia-secrets`) and rejects an
15
- * absolute `candidate`, which `resolve()` returns verbatim. Not sufficient
16
- * alone: `resolve()` collapses `..` without following symlinks, so use
17
- * {@link isRealPathWithin} before reading the file.
18
- */
19
- function isPathWithin(root, candidate) {
20
- return candidate.startsWith(root.endsWith(sep) ? root : root + sep);
21
- }
22
- /**
23
- * Containment once both sides are canonicalized. Every reader downstream
24
- * (`Bun.file().text()`, `new Response(file)`) follows symlinks, so a lexical
25
- * check alone accepts `<root>/link/secret`. *Both* sides, because a root
26
- * reached through a symlink is routine (macOS `/var` → `/private/var`) and
27
- * doing only the candidate would 404 every asset such an app serves.
28
- */
29
- async function isRealPathWithin(root, candidate) {
30
- if (!isPathWithin(root, candidate)) return false;
31
- const [realRoot, realCandidate] = await Promise.all([canonicalize(root), canonicalize(candidate)]);
32
- if (!realRoot || !realCandidate) return false;
33
- return isPathWithin(realRoot, realCandidate);
34
- }
35
- async function canonicalize(path) {
36
- try {
37
- return await realpath(path);
38
- } catch {
39
- return;
40
- }
41
- }
42
- //#endregion
43
11
  //#region src/http/static-documents.ts
44
12
  /**
45
13
  * The one rule for "a browser would render this as a document in the serving
@@ -105,8 +73,16 @@ const DEFAULT_ROOT_PUBLIC_ASSET_EXTENSIONS = [
105
73
  ".webp",
106
74
  ".avif",
107
75
  ".webmanifest",
108
- ".txt"
76
+ ".txt",
77
+ ".woff2",
78
+ ".woff",
79
+ ".ttf",
80
+ ".otf"
109
81
  ];
82
+ /**
83
+ * Must give each extension the media type Hono's `getMimeType` does
84
+ * (`public-assets.test.ts`): `serveStatic` types the same file under `/public/*`.
85
+ */
110
86
  const DEFAULT_CONTENT_TYPES = {
111
87
  ".svg": "image/svg+xml",
112
88
  ".png": "image/png",
@@ -118,6 +94,10 @@ const DEFAULT_CONTENT_TYPES = {
118
94
  ".avif": "image/avif",
119
95
  ".webmanifest": "application/manifest+json",
120
96
  ".txt": "text/plain; charset=utf-8",
97
+ ".woff2": "font/woff2",
98
+ ".woff": "font/woff",
99
+ ".ttf": "font/ttf",
100
+ ".otf": "font/otf",
121
101
  ".js": "text/javascript; charset=utf-8",
122
102
  ".mjs": "text/javascript; charset=utf-8",
123
103
  ".css": "text/css; charset=utf-8"
@@ -1,6 +1,7 @@
1
1
  import type { TaskDefinition } from './types.js';
2
2
  export declare class ScheduledTask {
3
3
  private readonly definition;
4
+ private readonly cron;
4
5
  private lastRun;
5
6
  /**
6
7
  * The invocation holding the overlap guard; null when idle. The token is an
@@ -12,7 +13,7 @@ export declare class ScheduledTask {
12
13
  getName(): string;
13
14
  getExpression(): string;
14
15
  getTimezone(): string | undefined;
15
- isDue(date?: Date): boolean;
16
+ isDue(date?: Date, defaultTimezone?: string): boolean;
16
17
  shouldRun(): Promise<boolean>;
17
18
  /** `now` is the instant the overlap guard is judged against; a fixed clock can be handed in. */
18
19
  run(now?: Date): Promise<void>;
@@ -1,2 +1,2 @@
1
- import { a as ScheduledTask, c as isDue, d as parseCron, f as toTimezone, i as Schedule, l as isDueInTimezone, n as createScheduler, o as getNextOccurrence, p as MemorySchedulerLock, r as PendingSchedule, s as getNextOccurrences, t as Scheduler, u as matchesCron } from "../scheduling-DhYfbJFj.js";
1
+ import { a as ScheduledTask, c as isDue, d as parseCron, f as toTimezone, i as Schedule, l as isDueInTimezone, n as createScheduler, o as getNextOccurrence, p as MemorySchedulerLock, r as PendingSchedule, s as getNextOccurrences, t as Scheduler, u as matchesCron } from "../scheduling-DNV5tj44.js";
2
2
  export { MemorySchedulerLock, PendingSchedule, Schedule, ScheduledTask, Scheduler, createScheduler, getNextOccurrence, getNextOccurrences, isDue, isDueInTimezone, matchesCron, parseCron, toTimezone };
@@ -33,30 +33,20 @@ var MemorySchedulerLock = class MemorySchedulerLock {
33
33
  //#region src/scheduling/CronParser.ts
34
34
  function parseField(field, min, max) {
35
35
  const values = /* @__PURE__ */ new Set();
36
- const parts = field.split(",");
37
- for (const part of parts) {
38
- const stepMatch = part.match(/^(.+)\/(\d+)$/);
39
- let range;
40
- let step = 1;
41
- if (stepMatch) {
42
- range = stepMatch[1];
43
- step = parseInt(stepMatch[2], 10);
44
- } else range = part;
45
- if (range === "*") {
46
- for (let i = min; i <= max; i += step) values.add(i);
47
- continue;
48
- }
49
- const rangeMatch = range.match(/^(\d+)-(\d+)$/);
50
- if (rangeMatch) {
51
- const start = parseInt(rangeMatch[1], 10);
52
- const end = parseInt(rangeMatch[2], 10);
53
- for (let i = start; i <= end; i += step) if (i >= min && i <= max) values.add(i);
54
- continue;
55
- }
56
- const value = parseInt(range, 10);
57
- if (!isNaN(value) && value >= min && value <= max) values.add(value);
58
- }
59
- return Array.from(values).sort((a, b) => a - b);
36
+ const invalid = () => /* @__PURE__ */ new Error(`Invalid cron field: ${field}`);
37
+ for (const part of field.split(",")) {
38
+ const match = /^(\*|\d+(?:-\d+)?)(?:\/(\d+))?$/.exec(part);
39
+ if (!match) throw invalid();
40
+ const step = match[2] === void 0 ? 1 : Number(match[2]);
41
+ if (!Number.isSafeInteger(step) || step < 1) throw invalid();
42
+ const range = match[1];
43
+ const bounds = range === "*" ? [min, max] : range.split("-").map(Number);
44
+ const start = bounds[0];
45
+ const end = bounds[1] ?? (match[2] === void 0 ? start : max);
46
+ if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < min || end > max || end < start) throw invalid();
47
+ for (let value = start; value <= end; value += step) values.add(value);
48
+ }
49
+ return [...values].sort((a, b) => a - b);
60
50
  }
61
51
  function parseCron(expression) {
62
52
  const parts = expression.trim().split(/\s+/);
@@ -69,13 +59,11 @@ function parseCron(expression) {
69
59
  dayOfWeek: parseField(parts[4], 0, 6)
70
60
  };
71
61
  }
62
+ function matchesDay(date, cron) {
63
+ return cron.dayOfMonth.includes(date.getDate()) && cron.month.includes(date.getMonth() + 1) && cron.dayOfWeek.includes(date.getDay());
64
+ }
72
65
  function matchesCron(date, cron) {
73
- const minute = date.getMinutes();
74
- const hour = date.getHours();
75
- const dayOfMonth = date.getDate();
76
- const month = date.getMonth() + 1;
77
- const dayOfWeek = date.getDay();
78
- return cron.minute.includes(minute) && cron.hour.includes(hour) && cron.dayOfMonth.includes(dayOfMonth) && cron.month.includes(month) && cron.dayOfWeek.includes(dayOfWeek);
66
+ return cron.minute.includes(date.getMinutes()) && cron.hour.includes(date.getHours()) && matchesDay(date, cron);
79
67
  }
80
68
  function getNextOccurrence(expression, from = /* @__PURE__ */ new Date()) {
81
69
  const cron = parseCron(expression);
@@ -83,12 +71,15 @@ function getNextOccurrence(expression, from = /* @__PURE__ */ new Date()) {
83
71
  next.setSeconds(0);
84
72
  next.setMilliseconds(0);
85
73
  next.setMinutes(next.getMinutes() + 1);
86
- const maxIterations = 525600;
87
- let iterations = 0;
88
- while (iterations < maxIterations) {
74
+ const endYear = next.getFullYear() + 400;
75
+ while (next.getFullYear() < endYear) {
76
+ if (!matchesDay(next, cron)) {
77
+ next.setDate(next.getDate() + 1);
78
+ next.setHours(0, 0, 0, 0);
79
+ continue;
80
+ }
89
81
  if (matchesCron(next, cron)) return next;
90
82
  next.setMinutes(next.getMinutes() + 1);
91
- iterations++;
92
83
  }
93
84
  throw new Error(`Could not find next occurrence for: ${expression}`);
94
85
  }
@@ -133,6 +124,7 @@ function isDueInTimezone(expression, timezone, date = /* @__PURE__ */ new Date()
133
124
  //#region src/scheduling/ScheduledTask.ts
134
125
  var ScheduledTask = class {
135
126
  definition;
127
+ cron;
136
128
  lastRun = null;
137
129
  /**
138
130
  * The invocation holding the overlap guard; null when idle. The token is an
@@ -141,6 +133,7 @@ var ScheduledTask = class {
141
133
  */
142
134
  running = null;
143
135
  constructor(definition) {
136
+ this.cron = parseCron(definition.expression);
144
137
  this.definition = definition;
145
138
  }
146
139
  getName() {
@@ -152,9 +145,10 @@ var ScheduledTask = class {
152
145
  getTimezone() {
153
146
  return this.definition.timezone;
154
147
  }
155
- isDue(date = /* @__PURE__ */ new Date()) {
156
- if (this.definition.timezone) return isDueInTimezone(this.definition.expression, this.definition.timezone, date);
157
- return isDue(this.definition.expression, date);
148
+ isDue(date = /* @__PURE__ */ new Date(), defaultTimezone) {
149
+ const timezone = this.definition.timezone ?? defaultTimezone;
150
+ if (timezone) return isDueInTimezone(this.definition.expression, timezone, date);
151
+ return matchesCron(date, this.cron);
158
152
  }
159
153
  async shouldRun() {
160
154
  if (this.definition.when) {
@@ -559,7 +553,7 @@ var Scheduler = class {
559
553
  return [...this.tasks];
560
554
  }
561
555
  getDueTasks(date = /* @__PURE__ */ new Date()) {
562
- return this.tasks.filter((task) => task.isDue(date));
556
+ return this.tasks.filter((task) => task.isDue(date, this.options.timezone));
563
557
  }
564
558
  /**
565
559
  * Due tasks run concurrently: awaited one by one, a slow task pushed the rest
@@ -0,0 +1,17 @@
1
+ //#region src/queue/serialize.ts
2
+ /**
3
+ * Read a queued job out of a JSON message body. The dates are strings on the
4
+ * wire, so a reader that skips them hands callers a `QueuedJob` whose date
5
+ * fields are not dates.
6
+ */
7
+ function deserializeQueuedJob(body) {
8
+ const raw = JSON.parse(body);
9
+ return {
10
+ ...raw,
11
+ availableAt: new Date(raw.availableAt),
12
+ createdAt: new Date(raw.createdAt),
13
+ reservedAt: raw.reservedAt ? new Date(raw.reservedAt) : null
14
+ };
15
+ }
16
+ //#endregion
17
+ export { deserializeQueuedJob as t };
@@ -1,8 +1,11 @@
1
1
  import type { StorageDriver, StorageDriverFactory, StorageConfig } from './types.js';
2
+ import type { DriverMapEntry } from '../introspection/types.js';
2
3
  export declare class StorageManager {
3
4
  private readonly defaultDiskName;
4
5
  private readonly diskFactories;
5
6
  private readonly resolvedDisks;
7
+ /** The configured driver per disk, keyed like `diskFactories`; null for a bare `registerDisk()` factory. */
8
+ private readonly diskDrivers;
6
9
  private driverFactories;
7
10
  constructor(config?: StorageConfig);
8
11
  private registerBuiltinDrivers;
@@ -13,5 +16,7 @@ export declare class StorageManager {
13
16
  hasDisk(name: string): boolean;
14
17
  getDefaultDiskName(): string;
15
18
  getDiskNames(): string[];
19
+ /** The declared disks and the default, building none of them (RFC 0026 §1). */
20
+ describe(): DriverMapEntry;
16
21
  }
17
22
  export declare function createStorageManager(config?: StorageConfig): StorageManager;
@@ -3,8 +3,23 @@ export declare class LocalDriver implements StorageDriver {
3
3
  private readonly root;
4
4
  private readonly baseUrl;
5
5
  private readonly defaultVisibility;
6
+ private resolvedRoot?;
6
7
  constructor(options: LocalDriverOptions);
7
8
  private fullPath;
9
+ /**
10
+ * `resolve()` collapses `..` without following links, so the lexical check
11
+ * above still accepts `<root>/link/secret`, and every reader below follows
12
+ * the link. Each component is resolved instead of refused: a link that stays
13
+ * inside the disk is legitimate. One resolution per component is enough,
14
+ * since `realPathOfNearestExisting()` returns a path holding no further link.
15
+ */
16
+ private assertNoEscapingLink;
17
+ /**
18
+ * Memoized: the root is fixed for the driver's lifetime and re-resolving it
19
+ * costs a third of an operation's syscalls. A disk whose root does not exist
20
+ * yet caches nothing, so the guard starts once the root is created.
21
+ */
22
+ private canonicalRoot;
8
23
  private ensureDirectory;
9
24
  put(path: string, content: Buffer | string, options?: PutOptions): Promise<string>;
10
25
  putFile(path: string, localPath: string, options?: PutOptions): Promise<string>;
@@ -1,2 +1,2 @@
1
- import { a as LocalDriver, i as S3Driver, n as createStorageManager, r as MemoryDriver, t as StorageManager } from "../storage-6HLaUf9j.js";
1
+ import { a as LocalDriver, i as S3Driver, n as createStorageManager, r as MemoryDriver, t as StorageManager } from "../storage-IlUesK2t.js";
2
2
  export { LocalDriver, MemoryDriver, S3Driver, StorageManager, createStorageManager };
@@ -0,0 +1,2 @@
1
+ /** Encode object-key segments without turning directory separators into data. */
2
+ export declare function encodeStoragePath(path: string): string;
@@ -1,32 +1,84 @@
1
- import { t as trimSlashes } from "./trim-slashes-BLY9hKAa.js";
1
+ import { i as trimSlashes, r as realPathOfNearestExisting, t as isPathWithin } from "./contained-path-BkNSBljW.js";
2
2
  import { t as warnOnce } from "./warn-once-p-IlMjra.js";
3
- import { dirname, join, resolve, sep } from "node:path";
4
- import { copyFile, mkdir, open, readFile, readdir, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
3
+ import { t as describeDriverMap } from "./driver-map-CkQc52j-.js";
4
+ import { dirname, join, relative, resolve, sep } from "node:path";
5
+ import { copyFile, lstat, mkdir, open, readFile, readdir, readlink, realpath, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
5
6
  import { existsSync } from "node:fs";
6
7
  import { Readable } from "node:stream";
8
+ //#region src/storage/url-path.ts
9
+ /** Encode object-key segments without turning directory separators into data. */
10
+ function encodeStoragePath(path) {
11
+ return path.split("/").map((segment) => encodeURIComponent(segment)).join("/");
12
+ }
13
+ //#endregion
7
14
  //#region src/storage/drivers/LocalDriver.ts
8
15
  var LocalDriver = class {
9
16
  root;
10
17
  baseUrl;
11
18
  defaultVisibility;
19
+ resolvedRoot;
12
20
  constructor(options) {
13
21
  this.root = options.root;
14
22
  this.baseUrl = options.url ?? "";
15
23
  this.defaultVisibility = options.visibility ?? "private";
16
24
  }
17
- fullPath(path) {
25
+ async fullPath(path) {
18
26
  const root = resolve(this.root);
19
27
  const candidate = resolve(root, path);
20
- if (candidate !== root && !candidate.startsWith(root + sep)) throw new Error(`LocalDriver: path escapes the storage root: "${path}"`);
28
+ if (candidate !== root && !isPathWithin(root, candidate)) throw new Error(`LocalDriver: path escapes the storage root: "${path}"`);
29
+ await this.assertNoEscapingLink(root, candidate, path);
21
30
  return candidate;
22
31
  }
32
+ /**
33
+ * `resolve()` collapses `..` without following links, so the lexical check
34
+ * above still accepts `<root>/link/secret`, and every reader below follows
35
+ * the link. Each component is resolved instead of refused: a link that stays
36
+ * inside the disk is legitimate. One resolution per component is enough,
37
+ * since `realPathOfNearestExisting()` returns a path holding no further link.
38
+ */
39
+ async assertNoEscapingLink(root, candidate, path) {
40
+ const realRoot = await this.canonicalRoot();
41
+ if (realRoot === void 0) return;
42
+ let current = realRoot;
43
+ for (const part of relative(root, candidate).split(sep).filter(Boolean)) {
44
+ current = join(current, part);
45
+ let link;
46
+ try {
47
+ if (!(await lstat(current)).isSymbolicLink()) continue;
48
+ link = await readlink(current);
49
+ } catch (error) {
50
+ const code = error.code;
51
+ if (code === "ENOENT" || code === "ENOTDIR") return;
52
+ throw error;
53
+ }
54
+ const target = await realPathOfNearestExisting(resolve(dirname(current), link));
55
+ if (target === void 0) throw new Error(`LocalDriver: cannot resolve a symbolic link in the path: "${path}"`);
56
+ if (target !== realRoot && !isPathWithin(realRoot, target)) throw new Error(`LocalDriver: path escapes the storage root through a symbolic link: "${path}"`);
57
+ current = target;
58
+ }
59
+ }
60
+ /**
61
+ * Memoized: the root is fixed for the driver's lifetime and re-resolving it
62
+ * costs a third of an operation's syscalls. A disk whose root does not exist
63
+ * yet caches nothing, so the guard starts once the root is created.
64
+ */
65
+ async canonicalRoot() {
66
+ this.resolvedRoot ??= realpath(resolve(this.root));
67
+ try {
68
+ return await this.resolvedRoot;
69
+ } catch (error) {
70
+ this.resolvedRoot = void 0;
71
+ if (error.code === "ENOENT") return void 0;
72
+ throw error;
73
+ }
74
+ }
23
75
  async ensureDirectory(filePath) {
24
76
  const dir = dirname(filePath);
25
77
  if (!existsSync(dir)) await mkdir(dir, { recursive: true });
26
78
  }
27
79
  async put(path, content, options) {
28
80
  if (options?.visibility) this.warnUnsupportedVisibility(options.visibility, "put");
29
- const fullPath = this.fullPath(path);
81
+ const fullPath = await this.fullPath(path);
30
82
  await this.ensureDirectory(fullPath);
31
83
  const buffer = typeof content === "string" ? Buffer.from(content) : content;
32
84
  await writeFile(fullPath, buffer);
@@ -37,7 +89,7 @@ var LocalDriver = class {
37
89
  return this.put(path, content, options);
38
90
  }
39
91
  async get(path) {
40
- const fullPath = this.fullPath(path);
92
+ const fullPath = await this.fullPath(path);
41
93
  try {
42
94
  return await readFile(fullPath);
43
95
  } catch {
@@ -49,7 +101,7 @@ var LocalDriver = class {
49
101
  return content ? content.toString("utf-8") : null;
50
102
  }
51
103
  async getStream(path, options) {
52
- const fullPath = this.fullPath(path);
104
+ const fullPath = await this.fullPath(path);
53
105
  let handle;
54
106
  try {
55
107
  handle = await open(fullPath, "r");
@@ -67,10 +119,10 @@ var LocalDriver = class {
67
119
  return Readable.toWeb(nodeStream);
68
120
  }
69
121
  async exists(path) {
70
- return existsSync(this.fullPath(path));
122
+ return existsSync(await this.fullPath(path));
71
123
  }
72
124
  async delete(path) {
73
- const fullPath = this.fullPath(path);
125
+ const fullPath = await this.fullPath(path);
74
126
  try {
75
127
  await unlink(fullPath);
76
128
  return true;
@@ -84,35 +136,35 @@ var LocalDriver = class {
84
136
  return deleted;
85
137
  }
86
138
  async copy(from, to) {
87
- const fromPath = this.fullPath(from);
88
- const toPath = this.fullPath(to);
139
+ const fromPath = await this.fullPath(from);
140
+ const toPath = await this.fullPath(to);
89
141
  await this.ensureDirectory(toPath);
90
142
  await copyFile(fromPath, toPath);
91
143
  return to;
92
144
  }
93
145
  async move(from, to) {
94
- const fromPath = this.fullPath(from);
95
- const toPath = this.fullPath(to);
146
+ const fromPath = await this.fullPath(from);
147
+ const toPath = await this.fullPath(to);
96
148
  await this.ensureDirectory(toPath);
97
149
  await rename(fromPath, toPath);
98
150
  return to;
99
151
  }
100
152
  url(path) {
101
- return `${this.baseUrl}/${path}`;
153
+ return `${this.baseUrl}/${encodeStoragePath(path)}`;
102
154
  }
103
155
  async temporaryUrl(path, _expiration) {
104
156
  return this.url(path);
105
157
  }
106
158
  async size(path) {
107
- const fullPath = this.fullPath(path);
159
+ const fullPath = await this.fullPath(path);
108
160
  return (await stat(fullPath)).size;
109
161
  }
110
162
  async lastModified(path) {
111
- const fullPath = this.fullPath(path);
163
+ const fullPath = await this.fullPath(path);
112
164
  return (await stat(fullPath)).mtime;
113
165
  }
114
166
  async metadata(path) {
115
- const fullPath = this.fullPath(path);
167
+ const fullPath = await this.fullPath(path);
116
168
  try {
117
169
  const stats = await stat(fullPath);
118
170
  return {
@@ -126,36 +178,35 @@ var LocalDriver = class {
126
178
  }
127
179
  }
128
180
  async files(directory) {
129
- const fullPath = this.fullPath(directory);
181
+ const fullPath = await this.fullPath(directory);
130
182
  if (!existsSync(fullPath)) return [];
131
183
  return (await readdir(fullPath, { withFileTypes: true })).filter((entry) => entry.isFile()).map((entry) => join(directory, entry.name));
132
184
  }
133
185
  async directories(directory) {
134
- const fullPath = this.fullPath(directory);
186
+ const fullPath = await this.fullPath(directory);
135
187
  if (!existsSync(fullPath)) return [];
136
188
  return (await readdir(fullPath, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => join(directory, entry.name));
137
189
  }
138
190
  async allFiles(directory) {
139
191
  const files = [];
140
- const scan = async (dir) => {
141
- const fullPath = this.fullPath(dir);
192
+ const scan = async (dir, fullPath) => {
142
193
  if (!existsSync(fullPath)) return;
143
194
  const entries = await readdir(fullPath, { withFileTypes: true });
144
195
  for (const entry of entries) {
145
196
  const entryPath = join(dir, entry.name);
146
197
  if (entry.isFile()) files.push(entryPath);
147
- else if (entry.isDirectory()) await scan(entryPath);
198
+ else if (entry.isDirectory()) await scan(entryPath, join(fullPath, entry.name));
148
199
  }
149
200
  };
150
- await scan(directory);
201
+ await scan(directory, await this.fullPath(directory));
151
202
  return files;
152
203
  }
153
204
  async makeDirectory(path) {
154
- const fullPath = this.fullPath(path);
205
+ const fullPath = await this.fullPath(path);
155
206
  await mkdir(fullPath, { recursive: true });
156
207
  }
157
208
  async deleteDirectory(path) {
158
- const fullPath = this.fullPath(path);
209
+ const fullPath = await this.fullPath(path);
159
210
  if (existsSync(fullPath)) await rm(fullPath, {
160
211
  recursive: true,
161
212
  force: true
@@ -369,7 +420,7 @@ var S3Driver = class {
369
420
  return to;
370
421
  }
371
422
  url(path) {
372
- return `${this.baseUrl}/${this.prefixKey(path)}`;
423
+ return `${this.baseUrl}/${encodeStoragePath(this.prefixKey(path))}`;
373
424
  }
374
425
  async temporaryUrl(path, expiration, options) {
375
426
  const client = await this.getClient();
@@ -621,7 +672,7 @@ var MemoryDriver = class {
621
672
  }
622
673
  url(path) {
623
674
  const normalized = this.normalizePath(path);
624
- return `${this.baseUrl}/${normalized}`;
675
+ return `${this.baseUrl}/${encodeStoragePath(normalized)}`;
625
676
  }
626
677
  async temporaryUrl(path, _expiration) {
627
678
  return this.url(path);
@@ -709,12 +760,17 @@ var StorageManager = class {
709
760
  defaultDiskName;
710
761
  diskFactories = /* @__PURE__ */ new Map();
711
762
  resolvedDisks = /* @__PURE__ */ new Map();
763
+ /** The configured driver per disk, keyed like `diskFactories`; null for a bare `registerDisk()` factory. */
764
+ diskDrivers = /* @__PURE__ */ new Map();
712
765
  driverFactories = /* @__PURE__ */ new Map();
713
766
  constructor(config = {}) {
714
767
  this.defaultDiskName = config.default ?? "local";
715
768
  this.registerBuiltinDrivers();
716
769
  if (config.disks) for (const [name, diskConfig] of Object.entries(config.disks)) this.registerDiskFromConfig(name, diskConfig);
717
- if (!this.diskFactories.has(this.defaultDiskName) && this.defaultDiskName === "local") this.diskFactories.set("local", () => new LocalDriver({ root: "./storage" }));
770
+ if (!this.diskFactories.has(this.defaultDiskName) && this.defaultDiskName === "local") {
771
+ this.diskFactories.set("local", () => new LocalDriver({ root: "./storage" }));
772
+ this.diskDrivers.set("local", "local");
773
+ }
718
774
  }
719
775
  registerBuiltinDrivers() {
720
776
  this.driverFactories.set("local", (options) => {
@@ -732,6 +788,7 @@ var StorageManager = class {
732
788
  const factory = this.driverFactories.get(driver);
733
789
  if (!factory) throw new Error(`Unknown storage driver: ${driver}`);
734
790
  this.diskFactories.set(name, () => factory(options));
791
+ this.diskDrivers.set(name, driver);
735
792
  }
736
793
  disk(name) {
737
794
  const diskName = name ?? this.defaultDiskName;
@@ -745,6 +802,7 @@ var StorageManager = class {
745
802
  }
746
803
  registerDisk(name, factory) {
747
804
  this.diskFactories.set(name, factory);
805
+ this.diskDrivers.set(name, null);
748
806
  this.resolvedDisks.delete(name);
749
807
  }
750
808
  registerDriver(name, factory) {
@@ -759,6 +817,10 @@ var StorageManager = class {
759
817
  getDiskNames() {
760
818
  return Array.from(this.diskFactories.keys());
761
819
  }
820
+ /** The declared disks and the default, building none of them (RFC 0026 §1). */
821
+ describe() {
822
+ return describeDriverMap(this.defaultDiskName, this.diskDrivers);
823
+ }
762
824
  };
763
825
  function createStorageManager(config) {
764
826
  return new StorageManager(config);
@@ -14,3 +14,11 @@ export declare function isPathWithin(root: string, candidate: string): boolean;
14
14
  * doing only the candidate would 404 every asset such an app serves.
15
15
  */
16
16
  export declare function isRealPathWithin(root: string, candidate: string): Promise<boolean>;
17
+ /**
18
+ * The canonical form of a path that need not exist: the deepest ancestor that
19
+ * resolves is canonicalized and the missing tail rejoined, so a caller can
20
+ * judge where a write would land. `undefined` when the path cannot be resolved
21
+ * at all — a link cycle, a directory that will not open — which a containment
22
+ * check must treat as out of bounds rather than as inside.
23
+ */
24
+ export declare function realPathOfNearestExisting(path: string): Promise<string | undefined>;
@@ -0,0 +1,12 @@
1
+ /** The name-keyed class registries a queued message is resolved back through. */
2
+ export type ClassRegistryKind = 'job' | 'event' | 'notification';
3
+ interface NamedClass {
4
+ readonly name: string;
5
+ }
6
+ /**
7
+ * Warns when a different class takes a name another class holds; the same class
8
+ * again is silent. The caller still overwrites, last wins, so only the log
9
+ * changes. A future major will throw here instead.
10
+ */
11
+ export declare function reportRegistryCollision(kind: ClassRegistryKind, name: string, taken: NamedClass | undefined, incoming: NamedClass): void;
12
+ export {};
@@ -1,62 +1,6 @@
1
- import { n as trimTrailingSlashes } from "./trim-slashes-BLY9hKAa.js";
1
+ import { a as trimTrailingSlashes } from "./contained-path-BkNSBljW.js";
2
2
  import { resolve } from "node:path";
3
- import chalk from "chalk";
4
- import figlet from "figlet";
5
- import standard from "figlet/importable-fonts/Standard.js";
6
3
  import { readFileSync } from "node:fs";
7
- //#region package.json
8
- var version = "2.25.1";
9
- //#endregion
10
- //#region src/http/dev-banner.ts
11
- figlet.parseFont("Standard", standard);
12
- function generateAsciiArt(text) {
13
- try {
14
- return figlet.textSync(text, {
15
- font: "Standard",
16
- horizontalLayout: "default",
17
- verticalLayout: "default"
18
- });
19
- } catch (error) {
20
- console.error("Failed to generate FIGlet banner, falling back to plain text:", error);
21
- return text.toUpperCase();
22
- }
23
- }
24
- const GUREN_ASCII_ART = chalk.redBright.bold(generateAsciiArt("GUREN"));
25
- const GUREN_VERSION = version;
26
- /**
27
- * A wildcard bind answers on every interface but is not itself dialable on
28
- * every platform. Shared with `Application.listen()`'s returned address, which
29
- * is the same fact rendered twice.
30
- */
31
- function isWildcardHost(hostname) {
32
- return hostname === "0.0.0.0" || hostname === "::";
33
- }
34
- /** `host:port`, bracketing an IPv6 literal so the result is dialable. */
35
- function formatHostPort(hostname, port) {
36
- return `${hostname.includes(":") ? `[${hostname}]` : hostname}:${port}`;
37
- }
38
- function logDevServerBanner({ hostname, port, assetsUrl = "http://localhost:5173" }) {
39
- const localUrl = `http://localhost:${port}`;
40
- const boundUrl = `http://${formatHostPort(hostname, port)}`;
41
- const boundLabel = isWildcardHost(hostname) ? " (all interfaces)" : "";
42
- const header = [
43
- GUREN_ASCII_ART,
44
- chalk.magentaBright.bold(`Guren v${GUREN_VERSION} ignites — burning bright like a crimson lotus.`),
45
- ""
46
- ];
47
- const detail = (label, value) => `${chalk.magentaBright(" •")} ${chalk.bold(label.padEnd(14))}: ${chalk.cyanBright(value)}`;
48
- const banner = [
49
- ...header,
50
- detail("App URL", localUrl),
51
- detail("Bound address", `${boundUrl}${boundLabel}`),
52
- detail("Asset server", `${assetsUrl} (Vite)`),
53
- "",
54
- chalk.yellowBright("Press Ctrl+C to douse the flames."),
55
- ""
56
- ].join("\n");
57
- console.log(banner);
58
- }
59
- //#endregion
60
4
  //#region src/http/vite-dev-server.ts
61
5
  /**
62
6
  * Build the inline config the managed dev server starts with. `server.host` is
@@ -199,4 +143,4 @@ function getManifestCss(entry) {
199
143
  return entry.css;
200
144
  }
201
145
  //#endregion
202
- export { getManifestCss as a, isViteProduction as c, startViteDevServer as d, GUREN_ASCII_ART as f, logDevServerBanner as h, clientManifestCandidates as i, loadViteManifest as l, isWildcardHost as m, INJECTED_CLIENT_MANIFEST_SOURCE as n, getManifestFile as o, formatHostPort as p, PUBLIC_ASSETS_URL_PREFIX as r, injectedClientManifest as s, DEFAULT_DEV_SERVER_URL as t, normalizeDevServerUrl as u };
146
+ export { getManifestCss as a, isViteProduction as c, startViteDevServer as d, 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 };