@nocobase/server 0.19.0-alpha.9 → 0.20.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/application.d.ts +9 -10
- package/lib/application.js +44 -24
- package/lib/commands/db-sync.js +5 -1
- package/lib/commands/start.js +1 -1
- package/lib/helper.d.ts +0 -2
- package/lib/helper.js +5 -15
- package/lib/helpers/multiple-instance-manager.d.ts +6 -0
- package/lib/helpers/multiple-instance-manager.js +40 -0
- package/lib/main-data-source.d.ts +4 -0
- package/lib/main-data-source.js +45 -0
- package/lib/middlewares/db2resource.js +11 -2
- package/package.json +14 -13
package/lib/application.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
/// <reference types="koa-bodyparser" />
|
|
4
|
-
import { ACL } from '@nocobase/acl';
|
|
5
3
|
import { AuthManager, AuthManagerOptions } from '@nocobase/auth';
|
|
6
4
|
import { Cache, CacheManager, CacheManagerOptions } from '@nocobase/cache';
|
|
7
5
|
import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
|
|
@@ -10,7 +8,7 @@ import { ResourceOptions, Resourcer } from '@nocobase/resourcer';
|
|
|
10
8
|
import { Telemetry, TelemetryOptions } from '@nocobase/telemetry';
|
|
11
9
|
import { AsyncEmitter, ToposortOptions } from '@nocobase/utils';
|
|
12
10
|
import { Command, CommandOptions, ParseOptions } from 'commander';
|
|
13
|
-
import { IncomingMessage,
|
|
11
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
14
12
|
import { i18n, InitOptions } from 'i18next';
|
|
15
13
|
import Koa, { DefaultContext as KoaDefaultContext, DefaultState as KoaDefaultState } from 'koa';
|
|
16
14
|
import { RecordableHistogram } from 'node:perf_hooks';
|
|
@@ -21,6 +19,7 @@ import { ApplicationVersion } from './helpers/application-version';
|
|
|
21
19
|
import { Locale } from './locale';
|
|
22
20
|
import { Plugin } from './plugin';
|
|
23
21
|
import { InstallOptions, PluginManager } from './plugin-manager';
|
|
22
|
+
import { DataSourceManager, SequelizeDataSource } from '@nocobase/data-source-manager';
|
|
24
23
|
export type PluginType = string | typeof Plugin;
|
|
25
24
|
export type PluginConfiguration = PluginType | [PluginType, any];
|
|
26
25
|
export interface ResourcerOptions {
|
|
@@ -84,7 +83,6 @@ export type MaintainingCommandStatus = {
|
|
|
84
83
|
};
|
|
85
84
|
export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {
|
|
86
85
|
options: ApplicationOptions;
|
|
87
|
-
listenServer: Server;
|
|
88
86
|
middleware: any;
|
|
89
87
|
stopped: boolean;
|
|
90
88
|
ready: boolean;
|
|
@@ -110,12 +108,11 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
110
108
|
get maintainingMessage(): string;
|
|
111
109
|
protected _cronJobManager: CronJobManager;
|
|
112
110
|
get cronJobManager(): CronJobManager;
|
|
113
|
-
|
|
111
|
+
get mainDataSource(): SequelizeDataSource;
|
|
114
112
|
get db(): Database;
|
|
115
113
|
protected _logger: SystemLogger;
|
|
116
114
|
get logger(): SystemLogger;
|
|
117
|
-
|
|
118
|
-
get resourcer(): Resourcer;
|
|
115
|
+
get resourcer(): import("@nocobase/data-source-manager").ResourceManager;
|
|
119
116
|
protected _cacheManager: CacheManager;
|
|
120
117
|
get cacheManager(): CacheManager;
|
|
121
118
|
protected _cache: Cache;
|
|
@@ -127,8 +124,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
127
124
|
get i18n(): i18n;
|
|
128
125
|
protected _pm: PluginManager;
|
|
129
126
|
get pm(): PluginManager;
|
|
130
|
-
|
|
131
|
-
get acl(): ACL;
|
|
127
|
+
get acl(): import("@nocobase/acl").ACL;
|
|
132
128
|
protected _authManager: AuthManager;
|
|
133
129
|
get authManager(): AuthManager;
|
|
134
130
|
protected _locales: Locale;
|
|
@@ -140,7 +136,8 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
140
136
|
get version(): ApplicationVersion;
|
|
141
137
|
get log(): SystemLogger;
|
|
142
138
|
get name(): string;
|
|
143
|
-
|
|
139
|
+
protected _dataSourceManager: DataSourceManager;
|
|
140
|
+
get dataSourceManager(): DataSourceManager;
|
|
144
141
|
getMaintaining(): MaintainingCommandStatus;
|
|
145
142
|
setMaintaining(_maintainingCommandStatus: MaintainingCommandStatus): void;
|
|
146
143
|
setMaintainingMessage(message: string): void;
|
|
@@ -167,6 +164,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
167
164
|
parse(argv?: string[]): Promise<AppCommand>;
|
|
168
165
|
authenticate(): Promise<void>;
|
|
169
166
|
runCommand(command: string, ...args: any[]): Promise<AppCommand>;
|
|
167
|
+
runCommandThrowError(command: string, ...args: any[]): Promise<AppCommand>;
|
|
170
168
|
createCli(): AppCommand;
|
|
171
169
|
loadMigrations(options: any): Promise<{
|
|
172
170
|
beforeLoad: any[];
|
|
@@ -206,6 +204,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
206
204
|
reInitEvents(): void;
|
|
207
205
|
createLogger(options: LoggerOptions): import("winston").Logger;
|
|
208
206
|
protected init(): void;
|
|
207
|
+
protected createMainDataSource(options: ApplicationOptions): void;
|
|
209
208
|
protected createDatabase(options: ApplicationOptions): Database;
|
|
210
209
|
}
|
|
211
210
|
export default Application;
|
package/lib/application.js
CHANGED
|
@@ -45,7 +45,7 @@ var import_koa_compose = __toESM(require("koa-compose"));
|
|
|
45
45
|
var import_lodash = __toESM(require("lodash"));
|
|
46
46
|
var import_path = require("path");
|
|
47
47
|
var import_semver = __toESM(require("semver"));
|
|
48
|
-
var
|
|
48
|
+
var import_acl = require("./acl");
|
|
49
49
|
var import_app_command = require("./app-command");
|
|
50
50
|
var import_app_supervisor = require("./app-supervisor");
|
|
51
51
|
var import_cache2 = require("./cache");
|
|
@@ -56,7 +56,9 @@ var import_helper = require("./helper");
|
|
|
56
56
|
var import_application_version = require("./helpers/application-version");
|
|
57
57
|
var import_locale = require("./locale");
|
|
58
58
|
var import_plugin_manager = require("./plugin-manager");
|
|
59
|
+
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
59
60
|
var import_package = __toESM(require("../package.json"));
|
|
61
|
+
var import_main_data_source = require("./main-data-source");
|
|
60
62
|
const _Application = class _Application extends import_koa.default {
|
|
61
63
|
constructor(options) {
|
|
62
64
|
super();
|
|
@@ -66,7 +68,6 @@ const _Application = class _Application extends import_koa.default {
|
|
|
66
68
|
this.init();
|
|
67
69
|
this._appSupervisor.addApp(this);
|
|
68
70
|
}
|
|
69
|
-
listenServer;
|
|
70
71
|
stopped = false;
|
|
71
72
|
ready = false;
|
|
72
73
|
rawOptions;
|
|
@@ -93,17 +94,22 @@ const _Application = class _Application extends import_koa.default {
|
|
|
93
94
|
get cronJobManager() {
|
|
94
95
|
return this._cronJobManager;
|
|
95
96
|
}
|
|
96
|
-
|
|
97
|
+
get mainDataSource() {
|
|
98
|
+
var _a;
|
|
99
|
+
return (_a = this.dataSourceManager) == null ? void 0 : _a.dataSources.get("main");
|
|
100
|
+
}
|
|
97
101
|
get db() {
|
|
98
|
-
|
|
102
|
+
if (!this.mainDataSource) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return this.mainDataSource.collectionManager.db;
|
|
99
106
|
}
|
|
100
107
|
_logger;
|
|
101
108
|
get logger() {
|
|
102
109
|
return this._logger;
|
|
103
110
|
}
|
|
104
|
-
_resourcer;
|
|
105
111
|
get resourcer() {
|
|
106
|
-
return this.
|
|
112
|
+
return this.mainDataSource.resourceManager;
|
|
107
113
|
}
|
|
108
114
|
_cacheManager;
|
|
109
115
|
get cacheManager() {
|
|
@@ -128,9 +134,8 @@ const _Application = class _Application extends import_koa.default {
|
|
|
128
134
|
get pm() {
|
|
129
135
|
return this._pm;
|
|
130
136
|
}
|
|
131
|
-
_acl;
|
|
132
137
|
get acl() {
|
|
133
|
-
return this.
|
|
138
|
+
return this.mainDataSource.acl;
|
|
134
139
|
}
|
|
135
140
|
_authManager;
|
|
136
141
|
get authManager() {
|
|
@@ -157,8 +162,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
157
162
|
get name() {
|
|
158
163
|
return this.options.name || "main";
|
|
159
164
|
}
|
|
160
|
-
|
|
161
|
-
|
|
165
|
+
_dataSourceManager;
|
|
166
|
+
get dataSourceManager() {
|
|
167
|
+
return this._dataSourceManager;
|
|
162
168
|
}
|
|
163
169
|
getMaintaining() {
|
|
164
170
|
return this._maintainingCommandStatus;
|
|
@@ -231,7 +237,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
231
237
|
if (this.telemetry.started) {
|
|
232
238
|
await this.telemetry.shutdown();
|
|
233
239
|
}
|
|
234
|
-
const oldDb = this.
|
|
240
|
+
const oldDb = this.db;
|
|
235
241
|
this.init();
|
|
236
242
|
if (!oldDb.closed()) {
|
|
237
243
|
await oldDb.close();
|
|
@@ -252,7 +258,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
252
258
|
if (this.telemetry.started) {
|
|
253
259
|
await this.telemetry.shutdown();
|
|
254
260
|
}
|
|
255
|
-
const oldDb = this.
|
|
261
|
+
const oldDb = this.db;
|
|
256
262
|
this.init();
|
|
257
263
|
if (!oldDb.closed()) {
|
|
258
264
|
await oldDb.close();
|
|
@@ -271,6 +277,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
271
277
|
this.telemetry.start();
|
|
272
278
|
}
|
|
273
279
|
await this.pm.load(options);
|
|
280
|
+
if (options == null ? void 0 : options.sync) {
|
|
281
|
+
await this.db.sync();
|
|
282
|
+
}
|
|
274
283
|
this.setMaintainingMessage("emit afterLoad");
|
|
275
284
|
if ((options == null ? void 0 : options.hooks) !== false) {
|
|
276
285
|
await this.emitAsync("afterLoad", this, options);
|
|
@@ -311,6 +320,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
311
320
|
async runCommand(command, ...args) {
|
|
312
321
|
return await this.runAsCLI([command, ...args], { from: "user" });
|
|
313
322
|
}
|
|
323
|
+
async runCommandThrowError(command, ...args) {
|
|
324
|
+
return await this.runAsCLI([command, ...args], { from: "user", throwError: true });
|
|
325
|
+
}
|
|
314
326
|
createCli() {
|
|
315
327
|
const command = new import_app_command.AppCommand("nocobase").usage("[command] [options]").hook("preAction", async (_, actionCommand) => {
|
|
316
328
|
this._actionCommand = actionCommand;
|
|
@@ -591,8 +603,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
591
603
|
await this.pm.initOtherPlugins();
|
|
592
604
|
const migrator3 = await this.pm.loadOtherMigrations();
|
|
593
605
|
await migrator3.beforeLoad.up();
|
|
594
|
-
await this.load();
|
|
595
|
-
await this.db.sync();
|
|
606
|
+
await this.load({ sync: true });
|
|
596
607
|
await migrator3.afterSync.up();
|
|
597
608
|
await this.pm.upgrade();
|
|
598
609
|
await migrator1.afterLoad.up();
|
|
@@ -641,17 +652,15 @@ const _Application = class _Application extends import_koa.default {
|
|
|
641
652
|
this.reInitEvents();
|
|
642
653
|
this.middleware = new import_utils.Toposort();
|
|
643
654
|
this.plugins = /* @__PURE__ */ new Map();
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
if (this._db) {
|
|
647
|
-
this._db.removeAllListeners();
|
|
655
|
+
if (this.db) {
|
|
656
|
+
this.db.removeAllListeners();
|
|
648
657
|
}
|
|
649
|
-
this.
|
|
650
|
-
this.
|
|
658
|
+
this.createMainDataSource(options);
|
|
659
|
+
this._cronJobManager = new import_cron_job_manager.CronJobManager(this);
|
|
651
660
|
this._cli = this.createCli();
|
|
652
661
|
this._i18n = (0, import_helper.createI18n)(options);
|
|
653
|
-
this.context.db = this.
|
|
654
|
-
this.context.resourcer = this.
|
|
662
|
+
this.context.db = this.db;
|
|
663
|
+
this.context.resourcer = this.resourcer;
|
|
655
664
|
this.context.cacheManager = this._cacheManager;
|
|
656
665
|
this.context.cache = this._cache;
|
|
657
666
|
const plugins = this._pm ? this._pm.options.plugins : options.plugins;
|
|
@@ -673,9 +682,10 @@ const _Application = class _Application extends import_koa.default {
|
|
|
673
682
|
name: "auth",
|
|
674
683
|
actions: import_auth.actions
|
|
675
684
|
});
|
|
676
|
-
this.
|
|
685
|
+
this._dataSourceManager.use(this._authManager.middleware(), { tag: "auth" });
|
|
686
|
+
this.resourcer.use(this._authManager.middleware(), { tag: "auth" });
|
|
677
687
|
if (this.options.acl !== false) {
|
|
678
|
-
this.
|
|
688
|
+
this.resourcer.use(this.acl.middleware(), { tag: "acl", after: ["auth"] });
|
|
679
689
|
}
|
|
680
690
|
this._locales = new import_locale.Locale((0, import_helper.createAppProxy)(this));
|
|
681
691
|
if (options.perfHooks) {
|
|
@@ -688,6 +698,16 @@ const _Application = class _Application extends import_koa.default {
|
|
|
688
698
|
(0, import_commands.registerCli)(this);
|
|
689
699
|
this._version = new import_application_version.ApplicationVersion(this);
|
|
690
700
|
}
|
|
701
|
+
createMainDataSource(options) {
|
|
702
|
+
const mainDataSourceInstance = new import_main_data_source.MainDataSource({
|
|
703
|
+
name: "main",
|
|
704
|
+
database: this.createDatabase(options),
|
|
705
|
+
acl: (0, import_acl.createACL)(),
|
|
706
|
+
resourceManager: (0, import_helper.createResourcer)(options)
|
|
707
|
+
});
|
|
708
|
+
this._dataSourceManager = new import_data_source_manager.DataSourceManager();
|
|
709
|
+
this.dataSourceManager.dataSources.set("main", mainDataSourceInstance);
|
|
710
|
+
}
|
|
691
711
|
createDatabase(options) {
|
|
692
712
|
const sqlLogger = this.createLogger({
|
|
693
713
|
filename: "sql",
|
package/lib/commands/db-sync.js
CHANGED
|
@@ -22,9 +22,13 @@ __export(db_sync_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(db_sync_exports);
|
|
24
24
|
var db_sync_default = /* @__PURE__ */ __name((app) => {
|
|
25
|
-
app.command("db:sync").auth().action(async (...cliArgs) => {
|
|
25
|
+
app.command("db:sync").auth().preload().action(async (...cliArgs) => {
|
|
26
26
|
const [opts] = cliArgs;
|
|
27
27
|
console.log("db sync...");
|
|
28
|
+
const Collection = app.db.getCollection("collections");
|
|
29
|
+
if (Collection) {
|
|
30
|
+
await Collection.repository.load();
|
|
31
|
+
}
|
|
28
32
|
const force = false;
|
|
29
33
|
await app.db.sync({
|
|
30
34
|
force,
|
package/lib/commands/start.js
CHANGED
|
@@ -25,7 +25,7 @@ var import_application_not_install = require("../errors/application-not-install"
|
|
|
25
25
|
var start_default = /* @__PURE__ */ __name((app) => {
|
|
26
26
|
app.command("start").auth().option("--db-sync").option("--quickstart").action(async (...cliArgs) => {
|
|
27
27
|
const [options] = cliArgs;
|
|
28
|
-
console.log("options", options);
|
|
28
|
+
console.log("start options", options);
|
|
29
29
|
if (options.quickstart) {
|
|
30
30
|
if (await app.isInstalled()) {
|
|
31
31
|
await app.upgrade();
|
package/lib/helper.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import Database from '@nocobase/database';
|
|
2
1
|
import { Resourcer } from '@nocobase/resourcer';
|
|
3
2
|
import { Command } from 'commander';
|
|
4
3
|
import Application, { ApplicationOptions } from './application';
|
|
5
4
|
export declare function createI18n(options: ApplicationOptions): import("i18next").i18n;
|
|
6
|
-
export declare function createDatabase(options: ApplicationOptions): Database;
|
|
7
5
|
export declare function createResourcer(options: ApplicationOptions): Resourcer;
|
|
8
6
|
export declare function registerMiddlewares(app: Application, options: ApplicationOptions): void;
|
|
9
7
|
export declare const createAppProxy: (app: Application) => Application<import("./application").DefaultState, import("./application").DefaultContext>;
|
package/lib/helper.js
CHANGED
|
@@ -29,7 +29,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var helper_exports = {};
|
|
30
30
|
__export(helper_exports, {
|
|
31
31
|
createAppProxy: () => createAppProxy,
|
|
32
|
-
createDatabase: () => createDatabase,
|
|
33
32
|
createI18n: () => createI18n,
|
|
34
33
|
createResourcer: () => createResourcer,
|
|
35
34
|
enablePerfHooks: () => enablePerfHooks,
|
|
@@ -39,21 +38,20 @@ __export(helper_exports, {
|
|
|
39
38
|
});
|
|
40
39
|
module.exports = __toCommonJS(helper_exports);
|
|
41
40
|
var import_cors = __toESM(require("@koa/cors"));
|
|
42
|
-
var
|
|
41
|
+
var import_logger = require("@nocobase/logger");
|
|
43
42
|
var import_resourcer = require("@nocobase/resourcer");
|
|
44
43
|
var import_utils = require("@nocobase/utils");
|
|
44
|
+
var import_crypto = require("crypto");
|
|
45
45
|
var import_fs = __toESM(require("fs"));
|
|
46
46
|
var import_i18next = __toESM(require("i18next"));
|
|
47
47
|
var import_koa_bodyparser = __toESM(require("koa-bodyparser"));
|
|
48
48
|
var import_path = require("path");
|
|
49
|
+
var import_perf_hooks = require("perf_hooks");
|
|
49
50
|
var import_middlewares = require("./middlewares");
|
|
50
51
|
var import_data_template = require("./middlewares/data-template");
|
|
51
52
|
var import_data_wrapping = require("./middlewares/data-wrapping");
|
|
52
53
|
var import_db2resource = require("./middlewares/db2resource");
|
|
53
54
|
var import_i18n = require("./middlewares/i18n");
|
|
54
|
-
var import_logger = require("@nocobase/logger");
|
|
55
|
-
var import_crypto = require("crypto");
|
|
56
|
-
var import_perf_hooks = require("perf_hooks");
|
|
57
55
|
function createI18n(options) {
|
|
58
56
|
const instance = import_i18next.default.createInstance();
|
|
59
57
|
instance.init({
|
|
@@ -66,14 +64,6 @@ function createI18n(options) {
|
|
|
66
64
|
return instance;
|
|
67
65
|
}
|
|
68
66
|
__name(createI18n, "createI18n");
|
|
69
|
-
function createDatabase(options) {
|
|
70
|
-
if (options.database instanceof import_database.default) {
|
|
71
|
-
return options.database;
|
|
72
|
-
} else {
|
|
73
|
-
return new import_database.default(options.database);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
__name(createDatabase, "createDatabase");
|
|
77
67
|
function createResourcer(options) {
|
|
78
68
|
return new import_resourcer.Resourcer({ ...options.resourcer });
|
|
79
69
|
}
|
|
@@ -127,7 +117,8 @@ function registerMiddlewares(app, options) {
|
|
|
127
117
|
});
|
|
128
118
|
app.resourcer.use(import_data_template.dateTemplate, { tag: "dateTemplate", after: "acl" });
|
|
129
119
|
app.use(import_db2resource.db2resource, { tag: "db2resource", after: "dataWrapping" });
|
|
130
|
-
app.use(app.resourcer.restApiMiddleware(), { tag: "restApi", after: "db2resource" });
|
|
120
|
+
app.use(app.resourcer.restApiMiddleware({ skipIfDataSourceExists: true }), { tag: "restApi", after: "db2resource" });
|
|
121
|
+
app.use(app.dataSourceManager.middleware(), { tag: "dataSource", after: "restApi" });
|
|
131
122
|
}
|
|
132
123
|
__name(registerMiddlewares, "registerMiddlewares");
|
|
133
124
|
const createAppProxy = /* @__PURE__ */ __name((app) => {
|
|
@@ -192,7 +183,6 @@ const enablePerfHooks = /* @__PURE__ */ __name((app) => {
|
|
|
192
183
|
// Annotate the CommonJS export names for ESM import in node:
|
|
193
184
|
0 && (module.exports = {
|
|
194
185
|
createAppProxy,
|
|
195
|
-
createDatabase,
|
|
196
186
|
createI18n,
|
|
197
187
|
createResourcer,
|
|
198
188
|
enablePerfHooks,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var multiple_instance_manager_exports = {};
|
|
20
|
+
__export(multiple_instance_manager_exports, {
|
|
21
|
+
MultipleInstanceManager: () => MultipleInstanceManager
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(multiple_instance_manager_exports);
|
|
24
|
+
const _MultipleInstanceManager = class _MultipleInstanceManager {
|
|
25
|
+
map = /* @__PURE__ */ new Map();
|
|
26
|
+
constructor() {
|
|
27
|
+
}
|
|
28
|
+
get(key) {
|
|
29
|
+
return this.map.get(key);
|
|
30
|
+
}
|
|
31
|
+
set(key, value) {
|
|
32
|
+
this.map.set(key, value);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
__name(_MultipleInstanceManager, "MultipleInstanceManager");
|
|
36
|
+
let MultipleInstanceManager = _MultipleInstanceManager;
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
MultipleInstanceManager
|
|
40
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var main_data_source_exports = {};
|
|
20
|
+
__export(main_data_source_exports, {
|
|
21
|
+
MainDataSource: () => MainDataSource
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(main_data_source_exports);
|
|
24
|
+
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
25
|
+
const _MainDataSource = class _MainDataSource extends import_data_source_manager.SequelizeDataSource {
|
|
26
|
+
init(options = {}) {
|
|
27
|
+
const { acl, resourceManager, database } = options;
|
|
28
|
+
this.acl = acl;
|
|
29
|
+
this.resourceManager = resourceManager;
|
|
30
|
+
this.collectionManager = this.createCollectionManager({
|
|
31
|
+
collectionManager: {
|
|
32
|
+
database,
|
|
33
|
+
collectionsFilter: (collection) => {
|
|
34
|
+
return collection.options.loadedFromCollectionManager;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
__name(_MainDataSource, "MainDataSource");
|
|
41
|
+
let MainDataSource = _MainDataSource;
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
MainDataSource
|
|
45
|
+
});
|
|
@@ -23,7 +23,11 @@ __export(db2resource_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(db2resource_exports);
|
|
25
25
|
var import_resourcer = require("@nocobase/resourcer");
|
|
26
|
-
function db2resource(ctx, next) {
|
|
26
|
+
async function db2resource(ctx, next) {
|
|
27
|
+
const dataSource = ctx.get("x-data-source");
|
|
28
|
+
if (dataSource) {
|
|
29
|
+
return next();
|
|
30
|
+
}
|
|
27
31
|
const resourcer = ctx.resourcer;
|
|
28
32
|
const database = ctx.db;
|
|
29
33
|
const params = (0, import_resourcer.parseRequest)(
|
|
@@ -43,7 +47,12 @@ function db2resource(ctx, next) {
|
|
|
43
47
|
if (resourcer.isDefined(resourceName)) {
|
|
44
48
|
return next();
|
|
45
49
|
}
|
|
46
|
-
const
|
|
50
|
+
const splitResult = resourceName.split(".");
|
|
51
|
+
let collectionName = splitResult[0];
|
|
52
|
+
const fieldName = splitResult[1];
|
|
53
|
+
if (collectionName.includes("@")) {
|
|
54
|
+
collectionName = collectionName.split("@")[1];
|
|
55
|
+
}
|
|
47
56
|
if (!database.hasCollection(collectionName)) {
|
|
48
57
|
return next();
|
|
49
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0-alpha.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -10,17 +10,18 @@
|
|
|
10
10
|
"@koa/cors": "^3.1.0",
|
|
11
11
|
"@koa/multer": "^3.0.2",
|
|
12
12
|
"@koa/router": "^9.4.0",
|
|
13
|
-
"@nocobase/acl": "0.
|
|
14
|
-
"@nocobase/actions": "0.
|
|
15
|
-
"@nocobase/auth": "0.
|
|
16
|
-
"@nocobase/cache": "0.
|
|
17
|
-
"@nocobase/
|
|
18
|
-
"@nocobase/
|
|
19
|
-
"@nocobase/
|
|
20
|
-
"@nocobase/
|
|
21
|
-
"@nocobase/
|
|
22
|
-
"@nocobase/
|
|
23
|
-
"@nocobase/
|
|
13
|
+
"@nocobase/acl": "0.20.0-alpha.2",
|
|
14
|
+
"@nocobase/actions": "0.20.0-alpha.2",
|
|
15
|
+
"@nocobase/auth": "0.20.0-alpha.2",
|
|
16
|
+
"@nocobase/cache": "0.20.0-alpha.2",
|
|
17
|
+
"@nocobase/data-source-manager": "0.20.0-alpha.2",
|
|
18
|
+
"@nocobase/database": "0.20.0-alpha.2",
|
|
19
|
+
"@nocobase/evaluators": "0.20.0-alpha.2",
|
|
20
|
+
"@nocobase/logger": "0.20.0-alpha.2",
|
|
21
|
+
"@nocobase/resourcer": "0.20.0-alpha.2",
|
|
22
|
+
"@nocobase/sdk": "0.20.0-alpha.2",
|
|
23
|
+
"@nocobase/telemetry": "0.20.0-alpha.2",
|
|
24
|
+
"@nocobase/utils": "0.20.0-alpha.2",
|
|
24
25
|
"@types/decompress": "4.2.4",
|
|
25
26
|
"@types/ini": "^1.3.31",
|
|
26
27
|
"@types/koa-send": "^4.1.3",
|
|
@@ -53,5 +54,5 @@
|
|
|
53
54
|
"@types/serve-handler": "^6.1.1",
|
|
54
55
|
"@types/ws": "^8.5.5"
|
|
55
56
|
},
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "6fb885dfc3554e4b0f29e9a7a1eecbbe85d0eebb"
|
|
57
58
|
}
|