@kashscript/lexicons 0.1.1 → 0.1.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/README.md CHANGED
@@ -10,8 +10,8 @@ A *lexicon* is the Kash equivalent of an AT-Protocol record schema: a
10
10
  versioned, NSID-addressed JSON shape that describes what valid `kash.*`
11
11
  records look like. This package gives you the primitives to **define**,
12
12
  **register**, and **validate** lexicons — but ships zero domain content
13
- out of the box. The domain extensions (`social`, `trade`, `zkp`) are
14
- explicit subpath imports.
13
+ out of the box. The domain extensions (`social`, `trade`, `zkp`,
14
+ `education`, `civic`, `community`) are explicit subpath imports.
15
15
 
16
16
  ---
17
17
 
@@ -19,51 +19,51 @@ explicit subpath imports.
19
19
 
20
20
  | Subpath | Purpose |
21
21
  |----------------------------------------|------------------------------------------------------|
22
- | `@kashscript/lexicons` | Default — re-exports `envelope`, `schema`, `registry`, `engine` |
23
- | `@kashscript/lexicons/envelope` | Record envelope shape + `wrap()` / `unwrap()` |
24
- | `@kashscript/lexicons/schema` | Schema DSL — `string()`, `object()`, `union()`, etc. |
22
+ | `@kashscript/lexicons` | Default — the framework + identity-tier `STANDARD_LIBRARY` |
23
+ | `@kashscript/lexicons/envelope` | Kash-Event envelope shape (header + body + signature) + `RecordRef` |
24
+ | `@kashscript/lexicons/schema` | Schema DSL — the `S` builder (`S.object`, `S.string`, …) + `validate()` |
25
25
  | `@kashscript/lexicons/registry` | `LexiconRegistry` — register, lookup, version-resolve |
26
- | `@kashscript/lexicons/engine` | `validate(envelope, registry)` — pure-TS validator |
26
+ | `@kashscript/lexicons/engine` | `validateEvent` / `validateBody` / `getSchemaDefinition` |
27
27
  | `@kashscript/lexicons/json-schema` | Export lexicons as JSON Schema (draft 2020-12) |
28
28
  | `@kashscript/lexicons/semver` | Strict semver for lexicon evolution |
29
29
  | `@kashscript/lexicons/extensions/social` | The `kash.social.*` vocabulary |
30
30
  | `@kashscript/lexicons/extensions/trade` | The `kash.trade.*` vocabulary |
31
31
  | `@kashscript/lexicons/extensions/zkp` | The `kash.zkp.*` vocabulary |
32
+ | `@kashscript/lexicons/extensions/{education,civic,community}` | Further opt-in vocabularies |
32
33
 
33
34
  ---
34
35
 
35
36
  ## Quickstart
36
37
 
37
38
  ```typescript
38
- import { object, string, number } from "@kashscript/lexicons/schema";
39
+ import { S } from "@kashscript/lexicons/schema";
39
40
  import { LexiconRegistry } from "@kashscript/lexicons/registry";
40
- import { validate } from "@kashscript/lexicons/engine";
41
-
42
- // 1. Define a lexicon
43
- const myPost = {
44
- nsid: "com.example.post",
45
- version: "1.0.0",
46
- shape: object({
47
- text: string({ maxLength: 280 }),
48
- createdAt: number(),
49
- }),
50
- };
51
-
52
- // 2. Register it
53
- const registry = new LexiconRegistry();
54
- registry.register(myPost);
41
+ import { validateBody, validateEvent } from "@kashscript/lexicons/engine";
55
42
 
56
- // 3. Validate a record
57
- const result = validate(
43
+ // 1. Define a body schema with the `S` builder (3rd arg of S.object = required keys).
44
+ const noteSchema = S.object(
58
45
  {
59
- $type: "com.example.post",
60
- $version:"1.0.0",
61
- text: "hello world",
62
- createdAt: Date.now(),
46
+ text: S.string({ maxLength: 280 }),
47
+ createdAt: S.string({ format: "iso8601" }),
63
48
  },
49
+ ["text", "createdAt"],
50
+ );
51
+
52
+ // 2. Register it under `<nsid>@<semver>` (register() is chainable).
53
+ const registry = new LexiconRegistry();
54
+ registry.register("com.example.note@1.0.0", noteSchema, { title: "Example Note" });
55
+
56
+ // 3a. Validate a record body before signing it.
57
+ const bodyResult = validateBody(
58
+ "com.example.note@1.0.0",
59
+ { text: "hello world", createdAt: new Date().toISOString() },
64
60
  registry,
65
61
  );
66
- if (!result.ok) console.error(result.errors);
62
+ if (!bodyResult.ok) console.error(bodyResult.errors); // [{ path, message, received }]
63
+
64
+ // 3b. Or validate a full signed Kash-Event envelope (header.lexicon picks the schema).
65
+ const eventResult = validateEvent(incomingEvent, registry); // incomingEvent: unknown
66
+ if (eventResult.ok) console.log("valid:", eventResult.value.header.lexicon);
67
67
  ```
68
68
 
69
69
  ---
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Shared brand types used across the lexicon framework.
3
- * Phase-3 may re-export these from @kashscript/identity once that package
4
- * publishes its own brand types.
2
+ * Shared brand types used across the lexicon framework. Kept local to
3
+ * preserve the zero-dependency posture; the canonical did:kash types
4
+ * live in `@kashscript/identity-core/types`.
5
5
  */
6
6
  /** W3C DID restricted to the did:kash method emitted by `@kashscript/identity-core`. */
7
7
  export type DID = `did:kash:${string}`;
package/dist/types.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Shared brand types used across the lexicon framework.
3
- * Phase-3 may re-export these from @kashscript/identity once that package
4
- * publishes its own brand types.
2
+ * Shared brand types used across the lexicon framework. Kept local to
3
+ * preserve the zero-dependency posture; the canonical did:kash types
4
+ * live in `@kashscript/identity-core/types`.
5
5
  */
6
6
  /** Domain-Separation Tag for record-tier signatures (Identity Protocol §5.5). */
7
7
  export const KASH_RECORD_DST = "kash-record-v1\n";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kashscript/lexicons",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Zero-dependency lexicon framework — envelope, schema DSL, registry, validator. Agnostic core; domain content ships as opt-in extensions.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/types.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Shared brand types used across the lexicon framework.
3
- * Phase-3 may re-export these from @kashscript/identity once that package
4
- * publishes its own brand types.
2
+ * Shared brand types used across the lexicon framework. Kept local to
3
+ * preserve the zero-dependency posture; the canonical did:kash types
4
+ * live in `@kashscript/identity-core/types`.
5
5
  */
6
6
 
7
7
  /** W3C DID restricted to the did:kash method emitted by `@kashscript/identity-core`. */