@niscorp/prism 0.1.1 → 0.2.0

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/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- export { MAPPING_OPS, getConfigJsonSchema, getNodeJsonSchema, getProfileJsonSchema } from './chunk-XABNV76M.js';
2
- import { PrismError, ErrorCode, explainIssues, desugar, primeJsonPathCache, createBudget, evaluateNode, measure, parseJsonPath, opConst, opRef, opVar, opGet, opWith, opMap, opFilter, opReduce, opSlice, opFlatten, opUnique, opSortBy, opAdd, opSub, opMul, opDiv, opRound, opJoin, opToString, opInterpolate, opFill, opTrim, opLower, opUpper, opSplit, opReplace, opEq, opNeq, opGt, opGte, opLt, opLte, opEmpty, opStartsWith, opEndsWith, opContains, opNot, opAnd, opOr, opMerge, opCoalesce, opCase, opEntriesOf, opKeyBy, opGroupBy, opKeys, opValues, opFromEntries, opPick, opOmit, opType, opLength, opHas, opRenameKeys, opUpdate, opAssert, opWalk, opDate, opDateAdd, opDateDiff, opLocaleDate, opLocaleMoney, opLocaleNumber } from './chunk-5ZHYURZO.js';
3
- export { DEFAULT_LIMITS, ErrorCode, PrismError, evaluate, evaluateSafe } from './chunk-5ZHYURZO.js';
4
- import { ConfigSchema, isJsonObject, isConstNode, isRefNode, isVarNode, isGetNode, isWithNode, isMapNode, isFilterNode, isReduceNode, isSliceNode, isFlattenNode, isUniqueNode, isSortByNode, isAddNode, isSubNode, isMulNode, isDivNode, isRoundNode, isJoinNode, isToStringNode, isInterpolateNode, isFillNode, isTrimNode, isLowerNode, isUpperNode, isSplitNode, isReplaceNode, isEqNode, isNeqNode, isGtNode, isGteNode, isLtNode, isLteNode, isEmptyNode, isStartsWithNode, isEndsWithNode, isContainsNode, isNotNode, isAndNode, isOrNode, isMergeNode, isCoalesceNode, isCaseNode, isEntriesOfNode, isKeyByNode, isGroupByNode, isKeysNode, isValuesNode, isFromEntriesNode, isPickNode, isOmitNode, isTypeNode, isLengthNode, isHasNode, isRenameKeysNode, isUpdateNode, isAssertNode, isWalkNode, isDateNode, isDateAddNode, isDateDiffNode, isLocaleDateNode, isLocaleMoneyNode, isLocaleNumberNode } from './chunk-HPUAEIWY.js';
5
- export { ConfigSchema, NodeSchema } from './chunk-HPUAEIWY.js';
1
+ export { MAPPING_OPS, getConfigJsonSchema, getNodeJsonSchema, getProfileJsonSchema } from './chunk-3PYQITGE.js';
2
+ import { PrismError, ErrorCode, explainIssues, desugar, primeJsonPathCache, createBudget, evaluateNode, measure, parseJsonPath, opConst, opRef, opVar, opGet, opWith, opMap, opFilter, opReduce, opSlice, opFlatten, opUnique, opSortBy, opAdd, opSub, opMul, opDiv, opRound, opJoin, opToString, opInterpolate, opFill, opTrim, opLower, opUpper, opSplit, opReplace, opEq, opNeq, opGt, opGte, opLt, opLte, opEmpty, opStartsWith, opEndsWith, opContains, opNot, opAnd, opOr, opMerge, opCoalesce, opCase, opEntriesOf, opKeyBy, opGroupBy, opKeys, opValues, opFromEntries, opPick, opOmit, opType, opLength, opHas, opRenameKeys, opUpdate, opAssert, opWalk, opDate, opDateAdd, opDateDiff, opLocaleDate, opLocaleMoney, opLocaleNumber } from './chunk-3GAYBBNH.js';
3
+ export { DEFAULT_LIMITS, ErrorCode, PrismError, evaluate, evaluateSafe } from './chunk-3GAYBBNH.js';
4
+ import { ConfigSchema, isJsonObject, isConstNode, isRefNode, isVarNode, isGetNode, isWithNode, isMapNode, isFilterNode, isReduceNode, isSliceNode, isFlattenNode, isUniqueNode, isSortByNode, isAddNode, isSubNode, isMulNode, isDivNode, isRoundNode, isJoinNode, isToStringNode, isInterpolateNode, isFillNode, isTrimNode, isLowerNode, isUpperNode, isSplitNode, isReplaceNode, isEqNode, isNeqNode, isGtNode, isGteNode, isLtNode, isLteNode, isEmptyNode, isStartsWithNode, isEndsWithNode, isContainsNode, isNotNode, isAndNode, isOrNode, isMergeNode, isCoalesceNode, isCaseNode, isEntriesOfNode, isKeyByNode, isGroupByNode, isKeysNode, isValuesNode, isFromEntriesNode, isPickNode, isOmitNode, isTypeNode, isLengthNode, isHasNode, isRenameKeysNode, isUpdateNode, isAssertNode, isWalkNode, isDateNode, isDateAddNode, isDateDiffNode, isLocaleDateNode, isLocaleMoneyNode, isLocaleNumberNode } from './chunk-BRIXDNJQ.js';
5
+ export { ConfigSchema, NodeSchema } from './chunk-BRIXDNJQ.js';
6
6
  import { exceedsDepth, depthRefusal } from '@niscorp/strata';
