@guren/server 2.25.0 → 2.26.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 (80) hide show
  1. package/README.md +42 -0
  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/{Resource-BdYd4J9a.js → Resource-gki0_2B6.js} +172 -37
  5. package/dist/agent/scopes.d.ts +1 -3
  6. package/dist/auth/email-verification.d.ts +6 -0
  7. package/dist/auth/index.js +1 -1
  8. package/dist/auth/password-reset.d.ts +8 -2
  9. package/dist/{auth-vFeem6uM.js → auth-DiyWALZT.js} +38 -9
  10. package/dist/authorization/index.js +2 -2
  11. package/dist/{authorization-BLhwA2Yh.js → authorization-E6X6Y-B6.js} +1 -1
  12. package/dist/broadcasting/index.js +1 -1
  13. package/dist/{broadcasting-BUBCPCnu.js → broadcasting-D0vMkKcq.js} +1 -1
  14. package/dist/cache/index.js +1 -1
  15. package/dist/cache/stores/FileStore.d.ts +2 -0
  16. package/dist/cache/stores/MemoryStore.d.ts +1 -0
  17. package/dist/cache/stores/RedisStore.d.ts +1 -0
  18. package/dist/cache/types.d.ts +2 -0
  19. package/dist/{cache-93n2PCnB.js → cache-DcnRufMe.js} +94 -25
  20. package/dist/contained-path-BkNSBljW.js +78 -0
  21. package/dist/container/Container.d.ts +6 -2
  22. package/dist/container/defineModule.d.ts +10 -0
  23. package/dist/{default-application-D5ezhhiV.js → default-application-DWwscxfW.js} +14 -18
  24. package/dist/encryption/index.js +1 -1
  25. package/dist/{encryption-D1dxfMqD.js → encryption-CWK5l22W.js} +1 -1
  26. package/dist/events/EventManager.d.ts +2 -0
  27. package/dist/events/index.js +1 -1
  28. package/dist/{events-c94CdUFc.js → events-DQavGm8W.js} +20 -7
  29. package/dist/health/HealthManager.d.ts +0 -1
  30. package/dist/health/index.js +1 -1
  31. package/dist/{health-CB0oS_UE.js → health-Bg0Xj3aD.js} +8 -8
  32. package/dist/http/Application.d.ts +12 -1
  33. package/dist/http/middleware/rate-limit.d.ts +1 -4
  34. package/dist/i18n/index.js +1 -1
  35. package/dist/{i18n-DqcRD4qL.js → i18n-DmMKcbqj.js} +1 -1
  36. package/dist/index.d.ts +3 -1
  37. package/dist/index.js +61 -50
  38. package/dist/internal/app-conventions.d.ts +6 -0
  39. package/dist/internal/app-conventions.js +9 -0
  40. package/dist/internal/testing.d.ts +1 -1
  41. package/dist/internal/testing.js +2 -2
  42. package/dist/lambda/index.js +66 -28
  43. package/dist/logging/index.js +1 -1
  44. package/dist/{logging-YbKmbAd7.js → logging-Ci0mBk5k.js} +1 -1
  45. package/dist/mail/index.js +1 -1
  46. package/dist/{mail-uRBrUl9q.js → mail-CI2Kfe8P.js} +2 -2
  47. package/dist/mvc/Controller.d.ts +3 -2
  48. package/dist/mvc/inertia/InertiaEngine.d.ts +31 -0
  49. package/dist/mvc/inertia/props.d.ts +71 -0
  50. package/dist/notifications/index.js +1 -1
  51. package/dist/notifications/registry.d.ts +2 -2
  52. package/dist/{notifications-LHuujttf.js → notifications-Bp2uamzD.js} +7 -5
  53. package/dist/providers/ConfigServiceProvider.d.ts +5 -5
  54. package/dist/queue/Job.d.ts +5 -0
  55. package/dist/queue/Worker.d.ts +6 -1
  56. package/dist/queue/drivers/RedisDriver.d.ts +4 -2
  57. package/dist/queue/drivers/SqsDriver.d.ts +31 -2
  58. package/dist/queue/drivers/redis-queue-scripts.d.ts +83 -0
  59. package/dist/queue/index.js +2 -2
  60. package/dist/queue/serialize.d.ts +7 -0
  61. package/dist/queue/types.d.ts +13 -2
  62. package/dist/{queue-BiBn5Sff.js → queue-Bo4Q857L.js} +294 -125
  63. package/dist/redis/RedisEmailVerificationStore.d.ts +2 -0
  64. package/dist/redis/RedisPasswordResetStore.d.ts +2 -0
  65. package/dist/redis/auth-token-scripts.d.ts +4 -0
  66. package/dist/redis/index.js +50 -0
  67. package/dist/runtime/index.js +3 -36
  68. package/dist/scheduling/ScheduledTask.d.ts +2 -1
  69. package/dist/scheduling/index.js +1 -1
  70. package/dist/{scheduling-DhYfbJFj.js → scheduling-DNV5tj44.js} +32 -38
  71. package/dist/serialize-CKXek0Tr.js +17 -0
  72. package/dist/storage/drivers/LocalDriver.d.ts +15 -0
  73. package/dist/storage/index.js +1 -1
  74. package/dist/storage/url-path.d.ts +2 -0
  75. package/dist/{storage-6HLaUf9j.js → storage-wFsUJHZW.js} +78 -28
  76. package/dist/support/contained-path.d.ts +8 -0
  77. package/dist/support/registry-collision.d.ts +12 -0
  78. package/dist/{vite-manifest-C5kqRoBV.js → vite-manifest-DlU94f3Z.js} +2 -2
  79. package/package.json +20 -2
  80. package/dist/trim-slashes-BLY9hKAa.js +0 -22
