@nocobase/server 0.5.0-alpha.38 → 0.7.0-alpha.10
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/LICENSE +201 -21
- package/esm/acl/available-action.d.ts +5 -0
- package/esm/acl/available-action.js +36 -0
- package/esm/acl/available-action.js.map +1 -0
- package/esm/acl/index.d.ts +2 -0
- package/esm/acl/index.js +19 -0
- package/esm/acl/index.js.map +1 -0
- package/esm/app-manager.d.ts +19 -0
- package/esm/app-manager.js +69 -0
- package/esm/app-manager.js.map +1 -0
- package/esm/application.d.ts +97 -0
- package/esm/application.js +156 -0
- package/esm/application.js.map +1 -0
- package/esm/commands/console.d.ts +4 -0
- package/esm/commands/console.js +25 -0
- package/esm/commands/console.js.map +1 -0
- package/esm/commands/create-plugin/create-plugin.d.ts +2 -0
- package/esm/commands/create-plugin/create-plugin.js +29 -0
- package/esm/commands/create-plugin/create-plugin.js.map +1 -0
- package/esm/commands/create-plugin/index.d.ts +5 -0
- package/esm/commands/create-plugin/index.js +6 -0
- package/esm/commands/create-plugin/index.js.map +1 -0
- package/esm/commands/create-plugin/resources/templates/package-json.d.ts +11 -0
- package/esm/commands/create-plugin/resources/templates/package-json.js +11 -0
- package/esm/commands/create-plugin/resources/templates/package-json.js.map +1 -0
- package/esm/commands/create-plugin/resources/templates/plugin.d.ts +4 -0
- package/esm/commands/create-plugin/resources/templates/plugin.js +12 -0
- package/esm/commands/create-plugin/resources/templates/plugin.js.map +1 -0
- package/esm/commands/db-sync.d.ts +5 -0
- package/esm/commands/db-sync.js +25 -0
- package/esm/commands/db-sync.js.map +1 -0
- package/esm/commands/index.d.ts +3 -0
- package/esm/commands/index.js +26 -0
- package/esm/commands/index.js.map +1 -0
- package/esm/commands/install.d.ts +5 -0
- package/esm/commands/install.js +23 -0
- package/esm/commands/install.js.map +1 -0
- package/esm/commands/start.d.ts +5 -0
- package/esm/commands/start.js +23 -0
- package/esm/commands/start.js.map +1 -0
- package/esm/helper.d.ts +7 -0
- package/esm/helper.js +59 -0
- package/esm/helper.js.map +1 -0
- package/esm/index.d.ts +7 -0
- package/esm/index.js +9 -0
- package/esm/index.js.map +1 -0
- package/esm/middlewares/data-wrapping.d.ts +3 -0
- package/esm/middlewares/data-wrapping.js +54 -0
- package/esm/middlewares/data-wrapping.js.map +1 -0
- package/esm/middlewares/index.d.ts +2 -0
- package/esm/middlewares/index.js +3 -0
- package/esm/middlewares/index.js.map +1 -0
- package/esm/middlewares/table2resource.d.ts +6 -0
- package/esm/middlewares/table2resource.js +51 -0
- package/esm/middlewares/table2resource.js.map +1 -0
- package/esm/plugin-manager.d.ts +23 -0
- package/esm/plugin-manager.js +57 -0
- package/esm/plugin-manager.js.map +1 -0
- package/esm/plugin.d.ts +32 -0
- package/esm/plugin.js +43 -0
- package/esm/plugin.js.map +1 -0
- package/esm/read-config.d.ts +8 -0
- package/esm/read-config.js +63 -0
- package/esm/read-config.js.map +1 -0
- package/lib/acl/available-action.d.ts +5 -0
- package/lib/acl/available-action.js +39 -0
- package/lib/acl/available-action.js.map +1 -0
- package/lib/acl/index.d.ts +2 -0
- package/lib/acl/index.js +23 -0
- package/lib/acl/index.js.map +1 -0
- package/lib/app-manager.d.ts +19 -0
- package/lib/app-manager.js +76 -0
- package/lib/app-manager.js.map +1 -0
- package/lib/application.d.ts +51 -12
- package/lib/application.js +147 -245
- package/lib/application.js.map +1 -1
- package/lib/commands/console.d.ts +4 -0
- package/lib/commands/console.js +27 -0
- package/lib/commands/console.js.map +1 -0
- package/lib/commands/create-plugin/create-plugin.d.ts +2 -0
- package/lib/commands/create-plugin/create-plugin.js +31 -0
- package/lib/commands/create-plugin/create-plugin.js.map +1 -0
- package/lib/commands/create-plugin/index.d.ts +5 -0
- package/lib/commands/create-plugin/index.js +8 -0
- package/lib/commands/create-plugin/index.js.map +1 -0
- package/lib/commands/create-plugin/resources/templates/package-json.d.ts +11 -0
- package/lib/commands/create-plugin/resources/templates/package-json.js +13 -0
- package/lib/commands/create-plugin/resources/templates/package-json.js.map +1 -0
- package/lib/commands/create-plugin/resources/templates/plugin.d.ts +4 -0
- package/lib/commands/create-plugin/resources/templates/plugin.js +33 -0
- package/lib/commands/create-plugin/resources/templates/plugin.js.map +1 -0
- package/lib/commands/db-sync.d.ts +5 -0
- package/lib/commands/db-sync.js +27 -0
- package/lib/commands/db-sync.js.map +1 -0
- package/lib/commands/index.d.ts +3 -0
- package/lib/commands/index.js +30 -0
- package/lib/commands/index.js.map +1 -0
- package/lib/commands/install.d.ts +5 -0
- package/lib/commands/install.js +25 -0
- package/lib/commands/install.js.map +1 -0
- package/lib/commands/start.d.ts +5 -0
- package/lib/commands/start.js +25 -0
- package/lib/commands/start.js.map +1 -0
- package/lib/helper.d.ts +1 -3
- package/lib/helper.js +50 -185
- package/lib/helper.js.map +1 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.js +28 -63
- package/lib/index.js.map +1 -1
- package/lib/middlewares/data-wrapping.js +49 -97
- package/lib/middlewares/data-wrapping.js.map +1 -1
- package/lib/middlewares/index.js +11 -35
- package/lib/middlewares/index.js.map +1 -1
- package/lib/middlewares/table2resource.d.ts +4 -1
- package/lib/middlewares/table2resource.js +45 -129
- package/lib/middlewares/table2resource.js.map +1 -1
- package/lib/plugin-manager.d.ts +23 -0
- package/lib/plugin-manager.js +61 -0
- package/lib/plugin-manager.js.map +1 -0
- package/lib/plugin.d.ts +17 -16
- package/lib/plugin.js +42 -99
- package/lib/plugin.js.map +1 -1
- package/lib/read-config.d.ts +8 -0
- package/lib/read-config.js +72 -0
- package/lib/read-config.js.map +1 -0
- package/package.json +22 -9
- package/tsconfig.build.json +9 -0
- package/lib/application.d.ts.map +0 -1
- package/lib/helper.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/middlewares/data-wrapping.d.ts.map +0 -1
- package/lib/middlewares/index.d.ts.map +0 -1
- package/lib/middlewares/table2resource.d.ts.map +0 -1
- package/lib/plugin.d.ts.map +0 -1
package/lib/plugin.js
CHANGED
|
@@ -1,107 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
16
|
-
function adopt(value) {
|
|
17
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
18
|
-
resolve(value);
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
9
|
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
-
function fulfilled(value) {
|
|
24
|
-
try {
|
|
25
|
-
step(generator.next(value));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
reject(e);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function rejected(value) {
|
|
32
|
-
try {
|
|
33
|
-
step(generator["throw"](value));
|
|
34
|
-
} catch (e) {
|
|
35
|
-
reject(e);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function step(result) {
|
|
40
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
44
|
-
});
|
|
45
10
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return mod && mod.__esModule ? mod : {
|
|
49
|
-
"default": mod
|
|
50
|
-
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
13
|
};
|
|
52
|
-
|
|
53
|
-
Object.defineProperty(exports, "__esModule", {
|
|
54
|
-
value: true
|
|
55
|
-
});
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
15
|
exports.Plugin = void 0;
|
|
57
|
-
|
|
58
|
-
const database_1 = require("@nocobase/database");
|
|
59
|
-
|
|
60
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
61
|
-
|
|
16
|
+
const find_package_json_1 = __importDefault(require("find-package-json"));
|
|
62
17
|
class Plugin {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const callback = this.callbacks[name].bind(this);
|
|
94
|
-
yield callback();
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
load() {
|
|
99
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
yield this.call('load');
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
18
|
+
constructor(app, options) {
|
|
19
|
+
this.app = app;
|
|
20
|
+
this.db = app.db;
|
|
21
|
+
this.setOptions(options);
|
|
22
|
+
}
|
|
23
|
+
setOptions(options) {
|
|
24
|
+
this.options = options || {};
|
|
25
|
+
}
|
|
26
|
+
beforeLoad() { }
|
|
27
|
+
install(options) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
29
|
+
}
|
|
30
|
+
load() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const collectionPath = this.collectionPath();
|
|
33
|
+
if (collectionPath) {
|
|
34
|
+
yield this.db.import({
|
|
35
|
+
directory: collectionPath,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
collectionPath() {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
getPackageName(dirname) {
|
|
44
|
+
const f = (0, find_package_json_1.default)(dirname);
|
|
45
|
+
const packageObj = f.next().value;
|
|
46
|
+
return packageObj['name'];
|
|
47
|
+
}
|
|
104
48
|
}
|
|
105
|
-
|
|
106
49
|
exports.Plugin = Plugin;
|
|
107
|
-
//# sourceMappingURL=plugin.js.map
|
|
50
|
+
//# sourceMappingURL=plugin.js.map
|
package/lib/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,0EAAuC;AAuBvC,MAAsB,MAAM;IAK1B,YAAY,GAAgB,EAAE,OAAW;QACvC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC;QACjB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,UAAU,CAAC,OAAU;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAK,EAAU,CAAC;IACxC,CAAC;IAID,UAAU,KAAI,CAAC;IAET,OAAO,CAAC,OAAwB;8DAAG,CAAC;KAAA;IAEpC,IAAI;;YACR,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAC7C,IAAI,cAAc,EAAE;gBAClB,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC;oBACnB,SAAS,EAAE,cAAc;iBAC1B,CAAC,CAAC;aACJ;QACH,CAAC;KAAA;IAED,cAAc;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAES,cAAc,CAAC,OAAe;QACtC,MAAM,CAAC,GAAG,IAAA,2BAAM,EAAC,OAAO,CAAC,CAAC;QAC1B,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;QAClC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;CACF;AAvCD,wBAuCC","sourcesContent":["import { Database } from '@nocobase/database';\nimport { Application } from './application';\nimport finder from 'find-package-json';\n\nimport { InstallOptions } from './plugin-manager';\n\nexport interface PluginInterface {\n beforeLoad?: () => void;\n load();\n getName(): string;\n}\n\nexport interface PluginOptions {\n activate?: boolean;\n displayName?: string;\n description?: string;\n version?: string;\n install?: (this: Plugin) => void;\n load?: (this: Plugin) => void;\n plugin?: typeof Plugin;\n [key: string]: any;\n}\n\nexport type PluginType = typeof Plugin;\n\nexport abstract class Plugin<O = any> implements PluginInterface {\n options: O;\n app: Application;\n db: Database;\n\n constructor(app: Application, options?: O) {\n this.app = app;\n this.db = app.db;\n this.setOptions(options);\n }\n\n setOptions(options: O) {\n this.options = options || ({} as any);\n }\n\n public abstract getName(): string;\n\n beforeLoad() {}\n\n async install(options?: InstallOptions) {}\n\n async load() {\n const collectionPath = this.collectionPath();\n if (collectionPath) {\n await this.db.import({\n directory: collectionPath,\n });\n }\n }\n\n collectionPath() {\n return null;\n }\n\n protected getPackageName(dirname: string) {\n const f = finder(dirname);\n const packageObj = f.next().value;\n return packageObj['name'];\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function readConfig(dir: string): Promise<{}>;
|
|
2
|
+
export declare class ConfigurationRepository {
|
|
3
|
+
protected items: Map<string, any>;
|
|
4
|
+
get(key: string, defaultValue?: any): any;
|
|
5
|
+
set(key: string, value: any): Map<string, any>;
|
|
6
|
+
toObject(): {};
|
|
7
|
+
}
|
|
8
|
+
export declare function loadConfiguration(configurationDir: string, repository: ConfigurationRepository): Promise<void>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.loadConfiguration = exports.ConfigurationRepository = exports.readConfig = void 0;
|
|
16
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
function readConfig(dir) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const repository = new ConfigurationRepository();
|
|
22
|
+
yield loadConfiguration(dir, repository);
|
|
23
|
+
return repository.toObject();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.readConfig = readConfig;
|
|
27
|
+
class ConfigurationRepository {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.items = new Map();
|
|
30
|
+
}
|
|
31
|
+
get(key, defaultValue = undefined) {
|
|
32
|
+
if (this.items.has(key)) {
|
|
33
|
+
return this.items.get(key);
|
|
34
|
+
}
|
|
35
|
+
return defaultValue;
|
|
36
|
+
}
|
|
37
|
+
set(key, value) {
|
|
38
|
+
return this.items.set(key, value);
|
|
39
|
+
}
|
|
40
|
+
toObject() {
|
|
41
|
+
const result = {};
|
|
42
|
+
for (const [key, value] of this.items.entries()) {
|
|
43
|
+
lodash_1.default.set(result, key, value);
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.ConfigurationRepository = ConfigurationRepository;
|
|
49
|
+
function loadConfiguration(configurationDir, repository) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const getConfigurationFiles = (dir, prefix = []) => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const files = yield fs_1.default.promises.readdir(dir, { withFileTypes: true });
|
|
53
|
+
for (const file of files) {
|
|
54
|
+
if (file.isDirectory()) {
|
|
55
|
+
yield getConfigurationFiles(path_1.default.join(dir, file.name), [...prefix, file.name]);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (!['ts', 'js'].includes(file.name.split('.').slice(1).join('.'))) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const filePath = path_1.default.join(dir, file.name);
|
|
62
|
+
const keyName = path_1.default.parse(filePath).name;
|
|
63
|
+
const configuration = require(filePath).default;
|
|
64
|
+
repository.set([...prefix, keyName].join('.'), configuration);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
yield getConfigurationFiles(configurationDir);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
exports.loadConfiguration = loadConfiguration;
|
|
72
|
+
//# sourceMappingURL=read-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-config.js","sourceRoot":"","sources":["../src/read-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA4B;AAC5B,4CAAoB;AACpB,gDAAwB;AAExB,SAAsB,UAAU,CAAC,GAAW;;QAC1C,MAAM,UAAU,GAAG,IAAI,uBAAuB,EAAE,CAAC;QACjD,MAAM,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QACzC,OAAO,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CAAA;AAJD,gCAIC;AAED,MAAa,uBAAuB;IAApC;QACY,UAAK,GAAG,IAAI,GAAG,EAAe,CAAC;IAuB3C,CAAC;IArBC,GAAG,CAAC,GAAW,EAAE,YAAY,GAAG,SAAS;QACvC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACvB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAC5B;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAU;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,QAAQ;QACN,MAAM,MAAM,GAAG,EAAE,CAAC;QAElB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE;YAC/C,gBAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;SAChC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAxBD,0DAwBC;AAED,SAAsB,iBAAiB,CAAC,gBAAwB,EAAE,UAAmC;;QACnG,MAAM,qBAAqB,GAAG,CAAO,GAAW,EAAE,MAAM,GAAG,EAAE,EAAE,EAAE;YAC/D,MAAM,KAAK,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;YACtE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE;oBACtB,MAAM,qBAAqB,CAAC,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;iBAChF;qBAAM;oBACL,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;wBACnE,SAAS;qBACV;oBAED,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC3C,MAAM,OAAO,GAAG,cAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;oBAC1C,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC;oBAEhD,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,CAAC;iBAC/D;aACF;QACH,CAAC,CAAA,CAAC;QAEF,MAAM,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;IAChD,CAAC;CAAA;AArBD,8CAqBC","sourcesContent":["import lodash from 'lodash';\nimport fs from 'fs';\nimport path from 'path';\n\nexport async function readConfig(dir: string) {\n const repository = new ConfigurationRepository();\n await loadConfiguration(dir, repository);\n return repository.toObject();\n}\n\nexport class ConfigurationRepository {\n protected items = new Map<string, any>();\n\n get(key: string, defaultValue = undefined) {\n if (this.items.has(key)) {\n return this.items.get(key);\n }\n\n return defaultValue;\n }\n\n set(key: string, value: any) {\n return this.items.set(key, value);\n }\n\n toObject() {\n const result = {};\n\n for (const [key, value] of this.items.entries()) {\n lodash.set(result, key, value);\n }\n\n return result;\n }\n}\n\nexport async function loadConfiguration(configurationDir: string, repository: ConfigurationRepository) {\n const getConfigurationFiles = async (dir: string, prefix = []) => {\n const files = await fs.promises.readdir(dir, { withFileTypes: true });\n for (const file of files) {\n if (file.isDirectory()) {\n await getConfigurationFiles(path.join(dir, file.name), [...prefix, file.name]);\n } else {\n if (!['ts', 'js'].includes(file.name.split('.').slice(1).join('.'))) {\n continue;\n }\n\n const filePath = path.join(dir, file.name);\n const keyName = path.parse(filePath).name;\n const configuration = require(filePath).default;\n\n repository.set([...prefix, keyName].join('.'), configuration);\n }\n }\n };\n\n await getConfigurationFiles(configurationDir);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-alpha.10",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
|
-
"license": "
|
|
7
|
-
"
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"licenses": [
|
|
8
|
+
{
|
|
9
|
+
"type": "Apache-2.0",
|
|
10
|
+
"url": "http://www.apache.org/licenses/LICENSE-2.0"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm",
|
|
15
|
+
"build:cjs": "tsc --project tsconfig.build.json",
|
|
16
|
+
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir esm"
|
|
17
|
+
},
|
|
8
18
|
"dependencies": {
|
|
9
19
|
"@koa/cors": "^3.1.0",
|
|
10
20
|
"@koa/router": "^9.4.0",
|
|
11
|
-
"@nocobase/
|
|
12
|
-
"@nocobase/
|
|
13
|
-
"@nocobase/
|
|
21
|
+
"@nocobase/acl": "0.7.0-alpha.10",
|
|
22
|
+
"@nocobase/actions": "0.7.0-alpha.10",
|
|
23
|
+
"@nocobase/database": "0.7.0-alpha.10",
|
|
24
|
+
"@nocobase/resourcer": "0.7.0-alpha.10",
|
|
14
25
|
"commander": "^8.1.0",
|
|
15
26
|
"dotenv": "^8.2.0",
|
|
27
|
+
"find-package-json": "^1.2.0",
|
|
16
28
|
"i18next": "^21.3.2",
|
|
17
|
-
"koa": "^2.13.
|
|
29
|
+
"koa": "^2.13.4",
|
|
18
30
|
"koa-bodyparser": "^4.3.0",
|
|
19
|
-
"koa-static": "^5.0.0"
|
|
31
|
+
"koa-static": "^5.0.0",
|
|
32
|
+
"lodash": "^4.17.21"
|
|
20
33
|
},
|
|
21
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "8144cfdbea320a9e6e1c228e320f8acea02d98b3"
|
|
22
35
|
}
|
package/lib/application.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["application.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,QAAQ,EAAE,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,SAAS,EAAE,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAS7D,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,IAAI,GAAG,WAAW,CAAC;CAC3B;AAED,UAAU,YAAY;IACpB,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,cAAc;IACtB,EAAE,EAAE,QAAQ,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,iBAAiB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,cAAc;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,qBAAa,WAAW,CACtB,MAAM,GAAG,YAAY,EACrB,QAAQ,GAAG,cAAc,CACzB,SAAQ,GAAG;IACX,SAAgB,EAAE,EAAE,QAAQ,CAAC;IAE7B,SAAgB,SAAS,EAAE,SAAS,CAAC;IAErC,SAAgB,GAAG,EAAE,OAAO,CAAC;IAE7B,SAAgB,IAAI,EAAE,IAAI,CAAC;IAE3B,SAAS,CAAC,OAAO,sBAA6B;gBAElC,OAAO,EAAE,kBAAkB;IAcvC,GAAG,CAAC,SAAS,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAClC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,SAAS,EAAE,QAAQ,GAAG,WAAW,CAAC,EACtE,OAAO,CAAC,EAAE,iBAAiB;IAM7B,UAAU,CAAC,OAAO,EAAE,YAAY;IAIhC,QAAQ,CAAC,OAAO,EAAE,eAAe;IAIjC,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc;IAI/C,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc;IAIlD,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIlC,MAAM,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,aAAa,EAAE,GAAG,CAAC,EAAE,aAAa,GAAG,MAAM;IA2CnE,IAAI;IAUJ,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAmDnE,KAAK,CAAC,IAAI,WAAe;IAKzB,OAAO;CAGd;AAED,eAAe,WAAW,CAAC","file":"application.d.ts","sourcesContent":["import Koa from 'koa';\nimport { Command, CommandOptions } from 'commander';\nimport Database, { DatabaseOptions, TableOptions } from '@nocobase/database';\nimport Resourcer, { ResourceOptions } from '@nocobase/resourcer';\nimport { PluginType, Plugin, PluginOptions } from './plugin';\nimport { registerActions } from '@nocobase/actions';\nimport {\n createCli,\n createI18n,\n createDatabase,\n createResourcer,\n registerMiddlewares,\n} from './helper';\nimport { i18n, InitOptions } from 'i18next';\n\nexport interface ResourcerOptions {\n prefix?: string;\n}\n\nexport interface ApplicationOptions {\n database?: DatabaseOptions;\n resourcer?: ResourcerOptions;\n bodyParser?: any;\n cors?: any;\n dataWrapping?: boolean;\n registerActions?: boolean;\n i18n?: i18n | InitOptions;\n}\n\ninterface DefaultState {\n currentUser?: any;\n [key: string]: any;\n}\n\ninterface DefaultContext {\n db: Database;\n resourcer: Resourcer;\n [key: string]: any;\n}\n\ninterface MiddlewareOptions {\n name?: string;\n resourceName?: string;\n resourceNames?: string[];\n insertBefore?: string;\n insertAfter?: string;\n}\n\ninterface ActionsOptions {\n resourceName?: string;\n resourceNames?: string[];\n}\n\nexport class Application<\n StateT = DefaultState,\n ContextT = DefaultContext\n> extends Koa {\n public readonly db: Database;\n\n public readonly resourcer: Resourcer;\n\n public readonly cli: Command;\n\n public readonly i18n: i18n;\n\n protected plugins = new Map<string, Plugin>();\n\n constructor(options: ApplicationOptions) {\n super();\n\n this.db = createDatabase(options);\n this.resourcer = createResourcer(options);\n this.cli = createCli(this, options);\n this.i18n = createI18n(options);\n\n registerMiddlewares(this, options);\n if (options.registerActions !== false) {\n registerActions(this);\n }\n }\n\n use<NewStateT = {}, NewContextT = {}>(\n middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>,\n options?: MiddlewareOptions,\n ) {\n // @ts-ignore\n return super.use(middleware);\n }\n\n collection(options: TableOptions) {\n return this.db.table(options);\n }\n\n resource(options: ResourceOptions) {\n return this.resourcer.define(options);\n }\n\n actions(handlers: any, options?: ActionsOptions) {\n return this.resourcer.registerActions(handlers);\n }\n\n command(nameAndArgs: string, opts?: CommandOptions) {\n return this.cli.command(nameAndArgs, opts);\n }\n\n findCommand(name: string): Command {\n return (this.cli as any)._findCommand(name);\n }\n\n plugin(options?: PluginType | PluginOptions, ext?: PluginOptions): Plugin {\n if (typeof options === 'string') {\n return this.plugin(require(options).default, ext);\n }\n let instance: Plugin;\n if (typeof options === 'function') {\n try {\n // @ts-ignore\n instance = new options({\n name: options.name,\n ...ext,\n app: this,\n });\n if (!(instance instanceof Plugin)) {\n throw new Error('plugin must be instanceof Plugin');\n }\n } catch (err) {\n // console.log(err);\n instance = new Plugin({\n name: options.name,\n ...ext,\n // @ts-ignore\n load: options,\n app: this,\n });\n }\n } else if (typeof options === 'object') {\n const plugin = options.plugin || Plugin;\n instance = new plugin({\n name: options.plugin ? plugin.name : undefined,\n ...options,\n ...ext,\n app: this,\n });\n }\n const name = instance.getName();\n if (this.plugins.has(name)) {\n throw new Error(`plugin name [${name}] is repeated`);\n }\n this.plugins.set(name, instance);\n return instance;\n }\n\n async load() {\n await this.emitAsync('plugins.beforeLoad');\n for (const [name, plugin] of this.plugins) {\n await this.emitAsync(`plugins.${name}.beforeLoad`);\n await plugin.load();\n await this.emitAsync(`plugins.${name}.afterLoad`);\n }\n await this.emitAsync('plugins.afterLoad');\n }\n\n async emitAsync(event: string | symbol, ...args: any[]): Promise<boolean> {\n // @ts-ignore\n const events = this._events;\n let callbacks = events[event];\n if (!callbacks) {\n return false;\n }\n // helper function to reuse as much code as possible\n const run = (cb) => {\n switch (args.length) {\n // fast cases\n case 0:\n cb = cb.call(this);\n break;\n case 1:\n cb = cb.call(this, args[0]);\n break;\n case 2:\n cb = cb.call(this, args[0], args[1]);\n break;\n case 3:\n cb = cb.call(this, args[0], args[1], args[2]);\n break;\n // slower\n default:\n cb = cb.apply(this, args);\n }\n\n if (cb && (cb instanceof Promise || typeof cb.then === 'function')) {\n return cb;\n }\n\n return Promise.resolve(true);\n };\n\n if (typeof callbacks === 'function') {\n await run(callbacks);\n } else if (typeof callbacks === 'object') {\n callbacks = callbacks.slice().filter(Boolean);\n await callbacks.reduce((prev, next) => {\n return prev.then((res) => {\n return run(next).then((result) =>\n Promise.resolve(res.concat(result)),\n );\n });\n }, Promise.resolve([]));\n }\n\n return true;\n }\n\n async parse(argv = process.argv) {\n await this.load();\n return this.cli.parseAsync(argv);\n }\n\n async destroy() {\n await this.db.close();\n }\n}\n\nexport default Application;\n"]}
|
package/lib/helper.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["helper.ts"],"names":[],"mappings":"AAGA,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,WAAW,EAAE,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAKhE,wBAAgB,cAAc,CAAC,OAAO,EAAE,kBAAkB,YAMzD;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,kBAAkB,aAE1D;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,kBAAkB,0BAQrD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB,WA2DtE;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,kBAAkB,QAoC5B","file":"helper.d.ts","sourcesContent":["import { DefaultContext, DefaultState } from 'koa';\nimport bodyParser from 'koa-bodyparser';\nimport cors from '@koa/cors';\nimport Database from '@nocobase/database';\nimport Resourcer from '@nocobase/resourcer';\nimport { Command } from 'commander';\nimport Application, { ApplicationOptions } from './application';\nimport { dataWrapping } from './middlewares/data-wrapping';\nimport { table2resource } from './middlewares/table2resource';\nimport i18next from 'i18next';\n\nexport function createDatabase(options: ApplicationOptions) {\n if (options.database instanceof Database) {\n return options.database;\n } else {\n return new Database(options.database);\n }\n}\n\nexport function createResourcer(options: ApplicationOptions) {\n return new Resourcer({ ...options.resourcer });\n}\n\nexport function createI18n(options: ApplicationOptions) {\n const instance = i18next.createInstance();\n instance.init({\n lng: 'en-US',\n resources: {},\n ...options.i18n,\n });\n return instance;\n}\n\nexport function createCli(app: Application, options: ApplicationOptions) {\n const cli = new Command();\n\n cli\n .command('db:sync')\n .option('-f, --force')\n .action(async (...args) => {\n console.log('db sync...');\n const cli = args.pop();\n const force = cli.opts()?.force;\n await app.db.sync(\n force\n ? {\n force: true,\n alter: {\n drop: true,\n },\n }\n : {},\n );\n await app.destroy();\n });\n\n cli\n .command('init')\n .option('-f, --force')\n .action(async (opts, ...args) => {\n if (!opts?.force) {\n const tables = await app.db.sequelize.getQueryInterface().showAllTables();\n if (tables.includes('collections')) {\n console.log('NocoBase is already installed. To reinstall, please execute:');\n console.log();\n let command = 'yarn nocobase init --force'\n for (const [key, value] of Object.entries(opts||{})) {\n command += value === true ? ` --${key}` : ` --${key}=${value}`;\n }\n console.log(command);\n console.log();\n return;\n }\n }\n await app.db.sync({\n force: true,\n });\n await app.emitAsync('db.init', opts, ...args);\n await app.destroy();\n });\n\n cli\n .command('start')\n .option('-p, --port [port]')\n .action(async (...args) => {\n const cli = args.pop();\n const opts = cli.opts();\n await app.emitAsync('beforeStart');\n app.listen(opts.port || 3000);\n console.log(`http://localhost:${opts.port || 3000}/`);\n });\n return cli;\n}\n\nexport function registerMiddlewares(\n app: Application,\n options: ApplicationOptions,\n) {\n if (options.bodyParser !== false) {\n app.use(\n bodyParser({\n ...options.bodyParser,\n }),\n );\n }\n\n app.use(\n cors({\n exposeHeaders: ['content-disposition'],\n ...options.cors,\n }),\n );\n\n app.use<DefaultState, DefaultContext>(async (ctx, next) => {\n ctx.db = app.db;\n ctx.resourcer = app.resourcer;\n const i18n = app.i18n.cloneInstance({ initImmediate: false })\n ctx.i18n = i18n;\n ctx.t = i18n.t.bind(i18n);\n const lng = ctx.request.query.locale as string || ctx.acceptsLanguages().shift();\n if (lng !== '*' && lng) {\n i18n.changeLanguage(lng);\n }\n await next();\n });\n\n if (options.dataWrapping !== false) {\n app.use(dataWrapping());\n }\n\n app.use(table2resource());\n app.use(app.resourcer.restApiMiddleware());\n}\n"]}
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,eAAe,CAAC","file":"index.d.ts","sourcesContent":["export * from './application';\nexport * as middlewares from './middlewares';\nexport * from './plugin';\nexport { Application as default } from './application';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/data-wrapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAElD,wBAAgB,YAAY,UACc,OAAO,QAAQ,IAAI,mBA0B5D;AAED,eAAe,YAAY,CAAC","file":"data-wrapping.d.ts","sourcesContent":["import { Context, Next } from '@nocobase/actions';\n\nexport function dataWrapping() {\n return async function dataWrapping(ctx: Context, next: Next) {\n await next();\n if (ctx.withoutDataWrapping) {\n return;\n }\n if (!ctx?.action?.params) {\n return;\n }\n if (ctx.body instanceof Buffer) {\n return;\n }\n if (!ctx.body) {\n ctx.body = {};\n }\n const { rows, ...meta } = ctx.body;\n if (rows) {\n ctx.body = {\n data: rows,\n meta,\n };\n } else {\n ctx.body = {\n data: ctx.body,\n };\n }\n }\n}\n\nexport default dataWrapping;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC","file":"index.d.ts","sourcesContent":["export * from './table2resource';\nexport * from './data-wrapping';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/table2resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;AAG7B,wBAAgB,cAAc,UAErB,gBAAgB,QACf,MAAM,QAAQ,GAAG,CAAC,kBA4D3B;AAED,eAAe,cAAc,CAAC","file":"table2resource.d.ts","sourcesContent":["import {\n getNameByParams,\n parseRequest,\n ResourcerContext,\n ResourceType,\n} from '@nocobase/resourcer';\nimport { BELONGSTO, BELONGSTOMANY, HASMANY, HASONE } from '@nocobase/database';\n\nexport function table2resource() {\n return async function table2resource(\n ctx: ResourcerContext,\n next: () => Promise<any>,\n ) {\n const resourcer = ctx.resourcer;\n const database = ctx.db;\n let params = parseRequest(\n {\n path: ctx.request.path,\n method: ctx.request.method,\n },\n {\n prefix: resourcer.options.prefix,\n accessors: resourcer.options.accessors,\n },\n );\n if (!params) {\n return next();\n }\n const resourceName = getNameByParams(params);\n // 如果资源名称未被定义\n if (resourcer.isDefined(resourceName)) {\n return next();\n }\n const [tableName, fieldName] = resourceName.split('.');\n // 如果经过加载后是已经定义的表\n if (!database.isDefined(tableName)) {\n return next();\n }\n const table = database.getTable(tableName);\n const field = table.getField(fieldName) as\n | BELONGSTO\n | HASMANY\n | BELONGSTOMANY\n | HASONE;\n if (!fieldName || field) {\n let resourceType: ResourceType = 'single';\n let actions = {};\n if (field) {\n if (field instanceof HASONE) {\n resourceType = 'hasOne';\n } else if (field instanceof HASMANY) {\n resourceType = 'hasMany';\n } else if (field instanceof BELONGSTO) {\n resourceType = 'belongsTo';\n } else if (field instanceof BELONGSTOMANY) {\n resourceType = 'belongsToMany';\n }\n if (field.options.actions) {\n actions = field.options.actions || {};\n }\n } else {\n actions = table.getOptions('actions') || {};\n }\n resourcer.define({\n type: resourceType,\n name: resourceName,\n actions,\n });\n }\n return next();\n };\n}\n\nexport default table2resource;\n"]}
|
package/lib/plugin.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,MAAM,CAAC,EAAE,OAAO,MAAM,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,oBAAY,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAE9C,oBAAY,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,MAAM,CAAC;AAE3D,qBAAa,MAAO,YAAW,OAAO;IACpC,OAAO,EAAE,aAAa,CAAM;IAC5B,GAAG,EAAE,WAAW,CAAC;IACjB,SAAS,EAAE,OAAO,CAAM;gBAEZ,OAAO,CAAC,EAAE,aAAa,GAAG;QAAE,GAAG,CAAC,EAAE,WAAW,CAAA;KAAE;IAM3D,OAAO;IAID,QAAQ;IAIR,OAAO;IAIP,IAAI,CAAC,IAAI,EAAE,MAAM;IAQjB,IAAI;CAGX","file":"plugin.d.ts","sourcesContent":["import { uid } from '@nocobase/database';\nimport { Application } from './application';\nimport _ from 'lodash';\n\nexport interface IPlugin {\n install?: (this: Plugin) => void;\n load?: (this: Plugin) => void;\n}\n\nexport interface PluginOptions {\n name?: string;\n activate?: boolean;\n displayName?: string;\n description?: string;\n version?: string;\n install?: (this: Plugin) => void;\n load?: (this: Plugin) => void;\n plugin?: typeof Plugin;\n [key: string]: any;\n}\n\nexport type PluginFn = (this: Plugin) => void;\n\nexport type PluginType = string | PluginFn | typeof Plugin;\n\nexport class Plugin implements IPlugin {\n options: PluginOptions = {};\n app: Application;\n callbacks: IPlugin = {};\n\n constructor(options?: PluginOptions & { app?: Application }) {\n this.app = options?.app;\n this.options = options;\n this.callbacks = _.pick(options, ['load', 'activate']);\n }\n\n getName() {\n return this.options.name || uid();\n }\n\n async activate() {\n this.options.activate = true;\n }\n\n async install() {\n await this.call('install');\n }\n\n async call(name: string) {\n if (!this.callbacks[name]) {\n return;\n }\n const callback = this.callbacks[name].bind(this);\n await callback();\n }\n\n async load() {\n await this.call('load');\n }\n}\n"]}
|