@tansr/protocol 0.2.0 → 0.3.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/README.md +1 -0
- package/dist/canonical/encode.js +81 -55
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/persistence-custody.d.ts +13 -0
- package/dist/persistence-custody.generated.d.ts +568 -0
- package/dist/persistence-custody.generated.js +8 -0
- package/dist/persistence-custody.js +28 -0
- package/dist/storage.d.ts +1047 -5
- package/dist/storage.js +69 -3
- package/package.json +1 -1
package/dist/storage.js
CHANGED
|
@@ -19,8 +19,10 @@
|
|
|
19
19
|
* 同词);冷清单由热清单派生时字段直接搬运,开发者不见两套清单词汇。
|
|
20
20
|
*/
|
|
21
21
|
import { z } from 'zod';
|
|
22
|
-
/**
|
|
23
|
-
export const STORAGE_FORMAT_VERSION =
|
|
22
|
+
/** 共同冷清单入口支持的最高格式;不是旧布局写入器的缺省版本。 */
|
|
23
|
+
export const STORAGE_FORMAT_VERSION = 5;
|
|
24
|
+
/** 原 SegmentManifest 读写合同的最高格式;1—4 的含义保持不变。 */
|
|
25
|
+
export const LEGACY_STORAGE_FORMAT_VERSION = 4;
|
|
24
26
|
/** 段编解码词表:jsonl 明文 / gzip(node:zlib 恒可用,缺省)/ zstd(Node ≥ 22.15 可选) */
|
|
25
27
|
export const SEGMENT_CODECS = ['jsonl', 'jsonl+gzip', 'jsonl+zstd'];
|
|
26
28
|
export const SegmentCodecSchema = z.enum(SEGMENT_CODECS);
|
|
@@ -77,7 +79,8 @@ export const AttachmentEntrySchema = z.object({
|
|
|
77
79
|
/** 清单 = 提交点(一卷一份;整体重写;CAS) */
|
|
78
80
|
export const SegmentManifestSchema = z
|
|
79
81
|
.object({
|
|
80
|
-
|
|
82
|
+
/** INIT:3 对应 indexed-journal-v1,4 对应有界页 v2;旧版语义保留,未知版本入口拒绝。 */
|
|
83
|
+
formatVersion: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(LEGACY_STORAGE_FORMAT_VERSION)]),
|
|
81
84
|
sessionId: z.string().min(1),
|
|
82
85
|
/** sha256(endUserId) 前 16 hex(doc/98 §九);sdk 单租户形态 'local' */
|
|
83
86
|
endUserKey: z.string().min(1),
|
|
@@ -108,3 +111,66 @@ export const SegmentManifestSchema = z
|
|
|
108
111
|
.optional(),
|
|
109
112
|
})
|
|
110
113
|
.passthrough();
|
|
114
|
+
/**
|
|
115
|
+
* STO-01 已会签格式 5:文件日志冷归档的独立提交点。
|
|
116
|
+
* 原 storage 提交链与原 JournalRecord 链分别登记,不复用旧 segments 单链。
|
|
117
|
+
* schema 只约束形状;消费端仍须校验完整 scope、同一提交、对象哈希与来源预算。
|
|
118
|
+
* storageIdentity / 原件中的 owner、lease 不能授予新的业务写资格。
|
|
119
|
+
*/
|
|
120
|
+
export const SessionLogFileManifestSchema = z.object({
|
|
121
|
+
formatVersion: z.literal(5),
|
|
122
|
+
layout: z.literal('session-log-file-v2'),
|
|
123
|
+
sessionId: z.string().min(1),
|
|
124
|
+
endUserKey: z.string().min(1),
|
|
125
|
+
volumeId: z.string().min(1),
|
|
126
|
+
generation: z.number().int().min(0).safe(),
|
|
127
|
+
updatedAt: z.string(),
|
|
128
|
+
expiresAt: z.string().optional(),
|
|
129
|
+
storageIdentity: z.object({
|
|
130
|
+
storageId: z.string().min(1),
|
|
131
|
+
generation: z.string().min(1),
|
|
132
|
+
}),
|
|
133
|
+
scopeKey: Sha256Hex,
|
|
134
|
+
commit: z.object({
|
|
135
|
+
revision: z.number().int().min(0).safe(),
|
|
136
|
+
lastSeq: z.number().int().min(0).safe(),
|
|
137
|
+
logDigest: Sha256Hex,
|
|
138
|
+
contextHead: z.number().int().min(0).safe(),
|
|
139
|
+
}),
|
|
140
|
+
resumeHead: z.object({
|
|
141
|
+
key: z.string().min(1),
|
|
142
|
+
bytes: z.number().int().min(1).safe(),
|
|
143
|
+
sha256: Sha256Hex,
|
|
144
|
+
headerBytes: z.number().int().min(1).safe(),
|
|
145
|
+
headerSha256: Sha256Hex,
|
|
146
|
+
}),
|
|
147
|
+
materialCatalog: z.object({
|
|
148
|
+
key: z.string().min(1),
|
|
149
|
+
bytes: z.number().int().min(1).safe(),
|
|
150
|
+
sha256: Sha256Hex,
|
|
151
|
+
/** 所列物理材料的总量;不递归包含目录根自身,实际目录 I/O 仍计操作预算。 */
|
|
152
|
+
objects: z.number().int().min(0).safe(),
|
|
153
|
+
totalBytes: z.number().int().min(0).safe(),
|
|
154
|
+
}),
|
|
155
|
+
originalJournal: z.object({
|
|
156
|
+
lastSeq: z.number().int().min(0).safe(),
|
|
157
|
+
lastEventId: z.string().min(1),
|
|
158
|
+
lastHash: Sha256Hex,
|
|
159
|
+
}).optional(),
|
|
160
|
+
sessionMeta: z.object({
|
|
161
|
+
createdAt: z.string().optional(),
|
|
162
|
+
title: z.string().optional(),
|
|
163
|
+
platformSessionId: z.string().optional(),
|
|
164
|
+
indexedJournalLayout: z.never().optional(),
|
|
165
|
+
}).passthrough().optional(),
|
|
166
|
+
// 显式拒绝新旧布局混合;未知描述字段仍可前向透传。
|
|
167
|
+
segments: z.never().optional(),
|
|
168
|
+
checkpoints: z.never().optional(),
|
|
169
|
+
attachments: z.never().optional(),
|
|
170
|
+
indexedJournalLayout: z.never().optional(),
|
|
171
|
+
}).passthrough();
|
|
172
|
+
/** 新共同入口按判别版本消费;旧 SegmentManifest 方法不因此接受格式 5。 */
|
|
173
|
+
export const ColdStorageManifestSchema = z.union([
|
|
174
|
+
SegmentManifestSchema,
|
|
175
|
+
SessionLogFileManifestSchema,
|
|
176
|
+
]);
|