@calcit/procs 0.12.1 → 0.12.2
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/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/build.rs
CHANGED
|
@@ -28,9 +28,15 @@ pub struct CodeEntry {
|
|
|
28
28
|
pub schema: Option<Edn>,
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
32
|
+
pub struct NsEntry {
|
|
33
|
+
pub doc: String,
|
|
34
|
+
pub code: Cirru,
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
32
38
|
pub struct FileInSnapShot {
|
|
33
|
-
pub ns:
|
|
39
|
+
pub ns: NsEntry,
|
|
34
40
|
pub defs: HashMap<String, CodeEntry>,
|
|
35
41
|
}
|
|
36
42
|
|
|
@@ -204,6 +210,31 @@ fn parse_code_entry(edn: Edn, owner: &str) -> Result<CodeEntry, String> {
|
|
|
204
210
|
})
|
|
205
211
|
}
|
|
206
212
|
|
|
213
|
+
fn parse_ns_entry(edn: Edn, owner: &str) -> Result<NsEntry, String> {
|
|
214
|
+
let record: EdnRecordView = match edn {
|
|
215
|
+
Edn::Record(r) => r,
|
|
216
|
+
other => {
|
|
217
|
+
return Err(format!(
|
|
218
|
+
"{owner}: expected NsEntry/CodeEntry record, got {}",
|
|
219
|
+
format_edn_preview(&other)
|
|
220
|
+
));
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
let mut doc = String::new();
|
|
224
|
+
let mut code: Option<Cirru> = None;
|
|
225
|
+
for (key, value) in &record.pairs {
|
|
226
|
+
match key.arc_str().as_ref() {
|
|
227
|
+
"doc" => doc = from_edn(value.clone()).map_err(|e| format!("{owner}: invalid `:doc`: {e}"))?,
|
|
228
|
+
"code" => code = Some(from_edn(value.clone()).map_err(|e| format!("{owner}: invalid `:code`: {e}"))?),
|
|
229
|
+
_ => {}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
Ok(NsEntry {
|
|
233
|
+
doc,
|
|
234
|
+
code: code.ok_or_else(|| format!("{owner}: missing `:code` field in NsEntry"))?,
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
|
|
207
238
|
fn parse_file_in_snapshot(edn: Edn, file_name: &str) -> Result<FileInSnapShot, String> {
|
|
208
239
|
let record: EdnRecordView = match edn {
|
|
209
240
|
Edn::Record(r) => r,
|
|
@@ -214,11 +245,11 @@ fn parse_file_in_snapshot(edn: Edn, file_name: &str) -> Result<FileInSnapShot, S
|
|
|
214
245
|
));
|
|
215
246
|
}
|
|
216
247
|
};
|
|
217
|
-
let mut ns: Option<
|
|
248
|
+
let mut ns: Option<NsEntry> = None;
|
|
218
249
|
let mut defs: HashMap<String, CodeEntry> = HashMap::new();
|
|
219
250
|
for (key, value) in &record.pairs {
|
|
220
251
|
match key.arc_str().as_ref() {
|
|
221
|
-
"ns" => ns = Some(
|
|
252
|
+
"ns" => ns = Some(parse_ns_entry(value.clone(), &format!("{file_name}/:ns"))?),
|
|
222
253
|
"defs" => {
|
|
223
254
|
let map = match value {
|
|
224
255
|
Edn::Map(m) => m,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# 2026-0310-1754 — snapshot namespace entry migrate to NsEntry
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
snapshot 里的 `:ns` 之前复用了 `CodeEntry` 结构,导致 namespace 也带着 `:schema` 和 `:examples` 字段,语义上并不合适,而且保存时经常只是写成 `(:schema nil)`。
|
|
6
|
+
|
|
7
|
+
这次改动把 namespace 入口单独收敛到 `NsEntry`,同时保持读取旧 `CodeEntry` 写法的兼容性。
|
|
8
|
+
|
|
9
|
+
## 核心改动
|
|
10
|
+
|
|
11
|
+
### `src/snapshot.rs`
|
|
12
|
+
|
|
13
|
+
- 新增 `NsEntry { doc, code }`
|
|
14
|
+
- `FileInSnapShot.ns` 从 `CodeEntry` 改为 `NsEntry`
|
|
15
|
+
- `RawFileInSnapShot.ns` 同步改为 `NsEntry`
|
|
16
|
+
- 新增 `TryFrom<Edn> for NsEntry` 与 `From<NsEntry> for Edn`
|
|
17
|
+
- 读取 snapshot 时,`ns` 只解析 `doc` 和 `code`,兼容旧 `CodeEntry` 形状并忽略 `schema/examples`
|
|
18
|
+
- 移除 `validate_snapshot_schemas_for_write` 对 `ns.schema` 的校验
|
|
19
|
+
- `gen_meta_ns`、`create_file_from_snippet` 等内部构造统一改为写 `NsEntry`
|
|
20
|
+
|
|
21
|
+
### `build.rs`
|
|
22
|
+
|
|
23
|
+
- 嵌入式 core snapshot 解析结构新增 `NsEntry`
|
|
24
|
+
- build 阶段读取 `src/cirru/calcit-core.cirru` 时,`ns` 不再解析为 `CodeEntry`
|
|
25
|
+
|
|
26
|
+
### `src/detailed_snapshot.rs`
|
|
27
|
+
|
|
28
|
+
- 新增 `DetailedNsEntry { doc, code }`
|
|
29
|
+
- `DetailedFileInSnapshot.ns` 从 `DetailedCodeEntry` 改为 `DetailedNsEntry`
|
|
30
|
+
- 详细快照读取仍兼容旧 namespace record,只提取 `doc` 和 `code`
|
|
31
|
+
|
|
32
|
+
### `src/bin/cr_sync.rs`
|
|
33
|
+
|
|
34
|
+
- namespace change payload 从 `CodeEntry` 拆成 `SnapshotEntry::Ns(NsEntry)`
|
|
35
|
+
- definition change payload 保持 `SnapshotEntry::Def(CodeEntry)`
|
|
36
|
+
- detailed snapshot 写回时,namespace 统一序列化为 `NsEntry`
|
|
37
|
+
|
|
38
|
+
### `src/bin/cli_handlers/edit.rs`
|
|
39
|
+
|
|
40
|
+
- `edit add-ns` 创建新 namespace 时直接写入 `NsEntry`
|
|
41
|
+
|
|
42
|
+
## 数据文件迁移
|
|
43
|
+
|
|
44
|
+
- 批量运行 `cr edit format`,将 compact snapshot 中旧的 `:ns $ %{} :CodeEntry ... (:schema nil) :examples []` 收敛为 `:NsEntry`
|
|
45
|
+
- 运行 `cr-sync` 重写 detailed snapshot:
|
|
46
|
+
- `demos/calcit.cirru`
|
|
47
|
+
- `calcit/editor/calcit.cirru`
|
|
48
|
+
- `src/cirru/calcit-core.cirru` 也已更新为 `NsEntry`
|
|
49
|
+
|
|
50
|
+
## 兼容策略
|
|
51
|
+
|
|
52
|
+
1. **读取兼容**:旧 snapshot/detailed snapshot 中 `ns` 仍然可以是 `CodeEntry` record
|
|
53
|
+
2. **内存收敛**:加载后统一存成 `NsEntry`
|
|
54
|
+
3. **保存统一**:以后重新保存或 format 都写回 `NsEntry`
|
|
55
|
+
|
|
56
|
+
## 验证
|
|
57
|
+
|
|
58
|
+
- `cargo fmt` ✅
|
|
59
|
+
- `cargo clippy -- -D warnings` ✅
|
|
60
|
+
- `cargo test` ✅
|
|
61
|
+
- `yarn check-all` ✅
|
|
62
|
+
|
|
63
|
+
## 备注
|
|
64
|
+
|
|
65
|
+
- `demos/compact.tmp.cirru` 不是合法 snapshot,`cr edit format` 会报 EDN 解析错误,因此未纳入统一格式化
|
|
66
|
+
- `demos/deps.cirru` 不是当前 snapshot loader 支持的结构,因此同样未走 `edit format`
|
package/lib/package.json
CHANGED