@nocobase/server 0.7.0-alpha.7 → 0.7.0-alpha.70

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.
Files changed (124) hide show
  1. package/lib/acl/available-action.js +37 -35
  2. package/lib/acl/index.js +45 -21
  3. package/lib/app-manager.d.ts +3 -3
  4. package/lib/app-manager.js +151 -72
  5. package/lib/application.d.ts +3 -2
  6. package/lib/application.js +291 -153
  7. package/lib/commands/console.d.ts +2 -3
  8. package/lib/commands/console.js +33 -24
  9. package/lib/commands/db-auth.d.ts +3 -0
  10. package/lib/commands/db-auth.js +26 -0
  11. package/lib/commands/db-clean.d.ts +3 -0
  12. package/lib/commands/db-clean.js +27 -0
  13. package/lib/commands/db-sync.d.ts +2 -4
  14. package/lib/commands/db-sync.js +25 -23
  15. package/lib/commands/index.d.ts +1 -2
  16. package/lib/commands/index.js +29 -29
  17. package/lib/commands/install.d.ts +2 -4
  18. package/lib/commands/install.js +68 -20
  19. package/lib/commands/start.d.ts +2 -4
  20. package/lib/commands/start.js +28 -22
  21. package/lib/commands/upgrade.d.ts +6 -0
  22. package/lib/commands/upgrade.js +45 -0
  23. package/lib/helper.js +132 -61
  24. package/lib/index.js +85 -32
  25. package/lib/middlewares/data-wrapping.js +65 -55
  26. package/lib/middlewares/index.js +30 -14
  27. package/lib/middlewares/table2resource.js +89 -52
  28. package/lib/plugin-manager.js +124 -55
  29. package/lib/plugin.js +65 -45
  30. package/lib/read-config.js +159 -64
  31. package/package.json +8 -13
  32. package/esm/acl/available-action.d.ts +0 -5
  33. package/esm/acl/available-action.js +0 -36
  34. package/esm/acl/available-action.js.map +0 -1
  35. package/esm/acl/index.d.ts +0 -2
  36. package/esm/acl/index.js +0 -19
  37. package/esm/acl/index.js.map +0 -1
  38. package/esm/app-manager.d.ts +0 -19
  39. package/esm/app-manager.js +0 -69
  40. package/esm/app-manager.js.map +0 -1
  41. package/esm/application.d.ts +0 -97
  42. package/esm/application.js +0 -156
  43. package/esm/application.js.map +0 -1
  44. package/esm/commands/console.d.ts +0 -4
  45. package/esm/commands/console.js +0 -25
  46. package/esm/commands/console.js.map +0 -1
  47. package/esm/commands/create-plugin/create-plugin.d.ts +0 -2
  48. package/esm/commands/create-plugin/create-plugin.js +0 -29
  49. package/esm/commands/create-plugin/create-plugin.js.map +0 -1
  50. package/esm/commands/create-plugin/index.d.ts +0 -5
  51. package/esm/commands/create-plugin/index.js +0 -6
  52. package/esm/commands/create-plugin/index.js.map +0 -1
  53. package/esm/commands/create-plugin/resources/templates/package-json.d.ts +0 -11
  54. package/esm/commands/create-plugin/resources/templates/package-json.js +0 -11
  55. package/esm/commands/create-plugin/resources/templates/package-json.js.map +0 -1
  56. package/esm/commands/create-plugin/resources/templates/plugin.d.ts +0 -4
  57. package/esm/commands/create-plugin/resources/templates/plugin.js +0 -12
  58. package/esm/commands/create-plugin/resources/templates/plugin.js.map +0 -1
  59. package/esm/commands/db-sync.d.ts +0 -5
  60. package/esm/commands/db-sync.js +0 -25
  61. package/esm/commands/db-sync.js.map +0 -1
  62. package/esm/commands/index.d.ts +0 -3
  63. package/esm/commands/index.js +0 -26
  64. package/esm/commands/index.js.map +0 -1
  65. package/esm/commands/install.d.ts +0 -5
  66. package/esm/commands/install.js +0 -23
  67. package/esm/commands/install.js.map +0 -1
  68. package/esm/commands/start.d.ts +0 -5
  69. package/esm/commands/start.js +0 -23
  70. package/esm/commands/start.js.map +0 -1
  71. package/esm/helper.d.ts +0 -7
  72. package/esm/helper.js +0 -59
  73. package/esm/helper.js.map +0 -1
  74. package/esm/index.d.ts +0 -7
  75. package/esm/index.js +0 -9
  76. package/esm/index.js.map +0 -1
  77. package/esm/middlewares/data-wrapping.d.ts +0 -3
  78. package/esm/middlewares/data-wrapping.js +0 -54
  79. package/esm/middlewares/data-wrapping.js.map +0 -1
  80. package/esm/middlewares/index.d.ts +0 -2
  81. package/esm/middlewares/index.js +0 -3
  82. package/esm/middlewares/index.js.map +0 -1
  83. package/esm/middlewares/table2resource.d.ts +0 -6
  84. package/esm/middlewares/table2resource.js +0 -51
  85. package/esm/middlewares/table2resource.js.map +0 -1
  86. package/esm/plugin-manager.d.ts +0 -23
  87. package/esm/plugin-manager.js +0 -57
  88. package/esm/plugin-manager.js.map +0 -1
  89. package/esm/plugin.d.ts +0 -32
  90. package/esm/plugin.js +0 -43
  91. package/esm/plugin.js.map +0 -1
  92. package/esm/read-config.d.ts +0 -8
  93. package/esm/read-config.js +0 -63
  94. package/esm/read-config.js.map +0 -1
  95. package/lib/acl/available-action.js.map +0 -1
  96. package/lib/acl/index.js.map +0 -1
  97. package/lib/app-manager.js.map +0 -1
  98. package/lib/application.js.map +0 -1
  99. package/lib/commands/console.js.map +0 -1
  100. package/lib/commands/create-plugin/create-plugin.d.ts +0 -2
  101. package/lib/commands/create-plugin/create-plugin.js +0 -31
  102. package/lib/commands/create-plugin/create-plugin.js.map +0 -1
  103. package/lib/commands/create-plugin/index.d.ts +0 -5
  104. package/lib/commands/create-plugin/index.js +0 -8
  105. package/lib/commands/create-plugin/index.js.map +0 -1
  106. package/lib/commands/create-plugin/resources/templates/package-json.d.ts +0 -11
  107. package/lib/commands/create-plugin/resources/templates/package-json.js +0 -13
  108. package/lib/commands/create-plugin/resources/templates/package-json.js.map +0 -1
  109. package/lib/commands/create-plugin/resources/templates/plugin.d.ts +0 -4
  110. package/lib/commands/create-plugin/resources/templates/plugin.js +0 -33
  111. package/lib/commands/create-plugin/resources/templates/plugin.js.map +0 -1
  112. package/lib/commands/db-sync.js.map +0 -1
  113. package/lib/commands/index.js.map +0 -1
  114. package/lib/commands/install.js.map +0 -1
  115. package/lib/commands/start.js.map +0 -1
  116. package/lib/helper.js.map +0 -1
  117. package/lib/index.js.map +0 -1
  118. package/lib/middlewares/data-wrapping.js.map +0 -1
  119. package/lib/middlewares/index.js.map +0 -1
  120. package/lib/middlewares/table2resource.js.map +0 -1
  121. package/lib/plugin-manager.js.map +0 -1
  122. package/lib/plugin.js.map +0 -1
  123. package/lib/read-config.js.map +0 -1
  124. package/tsconfig.build.json +0 -9
