alemonjs 2.1.53 → 2.1.55

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 (98) hide show
  1. package/lib/app/define-router.d.ts +1 -0
  2. package/lib/app/define-router.js +6 -1
  3. package/lib/app/event-format.js +1 -1
  4. package/lib/app/event-processor-cycleFiles.js +2 -6
  5. package/lib/app/expose.d.ts +16 -0
  6. package/lib/app/expose.js +190 -0
  7. package/lib/app/index.d.ts +1 -0
  8. package/lib/app/index.js +2 -1
  9. package/lib/app/load_modules/loadChild.js +4 -0
  10. package/lib/app/store.d.ts +9 -9
  11. package/lib/app/store.js +2 -0
  12. package/lib/index.js +2 -1
  13. package/lib/types/event/index.d.ts +2 -0
  14. package/lib/types/expose/index.d.ts +41 -0
  15. package/lib/types/expose/index.js +1 -0
  16. package/lib/types/index.d.ts +1 -0
  17. package/package.json +1 -1
  18. package/lib/app/define/define-children.d.ts +0 -8
  19. package/lib/app/define/define-children.js +0 -25
  20. package/lib/app/define/define-middleware.d.ts +0 -2
  21. package/lib/app/define/define-middleware.js +0 -8
  22. package/lib/app/define/define-platform.d.ts +0 -13
  23. package/lib/app/define/define-platform.js +0 -40
  24. package/lib/app/define/define-response.d.ts +0 -2
  25. package/lib/app/define/define-response.js +0 -8
  26. package/lib/app/define/define-router.d.ts +0 -17
  27. package/lib/app/define/define-router.js +0 -34
  28. package/lib/app/event/event-group.d.ts +0 -9
  29. package/lib/app/event/event-group.js +0 -29
  30. package/lib/app/event/event-middleware.d.ts +0 -23
  31. package/lib/app/event/event-middleware.js +0 -44
  32. package/lib/app/event/event-response.d.ts +0 -16
  33. package/lib/app/event/event-response.js +0 -23
  34. package/lib/app/event/event-selects.d.ts +0 -13
  35. package/lib/app/event/event-selects.js +0 -15
  36. package/lib/app/event-processor/event-processor-callHandler.d.ts +0 -1
  37. package/lib/app/event-processor/event-processor-callHandler.js +0 -43
  38. package/lib/app/event-processor/event-processor-cycle.d.ts +0 -14
  39. package/lib/app/event-processor/event-processor-cycle.js +0 -97
  40. package/lib/app/event-processor/event-processor-cycleFiles.d.ts +0 -11
  41. package/lib/app/event-processor/event-processor-cycleFiles.js +0 -147
  42. package/lib/app/event-processor/event-processor-cycleRoute.d.ts +0 -10
  43. package/lib/app/event-processor/event-processor-cycleRoute.js +0 -133
  44. package/lib/app/event-processor/event-processor-event.d.ts +0 -24
  45. package/lib/app/event-processor/event-processor-event.js +0 -41
  46. package/lib/app/event-processor/event-processor-middleware.d.ts +0 -14
  47. package/lib/app/event-processor/event-processor-middleware.js +0 -31
  48. package/lib/app/event-processor/event-processor-subscribe.d.ts +0 -35
  49. package/lib/app/event-processor/event-processor-subscribe.js +0 -115
  50. package/lib/app/event-processor/event-processor.d.ts +0 -17
  51. package/lib/app/event-processor/event-processor.js +0 -207
  52. package/lib/app/hook-use/hook-use-api.d.ts +0 -6
  53. package/lib/app/hook-use/hook-use-api.js +0 -22
  54. package/lib/app/hook-use/hook-use-channel.d.ts +0 -8
  55. package/lib/app/hook-use/hook-use-channel.js +0 -33
  56. package/lib/app/hook-use/hook-use-client.d.ts +0 -7
  57. package/lib/app/hook-use/hook-use-client.js +0 -27
  58. package/lib/app/hook-use/hook-use-me.d.ts +0 -8
  59. package/lib/app/hook-use/hook-use-me.js +0 -45
  60. package/lib/app/hook-use/hook-use-menber.d.ts +0 -8
  61. package/lib/app/hook-use/hook-use-menber.js +0 -59
  62. package/lib/app/hook-use/hook-use-mention.d.ts +0 -23
  63. package/lib/app/hook-use/hook-use-mention.js +0 -105
  64. package/lib/app/hook-use/hook-use-message.d.ts +0 -29
  65. package/lib/app/hook-use/hook-use-message.js +0 -88
  66. package/lib/app/hook-use/hook-use-state.d.ts +0 -30
  67. package/lib/app/hook-use/hook-use-state.js +0 -101
  68. package/lib/app/hook-use/hook-use-subscribe.d.ts +0 -46
  69. package/lib/app/hook-use/hook-use-subscribe.js +0 -143
  70. package/lib/app/hook-use-api.d.ts +0 -268
  71. package/lib/app/hook-use-api.js +0 -1213
  72. package/lib/app/hook-use-state.d.ts +0 -3
  73. package/lib/app/hook-use-state.js +0 -68
  74. package/lib/app/hook-use-subscribe.d.ts +0 -73
  75. package/lib/app/hook-use-subscribe.js +0 -112
  76. package/lib/app/message/message-api.d.ts +0 -69
  77. package/lib/app/message/message-api.js +0 -105
  78. package/lib/app/message/message-format-old.d.ts +0 -143
  79. package/lib/app/message/message-format-old.js +0 -359
  80. package/lib/app/message/message-format.d.ts +0 -215
  81. package/lib/app/message/message-format.js +0 -382
  82. package/lib/app/message-controller.d.ts +0 -25
  83. package/lib/app/message-controller.js +0 -66
  84. package/lib/app/message-format.old.d.ts +0 -50
  85. package/lib/app/message-format.old.js +0 -217
  86. package/lib/cbp/processor/handle.d.ts +0 -3
  87. package/lib/cbp/processor/handle.js +0 -32
  88. package/lib/jsx/index.d.ts +0 -105
  89. package/lib/jsx/index.js +0 -211
  90. package/lib/jsx/jsx-dev-runtime.d.ts +0 -2
  91. package/lib/jsx/jsx-dev-runtime.js +0 -1
  92. package/lib/jsx/jsx-runtime.d.ts +0 -18
  93. package/lib/jsx/jsx-runtime.js +0 -24
  94. package/lib/process/client.js +0 -109
  95. package/lib/store/SinglyLinkedList.d.ts +0 -22
  96. package/lib/store/SinglyLinkedList.js +0 -97
  97. package/lib/store/store.d.ts +0 -127
  98. package/lib/store/store.js +0 -443
