@puzzle-ui/media 0.0.0-stage → 0.16.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/README.md +305 -2
- package/ai/instructions.md +70 -0
- package/ai/manifest.json +10 -0
- package/dist/LICENSE +21 -0
- package/dist/adapters-Bon320yF.js +481 -0
- package/dist/adapters-Bon320yF.js.map +1 -0
- package/dist/adapters-C4N2gqSK.d.cts +63 -0
- package/dist/adapters-DXycRsjJ.cjs +492 -0
- package/dist/adapters-DXycRsjJ.cjs.map +1 -0
- package/dist/adapters-DhPviL_C.d.ts +63 -0
- package/dist/browser/index.cjs +200 -0
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.d.cts +89 -0
- package/dist/browser/index.d.ts +89 -0
- package/dist/browser/index.js +195 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/image-processing-B1lRPpsg.cjs +444 -0
- package/dist/image-processing-B1lRPpsg.cjs.map +1 -0
- package/dist/image-processing-XkoQ8NT7.js +400 -0
- package/dist/image-processing-XkoQ8NT7.js.map +1 -0
- package/dist/image-worker.cjs +36 -0
- package/dist/image-worker.cjs.map +1 -0
- package/dist/image-worker.d.cts +1 -0
- package/dist/image-worker.d.ts +1 -0
- package/dist/image-worker.js +37 -0
- package/dist/image-worker.js.map +1 -0
- package/dist/index-8Seqy-LJ.d.ts +297 -0
- package/dist/index-BP0ikbAS.d.cts +297 -0
- package/dist/index.cjs +38 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/media-validation-By6karZu.cjs +361 -0
- package/dist/media-validation-By6karZu.cjs.map +1 -0
- package/dist/media-validation-OyjGVUq3.js +230 -0
- package/dist/media-validation-OyjGVUq3.js.map +1 -0
- package/dist/media.types-dzfu0Nep.d.cts +127 -0
- package/dist/media.types-dzfu0Nep.d.ts +127 -0
- package/dist/processing.types-CPaSB88L.d.ts +238 -0
- package/dist/processing.types-Dd2XT8Qr.d.cts +238 -0
- package/dist/src-8d6s1iWH.js +1286 -0
- package/dist/src-8d6s1iWH.js.map +1 -0
- package/dist/src-C7WU7ovP.cjs +1363 -0
- package/dist/src-C7WU7ovP.cjs.map +1 -0
- package/dist/testing/adapters.cjs +4 -0
- package/dist/testing/adapters.d.cts +2 -0
- package/dist/testing/adapters.d.ts +2 -0
- package/dist/testing/adapters.js +1 -0
- package/dist/testing/index.cjs +264 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +14 -0
- package/dist/testing/index.d.ts +14 -0
- package/dist/testing/index.js +260 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +84 -4
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
const require_media_validation = require("./media-validation-By6karZu.cjs");
|
|
2
|
+
// src/testing/in-memory-object-storage.ts
|
|
3
|
+
const cloneBytes = (bytes) => new Uint8Array(bytes);
|
|
4
|
+
const toHex = (value) => [...new Uint8Array(value)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
5
|
+
const checksumBytes = async (bytes) => {
|
|
6
|
+
if (!globalThis.crypto?.subtle) throw new require_media_validation.MediaObjectStorageError("Web Crypto is required by the test adapter.");
|
|
7
|
+
const input = new Uint8Array(bytes);
|
|
8
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", input);
|
|
9
|
+
return {
|
|
10
|
+
algorithm: "sha256",
|
|
11
|
+
value: toHex(digest)
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const validateConstraints = (input) => {
|
|
15
|
+
if (typeof input.tenantId !== "string" || input.tenantId.trim() === "") throw new require_media_validation.MediaValidationError("tenantId must be a non-empty string.");
|
|
16
|
+
if (typeof input.fileName !== "string" || input.fileName.trim() === "") throw new require_media_validation.MediaValidationError("fileName must be a non-empty string.");
|
|
17
|
+
if (typeof input.contentType !== "string" || !/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/i.test(input.contentType)) throw new require_media_validation.MediaValidationError("contentType must be a valid MIME type.");
|
|
18
|
+
if (input.expectedSize !== void 0 && (!Number.isSafeInteger(input.expectedSize) || input.expectedSize < 1)) throw new require_media_validation.MediaValidationError("expectedSize must be a positive safe integer.");
|
|
19
|
+
if (!Number.isInteger(input.expiresInMs) || input.expiresInMs < 1) throw new require_media_validation.MediaValidationError("expiresInMs must be a positive integer.");
|
|
20
|
+
if (input.expectedChecksum) require_media_validation.normalizeMediaChecksum(input.expectedChecksum);
|
|
21
|
+
};
|
|
22
|
+
var InMemoryMediaObjectStorageAdapter = class {
|
|
23
|
+
uploads = /* @__PURE__ */ new Map();
|
|
24
|
+
objects = /* @__PURE__ */ new Map();
|
|
25
|
+
objectBytes = /* @__PURE__ */ new Map();
|
|
26
|
+
nextId = 0;
|
|
27
|
+
idFactory;
|
|
28
|
+
now;
|
|
29
|
+
maxSignedUrlTtlMs;
|
|
30
|
+
constructor(options = {}) {
|
|
31
|
+
this.idFactory = options.idFactory ?? (() => {
|
|
32
|
+
this.nextId += 1;
|
|
33
|
+
return `memory-${this.nextId}`;
|
|
34
|
+
});
|
|
35
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
36
|
+
this.maxSignedUrlTtlMs = options.maxSignedUrlTtlMs ?? 9e5;
|
|
37
|
+
}
|
|
38
|
+
async createUploadIntent(input) {
|
|
39
|
+
validateConstraints(input);
|
|
40
|
+
const now = this.validNow();
|
|
41
|
+
const id = this.idFactory();
|
|
42
|
+
const object = this.makeObjectReference(input);
|
|
43
|
+
const expiresAt = new Date(now.getTime() + input.expiresInMs);
|
|
44
|
+
const session = {
|
|
45
|
+
id,
|
|
46
|
+
tenantId: input.tenantId,
|
|
47
|
+
mode: "single",
|
|
48
|
+
state: "pending",
|
|
49
|
+
...input.expectedSize !== void 0 ? { expectedSize: input.expectedSize } : {},
|
|
50
|
+
...input.expectedChecksum ? { expectedChecksum: require_media_validation.normalizeMediaChecksum(input.expectedChecksum) } : {},
|
|
51
|
+
expiresAt,
|
|
52
|
+
uploadTarget: this.makeTarget(id, input.expiresInMs, expiresAt)
|
|
53
|
+
};
|
|
54
|
+
this.uploads.set(id, {
|
|
55
|
+
session,
|
|
56
|
+
constraints: input,
|
|
57
|
+
object,
|
|
58
|
+
parts: /* @__PURE__ */ new Map(),
|
|
59
|
+
issuedParts: /* @__PURE__ */ new Set()
|
|
60
|
+
});
|
|
61
|
+
return session;
|
|
62
|
+
}
|
|
63
|
+
async createMultipartUpload(input) {
|
|
64
|
+
validateConstraints(input);
|
|
65
|
+
if (!Number.isSafeInteger(input.partSizeBytes) || input.partSizeBytes < 1) throw new require_media_validation.MediaValidationError("partSizeBytes must be a positive safe integer.");
|
|
66
|
+
if (input.expiresInMs > this.maxSignedUrlTtlMs) throw new require_media_validation.MediaValidationError("Upload target expiry exceeds the configured limit.");
|
|
67
|
+
const now = this.validNow();
|
|
68
|
+
const id = this.idFactory();
|
|
69
|
+
const object = this.makeObjectReference(input);
|
|
70
|
+
const expiresAt = new Date(now.getTime() + input.expiresInMs);
|
|
71
|
+
const session = {
|
|
72
|
+
id,
|
|
73
|
+
tenantId: input.tenantId,
|
|
74
|
+
mode: "multipart",
|
|
75
|
+
state: "pending",
|
|
76
|
+
...input.expectedSize !== void 0 ? { expectedSize: input.expectedSize } : {},
|
|
77
|
+
...input.expectedChecksum ? { expectedChecksum: require_media_validation.normalizeMediaChecksum(input.expectedChecksum) } : {},
|
|
78
|
+
expiresAt,
|
|
79
|
+
partSizeBytes: input.partSizeBytes
|
|
80
|
+
};
|
|
81
|
+
this.uploads.set(id, {
|
|
82
|
+
session,
|
|
83
|
+
constraints: input,
|
|
84
|
+
object,
|
|
85
|
+
partSizeBytes: input.partSizeBytes,
|
|
86
|
+
parts: /* @__PURE__ */ new Map(),
|
|
87
|
+
issuedParts: /* @__PURE__ */ new Set()
|
|
88
|
+
});
|
|
89
|
+
return session;
|
|
90
|
+
}
|
|
91
|
+
async createMultipartPartTargets(sessionId, partNumbers, expiresInMs) {
|
|
92
|
+
const upload = this.getPendingUpload(sessionId);
|
|
93
|
+
if (upload.session.mode !== "multipart") throw new require_media_validation.MediaAssetConflictError("The upload session is not multipart.");
|
|
94
|
+
if (!Number.isInteger(expiresInMs) || expiresInMs < 1 || expiresInMs > this.maxSignedUrlTtlMs) throw new require_media_validation.MediaValidationError("Part target expiry is outside the configured limit.");
|
|
95
|
+
if (partNumbers.length === 0) throw new require_media_validation.MediaValidationError("At least one multipart part target is required.");
|
|
96
|
+
const unique = /* @__PURE__ */ new Set();
|
|
97
|
+
return partNumbers.map((partNumber) => {
|
|
98
|
+
if (!Number.isInteger(partNumber) || partNumber < 1 || unique.has(partNumber)) throw new require_media_validation.MediaValidationError("Multipart part numbers must be unique positive integers.");
|
|
99
|
+
const expectedSize = upload.session.expectedSize;
|
|
100
|
+
const partSize = upload.partSizeBytes ?? 0;
|
|
101
|
+
if (expectedSize !== void 0 && partNumber > Math.ceil(expectedSize / partSize)) throw new require_media_validation.MediaValidationError("A multipart part number exceeds the expected upload size.");
|
|
102
|
+
unique.add(partNumber);
|
|
103
|
+
upload.issuedParts.add(partNumber);
|
|
104
|
+
const expiresAt = new Date(Math.min(this.validNow().getTime() + expiresInMs, upload.session.expiresAt.getTime()));
|
|
105
|
+
return {
|
|
106
|
+
partNumber,
|
|
107
|
+
url: `memory://multipart/${encodeURIComponent(sessionId)}/${partNumber}`,
|
|
108
|
+
method: "PUT",
|
|
109
|
+
headers: { "content-type": upload.constraints.contentType },
|
|
110
|
+
expiresAt
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async completeUpload(sessionId, parts) {
|
|
115
|
+
const upload = this.findUpload(sessionId);
|
|
116
|
+
if (!upload) throw new require_media_validation.MediaNotFoundError("Upload session");
|
|
117
|
+
if (upload.session.state === "completed" && upload.storedObject) return upload.storedObject;
|
|
118
|
+
this.assertPendingAndUnexpired(upload);
|
|
119
|
+
let bytes;
|
|
120
|
+
if (upload.session.mode === "single") {
|
|
121
|
+
if (!upload.bytes) throw new require_media_validation.MediaAssetConflictError("The single upload has no uploaded bytes.");
|
|
122
|
+
bytes = upload.bytes;
|
|
123
|
+
} else bytes = this.collectMultipartBytes(upload, parts);
|
|
124
|
+
if (upload.constraints.expectedSize !== void 0 && bytes.byteLength !== upload.constraints.expectedSize) throw new require_media_validation.MediaObjectStorageError("The uploaded byte count does not match the declared size.", { details: {
|
|
125
|
+
expectedSize: upload.constraints.expectedSize,
|
|
126
|
+
actualSize: bytes.byteLength
|
|
127
|
+
} });
|
|
128
|
+
const checksum = await checksumBytes(bytes);
|
|
129
|
+
if (upload.constraints.expectedChecksum && checksum.value !== require_media_validation.normalizeMediaChecksum(upload.constraints.expectedChecksum).value) throw new require_media_validation.MediaChecksumMismatchError();
|
|
130
|
+
const createdAt = this.validNow();
|
|
131
|
+
const stored = {
|
|
132
|
+
object: upload.object,
|
|
133
|
+
tenantId: upload.session.tenantId,
|
|
134
|
+
mimeType: upload.constraints.contentType.toLowerCase(),
|
|
135
|
+
size: bytes.byteLength,
|
|
136
|
+
checksum,
|
|
137
|
+
createdAt
|
|
138
|
+
};
|
|
139
|
+
upload.storedObject = stored;
|
|
140
|
+
upload.session = {
|
|
141
|
+
...upload.session,
|
|
142
|
+
state: "completed"
|
|
143
|
+
};
|
|
144
|
+
this.objects.set(this.refKey(upload.object), stored);
|
|
145
|
+
this.objectBytes.set(this.refKey(upload.object), cloneBytes(bytes));
|
|
146
|
+
return stored;
|
|
147
|
+
}
|
|
148
|
+
async abortUpload(sessionId) {
|
|
149
|
+
const upload = this.findUpload(sessionId);
|
|
150
|
+
if (!upload || upload.session.state === "completed" || upload.session.state === "aborted") return false;
|
|
151
|
+
upload.session = {
|
|
152
|
+
...upload.session,
|
|
153
|
+
state: "aborted"
|
|
154
|
+
};
|
|
155
|
+
upload.bytes = void 0;
|
|
156
|
+
upload.parts.clear();
|
|
157
|
+
upload.issuedParts.clear();
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
async getUploadSession(sessionId) {
|
|
161
|
+
const upload = this.findUpload(sessionId);
|
|
162
|
+
if (!upload) return null;
|
|
163
|
+
if (upload.session.state === "pending" && upload.session.expiresAt.getTime() <= this.validNow().getTime()) upload.session = {
|
|
164
|
+
...upload.session,
|
|
165
|
+
state: "expired"
|
|
166
|
+
};
|
|
167
|
+
return upload.session;
|
|
168
|
+
}
|
|
169
|
+
async getObjectMetadata(object) {
|
|
170
|
+
return this.objects.get(this.refKey(object)) ?? null;
|
|
171
|
+
}
|
|
172
|
+
async createReadTarget(object, expiresInMs) {
|
|
173
|
+
if (!this.objects.has(this.refKey(object))) throw new require_media_validation.MediaNotFoundError("Media object");
|
|
174
|
+
if (!Number.isInteger(expiresInMs) || expiresInMs < 1 || expiresInMs > this.maxSignedUrlTtlMs) throw new require_media_validation.MediaValidationError("Read target expiry is outside the configured limit.");
|
|
175
|
+
return {
|
|
176
|
+
url: `memory://read/${encodeURIComponent(object.key)}`,
|
|
177
|
+
expiresAt: new Date(this.validNow().getTime() + expiresInMs)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
async deleteObject(object) {
|
|
181
|
+
const key = this.refKey(object);
|
|
182
|
+
const existed = this.objects.delete(key);
|
|
183
|
+
this.objectBytes.delete(key);
|
|
184
|
+
return existed;
|
|
185
|
+
}
|
|
186
|
+
async listObjects(input) {
|
|
187
|
+
if (!Number.isInteger(input.first) || input.first < 1 || input.first > 1e3) throw new require_media_validation.MediaValidationError("Object list first must be from 1 to 1000.");
|
|
188
|
+
if (input.olderThan !== void 0 && !Number.isFinite(input.olderThan.getTime())) throw new require_media_validation.MediaValidationError("olderThan must be a valid date.");
|
|
189
|
+
const items = [...this.objects.values()].filter((item) => input.olderThan === void 0 || item.createdAt.getTime() < input.olderThan.getTime()).sort((left, right) => this.objectCursor(left.object).localeCompare(this.objectCursor(right.object)));
|
|
190
|
+
const cursor = input.cursor;
|
|
191
|
+
const startIndex = cursor ? items.findIndex((item) => this.objectCursor(item.object) > cursor) : 0;
|
|
192
|
+
const start = startIndex < 0 ? items.length : startIndex;
|
|
193
|
+
const page = items.slice(start, start + input.first);
|
|
194
|
+
const nextCursor = start + page.length < items.length ? page.at(-1) ? this.objectCursor(page.at(-1).object) : null : null;
|
|
195
|
+
return {
|
|
196
|
+
items: page.map((item) => ({
|
|
197
|
+
object: item.object,
|
|
198
|
+
tenantId: item.tenantId,
|
|
199
|
+
size: item.size,
|
|
200
|
+
mimeType: item.mimeType,
|
|
201
|
+
checksum: item.checksum,
|
|
202
|
+
createdAt: item.createdAt
|
|
203
|
+
})),
|
|
204
|
+
nextCursor
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
async listExpiredUploadSessions(before, first) {
|
|
208
|
+
if (!Number.isInteger(first) || first < 1 || first > 1e3) throw new require_media_validation.MediaValidationError("first must be from 1 to 1000.");
|
|
209
|
+
return [...this.uploads.values()].filter((upload) => (upload.session.state === "pending" || upload.session.state === "expired") && upload.session.expiresAt.getTime() <= before.getTime()).sort((left, right) => left.session.expiresAt.getTime() - right.session.expiresAt.getTime()).slice(0, first).map((upload) => upload.session);
|
|
210
|
+
}
|
|
211
|
+
async writeForTesting(sessionId, bytes, contentType) {
|
|
212
|
+
const upload = this.getPendingUpload(sessionId);
|
|
213
|
+
if (upload.session.mode !== "single") throw new require_media_validation.MediaAssetConflictError("The upload session is multipart.");
|
|
214
|
+
this.assertContentType(upload, contentType);
|
|
215
|
+
upload.bytes = cloneBytes(bytes);
|
|
216
|
+
}
|
|
217
|
+
async writePartForTesting(sessionId, partNumber, bytes) {
|
|
218
|
+
const upload = this.getPendingUpload(sessionId);
|
|
219
|
+
if (upload.session.mode !== "multipart") throw new require_media_validation.MediaAssetConflictError("The upload session is not multipart.");
|
|
220
|
+
if (!Number.isInteger(partNumber) || partNumber < 1) throw new require_media_validation.MediaValidationError("partNumber must be a positive integer.");
|
|
221
|
+
if (!upload.issuedParts.has(partNumber)) throw new require_media_validation.MediaAssetConflictError("A multipart part cannot be uploaded without an issued part target.");
|
|
222
|
+
const partSize = upload.partSizeBytes ?? 0;
|
|
223
|
+
if (bytes.byteLength < 1 || bytes.byteLength > partSize) throw new require_media_validation.MediaValidationError("Multipart part size is outside the configured range.");
|
|
224
|
+
if (upload.session.expectedSize !== void 0 && partNumber < Math.ceil(upload.session.expectedSize / (upload.partSizeBytes ?? 1)) && bytes.byteLength !== upload.partSizeBytes) throw new require_media_validation.MediaValidationError("All non-final multipart parts must have partSizeBytes.");
|
|
225
|
+
const copy = cloneBytes(bytes);
|
|
226
|
+
const etag = (await checksumBytes(copy)).value;
|
|
227
|
+
upload.parts.set(partNumber, {
|
|
228
|
+
bytes: copy,
|
|
229
|
+
etag
|
|
230
|
+
});
|
|
231
|
+
return {
|
|
232
|
+
partNumber,
|
|
233
|
+
etag
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
getBytesForTesting(object) {
|
|
237
|
+
const bytes = this.objectBytes.get(this.refKey(object));
|
|
238
|
+
return bytes ? cloneBytes(bytes) : null;
|
|
239
|
+
}
|
|
240
|
+
reset() {
|
|
241
|
+
this.uploads.clear();
|
|
242
|
+
this.objects.clear();
|
|
243
|
+
this.objectBytes.clear();
|
|
244
|
+
this.nextId = 0;
|
|
245
|
+
}
|
|
246
|
+
findUpload(sessionId) {
|
|
247
|
+
return this.uploads.get(sessionId);
|
|
248
|
+
}
|
|
249
|
+
getPendingUpload(sessionId) {
|
|
250
|
+
const upload = this.findUpload(sessionId);
|
|
251
|
+
if (!upload) throw new require_media_validation.MediaNotFoundError("Upload session");
|
|
252
|
+
this.assertPendingAndUnexpired(upload);
|
|
253
|
+
return upload;
|
|
254
|
+
}
|
|
255
|
+
assertPendingAndUnexpired(upload) {
|
|
256
|
+
if (upload.session.state === "aborted") throw new require_media_validation.MediaAssetConflictError("The upload session was aborted.");
|
|
257
|
+
if (upload.session.state === "completed") throw new require_media_validation.MediaAssetConflictError("The upload session is already complete.");
|
|
258
|
+
if (upload.session.expiresAt.getTime() <= this.validNow().getTime()) {
|
|
259
|
+
upload.session = {
|
|
260
|
+
...upload.session,
|
|
261
|
+
state: "expired"
|
|
262
|
+
};
|
|
263
|
+
throw new require_media_validation.MediaUploadExpiredError();
|
|
264
|
+
}
|
|
265
|
+
if (upload.session.state === "expired") throw new require_media_validation.MediaUploadExpiredError();
|
|
266
|
+
}
|
|
267
|
+
collectMultipartBytes(upload, completedParts) {
|
|
268
|
+
if (!completedParts?.length) throw new require_media_validation.MediaAssetConflictError("Multipart completion requires the uploaded part numbers and ETags.");
|
|
269
|
+
const sorted = [...completedParts].sort((left, right) => left.partNumber - right.partNumber);
|
|
270
|
+
if (sorted.some((part, index) => part.partNumber !== index + 1 || upload.parts.get(part.partNumber)?.etag !== part.etag)) throw new require_media_validation.MediaAssetConflictError("Multipart completion parts do not match the uploaded parts.");
|
|
271
|
+
const partSize = upload.partSizeBytes ?? 0;
|
|
272
|
+
if (sorted.some((part, index) => index < sorted.length - 1 && upload.parts.get(part.partNumber)?.bytes.byteLength !== partSize)) throw new require_media_validation.MediaAssetConflictError("Every multipart part except the final part must use the configured part size.");
|
|
273
|
+
const length = sorted.reduce((sum, part) => sum + (upload.parts.get(part.partNumber)?.bytes.length ?? 0), 0);
|
|
274
|
+
const result = new Uint8Array(length);
|
|
275
|
+
let offset = 0;
|
|
276
|
+
for (const part of sorted) {
|
|
277
|
+
const bytes = upload.parts.get(part.partNumber)?.bytes;
|
|
278
|
+
if (!bytes) throw new require_media_validation.MediaAssetConflictError("A multipart part is missing.");
|
|
279
|
+
result.set(bytes, offset);
|
|
280
|
+
offset += bytes.length;
|
|
281
|
+
}
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
assertContentType(upload, contentType) {
|
|
285
|
+
if (contentType.toLowerCase() !== upload.constraints.contentType.toLowerCase()) throw new require_media_validation.MediaValidationError("Uploaded MIME type differs from the upload intent.");
|
|
286
|
+
}
|
|
287
|
+
makeObjectReference(input) {
|
|
288
|
+
const objectPrefix = input.objectPrefix?.replace(/^\/+|\/+$/g, "");
|
|
289
|
+
if (objectPrefix !== void 0 && (objectPrefix === "" || objectPrefix.split("/").some((segment) => segment === "." || segment === "..") || /[\u0000-\u001f\u007f]/.test(objectPrefix))) throw new require_media_validation.MediaValidationError("objectPrefix must be a safe relative key prefix.");
|
|
290
|
+
return { key: `${objectPrefix ? `${objectPrefix}/` : ""}${encodeURIComponent(input.tenantId)}/${this.idFactory()}` };
|
|
291
|
+
}
|
|
292
|
+
makeTarget(sessionId, expiresInMs, expiresAt) {
|
|
293
|
+
if (expiresInMs > this.maxSignedUrlTtlMs) throw new require_media_validation.MediaValidationError("Upload target expiry exceeds the configured limit.");
|
|
294
|
+
return {
|
|
295
|
+
url: `memory://upload/${encodeURIComponent(sessionId)}`,
|
|
296
|
+
method: "PUT",
|
|
297
|
+
headers: {},
|
|
298
|
+
expiresAt
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
refKey(object) {
|
|
302
|
+
return `${object.key}\u0000${object.versionId ?? ""}`;
|
|
303
|
+
}
|
|
304
|
+
objectCursor(object) {
|
|
305
|
+
return this.refKey(object);
|
|
306
|
+
}
|
|
307
|
+
validNow() {
|
|
308
|
+
const now = this.now();
|
|
309
|
+
if (!(now instanceof Date) || !Number.isFinite(now.getTime())) throw new require_media_validation.MediaValidationError("The configured clock returned an invalid date.");
|
|
310
|
+
return now;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
// src/testing/in-memory-processing-queue.ts
|
|
314
|
+
var InMemoryMediaProcessingQueueAdapter = class {
|
|
315
|
+
jobs = /* @__PURE__ */ new Map();
|
|
316
|
+
idempotency = /* @__PURE__ */ new Map();
|
|
317
|
+
async enqueue(input) {
|
|
318
|
+
const key = `${input.tenantId}\u0000${input.idempotencyKey}`;
|
|
319
|
+
const existingId = this.idempotency.get(key);
|
|
320
|
+
if (existingId) {
|
|
321
|
+
const existing = this.jobs.get(existingId);
|
|
322
|
+
if (!existing) throw new require_media_validation.MediaAssetConflictError("Idempotency index is inconsistent.");
|
|
323
|
+
if (existing.assetId !== input.assetId || existing.kind !== input.kind || JSON.stringify(existing.profiles) !== JSON.stringify(input.profiles)) throw new require_media_validation.MediaAssetConflictError("An idempotency key cannot be reused for a different processing request.");
|
|
324
|
+
return existing;
|
|
325
|
+
}
|
|
326
|
+
if (!Number.isInteger(input.maxAttempts) || input.maxAttempts < 1 || !Number.isFinite(input.createdAt.getTime())) throw new require_media_validation.MediaValidationError("The processing job input is invalid.");
|
|
327
|
+
const availableAt = input.availableAt ?? input.createdAt;
|
|
328
|
+
if (!Number.isFinite(availableAt.getTime())) throw new require_media_validation.MediaValidationError("availableAt must be a valid date.");
|
|
329
|
+
const job = {
|
|
330
|
+
...input,
|
|
331
|
+
status: "queued",
|
|
332
|
+
attempt: 0,
|
|
333
|
+
progress: 0,
|
|
334
|
+
availableAt,
|
|
335
|
+
workerId: null,
|
|
336
|
+
leaseExpiresAt: null,
|
|
337
|
+
result: [],
|
|
338
|
+
failure: null,
|
|
339
|
+
updatedAt: input.createdAt,
|
|
340
|
+
completedAt: null,
|
|
341
|
+
revision: 1
|
|
342
|
+
};
|
|
343
|
+
this.jobs.set(job.id, job);
|
|
344
|
+
this.idempotency.set(key, job.id);
|
|
345
|
+
return job;
|
|
346
|
+
}
|
|
347
|
+
async get(id) {
|
|
348
|
+
return this.jobs.get(id) ?? null;
|
|
349
|
+
}
|
|
350
|
+
async claimNext(input) {
|
|
351
|
+
this.validateClaim(input);
|
|
352
|
+
for (const job of this.jobs.values()) {
|
|
353
|
+
const leaseExpired = job.status === "processing" && (job.leaseExpiresAt?.getTime() ?? Number.POSITIVE_INFINITY) <= input.now.getTime();
|
|
354
|
+
const retryExhausted = (job.status === "queued" || job.status === "retrying") && job.attempt >= job.maxAttempts;
|
|
355
|
+
if ((leaseExpired || retryExhausted) && job.attempt >= job.maxAttempts) this.save({
|
|
356
|
+
...job,
|
|
357
|
+
status: "dead-letter",
|
|
358
|
+
failure: {
|
|
359
|
+
message: "The processing attempt limit was reached.",
|
|
360
|
+
retryable: true
|
|
361
|
+
},
|
|
362
|
+
workerId: null,
|
|
363
|
+
leaseExpiresAt: null,
|
|
364
|
+
completedAt: input.now,
|
|
365
|
+
updatedAt: input.now,
|
|
366
|
+
revision: job.revision + 1
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
const job = [...this.jobs.values()].filter((job) => (job.status === "queued" || job.status === "retrying") && job.attempt < job.maxAttempts && job.availableAt.getTime() <= input.now.getTime() || job.status === "processing" && job.attempt < job.maxAttempts && (job.leaseExpiresAt?.getTime() ?? Number.POSITIVE_INFINITY) <= input.now.getTime()).sort((left, right) => left.availableAt.getTime() - right.availableAt.getTime() || left.createdAt.getTime() - right.createdAt.getTime())[0];
|
|
370
|
+
if (!job) return null;
|
|
371
|
+
const claimed = {
|
|
372
|
+
...job,
|
|
373
|
+
status: "processing",
|
|
374
|
+
attempt: job.attempt + 1,
|
|
375
|
+
progress: 0,
|
|
376
|
+
workerId: input.workerId,
|
|
377
|
+
leaseExpiresAt: new Date(input.now.getTime() + input.leaseDurationMs),
|
|
378
|
+
updatedAt: input.now,
|
|
379
|
+
failure: null,
|
|
380
|
+
revision: job.revision + 1
|
|
381
|
+
};
|
|
382
|
+
this.jobs.set(job.id, claimed);
|
|
383
|
+
return claimed;
|
|
384
|
+
}
|
|
385
|
+
async updateProgress(id, workerId, progress, now) {
|
|
386
|
+
const job = this.getProcessingJob(id);
|
|
387
|
+
this.assertWorker(job, workerId);
|
|
388
|
+
if (!Number.isFinite(progress) || progress < job.progress || progress > 100) throw new require_media_validation.MediaValidationError("Processing progress must be monotonic and from 0 to 100.");
|
|
389
|
+
return this.save({
|
|
390
|
+
...job,
|
|
391
|
+
progress,
|
|
392
|
+
updatedAt: now,
|
|
393
|
+
revision: job.revision + 1
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
async renewLease(id, workerId, leaseDurationMs, now) {
|
|
397
|
+
const job = this.getProcessingJob(id);
|
|
398
|
+
if (job.workerId !== workerId) throw new require_media_validation.MediaAssetConflictError("Only the worker holding the processing lease can renew it.");
|
|
399
|
+
if (!Number.isInteger(leaseDurationMs) || leaseDurationMs < 1 || !Number.isFinite(now.getTime()) || (job.leaseExpiresAt?.getTime() ?? 0) <= now.getTime()) throw new require_media_validation.MediaValidationError("The processing lease cannot be renewed.");
|
|
400
|
+
return this.save({
|
|
401
|
+
...job,
|
|
402
|
+
leaseExpiresAt: new Date(now.getTime() + leaseDurationMs),
|
|
403
|
+
updatedAt: now,
|
|
404
|
+
revision: job.revision + 1
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
async complete(id, workerId, result, now) {
|
|
408
|
+
const job = this.getProcessingJob(id);
|
|
409
|
+
this.assertWorker(job, workerId);
|
|
410
|
+
return this.save({
|
|
411
|
+
...job,
|
|
412
|
+
status: "succeeded",
|
|
413
|
+
progress: 100,
|
|
414
|
+
result: result ?? [],
|
|
415
|
+
failure: null,
|
|
416
|
+
workerId: null,
|
|
417
|
+
leaseExpiresAt: null,
|
|
418
|
+
completedAt: now,
|
|
419
|
+
updatedAt: now,
|
|
420
|
+
revision: job.revision + 1
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
async fail(id, workerId, failure, retryAt, now) {
|
|
424
|
+
const job = this.getProcessingJob(id);
|
|
425
|
+
this.assertWorker(job, workerId);
|
|
426
|
+
if (retryAt && (!failure.retryable || retryAt.getTime() <= now.getTime())) throw new require_media_validation.MediaValidationError("A retry time is only valid for a retryable failure in the future.");
|
|
427
|
+
const retry = retryAt !== null && job.attempt < job.maxAttempts;
|
|
428
|
+
return this.save({
|
|
429
|
+
...job,
|
|
430
|
+
status: retry ? "retrying" : failure.retryable ? "dead-letter" : "failed",
|
|
431
|
+
availableAt: retry ? retryAt : job.availableAt,
|
|
432
|
+
progress: retry ? 0 : job.progress,
|
|
433
|
+
failure,
|
|
434
|
+
workerId: null,
|
|
435
|
+
leaseExpiresAt: null,
|
|
436
|
+
completedAt: retry ? null : now,
|
|
437
|
+
updatedAt: now,
|
|
438
|
+
revision: job.revision + 1
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
async cancel(id, now) {
|
|
442
|
+
const job = this.jobs.get(id);
|
|
443
|
+
if (!job || this.isTerminal(job.status)) return null;
|
|
444
|
+
return this.save({
|
|
445
|
+
...job,
|
|
446
|
+
status: "cancelled",
|
|
447
|
+
workerId: null,
|
|
448
|
+
leaseExpiresAt: null,
|
|
449
|
+
completedAt: now,
|
|
450
|
+
updatedAt: now,
|
|
451
|
+
revision: job.revision + 1
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
reset() {
|
|
455
|
+
this.jobs.clear();
|
|
456
|
+
this.idempotency.clear();
|
|
457
|
+
}
|
|
458
|
+
getProcessingJob(id) {
|
|
459
|
+
const job = this.jobs.get(id);
|
|
460
|
+
if (!job) throw new require_media_validation.MediaNotFoundError("Processing job");
|
|
461
|
+
if (job.status !== "processing") throw new require_media_validation.MediaAssetConflictError(`Processing job cannot be updated while its status is "${job.status}".`);
|
|
462
|
+
return job;
|
|
463
|
+
}
|
|
464
|
+
save(job) {
|
|
465
|
+
this.jobs.set(job.id, job);
|
|
466
|
+
return job;
|
|
467
|
+
}
|
|
468
|
+
assertWorker(job, workerId) {
|
|
469
|
+
if (job.workerId !== workerId) throw new require_media_validation.MediaAssetConflictError("Only the worker holding the processing lease can update this job.");
|
|
470
|
+
}
|
|
471
|
+
validateClaim(input) {
|
|
472
|
+
if (typeof input.workerId !== "string" || input.workerId.trim() === "") throw new require_media_validation.MediaValidationError("workerId must be a non-empty string.");
|
|
473
|
+
if (!Number.isInteger(input.leaseDurationMs) || input.leaseDurationMs < 1 || !Number.isFinite(input.now.getTime())) throw new require_media_validation.MediaValidationError("Processing lease configuration is invalid.");
|
|
474
|
+
}
|
|
475
|
+
isTerminal(status) {
|
|
476
|
+
return status === "succeeded" || status === "failed" || status === "dead-letter" || status === "cancelled";
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
Object.defineProperty(exports, "InMemoryMediaObjectStorageAdapter", {
|
|
480
|
+
enumerable: true,
|
|
481
|
+
get: function() {
|
|
482
|
+
return InMemoryMediaObjectStorageAdapter;
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
Object.defineProperty(exports, "InMemoryMediaProcessingQueueAdapter", {
|
|
486
|
+
enumerable: true,
|
|
487
|
+
get: function() {
|
|
488
|
+
return InMemoryMediaProcessingQueueAdapter;
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
//# sourceMappingURL=adapters-DXycRsjJ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters-DXycRsjJ.cjs","names":["MediaObjectStorageError","MediaValidationError","normalizeMediaChecksum","MediaAssetConflictError","MediaNotFoundError","MediaChecksumMismatchError","MediaUploadExpiredError","MediaAssetConflictError","MediaValidationError","MediaNotFoundError"],"sources":["../src/testing/in-memory-object-storage.ts","../src/testing/in-memory-processing-queue.ts"],"sourcesContent":["import {\n MediaAssetConflictError,\n MediaChecksumMismatchError,\n MediaNotFoundError,\n MediaObjectStorageError,\n MediaUploadExpiredError,\n MediaValidationError,\n} from \"../errors/media.errors\";\nimport type {\n MediaChecksum,\n MediaObjectReference,\n} from \"../types/media.types\";\nimport type {\n MediaMultipartCompletedPart,\n MediaMultipartPartTarget,\n MediaObjectListInput,\n MediaObjectPage,\n MediaObjectSummary,\n MediaObjectStorageAdapter,\n MediaReadTarget,\n MediaStoredObject,\n MediaUploadConstraints,\n MediaUploadSession,\n MediaUploadTarget,\n} from \"../types/object-storage.types\";\nimport { normalizeMediaChecksum } from \"../utils/media-validation\";\n\ntype StoredPart = {\n readonly bytes: Uint8Array;\n readonly etag: string;\n};\n\ntype InMemoryUpload = {\n session: MediaUploadSession;\n readonly constraints: MediaUploadConstraints;\n readonly object: MediaObjectReference;\n readonly partSizeBytes?: number;\n readonly parts: Map<number, StoredPart>;\n readonly issuedParts: Set<number>;\n bytes?: Uint8Array;\n storedObject?: MediaStoredObject;\n};\n\nexport type InMemoryMediaObjectStorageOptions = {\n readonly idFactory?: () => string;\n readonly now?: () => Date;\n readonly maxSignedUrlTtlMs?: number;\n};\n\nconst cloneBytes = (bytes: Uint8Array): Uint8Array => new Uint8Array(bytes);\n\nconst toHex = (value: ArrayBuffer): string =>\n [...new Uint8Array(value)]\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n\nconst checksumBytes = async (bytes: Uint8Array): Promise<MediaChecksum> => {\n if (!globalThis.crypto?.subtle) {\n throw new MediaObjectStorageError(\"Web Crypto is required by the test adapter.\");\n }\n const input = new Uint8Array(bytes);\n const digest = await globalThis.crypto.subtle.digest(\"SHA-256\", input);\n return { algorithm: \"sha256\", value: toHex(digest) };\n};\n\nconst validateConstraints = (input: MediaUploadConstraints): void => {\n if (typeof input.tenantId !== \"string\" || input.tenantId.trim() === \"\") {\n throw new MediaValidationError(\"tenantId must be a non-empty string.\");\n }\n if (typeof input.fileName !== \"string\" || input.fileName.trim() === \"\") {\n throw new MediaValidationError(\"fileName must be a non-empty string.\");\n }\n if (\n typeof input.contentType !== \"string\" ||\n !/^[a-z0-9!#$&^_.+-]+\\/[a-z0-9!#$&^_.+-]+$/i.test(input.contentType)\n ) {\n throw new MediaValidationError(\"contentType must be a valid MIME type.\");\n }\n if (\n input.expectedSize !== undefined &&\n (!Number.isSafeInteger(input.expectedSize) || input.expectedSize < 1)\n ) {\n throw new MediaValidationError(\"expectedSize must be a positive safe integer.\");\n }\n if (!Number.isInteger(input.expiresInMs) || input.expiresInMs < 1) {\n throw new MediaValidationError(\"expiresInMs must be a positive integer.\");\n }\n if (input.expectedChecksum) normalizeMediaChecksum(input.expectedChecksum);\n};\n\nexport class InMemoryMediaObjectStorageAdapter\n implements MediaObjectStorageAdapter\n{\n private readonly uploads = new Map<string, InMemoryUpload>();\n private readonly objects = new Map<string, MediaStoredObject>();\n private readonly objectBytes = new Map<string, Uint8Array>();\n private nextId = 0;\n private readonly idFactory: () => string;\n private readonly now: () => Date;\n private readonly maxSignedUrlTtlMs: number;\n\n constructor(options: InMemoryMediaObjectStorageOptions = {}) {\n this.idFactory =\n options.idFactory ??\n (() => {\n this.nextId += 1;\n return `memory-${this.nextId}`;\n });\n this.now = options.now ?? (() => new Date());\n this.maxSignedUrlTtlMs = options.maxSignedUrlTtlMs ?? 15 * 60 * 1000;\n }\n\n async createUploadIntent(\n input: MediaUploadConstraints,\n ): Promise<MediaUploadSession> {\n validateConstraints(input);\n const now = this.validNow();\n const id = this.idFactory();\n const object = this.makeObjectReference(input);\n const expiresAt = new Date(now.getTime() + input.expiresInMs);\n const session: MediaUploadSession = {\n id,\n tenantId: input.tenantId,\n mode: \"single\",\n state: \"pending\",\n ...(input.expectedSize !== undefined\n ? { expectedSize: input.expectedSize }\n : {}),\n ...(input.expectedChecksum\n ? { expectedChecksum: normalizeMediaChecksum(input.expectedChecksum) }\n : {}),\n expiresAt,\n uploadTarget: this.makeTarget(id, input.expiresInMs, expiresAt),\n };\n this.uploads.set(id, {\n session,\n constraints: input,\n object,\n parts: new Map(),\n issuedParts: new Set(),\n });\n return session;\n }\n\n async createMultipartUpload(\n input: MediaUploadConstraints & { readonly partSizeBytes: number },\n ): Promise<MediaUploadSession> {\n validateConstraints(input);\n if (!Number.isSafeInteger(input.partSizeBytes) || input.partSizeBytes < 1) {\n throw new MediaValidationError(\"partSizeBytes must be a positive safe integer.\");\n }\n if (input.expiresInMs > this.maxSignedUrlTtlMs) {\n throw new MediaValidationError(\"Upload target expiry exceeds the configured limit.\");\n }\n const now = this.validNow();\n const id = this.idFactory();\n const object = this.makeObjectReference(input);\n const expiresAt = new Date(now.getTime() + input.expiresInMs);\n const session: MediaUploadSession = {\n id,\n tenantId: input.tenantId,\n mode: \"multipart\",\n state: \"pending\",\n ...(input.expectedSize !== undefined\n ? { expectedSize: input.expectedSize }\n : {}),\n ...(input.expectedChecksum\n ? { expectedChecksum: normalizeMediaChecksum(input.expectedChecksum) }\n : {}),\n expiresAt,\n partSizeBytes: input.partSizeBytes,\n };\n this.uploads.set(id, {\n session,\n constraints: input,\n object,\n partSizeBytes: input.partSizeBytes,\n parts: new Map(),\n issuedParts: new Set(),\n });\n return session;\n }\n\n async createMultipartPartTargets(\n sessionId: string,\n partNumbers: readonly number[],\n expiresInMs: number,\n ): Promise<readonly MediaMultipartPartTarget[]> {\n const upload = this.getPendingUpload(sessionId);\n if (upload.session.mode !== \"multipart\") {\n throw new MediaAssetConflictError(\"The upload session is not multipart.\");\n }\n if (\n !Number.isInteger(expiresInMs) ||\n expiresInMs < 1 ||\n expiresInMs > this.maxSignedUrlTtlMs\n ) {\n throw new MediaValidationError(\"Part target expiry is outside the configured limit.\");\n }\n if (partNumbers.length === 0) {\n throw new MediaValidationError(\"At least one multipart part target is required.\");\n }\n const unique = new Set<number>();\n return partNumbers.map((partNumber) => {\n if (!Number.isInteger(partNumber) || partNumber < 1 || unique.has(partNumber)) {\n throw new MediaValidationError(\n \"Multipart part numbers must be unique positive integers.\",\n );\n }\n const expectedSize = upload.session.expectedSize;\n const partSize = upload.partSizeBytes ?? 0;\n if (\n expectedSize !== undefined &&\n partNumber > Math.ceil(expectedSize / partSize)\n ) {\n throw new MediaValidationError(\"A multipart part number exceeds the expected upload size.\");\n }\n unique.add(partNumber);\n upload.issuedParts.add(partNumber);\n const expiresAt = new Date(\n Math.min(\n this.validNow().getTime() + expiresInMs,\n upload.session.expiresAt.getTime(),\n ),\n );\n return {\n partNumber,\n url: `memory://multipart/${encodeURIComponent(sessionId)}/${partNumber}`,\n method: \"PUT\",\n headers: { \"content-type\": upload.constraints.contentType },\n expiresAt,\n };\n });\n }\n\n async completeUpload(\n sessionId: string,\n parts?: readonly MediaMultipartCompletedPart[],\n ): Promise<MediaStoredObject> {\n const upload = this.findUpload(sessionId);\n if (!upload) throw new MediaNotFoundError(\"Upload session\");\n if (upload.session.state === \"completed\" && upload.storedObject) {\n return upload.storedObject;\n }\n this.assertPendingAndUnexpired(upload);\n let bytes: Uint8Array;\n if (upload.session.mode === \"single\") {\n if (!upload.bytes) {\n throw new MediaAssetConflictError(\"The single upload has no uploaded bytes.\");\n }\n bytes = upload.bytes;\n } else {\n bytes = this.collectMultipartBytes(upload, parts);\n }\n if (\n upload.constraints.expectedSize !== undefined &&\n bytes.byteLength !== upload.constraints.expectedSize\n ) {\n throw new MediaObjectStorageError(\n \"The uploaded byte count does not match the declared size.\",\n { details: { expectedSize: upload.constraints.expectedSize, actualSize: bytes.byteLength } },\n );\n }\n const checksum = await checksumBytes(bytes);\n if (\n upload.constraints.expectedChecksum &&\n checksum.value !==\n normalizeMediaChecksum(upload.constraints.expectedChecksum).value\n ) {\n throw new MediaChecksumMismatchError();\n }\n const createdAt = this.validNow();\n const stored: MediaStoredObject = {\n object: upload.object,\n tenantId: upload.session.tenantId,\n mimeType: upload.constraints.contentType.toLowerCase(),\n size: bytes.byteLength,\n checksum,\n createdAt,\n };\n upload.storedObject = stored;\n upload.session = { ...upload.session, state: \"completed\" };\n this.objects.set(this.refKey(upload.object), stored);\n this.objectBytes.set(this.refKey(upload.object), cloneBytes(bytes));\n return stored;\n }\n\n async abortUpload(sessionId: string): Promise<boolean> {\n const upload = this.findUpload(sessionId);\n if (!upload || upload.session.state === \"completed\" || upload.session.state === \"aborted\") {\n return false;\n }\n upload.session = { ...upload.session, state: \"aborted\" };\n upload.bytes = undefined;\n upload.parts.clear();\n upload.issuedParts.clear();\n return true;\n }\n\n async getUploadSession(sessionId: string): Promise<MediaUploadSession | null> {\n const upload = this.findUpload(sessionId);\n if (!upload) return null;\n if (\n upload.session.state === \"pending\" &&\n upload.session.expiresAt.getTime() <= this.validNow().getTime()\n ) {\n upload.session = { ...upload.session, state: \"expired\" };\n }\n return upload.session;\n }\n\n async getObjectMetadata(\n object: MediaObjectReference,\n ): Promise<MediaStoredObject | null> {\n return this.objects.get(this.refKey(object)) ?? null;\n }\n\n async createReadTarget(\n object: MediaObjectReference,\n expiresInMs: number,\n ): Promise<MediaReadTarget> {\n if (!this.objects.has(this.refKey(object))) {\n throw new MediaNotFoundError(\"Media object\");\n }\n if (\n !Number.isInteger(expiresInMs) ||\n expiresInMs < 1 ||\n expiresInMs > this.maxSignedUrlTtlMs\n ) {\n throw new MediaValidationError(\"Read target expiry is outside the configured limit.\");\n }\n return {\n url: `memory://read/${encodeURIComponent(object.key)}`,\n expiresAt: new Date(this.validNow().getTime() + expiresInMs),\n };\n }\n\n async deleteObject(object: MediaObjectReference): Promise<boolean> {\n const key = this.refKey(object);\n const existed = this.objects.delete(key);\n this.objectBytes.delete(key);\n return existed;\n }\n\n async listObjects(input: MediaObjectListInput): Promise<MediaObjectPage> {\n if (!Number.isInteger(input.first) || input.first < 1 || input.first > 1000) {\n throw new MediaValidationError(\"Object list first must be from 1 to 1000.\");\n }\n if (\n input.olderThan !== undefined &&\n !Number.isFinite(input.olderThan.getTime())\n ) {\n throw new MediaValidationError(\"olderThan must be a valid date.\");\n }\n const items = [...this.objects.values()]\n .filter(\n (item) =>\n input.olderThan === undefined ||\n item.createdAt.getTime() < input.olderThan.getTime(),\n )\n .sort((left, right) =>\n this.objectCursor(left.object).localeCompare(this.objectCursor(right.object)),\n );\n const cursor = input.cursor;\n const startIndex = cursor\n ? items.findIndex((item) => this.objectCursor(item.object) > cursor)\n : 0;\n const start = startIndex < 0 ? items.length : startIndex;\n const page = items.slice(start, start + input.first);\n const nextCursor =\n start + page.length < items.length\n ? (page.at(-1) ? this.objectCursor(page.at(-1)!.object) : null)\n : null;\n const summaries: MediaObjectSummary[] = page.map((item) => ({\n object: item.object,\n tenantId: item.tenantId,\n size: item.size,\n mimeType: item.mimeType,\n checksum: item.checksum,\n createdAt: item.createdAt,\n }));\n return { items: summaries, nextCursor };\n }\n\n async listExpiredUploadSessions(\n before: Date,\n first: number,\n ): Promise<readonly MediaUploadSession[]> {\n if (!Number.isInteger(first) || first < 1 || first > 1000) {\n throw new MediaValidationError(\"first must be from 1 to 1000.\");\n }\n return [...this.uploads.values()]\n .filter(\n (upload) =>\n (upload.session.state === \"pending\" ||\n upload.session.state === \"expired\") &&\n upload.session.expiresAt.getTime() <= before.getTime(),\n )\n .sort(\n (left, right) =>\n left.session.expiresAt.getTime() - right.session.expiresAt.getTime(),\n )\n .slice(0, first)\n .map((upload) => upload.session);\n }\n\n async writeForTesting(\n sessionId: string,\n bytes: Uint8Array,\n contentType: string,\n ): Promise<void> {\n const upload = this.getPendingUpload(sessionId);\n if (upload.session.mode !== \"single\") {\n throw new MediaAssetConflictError(\"The upload session is multipart.\");\n }\n this.assertContentType(upload, contentType);\n upload.bytes = cloneBytes(bytes);\n }\n\n async writePartForTesting(\n sessionId: string,\n partNumber: number,\n bytes: Uint8Array,\n ): Promise<MediaMultipartCompletedPart> {\n const upload = this.getPendingUpload(sessionId);\n if (upload.session.mode !== \"multipart\") {\n throw new MediaAssetConflictError(\"The upload session is not multipart.\");\n }\n if (!Number.isInteger(partNumber) || partNumber < 1) {\n throw new MediaValidationError(\"partNumber must be a positive integer.\");\n }\n if (!upload.issuedParts.has(partNumber)) {\n throw new MediaAssetConflictError(\n \"A multipart part cannot be uploaded without an issued part target.\",\n );\n }\n const partSize = upload.partSizeBytes ?? 0;\n if (bytes.byteLength < 1 || bytes.byteLength > partSize) {\n throw new MediaValidationError(\"Multipart part size is outside the configured range.\");\n }\n if (\n upload.session.expectedSize !== undefined &&\n partNumber < Math.ceil(upload.session.expectedSize / (upload.partSizeBytes ?? 1)) &&\n bytes.byteLength !== upload.partSizeBytes\n ) {\n throw new MediaValidationError(\"All non-final multipart parts must have partSizeBytes.\");\n }\n const copy = cloneBytes(bytes);\n const etag = (await checksumBytes(copy)).value;\n upload.parts.set(partNumber, { bytes: copy, etag });\n return { partNumber, etag };\n }\n\n getBytesForTesting(object: MediaObjectReference): Uint8Array | null {\n const bytes = this.objectBytes.get(this.refKey(object));\n return bytes ? cloneBytes(bytes) : null;\n }\n\n reset(): void {\n this.uploads.clear();\n this.objects.clear();\n this.objectBytes.clear();\n this.nextId = 0;\n }\n\n private findUpload(sessionId: string): InMemoryUpload | undefined {\n return this.uploads.get(sessionId);\n }\n\n private getPendingUpload(sessionId: string): InMemoryUpload {\n const upload = this.findUpload(sessionId);\n if (!upload) throw new MediaNotFoundError(\"Upload session\");\n this.assertPendingAndUnexpired(upload);\n return upload;\n }\n\n private assertPendingAndUnexpired(upload: InMemoryUpload): void {\n if (upload.session.state === \"aborted\") {\n throw new MediaAssetConflictError(\"The upload session was aborted.\");\n }\n if (upload.session.state === \"completed\") {\n throw new MediaAssetConflictError(\"The upload session is already complete.\");\n }\n if (upload.session.expiresAt.getTime() <= this.validNow().getTime()) {\n upload.session = { ...upload.session, state: \"expired\" };\n throw new MediaUploadExpiredError();\n }\n if (upload.session.state === \"expired\") {\n throw new MediaUploadExpiredError();\n }\n }\n\n private collectMultipartBytes(\n upload: InMemoryUpload,\n completedParts: readonly MediaMultipartCompletedPart[] | undefined,\n ): Uint8Array {\n if (!completedParts?.length) {\n throw new MediaAssetConflictError(\n \"Multipart completion requires the uploaded part numbers and ETags.\",\n );\n }\n const sorted = [...completedParts].sort(\n (left, right) => left.partNumber - right.partNumber,\n );\n if (\n sorted.some(\n (part, index) =>\n part.partNumber !== index + 1 ||\n upload.parts.get(part.partNumber)?.etag !== part.etag,\n )\n ) {\n throw new MediaAssetConflictError(\n \"Multipart completion parts do not match the uploaded parts.\",\n );\n }\n const partSize = upload.partSizeBytes ?? 0;\n if (\n sorted.some(\n (part, index) =>\n index < sorted.length - 1 &&\n upload.parts.get(part.partNumber)?.bytes.byteLength !== partSize,\n )\n ) {\n throw new MediaAssetConflictError(\n \"Every multipart part except the final part must use the configured part size.\",\n );\n }\n const length = sorted.reduce(\n (sum, part) => sum + (upload.parts.get(part.partNumber)?.bytes.length ?? 0),\n 0,\n );\n const result = new Uint8Array(length);\n let offset = 0;\n for (const part of sorted) {\n const bytes = upload.parts.get(part.partNumber)?.bytes;\n if (!bytes) throw new MediaAssetConflictError(\"A multipart part is missing.\");\n result.set(bytes, offset);\n offset += bytes.length;\n }\n return result;\n }\n\n private assertContentType(upload: InMemoryUpload, contentType: string): void {\n if (contentType.toLowerCase() !== upload.constraints.contentType.toLowerCase()) {\n throw new MediaValidationError(\"Uploaded MIME type differs from the upload intent.\");\n }\n }\n\n private makeObjectReference(input: MediaUploadConstraints): MediaObjectReference {\n const objectPrefix = input.objectPrefix?.replace(/^\\/+|\\/+$/g, \"\");\n if (\n objectPrefix !== undefined &&\n (objectPrefix === \"\" ||\n objectPrefix.split(\"/\").some((segment) => segment === \".\" || segment === \"..\") ||\n /[\\u0000-\\u001f\\u007f]/.test(objectPrefix))\n ) {\n throw new MediaValidationError(\"objectPrefix must be a safe relative key prefix.\");\n }\n const prefix = objectPrefix ? `${objectPrefix}/` : \"\";\n return {\n key: `${prefix}${encodeURIComponent(input.tenantId)}/${this.idFactory()}`,\n };\n }\n\n private makeTarget(\n sessionId: string,\n expiresInMs: number,\n expiresAt: Date,\n ): MediaUploadTarget {\n if (expiresInMs > this.maxSignedUrlTtlMs) {\n throw new MediaValidationError(\"Upload target expiry exceeds the configured limit.\");\n }\n return {\n url: `memory://upload/${encodeURIComponent(sessionId)}`,\n method: \"PUT\",\n headers: {},\n expiresAt,\n };\n }\n\n private refKey(object: MediaObjectReference): string {\n return `${object.key}\\u0000${object.versionId ?? \"\"}`;\n }\n\n private objectCursor(object: MediaObjectReference): string {\n return this.refKey(object);\n }\n\n private validNow(): Date {\n const now = this.now();\n if (!(now instanceof Date) || !Number.isFinite(now.getTime())) {\n throw new MediaValidationError(\"The configured clock returned an invalid date.\");\n }\n return now;\n }\n}\n","import {\n MediaAssetConflictError,\n MediaNotFoundError,\n MediaValidationError,\n} from \"../errors/media.errors\";\nimport type {\n MediaProcessingFailure,\n MediaProcessingJob,\n MediaProcessingJobInput,\n MediaProcessingQueueAdapter,\n MediaProcessingQueueClaim,\n} from \"../types/processing.types\";\n\nexport class InMemoryMediaProcessingQueueAdapter\n implements MediaProcessingQueueAdapter\n{\n private readonly jobs = new Map<string, MediaProcessingJob>();\n private readonly idempotency = new Map<string, string>();\n\n async enqueue(input: MediaProcessingJobInput): Promise<MediaProcessingJob> {\n const key = `${input.tenantId}\\u0000${input.idempotencyKey}`;\n const existingId = this.idempotency.get(key);\n if (existingId) {\n const existing = this.jobs.get(existingId);\n if (!existing) throw new MediaAssetConflictError(\"Idempotency index is inconsistent.\");\n if (\n existing.assetId !== input.assetId ||\n existing.kind !== input.kind ||\n JSON.stringify(existing.profiles) !== JSON.stringify(input.profiles)\n ) {\n throw new MediaAssetConflictError(\n \"An idempotency key cannot be reused for a different processing request.\",\n );\n }\n return existing;\n }\n if (\n !Number.isInteger(input.maxAttempts) ||\n input.maxAttempts < 1 ||\n !Number.isFinite(input.createdAt.getTime())\n ) {\n throw new MediaValidationError(\"The processing job input is invalid.\");\n }\n const availableAt = input.availableAt ?? input.createdAt;\n if (!Number.isFinite(availableAt.getTime())) {\n throw new MediaValidationError(\"availableAt must be a valid date.\");\n }\n const job: MediaProcessingJob = {\n ...input,\n status: \"queued\",\n attempt: 0,\n progress: 0,\n availableAt,\n workerId: null,\n leaseExpiresAt: null,\n result: [],\n failure: null,\n updatedAt: input.createdAt,\n completedAt: null,\n revision: 1,\n };\n this.jobs.set(job.id, job);\n this.idempotency.set(key, job.id);\n return job;\n }\n\n async get(id: string): Promise<MediaProcessingJob | null> {\n return this.jobs.get(id) ?? null;\n }\n\n async claimNext(\n input: MediaProcessingQueueClaim,\n ): Promise<MediaProcessingJob | null> {\n this.validateClaim(input);\n for (const job of this.jobs.values()) {\n const leaseExpired =\n job.status === \"processing\" &&\n (job.leaseExpiresAt?.getTime() ?? Number.POSITIVE_INFINITY) <=\n input.now.getTime();\n const retryExhausted =\n (job.status === \"queued\" || job.status === \"retrying\") &&\n job.attempt >= job.maxAttempts;\n if ((leaseExpired || retryExhausted) && job.attempt >= job.maxAttempts) {\n this.save({\n ...job,\n status: \"dead-letter\",\n failure: {\n message: \"The processing attempt limit was reached.\",\n retryable: true,\n },\n workerId: null,\n leaseExpiresAt: null,\n completedAt: input.now,\n updatedAt: input.now,\n revision: job.revision + 1,\n });\n }\n }\n const eligible = [...this.jobs.values()]\n .filter(\n (job) =>\n ((job.status === \"queued\" || job.status === \"retrying\") &&\n job.attempt < job.maxAttempts &&\n job.availableAt.getTime() <= input.now.getTime()) ||\n (job.status === \"processing\" &&\n job.attempt < job.maxAttempts &&\n (job.leaseExpiresAt?.getTime() ?? Number.POSITIVE_INFINITY) <=\n input.now.getTime()),\n )\n .sort(\n (left, right) =>\n left.availableAt.getTime() - right.availableAt.getTime() ||\n left.createdAt.getTime() - right.createdAt.getTime(),\n );\n const job = eligible[0];\n if (!job) return null;\n const claimed: MediaProcessingJob = {\n ...job,\n status: \"processing\",\n attempt: job.attempt + 1,\n progress: 0,\n workerId: input.workerId,\n leaseExpiresAt: new Date(input.now.getTime() + input.leaseDurationMs),\n updatedAt: input.now,\n failure: null,\n revision: job.revision + 1,\n };\n this.jobs.set(job.id, claimed);\n return claimed;\n }\n\n async updateProgress(\n id: string,\n workerId: string,\n progress: number,\n now: Date,\n ): Promise<MediaProcessingJob> {\n const job = this.getProcessingJob(id);\n this.assertWorker(job, workerId);\n if (!Number.isFinite(progress) || progress < job.progress || progress > 100) {\n throw new MediaValidationError(\n \"Processing progress must be monotonic and from 0 to 100.\",\n );\n }\n return this.save({\n ...job,\n progress,\n updatedAt: now,\n revision: job.revision + 1,\n });\n }\n\n async renewLease(\n id: string,\n workerId: string,\n leaseDurationMs: number,\n now: Date,\n ): Promise<MediaProcessingJob> {\n const job = this.getProcessingJob(id);\n if (job.workerId !== workerId) {\n throw new MediaAssetConflictError(\n \"Only the worker holding the processing lease can renew it.\",\n );\n }\n if (\n !Number.isInteger(leaseDurationMs) ||\n leaseDurationMs < 1 ||\n !Number.isFinite(now.getTime()) ||\n (job.leaseExpiresAt?.getTime() ?? 0) <= now.getTime()\n ) {\n throw new MediaValidationError(\"The processing lease cannot be renewed.\");\n }\n return this.save({\n ...job,\n leaseExpiresAt: new Date(now.getTime() + leaseDurationMs),\n updatedAt: now,\n revision: job.revision + 1,\n });\n }\n\n async complete(\n id: string,\n workerId: string,\n result: MediaProcessingJob[\"result\"],\n now: Date,\n ): Promise<MediaProcessingJob> {\n const job = this.getProcessingJob(id);\n this.assertWorker(job, workerId);\n return this.save({\n ...job,\n status: \"succeeded\",\n progress: 100,\n result: result ?? [],\n failure: null,\n workerId: null,\n leaseExpiresAt: null,\n completedAt: now,\n updatedAt: now,\n revision: job.revision + 1,\n });\n }\n\n async fail(\n id: string,\n workerId: string,\n failure: MediaProcessingFailure,\n retryAt: Date | null,\n now: Date,\n ): Promise<MediaProcessingJob> {\n const job = this.getProcessingJob(id);\n this.assertWorker(job, workerId);\n if (retryAt && (!failure.retryable || retryAt.getTime() <= now.getTime())) {\n throw new MediaValidationError(\n \"A retry time is only valid for a retryable failure in the future.\",\n );\n }\n const retry = retryAt !== null && job.attempt < job.maxAttempts;\n return this.save({\n ...job,\n status: retry ? \"retrying\" : failure.retryable ? \"dead-letter\" : \"failed\",\n availableAt: retry ? retryAt : job.availableAt,\n progress: retry ? 0 : job.progress,\n failure,\n workerId: null,\n leaseExpiresAt: null,\n completedAt: retry ? null : now,\n updatedAt: now,\n revision: job.revision + 1,\n });\n }\n\n async cancel(id: string, now: Date): Promise<MediaProcessingJob | null> {\n const job = this.jobs.get(id);\n if (!job || this.isTerminal(job.status)) return null;\n return this.save({\n ...job,\n status: \"cancelled\",\n workerId: null,\n leaseExpiresAt: null,\n completedAt: now,\n updatedAt: now,\n revision: job.revision + 1,\n });\n }\n\n reset(): void {\n this.jobs.clear();\n this.idempotency.clear();\n }\n\n private getProcessingJob(id: string): MediaProcessingJob {\n const job = this.jobs.get(id);\n if (!job) throw new MediaNotFoundError(\"Processing job\");\n if (job.status !== \"processing\") {\n throw new MediaAssetConflictError(\n `Processing job cannot be updated while its status is \"${job.status}\".`,\n );\n }\n return job;\n }\n\n private save(job: MediaProcessingJob): MediaProcessingJob {\n this.jobs.set(job.id, job);\n return job;\n }\n\n private assertWorker(job: MediaProcessingJob, workerId: string): void {\n if (job.workerId !== workerId) {\n throw new MediaAssetConflictError(\n \"Only the worker holding the processing lease can update this job.\",\n );\n }\n }\n\n private validateClaim(input: MediaProcessingQueueClaim): void {\n if (typeof input.workerId !== \"string\" || input.workerId.trim() === \"\") {\n throw new MediaValidationError(\"workerId must be a non-empty string.\");\n }\n if (\n !Number.isInteger(input.leaseDurationMs) ||\n input.leaseDurationMs < 1 ||\n !Number.isFinite(input.now.getTime())\n ) {\n throw new MediaValidationError(\"Processing lease configuration is invalid.\");\n }\n }\n\n private isTerminal(status: MediaProcessingJob[\"status\"]): boolean {\n return (\n status === \"succeeded\" ||\n status === \"failed\" ||\n status === \"dead-letter\" ||\n status === \"cancelled\"\n );\n }\n}\n"],"mappings":";;AAiDA,MAAM,cAAc,UAAkC,IAAI,WAAW,KAAK;AAE1E,MAAM,SAAS,UACb,CAAC,GAAG,IAAI,WAAW,KAAK,CAAC,CAAC,CACvB,KAAK,SAAS,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CACjD,KAAK,EAAE;AAEZ,MAAM,gBAAgB,OAAO,UAA8C;CACzE,IAAI,CAAC,WAAW,QAAQ,QACtB,MAAM,IAAIA,yBAAAA,wBAAwB,6CAA6C;CAEjF,MAAM,QAAQ,IAAI,WAAW,KAAK;CAClC,MAAM,SAAS,MAAM,WAAW,OAAO,OAAO,OAAO,WAAW,KAAK;CACrE,OAAO;EAAE,WAAW;EAAU,OAAO,MAAM,MAAM;CAAE;AACrD;AAEA,MAAM,uBAAuB,UAAwC;CACnE,IAAI,OAAO,MAAM,aAAa,YAAY,MAAM,SAAS,KAAK,MAAM,IAClE,MAAM,IAAIC,yBAAAA,qBAAqB,sCAAsC;CAEvE,IAAI,OAAO,MAAM,aAAa,YAAY,MAAM,SAAS,KAAK,MAAM,IAClE,MAAM,IAAIA,yBAAAA,qBAAqB,sCAA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0,0 +1,63 @@
|
|
|
1
|
+
import { p as MediaObjectReference } from "./media.types-dzfu0Nep.js";
|
|
2
|
+
import { C as MediaObjectStorageAdapter, D as MediaUploadConstraints, E as MediaStoredObject, S as MediaObjectPage, T as MediaReadTarget, b as MediaMultipartPartTarget, d as MediaProcessingQueueClaim, i as MediaProcessingJobInput, k as MediaUploadSession, n as MediaProcessingFailure, r as MediaProcessingJob, u as MediaProcessingQueueAdapter, x as MediaObjectListInput, y as MediaMultipartCompletedPart } from "./processing.types-CPaSB88L.js";
|
|
3
|
+
type InMemoryMediaObjectStorageOptions = {
|
|
4
|
+
readonly idFactory?: () => string;
|
|
5
|
+
readonly now?: () => Date;
|
|
6
|
+
readonly maxSignedUrlTtlMs?: number;
|
|
7
|
+
};
|
|
8
|
+
declare class InMemoryMediaObjectStorageAdapter implements MediaObjectStorageAdapter {
|
|
9
|
+
private readonly uploads;
|
|
10
|
+
private readonly objects;
|
|
11
|
+
private readonly objectBytes;
|
|
12
|
+
private nextId;
|
|
13
|
+
private readonly idFactory;
|
|
14
|
+
private readonly now;
|
|
15
|
+
private readonly maxSignedUrlTtlMs;
|
|
16
|
+
constructor(options?: InMemoryMediaObjectStorageOptions);
|
|
17
|
+
createUploadIntent(input: MediaUploadConstraints): Promise<MediaUploadSession>;
|
|
18
|
+
createMultipartUpload(input: MediaUploadConstraints & {
|
|
19
|
+
readonly partSizeBytes: number;
|
|
20
|
+
}): Promise<MediaUploadSession>;
|
|
21
|
+
createMultipartPartTargets(sessionId: string, partNumbers: readonly number[], expiresInMs: number): Promise<readonly MediaMultipartPartTarget[]>;
|
|
22
|
+
completeUpload(sessionId: string, parts?: readonly MediaMultipartCompletedPart[]): Promise<MediaStoredObject>;
|
|
23
|
+
abortUpload(sessionId: string): Promise<boolean>;
|
|
24
|
+
getUploadSession(sessionId: string): Promise<MediaUploadSession | null>;
|
|
25
|
+
getObjectMetadata(object: MediaObjectReference): Promise<MediaStoredObject | null>;
|
|
26
|
+
createReadTarget(object: MediaObjectReference, expiresInMs: number): Promise<MediaReadTarget>;
|
|
27
|
+
deleteObject(object: MediaObjectReference): Promise<boolean>;
|
|
28
|
+
listObjects(input: MediaObjectListInput): Promise<MediaObjectPage>;
|
|
29
|
+
listExpiredUploadSessions(before: Date, first: number): Promise<readonly MediaUploadSession[]>;
|
|
30
|
+
writeForTesting(sessionId: string, bytes: Uint8Array, contentType: string): Promise<void>;
|
|
31
|
+
writePartForTesting(sessionId: string, partNumber: number, bytes: Uint8Array): Promise<MediaMultipartCompletedPart>;
|
|
32
|
+
getBytesForTesting(object: MediaObjectReference): Uint8Array | null;
|
|
33
|
+
reset(): void;
|
|
34
|
+
private findUpload;
|
|
35
|
+
private getPendingUpload;
|
|
36
|
+
private assertPendingAndUnexpired;
|
|
37
|
+
private collectMultipartBytes;
|
|
38
|
+
private assertContentType;
|
|
39
|
+
private makeObjectReference;
|
|
40
|
+
private makeTarget;
|
|
41
|
+
private refKey;
|
|
42
|
+
private objectCursor;
|
|
43
|
+
private validNow;
|
|
44
|
+
}
|
|
45
|
+
declare class InMemoryMediaProcessingQueueAdapter implements MediaProcessingQueueAdapter {
|
|
46
|
+
private readonly jobs;
|
|
47
|
+
private readonly idempotency;
|
|
48
|
+
enqueue(input: MediaProcessingJobInput): Promise<MediaProcessingJob>;
|
|
49
|
+
get(id: string): Promise<MediaProcessingJob | null>;
|
|
50
|
+
claimNext(input: MediaProcessingQueueClaim): Promise<MediaProcessingJob | null>;
|
|
51
|
+
updateProgress(id: string, workerId: string, progress: number, now: Date): Promise<MediaProcessingJob>;
|
|
52
|
+
renewLease(id: string, workerId: string, leaseDurationMs: number, now: Date): Promise<MediaProcessingJob>;
|
|
53
|
+
complete(id: string, workerId: string, result: MediaProcessingJob["result"], now: Date): Promise<MediaProcessingJob>;
|
|
54
|
+
fail(id: string, workerId: string, failure: MediaProcessingFailure, retryAt: Date | null, now: Date): Promise<MediaProcessingJob>;
|
|
55
|
+
cancel(id: string, now: Date): Promise<MediaProcessingJob | null>;
|
|
56
|
+
reset(): void;
|
|
57
|
+
private getProcessingJob;
|
|
58
|
+
private save;
|
|
59
|
+
private assertWorker;
|
|
60
|
+
private validateClaim;
|
|
61
|
+
private isTerminal;
|
|
62
|
+
}
|
|
63
|
+
export { InMemoryMediaObjectStorageAdapter as n, InMemoryMediaObjectStorageOptions as r, InMemoryMediaProcessingQueueAdapter as t };
|