@foldrun/core 17.3.0 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/approvals.js +3 -3
- package/dist/src/blob-cache.d.ts +58 -0
- package/dist/src/blob-cache.js +312 -0
- package/dist/src/blob-pins.d.ts +44 -0
- package/dist/src/blob-pins.js +61 -0
- package/dist/src/blob-store.d.ts +47 -0
- package/dist/src/blob-store.js +362 -0
- package/dist/src/blob-sweeper.d.ts +70 -0
- package/dist/src/blob-sweeper.js +282 -0
- package/dist/src/blob-types.d.ts +145 -0
- package/dist/src/blob-types.js +115 -0
- package/dist/src/evals.js +1 -1
- package/dist/src/history.d.ts +92 -9
- package/dist/src/history.js +168 -20
- package/dist/src/journal-store.d.ts +58 -0
- package/dist/src/journal-store.js +117 -0
- package/dist/src/manifest.d.ts +92 -0
- package/dist/src/manifest.js +239 -0
- package/dist/src/ops-log.js +26 -3
- package/dist/src/platform.d.ts +7 -0
- package/dist/src/platform.js +1 -0
- package/dist/src/publish.d.ts +134 -0
- package/dist/src/publish.js +434 -0
- package/dist/src/records.d.ts +72 -0
- package/dist/src/records.js +24 -0
- package/dist/src/revision-store.d.ts +161 -0
- package/dist/src/revision-store.js +378 -0
- package/dist/src/run-container.d.ts +20 -0
- package/dist/src/run-container.js +61 -0
- package/dist/src/runner.js +1 -1
- package/dist/src/s3-blob-store.d.ts +29 -0
- package/dist/src/s3-blob-store.js +531 -0
- package/dist/src/state-retention.d.ts +15 -0
- package/dist/src/state-retention.js +65 -0
- package/dist/src/storage.d.ts +29 -1
- package/dist/src/storage.js +331 -81
- package/dist/src/store.d.ts +41 -0
- package/dist/src/store.js +188 -5
- package/dist/src/trigger-log.js +17 -0
- package/dist/src/workspace-revisions.d.ts +269 -0
- package/dist/src/workspace-revisions.js +1382 -0
- package/package.json +1 -1
- package/src/approvals.ts +3 -3
- package/src/blob-cache.ts +357 -0
- package/src/blob-pins.ts +99 -0
- package/src/blob-store.ts +389 -0
- package/src/blob-sweeper.ts +336 -0
- package/src/blob-types.ts +216 -0
- package/src/evals.ts +1 -1
- package/src/history.ts +226 -19
- package/src/journal-store.ts +152 -0
- package/src/manifest.ts +274 -0
- package/src/ops-log.ts +25 -3
- package/src/platform.ts +8 -0
- package/src/publish.ts +520 -0
- package/src/records.ts +105 -0
- package/src/revision-store.ts +513 -0
- package/src/run-container.ts +62 -0
- package/src/runner.ts +1 -1
- package/src/s3-blob-store.ts +560 -0
- package/src/state-retention.ts +83 -0
- package/src/storage.ts +335 -81
- package/src/store.ts +178 -5
- package/src/trigger-log.ts +15 -0
- package/src/workspace-revisions.ts +1423 -0
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
// The s3 BlobStore driver (FOL-126): any S3-compatible endpoint (AWS, R2,
|
|
2
|
+
// MinIO), signed by the code in storage.ts — no SDK.
|
|
3
|
+
//
|
|
4
|
+
// What it does beyond "PUT/GET with a signature", each point learnt by running
|
|
5
|
+
// it against a real server (MinIO) instead of the in-process fake:
|
|
6
|
+
//
|
|
7
|
+
// * A conditional put is `If-None-Match: *`. 412 = "already there" and the
|
|
8
|
+
// reply carries the existing object's ETag, which is returned so a caller
|
|
9
|
+
// can tell "my bytes are there" from "something else is".
|
|
10
|
+
// * 409 (ConditionalRequestConflict: another put of the same key is still in
|
|
11
|
+
// flight) is transient: the retry then sees 412.
|
|
12
|
+
// * An error is read for its S3 `<Code>`, not just its status: RequestTimeout
|
|
13
|
+
// and BadDigest come back as 400 and ARE worth retrying; NoSuchBucket,
|
|
14
|
+
// AccessDenied, SignatureDoesNotMatch are final and say so by name.
|
|
15
|
+
// * A HEAD cannot tell a missing bucket from a missing key (both 404, no
|
|
16
|
+
// body). `checkBucket()` asks the bucket itself; run it at start-up.
|
|
17
|
+
// * An upload streams from a re-readable source (no Buffer of the whole
|
|
18
|
+
// object), signed with its real payload hash so the server verifies it.
|
|
19
|
+
// * Past a threshold the upload is multipart. Nothing is kept on the local
|
|
20
|
+
// side to resume it: the next call lists the in-flight uploads for the key
|
|
21
|
+
// and the parts already there, hashes the local parts, and uploads only
|
|
22
|
+
// the ones that differ. An upload that is cancelled or fails for a final
|
|
23
|
+
// reason is aborted; one that fails for a transient reason is left to be
|
|
24
|
+
// resumed (and swept by abortStaleUploads / a bucket lifecycle rule if no
|
|
25
|
+
// one comes back).
|
|
26
|
+
import crypto from "node:crypto";
|
|
27
|
+
import { s3Request, forgetS3Credentials } from "./storage.js";
|
|
28
|
+
import { BlobNotFound, BlobSourceError, BlobStoreError, BlobTransientError, assertKey, bufferSource, hashRange, } from "./blob-types.js";
|
|
29
|
+
const MiB = 1024 * 1024;
|
|
30
|
+
/** S3's floor for every part but the last. R2 and MinIO enforce the same. */
|
|
31
|
+
export const MIN_PART_BYTES = 5 * MiB;
|
|
32
|
+
/** S3's ceiling on the number of parts. */
|
|
33
|
+
export const MAX_PARTS = 10_000;
|
|
34
|
+
const MAX_TIMER_MS = 2 ** 31 - 1;
|
|
35
|
+
export const DEFAULT_S3_OPTIONS = {
|
|
36
|
+
multipartThresholdBytes: 64 * MiB,
|
|
37
|
+
partBytes: 16 * MiB,
|
|
38
|
+
partConcurrency: 4,
|
|
39
|
+
requestDeadlineMs: 30_000,
|
|
40
|
+
minBytesPerSec: 1 * MiB,
|
|
41
|
+
};
|
|
42
|
+
export function s3OptionsFromEnv(env = process.env) {
|
|
43
|
+
const n = (v, d) => (v !== undefined && /^\d+$/.test(v) && Number(v) > 0 ? Number(v) : d);
|
|
44
|
+
const d = DEFAULT_S3_OPTIONS;
|
|
45
|
+
return {
|
|
46
|
+
multipartThresholdBytes: n(env.FOLDRUN_BLOB_MULTIPART_THRESHOLD_MB, d.multipartThresholdBytes / MiB) * MiB,
|
|
47
|
+
partBytes: Math.max(MIN_PART_BYTES, n(env.FOLDRUN_BLOB_PART_MB, d.partBytes / MiB) * MiB),
|
|
48
|
+
partConcurrency: n(env.FOLDRUN_BLOB_PART_CONCURRENCY, d.partConcurrency),
|
|
49
|
+
requestDeadlineMs: n(env.FOLDRUN_BLOB_DEADLINE_MS, d.requestDeadlineMs),
|
|
50
|
+
minBytesPerSec: d.minBytesPerSec,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** The part size for an object: the configured one, raised until the object
|
|
54
|
+
* fits in MAX_PARTS parts. Every part but the last is exactly this size —
|
|
55
|
+
* R2 requires uniform parts, S3 and MinIO do not mind. */
|
|
56
|
+
export function planPartBytes(size, configured) {
|
|
57
|
+
let p = Math.max(MIN_PART_BYTES, configured);
|
|
58
|
+
if (Math.ceil(size / p) > MAX_PARTS)
|
|
59
|
+
p = Math.ceil(size / MAX_PARTS / MiB) * MiB;
|
|
60
|
+
return p;
|
|
61
|
+
}
|
|
62
|
+
// Codes that arrive with a non-5xx status but are worth another try.
|
|
63
|
+
const TRANSIENT_CODES = new Set([
|
|
64
|
+
"RequestTimeout",
|
|
65
|
+
"SlowDown",
|
|
66
|
+
"InternalError",
|
|
67
|
+
"ServiceUnavailable",
|
|
68
|
+
"BadDigest", // the body changed in flight
|
|
69
|
+
"XAmzContentSHA256Mismatch", // the same, seen by MinIO
|
|
70
|
+
"ConditionalRequestConflict",
|
|
71
|
+
"OperationAborted",
|
|
72
|
+
"ExpiredToken", // role credentials; the cache is dropped before the retry
|
|
73
|
+
]);
|
|
74
|
+
const transientStatus = (s) => s >= 500 || s === 429 || s === 408 || s === 409;
|
|
75
|
+
const codeOf = (xml) => /<Code>([^<]+)<\/Code>/.exec(xml)?.[1];
|
|
76
|
+
// MinIO writes a quote as `"`, AWS as `"`; both must read back as `"`
|
|
77
|
+
// (a part's ETag is handed back to the store verbatim to complete the upload).
|
|
78
|
+
const unxml = (s) => s
|
|
79
|
+
.replace(/&#(\d+);/g, (_, n) => String.fromCodePoint(Number(n)))
|
|
80
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, n) => String.fromCodePoint(parseInt(n, 16)))
|
|
81
|
+
.replace(/</g, "<")
|
|
82
|
+
.replace(/>/g, ">")
|
|
83
|
+
.replace(/"/g, '"')
|
|
84
|
+
.replace(/'/g, "'")
|
|
85
|
+
.replace(/&/g, "&");
|
|
86
|
+
const unquote = (etag) => (etag ? etag.replace(/^W\//, "").replace(/^"|"$/g, "") : undefined);
|
|
87
|
+
const isTimeout = (signal) => signal?.aborted === true && signal.reason?.name === "TimeoutError";
|
|
88
|
+
export function s3BlobStore(cfg, given = {}) {
|
|
89
|
+
if (!cfg)
|
|
90
|
+
throw new Error("the s3 blob store needs FOLDRUN_S3_ENDPOINT, FOLDRUN_S3_BUCKET and credentials");
|
|
91
|
+
const o = { ...s3OptionsFromEnv(), ...given };
|
|
92
|
+
// Clamped to the longest timer Node keeps: past 2^31-1 ms it fires after
|
|
93
|
+
// 1 ms instead, which would cut off the complete of a multi-TiB object.
|
|
94
|
+
const requestDeadline = (bytes) => Math.min(MAX_TIMER_MS, o.requestDeadlineMs + Math.ceil((bytes / o.minBytesPerSec) * 1000));
|
|
95
|
+
/** One signed request with the failures of the network turned into
|
|
96
|
+
* BlobTransientError, so the retry wrapper above knows what to retry.
|
|
97
|
+
*
|
|
98
|
+
* Every request carries this driver's own deadline (its floor plus its body
|
|
99
|
+
* at minBytesPerSec) on top of the caller's signal. bounded() leaves a
|
|
100
|
+
* streamed put to the driver, so without it a server that accepts the
|
|
101
|
+
* connection and never answers would hold the single PUT, or a multipart
|
|
102
|
+
* HEAD, list, create or complete, for as long as the caller's signal lets
|
|
103
|
+
* it — forever when there is none. `sizedBy` overrides the bytes the
|
|
104
|
+
* deadline is sized by (a complete, whose small body stands for a whole
|
|
105
|
+
* object the store has to assemble). A GET passes `false`: its signal also
|
|
106
|
+
* bounds reading the body, which is the caller's to bound. */
|
|
107
|
+
const send = async (what, method, key, body, extra = {}, signal, query, mime, sizedBy) => {
|
|
108
|
+
const ms = requestDeadline(sizedBy === undefined || sizedBy === false ? (body?.length ?? 0) : sizedBy);
|
|
109
|
+
const bound = sizedBy === false ? signal : signal ? AbortSignal.any([signal, AbortSignal.timeout(ms)]) : AbortSignal.timeout(ms);
|
|
110
|
+
try {
|
|
111
|
+
return await s3Request(cfg, method, key, body, mime, extra, bound, query ? { query } : {});
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
// A source that fails while it is being sent surfaces from fetch as
|
|
115
|
+
// "fetch failed" with the real error as its cause. It is not the
|
|
116
|
+
// network's fault and a retry would read the same bytes.
|
|
117
|
+
for (let e = err, i = 0; e && i < 4; e = e.cause, i++)
|
|
118
|
+
if (e instanceof BlobSourceError)
|
|
119
|
+
throw e;
|
|
120
|
+
if (signal?.aborted && !isTimeout(signal))
|
|
121
|
+
throw err; // the caller cancelled
|
|
122
|
+
if (bound?.aborted && isTimeout(bound))
|
|
123
|
+
throw new BlobTransientError(`s3 ${what}: no answer within ${ms}ms`);
|
|
124
|
+
const name = err?.name;
|
|
125
|
+
if (name === "AbortError" || name === "TimeoutError")
|
|
126
|
+
throw new BlobTransientError(`s3 ${what}: timed out`);
|
|
127
|
+
const cause = err.cause;
|
|
128
|
+
throw new BlobTransientError(`s3 ${what}: ${cause?.code ?? cause?.message ?? err?.message ?? err}`);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
/** Read an error reply: transient or final, with the store's code in the message. */
|
|
132
|
+
const failure = async (res, what) => {
|
|
133
|
+
const text = (await res.text().catch(() => "")).slice(0, 400);
|
|
134
|
+
const code = codeOf(text);
|
|
135
|
+
const msg = `s3 ${what} failed: ${res.status}${code ? ` ${code}` : ""} ${unxml(/<Message>([^<]*)<\/Message>/.exec(text)?.[1] ?? "").slice(0, 160)}`.trim();
|
|
136
|
+
if (code === "ExpiredToken")
|
|
137
|
+
forgetS3Credentials();
|
|
138
|
+
if (transientStatus(res.status) || (code && TRANSIENT_CODES.has(code)))
|
|
139
|
+
return new BlobTransientError(msg, res.status, code);
|
|
140
|
+
return new BlobStoreError(msg, res.status, code);
|
|
141
|
+
};
|
|
142
|
+
const drain = (res) => res.arrayBuffer().catch(() => { });
|
|
143
|
+
/** A reply's body. The request's deadline still runs while it is read, and
|
|
144
|
+
* a deadline or a dropped connection here is as transient as one before
|
|
145
|
+
* the headers came. */
|
|
146
|
+
const textOf = async (res, what) => {
|
|
147
|
+
try {
|
|
148
|
+
return await res.text();
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
if (err?.name === "TimeoutError")
|
|
152
|
+
throw new BlobTransientError(`s3 ${what}: timed out reading the reply`);
|
|
153
|
+
if (err instanceof TypeError)
|
|
154
|
+
throw new BlobTransientError(`s3 ${what}: the reply was cut off (${err.cause?.code ?? err.message})`);
|
|
155
|
+
throw err;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const headObject = async (key, signal) => {
|
|
159
|
+
const res = await send("head", "HEAD", key, undefined, {}, signal);
|
|
160
|
+
if (res.status === 404) {
|
|
161
|
+
await drain(res);
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
if (!res.ok)
|
|
165
|
+
throw await failure(res, "head");
|
|
166
|
+
await drain(res);
|
|
167
|
+
const size = Number(res.headers.get("content-length"));
|
|
168
|
+
const lm = res.headers.get("last-modified");
|
|
169
|
+
const etag = unquote(res.headers.get("etag"));
|
|
170
|
+
return { size: Number.isSafeInteger(size) && size >= 0 ? size : 0, ...(lm ? { modifiedAt: new Date(lm) } : {}), ...(etag ? { etag } : {}) };
|
|
171
|
+
};
|
|
172
|
+
// ---------- single request ----------
|
|
173
|
+
const putOnce = async (key, body, mime, signal) => {
|
|
174
|
+
const res = await send("put", "PUT", key, body, { "if-none-match": "*" }, signal, undefined, mime);
|
|
175
|
+
if (res.status === 412) {
|
|
176
|
+
await drain(res);
|
|
177
|
+
return { created: false, ...(unquote(res.headers.get("etag")) ? { etag: unquote(res.headers.get("etag")) } : {}) };
|
|
178
|
+
}
|
|
179
|
+
if (!res.ok)
|
|
180
|
+
throw await failure(res, "put");
|
|
181
|
+
await drain(res);
|
|
182
|
+
return { created: true, ...(unquote(res.headers.get("etag")) ? { etag: unquote(res.headers.get("etag")) } : {}) };
|
|
183
|
+
};
|
|
184
|
+
/** The upload to continue, if one is open for this exact key. */
|
|
185
|
+
const findUpload = async (key, signal) => {
|
|
186
|
+
let keyMarker = "";
|
|
187
|
+
let uploadMarker = "";
|
|
188
|
+
for (let page = 0; page < 20; page++) {
|
|
189
|
+
const q = { uploads: "", prefix: key, "max-uploads": "1000" };
|
|
190
|
+
if (keyMarker)
|
|
191
|
+
q["key-marker"] = keyMarker;
|
|
192
|
+
if (uploadMarker)
|
|
193
|
+
q["upload-id-marker"] = uploadMarker;
|
|
194
|
+
const res = await send("list uploads", "GET", "", undefined, {}, signal, q);
|
|
195
|
+
if (!res.ok)
|
|
196
|
+
throw await failure(res, "list uploads");
|
|
197
|
+
const xml = await textOf(res, "list uploads");
|
|
198
|
+
// The oldest open upload for the key: the one most likely to have parts.
|
|
199
|
+
const mine = [...xml.matchAll(/<Upload>([\s\S]*?)<\/Upload>/g)]
|
|
200
|
+
.map((m) => ({ key: unxml(/<Key>([^<]*)<\/Key>/.exec(m[1])?.[1] ?? ""), id: unxml(/<UploadId>([^<]*)<\/UploadId>/.exec(m[1])?.[1] ?? ""), at: Date.parse(/<Initiated>([^<]*)<\/Initiated>/.exec(m[1])?.[1] ?? "") || 0 }))
|
|
201
|
+
.filter((u) => u.key === key && u.id)
|
|
202
|
+
.sort((a, b) => a.at - b.at);
|
|
203
|
+
if (mine.length)
|
|
204
|
+
return mine[0].id;
|
|
205
|
+
if (!/<IsTruncated>true<\/IsTruncated>/.test(xml))
|
|
206
|
+
return null;
|
|
207
|
+
keyMarker = unxml(/<NextKeyMarker>([^<]*)<\/NextKeyMarker>/.exec(xml)?.[1] ?? "");
|
|
208
|
+
uploadMarker = unxml(/<NextUploadIdMarker>([^<]*)<\/NextUploadIdMarker>/.exec(xml)?.[1] ?? "");
|
|
209
|
+
if (!keyMarker && !uploadMarker)
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
};
|
|
214
|
+
const listParts = async (key, uploadId, signal) => {
|
|
215
|
+
const parts = new Map();
|
|
216
|
+
let marker = "";
|
|
217
|
+
for (;;) {
|
|
218
|
+
const q = { uploadId, "max-parts": "1000" };
|
|
219
|
+
if (marker)
|
|
220
|
+
q["part-number-marker"] = marker;
|
|
221
|
+
const res = await send("list parts", "GET", key, undefined, {}, signal, q);
|
|
222
|
+
if (res.status === 404) {
|
|
223
|
+
await drain(res);
|
|
224
|
+
return null; // NoSuchUpload: it was completed or aborted under us
|
|
225
|
+
}
|
|
226
|
+
if (!res.ok)
|
|
227
|
+
throw await failure(res, "list parts");
|
|
228
|
+
const xml = await textOf(res, "list parts");
|
|
229
|
+
for (const m of xml.matchAll(/<Part>([\s\S]*?)<\/Part>/g)) {
|
|
230
|
+
const n = Number(/<PartNumber>(\d+)<\/PartNumber>/.exec(m[1])?.[1]);
|
|
231
|
+
const size = Number(/<Size>(\d+)<\/Size>/.exec(m[1])?.[1]);
|
|
232
|
+
const etag = unxml(/<ETag>([^<]*)<\/ETag>/.exec(m[1])?.[1] ?? "");
|
|
233
|
+
if (n && etag)
|
|
234
|
+
parts.set(n, { etag, size });
|
|
235
|
+
}
|
|
236
|
+
if (!/<IsTruncated>true<\/IsTruncated>/.test(xml))
|
|
237
|
+
return parts;
|
|
238
|
+
marker = /<NextPartNumberMarker>(\d+)<\/NextPartNumberMarker>/.exec(xml)?.[1] ?? "";
|
|
239
|
+
if (!marker)
|
|
240
|
+
return parts;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
const abortUpload = async (key, uploadId) => {
|
|
244
|
+
// A fresh signal: the one that got us here is probably already aborted.
|
|
245
|
+
const res = await send("abort upload", "DELETE", key, undefined, {}, AbortSignal.timeout(10_000), { uploadId }).catch(() => null);
|
|
246
|
+
if (res)
|
|
247
|
+
await drain(res);
|
|
248
|
+
};
|
|
249
|
+
async function multipartPut(key, source, opts) {
|
|
250
|
+
const { signal } = opts;
|
|
251
|
+
// Already there: nothing to upload, and nothing to leave half-open.
|
|
252
|
+
const there = await headObject(key, signal);
|
|
253
|
+
if (there)
|
|
254
|
+
return { created: false, ...(there.etag ? { etag: there.etag } : {}) };
|
|
255
|
+
const partBytes = planPartBytes(source.size, o.partBytes);
|
|
256
|
+
const count = Math.ceil(source.size / partBytes);
|
|
257
|
+
const range = (n) => [(n - 1) * partBytes, Math.min(n * partBytes, source.size)];
|
|
258
|
+
let uploadId = await findUpload(key, signal);
|
|
259
|
+
let have = uploadId ? await listParts(key, uploadId, signal) : null;
|
|
260
|
+
if (!uploadId || !have) {
|
|
261
|
+
const res = await send("create upload", "POST", key, undefined, {}, signal, { uploads: "" }, opts.contentType);
|
|
262
|
+
if (!res.ok)
|
|
263
|
+
throw await failure(res, "create upload");
|
|
264
|
+
uploadId = unxml(/<UploadId>([^<]*)<\/UploadId>/.exec(await textOf(res, "create upload"))?.[1] ?? "");
|
|
265
|
+
if (!uploadId)
|
|
266
|
+
throw new BlobTransientError("s3 create upload: no upload id in the reply");
|
|
267
|
+
have = new Map();
|
|
268
|
+
}
|
|
269
|
+
const id = uploadId;
|
|
270
|
+
const done = new Map(); // part number → ETag to complete with
|
|
271
|
+
const inner = new AbortController();
|
|
272
|
+
// The error that stopped the upload, not whichever worker's rejection
|
|
273
|
+
// happens to sit first in the pool: the siblings it aborts reject with an
|
|
274
|
+
// AbortError, which would hide a transient or final cause.
|
|
275
|
+
let firstError = null;
|
|
276
|
+
const both = signal ? AbortSignal.any([signal, inner.signal]) : inner.signal;
|
|
277
|
+
// Each part is checked against the bytes read for it (the sha256 signed
|
|
278
|
+
// into its PUT, or the md5 a part already in the store must match), but
|
|
279
|
+
// that alone says nothing about the object: a file that changed after the
|
|
280
|
+
// caller hashed it would go up whole and consistent under the OLD content
|
|
281
|
+
// address. So the same reads also feed one sha256 of the whole object,
|
|
282
|
+
// compared with opts.sha256 before the upload is completed. A sha256
|
|
283
|
+
// cannot be put together from the parts' own, so the reads have to reach
|
|
284
|
+
// it in order: each part's hash pass waits for the one before it.
|
|
285
|
+
// Workers take part numbers in order, so chaining their passes keeps it,
|
|
286
|
+
// and the uploads still overlap. A part reused from an earlier attempt is
|
|
287
|
+
// read and hashed like the others, so a resumed upload is covered too.
|
|
288
|
+
const whole = opts.sha256 ? crypto.createHash("sha256") : null;
|
|
289
|
+
let hashed = Promise.resolve();
|
|
290
|
+
const hashPart = (start, end) => {
|
|
291
|
+
const pass = hashed.then(async () => {
|
|
292
|
+
const sha = crypto.createHash("sha256");
|
|
293
|
+
const md5 = crypto.createHash("md5");
|
|
294
|
+
for await (const chunk of source.read(start, end, both)) {
|
|
295
|
+
sha.update(chunk);
|
|
296
|
+
md5.update(chunk);
|
|
297
|
+
whole?.update(chunk);
|
|
298
|
+
}
|
|
299
|
+
return { sha256: sha.digest("hex"), md5: md5.digest("hex") };
|
|
300
|
+
});
|
|
301
|
+
hashed = pass; // a failed pass fails the ones after it: the upload is over anyway
|
|
302
|
+
return pass;
|
|
303
|
+
};
|
|
304
|
+
let next = 1;
|
|
305
|
+
const worker = async () => {
|
|
306
|
+
while (!both.aborted) {
|
|
307
|
+
const n = next++;
|
|
308
|
+
if (n > count)
|
|
309
|
+
return;
|
|
310
|
+
const [start, end] = range(n);
|
|
311
|
+
const len = end - start;
|
|
312
|
+
// Hash first: the sha256 is signed into the request, the md5 is what a
|
|
313
|
+
// part already in the store must match to be trusted. (No await
|
|
314
|
+
// between taking `n` and queueing its pass: that is what keeps the
|
|
315
|
+
// whole-object hash in order.)
|
|
316
|
+
const h = await hashPart(start, end);
|
|
317
|
+
const prior = have.get(n);
|
|
318
|
+
if (prior && prior.size === len && unquote(prior.etag) === h.md5) {
|
|
319
|
+
done.set(n, prior.etag);
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
const res = await send(`part ${n}/${count}`, "PUT", key, { stream: source.read(start, end, both), length: len, sha256: h.sha256 }, {}, both, // send() adds the part's deadline, sized by its length
|
|
323
|
+
{ partNumber: String(n), uploadId: id });
|
|
324
|
+
if (!res.ok)
|
|
325
|
+
throw await failure(res, `part ${n}`);
|
|
326
|
+
await drain(res);
|
|
327
|
+
const etag = res.headers.get("etag");
|
|
328
|
+
if (!etag)
|
|
329
|
+
throw new BlobTransientError(`s3 part ${n}: no ETag in the reply`);
|
|
330
|
+
done.set(n, etag);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
try {
|
|
334
|
+
const pool = Array.from({ length: Math.min(o.partConcurrency, count) }, () => worker().catch((err) => {
|
|
335
|
+
firstError ??= { err };
|
|
336
|
+
inner.abort(err); // stop the siblings
|
|
337
|
+
throw err;
|
|
338
|
+
}));
|
|
339
|
+
await Promise.allSettled(pool);
|
|
340
|
+
if (firstError)
|
|
341
|
+
throw firstError.err;
|
|
342
|
+
// Every part went through hashPart, in order: `whole` is the object the
|
|
343
|
+
// store would assemble. Not the bytes asked for means not this key —
|
|
344
|
+
// a final failure, so the catch below aborts the upload.
|
|
345
|
+
if (whole) {
|
|
346
|
+
const got = whole.digest("hex");
|
|
347
|
+
if (got !== opts.sha256)
|
|
348
|
+
throw new BlobSourceError(`the bytes for ${key} do not hash to ${opts.sha256} (they hash to ${got}): the source changed after it was hashed`);
|
|
349
|
+
}
|
|
350
|
+
const xml = `<CompleteMultipartUpload>` +
|
|
351
|
+
[...done.entries()]
|
|
352
|
+
.sort((a, b) => a[0] - b[0])
|
|
353
|
+
.map(([n, etag]) => `<Part><PartNumber>${n}</PartNumber><ETag>${etag.replace(/&/g, "&").replace(/</g, "<")}</ETag></Part>`)
|
|
354
|
+
.join("") +
|
|
355
|
+
`</CompleteMultipartUpload>`;
|
|
356
|
+
// Assembling the parts takes the store longer the bigger the object
|
|
357
|
+
// (AWS warns of minutes), so its deadline is sized by the object.
|
|
358
|
+
const res = await send("complete upload", "POST", key, Buffer.from(xml), { "if-none-match": "*" }, signal, { uploadId: id }, "application/xml", source.size);
|
|
359
|
+
if (res.status === 412) {
|
|
360
|
+
// Someone else's identical object won. Ours is not needed.
|
|
361
|
+
await drain(res);
|
|
362
|
+
await abortUpload(key, id);
|
|
363
|
+
return { created: false, ...(unquote(res.headers.get("etag")) ? { etag: unquote(res.headers.get("etag")) } : {}) };
|
|
364
|
+
}
|
|
365
|
+
if (res.status === 404) {
|
|
366
|
+
// NoSuchUpload: a twin of this call completed (or aborted) the same
|
|
367
|
+
// upload. If the object is there, the work is done.
|
|
368
|
+
await drain(res);
|
|
369
|
+
const now = await headObject(key, signal);
|
|
370
|
+
if (now)
|
|
371
|
+
return { created: false, ...(now.etag ? { etag: now.etag } : {}) };
|
|
372
|
+
throw new BlobTransientError("s3 complete upload: the upload vanished", 404, "NoSuchUpload");
|
|
373
|
+
}
|
|
374
|
+
if (!res.ok)
|
|
375
|
+
throw await failure(res, "complete upload");
|
|
376
|
+
// S3 can answer 200 and put the error in the body.
|
|
377
|
+
const text = await textOf(res, "complete upload");
|
|
378
|
+
if (/<Error>/.test(text)) {
|
|
379
|
+
const code = codeOf(text);
|
|
380
|
+
const msg = `s3 complete upload failed: 200 ${code ?? "error in body"}`;
|
|
381
|
+
throw code && !TRANSIENT_CODES.has(code) && code !== "NoSuchUpload" ? new BlobStoreError(msg, 200, code) : new BlobTransientError(msg, 200, code);
|
|
382
|
+
}
|
|
383
|
+
return { created: true, ...(unquote(/<ETag>([^<]*)<\/ETag>/.exec(text)?.[1]) ? { etag: unquote(unxml(/<ETag>([^<]*)<\/ETag>/.exec(text)[1])) } : {}) };
|
|
384
|
+
}
|
|
385
|
+
catch (err) {
|
|
386
|
+
// Cancelled by the caller, or a final failure: nothing will come back to
|
|
387
|
+
// finish this, so do not leave parts for the store to bill. A transient
|
|
388
|
+
// failure (including a deadline) leaves the upload for the retry.
|
|
389
|
+
const cancelled = signal?.aborted === true && !isTimeout(signal);
|
|
390
|
+
const final = !(err instanceof BlobTransientError);
|
|
391
|
+
if (cancelled || final)
|
|
392
|
+
await abortUpload(key, id);
|
|
393
|
+
throw err;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
// ---------- the interface ----------
|
|
397
|
+
return {
|
|
398
|
+
kind: "s3",
|
|
399
|
+
async putIfAbsent(key, body, opts = {}) {
|
|
400
|
+
assertKey(key);
|
|
401
|
+
return putOnce(key, Buffer.from(body), opts.contentType, opts.signal);
|
|
402
|
+
},
|
|
403
|
+
async putSourceIfAbsent(key, source, opts = {}) {
|
|
404
|
+
assertKey(key);
|
|
405
|
+
if (source.size >= o.multipartThresholdBytes)
|
|
406
|
+
return multipartPut(key, source, opts);
|
|
407
|
+
const sha256 = opts.sha256 ?? (await hashRange(source, 0, source.size, opts.signal)).sha256;
|
|
408
|
+
return putOnce(key, { stream: source.read(0, source.size, opts.signal), length: source.size, sha256 }, opts.contentType, opts.signal);
|
|
409
|
+
},
|
|
410
|
+
async get(key, opts = {}) {
|
|
411
|
+
assertKey(key);
|
|
412
|
+
const res = await send("get", "GET", key, undefined, opts.range ? { range: `bytes=${opts.range.start}-${opts.range.end}` } : {}, opts.signal, undefined, undefined, false);
|
|
413
|
+
if (res.status === 404) {
|
|
414
|
+
const text = await res.text().catch(() => "");
|
|
415
|
+
// A GET carries the reason a HEAD cannot: the bucket may be the thing that is missing.
|
|
416
|
+
if (codeOf(text) === "NoSuchBucket")
|
|
417
|
+
throw new BlobStoreError(`s3 get failed: 404 NoSuchBucket (${cfg.bucket})`, 404, "NoSuchBucket");
|
|
418
|
+
throw new BlobNotFound(key);
|
|
419
|
+
}
|
|
420
|
+
if (!res.ok || !res.body)
|
|
421
|
+
throw await failure(res, "get");
|
|
422
|
+
// A connection that drops mid-body is a retryable failure, not a TypeError.
|
|
423
|
+
const reader = res.body.getReader();
|
|
424
|
+
return new ReadableStream({
|
|
425
|
+
async pull(controller) {
|
|
426
|
+
try {
|
|
427
|
+
const { done, value } = await reader.read();
|
|
428
|
+
if (done)
|
|
429
|
+
controller.close();
|
|
430
|
+
else
|
|
431
|
+
controller.enqueue(value);
|
|
432
|
+
}
|
|
433
|
+
catch (err) {
|
|
434
|
+
controller.error(new BlobTransientError(`s3 get ${key}: the body was cut off (${err.cause?.code ?? err.message})`));
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
cancel: (reason) => reader.cancel(reason),
|
|
438
|
+
});
|
|
439
|
+
},
|
|
440
|
+
async head(key, opts = {}) {
|
|
441
|
+
assertKey(key);
|
|
442
|
+
return headObject(key, opts.signal);
|
|
443
|
+
},
|
|
444
|
+
async delete(key, opts = {}) {
|
|
445
|
+
assertKey(key);
|
|
446
|
+
const res = await send("delete", "DELETE", key, undefined, {}, opts.signal);
|
|
447
|
+
if (!res.ok && res.status !== 404)
|
|
448
|
+
throw await failure(res, "delete");
|
|
449
|
+
await drain(res);
|
|
450
|
+
},
|
|
451
|
+
async abortStaleUploads({ olderThanMs, prefix = "", signal }) {
|
|
452
|
+
let n = 0;
|
|
453
|
+
let keyMarker = "";
|
|
454
|
+
let uploadMarker = "";
|
|
455
|
+
for (;;) {
|
|
456
|
+
const q = { uploads: "", "max-uploads": "1000", ...(prefix ? { prefix } : {}) };
|
|
457
|
+
if (keyMarker)
|
|
458
|
+
q["key-marker"] = keyMarker;
|
|
459
|
+
if (uploadMarker)
|
|
460
|
+
q["upload-id-marker"] = uploadMarker;
|
|
461
|
+
const res = await send("list uploads", "GET", "", undefined, {}, signal, q);
|
|
462
|
+
if (!res.ok)
|
|
463
|
+
throw await failure(res, "list uploads");
|
|
464
|
+
const xml = await textOf(res, "list uploads");
|
|
465
|
+
for (const m of xml.matchAll(/<Upload>([\s\S]*?)<\/Upload>/g)) {
|
|
466
|
+
const key = unxml(/<Key>([^<]*)<\/Key>/.exec(m[1])?.[1] ?? "");
|
|
467
|
+
const id = unxml(/<UploadId>([^<]*)<\/UploadId>/.exec(m[1])?.[1] ?? "");
|
|
468
|
+
const at = Date.parse(/<Initiated>([^<]*)<\/Initiated>/.exec(m[1])?.[1] ?? "");
|
|
469
|
+
if (key && id && Number.isFinite(at) && Date.now() - at >= olderThanMs) {
|
|
470
|
+
await abortUpload(key, id);
|
|
471
|
+
n++;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (!/<IsTruncated>true<\/IsTruncated>/.test(xml))
|
|
475
|
+
return n;
|
|
476
|
+
keyMarker = unxml(/<NextKeyMarker>([^<]*)<\/NextKeyMarker>/.exec(xml)?.[1] ?? "");
|
|
477
|
+
uploadMarker = unxml(/<NextUploadIdMarker>([^<]*)<\/NextUploadIdMarker>/.exec(xml)?.[1] ?? "");
|
|
478
|
+
if (!keyMarker && !uploadMarker)
|
|
479
|
+
return n;
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
async *list(prefix, opts = {}) {
|
|
483
|
+
let token;
|
|
484
|
+
do {
|
|
485
|
+
const q = { "list-type": "2", prefix: prefix.endsWith("/") ? prefix : `${prefix}/`, ...(token ? { "continuation-token": token } : {}) };
|
|
486
|
+
const res = await send("list", "GET", "", undefined, {}, opts.signal, q);
|
|
487
|
+
if (!res.ok)
|
|
488
|
+
throw await failure(res, "list");
|
|
489
|
+
const xml = await textOf(res, "list");
|
|
490
|
+
for (const c of xml.matchAll(/<Contents>([\s\S]*?)<\/Contents>/g)) {
|
|
491
|
+
const key = xmlText(c[1], "Key");
|
|
492
|
+
const size = Number(xmlText(c[1], "Size"));
|
|
493
|
+
const lm = xmlText(c[1], "LastModified");
|
|
494
|
+
if (key)
|
|
495
|
+
yield { key, size: Number.isFinite(size) ? size : 0, modifiedAt: lm ? new Date(lm) : new Date(0) };
|
|
496
|
+
}
|
|
497
|
+
token = /<IsTruncated>true<\/IsTruncated>/.test(xml) ? (xmlText(xml, "NextContinuationToken") ?? undefined) : undefined;
|
|
498
|
+
} while (token);
|
|
499
|
+
},
|
|
500
|
+
async tenants(opts = {}) {
|
|
501
|
+
const out = [];
|
|
502
|
+
let token;
|
|
503
|
+
do {
|
|
504
|
+
const q = { "list-type": "2", prefix: "t/", delimiter: "/", ...(token ? { "continuation-token": token } : {}) };
|
|
505
|
+
const res = await send("list", "GET", "", undefined, {}, opts.signal, q);
|
|
506
|
+
if (!res.ok)
|
|
507
|
+
throw await failure(res, "list");
|
|
508
|
+
const xml = await textOf(res, "list");
|
|
509
|
+
for (const c of xml.matchAll(/<CommonPrefixes>\s*<Prefix>([^<]*)<\/Prefix>/g))
|
|
510
|
+
out.push(unxml(c[1]).replace(/^t\//, "").replace(/\/$/, ""));
|
|
511
|
+
token = /<IsTruncated>true<\/IsTruncated>/.test(xml) ? (xmlText(xml, "NextContinuationToken") ?? undefined) : undefined;
|
|
512
|
+
} while (token);
|
|
513
|
+
return out;
|
|
514
|
+
},
|
|
515
|
+
/** Is the bucket there, and may we use it? A HEAD on a key cannot say. */
|
|
516
|
+
async checkBucket(signal) {
|
|
517
|
+
const res = await send("head bucket", "HEAD", "", undefined, {}, signal);
|
|
518
|
+
if (res.ok)
|
|
519
|
+
return void (await drain(res));
|
|
520
|
+
await drain(res);
|
|
521
|
+
if (res.status === 404)
|
|
522
|
+
throw new BlobStoreError(`s3: bucket ${cfg.bucket} does not exist (or the endpoint is wrong)`, 404, "NoSuchBucket");
|
|
523
|
+
throw await failure(res, "head bucket");
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function xmlText(xml, tag) {
|
|
528
|
+
const m = new RegExp(`<${tag}>([\\s\\S]*?)</${tag}>`).exec(xml);
|
|
529
|
+
return m ? unxml(m[1]) : null;
|
|
530
|
+
}
|
|
531
|
+
export { bufferSource };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Deps } from "./publish.ts";
|
|
2
|
+
export interface StateRetention {
|
|
3
|
+
keep: number;
|
|
4
|
+
days: number;
|
|
5
|
+
}
|
|
6
|
+
export interface PruneResult {
|
|
7
|
+
pruned: number;
|
|
8
|
+
kept: number;
|
|
9
|
+
/** Outside the window but held by a run or a publish: left for next time. */
|
|
10
|
+
held: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function pruneStateRevisions(deps: Deps, ws: {
|
|
13
|
+
tenant: string;
|
|
14
|
+
workspace: string;
|
|
15
|
+
}, policy: StateRetention, now?: number): Promise<PruneResult>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// How long `state/` checkpoints are kept (FOL-126 fixes, 8 Nov 2026).
|
|
2
|
+
//
|
|
3
|
+
// Every step of every run writes `state/` and each is a revision on the state
|
|
4
|
+
// head; the manifests are small but the blobs are whatever the state holds
|
|
5
|
+
// (indexes, caches), and the ticket's 100 × 1 GB case is a state head that
|
|
6
|
+
// never forgets. So the state head keeps a window:
|
|
7
|
+
//
|
|
8
|
+
// keep the newest N checkpoints (0: no count limit)
|
|
9
|
+
// days and none older than D days (0: no age limit)
|
|
10
|
+
//
|
|
11
|
+
// A checkpoint goes when it is outside EITHER limit, except
|
|
12
|
+
// - the head, always (it is the state);
|
|
13
|
+
// - one whose manifest something other than a revision still holds — a run
|
|
14
|
+
// staged from it (pin holder `run`), a publish in flight — checked through
|
|
15
|
+
// the same pins the sweeper obeys. It is looked at again next time.
|
|
16
|
+
//
|
|
17
|
+
// Pruning removes the revision rows and releases the pins THOSE revisions held
|
|
18
|
+
// on their manifests; it deletes no object. The objects are the sweeper's: it
|
|
19
|
+
// deletes a manifest or blob only through guardDelete, and only when no pin is
|
|
20
|
+
// left. A manifest two checkpoints share (an unchanged state) keeps the other
|
|
21
|
+
// checkpoint's pin.
|
|
22
|
+
//
|
|
23
|
+
// The workspace head (authored files) is not pruned: that is the history page.
|
|
24
|
+
const PAGE = 500;
|
|
25
|
+
export async function pruneStateRevisions(deps, ws, policy, now = Date.now()) {
|
|
26
|
+
const keep = Math.max(0, Math.floor(policy.keep || 0));
|
|
27
|
+
const days = Math.max(0, policy.days || 0);
|
|
28
|
+
const out = { pruned: 0, kept: 0, held: 0 };
|
|
29
|
+
if (keep === 0 && days === 0)
|
|
30
|
+
return out;
|
|
31
|
+
const sws = { tenant: ws.tenant, workspace: ws.workspace, scope: "state" };
|
|
32
|
+
const cutoff = days > 0 ? now - days * 86_400_000 : -Infinity;
|
|
33
|
+
const doomed = [];
|
|
34
|
+
let seen = 0;
|
|
35
|
+
let before;
|
|
36
|
+
for (;;) {
|
|
37
|
+
const page = await deps.revisions.revisions(sws, { limit: PAGE, before });
|
|
38
|
+
if (!page.length)
|
|
39
|
+
break;
|
|
40
|
+
for (const r of page) {
|
|
41
|
+
const index = seen++;
|
|
42
|
+
if (index === 0) {
|
|
43
|
+
out.kept++; // the head
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const outside = (keep > 0 && index >= keep) || Date.parse(r.at) < cutoff;
|
|
47
|
+
if (!outside) {
|
|
48
|
+
out.kept++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (deps.pins && (await deps.pins.isPinnedBeyondRevisions(ws.tenant, "manifest", r.state))) {
|
|
52
|
+
out.held++;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
doomed.push(r.id);
|
|
56
|
+
}
|
|
57
|
+
before = page[page.length - 1].seq;
|
|
58
|
+
if (page.length < PAGE)
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
// In slices: one statement per slice, never an unbounded list.
|
|
62
|
+
for (let i = 0; i < doomed.length; i += 200)
|
|
63
|
+
out.pruned += await deps.revisions.prune(sws, doomed.slice(i, i + 200));
|
|
64
|
+
return out;
|
|
65
|
+
}
|
package/dist/src/storage.d.ts
CHANGED
|
@@ -93,7 +93,7 @@ export interface Driver {
|
|
|
93
93
|
/** Where the fs driver keeps a blob. Exported because the run mirror
|
|
94
94
|
* hardlinks straight to it rather than reading and rewriting the bytes. */
|
|
95
95
|
export declare function blobPath(tenant: string, workspace: string, sha: string): string;
|
|
96
|
-
interface S3Config {
|
|
96
|
+
export interface S3Config {
|
|
97
97
|
endpoint: string;
|
|
98
98
|
bucket: string;
|
|
99
99
|
region: string;
|
|
@@ -109,6 +109,21 @@ export declare function regionOfEndpoint(endpoint: string): string | null;
|
|
|
109
109
|
export declare function s3Config(): S3Config | null;
|
|
110
110
|
/** For tests: forget cached role credentials. */
|
|
111
111
|
export declare function forgetS3Credentials(): void;
|
|
112
|
+
/** A body that is not held in memory: read as it is sent. `length` and
|
|
113
|
+
* `sha256` (hex of the whole body) are needed up front: S3 wants a
|
|
114
|
+
* Content-Length (it refuses chunked uploads) and the hash is signed. */
|
|
115
|
+
export interface S3StreamBody {
|
|
116
|
+
stream: AsyncIterable<Uint8Array>;
|
|
117
|
+
length: number;
|
|
118
|
+
sha256: string;
|
|
119
|
+
}
|
|
120
|
+
export interface S3RequestOptions {
|
|
121
|
+
/** Sub-resource and list parameters (`uploads`, `uploadId`, `partNumber`,
|
|
122
|
+
* `prefix`...). Signed in canonical order. An empty value is `name=`. */
|
|
123
|
+
query?: Record<string, string>;
|
|
124
|
+
}
|
|
125
|
+
/** The header-signed form, for the calls the platform itself makes. */
|
|
126
|
+
export declare function s3Request(cfg: S3Config, method: "GET" | "PUT" | "POST" | "DELETE" | "HEAD", key: string, body?: Buffer | S3StreamBody, mime?: string, extra?: Record<string, string>, signal?: AbortSignal, opts?: S3RequestOptions): Promise<Response>;
|
|
112
127
|
/**
|
|
113
128
|
* The Content-Disposition a presigned GET asks the store to send back. The
|
|
114
129
|
* store echoes it as a header, and header values are bytes: a raw "報告.pdf"
|
|
@@ -122,6 +137,19 @@ export declare function contentDisposition(type: "inline" | "attachment", filena
|
|
|
122
137
|
* because a dashboard that boots and stores locally beats one that 500s.
|
|
123
138
|
*/
|
|
124
139
|
export declare function driverFor(tenant: string, workspace: string): Driver;
|
|
140
|
+
/**
|
|
141
|
+
* Run `fn` as the only writer of this workspace's file index, in this process
|
|
142
|
+
* and every other one on the volume. Callers of the same workspace in this
|
|
143
|
+
* process queue on a promise chain first, so they do not poll the file against
|
|
144
|
+
* each other. Keep `fn` to index work and blob bookkeeping; bytes a caller
|
|
145
|
+
* already holds are uploaded BEFORE taking the lock (a blob is immutable and
|
|
146
|
+
* named by its hash, so that is safe) and then confirmed present inside it.
|
|
147
|
+
*/
|
|
148
|
+
export declare function withFileStoreLock<T>(tenant: string, workspace: string, fn: () => Promise<T>): Promise<T>;
|
|
149
|
+
/** The same lock for any path: `file` is the lock file itself (its directory
|
|
150
|
+
* is created). Used by the local RevisionStore, which keeps its own state
|
|
151
|
+
* beside the data it guards. */
|
|
152
|
+
export declare function withFileLock<T>(file: string, fn: () => Promise<T>): Promise<T>;
|
|
125
153
|
export declare function putFile(tenant: string, workspace: string, rel: string, body: Buffer, by: string): Promise<FileRecord>;
|
|
126
154
|
/** Register bytes a browser PUT straight to the bucket. Same bookkeeping as
|
|
127
155
|
* putFile, minus the bytes — the platform never saw them.
|