@guren/server 2.11.0 → 2.12.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/{McpServiceProvider-BoAN-UcD.js → McpServiceProvider-D6D9nhgn.js} +1 -1
- package/dist/encryption/index.js +1 -1
- package/dist/{encryption-fOWQaKqX.js → encryption-DJtkkhiw.js} +35 -15
- package/dist/{errors-quJOkkCn.js → errors-BgeOl_DC.js} +1 -1
- package/dist/http/vite-assets.d.ts +50 -0
- package/dist/http/vite-manifest.d.ts +80 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +154 -9
- package/dist/jsx-dev-runtime.d.ts +6 -0
- package/dist/jsx-dev-runtime.js +2 -0
- package/dist/jsx-runtime.d.ts +12 -0
- package/dist/jsx-runtime.js +8 -0
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +23 -0
- package/dist/mvc/view.d.ts +15 -0
- package/dist/rolldown-runtime-B4FMCO8f.js +28 -0
- package/dist/runtime/index.js +13 -51
- package/dist/storage/drivers/LocalDriver.d.ts +2 -1
- package/dist/storage/drivers/S3Driver.d.ts +17 -2
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/storage/types.d.ts +61 -1
- package/dist/{storage-tWHMv2H_.js → storage-TLD9t0Q2.js} +101 -24
- package/dist/vite-manifest-BKuV1kfv.js +251 -0
- package/package.json +10 -2
- package/dist/rolldown-runtime-8H4AJuhK.js +0 -14
- package/dist/vite-dev-server-BSJkduhZ.js +0 -131
package/dist/runtime/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { n as trimTrailingSlashes } from "../trim-slashes-ZJ_VsY5s.js";
|
|
2
2
|
import { n as hash } from "../Hash-CzrwKeDp.js";
|
|
3
|
-
import { a as
|
|
3
|
+
import { _ as parseImportMap, 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-BKuV1kfv.js";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { realpath } from "node:fs/promises";
|
|
6
6
|
import { dirname, extname, join, resolve, sep } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
-
import { readFileSync } from "node:fs";
|
|
9
8
|
import { serveStatic } from "hono/bun";
|
|
10
9
|
//#region src/support/contained-path.ts
|
|
11
10
|
/**
|
|
@@ -414,8 +413,9 @@ function autoConfigureInertiaAssets(app, options) {
|
|
|
414
413
|
process.env[key] = value;
|
|
415
414
|
};
|
|
416
415
|
if (!moduleDir) return;
|
|
417
|
-
if (!(
|
|
418
|
-
|
|
416
|
+
if (!isViteProduction()) {
|
|
417
|
+
const devServerUrl = options.devServerUrl ?? process.env.VITE_DEV_SERVER_URL ?? "http://localhost:5173";
|
|
418
|
+
setEnvIfUserDidNotProvide("GUREN_INERTIA_ENTRY", `${normalizeDevServerUrl(devServerUrl)}/resources/js/dev-entry.ts`);
|
|
419
419
|
setEnvIfUserDidNotProvide("GUREN_INERTIA_STYLES", options.stylesEntry ?? "/resources/css/app.css");
|
|
420
420
|
importMapEntries["@guren/inertia-client"] = DEFAULT_VENDOR_CLIENT_PATH;
|
|
421
421
|
if (ssrEnabled) {
|
|
@@ -429,13 +429,13 @@ function autoConfigureInertiaAssets(app, options) {
|
|
|
429
429
|
process.env.GUREN_INERTIA_IMPORT_MAP = JSON.stringify(importMapEntries);
|
|
430
430
|
return;
|
|
431
431
|
}
|
|
432
|
-
const clientManifest = loadViteManifest(
|
|
432
|
+
const clientManifest = loadViteManifest(clientManifestCandidates(resolve(moduleDir, "..")), "client", { includeRaw: true });
|
|
433
433
|
const clientEntry = clientManifest?.["resources/js/app.tsx"];
|
|
434
434
|
const clientEntryFile = getManifestFile(clientEntry);
|
|
435
435
|
const clientCssFiles = getManifestCss(clientEntry);
|
|
436
436
|
if (clientManifest?.__raw__) setEnvIfUserDidNotProvide("GUREN_INERTIA_VERSION", hash(clientManifest.__raw__, "sha1").slice(0, 12));
|
|
437
|
-
if (clientEntryFile) setEnvIfUserDidNotProvide("GUREN_INERTIA_ENTRY",
|
|
438
|
-
if (clientCssFiles?.length) setEnvIfUserDidNotProvide("GUREN_INERTIA_STYLES", clientCssFiles.map((href) =>
|
|
437
|
+
if (clientEntryFile) setEnvIfUserDidNotProvide("GUREN_INERTIA_ENTRY", `${PUBLIC_ASSETS_URL_PREFIX}${clientEntryFile.replace(/^\//u, "")}`);
|
|
438
|
+
if (clientCssFiles?.length) setEnvIfUserDidNotProvide("GUREN_INERTIA_STYLES", clientCssFiles.map((href) => `${PUBLIC_ASSETS_URL_PREFIX}${href.replace(/^\//u, "")}`).join(","));
|
|
439
439
|
importMapEntries["@guren/inertia-client"] = DEFAULT_VENDOR_CLIENT_PATH;
|
|
440
440
|
if (!ssrEnabled) {
|
|
441
441
|
if (Object.keys(importMapEntries).length > 0) process.env.GUREN_INERTIA_IMPORT_MAP = JSON.stringify(importMapEntries);
|
|
@@ -443,19 +443,20 @@ function autoConfigureInertiaAssets(app, options) {
|
|
|
443
443
|
setEnvIfUserDidNotProvide("GUREN_INERTIA_SSR_MANIFEST", "");
|
|
444
444
|
return;
|
|
445
445
|
}
|
|
446
|
-
const
|
|
446
|
+
const ssrManifestPaths = [
|
|
447
447
|
options.ssrManifest,
|
|
448
|
-
resolve(moduleDir, `../${ssrOutDir}/manifest.json`),
|
|
449
448
|
resolve(moduleDir, `../${ssrOutDir}/.vite/manifest.json`),
|
|
449
|
+
resolve(moduleDir, `../${ssrOutDir}/manifest.json`),
|
|
450
450
|
resolve(moduleDir, `../${ssrOutDir}/ssr-manifest.json`),
|
|
451
|
-
resolve(moduleDir, "../build/ssr/manifest.json"),
|
|
452
451
|
resolve(moduleDir, "../build/ssr/.vite/manifest.json"),
|
|
452
|
+
resolve(moduleDir, "../build/ssr/manifest.json"),
|
|
453
453
|
resolve(moduleDir, "../build/ssr/ssr-manifest.json"),
|
|
454
|
-
resolve(moduleDir, "../public/assets/.ssr/manifest.json"),
|
|
455
454
|
resolve(moduleDir, "../public/assets/.ssr/.vite/manifest.json"),
|
|
455
|
+
resolve(moduleDir, "../public/assets/.ssr/manifest.json"),
|
|
456
456
|
resolve(moduleDir, "../public/assets/.ssr/ssr-manifest.json"),
|
|
457
457
|
resolve(moduleDir, "../public/assets/.vite/ssr-manifest.json")
|
|
458
|
-
].filter((value) => Boolean(value))
|
|
458
|
+
].filter((value) => Boolean(value));
|
|
459
|
+
const ssrManifest = loadViteManifest(ssrManifestPaths, "SSR");
|
|
459
460
|
const ssrEntry = ssrManifest?.["resources/js/ssr.tsx"];
|
|
460
461
|
const ssrEntryFile = getManifestFile(ssrEntry);
|
|
461
462
|
const ssrEntryRoot = deriveAssetRoot(ssrManifest, resolve(moduleDir, `../${ssrOutDir}`));
|
|
@@ -481,49 +482,10 @@ function resolveDevSsrEntry(options) {
|
|
|
481
482
|
const resourcesDir = resolve(moduleDir, resourcesPath);
|
|
482
483
|
return resolve(resourcesDir, "js/ssr.tsx");
|
|
483
484
|
}
|
|
484
|
-
function normalizeDevServerUrl(value) {
|
|
485
|
-
if (!value) return value;
|
|
486
|
-
const trimmed = value.trim();
|
|
487
|
-
if (!trimmed) return trimmed;
|
|
488
|
-
const stripped = trimTrailingSlashes(trimmed);
|
|
489
|
-
return stripped.length > 0 ? stripped : "/";
|
|
490
|
-
}
|
|
491
|
-
function loadViteManifest(candidatePaths, label) {
|
|
492
|
-
const command = label === "SSR" ? "bunx vite build --ssr" : "bunx vite build";
|
|
493
|
-
for (const manifestPath of candidatePaths) try {
|
|
494
|
-
const raw = readFileSync(manifestPath, "utf8");
|
|
495
|
-
const manifest = JSON.parse(raw);
|
|
496
|
-
Object.defineProperty(manifest, "__path__", {
|
|
497
|
-
value: manifestPath,
|
|
498
|
-
enumerable: false
|
|
499
|
-
});
|
|
500
|
-
Object.defineProperty(manifest, "__raw__", {
|
|
501
|
-
value: raw,
|
|
502
|
-
enumerable: false
|
|
503
|
-
});
|
|
504
|
-
return manifest;
|
|
505
|
-
} catch (error) {
|
|
506
|
-
if (error.code !== "ENOENT") {
|
|
507
|
-
console.warn(`Unable to load ${label} Vite manifest at ${manifestPath}.`, error);
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
if (candidatePaths.length) console.warn(`Unable to load ${label} Vite manifest. Checked paths:\n${candidatePaths.map((p) => ` - ${p}`).join("\n")}\nRun \`${command}\` before starting in production.`);
|
|
512
|
-
}
|
|
513
485
|
function deriveAssetRoot(manifest, fallback) {
|
|
514
486
|
if (!manifest?.__path__) return fallback;
|
|
515
487
|
return resolve(dirname(manifest.__path__), "..");
|
|
516
488
|
}
|
|
517
|
-
function getManifestFile(entry) {
|
|
518
|
-
if (!entry) return;
|
|
519
|
-
if (Array.isArray(entry)) return entry[0];
|
|
520
|
-
if (typeof entry === "string") return entry;
|
|
521
|
-
if ("file" in entry && typeof entry.file === "string") return entry.file;
|
|
522
|
-
}
|
|
523
|
-
function getManifestCss(entry) {
|
|
524
|
-
if (!entry || Array.isArray(entry) || typeof entry === "string") return;
|
|
525
|
-
return entry.css;
|
|
526
|
-
}
|
|
527
489
|
function resolveResourcesDir(options, moduleDir) {
|
|
528
490
|
if (options.resourcesDir) return options.resourcesDir;
|
|
529
491
|
if (!moduleDir) return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StorageDriver, LocalDriverOptions, PutOptions, FileMetadata } from '../types.js';
|
|
1
|
+
import type { StorageDriver, LocalDriverOptions, PutOptions, FileMetadata, GetStreamOptions } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Local filesystem storage driver.
|
|
4
4
|
*
|
|
@@ -31,6 +31,7 @@ export declare class LocalDriver implements StorageDriver {
|
|
|
31
31
|
putFile(path: string, localPath: string, options?: PutOptions): Promise<string>;
|
|
32
32
|
get(path: string): Promise<Buffer | null>;
|
|
33
33
|
getAsString(path: string): Promise<string | null>;
|
|
34
|
+
getStream(path: string, options?: GetStreamOptions): Promise<ReadableStream<Uint8Array> | null>;
|
|
34
35
|
exists(path: string): Promise<boolean>;
|
|
35
36
|
delete(path: string): Promise<boolean>;
|
|
36
37
|
deleteMany(paths: string[]): Promise<number>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StorageDriver, S3DriverOptions, PutOptions, FileMetadata } from '../types.js';
|
|
1
|
+
import type { StorageDriver, S3DriverOptions, PutOptions, FileMetadata, GetStreamOptions, TemporaryUrlOptions, StorageDriverCapabilities } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* AWS S3 storage driver.
|
|
4
4
|
*
|
|
@@ -18,6 +18,7 @@ import type { StorageDriver, S3DriverOptions, PutOptions, FileMetadata } from '.
|
|
|
18
18
|
*/
|
|
19
19
|
export declare class S3Driver implements StorageDriver {
|
|
20
20
|
private readonly options;
|
|
21
|
+
readonly capabilities: StorageDriverCapabilities;
|
|
21
22
|
private client;
|
|
22
23
|
private readonly bucket;
|
|
23
24
|
private readonly region;
|
|
@@ -41,18 +42,32 @@ export declare class S3Driver implements StorageDriver {
|
|
|
41
42
|
putFile(path: string, localPath: string, options?: PutOptions): Promise<string>;
|
|
42
43
|
get(path: string): Promise<Buffer | null>;
|
|
43
44
|
getAsString(path: string): Promise<string | null>;
|
|
45
|
+
getStream(path: string, options?: GetStreamOptions): Promise<ReadableStream<Uint8Array> | null>;
|
|
44
46
|
exists(path: string): Promise<boolean>;
|
|
45
47
|
delete(path: string): Promise<boolean>;
|
|
46
48
|
deleteMany(paths: string[]): Promise<number>;
|
|
47
49
|
copy(from: string, to: string): Promise<string>;
|
|
48
50
|
move(from: string, to: string): Promise<string>;
|
|
49
51
|
url(path: string): string;
|
|
50
|
-
temporaryUrl(path: string, expiration: Date): Promise<string>;
|
|
52
|
+
temporaryUrl(path: string, expiration: Date, options?: TemporaryUrlOptions): Promise<string>;
|
|
51
53
|
size(path: string): Promise<number>;
|
|
52
54
|
lastModified(path: string): Promise<Date>;
|
|
53
55
|
metadata(path: string): Promise<FileMetadata | null>;
|
|
54
56
|
/** `metadata()`, but honouring the contract's not-found error. */
|
|
55
57
|
private metadataOrFail;
|
|
58
|
+
/**
|
|
59
|
+
* Run ListObjectsV2 to exhaustion, following `NextContinuationToken` —
|
|
60
|
+
* a single request returns at most 1000 entries, so a one-page read
|
|
61
|
+
* silently truncates larger listings.
|
|
62
|
+
*/
|
|
63
|
+
private listAll;
|
|
64
|
+
/**
|
|
65
|
+
* The ListObjectsV2 `Prefix` for a directory: the prefixed key with exactly
|
|
66
|
+
* one trailing slash, or empty for the bucket (or disk prefix) root —
|
|
67
|
+
* naively appending `/` to `prefixKey('')` on a prefixed disk yields
|
|
68
|
+
* `prefix//`, which matches nothing.
|
|
69
|
+
*/
|
|
70
|
+
private listingPrefix;
|
|
56
71
|
files(directory: string): Promise<string[]>;
|
|
57
72
|
directories(directory: string): Promise<string[]>;
|
|
58
73
|
allFiles(directory: string): Promise<string[]>;
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { StorageDriver, StorageDriverFactory, StorageConfig, DiskConfig, PutOptions, FileMetadata, LocalDriverOptions, S3DriverOptions, MemoryDriverOptions, DriverConfig, } from './types.js';
|
|
1
|
+
export type { StorageDriver, StorageDriverFactory, StorageConfig, DiskConfig, PutOptions, FileMetadata, LocalDriverOptions, S3DriverOptions, MemoryDriverOptions, DriverConfig, TemporaryUrlOptions, GetStreamOptions, StorageDriverCapabilities, } from './types.js';
|
|
2
2
|
export { LocalDriver } from './drivers/LocalDriver.js';
|
|
3
3
|
export { S3Driver } from './drivers/S3Driver.js';
|
|
4
4
|
export { MemoryDriver } from './drivers/MemoryDriver.js';
|
package/dist/storage/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as LocalDriver, i as S3Driver, n as createStorageManager, r as MemoryDriver, t as StorageManager } from "../storage-
|
|
1
|
+
import { a as LocalDriver, i as S3Driver, n as createStorageManager, r as MemoryDriver, t as StorageManager } from "../storage-TLD9t0Q2.js";
|
|
2
2
|
export { LocalDriver, MemoryDriver, S3Driver, StorageManager, createStorageManager };
|
package/dist/storage/types.d.ts
CHANGED
|
@@ -44,10 +44,53 @@ export interface FileMetadata {
|
|
|
44
44
|
*/
|
|
45
45
|
metadata?: Record<string, string>;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Response-override options for temporary (presigned) URLs — RFC 0015 §3.
|
|
49
|
+
*
|
|
50
|
+
* Drivers that presign map these onto the backend's `response-*` overrides
|
|
51
|
+
* (S3: `ResponseContentDisposition` / `ResponseContentType` on the presigned
|
|
52
|
+
* `GetObjectCommand`) so Content-Disposition and Content-Type policy
|
|
53
|
+
* survives a redirect to the bucket. A driver that cannot honour them
|
|
54
|
+
* ignores them and serves its own object metadata — a caller that needs the
|
|
55
|
+
* guarantee must proxy the bytes instead.
|
|
56
|
+
*/
|
|
57
|
+
export interface TemporaryUrlOptions {
|
|
58
|
+
responseContentDisposition?: string;
|
|
59
|
+
responseContentType?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Streaming-read options. `range` is byte-inclusive (`start`..`end`, `end`
|
|
63
|
+
* omitted = to end of file), matching HTTP Range semantics.
|
|
64
|
+
*/
|
|
65
|
+
export interface GetStreamOptions {
|
|
66
|
+
range?: {
|
|
67
|
+
start: number;
|
|
68
|
+
end?: number;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Capabilities a driver positively declares — RFC 0015 §3. Absent means
|
|
73
|
+
* none: a capability not declared is treated as unavailable (fail-closed),
|
|
74
|
+
* never probed. Probing cannot work here: `LocalDriver.temporaryUrl()`
|
|
75
|
+
* succeeds and returns a plain public URL, so a try/catch probe would
|
|
76
|
+
* misclassify exactly the disk that must not redirect.
|
|
77
|
+
*/
|
|
78
|
+
export interface StorageDriverCapabilities {
|
|
79
|
+
/**
|
|
80
|
+
* `temporaryUrl()` returns a URL whose bearer-signature the backend
|
|
81
|
+
* itself enforces (S3-style presign) — not merely a URL. `LocalDriver`
|
|
82
|
+
* must NOT declare this: its `temporaryUrl()` is the plain public URL.
|
|
83
|
+
*/
|
|
84
|
+
presignedGet?: boolean;
|
|
85
|
+
}
|
|
47
86
|
/**
|
|
48
87
|
* Storage driver interface.
|
|
49
88
|
*/
|
|
50
89
|
export interface StorageDriver {
|
|
90
|
+
/**
|
|
91
|
+
* Capabilities the delivery layer may rely on. Absent ⇒ none declared.
|
|
92
|
+
*/
|
|
93
|
+
readonly capabilities?: StorageDriverCapabilities;
|
|
51
94
|
/**
|
|
52
95
|
* Put a file into storage.
|
|
53
96
|
* @param path File path
|
|
@@ -116,8 +159,25 @@ export interface StorageDriver {
|
|
|
116
159
|
* Get a temporary (signed) URL for a file.
|
|
117
160
|
* @param path File path
|
|
118
161
|
* @param expiration Expiration date
|
|
162
|
+
* @param options Response overrides for presigning drivers (ignored by
|
|
163
|
+
* drivers that cannot honour them — see TemporaryUrlOptions)
|
|
164
|
+
*/
|
|
165
|
+
temporaryUrl(path: string, expiration: Date, options?: TemporaryUrlOptions): Promise<string>;
|
|
166
|
+
/**
|
|
167
|
+
* Read a file as a stream. Optional — callers fall back to buffered
|
|
168
|
+
* `get()` where absent.
|
|
169
|
+
*
|
|
170
|
+
* Contract: resolves `null` for a missing file, verified *before* the
|
|
171
|
+
* stream is returned (a stream whose open fails after return cannot
|
|
172
|
+
* honour that), and the result is normalized to the global web
|
|
173
|
+
* `ReadableStream` at the driver's own boundary (`Readable.toWeb`,
|
|
174
|
+
* `Body.transformToWebStream()`, or a cast where the runtime's stream
|
|
175
|
+
* type is structurally compatible).
|
|
176
|
+
*
|
|
177
|
+
* @param path File path
|
|
178
|
+
* @param options Optional byte range
|
|
119
179
|
*/
|
|
120
|
-
|
|
180
|
+
getStream?(path: string, options?: GetStreamOptions): Promise<ReadableStream<Uint8Array> | null>;
|
|
121
181
|
/**
|
|
122
182
|
* Get the file size in bytes.
|
|
123
183
|
* @param path File path
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { t as trimSlashes } from "./trim-slashes-ZJ_VsY5s.js";
|
|
2
|
-
import { copyFile, mkdir, readFile, readdir, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { copyFile, mkdir, open, readFile, readdir, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
3
3
|
import { dirname, join, resolve, sep } from "node:path";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
|
+
import { Readable } from "node:stream";
|
|
5
6
|
//#region src/support/warn-once.ts
|
|
6
7
|
const warned = /* @__PURE__ */ new Set();
|
|
7
8
|
/**
|
|
@@ -83,6 +84,24 @@ var LocalDriver = class {
|
|
|
83
84
|
const content = await this.get(path);
|
|
84
85
|
return content ? content.toString("utf-8") : null;
|
|
85
86
|
}
|
|
87
|
+
async getStream(path, options) {
|
|
88
|
+
const fullPath = this.fullPath(path);
|
|
89
|
+
let handle;
|
|
90
|
+
try {
|
|
91
|
+
handle = await open(fullPath, "r");
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
if (!(await handle.stat()).isFile()) {
|
|
96
|
+
await handle.close();
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const nodeStream = handle.createReadStream(options?.range ? {
|
|
100
|
+
start: options.range.start,
|
|
101
|
+
end: options.range.end
|
|
102
|
+
} : void 0);
|
|
103
|
+
return Readable.toWeb(nodeStream);
|
|
104
|
+
}
|
|
86
105
|
async exists(path) {
|
|
87
106
|
return existsSync(this.fullPath(path));
|
|
88
107
|
}
|
|
@@ -247,6 +266,7 @@ function assertVisibilitySupported(acl, diskVisibility, requested, operation) {
|
|
|
247
266
|
*/
|
|
248
267
|
var S3Driver = class {
|
|
249
268
|
options;
|
|
269
|
+
capabilities = { presignedGet: true };
|
|
250
270
|
client = null;
|
|
251
271
|
bucket;
|
|
252
272
|
region;
|
|
@@ -337,6 +357,22 @@ var S3Driver = class {
|
|
|
337
357
|
const content = await this.get(path);
|
|
338
358
|
return content ? content.toString("utf-8") : null;
|
|
339
359
|
}
|
|
360
|
+
async getStream(path, options) {
|
|
361
|
+
const client = await this.getClient();
|
|
362
|
+
const { GetObjectCommand } = await importAwsModule("@aws-sdk/client-s3");
|
|
363
|
+
try {
|
|
364
|
+
const command = new GetObjectCommand({
|
|
365
|
+
Bucket: this.bucket,
|
|
366
|
+
Key: this.prefixKey(path),
|
|
367
|
+
...options?.range ? { Range: `bytes=${options.range.start}-${options.range.end ?? ""}` } : {}
|
|
368
|
+
});
|
|
369
|
+
const response = await client.send(command);
|
|
370
|
+
return response.Body ? response.Body.transformToWebStream() : null;
|
|
371
|
+
} catch (error) {
|
|
372
|
+
if (error && typeof error === "object" && "name" in error && error.name === "NoSuchKey") return null;
|
|
373
|
+
throw error;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
340
376
|
async exists(path) {
|
|
341
377
|
const client = await this.getClient();
|
|
342
378
|
const { HeadObjectCommand } = await importAwsModule("@aws-sdk/client-s3");
|
|
@@ -370,11 +406,16 @@ var S3Driver = class {
|
|
|
370
406
|
if (paths.length === 0) return 0;
|
|
371
407
|
const client = await this.getClient();
|
|
372
408
|
const { DeleteObjectsCommand } = await importAwsModule("@aws-sdk/client-s3");
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
409
|
+
let deleted = 0;
|
|
410
|
+
for (let index = 0; index < paths.length; index += 1e3) {
|
|
411
|
+
const command = new DeleteObjectsCommand({
|
|
412
|
+
Bucket: this.bucket,
|
|
413
|
+
Delete: { Objects: paths.slice(index, index + 1e3).map((path) => ({ Key: this.prefixKey(path) })) }
|
|
414
|
+
});
|
|
415
|
+
const response = await client.send(command);
|
|
416
|
+
deleted += response.Deleted?.length ?? 0;
|
|
417
|
+
}
|
|
418
|
+
return deleted;
|
|
378
419
|
}
|
|
379
420
|
async copy(from, to) {
|
|
380
421
|
const client = await this.getClient();
|
|
@@ -395,13 +436,15 @@ var S3Driver = class {
|
|
|
395
436
|
url(path) {
|
|
396
437
|
return `${this.baseUrl}/${this.prefixKey(path)}`;
|
|
397
438
|
}
|
|
398
|
-
async temporaryUrl(path, expiration) {
|
|
439
|
+
async temporaryUrl(path, expiration, options) {
|
|
399
440
|
const client = await this.getClient();
|
|
400
441
|
const { GetObjectCommand } = await importAwsModule("@aws-sdk/client-s3");
|
|
401
442
|
const { getSignedUrl } = await importAwsModule("@aws-sdk/s3-request-presigner");
|
|
402
443
|
return getSignedUrl(client, new GetObjectCommand({
|
|
403
444
|
Bucket: this.bucket,
|
|
404
|
-
Key: this.prefixKey(path)
|
|
445
|
+
Key: this.prefixKey(path),
|
|
446
|
+
...options?.responseContentDisposition ? { ResponseContentDisposition: options.responseContentDisposition } : {},
|
|
447
|
+
...options?.responseContentType ? { ResponseContentType: options.responseContentType } : {}
|
|
405
448
|
}), { expiresIn: Math.max(1, Math.floor((expiration.getTime() - Date.now()) / 1e3)) });
|
|
406
449
|
}
|
|
407
450
|
async size(path) {
|
|
@@ -441,37 +484,71 @@ var S3Driver = class {
|
|
|
441
484
|
if (!metadata) throw new Error(`File not found: ${path}`);
|
|
442
485
|
return metadata;
|
|
443
486
|
}
|
|
444
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Run ListObjectsV2 to exhaustion, following `NextContinuationToken` —
|
|
489
|
+
* a single request returns at most 1000 entries, so a one-page read
|
|
490
|
+
* silently truncates larger listings.
|
|
491
|
+
*/
|
|
492
|
+
async listAll(input) {
|
|
445
493
|
const client = await this.getClient();
|
|
446
494
|
const { ListObjectsV2Command } = await importAwsModule("@aws-sdk/client-s3");
|
|
495
|
+
const contents = [];
|
|
496
|
+
const commonPrefixes = [];
|
|
497
|
+
let continuationToken;
|
|
498
|
+
do {
|
|
499
|
+
const command = new ListObjectsV2Command(continuationToken ? {
|
|
500
|
+
...input,
|
|
501
|
+
ContinuationToken: continuationToken
|
|
502
|
+
} : input);
|
|
503
|
+
const response = await client.send(command);
|
|
504
|
+
contents.push(...response.Contents ?? []);
|
|
505
|
+
commonPrefixes.push(...response.CommonPrefixes ?? []);
|
|
506
|
+
if (response.IsTruncated) {
|
|
507
|
+
const next = response.NextContinuationToken;
|
|
508
|
+
if (!next || next === continuationToken) throw new Error("S3 listing reported IsTruncated without an advancing NextContinuationToken; refusing to return an incomplete listing.");
|
|
509
|
+
continuationToken = next;
|
|
510
|
+
} else continuationToken = void 0;
|
|
511
|
+
} while (continuationToken);
|
|
512
|
+
return {
|
|
513
|
+
contents,
|
|
514
|
+
commonPrefixes
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* The ListObjectsV2 `Prefix` for a directory: the prefixed key with exactly
|
|
519
|
+
* one trailing slash, or empty for the bucket (or disk prefix) root —
|
|
520
|
+
* naively appending `/` to `prefixKey('')` on a prefixed disk yields
|
|
521
|
+
* `prefix//`, which matches nothing.
|
|
522
|
+
*/
|
|
523
|
+
listingPrefix(directory) {
|
|
447
524
|
const prefix = this.prefixKey(directory);
|
|
448
|
-
|
|
525
|
+
let end = prefix.length;
|
|
526
|
+
while (end > 0 && prefix.charCodeAt(end - 1) === 47) end--;
|
|
527
|
+
const trimmed = prefix.slice(0, end);
|
|
528
|
+
return trimmed ? `${trimmed}/` : "";
|
|
529
|
+
}
|
|
530
|
+
async files(directory) {
|
|
531
|
+
const { contents } = await this.listAll({
|
|
449
532
|
Bucket: this.bucket,
|
|
450
|
-
Prefix:
|
|
533
|
+
Prefix: this.listingPrefix(directory),
|
|
451
534
|
Delimiter: "/"
|
|
452
535
|
});
|
|
453
|
-
return
|
|
536
|
+
return contents.map((item) => item.Key?.replace(this.prefix ? `${this.prefix}/` : "", "") ?? "").filter((key) => key && !key.endsWith("/"));
|
|
454
537
|
}
|
|
455
538
|
async directories(directory) {
|
|
456
|
-
const
|
|
457
|
-
const { ListObjectsV2Command } = await importAwsModule("@aws-sdk/client-s3");
|
|
458
|
-
const prefix = this.prefixKey(directory);
|
|
459
|
-
const command = new ListObjectsV2Command({
|
|
539
|
+
const { commonPrefixes } = await this.listAll({
|
|
460
540
|
Bucket: this.bucket,
|
|
461
|
-
Prefix:
|
|
541
|
+
Prefix: this.listingPrefix(directory),
|
|
462
542
|
Delimiter: "/"
|
|
463
543
|
});
|
|
464
|
-
return
|
|
544
|
+
return commonPrefixes.map((item) => item.Prefix?.replace(this.prefix ? `${this.prefix}/` : "", "").replace(/\/$/, "") ?? "").filter(Boolean);
|
|
465
545
|
}
|
|
466
546
|
async allFiles(directory) {
|
|
467
|
-
const
|
|
468
|
-
const { ListObjectsV2Command } = await importAwsModule("@aws-sdk/client-s3");
|
|
469
|
-
const prefix = this.prefixKey(directory);
|
|
470
|
-
const command = new ListObjectsV2Command({
|
|
547
|
+
const { contents } = await this.listAll({
|
|
471
548
|
Bucket: this.bucket,
|
|
472
|
-
Prefix:
|
|
549
|
+
Prefix: this.listingPrefix(directory)
|
|
473
550
|
});
|
|
474
|
-
return
|
|
551
|
+
return contents.map((item) => item.Key?.replace(this.prefix ? `${this.prefix}/` : "", "") ?? "").filter((key) => key && !key.endsWith("/"));
|
|
475
552
|
}
|
|
476
553
|
async makeDirectory(path) {
|
|
477
554
|
await this.put(`${path}/.keep`, "");
|