@webiny/api-file-manager 6.6.0-alpha.0 → 6.6.0-alpha.10
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/FileManagerAppFeature.js +4 -4
- package/FileManagerAppFeature.js.map +1 -1
- package/delivery/AssetDelivery/AssetRequest.d.ts +1 -1
- package/delivery/AssetDelivery/AssetRequest.js.map +1 -1
- package/delivery/AssetDeliveryRoute.d.ts +16 -6
- package/delivery/AssetDeliveryRoute.js +38 -34
- package/delivery/AssetDeliveryRoute.js.map +1 -1
- package/domain/file/abstractions.d.ts +13 -5
- package/domain/file/abstractions.js +2 -2
- package/domain/file/abstractions.js.map +1 -1
- package/domain/file/errors.d.ts +10 -0
- package/domain/file/errors.js +9 -1
- package/domain/file/errors.js.map +1 -1
- package/domain/file/file.model.d.ts +3 -3
- package/domain/file/file.model.js +12 -7
- package/domain/file/file.model.js.map +1 -1
- package/domain/file/validateFileKey.d.ts +10 -0
- package/domain/file/validateFileKey.js +15 -0
- package/domain/file/validateFileKey.js.map +1 -0
- package/domain/settings/validation.d.ts +1 -1
- package/domain/settings/validation.js +3 -10
- package/domain/settings/validation.js.map +1 -1
- package/exports/api/file-manager/file.d.ts +2 -1
- package/exports/api/file-manager/file.js +2 -1
- package/features/FileManagerFeature.js +2 -0
- package/features/FileManagerFeature.js.map +1 -1
- package/features/assetDelivery/abstractions/AssetType.d.ts +17 -0
- package/features/assetDelivery/abstractions/AssetType.js +5 -0
- package/features/assetDelivery/abstractions/AssetType.js.map +1 -0
- package/features/assetDelivery/{transformation → assetTypes/image}/AssetKeyGenerator.d.ts +5 -2
- package/features/assetDelivery/assetTypes/image/AssetKeyGenerator.js +30 -0
- package/features/assetDelivery/assetTypes/image/AssetKeyGenerator.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetType.d.ts +9 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetType.js +18 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetType.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetTypeHandler.d.ts +5 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetTypeHandler.js +5 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetTypeHandler.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/SharpTransformer.d.ts +18 -0
- package/features/assetDelivery/assetTypes/image/SharpTransformer.js +47 -0
- package/features/assetDelivery/assetTypes/image/SharpTransformer.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/WidthCollection.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/imageFormat.d.ts +26 -0
- package/features/assetDelivery/assetTypes/image/imageFormat.js +51 -0
- package/features/assetDelivery/assetTypes/image/imageFormat.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/imageTypes.d.ts +39 -0
- package/features/assetDelivery/assetTypes/image/imageTypes.js +0 -0
- package/features/assetDelivery/assetTypes/image/index.d.ts +5 -0
- package/features/assetDelivery/assetTypes/image/index.js +4 -0
- package/features/assetDelivery/assetTypes/image/normalizeImageOptions.d.ts +6 -0
- package/features/assetDelivery/assetTypes/image/normalizeImageOptions.js +56 -0
- package/features/assetDelivery/assetTypes/image/normalizeImageOptions.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/transformImage.d.ts +59 -0
- package/features/assetDelivery/assetTypes/image/transformImage.js +146 -0
- package/features/assetDelivery/assetTypes/image/transformImage.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/utils.d.ts +26 -0
- package/features/assetDelivery/assetTypes/image/utils.js +47 -0
- package/features/assetDelivery/assetTypes/image/utils.js.map +1 -0
- package/features/assetDelivery/feature.js +7 -7
- package/features/assetDelivery/feature.js.map +1 -1
- package/features/assetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +1 -1
- package/features/assetDelivery/transformation/TransformationAssetProcessor.d.ts +4 -6
- package/features/assetDelivery/transformation/TransformationAssetProcessor.js +13 -11
- package/features/assetDelivery/transformation/TransformationAssetProcessor.js.map +1 -1
- package/features/assetDelivery/transformation/index.d.ts +4 -3
- package/features/assetDelivery/transformation/index.js +3 -3
- package/features/file/CreateFile/CreateFileRepository.d.ts +3 -3
- package/features/file/CreateFile/CreateFileRepository.js +6 -5
- package/features/file/CreateFile/CreateFileRepository.js.map +1 -1
- package/features/file/CreateFile/CreateFileUseCase.js +6 -0
- package/features/file/CreateFile/CreateFileUseCase.js.map +1 -1
- package/features/file/CreateFile/abstractions.d.ts +2 -0
- package/features/file/CreateFile/abstractions.js.map +1 -1
- package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js +8 -0
- package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js.map +1 -1
- package/features/file/CreateFilesInBatch/abstractions.d.ts +2 -0
- package/features/file/CreateFilesInBatch/abstractions.js.map +1 -1
- package/features/file/DeleteFile/DeleteFileRepository.d.ts +3 -3
- package/features/file/DeleteFile/DeleteFileRepository.js +6 -5
- package/features/file/DeleteFile/DeleteFileRepository.js.map +1 -1
- package/features/file/FileModelProvider.d.ts +31 -0
- package/features/file/FileModelProvider.js +22 -0
- package/features/file/FileModelProvider.js.map +1 -0
- package/features/file/FileUrlGenerator/FileUrlGenerator.d.ts +4 -6
- package/features/file/FileUrlGenerator/FileUrlGenerator.js +7 -13
- package/features/file/FileUrlGenerator/FileUrlGenerator.js.map +1 -1
- package/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.d.ts +13 -0
- package/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.js +29 -0
- package/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.js.map +1 -0
- package/features/file/FileUrlGenerator/abstractions.d.ts +13 -2
- package/features/file/FileUrlGenerator/abstractions.js +2 -1
- package/features/file/FileUrlGenerator/abstractions.js.map +1 -1
- package/features/file/FileUrlGenerator/feature.js +2 -0
- package/features/file/FileUrlGenerator/feature.js.map +1 -1
- package/features/file/FileUrlGenerator/index.d.ts +1 -0
- package/features/file/FileUrlGenerator/index.js +1 -1
- package/features/file/GetFile/GetFileRepository.d.ts +3 -3
- package/features/file/GetFile/GetFileRepository.js +6 -5
- package/features/file/GetFile/GetFileRepository.js.map +1 -1
- package/features/file/ListFiles/ListFilesRepository.d.ts +3 -3
- package/features/file/ListFiles/ListFilesRepository.js +8 -7
- package/features/file/ListFiles/ListFilesRepository.js.map +1 -1
- package/features/file/ListImagesByTagTool/ListImagesByTagTool.d.ts +15 -5
- package/features/file/ListImagesByTagTool/ListImagesByTagTool.js +21 -7
- package/features/file/ListImagesByTagTool/ListImagesByTagTool.js.map +1 -1
- package/features/file/ListTags/ListTagsRepository.d.ts +3 -3
- package/features/file/ListTags/ListTagsRepository.js +28 -8
- package/features/file/ListTags/ListTagsRepository.js.map +1 -1
- package/features/file/UpdateFile/UpdateFileRepository.d.ts +3 -3
- package/features/file/UpdateFile/UpdateFileRepository.js +6 -5
- package/features/file/UpdateFile/UpdateFileRepository.js.map +1 -1
- package/features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.d.ts +11 -0
- package/features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.js +20 -0
- package/features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.js.map +1 -0
- package/features/settings/DefaultSrcPrefix/abstractions.d.ts +20 -0
- package/features/settings/DefaultSrcPrefix/abstractions.js +5 -0
- package/features/settings/DefaultSrcPrefix/abstractions.js.map +1 -0
- package/features/settings/DefaultSrcPrefix/feature.d.ts +4 -0
- package/features/settings/DefaultSrcPrefix/feature.js +11 -0
- package/features/settings/DefaultSrcPrefix/feature.js.map +1 -0
- package/features/settings/DefaultSrcPrefix/index.d.ts +1 -0
- package/features/settings/DefaultSrcPrefix/index.js +1 -0
- package/features/settings/GetSettings/GetSettingsUseCase.d.ts +7 -1
- package/features/settings/GetSettings/GetSettingsUseCase.js +15 -8
- package/features/settings/GetSettings/GetSettingsUseCase.js.map +1 -1
- package/features/settings/SettingsInstaller/SettingsInstaller.d.ts +1 -5
- package/features/settings/SettingsInstaller/SettingsInstaller.js +3 -16
- package/features/settings/SettingsInstaller/SettingsInstaller.js.map +1 -1
- package/features/settings/UpdateSettings/UpdateSettingsUseCase.d.ts +9 -1
- package/features/settings/UpdateSettings/UpdateSettingsUseCase.js +16 -4
- package/features/settings/UpdateSettings/UpdateSettingsUseCase.js.map +1 -1
- package/features/upload/WriteFileMetadata/WriteMetadataAfterUpdateHandler.d.ts +11 -0
- package/features/upload/WriteFileMetadata/WriteMetadataAfterUpdateHandler.js +22 -0
- package/features/upload/WriteFileMetadata/WriteMetadataAfterUpdateHandler.js.map +1 -0
- package/features/upload/WriteFileMetadata/feature.js +2 -0
- package/features/upload/WriteFileMetadata/feature.js.map +1 -1
- package/features/upload/utils/FileNormalizer.js +8 -1
- package/features/upload/utils/FileNormalizer.js.map +1 -1
- package/graphql/FmGraphQLSchema.d.ts +4 -5
- package/graphql/FmGraphQLSchema.js +33 -15
- package/graphql/FmGraphQLSchema.js.map +1 -1
- package/package.json +19 -20
- package/features/FileModelContextualSchema.d.ts +0 -13
- package/features/FileModelContextualSchema.js +0 -31
- package/features/FileModelContextualSchema.js.map +0 -1
- package/features/assetDelivery/transformation/AssetKeyGenerator.js +0 -24
- package/features/assetDelivery/transformation/AssetKeyGenerator.js.map +0 -1
- package/features/assetDelivery/transformation/PassthroughAssetTransformationStrategy.d.ts +0 -9
- package/features/assetDelivery/transformation/PassthroughAssetTransformationStrategy.js +0 -13
- package/features/assetDelivery/transformation/PassthroughAssetTransformationStrategy.js.map +0 -1
- package/features/assetDelivery/transformation/WidthCollection.js.map +0 -1
- package/features/assetDelivery/transformation/utils.d.ts +0 -9
- package/features/assetDelivery/transformation/utils.js +0 -31
- package/features/assetDelivery/transformation/utils.js.map +0 -1
- /package/features/assetDelivery/{transformation → assetTypes/image}/WidthCollection.d.ts +0 -0
- /package/features/assetDelivery/{transformation → assetTypes/image}/WidthCollection.js +0 -0
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry";
|
|
3
3
|
import { DeleteFileRepository } from "./abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { FileModelProvider } from "../../../domain/file/abstractions.js";
|
|
5
5
|
import { FileNotFoundError, FilePersistenceError } from "../../../domain/file/errors.js";
|
|
6
6
|
class DeleteFileRepositoryImpl {
|
|
7
|
-
constructor(deleteEntry,
|
|
7
|
+
constructor(deleteEntry, fileModelProvider){
|
|
8
8
|
this.deleteEntry = deleteEntry;
|
|
9
|
-
this.
|
|
9
|
+
this.fileModelProvider = fileModelProvider;
|
|
10
10
|
}
|
|
11
11
|
async delete(file) {
|
|
12
12
|
const entryId = `${file.id}#0001`;
|
|
13
|
-
const
|
|
13
|
+
const fileModel = await this.fileModelProvider.get();
|
|
14
|
+
const result = await this.deleteEntry.execute(fileModel, entryId);
|
|
14
15
|
if (result.isFail()) {
|
|
15
16
|
const error = result.error;
|
|
16
17
|
if ("Cms/Entry/NotFound" === error.code) return Result.fail(new FileNotFoundError(file.id));
|
|
@@ -23,7 +24,7 @@ const DeleteFileRepository_DeleteFileRepository = DeleteFileRepository.createImp
|
|
|
23
24
|
implementation: DeleteFileRepositoryImpl,
|
|
24
25
|
dependencies: [
|
|
25
26
|
DeleteEntryUseCase,
|
|
26
|
-
|
|
27
|
+
FileModelProvider
|
|
27
28
|
]
|
|
28
29
|
});
|
|
29
30
|
export { DeleteFileRepository_DeleteFileRepository as DeleteFileRepository };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/DeleteFile/DeleteFileRepository.js","sources":["../../../../src/features/file/DeleteFile/DeleteFileRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry\";\nimport { DeleteFileRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/file/DeleteFile/DeleteFileRepository.js","sources":["../../../../src/features/file/DeleteFile/DeleteFileRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry\";\nimport { DeleteFileRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { FileModelProvider } from \"~/domain/file/abstractions.js\";\nimport { FileNotFoundError, FilePersistenceError } from \"~/domain/file/errors.js\";\nimport { File } from \"~/domain/file/types.js\";\n\nclass DeleteFileRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private deleteEntry: DeleteEntryUseCase.Interface,\n private fileModelProvider: FileModelProvider.Interface\n ) {}\n\n async delete(file: File): Promise<Result<void, RepositoryAbstraction.Error>> {\n // Files are not versioned, so we're always deleting the same revision\n const entryId = `${file.id}#0001`;\n\n const fileModel = await this.fileModelProvider.get();\n const result = await this.deleteEntry.execute(fileModel, entryId);\n\n if (result.isFail()) {\n const error = result.error;\n if (error.code === \"Cms/Entry/NotFound\") {\n return Result.fail(new FileNotFoundError(file.id));\n }\n return Result.fail(new FilePersistenceError(result.error));\n }\n\n return Result.ok();\n }\n}\n\nexport const DeleteFileRepository = RepositoryAbstraction.createImplementation({\n implementation: DeleteFileRepositoryImpl,\n dependencies: [DeleteEntryUseCase, FileModelProvider]\n});\n"],"names":["DeleteFileRepositoryImpl","deleteEntry","fileModelProvider","file","entryId","fileModel","result","error","Result","FileNotFoundError","FilePersistenceError","DeleteFileRepository","RepositoryAbstraction","DeleteEntryUseCase","FileModelProvider"],"mappings":";;;;;AAOA,MAAMA;IACF,YACYC,WAAyC,EACzCC,iBAA8C,CACxD;aAFUD,WAAW,GAAXA;aACAC,iBAAiB,GAAjBA;IACT;IAEH,MAAM,OAAOC,IAAU,EAAsD;QAEzE,MAAMC,UAAU,GAAGD,KAAK,EAAE,CAAC,KAAK,CAAC;QAEjC,MAAME,YAAY,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG;QAClD,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAACD,WAAWD;QAEzD,IAAIE,OAAO,MAAM,IAAI;YACjB,MAAMC,QAAQD,OAAO,KAAK;YAC1B,IAAIC,AAAe,yBAAfA,MAAM,IAAI,EACV,OAAOC,OAAO,IAAI,CAAC,IAAIC,kBAAkBN,KAAK,EAAE;YAEpD,OAAOK,OAAO,IAAI,CAAC,IAAIE,qBAAqBJ,OAAO,KAAK;QAC5D;QAEA,OAAOE,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMG,4CAAuBC,qBAAAA,oBAA0C,CAAC;IAC3E,gBAAgBZ;IAChB,cAAc;QAACa;QAAoBC;KAAkB;AACzD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
3
|
+
import { FileModelProvider as Abstraction } from "../../domain/file/abstractions.js";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the tenant's `fmFile` model on demand.
|
|
6
|
+
*
|
|
7
|
+
* Two things this deliberately does NOT do, both of which the initializer it replaces did:
|
|
8
|
+
*
|
|
9
|
+
* - **No memoization.** `ModelsFetcher` already caches the model list per request (`ModelCache` is a
|
|
10
|
+
* per-request `createMemoryCache()`, see `ContentModelFeature`), so a second cache would buy only
|
|
11
|
+
* a repeat access-control check and an array lookup, at the cost of two lifetimes to reason about.
|
|
12
|
+
* - **No `withoutAuthorization`.** `fmFile` is a private model and `PrivateModelBuilder` sets
|
|
13
|
+
* `authorization: false`, which makes `AccessControl.modelAuthorizationDisabled()` short-circuit
|
|
14
|
+
* `canAccessModel()` to true for every identity — so the wrapper changed nothing. Confirmed
|
|
15
|
+
* against `filesSecurity.test.ts`, which exercises `fm.file`-only identities holding no CMS
|
|
16
|
+
* content-model permissions.
|
|
17
|
+
*
|
|
18
|
+
* `GetModelUseCase` is an ordinary constructor dependency: this provider is only constructed when a
|
|
19
|
+
* consumer first awaits `get()`, which happens during request handling — after the CMS has
|
|
20
|
+
* registered everything the use case needs. That timing is what previously forced the lazy
|
|
21
|
+
* `container.resolve()` inside the initializer.
|
|
22
|
+
*/
|
|
23
|
+
declare class FileModelProviderImpl implements Abstraction.Interface {
|
|
24
|
+
private getModel;
|
|
25
|
+
constructor(getModel: GetModelUseCase.Interface);
|
|
26
|
+
get(): Promise<CmsModel>;
|
|
27
|
+
}
|
|
28
|
+
export declare const FileModelProvider: typeof FileModelProviderImpl & {
|
|
29
|
+
__abstraction: import("@webiny/di").Abstraction<import("~/domain/file/abstractions.js").IFileModelProvider>;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
2
|
+
import { FileModelProvider } from "../../domain/file/abstractions.js";
|
|
3
|
+
import { FILE_MODEL_ID } from "../../domain/file/file.model.js";
|
|
4
|
+
class FileModelProviderImpl {
|
|
5
|
+
constructor(getModel){
|
|
6
|
+
this.getModel = getModel;
|
|
7
|
+
}
|
|
8
|
+
async get() {
|
|
9
|
+
const result = await this.getModel.execute(FILE_MODEL_ID);
|
|
10
|
+
if (result.isFail()) throw result.error;
|
|
11
|
+
return result.value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const FileModelProvider_FileModelProvider = FileModelProvider.createImplementation({
|
|
15
|
+
implementation: FileModelProviderImpl,
|
|
16
|
+
dependencies: [
|
|
17
|
+
GetModelUseCase
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
export { FileModelProvider_FileModelProvider as FileModelProvider };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=FileModelProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/file/FileModelProvider.js","sources":["../../../src/features/file/FileModelProvider.ts"],"sourcesContent":["import type { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { FileModelProvider as Abstraction } from \"~/domain/file/abstractions.js\";\nimport { FILE_MODEL_ID } from \"~/domain/file/file.model.js\";\n\n/**\n * Resolves the tenant's `fmFile` model on demand.\n *\n * Two things this deliberately does NOT do, both of which the initializer it replaces did:\n *\n * - **No memoization.** `ModelsFetcher` already caches the model list per request (`ModelCache` is a\n * per-request `createMemoryCache()`, see `ContentModelFeature`), so a second cache would buy only\n * a repeat access-control check and an array lookup, at the cost of two lifetimes to reason about.\n * - **No `withoutAuthorization`.** `fmFile` is a private model and `PrivateModelBuilder` sets\n * `authorization: false`, which makes `AccessControl.modelAuthorizationDisabled()` short-circuit\n * `canAccessModel()` to true for every identity — so the wrapper changed nothing. Confirmed\n * against `filesSecurity.test.ts`, which exercises `fm.file`-only identities holding no CMS\n * content-model permissions.\n *\n * `GetModelUseCase` is an ordinary constructor dependency: this provider is only constructed when a\n * consumer first awaits `get()`, which happens during request handling — after the CMS has\n * registered everything the use case needs. That timing is what previously forced the lazy\n * `container.resolve()` inside the initializer.\n */\nclass FileModelProviderImpl implements Abstraction.Interface {\n constructor(private getModel: GetModelUseCase.Interface) {}\n\n async get(): Promise<CmsModel> {\n const result = await this.getModel.execute(FILE_MODEL_ID);\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n }\n}\n\nexport const FileModelProvider = Abstraction.createImplementation({\n implementation: FileModelProviderImpl,\n dependencies: [GetModelUseCase]\n});\n"],"names":["FileModelProviderImpl","getModel","result","FILE_MODEL_ID","FileModelProvider","Abstraction","GetModelUseCase"],"mappings":";;;AAwBA,MAAMA;IACF,YAAoBC,QAAmC,CAAE;aAArCA,QAAQ,GAARA;IAAsC;IAE1D,MAAM,MAAyB;QAC3B,MAAMC,SAAS,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAACC;QAC3C,IAAID,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAEtB,OAAOA,OAAO,KAAK;IACvB;AACJ;AAEO,MAAME,sCAAoBC,kBAAAA,oBAAgC,CAAC;IAC9D,gBAAgBL;IAChB,cAAc;QAACM;KAAgB;AACnC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { FileUrlGenerator as Abstraction } from "./abstractions.js";
|
|
2
|
-
import {
|
|
2
|
+
import { FileUrlPrefixProvider } from "./abstractions.js";
|
|
3
3
|
import type { File } from "../../../domain/file/types.js";
|
|
4
4
|
declare class FileUrlGeneratorImpl implements Abstraction.Interface {
|
|
5
|
-
private readonly
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
generateUrl(file: File): string;
|
|
9
|
-
init(): Promise<void>;
|
|
5
|
+
private readonly prefixProvider;
|
|
6
|
+
constructor(prefixProvider: FileUrlPrefixProvider.Interface);
|
|
7
|
+
generateUrl(file: File): Promise<string>;
|
|
10
8
|
}
|
|
11
9
|
export declare const FileUrlGenerator: typeof FileUrlGeneratorImpl & {
|
|
12
10
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IFileUrlGenerator>;
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import { FileUrlGenerator } from "./abstractions.js";
|
|
2
|
-
import { GetSettingsUseCase } from "../../settings/GetSettings/abstractions.js";
|
|
1
|
+
import { FileUrlGenerator, FileUrlPrefixProvider } from "./abstractions.js";
|
|
3
2
|
class FileUrlGeneratorImpl {
|
|
4
|
-
constructor(
|
|
5
|
-
this.
|
|
6
|
-
this.srcPrefix = "";
|
|
3
|
+
constructor(prefixProvider){
|
|
4
|
+
this.prefixProvider = prefixProvider;
|
|
7
5
|
}
|
|
8
|
-
generateUrl(file) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async init() {
|
|
12
|
-
const result = await this.getSettings.execute();
|
|
13
|
-
const settings = result.value;
|
|
14
|
-
this.srcPrefix = settings?.srcPrefix ?? "";
|
|
6
|
+
async generateUrl(file) {
|
|
7
|
+
const prefix = await this.prefixProvider.getPrefix();
|
|
8
|
+
return prefix + file.key;
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
const FileUrlGenerator_FileUrlGenerator = FileUrlGenerator.createImplementation({
|
|
18
12
|
implementation: FileUrlGeneratorImpl,
|
|
19
13
|
dependencies: [
|
|
20
|
-
|
|
14
|
+
FileUrlPrefixProvider
|
|
21
15
|
]
|
|
22
16
|
});
|
|
23
17
|
export { FileUrlGenerator_FileUrlGenerator as FileUrlGenerator };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/FileUrlGenerator/FileUrlGenerator.js","sources":["../../../../src/features/file/FileUrlGenerator/FileUrlGenerator.ts"],"sourcesContent":["import { FileUrlGenerator as Abstraction } from \"./abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/file/FileUrlGenerator/FileUrlGenerator.js","sources":["../../../../src/features/file/FileUrlGenerator/FileUrlGenerator.ts"],"sourcesContent":["import { FileUrlGenerator as Abstraction } from \"./abstractions.js\";\nimport { FileUrlPrefixProvider } from \"./abstractions.js\";\nimport type { File } from \"~/domain/file/types.js\";\n\nclass FileUrlGeneratorImpl implements Abstraction.Interface {\n public constructor(private readonly prefixProvider: FileUrlPrefixProvider.Interface) {}\n\n public async generateUrl(file: File): Promise<string> {\n const prefix = await this.prefixProvider.getPrefix();\n return prefix + file.key;\n }\n}\n\nexport const FileUrlGenerator = Abstraction.createImplementation({\n implementation: FileUrlGeneratorImpl,\n dependencies: [FileUrlPrefixProvider]\n});\n"],"names":["FileUrlGeneratorImpl","prefixProvider","file","prefix","FileUrlGenerator","Abstraction","FileUrlPrefixProvider"],"mappings":";AAIA,MAAMA;IACF,YAAoCC,cAA+C,CAAE;aAAjDA,cAAc,GAAdA;IAAkD;IAEtF,MAAa,YAAYC,IAAU,EAAmB;QAClD,MAAMC,SAAS,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS;QAClD,OAAOA,SAASD,KAAK,GAAG;IAC5B;AACJ;AAEO,MAAME,oCAAmBC,iBAAAA,oBAAgC,CAAC;IAC7D,gBAAgBL;IAChB,cAAc;QAACM;KAAsB;AACzC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FileUrlPrefixProvider as Abstraction } from "./abstractions.js";
|
|
2
|
+
import { GetSettingsUseCase } from "../../../features/settings/GetSettings/abstractions.js";
|
|
3
|
+
declare class SettingsFileUrlPrefixProviderImpl implements Abstraction.Interface {
|
|
4
|
+
private readonly getSettings;
|
|
5
|
+
private prefix;
|
|
6
|
+
constructor(getSettings: GetSettingsUseCase.Interface);
|
|
7
|
+
getPrefix(): Promise<string>;
|
|
8
|
+
private loadPrefix;
|
|
9
|
+
}
|
|
10
|
+
export declare const SettingsFileUrlPrefixProvider: typeof SettingsFileUrlPrefixProviderImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IFileUrlPrefixProvider>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { FileUrlPrefixProvider } from "./abstractions.js";
|
|
2
|
+
import { GetSettingsUseCase } from "../../settings/GetSettings/abstractions.js";
|
|
3
|
+
class SettingsFileUrlPrefixProviderImpl {
|
|
4
|
+
constructor(getSettings){
|
|
5
|
+
this.getSettings = getSettings;
|
|
6
|
+
this.prefix = null;
|
|
7
|
+
}
|
|
8
|
+
getPrefix() {
|
|
9
|
+
if (!this.prefix) this.prefix = this.loadPrefix().catch((error)=>{
|
|
10
|
+
this.prefix = null;
|
|
11
|
+
throw error;
|
|
12
|
+
});
|
|
13
|
+
return this.prefix;
|
|
14
|
+
}
|
|
15
|
+
async loadPrefix() {
|
|
16
|
+
const result = await this.getSettings.execute();
|
|
17
|
+
if (result.isFail()) throw result.error;
|
|
18
|
+
return result.value?.srcPrefix ?? "";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const SettingsFileUrlPrefixProvider = FileUrlPrefixProvider.createImplementation({
|
|
22
|
+
implementation: SettingsFileUrlPrefixProviderImpl,
|
|
23
|
+
dependencies: [
|
|
24
|
+
GetSettingsUseCase
|
|
25
|
+
]
|
|
26
|
+
});
|
|
27
|
+
export { SettingsFileUrlPrefixProvider };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=SettingsFileUrlPrefixProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.js","sources":["../../../../src/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.ts"],"sourcesContent":["import { FileUrlPrefixProvider as Abstraction } from \"./abstractions.js\";\nimport { GetSettingsUseCase } from \"~/features/settings/GetSettings/abstractions.js\";\n\nclass SettingsFileUrlPrefixProviderImpl implements Abstraction.Interface {\n private prefix: Promise<string> | null = null;\n\n public constructor(private readonly getSettings: GetSettingsUseCase.Interface) {}\n\n // Read once per instance, when the first URL is needed. A failed read is forgotten, so the next\n // call tries again.\n public getPrefix(): Promise<string> {\n if (!this.prefix) {\n this.prefix = this.loadPrefix().catch(error => {\n this.prefix = null;\n throw error;\n });\n }\n return this.prefix;\n }\n\n private async loadPrefix(): Promise<string> {\n const result = await this.getSettings.execute();\n if (result.isFail()) {\n throw result.error;\n }\n return result.value?.srcPrefix ?? \"\";\n }\n}\n\nexport const SettingsFileUrlPrefixProvider = Abstraction.createImplementation({\n implementation: SettingsFileUrlPrefixProviderImpl,\n dependencies: [GetSettingsUseCase]\n});\n"],"names":["SettingsFileUrlPrefixProviderImpl","getSettings","error","result","SettingsFileUrlPrefixProvider","Abstraction","GetSettingsUseCase"],"mappings":";;AAGA,MAAMA;IAGF,YAAoCC,WAAyC,CAAE;aAA3CA,WAAW,GAAXA;aAF5B,MAAM,GAA2B;IAEuC;IAIzE,YAA6B;QAChC,IAAI,CAAC,IAAI,CAAC,MAAM,EACZ,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,GAAG,KAAK,CAACC,CAAAA;YAClC,IAAI,CAAC,MAAM,GAAG;YACd,MAAMA;QACV;QAEJ,OAAO,IAAI,CAAC,MAAM;IACtB;IAEA,MAAc,aAA8B;QACxC,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO;QAC7C,IAAIA,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAEtB,OAAOA,OAAO,KAAK,EAAE,aAAa;IACtC;AACJ;AAEO,MAAMC,gCAAgCC,sBAAAA,oBAAgC,CAAC;IAC1E,gBAAgBL;IAChB,cAAc;QAACM;KAAmB;AACtC"}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import type { File } from "../../../domain/file/types.js";
|
|
2
2
|
export interface IFileUrlGenerator {
|
|
3
|
-
generateUrl(file: File): string
|
|
4
|
-
init?(): Promise<void>;
|
|
3
|
+
generateUrl(file: File): Promise<string>;
|
|
5
4
|
}
|
|
6
5
|
export declare const FileUrlGenerator: import("@webiny/di").Abstraction<IFileUrlGenerator>;
|
|
7
6
|
export declare namespace FileUrlGenerator {
|
|
8
7
|
type Interface = IFileUrlGenerator;
|
|
9
8
|
}
|
|
9
|
+
export interface IFileUrlPrefixProvider {
|
|
10
|
+
getPrefix(): Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Provides the prefix the default FileUrlGenerator puts in front of a file's key. The default
|
|
14
|
+
* implementation reads `srcPrefix` from the File Manager settings. Replace it to load the prefix
|
|
15
|
+
* from somewhere else, without touching how URLs are put together.
|
|
16
|
+
*/
|
|
17
|
+
export declare const FileUrlPrefixProvider: import("@webiny/di").Abstraction<IFileUrlPrefixProvider>;
|
|
18
|
+
export declare namespace FileUrlPrefixProvider {
|
|
19
|
+
type Interface = IFileUrlPrefixProvider;
|
|
20
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
2
|
const FileUrlGenerator = createAbstraction("FileManager/FileUrlGenerator");
|
|
3
|
-
|
|
3
|
+
const FileUrlPrefixProvider = createAbstraction("FileManager/FileUrlPrefixProvider");
|
|
4
|
+
export { FileUrlGenerator, FileUrlPrefixProvider };
|
|
4
5
|
|
|
5
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/FileUrlGenerator/abstractions.js","sources":["../../../../src/features/file/FileUrlGenerator/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { File } from \"~/domain/file/types.js\";\n\nexport interface IFileUrlGenerator {\n generateUrl(file: File):
|
|
1
|
+
{"version":3,"file":"features/file/FileUrlGenerator/abstractions.js","sources":["../../../../src/features/file/FileUrlGenerator/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { File } from \"~/domain/file/types.js\";\n\nexport interface IFileUrlGenerator {\n generateUrl(file: File): Promise<string>;\n}\n\n/* Generate URLs for uploaded files. */\nexport const FileUrlGenerator = createAbstraction<IFileUrlGenerator>(\n \"FileManager/FileUrlGenerator\"\n);\n\nexport namespace FileUrlGenerator {\n export type Interface = IFileUrlGenerator;\n}\n\nexport interface IFileUrlPrefixProvider {\n getPrefix(): Promise<string>;\n}\n\n/**\n * Provides the prefix the default FileUrlGenerator puts in front of a file's key. The default\n * implementation reads `srcPrefix` from the File Manager settings. Replace it to load the prefix\n * from somewhere else, without touching how URLs are put together.\n */\nexport const FileUrlPrefixProvider = createAbstraction<IFileUrlPrefixProvider>(\n \"FileManager/FileUrlPrefixProvider\"\n);\n\nexport namespace FileUrlPrefixProvider {\n export type Interface = IFileUrlPrefixProvider;\n}\n"],"names":["FileUrlGenerator","createAbstraction","FileUrlPrefixProvider"],"mappings":";AAQO,MAAMA,mBAAmBC,kBAC5B;AAgBG,MAAMC,wBAAwBD,kBACjC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { FileUrlGenerator } from "./FileUrlGenerator.js";
|
|
3
|
+
import { SettingsFileUrlPrefixProvider } from "./SettingsFileUrlPrefixProvider.js";
|
|
3
4
|
const FileUrlGeneratorFeature = createFeature({
|
|
4
5
|
name: "FileManager/FileUrlGenerator",
|
|
5
6
|
register (container) {
|
|
6
7
|
container.register(FileUrlGenerator).inSingletonScope();
|
|
8
|
+
container.register(SettingsFileUrlPrefixProvider).inSingletonScope();
|
|
7
9
|
}
|
|
8
10
|
});
|
|
9
11
|
export { FileUrlGeneratorFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/FileUrlGenerator/feature.js","sources":["../../../../src/features/file/FileUrlGenerator/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FileUrlGenerator } from \"./FileUrlGenerator.js\";\n\nexport const FileUrlGeneratorFeature = createFeature({\n name: \"FileManager/FileUrlGenerator\",\n register(container) {\n container.register(FileUrlGenerator).inSingletonScope();\n }\n});\n"],"names":["FileUrlGeneratorFeature","createFeature","container","FileUrlGenerator"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/file/FileUrlGenerator/feature.js","sources":["../../../../src/features/file/FileUrlGenerator/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FileUrlGenerator } from \"./FileUrlGenerator.js\";\nimport { SettingsFileUrlPrefixProvider } from \"./SettingsFileUrlPrefixProvider.js\";\n\nexport const FileUrlGeneratorFeature = createFeature({\n name: \"FileManager/FileUrlGenerator\",\n register(container) {\n container.register(FileUrlGenerator).inSingletonScope();\n // A singleton, so the settings are read once per request however many URLs are generated.\n container.register(SettingsFileUrlPrefixProvider).inSingletonScope();\n }\n});\n"],"names":["FileUrlGeneratorFeature","createFeature","container","FileUrlGenerator","SettingsFileUrlPrefixProvider"],"mappings":";;;AAIO,MAAMA,0BAA0BC,cAAc;IACjD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,kBAAkB,gBAAgB;QAErDD,UAAU,QAAQ,CAACE,+BAA+B,gBAAgB;IACtE;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { FileUrlGenerator } from "./abstractions.js";
|
|
1
|
+
export { FileUrlGenerator, FileUrlPrefixProvider } from "./abstractions.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById";
|
|
3
3
|
import { GetFileRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { FileModelProvider } from "../../../domain/file/abstractions.js";
|
|
5
5
|
import type { File } from "../../../domain/file/types.js";
|
|
6
6
|
declare class GetFileRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
7
7
|
private getEntryById;
|
|
8
|
-
private
|
|
9
|
-
constructor(getEntryById: GetEntryByIdUseCase.Interface,
|
|
8
|
+
private fileModelProvider;
|
|
9
|
+
constructor(getEntryById: GetEntryByIdUseCase.Interface, fileModelProvider: FileModelProvider.Interface);
|
|
10
10
|
execute(id: string): Promise<Result<File, RepositoryAbstraction.Error>>;
|
|
11
11
|
}
|
|
12
12
|
export declare const GetFileRepository: typeof GetFileRepositoryImpl & {
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById";
|
|
3
3
|
import { GetFileRepository } from "./abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { FileModelProvider } from "../../../domain/file/abstractions.js";
|
|
5
5
|
import { FileNotAuthorizedError, FileNotFoundError, FilePersistenceError } from "../../../domain/file/errors.js";
|
|
6
6
|
import { EntryToFileMapper } from "../shared/EntryToFileMapper.js";
|
|
7
7
|
class GetFileRepositoryImpl {
|
|
8
|
-
constructor(getEntryById,
|
|
8
|
+
constructor(getEntryById, fileModelProvider){
|
|
9
9
|
this.getEntryById = getEntryById;
|
|
10
|
-
this.
|
|
10
|
+
this.fileModelProvider = fileModelProvider;
|
|
11
11
|
}
|
|
12
12
|
async execute(id) {
|
|
13
|
-
const
|
|
13
|
+
const fileModel = await this.fileModelProvider.get();
|
|
14
|
+
const result = await this.getEntryById.execute(fileModel, `${id}#0001`);
|
|
14
15
|
if (result.isFail()) {
|
|
15
16
|
const error = result.error;
|
|
16
17
|
if ("Cms/Entry/NotFound" === error.code) return Result.fail(new FileNotFoundError(id));
|
|
@@ -25,7 +26,7 @@ const GetFileRepository_GetFileRepository = GetFileRepository.createImplementati
|
|
|
25
26
|
implementation: GetFileRepositoryImpl,
|
|
26
27
|
dependencies: [
|
|
27
28
|
GetEntryByIdUseCase,
|
|
28
|
-
|
|
29
|
+
FileModelProvider
|
|
29
30
|
]
|
|
30
31
|
});
|
|
31
32
|
export { GetFileRepository_GetFileRepository as GetFileRepository };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/GetFile/GetFileRepository.js","sources":["../../../../src/features/file/GetFile/GetFileRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { GetFileRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/file/GetFile/GetFileRepository.js","sources":["../../../../src/features/file/GetFile/GetFileRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { GetFileRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { FileModelProvider } from \"~/domain/file/abstractions.js\";\nimport type { File } from \"~/domain/file/types.js\";\nimport {\n FileNotAuthorizedError,\n FileNotFoundError,\n FilePersistenceError\n} from \"~/domain/file/errors.js\";\nimport { EntryToFileMapper } from \"../shared/EntryToFileMapper.js\";\n\nclass GetFileRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private getEntryById: GetEntryByIdUseCase.Interface,\n private fileModelProvider: FileModelProvider.Interface\n ) {}\n\n async execute(id: string): Promise<Result<File, RepositoryAbstraction.Error>> {\n const fileModel = await this.fileModelProvider.get();\n const result = await this.getEntryById.execute(fileModel, `${id}#0001`);\n\n if (result.isFail()) {\n const error = result.error;\n\n if (error.code === \"Cms/Entry/NotFound\") {\n return Result.fail(new FileNotFoundError(id));\n }\n\n if (error.code === \"Cms/Entry/NotAuthorized\") {\n return Result.fail(new FileNotAuthorizedError());\n }\n return Result.fail(new FilePersistenceError(result.error));\n }\n\n const file = EntryToFileMapper.toFile(result.value);\n\n return Result.ok(file);\n }\n}\n\nexport const GetFileRepository = RepositoryAbstraction.createImplementation({\n implementation: GetFileRepositoryImpl,\n dependencies: [GetEntryByIdUseCase, FileModelProvider]\n});\n"],"names":["GetFileRepositoryImpl","getEntryById","fileModelProvider","id","fileModel","result","error","Result","FileNotFoundError","FileNotAuthorizedError","FilePersistenceError","file","EntryToFileMapper","GetFileRepository","RepositoryAbstraction","GetEntryByIdUseCase","FileModelProvider"],"mappings":";;;;;;AAYA,MAAMA;IACF,YACYC,YAA2C,EAC3CC,iBAA8C,CACxD;aAFUD,YAAY,GAAZA;aACAC,iBAAiB,GAAjBA;IACT;IAEH,MAAM,QAAQC,EAAU,EAAsD;QAC1E,MAAMC,YAAY,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG;QAClD,MAAMC,SAAS,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAACD,WAAW,GAAGD,GAAG,KAAK,CAAC;QAEtE,IAAIE,OAAO,MAAM,IAAI;YACjB,MAAMC,QAAQD,OAAO,KAAK;YAE1B,IAAIC,AAAe,yBAAfA,MAAM,IAAI,EACV,OAAOC,OAAO,IAAI,CAAC,IAAIC,kBAAkBL;YAG7C,IAAIG,AAAe,8BAAfA,MAAM,IAAI,EACV,OAAOC,OAAO,IAAI,CAAC,IAAIE;YAE3B,OAAOF,OAAO,IAAI,CAAC,IAAIG,qBAAqBL,OAAO,KAAK;QAC5D;QAEA,MAAMM,OAAOC,kBAAkB,MAAM,CAACP,OAAO,KAAK;QAElD,OAAOE,OAAO,EAAE,CAACI;IACrB;AACJ;AAEO,MAAME,sCAAoBC,kBAAAA,oBAA0C,CAAC;IACxE,gBAAgBd;IAChB,cAAc;QAACe;QAAqBC;KAAkB;AAC1D"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js";
|
|
3
3
|
import { ListFilesInput, ListFilesOutput, ListFilesRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { FileModelProvider } from "../../../domain/file/abstractions.js";
|
|
5
5
|
import { CmsWhereMapper } from "@webiny/api-headless-cms";
|
|
6
6
|
import { CmsSortMapper } from "@webiny/api-headless-cms";
|
|
7
7
|
declare class ListFilesRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
8
8
|
private listLatestEntries;
|
|
9
|
-
private
|
|
9
|
+
private fileModelProvider;
|
|
10
10
|
private cmsWhereMapper;
|
|
11
11
|
private cmsSortMapper;
|
|
12
|
-
constructor(listLatestEntries: ListLatestEntriesUseCase.Interface,
|
|
12
|
+
constructor(listLatestEntries: ListLatestEntriesUseCase.Interface, fileModelProvider: FileModelProvider.Interface, cmsWhereMapper: CmsWhereMapper.Interface, cmsSortMapper: CmsSortMapper.Interface);
|
|
13
13
|
execute(input: ListFilesInput): Promise<Result<ListFilesOutput, RepositoryAbstraction.Error>>;
|
|
14
14
|
}
|
|
15
15
|
export declare const ListFilesRepository: typeof ListFilesRepositoryImpl & {
|
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js";
|
|
3
3
|
import { ListFilesRepository } from "./abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { FileModelProvider } from "../../../domain/file/abstractions.js";
|
|
5
5
|
import { FilePersistenceError } from "../../../domain/file/errors.js";
|
|
6
6
|
import { EntryToFileMapper } from "../shared/EntryToFileMapper.js";
|
|
7
7
|
import { CmsSortMapper, CmsWhereMapper } from "@webiny/api-headless-cms";
|
|
8
8
|
class ListFilesRepositoryImpl {
|
|
9
|
-
constructor(listLatestEntries,
|
|
9
|
+
constructor(listLatestEntries, fileModelProvider, cmsWhereMapper, cmsSortMapper){
|
|
10
10
|
this.listLatestEntries = listLatestEntries;
|
|
11
|
-
this.
|
|
11
|
+
this.fileModelProvider = fileModelProvider;
|
|
12
12
|
this.cmsWhereMapper = cmsWhereMapper;
|
|
13
13
|
this.cmsSortMapper = cmsSortMapper;
|
|
14
14
|
}
|
|
15
15
|
async execute(input) {
|
|
16
|
+
const fileModel = await this.fileModelProvider.get();
|
|
16
17
|
const where = this.cmsWhereMapper.map({
|
|
17
18
|
input: input.where || {},
|
|
18
|
-
fields:
|
|
19
|
+
fields: fileModel.fields
|
|
19
20
|
});
|
|
20
21
|
const sort = this.cmsSortMapper.map({
|
|
21
22
|
input: input.sort,
|
|
22
|
-
fields:
|
|
23
|
+
fields: fileModel.fields
|
|
23
24
|
});
|
|
24
|
-
const result = await this.listLatestEntries.execute(
|
|
25
|
+
const result = await this.listLatestEntries.execute(fileModel, {
|
|
25
26
|
where,
|
|
26
27
|
limit: input.limit || 40,
|
|
27
28
|
after: input.after || void 0,
|
|
@@ -43,7 +44,7 @@ const ListFilesRepository_ListFilesRepository = ListFilesRepository.createImplem
|
|
|
43
44
|
implementation: ListFilesRepositoryImpl,
|
|
44
45
|
dependencies: [
|
|
45
46
|
ListLatestEntriesUseCase,
|
|
46
|
-
|
|
47
|
+
FileModelProvider,
|
|
47
48
|
CmsWhereMapper,
|
|
48
49
|
CmsSortMapper
|
|
49
50
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/ListFiles/ListFilesRepository.js","sources":["../../../../src/features/file/ListFiles/ListFilesRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport {\n ListFilesInput,\n ListFilesOutput,\n ListFilesRepository as RepositoryAbstraction\n} from \"./abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/file/ListFiles/ListFilesRepository.js","sources":["../../../../src/features/file/ListFiles/ListFilesRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries/index.js\";\nimport {\n ListFilesInput,\n ListFilesOutput,\n ListFilesRepository as RepositoryAbstraction\n} from \"./abstractions.js\";\nimport { FileModelProvider } from \"~/domain/file/abstractions.js\";\nimport { FilePersistenceError } from \"~/domain/file/errors.js\";\nimport { EntryToFileMapper } from \"../shared/EntryToFileMapper.js\";\nimport { CmsWhereMapper } from \"@webiny/api-headless-cms\";\nimport { CmsSortMapper } from \"@webiny/api-headless-cms\";\nimport { GenericRecord } from \"@webiny/api/types.js\";\n\nclass ListFilesRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private fileModelProvider: FileModelProvider.Interface,\n private cmsWhereMapper: CmsWhereMapper.Interface,\n private cmsSortMapper: CmsSortMapper.Interface\n ) {}\n\n async execute(\n input: ListFilesInput\n ): Promise<Result<ListFilesOutput, RepositoryAbstraction.Error>> {\n const fileModel = await this.fileModelProvider.get();\n\n const where = this.cmsWhereMapper.map<GenericRecord>({\n input: input.where || {},\n fields: fileModel.fields\n });\n\n const sort = this.cmsSortMapper.map({\n input: input.sort,\n fields: fileModel.fields\n });\n\n const result = await this.listLatestEntries.execute(fileModel, {\n where,\n limit: input.limit || 40,\n after: input.after || undefined,\n sort: sort || [\"id_DESC\"],\n search: input.search\n });\n\n if (result.isFail()) {\n return Result.fail(new FilePersistenceError(result.error));\n }\n\n const { entries, meta } = result.value;\n\n const files = entries.map(entry => EntryToFileMapper.toFile(entry));\n\n return Result.ok({\n items: files,\n meta\n });\n }\n}\n\nexport const ListFilesRepository = RepositoryAbstraction.createImplementation({\n implementation: ListFilesRepositoryImpl,\n dependencies: [ListLatestEntriesUseCase, FileModelProvider, CmsWhereMapper, CmsSortMapper]\n});\n"],"names":["ListFilesRepositoryImpl","listLatestEntries","fileModelProvider","cmsWhereMapper","cmsSortMapper","input","fileModel","where","sort","result","undefined","Result","FilePersistenceError","entries","meta","files","entry","EntryToFileMapper","ListFilesRepository","RepositoryAbstraction","ListLatestEntriesUseCase","FileModelProvider","CmsWhereMapper","CmsSortMapper"],"mappings":";;;;;;;AAcA,MAAMA;IACF,YACYC,iBAAqD,EACrDC,iBAA8C,EAC9CC,cAAwC,EACxCC,aAAsC,CAChD;aAJUH,iBAAiB,GAAjBA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,KAAqB,EACwC;QAC7D,MAAMC,YAAY,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG;QAElD,MAAMC,QAAQ,IAAI,CAAC,cAAc,CAAC,GAAG,CAAgB;YACjD,OAAOF,MAAM,KAAK,IAAI,CAAC;YACvB,QAAQC,UAAU,MAAM;QAC5B;QAEA,MAAME,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;YAChC,OAAOH,MAAM,IAAI;YACjB,QAAQC,UAAU,MAAM;QAC5B;QAEA,MAAMG,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACH,WAAW;YAC3DC;YACA,OAAOF,MAAM,KAAK,IAAI;YACtB,OAAOA,MAAM,KAAK,IAAIK;YACtB,MAAMF,QAAQ;gBAAC;aAAU;YACzB,QAAQH,MAAM,MAAM;QACxB;QAEA,IAAII,OAAO,MAAM,IACb,OAAOE,OAAO,IAAI,CAAC,IAAIC,qBAAqBH,OAAO,KAAK;QAG5D,MAAM,EAAEI,OAAO,EAAEC,IAAI,EAAE,GAAGL,OAAO,KAAK;QAEtC,MAAMM,QAAQF,QAAQ,GAAG,CAACG,CAAAA,QAASC,kBAAkB,MAAM,CAACD;QAE5D,OAAOL,OAAO,EAAE,CAAC;YACb,OAAOI;YACPD;QACJ;IACJ;AACJ;AAEO,MAAMI,0CAAsBC,oBAAAA,oBAA0C,CAAC;IAC1E,gBAAgBnB;IAChB,cAAc;QAACoB;QAA0BC;QAAmBC;QAAgBC;KAAc;AAC9F"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
|
|
3
3
|
import { ListFilesUseCase } from "../../../features/file/ListFiles/index.js";
|
|
4
4
|
declare const inputSchema: z.ZodObject<{
|
|
5
5
|
tag: z.ZodString;
|
|
@@ -11,17 +11,27 @@ interface ImageItem {
|
|
|
11
11
|
type: string;
|
|
12
12
|
tags: string[];
|
|
13
13
|
}
|
|
14
|
-
declare class
|
|
14
|
+
declare class ListImagesByTagToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
|
|
15
15
|
private listFiles;
|
|
16
|
+
constructor(listFiles: ListFilesUseCase.Interface);
|
|
17
|
+
execute(input: Input): Promise<ImageItem[]>;
|
|
18
|
+
}
|
|
19
|
+
declare class ListImagesByTagToolImpl implements AiSdkToolDefinition.Interface<Input> {
|
|
16
20
|
readonly name = "listImagesByTag";
|
|
21
|
+
readonly title = "List images by tag";
|
|
17
22
|
readonly description = "Lists images from the file manager filtered by a given tag. Returns name, type, and tags for each image.";
|
|
18
23
|
readonly inputSchema: z.ZodObject<{
|
|
19
24
|
tag: z.ZodString;
|
|
20
25
|
}, z.core.$strip>;
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
readonly annotations: {
|
|
27
|
+
readOnlyHint: boolean;
|
|
28
|
+
idempotentHint: boolean;
|
|
29
|
+
};
|
|
30
|
+
readonly handler: typeof ListImagesByTagToolHandlerImpl & {
|
|
31
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
|
|
32
|
+
};
|
|
23
33
|
}
|
|
24
34
|
export declare const ListImagesByTagTool: typeof ListImagesByTagToolImpl & {
|
|
25
|
-
__abstraction: import("@webiny/di").Abstraction<
|
|
35
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
|
|
26
36
|
};
|
|
27
37
|
export {};
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
|
|
3
3
|
import { ListFilesUseCase } from "../ListFiles/index.js";
|
|
4
4
|
const inputSchema = z.object({
|
|
5
5
|
tag: z.string().describe("Tag to filter images by")
|
|
6
6
|
});
|
|
7
|
-
class
|
|
7
|
+
class ListImagesByTagToolHandlerImpl {
|
|
8
8
|
constructor(listFiles){
|
|
9
9
|
this.listFiles = listFiles;
|
|
10
|
-
this.name = "listImagesByTag";
|
|
11
|
-
this.description = "Lists images from the file manager filtered by a given tag. Returns name, type, and tags for each image.";
|
|
12
|
-
this.inputSchema = inputSchema;
|
|
13
10
|
}
|
|
14
11
|
async execute(input) {
|
|
15
12
|
console.log("Call images tool", input);
|
|
@@ -31,12 +28,29 @@ class ListImagesByTagToolImpl {
|
|
|
31
28
|
}));
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
|
-
const
|
|
35
|
-
implementation:
|
|
31
|
+
const ListImagesByTagToolHandler = AiSdkToolHandler.createImplementation({
|
|
32
|
+
implementation: ListImagesByTagToolHandlerImpl,
|
|
36
33
|
dependencies: [
|
|
37
34
|
ListFilesUseCase
|
|
38
35
|
]
|
|
39
36
|
});
|
|
37
|
+
class ListImagesByTagToolImpl {
|
|
38
|
+
constructor(){
|
|
39
|
+
this.name = "listImagesByTag";
|
|
40
|
+
this.title = "List images by tag";
|
|
41
|
+
this.description = "Lists images from the file manager filtered by a given tag. Returns name, type, and tags for each image.";
|
|
42
|
+
this.inputSchema = inputSchema;
|
|
43
|
+
this.annotations = {
|
|
44
|
+
readOnlyHint: true,
|
|
45
|
+
idempotentHint: true
|
|
46
|
+
};
|
|
47
|
+
this.handler = ListImagesByTagToolHandler;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const ListImagesByTagTool = AiSdkToolDefinition.createImplementation({
|
|
51
|
+
implementation: ListImagesByTagToolImpl,
|
|
52
|
+
dependencies: []
|
|
53
|
+
});
|
|
40
54
|
export { ListImagesByTagTool };
|
|
41
55
|
|
|
42
56
|
//# sourceMappingURL=ListImagesByTagTool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/ListImagesByTagTool/ListImagesByTagTool.js","sources":["../../../../src/features/file/ListImagesByTagTool/ListImagesByTagTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/file/ListImagesByTagTool/ListImagesByTagTool.js","sources":["../../../../src/features/file/ListImagesByTagTool/ListImagesByTagTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { ListFilesUseCase } from \"~/features/file/ListFiles/index.js\";\n\nconst inputSchema = z.object({\n tag: z.string().describe(\"Tag to filter images by\")\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface ImageItem {\n id: string;\n name: string;\n type: string;\n tags: string[];\n}\n\nclass ListImagesByTagToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(private listFiles: ListFilesUseCase.Interface) {}\n\n async execute(input: Input): Promise<ImageItem[]> {\n console.log(\"Call images tool\", input);\n const result = await this.listFiles.execute({\n where: {\n type_startsWith: \"image/\",\n tags_in: [input.tag]\n },\n limit: 50\n });\n\n if (result.isFail()) {\n return [];\n }\n\n return result.value.items.map(file => ({\n id: file.id,\n name: file.name,\n type: file.type,\n tags: file.tags\n }));\n }\n}\n\nconst ListImagesByTagToolHandler = AiSdkToolHandler.createImplementation({\n implementation: ListImagesByTagToolHandlerImpl,\n dependencies: [ListFilesUseCase]\n});\n\nclass ListImagesByTagToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"listImagesByTag\";\n readonly title = \"List images by tag\";\n readonly description =\n \"Lists images from the file manager filtered by a given tag. Returns name, type, and tags for each image.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n readonly handler = ListImagesByTagToolHandler;\n}\n\nexport const ListImagesByTagTool = AiSdkToolDefinition.createImplementation({\n implementation: ListImagesByTagToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","ListImagesByTagToolHandlerImpl","listFiles","input","console","result","file","ListImagesByTagToolHandler","AiSdkToolHandler","ListFilesUseCase","ListImagesByTagToolImpl","ListImagesByTagTool","AiSdkToolDefinition"],"mappings":";;;AAIA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,KAAKA,EAAE,MAAM,GAAG,QAAQ,CAAC;AAC7B;AAWA,MAAMC;IACF,YAAoBC,SAAqC,CAAE;aAAvCA,SAAS,GAATA;IAAwC;IAE5D,MAAM,QAAQC,KAAY,EAAwB;QAC9CC,QAAQ,GAAG,CAAC,oBAAoBD;QAChC,MAAME,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;YACxC,OAAO;gBACH,iBAAiB;gBACjB,SAAS;oBAACF,MAAM,GAAG;iBAAC;YACxB;YACA,OAAO;QACX;QAEA,IAAIE,OAAO,MAAM,IACb,OAAO,EAAE;QAGb,OAAOA,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAACC,CAAAA,OAAS;gBACnC,IAAIA,KAAK,EAAE;gBACX,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;YACnB;IACJ;AACJ;AAEA,MAAMC,6BAA6BC,iBAAiB,oBAAoB,CAAC;IACrE,gBAAgBP;IAChB,cAAc;QAACQ;KAAiB;AACpC;AAEA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGX;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;aACzD,OAAO,GAAGQ;;AACvB;AAEO,MAAMI,sBAAsBC,oBAAoB,oBAAoB,CAAC;IACxE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetUniqueFieldValuesUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetUniqueFieldValues";
|
|
3
3
|
import { ListTagsInput, ListTagsRepository as RepositoryAbstraction, TagItem } from "./abstractions.js";
|
|
4
|
-
import {
|
|
4
|
+
import { FileModelProvider } from "../../../domain/file/abstractions.js";
|
|
5
5
|
import { CmsWhereMapper } from "@webiny/api-headless-cms";
|
|
6
6
|
declare class ListTagsRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
7
7
|
private getUniqueFieldValues;
|
|
8
|
-
private
|
|
8
|
+
private fileModelProvider;
|
|
9
9
|
private cmsWhereMapper;
|
|
10
|
-
constructor(getUniqueFieldValues: GetUniqueFieldValuesUseCase.Interface,
|
|
10
|
+
constructor(getUniqueFieldValues: GetUniqueFieldValuesUseCase.Interface, fileModelProvider: FileModelProvider.Interface, cmsWhereMapper: CmsWhereMapper.Interface);
|
|
11
11
|
execute(input: ListTagsInput): Promise<Result<TagItem[], RepositoryAbstraction.Error>>;
|
|
12
12
|
}
|
|
13
13
|
export declare const ListTagsRepository: typeof ListTagsRepositoryImpl & {
|