@nocobase/server 0.5.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 +21 -0
- package/lib/application.d.ts +53 -0
- package/lib/application.d.ts.map +1 -0
- package/lib/application.js +321 -0
- package/lib/application.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +70 -0
- package/lib/index.js.map +1 -0
- package/lib/middlewares/data-wrapping.d.ts +3 -0
- package/lib/middlewares/data-wrapping.d.ts.map +1 -0
- package/lib/middlewares/data-wrapping.js +106 -0
- package/lib/middlewares/data-wrapping.js.map +1 -0
- package/lib/middlewares/index.d.ts +2 -0
- package/lib/middlewares/index.d.ts.map +1 -0
- package/lib/middlewares/index.js +39 -0
- package/lib/middlewares/index.js.map +1 -0
- package/lib/middlewares/table2resource.d.ts +3 -0
- package/lib/middlewares/table2resource.d.ts.map +1 -0
- package/lib/middlewares/table2resource.js +139 -0
- package/lib/middlewares/table2resource.js.map +1 -0
- package/lib/plugin.d.ts +31 -0
- package/lib/plugin.d.ts.map +1 -0
- package/lib/plugin.js +107 -0
- package/lib/plugin.js.map +1 -0
- package/package.json +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 NocoBase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import Koa from 'koa';
|
|
2
|
+
import { Command, CommandOptions } from 'commander';
|
|
3
|
+
import Database, { DatabaseOptions, TableOptions } from '@nocobase/database';
|
|
4
|
+
import Resourcer, { ResourceOptions } from '@nocobase/resourcer';
|
|
5
|
+
import { PluginType, Plugin, PluginOptions } from './plugin';
|
|
6
|
+
export interface ResourcerOptions {
|
|
7
|
+
prefix?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ApplicationOptions {
|
|
10
|
+
database?: DatabaseOptions;
|
|
11
|
+
resourcer?: ResourcerOptions;
|
|
12
|
+
bodyParser?: any;
|
|
13
|
+
cors?: any;
|
|
14
|
+
dataWrapping?: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface DefaultState {
|
|
17
|
+
currentUser?: any;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
interface DefaultContext {
|
|
21
|
+
db: Database;
|
|
22
|
+
resourcer: Resourcer;
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}
|
|
25
|
+
interface MiddlewareOptions {
|
|
26
|
+
name?: string;
|
|
27
|
+
resourceName?: string;
|
|
28
|
+
resourceNames?: string[];
|
|
29
|
+
insertBefore?: string;
|
|
30
|
+
insertAfter?: string;
|
|
31
|
+
}
|
|
32
|
+
interface ActionsOptions {
|
|
33
|
+
resourceName?: string;
|
|
34
|
+
resourceNames?: string[];
|
|
35
|
+
}
|
|
36
|
+
export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa {
|
|
37
|
+
readonly db: Database;
|
|
38
|
+
readonly resourcer: Resourcer;
|
|
39
|
+
readonly cli: Command;
|
|
40
|
+
protected plugins: Map<string, Plugin>;
|
|
41
|
+
constructor(options: ApplicationOptions);
|
|
42
|
+
use<NewStateT = {}, NewContextT = {}>(middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>, options?: MiddlewareOptions): Koa<Koa.DefaultState & StateT & NewStateT, Koa.DefaultContext & ContextT & NewContextT>;
|
|
43
|
+
collection(options: TableOptions): import("@nocobase/database").Table;
|
|
44
|
+
resource(options: ResourceOptions): import("@nocobase/resourcer").Resource;
|
|
45
|
+
actions(handlers: any, options?: ActionsOptions): void;
|
|
46
|
+
command(nameAndArgs: string, opts?: CommandOptions): Command;
|
|
47
|
+
plugin(options?: PluginType | PluginOptions, ext?: PluginOptions): Plugin;
|
|
48
|
+
load(): Promise<void>;
|
|
49
|
+
emitAsync(event: string | symbol, ...args: any[]): Promise<boolean>;
|
|
50
|
+
parse(argv?: string[]): Promise<Command>;
|
|
51
|
+
destroy(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
export default Application;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["application.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAGtB,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;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CA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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,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 cors from '@koa/cors';\nimport bodyParser from 'koa-bodyparser';\nimport { Command, CommandOptions } from 'commander';\nimport Database, { DatabaseOptions, TableOptions } from '@nocobase/database';\nimport Resourcer, { ResourceOptions } from '@nocobase/resourcer';\nimport { dataWrapping, table2resource } from './middlewares';\nimport { PluginType, Plugin, PluginOptions } from './plugin';\nimport { registerActions } from '@nocobase/actions';\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}\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 protected plugins = new Map<string, Plugin>();\n\n constructor(options: ApplicationOptions) {\n super();\n\n if (options.database instanceof Database) {\n this.db = options.database;\n } else {\n this.db = new Database(options.database);\n }\n\n this.resourcer = new Resourcer({ ...options.resourcer });\n this.cli = new Command();\n\n if (options.bodyParser !== false) {\n this.use(\n bodyParser({\n ...options.bodyParser,\n }),\n );\n }\n\n this.use(\n cors({\n exposeHeaders: ['content-disposition'],\n ...options.cors,\n }),\n );\n\n this.use<DefaultState, DefaultContext>(async (ctx, next) => {\n ctx.db = this.db;\n ctx.resourcer = this.resourcer;\n await next();\n });\n\n if (options.dataWrapping !== false) {\n this.use(dataWrapping());\n }\n\n this.use(table2resource());\n this.use(this.resourcer.restApiMiddleware());\n\n registerActions(this);\n\n this.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 this.db.sync(\n force\n ? {\n force: true,\n alter: {\n drop: true,\n },\n }\n : {},\n );\n await this.destroy();\n });\n\n this.cli\n .command('init')\n // .option('-f, --force')\n .action(async (...args) => {\n const cli = args.pop();\n await this.db.sync({\n force: true,\n alter: {\n drop: true,\n },\n });\n await this.emitAsync('db.init');\n await this.destroy();\n });\n\n this.cli\n .command('start')\n .option('-p, --port [port]')\n .action(async (...args) => {\n const cli = args.pop();\n console.log(args);\n const opts = cli.opts();\n await this.emitAsync('beforeStart');\n this.listen(opts.port || 3000);\n console.log(`http://localhost:${opts.port || 3000}/`);\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 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"]}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _react() {
|
|
4
|
+
const data = _interopRequireDefault(require("react"));
|
|
5
|
+
|
|
6
|
+
_react = function _react() {
|
|
7
|
+
return data;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
+
|
|
17
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
+
|
|
19
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
20
|
+
|
|
21
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
|
+
|
|
23
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
24
|
+
|
|
25
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
26
|
+
|
|
27
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
28
|
+
|
|
29
|
+
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) {
|
|
31
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
32
|
+
resolve(value);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
+
function fulfilled(value) {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.next(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function rejected(value) {
|
|
46
|
+
try {
|
|
47
|
+
step(generator["throw"](value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function step(result) {
|
|
54
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
62
|
+
return mod && mod.__esModule ? mod : {
|
|
63
|
+
"default": mod
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
Object.defineProperty(exports, "__esModule", {
|
|
68
|
+
value: true
|
|
69
|
+
});
|
|
70
|
+
exports.Application = void 0;
|
|
71
|
+
|
|
72
|
+
const koa_1 = __importDefault(require("koa"));
|
|
73
|
+
|
|
74
|
+
const cors_1 = __importDefault(require("@koa/cors"));
|
|
75
|
+
|
|
76
|
+
const koa_bodyparser_1 = __importDefault(require("koa-bodyparser"));
|
|
77
|
+
|
|
78
|
+
const commander_1 = require("commander");
|
|
79
|
+
|
|
80
|
+
const database_1 = __importDefault(require("@nocobase/database"));
|
|
81
|
+
|
|
82
|
+
const resourcer_1 = __importDefault(require("@nocobase/resourcer"));
|
|
83
|
+
|
|
84
|
+
const middlewares_1 = require("./middlewares");
|
|
85
|
+
|
|
86
|
+
const plugin_1 = require("./plugin");
|
|
87
|
+
|
|
88
|
+
const actions_1 = require("@nocobase/actions");
|
|
89
|
+
|
|
90
|
+
class Application extends koa_1.default {
|
|
91
|
+
constructor(options) {
|
|
92
|
+
super();
|
|
93
|
+
this.plugins = new Map();
|
|
94
|
+
|
|
95
|
+
if (options.database instanceof database_1.default) {
|
|
96
|
+
this.db = options.database;
|
|
97
|
+
} else {
|
|
98
|
+
this.db = new database_1.default(options.database);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.resourcer = new resourcer_1.default(Object.assign({}, options.resourcer));
|
|
102
|
+
this.cli = new commander_1.Command();
|
|
103
|
+
|
|
104
|
+
if (options.bodyParser !== false) {
|
|
105
|
+
this.use(koa_bodyparser_1.default(Object.assign({}, options.bodyParser)));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.use(cors_1.default(Object.assign({
|
|
109
|
+
exposeHeaders: ['content-disposition']
|
|
110
|
+
}, options.cors)));
|
|
111
|
+
this.use((ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
ctx.db = this.db;
|
|
113
|
+
ctx.resourcer = this.resourcer;
|
|
114
|
+
yield next();
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
if (options.dataWrapping !== false) {
|
|
118
|
+
this.use(middlewares_1.dataWrapping());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
this.use(middlewares_1.table2resource());
|
|
122
|
+
this.use(this.resourcer.restApiMiddleware());
|
|
123
|
+
actions_1.registerActions(this);
|
|
124
|
+
this.cli.command('db:sync').option('-f, --force').action((...args) => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
var _a;
|
|
126
|
+
|
|
127
|
+
console.log('db sync...');
|
|
128
|
+
const cli = args.pop();
|
|
129
|
+
const force = (_a = cli.opts()) === null || _a === void 0 ? void 0 : _a.force;
|
|
130
|
+
yield this.db.sync(force ? {
|
|
131
|
+
force: true,
|
|
132
|
+
alter: {
|
|
133
|
+
drop: true
|
|
134
|
+
}
|
|
135
|
+
} : {});
|
|
136
|
+
yield this.destroy();
|
|
137
|
+
}));
|
|
138
|
+
this.cli.command('init').action((...args) => __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const cli = args.pop();
|
|
140
|
+
yield this.db.sync({
|
|
141
|
+
force: true,
|
|
142
|
+
alter: {
|
|
143
|
+
drop: true
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
yield this.emitAsync('db.init');
|
|
147
|
+
yield this.destroy();
|
|
148
|
+
}));
|
|
149
|
+
this.cli.command('start').option('-p, --port [port]').action((...args) => __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const cli = args.pop();
|
|
151
|
+
console.log(args);
|
|
152
|
+
const opts = cli.opts();
|
|
153
|
+
yield this.emitAsync('beforeStart');
|
|
154
|
+
this.listen(opts.port || 3000);
|
|
155
|
+
console.log(`http://localhost:${opts.port || 3000}/`);
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
use(middleware, options) {
|
|
160
|
+
return super.use(middleware);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
collection(options) {
|
|
164
|
+
return this.db.table(options);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
resource(options) {
|
|
168
|
+
return this.resourcer.define(options);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
actions(handlers, options) {
|
|
172
|
+
return this.resourcer.registerActions(handlers);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
command(nameAndArgs, opts) {
|
|
176
|
+
return this.cli.command(nameAndArgs, opts);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
plugin(options, ext) {
|
|
180
|
+
if (typeof options === 'string') {
|
|
181
|
+
return this.plugin(require(options).default, ext);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let instance;
|
|
185
|
+
|
|
186
|
+
if (typeof options === 'function') {
|
|
187
|
+
try {
|
|
188
|
+
instance = new options(Object.assign(Object.assign({
|
|
189
|
+
name: options.name
|
|
190
|
+
}, ext), {
|
|
191
|
+
app: this
|
|
192
|
+
}));
|
|
193
|
+
|
|
194
|
+
if (!(instance instanceof plugin_1.Plugin)) {
|
|
195
|
+
throw new Error('plugin must be instanceof Plugin');
|
|
196
|
+
}
|
|
197
|
+
} catch (err) {
|
|
198
|
+
instance = new plugin_1.Plugin(Object.assign(Object.assign({
|
|
199
|
+
name: options.name
|
|
200
|
+
}, ext), {
|
|
201
|
+
load: options,
|
|
202
|
+
app: this
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
} else if (typeof options === 'object') {
|
|
206
|
+
const plugin = options.plugin || plugin_1.Plugin;
|
|
207
|
+
instance = new plugin(Object.assign(Object.assign(Object.assign({
|
|
208
|
+
name: options.plugin ? plugin.name : undefined
|
|
209
|
+
}, options), ext), {
|
|
210
|
+
app: this
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const name = instance.getName();
|
|
215
|
+
|
|
216
|
+
if (this.plugins.has(name)) {
|
|
217
|
+
throw new Error(`plugin name [${name}] is repeated`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
this.plugins.set(name, instance);
|
|
221
|
+
return instance;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
load() {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
yield this.emitAsync('plugins.beforeLoad');
|
|
227
|
+
|
|
228
|
+
var _iterator = _createForOfIteratorHelper(this.plugins),
|
|
229
|
+
_step;
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
233
|
+
const _step$value = _slicedToArray(_step.value, 2),
|
|
234
|
+
name = _step$value[0],
|
|
235
|
+
plugin = _step$value[1];
|
|
236
|
+
|
|
237
|
+
yield this.emitAsync(`plugins.${name}.beforeLoad`);
|
|
238
|
+
yield plugin.load();
|
|
239
|
+
yield this.emitAsync(`plugins.${name}.afterLoad`);
|
|
240
|
+
}
|
|
241
|
+
} catch (err) {
|
|
242
|
+
_iterator.e(err);
|
|
243
|
+
} finally {
|
|
244
|
+
_iterator.f();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
yield this.emitAsync('plugins.afterLoad');
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
emitAsync(event, ...args) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
const events = this._events;
|
|
254
|
+
let callbacks = events[event];
|
|
255
|
+
|
|
256
|
+
if (!callbacks) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const run = cb => {
|
|
261
|
+
switch (args.length) {
|
|
262
|
+
case 0:
|
|
263
|
+
cb = cb.call(this);
|
|
264
|
+
break;
|
|
265
|
+
|
|
266
|
+
case 1:
|
|
267
|
+
cb = cb.call(this, args[0]);
|
|
268
|
+
break;
|
|
269
|
+
|
|
270
|
+
case 2:
|
|
271
|
+
cb = cb.call(this, args[0], args[1]);
|
|
272
|
+
break;
|
|
273
|
+
|
|
274
|
+
case 3:
|
|
275
|
+
cb = cb.call(this, args[0], args[1], args[2]);
|
|
276
|
+
break;
|
|
277
|
+
|
|
278
|
+
default:
|
|
279
|
+
cb = cb.apply(this, args);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (cb && (cb instanceof Promise || typeof cb.then === 'function')) {
|
|
283
|
+
return cb;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return Promise.resolve(true);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
if (typeof callbacks === 'function') {
|
|
290
|
+
yield run(callbacks);
|
|
291
|
+
} else if (typeof callbacks === 'object') {
|
|
292
|
+
callbacks = callbacks.slice().filter(Boolean);
|
|
293
|
+
yield callbacks.reduce((prev, next) => {
|
|
294
|
+
return prev.then(res => {
|
|
295
|
+
return run(next).then(result => Promise.resolve(res.concat(result)));
|
|
296
|
+
});
|
|
297
|
+
}, Promise.resolve([]));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return true;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
parse(argv = process.argv) {
|
|
305
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
yield this.load();
|
|
307
|
+
return this.cli.parseAsync(argv);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
destroy() {
|
|
312
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
+
yield this.db.close();
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
exports.Application = Application;
|
|
320
|
+
exports.default = Application;
|
|
321
|
+
//# sourceMappingURL=application.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAAsB;AACtB,qDAA6B;AAC7B,oEAAwC;AACxC,yCAAoD;AACpD,kEAA6E;AAC7E,oEAAiE;AACjE,+CAA6D;AAC7D,qCAA6D;AAC7D,+CAAoD;AAsCpD,MAAa,WAGX,SAAQ,aAAG;IASX,YAAY,OAA2B;QACrC,KAAK,EAAE,CAAC;QAHA,YAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAK5C,IAAI,OAAO,CAAC,QAAQ,YAAY,kBAAQ,EAAE;YACxC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;SAC5B;aAAM;YACL,IAAI,CAAC,EAAE,GAAG,IAAI,kBAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;SAC1C;QAED,IAAI,CAAC,SAAS,GAAG,IAAI,mBAAS,mBAAM,OAAO,CAAC,SAAS,EAAG,CAAC;QACzD,IAAI,CAAC,GAAG,GAAG,IAAI,mBAAO,EAAE,CAAC;QAEzB,IAAI,OAAO,CAAC,UAAU,KAAK,KAAK,EAAE;YAChC,IAAI,CAAC,GAAG,CACN,wBAAU,mBACL,OAAO,CAAC,UAAU,EACrB,CACH,CAAC;SACH;QAED,IAAI,CAAC,GAAG,CACN,cAAI,iBACF,aAAa,EAAE,CAAC,qBAAqB,CAAC,IACnC,OAAO,CAAC,IAAI,EACf,CACH,CAAC;QAEF,IAAI,CAAC,GAAG,CAA+B,CAAO,GAAG,EAAE,IAAI,EAAE,EAAE;YACzD,GAAG,CAA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AC;KAAA;IAEK,OAAO;;YACX,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;KAAA;CACF;AA9OD,kCA8OC;AAED,kBAAe,WAAW,CAAC","file":"application.js","sourcesContent":["import Koa from 'koa';\nimport cors from '@koa/cors';\nimport bodyParser from 'koa-bodyparser';\nimport { Command, CommandOptions } from 'commander';\nimport Database, { DatabaseOptions, TableOptions } from '@nocobase/database';\nimport Resourcer, { ResourceOptions } from '@nocobase/resourcer';\nimport { dataWrapping, table2resource } from './middlewares';\nimport { PluginType, Plugin, PluginOptions } from './plugin';\nimport { registerActions } from '@nocobase/actions';\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}\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 protected plugins = new Map<string, Plugin>();\n\n constructor(options: ApplicationOptions) {\n super();\n\n if (options.database instanceof Database) {\n this.db = options.database;\n } else {\n this.db = new Database(options.database);\n }\n\n this.resourcer = new Resourcer({ ...options.resourcer });\n this.cli = new Command();\n\n if (options.bodyParser !== false) {\n this.use(\n bodyParser({\n ...options.bodyParser,\n }),\n );\n }\n\n this.use(\n cors({\n exposeHeaders: ['content-disposition'],\n ...options.cors,\n }),\n );\n\n this.use<DefaultState, DefaultContext>(async (ctx, next) => {\n ctx.db = this.db;\n ctx.resourcer = this.resourcer;\n await next();\n });\n\n if (options.dataWrapping !== false) {\n this.use(dataWrapping());\n }\n\n this.use(table2resource());\n this.use(this.resourcer.restApiMiddleware());\n\n registerActions(this);\n\n this.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 this.db.sync(\n force\n ? {\n force: true,\n alter: {\n drop: true,\n },\n }\n : {},\n );\n await this.destroy();\n });\n\n this.cli\n .command('init')\n // .option('-f, --force')\n .action(async (...args) => {\n const cli = args.pop();\n await this.db.sync({\n force: true,\n alter: {\n drop: true,\n },\n });\n await this.emitAsync('db.init');\n await this.destroy();\n });\n\n this.cli\n .command('start')\n .option('-p, --port [port]')\n .action(async (...args) => {\n const cli = args.pop();\n console.log(args);\n const opts = cli.opts();\n await this.emitAsync('beforeStart');\n this.listen(opts.port || 3000);\n console.log(`http://localhost:${opts.port || 3000}/`);\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 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/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _react() {
|
|
4
|
+
const data = _interopRequireDefault(require("react"));
|
|
5
|
+
|
|
6
|
+
_react = function _react() {
|
|
7
|
+
return data;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
Object.defineProperty(o, k2, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function get() {
|
|
20
|
+
return m[k];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
} : function (o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
value: v
|
|
32
|
+
});
|
|
33
|
+
} : function (o, v) {
|
|
34
|
+
o["default"] = v;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
38
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var __importStar = void 0 && (void 0).__importStar || function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
45
|
+
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
Object.defineProperty(exports, "__esModule", {
|
|
52
|
+
value: true
|
|
53
|
+
});
|
|
54
|
+
exports.default = exports.middlewares = void 0;
|
|
55
|
+
|
|
56
|
+
__exportStar(require("./application"), exports);
|
|
57
|
+
|
|
58
|
+
exports.middlewares = __importStar(require("./middlewares"));
|
|
59
|
+
|
|
60
|
+
__exportStar(require("./plugin"), exports);
|
|
61
|
+
|
|
62
|
+
var application_1 = require("./application");
|
|
63
|
+
|
|
64
|
+
Object.defineProperty(exports, "default", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function get() {
|
|
67
|
+
return application_1.Application;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,6DAA6C;AAC7C,2CAAyB;AACzB,6CAAuD;AAA9C,sGAAA,WAAW,OAAW","file":"index.js","sourcesContent":["export * from './application';\nexport * as middlewares from './middlewares';\nexport * from './plugin';\nexport { Application as default } from './application';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _react() {
|
|
4
|
+
const data = _interopRequireDefault(require("react"));
|
|
5
|
+
|
|
6
|
+
_react = function _react() {
|
|
7
|
+
return data;
|
|
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);
|
|
19
|
+
});
|
|
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
|
+
};
|
|
46
|
+
|
|
47
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
48
|
+
var t = {};
|
|
49
|
+
|
|
50
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
51
|
+
|
|
52
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
53
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
54
|
+
}
|
|
55
|
+
return t;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
Object.defineProperty(exports, "__esModule", {
|
|
59
|
+
value: true
|
|
60
|
+
});
|
|
61
|
+
exports.dataWrapping = void 0;
|
|
62
|
+
|
|
63
|
+
function dataWrapping() {
|
|
64
|
+
return function dataWrapping(ctx, next) {
|
|
65
|
+
var _a;
|
|
66
|
+
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
yield next();
|
|
69
|
+
|
|
70
|
+
if (ctx.withoutDataWrapping) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!((_a = ctx === null || ctx === void 0 ? void 0 : ctx.action) === null || _a === void 0 ? void 0 : _a.params)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (ctx.body instanceof Buffer) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!ctx.body) {
|
|
83
|
+
ctx.body = {};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const _b = ctx.body,
|
|
87
|
+
rows = _b.rows,
|
|
88
|
+
meta = __rest(_b, ["rows"]);
|
|
89
|
+
|
|
90
|
+
if (rows) {
|
|
91
|
+
ctx.body = {
|
|
92
|
+
data: rows,
|
|
93
|
+
meta
|
|
94
|
+
};
|
|
95
|
+
} else {
|
|
96
|
+
ctx.body = {
|
|
97
|
+
data: ctx.body
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
exports.dataWrapping = dataWrapping;
|
|
105
|
+
exports.default = dataWrapping;
|
|
106
|
+
//# sourceMappingURL=data-wrapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["middlewares/data-wrapping.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAgB,YAAY;IAC1B,OAAO,SAAe,YAAY,CAAC,GAAY,EAAE,IAAU;;;YACzD,MAAM,IAAI,EAAE,CAAC;YACb,IAAI,GAAG,CAAC,mBAAmB,EAAE;gBAC3B,OAAO;aACR;YACD,IAAI,QAAC,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,0CAAE,MAAM,CAAA,EAAE;gBACxB,OAAO;aACR;YACD,IAAI,GAAG,CAAC,IAAI,YAAY,MAAM,EAAE;gBAC9B,OAAO;aACR;YACD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;gBACb,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;aACf;YACD,MAAM,KAAoB,GAAG,CAAC,IAAI,EAA5B,EAAE,IAAI,OAAsB,EAAjB,IAAI,cAAf,QAAiB,CAAW,CAAC;YACnC,IAAI,IAAI,EAAE;gBACR,GAAG,CAAC,IAAI,GAAG;oBACT,IAAI,EAAE,IAAI;oBACV,IAAI;iBACL,CAAC;aACH;iBAAM;gBACL,GAAG,CAAC,IAAI,GAAG;oBACT,IAAI,EAAE,GAAG,CAAC,IAAI;iBACf,CAAC;aACH;;KACF,CAAA;AACH,CAAC;AA3BD,oCA2BC;AAED,kBAAe,YAAY,CAAC","file":"data-wrapping.js","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _react() {
|
|
4
|
+
const data = _interopRequireDefault(require("react"));
|
|
5
|
+
|
|
6
|
+
_react = function _react() {
|
|
7
|
+
return data;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
Object.defineProperty(o, k2, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function get() {
|
|
20
|
+
return m[k];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
} : function (o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
29
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
Object.defineProperty(exports, "__esModule", {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
__exportStar(require("./table2resource"), exports);
|
|
37
|
+
|
|
38
|
+
__exportStar(require("./data-wrapping"), exports);
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["middlewares/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AACjC,kDAAgC","file":"index.js","sourcesContent":["export * from './table2resource';\nexport * from './data-wrapping';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _react() {
|
|
4
|
+
const data = _interopRequireDefault(require("react"));
|
|
5
|
+
|
|
6
|
+
_react = function _react() {
|
|
7
|
+
return data;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
+
|
|
17
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
+
|
|
19
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
+
|
|
21
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
22
|
+
|
|
23
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
24
|
+
|
|
25
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
26
|
+
|
|
27
|
+
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
28
|
+
function adopt(value) {
|
|
29
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
30
|
+
resolve(value);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
+
function fulfilled(value) {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.next(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function rejected(value) {
|
|
44
|
+
try {
|
|
45
|
+
step(generator["throw"](value));
|
|
46
|
+
} catch (e) {
|
|
47
|
+
reject(e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function step(result) {
|
|
52
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
Object.defineProperty(exports, "__esModule", {
|
|
60
|
+
value: true
|
|
61
|
+
});
|
|
62
|
+
exports.table2resource = void 0;
|
|
63
|
+
|
|
64
|
+
const resourcer_1 = require("@nocobase/resourcer");
|
|
65
|
+
|
|
66
|
+
const database_1 = require("@nocobase/database");
|
|
67
|
+
|
|
68
|
+
function table2resource() {
|
|
69
|
+
return function table2resource(ctx, next) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const resourcer = ctx.resourcer;
|
|
72
|
+
const database = ctx.db;
|
|
73
|
+
let params = resourcer_1.parseRequest({
|
|
74
|
+
path: ctx.request.path,
|
|
75
|
+
method: ctx.request.method
|
|
76
|
+
}, {
|
|
77
|
+
prefix: resourcer.options.prefix,
|
|
78
|
+
accessors: resourcer.options.accessors
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (!params) {
|
|
82
|
+
return next();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const resourceName = resourcer_1.getNameByParams(params);
|
|
86
|
+
|
|
87
|
+
if (resourcer.isDefined(resourceName)) {
|
|
88
|
+
return next();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const _resourceName$split = resourceName.split('.'),
|
|
92
|
+
_resourceName$split2 = _slicedToArray(_resourceName$split, 2),
|
|
93
|
+
tableName = _resourceName$split2[0],
|
|
94
|
+
fieldName = _resourceName$split2[1];
|
|
95
|
+
|
|
96
|
+
if (!database.isDefined(tableName)) {
|
|
97
|
+
return next();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const table = database.getTable(tableName);
|
|
101
|
+
const field = table.getField(fieldName);
|
|
102
|
+
|
|
103
|
+
if (!fieldName || field) {
|
|
104
|
+
let resourceType = 'single';
|
|
105
|
+
let actions = {};
|
|
106
|
+
|
|
107
|
+
if (field) {
|
|
108
|
+
if (field instanceof database_1.HASONE) {
|
|
109
|
+
resourceType = 'hasOne';
|
|
110
|
+
} else if (field instanceof database_1.HASMANY) {
|
|
111
|
+
resourceType = 'hasMany';
|
|
112
|
+
} else if (field instanceof database_1.BELONGSTO) {
|
|
113
|
+
resourceType = 'belongsTo';
|
|
114
|
+
} else if (field instanceof database_1.BELONGSTOMANY) {
|
|
115
|
+
resourceType = 'belongsToMany';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (field.options.actions) {
|
|
119
|
+
actions = field.options.actions || {};
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
actions = table.getOptions('actions') || {};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
resourcer.define({
|
|
126
|
+
type: resourceType,
|
|
127
|
+
name: resourceName,
|
|
128
|
+
actions
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return next();
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
exports.table2resource = table2resource;
|
|
138
|
+
exports.default = table2resource;
|
|
139
|
+
//# sourceMappingURL=table2resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["middlewares/table2resource.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAK6B;AAC7B,iDAA+E;AAE/E,SAAgB,cAAc;IAC5B,OAAO,SAAe,cAAc,CAClC,GAAqB,EACrB,IAAwB;;YAExB,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;YAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,EAAE,CAAC;YACxB,IAAI,MAAM,GAAG,wBAAY,CACvB;gBACE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI;gBACtB,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM;aAC3B,EACD;gBACE,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,MAAM;gBAChC,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,SAAS;aACvC,CACF,CAAC;YACF,IAAI,CAAC,MAAM,EAAE;gBACX,OAAO,IAAI,EAAE,CAAC;aACf;YACD,MAAM,YAAY,GAAG,2BAAe,CAAC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AO,IAAI,EAAE,CAAC;QAChB,CAAC;KAAA,CAAC;AACJ,CAAC;AA/DD,wCA+DC;AAED,kBAAe,cAAc,CAAC","file":"table2resource.js","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
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Application } from './application';
|
|
2
|
+
export interface IPlugin {
|
|
3
|
+
install?: (this: Plugin) => void;
|
|
4
|
+
load?: (this: Plugin) => void;
|
|
5
|
+
}
|
|
6
|
+
export interface PluginOptions {
|
|
7
|
+
name?: string;
|
|
8
|
+
activate?: boolean;
|
|
9
|
+
displayName?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
version?: string;
|
|
12
|
+
install?: (this: Plugin) => void;
|
|
13
|
+
load?: (this: Plugin) => void;
|
|
14
|
+
plugin?: typeof Plugin;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}
|
|
17
|
+
export declare type PluginFn = (this: Plugin) => void;
|
|
18
|
+
export declare type PluginType = string | PluginFn | typeof Plugin;
|
|
19
|
+
export declare class Plugin implements IPlugin {
|
|
20
|
+
options: PluginOptions;
|
|
21
|
+
app: Application;
|
|
22
|
+
callbacks: IPlugin;
|
|
23
|
+
constructor(options?: PluginOptions & {
|
|
24
|
+
app?: Application;
|
|
25
|
+
});
|
|
26
|
+
getName(): string;
|
|
27
|
+
activate(): Promise<void>;
|
|
28
|
+
install(): Promise<void>;
|
|
29
|
+
call(name: string): Promise<void>;
|
|
30
|
+
load(): Promise<void>;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
package/lib/plugin.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _react() {
|
|
4
|
+
const data = _interopRequireDefault(require("react"));
|
|
5
|
+
|
|
6
|
+
_react = function _react() {
|
|
7
|
+
return data;
|
|
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);
|
|
19
|
+
});
|
|
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
|
+
};
|
|
46
|
+
|
|
47
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
48
|
+
return mod && mod.__esModule ? mod : {
|
|
49
|
+
"default": mod
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
Object.defineProperty(exports, "__esModule", {
|
|
54
|
+
value: true
|
|
55
|
+
});
|
|
56
|
+
exports.Plugin = void 0;
|
|
57
|
+
|
|
58
|
+
const database_1 = require("@nocobase/database");
|
|
59
|
+
|
|
60
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
61
|
+
|
|
62
|
+
class Plugin {
|
|
63
|
+
constructor(options) {
|
|
64
|
+
this.options = {};
|
|
65
|
+
this.callbacks = {};
|
|
66
|
+
this.app = options === null || options === void 0 ? void 0 : options.app;
|
|
67
|
+
this.options = options;
|
|
68
|
+
this.callbacks = lodash_1.default.pick(options, ['load', 'activate']);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getName() {
|
|
72
|
+
return this.options.name || database_1.uid();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
activate() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
this.options.activate = true;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
install() {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
yield this.call('install');
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
call(name) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
if (!this.callbacks[name]) {
|
|
90
|
+
return;
|
|
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
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
exports.Plugin = Plugin;
|
|
107
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iDAAyC;AAEzC,oDAAuB;AAuBvB,MAAa,MAAM;IAKjB,YAAY,OAA+C;QAJ3D,YAAO,GAAkB,EAAE,CAAC;QAE5B,cAAS,GAAY,EAAE,CAAC;QAGtB,IAAI,CAAC,GAAG,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,gBAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,cAAG,EAAE,CAAC;IACpC,CAAC;IAEK,QAAQ;;YACZ,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC/B,CAAC;KAAA;IAEK,OAAO;;YACX,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7B,CAAC;KAAA;IAEK,IAAI,CAAC,IAAY;;YACrB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;gBACzB,OAAO;aACR;YACD,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjD,MAAM,QAAQ,EAAE,CAAC;QACnB,CAAC;KAAA;IAEK,IAAI;;YACR,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;KAAA;CACF;AAlCD,wBAkCC","file":"plugin.js","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"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/server",
|
|
3
|
+
"version": "0.5.0-alpha.10",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"types": "./lib/index.d.ts",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@koa/cors": "^3.1.0",
|
|
10
|
+
"@koa/router": "^9.4.0",
|
|
11
|
+
"@nocobase/actions": "^0.5.0-alpha.10",
|
|
12
|
+
"@nocobase/database": "^0.5.0-alpha.10",
|
|
13
|
+
"@nocobase/resourcer": "^0.5.0-alpha.10",
|
|
14
|
+
"commander": "^8.1.0",
|
|
15
|
+
"dotenv": "^8.2.0",
|
|
16
|
+
"koa": "^2.13.0",
|
|
17
|
+
"koa-bodyparser": "^4.3.0",
|
|
18
|
+
"koa-static": "^5.0.0",
|
|
19
|
+
"mockjs": "^1.1.0",
|
|
20
|
+
"mysql2": "^2.1.0",
|
|
21
|
+
"pg": "^8.3.3",
|
|
22
|
+
"pg-hstore": "^2.3.3"
|
|
23
|
+
},
|
|
24
|
+
"gitHead": "9787bedb3c65dbf54ea905dd840944bb6a1ee67b"
|
|
25
|
+
}
|