@ asterql/ 仓库
npm install @asterql/store
AsterQL 的规范化实体存储、 范围光标和查看缓存
状态同步 。 这是客户端协议B的底物: 它摄入
ServerEventEnvelope从 @asterql/view-protocol 并保持一个确认
复制每个实体,同时执行 A 协议的查看缓存
停止资格政策,而不是取消资格.
心理模型(参见状态同步架构 doc):服务器拥有真理 和秩序; 客户拥有时间和意图; 观点拥有什么.
API 密码
国家基数 :
ScopeCursors: 单声道入镜序列光标-beginScope(scope, lastSeq), (中文(简体) ),scopeLastSeq(scope),以及ingestSequenced(envelope, apply)返回时applied, (中文(简体) ),duplicate,或gap。光标即使在apply投出( 信封是 重置光标总是清晰的 所以 stale快照永远无法回溯到它已经应用过的序列中.CoalescedEmitter<TTopic>: 微任务组合变化通知 全球、按专题和按键听众。 一个内的任何标记数 任务冲洗作为每个听众的单一通知.EntityStore: 实现正常化EntityRecord映射已按键kind:id时ingest(envelope)页:1patch, (中文(简体) ),snapshot,以及invalidate信封 类型。 应用补丁通过applyEntityPatches; 记录版本来 从信封或hashRecordVersion。 。 。 .subscribeEntity, (中文(简体) ),subscribeKind,以及subscribe准确通知.snapshotHash()产生犬科动物h1_用于跨地表差异检查的散列.ViewInstanceCache数字 :fresh | stale | loading | error键入条目viewId.paramsHash.authScopeHash。条目记录的类版本 其依赖性清单为双倍;invalidate(classes, classVersions?)标记 只有依赖的条目 stale, 并且只有当一个类实际升级.
示例
import { EntityStore, ViewInstanceCache } from "@asterql/store";
const store = new EntityStore();
store.cursors.beginScope("chat:abc", 0);
const { result, changedKeys, invalidated } = store.ingest({
eventId: "ev1_…",
kind: "patch",
scope: "chat:abc",
seq: 1,
entities: [
{
key: "message:m1",
patches: [{ op: "appendText", path: "/text", delta: "Hello" }],
},
],
});
if (result.kind === "gap") {
// fetch /scopes/chat:abc/events?afterSeq=result.lastSeq, then re-ingest;
// escalate to a snapshot replace when the retention window is exceeded.
}
const views = new ViewInstanceCache();
views.invalidate(invalidated, { "entityKind:message": Date.now() });
获取,运输,和乐观的突变 故意超出范围: 这个包是这些层共享的存储和固态政策.
结构共享
EntityStore.ingest 保存现有记录(相同的引用,相同)
如果更改产生一个等值记录,并报告否
变了的密钥——一个平等的快照使下游没有什么.