@pwfabric/runtime 1.2.0 → 2.1.0

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 (48) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +1 -1
  3. package/dist/binding/expression.js +4 -1
  4. package/dist/binding/expression.js.map +1 -1
  5. package/dist/connectors/types.d.ts +4 -2
  6. package/dist/connectors/types.js +4 -2
  7. package/dist/connectors/types.js.map +1 -1
  8. package/dist/entity/http-connector.js +1 -1
  9. package/dist/entity/http-connector.js.map +1 -1
  10. package/dist/entity/registry.js +1 -1
  11. package/dist/entity/registry.js.map +1 -1
  12. package/dist/forms/validator.js +1 -1
  13. package/dist/forms/validator.js.map +1 -1
  14. package/dist/index.d.ts +3 -2
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/render/DataBoundSurfaceRenderer.d.ts +10 -0
  18. package/dist/render/DataBoundSurfaceRenderer.js +45 -11
  19. package/dist/render/DataBoundSurfaceRenderer.js.map +1 -1
  20. package/dist/render/data-binding-types.d.ts +13 -2
  21. package/dist/render/data-binding-types.js.map +1 -1
  22. package/dist/render/index.d.ts +3 -1
  23. package/dist/render/index.js +2 -1
  24. package/dist/render/index.js.map +1 -1
  25. package/dist/render/links.d.ts +50 -0
  26. package/dist/render/links.js +78 -0
  27. package/dist/render/links.js.map +1 -0
  28. package/dist/render/resolve-expressions.d.ts +22 -1
  29. package/dist/render/resolve-expressions.js +65 -5
  30. package/dist/render/resolve-expressions.js.map +1 -1
  31. package/dist/render/scoped-css.d.ts +8 -1
  32. package/dist/render/scoped-css.js +16 -0
  33. package/dist/render/scoped-css.js.map +1 -1
  34. package/dist/surface/expression.js +0 -1
  35. package/dist/surface/expression.js.map +1 -1
  36. package/dist/surface/output.js +4 -4
  37. package/dist/surface/output.js.map +1 -1
  38. package/dist/surface/schemas.d.ts +28 -96
  39. package/dist/surface/schemas.js +3 -3
  40. package/dist/surface/schemas.js.map +1 -1
  41. package/dist/surface/transforms.d.ts +7 -33
  42. package/dist/surface/transforms.js +2 -2
  43. package/dist/surface/transforms.js.map +1 -1
  44. package/dist/surface/validation.js +1 -1
  45. package/dist/surface/validation.js.map +1 -1
  46. package/dist/validator.js +1 -1
  47. package/dist/validator.js.map +1 -1
  48. package/package.json +8 -8
