Skip to content

Commit

Permalink
Move some types to the correct place, improve build errors on first b…
Browse files Browse the repository at this point in the history
…uild with the goal of having no inter-dependencies between core and non core packages
  • Loading branch information
pozylon committed Oct 22, 2024
1 parent 61e2903 commit 3f9dd33
Show file tree
Hide file tree
Showing 56 changed files with 256 additions and 160 deletions.
32 changes: 31 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 35 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,41 @@
"npm": ">=10.0.0"
},
"workspaces": [
"packages/*",
"packages/logger",
"packages/utils",
"packages/mongodb",
"packages/events",
"packages/file-upload",
"packages/roles",
"packages/shared",

"packages/core-countries",
"packages/core-currencies",
"packages/core-languages",
"packages/core-events",
"packages/core-files",
"packages/core-users",

"packages/core-bookmarks",
"packages/core-delivery",
"packages/core-messaging",
"packages/core-payment",
"packages/core-quotations",

"packages/core-products",
"packages/core-assortments",
"packages/core-filters",
"packages/core-orders",
"packages/core-warehousing",
"packages/core-worker",
"packages/core-enrollments",
"packages/core",

"packages/api",
"packages/plugins",
"packages/ticketing",
"packages/platform",

"examples/kitchensink",
"examples/minimal"
],
Expand Down
9 changes: 4 additions & 5 deletions packages/core-assortments/src/migrations/addMigrations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Migration, MigrationRepository } from '@unchainedshop/core';
import { mongodb } from '@unchainedshop/mongodb';
import { mongodb, MigrationRepository } from '@unchainedshop/mongodb';
import { AssortmentMediaCollection } from '../db/AssortmentMediaCollection.js';
import { AssortmentsCollection } from '../db/AssortmentsCollection.js';

Expand All @@ -22,7 +21,7 @@ const convertTagsToLowerCase = async (collection: mongodb.Collection<any>) => {
if (count > 0) bulk.execute();
};

