typebars 1.0.2 → 1.0.3

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.
Files changed (40) hide show
  1. package/dist/analyzer.js +2 -2
  2. package/dist/analyzer.js.map +1 -1
  3. package/dist/{chunk-jms1ndxn.js → chunk-5znsrn10.js} +4 -4
  4. package/dist/{chunk-jms1ndxn.js.map → chunk-5znsrn10.js.map} +1 -1
  5. package/dist/{chunk-ecs3yth2.js → chunk-867xywnk.js} +4 -4
  6. package/dist/{chunk-ecs3yth2.js.map → chunk-867xywnk.js.map} +1 -1
  7. package/dist/{chunk-6955jpr7.js → chunk-8xza8tca.js} +3 -3
  8. package/dist/{chunk-6955jpr7.js.map → chunk-8xza8tca.js.map} +1 -1
  9. package/dist/{chunk-p5efqsxw.js → chunk-9jxzj2h4.js} +3 -3
  10. package/dist/{chunk-p5efqsxw.js.map → chunk-9jxzj2h4.js.map} +1 -1
  11. package/dist/chunk-dpffacsy.js +4 -0
  12. package/dist/{chunk-t6n956qz.js.map → chunk-dpffacsy.js.map} +2 -2
  13. package/dist/{chunk-zh1e0yhd.js → chunk-gayk9ew1.js} +3 -3
  14. package/dist/{chunk-zh1e0yhd.js.map → chunk-gayk9ew1.js.map} +1 -1
  15. package/dist/{chunk-rkrp4ysw.js → chunk-s96k41p3.js} +4 -4
  16. package/dist/{chunk-rkrp4ysw.js.map → chunk-s96k41p3.js.map} +1 -1
  17. package/dist/{chunk-efqd0598.js → chunk-wvnn9g55.js} +4 -4
  18. package/dist/{chunk-efqd0598.js.map → chunk-wvnn9g55.js.map} +1 -1
  19. package/dist/compiled-template.js +2 -2
  20. package/dist/compiled-template.js.map +1 -1
  21. package/dist/errors.js +2 -2
  22. package/dist/errors.js.map +1 -1
  23. package/dist/executor.js +2 -2
  24. package/dist/executor.js.map +1 -1
  25. package/dist/index.js +2 -2
  26. package/dist/index.js.map +1 -1
  27. package/dist/parser.js +2 -2
  28. package/dist/parser.js.map +1 -1
  29. package/dist/schema-resolver.js +2 -2
  30. package/dist/schema-resolver.js.map +1 -1
  31. package/dist/typebars.js +2 -2
  32. package/dist/typebars.js.map +8 -3
  33. package/dist/types.js +2 -2
  34. package/dist/types.js.map +1 -1
  35. package/dist/utils.js +2 -2
  36. package/dist/utils.js.map +1 -1
  37. package/package.json +2 -2
  38. package/dist/chunk-t6n956qz.js +0 -4
  39. package/dist/chunk-xd2vmd03.js +0 -5
  40. package/dist/chunk-xd2vmd03.js.map +0 -14
@@ -5,6 +5,6 @@
5
5
  "import Handlebars from \"handlebars\";\nimport { TemplateRuntimeError } from \"./errors.ts\";\nimport {\n\tcanUseFastPath,\n\tcoerceLiteral,\n\textractExpressionIdentifier,\n\textractPathSegments,\n\tgetEffectivelySingleBlock,\n\tgetEffectivelySingleExpression,\n\tisSingleExpression,\n\tisThisExpression,\n\tparse,\n} from \"./parser.ts\";\nimport type { TemplateInput, TemplateInputObject } from \"./types.ts\";\nimport { isLiteralInput, isObjectInput } from \"./types.ts\";\nimport { LRUCache } from \"./utils.ts\";\n\n// ─── Template Executor ───────────────────────────────────────────────────────\n// Executes a Handlebars template with real data.\n//\n// Four execution modes (from fastest to most general):\n//\n// 1. **Single expression** (`{{value}}` or ` {{value}} `) → returns the raw\n// value without converting to string. This preserves the original type\n// (number, boolean, object, array, null).\n//\n// 2. **Fast-path** (text + simple expressions, no blocks or helpers) →\n// direct concatenation without going through Handlebars.compile(). Up to\n// 10-100x faster for simple templates like `Hello {{name}}`.\n//\n// 3. **Single block** (`{{#if x}}10{{else}}20{{/if}}` possibly surrounded\n// by whitespace) → rendered via Handlebars then intelligently coerced\n// (detecting number, boolean, null literals).\n//\n// 4. **Mixed template** (text + multiple blocks, helpers, …) →\n// delegates to Handlebars which always produces a string.\n//\n// ─── Caching ─────────────────────────────────────────────────────────────────\n// Handlebars-compiled templates are cached in an LRU cache to avoid costly\n// recompilation on repeated calls.\n//\n// Two cache levels:\n// - **Global cache** (module-level) for standalone `execute()` calls\n// - **Instance cache** for `Typebars` (passed via `ExecutorContext`)\n//\n// ─── Template Identifiers ────────────────────────────────────────────────────\n// The `{{key:N}}` syntax allows resolving a variable from a specific data\n// source, identified by an integer N. The optional `identifierData` parameter\n// provides a mapping `{ [id]: { key: value, ... } }`.\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Optional context for execution (used by Typebars/CompiledTemplate) */\nexport interface ExecutorContext {\n\t/** Data by identifier `{ [id]: { key: value } }` */\n\tidentifierData?: Record<number, Record<string, unknown>>;\n\t/** Pre-compiled Handlebars template (for CompiledTemplate) */\n\tcompiledTemplate?: HandlebarsTemplateDelegate;\n\t/** Isolated Handlebars environment (for custom helpers) */\n\thbs?: typeof Handlebars;\n\t/** Compilation cache shared by the engine */\n\tcompilationCache?: LRUCache<string, HandlebarsTemplateDelegate>;\n}\n\n// ─── Global Compilation Cache ────────────────────────────────────────────────\n// Used by the standalone `execute()` function and `renderWithHandlebars()`.\n// `Typebars` instances use their own cache.\nconst globalCompilationCache = new LRUCache<string, HandlebarsTemplateDelegate>(\n\t128,\n);\n\n// ─── Public API (backward-compatible) ────────────────────────────────────────\n\n/**\n * Executes a template with the provided data and returns the result.\n *\n * The return type depends on the template structure:\n * - Single expression `{{expr}}` → raw value (any)\n * - Single block → coerced value (number, boolean, null, or string)\n * - Mixed template → `string`\n *\n * @param template - The template string\n * @param data - The main context data\n * @param identifierData - (optional) Data by identifier `{ [id]: { key: value } }`\n */\nexport function execute(\n\ttemplate: TemplateInput,\n\tdata: Record<string, unknown>,\n\tidentifierData?: Record<number, Record<string, unknown>>,\n): unknown {\n\tif (isObjectInput(template)) {\n\t\treturn executeObjectTemplate(template, data, identifierData);\n\t}\n\tif (isLiteralInput(template)) return template;\n\tconst ast = parse(template);\n\treturn executeFromAst(ast, template, data, { identifierData });\n}\n\n/**\n * Executes an object template recursively (standalone version).\n * Each property is executed individually and the result is an object\n * with the same structure but resolved values.\n */\nfunction executeObjectTemplate(\n\ttemplate: TemplateInputObject,\n\tdata: Record<string, unknown>,\n\tidentifierData?: Record<number, Record<string, unknown>>,\n): Record<string, unknown> {\n\tconst result: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(template)) {\n\t\tresult[key] = execute(value, data, identifierData);\n\t}\n\treturn result;\n}\n\n// ─── Internal API (for Typebars / CompiledTemplate) ──────────────────────\n\n/**\n * Executes a template from an already-parsed AST.\n *\n * This function is the core of execution. It is used by:\n * - `execute()` (backward-compatible wrapper)\n * - `CompiledTemplate.execute()` (with pre-parsed AST and cache)\n * - `Typebars.execute()` (with cache and helpers)\n *\n * @param ast - The already-parsed Handlebars AST\n * @param template - The template source (for Handlebars compilation if needed)\n * @param data - The main context data\n * @param ctx - Optional execution context\n */\nexport function executeFromAst(\n\tast: hbs.AST.Program,\n\ttemplate: string,\n\tdata: Record<string, unknown>,\n\tctx?: ExecutorContext,\n): unknown {\n\tconst identifierData = ctx?.identifierData;\n\n\t// ── Case 1: strict single expression `{{expr}}` ──────────────────────\n\t// Exclude helper calls (params > 0 or hash) because they must go\n\t// through Handlebars for correct execution.\n\tif (isSingleExpression(ast)) {\n\t\tconst stmt = ast.body[0] as hbs.AST.MustacheStatement;\n\t\tif (stmt.params.length === 0 && !stmt.hash) {\n\t\t\treturn resolveExpression(stmt.path, data, identifierData);\n\t\t}\n\t}\n\n\t// ── Case 1b: single expression with surrounding whitespace ` {{expr}} `\n\tconst singleExpr = getEffectivelySingleExpression(ast);\n\tif (singleExpr && singleExpr.params.length === 0 && !singleExpr.hash) {\n\t\treturn resolveExpression(singleExpr.path, data, identifierData);\n\t}\n\n\t// ── Case 1c: single expression with helper (params > 0) ──────────────\n\t// E.g. `{{ divide accountIds.length 10 }}` or `{{ math a \"+\" b }}`\n\t// The helper returns a typed value but Handlebars converts it to a\n\t// string. We render via Handlebars then coerce the result to recover\n\t// the original type (number, boolean, null).\n\tif (singleExpr && (singleExpr.params.length > 0 || singleExpr.hash)) {\n\t\tconst merged = mergeDataWithIdentifiers(data, identifierData);\n\t\tconst raw = renderWithHandlebars(template, merged, ctx);\n\t\treturn coerceLiteral(raw);\n\t}\n\n\t// ── Case 2: fast-path for simple templates (text + expressions) ──────\n\t// If the template only contains text and simple expressions (no blocks,\n\t// no helpers with parameters), we can do direct concatenation without\n\t// going through Handlebars.compile().\n\tif (canUseFastPath(ast) && ast.body.length > 1) {\n\t\treturn executeFastPath(ast, data, identifierData);\n\t}\n\n\t// ── Case 3: single block (possibly surrounded by whitespace) ─────────\n\t// Render via Handlebars then attempt to coerce the result to the\n\t// detected literal type (number, boolean, null).\n\tconst singleBlock = getEffectivelySingleBlock(ast);\n\tif (singleBlock) {\n\t\tconst merged = mergeDataWithIdentifiers(data, identifierData);\n\t\tconst raw = renderWithHandlebars(template, merged, ctx);\n\t\treturn coerceLiteral(raw);\n\t}\n\n\t// ── Case 4: mixed template → string ──────────────────────────────────\n\tconst merged = mergeDataWithIdentifiers(data, identifierData);\n\treturn renderWithHandlebars(template, merged, ctx);\n}\n\n// ─── Fast-Path Execution ─────────────────────────────────────────────────────\n// For templates consisting only of text and simple expressions (no blocks,\n// no helpers), we bypass Handlebars and do direct concatenation.\n// This is significantly faster.\n\n/**\n * Executes a template via the fast-path (direct concatenation).\n *\n * Precondition: `canUseFastPath(ast)` must return `true`.\n *\n * @param ast - The template AST (only ContentStatement and simple MustacheStatement)\n * @param data - The context data\n * @param identifierData - Data by identifier (optional)\n * @returns The resulting string\n */\nfunction executeFastPath(\n\tast: hbs.AST.Program,\n\tdata: Record<string, unknown>,\n\tidentifierData?: Record<number, Record<string, unknown>>,\n): string {\n\tlet result = \"\";\n\n\tfor (const stmt of ast.body) {\n\t\tif (stmt.type === \"ContentStatement\") {\n\t\t\tresult += (stmt as hbs.AST.ContentStatement).value;\n\t\t} else if (stmt.type === \"MustacheStatement\") {\n\t\t\tconst value = resolveExpression(\n\t\t\t\t(stmt as hbs.AST.MustacheStatement).path,\n\t\t\t\tdata,\n\t\t\t\tidentifierData,\n\t\t\t);\n\t\t\t// Handlebars converts values to strings for rendering.\n\t\t\t// We replicate this behavior: null/undefined → \"\", otherwise String(value).\n\t\t\tif (value != null) {\n\t\t\t\tresult += String(value);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result;\n}\n\n// ─── Direct Expression Resolution ────────────────────────────────────────────\n// Used for single-expression templates and the fast-path, to return the raw\n// value without going through the Handlebars engine.\n\n/**\n * Resolves an AST expression by following the path through the data.\n *\n * If the expression contains an identifier (e.g. `meetingId:1`), resolution\n * is performed in `identifierData[1]` instead of `data`.\n *\n * @param expr - The AST expression to resolve\n * @param data - The main data context\n * @param identifierData - Data by identifier (optional)\n * @returns The raw value pointed to by the expression\n */\nfunction resolveExpression(\n\texpr: hbs.AST.Expression,\n\tdata: Record<string, unknown>,\n\tidentifierData?: Record<number, Record<string, unknown>>,\n): unknown {\n\t// this / . → return the entire context\n\tif (isThisExpression(expr)) {\n\t\treturn data;\n\t}\n\n\t// Literals\n\tif (expr.type === \"StringLiteral\")\n\t\treturn (expr as hbs.AST.StringLiteral).value;\n\tif (expr.type === \"NumberLiteral\")\n\t\treturn (expr as hbs.AST.NumberLiteral).value;\n\tif (expr.type === \"BooleanLiteral\")\n\t\treturn (expr as hbs.AST.BooleanLiteral).value;\n\tif (expr.type === \"NullLiteral\") return null;\n\tif (expr.type === \"UndefinedLiteral\") return undefined;\n\n\t// PathExpression — navigate through segments in the data object\n\tconst segments = extractPathSegments(expr);\n\tif (segments.length === 0) {\n\t\tthrow new TemplateRuntimeError(\n\t\t\t`Cannot resolve expression of type \"${expr.type}\"`,\n\t\t);\n\t}\n\n\t// Extract the potential identifier from the last segment\n\tconst { cleanSegments, identifier } = extractExpressionIdentifier(segments);\n\n\tif (identifier !== null && identifierData) {\n\t\tconst source = identifierData[identifier];\n\t\tif (source) {\n\t\t\treturn resolveDataPath(source, cleanSegments);\n\t\t}\n\t\t// Source does not exist → undefined (like a missing key)\n\t\treturn undefined;\n\t}\n\n\tif (identifier !== null && !identifierData) {\n\t\t// Template uses an identifier but no identifierData was provided\n\t\treturn undefined;\n\t}\n\n\treturn resolveDataPath(data, cleanSegments);\n}\n\n/**\n * Navigates through a data object by following a path of segments.\n *\n * @param data - The data object\n * @param segments - The path segments (e.g. `[\"user\", \"address\", \"city\"]`)\n * @returns The value at the end of the path, or `undefined` if an\n * intermediate segment is null/undefined\n */\nexport function resolveDataPath(data: unknown, segments: string[]): unknown {\n\tlet current: unknown = data;\n\n\tfor (const segment of segments) {\n\t\tif (current === null || current === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (typeof current !== \"object\") {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tcurrent = (current as Record<string, unknown>)[segment];\n\t}\n\n\treturn current;\n}\n\n// ─── Data Merging ────────────────────────────────────────────────────────────\n// For Handlebars rendering (mixed templates / blocks), we cannot intercept\n// resolution on a per-expression basis. Instead, we merge identifier data\n// into the main object using the format `\"key:N\"`.\n//\n// Handlebars parses `{{meetingId:1}}` as a PathExpression with a single\n// segment `\"meetingId:1\"`, so it looks up the key `\"meetingId:1\"` in the\n// data object — which matches our flattened format exactly.\n\n/**\n * Merges the main data with identifier data.\n *\n * @param data - Main data\n * @param identifierData - Data by identifier\n * @returns A merged object where identifier data appears as `\"key:N\"` keys\n *\n * @example\n * ```\n * mergeDataWithIdentifiers(\n * { name: \"Alice\" },\n * { 1: { meetingId: \"val1\" }, 2: { meetingId: \"val2\" } }\n * )\n * // → { name: \"Alice\", \"meetingId:1\": \"val1\", \"meetingId:2\": \"val2\" }\n * ```\n */\nfunction mergeDataWithIdentifiers(\n\tdata: Record<string, unknown>,\n\tidentifierData?: Record<number, Record<string, unknown>>,\n): Record<string, unknown> {\n\tif (!identifierData) return data;\n\n\tconst merged: Record<string, unknown> = { ...data };\n\n\tfor (const [id, idData] of Object.entries(identifierData)) {\n\t\tfor (const [key, value] of Object.entries(idData)) {\n\t\t\tmerged[`${key}:${id}`] = value;\n\t\t}\n\t}\n\n\treturn merged;\n}\n\n// ─── Handlebars Rendering ────────────────────────────────────────────────────\n// For complex templates (blocks, helpers), we delegate to Handlebars.\n// Compilation is cached to avoid costly recompilations.\n\n/**\n * Compiles and executes a template via Handlebars.\n *\n * Uses a compilation cache (LRU) to avoid recompiling the same template\n * on repeated calls. The cache is either:\n * - The global cache (for the standalone `execute()` function)\n * - The instance cache provided via `ExecutorContext` (for `Typebars`)\n *\n * @param template - The template string\n * @param data - The context data\n * @param ctx - Optional execution context (cache, Handlebars env)\n * @returns Always a string\n */\nfunction renderWithHandlebars(\n\ttemplate: string,\n\tdata: Record<string, unknown>,\n\tctx?: ExecutorContext,\n): string {\n\ttry {\n\t\t// 1. Use the pre-compiled template if available (CompiledTemplate)\n\t\tif (ctx?.compiledTemplate) {\n\t\t\treturn ctx.compiledTemplate(data);\n\t\t}\n\n\t\t// 2. Look up in the cache (instance or global)\n\t\tconst cache = ctx?.compilationCache ?? globalCompilationCache;\n\t\tconst hbs = ctx?.hbs ?? Handlebars;\n\n\t\tlet compiled = cache.get(template);\n\t\tif (!compiled) {\n\t\t\tcompiled = hbs.compile(template, {\n\t\t\t\t// Disable HTML-escaping by default — this engine is not\n\t\t\t\t// HTML-specific, we want raw values.\n\t\t\t\tnoEscape: true,\n\t\t\t\t// Strict mode: throws if a path does not exist in the data.\n\t\t\t\tstrict: false,\n\t\t\t});\n\t\t\tcache.set(template, compiled);\n\t\t}\n\n\t\treturn compiled(data);\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new TemplateRuntimeError(message);\n\t}\n}\n\n/**\n * Clears the global Handlebars compilation cache.\n * Useful for tests or to free memory.\n */\nexport function clearCompilationCache(): void {\n\tglobalCompilationCache.clear();\n}\n"