@@ -2,4 +2,5 @@ import { DefineRouterFunc } from '../types';
2
2
  export declare const lazy: <T extends {
3
3
  default: any;
4
4
  }>(fnc: () => Promise<T>) => (() => Promise<T["default"]>);
5
+ export declare function runHandler(loader: () => Promise<any>, args: any[]): Promise<any>;
5
6
  export declare const defineRouter: DefineRouterFunc;
@@ -11,10 +11,15 @@ const lazy = (fnc) => {
11
11
  };
12
12
  return back;
13
13
  };
14
+ async function runHandler(loader, args) {
15
+ const mod = await loader();
16
+ const handler = mod.default ?? mod;
17
+ return handler(...args);
18
+ }
14
19
  const defineRouter = routes => {
15
20
  return {
16
21
  current: routes
17
22
  };
18
23
  };
19
24
 
20
- export { defineRouter, lazy };
25
+ export { defineRouter, lazy, runHandler };
@@ -11,7 +11,7 @@ class FormatEvent {
11
11
  Object.assign(this.#data, otherParams);
12
12
  Object.defineProperty(this.#data, 'value', {
13
13
  value,
14
- enumerable: false
14
+ enumerable: true
15
15
  });
16
16
  return this;
17
17
  }
@@ -121,9 +121,7 @@ const createFileTreeStep = (valueEvent, select, next, root, callHandler) => {
121
121
  void processContent(node, done);
122
122
  }, app => {
123
123
  matched = true;
124
- const items = Array.isArray(app.default.current)
125
- ? app.default.current
126
- : [app.default.current];
124
+ const items = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
127
125
  mwCurrents.push(...items);
128
126
  });
