@kashscript/lexicons
v0.1.1
Published
Zero-dependency lexicon framework — envelope, schema DSL, registry, validator. Agnostic core; domain content ships as opt-in extensions.
Readme
@kashscript/lexicons
Zero-dependency lexicon framework — envelope, schema DSL, registry, validator. Domain-agnostic core; vocabularies ship as opt-in extensions.
bun add @kashscript/lexiconsA lexicon is the Kash equivalent of an AT-Protocol record schema: a
versioned, NSID-addressed JSON shape that describes what valid kash.*
records look like. This package gives you the primitives to define,
register, and validate lexicons — but ships zero domain content
out of the box. The domain extensions (social, trade, zkp) are
explicit subpath imports.
What's in the box
| Subpath | Purpose |
|----------------------------------------|------------------------------------------------------|
| @kashscript/lexicons | Default — re-exports envelope, schema, registry, engine |
| @kashscript/lexicons/envelope | Record envelope shape + wrap() / unwrap() |
| @kashscript/lexicons/schema | Schema DSL — string(), object(), union(), etc. |
| @kashscript/lexicons/registry | LexiconRegistry — register, lookup, version-resolve |
| @kashscript/lexicons/engine | validate(envelope, registry) — pure-TS validator |
| @kashscript/lexicons/json-schema | Export lexicons as JSON Schema (draft 2020-12) |
| @kashscript/lexicons/semver | Strict semver for lexicon evolution |
| @kashscript/lexicons/extensions/social | The kash.social.* vocabulary |
| @kashscript/lexicons/extensions/trade | The kash.trade.* vocabulary |
| @kashscript/lexicons/extensions/zkp | The kash.zkp.* vocabulary |
Quickstart
import { object, string, number } from "@kashscript/lexicons/schema";
import { LexiconRegistry } from "@kashscript/lexicons/registry";
import { validate } from "@kashscript/lexicons/engine";
// 1. Define a lexicon
const myPost = {
nsid: "com.example.post",
version: "1.0.0",
shape: object({
text: string({ maxLength: 280 }),
createdAt: number(),
}),
};
// 2. Register it
const registry = new LexiconRegistry();
registry.register(myPost);
// 3. Validate a record
const result = validate(
{
$type: "com.example.post",
$version:"1.0.0",
text: "hello world",
createdAt: Date.now(),
},
registry,
);
if (!result.ok) console.error(result.errors);License
Apache-2.0. Also covered by SSLA v1.0 Schedule A (Permissive). See LICENSE.
