@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
|
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c,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC;KAAA;IAEK,OAAO,CAAC,OAAwB;;YACpC,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YAErD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,EAAE;gBAClB,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;aACzF;YAED,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,CAAC;YAClC,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC/B,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC;KAAA;CAGF;AAED,WAAW,CAAC,WAAW,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;AAEzC,eAAe,WAAW,CAAC","sourcesContent":["import { ACL } from '@nocobase/acl';\nimport { registerActions } from '@nocobase/actions';\nimport Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';\nimport Resourcer, { ResourceOptions } from '@nocobase/resourcer';\nimport { applyMixins, AsyncEmitter } from '@nocobase/utils';\nimport { Command, CommandOptions } from 'commander';\nimport { Server } from 'http';\nimport { i18n, InitOptions } from 'i18next';\nimport Koa from 'koa';\nimport { isBoolean } from 'lodash';\nimport { createACL } from './acl';\nimport { AppManager } from './app-manager';\nimport { createCli } from './commands';\nimport { createDatabase, createI18n, createResourcer, registerMiddlewares } from './helper';\nimport { Plugin } from './plugin';\nimport { InstallOptions, PluginManager } from './plugin-manager';\n\nexport type PluginConfiguration = string | [string, any];\nexport type PluginsConfigurations = Array<PluginConfiguration>;\n\nexport interface ResourcerOptions {\n prefix?: string;\n}\n\nexport interface ApplicationOptions {\n database?: IDatabaseOptions | Database;\n resourcer?: ResourcerOptions;\n bodyParser?: any;\n cors?: any;\n dataWrapping?: boolean;\n registerActions?: boolean;\n i18n?: i18n | InitOptions;\n plugins?: PluginsConfigurations;\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\ninterface ListenOptions {\n port?: number | undefined;\n host?: string | undefined;\n backlog?: number | undefined;\n path?: string | undefined;\n exclusive?: boolean | undefined;\n readableAll?: boolean | undefined;\n writableAll?: boolean | undefined;\n /**\n * @default false\n */\n ipv6Only?: boolean | undefined;\n signal?: AbortSignal | undefined;\n}\n\ninterface StartOptions {\n cliArgs?: any[];\n listen?: ListenOptions;\n}\n\nexport class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {\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 public readonly pm: PluginManager;\n\n public readonly acl: ACL;\n\n public readonly appManager: AppManager;\n\n protected plugins = new Map<string, Plugin>();\n\n public listenServer: Server;\n\n constructor(public options: ApplicationOptions) {\n super();\n\n this.acl = createACL();\n this.db = createDatabase(options);\n this.resourcer = createResourcer(options);\n this.cli = createCli(this);\n this.i18n = createI18n(options);\n\n this.pm = new PluginManager({\n app: this,\n });\n\n this.appManager = new AppManager(this);\n\n registerMiddlewares(this, options);\n\n if (options.registerActions !== false) {\n registerActions(this);\n }\n\n this.loadPluginConfig(options.plugins || []);\n }\n\n plugin<O = any>(pluginClass: any, options?: O): Plugin<O> {\n return this.pm.add(pluginClass, options);\n }\n\n loadPluginConfig(pluginsConfigurations: PluginsConfigurations) {\n for (let pluginConfiguration of pluginsConfigurations) {\n if (typeof pluginConfiguration == 'string') {\n pluginConfiguration = [pluginConfiguration, {}];\n }\n\n const plugin = PluginManager.resolvePlugin(pluginConfiguration[0]);\n const pluginOptions = pluginConfiguration[1];\n\n this.plugin(plugin, pluginOptions);\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: CollectionOptions) {\n return this.db.collection(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(name: string, desc?: string, opts?: CommandOptions): Command {\n return this.cli.command(name, desc, opts);\n }\n\n findCommand(name: string): Command {\n return (<any>this.cli)._findCommand(name);\n }\n\n async load() {\n await this.pm.load();\n }\n\n getPlugin<P extends Plugin>(name: string) {\n return this.pm.get(name) as P;\n }\n\n async parse(argv = process.argv) {\n await this.load();\n return this.cli.parseAsync(argv);\n }\n\n async start(options?: StartOptions) {\n // reconnect database\n if (this.db.closed()) {\n await this.db.reconnect();\n }\n\n await this.emitAsync('beforeStart', this, options);\n\n if (options?.listen?.port) {\n const listen = () =>\n new Promise((resolve) => {\n const Server = this.listen(options?.listen, () => {\n resolve(Server);\n });\n });\n\n // @ts-ignore\n this.listenServer = await listen();\n }\n\n await this.emitAsync('afterStart', this, options);\n }\n\n listen(...args): Server {\n return this.appManager.listen(...args);\n }\n\n async stop(options?: any) {\n await this.emitAsync('beforeStop', this, options);\n\n try {\n // close database connection\n // silent if database already closed\n await this.db.close();\n } catch (e) {\n console.log(e);\n }\n\n // close http server\n if (this.listenServer) {\n const closeServer = () =>\n new Promise((resolve, reject) => {\n this.listenServer.close((err) => {\n if (err) {\n return reject(err);\n }\n this.listenServer = null;\n resolve(true);\n });\n });\n\n await closeServer();\n }\n\n await this.emitAsync('afterStop', this, options);\n }\n\n async destroy(options?: any) {\n await this.emitAsync('beforeDestroy', this, options);\n await this.stop(options);\n await this.emitAsync('afterDestroy', this, options);\n }\n\n async install(options?: InstallOptions) {\n await this.emitAsync('beforeInstall', this, options);\n\n if (options?.clean) {\n await this.db.clean(isBoolean(options.clean) ? { drop: options.clean } : options.clean);\n }\n\n await this.db.sync(options?.sync);\n await this.pm.install(options);\n await this.emitAsync('afterInstall', this, options);\n }\n\n emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;\n}\n\napplyMixins(Application, [AsyncEmitter]);\n\nexport default Application;\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const REPL = require('repl');
|
|
11
|
+
export default ({ app }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
yield app.start();
|
|
13
|
+
const repl = (REPL.start('nocobase > ').context.app = app);
|
|
14
|
+
repl.on('exit', function (err) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
if (err) {
|
|
17
|
+
console.log(err);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
yield app.stop();
|
|
21
|
+
process.exit(0);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/commands/console.ts"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE7B,eAAe,CAAO,EAAE,GAAG,EAAE,EAAE,EAAE;IAC/B,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IAClB,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;IAE3D,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,UAAgB,GAAG;;YACjC,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;YAED,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;KAAA,CAAC,CAAC;AACL,CAAC,CAAA,CAAC","sourcesContent":["const REPL = require('repl');\n\nexport default async ({ app }) => {\n await app.start();\n const repl = (REPL.start('nocobase > ').context.app = app);\n\n repl.on('exit', async function (err) {\n if (err) {\n console.log(err);\n process.exit(1);\n }\n\n await app.stop();\n process.exit(0);\n });\n};\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const fse = require('fs-extra');
|
|
12
|
+
const { join } = require('path');
|
|
13
|
+
const createPackageJson = require('./resources/templates/package-json');
|
|
14
|
+
const createPluginClass = require('./resources/templates/plugin');
|
|
15
|
+
export default (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const pluginName = `plugin-${name}`;
|
|
17
|
+
const pluginPath = join(process.cwd(), `packages/${pluginName}`);
|
|
18
|
+
const resourcePath = join(__dirname, 'resources');
|
|
19
|
+
console.log(`Creating a new NocoBase plugin at ${chalk.green(pluginPath)}.`);
|
|
20
|
+
yield fse.copy(join(resourcePath, 'files'), pluginPath);
|
|
21
|
+
yield fse.outputFile(join(pluginPath, 'src/server/index.ts'), createPluginClass({ name }));
|
|
22
|
+
// write server package.json
|
|
23
|
+
yield fse.writeJson(join(pluginPath, 'package.json'), createPackageJson({
|
|
24
|
+
name: pluginName,
|
|
25
|
+
}), {
|
|
26
|
+
spaces: 2,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=create-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-plugin.js","sourceRoot":"","sources":["../../../src/commands/create-plugin/create-plugin.ts"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/B,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAChC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AACjC,MAAM,iBAAiB,GAAG,OAAO,CAAC,oCAAoC,CAAC,CAAC;AACxE,MAAM,iBAAiB,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAElE,eAAe,CAAO,IAAI,EAAE,EAAE;IAC5B,MAAM,UAAU,GAAG,UAAU,IAAI,EAAE,CAAC;IAEpC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,UAAU,EAAE,CAAC,CAAC;IACjE,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAElD,OAAO,CAAC,GAAG,CAAC,qCAAqC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7E,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC;IAExD,MAAM,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,qBAAqB,CAAC,EAAE,iBAAiB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAE3F,4BAA4B;IAC5B,MAAM,GAAG,CAAC,SAAS,CACjB,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,EAChC,iBAAiB,CAAC;QAChB,IAAI,EAAE,UAAU;KACjB,CAAC,EACF;QACE,MAAM,EAAE,CAAC;KACV,CACF,CAAC;AACJ,CAAC,CAAA,CAAC","sourcesContent":["const chalk = require('chalk');\nconst fse = require('fs-extra');\nconst { join } = require('path');\nconst createPackageJson = require('./resources/templates/package-json');\nconst createPluginClass = require('./resources/templates/plugin');\n\nexport default async (name) => {\n const pluginName = `plugin-${name}`;\n\n const pluginPath = join(process.cwd(), `packages/${pluginName}`);\n const resourcePath = join(__dirname, 'resources');\n\n console.log(`Creating a new NocoBase plugin at ${chalk.green(pluginPath)}.`);\n await fse.copy(join(resourcePath, 'files'), pluginPath);\n\n await fse.outputFile(join(pluginPath, 'src/server/index.ts'), createPluginClass({ name }));\n\n // write server package.json\n await fse.writeJson(\n join(pluginPath, 'package.json'),\n createPackageJson({\n name: pluginName,\n }),\n {\n spaces: 2,\n },\n );\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/create-plugin/index.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAChD,eAAe,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACxB,YAAY,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC,CAAC","sourcesContent":["const createPlugin = require('./create-plugin');\nexport default ({ app, cliArgs }) => {\n const name = cliArgs[0];\n createPlugin(name);\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.js","sourceRoot":"","sources":["../../../../../src/commands/create-plugin/resources/templates/package-json.ts"],"names":[],"mappings":"AAAA,eAAe,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC1B,OAAO;QACL,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE,WAAW;QACjB,YAAY,EAAE;YACZ,kBAAkB,EAAE,gBAAgB;SACrC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["export default ({ name }) => {\n return {\n name: name,\n version: '0.1.0',\n main: 'server.js',\n dependencies: {\n '@nocobase/server': '^0.6.0-alpha.0',\n },\n };\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as _ from 'lodash';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
export default ({ name }) => {
|
|
5
|
+
const tmpl = fs.readFileSync(path.join(__dirname, 'plugin-class.template'), { encoding: 'utf-8' });
|
|
6
|
+
const compile = _.template(tmpl);
|
|
7
|
+
return compile({
|
|
8
|
+
name,
|
|
9
|
+
className: _.startCase(_.camelCase(name)),
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../../../src/commands/create-plugin/resources/templates/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,eAAe,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC1B,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IACnG,MAAM,OAAO,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEjC,OAAO,OAAO,CAAC;QACb,IAAI;QACJ,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import * as _ from 'lodash';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nexport default ({ name }) => {\n const tmpl = fs.readFileSync(path.join(__dirname, 'plugin-class.template'), { encoding: 'utf-8' });\n const compile = _.template(tmpl);\n\n return compile({\n name,\n className: _.startCase(_.camelCase(name)),\n });\n};\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export default ({ app, cliArgs }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
const [opts] = cliArgs;
|
|
12
|
+
console.log('db sync...');
|
|
13
|
+
yield app.db.sync(opts.force
|
|
14
|
+
? {
|
|
15
|
+
force: true,
|
|
16
|
+
alter: {
|
|
17
|
+
drop: true,
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
: {});
|
|
21
|
+
yield app.stop({
|
|
22
|
+
cliArgs,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=db-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-sync.js","sourceRoot":"","sources":["../../src/commands/db-sync.ts"],"names":[],"mappings":";;;;;;;;;AAAA,eAAe,CAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IACxC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IACvB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1B,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CACf,IAAI,CAAC,KAAK;QACR,CAAC,CAAC;YACE,KAAK,EAAE,IAAI;YACX,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI;aACX;SACF;QACH,CAAC,CAAC,EAAE,CACP,CAAC;IACF,MAAM,GAAG,CAAC,IAAI,CAAC;QACb,OAAO;KACR,CAAC,CAAC;AACL,CAAC,CAAA,CAAC","sourcesContent":["export default async ({ app, cliArgs }) => {\n const [opts] = cliArgs;\n console.log('db sync...');\n await app.db.sync(\n opts.force\n ? {\n force: true,\n alter: {\n drop: true,\n },\n }\n : {},\n );\n await app.stop({\n cliArgs,\n });\n};\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export function createCli(app) {
|
|
3
|
+
const program = new Command();
|
|
4
|
+
const runSubCommand = (name) => (...cliArgs) => {
|
|
5
|
+
const command = require(`./${name}`).default;
|
|
6
|
+
Promise.resolve()
|
|
7
|
+
.then(() => {
|
|
8
|
+
return command({ app, cliArgs });
|
|
9
|
+
})
|
|
10
|
+
.catch((error) => {
|
|
11
|
+
console.error(error);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
program.command('start').description('start NocoBase application').action(runSubCommand('start'));
|
|
16
|
+
program.command('install').option('-f, --force').option('-c, --clean').action(runSubCommand('install'));
|
|
17
|
+
program.command('db:sync').option('-f, --force').action(runSubCommand('db-sync'));
|
|
18
|
+
program.command('console').action(runSubCommand('console'));
|
|
19
|
+
program
|
|
20
|
+
.command('create-plugin')
|
|
21
|
+
.argument('<name>', 'name of plugin')
|
|
22
|
+
.description('create NocoBase plugin')
|
|
23
|
+
.action(runSubCommand('create-plugin'));
|
|
24
|
+
return program;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,UAAU,SAAS,CAAC,GAAgB;IACxC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,MAAM,aAAa,GACjB,CAAC,IAAI,EAAE,EAAE,CACT,CAAC,GAAG,OAAO,EAAE,EAAE;QACb,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC;QAE7C,OAAO,CAAC,OAAO,EAAE;aACd,IAAI,CAAC,GAAG,EAAE;YACT,OAAO,OAAO,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;IAEJ,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,4BAA4B,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IAClG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IACxG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IAClF,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IAE5D,OAAO;SACJ,OAAO,CAAC,eAAe,CAAC;SACxB,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;SACpC,WAAW,CAAC,wBAAwB,CAAC;SACrC,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC;IAE1C,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import Application from '../application';\nimport { Command } from 'commander';\n\nexport function createCli(app: Application) {\n const program = new Command();\n\n const runSubCommand =\n (name) =>\n (...cliArgs) => {\n const command = require(`./${name}`).default;\n\n Promise.resolve()\n .then(() => {\n return command({ app, cliArgs });\n })\n .catch((error) => {\n console.error(error);\n process.exit(1);\n });\n };\n\n program.command('start').description('start NocoBase application').action(runSubCommand('start'));\n program.command('install').option('-f, --force').option('-c, --clean').action(runSubCommand('install'));\n program.command('db:sync').option('-f, --force').action(runSubCommand('db-sync'));\n program.command('console').action(runSubCommand('console'));\n\n program\n .command('create-plugin')\n .argument('<name>', 'name of plugin')\n .description('create NocoBase plugin')\n .action(runSubCommand('create-plugin'));\n\n return program;\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export default ({ app, cliArgs }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
const [opts] = cliArgs;
|
|
12
|
+
yield app.install({
|
|
13
|
+
cliArgs,
|
|
14
|
+
clean: opts.clean,
|
|
15
|
+
sync: {
|
|
16
|
+
force: opts.force,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
yield app.stop({
|
|
20
|
+
cliArgs,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/commands/install.ts"],"names":[],"mappings":";;;;;;;;;AAAA,eAAe,CAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IACxC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IACvB,MAAM,GAAG,CAAC,OAAO,CAAC;QAChB,OAAO;QACP,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,IAAI,EAAE;YACJ,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB;KACF,CAAC,CAAC;IACH,MAAM,GAAG,CAAC,IAAI,CAAC;QACb,OAAO;KACR,CAAC,CAAC;AACL,CAAC,CAAA,CAAC","sourcesContent":["export default async ({ app, cliArgs }) => {\n const [opts] = cliArgs;\n await app.install({\n cliArgs,\n clean: opts.clean,\n sync: {\n force: opts.force,\n },\n });\n await app.stop({\n cliArgs,\n });\n};\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export default ({ app, cliArgs }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
const [opts] = cliArgs;
|
|
12
|
+
const port = opts.port || process.env.SERVER_PORT || 3000;
|
|
13
|
+
const host = opts.host || process.env.SERVER_HOST || '0.0.0.0';
|
|
14
|
+
yield app.start({
|
|
15
|
+
cliArgs,
|
|
16
|
+
listen: {
|
|
17
|
+
port,
|
|
18
|
+
host,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
console.log(`🚀 nocobase server had started at http://${host}:${port}`);
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=start.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":";;;;;;;;;AAAA,eAAe,CAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IACxC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,IAAI,CAAC;IAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,SAAS,CAAC;IAE/D,MAAM,GAAG,CAAC,KAAK,CAAC;QACd,OAAO;QACP,MAAM,EAAE;YACN,IAAI;YACJ,IAAI;SACL;KACF,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,4CAA4C,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAA,CAAC","sourcesContent":["export default async ({ app, cliArgs }) => {\n const [opts] = cliArgs;\n const port = opts.port || process.env.SERVER_PORT || 3000;\n const host = opts.host || process.env.SERVER_HOST || '0.0.0.0';\n\n await app.start({\n cliArgs,\n listen: {\n port,\n host,\n },\n });\n\n console.log(`🚀 nocobase server had started at http://${host}:${port}`);\n};\n"]}
|
package/esm/helper.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Database from '@nocobase/database';
|
|
2
|
+
import Resourcer from '@nocobase/resourcer';
|
|
3
|
+
import Application, { ApplicationOptions } from './application';
|
|
4
|
+
export declare function createI18n(options: ApplicationOptions): import("i18next").i18n;
|
|
5
|
+
export declare function createDatabase(options: ApplicationOptions): Database;
|
|
6
|
+
export declare function createResourcer(options: ApplicationOptions): Resourcer;
|
|
7
|
+
export declare function registerMiddlewares(app: Application, options: ApplicationOptions): void;
|
package/esm/helper.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import cors from '@koa/cors';
|
|
11
|
+
import Database from '@nocobase/database';
|
|
12
|
+
import Resourcer from '@nocobase/resourcer';
|
|
13
|
+
import i18next from 'i18next';
|
|
14
|
+
import bodyParser from 'koa-bodyparser';
|
|
15
|
+
import { dataWrapping } from './middlewares/data-wrapping';
|
|
16
|
+
import { table2resource } from './middlewares/table2resource';
|
|
17
|
+
export function createI18n(options) {
|
|
18
|
+
const instance = i18next.createInstance();
|
|
19
|
+
instance.init(Object.assign({ lng: 'en-US', resources: {} }, options.i18n));
|
|
20
|
+
return instance;
|
|
21
|
+
}
|
|
22
|
+
export function createDatabase(options) {
|
|
23
|
+
if (options.database instanceof Database) {
|
|
24
|
+
return options.database;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return new Database(options.database);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function createResourcer(options) {
|
|
31
|
+
return new Resourcer(Object.assign({}, options.resourcer));
|
|
32
|
+
}
|
|
33
|
+
export function registerMiddlewares(app, options) {
|
|
34
|
+
if (options.bodyParser !== false) {
|
|
35
|
+
app.use(bodyParser(Object.assign({}, options.bodyParser)));
|
|
36
|
+
}
|
|
37
|
+
app.use(cors(Object.assign({ exposeHeaders: ['content-disposition'] }, options.cors)));
|
|
38
|
+
app.use((ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
ctx.getBearerToken = () => {
|
|
40
|
+
return ctx.get('Authorization').replace(/^Bearer\s+/gi, '');
|
|
41
|
+
};
|
|
42
|
+
ctx.db = app.db;
|
|
43
|
+
ctx.resourcer = app.resourcer;
|
|
44
|
+
const i18n = app.i18n.cloneInstance({ initImmediate: false });
|
|
45
|
+
ctx.i18n = i18n;
|
|
46
|
+
ctx.t = i18n.t.bind(i18n);
|
|
47
|
+
const lng = ctx.request.query.locale || ctx.acceptsLanguages().shift();
|
|
48
|
+
if (lng !== '*' && lng) {
|
|
49
|
+
i18n.changeLanguage(lng);
|
|
50
|
+
}
|
|
51
|
+
yield next();
|
|
52
|
+
}));
|
|
53
|
+
if (options.dataWrapping !== false) {
|
|
54
|
+
app.use(dataWrapping());
|
|
55
|
+
}
|
|
56
|
+
app.use(table2resource());
|
|
57
|
+
app.use(app.resourcer.restApiMiddleware());
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAE5C,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,UAAU,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,MAAM,UAAU,UAAU,CAAC,OAA2B;IACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAC1C,QAAQ,CAAC,IAAI,iBACX,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,EAAE,IACV,OAAO,CAAC,IAAI,EACf,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAA2B;IACxD,IAAI,OAAO,CAAC,QAAQ,YAAY,QAAQ,EAAE;QACxC,OAAO,OAAO,CAAC,QAAQ,CAAC;KACzB;SAAM;QACL,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;KACvC;AACH,CAAC;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C,CAAA,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,YAAY,KAAK,KAAK,EAAE;QAClC,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC;KACzB;IAED,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,CAAC;IAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import cors from '@koa/cors';\nimport Database from '@nocobase/database';\nimport Resourcer from '@nocobase/resourcer';\nimport { Command } from 'commander';\nimport i18next from 'i18next';\nimport { DefaultContext, DefaultState } from 'koa';\nimport bodyParser from 'koa-bodyparser';\nimport Application, { ApplicationOptions } from './application';\nimport { dataWrapping } from './middlewares/data-wrapping';\nimport { table2resource } from './middlewares/table2resource';\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 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 registerMiddlewares(app: Application, options: ApplicationOptions) {\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.getBearerToken = () => {\n return ctx.get('Authorization').replace(/^Bearer\\s+/gi, '');\n };\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/esm/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { AppManager } from './app-manager';
|
|
2
|
+
export * from './application';
|
|
3
|
+
export { Application as default } from './application';
|
|
4
|
+
export * as middlewares from './middlewares';
|
|
5
|
+
export * from './plugin';
|
|
6
|
+
export * from './plugin-manager';
|
|
7
|
+
export * from './read-config';
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { AppManager } from './app-manager';
|
|
2
|
+
export * from './application';
|
|
3
|
+
export { Application as default } from './application';
|
|
4
|
+
import * as middlewares_1 from './middlewares';
|
|
5
|
+
export { middlewares_1 as middlewares };
|
|
6
|
+
export * from './plugin';
|
|
7
|
+
export * from './plugin-manager';
|
|
8
|
+
export * from './read-config';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,eAAe,CAAC;+BAC1B,eAAe;0BAAhC,WAAW;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC","sourcesContent":["export { AppManager } from './app-manager';\nexport * from './application';\nexport { Application as default } from './application';\nexport * as middlewares from './middlewares';\nexport * from './plugin';\nexport * from './plugin-manager';\nexport * from './read-config';\n\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
export function dataWrapping() {
|
|
22
|
+
return function dataWrapping(ctx, next) {
|
|
23
|
+
var _a;
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
yield next();
|
|
26
|
+
if (ctx.withoutDataWrapping) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (!((_a = ctx === null || ctx === void 0 ? void 0 : ctx.action) === null || _a === void 0 ? void 0 : _a.params)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (ctx.body instanceof Buffer) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!ctx.body) {
|
|
36
|
+
ctx.body = {};
|
|
37
|
+
}
|
|
38
|
+
const _b = ctx.body, { rows } = _b, meta = __rest(_b, ["rows"]);
|
|
39
|
+
if (rows) {
|
|
40
|
+
ctx.body = {
|
|
41
|
+
data: rows,
|
|
42
|
+
meta,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
ctx.body = {
|
|
47
|
+
data: ctx.body,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export default dataWrapping;
|
|
54
|
+
//# sourceMappingURL=data-wrapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-wrapping.js","sourceRoot":"","sources":["../../src/middlewares/data-wrapping.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA,MAAM,UAAU,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,CAAC,CAAA,MAAA,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,CAAC;AACJ,CAAC;AAED,eAAe,YAAY,CAAC","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,"file":"index.js","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './table2resource';\nexport * from './data-wrapping';\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { getNameByParams, parseRequest } from '@nocobase/resourcer';
|
|
11
|
+
export function table2resource() {
|
|
12
|
+
return function table2resource(ctx, next) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const resourcer = ctx.resourcer;
|
|
15
|
+
const database = ctx.db;
|
|
16
|
+
let params = parseRequest({
|
|
17
|
+
path: ctx.request.path,
|
|
18
|
+
method: ctx.request.method,
|
|
19
|
+
}, {
|
|
20
|
+
prefix: resourcer.options.prefix,
|
|
21
|
+
accessors: resourcer.options.accessors,
|
|
22
|
+
});
|
|
23
|
+
if (!params) {
|
|
24
|
+
return next();
|
|
25
|
+
}
|
|
26
|
+
const resourceName = getNameByParams(params);
|
|
27
|
+
// 如果资源名称未被定义
|
|
28
|
+
if (resourcer.isDefined(resourceName)) {
|
|
29
|
+
return next();
|
|
30
|
+
}
|
|
31
|
+
const [collectionName, fieldName] = resourceName.split('.');
|
|
32
|
+
// 如果经过加载后是已经定义的表
|
|
33
|
+
if (!database.hasCollection(collectionName)) {
|
|
34
|
+
return next();
|
|
35
|
+
}
|
|
36
|
+
const collection = database.getCollection(collectionName);
|
|
37
|
+
let resourceType = 'single';
|
|
38
|
+
if (fieldName && collection.hasField(fieldName)) {
|
|
39
|
+
const field = collection.getField(fieldName);
|
|
40
|
+
resourceType = field.type;
|
|
41
|
+
}
|
|
42
|
+
resourcer.define({
|
|
43
|
+
type: resourceType,
|
|
44
|
+
name: resourceName,
|
|
45
|
+
});
|
|
46
|
+
return next();
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export default table2resource;
|
|
51
|
+
//# sourceMappingURL=table2resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table2resource.js","sourceRoot":"","sources":["../../src/middlewares/table2resource.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAkC,MAAM,qBAAqB,CAAC;AAGpG,MAAM,UAAU,cAAc;IAC5B,OAAO,SAAe,cAAc,CAAC,GAAwC,EAAE,IAAwB;;YACrG,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;YAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,EAAE,CAAC;YACxB,IAAI,MAAM,GAAG,YAAY,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,eAAe,CAAC,MAAM,CAAC,CAAC;YAC7C,aAAa;YACb,IAAI,SAAS,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE;gBACrC,OAAO,IAAI,EAAE,CAAC;aACf;YACD,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5D,iBAAiB;YACjB,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE;gBAC3C,OAAO,IAAI,EAAE,CAAC;aACf;YACD,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;YAC1D,IAAI,YAAY,GAAiB,QAAQ,CAAC;YAC1C,IAAI,SAAS,IAAI,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;gBAC/C,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;gBAC7C,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC;aAC3B;YACD,SAAS,CAAC,MAAM,CAAC;gBACf,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,YAAY;aACnB,CAAC,CAAC;YACH,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;KAAA,CAAC;AACJ,CAAC;AAED,eAAe,cAAc,CAAC","sourcesContent":["import { getNameByParams, parseRequest, ResourcerContext, ResourceType } from '@nocobase/resourcer';\nimport Database from '@nocobase/database';\n\nexport function table2resource() {\n return async function table2resource(ctx: ResourcerContext & { db: Database }, next: () => Promise<any>) {\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 [collectionName, fieldName] = resourceName.split('.');\n // 如果经过加载后是已经定义的表\n if (!database.hasCollection(collectionName)) {\n return next();\n }\n const collection = database.getCollection(collectionName);\n let resourceType: ResourceType = 'single';\n if (fieldName && collection.hasField(fieldName)) {\n const field = collection.getField(fieldName);\n resourceType = field.type;\n }\n resourcer.define({\n type: resourceType,\n name: resourceName,\n });\n return next();\n };\n}\n\nexport default table2resource;\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CleanOptions, SyncOptions } from '@nocobase/database';
|
|
2
|
+
import Application from './application';
|
|
3
|
+
import { Plugin } from './plugin';
|
|
4
|
+
interface PluginManagerOptions {
|
|
5
|
+
app: Application;
|
|
6
|
+
}
|
|
7
|
+
export interface InstallOptions {
|
|
8
|
+
cliArgs?: any[];
|
|
9
|
+
clean?: CleanOptions | boolean;
|
|
10
|
+
sync?: SyncOptions;
|
|
11
|
+
}
|
|
12
|
+
export declare class PluginManager {
|
|
13
|
+
app: Application;
|
|
14
|
+
protected plugins: Map<string, Plugin<any>>;
|
|
15
|
+
constructor(options: PluginManagerOptions);
|
|
16
|
+
getPlugins(): Map<string, Plugin<any>>;
|
|
17
|
+
get(name: string): Plugin<any>;
|
|
18
|
+
add<P = Plugin, O = any>(pluginClass: any, options?: O): P;
|
|
19
|
+
load(): Promise<void>;
|
|
20
|
+
install(options?: InstallOptions): Promise<void>;
|
|
21
|
+
static resolvePlugin(pluginName: string): any;
|
|
22
|
+
}
|
|
23
|
+
export {};
|