alemonjs 2.1.41 → 2.1.42

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 (80) hide show
  1. package/lib/app/define/define-children.d.ts +8 -0
  2. package/lib/app/define/define-children.js +25 -0
  3. package/lib/app/define/define-middleware.d.ts +2 -0
  4. package/lib/app/define/define-middleware.js +8 -0
  5. package/lib/app/define/define-platform.d.ts +13 -0
  6. package/lib/app/define/define-platform.js +40 -0
  7. package/lib/app/define/define-response.d.ts +2 -0
  8. package/lib/app/define/define-response.js +8 -0
  9. package/lib/app/define/define-router.d.ts +17 -0
  10. package/lib/app/define/define-router.js +34 -0
  11. package/lib/app/event/event-group.d.ts +9 -0
  12. package/lib/app/event/event-group.js +29 -0
  13. package/lib/app/event/event-middleware.d.ts +23 -0
  14. package/lib/app/event/event-middleware.js +44 -0
  15. package/lib/app/event/event-response.d.ts +16 -0
  16. package/lib/app/event/event-response.js +23 -0
  17. package/lib/app/event/event-selects.d.ts +13 -0
  18. package/lib/app/event/event-selects.js +15 -0
  19. package/lib/app/event-processor/event-processor-callHandler.d.ts +1 -0
  20. package/lib/app/event-processor/event-processor-callHandler.js +43 -0
  21. package/lib/app/event-processor/event-processor-cycle.d.ts +14 -0
  22. package/lib/app/event-processor/event-processor-cycle.js +97 -0
  23. package/lib/app/event-processor/event-processor-cycleFiles.d.ts +11 -0
  24. package/lib/app/event-processor/event-processor-cycleFiles.js +147 -0
  25. package/lib/app/event-processor/event-processor-cycleRoute.d.ts +10 -0
  26. package/lib/app/event-processor/event-processor-cycleRoute.js +133 -0
  27. package/lib/app/event-processor/event-processor-event.d.ts +24 -0
  28. package/lib/app/event-processor/event-processor-event.js +41 -0
  29. package/lib/app/event-processor/event-processor-middleware.d.ts +14 -0
  30. package/lib/app/event-processor/event-processor-middleware.js +31 -0
  31. package/lib/app/event-processor/event-processor-subscribe.d.ts +35 -0
  32. package/lib/app/event-processor/event-processor-subscribe.js +115 -0
  33. package/lib/app/event-processor/event-processor.d.ts +17 -0
  34. package/lib/app/event-processor/event-processor.js +207 -0
  35. package/lib/app/hook-use/hook-use-api.d.ts +6 -0
  36. package/lib/app/hook-use/hook-use-api.js +22 -0
  37. package/lib/app/hook-use/hook-use-channel.d.ts +8 -0
  38. package/lib/app/hook-use/hook-use-channel.js +33 -0
  39. package/lib/app/hook-use/hook-use-client.d.ts +7 -0
  40. package/lib/app/hook-use/hook-use-client.js +27 -0
  41. package/lib/app/hook-use/hook-use-me.d.ts +8 -0
  42. package/lib/app/hook-use/hook-use-me.js +45 -0
  43. package/lib/app/hook-use/hook-use-menber.d.ts +8 -0
  44. package/lib/app/hook-use/hook-use-menber.js +59 -0
  45. package/lib/app/hook-use/hook-use-mention.d.ts +23 -0
  46. package/lib/app/hook-use/hook-use-mention.js +105 -0
  47. package/lib/app/hook-use/hook-use-message.d.ts +29 -0
  48. package/lib/app/hook-use/hook-use-message.js +88 -0
  49. package/lib/app/hook-use/hook-use-state.d.ts +30 -0
  50. package/lib/app/hook-use/hook-use-state.js +101 -0
  51. package/lib/app/hook-use/hook-use-subscribe.d.ts +46 -0
  52. package/lib/app/hook-use/hook-use-subscribe.js +143 -0
  53. package/lib/app/hook-use-api.d.ts +1 -3
  54. package/lib/app/hook-use-api.js +3 -3
  55. package/lib/app/index.js +1 -1
  56. package/lib/app/message/message-api.d.ts +69 -0
  57. package/lib/app/message/message-api.js +105 -0
  58. package/lib/app/message/message-format-old.d.ts +143 -0
  59. package/lib/app/message/message-format-old.js +359 -0
  60. package/lib/app/message/message-format.d.ts +215 -0
  61. package/lib/app/message/message-format.js +382 -0
  62. package/lib/app/message-api.d.ts +13 -0
  63. package/lib/app/message-api.js +47 -1
  64. package/lib/app/message-format.old.d.ts +50 -0
  65. package/lib/app/message-format.old.js +217 -0
  66. package/lib/cbp/processor/handle.d.ts +3 -0
  67. package/lib/cbp/processor/handle.js +32 -0
  68. package/lib/index.js +1 -1
  69. package/lib/jsx/index.d.ts +105 -0
  70. package/lib/jsx/index.js +211 -0
  71. package/lib/jsx/jsx-dev-runtime.d.ts +2 -0
  72. package/lib/jsx/jsx-dev-runtime.js +1 -0
  73. package/lib/jsx/jsx-runtime.d.ts +18 -0
  74. package/lib/jsx/jsx-runtime.js +24 -0
  75. package/lib/process/client.js +109 -0
  76. package/lib/store/SinglyLinkedList.d.ts +22 -0
  77. package/lib/store/SinglyLinkedList.js +97 -0
  78. package/lib/store/store.d.ts +127 -0
  79. package/lib/store/store.js +443 -0
  80. package/package.json +1 -1
