@amritk/helpers 0.13.3 → 0.13.4
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/AI.md +40 -0
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/helpers",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.4",
|
|
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"
|