@amritk/helpers 0.13.3 → 0.13.5

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 (3) hide show
  1. package/AI.md +40 -0
  2. package/README.md +2 -1
  3. package/package.json +3 -2
package/AI.md ADDED
@@ -0,0 +1,40 @@
1
+ # @amritk/helpers — notes for AI coding agents
2
+
3
+ Shared schema-traversal, codegen, and runtime utilities for the mjst ecosystem,
4
+ each published as its own subpath so consumers import only what they need. Full
5
+ reference is [README.md](./README.md).
6
+
7
+ > Pre-alpha: internal ecosystem package — most users never import it directly.
8
+ > APIs change in **minor** versions.
9
+
10
+ ## Minimal example
11
+
12
+ ```ts
13
+ import { resolveRef } from '@amritk/helpers/resolve-ref'
14
+ import { isObjectSchema, hasProperties } from '@amritk/helpers/schema-guards'
15
+
16
+ const node = resolveRef('#/$defs/info', rootSchema) // (ref, root); undefined on miss
17
+
18
+ if (node && isObjectSchema(node) && hasProperties(node)) {
19
+ for (const [name, property] of Object.entries(node.properties)) {
20
+ // …
21
+ }
22
+ }
23
+ ```
24
+
25
+ ## Gotchas — where agents fail
26
+
27
+ 1. **No barrel — import per subpath.** `@amritk/helpers/resolve-ref`, NOT
28
+ `@amritk/helpers`. The subpath is the exact kebab-case filename with no `.ts`.
29
+ 2. **`resolveRef(ref, rootSchema)`** takes the ref first, root second, handles
30
+ JSON-pointer `$ref`s only, and returns `undefined` on a miss (no throw) —
31
+ guard the result.
32
+ 3. **Two similar guards:** `isSchemaObject` narrows to a non-boolean schema;
33
+ `isObjectSchema` narrows to a `type: object` schema. Don't confuse them.
34
+ 4. **Some modules are copied verbatim into generated output** (`is-object`,
35
+ `safe-accessor`, `validate-array`, `validate-record`) — intentionally
36
+ dependency-free and minimal, not general-purpose validators.
37
+
38
+ Notable subpaths: `/resolve-ref`, `/extract-refs`, `/schema-guards`,
39
+ `/ref-to-name`, `/ref-to-filename`, `/upgrade-draft07-schema`,
40
+ `/generate-type-definition`, `/is-object`. Install: `bun add @amritk/helpers`.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  **Shared schema-traversal and runtime helpers for the mjst code generation ecosystem.**
6
6
 
7
7
  ![status](https://img.shields.io/badge/status-pre--alpha-ef4444?style=flat-square) 
8
- ![version](https://img.shields.io/badge/version-v0.1.0-6366f1?style=flat-square&logo=npm&logoColor=white) 
8
+ ![version](https://img.shields.io/npm/v/@amritk/helpers?style=flat-square&logo=npm&logoColor=white&label=version&color=6366f1) 
9
9
  ![license](https://img.shields.io/badge/license-MIT-22c55e?style=flat-square) 
10
10
  ![JSON Schema](https://img.shields.io/badge/JSON%20Schema-2020--12-f97316?style=flat-square) 
11
11
  ![node](https://img.shields.io/badge/node-%E2%89%A520-339933?style=flat-square&logo=node.js&logoColor=white) 
@@ -55,6 +55,7 @@ bun add @amritk/helpers
55
55
  | Subpath | Exports | Purpose |
56
56
  |:---|:---|:---|
57
57
  | `@amritk/helpers/generate-type-definition` | `generateTypeDefinition` | Render a TypeScript type from a schema node. |
58
+ | `@amritk/helpers/mjst-extension` | `MJST_EXTENSION_KEY`, `getMjstInstanceOf`, `getMjstPrimitive`, `getMjstBrand` | Read the `x-mjst` vendor hints (`instanceOf`, `primitive`, `brand`) a schema carries. |
58
59
  | `@amritk/helpers/parse-documentation` | `parseDocumentation`, `ObjectDocumentation` | Parse a markdown doc file into per-property descriptions. |
59
60
 
60
61
  ### Runtime helpers (also copied into generated output)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amritk/helpers",
3
- "version": "0.13.3",
3
+ "version": "0.13.5",
4
4
  "description": "Shared utilities for the mjst code generation ecosystem.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,7 +22,8 @@
22
22
  "files": [
23
23
  "dist",
24
24
  "src/**/*.ts",
25
- "!src/**/*.test.ts"
25
+ "!src/**/*.test.ts",
26
+ "AI.md"
26
27
  ],
27
28
  "publishConfig": {
28
29
  "access": "public"