6
6
  ],
7
7
  "mappings": "iPAAA,oBAmEA,FAAM,JAAyB,IAAI,EAClC,GACD,EAgBO,SAAS,CAAO,CACtB,EACA,EACA,EACU,CACV,GAAI,EAAc,CAAQ,EACzB,OAAO,EAAsB,EAAU,EAAM,CAAc,EAE5D,GAAI,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OAAO,EAAI,iBAAiB,CAAI,EAIjC,IAAM,EAAQ,GAAK,kBAAoB,EACjC,EAAM,GAAK,KAAO,EAEpB,EAAW,EAAM,IAAI,CAAQ,EACjC,GAAI,CAAC,EACJ,EAAW,EAAI,QAAQ,EAAU,CAGhC,SAAU,GAEV,OAAQ,EACT,CAAC,EACD,EAAM,IAAI,EAAU,CAAQ,EAG7B,OAAO,EAAS,CAAI,EACnB,MAAO,EAAgB,CACxB,IAAM,EAAU,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,EACrE,MAAM,IAAI,EAAqB,CAAO,GAQjC,SAAS,CAAqB,EAAS,CAC7C,EAAuB,MAAM",
8
- "debugId": "238A297F9D815C1664756E2164756E21",
8
+ "debugId": "93ED260B549AAA3364756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
- import{b as a}from"./chunk-ecs3yth2.js";import"./chunk-t6n956qz.js";import"./chunk-efqd0598.js";import"./chunk-6955jpr7.js";import"./chunk-rkrp4ysw.js";import"./chunk-jms1ndxn.js";import"./chunk-p5efqsxw.js";import"./chunk-zh1e0yhd.js";export{a as CompiledTemplate};
1
+ import{a}from"./chunk-867xywnk.js";import"./chunk-dpffacsy.js";import"./chunk-wvnn9g55.js";import"./chunk-8xza8tca.js";import"./chunk-s96k41p3.js";import"./chunk-5znsrn10.js";import"./chunk-9jxzj2h4.js";import"./chunk-gayk9ew1.js";export{a as CompiledTemplate};
2
2
 
3
- //# debugId=771271DE7F3CA9FE64756E2164756E21
3
+ //# debugId=EA7156E904A2F7A364756E2164756E21
4
4
  //# sourceMappingURL=compiled-template.js.map
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "771271DE7F3CA9FE64756E2164756E21",
7
+ "debugId": "EA7156E904A2F7A364756E2164756E21",
8
8
  "names": []
9
9
  }
package/dist/errors.js CHANGED
@@ -1,4 +1,4 @@
1
- import{K as a,L as b,M as c,N as d,O as e,P as f,Q as g,R as h,S as i,T as j}from"./chunk-zh1e0yhd.js";export{i as createUnknownHelperMessage,j as createUnanalyzableMessage,g as createTypeMismatchMessage,f as createPropertyNotFoundMessage,h as createMissingArgumentMessage,e as UnsupportedSchemaError,d as TemplateRuntimeError,b as TemplateParseError,a as TemplateError,c as TemplateAnalysisError};
1
+ import{J as a,K as b,L as c,M as d,N as e,O as f,P as g,Q as h,R as i,S as j}from"./chunk-gayk9ew1.js";export{i as createUnknownHelperMessage,j as createUnanalyzableMessage,g as createTypeMismatchMessage,f as createPropertyNotFoundMessage,h as createMissingArgumentMessage,e as UnsupportedSchemaError,d as TemplateRuntimeError,b as TemplateParseError,a as TemplateError,c as TemplateAnalysisError};
2
2
 
3
- //# debugId=5F99984E8843AC9E64756E2164756E21
3
+ //# debugId=0EEAB5333550372B64756E2164756E21
4
4
  //# sourceMappingURL=errors.js.map
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "5F99984E8843AC9E64756E2164756E21",
7
+ "debugId": "0EEAB5333550372B64756E2164756E21",
8
8
  "names": []
9
9
  }
package/dist/executor.js CHANGED
@@ -1,4 +1,4 @@
1
- import{f as a,g as b,h as c,i as d}from"./chunk-efqd0598.js";import"./chunk-6955jpr7.js";import"./chunk-rkrp4ysw.js";import"./chunk-p5efqsxw.js";import"./chunk-zh1e0yhd.js";export{c as resolveDataPath,b as executeFromAst,a as execute,d as clearCompilationCache};
1
+ import{e as a,f as b,g as c,h as d}from"./chunk-wvnn9g55.js";import"./chunk-8xza8tca.js";import"./chunk-s96k41p3.js";import"./chunk-9jxzj2h4.js";import"./chunk-gayk9ew1.js";export{c as resolveDataPath,b as executeFromAst,a as execute,d as clearCompilationCache};
2
2
 
3
- //# debugId=E439EBF232D2886264756E2164756E21
3
+ //# debugId=287C3A3F583887C664756E2164756E21
4
4
  //# sourceMappingURL=executor.js.map
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "E439EBF232D2886264756E2164756E21",
7
+ "debugId": "287C3A3F583887C664756E2164756E21",
8
8
  "names": []
9
9
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as r}from"./chunk-xd2vmd03.js";import"./chunk-ecs3yth2.js";import"./chunk-t6n956qz.js";import"./chunk-efqd0598.js";import{m as e}from"./chunk-6955jpr7.js";import"./chunk-rkrp4ysw.js";import"./chunk-jms1ndxn.js";import"./chunk-p5efqsxw.js";import{K as t,L as x,M as a,N as b,O as d,P as i,Q as l,R as n,S as s,T as y}from"./chunk-zh1e0yhd.js";export{e as defineHelper,s as createUnknownHelperMessage,y as createUnanalyzableMessage,l as createTypeMismatchMessage,i as createPropertyNotFoundMessage,n as createMissingArgumentMessage,d as UnsupportedSchemaError,r as Typebars,b as TemplateRuntimeError,x as TemplateParseError,t as TemplateError,a as TemplateAnalysisError};
1
+ import{J as t,K as x,L as a,M as b,N as d,O as i,P as l,Q as n,R as s,S as y}from"./chunk-gayk9ew1.js";export{m as defineHelper,s as createUnknownHelperMessage,y as createUnanalyzableMessage,l as createTypeMismatchMessage,i as createPropertyNotFoundMessage,n as createMissingArgumentMessage,d as UnsupportedSchemaError,p as Typebars,b as TemplateRuntimeError,x as TemplateParseError,t as TemplateError,a as TemplateAnalysisError};
2
2
 
3
- //# debugId=907E45F8A123358764756E2164756E21
3
+ //# debugId=E34726013A165F5B64756E2164756E21
4
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "907E45F8A123358764756E2164756E21",
7
+ "debugId": "E34726013A165F5B64756E2164756E21",
8
8
  "names": []
9
9
  }
package/dist/parser.js CHANGED
@@ -1,4 +1,4 @@
1
- import{n as a,o as b,p as c,q as d,r as e,s as f,t as g,u as h,v as i,w as j,x as k,y as l}from"./chunk-rkrp4ysw.js";import"./chunk-zh1e0yhd.js";export{k as parseIdentifier,a as parse,d as isThisExpression,b as isSingleExpression,g as getEffectivelySingleExpression,f as getEffectivelySingleBlock,e as getEffectiveBody,c as extractPathSegments,l as extractExpressionIdentifier,i as detectLiteralType,j as coerceLiteral,h as canUseFastPath};
1
+ import{m as a,n as b,o as c,p as d,q as e,r as f,s as g,t as h,u as i,v as j,w as k,x as l}from"./chunk-s96k41p3.js";import"./chunk-gayk9ew1.js";export{k as parseIdentifier,a as parse,d as isThisExpression,b as isSingleExpression,g as getEffectivelySingleExpression,f as getEffectivelySingleBlock,e as getEffectiveBody,c as extractPathSegments,l as extractExpressionIdentifier,i as detectLiteralType,j as coerceLiteral,h as canUseFastPath};
2
2
 
3
- //# debugId=238977E59328291964756E2164756E21
3
+ //# debugId=C867B0C49B4AE84764756E2164756E21
4
4
  //# sourceMappingURL=parser.js.map
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "238977E59328291964756E2164756E21",
7
+ "debugId": "C867B0C49B4AE84764756E2164756E21",
8
8
  "names": []
9
9
  }
@@ -1,4 +1,4 @@
1
- import{A as b,B as c,C as d,D as e,z as a}from"./chunk-jms1ndxn.js";import"./chunk-p5efqsxw.js";import"./chunk-zh1e0yhd.js";export{e as simplifySchema,c as resolveSchemaPath,b as resolveRef,d as resolveArrayItems,a as assertNoConditionalSchema};
1
+ import{A as c,B as d,C as e,y as a,z as b}from"./chunk-5znsrn10.js";import"./chunk-9jxzj2h4.js";import"./chunk-gayk9ew1.js";export{e as simplifySchema,c as resolveSchemaPath,b as resolveRef,d as resolveArrayItems,a as assertNoConditionalSchema};
2
2
 
3
- //# debugId=EA8E60A23E3E11CC64756E2164756E21
3
+ //# debugId=B3B51E4CF405F62E64756E2164756E21
4
4
  //# sourceMappingURL=schema-resolver.js.map
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "EA8E60A23E3E11CC64756E2164756E21",
7
+ "debugId": "B3B51E4CF405F62E64756E2164756E21",
8
8
  "names": []
9
9
  }
