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);
|
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>> {
|
async import(options: { directory: string; extensions?: ImportFileExtension[] }): Promise<Map<string, Collection>> {
|
||||||
const reader = new ImporterReader(options.directory, options.extensions);
|
const reader = new ImporterReader(options.directory, options.extensions);
|
||||||
const modules = await reader.read();
|
const modules = await reader.read();
|
||||||
@ -473,15 +485,7 @@ export class Database extends EventEmitter implements AsyncEmitter {
|
|||||||
|
|
||||||
for (const module of modules) {
|
for (const module of modules) {
|
||||||
if (module.extend) {
|
if (module.extend) {
|
||||||
const collectionName = module.collectionOptions.name;
|
this.extendCollection(module.collectionOptions, module.mergeOptions);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const collection = this.collection(module);
|
const collection = this.collection(module);
|
||||||
result.set(collection.name, collection);
|
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>;
|
declare emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extend(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) {
|
export function extendCollection(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) {
|
||||||
return {
|
return {
|
||||||
collectionOptions,
|
collectionOptions,
|
||||||
mergeOptions,
|
mergeOptions,
|
||||||
@ -502,18 +506,12 @@ export function extend(collectionOptions: CollectionOptions, mergeOptions?: Merg
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const extend = extendCollection;
|
||||||
|
|
||||||
export const defineCollection = (collectionOptions: CollectionOptions) => {
|
export const defineCollection = (collectionOptions: CollectionOptions) => {
|
||||||
return collectionOptions;
|
return collectionOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extendCollection = (collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) => {
|
|
||||||
return {
|
|
||||||
collectionOptions,
|
|
||||||
mergeOptions,
|
|
||||||
extend: true,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
applyMixins(Database, [AsyncEmitter]);
|
applyMixins(Database, [AsyncEmitter]);
|
||||||
|
|
||||||
export default Database;
|
export default Database;
|
||||||
|
@ -75,7 +75,7 @@ export interface CommonFindOptions extends Transactionable {
|
|||||||
context?: any;
|
context?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FindOneOptions extends FindOptions, CommonFindOptions {}
|
interface FindOneOptions extends FindOptions {}
|
||||||
|
|
||||||
export interface DestroyOptions extends SequelizeDestroyOptions {
|
export interface DestroyOptions extends SequelizeDestroyOptions {
|
||||||
filter?: Filter;
|
filter?: Filter;
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { extend } from '@nocobase/database';
|
export default {
|
||||||
|
|
||||||
export default extend({
|
|
||||||
name: 'jobs',
|
name: 'jobs',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
@ -15,4 +13,4 @@ export default extend({
|
|||||||
foreignKey: 'jobId'
|
foreignKey: 'jobId'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
};
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { extend } from '@nocobase/database';
|
export default {
|
||||||
|
|
||||||
export default extend({
|
|
||||||
name: 'users',
|
name: 'users',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
@ -14,4 +12,4 @@ export default extend({
|
|||||||
target: 'users_jobs'
|
target: 'users_jobs'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
};
|
||||||
|
@ -201,8 +201,8 @@ export default async function(plugin: Plugin) {
|
|||||||
// directory: path.join(__dirname, './collections')
|
// directory: path.join(__dirname, './collections')
|
||||||
// });
|
// });
|
||||||
plugin.db.collection(requireModule(path.join(__dirname, './collections/users_jobs')));
|
plugin.db.collection(requireModule(path.join(__dirname, './collections/users_jobs')));
|
||||||
plugin.db.collection(requireModule(path.join(__dirname, './collections/users')));
|
plugin.db.extendCollection(requireModule(path.join(__dirname, './collections/users')));
|
||||||
plugin.db.collection(requireModule(path.join(__dirname, './collections/jobs')));
|
plugin.db.extendCollection(requireModule(path.join(__dirname, './collections/jobs')));
|
||||||
|
|
||||||
plugin.app.actions({
|
plugin.app.actions({
|
||||||
'users_jobs:submit': submit
|
'users_jobs:submit': submit
|
||||||
|
Loading…
Reference in New Issue
Block a user