@tachybase/module-multi-app 0.23.8

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 (117) hide show
  1. package/.turbo/turbo-build.log +14 -0
  2. package/README.md +34 -0
  3. package/README.zh-CN.md +34 -0
  4. package/client.d.ts +1 -0
  5. package/client.js +1 -0
  6. package/dist/client/AppManager.d.ts +2 -0
  7. package/dist/client/AppNameInput.d.ts +2 -0
  8. package/dist/client/MultiAppBlockInitializer.d.ts +2 -0
  9. package/dist/client/MultiAppManagerProvider.d.ts +2 -0
  10. package/dist/client/MultiAppManagerProvider.style.d.ts +5 -0
  11. package/dist/client/Settings.d.ts +2 -0
  12. package/dist/client/index.d.ts +6 -0
  13. package/dist/client/index.js +1 -0
  14. package/dist/client/settings/schemas/applications.d.ts +13 -0
  15. package/dist/client/utils.d.ts +4 -0
  16. package/dist/constants.d.ts +1 -0
  17. package/dist/constants.js +27 -0
  18. package/dist/externalVersion.js +16 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +39 -0
  21. package/dist/locale/en-US.json +27 -0
  22. package/dist/locale/es-ES.json +9 -0
  23. package/dist/locale/ko_KR.json +11 -0
  24. package/dist/locale/pt-BR.json +9 -0
  25. package/dist/locale/zh-CN.json +27 -0
  26. package/dist/node_modules/mariadb/LICENSE +502 -0
  27. package/dist/node_modules/mariadb/callback.js +41 -0
  28. package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +278 -0
  29. package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +372 -0
  30. package/dist/node_modules/mariadb/lib/cmd/change-user.js +149 -0
  31. package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +17 -0
  32. package/dist/node_modules/mariadb/lib/cmd/column-definition.js +102 -0
  33. package/dist/node_modules/mariadb/lib/cmd/command.js +168 -0
  34. package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +327 -0
  35. package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +427 -0
  36. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +168 -0
  37. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +23 -0
  38. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +761 -0
  39. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +55 -0
  40. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +58 -0
  41. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +19 -0
  42. package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +142 -0
  43. package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +74 -0
  44. package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +126 -0
  45. package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +292 -0
  46. package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +74 -0
  47. package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +29 -0
  48. package/dist/node_modules/mariadb/lib/cmd/ping.js +52 -0
  49. package/dist/node_modules/mariadb/lib/cmd/query.js +255 -0
  50. package/dist/node_modules/mariadb/lib/cmd/quit.js +28 -0
  51. package/dist/node_modules/mariadb/lib/cmd/reset.js +54 -0
  52. package/dist/node_modules/mariadb/lib/cmd/resultset.js +607 -0
  53. package/dist/node_modules/mariadb/lib/cmd/stream.js +45 -0
  54. package/dist/node_modules/mariadb/lib/config/connection-options.js +258 -0
  55. package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +19 -0
  56. package/dist/node_modules/mariadb/lib/config/pool-options.js +47 -0
  57. package/dist/node_modules/mariadb/lib/connection-callback.js +160 -0
  58. package/dist/node_modules/mariadb/lib/connection.js +1460 -0
  59. package/dist/node_modules/mariadb/lib/const/capabilities.js +64 -0
  60. package/dist/node_modules/mariadb/lib/const/collations.js +473 -0
  61. package/dist/node_modules/mariadb/lib/const/connection_status.js +13 -0
  62. package/dist/node_modules/mariadb/lib/const/error-code.js +1282 -0
  63. package/dist/node_modules/mariadb/lib/const/field-detail.js +35 -0
  64. package/dist/node_modules/mariadb/lib/const/field-type.js +71 -0
  65. package/dist/node_modules/mariadb/lib/const/server-status.js +30 -0
  66. package/dist/node_modules/mariadb/lib/const/state-change.js +12 -0
  67. package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +81 -0
  68. package/dist/node_modules/mariadb/lib/io/bulk-packet.js +590 -0
  69. package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +141 -0
  70. package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +171 -0
  71. package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +193 -0
  72. package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +36 -0
  73. package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +37 -0
  74. package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +502 -0
  75. package/dist/node_modules/mariadb/lib/io/packet.js +515 -0
  76. package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +481 -0
  77. package/dist/node_modules/mariadb/lib/misc/connection-information.js +96 -0
  78. package/dist/node_modules/mariadb/lib/misc/errors.js +123 -0
  79. package/dist/node_modules/mariadb/lib/misc/parse.js +1033 -0
  80. package/dist/node_modules/mariadb/lib/misc/utils.js +298 -0
  81. package/dist/node_modules/mariadb/lib/pool-base.js +611 -0
  82. package/dist/node_modules/mariadb/lib/pool-callback.js +202 -0
  83. package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +66 -0
  84. package/dist/node_modules/mariadb/lib/pool-cluster.js +407 -0
  85. package/dist/node_modules/mariadb/lib/pool-promise.js +108 -0
  86. package/dist/node_modules/mariadb/package.json +1 -0
  87. package/dist/node_modules/mariadb/promise.js +34 -0
  88. package/dist/node_modules/mariadb/types/index.d.ts +870 -0
  89. package/dist/server/actions/apps.d.ts +5 -0
  90. package/dist/server/actions/apps.js +117 -0
  91. package/dist/server/app-lifecycle.d.ts +8 -0
  92. package/dist/server/app-lifecycle.js +99 -0
  93. package/dist/server/app-start-env.d.ts +2 -0
  94. package/dist/server/app-start-env.js +105 -0
  95. package/dist/server/collections/applications.d.ts +2 -0
  96. package/dist/server/collections/applications.js +82 -0
  97. package/dist/server/index.d.ts +4 -0
  98. package/dist/server/index.js +29 -0
  99. package/dist/server/middlewares/app-selector.d.ts +1 -0
  100. package/dist/server/middlewares/app-selector.js +47 -0
  101. package/dist/server/middlewares/index.d.ts +2 -0
  102. package/dist/server/middlewares/index.js +23 -0
  103. package/dist/server/middlewares/inject-app-list.d.ts +1 -0
  104. package/dist/server/middlewares/inject-app-list.js +48 -0
  105. package/dist/server/migrations/20240820153000-add-apps-tmpl.d.ts +6 -0
  106. package/dist/server/migrations/20240820153000-add-apps-tmpl.js +47 -0
  107. package/dist/server/migrations/20241126124904-add-createdBy.d.ts +6 -0
  108. package/dist/server/migrations/20241126124904-add-createdBy.js +41 -0
  109. package/dist/server/models/application.d.ts +10 -0
  110. package/dist/server/models/application.js +57 -0
  111. package/dist/server/server.d.ts +19 -0
  112. package/dist/server/server.js +246 -0
  113. package/dist/swagger/index.d.ts +197 -0
  114. package/dist/swagger/index.js +227 -0
  115. package/package.json +38 -0
  116. package/server.d.ts +2 -0
  117. package/server.js +1 -0