package/dist/typebars.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a}from"./chunk-xd2vmd03.js";import"./chunk-ecs3yth2.js";import"./chunk-t6n956qz.js";import"./chunk-efqd0598.js";import"./chunk-6955jpr7.js";import"./chunk-rkrp4ysw.js";import"./chunk-jms1ndxn.js";import"./chunk-p5efqsxw.js";import"./chunk-zh1e0yhd.js";export{a as Typebars};
1
+ import{a as C}from"./chunk-867xywnk.js";import{c as z}from"./chunk-dpffacsy.js";import{f as L}from"./chunk-wvnn9g55.js";import{i as Q,j as W,k as _}from"./chunk-8xza8tca.js";import{m as k}from"./chunk-s96k41p3.js";import"./chunk-5znsrn10.js";import{E as N,H as E,I}from"./chunk-9jxzj2h4.js";import{L as U}from"./chunk-gayk9ew1.js";import P from"handlebars";class Y{_definitions=null;_helperNames=null;_helperNamesSet=null;getDefinitions(){if(!this._definitions)this._definitions=new Map,this.buildDefinitions(this._definitions);return this._definitions}getHelperNames(){if(!this._helperNames)this._helperNames=[...this.getDefinitions().keys()];return this._helperNames}isHelper(w){if(!this._helperNamesSet)this._helperNamesSet=new Set(this.getHelperNames());return this._helperNamesSet.has(w)}register(w){for(let[M,H]of this.getDefinitions())w.registerHelper(M,H)}unregister(w){for(let M of this.getHelperNames())w.unregisterHelper(M)}}function B(w,M=NaN){if(typeof w==="number")return w;if(typeof w==="string"){let H=Number(w);return Number.isNaN(H)?M:H}if(typeof w==="boolean")return w?1:0;return M}var j=new Set(["==","===","!=","!==","<","<=",">",">="]);function T(w,M,H){switch(M){case"==":return w==H;case"===":return w===H;case"!=":return w!=H;case"!==":return w!==H;case"<":return B(w)<B(H);case"<=":return B(w)<=B(H);case">":return B(w)>B(H);case">=":return B(w)>=B(H)}}function A(w){return w!==null&&typeof w==="object"&&"hash"in w&&"name"in w}class Z extends Y{buildDefinitions(w){this.registerEquality(w),this.registerComparison(w),this.registerLogicalOperators(w),this.registerCollectionHelpers(w),this.registerGenericCompare(w)}registerEquality(w){w.set("eq",{fn:(H,V)=>H===V,params:[{name:"a",description:"Left value"},{name:"b",description:"Right value"}],returnType:{type:"boolean"},description:"Returns true if a is strictly equal to b: {{#if (eq a b)}}"});let M={fn:(H,V)=>H!==V,params:[{name:"a",description:"Left value"},{name:"b",description:"Right value"}],returnType:{type:"boolean"},description:"Returns true if a is not strictly equal to b: {{#if (ne a b)}}"};w.set("ne",M),w.set("neq",M)}registerComparison(w){w.set("lt",{fn:(V,q)=>B(V)<B(q),params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"boolean"},description:"Returns true if a < b: {{#if (lt a b)}}"});let M={fn:(V,q)=>B(V)<=B(q),params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"boolean"},description:"Returns true if a <= b: {{#if (lte a b)}}"};w.set("lte",M),w.set("le",M),w.set("gt",{fn:(V,q)=>B(V)>B(q),params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"boolean"},description:"Returns true if a > b: {{#if (gt a b)}}"});let H={fn:(V,q)=>B(V)>=B(q),params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"boolean"},description:"Returns true if a >= b: {{#if (gte a b)}}"};w.set("gte",H),w.set("ge",H)}registerLogicalOperators(w){w.set("not",{fn:(M)=>!M,params:[{name:"value",description:"Value to negate"}],returnType:{type:"boolean"},description:"Returns true if the value is falsy: {{#if (not active)}}"}),w.set("and",{fn:(M,H)=>!!M&&!!H,params:[{name:"a",description:"First condition"},{name:"b",description:"Second condition"}],returnType:{type:"boolean"},description:"Returns true if both values are truthy: {{#if (and a b)}}"}),w.set("or",{fn:(M,H)=>!!M||!!H,params:[{name:"a",description:"First condition"},{name:"b",description:"Second condition"}],returnType:{type:"boolean"},description:"Returns true if at least one value is truthy: {{#if (or a b)}}"})}registerCollectionHelpers(w){w.set("contains",{fn:(M,H)=>{if(typeof M==="string")return M.includes(String(H));if(Array.isArray(M))return M.includes(H);return!1},params:[{name:"haystack",description:"String or array to search in"},{name:"needle",description:"Value to search for"}],returnType:{type:"boolean"},description:'Checks if a string contains a substring or an array contains an element: {{#if (contains name "ali")}}'}),w.set("in",{fn:(...M)=>{if(M.length<2)return!1;let H=M[0];return M.slice(1).filter((q)=>!A(q)).some((q)=>q===H)},params:[{name:"value",description:"Value to look for"},{name:"candidates",description:'One or more candidate values (variadic): {{#if (in status "active" "pending")}}'}],returnType:{type:"boolean"},description:'Checks if a value is one of the provided options: {{#if (in status "active" "pending" "draft")}}'})}registerGenericCompare(w){w.set("compare",{fn:(M,H,V)=>{let q=String(H);if(!j.has(q))throw Error(`[compare helper] Unknown operator "${q}". Supported: ${[...j].join(", ")} `);return T(M,q,V)},params:[{name:"a",description:"Left operand"},{name:"operator",type:{type:"string",enum:["==","===","!=","!==","<","<=",">",">="]},description:'Comparison operator: "==", "===", "!=", "!==", "<", "<=", ">", ">="'},{name:"b",description:"Right operand"}],returnType:{type:"boolean"},description:'Generic comparison helper with operator as parameter: {{#if (compare a "<" b)}}. Supported operators: ==, ===, !=, !==, <, <=, >, >='})}}var F=new Set(["+","-","*","/","%","**"]),x=(w)=>B(w,0);function g(w,M,H){switch(M){case"+":return w+H;case"-":return w-H;case"*":return w*H;case"/":return H===0?1/0:w/H;case"%":return H===0?NaN:w%H;case"**":return w**H}}class $ extends Y{buildDefinitions(w){this.registerBinaryOperators(w),this.registerUnaryFunctions(w),this.registerMinMax(w),this.registerGenericMath(w)}registerBinaryOperators(w){let M={fn:(G,K)=>x(G)+x(K),params:[{name:"a",type:{type:"number"},description:"First operand"},{name:"b",type:{type:"number"},description:"Second operand"}],returnType:{type:"number"},description:"Adds two numbers: {{ add a b }}"};w.set("add",M);let H={fn:(G,K)=>x(G)-x(K),params:[{name:"a",type:{type:"number"},description:"Value to subtract from"},{name:"b",type:{type:"number"},description:"Value to subtract"}],returnType:{type:"number"},description:"Subtracts b from a: {{ subtract a b }}"};w.set("subtract",H),w.set("sub",H);let V={fn:(G,K)=>x(G)*x(K),params:[{name:"a",type:{type:"number"},description:"First factor"},{name:"b",type:{type:"number"},description:"Second factor"}],returnType:{type:"number"},description:"Multiplies two numbers: {{ multiply a b }}"};w.set("multiply",V),w.set("mul",V);let q={fn:(G,K)=>{let X=x(K);return X===0?1/0:x(G)/X},params:[{name:"a",type:{type:"number"},description:"Dividend"},{name:"b",type:{type:"number"},description:"Divisor"}],returnType:{type:"number"},description:"Divides a by b: {{ divide a b }}. Returns Infinity if b is 0."};w.set("divide",q),w.set("div",q);let J={fn:(G,K)=>{let X=x(K);return X===0?NaN:x(G)%X},params:[{name:"a",type:{type:"number"},description:"Dividend"},{name:"b",type:{type:"number"},description:"Divisor"}],returnType:{type:"number"},description:"Returns the remainder of a divided by b: {{ modulo a b }}"};w.set("modulo",J),w.set("mod",J),w.set("pow",{fn:(G,K)=>x(G)**x(K),params:[{name:"base",type:{type:"number"},description:"The base"},{name:"exponent",type:{type:"number"},description:"The exponent"}],returnType:{type:"number"},description:"Raises base to the power of exponent: {{ pow base exponent }}"})}registerUnaryFunctions(w){w.set("abs",{fn:(M)=>Math.abs(x(M)),params:[{name:"value",type:{type:"number"},description:"The number"}],returnType:{type:"number"},description:"Returns the absolute value: {{ abs value }}"}),w.set("ceil",{fn:(M)=>Math.ceil(x(M)),params:[{name:"value",type:{type:"number"},description:"The number to round up"}],returnType:{type:"number"},description:"Rounds up to the nearest integer: {{ ceil value }}"}),w.set("floor",{fn:(M)=>Math.floor(x(M)),params:[{name:"value",type:{type:"number"},description:"The number to round down"}],returnType:{type:"number"},description:"Rounds down to the nearest integer: {{ floor value }}"}),w.set("round",{fn:(M,H)=>{let V=x(M);if(H===void 0||H===null||typeof H==="object")return Math.round(V);let J=10**x(H);return Math.round(V*J)/J},params:[{name:"value",type:{type:"number"},description:"The number to round"},{name:"precision",type:{type:"number"},description:"Number of decimal places (default: 0)",optional:!0}],returnType:{type:"number"},description:"Rounds to the nearest integer or to a given precision: {{ round value }} or {{ round value 2 }}"}),w.set("sqrt",{fn:(M)=>Math.sqrt(x(M)),params:[{name:"value",type:{type:"number"},description:"The number"}],returnType:{type:"number"},description:"Returns the square root: {{ sqrt value }}"})}registerMinMax(w){w.set("min",{fn:(M,H)=>Math.min(x(M),x(H)),params:[{name:"a",type:{type:"number"},description:"First number"},{name:"b",type:{type:"number"},description:"Second number"}],returnType:{type:"number"},description:"Returns the smaller of two numbers: {{ min a b }}"}),w.set("max",{fn:(M,H)=>Math.max(x(M),x(H)),params:[{name:"a",type:{type:"number"},description:"First number"},{name:"b",type:{type:"number"},description:"Second number"}],returnType:{type:"number"},description:"Returns the larger of two numbers: {{ max a b }}"})}registerGenericMath(w){w.set("math",{fn:(M,H,V)=>{let q=String(H);if(!F.has(q))throw Error(`[math helper] Unknown operator "${q}". Supported: ${[...F].join(", ")} `);return g(x(M),q,x(V))},params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"operator",type:{type:"string",enum:["+","-","*","/","%","**"]},description:'Arithmetic operator: "+", "-", "*", "/", "%", "**"'},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"number"},description:'Generic math helper with operator as parameter: {{ math a "+" b }}, {{ math a "/" b }}. Supported operators: +, -, *, /, %, **'})}}class R{hbs;astCache;compilationCache;helpers=new Map;constructor(w={}){if(this.hbs=P.create(),this.astCache=new N(w.astCacheSize??256),this.compilationCache=new N(w.compilationCacheSize??256),new $().register(this),new Z().register(this),w.helpers)for(let M of w.helpers){let{name:H,...V}=M;this.registerHelper(H,V)}}compile(w){if(W(w)){let V={};for(let[q,J]of Object.entries(w))V[q]=this.compile(J);return C.fromObject(V,{helpers:this.helpers,hbs:this.hbs,compilationCache:this.compilationCache})}if(Q(w))return C.fromLiteral(w,{helpers:this.helpers,hbs:this.hbs,compilationCache:this.compilationCache});let M=this.getCachedAst(w),H={helpers:this.helpers,hbs:this.hbs,compilationCache:this.compilationCache};return C.fromTemplate(M,w,H)}analyze(w,M,H){if(W(w))return E(Object.keys(w),(q)=>this.analyze(w[q],M,H));if(Q(w))return{valid:!0,diagnostics:[],outputSchema:_(w)};let V=this.getCachedAst(w);return z(V,w,M,{identifierSchemas:H,helpers:this.helpers})}validate(w,M,H){let V=this.analyze(w,M,H);return{valid:V.valid,diagnostics:V.diagnostics}}isValidSyntax(w){if(W(w))return Object.values(w).every((M)=>this.isValidSyntax(M));if(Q(w))return!0;try{return this.getCachedAst(w),!0}catch{return!1}}execute(w,M,H){if(W(w)){let q={};for(let[J,G]of Object.entries(w))q[J]=this.execute(G,M,H);return q}if(Q(w))return w;let V=this.getCachedAst(w);if(H?.schema){let q=z(V,w,H.schema,{identifierSchemas:H.identifierSchemas,helpers:this.helpers});if(!q.valid)throw new U(q.diagnostics)}return L(V,w,M,{identifierData:H?.identifierData,hbs:this.hbs,compilationCache:this.compilationCache})}analyzeAndExecute(w,M,H,V){if(W(w))return I(Object.keys(w),(K)=>this.analyzeAndExecute(w[K],M,H,V));if(Q(w))return{analysis:{valid:!0,diagnostics:[],outputSchema:_(w)},value:w};let q=this.getCachedAst(w),J=z(q,w,M,{identifierSchemas:V?.identifierSchemas,helpers:this.helpers});if(!J.valid)return{analysis:J,value:void 0};let G=L(q,w,H,{identifierData:V?.identifierData,hbs:this.hbs,compilationCache:this.compilationCache});return{analysis:J,value:G}}registerHelper(w,M){return this.helpers.set(w,M),this.hbs.registerHelper(w,M.fn),this.compilationCache.clear(),this}unregisterHelper(w){return this.helpers.delete(w),this.hbs.unregisterHelper(w),this.compilationCache.clear(),this}hasHelper(w){return this.helpers.has(w)}clearCaches(){this.astCache.clear(),this.compilationCache.clear()}getCachedAst(w){let M=this.astCache.get(w);if(!M)M=k(w),this.astCache.set(w,M);return M}}export{R as Typebars};
2
2
 
