@nocobase/data-source-manager 0.20.0-alpha.9 → 0.21.0-alpha.2
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/data-source-manager.js +6 -11
- package/lib/data-source.d.ts +2 -2
- package/lib/data-source.js +7 -6
- package/lib/default-actions/utils.js +7 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -3
- package/lib/utils.d.ts +2 -0
- package/lib/{resource-manager.js → utils.js} +24 -10
- package/package.json +7 -7
- package/lib/resource-manager.d.ts +0 -3
|
@@ -40,18 +40,13 @@ const _DataSourceManager = class _DataSourceManager {
|
|
|
40
40
|
}
|
|
41
41
|
middleware() {
|
|
42
42
|
return async (ctx, next) => {
|
|
43
|
-
const name = ctx.get("x-data-source");
|
|
44
|
-
if (name) {
|
|
45
|
-
|
|
46
|
-
const ds = this.dataSources.get(name);
|
|
47
|
-
ctx.dataSource = ds;
|
|
48
|
-
return ds.middleware(this.middlewares)(ctx, next);
|
|
49
|
-
} else {
|
|
50
|
-
ctx.throw(`data source ${name} does not exist`);
|
|
51
|
-
}
|
|
43
|
+
const name = ctx.get("x-data-source") || "main";
|
|
44
|
+
if (!this.dataSources.has(name)) {
|
|
45
|
+
ctx.throw(`data source ${name} does not exist`);
|
|
52
46
|
}
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
const ds = this.dataSources.get(name);
|
|
48
|
+
ctx.dataSource = ds;
|
|
49
|
+
return ds.middleware(this.middlewares)(ctx, next);
|
|
55
50
|
};
|
|
56
51
|
}
|
|
57
52
|
};
|
package/lib/data-source.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ACL } from '@nocobase/acl';
|
|
3
|
-
import { ResourceManager } from '
|
|
4
|
-
import { ICollectionManager } from './types';
|
|
3
|
+
import { ResourceManager } from '@nocobase/resourcer';
|
|
5
4
|
import EventEmitter from 'events';
|
|
5
|
+
import { ICollectionManager } from './types';
|
|
6
6
|
export type DataSourceOptions = any;
|
|
7
7
|
export declare abstract class DataSource extends EventEmitter {
|
|
8
8
|
protected options: DataSourceOptions;
|
package/lib/data-source.js
CHANGED
|
@@ -33,10 +33,9 @@ __export(data_source_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(data_source_exports);
|
|
34
34
|
var import_acl = require("@nocobase/acl");
|
|
35
35
|
var import_resourcer = require("@nocobase/resourcer");
|
|
36
|
+
var import_events = __toESM(require("events"));
|
|
36
37
|
var import_koa_compose = __toESM(require("koa-compose"));
|
|
37
|
-
var import_resource_manager = require("./resource-manager");
|
|
38
38
|
var import_load_default_actions = require("./load-default-actions");
|
|
39
|
-
var import_events = __toESM(require("events"));
|
|
40
39
|
const _DataSource = class _DataSource extends import_events.default {
|
|
41
40
|
constructor(options) {
|
|
42
41
|
super();
|
|
@@ -55,7 +54,7 @@ const _DataSource = class _DataSource extends import_events.default {
|
|
|
55
54
|
init(options = {}) {
|
|
56
55
|
this.acl = this.createACL();
|
|
57
56
|
this.resourceManager = this.createResourceManager({
|
|
58
|
-
prefix:
|
|
57
|
+
prefix: process.env.API_BASE_PATH,
|
|
59
58
|
...options.resourceManager
|
|
60
59
|
});
|
|
61
60
|
this.collectionManager = this.createCollectionManager(options);
|
|
@@ -83,7 +82,9 @@ const _DataSource = class _DataSource extends import_events.default {
|
|
|
83
82
|
if (this.resourceManager.isDefined(resourceName)) {
|
|
84
83
|
return next();
|
|
85
84
|
}
|
|
86
|
-
|
|
85
|
+
const splitResult = resourceName.split(".");
|
|
86
|
+
const collectionName = splitResult[0];
|
|
87
|
+
if (!this.collectionManager.hasCollection(collectionName)) {
|
|
87
88
|
return next();
|
|
88
89
|
}
|
|
89
90
|
this.resourceManager.define({
|
|
@@ -104,14 +105,14 @@ const _DataSource = class _DataSource extends import_events.default {
|
|
|
104
105
|
const { resourceName, resourceOf } = ctx.action;
|
|
105
106
|
return this.collectionManager.getRepository(resourceName, resourceOf);
|
|
106
107
|
};
|
|
107
|
-
return (0, import_koa_compose.default)([this.collectionToResourceMiddleware(), this.resourceManager.
|
|
108
|
+
return (0, import_koa_compose.default)([this.collectionToResourceMiddleware(), this.resourceManager.middleware()])(ctx, next);
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
createACL() {
|
|
111
112
|
return new import_acl.ACL();
|
|
112
113
|
}
|
|
113
114
|
createResourceManager(options) {
|
|
114
|
-
return new
|
|
115
|
+
return new import_resourcer.ResourceManager(options);
|
|
115
116
|
}
|
|
116
117
|
async load(options = {}) {
|
|
117
118
|
}
|
|
@@ -30,10 +30,14 @@ function pageArgsToLimitArgs(page, pageSize) {
|
|
|
30
30
|
}
|
|
31
31
|
__name(pageArgsToLimitArgs, "pageArgsToLimitArgs");
|
|
32
32
|
function getRepositoryFromParams(ctx) {
|
|
33
|
-
const { resourceName,
|
|
33
|
+
const { resourceName, sourceId, actionName } = ctx.action;
|
|
34
34
|
const dataSource = ctx.dataSource;
|
|
35
|
-
if (
|
|
36
|
-
|
|
35
|
+
if (sourceId === "_" && ["get", "list"].includes(actionName)) {
|
|
36
|
+
const collection = dataSource.collectionManager.getCollection(resourceName);
|
|
37
|
+
return dataSource.collectionManager.getRepository(collection.name);
|
|
38
|
+
}
|
|
39
|
+
if (sourceId) {
|
|
40
|
+
return dataSource.collectionManager.getRepository(resourceName, sourceId);
|
|
37
41
|
}
|
|
38
42
|
return dataSource.collectionManager.getRepository(resourceName);
|
|
39
43
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export * from './collection-manager';
|
|
2
2
|
export * from './data-source';
|
|
3
3
|
export * from './data-source-manager';
|
|
4
|
-
export * from './resource-manager';
|
|
5
4
|
export * from './sequelize-collection-manager';
|
|
6
5
|
export * from './sequelize-data-source';
|
|
7
6
|
export * from './load-default-actions';
|
|
8
7
|
export * from './types';
|
|
9
8
|
export * from './data-source-with-database';
|
|
9
|
+
export * from './utils';
|
package/lib/index.js
CHANGED
|
@@ -17,21 +17,21 @@ module.exports = __toCommonJS(src_exports);
|
|
|
17
17
|
__reExport(src_exports, require("./collection-manager"), module.exports);
|
|
18
18
|
__reExport(src_exports, require("./data-source"), module.exports);
|
|
19
19
|
__reExport(src_exports, require("./data-source-manager"), module.exports);
|
|
20
|
-
__reExport(src_exports, require("./resource-manager"), module.exports);
|
|
21
20
|
__reExport(src_exports, require("./sequelize-collection-manager"), module.exports);
|
|
22
21
|
__reExport(src_exports, require("./sequelize-data-source"), module.exports);
|
|
23
22
|
__reExport(src_exports, require("./load-default-actions"), module.exports);
|
|
24
23
|
__reExport(src_exports, require("./types"), module.exports);
|
|
25
24
|
__reExport(src_exports, require("./data-source-with-database"), module.exports);
|
|
25
|
+
__reExport(src_exports, require("./utils"), module.exports);
|
|
26
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
27
|
0 && (module.exports = {
|
|
28
28
|
...require("./collection-manager"),
|
|
29
29
|
...require("./data-source"),
|
|
30
30
|
...require("./data-source-manager"),
|
|
31
|
-
...require("./resource-manager"),
|
|
32
31
|
...require("./sequelize-collection-manager"),
|
|
33
32
|
...require("./sequelize-data-source"),
|
|
34
33
|
...require("./load-default-actions"),
|
|
35
34
|
...require("./types"),
|
|
36
|
-
...require("./data-source-with-database")
|
|
35
|
+
...require("./data-source-with-database"),
|
|
36
|
+
...require("./utils")
|
|
37
37
|
});
|
package/lib/utils.d.ts
ADDED
|
@@ -16,17 +16,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
joinCollectionName: () => joinCollectionName,
|
|
22
|
+
parseCollectionName: () => parseCollectionName
|
|
22
23
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
module.exports = __toCommonJS(utils_exports);
|
|
25
|
+
function parseCollectionName(collection) {
|
|
26
|
+
if (!collection) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const dataSourceCollection = collection.split(":");
|
|
30
|
+
const collectionName = dataSourceCollection.pop();
|
|
31
|
+
const dataSourceName = dataSourceCollection[0] ?? "main";
|
|
32
|
+
return [dataSourceName, collectionName];
|
|
33
|
+
}
|
|
34
|
+
__name(parseCollectionName, "parseCollectionName");
|
|
35
|
+
function joinCollectionName(dataSourceName, collectionName) {
|
|
36
|
+
if (!dataSourceName || dataSourceName === "main") {
|
|
37
|
+
return collectionName;
|
|
38
|
+
}
|
|
39
|
+
return `${dataSourceName}:${collectionName}`;
|
|
40
|
+
}
|
|
41
|
+
__name(joinCollectionName, "joinCollectionName");
|
|
29
42
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
43
|
0 && (module.exports = {
|
|
31
|
-
|
|
44
|
+
joinCollectionName,
|
|
45
|
+
parseCollectionName
|
|
32
46
|
});
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/data-source-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0-alpha.2",
|
|
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.
|
|
10
|
-
"@nocobase/cache": "0.
|
|
11
|
-
"@nocobase/database": "0.
|
|
12
|
-
"@nocobase/resourcer": "0.
|
|
13
|
-
"@nocobase/utils": "0.
|
|
9
|
+
"@nocobase/actions": "0.21.0-alpha.2",
|
|
10
|
+
"@nocobase/cache": "0.21.0-alpha.2",
|
|
11
|
+
"@nocobase/database": "0.21.0-alpha.2",
|
|
12
|
+
"@nocobase/resourcer": "0.21.0-alpha.2",
|
|
13
|
+
"@nocobase/utils": "0.21.0-alpha.2",
|
|
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": "90628f2e2da846208fb2d7966ddb4e467d187ffb"
|
|
23
23
|
}
|