fix(plugin-workflow): fix extend collection (#708)
* fix(plugin-workflow): fix extend collection * fix: extendCollection Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
parent
cec5733260
commit
0190c573c5
@ -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<Map<string, Collection>> {
|
||||
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<boolean>;
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -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;
|
||||
|
@ -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'
|
||||
}
|
||||
]
|
||||
});
|
||||
};
|
||||
|
@ -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'
|
||||
}
|
||||
]
|
||||
});
|
||||
};
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user