From c736d3dbed9adecc6551461f2084cfdc8d68e71b Mon Sep 17 00:00:00 2001 From: Pascal Kaufmann Date: Fri, 22 Nov 2024 17:32:32 +0100 Subject: [PATCH] Move more services --- packages/core-bookmarks/package.json | 2 +- .../core-bookmarks/src/bookmarks-index.ts | 2 +- .../src/module/configureBookmarksModule.ts | 9 ++- .../src/service/bookmarkServices.ts | 11 --- packages/core-files/src/files-index.ts | 3 +- .../core-files/src/service/fileServices.ts | 30 --------- .../src/utils/getFileFromFileData.ts} | 2 +- packages/core-orders/src/orders-index.ts | 1 - .../core-orders/src/service/orderServices.ts | 12 ---- packages/core/package.json | 1 + packages/core/src/core-index.ts | 51 ++------------ .../services}/createDownloadStreamService.ts | 3 +- .../src/services}/createSignedURLService.ts | 10 +-- packages/core/src/services/index.ts | 67 +++++++++++++++++++ .../src/services}/linkFileService.ts | 5 +- .../src/services}/migrateBookmarksService.ts | 2 +- .../src/services}/migrateOrderCartService.ts | 15 +++-- .../src/services/migrateUserDataService.ts | 5 +- .../src/services}/nextUserCartService.ts | 19 ++++-- .../src/services}/removeFilesService.ts | 13 ++-- .../updateUserAvatarAfterUploadService.ts | 11 ++- .../services}/uploadFileFromStreamService.ts | 5 +- .../src/services}/uploadFileFromURLService.ts | 5 +- packages/file-upload/src/file-upload-index.ts | 3 +- 24 files changed, 138 insertions(+), 149 deletions(-) delete mode 100644 packages/core-bookmarks/src/service/bookmarkServices.ts delete mode 100644 packages/core-files/src/service/fileServices.ts rename packages/{file-upload/src/get-file-from-file-data.ts => core-files/src/utils/getFileFromFileData.ts} (84%) delete mode 100644 packages/core-orders/src/service/orderServices.ts rename packages/{core-files/src/service => core/src/services}/createDownloadStreamService.ts (83%) rename packages/{core-files/src/service => core/src/services}/createSignedURLService.ts (78%) create mode 100644 packages/core/src/services/index.ts rename packages/{core-files/src/service => core/src/services}/linkFileService.ts (86%) rename packages/{core-bookmarks/src/service => core/src/services}/migrateBookmarksService.ts (95%) rename packages/{core-orders/src/service => core/src/services}/migrateOrderCartService.ts (87%) rename packages/{core-orders/src/service => core/src/services}/nextUserCartService.ts (73%) rename packages/{core-files/src/service => core/src/services}/removeFilesService.ts (73%) rename packages/{core-files/src/service => core/src/services}/uploadFileFromStreamService.ts (76%) rename packages/{core-files/src/service => core/src/services}/uploadFileFromURLService.ts (79%) diff --git a/packages/core-bookmarks/package.json b/packages/core-bookmarks/package.json index fa89a50a42..f788e9c2fb 100644 --- a/packages/core-bookmarks/package.json +++ b/packages/core-bookmarks/package.json @@ -29,7 +29,7 @@ "homepage": "https://github.com/unchainedshop/unchained#readme", "dependencies": { "@unchainedshop/events": "^3.0.0-alpha4", - "@unchainedshop/utils": "^3.0.0-alpha4" + "@unchainedshop/mongodb": "^3.0.0-alpha4" }, "devDependencies": { "@types/node": "^22.9.1", diff --git a/packages/core-bookmarks/src/bookmarks-index.ts b/packages/core-bookmarks/src/bookmarks-index.ts index 7d991fbed9..49bd3e5208 100644 --- a/packages/core-bookmarks/src/bookmarks-index.ts +++ b/packages/core-bookmarks/src/bookmarks-index.ts @@ -1,2 +1,2 @@ export * from './module/configureBookmarksModule.js'; -export * from './service/bookmarkServices.js'; +export * from './db/BookmarksCollection.js'; diff --git a/packages/core-bookmarks/src/module/configureBookmarksModule.ts b/packages/core-bookmarks/src/module/configureBookmarksModule.ts index f0f769dae3..99cfc660a0 100644 --- a/packages/core-bookmarks/src/module/configureBookmarksModule.ts +++ b/packages/core-bookmarks/src/module/configureBookmarksModule.ts @@ -1,7 +1,12 @@ import { emit, registerEvents } from '@unchainedshop/events'; -import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb'; +import { + generateDbFilterById, + generateDbObjectId, + mongodb, + TimestampFields, + ModuleInput, +} from '@unchainedshop/mongodb'; import { BookmarksCollection } from '../db/BookmarksCollection.js'; -import { TimestampFields, ModuleInput } from '@unchainedshop/mongodb'; const BOOKMARK_EVENTS: string[] = ['BOOKMARK_CREATE', 'BOOKMARK_UPDATE', 'BOOKMARK_REMOVE']; diff --git a/packages/core-bookmarks/src/service/bookmarkServices.ts b/packages/core-bookmarks/src/service/bookmarkServices.ts deleted file mode 100644 index 51ba371d69..0000000000 --- a/packages/core-bookmarks/src/service/bookmarkServices.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { MigrateBookmarksService, migrateBookmarksService } from './migrateBookmarksService.js'; - -export interface BookmarkServices { - migrateBookmarks: MigrateBookmarksService; -} - -export const bookmarkServices: BookmarkServices = { - migrateBookmarks: migrateBookmarksService, -}; - -export type { MigrateBookmarksService }; diff --git a/packages/core-files/src/files-index.ts b/packages/core-files/src/files-index.ts index 8ee138a771..1def7bb5b2 100644 --- a/packages/core-files/src/files-index.ts +++ b/packages/core-files/src/files-index.ts @@ -1,4 +1,5 @@ export * from './types.js'; export * from './module/configureFilesModule.js'; -export * from './service/fileServices.js'; export * from './files-settings.js'; +export * from './utils/getFileAdapter.js'; +export * from './utils/getFileFromFileData.js'; diff --git a/packages/core-files/src/service/fileServices.ts b/packages/core-files/src/service/fileServices.ts deleted file mode 100644 index 7d74abfb9f..0000000000 --- a/packages/core-files/src/service/fileServices.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { LinkFileService, linkFileService } from './linkFileService.js'; -import { CreateSignedURLService, createSignedURLService } from './createSignedURLService.js'; -import { UploadFileFromURLService, uploadFileFromURLService } from './uploadFileFromURLService.js'; -import { - UploadFileFromStreamService, - uploadFileFromStreamService, -} from './uploadFileFromStreamService.js'; -import { RemoveFilesService, removeFilesService } from './removeFilesService.js'; -import { - CreateDownloadStreamService, - createDownloadStreamService, -} from './createDownloadStreamService.js'; - -export interface FileServices { - linkFile: LinkFileService; - uploadFileFromStream: UploadFileFromStreamService; - uploadFileFromURL: UploadFileFromURLService; - createSignedURL: CreateSignedURLService; - removeFiles: RemoveFilesService; - createDownloadStream: CreateDownloadStreamService; -} - -export const fileServices: FileServices = { - linkFile: linkFileService, - createSignedURL: createSignedURLService, - uploadFileFromURL: uploadFileFromURLService, - uploadFileFromStream: uploadFileFromStreamService, - removeFiles: removeFilesService, - createDownloadStream: createDownloadStreamService, -}; diff --git a/packages/file-upload/src/get-file-from-file-data.ts b/packages/core-files/src/utils/getFileFromFileData.ts similarity index 84% rename from packages/file-upload/src/get-file-from-file-data.ts rename to packages/core-files/src/utils/getFileFromFileData.ts index b7b4a5df49..3805524496 100644 --- a/packages/file-upload/src/get-file-from-file-data.ts +++ b/packages/core-files/src/utils/getFileFromFileData.ts @@ -1,4 +1,4 @@ -import { UploadFileData } from './types.js'; +import { UploadFileData } from '@unchainedshop/file-upload'; export const getFileFromFileData = (fileData: UploadFileData, meta: any) => ({ _id: fileData._id, diff --git a/packages/core-orders/src/orders-index.ts b/packages/core-orders/src/orders-index.ts index c5d9facfe6..018ad6c6a3 100644 --- a/packages/core-orders/src/orders-index.ts +++ b/packages/core-orders/src/orders-index.ts @@ -1,6 +1,5 @@ export * from './types.js'; export * from './module/configureOrdersModule.js'; -export * from './service/orderServices.js'; export * from './orders-settings.js'; export * from './director/OrderDiscountConfiguration.js'; diff --git a/packages/core-orders/src/service/orderServices.ts b/packages/core-orders/src/service/orderServices.ts deleted file mode 100644 index 68c7bc7672..0000000000 --- a/packages/core-orders/src/service/orderServices.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { migrateOrderCartsService, MigrateOrderCartsService } from './migrateOrderCartService.js'; -import { nextUserCartService, NextUserCartService } from './nextUserCartService.js'; - -export interface OrderServices { - migrateOrderCarts: MigrateOrderCartsService; - nextUserCart: NextUserCartService; -} - -export const orderServices: OrderServices = { - migrateOrderCarts: migrateOrderCartsService, - nextUserCart: nextUserCartService, -}; diff --git a/packages/core/package.json b/packages/core/package.json index 710ad93262..8578b3917a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -46,6 +46,7 @@ "@unchainedshop/core-users": "^3.0.0-alpha4", "@unchainedshop/core-warehousing": "^3.0.0-alpha4", "@unchainedshop/core-worker": "^3.0.0-alpha4", + "@unchainedshop/utils": "^3.0.0-alpha4", "@unchainedshop/logger": "^3.0.0-alpha4" }, "devDependencies": { diff --git a/packages/core/src/core-index.ts b/packages/core/src/core-index.ts index 6f75bcddca..3c8c888c02 100644 --- a/packages/core/src/core-index.ts +++ b/packages/core/src/core-index.ts @@ -4,12 +4,7 @@ import { AssortmentsSettingsOptions, configureAssortmentsModule, } from '@unchainedshop/core-assortments'; -import { - BookmarkServices, - bookmarkServices, - BookmarksModule, - configureBookmarksModule, -} from '@unchainedshop/core-bookmarks'; +import { BookmarksModule, configureBookmarksModule } from '@unchainedshop/core-bookmarks'; import { configureCountriesModule, CountriesModule } from '@unchainedshop/core-countries'; import { configureCurrenciesModule, CurrenciesModule } from '@unchainedshop/core-currencies'; import { @@ -23,13 +18,7 @@ import { EnrollmentsSettingsOptions, } from '@unchainedshop/core-enrollments'; import { configureEventsModule, EventsModule } from '@unchainedshop/core-events'; -import { - configureFilesModule, - FileServices, - fileServices, - FilesModule, - FilesSettingsOptions, -} from '@unchainedshop/core-files'; +import { configureFilesModule, FilesModule, FilesSettingsOptions } from '@unchainedshop/core-files'; import { configureFiltersModule, FiltersModule, @@ -37,13 +26,7 @@ import { } from '@unchainedshop/core-filters'; import { configureLanguagesModule, LanguagesModule } from '@unchainedshop/core-languages'; import { configureMessagingModule, MessagingModule } from '@unchainedshop/core-messaging'; -import { - configureOrdersModule, - OrderServices, - orderServices, - OrdersModule, - OrdersSettingsOptions, -} from '@unchainedshop/core-orders'; +import { configureOrdersModule, OrdersModule, OrdersSettingsOptions } from '@unchainedshop/core-orders'; import { configurePaymentModule, PaymentModule, @@ -51,8 +34,6 @@ import { } from '@unchainedshop/core-payment'; import { configureProductsModule, - ProductServices, - productServices, ProductsModule, ProductsSettingsOptions, } from '@unchainedshop/core-products'; @@ -65,9 +46,9 @@ import { configureUsersModule, UserSettingsOptions, UsersModule } from '@unchain import { configureWarehousingModule, WarehousingModule } from '@unchainedshop/core-warehousing'; import { configureWorkerModule, WorkerModule, WorkerSettingsOptions } from '@unchainedshop/core-worker'; import { mongodb, MigrationRepository, ModuleInput } from '@unchainedshop/mongodb'; -import { migrateUserDataService } from './services/migrateUserDataService.js'; -import { updateUserAvatarAfterUploadService } from './services/updateUserAvatarAfterUploadService.js'; +import defaultServices, { Services } from './services/index.js'; +export * from './services/index.js'; export * from './types.js'; export interface ModuleOptions { @@ -119,19 +100,6 @@ export interface Modules { worker: WorkerModule; } -export interface UserServices { - updateUserAvatarAfterUpload: typeof updateUserAvatarAfterUploadService; - migrateUserData: typeof migrateUserDataService; -} - -export interface Services { - bookmarks: BookmarkServices; - files: FileServices; - orders: OrderServices; - products: ProductServices; - users: UserServices; -} - export interface UnchainedCore { modules: Modules; services: Services; @@ -267,14 +235,7 @@ export const initCore = async ({ ...customModules, }, services: { - bookmarks: bookmarkServices, - files: fileServices, - orders: orderServices, - products: productServices, - users: { - migrateUserData: migrateUserDataService, - updateUserAvatarAfterUpload: updateUserAvatarAfterUploadService, - }, + ...defaultServices, ...services, }, bulkImporter, diff --git a/packages/core-files/src/service/createDownloadStreamService.ts b/packages/core/src/services/createDownloadStreamService.ts similarity index 83% rename from packages/core-files/src/service/createDownloadStreamService.ts rename to packages/core/src/services/createDownloadStreamService.ts index 51971a7803..f43b843a01 100644 --- a/packages/core-files/src/service/createDownloadStreamService.ts +++ b/packages/core/src/services/createDownloadStreamService.ts @@ -1,6 +1,5 @@ -import { getFileAdapter } from '../utils/getFileAdapter.js'; import { Readable } from 'stream'; -import { FilesModule } from '../files-index.js'; +import { FilesModule, getFileAdapter } from '@unchainedshop/core-files'; export type CreateDownloadStreamService = ( params: { diff --git a/packages/core-files/src/service/createSignedURLService.ts b/packages/core/src/services/createSignedURLService.ts similarity index 78% rename from packages/core-files/src/service/createSignedURLService.ts rename to packages/core/src/services/createSignedURLService.ts index 339ec268a5..285681024e 100644 --- a/packages/core-files/src/service/createSignedURLService.ts +++ b/packages/core/src/services/createSignedURLService.ts @@ -1,7 +1,9 @@ -import { getFileFromFileData } from '@unchainedshop/file-upload'; -import { getFileAdapter } from '../utils/getFileAdapter.js'; -import { SignedFileUpload } from '../types.js'; -import { FilesModule } from '../files-index.js'; +import { + getFileFromFileData, + getFileAdapter, + SignedFileUpload, + FilesModule, +} from '@unchainedshop/core-files'; export type CreateSignedURLService = ( params: { directoryName: string; fileName: string; meta?: any }, diff --git a/packages/core/src/services/index.ts b/packages/core/src/services/index.ts new file mode 100644 index 0000000000..9de9d86a9a --- /dev/null +++ b/packages/core/src/services/index.ts @@ -0,0 +1,67 @@ +import { productServices, ProductServices } from '@unchainedshop/core-products'; + +import { migrateUserDataService } from './migrateUserDataService.js'; +import { updateUserAvatarAfterUploadService } from './updateUserAvatarAfterUploadService.js'; +import { linkFileService } from './linkFileService.js'; +import { createSignedURLService } from './createSignedURLService.js'; +import { uploadFileFromURLService } from './uploadFileFromURLService.js'; +import { uploadFileFromStreamService } from './uploadFileFromStreamService.js'; +import { removeFilesService } from './removeFilesService.js'; +import { createDownloadStreamService } from './createDownloadStreamService.js'; +import { migrateBookmarksService } from './migrateBookmarksService.js'; +import { migrateOrderCartsService } from './migrateOrderCartService.js'; +import { nextUserCartService } from './nextUserCartService.js'; + +export interface UserServices { + updateUserAvatarAfterUpload: typeof updateUserAvatarAfterUploadService; + migrateUserData: typeof migrateUserDataService; +} + +export interface FileServices { + linkFile: typeof linkFileService; + uploadFileFromStream: typeof uploadFileFromStreamService; + uploadFileFromURL: typeof uploadFileFromURLService; + createSignedURL: typeof createSignedURLService; + removeFiles: typeof removeFilesService; + createDownloadStream: typeof createDownloadStreamService; +} + +export interface BookmarkServices { + migrateBookmarks: typeof migrateBookmarksService; +} + +export interface OrderServices { + migrateOrderCarts: typeof migrateOrderCartsService; + nextUserCart: typeof nextUserCartService; +} + +export interface Services { + bookmarks: BookmarkServices; + files: FileServices; + orders: OrderServices; + products: ProductServices; + users: UserServices; +} + +export default { + bookmarks: { + migrateBookmarks: migrateBookmarksService, + }, + files: { + linkFile: linkFileService, + createSignedURL: createSignedURLService, + uploadFileFromURL: uploadFileFromURLService, + uploadFileFromStream: uploadFileFromStreamService, + removeFiles: removeFilesService, + createDownloadStream: createDownloadStreamService, + }, + orders: { + migrateOrderCarts: migrateOrderCartsService, + nextUserCart: nextUserCartService, + }, + products: productServices, + users: { + migrateUserData: migrateUserDataService, + updateUserAvatarAfterUpload: updateUserAvatarAfterUploadService, + }, +}; diff --git a/packages/core-files/src/service/linkFileService.ts b/packages/core/src/services/linkFileService.ts similarity index 86% rename from packages/core-files/src/service/linkFileService.ts rename to packages/core/src/services/linkFileService.ts index 3238fd6fff..f48c4dd362 100644 --- a/packages/core-files/src/service/linkFileService.ts +++ b/packages/core/src/services/linkFileService.ts @@ -1,6 +1,7 @@ import { FileDirector } from '@unchainedshop/file-upload'; -import { File } from '../types.js'; -import { FilesModule } from '../files-index.js'; +import { FilesModule, File } from '@unchainedshop/core-files'; + +// TODO: Find solution for FileDirector dependency export type LinkFileService = ( params: { fileId: string; size: number; type?: string }, diff --git a/packages/core-bookmarks/src/service/migrateBookmarksService.ts b/packages/core/src/services/migrateBookmarksService.ts similarity index 95% rename from packages/core-bookmarks/src/service/migrateBookmarksService.ts rename to packages/core/src/services/migrateBookmarksService.ts index f9967b1902..46d9141a7a 100644 --- a/packages/core-bookmarks/src/service/migrateBookmarksService.ts +++ b/packages/core/src/services/migrateBookmarksService.ts @@ -1,4 +1,4 @@ -import { BookmarksModule } from '../bookmarks-index.js'; +import { BookmarksModule } from '@unchainedshop/core-bookmarks'; export type MigrateBookmarksService = ( params: { diff --git a/packages/core-orders/src/service/migrateOrderCartService.ts b/packages/core/src/services/migrateOrderCartService.ts similarity index 87% rename from packages/core-orders/src/service/migrateOrderCartService.ts rename to packages/core/src/services/migrateOrderCartService.ts index 09ad2520a6..774a4521c7 100644 --- a/packages/core-orders/src/service/migrateOrderCartService.ts +++ b/packages/core/src/services/migrateOrderCartService.ts @@ -1,5 +1,4 @@ -import { UnchainedCore } from '@unchainedshop/core'; -import { Order } from '../types.js'; +import { Order, OrdersModule } from '@unchainedshop/core-orders'; export type MigrateOrderCartsService = ( params: { @@ -8,7 +7,11 @@ export type MigrateOrderCartsService = ( shouldMerge: boolean; countryContext: string; }, - unchainedAPI: UnchainedCore, + unchainedAPI: { + modules: { + orders: OrdersModule; + }; + }, ) => Promise; export const migrateOrderCartsService: MigrateOrderCartsService = async ( @@ -32,7 +35,7 @@ export const migrateOrderCartsService: MigrateOrderCartsService = async ( if (!toCart || !shouldMerge) { // No destination cart, move whole cart unchainedAPI.modules.orders.setCartOwner({ orderId: fromCart._id, userId: toUserId }); - return unchainedAPI.modules.orders.updateCalculation(fromCart._id, unchainedAPI); + return unchainedAPI.modules.orders.updateCalculation(fromCart._id, unchainedAPI as any); } // Move positions @@ -48,6 +51,6 @@ export const migrateOrderCartsService: MigrateOrderCartsService = async ( await unchainedAPI.modules.orders.updateContact(toCart._id, fromCart.contact); } - await unchainedAPI.modules.orders.updateCalculation(fromCart._id, unchainedAPI); - return unchainedAPI.modules.orders.updateCalculation(toCart._id, unchainedAPI); + await unchainedAPI.modules.orders.updateCalculation(fromCart._id, unchainedAPI as any); + return unchainedAPI.modules.orders.updateCalculation(toCart._id, unchainedAPI as any); }; diff --git a/packages/core/src/services/migrateUserDataService.ts b/packages/core/src/services/migrateUserDataService.ts index 876ea42dac..0ec7f38cc4 100644 --- a/packages/core/src/services/migrateUserDataService.ts +++ b/packages/core/src/services/migrateUserDataService.ts @@ -1,4 +1,6 @@ import { userSettings, UsersModule } from '@unchainedshop/core-users'; +import { BookmarksModule } from '@unchainedshop/core-bookmarks'; +import { migrateBookmarksService } from './migrateBookmarksService.js'; export type MigrateUserDataService = ( userIdBeforeLogin, @@ -6,13 +8,14 @@ export type MigrateUserDataService = ( unchainedAPI: { modules: { users: UsersModule; + bookmarks: BookmarksModule; }; services: { orders: { migrateOrderCarts: any; }; bookmarks: { - migrateBookmarks: any; + migrateBookmarks: typeof migrateBookmarksService; }; }; }, diff --git a/packages/core-orders/src/service/nextUserCartService.ts b/packages/core/src/services/nextUserCartService.ts similarity index 73% rename from packages/core-orders/src/service/nextUserCartService.ts rename to packages/core/src/services/nextUserCartService.ts index ad6204f694..f0f9bc93cd 100644 --- a/packages/core-orders/src/service/nextUserCartService.ts +++ b/packages/core/src/services/nextUserCartService.ts @@ -1,8 +1,8 @@ -import { User } from '@unchainedshop/core-users'; -import { ordersSettings } from '../orders-settings.js'; +import { User, UsersModule } from '@unchainedshop/core-users'; import { resolveBestCurrency } from '@unchainedshop/utils'; -import { UnchainedCore } from '@unchainedshop/core'; -import { Order } from '../types.js'; +import { ordersSettings, Order, OrdersModule } from '@unchainedshop/core-orders'; +import { CountriesModule } from '@unchainedshop/core-countries'; +import { CurrenciesModule } from '@unchainedshop/core-currencies'; export type NextUserCartService = ( params: { @@ -11,7 +11,14 @@ export type NextUserCartService = ( countryCode?: string; forceCartCreation?: boolean; }, - unchainedAPI: UnchainedCore, + unchainedAPI: { + modules: { + orders: OrdersModule; + countries: CountriesModule; + currencies: CurrenciesModule; + users: UsersModule; + }; + }, ) => Promise; export const nextUserCartService: NextUserCartService = async ( @@ -50,5 +57,5 @@ export const nextUserCartService: NextUserCartService = async ( : {}), }); - return modules.orders.initProviders(order, unchainedAPI); + return modules.orders.initProviders(order, unchainedAPI as any); }; diff --git a/packages/core-files/src/service/removeFilesService.ts b/packages/core/src/services/removeFilesService.ts similarity index 73% rename from packages/core-files/src/service/removeFilesService.ts rename to packages/core/src/services/removeFilesService.ts index 200f3c03f8..dd358cd986 100644 --- a/packages/core-files/src/service/removeFilesService.ts +++ b/packages/core/src/services/removeFilesService.ts @@ -1,7 +1,4 @@ -import { mongodb } from '@unchainedshop/mongodb'; -import { getFileAdapter } from '../utils/getFileAdapter.js'; -import { File } from '../types.js'; -import { FilesModule } from '../files-index.js'; +import { FilesModule, getFileAdapter } from '@unchainedshop/core-files'; export type RemoveFilesService = ( params: { fileIds: Array }, @@ -16,13 +13,11 @@ export const removeFilesService: RemoveFilesService = async ({ fileIds }, unchai if (fileIds && typeof fileIds !== 'string' && !Array.isArray(fileIds)) throw Error('Media id/s to be removed not provided as a string or array'); - const selector: mongodb.Filter = { - _id: { $in: fileIds }, - }; - const fileUploadAdapter = getFileAdapter(); - const fileObjects = await files.findFiles(selector); + const fileObjects = await files.findFiles({ + _id: { $in: fileIds }, + }); try { await fileUploadAdapter.removeFiles(fileObjects, unchainedAPI); diff --git a/packages/core/src/services/updateUserAvatarAfterUploadService.ts b/packages/core/src/services/updateUserAvatarAfterUploadService.ts index c0c697554e..0739c57aea 100644 --- a/packages/core/src/services/updateUserAvatarAfterUploadService.ts +++ b/packages/core/src/services/updateUserAvatarAfterUploadService.ts @@ -1,12 +1,17 @@ -import { File, FileServices, FilesModule } from '@unchainedshop/core-files'; +import { File, FilesModule } from '@unchainedshop/core-files'; import { log, LogLevel } from '@unchainedshop/logger'; -import { UsersModule } from '@unchainedshop/core-users/lib/users-index.js'; +import { UsersModule } from '@unchainedshop/core-users'; +import { removeFilesService } from './removeFilesService.js'; export type UpdateUserAvatarAfterUploadService = ( params: { file: File }, context: { modules: { files: FilesModule; users: UsersModule }; - services: { files: FileServices }; + services: { + files: { + removeFiles: typeof removeFilesService; + }; + }; }, ) => Promise; diff --git a/packages/core-files/src/service/uploadFileFromStreamService.ts b/packages/core/src/services/uploadFileFromStreamService.ts similarity index 76% rename from packages/core-files/src/service/uploadFileFromStreamService.ts rename to packages/core/src/services/uploadFileFromStreamService.ts index 60c15ee091..600f5d7485 100644 --- a/packages/core-files/src/service/uploadFileFromStreamService.ts +++ b/packages/core/src/services/uploadFileFromStreamService.ts @@ -1,7 +1,4 @@ -import { getFileAdapter } from '../utils/getFileAdapter.js'; -import { getFileFromFileData } from '@unchainedshop/file-upload'; -import { File } from '../types.js'; -import { FilesModule } from '../files-index.js'; +import { getFileFromFileData, getFileAdapter, File, FilesModule } from '@unchainedshop/core-files'; export type UploadFileFromStreamService = ( params: { directoryName: string; rawFile: any; meta?: any }, diff --git a/packages/core-files/src/service/uploadFileFromURLService.ts b/packages/core/src/services/uploadFileFromURLService.ts similarity index 79% rename from packages/core-files/src/service/uploadFileFromURLService.ts rename to packages/core/src/services/uploadFileFromURLService.ts index 6e63cc803d..073289f54c 100644 --- a/packages/core-files/src/service/uploadFileFromURLService.ts +++ b/packages/core/src/services/uploadFileFromURLService.ts @@ -1,7 +1,4 @@ -import { getFileAdapter } from '../utils/getFileAdapter.js'; -import { getFileFromFileData } from '@unchainedshop/file-upload'; -import { File } from '../types.js'; -import { FilesModule } from '../files-index.js'; +import { getFileFromFileData, getFileAdapter, FilesModule, File } from '@unchainedshop/core-files'; export type UploadFileFromURLService = ( params: { diff --git a/packages/file-upload/src/file-upload-index.ts b/packages/file-upload/src/file-upload-index.ts index a5eff953cf..58c9e2ae1c 100644 --- a/packages/file-upload/src/file-upload-index.ts +++ b/packages/file-upload/src/file-upload-index.ts @@ -1,8 +1,7 @@ import buildHashedFilename from './build-hashed-filename.js'; import resolveExpirationDate from './put-expiration.js'; -import getFileFromFileData from './get-file-from-file-data.js'; export { FileDirector } from './director/FileDirector.js'; export { FileAdapter, IFileAdapter } from './director/FileAdapter.js'; -export { buildHashedFilename, resolveExpirationDate, getFileFromFileData }; +export { buildHashedFilename, resolveExpirationDate }; export type * from './types.js';