@dshtrading/eventbus 0.1.0
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/LICENSE +75 -0
- package/lib/index.d.ts +45 -0
- package/lib/index.js +56 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Copyright (c) 2026 zhu1090093659 (dsh-trading)
|
|
2
|
+
|
|
3
|
+
# PolyForm Noncommercial License 1.0.0
|
|
4
|
+
|
|
5
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
14
|
+
|
|
15
|
+
## Distribution License
|
|
16
|
+
|
|
17
|
+
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
18
|
+
|
|
19
|
+
## Notices
|
|
20
|
+
|
|
21
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
22
|
+
|
|
23
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
24
|
+
|
|
25
|
+
## Changes and New Works License
|
|
26
|
+
|
|
27
|
+
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
28
|
+
|
|
29
|
+
## Patent License
|
|
30
|
+
|
|
31
|
+
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
32
|
+
|
|
33
|
+
## Noncommercial Purposes
|
|
34
|
+
|
|
35
|
+
Any noncommercial purpose is a permitted purpose.
|
|
36
|
+
|
|
37
|
+
## Personal Uses
|
|
38
|
+
|
|
39
|
+
Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
|
|
40
|
+
|
|
41
|
+
## Noncommercial Organizations
|
|
42
|
+
|
|
43
|
+
Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
|
|
44
|
+
|
|
45
|
+
## Fair Use
|
|
46
|
+
|
|
47
|
+
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
48
|
+
|
|
49
|
+
## No Other Rights
|
|
50
|
+
|
|
51
|
+
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
52
|
+
|
|
53
|
+
## Patent Defense
|
|
54
|
+
|
|
55
|
+
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
56
|
+
|
|
57
|
+
## Violations
|
|
58
|
+
|
|
59
|
+
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
60
|
+
|
|
61
|
+
## No Liability
|
|
62
|
+
|
|
63
|
+
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
64
|
+
|
|
65
|
+
## Definitions
|
|
66
|
+
|
|
67
|
+
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
68
|
+
|
|
69
|
+
**You** refers to the individual or entity agreeing to these terms.
|
|
70
|
+
|
|
71
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
72
|
+
|
|
73
|
+
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
74
|
+
|
|
75
|
+
**Use** means anything you do with the software requiring one of your licenses.
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Context, Service } from "@deepseek-ai/cordis";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Cordis 插件名 = patch 行 id(TEMPLATES §8):市场无关共享行 id 全仓唯一,
|
|
5
|
+
* `dsh-trading-` 命名空间(insert-only 铁律 #1)。
|
|
6
|
+
*/
|
|
7
|
+
declare const name = "dsh-trading-eventbus";
|
|
8
|
+
/**
|
|
9
|
+
* store 词汇(v1,封闭集合)。新 store = 本 union 加成员 + 客户端 handler 注册,
|
|
10
|
+
* 事件面不开放任意字符串(防注入 & 保持可枚举)。
|
|
11
|
+
*/
|
|
12
|
+
type TradingEventStore = 'indicators' | 'strategies' | 'knowledge' | 'watchlists' | 'selection' | 'routing';
|
|
13
|
+
/** 单条失效信号(桥 SSE 帧的 data 载荷形状,也是 subscribe 回调入参)。 */
|
|
14
|
+
interface TradingEvent {
|
|
15
|
+
readonly store: TradingEventStore;
|
|
16
|
+
/** 该 store 的修订号(emit 自增;客户端据此做幂等 refetch 判重)。 */
|
|
17
|
+
readonly revision: number;
|
|
18
|
+
}
|
|
19
|
+
/** 订阅回调;同步调用,emit 方不等待。 */
|
|
20
|
+
type TradingEventListener = (event: TradingEvent) => void;
|
|
21
|
+
/** SDK 服务键(与 Context 模块增强一致;消费者 `ctx.get('tradingEvents', false)`)。 */
|
|
22
|
+
declare const TRADING_EVENTS_KEY = "tradingEvents";
|
|
23
|
+
/**
|
|
24
|
+
* tradingEvents 服务:per-store revision 自增 + 订阅扇出。
|
|
25
|
+
*
|
|
26
|
+
* TS 编译期 private 而非 ECMAScript #(realm 代理按类身份校验,README 定稿 5)。
|
|
27
|
+
*/
|
|
28
|
+
declare class TradingEventsService extends Service {
|
|
29
|
+
private readonly revisions;
|
|
30
|
+
private readonly listeners;
|
|
31
|
+
constructor(ctx: Context, serviceName?: string);
|
|
32
|
+
/** 某 store 当前修订号(从 0 起;未 emit 过 = 0)。 */
|
|
33
|
+
revision(store: TradingEventStore): number;
|
|
34
|
+
/**
|
|
35
|
+
* 发布失效信号:revision 自增 + 同步扇出给全部订阅者。
|
|
36
|
+
* 监听器抛错不阻断其他监听器(错误打到 console,总线不因消费者崩溃)。
|
|
37
|
+
*/
|
|
38
|
+
emit(store: TradingEventStore): TradingEvent;
|
|
39
|
+
/** 订阅失效信号;返回退订函数(幂等)。 */
|
|
40
|
+
subscribe(listener: TradingEventListener): () => void;
|
|
41
|
+
}
|
|
42
|
+
/** Host plugin body:provide tradingEvents(无配置面——总线没有可调行为)。 */
|
|
43
|
+
declare function apply(ctx: Context): void;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { TRADING_EVENTS_KEY, TradingEvent, TradingEventListener, TradingEventStore, TradingEventsService, apply, name };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Cordis 插件名 = patch 行 id(TEMPLATES §8):市场无关共享行 id 全仓唯一,
|
|
5
|
+
* `dsh-trading-` 命名空间(insert-only 铁律 #1)。
|
|
6
|
+
*/
|
|
7
|
+
const name = "dsh-trading-eventbus";
|
|
8
|
+
/** SDK 服务键(与 Context 模块增强一致;消费者 `ctx.get('tradingEvents', false)`)。 */
|
|
9
|
+
const TRADING_EVENTS_KEY = "tradingEvents";
|
|
10
|
+
/**
|
|
11
|
+
* tradingEvents 服务:per-store revision 自增 + 订阅扇出。
|
|
12
|
+
*
|
|
13
|
+
* TS 编译期 private 而非 ECMAScript #(realm 代理按类身份校验,README 定稿 5)。
|
|
14
|
+
*/
|
|
15
|
+
var TradingEventsService = class extends Service {
|
|
16
|
+
revisions = /* @__PURE__ */ new Map();
|
|
17
|
+
listeners = /* @__PURE__ */ new Set();
|
|
18
|
+
constructor(ctx, serviceName = TRADING_EVENTS_KEY) {
|
|
19
|
+
super(ctx, serviceName);
|
|
20
|
+
}
|
|
21
|
+
/** 某 store 当前修订号(从 0 起;未 emit 过 = 0)。 */
|
|
22
|
+
revision(store) {
|
|
23
|
+
return this.revisions.get(store) ?? 0;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 发布失效信号:revision 自增 + 同步扇出给全部订阅者。
|
|
27
|
+
* 监听器抛错不阻断其他监听器(错误打到 console,总线不因消费者崩溃)。
|
|
28
|
+
*/
|
|
29
|
+
emit(store) {
|
|
30
|
+
const revision = this.revision(store) + 1;
|
|
31
|
+
this.revisions.set(store, revision);
|
|
32
|
+
const event = {
|
|
33
|
+
store,
|
|
34
|
+
revision
|
|
35
|
+
};
|
|
36
|
+
for (const listener of this.listeners) try {
|
|
37
|
+
listener(event);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error("[dsh-trading/eventbus] listener crashed:", error);
|
|
40
|
+
}
|
|
41
|
+
return event;
|
|
42
|
+
}
|
|
43
|
+
/** 订阅失效信号;返回退订函数(幂等)。 */
|
|
44
|
+
subscribe(listener) {
|
|
45
|
+
this.listeners.add(listener);
|
|
46
|
+
return () => {
|
|
47
|
+
this.listeners.delete(listener);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
/** Host plugin body:provide tradingEvents(无配置面——总线没有可调行为)。 */
|
|
52
|
+
function apply(ctx) {
|
|
53
|
+
new TradingEventsService(ctx);
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { TRADING_EVENTS_KEY, TradingEventsService, apply, name };
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dshtrading/eventbus",
|
|
3
|
+
"description": "In-process invalidation event bus for dsh-trading: tradingEvents cordis service (emit/subscribe/per-store revision), zero HTTP, zero business data",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib"
|
|
17
|
+
],
|
|
18
|
+
"license": "PolyForm-Noncommercial-1.0.0",
|
|
19
|
+
"dependencies": {},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@deepseek-ai/cordis": ">=4.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"tsdown": "^0.22.0",
|
|
25
|
+
"vitest": "^3.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsdown",
|
|
29
|
+
"test": "vitest run"
|
|
30
|
+
}
|
|
31
|
+
}
|