diff --git a/packages/core/database/src/database.ts b/packages/core/database/src/database.ts index b72900a746..45ee08365e 100644 --- a/packages/core/database/src/database.ts +++ b/packages/core/database/src/database.ts @@ -466,6 +466,18 @@ export class Database extends EventEmitter implements AsyncEmitter { return super.on(event, listener); } + extendCollection(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) { + const collectionName = collectionOptions.name; + const existCollection = this.getCollection(collectionName); + if (existCollection) { + existCollection.updateOptions(collectionOptions, mergeOptions); + } else { + const existDelayExtends = this.delayCollectionExtend.get(collectionName) || []; + + this.delayCollectionExtend.set(collectionName, [...existDelayExtends, { collectionOptions, mergeOptions }]); + } + } + async import(options: { directory: string; extensions?: ImportFileExtension[] }): Promise> { const reader = new ImporterReader(options.directory, options.extensions); const modules = await reader.read(); @@ -473,15 +485,7 @@ export class Database extends EventEmitter implements AsyncEmitter { for (const module of modules) { if (module.extend) { - const collectionName = module.collectionOptions.name; - const existCollection = this.getCollection(collectionName); - if (existCollection) { - existCollection.updateOptions(module.collectionOptions, module.mergeOptions); - } else { - const existDelayExtends = this.delayCollectionExtend.get(collectionName) || []; - - this.delayCollectionExtend.set(collectionName, [...existDelayExtends, module]); - } + this.extendCollection(module.collectionOptions, module.mergeOptions); } else { const collection = this.collection(module); result.set(collection.name, collection); @@ -494,7 +498,7 @@ export class Database extends EventEmitter implements AsyncEmitter { declare emitAsync: (event: string | symbol, ...args: any[]) => Promise; } -export function extend(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) { +export function extendCollection(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) { return { collectionOptions, mergeOptions, @@ -502,18 +506,12 @@ export function extend(collectionOptions: CollectionOptions, mergeOptions?: Merg }; } +export const extend = extendCollection; + export const defineCollection = (collectionOptions: CollectionOptions) => { return collectionOptions; }; -export const extendCollection = (collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) => { - return { - collectionOptions, - mergeOptions, - extend: true, - }; -}; - applyMixins(Database, [AsyncEmitter]); export default Database; diff --git a/packages/core/database/src/repository.ts b/packages/core/database/src/repository.ts index 09aa4dcfae..bc21dbf289 100644 --- a/packages/core/database/src/repository.ts +++ b/packages/core/database/src/repository.ts @@ -75,7 +75,7 @@ export interface CommonFindOptions extends Transactionable { context?: any; } -interface FindOneOptions extends FindOptions, CommonFindOptions {} +interface FindOneOptions extends FindOptions {} export interface DestroyOptions extends SequelizeDestroyOptions { filter?: Filter; diff --git a/packages/plugins/workflow/src/server/extensions/assignees/collections/jobs.ts b/packages/plugins/workflow/src/server/extensions/assignees/collections/jobs.ts index 93613f72eb..294eccec89 100644 --- a/packages/plugins/workflow/src/server/extensions/assignees/collections/jobs.ts +++ b/packages/plugins/workflow/src/server/extensions/assignees/collections/jobs.ts @@ -1,6 +1,4 @@ -import { extend } from '@nocobase/database'; - -export default extend({ +export default { name: 'jobs', fields: [ { @@ -15,4 +13,4 @@ export default extend({ foreignKey: 'jobId' } ] -}); +}; diff --git a/packages/plugins/workflow/src/server/extensions/assignees/collections/users.ts b/packages/plugins/workflow/src/server/extensions/assignees/collections/users.ts index b83626ab4b..21ebdaffed 100644 --- a/packages/plugins/workflow/src/server/extensions/assignees/collections/users.ts +++ b/packages/plugins/workflow/src/server/extensions/assignees/collections/users.ts @@ -1,6 +1,4 @@ -import { extend } from '@nocobase/database'; - -export default extend({ +export default { name: 'users', fields: [ { @@ -14,4 +12,4 @@ export default extend({ target: 'users_jobs' } ] -}); +}; diff --git a/packages/plugins/workflow/src/server/extensions/assignees/index.ts b/packages/plugins/workflow/src/server/extensions/assignees/index.ts index 6b1bdf47bd..040bf83c5e 100644 --- a/packages/plugins/workflow/src/server/extensions/assignees/index.ts +++ b/packages/plugins/workflow/src/server/extensions/assignees/index.ts @@ -201,8 +201,8 @@ export default async function(plugin: Plugin) { // directory: path.join(__dirname, './collections') // }); plugin.db.collection(requireModule(path.join(__dirname, './collections/users_jobs'))); - plugin.db.collection(requireModule(path.join(__dirname, './collections/users'))); - plugin.db.collection(requireModule(path.join(__dirname, './collections/jobs'))); + plugin.db.extendCollection(requireModule(path.join(__dirname, './collections/users'))); + plugin.db.extendCollection(requireModule(path.join(__dirname, './collections/jobs'))); plugin.app.actions({ 'users_jobs:submit': submit