@powerhousedao/reactor-attachments 6.2.3-dev.9 → 6.2.3-dev.91
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/attachment-schema-compiler-BytE6Hev.js +255 -0
- package/dist/attachment-schema-compiler-BytE6Hev.js.map +1 -0
- package/dist/client.d.ts +65 -40
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +38 -23
- package/dist/client.js.map +1 -1
- package/dist/hash-BobbR4r4.js +63 -0
- package/dist/hash-BobbR4r4.js.map +1 -0
- package/dist/index.d.ts +81 -111
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +134 -406
- package/dist/index.js.map +1 -1
- package/dist/{null-attachment-transport-CMrO_ZKA.d.ts → interfaces-cFMtcMqR.d.ts} +38 -327
- package/dist/interfaces-cFMtcMqR.d.ts.map +1 -0
- package/dist/replication.d.ts +955 -0
- package/dist/replication.d.ts.map +1 -0
- package/dist/replication.js +1975 -0
- package/dist/replication.js.map +1 -0
- package/dist/{null-attachment-transport-CrsUafCi.js → routing-attachment-service-C88ryRgj.js} +93 -282
- package/dist/routing-attachment-service-C88ryRgj.js.map +1 -0
- package/dist/routing-attachment-service-Dri6e2Vz.d.ts +343 -0
- package/dist/routing-attachment-service-Dri6e2Vz.d.ts.map +1 -0
- package/dist/switchboard-attachment-transport-BH3ZAmxE.js +284 -0
- package/dist/switchboard-attachment-transport-BH3ZAmxE.js.map +1 -0
- package/dist/types-AagIcjTD.d.ts +61 -0
- package/dist/types-AagIcjTD.d.ts.map +1 -0
- package/package.json +17 -8
- package/dist/null-attachment-transport-CMrO_ZKA.d.ts.map +0 -1
- package/dist/null-attachment-transport-CrsUafCi.js.map +0 -1
package/dist/{null-attachment-transport-CrsUafCi.js → routing-attachment-service-C88ryRgj.js}
RENAMED
|
@@ -1,124 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when an attachment ref or hash is not known to the store.
|
|
4
|
-
*/
|
|
5
|
-
var AttachmentNotFound = class extends Error {
|
|
6
|
-
constructor(identifier) {
|
|
7
|
-
super(`Attachment not found: ${identifier}`);
|
|
8
|
-
this.name = "AttachmentNotFound";
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Thrown when a reservation ID is not found in the reservation store.
|
|
13
|
-
*/
|
|
14
|
-
var ReservationNotFound = class extends Error {
|
|
15
|
-
constructor(reservationId) {
|
|
16
|
-
super(`Reservation not found: ${reservationId}`);
|
|
17
|
-
this.name = "ReservationNotFound";
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Thrown when an attachment ref string does not match the expected format.
|
|
22
|
-
*/
|
|
23
|
-
var InvalidAttachmentRef = class extends Error {
|
|
24
|
-
constructor(ref) {
|
|
25
|
-
super(`Invalid attachment ref: ${ref}`);
|
|
26
|
-
this.name = "InvalidAttachmentRef";
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Thrown when an upload exceeds the configured maximum byte cap.
|
|
31
|
-
* Route handlers should map this to HTTP 413 Payload Too Large.
|
|
32
|
-
*/
|
|
33
|
-
var UploadTooLarge = class extends Error {
|
|
34
|
-
maxBytes;
|
|
35
|
-
constructor(maxBytes) {
|
|
36
|
-
super(`Upload exceeds maximum size of ${maxBytes} bytes`);
|
|
37
|
-
this.name = "UploadTooLarge";
|
|
38
|
-
this.maxBytes = maxBytes;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Thrown by reserve() when the claimed hash is already available in the store.
|
|
43
|
-
* The caller should use err.ref directly and upload nothing -- this is the
|
|
44
|
-
* dedup fast path: duplicate content never leaves the client.
|
|
45
|
-
*/
|
|
46
|
-
var AttachmentAlreadyExists = class extends Error {
|
|
47
|
-
hash;
|
|
48
|
-
ref;
|
|
49
|
-
constructor(hash, ref) {
|
|
50
|
-
super(`Attachment already exists for hash: ${hash}`);
|
|
51
|
-
this.name = "AttachmentAlreadyExists";
|
|
52
|
-
this.hash = hash;
|
|
53
|
-
this.ref = ref;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Thrown by send() when the server-computed hash of the uploaded bytes
|
|
58
|
-
* does not match the hash claimed at reservation time. Nothing is committed;
|
|
59
|
-
* the reservation is retained so the client can retry with correct bytes.
|
|
60
|
-
*/
|
|
61
|
-
var HashMismatch = class extends Error {
|
|
62
|
-
claimed;
|
|
63
|
-
actual;
|
|
64
|
-
constructor(claimed, actual) {
|
|
65
|
-
super(`Hash mismatch: claimed ${claimed} but computed ${actual}`);
|
|
66
|
-
this.name = "HashMismatch";
|
|
67
|
-
this.claimed = claimed;
|
|
68
|
-
this.actual = actual;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Thrown by send() when the uploaded byte count does not equal the
|
|
73
|
-
* sizeBytes declared at reservation time. The handle may reject
|
|
74
|
-
* mid-stream as soon as the count exceeds the declaration.
|
|
75
|
-
* Nothing is committed; the reservation is retained for retry.
|
|
76
|
-
*
|
|
77
|
-
* "actual" is the byte count received from the stream before aborting --
|
|
78
|
-
* it includes the chunk that crossed the declaration and can exceed bytes
|
|
79
|
-
* persisted. On mid-stream aborts the true total is unknown; at least
|
|
80
|
-
* "actual" bytes were sent.
|
|
81
|
-
*/
|
|
82
|
-
var SizeMismatch = class extends Error {
|
|
83
|
-
declared;
|
|
84
|
-
actual;
|
|
85
|
-
constructor(declared, actual) {
|
|
86
|
-
super(`Size mismatch: declared ${declared} bytes but received ${actual}`);
|
|
87
|
-
this.name = "SizeMismatch";
|
|
88
|
-
this.declared = declared;
|
|
89
|
-
this.actual = actual;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Thrown when a remote transfer step fails. Identifies the stage only; it
|
|
94
|
-
* intentionally carries no URL, signature query, bucket key, or bearer
|
|
95
|
-
* material so it is always safe to log or surface.
|
|
96
|
-
*/
|
|
97
|
-
var AttachmentTransferError = class extends Error {
|
|
98
|
-
stage;
|
|
99
|
-
status;
|
|
100
|
-
constructor(stage, status) {
|
|
101
|
-
super(status === void 0 ? `Attachment ${stage} request failed` : `Attachment ${stage} request failed with status ${status}`);
|
|
102
|
-
this.name = "AttachmentTransferError";
|
|
103
|
-
this.stage = stage;
|
|
104
|
-
this.status = status;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
var AttachmentPending = class extends Error {
|
|
108
|
-
hash;
|
|
109
|
-
expiresAtUtc;
|
|
110
|
-
metadata;
|
|
111
|
-
constructor(hash, expiresAtUtc, meta) {
|
|
112
|
-
super(`Attachment pending upload for hash: ${hash}, expires: ${expiresAtUtc}`);
|
|
113
|
-
this.name = "AttachmentPending";
|
|
114
|
-
this.hash = hash;
|
|
115
|
-
this.expiresAtUtc = expiresAtUtc;
|
|
116
|
-
this.metadata = meta;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
//#endregion
|
|
1
|
+
import { a as parseRef, c as AttachmentPending, i as createRef, l as AttachmentTransferError, m as SizeMismatch, n as buildAuthHeaders, o as AttachmentAlreadyExists, p as ReservationNotFound, s as AttachmentNotFound, u as HashMismatch } from "./switchboard-attachment-transport-BH3ZAmxE.js";
|
|
120
2
|
//#region src/targets.ts
|
|
121
|
-
function isRecord$
|
|
3
|
+
function isRecord$3(value) {
|
|
122
4
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
123
5
|
}
|
|
124
6
|
function parseUrl(value) {
|
|
@@ -134,7 +16,7 @@ function parseUrl(value) {
|
|
|
134
16
|
return value;
|
|
135
17
|
}
|
|
136
18
|
function parseHeaders(value) {
|
|
137
|
-
if (!isRecord$
|
|
19
|
+
if (!isRecord$3(value)) throw new Error("Attachment target headers must be an object");
|
|
138
20
|
const headers = Object.create(null);
|
|
139
21
|
const headerName = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
140
22
|
for (const [name, headerValue] of Object.entries(value)) {
|
|
@@ -166,7 +48,7 @@ function parseExpiry(value, required) {
|
|
|
166
48
|
return value;
|
|
167
49
|
}
|
|
168
50
|
function parseAttachmentUploadTarget(value) {
|
|
169
|
-
if (!isRecord$
|
|
51
|
+
if (!isRecord$3(value)) throw new Error("Attachment upload target must be an object");
|
|
170
52
|
const url = parseUrl(value.url);
|
|
171
53
|
const headers = parseHeaders(value.headers);
|
|
172
54
|
switch (value.kind) {
|
|
@@ -192,7 +74,7 @@ function parseAttachmentUploadTarget(value) {
|
|
|
192
74
|
}
|
|
193
75
|
}
|
|
194
76
|
function parseAttachmentDownloadTarget(value) {
|
|
195
|
-
if (!isRecord$
|
|
77
|
+
if (!isRecord$3(value)) throw new Error("Attachment download target must be an object");
|
|
196
78
|
const url = parseUrl(value.url);
|
|
197
79
|
const headers = parseHeaders(value.headers);
|
|
198
80
|
switch (value.kind) {
|
|
@@ -218,24 +100,13 @@ function parseAttachmentDownloadTarget(value) {
|
|
|
218
100
|
}
|
|
219
101
|
}
|
|
220
102
|
//#endregion
|
|
221
|
-
//#region src/ref.ts
|
|
222
|
-
const REF_PATTERN = /^attachment:\/\/v(\d+):(.+)$/;
|
|
223
|
-
const DEFAULT_VERSION = 1;
|
|
224
|
-
function parseRef(ref) {
|
|
225
|
-
const match = REF_PATTERN.exec(ref);
|
|
226
|
-
if (!match) throw new InvalidAttachmentRef(ref);
|
|
227
|
-
return {
|
|
228
|
-
version: Number(match[1]),
|
|
229
|
-
hash: match[2]
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
function createRef(hash, version = DEFAULT_VERSION) {
|
|
233
|
-
return `attachment://v${version}:${hash}`;
|
|
234
|
-
}
|
|
235
|
-
//#endregion
|
|
236
103
|
//#region src/attachment-service.ts
|
|
237
104
|
const CLIENT_HASH_PATTERN = /^[a-f0-9]{64}$/;
|
|
238
105
|
var AttachmentService = class {
|
|
106
|
+
store;
|
|
107
|
+
reservations;
|
|
108
|
+
uploadFactory;
|
|
109
|
+
backend;
|
|
239
110
|
constructor(store, reservations, uploadFactory, backend) {
|
|
240
111
|
this.store = store;
|
|
241
112
|
this.reservations = reservations;
|
|
@@ -248,9 +119,9 @@ var AttachmentService = class {
|
|
|
248
119
|
const reservation = await this.reservations.create(options);
|
|
249
120
|
return this.uploadFactory.createUpload(reservation);
|
|
250
121
|
}
|
|
251
|
-
async stat(ref) {
|
|
122
|
+
async stat(ref, options) {
|
|
252
123
|
const { hash } = parseRef(ref);
|
|
253
|
-
return this.store.stat(hash);
|
|
124
|
+
return options?.documentId === void 0 ? this.store.stat(hash) : this.store.stat(hash, options.documentId);
|
|
254
125
|
}
|
|
255
126
|
async get(ref, options) {
|
|
256
127
|
const { hash } = parseRef(ref);
|
|
@@ -266,7 +137,7 @@ var AttachmentService = class {
|
|
|
266
137
|
async reserveHashFirst(options) {
|
|
267
138
|
const normalized = options.clientHash.toLowerCase();
|
|
268
139
|
if (!CLIENT_HASH_PATTERN.test(normalized)) throw new Error(`clientHash must be a 64-character lowercase hex string, got: ${options.clientHash}`);
|
|
269
|
-
if (options.sizeBytes === void 0 || !Number.
|
|
140
|
+
if (options.sizeBytes === void 0 || !Number.isSafeInteger(options.sizeBytes) || options.sizeBytes < 0) throw new Error("sizeBytes must be a non-negative safe integer when clientHash is provided");
|
|
270
141
|
const normalizedOptions = {
|
|
271
142
|
...options,
|
|
272
143
|
clientHash: normalized
|
|
@@ -292,137 +163,30 @@ var AttachmentService = class {
|
|
|
292
163
|
}
|
|
293
164
|
};
|
|
294
165
|
//#endregion
|
|
295
|
-
//#region src/
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const token = await jwtHandler(url);
|
|
300
|
-
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
301
|
-
}
|
|
302
|
-
return headers;
|
|
166
|
+
//#region src/blob.ts
|
|
167
|
+
/** Tells a Blob from a stream by shape: `instanceof Blob` misses other realms and polyfills. */
|
|
168
|
+
function isBlob(data) {
|
|
169
|
+
return !("getReader" in data);
|
|
303
170
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const response = await this.fetchFn(url, {
|
|
319
|
-
signal,
|
|
320
|
-
headers
|
|
321
|
-
});
|
|
322
|
-
if (response.status === 202) {
|
|
323
|
-
const expiresAtUtc = this.parsePendingExpiry(response);
|
|
324
|
-
if (!expiresAtUtc) throw new Error("Attachment fetch returned 202 with missing or malformed Attachment-Pending header");
|
|
325
|
-
return {
|
|
326
|
-
kind: "pending",
|
|
327
|
-
hash,
|
|
328
|
-
expiresAtUtc,
|
|
329
|
-
retryAfterMs: parseRetryAfterMs(response)
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
if (response.status === 404) return { kind: "not-found" };
|
|
333
|
-
if (!response.ok) throw new Error(`Attachment fetch failed: ${response.status} ${response.statusText}`);
|
|
334
|
-
const metadata = this.parseMetadataHeaders(response);
|
|
335
|
-
const body = response.body;
|
|
336
|
-
if (!body) throw new Error("Response body is null");
|
|
337
|
-
return {
|
|
338
|
-
kind: "data",
|
|
339
|
-
response: {
|
|
340
|
-
hash,
|
|
341
|
-
metadata,
|
|
342
|
-
body
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
async announce(_hash) {}
|
|
347
|
-
async push(hash, remote, data) {
|
|
348
|
-
const url = `${remote}/attachments/${hash}`;
|
|
349
|
-
const headers = await buildAuthHeaders(url, this.jwtHandler);
|
|
350
|
-
const response = await this.fetchFn(url, {
|
|
351
|
-
method: "PUT",
|
|
352
|
-
body: data,
|
|
353
|
-
headers,
|
|
354
|
-
duplex: "half"
|
|
355
|
-
});
|
|
356
|
-
if (!response.ok) throw new Error(`Attachment push failed: ${response.status} ${response.statusText}`);
|
|
357
|
-
}
|
|
358
|
-
parsePendingExpiry(response) {
|
|
359
|
-
const header = response.headers.get("Attachment-Pending");
|
|
360
|
-
if (!header) return null;
|
|
361
|
-
try {
|
|
362
|
-
const parsed = JSON.parse(header);
|
|
363
|
-
if (!isRecord$3(parsed)) return null;
|
|
364
|
-
if (typeof parsed.expiresAtUtc !== "string") return null;
|
|
365
|
-
return parsed.expiresAtUtc;
|
|
366
|
-
} catch {
|
|
367
|
-
return null;
|
|
171
|
+
const BLOB_SLICE_BYTES = 8388608;
|
|
172
|
+
/**
|
|
173
|
+
* A Blob's bytes as a stream, read a slice at a time and only when asked.
|
|
174
|
+
*
|
|
175
|
+
* Not `blob.stream()`: under Node 24 that call keeps the async context it was
|
|
176
|
+
* made in alive for good, read or not, and with it everything the context's
|
|
177
|
+
* stores reach. A workflow run's context reaches the run's whole output.
|
|
178
|
+
*/
|
|
179
|
+
function blobStream(blob, sliceBytes = BLOB_SLICE_BYTES) {
|
|
180
|
+
let offset = 0;
|
|
181
|
+
return new ReadableStream({ async pull(controller) {
|
|
182
|
+
if (offset >= blob.size) {
|
|
183
|
+
controller.close();
|
|
184
|
+
return;
|
|
368
185
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (fallbackCache === void 0) fallbackCache = contentTypeFallback$1(response);
|
|
374
|
-
return fallbackCache;
|
|
375
|
-
};
|
|
376
|
-
const metaHeader = response.headers.get("Attachment-Metadata");
|
|
377
|
-
if (metaHeader) try {
|
|
378
|
-
const parsed = JSON.parse(metaHeader);
|
|
379
|
-
if (isRecord$3(parsed)) {
|
|
380
|
-
if (parsed.extension === void 0) parsed.extension = null;
|
|
381
|
-
if (parsed.createdAtUtc === void 0) parsed.createdAtUtc = fallback().createdAtUtc;
|
|
382
|
-
if (parsed.lastAccessedAtUtc === void 0) parsed.lastAccessedAtUtc = fallback().lastAccessedAtUtc;
|
|
383
|
-
}
|
|
384
|
-
if (isAttachmentMetadata$1(parsed)) return parsed;
|
|
385
|
-
} catch {}
|
|
386
|
-
return fallback();
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
const DEFAULT_RETRY_AFTER_MS = 5e3;
|
|
390
|
-
function parseRetryAfterMs(response) {
|
|
391
|
-
const retryAfter = response.headers.get("Retry-After");
|
|
392
|
-
if (!retryAfter) return DEFAULT_RETRY_AFTER_MS;
|
|
393
|
-
const seconds = Number(retryAfter);
|
|
394
|
-
if (!Number.isFinite(seconds) || seconds < 0) return DEFAULT_RETRY_AFTER_MS;
|
|
395
|
-
return Math.round(seconds * 1e3);
|
|
396
|
-
}
|
|
397
|
-
function isRecord$3(value) {
|
|
398
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
399
|
-
}
|
|
400
|
-
function isAttachmentMetadata$1(value) {
|
|
401
|
-
if (!isRecord$3(value)) return false;
|
|
402
|
-
if (typeof value.mimeType !== "string") return false;
|
|
403
|
-
if (typeof value.fileName !== "string") return false;
|
|
404
|
-
if (typeof value.sizeBytes !== "number" || !Number.isFinite(value.sizeBytes) || value.sizeBytes < 0) return false;
|
|
405
|
-
if (value.extension !== null && typeof value.extension !== "string") return false;
|
|
406
|
-
if (typeof value.createdAtUtc !== "string") return false;
|
|
407
|
-
if (value.lastAccessedAtUtc !== void 0 && typeof value.lastAccessedAtUtc !== "string") return false;
|
|
408
|
-
return true;
|
|
409
|
-
}
|
|
410
|
-
function contentTypeFallback$1(response) {
|
|
411
|
-
const contentLength = response.headers.get("Content-Length");
|
|
412
|
-
if (contentLength === null) throw new Error("Switchboard response missing both Attachment-Metadata and Content-Length headers");
|
|
413
|
-
const sizeBytes = Number(contentLength);
|
|
414
|
-
if (!Number.isInteger(sizeBytes) || sizeBytes < 0) throw new Error(`Switchboard response has invalid Content-Length header: ${JSON.stringify(contentLength)}`);
|
|
415
|
-
const lastModified = response.headers.get("Last-Modified");
|
|
416
|
-
const dateHeader = response.headers.get("Date");
|
|
417
|
-
const createdAtUtc = lastModified ? new Date(lastModified).toISOString() : dateHeader ? new Date(dateHeader).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
|
|
418
|
-
return {
|
|
419
|
-
mimeType: response.headers.get("Content-Type") ?? "application/octet-stream",
|
|
420
|
-
fileName: "unknown",
|
|
421
|
-
sizeBytes,
|
|
422
|
-
extension: null,
|
|
423
|
-
createdAtUtc,
|
|
424
|
-
lastAccessedAtUtc: createdAtUtc
|
|
425
|
-
};
|
|
186
|
+
const slice = blob.slice(offset, offset + sliceBytes);
|
|
187
|
+
offset += sliceBytes;
|
|
188
|
+
controller.enqueue(new Uint8Array(await slice.arrayBuffer()));
|
|
189
|
+
} }, { highWaterMark: 0 });
|
|
426
190
|
}
|
|
427
191
|
//#endregion
|
|
428
192
|
//#region src/switchboard/upload-transport.ts
|
|
@@ -623,7 +387,7 @@ var RemoteReservationStore = class {
|
|
|
623
387
|
fileName: options.fileName,
|
|
624
388
|
extension,
|
|
625
389
|
createdAtUtc: body.createdAtUtc ?? now.toISOString(),
|
|
626
|
-
expiresAtUtc: body.expiresAtUtc ?? new Date(now.getTime() +
|
|
390
|
+
expiresAtUtc: body.expiresAtUtc ?? new Date(now.getTime() + 864e5).toISOString(),
|
|
627
391
|
clientHash: options.clientHash ?? null,
|
|
628
392
|
sizeBytes: options.sizeBytes ?? null,
|
|
629
393
|
...body.uploadTarget === void 0 ? {} : { uploadTarget: parseAttachmentUploadTarget(body.uploadTarget) }
|
|
@@ -672,6 +436,13 @@ var RemoteReservationStore = class {
|
|
|
672
436
|
function isRecord$1(value) {
|
|
673
437
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
674
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* A Blob goes out untouched, so a File streams from disk. A stream is
|
|
441
|
+
* buffered: browsers don't portably accept a ReadableStream request body.
|
|
442
|
+
*/
|
|
443
|
+
async function toBody(data) {
|
|
444
|
+
return isBlob(data) ? data : new Response(data).blob();
|
|
445
|
+
}
|
|
675
446
|
var RemoteAttachmentUpload = class {
|
|
676
447
|
reservationId;
|
|
677
448
|
ref;
|
|
@@ -695,7 +466,7 @@ var RemoteAttachmentUpload = class {
|
|
|
695
466
|
if (this.uploadTarget?.kind === "presigned-put") return this.sendPresigned(this.uploadTarget, data, options);
|
|
696
467
|
const url = `${this.remoteUrl}/attachments/reservations/${this.reservationId}`;
|
|
697
468
|
const authHeaders = await buildAuthHeaders(url, this.jwtHandler);
|
|
698
|
-
const body = await
|
|
469
|
+
const body = await toBody(data);
|
|
699
470
|
const response = await this.uploadTransport({
|
|
700
471
|
url,
|
|
701
472
|
method: "PUT",
|
|
@@ -732,7 +503,7 @@ var RemoteAttachmentUpload = class {
|
|
|
732
503
|
*/
|
|
733
504
|
async sendPresigned(target, data, options) {
|
|
734
505
|
if (this.reservation.clientHash === null || this.ref === null) throw new Error("Presigned upload targets require a hash-first reservation");
|
|
735
|
-
const body = await
|
|
506
|
+
const body = await toBody(data);
|
|
736
507
|
const response = await this.uploadTransport({
|
|
737
508
|
url: target.url,
|
|
738
509
|
method: target.method,
|
|
@@ -765,6 +536,7 @@ var RemoteAttachmentUpload = class {
|
|
|
765
536
|
//#endregion
|
|
766
537
|
//#region src/switchboard/remote-attachment-upload-factory.ts
|
|
767
538
|
var RemoteAttachmentUploadFactory = class {
|
|
539
|
+
config;
|
|
768
540
|
constructor(config) {
|
|
769
541
|
this.config = config;
|
|
770
542
|
}
|
|
@@ -774,6 +546,7 @@ var RemoteAttachmentUploadFactory = class {
|
|
|
774
546
|
};
|
|
775
547
|
//#endregion
|
|
776
548
|
//#region src/switchboard/remote-attachment-store.ts
|
|
549
|
+
const MISSING_DOCUMENT_ID = "Remote attachment reads require the documentId whose operations reference the attachment";
|
|
777
550
|
function isRecord(value) {
|
|
778
551
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
779
552
|
}
|
|
@@ -865,8 +638,9 @@ var RemoteAttachmentStore = class {
|
|
|
865
638
|
* header (degraded wire), throws AttachmentPending instead -- the
|
|
866
639
|
* AttachmentPending throw is the degraded-wire case.
|
|
867
640
|
*/
|
|
868
|
-
async stat(hash) {
|
|
869
|
-
|
|
641
|
+
async stat(hash, documentId) {
|
|
642
|
+
if (documentId === void 0) throw new AttachmentNotFound(hash);
|
|
643
|
+
const url = `${this.remoteUrl}/attachments/${hash}?documentId=${encodeURIComponent(documentId)}`;
|
|
870
644
|
const authHeaders = await buildAuthHeaders(url, this.jwtHandler);
|
|
871
645
|
const response = await this.fetchFn(url, {
|
|
872
646
|
method: "HEAD",
|
|
@@ -884,13 +658,13 @@ var RemoteAttachmentStore = class {
|
|
|
884
658
|
return buildHeader(hash, parseMetadata(response));
|
|
885
659
|
}
|
|
886
660
|
async get(hash, signal, documentId) {
|
|
887
|
-
if (documentId === void 0)
|
|
661
|
+
if (documentId === void 0) throw new Error(MISSING_DOCUMENT_ID);
|
|
888
662
|
const target = await this.getDownloadTarget(hash, {
|
|
889
663
|
documentId,
|
|
890
664
|
signal
|
|
891
665
|
});
|
|
892
666
|
if (target.kind === "presigned-get") return this.fetchPresigned(hash, target, signal);
|
|
893
|
-
return this.fetchAttachment(hash,
|
|
667
|
+
return this.fetchAttachment(hash, target, signal);
|
|
894
668
|
}
|
|
895
669
|
/**
|
|
896
670
|
* Asks Switchboard for an authorized download target. The request carries
|
|
@@ -936,11 +710,11 @@ var RemoteAttachmentStore = class {
|
|
|
936
710
|
body: response.body
|
|
937
711
|
};
|
|
938
712
|
}
|
|
939
|
-
async fetchAttachment(hash,
|
|
940
|
-
const url = target
|
|
713
|
+
async fetchAttachment(hash, target, signal) {
|
|
714
|
+
const url = target.url;
|
|
941
715
|
const authHeaders = await buildAuthHeaders(url, this.jwtHandler);
|
|
942
716
|
const headers = {
|
|
943
|
-
...target
|
|
717
|
+
...target.headers,
|
|
944
718
|
...authHeaders
|
|
945
719
|
};
|
|
946
720
|
const response = await this.fetchFn(url, {
|
|
@@ -1015,6 +789,43 @@ var NullAttachmentTransport = class {
|
|
|
1015
789
|
}
|
|
1016
790
|
};
|
|
1017
791
|
//#endregion
|
|
1018
|
-
|
|
792
|
+
//#region src/routing/routing-attachment-service.ts
|
|
793
|
+
/** Routes by `documentId` to its backend's service; anything unroutable goes to `fallback`. */
|
|
794
|
+
var RoutingAttachmentService = class {
|
|
795
|
+
resolve;
|
|
796
|
+
byBackend;
|
|
797
|
+
fallback;
|
|
798
|
+
constructor(resolve, byBackend, fallback) {
|
|
799
|
+
this.resolve = resolve;
|
|
800
|
+
this.byBackend = byBackend;
|
|
801
|
+
this.fallback = fallback;
|
|
802
|
+
}
|
|
803
|
+
async reserve(options) {
|
|
804
|
+
const { documentId, ...rest } = options;
|
|
805
|
+
return (await this.serviceFor(documentId)).reserve(rest);
|
|
806
|
+
}
|
|
807
|
+
async stat(ref, options) {
|
|
808
|
+
return (await this.serviceFor(options?.documentId)).stat(ref, options);
|
|
809
|
+
}
|
|
810
|
+
async get(ref, options) {
|
|
811
|
+
return (options === void 0 || options instanceof AbortSignal ? this.fallback : await this.serviceFor(options.documentId, options.signal)).get(ref, options);
|
|
812
|
+
}
|
|
813
|
+
async getDownloadTarget(ref, options) {
|
|
814
|
+
return (await this.serviceFor(options.documentId, options.signal)).getDownloadTarget(ref, options);
|
|
815
|
+
}
|
|
816
|
+
async serviceFor(documentId, signal) {
|
|
817
|
+
if (documentId === void 0) return this.fallback;
|
|
818
|
+
let backend;
|
|
819
|
+
try {
|
|
820
|
+
backend = await this.resolve(documentId, signal);
|
|
821
|
+
} catch (error) {
|
|
822
|
+
if (signal?.aborted) throw error;
|
|
823
|
+
return this.fallback;
|
|
824
|
+
}
|
|
825
|
+
return this.byBackend.get(backend) ?? this.fallback;
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
//#endregion
|
|
829
|
+
export { RemoteAttachmentUploadFactory as a, createXhrUploadTransport as c, isBlob as d, AttachmentService as f, RemoteAttachmentStore as i, createFetchUploadTransport as l, parseAttachmentUploadTarget as m, NullAttachmentTransport as n, RemoteAttachmentUpload as o, parseAttachmentDownloadTarget as p, createRemoteAttachmentService as r, RemoteReservationStore as s, RoutingAttachmentService as t, blobStream as u };
|
|
1019
830
|
|
|
1020
|
-
//# sourceMappingURL=
|
|
831
|
+
//# sourceMappingURL=routing-attachment-service-C88ryRgj.js.map
|