@nocobase/server 1.2.13-alpha → 1.3.0-alpha.20240710084543

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/package.json +14 -14
  2. package/lib/acl/available-action.d.ts +0 -13
  3. package/lib/acl/available-action.js +0 -71
  4. package/lib/acl/index.d.ts +0 -10
  5. package/lib/acl/index.js +0 -46
  6. package/lib/app-command.d.ts +0 -20
  7. package/lib/app-command.js +0 -82
  8. package/lib/app-supervisor.d.ts +0 -69
  9. package/lib/app-supervisor.js +0 -302
  10. package/lib/application.d.ts +0 -345
  11. package/lib/application.js +0 -876
  12. package/lib/cache/index.d.ts +0 -11
  13. package/lib/cache/index.js +0 -44
  14. package/lib/commands/console.d.ts +0 -11
  15. package/lib/commands/console.js +0 -48
  16. package/lib/commands/create-migration.d.ts +0 -11
  17. package/lib/commands/create-migration.js +0 -79
  18. package/lib/commands/db-auth.d.ts +0 -11
  19. package/lib/commands/db-auth.js +0 -38
  20. package/lib/commands/db-clean.d.ts +0 -11
  21. package/lib/commands/db-clean.js +0 -41
  22. package/lib/commands/db-sync.d.ts +0 -11
  23. package/lib/commands/db-sync.js +0 -50
  24. package/lib/commands/destroy.d.ts +0 -11
  25. package/lib/commands/destroy.js +0 -40
  26. package/lib/commands/index.d.ts +0 -10
  27. package/lib/commands/index.js +0 -82
  28. package/lib/commands/install.d.ts +0 -11
  29. package/lib/commands/install.js +0 -43
  30. package/lib/commands/migrator.d.ts +0 -11
  31. package/lib/commands/migrator.js +0 -41
  32. package/lib/commands/pm.d.ts +0 -11
  33. package/lib/commands/pm.js +0 -98
  34. package/lib/commands/refresh.d.ts +0 -11
  35. package/lib/commands/refresh.js +0 -41
  36. package/lib/commands/restart.d.ts +0 -11
  37. package/lib/commands/restart.js +0 -45
  38. package/lib/commands/start.d.ts +0 -11
  39. package/lib/commands/start.js +0 -85
  40. package/lib/commands/stop.d.ts +0 -11
  41. package/lib/commands/stop.js +0 -44
  42. package/lib/commands/upgrade.d.ts +0 -14
  43. package/lib/commands/upgrade.js +0 -39
  44. package/lib/cron/cron-job-manager.d.ts +0 -22
  45. package/lib/cron/cron-job-manager.js +0 -82
  46. package/lib/errors/application-not-install.d.ts +0 -12
  47. package/lib/errors/application-not-install.js +0 -45
  48. package/lib/errors/handler.d.ts +0 -11
  49. package/lib/errors/handler.js +0 -50
  50. package/lib/errors/plugin-command-error.d.ts +0 -10
  51. package/lib/errors/plugin-command-error.js +0 -40
  52. package/lib/errors/plugin-not-exist.d.ts +0 -10
  53. package/lib/errors/plugin-not-exist.js +0 -40
  54. package/lib/gateway/errors.d.ts +0 -30
  55. package/lib/gateway/errors.js +0 -154
  56. package/lib/gateway/index.d.ts +0 -79
  57. package/lib/gateway/index.js +0 -393
  58. package/lib/gateway/ipc-socket-client.d.ts +0 -27
  59. package/lib/gateway/ipc-socket-client.js +0 -110
  60. package/lib/gateway/ipc-socket-server.d.ts +0 -21
  61. package/lib/gateway/ipc-socket-server.js +0 -150
  62. package/lib/gateway/ws-server.d.ts +0 -36
  63. package/lib/gateway/ws-server.js +0 -196
  64. package/lib/helper.d.ts +0 -18
  65. package/lib/helper.js +0 -193
  66. package/lib/helpers/application-version.d.ts +0 -18
  67. package/lib/helpers/application-version.js +0 -88
  68. package/lib/index.d.ts +0 -17
  69. package/lib/index.js +0 -64
  70. package/lib/locale/index.d.ts +0 -9
  71. package/lib/locale/index.js +0 -30
  72. package/lib/locale/locale.d.ts +0 -38
  73. package/lib/locale/locale.js +0 -174
  74. package/lib/locale/resource.d.ts +0 -9
  75. package/lib/locale/resource.js +0 -87
  76. package/lib/main-data-source.d.ts +0 -12
  77. package/lib/main-data-source.js +0 -57
  78. package/lib/middlewares/data-template.d.ts +0 -10
  79. package/lib/middlewares/data-template.js +0 -146
  80. package/lib/middlewares/data-wrapping.d.ts +0 -11
  81. package/lib/middlewares/data-wrapping.js +0 -100
  82. package/lib/middlewares/i18n.d.ts +0 -9
  83. package/lib/middlewares/i18n.js +0 -53
  84. package/lib/middlewares/index.d.ts +0 -10
  85. package/lib/middlewares/index.js +0 -39
  86. package/lib/middlewares/parse-variables.d.ts +0 -9
  87. package/lib/middlewares/parse-variables.js +0 -95
  88. package/lib/middlewares/validate-filter-params.d.ts +0 -9
  89. package/lib/middlewares/validate-filter-params.js +0 -42
  90. package/lib/migration.d.ts +0 -20
  91. package/lib/migration.js +0 -54
  92. package/lib/migrations/20230912193824-package-name-unique.d.ts +0 -14
  93. package/lib/migrations/20230912193824-package-name-unique.js +0 -59
  94. package/lib/migrations/20230912294620-update-pkg.d.ts +0 -14
  95. package/lib/migrations/20230912294620-update-pkg.js +0 -65
  96. package/lib/migrations/20240106082756-update-plugins.d.ts +0 -14
  97. package/lib/migrations/20240106082756-update-plugins.js +0 -51
  98. package/lib/migrations/20240428235620-rename-plugins.d.ts +0 -14
  99. package/lib/migrations/20240428235620-rename-plugins.js +0 -49
  100. package/lib/plugin-manager/clientStaticUtils.d.ts +0 -31
  101. package/lib/plugin-manager/clientStaticUtils.js +0 -129
  102. package/lib/plugin-manager/constants.d.ts +0 -15
  103. package/lib/plugin-manager/constants.js +0 -135
  104. package/lib/plugin-manager/deps.d.ts +0 -10
  105. package/lib/plugin-manager/deps.js +0 -83
  106. package/lib/plugin-manager/index.d.ts +0 -10
  107. package/lib/plugin-manager/index.js +0 -32
  108. package/lib/plugin-manager/middleware.d.ts +0 -10
  109. package/lib/plugin-manager/middleware.js +0 -45
  110. package/lib/plugin-manager/options/collection.d.ts +0 -10
  111. package/lib/plugin-manager/options/collection.js +0 -47
  112. package/lib/plugin-manager/options/resource.d.ts +0 -23
  113. package/lib/plugin-manager/options/resource.js +0 -186
  114. package/lib/plugin-manager/plugin-manager-repository.d.ts +0 -36
  115. package/lib/plugin-manager/plugin-manager-repository.js +0 -158
  116. package/lib/plugin-manager/plugin-manager.d.ts +0 -206
  117. package/lib/plugin-manager/plugin-manager.js +0 -1100
  118. package/lib/plugin-manager/types.d.ts +0 -23
  119. package/lib/plugin-manager/types.js +0 -24
  120. package/lib/plugin-manager/utils.d.ts +0 -115
  121. package/lib/plugin-manager/utils.js +0 -568
  122. package/lib/plugin.d.ts +0 -99
  123. package/lib/plugin.js +0 -228
  124. package/lib/swagger/index.json +0 -1569
