@collidor/struct

中文文档
1.1.2发布于 2026/11/05MITTypeScriptESM + CJS构建来源已验证近 30 天下载 8079

Modular data structure builder with Standard Schema, JSON Schema, Zod interop, Axon graph port typing, and Vee-Validate form generation

原始使用文档
文档目录8 节
  1. Features
  2. Installation
  3. Deno / JSR
  4. Node / npm / pnpm / Bun
  5. Quick Start
  6. Unified Form Builder ( @collidor/struct/form )
  7. Zod & JSON Schema Interop
  8. License

@collidor/struct

Modular data structure builder with Standard Schema compliance, JSON Schema / Zod bidirectional bridges, Axon graph port typing, and Vee-Validate form generation.

Features

  • 📐 Standard Schema V1 Compliant: Works directly with modern form, validation, and API libraries.
  • 🔄 Bidirectional Bridges: Lossless interop with Zod (toZod, fromZod) and JSON Schema (toJSONSchema, fromJSONSchema).
  • ⚡ Axon Port Subtyping: Complete graph data type descriptor mapping and subtype compatibility checker (isAssignable).
  • 📝 Dynamic UI Form Generation: Automated field layout, widget inference, and interactive form builder (StructBuilder, getFormFields).
  • 🗄️ Storage & DDL Migrations: Schema DDL generation and transactional migrations for SQLite/SQL backends.
  • 🧮 Computed Properties: Safe in-memory formula evaluation with AST dependency topological resolution.

Installation

Deno / JSR

deno add jsr:@collidor/struct

Node / npm / pnpm / Bun

npx jsr add @collidor/struct
# or
pnpm dlx jsr add @collidor/struct
# or
bunx jsr add @collidor/struct

Quick Start

import { s } from "@collidor/struct";

// Define a schema
const UserSchema = s.struct({
  id: s.string().uuid(),
  name: s.string().min(2).max(50),
  email: s.string().email(),
  age: s.number().positive().optional(),
  tags: s.array(s.string()).default([]),
});

// Validate synchronous or asynchronous
const result = UserSchema.safeParse({
  id: "123e4567-e89b-12d3-a456-426614174000",
  name: "Alykam",
  email: "[email protected]",
});

if (result.success) {
  console.log("Validated user:", result.data);
} else {
  console.error("Validation issues:", result.issues);
}

Unified Form Builder (@collidor/struct/form)

The @collidor/struct/form secondary export unifies spatial layout containers, non-data UI decorators, conditional rendering, and collection view modes directly inside structure definitions:

import { f } from "@collidor/struct/form";

const OnboardingForm = f.struct({
  banner: f.alert({
    title: "Welcome",
    message: "Fill in your details below",
    tone: "info",
  }),

  // Put two inputs on the same line
  nameRow: f.row({
    firstName: f.string().min(2),
    lastName: f.string().min(2),
  }, { gap: "1rem" }),

  accountType: f.enum(["personal", "business"] as const).default("personal"),

  // Conditional branch (validation bypassed when hidden)
  companyInfo: f.when('accountType == "business"', {
    companyName: f.string(),
    vatId: f.string(),
  }),

  // Collection view modes (asTable, asList, asCards, asTags)
  skills: f.array(f.string()).asTags(),
  submitBtn: f.button({ label: "Create Account", action: "submit" }),
});

// Flat data model: UI-only nodes stripped, layout containers flattened!
const validated = OnboardingForm.parse({
  firstName: "Ada",
  lastName: "Lovelace",
  accountType: "personal",
  skills: ["computing", "math"],
});

// Framework-agnostic Headless Form Controller
const controller = f.createController(OnboardingForm, {
  initialValues: validated,
  onSubmit: (values) => console.log("Submitted:", values),
});

Zod & JSON Schema Interop

import { s, toZod, fromZod, toJSONSchema, fromJSONSchema } from "@collidor/struct";
import { z } from "zod";

// Convert struct to Zod
const zodUser = toZod(UserSchema);

// Convert Zod to struct
const zodSchema = z.object({ count: z.number().int().positive() });
const structFromZod = fromZod(zodSchema);

// JSON Schema export
const jsonSchema = toJSONSchema(UserSchema);

License

MIT © Alykam Burdzaki

版本与发布记录

@collidor/struct 共发布 6 个版本,首次发布于 2026/10/04;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.2latest2026/11/054 天前
1.1.12026/10/101 个月前
1.1.02026/10/101 个月前
1.0.12026/10/081 个月前
1.0.02026/10/061 个月前
0.1.02026/10/041 个月前

关于 @collidor/struct 的常见问题

@collidor/struct 是什么?

Modular data structure builder with Standard Schema, JSON Schema, Zod interop, Axon graph port typing, and Vee-Validate form generation

如何安装 @collidor/struct?

在项目目录运行 npm install @collidor/struct,或使用 pnpm add / yarn add / bun add。

@collidor/struct 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@collidor/struct 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@collidor/struct 可以商用吗?

@collidor/struct 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@collidor/struct 的下载量有多少?

根据 npm 官方下载统计,@collidor/struct 在 2026/10/11 – 2026/11/09 这 30 天内被下载 8,079 次,日均约 269 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@collidor/struct 还在维护吗?

最新版本 1.1.2 发布于 2026/11/05(4 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/10/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。