@@ -1 +1 @@
1
- {"version":3,"file":"expression.js","sourceRoot":"","sources":["../../src/surface/expression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,+DAA+D;AAC/D,mBAAmB;AACnB,+DAA+D;AAE/D;;GAEG;AACH,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAcnG,+DAA+D;AAC/D,kBAAkB;AAClB,+DAA+D;AAE/D;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY,EAAE,IAAY;IACpD,IAAI,CAAC,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACrD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,OAAO,GAAY,GAAG,CAAA;IAE1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC9C,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,kCAAkC;QAClC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAA;QACjD,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;YAC1B,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;YAC3B,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;gBAClB,OAAO,GAAG,YAAY,CAAC,O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QACL,IAAI;QACJ,OAAO,EAAE,EAAE,GAAG,eAAe,EAAE,GAAG,iBAAiB,EAAE;KACtD,CAAA;AACH,CAAC","sourcesContent":["/**\n * Expression Evaluator\n *\n * Safe expression evaluation for surface rendering\n *\n * Expressions are used in conditionals, loops, and data bindings.\n * This evaluator provides a safe, sandboxed way to evaluate expressions.\n *\n * @module @pwfabric/runtime/surface/expression\n */\n\n// ============================================================\n// EXPRESSION TYPES\n// ============================================================\n\n/**\n * Expression result\n */\nimport { DEFAULT_BINDING_HELPERS, evaluateWithScope, readProperty } from '../binding/expression.js'\n\nexport type ExpressionResult<T = unknown> =\n | { readonly success: true; readonly value: T }\n | { readonly success: false; readonly error: string }\n\n/**\n * Expression context - the scope for evaluation\n */\nexport interface ExpressionContext {\n readonly data: Record<string, unknown>\n readonly helpers?: Record<string, (...args: unknown[]) => unknown>\n}\n\n// ============================================================\n// PATH RESOLUTION\n// ============================================================\n\n/**\n * Resolve a dotted path in an object\n * e.g., \"user.profile.name\" -> obj.user.profile.name\n */\nexport function resolvePath(obj: unknown, path: string): unknown {\n if (!path || typeof obj !== 'object' || obj === null) {\n return undefined\n }\n\n const parts = path.split('.')\n let current: unknown = obj\n\n for (const part of parts) {\n if (current === null || current === undefined) {\n return undefined\n }\n\n // Handle array indexing: items[0]\n const arrayMatch = part.match(/^(\\w+)\\[(\\d+)\\]$/)\n if (arrayMatch) {\n const prop = arrayMatch[1]\n const index = arrayMatch[2]\n if (prop && index) {\n current = readProperty(current, prop)\n if (Array.isArray(current)) {\n current = current[parseInt(index, 10)]\n } else {\n return undefined\n }\n }\n } else if (typeof current === 'object') {\n // A list of ONE record is read through — see readProperty.\n current = readProperty(current, part)\n } else {\n return undefined\n }\n }\n\n return current\n}\n\n// ============================================================\n// EXPRESSION EVALUATOR\n// ============================================================\n\n/**\n * Evaluate an expression (the text between `{{` and `}}`).\n *\n * THE SAME PARSER AS THE BINDING EVALUATOR (binding/expression.ts). This used\n * to be a regex/`split` evaluator of its own, and the two drifted: no\n * parentheses, no arithmetic, helper arguments split on every comma — so\n * `{{a == 'x' && (b || c)}}` failed, and a failed `visibleWhen` rendered its\n * raw template, which counts as visible.\n *\n * Supported: paths (`user.name`, `items[0]`, `items.0`, hyphenated source ids\n * `hero-stats.0.text`), literals, `! - +`, `* / %`, `+ -`, comparisons,\n * `&& || ??` (short-circuit), `?:`, parentheses, array literals, helper calls\n * (`join(xs, ', ')`) and a safe list of string / array / number methods\n * (`name.toLowerCase().includes(q)`).\n *\n * Names resolve against `context.data`; a call resolves against\n * `context.helpers`. In this mode a `-` between two name characters is part of\n * the name (source ids are hyphenated) — write subtraction as `a - b`.\n *\n * A syntax error, an unknown helper or an unsupported method is a FAILURE\n * (`success: false`), never a partial value.\n */\nexport function evaluate(expression: string, context: ExpressionContext): ExpressionResult {\n try {\n const data = context.data\n const helpers = context.helpers\n const value = evaluateWithScope(\n expression,\n {\n lookup: (name) => data[name],\n helper: (name) =>\n helpers && Object.prototype.hasOwnProperty.call(helpers, name) ? helpers[name] : undefined,\n },\n { hyphenNames: true }\n )\n return { success: true, value }\n } catch (e) {\n return { success: false, error: `Unable to evaluate expression: ${expression.trim()} — ${e instanceof Error ? e.message : String(e)}` }\n }\n}\n\n// ============================================================\n// INTERPOLATION\n// ============================================================\n\n/**\n * Interpolate expressions within a template string\n * e.g., \"Hello, {{user.name}}!\" -> \"Hello, John!\"\n */\nexport function interpolate(\n template: string,\n context: ExpressionContext\n): ExpressionResult<string> {\n const pattern = /\\{\\{(.+?)\\}\\}/g\n let result = template\n let match: RegExpExecArray | null\n\n while ((match = pattern.exec(template)) !== null) {\n const placeholder = match[0]\n const expression = match[1]\n if (!expression) continue\n const evalResult = evaluate(expression.trim(), context)\n if (!evalResult.success) {\n return evalResult as ExpressionResult<string>\n }\n // CALLBACK replacer, NOT a string replacement. When its second argument is\n // a string, `String.replace` treats `$&`, `$\\``, `$'`, `$$` as REPLACEMENT\n // PATTERNS: `\"$$5\"` in the data would print as `\"$5\"`, and `\"a$&b\"` would\n // bring back the placeholder itself. The sibling evaluator\n // (binding/expression.ts) uses a callback too.\n const replacement = String(evalResult.value ?? '')\n result = result.replace(placeholder, () => replacement)\n }\n\n return { success: true, value: result }\n}\n\n// ============================================================\n// BUILT-IN HELPERS\n// ============================================================\n\n/**\n * Default helper functions available in expressions\n */\nexport const DEFAULT_HELPERS: Record<string, (...args: unknown[]) => unknown> = {\n // The binding evaluator's helper set comes first. Two evaluators exist —\n // binding/expression (bindings, computed values) and this one (block props\n // through resolveBlockExpressions) — and their helper lists drifted:\n // `sumBy`, `groupCount`, `min`, `max`, `currency`, `date`… live in the\n // binding set, and without it a KPI tile authored as\n // `{{sumBy(customers,'mrr')}}` would render the raw template. One name, one meaning: the surface-specific entries below\n // override where both define the same name.\n ...DEFAULT_BINDING_HELPERS,\n // String helpers\n upper: (s: unknown) => String(s).toUpperCase(),\n lower: (s: unknown) => String(s).toLowerCase(),\n trim: (s: unknown) => String(s).trim(),\n length: (s: unknown) => (Array.isArray(s) ? s.length : String(s).length),\n concat: (...args: unknown[]) => args.map(String).join(''),\n\n // Number helpers\n // `round` comes from the binding set: `round(n)` as before, `round(n, 2)`\n // to two decimals (this override used to drop the second argument).\n floor: (n: unknown) => Math.floor(Number(n)),\n ceil: (n: unknown) => Math.ceil(Number(n)),\n abs: (n: unknown) => Math.abs(Number(n)),\n\n // Array helpers\n first: (arr: unknown) => (Array.isArray(arr) ? arr[0] : undefined),\n last: (arr: unknown) => (Array.isArray(arr) ? arr[arr.length - 1] : undefined),\n isEmpty: (v: unknown) =>\n v === null || v === undefined || v === '' || (Array.isArray(v) && v.length === 0),\n isNotEmpty: (v: unknown) =>\n v !== null && v !== undefined && v !== '' && !(Array.isArray(v) && v.length === 0),\n\n // Type helpers\n typeof: (v: unknown) => typeof v,\n isArray: (v: unknown) => Array.isArray(v),\n isString: (v: unknown) => typeof v === 'string',\n isNumber: (v: unknown) => typeof v === 'number',\n isBool: (v: unknown) => typeof v === 'boolean',\n\n // Formatting helpers\n json: (v: unknown) => JSON.stringify(v),\n}\n\n/**\n * Create an expression context with default helpers\n */\nexport function createExpressionContext(\n data: Record<string, unknown>,\n additionalHelpers?: Record<string, (...args: unknown[]) => unknown>\n): ExpressionContext {\n return {\n data,\n helpers: { ...DEFAULT_HELPERS, ...additionalHelpers },\n }\n}\n"]}
1
+ {"version":3,"file":"expression.js","sourceRoot":"","sources":["../../src/surface/expression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,+DAA+D;AAC/D,mBAAmB;AACnB,+DAA+D;AAE/D;;GAEG;AACH,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAcnG,+DAA+D;AAC/D,kBAAkB;AAClB,+DAA+D;AAE/D;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY,EAAE,IAAY;IACpD,IAAI,CAAC,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACrD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,OAAO,GAAY,GAAG,CAAA;IAE1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC9C,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,kCAAkC;QAClC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAA;QACjD,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;YAC1B,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;YAC3B,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;gBAClB,OAAO,GAAG,YAAY,CAAC,OAAO,EAAE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GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9E,OAAO,EAAE,CAAC,CAAU,EAAE,EAAE,CACtB,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACnF,UAAU,EAAE,CAAC,CAAU,EAAE,EAAE,CACzB,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IAEpF,eAAe;IACf,MAAM,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,OAAO,CAAC;IAChC,OAAO,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IACzC,QAAQ,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ;IAC/C,QAAQ,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ;IAC/C,MAAM,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,SAAS;IAE9C,qBAAqB;IACrB,IAAI,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;CACxC,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAA6B,EAC7B,iBAAmE;IAEnE,OAAO;QACL,IAAI;QACJ,OAAO,EAAE,EAAE,GAAG,eAAe,EAAE,GAAG,iBAAiB,EAAE;KACtD,CAAA;AACH,CAAC","sourcesContent":["/**\n * Expression Evaluator\n *\n * Safe expression evaluation for surface rendering\n *\n * Expressions are used in conditionals, loops, and data bindings.\n * This evaluator provides a safe, sandboxed way to evaluate expressions.\n *\n * @module @pwfabric/runtime/surface/expression\n */\n\n// ============================================================\n// EXPRESSION TYPES\n// ============================================================\n\n/**\n * Expression result\n */\nimport { DEFAULT_BINDING_HELPERS, evaluateWithScope, readProperty } from '../binding/expression.js'\n\nexport type ExpressionResult<T = unknown> =\n | { readonly success: true; readonly value: T }\n | { readonly success: false; readonly error: string }\n\n/**\n * Expression context - the scope for evaluation\n */\nexport interface ExpressionContext {\n readonly data: Record<string, unknown>\n readonly helpers?: Record<string, (...args: unknown[]) => unknown>\n}\n\n// ============================================================\n// PATH RESOLUTION\n// ============================================================\n\n/**\n * Resolve a dotted path in an object\n * e.g., \"user.profile.name\" -> obj.user.profile.name\n */\nexport function resolvePath(obj: unknown, path: string): unknown {\n if (!path || typeof obj !== 'object' || obj === null) {\n return undefined\n }\n\n const parts = path.split('.')\n let current: unknown = obj\n\n for (const part of parts) {\n if (current === null || current === undefined) {\n return undefined\n }\n\n // Handle array indexing: items[0]\n const arrayMatch = part.match(/^(\\w+)\\[(\\d+)\\]$/)\n if (arrayMatch) {\n const prop = arrayMatch[1]\n const index = arrayMatch[2]\n if (prop && index) {\n current = readProperty(current, prop)\n if (Array.isArray(current)) {\n current = current[parseInt(index, 10)]\n } else {\n return undefined\n }\n }\n } else if (typeof current === 'object') {\n // A list of ONE record is read through — see readProperty.\n current = readProperty(current, part)\n } else {\n return undefined\n }\n }\n\n return current\n}\n\n// ============================================================\n// EXPRESSION EVALUATOR\n// ============================================================\n\n/**\n * Evaluate an expression (the text between `{{` and `}}`).\n *\n * THE SAME PARSER AS THE BINDING EVALUATOR (binding/expression.ts). This used\n * to be a regex/`split` evaluator of its own, and the two drifted: no\n * parentheses, no arithmetic, helper arguments split on every comma — so\n * `{{a == 'x' && (b || c)}}` failed, and a failed `visibleWhen` rendered its\n * raw template, which counts as visible.\n *\n * Supported: paths (`user.name`, `items[0]`, `items.0`, hyphenated source ids\n * `hero-stats.0.text`), literals, `! - +`, `* / %`, `+ -`, comparisons,\n * `&& || ??` (short-circuit), `?:`, parentheses, array literals, helper calls\n * (`join(xs, ', ')`) and a safe list of string / array / number methods\n * (`name.toLowerCase().includes(q)`).\n *\n * Names resolve against `context.data`; a call resolves against\n * `context.helpers`. In this mode a `-` between two name characters is part of\n * the name (source ids are hyphenated) — write subtraction as `a - b`.\n *\n * A syntax error, an unknown helper or an unsupported method is a FAILURE\n * (`success: false`), never a partial value.\n */\nexport function evaluate(expression: string, context: ExpressionContext): ExpressionResult {\n try {\n const data = context.data\n const helpers = context.helpers\n const value = evaluateWithScope(\n expression,\n {\n lookup: (name) => data[name],\n helper: (name) =>\n helpers && Object.prototype.hasOwnProperty.call(helpers, name) ? helpers[name] : undefined,\n },\n { hyphenNames: true }\n )\n return { success: true, value }\n } catch (e) {\n return { success: false, error: `Unable to evaluate expression: ${expression.trim()} — ${e instanceof Error ? e.message : String(e)}` }\n }\n}\n\n// ============================================================\n// INTERPOLATION\n// ============================================================\n\n/**\n * Interpolate expressions within a template string\n * e.g., \"Hello, {{user.name}}!\" -> \"Hello, John!\"\n */\nexport function interpolate(\n template: string,\n context: ExpressionContext\n): ExpressionResult<string> {\n const pattern = /\\{\\{(.+?)\\}\\}/g\n let result = template\n let match: RegExpExecArray | null\n\n while ((match = pattern.exec(template)) !== null) {\n const placeholder = match[0]\n const expression = match[1]\n if (!expression) continue\n const evalResult = evaluate(expression.trim(), context)\n if (!evalResult.success) {\n return evalResult as ExpressionResult<string>\n }\n // CALLBACK replacer, NOT a string replacement. When its second argument is\n // a string, `String.replace` treats `$&`, `$\\``, `$'`, `$$` as REPLACEMENT\n // PATTERNS: `\"$$5\"` in the data would print as `\"$5\"`, and `\"a$&b\"` would\n // bring back the placeholder itself. The sibling evaluator\n // (binding/expression.ts) uses a callback too.\n const replacement = String(evalResult.value ?? '')\n result = result.replace(placeholder, () => replacement)\n }\n\n return { success: true, value: result }\n}\n\n// ============================================================\n// BUILT-IN HELPERS\n// ============================================================\n\n/**\n * Default helper functions available in expressions\n */\nexport const DEFAULT_HELPERS: Record<string, (...args: unknown[]) => unknown> = {\n // The binding evaluator's helper set comes first. Two evaluators exist —\n // binding/expression (bindings, computed values) and this one (block props\n // through resolveBlockExpressions) — and their helper lists drifted:\n // `sumBy`, `groupCount`, `min`, `max`, `currency`, `date`… live in the\n // binding set, and without it a KPI tile authored as\n // `{{sumBy(customers,'mrr')}}` would render the raw template. One name, one meaning: the surface-specific entries below\n // override where both define the same name.\n ...DEFAULT_BINDING_HELPERS,\n // String helpers\n upper: (s: unknown) => String(s).toUpperCase(),\n lower: (s: unknown) => String(s).toLowerCase(),\n trim: (s: unknown) => String(s).trim(),\n concat: (...args: unknown[]) => args.map(String).join(''),\n\n // Number helpers\n // `round` comes from the binding set: `round(n)` as before, `round(n, 2)`\n // to two decimals (this override used to drop the second argument).\n floor: (n: unknown) => Math.floor(Number(n)),\n ceil: (n: unknown) => Math.ceil(Number(n)),\n abs: (n: unknown) => Math.abs(Number(n)),\n\n // Array helpers\n first: (arr: unknown) => (Array.isArray(arr) ? arr[0] : undefined),\n last: (arr: unknown) => (Array.isArray(arr) ? arr[arr.length - 1] : undefined),\n isEmpty: (v: unknown) =>\n v === null || v === undefined || v === '' || (Array.isArray(v) && v.length === 0),\n isNotEmpty: (v: unknown) =>\n v !== null && v !== undefined && v !== '' && !(Array.isArray(v) && v.length === 0),\n\n // Type helpers\n typeof: (v: unknown) => typeof v,\n isArray: (v: unknown) => Array.isArray(v),\n isString: (v: unknown) => typeof v === 'string',\n isNumber: (v: unknown) => typeof v === 'number',\n isBool: (v: unknown) => typeof v === 'boolean',\n\n // Formatting helpers\n json: (v: unknown) => JSON.stringify(v),\n}\n\n/**\n * Create an expression context with default helpers\n */\nexport function createExpressionContext(\n data: Record<string, unknown>,\n additionalHelpers?: Record<string, (...args: unknown[]) => unknown>\n): ExpressionContext {\n return {\n data,\n helpers: { ...DEFAULT_HELPERS, ...additionalHelpers },\n }\n}\n"]}
@@ -17,7 +17,7 @@ const webOutputDataSchema = z.object({
17
17
  head: z.string().optional(),
18
18
  });
19
19
  const apiOutputDataSchema = z.object({
20
- json: z.unknown(),
20
+ json: z.unknown().optional(),
21
21
  status: z.number().int().min(100).max(599),
22
22
  });
23
23
  const cliOutputDataSchema = z.object({
@@ -37,7 +37,7 @@ export function createWebOutput(options) {
37
37
  if (!dataResult.success) {
38
38
  return {
39
39
  success: false,
40
- errors: dataResult.error.issues.map((i) => `data.${i.path.join('.')}: ${i.message}`),
40
+ errors: dataResult.error.issues.map((i) => `data.${i.path.map(String).join('.')}: ${i.message}`),
41
41
  };
42
42
  }
43
43
  const data = {
@@ -63,7 +63,7 @@ export function createApiOutput(options) {
63
63
  if (!dataResult.success) {
64
64
  return {
65
65
  success: false,
66
- errors: dataResult.error.issues.map((i) => `data.${i.path.join('.')}: ${i.message}`),
66
+ errors: dataResult.error.issues.map((i) => `data.${i.path.map(String).join('.')}: ${i.message}`),
67
67
  };
68
68
  }
69
69
  const data = {
@@ -89,7 +89,7 @@ export function createCliOutput(options) {
89
89
  if (!dataResult.success) {
90
90
  return {
91
91
  success: false,
92
- errors: dataResult.error.issues.map((i) => `data.${i.path.join('.')}: ${i.message}`),
92
+ errors: dataResult.error.issues.map((i) => `data.${i.path.map(String).join('.')}: ${i.message}`),
93
93
  };
94
94
  }
95
95
  const output = {
@@ -1 +1 @@
1
- {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/surface/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAsCvB,+DAA+D;AAC/D,cAAc;AACd,+DAA+D;AAE/D,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC5B,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AAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzD,CAAA;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,OAK/B;IACC,MAAM,UAAU,GAAG,mBAAmB,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAE9D,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;SACrF,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAAmB;QAC7B,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/D,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;KAChE,CAAA;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AAClC,CAAC","sourcesContent":["/**\n * Typed Output Factories\n *\n * Typed wrappers for BaseSurfaceOutput.data.\n * These do NOT modify @pwfabric/contracts. They extend the contract types\n * with narrowed data fields and provide factory functions that validate.\n *\n * @module @pwfabric/runtime/surface/output\n */\n\nimport { z } from 'zod'\nimport type { WebSurfaceOutput, ApiSurfaceOutput, CliSurfaceOutput } from '@pwfabric/contracts'\n\n// ============================================================\n// TYPED OUTPUT INTERFACES\n// ============================================================\n\n/**\n * Web output with narrowed data type\n */\nexport interface TypedWebOutput extends WebSurfaceOutput {\n readonly data: {\n readonly html: string\n readonly css?: string\n readonly head?: string\n }\n}\n\n/**\n * API output with narrowed data type\n */\nexport interface TypedApiOutput extends ApiSurfaceOutput {\n readonly data: {\n readonly json: unknown\n readonly status: number\n }\n}\n\n/**\n * CLI output with narrowed data type\n */\nexport interface TypedCliOutput extends CliSurfaceOutput {\n readonly data: {\n readonly formatted: string\n readonly raw?: unknown\n }\n}\n\n// ============================================================\n// ZOD SCHEMAS\n// ============================================================\n\nconst webOutputDataSchema = z.object({\n html: z.string(),\n css: z.string().optional(),\n head: z.string().optional(),\n})\n\nconst apiOutputDataSchema = z.object({\n json: z.unknown(),\n status: z.number().int().min(100).max(599),\n})\n\nconst cliOutputDataSchema = z.object({\n formatted: z.string(),\n raw: z.unknown().optional(),\n})\n\n// ============================================================\n// VALIDATION RESULT\n// ============================================================\n\n/**\n * Result of creating a typed output\n */\nexport type OutputFactoryResult<T> =\n | { readonly success: true; readonly output: T }\n | { readonly success: false; readonly errors: readonly string[] }\n\n// ============================================================\n// FACTORY FUNCTIONS\n// ============================================================\n\n/**\n * Create a validated TypedWebOutput.\n *\n * Validates the data shape and returns a typed output or errors.\n */\nexport function createWebOutput(options: {\n readonly data: { readonly html: string; readonly css?: string; readonly head?: string }\n readonly component?: unknown\n readonly html?: string\n}): OutputFactoryResult<TypedWebOutput> {\n const dataResult = webOutputDataSchema.safeParse(options.data)\n\n if (!dataResult.success) {\n return {\n success: false,\n errors: dataResult.error.issues.map((i) => `data.${i.path.join('.')}: ${i.message}`),\n }\n }\n\n const data: TypedWebOutput['data'] = {\n html: dataResult.data.html,\n ...(dataResult.data.css !== undefined ? { css: dataResult.data.css } : {}),\n ...(dataResult.data.head !== undefined ? { head: dataResult.data.head } : {}),\n }\n\n const output: TypedWebOutput = {\n type: 'web',\n data,\n ...(options.component !== undefined ? { component: options.component } : {}),\n ...(options.html !== undefined ? { html: options.html } : {}),\n }\n\n return { success: true, output }\n}\n\n/**\n * Create a validated TypedApiOutput.\n *\n * Validates the data shape and returns a typed output or errors.\n */\nexport function createApiOutput(options: {\n readonly data: { readonly json: unknown; readonly status: number }\n readonly status: number\n readonly headers?: Record<string, string>\n readonly body?: unknown\n}): OutputFactoryResult<TypedApiOutput> {\n const dataResult = apiOutputDataSchema.safeParse(options.data)\n\n if (!dataResult.success) {\n return {\n success: false,\n errors: dataResult.error.issues.map((i) => `data.${i.path.join('.')}: ${i.message}`),\n }\n }\n\n const data: TypedApiOutput['data'] = {\n json: dataResult.data.json,\n status: dataResult.data.status,\n }\n\n const output: TypedApiOutput = {\n type: 'api',\n data,\n status: options.status,\n body: options.body ?? null,\n ...(options.headers ? { headers: options.headers } : {}),\n }\n\n return { success: true, output }\n}\n\n/**\n * Create a validated TypedCliOutput.\n *\n * Validates the data shape and returns a typed output or errors.\n */\nexport function createCliOutput(options: {\n readonly data: { readonly formatted: string; readonly raw?: unknown }\n readonly exitCode: number\n readonly stdout?: string\n readonly stderr?: string\n}): OutputFactoryResult<TypedCliOutput> {\n const dataResult = cliOutputDataSchema.safeParse(options.data)\n\n if (!dataResult.success) {\n return {\n success: false,\n errors: dataResult.error.issues.map((i) => `data.${i.path.join('.')}: ${i.message}`),\n }\n }\n\n const output: TypedCliOutput = {\n type: 'cli',\n data: dataResult.data,\n exitCode: options.exitCode,\n ...(options.stdout !== undefined && { stdout: options.stdout }),\n ...(options.stderr !== undefined && { stderr: options.stderr }),\n }\n\n return { success: true, output }\n}\n"]}
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/surface/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAsCvB,+DAA+D;AAC/D,cAAc;AACd,+DAA+D;AAE/D,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;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EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AAClC,CAAC","sourcesContent":["/**\n * Typed Output Factories\n *\n * Typed wrappers for BaseSurfaceOutput.data.\n * These do NOT modify @pwfabric/contracts. They extend the contract types\n * with narrowed data fields and provide factory functions that validate.\n *\n * @module @pwfabric/runtime/surface/output\n */\n\nimport { z } from 'zod'\nimport type { WebSurfaceOutput, ApiSurfaceOutput, CliSurfaceOutput } from '@pwfabric/contracts'\n\n// ============================================================\n// TYPED OUTPUT INTERFACES\n// ============================================================\n\n/**\n * Web output with narrowed data type\n */\nexport interface TypedWebOutput extends WebSurfaceOutput {\n readonly data: {\n readonly html: string\n readonly css?: string\n readonly head?: string\n }\n}\n\n/**\n * API output with narrowed data type\n */\nexport interface TypedApiOutput extends ApiSurfaceOutput {\n readonly data: {\n readonly json: unknown\n readonly status: number\n }\n}\n\n/**\n * CLI output with narrowed data type\n */\nexport interface TypedCliOutput extends CliSurfaceOutput {\n readonly data: {\n readonly formatted: string\n readonly raw?: unknown\n }\n}\n\n// ============================================================\n// ZOD SCHEMAS\n// ============================================================\n\nconst webOutputDataSchema = z.object({\n html: z.string(),\n css: z.string().optional(),\n head: z.string().optional(),\n})\n\nconst apiOutputDataSchema = z.object({\n json: z.unknown().optional(),\n status: z.number().int().min(100).max(599),\n})\n\nconst cliOutputDataSchema = z.object({\n formatted: z.string(),\n raw: z.unknown().optional(),\n})\n\n// ============================================================\n// VALIDATION RESULT\n// ============================================================\n\n/**\n * Result of creating a typed output\n */\nexport type OutputFactoryResult<T> =\n | { readonly success: true; readonly output: T }\n | { readonly success: false; readonly errors: readonly string[] }\n\n// ============================================================\n// FACTORY FUNCTIONS\n// ============================================================\n\n/**\n * Create a validated TypedWebOutput.\n *\n * Validates the data shape and returns a typed output or errors.\n */\nexport function createWebOutput(options: {\n readonly data: { readonly html: string; readonly css?: string; readonly head?: string }\n readonly component?: unknown\n readonly html?: string\n}): OutputFactoryResult<TypedWebOutput> {\n const dataResult = webOutputDataSchema.safeParse(options.data)\n\n if (!dataResult.success) {\n return {\n success: false,\n errors: dataResult.error.issues.map((i) => `data.${i.path.map(String).join('.')}: ${i.message}`),\n }\n }\n\n const data: TypedWebOutput['data'] = {\n html: dataResult.data.html,\n ...(dataResult.data.css !== undefined ? { css: dataResult.data.css } : {}),\n ...(dataResult.data.head !== undefined ? { head: dataResult.data.head } : {}),\n }\n\n const output: TypedWebOutput = {\n type: 'web',\n data,\n ...(options.component !== undefined ? { component: options.component } : {}),\n ...(options.html !== undefined ? { html: options.html } : {}),\n }\n\n return { success: true, output }\n}\n\n/**\n * Create a validated TypedApiOutput.\n *\n * Validates the data shape and returns a typed output or errors.\n */\nexport function createApiOutput(options: {\n readonly data: { readonly json: unknown; readonly status: number }\n readonly status: number\n readonly headers?: Record<string, string>\n readonly body?: unknown\n}): OutputFactoryResult<TypedApiOutput> {\n const dataResult = apiOutputDataSchema.safeParse(options.data)\n\n if (!dataResult.success) {\n return {\n success: false,\n errors: dataResult.error.issues.map((i) => `data.${i.path.map(String).join('.')}: ${i.message}`),\n }\n }\n\n const data: TypedApiOutput['data'] = {\n json: dataResult.data.json,\n status: dataResult.data.status,\n }\n\n const output: TypedApiOutput = {\n type: 'api',\n data,\n status: options.status,\n body: options.body ?? null,\n ...(options.headers ? { headers: options.headers } : {}),\n }\n\n return { success: true, output }\n}\n\n/**\n * Create a validated TypedCliOutput.\n *\n * Validates the data shape and returns a typed output or errors.\n */\nexport function createCliOutput(options: {\n readonly data: { readonly formatted: string; readonly raw?: unknown }\n readonly exitCode: number\n readonly stdout?: string\n readonly stderr?: string\n}): OutputFactoryResult<TypedCliOutput> {\n const dataResult = cliOutputDataSchema.safeParse(options.data)\n\n if (!dataResult.success) {\n return {\n success: false,\n errors: dataResult.error.issues.map((i) => `data.${i.path.map(String).join('.')}: ${i.message}`),\n }\n }\n\n const output: TypedCliOutput = {\n type: 'cli',\n data: dataResult.data,\n exitCode: options.exitCode,\n ...(options.stdout !== undefined && { stdout: options.stdout }),\n ...(options.stderr !== undefined && { stderr: options.stderr }),\n }\n\n return { success: true, output }\n}\n"]}
@@ -14,7 +14,16 @@ import type { SurfaceJSON, LayoutJSON, BindingJSON } from './types.js';
14
14
  /**
15
15
  * Valid environment types for surfaces
16
16
  */
17
- export declare const environmentSchema: z.ZodEnum<["web", "api", "cli", "worker", "edge", "node", "native", "test"]>;
17
+ export declare const environmentSchema: z.ZodEnum<{
18
+ web: "web";
19
+ api: "api";
20
+ cli: "cli";
21
+ worker: "worker";
22
+ edge: "edge";
23
+ node: "node";
24
+ native: "native";
25
+ test: "test";
26
+ }>;
18
27
  /**
19
28
  * Zod schema for BindingJSON
20
29
  *
@@ -29,28 +38,8 @@ export declare const bindingJsonSchema: z.ZodObject<{
29
38
  transform: z.ZodOptional<z.ZodObject<{
30
39
  input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
31
40
  output: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
32
- }, "strip", z.ZodTypeAny, {
33
- input?: Record<string, unknown> | undefined;
34
- output?: Record<string, unknown> | undefined;
35
- }, {
36
- input?: Record<string, unknown> | undefined;
37
- output?: Record<string, unknown> | undefined;
38
- }>>;
39
- }, "strip", z.ZodTypeAny, {
40
- capability: string;
41
- alias?: string | undefined;
42
- transform?: {
43
- input?: Record<string, unknown> | undefined;
44
- output?: Record<string, unknown> | undefined;
45
- } | undefined;
46
- }, {
47
- capability: string;
48
- alias?: string | undefined;
49
- transform?: {
50
- input?: Record<string, unknown> | undefined;
51
- output?: Record<string, unknown> | undefined;
52
- } | undefined;
53
- }>;
41
+ }, z.core.$strip>>;
42
+ }, z.core.$strip>;
54
43
  /**
55
44
  * Zod schema for LayoutJSON
56
45
  *
@@ -79,88 +68,31 @@ export declare const surfaceJsonSchema: z.ZodObject<{
79
68
  $schema: z.ZodOptional<z.ZodString>;
80
69
  id: z.ZodString;
81
70
  version: z.ZodString;
82
- environment: z.ZodEnum<["web", "api", "cli", "worker", "edge", "node", "native", "test"]>;
71
+ environment: z.ZodEnum<{
72
+ web: "web";
73
+ api: "api";
74
+ cli: "cli";
75
+ worker: "worker";
76
+ edge: "edge";
77
+ node: "node";
78
+ native: "native";
79
+ test: "test";
80
+ }>;
83
81
  metadata: z.ZodOptional<z.ZodObject<{
84
82
  name: z.ZodOptional<z.ZodString>;
85
83
  description: z.ZodOptional<z.ZodString>;
86
- tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
87
- }, "strip", z.ZodTypeAny, {
88
- description?: string | undefined;
89
- name?: string | undefined;
90
- tags?: string[] | undefined;
91
- }, {
92
- description?: string | undefined;
93
- name?: string | undefined;
94
- tags?: string[] | undefined;
95
- }>>;
84
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
85
+ }, z.core.$strip>>;
96
86
  bindings: z.ZodOptional<z.ZodArray<z.ZodObject<{
97
87
  capability: z.ZodString;
98
88
  alias: z.ZodOptional<z.ZodString>;
99
89
  transform: z.ZodOptional<z.ZodObject<{
100
90
  input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
101
91
  output: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
102
- }, "strip", z.ZodTypeAny, {
103
- input?: Record<string, unknown> | undefined;
104
- output?: Record<string, unknown> | undefined;
105
- }, {
106
- input?: Record<string, unknown> | undefined;
107
- output?: Record<string, unknown> | undefined;
108
- }>>;
109
- }, "strip", z.ZodTypeAny, {
110
- capability: string;
111
- alias?: string | undefined;
112
- transform?: {
113
- input?: Record<string, unknown> | undefined;
114
- output?: Record<string, unknown> | undefined;
115
- } | undefined;
116
- }, {
117
- capability: string;
118
- alias?: string | undefined;
119
- transform?: {
120
- input?: Record<string, unknown> | undefined;
121
- output?: Record<string, unknown> | undefined;
122
- } | undefined;
123
- }>, "many">>;
124
- layout: z.ZodType<any, z.ZodTypeDef, any>;
125
- }, "strip", z.ZodTypeAny, {
126
- id: string;
127
- version: string;
128
- environment: "web" | "api" | "cli" | "worker" | "edge" | "node" | "native" | "test";
129
- metadata?: {
130
- description?: string | undefined;
131
- name?: string | undefined;
132
- tags?: string[] | undefined;
133
- } | undefined;
134
- $schema?: string | undefined;
135
- bindings?: {
136
- capability: string;
137
- alias?: string | undefined;
138
- transform?: {
139
- input?: Record<string, unknown> | undefined;
140
- output?: Record<string, unknown> | undefined;
141
- } | undefined;
142
- }[] | undefined;
143
- layout?: any;
144
- }, {
145
- id: string;
146
- version: string;
147
- environment: "web" | "api" | "cli" | "worker" | "edge" | "node" | "native" | "test";
148
- metadata?: {
149
- description?: string | undefined;
150
- name?: string | undefined;
151
- tags?: string[] | undefined;
152
- } | undefined;
153
- $schema?: string | undefined;
154
- bindings?: {
155
- capability: string;
156
- alias?: string | undefined;
157
- transform?: {
158
- input?: Record<string, unknown> | undefined;
159
- output?: Record<string, unknown> | undefined;
160
- } | undefined;
161
- }[] | undefined;
162
- layout?: any;
163
- }>;
92
+ }, z.core.$strip>>;
93
+ }, z.core.$strip>>>;
94
+ layout: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
95
+ }, z.core.$strip>;
164
96
  /**
165
97
  * Type guard for SurfaceJSON
166
98
  *
@@ -42,8 +42,8 @@ export const bindingJsonSchema = z.object({
42
42
  alias: z.string().optional(),
43
43
  transform: z
44
44
  .object({
45
- input: z.record(z.unknown()).optional(),
46
- output: z.record(z.unknown()).optional(),
45
+ input: z.record(z.string(), z.unknown()).optional(),
46
+ output: z.record(z.string(), z.unknown()).optional(),
47
47
  })
48
48
  .optional(),
49
49
  });
@@ -66,7 +66,7 @@ export const bindingJsonSchema = z.object({
66
66
  // schema variable to exist at the point of self-reference in children.
67
67
  export const layoutJsonSchema = z.lazy(() => z.object({
68
68
  type: z.string().min(1, 'Layout must have a type'),
69
- props: z.record(z.unknown()).optional(),
69
+ props: z.record(z.string(), z.unknown()).optional(),
70
70
  children: z.array(layoutJsonSchema).optional(),
71
71
  slot: z.string().optional(),
72
72
  if: z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,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,oCAAoC,CAAC;IAChE,WAAW,EAAE,iBAAiB;IAC9B,QAAQ,EAAE,cAAc;IACxB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAAE;IAC/C,MAAM,EAAE,gBAAgB;CACzB,CAAC,CAAA;AAEF,+DAA+D;AAC/D,cAAc;AACd,+DAA+D;AAE/D;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAa;IACzC,OAAO,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAA;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAa;IACxC,OAAO,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAA;AACjD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAa;IACzC,OAAO,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAA;AAClD,CAAC","sourcesContent":["/**\n * Surface JSON Zod Schemas\n *\n * Zod validation schemas for Surface JSON definitions\n *\n * Provides schema-based validation to replace manual string-based\n * validation in the interpreter. Ensures SurfaceJSON, LayoutJSON,\n * and BindingJSON conform to their TypeScript interfaces.\n *\n * @module @pwfabric/runtime/surface/schemas\n */\n\nimport { z } from 'zod'\nimport type { SurfaceJSON, LayoutJSON, BindingJSON } from './types.js'\n\n// ============================================================\n// ENVIRONMENT SCHEMA\n// ============================================================\n\n/**\n * Valid environment types for surfaces\n */\nexport const environmentSchema = z.enum([\n 'web',\n 'api',\n 'cli',\n 'worker',\n 'edge',\n 'node',\n 'native',\n 'test',\n])\n\n// ============================================================\n// BINDING JSON SCHEMA\n// ============================================================\n\n/**\n * Zod schema for BindingJSON\n *\n * Validates capability bindings in surface definitions.\n * - capability: required string identifying the capability\n * - alias: optional string alias for the binding\n * - transform: optional input/output transform configuration\n */\nexport const bindingJsonSchema = z.object({\n capability: z.string().min(1, 'Binding capability must be a non-empty string'),\n alias: z.string().optional(),\n transform: z\n .object({\n input: z.record(z.unknown()).optional(),\n output: z.record(z.unknown()).optional(),\n })\n .optional(),\n})\n\n// ============================================================\n// LAYOUT JSON SCHEMA (RECURSIVE)\n// ============================================================\n\n/**\n * Zod schema for LayoutJSON\n *\n * Uses z.lazy() for recursive children validation.\n * - type: required string identifying the layout element type\n * - props: optional record of properties\n * - children: optional array of nested LayoutJSON (recursive)\n * - slot: optional named slot reference\n * - if: optional conditional expression\n * - each: optional loop configuration (items, as, key)\n */\n// Recursive schema uses z.lazy() with a forward-declared type variable.\n// The explicit ZodType cast is required because z.lazy() needs the\n// schema variable to exist at the point of self-reference in children.\nexport const layoutJsonSchema: z.ZodType = z.lazy(() =>\n z.object({\n type: z.string().min(1, 'Layout must have a type'),\n props: z.record(z.unknown()).optional(),\n children: z.array(layoutJsonSchema).optional(),\n slot: z.string().optional(),\n if: z.string().optional(),\n each: z\n .object({\n items: z.string().min(1, 'Loop layout must have items expression'),\n as: z.string().min(1, 'Loop layout must have as variable name'),\n key: z.string().optional(),\n })\n .optional(),\n })\n)\n\n// ============================================================\n// SURFACE JSON SCHEMA\n// ============================================================\n\n/**\n * Metadata schema for surface definitions\n */\nconst metadataSchema = z\n .object({\n name: z.string().optional(),\n description: z.string().optional(),\n tags: z.array(z.string()).optional(),\n })\n .optional()\n\n/**\n * Zod schema for SurfaceJSON\n *\n * Validates the top-level surface definition structure.\n * - id: required non-empty string\n * - version: required non-empty string (semver)\n * - environment: required enum of valid environment types\n * - $schema: optional schema reference\n * - metadata: optional name, description, tags\n * - bindings: optional array of capability bindings\n * - layout: required recursive layout definition\n */\nexport const surfaceJsonSchema = z.object({\n $schema: z.string().optional(),\n id: z.string().min(1, 'Surface must have a string id'),\n version: z.string().min(1, 'Surface must have a string version'),\n environment: environmentSchema,\n metadata: metadataSchema,\n bindings: z.array(bindingJsonSchema).optional(),\n layout: layoutJsonSchema,\n})\n\n// ============================================================\n// TYPE GUARDS\n// ============================================================\n\n/**\n * Type guard for SurfaceJSON\n *\n * Returns true if the provided data conforms to the SurfaceJSON schema.\n */\nexport function isSurfaceJSON(data: unknown): data is SurfaceJSON {\n return surfaceJsonSchema.safeParse(data).success\n}\n\n/**\n * Type guard for LayoutJSON\n *\n * Returns true if the provided data conforms to the LayoutJSON schema.\n */\nexport function isLayoutJSON(data: unknown): data is LayoutJSON {\n return layoutJsonSchema.safeParse(data).success\n}\n\n/**\n * Type guard for BindingJSON\n *\n * Returns true if the provided data conforms to the BindingJSON schema.\n */\nexport function isBindingJSON(data: unknown): data is BindingJSON {\n return bindingJsonSchema.safeParse(data).success\n}\n"]}
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/surface/schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,+DAA+D;AAC/D,qBAAqB;AACrB,+DAA+D;AAE/D;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,IAAI,CAAC;IACtC,KAAK;IACL,KAAK;IACL,KAAK;IACL,QAAQ;IACR,MAAM;IACN,MAAM;IACN,QAAQ;IACR,MAAM;CACP,CAAC,CAAA;AAEF,+DAA+D;AAC/D,sBAAsB;AACtB,+DAA+D;AAE/D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,+CAA+C,CAAC;IAC9E,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,SAAS,EAAE,CAAC;SACT,MAAM,CAAC;QACN,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,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JSON Zod Schemas\n *\n * Zod validation schemas for Surface JSON definitions\n *\n * Provides schema-based validation to replace manual string-based\n * validation in the interpreter. Ensures SurfaceJSON, LayoutJSON,\n * and BindingJSON conform to their TypeScript interfaces.\n *\n * @module @pwfabric/runtime/surface/schemas\n */\n\nimport { z } from 'zod'\nimport type { SurfaceJSON, LayoutJSON, BindingJSON } from './types.js'\n\n// ============================================================\n// ENVIRONMENT SCHEMA\n// ============================================================\n\n/**\n * Valid environment types for surfaces\n */\nexport const environmentSchema = z.enum([\n 'web',\n 'api',\n 'cli',\n 'worker',\n 'edge',\n 'node',\n 'native',\n 'test',\n])\n\n// ============================================================\n// BINDING JSON SCHEMA\n// ============================================================\n\n/**\n * Zod schema for BindingJSON\n *\n * Validates capability bindings in surface definitions.\n * - capability: required string identifying the capability\n * - alias: optional string alias for the binding\n * - transform: optional input/output transform configuration\n */\nexport const bindingJsonSchema = z.object({\n capability: z.string().min(1, 'Binding capability must be a non-empty string'),\n alias: z.string().optional(),\n transform: z\n .object({\n input: z.record(z.string(), z.unknown()).optional(),\n output: z.record(z.string(), z.unknown()).optional(),\n })\n .optional(),\n})\n\n// ============================================================\n// LAYOUT JSON SCHEMA (RECURSIVE)\n// ============================================================\n\n/**\n * Zod schema for LayoutJSON\n *\n * Uses z.lazy() for recursive children validation.\n * - type: required string identifying the layout element type\n * - props: optional record of properties\n * - children: optional array of nested LayoutJSON (recursive)\n * - slot: optional named slot reference\n * - if: optional conditional expression\n * - each: optional loop configuration (items, as, key)\n */\n// Recursive schema uses z.lazy() with a forward-declared type variable.\n// The explicit ZodType cast is required because z.lazy() needs the\n// schema variable to exist at the point of self-reference in children.\nexport const layoutJsonSchema: z.ZodType = z.lazy(() =>\n z.object({\n type: z.string().min(1, 'Layout must have a type'),\n props: z.record(z.string(), z.unknown()).optional(),\n children: z.array(layoutJsonSchema).optional(),\n slot: z.string().optional(),\n if: z.string().optional(),\n each: z\n .object({\n items: z.string().min(1, 'Loop layout must have items expression'),\n as: z.string().min(1, 'Loop layout must have as variable name'),\n key: z.string().optional(),\n })\n .optional(),\n })\n)\n\n// ============================================================\n// SURFACE JSON SCHEMA\n// ============================================================\n\n/**\n * Metadata schema for surface definitions\n */\nconst metadataSchema = z\n .object({\n name: z.string().optional(),\n description: z.string().optional(),\n tags: z.array(z.string()).optional(),\n })\n .optional()\n\n/**\n * Zod schema for SurfaceJSON\n *\n * Validates the top-level surface definition structure.\n * - id: required non-empty string\n * - version: required non-empty string (semver)\n * - environment: required enum of valid environment types\n * - $schema: optional schema reference\n * - metadata: optional name, description, tags\n * - bindings: optional array of capability bindings\n * - layout: required recursive layout definition\n */\nexport const surfaceJsonSchema = z.object({\n $schema: z.string().optional(),\n id: z.string().min(1, 'Surface must have a string id'),\n version: z.string().min(1, 'Surface must have a string version'),\n environment: environmentSchema,\n metadata: metadataSchema,\n bindings: z.array(bindingJsonSchema).optional(),\n layout: layoutJsonSchema,\n})\n\n// ============================================================\n// TYPE GUARDS\n// ============================================================\n\n/**\n * Type guard for SurfaceJSON\n *\n * Returns true if the provided data conforms to the SurfaceJSON schema.\n */\nexport function isSurfaceJSON(data: unknown): data is SurfaceJSON {\n return surfaceJsonSchema.safeParse(data).success\n}\n\n/**\n * Type guard for LayoutJSON\n *\n * Returns true if the provided data conforms to the LayoutJSON schema.\n */\nexport function isLayoutJSON(data: unknown): data is LayoutJSON {\n return layoutJsonSchema.safeParse(data).success\n}\n\n/**\n * Type guard for BindingJSON\n *\n * Returns true if the provided data conforms to the BindingJSON schema.\n */\nexport function isBindingJSON(data: unknown): data is BindingJSON {\n return bindingJsonSchema.safeParse(data).success\n}\n"]}
@@ -64,47 +64,21 @@ export type TypedTransformConfig = {
64
64
  export declare const mapTransformConfigSchema: z.ZodObject<{
65
65
  field: z.ZodString;
66
66
  mapper: z.ZodString;
67
- }, "strip", z.ZodTypeAny, {
68
- field: string;
69
- mapper: string;
70
- }, {
71
- field: string;
72
- mapper: string;
73
- }>;
67
+ }, z.core.$strip>;
74
68
  export declare const filterTransformConfigSchema: z.ZodObject<{
75
69
  field: z.ZodString;
76
70
  predicate: z.ZodString;
77
- }, "strip", z.ZodTypeAny, {
78
- field: string;
79
- predicate: string;
80
- }, {
81
- field: string;
82
- predicate: string;
83
- }>;
71
+ }, z.core.$strip>;
84
72
  export declare const pickTransformConfigSchema: z.ZodObject<{
85
- fields: z.ZodArray<z.ZodString, "many">;
86
- }, "strip", z.ZodTypeAny, {
87
- fields: string[];
88
- }, {
89
- fields: string[];
90
- }>;
73
+ fields: z.ZodArray<z.ZodString>;
74
+ }, z.core.$strip>;
91
75
  export declare const omitTransformConfigSchema: z.ZodObject<{
92
- fields: z.ZodArray<z.ZodString, "many">;
93
- }, "strip", z.ZodTypeAny, {
94
- fields: string[];
95
- }, {
96
- fields: string[];
97
- }>;
76
+ fields: z.ZodArray<z.ZodString>;
77
+ }, z.core.$strip>;
98
78
  export declare const customTransformConfigSchema: z.ZodObject<{
99
79
  handler: z.ZodString;
100
80
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
101
- }, "strip", z.ZodTypeAny, {
102
- handler: string;
103
- params?: Record<string, unknown> | undefined;
104
- }, {
105
- handler: string;
106
- params?: Record<string, unknown> | undefined;
107
- }>;
81
+ }, z.core.$strip>;
108
82
  /**
109
83
  * Result of validating a transform config
110
84
  */
@@ -27,7 +27,7 @@ export const omitTransformConfigSchema = z.object({
27
27
  });
28
28
  export const customTransformConfigSchema = z.object({
29
29
  handler: z.string().min(1),
30
- params: z.record(z.unknown()).optional(),
30
+ params: z.record(z.string(), z.unknown()).optional(),
31
31
  });
32
32
  /**
33
33
  * Map of transform types to their Zod schemas
@@ -54,7 +54,7 @@ export function validateTransformConfig(type, config) {
54
54
  }
55
55
  return {
56
56
  valid: false,
57
- errors: result.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`),
57
+ errors: result.error.issues.map((i) => `${i.path.map(String).join('.')}: ${i.message}`),
58
58
  };
59
59
  }
60
60
  // ============================================================
@@ -1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C,MAA6B;IACjE,MAAM,MAAM,GAAG,2BAA2B,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACxD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;AAC3C,CAAC","sourcesContent":["/**\n * Typed Transform Wrappers\n *\n * Typed runtime wrappers for TransformDescriptor.config.\n * These do NOT modify @pwfabric/contracts. They provide typed alternatives\n * that narrow the opaque Record<string, unknown> config.\n *\n * @module @pwfabric/runtime/surface/transforms\n */\n\nimport { z } from 'zod'\nimport type { TransformDescriptor } from '@pwfabric/contracts'\n\n// ============================================================\n// TYPED TRANSFORM CONFIG INTERFACES\n// ============================================================\n\n/**\n * Config for 'map' transforms\n */\nexport interface MapTransformConfig {\n readonly field: string\n readonly mapper: string\n}\n\n/**\n * Config for 'filter' transforms\n */\nexport interface FilterTransformConfig {\n readonly field: string\n readonly predicate: string\n}\n\n/**\n * Config for 'pick' transforms\n */\nexport interface PickTransformConfig {\n readonly fields: readonly string[]\n}\n\n/**\n * Config for 'omit' transforms\n */\nexport interface OmitTransformConfig {\n readonly fields: readonly string[]\n}\n\n/**\n * Config for 'custom' transforms\n */\nexport interface CustomTransformConfig {\n readonly handler: string\n readonly params?: Record<string, unknown>\n}\n\n/**\n * Discriminated union of all typed transform configs\n */\nexport type TypedTransformConfig =\n | { readonly type: 'map'; readonly config: MapTransformConfig }\n | { readonly type: 'filter'; readonly config: FilterTransformConfig }\n | { readonly type: 'pick'; readonly config: PickTransformConfig }\n | { readonly type: 'omit'; readonly config: OmitTransformConfig }\n | { readonly type: 'custom'; readonly config: CustomTransformConfig }\n\n// ============================================================\n// ZOD SCHEMAS\n// ============================================================\n\nexport const mapTransformConfigSchema = z.object({\n field: z.string().min(1),\n mapper: z.string().min(1),\n})\n\nexport const filterTransformConfigSchema = z.object({\n field: z.string().min(1),\n predicate: z.string().min(1),\n})\n\nexport const pickTransformConfigSchema = z.object({\n fields: z.array(z.string().min(1)).min(1),\n})\n\nexport const omitTransformConfigSchema = z.object({\n fields: z.array(z.string().min(1)).min(1),\n})\n\nexport const customTransformConfigSchema = z.object({\n handler: z.string().min(1),\n params: z.record(z.unknown()).optional(),\n})\n\n/**\n * Map of transform types to their Zod schemas\n */\nconst transformConfigSchemas = {\n map: mapTransformConfigSchema,\n filter: filterTransformConfigSchema,\n pick: pickTransformConfigSchema,\n omit: omitTransformConfigSchema,\n custom: customTransformConfigSchema,\n} as const\n\n// ============================================================\n// VALIDATION TYPES\n// ============================================================\n\n/**\n * Result of validating a transform config\n */\nexport interface TransformValidationResult {\n readonly valid: boolean\n readonly errors: readonly string[]\n}\n\n// ============================================================\n// VALIDATION FUNCTION\n// ============================================================\n\n/**\n * Validate a transform descriptor's config against the typed schema\n * for the given transform type.\n */\nexport function validateTransformConfig(\n type: TransformDescriptor['type'],\n config: Record<string, unknown>\n): TransformValidationResult {\n const schema = transformConfigSchemas[type]\n\n const result = schema.safeParse(config)\n\n if (result.success) {\n return { valid: true, errors: [] }\n }\n\n return {\n valid: false,\n errors: result.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`),\n }\n}\n\n// ============================================================\n// TYPE GUARD\n// ============================================================\n\n/**\n * Type guard that narrows an opaque TransformDescriptor into\n * a TypedTransformConfig if the config passes validation.\n */\nexport function narrowTransformDescriptor(\n descriptor: TransformDescriptor\n): TypedTransformConfig | null {\n if (!descriptor.config) {\n return null\n }\n\n const schema = transformConfigSchemas[descriptor.type]\n const result = schema.safeParse(descriptor.config)\n\n if (!result.success) {\n return null\n }\n\n // The type assertion is safe because Zod validated the config shape\n return {\n type: descriptor.type,\n config: result.data,\n } as TypedTransformConfig\n}\n\n// ============================================================\n// FACTORY FUNCTIONS\n// ============================================================\n\n/**\n * Create a typed 'map' transform descriptor\n */\nexport function createMapTransform(config: MapTransformConfig): TransformDescriptor {\n const parsed = mapTransformConfigSchema.parse(config)\n return { type: 'map', config: parsed }\n}\n\n/**\n * Create a typed 'filter' transform descriptor\n */\nexport function createFilterTransform(config: FilterTransformConfig): TransformDescriptor {\n const parsed = filterTransformConfigSchema.parse(config)\n return { type: 'filter', config: parsed }\n}\n\n/**\n * Create a typed 'pick' transform descriptor\n */\nexport function createPickTransform(config: PickTransformConfig): TransformDescriptor {\n const parsed = pickTransformConfigSchema.parse(config)\n return { type: 'pick', config: { ...parsed, fields: [...parsed.fields] } }\n}\n\n/**\n * Create a typed 'omit' transform descriptor\n */\nexport function createOmitTransform(config: OmitTransformConfig): TransformDescriptor {\n const parsed = omitTransformConfigSchema.parse(config)\n return { type: 'omit', config: { ...parsed, fields: [...parsed.fields] } }\n}\n\n/**\n * Create a typed 'custom' transform descriptor\n */\nexport function createCustomTransform(config: CustomTransformConfig): TransformDescriptor {\n const parsed = customTransformConfigSchema.parse(config)\n return { type: 'custom', config: parsed }\n}\n"]}
1
+ {"version":3,"file":"transforms.js","sourceRoot":"","sources":["../../src/surface/transforms.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAuDvB,+DAA+D;AAC/D,cAAc;AACd,+DAA+D;AAE/D,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC1B,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACxB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7B,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChD,MAAM,EAAE,C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AmB,CAAC,MAA2B;IAC7D,MAAM,MAAM,GAAG,yBAAyB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACtD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;AAC5E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAA2B;IAC7D,MAAM,MAAM,GAAG,yBAAyB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACtD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;AAC5E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAA6B;IACjE,MAAM,MAAM,GAAG,2BAA2B,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACxD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;AAC3C,CAAC","sourcesContent":["/**\n * Typed Transform Wrappers\n *\n * Typed runtime wrappers for TransformDescriptor.config.\n * These do NOT modify @pwfabric/contracts. They provide typed alternatives\n * that narrow the opaque Record<string, unknown> config.\n *\n * @module @pwfabric/runtime/surface/transforms\n */\n\nimport { z } from 'zod'\nimport type { TransformDescriptor } from '@pwfabric/contracts'\n\n// ============================================================\n// TYPED TRANSFORM CONFIG INTERFACES\n// ============================================================\n\n/**\n * Config for 'map' transforms\n */\nexport interface MapTransformConfig {\n readonly field: string\n readonly mapper: string\n}\n\n/**\n * Config for 'filter' transforms\n */\nexport interface FilterTransformConfig {\n readonly field: string\n readonly predicate: string\n}\n\n/**\n * Config for 'pick' transforms\n */\nexport interface PickTransformConfig {\n readonly fields: readonly string[]\n}\n\n/**\n * Config for 'omit' transforms\n */\nexport interface OmitTransformConfig {\n readonly fields: readonly string[]\n}\n\n/**\n * Config for 'custom' transforms\n */\nexport interface CustomTransformConfig {\n readonly handler: string\n readonly params?: Record<string, unknown>\n}\n\n/**\n * Discriminated union of all typed transform configs\n */\nexport type TypedTransformConfig =\n | { readonly type: 'map'; readonly config: MapTransformConfig }\n | { readonly type: 'filter'; readonly config: FilterTransformConfig }\n | { readonly type: 'pick'; readonly config: PickTransformConfig }\n | { readonly type: 'omit'; readonly config: OmitTransformConfig }\n | { readonly type: 'custom'; readonly config: CustomTransformConfig }\n\n// ============================================================\n// ZOD SCHEMAS\n// ============================================================\n\nexport const mapTransformConfigSchema = z.object({\n field: z.string().min(1),\n mapper: z.string().min(1),\n})\n\nexport const filterTransformConfigSchema = z.object({\n field: z.string().min(1),\n predicate: z.string().min(1),\n})\n\nexport const pickTransformConfigSchema = z.object({\n fields: z.array(z.string().min(1)).min(1),\n})\n\nexport const omitTransformConfigSchema = z.object({\n fields: z.array(z.string().min(1)).min(1),\n})\n\nexport const customTransformConfigSchema = z.object({\n handler: z.string().min(1),\n params: z.record(z.string(), z.unknown()).optional(),\n})\n\n/**\n * Map of transform types to their Zod schemas\n */\nconst transformConfigSchemas = {\n map: mapTransformConfigSchema,\n filter: filterTransformConfigSchema,\n pick: pickTransformConfigSchema,\n omit: omitTransformConfigSchema,\n custom: customTransformConfigSchema,\n} as const\n\n// ============================================================\n// VALIDATION TYPES\n// ============================================================\n\n/**\n * Result of validating a transform config\n */\nexport interface TransformValidationResult {\n readonly valid: boolean\n readonly errors: readonly string[]\n}\n\n// ============================================================\n// VALIDATION FUNCTION\n// ============================================================\n\n/**\n * Validate a transform descriptor's config against the typed schema\n * for the given transform type.\n */\nexport function validateTransformConfig(\n type: TransformDescriptor['type'],\n config: Record<string, unknown>\n): TransformValidationResult {\n const schema = transformConfigSchemas[type]\n\n const result = schema.safeParse(config)\n\n if (result.success) {\n return { valid: true, errors: [] }\n }\n\n return {\n valid: false,\n errors: result.error.issues.map((i) => `${i.path.map(String).join('.')}: ${i.message}`),\n }\n}\n\n// ============================================================\n// TYPE GUARD\n// ============================================================\n\n/**\n * Type guard that narrows an opaque TransformDescriptor into\n * a TypedTransformConfig if the config passes validation.\n */\nexport function narrowTransformDescriptor(\n descriptor: TransformDescriptor\n): TypedTransformConfig | null {\n if (!descriptor.config) {\n return null\n }\n\n const schema = transformConfigSchemas[descriptor.type]\n const result = schema.safeParse(descriptor.config)\n\n if (!result.success) {\n return null\n }\n\n // The type assertion is safe because Zod validated the config shape\n return {\n type: descriptor.type,\n config: result.data,\n } as TypedTransformConfig\n}\n\n// ============================================================\n// FACTORY FUNCTIONS\n// ============================================================\n\n/**\n * Create a typed 'map' transform descriptor\n */\nexport function createMapTransform(config: MapTransformConfig): TransformDescriptor {\n const parsed = mapTransformConfigSchema.parse(config)\n return { type: 'map', config: parsed }\n}\n\n/**\n * Create a typed 'filter' transform descriptor\n */\nexport function createFilterTransform(config: FilterTransformConfig): TransformDescriptor {\n const parsed = filterTransformConfigSchema.parse(config)\n return { type: 'filter', config: parsed }\n}\n\n/**\n * Create a typed 'pick' transform descriptor\n */\nexport function createPickTransform(config: PickTransformConfig): TransformDescriptor {\n const parsed = pickTransformConfigSchema.parse(config)\n return { type: 'pick', config: { ...parsed, fields: [...parsed.fields] } }\n}\n\n/**\n * Create a typed 'omit' transform descriptor\n */\nexport function createOmitTransform(config: OmitTransformConfig): TransformDescriptor {\n const parsed = omitTransformConfigSchema.parse(config)\n return { type: 'omit', config: { ...parsed, fields: [...parsed.fields] } }\n}\n\n/**\n * Create a typed 'custom' transform descriptor\n */\nexport function createCustomTransform(config: CustomTransformConfig): TransformDescriptor {\n const parsed = customTransformConfigSchema.parse(config)\n return { type: 'custom', config: parsed }\n}\n"]}
@@ -43,7 +43,7 @@ export function validateBlockProps(type, props, options = {}) {
43
43
  }
44
44
  return {
45
45
  valid: false,
46
- errors: result.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`),
46
+ errors: result.error.issues.map((i) => `${i.path.map(String).join('.')}: ${i.message}`),
47
47
  };
48
48
  }
49
49
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/surface/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA6CH,+DAA+D;AAC/D,uBAAuB;AACvB,+DAA+D;AAE/D;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,KAA8B,EAC9B,UAAuC,EAAE;IAEzC,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;IAE3C,MAAM,MAAM,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,CAAA;IAE9B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,IAAI,MAAM,EAAE,CAAC;YACX,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,MAAM,EAAE,CAAC,uBAAuB,IAAI,EAAE,CAAC;aACxC,CAAA;QACH,CAAC;QACD,wDAAwD;QACxD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;IACpC,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAEtC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO;YACL,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,MAAM,CAAC,IAA+B;SAChD,CAAA;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAC7B,CAAC,CAAiD,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAC3F;KACF,CAAA;AACH,CAAC;AAqBD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAk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I,CAAC;gBACP,IAAI;gBACJ,IAAI;gBACJ,IAAI;gBACJ,IAAI,EAAE,wBAAwB;gBAC9B,QAAQ,EAAE,SAAS;gBACnB,OAAO,EAAE,IAAI,IAAI,QAAQ,IAAI,iEAAiE;aAC/F,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAkB,EAClB,SAAgC,EAChC,IAAI,GAAG,MAAM;IAEb,MAAM,GAAG,GAAG,yBAAyB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;IAC9F,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YACnC,IAAI,KAAK;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC,CAAA;QAC1F,CAAC,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["/**\n * Block Props Validation\n *\n * Runtime validation of block props using injected Zod schemas.\n * the legacy `blockSchemas` map is gone — production\n * callers supply a schema map sourced from the install pipeline (per-atom\n * `manifest.definition.props[*].jsonSchema` rebuilt into Zod). Without a\n * schema map the validator runs in lenient mode and passes everything\n * through.\n *\n * @module @pwfabric/runtime/surface/validation\n */\n\nimport type { ZodSchema } from 'zod'\n\n/** Map of block type → Zod schema. Supply via options to enable strict checks. */\nexport type BlockSchemaMap = Readonly<Record<string, ZodSchema>>\n\n// ============================================================\n// VALIDATION TYPES\n// ============================================================\n\n/**\n * Options for block props validation\n */\nexport interface BlockPropsValidationOptions {\n /**\n * When true, unknown block types cause validation failure.\n * When false (default), unknown block types pass through.\n */\n readonly strict?: boolean\n /**\n * Per-block-type Zod schemas. the runtime no longer\n * ships a built-in schema map — callers that want prop validation\n * supply their own (typically rebuilt from\n * each installed block manifest's `definition.props[*].jsonSchema`).\n * Omitting the map yields lenient pass-through behaviour.\n */\n readonly schemas?: BlockSchemaMap\n /**\n * Per-block-type manifest props. When supplied, props a manifest\n * does not declare and templates on `bindable: false` props are reported as\n * WARNINGS (`manifestPropFindings`); they never fail validation.\n */\n readonly manifests?: BlockManifestPropsMap\n}\n\n/**\n * Result of validating block props against the schema\n */\nexport interface BlockPropsValidationResult {\n readonly valid: boolean\n readonly errors: readonly string[]\n readonly coerced?: Record<string, unknown>\n}\n\n// ============================================================\n// VALIDATION FUNCTIONS\n// ============================================================\n\n/**\n * Validate block props against the known Zod schema for the given block type.\n *\n * - Known block types are validated against the schema from @pwfabric/core.\n * - Unknown block types pass through in lenient mode (default) and fail in strict mode.\n * - On success, returns coerced data (with defaults applied by Zod).\n */\nexport function validateBlockProps(\n type: string,\n props: Record<string, unknown>,\n options: BlockPropsValidationOptions = {}\n): BlockPropsValidationResult {\n const { strict = false, schemas } = options\n\n const schema = schemas?.[type]\n\n if (!schema) {\n if (strict) {\n return {\n valid: false,\n errors: [`Unknown block type: ${type}`],\n }\n }\n // Lenient mode: unknown / unsupplied types pass through\n return { valid: true, errors: [] }\n }\n\n const result = schema.safeParse(props)\n\n if (result.success) {\n return {\n valid: true,\n errors: [],\n coerced: result.data as Record<string, unknown>,\n }\n }\n\n return {\n valid: false,\n errors: result.error.issues.map(\n (i: { path: (string | number)[]; message: string }) => `${i.path.join('.')}: ${i.message}`\n ),\n }\n}\n\n/**\n * Layout node shape for recursive validation.\n * Matches LayoutJSON structure without importing it to avoid circular deps.\n */\ninterface LayoutNode {\n readonly type: string\n readonly props?: Record<string, unknown>\n readonly children?: readonly LayoutNode[]\n}\n\n/**\n * A single validation issue with path context\n */\nexport interface LayoutPropsIssue {\n readonly path: string\n readonly type: string\n readonly errors: readonly string[]\n}\n\n/**\n * Validate all block props in a layout tree recursively.\n *\n * Returns a flat list of validation issues with path context.\n */\nexport function validateLayoutProps(\n layout: LayoutNode,\n options: BlockPropsValidationOptions = {},\n path = 'root'\n): readonly LayoutPropsIssue[] {\n const issues: LayoutPropsIssue[] = []\n\n const result = validateBlockProps(layout.type, layout.props ?? {}, options)\n if (!result.valid) {\n issues.push({\n path,\n type: layout.type,\n errors: result.errors,\n })\n }\n\n if (layout.children) {\n for (let i = 0; i < layout.children.length; i++) {\n const child = layout.children[i]\n if (child) {\n const childIssues = validateLayoutProps(child, options, `${path}.children[${i}]`)\n issues.push(...childIssues)\n }\n }\n }\n\n return issues\n}\n\n// ============================================================\n// PACK MANIFEST ENFORCEMENT\n// ============================================================\n\n/**\n * One prop a pack manifest declares: `manifest.definition.props[*]`. Only the\n * two fields the check reads; a full manifest entry passes as it is.\n */\nexport interface ManifestPropSpec {\n readonly name: string\n /** `false` = the prop takes a literal only; a `{{ }}` template is not resolved for it. */\n readonly bindable?: boolean\n}\n\n/** Block type → the props its manifest declares. */\nexport type BlockManifestPropsMap = Readonly<Record<string, readonly ManifestPropSpec[]>>\n\nexport type ManifestPropFindingCode = 'UNKNOWN_PROP' | 'TEMPLATE_ON_UNBINDABLE'\n\n/**\n * A prop that does not match its block's manifest. Always a WARNING:\n * existing apps carry such props and must keep rendering; a caller\n * decides whether to show, count or (later) refuse them.\n */\nexport interface ManifestPropFinding {\n readonly path: string\n readonly type: string\n readonly prop: string\n readonly code: ManifestPropFindingCode\n readonly severity: 'warning'\n readonly message: string\n}\n\nfunction carriesTemplate(value: unknown, depth = 0): boolean {\n if (depth > 8) return false\n if (typeof value === 'string') return value.includes('{{')\n if (Array.isArray(value)) return value.some((v) => carriesTemplate(v, depth + 1))\n if (value && typeof value === 'object') {\n return Object.values(value as Record<string, unknown>).some((v) => carriesTemplate(v, depth + 1))\n }\n return false\n}\n\n/**\n * The props of ONE block that its manifest does not allow.\n *\n * WHY: a prop the manifest does not declare was\n * accepted silently. The schema check rebuilds each prop's JSON schema into a\n * passthrough object, so a misspelt or invented prop (`tone` on a block that\n * has none, `paddingY` where the block reads `padding`) validated clean and\n * did nothing on screen. And a `{{ }}` template on a `bindable: false` prop was\n * shown to the visitor as literal braces. Both are now named.\n *\n * @param specs the block's declared props; `undefined` (block not in the map)\n * yields nothing, because an unknown block type is a different finding.\n */\nexport function blockManifestPropFindings(\n type: string,\n props: Record<string, unknown> | undefined,\n specs: readonly ManifestPropSpec[] | undefined,\n path = 'root'\n): ManifestPropFinding[] {\n if (!specs || !props) return []\n const byName = new Map(specs.map((s) => [s.name, s]))\n const out: ManifestPropFinding[] = []\n for (const [prop, value] of Object.entries(props)) {\n if (value === undefined) continue\n const spec = byName.get(prop)\n if (!spec) {\n out.push({\n path,\n type,\n prop,\n code: 'UNKNOWN_PROP',\n severity: 'warning',\n message: `\"${prop}\" is not a prop of ${type}; the block ignores it.`,\n })\n continue\n }\n if (spec.bindable === false && carriesTemplate(value)) {\n out.push({\n path,\n type,\n prop,\n code: 'TEMPLATE_ON_UNBINDABLE',\n severity: 'warning',\n message: `\"${prop}\" on ${type} takes a literal value; its {{ }} template is shown as written.`,\n })\n }\n }\n return out\n}\n\n/**\n * Every manifest finding in a layout tree, with path context. Blocks whose\n * type is not in `manifests` are skipped.\n */\nexport function manifestPropFindings(\n layout: LayoutNode,\n manifests: BlockManifestPropsMap,\n path = 'root'\n): ManifestPropFinding[] {\n const out = blockManifestPropFindings(layout.type, layout.props, manifests[layout.type], path)\n if (layout.children) {\n layout.children.forEach((child, i) => {\n if (child) out.push(...manifestPropFindings(child, manifests, `${path}.children[${i}]`))\n })\n }\n return out\n}\n"]}
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/surface/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA6CH,+DAA+D;AAC/D,uBAAuB;AACvB,+DAA+D;AAE/D;;;;;;GAMG;AACH,MAAM,UAAU,kBA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ACZ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAkB,EAClB,SAAgC,EAChC,IAAI,GAAG,MAAM;IAEb,MAAM,GAAG,GAAG,yBAAyB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;IAC9F,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YACnC,IAAI,KAAK;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC,CAAA;QAC1F,CAAC,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["/**\n * Block Props Validation\n *\n * Runtime validation of block props using injected Zod schemas.\n * the legacy `blockSchemas` map is gone — production\n * callers supply a schema map sourced from the install pipeline (per-atom\n * `manifest.definition.props[*].jsonSchema` rebuilt into Zod). Without a\n * schema map the validator runs in lenient mode and passes everything\n * through.\n *\n * @module @pwfabric/runtime/surface/validation\n */\n\nimport type { ZodSchema } from 'zod'\n\n/** Map of block type → Zod schema. Supply via options to enable strict checks. */\nexport type BlockSchemaMap = Readonly<Record<string, ZodSchema>>\n\n// ============================================================\n// VALIDATION TYPES\n// ============================================================\n\n/**\n * Options for block props validation\n */\nexport interface BlockPropsValidationOptions {\n /**\n * When true, unknown block types cause validation failure.\n * When false (default), unknown block types pass through.\n */\n readonly strict?: boolean\n /**\n * Per-block-type Zod schemas. the runtime no longer\n * ships a built-in schema map — callers that want prop validation\n * supply their own (typically rebuilt from\n * each installed block manifest's `definition.props[*].jsonSchema`).\n * Omitting the map yields lenient pass-through behaviour.\n */\n readonly schemas?: BlockSchemaMap\n /**\n * Per-block-type manifest props. When supplied, props a manifest\n * does not declare and templates on `bindable: false` props are reported as\n * WARNINGS (`manifestPropFindings`); they never fail validation.\n */\n readonly manifests?: BlockManifestPropsMap\n}\n\n/**\n * Result of validating block props against the schema\n */\nexport interface BlockPropsValidationResult {\n readonly valid: boolean\n readonly errors: readonly string[]\n readonly coerced?: Record<string, unknown>\n}\n\n// ============================================================\n// VALIDATION FUNCTIONS\n// ============================================================\n\n/**\n * Validate block props against the known Zod schema for the given block type.\n *\n * - Known block types are validated against the schema from @pwfabric/core.\n * - Unknown block types pass through in lenient mode (default) and fail in strict mode.\n * - On success, returns coerced data (with defaults applied by Zod).\n */\nexport function validateBlockProps(\n type: string,\n props: Record<string, unknown>,\n options: BlockPropsValidationOptions = {}\n): BlockPropsValidationResult {\n const { strict = false, schemas } = options\n\n const schema = schemas?.[type]\n\n if (!schema) {\n if (strict) {\n return {\n valid: false,\n errors: [`Unknown block type: ${type}`],\n }\n }\n // Lenient mode: unknown / unsupplied types pass through\n return { valid: true, errors: [] }\n }\n\n const result = schema.safeParse(props)\n\n if (result.success) {\n return {\n valid: true,\n errors: [],\n coerced: result.data as Record<string, unknown>,\n }\n }\n\n return {\n valid: false,\n errors: result.error.issues.map(\n (i) => `${i.path.map(String).join('.')}: ${i.message}`\n ),\n }\n}\n\n/**\n * Layout node shape for recursive validation.\n * Matches LayoutJSON structure without importing it to avoid circular deps.\n */\ninterface LayoutNode {\n readonly type: string\n readonly props?: Record<string, unknown>\n readonly children?: readonly LayoutNode[]\n}\n\n/**\n * A single validation issue with path context\n */\nexport interface LayoutPropsIssue {\n readonly path: string\n readonly type: string\n readonly errors: readonly string[]\n}\n\n/**\n * Validate all block props in a layout tree recursively.\n *\n * Returns a flat list of validation issues with path context.\n */\nexport function validateLayoutProps(\n layout: LayoutNode,\n options: BlockPropsValidationOptions = {},\n path = 'root'\n): readonly LayoutPropsIssue[] {\n const issues: LayoutPropsIssue[] = []\n\n const result = validateBlockProps(layout.type, layout.props ?? {}, options)\n if (!result.valid) {\n issues.push({\n path,\n type: layout.type,\n errors: result.errors,\n })\n }\n\n if (layout.children) {\n for (let i = 0; i < layout.children.length; i++) {\n const child = layout.children[i]\n if (child) {\n const childIssues = validateLayoutProps(child, options, `${path}.children[${i}]`)\n issues.push(...childIssues)\n }\n }\n }\n\n return issues\n}\n\n// ============================================================\n// PACK MANIFEST ENFORCEMENT\n// ============================================================\n\n/**\n * One prop a pack manifest declares: `manifest.definition.props[*]`. Only the\n * two fields the check reads; a full manifest entry passes as it is.\n */\nexport interface ManifestPropSpec {\n readonly name: string\n /** `false` = the prop takes a literal only; a `{{ }}` template is not resolved for it. */\n readonly bindable?: boolean\n}\n\n/** Block type → the props its manifest declares. */\nexport type BlockManifestPropsMap = Readonly<Record<string, readonly ManifestPropSpec[]>>\n\nexport type ManifestPropFindingCode = 'UNKNOWN_PROP' | 'TEMPLATE_ON_UNBINDABLE'\n\n/**\n * A prop that does not match its block's manifest. Always a WARNING:\n * existing apps carry such props and must keep rendering; a caller\n * decides whether to show, count or (later) refuse them.\n */\nexport interface ManifestPropFinding {\n readonly path: string\n readonly type: string\n readonly prop: string\n readonly code: ManifestPropFindingCode\n readonly severity: 'warning'\n readonly message: string\n}\n\nfunction carriesTemplate(value: unknown, depth = 0): boolean {\n if (depth > 8) return false\n if (typeof value === 'string') return value.includes('{{')\n if (Array.isArray(value)) return value.some((v) => carriesTemplate(v, depth + 1))\n if (value && typeof value === 'object') {\n return Object.values(value as Record<string, unknown>).some((v) => carriesTemplate(v, depth + 1))\n }\n return false\n}\n\n/**\n * The props of ONE block that its manifest does not allow.\n *\n * WHY: a prop the manifest does not declare was\n * accepted silently. The schema check rebuilds each prop's JSON schema into a\n * passthrough object, so a misspelt or invented prop (`tone` on a block that\n * has none, `paddingY` where the block reads `padding`) validated clean and\n * did nothing on screen. And a `{{ }}` template on a `bindable: false` prop was\n * shown to the visitor as literal braces. Both are now named.\n *\n * @param specs the block's declared props; `undefined` (block not in the map)\n * yields nothing, because an unknown block type is a different finding.\n */\nexport function blockManifestPropFindings(\n type: string,\n props: Record<string, unknown> | undefined,\n specs: readonly ManifestPropSpec[] | undefined,\n path = 'root'\n): ManifestPropFinding[] {\n if (!specs || !props) return []\n const byName = new Map(specs.map((s) => [s.name, s]))\n const out: ManifestPropFinding[] = []\n for (const [prop, value] of Object.entries(props)) {\n if (value === undefined) continue\n const spec = byName.get(prop)\n if (!spec) {\n out.push({\n path,\n type,\n prop,\n code: 'UNKNOWN_PROP',\n severity: 'warning',\n message: `\"${prop}\" is not a prop of ${type}; the block ignores it.`,\n })\n continue\n }\n if (spec.bindable === false && carriesTemplate(value)) {\n out.push({\n path,\n type,\n prop,\n code: 'TEMPLATE_ON_UNBINDABLE',\n severity: 'warning',\n message: `\"${prop}\" on ${type} takes a literal value; its {{ }} template is shown as written.`,\n })\n }\n }\n return out\n}\n\n/**\n * Every manifest finding in a layout tree, with path context. Blocks whose\n * type is not in `manifests` are skipped.\n */\nexport function manifestPropFindings(\n layout: LayoutNode,\n manifests: BlockManifestPropsMap,\n path = 'root'\n): ManifestPropFinding[] {\n const out = blockManifestPropFindings(layout.type, layout.props, manifests[layout.type], path)\n if (layout.children) {\n layout.children.forEach((child, i) => {\n if (child) out.push(...manifestPropFindings(child, manifests, `${path}.children[${i}]`))\n })\n }\n return out\n}\n"]}
package/dist/validator.js CHANGED
@@ -92,7 +92,7 @@ export function isValidationFailure(result) {
92
92
  export function formatValidationErrors(errors) {
93
93
  return errors
94
94
  .map((e) => {
95
- const path = e.path.length > 0 ? `${e.path.join('.')}: ` : '';
95
+ const path = e.path.length > 0 ? `${e.path.map(String).join('.')}: ` : '';
96
96
  return `${path}${e.message} (${e.code})`;
97
97
  })
98
98
  .join('\n');
@@ -1 +1 @@
1
- {"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,qBAAqB,CA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,UAAU,mBAAmB,CACjC,MAA2B;IAE3B,OAAO,MAAM,CAAC,OAAO,KAAK,KAAK,CAAA;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAyB;IAC9D,OAAO,MAAM;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;QAC7D,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,IAAI,GAAG,CAAA;IAC1C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC","sourcesContent":["/**\n * Contract Validator\n *\n * Runtime validation for contracts\n *\n * @module @pwfabric/runtime/validator\n */\n\nimport type { Contract, Capability, ValidationResult, ValidationError } from '@pwfabric/contracts'\nimport { ok, err, validationError } from '@pwfabric/contracts'\n\n// ============================================================\n// VALIDATOR INTERFACE\n// ============================================================\n\n/**\n * Contract validator interface\n */\nexport interface ContractValidator {\n /**\n * Validate input against a contract\n */\n validateInput<T>(contract: Contract<T, unknown>, data: unknown): ValidationResult<T>\n\n /**\n * Validate output against a contract\n */\n validateOutput<T>(contract: Contract<unknown, T>, data: unknown): ValidationResult<T>\n\n /**\n * Validate a capability's contract\n */\n validateCapability(capability: Capability): ValidationResult<void>\n}\n\n// ============================================================\n// RUNTIME VALIDATOR IMPLEMENTATION\n// ============================================================\n\n/**\n * Runtime contract validator\n */\nexport class RuntimeContractValidator implements ContractValidator {\n validateInput<T>(contract: Contract<T, unknown>, data: unknown): ValidationResult<T> {\n try {\n return contract.validateInput(data)\n } catch (error) {\n const errors: ValidationError[] = [\n validationError(\n [],\n error instanceof Error ? error.message : 'Unknown validation error',\n 'validation_error'\n ),\n ]\n return err(errors)\n }\n }\n\n validateOutput<T>(contract: Contract<unknown, T>, data: unknown): ValidationResult<T> {\n try {\n return contract.validateOutput(data)\n } catch (error) {\n const errors: ValidationError[] = [\n validationError(\n [],\n error instanceof Error ? error.message : 'Unknown validation error',\n 'validation_error'\n ),\n ]\n return err(errors)\n }\n }\n\n validateCapability(capability: Capability): ValidationResult<void> {\n const errors: ValidationError[] = []\n\n // Validate capability has required fields\n if (!capability.id) {\n errors.push(validationError(['id'], 'Capability ID is required', 'required'))\n }\n\n if (!capability.version) {\n errors.push(validationError(['version'], 'Capability version is required', 'required'))\n }\n\n if (!capability.contract) {\n errors.push(validationError(['contract'], 'Capability contract is required', 'required'))\n }\n\n if (!capability.execute) {\n errors.push(\n validationError(['execute'], 'Capability execute function is required', 'required')\n )\n }\n\n // Validate contract exists and has required methods\n if (capability.contract) {\n if (!capability.contract.validateInput) {\n errors.push(\n validationError(\n ['contract', 'validateInput'],\n 'Contract validateInput method is required',\n 'required'\n )\n )\n }\n\n if (!capability.contract.validateOutput) {\n errors.push(\n validationError(\n ['contract', 'validateOutput'],\n 'Contract validateOutput method is required',\n 'required'\n )\n )\n }\n }\n\n if (errors.length > 0) {\n return err(errors)\n }\n\n return ok(undefined)\n }\n}\n\n// ============================================================\n// VALIDATION UTILITIES\n// ============================================================\n\n/**\n * Create a contract validator\n */\nexport function createValidator(): ContractValidator {\n return new RuntimeContractValidator()\n}\n\n/**\n * Validation result type guard\n */\nexport function isValidationSuccess<T>(\n result: ValidationResult<T>\n): result is { success: true; data: T } {\n return result.success === true\n}\n\n/**\n * Validation result type guard for errors\n */\nexport function isValidationFailure<T>(\n result: ValidationResult<T>\n): result is { success: false; error: ValidationError[] } {\n return result.success === false\n}\n\n/**\n * Format validation errors as a string\n */\nexport function formatValidationErrors(errors: ValidationError[]): string {\n return errors\n .map((e) => {\n const path = e.path.length > 0 ? `${e.path.join('.')}: ` : ''\n return `${path}${e.message} (${e.code})`\n })\n .join('\\n')\n}\n"]}
1
+ {"version":3,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,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA2B;IAE3B,OAAO,MAAM,CAAC,OAAO,KAAK,IAAI,CAAA;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA2B;IAE3B,OAAO,MAAM,CAAC,OAAO,KAAK,KAAK,CAAA;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAyB;IAC9D,OAAO,MAAM;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;QACzE,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,IAAI,GAAG,CAAA;IAC1C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC","sourcesContent":["/**\n * Contract Validator\n *\n * Runtime validation for contracts\n *\n * @module @pwfabric/runtime/validator\n */\n\nimport type { Contract, Capability, ValidationResult, ValidationError } from '@pwfabric/contracts'\nimport { ok, err, validationError } from '@pwfabric/contracts'\n\n// ============================================================\n// VALIDATOR INTERFACE\n// ============================================================\n\n/**\n * Contract validator interface\n */\nexport interface ContractValidator {\n /**\n * Validate input against a contract\n */\n validateInput<T>(contract: Contract<T, unknown>, data: unknown): ValidationResult<T>\n\n /**\n * Validate output against a contract\n */\n validateOutput<T>(contract: Contract<unknown, T>, data: unknown): ValidationResult<T>\n\n /**\n * Validate a capability's contract\n */\n validateCapability(capability: Capability): ValidationResult<void>\n}\n\n// ============================================================\n// RUNTIME VALIDATOR IMPLEMENTATION\n// ============================================================\n\n/**\n * Runtime contract validator\n */\nexport class RuntimeContractValidator implements ContractValidator {\n validateInput<T>(contract: Contract<T, unknown>, data: unknown): ValidationResult<T> {\n try {\n return contract.validateInput(data)\n } catch (error) {\n const errors: ValidationError[] = [\n validationError(\n [],\n error instanceof Error ? error.message : 'Unknown validation error',\n 'validation_error'\n ),\n ]\n return err(errors)\n }\n }\n\n validateOutput<T>(contract: Contract<unknown, T>, data: unknown): ValidationResult<T> {\n try {\n return contract.validateOutput(data)\n } catch (error) {\n const errors: ValidationError[] = [\n validationError(\n [],\n error instanceof Error ? error.message : 'Unknown validation error',\n 'validation_error'\n ),\n ]\n return err(errors)\n }\n }\n\n validateCapability(capability: Capability): ValidationResult<void> {\n const errors: ValidationError[] = []\n\n // Validate capability has required fields\n if (!capability.id) {\n errors.push(validationError(['id'], 'Capability ID is required', 'required'))\n }\n\n if (!capability.version) {\n errors.push(validationError(['version'], 'Capability version is required', 'required'))\n }\n\n if (!capability.contract) {\n errors.push(validationError(['contract'], 'Capability contract is required', 'required'))\n }\n\n if (!capability.execute) {\n errors.push(\n validationError(['execute'], 'Capability execute function is required', 'required')\n )\n }\n\n // Validate contract exists and has required methods\n if (capability.contract) {\n if (!capability.contract.validateInput) {\n errors.push(\n validationError(\n ['contract', 'validateInput'],\n 'Contract validateInput method is required',\n 'required'\n )\n )\n }\n\n if (!capability.contract.validateOutput) {\n errors.push(\n validationError(\n ['contract', 'validateOutput'],\n 'Contract validateOutput method is required',\n 'required'\n )\n )\n }\n }\n\n if (errors.length > 0) {\n return err(errors)\n }\n\n return ok(undefined)\n }\n}\n\n// ============================================================\n// VALIDATION UTILITIES\n// ============================================================\n\n/**\n * Create a contract validator\n */\nexport function createValidator(): ContractValidator {\n return new RuntimeContractValidator()\n}\n\n/**\n * Validation result type guard\n */\nexport function isValidationSuccess<T>(\n result: ValidationResult<T>\n): result is { success: true; data: T } {\n return result.success === true\n}\n\n/**\n * Validation result type guard for errors\n */\nexport function isValidationFailure<T>(\n result: ValidationResult<T>\n): result is { success: false; error: ValidationError[] } {\n return result.success === false\n}\n\n/**\n * Format validation errors as a string\n */\nexport function formatValidationErrors(errors: ValidationError[]): string {\n return errors\n .map((e) => {\n const path = e.path.length > 0 ? `${e.path.map(String).join('.')}: ` : ''\n return `${path}${e.message} (${e.code})`\n })\n .join('\\n')\n}\n"]}