@anvilkit/plugin-asset-manager 0.1.6 → 0.1.8
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 +28 -20
- package/dist/adapters/data-url.d.cts +13 -0
- package/dist/adapters/data-url.d.cts.map +1 -1
- package/dist/adapters/data-url.d.ts +13 -0
- package/dist/adapters/data-url.d.ts.map +1 -1
- package/dist/adapters/in-memory.d.cts +8 -1
- package/dist/adapters/in-memory.d.cts.map +1 -1
- package/dist/adapters/in-memory.d.ts +8 -1
- package/dist/adapters/in-memory.d.ts.map +1 -1
- package/dist/i18n/entry.cjs +75 -0
- package/dist/i18n/entry.d.cts +15 -0
- package/dist/i18n/entry.d.cts.map +1 -0
- package/dist/i18n/entry.d.ts +15 -0
- package/dist/i18n/entry.d.ts.map +1 -0
- package/dist/i18n/entry.js +29 -0
- package/dist/i18n/provider.cjs +49 -0
- package/dist/i18n/provider.d.cts +20 -0
- package/dist/i18n/provider.d.cts.map +1 -0
- package/dist/i18n/provider.d.ts +20 -0
- package/dist/i18n/provider.d.ts.map +1 -0
- package/dist/i18n/provider.js +11 -0
- package/dist/index.cjs +7 -0
- package/dist/index.d.cts +11 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/plugin.cjs +70 -5
- package/dist/plugin.d.cts +3 -2
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.ts +3 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +70 -5
- package/dist/sources/composite-source.cjs +138 -0
- package/dist/sources/composite-source.d.cts +39 -0
- package/dist/sources/composite-source.d.cts.map +1 -0
- package/dist/sources/composite-source.d.ts +39 -0
- package/dist/sources/composite-source.d.ts.map +1 -0
- package/dist/sources/composite-source.js +100 -0
- package/dist/sources/federated-search.cjs +173 -0
- package/dist/sources/federated-search.d.cts +33 -0
- package/dist/sources/federated-search.d.cts.map +1 -0
- package/dist/sources/federated-search.d.ts +33 -0
- package/dist/sources/federated-search.d.ts.map +1 -0
- package/dist/sources/federated-search.js +123 -0
- package/dist/sources/provider.cjs +18 -0
- package/dist/sources/provider.d.cts +51 -0
- package/dist/sources/provider.d.cts.map +1 -0
- package/dist/sources/provider.d.ts +51 -0
- package/dist/sources/provider.d.ts.map +1 -0
- package/dist/sources/provider.js +1 -0
- package/dist/sources/unsplash/client.cjs +189 -0
- package/dist/sources/unsplash/client.d.cts +87 -0
- package/dist/sources/unsplash/client.d.cts.map +1 -0
- package/dist/sources/unsplash/client.d.ts +87 -0
- package/dist/sources/unsplash/client.d.ts.map +1 -0
- package/dist/sources/unsplash/client.js +151 -0
- package/dist/sources/unsplash/index.cjs +194 -0
- package/dist/sources/unsplash/index.d.cts +16 -0
- package/dist/sources/unsplash/index.d.cts.map +1 -0
- package/dist/sources/unsplash/index.d.ts +16 -0
- package/dist/sources/unsplash/index.d.ts.map +1 -0
- package/dist/sources/unsplash/index.js +150 -0
- package/dist/sources/unsplash/themes.cjs +141 -0
- package/dist/sources/unsplash/themes.d.cts +18 -0
- package/dist/sources/unsplash/themes.d.cts.map +1 -0
- package/dist/sources/unsplash/themes.d.ts +18 -0
- package/dist/sources/unsplash/themes.d.ts.map +1 -0
- package/dist/sources/unsplash/themes.js +93 -0
- package/dist/sources/unsplash/throttle-cache.cjs +86 -0
- package/dist/sources/unsplash/throttle-cache.d.cts +25 -0
- package/dist/sources/unsplash/throttle-cache.d.cts.map +1 -0
- package/dist/sources/unsplash/throttle-cache.d.ts +25 -0
- package/dist/sources/unsplash/throttle-cache.d.ts.map +1 -0
- package/dist/sources/unsplash/throttle-cache.js +45 -0
- package/dist/types/categories.cjs +18 -0
- package/dist/types/categories.d.cts +48 -0
- package/dist/types/categories.d.cts.map +1 -0
- package/dist/types/categories.d.ts +48 -0
- package/dist/types/categories.d.ts.map +1 -0
- package/dist/types/categories.js +1 -0
- package/dist/types/data-source.cjs +18 -0
- package/dist/types/data-source.d.cts +59 -0
- package/dist/types/data-source.d.cts.map +1 -0
- package/dist/types/data-source.d.ts +59 -0
- package/dist/types/data-source.d.ts.map +1 -0
- package/dist/types/data-source.js +1 -0
- package/dist/types/filter.cjs +18 -0
- package/dist/types/filter.d.cts +55 -0
- package/dist/types/filter.d.cts.map +1 -0
- package/dist/types/filter.d.ts +55 -0
- package/dist/types/filter.d.ts.map +1 -0
- package/dist/types/filter.js +1 -0
- package/dist/types/folders.cjs +42 -0
- package/dist/types/folders.d.cts +46 -0
- package/dist/types/folders.d.cts.map +1 -0
- package/dist/types/folders.d.ts +46 -0
- package/dist/types/folders.d.ts.map +1 -0
- package/dist/types/folders.js +4 -0
- package/dist/types/options.cjs +18 -0
- package/dist/types/options.d.cts +68 -0
- package/dist/types/options.d.cts.map +1 -0
- package/dist/types/options.d.ts +68 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/options.js +1 -0
- package/dist/types/types.d.cts +21 -27
- package/dist/types/types.d.cts.map +1 -1
- package/dist/types/types.d.ts +21 -27
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/unsplash.cjs +18 -0
- package/dist/types/unsplash.d.cts +60 -0
- package/dist/types/unsplash.d.cts.map +1 -0
- package/dist/types/unsplash.d.ts +60 -0
- package/dist/types/unsplash.d.ts.map +1 -0
- package/dist/types/unsplash.js +1 -0
- package/dist/ui/AssetBrowser.cjs +183 -121
- package/dist/ui/AssetBrowser.d.cts +12 -1
- package/dist/ui/AssetBrowser.d.cts.map +1 -1
- package/dist/ui/AssetBrowser.d.ts +12 -1
- package/dist/ui/AssetBrowser.d.ts.map +1 -1
- package/dist/ui/AssetBrowser.js +183 -121
- package/dist/ui/AssetCommandPalette.cjs +20 -18
- package/dist/ui/AssetCommandPalette.d.cts.map +1 -1
- package/dist/ui/AssetCommandPalette.d.ts.map +1 -1
- package/dist/ui/AssetCommandPalette.js +20 -18
- package/dist/ui/AssetManagerUI.cjs +31 -17
- package/dist/ui/AssetManagerUI.d.cts +19 -3
- package/dist/ui/AssetManagerUI.d.cts.map +1 -1
- package/dist/ui/AssetManagerUI.d.ts +19 -3
- package/dist/ui/AssetManagerUI.d.ts.map +1 -1
- package/dist/ui/AssetManagerUI.js +31 -17
- package/dist/ui/DeleteAssetDialog.cjs +5 -3
- package/dist/ui/DeleteAssetDialog.d.cts.map +1 -1
- package/dist/ui/DeleteAssetDialog.d.ts.map +1 -1
- package/dist/ui/DeleteAssetDialog.js +5 -3
- package/dist/ui/DeleteFolderDialog.cjs +80 -0
- package/dist/ui/DeleteFolderDialog.d.cts +11 -0
- package/dist/ui/DeleteFolderDialog.d.cts.map +1 -0
- package/dist/ui/DeleteFolderDialog.d.ts +11 -0
- package/dist/ui/DeleteFolderDialog.d.ts.map +1 -0
- package/dist/ui/DeleteFolderDialog.js +42 -0
- package/dist/ui/EmptyFolderState.cjs +56 -0
- package/dist/ui/EmptyFolderState.d.cts +6 -0
- package/dist/ui/EmptyFolderState.d.cts.map +1 -0
- package/dist/ui/EmptyFolderState.d.ts +6 -0
- package/dist/ui/EmptyFolderState.d.ts.map +1 -0
- package/dist/ui/EmptyFolderState.js +18 -0
- package/dist/ui/FolderBreadcrumb.cjs +76 -0
- package/dist/ui/FolderBreadcrumb.d.cts +9 -0
- package/dist/ui/FolderBreadcrumb.d.cts.map +1 -0
- package/dist/ui/FolderBreadcrumb.d.ts +9 -0
- package/dist/ui/FolderBreadcrumb.d.ts.map +1 -0
- package/dist/ui/FolderBreadcrumb.js +38 -0
- package/dist/ui/FolderNameDialog.cjs +105 -0
- package/dist/ui/FolderNameDialog.d.cts +14 -0
- package/dist/ui/FolderNameDialog.d.cts.map +1 -0
- package/dist/ui/FolderNameDialog.d.ts +14 -0
- package/dist/ui/FolderNameDialog.d.ts.map +1 -0
- package/dist/ui/FolderNameDialog.js +67 -0
- package/dist/ui/FolderTree.cjs +85 -0
- package/dist/ui/FolderTree.d.cts +13 -0
- package/dist/ui/FolderTree.d.cts.map +1 -0
- package/dist/ui/FolderTree.d.ts +13 -0
- package/dist/ui/FolderTree.d.ts.map +1 -0
- package/dist/ui/FolderTree.js +44 -0
- package/dist/ui/MetadataPanel.cjs +23 -17
- package/dist/ui/MetadataPanel.d.cts.map +1 -1
- package/dist/ui/MetadataPanel.d.ts.map +1 -1
- package/dist/ui/MetadataPanel.js +23 -17
- package/dist/ui/MoveTargetPicker.cjs +87 -0
- package/dist/ui/MoveTargetPicker.d.cts +16 -0
- package/dist/ui/MoveTargetPicker.d.cts.map +1 -0
- package/dist/ui/MoveTargetPicker.d.ts +16 -0
- package/dist/ui/MoveTargetPicker.d.ts.map +1 -0
- package/dist/ui/MoveTargetPicker.js +49 -0
- package/dist/ui/ReplaceAssetDialog.cjs +19 -17
- package/dist/ui/ReplaceAssetDialog.d.cts +2 -1
- package/dist/ui/ReplaceAssetDialog.d.cts.map +1 -1
- package/dist/ui/ReplaceAssetDialog.d.ts +2 -1
- package/dist/ui/ReplaceAssetDialog.d.ts.map +1 -1
- package/dist/ui/ReplaceAssetDialog.js +19 -17
- package/dist/ui/UnsplashPanel.cjs +137 -0
- package/dist/ui/UnsplashPanel.d.cts +28 -0
- package/dist/ui/UnsplashPanel.d.cts.map +1 -0
- package/dist/ui/UnsplashPanel.d.ts +28 -0
- package/dist/ui/UnsplashPanel.d.ts.map +1 -0
- package/dist/ui/UnsplashPanel.js +99 -0
- package/dist/ui/UploadButton.cjs +12 -13
- package/dist/ui/UploadButton.d.cts +9 -2
- package/dist/ui/UploadButton.d.cts.map +1 -1
- package/dist/ui/UploadButton.d.ts +9 -2
- package/dist/ui/UploadButton.d.ts.map +1 -1
- package/dist/ui/UploadButton.js +12 -13
- package/dist/ui/index.cjs +41 -0
- package/dist/ui/index.d.cts +15 -0
- package/dist/ui/index.d.cts.map +1 -1
- package/dist/ui/index.d.ts +15 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +8 -0
- package/dist/utils/data-source.cjs +190 -0
- package/dist/utils/data-source.d.cts +63 -0
- package/dist/utils/data-source.d.cts.map +1 -0
- package/dist/utils/data-source.d.ts +63 -0
- package/dist/utils/data-source.d.ts.map +1 -0
- package/dist/utils/data-source.js +149 -0
- package/dist/utils/errors.cjs +18 -0
- package/dist/utils/errors.d.cts +27 -0
- package/dist/utils/errors.d.cts.map +1 -1
- package/dist/utils/errors.d.ts +27 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +16 -1
- package/dist/utils/folders.cjs +335 -0
- package/dist/utils/folders.d.cts +54 -0
- package/dist/utils/folders.d.cts.map +1 -0
- package/dist/utils/folders.d.ts +54 -0
- package/dist/utils/folders.d.ts.map +1 -0
- package/dist/utils/folders.js +297 -0
- package/dist/utils/header-action.cjs +1 -1
- package/dist/utils/header-action.d.cts.map +1 -1
- package/dist/utils/header-action.d.ts.map +1 -1
- package/dist/utils/header-action.js +1 -1
- package/dist/utils/registry.cjs +38 -12
- package/dist/utils/registry.d.cts +29 -1
- package/dist/utils/registry.d.cts.map +1 -1
- package/dist/utils/registry.d.ts +29 -1
- package/dist/utils/registry.d.ts.map +1 -1
- package/dist/utils/registry.js +31 -11
- package/dist/utils/resolver.cjs +5 -4
- package/dist/utils/resolver.d.cts.map +1 -1
- package/dist/utils/resolver.d.ts.map +1 -1
- package/dist/utils/resolver.js +5 -4
- package/dist/utils/studio-asset-source.cjs +13 -4
- package/dist/utils/studio-asset-source.d.cts +6 -1
- package/dist/utils/studio-asset-source.d.cts.map +1 -1
- package/dist/utils/studio-asset-source.d.ts +6 -1
- package/dist/utils/studio-asset-source.d.ts.map +1 -1
- package/dist/utils/studio-asset-source.js +9 -3
- package/dist/utils/validate-upload-result.d.cts +2 -1
- package/dist/utils/validate-upload-result.d.cts.map +1 -1
- package/dist/utils/validate-upload-result.d.ts +2 -1
- package/dist/utils/validate-upload-result.d.ts.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/i18n/messages/en.json +99 -0
- package/i18n/messages/ja.json +99 -0
- package/i18n/messages/ko.json +99 -0
- package/i18n/messages/zh.json +99 -0
- package/meta/config.json +1 -1
- package/package.json +19 -8
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
createInMemoryDataSource: ()=>createInMemoryDataSource,
|
|
32
|
+
resolveDataSource: ()=>resolveDataSource
|
|
33
|
+
});
|
|
34
|
+
const folders_cjs_namespaceObject = require("../types/folders.cjs");
|
|
35
|
+
const external_errors_cjs_namespaceObject = require("./errors.cjs");
|
|
36
|
+
const external_folders_cjs_namespaceObject = require("./folders.cjs");
|
|
37
|
+
const external_registry_cjs_namespaceObject = require("./registry.cjs");
|
|
38
|
+
function collectSubtreeAssetIds(folders, root) {
|
|
39
|
+
const out = [];
|
|
40
|
+
for (const fid of folders.subtreeIds(root))out.push(...folders.directAssetIds(fid));
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function makeAbortError() {
|
|
44
|
+
if ("u" > typeof DOMException) return new DOMException("Operation aborted", "AbortError");
|
|
45
|
+
const error = new Error("Operation aborted");
|
|
46
|
+
error.name = "AbortError";
|
|
47
|
+
return error;
|
|
48
|
+
}
|
|
49
|
+
function createInMemoryDataSource(options) {
|
|
50
|
+
const { registry, upload, maxDepth } = options;
|
|
51
|
+
const folders = options.folderStore ?? (0, external_folders_cjs_namespaceObject.createFolderStore)();
|
|
52
|
+
const buildPage = (page, query)=>{
|
|
53
|
+
const base = {
|
|
54
|
+
items: page.items,
|
|
55
|
+
total: page.total,
|
|
56
|
+
nextCursor: page.nextCursor
|
|
57
|
+
};
|
|
58
|
+
if (void 0 === query.folderId) return base;
|
|
59
|
+
return {
|
|
60
|
+
...base,
|
|
61
|
+
folders: folders.listChildren(query.folderId),
|
|
62
|
+
folderPath: folders.path(query.folderId)
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
folders,
|
|
67
|
+
list (query) {
|
|
68
|
+
if (void 0 === query.folderId) return Promise.resolve(buildPage(registry.search(query), query));
|
|
69
|
+
const target = (0, folders_cjs_namespaceObject.resolveFolderId)(query.folderId);
|
|
70
|
+
const recursive = true === query.recursive;
|
|
71
|
+
const matchesFilter = (0, external_registry_cjs_namespaceObject.prepareAssetMatcher)(query);
|
|
72
|
+
let matches;
|
|
73
|
+
if (null === target) matches = registry.list().filter((entry)=>{
|
|
74
|
+
const folderOk = recursive || null === folders.folderOf(entry.id);
|
|
75
|
+
return folderOk && matchesFilter(entry);
|
|
76
|
+
});
|
|
77
|
+
else {
|
|
78
|
+
const ids = recursive ? collectSubtreeAssetIds(folders, target) : folders.directAssetIds(target);
|
|
79
|
+
matches = [];
|
|
80
|
+
for (const id of ids){
|
|
81
|
+
const entry = registry.get(id);
|
|
82
|
+
if (void 0 !== entry && matchesFilter(entry)) matches.push(entry);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return Promise.resolve(buildPage((0, external_registry_cjs_namespaceObject.paginateMatches)(matches, query), query));
|
|
86
|
+
},
|
|
87
|
+
remove (id) {
|
|
88
|
+
registry.delete(id);
|
|
89
|
+
folders.removeAsset(id);
|
|
90
|
+
return Promise.resolve();
|
|
91
|
+
},
|
|
92
|
+
async replace (id, payload, signal) {
|
|
93
|
+
const result = await upload(payload, signal ? {
|
|
94
|
+
signal
|
|
95
|
+
} : void 0);
|
|
96
|
+
if (signal?.aborted) throw makeAbortError();
|
|
97
|
+
const replaced = registry.replace(id, result);
|
|
98
|
+
return replaced ?? result;
|
|
99
|
+
},
|
|
100
|
+
rename (id, name) {
|
|
101
|
+
const updated = registry.rename(id, name);
|
|
102
|
+
if (void 0 === updated) return Promise.reject(new external_errors_cjs_namespaceObject.AssetSourceError("ASSET_MUTATION_REJECTED", `Cannot rename unknown asset "${id}".`));
|
|
103
|
+
return Promise.resolve(updated);
|
|
104
|
+
},
|
|
105
|
+
move (id, folderId) {
|
|
106
|
+
folders.moveAsset(id, folderId);
|
|
107
|
+
return Promise.resolve();
|
|
108
|
+
},
|
|
109
|
+
createFolder (parentId, name) {
|
|
110
|
+
return Promise.resolve(folders.createFolder(parentId, name, maxDepth));
|
|
111
|
+
},
|
|
112
|
+
renameFolder (id, name) {
|
|
113
|
+
return Promise.resolve(folders.renameFolder(id, name));
|
|
114
|
+
},
|
|
115
|
+
removeFolder (id, opts) {
|
|
116
|
+
const { removedAssetIds } = folders.removeFolder(id, opts);
|
|
117
|
+
for (const assetId of removedAssetIds)registry.delete(assetId);
|
|
118
|
+
return Promise.resolve();
|
|
119
|
+
},
|
|
120
|
+
moveFolder (id, parentId) {
|
|
121
|
+
return Promise.resolve(folders.moveFolder(id, parentId, maxDepth));
|
|
122
|
+
},
|
|
123
|
+
subscribe (listener) {
|
|
124
|
+
const offRegistry = registry.subscribe(listener);
|
|
125
|
+
const offFolders = folders.subscribe(listener);
|
|
126
|
+
return ()=>{
|
|
127
|
+
offRegistry();
|
|
128
|
+
offFolders();
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
subscribeStatus (listener) {
|
|
132
|
+
listener({
|
|
133
|
+
phase: "idle"
|
|
134
|
+
});
|
|
135
|
+
return ()=>{};
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const ASSET_PLANE = [
|
|
140
|
+
"list",
|
|
141
|
+
"remove",
|
|
142
|
+
"replace",
|
|
143
|
+
"rename",
|
|
144
|
+
"move"
|
|
145
|
+
];
|
|
146
|
+
const FOLDER_PLANE = [
|
|
147
|
+
"createFolder",
|
|
148
|
+
"renameFolder",
|
|
149
|
+
"removeFolder",
|
|
150
|
+
"moveFolder"
|
|
151
|
+
];
|
|
152
|
+
function resolveDataSource(input) {
|
|
153
|
+
const fallback = createInMemoryDataSource(input);
|
|
154
|
+
const host = input.hostDataSource;
|
|
155
|
+
if (void 0 === host) return fallback;
|
|
156
|
+
const ownsPlane = (plane, label)=>{
|
|
157
|
+
const provided = plane.filter((m)=>"function" == typeof host[m]);
|
|
158
|
+
if (0 === provided.length) return false;
|
|
159
|
+
if (provided.length === plane.length) return true;
|
|
160
|
+
input.warn?.(`asset-manager: dataSource provides a partial ${label} method set (${provided.join(", ")}) — falling back to the in-memory default for the whole ${label} plane. Provide all of {${plane.join(", ")}} or none.`);
|
|
161
|
+
return false;
|
|
162
|
+
};
|
|
163
|
+
const resolved = {
|
|
164
|
+
...fallback
|
|
165
|
+
};
|
|
166
|
+
if (ownsPlane(ASSET_PLANE, "asset")) {
|
|
167
|
+
resolved.list = host.list.bind(host);
|
|
168
|
+
resolved.remove = host.remove.bind(host);
|
|
169
|
+
resolved.replace = host.replace.bind(host);
|
|
170
|
+
resolved.rename = host.rename.bind(host);
|
|
171
|
+
resolved.move = host.move.bind(host);
|
|
172
|
+
}
|
|
173
|
+
if (ownsPlane(FOLDER_PLANE, "folder")) {
|
|
174
|
+
resolved.createFolder = host.createFolder.bind(host);
|
|
175
|
+
resolved.renameFolder = host.renameFolder.bind(host);
|
|
176
|
+
resolved.removeFolder = host.removeFolder.bind(host);
|
|
177
|
+
resolved.moveFolder = host.moveFolder.bind(host);
|
|
178
|
+
}
|
|
179
|
+
if ("function" == typeof host.subscribeStatus) resolved.subscribeStatus = host.subscribeStatus.bind(host);
|
|
180
|
+
return resolved;
|
|
181
|
+
}
|
|
182
|
+
exports.createInMemoryDataSource = __webpack_exports__.createInMemoryDataSource;
|
|
183
|
+
exports.resolveDataSource = __webpack_exports__.resolveDataSource;
|
|
184
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
185
|
+
"createInMemoryDataSource",
|
|
186
|
+
"resolveDataSource"
|
|
187
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
188
|
+
Object.defineProperty(exports, '__esModule', {
|
|
189
|
+
value: true
|
|
190
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file In-memory `AssetDataSource` (PRD 0002 §6). Adapts the synchronous
|
|
3
|
+
* `AssetRegistry` + the {@link FolderStore} into the async, folder-aware data
|
|
4
|
+
* plane, WITHOUT changing the registry's API. The registry stays the single
|
|
5
|
+
* store for assets; folder membership lives in the side-index the folder store
|
|
6
|
+
* owns. Lazy-importable so flat callers pay nothing for folder code.
|
|
7
|
+
*/
|
|
8
|
+
import type { AssetDataSource, AssetSourceStatus, ReplacePayload } from "../types/data-source.js";
|
|
9
|
+
import type { AssetFilter, AssetListPage } from "../types/filter.js";
|
|
10
|
+
import type { AssetFolder, FolderId } from "../types/folders.js";
|
|
11
|
+
import type { AssetRegistry, UploadResult } from "../types/types.js";
|
|
12
|
+
import { type FolderStore } from "./folders.js";
|
|
13
|
+
/**
|
|
14
|
+
* Binary ingest used by `replace` — the same `uploadAsset`-bound callback the
|
|
15
|
+
* `StudioAssetSource` already threads, so the security pipeline is single-sourced.
|
|
16
|
+
*/
|
|
17
|
+
export type UploadFn = (file: File, options?: {
|
|
18
|
+
readonly signal?: AbortSignal;
|
|
19
|
+
}) => Promise<UploadResult>;
|
|
20
|
+
/** Fully-resolved data plane (no optional methods) stored on the runtime state. */
|
|
21
|
+
export interface ResolvedAssetDataSource {
|
|
22
|
+
list(query: AssetFilter, signal?: AbortSignal): Promise<AssetListPage>;
|
|
23
|
+
remove(id: string, signal?: AbortSignal): Promise<void>;
|
|
24
|
+
replace(id: string, payload: ReplacePayload, signal?: AbortSignal): Promise<UploadResult>;
|
|
25
|
+
rename(id: string, name: string, signal?: AbortSignal): Promise<UploadResult>;
|
|
26
|
+
move(id: string, folderId: FolderId | null, signal?: AbortSignal): Promise<void>;
|
|
27
|
+
createFolder(parentId: FolderId | null, name: string, signal?: AbortSignal): Promise<AssetFolder>;
|
|
28
|
+
renameFolder(id: FolderId, name: string, signal?: AbortSignal): Promise<AssetFolder>;
|
|
29
|
+
removeFolder(id: FolderId, opts?: {
|
|
30
|
+
readonly cascade?: boolean;
|
|
31
|
+
}, signal?: AbortSignal): Promise<void>;
|
|
32
|
+
moveFolder(id: FolderId, parentId: FolderId | null, signal?: AbortSignal): Promise<AssetFolder>;
|
|
33
|
+
/** Fires on any asset OR folder mutation (the sidebar re-lists). */
|
|
34
|
+
subscribe(listener: () => void): () => void;
|
|
35
|
+
subscribeStatus(listener: (status: AssetSourceStatus) => void): () => void;
|
|
36
|
+
/** The shared folder store (for the composite source / UI). */
|
|
37
|
+
readonly folders: FolderStore;
|
|
38
|
+
}
|
|
39
|
+
export interface CreateInMemoryDataSourceOptions {
|
|
40
|
+
readonly registry: AssetRegistry;
|
|
41
|
+
readonly upload: UploadFn;
|
|
42
|
+
/** Shared folder store — injected by the factory so the UI sees the same one. */
|
|
43
|
+
readonly folderStore?: FolderStore;
|
|
44
|
+
/** Max nesting depth from `FolderOptions`. */
|
|
45
|
+
readonly maxDepth?: number;
|
|
46
|
+
}
|
|
47
|
+
export declare function createInMemoryDataSource(options: CreateInMemoryDataSourceOptions): ResolvedAssetDataSource;
|
|
48
|
+
export interface ResolveDataSourceInput extends CreateInMemoryDataSourceOptions {
|
|
49
|
+
/** Host-supplied backend. When absent, the full in-memory default is used. */
|
|
50
|
+
readonly hostDataSource?: AssetDataSource;
|
|
51
|
+
/** One-time dev warning sink (e.g. `ctx.log`). */
|
|
52
|
+
readonly warn?: (message: string) => void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Per-PLANE resolution ladder (PRD 0002 §5). A host that supplies the FULL
|
|
56
|
+
* method set of a plane owns that plane; a PARTIAL set warns once and the WHOLE
|
|
57
|
+
* plane falls back to the in-memory default — so the read and write planes are
|
|
58
|
+
* never split across two stores. `subscribeStatus` is taken from the host when
|
|
59
|
+
* present; `subscribe`/`folders` always come from the in-memory layer (the
|
|
60
|
+
* composite re-lists after host mutations; external push is out of scope).
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveDataSource(input: ResolveDataSourceInput): ResolvedAssetDataSource;
|
|
63
|
+
//# sourceMappingURL=data-source.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-source.d.cts","sourceRoot":"","sources":["../../src/utils/data-source.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACX,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,KAAK,EACX,aAAa,EAEb,YAAY,EACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAqB,KAAK,WAAW,EAAE,MA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WITHOUT changing the registry's API. The registry stays the single
|
|
5
|
+
* store for assets; folder membership lives in the side-index the folder store
|
|
6
|
+
* owns. Lazy-importable so flat callers pay nothing for folder code.
|
|
7
|
+
*/
|
|
8
|
+
import type { AssetDataSource, AssetSourceStatus, ReplacePayload } from "../types/data-source.js";
|
|
9
|
+
import type { AssetFilter, AssetListPage } from "../types/filter.js";
|
|
10
|
+
import type { AssetFolder, FolderId } from "../types/folders.js";
|
|
11
|
+
import type { AssetRegistry, UploadResult } from "../types/types.js";
|
|
12
|
+
import { type FolderStore } from "./folders.js";
|
|
13
|
+
/**
|
|
14
|
+
* Binary ingest used by `replace` — the same `uploadAsset`-bound callback the
|
|
15
|
+
* `StudioAssetSource` already threads, so the security pipeline is single-sourced.
|
|
16
|
+
*/
|
|
17
|
+
export type UploadFn = (file: File, options?: {
|
|
18
|
+
readonly signal?: AbortSignal;
|
|
19
|
+
}) => Promise<UploadResult>;
|
|
20
|
+
/** Fully-resolved data plane (no optional methods) stored on the runtime state. */
|
|
21
|
+
export interface ResolvedAssetDataSource {
|
|
22
|
+
list(query: AssetFilter, signal?: AbortSignal): Promise<AssetListPage>;
|
|
23
|
+
remove(id: string, signal?: AbortSignal): Promise<void>;
|
|
24
|
+
replace(id: string, payload: ReplacePayload, signal?: AbortSignal): Promise<UploadResult>;
|
|
25
|
+
rename(id: string, name: string, signal?: AbortSignal): Promise<UploadResult>;
|
|
26
|
+
move(id: string, folderId: FolderId | null, signal?: AbortSignal): Promise<void>;
|
|
27
|
+
createFolder(parentId: FolderId | null, name: string, signal?: AbortSignal): Promise<AssetFolder>;
|
|
28
|
+
renameFolder(id: FolderId, name: string, signal?: AbortSignal): Promise<AssetFolder>;
|
|
29
|
+
removeFolder(id: FolderId, opts?: {
|
|
30
|
+
readonly cascade?: boolean;
|
|
31
|
+
}, signal?: AbortSignal): Promise<void>;
|
|
32
|
+
moveFolder(id: FolderId, parentId: FolderId | null, signal?: AbortSignal): Promise<AssetFolder>;
|
|
33
|
+
/** Fires on any asset OR folder mutation (the sidebar re-lists). */
|
|
34
|
+
subscribe(listener: () => void): () => void;
|
|
35
|
+
subscribeStatus(listener: (status: AssetSourceStatus) => void): () => void;
|
|
36
|
+
/** The shared folder store (for the composite source / UI). */
|
|
37
|
+
readonly folders: FolderStore;
|
|
38
|
+
}
|
|
39
|
+
export interface CreateInMemoryDataSourceOptions {
|
|
40
|
+
readonly registry: AssetRegistry;
|
|
41
|
+
readonly upload: UploadFn;
|
|
42
|
+
/** Shared folder store — injected by the factory so the UI sees the same one. */
|
|
43
|
+
readonly folderStore?: FolderStore;
|
|
44
|
+
/** Max nesting depth from `FolderOptions`. */
|
|
45
|
+
readonly maxDepth?: number;
|
|
46
|
+
}
|
|
47
|
+
export declare function createInMemoryDataSource(options: CreateInMemoryDataSourceOptions): ResolvedAssetDataSource;
|
|
48
|
+
export interface ResolveDataSourceInput extends CreateInMemoryDataSourceOptions {
|
|
49
|
+
/** Host-supplied backend. When absent, the full in-memory default is used. */
|
|
50
|
+
readonly hostDataSource?: AssetDataSource;
|
|
51
|
+
/** One-time dev warning sink (e.g. `ctx.log`). */
|
|
52
|
+
readonly warn?: (message: string) => void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Per-PLANE resolution ladder (PRD 0002 §5). A host that supplies the FULL
|
|
56
|
+
* method set of a plane owns that plane; a PARTIAL set warns once and the WHOLE
|
|
57
|
+
* plane falls back to the in-memory default — so the read and write planes are
|
|
58
|
+
* never split across two stores. `subscribeStatus` is taken from the host when
|
|
59
|
+
* present; `subscribe`/`folders` always come from the in-memory layer (the
|
|
60
|
+
* composite re-lists after host mutations; external push is out of scope).
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveDataSource(input: ResolveDataSourceInput): ResolvedAssetDataSource;
|
|
63
|
+
//# sourceMappingURL=data-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-source.d.ts","sourceRoot":"","sources":["../../src/utils/data-source.ts"],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C1C,kDAAkD;IAClD,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,sBAAsB,GAC3B,uBAAuB,CA0CzB"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { resolveFolderId } from "../types/folders.js";
|
|
2
|
+
import { AssetSourceError } from "./errors.js";
|
|
3
|
+
import { createFolderStore } from "./folders.js";
|
|
4
|
+
import { paginateMatches, prepareAssetMatcher } from "./registry.js";
|
|
5
|
+
function collectSubtreeAssetIds(folders, root) {
|
|
6
|
+
const out = [];
|
|
7
|
+
for (const fid of folders.subtreeIds(root))out.push(...folders.directAssetIds(fid));
|
|
8
|
+
return out;
|
|
9
|
+
}
|
|
10
|
+
function makeAbortError() {
|
|
11
|
+
if ("u" > typeof DOMException) return new DOMException("Operation aborted", "AbortError");
|
|
12
|
+
const error = new Error("Operation aborted");
|
|
13
|
+
error.name = "AbortError";
|
|
14
|
+
return error;
|
|
15
|
+
}
|
|
16
|
+
function createInMemoryDataSource(options) {
|
|
17
|
+
const { registry, upload, maxDepth } = options;
|
|
18
|
+
const folders = options.folderStore ?? createFolderStore();
|
|
19
|
+
const buildPage = (page, query)=>{
|
|
20
|
+
const base = {
|
|
21
|
+
items: page.items,
|
|
22
|
+
total: page.total,
|
|
23
|
+
nextCursor: page.nextCursor
|
|
24
|
+
};
|
|
25
|
+
if (void 0 === query.folderId) return base;
|
|
26
|
+
return {
|
|
27
|
+
...base,
|
|
28
|
+
folders: folders.listChildren(query.folderId),
|
|
29
|
+
folderPath: folders.path(query.folderId)
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
folders,
|
|
34
|
+
list (query) {
|
|
35
|
+
if (void 0 === query.folderId) return Promise.resolve(buildPage(registry.search(query), query));
|
|
36
|
+
const target = resolveFolderId(query.folderId);
|
|
37
|
+
const recursive = true === query.recursive;
|
|
38
|
+
const matchesFilter = prepareAssetMatcher(query);
|
|
39
|
+
let matches;
|
|
40
|
+
if (null === target) matches = registry.list().filter((entry)=>{
|
|
41
|
+
const folderOk = recursive || null === folders.folderOf(entry.id);
|
|
42
|
+
return folderOk && matchesFilter(entry);
|
|
43
|
+
});
|
|
44
|
+
else {
|
|
45
|
+
const ids = recursive ? collectSubtreeAssetIds(folders, target) : folders.directAssetIds(target);
|
|
46
|
+
matches = [];
|
|
47
|
+
for (const id of ids){
|
|
48
|
+
const entry = registry.get(id);
|
|
49
|
+
if (void 0 !== entry && matchesFilter(entry)) matches.push(entry);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return Promise.resolve(buildPage(paginateMatches(matches, query), query));
|
|
53
|
+
},
|
|
54
|
+
remove (id) {
|
|
55
|
+
registry.delete(id);
|
|
56
|
+
folders.removeAsset(id);
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
},
|
|
59
|
+
async replace (id, payload, signal) {
|
|
60
|
+
const result = await upload(payload, signal ? {
|
|
61
|
+
signal
|
|
62
|
+
} : void 0);
|
|
63
|
+
if (signal?.aborted) throw makeAbortError();
|
|
64
|
+
const replaced = registry.replace(id, result);
|
|
65
|
+
return replaced ?? result;
|
|
66
|
+
},
|
|
67
|
+
rename (id, name) {
|
|
68
|
+
const updated = registry.rename(id, name);
|
|
69
|
+
if (void 0 === updated) return Promise.reject(new AssetSourceError("ASSET_MUTATION_REJECTED", `Cannot rename unknown asset "${id}".`));
|
|
70
|
+
return Promise.resolve(updated);
|
|
71
|
+
},
|
|
72
|
+
move (id, folderId) {
|
|
73
|
+
folders.moveAsset(id, folderId);
|
|
74
|
+
return Promise.resolve();
|
|
75
|
+
},
|
|
76
|
+
createFolder (parentId, name) {
|
|
77
|
+
return Promise.resolve(folders.createFolder(parentId, name, maxDepth));
|
|
78
|
+
},
|
|
79
|
+
renameFolder (id, name) {
|
|
80
|
+
return Promise.resolve(folders.renameFolder(id, name));
|
|
81
|
+
},
|
|
82
|
+
removeFolder (id, opts) {
|
|
83
|
+
const { removedAssetIds } = folders.removeFolder(id, opts);
|
|
84
|
+
for (const assetId of removedAssetIds)registry.delete(assetId);
|
|
85
|
+
return Promise.resolve();
|
|
86
|
+
},
|
|
87
|
+
moveFolder (id, parentId) {
|
|
88
|
+
return Promise.resolve(folders.moveFolder(id, parentId, maxDepth));
|
|
89
|
+
},
|
|
90
|
+
subscribe (listener) {
|
|
91
|
+
const offRegistry = registry.subscribe(listener);
|
|
92
|
+
const offFolders = folders.subscribe(listener);
|
|
93
|
+
return ()=>{
|
|
94
|
+
offRegistry();
|
|
95
|
+
offFolders();
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
subscribeStatus (listener) {
|
|
99
|
+
listener({
|
|
100
|
+
phase: "idle"
|
|
101
|
+
});
|
|
102
|
+
return ()=>{};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const ASSET_PLANE = [
|
|
107
|
+
"list",
|
|
108
|
+
"remove",
|
|
109
|
+
"replace",
|
|
110
|
+
"rename",
|
|
111
|
+
"move"
|
|
112
|
+
];
|
|
113
|
+
const FOLDER_PLANE = [
|
|
114
|
+
"createFolder",
|
|
115
|
+
"renameFolder",
|
|
116
|
+
"removeFolder",
|
|
117
|
+
"moveFolder"
|
|
118
|
+
];
|
|
119
|
+
function resolveDataSource(input) {
|
|
120
|
+
const fallback = createInMemoryDataSource(input);
|
|
121
|
+
const host = input.hostDataSource;
|
|
122
|
+
if (void 0 === host) return fallback;
|
|
123
|
+
const ownsPlane = (plane, label)=>{
|
|
124
|
+
const provided = plane.filter((m)=>"function" == typeof host[m]);
|
|
125
|
+
if (0 === provided.length) return false;
|
|
126
|
+
if (provided.length === plane.length) return true;
|
|
127
|
+
input.warn?.(`asset-manager: dataSource provides a partial ${label} method set (${provided.join(", ")}) — falling back to the in-memory default for the whole ${label} plane. Provide all of {${plane.join(", ")}} or none.`);
|
|
128
|
+
return false;
|
|
129
|
+
};
|
|
130
|
+
const resolved = {
|
|
131
|
+
...fallback
|
|
132
|
+
};
|
|
133
|
+
if (ownsPlane(ASSET_PLANE, "asset")) {
|
|
134
|
+
resolved.list = host.list.bind(host);
|
|
135
|
+
resolved.remove = host.remove.bind(host);
|
|
136
|
+
resolved.replace = host.replace.bind(host);
|
|
137
|
+
resolved.rename = host.rename.bind(host);
|
|
138
|
+
resolved.move = host.move.bind(host);
|
|
139
|
+
}
|
|
140
|
+
if (ownsPlane(FOLDER_PLANE, "folder")) {
|
|
141
|
+
resolved.createFolder = host.createFolder.bind(host);
|
|
142
|
+
resolved.renameFolder = host.renameFolder.bind(host);
|
|
143
|
+
resolved.removeFolder = host.removeFolder.bind(host);
|
|
144
|
+
resolved.moveFolder = host.moveFolder.bind(host);
|
|
145
|
+
}
|
|
146
|
+
if ("function" == typeof host.subscribeStatus) resolved.subscribeStatus = host.subscribeStatus.bind(host);
|
|
147
|
+
return resolved;
|
|
148
|
+
}
|
|
149
|
+
export { createInMemoryDataSource, resolveDataSource };
|
package/dist/utils/errors.cjs
CHANGED
|
@@ -36,6 +36,21 @@ class AssetValidationError extends Error {
|
|
|
36
36
|
if (options && "cause" in options) this.cause = options.cause;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
class AssetSourceError extends Error {
|
|
40
|
+
code;
|
|
41
|
+
retryable;
|
|
42
|
+
status;
|
|
43
|
+
retryAfterMs;
|
|
44
|
+
constructor(code, message, options){
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = "AssetSourceError";
|
|
47
|
+
this.code = code;
|
|
48
|
+
this.retryable = options?.retryable ?? false;
|
|
49
|
+
this.status = options?.status;
|
|
50
|
+
this.retryAfterMs = options?.retryAfterMs;
|
|
51
|
+
if (options && "cause" in options) this.cause = options.cause;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
39
54
|
class AssetResolutionError extends Error {
|
|
40
55
|
assetId;
|
|
41
56
|
code;
|
|
@@ -49,12 +64,15 @@ class AssetResolutionError extends Error {
|
|
|
49
64
|
}
|
|
50
65
|
__webpack_require__.d(__webpack_exports__, {
|
|
51
66
|
AssetResolutionError: ()=>AssetResolutionError,
|
|
67
|
+
AssetSourceError: ()=>AssetSourceError,
|
|
52
68
|
AssetValidationError: ()=>AssetValidationError
|
|
53
69
|
});
|
|
54
70
|
exports.AssetResolutionError = __webpack_exports__.AssetResolutionError;
|
|
71
|
+
exports.AssetSourceError = __webpack_exports__.AssetSourceError;
|
|
55
72
|
exports.AssetValidationError = __webpack_exports__.AssetValidationError;
|
|
56
73
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
57
74
|
"AssetResolutionError",
|
|
75
|
+
"AssetSourceError",
|
|
58
76
|
"AssetValidationError"
|
|
59
77
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
60
78
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/utils/errors.d.cts
CHANGED
|
@@ -4,6 +4,33 @@ export declare class AssetValidationError extends Error {
|
|
|
4
4
|
readonly cause?: unknown;
|
|
5
5
|
});
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Failure codes raised by the async data-source / folder / external-provider
|
|
9
|
+
* surfaces (PRD 0002 §3.6). Distinct from {@link AssetValidationError}
|
|
10
|
+
* (upload validation) and {@link AssetResolutionError} (resolver domain) — in
|
|
11
|
+
* particular `ASSET_NOT_FOUND` belongs to the resolver, never here.
|
|
12
|
+
*/
|
|
13
|
+
export type AssetSourceErrorCode = "DATA_SOURCE_UNAVAILABLE" | "DATA_SOURCE_TIMEOUT" | "ASSET_MUTATION_REJECTED" | "FOLDER_NOT_FOUND" | "FOLDER_CYCLE" | "FOLDER_NAME_CONFLICT" | "FOLDER_NOT_EMPTY" | "MOVE_REJECTED" | "PROVIDER_RATE_LIMITED" | "PROVIDER_UNAUTHORIZED" | "PROVIDER_NETWORK" | "PROVIDER_BAD_RESPONSE" | "READ_ONLY_SOURCE" | "OPTIMISTIC_ROLLBACK";
|
|
14
|
+
/**
|
|
15
|
+
* Error for async catalog operations: host `dataSource` failures, folder
|
|
16
|
+
* mutations, and external `AssetSourceProvider` calls (e.g. Unsplash). Carries
|
|
17
|
+
* retry metadata so callers can drive backoff (`./retry`) without re-deriving
|
|
18
|
+
* it: `retryable` gates whether a retry is attempted at all, `status` mirrors
|
|
19
|
+
* an HTTP status (429, 401, …), and `retryAfterMs` is sourced from a
|
|
20
|
+
* `Retry-After` / `X-Ratelimit-Reset` header when present.
|
|
21
|
+
*/
|
|
22
|
+
export declare class AssetSourceError extends Error {
|
|
23
|
+
readonly code: AssetSourceErrorCode;
|
|
24
|
+
readonly retryable: boolean;
|
|
25
|
+
readonly status?: number;
|
|
26
|
+
readonly retryAfterMs?: number;
|
|
27
|
+
constructor(code: AssetSourceErrorCode, message: string, options?: {
|
|
28
|
+
readonly cause?: unknown;
|
|
29
|
+
readonly retryable?: boolean;
|
|
30
|
+
readonly status?: number;
|
|
31
|
+
readonly retryAfterMs?: number;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
7
34
|
export type AssetResolutionErrorCode = "ASSET_NOT_FOUND" | "ASSET_URL_REJECTED" | "ASSET_VALIDATION_FAILED";
|
|
8
35
|
export declare class AssetResolutionError extends Error {
|
|
9
36
|
readonly assetId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.cts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAGrB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAUvC;AAED,MAAM,MAAM,wBAAwB,GACjC,iBAAiB,GACjB,oBAAoB,GACpB,yBAAyB,CAAC;AAE7B,qBAAa,oBAAqB,SAAQ,KAA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AM,CAAC,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;KAC/B;CAaF;AAED,MAAM,MAAM,wBAAwB,GACjC,iBAAiB,GACjB,oBAAoB,GACpB,yBAAyB,CAAC;AAE7B,qBAAa,oBAAqB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;gBAGvC,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,wBAA4C,EAClD,OAAO,SAAyC,EAChD,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAWvC"}
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -4,6 +4,33 @@ export declare class AssetValidationError extends Error {
|
|
|
4
4
|
readonly cause?: unknown;
|
|
5
5
|
});
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Failure codes raised by the async data-source / folder / external-provider
|
|
9
|
+
* surfaces (PRD 0002 §3.6). Distinct from {@link AssetValidationError}
|
|
10
|
+
* (upload validation) and {@link AssetResolutionError} (resolver domain) — in
|
|
11
|
+
* particular `ASSET_NOT_FOUND` belongs to the resolver, never here.
|
|
12
|
+
*/
|
|
13
|
+
export type AssetSourceErrorCode = "DATA_SOURCE_UNAVAILABLE" | "DATA_SOURCE_TIMEOUT" | "ASSET_MUTATION_REJECTED" | "FOLDER_NOT_FOUND" | "FOLDER_CYCLE" | "FOLDER_NAME_CONFLICT" | "FOLDER_NOT_EMPTY" | "MOVE_REJECTED" | "PROVIDER_RATE_LIMITED" | "PROVIDER_UNAUTHORIZED" | "PROVIDER_NETWORK" | "PROVIDER_BAD_RESPONSE" | "READ_ONLY_SOURCE" | "OPTIMISTIC_ROLLBACK";
|
|
14
|
+
/**
|
|
15
|
+
* Error for async catalog operations: host `dataSource` failures, folder
|
|
16
|
+
* mutations, and external `AssetSourceProvider` calls (e.g. Unsplash). Carries
|
|
17
|
+
* retry metadata so callers can drive backoff (`./retry`) without re-deriving
|
|
18
|
+
* it: `retryable` gates whether a retry is attempted at all, `status` mirrors
|
|
19
|
+
* an HTTP status (429, 401, …), and `retryAfterMs` is sourced from a
|
|
20
|
+
* `Retry-After` / `X-Ratelimit-Reset` header when present.
|
|
21
|
+
*/
|
|
22
|
+
export declare class AssetSourceError extends Error {
|
|
23
|
+
readonly code: AssetSourceErrorCode;
|
|
24
|
+
readonly retryable: boolean;
|
|
25
|
+
readonly status?: number;
|
|
26
|
+
readonly retryAfterMs?: number;
|
|
27
|
+
constructor(code: AssetSourceErrorCode, message: string, options?: {
|
|
28
|
+
readonly cause?: unknown;
|
|
29
|
+
readonly retryable?: boolean;
|
|
30
|
+
readonly status?: number;
|
|
31
|
+
readonly retryAfterMs?: number;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
7
34
|
export type AssetResolutionErrorCode = "ASSET_NOT_FOUND" | "ASSET_URL_REJECTED" | "ASSET_VALIDATION_FAILED";
|
|
8
35
|
export declare class AssetResolutionError extends Error {
|
|
9
36
|
readonly assetId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAGrB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAUvC;AAED,MAAM,MAAM,wBAAwB,GACjC,iBAAiB,GACjB,oBAAoB,GACpB,yBAAyB,CAAC;AAE7B,qBAAa,oBAAqB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;gBAGvC,OAAO,EAAE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wB,GACjC,iBAAiB,GACjB,oBAAoB,GACpB,yBAAyB,CAAC;AAE7B,qBAAa,oBAAqB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;gBAGvC,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,wBAA4C,EAClD,OAAO,SAAyC,EAChD,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAWvC"}
|
package/dist/utils/errors.js
CHANGED
|
@@ -7,6 +7,21 @@ class AssetValidationError extends Error {
|
|
|
7
7
|
if (options && "cause" in options) this.cause = options.cause;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
+
class AssetSourceError extends Error {
|
|
11
|
+
code;
|
|
12
|
+
retryable;
|
|
13
|
+
status;
|
|
14
|
+
retryAfterMs;
|
|
15
|
+
constructor(code, message, options){
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "AssetSourceError";
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.retryable = options?.retryable ?? false;
|
|
20
|
+
this.status = options?.status;
|
|
21
|
+
this.retryAfterMs = options?.retryAfterMs;
|
|
22
|
+
if (options && "cause" in options) this.cause = options.cause;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
10
25
|
class AssetResolutionError extends Error {
|
|
11
26
|
assetId;
|
|
12
27
|
code;
|
|
@@ -18,4 +33,4 @@ class AssetResolutionError extends Error {
|
|
|
18
33
|
if (options && "cause" in options) this.cause = options.cause;
|
|
19
34
|
}
|
|
20
35
|
}
|
|
21
|
-
export { AssetResolutionError, AssetValidationError };
|
|
36
|
+
export { AssetResolutionError, AssetSourceError, AssetValidationError };
|