@@ -0,0 +1,5 @@
1
+ import { Context, Next } from '@tachybase/actions';
2
+ export declare function start(ctx: Context, next: Next): Promise<void>;
3
+ export declare function stop(ctx: Context, next: Next): Promise<void>;
4
+ export declare function listPinned(ctx: Context, next: Next): Promise<void>;
5
+ export declare function create(ctx: Context, next: Next): Promise<void>;
@@ -0,0 +1,117 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var apps_exports = {};
19
+ __export(apps_exports, {
20
+ create: () => create,
21
+ listPinned: () => listPinned,
22
+ start: () => start,
23
+ stop: () => stop
24
+ });
25
+ module.exports = __toCommonJS(apps_exports);
26
+ var import_server = require("@tachybase/server");
27
+ var import_constants = require("../../constants");
28
+ async function start(ctx, next) {
29
+ const targetAppId = String(ctx.request.url.split("filterByTk=")[1]);
30
+ const appSupervisor = import_server.AppSupervisor.getInstance();
31
+ if (!appSupervisor.hasApp(targetAppId)) {
32
+ appSupervisor.blockApps.delete(targetAppId);
33
+ await import_server.AppSupervisor.getInstance().getApp(targetAppId);
34
+ ctx.body = "ok";
35
+ await next();
36
+ } else {
37
+ ctx.throw(400, ctx.t("App already started", { ns: import_constants.NAMESPACE }));
38
+ }
39
+ }
40
+ async function stop(ctx, next) {
41
+ const targetAppId = String(ctx.request.url.split("filterByTk=")[1]);
42
+ const appSupervisor = import_server.AppSupervisor.getInstance();
43
+ if (appSupervisor.hasApp(targetAppId)) {
44
+ appSupervisor.blockApps.add(targetAppId);
45
+ await appSupervisor.removeApp(targetAppId);
46
+ ctx.body = "ok";
47
+ await next();
48
+ } else {
49
+ ctx.throw(400, ctx.t("App already stopped", { ns: import_constants.NAMESPACE }));
50
+ }
51
+ }
52
+ async function listPinned(ctx, next) {
53
+ const items = await ctx.db.getRepository("applications").find({
54
+ filter: {
55
+ pinned: true
56
+ }
57
+ });
58
+ ctx.body = items;
59
+ await next();
60
+ }
61
+ async function create(ctx, next) {
62
+ var _a, _b, _c;
63
+ const params = ctx.action.params;
64
+ const tmpl = (_a = params.values) == null ? void 0 : _a.tmpl;
65
+ if (tmpl) {
66
+ const startEnvs = (_c = (_b = params.values) == null ? void 0 : _b.options) == null ? void 0 : _c.startEnvs;
67
+ if (startEnvs) {
68
+ const dbDialect = startEnvs.split("\n").find((line) => line.startsWith("DB_DIALECT="));
69
+ if (dbDialect) {
70
+ const dbType2 = dbDialect.split("=")[1].trim();
71
+ if (dbType2 !== "postgres") {
72
+ ctx.throw(
73
+ 400,
74
+ ctx.t("This database does not support to create application using template", { ns: import_constants.NAMESPACE })
75
+ );
76
+ }
77
+ }
78
+ }
79
+ const dbType = ctx.db.options.dialect;
80
+ if (dbType !== "postgres") {
81
+ ctx.throw(400, ctx.t("This database does not support to create application using template", { ns: import_constants.NAMESPACE }));
82
+ }
83
+ const matchedApp = await ctx.db.getRepository("applications").find({
84
+ filter: {
85
+ name: tmpl
86
+ }
87
+ });
88
+ if (matchedApp.length === 0) {
89
+ ctx.throw(400, ctx.t("Template not exists", { ns: import_constants.NAMESPACE }));
90
+ }
91
+ const appStatus = import_server.AppSupervisor.getInstance().getAppStatus(tmpl, "initialized");
92
+ if (appStatus !== "stopped" && appStatus !== "initialized") {
93
+ ctx.throw(400, ctx.t("Template is in use", { ns: import_constants.NAMESPACE }));
94
+ }
95
+ }
96
+ await ctx.db.getRepository("applications").create({
97
+ values: {
98
+ ...params.values,
99
+ createdBy: ctx.state.currentUser.id,
100
+ updatedBy: ctx.state.currentUser.id
101
+ }
102
+ });
103
+ const app = await ctx.db.getRepository("applications").find({
104
+ filter: {
105
+ name: ctx.request.body.name
106
+ }
107
+ });
108
+ ctx.body = app;
109
+ await next();
110
+ }
111
+ // Annotate the CommonJS export names for ESM import in node:
112
+ 0 && (module.exports = {
113
+ create,
114
+ listPinned,
115
+ start,
116
+ stop
117
+ });
@@ -0,0 +1,8 @@
1
+ import Application, { AppSupervisor } from '@tachybase/server';
2
+ export type AppOptionsFactory = (appName: string, mainApp: Application, preset: string) => any;
3
+ export declare function LazyLoadApplication(context: any): ({ appSupervisor, appName, options, }: {
4
+ appSupervisor: AppSupervisor;
5
+ appName: string;
6
+ options: any;
7
+ }) => Promise<void>;
8
+ export declare function onAfterStart(db: any): (app: Application) => Promise<void>;
@@ -0,0 +1,99 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var app_lifecycle_exports = {};
19
+ __export(app_lifecycle_exports, {
20
+ LazyLoadApplication: () => LazyLoadApplication,
21
+ onAfterStart: () => onAfterStart
22
+ });
23
+ module.exports = __toCommonJS(app_lifecycle_exports);
24
+ var import_server = require("@tachybase/server");
25
+ function LazyLoadApplication(context) {
26
+ return async ({
27
+ appSupervisor,
28
+ appName,
29
+ options
30
+ }) => {
31
+ const loadButNotStart = options == null ? void 0 : options.upgrading;
32
+ const name = appName;
33
+ if (appSupervisor.hasApp(name)) {
34
+ return;
35
+ }
36
+ const applicationRecord = await context.app.db.getRepository("applications").findOne({
37
+ filter: {
38
+ name
39
+ }
40
+ });
41
+ if (!applicationRecord) {
42
+ return;
43
+ }
44
+ const instanceOptions = applicationRecord.get("options");
45
+ if ((instanceOptions == null ? void 0 : instanceOptions.standaloneDeployment) && appSupervisor.runningMode !== "single") {
46
+ return;
47
+ }
48
+ if (!applicationRecord) {
49
+ return;
50
+ }
51
+ const subApp = applicationRecord.registerToSupervisor(context.app, {
52
+ appOptionsFactory: context.appOptionsFactory
53
+ });
54
+ if (!loadButNotStart) {
55
+ await subApp.runCommand("start", "--quickstart");
56
+ }
57
+ };
58
+ }
59
+ function onAfterStart(db) {
60
+ return async (app) => {
61
+ const repository = db.getRepository("applications");
62
+ const appSupervisor = import_server.AppSupervisor.getInstance();
63
+ app.setMaintainingMessage("starting sub applications...");
64
+ if (appSupervisor.runningMode == "single") {
65
+ import_server.Gateway.getInstance().addAppSelectorMiddleware((ctx) => ctx.resolvedAppName = appSupervisor.singleAppName);
66
+ try {
67
+ await import_server.AppSupervisor.getInstance().getApp(appSupervisor.singleAppName);
68
+ } catch (err) {
69
+ console.error("Auto register sub application in single mode failed: ", appSupervisor.singleAppName, err);
70
+ }
71
+ return;
72
+ }
73
+ try {
74
+ const subApps = await repository.find({
75
+ filter: {
76
+ "options.autoStart": true
77
+ }
78
+ });
79
+ const promises = [];
80
+ for (const subAppInstance of subApps) {
81
+ promises.push(
82
+ (async () => {
83
+ if (!appSupervisor.hasApp(subAppInstance.name)) {
84
+ await import_server.AppSupervisor.getInstance().getApp(subAppInstance.name);
85
+ }
86
+ })()
87
+ );
88
+ }
89
+ await Promise.all(promises);
90
+ } catch (err) {
91
+ console.error("Auto register sub applications failed: ", err);
92
+ }
93
+ };
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ LazyLoadApplication,
98
+ onAfterStart
99
+ });
@@ -0,0 +1,2 @@
1
+ import { Application } from '@tachybase/server';
2
+ export default function mergeApplicationStartEnvs(appName: String, mainApp: Application, options: any, startEnvs: any): any;
@@ -0,0 +1,105 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var app_start_env_exports = {};
19
+ __export(app_start_env_exports, {
20
+ default: () => mergeApplicationStartEnvs
21
+ });
22
+ module.exports = __toCommonJS(app_start_env_exports);
23
+ function mergeApplicationStartEnvs(appName, mainApp, options, startEnvs) {
24
+ if (typeof startEnvs === "string") {
25
+ const envs = startEnvs.trim().split("\n");
26
+ startEnvs = {};
27
+ for (const env of envs) {
28
+ const [key, value] = env.split("=");
29
+ startEnvs[key] = value;
30
+ }
31
+ }
32
+ if (startEnvs && Object.keys(startEnvs).length !== 0) {
33
+ if (startEnvs.APP_KEY) {
34
+ options = {
35
+ ...options,
36
+ authManager: {
37
+ jwt: {
38
+ secret: startEnvs.APP_KEY
39
+ }
40
+ }
41
+ };
42
+ delete startEnvs.APP_KEY;
43
+ }
44
+ if (startEnvs.API_BASE_PATH) {
45
+ options.resourcer.prefix = startEnvs.API_BASE_PATH;
46
+ delete startEnvs.API_BASE_PATH;
47
+ }
48
+ if (startEnvs.DB_DIALECT) {
49
+ options.database.dialect = startEnvs.DB_DIALECT;
50
+ delete startEnvs.DB_DIALECT;
51
+ }
52
+ if (startEnvs.DB_STORAGE) {
53
+ options.database.storage = startEnvs.DB_STORAGE;
54
+ delete startEnvs.DB_STORAGE;
55
+ }
56
+ if (startEnvs.DB_TABLE_PREFIX) {
57
+ options.database.tablePrefix = startEnvs.DB_TABLE_PREFIX;
58
+ delete startEnvs.DB_TABLE_PREFIX;
59
+ }
60
+ if (startEnvs.DB_HOST) {
61
+ options.database.host = startEnvs.DB_HOST;
62
+ delete startEnvs.DB_HOST;
63
+ }
64
+ if (startEnvs.DB_PORT) {
65
+ options.database.port = parseInt(startEnvs.DB_PORT);
66
+ delete startEnvs.DB_PORT;
67
+ }
68
+ if (startEnvs.DB_DATABASE) {
69
+ options.database.database = startEnvs.DB_DATABASE;
70
+ delete startEnvs.DB_DATABASE;
71
+ }
72
+ if (startEnvs.DB_USER) {
73
+ options.database.username = startEnvs.DB_USER;
74
+ delete startEnvs.DB_USER;
75
+ }
76
+ if (startEnvs.DB_PASSWORD) {
77
+ options.database.password = startEnvs.DB_PASSWORD;
78
+ delete startEnvs.DB_PASSWORD;
79
+ }
80
+ if (startEnvs.DB_UNDERSCORED) {
81
+ options.database.underscored = startEnvs.DB_UNDERSCORED === "true";
82
+ delete startEnvs.DB_UNDERSCORED;
83
+ }
84
+ if (startEnvs.DB_TIMEZONE) {
85
+ options.database.timezone = startEnvs.DB_TIMEZONE;
86
+ delete startEnvs.DB_TIMEZONE;
87
+ }
88
+ if (startEnvs.DB_SCHEMA) {
89
+ options.database.schema = startEnvs.DB_SCHEMA;
90
+ delete startEnvs.DB_SCHEMA;
91
+ }
92
+ if (startEnvs.CACHE_DEFAULT_STORE) {
93
+ options.cacheManager.defaultStore = startEnvs.CACHE_DEFAULT_STORE;
94
+ delete startEnvs.CACHE_DEFAULT_STORE;
95
+ }
96
+ if (startEnvs.CACHE_MEMORY_MAX) {
97
+ options.cacheManager.stores.memory.max = parseInt(startEnvs.CACHE_MEMORY_MAX);
98
+ delete startEnvs.CACHE_MEMORY_MAX;
99
+ }
100
+ if (Object.keys(startEnvs).length !== 0) {
101
+ mainApp.logger.warn(`Application ${appName} has unsupported startEnvs: ${JSON.stringify(startEnvs)}`);
102
+ }
103
+ }
104
+ return options;
105
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@tachybase/database").CollectionOptions;
2
+ export default _default;
@@ -0,0 +1,82 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var applications_exports = {};
19
+ __export(applications_exports, {
20
+ default: () => applications_default
21
+ });
22
+ module.exports = __toCommonJS(applications_exports);
23
+ var import_database = require("@tachybase/database");
24
+ var applications_default = (0, import_database.defineCollection)({
25
+ dumpRules: {
26
+ group: "third-party"
27
+ },
28
+ name: "applications",
29
+ model: "ApplicationModel",
30
+ autoGenId: false,
31
+ sortable: "sort",
32
+ filterTargetKey: "name",
33
+ createdBy: true,
34
+ updatedBy: true,
35
+ fields: [
36
+ {
37
+ type: "uid",
38
+ name: "name",
39
+ primaryKey: true
40
+ },
41
+ {
42
+ type: "string",
43
+ name: "displayName"
44
+ },
45
+ {
46
+ type: "string",
47
+ name: "cname",
48
+ unique: true
49
+ },
50
+ {
51
+ type: "string",
52
+ name: "preset",
53
+ defaultValue: "tachybase"
54
+ },
55
+ {
56
+ type: "string",
57
+ name: "tmpl"
58
+ },
59
+ {
60
+ type: "boolean",
61
+ name: "pinned"
62
+ },
63
+ {
64
+ type: "string",
65
+ name: "icon"
66
+ },
67
+ {
68
+ type: "string",
69
+ name: "status",
70
+ defaultValue: "pending"
71
+ },
72
+ {
73
+ type: "json",
74
+ name: "options"
75
+ },
76
+ {
77
+ type: "boolean",
78
+ name: "isTemplate",
79
+ defaultValue: false
80
+ }
81
+ ]
82
+ });
@@ -0,0 +1,4 @@
1
+ import { ApplicationModel, registerAppOptions } from './models/application';
2
+ export { PluginMultiAppManager as default } from './server';
3
+ export { ApplicationModel };
4
+ export type { registerAppOptions };
@@ -0,0 +1,29 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var server_exports = {};
19
+ __export(server_exports, {
20
+ ApplicationModel: () => import_application.ApplicationModel,
21
+ default: () => import_server.PluginMultiAppManager
22
+ });
23
+ module.exports = __toCommonJS(server_exports);
24
+ var import_application = require("./models/application");
25
+ var import_server = require("./server");
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ ApplicationModel
29
+ });
@@ -0,0 +1 @@
1
+ export declare function appSelectorMiddleware(app: any): (ctx: any, next: any) => Promise<void>;
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var app_selector_exports = {};
19
+ __export(app_selector_exports, {
20
+ appSelectorMiddleware: () => appSelectorMiddleware
21
+ });
22
+ module.exports = __toCommonJS(app_selector_exports);
23
+ function appSelectorMiddleware(app) {
24
+ return async (ctx, next) => {
25
+ const { req } = ctx;
26
+ if (!ctx.resolvedAppName && req.headers["x-hostname"]) {
27
+ const repository = app.db.getRepository("applications");
28
+ if (!repository) {
29
+ await next();
30
+ return;
31
+ }
32
+ const appInstance = await repository.findOne({
33
+ filter: {
34
+ cname: req.headers["x-hostname"]
35
+ }
36
+ });
37
+ if (appInstance) {
38
+ ctx.resolvedAppName = appInstance.name;
39
+ }
40
+ }
41
+ await next();
42
+ };
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ appSelectorMiddleware
47
+ });
@@ -0,0 +1,2 @@
1
+ export * from './app-selector';
2
+ export * from './inject-app-list';
@@ -0,0 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var middlewares_exports = {};
16
+ module.exports = __toCommonJS(middlewares_exports);
17
+ __reExport(middlewares_exports, require("./app-selector"), module.exports);
18
+ __reExport(middlewares_exports, require("./inject-app-list"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./app-selector"),
22
+ ...require("./inject-app-list")
23
+ });
@@ -0,0 +1 @@
1
+ export declare function injectAppListMiddleware(): (ctx: any, next: any) => Promise<void>;
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var inject_app_list_exports = {};
19
+ __export(inject_app_list_exports, {
20
+ injectAppListMiddleware: () => injectAppListMiddleware
21
+ });
22
+ module.exports = __toCommonJS(inject_app_list_exports);
23
+ var import_server = require("@tachybase/server");
24
+ function injectAppListMiddleware() {
25
+ return async (ctx, next) => {
26
+ await next();
27
+ const { actionName, resourceName, params } = ctx.action;
28
+ if (actionName === "list" && resourceName === "applications") {
29
+ const applications = ctx.body.rows;
30
+ for (const application of applications) {
31
+ const appStatus = import_server.AppSupervisor.getInstance().getAppStatus(application.name, "stopped");
32
+ application.status = appStatus;
33
+ if (application.tmpl) {
34
+ const matchedApp = applications.find((app) => app.name === application.tmpl);
35
+ if (matchedApp) {
36
+ application.tmpl = `${matchedApp.displayName}(${application.tmpl})`;
37
+ } else {
38
+ application.tmpl = `Not Exists(${application.tmpl})`;
39
+ }
40
+ }
41
+ }
42
+ }
43
+ };
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ injectAppListMiddleware
48
+ });
@@ -0,0 +1,6 @@
1
+ import { Migration } from '@tachybase/server';
2
+ export default class AddAppTmplMigration extends Migration {
3
+ appVersion: string;
4
+ up(): Promise<void>;
5
+ down(): Promise<void>;
6
+ }
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var add_apps_tmpl_exports = {};
19
+ __export(add_apps_tmpl_exports, {
20
+ default: () => AddAppTmplMigration
21
+ });
22
+ module.exports = __toCommonJS(add_apps_tmpl_exports);
23
+ var import_server = require("@tachybase/server");
24
+ class AddAppTmplMigration extends import_server.Migration {
25
+ appVersion = "<0.21.99";
26
+ async up() {
27
+ const Field = this.context.db.getRepository("fields");
28
+ const existed = await Field.count({
29
+ filter: {
30
+ name: "tmpl",
31
+ collectionName: "applications"
32
+ }
33
+ });
34
+ if (!existed) {
35
+ await Field.create({
36
+ values: {
37
+ name: "tmpl",
38
+ collectionName: "applications",
39
+ type: "string",
40
+ unique: true
41
+ }
42
+ });
43
+ }
44
+ }
45
+ async down() {
46
+ }
47
+ }
@@ -0,0 +1,6 @@
1
+ import { Migration } from '@tachybase/server';
2
+ export default class extends Migration {
3
+ on: string;
4
+ appVersion: string;
5
+ up(): Promise<void>;
6
+ }