@anvilkit/plugin-asset-manager 0.1.6 → 0.1.7
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 +26 -18
- 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 +67 -4
- 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 +67 -4
- package/dist/sources/composite-source.cjs +137 -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 +99 -0
- package/dist/sources/federated-search.cjs +163 -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 +113 -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 +192 -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 +148 -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 +15 -27
- package/dist/types/types.d.cts.map +1 -1
- package/dist/types/types.d.ts +15 -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 +33 -12
- 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 +33 -12
- package/dist/ui/AssetManagerUI.cjs +8 -2
- 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 +8 -2
- package/dist/ui/DeleteFolderDialog.cjs +78 -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 +40 -0
- package/dist/ui/EmptyFolderState.cjs +53 -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 +15 -0
- package/dist/ui/FolderBreadcrumb.cjs +73 -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 +35 -0
- package/dist/ui/FolderNameDialog.cjs +98 -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 +60 -0
- package/dist/ui/FolderTree.cjs +83 -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 +42 -0
- package/dist/ui/MetadataPanel.cjs +7 -4
- package/dist/ui/MetadataPanel.d.cts.map +1 -1
- package/dist/ui/MetadataPanel.d.ts.map +1 -1
- package/dist/ui/MetadataPanel.js +7 -4
- package/dist/ui/MoveTargetPicker.cjs +84 -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 +46 -0
- 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/UnsplashPanel.cjs +134 -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 +96 -0
- package/dist/ui/UploadButton.cjs +1 -5
- 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 +1 -5
- package/dist/ui/index.cjs +37 -0
- package/dist/ui/index.d.cts +14 -0
- package/dist/ui/index.d.cts.map +1 -1
- package/dist/ui/index.d.ts +14 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +7 -0
- package/dist/utils/data-source.cjs +177 -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 +136 -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 +261 -0
- package/dist/utils/folders.d.cts +49 -0
- package/dist/utils/folders.d.cts.map +1 -0
- package/dist/utils/folders.d.ts +49 -0
- package/dist/utils/folders.d.ts.map +1 -0
- package/dist/utils/folders.js +223 -0
- package/dist/utils/registry.cjs +27 -12
- package/dist/utils/registry.d.cts +21 -1
- package/dist/utils/registry.d.cts.map +1 -1
- package/dist/utils/registry.d.ts +21 -1
- package/dist/utils/registry.d.ts.map +1 -1
- package/dist/utils/registry.js +20 -11
- package/dist/utils/studio-asset-source.cjs +5 -2
- 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 +1 -1
- 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/meta/config.json +1 -1
- package/package.json +12 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `CompositeAssetSource` (PRD 0002 §6.1, §8.1). Implements core's
|
|
3
|
+
* `StudioAssetSource` by routing reads + catalog mutations through the resolved
|
|
4
|
+
* `AssetDataSource` (so host backends and folder scoping work), while reusing
|
|
5
|
+
* the proven upload pipeline + projection from `createStudioAssetSource`.
|
|
6
|
+
*
|
|
7
|
+
* Lazy-loaded by the factory only when a host opts into a richer surface
|
|
8
|
+
* (`dataSource`/`providers`/`unsplash`), so flat callers never pull this — or
|
|
9
|
+
* the folder/data-source code it imports — into the headless entry chunk.
|
|
10
|
+
*/
|
|
11
|
+
import type { StudioAssetSource } from "@anvilkit/core/types";
|
|
12
|
+
import type { AssetFolder, FolderId } from "../types/folders.js";
|
|
13
|
+
import type { AssetRegistry, UploadResult } from "../types/types.js";
|
|
14
|
+
import type { ResolvedAssetDataSource, UploadFn } from "../utils/data-source.js";
|
|
15
|
+
import type { AssetSourceProvider } from "./provider.js";
|
|
16
|
+
export interface CreateCompositeAssetSourceOptions {
|
|
17
|
+
readonly source: ResolvedAssetDataSource;
|
|
18
|
+
readonly registry: AssetRegistry;
|
|
19
|
+
readonly upload: UploadFn;
|
|
20
|
+
readonly getThumbnail?: (entry: UploadResult) => string | undefined;
|
|
21
|
+
/** External read-only sources (e.g. Unsplash) federated alongside the local library. */
|
|
22
|
+
readonly providers?: readonly AssetSourceProvider[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The core `StudioAssetSource` plus the folder methods the plugin's `./ui` and
|
|
26
|
+
* (Phase 2) core `ImageModule` consume. The folder methods are additive — core
|
|
27
|
+
* ignores what it doesn't know until its sidebar types adopt them.
|
|
28
|
+
*/
|
|
29
|
+
export interface CompositeAssetSource extends StudioAssetSource {
|
|
30
|
+
createFolder(parentId: FolderId | null, name: string): Promise<AssetFolder>;
|
|
31
|
+
renameFolder(id: FolderId, name: string): Promise<AssetFolder>;
|
|
32
|
+
removeFolder(id: FolderId, opts?: {
|
|
33
|
+
readonly cascade?: boolean;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
moveFolder(id: FolderId, parentId: FolderId | null): Promise<AssetFolder>;
|
|
36
|
+
moveAsset(assetId: string, folderId: FolderId | null): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export declare function createCompositeAssetSource(options: CreateCompositeAssetSourceOptions): CompositeAssetSource;
|
|
39
|
+
//# sourceMappingURL=composite-source.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composite-source.d.cts","sourceRoot":"","sources":["../../src/sources/composite-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAIX,iBAAiB,EAEjB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,KAAK,EACX,uBAAuB,EACvB,QAAQ,EACR,MAAM,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,MAAM,WAAW,iCAAiC;IACjD,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,MAAM,GAAG,SAAS,CAAC;IACpE,wFAAwF;IACxF,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACpD;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC9D,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5E,YAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/D,YAAY,CACX,EAAE,EAAE,QAAQ,EACZ,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GACnC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1E,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,iCAAiC,GACxC,oBAAoB,CA8HtB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `CompositeAssetSource` (PRD 0002 §6.1, §8.1). Implements core's
|
|
3
|
+
* `StudioAssetSource` by routing reads + catalog mutations through the resolved
|
|
4
|
+
* `AssetDataSource` (so host backends and folder scoping work), while reusing
|
|
5
|
+
* the proven upload pipeline + projection from `createStudioAssetSource`.
|
|
6
|
+
*
|
|
7
|
+
* Lazy-loaded by the factory only when a host opts into a richer surface
|
|
8
|
+
* (`dataSource`/`providers`/`unsplash`), so flat callers never pull this — or
|
|
9
|
+
* the folder/data-source code it imports — into the headless entry chunk.
|
|
10
|
+
*/
|
|
11
|
+
import type { StudioAssetSource } from "@anvilkit/core/types";
|
|
12
|
+
import type { AssetFolder, FolderId } from "../types/folders.js";
|
|
13
|
+
import type { AssetRegistry, UploadResult } from "../types/types.js";
|
|
14
|
+
import type { ResolvedAssetDataSource, UploadFn } from "../utils/data-source.js";
|
|
15
|
+
import type { AssetSourceProvider } from "./provider.js";
|
|
16
|
+
export interface CreateCompositeAssetSourceOptions {
|
|
17
|
+
readonly source: ResolvedAssetDataSource;
|
|
18
|
+
readonly registry: AssetRegistry;
|
|
19
|
+
readonly upload: UploadFn;
|
|
20
|
+
readonly getThumbnail?: (entry: UploadResult) => string | undefined;
|
|
21
|
+
/** External read-only sources (e.g. Unsplash) federated alongside the local library. */
|
|
22
|
+
readonly providers?: readonly AssetSourceProvider[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The core `StudioAssetSource` plus the folder methods the plugin's `./ui` and
|
|
26
|
+
* (Phase 2) core `ImageModule` consume. The folder methods are additive — core
|
|
27
|
+
* ignores what it doesn't know until its sidebar types adopt them.
|
|
28
|
+
*/
|
|
29
|
+
export interface CompositeAssetSource extends StudioAssetSource {
|
|
30
|
+
createFolder(parentId: FolderId | null, name: string): Promise<AssetFolder>;
|
|
31
|
+
renameFolder(id: FolderId, name: string): Promise<AssetFolder>;
|
|
32
|
+
removeFolder(id: FolderId, opts?: {
|
|
33
|
+
readonly cascade?: boolean;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
moveFolder(id: FolderId, parentId: FolderId | null): Promise<AssetFolder>;
|
|
36
|
+
moveAsset(assetId: string, folderId: FolderId | null): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export declare function createCompositeAssetSource(options: CreateCompositeAssetSourceOptions): CompositeAssetSource;
|
|
39
|
+
//# sourceMappingURL=composite-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composite-source.d.ts","sourceRoot":"","sources":["../../src/sources/composite-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAIX,iBAAiB,EAEjB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,KAAK,EACX,uBAAuB,EACvB,QAAQ,EACR,MAAM,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,MAAM,WAAW,iCAAiC;IACjD,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,MAAM,GAAG,SAAS,CAAC;IACpE,wFAAwF;IACxF,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACpD;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC9D,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5E,YAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/D,YAAY,CACX,EAAE,EAAE,QAAQ,EACZ,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GACnC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1E,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,iCAAiC,GACxC,oBAAoB,CA8HtB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createAssetReference } from "../utils/asset-reference.js";
|
|
2
|
+
import { createStudioAssetSource, toStudioAsset } from "../utils/studio-asset-source.js";
|
|
3
|
+
import { createLocalProvider, federatedSearch } from "./federated-search.js";
|
|
4
|
+
function createCompositeAssetSource(options) {
|
|
5
|
+
const { source, registry, upload, getThumbnail } = options;
|
|
6
|
+
const base = createStudioAssetSource({
|
|
7
|
+
registry,
|
|
8
|
+
upload,
|
|
9
|
+
...getThumbnail ? {
|
|
10
|
+
getThumbnail
|
|
11
|
+
} : {}
|
|
12
|
+
});
|
|
13
|
+
const project = (entry)=>{
|
|
14
|
+
const attribution = entry.meta?.attribution;
|
|
15
|
+
const isExternal = entry.id.startsWith("unsplash:");
|
|
16
|
+
return {
|
|
17
|
+
...toStudioAsset(entry, getThumbnail),
|
|
18
|
+
...isExternal ? {
|
|
19
|
+
url: entry.url
|
|
20
|
+
} : {},
|
|
21
|
+
folderId: source.folders.folderOf(entry.id),
|
|
22
|
+
source: isExternal ? "unsplash" : "local",
|
|
23
|
+
...attribution ? {
|
|
24
|
+
attribution: {
|
|
25
|
+
photographerName: attribution.photographerName,
|
|
26
|
+
photographerUrl: attribution.photographerUrl,
|
|
27
|
+
sourceUrl: attribution.unsplashUrl
|
|
28
|
+
}
|
|
29
|
+
} : {}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const providers = [
|
|
33
|
+
createLocalProvider(source, registry),
|
|
34
|
+
...options.providers ?? []
|
|
35
|
+
];
|
|
36
|
+
const runList = (filter, signal)=>1 === providers.length ? source.list(filter, signal) : federatedSearch({
|
|
37
|
+
providers,
|
|
38
|
+
filter,
|
|
39
|
+
signal
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
async list () {
|
|
43
|
+
const page = await runList({});
|
|
44
|
+
return Object.freeze(page.items.map(project));
|
|
45
|
+
},
|
|
46
|
+
async listPaginated (query) {
|
|
47
|
+
const page = await runList({
|
|
48
|
+
...query
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
items: Object.freeze(page.items.map(project)),
|
|
52
|
+
total: page.total,
|
|
53
|
+
nextCursor: page.nextCursor,
|
|
54
|
+
...page.folders ? {
|
|
55
|
+
folders: page.folders
|
|
56
|
+
} : {},
|
|
57
|
+
...page.folderPath ? {
|
|
58
|
+
folderPath: page.folderPath
|
|
59
|
+
} : {},
|
|
60
|
+
...page.sourceCursors ? {
|
|
61
|
+
sourceCursors: page.sourceCursors
|
|
62
|
+
} : {}
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
upload: base.upload,
|
|
66
|
+
setTags: base.setTags,
|
|
67
|
+
subscribeUploads: base.subscribeUploads,
|
|
68
|
+
getUrl: (assetId)=>createAssetReference(assetId),
|
|
69
|
+
async delete (assetId) {
|
|
70
|
+
await source.remove(assetId);
|
|
71
|
+
},
|
|
72
|
+
async rename (assetId, nextName) {
|
|
73
|
+
await source.rename(assetId, nextName);
|
|
74
|
+
},
|
|
75
|
+
async replace (assetId, file) {
|
|
76
|
+
return project(await source.replace(assetId, file));
|
|
77
|
+
},
|
|
78
|
+
subscribe: (listener)=>source.subscribe(listener),
|
|
79
|
+
createFolder: (parentId, name)=>source.createFolder(parentId, name),
|
|
80
|
+
renameFolder: (id, name)=>source.renameFolder(id, name),
|
|
81
|
+
removeFolder: (id, opts)=>source.removeFolder(id, opts),
|
|
82
|
+
moveFolder: (id, parentId)=>source.moveFolder(id, parentId),
|
|
83
|
+
moveAsset: (assetId, folderId)=>source.move(assetId, folderId),
|
|
84
|
+
async pickResult (asset) {
|
|
85
|
+
const provider = providers.find((p)=>p.id === asset.source);
|
|
86
|
+
if (void 0 === provider || "local" === provider.id) return asset;
|
|
87
|
+
const result = await provider.pickResult(asset);
|
|
88
|
+
registry.register(result);
|
|
89
|
+
return project(result);
|
|
90
|
+
},
|
|
91
|
+
subscribeStatus: (listener)=>source.subscribeStatus(listener),
|
|
92
|
+
async listThemes () {
|
|
93
|
+
const themes = [];
|
|
94
|
+
for (const provider of providers)if ("local" !== provider.id) themes.push(...await provider.listThemes());
|
|
95
|
+
return themes;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export { createCompositeAssetSource };
|
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
createLocalProvider: ()=>createLocalProvider,
|
|
32
|
+
decodeCompositeCursor: ()=>decodeCompositeCursor,
|
|
33
|
+
encodeCompositeCursor: ()=>encodeCompositeCursor,
|
|
34
|
+
federatedSearch: ()=>federatedSearch,
|
|
35
|
+
providerCanSatisfy: ()=>providerCanSatisfy
|
|
36
|
+
});
|
|
37
|
+
const infer_kind_cjs_namespaceObject = require("../utils/infer-kind.cjs");
|
|
38
|
+
function toBase64Url(json) {
|
|
39
|
+
return btoa(json).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
40
|
+
}
|
|
41
|
+
function fromBase64Url(token) {
|
|
42
|
+
const padded = token.length % 4 === 0 ? token : token + "=".repeat(4 - token.length % 4);
|
|
43
|
+
return atob(padded.replace(/-/g, "+").replace(/_/g, "/"));
|
|
44
|
+
}
|
|
45
|
+
function encodeCompositeCursor(cursor) {
|
|
46
|
+
return toBase64Url(JSON.stringify(cursor));
|
|
47
|
+
}
|
|
48
|
+
function decodeCompositeCursor(token) {
|
|
49
|
+
if (void 0 === token || "" === token) return {};
|
|
50
|
+
try {
|
|
51
|
+
const parsed = JSON.parse(fromBase64Url(token));
|
|
52
|
+
return "object" == typeof parsed && null !== parsed ? parsed : {};
|
|
53
|
+
} catch {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function providerCanSatisfy(provider, filter) {
|
|
58
|
+
if (void 0 !== filter.folderId && true !== provider.capabilities.folders) return false;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
function createLocalProvider(source, registry, label = "assetManager.source.library") {
|
|
62
|
+
return {
|
|
63
|
+
id: "local",
|
|
64
|
+
label,
|
|
65
|
+
capabilities: {
|
|
66
|
+
searchable: true,
|
|
67
|
+
themed: false,
|
|
68
|
+
mutable: true,
|
|
69
|
+
requiresAttribution: false,
|
|
70
|
+
folders: true
|
|
71
|
+
},
|
|
72
|
+
listThemes: ()=>[],
|
|
73
|
+
search: (filter, page, signal)=>source.list(void 0 !== page ? {
|
|
74
|
+
...filter,
|
|
75
|
+
cursor: page
|
|
76
|
+
} : filter, signal),
|
|
77
|
+
pickResult: async (asset)=>registry.get(asset.id) ?? {
|
|
78
|
+
id: asset.id,
|
|
79
|
+
url: asset.url
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function sortKey(entry, field) {
|
|
84
|
+
switch(field){
|
|
85
|
+
case "name":
|
|
86
|
+
return (entry.name ?? "").toLowerCase();
|
|
87
|
+
case "size":
|
|
88
|
+
return entry.meta?.size ?? 0;
|
|
89
|
+
case "kind":
|
|
90
|
+
return (0, infer_kind_cjs_namespaceObject.inferAssetKind)(entry);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function compareEntries(a, b, field) {
|
|
94
|
+
const ka = sortKey(a, field);
|
|
95
|
+
const kb = sortKey(b, field);
|
|
96
|
+
if ("number" == typeof ka && "number" == typeof kb) return ka - kb;
|
|
97
|
+
return String(ka).localeCompare(String(kb));
|
|
98
|
+
}
|
|
99
|
+
function mergePages(pages, filter) {
|
|
100
|
+
const field = filter.sort?.field ?? "recent";
|
|
101
|
+
const comparable = "name" === field || "size" === field || "kind" === field;
|
|
102
|
+
const items = pages.flatMap((p)=>[
|
|
103
|
+
...p.page.items
|
|
104
|
+
]);
|
|
105
|
+
if (comparable) {
|
|
106
|
+
const dir = filter.sort?.direction ?? ("name" === field ? "asc" : "desc");
|
|
107
|
+
const sign = "asc" === dir ? 1 : -1;
|
|
108
|
+
items.sort((a, b)=>compareEntries(a, b, field) * sign);
|
|
109
|
+
}
|
|
110
|
+
const total = pages.reduce((n, p)=>n + p.page.total, 0);
|
|
111
|
+
const sourceCursors = {};
|
|
112
|
+
const next = {};
|
|
113
|
+
let hasNext = false;
|
|
114
|
+
for (const { provider, page } of pages){
|
|
115
|
+
sourceCursors[provider.id] = page.nextCursor;
|
|
116
|
+
if (void 0 !== page.nextCursor) {
|
|
117
|
+
next[provider.id] = page.nextCursor;
|
|
118
|
+
hasNext = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
items: Object.freeze(items),
|
|
123
|
+
total,
|
|
124
|
+
nextCursor: hasNext ? encodeCompositeCursor(next) : void 0,
|
|
125
|
+
sourceCursors
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async function federatedSearch(input) {
|
|
129
|
+
const { providers, filter, signal } = input;
|
|
130
|
+
const eligible = providers.filter((p)=>providerCanSatisfy(p, filter));
|
|
131
|
+
const targets = filter.sources && filter.sources.length > 0 ? eligible.filter((p)=>filter.sources?.includes(p.id)) : eligible;
|
|
132
|
+
if (0 === targets.length) return {
|
|
133
|
+
items: Object.freeze([]),
|
|
134
|
+
total: 0,
|
|
135
|
+
nextCursor: void 0
|
|
136
|
+
};
|
|
137
|
+
const cursors = decodeCompositeCursor(filter.cursor);
|
|
138
|
+
const settled = await Promise.allSettled(targets.map((p)=>p.search(filter, cursors[p.id], signal)));
|
|
139
|
+
const ok = [];
|
|
140
|
+
settled.forEach((result, index)=>{
|
|
141
|
+
const provider = targets[index];
|
|
142
|
+
if (void 0 !== provider && "fulfilled" === result.status) ok.push({
|
|
143
|
+
provider,
|
|
144
|
+
page: result.value
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
return mergePages(ok, filter);
|
|
148
|
+
}
|
|
149
|
+
exports.createLocalProvider = __webpack_exports__.createLocalProvider;
|
|
150
|
+
exports.decodeCompositeCursor = __webpack_exports__.decodeCompositeCursor;
|
|
151
|
+
exports.encodeCompositeCursor = __webpack_exports__.encodeCompositeCursor;
|
|
152
|
+
exports.federatedSearch = __webpack_exports__.federatedSearch;
|
|
153
|
+
exports.providerCanSatisfy = __webpack_exports__.providerCanSatisfy;
|
|
154
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
155
|
+
"createLocalProvider",
|
|
156
|
+
"decodeCompositeCursor",
|
|
157
|
+
"encodeCompositeCursor",
|
|
158
|
+
"federatedSearch",
|
|
159
|
+
"providerCanSatisfy"
|
|
160
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
161
|
+
Object.defineProperty(exports, '__esModule', {
|
|
162
|
+
value: true
|
|
163
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Federated search across asset source providers (PRD 0002 §9.3).
|
|
3
|
+
*
|
|
4
|
+
* Routes a single-source query to one provider, or federates across many with
|
|
5
|
+
* `Promise.allSettled` (one failing remote never blanks the rest). The page
|
|
6
|
+
* cursor is an OPAQUE composite token carrying one sub-cursor per source, so
|
|
7
|
+
* each provider paginates independently. Comparable sorts (name/size/kind) are
|
|
8
|
+
* k-way merged; `recent`/`relevance` fall back to provider-grouped order
|
|
9
|
+
* (incomparable across heterogeneous sources).
|
|
10
|
+
*/
|
|
11
|
+
import type { AssetFilter, AssetListPage } from "../types/filter.js";
|
|
12
|
+
import type { AssetRegistry } from "../types/types.js";
|
|
13
|
+
import type { ResolvedAssetDataSource } from "../utils/data-source.js";
|
|
14
|
+
import type { AssetSourceProvider } from "./provider.js";
|
|
15
|
+
type CompositeCursor = Record<string, string | undefined>;
|
|
16
|
+
export declare function encodeCompositeCursor(cursor: CompositeCursor): string;
|
|
17
|
+
export declare function decodeCompositeCursor(token: string | undefined): CompositeCursor;
|
|
18
|
+
/** A provider is eligible only if it can satisfy every required axis of the filter. */
|
|
19
|
+
export declare function providerCanSatisfy(provider: AssetSourceProvider, filter: AssetFilter): boolean;
|
|
20
|
+
/** Adapt the resolved (local) data source into an `AssetSourceProvider`. */
|
|
21
|
+
export declare function createLocalProvider(source: ResolvedAssetDataSource, registry: AssetRegistry, label?: string): AssetSourceProvider;
|
|
22
|
+
export interface FederatedSearchInput {
|
|
23
|
+
readonly providers: readonly AssetSourceProvider[];
|
|
24
|
+
readonly filter: AssetFilter;
|
|
25
|
+
readonly signal?: AbortSignal;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Run a filter across providers. `filter.sources` naming exactly one provider
|
|
29
|
+
* ROUTES to it (zero other calls); otherwise eligible providers FEDERATE.
|
|
30
|
+
*/
|
|
31
|
+
export declare function federatedSearch(input: FederatedSearchInput): Promise<AssetListPage>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=federated-search.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"federated-search.d.cts","sourceRoot":"","sources":["../../src/sources/federated-search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAY1D,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAErE;AAED,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,MAAM,GAAG,SAAS,GACvB,eAAe,CAUjB;AAED,uFAAuF;AACvF,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,mBAAmB,EAC7B,MAAM,EAAE,WAAW,GACjB,OAAO,CAKT;AAED,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,uBAAuB,EAC/B,QAAQ,EAAE,aAAa,EACvB,KAAK,SAAgC,GACnC,mBAAmB,CAqBrB;AA+DD,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,SAAS,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACpC,KAAK,EAAE,oBAAoB,GACzB,OAAO,CAAC,aAAa,CAAC,CA4BxB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Federated search across asset source providers (PRD 0002 §9.3).
|
|
3
|
+
*
|
|
4
|
+
* Routes a single-source query to one provider, or federates across many with
|
|
5
|
+
* `Promise.allSettled` (one failing remote never blanks the rest). The page
|
|
6
|
+
* cursor is an OPAQUE composite token carrying one sub-cursor per source, so
|
|
7
|
+
* each provider paginates independently. Comparable sorts (name/size/kind) are
|
|
8
|
+
* k-way merged; `recent`/`relevance` fall back to provider-grouped order
|
|
9
|
+
* (incomparable across heterogeneous sources).
|
|
10
|
+
*/
|
|
11
|
+
import type { AssetFilter, AssetListPage } from "../types/filter.js";
|
|
12
|
+
import type { AssetRegistry } from "../types/types.js";
|
|
13
|
+
import type { ResolvedAssetDataSource } from "../utils/data-source.js";
|
|
14
|
+
import type { AssetSourceProvider } from "./provider.js";
|
|
15
|
+
type CompositeCursor = Record<string, string | undefined>;
|
|
16
|
+
export declare function encodeCompositeCursor(cursor: CompositeCursor): string;
|
|
17
|
+
export declare function decodeCompositeCursor(token: string | undefined): CompositeCursor;
|
|
18
|
+
/** A provider is eligible only if it can satisfy every required axis of the filter. */
|
|
19
|
+
export declare function providerCanSatisfy(provider: AssetSourceProvider, filter: AssetFilter): boolean;
|
|
20
|
+
/** Adapt the resolved (local) data source into an `AssetSourceProvider`. */
|
|
21
|
+
export declare function createLocalProvider(source: ResolvedAssetDataSource, registry: AssetRegistry, label?: string): AssetSourceProvider;
|
|
22
|
+
export interface FederatedSearchInput {
|
|
23
|
+
readonly providers: readonly AssetSourceProvider[];
|
|
24
|
+
readonly filter: AssetFilter;
|
|
25
|
+
readonly signal?: AbortSignal;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Run a filter across providers. `filter.sources` naming exactly one provider
|
|
29
|
+
* ROUTES to it (zero other calls); otherwise eligible providers FEDERATE.
|
|
30
|
+
*/
|
|
31
|
+
export declare function federatedSearch(input: FederatedSearchInput): Promise<AssetListPage>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=federated-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"federated-search.d.ts","sourceRoot":"","sources":["../../src/sources/federated-search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAY1D,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAErE;AAED,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,MAAM,GAAG,SAAS,GACvB,eAAe,CAUjB;AAED,uFAAuF;AACvF,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,mBAAmB,EAC7B,MAAM,EAAE,WAAW,GACjB,OAAO,CAKT;AAED,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,uBAAuB,EAC/B,QAAQ,EAAE,aAAa,EACvB,KAAK,SAAgC,GACnC,mBAAmB,CAqBrB;AA+DD,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,SAAS,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACpC,KAAK,EAAE,oBAAoB,GACzB,OAAO,CAAC,aAAa,CAAC,CA4BxB"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { inferAssetKind } from "../utils/infer-kind.js";
|
|
2
|
+
function toBase64Url(json) {
|
|
3
|
+
return btoa(json).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
4
|
+
}
|
|
5
|
+
function fromBase64Url(token) {
|
|
6
|
+
const padded = token.length % 4 === 0 ? token : token + "=".repeat(4 - token.length % 4);
|
|
7
|
+
return atob(padded.replace(/-/g, "+").replace(/_/g, "/"));
|
|
8
|
+
}
|
|
9
|
+
function encodeCompositeCursor(cursor) {
|
|
10
|
+
return toBase64Url(JSON.stringify(cursor));
|
|
11
|
+
}
|
|
12
|
+
function decodeCompositeCursor(token) {
|
|
13
|
+
if (void 0 === token || "" === token) return {};
|
|
14
|
+
try {
|
|
15
|
+
const parsed = JSON.parse(fromBase64Url(token));
|
|
16
|
+
return "object" == typeof parsed && null !== parsed ? parsed : {};
|
|
17
|
+
} catch {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function providerCanSatisfy(provider, filter) {
|
|
22
|
+
if (void 0 !== filter.folderId && true !== provider.capabilities.folders) return false;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
function createLocalProvider(source, registry, label = "assetManager.source.library") {
|
|
26
|
+
return {
|
|
27
|
+
id: "local",
|
|
28
|
+
label,
|
|
29
|
+
capabilities: {
|
|
30
|
+
searchable: true,
|
|
31
|
+
themed: false,
|
|
32
|
+
mutable: true,
|
|
33
|
+
requiresAttribution: false,
|
|
34
|
+
folders: true
|
|
35
|
+
},
|
|
36
|
+
listThemes: ()=>[],
|
|
37
|
+
search: (filter, page, signal)=>source.list(void 0 !== page ? {
|
|
38
|
+
...filter,
|
|
39
|
+
cursor: page
|
|
40
|
+
} : filter, signal),
|
|
41
|
+
pickResult: async (asset)=>registry.get(asset.id) ?? {
|
|
42
|
+
id: asset.id,
|
|
43
|
+
url: asset.url
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function sortKey(entry, field) {
|
|
48
|
+
switch(field){
|
|
49
|
+
case "name":
|
|
50
|
+
return (entry.name ?? "").toLowerCase();
|
|
51
|
+
case "size":
|
|
52
|
+
return entry.meta?.size ?? 0;
|
|
53
|
+
case "kind":
|
|
54
|
+
return inferAssetKind(entry);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function compareEntries(a, b, field) {
|
|
58
|
+
const ka = sortKey(a, field);
|
|
59
|
+
const kb = sortKey(b, field);
|
|
60
|
+
if ("number" == typeof ka && "number" == typeof kb) return ka - kb;
|
|
61
|
+
return String(ka).localeCompare(String(kb));
|
|
62
|
+
}
|
|
63
|
+
function mergePages(pages, filter) {
|
|
64
|
+
const field = filter.sort?.field ?? "recent";
|
|
65
|
+
const comparable = "name" === field || "size" === field || "kind" === field;
|
|
66
|
+
const items = pages.flatMap((p)=>[
|
|
67
|
+
...p.page.items
|
|
68
|
+
]);
|
|
69
|
+
if (comparable) {
|
|
70
|
+
const dir = filter.sort?.direction ?? ("name" === field ? "asc" : "desc");
|
|
71
|
+
const sign = "asc" === dir ? 1 : -1;
|
|
72
|
+
items.sort((a, b)=>compareEntries(a, b, field) * sign);
|
|
73
|
+
}
|
|
74
|
+
const total = pages.reduce((n, p)=>n + p.page.total, 0);
|
|
75
|
+
const sourceCursors = {};
|
|
76
|
+
const next = {};
|
|
77
|
+
let hasNext = false;
|
|
78
|
+
for (const { provider, page } of pages){
|
|
79
|
+
sourceCursors[provider.id] = page.nextCursor;
|
|
80
|
+
if (void 0 !== page.nextCursor) {
|
|
81
|
+
next[provider.id] = page.nextCursor;
|
|
82
|
+
hasNext = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
items: Object.freeze(items),
|
|
87
|
+
total,
|
|
88
|
+
nextCursor: hasNext ? encodeCompositeCursor(next) : void 0,
|
|
89
|
+
sourceCursors
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async function federatedSearch(input) {
|
|
93
|
+
const { providers, filter, signal } = input;
|
|
94
|
+
const eligible = providers.filter((p)=>providerCanSatisfy(p, filter));
|
|
95
|
+
const targets = filter.sources && filter.sources.length > 0 ? eligible.filter((p)=>filter.sources?.includes(p.id)) : eligible;
|
|
96
|
+
if (0 === targets.length) return {
|
|
97
|
+
items: Object.freeze([]),
|
|
98
|
+
total: 0,
|
|
99
|
+
nextCursor: void 0
|
|
100
|
+
};
|
|
101
|
+
const cursors = decodeCompositeCursor(filter.cursor);
|
|
102
|
+
const settled = await Promise.allSettled(targets.map((p)=>p.search(filter, cursors[p.id], signal)));
|
|
103
|
+
const ok = [];
|
|
104
|
+
settled.forEach((result, index)=>{
|
|
105
|
+
const provider = targets[index];
|
|
106
|
+
if (void 0 !== provider && "fulfilled" === result.status) ok.push({
|
|
107
|
+
provider,
|
|
108
|
+
page: result.value
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
return mergePages(ok, filter);
|
|
112
|
+
}
|
|
113
|
+
export { createLocalProvider, decodeCompositeCursor, encodeCompositeCursor, federatedSearch, providerCanSatisfy };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file External read-only source provider contract (PRD 0002 §3.4, §8).
|
|
3
|
+
*
|
|
4
|
+
* Unsplash (and any host-defined stock source) implements this. All providers
|
|
5
|
+
* compose behind the single `StudioAssetSource` the plugin registers; the
|
|
6
|
+
* built-in `local` provider wraps the resolved `AssetDataSource`. These are
|
|
7
|
+
* types only — erased at runtime, zero bytes in any chunk.
|
|
8
|
+
*/
|
|
9
|
+
import type { StudioAsset } from "@anvilkit/core/types";
|
|
10
|
+
import type { AssetFilter, AssetListPage, AssetSourceId } from "../types/filter.js";
|
|
11
|
+
import type { UploadResult } from "../types/types.js";
|
|
12
|
+
export interface AssetSourceCapabilities {
|
|
13
|
+
readonly searchable: boolean;
|
|
14
|
+
readonly themed: boolean;
|
|
15
|
+
/** Unsplash = false (browse + insert only). */
|
|
16
|
+
readonly mutable: boolean;
|
|
17
|
+
/** Unsplash = true. */
|
|
18
|
+
readonly requiresAttribution: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Supports folder scoping. Only the local library provider sets this; a
|
|
21
|
+
* folder-scoped query (`AssetFilter.folderId`) drops providers without it
|
|
22
|
+
* from the federation. Defaults to `false` when omitted.
|
|
23
|
+
*/
|
|
24
|
+
readonly folders?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface AssetTheme {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
/** i18n message key (not inline copy). */
|
|
29
|
+
readonly label: string;
|
|
30
|
+
readonly description?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface AssetSourceProvider {
|
|
33
|
+
/** `"unsplash"` | host id. The built-in `"local"` provider wraps the data source. */
|
|
34
|
+
readonly id: AssetSourceId;
|
|
35
|
+
readonly label: string;
|
|
36
|
+
readonly capabilities: AssetSourceCapabilities;
|
|
37
|
+
/** Content-Security-Policy hosts this provider needs (e.g. Unsplash img/connect src). */
|
|
38
|
+
readonly requiredCsp?: () => {
|
|
39
|
+
readonly connectSrc?: readonly string[];
|
|
40
|
+
readonly imgSrc?: readonly string[];
|
|
41
|
+
};
|
|
42
|
+
listThemes(): readonly AssetTheme[] | Promise<readonly AssetTheme[]>;
|
|
43
|
+
search(query: AssetFilter, page: string | undefined, signal?: AbortSignal): Promise<AssetListPage>;
|
|
44
|
+
/**
|
|
45
|
+
* Convert a browsed result into a real asset (fires the source's
|
|
46
|
+
* download-trigger / attribution work) and feed it into the existing
|
|
47
|
+
* registry → IR → `asset://` pipeline.
|
|
48
|
+
*/
|
|
49
|
+
pickResult(asset: StudioAsset, signal?: AbortSignal): Promise<UploadResult>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=provider.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.cts","sourceRoot":"","sources":["../../src/sources/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EACX,WAAW,EACX,aAAa,EACb,aAAa,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,uBAAuB;IACvB,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,mBAAmB;IACnC,qFAAqF;IACrF,QAAQ,CAAC,EAAE,EAAE,aAAa,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,uBAAuB,CAAC;IAC/C,yFAAyF;IACzF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM;QAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;QACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;KACpC,CAAC;IACF,UAAU,IAAI,SAAS,UAAU,EAAE,GAAG,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAAC;IACrE,MAAM,CACL,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1B;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC5E"}
|