@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.
- package/dist/{DocsViewerServiceProvider-CIRNHQ2I.js → DocsViewerServiceProvider-BMbcTYVw.js} +1 -1
- package/dist/{Gate-YOt54xGF.js → Gate-BL_zW82W.js} +1 -1
- package/dist/{Job-COMzBNOL.js → Job-DsFMcXVk.js} +35 -3
- package/dist/{McpServiceProvider-B-LioPSz.js → McpServiceProvider-PGFPlYTy.js} +1 -1
- package/dist/{Resource-BdYd4J9a.js → Resource-q3tJpJ0K.js} +194 -54
- package/dist/{ServiceProvider-DDW3MqQJ.js → ServiceProvider-G0YclITd.js} +60 -8
- package/dist/agent/dispatch.d.ts +4 -4
- package/dist/agent/public.js +1 -1
- package/dist/agent/scopes.d.ts +1 -3
- package/dist/agent-request-Caj6bnbj.js +18 -0
- package/dist/auth/AuthManager.d.ts +4 -0
- package/dist/auth/email-verification.d.ts +8 -1
- package/dist/auth/index.js +1 -1
- package/dist/auth/password/describe-hasher.d.ts +11 -0
- package/dist/auth/password-reset.d.ts +8 -2
- package/dist/{auth-vFeem6uM.js → auth-DIugW0O-.js} +108 -13
- package/dist/authorization/index.js +2 -2
- package/dist/authorization/middleware.d.ts +8 -0
- package/dist/{authorization-BLhwA2Yh.js → authorization-Daa6CxCg.js} +17 -2
- package/dist/broadcasting/BroadcastManager.d.ts +23 -6
- package/dist/broadcasting/index.d.ts +1 -1
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/types.d.ts +13 -1
- package/dist/{broadcasting-BUBCPCnu.js → broadcasting-N4cRV42s.js} +205 -34
- package/dist/cache/CacheManager.d.ts +5 -0
- package/dist/cache/TaggedCache.d.ts +2 -0
- package/dist/cache/index.js +1 -1
- package/dist/cache/pending-computations.d.ts +22 -0
- package/dist/cache/stores/FileStore.d.ts +2 -0
- package/dist/cache/stores/MemoryStore.d.ts +1 -0
- package/dist/cache/stores/RedisStore.d.ts +1 -0
- package/dist/cache/stores/file-lock.d.ts +1 -0
- package/dist/cache/types.d.ts +2 -0
- package/dist/{cache-93n2PCnB.js → cache-BlXopnH1.js} +247 -38
- package/dist/contained-path-BkNSBljW.js +78 -0
- package/dist/container/Container.d.ts +6 -2
- package/dist/container/ServiceProvider.d.ts +27 -2
- package/dist/container/defineModule.d.ts +14 -5
- package/dist/container/definePlugin.d.ts +2 -0
- package/dist/{default-application-D5ezhhiV.js → default-application-DWwscxfW.js} +14 -18
- package/dist/dev-banner-CfQDnkfQ.js +51 -0
- package/dist/{dispatch-BAwzftws.js → dispatch-ENWpBxbE.js} +26 -4
- package/dist/driver-map-CkQc52j-.js +12 -0
- package/dist/encryption/index.js +1 -1
- package/dist/{encryption-D1dxfMqD.js → encryption-CWK5l22W.js} +1 -1
- package/dist/events/EventManager.d.ts +2 -0
- package/dist/events/index.js +1 -1
- package/dist/{events-c94CdUFc.js → events-DQavGm8W.js} +20 -7
- package/dist/health/HealthManager.d.ts +0 -1
- package/dist/health/index.js +1 -1
- package/dist/{health-CB0oS_UE.js → health-Bg0Xj3aD.js} +8 -8
- package/dist/host-port-t6wQFaRu.js +15 -0
- package/dist/hot-reload/testing.d.ts +2 -1
- package/dist/http/Application.d.ts +31 -2
- package/dist/http/dev-banner.d.ts +0 -8
- package/dist/http/host-port.d.ts +8 -0
- package/dist/http/middleware/force-https.d.ts +2 -1
- package/dist/http/middleware/index.d.ts +1 -0
- package/dist/http/middleware/rate-limit.d.ts +1 -4
- package/dist/http/middleware/session-manager.d.ts +5 -0
- package/dist/http/middleware/websocket-origin.d.ts +22 -0
- package/dist/http/public-assets.d.ts +6 -1
- package/dist/i18n/index.js +1 -1
- package/dist/{i18n-DqcRD4qL.js → i18n-DmMKcbqj.js} +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +744 -273
- package/dist/internal/agent-request.d.ts +18 -0
- package/dist/internal/app-conventions.d.ts +6 -0
- package/dist/internal/app-conventions.js +9 -0
- package/dist/internal/dispatched-request.d.ts +4 -0
- package/dist/internal/testing.d.ts +1 -1
- package/dist/internal/testing.js +3 -3
- package/dist/internal/zod-json-schema.js +1 -1
- package/dist/introspection/driver-map.d.ts +3 -0
- package/dist/introspection/flag.d.ts +12 -0
- package/dist/introspection/manifest.d.ts +17 -0
- package/dist/introspection/plain-json.d.ts +7 -0
- package/dist/introspection/types.d.ts +167 -0
- package/dist/lambda/index.js +66 -28
- package/dist/logging/index.js +1 -1
- package/dist/{logging-YbKmbAd7.js → logging-Ci0mBk5k.js} +1 -1
- package/dist/mail/index.js +1 -1
- package/dist/{mail-uRBrUl9q.js → mail-CI2Kfe8P.js} +2 -2
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +3 -2
- package/dist/mvc/Router.d.ts +33 -0
- package/dist/mvc/inertia/InertiaEngine.d.ts +31 -0
- package/dist/mvc/inertia/props.d.ts +71 -0
- package/dist/notifications/index.js +1 -1
- package/dist/notifications/registry.d.ts +2 -2
- package/dist/{notifications-LHuujttf.js → notifications-Bp2uamzD.js} +7 -5
- package/dist/providers/ConfigServiceProvider.d.ts +12 -5
- package/dist/queue/Job.d.ts +5 -0
- package/dist/queue/QueueManager.d.ts +3 -0
- package/dist/queue/Worker.d.ts +6 -1
- package/dist/queue/drivers/RedisDriver.d.ts +4 -2
- package/dist/queue/drivers/SqsDriver.d.ts +31 -2
- package/dist/queue/drivers/redis-queue-scripts.d.ts +83 -0
- package/dist/queue/index.js +2 -2
- package/dist/queue/serialize.d.ts +7 -0
- package/dist/queue/types.d.ts +13 -2
- package/dist/{queue-BiBn5Sff.js → queue-C8s3buYz.js} +299 -125
- package/dist/redis/RedisEmailVerificationStore.d.ts +2 -0
- package/dist/redis/RedisPasswordResetStore.d.ts +2 -0
- package/dist/redis/auth-token-scripts.d.ts +4 -0
- package/dist/redis/index.js +50 -0
- package/dist/runtime/index.js +17 -37
- package/dist/scheduling/ScheduledTask.d.ts +2 -1
- package/dist/scheduling/index.js +1 -1
- package/dist/{scheduling-DhYfbJFj.js → scheduling-DNV5tj44.js} +32 -38
- package/dist/serialize-CKXek0Tr.js +17 -0
- package/dist/storage/StorageManager.d.ts +5 -0
- package/dist/storage/drivers/LocalDriver.d.ts +15 -0
- package/dist/storage/index.js +1 -1
- package/dist/storage/url-path.d.ts +2 -0
- package/dist/{storage-6HLaUf9j.js → storage-IlUesK2t.js} +91 -29
- package/dist/support/contained-path.d.ts +8 -0
- package/dist/support/registry-collision.d.ts +12 -0
- package/dist/{vite-manifest-DK55BTLk.js → vite-manifest-wPxfAzjW.js} +2 -58
- package/package.json +6 -2
- package/dist/trim-slashes-BLY9hKAa.js +0 -22
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { r as isPromiseLike } from "./Logger-DWXdtLSJ.js";
|
|
2
2
|
import { n as isHotReloadRuntime, t as claimHotDisposable } from "./hot-disposables-W2fH-GID.js";
|
|
3
|
-
import {
|
|
3
|
+
import { t as describeDriverMap } from "./driver-map-CkQc52j-.js";
|
|
4
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
5
|
import { dirname, join } from "node:path";
|
|
5
|
-
import { mkdir, readFile, readdir, rm, unlink, writeFile } from "node:fs/promises";
|
|
6
|
+
import { mkdir, readFile, readdir, rename, rm, rmdir, unlink, writeFile } from "node:fs/promises";
|
|
6
7
|
import { existsSync } from "node:fs";
|
|
7
8
|
//#region src/redis/lazy-client.ts
|
|
8
9
|
/**
|
|
@@ -43,8 +44,8 @@ var MemoryStore = class {
|
|
|
43
44
|
isExpired(item) {
|
|
44
45
|
return item.expiresAt !== null && item.expiresAt <= this.now();
|
|
45
46
|
}
|
|
46
|
-
evictIfNeeded() {
|
|
47
|
-
if (this.cache.size >= this.maxSize) {
|
|
47
|
+
evictIfNeeded(key) {
|
|
48
|
+
if (!this.cache.has(key) && this.cache.size >= this.maxSize) {
|
|
48
49
|
const firstKey = this.cache.keys().next().value;
|
|
49
50
|
if (firstKey !== void 0) this.cache.delete(firstKey);
|
|
50
51
|
}
|
|
@@ -59,13 +60,23 @@ var MemoryStore = class {
|
|
|
59
60
|
return item.value;
|
|
60
61
|
}
|
|
61
62
|
async set(key, value, ttl) {
|
|
62
|
-
this.evictIfNeeded();
|
|
63
|
+
this.evictIfNeeded(key);
|
|
63
64
|
const expiresAt = ttl ? this.now() + ttl * 1e3 : null;
|
|
64
65
|
this.cache.set(key, {
|
|
65
66
|
value,
|
|
66
67
|
expiresAt
|
|
67
68
|
});
|
|
68
69
|
}
|
|
70
|
+
async add(key, value) {
|
|
71
|
+
const item = this.cache.get(key);
|
|
72
|
+
if (item && !this.isExpired(item)) return false;
|
|
73
|
+
this.evictIfNeeded(key);
|
|
74
|
+
this.cache.set(key, {
|
|
75
|
+
value,
|
|
76
|
+
expiresAt: null
|
|
77
|
+
});
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
69
80
|
async has(key) {
|
|
70
81
|
const item = this.cache.get(key);
|
|
71
82
|
if (!item) return false;
|
|
@@ -82,10 +93,14 @@ var MemoryStore = class {
|
|
|
82
93
|
this.cache.clear();
|
|
83
94
|
}
|
|
84
95
|
async increment(key, value = 1) {
|
|
85
|
-
const newValue = (await this.get(key) ?? 0) + value;
|
|
86
96
|
const item = this.cache.get(key);
|
|
87
|
-
const
|
|
88
|
-
|
|
97
|
+
const active = item && !this.isExpired(item) ? item : void 0;
|
|
98
|
+
const newValue = (active?.value ?? 0) + value;
|
|
99
|
+
this.evictIfNeeded(key);
|
|
100
|
+
this.cache.set(key, {
|
|
101
|
+
value: newValue,
|
|
102
|
+
expiresAt: active?.expiresAt ?? null
|
|
103
|
+
});
|
|
89
104
|
return newValue;
|
|
90
105
|
}
|
|
91
106
|
async decrement(key, value = 1) {
|
|
@@ -173,6 +188,9 @@ var RedisStore = class {
|
|
|
173
188
|
if (ttl) await this.client.setex(prefixedKey, ttl, serialized);
|
|
174
189
|
else await this.client.set(prefixedKey, serialized);
|
|
175
190
|
}
|
|
191
|
+
async add(key, value) {
|
|
192
|
+
return await this.client.set(this.prefixKey(key), this.serialize(value), "NX") === "OK";
|
|
193
|
+
}
|
|
176
194
|
async has(key) {
|
|
177
195
|
return await this.client.exists(this.prefixKey(key)) > 0;
|
|
178
196
|
}
|
|
@@ -236,7 +254,80 @@ var RedisStore = class {
|
|
|
236
254
|
}
|
|
237
255
|
};
|
|
238
256
|
//#endregion
|
|
257
|
+
//#region src/cache/stores/file-lock.ts
|
|
258
|
+
const POLL_MS = 5;
|
|
259
|
+
function hasCode(error, code) {
|
|
260
|
+
return error.code === code;
|
|
261
|
+
}
|
|
262
|
+
async function entriesOf(lockPath) {
|
|
263
|
+
try {
|
|
264
|
+
return await readdir(lockPath);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (hasCode(error, "ENOENT")) return void 0;
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function ignoreRaced(error) {
|
|
271
|
+
if (![
|
|
272
|
+
"ENOENT",
|
|
273
|
+
"ENOTEMPTY",
|
|
274
|
+
"EEXIST"
|
|
275
|
+
].some((code) => hasCode(error, code))) throw error;
|
|
276
|
+
}
|
|
277
|
+
async function remove(lockPath, names) {
|
|
278
|
+
for (const name of names) await unlink(join(lockPath, name)).catch(ignoreRaced);
|
|
279
|
+
await rmdir(lockPath).catch(ignoreRaced);
|
|
280
|
+
}
|
|
281
|
+
async function tryAcquire(lockPath) {
|
|
282
|
+
try {
|
|
283
|
+
await mkdir(lockPath);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
if (hasCode(error, "EEXIST")) return void 0;
|
|
286
|
+
if (!hasCode(error, "ENOENT")) throw error;
|
|
287
|
+
await mkdir(dirname(lockPath), { recursive: true });
|
|
288
|
+
return tryAcquire(lockPath);
|
|
289
|
+
}
|
|
290
|
+
const token = randomUUID();
|
|
291
|
+
let held = false;
|
|
292
|
+
try {
|
|
293
|
+
await writeFile(join(lockPath, token), "");
|
|
294
|
+
const entries = await readdir(lockPath);
|
|
295
|
+
held = entries.length === 1 && entries[0] === token;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
if (!hasCode(error, "ENOENT")) throw error;
|
|
298
|
+
} finally {
|
|
299
|
+
if (!held) await remove(lockPath, [token]);
|
|
300
|
+
}
|
|
301
|
+
return held ? token : void 0;
|
|
302
|
+
}
|
|
303
|
+
async function withFileLock(lockPath, timeoutMs, callback) {
|
|
304
|
+
let seen;
|
|
305
|
+
let takeOverAt = 0;
|
|
306
|
+
for (;;) {
|
|
307
|
+
const token = await tryAcquire(lockPath);
|
|
308
|
+
if (token !== void 0) try {
|
|
309
|
+
return await callback();
|
|
310
|
+
} finally {
|
|
311
|
+
await remove(lockPath, [token]).catch(() => void 0);
|
|
312
|
+
}
|
|
313
|
+
if (performance.now() >= takeOverAt) {
|
|
314
|
+
const entries = await entriesOf(lockPath);
|
|
315
|
+
if (entries === void 0) continue;
|
|
316
|
+
const current = entries.sort().join("/");
|
|
317
|
+
if (current === seen) {
|
|
318
|
+
await remove(lockPath, entries);
|
|
319
|
+
seen = void 0;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
seen = current;
|
|
323
|
+
takeOverAt = performance.now() + timeoutMs;
|
|
324
|
+
}
|
|
325
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
239
329
|
//#region src/cache/stores/FileStore.ts
|
|
330
|
+
const LOCK_TIMEOUT_MS = 5e3;
|
|
240
331
|
/** File-based cache store. */
|
|
241
332
|
var FileStore = class {
|
|
242
333
|
basePath;
|
|
@@ -266,7 +357,17 @@ var FileStore = class {
|
|
|
266
357
|
}
|
|
267
358
|
async writeCacheFile(filePath, item) {
|
|
268
359
|
await this.ensureDirectory(filePath);
|
|
269
|
-
|
|
360
|
+
const temporary = `${filePath}.${randomUUID()}.tmp`;
|
|
361
|
+
try {
|
|
362
|
+
await writeFile(temporary, JSON.stringify(item), "utf-8");
|
|
363
|
+
await rename(temporary, filePath);
|
|
364
|
+
} catch (error) {
|
|
365
|
+
await unlink(temporary).catch(() => void 0);
|
|
366
|
+
throw error;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
locked(filePath, callback) {
|
|
370
|
+
return withFileLock(`${filePath}.lock`, LOCK_TIMEOUT_MS, callback);
|
|
270
371
|
}
|
|
271
372
|
async deleteCacheFile(filePath) {
|
|
272
373
|
try {
|
|
@@ -297,6 +398,18 @@ var FileStore = class {
|
|
|
297
398
|
expiresAt
|
|
298
399
|
});
|
|
299
400
|
}
|
|
401
|
+
async add(key, value) {
|
|
402
|
+
const filePath = this.getFilePath(key);
|
|
403
|
+
return this.locked(filePath, async () => {
|
|
404
|
+
const item = await this.readCacheFile(filePath);
|
|
405
|
+
if (item && !this.isExpired(item)) return false;
|
|
406
|
+
await this.writeCacheFile(filePath, {
|
|
407
|
+
value,
|
|
408
|
+
expiresAt: null
|
|
409
|
+
});
|
|
410
|
+
return true;
|
|
411
|
+
});
|
|
412
|
+
}
|
|
300
413
|
async has(key) {
|
|
301
414
|
return await this.get(key) !== null;
|
|
302
415
|
}
|
|
@@ -313,12 +426,17 @@ var FileStore = class {
|
|
|
313
426
|
await mkdir(this.basePath, { recursive: true });
|
|
314
427
|
}
|
|
315
428
|
async increment(key, value = 1) {
|
|
316
|
-
const newValue = (await this.get(key) ?? 0) + value;
|
|
317
429
|
const filePath = this.getFilePath(key);
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
430
|
+
return this.locked(filePath, async () => {
|
|
431
|
+
const item = await this.readCacheFile(filePath);
|
|
432
|
+
const active = item && !this.isExpired(item) ? item : null;
|
|
433
|
+
const newValue = (active?.value ?? 0) + value;
|
|
434
|
+
await this.writeCacheFile(filePath, {
|
|
435
|
+
value: newValue,
|
|
436
|
+
expiresAt: active?.expiresAt ?? null
|
|
437
|
+
});
|
|
438
|
+
return newValue;
|
|
439
|
+
});
|
|
322
440
|
}
|
|
323
441
|
async decrement(key, value = 1) {
|
|
324
442
|
return this.increment(key, -value);
|
|
@@ -380,10 +498,7 @@ var FileStore = class {
|
|
|
380
498
|
if (!file.endsWith(this.extension)) continue;
|
|
381
499
|
const filePath = join(subdirPath, file);
|
|
382
500
|
const item = await this.readCacheFile(filePath);
|
|
383
|
-
if (item && this.isExpired(item))
|
|
384
|
-
await this.deleteCacheFile(filePath);
|
|
385
|
-
cleaned++;
|
|
386
|
-
}
|
|
501
|
+
if (item && this.isExpired(item) && await this.deleteCacheFile(filePath)) cleaned++;
|
|
387
502
|
}
|
|
388
503
|
}
|
|
389
504
|
return cleaned;
|
|
@@ -392,6 +507,58 @@ var FileStore = class {
|
|
|
392
507
|
return this.basePath;
|
|
393
508
|
}
|
|
394
509
|
};
|
|
510
|
+
/**
|
|
511
|
+
* One running computation per key and TTL, shared by the callers that ask
|
|
512
|
+
* while it runs. The TTL is part of the match because it is what the
|
|
513
|
+
* computation stores: a caller asking for 60 seconds must not get a forever entry.
|
|
514
|
+
*/
|
|
515
|
+
var PendingComputations = class {
|
|
516
|
+
now;
|
|
517
|
+
pending = /* @__PURE__ */ new Map();
|
|
518
|
+
constructor(now = Date.now) {
|
|
519
|
+
this.now = now;
|
|
520
|
+
}
|
|
521
|
+
run(key, ttl, compute) {
|
|
522
|
+
const now = this.now();
|
|
523
|
+
const current = this.pending.get(key)?.get(ttl);
|
|
524
|
+
return (current && now - current.startedAt < 1e4 ? current : this.start(key, ttl, compute, now)).promise.then();
|
|
525
|
+
}
|
|
526
|
+
start(key, ttl, compute, now) {
|
|
527
|
+
const entry = {
|
|
528
|
+
promise: new Promise((resolve) => resolve(compute())),
|
|
529
|
+
startedAt: now
|
|
530
|
+
};
|
|
531
|
+
let byTtl = this.pending.get(key);
|
|
532
|
+
if (!byTtl) {
|
|
533
|
+
byTtl = /* @__PURE__ */ new Map();
|
|
534
|
+
this.pending.set(key, byTtl);
|
|
535
|
+
}
|
|
536
|
+
byTtl.set(ttl, entry);
|
|
537
|
+
const settle = () => {
|
|
538
|
+
const current = this.pending.get(key);
|
|
539
|
+
if (current?.get(ttl) !== entry) return;
|
|
540
|
+
current.delete(ttl);
|
|
541
|
+
if (current.size === 0) this.pending.delete(key);
|
|
542
|
+
};
|
|
543
|
+
entry.promise.then(settle, settle);
|
|
544
|
+
return entry;
|
|
545
|
+
}
|
|
546
|
+
forget(key) {
|
|
547
|
+
this.pending.delete(key);
|
|
548
|
+
}
|
|
549
|
+
forgetAll() {
|
|
550
|
+
this.pending.clear();
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
const byStore = /* @__PURE__ */ new WeakMap();
|
|
554
|
+
function pendingComputationsFor(store) {
|
|
555
|
+
let computations = byStore.get(store);
|
|
556
|
+
if (!computations) {
|
|
557
|
+
computations = new PendingComputations();
|
|
558
|
+
byStore.set(store, computations);
|
|
559
|
+
}
|
|
560
|
+
return computations;
|
|
561
|
+
}
|
|
395
562
|
//#endregion
|
|
396
563
|
//#region src/cache/TaggedCache.ts
|
|
397
564
|
/** Groups cache items by tags for bulk invalidation. */
|
|
@@ -399,10 +566,12 @@ var TaggedCache = class {
|
|
|
399
566
|
store;
|
|
400
567
|
tags;
|
|
401
568
|
tagSetPrefix;
|
|
569
|
+
pending;
|
|
402
570
|
constructor(store, tags, tagSetPrefix = "tag:") {
|
|
403
571
|
this.store = store;
|
|
404
572
|
this.tags = tags;
|
|
405
573
|
this.tagSetPrefix = tagSetPrefix;
|
|
574
|
+
this.pending = pendingComputationsFor(store);
|
|
406
575
|
}
|
|
407
576
|
async getTagNamespace() {
|
|
408
577
|
const namespaces = [];
|
|
@@ -410,8 +579,14 @@ var TaggedCache = class {
|
|
|
410
579
|
const tagKey = `${this.tagSetPrefix}${tag}`;
|
|
411
580
|
let namespace = await this.store.get(tagKey);
|
|
412
581
|
if (!namespace) {
|
|
413
|
-
|
|
414
|
-
|
|
582
|
+
const proposed = this.generateNamespace();
|
|
583
|
+
if (this.store.add) {
|
|
584
|
+
namespace = await this.store.add(tagKey, proposed) ? proposed : await this.store.get(tagKey);
|
|
585
|
+
if (!namespace) throw new Error("Tag namespace was evicted during initialization; retry the cache operation.");
|
|
586
|
+
} else {
|
|
587
|
+
await this.store.set(tagKey, proposed);
|
|
588
|
+
namespace = proposed;
|
|
589
|
+
}
|
|
415
590
|
}
|
|
416
591
|
namespaces.push(namespace);
|
|
417
592
|
}
|
|
@@ -423,8 +598,7 @@ var TaggedCache = class {
|
|
|
423
598
|
async taggedKey(key) {
|
|
424
599
|
return `tagged:${await this.getTagNamespace()}:${key}`;
|
|
425
600
|
}
|
|
426
|
-
async trackKey(
|
|
427
|
-
const taggedKey = await this.taggedKey(key);
|
|
601
|
+
async trackKey(taggedKey) {
|
|
428
602
|
for (const tag of this.tags) {
|
|
429
603
|
const setKey = `${this.tagSetPrefix}${tag}:keys`;
|
|
430
604
|
const keys = await this.store.get(setKey) ?? [];
|
|
@@ -440,8 +614,9 @@ var TaggedCache = class {
|
|
|
440
614
|
}
|
|
441
615
|
async set(key, value, ttl) {
|
|
442
616
|
const taggedKey = await this.taggedKey(key);
|
|
617
|
+
this.pending.forget(taggedKey);
|
|
443
618
|
await this.store.set(taggedKey, value, ttl);
|
|
444
|
-
await this.trackKey(
|
|
619
|
+
await this.trackKey(taggedKey);
|
|
445
620
|
}
|
|
446
621
|
async has(key) {
|
|
447
622
|
const taggedKey = await this.taggedKey(key);
|
|
@@ -449,6 +624,7 @@ var TaggedCache = class {
|
|
|
449
624
|
}
|
|
450
625
|
async delete(key) {
|
|
451
626
|
const taggedKey = await this.taggedKey(key);
|
|
627
|
+
this.pending.forget(taggedKey);
|
|
452
628
|
return this.store.delete(taggedKey);
|
|
453
629
|
}
|
|
454
630
|
async clear() {
|
|
@@ -456,27 +632,31 @@ var TaggedCache = class {
|
|
|
456
632
|
}
|
|
457
633
|
async increment(key, value = 1) {
|
|
458
634
|
const taggedKey = await this.taggedKey(key);
|
|
459
|
-
await this.trackKey(
|
|
635
|
+
await this.trackKey(taggedKey);
|
|
460
636
|
return this.store.increment(taggedKey, value);
|
|
461
637
|
}
|
|
462
638
|
async decrement(key, value = 1) {
|
|
463
639
|
const taggedKey = await this.taggedKey(key);
|
|
464
|
-
await this.trackKey(
|
|
640
|
+
await this.trackKey(taggedKey);
|
|
465
641
|
return this.store.decrement(taggedKey, value);
|
|
466
642
|
}
|
|
467
643
|
async remember(key, ttl, callback) {
|
|
468
|
-
|
|
469
|
-
if (cached !== null) return cached;
|
|
470
|
-
const value = await callback();
|
|
471
|
-
await this.set(key, value, ttl);
|
|
472
|
-
return value;
|
|
644
|
+
return this.rememberAt(await this.taggedKey(key), ttl, callback);
|
|
473
645
|
}
|
|
474
646
|
async rememberForever(key, callback) {
|
|
475
|
-
|
|
647
|
+
return this.rememberAt(await this.taggedKey(key), void 0, callback);
|
|
648
|
+
}
|
|
649
|
+
async rememberAt(taggedKey, ttl, callback) {
|
|
650
|
+
const cached = await this.store.get(taggedKey);
|
|
476
651
|
if (cached !== null) return cached;
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
652
|
+
return this.pending.run(taggedKey, ttl, async () => {
|
|
653
|
+
const stored = await this.store.get(taggedKey);
|
|
654
|
+
if (stored !== null) return stored;
|
|
655
|
+
const value = await callback();
|
|
656
|
+
await this.store.set(taggedKey, value, ttl);
|
|
657
|
+
await this.trackKey(taggedKey);
|
|
658
|
+
return value;
|
|
659
|
+
});
|
|
480
660
|
}
|
|
481
661
|
async getMany(keys) {
|
|
482
662
|
const result = /* @__PURE__ */ new Map();
|
|
@@ -515,25 +695,36 @@ var TaggedCache = class {
|
|
|
515
695
|
};
|
|
516
696
|
//#endregion
|
|
517
697
|
//#region src/cache/CacheManager.ts
|
|
518
|
-
/**
|
|
698
|
+
/**
|
|
699
|
+
* Adds tag support to any cache store, and shares one `remember` callback
|
|
700
|
+
* between the callers that miss the same key with the same TTL at once. A hit
|
|
701
|
+
* is read on its own, so hits get what `get` returns. A write to a key forgets
|
|
702
|
+
* its running computation, so a later miss does not join one that started
|
|
703
|
+
* before the write.
|
|
704
|
+
*/
|
|
519
705
|
var TaggableCacheStoreWrapper = class {
|
|
520
706
|
store;
|
|
707
|
+
pending;
|
|
521
708
|
constructor(store) {
|
|
522
709
|
this.store = store;
|
|
710
|
+
this.pending = pendingComputationsFor(store);
|
|
523
711
|
}
|
|
524
712
|
get(key) {
|
|
525
713
|
return this.store.get(key);
|
|
526
714
|
}
|
|
527
715
|
set(key, value, ttl) {
|
|
716
|
+
this.pending.forget(key);
|
|
528
717
|
return this.store.set(key, value, ttl);
|
|
529
718
|
}
|
|
530
719
|
has(key) {
|
|
531
720
|
return this.store.has(key);
|
|
532
721
|
}
|
|
533
722
|
delete(key) {
|
|
723
|
+
this.pending.forget(key);
|
|
534
724
|
return this.store.delete(key);
|
|
535
725
|
}
|
|
536
726
|
clear() {
|
|
727
|
+
this.pending.forgetAll();
|
|
537
728
|
return this.store.clear();
|
|
538
729
|
}
|
|
539
730
|
increment(key, value) {
|
|
@@ -543,18 +734,25 @@ var TaggableCacheStoreWrapper = class {
|
|
|
543
734
|
return this.store.decrement(key, value);
|
|
544
735
|
}
|
|
545
736
|
remember(key, ttl, callback) {
|
|
546
|
-
return this.store.remember(key, ttl, callback);
|
|
737
|
+
return this.rememberOnMiss(key, ttl, () => this.store.remember(key, ttl, callback));
|
|
547
738
|
}
|
|
548
739
|
rememberForever(key, callback) {
|
|
549
|
-
return this.store.rememberForever(key, callback);
|
|
740
|
+
return this.rememberOnMiss(key, void 0, () => this.store.rememberForever(key, callback));
|
|
741
|
+
}
|
|
742
|
+
async rememberOnMiss(key, ttl, remember) {
|
|
743
|
+
const cached = await this.store.get(key);
|
|
744
|
+
if (cached !== null) return cached;
|
|
745
|
+
return this.pending.run(key, ttl, remember);
|
|
550
746
|
}
|
|
551
747
|
getMany(keys) {
|
|
552
748
|
return this.store.getMany(keys);
|
|
553
749
|
}
|
|
554
750
|
setMany(items, ttl) {
|
|
751
|
+
for (const key of items.keys()) this.pending.forget(key);
|
|
555
752
|
return this.store.setMany(items, ttl);
|
|
556
753
|
}
|
|
557
754
|
deleteMany(keys) {
|
|
755
|
+
for (const key of keys) this.pending.forget(key);
|
|
558
756
|
return this.store.deleteMany(keys);
|
|
559
757
|
}
|
|
560
758
|
ttl(key) {
|
|
@@ -569,6 +767,8 @@ var CacheManager = class {
|
|
|
569
767
|
defaultStoreName;
|
|
570
768
|
storeFactories = /* @__PURE__ */ new Map();
|
|
571
769
|
resolvedStores = /* @__PURE__ */ new Map();
|
|
770
|
+
/** The configured driver per store, keyed like `storeFactories`; null for a bare `registerStore()` factory. */
|
|
771
|
+
storeDrivers = /* @__PURE__ */ new Map();
|
|
572
772
|
/**
|
|
573
773
|
* Where this manager was built, for identifying its stores across hot reloads.
|
|
574
774
|
* Captured here rather than in `store()` because stores resolve lazily, from
|
|
@@ -581,7 +781,10 @@ var CacheManager = class {
|
|
|
581
781
|
this.defaultStoreName = config.default ?? "memory";
|
|
582
782
|
this.registerBuiltinDrivers();
|
|
583
783
|
if (config.stores) for (const [name, storeConfig] of Object.entries(config.stores)) this.registerStoreFromConfig(name, storeConfig);
|
|
584
|
-
if (!this.storeFactories.has(this.defaultStoreName) && this.defaultStoreName === "memory")
|
|
784
|
+
if (!this.storeFactories.has(this.defaultStoreName) && this.defaultStoreName === "memory") {
|
|
785
|
+
this.storeFactories.set("memory", () => new MemoryStore());
|
|
786
|
+
this.storeDrivers.set("memory", "memory");
|
|
787
|
+
}
|
|
585
788
|
}
|
|
586
789
|
driverFactories = /* @__PURE__ */ new Map();
|
|
587
790
|
registerBuiltinDrivers() {
|
|
@@ -600,6 +803,7 @@ var CacheManager = class {
|
|
|
600
803
|
const factory = this.driverFactories.get(driver);
|
|
601
804
|
if (!factory) throw new Error(`Unknown cache driver: ${driver}`);
|
|
602
805
|
this.storeFactories.set(name, () => factory(options));
|
|
806
|
+
this.storeDrivers.set(name, driver);
|
|
603
807
|
}
|
|
604
808
|
/** Returns the default store if no name is given. */
|
|
605
809
|
store(name) {
|
|
@@ -626,6 +830,7 @@ var CacheManager = class {
|
|
|
626
830
|
}
|
|
627
831
|
registerStore(name, factory) {
|
|
628
832
|
this.storeFactories.set(name, factory);
|
|
833
|
+
this.storeDrivers.set(name, null);
|
|
629
834
|
this.resolvedStores.delete(name);
|
|
630
835
|
}
|
|
631
836
|
registerDriver(name, factory) {
|
|
@@ -640,6 +845,10 @@ var CacheManager = class {
|
|
|
640
845
|
getStoreNames() {
|
|
641
846
|
return Array.from(this.storeFactories.keys());
|
|
642
847
|
}
|
|
848
|
+
/** The declared stores and the default, building none of them (RFC 0026 §1). */
|
|
849
|
+
describe() {
|
|
850
|
+
return describeDriverMap(this.defaultStoreName, this.storeDrivers);
|
|
851
|
+
}
|
|
643
852
|
};
|
|
644
853
|
function createCacheManager(config) {
|
|
645
854
|
return new CacheManager(config);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { basename, dirname, join, sep } from "node:path";
|
|
2
|
+
import { realpath } from "node:fs/promises";
|
|
3
|
+
//#region src/support/trim-slashes.ts
|
|
4
|
+
/**
|
|
5
|
+
* No regex: patterns like `/\/+$/` backtrack quadratically on long slash runs
|
|
6
|
+
* mid-string, and several call sites feed request-derived paths.
|
|
7
|
+
*
|
|
8
|
+
* Twins that cannot import this module: `@guren/cli` (`src/utils.ts`) and
|
|
9
|
+
* `@guren/plugin-cloudflare` (`src/storage/R2Driver.ts`) — keep them in step.
|
|
10
|
+
*/
|
|
11
|
+
function trimTrailingSlashes(value) {
|
|
12
|
+
let end = value.length;
|
|
13
|
+
while (end > 0 && value[end - 1] === "/") end--;
|
|
14
|
+
return value.slice(0, end);
|
|
15
|
+
}
|
|
16
|
+
function trimSlashes(value) {
|
|
17
|
+
let start = 0;
|
|
18
|
+
let end = value.length;
|
|
19
|
+
while (start < end && value[start] === "/") start++;
|
|
20
|
+
while (end > start && value[end - 1] === "/") end--;
|
|
21
|
+
return value.slice(start, end);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/support/contained-path.ts
|
|
25
|
+
/**
|
|
26
|
+
* Lexical containment. The trailing separator keeps out a sibling whose name
|
|
27
|
+
* merely extends the root's (`…/inertia` vs `…/inertia-secrets`) and rejects an
|
|
28
|
+
* absolute `candidate`, which `resolve()` returns verbatim. Not sufficient
|
|
29
|
+
* alone: `resolve()` collapses `..` without following symlinks, so use
|
|
30
|
+
* {@link isRealPathWithin} before reading the file.
|
|
31
|
+
*/
|
|
32
|
+
function isPathWithin(root, candidate) {
|
|
33
|
+
return candidate.startsWith(root.endsWith(sep) ? root : root + sep);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Containment once both sides are canonicalized. Every reader downstream
|
|
37
|
+
* (`Bun.file().text()`, `new Response(file)`) follows symlinks, so a lexical
|
|
38
|
+
* check alone accepts `<root>/link/secret`. *Both* sides, because a root
|
|
39
|
+
* reached through a symlink is routine (macOS `/var` → `/private/var`) and
|
|
40
|
+
* doing only the candidate would 404 every asset such an app serves.
|
|
41
|
+
*/
|
|
42
|
+
async function isRealPathWithin(root, candidate) {
|
|
43
|
+
if (!isPathWithin(root, candidate)) return false;
|
|
44
|
+
const [realRoot, realCandidate] = await Promise.all([canonicalize(root), canonicalize(candidate)]);
|
|
45
|
+
if (!realRoot || !realCandidate) return false;
|
|
46
|
+
return isPathWithin(realRoot, realCandidate);
|
|
47
|
+
}
|
|
48
|
+
async function canonicalize(path) {
|
|
49
|
+
try {
|
|
50
|
+
return await realpath(path);
|
|
51
|
+
} catch {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The canonical form of a path that need not exist: the deepest ancestor that
|
|
57
|
+
* resolves is canonicalized and the missing tail rejoined, so a caller can
|
|
58
|
+
* judge where a write would land. `undefined` when the path cannot be resolved
|
|
59
|
+
* at all — a link cycle, a directory that will not open — which a containment
|
|
60
|
+
* check must treat as out of bounds rather than as inside.
|
|
61
|
+
*/
|
|
62
|
+
async function realPathOfNearestExisting(path) {
|
|
63
|
+
const missing = [];
|
|
64
|
+
let current = path;
|
|
65
|
+
while (true) {
|
|
66
|
+
try {
|
|
67
|
+
return join(await realpath(current), ...missing);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error.code !== "ENOENT") return void 0;
|
|
70
|
+
}
|
|
71
|
+
const parent = dirname(current);
|
|
72
|
+
if (parent === current) return void 0;
|
|
73
|
+
missing.unshift(basename(current));
|
|
74
|
+
current = parent;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { trimTrailingSlashes as a, trimSlashes as i, isRealPathWithin as n, realPathOfNearestExisting as r, isPathWithin as t };
|
|
@@ -10,7 +10,7 @@ export declare class Container {
|
|
|
10
10
|
protected tags: Map<string, Set<string>>;
|
|
11
11
|
protected contextualBindings: ContextualBinding[];
|
|
12
12
|
protected resolvingStack: string[];
|
|
13
|
-
|
|
13
|
+
private scope?;
|
|
14
14
|
protected fakes: Map<string, unknown>;
|
|
15
15
|
/**
|
|
16
16
|
* @internal Installed by ProviderManager once every eager provider has booted.
|
|
@@ -47,7 +47,11 @@ export declare class Container {
|
|
|
47
47
|
tag(keys: string[], tagName: string): this;
|
|
48
48
|
tagged<T = unknown>(tagName: string): T[];
|
|
49
49
|
when(concrete: string): ContextualBindingBuilder;
|
|
50
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Services resolved inside the callback are cached for the scope. The cache lives
|
|
52
|
+
* as long as the async context: work detached inside the scope (a timer, an
|
|
53
|
+
* un-awaited promise) keeps it and every cached instance reachable.
|
|
54
|
+
*/
|
|
51
55
|
scoped<T>(callback: () => T): T;
|
|
52
56
|
scopedAsync<T>(callback: () => Promise<T>): Promise<T>;
|
|
53
57
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Container } from './Container.js';
|
|
2
2
|
import type { Provider } from './types.js';
|
|
3
|
+
import type { ManifestWarning, ProviderEntry, ProviderSource } from '../introspection/types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Constructor shape accepted wherever a provider class can be registered.
|
|
5
6
|
*/
|
|
@@ -20,6 +21,12 @@ export declare abstract class ServiceProvider implements Provider {
|
|
|
20
21
|
abstract register(): void | Promise<void>;
|
|
21
22
|
/** Runs after all providers have registered. */
|
|
22
23
|
boot?(): void | Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Runs in place of `register()` under introspection (RFC 0026 §2). Bind only
|
|
26
|
+
* what the manifest describes; leave anything that connects or reads a runtime
|
|
27
|
+
* binding to `register()`. Absent, introspection runs `register()` unchanged.
|
|
28
|
+
*/
|
|
29
|
+
introspect?(): void | Promise<void>;
|
|
23
30
|
provides(): string[];
|
|
24
31
|
isDeferred(): boolean;
|
|
25
32
|
}
|
|
@@ -28,6 +35,11 @@ export interface OwnedBinding {
|
|
|
28
35
|
readonly binding: unknown;
|
|
29
36
|
readonly source: string;
|
|
30
37
|
}
|
|
38
|
+
/** @internal Where a provider came from, for the manifest's `providers[].source`. */
|
|
39
|
+
export interface ProviderOrigin {
|
|
40
|
+
readonly source: ProviderSource;
|
|
41
|
+
readonly module?: string;
|
|
42
|
+
}
|
|
31
43
|
/**
|
|
32
44
|
* Provider manager for registering and booting providers.
|
|
33
45
|
*/
|
|
@@ -41,10 +53,23 @@ export declare class ProviderManager {
|
|
|
41
53
|
private deferredActivations;
|
|
42
54
|
private bindingOwners;
|
|
43
55
|
private allBooted;
|
|
56
|
+
/** Every provider in registration order, deferred ones included, with where it came from. */
|
|
57
|
+
private readonly origins;
|
|
44
58
|
constructor(container: Container);
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
/** `origin` is internal: `Application` passes it for the manifest (RFC 0026). */
|
|
60
|
+
register(providerOrClass: ServiceProvider | ServiceProviderConstructor, origin?: ProviderOrigin): this;
|
|
61
|
+
/** `origin` is internal, as on {@link register}. */
|
|
62
|
+
registerMany(providers: Array<ServiceProvider | ServiceProviderConstructor>, origin?: ProviderOrigin): this;
|
|
47
63
|
registerAll(): Promise<void>;
|
|
64
|
+
private registerOne;
|
|
65
|
+
/**
|
|
66
|
+
* @internal `registerAll()` for introspection (RFC 0026 §2): `introspect()` where a
|
|
67
|
+
* provider has one, and a throw is recorded rather than stopping the rest.
|
|
68
|
+
* Deferred providers are reported `skipped`; they register only after boot.
|
|
69
|
+
*/
|
|
70
|
+
registerAllForIntrospection(): Promise<ProviderEntry[]>;
|
|
71
|
+
/** @internal Findings registered providers hold for the manifest, each named after its provider. */
|
|
72
|
+
manifestWarnings(): ManifestWarning[];
|
|
48
73
|
private assertOwnedBindingsKept;
|
|
49
74
|
bootAll(): Promise<void>;
|
|
50
75
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ConfigDefinition } from '../config/define.js';
|
|
1
2
|
import type { CommandClass } from '../console/types.js';
|
|
2
3
|
import type { Router } from '../mvc/Router.js';
|
|
3
4
|
import type { ServiceProviderConstructor } from './ServiceProvider.js';
|
|
@@ -26,6 +27,13 @@ export interface ModuleDefinition {
|
|
|
26
27
|
* explicit registration keeps a bundled deployment resolving the same set.
|
|
27
28
|
*/
|
|
28
29
|
commands?: CommandClass[];
|
|
30
|
+
/**
|
|
31
|
+
* Config definitions the module owns (`modules/<name>/config/<key>.ts`),
|
|
32
|
+
* bound after `createApp({ config })` in `modules` order. Keys share the
|
|
33
|
+
* application's one container, so a key the app or another module also
|
|
34
|
+
* defines fails the boot, naming both.
|
|
35
|
+
*/
|
|
36
|
+
config?: ReadonlyArray<ConfigDefinition>;
|
|
29
37
|
}
|
|
30
38
|
/**
|
|
31
39
|
* A module as `Application` consumes it: `providers` and `commands` normalized
|
|
@@ -37,14 +45,15 @@ export interface GurenModule {
|
|
|
37
45
|
routes?: (router: Router) => void | Promise<void>;
|
|
38
46
|
providers: ServiceProviderConstructor[];
|
|
39
47
|
commands: CommandClass[];
|
|
48
|
+
/** Optional, unlike `providers`, so a module literal built without `defineModule()` stays valid. */
|
|
49
|
+
config?: ReadonlyArray<ConfigDefinition>;
|
|
40
50
|
}
|
|
41
51
|
/** Define a Guren application module without boilerplate. */
|
|
42
52
|
export declare function defineModule(definition: ModuleDefinition): GurenModule;
|
|
43
53
|
/**
|
|
44
|
-
* Runs a module's route registrar
|
|
45
|
-
* Shared by `Application.mountRoutes()` and the CLI's route loader, so both see
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* inside an async prefixed registrar run with the prefix already popped.
|
|
54
|
+
* Runs a module's route registrar under its `prefix` and names the module on each route it added.
|
|
55
|
+
* Shared by `Application.mountRoutes()` and the CLI's route loader, so both see the same route set.
|
|
56
|
+
* `router.group()`'s callback is synchronous, so route calls made after an `await` inside an
|
|
57
|
+
* async prefixed registrar run with the prefix already popped (and still carry the module).
|
|
49
58
|
*/
|
|
50
59
|
export declare function mountModuleRoutes(router: Router, gurenModule: GurenModule): Promise<void>;
|