129
127
  if (matched) {
@@ -168,9 +166,7 @@ const createFileTreeStep = (valueEvent, select, next, root, callHandler) => {
168
166
  void callHandlerFile(valueEvent, select, file, () => {
169
167
  processFiles(node, idx + 1, filesDone, treeDone);
170
168
  }, app => {
171
- const fileCurrents = Array.isArray(app.default.current)
172
- ? app.default.current
173
- : [app.default.current];
169
+ const fileCurrents = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
174
170
  callHandler(fileCurrents, (cn, ...cns) => {
175
171
  if (cn) {
176
172
  treeDone(true, ...cns);
@@ -0,0 +1,16 @@
1
+ import { ExposeProvideConfig, ExposeListItem, ExposeWatchEvent, ExposeSchemaItem } from '../types';
2
+ type WatchCallback = (event: ExposeWatchEvent) => void;
3
+ export declare function registerExpose(appName: string, configs: ExposeProvideConfig[]): void;
4
+ export declare class Expose {
5
+ #private;
6
+ static create(): Expose;
7
+ provide(config: ExposeProvideConfig): this;
8
+ getConfigs(): ExposeProvideConfig[];
9
+ list(protocol?: string): ExposeListItem[];
10
+ invoke(protocol: string, appName: string, action: string, value?: any): any;
11
+ schema(): ExposeSchemaItem[];
12
+ watch(protocolOrCallback: string | WatchCallback, callback?: WatchCallback): () => void;
13
+ }
14
+ export declare function disposeExpose(appName: string): void;
15
+ export declare function clearAllExpose(): void;
16
+ export {};
@@ -0,0 +1,190 @@
1
+ const storeExpose = new Map();
2
+ const protocolWatchers = new Map();
3
+ const globalWatchers = new Set();
4
+ function emitWatch(event) {
5
+ const watchers = protocolWatchers.get(event.protocol);
6
+ if (watchers) {
7
+ for (const cb of watchers) {
8
+ try {
9
+ cb(event);
10
+ }
11
+ catch {
12
+ }
13
+ }
14
+ }
15
+ for (const cb of globalWatchers) {
16
+ try {
17
+ cb(event);
18
+ }
19
+ catch {
20
+ }
21
+ }
22
+ }
23
+ function registerExpose(appName, configs) {
24
+ for (const config of configs) {
25
+ const protocol = config.name;
26
+ if (!storeExpose.has(protocol)) {
27
+ storeExpose.set(protocol, new Map());
28
+ }
29
+ const providers = storeExpose.get(protocol);
30
+ if (providers.has(appName)) {
31
+ console.warn(`[expose] ${appName} already provided "${protocol}", overwriting.`);
32
+ }
33
+ providers.set(appName, { appName, config });
34
+ }
35
+ }
36
+ class Expose {
37
+ #configs = [];
38
+ static create() {
39
+ return new Expose();
40
+ }
41
+ provide(config) {
42
+ this.#configs.push(config);
43
+ return this;
44
+ }
45
+ getConfigs() {
46
+ return this.#configs;
47
+ }
48
+ list(protocol) {
49
+ const result = [];
50
+ if (protocol) {
51
+ const providers = storeExpose.get(protocol);
52
+ if (!providers) {
53
+ return result;
54
+ }
55
+ for (const [, entry] of providers) {
56
+ result.push(createListItem(entry, protocol));
57
+ }
58
+ }
59
+ else {
60
+ for (const [proto, providers] of storeExpose) {
61
+ for (const [, entry] of providers) {
62
+ result.push(createListItem(entry, proto));
63
+ }
64
+ }
65
+ }
66
+ return result;
67
+ }
68
+ invoke(protocol, appName, action, value) {
69
+ const providers = storeExpose.get(protocol);
70
+ if (!providers) {
71
+ throw new Error(`[expose] protocol "${protocol}" not found`);
72
+ }
73
+ const entry = providers.get(appName);
74
+ if (!entry) {
75
+ throw new Error(`[expose] provider "${appName}" not found in protocol "${protocol}"`);
76
+ }
77
+ const actionMeta = entry.config.actions[action];
78
+ if (!actionMeta) {
79
+ throw new Error(`[expose] action "${action}" not found in "${protocol}" of "${appName}"`);
80
+ }
81
+ const result = actionMeta.handler(value);
82
+ if (action !== 'read') {
83
+ emitWatch({
84
+ name: appName,
85
+ protocol,
86
+ action,
87
+ value
88
+ });
89
+ }
90
+ return result;
91
+ }
92
+ schema() {
93
+ const result = [];
94
+ for (const [protocol, providers] of storeExpose) {
95
+ const firstEntry = providers.values().next().value;
96
+ if (!firstEntry) {
97
+ continue;
98
+ }
99
+ const actions = {};
100
+ for (const [actionName, meta] of Object.entries(firstEntry.config.actions)) {
101
+ actions[actionName] = {
102
+ description: meta.description,
103
+ ...(meta.params ? { params: meta.params } : {}),
104
+ ...(meta.returns ? { returns: meta.returns } : {})
105
+ };
106
+ }
107
+ result.push({
108
+ protocol,
109
+ description: firstEntry.config.description,
110
+ providers: Array.from(providers.keys()).map(name => ({ name })),
111
+ actions,
112
+ invoke: 'Expose.invoke(protocol, appName, action, value?)'
113
+ });
114
+ }
115
+ return result;
116
+ }
117
+ watch(protocolOrCallback, callback) {
118
+ if (typeof protocolOrCallback === 'function') {
119
+ const cb = protocolOrCallback;
120
+ globalWatchers.add(cb);
121
+ return () => {
122
+ globalWatchers.delete(cb);
123
+ };
124
+ }
125
+ const protocol = protocolOrCallback;
126
+ if (!callback) {
127
+ throw new Error('[expose] watch(protocol, callback) requires a callback');
128
+ }
129
+ if (!protocolWatchers.has(protocol)) {
130
+ protocolWatchers.set(protocol, new Set());
131
+ }
132
+ protocolWatchers.get(protocol).add(callback);
133
+ return () => {
134
+ const set = protocolWatchers.get(protocol);
135
+ if (set) {
136
+ set.delete(callback);
137
+ if (set.size === 0) {
138
+ protocolWatchers.delete(protocol);
139
+ }
140
+ }
141
+ };
142
+ }
143
+ }
144
+ function createListItem(entry, protocol) {
145
+ const actions = {};
146
+ for (const [actionName, meta] of Object.entries(entry.config.actions)) {
147
+ actions[actionName] = {
148
+ description: meta.description,
149
+ ...(meta.params ? { params: meta.params } : {}),
150
+ ...(meta.returns ? { returns: meta.returns } : {})
151
+ };
152
+ }
153
+ return {
154
+ name: entry.appName,
155
+ protocol,
156
+ description: entry.config.description,
157
+ actions,
158
+ invoke(action, value) {
159
+ const actionMeta = entry.config.actions[action];
160
+ if (!actionMeta) {
161
+ throw new Error(`[expose] action "${action}" not found in "${protocol}" of "${entry.appName}"`);
162
+ }
163
+ const result = actionMeta.handler(value);
164
+ if (action !== 'read') {
165
+ emitWatch({
166
+ name: entry.appName,
167
+ protocol,
168
+ action,
169
+ value
170
+ });
171
+ }
172
+ return result;
173
+ }
174
+ };
175
+ }
176
+ function disposeExpose(appName) {
177
+ for (const [protocol, providers] of storeExpose) {
178
+ providers.delete(appName);
179
+ if (providers.size === 0) {
180
+ storeExpose.delete(protocol);
181
+ }
182
+ }
183
+ }
184
+ function clearAllExpose() {
185
+ storeExpose.clear();
186
+ protocolWatchers.clear();
187
+ globalWatchers.clear();
188
+ }
189
+
190
+ export { Expose, clearAllExpose, disposeExpose, registerExpose };
@@ -1,4 +1,5 @@
1
1
  export * from './store.js';
2
+ export * from './expose.js';
2
3
  export * from './load_modules/index.js';
3
4
  export * from './define-children.js';
4
5
  export * from './define-platform.js';
package/lib/app/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  export { ChildrenApp, Core, Logger, Middleware, MiddlewareRouter, MiddlewareTree, ProcessorEventAutoClearMap, ProcessorEventUserAutoClearMap, Response, ResponseMiddleware, ResponseRouter, ResponseTree, State, StateSubscribe, SubscribeList, bumpStoreVersion, core, getSubscribeList, logger } from './store.js';
2
+ export { Expose, clearAllExpose, disposeExpose, registerExpose } from './expose.js';
2
3
  export { loadModels, run } from './load_modules/load.js';
3
4
  export { loadChildren, loadChildrenFile } from './load_modules/loadChild.js';
4
5
  export { defineChildren } from './define-children.js';
5
6
  export { definePlatform } from './define-platform.js';
6
7
  export { defineResponse } from './define-response.js';
7
8
  export { defineMiddleware } from './define-middleware.js';
8
- export { defineRouter, lazy } from './define-router.js';
9
+ export { defineRouter, lazy, runHandler } from './define-router.js';
9
10
  export { FormatEvent, wrapEvent } from './event-format.js';
10
11
  export { onGroup } from './event-group.js';
11
12
  export { OnMiddleware, onMiddleware } from './event-middleware.js';
@@ -2,6 +2,7 @@ import { dirname, join } from 'path';
2
2
  import { existsSync } from 'fs';
3
3
  import { showErrorModule, getRecursiveDirFiles, createEventName } from '../../core/utils.js';
4
4
  import { ChildrenApp } from '../store.js';
5
+ import { registerExpose } from '../expose.js';
5
6
  import { ResultCode, fileSuffixMiddleware } from '../../core/variable.js';
6
7
  import module$1 from 'module';
7
8
 
@@ -67,6 +68,9 @@ const loadChildren = async (mainPath, appName) => {
67
68
  if (res && (res?.response || res?.middleware || res?.responseRouter || res?.middlewareRouter)) {
68
69
  App.register(res);
69
70
  }
71
+ if (res?.expose) {
72
+ registerExpose(appName, res.expose.getConfigs());
73
+ }
70
74
  App.on();
71
75
  try {
72
76
  if (app?.onMounted) {
@@ -8,11 +8,11 @@ export declare class Logger {
8
8
  export declare class Core {
9
9
  constructor();
10
10
  get value(): {
11
- storeState: import("..").ResponseState;
12
- storeStateSubscribe: import("..").StateSubscribeMap;
13
- storeSubscribeList: import("..").SubscribeKeysMap;
11
+ storeState: import("../types").ResponseState;
12
+ storeStateSubscribe: import("../types").StateSubscribeMap;
13
+ storeSubscribeList: import("../types").SubscribeKeysMap;
14
14
  storeChildrenApp: {
15
- [key: string]: import("..").StoreChildrenApp;
15
+ [key: string]: import("../types").StoreChildrenApp;
16
16
  };
17
17
  };
18
18
  }
@@ -75,16 +75,16 @@ export declare class ChildrenApp {
75
75
  pushCycle(data: ChildrenCycle): void;
76
76
  on(): void;
77
77
  un(): void;
78
- get value(): import("..").StoreChildrenApp;
78
+ get value(): import("../types").StoreChildrenApp;
79
79
  }
80
80
  export declare const ProcessorEventAutoClearMap: Map<any, any>;
81
81
  export declare const ProcessorEventUserAutoClearMap: Map<any, any>;
82
82
  export declare const logger: any;
83
83
  export declare const core: {
84
- storeState: import("..").ResponseState;
85
- storeStateSubscribe: import("..").StateSubscribeMap;
86
- storeSubscribeList: import("..").SubscribeKeysMap;
84
+ storeState: import("../types").ResponseState;
85
+ storeStateSubscribe: import("../types").StateSubscribeMap;
86
+ storeSubscribeList: import("../types").SubscribeKeysMap;
87
87
  storeChildrenApp: {
88
- [key: string]: import("..").StoreChildrenApp;
88
+ [key: string]: import("../types").StoreChildrenApp;
89
89
  };
90
90
  };
package/lib/app/store.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { SinglyLinkedList } from './SinglyLinkedList.js';
2
2
  import { mkdirSync } from 'node:fs';
3
3
  import log4js from 'log4js';
4
+ import { disposeExpose } from './expose.js';
4
5
 
5
6
  const createLogger = () => {
6
7
  if (process.env.BROWSER_ENV === 'browser') {
@@ -424,6 +425,7 @@ class ChildrenApp {
424
425
  bumpStoreVersion();
425
426
  }
426
427
  un() {
428
+ disposeExpose(this.#name);
427
429
  delete alemonjsCore.storeChildrenApp[this.#name];
428
430
  bumpStoreVersion();
429
431
  }
package/lib/index.js CHANGED
@@ -6,13 +6,14 @@ export { cbpClient } from './cbp/connects/client.js';
6
6
  export { cbpPlatform } from './cbp/connects/platform.js';
7
7
  export { cbpServer } from './cbp/server/main.js';
8
8
  export { ChildrenApp, Core, Logger, Middleware, MiddlewareRouter, MiddlewareTree, ProcessorEventAutoClearMap, ProcessorEventUserAutoClearMap, Response, ResponseMiddleware, ResponseRouter, ResponseTree, State, StateSubscribe, SubscribeList, bumpStoreVersion, core, getSubscribeList, logger } from './app/store.js';
9
+ export { Expose, clearAllExpose, disposeExpose, registerExpose } from './app/expose.js';
9
10
  export { loadModels, run } from './app/load_modules/load.js';
10
11
  export { loadChildren, loadChildrenFile } from './app/load_modules/loadChild.js';
11
12
  export { defineChildren } from './app/define-children.js';
12
13
  export { definePlatform } from './app/define-platform.js';
13
14
  export { defineResponse } from './app/define-response.js';
14
15
  export { defineMiddleware } from './app/define-middleware.js';
15
- export { defineRouter, lazy } from './app/define-router.js';
16
+ export { defineRouter, lazy, runHandler } from './app/define-router.js';
16
17
  export { FormatEvent, wrapEvent } from './app/event-format.js';
17
18
  export { onGroup } from './app/event-group.js';
18
19
  export { OnMiddleware, onMiddleware } from './app/event-middleware.js';
@@ -2,6 +2,7 @@ import { ChildrenCycle, Next } from '../cycle';
2
2
  import { ClientAPI } from '../client';
3
3
  import { EventKeys, Events } from './map';
4
4
  import { DataEnums } from '../message';
5
+ import { Expose } from '../../app/expose';
5
6
  export type Current<T extends EventKeys> = (event: Events[T], next: Next) => Promise<boolean | void | undefined> | boolean | void | undefined;
6
7
  export type OnResponseValue<C, T extends EventKeys> = {
7
8
  current: C;
@@ -54,6 +55,7 @@ export type childrenCallbackRes = {
54
55
  middleware?: ReturnType<defineMiddlewareFunc>;
55
56
  responseRouter?: ReturnType<DefineRouterFunc>;
56
57
  middlewareRouter?: ReturnType<DefineRouterFunc>;
58
+ expose?: Expose;
57
59
  } | undefined;
58
60
  export type childrenCallback = ChildrenCycle & {
59
61
  register?: () => (childrenCallbackRes | undefined) | Promise<childrenCallbackRes | undefined>;
@@ -0,0 +1,41 @@
1
+ export interface ExposeActionMeta {
2
+ description: string;
3
+ params?: Record<string, string>;
4
+ returns?: Record<string, string>;
5
+ handler: (...args: any[]) => any;
6
+ }
7
+ export interface ExposeProvideConfig {
8
+ name: string;
9
+ description: string;
10
+ actions: Record<string, ExposeActionMeta>;
11
+ }
12
+ export interface ExposeListItem {
13
+ name: string;
14
+ protocol: string;
15
+ description: string;
16
+ actions: Record<string, {
17
+ description: string;
18
+ params?: Record<string, string>;
19
+ returns?: Record<string, string>;
20
+ }>;
21
+ invoke: (action: string, value?: any) => any;
22
+ }
23
+ export interface ExposeWatchEvent {
24
+ name: string;
25
+ protocol: string;
26
+ action: string;
27
+ value?: any;
28
+ }
29
+ export interface ExposeSchemaItem {
30
+ protocol: string;
31
+ description: string;
32
+ providers: {
33
+ name: string;
34
+ }[];
35
+ actions: Record<string, {
36
+ description: string;
37
+ params?: Record<string, string>;
38
+ returns?: Record<string, string>;
39
+ }>;
40
+ invoke: string;
41
+ }
@@ -0,0 +1 @@
1
+
@@ -23,6 +23,7 @@ export * from './message/index';
23
23
  export * from './package/index';
24
24
  export * from './state/index';
25
25
  export * from './store/res';
26
+ export * from './expose/index';
26
27
  export * from './subscribe';
27
28
  export * from './standard';
28
29
  export * from './actions';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.53",
3
+ "version": "2.1.55",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -1,8 +0,0 @@
1
- import { DefineChildrenFunc } from '../../types';
2
- /**
3
- * 定义子事件
4
- * @param callback
5
- * @throws {Error} - 如果 callback 无效,抛出错误。
6
- * @returns
7
- */
8
- export declare const defineChildren: DefineChildrenFunc;
@@ -1,25 +0,0 @@
1
- import { ResultCode } from '../../core/variable.js';
2
-
3
- /**
4
- * 定义子事件
5
- * @param callback
6
- * @throws {Error} - 如果 callback 无效,抛出错误。
7
- * @returns
8
- */
9
- const defineChildren = callback => {
10
- if (typeof callback === 'function' || typeof callback === 'object') {
11
- return {
12
- _name: 'app',
13
- callback
14
- };
15
- }
16
- logger.error({
17
- code: ResultCode.FailParams,
18
- message: 'Invalid callback: callback must be a object or function',
19
- data: null
20
- });
21
- throw new Error('Invalid callback: callback must be a object or function');
22
- };
23
- global.defineChildren = defineChildren;
24
-
25
- export { defineChildren };
@@ -1,2 +0,0 @@
1
- import { defineMiddlewareFunc } from '../../types';
2
- export declare const defineMiddleware: defineMiddlewareFunc;
@@ -1,8 +0,0 @@
1
- const defineMiddleware = middleware => {
2
- return {
3
- current: middleware
4
- };
5
- };
6
- global.defineMiddleware = defineMiddleware;
7
-
8
- export { defineMiddleware };
@@ -1,13 +0,0 @@
1
- type Options = {
2
- /**
3
- * 注册入口
4
- * @returns
5
- */
6
- main: () => any;
7
- /**
8
- * 平台名称,用于日志标识
9
- */
10
- name?: string;
11
- };
12
- export declare const definePlatform: (options: Options) => () => any;
13
- export {};
@@ -1,40 +0,0 @@
1
- const definePlatform = (options) => {
2
- const platformName = options.name || process.env.platform || 'unknown';
3
- // 开始注册子进程交互
4
- const mainProcess = () => {
5
- ['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
6
- process?.on?.(sig, () => {
7
- logger.info?.(`[${platformName}][${sig}] 收到信号,正在关闭...`);
8
- setImmediate(() => process.exit(0));
9
- });
10
- });
11
- process?.on?.('exit', code => {
12
- logger.info?.(`[${platformName}][exit] 进程退出,code=${code}`);
13
- });
14
- // 监听主进程消息
15
- process.on('message', msg => {
16
- try {
17
- const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
18
- if (data?.type === 'start') {
19
- options.main();
20
- }
21
- else if (data?.type === 'stop') {
22
- process.exit(0);
23
- }
24
- }
25
- catch { }
26
- });
27
- // 主动发送 ready 消息
28
- if (process.send) {
29
- process.send(JSON.stringify({ type: 'ready' }));
30
- }
31
- };
32
- // 仅当作为平台进程入口加载时才执行 mainProcess,
33
- if (!global.__client_loaded) {
34
- mainProcess();
35
- }
36
- // 这里是旧兼容性返回
37
- return options.main;
38
- };
39
-
40
- export { definePlatform };
@@ -1,2 +0,0 @@
1
- import { DefineResponseFunc } from '../../types';
2
- export declare const defineResponse: DefineResponseFunc;
@@ -1,8 +0,0 @@
1
- const defineResponse = responses => {
2
- return {
3
- current: responses
4
- };
5
- };
6
- global.defineResponse = defineResponse;
7
-
8
- export { defineResponse };
@@ -1,17 +0,0 @@
1
- import { DefineRouterFunc } from '../../types';
2
- /**
3
- * Lazy load a response handler
4
- * @param fnc
5
- * @returns
6
- */
7
- export declare const lazy: <T extends {
8
- default: any;
9
- }>(fnc: () => Promise<T>) => (() => Promise<T["default"]>);
10
- /**
11
- * 定义路由
12
- * 与 defineResponse 类似,但路由处理器是纯异步函数组件,
13
- * 内部自动根据 selects 来分类。
14
- * @param routes 路由配置数组
15
- * @returns
16
- */
17
- export declare const defineRouter: DefineRouterFunc;
@@ -1,34 +0,0 @@
1
- /**
2
- * Lazy load a response handler
3
- * @param fnc
4
- * @returns
5
- */
6
- const lazy = (fnc) => {
7
- let c = null;
8
- // fnc 是一个 ()=> imoprt(); 函数。
9
- const back = async () => {
10
- if (c) {
11
- return c;
12
- }
13
- const mod = await fnc();
14
- if (!mod || !mod.default) ;
15
- c = mod.default;
16
- // 当back被调用时。
17
- return c;
18
- };
19
- return back;
20
- };
21
- /**
22
- * 定义路由
23
- * 与 defineResponse 类似,但路由处理器是纯异步函数组件,
24
- * 内部自动根据 selects 来分类。
25
- * @param routes 路由配置数组
26
- * @returns
27
- */
28
- const defineRouter = routes => {
29
- return {
30
- current: routes
31
- };
32
- };
33
-
34
- export { defineRouter, lazy };
@@ -1,9 +0,0 @@
1
- import { OnGroupFunc } from '../../types';
2
- /**
3
- * 定义一组标准执行导出
4
- * @param calls
5
- * @deprecated 废弃
6
- * @returns
7
- */
8
- declare const onGroup: OnGroupFunc;
9
- export { onGroup };
@@ -1,29 +0,0 @@
1
- /**
2
- * 定义一组标准执行导出
3
- * @param calls
4
- * @deprecated 废弃
5
- * @returns
6
- */
7
- const onGroup = (...calls) => {
8
- if (calls.length === 0) {
9
- throw new Error('onGroup: 至少需要一个响应或中间件');
10
- }
11
- const firstItem = calls[0];
12
- const baseSelects = firstItem.select;
13
- // 把如果item是数组的,豆扁平起来。
14
- const currents = calls.reduce((acc, item) => {
15
- if (Array.isArray(item.current)) {
16
- return acc.concat(item.current);
17
- }
18
- else {
19
- return acc.concat(item.current);
20
- }
21
- }, []);
22
- return {
23
- select: baseSelects,
24
- current: currents
25
- };
26
- };
27
- global.onGroup = onGroup;
28
-
29
- export { onGroup };