@@ -1,156 +0,0 @@
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 { registerActions } from '@nocobase/actions';
11
- import { applyMixins, AsyncEmitter } from '@nocobase/utils';
12
- import Koa from 'koa';
13
- import { isBoolean } from 'lodash';
14
- import { createACL } from './acl';
15
- import { AppManager } from './app-manager';
16
- import { createCli } from './commands';
17
- import { createDatabase, createI18n, createResourcer, registerMiddlewares } from './helper';
18
- import { PluginManager } from './plugin-manager';
19
- export class Application extends Koa {
20
- constructor(options) {
21
- super();
22
- this.options = options;
23
- this.plugins = new Map();
24
- this.acl = createACL();
25
- this.db = createDatabase(options);
26
- this.resourcer = createResourcer(options);
27
- this.cli = createCli(this);
28
- this.i18n = createI18n(options);
29
- this.pm = new PluginManager({
30
- app: this,
31
- });
32
- this.appManager = new AppManager(this);
33
- registerMiddlewares(this, options);
34
- if (options.registerActions !== false) {
35
- registerActions(this);
36
- }
37
- this.loadPluginConfig(options.plugins || []);
38
- }
39
- plugin(pluginClass, options) {
40
- return this.pm.add(pluginClass, options);
41
- }
42
- loadPluginConfig(pluginsConfigurations) {
43
- for (let pluginConfiguration of pluginsConfigurations) {
44
- if (typeof pluginConfiguration == 'string') {
45
- pluginConfiguration = [pluginConfiguration, {}];
46
- }
47
- const plugin = PluginManager.resolvePlugin(pluginConfiguration[0]);
48
- const pluginOptions = pluginConfiguration[1];
49
- this.plugin(plugin, pluginOptions);
50
- }
51
- }
52
- use(middleware, options) {
53
- // @ts-ignore
54
- return super.use(middleware);
55
- }
56
- collection(options) {
57
- return this.db.collection(options);
58
- }
59
- resource(options) {
60
- return this.resourcer.define(options);
61
- }
62
- actions(handlers, options) {
63
- return this.resourcer.registerActions(handlers);
64
- }
65
- command(name, desc, opts) {
66
- return this.cli.command(name, desc, opts);
67
- }
68
- findCommand(name) {
69
- return this.cli._findCommand(name);
70
- }
71
- load() {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- yield this.pm.load();
74
- });
75
- }
76
- getPlugin(name) {
77
- return this.pm.get(name);
78
- }
79
- parse(argv = process.argv) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- yield this.load();
82
- return this.cli.parseAsync(argv);
83
- });
84
- }
85
- start(options) {
86
- var _a;
87
- return __awaiter(this, void 0, void 0, function* () {
88
- // reconnect database
89
- if (this.db.closed()) {
90
- yield this.db.reconnect();
91
- }
92
- yield this.emitAsync('beforeStart', this, options);
93
- if ((_a = options === null || options === void 0 ? void 0 : options.listen) === null || _a === void 0 ? void 0 : _a.port) {
94
- const listen = () => new Promise((resolve) => {
95
- const Server = this.listen(options === null || options === void 0 ? void 0 : options.listen, () => {
96
- resolve(Server);
97
- });
98
- });
99
- // @ts-ignore
100
- this.listenServer = yield listen();
101
- }
102
- yield this.emitAsync('afterStart', this, options);
103
- });
104
- }
105
- listen(...args) {
106
- return this.appManager.listen(...args);
107
- }
108
- stop(options) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- yield this.emitAsync('beforeStop', this, options);
111
- try {
112
- // close database connection
113
- // silent if database already closed
114
- yield this.db.close();
115
- }
116
- catch (e) {
117
- console.log(e);
118
- }
119
- // close http server
120
- if (this.listenServer) {
121
- const closeServer = () => new Promise((resolve, reject) => {
122
- this.listenServer.close((err) => {
123
- if (err) {
124
- return reject(err);
125
- }
126
- this.listenServer = null;
127
- resolve(true);
128
- });
129
- });
130
- yield closeServer();
131
- }
132
- yield this.emitAsync('afterStop', this, options);
133
- });
134
- }
135
- destroy(options) {
136
- return __awaiter(this, void 0, void 0, function* () {
137
- yield this.emitAsync('beforeDestroy', this, options);
138
- yield this.stop(options);
139
- yield this.emitAsync('afterDestroy', this, options);
140
- });
141
- }
142
- install(options) {
143
- return __awaiter(this, void 0, void 0, function* () {
144
- yield this.emitAsync('beforeInstall', this, options);
145
- if (options === null || options === void 0 ? void 0 : options.clean) {
146
- yield this.db.clean(isBoolean(options.clean) ? { drop: options.clean } : options.clean);
147
- }
148
- yield this.db.sync(options === null || options === void 0 ? void 0 : options.sync);
149
- yield this.pm.install(options);
150
- yield this.emitAsync('afterInstall', this, options);
151
- });
152
- }
153
- }
154
- applyMixins(Application, [AsyncEmitter]);
155
- export default Application;
156
- //# sourceMappingURL=application.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI5D,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE5F,OAAO,EAAkB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAgEjE,MAAM,OAAO,WAA8D,SAAQ,GAAG;IAmBpF,YAAmB,OAA2B;QAC5C,KAAK,EAAE,CAAC;QADS,YAAO,GAAP,OAAO,CAAoB;QAJpC,YAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAO5C,IAAI,CAAC,GAAG,GAAG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C","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"]}
@@ -1,4 +0,0 @@
1
- declare const _default: ({ app }: {
2
- app: any;
3
- }) => Promise<void>;
4
- export default _default;
@@ -1,25 +0,0 @@
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
@@ -1 +0,0 @@
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"]}
@@ -1,2 +0,0 @@
1
- declare const _default: (name: any) => Promise<void>;
2
- export default _default;
@@ -1,29 +0,0 @@
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
@@ -1 +0,0 @@
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"]}
@@ -1,5 +0,0 @@
1
- declare const _default: ({ app, cliArgs }: {
2
- app: any;
3
- cliArgs: any;
4
- }) => void;
5
- export default _default;
@@ -1,6 +0,0 @@
1
- const createPlugin = require('./create-plugin');
2
- export default ({ app, cliArgs }) => {
3
- const name = cliArgs[0];
4
- createPlugin(name);
5
- };
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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"]}
@@ -1,11 +0,0 @@
1
- declare const _default: ({ name }: {
2
- name: any;
3
- }) => {
4
- name: any;
5
- version: string;
6
- main: string;
7
- dependencies: {
8
- '@nocobase/server': string;
9
- };
10
- };
11
- export default _default;
@@ -1,11 +0,0 @@
1
- export default ({ name }) => {
2
- return {
3
- name: name,
4
- version: '0.1.0',
5
- main: 'server.js',
6
- dependencies: {
7
- '@nocobase/server': '^0.6.0-alpha.0',
8
- },
9
- };
10
- };
11
- //# sourceMappingURL=package-json.js.map
@@ -1 +0,0 @@
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"]}
@@ -1,4 +0,0 @@
1
- declare const _default: ({ name }: {
2
- name: any;
3
- }) => string;
4
- export default _default;
@@ -1,12 +0,0 @@
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
@@ -1 +0,0 @@
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"]}
@@ -1,5 +0,0 @@
1
- declare const _default: ({ app, cliArgs }: {
2
- app: any;
3
- cliArgs: any;
4
- }) => Promise<void>;
5
- export default _default;
@@ -1,25 +0,0 @@
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
@@ -1 +0,0 @@
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"]}
@@ -1,3 +0,0 @@
1
- import Application from '../application';
2
- import { Command } from 'commander';
3
- export declare function createCli(app: Application): Command;
@@ -1,26 +0,0 @@
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
@@ -1 +0,0 @@
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"]}
@@ -1,5 +0,0 @@
1
- declare const _default: ({ app, cliArgs }: {
2
- app: any;
3
- cliArgs: any;
4
- }) => Promise<void>;
5
- export default _default;
@@ -1,23 +0,0 @@
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
@@ -1 +0,0 @@
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"]}
@@ -1,5 +0,0 @@
1
- declare const _default: ({ app, cliArgs }: {
2
- app: any;
3
- cliArgs: any;
4
- }) => Promise<void>;
5
- export default _default;
@@ -1,23 +0,0 @@
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
@@ -1 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
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 DELETED
@@ -1,59 +0,0 @@
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
package/esm/helper.js.map DELETED
@@ -1 +0,0 @@
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;AA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AC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QAC9D,CAAC,CAAC;QACF,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC;QAChB,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;QAC9B,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9D,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;QAChB,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,MAAM,GAAG,GAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,MAAiB,IAAI,GAAG,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,CAAC;QACnF,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,EAAE;YACtB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;SAC1B;QACD,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,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 DELETED
@@ -1,7 +0,0 @@
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 DELETED
@@ -1,9 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
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"]}
@@ -1,3 +0,0 @@
1
- import { Context, Next } from '@nocobase/actions';
2
- export declare function dataWrapping(): (ctx: Context, next: Next) => Promise<void>;
3
- export default dataWrapping;