@@ -0,0 +1,382 @@
1
+ import { BT, MD, Text, Image, Mention, MarkdownOriginal, Attachment, Audio, Video, Link, ImageFile, ImageURL } from './message-format-old.js';
2
+
3
+ class FormatButtonGroup {
4
+ #rows = [];
5
+ #currentRow = null;
6
+ /**
7
+ * 获取按钮组数据
8
+ */
9
+ get value() {
10
+ this.#flush();
11
+ return BT.group(...this.#rows);
12
+ }
13
+ /**
14
+ * 将当前行刷入 rows
15
+ */
16
+ #flush() {
17
+ if (this.#currentRow && this.#currentRow.length > 0) {
18
+ this.#rows.push(BT.row(...this.#currentRow));
19
+ this.#currentRow = null;
20
+ }
21
+ }
22
+ /**
23
+ * 吸收另一个 FormatButtonGroup 的数据
24
+ * @param group 要吸收的 FormatButtonGroup 实例
25
+ * @returns 当前实例
26
+ */
27
+ absorb(group) {
28
+ // 如果当前有row且不是空的,则新增一行
29
+ if (this.#currentRow && this.#currentRow.length > 0) {
30
+ this.#flush();
31
+ }
32
+ // 吸收另一个实例的所有行
33
+ this.#rows.push(...group.value.value);
34
+ return this;
35
+ }
36
+ /**
37
+ * 新增一行按钮
38
+ * @returns 当前实例
39
+ */
40
+ addRow() {
41
+ this.#flush();
42
+ this.#currentRow = [];
43
+ return this;
44
+ }
45
+ /**
46
+ * 添加一个按钮到当前行,若无行则自动创建
47
+ */
48
+ addButton(...args) {
49
+ if (!this.#currentRow) {
50
+ this.#currentRow = [];
51
+ }
52
+ this.#currentRow.push(BT(...args));
53
+ return this;
54
+ }
55
+ /**
56
+ * 清空
57
+ */
58
+ clear() {
59
+ this.#rows = [];
60
+ this.#currentRow = null;
61
+ return this;
62
+ }
63
+ }
64
+ class FormatMarkDown {
65
+ #data = [];
66
+ /**
67
+ * 获取 Markdown 数据
68
+ */
69
+ get value() {
70
+ return MD(...this.#data);
71
+ }
72
+ /**
73
+ * 吸收另一个 FormatMarkDown 的数据
74
+ * @param md 要吸收的 FormatMarkDown 实例
75
+ * @returns 当前实例
76
+ */
77
+ absorb(md) {
78
+ this.#data.push(...md.value.value);
79
+ return this;
80
+ }
81
+ /**
82
+ * 添加原始文本
83
+ */
84
+ addContent(...args) {
85
+ this.#data.push(MD.content(...args));
86
+ return this;
87
+ }
88
+ /**
89
+ * 添加文本
90
+ */
91
+ addText(...args) {
92
+ this.#data.push(MD.text(...args));
93
+ return this;
94
+ }
95
+ /**
96
+ * 添加标题
97
+ */
98
+ addTitle(...args) {
99
+ this.#data.push(MD.title(...args));
100
+ return this;
101
+ }
102
+ /**
103
+ * 添加副标题
104
+ */
105
+ addSubtitle(...args) {
106
+ this.#data.push(MD.subtitle(...args));
107
+ return this;
108
+ }
109
+ /**
110
+ * 添加粗体
111
+ */
112
+ addBold(...args) {
113
+ this.#data.push(MD.bold(...args));
114
+ return this;
115
+ }
116
+ /**
117
+ * 添加斜体
118
+ */
119
+ addItalic(...args) {
120
+ this.#data.push(MD.italic(...args));
121
+ return this;
122
+ }
123
+ /**
124
+ * 添加斜体(星号)
125
+ */
126
+ addItalicStar(...args) {
127
+ this.#data.push(MD.italicStar(...args));
128
+ return this;
129
+ }
130
+ /**
131
+ * 添加删除线
132
+ */
133
+ addStrikethrough(...args) {
134
+ this.#data.push(MD.strikethrough(...args));
135
+ return this;
136
+ }
137
+ /**
138
+ * 添加链接
139
+ */
140
+ addLink(...args) {
141
+ this.#data.push(MD.link(...args));
142
+ return this;
143
+ }
144
+ /**
145
+ * 添加图片
146
+ */
147
+ addImage(...args) {
148
+ this.#data.push(MD.image(...args));
149
+ return this;
150
+ }
151
+ /**
152
+ * 添加列表
153
+ */
154
+ addList(...args) {
155
+ this.#data.push(MD.list(...args));
156
+ return this;
157
+ }
158
+ /**
159
+ * 添加引用
160
+ */
161
+ addBlockquote(...args) {
162
+ this.#data.push(MD.blockquote(...args));
163
+ return this;
164
+ }
165
+ /**
166
+ * 添加分割线
167
+ */
168
+ addDivider() {
169
+ this.#data.push(MD.divider());
170
+ return this;
171
+ }
172
+ /**
173
+ * 添加换行
174
+ */
175
+ addNewline(...args) {
176
+ this.#data.push(MD.newline(...args));
177
+ return this;
178
+ }
179
+ /**
180
+ * 添加代码
181
+ */
182
+ addCode(...args) {
183
+ this.#data.push(MD.code(...args));
184
+ return this;
185
+ }
186
+ /**
187
+ * 换行
188
+ */
189
+ addBreak() {
190
+ this.#data.push(MD.newline());
191
+ return this;
192
+ }
193
+ addMention(...args) {
194
+ this.#data.push(MD.mention(...args));
195
+ return this;
196
+ }
197
+ addButton(...args) {
198
+ this.#data.push(MD.button(...args));
199
+ return this;
200
+ }
201
+ /**
202
+ * 清空
203
+ */
204
+ clear() {
205
+ this.#data = [];
206
+ return this;
207
+ }
208
+ }
209
+ /**
210
+ * 消息格式化构建器
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * const format = Format.create()
215
+ * format.addText('hello').addBreak().addText('world')
216
+ * message.send({ format })
217
+ * ```
218
+ */
219
+ class Format {
220
+ #data = [];
221
+ /**
222
+ * 创建一个新的 Format 实例
223
+ */
224
+ static create() {
225
+ return new Format();
226
+ }
227
+ /**
228
+ * 创建一个新的 Markdown Format 实例
229
+ */
230
+ static createMarkdown() {
231
+ return new FormatMarkDown();
232
+ }
233
+ /**
234
+ * 创建一个新的 Button Format 实例
235
+ */
236
+ static createButtonGroup() {
237
+ return new FormatButtonGroup();
238
+ }
239
+ /**
240
+ * 获取内部格式化数据
241
+ */
242
+ get value() {
243
+ return this.#data;
244
+ }
245
+ absorb(format) {
246
+ this.#data.push(...format.value);
247
+ return this;
248
+ }
249
+ /**
250
+ * 添加文本
251
+ */
252
+ addText(...args) {
253
+ this.#data.push(Text(...args));
254
+ return this;
255
+ }
256
+ /**
257
+ * 添加图片 (Buffer 或带协议字符串)
258
+ */
259
+ addImage(...args) {
260
+ this.#data.push(Image(...args));
261
+ return this;
262
+ }
263
+ /**
264
+ * 添加提及
265
+ */
266
+ addMention(...args) {
267
+ this.#data.push(Mention(...args));
268
+ return this;
269
+ }
270
+ addButtonGroup(...args) {
271
+ if (args[0] instanceof FormatButtonGroup) {
272
+ this.#data.push(args[0].value);
273
+ }
274
+ else {
275
+ this.#data.push(BT.group(...args));
276
+ }
277
+ return this;
278
+ }
279
+ addMarkdown(...args) {
280
+ if (args[0] instanceof FormatMarkDown) {
281
+ this.#data.push(args[0].value);
282
+ }
283
+ else {
284
+ this.#data.push(MD(...args));
285
+ }
286
+ return this;
287
+ }
288
+ /**
289
+ * 添加纯 Markdown 文本
290
+ */
291
+ addMarkdownOriginal(...args) {
292
+ this.#data.push(MarkdownOriginal(...args));
293
+ return this;
294
+ }
295
+ /**
296
+ * 添加附件
297
+ */
298
+ addAttachment(...args) {
299
+ this.#data.push(Attachment(...args));
300
+ return this;
301
+ }
302
+ /**
303
+ * 添加音频
304
+ */
305
+ addAudio(...args) {
306
+ this.#data.push(Audio(...args));
307
+ return this;
308
+ }
309
+ /**
310
+ * 添加视频
311
+ */
312
+ addVideo(...args) {
313
+ this.#data.push(Video(...args));
314
+ return this;
315
+ }
316
+ /**
317
+ * 添加链接
318
+ * @deprecated 废弃,这个应该是md语法里的
319
+ */
320
+ addLink(...args) {
321
+ this.#data.push(Link(...args));
322
+ return this;
323
+ }
324
+ /**
325
+ * 添加图片文件
326
+ * @deprecated 废弃,推荐使用 addImage
327
+ */
328
+ addImageFile(...args) {
329
+ this.#data.push(ImageFile(...args));
330
+ return this;
331
+ }
332
+ /**
333
+ * 添加图片链接
334
+ * @deprecated 废弃,推荐使用 addImage
335
+ */
336
+ addImageURL(...args) {
337
+ this.#data.push(ImageURL(...args));
338
+ return this;
339
+ }
340
+ /**
341
+ * 清空
342
+ */
343
+ clear() {
344
+ this.#data = [];
345
+ return this;
346
+ }
347
+ }
348
+ /**
349
+ * 创建event
350
+ * @param options
351
+ * @returns
352
+ */
353
+ function createEvent(options) {
354
+ const { event, selects, regular, prefix, exact } = options;
355
+ const { name, MessageText } = event || {};
356
+ const selectsArr = Array.isArray(selects) ? selects : [selects];
357
+ const o = {
358
+ selects: false,
359
+ regular: false,
360
+ prefix: false,
361
+ exact: false
362
+ };
363
+ // 匹配选择事件类型
364
+ if (selectsArr.includes(name)) {
365
+ o.selects = true;
366
+ }
367
+ // 精准匹配
368
+ if (exact && MessageText && MessageText === exact) {
369
+ o.exact = true;
370
+ }
371
+ // 前缀匹配
372
+ if (prefix && MessageText?.startsWith(prefix)) {
373
+ o.prefix = true;
374
+ }
375
+ // 正则匹配
376
+ if (regular && MessageText && new RegExp(regular).test(MessageText)) {
377
+ o.regular = true;
378
+ }
379
+ return { ...event, ...o };
380
+ }
381
+
382
+ export { Format, FormatButtonGroup, FormatMarkDown, createEvent };
@@ -1,5 +1,6 @@
1
1
  import { DataEnums, OnDataFormatFunc } from '../types';
2
2
  import { Result } from '../core';
3
+ import { Format } from './message-format';
3
4
  type BaseMap = {
4
5
  [key: string]: unknown;
5
6
  };
@@ -8,6 +9,18 @@ export declare const createEventValue: <T extends keyof R, R extends BaseMap>(ev
8
9
  }) => R[T];