@@ -1,150 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var ipc_socket_server_exports = {};
39
- __export(ipc_socket_server_exports, {
40
- IPCSocketServer: () => IPCSocketServer
41
- });
42
- module.exports = __toCommonJS(ipc_socket_server_exports);
43
- var import_crypto = require("crypto");
44
- var import_fs = __toESM(require("fs"));
45
- var import_net = __toESM(require("net"));
46
- var import_path = __toESM(require("path"));
47
- var import_xpipe = __toESM(require("xpipe"));
48
- var import_app_supervisor = require("../app-supervisor");
49
- var import_ipc_socket_client = require("./ipc-socket-client");
50
- const _IPCSocketServer = class _IPCSocketServer {
51
- socketServer;
52
- constructor(server) {
53
- this.socketServer = server;
54
- }
55
- static buildServer(socketPath) {
56
- if (import_fs.default.existsSync(socketPath)) {
57
- import_fs.default.unlinkSync(socketPath);
58
- }
59
- const dir = import_path.default.dirname(socketPath);
60
- if (!import_fs.default.existsSync(dir)) {
61
- import_fs.default.mkdirSync(dir, { recursive: true });
62
- }
63
- const socketServer = import_net.default.createServer((c) => {
64
- console.log("client connected");
65
- c.on("end", () => {
66
- console.log("client disconnected");
67
- });
68
- c.on("data", (data) => {
69
- const dataAsString = data.toString();
70
- const messages = dataAsString.split("\n");
71
- for (const message of messages) {
72
- if (message.length === 0) {
73
- continue;
74
- }
75
- const reqId = (0, import_crypto.randomUUID)();
76
- const dataObj = JSON.parse(message);
77
- _IPCSocketServer.handleClientMessage({ reqId, ...dataObj }).then((result) => {
78
- (0, import_ipc_socket_client.writeJSON)(c, {
79
- reqId,
80
- type: result === false ? "not_found" : "success"
81
- });
82
- }).catch((err) => {
83
- (0, import_ipc_socket_client.writeJSON)(c, {
84
- reqId,
85
- type: "error",
86
- payload: {
87
- message: err.message,
88
- stack: err.stack
89
- }
90
- });
91
- });
92
- }
93
- });
94
- });
95
- socketServer.listen(import_xpipe.default.eq(socketPath), () => {
96
- console.log(`Gateway IPC Server running at ${socketPath}`);
97
- });
98
- return new _IPCSocketServer(socketServer);
99
- }
100
- static async handleClientMessage({ reqId, type, payload }) {
101
- if (type === "appReady") {
102
- const status = await new Promise((resolve, reject) => {
103
- let status2;
104
- const max = 300;
105
- let count = 0;
106
- const timer = setInterval(async () => {
107
- status2 = import_app_supervisor.AppSupervisor.getInstance().getAppStatus("main");
108
- if (status2 === "running") {
109
- clearInterval(timer);
110
- resolve(status2);
111
- }
112
- if (count++ > max) {
113
- reject("error");
114
- }
115
- }, 500);
116
- });
117
- console.log("status", status);
118
- return status;
119
- }
120
- if (type === "passCliArgv") {
121
- const argv = payload.argv;
122
- const mainApp = await import_app_supervisor.AppSupervisor.getInstance().getApp("main");
123
- if (!mainApp.cli.hasCommand(argv[2])) {
124
- await mainApp.pm.loadCommands();
125
- }
126
- const cli = mainApp.cli;
127
- if (!cli.parseHandleByIPCServer(argv, {
128
- from: "node"
129
- })) {
130
- mainApp.log.debug("Not handle by ipc server");
131
- return false;
132
- }
133
- return mainApp.runAsCLI(argv, {
134
- reqId,
135
- from: "node",
136
- throwError: true
137
- });
138
- }
139
- throw new Error(`Unknown message type ${type}`);
140
- }
141
- close() {
142
- this.socketServer.close();
143
- }
144
- };
145
- __name(_IPCSocketServer, "IPCSocketServer");
146
- let IPCSocketServer = _IPCSocketServer;
147
- // Annotate the CommonJS export names for ESM import in node:
148
- 0 && (module.exports = {
149
- IPCSocketServer
150
- });
@@ -1,36 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- /// <reference types="node" />
10
- import WebSocket from 'ws';
11
- import { IncomingMessage } from 'http';
12
- import { Logger } from '@nocobase/logger';
13
- declare class WebSocketWithId extends WebSocket {
14
- id: string;
15
- }
16
- interface WebSocketClient {
17
- ws: WebSocketWithId;
18
- tags: string[];
19
- url: string;
20
- headers: any;
21
- app?: string;
22
- }
23
- export declare class WSServer {
24
- wss: WebSocket.Server;
25
- webSocketClients: Map<string, WebSocketClient>;
26
- logger: Logger;
27
- constructor();
28
- addNewConnection(ws: WebSocketWithId, request: IncomingMessage): WebSocketClient;
29
- setClientApp(client: WebSocketClient): Promise<void>;
30
- removeConnection(id: string): void;
31
- sendMessageToConnection(client: WebSocketClient, sendMessage: object): void;
32
- sendToConnectionsByTag(tagName: string, tagValue: string, sendMessage: object): void;
33
- loopThroughConnections(callback: (client: WebSocketClient) => void): void;
34
- close(): void;
35
- }
36
- export {};
@@ -1,196 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var ws_server_exports = {};
39
- __export(ws_server_exports, {
40
- WSServer: () => WSServer
41
- });
42
- module.exports = __toCommonJS(ws_server_exports);
43
- var import_gateway = require("../gateway");
44
- var import_ws = require("ws");
45
- var import_nanoid = require("nanoid");
46
- var import_app_supervisor = require("../app-supervisor");
47
- var import_errors = require("./errors");
48
- var import_lodash = __toESM(require("lodash"));
49
- function getPayloadByErrorCode(code, options) {
50
- const error = (0, import_errors.getErrorWithCode)(code);
51
- return import_lodash.default.omit((0, import_errors.applyErrorWithArgs)(error, options), ["status", "maintaining"]);
52
- }
53
- __name(getPayloadByErrorCode, "getPayloadByErrorCode");
54
- const _WSServer = class _WSServer {
55
- wss;
56
- webSocketClients = /* @__PURE__ */ new Map();
57
- logger;
58
- constructor() {
59
- this.wss = new import_ws.WebSocketServer({ noServer: true });
60
- this.wss.on("connection", (ws, request) => {
61
- const client = this.addNewConnection(ws, request);
62
- console.log(`new client connected ${ws.id}`);
63
- ws.on("error", () => {
64
- this.removeConnection(ws.id);
65
- });
66
- ws.on("close", () => {
67
- this.removeConnection(ws.id);
68
- });
69
- });
70
- import_gateway.Gateway.getInstance().on("appSelectorChanged", () => {
71
- this.loopThroughConnections(async (client) => {
72
- const handleAppName = await import_gateway.Gateway.getInstance().getRequestHandleAppName({
73
- url: client.url,
74
- headers: client.headers
75
- });
76
- client.tags = client.tags.filter((tag) => !tag.startsWith("app#"));
77
- client.tags.push(`app#${handleAppName}`);
78
- import_app_supervisor.AppSupervisor.getInstance().bootStrapApp(handleAppName);
79
- });
80
- });
81
- import_app_supervisor.AppSupervisor.getInstance().on("appError", async ({ appName, error }) => {
82
- let message = error.message;
83
- if (error.cause) {
84
- message = `${message}: ${error.cause.message}`;
85
- }
86
- this.sendToConnectionsByTag("app", appName, {
87
- type: "notification",
88
- payload: {
89
- message,
90
- type: "error"
91
- }
92
- });
93
- });
94
- import_app_supervisor.AppSupervisor.getInstance().on("appMaintainingMessageChanged", async ({ appName, message, command, status }) => {
95
- const app = await import_app_supervisor.AppSupervisor.getInstance().getApp(appName, {
96
- withOutBootStrap: true
97
- });
98
- const payload = getPayloadByErrorCode(status, {
99
- app,
100
- message,
101
- command
102
- });
103
- this.sendToConnectionsByTag("app", appName, {
104
- type: "maintaining",
105
- payload
106
- });
107
- });
108
- import_app_supervisor.AppSupervisor.getInstance().on("appStatusChanged", async ({ appName, status, options }) => {
109
- const app = await import_app_supervisor.AppSupervisor.getInstance().getApp(appName, {
110
- withOutBootStrap: true
111
- });
112
- const payload = getPayloadByErrorCode(status, { app, appName });
113
- this.sendToConnectionsByTag("app", appName, {
114
- type: "maintaining",
115
- payload: {
116
- ...payload,
117
- ...options
118
- }
119
- });
120
- });
121
- }
122
- addNewConnection(ws, request) {
123
- const id = (0, import_nanoid.nanoid)();
124
- ws.id = id;
125
- this.webSocketClients.set(id, {
126
- ws,
127
- tags: [],
128
- url: request.url,
129
- headers: request.headers
130
- });
131
- this.setClientApp(this.webSocketClients.get(id));
132
- return this.webSocketClients.get(id);
133
- }
134
- async setClientApp(client) {
135
- const req = {
136
- url: client.url,
137
- headers: client.headers
138
- };
139
- const handleAppName = await import_gateway.Gateway.getInstance().getRequestHandleAppName(req);
140
- client.app = handleAppName;
141
- console.log(`client tags: app#${handleAppName}`);
142
- client.tags.push(`app#${handleAppName}`);
143
- const hasApp = import_app_supervisor.AppSupervisor.getInstance().hasApp(handleAppName);
144
- if (!hasApp) {
145
- import_app_supervisor.AppSupervisor.getInstance().bootStrapApp(handleAppName);
146
- }
147
- const appStatus = import_app_supervisor.AppSupervisor.getInstance().getAppStatus(handleAppName, "initializing");
148
- if (appStatus === "not_found") {
149
- this.sendMessageToConnection(client, {
150
- type: "maintaining",
151
- payload: getPayloadByErrorCode("APP_NOT_FOUND", { appName: handleAppName })
152
- });
153
- return;
154
- }
155
- if (appStatus === "initializing") {
156
- this.sendMessageToConnection(client, {
157
- type: "maintaining",
158
- payload: getPayloadByErrorCode("APP_INITIALIZING", { appName: handleAppName })
159
- });
160
- return;
161
- }
162
- const app = await import_app_supervisor.AppSupervisor.getInstance().getApp(handleAppName);
163
- this.sendMessageToConnection(client, {
164
- type: "maintaining",
165
- payload: getPayloadByErrorCode(appStatus, { app })
166
- });
167
- }
168
- removeConnection(id) {
169
- console.log(`client disconnected ${id}`);
170
- this.webSocketClients.delete(id);
171
- }
172
- sendMessageToConnection(client, sendMessage) {
173
- client.ws.send(JSON.stringify(sendMessage));
174
- }
175
- sendToConnectionsByTag(tagName, tagValue, sendMessage) {
176
- this.loopThroughConnections((client) => {
177
- if (client.tags.includes(`${tagName}#${tagValue}`)) {
178
- this.sendMessageToConnection(client, sendMessage);
179
- }
180
- });
181
- }
182
- loopThroughConnections(callback) {
183
- this.webSocketClients.forEach((client) => {
184
- callback(client);
185
- });
186
- }
187
- close() {
188
- this.wss.close();
189
- }
190
- };
191
- __name(_WSServer, "WSServer");
192
- let WSServer = _WSServer;
193
- // Annotate the CommonJS export names for ESM import in node:
194
- 0 && (module.exports = {
195
- WSServer
196
- });
package/lib/helper.d.ts DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Resourcer } from '@nocobase/resourcer';
10
- import { Command } from 'commander';
11
- import Application, { ApplicationOptions } from './application';
12
- export declare function createI18n(options: ApplicationOptions): import("i18next").i18n;
13
- export declare function createResourcer(options: ApplicationOptions): Resourcer;
14
- export declare function registerMiddlewares(app: Application, options: ApplicationOptions): void;
15
- export declare const createAppProxy: (app: Application) => Application<import("./application").DefaultState, import("./application").DefaultContext>;
16
- export declare const getCommandFullName: (command: Command) => string;
17
- export declare const tsxRerunning: () => Promise<void>;
18
- export declare const enablePerfHooks: (app: Application) => void;
package/lib/helper.js DELETED
@@ -1,193 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var helper_exports = {};
39
- __export(helper_exports, {
40
- createAppProxy: () => createAppProxy,
41
- createI18n: () => createI18n,
42
- createResourcer: () => createResourcer,
43
- enablePerfHooks: () => enablePerfHooks,
44
- getCommandFullName: () => getCommandFullName,
45
- registerMiddlewares: () => registerMiddlewares,
46
- tsxRerunning: () => tsxRerunning
47
- });
48
- module.exports = __toCommonJS(helper_exports);
49
- var import_cors = __toESM(require("@koa/cors"));
50
- var import_logger = require("@nocobase/logger");
51
- var import_resourcer = require("@nocobase/resourcer");
52
- var import_utils = require("@nocobase/utils");
53
- var import_crypto = require("crypto");
54
- var import_fs = __toESM(require("fs"));
55
- var import_i18next = __toESM(require("i18next"));
56
- var import_koa_bodyparser = __toESM(require("koa-bodyparser"));
57
- var import_path = require("path");
58
- var import_perf_hooks = require("perf_hooks");
59
- var import_data_wrapping = require("./middlewares/data-wrapping");
60
- var import_i18n = require("./middlewares/i18n");
61
- function createI18n(options) {
62
- const instance = import_i18next.default.createInstance();
63
- instance.init({
64
- lng: "en-US",
65
- resources: {},
66
- keySeparator: false,
67
- nsSeparator: false,
68
- ...options.i18n
69
- });
70
- return instance;
71
- }
72
- __name(createI18n, "createI18n");
73
- function createResourcer(options) {
74
- return new import_resourcer.Resourcer({ ...options.resourcer });
75
- }
76
- __name(createResourcer, "createResourcer");
77
- function registerMiddlewares(app, options) {
78
- var _a;
79
- app.use(async (ctx, next) => {
80
- app.context.reqId = (0, import_crypto.randomUUID)();
81
- await next();
82
- });
83
- app.use((0, import_logger.requestLogger)(app.name, app.requestLogger, (_a = options.logger) == null ? void 0 : _a.request), { tag: "logger" });
84
- app.use(
85
- (0, import_cors.default)({
86
- exposeHeaders: ["content-disposition"],
87
- ...options.cors
88
- }),
89
- {
90
- tag: "cors",
91
- after: "bodyParser"
92
- }
93
- );
94
- if (options.bodyParser !== false) {
95
- const bodyLimit = "10mb";
96
- app.use(
97
- (0, import_koa_bodyparser.default)({
98
- jsonLimit: bodyLimit,
99
- formLimit: bodyLimit,
100
- textLimit: bodyLimit,
101
- ...options.bodyParser
102
- }),
103
- {
104
- tag: "bodyParser",
105
- after: "logger"
106
- }
107
- );
108
- }
109
- app.use(async (ctx, next) => {
110
- ctx.getBearerToken = () => {
111
- const token = ctx.get("Authorization").replace(/^Bearer\s+/gi, "");
112
- return token || ctx.query.token;
113
- };
114
- await next();
115
- });
116
- app.use(import_i18n.i18n, { tag: "i18n", after: "cors" });
117
- if (options.dataWrapping !== false) {
118
- app.use((0, import_data_wrapping.dataWrapping)(), { tag: "dataWrapping", after: "i18n" });
119
- }
120
- app.use(app.dataSourceManager.middleware(), { tag: "dataSource", after: "dataWrapping" });
121
- }
122
- __name(registerMiddlewares, "registerMiddlewares");
123
- const createAppProxy = /* @__PURE__ */ __name((app) => {
124
- return new Proxy(app, {
125
- get(target, prop, ...args) {
126
- if (typeof prop === "string" && ["on", "once", "addListener"].includes(prop)) {
127
- return (eventName, listener) => {
128
- listener["_reinitializable"] = true;
129
- return target[prop](eventName, listener);
130
- };
131
- }
132
- return Reflect.get(target, prop, ...args);
133
- }
134
- });
135
- }, "createAppProxy");
136
- const getCommandFullName = /* @__PURE__ */ __name((command) => {
137
- const names = [];
138
- names.push(command.name());
139
- let parent = command == null ? void 0 : command.parent;
140
- while (parent) {
141
- if (!(parent == null ? void 0 : parent.parent)) {
142
- break;
143
- }
144
- names.unshift(parent.name());
145
- parent = parent.parent;
146
- }
147
- return names.join(".");
148
- }, "getCommandFullName");
149
- /* istanbul ignore next -- @preserve */
150
- const tsxRerunning = /* @__PURE__ */ __name(async () => {
151
- const file = (0, import_path.resolve)(process.cwd(), "storage/app.watch.ts");
152
- await import_fs.default.promises.writeFile(file, `export const watchId = '${(0, import_utils.uid)()}';`, "utf-8");
153
- }, "tsxRerunning");
154
- /* istanbul ignore next -- @preserve */
155
- const enablePerfHooks = /* @__PURE__ */ __name((app) => {
156
- app.context.getPerfHistogram = (name) => {
157
- if (!app.perfHistograms.has(name)) {
158
- app.perfHistograms.set(name, (0, import_perf_hooks.createHistogram)());
159
- }
160
- return app.perfHistograms.get(name);
161
- };
162
- app.resourcer.define({
163
- name: "perf",
164
- actions: {
165
- view: async (ctx, next) => {
166
- const result = {};
167
- const histograms = ctx.app.perfHistograms;
168
- const sortedHistograms = [...histograms.entries()].sort(([i, a], [j, b]) => b.mean - a.mean);
169
- sortedHistograms.forEach(([name, histogram]) => {
170
- result[name] = histogram;
171
- });
172
- ctx.body = result;
173
- await next();
174
- },
175
- reset: async (ctx, next) => {
176
- const histograms = ctx.app.perfHistograms;
177
- histograms.forEach((histogram) => histogram.reset());
178
- await next();
179
- }
180
- }
181
- });
182
- app.acl.allow("perf", "*", "public");
183
- }, "enablePerfHooks");
184
- // Annotate the CommonJS export names for ESM import in node:
185
- 0 && (module.exports = {
186
- createAppProxy,
187
- createI18n,
188
- createResourcer,
189
- enablePerfHooks,
190
- getCommandFullName,
191
- registerMiddlewares,
192
- tsxRerunning
193
- });
@@ -1,18 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Collection } from '@nocobase/database';
10
- import Application from '../application';
11
- export declare class ApplicationVersion {
12
- protected app: Application;
13
- protected collection: Collection;
14
- constructor(app: Application);
15
- get(): Promise<any>;
16
- update(version?: string): Promise<void>;
17
- satisfies(range: string): Promise<boolean>;
18
- }