typebars 1.0.15 → 1.0.16
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/dispatch.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 dispatchAnalyze(){return dispatchAnalyze},get dispatchAnalyzeAndExecute(){return dispatchAnalyzeAndExecute},get dispatchExecute(){return dispatchExecute},get resolveChildCoerceSchema(){return resolveChildCoerceSchema},get shouldExcludeEntry(){return shouldExcludeEntry}});const _parserts=require("./parser.js");const _schemaresolverts=require("./schema-resolver.js");const _typests=require("./types.js");const _utilsts=require("./utils.js");function dispatchAnalyze(template,options,analyzeString,recurse){if((0,_typests.isArrayInput)(template)){const exclude=options?.excludeTemplateExpression===true;if(exclude){const kept=template.filter(item=>!shouldExcludeEntry(item));return(0,_utilsts.aggregateArrayAnalysis)(kept.length,index=>recurse(kept[index],
|
|
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 dispatchAnalyze(){return dispatchAnalyze},get dispatchAnalyzeAndExecute(){return dispatchAnalyzeAndExecute},get dispatchExecute(){return dispatchExecute},get resolveChildCoerceSchema(){return resolveChildCoerceSchema},get shouldExcludeEntry(){return shouldExcludeEntry}});const _parserts=require("./parser.js");const _schemaresolverts=require("./schema-resolver.js");const _typests=require("./types.js");const _utilsts=require("./utils.js");function dispatchAnalyze(template,options,analyzeString,recurse){if((0,_typests.isArrayInput)(template)){const exclude=options?.excludeTemplateExpression===true;const childOptions=resolveArrayChildOptions(options);if(exclude){const kept=template.filter(item=>!shouldExcludeEntry(item));return(0,_utilsts.aggregateArrayAnalysis)(kept.length,index=>recurse(kept[index],childOptions))}return(0,_utilsts.aggregateArrayAnalysis)(template.length,index=>recurse(template[index],childOptions))}if((0,_typests.isObjectInput)(template)){return dispatchObjectAnalysis(template,options,recurse)}if((0,_typests.isLiteralInput)(template)){return{valid:true,diagnostics:[],outputSchema:(0,_typests.inferPrimitiveSchema)(template)}}return analyzeString(template,options?.coerceSchema)}function dispatchObjectAnalysis(template,options,recurse){const coerceSchema=options?.coerceSchema;const exclude=options?.excludeTemplateExpression===true;const keys=exclude?Object.keys(template).filter(key=>!shouldExcludeEntry(template[key])):Object.keys(template);return(0,_utilsts.aggregateObjectAnalysis)(keys,key=>{const childCoerceSchema=resolveChildCoerceSchema(coerceSchema,key);return recurse(template[key],{identifierSchemas:options?.identifierSchemas,coerceSchema:childCoerceSchema,excludeTemplateExpression:options?.excludeTemplateExpression})})}function dispatchExecute(template,options,executeString,recurse){const exclude=options?.excludeTemplateExpression===true;if((0,_typests.isArrayInput)(template)){const childOptions=resolveArrayChildOptions(options);const elements=exclude?template.filter(item=>!shouldExcludeEntry(item)):template;const result=[];for(const element of elements){result.push(recurse(element,childOptions))}return result}if((0,_typests.isObjectInput)(template)){const coerceSchema=options?.coerceSchema;const result={};const keys=exclude?Object.keys(template).filter(key=>!shouldExcludeEntry(template[key])):Object.keys(template);for(const key of keys){const childCoerceSchema=resolveChildCoerceSchema(coerceSchema,key);result[key]=recurse(template[key],{...options,coerceSchema:childCoerceSchema})}return result}if((0,_typests.isLiteralInput)(template))return template;if(exclude&&shouldExcludeEntry(template)){return null}return executeString(template,options?.coerceSchema)}function dispatchAnalyzeAndExecute(template,options,processString,recurse){const exclude=options?.excludeTemplateExpression===true;if((0,_typests.isArrayInput)(template)){const childOptions=resolveArrayChildOptions(options);const elements=exclude?template.filter(item=>!shouldExcludeEntry(item)):template;return(0,_utilsts.aggregateArrayAnalysisAndExecution)(elements.length,index=>recurse(elements[index],childOptions))}if((0,_typests.isObjectInput)(template)){const coerceSchema=options?.coerceSchema;const keys=exclude?Object.keys(template).filter(key=>!shouldExcludeEntry(template[key])):Object.keys(template);return(0,_utilsts.aggregateObjectAnalysisAndExecution)(keys,key=>{const childCoerceSchema=resolveChildCoerceSchema(coerceSchema,key);return recurse(template[key],{identifierSchemas:options?.identifierSchemas,identifierData:options?.identifierData,coerceSchema:childCoerceSchema,excludeTemplateExpression:options?.excludeTemplateExpression})})}if((0,_typests.isLiteralInput)(template)){return{analysis:{valid:true,diagnostics:[],outputSchema:(0,_typests.inferPrimitiveSchema)(template)},value:template}}if(exclude&&shouldExcludeEntry(template)){return{analysis:{valid:true,diagnostics:[],outputSchema:{type:"null"}},value:null}}return processString(template,options?.coerceSchema)}function resolveArrayChildOptions(options){if(!options?.coerceSchema)return options;const itemsSchema=resolveItemsCoerceSchema(options.coerceSchema);if(itemsSchema===options.coerceSchema)return options;return{...options,coerceSchema:itemsSchema}}function resolveItemsCoerceSchema(coerceSchema){if(typeof coerceSchema==="boolean")return undefined;const items=coerceSchema.items;if(items!=null&&typeof items==="object"&&!Array.isArray(items)){return items}return undefined}function resolveChildCoerceSchema(coerceSchema,key){return coerceSchema?(0,_schemaresolverts.resolveSchemaPath)(coerceSchema,[key]):undefined}function shouldExcludeEntry(input){return typeof input==="string"&&(0,_parserts.hasHandlebarsExpression)(input)}
|
|
2
2
|
//# sourceMappingURL=dispatch.js.map
|
package/dist/cjs/dispatch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/dispatch.ts"],"sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport { hasHandlebarsExpression } from \"./parser.ts\";\nimport { resolveSchemaPath } from \"./schema-resolver.ts\";\nimport type { AnalysisResult, TemplateInput } from \"./types.ts\";\nimport {\n\tinferPrimitiveSchema,\n\tisArrayInput,\n\tisLiteralInput,\n\tisObjectInput,\n} from \"./types.ts\";\nimport {\n\taggregateArrayAnalysis,\n\taggregateArrayAnalysisAndExecution,\n\taggregateObjectAnalysis,\n\taggregateObjectAnalysisAndExecution,\n} from \"./utils.ts\";\n\n// ─── Template Input Dispatching ──────────────────────────────────────────────\n// Factorized dispatching for recursive processing of `TemplateInput` values.\n//\n// Every method in the engine (`analyze`, `execute`, `analyzeAndExecute`,\n// `compile`) follows the same recursive pattern:\n//\n// 1. If the input is an **array** → process each element recursively\n// 2. If the input is an **object** → process each property recursively\n// 3. If the input is a **literal** (number, boolean, null) → passthrough\n// 4. If the input is a **string** → delegate to a template-specific handler\n//\n// This module extracts the common dispatching logic into generic functions\n// that accept a callback for the string (template) case. This eliminates\n// the duplication across `Typebars`, `CompiledTemplate`, and `analyzer.ts`.\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Options controlling recursive dispatching behavior */\nexport interface DispatchAnalyzeOptions {\n\t/** Schemas by template identifier */\n\tidentifierSchemas?: Record<number, JSONSchema7>;\n\t/** Explicit coercion schema for static literal output type */\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n/** Options controlling recursive execution dispatching */\nexport interface DispatchExecuteOptions {\n\t/** Explicit coercion schema for output type coercion */\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n// ─── Analysis Dispatching ────────────────────────────────────────────────────\n\n/**\n * Dispatches a `TemplateInput` for analysis, handling the array/object/literal\n * cases generically and delegating the string (template) case to a callback.\n *\n * @param template - The input to analyze\n * @param options - Dispatching options (coerceSchema, excludeTemplateExpression)\n * @param analyzeString - Callback for analyzing a string template.\n * Receives `(template, coerceSchema?)` and must return an `AnalysisResult`.\n * @param recurse - Callback for recursively analyzing a child `TemplateInput`.\n * Receives `(child, options?)` and must return an `AnalysisResult`.\n * This allows callers (like `Typebars`) to rebind `this` or inject\n * additional context on each recursive call.\n * @returns An `AnalysisResult`\n */\nexport function dispatchAnalyze(\n\ttemplate: TemplateInput,\n\toptions: DispatchAnalyzeOptions | undefined,\n\tanalyzeString: (\n\t\ttemplate: string,\n\t\tcoerceSchema?: JSONSchema7,\n\t) => AnalysisResult,\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeOptions,\n\t) => AnalysisResult,\n): AnalysisResult {\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst exclude = options?.excludeTemplateExpression === true;\n\t\tif (exclude) {\n\t\t\tconst kept = template.filter(\n\t\t\t\t(item) => !shouldExcludeEntry(item as TemplateInput),\n\t\t\t);\n\t\t\treturn aggregateArrayAnalysis(kept.length, (index) =>\n\t\t\t\trecurse(kept[index] as TemplateInput, options),\n\t\t\t);\n\t\t}\n\t\treturn aggregateArrayAnalysis(template.length, (index) =>\n\t\t\trecurse(template[index] as TemplateInput, options),\n\t\t);\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\treturn dispatchObjectAnalysis(template, options, recurse);\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) {\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\tdiagnostics: [],\n\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t};\n\t}\n\n\t// ── String template ──────────────────────────────────────────────────\n\treturn analyzeString(template, options?.coerceSchema);\n}\n\n/**\n * Dispatches object analysis with `coerceSchema` propagation and\n * `excludeTemplateExpression` filtering.\n *\n * Extracted as a separate function because the object case is the most\n * complex (key filtering + per-key coerceSchema resolution).\n */\nfunction dispatchObjectAnalysis(\n\ttemplate: Record<string, TemplateInput>,\n\toptions: DispatchAnalyzeOptions | undefined,\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeOptions,\n\t) => AnalysisResult,\n): AnalysisResult {\n\tconst coerceSchema = options?.coerceSchema;\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\tconst keys = exclude\n\t\t? Object.keys(template).filter(\n\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t)\n\t\t: Object.keys(template);\n\n\treturn aggregateObjectAnalysis(keys, (key) => {\n\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\treturn recurse(template[key] as TemplateInput, {\n\t\t\tidentifierSchemas: options?.identifierSchemas,\n\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\texcludeTemplateExpression: options?.excludeTemplateExpression,\n\t\t});\n\t});\n}\n\n// ─── Execution Dispatching ───────────────────────────────────────────────────\n\n/**\n * Dispatches a `TemplateInput` for execution, handling the array/object/literal\n * cases generically and delegating the string (template) case to a callback.\n *\n * @param template - The input to execute\n * @param options - Dispatching options (coerceSchema)\n * @param executeString - Callback for executing a string template.\n * Receives `(template, coerceSchema?)` and must return the result.\n * @param recurse - Callback for recursively executing a child `TemplateInput`.\n * Receives `(child, options?)` and must return the result.\n * @returns The execution result\n */\nexport function dispatchExecute(\n\ttemplate: TemplateInput,\n\toptions: DispatchExecuteOptions | undefined,\n\texecuteString: (template: string, coerceSchema?: JSONSchema7) => unknown,\n\trecurse: (child: TemplateInput, options?: DispatchExecuteOptions) => unknown,\n): unknown {\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst elements = exclude\n\t\t\t? template.filter((item) => !shouldExcludeEntry(item as TemplateInput))\n\t\t\t: template;\n\t\tconst result: unknown[] = [];\n\t\tfor (const element of elements) {\n\t\t\tresult.push(recurse(element as TemplateInput, options));\n\t\t}\n\t\treturn result;\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\tconst coerceSchema = options?.coerceSchema;\n\t\tconst result: Record<string, unknown> = {};\n\t\tconst keys = exclude\n\t\t\t? Object.keys(template).filter(\n\t\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t\t)\n\t\t\t: Object.keys(template);\n\t\tfor (const key of keys) {\n\t\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\t\tresult[key] = recurse(template[key] as TemplateInput, {\n\t\t\t\t...options,\n\t\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) return template;\n\n\t// ── String template ──────────────────────────────────────────────────\n\t// At root level, if the string contains expressions and exclude is on,\n\t// return null (there is no parent to remove it from).\n\tif (exclude && shouldExcludeEntry(template)) {\n\t\treturn null;\n\t}\n\n\treturn executeString(template, options?.coerceSchema);\n}\n\n// ─── Analyze-and-Execute Dispatching ─────────────────────────────────────────\n\n/** Options for combined analyze-and-execute dispatching */\nexport interface DispatchAnalyzeAndExecuteOptions {\n\tidentifierSchemas?: Record<number, JSONSchema7>;\n\tidentifierData?: Record<number, Record<string, unknown>>;\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n/**\n * Dispatches a `TemplateInput` for combined analysis and execution,\n * handling array/object/literal cases generically and delegating\n * the string case to a callback.\n *\n * @param template - The input to process\n * @param options - Options (identifierSchemas, identifierData, coerceSchema)\n * @param processString - Callback for analyzing and executing a string template.\n * Receives `(template, coerceSchema?)` and must return\n * `{ analysis, value }`.\n * @param recurse - Callback for recursively processing a child `TemplateInput`.\n * @returns `{ analysis, value }` where `value` is `undefined` if analysis fails\n */\nexport function dispatchAnalyzeAndExecute(\n\ttemplate: TemplateInput,\n\toptions: DispatchAnalyzeAndExecuteOptions | undefined,\n\tprocessString: (\n\t\ttemplate: string,\n\t\tcoerceSchema?: JSONSchema7,\n\t) => { analysis: AnalysisResult; value: unknown },\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeAndExecuteOptions,\n\t) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst elements = exclude\n\t\t\t? template.filter((item) => !shouldExcludeEntry(item as TemplateInput))\n\t\t\t: template;\n\t\treturn aggregateArrayAnalysisAndExecution(elements.length, (index) =>\n\t\t\trecurse(elements[index] as TemplateInput, options),\n\t\t);\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\tconst coerceSchema = options?.coerceSchema;\n\t\tconst keys = exclude\n\t\t\t? Object.keys(template).filter(\n\t\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t\t)\n\t\t\t: Object.keys(template);\n\t\treturn aggregateObjectAnalysisAndExecution(keys, (key) => {\n\t\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\t\treturn recurse(template[key] as TemplateInput, {\n\t\t\t\tidentifierSchemas: options?.identifierSchemas,\n\t\t\t\tidentifierData: options?.identifierData,\n\t\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\t\texcludeTemplateExpression: options?.excludeTemplateExpression,\n\t\t\t});\n\t\t});\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) {\n\t\treturn {\n\t\t\tanalysis: {\n\t\t\t\tvalid: true,\n\t\t\t\tdiagnostics: [],\n\t\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t\t},\n\t\t\tvalue: template,\n\t\t};\n\t}\n\n\t// ── String template ──────────────────────────────────────────────────\n\t// At root level, if the string contains expressions and exclude is on,\n\t// return null with a valid analysis (no parent to remove from).\n\tif (exclude && shouldExcludeEntry(template)) {\n\t\treturn {\n\t\t\tanalysis: {\n\t\t\t\tvalid: true,\n\t\t\t\tdiagnostics: [],\n\t\t\t\toutputSchema: { type: \"null\" },\n\t\t\t},\n\t\t\tvalue: null,\n\t\t};\n\t}\n\n\treturn processString(template, options?.coerceSchema);\n}\n\n// ─── Internal Utilities ──────────────────────────────────────────────────────\n\n/**\n * Resolves the child `coerceSchema` for a given object key.\n *\n * When a `coerceSchema` is provided, navigates into its `properties`\n * to find the schema for the given key. This allows deeply nested\n * objects to propagate coercion at every level.\n *\n * @param coerceSchema - The parent coercion schema (may be `undefined`)\n * @param key - The object property key\n * @returns The child coercion schema, or `undefined`\n */\nexport function resolveChildCoerceSchema(\n\tcoerceSchema: JSONSchema7 | undefined,\n\tkey: string,\n): JSONSchema7 | undefined {\n\treturn coerceSchema ? resolveSchemaPath(coerceSchema, [key]) : undefined;\n}\n\n/**\n * Determines whether a `TemplateInput` value should be excluded when\n * `excludeTemplateExpression` is enabled.\n *\n * A value is excluded if it is a string containing at least one Handlebars\n * expression (`{{…}}`). Literals (number, boolean, null), plain strings\n * without expressions, objects, and arrays are never excluded at the\n * entry level — objects and arrays are recursively filtered by the\n * dispatching functions themselves.\n *\n * @param input - The template input to check\n * @returns `true` if the input should be excluded\n */\nexport function shouldExcludeEntry(input: TemplateInput): boolean {\n\treturn typeof input === \"string\" && hasHandlebarsExpression(input);\n}\n"],"names":["dispatchAnalyze","dispatchAnalyzeAndExecute","dispatchExecute","resolveChildCoerceSchema","shouldExcludeEntry","template","options","analyzeString","recurse","isArrayInput","exclude","excludeTemplateExpression","kept","filter","item","aggregateArrayAnalysis","length","index","isObjectInput","dispatchObjectAnalysis","isLiteralInput","valid","diagnostics","outputSchema","inferPrimitiveSchema","coerceSchema","keys","Object","key","aggregateObjectAnalysis","childCoerceSchema","identifierSchemas","executeString","elements","result","element","push","processString","aggregateArrayAnalysisAndExecution","aggregateObjectAnalysisAndExecution","identifierData","analysis","value","type","resolveSchemaPath","undefined","input","hasHandlebarsExpression"],"mappings":"mPAoEgBA,yBAAAA,qBA0KAC,mCAAAA,+BA5EAC,yBAAAA,qBAiKAC,kCAAAA,8BAoBAC,4BAAAA,8CAtVwB,+CACN,+CAO3B,qCAMA,cAqDA,SAASJ,gBACfK,QAAuB,CACvBC,OAA2C,CAC3CC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AAM,CAAmBX,SAE5C,CAGA,GAAIY,GAAAA,sBAAa,EAACb,UAAW,CAC5B,MAAMoB,aAAenB,SAASmB,aAC9B,MAAMC,KAAOhB,QACViB,OAAOD,IAAI,CAACrB,UAAUQ,MAAM,CAC5B,AAACe,KAAQ,CAACxB,mBAAmBC,QAAQ,CAACuB,IAAI,GAE1CD,OAAOD,IAAI,CAACrB,UACf,MAAOkC,GAAAA,4CAAmC,EAACb,KAAM,AAACE,MACjD,MAAME,kBAAoB3B,yBAAyBsB,aAAcG,KACjE,OAAOpB,QAAQH,QAAQ,CAACuB,IAAI,CAAmB,CAC9CG,kBAAmBzB,SAASyB,kBAC5BS,eAAgBlC,SAASkC,eACzBf,aAAcK,kBACdnB,0BAA2BL,SAASK,yBACrC,EACD,EACD,CAGA,GAAIS,GAAAA,uBAAc,EAACf,UAAW,CAC7B,MAAO,CACNoC,SAAU,CACTpB,MAAO,KACPC,YAAa,EAAE,CACfC,aAAcC,GAAAA,6BAAoB,EAACnB,SACpC,EACAqC,MAAOrC,QACR,CACD,CAKA,GAAIK,SAAWN,mBAAmBC,UAAW,CAC5C,MAAO,CACNoC,SAAU,CACTpB,MAAO,KACPC,YAAa,EAAE,CACfC,aAAc,CAAEoB,KAAM,MAAO,CAC9B,EACAD,MAAO,IACR,CACD,CAEA,OAAOL,cAAchC,SAAUC,SAASmB,aACzC,CAeO,SAAStB,yBACfsB,YAAqC,CACrCG,GAAW,EAEX,OAAOH,aAAemB,GAAAA,mCAAiB,EAACnB,aAAc,CAACG,IAAI,EAAIiB,SAChE,CAeO,SAASzC,mBAAmB0C,KAAoB,EACtD,OAAO,OAAOA,QAAU,UAAYC,GAAAA,iCAAuB,EAACD,MAC7D"}
|
|
1
|
+
{"version":3,"sources":["../../src/dispatch.ts"],"sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport { hasHandlebarsExpression } from \"./parser.ts\";\nimport { resolveSchemaPath } from \"./schema-resolver.ts\";\nimport type { AnalysisResult, TemplateInput } from \"./types.ts\";\nimport {\n\tinferPrimitiveSchema,\n\tisArrayInput,\n\tisLiteralInput,\n\tisObjectInput,\n} from \"./types.ts\";\nimport {\n\taggregateArrayAnalysis,\n\taggregateArrayAnalysisAndExecution,\n\taggregateObjectAnalysis,\n\taggregateObjectAnalysisAndExecution,\n} from \"./utils.ts\";\n\n// ─── Template Input Dispatching ──────────────────────────────────────────────\n// Factorized dispatching for recursive processing of `TemplateInput` values.\n//\n// Every method in the engine (`analyze`, `execute`, `analyzeAndExecute`,\n// `compile`) follows the same recursive pattern:\n//\n// 1. If the input is an **array** → process each element recursively\n// 2. If the input is an **object** → process each property recursively\n// 3. If the input is a **literal** (number, boolean, null) → passthrough\n// 4. If the input is a **string** → delegate to a template-specific handler\n//\n// This module extracts the common dispatching logic into generic functions\n// that accept a callback for the string (template) case. This eliminates\n// the duplication across `Typebars`, `CompiledTemplate`, and `analyzer.ts`.\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Options controlling recursive dispatching behavior */\nexport interface DispatchAnalyzeOptions {\n\t/** Schemas by template identifier */\n\tidentifierSchemas?: Record<number, JSONSchema7>;\n\t/** Explicit coercion schema for static literal output type */\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n/** Options controlling recursive execution dispatching */\nexport interface DispatchExecuteOptions {\n\t/** Explicit coercion schema for output type coercion */\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n// ─── Analysis Dispatching ────────────────────────────────────────────────────\n\n/**\n * Dispatches a `TemplateInput` for analysis, handling the array/object/literal\n * cases generically and delegating the string (template) case to a callback.\n *\n * @param template - The input to analyze\n * @param options - Dispatching options (coerceSchema, excludeTemplateExpression)\n * @param analyzeString - Callback for analyzing a string template.\n * Receives `(template, coerceSchema?)` and must return an `AnalysisResult`.\n * @param recurse - Callback for recursively analyzing a child `TemplateInput`.\n * Receives `(child, options?)` and must return an `AnalysisResult`.\n * This allows callers (like `Typebars`) to rebind `this` or inject\n * additional context on each recursive call.\n * @returns An `AnalysisResult`\n */\nexport function dispatchAnalyze(\n\ttemplate: TemplateInput,\n\toptions: DispatchAnalyzeOptions | undefined,\n\tanalyzeString: (\n\t\ttemplate: string,\n\t\tcoerceSchema?: JSONSchema7,\n\t) => AnalysisResult,\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeOptions,\n\t) => AnalysisResult,\n): AnalysisResult {\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst exclude = options?.excludeTemplateExpression === true;\n\t\tconst childOptions = resolveArrayChildOptions(options);\n\t\tif (exclude) {\n\t\t\tconst kept = template.filter(\n\t\t\t\t(item) => !shouldExcludeEntry(item as TemplateInput),\n\t\t\t);\n\t\t\treturn aggregateArrayAnalysis(kept.length, (index) =>\n\t\t\t\trecurse(kept[index] as TemplateInput, childOptions),\n\t\t\t);\n\t\t}\n\t\treturn aggregateArrayAnalysis(template.length, (index) =>\n\t\t\trecurse(template[index] as TemplateInput, childOptions),\n\t\t);\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\treturn dispatchObjectAnalysis(template, options, recurse);\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) {\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\tdiagnostics: [],\n\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t};\n\t}\n\n\t// ── String template ──────────────────────────────────────────────────\n\treturn analyzeString(template, options?.coerceSchema);\n}\n\n/**\n * Dispatches object analysis with `coerceSchema` propagation and\n * `excludeTemplateExpression` filtering.\n *\n * Extracted as a separate function because the object case is the most\n * complex (key filtering + per-key coerceSchema resolution).\n */\nfunction dispatchObjectAnalysis(\n\ttemplate: Record<string, TemplateInput>,\n\toptions: DispatchAnalyzeOptions | undefined,\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeOptions,\n\t) => AnalysisResult,\n): AnalysisResult {\n\tconst coerceSchema = options?.coerceSchema;\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\tconst keys = exclude\n\t\t? Object.keys(template).filter(\n\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t)\n\t\t: Object.keys(template);\n\n\treturn aggregateObjectAnalysis(keys, (key) => {\n\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\treturn recurse(template[key] as TemplateInput, {\n\t\t\tidentifierSchemas: options?.identifierSchemas,\n\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\texcludeTemplateExpression: options?.excludeTemplateExpression,\n\t\t});\n\t});\n}\n\n// ─── Execution Dispatching ───────────────────────────────────────────────────\n\n/**\n * Dispatches a `TemplateInput` for execution, handling the array/object/literal\n * cases generically and delegating the string (template) case to a callback.\n *\n * @param template - The input to execute\n * @param options - Dispatching options (coerceSchema)\n * @param executeString - Callback for executing a string template.\n * Receives `(template, coerceSchema?)` and must return the result.\n * @param recurse - Callback for recursively executing a child `TemplateInput`.\n * Receives `(child, options?)` and must return the result.\n * @returns The execution result\n */\nexport function dispatchExecute(\n\ttemplate: TemplateInput,\n\toptions: DispatchExecuteOptions | undefined,\n\texecuteString: (template: string, coerceSchema?: JSONSchema7) => unknown,\n\trecurse: (child: TemplateInput, options?: DispatchExecuteOptions) => unknown,\n): unknown {\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst childOptions = resolveArrayChildOptions(options);\n\t\tconst elements = exclude\n\t\t\t? template.filter((item) => !shouldExcludeEntry(item as TemplateInput))\n\t\t\t: template;\n\t\tconst result: unknown[] = [];\n\t\tfor (const element of elements) {\n\t\t\tresult.push(recurse(element as TemplateInput, childOptions));\n\t\t}\n\t\treturn result;\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\tconst coerceSchema = options?.coerceSchema;\n\t\tconst result: Record<string, unknown> = {};\n\t\tconst keys = exclude\n\t\t\t? Object.keys(template).filter(\n\t\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t\t)\n\t\t\t: Object.keys(template);\n\t\tfor (const key of keys) {\n\t\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\t\tresult[key] = recurse(template[key] as TemplateInput, {\n\t\t\t\t...options,\n\t\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) return template;\n\n\t// ── String template ──────────────────────────────────────────────────\n\t// At root level, if the string contains expressions and exclude is on,\n\t// return null (there is no parent to remove it from).\n\tif (exclude && shouldExcludeEntry(template)) {\n\t\treturn null;\n\t}\n\n\treturn executeString(template, options?.coerceSchema);\n}\n\n// ─── Analyze-and-Execute Dispatching ─────────────────────────────────────────\n\n/** Options for combined analyze-and-execute dispatching */\nexport interface DispatchAnalyzeAndExecuteOptions {\n\tidentifierSchemas?: Record<number, JSONSchema7>;\n\tidentifierData?: Record<number, Record<string, unknown>>;\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n/**\n * Dispatches a `TemplateInput` for combined analysis and execution,\n * handling array/object/literal cases generically and delegating\n * the string case to a callback.\n *\n * @param template - The input to process\n * @param options - Options (identifierSchemas, identifierData, coerceSchema)\n * @param processString - Callback for analyzing and executing a string template.\n * Receives `(template, coerceSchema?)` and must return\n * `{ analysis, value }`.\n * @param recurse - Callback for recursively processing a child `TemplateInput`.\n * @returns `{ analysis, value }` where `value` is `undefined` if analysis fails\n */\nexport function dispatchAnalyzeAndExecute(\n\ttemplate: TemplateInput,\n\toptions: DispatchAnalyzeAndExecuteOptions | undefined,\n\tprocessString: (\n\t\ttemplate: string,\n\t\tcoerceSchema?: JSONSchema7,\n\t) => { analysis: AnalysisResult; value: unknown },\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeAndExecuteOptions,\n\t) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst childOptions = resolveArrayChildOptions(options);\n\t\tconst elements = exclude\n\t\t\t? template.filter((item) => !shouldExcludeEntry(item as TemplateInput))\n\t\t\t: template;\n\t\treturn aggregateArrayAnalysisAndExecution(elements.length, (index) =>\n\t\t\trecurse(elements[index] as TemplateInput, childOptions),\n\t\t);\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\tconst coerceSchema = options?.coerceSchema;\n\t\tconst keys = exclude\n\t\t\t? Object.keys(template).filter(\n\t\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t\t)\n\t\t\t: Object.keys(template);\n\t\treturn aggregateObjectAnalysisAndExecution(keys, (key) => {\n\t\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\t\treturn recurse(template[key] as TemplateInput, {\n\t\t\t\tidentifierSchemas: options?.identifierSchemas,\n\t\t\t\tidentifierData: options?.identifierData,\n\t\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\t\texcludeTemplateExpression: options?.excludeTemplateExpression,\n\t\t\t});\n\t\t});\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) {\n\t\treturn {\n\t\t\tanalysis: {\n\t\t\t\tvalid: true,\n\t\t\t\tdiagnostics: [],\n\t\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t\t},\n\t\t\tvalue: template,\n\t\t};\n\t}\n\n\t// ── String template ──────────────────────────────────────────────────\n\t// At root level, if the string contains expressions and exclude is on,\n\t// return null with a valid analysis (no parent to remove from).\n\tif (exclude && shouldExcludeEntry(template)) {\n\t\treturn {\n\t\t\tanalysis: {\n\t\t\t\tvalid: true,\n\t\t\t\tdiagnostics: [],\n\t\t\t\toutputSchema: { type: \"null\" },\n\t\t\t},\n\t\t\tvalue: null,\n\t\t};\n\t}\n\n\treturn processString(template, options?.coerceSchema);\n}\n\n// ─── Internal Utilities ──────────────────────────────────────────────────────\n\n/**\n * Resolves the child options for array element recursion.\n *\n * When a `coerceSchema` with `items` is provided, the child options\n * will use `coerceSchema.items` as the element-level coercion schema.\n * All other options are passed through unchanged.\n *\n * @param options - The parent dispatching options (may be `undefined`)\n * @returns New options with `coerceSchema` resolved to the items schema, or\n * the original options if no items schema is available.\n */\nfunction resolveArrayChildOptions<\n\tT extends { coerceSchema?: JSONSchema7 } | undefined,\n>(options: T): T {\n\tif (!options?.coerceSchema) return options;\n\n\tconst itemsSchema = resolveItemsCoerceSchema(options.coerceSchema);\n\tif (itemsSchema === options.coerceSchema) return options;\n\n\treturn { ...options, coerceSchema: itemsSchema };\n}\n\n/**\n * Extracts the `items` schema from an array-typed `coerceSchema`.\n *\n * If the schema declares `items` as a single schema (not a tuple),\n * returns that schema. Otherwise returns `undefined`.\n *\n * @param coerceSchema - The parent coercion schema\n * @returns The items coercion schema, or `undefined`\n */\nfunction resolveItemsCoerceSchema(\n\tcoerceSchema: JSONSchema7,\n): JSONSchema7 | undefined {\n\tif (typeof coerceSchema === \"boolean\") return undefined;\n\n\tconst items = coerceSchema.items;\n\tif (items != null && typeof items === \"object\" && !Array.isArray(items)) {\n\t\treturn items as JSONSchema7;\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Resolves the child `coerceSchema` for a given object key.\n *\n * When a `coerceSchema` is provided, navigates into its `properties`\n * to find the schema for the given key. This allows deeply nested\n * objects to propagate coercion at every level.\n *\n * @param coerceSchema - The parent coercion schema (may be `undefined`)\n * @param key - The object property key\n * @returns The child coercion schema, or `undefined`\n */\nexport function resolveChildCoerceSchema(\n\tcoerceSchema: JSONSchema7 | undefined,\n\tkey: string,\n): JSONSchema7 | undefined {\n\treturn coerceSchema ? resolveSchemaPath(coerceSchema, [key]) : undefined;\n}\n\n/**\n * Determines whether a `TemplateInput` value should be excluded when\n * `excludeTemplateExpression` is enabled.\n *\n * A value is excluded if it is a string containing at least one Handlebars\n * expression (`{{…}}`). Literals (number, boolean, null), plain strings\n * without expressions, objects, and arrays are never excluded at the\n * entry level — objects and arrays are recursively filtered by the\n * dispatching functions themselves.\n *\n * @param input - The template input to check\n * @returns `true` if the input should be excluded\n */\nexport function shouldExcludeEntry(input: TemplateInput): boolean {\n\treturn typeof input === \"string\" && hasHandlebarsExpression(input);\n}\n"],"names":["dispatchAnalyze","dispatchAnalyzeAndExecute","dispatchExecute","resolveChildCoerceSchema","shouldExcludeEntry","template","options","analyzeString","recurse","isArrayInput","exclude","excludeTemplateExpression","childOptions","resolveArrayChildOptions","kept","filter","item","aggregateArrayAnalysis","length","index","isObjectInput","dispatchObjectAnalysis","isLiteralInput","valid","diagnostics","outputSchema","inferPrimitiveSchema","coerceSchema","keys","Object","key","aggregateObjectAnalysis","childCoerceSchema","identifierSchemas","executeString","elements","result","element","push","processString","aggregateArrayAnalysisAndExecution","aggregateObjectAnalysisAndExecution","identifierData","analysis","value","type","itemsSchema","resolveItemsCoerceSchema","undefined","items","Array","isArray","resolveSchemaPath","input","hasHandlebarsExpression"],"mappings":"mPAoEgBA,yBAAAA,qBA4KAC,mCAAAA,+BA7EAC,yBAAAA,qBA+MAC,kCAAAA,8BAoBAC,4BAAAA,8CArYwB,+CACN,+CAO3B,qCAMA,cAqDA,SAASJ,gBACfK,QAAuB,CACvBC,OAA2C,CAC3CC,aAGmB,CACnBC,OAGmB,EAGnB,GAAIC,GAAAA,qBAAY,EAACJ,UAAW,CAC3B,MAAMK,QAAUJ,SAASK,4BAA8B,KACvD,MAAMC,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,MAAMC,OAAO,CAACF,OAAQ,CACxE,OAAOA,KACR,CAEA,OAAOD,SACR,CAaO,SAAS7C,yBACfwB,YAAqC,CACrCG,GAAW,EAEX,OAAOH,aAAeyB,GAAAA,mCAAiB,EAACzB,aAAc,CAACG,IAAI,EAAIkB,SAChE,CAeO,SAAS5C,mBAAmBiD,KAAoB,EACtD,OAAO,OAAOA,QAAU,UAAYC,GAAAA,iCAAuB,EAACD,MAC7D"}
|
package/dist/esm/dispatch.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{hasHandlebarsExpression}from"./parser.js";import{resolveSchemaPath}from"./schema-resolver.js";import{inferPrimitiveSchema,isArrayInput,isLiteralInput,isObjectInput}from"./types.js";import{aggregateArrayAnalysis,aggregateArrayAnalysisAndExecution,aggregateObjectAnalysis,aggregateObjectAnalysisAndExecution}from"./utils.js";export function dispatchAnalyze(template,options,analyzeString,recurse){if(isArrayInput(template)){const exclude=options?.excludeTemplateExpression===true;if(exclude){const kept=template.filter(item=>!shouldExcludeEntry(item));return aggregateArrayAnalysis(kept.length,index=>recurse(kept[index],
|
|
1
|
+
import{hasHandlebarsExpression}from"./parser.js";import{resolveSchemaPath}from"./schema-resolver.js";import{inferPrimitiveSchema,isArrayInput,isLiteralInput,isObjectInput}from"./types.js";import{aggregateArrayAnalysis,aggregateArrayAnalysisAndExecution,aggregateObjectAnalysis,aggregateObjectAnalysisAndExecution}from"./utils.js";export function dispatchAnalyze(template,options,analyzeString,recurse){if(isArrayInput(template)){const exclude=options?.excludeTemplateExpression===true;const childOptions=resolveArrayChildOptions(options);if(exclude){const kept=template.filter(item=>!shouldExcludeEntry(item));return aggregateArrayAnalysis(kept.length,index=>recurse(kept[index],childOptions))}return aggregateArrayAnalysis(template.length,index=>recurse(template[index],childOptions))}if(isObjectInput(template)){return dispatchObjectAnalysis(template,options,recurse)}if(isLiteralInput(template)){return{valid:true,diagnostics:[],outputSchema:inferPrimitiveSchema(template)}}return analyzeString(template,options?.coerceSchema)}function dispatchObjectAnalysis(template,options,recurse){const coerceSchema=options?.coerceSchema;const exclude=options?.excludeTemplateExpression===true;const keys=exclude?Object.keys(template).filter(key=>!shouldExcludeEntry(template[key])):Object.keys(template);return aggregateObjectAnalysis(keys,key=>{const childCoerceSchema=resolveChildCoerceSchema(coerceSchema,key);return recurse(template[key],{identifierSchemas:options?.identifierSchemas,coerceSchema:childCoerceSchema,excludeTemplateExpression:options?.excludeTemplateExpression})})}export function dispatchExecute(template,options,executeString,recurse){const exclude=options?.excludeTemplateExpression===true;if(isArrayInput(template)){const childOptions=resolveArrayChildOptions(options);const elements=exclude?template.filter(item=>!shouldExcludeEntry(item)):template;const result=[];for(const element of elements){result.push(recurse(element,childOptions))}return result}if(isObjectInput(template)){const coerceSchema=options?.coerceSchema;const result={};const keys=exclude?Object.keys(template).filter(key=>!shouldExcludeEntry(template[key])):Object.keys(template);for(const key of keys){const childCoerceSchema=resolveChildCoerceSchema(coerceSchema,key);result[key]=recurse(template[key],{...options,coerceSchema:childCoerceSchema})}return result}if(isLiteralInput(template))return template;if(exclude&&shouldExcludeEntry(template)){return null}return executeString(template,options?.coerceSchema)}export function dispatchAnalyzeAndExecute(template,options,processString,recurse){const exclude=options?.excludeTemplateExpression===true;if(isArrayInput(template)){const childOptions=resolveArrayChildOptions(options);const elements=exclude?template.filter(item=>!shouldExcludeEntry(item)):template;return aggregateArrayAnalysisAndExecution(elements.length,index=>recurse(elements[index],childOptions))}if(isObjectInput(template)){const coerceSchema=options?.coerceSchema;const keys=exclude?Object.keys(template).filter(key=>!shouldExcludeEntry(template[key])):Object.keys(template);return aggregateObjectAnalysisAndExecution(keys,key=>{const childCoerceSchema=resolveChildCoerceSchema(coerceSchema,key);return recurse(template[key],{identifierSchemas:options?.identifierSchemas,identifierData:options?.identifierData,coerceSchema:childCoerceSchema,excludeTemplateExpression:options?.excludeTemplateExpression})})}if(isLiteralInput(template)){return{analysis:{valid:true,diagnostics:[],outputSchema:inferPrimitiveSchema(template)},value:template}}if(exclude&&shouldExcludeEntry(template)){return{analysis:{valid:true,diagnostics:[],outputSchema:{type:"null"}},value:null}}return processString(template,options?.coerceSchema)}function resolveArrayChildOptions(options){if(!options?.coerceSchema)return options;const itemsSchema=resolveItemsCoerceSchema(options.coerceSchema);if(itemsSchema===options.coerceSchema)return options;return{...options,coerceSchema:itemsSchema}}function resolveItemsCoerceSchema(coerceSchema){if(typeof coerceSchema==="boolean")return undefined;const items=coerceSchema.items;if(items!=null&&typeof items==="object"&&!Array.isArray(items)){return items}return undefined}export function resolveChildCoerceSchema(coerceSchema,key){return coerceSchema?resolveSchemaPath(coerceSchema,[key]):undefined}export function shouldExcludeEntry(input){return typeof input==="string"&&hasHandlebarsExpression(input)}
|
|
2
2
|
//# sourceMappingURL=dispatch.js.map
|
package/dist/esm/dispatch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/dispatch.ts"],"sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport { hasHandlebarsExpression } from \"./parser.ts\";\nimport { resolveSchemaPath } from \"./schema-resolver.ts\";\nimport type { AnalysisResult, TemplateInput } from \"./types.ts\";\nimport {\n\tinferPrimitiveSchema,\n\tisArrayInput,\n\tisLiteralInput,\n\tisObjectInput,\n} from \"./types.ts\";\nimport {\n\taggregateArrayAnalysis,\n\taggregateArrayAnalysisAndExecution,\n\taggregateObjectAnalysis,\n\taggregateObjectAnalysisAndExecution,\n} from \"./utils.ts\";\n\n// ─── Template Input Dispatching ──────────────────────────────────────────────\n// Factorized dispatching for recursive processing of `TemplateInput` values.\n//\n// Every method in the engine (`analyze`, `execute`, `analyzeAndExecute`,\n// `compile`) follows the same recursive pattern:\n//\n// 1. If the input is an **array** → process each element recursively\n// 2. If the input is an **object** → process each property recursively\n// 3. If the input is a **literal** (number, boolean, null) → passthrough\n// 4. If the input is a **string** → delegate to a template-specific handler\n//\n// This module extracts the common dispatching logic into generic functions\n// that accept a callback for the string (template) case. This eliminates\n// the duplication across `Typebars`, `CompiledTemplate`, and `analyzer.ts`.\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Options controlling recursive dispatching behavior */\nexport interface DispatchAnalyzeOptions {\n\t/** Schemas by template identifier */\n\tidentifierSchemas?: Record<number, JSONSchema7>;\n\t/** Explicit coercion schema for static literal output type */\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n/** Options controlling recursive execution dispatching */\nexport interface DispatchExecuteOptions {\n\t/** Explicit coercion schema for output type coercion */\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n// ─── Analysis Dispatching ────────────────────────────────────────────────────\n\n/**\n * Dispatches a `TemplateInput` for analysis, handling the array/object/literal\n * cases generically and delegating the string (template) case to a callback.\n *\n * @param template - The input to analyze\n * @param options - Dispatching options (coerceSchema, excludeTemplateExpression)\n * @param analyzeString - Callback for analyzing a string template.\n * Receives `(template, coerceSchema?)` and must return an `AnalysisResult`.\n * @param recurse - Callback for recursively analyzing a child `TemplateInput`.\n * Receives `(child, options?)` and must return an `AnalysisResult`.\n * This allows callers (like `Typebars`) to rebind `this` or inject\n * additional context on each recursive call.\n * @returns An `AnalysisResult`\n */\nexport function dispatchAnalyze(\n\ttemplate: TemplateInput,\n\toptions: DispatchAnalyzeOptions | undefined,\n\tanalyzeString: (\n\t\ttemplate: string,\n\t\tcoerceSchema?: JSONSchema7,\n\t) => AnalysisResult,\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeOptions,\n\t) => AnalysisResult,\n): AnalysisResult {\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst exclude = options?.excludeTemplateExpression === true;\n\t\tif (exclude) {\n\t\t\tconst kept = template.filter(\n\t\t\t\t(item) => !shouldExcludeEntry(item as TemplateInput),\n\t\t\t);\n\t\t\treturn aggregateArrayAnalysis(kept.length, (index) =>\n\t\t\t\trecurse(kept[index] as TemplateInput, options),\n\t\t\t);\n\t\t}\n\t\treturn aggregateArrayAnalysis(template.length, (index) =>\n\t\t\trecurse(template[index] as TemplateInput, options),\n\t\t);\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\treturn dispatchObjectAnalysis(template, options, recurse);\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) {\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\tdiagnostics: [],\n\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t};\n\t}\n\n\t// ── String template ──────────────────────────────────────────────────\n\treturn analyzeString(template, options?.coerceSchema);\n}\n\n/**\n * Dispatches object analysis with `coerceSchema` propagation and\n * `excludeTemplateExpression` filtering.\n *\n * Extracted as a separate function because the object case is the most\n * complex (key filtering + per-key coerceSchema resolution).\n */\nfunction dispatchObjectAnalysis(\n\ttemplate: Record<string, TemplateInput>,\n\toptions: DispatchAnalyzeOptions | undefined,\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeOptions,\n\t) => AnalysisResult,\n): AnalysisResult {\n\tconst coerceSchema = options?.coerceSchema;\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\tconst keys = exclude\n\t\t? Object.keys(template).filter(\n\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t)\n\t\t: Object.keys(template);\n\n\treturn aggregateObjectAnalysis(keys, (key) => {\n\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\treturn recurse(template[key] as TemplateInput, {\n\t\t\tidentifierSchemas: options?.identifierSchemas,\n\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\texcludeTemplateExpression: options?.excludeTemplateExpression,\n\t\t});\n\t});\n}\n\n// ─── Execution Dispatching ───────────────────────────────────────────────────\n\n/**\n * Dispatches a `TemplateInput` for execution, handling the array/object/literal\n * cases generically and delegating the string (template) case to a callback.\n *\n * @param template - The input to execute\n * @param options - Dispatching options (coerceSchema)\n * @param executeString - Callback for executing a string template.\n * Receives `(template, coerceSchema?)` and must return the result.\n * @param recurse - Callback for recursively executing a child `TemplateInput`.\n * Receives `(child, options?)` and must return the result.\n * @returns The execution result\n */\nexport function dispatchExecute(\n\ttemplate: TemplateInput,\n\toptions: DispatchExecuteOptions | undefined,\n\texecuteString: (template: string, coerceSchema?: JSONSchema7) => unknown,\n\trecurse: (child: TemplateInput, options?: DispatchExecuteOptions) => unknown,\n): unknown {\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst elements = exclude\n\t\t\t? template.filter((item) => !shouldExcludeEntry(item as TemplateInput))\n\t\t\t: template;\n\t\tconst result: unknown[] = [];\n\t\tfor (const element of elements) {\n\t\t\tresult.push(recurse(element as TemplateInput, options));\n\t\t}\n\t\treturn result;\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\tconst coerceSchema = options?.coerceSchema;\n\t\tconst result: Record<string, unknown> = {};\n\t\tconst keys = exclude\n\t\t\t? Object.keys(template).filter(\n\t\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t\t)\n\t\t\t: Object.keys(template);\n\t\tfor (const key of keys) {\n\t\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\t\tresult[key] = recurse(template[key] as TemplateInput, {\n\t\t\t\t...options,\n\t\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) return template;\n\n\t// ── String template ──────────────────────────────────────────────────\n\t// At root level, if the string contains expressions and exclude is on,\n\t// return null (there is no parent to remove it from).\n\tif (exclude && shouldExcludeEntry(template)) {\n\t\treturn null;\n\t}\n\n\treturn executeString(template, options?.coerceSchema);\n}\n\n// ─── Analyze-and-Execute Dispatching ─────────────────────────────────────────\n\n/** Options for combined analyze-and-execute dispatching */\nexport interface DispatchAnalyzeAndExecuteOptions {\n\tidentifierSchemas?: Record<number, JSONSchema7>;\n\tidentifierData?: Record<number, Record<string, unknown>>;\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n/**\n * Dispatches a `TemplateInput` for combined analysis and execution,\n * handling array/object/literal cases generically and delegating\n * the string case to a callback.\n *\n * @param template - The input to process\n * @param options - Options (identifierSchemas, identifierData, coerceSchema)\n * @param processString - Callback for analyzing and executing a string template.\n * Receives `(template, coerceSchema?)` and must return\n * `{ analysis, value }`.\n * @param recurse - Callback for recursively processing a child `TemplateInput`.\n * @returns `{ analysis, value }` where `value` is `undefined` if analysis fails\n */\nexport function dispatchAnalyzeAndExecute(\n\ttemplate: TemplateInput,\n\toptions: DispatchAnalyzeAndExecuteOptions | undefined,\n\tprocessString: (\n\t\ttemplate: string,\n\t\tcoerceSchema?: JSONSchema7,\n\t) => { analysis: AnalysisResult; value: unknown },\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeAndExecuteOptions,\n\t) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst elements = exclude\n\t\t\t? template.filter((item) => !shouldExcludeEntry(item as TemplateInput))\n\t\t\t: template;\n\t\treturn aggregateArrayAnalysisAndExecution(elements.length, (index) =>\n\t\t\trecurse(elements[index] as TemplateInput, options),\n\t\t);\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\tconst coerceSchema = options?.coerceSchema;\n\t\tconst keys = exclude\n\t\t\t? Object.keys(template).filter(\n\t\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t\t)\n\t\t\t: Object.keys(template);\n\t\treturn aggregateObjectAnalysisAndExecution(keys, (key) => {\n\t\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\t\treturn recurse(template[key] as TemplateInput, {\n\t\t\t\tidentifierSchemas: options?.identifierSchemas,\n\t\t\t\tidentifierData: options?.identifierData,\n\t\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\t\texcludeTemplateExpression: options?.excludeTemplateExpression,\n\t\t\t});\n\t\t});\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) {\n\t\treturn {\n\t\t\tanalysis: {\n\t\t\t\tvalid: true,\n\t\t\t\tdiagnostics: [],\n\t\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t\t},\n\t\t\tvalue: template,\n\t\t};\n\t}\n\n\t// ── String template ──────────────────────────────────────────────────\n\t// At root level, if the string contains expressions and exclude is on,\n\t// return null with a valid analysis (no parent to remove from).\n\tif (exclude && shouldExcludeEntry(template)) {\n\t\treturn {\n\t\t\tanalysis: {\n\t\t\t\tvalid: true,\n\t\t\t\tdiagnostics: [],\n\t\t\t\toutputSchema: { type: \"null\" },\n\t\t\t},\n\t\t\tvalue: null,\n\t\t};\n\t}\n\n\treturn processString(template, options?.coerceSchema);\n}\n\n// ─── Internal Utilities ──────────────────────────────────────────────────────\n\n/**\n * Resolves the child `coerceSchema` for a given object key.\n *\n * When a `coerceSchema` is provided, navigates into its `properties`\n * to find the schema for the given key. This allows deeply nested\n * objects to propagate coercion at every level.\n *\n * @param coerceSchema - The parent coercion schema (may be `undefined`)\n * @param key - The object property key\n * @returns The child coercion schema, or `undefined`\n */\nexport function resolveChildCoerceSchema(\n\tcoerceSchema: JSONSchema7 | undefined,\n\tkey: string,\n): JSONSchema7 | undefined {\n\treturn coerceSchema ? resolveSchemaPath(coerceSchema, [key]) : undefined;\n}\n\n/**\n * Determines whether a `TemplateInput` value should be excluded when\n * `excludeTemplateExpression` is enabled.\n *\n * A value is excluded if it is a string containing at least one Handlebars\n * expression (`{{…}}`). Literals (number, boolean, null), plain strings\n * without expressions, objects, and arrays are never excluded at the\n * entry level — objects and arrays are recursively filtered by the\n * dispatching functions themselves.\n *\n * @param input - The template input to check\n * @returns `true` if the input should be excluded\n */\nexport function shouldExcludeEntry(input: TemplateInput): boolean {\n\treturn typeof input === \"string\" && hasHandlebarsExpression(input);\n}\n"],"names":["hasHandlebarsExpression","resolveSchemaPath","inferPrimitiveSchema","isArrayInput","isLiteralInput","isObjectInput","aggregateArrayAnalysis","aggregateArrayAnalysisAndExecution","aggregateObjectAnalysis","aggregateObjectAnalysisAndExecution","dispatchAnalyze","template","options","analyzeString","recurse","exclude","excludeTemplateExpression","kept","filter","item","shouldExcludeEntry","length","index","dispatchObjectAnalysis","valid","diagnostics","outputSchema","coerceSchema","keys","Object","key","childCoerceSchema","resolveChildCoerceSchema","identifierSchemas","dispatchExecute","executeString","elements","result","element","push","dispatchAnalyzeAndExecute","processString","identifierData","analysis","value","type","undefined","input"],"mappings":"AACA,OAASA,uBAAuB,KAAQ,aAAc,AACtD,QAASC,iBAAiB,KAAQ,sBAAuB,AAEzD,QACCC,oBAAoB,CACpBC,YAAY,CACZC,cAAc,CACdC,aAAa,KACP,YAAa,AACpB,QACCC,sBAAsB,CACtBC,kCAAkC,CAClCC,uBAAuB,CACvBC,mCAAmC,KAC7B,YAAa,AAqDpB,QAAO,SAASC,gBACfC,QAAuB,CACvBC,OAA2C,CAC3CC,aAGmB,CACnBC,OAGmB,EAGnB,GAAIX,aAAaQ,UAAW,CAC3B,MAAMI,QAAUH,SAASI,4BAA8B,KACvD,GAAID,QAAS,CACZ,MAAME,KAAON,SAASO,MAAM,CAC3B,AAACC,MAAS,CAACC,mBAAmBD,OAE/B,OAAOb,uBAAuBW,KAAKI,MAAM,CAAE,AAACC,OAC3CR,QAA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8B,eACzBf,aAAcI,kBACdf,0BAA2BJ,SAASI,yBACrC,EACD,EACD,CAGA,GAAIZ,eAAeO,UAAW,CAC7B,MAAO,CACNgC,SAAU,CACTnB,MAAO,KACPC,YAAa,EAAE,CACfC,aAAcxB,qBAAqBS,SACpC,EACAiC,MAAOjC,QACR,CACD,CAKA,GAAII,SAAWK,mBAAmBT,UAAW,CAC5C,MAAO,CACNgC,SAAU,CACTnB,MAAO,KACPC,YAAa,EAAE,CACfC,aAAc,CAAEmB,KAAM,MAAO,CAC9B,EACAD,MAAO,IACR,CACD,CAEA,OAAOH,cAAc9B,SAAUC,SAASe,aACzC,CAeA,OAAO,SAASK,yBACfL,YAAqC,CACrCG,GAAW,EAEX,OAAOH,aAAe1B,kBAAkB0B,aAAc,CAACG,IAAI,EAAIgB,SAChE,CAeA,OAAO,SAAS1B,mBAAmB2B,KAAoB,EACtD,OAAO,OAAOA,QAAU,UAAY/C,wBAAwB+C,MAC7D"}
|
|
1
|
+
{"version":3,"sources":["../../src/dispatch.ts"],"sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport { hasHandlebarsExpression } from \"./parser.ts\";\nimport { resolveSchemaPath } from \"./schema-resolver.ts\";\nimport type { AnalysisResult, TemplateInput } from \"./types.ts\";\nimport {\n\tinferPrimitiveSchema,\n\tisArrayInput,\n\tisLiteralInput,\n\tisObjectInput,\n} from \"./types.ts\";\nimport {\n\taggregateArrayAnalysis,\n\taggregateArrayAnalysisAndExecution,\n\taggregateObjectAnalysis,\n\taggregateObjectAnalysisAndExecution,\n} from \"./utils.ts\";\n\n// ─── Template Input Dispatching ──────────────────────────────────────────────\n// Factorized dispatching for recursive processing of `TemplateInput` values.\n//\n// Every method in the engine (`analyze`, `execute`, `analyzeAndExecute`,\n// `compile`) follows the same recursive pattern:\n//\n// 1. If the input is an **array** → process each element recursively\n// 2. If the input is an **object** → process each property recursively\n// 3. If the input is a **literal** (number, boolean, null) → passthrough\n// 4. If the input is a **string** → delegate to a template-specific handler\n//\n// This module extracts the common dispatching logic into generic functions\n// that accept a callback for the string (template) case. This eliminates\n// the duplication across `Typebars`, `CompiledTemplate`, and `analyzer.ts`.\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Options controlling recursive dispatching behavior */\nexport interface DispatchAnalyzeOptions {\n\t/** Schemas by template identifier */\n\tidentifierSchemas?: Record<number, JSONSchema7>;\n\t/** Explicit coercion schema for static literal output type */\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n/** Options controlling recursive execution dispatching */\nexport interface DispatchExecuteOptions {\n\t/** Explicit coercion schema for output type coercion */\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n// ─── Analysis Dispatching ────────────────────────────────────────────────────\n\n/**\n * Dispatches a `TemplateInput` for analysis, handling the array/object/literal\n * cases generically and delegating the string (template) case to a callback.\n *\n * @param template - The input to analyze\n * @param options - Dispatching options (coerceSchema, excludeTemplateExpression)\n * @param analyzeString - Callback for analyzing a string template.\n * Receives `(template, coerceSchema?)` and must return an `AnalysisResult`.\n * @param recurse - Callback for recursively analyzing a child `TemplateInput`.\n * Receives `(child, options?)` and must return an `AnalysisResult`.\n * This allows callers (like `Typebars`) to rebind `this` or inject\n * additional context on each recursive call.\n * @returns An `AnalysisResult`\n */\nexport function dispatchAnalyze(\n\ttemplate: TemplateInput,\n\toptions: DispatchAnalyzeOptions | undefined,\n\tanalyzeString: (\n\t\ttemplate: string,\n\t\tcoerceSchema?: JSONSchema7,\n\t) => AnalysisResult,\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeOptions,\n\t) => AnalysisResult,\n): AnalysisResult {\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst exclude = options?.excludeTemplateExpression === true;\n\t\tconst childOptions = resolveArrayChildOptions(options);\n\t\tif (exclude) {\n\t\t\tconst kept = template.filter(\n\t\t\t\t(item) => !shouldExcludeEntry(item as TemplateInput),\n\t\t\t);\n\t\t\treturn aggregateArrayAnalysis(kept.length, (index) =>\n\t\t\t\trecurse(kept[index] as TemplateInput, childOptions),\n\t\t\t);\n\t\t}\n\t\treturn aggregateArrayAnalysis(template.length, (index) =>\n\t\t\trecurse(template[index] as TemplateInput, childOptions),\n\t\t);\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\treturn dispatchObjectAnalysis(template, options, recurse);\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) {\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\tdiagnostics: [],\n\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t};\n\t}\n\n\t// ── String template ──────────────────────────────────────────────────\n\treturn analyzeString(template, options?.coerceSchema);\n}\n\n/**\n * Dispatches object analysis with `coerceSchema` propagation and\n * `excludeTemplateExpression` filtering.\n *\n * Extracted as a separate function because the object case is the most\n * complex (key filtering + per-key coerceSchema resolution).\n */\nfunction dispatchObjectAnalysis(\n\ttemplate: Record<string, TemplateInput>,\n\toptions: DispatchAnalyzeOptions | undefined,\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeOptions,\n\t) => AnalysisResult,\n): AnalysisResult {\n\tconst coerceSchema = options?.coerceSchema;\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\tconst keys = exclude\n\t\t? Object.keys(template).filter(\n\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t)\n\t\t: Object.keys(template);\n\n\treturn aggregateObjectAnalysis(keys, (key) => {\n\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\treturn recurse(template[key] as TemplateInput, {\n\t\t\tidentifierSchemas: options?.identifierSchemas,\n\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\texcludeTemplateExpression: options?.excludeTemplateExpression,\n\t\t});\n\t});\n}\n\n// ─── Execution Dispatching ───────────────────────────────────────────────────\n\n/**\n * Dispatches a `TemplateInput` for execution, handling the array/object/literal\n * cases generically and delegating the string (template) case to a callback.\n *\n * @param template - The input to execute\n * @param options - Dispatching options (coerceSchema)\n * @param executeString - Callback for executing a string template.\n * Receives `(template, coerceSchema?)` and must return the result.\n * @param recurse - Callback for recursively executing a child `TemplateInput`.\n * Receives `(child, options?)` and must return the result.\n * @returns The execution result\n */\nexport function dispatchExecute(\n\ttemplate: TemplateInput,\n\toptions: DispatchExecuteOptions | undefined,\n\texecuteString: (template: string, coerceSchema?: JSONSchema7) => unknown,\n\trecurse: (child: TemplateInput, options?: DispatchExecuteOptions) => unknown,\n): unknown {\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst childOptions = resolveArrayChildOptions(options);\n\t\tconst elements = exclude\n\t\t\t? template.filter((item) => !shouldExcludeEntry(item as TemplateInput))\n\t\t\t: template;\n\t\tconst result: unknown[] = [];\n\t\tfor (const element of elements) {\n\t\t\tresult.push(recurse(element as TemplateInput, childOptions));\n\t\t}\n\t\treturn result;\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\tconst coerceSchema = options?.coerceSchema;\n\t\tconst result: Record<string, unknown> = {};\n\t\tconst keys = exclude\n\t\t\t? Object.keys(template).filter(\n\t\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t\t)\n\t\t\t: Object.keys(template);\n\t\tfor (const key of keys) {\n\t\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\t\tresult[key] = recurse(template[key] as TemplateInput, {\n\t\t\t\t...options,\n\t\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) return template;\n\n\t// ── String template ──────────────────────────────────────────────────\n\t// At root level, if the string contains expressions and exclude is on,\n\t// return null (there is no parent to remove it from).\n\tif (exclude && shouldExcludeEntry(template)) {\n\t\treturn null;\n\t}\n\n\treturn executeString(template, options?.coerceSchema);\n}\n\n// ─── Analyze-and-Execute Dispatching ─────────────────────────────────────────\n\n/** Options for combined analyze-and-execute dispatching */\nexport interface DispatchAnalyzeAndExecuteOptions {\n\tidentifierSchemas?: Record<number, JSONSchema7>;\n\tidentifierData?: Record<number, Record<string, unknown>>;\n\tcoerceSchema?: JSONSchema7;\n\t/** When true, exclude entries containing Handlebars expressions */\n\texcludeTemplateExpression?: boolean;\n}\n\n/**\n * Dispatches a `TemplateInput` for combined analysis and execution,\n * handling array/object/literal cases generically and delegating\n * the string case to a callback.\n *\n * @param template - The input to process\n * @param options - Options (identifierSchemas, identifierData, coerceSchema)\n * @param processString - Callback for analyzing and executing a string template.\n * Receives `(template, coerceSchema?)` and must return\n * `{ analysis, value }`.\n * @param recurse - Callback for recursively processing a child `TemplateInput`.\n * @returns `{ analysis, value }` where `value` is `undefined` if analysis fails\n */\nexport function dispatchAnalyzeAndExecute(\n\ttemplate: TemplateInput,\n\toptions: DispatchAnalyzeAndExecuteOptions | undefined,\n\tprocessString: (\n\t\ttemplate: string,\n\t\tcoerceSchema?: JSONSchema7,\n\t) => { analysis: AnalysisResult; value: unknown },\n\trecurse: (\n\t\tchild: TemplateInput,\n\t\toptions?: DispatchAnalyzeAndExecuteOptions,\n\t) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst exclude = options?.excludeTemplateExpression === true;\n\n\t// ── Array ─────────────────────────────────────────────────────────────\n\tif (isArrayInput(template)) {\n\t\tconst childOptions = resolveArrayChildOptions(options);\n\t\tconst elements = exclude\n\t\t\t? template.filter((item) => !shouldExcludeEntry(item as TemplateInput))\n\t\t\t: template;\n\t\treturn aggregateArrayAnalysisAndExecution(elements.length, (index) =>\n\t\t\trecurse(elements[index] as TemplateInput, childOptions),\n\t\t);\n\t}\n\n\t// ── Object ────────────────────────────────────────────────────────────\n\tif (isObjectInput(template)) {\n\t\tconst coerceSchema = options?.coerceSchema;\n\t\tconst keys = exclude\n\t\t\t? Object.keys(template).filter(\n\t\t\t\t\t(key) => !shouldExcludeEntry(template[key] as TemplateInput),\n\t\t\t\t)\n\t\t\t: Object.keys(template);\n\t\treturn aggregateObjectAnalysisAndExecution(keys, (key) => {\n\t\t\tconst childCoerceSchema = resolveChildCoerceSchema(coerceSchema, key);\n\t\t\treturn recurse(template[key] as TemplateInput, {\n\t\t\t\tidentifierSchemas: options?.identifierSchemas,\n\t\t\t\tidentifierData: options?.identifierData,\n\t\t\t\tcoerceSchema: childCoerceSchema,\n\t\t\t\texcludeTemplateExpression: options?.excludeTemplateExpression,\n\t\t\t});\n\t\t});\n\t}\n\n\t// ── Literal (number, boolean, null) ───────────────────────────────────\n\tif (isLiteralInput(template)) {\n\t\treturn {\n\t\t\tanalysis: {\n\t\t\t\tvalid: true,\n\t\t\t\tdiagnostics: [],\n\t\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t\t},\n\t\t\tvalue: template,\n\t\t};\n\t}\n\n\t// ── String template ──────────────────────────────────────────────────\n\t// At root level, if the string contains expressions and exclude is on,\n\t// return null with a valid analysis (no parent to remove from).\n\tif (exclude && shouldExcludeEntry(template)) {\n\t\treturn {\n\t\t\tanalysis: {\n\t\t\t\tvalid: true,\n\t\t\t\tdiagnostics: [],\n\t\t\t\toutputSchema: { type: \"null\" },\n\t\t\t},\n\t\t\tvalue: null,\n\t\t};\n\t}\n\n\treturn processString(template, options?.coerceSchema);\n}\n\n// ─── Internal Utilities ──────────────────────────────────────────────────────\n\n/**\n * Resolves the child options for array element recursion.\n *\n * When a `coerceSchema` with `items` is provided, the child options\n * will use `coerceSchema.items` as the element-level coercion schema.\n * All other options are passed through unchanged.\n *\n * @param options - The parent dispatching options (may be `undefined`)\n * @returns New options with `coerceSchema` resolved to the items schema, or\n * the original options if no items schema is available.\n */\nfunction resolveArrayChildOptions<\n\tT extends { coerceSchema?: JSONSchema7 } | undefined,\n>(options: T): T {\n\tif (!options?.coerceSchema) return options;\n\n\tconst itemsSchema = resolveItemsCoerceSchema(options.coerceSchema);\n\tif (itemsSchema === options.coerceSchema) return options;\n\n\treturn { ...options, coerceSchema: itemsSchema };\n}\n\n/**\n * Extracts the `items` schema from an array-typed `coerceSchema`.\n *\n * If the schema declares `items` as a single schema (not a tuple),\n * returns that schema. Otherwise returns `undefined`.\n *\n * @param coerceSchema - The parent coercion schema\n * @returns The items coercion schema, or `undefined`\n */\nfunction resolveItemsCoerceSchema(\n\tcoerceSchema: JSONSchema7,\n): JSONSchema7 | undefined {\n\tif (typeof coerceSchema === \"boolean\") return undefined;\n\n\tconst items = coerceSchema.items;\n\tif (items != null && typeof items === \"object\" && !Array.isArray(items)) {\n\t\treturn items as JSONSchema7;\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Resolves the child `coerceSchema` for a given object key.\n *\n * When a `coerceSchema` is provided, navigates into its `properties`\n * to find the schema for the given key. This allows deeply nested\n * objects to propagate coercion at every level.\n *\n * @param coerceSchema - The parent coercion schema (may be `undefined`)\n * @param key - The object property key\n * @returns The child coercion schema, or `undefined`\n */\nexport function resolveChildCoerceSchema(\n\tcoerceSchema: JSONSchema7 | undefined,\n\tkey: string,\n): JSONSchema7 | undefined {\n\treturn coerceSchema ? resolveSchemaPath(coerceSchema, [key]) : undefined;\n}\n\n/**\n * Determines whether a `TemplateInput` value should be excluded when\n * `excludeTemplateExpression` is enabled.\n *\n * A value is excluded if it is a string containing at least one Handlebars\n * expression (`{{…}}`). Literals (number, boolean, null), plain strings\n * without expressions, objects, and arrays are never excluded at the\n * entry level — objects and arrays are recursively filtered by the\n * dispatching functions themselves.\n *\n * @param input - The template input to check\n * @returns `true` if the input should be excluded\n */\nexport function shouldExcludeEntry(input: TemplateInput): boolean {\n\treturn typeof input === \"string\" && hasHandlebarsExpression(input);\n}\n"],"names":["hasHandlebarsExpression","resolveSchemaPath","inferPrimitiveSchema","isArrayInput","isLiteralInput","isObjectInput","aggregateArrayAnalysis","aggregateArrayAnalysisAndExecution","aggregateObjectAnalysis","aggregateObjectAnalysisAndExecution","dispatchAnalyze","template","options","analyzeString","recurse","exclude","excludeTemplateExpression","childOptions","resolveArrayChildOptions","kept","filter","item","shouldExcludeEntry","length","index","dispatchObjectAnalysis","valid","diagnostics","outputSchema","coerceSchema","keys","Object","key","childCoerceSchema","resolveChildCoerceSchema","identifierSchemas","dispatchExecute","executeString","elements","result","element","push","dispatchAnalyzeAndExecute","processString","identifierData","analysis","value","type","itemsSchema","resolveItemsCoerceSchema","undefined","items","Array","isArray","input"],"mappings":"AACA,OAASA,uBAAuB,KAAQ,aAAc,AACtD,QAASC,iBAAiB,KAAQ,sBAAuB,AAEzD,QACCC,oBAAoB,CACpBC,YAAY,CACZC,cAAc,CACdC,aAAa,KACP,YAAa,AACpB,QACCC,sBAAsB,CACtBC,kCAAkC,CAClCC,uBAAuB,CACvBC,mCAAmC,KAC7B,YAAa,AAqDpB,QAAO,SAASC,gBACfC,QAAuB,CACvBC,OAA2C,CAC3CC,aAGmB,CACnBC,OAGmB,EAGnB,GAAIX,aAAaQ,UAAW,CAC3B,MAAMI,QAAUH,SAASI,4BAA8B,KACvD,MAAMC,aAAeC,yBAAyBN,SAC9C,GAAIG,QAAS,CACZ,MAAMI,KAAOR,SAASS,MAAM,CAC3B,AAACC,MAAS,CAACC,mBAAmBD,OAE/B,OAAOf,uBAAuBa,KAAKI,MAAM,CAAE,AAACC,OAC3CV,QAAQK,IAAI,CAACK,MAAM,CAAmBP,cAExC,CACA,OAAOX,uBAAuBK,SAASY,MAAM,CAAE,AAACC,OAC/CV,QAAQH,QAAQ,CAACa,MAAM,CAAmBP,cAE5C,CAGA,GAAIZ,cAAcM,UAAW,CAC5B,OAAOc,uBAAuBd,SAAUC,QAASE,QAClD,CAG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