@@ -1,45 +1,12 @@
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-C5kqRoBV.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-DlU94f3Z.js";
5
5
  import { createRequire } from "node:module";
6
- import { dirname, extname, join, resolve, sep } from "node:path";
6
+ import { dirname, extname, join, resolve } from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
- import { realpath } from "node:fs/promises";
9
8
  import { serveStatic } from "hono/bun";
10
9
  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
10
  //#region src/http/static-documents.ts
44
11
  /**
45
12
  * The one rule for "a browser would render this as a document in the serving
@@ -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 };
@@ -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-wFsUJHZW.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,83 @@
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 { dirname, join, relative, resolve, sep } from "node:path";
4
+ import { copyFile, lstat, mkdir, open, readFile, readdir, readlink, realpath, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
5
5
  import { existsSync } from "node:fs";
6
6
  import { Readable } from "node:stream";
7
+ //#region src/storage/url-path.ts
8
+ /** Encode object-key segments without turning directory separators into data. */
9
+ function encodeStoragePath(path) {
10
+ return path.split("/").map((segment) => encodeURIComponent(segment)).join("/");
11
+ }
12
+ //#endregion
7
13
  //#region src/storage/drivers/LocalDriver.ts
8
14
  var LocalDriver = class {
9
15
  root;
10
16
  baseUrl;
11
17
  defaultVisibility;
18
+ resolvedRoot;
12
19
  constructor(options) {
13
20
  this.root = options.root;
14
21
  this.baseUrl = options.url ?? "";
15
22
  this.defaultVisibility = options.visibility ?? "private";
16
23
  }
17
- fullPath(path) {
24
+ async fullPath(path) {
18
25
  const root = resolve(this.root);
19
26
  const candidate = resolve(root, path);
20
- if (candidate !== root && !candidate.startsWith(root + sep)) throw new Error(`LocalDriver: path escapes the storage root: "${path}"`);
27
+ if (candidate !== root && !isPathWithin(root, candidate)) throw new Error(`LocalDriver: path escapes the storage root: "${path}"`);
28
+ await this.assertNoEscapingLink(root, candidate, path);
21
29
  return candidate;
22
30
  }
31
+ /**
32
+ * `resolve()` collapses `..` without following links, so the lexical check
33
+ * above still accepts `<root>/link/secret`, and every reader below follows
34
+ * the link. Each component is resolved instead of refused: a link that stays
35
+ * inside the disk is legitimate. One resolution per component is enough,
36
+ * since `realPathOfNearestExisting()` returns a path holding no further link.
37
+ */
38
+ async assertNoEscapingLink(root, candidate, path) {
39
+ const realRoot = await this.canonicalRoot();
40
+ if (realRoot === void 0) return;
41
+ let current = realRoot;
42
+ for (const part of relative(root, candidate).split(sep).filter(Boolean)) {
43
+ current = join(current, part);
44
+ let link;
45
+ try {
46
+ if (!(await lstat(current)).isSymbolicLink()) continue;
47
+ link = await readlink(current);
48
+ } catch (error) {
49
+ const code = error.code;
50
+ if (code === "ENOENT" || code === "ENOTDIR") return;
51
+ throw error;
52
+ }
53
+ const target = await realPathOfNearestExisting(resolve(dirname(current), link));
54
+ if (target === void 0) throw new Error(`LocalDriver: cannot resolve a symbolic link in the path: "${path}"`);
55
+ if (target !== realRoot && !isPathWithin(realRoot, target)) throw new Error(`LocalDriver: path escapes the storage root through a symbolic link: "${path}"`);
56
+ current = target;
57
+ }
58
+ }
59
+ /**
60
+ * Memoized: the root is fixed for the driver's lifetime and re-resolving it
61
+ * costs a third of an operation's syscalls. A disk whose root does not exist
62
+ * yet caches nothing, so the guard starts once the root is created.
63
+ */
64
+ async canonicalRoot() {
65
+ this.resolvedRoot ??= realpath(resolve(this.root));
66
+ try {
67
+ return await this.resolvedRoot;
68
+ } catch (error) {
69
+ this.resolvedRoot = void 0;
70
+ if (error.code === "ENOENT") return void 0;
71
+ throw error;
72
+ }
73
+ }
23
74
  async ensureDirectory(filePath) {
24
75
  const dir = dirname(filePath);
25
76
  if (!existsSync(dir)) await mkdir(dir, { recursive: true });
26
77
  }
27
78
  async put(path, content, options) {
28
79
  if (options?.visibility) this.warnUnsupportedVisibility(options.visibility, "put");
29
- const fullPath = this.fullPath(path);
80
+ const fullPath = await this.fullPath(path);
30
81
  await this.ensureDirectory(fullPath);
31
82
  const buffer = typeof content === "string" ? Buffer.from(content) : content;
32
83
  await writeFile(fullPath, buffer);
@@ -37,7 +88,7 @@ var LocalDriver = class {
37
88
  return this.put(path, content, options);
38
89
  }
39
90
  async get(path) {
40
- const fullPath = this.fullPath(path);
91
+ const fullPath = await this.fullPath(path);
41
92
  try {
42
93
  return await readFile(fullPath);
43
94
  } catch {
@@ -49,7 +100,7 @@ var LocalDriver = class {
49
100
  return content ? content.toString("utf-8") : null;
50
101
  }
51
102
  async getStream(path, options) {
52
- const fullPath = this.fullPath(path);
103
+ const fullPath = await this.fullPath(path);
53
104
  let handle;
54
105
  try {
55
106
  handle = await open(fullPath, "r");
@@ -67,10 +118,10 @@ var LocalDriver = class {
67
118
  return Readable.toWeb(nodeStream);
68
119
  }
69
120
  async exists(path) {
70
- return existsSync(this.fullPath(path));
121
+ return existsSync(await this.fullPath(path));
71
122
  }
72
123
  async delete(path) {
73
- const fullPath = this.fullPath(path);
124
+ const fullPath = await this.fullPath(path);
74
125
  try {
75
126
  await unlink(fullPath);
76
127
  return true;
@@ -84,35 +135,35 @@ var LocalDriver = class {
84
135
  return deleted;
85
136
  }
86
137
  async copy(from, to) {
87
- const fromPath = this.fullPath(from);
88
- const toPath = this.fullPath(to);
138
+ const fromPath = await this.fullPath(from);
139
+ const toPath = await this.fullPath(to);
89
140
  await this.ensureDirectory(toPath);
90
141
  await copyFile(fromPath, toPath);
91
142
  return to;
92
143
  }
93
144
  async move(from, to) {
94
- const fromPath = this.fullPath(from);
95
- const toPath = this.fullPath(to);
145
+ const fromPath = await this.fullPath(from);
146
+ const toPath = await this.fullPath(to);
96
147
  await this.ensureDirectory(toPath);
97
148
  await rename(fromPath, toPath);
98
149
  return to;
99
150
  }
100
151
  url(path) {
101
- return `${this.baseUrl}/${path}`;
152
+ return `${this.baseUrl}/${encodeStoragePath(path)}`;
102
153
  }
103
154
  async temporaryUrl(path, _expiration) {
104
155
  return this.url(path);
105
156
  }
106
157
  async size(path) {
107
- const fullPath = this.fullPath(path);
158
+ const fullPath = await this.fullPath(path);
108
159
  return (await stat(fullPath)).size;
109
160
  }
110
161
  async lastModified(path) {
111
- const fullPath = this.fullPath(path);
162
+ const fullPath = await this.fullPath(path);
112
163
  return (await stat(fullPath)).mtime;
113
164
  }
114
165
  async metadata(path) {
115
- const fullPath = this.fullPath(path);
166
+ const fullPath = await this.fullPath(path);
116
167
  try {
117
168
  const stats = await stat(fullPath);
118
169
  return {
@@ -126,36 +177,35 @@ var LocalDriver = class {
126
177
  }
127
178
  }
128
179
  async files(directory) {
129
- const fullPath = this.fullPath(directory);
180
+ const fullPath = await this.fullPath(directory);
130
181
  if (!existsSync(fullPath)) return [];
131
182
  return (await readdir(fullPath, { withFileTypes: true })).filter((entry) => entry.isFile()).map((entry) => join(directory, entry.name));
132
183
  }
133
184
  async directories(directory) {
134
- const fullPath = this.fullPath(directory);
185
+ const fullPath = await this.fullPath(directory);
135
186
  if (!existsSync(fullPath)) return [];
136
187
  return (await readdir(fullPath, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => join(directory, entry.name));
137
188
  }
138
189
  async allFiles(directory) {
139
190
  const files = [];
140
- const scan = async (dir) => {
141
- const fullPath = this.fullPath(dir);
191
+ const scan = async (dir, fullPath) => {
142
192
  if (!existsSync(fullPath)) return;
143
193
  const entries = await readdir(fullPath, { withFileTypes: true });
144
194
  for (const entry of entries) {
145
195
  const entryPath = join(dir, entry.name);
146
196
  if (entry.isFile()) files.push(entryPath);
147
- else if (entry.isDirectory()) await scan(entryPath);
197
+ else if (entry.isDirectory()) await scan(entryPath, join(fullPath, entry.name));
148
198
  }
149
199
  };
150
- await scan(directory);
200
+ await scan(directory, await this.fullPath(directory));
151
201
  return files;
152
202
  }
153
203
  async makeDirectory(path) {
154
- const fullPath = this.fullPath(path);
204
+ const fullPath = await this.fullPath(path);
155
205
  await mkdir(fullPath, { recursive: true });
156
206
  }
157
207
  async deleteDirectory(path) {
158
- const fullPath = this.fullPath(path);
208
+ const fullPath = await this.fullPath(path);
159
209
  if (existsSync(fullPath)) await rm(fullPath, {
160
210
  recursive: true,
161
211
  force: true
@@ -369,7 +419,7 @@ var S3Driver = class {
369
419
  return to;
370
420
  }
371
421
  url(path) {
372
- return `${this.baseUrl}/${this.prefixKey(path)}`;
422
+ return `${this.baseUrl}/${encodeStoragePath(this.prefixKey(path))}`;
373
423
  }
374
424
  async temporaryUrl(path, expiration, options) {
375
425
  const client = await this.getClient();
@@ -621,7 +671,7 @@ var MemoryDriver = class {
621
671
  }
622
672
  url(path) {
623
673
  const normalized = this.normalizePath(path);
624
- return `${this.baseUrl}/${normalized}`;
674
+ return `${this.baseUrl}/${encodeStoragePath(normalized)}`;
625
675
  }
626
676
  async temporaryUrl(path, _expiration) {
627
677
  return this.url(path);
@@ -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,11 +1,11 @@
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
3
  import chalk from "chalk";
4
4
  import figlet from "figlet";
5
5
  import standard from "figlet/importable-fonts/Standard.js";
6
6
  import { readFileSync } from "node:fs";
7
7
  //#region package.json
8
- var version = "2.25.0";
8
+ var version = "2.26.0";
9
9
  //#endregion
10
10
  //#region src/http/dev-banner.ts
11
11
  figlet.parseFont("Standard", standard);
package/package.json CHANGED
@@ -1,6 +1,20 @@
1
1
  {
2
2
  "name": "@guren/server",
3
- "version": "2.25.0",
3
+ "version": "2.26.0",
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
+ "keywords": [
6
+ "guren",
7
+ "bun",
8
+ "typescript",
9
+ "fullstack",
10
+ "framework",
11
+ "hono",
12
+ "http",
13
+ "router",
14
+ "mvc",
15
+ "middleware",
16
+ "auth"
17
+ ],
4
18
  "type": "module",
5
19
  "sideEffects": false,
6
20
  "license": "MIT",
@@ -137,6 +151,10 @@
137
151
  "./jsx-dev-runtime": {
138
152
  "types": "./dist/jsx-dev-runtime.d.ts",
139
153
  "default": "./dist/jsx-dev-runtime.js"
154
+ },
155
+ "./internal/app-conventions": {
156
+ "types": "./dist/internal/app-conventions.d.ts",
157
+ "default": "./dist/internal/app-conventions.js"
140
158
  }
141
159
  },
142
160
  "scripts": {
@@ -146,7 +164,7 @@
146
164
  "test": "bun test"
147
165
  },
148
166
  "dependencies": {
149
- "@guren/orm": "^2.11.0",
167
+ "@guren/orm": "^2.12.0",
150
168
  "chalk": "^5.3.0",
151
169
  "consola": "^3.4.2",
152
170
  "figlet": "^1.7.0",
@@ -1,22 +0,0 @@
1
- //#region src/support/trim-slashes.ts
2
- /**
3
- * No regex: patterns like `/\/+$/` backtrack quadratically on long slash runs
4
- * mid-string, and several call sites feed request-derived paths.
5
- *
6
- * Twins that cannot import this module: `@guren/cli` (`src/utils.ts`) and
7
- * `@guren/plugin-cloudflare` (`src/storage/R2Driver.ts`) — keep them in step.
8
- */
9
- function trimTrailingSlashes(value) {
10
- let end = value.length;
11
- while (end > 0 && value[end - 1] === "/") end--;
12
- return value.slice(0, end);
13
- }
14
- function trimSlashes(value) {
15
- let start = 0;
16
- let end = value.length;
17
- while (start < end && value[start] === "/") start++;
18
- while (end > start && value[end - 1] === "/") end--;
19
- return value.slice(start, end);
20
- }
21
- //#endregion
22
- export { trimTrailingSlashes as n, trimSlashes as t };