@nocobase/server 2.1.0-alpha.40 → 2.1.0-alpha.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/app-supervisor/index.d.ts +13 -5
- package/lib/app-supervisor/index.js +33 -12
- package/lib/app-supervisor/main-only-adapter.d.ts +3 -0
- package/lib/app-supervisor/main-only-adapter.js +7 -0
- package/lib/app-supervisor/types.d.ts +18 -3
- package/lib/gateway/static-file-security.js +1 -1
- package/package.json +17 -17
|
@@ -13,7 +13,7 @@ import { IncomingMessage, ServerResponse } from 'http';
|
|
|
13
13
|
import { AsyncEmitter } from '@nocobase/utils';
|
|
14
14
|
import { EventEmitter } from 'events';
|
|
15
15
|
import Application, { ApplicationOptions } from '../application';
|
|
16
|
-
import type { AppDiscoveryAdapter, AppProcessAdapter, AppStatus, EnvironmentInfo, GetAppOptions, ProcessCommand, AppDbCreator, AppOptionsFactory, AppDbCreatorOptions, AppCommandAdapter, AppModel, BootstrapLock } from './types';
|
|
16
|
+
import type { AppDiscoveryAdapter, AppProcessAdapter, AppStatus, EnvironmentInfo, GetAppOptions, ProcessCommand, AppDbCreator, AppOptionsFactory, AppDbCreatorOptions, AppCommandAdapter, AppModel, BootstrapLock, AppCondition, GetAppsByConditionOptions } from './types';
|
|
17
17
|
import { Predicate } from './condition-registry';
|
|
18
18
|
import { PubSubManagerPublishOptions } from '../pub-sub-manager';
|
|
19
19
|
import { Transaction, Transactionable } from '@nocobase/database';
|
|
@@ -48,6 +48,7 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
|
|
|
48
48
|
private processAdapterName;
|
|
49
49
|
private commandAdapterName;
|
|
50
50
|
private appDbCreator;
|
|
51
|
+
private appConditions;
|
|
51
52
|
appOptionsFactory: AppOptionsFactory;
|
|
52
53
|
private environmentHeartbeatInterval;
|
|
53
54
|
private environmentHeartbeatTimer;
|
|
@@ -107,11 +108,15 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
|
|
|
107
108
|
getAppLastSeenAt(appName: string): Promise<number>;
|
|
108
109
|
addAppModel(appModel: AppModel): Promise<void>;
|
|
109
110
|
getAppModel(appName: string): Promise<AppModel>;
|
|
111
|
+
registerAppCondition(name: string, condition: AppCondition): void;
|
|
112
|
+
unregisterAppCondition(name: string): void;
|
|
113
|
+
getAppCondition(name: string): AppCondition;
|
|
114
|
+
getAppConditions(): [string, AppCondition][];
|
|
115
|
+
getAppsByCondition(conditionName: string, options?: GetAppsByConditionOptions): Promise<string[]>;
|
|
110
116
|
removeAppModel(appName: string): Promise<void>;
|
|
111
117
|
getAppNameByCName(cname: string): Promise<string>;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
removeAutoStartApps(environmentName: string, appNames: string[]): Promise<void>;
|
|
118
|
+
addAppsToCondition(conditionName: string, environmentName: string, appNames: string[]): Promise<void>;
|
|
119
|
+
removeAppsFromCondition(conditionName: string, environmentName: string, appNames: string[]): Promise<void>;
|
|
115
120
|
addApp(app: Application): Application<import("../application").DefaultState, import("../application").DefaultContext>;
|
|
116
121
|
getApp(appName: string, options?: GetAppOptions): Promise<Application<import("../application").DefaultState, import("../application").DefaultContext>>;
|
|
117
122
|
hasApp(appName: string): boolean;
|
|
@@ -134,6 +139,9 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
|
|
|
134
139
|
upgradeApp(appName: string, context?: {
|
|
135
140
|
requestId: string;
|
|
136
141
|
}): Promise<void>;
|
|
142
|
+
dispatchAppEvent(appName: string, event: string, payload?: any, context?: {
|
|
143
|
+
requestId: string;
|
|
144
|
+
}): Promise<void>;
|
|
137
145
|
/**
|
|
138
146
|
* @deprecated
|
|
139
147
|
* use {#getApps} instead
|
|
@@ -157,5 +165,5 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
|
|
|
157
165
|
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
158
166
|
private bindAppEvents;
|
|
159
167
|
}
|
|
160
|
-
export type { AppDiscoveryAdapter, AppProcessAdapter, AppCommandAdapter, AppStatus, ProcessCommand, EnvironmentInfo, GetAppOptions, AppDbCreator, AppOptionsFactory, AppModel, AppModelOptions, BootstrapLock, } from './types';
|
|
168
|
+
export type { AppDiscoveryAdapter, AppProcessAdapter, AppCommandAdapter, AppStatus, ProcessCommand, EnvironmentInfo, GetAppOptions, AppDbCreator, AppOptionsFactory, AppModel, AppModelOptions, AppCondition, GetAppsByConditionOptions, BootstrapLock, } from './types';
|
|
161
169
|
export { MainOnlyAdapter } from './main-only-adapter';
|
|
@@ -69,6 +69,7 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
69
69
|
processAdapterName;
|
|
70
70
|
commandAdapterName;
|
|
71
71
|
appDbCreator = new import_condition_registry.ConditionalRegistry();
|
|
72
|
+
appConditions = /* @__PURE__ */ new Map();
|
|
72
73
|
appOptionsFactory = import_app_options_factory.appOptionsFactory;
|
|
73
74
|
environmentHeartbeatInterval = 2 * 60 * 1e3;
|
|
74
75
|
environmentHeartbeatTimer = null;
|
|
@@ -420,6 +421,28 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
420
421
|
async getAppModel(appName) {
|
|
421
422
|
return this.discoveryAdapter.getAppModel(appName);
|
|
422
423
|
}
|
|
424
|
+
registerAppCondition(name, condition) {
|
|
425
|
+
this.appConditions.set(name, condition);
|
|
426
|
+
}
|
|
427
|
+
unregisterAppCondition(name) {
|
|
428
|
+
this.appConditions.delete(name);
|
|
429
|
+
}
|
|
430
|
+
getAppCondition(name) {
|
|
431
|
+
return this.appConditions.get(name);
|
|
432
|
+
}
|
|
433
|
+
getAppConditions() {
|
|
434
|
+
return Array.from(this.appConditions.entries());
|
|
435
|
+
}
|
|
436
|
+
async getAppsByCondition(conditionName, options = {}) {
|
|
437
|
+
const condition = this.getAppCondition(conditionName);
|
|
438
|
+
if (!condition || typeof this.discoveryAdapter.getAppsByCondition !== "function") {
|
|
439
|
+
return [];
|
|
440
|
+
}
|
|
441
|
+
return this.discoveryAdapter.getAppsByCondition(conditionName, condition, {
|
|
442
|
+
...options,
|
|
443
|
+
environmentName: options.allEnvironments ? options.environmentName : options.environmentName ?? this.environmentName
|
|
444
|
+
});
|
|
445
|
+
}
|
|
423
446
|
async removeAppModel(appName) {
|
|
424
447
|
if (typeof this.discoveryAdapter.removeAppModel !== "function") {
|
|
425
448
|
return;
|
|
@@ -432,23 +455,17 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
432
455
|
}
|
|
433
456
|
return this.discoveryAdapter.getAppNameByCName(cname);
|
|
434
457
|
}
|
|
435
|
-
async
|
|
436
|
-
if (typeof this.discoveryAdapter.
|
|
458
|
+
async addAppsToCondition(conditionName, environmentName, appNames) {
|
|
459
|
+
if (typeof this.discoveryAdapter.addAppsToCondition !== "function") {
|
|
437
460
|
return;
|
|
438
461
|
}
|
|
439
|
-
return this.discoveryAdapter.
|
|
440
|
-
}
|
|
441
|
-
async getAutoStartApps() {
|
|
442
|
-
if (typeof this.discoveryAdapter.getAutoStartApps === "function") {
|
|
443
|
-
return this.discoveryAdapter.getAutoStartApps(this.environmentName);
|
|
444
|
-
}
|
|
445
|
-
return [];
|
|
462
|
+
return this.discoveryAdapter.addAppsToCondition(conditionName, environmentName, appNames);
|
|
446
463
|
}
|
|
447
|
-
async
|
|
448
|
-
if (typeof this.discoveryAdapter.
|
|
464
|
+
async removeAppsFromCondition(conditionName, environmentName, appNames) {
|
|
465
|
+
if (typeof this.discoveryAdapter.removeAppsFromCondition !== "function") {
|
|
449
466
|
return;
|
|
450
467
|
}
|
|
451
|
-
return this.discoveryAdapter.
|
|
468
|
+
return this.discoveryAdapter.removeAppsFromCondition(conditionName, environmentName, appNames);
|
|
452
469
|
}
|
|
453
470
|
addApp(app) {
|
|
454
471
|
this.processAdapter.addApp(app);
|
|
@@ -477,6 +494,10 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
477
494
|
async upgradeApp(appName, context) {
|
|
478
495
|
await this.processAdapter.upgradeApp(appName, context);
|
|
479
496
|
}
|
|
497
|
+
async dispatchAppEvent(appName, event, payload, context) {
|
|
498
|
+
var _a, _b;
|
|
499
|
+
return (_b = (_a = this.processAdapter).dispatchAppEvent) == null ? void 0 : _b.call(_a, appName, event, payload, context);
|
|
500
|
+
}
|
|
480
501
|
/**
|
|
481
502
|
* @deprecated
|
|
482
503
|
* use {#getApps} instead
|
|
@@ -26,6 +26,9 @@ export declare class MainOnlyAdapter implements AppDiscoveryAdapter, AppProcessA
|
|
|
26
26
|
stopApp(appName: string): Promise<void>;
|
|
27
27
|
removeApp(appName: string): Promise<void>;
|
|
28
28
|
upgradeApp(appName: string): Promise<void>;
|
|
29
|
+
dispatchAppEvent(appName: string, event: string, payload?: any, _context?: {
|
|
30
|
+
requestId: string;
|
|
31
|
+
}): Promise<void>;
|
|
29
32
|
removeAllApps(): Promise<void>;
|
|
30
33
|
setAppStatus(appName: string, status: AppStatus, options?: {}): void;
|
|
31
34
|
getAppStatus(appName: string, defaultStatus?: AppStatus): AppStatus;
|
|
@@ -124,6 +124,13 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
|
|
|
124
124
|
}
|
|
125
125
|
await this.apps[appName].runCommand("upgrade");
|
|
126
126
|
}
|
|
127
|
+
async dispatchAppEvent(appName, event, payload, _context) {
|
|
128
|
+
const app = await this.getApp(appName, { withOutBootStrap: true });
|
|
129
|
+
if (!app) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
await app.emitAsync(event, payload);
|
|
133
|
+
}
|
|
127
134
|
async removeAllApps() {
|
|
128
135
|
return this.removeApp("main");
|
|
129
136
|
}
|
|
@@ -57,11 +57,23 @@ export type AppModelOptions = {
|
|
|
57
57
|
};
|
|
58
58
|
export type AppModel = {
|
|
59
59
|
name: string;
|
|
60
|
+
title?: string;
|
|
61
|
+
icon?: string;
|
|
60
62
|
cname?: string;
|
|
63
|
+
sort?: number;
|
|
64
|
+
pinned?: boolean;
|
|
61
65
|
environment?: string;
|
|
62
66
|
environments?: string[];
|
|
63
67
|
options: AppModelOptions;
|
|
64
68
|
};
|
|
69
|
+
export type AppCondition = {
|
|
70
|
+
filter?: Record<string, any>;
|
|
71
|
+
match?: (appModel: AppModel) => boolean;
|
|
72
|
+
};
|
|
73
|
+
export type GetAppsByConditionOptions = {
|
|
74
|
+
environmentName?: string;
|
|
75
|
+
allEnvironments?: boolean;
|
|
76
|
+
};
|
|
65
77
|
export type ProcessCommand = {
|
|
66
78
|
requestId: string;
|
|
67
79
|
appName: string;
|
|
@@ -102,9 +114,9 @@ export interface AppDiscoveryAdapter {
|
|
|
102
114
|
clearAppStatus?(appName: string): void | Promise<void>;
|
|
103
115
|
loadAppModels?(mainApp: Application): Promise<void>;
|
|
104
116
|
getAppsStatuses?(appNames?: string[]): Promise<AppStatusesResult> | AppStatusesResult;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
117
|
+
getAppsByCondition?(conditionName: string, condition: AppCondition, options?: GetAppsByConditionOptions): Promise<string[]>;
|
|
118
|
+
addAppsToCondition?(conditionName: string, environmentName: string, appNames: string[]): Promise<void>;
|
|
119
|
+
removeAppsFromCondition?(conditionName: string, environmentName: string, appNames: string[]): Promise<void>;
|
|
108
120
|
addAppModel?(appModel: AppModel): Promise<void>;
|
|
109
121
|
getAppModel?(appName: string): Promise<AppModel>;
|
|
110
122
|
removeAppModel?(appName: string): Promise<void>;
|
|
@@ -149,6 +161,9 @@ export interface AppProcessAdapter {
|
|
|
149
161
|
upgradeApp?(appName: string, context?: {
|
|
150
162
|
requestId: string;
|
|
151
163
|
}): Promise<void>;
|
|
164
|
+
dispatchAppEvent?(appName: string, event: string, payload?: any, context?: {
|
|
165
|
+
requestId: string;
|
|
166
|
+
}): Promise<void>;
|
|
152
167
|
removeAllApps?(): Promise<void>;
|
|
153
168
|
setAppError?(appName: string, error: Error): void;
|
|
154
169
|
hasAppError?(appName: string): boolean;
|
|
@@ -42,7 +42,7 @@ __export(static_file_security_exports, {
|
|
|
42
42
|
});
|
|
43
43
|
module.exports = __toCommonJS(static_file_security_exports);
|
|
44
44
|
var import_node_path = __toESM(require("node:path"));
|
|
45
|
-
const ACTIVE_CONTENT_EXTENSIONS = /* @__PURE__ */ new Set([".htm", ".html", ".svg", ".svgz", ".xhtml"]);
|
|
45
|
+
const ACTIVE_CONTENT_EXTENSIONS = /* @__PURE__ */ new Set([".htm", ".html", ".pdf", ".svg", ".svgz", ".xhtml"]);
|
|
46
46
|
function stripQueryAndHash(pathname = "") {
|
|
47
47
|
return pathname.split("?")[0].split("#")[0];
|
|
48
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.45",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -10,21 +10,21 @@
|
|
|
10
10
|
"@koa/cors": "^5.0.0",
|
|
11
11
|
"@koa/multer": "^3.1.0",
|
|
12
12
|
"@koa/router": "^13.1.0",
|
|
13
|
-
"@nocobase/acl": "2.1.0-alpha.
|
|
14
|
-
"@nocobase/actions": "2.1.0-alpha.
|
|
15
|
-
"@nocobase/ai": "2.1.0-alpha.
|
|
16
|
-
"@nocobase/auth": "2.1.0-alpha.
|
|
17
|
-
"@nocobase/cache": "2.1.0-alpha.
|
|
18
|
-
"@nocobase/data-source-manager": "2.1.0-alpha.
|
|
19
|
-
"@nocobase/database": "2.1.0-alpha.
|
|
20
|
-
"@nocobase/evaluators": "2.1.0-alpha.
|
|
21
|
-
"@nocobase/lock-manager": "2.1.0-alpha.
|
|
22
|
-
"@nocobase/logger": "2.1.0-alpha.
|
|
23
|
-
"@nocobase/resourcer": "2.1.0-alpha.
|
|
24
|
-
"@nocobase/sdk": "2.1.0-alpha.
|
|
25
|
-
"@nocobase/snowflake-id": "2.1.0-alpha.
|
|
26
|
-
"@nocobase/telemetry": "2.1.0-alpha.
|
|
27
|
-
"@nocobase/utils": "2.1.0-alpha.
|
|
13
|
+
"@nocobase/acl": "2.1.0-alpha.45",
|
|
14
|
+
"@nocobase/actions": "2.1.0-alpha.45",
|
|
15
|
+
"@nocobase/ai": "2.1.0-alpha.45",
|
|
16
|
+
"@nocobase/auth": "2.1.0-alpha.45",
|
|
17
|
+
"@nocobase/cache": "2.1.0-alpha.45",
|
|
18
|
+
"@nocobase/data-source-manager": "2.1.0-alpha.45",
|
|
19
|
+
"@nocobase/database": "2.1.0-alpha.45",
|
|
20
|
+
"@nocobase/evaluators": "2.1.0-alpha.45",
|
|
21
|
+
"@nocobase/lock-manager": "2.1.0-alpha.45",
|
|
22
|
+
"@nocobase/logger": "2.1.0-alpha.45",
|
|
23
|
+
"@nocobase/resourcer": "2.1.0-alpha.45",
|
|
24
|
+
"@nocobase/sdk": "2.1.0-alpha.45",
|
|
25
|
+
"@nocobase/snowflake-id": "2.1.0-alpha.45",
|
|
26
|
+
"@nocobase/telemetry": "2.1.0-alpha.45",
|
|
27
|
+
"@nocobase/utils": "2.1.0-alpha.45",
|
|
28
28
|
"@types/decompress": "4.2.7",
|
|
29
29
|
"@types/ini": "^1.3.31",
|
|
30
30
|
"@types/koa-send": "^4.1.3",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"@types/serve-handler": "^6.1.1",
|
|
62
62
|
"@types/ws": "^8.5.5"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "e9e24987e12d0ad10a5db8815b1e1b7b447f1938"
|
|
65
65
|
}
|