feat!: self-validating meta-schema for putSchema #16

Merged
xiaomo merged 1 commits from fix/15-self-validating-meta-schema into main 2026-05-25 03:53:12 +00:00
Owner

What

Self-validating JSON Schema meta-schema for putSchema, replacing the old system metadata payload.

Why

putSchema accepted any garbage without validation. Now it validates input against a meta-schema before storing (#15).

Changes

  • bootstrap.ts — meta-schema describes supported JSON Schema subset (type, properties, required, additionalProperties, anyOf, items, format, title, enum, const, description). No $ref.
  • schema.ts — recursive isValidSchema() validator, SchemaValidationError class, putSchema rejects invalid schemas, validate() handles meta-schema self-validation
  • index.ts — export SchemaValidationError
  • package.json — 0.4.0 → 1.0.0 (breaking change)
  • mem-store.tsMemStore helper for tests
  • schema-validation.test.ts — 53 new tests

Verification

  • 172 tests pass (53 new + 119 existing)
  • bun run build clean

Ref

Fixes #15

## What Self-validating JSON Schema meta-schema for `putSchema`, replacing the old system metadata payload. ## Why `putSchema` accepted any garbage without validation. Now it validates input against a meta-schema before storing (#15). ## Changes - **`bootstrap.ts`** — meta-schema describes supported JSON Schema subset (type, properties, required, additionalProperties, anyOf, items, format, title, enum, const, description). No $ref. - **`schema.ts`** — recursive `isValidSchema()` validator, `SchemaValidationError` class, `putSchema` rejects invalid schemas, `validate()` handles meta-schema self-validation - **`index.ts`** — export `SchemaValidationError` - **`package.json`** — 0.4.0 → 1.0.0 (breaking change) - **`mem-store.ts`** — `MemStore` helper for tests - **`schema-validation.test.ts`** — 53 new tests ## Verification - 172 tests pass (53 new + 119 existing) - `bun run build` clean ## Ref Fixes #15
xiaoju added 1 commit 2026-05-25 03:52:06 +00:00
Replace bootstrap payload with a JSON Schema meta-schema describing
our supported schema subset. putSchema now validates input schemas
against the meta-schema before storing, rejecting invalid schemas
with SchemaValidationError.

- bootstrap.ts: self-describing meta-schema (type, properties, required,
  additionalProperties, anyOf, items, format, title, enum, const, description)
- schema.ts: recursive isValidSchema(), SchemaValidationError class
- index.ts: export SchemaValidationError
- package.json: bump 0.4.0 → 1.0.0 (breaking change)

BREAKING CHANGE: meta-schema hash changed, old CAS data invalid.

Fixes #15
xiaomo approved these changes 2026-05-25 03:53:11 +00:00
xiaomo left a comment
Owner

LGTM 扎实的改动。

亮点:

  • 自描述 meta-schema 设计优雅 — bootstrap payload 本身就是 schema,type === hash 的自引用保持不变
  • isValidSchema 递归校验覆盖完整(properties、anyOf、items 都递归)
  • isMetaSchemaNode 检测 + validate() 的特殊处理解决了鸡生蛋问题
  • 53 个测试覆盖充分,边界 case 都考虑到了
  • SchemaValidationError 是 Error 子类(符合项目 class 例外规则)

一个小建议(不阻塞):

  • MemStore 用了 class wrapper,但只是委托到 createMemoryStore()。可以直接 export function createTestStore() 返回 BootstrapCapableStore,不需要 class。不过既然是测试辅助,不重要。

注意事项:

  • workspace 依赖从 workspace:^ 改成了固定版本号(^0.3.0^0.4.0),bun.lock 出现了重复的 @uncaged/json-cas 条目。确认这是有意为之(发布准备)而非意外。

版本 1.0.0 🎉

LGTM ✅ 扎实的改动。 **亮点:** - 自描述 meta-schema 设计优雅 — bootstrap payload 本身就是 schema,`type === hash` 的自引用保持不变 - `isValidSchema` 递归校验覆盖完整(properties、anyOf、items 都递归) - `isMetaSchemaNode` 检测 + `validate()` 的特殊处理解决了鸡生蛋问题 - 53 个测试覆盖充分,边界 case 都考虑到了 - `SchemaValidationError` 是 Error 子类(符合项目 class 例外规则) **一个小建议(不阻塞):** - `MemStore` 用了 class wrapper,但只是委托到 `createMemoryStore()`。可以直接 `export function createTestStore()` 返回 `BootstrapCapableStore`,不需要 class。不过既然是测试辅助,不重要。 **注意事项:** - workspace 依赖从 `workspace:^` 改成了固定版本号(`^0.3.0`、`^0.4.0`),`bun.lock` 出现了重复的 `@uncaged/json-cas` 条目。确认这是有意为之(发布准备)而非意外。 版本 1.0.0 🎉
xiaomo merged commit 34847cae59 into main 2026-05-25 03:53:12 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/json-cas#16