vona-module-a-broadcast 5.0.9 → 5.0.11

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.
@@ -0,0 +1,52 @@
1
+ import type { BeanScopeUtil } from 'vona';
2
+ /** service: end */
3
+ /** service: begin */
4
+ import type { ServiceBroadcast } from '../service/broadcast.ts';
5
+ /** service: end */
6
+ /** service: begin */
7
+ /** main: end */
8
+ /** scope: begin */
9
+ import { BeanScopeBase } from 'vona';
10
+ /** monkey: end */
11
+ /** main: begin */
12
+ import 'vona';
13
+ import 'vona';
14
+ import 'vona';
15
+ export * from '../main.ts';
16
+ declare module 'vona-module-a-web' {
17
+ interface IServiceRecord {
18
+ 'a-broadcast:broadcast': never;
19
+ }
20
+ }
21
+ declare module 'vona-module-a-broadcast' {
22
+ interface ServiceBroadcast {
23
+ }
24
+ }
25
+ export interface IModuleService {
26
+ broadcast: ServiceBroadcast;
27
+ }
28
+ declare module 'vona' {
29
+ interface IBeanRecordGeneral {
30
+ 'a-broadcast.service.broadcast': ServiceBroadcast;
31
+ }
32
+ }
33
+ /** service: end */
34
+ /** monkey: begin */
35
+ export * from '../monkey.ts';
36
+ /** service: begin */
37
+ export * from '../service/broadcast.ts';
38
+ export declare class ScopeModuleABroadcast extends BeanScopeBase {
39
+ }
40
+ export interface ScopeModuleABroadcast {
41
+ util: BeanScopeUtil;
42
+ service: IModuleService;
43
+ }
44
+ declare module 'vona' {
45
+ interface IBeanScopeRecord {
46
+ 'a-broadcast': ScopeModuleABroadcast;
47
+ }
48
+ interface IBeanScopeContainer {
49
+ broadcast: ScopeModuleABroadcast;
50
+ }
51
+ }
52
+ /** scope: end */
@@ -0,0 +1,2 @@
1
+ export declare const __ThisModule__ = "a-broadcast";
2
+ export { ScopeModuleABroadcast as ScopeModule } from './index.ts';
@@ -0,0 +1,3 @@
1
+ export * from './.metadata/index.ts';
2
+ export * from './lib/index.ts';
3
+ export * from './types/index.ts';
package/dist/index.js ADDED
@@ -0,0 +1,110 @@
1
+ import { BeanSimple, BeanInfo, BeanBase, BeanScopeBase, createBeanDecorator } from 'vona';
2
+ import { Scope } from 'vona-module-a-bean';
3
+ import { Service } from 'vona-module-a-web';
4
+
5
+ class Main extends BeanSimple {
6
+ async moduleLoading() {}
7
+ async moduleLoaded() {
8
+ // force broadcast init
9
+ this.bean._getBean('a-broadcast.service.broadcast');
10
+ }
11
+ async configLoaded(_config) {}
12
+ }
13
+
14
+ const __ThisModule__ = 'a-broadcast';
15
+
16
+ class Monkey extends BeanSimple {
17
+ async appClose() {
18
+ const scopeSelf = this.bean.scope(__ThisModule__);
19
+ await scopeSelf.service.broadcast.disposeSub();
20
+ }
21
+ async appClosed() {
22
+ const scopeSelf = this.bean.scope(__ThisModule__);
23
+ await scopeSelf.service.broadcast.disposePub();
24
+ }
25
+ }
26
+
27
+ var _dec$1, _dec2$1, _class$1;
28
+ let ServiceBroadcast = (_dec$1 = Service(), _dec2$1 = BeanInfo({
29
+ module: "a-broadcast"
30
+ }), _dec$1(_class$1 = _dec2$1(_class$1 = class ServiceBroadcast extends BeanBase {
31
+ constructor(...args) {
32
+ super(...args);
33
+ this.__callerId = void 0;
34
+ this.__channelName = void 0;
35
+ this.__sub = void 0;
36
+ this.__pub = void 0;
37
+ }
38
+ __init__() {
39
+ const app = this.app;
40
+ this.__callerId = app.bean.worker.id;
41
+ this.__channelName = `broadcast_${this.app.name}:`;
42
+ this.__pub = app.bean.redis.get('broadcast').duplicate();
43
+ this.__sub = app.bean.redis.get('broadcast').duplicate();
44
+ this.__sub.subscribe(this.__channelName, () => {});
45
+ this.__sub.on('message', (_channel, info) => {
46
+ this._performTask(JSON.parse(info)).then(() => {
47
+ // do nothing
48
+ }).catch(err => {
49
+ this.$logger.error(err);
50
+ });
51
+ });
52
+ }
53
+ async disposePub() {
54
+ await this.__pub?.quit();
55
+ }
56
+ async disposeSub() {
57
+ await this.__sub?.quit();
58
+ }
59
+ emit(info) {
60
+ info.callerId = this.__callerId;
61
+ this.__pub.publish(this.__channelName, JSON.stringify(info));
62
+ }
63
+ async _performTask(info) {
64
+ // isEmitter
65
+ const isEmitter = info.callerId === this.__callerId;
66
+ // broadcast config
67
+ const broadcastItem = this.bean.onion.broadcast.getOnionSlice(info.broadcastName);
68
+ const broadcastConfig = this.bean.onion.broadcast.getOnionOptions(info.broadcastName);
69
+ // execute
70
+ return await this.bean.executor.newCtx(async () => {
71
+ const beanFullName = broadcastItem.beanOptions.beanFullName;
72
+ const beanInstance = this.app.bean._getBean(beanFullName);
73
+ return await beanInstance.execute(info.data, isEmitter);
74
+ }, {
75
+ dbInfo: info.options?.dbInfo,
76
+ locale: info.options?.locale,
77
+ instanceName: info.options?.instanceName,
78
+ extraData: info.options?.extraData,
79
+ transaction: broadcastConfig?.transaction,
80
+ instance: broadcastConfig?.instance !== false
81
+ });
82
+ }
83
+ }) || _class$1) || _class$1);
84
+
85
+ var _dec, _dec2, _class;
86
+ let ScopeModuleABroadcast = (_dec = Scope(), _dec2 = BeanInfo({
87
+ module: "a-broadcast"
88
+ }), _dec(_class = _dec2(_class = class ScopeModuleABroadcast extends BeanScopeBase {}) || _class) || _class);
89
+
90
+ /** scope: end */
91
+
92
+ class BeanBroadcastBase extends BeanBase {
93
+ emit(data, options) {
94
+ return this.$scope.broadcast.service.broadcast.emit(this._prepareInfo(data, options));
95
+ }
96
+ _prepareInfo(data, options) {
97
+ options = this.$scope.executor.service.executor.prepareGeneralInfo(options);
98
+ return {
99
+ broadcastName: this.$onionName,
100
+ data,
101
+ options
102
+ };
103
+ }
104
+ }
105
+
106
+ function Broadcast(options) {
107
+ return createBeanDecorator('broadcast', options);
108
+ }
109
+
110
+ export { BeanBroadcastBase, Broadcast, Main, Monkey, ScopeModuleABroadcast, ServiceBroadcast };
@@ -0,0 +1,6 @@
1
+ import type { IBroadcastEmitOptions } from '../types/broadcast.ts';
2
+ import { BeanBase } from 'vona';
3
+ export declare class BeanBroadcastBase<DATA = unknown> extends BeanBase {
4
+ emit(data?: DATA, options?: IBroadcastEmitOptions): void;
5
+ private _prepareInfo;
6
+ }
@@ -0,0 +1,2 @@
1
+ import type { IDecoratorBroadcastOptions } from '../types/broadcast.ts';
2
+ export declare function Broadcast(options?: IDecoratorBroadcastOptions): ClassDecorator;
@@ -0,0 +1,2 @@
1
+ export * from './beanBroadcastBase.ts';
2
+ export * from './broadcast.ts';
package/dist/main.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { IModuleMain } from 'vona';
2
+ import { BeanSimple } from 'vona';
3
+ export declare class Main extends BeanSimple implements IModuleMain {
4
+ moduleLoading(): Promise<void>;
5
+ moduleLoaded(): Promise<void>;
6
+ configLoaded(_config: any): Promise<void>;
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { IMonkeyAppClose, IMonkeyAppClosed } from 'vona';
2
+ import { BeanSimple } from 'vona';
3
+ export declare class Monkey extends BeanSimple implements IMonkeyAppClose, IMonkeyAppClosed {
4
+ appClose(): Promise<void>;
5
+ appClosed(): Promise<void>;
6
+ }
@@ -0,0 +1,13 @@
1
+ import type { IBroadcastJobContext } from '../types/broadcast.ts';
2
+ import { BeanBase } from 'vona';
3
+ export declare class ServiceBroadcast extends BeanBase {
4
+ private __callerId;
5
+ private __channelName;
6
+ private __sub;
7
+ private __pub;
8
+ protected __init__(): void;
9
+ disposePub(): Promise<void>;
10
+ disposeSub(): Promise<void>;
11
+ emit<DATA>(info: IBroadcastJobContext<DATA>): void;
12
+ _performTask<DATA>(info: IBroadcastJobContext<DATA>): Promise<void>;
13
+ }
@@ -0,0 +1,33 @@
1
+ import type { OmitNever } from 'vona';
2
+ import type { IGeneralInfoOptions } from 'vona-module-a-executor';
3
+ import type { ServiceOnion } from 'vona-module-a-onion';
4
+ export interface IBroadcastEmitOptions extends IGeneralInfoOptions {
5
+ }
6
+ export interface IBroadcastExecute<DATA = unknown> {
7
+ execute(data?: DATA, isEmitter?: boolean): Promise<void>;
8
+ }
9
+ export interface IBroadcastJobContext<DATA> {
10
+ broadcastName: keyof IBroadcastRecord;
11
+ data?: DATA;
12
+ options?: IBroadcastEmitOptions;
13
+ callerId?: string;
14
+ }
15
+ export interface IBroadcastRecord {
16
+ }
17
+ export interface IDecoratorBroadcastOptions {
18
+ transaction?: boolean;
19
+ instance?: boolean;
20
+ }
21
+ declare module 'vona-module-a-onion' {
22
+ interface BeanOnion {
23
+ broadcast: ServiceOnion<IDecoratorBroadcastOptions, keyof IBroadcastRecord>;
24
+ }
25
+ }
26
+ declare module 'vona' {
27
+ interface ConfigOnions {
28
+ broadcast: OmitNever<IBroadcastRecord>;
29
+ }
30
+ interface IBeanSceneRecord {
31
+ broadcast: never;
32
+ }
33
+ }
@@ -0,0 +1 @@
1
+ export * from './broadcast.ts';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-broadcast",
3
3
  "type": "module",
4
- "version": "5.0.9",
4
+ "version": "5.0.11",
5
5
  "title": "a-broadcast",
6
6
  "vonaModule": {
7
7
  "dependencies": {
@@ -39,8 +39,12 @@
39
39
  "dist",
40
40
  "static"
41
41
  ],
42
+ "devDependencies": {
43
+ "clean-package": "^2.2.0",
44
+ "rimraf": "^6.0.1"
45
+ },
42
46
  "scripts": {
43
- "clean": "rimraf dist tsconfig.tsbuildinfo",
44
- "tsc:publish": "npm run clean && tsc"
47
+ "clean": "rimraf dist tsconfig.build.tsbuildinfo",
48
+ "tsc:publish": "npm run clean && vona :bin:buildModule && tsc -p tsconfig.build.json"
45
49
  }
46
50
  }