接入一个 provider
用 provideVenue(s) 注册一份 venue manifest,并跑通第一条数据面。

目标
让核心认识一个新 venue:它有 id、双语显示名、市场,以及至少一个切面。跑通后 /dsh-invest/health 的 invest.venues 会多 1。
要改哪些文件
新建一个 integrations/dsh-invest-provider-<name>/ 包:
src/index.ts apply:ctx.effect(() => ctx.invest.provideVenues([...]))
src/shared/manifest.ts 一份或多份 VenueManifest
src/shared/descriptor.ts id / label / origin 等字面量只留一份
package.json main 指向 lib/index.js,dsh.bundle.patch 指向 cordis.patch.yml
cordis.patch.yml insert 一行,id/name 都是包名
tsconfig.json paths 把 dsh-invest 指到核心源码,供 typecheck
tests/conformance.spec.ts describeVenue(manifest) 的一致性用例
provider 只 import type 核心;唯一的 value 例外是 dsh-invest/identity(marketKey / executorIdOf)。
契约
import type { InvestHostCtx, VenueManifest } from 'dsh-invest';
const demo: VenueManifest = {
id: 'demo',
display: { zh: '演示源', en: 'Demo feed' },
markets: [],
facets: {
detail: {
caps: { sections: ['profile'] },
accepts: ({ venue, symbol }) => venue === 'demo' && symbol !== '',
async profile(_query, ports) {
return {
ok: true,
data: { title: '演示标的', sections: [
{ id: 'basic', title: '基本', kind: 'facts', facts: [{ label: '来源', value: 'demo' }] },
] },
asOf: ports.now(),
};
},
},
},
};
export function apply(ctx: InvestHostCtx): void {
ctx.effect(() => ctx.invest.provideVenues([{ ...demo, plugin: 'dsh-invest-provider-demo' }]), 'demo:venues');
}
要点:
provideVenues整批成功或整批失败,返回 disposer。单条用provideVenue,它返回的句柄还能replace()。markets为空只允许 detail-only 源;带市场轴的切面必须声明markets。marketKey不得重复;display必须双语非空;未知切面名会被拒绝。- 注册期校验在
packages/dsh-invest/src/shared/invest/validation.ts,错误码是invalid-manifest/capability-conflict/unsupported-feature。 - 字段表见 VenueManifest 字段。
失败与重试
注册失败是作者错误,不要静默吞掉。可选做法是包一层 try/catch,记一条可检索的日志并让这个源缺席,避免炸掉宿主启动链:
const logger = (ctx as { logger?: (name: string) => { warn?: (message: string) => void } })
.logger?.('dsh-invest-provider-demo');
ctx.effect(() => {
try {
return ctx.invest.provideVenues(manifests());
} catch (error) {
logger?.warn?.(`注册失败,源缺席:${String(error)}`);
return undefined;
}
}, 'demo:venues');
provideVenues 内部已经做了回滚:任何一条挂载失败,本批已挂的湖/执行器/适配器都会撤掉,不会留下半注册。不要自己再补一次注册。
验证
pnpm --filter dsh-invest-provider-demo run build
pnpm --filter dsh-invest-provider-demo exec vitest run tests/conformance.spec.ts
预期:lib/index.js 生成;vitest 输出 Test Files 1 passed,用例为 describeVenue 逐条检查的名字。
装进 profile 后重启,读健康检查:
curl -s http://127.0.0.1:<port>/dsh-invest/health | jq '.invest.venues'
预期比安装前多 1;jq '.invest.facets.detail' 也应增加。