@mzzsfy/dsh-stock-assistant 0.7.1 → 0.8.1
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/CHANGELOG.md +459 -0
- package/README.md +33 -19
- package/package.json +67 -65
- package/src/application.mjs +186 -52
- package/src/catalog.mjs +50 -25
- package/src/client.js +436 -148
- package/src/collector.mjs +128 -34
- package/src/executor.mjs +59 -23
- package/src/index.js +45 -41
- package/src/kline-cache.mjs +6 -7
- package/src/market-model.mjs +88 -16
- package/src/provider-registry.mjs +5 -1
- package/src/provider-router.mjs +76 -9
- package/src/providers/eastmoney.mjs +226 -245
- package/src/providers/sina.mjs +3 -1
- package/src/providers/tencent.mjs +168 -122
- package/src/providers/tushare.mjs +92 -92
- package/src/recovery.mjs +64 -0
- package/src/route-gate.mjs +85 -29
- package/src/routes.mjs +68 -68
- package/src/schemas.mjs +126 -19
- package/src/state.mjs +9 -5
- package/src/ticks.mjs +45 -0
- package/src/trend-cache.mjs +26 -0
- package//345/205/274/345/256/271/346/200/247/346/265/213/350/257/225.md +215 -1
package/src/application.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto'
|
|
2
2
|
import { z } from 'zod'
|
|
3
3
|
import { createRegistry } from './provider-registry.mjs'
|
|
4
|
-
import { createRouter } from './provider-router.mjs'
|
|
4
|
+
import { createRouter, RECOVERY_PROBE_MS, TRANSIENT_CODES } from './provider-router.mjs'
|
|
5
|
+
import { createRecovery, createRecoveryLoop } from './recovery.mjs'
|
|
5
6
|
import { tushare } from './providers/tushare.mjs'
|
|
6
7
|
import { tencent } from './providers/tencent.mjs'
|
|
7
8
|
import { sina } from './providers/sina.mjs'
|
|
@@ -9,7 +10,7 @@ import { eastmoney } from './providers/eastmoney.mjs'
|
|
|
9
10
|
import { xueqiu } from './providers/xueqiu.mjs'
|
|
10
11
|
import { finnhub } from './providers/finnhub.mjs'
|
|
11
12
|
import { openState, digest } from './state.mjs'
|
|
12
|
-
import { parseConfiguration, preferencesSchema, defaultConfig, klineQuerySchema } from './schemas.mjs'
|
|
13
|
+
import { parseConfiguration, preferencesSchema, defaultConfig, klineQuerySchema, refreshSecuritiesSchema, CAPABILITIES, TREND_ROUTE_MIGRATION, tickPeriodMs } from './schemas.mjs'
|
|
13
14
|
import { createWatchlistService } from './service.mjs'
|
|
14
15
|
import { createBudget } from './budget.mjs'
|
|
15
16
|
import { createExecutor } from './executor.mjs'
|
|
@@ -17,11 +18,14 @@ import { createCollector, deriveDelay } from './collector.mjs'
|
|
|
17
18
|
import { createCatalog } from './catalog.mjs'
|
|
18
19
|
import { createDemand } from './demand.mjs'
|
|
19
20
|
import { createKlineCache } from './kline-cache.mjs'
|
|
20
|
-
import {
|
|
21
|
+
import { createTrendCache } from './trend-cache.mjs'
|
|
22
|
+
import { createTickStore } from './ticks.mjs'
|
|
23
|
+
import { fail, parseSecurityId, MARKET_META, clockInZone } from './market-model.mjs'
|
|
21
24
|
const WINDOW = 5 * 60 * 1000
|
|
25
|
+
// 分时来源(东财/腾讯)的时间戳统一按北京时间给出, 拍点线的横轴必须与之一致, 否则切到离线时整体偏移
|
|
26
|
+
const TREND_SOURCE_TIME_ZONE = 'Asia/Shanghai'
|
|
22
27
|
const US_SYMBOL_TTL = 24 * 60 * 60 * 1000
|
|
23
28
|
const US_SYMBOL_LIMIT = 500
|
|
24
|
-
const PROBE_LIMIT = 512
|
|
25
29
|
export async function createApplication({ storageDomain, providers = [tushare, tencent, sina, eastmoney, xueqiu, finnhub], publish = () => {}, env = process.env, credentials = null, fetch = globalThis.fetch, now = Date.now, timers = globalThis, vendorAvailable = true }) {
|
|
26
30
|
const serverEpoch = randomUUID(), checks = new Map()
|
|
27
31
|
// 凭据解析: 宿主提供 credentials 服务时交给它(插件存储层优先, 再逐层回退到进程环境与 .env 文件),
|
|
@@ -29,9 +33,7 @@ export async function createApplication({ storageDomain, providers = [tushare, t
|
|
|
29
33
|
// 接口按能力逐个核对: 宿主给的对象缺哪个方法, 就只退回哪条路径, 而不是在取数时炸掉。
|
|
30
34
|
const credentialStore = credentials && ['resolve', 'set', 'unset'].every(method => typeof credentials[method] === 'function') ? credentials : null
|
|
31
35
|
const resolveCredential = credentialStore ? async ref => (await credentialStore.resolve(ref))?.value : async ref => env[ref]
|
|
32
|
-
|
|
33
|
-
const probeCache = new Map()
|
|
34
|
-
let snapshotSeq = 0, stopped = false, collector, catalog, demand, watchlist
|
|
36
|
+
let snapshotSeq = 0, stopped = false, collector, catalog, demand, watchlist, recoveryLoop
|
|
35
37
|
let ensuring = null, lastEnsure = -Infinity, ensureError = null, hadDemand = false, ensureCaches = () => {}
|
|
36
38
|
const usSymbols = new Map()
|
|
37
39
|
const touched = () => snapshotSeq++
|
|
@@ -39,34 +41,57 @@ export async function createApplication({ storageDomain, providers = [tushare, t
|
|
|
39
41
|
// 凭据存在性只给设置页看, 而解析是异步的、快照是同步的: 保存配置与启动时各算一次, 快照读这份结果。
|
|
40
42
|
const credentialPresence = new Map()
|
|
41
43
|
const refreshCredentialPresence = async () => {
|
|
42
|
-
for (const p of state.get().providers)
|
|
44
|
+
for (const p of state.get().providers) {
|
|
45
|
+
credentialPresence.set(`${p.id}:credential`, p.credentialRef === null || !!(await resolveCredential(p.credentialRef)))
|
|
46
|
+
if (p.proxyCredentialRef) credentialPresence.set(`${p.id}:proxy`, !!(await resolveCredential(p.proxyCredentialRef)))
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
|
-
let state, registry, executor, getControl, router, klineCache
|
|
49
|
+
let state, registry, executor, getControl, router, klineCache, trendCache, ticks
|
|
45
50
|
try {
|
|
46
51
|
state = await openState(storageDomain, changed, now)
|
|
47
52
|
await refreshCredentialPresence()
|
|
48
53
|
registry = createRegistry(providers)
|
|
49
54
|
const budget = createBudget(now)
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
// 代理出口: undici ProxyAgent + 同一份 undici.fetch。dispatcher 是 undici 私有契约,
|
|
56
|
+
// Node 内置 fetch 不认 userland dispatcher(invalid onRequestStart method), 不能混用。
|
|
57
|
+
// 包不可用时两者都为 null, 代理实例在请求时明确 NETWORK/502, 不静默直连。
|
|
58
|
+
let proxyFactory = null, proxyFetch = null
|
|
59
|
+
try {
|
|
60
|
+
const undici = await import('undici')
|
|
61
|
+
if (typeof undici.fetch === 'function') { proxyFactory = url => new undici.ProxyAgent(url); proxyFetch = (...args) => undici.fetch(...args) }
|
|
62
|
+
} catch {}
|
|
63
|
+
executor = createExecutor({ registry, budget, env, resolveCredential, fetch, proxyFetch, now, timers, usSymbols, proxyFactory, tickPeriodMs: () => tickPeriodMs(state.get().preferences) })
|
|
54
64
|
getControl = state.get
|
|
55
|
-
|
|
65
|
+
// 自动故障切换/手动回主源只换来源: 清掉该路由的退避与失败计数即可, 不能重置 collector。
|
|
66
|
+
// 重置会递增代次并中止在飞请求, 当前刷新随后被判定成"配置已变化"抛假 ROUTE_CONFLICT。
|
|
67
|
+
router = createRouter(getControl, now, routeId => collector?.routeChanged(routeId))
|
|
56
68
|
klineCache = createKlineCache({ cacheTable: state.klineCache, now })
|
|
69
|
+
// 分时当日缓存走独立小池: 它与报价拍点都只放内存, 不入配置记录
|
|
70
|
+
trendCache = createTrendCache({ table: state.trendCache, now })
|
|
71
|
+
ticks = createTickStore({ now })
|
|
72
|
+
// 回探跟着面板活跃走: 有人看时每 RECOVERY_PROBE_MS 把已降级路由的上级全探一遍, 没人看就停
|
|
73
|
+
recoveryLoop = createRecoveryLoop({ probe: createRecovery({ getControl, router, executor }), timers, interval: RECOVERY_PROBE_MS, canRun: () => executor.idle() })
|
|
57
74
|
catalog = createCatalog({ state, getControl, router, executor, registry, now, changed })
|
|
58
75
|
demand = createDemand(() => {
|
|
59
76
|
const wanted = demand.active(), opening = wanted && !hadDemand; hadDemand = wanted
|
|
60
77
|
if (wanted) {
|
|
61
|
-
ensureCaches()
|
|
62
78
|
// 缓存新鲜时进入面板不重复打上游(限流主因); 过期才拉取, 定时器照常量节奏维持
|
|
63
79
|
const freshFor = (getControl().preferences?.refreshSeconds ?? 15) * 1000
|
|
64
80
|
if (opening && !collector?.freshWithin(freshFor)) collector?.refresh().catch(() => {})
|
|
65
81
|
collector?.reconcile()
|
|
66
|
-
} else
|
|
82
|
+
} else {
|
|
83
|
+
// 后台预热只在面板空闲时做: 之前只写在 wanted 分支又要求 !demand.active(), 两个条件互斥,
|
|
84
|
+
// 目录/日历永远不会在后台补, 过期目录只能等用户手动同步。
|
|
85
|
+
collector?.cancelIdle(); ensureCaches()
|
|
86
|
+
}
|
|
87
|
+
// 排在首屏刷新之后: 探测也占额度, 不该跟用户要的数据抢顺序
|
|
88
|
+
recoveryLoop.sync(wanted)
|
|
67
89
|
}, now, timers)
|
|
68
|
-
collector = createCollector({ getControl, router, registry, executor, resolveSecurity: catalog.resolve, changed, touched, now, timers, active: demand.active, calendarState: catalog.marketState })
|
|
90
|
+
collector = createCollector({ getControl, router, registry, executor, resolveSecurity: catalog.resolve, changed, touched, now, timers, active: demand.active, calendarState: catalog.marketState, ticks })
|
|
69
91
|
watchlist = createWatchlistService(state, catalog.resolve, now)
|
|
92
|
+
// 存量配置升级: 分时能力独立后没有 trend 路由的库在打开时补齐。
|
|
93
|
+
// 补齐失败不该让整个面板躺下(面板可用性高于分时), 记下原因继续, 与目录预热同构
|
|
94
|
+
try { await ensureTrendRoutes() } catch (e) { ensureError = { message: `分时来源补齐失败:${e.message}`, at: now() } }
|
|
70
95
|
// 面板活跃(demand)时让路: 目录后台同步占满并发槽会拖死交互请求(浏览504实测), 仅在面板空闲时补目录
|
|
71
96
|
ensureCaches = () => {
|
|
72
97
|
if (ensuring || now() - lastEnsure < 60 * 1000 || demand.active()) return
|
|
@@ -81,17 +106,15 @@ export async function createApplication({ storageDomain, providers = [tushare, t
|
|
|
81
106
|
}
|
|
82
107
|
const snapshot = () => {
|
|
83
108
|
const control = state.get(); delete control.operations
|
|
84
|
-
return { serverEpoch, snapshotSeq, routingRevision: control.routingRevision, control, quotes: collector.
|
|
109
|
+
return { serverEpoch, snapshotSeq, routingRevision: control.routingRevision, control, quotes: collector.watchEntries(), routeSelections: router.selections(), catalogs: catalog.status(), adapters: registry.descriptors(), suggested: defaultConfig(), ensureError, vendorAvailable, providerStatus: control.providers.map(p => ({ id: p.id, credentialPresent: p.credentialRef === null || credentialPresence.get(`${p.id}:credential`) === true, credentialRef: p.credentialRef, proxy: !!p.proxy, proxyCredentialRef: p.proxyCredentialRef ?? null, proxyCredentialPresent: p.proxyCredentialRef ? credentialPresence.get(`${p.id}:proxy`) === true : null, endpointsCovered: Object.keys(p.endpoints || {}).length, recentRequests: executor.recentRequests(p.id) })), klineReady: Object.fromEntries(control.routes.filter(r => r.capability === 'kline').map(r => [r.market, true])), markets: Object.fromEntries(Object.entries(MARKET_META).map(([market, meta]) => [market, { currency: meta.currency, verified: meta.verifiedByDefault }])) }
|
|
85
110
|
}
|
|
86
111
|
function assertLive() { if (stopped) fail('STOPPED', '股票工具已停止', 503) }
|
|
87
112
|
async function providerCheck(input, signal) {
|
|
88
113
|
assertLive()
|
|
89
114
|
const config = parseConfiguration({ providers: input.providers, routes: input.routes })
|
|
90
|
-
const caps = z.array(z.enum(
|
|
115
|
+
const caps = z.array(z.enum(CAPABILITIES)).min(1).max(CAPABILITIES.length).parse(input.capabilities)
|
|
91
116
|
const at = now()
|
|
92
117
|
for (const [id, check] of checks) if (check.until <= at) checks.delete(id)
|
|
93
|
-
// 过期目标直接淘汰: 键空间随实例/市场/能力组合有界, 但不留过期条目占位
|
|
94
|
-
for (const [key, entry] of probeCache) if (entry.until <= at) probeCache.delete(key)
|
|
95
118
|
if (checks.size >= 64) fail('CHECK_LIMIT', '检查请求过多,请稍后重试', 429)
|
|
96
119
|
const results = []
|
|
97
120
|
for (const route of config.routes.filter(r => caps.includes(r.capability))) for (const target of [route.primaryInstanceId, ...route.fallbackInstanceIds]) {
|
|
@@ -103,15 +126,16 @@ export async function createApplication({ storageDomain, providers = [tushare, t
|
|
|
103
126
|
const startedAt = now()
|
|
104
127
|
try {
|
|
105
128
|
const result = await executor.run(instance, route.capability, { market: route.market, instrument: route.instrument }, { probe: true, signal })
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
results.push({ key, providerInstanceId: instance.id, capability: route.capability, market: route.market, status, ms: now() - startedAt })
|
|
129
|
+
// 探针必须由同名能力的端点产出: 适配器拿别的能力冒充(漏实现分支)时不能当就绪, 且要说清是谁被验了
|
|
130
|
+
const ready = result?.status === 'ready' && result.capability === route.capability
|
|
131
|
+
results.push({ key, providerInstanceId: instance.id, capability: route.capability, market: route.market, status: ready ? 'ready' : 'unavailable', ms: now() - startedAt, ...(ready ? {} : { error: { code: 'PROBE_MISMATCH', message: `探针校验的是${result?.capability ?? '未知'}能力` } }) })
|
|
110
132
|
} catch (e) { results.push({ key, providerInstanceId: instance.id, capability: route.capability, market: route.market, status: 'denied', ms: now() - startedAt, error: { code: e.code, message: e.message } }) }
|
|
111
133
|
}
|
|
112
134
|
const checkId = randomUUID()
|
|
113
135
|
checks.set(checkId, { hash: digest(config), until: now() + WINDOW, results })
|
|
114
|
-
|
|
136
|
+
// 解除采集暂停只认行情: 分时/目录/K 线的探针失败不该左右行情采集状态机
|
|
137
|
+
const quoteResults = results.filter(r => r.capability === 'quotes')
|
|
138
|
+
if (digest(config) === digest({ providers: getControl().providers, routes: getControl().routes }) && quoteResults.length && quoteResults.every(r => r.status === 'ready')) collector.resume()
|
|
115
139
|
return { checkId, checks: results }
|
|
116
140
|
}
|
|
117
141
|
async function configuration(operation) {
|
|
@@ -139,20 +163,91 @@ export async function createApplication({ storageDomain, providers = [tushare, t
|
|
|
139
163
|
if (meta) { item.currency = meta.currency; item.priceScale = meta.priceScale }
|
|
140
164
|
}
|
|
141
165
|
}
|
|
142
|
-
//
|
|
143
|
-
|
|
166
|
+
// K 线类请求的即时故障转移: 触发码 NETWORK/TIMEOUT/BAD_PAYLOAD 时顺着「环上下一格」试一次;
|
|
167
|
+
// 只有当前选择自己的失败算一轮, 顺着链试备源是同一轮里的补救, 不额外计次
|
|
168
|
+
async function runWithFailover(capability, route, primary, fallbacks, request, signal) {
|
|
144
169
|
const chain = [primary, ...fallbacks]
|
|
145
|
-
let lastError
|
|
146
|
-
for (const cand of chain) {
|
|
170
|
+
let lastError, unsupported
|
|
171
|
+
for (const [index, cand] of chain.entries()) {
|
|
147
172
|
try {
|
|
148
|
-
|
|
173
|
+
const result = await executor.run(cand, capability, request, { signal })
|
|
174
|
+
// 当前选择能出数就是最好的证据: 清掉它的失败计数与探测退避
|
|
175
|
+
if (index === 0) router.recordRound(route.id, null)
|
|
176
|
+
return result
|
|
149
177
|
} catch (e) {
|
|
178
|
+
if (index === 0) router.recordRound(route.id, e)
|
|
179
|
+
// 备源不支持这个能力就继续试下一个; 用户该看到的是主源的真实错误, 不是备源的描述符差异
|
|
180
|
+
if (e.code === 'UNSUPPORTED_CAPABILITY') { unsupported ??= e; continue }
|
|
150
181
|
lastError = e
|
|
151
|
-
|
|
152
|
-
if (!['NETWORK', 'TIMEOUT', 'BAD_PAYLOAD'].includes(e.code)) throw e
|
|
182
|
+
if (!TRANSIENT_CODES.includes(e.code) && e.code !== 'BAD_PAYLOAD') throw e
|
|
153
183
|
}
|
|
154
184
|
}
|
|
155
|
-
throw lastError
|
|
185
|
+
throw lastError ?? unsupported
|
|
186
|
+
}
|
|
187
|
+
// 分时没有路由时用户只会看到"未配置数据来源", 看不出缺的是哪一种能力
|
|
188
|
+
function selectRoute(capability, market) {
|
|
189
|
+
try { return router.select(capability, market, 'equity') }
|
|
190
|
+
catch (e) {
|
|
191
|
+
if (capability === 'trend' && e.code === 'NO_ROUTE') fail('NO_ROUTE', '未配置分时来源:请在设置的能力路由里为分时指定来源', 422)
|
|
192
|
+
throw e
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// 分时拆成独立能力之前的存量配置没有 trend 路由: 打开时按适配器能力声明补齐, 优先沿用该市场 K 线的来源。
|
|
196
|
+
// 不能假设某个具体来源: 谁声明了 trend 且覆盖该市场, 谁才有资格承接下来。
|
|
197
|
+
async function ensureTrendRoutes() {
|
|
198
|
+
const control = state.get()
|
|
199
|
+
if (control.routeMigration >= TREND_ROUTE_MIGRATION) return
|
|
200
|
+
const declared = registry.descriptors()
|
|
201
|
+
const capable = (instance, market) => {
|
|
202
|
+
const descriptor = declared.find(d => d.adapterId === instance.adapterId)
|
|
203
|
+
return !!descriptor?.capabilities.includes('trend') && descriptor.markets.includes(market)
|
|
204
|
+
}
|
|
205
|
+
// 市场面取现有任意路由: 分时不依赖 K 线, 用户删掉 K 线路由不代表这个市场不要分时
|
|
206
|
+
const markets = [...new Set(control.routes.map(r => r.market))]
|
|
207
|
+
const missing = [], spares = []
|
|
208
|
+
for (const market of markets) {
|
|
209
|
+
const route = control.routes.find(r => r.market === market && r.capability === 'trend')
|
|
210
|
+
if (!route) {
|
|
211
|
+
const kline = control.routes.find(r => r.market === market && r.capability === 'kline')
|
|
212
|
+
const order = [kline?.primaryInstanceId, ...control.providers.map(p => p.id)].filter(Boolean)
|
|
213
|
+
const target = order.map(id => control.providers.find(p => p.id === id)).find(instance => instance?.enabled !== false && capable(instance, market))
|
|
214
|
+
if (target) missing.push({ id: `${market.toLowerCase()}-trend`, capability: 'trend', market, instrument: 'equity', primaryInstanceId: target.id, fallbackInstanceIds: [], failoverMode: 'off', maxDelaySeconds: null, acceptUnknownDelay: true })
|
|
215
|
+
continue
|
|
216
|
+
}
|
|
217
|
+
// 主源不该是唯一来源: 分时只有一个来源时, 它一断就整块空白。把其它声明分时的实例登记为网络失败后的备源
|
|
218
|
+
// 已有备用源的不再追加: 自动切换是用户开关, 迁移既不替他打开, 也不改他已经配好的备用链
|
|
219
|
+
if (route.fallbackInstanceIds.length) continue
|
|
220
|
+
const spare = control.providers.find(p => p.enabled !== false && p.id !== route.primaryInstanceId && capable(p, market))
|
|
221
|
+
if (spare) spares.push({ id: route.id, fallback: spare.id })
|
|
222
|
+
}
|
|
223
|
+
// 一条也补不出来且当前没有任何分时路由, 说明只是「暂时没有可用分时源」: 不烧迁移标记,
|
|
224
|
+
// 之后装上声明分时的源还能自动补; 已有分时路由(或刚补出来)才算迁移完成, 用户删掉后不该复活
|
|
225
|
+
if (!missing.length && !spares.length && !control.routes.some(r => r.capability === 'trend')) return
|
|
226
|
+
const patch = route => {
|
|
227
|
+
const spare = spares.find(s => s.id === route.id)
|
|
228
|
+
return spare ? { ...route, fallbackInstanceIds: [...route.fallbackInstanceIds, spare.fallback], failoverMode: 'network' } : route
|
|
229
|
+
}
|
|
230
|
+
await state.mutate({ operationId: randomUUID(), expectedRevision: control.revision, action: 'trend-routes', payload: { added: missing.map(r => r.id), spared: spares.map(s => s.id) } }, current => ({ ...current, routeMigration: TREND_ROUTE_MIGRATION, routes: [...current.routes.map(patch), ...missing], routingRevision: missing.length || spares.length ? current.routingRevision + 1 : current.routingRevision }))
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// 分时离线兜底: 只续在当日真实分时后面。
|
|
234
|
+
// 没有真实分时打底时, 几个报价点连成的线说明不了走势, 不如把上游错误如实抛出去
|
|
235
|
+
async function offlineTrend({ market, code, limit, securityId }, error) {
|
|
236
|
+
const cached = await trendCache.get({ market, code, limit })
|
|
237
|
+
if (!cached) return null
|
|
238
|
+
const real = cached.payload.candles || []
|
|
239
|
+
const lastAt = Number(real.at(-1)?.at)
|
|
240
|
+
// 只补最后一根之后、且不在同一分钟的新报价: 早于它的已经在图里, 同一分钟的会画成重复的一根
|
|
241
|
+
const lastMinute = Math.floor(lastAt / 60)
|
|
242
|
+
const extra = Number.isFinite(lastAt) ? ticks.series(securityId, market).filter(point => point.at > lastAt && Math.floor(point.at / 60) > lastMinute) : []
|
|
243
|
+
const appended = extra.map(point => ({ time: clockInZone(TREND_SOURCE_TIME_ZONE, point.at), at: point.at, open: point.price, high: point.price, low: point.price, close: point.price }))
|
|
244
|
+
return {
|
|
245
|
+
...cached.payload,
|
|
246
|
+
...(appended.length ? { complete: false } : {}),
|
|
247
|
+
// 拍点只有收盘价: 开高低补齐成同一个值, 否则客户端按 OHLC 校验会把每根都丢掉, 图上仍然是空的
|
|
248
|
+
candles: [...real, ...appended],
|
|
249
|
+
offline: { kind: 'cache', cachedAt: cached.cachedAt, appended: appended.length, reason: error.message },
|
|
250
|
+
}
|
|
156
251
|
}
|
|
157
252
|
|
|
158
253
|
return {
|
|
@@ -184,17 +279,29 @@ export async function createApplication({ storageDomain, providers = [tushare, t
|
|
|
184
279
|
let exchange, code
|
|
185
280
|
try { ({ exchange, code } = parseSecurityId(sid)) } catch { fail('INVALID_PARAM', '证券身份无效', 400) }
|
|
186
281
|
const config = state.get()
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
282
|
+
// 分时与日/周/月是两种上游, 各走各的路由: K 线来源不供分时时, 分时不该跟着一起死
|
|
283
|
+
const capability = period === 'trend' ? 'trend' : 'kline'
|
|
284
|
+
const { route, instance } = selectRoute(capability, exchange)
|
|
285
|
+
// 同轮补救只取环上的下一格: 走到末级时回到主源, 否则末级是死胡同
|
|
286
|
+
const next = router.nextInRing(route.id, instance.id)
|
|
287
|
+
const fallbacks = next ? config.providers.filter(p => p.id === next && p.enabled !== false && p.budget?.requestsPerMinute !== null) : []
|
|
288
|
+
// force=1 跳过缓存读(详情页手动刷新);分时每次真取, 缓存只在上游失败时用
|
|
289
|
+
if (capability === 'kline' && force !== '1') {
|
|
290
|
+
for (const cand of [instance, ...fallbacks.filter(spare => spare.id !== instance.id)]) {
|
|
291
|
+
const cached = await klineCache.get({ providerInstanceId: cand.id, market: exchange, period, code, limit }, config.routingRevision)
|
|
193
292
|
if (cached) return { ...cached.payload, source: cand.id, revision: config.revision }
|
|
194
293
|
}
|
|
195
294
|
}
|
|
196
|
-
const result = await runWithFailover(route, instance, fallbacks, { securityId: sid, market: exchange, code, period, adjust: 'qfq', limit }, signal)
|
|
197
|
-
|
|
295
|
+
const result = await runWithFailover(capability, route, instance, fallbacks, { securityId: sid, market: exchange, code, period, adjust: 'qfq', limit }, signal).catch(async error => {
|
|
296
|
+
// 分时没有别的来源可退: 有当日真实分时就拿它兜底并续上之后的报价点, 没有就如实报错
|
|
297
|
+
if (capability !== 'trend') throw error
|
|
298
|
+
const offline = await offlineTrend({ market: exchange, code, limit, securityId: sid }, error)
|
|
299
|
+
if (!offline) throw error
|
|
300
|
+
return offline
|
|
301
|
+
})
|
|
302
|
+
if (capability === 'kline') await klineCache.put({ providerInstanceId: result.providerInstanceId, market: exchange, period, code, limit }, result, config.routingRevision)
|
|
303
|
+
// 成功一次就覆盖当日缓存: 离线时它就是"最后一个完整的分时"; 兜底结果与空结果由缓存自己挡掉
|
|
304
|
+
else await trendCache.put({ market: exchange, code, limit }, result)
|
|
198
305
|
return { ...result, source: result.providerInstanceId, revision: config.revision }
|
|
199
306
|
},
|
|
200
307
|
async browse(input) {
|
|
@@ -205,12 +312,14 @@ export async function createApplication({ storageDomain, providers = [tushare, t
|
|
|
205
312
|
const index = INDEX[input.market]
|
|
206
313
|
// 概览指数是装饰性数据: 无路由或拉取失败(含5s短超时不与目录翻页争槽)都静默为 null, 不阻断目录浏览
|
|
207
314
|
let overview = null
|
|
315
|
+
// 概览时段与采集同源: 都走 catalog.marketState(日历 + 市场本地时段), 不用来源字段猜
|
|
316
|
+
const phase = catalog.marketState(input.market)
|
|
208
317
|
try {
|
|
209
318
|
const route = router.select('quotes', input.market)
|
|
210
319
|
if (route.instance) {
|
|
211
320
|
const result = await executor.run(route.instance, 'quotes', { securities: [{ id: index.id, exchange: index.exchange, code: index.code }], routingRevision: state.get().routingRevision }, { signal: AbortSignal.timeout(5 * 1000) })
|
|
212
321
|
const quote = result.items?.find(q => q.securityId === index.id)
|
|
213
|
-
if (quote && quote.last !== null) { deriveDelay(quote, now,
|
|
322
|
+
if (quote && quote.last !== null) { deriveDelay(quote, now, ['trading', 'auction', 'unknown'].includes(phase.state)); overview = { name: index.name, last: quote.last, change: quote.change, changePct: quote.changePct, quoteAt: quote.quoteAt, delayKind: quote.delayKind, delaySeconds: quote.delaySeconds, sessionState: phase.state, source: quote.providerInstanceId } }
|
|
214
323
|
}
|
|
215
324
|
} catch {}
|
|
216
325
|
return { ...await catalog.browse(input), overview, catalogs: catalog.status(), routingRevision: state.get().routingRevision }
|
|
@@ -218,19 +327,30 @@ export async function createApplication({ storageDomain, providers = [tushare, t
|
|
|
218
327
|
async sync(input) {
|
|
219
328
|
assertLive()
|
|
220
329
|
if (!MARKET_META[input.market] || input.expectedRoutingRevision !== state.get().routingRevision) fail('ROUTE_CONFLICT', '目录路由已变化', 409)
|
|
221
|
-
|
|
330
|
+
// 只同步该市场真实配置的能力: 默认参数同时要目录+日历, 没配日历时每次手动同步都必然回一条 NO_ROUTE 错误
|
|
331
|
+
const capabilities = ['catalog', 'calendar'].filter(capability => state.get().routes.some(route => route.capability === capability && route.market === input.market))
|
|
332
|
+
if (!capabilities.length) fail('NO_ROUTE', '该市场未配置目录或日历来源', 422)
|
|
333
|
+
const result = await catalog.sync(input.market, capabilities); collector.reconcile(); return result
|
|
334
|
+
},
|
|
335
|
+
async watchlist(operation) {
|
|
336
|
+
assertLive()
|
|
337
|
+
const result = await watchlist.execute(operation)
|
|
338
|
+
// 移除后立即丢弃该标的行情; 否则已删自选的旧报价仍留在 /snapshot 并无限累积
|
|
339
|
+
if (operation.action === 'remove' && operation.payload?.securityId) collector.prune(operation.payload.securityId)
|
|
340
|
+
collector.reconcile(); return result
|
|
222
341
|
},
|
|
223
|
-
async watchlist(operation) { assertLive(); const result = await watchlist.execute(operation); collector.reconcile(); return result },
|
|
224
342
|
// 密钥只写宿主的凭据存储, 不回显也不落插件状态;引用必须已被某个数据源声明, 插件不越界写别人的密钥空间。
|
|
225
343
|
async credential(input) {
|
|
226
344
|
assertLive()
|
|
227
345
|
if (!credentialStore) fail('UNSUPPORTED', '宿主未提供凭据服务', 501)
|
|
228
346
|
const ref = z.string().regex(/^[A-Z][A-Z0-9_]{0,63}$/).parse(input.ref)
|
|
229
|
-
if (!state.get().providers.some(p => p.credentialRef === ref)) fail('INVALID_REQUEST', '该凭据未被任何数据源使用', 422)
|
|
347
|
+
if (!state.get().providers.some(p => p.credentialRef === ref || p.proxyCredentialRef === ref)) fail('INVALID_REQUEST', '该凭据未被任何数据源使用', 422)
|
|
230
348
|
const value = input.value === null ? null : z.string().min(1).max(512).parse(input.value)
|
|
231
349
|
if (value === null) await credentialStore.unset(ref)
|
|
232
350
|
else await credentialStore.set(ref, value)
|
|
233
351
|
await refreshCredentialPresence()
|
|
352
|
+
// 填入正确密钥后立即解除引用该凭据实例的 AUTH 永久暂停, 不必再点一次"检查所有来源"
|
|
353
|
+
collector.recoverCredential(ref)
|
|
234
354
|
return { ref, present: value !== null }
|
|
235
355
|
},
|
|
236
356
|
async preferences(operation) {
|
|
@@ -246,9 +366,21 @@ export async function createApplication({ storageDomain, providers = [tushare, t
|
|
|
246
366
|
async refresh(input = {}, signal) {
|
|
247
367
|
assertLive()
|
|
248
368
|
if (input.expectedRoutingRevision !== undefined && input.expectedRoutingRevision !== state.get().routingRevision) fail('ROUTE_CONFLICT', '路由配置已变化', 409)
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
369
|
+
const submitted = input.securities === undefined ? undefined : refreshSecuritiesSchema.safeParse(input.securities)
|
|
370
|
+
if (submitted && !submitted.success) {
|
|
371
|
+
const [first] = submitted.error.issues, path = first.path.length ? first.path.join('.') : '根'
|
|
372
|
+
fail('INVALID_REFRESH', `刷新证券参数无效:${path} ${first.message}`, 400)
|
|
373
|
+
}
|
|
374
|
+
let quotes
|
|
375
|
+
try { quotes = await collector.refresh(submitted?.data, { signal }) } catch (e) {
|
|
376
|
+
// peek 刷新失败时 collector 里还留着带 lastError 的条目(否则详情只剩"等待报价");
|
|
377
|
+
// 常驻快照按自选过滤会顺手删掉它, 这里在快照构造前抓一份只随本次错误下发的报价。
|
|
378
|
+
const failed = collector.entries()
|
|
379
|
+
e.snapshot = { ...snapshot(), quotes: failed }
|
|
380
|
+
throw e
|
|
381
|
+
}
|
|
382
|
+
// peek 报价只随本次响应下发, 不进常驻快照: 详情关闭后服务端不再保留任何非自选报价
|
|
383
|
+
return { ...snapshot(), quotes }
|
|
252
384
|
},
|
|
253
385
|
async routeSelection(input, signal) {
|
|
254
386
|
assertLive()
|
|
@@ -256,11 +388,13 @@ export async function createApplication({ storageDomain, providers = [tushare, t
|
|
|
256
388
|
if (!route || input.target !== 'primary' || input.expectedRoutingRevision !== config.routingRevision) fail('ROUTE_CONFLICT', '路由配置已变化', 409)
|
|
257
389
|
const instance = config.providers.find(p => p.id === route.primaryInstanceId)
|
|
258
390
|
const selected = router.selections()[route.id]
|
|
259
|
-
if (selected.routeEpoch !== input.expectedRouteEpoch
|
|
260
|
-
|
|
391
|
+
if (selected.routeEpoch !== input.expectedRouteEpoch) fail('ROUTE_CONFLICT', '来源已变化', 409)
|
|
392
|
+
registry.validate(instance, route)
|
|
393
|
+
// 探针按这条路由自身的能力: 用 quotes 探针验 K 线路由会在来源缺报价时误判, 也没验到要切过去的能力
|
|
394
|
+
const checked = await executor.run(instance, route.capability, { capability: route.capability, market: route.market, instrument: route.instrument }, { probe: true, signal })
|
|
261
395
|
if (checked.status !== 'ready' || config.routingRevision !== state.get().routingRevision) fail('CHECK_REQUIRED', '主源未就绪或路由已变化', 422)
|
|
262
396
|
router.switchPrimary(route.id, input.expectedRouteEpoch); return snapshot()
|
|
263
397
|
},
|
|
264
|
-
async close() { stopped = true; demand.dispose(); collector.dispose(); const cacheClosed = catalog.dispose();
|
|
398
|
+
async close() { stopped = true; recoveryLoop?.stop(); executor.dispose(); await recoveryLoop?.idle?.(); demand.dispose(); collector.dispose(); const cacheClosed = catalog.dispose(); await cacheClosed; await ensuring; await state.close() },
|
|
265
399
|
}
|
|
266
400
|
}
|
package/src/catalog.mjs
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import { securitySchema } from './schemas.mjs'
|
|
2
|
-
import { fail,
|
|
2
|
+
import { fail, marketDate, marketStateOf } from './market-model.mjs'
|
|
3
3
|
const DAY = 24 * 60 * 60 * 1000
|
|
4
4
|
const SEARCH_TTL = 60 * 1000
|
|
5
5
|
const SEARCH_CACHE_LIMIT = 64
|
|
6
6
|
const SEARCH_FLIGHT_LIMIT = 32
|
|
7
7
|
const CANDIDATE_TTL = 5 * 60 * 1000
|
|
8
8
|
const CANDIDATE_LIMIT = 200
|
|
9
|
+
// 同步失败后自动重试的间隔: 失败原因(缺路由/来源不可达)不会在一秒内自愈, 每次浏览都重试等于打上游;
|
|
10
|
+
// 用户仍可从设置页或浏览页手动重试
|
|
11
|
+
const AUTO_SYNC_RETRY_MS = 30 * 1000
|
|
12
|
+
const SYNC_ATTEMPT_LIMIT = 64
|
|
13
|
+
// 目录一天、日历一周过期: 过期数据仍可展示, 但浏览/后台预热要重新同步, 不能一直吃旧快照
|
|
14
|
+
const CATALOG_TTL = DAY, CALENDAR_TTL = 7 * DAY
|
|
15
|
+
// 市场状态只随分钟粒度的时段边界变化; 5 秒短缓存挡掉采集热路径的重复全量扫描
|
|
16
|
+
const MARKET_STATE_TTL = 5 * 1000
|
|
17
|
+
const MARKET_STATE_CACHE_LIMIT = 64
|
|
9
18
|
// 有界写入: Map 迭代序即插入序, 超限淘汰最早条目, 保证长跑内存不随查询次数增长
|
|
10
19
|
export function setBounded(map, key, value, limit) {
|
|
11
20
|
map.set(key, value)
|
|
12
21
|
while (map.size > limit) map.delete(map.keys().next().value)
|
|
13
22
|
return map
|
|
14
23
|
}
|
|
15
|
-
const localDate = ms => new Date(ms + 8 * 60 * 60 * 1000).toISOString().slice(0, 10)
|
|
16
24
|
// 实例id→其适配器 markets 集合(搜索市场面唯一事实源)
|
|
17
25
|
function adapterMarketsOf(config, registry) {
|
|
18
26
|
const map = new Map()
|
|
@@ -23,8 +31,9 @@ function adapterMarketsOf(config, registry) {
|
|
|
23
31
|
return map
|
|
24
32
|
}
|
|
25
33
|
|
|
34
|
+
const shiftDate = (date, days) => new Date(Date.parse(`${date}T00:00:00Z`) + days * DAY).toISOString().slice(0, 10)
|
|
26
35
|
export function createCatalog({ state, getControl = state.get, router, executor, registry, now = Date.now, changed = () => {} }) {
|
|
27
|
-
const flights = new Map(), candidates = new Map(), searchCache = new Map(), searchFlights = new Map()
|
|
36
|
+
const flights = new Map(), candidates = new Map(), searchCache = new Map(), searchFlights = new Map(), marketStateCache = new Map(), syncAttempts = new Map()
|
|
28
37
|
let stopped = false
|
|
29
38
|
const controllers = new Set()
|
|
30
39
|
function records(kind) {
|
|
@@ -51,11 +60,21 @@ export function createCatalog({ state, getControl = state.get, router, executor,
|
|
|
51
60
|
return {
|
|
52
61
|
search,
|
|
53
62
|
async browse({ market, offset, limit }) {
|
|
54
|
-
// 缓存缺失不再报错甩给用户: 返回 syncing 态并触发后台同步(sync 内部 flights 去重),
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
// 缓存缺失不再报错甩给用户: 返回 syncing 态并触发后台同步(sync 内部 flights 去重), 同步后为空是合法状态。
|
|
64
|
+
// 失败要带出口: 只回 syncing 会让"首次同步中"永远挂着, 用户既不知道失败也没有重试入口。
|
|
65
|
+
const cached = records('catalog').filter(c => c.payload.market === market)
|
|
66
|
+
if (!cached.length) {
|
|
67
|
+
const revision = getControl().routingRevision
|
|
68
|
+
const attempt = syncAttempts.get(`catalog:${market}`)
|
|
69
|
+
// 只认当前路由版本下的失败: 换过路由还回旧版本的错误, 会把已经修好的市场显示成失败
|
|
70
|
+
const failed = attempt?.ok === false && attempt.revision === revision
|
|
71
|
+
const due = !failed || now() - attempt.at >= AUTO_SYNC_RETRY_MS
|
|
72
|
+
if (due) this.sync(market, ['catalog']).catch(() => {})
|
|
73
|
+
return { syncing: true, syncError: failed ? attempt.error : null, syncAttemptAt: failed ? attempt.at : null, total: 0, items: [] }
|
|
58
74
|
}
|
|
75
|
+
// 已有目录但过期: 先展示旧数据, 同时后台刷新, 下一次浏览/轮询就能拿到新目录
|
|
76
|
+
const newest = Math.max(...cached.map(c => c.fetchedAt))
|
|
77
|
+
if (now() - newest > CATALOG_TTL) this.sync(market, ['catalog']).catch(() => {})
|
|
59
78
|
const securities = all().filter(s => s.exchange === market).sort((a, b) => a.code.localeCompare(b.code))
|
|
60
79
|
const start = Math.max(0, Math.trunc(Number(offset) || 0)), size = Math.min(200, Math.max(1, Math.trunc(Number(limit) || 50)))
|
|
61
80
|
return { total: securities.length, items: securities.slice(start, start + size) }
|
|
@@ -66,7 +85,7 @@ export function createCatalog({ state, getControl = state.get, router, executor,
|
|
|
66
85
|
const candidate = candidates.get(id)
|
|
67
86
|
return candidate && candidate.until > now() && candidate.revision === getControl().routingRevision ? candidate.security : null
|
|
68
87
|
},
|
|
69
|
-
status: () => records('catalog').map(c => ({ source: c.source, fetchedAt: c.fetchedAt, complete: c.payload.complete, stale: now() - c.fetchedAt > (c.kind === 'calendar' ?
|
|
88
|
+
status: () => records('catalog').map(c => ({ source: c.source, fetchedAt: c.fetchedAt, complete: c.payload.complete, stale: now() - c.fetchedAt > (c.kind === 'calendar' ? CALENDAR_TTL : CATALOG_TTL) })),
|
|
70
89
|
async remote(q, signal) {
|
|
71
90
|
const config = structuredClone(getControl()), revision = config.routingRevision, key = `${revision}:${q.trim().toLowerCase()}`
|
|
72
91
|
// 结果缓存与在途合并: 联想接口按查询词去重, 退格重输同一词零远端开销
|
|
@@ -114,14 +133,15 @@ export function createCatalog({ state, getControl = state.get, router, executor,
|
|
|
114
133
|
try { return await job } finally { if (searchFlights.get(key)?.job === job) searchFlights.delete(key) }
|
|
115
134
|
},
|
|
116
135
|
// 内存占用可观测: 长跑核对缓存不越界
|
|
117
|
-
stats: () => ({ searchCache: searchCache.size, candidates: candidates.size, searchFlights: searchFlights.size, syncFlights: flights.size }),
|
|
136
|
+
stats: () => ({ searchCache: searchCache.size, candidates: candidates.size, searchFlights: searchFlights.size, syncFlights: flights.size, syncAttempts: syncAttempts.size }),
|
|
118
137
|
async ensure() {
|
|
119
138
|
for (const route of getControl().routes.filter(r => ['catalog', 'calendar'].includes(r.capability))) {
|
|
120
139
|
if (getControl().providers.find(p => p.id === route.primaryInstanceId)?.budget.requestsPerMinute === null) continue
|
|
121
140
|
const caches = records(route.capability).filter(c => c.payload.market === route.market)
|
|
122
141
|
const cache = caches[0]
|
|
123
|
-
const today =
|
|
124
|
-
const
|
|
142
|
+
const today = marketDate(route.market, now())
|
|
143
|
+
const ttl = route.capability === 'calendar' ? CALENDAR_TTL : CATALOG_TTL
|
|
144
|
+
const missing = !cache || now() - cache.fetchedAt > ttl || route.capability === 'calendar' && !cache.payload.items.some(day => day.date === today)
|
|
125
145
|
if (missing) await this.sync(route.market, [route.capability])
|
|
126
146
|
}
|
|
127
147
|
},
|
|
@@ -134,14 +154,20 @@ export function createCatalog({ state, getControl = state.get, router, executor,
|
|
|
134
154
|
for (const capability of capabilities) {
|
|
135
155
|
try {
|
|
136
156
|
const selected = router.select(capability, market)
|
|
137
|
-
const
|
|
157
|
+
const today = marketDate(market, now())
|
|
158
|
+
const request = { market, routingRevision: config.routingRevision, startDate: shiftDate(today, -7), endDate: shiftDate(today, 45) }
|
|
138
159
|
const batch = await executor.run(selected.instance, capability, request, { signal: controller.signal })
|
|
139
160
|
if (stopped || config.routingRevision !== getControl().routingRevision) fail('ROUTE_CONFLICT', '来源已变化,旧目录已丢弃', 409)
|
|
140
161
|
if (!Array.isArray(batch.items) || capability === 'catalog' && batch.items.some(s => !securitySchema.safeParse(s).success || s.exchange !== market) || capability === 'calendar' && batch.items.some(d => !/^\d{4}-\d{2}-\d{2}$/.test(d.date) || typeof d.isOpen !== 'boolean')) fail('BAD_PAYLOAD', '目录来源返回不受支持的证券身份', 502)
|
|
141
162
|
const items = batch.items
|
|
142
163
|
await state.cache.put(`${capability}:${selected.instance.id}:${market}`, { kind: capability, source: selected.instance.id, fetchedAt: now(), payload: { routingRevision: config.routingRevision, market, complete: batch.complete ?? true, items } })
|
|
164
|
+
if (capability === 'calendar') marketStateCache.clear()
|
|
165
|
+
setBounded(syncAttempts, `${capability}:${market}`, { ok: true, at: now(), revision: config.routingRevision }, SYNC_ATTEMPT_LIMIT)
|
|
143
166
|
status.push({ capability, ok: true, count: items.length }); changed()
|
|
144
|
-
} catch (e) {
|
|
167
|
+
} catch (e) {
|
|
168
|
+
setBounded(syncAttempts, `${capability}:${market}`, { ok: false, at: now(), revision: config.routingRevision, error: { code: e.code, message: e.message } }, SYNC_ATTEMPT_LIMIT)
|
|
169
|
+
status.push({ capability, ok: false, error: { code: e.code, message: e.message } })
|
|
170
|
+
}
|
|
145
171
|
}
|
|
146
172
|
return status
|
|
147
173
|
})()
|
|
@@ -150,18 +176,17 @@ export function createCatalog({ state, getControl = state.get, router, executor,
|
|
|
150
176
|
return job
|
|
151
177
|
},
|
|
152
178
|
marketState(market) {
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return { state: 'closed', nextAt: at(24 * 60 + 9 * 60 + 15) }
|
|
179
|
+
const at = now(), date = marketDate(market, at), revision = getControl().routingRevision
|
|
180
|
+
const key = `${market}:${date}:${revision}`
|
|
181
|
+
const cached = marketStateCache.get(key)
|
|
182
|
+
if (cached && at - cached.at < MARKET_STATE_TTL) return { ...cached.value }
|
|
183
|
+
// 没同步过日历就按市场自身时段判断(仍给 nextAt, 休市不再按秒轮询); 有日历时以日历(含节假日)为准
|
|
184
|
+
const days = new Map()
|
|
185
|
+
for (const cache of records('calendar')) if (cache.payload.market === market) for (const day of cache.payload.items) days.set(day.date, day.isOpen)
|
|
186
|
+
const value = marketStateOf(market, at, days)
|
|
187
|
+
marketStateCache.set(key, { at, value })
|
|
188
|
+
while (marketStateCache.size > MARKET_STATE_CACHE_LIMIT) marketStateCache.delete(marketStateCache.keys().next().value)
|
|
189
|
+
return { ...value }
|
|
165
190
|
},
|
|
166
191
|
async dispose() { stopped = true; for (const c of controllers) c.abort(); candidates.clear(); await Promise.allSettled([...flights.values()]) },
|
|
167
192
|
}
|