@tachybase/module-multi-app 0.23.40 → 0.23.47
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/dist/client/AppNameInput.d.ts +1 -1
- package/dist/externalVersion.js +6 -6
- package/dist/node_modules/mariadb/package.json +1 -1
- package/dist/node_modules/qs/.editorconfig +46 -0
- package/dist/node_modules/qs/.eslintrc +39 -0
- package/dist/node_modules/qs/.github/FUNDING.yml +12 -0
- package/dist/node_modules/qs/.nycrc +13 -0
- package/dist/node_modules/qs/dist/qs.js +90 -0
- package/dist/node_modules/qs/lib/formats.js +23 -0
- package/dist/node_modules/qs/lib/index.js +1 -0
- package/dist/node_modules/qs/lib/parse.js +297 -0
- package/dist/node_modules/qs/lib/stringify.js +356 -0
- package/dist/node_modules/qs/lib/utils.js +268 -0
- package/dist/node_modules/qs/package.json +1 -0
- package/dist/node_modules/qs/test/empty-keys-cases.js +267 -0
- package/dist/node_modules/qs/test/parse.js +1187 -0
- package/dist/node_modules/qs/test/stringify.js +1306 -0
- package/dist/node_modules/qs/test/utils.js +150 -0
- package/dist/server/middlewares/app-selector.d.ts +1 -1
- package/dist/server/middlewares/app-selector.js +27 -2
- package/dist/server/migrations/20240820153000-add-apps-tmpl.js +4 -1
- package/dist/server/migrations/20241126124904-add-createdBy.js +6 -3
- package/dist/server/server.d.ts +5 -0
- package/dist/server/server.js +23 -18
- package/package.json +11 -9
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var test = require('tape');
|
|
4
|
+
var inspect = require('object-inspect');
|
|
5
|
+
var SaferBuffer = require('safer-buffer').Buffer;
|
|
6
|
+
var forEach = require('for-each');
|
|
7
|
+
var utils = require('../lib/utils');
|
|
8
|
+
|
|
9
|
+
test('merge()', function (t) {
|
|
10
|
+
t.deepEqual(utils.merge(null, true), [null, true], 'merges true into null');
|
|
11
|
+
|
|
12
|
+
t.deepEqual(utils.merge(null, [42]), [null, 42], 'merges null into an array');
|
|
13
|
+
|
|
14
|
+
t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key');
|
|
15
|
+
|
|
16
|
+
var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } });
|
|
17
|
+
t.deepEqual(oneMerged, { foo: ['bar', { first: '123' }] }, 'merges a standalone and an object into an array');
|
|
18
|
+
|
|
19
|
+
var twoMerged = utils.merge({ foo: ['bar', { first: '123' }] }, { foo: { second: '456' } });
|
|
20
|
+
t.deepEqual(twoMerged, { foo: { 0: 'bar', 1: { first: '123' }, second: '456' } }, 'merges a standalone and two objects into an array');
|
|
21
|
+
|
|
22
|
+
var sandwiched = utils.merge({ foo: ['bar', { first: '123', second: '456' }] }, { foo: 'baz' });
|
|
23
|
+
t.deepEqual(sandwiched, { foo: ['bar', { first: '123', second: '456' }, 'baz'] }, 'merges an object sandwiched by two standalones into an array');
|
|
24
|
+
|
|
25
|
+
var nestedArrays = utils.merge({ foo: ['baz'] }, { foo: ['bar', 'xyzzy'] });
|
|
26
|
+
t.deepEqual(nestedArrays, { foo: ['baz', 'bar', 'xyzzy'] });
|
|
27
|
+
|
|
28
|
+
var noOptionsNonObjectSource = utils.merge({ foo: 'baz' }, 'bar');
|
|
29
|
+
t.deepEqual(noOptionsNonObjectSource, { foo: 'baz', bar: true });
|
|
30
|
+
|
|
31
|
+
var func = function f() {};
|
|
32
|
+
t.deepEqual(
|
|
33
|
+
utils.merge(func, { foo: 'bar' }),
|
|
34
|
+
[func, { foo: 'bar' }],
|
|
35
|
+
'functions can not be merged into'
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
func.bar = 'baz';
|
|
39
|
+
t.deepEqual(
|
|
40
|
+
utils.merge({ foo: 'bar' }, func),
|
|
41
|
+
{ foo: 'bar', bar: 'baz' },
|
|
42
|
+
'functions can be merge sources'
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
t.test(
|
|
46
|
+
'avoids invoking array setters unnecessarily',
|
|
47
|
+
{ skip: typeof Object.defineProperty !== 'function' },
|
|
48
|
+
function (st) {
|
|
49
|
+
var setCount = 0;
|
|
50
|
+
var getCount = 0;
|
|
51
|
+
var observed = [];
|
|
52
|
+
Object.defineProperty(observed, 0, {
|
|
53
|
+
get: function () {
|
|
54
|
+
getCount += 1;
|
|
55
|
+
return { bar: 'baz' };
|
|
56
|
+
},
|
|
57
|
+
set: function () { setCount += 1; }
|
|
58
|
+
});
|
|
59
|
+
utils.merge(observed, [null]);
|
|
60
|
+
st.equal(setCount, 0);
|
|
61
|
+
st.equal(getCount, 1);
|
|
62
|
+
observed[0] = observed[0]; // eslint-disable-line no-self-assign
|
|
63
|
+
st.equal(setCount, 1);
|
|
64
|
+
st.equal(getCount, 2);
|
|
65
|
+
st.end();
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
t.end();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('assign()', function (t) {
|
|
73
|
+
var target = { a: 1, b: 2 };
|
|
74
|
+
var source = { b: 3, c: 4 };
|
|
75
|
+
var result = utils.assign(target, source);
|
|
76
|
+
|
|
77
|
+
t.equal(result, target, 'returns the target');
|
|
78
|
+
t.deepEqual(target, { a: 1, b: 3, c: 4 }, 'target and source are merged');
|
|
79
|
+
t.deepEqual(source, { b: 3, c: 4 }, 'source is untouched');
|
|
80
|
+
|
|
81
|
+
t.end();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('combine()', function (t) {
|
|
85
|
+
t.test('both arrays', function (st) {
|
|
86
|
+
var a = [1];
|
|
87
|
+
var b = [2];
|
|
88
|
+
var combined = utils.combine(a, b);
|
|
89
|
+
|
|
90
|
+
st.deepEqual(a, [1], 'a is not mutated');
|
|
91
|
+
st.deepEqual(b, [2], 'b is not mutated');
|
|
92
|
+
st.notEqual(a, combined, 'a !== combined');
|
|
93
|
+
st.notEqual(b, combined, 'b !== combined');
|
|
94
|
+
st.deepEqual(combined, [1, 2], 'combined is a + b');
|
|
95
|
+
|
|
96
|
+
st.end();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
t.test('one array, one non-array', function (st) {
|
|
100
|
+
var aN = 1;
|
|
101
|
+
var a = [aN];
|
|
102
|
+
var bN = 2;
|
|
103
|
+
var b = [bN];
|
|
104
|
+
|
|
105
|
+
var combinedAnB = utils.combine(aN, b);
|
|
106
|
+
st.deepEqual(b, [bN], 'b is not mutated');
|
|
107
|
+
st.notEqual(aN, combinedAnB, 'aN + b !== aN');
|
|
108
|
+
st.notEqual(a, combinedAnB, 'aN + b !== a');
|
|
109
|
+
st.notEqual(bN, combinedAnB, 'aN + b !== bN');
|
|
110
|
+
st.notEqual(b, combinedAnB, 'aN + b !== b');
|
|
111
|
+
st.deepEqual([1, 2], combinedAnB, 'first argument is array-wrapped when not an array');
|
|
112
|
+
|
|
113
|
+
var combinedABn = utils.combine(a, bN);
|
|
114
|
+
st.deepEqual(a, [aN], 'a is not mutated');
|
|
115
|
+
st.notEqual(aN, combinedABn, 'a + bN !== aN');
|
|
116
|
+
st.notEqual(a, combinedABn, 'a + bN !== a');
|
|
117
|
+
st.notEqual(bN, combinedABn, 'a + bN !== bN');
|
|
118
|
+
st.notEqual(b, combinedABn, 'a + bN !== b');
|
|
119
|
+
st.deepEqual([1, 2], combinedABn, 'second argument is array-wrapped when not an array');
|
|
120
|
+
|
|
121
|
+
st.end();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
t.test('neither is an array', function (st) {
|
|
125
|
+
var combined = utils.combine(1, 2);
|
|
126
|
+
st.notEqual(1, combined, '1 + 2 !== 1');
|
|
127
|
+
st.notEqual(2, combined, '1 + 2 !== 2');
|
|
128
|
+
st.deepEqual([1, 2], combined, 'both arguments are array-wrapped when not an array');
|
|
129
|
+
|
|
130
|
+
st.end();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
t.end();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('isBuffer()', function (t) {
|
|
137
|
+
forEach([null, undefined, true, false, '', 'abc', 42, 0, NaN, {}, [], function () {}, /a/g], function (x) {
|
|
138
|
+
t.equal(utils.isBuffer(x), false, inspect(x) + ' is not a buffer');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
var fakeBuffer = { constructor: Buffer };
|
|
142
|
+
t.equal(utils.isBuffer(fakeBuffer), false, 'fake buffer is not a buffer');
|
|
143
|
+
|
|
144
|
+
var saferBuffer = SaferBuffer.from('abc');
|
|
145
|
+
t.equal(utils.isBuffer(saferBuffer), true, 'SaferBuffer instance is a buffer');
|
|
146
|
+
|
|
147
|
+
var buffer = Buffer.from && Buffer.alloc ? Buffer.from('abc') : new Buffer('abc');
|
|
148
|
+
t.equal(utils.isBuffer(buffer), true, 'real Buffer instance is a buffer');
|
|
149
|
+
t.end();
|
|
150
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function appSelectorMiddleware(app: any): (ctx: any, next: any) => Promise<
|
|
1
|
+
export declare function appSelectorMiddleware(app: any): (ctx: any, next: any) => Promise<any>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,16 +16,39 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
var app_selector_exports = {};
|
|
19
29
|
__export(app_selector_exports, {
|
|
20
30
|
appSelectorMiddleware: () => appSelectorMiddleware
|
|
21
31
|
});
|
|
22
32
|
module.exports = __toCommonJS(app_selector_exports);
|
|
33
|
+
var import_qs = __toESM(require("qs"));
|
|
23
34
|
function appSelectorMiddleware(app) {
|
|
24
35
|
return async (ctx, next) => {
|
|
25
36
|
const { req } = ctx;
|
|
26
|
-
|
|
37
|
+
let subAppName;
|
|
38
|
+
if (!ctx.resolvedAppName) {
|
|
39
|
+
if (req.headers["x-hostname"]) {
|
|
40
|
+
subAppName = req.headers["x-hostname"];
|
|
41
|
+
} else {
|
|
42
|
+
const url = req.url;
|
|
43
|
+
const [path, query] = url.split("?");
|
|
44
|
+
if (path === "/ws" && query) {
|
|
45
|
+
const queryObj = import_qs.default.parse(query);
|
|
46
|
+
subAppName = queryObj.__hostname;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!subAppName) {
|
|
50
|
+
return next();
|
|
51
|
+
}
|
|
27
52
|
const repository = app.db.getRepository("applications");
|
|
28
53
|
if (!repository) {
|
|
29
54
|
await next();
|
|
@@ -31,7 +56,7 @@ function appSelectorMiddleware(app) {
|
|
|
31
56
|
}
|
|
32
57
|
const appInstance = await repository.findOne({
|
|
33
58
|
filter: {
|
|
34
|
-
cname:
|
|
59
|
+
cname: subAppName
|
|
35
60
|
}
|
|
36
61
|
});
|
|
37
62
|
if (appInstance) {
|
|
@@ -22,7 +22,10 @@ __export(add_apps_tmpl_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(add_apps_tmpl_exports);
|
|
23
23
|
var import_server = require("@tachybase/server");
|
|
24
24
|
class AddAppTmplMigration extends import_server.Migration {
|
|
25
|
-
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
this.appVersion = "<0.21.99";
|
|
28
|
+
}
|
|
26
29
|
async up() {
|
|
27
30
|
const Field = this.context.db.getRepository("fields");
|
|
28
31
|
const existed = await Field.count({
|
|
@@ -22,9 +22,12 @@ __export(add_createdBy_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(add_createdBy_exports);
|
|
23
23
|
var import_server = require("@tachybase/server");
|
|
24
24
|
class add_createdBy_default extends import_server.Migration {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
this.on = "afterLoad";
|
|
28
|
+
// 'beforeLoad' or 'afterLoad'
|
|
29
|
+
this.appVersion = "<0.22.47";
|
|
30
|
+
}
|
|
28
31
|
async up() {
|
|
29
32
|
const userRepo = this.context.db.getRepository("users");
|
|
30
33
|
const appRepo = this.context.db.getRepository("applications");
|
package/dist/server/server.d.ts
CHANGED
|
@@ -16,4 +16,9 @@ export declare class PluginMultiAppManager extends Plugin {
|
|
|
16
16
|
setAppDbCreator(appDbCreator: AppDbCreator): void;
|
|
17
17
|
beforeLoad(): void;
|
|
18
18
|
load(): Promise<void>;
|
|
19
|
+
notifyStatusChange({ appName, status, options }: {
|
|
20
|
+
appName: any;
|
|
21
|
+
status: any;
|
|
22
|
+
options: any;
|
|
23
|
+
}): void;
|
|
19
24
|
}
|
package/dist/server/server.js
CHANGED
|
@@ -157,9 +157,12 @@ const defaultAppOptionsFactory = (appName, mainApp, preset) => {
|
|
|
157
157
|
};
|
|
158
158
|
};
|
|
159
159
|
class PluginMultiAppManager extends import_server.Plugin {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
constructor() {
|
|
161
|
+
super(...arguments);
|
|
162
|
+
this.appDbCreator = defaultDbCreator;
|
|
163
|
+
this.appOptionsFactory = defaultAppOptionsFactory;
|
|
164
|
+
this.subAppUpgradeHandler = defaultSubAppUpgradeHandle;
|
|
165
|
+
}
|
|
163
166
|
static getDatabaseConfig(app) {
|
|
164
167
|
let oldConfig = app.options.database instanceof import_database.Database ? app.options.database.options : app.options.database;
|
|
165
168
|
if (!oldConfig && app.db) {
|
|
@@ -214,22 +217,11 @@ class PluginMultiAppManager extends import_server.Plugin {
|
|
|
214
217
|
this.app.on("afterUpgrade", async (app, options) => {
|
|
215
218
|
await this.subAppUpgradeHandler(app);
|
|
216
219
|
});
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
const app = await import_server.AppSupervisor.getInstance().getApp(appName, {
|
|
223
|
-
withOutBootStrap: true
|
|
224
|
-
});
|
|
225
|
-
const level = ["error", "not_found"].includes(status) ? "error" : "info";
|
|
226
|
-
this.app.noticeManager.notify(import_constants.NOTIFY_STATUS_EVENT_KEY, {
|
|
227
|
-
app: appName,
|
|
228
|
-
status,
|
|
229
|
-
level,
|
|
230
|
-
message: (_a = options.error) == null ? void 0 : _a.message
|
|
231
|
-
});
|
|
220
|
+
const notifyStatusChange = this.notifyStatusChange.bind(this);
|
|
221
|
+
this.app.on("beforeStop", async (app) => {
|
|
222
|
+
import_server.AppSupervisor.getInstance().off("appStatusChanged", notifyStatusChange);
|
|
232
223
|
});
|
|
224
|
+
import_server.AppSupervisor.getInstance().on("appStatusChanged", notifyStatusChange);
|
|
233
225
|
this.app.acl.allow("applications", "listPinned", "loggedIn");
|
|
234
226
|
this.app.acl.allow("applications", "list", "loggedIn");
|
|
235
227
|
this.app.acl.registerSnippet({
|
|
@@ -258,6 +250,19 @@ class PluginMultiAppManager extends import_server.Plugin {
|
|
|
258
250
|
this.app.resourcer.registerActionHandler(`applications:${key}`, action);
|
|
259
251
|
}
|
|
260
252
|
}
|
|
253
|
+
notifyStatusChange({ appName, status, options }) {
|
|
254
|
+
var _a;
|
|
255
|
+
if (appName === "main") {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const level = ["error", "not_found"].includes(status) ? "error" : "info";
|
|
259
|
+
this.app.noticeManager.notify(import_constants.NOTIFY_STATUS_EVENT_KEY, {
|
|
260
|
+
app: appName,
|
|
261
|
+
status,
|
|
262
|
+
level,
|
|
263
|
+
message: (_a = options.error) == null ? void 0 : _a.message
|
|
264
|
+
});
|
|
265
|
+
}
|
|
261
266
|
}
|
|
262
267
|
// Annotate the CommonJS export names for ESM import in node:
|
|
263
268
|
0 && (module.exports = {
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/module-multi-app",
|
|
3
3
|
"displayName": "Multi-app manager",
|
|
4
|
-
"version": "0.23.
|
|
4
|
+
"version": "0.23.47",
|
|
5
5
|
"description": "Dynamically create multiple apps without separate deployments.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"System management"
|
|
8
8
|
],
|
|
9
9
|
"license": "Apache-2.0",
|
|
10
10
|
"main": "./dist/server/index.js",
|
|
11
|
-
"dependencies": {
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"qs": "^6.13.1"
|
|
13
|
+
},
|
|
12
14
|
"devDependencies": {
|
|
13
15
|
"@ant-design/icons": "^5.5.2",
|
|
14
16
|
"antd": "5.22.5",
|
|
@@ -19,15 +21,15 @@
|
|
|
19
21
|
"react": "~18.3.1",
|
|
20
22
|
"react-i18next": "^15.2.0",
|
|
21
23
|
"react-router-dom": "6.28.1",
|
|
22
|
-
"@tachybase/schema": "0.23.
|
|
24
|
+
"@tachybase/schema": "0.23.47"
|
|
23
25
|
},
|
|
24
26
|
"peerDependencies": {
|
|
25
|
-
"@tachybase/actions": "0.23.
|
|
26
|
-
"@tachybase/
|
|
27
|
-
"@tachybase/
|
|
28
|
-
"@tachybase/
|
|
29
|
-
"@tachybase/
|
|
30
|
-
"@tachybase/
|
|
27
|
+
"@tachybase/actions": "0.23.47",
|
|
28
|
+
"@tachybase/client": "0.23.47",
|
|
29
|
+
"@tachybase/database": "0.23.47",
|
|
30
|
+
"@tachybase/test": "0.23.47",
|
|
31
|
+
"@tachybase/server": "0.23.47",
|
|
32
|
+
"@tachybase/utils": "0.23.47"
|
|
31
33
|
},
|
|
32
34
|
"description.zh-CN": "无需单独部署即可动态创建多个应用。",
|
|
33
35
|
"displayName.zh-CN": "多应用管理器",
|