@niscorp/prism 0.1.2 → 0.2.1

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 (38) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/DESIGN.md +5 -2
  3. package/DOCS.md +35 -2
  4. package/README.md +49 -3
  5. package/dist/agent.cjs +6 -4
  6. package/dist/agent.cjs.map +1 -1
  7. package/dist/agent.js +2 -2
  8. package/dist/{chunk-HPUAEIWY.js → chunk-O3OJAQWA.js} +9 -7
  9. package/dist/chunk-O3OJAQWA.js.map +1 -0
  10. package/dist/{chunk-5ZHYURZO.js → chunk-VC4PRB4H.js} +21 -4
  11. package/dist/chunk-VC4PRB4H.js.map +1 -0
  12. package/dist/{chunk-XABNV76M.js → chunk-XRK55NPE.js} +3 -3
  13. package/dist/chunk-XRK55NPE.js.map +1 -0
  14. package/dist/examples/index.cjs +1543 -0
  15. package/dist/examples/index.cjs.map +1 -0
  16. package/dist/examples/index.d.cts +26 -0
  17. package/dist/examples/index.d.ts +26 -0
  18. package/dist/examples/index.js +1540 -0
  19. package/dist/examples/index.js.map +1 -0
  20. package/dist/index.cjs +25 -4
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +5 -82
  23. package/dist/index.d.ts +5 -82
  24. package/dist/index.js +5 -5
  25. package/dist/migrations/index.cjs +33 -19
  26. package/dist/migrations/index.cjs.map +1 -1
  27. package/dist/migrations/index.d.cts +3 -2
  28. package/dist/migrations/index.d.ts +3 -2
  29. package/dist/migrations/index.js +13 -18
  30. package/dist/migrations/index.js.map +1 -1
  31. package/dist/profiles-C6r-x-Vj.d.cts +83 -0
  32. package/dist/profiles-C6r-x-Vj.d.ts +83 -0
  33. package/dist/transform-DcVcOBzQ.d.cts +3 -0
  34. package/dist/transform-DcVcOBzQ.d.ts +3 -0
  35. package/package.json +19 -8
  36. package/dist/chunk-5ZHYURZO.js.map +0 -1
  37. package/dist/chunk-HPUAEIWY.js.map +0 -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AAA;AAAA,EAAQ,OAAA;AAAA;AAAA,EAElC,MAAA;AAAA,EAAQ,SAAA;AAAA,EAAW,SAAA;AAAA,EAAW,QAAA;AAAA,EAAU,SAAA;AAAA,EAAW,SAAA;AAAA,EAAW,OAAA;AAAA,EAAS,QAAA;AAAA;AAAA,EAEvE,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,QAAA;AAAA,EAAU,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,QAAA;AAAA,EAAU,MAAA;AAAA,EAAQ,MAAA;AAAA;AAAA,EAE5E,OAAA;AAAA,EAAS,WAAA;AAAA,EAAa,cAAA;AAAA,EAAgB,OAAA;AAAA,EAAS,QAAA;AAAA,EAAU,QAAA;AAAA,EAAU,QAAA;AAAA;AAAA,EAEnE,KAAA;AAAA,EAAO,MAAA;AAAA,EAAQ,KAAA;AAAA,EAAO,MAAA;AAAA,EAAQ,KAAA;AAAA,EAAO,MAAA;AAAA,EAAQ,QAAA;AAAA,EAAU,WAAA;AAAA,EAAa,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,KAAA;AAAA;AAAA,EAEpF,QAAA;AAAA,EAAU,WAAA;AAAA,EAAa,OAAA;AAAA,EAAS,UAAA;AAAA,EAAY,OAAA;AAAA,EAAS,OAAA;AAAA,EAAS,SAAA;AAAA;AAAA,EAE9D,OAAA;AAAA,EAAS,WAAA;AAAA,EAAa,aAAA;AAAA,EAAe,cAAA;AAAA,EAAgB;AACvD","file":"chunk-XABNV76M.js","sourcesContent":["import { z } from 'zod';\n\nimport { NodeSchema } from '../schemas/node.schema';\nimport { ConfigSchema } from '../schemas/config.schema';\nimport type { OpKey } from '../schemas/profiles';\n\nexport type JsonSchemaTarget = 'draft-2020-12' | 'draft-7' | 'draft-4';\n\nexport const getNodeJsonSchema = (target: JsonSchemaTarget = 'draft-2020-12'): object =>\n z.toJSONSchema(NodeSchema, { target });\n\nexport const getConfigJsonSchema = (target: JsonSchemaTarget = 'draft-2020-12'): object =>\n z.toJSONSchema(ConfigSchema, { target });\n\n// ─────────────────────────────────────────────────────────\n// Profiles — the config schema, documenting only some ops\n// ─────────────────────────────────────────────────────────\n//\n// DERIVED from getConfigJsonSchema, never written by hand: the node is one\n// recursive definition whose `anyOf` holds one alternative per op, and every\n// child position refers back to it — so dropping an op's alternative there\n// drops it everywhere. Everything that is not an op (primitives, arrays, the\n// plain-object template, whose key pattern still names EVERY op, since a\n// plain object may never use one as a key) is kept as it is. Definitions only\n// the dropped ops used are removed. Documentation only: validation is always\n// the full ConfigSchema (schemas/profiles.ts).\n//\n// A reference is read in either spelling. Drafts 4–7 ignore keywords beside a\n// `$ref`, so a described reference is written `allOf: [{ $ref }]` there — and\n// zod does so for the root and for a described op in every version but 4.3.\n\ntype JsonObject = Record<string, unknown>;\nconst isObject = (value: unknown): value is JsonObject => typeof value === 'object' && value !== null && !Array.isArray(value);\n\n// `allOf: [{ $ref }]` → `{ $ref }`; anything else as it is.\nconst unwrapRef = (value: unknown): unknown => {\n const allOf = isObject(value) ? value['allOf'] : undefined;\n const only: unknown = Array.isArray(allOf) && allOf.length === 1 ? allOf[0] : undefined;\n return isObject(only) && '$ref' in only ? only : value;\n};\n\n// `#/$defs/x` or `#/definitions/x` → ['$defs', 'x'].\nconst refTarget = (ref: unknown): [string, string] | undefined => {\n if (typeof ref !== 'string') return undefined;\n const match = /^#\\/([^/]+)\\/([^/]+)$/.exec(ref);\n return match?.[1] !== undefined && match[2] !== undefined ? [match[1], match[2]] : undefined;\n};\n\nconst resolve = (root: JsonObject, ref: unknown): JsonObject | undefined => {\n const target = refTarget(ref);\n if (target === undefined) return undefined;\n const container = root[target[0]];\n const def = isObject(container) ? container[target[1]] : undefined;\n return isObject(def) ? def : undefined;\n};\n\n// The op an alternative is — its one `$`-key — whether written inline or\n// behind a `$ref` to its own definition.\nconst opOf = (root: JsonObject, written: unknown): string | undefined => {\n const alternative = unwrapRef(written);\n const node = isObject(alternative) && '$ref' in alternative ? resolve(root, alternative['$ref']) : alternative;\n const properties = isObject(node) ? node['properties'] : undefined;\n const key = isObject(properties) ? Object.keys(properties)[0] : undefined;\n return key !== undefined && key.startsWith('$') ? key : undefined;\n};\n\nconst refsIn = (value: unknown, found: Set<string>): void => {\n if (Array.isArray(value)) {\n for (const item of value) refsIn(item, found);\n return;\n }\n if (!isObject(value)) return;\n for (const [key, child] of Object.entries(value)) {\n if (key === '$ref' && typeof child === 'string') found.add(child);\n else refsIn(child, found);\n }\n};\n\nexport const getProfileJsonSchema = (ops: readonly OpKey[], target: JsonSchemaTarget = 'draft-2020-12'): object =>\n narrowConfigJsonSchema(getConfigJsonSchema(target), ops);\n\n// The narrowing itself, over any spelling of the config schema — exported for\n// the tests, which feed it both.\nexport const narrowConfigJsonSchema = (full: unknown, ops: readonly OpKey[]): object => {\n if (!isObject(full)) throw new Error('prism: the config JSON Schema is not an object');\n const root = structuredClone(full);\n const top = unwrapRef(root);\n const node = resolve(root, isObject(top) ? top['$ref'] : undefined);\n const alternatives = node?.['anyOf'];\n if (node === undefined || !Array.isArray(alternatives)) throw new Error('prism: the config JSON Schema has no node union to narrow');\n\n const keep = new Set<string>(ops);\n node['anyOf'] = alternatives.filter((alternative) => {\n const op = opOf(root, alternative);\n return op === undefined || keep.has(op);\n });\n\n // Keep the definitions still reachable from the root, and only those: a\n // worklist, so a chain of definitions is followed to its end.\n const reached = new Set<string>();\n const pending: string[] = [];\n const visit = (value: unknown): void => {\n const found = new Set<string>();\n refsIn(value, found);\n for (const ref of found) {\n if (reached.has(ref)) continue;\n reached.add(ref);\n pending.push(ref);\n }\n };\n visit({ ...root, $defs: undefined, definitions: undefined });\n for (let ref = pending.pop(); ref !== undefined; ref = pending.pop()) visit(resolve(root, ref));\n\n for (const container of ['$defs', 'definitions']) {\n const defs = root[container];\n if (!isObject(defs)) continue;\n for (const name of Object.keys(defs)) if (!reached.has(`#/${container}/${name}`)) delete defs[name];\n }\n return root;\n};\n","import type { OP_KEYS } from './node.schema';\n\n// ═══════════════════════════════════════════════════════════\n// Profiles — named subsets of the ops, for DOCUMENTATION only\n// ═══════════════════════════════════════════════════════════\n//\n// A profile narrows what a prompt teaches, never what the grammar accepts:\n// every config is still parsed by the full ConfigSchema, so a config written\n// under a profile is an ordinary Prism config, and one using an op outside\n// the profile is still valid. What changes is the size of the grammar an\n// agent is handed — the full node schema is ~35k characters, most of it the\n// per-op descriptions, and an agent that only maps rows into a shape does not\n// need the ops strata rewrites documents with.\n//\n// `getProfileJsonSchema(ops)` (engine/documentation.ts) derives the narrowed\n// JSON Schema from the full one; nothing about an op is restated here.\n\nexport type OpKey = (typeof OP_KEYS)[number];\n\n// Mapping rows into a caller's shape (vex's shape mapper, prism's mapping\n// agent). Every op the repo's authored mappings and endpoint configs use —\n// counted across *.entries.ts and *.prism.ts, 2026-09-27 — and the shaping ops\n// a mapping plainly needs beside them. Left out: the document-rewriting ops\n// ($has, $renameKeys, $update, $assert, $walk) and ops no mapping here has\n// needed ($fill, $replace, $keyBy, $entriesOf, $fromEntries, $keys, $values,\n// $type, $flatten, $flatMap, $match, $drop, $dateAdd, $startsWith, $endsWith).\nexport const MAPPING_OPS: readonly OpKey[] = [\n // reading the source\n '$ref', '$const', '$var', '$get', '$with',\n // arrays\n '$map', '$filter', '$reduce', '$slice', '$unique', '$sortBy', '$take', '$pluck',\n // numbers and aggregates\n '$add', '$sub', '$mul', '$div', '$round', '$sum', '$avg', '$count', '$min', '$max',\n // strings\n '$join', '$toString', '$interpolate', '$trim', '$lower', '$upper', '$split',\n // conditions\n '$eq', '$neq', '$gt', '$gte', '$lt', '$lte', '$empty', '$contains', '$not', '$and', '$or',\n // structure\n '$merge', '$coalesce', '$case', '$groupBy', '$pick', '$omit', '$length',\n // dates and locale formatting\n '$date', '$dateDiff', '$localeDate', '$localeMoney', '$localeNumber',\n];\n"]}