typebars 1.0.0 → 1.0.2
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/analyzer.js +1 -1
- package/dist/{chunk-kznb0bev.js → chunk-ecs3yth2.js} +3 -3
- package/dist/{chunk-z6yh5qvc.js.map → chunk-ecs3yth2.js.map} +1 -1
- package/dist/{chunk-qpzzr2rd.js → chunk-efqd0598.js} +3 -3
- package/dist/{chunk-qpzzr2rd.js.map → chunk-efqd0598.js.map} +1 -1
- package/dist/chunk-jms1ndxn.js +5 -0
- package/dist/chunk-jms1ndxn.js.map +10 -0
- package/dist/{chunk-4zv02svp.js → chunk-p5efqsxw.js} +3 -3
- package/dist/{chunk-4zv02svp.js.map → chunk-p5efqsxw.js.map} +1 -1
- package/dist/{chunk-1gm6cf0e.js → chunk-rkrp4ysw.js} +3 -3
- package/dist/{chunk-1gm6cf0e.js.map → chunk-rkrp4ysw.js.map} +1 -1
- package/dist/chunk-t6n956qz.js +4 -0
- package/dist/chunk-t6n956qz.js.map +10 -0
- package/dist/chunk-xd2vmd03.js +5 -0
- package/dist/{chunk-7j6q1e3z.js.map → chunk-xd2vmd03.js.map} +2 -2
- package/dist/chunk-zh1e0yhd.js +7 -0
- package/dist/chunk-zh1e0yhd.js.map +10 -0
- package/dist/compiled-template.js +1 -1
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +2 -2
- package/dist/errors.js.map +1 -1
- package/dist/executor.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/parser.js +1 -1
- package/dist/schema-resolver.d.ts +38 -0
- package/dist/schema-resolver.js +2 -2
- package/dist/schema-resolver.js.map +1 -1
- package/dist/typebars.js +1 -1
- package/dist/utils.js +2 -2
- package/dist/utils.js.map +1 -1
- package/package.json +40 -40
- package/dist/chunk-1qwj7pjc.js +0 -4
- package/dist/chunk-1qwj7pjc.js.map +0 -10
- package/dist/chunk-60gk3q7z.js +0 -5
- package/dist/chunk-60gk3q7z.js.map +0 -10
- package/dist/chunk-6c0pw73w.js +0 -7
- package/dist/chunk-6c0pw73w.js.map +0 -10
- package/dist/chunk-7j6q1e3z.js +0 -5
- package/dist/chunk-8g0d6h85.js +0 -5
- package/dist/chunk-8g0d6h85.js.map +0 -10
- package/dist/chunk-9mg6qfrs.js +0 -5
- package/dist/chunk-9mg6qfrs.js.map +0 -10
- package/dist/chunk-a37yzqra.js +0 -5
- package/dist/chunk-a37yzqra.js.map +0 -11
- package/dist/chunk-awgj10qg.js +0 -4
- package/dist/chunk-awgj10qg.js.map +0 -10
- package/dist/chunk-fhvf5y4x.js +0 -7
- package/dist/chunk-fhvf5y4x.js.map +0 -10
- package/dist/chunk-ggdfaqhe.js +0 -5
- package/dist/chunk-ggdfaqhe.js.map +0 -10
- package/dist/chunk-hc1jnqaw.js +0 -5
- package/dist/chunk-hc1jnqaw.js.map +0 -10
- package/dist/chunk-kznb0bev.js.map +0 -10
- package/dist/chunk-mx8neh7q.js +0 -5
- package/dist/chunk-mx8neh7q.js.map +0 -10
- package/dist/chunk-p3xzf1ew.js +0 -5
- package/dist/chunk-p3xzf1ew.js.map +0 -10
- package/dist/chunk-qh2r1pa1.js +0 -5
- package/dist/chunk-qh2r1pa1.js.map +0 -10
- package/dist/chunk-vka4e61h.js +0 -7
- package/dist/chunk-vka4e61h.js.map +0 -10
- package/dist/chunk-xbvk4ygq.js +0 -5
- package/dist/chunk-xbvk4ygq.js.map +0 -11
- package/dist/chunk-ybh51hbe.js +0 -7
- package/dist/chunk-ybh51hbe.js.map +0 -10
- package/dist/chunk-yczpjh73.js +0 -4
- package/dist/chunk-yczpjh73.js.map +0 -10
- package/dist/chunk-yraqh2tz.js +0 -5
- package/dist/chunk-yraqh2tz.js.map +0 -10
- package/dist/chunk-z6yh5qvc.js +0 -5
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/errors.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type { TemplateDiagnostic } from \"./types.ts\";\n\n// ─── Base Class ──────────────────────────────────────────────────────────────\n// All template engine errors extend this class, enabling targeted catch blocks:\n// `catch (e) { if (e instanceof TemplateError) … }`\n\nexport class TemplateError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"TemplateError\";\n\t}\n\n\t/**\n\t * Serializes the error into a JSON-compatible object, suitable for sending\n\t * to a frontend or a structured logging system.\n\t */\n\ttoJSON(): Record<string, unknown> {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t};\n\t}\n}\n\n// ─── Parse Error ─────────────────────────────────────────────────────────────\n// Thrown when Handlebars fails to parse the template (invalid syntax).\n\nexport class TemplateParseError extends TemplateError {\n\tconstructor(\n\t\tmessage: string,\n\t\t/** Approximate position of the error in the source */\n\t\tpublic readonly loc?: { line: number; column: number },\n\t\t/** Fragment of the template source around the error */\n\t\tpublic readonly source?: string,\n\t) {\n\t\tsuper(`Parse error: ${message}`);\n\t\tthis.name = \"TemplateParseError\";\n\t}\n\n\toverride toJSON(): Record<string, unknown> {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tloc: this.loc,\n\t\t\tsource: this.source,\n\t\t};\n\t}\n}\n\n// ─── Static Analysis Error ───────────────────────────────────────────────────\n// Thrown in strict mode when the analysis produces at least one error.\n// Contains the full list of diagnostics for detailed inspection.\n\nexport class TemplateAnalysisError extends TemplateError {\n\t/** Full list of diagnostics (errors + warnings) */\n\tpublic readonly diagnostics: TemplateDiagnostic[];\n\n\t/** Only diagnostics with \"error\" severity */\n\tpublic readonly errors: TemplateDiagnostic[];\n\n\t/** Only diagnostics with \"warning\" severity */\n\tpublic readonly warnings: TemplateDiagnostic[];\n\n\t/** Total number of errors */\n\tpublic readonly errorCount: number;\n\n\t/** Total number of warnings */\n\tpublic readonly warningCount: number;\n\n\tconstructor(diagnostics: TemplateDiagnostic[]) {\n\t\tconst errors = diagnostics.filter((d) => d.severity === \"error\");\n\t\tconst warnings = diagnostics.filter((d) => d.severity === \"warning\");\n\n\t\tconst summary = errors.map((d) => formatDiagnosticLine(d)).join(\"\\n\");\n\t\tsuper(`Static analysis failed with ${errors.length} error(s):\\n${summary}`);\n\n\t\tthis.name = \"TemplateAnalysisError\";\n\t\tthis.diagnostics = diagnostics;\n\t\tthis.errors = errors;\n\t\tthis.warnings = warnings;\n\t\tthis.errorCount = errors.length;\n\t\tthis.warningCount = warnings.length;\n\t}\n\n\t/**\n\t * Serializes the analysis error into a JSON-compatible object.\n\t *\n\t * Designed for direct use in API responses:\n\t * ```\n\t * res.status(400).json(error.toJSON());\n\t * ```\n\t *\n\t * Returned structure:\n\t * ```\n\t * {\n\t * name: \"TemplateAnalysisError\",\n\t * message: \"Static analysis failed with 2 error(s): ...\",\n\t * errorCount: 2,\n\t * warningCount: 0,\n\t * diagnostics: [\n\t * {\n\t * severity: \"error\",\n\t * code: \"UNKNOWN_PROPERTY\",\n\t * message: \"Property \\\"foo\\\" does not exist...\",\n\t * loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 7 } },\n\t * source: \"{{foo}}\",\n\t * details: { path: \"foo\", availableProperties: [\"name\", \"age\"] }\n\t * }\n\t * ]\n\t * }\n\t * ```\n\t */\n\toverride toJSON(): Record<string, unknown> {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\terrorCount: this.errorCount,\n\t\t\twarningCount: this.warningCount,\n\t\t\tdiagnostics: this.diagnostics,\n\t\t};\n\t}\n}\n\n// ─── Runtime Error ───────────────────────────────────────────────────────────\n// Thrown when template execution fails (accessing a non-existent property\n// in strict mode, unexpected type, etc.).\n\nexport class TemplateRuntimeError extends TemplateError {\n\tconstructor(message: string) {\n\t\tsuper(`Runtime error: ${message}`);\n\t\tthis.name = \"TemplateRuntimeError\";\n\t}\n}\n\n// ─── Internal Utilities ──────────────────────────────────────────────────────\n\n/**\n * Formats a single diagnostic line for the summary message\n * of a `TemplateAnalysisError`.\n *\n * Produces a human-readable format:\n * ` • [UNKNOWN_PROPERTY] Property \"foo\" does not exist (at 1:0)`\n */\nfunction formatDiagnosticLine(diag: TemplateDiagnostic): string {\n\tconst parts: string[] = [` • [${diag.code}] ${diag.message}`];\n\n\tif (diag.loc) {\n\t\tparts.push(`(at ${diag.loc.start.line}:${diag.loc.start.column})`);\n\t}\n\n\treturn parts.join(\" \");\n}\n\n// ─── Common Error Factories ──────────────────────────────────────────────────\n// These functions simplify the creation of typed errors across the codebase.\n\n/**\n * Creates a structured diagnostic message for a missing property.\n * Used by the analyzer to produce enriched error messages with suggestions.\n */\nexport function createPropertyNotFoundMessage(\n\tpath: string,\n\tavailableProperties: string[],\n): string {\n\tconst base = `Property \"${path}\" does not exist in the context schema`;\n\tif (availableProperties.length === 0) return base;\n\treturn `${base}. Available properties: ${availableProperties.join(\", \")}`;\n}\n\n/**\n * Creates a message for a type mismatch on a block helper.\n */\nexport function createTypeMismatchMessage(\n\thelperName: string,\n\texpected: string,\n\tactual: string,\n): string {\n\treturn `\"{{#${helperName}}}\" expects ${expected}, but resolved schema has type \"${actual}\"`;\n}\n\n/**\n * Creates a message for a missing argument on a block helper.\n */\nexport function createMissingArgumentMessage(helperName: string): string {\n\treturn `\"{{#${helperName}}}\" requires an argument`;\n}\n\n/**\n * Creates a message for an unknown block helper.\n */\nexport function createUnknownHelperMessage(helperName: string): string {\n\treturn `Unknown block helper \"{{#${helperName}}}\" — cannot analyze statically`;\n}\n\n/**\n * Creates a message for an expression that cannot be statically analyzed.\n */\nexport function createUnanalyzableMessage(nodeType: string): string {\n\treturn `Expression of type \"${nodeType}\" cannot be statically analyzed`;\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": "AAMO,MAAM,UAAsB,KAAM,CACxC,WAAW,CAAC,EAAiB,CAC5B,MAAM,CAAO,EACb,KAAK,KAAO,gBAOb,MAAM,EAA4B,CACjC,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AM,EAAO,aAAa,0CAC1B,GAAI,EAAoB,SAAW,EAAG,OAAO,EAC7C,MAAO,GAAG,4BAA+B,EAAoB,KAAK,IAAI,IAMhE,SAAS,CAAyB,CACxC,EACA,EACA,EACS,CACT,MAAO,OAAO,gBAAyB,oCAA2C,KAM5E,SAAS,CAA4B,CAAC,EAA4B,CACxE,MAAO,OAAO,4BAMR,SAAS,CAA0B,CAAC,EAA4B,CACtE,MAAO,4BAA4B,mCAM7B,SAAS,CAAyB,CAAC,EAA0B,CACnE,MAAO,uBAAuB",
|
|
8
|
-
"debugId": "C1C5104B96E761E764756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
package/dist/chunk-yczpjh73.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{j as u,k as v,l as S}from"./chunk-6955jpr7.js";import{A as y,n as C,r as k,s as D,t as W,u as E,v as T,x as P}from"./chunk-ggdfaqhe.js";import{F as Z,G as _,H as R,I as $,J as B}from"./chunk-vka4e61h.js";import{M as X,N,O as Y}from"./chunk-mx8neh7q.js";import{P as M,R as b,S as V,T as q}from"./chunk-fhvf5y4x.js";function o(j,w,A){if(v(j))return d(j,w,A);if(u(j))return{valid:!0,diagnostics:[],outputSchema:S(j)};let F=C(j);return n(F,j,w,{identifierSchemas:A})}function d(j,w,A){return q(Object.keys(j),(F)=>o(j[F],w,A))}function n(j,w,A,F){let z={root:A,current:A,diagnostics:[],template:w,identifierSchemas:F?.identifierSchemas,helpers:F?.helpers},G=J(j,z);return{valid:!z.diagnostics.some((I)=>I.severity==="error"),diagnostics:z.diagnostics,outputSchema:Y(G)}}function l(j,w){switch(j.type){case"ContentStatement":case"CommentStatement":return;case"MustacheStatement":return g(j,w);case"BlockStatement":return f(j,w);default:K(w,"UNANALYZABLE","warning",`Unsupported AST node type: "${j.type}"`,j);return}}function g(j,w){if(j.path.type==="SubExpression")return K(w,"UNANALYZABLE","warning","Sub-expressions are not statically analyzable",j),{};if(j.params.length>0||j.hash){let A=i(j.path),F=w.helpers?.get(A);if(F){let z=F.params;if(z){let G=z.filter((H)=>!H.optional).length;if(j.params.length<G)K(w,"MISSING_ARGUMENT","error",`Helper "${A}" expects at least ${G} argument(s), but got ${j.params.length}`,j,{helperName:A,expected:`${G} argument(s)`,actual:`${j.params.length} argument(s)`})}for(let G=0;G<j.params.length;G++){let H=O(j.params[G],w,j),I=z?.[G];if(H&&I?.type){let L=I.type;if(!p(H,L)){let h=I.name;K(w,"TYPE_MISMATCH","error",`Helper "${A}" parameter "${h}" expects ${Q(L)}, but got ${Q(H)}`,j,{helperName:A,expected:Q(L),actual:Q(H)})}}}return F.returnType??{type:"string"}}return K(w,"UNKNOWN_HELPER","warning",`Unknown inline helper "${A}" — cannot analyze statically`,j,{helperName:A}),{type:"string"}}return O(j.path,w,j)??{}}function p(j,w){if(!w.type||!j.type)return!0;let A=Array.isArray(w.type)?w.type:[w.type];return(Array.isArray(j.type)?j.type:[j.type]).some((z)=>A.some((G)=>z===G||G==="number"&&z==="integer"||G==="integer"&&z==="number"))}function J(j,w){let A=W(j);if(A.length===0)return{type:"string"};let F=T(j);if(F)return g(F,w);let z=E(j);if(z)return f(z,w);if(A.every((H)=>H.type==="ContentStatement")){let H=A.map((L)=>L.value).join("").trim();if(H==="")return{type:"string"};let I=P(H);if(I)return{type:I}}for(let H of j.body)l(H,w);return{type:"string"}}function f(j,w){let A=r(j);switch(A){case"if":case"unless":{let F=U(j);if(F)O(F,w,j);else K(w,"MISSING_ARGUMENT","error",R(A),j,{helperName:A});let z=J(j.program,w);if(j.inverse){let G=J(j.inverse,w);if(M(z,G))return z;return Y({oneOf:[z,G]})}return z}case"each":{let F=U(j);if(!F){K(w,"MISSING_ARGUMENT","error",R("each"),j,{helperName:"each"});let I=w.current;if(w.current={},J(j.program,w),w.current=I,j.inverse)J(j.inverse,w);return{type:"string"}}let z=O(F,w,j);if(!z){let I=w.current;if(w.current={},J(j.program,w),w.current=I,j.inverse)J(j.inverse,w);return{type:"string"}}let G=N(z,w.root);if(!G){K(w,"TYPE_MISMATCH","error",_("each","an array",Q(z)),j,{helperName:"each",expected:"array",actual:Q(z)});let I=w.current;if(w.current={},J(j.program,w),w.current=I,j.inverse)J(j.inverse,w);return{type:"string"}}let H=w.current;if(w.current=G,J(j.program,w),w.current=H,j.inverse)J(j.inverse,w);return{type:"string"}}case"with":{let F=U(j);if(!F){K(w,"MISSING_ARGUMENT","error",R("with"),j,{helperName:"with"});let I=w.current;w.current={};let L=J(j.program,w);if(w.current=I,j.inverse)J(j.inverse,w);return L}let z=O(F,w,j),G=w.current;w.current=z??{};let H=J(j.program,w);if(w.current=G,j.inverse)J(j.inverse,w);return H}default:{let F=w.helpers?.get(A);if(F){for(let z of j.params)O(z,w,j);if(J(j.program,w),j.inverse)J(j.inverse,w);return F.returnType??{type:"string"}}if(K(w,"UNKNOWN_HELPER","warning",$(A),j,{helperName:A}),J(j.program,w),j.inverse)J(j.inverse,w);return{type:"string"}}}}function O(j,w,A){if(D(j))return w.current;let F=k(j);if(F.length===0){if(j.type==="StringLiteral")return{type:"string"};if(j.type==="NumberLiteral")return{type:"number"};if(j.type==="BooleanLiteral")return{type:"boolean"};if(j.type==="NullLiteral")return{type:"null"};if(j.type==="UndefinedLiteral")return{};K(w,"UNANALYZABLE","warning",B(j.type),A??j);return}let{cleanSegments:z,identifier:G}=y(F);if(G!==null)return a(z,G,w,A??j);let H=X(w.current,z);if(H===void 0){let I=z.join("."),L=V(w.current);K(w,"UNKNOWN_PROPERTY","error",Z(I,L),A??j,{path:I,availableProperties:L});return}return H}function a(j,w,A,F){let z=j.join(".");if(!A.identifierSchemas){K(A,"MISSING_IDENTIFIER_SCHEMAS","error",`Property "${z}:${w}" uses an identifier but no identifier schemas were provided`,F,{path:`${z}:${w}`,identifier:w});return}let G=A.identifierSchemas[w];if(!G){K(A,"UNKNOWN_IDENTIFIER","error",`Property "${z}:${w}" references identifier ${w} but no schema exists for this identifier`,F,{path:`${z}:${w}`,identifier:w});return}let H=X(G,j);if(H===void 0){let I=V(G);K(A,"IDENTIFIER_PROPERTY_NOT_FOUND","error",`Property "${z}" does not exist in the schema for identifier ${w}`,F,{path:z,identifier:w,availableProperties:I});return}return H}function U(j){return j.params[0]}function r(j){if(j.path.type==="PathExpression")return j.path.original;return""}function i(j){if(j.type==="PathExpression")return j.original;return""}function K(j,w,A,F,z,G){let H={severity:A,code:w,message:F};if(z&&"loc"in z&&z.loc)H.loc={start:{line:z.loc.start.line,column:z.loc.start.column},end:{line:z.loc.end.line,column:z.loc.end.column}},H.source=b(j.template,H.loc);if(G)H.details=G;j.diagnostics.push(H)}function Q(j){if(j.type)return Array.isArray(j.type)?j.type.join(" | "):j.type;if(j.oneOf)return"oneOf(...)";if(j.anyOf)return"anyOf(...)";if(j.allOf)return"allOf(...)";if(j.enum)return"enum";return"unknown"}export{o as c,n as d,f as e};
|
|
2
|
-
|
|
3
|
-
//# debugId=4E3D7DCBEE379AF464756E2164756E21
|
|
4
|
-
//# sourceMappingURL=chunk-yczpjh73.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/analyzer.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type { JSONSchema7 } from \"json-schema\";\nimport {\n\tcreateMissingArgumentMessage,\n\tcreatePropertyNotFoundMessage,\n\tcreateTypeMismatchMessage,\n\tcreateUnanalyzableMessage,\n\tcreateUnknownHelperMessage,\n} from \"./errors.ts\";\nimport {\n\tdetectLiteralType,\n\textractExpressionIdentifier,\n\textractPathSegments,\n\tgetEffectiveBody,\n\tgetEffectivelySingleBlock,\n\tgetEffectivelySingleExpression,\n\tisThisExpression,\n\tparse,\n} from \"./parser.ts\";\nimport {\n\tresolveArrayItems,\n\tresolveSchemaPath,\n\tsimplifySchema,\n} from \"./schema-resolver.ts\";\nimport type {\n\tAnalysisResult,\n\tDiagnosticCode,\n\tDiagnosticDetails,\n\tHelperDefinition,\n\tTemplateDiagnostic,\n\tTemplateInput,\n\tTemplateInputObject,\n} from \"./types.ts\";\nimport {\n\tinferPrimitiveSchema,\n\tisLiteralInput,\n\tisObjectInput,\n} from \"./types.ts\";\nimport {\n\taggregateObjectAnalysis,\n\tdeepEqual,\n\textractSourceSnippet,\n\tgetSchemaPropertyNames,\n} from \"./utils.ts\";\n\n// ─── Static Analyzer ─────────────────────────────────────────────────────────\n// Analyse statique d'un template Handlebars par rapport à un JSON Schema v7\n// décrivant le contexte disponible.\n//\n// Architecture fusionnée (v2) :\n// Un seul parcours de l'AST effectue simultanément la **validation** et\n// l'**inférence du type de retour**. Cela élimine la duplication entre les\n// anciennes fonctions `validate*` et `infer*`, et améliore la performance\n// en évitant un double parcours.\n//\n// Contexte :\n// Le contexte d'analyse utilise un pattern **save/restore** au lieu de\n// créer de nouveaux objets à chaque récursion (`{ ...ctx, current: X }`).\n// Cela réduit la pression sur le GC pour les templates profondément imbriqués.\n//\n// ─── Template Identifiers ────────────────────────────────────────────────────\n// La syntaxe `{{key:N}}` permet de référencer une variable depuis un schema\n// spécifique, identifié par un entier N. Le paramètre optionnel\n// `identifierSchemas` fournit un mapping `{ [id]: JSONSchema7 }`.\n//\n// Règles de résolution :\n// - `{{meetingId}}` → validé contre `inputSchema` (comportement standard)\n// - `{{meetingId:1}}` → validé contre `identifierSchemas[1]`\n// - `{{meetingId:1}}` sans `identifierSchemas[1]` → erreur\n\n// ─── Types internes ──────────────────────────────────────────────────────────\n\n/** Contexte transmis récursivement pendant le parcours de l'AST */\ninterface AnalysisContext {\n\t/** Schema racine (pour résoudre les $ref) */\n\troot: JSONSchema7;\n\t/** Schema du contexte courant (change avec #each, #with) — muté via save/restore */\n\tcurrent: JSONSchema7;\n\t/** Accumulateur de diagnostics */\n\tdiagnostics: TemplateDiagnostic[];\n\t/** Template source complet (pour extraire les snippets d'erreur) */\n\ttemplate: string;\n\t/** Schemas par identifiant de template (pour la syntaxe {{key:N}}) */\n\tidentifierSchemas?: Record<number, JSONSchema7>;\n\t/** Helpers custom enregistrés (pour l'analyse statique) */\n\thelpers?: Map<string, HelperDefinition>;\n}\n\n// ─── API publique ────────────────────────────────────────────────────────────\n\n/**\n * Analyse statiquement un template par rapport à un JSON Schema v7 décrivant\n * le contexte disponible.\n *\n * Version backward-compatible — parse le template en interne.\n *\n * @param template - La chaîne de template (ex: `\"Hello {{user.name}}\"`)\n * @param inputSchema - JSON Schema v7 décrivant les variables disponibles\n * @param identifierSchemas - (optionnel) Schemas par identifiant `{ [id]: JSONSchema7 }`\n * @returns Un `AnalysisResult` contenant la validité, les diagnostics et le\n * schema de sortie inféré.\n */\nexport function analyze(\n\ttemplate: TemplateInput,\n\tinputSchema: JSONSchema7,\n\tidentifierSchemas?: Record<number, JSONSchema7>,\n): AnalysisResult {\n\tif (isObjectInput(template)) {\n\t\treturn analyzeObjectTemplate(template, inputSchema, identifierSchemas);\n\t}\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\tconst ast = parse(template);\n\treturn analyzeFromAst(ast, template, inputSchema, { identifierSchemas });\n}\n\n/**\n * Analyse un objet template récursivement (version standalone).\n * Chaque propriété est analysée individuellement, les diagnostics sont\n * fusionnés, et le `outputSchema` reflète la structure de l'objet.\n */\nfunction analyzeObjectTemplate(\n\ttemplate: TemplateInputObject,\n\tinputSchema: JSONSchema7,\n\tidentifierSchemas?: Record<number, JSONSchema7>,\n): AnalysisResult {\n\treturn aggregateObjectAnalysis(Object.keys(template), (key) =>\n\t\tanalyze(template[key] as TemplateInput, inputSchema, identifierSchemas),\n\t);\n}\n\n/**\n * Analyse statiquement un template à partir d'un AST déjà parsé.\n *\n * C'est la fonction interne utilisée par `Typebars.compile()` et\n * `CompiledTemplate.analyze()` pour éviter un re-parsing coûteux.\n *\n * @param ast - L'AST Handlebars déjà parsé\n * @param template - Le template source (pour les snippets d'erreur)\n * @param inputSchema - JSON Schema v7 décrivant les variables disponibles\n * @param options - Options supplémentaires\n * @returns Un `AnalysisResult`\n */\nexport function analyzeFromAst(\n\tast: hbs.AST.Program,\n\ttemplate: string,\n\tinputSchema: JSONSchema7,\n\toptions?: {\n\t\tidentifierSchemas?: Record<number, JSONSchema7>;\n\t\thelpers?: Map<string, HelperDefinition>;\n\t},\n): AnalysisResult {\n\tconst ctx: AnalysisContext = {\n\t\troot: inputSchema,\n\t\tcurrent: inputSchema,\n\t\tdiagnostics: [],\n\t\ttemplate,\n\t\tidentifierSchemas: options?.identifierSchemas,\n\t\thelpers: options?.helpers,\n\t};\n\n\t// Parcours unique : inférence du type + validation en un seul pass.\n\tconst outputSchema = inferProgramType(ast, ctx);\n\n\tconst hasErrors = ctx.diagnostics.some((d) => d.severity === \"error\");\n\n\treturn {\n\t\tvalid: !hasErrors,\n\t\tdiagnostics: ctx.diagnostics,\n\t\toutputSchema: simplifySchema(outputSchema),\n\t};\n}\n\n// ─── Parcours unifié de l'AST ────────────────────────────────────────────────\n// Un seul ensemble de fonctions gère à la fois la validation (émission de\n// diagnostics) et l'inférence de type (retour d'un JSONSchema7).\n//\n// Fonctions principales :\n// - `inferProgramType` — point d'entrée pour un Program (corps de template ou bloc)\n// - `processStatement` — dispatche un statement (validation side-effect)\n// - `processMustache` — gère un MustacheStatement (expression ou helper inline)\n// - `inferBlockType` — gère un BlockStatement (if, each, with, custom…)\n\n/**\n * Dispatche le traitement d'un statement individuel.\n *\n * Appelé par `inferProgramType` dans le cas \"template mixte\" pour valider\n * chaque statement tout en ignorant le type retourné (le résultat est\n * toujours `string` pour un template mixte).\n *\n * @returns Le schema inféré pour ce statement, ou `undefined` pour les\n * statements sans sémantique (ContentStatement, CommentStatement).\n */\nfunction processStatement(\n\tstmt: hbs.AST.Statement,\n\tctx: AnalysisContext,\n): JSONSchema7 | undefined {\n\tswitch (stmt.type) {\n\t\tcase \"ContentStatement\":\n\t\tcase \"CommentStatement\":\n\t\t\t// Texte statique ou commentaire — rien à valider, pas de type à inférer\n\t\t\treturn undefined;\n\n\t\tcase \"MustacheStatement\":\n\t\t\treturn processMustache(stmt as hbs.AST.MustacheStatement, ctx);\n\n\t\tcase \"BlockStatement\":\n\t\t\treturn inferBlockType(stmt as hbs.AST.BlockStatement, ctx);\n\n\t\tdefault:\n\t\t\t// Nœud AST non reconnu — on émet un warning plutôt qu'une erreur\n\t\t\t// pour ne pas bloquer sur des extensions futures de Handlebars.\n\t\t\taddDiagnostic(\n\t\t\t\tctx,\n\t\t\t\t\"UNANALYZABLE\",\n\t\t\t\t\"warning\",\n\t\t\t\t`Unsupported AST node type: \"${stmt.type}\"`,\n\t\t\t\tstmt,\n\t\t\t);\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Traite un MustacheStatement `{{expression}}` ou `{{helper arg}}`.\n *\n * Distingue deux cas :\n * 1. **Expression simple** (`{{name}}`, `{{user.age}}`) — résolution dans le schema\n * 2. **Helper inline** (`{{uppercase name}}`) — params > 0 ou hash présent\n *\n * @returns Le schema inféré pour cette expression\n */\nfunction processMustache(\n\tstmt: hbs.AST.MustacheStatement,\n\tctx: AnalysisContext,\n): JSONSchema7 {\n\t// Sub-expressions (helpers imbriqués) ne sont pas supportées pour\n\t// l'analyse statique — on émet un warning.\n\tif (stmt.path.type === \"SubExpression\") {\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"UNANALYZABLE\",\n\t\t\t\"warning\",\n\t\t\t\"Sub-expressions are not statically analyzable\",\n\t\t\tstmt,\n\t\t);\n\t\treturn {};\n\t}\n\n\t// ── Détection des helpers inline ─────────────────────────────────────────\n\t// Si le MustacheStatement a des paramètres ou un hash, c'est un appel\n\t// de helper (ex: `{{uppercase name}}`), pas une simple expression.\n\tif (stmt.params.length > 0 || stmt.hash) {\n\t\tconst helperName = getExpressionName(stmt.path);\n\n\t\t// Vérifier si le helper est enregistré\n\t\tconst helper = ctx.helpers?.get(helperName);\n\t\tif (helper) {\n\t\t\tconst helperParams = helper.params;\n\n\t\t\t// ── Vérifier le nombre de paramètres requis ──────────────────\n\t\t\tif (helperParams) {\n\t\t\t\tconst requiredCount = helperParams.filter((p) => !p.optional).length;\n\t\t\t\tif (stmt.params.length < requiredCount) {\n\t\t\t\t\taddDiagnostic(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\"MISSING_ARGUMENT\",\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t`Helper \"${helperName}\" expects at least ${requiredCount} argument(s), but got ${stmt.params.length}`,\n\t\t\t\t\t\tstmt,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\thelperName,\n\t\t\t\t\t\t\texpected: `${requiredCount} argument(s)`,\n\t\t\t\t\t\t\tactual: `${stmt.params.length} argument(s)`,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ── Valider chaque paramètre (existence + type) ─────────────\n\t\t\tfor (let i = 0; i < stmt.params.length; i++) {\n\t\t\t\tconst resolvedSchema = resolveExpressionWithDiagnostics(\n\t\t\t\t\tstmt.params[i] as hbs.AST.Expression,\n\t\t\t\t\tctx,\n\t\t\t\t\tstmt,\n\t\t\t\t);\n\n\t\t\t\t// Vérifier la compatibilité de type si le helper déclare\n\t\t\t\t// le type attendu pour ce paramètre\n\t\t\t\tconst helperParam = helperParams?.[i];\n\t\t\t\tif (resolvedSchema && helperParam?.type) {\n\t\t\t\t\tconst expectedType = helperParam.type;\n\t\t\t\t\tif (!isParamTypeCompatible(resolvedSchema, expectedType)) {\n\t\t\t\t\t\tconst paramName = helperParam.name;\n\t\t\t\t\t\taddDiagnostic(\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\t\"TYPE_MISMATCH\",\n\t\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t\t`Helper \"${helperName}\" parameter \"${paramName}\" expects ${schemaTypeLabel(expectedType)}, but got ${schemaTypeLabel(resolvedSchema)}`,\n\t\t\t\t\t\t\tstmt,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\thelperName,\n\t\t\t\t\t\t\t\texpected: schemaTypeLabel(expectedType),\n\t\t\t\t\t\t\t\tactual: schemaTypeLabel(resolvedSchema),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn helper.returnType ?? { type: \"string\" };\n\t\t}\n\n\t\t// Helper inline inconnu — warning\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"UNKNOWN_HELPER\",\n\t\t\t\"warning\",\n\t\t\t`Unknown inline helper \"${helperName}\" — cannot analyze statically`,\n\t\t\tstmt,\n\t\t\t{ helperName },\n\t\t);\n\t\treturn { type: \"string\" };\n\t}\n\n\t// ── Expression simple ────────────────────────────────────────────────────\n\treturn resolveExpressionWithDiagnostics(stmt.path, ctx, stmt) ?? {};\n}\n\n/**\n * Vérifie si un type résolu est compatible avec le type attendu par un\n * paramètre de helper.\n *\n * Règles de compatibilité :\n * - Si l'un des deux schemas n'a pas de `type`, on ne peut pas valider → compatible\n * - `integer` est compatible avec `number` (integer ⊂ number)\n * - Pour les types multiples (ex: `[\"string\", \"number\"]`), il suffit qu'un\n * type résolu corresponde à un type attendu\n */\nfunction isParamTypeCompatible(\n\tresolved: JSONSchema7,\n\texpected: JSONSchema7,\n): boolean {\n\t// Si l'un des deux n'a pas d'info de type, on ne peut pas valider\n\tif (!expected.type || !resolved.type) return true;\n\n\tconst expectedTypes = Array.isArray(expected.type)\n\t\t? expected.type\n\t\t: [expected.type];\n\tconst resolvedTypes = Array.isArray(resolved.type)\n\t\t? resolved.type\n\t\t: [resolved.type];\n\n\t// Au moins un type résolu doit être compatible avec un type attendu\n\treturn resolvedTypes.some((rt) =>\n\t\texpectedTypes.some(\n\t\t\t(et) =>\n\t\t\t\trt === et ||\n\t\t\t\t// integer est un sous-type de number\n\t\t\t\t(et === \"number\" && rt === \"integer\") ||\n\t\t\t\t(et === \"integer\" && rt === \"number\"),\n\t\t),\n\t);\n}\n\n/**\n * Infère le type de sortie d'un `Program` (corps d'un template ou d'un bloc).\n *\n * Gère 4 cas, du plus spécifique au plus général :\n *\n * 1. **Expression unique** `{{expr}}` → type de l'expression\n * 2. **Bloc unique** `{{#if}}…{{/if}}` → type du bloc\n * 3. **Contenu textuel pur** → détection de littéral (number, boolean, null)\n * 4. **Template mixte** → toujours `string` (concaténation)\n *\n * La validation est effectuée en même temps que l'inférence : chaque\n * expression et bloc est validé lors de son traitement.\n */\nfunction inferProgramType(\n\tprogram: hbs.AST.Program,\n\tctx: AnalysisContext,\n): JSONSchema7 {\n\tconst effective = getEffectiveBody(program);\n\n\t// Aucun statement significatif → string vide\n\tif (effective.length === 0) {\n\t\treturn { type: \"string\" };\n\t}\n\n\t// ── Cas 1 : une seule expression {{expr}} ──────────────────────────────\n\tconst singleExpr = getEffectivelySingleExpression(program);\n\tif (singleExpr) {\n\t\treturn processMustache(singleExpr, ctx);\n\t}\n\n\t// ── Cas 2 : un seul bloc {{#if}}, {{#each}}, {{#with}}, … ─────────────\n\tconst singleBlock = getEffectivelySingleBlock(program);\n\tif (singleBlock) {\n\t\treturn inferBlockType(singleBlock, ctx);\n\t}\n\n\t// ── Cas 3 : uniquement des ContentStatements (pas d'expressions) ───────\n\t// Si le texte concaténé (trimé) est un littéral typé (nombre, booléen,\n\t// null), on infère le type correspondant.\n\tconst allContent = effective.every((s) => s.type === \"ContentStatement\");\n\tif (allContent) {\n\t\tconst text = effective\n\t\t\t.map((s) => (s as hbs.AST.ContentStatement).value)\n\t\t\t.join(\"\")\n\t\t\t.trim();\n\n\t\tif (text === \"\") return { type: \"string\" };\n\n\t\tconst literalType = detectLiteralType(text);\n\t\tif (literalType) return { type: literalType };\n\t}\n\n\t// ── Cas 4 : template mixte (texte + expressions, blocs multiples…) ────\n\t// On parcourt tous les statements pour valider (side-effects : diagnostics).\n\t// Le résultat est toujours string (concaténation).\n\tfor (const stmt of program.body) {\n\t\tprocessStatement(stmt, ctx);\n\t}\n\treturn { type: \"string\" };\n}\n\n/**\n * Infère le type de sortie d'un BlockStatement et valide son contenu.\n *\n * Supporte les helpers built-in (`if`, `unless`, `each`, `with`) et les\n * helpers custom enregistrés via `Typebars.registerHelper()`.\n *\n * Utilise le pattern **save/restore** pour le contexte : au lieu de créer\n * un nouvel objet `{ ...ctx, current: X }` à chaque récursion, on sauvegarde\n * `ctx.current`, on le mute, on traite le corps, puis on restaure. Cela\n * réduit la pression sur le GC pour les templates profondément imbriqués.\n */\nfunction inferBlockType(\n\tstmt: hbs.AST.BlockStatement,\n\tctx: AnalysisContext,\n): JSONSchema7 {\n\tconst helperName = getBlockHelperName(stmt);\n\n\tswitch (helperName) {\n\t\t// ── if / unless ──────────────────────────────────────────────────────\n\t\tcase \"if\":\n\t\tcase \"unless\": {\n\t\t\tconst arg = getBlockArgument(stmt);\n\t\t\tif (arg) {\n\t\t\t\tresolveExpressionWithDiagnostics(arg, ctx, stmt);\n\t\t\t} else {\n\t\t\t\taddDiagnostic(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"MISSING_ARGUMENT\",\n\t\t\t\t\t\"error\",\n\t\t\t\t\tcreateMissingArgumentMessage(helperName),\n\t\t\t\t\tstmt,\n\t\t\t\t\t{ helperName },\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Inférer le type de la branche \"then\"\n\t\t\tconst thenType = inferProgramType(stmt.program, ctx);\n\n\t\t\tif (stmt.inverse) {\n\t\t\t\tconst elseType = inferProgramType(stmt.inverse, ctx);\n\t\t\t\t// Si les deux branches ont le même type → type unique\n\t\t\t\tif (deepEqual(thenType, elseType)) return thenType;\n\t\t\t\t// Sinon → union des deux types\n\t\t\t\treturn simplifySchema({ oneOf: [thenType, elseType] });\n\t\t\t}\n\n\t\t\t// Pas de branche else → le résultat est le type de la branche then\n\t\t\t// (conceptuellement optionnel, mais Handlebars retourne \"\" pour falsy)\n\t\t\treturn thenType;\n\t\t}\n\n\t\t// ── each ─────────────────────────────────────────────────────────────\n\t\tcase \"each\": {\n\t\t\tconst arg = getBlockArgument(stmt);\n\t\t\tif (!arg) {\n\t\t\t\taddDiagnostic(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"MISSING_ARGUMENT\",\n\t\t\t\t\t\"error\",\n\t\t\t\t\tcreateMissingArgumentMessage(\"each\"),\n\t\t\t\t\tstmt,\n\t\t\t\t\t{ helperName: \"each\" },\n\t\t\t\t);\n\t\t\t\t// Valider le corps avec un contexte vide (best-effort)\n\t\t\t\tconst saved = ctx.current;\n\t\t\t\tctx.current = {};\n\t\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\t\tctx.current = saved;\n\t\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\t\treturn { type: \"string\" };\n\t\t\t}\n\n\t\t\tconst collectionSchema = resolveExpressionWithDiagnostics(arg, ctx, stmt);\n\t\t\tif (!collectionSchema) {\n\t\t\t\t// Le chemin n'a pas pu être résolu — diagnostic déjà émis.\n\t\t\t\tconst saved = ctx.current;\n\t\t\t\tctx.current = {};\n\t\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\t\tctx.current = saved;\n\t\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\t\treturn { type: \"string\" };\n\t\t\t}\n\n\t\t\t// Résoudre le schema des éléments du tableau\n\t\t\tconst itemSchema = resolveArrayItems(collectionSchema, ctx.root);\n\t\t\tif (!itemSchema) {\n\t\t\t\taddDiagnostic(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"TYPE_MISMATCH\",\n\t\t\t\t\t\"error\",\n\t\t\t\t\tcreateTypeMismatchMessage(\n\t\t\t\t\t\t\"each\",\n\t\t\t\t\t\t\"an array\",\n\t\t\t\t\t\tschemaTypeLabel(collectionSchema),\n\t\t\t\t\t),\n\t\t\t\t\tstmt,\n\t\t\t\t\t{\n\t\t\t\t\t\thelperName: \"each\",\n\t\t\t\t\t\texpected: \"array\",\n\t\t\t\t\t\tactual: schemaTypeLabel(collectionSchema),\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\t// Valider le corps avec un contexte vide (best-effort)\n\t\t\t\tconst saved = ctx.current;\n\t\t\t\tctx.current = {};\n\t\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\t\tctx.current = saved;\n\t\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\t\treturn { type: \"string\" };\n\t\t\t}\n\n\t\t\t// Valider le corps avec le schema des éléments comme contexte\n\t\t\tconst saved = ctx.current;\n\t\t\tctx.current = itemSchema;\n\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\tctx.current = saved;\n\n\t\t\t// La branche inverse ({{else}}) garde le contexte parent\n\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\n\t\t\t// Un each concatène les rendus → toujours string\n\t\t\treturn { type: \"string\" };\n\t\t}\n\n\t\t// ── with ─────────────────────────────────────────────────────────────\n\t\tcase \"with\": {\n\t\t\tconst arg = getBlockArgument(stmt);\n\t\t\tif (!arg) {\n\t\t\t\taddDiagnostic(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"MISSING_ARGUMENT\",\n\t\t\t\t\t\"error\",\n\t\t\t\t\tcreateMissingArgumentMessage(\"with\"),\n\t\t\t\t\tstmt,\n\t\t\t\t\t{ helperName: \"with\" },\n\t\t\t\t);\n\t\t\t\t// Valider le corps avec un contexte vide\n\t\t\t\tconst saved = ctx.current;\n\t\t\t\tctx.current = {};\n\t\t\t\tconst result = inferProgramType(stmt.program, ctx);\n\t\t\t\tctx.current = saved;\n\t\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tconst innerSchema = resolveExpressionWithDiagnostics(arg, ctx, stmt);\n\n\t\t\tconst saved = ctx.current;\n\t\t\tctx.current = innerSchema ?? {};\n\t\t\tconst result = inferProgramType(stmt.program, ctx);\n\t\t\tctx.current = saved;\n\n\t\t\t// La branche inverse garde le contexte parent\n\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\n\t\t\treturn result;\n\t\t}\n\n\t\t// ── Helper custom ou inconnu ─────────────────────────────────────────\n\t\tdefault: {\n\t\t\tconst helper = ctx.helpers?.get(helperName);\n\t\t\tif (helper) {\n\t\t\t\t// Helper custom enregistré — valider les paramètres\n\t\t\t\tfor (const param of stmt.params) {\n\t\t\t\t\tresolveExpressionWithDiagnostics(\n\t\t\t\t\t\tparam as hbs.AST.Expression,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tstmt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Valider le corps avec le contexte courant\n\t\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\t\treturn helper.returnType ?? { type: \"string\" };\n\t\t\t}\n\n\t\t\t// Helper inconnu — warning\n\t\t\taddDiagnostic(\n\t\t\t\tctx,\n\t\t\t\t\"UNKNOWN_HELPER\",\n\t\t\t\t\"warning\",\n\t\t\t\tcreateUnknownHelperMessage(helperName),\n\t\t\t\tstmt,\n\t\t\t\t{ helperName },\n\t\t\t);\n\t\t\t// Valider quand même le corps avec le contexte courant (best-effort)\n\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\treturn { type: \"string\" };\n\t\t}\n\t}\n}\n\n// ─── Résolution d'expressions ────────────────────────────────────────────────\n\n/**\n * Résout une expression AST en un sous-schema, en émettant un diagnostic\n * si le chemin n'est pas résolvable.\n *\n * Gère la syntaxe `{{key:N}}` :\n * - Si l'expression a un identifiant N → résolution dans `identifierSchemas[N]`\n * - Si l'identifiant N n'a pas de schema associé → erreur\n * - Si pas d'identifiant → résolution dans `ctx.current` (comportement standard)\n *\n * @returns Le sous-schema résolu, ou `undefined` si le chemin est invalide.\n */\nfunction resolveExpressionWithDiagnostics(\n\texpr: hbs.AST.Expression,\n\tctx: AnalysisContext,\n\t/** Nœud AST parent (pour la localisation du diagnostic) */\n\tparentNode?: hbs.AST.Node,\n): JSONSchema7 | undefined {\n\t// Gestion de `this` / `.` → retourne le contexte courant\n\tif (isThisExpression(expr)) {\n\t\treturn ctx.current;\n\t}\n\n\tconst segments = extractPathSegments(expr);\n\tif (segments.length === 0) {\n\t\t// Expression qui n'est pas un PathExpression (ex: literal, SubExpression)\n\t\tif (expr.type === \"StringLiteral\") return { type: \"string\" };\n\t\tif (expr.type === \"NumberLiteral\") return { type: \"number\" };\n\t\tif (expr.type === \"BooleanLiteral\") return { type: \"boolean\" };\n\t\tif (expr.type === \"NullLiteral\") return { type: \"null\" };\n\t\tif (expr.type === \"UndefinedLiteral\") return {};\n\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"UNANALYZABLE\",\n\t\t\t\"warning\",\n\t\t\tcreateUnanalyzableMessage(expr.type),\n\t\t\tparentNode ?? expr,\n\t\t);\n\t\treturn undefined;\n\t}\n\n\t// ── Extraction de l'identifiant ────────────────────────────────────────\n\tconst { cleanSegments, identifier } = extractExpressionIdentifier(segments);\n\n\tif (identifier !== null) {\n\t\t// L'expression utilise la syntaxe {{key:N}} — résoudre depuis\n\t\t// le schema de l'identifiant N.\n\t\treturn resolveWithIdentifier(\n\t\t\tcleanSegments,\n\t\t\tidentifier,\n\t\t\tctx,\n\t\t\tparentNode ?? expr,\n\t\t);\n\t}\n\n\t// ── Résolution standard (pas d'identifiant) ────────────────────────────\n\tconst resolved = resolveSchemaPath(ctx.current, cleanSegments);\n\tif (resolved === undefined) {\n\t\tconst fullPath = cleanSegments.join(\".\");\n\t\tconst availableProperties = getSchemaPropertyNames(ctx.current);\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"UNKNOWN_PROPERTY\",\n\t\t\t\"error\",\n\t\t\tcreatePropertyNotFoundMessage(fullPath, availableProperties),\n\t\t\tparentNode ?? expr,\n\t\t\t{ path: fullPath, availableProperties },\n\t\t);\n\t\treturn undefined;\n\t}\n\n\treturn resolved;\n}\n\n/**\n * Résout une expression avec identifiant `{{key:N}}` en cherchant dans\n * le schema associé à l'identifiant N.\n *\n * Émet un diagnostic d'erreur si :\n * - Aucun `identifierSchemas` n'a été fourni\n * - L'identifiant N n'a pas de schema associé\n * - La propriété n'existe pas dans le schema de l'identifiant\n */\nfunction resolveWithIdentifier(\n\tcleanSegments: string[],\n\tidentifier: number,\n\tctx: AnalysisContext,\n\tnode: hbs.AST.Node,\n): JSONSchema7 | undefined {\n\tconst fullPath = cleanSegments.join(\".\");\n\n\t// Pas d'identifierSchemas fourni du tout\n\tif (!ctx.identifierSchemas) {\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"MISSING_IDENTIFIER_SCHEMAS\",\n\t\t\t\"error\",\n\t\t\t`Property \"${fullPath}:${identifier}\" uses an identifier but no identifier schemas were provided`,\n\t\t\tnode,\n\t\t\t{ path: `${fullPath}:${identifier}`, identifier },\n\t\t);\n\t\treturn undefined;\n\t}\n\n\t// L'identifiant n'existe pas dans les schemas fournis\n\tconst idSchema = ctx.identifierSchemas[identifier];\n\tif (!idSchema) {\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"UNKNOWN_IDENTIFIER\",\n\t\t\t\"error\",\n\t\t\t`Property \"${fullPath}:${identifier}\" references identifier ${identifier} but no schema exists for this identifier`,\n\t\t\tnode,\n\t\t\t{ path: `${fullPath}:${identifier}`, identifier },\n\t\t);\n\t\treturn undefined;\n\t}\n\n\t// Résoudre le chemin dans le schema de l'identifiant\n\tconst resolved = resolveSchemaPath(idSchema, cleanSegments);\n\tif (resolved === undefined) {\n\t\tconst availableProperties = getSchemaPropertyNames(idSchema);\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"IDENTIFIER_PROPERTY_NOT_FOUND\",\n\t\t\t\"error\",\n\t\t\t`Property \"${fullPath}\" does not exist in the schema for identifier ${identifier}`,\n\t\t\tnode,\n\t\t\t{\n\t\t\t\tpath: fullPath,\n\t\t\t\tidentifier,\n\t\t\t\tavailableProperties,\n\t\t\t},\n\t\t);\n\t\treturn undefined;\n\t}\n\n\treturn resolved;\n}\n\n// ─── Utilitaires ─────────────────────────────────────────────────────────────\n\n/**\n * Extrait le premier argument d'un BlockStatement.\n *\n * Dans l'AST Handlebars, pour `{{#if active}}` :\n * - `stmt.path` → PathExpression(\"if\") ← le nom du helper\n * - `stmt.params[0]` → PathExpression(\"active\") ← l'argument réel\n *\n * @returns L'expression argument, ou `undefined` si le bloc n'a pas d'argument.\n */\nfunction getBlockArgument(\n\tstmt: hbs.AST.BlockStatement,\n): hbs.AST.Expression | undefined {\n\treturn stmt.params[0] as hbs.AST.Expression | undefined;\n}\n\n/**\n * Récupère le nom du helper d'un BlockStatement (ex: \"if\", \"each\", \"with\").\n */\nfunction getBlockHelperName(stmt: hbs.AST.BlockStatement): string {\n\tif (stmt.path.type === \"PathExpression\") {\n\t\treturn (stmt.path as hbs.AST.PathExpression).original;\n\t}\n\treturn \"\";\n}\n\n/**\n * Récupère le nom d'une expression (premier segment du PathExpression).\n * Utilisé pour identifier les helpers inline.\n */\nfunction getExpressionName(expr: hbs.AST.Expression): string {\n\tif (expr.type === \"PathExpression\") {\n\t\treturn (expr as hbs.AST.PathExpression).original;\n\t}\n\treturn \"\";\n}\n\n/**\n * Ajoute un diagnostic enrichi au contexte d'analyse.\n *\n * Chaque diagnostic inclut :\n * - Un `code` machine-readable pour le frontend\n * - Un `message` humain décrivant le problème\n * - Un `source` snippet du template (si la position est disponible)\n * - Des `details` structurés pour le debugging\n */\nfunction addDiagnostic(\n\tctx: AnalysisContext,\n\tcode: DiagnosticCode,\n\tseverity: \"error\" | \"warning\",\n\tmessage: string,\n\tnode?: hbs.AST.Node,\n\tdetails?: DiagnosticDetails,\n): void {\n\tconst diagnostic: TemplateDiagnostic = { severity, code, message };\n\n\t// Extraire la position et le snippet source si disponible\n\tif (node && \"loc\" in node && node.loc) {\n\t\tdiagnostic.loc = {\n\t\t\tstart: { line: node.loc.start.line, column: node.loc.start.column },\n\t\t\tend: { line: node.loc.end.line, column: node.loc.end.column },\n\t\t};\n\t\t// Extraire le fragment de template autour de l'erreur\n\t\tdiagnostic.source = extractSourceSnippet(ctx.template, diagnostic.loc);\n\t}\n\n\tif (details) {\n\t\tdiagnostic.details = details;\n\t}\n\n\tctx.diagnostics.push(diagnostic);\n}\n\n/**\n * Retourne un label lisible du type d'un schema (pour les messages d'erreur).\n */\nfunction schemaTypeLabel(schema: JSONSchema7): string {\n\tif (schema.type) {\n\t\treturn Array.isArray(schema.type) ? schema.type.join(\" | \") : schema.type;\n\t}\n\tif (schema.oneOf) return \"oneOf(...)\";\n\tif (schema.anyOf) return \"anyOf(...)\";\n\tif (schema.allOf) return \"allOf(...)\";\n\tif (schema.enum) return \"enum\";\n\treturn \"unknown\";\n}\n\n// ─── Export pour usage interne ────────────────────────────────────────────────\n// `inferBlockType` est exporté pour permettre des tests unitaires ciblés\n// sur l'inférence de type des blocs.\nexport { inferBlockType };\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": "yVAqGO,GAAS,LAAO,LACtB,JACA,EACA,EACiB,CACjB,GAAI,EAAc,CAAQ,EACzB,OAAO,EAAsB,EAAU,EAAa,CAAiB,EAEtE,GAAI,EAAe,CAAQ,EAC1B,MAAO,CACN,MAAO,GACP,YAAa,CAAC,EACd,aAAc,EAAqB,CAAQ,CAC5C,EAED,IAAM,EAAM,EAAM,CAAQ,EAC1B,OAAO,EAAe,EAAK,EAAU,EAAa,CAAE,mBAAkB,CAAC,EAQxE,SAAS,CAAqB,CAC7B,EACA,EACA,EACiB,CACjB,OAAO,EAAwB,OAAO,KAAK,CAAQ,EAAG,CAAC,IACtD,EAAQ,EAAS,GAAuB,EAAa,CAAiB,CACvE,EAeM,SAAS,CAAc,CAC7B,EACA,EACA,EACA,EAIiB,CACjB,IAAM,EAAuB,CAC5B,KAAM,EACN,QAAS,EACT,YAAa,CAAC,EACd,WACA,kBAAmB,GAAS,kBAC5B,QAAS,GA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O,MAAO,aACzB,GAAI,EAAO,KAAM,MAAO,OACxB,MAAO",
|
|
8
|
-
"debugId": "4E3D7DCBEE379AF464756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
package/dist/chunk-yraqh2tz.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{d as N}from"./chunk-yczpjh73.js";import{g as J}from"./chunk-p3xzf1ew.js";import{l as I}from"./chunk-6955jpr7.js";import{D as K}from"./chunk-vka4e61h.js";import{T as L,U as M}from"./chunk-fhvf5y4x.js";class H{state;options;hbsCompiled=null;get ast(){return this.state.kind==="template"?this.state.ast:null}get template(){return this.state.kind==="template"?this.state.source:""}constructor(w,q){this.state=w,this.options=q}static fromTemplate(w,q,B){return new H({kind:"template",ast:w,source:q},B)}static fromLiteral(w,q){return new H({kind:"literal",value:w},q)}static fromObject(w,q){return new H({kind:"object",children:w},q)}analyze(w,q){switch(this.state.kind){case"object":{let{children:B}=this.state;return L(Object.keys(B),(D)=>{let G=B[D];if(!G)throw Error(`unreachable: missing child "${D}"`);return G.analyze(w,q)})}case"literal":return{valid:!0,diagnostics:[],outputSchema:I(this.state.value)};case"template":return N(this.state.ast,this.state.source,w,{identifierSchemas:q,helpers:this.options.helpers})}}validate(w,q){let B=this.analyze(w,q);return{valid:B.valid,diagnostics:B.diagnostics}}execute(w,q){switch(this.state.kind){case"object":{let{children:B}=this.state,D={};for(let[G,Q]of Object.entries(B))D[G]=Q.execute(w,q);return D}case"literal":return this.state.value;case"template":{if(q?.schema){let B=this.analyze(q.schema,q.identifierSchemas);if(!B.valid)throw new K(B.diagnostics)}return J(this.state.ast,this.state.source,w,this.buildExecutorContext(q))}}}analyzeAndExecute(w,q,B){switch(this.state.kind){case"object":{let{children:D}=this.state;return M(Object.keys(D),(G)=>D[G].analyzeAndExecute(w,q,B))}case"literal":return{analysis:{valid:!0,diagnostics:[],outputSchema:I(this.state.value)},value:this.state.value};case"template":{let D=this.analyze(w,B?.identifierSchemas);if(!D.valid)return{analysis:D,value:void 0};let G=J(this.state.ast,this.state.source,q,this.buildExecutorContext({identifierData:B?.identifierData}));return{analysis:D,value:G}}}}buildExecutorContext(w){return{identifierData:w?.identifierData,compiledTemplate:this.getOrCompileHbs(),hbs:this.options.hbs,compilationCache:this.options.compilationCache}}getOrCompileHbs(){if(!this.hbsCompiled)this.hbsCompiled=this.options.hbs.compile(this.template,{noEscape:!0,strict:!1});return this.hbsCompiled}}
|
|
2
|
-
export{H as b};
|
|
3
|
-
|
|
4
|
-
//# debugId=BFAFD14D960B2FAD64756E2164756E21
|
|
5
|
-
//# sourceMappingURL=chunk-yraqh2tz.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/compiled-template.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type Handlebars from \"handlebars\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport { analyzeFromAst } from \"./analyzer.ts\";\nimport { TemplateAnalysisError } from \"./errors.ts\";\nimport { type ExecutorContext, executeFromAst } from \"./executor.ts\";\nimport type {\n\tAnalysisResult,\n\tExecuteOptions,\n\tHelperDefinition,\n\tValidationResult,\n} from \"./types.ts\";\nimport { inferPrimitiveSchema } from \"./types.ts\";\nimport {\n\taggregateObjectAnalysis,\n\taggregateObjectAnalysisAndExecution,\n\ttype LRUCache,\n} from \"./utils.ts\";\n\n// ─── CompiledTemplate ────────────────────────────────────────────────────────\n// Template pré-parsé et prêt à être exécuté ou analysé sans re-parsing.\n//\n// Le pattern compile-once / execute-many évite le coût du parsing Handlebars\n// à chaque appel. L'AST est parsé une seule fois lors de la compilation,\n// et le template Handlebars est compilé paresseusement au premier `execute()`.\n//\n// Usage :\n// const tpl = engine.compile(\"Hello {{name}}\");\n// tpl.execute({ name: \"Alice\" }); // pas de re-parsing\n// tpl.execute({ name: \"Bob\" }); // pas de re-parsing ni recompilation\n// tpl.analyze(schema); // pas de re-parsing\n//\n// ─── État interne (TemplateState) ────────────────────────────────────────────\n// Le CompiledTemplate fonctionne en 3 modes exclusifs, modélisés par un\n// discriminated union `TemplateState` :\n//\n// - `\"template\"` — template Handlebars parsé (AST + source string)\n// - `\"literal\"` — valeur primitive passthrough (number, boolean, null)\n// - `\"object\"` — objet dont chaque propriété est un CompiledTemplate enfant\n//\n// Ce design élimine les champs optionnels et les `!` assertions en faveur\n// d'un narrowing TypeScript naturel via `switch (this.state.kind)`.\n//\n// ─── Avantages par rapport à l'API directe ───────────────────────────────────\n// - **Performance** : parsing et compilation ne sont faits qu'une seule fois\n// - **API simplifiée** : pas besoin de repasser le template string à chaque appel\n// - **Cohérence** : le même AST est utilisé pour l'analyse et l'exécution\n\n// ─── Types internes ──────────────────────────────────────────────────────────\n\n/** Options internes passées par le Typebars lors de la compilation */\nexport interface CompiledTemplateOptions {\n\t/** Helpers custom enregistrés sur l'engine */\n\thelpers: Map<string, HelperDefinition>;\n\t/** Environnement Handlebars isolé (avec les helpers enregistrés) */\n\thbs: typeof Handlebars;\n\t/** Cache de compilation partagé par l'engine */\n\tcompilationCache: LRUCache<string, HandlebarsTemplateDelegate>;\n}\n\n/** État interne discriminé du CompiledTemplate */\ntype TemplateState =\n\t| {\n\t\t\treadonly kind: \"template\";\n\t\t\treadonly ast: hbs.AST.Program;\n\t\t\treadonly source: string;\n\t }\n\t| { readonly kind: \"literal\"; readonly value: number | boolean | null }\n\t| {\n\t\t\treadonly kind: \"object\";\n\t\t\treadonly children: Record<string, CompiledTemplate>;\n\t };\n\n// ─── Classe publique ─────────────────────────────────────────────────────────\n\nexport class CompiledTemplate {\n\t/** État interne discriminé */\n\tprivate readonly state: TemplateState;\n\n\t/** Options héritées du Typebars parent */\n\tprivate readonly options: CompiledTemplateOptions;\n\n\t/** Template Handlebars compilé (lazy — créé au premier `execute()` qui en a besoin) */\n\tprivate hbsCompiled: HandlebarsTemplateDelegate | null = null;\n\n\t// ─── Accesseurs publics (backward-compatible) ────────────────────────\n\n\t/** L'AST Handlebars pré-parsé — `null` en mode littéral ou objet */\n\tget ast(): hbs.AST.Program | null {\n\t\treturn this.state.kind === \"template\" ? this.state.ast : null;\n\t}\n\n\t/** Le template source original — string vide en mode littéral ou objet */\n\tget template(): string {\n\t\treturn this.state.kind === \"template\" ? this.state.source : \"\";\n\t}\n\n\t// ─── Construction ────────────────────────────────────────────────────\n\n\tprivate constructor(state: TemplateState, options: CompiledTemplateOptions) {\n\t\tthis.state = state;\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * Crée un CompiledTemplate pour un template Handlebars parsé.\n\t *\n\t * @param ast - L'AST Handlebars pré-parsé\n\t * @param source - Le template source original\n\t * @param options - Options héritées du Typebars\n\t */\n\tstatic fromTemplate(\n\t\tast: hbs.AST.Program,\n\t\tsource: string,\n\t\toptions: CompiledTemplateOptions,\n\t): CompiledTemplate {\n\t\treturn new CompiledTemplate({ kind: \"template\", ast, source }, options);\n\t}\n\n\t/**\n\t * Crée un CompiledTemplate en mode passthrough pour une valeur littérale\n\t * (number, boolean, null). Aucun parsing ni compilation n'est effectué.\n\t *\n\t * @param value - La valeur primitive\n\t * @param options - Options héritées du Typebars\n\t * @returns Un CompiledTemplate qui retourne toujours `value`\n\t */\n\tstatic fromLiteral(\n\t\tvalue: number | boolean | null,\n\t\toptions: CompiledTemplateOptions,\n\t): CompiledTemplate {\n\t\treturn new CompiledTemplate({ kind: \"literal\", value }, options);\n\t}\n\n\t/**\n\t * Crée un CompiledTemplate en mode objet, où chaque propriété est un\n\t * CompiledTemplate enfant. Toutes les opérations sont déléguées\n\t * récursivement aux enfants.\n\t *\n\t * @param children - Les templates enfants compilés `{ [key]: CompiledTemplate }`\n\t * @param options - Options héritées du Typebars\n\t * @returns Un CompiledTemplate qui délègue aux enfants\n\t */\n\tstatic fromObject(\n\t\tchildren: Record<string, CompiledTemplate>,\n\t\toptions: CompiledTemplateOptions,\n\t): CompiledTemplate {\n\t\treturn new CompiledTemplate({ kind: \"object\", children }, options);\n\t}\n\n\t// ─── Analyse statique ────────────────────────────────────────────────\n\n\t/**\n\t * Analyse statiquement ce template par rapport à un JSON Schema v7.\n\t *\n\t * Retourne un `AnalysisResult` contenant :\n\t * - `valid` — `true` si aucune erreur\n\t * - `diagnostics` — liste de diagnostics (erreurs + warnings)\n\t * - `outputSchema` — JSON Schema décrivant le type de retour\n\t *\n\t * L'AST étant pré-parsé, cette méthode ne re-parse jamais le template.\n\t *\n\t * @param inputSchema - JSON Schema décrivant les variables disponibles\n\t * @param identifierSchemas - (optionnel) Schemas par identifiant `{ [id]: JSONSchema7 }`\n\t */\n\tanalyze(\n\t\tinputSchema: JSONSchema7,\n\t\tidentifierSchemas?: Record<number, JSONSchema7>,\n\t): AnalysisResult {\n\t\tswitch (this.state.kind) {\n\t\t\tcase \"object\": {\n\t\t\t\tconst { children } = this.state;\n\t\t\t\treturn aggregateObjectAnalysis(Object.keys(children), (key) => {\n\t\t\t\t\tconst child = children[key];\n\t\t\t\t\tif (!child) throw new Error(`unreachable: missing child \"${key}\"`);\n\t\t\t\t\treturn child.analyze(inputSchema, identifierSchemas);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcase \"literal\":\n\t\t\t\treturn {\n\t\t\t\t\tvalid: true,\n\t\t\t\t\tdiagnostics: [],\n\t\t\t\t\toutputSchema: inferPrimitiveSchema(this.state.value),\n\t\t\t\t};\n\n\t\t\tcase \"template\":\n\t\t\t\treturn analyzeFromAst(this.state.ast, this.state.source, inputSchema, {\n\t\t\t\t\tidentifierSchemas,\n\t\t\t\t\thelpers: this.options.helpers,\n\t\t\t\t});\n\t\t}\n\t}\n\n\t// ─── Validation ──────────────────────────────────────────────────────\n\n\t/**\n\t * Valide le template contre un schema sans retourner le type de sortie.\n\t *\n\t * C'est un raccourci d'API pour `analyze()` qui ne retourne que `valid`\n\t * et `diagnostics`, sans `outputSchema`. L'analyse complète (y compris\n\t * l'inférence de type) est exécutée en interne — cette méthode ne\n\t * fournit pas de gain de performance, uniquement une API simplifiée.\n\t *\n\t * @param inputSchema - JSON Schema décrivant les variables disponibles\n\t * @param identifierSchemas - (optionnel) Schemas par identifiant\n\t */\n\tvalidate(\n\t\tinputSchema: JSONSchema7,\n\t\tidentifierSchemas?: Record<number, JSONSchema7>,\n\t): ValidationResult {\n\t\tconst analysis = this.analyze(inputSchema, identifierSchemas);\n\t\treturn {\n\t\t\tvalid: analysis.valid,\n\t\t\tdiagnostics: analysis.diagnostics,\n\t\t};\n\t}\n\n\t// ─── Exécution ───────────────────────────────────────────────────────\n\n\t/**\n\t * Exécute ce template avec les données fournies.\n\t *\n\t * Le type de retour dépend de la structure du template :\n\t * - Expression unique `{{expr}}` → valeur brute (number, boolean, object…)\n\t * - Template mixte ou avec blocs → `string`\n\t * - Littéral primitif → la valeur telle quelle\n\t * - Objet template → objet avec les valeurs résolues\n\t *\n\t * Si un `schema` est fourni dans les options, l'analyse statique est\n\t * lancée avant l'exécution. Une `TemplateAnalysisError` est levée en\n\t * cas d'erreur.\n\t *\n\t * @param data - Les données de contexte pour le rendu\n\t * @param options - Options d'exécution (schema, identifierData, etc.)\n\t * @returns Le résultat de l'exécution\n\t */\n\texecute(data: Record<string, unknown>, options?: ExecuteOptions): unknown {\n\t\tswitch (this.state.kind) {\n\t\t\tcase \"object\": {\n\t\t\t\tconst { children } = this.state;\n\t\t\t\tconst result: Record<string, unknown> = {};\n\t\t\t\tfor (const [key, child] of Object.entries(children)) {\n\t\t\t\t\tresult[key] = child.execute(data, options);\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tcase \"literal\":\n\t\t\t\treturn this.state.value;\n\n\t\t\tcase \"template\": {\n\t\t\t\t// Validation statique préalable si un schema est fourni\n\t\t\t\tif (options?.schema) {\n\t\t\t\t\tconst analysis = this.analyze(\n\t\t\t\t\t\toptions.schema,\n\t\t\t\t\t\toptions.identifierSchemas,\n\t\t\t\t\t);\n\t\t\t\t\tif (!analysis.valid) {\n\t\t\t\t\t\tthrow new TemplateAnalysisError(analysis.diagnostics);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn executeFromAst(\n\t\t\t\t\tthis.state.ast,\n\t\t\t\t\tthis.state.source,\n\t\t\t\t\tdata,\n\t\t\t\t\tthis.buildExecutorContext(options),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// ─── Raccourcis combinés ─────────────────────────────────────────────\n\n\t/**\n\t * Analyse et exécute le template en un seul appel.\n\t *\n\t * Retourne à la fois le résultat d'analyse et la valeur exécutée.\n\t * Si l'analyse échoue, `value` est `undefined`.\n\t *\n\t * @param inputSchema - JSON Schema décrivant les variables disponibles\n\t * @param data - Les données de contexte pour le rendu\n\t * @param options - Options supplémentaires\n\t * @returns `{ analysis, value }`\n\t */\n\tanalyzeAndExecute(\n\t\tinputSchema: JSONSchema7,\n\t\tdata: Record<string, unknown>,\n\t\toptions?: {\n\t\t\tidentifierSchemas?: Record<number, JSONSchema7>;\n\t\t\tidentifierData?: Record<number, Record<string, unknown>>;\n\t\t},\n\t): { analysis: AnalysisResult; value: unknown } {\n\t\tswitch (this.state.kind) {\n\t\t\tcase \"object\": {\n\t\t\t\tconst { children } = this.state;\n\t\t\t\treturn aggregateObjectAnalysisAndExecution(\n\t\t\t\t\tObject.keys(children),\n\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: key comes from Object.keys(children), access is guaranteed\n\t\t\t\t\t(key) => children[key]!.analyzeAndExecute(inputSchema, data, options),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tcase \"literal\":\n\t\t\t\treturn {\n\t\t\t\t\tanalysis: {\n\t\t\t\t\t\tvalid: true,\n\t\t\t\t\t\tdiagnostics: [],\n\t\t\t\t\t\toutputSchema: inferPrimitiveSchema(this.state.value),\n\t\t\t\t\t},\n\t\t\t\t\tvalue: this.state.value,\n\t\t\t\t};\n\n\t\t\tcase \"template\": {\n\t\t\t\tconst analysis = this.analyze(inputSchema, options?.identifierSchemas);\n\n\t\t\t\tif (!analysis.valid) {\n\t\t\t\t\treturn { analysis, value: undefined };\n\t\t\t\t}\n\n\t\t\t\tconst value = executeFromAst(\n\t\t\t\t\tthis.state.ast,\n\t\t\t\t\tthis.state.source,\n\t\t\t\t\tdata,\n\t\t\t\t\tthis.buildExecutorContext({\n\t\t\t\t\t\tidentifierData: options?.identifierData,\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\treturn { analysis, value };\n\t\t\t}\n\t\t}\n\t}\n\n\t// ─── Internals ───────────────────────────────────────────────────────\n\n\t/**\n\t * Construit le contexte d'exécution pour `executeFromAst`.\n\t *\n\t * Utilise la compilation Handlebars lazy : le template n'est compilé\n\t * qu'au premier appel qui en a besoin (pas les expressions uniques).\n\t */\n\tprivate buildExecutorContext(options?: ExecuteOptions): ExecutorContext {\n\t\treturn {\n\t\t\tidentifierData: options?.identifierData,\n\t\t\tcompiledTemplate: this.getOrCompileHbs(),\n\t\t\thbs: this.options.hbs,\n\t\t\tcompilationCache: this.options.compilationCache,\n\t\t};\n\t}\n\n\t/**\n\t * Compile le template Handlebars de manière lazy et le met en cache.\n\t *\n\t * La compilation n'est faite qu'une seule fois — les appels suivants\n\t * retournent le template compilé en mémoire.\n\t *\n\t * Pré-condition : cette méthode n'est appelée que depuis le mode \"template\".\n\t */\n\tprivate getOrCompileHbs(): HandlebarsTemplateDelegate {\n\t\tif (!this.hbsCompiled) {\n\t\t\t// En mode \"template\", `this.template` retourne la source string\n\t\t\tthis.hbsCompiled = this.options.hbs.compile(this.template, {\n\t\t\t\tnoEscape: true,\n\t\t\t\tstrict: false,\n\t\t\t});\n\t\t}\n\t\treturn this.hbsCompiled;\n\t}\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": "uOA0EO,AAAM,LAAiB,LAEZ,AAGA,QAGT,YAAiD,QAKrD,IAAG,EAA2B,CACjC,OAAO,KAAK,MAAM,OAAS,WAAa,KAAK,MAAM,IAAM,QAItD,SAAQ,EAAW,CACtB,OAAO,KAAK,MAAM,OAAS,WAAa,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package/dist/chunk-z6yh5qvc.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{d as N}from"./chunk-awgj10qg.js";import{g as J}from"./chunk-qpzzr2rd.js";import{l as I}from"./chunk-6955jpr7.js";import{B as K}from"./chunk-ybh51hbe.js";import{Q as L,R as M}from"./chunk-4zv02svp.js";class H{state;options;hbsCompiled=null;get ast(){return this.state.kind==="template"?this.state.ast:null}get template(){return this.state.kind==="template"?this.state.source:""}constructor(w,q){this.state=w,this.options=q}static fromTemplate(w,q,B){return new H({kind:"template",ast:w,source:q},B)}static fromLiteral(w,q){return new H({kind:"literal",value:w},q)}static fromObject(w,q){return new H({kind:"object",children:w},q)}analyze(w,q){switch(this.state.kind){case"object":{let{children:B}=this.state;return L(Object.keys(B),(D)=>{let G=B[D];if(!G)throw Error(`unreachable: missing child "${D}"`);return G.analyze(w,q)})}case"literal":return{valid:!0,diagnostics:[],outputSchema:I(this.state.value)};case"template":return N(this.state.ast,this.state.source,w,{identifierSchemas:q,helpers:this.options.helpers})}}validate(w,q){let B=this.analyze(w,q);return{valid:B.valid,diagnostics:B.diagnostics}}execute(w,q){switch(this.state.kind){case"object":{let{children:B}=this.state,D={};for(let[G,Q]of Object.entries(B))D[G]=Q.execute(w,q);return D}case"literal":return this.state.value;case"template":{if(q?.schema){let B=this.analyze(q.schema,q.identifierSchemas);if(!B.valid)throw new K(B.diagnostics)}return J(this.state.ast,this.state.source,w,this.buildExecutorContext(q))}}}analyzeAndExecute(w,q,B){switch(this.state.kind){case"object":{let{children:D}=this.state;return M(Object.keys(D),(G)=>D[G].analyzeAndExecute(w,q,B))}case"literal":return{analysis:{valid:!0,diagnostics:[],outputSchema:I(this.state.value)},value:this.state.value};case"template":{let D=this.analyze(w,B?.identifierSchemas);if(!D.valid)return{analysis:D,value:void 0};let G=J(this.state.ast,this.state.source,q,this.buildExecutorContext({identifierData:B?.identifierData}));return{analysis:D,value:G}}}}buildExecutorContext(w){return{identifierData:w?.identifierData,compiledTemplate:this.getOrCompileHbs(),hbs:this.options.hbs,compilationCache:this.options.compilationCache}}getOrCompileHbs(){if(!this.hbsCompiled)this.hbsCompiled=this.options.hbs.compile(this.template,{noEscape:!0,strict:!1});return this.hbsCompiled}}
|
|
2
|
-
export{H as b};
|
|
3
|
-
|
|
4
|
-
//# debugId=7E9B6C0E0074084D64756E2164756E21
|
|
5
|
-
//# sourceMappingURL=chunk-z6yh5qvc.js.map
|