7
7
 
8
8
  // src/engine/optimize.ts
@@ -503,7 +503,9 @@ var OP_KEYS = [
503
503
  "$walk"
504
504
  ];
505
505
  var OPTIONAL_FIELDS_KEY = "__optional";
506
- var NOT_AN_OP_KEY = new RegExp(`^(?!(?:${OP_KEYS.map((k) => k.replace(/\$/g, "\\$")).join("|")})$)`);
506
+ var TEMPLATE_KEY = /^(?!\$)/;
507
+ var isOpKey = (key) => OP_KEYS.some((op) => op === key);
508
+ var templateKeyRefusal = (key) => isOpKey(key) ? "An op name cannot be a plain object key. Use the op itself." : 'Not a Prism op. A key that starts with "$" names an op; data with such a key goes in $const.';
507
509
  var hasValidOptionalMeta = (obj) => {
508
510
  const meta = obj[OPTIONAL_FIELDS_KEY];
509
511
  if (meta === void 0) return true;
@@ -601,14 +603,14 @@ var NodeSchema = zod.z.lazy(
601
603
  JsonPrimitiveSchema,
602
604
  // Arrays of nodes
603
605
  zod.z.array(zod.z.lazy(() => NodeSchema)),
604
- // Plain objects (no op keys, recursive values)
605
- // An op's name is not a template key. Said in the KEY schema, not a
606
+ // Plain objects (no `$` keys, recursive values)
607
+ // A `$` key is not a template key. Said in the KEY schema, not a
606
608
  // refinement: a refinement leaves this branch structurally matched, and
607
609
  // zod then reports its complaint instead of the union's — so a typo inside
608
610
  // a real op (`{ $get: { pathh } }`) read as "plain object must not contain
609
611
  // $ op keys" at the root. As a key pattern it is also plain JSON Schema
610
612
  // (`propertyNames`), which the grammar snapshot and agent prompts read.
611
- zod.z.record(zod.z.string().regex(NOT_AN_OP_KEY, { message: "An op name cannot be a plain object key. Use the op itself." }), zod.z.lazy(() => NodeSchema)).refine((o) => hasValidOptionalMeta(o), { message: "__optional must be an array of non-empty field name strings." })
613
+ zod.z.record(zod.z.string().regex(TEMPLATE_KEY, { error: (issue) => templateKeyRefusal(issue.input) }), zod.z.lazy(() => NodeSchema)).refine((o) => hasValidOptionalMeta(o), { message: "__optional must be an array of non-empty field name strings." })
612
614
  ]).describe("A Prism node: an op, a plain JSON value, an array of nodes, or a plain object template.")
613
615
  );
614
616
  setNodeSchema(NodeSchema);
@@ -1769,6 +1771,16 @@ var PRISM_SEQUENCE = {
1769
1771
  // five new op names are no longer accepted as plain template keys.
1770
1772
  description: 'Transform ops ($has, $renameKeys, $update, $assert, $walk); $ref "$" for the whole source; $join parts may be any node that evaluates to an array; an op name is not a template key',
1771
1773
  steps: []
1774
+ },
1775
+ {
1776
+ // A MARKER for a NARROWING, and a breaking release (approved): a `$` key
1777
+ // that is not an op was accepted as a template key and refused when it
1778
+ // was evaluated (E_NODE_SHAPE). No step rewrites one — it never evaluated
1779
+ // to anything, so there is nothing to rewrite it to. Checked against the
1780
+ // corpus: no captured config uses one. What it can break is a config
1781
+ // that kept such a key where evaluation never reached it.
1782
+ description: 'A template key never starts with "$": a `$` name that is not an op is refused by the schema, where it was refused only once evaluated',
1783
+ steps: []
1772
1784
  }
1773
1785
  ]
1774
1786
  };