vona-module-a-broadcast 5.0.8 → 5.0.10
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 +52 -0
- package/dist/.metadata/index.js +30 -0
- package/dist/.metadata/this.d.ts +2 -0
- package/dist/.metadata/this.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/lib/beanBroadcastBase.d.ts +6 -0
- package/dist/lib/beanBroadcastBase.js +14 -0
- package/dist/lib/broadcast.d.ts +2 -0
- package/dist/lib/broadcast.js +4 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +2 -0
- package/dist/main.d.ts +7 -0
- package/dist/main.js +9 -0
- package/dist/monkey.d.ts +6 -0
- package/dist/monkey.js +12 -0
- package/dist/service/broadcast.d.ts +13 -0
- package/dist/service/broadcast.js +65 -0
- package/dist/types/broadcast.d.ts +33 -0
- package/dist/types/broadcast.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/package.json +7 -3
|
@@ -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,30 @@
|
|
|
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/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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/main.d.ts
ADDED
package/dist/main.js
ADDED
package/dist/monkey.d.ts
ADDED
package/dist/monkey.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}
|
|
@@ -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,65 @@
|
|
|
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 };
|
|
@@ -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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './broadcast.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./broadcast.js";
|
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.10",
|
|
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 && tsc -p tsconfig.build.json"
|
|
45
49
|
}
|
|
46
50
|
}
|