3
- //# debugId=AADE9F1482151B2C64756E2164756E21
3
+ //# debugId=B6C693AB7E88031064756E2164756E21
4
4
  //# sourceMappingURL=typebars.js.map
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
3
+ "sources": ["../src/typebars.ts", "../src/helpers/helper-factory.ts", "../src/helpers/utils.ts", "../src/helpers/logical-helpers.ts", "../src/helpers/math-helpers.ts"],
4
4
  "sourcesContent": [
5
+ "import Handlebars from \"handlebars\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport { analyzeFromAst } from \"./analyzer.ts\";\nimport {\n\tCompiledTemplate,\n\ttype CompiledTemplateOptions,\n} from \"./compiled-template.ts\";\nimport { TemplateAnalysisError } from \"./errors.ts\";\nimport { executeFromAst } from \"./executor.ts\";\nimport { LogicalHelpers, MathHelpers } from \"./helpers/index.ts\";\nimport { parse } from \"./parser.ts\";\nimport type {\n\tAnalysisResult,\n\tAnalyzeAndExecuteOptions,\n\tExecuteOptions,\n\tHelperDefinition,\n\tTemplateEngineOptions,\n\tTemplateInput,\n\tValidationResult,\n} from \"./types.ts\";\nimport {\n\tinferPrimitiveSchema,\n\tisLiteralInput,\n\tisObjectInput,\n} from \"./types.ts\";\nimport {\n\taggregateObjectAnalysis,\n\taggregateObjectAnalysisAndExecution,\n\tLRUCache,\n} from \"./utils.ts\";\n\n// ─── Typebars ────────────────────────────────────────────────────────────────\n// Public entry point of the template engine. Orchestrates three phases:\n//\n// 1. **Parsing** — transforms the template string into an AST (via Handlebars)\n// 2. **Analysis** — static validation + return type inference\n// 3. **Execution** — renders the template with real data\n//\n// ─── Architecture v2 ─────────────────────────────────────────────────────────\n// - **LRU cache** for parsed ASTs and compiled Handlebars templates\n// - **Isolated Handlebars environment** per instance (custom helpers)\n// - **`compile()` pattern**: parse-once / execute-many\n// - **`validate()` method**: API shortcut without `outputSchema`\n// - **`registerHelper()`**: custom helpers with static typing\n// - **`ExecuteOptions`**: options object for `execute()`\n//\n// ─── Template Identifiers ────────────────────────────────────────────────────\n// The `{{key:N}}` syntax allows referencing variables from specific data\n// sources, identified by an integer N.\n//\n// - `identifierSchemas`: mapping `{ [id]: JSONSchema7 }` for static analysis\n// - `identifierData`: mapping `{ [id]: Record<string, unknown> }` for execution\n//\n// Usage:\n// engine.execute(\"{{meetingId:1}}\", data, { identifierData: { 1: node1Data } });\n// engine.analyze(\"{{meetingId:1}}\", schema, { 1: node1Schema });\n\n// ─── Main Class ──────────────────────────────────────────────────────────────\n\nexport class Typebars {\n\t/** Isolated Handlebars environment — each engine has its own helpers */\n\tprivate readonly hbs: typeof Handlebars;\n\n\t/** LRU cache of parsed ASTs (avoids re-parsing) */\n\tprivate readonly astCache: LRUCache<string, hbs.AST.Program>;\n\n\t/** LRU cache of compiled Handlebars templates (avoids recompilation) */\n\tprivate readonly compilationCache: LRUCache<\n\t\tstring,\n\t\tHandlebarsTemplateDelegate\n\t>;\n\n\t/** Custom helpers registered on this instance */\n\tprivate readonly helpers = new Map<string, HelperDefinition>();\n\n\tconstructor(options: TemplateEngineOptions = {}) {\n\t\tthis.hbs = Handlebars.create();\n\t\tthis.astCache = new LRUCache(options.astCacheSize ?? 256);\n\t\tthis.compilationCache = new LRUCache(options.compilationCacheSize ?? 256);\n\n\t\t// ── Built-in helpers ─────────────────────────────────────────────\n\t\tnew MathHelpers().register(this);\n\t\tnew LogicalHelpers().register(this);\n\n\t\t// ── Custom helpers via options ───────────────────────────────────\n\t\tif (options.helpers) {\n\t\t\tfor (const helper of options.helpers) {\n\t\t\t\tconst { name, ...definition } = helper;\n\t\t\t\tthis.registerHelper(name, definition);\n\t\t\t}\n\t\t}\n\t}\n\n\t// ─── Compilation ───────────────────────────────────────────────────────\n\n\t/**\n\t * Compiles a template and returns a `CompiledTemplate` ready to be\n\t * executed or analyzed without re-parsing.\n\t *\n\t * Accepts a `TemplateInput`: string, number, boolean, null, or object.\n\t * For objects, each property is compiled recursively.\n\t *\n\t * @param template - The template to compile\n\t * @returns A reusable `CompiledTemplate`\n\t */\n\tcompile(template: TemplateInput): CompiledTemplate {\n\t\tif (isObjectInput(template)) {\n\t\t\tconst children: Record<string, CompiledTemplate> = {};\n\t\t\tfor (const [key, value] of Object.entries(template)) {\n\t\t\t\tchildren[key] = this.compile(value);\n\t\t\t}\n\t\t\treturn CompiledTemplate.fromObject(children, {\n\t\t\t\thelpers: this.helpers,\n\t\t\t\thbs: this.hbs,\n\t\t\t\tcompilationCache: this.compilationCache,\n\t\t\t});\n\t\t}\n\t\tif (isLiteralInput(template)) {\n\t\t\treturn CompiledTemplate.fromLiteral(template, {\n\t\t\t\thelpers: this.helpers,\n\t\t\t\thbs: this.hbs,\n\t\t\t\tcompilationCache: this.compilationCache,\n\t\t\t});\n\t\t}\n\t\tconst ast = this.getCachedAst(template);\n\t\tconst options: CompiledTemplateOptions = {\n\t\t\thelpers: this.helpers,\n\t\t\thbs: this.hbs,\n\t\t\tcompilationCache: this.compilationCache,\n\t\t};\n\t\treturn CompiledTemplate.fromTemplate(ast, template, options);\n\t}\n\n\t// ─── Static Analysis ─────────────────────────────────────────────────────\n\n\t/**\n\t * Statically analyzes a template against a JSON Schema v7 describing\n\t * the available context.\n\t *\n\t * Accepts a `TemplateInput`: string, number, boolean, null, or object.\n\t * For objects, each property is analyzed recursively and the\n\t * `outputSchema` reflects the object structure with resolved types.\n\t *\n\t * @param template - The template to analyze\n\t * @param inputSchema - JSON Schema v7 describing the available variables\n\t * @param identifierSchemas - (optional) Schemas by identifier `{ [id]: JSONSchema7 }`\n\t */\n\tanalyze(\n\t\ttemplate: TemplateInput,\n\t\tinputSchema: JSONSchema7,\n\t\tidentifierSchemas?: Record<number, JSONSchema7>,\n\t): AnalysisResult {\n\t\tif (isObjectInput(template)) {\n\t\t\treturn aggregateObjectAnalysis(Object.keys(template), (key) =>\n\t\t\t\tthis.analyze(\n\t\t\t\t\ttemplate[key] as TemplateInput,\n\t\t\t\t\tinputSchema,\n\t\t\t\t\tidentifierSchemas,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tif (isLiteralInput(template)) {\n\t\t\treturn {\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}\n\t\tconst ast = this.getCachedAst(template);\n\t\treturn analyzeFromAst(ast, template, inputSchema, {\n\t\t\tidentifierSchemas,\n\t\t\thelpers: this.helpers,\n\t\t});\n\t}\n\n\t// ─── Validation ──────────────────────────────────────────────────────────\n\n\t/**\n\t * Validates a template against a schema without returning the output type.\n\t *\n\t * This is an API shortcut for `analyze()` that only returns `valid` and\n\t * `diagnostics`, without `outputSchema`. The full analysis (including type\n\t * inference) is executed internally — this method provides no performance\n\t * gain, only a simplified API.\n\t *\n\t * @param template - The template to validate\n\t * @param inputSchema - JSON Schema v7 describing the available variables\n\t * @param identifierSchemas - (optional) Schemas by identifier\n\t */\n\tvalidate(\n\t\ttemplate: TemplateInput,\n\t\tinputSchema: JSONSchema7,\n\t\tidentifierSchemas?: Record<number, JSONSchema7>,\n\t): ValidationResult {\n\t\tconst analysis = this.analyze(template, 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// ─── Syntax Validation ───────────────────────────────────────────────────\n\n\t/**\n\t * Checks only that the template syntax is valid (parsing).\n\t * Does not require a schema — useful for quick feedback in an editor.\n\t *\n\t * For objects, recursively checks each property.\n\t *\n\t * @param template - The template to validate\n\t * @returns `true` if the template is syntactically correct\n\t */\n\tisValidSyntax(template: TemplateInput): boolean {\n\t\tif (isObjectInput(template)) {\n\t\t\treturn Object.values(template).every((v) => this.isValidSyntax(v));\n\t\t}\n\t\tif (isLiteralInput(template)) return true;\n\t\ttry {\n\t\t\tthis.getCachedAst(template);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// ─── Execution ───────────────────────────────────────────────────────────\n\n\t/**\n\t * Executes a template with the provided data.\n\t *\n\t * Accepts a `TemplateInput`: string, number, boolean, null, or object.\n\t * For objects, each property is executed recursively and an object with\n\t * resolved values is returned.\n\t *\n\t * If a `schema` is provided in options, static analysis is performed\n\t * before execution. A `TemplateAnalysisError` is thrown on errors.\n\t *\n\t * @param template - The template to execute\n\t * @param data - The context data for rendering\n\t * @param options - Execution options (schema, identifierData, identifierSchemas)\n\t * @returns The execution result\n\t */\n\texecute(\n\t\ttemplate: TemplateInput,\n\t\tdata: Record<string, unknown>,\n\t\toptions?: ExecuteOptions,\n\t): unknown {\n\t\t// ── Object template → recursive execution ────────────────────────────\n\t\tif (isObjectInput(template)) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, value] of Object.entries(template)) {\n\t\t\t\tresult[key] = this.execute(value, data, options);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t// ── Passthrough for literal values ────────────────────────────────────\n\t\tif (isLiteralInput(template)) return template;\n\n\t\t// ── Parse once ───────────────────────────────────────────────────────\n\t\tconst ast = this.getCachedAst(template);\n\n\t\t// ── Pre-execution static validation ──────────────────────────────────\n\t\tif (options?.schema) {\n\t\t\tconst analysis = analyzeFromAst(ast, template, options.schema, {\n\t\t\t\tidentifierSchemas: options.identifierSchemas,\n\t\t\t\thelpers: this.helpers,\n\t\t\t});\n\t\t\tif (!analysis.valid) {\n\t\t\t\tthrow new TemplateAnalysisError(analysis.diagnostics);\n\t\t\t}\n\t\t}\n\n\t\t// ── Execution ────────────────────────────────────────────────────────\n\t\treturn executeFromAst(ast, template, data, {\n\t\t\tidentifierData: options?.identifierData,\n\t\t\thbs: this.hbs,\n\t\t\tcompilationCache: this.compilationCache,\n\t\t});\n\t}\n\n\t// ─── Combined Shortcuts ──────────────────────────────────────────────────\n\n\t/**\n\t * Analyzes a template and, if valid, executes it with the provided data.\n\t * Returns both the analysis result and the executed value.\n\t *\n\t * For objects, each property is analyzed and executed recursively.\n\t * The entire object is considered invalid if at least one property is.\n\t *\n\t * @param template - The template\n\t * @param inputSchema - JSON Schema v7 describing the available variables\n\t * @param data - The context data for rendering\n\t * @param options - (optional) Options for template identifiers\n\t * @returns An object `{ analysis, value }` where `value` is `undefined`\n\t * if analysis failed.\n\t */\n\tanalyzeAndExecute(\n\t\ttemplate: TemplateInput,\n\t\tinputSchema: JSONSchema7,\n\t\tdata: Record<string, unknown>,\n\t\toptions?: AnalyzeAndExecuteOptions,\n\t): { analysis: AnalysisResult; value: unknown } {\n\t\tif (isObjectInput(template)) {\n\t\t\treturn aggregateObjectAnalysisAndExecution(Object.keys(template), (key) =>\n\t\t\t\tthis.analyzeAndExecute(\n\t\t\t\t\ttemplate[key] as TemplateInput,\n\t\t\t\t\tinputSchema,\n\t\t\t\t\tdata,\n\t\t\t\t\toptions,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tif (isLiteralInput(template)) {\n\t\t\treturn {\n\t\t\t\tanalysis: {\n\t\t\t\t\tvalid: true,\n\t\t\t\t\tdiagnostics: [],\n\t\t\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t\t\t},\n\t\t\t\tvalue: template,\n\t\t\t};\n\t\t}\n\n\t\tconst ast = this.getCachedAst(template);\n\t\tconst analysis = analyzeFromAst(ast, template, inputSchema, {\n\t\t\tidentifierSchemas: options?.identifierSchemas,\n\t\t\thelpers: this.helpers,\n\t\t});\n\n\t\tif (!analysis.valid) {\n\t\t\treturn { analysis, value: undefined };\n\t\t}\n\n\t\tconst value = executeFromAst(ast, template, data, {\n\t\t\tidentifierData: options?.identifierData,\n\t\t\thbs: this.hbs,\n\t\t\tcompilationCache: this.compilationCache,\n\t\t});\n\t\treturn { analysis, value };\n\t}\n\n\t// ─── Custom Helper Management ──────────────────────────────────────────\n\n\t/**\n\t * Registers a custom helper on this engine instance.\n\t *\n\t * The helper is available for both execution (via Handlebars) and\n\t * static analysis (via its declared `returnType`).\n\t *\n\t * @param name - Helper name (e.g. `\"uppercase\"`)\n\t * @param definition - Helper definition (implementation + return type)\n\t * @returns `this` to allow chaining\n\t */\n\tregisterHelper(name: string, definition: HelperDefinition): this {\n\t\tthis.helpers.set(name, definition);\n\t\tthis.hbs.registerHelper(name, definition.fn);\n\n\t\t// Invalidate the compilation cache because helpers have changed\n\t\tthis.compilationCache.clear();\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes a custom helper from this engine instance.\n\t *\n\t * @param name - Name of the helper to remove\n\t * @returns `this` to allow chaining\n\t */\n\tunregisterHelper(name: string): this {\n\t\tthis.helpers.delete(name);\n\t\tthis.hbs.unregisterHelper(name);\n\n\t\t// Invalidate the compilation cache\n\t\tthis.compilationCache.clear();\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Checks whether a helper is registered on this instance.\n\t *\n\t * @param name - Helper name\n\t * @returns `true` if the helper is registered\n\t */\n\thasHelper(name: string): boolean {\n\t\treturn this.helpers.has(name);\n\t}\n\n\t// ─── Cache Management ──────────────────────────────────────────────────\n\n\t/**\n\t * Clears all internal caches (AST + compilation).\n\t *\n\t * Useful after a configuration change or to free memory.\n\t */\n\tclearCaches(): void {\n\t\tthis.astCache.clear();\n\t\tthis.compilationCache.clear();\n\t}\n\n\t// ─── Internals ─────────────────────────────────────────────────────────\n\n\t/**\n\t * Retrieves the AST of a template from the cache, or parses and caches it.\n\t */\n\tprivate getCachedAst(template: string): hbs.AST.Program {\n\t\tlet ast = this.astCache.get(template);\n\t\tif (!ast) {\n\t\t\tast = parse(template);\n\t\t\tthis.astCache.set(template, ast);\n\t\t}\n\t\treturn ast;\n\t}\n}\n",
6
+ "import type { HelperDefinition } from \"../types.ts\";\n\n// ─── HelperFactory ───────────────────────────────────────────────────────────\n// Abstract base class that enforces a consistent pattern for creating,\n// registering, and managing groups of related helpers.\n//\n// Every helper factory (MathHelpers, LogicalHelpers, …) must extend this class\n// and implement the `buildDefinitions()` method to populate its helpers.\n//\n// The base class provides:\n// - Lazy-cached definitions, helper names, and name set\n// - `register()` / `unregister()` for any `HelperRegistry`\n// - `getHelperNames()` / `isHelper()` for introspection\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Minimal registration interface — avoids tight coupling with Typebars */\nexport interface HelperRegistry {\n\tregisterHelper(name: string, definition: HelperDefinition): unknown;\n\tunregisterHelper(name: string): unknown;\n}\n\n// ─── Abstract Base Class ─────────────────────────────────────────────────────\n\nexport abstract class HelperFactory {\n\t// ── Lazy caches (populated on first access) ──────────────────────────\n\tprivate _definitions: Map<string, HelperDefinition> | null = null;\n\tprivate _helperNames: readonly string[] | null = null;\n\tprivate _helperNamesSet: ReadonlySet<string> | null = null;\n\n\t// ── Abstract method — must be implemented by each factory ────────────\n\n\t/**\n\t * Populates the `defs` map with all helper definitions.\n\t *\n\t * Subclasses implement this method to register their helpers:\n\t * ```\n\t * protected buildDefinitions(defs: Map<string, HelperDefinition>): void {\n\t * defs.set(\"myHelper\", {\n\t * fn: (a: unknown) => String(a).toUpperCase(),\n\t * params: [{ name: \"a\", type: { type: \"string\" } }],\n\t * returnType: { type: \"string\" },\n\t * description: \"Converts to uppercase\",\n\t * });\n\t * }\n\t * ```\n\t *\n\t * @param defs - The map to populate with `[name, HelperDefinition]` entries\n\t */\n\tprotected abstract buildDefinitions(\n\t\tdefs: Map<string, HelperDefinition>,\n\t): void;\n\n\t// ── Public API ───────────────────────────────────────────────────────\n\n\t/**\n\t * Returns all definitions as a `Map<name, HelperDefinition>`.\n\t * The map is lazily built and cached on first access.\n\t */\n\tgetDefinitions(): Map<string, HelperDefinition> {\n\t\tif (!this._definitions) {\n\t\t\tthis._definitions = new Map();\n\t\t\tthis.buildDefinitions(this._definitions);\n\t\t}\n\t\treturn this._definitions;\n\t}\n\n\t/**\n\t * Returns the list of all helper names provided by this factory.\n\t */\n\tgetHelperNames(): readonly string[] {\n\t\tif (!this._helperNames) {\n\t\t\tthis._helperNames = [...this.getDefinitions().keys()];\n\t\t}\n\t\treturn this._helperNames;\n\t}\n\n\t/**\n\t * Checks whether a helper name belongs to this factory.\n\t *\n\t * @param name - The helper name to check\n\t */\n\tisHelper(name: string): boolean {\n\t\tif (!this._helperNamesSet) {\n\t\t\tthis._helperNamesSet = new Set(this.getHelperNames());\n\t\t}\n\t\treturn this._helperNamesSet.has(name);\n\t}\n\n\t/**\n\t * Registers all helpers from this factory on the given registry.\n\t *\n\t * @param registry - The engine or target registry\n\t */\n\tregister(registry: HelperRegistry): void {\n\t\tfor (const [name, def] of this.getDefinitions()) {\n\t\t\tregistry.registerHelper(name, def);\n\t\t}\n\t}\n\n\t/**\n\t * Removes all helpers from this factory from the given registry.\n\t *\n\t * @param registry - The engine or target registry\n\t */\n\tunregister(registry: HelperRegistry): void {\n\t\tfor (const name of this.getHelperNames()) {\n\t\t\tregistry.unregisterHelper(name);\n\t\t}\n\t}\n}\n",
7
+ "// ─── Shared Helper Utilities ─────────────────────────────────────────────────\n// Common utilities used across helper packs (MathHelpers, LogicalHelpers, …).\n\n/**\n * Converts an unknown value to a number.\n *\n * Conversion rules:\n * - `number` → returned as-is\n * - `string` → parsed via `Number()`; returns `fallback` if result is `NaN`\n * - `boolean` → `true` → `1`, `false` → `0`\n * - anything else → `fallback`\n *\n * The `fallback` parameter lets each consumer choose the right semantics:\n * - **Math helpers** pass `0` so that invalid inputs silently become zero\n * (e.g. `add(\"abc\", 5)` → `5`).\n * - **Logical helpers** pass `NaN` (the default) so that invalid comparisons\n * evaluate to `false` (e.g. `lt(\"abc\", 5)` → `false`).\n *\n * @param value - The value to convert\n * @param fallback - Value returned when conversion fails (default: `NaN`)\n */\nexport function toNumber(value: unknown, fallback: number = NaN): number {\n\tif (typeof value === \"number\") return value;\n\tif (typeof value === \"string\") {\n\t\tconst n = Number(value);\n\t\treturn Number.isNaN(n) ? fallback : n;\n\t}\n\tif (typeof value === \"boolean\") return value ? 1 : 0;\n\treturn fallback;\n}\n",
8
+ "import type { HelperDefinition } from \"../types.ts\";\nimport { HelperFactory } from \"./helper-factory.ts\";\nimport { toNumber } from \"./utils.ts\";\n\n// ─── LogicalHelpers ──────────────────────────────────────────────────────────\n// Aggregates all logical / comparison helpers for the template engine.\n//\n// Provides two kinds of helpers:\n//\n// 1. **Named helpers** — one helper per operation (`eq`, `lt`, `not`, …)\n// Usage: `{{#if (eq status \"active\")}}`, `{{#if (lt price 100)}}`\n//\n// 2. **Generic `compare` helper** — single helper with the operator as a param\n// Usage: `{{#if (compare a \"<\" b)}}`, `{{#if (compare name \"==\" \"Alice\")}}`\n//\n// ─── Registration ────────────────────────────────────────────────────────────\n// LogicalHelpers are automatically pre-registered by the `Typebars` constructor.\n// They can also be registered manually on any object implementing\n// `HelperRegistry`:\n//\n// const factory = new LogicalHelpers();\n// factory.register(engine); // registers all helpers\n// factory.unregister(engine); // removes all helpers\n//\n// ─── Supported operators (generic `compare` helper) ──────────────────────────\n// == Loose equality\n// === Strict equality\n// != Loose inequality\n// !== Strict inequality\n// < Less than\n// <= Less than or equal\n// > Greater than\n// >= Greater than or equal\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Operators supported by the generic `compare` helper */\ntype CompareOperator = \"==\" | \"===\" | \"!=\" | \"!==\" | \"<\" | \"<=\" | \">\" | \">=\";\n\nconst SUPPORTED_OPERATORS = new Set<string>([\n\t\"==\",\n\t\"===\",\n\t\"!=\",\n\t\"!==\",\n\t\"<\",\n\t\"<=\",\n\t\">\",\n\t\">=\",\n]);\n\n// ─── Internal utilities ─────────────────────────────────────────────────────\n\n/**\n * Applies a comparison operator to two operands.\n */\nfunction applyOperator(a: unknown, op: CompareOperator, b: unknown): boolean {\n\tswitch (op) {\n\t\tcase \"==\":\n\t\t\t// biome-ignore lint/suspicious/noDoubleEquals: intentional loose equality\n\t\t\treturn a == b;\n\t\tcase \"===\":\n\t\t\treturn a === b;\n\t\tcase \"!=\":\n\t\t\t// biome-ignore lint/suspicious/noDoubleEquals: intentional loose inequality\n\t\t\treturn a != b;\n\t\tcase \"!==\":\n\t\t\treturn a !== b;\n\t\tcase \"<\":\n\t\t\treturn toNumber(a) < toNumber(b);\n\t\tcase \"<=\":\n\t\t\treturn toNumber(a) <= toNumber(b);\n\t\tcase \">\":\n\t\t\treturn toNumber(a) > toNumber(b);\n\t\tcase \">=\":\n\t\t\treturn toNumber(a) >= toNumber(b);\n\t}\n}\n\n/**\n * Checks whether a value is a Handlebars options object.\n * Handlebars always passes an options object as the last argument to helpers.\n */\nfunction isHandlebarsOptions(value: unknown): boolean {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === \"object\" &&\n\t\t\"hash\" in (value as Record<string, unknown>) &&\n\t\t\"name\" in (value as Record<string, unknown>)\n\t);\n}\n\n// ─── Main class ─────────────────────────────────────────────────────────────\n\nexport class LogicalHelpers extends HelperFactory {\n\t// ─── buildDefinitions (required by HelperFactory) ──────────────────\n\n\tprotected buildDefinitions(defs: Map<string, HelperDefinition>): void {\n\t\tthis.registerEquality(defs);\n\t\tthis.registerComparison(defs);\n\t\tthis.registerLogicalOperators(defs);\n\t\tthis.registerCollectionHelpers(defs);\n\t\tthis.registerGenericCompare(defs);\n\t}\n\n\t// ── Equality helpers ─────────────────────────────────────────────\n\n\t/** Registers eq, ne / neq */\n\tprivate registerEquality(defs: Map<string, HelperDefinition>): void {\n\t\t// eq — Strict equality: {{#if (eq a b)}}\n\t\tdefs.set(\"eq\", {\n\t\t\tfn: (a: unknown, b: unknown) => a === b,\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", description: \"Left value\" },\n\t\t\t\t{ name: \"b\", description: \"Right value\" },\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription: \"Returns true if a is strictly equal to b: {{#if (eq a b)}}\",\n\t\t});\n\n\t\t// ne / neq — Strict inequality: {{#if (ne a b)}}\n\t\tconst neDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => a !== b,\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", description: \"Left value\" },\n\t\t\t\t{ name: \"b\", description: \"Right value\" },\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription:\n\t\t\t\t\"Returns true if a is not strictly equal to b: {{#if (ne a b)}}\",\n\t\t};\n\t\tdefs.set(\"ne\", neDef);\n\t\tdefs.set(\"neq\", neDef);\n\t}\n\n\t// ── Comparison helpers ───────────────────────────────────────────\n\n\t/** Registers lt, lte / le, gt, gte / ge */\n\tprivate registerComparison(defs: Map<string, HelperDefinition>): void {\n\t\t// lt — Less than: {{#if (lt a b)}}\n\t\tdefs.set(\"lt\", {\n\t\t\tfn: (a: unknown, b: unknown) => toNumber(a) < toNumber(b),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"Left operand\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Right operand\" },\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription: \"Returns true if a < b: {{#if (lt a b)}}\",\n\t\t});\n\n\t\t// lte / le — Less than or equal: {{#if (lte a b)}}\n\t\tconst lteDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => toNumber(a) <= toNumber(b),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"Left operand\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Right operand\" },\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription: \"Returns true if a <= b: {{#if (lte a b)}}\",\n\t\t};\n\t\tdefs.set(\"lte\", lteDef);\n\t\tdefs.set(\"le\", lteDef);\n\n\t\t// gt — Greater than: {{#if (gt a b)}}\n\t\tdefs.set(\"gt\", {\n\t\t\tfn: (a: unknown, b: unknown) => toNumber(a) > toNumber(b),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"Left operand\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Right operand\" },\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription: \"Returns true if a > b: {{#if (gt a b)}}\",\n\t\t});\n\n\t\t// gte / ge — Greater than or equal: {{#if (gte a b)}}\n\t\tconst gteDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => toNumber(a) >= toNumber(b),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"Left operand\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Right operand\" },\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription: \"Returns true if a >= b: {{#if (gte a b)}}\",\n\t\t};\n\t\tdefs.set(\"gte\", gteDef);\n\t\tdefs.set(\"ge\", gteDef);\n\t}\n\n\t// ── Logical operators ────────────────────────────────────────────\n\n\t/** Registers not, and, or */\n\tprivate registerLogicalOperators(defs: Map<string, HelperDefinition>): void {\n\t\t// not — Logical negation: {{#if (not active)}}\n\t\tdefs.set(\"not\", {\n\t\t\tfn: (value: unknown) => !value,\n\t\t\tparams: [{ name: \"value\", description: \"Value to negate\" }],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription: \"Returns true if the value is falsy: {{#if (not active)}}\",\n\t\t});\n\n\t\t// and — Logical AND: {{#if (and a b)}}\n\t\tdefs.set(\"and\", {\n\t\t\tfn: (a: unknown, b: unknown) => !!a && !!b,\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", description: \"First condition\" },\n\t\t\t\t{ name: \"b\", description: \"Second condition\" },\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription: \"Returns true if both values are truthy: {{#if (and a b)}}\",\n\t\t});\n\n\t\t// or — Logical OR: {{#if (or a b)}}\n\t\tdefs.set(\"or\", {\n\t\t\tfn: (a: unknown, b: unknown) => !!a || !!b,\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", description: \"First condition\" },\n\t\t\t\t{ name: \"b\", description: \"Second condition\" },\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription:\n\t\t\t\t\"Returns true if at least one value is truthy: {{#if (or a b)}}\",\n\t\t});\n\t}\n\n\t// ── Collection / String helpers ──────────────────────────────────\n\n\t/** Registers contains, in */\n\tprivate registerCollectionHelpers(defs: Map<string, HelperDefinition>): void {\n\t\t// contains — Checks if a string contains a substring or an array contains an element\n\t\t// Usage: {{#if (contains name \"ali\")}} or {{#if (contains tags \"admin\")}}\n\t\tdefs.set(\"contains\", {\n\t\t\tfn: (haystack: unknown, needle: unknown) => {\n\t\t\t\tif (typeof haystack === \"string\") {\n\t\t\t\t\treturn haystack.includes(String(needle));\n\t\t\t\t}\n\t\t\t\tif (Array.isArray(haystack)) {\n\t\t\t\t\treturn haystack.includes(needle);\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"haystack\",\n\t\t\t\t\tdescription: \"String or array to search in\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"needle\",\n\t\t\t\t\tdescription: \"Value to search for\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription:\n\t\t\t\t'Checks if a string contains a substring or an array contains an element: {{#if (contains name \"ali\")}}',\n\t\t});\n\n\t\t// in — Checks if a value is one of the provided options (variadic)\n\t\t// Usage: {{#if (in status \"active\" \"pending\" \"draft\")}}\n\t\tdefs.set(\"in\", {\n\t\t\tfn: (...args: unknown[]) => {\n\t\t\t\t// Handlebars always passes an options object as the last argument.\n\t\t\t\t// We need to exclude it from the candidate list.\n\t\t\t\tif (args.length < 2) return false;\n\n\t\t\t\tconst value = args[0];\n\t\t\t\t// Filter out the trailing Handlebars options object\n\t\t\t\tconst candidates = args.slice(1).filter((a) => !isHandlebarsOptions(a));\n\n\t\t\t\treturn candidates.some((c) => c === value);\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"value\",\n\t\t\t\t\tdescription: \"Value to look for\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"candidates\",\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'One or more candidate values (variadic): {{#if (in status \"active\" \"pending\")}}',\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription:\n\t\t\t\t'Checks if a value is one of the provided options: {{#if (in status \"active\" \"pending\" \"draft\")}}',\n\t\t});\n\t}\n\n\t// ── Generic helper ───────────────────────────────────────────────\n\n\t/** Registers the generic `compare` helper with operator as a parameter */\n\tprivate registerGenericCompare(defs: Map<string, HelperDefinition>): void {\n\t\t// Usage: {{#if (compare a \"<\" b)}}, {{#if (compare name \"===\" \"Alice\")}}\n\t\tdefs.set(\"compare\", {\n\t\t\tfn: (a: unknown, operator: unknown, b: unknown) => {\n\t\t\t\tconst op = String(operator);\n\t\t\t\tif (!SUPPORTED_OPERATORS.has(op)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`[compare helper] Unknown operator \"${op}\". ` +\n\t\t\t\t\t\t\t`Supported: ${[...SUPPORTED_OPERATORS].join(\", \")} `,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn applyOperator(a, op as CompareOperator, b);\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", description: \"Left operand\" },\n\t\t\t\t{\n\t\t\t\t\tname: \"operator\",\n\t\t\t\t\ttype: {\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\tenum: [\"==\", \"===\", \"!=\", \"!==\", \"<\", \"<=\", \">\", \">=\"],\n\t\t\t\t\t},\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Comparison operator: \"==\", \"===\", \"!=\", \"!==\", \"<\", \"<=\", \">\", \">=\"',\n\t\t\t\t},\n\t\t\t\t{ name: \"b\", description: \"Right operand\" },\n\t\t\t],\n\t\t\treturnType: { type: \"boolean\" },\n\t\t\tdescription:\n\t\t\t\t'Generic comparison helper with operator as parameter: {{#if (compare a \"<\" b)}}. ' +\n\t\t\t\t\"Supported operators: ==, ===, !=, !==, <, <=, >, >=\",\n\t\t});\n\t}\n}\n",
9
+ "import type { HelperDefinition } from \"../types.ts\";\nimport { HelperFactory } from \"./helper-factory.ts\";\nimport { toNumber } from \"./utils.ts\";\n\n// ─── MathHelpers ─────────────────────────────────────────────────────────────\n// Aggregates all math-related helpers for the template engine.\n//\n// Provides two kinds of helpers:\n//\n// 1. **Named helpers** — one helper per operation (`add`, `subtract`, `divide`, …)\n// Usage: `{{ add a b }}`, `{{ abs value }}`, `{{ round value 2 }}`\n//\n// 2. **Generic `math` helper** — single helper with the operator as a parameter\n// Usage: `{{ math a \"+\" b }}`, `{{ math a \"/\" b }}`, `{{ math a \"**\" b }}`\n//\n// ─── Registration ────────────────────────────────────────────────────────────\n// MathHelpers are automatically pre-registered by the `Typebars` constructor.\n// They can also be registered manually on any object implementing\n// `HelperRegistry`:\n//\n// const factory = new MathHelpers();\n// factory.register(engine); // registers all helpers\n// factory.unregister(engine); // removes all helpers\n//\n// ─── Supported operators (generic `math` helper) ─────────────────────────────\n// + Addition\n// - Subtraction\n// * Multiplication\n// / Division\n// % Modulo\n// ** Exponentiation\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Operators supported by the generic `math` helper */\ntype MathOperator = \"+\" | \"-\" | \"*\" | \"/\" | \"%\" | \"**\";\n\nconst SUPPORTED_OPERATORS = new Set<string>([\"+\", \"-\", \"*\", \"/\", \"%\", \"**\"]);\n\n// ─── Internal utilities ─────────────────────────────────────────────────────\n\n/** Converts a value to a number with a fallback of `0` for math operations. */\nconst num = (value: unknown): number => toNumber(value, 0);\n\n/**\n * Applies a binary operator to two operands.\n */\nfunction applyOperator(a: number, op: MathOperator, b: number): number {\n\tswitch (op) {\n\t\tcase \"+\":\n\t\t\treturn a + b;\n\t\tcase \"-\":\n\t\t\treturn a - b;\n\t\tcase \"*\":\n\t\t\treturn a * b;\n\t\tcase \"/\":\n\t\t\treturn b === 0 ? Infinity : a / b;\n\t\tcase \"%\":\n\t\t\treturn b === 0 ? NaN : a % b;\n\t\tcase \"**\":\n\t\t\treturn a ** b;\n\t}\n}\n\n// ─── Main class ─────────────────────────────────────────────────────────────\n\nexport class MathHelpers extends HelperFactory {\n\t// ─── buildDefinitions (required by HelperFactory) ──────────────────\n\n\tprotected buildDefinitions(defs: Map<string, HelperDefinition>): void {\n\t\tthis.registerBinaryOperators(defs);\n\t\tthis.registerUnaryFunctions(defs);\n\t\tthis.registerMinMax(defs);\n\t\tthis.registerGenericMath(defs);\n\t}\n\n\t// ── Binary operators ─────────────────────────────────────────────\n\n\t/** Registers add, subtract/sub, multiply/mul, divide/div, modulo/mod, pow */\n\tprivate registerBinaryOperators(defs: Map<string, HelperDefinition>): void {\n\t\t// add — Addition : {{ add a b }}\n\t\tconst addDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => num(a) + num(b),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"First operand\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Second operand\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Adds two numbers: {{ add a b }}\",\n\t\t};\n\t\tdefs.set(\"add\", addDef);\n\n\t\t// subtract / sub — Subtraction: {{ subtract a b }} or {{ sub a b }}\n\t\tconst subtractDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => num(a) - num(b),\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"a\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"Value to subtract from\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"b\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"Value to subtract\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Subtracts b from a: {{ subtract a b }}\",\n\t\t};\n\t\tdefs.set(\"subtract\", subtractDef);\n\t\tdefs.set(\"sub\", subtractDef);\n\n\t\t// multiply / mul — Multiplication: {{ multiply a b }} or {{ mul a b }}\n\t\tconst multiplyDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => num(a) * num(b),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"First factor\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Second factor\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Multiplies two numbers: {{ multiply a b }}\",\n\t\t};\n\t\tdefs.set(\"multiply\", multiplyDef);\n\t\tdefs.set(\"mul\", multiplyDef);\n\n\t\t// divide / div — Division: {{ divide a b }} or {{ div a b }}\n\t\tconst divideDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => {\n\t\t\t\tconst divisor = num(b);\n\t\t\t\treturn divisor === 0 ? Infinity : num(a) / divisor;\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"Dividend\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Divisor\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription:\n\t\t\t\t\"Divides a by b: {{ divide a b }}. Returns Infinity if b is 0.\",\n\t\t};\n\t\tdefs.set(\"divide\", divideDef);\n\t\tdefs.set(\"div\", divideDef);\n\n\t\t// modulo / mod — Modulo: {{ modulo a b }} or {{ mod a b }}\n\t\tconst moduloDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => {\n\t\t\t\tconst divisor = num(b);\n\t\t\t\treturn divisor === 0 ? NaN : num(a) % divisor;\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"Dividend\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Divisor\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Returns the remainder of a divided by b: {{ modulo a b }}\",\n\t\t};\n\t\tdefs.set(\"modulo\", moduloDef);\n\t\tdefs.set(\"mod\", moduloDef);\n\n\t\t// pow — Exponentiation : {{ pow base exponent }}\n\t\tdefs.set(\"pow\", {\n\t\t\tfn: (base: unknown, exponent: unknown) => num(base) ** num(exponent),\n\t\t\tparams: [\n\t\t\t\t{ name: \"base\", type: { type: \"number\" }, description: \"The base\" },\n\t\t\t\t{\n\t\t\t\t\tname: \"exponent\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"The exponent\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription:\n\t\t\t\t\"Raises base to the power of exponent: {{ pow base exponent }}\",\n\t\t});\n\t}\n\n\t// ── Unary functions ──────────────────────────────────────────────\n\n\t/** Registers abs, ceil, floor, round, sqrt */\n\tprivate registerUnaryFunctions(defs: Map<string, HelperDefinition>): void {\n\t\t// abs — Absolute value: {{ abs value }}\n\t\tdefs.set(\"abs\", {\n\t\t\tfn: (value: unknown) => Math.abs(num(value)),\n\t\t\tparams: [\n\t\t\t\t{ name: \"value\", type: { type: \"number\" }, description: \"The number\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Returns the absolute value: {{ abs value }}\",\n\t\t});\n\n\t\t// ceil — Round up: {{ ceil value }}\n\t\tdefs.set(\"ceil\", {\n\t\t\tfn: (value: unknown) => Math.ceil(num(value)),\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"value\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"The number to round up\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Rounds up to the nearest integer: {{ ceil value }}\",\n\t\t});\n\n\t\t// floor — Round down: {{ floor value }}\n\t\tdefs.set(\"floor\", {\n\t\t\tfn: (value: unknown) => Math.floor(num(value)),\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"value\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"The number to round down\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Rounds down to the nearest integer: {{ floor value }}\",\n\t\t});\n\n\t\t// round — Rounding: {{ round value }} or {{ round value precision }}\n\t\t// With precision: {{ round 3.14159 2 }} → 3.14\n\t\tdefs.set(\"round\", {\n\t\t\tfn: (value: unknown, precision: unknown) => {\n\t\t\t\tconst n = num(value);\n\t\t\t\t// If precision is a Handlebars options object (not a number),\n\t\t\t\t// it means the second parameter was not provided.\n\t\t\t\tif (\n\t\t\t\t\tprecision === undefined ||\n\t\t\t\t\tprecision === null ||\n\t\t\t\t\ttypeof precision === \"object\"\n\t\t\t\t) {\n\t\t\t\t\treturn Math.round(n);\n\t\t\t\t}\n\t\t\t\tconst p = num(precision);\n\t\t\t\tconst factor = 10 ** p;\n\t\t\t\treturn Math.round(n * factor) / factor;\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"value\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"The number to round\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"precision\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"Number of decimal places (default: 0)\",\n\t\t\t\t\toptional: true,\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription:\n\t\t\t\t\"Rounds to the nearest integer or to a given precision: {{ round value }} or {{ round value 2 }}\",\n\t\t});\n\n\t\t// sqrt — Square root: {{ sqrt value }}\n\t\tdefs.set(\"sqrt\", {\n\t\t\tfn: (value: unknown) => Math.sqrt(num(value)),\n\t\t\tparams: [\n\t\t\t\t{ name: \"value\", type: { type: \"number\" }, description: \"The number\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Returns the square root: {{ sqrt value }}\",\n\t\t});\n\t}\n\n\t// ── Min / Max ────────────────────────────────────────────────────\n\n\t/** Registers min and max */\n\tprivate registerMinMax(defs: Map<string, HelperDefinition>): void {\n\t\t// min — Minimum : {{ min a b }}\n\t\tdefs.set(\"min\", {\n\t\t\tfn: (a: unknown, b: unknown) => Math.min(num(a), num(b)),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"First number\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Second number\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Returns the smaller of two numbers: {{ min a b }}\",\n\t\t});\n\n\t\t// max — Maximum : {{ max a b }}\n\t\tdefs.set(\"max\", {\n\t\t\tfn: (a: unknown, b: unknown) => Math.max(num(a), num(b)),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"First number\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Second number\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Returns the larger of two numbers: {{ max a b }}\",\n\t\t});\n\t}\n\n\t// ── Generic helper ───────────────────────────────────────────────\n\n\t/** Registers the generic `math` helper with operator as a parameter */\n\tprivate registerGenericMath(defs: Map<string, HelperDefinition>): void {\n\t\t// Usage : {{ math a \"+\" b }}, {{ math a \"/\" b }}, {{ math a \"**\" b }}\n\t\tdefs.set(\"math\", {\n\t\t\tfn: (a: unknown, operator: unknown, b: unknown) => {\n\t\t\t\tconst op = String(operator);\n\t\t\t\tif (!SUPPORTED_OPERATORS.has(op)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`[math helper] Unknown operator \"${op}\". ` +\n\t\t\t\t\t\t\t`Supported: ${[...SUPPORTED_OPERATORS].join(\", \")} `,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn applyOperator(num(a), op as MathOperator, num(b));\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"Left operand\" },\n\t\t\t\t{\n\t\t\t\t\tname: \"operator\",\n\t\t\t\t\ttype: { type: \"string\", enum: [\"+\", \"-\", \"*\", \"/\", \"%\", \"**\"] },\n\t\t\t\t\tdescription: 'Arithmetic operator: \"+\", \"-\", \"*\", \"/\", \"%\", \"**\"',\n\t\t\t\t},\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Right operand\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription:\n\t\t\t\t'Generic math helper with operator as parameter: {{ math a \"+\" b }}, {{ math a \"/\" b }}. ' +\n\t\t\t\t\"Supported operators: +, -, *, /, %, **\",\n\t\t});\n\t}\n}\n"
5
10
  ],
