@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.
- package/CHANGELOG.md +43 -0
- package/DESIGN.md +5 -2
- package/DOCS.md +35 -2
- package/README.md +49 -3
- package/dist/agent.cjs +6 -4
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.js +2 -2
- package/dist/{chunk-HPUAEIWY.js → chunk-O3OJAQWA.js} +9 -7
- package/dist/chunk-O3OJAQWA.js.map +1 -0
- package/dist/{chunk-5ZHYURZO.js → chunk-VC4PRB4H.js} +21 -4
- package/dist/chunk-VC4PRB4H.js.map +1 -0
- package/dist/{chunk-XABNV76M.js → chunk-XRK55NPE.js} +3 -3
- package/dist/chunk-XRK55NPE.js.map +1 -0
- package/dist/examples/index.cjs +1543 -0
- package/dist/examples/index.cjs.map +1 -0
- package/dist/examples/index.d.cts +26 -0
- package/dist/examples/index.d.ts +26 -0
- package/dist/examples/index.js +1540 -0
- package/dist/examples/index.js.map +1 -0
- package/dist/index.cjs +25 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -82
- package/dist/index.d.ts +5 -82
- package/dist/index.js +5 -5
- package/dist/migrations/index.cjs +33 -19
- package/dist/migrations/index.cjs.map +1 -1
- package/dist/migrations/index.d.cts +3 -2
- package/dist/migrations/index.d.ts +3 -2
- package/dist/migrations/index.js +13 -18
- package/dist/migrations/index.js.map +1 -1
- package/dist/profiles-C6r-x-Vj.d.cts +83 -0
- package/dist/profiles-C6r-x-Vj.d.ts +83 -0
- package/dist/transform-DcVcOBzQ.d.cts +3 -0
- package/dist/transform-DcVcOBzQ.d.ts +3 -0
- package/package.json +19 -8
- package/dist/chunk-5ZHYURZO.js.map +0 -1
- package/dist/chunk-HPUAEIWY.js.map +0 -1
- package/dist/chunk-XABNV76M.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,80 +1,9 @@
|
|
|
1
|
+
import { J as JsonValue, L as Limits, R as Result, C as CompileOptions, a as CompiledIr, b as JsonObject, V as ValidationResult, O as OpKey } from './profiles-C6r-x-Vj.cjs';
|
|
2
|
+
export { D as DEFAULT_LIMITS, E as EvalContext, c as JsonPrimitive, M as MAPPING_OPS, N as NodeSchema, d as OP_KEYS, e as OptimizationStats, f as ValidationIssue } from './profiles-C6r-x-Vj.cjs';
|
|
1
3
|
import { C as Config } from './config.schema-vy-_YxHP.cjs';
|
|
2
4
|
export { a as ConfigSchema } from './config.schema-vy-_YxHP.cjs';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type Limits = {
|
|
6
|
-
maxSteps: number;
|
|
7
|
-
maxStringLength: number;
|
|
8
|
-
maxValues: number;
|
|
9
|
-
};
|
|
10
|
-
declare const DEFAULT_LIMITS: Limits;
|
|
11
|
-
type Budget = {
|
|
12
|
-
readonly limits: Limits;
|
|
13
|
-
steps: number;
|
|
14
|
-
readonly sizes: WeakMap<object, number>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type JsonPrimitive = string | number | boolean | null;
|
|
18
|
-
type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
|
|
19
|
-
type JsonObject = {
|
|
20
|
-
[key: string]: JsonValue;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
type EvalContext = {
|
|
24
|
-
readonly source: JsonValue;
|
|
25
|
-
readonly vars: Record<string, JsonValue>;
|
|
26
|
-
readonly budget?: Budget;
|
|
27
|
-
};
|
|
28
|
-
type Result<T> = {
|
|
29
|
-
ok: true;
|
|
30
|
-
data: T;
|
|
31
|
-
} | {
|
|
32
|
-
ok: false;
|
|
33
|
-
error: Error;
|
|
34
|
-
};
|
|
35
|
-
type CompileOptions = {
|
|
36
|
-
name?: string;
|
|
37
|
-
version?: string;
|
|
38
|
-
};
|
|
39
|
-
type OptimizationStats = {
|
|
40
|
-
refsInlined: number;
|
|
41
|
-
handlersAttached: number;
|
|
42
|
-
constantsFolded: number;
|
|
43
|
-
};
|
|
44
|
-
type CompiledIr = {
|
|
45
|
-
irVersion: 1;
|
|
46
|
-
compiler: {
|
|
47
|
-
name: string;
|
|
48
|
-
version: string;
|
|
49
|
-
};
|
|
50
|
-
meta: {
|
|
51
|
-
name?: string;
|
|
52
|
-
createdAt: string;
|
|
53
|
-
fingerprint: string;
|
|
54
|
-
stats: {
|
|
55
|
-
nodeCount: number;
|
|
56
|
-
opCount: Record<string, number>;
|
|
57
|
-
maxDepth: number;
|
|
58
|
-
optimizations: OptimizationStats;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
tables: {
|
|
62
|
-
paths: string[];
|
|
63
|
-
strings: string[];
|
|
64
|
-
};
|
|
65
|
-
core: unknown;
|
|
66
|
-
};
|
|
67
|
-
type ValidationIssue = {
|
|
68
|
-
path: (string | number)[];
|
|
69
|
-
message: string;
|
|
70
|
-
};
|
|
71
|
-
type ValidationResult = {
|
|
72
|
-
ok: true;
|
|
73
|
-
data: unknown;
|
|
74
|
-
} | {
|
|
75
|
-
ok: false;
|
|
76
|
-
issues: ValidationIssue[];
|
|
77
|
-
};
|
|
5
|
+
export { p as prismTransform } from './transform-DcVcOBzQ.cjs';
|
|
6
|
+
import 'zod';
|
|
78
7
|
|
|
79
8
|
declare const evaluate: (config: Config, source: JsonValue, limits?: Partial<Limits>) => JsonValue;
|
|
80
9
|
declare const evaluateSafe: (config: Config, source: JsonValue, limits?: Partial<Limits>) => Result<JsonValue>;
|
|
@@ -85,12 +14,6 @@ declare const execute: (ir: CompiledIr, source: JsonObject, limits?: Partial<Lim
|
|
|
85
14
|
|
|
86
15
|
declare const validate: (config: unknown) => ValidationResult;
|
|
87
16
|
|
|
88
|
-
declare const OP_KEYS: readonly ["$ref", "$const", "$var", "$get", "$with", "$map", "$filter", "$reduce", "$slice", "$flatten", "$unique", "$sortBy", "$add", "$sub", "$mul", "$div", "$round", "$fill", "$join", "$toString", "$interpolate", "$trim", "$lower", "$upper", "$split", "$replace", "$eq", "$neq", "$gt", "$gte", "$lt", "$lte", "$empty", "$startsWith", "$endsWith", "$contains", "$not", "$and", "$or", "$merge", "$coalesce", "$case", "$entriesOf", "$keyBy", "$groupBy", "$keys", "$values", "$fromEntries", "$pick", "$omit", "$type", "$length", "$date", "$dateAdd", "$dateDiff", "$localeDate", "$localeMoney", "$localeNumber", "$sum", "$avg", "$count", "$min", "$max", "$pluck", "$take", "$drop", "$match", "$flatMap", "$has", "$renameKeys", "$update", "$assert", "$walk"];
|
|
89
|
-
declare const NodeSchema: z.ZodType<unknown>;
|
|
90
|
-
|
|
91
|
-
type OpKey = (typeof OP_KEYS)[number];
|
|
92
|
-
declare const MAPPING_OPS: readonly OpKey[];
|
|
93
|
-
|
|
94
17
|
type JsonSchemaTarget = 'draft-2020-12' | 'draft-7' | 'draft-4';
|
|
95
18
|
declare const getNodeJsonSchema: (target?: JsonSchemaTarget) => object;
|
|
96
19
|
declare const getConfigJsonSchema: (target?: JsonSchemaTarget) => object;
|
|
@@ -119,4 +42,4 @@ declare class PrismError extends Error {
|
|
|
119
42
|
constructor(message: string, code: ErrorCode, context?: PrismErrorContext);
|
|
120
43
|
}
|
|
121
44
|
|
|
122
|
-
export {
|
|
45
|
+
export { CompileOptions, CompiledIr, Config, ErrorCode, JsonObject, type JsonSchemaTarget, JsonValue, Limits, OpKey, PrismError, type PrismErrorContext, Result, ValidationResult, compile, evaluate, evaluateSafe, execute, getConfigJsonSchema, getNodeJsonSchema, getProfileJsonSchema, validate };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,80 +1,9 @@
|
|
|
1
|
+
import { J as JsonValue, L as Limits, R as Result, C as CompileOptions, a as CompiledIr, b as JsonObject, V as ValidationResult, O as OpKey } from './profiles-C6r-x-Vj.js';
|
|
2
|
+
export { D as DEFAULT_LIMITS, E as EvalContext, c as JsonPrimitive, M as MAPPING_OPS, N as NodeSchema, d as OP_KEYS, e as OptimizationStats, f as ValidationIssue } from './profiles-C6r-x-Vj.js';
|
|
1
3
|
import { C as Config } from './config.schema-vy-_YxHP.js';
|
|
2
4
|
export { a as ConfigSchema } from './config.schema-vy-_YxHP.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type Limits = {
|
|
6
|
-
maxSteps: number;
|
|
7
|
-
maxStringLength: number;
|
|
8
|
-
maxValues: number;
|
|
9
|
-
};
|
|
10
|
-
declare const DEFAULT_LIMITS: Limits;
|
|
11
|
-
type Budget = {
|
|
12
|
-
readonly limits: Limits;
|
|
13
|
-
steps: number;
|
|
14
|
-
readonly sizes: WeakMap<object, number>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type JsonPrimitive = string | number | boolean | null;
|
|
18
|
-
type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
|
|
19
|
-
type JsonObject = {
|
|
20
|
-
[key: string]: JsonValue;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
type EvalContext = {
|
|
24
|
-
readonly source: JsonValue;
|
|
25
|
-
readonly vars: Record<string, JsonValue>;
|
|
26
|
-
readonly budget?: Budget;
|
|
27
|
-
};
|
|
28
|
-
type Result<T> = {
|
|
29
|
-
ok: true;
|
|
30
|
-
data: T;
|
|
31
|
-
} | {
|
|
32
|
-
ok: false;
|
|
33
|
-
error: Error;
|
|
34
|
-
};
|
|
35
|
-
type CompileOptions = {
|
|
36
|
-
name?: string;
|
|
37
|
-
version?: string;
|
|
38
|
-
};
|
|
39
|
-
type OptimizationStats = {
|
|
40
|
-
refsInlined: number;
|
|
41
|
-
handlersAttached: number;
|
|
42
|
-
constantsFolded: number;
|
|
43
|
-
};
|
|
44
|
-
type CompiledIr = {
|
|
45
|
-
irVersion: 1;
|
|
46
|
-
compiler: {
|
|
47
|
-
name: string;
|
|
48
|
-
version: string;
|
|
49
|
-
};
|
|
50
|
-
meta: {
|
|
51
|
-
name?: string;
|
|
52
|
-
createdAt: string;
|
|
53
|
-
fingerprint: string;
|
|
54
|
-
stats: {
|
|
55
|
-
nodeCount: number;
|
|
56
|
-
opCount: Record<string, number>;
|
|
57
|
-
maxDepth: number;
|
|
58
|
-
optimizations: OptimizationStats;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
tables: {
|
|
62
|
-
paths: string[];
|
|
63
|
-
strings: string[];
|
|
64
|
-
};
|
|
65
|
-
core: unknown;
|
|
66
|
-
};
|
|
67
|
-
type ValidationIssue = {
|
|
68
|
-
path: (string | number)[];
|
|
69
|
-
message: string;
|
|
70
|
-
};
|
|
71
|
-
type ValidationResult = {
|
|
72
|
-
ok: true;
|
|
73
|
-
data: unknown;
|
|
74
|
-
} | {
|
|
75
|
-
ok: false;
|
|
76
|
-
issues: ValidationIssue[];
|
|
77
|
-
};
|
|
5
|
+
export { p as prismTransform } from './transform-DcVcOBzQ.js';
|
|
6
|
+
import 'zod';
|
|
78
7
|
|
|
79
8
|
declare const evaluate: (config: Config, source: JsonValue, limits?: Partial<Limits>) => JsonValue;
|
|
80
9
|
declare const evaluateSafe: (config: Config, source: JsonValue, limits?: Partial<Limits>) => Result<JsonValue>;
|
|
@@ -85,12 +14,6 @@ declare const execute: (ir: CompiledIr, source: JsonObject, limits?: Partial<Lim
|
|
|
85
14
|
|
|
86
15
|
declare const validate: (config: unknown) => ValidationResult;
|
|
87
16
|
|
|
88
|
-
declare const OP_KEYS: readonly ["$ref", "$const", "$var", "$get", "$with", "$map", "$filter", "$reduce", "$slice", "$flatten", "$unique", "$sortBy", "$add", "$sub", "$mul", "$div", "$round", "$fill", "$join", "$toString", "$interpolate", "$trim", "$lower", "$upper", "$split", "$replace", "$eq", "$neq", "$gt", "$gte", "$lt", "$lte", "$empty", "$startsWith", "$endsWith", "$contains", "$not", "$and", "$or", "$merge", "$coalesce", "$case", "$entriesOf", "$keyBy", "$groupBy", "$keys", "$values", "$fromEntries", "$pick", "$omit", "$type", "$length", "$date", "$dateAdd", "$dateDiff", "$localeDate", "$localeMoney", "$localeNumber", "$sum", "$avg", "$count", "$min", "$max", "$pluck", "$take", "$drop", "$match", "$flatMap", "$has", "$renameKeys", "$update", "$assert", "$walk"];
|
|
89
|
-
declare const NodeSchema: z.ZodType<unknown>;
|
|
90
|
-
|
|
91
|
-
type OpKey = (typeof OP_KEYS)[number];
|
|
92
|
-
declare const MAPPING_OPS: readonly OpKey[];
|
|
93
|
-
|
|
94
17
|
type JsonSchemaTarget = 'draft-2020-12' | 'draft-7' | 'draft-4';
|
|
95
18
|
declare const getNodeJsonSchema: (target?: JsonSchemaTarget) => object;
|
|
96
19
|
declare const getConfigJsonSchema: (target?: JsonSchemaTarget) => object;
|
|
@@ -119,4 +42,4 @@ declare class PrismError extends Error {
|
|
|
119
42
|
constructor(message: string, code: ErrorCode, context?: PrismErrorContext);
|
|
120
43
|
}
|
|
121
44
|
|
|
122
|
-
export {
|
|
45
|
+
export { CompileOptions, CompiledIr, Config, ErrorCode, JsonObject, type JsonSchemaTarget, JsonValue, Limits, OpKey, PrismError, type PrismErrorContext, Result, ValidationResult, compile, evaluate, evaluateSafe, execute, getConfigJsonSchema, getNodeJsonSchema, getProfileJsonSchema, validate };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { MAPPING_OPS, getConfigJsonSchema, getNodeJsonSchema, getProfileJsonSchema } from './chunk-
|
|
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-
|
|
3
|
-
export { DEFAULT_LIMITS, ErrorCode, PrismError, evaluate, evaluateSafe } from './chunk-
|
|
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-
|
|
5
|
-
export { ConfigSchema, NodeSchema } from './chunk-
|
|
1
|
+
export { MAPPING_OPS, getConfigJsonSchema, getNodeJsonSchema, getProfileJsonSchema } from './chunk-XRK55NPE.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-VC4PRB4H.js';
|
|
3
|
+
export { DEFAULT_LIMITS, ErrorCode, PrismError, evaluate, evaluateSafe, prismTransform } from './chunk-VC4PRB4H.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-O3OJAQWA.js';
|
|
5
|
+
export { ConfigSchema, NodeSchema, OP_KEYS } from './chunk-O3OJAQWA.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
|
|
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
|
|
605
|
-
//
|
|
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(
|
|
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);
|
|
@@ -1757,6 +1759,23 @@ var evaluate = (config, source, limits) => {
|
|
|
1757
1759
|
return result;
|
|
1758
1760
|
};
|
|
1759
1761
|
|
|
1762
|
+
// src/engine/transform.ts
|
|
1763
|
+
var isJsonValue = (value) => {
|
|
1764
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
1765
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
1766
|
+
if (Array.isArray(value)) return value.every(isJsonValue);
|
|
1767
|
+
if (typeof value === "object") return Object.values(value).every(isJsonValue);
|
|
1768
|
+
return false;
|
|
1769
|
+
};
|
|
1770
|
+
var parsedConfigs = /* @__PURE__ */ new WeakMap();
|
|
1771
|
+
var prismTransform = (config, source) => {
|
|
1772
|
+
if (!isJsonValue(source)) throw new Error("The source of a transform must be plain JSON.");
|
|
1773
|
+
const cached = typeof config === "object" && config !== null ? parsedConfigs.get(config) : void 0;
|
|
1774
|
+
const parsed = cached ?? ConfigSchema.parse(config);
|
|
1775
|
+
if (cached === void 0 && typeof config === "object" && config !== null) parsedConfigs.set(config, parsed);
|
|
1776
|
+
return evaluate(parsed, source);
|
|
1777
|
+
};
|
|
1778
|
+
|
|
1760
1779
|
// src/migrations/index.ts
|
|
1761
1780
|
var PRISM_SEQUENCE = {
|
|
1762
1781
|
id: "nisc.prism",
|
|
@@ -1769,24 +1788,19 @@ var PRISM_SEQUENCE = {
|
|
|
1769
1788
|
// five new op names are no longer accepted as plain template keys.
|
|
1770
1789
|
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
1790
|
steps: []
|
|
1791
|
+
},
|
|
1792
|
+
{
|
|
1793
|
+
// A MARKER for a NARROWING, and a breaking release (approved): a `$` key
|
|
1794
|
+
// that is not an op was accepted as a template key and refused when it
|
|
1795
|
+
// was evaluated (E_NODE_SHAPE). No step rewrites one — it never evaluated
|
|
1796
|
+
// to anything, so there is nothing to rewrite it to. Checked against the
|
|
1797
|
+
// corpus: no captured config uses one. What it can break is a config
|
|
1798
|
+
// that kept such a key where evaluation never reached it.
|
|
1799
|
+
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',
|
|
1800
|
+
steps: []
|
|
1772
1801
|
}
|
|
1773
1802
|
]
|
|
1774
1803
|
};
|
|
1775
|
-
var isJsonValue = (value) => {
|
|
1776
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
1777
|
-
if (typeof value === "number") return Number.isFinite(value);
|
|
1778
|
-
if (Array.isArray(value)) return value.every(isJsonValue);
|
|
1779
|
-
if (typeof value === "object") return Object.values(value).every(isJsonValue);
|
|
1780
|
-
return false;
|
|
1781
|
-
};
|
|
1782
|
-
var parsedConfigs = /* @__PURE__ */ new WeakMap();
|
|
1783
|
-
var prismTransform = (config, source) => {
|
|
1784
|
-
if (!isJsonValue(source)) throw new Error("A document to migrate must be plain JSON.");
|
|
1785
|
-
const cached = typeof config === "object" && config !== null ? parsedConfigs.get(config) : void 0;
|
|
1786
|
-
const parsed = cached ?? ConfigSchema.parse(config);
|
|
1787
|
-
if (cached === void 0 && typeof config === "object" && config !== null) parsedConfigs.set(config, parsed);
|
|
1788
|
-
return evaluate(parsed, source);
|
|
1789
|
-
};
|
|
1790
1804
|
var PRISM_SCHEMAS = { "nisc.prism/config": ConfigSchema };
|
|
1791
1805
|
|
|
1792
1806
|
exports.PRISM_SCHEMAS = PRISM_SCHEMAS;
|