mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 14:39:25 +08:00
* chore: main datasource api * chore: test * chore: console.log * chore: middleware order * chore: test * chore: middleware order * chore: test * chore: middleware options
33 lines
1005 B
TypeScript
33 lines
1005 B
TypeScript
import { DataSourceOptions, SequelizeDataSource } from '@nocobase/data-source-manager';
|
|
import { db2resource, parseVariables } from './middlewares';
|
|
import { dateTemplate } from './middlewares/data-template';
|
|
|
|
export class MainDataSource extends SequelizeDataSource {
|
|
init(options: DataSourceOptions = {}) {
|
|
const { acl, resourceManager, database } = options;
|
|
|
|
this.acl = acl;
|
|
this.resourceManager = resourceManager;
|
|
|
|
this.collectionManager = this.createCollectionManager({
|
|
collectionManager: {
|
|
database,
|
|
collectionsFilter: (collection) => {
|
|
return collection.options.loadedFromCollectionManager;
|
|
},
|
|
},
|
|
});
|
|
|
|
if (options.useACL !== false) {
|
|
this.resourceManager.use(this.acl.middleware(), { group: 'acl', after: 'auth' });
|
|
}
|
|
|
|
this.resourceManager.use(parseVariables, {
|
|
group: 'parseVariables',
|
|
after: 'acl',
|
|
});
|
|
|
|
this.resourceManager.use(dateTemplate, { group: 'dateTemplate', after: 'acl' });
|
|
}
|
|
}
|