@calcit/procs 0.12.0 → 0.12.1

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.
Binary file
@@ -0,0 +1,42 @@
1
+ # cr edit schema: support primitive type tag leaves
2
+
3
+ ## 背景
4
+
5
+ `cr edit schema` 原来只接受 `:: :fn $ {}` 这样的函数 schema 或 `{}` map 形式。
6
+ 有些定义的类型本身就是简单原始类型(如 `:string`、`:number`),不是函数,需要直接用 tag 表达。
7
+
8
+ ## 新语法
9
+
10
+ ```bash
11
+ cr edit schema 'respo.comp.space/style-space' --leaf -e ':string'
12
+ cr edit schema 'some.ns/my-val' --leaf -e ':number'
13
+ cr edit schema 'some.ns/my-flag' --leaf -e ':bool'
14
+ ```
15
+
16
+ 接受的 primitive 类型 tag:`bool`, `number`, `string`, `symbol`, `tag`, `list`, `map`, `set`, `fn`, `tuple`, `ref`, `buffer`, `dynamic`, `unit`
17
+
18
+ ## 改动文件
19
+
20
+ ### `src/calcit/type_annotation.rs`
21
+
22
+ - `builtin_tag_name` 改为 `pub(crate)`,供 snapshot 序列化侧调用。
23
+
24
+ ### `src/snapshot.rs`
25
+
26
+ - 新增常量 `PRIMITIVE_SCHEMA_TAGS`:列出允许作为 leaf schema 的原始类型。
27
+ - `validate_schema_for_write`:对 `Cirru::Leaf` 先检查是否在允许列表,允许则直接 Ok;否则给出提示信息。
28
+ - `parse_loaded_schema_annotation`:新增对 `Edn::Tag` 的处理,返回对应 `CalcitTypeAnnotation`。
29
+ - 两处 `CodeEntry::From` impl:`_ => Edn::Nil` 改为调用 `builtin_tag_name().map(Edn::tag)` 把原始类型 tag 正确序列化到快照。
30
+ - 测试 `test_validate_schema_for_write`:更新为测试原始类型 leaf 通过、未知 leaf 拒绝。
31
+
32
+ ### `src/bin/cli_handlers/edit.rs`
33
+
34
+ - `handle_schema`:`validate_schema_for_write` 通过后,若 `schema_payload` 是 `Cirru::Leaf`,用 `CalcitTypeAnnotation::from_tag_name` 直接设置 schema 并返回,不走函数 schema 解析路径。
35
+
36
+ ## 完整数据流(以 `:string` 为例)
37
+
38
+ 1. CLI 收到 `--leaf -e ':string'` → `Cirru::Leaf(":string")`
39
+ 2. `validate_schema_for_write` → `"string"` 在 `PRIMITIVE_SCHEMA_TAGS` → Ok
40
+ 3. `CalcitTypeAnnotation::from_tag_name("string")` → `CalcitTypeAnnotation::String`
41
+ 4. 写入快照 → `CodeEntry::From` 序列化为 `Edn::tag("string")`
42
+ 5. 读回快照 → `parse_loaded_schema_annotation(Edn::Tag("string"))` → `CalcitTypeAnnotation::String`
@@ -0,0 +1,17 @@
1
+ # schema type-fail tests and error codes
2
+
3
+ - 新增 `calcit/type-fail/` 下 schema 相关失败 fixture 的自动化测试,覆盖:
4
+ - `:args` required arity mismatch
5
+ - `:rest` presence mismatch
6
+ - `:kind` mismatch
7
+ - 基于 schema 的调用参数类型不匹配
8
+ - 在 `src/bin/cr.rs` 中补充 fixture 加载 helper,并通过 `run_check_only()` / preprocess warning 断言行为。
9
+ - 为类型/预处理相关告警补充 code:
10
+ - `W_FN_ARG_TYPE_MISMATCH`
11
+ - `W_PROC_ARG_TYPE_MISMATCH`
12
+ - `W_CORE_FN_ARG_TYPE_MISMATCH`
13
+ - `W_FN_RETURN_TYPE_MISMATCH`
14
+ - 为 schema 定义不匹配错误补充 code:
15
+ - `E_SCHEMA_DEF_MISMATCH`
16
+ - 为 `CalcitErr` 增加 `code` 字段和 `headline()`,让 CLI 输出可携带错误码。
17
+ - 更新 `calcit/type-fail/README.md`,记录自动化测试与当前相关 code。
@@ -0,0 +1,5 @@
1
+ # add test-fail script
2
+
3
+ - 在 `package.json` 中新增 `yarn test-fail`,用于日常单独执行 schema/type-fail 相关测试。
4
+ - 该命令当前映射到 `cargo test -q --bin cr type_fail_`,覆盖 `src/bin/cr.rs` 中新增的 fixture 测试。
5
+ - 更新 `calcit/type-fail/README.md`,补充 `yarn test-fail` 的使用说明。
@@ -0,0 +1,8 @@
1
+ # split type-fail tests into separate file
2
+
3
+ - 将 `src/bin/cr.rs` 中与 `type-fail` fixture 相关的 helper 和测试拆分到独立文件 `src/bin/cr_type_fail_tests.rs`。
4
+ - 在 `src/bin/cr.rs` 顶部通过 `#[cfg(test)] mod cr_type_fail_tests;` 挂载测试模块。
5
+ - 保留 `cr.rs` 中的通用 schema/type 覆盖测试,减少主文件体积。
6
+ - 验证通过:
7
+ - `cargo test -q --bin cr`
8
+ - `yarn test-fail`
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^25.0.9",
@@ -14,6 +14,7 @@
14
14
  "fmt-rs": "cargo fmt --all",
15
15
  "lint-rs": "cargo clippy --all-targets -- -D warnings",
16
16
  "test-rs": "cargo test -q",
17
+ "test-fail": "cargo test -q --bin cr type_fail_",
17
18
  "test-snippets": "cargo test -q snippets::tests",
18
19
  "bench-recur-smoke": "cargo run --bin cr -- calcit/test.cirru -1 js && node --input-type=module -e \"import { test_loop } from './js-out/test-recursion.main.mjs'; const n=3000; const t0=process.hrtime.bigint(); for(let i=0;i<n;i++) test_loop(); const dt=Number(process.hrtime.bigint()-t0)/1e6; console.log('test_loop_ms='+dt.toFixed(3));\"",
19
20
  "check-smooth": "yarn fmt-rs && yarn lint-rs && yarn test-rs && yarn check-all",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^25.0.9",
@@ -14,6 +14,7 @@
14
14
  "fmt-rs": "cargo fmt --all",
15
15
  "lint-rs": "cargo clippy --all-targets -- -D warnings",
16
16
  "test-rs": "cargo test -q",
17
+ "test-fail": "cargo test -q --bin cr type_fail_",
17
18
  "test-snippets": "cargo test -q snippets::tests",
18
19
  "bench-recur-smoke": "cargo run --bin cr -- calcit/test.cirru -1 js && node --input-type=module -e \"import { test_loop } from './js-out/test-recursion.main.mjs'; const n=3000; const t0=process.hrtime.bigint(); for(let i=0;i<n;i++) test_loop(); const dt=Number(process.hrtime.bigint()-t0)/1e6; console.log('test_loop_ms='+dt.toFixed(3));\"",
19
20
  "check-smooth": "yarn fmt-rs && yarn lint-rs && yarn test-rs && yarn check-all",