vona-module-a-broadcast 5.0.10 → 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.
package/dist/index.js CHANGED
@@ -1,3 +1,110 @@
1
- export * from "./.metadata/index.js";
2
- export * from "./lib/index.js";
3
- export * from "./types/index.js";
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 };
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.10",
4
+ "version": "5.0.11",
5
5
  "title": "a-broadcast",
6
6
  "vonaModule": {
7
7
  "dependencies": {
@@ -45,6 +45,6 @@
45
45
  },
46
46
  "scripts": {
47
47
  "clean": "rimraf dist tsconfig.build.tsbuildinfo",
48
- "tsc:publish": "npm run clean && tsc -p tsconfig.build.json"
48
+ "tsc:publish": "npm run clean && vona :bin:buildModule && tsc -p tsconfig.build.json"
49
49
  }
50
50
  }
@@ -1,30 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- /** service: end */
8
- /** service: begin */
9
- /** main: end */
10
- /** scope: begin */
11
- import { BeanScopeBase } from 'vona';
12
- import { Scope } from 'vona-module-a-bean';
13
- /** monkey: end */
14
- /** main: begin */
15
- import 'vona';
16
- import 'vona';
17
- import 'vona';
18
- export * from "../main.js";
19
- /** service: end */
20
- /** monkey: begin */
21
- export * from "../monkey.js";
22
- /** service: begin */
23
- export * from "../service/broadcast.js";
24
- let ScopeModuleABroadcast = class ScopeModuleABroadcast extends BeanScopeBase {
25
- };
26
- ScopeModuleABroadcast = __decorate([
27
- Scope()
28
- ], ScopeModuleABroadcast);
29
- export { ScopeModuleABroadcast };
30
- /** scope: end */
@@ -1,2 +0,0 @@
1
- export const __ThisModule__ = 'a-broadcast';
2
- export { ScopeModuleABroadcast as ScopeModule } from "./index.js";
@@ -1,14 +0,0 @@
1
- import { BeanBase } from 'vona';
2
- export class BeanBroadcastBase extends BeanBase {
3
- emit(data, options) {
4
- return this.$scope.broadcast.service.broadcast.emit(this._prepareInfo(data, options));
5
- }
6
- _prepareInfo(data, options) {
7
- options = this.$scope.executor.service.executor.prepareGeneralInfo(options);
8
- return {
9
- broadcastName: this.$onionName,
10
- data,
11
- options,
12
- };
13
- }
14
- }
@@ -1,4 +0,0 @@
1
- import { createBeanDecorator } from 'vona';
2
- export function Broadcast(options) {
3
- return createBeanDecorator('broadcast', options);
4
- }
package/dist/lib/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "./beanBroadcastBase.js";
2
- export * from "./broadcast.js";
package/dist/main.js DELETED
@@ -1,9 +0,0 @@
1
- import { BeanSimple } from 'vona';
2
- export class Main extends BeanSimple {
3
- async moduleLoading() { }
4
- async moduleLoaded() {
5
- // force broadcast init
6
- this.bean._getBean('a-broadcast.service.broadcast');
7
- }
8
- async configLoaded(_config) { }
9
- }
package/dist/monkey.js DELETED
@@ -1,12 +0,0 @@
1
- import { BeanSimple } from 'vona';
2
- import { __ThisModule__ } from "./.metadata/this.js";
3
- export class Monkey extends BeanSimple {
4
- async appClose() {
5
- const scopeSelf = this.bean.scope(__ThisModule__);
6
- await scopeSelf.service.broadcast.disposeSub();
7
- }
8
- async appClosed() {
9
- const scopeSelf = this.bean.scope(__ThisModule__);
10
- await scopeSelf.service.broadcast.disposePub();
11
- }
12
- }
@@ -1,65 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { BeanBase } from 'vona';
8
- import { Service } from 'vona-module-a-web';
9
- let ServiceBroadcast = class ServiceBroadcast extends BeanBase {
10
- __callerId;
11
- __channelName;
12
- __sub;
13
- __pub;
14
- __init__() {
15
- const app = this.app;
16
- this.__callerId = app.bean.worker.id;
17
- this.__channelName = `broadcast_${this.app.name}:`;
18
- this.__pub = app.bean.redis.get('broadcast').duplicate();
19
- this.__sub = app.bean.redis.get('broadcast').duplicate();
20
- this.__sub.subscribe(this.__channelName, () => { });
21
- this.__sub.on('message', (_channel, info) => {
22
- this._performTask(JSON.parse(info))
23
- .then(() => {
24
- // do nothing
25
- })
26
- .catch((err) => {
27
- this.$logger.error(err);
28
- });
29
- });
30
- }
31
- async disposePub() {
32
- await this.__pub?.quit();
33
- }
34
- async disposeSub() {
35
- await this.__sub?.quit();
36
- }
37
- emit(info) {
38
- info.callerId = this.__callerId;
39
- this.__pub.publish(this.__channelName, JSON.stringify(info));
40
- }
41
- async _performTask(info) {
42
- // isEmitter
43
- const isEmitter = info.callerId === this.__callerId;
44
- // broadcast config
45
- const broadcastItem = this.bean.onion.broadcast.getOnionSlice(info.broadcastName);
46
- const broadcastConfig = this.bean.onion.broadcast.getOnionOptions(info.broadcastName);
47
- // execute
48
- return await this.bean.executor.newCtx(async () => {
49
- const beanFullName = broadcastItem.beanOptions.beanFullName;
50
- const beanInstance = this.app.bean._getBean(beanFullName);
51
- return await beanInstance.execute(info.data, isEmitter);
52
- }, {
53
- dbInfo: info.options?.dbInfo,
54
- locale: info.options?.locale,
55
- instanceName: info.options?.instanceName,
56
- extraData: info.options?.extraData,
57
- transaction: broadcastConfig?.transaction,
58
- instance: broadcastConfig?.instance !== false,
59
- });
60
- }
61
- };
62
- ServiceBroadcast = __decorate([
63
- Service()
64
- ], ServiceBroadcast);
65
- export { ServiceBroadcast };
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export * from "./broadcast.js";