@nocobase/data-source-manager 1.3.44-beta → 1.4.0-alpha.0
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.
- package/lib/collection.d.ts +1 -1
- package/lib/data-source-manager.d.ts +1 -1
- package/lib/data-source-manager.js +7 -5
- package/lib/data-source.d.ts +9 -4
- package/lib/data-source.js +20 -14
- package/lib/types.d.ts +1 -1
- package/package.json +7 -7
package/lib/collection.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare class Collection implements ICollection {
|
|
|
15
15
|
fields: Map<string, IField>;
|
|
16
16
|
constructor(options: CollectionOptions, collectionManager: ICollectionManager);
|
|
17
17
|
get name(): string;
|
|
18
|
-
get filterTargetKey(): string;
|
|
18
|
+
get filterTargetKey(): string | string[];
|
|
19
19
|
updateOptions(options: CollectionOptions, mergeOptions?: any): this;
|
|
20
20
|
setFields(fields: any[]): void;
|
|
21
21
|
setField(name: string, options: any): CollectionField;
|
|
@@ -29,7 +29,7 @@ export declare class DataSourceManager {
|
|
|
29
29
|
get(dataSourceKey: string): DataSource;
|
|
30
30
|
add(dataSource: DataSource, options?: any): Promise<void>;
|
|
31
31
|
use(fn: any, options?: ToposortOptions): void;
|
|
32
|
-
middleware(): (ctx: any, next: any) => Promise<
|
|
32
|
+
middleware(): (ctx: any, next: any) => Promise<void>;
|
|
33
33
|
registerDataSourceType(type: string, DataSourceClass: typeof DataSource): void;
|
|
34
34
|
getDataSourceType(type: string): typeof DataSource | undefined;
|
|
35
35
|
buildDataSourceByType(type: string, options?: any): DataSource;
|
|
@@ -85,15 +85,17 @@ const _DataSourceManager = class _DataSourceManager {
|
|
|
85
85
|
this.middlewares.push([fn, options]);
|
|
86
86
|
}
|
|
87
87
|
middleware() {
|
|
88
|
-
|
|
88
|
+
const self = this;
|
|
89
|
+
return /* @__PURE__ */ __name(async function dataSourceManager(ctx, next) {
|
|
89
90
|
const name = ctx.get("x-data-source") || "main";
|
|
90
|
-
if (!
|
|
91
|
+
if (!self.dataSources.has(name)) {
|
|
91
92
|
ctx.throw(`data source ${name} does not exist`);
|
|
92
93
|
}
|
|
93
|
-
const ds =
|
|
94
|
+
const ds = self.dataSources.get(name);
|
|
94
95
|
ctx.dataSource = ds;
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
const composedFn = ds.middleware(self.middlewares);
|
|
97
|
+
return composedFn(ctx, next);
|
|
98
|
+
}, "dataSourceManager");
|
|
97
99
|
}
|
|
98
100
|
registerDataSourceType(type, DataSourceClass) {
|
|
99
101
|
this.factory.register(type, DataSourceClass);
|
package/lib/data-source.d.ts
CHANGED
|
@@ -13,24 +13,29 @@ import EventEmitter from 'events';
|
|
|
13
13
|
import { ICollectionManager } from './types';
|
|
14
14
|
import { Logger } from '@nocobase/logger';
|
|
15
15
|
export type DataSourceOptions = any;
|
|
16
|
+
export type LoadingProgress = {
|
|
17
|
+
total: number;
|
|
18
|
+
loaded: number;
|
|
19
|
+
};
|
|
16
20
|
export declare abstract class DataSource extends EventEmitter {
|
|
17
21
|
protected options: DataSourceOptions;
|
|
18
22
|
collectionManager: ICollectionManager;
|
|
19
23
|
resourceManager: ResourceManager;
|
|
20
24
|
acl: ACL;
|
|
21
25
|
logger: Logger;
|
|
22
|
-
_sqlLogger: Logger;
|
|
23
26
|
constructor(options: DataSourceOptions);
|
|
24
|
-
|
|
25
|
-
setSqlLogger(logger: Logger): void;
|
|
27
|
+
_sqlLogger: Logger;
|
|
26
28
|
get sqlLogger(): Logger;
|
|
27
29
|
get name(): any;
|
|
28
30
|
static testConnection(options?: any): Promise<boolean>;
|
|
31
|
+
setLogger(logger: Logger): void;
|
|
32
|
+
setSqlLogger(logger: Logger): void;
|
|
29
33
|
init(options?: DataSourceOptions): void;
|
|
30
|
-
middleware(middlewares?: any): (ctx: any, next: any) => Promise<
|
|
34
|
+
middleware(middlewares?: any): (ctx: any, next: any) => Promise<void>;
|
|
31
35
|
createACL(): ACL;
|
|
32
36
|
createResourceManager(options: any): ResourceManager;
|
|
33
37
|
publicOptions(): any;
|
|
38
|
+
emitLoadingProgress(progress: LoadingProgress): void;
|
|
34
39
|
load(options?: any): Promise<void>;
|
|
35
40
|
close(): Promise<void>;
|
|
36
41
|
abstract createCollectionManager(options?: any): ICollectionManager;
|
package/lib/data-source.js
CHANGED
|
@@ -45,6 +45,7 @@ var import_resourcer = require("@nocobase/resourcer");
|
|
|
45
45
|
var import_events = __toESM(require("events"));
|
|
46
46
|
var import_koa_compose = __toESM(require("koa-compose"));
|
|
47
47
|
var import_load_default_actions = require("./load-default-actions");
|
|
48
|
+
var import_utils = require("@nocobase/utils");
|
|
48
49
|
const _DataSource = class _DataSource extends import_events.default {
|
|
49
50
|
constructor(options) {
|
|
50
51
|
super();
|
|
@@ -56,12 +57,6 @@ const _DataSource = class _DataSource extends import_events.default {
|
|
|
56
57
|
acl;
|
|
57
58
|
logger;
|
|
58
59
|
_sqlLogger;
|
|
59
|
-
setLogger(logger) {
|
|
60
|
-
this.logger = logger;
|
|
61
|
-
}
|
|
62
|
-
setSqlLogger(logger) {
|
|
63
|
-
this._sqlLogger = logger;
|
|
64
|
-
}
|
|
65
60
|
get sqlLogger() {
|
|
66
61
|
return this._sqlLogger || this.logger;
|
|
67
62
|
}
|
|
@@ -71,6 +66,12 @@ const _DataSource = class _DataSource extends import_events.default {
|
|
|
71
66
|
static testConnection(options) {
|
|
72
67
|
return Promise.resolve(true);
|
|
73
68
|
}
|
|
69
|
+
setLogger(logger) {
|
|
70
|
+
this.logger = logger;
|
|
71
|
+
}
|
|
72
|
+
setSqlLogger(logger) {
|
|
73
|
+
this._sqlLogger = logger;
|
|
74
|
+
}
|
|
74
75
|
init(options = {}) {
|
|
75
76
|
this.acl = this.createACL();
|
|
76
77
|
this.resourceManager = this.createResourceManager({
|
|
@@ -97,7 +98,8 @@ const _DataSource = class _DataSource extends import_events.default {
|
|
|
97
98
|
const { resourceName, resourceOf } = ctx.action;
|
|
98
99
|
return this.collectionManager.getRepository(resourceName, resourceOf);
|
|
99
100
|
};
|
|
100
|
-
|
|
101
|
+
const middlewares2 = [this.collectionToResourceMiddleware(), this.resourceManager.middleware()];
|
|
102
|
+
return (0, import_koa_compose.default)(middlewares2.map((fn) => (0, import_utils.wrapMiddlewareWithLogging)(fn)))(ctx, next);
|
|
101
103
|
};
|
|
102
104
|
}
|
|
103
105
|
createACL() {
|
|
@@ -109,39 +111,43 @@ const _DataSource = class _DataSource extends import_events.default {
|
|
|
109
111
|
publicOptions() {
|
|
110
112
|
return null;
|
|
111
113
|
}
|
|
114
|
+
emitLoadingProgress(progress) {
|
|
115
|
+
this.emit("loadingProgress", progress);
|
|
116
|
+
}
|
|
112
117
|
async load(options = {}) {
|
|
113
118
|
}
|
|
114
119
|
async close() {
|
|
115
120
|
}
|
|
116
121
|
collectionToResourceMiddleware() {
|
|
117
|
-
|
|
122
|
+
const self = this;
|
|
123
|
+
return /* @__PURE__ */ __name(async function collectionToResource(ctx, next) {
|
|
118
124
|
const params = (0, import_resourcer.parseRequest)(
|
|
119
125
|
{
|
|
120
126
|
path: ctx.request.path,
|
|
121
127
|
method: ctx.request.method
|
|
122
128
|
},
|
|
123
129
|
{
|
|
124
|
-
prefix:
|
|
125
|
-
accessors:
|
|
130
|
+
prefix: self.resourceManager.options.prefix,
|
|
131
|
+
accessors: self.resourceManager.options.accessors
|
|
126
132
|
}
|
|
127
133
|
);
|
|
128
134
|
if (!params) {
|
|
129
135
|
return next();
|
|
130
136
|
}
|
|
131
137
|
const resourceName = (0, import_resourcer.getNameByParams)(params);
|
|
132
|
-
if (
|
|
138
|
+
if (self.resourceManager.isDefined(resourceName)) {
|
|
133
139
|
return next();
|
|
134
140
|
}
|
|
135
141
|
const splitResult = resourceName.split(".");
|
|
136
142
|
const collectionName = splitResult[0];
|
|
137
|
-
if (!
|
|
143
|
+
if (!self.collectionManager.hasCollection(collectionName)) {
|
|
138
144
|
return next();
|
|
139
145
|
}
|
|
140
|
-
|
|
146
|
+
self.resourceManager.define({
|
|
141
147
|
name: resourceName
|
|
142
148
|
});
|
|
143
149
|
return next();
|
|
144
|
-
};
|
|
150
|
+
}, "collectionToResource");
|
|
145
151
|
}
|
|
146
152
|
};
|
|
147
153
|
__name(_DataSource, "DataSource");
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/data-source-manager",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/actions": "1.
|
|
10
|
-
"@nocobase/cache": "1.
|
|
11
|
-
"@nocobase/database": "1.
|
|
12
|
-
"@nocobase/resourcer": "1.
|
|
13
|
-
"@nocobase/utils": "1.
|
|
9
|
+
"@nocobase/actions": "1.4.0-alpha.0",
|
|
10
|
+
"@nocobase/cache": "1.4.0-alpha.0",
|
|
11
|
+
"@nocobase/database": "1.4.0-alpha.0",
|
|
12
|
+
"@nocobase/resourcer": "1.4.0-alpha.0",
|
|
13
|
+
"@nocobase/utils": "1.4.0-alpha.0",
|
|
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": "8ffa7b54bbaf720c0c9857da4b19a99110dffc4b"
|
|
23
23
|
}
|