6
- "mappings": "",
7
- "debugId": "AADE9F1482151B2C64756E2164756E21",
11
+ "mappings": "qXAAA,oBCwBO,AAAe,LAAc,LAE3B,OAAqD,DACrD,OAAyC,KACzC,gBAA8C,KA+BtD,cAAc,EAAkC,CAC/C,GAAI,CAAC,KAAK,aACT,KAAK,aAAe,IAAI,IACxB,KAAK,iBAAiB,KAAK,YAAY,EAExC,OAAO,KAAK,aAMb,cAAc,EAAsB,CACnC,GAAI,CAAC,KAAK,aACT,KAAK,aAAe,CAAC,GAAG,KAAK,eAAe,EAAE,KAAK,CAAC,EAErD,OAAO,KAAK,aAQb,QAAQ,CAAC,EAAuB,CAC/B,GAAI,CAAC,KAAK,gBACT,KAAK,gBAAkB,IAAI,IAAI,KAAK,eAAe,CAAC,EAErD,OAAO,KAAK,gBAAgB,IAAI,CAAI,EAQrC,QAAQ,CAAC,EAAgC,CACxC,QAAY,EAAM,KAAQ,KAAK,eAAe,EAC7C,EAAS,eAAe,EAAM,CAAG,EASnC,UAAU,CAAC,EAAgC,CAC1C,QAAW,KAAQ,KAAK,eAAe,EACtC,EAAS,iBAAiB,CAAI,EAGjC,CCzFO,SAAS,CAAQ,CAAC,EAAgB,EAAmB,IAAa,CACxE,GAAI,OAAO,IAAU,SAAU,OAAO,EACtC,GA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Ac,EAAqB,CAAQ,CAC5C,EACA,MAAO,CACR,EAGD,IAAM,EAAM,KAAK,aAAa,CAAQ,EAChC,EAAW,EAAe,EAAK,EAAU,EAAa,CAC3D,kBAAmB,GAAS,kBAC5B,QAAS,KAAK,OACf,CAAC,EAED,GAAI,CAAC,EAAS,MACb,MAAO,CAAE,WAAU,MAAO,MAAU,EAGrC,IAAM,EAAQ,EAAe,EAAK,EAAU,EAAM,CACjD,eAAgB,GAAS,eACzB,IAAK,KAAK,IACV,iBAAkB,KAAK,gBACxB,CAAC,EACD,MAAO,CAAE,WAAU,OAAM,EAe1B,cAAc,CAAC,EAAc,EAAoC,CAOhE,OANA,KAAK,QAAQ,IAAI,EAAM,CAAU,EACjC,KAAK,IAAI,eAAe,EAAM,EAAW,EAAE,EAG3C,KAAK,iBAAiB,MAAM,EAErB,KASR,gBAAgB,CAAC,EAAoB,CAOpC,OANA,KAAK,QAAQ,OAAO,CAAI,EACxB,KAAK,IAAI,iBAAiB,CAAI,EAG9B,KAAK,iBAAiB,MAAM,EAErB,KASR,SAAS,CAAC,EAAuB,CAChC,OAAO,KAAK,QAAQ,IAAI,CAAI,EAU7B,WAAW,EAAS,CACnB,KAAK,SAAS,MAAM,EACpB,KAAK,iBAAiB,MAAM,EAQrB,YAAY,CAAC,EAAmC,CACvD,IAAI,EAAM,KAAK,SAAS,IAAI,CAAQ,EACpC,GAAI,CAAC,EACJ,EAAM,EAAM,CAAQ,EACpB,KAAK,SAAS,IAAI,EAAU,CAAG,EAEhC,OAAO,EAET",
12
+ "debugId": "B6C693AB7E88031064756E2164756E21",
8
13
  "names": []