export default function addMigrations(repository: MigrationRepository<Migration>) {
export default function addMigrations(repository: MigrationRepository) {
repository?.register({
id: 20220216000000,
name: 'Move _cachedProductIds cache to own collection in order to save a lot of bandwidth',
Expand All @@ -44,8 +43,8 @@ export default function addMigrations(repository: MigrationRepository<Migration>
},
{
// eslint-disable-next-line
// @ts-ignore
$set: { productIds: assortment._cachedProductIds }, // eslint-disable-line
// @ts-ignore
$set: { productIds: assortment._cachedProductIds }, // eslint-disable-line
},
{
upsert: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ModuleInput } from '@unchainedshop/core';
import { emit, registerEvents } from '@unchainedshop/events';
import {
findLocalizedText,
generateDbFilterById,
generateDbObjectId,
mongodb,
ModuleInput,
} from '@unchainedshop/mongodb';
import { FileDirector } from '@unchainedshop/file-upload';
import { AssortmentMediaCollection } from '../db/AssortmentMediaCollection.js';
Expand All @@ -17,13 +17,6 @@ const ASSORTMENT_MEDIA_EVENTS = [
'ASSORTMENT_UPDATE_MEDIA_TEXT',
];

FileDirector.registerFileUploadCallback('assortment-media', async (file, { modules }) => {
await modules.assortments.media.create({
assortmentId: file.meta.assortmentId as string,
mediaId: file._id,
});
});

export type AssortmentMediaModule = {
// Queries
findAssortmentMedia: (params: { assortmentMediaId: string }) => Promise<AssortmentMediaType>;
Expand Down Expand Up @@ -280,3 +273,16 @@ export const configureAssortmentMediaModule = async ({
},
};
};

FileDirector.registerFileUploadCallback<{
modules: {
assortments: {
media: AssortmentMediaModule;
};
};
}>('assortment-media', async (file, { modules }) => {
await modules.assortments.media.create({
assortmentId: file.meta.assortmentId as string,
mediaId: file._id,
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Tree, SortOption, SortDirection } from '@unchainedshop/utils';
import { ModuleInput } from '@unchainedshop/core';
import { emit, registerEvents } from '@unchainedshop/events';
import { log, LogLevel } from '@unchainedshop/logger';
import {
Expand All @@ -8,6 +7,7 @@ import {
buildSortOptions,
mongodb,
generateDbObjectId,
ModuleInput,
} from '@unchainedshop/mongodb';
import { resolveAssortmentProductFromDatabase } from '../utils/breadcrumbs/resolveAssortmentProductFromDatabase.js';
import { resolveAssortmentLinkFromDatabase } from '../utils/breadcrumbs/resolveAssortmentLinkFromDatabase.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { emit, registerEvents } from '@unchainedshop/events';
import { ModuleInput } from '@unchainedshop/core';
import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb';
import { BookmarksCollection } from '../db/BookmarksCollection.js';
import type { TimestampFields } from '@unchainedshop/mongodb';
import type { TimestampFields, ModuleInput } from '@unchainedshop/mongodb';

const BOOKMARK_EVENTS: string[] = ['BOOKMARK_CREATE', 'BOOKMARK_UPDATE', 'BOOKMARK_REMOVE'];

Expand Down
4 changes: 2 additions & 2 deletions packages/core-countries/src/migrations/addMigrations.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Migration, MigrationRepository } from '@unchainedshop/core';
import { MigrationRepository } from '@unchainedshop/mongodb';
import { CountriesCollection } from '../db/CountriesCollection.js';
import { Country } from '../countries-index.js';

export default function addMigrations(repository: MigrationRepository<Migration>) {
export default function addMigrations(repository: MigrationRepository) {
repository?.register({
id: 20240712123500,
name: 'Convert all tags to lower case to make it easy for search',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { mongodb, TimestampFields } from '@unchainedshop/mongodb';
import { ModuleInput } from '@unchainedshop/core';
import type { mongodb, TimestampFields, ModuleInput } from '@unchainedshop/mongodb';
import { emit, registerEvents } from '@unchainedshop/events';
import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb';
import { SortDirection, SortOption } from '@unchainedshop/utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { ModuleInput } from '@unchainedshop/core';
import { Currency, CurrencyQuery } from '../types.js';
import { emit, registerEvents } from '@unchainedshop/events';
import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb';
import {
generateDbFilterById,
buildSortOptions,
generateDbObjectId,
ModuleInput,
} from '@unchainedshop/mongodb';
import { SortDirection, SortOption } from '@unchainedshop/utils';
import { CurrenciesCollection } from '../db/CurrenciesCollection.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/core-delivery/src/module/configureDeliveryModule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ModuleInput, UnchainedCore } from '@unchainedshop/core';
import { UnchainedCore } from '@unchainedshop/core';
import { DeliveryContext, DeliveryInterface, DeliveryProvider, DeliveryProviderType } from '../types.js';
import { emit, registerEvents } from '@unchainedshop/events';
import { mongodb, generateDbFilterById, generateDbObjectId } from '@unchainedshop/mongodb';
import { mongodb, generateDbFilterById, generateDbObjectId, ModuleInput } from '@unchainedshop/mongodb';
import { DeliveryPricingSheet } from '../director/DeliveryPricingSheet.js';
import { DeliveryProvidersCollection } from '../db/DeliveryProvidersCollection.js';
import { deliverySettings, DeliverySettingsOptions } from '../delivery-settings.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SortDirection, SortOption } from '@unchainedshop/utils';
import { ModuleInput, UnchainedCore } from '@unchainedshop/core';
import { UnchainedCore } from '@unchainedshop/core';
import {
Enrollment,
EnrollmentData,
Expand All @@ -15,6 +15,7 @@ import {
Address,
Contact,
generateDbObjectId,
ModuleInput,
} from '@unchainedshop/mongodb';
import { EnrollmentsCollection } from '../db/EnrollmentsCollection.js';
import { EnrollmentStatus } from '../db/EnrollmentStatus.js';
Expand Down
5 changes: 3 additions & 2 deletions packages/core-events/src/module/configureEventsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { mongodb } from '@unchainedshop/mongodb';
import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb';
import { getRegisteredEvents } from '@unchainedshop/events';
import { SortDirection, SortOption } from '@unchainedshop/utils';
import { ModuleCreateMutation, ModuleInput } from '@unchainedshop/core';
import { ModuleInput } from '@unchainedshop/mongodb';
import { EventsCollection, Event } from '../db/EventsCollection.js';
import { configureEventHistoryAdapter } from './configureEventHistoryAdapter.js';

Expand All @@ -27,7 +27,7 @@ export const buildFindSelector = ({ types, queryString, created }: EventQuery) =
return selector;
};

export interface EventsModule extends ModuleCreateMutation<Event> {
export interface EventsModule {
findEvent: (
params: mongodb.Filter<Event> & { eventId: string },
options?: mongodb.FindOptions,
Expand All @@ -43,6 +43,7 @@ export interface EventsModule extends ModuleCreateMutation<Event> {
) => Promise<Array<Event>>;

type: (event: Event) => string;
create: (doc: Event) => Promise<string | null>;

count: (query: EventQuery) => Promise<number>;
getReport: (params?: { from?: Date; to?: Date; types?: string[] }) => Promise<EventReport[]>;
Expand Down
4 changes: 2 additions & 2 deletions packages/core-files/src/module/configureFilesModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ModuleInput } from '@unchainedshop/core';
import { ModuleInput } from '@unchainedshop/mongodb';
import { File } from '../types.js';
import { emit, registerEvents } from '@unchainedshop/events';
import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb';
Expand Down Expand Up @@ -61,7 +61,7 @@ export const configureFilesModule = async ({
return fileId;
},

update: async (fileId: string, doc: File) => {
update: async (fileId: string, doc: Partial<File>) => {
await Files.updateOne(
{ _id: fileId },
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getFileAdapter } from '../utils/getFileAdapter.js';
import { UnchainedCore } from '@unchainedshop/core';
import { Readable } from 'stream';
import { FilesModule } from '../files-index.js';

export type CreateDownloadStreamService = (
params: {
fileId: string;
},
unchainedAPI: UnchainedCore,
unchainedAPI: { modules: { files: FilesModule } },
) => Promise<Readable>;

export const createDownloadStreamService: CreateDownloadStreamService = async (
Expand Down
6 changes: 3 additions & 3 deletions packages/core-files/src/service/createSignedURLService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { UnchainedCore } from '@unchainedshop/core';
import { getFileFromFileData } from '@unchainedshop/file-upload';
import { getFileAdapter } from '../utils/getFileAdapter.js';
import { getFileFromFileData } from '../utils/getFileFromFileData.js';
import { SignedFileUpload } from '../types.js';
import { FilesModule } from '../files-index.js';

export type CreateSignedURLService = (
params: { directoryName: string; fileName: string; meta?: any },
unchainedAPI: UnchainedCore,
unchainedAPI: { modules: { files: FilesModule } },
) => Promise<SignedFileUpload>;

export const createSignedURLService: CreateSignedURLService = async (
Expand Down
4 changes: 2 additions & 2 deletions packages/core-files/src/service/linkFileService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FileDirector } from '@unchainedshop/file-upload';
import { UnchainedCore } from '@unchainedshop/core';
import { File } from '../types.js';
import { FilesModule } from '../files-index.js';

export type LinkFileService = (
params: { fileId: string; size: number; type?: string },
unchainedAPI: UnchainedCore,
unchainedAPI: { modules: { files: FilesModule } },
) => Promise<File>;

export const linkFileService: LinkFileService = async ({ fileId, size, type }, unchainedAPI) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core-files/src/service/removeFilesService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { mongodb } from '@unchainedshop/mongodb';
import { getFileAdapter } from '../utils/getFileAdapter.js';
import { UnchainedCore } from '@unchainedshop/core';
import { File } from '../types.js';
import { FilesModule } from '../files-index.js';

export type RemoveFilesService = (
params: { fileIds: Array<string> },
unchainedAPI: UnchainedCore,
unchainedAPI: { modules: { files: FilesModule } },
) => Promise<number>;

export const removeFilesService: RemoveFilesService = async ({ fileIds }, unchainedAPI) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { UnchainedCore } from '@unchainedshop/core';
import { getFileAdapter } from '../utils/getFileAdapter.js';
import { getFileFromFileData } from '../utils/getFileFromFileData.js';
import { getFileFromFileData } from '@unchainedshop/file-upload';
import { File } from '../types.js';
import { FilesModule } from '../files-index.js';

export type UploadFileFromStreamService = (
params: { directoryName: string; rawFile: any; meta?: any },
unchainedAPI: UnchainedCore,
unchainedAPI: { modules: { files: FilesModule } },
) => Promise<File>;

export const uploadFileFromStreamService: UploadFileFromStreamService = async (
Expand Down
6 changes: 3 additions & 3 deletions packages/core-files/src/service/uploadFileFromURLService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getFileAdapter } from '../utils/getFileAdapter.js';
import { getFileFromFileData } from '../utils/getFileFromFileData.js';
import { UnchainedCore } from '@unchainedshop/core';
import { getFileFromFileData } from '@unchainedshop/file-upload';
import { File } from '../types.js';
import { FilesModule } from '../files-index.js';

export type UploadFileFromURLService = (
params: {
Expand All @@ -14,7 +14,7 @@ export type UploadFileFromURLService = (
};
meta?: any;
},
unchainedAPI: UnchainedCore,
unchainedAPI: { modules: { files: FilesModule } },
) => Promise<File>;

export const uploadFileFromURLService: UploadFileFromURLService = async (
Expand Down
12 changes: 0 additions & 12 deletions packages/core-files/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,3 @@ export type File = {
export type SignedFileUpload = File & {
putURL: string;
};

export interface UploadFileData {
_id?: string;
directoryName: string;
expiryDate: Date;
fileName: string;
hash: string;
hashedName: string;
size?: number;
type: string;
url: string;
}
3 changes: 2 additions & 1 deletion packages/core-filters/src/module/configureFiltersModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
generateDbFilterById,
buildSortOptions,
generateDbObjectId,
ModuleInput,
} from '@unchainedshop/mongodb';
import { ModuleInput, UnchainedCore } from '@unchainedshop/core';
import { UnchainedCore } from '@unchainedshop/core';
import { FilterType } from '../db/FilterType.js';
import { FilterDirector } from '../director/FilterDirector.js';
import { FiltersCollection } from '../db/FiltersCollection.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ModuleInput } from '@unchainedshop/core';
import { ModuleInput } from '@unchainedshop/mongodb';
import { emit, registerEvents } from '@unchainedshop/events';
import {
generateDbFilterById,
Expand Down
Loading

0 comments on commit 3f9dd33

Please sign in to comment.