npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@x1a0f3n9/dsh-session-format

v0.1.5-rc.5

Published

Streaming adjacent Session format migration machinery

Downloads

1,198

Readme


description: "纯函数式相邻会话格式规划、无损 JSON 值检查、仅标头迁移与物理编解码分派。" kind: "package-library"

@x1a0f3n9/dsh-session-format

English | 中文

概述

dsh-session-format 让持久化代码可以直接还原当前会话,或在只消费一次物理行的同时组合唯一的相邻迁移序列。一次还原会让调用方拥有的已解析值流经有状态 Stage,不复制或冻结中间产物。物理分帧、压缩、不可变 generation 命名、排他发布和 Cordis 生命周期行为不属于本库。

目录


使用本包

何时使用

当持久化或格式目录代码需要分类物理会话 header、还原当前逻辑值或组合已发布相邻迁移时,使用本库。它不是 Cordis 插件,也没有 profile 挂载行。它不发布运行时不变式伴生入口,因为每个已完成操作都会校验结果;decoder 与 transformer 状态只属于一次尚未完成的流式还原,绝不在多次还原间共享。

入口

const catalog = createSessionFormatCatalog({ currentVersion, codecs, currentEncoder, migrations, restoreCurrent, restoreTransformedCurrent, restoreCurrentHeader })
const descriptor = catalog.readHeader(physicalHeader)
const restore = catalog.createRestore(physicalHeader, { recovery: 'recoverable', validation: 'transformed' })
for (const row of physicalRows) restore.decodeRow(row)
const current = restore.finish()
const headerRecord = catalog.encodeCurrentHeader(current.header, current.inheritedEventCount)
const eventRecords = current.events.map(catalog.encodeCurrentEvent)

createSessionFormatCatalog() 接收每个受支持版本的一个冻结 codec、当前格式的逐记录 encoder、每组相邻版本的一个迁移,以及当前产物与 header 还原器。readHeader() 在不读取事件的情况下返回 current、migration-required、unsupported 或 malformed 描述符。正文读取方创建一次 restore,把每个已解析物理行传给 decodeRow(),再调用一次 finish() 获得当前产物。写入方逐条编码其 header 与事件。

recovery 选项决定严格拒绝故障行,还是执行可恢复后缀处理。validation: 'current' 会执行所有已安装的 current 格式校验。validation: 'transformed' 会在历史迁移后执行已发布的 current 格式校验;已经是 current 的输入则只接受其 codec 的物理校验。

可恢复解码器返回已接受的逻辑前缀。编解码器可以丢弃一个格式错误或序号不连续的行及其未提交后缀,但后续成功解码的 turn/end 会使原始问题成为致命错误。


理解实现

迁移链在构造时校验唯一且无缺口的顺序。源切点可以在 EOF 前保持未知;依赖头部切点的 Stage 拒绝缺失值,而基于标记的 Stage 从已发出的事件推导切点。每个 Stage 在完成时返回精确的目标切点,且必须与预声明切点一致。Catalog 把一个行 decoder 与有状态的相邻事件 transformer 组合起来,只保留其有界状态与最终当前事件,并在 finish() 时执行目标校验;只有调用方决定是否发布该结果以及如何发布。

| 文件 | 职责 | |---|---| | src/chain.ts | 相邻计划构造与当前格式绕过 | | src/catalog.ts | 物理版本分派与标头分类 | | src/json.ts | 分离的无损 JSON 快照与通用坐标校验 | | src/filename.ts | 持久化、导出与 fixture(测试前置数据)共用的规范 session[.vN].jsonl 文件名 |


进一步探索


模型体验

会话还原

模型看到什么

没有直接内容。消费方通过 deriveMessages() 从经过校验的当前产物重建模型历史。

Token 影响

不直接产生 token。

KV Cache 影响

没有直接影响。迁移若改变当前历史,可能改变由请求重建逻辑拥有的缓存身份。

已知限制与延期工作

  • 最终当前历史仍常驻内存——流式处理只保留有界中间状态,但返回的当前事件数组和必需的序号重映射表仍为 O(事件数)。
  • 仅支持相邻整数版本——本库不暴露 span、稳定事件身份或通用引用重写代数。

开发备注

无。