@nocobase/server 2.1.0-alpha.2 → 2.1.0-alpha.21
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/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/acl/available-action.js +1 -1
- package/lib/aes-encryptor.js +3 -2
- package/lib/ai/create-docs-index.js +2 -1
- package/lib/app-supervisor/app-options-factory.d.ts +1 -0
- package/lib/app-supervisor/index.js +15 -1
- package/lib/app-supervisor/main-only-adapter.d.ts +1 -1
- package/lib/app-supervisor/main-only-adapter.js +17 -12
- package/lib/application.d.ts +1 -2
- package/lib/application.js +3 -24
- package/lib/commands/create-migration.js +1 -1
- package/lib/commands/install.js +3 -1
- package/lib/commands/pm.js +7 -0
- package/lib/commands/start.js +2 -2
- package/lib/commands/upgrade.js +3 -1
- package/lib/event-queue.js +1 -1
- package/lib/gateway/index.d.ts +13 -3
- package/lib/gateway/index.js +137 -15
- package/lib/gateway/utils.d.ts +17 -0
- package/lib/gateway/utils.js +115 -0
- package/lib/helper.js +33 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/main-data-source.js +1 -1
- package/lib/plugin-manager/deps.js +2 -1
- package/lib/plugin-manager/options/resource.d.ts +11 -1
- package/lib/plugin-manager/options/resource.js +153 -53
- package/lib/plugin-manager/plugin-manager.d.ts +7 -2
- package/lib/plugin-manager/plugin-manager.js +56 -43
- package/lib/plugin-manager/utils.d.ts +7 -1
- package/lib/plugin-manager/utils.js +33 -9
- package/lib/plugin.js +47 -2
- package/lib/pub-sub-manager/handler-manager.d.ts +1 -0
- package/lib/pub-sub-manager/handler-manager.js +11 -0
- package/lib/pub-sub-manager/pub-sub-manager.js +2 -1
- package/lib/swagger/app.d.ts +102 -0
- package/lib/swagger/app.js +124 -0
- package/lib/swagger/base.d.ts +244 -0
- package/lib/swagger/base.js +292 -0
- package/lib/swagger/collections.d.ts +996 -0
- package/lib/swagger/collections.js +1264 -0
- package/lib/swagger/index.d.ts +1774 -0
- package/lib/swagger/index.js +70 -0
- package/lib/swagger/pm.d.ts +462 -0
- package/lib/swagger/pm.js +422 -0
- package/lib/sync-message-manager.js +8 -1
- package/lib/worker-mode.d.ts +19 -0
- package/lib/worker-mode.js +67 -0
- package/package.json +18 -18
- package/lib/swagger/index.json +0 -1569
package/lib/gateway/index.js
CHANGED
|
@@ -39,7 +39,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
39
39
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
40
40
|
var gateway_exports = {};
|
|
41
41
|
__export(gateway_exports, {
|
|
42
|
-
Gateway: () => Gateway
|
|
42
|
+
Gateway: () => Gateway,
|
|
43
|
+
getHost: () => import_utils4.getHost,
|
|
44
|
+
getHostname: () => import_utils4.getHostname
|
|
43
45
|
});
|
|
44
46
|
module.exports = __toCommonJS(gateway_exports);
|
|
45
47
|
var import_logger = require("@nocobase/logger");
|
|
@@ -54,6 +56,7 @@ var import_fs = __toESM(require("fs"));
|
|
|
54
56
|
var import_http = __toESM(require("http"));
|
|
55
57
|
var import_koa_compose = __toESM(require("koa-compose"));
|
|
56
58
|
var import_node_util = require("node:util");
|
|
59
|
+
var import_node_os = require("node:os");
|
|
57
60
|
var import_path = require("path");
|
|
58
61
|
var import_qs = __toESM(require("qs"));
|
|
59
62
|
var import_serve_handler = __toESM(require("serve-handler"));
|
|
@@ -63,16 +66,26 @@ var import_plugin_manager = require("../plugin-manager");
|
|
|
63
66
|
var import_errors = require("./errors");
|
|
64
67
|
var import_ipc_socket_client = require("./ipc-socket-client");
|
|
65
68
|
var import_ipc_socket_server = require("./ipc-socket-server");
|
|
69
|
+
var import_utils3 = require("./utils");
|
|
66
70
|
var import_ws_server = require("./ws-server");
|
|
67
71
|
var import_node_worker_threads = require("node:worker_threads");
|
|
68
72
|
var import_node_process = __toESM(require("node:process"));
|
|
73
|
+
var import_utils4 = require("./utils");
|
|
69
74
|
const compress = (0, import_node_util.promisify)((0, import_compression.default)());
|
|
75
|
+
function normalizeBasePath(path = "") {
|
|
76
|
+
const normalized = path.replace(/\/+/g, "/").replace(/\/$/, "");
|
|
77
|
+
return normalized || "/";
|
|
78
|
+
}
|
|
79
|
+
__name(normalizeBasePath, "normalizeBasePath");
|
|
70
80
|
function getSocketPath() {
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
81
|
+
const socketPath = import_node_process.default.env.SOCKET_PATH;
|
|
82
|
+
if (socketPath) {
|
|
83
|
+
return (0, import_path.isAbsolute)(socketPath) ? socketPath : (0, import_path.resolve)(import_node_process.default.cwd(), socketPath);
|
|
84
|
+
}
|
|
85
|
+
if (import_node_process.default.env.NOCOBASE_RUNNING_IN_DOCKER === "true") {
|
|
86
|
+
return (0, import_path.resolve)((0, import_node_os.homedir)(), ".nocobase", "gateway.sock");
|
|
74
87
|
}
|
|
75
|
-
return (0,
|
|
88
|
+
return (0, import_utils.storagePathJoin)("gateway.sock");
|
|
76
89
|
}
|
|
77
90
|
__name(getSocketPath, "getSocketPath");
|
|
78
91
|
const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
@@ -87,7 +100,8 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
87
100
|
loggers = new import_utils.Registry();
|
|
88
101
|
port = import_node_process.default.env.APP_PORT ? parseInt(import_node_process.default.env.APP_PORT) : null;
|
|
89
102
|
host = "0.0.0.0";
|
|
90
|
-
socketPath = (
|
|
103
|
+
socketPath = getSocketPath();
|
|
104
|
+
v2IndexTemplateCache = null;
|
|
91
105
|
terminating = false;
|
|
92
106
|
onTerminate = /* @__PURE__ */ __name(async (signal) => {
|
|
93
107
|
var _a;
|
|
@@ -119,7 +133,6 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
119
133
|
constructor() {
|
|
120
134
|
super();
|
|
121
135
|
this.reset();
|
|
122
|
-
this.socketPath = getSocketPath();
|
|
123
136
|
import_node_process.default.once("SIGTERM", this.onTerminate);
|
|
124
137
|
import_node_process.default.once("SIGINT", this.onTerminate);
|
|
125
138
|
}
|
|
@@ -151,14 +164,30 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
151
164
|
this.selectorMiddlewares = new import_utils.Toposort();
|
|
152
165
|
this.addAppSelectorMiddleware(
|
|
153
166
|
async (ctx, next) => {
|
|
154
|
-
var _a;
|
|
167
|
+
var _a, _b;
|
|
155
168
|
const { req } = ctx;
|
|
156
|
-
const
|
|
169
|
+
const parsedUrl = (0, import_url.parse)(req.url);
|
|
170
|
+
const appName = (_a = import_qs.default.parse(parsedUrl.query)) == null ? void 0 : _a.__appName;
|
|
171
|
+
const apiBasePath = normalizeBasePath(import_node_process.default.env.API_BASE_PATH || "/api");
|
|
172
|
+
const appPathPrefix = `${apiBasePath}/__app/`;
|
|
173
|
+
if (req.headers["x-app"]) {
|
|
174
|
+
ctx.resolvedAppName = req.headers["x-app"];
|
|
175
|
+
}
|
|
157
176
|
if (appName) {
|
|
158
177
|
ctx.resolvedAppName = appName;
|
|
159
178
|
}
|
|
160
|
-
if (
|
|
161
|
-
|
|
179
|
+
if ((_b = parsedUrl.pathname) == null ? void 0 : _b.startsWith(appPathPrefix)) {
|
|
180
|
+
const restPath = parsedUrl.pathname.slice(appPathPrefix.length);
|
|
181
|
+
const [pathAppName, ...segments] = restPath.split("/");
|
|
182
|
+
if (pathAppName) {
|
|
183
|
+
ctx.resolvedAppName = pathAppName;
|
|
184
|
+
const rewrittenPath = `${apiBasePath}${segments.length ? `/${segments.join("/")}` : ""}`;
|
|
185
|
+
const rewrittenUrl = `${rewrittenPath}${parsedUrl.search || ""}`;
|
|
186
|
+
if (!req.originalUrl) {
|
|
187
|
+
req.originalUrl = req.url;
|
|
188
|
+
}
|
|
189
|
+
req.url = rewrittenUrl;
|
|
190
|
+
}
|
|
162
191
|
}
|
|
163
192
|
await next();
|
|
164
193
|
},
|
|
@@ -222,9 +251,79 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
222
251
|
});
|
|
223
252
|
this.responseError(res, error);
|
|
224
253
|
}
|
|
254
|
+
getV2PublicPath() {
|
|
255
|
+
return (0, import_utils3.resolveV2PublicPath)(import_node_process.default.env.APP_PUBLIC_PATH || "/");
|
|
256
|
+
}
|
|
257
|
+
getAppPublicPath() {
|
|
258
|
+
return (0, import_utils3.resolvePublicPath)(import_node_process.default.env.APP_PUBLIC_PATH || "/");
|
|
259
|
+
}
|
|
260
|
+
isV2Request(pathname) {
|
|
261
|
+
const v2PublicPath = this.getV2PublicPath();
|
|
262
|
+
return pathname === v2PublicPath.slice(0, -1) || pathname.startsWith(v2PublicPath);
|
|
263
|
+
}
|
|
264
|
+
isV2IndexRequest(pathname) {
|
|
265
|
+
if (!this.isV2Request(pathname)) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
const v2PublicPath = this.getV2PublicPath();
|
|
269
|
+
if (pathname === v2PublicPath || pathname === v2PublicPath.slice(0, -1) || pathname === `${v2PublicPath}index.html`) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
return !(0, import_path.extname)(pathname);
|
|
273
|
+
}
|
|
274
|
+
getV2RuntimeConfig() {
|
|
275
|
+
return {
|
|
276
|
+
__nocobase_public_path__: this.getV2PublicPath(),
|
|
277
|
+
__nocobase_api_base_url__: import_node_process.default.env.API_BASE_URL || import_node_process.default.env.API_BASE_PATH,
|
|
278
|
+
__nocobase_api_client_storage_prefix__: import_node_process.default.env.API_CLIENT_STORAGE_PREFIX,
|
|
279
|
+
__nocobase_api_client_storage_type__: import_node_process.default.env.API_CLIENT_STORAGE_TYPE,
|
|
280
|
+
__nocobase_api_client_share_token__: import_node_process.default.env.API_CLIENT_SHARE_TOKEN === "true",
|
|
281
|
+
__nocobase_ws_url__: import_node_process.default.env.WEBSOCKET_URL || "",
|
|
282
|
+
__nocobase_ws_path__: import_node_process.default.env.WS_PATH,
|
|
283
|
+
__esm_cdn_base_url__: import_node_process.default.env.ESM_CDN_BASE_URL || "https://esm.sh",
|
|
284
|
+
__esm_cdn_suffix__: import_node_process.default.env.ESM_CDN_SUFFIX || ""
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
getV2RuntimeConfigScript() {
|
|
288
|
+
const runtimeConfig = this.getV2RuntimeConfig();
|
|
289
|
+
const scriptContent = Object.entries(runtimeConfig).map(([key, value]) => `window['${key}'] = ${JSON.stringify(value)};`).join("\n");
|
|
290
|
+
return `<script>${scriptContent}</script>`;
|
|
291
|
+
}
|
|
292
|
+
getV2AssetPublicPath() {
|
|
293
|
+
if (import_node_process.default.env.CDN_BASE_URL) {
|
|
294
|
+
return `${import_node_process.default.env.CDN_BASE_URL.replace(/\/+$/, "")}/v2/`;
|
|
295
|
+
}
|
|
296
|
+
return this.getV2PublicPath();
|
|
297
|
+
}
|
|
298
|
+
getV2IndexTemplate() {
|
|
299
|
+
const file = `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client/v2/index.html`;
|
|
300
|
+
if (!import_fs.default.existsSync(file)) {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
const stat = import_fs.default.statSync(file);
|
|
304
|
+
if (this.v2IndexTemplateCache && this.v2IndexTemplateCache.file === file && this.v2IndexTemplateCache.mtimeMs === stat.mtimeMs) {
|
|
305
|
+
return this.v2IndexTemplateCache.html;
|
|
306
|
+
}
|
|
307
|
+
const html = import_fs.default.readFileSync(file, "utf-8");
|
|
308
|
+
this.v2IndexTemplateCache = {
|
|
309
|
+
file,
|
|
310
|
+
mtimeMs: stat.mtimeMs,
|
|
311
|
+
html
|
|
312
|
+
};
|
|
313
|
+
return html;
|
|
314
|
+
}
|
|
315
|
+
renderV2IndexHtml() {
|
|
316
|
+
const template = this.getV2IndexTemplate();
|
|
317
|
+
if (!template) {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
const html = (0, import_utils3.rewriteV2AssetPublicPath)(template, this.getV2AssetPublicPath());
|
|
321
|
+
return (0, import_utils3.injectRuntimeScript)(html, this.getV2RuntimeConfigScript());
|
|
322
|
+
}
|
|
225
323
|
async requestHandler(req, res) {
|
|
226
324
|
const { pathname } = (0, import_url.parse)(req.url);
|
|
227
|
-
const { PLUGIN_STATICS_PATH
|
|
325
|
+
const { PLUGIN_STATICS_PATH } = import_node_process.default.env;
|
|
326
|
+
const APP_PUBLIC_PATH = this.getAppPublicPath();
|
|
228
327
|
if (pathname.endsWith("/__umi/api/bundle-status")) {
|
|
229
328
|
res.statusCode = 200;
|
|
230
329
|
res.end("ok");
|
|
@@ -246,10 +345,10 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
246
345
|
return;
|
|
247
346
|
}
|
|
248
347
|
}
|
|
249
|
-
req.url = req.url.substring(APP_PUBLIC_PATH.length
|
|
348
|
+
req.url = req.url.substring(APP_PUBLIC_PATH.length + "storage".length);
|
|
250
349
|
await compress(req, res);
|
|
251
350
|
return (0, import_serve_handler.default)(req, res, {
|
|
252
|
-
public: (0,
|
|
351
|
+
public: (0, import_utils.resolveStorageRoot)(),
|
|
253
352
|
directoryListing: false
|
|
254
353
|
});
|
|
255
354
|
}
|
|
@@ -275,6 +374,27 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
275
374
|
});
|
|
276
375
|
}
|
|
277
376
|
if (!pathname.startsWith(import_node_process.default.env.API_BASE_PATH)) {
|
|
377
|
+
if (this.isV2Request(pathname)) {
|
|
378
|
+
if (handleApp !== "main") {
|
|
379
|
+
const isProxy = await supervisor.proxyWeb(handleApp, req, res);
|
|
380
|
+
if (isProxy) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (this.isV2IndexRequest(pathname)) {
|
|
385
|
+
const v2Html = this.renderV2IndexHtml();
|
|
386
|
+
if (v2Html) {
|
|
387
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
388
|
+
res.end(v2Html);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
req.url = req.url.substring(APP_PUBLIC_PATH.length - 1);
|
|
393
|
+
await compress(req, res);
|
|
394
|
+
return (0, import_serve_handler.default)(req, res, {
|
|
395
|
+
public: `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client`
|
|
396
|
+
});
|
|
397
|
+
}
|
|
278
398
|
if (handleApp !== "main") {
|
|
279
399
|
const isProxy = await supervisor.proxyWeb(handleApp, req, res);
|
|
280
400
|
if (isProxy) {
|
|
@@ -541,5 +661,7 @@ __publicField(_Gateway, "wsServers", []);
|
|
|
541
661
|
let Gateway = _Gateway;
|
|
542
662
|
// Annotate the CommonJS export names for ESM import in node:
|
|
543
663
|
0 && (module.exports = {
|
|
544
|
-
Gateway
|
|
664
|
+
Gateway,
|
|
665
|
+
getHost,
|
|
666
|
+
getHostname
|
|
545
667
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { IncomingMessage } from 'http';
|
|
11
|
+
import { IncomingRequest } from '.';
|
|
12
|
+
export declare function resolvePublicPath(appPublicPath?: string): string;
|
|
13
|
+
export declare function resolveV2PublicPath(appPublicPath?: string): string;
|
|
14
|
+
export declare function rewriteV2AssetPublicPath(html: string, assetPublicPath: string): string;
|
|
15
|
+
export declare function injectRuntimeScript(html: string, runtimeScript: string): string;
|
|
16
|
+
export declare function getHost(req: IncomingMessage | IncomingRequest): any;
|
|
17
|
+
export declare function getHostname(req: IncomingMessage | IncomingRequest): any;
|
|
@@ -0,0 +1,115 @@
|
|
|
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 __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var utils_exports = {};
|
|
29
|
+
__export(utils_exports, {
|
|
30
|
+
getHost: () => getHost,
|
|
31
|
+
getHostname: () => getHostname,
|
|
32
|
+
injectRuntimeScript: () => injectRuntimeScript,
|
|
33
|
+
resolvePublicPath: () => resolvePublicPath,
|
|
34
|
+
resolveV2PublicPath: () => resolveV2PublicPath,
|
|
35
|
+
rewriteV2AssetPublicPath: () => rewriteV2AssetPublicPath
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(utils_exports);
|
|
38
|
+
function resolvePublicPath(appPublicPath = "/") {
|
|
39
|
+
const normalized = String(appPublicPath || "/").trim() || "/";
|
|
40
|
+
const withLeadingSlash = normalized.startsWith("/") ? normalized : `/${normalized}`;
|
|
41
|
+
return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
|
|
42
|
+
}
|
|
43
|
+
__name(resolvePublicPath, "resolvePublicPath");
|
|
44
|
+
function resolveV2PublicPath(appPublicPath = "/") {
|
|
45
|
+
const publicPath = resolvePublicPath(appPublicPath);
|
|
46
|
+
return `${publicPath.replace(/\/$/, "")}/v2/`;
|
|
47
|
+
}
|
|
48
|
+
__name(resolveV2PublicPath, "resolveV2PublicPath");
|
|
49
|
+
function ensureTrailingSlash(value) {
|
|
50
|
+
return value.endsWith("/") ? value : `${value}/`;
|
|
51
|
+
}
|
|
52
|
+
__name(ensureTrailingSlash, "ensureTrailingSlash");
|
|
53
|
+
function rewriteV2AssetPublicPath(html, assetPublicPath) {
|
|
54
|
+
const normalizedAssetPublicPath = ensureTrailingSlash(assetPublicPath);
|
|
55
|
+
if (normalizedAssetPublicPath === "/v2/") {
|
|
56
|
+
return html;
|
|
57
|
+
}
|
|
58
|
+
return html.replace(/((?:src|href)=["'])\/v2\//g, `$1${normalizedAssetPublicPath}`);
|
|
59
|
+
}
|
|
60
|
+
__name(rewriteV2AssetPublicPath, "rewriteV2AssetPublicPath");
|
|
61
|
+
function injectRuntimeScript(html, runtimeScript) {
|
|
62
|
+
const browserCheckerScriptMatch = html.match(/<script\b[^>]*browser-checker\.js[^>]*><\/script>/i);
|
|
63
|
+
if (browserCheckerScriptMatch == null ? void 0 : browserCheckerScriptMatch[0]) {
|
|
64
|
+
return html.replace(browserCheckerScriptMatch[0], `${runtimeScript}
|
|
65
|
+
${browserCheckerScriptMatch[0]}`);
|
|
66
|
+
}
|
|
67
|
+
const moduleScriptMatch = html.match(/<script\b[^>]*type=["']module["'][^>]*>/i);
|
|
68
|
+
if (moduleScriptMatch == null ? void 0 : moduleScriptMatch[0]) {
|
|
69
|
+
return html.replace(moduleScriptMatch[0], `${runtimeScript}
|
|
70
|
+
${moduleScriptMatch[0]}`);
|
|
71
|
+
}
|
|
72
|
+
if (html.includes("</head>")) {
|
|
73
|
+
return html.replace("</head>", `${runtimeScript}
|
|
74
|
+
</head>`);
|
|
75
|
+
}
|
|
76
|
+
return `${runtimeScript}
|
|
77
|
+
${html}`;
|
|
78
|
+
}
|
|
79
|
+
__name(injectRuntimeScript, "injectRuntimeScript");
|
|
80
|
+
function splitCommaSeparatedValues(value, limit) {
|
|
81
|
+
return value.split(",", limit).map((v) => v.trim());
|
|
82
|
+
}
|
|
83
|
+
__name(splitCommaSeparatedValues, "splitCommaSeparatedValues");
|
|
84
|
+
function getHost(req) {
|
|
85
|
+
let host = req.headers["x-forwarded-host"];
|
|
86
|
+
if (!host) {
|
|
87
|
+
host = req.headers[":authority"] || req.headers["host"];
|
|
88
|
+
}
|
|
89
|
+
if (!host) return "";
|
|
90
|
+
host = splitCommaSeparatedValues(host, 1)[0];
|
|
91
|
+
if (host.includes("@")) {
|
|
92
|
+
try {
|
|
93
|
+
host = new URL(`http://${host}`).host;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return host;
|
|
99
|
+
}
|
|
100
|
+
__name(getHost, "getHost");
|
|
101
|
+
function getHostname(req) {
|
|
102
|
+
const host = getHost(req);
|
|
103
|
+
if (!host) return "";
|
|
104
|
+
return host.split(":", 1)[0];
|
|
105
|
+
}
|
|
106
|
+
__name(getHostname, "getHostname");
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
getHost,
|
|
110
|
+
getHostname,
|
|
111
|
+
injectRuntimeScript,
|
|
112
|
+
resolvePublicPath,
|
|
113
|
+
resolveV2PublicPath,
|
|
114
|
+
rewriteV2AssetPublicPath
|
|
115
|
+
});
|
package/lib/helper.js
CHANGED
|
@@ -239,14 +239,46 @@ function isNumeric(str) {
|
|
|
239
239
|
return !isNaN(str) && !isNaN(parseFloat(str));
|
|
240
240
|
}
|
|
241
241
|
__name(isNumeric, "isNumeric");
|
|
242
|
+
function getFieldFromCollectionManager(ctx, resourceName, fieldPath) {
|
|
243
|
+
var _a;
|
|
244
|
+
const collectionManager = (_a = ctx.dataSource) == null ? void 0 : _a.collectionManager;
|
|
245
|
+
if (!(collectionManager == null ? void 0 : collectionManager.getCollection)) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const collection = collectionManager.getCollection(resourceName);
|
|
249
|
+
if (!(collection == null ? void 0 : collection.getField)) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const [firstName, ...others] = fieldPath.split(".");
|
|
253
|
+
let field = collection.getField(firstName);
|
|
254
|
+
if (!field || !others.length) {
|
|
255
|
+
return field;
|
|
256
|
+
}
|
|
257
|
+
let currentCollection = typeof field.targetCollection === "function" ? field.targetCollection() : field.targetCollection;
|
|
258
|
+
for (const name of others) {
|
|
259
|
+
if (!(currentCollection == null ? void 0 : currentCollection.getField)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
field = currentCollection.getField(name);
|
|
263
|
+
if (!field) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
currentCollection = typeof field.targetCollection === "function" ? field.targetCollection() : field.targetCollection;
|
|
267
|
+
}
|
|
268
|
+
return field;
|
|
269
|
+
}
|
|
270
|
+
__name(getFieldFromCollectionManager, "getFieldFromCollectionManager");
|
|
242
271
|
function createContextVariablesScope(ctx) {
|
|
243
272
|
const state = JSON.parse(JSON.stringify(ctx.state));
|
|
244
273
|
return {
|
|
245
274
|
timezone: ctx.get("x-timezone"),
|
|
246
275
|
now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
247
276
|
getField: /* @__PURE__ */ __name((path) => {
|
|
248
|
-
const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
|
|
249
277
|
const { resourceName } = ctx.action;
|
|
278
|
+
const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
|
|
279
|
+
if (!ctx.database) {
|
|
280
|
+
return getFieldFromCollectionManager(ctx, resourceName, fieldPath);
|
|
281
|
+
}
|
|
250
282
|
return ctx.database.getFieldByPath(`${resourceName}.${fieldPath}`);
|
|
251
283
|
}, "getField"),
|
|
252
284
|
vars: {
|
package/lib/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from './plugin-manager';
|
|
|
20
20
|
export * from './pub-sub-manager';
|
|
21
21
|
export * from './event-queue';
|
|
22
22
|
export * from './worker-id-allocator';
|
|
23
|
+
export * from './worker-mode';
|
|
23
24
|
export * from './redis-connection-manager';
|
|
24
25
|
export * from './main-data-source';
|
|
25
26
|
export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
package/lib/index.js
CHANGED
|
@@ -63,6 +63,7 @@ __reExport(src_exports, require("./plugin-manager"), module.exports);
|
|
|
63
63
|
__reExport(src_exports, require("./pub-sub-manager"), module.exports);
|
|
64
64
|
__reExport(src_exports, require("./event-queue"), module.exports);
|
|
65
65
|
__reExport(src_exports, require("./worker-id-allocator"), module.exports);
|
|
66
|
+
__reExport(src_exports, require("./worker-mode"), module.exports);
|
|
66
67
|
__reExport(src_exports, require("./redis-connection-manager"), module.exports);
|
|
67
68
|
__reExport(src_exports, require("./main-data-source"), module.exports);
|
|
68
69
|
var import_findPackageNames = require("./plugin-manager/findPackageNames");
|
|
@@ -92,6 +93,7 @@ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
|
|
|
92
93
|
...require("./pub-sub-manager"),
|
|
93
94
|
...require("./event-queue"),
|
|
94
95
|
...require("./worker-id-allocator"),
|
|
96
|
+
...require("./worker-mode"),
|
|
95
97
|
...require("./redis-connection-manager"),
|
|
96
98
|
...require("./main-data-source")
|
|
97
99
|
});
|
package/lib/main-data-source.js
CHANGED
|
@@ -122,7 +122,7 @@ const _MainDataSource = class _MainDataSource extends import_data_source_manager
|
|
|
122
122
|
const loadedData = {};
|
|
123
123
|
for (const collection of collections) {
|
|
124
124
|
const c = db.getCollection(collection.name);
|
|
125
|
-
loadedData[c.tableName
|
|
125
|
+
loadedData[c.model.tableName] = {
|
|
126
126
|
...collection.toJSON(),
|
|
127
127
|
fields: collection.fields.map((field) => {
|
|
128
128
|
const f = c.getField(field.name);
|
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
export type PluginClientLane = 'client' | 'client-v2';
|
|
10
|
+
export declare class PackageUrls {
|
|
11
|
+
static items: Record<string, string | undefined>;
|
|
12
|
+
static clear(): void;
|
|
13
|
+
static getCacheKey(packageName: string, lane: PluginClientLane): string;
|
|
14
|
+
static get(packageName: string, lane?: PluginClientLane): Promise<string>;
|
|
15
|
+
static hasClientEntry(packageName: string, lane: PluginClientLane): Promise<boolean>;
|
|
16
|
+
static fetch(packageName: string, lane?: PluginClientLane): Promise<string>;
|
|
17
|
+
}
|
|
9
18
|
declare const _default: {
|
|
10
19
|
name: string;
|
|
11
20
|
actions: {
|
|
@@ -15,8 +24,9 @@ declare const _default: {
|
|
|
15
24
|
enable(ctx: any, next: any): Promise<void>;
|
|
16
25
|
disable(ctx: any, next: any): Promise<void>;
|
|
17
26
|
remove(ctx: any, next: any): Promise<void>;
|
|
18
|
-
list(ctx: any, next: any): Promise<
|
|
27
|
+
list(ctx: any, next: any): Promise<any>;
|
|
19
28
|
listEnabled(ctx: any, next: any): Promise<void>;
|
|
29
|
+
listEnabledV2(ctx: any, next: any): Promise<void>;
|
|
20
30
|
get(ctx: any, next: any): Promise<void>;
|
|
21
31
|
};
|
|
22
32
|
};
|