vona-module-a-broadcast 5.0.10 → 5.0.12
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/.metadata/index.d.ts +15 -16
- package/dist/index.js +110 -3
- package/package.json +2 -2
- package/dist/.metadata/index.js +0 -30
- package/dist/.metadata/this.js +0 -2
- package/dist/lib/beanBroadcastBase.js +0 -14
- package/dist/lib/broadcast.js +0 -4
- package/dist/lib/index.js +0 -2
- package/dist/main.js +0 -9
- package/dist/monkey.js +0 -12
- package/dist/service/broadcast.js +0 -65
- package/dist/types/broadcast.js +0 -1
- package/dist/types/index.js +0 -1
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
import type { BeanScopeUtil } from 'vona';
|
|
2
|
-
/** service: end */
|
|
3
|
-
/** service: begin */
|
|
4
|
-
import type { ServiceBroadcast } from '../service/broadcast.ts';
|
|
5
|
-
/** service: end */
|
|
6
1
|
/** service: begin */
|
|
7
|
-
|
|
8
|
-
/** scope: begin */
|
|
9
|
-
import { BeanScopeBase } from 'vona';
|
|
10
|
-
/** monkey: end */
|
|
11
|
-
/** main: begin */
|
|
12
|
-
import 'vona';
|
|
13
|
-
import 'vona';
|
|
2
|
+
export * from '../service/broadcast.ts';
|
|
14
3
|
import 'vona';
|
|
15
|
-
export * from '../main.ts';
|
|
16
4
|
declare module 'vona-module-a-web' {
|
|
17
5
|
interface IServiceRecord {
|
|
18
6
|
'a-broadcast:broadcast': never;
|
|
@@ -22,9 +10,15 @@ declare module 'vona-module-a-broadcast' {
|
|
|
22
10
|
interface ServiceBroadcast {
|
|
23
11
|
}
|
|
24
12
|
}
|
|
13
|
+
/** service: end */
|
|
14
|
+
/** service: begin */
|
|
15
|
+
import type { ServiceBroadcast } from '../service/broadcast.ts';
|
|
25
16
|
export interface IModuleService {
|
|
26
|
-
broadcast: ServiceBroadcast;
|
|
17
|
+
'broadcast': ServiceBroadcast;
|
|
27
18
|
}
|
|
19
|
+
/** service: end */
|
|
20
|
+
/** service: begin */
|
|
21
|
+
import 'vona';
|
|
28
22
|
declare module 'vona' {
|
|
29
23
|
interface IBeanRecordGeneral {
|
|
30
24
|
'a-broadcast.service.broadcast': ServiceBroadcast;
|
|
@@ -33,14 +27,19 @@ declare module 'vona' {
|
|
|
33
27
|
/** service: end */
|
|
34
28
|
/** monkey: begin */
|
|
35
29
|
export * from '../monkey.ts';
|
|
36
|
-
/**
|
|
37
|
-
|
|
30
|
+
/** monkey: end */
|
|
31
|
+
/** main: begin */
|
|
32
|
+
export * from '../main.ts';
|
|
33
|
+
/** main: end */
|
|
34
|
+
/** scope: begin */
|
|
35
|
+
import { BeanScopeBase, type BeanScopeUtil } from 'vona';
|
|
38
36
|
export declare class ScopeModuleABroadcast extends BeanScopeBase {
|
|
39
37
|
}
|
|
40
38
|
export interface ScopeModuleABroadcast {
|
|
41
39
|
util: BeanScopeUtil;
|
|
42
40
|
service: IModuleService;
|
|
43
41
|
}
|
|
42
|
+
import 'vona';
|
|
44
43
|
declare module 'vona' {
|
|
45
44
|
interface IBeanScopeRecord {
|
|
46
45
|
'a-broadcast': ScopeModuleABroadcast;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { BeanInfo, BeanBase, BeanSimple, BeanScopeBase, createBeanDecorator } from 'vona';
|
|
2
|
+
import { Service } from 'vona-module-a-web';
|
|
3
|
+
import { Scope } from 'vona-module-a-bean';
|
|
4
|
+
|
|
5
|
+
var _dec$1, _dec2$1, _class$1;
|
|
6
|
+
let ServiceBroadcast = (_dec$1 = Service(), _dec2$1 = BeanInfo({
|
|
7
|
+
module: "a-broadcast"
|
|
8
|
+
}), _dec$1(_class$1 = _dec2$1(_class$1 = class ServiceBroadcast extends BeanBase {
|
|
9
|
+
constructor(...args) {
|
|
10
|
+
super(...args);
|
|
11
|
+
this.__callerId = void 0;
|
|
12
|
+
this.__channelName = void 0;
|
|
13
|
+
this.__sub = void 0;
|
|
14
|
+
this.__pub = void 0;
|
|
15
|
+
}
|
|
16
|
+
__init__() {
|
|
17
|
+
const app = this.app;
|
|
18
|
+
this.__callerId = app.bean.worker.id;
|
|
19
|
+
this.__channelName = `broadcast_${this.app.name}:`;
|
|
20
|
+
this.__pub = app.bean.redis.get('broadcast').duplicate();
|
|
21
|
+
this.__sub = app.bean.redis.get('broadcast').duplicate();
|
|
22
|
+
this.__sub.subscribe(this.__channelName, () => {});
|
|
23
|
+
this.__sub.on('message', (_channel, info) => {
|
|
24
|
+
this._performTask(JSON.parse(info)).then(() => {
|
|
25
|
+
// do nothing
|
|
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
|
+
}) || _class$1) || _class$1);
|
|
62
|
+
|
|
63
|
+
const __ThisModule__ = 'a-broadcast';
|
|
64
|
+
|
|
65
|
+
class Monkey extends BeanSimple {
|
|
66
|
+
async appClose() {
|
|
67
|
+
const scopeSelf = this.bean.scope(__ThisModule__);
|
|
68
|
+
await scopeSelf.service.broadcast.disposeSub();
|
|
69
|
+
}
|
|
70
|
+
async appClosed() {
|
|
71
|
+
const scopeSelf = this.bean.scope(__ThisModule__);
|
|
72
|
+
await scopeSelf.service.broadcast.disposePub();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class Main extends BeanSimple {
|
|
77
|
+
async moduleLoading() {}
|
|
78
|
+
async moduleLoaded() {
|
|
79
|
+
// force broadcast init
|
|
80
|
+
this.bean._getBean('a-broadcast.service.broadcast');
|
|
81
|
+
}
|
|
82
|
+
async configLoaded(_config) {}
|
|
83
|
+
}
|
|
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.
|
|
4
|
+
"version": "5.0.12",
|
|
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
|
}
|
package/dist/.metadata/index.js
DELETED
|
@@ -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 */
|
package/dist/.metadata/this.js
DELETED
|
@@ -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
|
-
}
|
package/dist/lib/broadcast.js
DELETED
package/dist/lib/index.js
DELETED
package/dist/main.js
DELETED
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 };
|
package/dist/types/broadcast.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./broadcast.js";
|