@anvilkit/plugin-asset-manager 0.1.1 → 0.1.3
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 +366 -108
- package/dist/adapters/data-url.cjs +6 -2
- package/dist/adapters/data-url.d.cts.map +1 -1
- package/dist/adapters/data-url.d.ts.map +1 -1
- package/dist/adapters/data-url.js +6 -2
- package/dist/adapters/extract-image-dimensions.cjs +9 -0
- package/dist/adapters/extract-image-dimensions.d.cts +6 -0
- package/dist/adapters/extract-image-dimensions.d.cts.map +1 -1
- package/dist/adapters/extract-image-dimensions.d.ts +6 -0
- package/dist/adapters/extract-image-dimensions.d.ts.map +1 -1
- package/dist/adapters/extract-image-dimensions.js +9 -0
- package/dist/adapters/in-memory.cjs +6 -4
- package/dist/adapters/in-memory.d.cts +6 -0
- package/dist/adapters/in-memory.d.cts.map +1 -1
- package/dist/adapters/in-memory.d.ts +6 -0
- package/dist/adapters/in-memory.d.ts.map +1 -1
- package/dist/adapters/in-memory.js +6 -4
- package/dist/adapters/s3-presigned.cjs +78 -28
- package/dist/adapters/s3-presigned.d.cts +1 -0
- package/dist/adapters/s3-presigned.d.cts.map +1 -1
- package/dist/adapters/s3-presigned.d.ts +1 -0
- package/dist/adapters/s3-presigned.d.ts.map +1 -1
- package/dist/adapters/s3-presigned.js +78 -28
- package/dist/csp.d.cts.map +1 -1
- package/dist/csp.d.ts.map +1 -1
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/plugin.cjs +32 -5
- package/dist/plugin.d.cts +4 -3
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.ts +4 -3
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +22 -5
- package/dist/registry.d.cts.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/resolver.cjs +6 -1
- package/dist/resolver.d.cts.map +1 -1
- package/dist/resolver.d.ts.map +1 -1
- package/dist/resolver.js +6 -1
- package/dist/retry.cjs +10 -8
- package/dist/retry.d.cts.map +1 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +10 -8
- package/dist/studio-asset-source.cjs +26 -5
- package/dist/studio-asset-source.d.cts +2 -2
- package/dist/studio-asset-source.d.cts.map +1 -1
- package/dist/studio-asset-source.d.ts +2 -2
- package/dist/studio-asset-source.d.ts.map +1 -1
- package/dist/studio-asset-source.js +26 -5
- package/dist/testing/index.d.cts.map +1 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/types.d.cts +9 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +9 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/AssetBrowser.cjs +54 -19
- package/dist/ui/AssetBrowser.d.cts +10 -1
- package/dist/ui/AssetBrowser.d.cts.map +1 -1
- package/dist/ui/AssetBrowser.d.ts +10 -1
- package/dist/ui/AssetBrowser.d.ts.map +1 -1
- package/dist/ui/AssetBrowser.js +54 -19
- package/dist/ui/AssetCommandPalette.cjs +18 -9
- package/dist/ui/AssetCommandPalette.d.cts.map +1 -1
- package/dist/ui/AssetCommandPalette.d.ts.map +1 -1
- package/dist/ui/AssetCommandPalette.js +18 -9
- package/dist/ui/AssetManagerUI.cjs +1 -0
- package/dist/ui/AssetManagerUI.d.cts.map +1 -1
- package/dist/ui/AssetManagerUI.d.ts.map +1 -1
- package/dist/ui/AssetManagerUI.js +1 -0
- package/dist/ui/DeleteAssetDialog.cjs +1 -0
- package/dist/ui/DeleteAssetDialog.d.cts.map +1 -1
- package/dist/ui/DeleteAssetDialog.d.ts.map +1 -1
- package/dist/ui/DeleteAssetDialog.js +1 -0
- package/dist/ui/MetadataPanel.cjs +1 -0
- package/dist/ui/MetadataPanel.d.cts.map +1 -1
- package/dist/ui/MetadataPanel.d.ts.map +1 -1
- package/dist/ui/MetadataPanel.js +1 -0
- package/dist/ui/ReplaceAssetDialog.cjs +1 -0
- package/dist/ui/ReplaceAssetDialog.d.cts.map +1 -1
- package/dist/ui/ReplaceAssetDialog.d.ts.map +1 -1
- package/dist/ui/ReplaceAssetDialog.js +1 -0
- package/dist/ui/UploadButton.cjs +22 -7
- package/dist/ui/UploadButton.d.cts.map +1 -1
- package/dist/ui/UploadButton.d.ts.map +1 -1
- package/dist/ui/UploadButton.js +22 -7
- package/dist/ui/index.d.cts.map +1 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/validate-upload-result.cjs +49 -10
- package/dist/validate-upload-result.d.cts.map +1 -1
- package/dist/validate-upload-result.d.ts.map +1 -1
- package/dist/validate-upload-result.js +49 -10
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-image-dimensions.d.ts","sourceRoot":"","sources":["../../src/adapters/extract-image-dimensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,6BAA6B;
|
|
1
|
+
{"version":3,"file":"extract-image-dimensions.d.ts","sourceRoot":"","sources":["../../src/adapters/extract-image-dimensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,6BAA6B;IAC5C,qDAAqD;IACrD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAID,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,OAAO,GAAE,6BAAkC,GAC1C,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAkEtC"}
|
|
@@ -3,17 +3,26 @@ async function extractImageDimensions(url, mimeType, options = {}) {
|
|
|
3
3
|
if (!mimeType || !mimeType.startsWith("image/")) return;
|
|
4
4
|
if ("u" < typeof Image) return;
|
|
5
5
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
6
|
+
const signal = options.signal;
|
|
7
|
+
if (signal?.aborted) return;
|
|
6
8
|
return new Promise((resolve)=>{
|
|
7
9
|
let settled = false;
|
|
8
10
|
const image = new Image();
|
|
11
|
+
const onAbort = ()=>{
|
|
12
|
+
settle(void 0);
|
|
13
|
+
};
|
|
9
14
|
const settle = (value)=>{
|
|
10
15
|
if (settled) return;
|
|
11
16
|
settled = true;
|
|
12
17
|
image.onload = null;
|
|
13
18
|
image.onerror = null;
|
|
14
19
|
if (void 0 !== timer) clearTimeout(timer);
|
|
20
|
+
signal?.removeEventListener("abort", onAbort);
|
|
15
21
|
resolve(value);
|
|
16
22
|
};
|
|
23
|
+
signal?.addEventListener("abort", onAbort, {
|
|
24
|
+
once: true
|
|
25
|
+
});
|
|
17
26
|
image.onload = ()=>{
|
|
18
27
|
const width = Math.round(image.naturalWidth);
|
|
19
28
|
const height = Math.round(image.naturalHeight);
|
|
@@ -28,14 +28,16 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
});
|
|
29
29
|
const external_extract_image_dimensions_cjs_namespaceObject = require("./extract-image-dimensions.cjs");
|
|
30
30
|
function inMemoryUploader() {
|
|
31
|
-
const filesById = new Map();
|
|
32
31
|
let counter = 0;
|
|
33
|
-
return async (file)=>{
|
|
32
|
+
return async (file, opts)=>{
|
|
34
33
|
counter += 1;
|
|
35
34
|
const id = `asset-${counter}`;
|
|
36
|
-
filesById.set(id, file);
|
|
37
35
|
const url = "function" == typeof URL.createObjectURL ? URL.createObjectURL(file) : `blob:asset-manager/${id}`;
|
|
38
|
-
const dimensions = await (0, external_extract_image_dimensions_cjs_namespaceObject.extractImageDimensions)(url, file.type
|
|
36
|
+
const dimensions = await (0, external_extract_image_dimensions_cjs_namespaceObject.extractImageDimensions)(url, file.type, {
|
|
37
|
+
...opts?.signal ? {
|
|
38
|
+
signal: opts.signal
|
|
39
|
+
} : {}
|
|
40
|
+
});
|
|
39
41
|
const result = {
|
|
40
42
|
id,
|
|
41
43
|
url,
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { UploadAdapter } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory upload adapter for demos and tests. Returns a `blob:` URL
|
|
4
|
+
* that the consumer renders directly, so the object URL intentionally
|
|
5
|
+
* lives for the page lifetime — it cannot be revoked while the asset is
|
|
6
|
+
* still referenced. Not for production use.
|
|
7
|
+
*/
|
|
2
8
|
export declare function inMemoryUploader(): UploadAdapter;
|
|
3
9
|
//# sourceMappingURL=in-memory.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.d.cts","sourceRoot":"","sources":["../../src/adapters/in-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;AAG/D,wBAAgB,gBAAgB,IAAI,aAAa,CA8BhD"}
|
|
1
|
+
{"version":3,"file":"in-memory.d.cts","sourceRoot":"","sources":["../../src/adapters/in-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;AAG/D;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CA8BhD"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { UploadAdapter } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory upload adapter for demos and tests. Returns a `blob:` URL
|
|
4
|
+
* that the consumer renders directly, so the object URL intentionally
|
|
5
|
+
* lives for the page lifetime — it cannot be revoked while the asset is
|
|
6
|
+
* still referenced. Not for production use.
|
|
7
|
+
*/
|
|
2
8
|
export declare function inMemoryUploader(): UploadAdapter;
|
|
3
9
|
//# sourceMappingURL=in-memory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../src/adapters/in-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;AAG/D,wBAAgB,gBAAgB,IAAI,aAAa,CA8BhD"}
|
|
1
|
+
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../src/adapters/in-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;AAG/D;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CA8BhD"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { extractImageDimensions } from "./extract-image-dimensions.js";
|
|
2
2
|
function inMemoryUploader() {
|
|
3
|
-
const filesById = new Map();
|
|
4
3
|
let counter = 0;
|
|
5
|
-
return async (file)=>{
|
|
4
|
+
return async (file, opts)=>{
|
|
6
5
|
counter += 1;
|
|
7
6
|
const id = `asset-${counter}`;
|
|
8
|
-
filesById.set(id, file);
|
|
9
7
|
const url = "function" == typeof URL.createObjectURL ? URL.createObjectURL(file) : `blob:asset-manager/${id}`;
|
|
10
|
-
const dimensions = await extractImageDimensions(url, file.type
|
|
8
|
+
const dimensions = await extractImageDimensions(url, file.type, {
|
|
9
|
+
...opts?.signal ? {
|
|
10
|
+
signal: opts.signal
|
|
11
|
+
} : {}
|
|
12
|
+
});
|
|
11
13
|
const result = {
|
|
12
14
|
id,
|
|
13
15
|
url,
|
|
@@ -33,34 +33,39 @@ function s3PresignedAdapter(options) {
|
|
|
33
33
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
34
34
|
if ("function" != typeof fetchImpl) throw new Error("s3PresignedAdapter: no `fetch` implementation available. Pass `options.fetch`.");
|
|
35
35
|
const generateId = options.idGenerator ?? defaultIdGenerator;
|
|
36
|
-
return async (file)=>{
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
36
|
+
return async (file, callOptions)=>{
|
|
37
|
+
const { signal, dispose } = combineSignals(options.signal, callOptions?.signal);
|
|
38
|
+
try {
|
|
39
|
+
const presign = await (0, external_retry_cjs_namespaceObject.withRetry)(()=>requestPresign(file, fetchImpl, options, signal), {
|
|
40
|
+
...options.retry ?? {},
|
|
41
|
+
signal
|
|
42
|
+
});
|
|
43
|
+
await (0, external_retry_cjs_namespaceObject.withRetry)(()=>putToS3(file, presign, fetchImpl, signal), {
|
|
44
|
+
...options.retry ?? {},
|
|
45
|
+
signal
|
|
46
|
+
});
|
|
47
|
+
const id = presign.id ?? generateId();
|
|
48
|
+
const publicUrl = presign.publicUrl ?? stripQueryAndFragment(presign.url);
|
|
49
|
+
const result = {
|
|
50
|
+
id,
|
|
51
|
+
url: publicUrl,
|
|
52
|
+
...file.name ? {
|
|
53
|
+
name: file.name
|
|
54
|
+
} : {},
|
|
55
|
+
meta: {
|
|
56
|
+
size: file.size,
|
|
57
|
+
...file.type ? {
|
|
58
|
+
mimeType: file.type
|
|
59
|
+
} : {}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return result;
|
|
63
|
+
} finally{
|
|
64
|
+
dispose();
|
|
65
|
+
}
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
|
-
async function requestPresign(file, fetchImpl, options) {
|
|
68
|
+
async function requestPresign(file, fetchImpl, options, signal) {
|
|
64
69
|
const url = "string" == typeof options.presignEndpoint ? options.presignEndpoint : options.presignEndpoint.toString();
|
|
65
70
|
const body = JSON.stringify({
|
|
66
71
|
name: file.name,
|
|
@@ -76,8 +81,8 @@ async function requestPresign(file, fetchImpl, options) {
|
|
|
76
81
|
...options.headers ?? {}
|
|
77
82
|
},
|
|
78
83
|
body,
|
|
79
|
-
...
|
|
80
|
-
signal
|
|
84
|
+
...signal ? {
|
|
85
|
+
signal
|
|
81
86
|
} : {}
|
|
82
87
|
});
|
|
83
88
|
} catch (cause) {
|
|
@@ -155,6 +160,51 @@ function defaultIdGenerator() {
|
|
|
155
160
|
if (void 0 !== globalThis.crypto && "function" == typeof globalThis.crypto.randomUUID) return globalThis.crypto.randomUUID();
|
|
156
161
|
return `asset-${Math.random().toString(36).slice(2)}-${Date.now()}`;
|
|
157
162
|
}
|
|
163
|
+
const NOOP_DISPOSE = ()=>{};
|
|
164
|
+
function combineSignals(a, b) {
|
|
165
|
+
if (!a) return {
|
|
166
|
+
signal: b,
|
|
167
|
+
dispose: NOOP_DISPOSE
|
|
168
|
+
};
|
|
169
|
+
if (!b) return {
|
|
170
|
+
signal: a,
|
|
171
|
+
dispose: NOOP_DISPOSE
|
|
172
|
+
};
|
|
173
|
+
if (a === b) return {
|
|
174
|
+
signal: a,
|
|
175
|
+
dispose: NOOP_DISPOSE
|
|
176
|
+
};
|
|
177
|
+
const anyImpl = AbortSignal.any;
|
|
178
|
+
if ("function" == typeof anyImpl) return {
|
|
179
|
+
signal: anyImpl([
|
|
180
|
+
a,
|
|
181
|
+
b
|
|
182
|
+
]),
|
|
183
|
+
dispose: NOOP_DISPOSE
|
|
184
|
+
};
|
|
185
|
+
const controller = new AbortController();
|
|
186
|
+
const onAbortA = ()=>{
|
|
187
|
+
if (!controller.signal.aborted) controller.abort(a.reason);
|
|
188
|
+
};
|
|
189
|
+
const onAbortB = ()=>{
|
|
190
|
+
if (!controller.signal.aborted) controller.abort(b.reason);
|
|
191
|
+
};
|
|
192
|
+
if (a.aborted) onAbortA();
|
|
193
|
+
else a.addEventListener("abort", onAbortA, {
|
|
194
|
+
once: true
|
|
195
|
+
});
|
|
196
|
+
if (b.aborted) onAbortB();
|
|
197
|
+
else b.addEventListener("abort", onAbortB, {
|
|
198
|
+
once: true
|
|
199
|
+
});
|
|
200
|
+
return {
|
|
201
|
+
signal: controller.signal,
|
|
202
|
+
dispose: ()=>{
|
|
203
|
+
a.removeEventListener("abort", onAbortA);
|
|
204
|
+
b.removeEventListener("abort", onAbortB);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
158
208
|
exports.RetryableError = __webpack_exports__.RetryableError;
|
|
159
209
|
exports.s3PresignedAdapter = __webpack_exports__.s3PresignedAdapter;
|
|
160
210
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { type RetryOptions } from "../retry.js";
|
|
21
21
|
import type { UploadAdapter } from "../types.js";
|
|
22
|
+
/** @deprecated Import from `@anvilkit/plugin-asset-manager/retry` instead. */
|
|
22
23
|
export { RetryableError } from "../retry.js";
|
|
23
24
|
export type { RetryOptions } from "../retry.js";
|
|
24
25
|
export interface S3PresignedAdapterOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-presigned.d.cts","sourceRoot":"","sources":["../../src/adapters/s3-presigned.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAkB,KAAK,YAAY,EAAa,MAAM,aAAa,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"s3-presigned.d.cts","sourceRoot":"","sources":["../../src/adapters/s3-presigned.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAkB,KAAK,YAAY,EAAa,MAAM,aAAa,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;AAO/D,8EAA8E;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,yBAAyB;IACxC,iEAAiE;IACjE,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,GAAG,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACzC,yEAAyE;IACzE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,kDAAkD;IAClD,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;IAC9B,iEAAiE;IACjE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,uEAAuE;IACvE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,MAAM,CAAC;CACrC;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,yBAAyB;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,wDAAwD;IACxD,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,yBAAyB,GACjC,aAAa,CA+Cf"}
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { type RetryOptions } from "../retry.js";
|
|
21
21
|
import type { UploadAdapter } from "../types.js";
|
|
22
|
+
/** @deprecated Import from `@anvilkit/plugin-asset-manager/retry` instead. */
|
|
22
23
|
export { RetryableError } from "../retry.js";
|
|
23
24
|
export type { RetryOptions } from "../retry.js";
|
|
24
25
|
export interface S3PresignedAdapterOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-presigned.d.ts","sourceRoot":"","sources":["../../src/adapters/s3-presigned.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAkB,KAAK,YAAY,EAAa,MAAM,aAAa,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"s3-presigned.d.ts","sourceRoot":"","sources":["../../src/adapters/s3-presigned.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAkB,KAAK,YAAY,EAAa,MAAM,aAAa,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;AAO/D,8EAA8E;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,yBAAyB;IACxC,iEAAiE;IACjE,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,GAAG,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACzC,yEAAyE;IACzE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,kDAAkD;IAClD,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;IAC9B,iEAAiE;IACjE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,uEAAuE;IACvE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,MAAM,CAAC;CACrC;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,yBAAyB;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,wDAAwD;IACxD,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,yBAAyB,GACjC,aAAa,CA+Cf"}
|
|
@@ -4,34 +4,39 @@ function s3PresignedAdapter(options) {
|
|
|
4
4
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
5
5
|
if ("function" != typeof fetchImpl) throw new Error("s3PresignedAdapter: no `fetch` implementation available. Pass `options.fetch`.");
|
|
6
6
|
const generateId = options.idGenerator ?? defaultIdGenerator;
|
|
7
|
-
return async (file)=>{
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
signal
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
7
|
+
return async (file, callOptions)=>{
|
|
8
|
+
const { signal, dispose } = combineSignals(options.signal, callOptions?.signal);
|
|
9
|
+
try {
|
|
10
|
+
const presign = await withRetry(()=>requestPresign(file, fetchImpl, options, signal), {
|
|
11
|
+
...options.retry ?? {},
|
|
12
|
+
signal
|
|
13
|
+
});
|
|
14
|
+
await withRetry(()=>putToS3(file, presign, fetchImpl, signal), {
|
|
15
|
+
...options.retry ?? {},
|
|
16
|
+
signal
|
|
17
|
+
});
|
|
18
|
+
const id = presign.id ?? generateId();
|
|
19
|
+
const publicUrl = presign.publicUrl ?? stripQueryAndFragment(presign.url);
|
|
20
|
+
const result = {
|
|
21
|
+
id,
|
|
22
|
+
url: publicUrl,
|
|
23
|
+
...file.name ? {
|
|
24
|
+
name: file.name
|
|
25
|
+
} : {},
|
|
26
|
+
meta: {
|
|
27
|
+
size: file.size,
|
|
28
|
+
...file.type ? {
|
|
29
|
+
mimeType: file.type
|
|
30
|
+
} : {}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return result;
|
|
34
|
+
} finally{
|
|
35
|
+
dispose();
|
|
36
|
+
}
|
|
32
37
|
};
|
|
33
38
|
}
|
|
34
|
-
async function requestPresign(file, fetchImpl, options) {
|
|
39
|
+
async function requestPresign(file, fetchImpl, options, signal) {
|
|
35
40
|
const url = "string" == typeof options.presignEndpoint ? options.presignEndpoint : options.presignEndpoint.toString();
|
|
36
41
|
const body = JSON.stringify({
|
|
37
42
|
name: file.name,
|
|
@@ -47,8 +52,8 @@ async function requestPresign(file, fetchImpl, options) {
|
|
|
47
52
|
...options.headers ?? {}
|
|
48
53
|
},
|
|
49
54
|
body,
|
|
50
|
-
...
|
|
51
|
-
signal
|
|
55
|
+
...signal ? {
|
|
56
|
+
signal
|
|
52
57
|
} : {}
|
|
53
58
|
});
|
|
54
59
|
} catch (cause) {
|
|
@@ -126,4 +131,49 @@ function defaultIdGenerator() {
|
|
|
126
131
|
if (void 0 !== globalThis.crypto && "function" == typeof globalThis.crypto.randomUUID) return globalThis.crypto.randomUUID();
|
|
127
132
|
return `asset-${Math.random().toString(36).slice(2)}-${Date.now()}`;
|
|
128
133
|
}
|
|
134
|
+
const NOOP_DISPOSE = ()=>{};
|
|
135
|
+
function combineSignals(a, b) {
|
|
136
|
+
if (!a) return {
|
|
137
|
+
signal: b,
|
|
138
|
+
dispose: NOOP_DISPOSE
|
|
139
|
+
};
|
|
140
|
+
if (!b) return {
|
|
141
|
+
signal: a,
|
|
142
|
+
dispose: NOOP_DISPOSE
|
|
143
|
+
};
|
|
144
|
+
if (a === b) return {
|
|
145
|
+
signal: a,
|
|
146
|
+
dispose: NOOP_DISPOSE
|
|
147
|
+
};
|
|
148
|
+
const anyImpl = AbortSignal.any;
|
|
149
|
+
if ("function" == typeof anyImpl) return {
|
|
150
|
+
signal: anyImpl([
|
|
151
|
+
a,
|
|
152
|
+
b
|
|
153
|
+
]),
|
|
154
|
+
dispose: NOOP_DISPOSE
|
|
155
|
+
};
|
|
156
|
+
const controller = new AbortController();
|
|
157
|
+
const onAbortA = ()=>{
|
|
158
|
+
if (!controller.signal.aborted) controller.abort(a.reason);
|
|
159
|
+
};
|
|
160
|
+
const onAbortB = ()=>{
|
|
161
|
+
if (!controller.signal.aborted) controller.abort(b.reason);
|
|
162
|
+
};
|
|
163
|
+
if (a.aborted) onAbortA();
|
|
164
|
+
else a.addEventListener("abort", onAbortA, {
|
|
165
|
+
once: true
|
|
166
|
+
});
|
|
167
|
+
if (b.aborted) onAbortB();
|
|
168
|
+
else b.addEventListener("abort", onAbortB, {
|
|
169
|
+
once: true
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
signal: controller.signal,
|
|
173
|
+
dispose: ()=>{
|
|
174
|
+
a.removeEventListener("abort", onAbortA);
|
|
175
|
+
b.removeEventListener("abort", onAbortB);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
129
179
|
export { RetryableError, s3PresignedAdapter };
|
package/dist/csp.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csp.d.cts","sourceRoot":"","sources":["../src/csp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"csp.d.cts","sourceRoot":"","sources":["../src/csp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,GAAG,CAAC;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,kBAAkB;IACjC,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,CAAC,EAAE,YAAY,GAAG,SAAS,YAAY,EAAE,CAAC;CACtD;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,wBAAgB,cAAc,CAAC,OAAO,GAAE,kBAAuB,GAAG,WAAW,CA4C5E"}
|
package/dist/csp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csp.d.ts","sourceRoot":"","sources":["../src/csp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"csp.d.ts","sourceRoot":"","sources":["../src/csp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,GAAG,CAAC;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,kBAAkB;IACjC,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,CAAC,EAAE,YAAY,GAAG,SAAS,YAAY,EAAE,CAAC;CACtD;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,wBAAgB,cAAc,CAAC,OAAO,GAAE,kBAAuB,GAAG,WAAW,CA4C5E"}
|
package/dist/errors.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.cts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.d.cts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAGpB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAUzC;AAED,MAAM,MAAM,wBAAwB,GAChC,iBAAiB,GACjB,oBAAoB,GACpB,yBAAyB,CAAC;AAE9B,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;gBAGtC,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,wBAA4C,EAClD,OAAO,SAAyC,EAChD,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAWzC"}
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAGpB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAUzC;AAED,MAAM,MAAM,wBAAwB,GAChC,iBAAiB,GACjB,oBAAoB,GACpB,yBAAyB,CAAC;AAE9B,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;gBAGtC,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,wBAA4C,EAClD,OAAO,SAAyC,EAChD,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAWzC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export type { DataUrlUploaderOptions } from "./adapters/data-url.js";
|
|
2
2
|
export { dataUrlUploader } from "./adapters/data-url.js";
|
|
3
3
|
export { inMemoryUploader } from "./adapters/in-memory.js";
|
|
4
|
-
export type { RequiredCsp, RequiredCspOptions, S3CspOptions
|
|
4
|
+
export type { RequiredCsp, RequiredCspOptions, S3CspOptions } from "./csp.js";
|
|
5
5
|
export { getRequiredCsp } from "./csp.js";
|
|
6
6
|
export type { AssetResolutionErrorCode } from "./errors.js";
|
|
7
|
-
export { AssetResolutionError, AssetValidationError
|
|
7
|
+
export { AssetResolutionError, AssetValidationError } from "./errors.js";
|
|
8
8
|
export { inferAssetKind } from "./infer-kind.js";
|
|
9
9
|
export { createAssetManagerPlugin, createAssetReference, getAssetRegistry, uploadAsset, } from "./plugin.js";
|
|
10
10
|
export { createAssetRegistry } from "./registry.js";
|
|
@@ -12,7 +12,7 @@ export type { CreateIRAssetResolverOptions } from "./resolver.js";
|
|
|
12
12
|
export { createIRAssetResolver, resolveAssets } from "./resolver.js";
|
|
13
13
|
export type { CreateStudioAssetSourceOptions } from "./studio-asset-source.js";
|
|
14
14
|
export { createStudioAssetSource, inferStudioAssetKind, } from "./studio-asset-source.js";
|
|
15
|
-
export type { AssetKind, AssetManagerOptions, AssetMeta, AssetRegistry, AssetRegistryListener, AssetSearchOptions, AssetSearchPage, UploadAdapter, UploadResult, } from "./types.js";
|
|
15
|
+
export type { AssetKind, AssetManagerOptions, AssetMeta, AssetRegistry, AssetRegistryListener, AssetSearchOptions, AssetSearchPage, UploadAdapter, UploadAdapterOptions, UploadResult, } from "./types.js";
|
|
16
16
|
export type { ValidateUploadResultOptions } from "./validate-upload-result.js";
|
|
17
17
|
export { validateUploadResult } from "./validate-upload-result.js";
|
|
18
18
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACrE,YAAY,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export type { DataUrlUploaderOptions } from "./adapters/data-url.js";
|
|
2
2
|
export { dataUrlUploader } from "./adapters/data-url.js";
|
|
3
3
|
export { inMemoryUploader } from "./adapters/in-memory.js";
|
|
4
|
-
export type { RequiredCsp, RequiredCspOptions, S3CspOptions
|
|
4
|
+
export type { RequiredCsp, RequiredCspOptions, S3CspOptions } from "./csp.js";
|
|
5
5
|
export { getRequiredCsp } from "./csp.js";
|
|
6
6
|
export type { AssetResolutionErrorCode } from "./errors.js";
|
|
7
|
-
export { AssetResolutionError, AssetValidationError
|
|
7
|
+
export { AssetResolutionError, AssetValidationError } from "./errors.js";
|
|
8
8
|
export { inferAssetKind } from "./infer-kind.js";
|
|
9
9
|
export { createAssetManagerPlugin, createAssetReference, getAssetRegistry, uploadAsset, } from "./plugin.js";
|
|
10
10
|
export { createAssetRegistry } from "./registry.js";
|
|
@@ -12,7 +12,7 @@ export type { CreateIRAssetResolverOptions } from "./resolver.js";
|
|
|
12
12
|
export { createIRAssetResolver, resolveAssets } from "./resolver.js";
|
|
13
13
|
export type { CreateStudioAssetSourceOptions } from "./studio-asset-source.js";
|
|
14
14
|
export { createStudioAssetSource, inferStudioAssetKind, } from "./studio-asset-source.js";
|
|
15
|
-
export type { AssetKind, AssetManagerOptions, AssetMeta, AssetRegistry, AssetRegistryListener, AssetSearchOptions, AssetSearchPage, UploadAdapter, UploadResult, } from "./types.js";
|
|
15
|
+
export type { AssetKind, AssetManagerOptions, AssetMeta, AssetRegistry, AssetRegistryListener, AssetSearchOptions, AssetSearchPage, UploadAdapter, UploadAdapterOptions, UploadResult, } from "./types.js";
|
|
16
16
|
export type { ValidateUploadResultOptions } from "./validate-upload-result.js";
|
|
17
17
|
export { validateUploadResult } from "./validate-upload-result.js";
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACrE,YAAY,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/plugin.cjs
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
3
12
|
(()=>{
|
|
4
13
|
__webpack_require__.d = (exports1, definition)=>{
|
|
5
14
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
@@ -30,6 +39,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
30
39
|
getAssetRegistry: ()=>getAssetRegistry,
|
|
31
40
|
createAssetReference: ()=>external_asset_reference_cjs_namespaceObject.createAssetReference
|
|
32
41
|
});
|
|
42
|
+
const external_package_json_namespaceObject = require("../package.json");
|
|
43
|
+
var external_package_json_default = /*#__PURE__*/ __webpack_require__.n(external_package_json_namespaceObject);
|
|
33
44
|
const external_asset_reference_cjs_namespaceObject = require("./asset-reference.cjs");
|
|
34
45
|
const external_errors_cjs_namespaceObject = require("./errors.cjs");
|
|
35
46
|
const external_header_action_cjs_namespaceObject = require("./header-action.cjs");
|
|
@@ -41,7 +52,7 @@ const external_validate_upload_result_cjs_namespaceObject = require("./validate-
|
|
|
41
52
|
const META = {
|
|
42
53
|
id: "anvilkit-plugin-asset-manager",
|
|
43
54
|
name: "Asset Manager",
|
|
44
|
-
version:
|
|
55
|
+
version: external_package_json_default().version,
|
|
45
56
|
coreVersion: "^0.1.0-alpha",
|
|
46
57
|
description: "Headless asset upload plugin with host-provided persistence and a separate React UI subpath."
|
|
47
58
|
};
|
|
@@ -76,7 +87,7 @@ function createAssetManagerPlugin(options) {
|
|
|
76
87
|
initCtx.registerAssetResolver(assetResolver);
|
|
77
88
|
const studioAssetSource = (0, external_studio_asset_source_cjs_namespaceObject.createStudioAssetSource)({
|
|
78
89
|
registry,
|
|
79
|
-
upload: (file)=>uploadAsset(initCtx, file),
|
|
90
|
+
upload: (file, opts)=>uploadAsset(initCtx, file, opts?.signal),
|
|
80
91
|
...normalizedOptions.getThumbnail ? {
|
|
81
92
|
getThumbnail: normalizedOptions.getThumbnail
|
|
82
93
|
} : {}
|
|
@@ -100,12 +111,15 @@ function getAssetRegistry(ctx) {
|
|
|
100
111
|
const token = tokenByContext.get(ctx);
|
|
101
112
|
return token ? stateByToken.get(token)?.registry : void 0;
|
|
102
113
|
}
|
|
103
|
-
async function uploadAsset(ctx, file) {
|
|
114
|
+
async function uploadAsset(ctx, file, signal) {
|
|
104
115
|
const state = getRuntimeState(ctx);
|
|
105
116
|
const { options, registry } = state;
|
|
106
117
|
try {
|
|
107
118
|
validateSelectedFile(file, options);
|
|
108
|
-
const uploadResult = await options.uploader(file
|
|
119
|
+
const uploadResult = await options.uploader(file, signal ? {
|
|
120
|
+
signal
|
|
121
|
+
} : void 0);
|
|
122
|
+
if (signal?.aborted) throw makePluginAbortError();
|
|
109
123
|
const validated = (0, external_validate_upload_result_cjs_namespaceObject.validateUploadResult)(mergeUploadMeta(uploadResult, file), options);
|
|
110
124
|
const tagged = withDerivedTags(validated, file);
|
|
111
125
|
const stored = registry.register(tagged);
|
|
@@ -116,6 +130,7 @@ async function uploadAsset(ctx, file) {
|
|
|
116
130
|
});
|
|
117
131
|
return stored;
|
|
118
132
|
} catch (error) {
|
|
133
|
+
if (isAbortLikeError(error) || signal?.aborted) throw error;
|
|
119
134
|
const normalizedError = error instanceof external_errors_cjs_namespaceObject.AssetValidationError ? error : new external_errors_cjs_namespaceObject.AssetValidationError("UPLOAD_FAILED", error instanceof Error ? error.message : String(error), {
|
|
120
135
|
cause: error
|
|
121
136
|
});
|
|
@@ -202,7 +217,8 @@ function mimeTypeMatches(input, acceptedMimeTypes) {
|
|
|
202
217
|
}
|
|
203
218
|
function dispatchAssetReference(ctx, asset) {
|
|
204
219
|
const currentData = ctx.getData();
|
|
205
|
-
const
|
|
220
|
+
const assetsView = currentData.assets;
|
|
221
|
+
const currentAssetsRaw = Array.isArray(assetsView) ? assetsView : [];
|
|
206
222
|
const assetEntry = toIRAsset(asset);
|
|
207
223
|
const nextAssets = [];
|
|
208
224
|
let replaced = false;
|
|
@@ -241,6 +257,17 @@ function inferIRAssetKind(mimeType, url) {
|
|
|
241
257
|
function isRecord(value) {
|
|
242
258
|
return "object" == typeof value && null !== value;
|
|
243
259
|
}
|
|
260
|
+
function makePluginAbortError() {
|
|
261
|
+
if ("u" > typeof DOMException) return new DOMException("Upload aborted", "AbortError");
|
|
262
|
+
const error = new Error("Upload aborted");
|
|
263
|
+
error.name = "AbortError";
|
|
264
|
+
return error;
|
|
265
|
+
}
|
|
266
|
+
function isAbortLikeError(error) {
|
|
267
|
+
if (null === error || "object" != typeof error) return false;
|
|
268
|
+
const name = error.name;
|
|
269
|
+
return "AbortError" === name;
|
|
270
|
+
}
|
|
244
271
|
exports.createAssetManagerPlugin = __webpack_exports__.createAssetManagerPlugin;
|
|
245
272
|
exports.createAssetReference = __webpack_exports__.createAssetReference;
|
|
246
273
|
exports.getAssetRegistry = __webpack_exports__.getAssetRegistry;
|
package/dist/plugin.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { StudioPlugin, StudioPluginContext } from "@anvilkit/core/types";
|
|
2
|
+
import type { Config as PuckConfig } from "@puckeditor/core";
|
|
2
3
|
import { createAssetReference } from "./asset-reference.js";
|
|
3
4
|
import type { AssetManagerOptions, AssetRegistry, UploadResult } from "./types.js";
|
|
4
5
|
export { createAssetReference };
|
|
5
|
-
export declare function createAssetManagerPlugin(options: AssetManagerOptions): StudioPlugin
|
|
6
|
-
export declare function getAssetRegistry(ctx: StudioPluginContext): AssetRegistry | undefined;
|
|
7
|
-
export declare function uploadAsset(ctx: StudioPluginContext
|
|
6
|
+
export declare function createAssetManagerPlugin<UserConfig extends PuckConfig = PuckConfig>(options: AssetManagerOptions): StudioPlugin<UserConfig>;
|
|
7
|
+
export declare function getAssetRegistry<UserConfig extends PuckConfig = PuckConfig>(ctx: StudioPluginContext<UserConfig>): AssetRegistry | undefined;
|
|
8
|
+
export declare function uploadAsset<UserConfig extends PuckConfig = PuckConfig>(ctx: StudioPluginContext<UserConfig>, file: File, signal?: AbortSignal): Promise<UploadResult>;
|
|
8
9
|
export declare function validateSelectedFile(file: File, options: Pick<AssetManagerOptions, "acceptedMimeTypes" | "maxFileSize">): void;
|
|
9
10
|
//# sourceMappingURL=plugin.d.cts.map
|
package/dist/plugin.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,YAAY,EACZ,mBAAmB,EAEpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAO5D,OAAO,KAAK,EACV,mBAAmB,EAEnB,aAAa,EACb,YAAY,EACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,oBAAoB,EAAE,CAAC;AA4BhC,wBAAgB,wBAAwB,CACtC,UAAU,SAAS,UAAU,GAAG,UAAU,EAC1C,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAAC,UAAU,CAAC,CAwDxD;AAED,wBAAgB,gBAAgB,CAAC,UAAU,SAAS,UAAU,GAAG,UAAU,EACzE,GAAG,EAAE,mBAAmB,CAAC,UAAU,CAAC,GACnC,aAAa,GAAG,SAAS,CAG3B;AAED,wBAAsB,WAAW,CAAC,UAAU,SAAS,UAAU,GAAG,UAAU,EAC1E,GAAG,EAAE,mBAAmB,CAAC,UAAU,CAAC,EACpC,IAAI,EAAE,IAAI,EACV,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,YAAY,CAAC,CAwDvB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,aAAa,CAAC,GACtE,IAAI,CAmBN"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { StudioPlugin, StudioPluginContext } from "@anvilkit/core/types";
|
|
2
|
+
import type { Config as PuckConfig } from "@puckeditor/core";
|
|
2
3
|
import { createAssetReference } from "./asset-reference.js";
|
|
3
4
|
import type { AssetManagerOptions, AssetRegistry, UploadResult } from "./types.js";
|
|
4
5
|
export { createAssetReference };
|
|
5
|
-
export declare function createAssetManagerPlugin(options: AssetManagerOptions): StudioPlugin
|
|
6
|
-
export declare function getAssetRegistry(ctx: StudioPluginContext): AssetRegistry | undefined;
|
|
7
|
-
export declare function uploadAsset(ctx: StudioPluginContext
|
|
6
|
+
export declare function createAssetManagerPlugin<UserConfig extends PuckConfig = PuckConfig>(options: AssetManagerOptions): StudioPlugin<UserConfig>;
|
|
7
|
+
export declare function getAssetRegistry<UserConfig extends PuckConfig = PuckConfig>(ctx: StudioPluginContext<UserConfig>): AssetRegistry | undefined;
|
|
8
|
+
export declare function uploadAsset<UserConfig extends PuckConfig = PuckConfig>(ctx: StudioPluginContext<UserConfig>, file: File, signal?: AbortSignal): Promise<UploadResult>;
|
|
8
9
|
export declare function validateSelectedFile(file: File, options: Pick<AssetManagerOptions, "acceptedMimeTypes" | "maxFileSize">): void;
|
|
9
10
|
//# sourceMappingURL=plugin.d.ts.map
|