9
14
  }
package/dist/types.js CHANGED
@@ -1,4 +1,4 @@
1
- import{j as a,k as b,l as c,m as d}from"./chunk-6955jpr7.js";export{b as isObjectInput,a as isLiteralInput,c as inferPrimitiveSchema,d as defineHelper};
1
+ import{i as a,j as b,k as c,l as d}from"./chunk-8xza8tca.js";export{b as isObjectInput,a as isLiteralInput,c as inferPrimitiveSchema,d as defineHelper};
2
2
 
3
- //# debugId=9DCD2B51206A921264756E2164756E21
3
+ //# debugId=482DEAA3F7698BB464756E2164756E21
4
4
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "9DCD2B51206A921264756E2164756E21",
7
+ "debugId": "482DEAA3F7698BB464756E2164756E21",
8
8
  "names": []
9
9
  }
package/dist/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import{E as a,F as b,G as c,H as d,I as e,J as f}from"./chunk-p5efqsxw.js";export{d as getSchemaPropertyNames,c as extractSourceSnippet,a as deepEqual,f as aggregateObjectAnalysisAndExecution,e as aggregateObjectAnalysis,b as LRUCache};
1
+ import{D as a,E as b,F as c,G as d,H as e,I as f}from"./chunk-9jxzj2h4.js";export{d as getSchemaPropertyNames,c as extractSourceSnippet,a as deepEqual,f as aggregateObjectAnalysisAndExecution,e as aggregateObjectAnalysis,b as LRUCache};
2
2
 
