@nocobase/data-source-manager 0.21.0-alpha.6 → 0.21.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { ToposortOptions } from '@nocobase/utils';
|
|
2
2
|
import { DataSource } from './data-source';
|
|
3
3
|
import { DataSourceFactory } from './data-source-factory';
|
|
4
|
+
type DataSourceHook = (dataSource: DataSource) => void;
|
|
4
5
|
export declare class DataSourceManager {
|
|
5
6
|
options: {};
|
|
6
7
|
dataSources: Map<string, DataSource>;
|
|
7
8
|
factory: DataSourceFactory;
|
|
9
|
+
onceHooks: Array<DataSourceHook>;
|
|
8
10
|
protected middlewares: any[];
|
|
9
11
|
constructor(options?: {});
|
|
10
12
|
add(dataSource: DataSource, options?: any): Promise<void>;
|
|
11
13
|
use(fn: any, options?: ToposortOptions): void;
|
|
12
14
|
middleware(): (ctx: any, next: any) => Promise<any>;
|
|
15
|
+
afterAddDataSource(hook: DataSourceHook): void;
|
|
16
|
+
private addHookAndRun;
|
|
13
17
|
}
|
|
18
|
+
export {};
|
|
@@ -30,10 +30,14 @@ const _DataSourceManager = class _DataSourceManager {
|
|
|
30
30
|
}
|
|
31
31
|
dataSources;
|
|
32
32
|
factory = new import_data_source_factory.DataSourceFactory();
|
|
33
|
+
onceHooks = [];
|
|
33
34
|
middlewares = [];
|
|
34
35
|
async add(dataSource, options = {}) {
|
|
35
36
|
await dataSource.load(options);
|
|
36
37
|
this.dataSources.set(dataSource.name, dataSource);
|
|
38
|
+
for (const hook of this.onceHooks) {
|
|
39
|
+
hook(dataSource);
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
use(fn, options) {
|
|
39
43
|
this.middlewares.push([fn, options]);
|
|
@@ -49,6 +53,15 @@ const _DataSourceManager = class _DataSourceManager {
|
|
|
49
53
|
return ds.middleware(this.middlewares)(ctx, next);
|
|
50
54
|
};
|
|
51
55
|
}
|
|
56
|
+
afterAddDataSource(hook) {
|
|
57
|
+
this.addHookAndRun(hook);
|
|
58
|
+
}
|
|
59
|
+
addHookAndRun(hook) {
|
|
60
|
+
this.onceHooks.push(hook);
|
|
61
|
+
for (const dataSource of this.dataSources.values()) {
|
|
62
|
+
hook(dataSource);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
52
65
|
};
|
|
53
66
|
__name(_DataSourceManager, "DataSourceManager");
|
|
54
67
|
let DataSourceManager = _DataSourceManager;
|
package/lib/data-source.js
CHANGED
|
@@ -94,6 +94,7 @@ const _DataSource = class _DataSource extends import_events.default {
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
middleware(middlewares = []) {
|
|
97
|
+
const dataSource = this;
|
|
97
98
|
if (!this["_used"]) {
|
|
98
99
|
for (const [fn, options] of middlewares) {
|
|
99
100
|
this.resourceManager.use(fn, options);
|
|
@@ -105,6 +106,7 @@ const _DataSource = class _DataSource extends import_events.default {
|
|
|
105
106
|
const { resourceName, resourceOf } = ctx.action;
|
|
106
107
|
return this.collectionManager.getRepository(resourceName, resourceOf);
|
|
107
108
|
};
|
|
109
|
+
ctx.dataSource = dataSource;
|
|
108
110
|
return (0, import_koa_compose.default)([this.collectionToResourceMiddleware(), this.resourceManager.middleware()])(ctx, next);
|
|
109
111
|
};
|
|
110
112
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/data-source-manager",
|
|
3
|
-
"version": "0.21.0-alpha.
|
|
3
|
+
"version": "0.21.0-alpha.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/actions": "0.21.0-alpha.
|
|
10
|
-
"@nocobase/cache": "0.21.0-alpha.
|
|
11
|
-
"@nocobase/database": "0.21.0-alpha.
|
|
12
|
-
"@nocobase/resourcer": "0.21.0-alpha.
|
|
13
|
-
"@nocobase/utils": "0.21.0-alpha.
|
|
9
|
+
"@nocobase/actions": "0.21.0-alpha.7",
|
|
10
|
+
"@nocobase/cache": "0.21.0-alpha.7",
|
|
11
|
+
"@nocobase/database": "0.21.0-alpha.7",
|
|
12
|
+
"@nocobase/resourcer": "0.21.0-alpha.7",
|
|
13
|
+
"@nocobase/utils": "0.21.0-alpha.7",
|
|
14
14
|
"@types/jsonwebtoken": "^8.5.8",
|
|
15
15
|
"jsonwebtoken": "^8.5.1"
|
|
16
16
|
},
|
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
20
20
|
"directory": "packages/auth"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "b1be3993f8aa81173d01bc390aa8e4c5adcc0e2d"
|
|
23
23
|
}
|