typebars 1.0.19 → 1.0.20
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/cjs/utils.js +1 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/utils.js +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get LRUCache(){return LRUCache},get aggregateArrayAnalysis(){return aggregateArrayAnalysis},get aggregateArrayAnalysisAndExecution(){return aggregateArrayAnalysisAndExecution},get aggregateObjectAnalysis(){return aggregateObjectAnalysis},get aggregateObjectAnalysisAndExecution(){return aggregateObjectAnalysisAndExecution},get deepEqual(){return deepEqual},get extractSourceSnippet(){return extractSourceSnippet},get getSchemaPropertyNames(){return getSchemaPropertyNames}});function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function deepEqual(a,b){if(a===b)return true;if(a===null||b===null)return false;if(typeof a!==typeof b)return false;if(Array.isArray(a)){if(!Array.isArray(b))return false;if(a.length!==b.length)return false;for(let i=0;i<a.length;i++){if(!deepEqual(a[i],b[i]))return false}return true}if(typeof a==="object"){const objA=a;const objB=b;const keysA=Object.keys(objA);const keysB=Object.keys(objB);if(keysA.length!==keysB.length)return false;for(const key of keysA){if(!(key in objB)||!deepEqual(objA[key],objB[key]))return false}return true}return false}class LRUCache{get(key){if(!this.cache.has(key))return undefined;const value=this.cache.get(key);this.cache.delete(key);this.cache.set(key,value);return value}set(key,value){if(this.cache.has(key)){this.cache.delete(key)}else if(this.cache.size>=this.capacity){const oldestKey=this.cache.keys().next().value;if(oldestKey!==undefined){this.cache.delete(oldestKey)}}this.cache.set(key,value)}has(key){return this.cache.has(key)}delete(key){return this.cache.delete(key)}clear(){this.cache.clear()}get size(){return this.cache.size}constructor(capacity){_define_property(this,"capacity",void 0);_define_property(this,"cache",void 0);this.capacity=capacity;this.cache=new Map;if(capacity<1){throw new Error("LRUCache capacity must be at least 1")}}}function extractSourceSnippet(template,loc){const lines=template.split("\n");const startLine=loc.start.line-1;const endLine=loc.end.line-1;if(startLine<0||startLine>=lines.length)return"";if(startLine===endLine){const line=lines[startLine]??"";return line.trim()}const clampedEnd=Math.min(endLine,lines.length-1);return lines.slice(startLine,clampedEnd+1).map(l=>l.trimEnd()).join("\n").trim()}function getSchemaPropertyNames(schema){const names=new Set;if(schema.properties){for(const key of Object.keys(schema.properties)){names.add(key)}}for(const combinator of["allOf","anyOf","oneOf"]){const branches=schema[combinator];if(branches){for(const branch of branches){if(typeof branch==="boolean")continue;if(branch.properties){for(const key of Object.keys(branch.properties)){names.add(key)}}}}}return Array.from(names).sort()}function aggregateObjectAnalysis(keys,analyzeEntry){const allDiagnostics=[];const properties={};let allValid=true;for(const key of keys){const child=analyzeEntry(key);if(!child.valid)allValid=false;allDiagnostics.push(...child.diagnostics);properties[key]=child.outputSchema}return{valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"object",properties,required:keys}}}function aggregateObjectAnalysisAndExecution(keys,processEntry){const allDiagnostics=[];const properties={};const resultValues={};let allValid=true;for(const key of keys){const child=processEntry(key);if(!child.analysis.valid)allValid=false;allDiagnostics.push(...child.analysis.diagnostics);properties[key]=child.analysis.outputSchema;resultValues[key]=child.value}const analysis={valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"object",properties,required:keys}};return{analysis,value:allValid?resultValues:undefined}}function computeArrayItemsSchema(elementSchemas){if(elementSchemas.length===0)return{};const unique=[];for(const schema of elementSchemas){if(!unique.some(u=>deepEqual(u,schema))){unique.push(schema)}}if(unique.length===1){return unique[0]}return{oneOf:unique}}function aggregateArrayAnalysis(length,analyzeEntry){const allDiagnostics=[];const elementSchemas=[];let allValid=true;for(let i=0;i<length;i++){const child=analyzeEntry(i);if(!child.valid)allValid=false;allDiagnostics.push(...child.diagnostics);elementSchemas.push(child.outputSchema)}return{valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"array",items:computeArrayItemsSchema(elementSchemas)}}}function aggregateArrayAnalysisAndExecution(length,processEntry){const allDiagnostics=[];const elementSchemas=[];const resultValues=[];let allValid=true;for(let i=0;i<length;i++){const child=processEntry(i);if(!child.analysis.valid)allValid=false;allDiagnostics.push(...child.analysis.diagnostics);elementSchemas.push(child.analysis.outputSchema);resultValues.push(child.value)}const analysis={valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"array",items:computeArrayItemsSchema(elementSchemas)}};return{analysis,value:allValid?resultValues:undefined}}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get LRUCache(){return LRUCache},get aggregateArrayAnalysis(){return aggregateArrayAnalysis},get aggregateArrayAnalysisAndExecution(){return aggregateArrayAnalysisAndExecution},get aggregateObjectAnalysis(){return aggregateObjectAnalysis},get aggregateObjectAnalysisAndExecution(){return aggregateObjectAnalysisAndExecution},get deepEqual(){return deepEqual},get extractSourceSnippet(){return extractSourceSnippet},get getSchemaPropertyNames(){return getSchemaPropertyNames}});function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function deepEqual(a,b){if(a===b)return true;if(a===null||b===null)return false;if(typeof a!==typeof b)return false;if(Array.isArray(a)){if(!Array.isArray(b))return false;if(a.length!==b.length)return false;for(let i=0;i<a.length;i++){if(!deepEqual(a[i],b[i]))return false}return true}if(typeof a==="object"){const objA=a;const objB=b;const keysA=Object.keys(objA);const keysB=Object.keys(objB);if(keysA.length!==keysB.length)return false;for(const key of keysA){if(!(key in objB)||!deepEqual(objA[key],objB[key]))return false}return true}return false}class LRUCache{get(key){if(!this.cache.has(key))return undefined;const value=this.cache.get(key);this.cache.delete(key);this.cache.set(key,value);return value}set(key,value){if(this.cache.has(key)){this.cache.delete(key)}else if(this.cache.size>=this.capacity){const oldestKey=this.cache.keys().next().value;if(oldestKey!==undefined){this.cache.delete(oldestKey)}}this.cache.set(key,value)}has(key){return this.cache.has(key)}delete(key){return this.cache.delete(key)}clear(){this.cache.clear()}get size(){return this.cache.size}constructor(capacity){_define_property(this,"capacity",void 0);_define_property(this,"cache",void 0);this.capacity=capacity;this.cache=new Map;if(capacity<1){throw new Error("LRUCache capacity must be at least 1")}}}function extractSourceSnippet(template,loc){const lines=template.split("\n");const startLine=loc.start.line-1;const endLine=loc.end.line-1;if(startLine<0||startLine>=lines.length)return"";if(startLine===endLine){const line=lines[startLine]??"";return line.trim()}const clampedEnd=Math.min(endLine,lines.length-1);return lines.slice(startLine,clampedEnd+1).map(l=>l.trimEnd()).join("\n").trim()}function getSchemaPropertyNames(schema){const names=new Set;if(schema.properties){for(const key of Object.keys(schema.properties)){names.add(key)}}for(const combinator of["allOf","anyOf","oneOf"]){const branches=schema[combinator];if(branches){for(const branch of branches){if(typeof branch==="boolean")continue;if(branch.properties){for(const key of Object.keys(branch.properties)){names.add(key)}}}}}return Array.from(names).sort()}function aggregateObjectAnalysis(keys,analyzeEntry){const allDiagnostics=[];const properties={};let allValid=true;for(const key of keys){const child=analyzeEntry(key);if(!child.valid)allValid=false;allDiagnostics.push(...child.diagnostics);properties[key]=child.outputSchema}return{valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"object",properties,required:keys}}}function aggregateObjectAnalysisAndExecution(keys,processEntry){const allDiagnostics=[];const properties={};const resultValues={};let allValid=true;for(const key of keys){const child=processEntry(key);if(!child.analysis.valid)allValid=false;allDiagnostics.push(...child.analysis.diagnostics);properties[key]=child.analysis.outputSchema;resultValues[key]=child.value}const analysis={valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"object",properties,required:keys}};return{analysis,value:allValid?resultValues:undefined}}function computeArrayItemsSchema(elementSchemas){if(elementSchemas.length===0)return{};const unique=[];for(const schema of elementSchemas){if(!unique.some(u=>deepEqual(u,schema))){unique.push(schema)}}if(unique.length===1){return unique[0]}return{oneOf:unique}}function aggregateArrayAnalysis(length,analyzeEntry){const allDiagnostics=[];const elementSchemas=[];let allValid=true;for(let i=0;i<length;i++){const child=analyzeEntry(i);if(!child.valid)allValid=false;allDiagnostics.push(...child.diagnostics);elementSchemas.push(child.outputSchema)}return{valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"array",items:computeArrayItemsSchema(elementSchemas),minItems:length,maxItems:length}}}function aggregateArrayAnalysisAndExecution(length,processEntry){const allDiagnostics=[];const elementSchemas=[];const resultValues=[];let allValid=true;for(let i=0;i<length;i++){const child=processEntry(i);if(!child.analysis.valid)allValid=false;allDiagnostics.push(...child.analysis.diagnostics);elementSchemas.push(child.analysis.outputSchema);resultValues.push(child.value)}const analysis={valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"array",items:computeArrayItemsSchema(elementSchemas),minItems:length,maxItems:length}};return{analysis,value:allValid?resultValues:undefined}}
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
package/dist/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport type { AnalysisResult, TemplateDiagnostic } from \"./types.ts\";\n\n// ─── Utilities ───────────────────────────────────────────────────────────────\n// Shared utility functions and classes used across the different modules\n// of the template engine.\n\n// ─── Deep Equality ───────────────────────────────────────────────────────────\n// Deep structural comparison for JSON-compatible values.\n// More robust than `JSON.stringify` because it is independent of key order\n// and does not allocate intermediate strings.\n\n/**\n * Recursively compares two JSON-compatible values.\n *\n * @param a - First value\n * @param b - Second value\n * @returns `true` if the two values are structurally identical\n *\n * @example\n * ```\n * deepEqual({ a: 1, b: 2 }, { b: 2, a: 1 }) // → true\n * deepEqual([1, 2], [1, 2]) // → true\n * deepEqual({ a: 1 }, { a: 2 }) // → false\n * ```\n */\nexport function deepEqual(a: unknown, b: unknown): boolean {\n\t// Strict identity (covers primitives, same ref; NaN !== NaN is intentional)\n\tif (a === b) return true;\n\n\t// null is typeof \"object\" in JS — handle it separately\n\tif (a === null || b === null) return false;\n\tif (typeof a !== typeof b) return false;\n\n\t// ── Arrays ───────────────────────────────────────────────────────────────\n\tif (Array.isArray(a)) {\n\t\tif (!Array.isArray(b)) return false;\n\t\tif (a.length !== b.length) return false;\n\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\tif (!deepEqual(a[i], b[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// ── Objects ──────────────────────────────────────────────────────────────\n\tif (typeof a === \"object\") {\n\t\tconst objA = a as Record<string, unknown>;\n\t\tconst objB = b as Record<string, unknown>;\n\t\tconst keysA = Object.keys(objA);\n\t\tconst keysB = Object.keys(objB);\n\n\t\tif (keysA.length !== keysB.length) return false;\n\n\t\tfor (const key of keysA) {\n\t\t\tif (!(key in objB) || !deepEqual(objA[key], objB[key])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Different primitives (already covered by a === b at the top)\n\treturn false;\n}\n\n// ─── LRU Cache ───────────────────────────────────────────────────────────────\n// Fixed-capacity cache with Least Recently Used (LRU) eviction.\n// Leverages `Map` insertion order to track access: the oldest entry\n// is always in the first position.\n\n/**\n * Simple fixed-capacity LRU cache.\n *\n * @example\n * ```\n * const cache = new LRUCache<string, number>(2);\n * cache.set(\"a\", 1);\n * cache.set(\"b\", 2);\n * cache.get(\"a\"); // → 1 (marks \"a\" as recently used)\n * cache.set(\"c\", 3); // evicts \"b\" (least recently used)\n * cache.get(\"b\"); // → undefined\n * ```\n */\nexport class LRUCache<K, V> {\n\tprivate readonly cache = new Map<K, V>();\n\n\tconstructor(private readonly capacity: number) {\n\t\tif (capacity < 1) {\n\t\t\tthrow new Error(\"LRUCache capacity must be at least 1\");\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves a value from the cache. Returns `undefined` if absent.\n\t * Marks the entry as recently used.\n\t */\n\tget(key: K): V | undefined {\n\t\tif (!this.cache.has(key)) return undefined;\n\n\t\t// Move to the end of the Map (= most recently used)\n\t\tconst value = this.cache.get(key) as V;\n\t\tthis.cache.delete(key);\n\t\tthis.cache.set(key, value);\n\t\treturn value;\n\t}\n\n\t/**\n\t * Inserts or updates a value in the cache.\n\t * If the cache is full, evicts the least recently used entry.\n\t */\n\tset(key: K, value: V): void {\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.delete(key);\n\t\t} else if (this.cache.size >= this.capacity) {\n\t\t\t// Evict the first entry (the oldest one)\n\t\t\tconst oldestKey = this.cache.keys().next().value;\n\t\t\tif (oldestKey !== undefined) {\n\t\t\t\tthis.cache.delete(oldestKey);\n\t\t\t}\n\t\t}\n\t\tthis.cache.set(key, value);\n\t}\n\n\t/**\n\t * Checks whether a key exists in the cache (without affecting LRU order).\n\t */\n\thas(key: K): boolean {\n\t\treturn this.cache.has(key);\n\t}\n\n\t/**\n\t * Removes an entry from the cache.\n\t * @returns `true` if the entry existed and was removed\n\t */\n\tdelete(key: K): boolean {\n\t\treturn this.cache.delete(key);\n\t}\n\n\t/** Clears the entire cache. */\n\tclear(): void {\n\t\tthis.cache.clear();\n\t}\n\n\t/** Number of entries currently in the cache. */\n\tget size(): number {\n\t\treturn this.cache.size;\n\t}\n}\n\n// ─── Source Snippet Extraction ────────────────────────────────────────────────\n// Used to enrich diagnostics with the template fragment that caused the error.\n\n/**\n * Extracts a template fragment around a given position.\n *\n * @param template - The full template source\n * @param loc - The position (line/column, 1-based) of the error\n * @returns The corresponding code fragment (trimmed)\n */\nexport function extractSourceSnippet(\n\ttemplate: string,\n\tloc: {\n\t\tstart: { line: number; column: number };\n\t\tend: { line: number; column: number };\n\t},\n): string {\n\tconst lines = template.split(\"\\n\");\n\tconst startLine = loc.start.line - 1; // 0-based\n\tconst endLine = loc.end.line - 1;\n\n\tif (startLine < 0 || startLine >= lines.length) return \"\";\n\n\tif (startLine === endLine) {\n\t\t// Same line — extract the portion between start.column and end.column\n\t\tconst line = lines[startLine] ?? \"\";\n\t\treturn line.trim();\n\t}\n\n\t// Multi-line — return the affected lines\n\tconst clampedEnd = Math.min(endLine, lines.length - 1);\n\treturn lines\n\t\t.slice(startLine, clampedEnd + 1)\n\t\t.map((l) => l.trimEnd())\n\t\t.join(\"\\n\")\n\t\t.trim();\n}\n\n// ─── Schema Properties ──────────────────────────────────────────────────────\n// Utility for listing available properties in a schema, used to enrich\n// error messages with suggestions.\n\n/**\n * Lists the declared property names in a JSON Schema.\n * Returns an empty array if the schema has no `properties`.\n */\nexport function getSchemaPropertyNames(schema: JSONSchema7): string[] {\n\tconst names = new Set<string>();\n\n\t// Direct properties\n\tif (schema.properties) {\n\t\tfor (const key of Object.keys(schema.properties)) {\n\t\t\tnames.add(key);\n\t\t}\n\t}\n\n\t// Properties within combinators\n\tfor (const combinator of [\"allOf\", \"anyOf\", \"oneOf\"] as const) {\n\t\tconst branches = schema[combinator];\n\t\tif (branches) {\n\t\t\tfor (const branch of branches) {\n\t\t\t\tif (typeof branch === \"boolean\") continue;\n\t\t\t\tif (branch.properties) {\n\t\t\t\t\tfor (const key of Object.keys(branch.properties)) {\n\t\t\t\t\t\tnames.add(key);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Array.from(names).sort();\n}\n\n// ─── Object Analysis Aggregation ─────────────────────────────────────────────\n// Factorizes the common recursion pattern over template objects:\n// iterate the keys, analyze each entry via a callback, accumulate\n// diagnostics, and build the output object schema.\n//\n// Used by:\n// - `analyzer.ts` (analyzeObjectTemplate)\n// - `Typebars.analyzeObject()` (typebars.ts)\n// - `CompiledTemplate.analyze()` in object mode (compiled-template.ts)\n\n/**\n * Aggregates analysis results from a set of named entries into a single\n * `AnalysisResult` with an object-typed `outputSchema`.\n *\n * @param keys - The keys of the object to analyze\n * @param analyzeEntry - Callback that analyzes an entry by its key\n * @returns An aggregated `AnalysisResult`\n *\n * @example\n * ```\n * aggregateObjectAnalysis(\n * Object.keys(template),\n * (key) => analyze(template[key], inputSchema),\n * );\n * ```\n */\nexport function aggregateObjectAnalysis(\n\tkeys: string[],\n\tanalyzeEntry: (key: string) => AnalysisResult,\n): AnalysisResult {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst properties: Record<string, JSONSchema7> = {};\n\tlet allValid = true;\n\n\tfor (const key of keys) {\n\t\tconst child = analyzeEntry(key);\n\t\tif (!child.valid) allValid = false;\n\t\tallDiagnostics.push(...child.diagnostics);\n\t\tproperties[key] = child.outputSchema;\n\t}\n\n\treturn {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired: keys,\n\t\t},\n\t};\n}\n\n/**\n * Aggregates both analysis **and** execution results from a set of named\n * entries. Returns the aggregated `AnalysisResult` and the object of\n * executed values (or `undefined` if at least one entry is invalid).\n *\n * @param keys - The keys of the object\n * @param processEntry - Callback that analyzes and executes an entry by its key\n * @returns Aggregated `{ analysis, value }`\n */\nexport function aggregateObjectAnalysisAndExecution(\n\tkeys: string[],\n\tprocessEntry: (key: string) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst properties: Record<string, JSONSchema7> = {};\n\tconst resultValues: Record<string, unknown> = {};\n\tlet allValid = true;\n\n\tfor (const key of keys) {\n\t\tconst child = processEntry(key);\n\t\tif (!child.analysis.valid) allValid = false;\n\t\tallDiagnostics.push(...child.analysis.diagnostics);\n\t\tproperties[key] = child.analysis.outputSchema;\n\t\tresultValues[key] = child.value;\n\t}\n\n\tconst analysis: AnalysisResult = {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired: keys,\n\t\t},\n\t};\n\n\treturn {\n\t\tanalysis,\n\t\tvalue: allValid ? resultValues : undefined,\n\t};\n}\n\n// ─── Array Analysis Aggregation ──────────────────────────────────────────────\n// Factorizes the common recursion pattern over template arrays:\n// iterate the elements, analyze each entry via a callback, accumulate\n// diagnostics, and build the output array schema with a proper `items`.\n//\n// Used by:\n// - `analyzer.ts` (analyzeArrayTemplate)\n// - `Typebars.analyze()` (typebars.ts)\n// - `CompiledTemplate.analyze()` in array mode (compiled-template.ts)\n\n/**\n * Computes the `items` schema for an array from the output schemas of its\n * elements:\n * - If all elements share the same schema → that schema\n * - If there are multiple distinct schemas → `{ oneOf: [...] }`\n * - If the array is empty → `{}` (any type)\n */\nfunction computeArrayItemsSchema(elementSchemas: JSONSchema7[]): JSONSchema7 {\n\tif (elementSchemas.length === 0) return {};\n\n\t// Deduplicate schemas using deep equality\n\tconst unique: JSONSchema7[] = [];\n\tfor (const schema of elementSchemas) {\n\t\tif (!unique.some((u) => deepEqual(u, schema))) {\n\t\t\tunique.push(schema);\n\t\t}\n\t}\n\n\tif (unique.length === 1) {\n\t\treturn unique[0] as JSONSchema7;\n\t}\n\n\treturn { oneOf: unique };\n}\n\n/**\n * Aggregates analysis results from a set of array elements into a single\n * `AnalysisResult` with an array-typed `outputSchema`.\n *\n * @param length - The number of elements in the array\n * @param analyzeEntry - Callback that analyzes an element by its index\n * @returns An aggregated `AnalysisResult`\n *\n * @example\n * ```\n * aggregateArrayAnalysis(\n * template.length,\n * (index) => analyze(template[index], inputSchema),\n * );\n * ```\n */\nexport function aggregateArrayAnalysis(\n\tlength: number,\n\tanalyzeEntry: (index: number) => AnalysisResult,\n): AnalysisResult {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst elementSchemas: JSONSchema7[] = [];\n\tlet allValid = true;\n\n\tfor (let i = 0; i < length; i++) {\n\t\tconst child = analyzeEntry(i);\n\t\tif (!child.valid) allValid = false;\n\t\tallDiagnostics.push(...child.diagnostics);\n\t\telementSchemas.push(child.outputSchema);\n\t}\n\n\treturn {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"array\",\n\t\t\titems: computeArrayItemsSchema(elementSchemas),\n\t\t},\n\t};\n}\n\n/**\n * Aggregates both analysis **and** execution results from a set of array\n * elements. Returns the aggregated `AnalysisResult` and the array of\n * executed values (or `undefined` if at least one element is invalid).\n *\n * @param length - The number of elements\n * @param processEntry - Callback that analyzes and executes an element by index\n * @returns Aggregated `{ analysis, value }`\n */\nexport function aggregateArrayAnalysisAndExecution(\n\tlength: number,\n\tprocessEntry: (index: number) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst elementSchemas: JSONSchema7[] = [];\n\tconst resultValues: unknown[] = [];\n\tlet allValid = true;\n\n\tfor (let i = 0; i < length; i++) {\n\t\tconst child = processEntry(i);\n\t\tif (!child.analysis.valid) allValid = false;\n\t\tallDiagnostics.push(...child.analysis.diagnostics);\n\t\telementSchemas.push(child.analysis.outputSchema);\n\t\tresultValues.push(child.value);\n\t}\n\n\tconst analysis: AnalysisResult = {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"array\",\n\t\t\titems: computeArrayItemsSchema(elementSchemas),\n\t\t},\n\t};\n\n\treturn {\n\t\tanalysis,\n\t\tvalue: allValid ? resultValues : undefined,\n\t};\n}\n"],"names":["LRUCache","aggregateArrayAnalysis","aggregateArrayAnalysisAndExecution","aggregateObjectAnalysis","aggregateObjectAnalysisAndExecution","deepEqual","extractSourceSnippet","getSchemaPropertyNames","a","b","Array","isArray","length","i","objA","objB","keysA","Object","keys","keysB","key","get","cache","has","undefined","value","delete","set","size","capacity","oldestKey","next","clear","Map","Error","template","loc","lines","split","startLine","start","line","endLine","end","trim","clampedEnd","Math","min","slice","map","l","trimEnd","join","schema","names","Set","properties","add","combinator","branches","branch","from","sort","analyzeEntry","allDiagnostics","allValid","child","valid","push","diagnostics","outputSchema","type","required","processEntry","resultValues","analysis","computeArrayItemsSchema","elementSchemas","unique","some","u","oneOf","items"],"mappings":"mPAiFaA,kBAAAA,cA6RGC,gCAAAA,4BAkCAC,4CAAAA,wCAzJAC,iCAAAA,6BAmCAC,6CAAAA,yCAhQAC,mBAAAA,eAmIAC,8BAAAA,0BAoCAC,gCAAAA,8MAvKT,SAASF,UAAUG,CAAU,CAAEC,CAAU,EAE/C,GAAID,IAAMC,EAAG,OAAO,KAGpB,GAAID,IAAM,MAAQC,IAAM,KAAM,OAAO,MACrC,GAAI,OAAOD,IAAM,OAAOC,EAAG,OAAO,MAGlC,GAAIC,MAAMC,OAAO,CAACH,GAAI,CACrB,GAAI,CAACE,MAAMC,OAAO,CAACF,GAAI,OAAO,MAC9B,GAAID,EAAEI,MAAM,GAAKH,EAAEG,MAAM,CAAE,OAAO,MAClC,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAAEI,MAAM,CAAEC,IAAK,CAClC,GAAI,CAACR,UAAUG,CAAC,CAACK,EAAE,CAAEJ,CAAC,CAACI,EAAE,EAAG,OAAO,KACpC,CACA,OAAO,IACR,CAGA,GAAI,OAAOL,IAAM,SAAU,CAC1B,MAAMM,KAAON,EACb,MAAMO,KAAON,EACb,MAAMO,MAAQC,OAAOC,IAAI,CAACJ,MAC1B,MAAMK,MAAQF,OAAOC,IAAI,CAACH,MAE1B,GAAIC,MAAMJ,MAAM,GAAKO,MAAMP,MAAM,CAAE,OAAO,MAE1C,IAAK,MAAMQ,OAAOJ,MAAO,CACxB,GAAI,CAAEI,CAAAA,OAAOL,IAAG,GAAM,CAACV,UAAUS,IAAI,CAACM,IAAI,CAAEL,IAAI,CAACK,IAAI,EAAG,OAAO,KAChE,CACA,OAAO,IACR,CAGA,OAAO,KACR,CAoBO,MAAMpB,SAaZqB,IAAID,GAAM,CA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B,CAkBO,SAAS7E,uBACfW,MAAc,CACdmD,YAA+C,EAE/C,MAAMC,eAAuC,EAAE,CAC/C,MAAMa,eAAgC,EAAE,CACxC,IAAIZ,SAAW,KAEf,IAAK,IAAIpD,EAAI,EAAGA,EAAID,OAAQC,IAAK,CAChC,MAAMqD,MAAQH,aAAalD,GAC3B,GAAI,CAACqD,MAAMC,KAAK,CAAEF,SAAW,MAC7BD,eAAeI,IAAI,IAAIF,MAAMG,WAAW,EACxCQ,eAAeT,IAAI,CAACF,MAAMI,YAAY,CACvC,CAEA,MAAO,CACNH,MAAOF,SACPI,YAAaL,eACbM,aAAc,CACbC,KAAM,QACNW,MAAON,wBAAwBC,eAChC,CACD,CACD,CAWO,SAAS3E,mCACfU,MAAc,CACd6D,YAA6E,EAE7E,MAAMT,eAAuC,EAAE,CAC/C,MAAMa,eAAgC,EAAE,CACxC,MAAMH,aAA0B,EAAE,CAClC,IAAIT,SAAW,KAEf,IAAK,IAAIpD,EAAI,EAAGA,EAAID,OAAQC,IAAK,CAChC,MAAMqD,MAAQO,aAAa5D,GAC3B,GAAI,CAACqD,MAAMS,QAAQ,CAACR,KAAK,CAAEF,SAAW,MACtCD,eAAeI,IAAI,IAAIF,MAAMS,QAAQ,CAACN,WAAW,EACjDQ,eAAeT,IAAI,CAACF,MAAMS,QAAQ,CAACL,YAAY,EAC/CI,aAAaN,IAAI,CAACF,MAAMzC,KAAK,CAC9B,CAEA,MAAMkD,SAA2B,CAChCR,MAAOF,SACPI,YAAaL,eACbM,aAAc,CACbC,KAAM,QACNW,MAAON,wBAAwBC,eAChC,CACD,EAEA,MAAO,CACNF,SACAlD,MAAOwC,SAAWS,aAAelD,SAClC,CACD"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport type { AnalysisResult, TemplateDiagnostic } from \"./types.ts\";\n\n// ─── Utilities ───────────────────────────────────────────────────────────────\n// Shared utility functions and classes used across the different modules\n// of the template engine.\n\n// ─── Deep Equality ───────────────────────────────────────────────────────────\n// Deep structural comparison for JSON-compatible values.\n// More robust than `JSON.stringify` because it is independent of key order\n// and does not allocate intermediate strings.\n\n/**\n * Recursively compares two JSON-compatible values.\n *\n * @param a - First value\n * @param b - Second value\n * @returns `true` if the two values are structurally identical\n *\n * @example\n * ```\n * deepEqual({ a: 1, b: 2 }, { b: 2, a: 1 }) // → true\n * deepEqual([1, 2], [1, 2]) // → true\n * deepEqual({ a: 1 }, { a: 2 }) // → false\n * ```\n */\nexport function deepEqual(a: unknown, b: unknown): boolean {\n\t// Strict identity (covers primitives, same ref; NaN !== NaN is intentional)\n\tif (a === b) return true;\n\n\t// null is typeof \"object\" in JS — handle it separately\n\tif (a === null || b === null) return false;\n\tif (typeof a !== typeof b) return false;\n\n\t// ── Arrays ───────────────────────────────────────────────────────────────\n\tif (Array.isArray(a)) {\n\t\tif (!Array.isArray(b)) return false;\n\t\tif (a.length !== b.length) return false;\n\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\tif (!deepEqual(a[i], b[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// ── Objects ──────────────────────────────────────────────────────────────\n\tif (typeof a === \"object\") {\n\t\tconst objA = a as Record<string, unknown>;\n\t\tconst objB = b as Record<string, unknown>;\n\t\tconst keysA = Object.keys(objA);\n\t\tconst keysB = Object.keys(objB);\n\n\t\tif (keysA.length !== keysB.length) return false;\n\n\t\tfor (const key of keysA) {\n\t\t\tif (!(key in objB) || !deepEqual(objA[key], objB[key])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Different primitives (already covered by a === b at the top)\n\treturn false;\n}\n\n// ─── LRU Cache ───────────────────────────────────────────────────────────────\n// Fixed-capacity cache with Least Recently Used (LRU) eviction.\n// Leverages `Map` insertion order to track access: the oldest entry\n// is always in the first position.\n\n/**\n * Simple fixed-capacity LRU cache.\n *\n * @example\n * ```\n * const cache = new LRUCache<string, number>(2);\n * cache.set(\"a\", 1);\n * cache.set(\"b\", 2);\n * cache.get(\"a\"); // → 1 (marks \"a\" as recently used)\n * cache.set(\"c\", 3); // evicts \"b\" (least recently used)\n * cache.get(\"b\"); // → undefined\n * ```\n */\nexport class LRUCache<K, V> {\n\tprivate readonly cache = new Map<K, V>();\n\n\tconstructor(private readonly capacity: number) {\n\t\tif (capacity < 1) {\n\t\t\tthrow new Error(\"LRUCache capacity must be at least 1\");\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves a value from the cache. Returns `undefined` if absent.\n\t * Marks the entry as recently used.\n\t */\n\tget(key: K): V | undefined {\n\t\tif (!this.cache.has(key)) return undefined;\n\n\t\t// Move to the end of the Map (= most recently used)\n\t\tconst value = this.cache.get(key) as V;\n\t\tthis.cache.delete(key);\n\t\tthis.cache.set(key, value);\n\t\treturn value;\n\t}\n\n\t/**\n\t * Inserts or updates a value in the cache.\n\t * If the cache is full, evicts the least recently used entry.\n\t */\n\tset(key: K, value: V): void {\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.delete(key);\n\t\t} else if (this.cache.size >= this.capacity) {\n\t\t\t// Evict the first entry (the oldest one)\n\t\t\tconst oldestKey = this.cache.keys().next().value;\n\t\t\tif (oldestKey !== undefined) {\n\t\t\t\tthis.cache.delete(oldestKey);\n\t\t\t}\n\t\t}\n\t\tthis.cache.set(key, value);\n\t}\n\n\t/**\n\t * Checks whether a key exists in the cache (without affecting LRU order).\n\t */\n\thas(key: K): boolean {\n\t\treturn this.cache.has(key);\n\t}\n\n\t/**\n\t * Removes an entry from the cache.\n\t * @returns `true` if the entry existed and was removed\n\t */\n\tdelete(key: K): boolean {\n\t\treturn this.cache.delete(key);\n\t}\n\n\t/** Clears the entire cache. */\n\tclear(): void {\n\t\tthis.cache.clear();\n\t}\n\n\t/** Number of entries currently in the cache. */\n\tget size(): number {\n\t\treturn this.cache.size;\n\t}\n}\n\n// ─── Source Snippet Extraction ────────────────────────────────────────────────\n// Used to enrich diagnostics with the template fragment that caused the error.\n\n/**\n * Extracts a template fragment around a given position.\n *\n * @param template - The full template source\n * @param loc - The position (line/column, 1-based) of the error\n * @returns The corresponding code fragment (trimmed)\n */\nexport function extractSourceSnippet(\n\ttemplate: string,\n\tloc: {\n\t\tstart: { line: number; column: number };\n\t\tend: { line: number; column: number };\n\t},\n): string {\n\tconst lines = template.split(\"\\n\");\n\tconst startLine = loc.start.line - 1; // 0-based\n\tconst endLine = loc.end.line - 1;\n\n\tif (startLine < 0 || startLine >= lines.length) return \"\";\n\n\tif (startLine === endLine) {\n\t\t// Same line — extract the portion between start.column and end.column\n\t\tconst line = lines[startLine] ?? \"\";\n\t\treturn line.trim();\n\t}\n\n\t// Multi-line — return the affected lines\n\tconst clampedEnd = Math.min(endLine, lines.length - 1);\n\treturn lines\n\t\t.slice(startLine, clampedEnd + 1)\n\t\t.map((l) => l.trimEnd())\n\t\t.join(\"\\n\")\n\t\t.trim();\n}\n\n// ─── Schema Properties ──────────────────────────────────────────────────────\n// Utility for listing available properties in a schema, used to enrich\n// error messages with suggestions.\n\n/**\n * Lists the declared property names in a JSON Schema.\n * Returns an empty array if the schema has no `properties`.\n */\nexport function getSchemaPropertyNames(schema: JSONSchema7): string[] {\n\tconst names = new Set<string>();\n\n\t// Direct properties\n\tif (schema.properties) {\n\t\tfor (const key of Object.keys(schema.properties)) {\n\t\t\tnames.add(key);\n\t\t}\n\t}\n\n\t// Properties within combinators\n\tfor (const combinator of [\"allOf\", \"anyOf\", \"oneOf\"] as const) {\n\t\tconst branches = schema[combinator];\n\t\tif (branches) {\n\t\t\tfor (const branch of branches) {\n\t\t\t\tif (typeof branch === \"boolean\") continue;\n\t\t\t\tif (branch.properties) {\n\t\t\t\t\tfor (const key of Object.keys(branch.properties)) {\n\t\t\t\t\t\tnames.add(key);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Array.from(names).sort();\n}\n\n// ─── Object Analysis Aggregation ─────────────────────────────────────────────\n// Factorizes the common recursion pattern over template objects:\n// iterate the keys, analyze each entry via a callback, accumulate\n// diagnostics, and build the output object schema.\n//\n// Used by:\n// - `analyzer.ts` (analyzeObjectTemplate)\n// - `Typebars.analyzeObject()` (typebars.ts)\n// - `CompiledTemplate.analyze()` in object mode (compiled-template.ts)\n\n/**\n * Aggregates analysis results from a set of named entries into a single\n * `AnalysisResult` with an object-typed `outputSchema`.\n *\n * @param keys - The keys of the object to analyze\n * @param analyzeEntry - Callback that analyzes an entry by its key\n * @returns An aggregated `AnalysisResult`\n *\n * @example\n * ```\n * aggregateObjectAnalysis(\n * Object.keys(template),\n * (key) => analyze(template[key], inputSchema),\n * );\n * ```\n */\nexport function aggregateObjectAnalysis(\n\tkeys: string[],\n\tanalyzeEntry: (key: string) => AnalysisResult,\n): AnalysisResult {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst properties: Record<string, JSONSchema7> = {};\n\tlet allValid = true;\n\n\tfor (const key of keys) {\n\t\tconst child = analyzeEntry(key);\n\t\tif (!child.valid) allValid = false;\n\t\tallDiagnostics.push(...child.diagnostics);\n\t\tproperties[key] = child.outputSchema;\n\t}\n\n\treturn {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired: keys,\n\t\t},\n\t};\n}\n\n/**\n * Aggregates both analysis **and** execution results from a set of named\n * entries. Returns the aggregated `AnalysisResult` and the object of\n * executed values (or `undefined` if at least one entry is invalid).\n *\n * @param keys - The keys of the object\n * @param processEntry - Callback that analyzes and executes an entry by its key\n * @returns Aggregated `{ analysis, value }`\n */\nexport function aggregateObjectAnalysisAndExecution(\n\tkeys: string[],\n\tprocessEntry: (key: string) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst properties: Record<string, JSONSchema7> = {};\n\tconst resultValues: Record<string, unknown> = {};\n\tlet allValid = true;\n\n\tfor (const key of keys) {\n\t\tconst child = processEntry(key);\n\t\tif (!child.analysis.valid) allValid = false;\n\t\tallDiagnostics.push(...child.analysis.diagnostics);\n\t\tproperties[key] = child.analysis.outputSchema;\n\t\tresultValues[key] = child.value;\n\t}\n\n\tconst analysis: AnalysisResult = {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired: keys,\n\t\t},\n\t};\n\n\treturn {\n\t\tanalysis,\n\t\tvalue: allValid ? resultValues : undefined,\n\t};\n}\n\n// ─── Array Analysis Aggregation ──────────────────────────────────────────────\n// Factorizes the common recursion pattern over template arrays:\n// iterate the elements, analyze each entry via a callback, accumulate\n// diagnostics, and build the output array schema with a proper `items`.\n//\n// Used by:\n// - `analyzer.ts` (analyzeArrayTemplate)\n// - `Typebars.analyze()` (typebars.ts)\n// - `CompiledTemplate.analyze()` in array mode (compiled-template.ts)\n\n/**\n * Computes the `items` schema for an array from the output schemas of its\n * elements:\n * - If all elements share the same schema → that schema\n * - If there are multiple distinct schemas → `{ oneOf: [...] }`\n * - If the array is empty → `{}` (any type)\n */\nfunction computeArrayItemsSchema(elementSchemas: JSONSchema7[]): JSONSchema7 {\n\tif (elementSchemas.length === 0) return {};\n\n\t// Deduplicate schemas using deep equality\n\tconst unique: JSONSchema7[] = [];\n\tfor (const schema of elementSchemas) {\n\t\tif (!unique.some((u) => deepEqual(u, schema))) {\n\t\t\tunique.push(schema);\n\t\t}\n\t}\n\n\tif (unique.length === 1) {\n\t\treturn unique[0] as JSONSchema7;\n\t}\n\n\treturn { oneOf: unique };\n}\n\n/**\n * Aggregates analysis results from a set of array elements into a single\n * `AnalysisResult` with an array-typed `outputSchema`.\n *\n * @param length - The number of elements in the array\n * @param analyzeEntry - Callback that analyzes an element by its index\n * @returns An aggregated `AnalysisResult`\n *\n * @example\n * ```\n * aggregateArrayAnalysis(\n * template.length,\n * (index) => analyze(template[index], inputSchema),\n * );\n * ```\n */\nexport function aggregateArrayAnalysis(\n\tlength: number,\n\tanalyzeEntry: (index: number) => AnalysisResult,\n): AnalysisResult {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst elementSchemas: JSONSchema7[] = [];\n\tlet allValid = true;\n\n\tfor (let i = 0; i < length; i++) {\n\t\tconst child = analyzeEntry(i);\n\t\tif (!child.valid) allValid = false;\n\t\tallDiagnostics.push(...child.diagnostics);\n\t\telementSchemas.push(child.outputSchema);\n\t}\n\n\treturn {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"array\",\n\t\t\titems: computeArrayItemsSchema(elementSchemas),\n\t\t\tminItems: length,\n\t\t\tmaxItems: length,\n\t\t},\n\t};\n}\n\n/**\n * Aggregates both analysis **and** execution results from a set of array\n * elements. Returns the aggregated `AnalysisResult` and the array of\n * executed values (or `undefined` if at least one element is invalid).\n *\n * @param length - The number of elements\n * @param processEntry - Callback that analyzes and executes an element by index\n * @returns Aggregated `{ analysis, value }`\n */\nexport function aggregateArrayAnalysisAndExecution(\n\tlength: number,\n\tprocessEntry: (index: number) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst elementSchemas: JSONSchema7[] = [];\n\tconst resultValues: unknown[] = [];\n\tlet allValid = true;\n\n\tfor (let i = 0; i < length; i++) {\n\t\tconst child = processEntry(i);\n\t\tif (!child.analysis.valid) allValid = false;\n\t\tallDiagnostics.push(...child.analysis.diagnostics);\n\t\telementSchemas.push(child.analysis.outputSchema);\n\t\tresultValues.push(child.value);\n\t}\n\n\tconst analysis: AnalysisResult = {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"array\",\n\t\t\titems: computeArrayItemsSchema(elementSchemas),\n\t\t\tminItems: length,\n\t\t\tmaxItems: length,\n\t\t},\n\t};\n\n\treturn {\n\t\tanalysis,\n\t\tvalue: allValid ? resultValues : undefined,\n\t};\n}\n"],"names":["LRUCache","aggregateArrayAnalysis","aggregateArrayAnalysisAndExecution","aggregateObjectAnalysis","aggregateObjectAnalysisAndExecution","deepEqual","extractSourceSnippet","getSchemaPropertyNames","a","b","Array","isArray","length","i","objA","objB","keysA","Object","keys","keysB","key","get","cache","has","undefined","value","delete","set","size","capacity","oldestKey","next","clear","Map","Error","template","loc","lines","split","startLine","start","line","endLine","end","trim","clampedEnd","Math","min","slice","map","l","trimEnd","join","schema","names","Set","properties","add","combinator","branches","branch","from","sort","analyzeEntry","allDiagnostics","allValid","child","valid","push","diagnostics","outputSchema","type","required","processEntry","resultValues","analysis","computeArrayItemsSchema","elementSchemas","unique","some","u","oneOf","items","minItems","maxItems"],"mappings":"mPAiFaA,kBAAAA,cA6RGC,gCAAAA,4BAoCAC,4CAAAA,wCA3JAC,iCAAAA,6BAmCAC,6CAAAA,yCAhQAC,mBAAAA,eAmIAC,8BAAAA,0BAoCAC,gCAAAA,8MAvKT,SAASF,UAAUG,CAAU,CAAEC,CAAU,EAE/C,GAAID,IAAMC,EAAG,OAAO,KAGpB,GAAID,IAAM,MAAQC,IAAM,KAAM,OAAO,MACrC,GAAI,OAAOD,IAAM,OAAOC,EAAG,OAAO,MAGlC,GAAIC,MAAMC,OAAO,CAACH,GAAI,CACrB,GAAI,CAACE,MAAMC,OAAO,CAACF,GAAI,OAAO,MAC9B,GAAID,EAAEI,MAAM,GAAKH,EAAEG,MAAM,CAAE,OAAO,MAClC,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAAEI,MAAM,CAAEC,IAAK,CAClC,GAAI,CAACR,UAAUG,CAAC,CAACK,EAAE,CAAEJ,CAAC,CAACI,EAAE,EAAG,OAAO,KACpC,CACA,OAAO,IACR,CAGA,GAAI,OAAOL,IAAM,SAAU,CAC1B,MAAMM,KAAON,EACb,MAAMO,KAAON,EACb,MAAMO,MAAQC,OAAOC,IAAI,CAACJ,M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K,CAC9B,CAEA,MAAMkD,SAA2B,CAChCR,MAAOF,SACPI,YAAaL,eACbM,aAAc,CACbC,KAAM,QACNW,MAAON,wBAAwBC,gBAC/BM,SAAUvE,OACVwE,SAAUxE,MACX,CACD,EAEA,MAAO,CACN+D,SACAlD,MAAOwC,SAAWS,aAAelD,SAClC,CACD"}
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}export function deepEqual(a,b){if(a===b)return true;if(a===null||b===null)return false;if(typeof a!==typeof b)return false;if(Array.isArray(a)){if(!Array.isArray(b))return false;if(a.length!==b.length)return false;for(let i=0;i<a.length;i++){if(!deepEqual(a[i],b[i]))return false}return true}if(typeof a==="object"){const objA=a;const objB=b;const keysA=Object.keys(objA);const keysB=Object.keys(objB);if(keysA.length!==keysB.length)return false;for(const key of keysA){if(!(key in objB)||!deepEqual(objA[key],objB[key]))return false}return true}return false}export class LRUCache{get(key){if(!this.cache.has(key))return undefined;const value=this.cache.get(key);this.cache.delete(key);this.cache.set(key,value);return value}set(key,value){if(this.cache.has(key)){this.cache.delete(key)}else if(this.cache.size>=this.capacity){const oldestKey=this.cache.keys().next().value;if(oldestKey!==undefined){this.cache.delete(oldestKey)}}this.cache.set(key,value)}has(key){return this.cache.has(key)}delete(key){return this.cache.delete(key)}clear(){this.cache.clear()}get size(){return this.cache.size}constructor(capacity){_define_property(this,"capacity",void 0);_define_property(this,"cache",void 0);this.capacity=capacity;this.cache=new Map;if(capacity<1){throw new Error("LRUCache capacity must be at least 1")}}}export function extractSourceSnippet(template,loc){const lines=template.split("\n");const startLine=loc.start.line-1;const endLine=loc.end.line-1;if(startLine<0||startLine>=lines.length)return"";if(startLine===endLine){const line=lines[startLine]??"";return line.trim()}const clampedEnd=Math.min(endLine,lines.length-1);return lines.slice(startLine,clampedEnd+1).map(l=>l.trimEnd()).join("\n").trim()}export function getSchemaPropertyNames(schema){const names=new Set;if(schema.properties){for(const key of Object.keys(schema.properties)){names.add(key)}}for(const combinator of["allOf","anyOf","oneOf"]){const branches=schema[combinator];if(branches){for(const branch of branches){if(typeof branch==="boolean")continue;if(branch.properties){for(const key of Object.keys(branch.properties)){names.add(key)}}}}}return Array.from(names).sort()}export function aggregateObjectAnalysis(keys,analyzeEntry){const allDiagnostics=[];const properties={};let allValid=true;for(const key of keys){const child=analyzeEntry(key);if(!child.valid)allValid=false;allDiagnostics.push(...child.diagnostics);properties[key]=child.outputSchema}return{valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"object",properties,required:keys}}}export function aggregateObjectAnalysisAndExecution(keys,processEntry){const allDiagnostics=[];const properties={};const resultValues={};let allValid=true;for(const key of keys){const child=processEntry(key);if(!child.analysis.valid)allValid=false;allDiagnostics.push(...child.analysis.diagnostics);properties[key]=child.analysis.outputSchema;resultValues[key]=child.value}const analysis={valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"object",properties,required:keys}};return{analysis,value:allValid?resultValues:undefined}}function computeArrayItemsSchema(elementSchemas){if(elementSchemas.length===0)return{};const unique=[];for(const schema of elementSchemas){if(!unique.some(u=>deepEqual(u,schema))){unique.push(schema)}}if(unique.length===1){return unique[0]}return{oneOf:unique}}export function aggregateArrayAnalysis(length,analyzeEntry){const allDiagnostics=[];const elementSchemas=[];let allValid=true;for(let i=0;i<length;i++){const child=analyzeEntry(i);if(!child.valid)allValid=false;allDiagnostics.push(...child.diagnostics);elementSchemas.push(child.outputSchema)}return{valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"array",items:computeArrayItemsSchema(elementSchemas)}}}export function aggregateArrayAnalysisAndExecution(length,processEntry){const allDiagnostics=[];const elementSchemas=[];const resultValues=[];let allValid=true;for(let i=0;i<length;i++){const child=processEntry(i);if(!child.analysis.valid)allValid=false;allDiagnostics.push(...child.analysis.diagnostics);elementSchemas.push(child.analysis.outputSchema);resultValues.push(child.value)}const analysis={valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"array",items:computeArrayItemsSchema(elementSchemas)}};return{analysis,value:allValid?resultValues:undefined}}
|
|
1
|
+
function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}export function deepEqual(a,b){if(a===b)return true;if(a===null||b===null)return false;if(typeof a!==typeof b)return false;if(Array.isArray(a)){if(!Array.isArray(b))return false;if(a.length!==b.length)return false;for(let i=0;i<a.length;i++){if(!deepEqual(a[i],b[i]))return false}return true}if(typeof a==="object"){const objA=a;const objB=b;const keysA=Object.keys(objA);const keysB=Object.keys(objB);if(keysA.length!==keysB.length)return false;for(const key of keysA){if(!(key in objB)||!deepEqual(objA[key],objB[key]))return false}return true}return false}export class LRUCache{get(key){if(!this.cache.has(key))return undefined;const value=this.cache.get(key);this.cache.delete(key);this.cache.set(key,value);return value}set(key,value){if(this.cache.has(key)){this.cache.delete(key)}else if(this.cache.size>=this.capacity){const oldestKey=this.cache.keys().next().value;if(oldestKey!==undefined){this.cache.delete(oldestKey)}}this.cache.set(key,value)}has(key){return this.cache.has(key)}delete(key){return this.cache.delete(key)}clear(){this.cache.clear()}get size(){return this.cache.size}constructor(capacity){_define_property(this,"capacity",void 0);_define_property(this,"cache",void 0);this.capacity=capacity;this.cache=new Map;if(capacity<1){throw new Error("LRUCache capacity must be at least 1")}}}export function extractSourceSnippet(template,loc){const lines=template.split("\n");const startLine=loc.start.line-1;const endLine=loc.end.line-1;if(startLine<0||startLine>=lines.length)return"";if(startLine===endLine){const line=lines[startLine]??"";return line.trim()}const clampedEnd=Math.min(endLine,lines.length-1);return lines.slice(startLine,clampedEnd+1).map(l=>l.trimEnd()).join("\n").trim()}export function getSchemaPropertyNames(schema){const names=new Set;if(schema.properties){for(const key of Object.keys(schema.properties)){names.add(key)}}for(const combinator of["allOf","anyOf","oneOf"]){const branches=schema[combinator];if(branches){for(const branch of branches){if(typeof branch==="boolean")continue;if(branch.properties){for(const key of Object.keys(branch.properties)){names.add(key)}}}}}return Array.from(names).sort()}export function aggregateObjectAnalysis(keys,analyzeEntry){const allDiagnostics=[];const properties={};let allValid=true;for(const key of keys){const child=analyzeEntry(key);if(!child.valid)allValid=false;allDiagnostics.push(...child.diagnostics);properties[key]=child.outputSchema}return{valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"object",properties,required:keys}}}export function aggregateObjectAnalysisAndExecution(keys,processEntry){const allDiagnostics=[];const properties={};const resultValues={};let allValid=true;for(const key of keys){const child=processEntry(key);if(!child.analysis.valid)allValid=false;allDiagnostics.push(...child.analysis.diagnostics);properties[key]=child.analysis.outputSchema;resultValues[key]=child.value}const analysis={valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"object",properties,required:keys}};return{analysis,value:allValid?resultValues:undefined}}function computeArrayItemsSchema(elementSchemas){if(elementSchemas.length===0)return{};const unique=[];for(const schema of elementSchemas){if(!unique.some(u=>deepEqual(u,schema))){unique.push(schema)}}if(unique.length===1){return unique[0]}return{oneOf:unique}}export function aggregateArrayAnalysis(length,analyzeEntry){const allDiagnostics=[];const elementSchemas=[];let allValid=true;for(let i=0;i<length;i++){const child=analyzeEntry(i);if(!child.valid)allValid=false;allDiagnostics.push(...child.diagnostics);elementSchemas.push(child.outputSchema)}return{valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"array",items:computeArrayItemsSchema(elementSchemas),minItems:length,maxItems:length}}}export function aggregateArrayAnalysisAndExecution(length,processEntry){const allDiagnostics=[];const elementSchemas=[];const resultValues=[];let allValid=true;for(let i=0;i<length;i++){const child=processEntry(i);if(!child.analysis.valid)allValid=false;allDiagnostics.push(...child.analysis.diagnostics);elementSchemas.push(child.analysis.outputSchema);resultValues.push(child.value)}const analysis={valid:allValid,diagnostics:allDiagnostics,outputSchema:{type:"array",items:computeArrayItemsSchema(elementSchemas),minItems:length,maxItems:length}};return{analysis,value:allValid?resultValues:undefined}}
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport type { AnalysisResult, TemplateDiagnostic } from \"./types.ts\";\n\n// ─── Utilities ───────────────────────────────────────────────────────────────\n// Shared utility functions and classes used across the different modules\n// of the template engine.\n\n// ─── Deep Equality ───────────────────────────────────────────────────────────\n// Deep structural comparison for JSON-compatible values.\n// More robust than `JSON.stringify` because it is independent of key order\n// and does not allocate intermediate strings.\n\n/**\n * Recursively compares two JSON-compatible values.\n *\n * @param a - First value\n * @param b - Second value\n * @returns `true` if the two values are structurally identical\n *\n * @example\n * ```\n * deepEqual({ a: 1, b: 2 }, { b: 2, a: 1 }) // → true\n * deepEqual([1, 2], [1, 2]) // → true\n * deepEqual({ a: 1 }, { a: 2 }) // → false\n * ```\n */\nexport function deepEqual(a: unknown, b: unknown): boolean {\n\t// Strict identity (covers primitives, same ref; NaN !== NaN is intentional)\n\tif (a === b) return true;\n\n\t// null is typeof \"object\" in JS — handle it separately\n\tif (a === null || b === null) return false;\n\tif (typeof a !== typeof b) return false;\n\n\t// ── Arrays ───────────────────────────────────────────────────────────────\n\tif (Array.isArray(a)) {\n\t\tif (!Array.isArray(b)) return false;\n\t\tif (a.length !== b.length) return false;\n\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\tif (!deepEqual(a[i], b[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// ── Objects ──────────────────────────────────────────────────────────────\n\tif (typeof a === \"object\") {\n\t\tconst objA = a as Record<string, unknown>;\n\t\tconst objB = b as Record<string, unknown>;\n\t\tconst keysA = Object.keys(objA);\n\t\tconst keysB = Object.keys(objB);\n\n\t\tif (keysA.length !== keysB.length) return false;\n\n\t\tfor (const key of keysA) {\n\t\t\tif (!(key in objB) || !deepEqual(objA[key], objB[key])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Different primitives (already covered by a === b at the top)\n\treturn false;\n}\n\n// ─── LRU Cache ───────────────────────────────────────────────────────────────\n// Fixed-capacity cache with Least Recently Used (LRU) eviction.\n// Leverages `Map` insertion order to track access: the oldest entry\n// is always in the first position.\n\n/**\n * Simple fixed-capacity LRU cache.\n *\n * @example\n * ```\n * const cache = new LRUCache<string, number>(2);\n * cache.set(\"a\", 1);\n * cache.set(\"b\", 2);\n * cache.get(\"a\"); // → 1 (marks \"a\" as recently used)\n * cache.set(\"c\", 3); // evicts \"b\" (least recently used)\n * cache.get(\"b\"); // → undefined\n * ```\n */\nexport class LRUCache<K, V> {\n\tprivate readonly cache = new Map<K, V>();\n\n\tconstructor(private readonly capacity: number) {\n\t\tif (capacity < 1) {\n\t\t\tthrow new Error(\"LRUCache capacity must be at least 1\");\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves a value from the cache. Returns `undefined` if absent.\n\t * Marks the entry as recently used.\n\t */\n\tget(key: K): V | undefined {\n\t\tif (!this.cache.has(key)) return undefined;\n\n\t\t// Move to the end of the Map (= most recently used)\n\t\tconst value = this.cache.get(key) as V;\n\t\tthis.cache.delete(key);\n\t\tthis.cache.set(key, value);\n\t\treturn value;\n\t}\n\n\t/**\n\t * Inserts or updates a value in the cache.\n\t * If the cache is full, evicts the least recently used entry.\n\t */\n\tset(key: K, value: V): void {\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.delete(key);\n\t\t} else if (this.cache.size >= this.capacity) {\n\t\t\t// Evict the first entry (the oldest one)\n\t\t\tconst oldestKey = this.cache.keys().next().value;\n\t\t\tif (oldestKey !== undefined) {\n\t\t\t\tthis.cache.delete(oldestKey);\n\t\t\t}\n\t\t}\n\t\tthis.cache.set(key, value);\n\t}\n\n\t/**\n\t * Checks whether a key exists in the cache (without affecting LRU order).\n\t */\n\thas(key: K): boolean {\n\t\treturn this.cache.has(key);\n\t}\n\n\t/**\n\t * Removes an entry from the cache.\n\t * @returns `true` if the entry existed and was removed\n\t */\n\tdelete(key: K): boolean {\n\t\treturn this.cache.delete(key);\n\t}\n\n\t/** Clears the entire cache. */\n\tclear(): void {\n\t\tthis.cache.clear();\n\t}\n\n\t/** Number of entries currently in the cache. */\n\tget size(): number {\n\t\treturn this.cache.size;\n\t}\n}\n\n// ─── Source Snippet Extraction ────────────────────────────────────────────────\n// Used to enrich diagnostics with the template fragment that caused the error.\n\n/**\n * Extracts a template fragment around a given position.\n *\n * @param template - The full template source\n * @param loc - The position (line/column, 1-based) of the error\n * @returns The corresponding code fragment (trimmed)\n */\nexport function extractSourceSnippet(\n\ttemplate: string,\n\tloc: {\n\t\tstart: { line: number; column: number };\n\t\tend: { line: number; column: number };\n\t},\n): string {\n\tconst lines = template.split(\"\\n\");\n\tconst startLine = loc.start.line - 1; // 0-based\n\tconst endLine = loc.end.line - 1;\n\n\tif (startLine < 0 || startLine >= lines.length) return \"\";\n\n\tif (startLine === endLine) {\n\t\t// Same line — extract the portion between start.column and end.column\n\t\tconst line = lines[startLine] ?? \"\";\n\t\treturn line.trim();\n\t}\n\n\t// Multi-line — return the affected lines\n\tconst clampedEnd = Math.min(endLine, lines.length - 1);\n\treturn lines\n\t\t.slice(startLine, clampedEnd + 1)\n\t\t.map((l) => l.trimEnd())\n\t\t.join(\"\\n\")\n\t\t.trim();\n}\n\n// ─── Schema Properties ──────────────────────────────────────────────────────\n// Utility for listing available properties in a schema, used to enrich\n// error messages with suggestions.\n\n/**\n * Lists the declared property names in a JSON Schema.\n * Returns an empty array if the schema has no `properties`.\n */\nexport function getSchemaPropertyNames(schema: JSONSchema7): string[] {\n\tconst names = new Set<string>();\n\n\t// Direct properties\n\tif (schema.properties) {\n\t\tfor (const key of Object.keys(schema.properties)) {\n\t\t\tnames.add(key);\n\t\t}\n\t}\n\n\t// Properties within combinators\n\tfor (const combinator of [\"allOf\", \"anyOf\", \"oneOf\"] as const) {\n\t\tconst branches = schema[combinator];\n\t\tif (branches) {\n\t\t\tfor (const branch of branches) {\n\t\t\t\tif (typeof branch === \"boolean\") continue;\n\t\t\t\tif (branch.properties) {\n\t\t\t\t\tfor (const key of Object.keys(branch.properties)) {\n\t\t\t\t\t\tnames.add(key);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Array.from(names).sort();\n}\n\n// ─── Object Analysis Aggregation ─────────────────────────────────────────────\n// Factorizes the common recursion pattern over template objects:\n// iterate the keys, analyze each entry via a callback, accumulate\n// diagnostics, and build the output object schema.\n//\n// Used by:\n// - `analyzer.ts` (analyzeObjectTemplate)\n// - `Typebars.analyzeObject()` (typebars.ts)\n// - `CompiledTemplate.analyze()` in object mode (compiled-template.ts)\n\n/**\n * Aggregates analysis results from a set of named entries into a single\n * `AnalysisResult` with an object-typed `outputSchema`.\n *\n * @param keys - The keys of the object to analyze\n * @param analyzeEntry - Callback that analyzes an entry by its key\n * @returns An aggregated `AnalysisResult`\n *\n * @example\n * ```\n * aggregateObjectAnalysis(\n * Object.keys(template),\n * (key) => analyze(template[key], inputSchema),\n * );\n * ```\n */\nexport function aggregateObjectAnalysis(\n\tkeys: string[],\n\tanalyzeEntry: (key: string) => AnalysisResult,\n): AnalysisResult {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst properties: Record<string, JSONSchema7> = {};\n\tlet allValid = true;\n\n\tfor (const key of keys) {\n\t\tconst child = analyzeEntry(key);\n\t\tif (!child.valid) allValid = false;\n\t\tallDiagnostics.push(...child.diagnostics);\n\t\tproperties[key] = child.outputSchema;\n\t}\n\n\treturn {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired: keys,\n\t\t},\n\t};\n}\n\n/**\n * Aggregates both analysis **and** execution results from a set of named\n * entries. Returns the aggregated `AnalysisResult` and the object of\n * executed values (or `undefined` if at least one entry is invalid).\n *\n * @param keys - The keys of the object\n * @param processEntry - Callback that analyzes and executes an entry by its key\n * @returns Aggregated `{ analysis, value }`\n */\nexport function aggregateObjectAnalysisAndExecution(\n\tkeys: string[],\n\tprocessEntry: (key: string) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst properties: Record<string, JSONSchema7> = {};\n\tconst resultValues: Record<string, unknown> = {};\n\tlet allValid = true;\n\n\tfor (const key of keys) {\n\t\tconst child = processEntry(key);\n\t\tif (!child.analysis.valid) allValid = false;\n\t\tallDiagnostics.push(...child.analysis.diagnostics);\n\t\tproperties[key] = child.analysis.outputSchema;\n\t\tresultValues[key] = child.value;\n\t}\n\n\tconst analysis: AnalysisResult = {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired: keys,\n\t\t},\n\t};\n\n\treturn {\n\t\tanalysis,\n\t\tvalue: allValid ? resultValues : undefined,\n\t};\n}\n\n// ─── Array Analysis Aggregation ──────────────────────────────────────────────\n// Factorizes the common recursion pattern over template arrays:\n// iterate the elements, analyze each entry via a callback, accumulate\n// diagnostics, and build the output array schema with a proper `items`.\n//\n// Used by:\n// - `analyzer.ts` (analyzeArrayTemplate)\n// - `Typebars.analyze()` (typebars.ts)\n// - `CompiledTemplate.analyze()` in array mode (compiled-template.ts)\n\n/**\n * Computes the `items` schema for an array from the output schemas of its\n * elements:\n * - If all elements share the same schema → that schema\n * - If there are multiple distinct schemas → `{ oneOf: [...] }`\n * - If the array is empty → `{}` (any type)\n */\nfunction computeArrayItemsSchema(elementSchemas: JSONSchema7[]): JSONSchema7 {\n\tif (elementSchemas.length === 0) return {};\n\n\t// Deduplicate schemas using deep equality\n\tconst unique: JSONSchema7[] = [];\n\tfor (const schema of elementSchemas) {\n\t\tif (!unique.some((u) => deepEqual(u, schema))) {\n\t\t\tunique.push(schema);\n\t\t}\n\t}\n\n\tif (unique.length === 1) {\n\t\treturn unique[0] as JSONSchema7;\n\t}\n\n\treturn { oneOf: unique };\n}\n\n/**\n * Aggregates analysis results from a set of array elements into a single\n * `AnalysisResult` with an array-typed `outputSchema`.\n *\n * @param length - The number of elements in the array\n * @param analyzeEntry - Callback that analyzes an element by its index\n * @returns An aggregated `AnalysisResult`\n *\n * @example\n * ```\n * aggregateArrayAnalysis(\n * template.length,\n * (index) => analyze(template[index], inputSchema),\n * );\n * ```\n */\nexport function aggregateArrayAnalysis(\n\tlength: number,\n\tanalyzeEntry: (index: number) => AnalysisResult,\n): AnalysisResult {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst elementSchemas: JSONSchema7[] = [];\n\tlet allValid = true;\n\n\tfor (let i = 0; i < length; i++) {\n\t\tconst child = analyzeEntry(i);\n\t\tif (!child.valid) allValid = false;\n\t\tallDiagnostics.push(...child.diagnostics);\n\t\telementSchemas.push(child.outputSchema);\n\t}\n\n\treturn {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"array\",\n\t\t\titems: computeArrayItemsSchema(elementSchemas),\n\t\t},\n\t};\n}\n\n/**\n * Aggregates both analysis **and** execution results from a set of array\n * elements. Returns the aggregated `AnalysisResult` and the array of\n * executed values (or `undefined` if at least one element is invalid).\n *\n * @param length - The number of elements\n * @param processEntry - Callback that analyzes and executes an element by index\n * @returns Aggregated `{ analysis, value }`\n */\nexport function aggregateArrayAnalysisAndExecution(\n\tlength: number,\n\tprocessEntry: (index: number) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst elementSchemas: JSONSchema7[] = [];\n\tconst resultValues: unknown[] = [];\n\tlet allValid = true;\n\n\tfor (let i = 0; i < length; i++) {\n\t\tconst child = processEntry(i);\n\t\tif (!child.analysis.valid) allValid = false;\n\t\tallDiagnostics.push(...child.analysis.diagnostics);\n\t\telementSchemas.push(child.analysis.outputSchema);\n\t\tresultValues.push(child.value);\n\t}\n\n\tconst analysis: AnalysisResult = {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"array\",\n\t\t\titems: computeArrayItemsSchema(elementSchemas),\n\t\t},\n\t};\n\n\treturn {\n\t\tanalysis,\n\t\tvalue: allValid ? resultValues : undefined,\n\t};\n}\n"],"names":["deepEqual","a","b","Array","isArray","length","i","objA","objB","keysA","Object","keys","keysB","key","LRUCache","get","cache","has","undefined","value","delete","set","size","capacity","oldestKey","next","clear","Map","Error","extractSourceSnippet","template","loc","lines","split","startLine","start","line","endLine","end","trim","clampedEnd","Math","min","slice","map","l","trimEnd","join","getSchemaPropertyNames","schema","names","Set","properties","add","combinator","branches","branch","from","sort","aggregateObjectAnalysis","analyzeEntry","allDiagnostics","allValid","child","valid","push","diagnostics","outputSchema","type","required","aggregateObjectAnalysisAndExecution","processEntry","resultValues","analysis","computeArrayItemsSchema","elementSchemas","unique","some","u","oneOf","aggregateArrayAnalysis","items","aggregateArrayAnalysisAndExecution"],"mappings":"oLA0BA,OAAO,SAASA,UAAUC,CAAU,CAAEC,CAAU,EAE/C,GAAID,IAAMC,EAAG,OAAO,KAGpB,GAAID,IAAM,MAAQC,IAAM,KAAM,OAAO,MACrC,GAAI,OAAOD,IAAM,OAAOC,EAAG,OAAO,MAGlC,GAAIC,MAAMC,OAAO,CAACH,GAAI,CACrB,GAAI,CAACE,MAAMC,OAAO,CAACF,GAAI,OAAO,MAC9B,GAAID,EAAEI,MAAM,GAAKH,EAAEG,MAAM,CAAE,OAAO,MAClC,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAAEI,MAAM,CAAEC,IAAK,CAClC,GAAI,CAACN,UAAUC,CAAC,CAACK,EAAE,CAAEJ,CAAC,CAACI,EAAE,EAAG,OAAO,KACpC,CACA,OAAO,IACR,CAGA,GAAI,OAAOL,IAAM,SAAU,CAC1B,MAAMM,KAAON,EACb,MAAMO,KAAON,EACb,MAAMO,MAAQ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/CK,aAAaP,IAAI,CAACF,MAAM5C,KAAK,CAC9B,CAEA,MAAMsD,SAA2B,CAChCT,MAAOF,SACPI,YAAaL,eACbM,aAAc,CACbC,KAAM,QACNa,MAAOP,wBAAwBC,eAChC,CACD,EAEA,MAAO,CACNF,SACAtD,MAAO2C,SAAWU,aAAetD,SAClC,CACD"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport type { AnalysisResult, TemplateDiagnostic } from \"./types.ts\";\n\n// ─── Utilities ───────────────────────────────────────────────────────────────\n// Shared utility functions and classes used across the different modules\n// of the template engine.\n\n// ─── Deep Equality ───────────────────────────────────────────────────────────\n// Deep structural comparison for JSON-compatible values.\n// More robust than `JSON.stringify` because it is independent of key order\n// and does not allocate intermediate strings.\n\n/**\n * Recursively compares two JSON-compatible values.\n *\n * @param a - First value\n * @param b - Second value\n * @returns `true` if the two values are structurally identical\n *\n * @example\n * ```\n * deepEqual({ a: 1, b: 2 }, { b: 2, a: 1 }) // → true\n * deepEqual([1, 2], [1, 2]) // → true\n * deepEqual({ a: 1 }, { a: 2 }) // → false\n * ```\n */\nexport function deepEqual(a: unknown, b: unknown): boolean {\n\t// Strict identity (covers primitives, same ref; NaN !== NaN is intentional)\n\tif (a === b) return true;\n\n\t// null is typeof \"object\" in JS — handle it separately\n\tif (a === null || b === null) return false;\n\tif (typeof a !== typeof b) return false;\n\n\t// ── Arrays ───────────────────────────────────────────────────────────────\n\tif (Array.isArray(a)) {\n\t\tif (!Array.isArray(b)) return false;\n\t\tif (a.length !== b.length) return false;\n\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\tif (!deepEqual(a[i], b[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// ── Objects ──────────────────────────────────────────────────────────────\n\tif (typeof a === \"object\") {\n\t\tconst objA = a as Record<string, unknown>;\n\t\tconst objB = b as Record<string, unknown>;\n\t\tconst keysA = Object.keys(objA);\n\t\tconst keysB = Object.keys(objB);\n\n\t\tif (keysA.length !== keysB.length) return false;\n\n\t\tfor (const key of keysA) {\n\t\t\tif (!(key in objB) || !deepEqual(objA[key], objB[key])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Different primitives (already covered by a === b at the top)\n\treturn false;\n}\n\n// ─── LRU Cache ───────────────────────────────────────────────────────────────\n// Fixed-capacity cache with Least Recently Used (LRU) eviction.\n// Leverages `Map` insertion order to track access: the oldest entry\n// is always in the first position.\n\n/**\n * Simple fixed-capacity LRU cache.\n *\n * @example\n * ```\n * const cache = new LRUCache<string, number>(2);\n * cache.set(\"a\", 1);\n * cache.set(\"b\", 2);\n * cache.get(\"a\"); // → 1 (marks \"a\" as recently used)\n * cache.set(\"c\", 3); // evicts \"b\" (least recently used)\n * cache.get(\"b\"); // → undefined\n * ```\n */\nexport class LRUCache<K, V> {\n\tprivate readonly cache = new Map<K, V>();\n\n\tconstructor(private readonly capacity: number) {\n\t\tif (capacity < 1) {\n\t\t\tthrow new Error(\"LRUCache capacity must be at least 1\");\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves a value from the cache. Returns `undefined` if absent.\n\t * Marks the entry as recently used.\n\t */\n\tget(key: K): V | undefined {\n\t\tif (!this.cache.has(key)) return undefined;\n\n\t\t// Move to the end of the Map (= most recently used)\n\t\tconst value = this.cache.get(key) as V;\n\t\tthis.cache.delete(key);\n\t\tthis.cache.set(key, value);\n\t\treturn value;\n\t}\n\n\t/**\n\t * Inserts or updates a value in the cache.\n\t * If the cache is full, evicts the least recently used entry.\n\t */\n\tset(key: K, value: V): void {\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.delete(key);\n\t\t} else if (this.cache.size >= this.capacity) {\n\t\t\t// Evict the first entry (the oldest one)\n\t\t\tconst oldestKey = this.cache.keys().next().value;\n\t\t\tif (oldestKey !== undefined) {\n\t\t\t\tthis.cache.delete(oldestKey);\n\t\t\t}\n\t\t}\n\t\tthis.cache.set(key, value);\n\t}\n\n\t/**\n\t * Checks whether a key exists in the cache (without affecting LRU order).\n\t */\n\thas(key: K): boolean {\n\t\treturn this.cache.has(key);\n\t}\n\n\t/**\n\t * Removes an entry from the cache.\n\t * @returns `true` if the entry existed and was removed\n\t */\n\tdelete(key: K): boolean {\n\t\treturn this.cache.delete(key);\n\t}\n\n\t/** Clears the entire cache. */\n\tclear(): void {\n\t\tthis.cache.clear();\n\t}\n\n\t/** Number of entries currently in the cache. */\n\tget size(): number {\n\t\treturn this.cache.size;\n\t}\n}\n\n// ─── Source Snippet Extraction ────────────────────────────────────────────────\n// Used to enrich diagnostics with the template fragment that caused the error.\n\n/**\n * Extracts a template fragment around a given position.\n *\n * @param template - The full template source\n * @param loc - The position (line/column, 1-based) of the error\n * @returns The corresponding code fragment (trimmed)\n */\nexport function extractSourceSnippet(\n\ttemplate: string,\n\tloc: {\n\t\tstart: { line: number; column: number };\n\t\tend: { line: number; column: number };\n\t},\n): string {\n\tconst lines = template.split(\"\\n\");\n\tconst startLine = loc.start.line - 1; // 0-based\n\tconst endLine = loc.end.line - 1;\n\n\tif (startLine < 0 || startLine >= lines.length) return \"\";\n\n\tif (startLine === endLine) {\n\t\t// Same line — extract the portion between start.column and end.column\n\t\tconst line = lines[startLine] ?? \"\";\n\t\treturn line.trim();\n\t}\n\n\t// Multi-line — return the affected lines\n\tconst clampedEnd = Math.min(endLine, lines.length - 1);\n\treturn lines\n\t\t.slice(startLine, clampedEnd + 1)\n\t\t.map((l) => l.trimEnd())\n\t\t.join(\"\\n\")\n\t\t.trim();\n}\n\n// ─── Schema Properties ──────────────────────────────────────────────────────\n// Utility for listing available properties in a schema, used to enrich\n// error messages with suggestions.\n\n/**\n * Lists the declared property names in a JSON Schema.\n * Returns an empty array if the schema has no `properties`.\n */\nexport function getSchemaPropertyNames(schema: JSONSchema7): string[] {\n\tconst names = new Set<string>();\n\n\t// Direct properties\n\tif (schema.properties) {\n\t\tfor (const key of Object.keys(schema.properties)) {\n\t\t\tnames.add(key);\n\t\t}\n\t}\n\n\t// Properties within combinators\n\tfor (const combinator of [\"allOf\", \"anyOf\", \"oneOf\"] as const) {\n\t\tconst branches = schema[combinator];\n\t\tif (branches) {\n\t\t\tfor (const branch of branches) {\n\t\t\t\tif (typeof branch === \"boolean\") continue;\n\t\t\t\tif (branch.properties) {\n\t\t\t\t\tfor (const key of Object.keys(branch.properties)) {\n\t\t\t\t\t\tnames.add(key);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Array.from(names).sort();\n}\n\n// ─── Object Analysis Aggregation ─────────────────────────────────────────────\n// Factorizes the common recursion pattern over template objects:\n// iterate the keys, analyze each entry via a callback, accumulate\n// diagnostics, and build the output object schema.\n//\n// Used by:\n// - `analyzer.ts` (analyzeObjectTemplate)\n// - `Typebars.analyzeObject()` (typebars.ts)\n// - `CompiledTemplate.analyze()` in object mode (compiled-template.ts)\n\n/**\n * Aggregates analysis results from a set of named entries into a single\n * `AnalysisResult` with an object-typed `outputSchema`.\n *\n * @param keys - The keys of the object to analyze\n * @param analyzeEntry - Callback that analyzes an entry by its key\n * @returns An aggregated `AnalysisResult`\n *\n * @example\n * ```\n * aggregateObjectAnalysis(\n * Object.keys(template),\n * (key) => analyze(template[key], inputSchema),\n * );\n * ```\n */\nexport function aggregateObjectAnalysis(\n\tkeys: string[],\n\tanalyzeEntry: (key: string) => AnalysisResult,\n): AnalysisResult {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst properties: Record<string, JSONSchema7> = {};\n\tlet allValid = true;\n\n\tfor (const key of keys) {\n\t\tconst child = analyzeEntry(key);\n\t\tif (!child.valid) allValid = false;\n\t\tallDiagnostics.push(...child.diagnostics);\n\t\tproperties[key] = child.outputSchema;\n\t}\n\n\treturn {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired: keys,\n\t\t},\n\t};\n}\n\n/**\n * Aggregates both analysis **and** execution results from a set of named\n * entries. Returns the aggregated `AnalysisResult` and the object of\n * executed values (or `undefined` if at least one entry is invalid).\n *\n * @param keys - The keys of the object\n * @param processEntry - Callback that analyzes and executes an entry by its key\n * @returns Aggregated `{ analysis, value }`\n */\nexport function aggregateObjectAnalysisAndExecution(\n\tkeys: string[],\n\tprocessEntry: (key: string) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst properties: Record<string, JSONSchema7> = {};\n\tconst resultValues: Record<string, unknown> = {};\n\tlet allValid = true;\n\n\tfor (const key of keys) {\n\t\tconst child = processEntry(key);\n\t\tif (!child.analysis.valid) allValid = false;\n\t\tallDiagnostics.push(...child.analysis.diagnostics);\n\t\tproperties[key] = child.analysis.outputSchema;\n\t\tresultValues[key] = child.value;\n\t}\n\n\tconst analysis: AnalysisResult = {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired: keys,\n\t\t},\n\t};\n\n\treturn {\n\t\tanalysis,\n\t\tvalue: allValid ? resultValues : undefined,\n\t};\n}\n\n// ─── Array Analysis Aggregation ──────────────────────────────────────────────\n// Factorizes the common recursion pattern over template arrays:\n// iterate the elements, analyze each entry via a callback, accumulate\n// diagnostics, and build the output array schema with a proper `items`.\n//\n// Used by:\n// - `analyzer.ts` (analyzeArrayTemplate)\n// - `Typebars.analyze()` (typebars.ts)\n// - `CompiledTemplate.analyze()` in array mode (compiled-template.ts)\n\n/**\n * Computes the `items` schema for an array from the output schemas of its\n * elements:\n * - If all elements share the same schema → that schema\n * - If there are multiple distinct schemas → `{ oneOf: [...] }`\n * - If the array is empty → `{}` (any type)\n */\nfunction computeArrayItemsSchema(elementSchemas: JSONSchema7[]): JSONSchema7 {\n\tif (elementSchemas.length === 0) return {};\n\n\t// Deduplicate schemas using deep equality\n\tconst unique: JSONSchema7[] = [];\n\tfor (const schema of elementSchemas) {\n\t\tif (!unique.some((u) => deepEqual(u, schema))) {\n\t\t\tunique.push(schema);\n\t\t}\n\t}\n\n\tif (unique.length === 1) {\n\t\treturn unique[0] as JSONSchema7;\n\t}\n\n\treturn { oneOf: unique };\n}\n\n/**\n * Aggregates analysis results from a set of array elements into a single\n * `AnalysisResult` with an array-typed `outputSchema`.\n *\n * @param length - The number of elements in the array\n * @param analyzeEntry - Callback that analyzes an element by its index\n * @returns An aggregated `AnalysisResult`\n *\n * @example\n * ```\n * aggregateArrayAnalysis(\n * template.length,\n * (index) => analyze(template[index], inputSchema),\n * );\n * ```\n */\nexport function aggregateArrayAnalysis(\n\tlength: number,\n\tanalyzeEntry: (index: number) => AnalysisResult,\n): AnalysisResult {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst elementSchemas: JSONSchema7[] = [];\n\tlet allValid = true;\n\n\tfor (let i = 0; i < length; i++) {\n\t\tconst child = analyzeEntry(i);\n\t\tif (!child.valid) allValid = false;\n\t\tallDiagnostics.push(...child.diagnostics);\n\t\telementSchemas.push(child.outputSchema);\n\t}\n\n\treturn {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"array\",\n\t\t\titems: computeArrayItemsSchema(elementSchemas),\n\t\t\tminItems: length,\n\t\t\tmaxItems: length,\n\t\t},\n\t};\n}\n\n/**\n * Aggregates both analysis **and** execution results from a set of array\n * elements. Returns the aggregated `AnalysisResult` and the array of\n * executed values (or `undefined` if at least one element is invalid).\n *\n * @param length - The number of elements\n * @param processEntry - Callback that analyzes and executes an element by index\n * @returns Aggregated `{ analysis, value }`\n */\nexport function aggregateArrayAnalysisAndExecution(\n\tlength: number,\n\tprocessEntry: (index: number) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst elementSchemas: JSONSchema7[] = [];\n\tconst resultValues: unknown[] = [];\n\tlet allValid = true;\n\n\tfor (let i = 0; i < length; i++) {\n\t\tconst child = processEntry(i);\n\t\tif (!child.analysis.valid) allValid = false;\n\t\tallDiagnostics.push(...child.analysis.diagnostics);\n\t\telementSchemas.push(child.analysis.outputSchema);\n\t\tresultValues.push(child.value);\n\t}\n\n\tconst analysis: AnalysisResult = {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"array\",\n\t\t\titems: computeArrayItemsSchema(elementSchemas),\n\t\t\tminItems: length,\n\t\t\tmaxItems: length,\n\t\t},\n\t};\n\n\treturn {\n\t\tanalysis,\n\t\tvalue: allValid ? resultValues : undefined,\n\t};\n}\n"],"names":["deepEqual","a","b","Array","isArray","length","i","objA","objB","keysA","Object","keys","keysB","key","LRUCache","get","cache","has","undefined","value","delete","set","size","capacity","oldestKey","next","clear","Map","Error","extractSourceSnippet","template","loc","lines","split","startLine","start","line","endLine","end","trim","clampedEnd","Math","min","slice","map","l","trimEnd","join","getSchemaPropertyNames","schema","names","Set","properties","add","combinator","branches","branch","from","sort","aggregateObjectAnalysis","analyzeEntry","allDiagnostics","allValid","child","valid","push","diagnostics","outputSchema","type","required","aggregateObjectAnalysisAndExecution","processEntry","resultValues","analysis","computeArrayItemsSchema","elementSchemas","unique","some","u","oneOf","aggregateArrayAnalysis","items","minItems","maxItems","aggregateArrayAnalysisAndExecution"],"mappings":"oLA0BA,OAAO,SAASA,UAAUC,CAAU,CAAEC,CAAU,EAE/C,GAAID,IAAMC,EAAG,OAAO,KAGpB,GAAID,IAAM,MAAQC,IAAM,KAAM,OAAO,MACrC,GAAI,OAAOD,IAAM,OAAOC,EAAG,OAAO,MAGlC,GAAIC,MAAMC,OAAO,CAACH,GAAI,CACrB,GAAI,CAACE,MAAMC,OAAO,CAACF,GAAI,OAAO,MAC9B,GAAID,EAAEI,MAAM,GAAKH,EAAEG,MAAM,CAAE,OAAO,MAClC,IAAK,IAAIC,E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