alemonjs 2.1.68 → 2.1.70
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/bin/alemonc.js +15 -8
- package/lib/app/event-processor.js +2 -1
- package/lib/app/index.d.ts +1 -0
- package/lib/app/index.js +4 -0
- package/lib/app/router/dsl.d.ts +61 -0
- package/lib/app/router/dsl.js +722 -0
- package/lib/app/router/fallback.d.ts +12 -0
- package/lib/app/router/fallback.js +85 -0
- package/lib/app/router/main.d.ts +7 -0
- package/lib/app/router/main.js +4 -0
- package/lib/app/router/parser.d.ts +8 -0
- package/lib/app/router/parser.js +24 -0
- package/lib/app/router/types.d.ts +102 -0
- package/lib/app/router/types.js +1 -0
- package/lib/app/router/validator.d.ts +50 -0
- package/lib/app/router/validator.js +306 -0
- package/lib/index.js +4 -0
- package/package.json +1 -1
package/bin/alemonc.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
2
|
+
import {updateConfig} from './updateConfig.js';
|
|
3
|
+
import {run} from './run.js';
|
|
4
|
+
import {start} from './start.js';
|
|
5
|
+
import {versionUpdate} from './versionUpdate.js';
|
|
6
|
+
import {info} from './info.js';
|
|
7
|
+
import {platformAdd, platformRemove, platformList} from './platform.js';
|
|
8
|
+
import {login} from './login.js';
|
|
9
|
+
import {Command} from 'commander';
|
|
10
10
|
const program = new Command();
|
|
11
11
|
|
|
12
12
|
program.name('alemonc').description('CLI to some alemonc actions and scripts').version('1.0.0');
|
|
@@ -67,6 +67,13 @@ program
|
|
|
67
67
|
versionUpdate();
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
+
program
|
|
71
|
+
.command('upgrade')
|
|
72
|
+
.description('检查并更新 alemonjs 和 @alemonjs/* 包到最新版本')
|
|
73
|
+
.action(() => {
|
|
74
|
+
versionUpdate();
|
|
75
|
+
});
|
|
76
|
+
|
|
70
77
|
program
|
|
71
78
|
.command('info')
|
|
72
79
|
.description('输出项目诊断信息')
|
|
@@ -93,7 +93,8 @@ const onProcessor = (name, event, data) => {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
const mappingText = value?.mapping_text ?? [];
|
|
96
|
-
if (event['MessageText']) {
|
|
96
|
+
if (event['MessageText'] && typeof event['MessageText'] === 'string') {
|
|
97
|
+
event['MessageText'] = event['MessageText'].trim();
|
|
97
98
|
for (const mapping of mappingText) {
|
|
98
99
|
const { regular, target } = mapping ?? {};
|
|
99
100
|
if (!regular) {
|
package/lib/app/index.d.ts
CHANGED
package/lib/app/index.js
CHANGED
|
@@ -39,4 +39,8 @@ export { registerAppDir, scheduleCancel, scheduleCancelAll, scheduleCancelByApp,
|
|
|
39
39
|
export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './event-utils.js';
|
|
40
40
|
export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
|
|
41
41
|
export { Format, FormatButtonGroup, FormatMarkDown, FormatSelect } from './message-format.js';
|
|
42
|
+
export { Router } from './router/dsl.js';
|
|
43
|
+
export { checkFallbackHint } from './router/fallback.js';
|
|
44
|
+
export { normalizeRoutePath, parseMessageText } from './router/parser.js';
|
|
45
|
+
export { validateRouteArgs } from './router/validator.js';
|
|
42
46
|
export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video } from './message-format-old.js';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AppDispatchResult, AppMatchResult, RegisteredRes, RegisteredRoute, RouteDefinitions, RouteGroupConditions, RouteImporter, RouteResConfig } from './types';
|
|
2
|
+
export type RouterOptions<P extends string = string, E extends string = string> = {
|
|
3
|
+
regular?: RegExp;
|
|
4
|
+
events?: readonly E[];
|
|
5
|
+
platforms?: readonly P[];
|
|
6
|
+
};
|
|
7
|
+
type GroupOptions<P extends string = string, E extends string = string> = RouteGroupConditions<P, E>;
|
|
8
|
+
declare class RouteGroup<P extends string, E extends string> {
|
|
9
|
+
private readonly app;
|
|
10
|
+
private readonly middlewares;
|
|
11
|
+
private readonly options;
|
|
12
|
+
private readonly scopeId;
|
|
13
|
+
constructor(app: Router<P, E>, middlewares: RouteImporter[], options: GroupOptions<P, E>, scopeId: string);
|
|
14
|
+
group(options: GroupOptions<P, E>, ...middlewares: RouteImporter[]): RouteGroup<P, E>;
|
|
15
|
+
use(config: RouteDefinitions<P, E>, ...importers: RouteImporter[]): RegisteredRoute<P, E> | RegisteredRoute<P, E>[];
|
|
16
|
+
}
|
|
17
|
+
export declare class Router<P extends string = string, E extends string = string> {
|
|
18
|
+
private readonly defaults;
|
|
19
|
+
private readonly globalImporters;
|
|
20
|
+
private readonly topLevelEntries;
|
|
21
|
+
private readonly scopes;
|
|
22
|
+
private readonly routes;
|
|
23
|
+
private defaultScopeId?;
|
|
24
|
+
constructor(options?: RouterOptions<P, E>);
|
|
25
|
+
static create<const P extends string, const E extends string>(options?: RouterOptions<P, E>): Router<P, E>;
|
|
26
|
+
group(options: GroupOptions<P, E>, ...middlewares: RouteImporter[]): RouteGroup<P, E>;
|
|
27
|
+
use(config: RouteDefinitions<P, E>, ...importers: RouteImporter[]): RegisteredRoute<P, E> | RegisteredRoute<P, E>[];
|
|
28
|
+
res(config: RouteResConfig<P, E>, ...importers: RouteImporter[]): RegisteredRes<P, E>[];
|
|
29
|
+
register(config: RouteDefinitions<P, E>, importers: RouteImporter[], inheritedOptions: GroupOptions<P, E>, scopeId: string): RegisteredRoute<P, E> | RegisteredRoute<P, E>[];
|
|
30
|
+
private registerOne;
|
|
31
|
+
inspect(): {
|
|
32
|
+
eventName: string;
|
|
33
|
+
routes: {
|
|
34
|
+
path: string;
|
|
35
|
+
importerCount: number;
|
|
36
|
+
}[];
|
|
37
|
+
}[];
|
|
38
|
+
get values(): any[];
|
|
39
|
+
get define(): {
|
|
40
|
+
current: import("../..").ResponseRoute[];
|
|
41
|
+
};
|
|
42
|
+
match(event: {
|
|
43
|
+
name?: string;
|
|
44
|
+
MessageText?: string;
|
|
45
|
+
platform?: string;
|
|
46
|
+
}, scopeId?: string): AppMatchResult;
|
|
47
|
+
dispatch(event: Record<string, unknown>, depth?: number): Promise<AppDispatchResult>;
|
|
48
|
+
dispatchInScope(event: Record<string, unknown>, scopeId: string | undefined, depth?: number): Promise<AppDispatchResult>;
|
|
49
|
+
handleScopeEvent(scopeId: string, event: Record<string, unknown>, next: () => void | Promise<void>): Promise<void>;
|
|
50
|
+
handleFallbackEvent(event: Record<string, unknown>, next: () => void | Promise<void>): Promise<void>;
|
|
51
|
+
private replyValidationFailure;
|
|
52
|
+
private buildTopLevelEntries;
|
|
53
|
+
private buildResEntriesFor;
|
|
54
|
+
private buildScopeEntriesFor;
|
|
55
|
+
private buildFallbackEntry;
|
|
56
|
+
private ensureDefaultScope;
|
|
57
|
+
private createScope;
|
|
58
|
+
private getApplicableScopeIds;
|
|
59
|
+
private runImporters;
|
|
60
|
+
}
|
|
61
|
+
export {};
|