9
10
  export declare const format: OnDataFormatFunc;
10
11
  export declare const createDataFormat: OnDataFormatFunc;
12
+ export declare class MessageDirect {
13
+ static create(): MessageDirect;
14
+ sendToChannel(params: {
15
+ SpaceId: string;
16
+ format: Format;
17
+ replyId?: string;
18
+ }): Promise<Result[]>;
19
+ sendToUser(params: {
20
+ OpenID: string;
21
+ format: Format;
22
+ }): Promise<Result[]>;
23
+ }
11
24
  export declare const sendToChannel: (SpaceId: string, data: DataEnums[]) => Promise<Result[]>;
12
25
  export declare const sendToUser: (OpenID: string, data: DataEnums[]) => Promise<Result[]>;
13
26
  type IntentResult = {
@@ -21,6 +21,52 @@ const format = (...data) => {
21
21
  };
22
22
  global.format = format;
23
23
  const createDataFormat = format;
24
+ class MessageDirect {
25
+ static create() {
26
+ return new MessageDirect();
27
+ }
28
+ async sendToChannel(params) {
29
+ if (!params.SpaceId || typeof params.SpaceId !== 'string') {
30
+ logger.error({
31
+ code: ResultCode.FailParams,
32
+ message: 'Invalid SpaceId: SpaceId must be a string',
33
+ data: null
34
+ });
35
+ throw new Error('Invalid SpaceId: SpaceId must be a string');
36
+ }
37
+ return await sendAction({
38
+ action: 'message.send.channel',
39
+ payload: {
40
+ ChannelId: params.SpaceId,
41
+ params: {
42
+ format: params.format.value,
43
+ replyId: params?.replyId
44
+ }
45
+ }
46
+ });
47
+ }
48
+ ;
49
+ async sendToUser(params) {
50
+ if (!params.OpenID || typeof params.OpenID !== 'string') {
51
+ logger.error({
52
+ code: ResultCode.FailParams,
53
+ message: 'Invalid OpenID: OpenID must be a string',
54
+ data: null
55
+ });
56
+ throw new Error('Invalid OpenID: OpenID must be a string');
57
+ }
58
+ return await sendAction({
59
+ action: 'message.send.user',
60
+ payload: {
61
+ UserId: params.OpenID,
62
+ params: {
63
+ format: params.format.value
64
+ }
65
+ }
66
+ });
67
+ }
68
+ ;
69
+ }
24
70
  const sendToChannel = async (SpaceId, data) => {
25
71
  if (!SpaceId || typeof SpaceId !== 'string') {
26
72
  logger.error({
@@ -67,4 +113,4 @@ const getMessageIntent = async () => {
67
113
  return createResult(ResultCode.Ok, '获取成功', results[0]?.data ?? null);
68
114
  };
69
115
 
70
- export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser };
116
+ export { MessageDirect, createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser };
@@ -0,0 +1,50 @@
1
+ import { DataMention, DataImage, DataText, DataImageURL, DataImageFile, ButtonRow, DataButtonGroup, DataButton, DataArkList, DataArkListTip, DataArkListContent, DataArkListItem, DataArkCard, DataArkBigCard, DataMarkdownTemplate, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataLink, DataMarkdownText, DataButtonTemplate, DataMarkdownCode } from '../types';
2
+ export declare const Text: (val: DataText["value"], options?: DataText["options"]) => DataText;
3
+ export declare const Link: (val: DataLink["value"], options?: DataText["options"]) => DataText;
4
+ export declare const ImageURL: (val: DataImageURL["value"]) => DataImageURL;
5
+ export declare const ImageFile: (val: DataImageFile["value"]) => DataImageFile;
6
+ declare const Image: {
7
+ (val: Buffer): DataImage;
8
+ url: (val: DataImageURL["value"]) => DataImageURL;
9
+ file: (val: DataImageFile["value"]) => DataImageFile;
10
+ };
11
+ export { Image };
12
+ export declare const Mention: (UserId?: DataMention["value"], options?: DataMention["options"]) => DataMention;
13
+ declare const BT: {
14
+ (title: string, data: DataButton["options"]["data"], options?: Omit<DataButton["options"], "data">): DataButton;
15
+ group(...rows: ButtonRow[]): DataButtonGroup;
16
+ template(templateId: DataButtonTemplate["value"]): DataButtonTemplate;
17
+ row(...buttons: DataButton[]): ButtonRow;
18
+ };
19
+ export { BT };
20
+ export declare const Ark: {
21
+ list: (values_0: DataArkListTip, values_1: DataArkListContent) => DataArkList;
22
+ listTip: (options: DataArkListTip["value"]) => DataArkListTip;
23
+ listContent: (...values: DataArkListContent["value"]) => DataArkListContent;
24
+ listItem: (value: DataArkListItem["value"]) => DataArkListItem;
25
+ Card: (value: DataArkCard["value"]) => DataArkCard;
26
+ BigCard: (value: DataArkBigCard["value"]) => DataArkBigCard;
27
+ };
28
+ declare const MD: {
29
+ (...values: DataMarkDown["value"]): DataMarkDown;
30
+ template(templateId: DataMarkdownTemplate["value"], params?: DataMarkdownTemplate["options"]["params"]): DataMarkdownTemplate;
31
+ text(text: string): DataMarkdownText;
32
+ title(text: string): DataMarkdownTitle;
33
+ subtitle(text: string): DataMarkdownSubtitle;
34
+ bold(text: string): DataMarkdownBold;
35
+ italic(text: string): DataMarkdownItalic;
36
+ italicStar(text: string): DataMarkdownItalicStar;
37
+ strikethrough(text: string): DataMarkdownStrikethrough;
38
+ link(text: string, url: string): DataMarkdownLink;
39
+ image(url: string, options?: {
40
+ width?: number;
41
+ height?: number;
42
+ }): DataMarkdownImage;
43
+ list(...items: any[]): DataMarkdownList;
44
+ listItem(indexOrText: number | string, text?: string): DataMarkdownListItem;
45
+ blockquote(text: string): DataMarkdownBlockquote;
46
+ divider(): DataMarkdownDivider;
47
+ newline(value?: boolean): DataMarkdownNewline;
48
+ code(value: DataMarkdownCode["value"], options?: DataMarkdownCode["options"]): DataMarkdownCode;
49
+ };
50
+ export { MD };