toolcraft-schema 0.0.93 → 0.0.94

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.
Files changed (2) hide show
  1. package/README.md +19 -5
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,21 +1,21 @@
1
1
  # toolcraft-schema
2
2
 
3
- tools for agents and humans
4
-
5
- Zero-dependency schema builder for typed command inputs and JSON Schema generation.
3
+ Zero-dependency schema builder for typed command inputs, runtime validation,
4
+ and JSON Schema generation.
6
5
 
7
6
  ## Features
8
7
 
9
8
  - Zero runtime dependencies
10
9
  - Typed schema descriptors
11
10
  - `Static<typeof schema>` type inference
11
+ - Runtime validation with `validateValue()`
12
12
  - JSON Schema serialization via `toJsonSchema()`
13
13
  - JSON Schema document serialization via `toJsonSchemaDocument()`
14
14
 
15
15
  ## Usage
16
16
 
17
17
  ```ts
18
- import { S, toJsonSchema, toJsonSchemaDocument } from "toolcraft-schema";
18
+ import { S, toJsonSchema, toJsonSchemaDocument, validateValue } from "toolcraft-schema";
19
19
  import type { Static } from "toolcraft-schema";
20
20
 
21
21
  const schema = S.Object({
@@ -38,6 +38,11 @@ const document = toJsonSchemaDocument(schema, {
38
38
  id: "https://example.test/schema.json",
39
39
  title: "Example schema"
40
40
  });
41
+ const validation = validateValue(schema, {
42
+ name: "Ada",
43
+ mode: "safe",
44
+ tags: []
45
+ });
41
46
  ```
42
47
 
43
48
  ## API
@@ -49,6 +54,9 @@ const document = toJsonSchemaDocument(schema, {
49
54
  - `S.Boolean({ description?, default?, short?, cliAliases? })`
50
55
  - `S.Enum(values, { description?, default?, short?, cliAliases? })`
51
56
  - `S.Array(itemSchema, { description?, default?, short?, cliAliases? })`
57
+ - `S.Record(valueSchema, { description?, default? })`
58
+ - `S.Union([schemaA, schemaB], { description?, default? })`
59
+ - `S.OneOf([schemaA, schemaB], { description?, default? })`
52
60
  - `S.Object({ [key]: schema })`
53
61
  - `S.Optional(schema)`
54
62
 
@@ -66,7 +74,13 @@ const document = toJsonSchemaDocument(schema, {
66
74
  - Nested `S.Object(...)` schemas produce nested JSON Schema objects.
67
75
  - `S.Enum(...)` rejects empty or duplicate values at runtime for JavaScript callers.
68
76
 
69
- ## Environment variables
77
+ ### Runtime validation
78
+
79
+ - `validateValue(schema, value)` returns `{ ok: true, value }` for valid input.
80
+ - Invalid input returns `{ ok: false, issues }` with path-aware diagnostics.
81
+ - Validation applies defaults from schema descriptors.
82
+
83
+ ## Environment Variables
70
84
 
71
85
  This package exposes no environment variables.
72
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-schema",
3
- "version": "0.0.93",
3
+ "version": "0.0.94",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",