3
- //# debugId=6C8BFE07B8FFC81B64756E2164756E21
3
+ //# debugId=6FEE0731DB745ACE64756E2164756E21
4
4
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "6C8BFE07B8FFC81B64756E2164756E21",
7
+ "debugId": "6FEE0731DB745ACE64756E2164756E21",
8
8
  "names": []
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typebars",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "license": "MIT",
5
5
  "description": "Typebars is a type-safe handlebars based template engine for generating object or content with static type checking",
6
6
  "author": {
@@ -17,7 +17,7 @@
17
17
  "README.md"
18
18
  ],
19
19
  "scripts": {
20
- "postinstall": "lefthook install",
20
+ "prepare": "lefthook install",
21
21
  "build:bun": "bun build src/*.ts --outdir ./dist --production --minify --root src --sourcemap --splitting --target node --format esm --packages external --chunk-naming='chunk-[hash].js'",
22
22
  "build:tsc": "tsc --project tsconfig.build.json",
23
23
  "build": "bun --parallel build:bun build:tsc",
@@ -1,4 +0,0 @@
1
- import{j as S,k as f,l as h}from"./chunk-6955jpr7.js";import{n as q,p as C,q as D,r as W,s as E,t as T,v as P,y}from"./chunk-rkrp4ysw.js";import{B as $,C as v,D as V,z as Y}from"./chunk-jms1ndxn.js";import{E as u,G as N,H as _,I as g}from"./chunk-p5efqsxw.js";import{P as B,Q as M,R as U,S as b,T as k}from"./chunk-zh1e0yhd.js";function i(j,w,A){if(f(j))return p(j,w,A);if(S(j))return{valid:!0,diagnostics:[],outputSchema:h(j)};let F=q(j);return a(F,j,w,{identifierSchemas:A})}function p(j,w,A){return g(Object.keys(j),(F)=>i(j[F],w,A))}function a(j,w,A,F){if(Y(A),F?.identifierSchemas)for(let[G,J]of Object.entries(F.identifierSchemas))Y(J,`/identifierSchemas/${G}`);let z={root:A,current:A,diagnostics:[],template:w,identifierSchemas:F?.identifierSchemas,helpers:F?.helpers},H=K(j,z);return{valid:!z.diagnostics.some((G)=>G.severity==="error"),diagnostics:z.diagnostics,outputSchema:V(H)}}function x(j,w){switch(j.type){case"ContentStatement":case"CommentStatement":return;case"MustacheStatement":return d(j,w);case"BlockStatement":return Z(j,w);default:L(w,"UNANALYZABLE","warning",`Unsupported AST node type: "${j.type}"`,j);return}}function d(j,w){if(j.path.type==="SubExpression")return L(w,"UNANALYZABLE","warning","Sub-expressions are not statically analyzable",j),{};if(j.params.length>0||j.hash){let A=n(j.path),F=w.helpers?.get(A);if(F){let z=F.params;if(z){let H=z.filter((I)=>!I.optional).length;if(j.params.length<H)L(w,"MISSING_ARGUMENT","error",`Helper "${A}" expects at least ${H} argument(s), but got ${j.params.length}`,j,{helperName:A,expected:`${H} argument(s)`,actual:`${j.params.length} argument(s)`})}for(let H=0;H<j.params.length;H++){let I=R(j.params[H],w,j),G=z?.[H];if(I&&G?.type){let J=G.type;if(!o(I,J)){let O=G.name;L(w,"TYPE_MISMATCH","error",`Helper "${A}" parameter "${O}" expects ${Q(J)}, but got ${Q(I)}`,j,{helperName:A,expected:Q(J),actual:Q(I)})}}}return F.returnType??{type:"string"}}return L(w,"UNKNOWN_HELPER","warning",`Unknown inline helper "${A}" — cannot analyze statically`,j,{helperName:A}),{type:"string"}}return R(j.path,w,j)??{}}function o(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((H)=>z===H||H==="number"&&z==="integer"||H==="integer"&&z==="number"))}function K(j,w){let A=W(j);if(A.length===0)return{type:"string"};let F=T(j);if(F)return d(F,w);let z=E(j);if(z)return Z(z,w);if(A.every((G)=>G.type==="ContentStatement")){let G=A.map((O)=>O.value).join("").trim();if(G==="")return{type:"string"};let J=P(G);if(J)return{type:J}}if(A.every((G)=>G.type==="BlockStatement")){let G=[];for(let J of A){let O=Z(J,w);if(O)G.push(O)}if(G.length===1)return G[0];if(G.length>1)return V({oneOf:G});return{type:"string"}}for(let G of j.body)x(G,w);return{type:"string"}}function Z(j,w){let A=c(j);switch(A){case"if":case"unless":{let F=X(j);if(F)R(F,w,j);else L(w,"MISSING_ARGUMENT","error",U(A),j,{helperName:A});let z=K(j.program,w);if(j.inverse){let H=K(j.inverse,w);if(u(z,H))return z;return V({oneOf:[z,H]})}return z}case"each":{let F=X(j);if(!F){L(w,"MISSING_ARGUMENT","error",U("each"),j,{helperName:"each"});let G=w.current;if(w.current={},K(j.program,w),w.current=G,j.inverse)K(j.inverse,w);return{type:"string"}}let z=R(F,w,j);if(!z){let G=w.current;if(w.current={},K(j.program,w),w.current=G,j.inverse)K(j.inverse,w);return{type:"string"}}let H=v(z,w.root);if(!H){L(w,"TYPE_MISMATCH","error",M("each","an array",Q(z)),j,{helperName:"each",expected:"array",actual:Q(z)});let G=w.current;if(w.current={},K(j.program,w),w.current=G,j.inverse)K(j.inverse,w);return{type:"string"}}let I=w.current;if(w.current=H,K(j.program,w),w.current=I,j.inverse)K(j.inverse,w);return{type:"string"}}case"with":{let F=X(j);if(!F){L(w,"MISSING_ARGUMENT","error",U("with"),j,{helperName:"with"});let G=w.current;w.current={};let J=K(j.program,w);if(w.current=G,j.inverse)K(j.inverse,w);return J}let z=R(F,w,j),H=w.current;w.current=z??{};let I=K(j.program,w);if(w.current=H,j.inverse)K(j.inverse,w);return I}default:{let F=w.helpers?.get(A);if(F){for(let z of j.params)R(z,w,j);if(K(j.program,w),j.inverse)K(j.inverse,w);return F.returnType??{type:"string"}}if(L(w,"UNKNOWN_HELPER","warning",b(A),j,{helperName:A}),K(j.program,w),j.inverse)K(j.inverse,w);return{type:"string"}}}}function R(j,w,A){if(D(j))return w.current;if(j.type==="SubExpression")return m(j,w,A);let F=C(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{};L(w,"UNANALYZABLE","warning",k(j.type),A??j);return}let{cleanSegments:z,identifier:H}=y(F);if(H!==null)return r(z,H,w,A??j);let I=$(w.current,z);if(I===void 0){let G=z.join("."),J=_(w.current);L(w,"UNKNOWN_PROPERTY","error",B(G,J),A??j,{path:G,availableProperties:J});return}return I}function r(j,w,A,F){let z=j.join(".");if(!A.identifierSchemas){L(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 H=A.identifierSchemas[w];if(!H){L(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 I=$(H,j);if(I===void 0){let G=_(H);L(A,"IDENTIFIER_PROPERTY_NOT_FOUND","error",`Property "${z}" does not exist in the schema for identifier ${w}`,F,{path:z,identifier:w,availableProperties:G});return}return I}function m(j,w,A){let F=n(j.path),z=w.helpers?.get(F);if(!z)return L(w,"UNKNOWN_HELPER","warning",`Unknown sub-expression helper "${F}" — cannot analyze statically`,A??j,{helperName:F}),{type:"string"};let H=z.params;if(H){let I=H.filter((G)=>!G.optional).length;if(j.params.length<I)L(w,"MISSING_ARGUMENT","error",`Helper "${F}" expects at least ${I} argument(s), but got ${j.params.length}`,A??j,{helperName:F,expected:`${I} argument(s)`,actual:`${j.params.length} argument(s)`})}for(let I=0;I<j.params.length;I++){let G=R(j.params[I],w,A??j),J=H?.[I];if(G&&J?.type){let O=J.type;if(!o(G,O)){let l=J.name;L(w,"TYPE_MISMATCH","error",`Helper "${F}" parameter "${l}" expects ${Q(O)}, but got ${Q(G)}`,A??j,{helperName:F,expected:Q(O),actual:Q(G)})}}}return z.returnType??{type:"string"}}function X(j){return j.params[0]}function c(j){if(j.path.type==="PathExpression")return j.path.original;return""}function n(j){if(j.type==="PathExpression")return j.original;return""}function L(j,w,A,F,z,H){let I={severity:A,code:w,message:F};if(z&&"loc"in z&&z.loc)I.loc={start:{line:z.loc.start.line,column:z.loc.start.column},end:{line:z.loc.end.line,column:z.loc.end.column}},I.source=N(j.template,I.loc);if(H)I.details=H;j.diagnostics.push(I)}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{i as c,a as d,Z as e};
2
-
3
- //# debugId=7EA14E90D54F63A864756E2164756E21
4
- //# sourceMappingURL=chunk-t6n956qz.js.map
@@ -1,5 +0,0 @@
1
- import{b as C}from"./chunk-ecs3yth2.js";import{d as z}from"./chunk-t6n956qz.js";import{g as L}from"./chunk-efqd0598.js";import{j as Q,k as W,l as _}from"./chunk-6955jpr7.js";import{n as k}from"./chunk-rkrp4ysw.js";import{F as N,I as E,J as I}from"./chunk-p5efqsxw.js";import{M as U}from"./chunk-zh1e0yhd.js";import P from"handlebars";class Y{_definitions=null;_helperNames=null;_helperNamesSet=null;getDefinitions(){if(!this._definitions)this._definitions=new Map,this.buildDefinitions(this._definitions);return this._definitions}getHelperNames(){if(!this._helperNames)this._helperNames=[...this.getDefinitions().keys()];return this._helperNames}isHelper(w){if(!this._helperNamesSet)this._helperNamesSet=new Set(this.getHelperNames());return this._helperNamesSet.has(w)}register(w){for(let[M,H]of this.getDefinitions())w.registerHelper(M,H)}unregister(w){for(let M of this.getHelperNames())w.unregisterHelper(M)}}function B(w,M=NaN){if(typeof w==="number")return w;if(typeof w==="string"){let H=Number(w);return Number.isNaN(H)?M:H}if(typeof w==="boolean")return w?1:0;return M}var j=new Set(["==","===","!=","!==","<","<=",">",">="]);function T(w,M,H){switch(M){case"==":return w==H;case"===":return w===H;case"!=":return w!=H;case"!==":return w!==H;case"<":return B(w)<B(H);case"<=":return B(w)<=B(H);case">":return B(w)>B(H);case">=":return B(w)>=B(H)}}function A(w){return w!==null&&typeof w==="object"&&"hash"in w&&"name"in w}class Z extends Y{buildDefinitions(w){this.registerEquality(w),this.registerComparison(w),this.registerLogicalOperators(w),this.registerCollectionHelpers(w),this.registerGenericCompare(w)}registerEquality(w){w.set("eq",{fn:(H,V)=>H===V,params:[{name:"a",description:"Left value"},{name:"b",description:"Right value"}],returnType:{type:"boolean"},description:"Returns true if a is strictly equal to b: {{#if (eq a b)}}"});let M={fn:(H,V)=>H!==V,params:[{name:"a",description:"Left value"},{name:"b",description:"Right value"}],returnType:{type:"boolean"},description:"Returns true if a is not strictly equal to b: {{#if (ne a b)}}"};w.set("ne",M),w.set("neq",M)}registerComparison(w){w.set("lt",{fn:(V,q)=>B(V)<B(q),params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"boolean"},description:"Returns true if a < b: {{#if (lt a b)}}"});let M={fn:(V,q)=>B(V)<=B(q),params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"boolean"},description:"Returns true if a <= b: {{#if (lte a b)}}"};w.set("lte",M),w.set("le",M),w.set("gt",{fn:(V,q)=>B(V)>B(q),params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"boolean"},description:"Returns true if a > b: {{#if (gt a b)}}"});let H={fn:(V,q)=>B(V)>=B(q),params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"boolean"},description:"Returns true if a >= b: {{#if (gte a b)}}"};w.set("gte",H),w.set("ge",H)}registerLogicalOperators(w){w.set("not",{fn:(M)=>!M,params:[{name:"value",description:"Value to negate"}],returnType:{type:"boolean"},description:"Returns true if the value is falsy: {{#if (not active)}}"}),w.set("and",{fn:(M,H)=>!!M&&!!H,params:[{name:"a",description:"First condition"},{name:"b",description:"Second condition"}],returnType:{type:"boolean"},description:"Returns true if both values are truthy: {{#if (and a b)}}"}),w.set("or",{fn:(M,H)=>!!M||!!H,params:[{name:"a",description:"First condition"},{name:"b",description:"Second condition"}],returnType:{type:"boolean"},description:"Returns true if at least one value is truthy: {{#if (or a b)}}"})}registerCollectionHelpers(w){w.set("contains",{fn:(M,H)=>{if(typeof M==="string")return M.includes(String(H));if(Array.isArray(M))return M.includes(H);return!1},params:[{name:"haystack",description:"String or array to search in"},{name:"needle",description:"Value to search for"}],returnType:{type:"boolean"},description:'Checks if a string contains a substring or an array contains an element: {{#if (contains name "ali")}}'}),w.set("in",{fn:(...M)=>{if(M.length<2)return!1;let H=M[0];return M.slice(1).filter((q)=>!A(q)).some((q)=>q===H)},params:[{name:"value",description:"Value to look for"},{name:"candidates",description:'One or more candidate values (variadic): {{#if (in status "active" "pending")}}'}],returnType:{type:"boolean"},description:'Checks if a value is one of the provided options: {{#if (in status "active" "pending" "draft")}}'})}registerGenericCompare(w){w.set("compare",{fn:(M,H,V)=>{let q=String(H);if(!j.has(q))throw Error(`[compare helper] Unknown operator "${q}". Supported: ${[...j].join(", ")} `);return T(M,q,V)},params:[{name:"a",description:"Left operand"},{name:"operator",type:{type:"string",enum:["==","===","!=","!==","<","<=",">",">="]},description:'Comparison operator: "==", "===", "!=", "!==", "<", "<=", ">", ">="'},{name:"b",description:"Right operand"}],returnType:{type:"boolean"},description:'Generic comparison helper with operator as parameter: {{#if (compare a "<" b)}}. Supported operators: ==, ===, !=, !==, <, <=, >, >='})}}var F=new Set(["+","-","*","/","%","**"]),x=(w)=>B(w,0);function g(w,M,H){switch(M){case"+":return w+H;case"-":return w-H;case"*":return w*H;case"/":return H===0?1/0:w/H;case"%":return H===0?NaN:w%H;case"**":return w**H}}class $ extends Y{buildDefinitions(w){this.registerBinaryOperators(w),this.registerUnaryFunctions(w),this.registerMinMax(w),this.registerGenericMath(w)}registerBinaryOperators(w){let M={fn:(G,K)=>x(G)+x(K),params:[{name:"a",type:{type:"number"},description:"First operand"},{name:"b",type:{type:"number"},description:"Second operand"}],returnType:{type:"number"},description:"Adds two numbers: {{ add a b }}"};w.set("add",M);let H={fn:(G,K)=>x(G)-x(K),params:[{name:"a",type:{type:"number"},description:"Value to subtract from"},{name:"b",type:{type:"number"},description:"Value to subtract"}],returnType:{type:"number"},description:"Subtracts b from a: {{ subtract a b }}"};w.set("subtract",H),w.set("sub",H);let V={fn:(G,K)=>x(G)*x(K),params:[{name:"a",type:{type:"number"},description:"First factor"},{name:"b",type:{type:"number"},description:"Second factor"}],returnType:{type:"number"},description:"Multiplies two numbers: {{ multiply a b }}"};w.set("multiply",V),w.set("mul",V);let q={fn:(G,K)=>{let X=x(K);return X===0?1/0:x(G)/X},params:[{name:"a",type:{type:"number"},description:"Dividend"},{name:"b",type:{type:"number"},description:"Divisor"}],returnType:{type:"number"},description:"Divides a by b: {{ divide a b }}. Returns Infinity if b is 0."};w.set("divide",q),w.set("div",q);let J={fn:(G,K)=>{let X=x(K);return X===0?NaN:x(G)%X},params:[{name:"a",type:{type:"number"},description:"Dividend"},{name:"b",type:{type:"number"},description:"Divisor"}],returnType:{type:"number"},description:"Returns the remainder of a divided by b: {{ modulo a b }}"};w.set("modulo",J),w.set("mod",J),w.set("pow",{fn:(G,K)=>x(G)**x(K),params:[{name:"base",type:{type:"number"},description:"The base"},{name:"exponent",type:{type:"number"},description:"The exponent"}],returnType:{type:"number"},description:"Raises base to the power of exponent: {{ pow base exponent }}"})}registerUnaryFunctions(w){w.set("abs",{fn:(M)=>Math.abs(x(M)),params:[{name:"value",type:{type:"number"},description:"The number"}],returnType:{type:"number"},description:"Returns the absolute value: {{ abs value }}"}),w.set("ceil",{fn:(M)=>Math.ceil(x(M)),params:[{name:"value",type:{type:"number"},description:"The number to round up"}],returnType:{type:"number"},description:"Rounds up to the nearest integer: {{ ceil value }}"}),w.set("floor",{fn:(M)=>Math.floor(x(M)),params:[{name:"value",type:{type:"number"},description:"The number to round down"}],returnType:{type:"number"},description:"Rounds down to the nearest integer: {{ floor value }}"}),w.set("round",{fn:(M,H)=>{let V=x(M);if(H===void 0||H===null||typeof H==="object")return Math.round(V);let J=10**x(H);return Math.round(V*J)/J},params:[{name:"value",type:{type:"number"},description:"The number to round"},{name:"precision",type:{type:"number"},description:"Number of decimal places (default: 0)",optional:!0}],returnType:{type:"number"},description:"Rounds to the nearest integer or to a given precision: {{ round value }} or {{ round value 2 }}"}),w.set("sqrt",{fn:(M)=>Math.sqrt(x(M)),params:[{name:"value",type:{type:"number"},description:"The number"}],returnType:{type:"number"},description:"Returns the square root: {{ sqrt value }}"})}registerMinMax(w){w.set("min",{fn:(M,H)=>Math.min(x(M),x(H)),params:[{name:"a",type:{type:"number"},description:"First number"},{name:"b",type:{type:"number"},description:"Second number"}],returnType:{type:"number"},description:"Returns the smaller of two numbers: {{ min a b }}"}),w.set("max",{fn:(M,H)=>Math.max(x(M),x(H)),params:[{name:"a",type:{type:"number"},description:"First number"},{name:"b",type:{type:"number"},description:"Second number"}],returnType:{type:"number"},description:"Returns the larger of two numbers: {{ max a b }}"})}registerGenericMath(w){w.set("math",{fn:(M,H,V)=>{let q=String(H);if(!F.has(q))throw Error(`[math helper] Unknown operator "${q}". Supported: ${[...F].join(", ")} `);return g(x(M),q,x(V))},params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"operator",type:{type:"string",enum:["+","-","*","/","%","**"]},description:'Arithmetic operator: "+", "-", "*", "/", "%", "**"'},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"number"},description:'Generic math helper with operator as parameter: {{ math a "+" b }}, {{ math a "/" b }}. Supported operators: +, -, *, /, %, **'})}}class R{hbs;astCache;compilationCache;helpers=new Map;constructor(w={}){if(this.hbs=P.create(),this.astCache=new N(w.astCacheSize??256),this.compilationCache=new N(w.compilationCacheSize??256),new $().register(this),new Z().register(this),w.helpers)for(let M of w.helpers){let{name:H,...V}=M;this.registerHelper(H,V)}}compile(w){if(W(w)){let V={};for(let[q,J]of Object.entries(w))V[q]=this.compile(J);return C.fromObject(V,{helpers:this.helpers,hbs:this.hbs,compilationCache:this.compilationCache})}if(Q(w))return C.fromLiteral(w,{helpers:this.helpers,hbs:this.hbs,compilationCache:this.compilationCache});let M=this.getCachedAst(w),H={helpers:this.helpers,hbs:this.hbs,compilationCache:this.compilationCache};return C.fromTemplate(M,w,H)}analyze(w,M,H){if(W(w))return E(Object.keys(w),(q)=>this.analyze(w[q],M,H));if(Q(w))return{valid:!0,diagnostics:[],outputSchema:_(w)};let V=this.getCachedAst(w);return z(V,w,M,{identifierSchemas:H,helpers:this.helpers})}validate(w,M,H){let V=this.analyze(w,M,H);return{valid:V.valid,diagnostics:V.diagnostics}}isValidSyntax(w){if(W(w))return Object.values(w).every((M)=>this.isValidSyntax(M));if(Q(w))return!0;try{return this.getCachedAst(w),!0}catch{return!1}}execute(w,M,H){if(W(w)){let q={};for(let[J,G]of Object.entries(w))q[J]=this.execute(G,M,H);return q}if(Q(w))return w;let V=this.getCachedAst(w);if(H?.schema){let q=z(V,w,H.schema,{identifierSchemas:H.identifierSchemas,helpers:this.helpers});if(!q.valid)throw new U(q.diagnostics)}return L(V,w,M,{identifierData:H?.identifierData,hbs:this.hbs,compilationCache:this.compilationCache})}analyzeAndExecute(w,M,H,V){if(W(w))return I(Object.keys(w),(K)=>this.analyzeAndExecute(w[K],M,H,V));if(Q(w))return{analysis:{valid:!0,diagnostics:[],outputSchema:_(w)},value:w};let q=this.getCachedAst(w),J=z(q,w,M,{identifierSchemas:V?.identifierSchemas,helpers:this.helpers});if(!J.valid)return{analysis:J,value:void 0};let G=L(q,w,H,{identifierData:V?.identifierData,hbs:this.hbs,compilationCache:this.compilationCache});return{analysis:J,value:G}}registerHelper(w,M){return this.helpers.set(w,M),this.hbs.registerHelper(w,M.fn),this.compilationCache.clear(),this}unregisterHelper(w){return this.helpers.delete(w),this.hbs.unregisterHelper(w),this.compilationCache.clear(),this}hasHelper(w){return this.helpers.has(w)}clearCaches(){this.astCache.clear(),this.compilationCache.clear()}getCachedAst(w){let M=this.astCache.get(w);if(!M)M=k(w),this.astCache.set(w,M);return M}}
2
- export{R as a};
3
-
4
- //# debugId=2517AB2E996B3F7E64756E2164756E21
5
- //# sourceMappingURL=chunk-xd2vmd03.js.map