@elastic/isomer-sdk 0.2.0 → 0.3.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 (154) hide show
  1. package/NOTICE.txt +0 -286
  2. package/THIRD_PARTY_LICENSES.md +1 -885
  3. package/dist/author/authored_fields.d.ts +37 -12
  4. package/dist/author/authored_fields.d.ts.map +1 -1
  5. package/dist/author/authored_fields.js +45 -69
  6. package/dist/author/authored_fields.js.map +1 -1
  7. package/dist/author/authoring_input.d.ts.map +1 -1
  8. package/dist/author/authoring_input.js +12 -6
  9. package/dist/author/authoring_input.js.map +1 -1
  10. package/dist/author/authoring_model.d.ts +8 -2
  11. package/dist/author/authoring_model.d.ts.map +1 -1
  12. package/dist/author/authoring_model.js +67 -23
  13. package/dist/author/authoring_model.js.map +1 -1
  14. package/dist/author/declarations.d.ts.map +1 -1
  15. package/dist/author/declarations.js +45 -34
  16. package/dist/author/declarations.js.map +1 -1
  17. package/dist/author/index.d.ts +2 -1
  18. package/dist/author/index.d.ts.map +1 -1
  19. package/dist/author/index.js +2 -1
  20. package/dist/author/index.js.map +1 -1
  21. package/dist/author/jsx_shim.d.ts +49 -30
  22. package/dist/author/jsx_shim.d.ts.map +1 -1
  23. package/dist/author/jsx_shim.js +131 -40
  24. package/dist/author/jsx_shim.js.map +1 -1
  25. package/dist/author/print_jsx.d.ts +19 -0
  26. package/dist/author/print_jsx.d.ts.map +1 -0
  27. package/dist/author/print_jsx.js +372 -0
  28. package/dist/author/print_jsx.js.map +1 -0
  29. package/dist/author/prompt.d.ts +2 -2
  30. package/dist/author/prompt.d.ts.map +1 -1
  31. package/dist/author/prompt.js +7 -2
  32. package/dist/author/prompt.js.map +1 -1
  33. package/dist/author/schema_to_typescript.d.ts.map +1 -1
  34. package/dist/author/schema_to_typescript.js +6 -3
  35. package/dist/author/schema_to_typescript.js.map +1 -1
  36. package/dist/cjs/author/authored_fields.js +47 -70
  37. package/dist/cjs/author/authored_fields.js.map +1 -1
  38. package/dist/cjs/author/authoring_input.js +12 -6
  39. package/dist/cjs/author/authoring_input.js.map +1 -1
  40. package/dist/cjs/author/authoring_model.js +69 -24
  41. package/dist/cjs/author/authoring_model.js.map +1 -1
  42. package/dist/cjs/author/declarations.js +44 -33
  43. package/dist/cjs/author/declarations.js.map +1 -1
  44. package/dist/cjs/author/index.js +5 -1
  45. package/dist/cjs/author/index.js.map +1 -1
  46. package/dist/cjs/author/jsx_shim.js +130 -39
  47. package/dist/cjs/author/jsx_shim.js.map +1 -1
  48. package/dist/cjs/author/print_jsx.js +378 -0
  49. package/dist/cjs/author/print_jsx.js.map +1 -0
  50. package/dist/cjs/author/prompt.js +7 -2
  51. package/dist/cjs/author/prompt.js.map +1 -1
  52. package/dist/cjs/author/schema_to_typescript.js +6 -3
  53. package/dist/cjs/author/schema_to_typescript.js.map +1 -1
  54. package/dist/cjs/composition/error.js +1 -0
  55. package/dist/cjs/composition/error.js.map +1 -1
  56. package/dist/cjs/composition/structured_value.js.map +1 -1
  57. package/dist/cjs/define/primitive_module.js +10 -4
  58. package/dist/cjs/define/primitive_module.js.map +1 -1
  59. package/dist/cjs/entries/index.js +3 -2
  60. package/dist/cjs/entries/index.js.map +1 -1
  61. package/dist/cjs/entries/markdown.js +2 -1
  62. package/dist/cjs/entries/markdown.js.map +1 -1
  63. package/dist/cjs/pack/index.js +2 -1
  64. package/dist/cjs/pack/index.js.map +1 -1
  65. package/dist/cjs/pack/primitive_pack.js +14 -4
  66. package/dist/cjs/pack/primitive_pack.js.map +1 -1
  67. package/dist/cjs/render/format_number.js +2 -1
  68. package/dist/cjs/render/format_number.js.map +1 -1
  69. package/dist/cjs/render/html/envelope.js +12 -6
  70. package/dist/cjs/render/html/envelope.js.map +1 -1
  71. package/dist/cjs/render/markdown/builder.js +6 -2
  72. package/dist/cjs/render/markdown/builder.js.map +1 -1
  73. package/dist/cjs/render/markdown/format.js +46 -24
  74. package/dist/cjs/render/markdown/format.js.map +1 -1
  75. package/dist/cjs/render/markdown/host_tags.js +67 -0
  76. package/dist/cjs/render/markdown/host_tags.js.map +1 -0
  77. package/dist/cjs/render/markdown/index.js +3 -1
  78. package/dist/cjs/render/markdown/index.js.map +1 -1
  79. package/dist/cjs/render/markdown/split.js +325 -0
  80. package/dist/cjs/render/markdown/split.js.map +1 -0
  81. package/dist/cjs/render/react/content.js +3 -1
  82. package/dist/cjs/render/react/content.js.map +1 -1
  83. package/dist/cjs/render/slack/markdown_content.js +7 -1
  84. package/dist/cjs/render/slack/markdown_content.js.map +1 -1
  85. package/dist/cjs/validate/json_schema.js +10 -3
  86. package/dist/cjs/validate/json_schema.js.map +1 -1
  87. package/dist/cjs/validate/url.js +2 -1
  88. package/dist/cjs/validate/url.js.map +1 -1
  89. package/dist/composition/error.d.ts +1 -0
  90. package/dist/composition/error.d.ts.map +1 -1
  91. package/dist/composition/error.js +1 -0
  92. package/dist/composition/error.js.map +1 -1
  93. package/dist/composition/structured_value.d.ts +3 -3
  94. package/dist/composition/structured_value.d.ts.map +1 -1
  95. package/dist/composition/structured_value.js.map +1 -1
  96. package/dist/define/primitive_module.d.ts +7 -0
  97. package/dist/define/primitive_module.d.ts.map +1 -1
  98. package/dist/define/primitive_module.js +10 -4
  99. package/dist/define/primitive_module.js.map +1 -1
  100. package/dist/entries/index.d.ts +1 -1
  101. package/dist/entries/index.d.ts.map +1 -1
  102. package/dist/entries/index.js +1 -1
  103. package/dist/entries/index.js.map +1 -1
  104. package/dist/entries/markdown.d.ts +1 -1
  105. package/dist/entries/markdown.d.ts.map +1 -1
  106. package/dist/entries/markdown.js +1 -1
  107. package/dist/entries/markdown.js.map +1 -1
  108. package/dist/pack/index.d.ts +1 -1
  109. package/dist/pack/index.d.ts.map +1 -1
  110. package/dist/pack/index.js +1 -1
  111. package/dist/pack/index.js.map +1 -1
  112. package/dist/pack/primitive_pack.d.ts +3 -1
  113. package/dist/pack/primitive_pack.d.ts.map +1 -1
  114. package/dist/pack/primitive_pack.js +13 -3
  115. package/dist/pack/primitive_pack.js.map +1 -1
  116. package/dist/render/format_number.d.ts.map +1 -1
  117. package/dist/render/format_number.js +2 -1
  118. package/dist/render/format_number.js.map +1 -1
  119. package/dist/render/html/envelope.js +12 -6
  120. package/dist/render/html/envelope.js.map +1 -1
  121. package/dist/render/markdown/builder.d.ts +3 -0
  122. package/dist/render/markdown/builder.d.ts.map +1 -1
  123. package/dist/render/markdown/builder.js +3 -1
  124. package/dist/render/markdown/builder.js.map +1 -1
  125. package/dist/render/markdown/format.d.ts +2 -0
  126. package/dist/render/markdown/format.d.ts.map +1 -1
  127. package/dist/render/markdown/format.js +42 -22
  128. package/dist/render/markdown/format.js.map +1 -1
  129. package/dist/render/markdown/host_tags.d.ts +14 -0
  130. package/dist/render/markdown/host_tags.d.ts.map +1 -0
  131. package/dist/render/markdown/host_tags.js +63 -0
  132. package/dist/render/markdown/host_tags.js.map +1 -0
  133. package/dist/render/markdown/index.d.ts +1 -0
  134. package/dist/render/markdown/index.d.ts.map +1 -1
  135. package/dist/render/markdown/index.js +1 -0
  136. package/dist/render/markdown/index.js.map +1 -1
  137. package/dist/render/markdown/split.d.ts +32 -0
  138. package/dist/render/markdown/split.d.ts.map +1 -0
  139. package/dist/render/markdown/split.js +321 -0
  140. package/dist/render/markdown/split.js.map +1 -0
  141. package/dist/render/react/content.d.ts +1 -1
  142. package/dist/render/react/content.d.ts.map +1 -1
  143. package/dist/render/react/content.js +3 -1
  144. package/dist/render/react/content.js.map +1 -1
  145. package/dist/render/slack/markdown_content.d.ts.map +1 -1
  146. package/dist/render/slack/markdown_content.js +7 -1
  147. package/dist/render/slack/markdown_content.js.map +1 -1
  148. package/dist/validate/json_schema.d.ts.map +1 -1
  149. package/dist/validate/json_schema.js +10 -3
  150. package/dist/validate/json_schema.js.map +1 -1
  151. package/dist/validate/url.d.ts.map +1 -1
  152. package/dist/validate/url.js +2 -1
  153. package/dist/validate/url.js.map +1 -1
  154. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":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GAAG,CAAC,GAAG,IAAI,KAC3C,SAAS,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,IACzC,KAAK,CAAC;QACR,CAAC,CAAC;aACD,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,EAAE,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,IAAI;QACtE,OAAO,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CACvC,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,CAAC;QACjD,QAAQ,EAAE,GAAG,EAAE;YACb,MAAM,OAAO,GAAa,EAAE,CAAC;YAC7B,KAAK,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,aAAa,EAAE,CAAC;gBACvC,OAAO,CAAC,IAAI,CACV,QAAQ,IAAI,MAAM,SAAS,CAAC,IAAA,cAAM,EAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CACxE,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AA9PW,QAAA,iBAAiB,qBA8P5B","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport type JsonObject = Record<string, unknown>;\n\nexport const DEF_PREFIX = '#/$defs/';\n\n/** Ids `z.toJSONSchema` gives a def no one named. */\nexport const ANONYMOUS_DEF = /^__schema\\d+$/;\n\nconst STRUCTURAL_KEYS = [\n 'type',\n 'const',\n 'enum',\n 'properties',\n 'additionalProperties',\n 'patternProperties',\n 'propertyNames',\n 'items',\n 'prefixItems',\n 'oneOf',\n 'anyOf',\n 'allOf',\n] as const;\n\nconst INDENT = ' ';\n\nexport const IDENTIFIER = /^[A-Za-z_$][\\w$]*$/;\n\nexport const isJsonObject = (value: unknown): value is JsonObject =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nexport const parseDefRef = (ref: unknown): string | undefined =>\n typeof ref === 'string' && ref.startsWith(DEF_PREFIX)\n ? ref.slice(DEF_PREFIX.length)\n : undefined;\n\nexport const ownDef = (defs: JsonObject, id: string): unknown =>\n Object.hasOwn(defs, id) ? defs[id] : undefined;\n\n/** `slideStats` becomes `SlideStats`; anything but letters and digits splits words. */\nexport const pascalCase = (value: string): string => {\n const name = value\n .split(/[^A-Za-z0-9]+/)\n .filter(Boolean)\n .map((word) => `${word.slice(0, 1).toUpperCase()}${word.slice(1)}`)\n .join('');\n if (name === '') {\n return 'Type';\n }\n return /^\\d/.test(name) ? `_${name}` : name;\n};\n\n/** A JSDoc block for `lines`, or `''` when there are none. */\nexport const jsDoc = (lines: readonly string[], pad: string): string => {\n const text = lines\n .flatMap((line) => line.split('\\n'))\n .map((line) => line.replaceAll('*/', '*\\\\/').trimEnd());\n while (text[0] === '') {\n text.shift();\n }\n while (text.at(-1) === '') {\n text.pop();\n }\n if (text.length === 0) {\n return '';\n }\n const [only] = text;\n if (text.length === 1 && only !== undefined) {\n return `${pad}/** ${only} */\\n`;\n }\n return `${pad}/**\\n${text\n .map((line) => (line === '' ? `${pad} *` : `${pad} * ${line}`))\n .join('\\n')}\\n${pad} */\\n`;\n};\n\nconst propertyKey = (key: string): string =>\n IDENTIFIER.test(key) ? key : JSON.stringify(key);\n\nconst literal = (value: unknown): string => {\n if (value === null) {\n return 'null';\n }\n switch (typeof value) {\n case 'string':\n return JSON.stringify(value);\n case 'number':\n case 'boolean':\n return String(value);\n default:\n return 'unknown';\n }\n};\n\ninterface Printed {\n text: string;\n kind: 'atom' | 'union' | 'intersection';\n}\n\nconst atom = (text: string): Printed => ({ text, kind: 'atom' });\n\nconst union = (members: readonly Printed[]): Printed => {\n if (members.some(({ text }) => text === 'unknown')) return atom('unknown');\n const unique = new Map(members.map((member) => [member.text, member]));\n const [only] = [...unique.values()];\n if (unique.size === 0) {\n return atom('never');\n }\n return unique.size === 1 && only\n ? only\n : { text: [...unique.keys()].join(' | '), kind: 'union' };\n};\n\nconst intersection = (members: readonly Printed[]): Printed => {\n const unique = new Map(members.map((member) => [member.text, member]));\n const [only] = [...unique.values()];\n if (!only) return atom('unknown');\n if (unique.size === 1 && only) {\n return only;\n }\n return {\n text: [...unique.values()]\n .map(({ text, kind }) => (kind === 'union' ? `(${text})` : text))\n .join(' & '),\n kind: 'intersection',\n };\n};\n\nconst arrayOf = ({ text, kind }: Printed): Printed =>\n atom(kind === 'atom' ? `${text}[]` : `(${text})[]`);\n\n/** What {@link TypePrinter.members} prints and how. */\nexport interface MemberOptions {\n /** Properties left out. */\n omit?: ReadonlySet<string>;\n /** Properties printed optional whether or not the schema requires them. */\n optional?: ReadonlySet<string>;\n}\n\nexport interface TypePrinterOptions {\n defs: JsonObject;\n /** TypeScript names for defs printed by reference; every other def is inlined. */\n names: ReadonlyMap<string, string>;\n /** A fresh, unused name, for a def inlining cannot express. */\n claim: (base: string) => string;\n}\n\nexport interface TypePrinter {\n /** `schema` as a TypeScript type, written at `depth` levels of indent. */\n print: (schema: unknown, depth?: number) => string;\n /** The `key?: Type;` members of an object schema, with their JSDoc, at `depth + 1`. */\n members: (\n schema: JsonObject,\n depth: number,\n options?: MemberOptions\n ) => string;\n /** Type aliases for the anonymous defs that refer to themselves. Call last. */\n promoted: () => string[];\n}\n\n/** A TypeScript printer over the subset of JSON Schema `z.toJSONSchema` emits. */\nexport const createTypePrinter = ({\n defs,\n names,\n claim,\n}: TypePrinterOptions): TypePrinter => {\n const promotedNames = new Map<string, string>();\n\n const printRef = (\n id: string,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const named = names.get(id);\n if (named !== undefined) {\n return atom(named);\n }\n const target = ownDef(defs, id);\n if (target === undefined) {\n return atom('unknown');\n }\n if (active.has(id)) {\n const name = promotedNames.get(id) ?? claim(pascalCase(id));\n promotedNames.set(id, name);\n return atom(name);\n }\n return printNode(target, depth, new Set([...active, id]));\n };\n\n const printNode = (\n node: unknown,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n if (node === false) {\n return atom('never');\n }\n if (!isJsonObject(node)) {\n return atom('unknown');\n }\n const parts: Printed[] = [];\n const ref = parseDefRef(node.$ref);\n if (ref !== undefined) {\n parts.push(printRef(ref, depth, active));\n }\n if (STRUCTURAL_KEYS.some((key) => Object.hasOwn(node, key))) {\n parts.push(printStructure(node, depth, active));\n }\n return parts.length === 0 ? atom('unknown') : intersection(parts);\n };\n\n const printStructure = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const parts: Printed[] = [];\n const own = printOwn(node, depth, active);\n if (own) {\n parts.push(own);\n }\n for (const key of ['oneOf', 'anyOf'] as const) {\n const members = node[key];\n if (Array.isArray(members)) {\n parts.push(\n union(members.map((member) => printNode(member, depth, active)))\n );\n }\n }\n if (Array.isArray(node.allOf)) {\n parts.push(\n intersection(\n node.allOf.map((member) => printNode(member, depth, active))\n )\n );\n }\n return parts.length === 0 ? atom('unknown') : intersection(parts);\n };\n\n // `undefined` when the node only combines other schemas.\n const printOwn = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed | undefined => {\n if (Object.hasOwn(node, 'const')) {\n return atom(literal(node.const));\n }\n if (Array.isArray(node.enum)) {\n return union(node.enum.map((value) => atom(literal(value))));\n }\n const { type } = node;\n if (Array.isArray(type)) {\n return union(\n type.map((member) => printTyped(member, node, depth, active))\n );\n }\n if (typeof type === 'string') {\n return printTyped(type, node, depth, active);\n }\n if (\n Object.hasOwn(node, 'properties') ||\n Object.hasOwn(node, 'additionalProperties')\n ) {\n return printObject(node, depth, active);\n }\n if (Object.hasOwn(node, 'items') || Object.hasOwn(node, 'prefixItems')) {\n return printArray(node, depth, active);\n }\n return undefined;\n };\n\n const printTyped = (\n type: unknown,\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n switch (type) {\n case 'string':\n return atom('string');\n case 'number':\n case 'integer':\n return atom('number');\n case 'boolean':\n return atom('boolean');\n case 'null':\n return atom('null');\n case 'array':\n return printArray(node, depth, active);\n case 'object':\n return printObject(node, depth, active);\n default:\n return atom('unknown');\n }\n };\n\n const printArray = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const { prefixItems, items } = node;\n if (Array.isArray(prefixItems)) {\n const required = typeof node.minItems === 'number' ? node.minItems : 0;\n const elements = prefixItems.map((item, index) => {\n const printed = printNode(item, depth, active);\n return index < required\n ? printed.text\n : `${printed.kind === 'atom' ? printed.text : `(${printed.text})`}?`;\n });\n if (items !== undefined && items !== false) {\n elements.push(`...${arrayOf(printNode(items, depth, active)).text}`);\n }\n return atom(`[${elements.join(', ')}]`);\n }\n return arrayOf(\n items === undefined ? atom('unknown') : printNode(items, depth, active)\n );\n };\n\n const printObject = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const properties = isJsonObject(node.properties) ? node.properties : {};\n const lines = printMembers(node, depth, active, {});\n const extra = node.additionalProperties;\n const patterns = isJsonObject(node.patternProperties)\n ? Object.values(node.patternProperties)\n : [];\n const open = extra !== false;\n const values = [\n ...patterns.map((schema) => printNode(schema, depth, active)),\n ];\n if (open)\n values.push(\n extra === undefined || extra === true\n ? atom('unknown')\n : printNode(extra, depth, active)\n );\n const index =\n values.length === 0\n ? Object.keys(properties).length === 0\n ? `${INDENT.repeat(depth + 1)}[key: string]: never;\\n`\n : ''\n : `${INDENT.repeat(depth + 1)}[key: string]: ${\n union([\n ...values,\n ...Object.values(properties).map((schema) =>\n printNode(schema, depth, active)\n ),\n ...(Object.keys(properties).some(\n (key) =>\n !Array.isArray(node.required) || !node.required.includes(key)\n )\n ? [atom('undefined')]\n : []),\n ]).text\n };\\n`;\n return atom(`{\\n${lines}${index}${INDENT.repeat(depth)}}`);\n };\n\n const printMembers = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>,\n { omit, optional }: MemberOptions\n ): string => {\n const pad = INDENT.repeat(depth + 1);\n const required = new Set(\n Array.isArray(node.required)\n ? node.required.filter((key) => typeof key === 'string')\n : []\n );\n const properties = isJsonObject(node.properties) ? node.properties : {};\n return Object.entries(properties)\n .filter(([key]) => !omit?.has(key))\n .map(([key, property]) => {\n const doc = isJsonObject(property)\n ? jsDoc(\n [\n typeof property.description === 'string'\n ? property.description\n : '',\n ...(Object.hasOwn(property, 'default')\n ? [`@default ${JSON.stringify(property.default)}`]\n : []),\n ],\n pad\n )\n : '';\n const mark = required.has(key) && !optional?.has(key) ? '' : '?';\n return `${doc}${pad}${propertyKey(key)}${mark}: ${\n printNode(property, depth + 1, active).text\n };\\n`;\n })\n .join('');\n };\n\n return {\n print: (schema, depth = 0) => printNode(schema, depth, new Set()).text,\n members: (schema, depth, options = {}) =>\n printMembers(schema, depth, new Set(), options),\n promoted: () => {\n const aliases: string[] = [];\n for (const [id, name] of promotedNames) {\n aliases.push(\n `type ${name} = ${printNode(ownDef(defs, id), 0, new Set([id])).text};`\n );\n }\n return aliases;\n },\n };\n};\n"]}
1
+ {"version":3,"file":"schema_to_typescript.js","sourceRoot":"","sources":["../../../src/author/schema_to_typescript.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIU,QAAA,UAAU,GAAG,UAAU,CAAC;AAErC,qDAAqD;AACxC,QAAA,aAAa,GAAG,eAAe,CAAC;AAE7C,MAAM,eAAe,GAAG;IACtB,MAAM;IACN,OAAO;IACP,MAAM;IACN,YAAY;IACZ,sBAAsB;IACtB,mBAAmB;IACnB,eAAe;IACf,OAAO;IACP,aAAa;IACb,OAAO;IACP,OAAO;IACP,OAAO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AC,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,IAAI;QACtE,OAAO,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CACvC,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,CAAC;QACjD,QAAQ,EAAE,GAAG,EAAE;YACb,MAAM,OAAO,GAAa,EAAE,CAAC;YAC7B,KAAK,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,aAAa,EAAE,CAAC;gBACvC,OAAO,CAAC,IAAI,CACV,QAAQ,IAAI,MAAM,SAAS,CAAC,IAAA,cAAM,EAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CACxE,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AA/PW,QAAA,iBAAiB,qBA+P5B","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport type JsonObject = Record<string, unknown>;\n\nexport const DEF_PREFIX = '#/$defs/';\n\n/** Ids `z.toJSONSchema` gives a def no one named. */\nexport const ANONYMOUS_DEF = /^__schema\\d+$/;\n\nconst STRUCTURAL_KEYS = [\n 'type',\n 'const',\n 'enum',\n 'properties',\n 'additionalProperties',\n 'patternProperties',\n 'propertyNames',\n 'items',\n 'prefixItems',\n 'oneOf',\n 'anyOf',\n 'allOf',\n] as const;\n\nconst INDENT = ' ';\n\nexport const IDENTIFIER = /^[A-Za-z_$][\\w$]*$/;\n\nexport const isJsonObject = (value: unknown): value is JsonObject =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nexport const parseDefRef = (ref: unknown): string | undefined =>\n typeof ref === 'string' && ref.startsWith(DEF_PREFIX)\n ? ref.slice(DEF_PREFIX.length)\n : undefined;\n\nexport const ownDef = (defs: JsonObject, id: string): unknown =>\n Object.hasOwn(defs, id) ? defs[id] : undefined;\n\n/** `slideStats` becomes `SlideStats`; anything but letters and digits splits words. */\nexport const pascalCase = (value: string): string => {\n const name = value\n .split(/[^A-Za-z0-9]+/)\n .filter(Boolean)\n .map((word) => `${word.slice(0, 1).toUpperCase()}${word.slice(1)}`)\n .join('');\n if (name === '') {\n return 'Type';\n }\n return /^\\d/.test(name) ? `_${name}` : name;\n};\n\n/** A JSDoc block for `lines`, or `''` when there are none. */\nexport const jsDoc = (lines: readonly string[], pad: string): string => {\n const text = lines\n .flatMap((line) => line.split('\\n'))\n .map((line) => line.replaceAll('*/', '*\\\\/').trimEnd());\n while (text[0] === '') {\n text.shift();\n }\n while (text.at(-1) === '') {\n text.pop();\n }\n if (text.length === 0) {\n return '';\n }\n const [only] = text;\n if (text.length === 1 && only !== undefined) {\n return `${pad}/** ${only} */\\n`;\n }\n return `${pad}/**\\n${text\n .map((line) => (line === '' ? `${pad} *` : `${pad} * ${line}`))\n .join('\\n')}\\n${pad} */\\n`;\n};\n\nconst propertyKey = (key: string): string =>\n IDENTIFIER.test(key) ? key : JSON.stringify(key);\n\nconst literal = (value: unknown): string => {\n if (value === null) {\n return 'null';\n }\n switch (typeof value) {\n case 'string':\n return JSON.stringify(value);\n case 'number':\n case 'boolean':\n return String(value);\n default:\n return 'unknown';\n }\n};\n\ninterface Printed {\n text: string;\n kind: 'atom' | 'union' | 'intersection';\n}\n\nconst atom = (text: string): Printed => ({ text, kind: 'atom' });\n\nconst union = (members: readonly Printed[]): Printed => {\n if (members.some(({ text }) => text === 'unknown')) {\n return atom('unknown');\n }\n const unique = new Map(members.map((member) => [member.text, member]));\n const [only] = [...unique.values()];\n if (unique.size === 0) {\n return atom('never');\n }\n return unique.size === 1 && only\n ? only\n : { text: [...unique.keys()].join(' | '), kind: 'union' };\n};\n\nconst intersection = (members: readonly Printed[]): Printed => {\n const unique = new Map(members.map((member) => [member.text, member]));\n const [only] = [...unique.values()];\n if (!only) {\n return atom('unknown');\n }\n if (unique.size === 1 && only) {\n return only;\n }\n return {\n text: [...unique.values()]\n .map(({ text, kind }) => (kind === 'union' ? `(${text})` : text))\n .join(' & '),\n kind: 'intersection',\n };\n};\n\nconst arrayOf = ({ text, kind }: Printed): Printed =>\n atom(kind === 'atom' ? `${text}[]` : `(${text})[]`);\n\n/** What {@link TypePrinter.members} prints and how. */\nexport interface MemberOptions {\n /** Properties left out. */\n omit?: ReadonlySet<string>;\n /** Properties printed optional whether or not the schema requires them. */\n optional?: ReadonlySet<string>;\n}\n\nexport interface TypePrinterOptions {\n defs: JsonObject;\n /** TypeScript names for defs printed by reference; every other def is inlined. */\n names: ReadonlyMap<string, string>;\n /** A fresh, unused name, for a def inlining cannot express. */\n claim: (base: string) => string;\n}\n\nexport interface TypePrinter {\n /** `schema` as a TypeScript type, written at `depth` levels of indent. */\n print: (schema: unknown, depth?: number) => string;\n /** The `key?: Type;` members of an object schema, with their JSDoc, at `depth + 1`. */\n members: (\n schema: JsonObject,\n depth: number,\n options?: MemberOptions\n ) => string;\n /** Type aliases for the anonymous defs that refer to themselves. Call last. */\n promoted: () => string[];\n}\n\n/** A TypeScript printer over the subset of JSON Schema `z.toJSONSchema` emits. */\nexport const createTypePrinter = ({\n defs,\n names,\n claim,\n}: TypePrinterOptions): TypePrinter => {\n const promotedNames = new Map<string, string>();\n\n const printRef = (\n id: string,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const named = names.get(id);\n if (named !== undefined) {\n return atom(named);\n }\n const target = ownDef(defs, id);\n if (target === undefined) {\n return atom('unknown');\n }\n if (active.has(id)) {\n const name = promotedNames.get(id) ?? claim(pascalCase(id));\n promotedNames.set(id, name);\n return atom(name);\n }\n return printNode(target, depth, new Set([...active, id]));\n };\n\n const printNode = (\n node: unknown,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n if (node === false) {\n return atom('never');\n }\n if (!isJsonObject(node)) {\n return atom('unknown');\n }\n const parts: Printed[] = [];\n const ref = parseDefRef(node.$ref);\n if (ref !== undefined) {\n parts.push(printRef(ref, depth, active));\n }\n if (STRUCTURAL_KEYS.some((key) => Object.hasOwn(node, key))) {\n parts.push(printStructure(node, depth, active));\n }\n return parts.length === 0 ? atom('unknown') : intersection(parts);\n };\n\n const printStructure = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const parts: Printed[] = [];\n const own = printOwn(node, depth, active);\n if (own) {\n parts.push(own);\n }\n for (const key of ['oneOf', 'anyOf'] as const) {\n const members = node[key];\n if (Array.isArray(members)) {\n parts.push(\n union(members.map((member) => printNode(member, depth, active)))\n );\n }\n }\n if (Array.isArray(node.allOf)) {\n parts.push(\n intersection(\n node.allOf.map((member) => printNode(member, depth, active))\n )\n );\n }\n return parts.length === 0 ? atom('unknown') : intersection(parts);\n };\n\n // `undefined` when the node only combines other schemas.\n const printOwn = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed | undefined => {\n if (Object.hasOwn(node, 'const')) {\n return atom(literal(node.const));\n }\n if (Array.isArray(node.enum)) {\n return union(node.enum.map((value) => atom(literal(value))));\n }\n const { type } = node;\n if (Array.isArray(type)) {\n return union(\n type.map((member) => printTyped(member, node, depth, active))\n );\n }\n if (typeof type === 'string') {\n return printTyped(type, node, depth, active);\n }\n if (\n Object.hasOwn(node, 'properties') ||\n Object.hasOwn(node, 'additionalProperties')\n ) {\n return printObject(node, depth, active);\n }\n if (Object.hasOwn(node, 'items') || Object.hasOwn(node, 'prefixItems')) {\n return printArray(node, depth, active);\n }\n return undefined;\n };\n\n const printTyped = (\n type: unknown,\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n switch (type) {\n case 'string':\n return atom('string');\n case 'number':\n case 'integer':\n return atom('number');\n case 'boolean':\n return atom('boolean');\n case 'null':\n return atom('null');\n case 'array':\n return printArray(node, depth, active);\n case 'object':\n return printObject(node, depth, active);\n default:\n return atom('unknown');\n }\n };\n\n const printArray = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const { prefixItems, items } = node;\n if (Array.isArray(prefixItems)) {\n const required = typeof node.minItems === 'number' ? node.minItems : 0;\n const elements = prefixItems.map((item, index) => {\n const printed = printNode(item, depth, active);\n return index < required\n ? printed.text\n : `${printed.kind === 'atom' ? printed.text : `(${printed.text})`}?`;\n });\n if (items !== undefined && items !== false) {\n elements.push(`...${arrayOf(printNode(items, depth, active)).text}`);\n }\n return atom(`[${elements.join(', ')}]`);\n }\n return arrayOf(\n items === undefined ? atom('unknown') : printNode(items, depth, active)\n );\n };\n\n const printObject = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>\n ): Printed => {\n const properties = isJsonObject(node.properties) ? node.properties : {};\n const lines = printMembers(node, depth, active, {});\n const extra = node.additionalProperties;\n const patterns = isJsonObject(node.patternProperties)\n ? Object.values(node.patternProperties)\n : [];\n const open = extra !== false;\n const values = [\n ...patterns.map((schema) => printNode(schema, depth, active)),\n ];\n if (open) {\n values.push(\n extra === undefined || extra === true\n ? atom('unknown')\n : printNode(extra, depth, active)\n );\n }\n const index =\n values.length === 0\n ? Object.keys(properties).length === 0\n ? `${INDENT.repeat(depth + 1)}[key: string]: never;\\n`\n : ''\n : `${INDENT.repeat(depth + 1)}[key: string]: ${\n union([\n ...values,\n ...Object.values(properties).map((schema) =>\n printNode(schema, depth, active)\n ),\n ...(Object.keys(properties).some(\n (key) =>\n !Array.isArray(node.required) || !node.required.includes(key)\n )\n ? [atom('undefined')]\n : []),\n ]).text\n };\\n`;\n return atom(`{\\n${lines}${index}${INDENT.repeat(depth)}}`);\n };\n\n const printMembers = (\n node: JsonObject,\n depth: number,\n active: ReadonlySet<string>,\n { omit, optional }: MemberOptions\n ): string => {\n const pad = INDENT.repeat(depth + 1);\n const required = new Set(\n Array.isArray(node.required)\n ? node.required.filter((key) => typeof key === 'string')\n : []\n );\n const properties = isJsonObject(node.properties) ? node.properties : {};\n return Object.entries(properties)\n .filter(([key]) => !omit?.has(key))\n .map(([key, property]) => {\n const doc = isJsonObject(property)\n ? jsDoc(\n [\n typeof property.description === 'string'\n ? property.description\n : '',\n ...(Object.hasOwn(property, 'default')\n ? [`@default ${JSON.stringify(property.default)}`]\n : []),\n ],\n pad\n )\n : '';\n const mark = required.has(key) && !optional?.has(key) ? '' : '?';\n return `${doc}${pad}${propertyKey(key)}${mark}: ${\n printNode(property, depth + 1, active).text\n };\\n`;\n })\n .join('');\n };\n\n return {\n print: (schema, depth = 0) => printNode(schema, depth, new Set()).text,\n members: (schema, depth, options = {}) =>\n printMembers(schema, depth, new Set(), options),\n promoted: () => {\n const aliases: string[] = [];\n for (const [id, name] of promotedNames) {\n aliases.push(\n `type ${name} = ${printNode(ownDef(defs, id), 0, new Set([id])).text};`\n );\n }\n return aliases;\n },\n };\n};\n"]}
@@ -41,6 +41,7 @@ exports.ISOMER_ERROR_CODES = {
41
41
  INPUT_OVER_BUDGET: 'INPUT_OVER_BUDGET',
42
42
  INVALID_BODY_NODE: 'INVALID_BODY_NODE',
43
43
  INVALID_FRAME_BODY: 'INVALID_FRAME_BODY',
44
+ INVALID_PACK_GROUPS: 'INVALID_PACK_GROUPS',
44
45
  MISSING_AUTHORED_TEXT: 'MISSING_AUTHORED_TEXT',
45
46
  MISSING_STYLE_ADAPTER: 'MISSING_STYLE_ADAPTER',
46
47
  RESERVED_NODE_FIELD: 'RESERVED_NODE_FIELD',
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/composition/error.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH;;;;;;GAMG;AACU,QAAA,kBAAkB,GAAG;IAChC,eAAe,EAAE,iBAAiB;IAClC,uBAAuB,EAAE,yBAAyB;IAClD,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EA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Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n/**\n * Stable codes for {@link IsomerError}, {@link CompositionValidationError},\n * and the runtime's `RegisteredViewInputError`. Hosts branch on `code`, not\n * on `message`. Codes name the condition, not the throwing module: duplicate\n * type at `definePrimitivePack`, `composePacks`, and `createIsomerRuntime` is the same\n * `DUPLICATE_PRIMITIVE_TYPE`; the message names the layer.\n */\nexport const ISOMER_ERROR_CODES = {\n AMBIGUOUS_FRAME: 'AMBIGUOUS_FRAME',\n AMBIGUOUS_STYLE_ADAPTER: 'AMBIGUOUS_STYLE_ADAPTER',\n AUTHOR_TYPE_MISMATCH: 'AUTHOR_TYPE_MISMATCH',\n AUTHORED_SCHEMA_REUSED: 'AUTHORED_SCHEMA_REUSED',\n COMPOSITION_INVALID: 'COMPOSITION_INVALID',\n CYCLIC_COMPOSITION: 'CYCLIC_COMPOSITION',\n DUPLICATE_AUTHORED_CHILD: 'DUPLICATE_AUTHORED_CHILD',\n DUPLICATE_ENHANCEMENT: 'DUPLICATE_ENHANCEMENT',\n DUPLICATE_FORMAT: 'DUPLICATE_FORMAT',\n DUPLICATE_PACK_ID: 'DUPLICATE_PACK_ID',\n DUPLICATE_PRIMITIVE_TYPE: 'DUPLICATE_PRIMITIVE_TYPE',\n DUPLICATE_VIEW: 'DUPLICATE_VIEW',\n EMPTY_FRAMES: 'EMPTY_FRAMES',\n EMPTY_PACK: 'EMPTY_PACK',\n EMPTY_PACKS: 'EMPTY_PACKS',\n EMPTY_PAGES: 'EMPTY_PAGES',\n EMPTY_VOCABULARY: 'EMPTY_VOCABULARY',\n ENHANCEMENT_ROOT_MISSING: 'ENHANCEMENT_ROOT_MISSING',\n EXPECTED_AUTHOR_COMPONENT: 'EXPECTED_AUTHOR_COMPONENT',\n EXPECTED_JSX_ELEMENT: 'EXPECTED_JSX_ELEMENT',\n EXPECTED_TEXT_CHILDREN: 'EXPECTED_TEXT_CHILDREN',\n INCOMPATIBLE_STYLE_COLLECTOR: 'INCOMPATIBLE_STYLE_COLLECTOR',\n INPUT_NOT_PLAIN_DATA: 'INPUT_NOT_PLAIN_DATA',\n INPUT_OVER_BUDGET: 'INPUT_OVER_BUDGET',\n INVALID_BODY_NODE: 'INVALID_BODY_NODE',\n INVALID_FRAME_BODY: 'INVALID_FRAME_BODY',\n MISSING_AUTHORED_TEXT: 'MISSING_AUTHORED_TEXT',\n MISSING_STYLE_ADAPTER: 'MISSING_STYLE_ADAPTER',\n RESERVED_NODE_FIELD: 'RESERVED_NODE_FIELD',\n UNEXPECTED_CHILDREN: 'UNEXPECTED_CHILDREN',\n UNKNOWN_FRAME: 'UNKNOWN_FRAME',\n UNKNOWN_PRIMITIVE_TYPE: 'UNKNOWN_PRIMITIVE_TYPE',\n UNKNOWN_SURFACE: 'UNKNOWN_SURFACE',\n UNKNOWN_VIEW: 'UNKNOWN_VIEW',\n UNSUPPORTED_CHILD_PATH: 'UNSUPPORTED_CHILD_PATH',\n VIEW_INPUT_INVALID: 'VIEW_INPUT_INVALID',\n VOCABULARY_UNRESOLVED: 'VOCABULARY_UNRESOLVED',\n} as const;\n\n/** One of {@link ISOMER_ERROR_CODES}. */\nexport type IsomerErrorCode =\n (typeof ISOMER_ERROR_CODES)[keyof typeof ISOMER_ERROR_CODES];\n\n/**\n * Thrown for construction and authoring failures that are not a\n * `CompositionValidationError`.\n *\n * Identify it by `name` and `code`, never `instanceof`: the SDK ships both\n * ESM and CJS builds, so a host can hold two copies of this class and an\n * identity check would miss one.\n */\nexport class IsomerError extends Error {\n readonly code: IsomerErrorCode;\n\n constructor(code: IsomerErrorCode, message: string) {\n super(message);\n this.name = 'IsomerError';\n this.code = code;\n }\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/composition/error.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH;;;;;;GAMG;AACU,QAAA,kBAAkB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CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AARD,kCAQC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n/**\n * Stable codes for {@link IsomerError}, {@link CompositionValidationError},\n * and the runtime's `RegisteredViewInputError`. Hosts branch on `code`, not\n * on `message`. Codes name the condition, not the throwing module: duplicate\n * type at `definePrimitivePack`, `composePacks`, and `createIsomerRuntime` is the same\n * `DUPLICATE_PRIMITIVE_TYPE`; the message names the layer.\n */\nexport const ISOMER_ERROR_CODES = {\n AMBIGUOUS_FRAME: 'AMBIGUOUS_FRAME',\n AMBIGUOUS_STYLE_ADAPTER: 'AMBIGUOUS_STYLE_ADAPTER',\n AUTHOR_TYPE_MISMATCH: 'AUTHOR_TYPE_MISMATCH',\n AUTHORED_SCHEMA_REUSED: 'AUTHORED_SCHEMA_REUSED',\n COMPOSITION_INVALID: 'COMPOSITION_INVALID',\n CYCLIC_COMPOSITION: 'CYCLIC_COMPOSITION',\n DUPLICATE_AUTHORED_CHILD: 'DUPLICATE_AUTHORED_CHILD',\n DUPLICATE_ENHANCEMENT: 'DUPLICATE_ENHANCEMENT',\n DUPLICATE_FORMAT: 'DUPLICATE_FORMAT',\n DUPLICATE_PACK_ID: 'DUPLICATE_PACK_ID',\n DUPLICATE_PRIMITIVE_TYPE: 'DUPLICATE_PRIMITIVE_TYPE',\n DUPLICATE_VIEW: 'DUPLICATE_VIEW',\n EMPTY_FRAMES: 'EMPTY_FRAMES',\n EMPTY_PACK: 'EMPTY_PACK',\n EMPTY_PACKS: 'EMPTY_PACKS',\n EMPTY_PAGES: 'EMPTY_PAGES',\n EMPTY_VOCABULARY: 'EMPTY_VOCABULARY',\n ENHANCEMENT_ROOT_MISSING: 'ENHANCEMENT_ROOT_MISSING',\n EXPECTED_AUTHOR_COMPONENT: 'EXPECTED_AUTHOR_COMPONENT',\n EXPECTED_JSX_ELEMENT: 'EXPECTED_JSX_ELEMENT',\n EXPECTED_TEXT_CHILDREN: 'EXPECTED_TEXT_CHILDREN',\n INCOMPATIBLE_STYLE_COLLECTOR: 'INCOMPATIBLE_STYLE_COLLECTOR',\n INPUT_NOT_PLAIN_DATA: 'INPUT_NOT_PLAIN_DATA',\n INPUT_OVER_BUDGET: 'INPUT_OVER_BUDGET',\n INVALID_BODY_NODE: 'INVALID_BODY_NODE',\n INVALID_FRAME_BODY: 'INVALID_FRAME_BODY',\n INVALID_PACK_GROUPS: 'INVALID_PACK_GROUPS',\n MISSING_AUTHORED_TEXT: 'MISSING_AUTHORED_TEXT',\n MISSING_STYLE_ADAPTER: 'MISSING_STYLE_ADAPTER',\n RESERVED_NODE_FIELD: 'RESERVED_NODE_FIELD',\n UNEXPECTED_CHILDREN: 'UNEXPECTED_CHILDREN',\n UNKNOWN_FRAME: 'UNKNOWN_FRAME',\n UNKNOWN_PRIMITIVE_TYPE: 'UNKNOWN_PRIMITIVE_TYPE',\n UNKNOWN_SURFACE: 'UNKNOWN_SURFACE',\n UNKNOWN_VIEW: 'UNKNOWN_VIEW',\n UNSUPPORTED_CHILD_PATH: 'UNSUPPORTED_CHILD_PATH',\n VIEW_INPUT_INVALID: 'VIEW_INPUT_INVALID',\n VOCABULARY_UNRESOLVED: 'VOCABULARY_UNRESOLVED',\n} as const;\n\n/** One of {@link ISOMER_ERROR_CODES}. */\nexport type IsomerErrorCode =\n (typeof ISOMER_ERROR_CODES)[keyof typeof ISOMER_ERROR_CODES];\n\n/**\n * Thrown for construction and authoring failures that are not a\n * `CompositionValidationError`.\n *\n * Identify it by `name` and `code`, never `instanceof`: the SDK ships both\n * ESM and CJS builds, so a host can hold two copies of this class and an\n * identity check would miss one.\n */\nexport class IsomerError extends Error {\n readonly code: IsomerErrorCode;\n\n constructor(code: IsomerErrorCode, message: string) {\n super(message);\n this.name = 'IsomerError';\n this.code = code;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"structured_value.js","sourceRoot":"","sources":["../../../src/composition/structured_value.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwD;AAC3C,QAAA,wBAAwB,GAAG;IACtC,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;IACV,OAAO;IACP,UAAU;IACV,MAAM;IACN,cAAc;CACN,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n/** Format hints a {@link StructuredValue} may carry. */\nexport const STRUCTURED_VALUE_FORMATS = [\n 'number',\n 'compact',\n 'percent',\n 'currency',\n 'bytes',\n 'duration',\n 'date',\n 'relativeTime',\n] as const;\n\n/** One of {@link STRUCTURED_VALUE_FORMATS}. */\nexport type StructuredValueFormat = (typeof STRUCTURED_VALUE_FORMATS)[number];\n\n/**\n * A raw quantity plus a format hint, so every surface renders the same string.\n *\n * Formatting happens once, in `formatDisplayValue`, rather than per renderer —\n * otherwise the text and Slack surfaces drift on rounding.\n */\nexport interface StructuredValue {\n /** Unformatted, in base units — a `percent` of `0.42` renders as 42%. */\n raw: number | string;\n /** How to render `raw`. Absent passes a string through and gives a number default formatting. */\n format?: StructuredValueFormat;\n /**\n * Fraction digits for numeric formats. `number`, `percent`, and `currency`\n * pad to it; omitted, `number` and `percent` keep at most two and `currency`\n * two. `compact` and `bytes` drop trailing zeros and keep one when omitted.\n */\n precision?: number;\n /** Three-letter currency code for `currency`; defaults to USD. */\n currency?: string;\n}\n\n/** A value-bearing field: preformatted prose, or a {@link StructuredValue} to format. */\nexport type DisplayValue = string | StructuredValue;\n"]}
1
+ {"version":3,"file":"structured_value.js","sourceRoot":"","sources":["../../../src/composition/structured_value.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwD;AAC3C,QAAA,wBAAwB,GAAG;IACtC,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;IACV,OAAO;IACP,UAAU;IACV,MAAM;IACN,cAAc;CACN,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n/** Format hints a {@link StructuredValue} may carry. */\nexport const STRUCTURED_VALUE_FORMATS = [\n 'number',\n 'compact',\n 'percent',\n 'currency',\n 'bytes',\n 'duration',\n 'date',\n 'relativeTime',\n] as const;\n\n/** One of {@link STRUCTURED_VALUE_FORMATS}. */\nexport type StructuredValueFormat = (typeof STRUCTURED_VALUE_FORMATS)[number];\n\n/**\n * A raw quantity plus a format hint, so every surface renders the same string.\n *\n * Formatting happens once, in `formatDisplayValue`, rather than per renderer —\n * otherwise the text and Slack surfaces drift on rounding.\n */\nexport interface StructuredValue {\n /** Unformatted, in base units — a `percent` of `0.42` renders as 42%. */\n raw: number | string;\n /** How to render `raw`. Absent passes a string through and gives a number default formatting. */\n format?: StructuredValueFormat | undefined;\n /**\n * Fraction digits for numeric formats. `number`, `percent`, and `currency`\n * pad to it; omitted, `number` and `percent` keep at most two and `currency`\n * two. `compact` and `bytes` drop trailing zeros and keep one when omitted.\n */\n precision?: number | undefined;\n /** Three-letter currency code for `currency`; defaults to USD. */\n currency?: string | undefined;\n}\n\n/** A value-bearing field: preformatted prose, or a {@link StructuredValue} to format. */\nexport type DisplayValue = string | StructuredValue;\n"]}
@@ -62,10 +62,14 @@ exports.unresolvedBodyNodeSchema = zod_1.z.looseObject({
62
62
  * {@link PackTypes}, so each primitive names only `TNode`.
63
63
  */
64
64
  const definePrimitive = (definition) => {
65
- const { schemaFor } = definition;
65
+ const { schemaFor, schema, catalog } = definition;
66
+ const described = catalog.description === undefined ? schema.description : undefined;
66
67
  return {
67
68
  ...definition,
68
- schema: withNodeFields(definition.schema),
69
+ ...(described === undefined
70
+ ? {}
71
+ : { catalog: { ...catalog, description: described } }),
72
+ schema: withNodeFields(schema),
69
73
  // Both forms get the node fields, or a container would accept `id` and
70
74
  // `surfaces` standalone and reject them inside a composition.
71
75
  ...(schemaFor
@@ -98,11 +102,13 @@ const NODE_FIELDS = {
98
102
  const isNodeField = (schema) => {
99
103
  let current = schema;
100
104
  while (current && typeof current === 'object') {
101
- if (Object.hasOwn(current, NODE_FIELD))
105
+ if (Object.hasOwn(current, NODE_FIELD)) {
102
106
  return true;
107
+ }
103
108
  const { def } = current;
104
- if (def?.type !== 'optional')
109
+ if (def?.type !== 'optional') {
105
110
  return false;
111
+ }
106
112
  current = def.innerType;
107
113
  }
108
114
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"primitive_module.js","sourceRoot":"","sources":["../../../src/define/primitive_module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,6BAAsD;AAGtD,kEAIuC;AACvC,gDAAuE;AASvE,6CAAsD;AACtD,+CAA+C;AAgP/C;;;;;;;GAOG;AACU,QAAA,iBAAiB,GAAG;IAC/B,OAAO;CACkC,CAAC;AAwL5C,oFAAoF;AAC7E,MAAM,kBAAkB,GAAG,CAChC,MAAuB,EACvB,IAAa,EACb,IAAY,EACZ,MAAyB,EACnB,EAAE;IACR,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,GAAG,IAAA,4BAAe,EAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,kBAAkB,sBAU7B;AAEF,kEAAkE;AACrD,QAAA,gBAAgB,GAAG,IAAA,4BAAc,EAAC,4BAA4B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AK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,CACtC,CAAC;AAC/B,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { ReactNode } from 'react';\nimport { z, type ZodObject, type ZodType } from 'zod';\n\nimport type { ActionEventRef } from '../composition/action_event';\nimport {\n type ChildNodeRef,\n SURFACE_NAMES,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport { ISOMER_ERROR_CODES, IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../composition/node';\nimport type { ValidationError } from '../composition/validation_error';\n\nimport type { MarkdownContent } from './markdown_content';\nimport type { PrimitiveExample } from './primitive_example';\nimport type { PrimitiveIcon } from './primitive_icon';\nimport type { SlackAssetCollector } from './slack_assets';\nimport type { SlackBlock } from './slack_blocks';\nimport { formatZodIssues, oneOf } from './zod_format';\nimport { requiredString } from './zod_helpers';\n\nexport type { PrimitiveNode };\n\n/**\n * A primitive's entry in the catalog the authoring prompt is built from.\n *\n * Written for the model rather than for a developer: `useWhen` and `avoidWhen`\n * are what steer it away from reaching for the wrong primitive. `name` is the\n * one host-facing field, and the prompt never prints it.\n */\nexport interface PrimitiveCatalogEntry {\n type: string;\n /** Short name a host shows for the primitive, e.g. `Stat group`. Absent means the host derives one from `type`. */\n name?: string;\n /** One line on what the primitive is for, in the model's voice. */\n purpose: string;\n /** Situations that call for this primitive. Phrase each as a user intent, not a shape. */\n useWhen: string[];\n /** Situations that look like a fit but are not, naming the primitive to reach for instead. */\n avoidWhen: string[];\n /** A node literal the authoring prompt inlines under this primitive. */\n example: unknown;\n}\n\n/** A style a renderer asks for by name, resolved to a class by the host's adapter. */\nexport interface StyleHandle {\n /** Stable lookup key. The adapter's map is keyed on this. */\n key: string;\n /** Debug-facing label, which an adapter may fold into a generated class name. */\n readableName: string;\n}\n\n/** Dotted path into a pack's theme tokens, e.g. `colors.text.subdued`. */\nexport type ThemeTokenPath = string;\n\n/**\n * The sdk's own render context, and {@link DefaultPackTypes.context}.\n *\n * A pack with real theme tokens or a richer style-handle type declares its\n * own context in its {@link PackTypes}; {@link StyledRenderContext} is the\n * sdk's own extension. The bag is what lets a pack narrow without\n * re-declaring everything that mentions a context.\n */\nexport interface PrimitiveRenderContext {\n /**\n * The progressive enhancements this render may assume, by id. A set rather\n * than a field per feature so adding an enhancement costs no plumbing:\n * containers forward the whole context, and a renderer asks\n * `context.enhancements?.has('tableSort')`.\n *\n * Empty or absent is the baseline every host can render, so a renderer must\n * still answer the question on its own. See `docs/rendering.md`.\n */\n enhancements?: ReadonlySet<string>;\n /** Turns on `nodeAnchor` outside an HTML surface render, on the React and `snapshot` surfaces; inside one, the surface decides. */\n anchors?: boolean;\n /** Raises an interaction for the host to route. Absent means render non-interactively. */\n onEvent?: (event: ActionEventRef) => void;\n}\n\n/**\n * The render-context argument, optional only when omitting it is sound.\n *\n * The sdk's own {@link PrimitiveRenderContext} has no required field, so `{}`\n * is a complete value and a caller may leave it out. A pack that narrows the\n * context with a required member makes the argument mandatory.\n */\nexport type ReactContextArg<TContext> =\n Record<string, never> extends TContext\n ? [context?: TContext]\n : [context: TContext];\n\n/**\n * {@link PrimitiveRenderContext} plus the CSS-in-JS hooks an HTML style adapter\n * supplies. A pack that styles differently uses its own `TContext` instead.\n */\nexport interface StyledRenderContext extends PrimitiveRenderContext {\n /** Resolves handles to a `className`. Absent means the host supplies no styling. */\n resolveClassName?: (...handles: StyleHandle[]) => string;\n /** Resolves a theme token to a CSS variable reference. Absent means inline the literal value. */\n cssVarRef?: (path: ThemeTokenPath) => `var(--${string})`;\n}\n\n/** Passed to a primitive's style collector so it can vary CSS by layout mode. */\nexport interface PrimitiveStyleCollectionContext {\n /** The render fills its container rather than sitting at a fixed width. */\n fluid?: boolean;\n}\n\n/** A pack's collected styles, opaque to the SDK. */\nexport type PrimitiveStyleCollector = object;\n\n/**\n * The types a pack binds once and writes every primitive against: the palette\n * its frames supply, the context its `react` renderers receive, the collector\n * its `collectStyles` hooks mutate, and the Slack payload and collector types.\n *\n * Extend {@link DefaultPackTypes} and narrow only what the pack needs:\n *\n * ```ts\n * interface SlidesPackTypes extends DefaultPackTypes {\n * theme: SlideTheme;\n * context: SlideRenderContext;\n * }\n * ```\n */\nexport interface PackTypes {\n theme: unknown;\n context: unknown;\n collector: PrimitiveStyleCollector;\n slackBlock: unknown;\n slackCollector: unknown;\n}\n\n/** {@link PackTypes} as the sdk itself binds them, and the default everywhere. */\nexport interface DefaultPackTypes extends PackTypes {\n theme: unknown;\n context: PrimitiveRenderContext;\n collector: PrimitiveStyleCollector;\n slackBlock: SlackBlock;\n slackCollector: SlackAssetCollector;\n}\n\n/**\n * Each surface's renderer signature: the env bag it receives beyond the node,\n * and what it returns.\n *\n * Written out per surface rather than derived through an indexed access. A bag\n * is additive: a new extra on a surface is not an arity break. {@link Renderer}\n * indexes this table for the dispatcher cast; {@link Renderers} does not.\n */\nexport interface SurfaceMap<T extends PackTypes = DefaultPackTypes> {\n react: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /**\n * The frame's resolved palette, when this render is reached through the\n * `snapshot` surface. A bare `react`/`html` render has no {@link Frame} to\n * resolve one from, so it is absent there — a pack that needs a\n * literal color outside `snapshot` still goes through `context`.\n */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n /**\n * Identical to `react`, and served by the same renderer: an image backend\n * lays out the pack's DOM tree and stylesheet rather than a second tree\n * authored for it. The surface stays separate so a node can be hidden from\n * snapshots alone, and so a {@link Frame} has something to draw inside.\n */\n snapshot: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** The frame's resolved palette for this render's mode; see `react.env.theme`. */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n text: {\n env: {\n scope: RenderScope<T>;\n };\n output: string;\n };\n /** Content built with `md`, escaped where it lands; authored Markdown source goes through `md.authored`. */\n markdown: {\n env: {\n scope: RenderScope<T>;\n };\n output: MarkdownContent;\n };\n /**\n * Returns one payload or several, so a primitive need not wrap a single\n * payload in an array.\n */\n slack: {\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n };\n output: T['slackBlock'] | readonly T['slackBlock'][];\n };\n}\n\n/**\n * The dispatcher a renderer is given so a container can recurse into a child\n * owned by another pack. Erased to {@link PrimitiveNode}: a heterogeneous\n * inventory has no single node type to name.\n *\n * Passed as `scope` on every renderer's env bag. The dispatcher's own named\n * methods stay positional.\n */\nexport interface RenderScope<T extends PackTypes = DefaultPackTypes> {\n readonly definitions: readonly AnyPrimitiveDefinition[];\n /** Throws for an unknown node type; a missing primitive is a bug, not a degradation. */\n getDefinition(node: PrimitiveNode): AnyPrimitiveDefinition;\n /** `undefined` when the node is hidden from `surface`, `sanitize` drops it, or its primitive declares no renderer for `surface`. */\n renderOn<S extends SurfaceName>(\n surface: S,\n node: PrimitiveNode,\n extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>\n ): SurfaceMap<T>[S]['output'] | undefined;\n renderReact(node: PrimitiveNode, context?: T['context']): ReactNode;\n collectStyles(\n node: PrimitiveNode,\n styles: PrimitiveStyleCollector,\n context: PrimitiveStyleCollectionContext\n ): void;\n renderText(node: PrimitiveNode): string;\n renderMarkdown(node: PrimitiveNode): string;\n /** A child as content, for a container building with `md`. */\n renderMarkdownContent(node: PrimitiveNode): MarkdownContent;\n /** Empty when the node is hidden from `slack`, `sanitize` drops it, or its renderer returns nothing; a node with no `slack` renderer degrades through its markdown. */\n renderSlack(\n node: PrimitiveNode,\n collector?: T['slackCollector']\n ): readonly T['slackBlock'][];\n /** `0` when the node is hidden from `snapshot` or its primitive declares no `metrics.snapshotHeight`. */\n estimateSnapshotHeight(node: PrimitiveNode): number;\n /** Appends schema failures under `path` to `errors`, each naming `node`'s type. */\n validate(node: PrimitiveNode, path: string, errors: ValidationError[]): void;\n}\n\n/**\n * One surface's renderer for one node type, per {@link SurfaceMap}.\n *\n * Indexes the env bag. Do not use this to type the renderers map: the\n * written-out signatures on {@link Renderers} are what keep the bags checked\n * per surface.\n */\nexport type Renderer<\n TNode extends PrimitiveNode,\n S extends SurfaceName,\n T extends PackTypes = DefaultPackTypes,\n> = (node: TNode, env: SurfaceMap<T>[S]['env']) => SurfaceMap<T>[S]['output'];\n\n/**\n * The surface a pack may declare beyond the mandatory three.\n *\n * Only `slack`, and even that stays optional per primitive: the dispatcher\n * converts the mandatory markdown to Block Kit, so a missing Slack renderer\n * degrades rather than disappearing. `snapshot` is not here because no primitive\n * implements it — the surface reuses `react`.\n */\nexport const OPTIONAL_SURFACES = [\n 'slack',\n] as const satisfies readonly SurfaceName[];\n\n/** One of the {@link OPTIONAL_SURFACES}. */\nexport type OptionalSurface = (typeof OPTIONAL_SURFACES)[number];\n\n/**\n * One renderer per surface a primitive implements.\n *\n * `react`, `text`, and `markdown` are always required: those three are what\n * make \"every composition degrades\" true. `react` serves the `snapshot` surface\n * too, so targeting images costs a primitive nothing.\n *\n * `slack` is declared method-style deliberately: method parameters are checked\n * bivariantly, which is what lets a pack narrow the collector's node type.\n */\nexport interface Renderers<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n> {\n react(\n node: TNode,\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** See {@link SurfaceMap.react}'s `env.theme`. */\n theme?: T['theme'];\n }\n ): ReactNode;\n text(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): string;\n markdown(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): MarkdownContent;\n slack?(\n node: TNode,\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n }\n ): T['slackBlock'] | readonly T['slackBlock'][];\n}\n\n/**\n * Measurements a frame can ask of a node before drawing it.\n *\n * `snapshotHeight` is optional. The height estimate is `0` when it is missing, so\n * a frame that sums node heights sizes short.\n */\nexport interface PrimitiveMetrics<TNode extends PrimitiveNode> {\n /** The node's drawn height in pixels at the frame's width. */\n snapshotHeight?: (node: TNode) => number;\n}\n\n/**\n * Every primitive's schema is an object schema, because {@link definePrimitive}\n * extends it with `id` and `surfaces` and the composition builds a\n * `z.discriminatedUnion('type', …)` over them. Typed as `ZodObject` rather\n * than `ZodType<unknown>` so a union or intersection schema is a compile\n * error at the definition, not a runtime failure at the first `.extend()`.\n * Zod 4 types `z.object().superRefine(…)` as a `ZodObject` and preserves the\n * refinement through `.extend()`, so top-level refinements are unaffected.\n */\nexport type PrimitiveSchema = ZodObject;\n\n/**\n * The child-ref shape a primitive definition's own `children` returns.\n *\n * {@link ChildNodeRef} stays erased (`node: unknown`) because\n * `createChildNodeWalker` mixes children from every primitive type in the\n * runtime into one map and cannot name a single node type for them. A single\n * definition has no such excuse: its `children` should not type-check\n * against `unknown` and let something that is not a {@link PrimitiveNode} —\n * `null`, for instance — silently disappear from every tree walk.\n */\nexport interface PrimitiveChildRef extends ChildNodeRef {\n node: PrimitiveNode;\n}\n\n/**\n * One primitive: its node type, schema, catalog entry, and a renderer per\n * surface. The unit of vocabulary, and what {@link definePrimitive} takes.\n *\n * `T` is the pack's {@link PackTypes}, bound once with\n * {@link definePrimitiveFor} so each primitive names only `TNode`.\n */\nexport interface PrimitiveDefinition<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n> {\n /** The node's discriminant, and the key this primitive occupies in an inventory. */\n type: TNode['type'];\n /** How the authoring prompt describes this primitive to the model. */\n catalog: PrimitiveCatalogEntry;\n /** Host-facing glyph, never shown to the model. Absent means the host supplies its own. */\n icon?: PrimitiveIcon;\n /**\n * Driven by the conformance harness, bare or named; read them with\n * `exampleNodes` or `primitiveExamples`. The catalog `example` is what the\n * prompt shows.\n */\n examples: readonly (TNode | PrimitiveExample<TNode>)[];\n /**\n * This primitive on its own. A container declares\n * {@link PrimitiveDefinition.schemaFor} as well, and uses\n * {@link unresolvedBodyNodeSchema} in the child slot here.\n */\n schema: TSchema;\n /**\n * A container's schema, bound to the body-node union of the composition it is\n * being built into.\n *\n * Declaring the shape and letting each composition supply its own union is\n * what lets one primitive appear in two runtimes with different inventories:\n * `z.lazy` memoizes per instance, and an instance built here belongs to\n * exactly one union.\n */\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n /** One function per surface; `react` serves `snapshot` as well. */\n renderers: Renderers<TNode, T>;\n /** Sizing a frame can ask for before drawing. Absent means it cannot be measured. */\n metrics?: PrimitiveMetrics<TNode>;\n /**\n * Render-time URL trust, the second of the two layers in `validate/url.ts`.\n *\n * Returning `null` drops the node. Applied even to an unvalidated node, so a\n * renderer invoked directly still cannot emit an unsafe URL.\n */\n sanitize?: (node: TNode) => TNode | null;\n /**\n * Nested nodes, for containers, in the order the `react` renderer draws\n * them; `findNodeElementPairs` relies on it. Absent means a leaf.\n */\n children?: (node: TNode) => readonly PrimitiveChildRef[];\n /**\n * True when this node produces surface output of its own, not only via\n * {@link PrimitiveDefinition.children}. A non-empty `children` result is\n * otherwise the complete source of rendered content, so a hybrid container\n * that still owns string fields returns true to keep rendering when every\n * nested node is hidden from the surface.\n */\n hasOwnContent?: (node: TNode) => boolean;\n /** Contributes this node's CSS by mutating `styles`, once per node per render. */\n collectStyles?: (\n node: TNode,\n env: { styles: T['collector']; context: PrimitiveStyleCollectionContext }\n ) => void;\n}\n\n/**\n * {@link PrimitiveDefinition} with every type parameter erased, and the form an\n * inventory is stored in.\n *\n * A heterogeneous pack has no single `TNode` to be generic over, so the\n * renderers degrade to `unknown` here.\n *\n * Each field carries the same contract as its {@link PrimitiveDefinition}\n * counterpart; only the types are erased.\n */\nexport interface AnyPrimitiveDefinition {\n type: string;\n catalog: PrimitiveCatalogEntry;\n icon?: PrimitiveIcon;\n examples: readonly (PrimitiveNode | PrimitiveExample)[];\n schema: PrimitiveSchema;\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n renderers: Record<'react' | 'text' | 'markdown', unknown> &\n Partial<Record<'slack', unknown>>;\n metrics?: {\n snapshotHeight?: unknown;\n };\n sanitize?: unknown;\n children?: unknown;\n hasOwnContent?: unknown;\n collectStyles?: unknown;\n}\n\n/** Parses `node` against `schema`, appending path-prefixed messages to `errors`. */\nexport const validateWithSchema = (\n schema: PrimitiveSchema,\n node: unknown,\n path: string,\n errors: ValidationError[]\n): void => {\n const result = schema.safeParse(node, { reportInput: true });\n if (!result.success) {\n errors.push(...formatZodIssues(result.error.issues, path));\n }\n};\n\n/** The `id` every node may carry, unique within a composition. */\nexport const bodyNodeIdSchema = requiredString('must be a non-empty string');\n\n/** The `surfaces` allowlist on a node. Absent means every surface; empty is rejected. */\nexport const bodyNodeSurfacesSchema = z\n .array(\n z.enum(SURFACE_NAMES, {\n error: () => oneOf(SURFACE_NAMES),\n })\n )\n .min(1, { error: 'must contain at least one surface' });\n\n/**\n * The child slot in a container's standalone {@link PrimitiveDefinition.schema},\n * where no body-node union is available.\n *\n * Deliberately permissive rather than `z.unknown()`: it still rejects a child\n * that is not a node at all, which is the error worth catching without an\n * inventory. Anything that depends on *which* types are legal — the validator,\n * the parser, the JSON Schema projection — goes through\n * {@link PrimitiveDefinition.schemaFor} and sees the real union.\n */\nexport const unresolvedBodyNodeSchema = z.looseObject({\n type: requiredString('must be a non-empty string'),\n});\n\n/**\n * Declares one primitive, extending its schema with the `id` and `surfaces`\n * fields every node carries, and closing it to unknown keys so a node is held\n * to the same rule as the composition root and the JSON Schema an agent reads.\n * A schema with its own catchall (`z.looseObject`) keeps it.\n *\n * A pack normally calls the form {@link definePrimitiveFor} binds to its own\n * {@link PackTypes}, so each primitive names only `TNode`.\n */\nexport const definePrimitive = <\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n>(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> => {\n const { schemaFor } = definition;\n return {\n ...definition,\n schema: withNodeFields(definition.schema),\n // Both forms get the node fields, or a container would accept `id` and\n // `surfaces` standalone and reject them inside a composition.\n ...(schemaFor\n ? {\n schemaFor: (bodyNodeSchema: ZodType<unknown>) =>\n withNodeFields(schemaFor(bodyNodeSchema)),\n }\n : {}),\n };\n};\n\n/**\n * {@link definePrimitive} bound to one pack's {@link PackTypes}.\n *\n * ```ts\n * const define = definePrimitiveFor<SlidesPackTypes>();\n * export const note = define({ type: 'note', … });\n * ```\n */\nexport const definePrimitiveFor =\n <T extends PackTypes>() =>\n <\n TNode extends PrimitiveNode,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n >(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n ): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> =>\n definePrimitive<TNode, T, TSchema>(definition);\n\n/**\n * `.extend()` on a generic `ZodObject` widens the shape to `any`, so the\n * return type is rebuilt from `TSchema`'s shape. The brand on a field schema\n * stays on that same object at runtime.\n */\nexport type WithNodeFields<TSchema extends PrimitiveSchema> =\n TSchema extends ZodObject<infer Shape>\n ? ZodObject<\n Shape & {\n id: ReturnType<typeof bodyNodeIdSchema.optional>;\n surfaces: ReturnType<typeof bodyNodeSurfacesSchema.optional>;\n }\n >\n : PrimitiveSchema;\n\n// Marks the field schemas `definePrimitive` adds. A schema derived from a\n// defined one shares them by reference, and `Symbol.for` matches across ESM and\n// CommonJS copies of the SDK.\nconst NODE_FIELD = Symbol.for('elastic.isomer.node_field');\n\nconst nodeField = <T extends ZodType>(schema: T): T =>\n Object.defineProperty(schema, NODE_FIELD, { value: true });\n\nconst NODE_FIELDS = {\n id: nodeField(bodyNodeIdSchema.optional()),\n surfaces: nodeField(bodyNodeSurfacesSchema.optional()),\n};\n\nconst isNodeField = (schema: unknown): boolean => {\n let current = schema;\n while (current && typeof current === 'object') {\n if (Object.hasOwn(current, NODE_FIELD)) return true;\n const { def } = current as {\n def?: { type?: string; innerType?: unknown };\n };\n if (def?.type !== 'optional') return false;\n current = def.innerType;\n }\n return false;\n};\n\nconst withNodeFields = <TSchema extends PrimitiveSchema>(\n schema: TSchema\n): WithNodeFields<TSchema> => {\n const reserved = Object.keys(NODE_FIELDS).find(\n (field) =>\n Object.hasOwn(schema.shape, field) && !isNodeField(schema.shape[field])\n );\n if (reserved) {\n throw new IsomerError(\n ISOMER_ERROR_CODES.RESERVED_NODE_FIELD,\n `definePrimitive: a primitive schema cannot declare \\`${reserved}\\`; every body node has it.`\n );\n }\n const extended = schema.extend(NODE_FIELDS);\n return (\n schema.def.catchall === undefined ? extended.strict() : extended\n ) as WithNodeFields<TSchema>;\n};\n"]}
1
+ {"version":3,"file":"primitive_module.js","sourceRoot":"","sources":["../../../src/define/primitive_module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,6BAAsD;AAGtD,kEAIuC;AACvC,gDAAuE;AASvE,6CAAsD;AACtD,+CAA+C;AAuP/C;;;;;;;GAOG;AACU,QAAA,iBAAiB,GAAG;IAC/B,OAAO;CACkC,CAAC;AAwL5C,oFAAoF;AAC7E,MAAM,kBAAkB,GAAG,CAChC,MAAuB,EACvB,IAAa,EACb,IAAY,EACZ,MAAyB,EACnB,EAAE;IACR,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,GAAG,IAAA,4BAAe,EAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,kBAAkB,sBAU7B;AAEF,kEAAkE;AACrD,QAAA,gBAAgB,GAAG,IAAA,4BAAc,EAAC,4BAA4B,CAAC,CAAC;AAE7E,yFAAyF;AAC5E,QAAA,sBAAsB,GAAG,OAAC;KACpC,KAAK,CAC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IACF,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,IAAI,mBAAW,CACnB,0BAAkB,CAAC,mBAAmB,EACtC,wDAAwD,QAAQ,6BAA6B,CAC9F,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5C,OAAO,CACL,MAAM,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,CACtC,CAAC;AAC/B,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { ReactNode } from 'react';\nimport { z, type ZodObject, type ZodType } from 'zod';\n\nimport type { ActionEventRef } from '../composition/action_event';\nimport {\n type ChildNodeRef,\n SURFACE_NAMES,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport { ISOMER_ERROR_CODES, IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../composition/node';\nimport type { ValidationError } from '../composition/validation_error';\n\nimport type { MarkdownContent } from './markdown_content';\nimport type { PrimitiveExample } from './primitive_example';\nimport type { PrimitiveIcon } from './primitive_icon';\nimport type { SlackAssetCollector } from './slack_assets';\nimport type { SlackBlock } from './slack_blocks';\nimport { formatZodIssues, oneOf } from './zod_format';\nimport { requiredString } from './zod_helpers';\n\nexport type { PrimitiveNode };\n\n/**\n * A primitive's entry in the catalog the authoring prompt is built from.\n *\n * Written for the model rather than for a developer: `useWhen` and `avoidWhen`\n * are what steer it away from reaching for the wrong primitive. `name` is the\n * one host-facing field, and the prompt never prints it.\n */\nexport interface PrimitiveCatalogEntry {\n type: string;\n /** Short name a host shows for the primitive, e.g. `Stat group`. Absent means the host derives one from `type`. */\n name?: string;\n /**\n * Description of this primitive's `$def` in the authoring JSON Schema.\n *\n * `z.toJSONSchema` drops refinements, so a cross-field rule is restated here.\n * {@link definePrimitive} copies `schema.description` when this is omitted.\n */\n description?: string;\n /** One line on what the primitive is for, in the model's voice. */\n purpose: string;\n /** Situations that call for this primitive. Phrase each as a user intent, not a shape. */\n useWhen: string[];\n /** Situations that look like a fit but are not, naming the primitive to reach for instead. */\n avoidWhen: string[];\n /** A node literal the authoring prompt inlines under this primitive. */\n example: unknown;\n}\n\n/** A style a renderer asks for by name, resolved to a class by the host's adapter. */\nexport interface StyleHandle {\n /** Stable lookup key. The adapter's map is keyed on this. */\n key: string;\n /** Debug-facing label, which an adapter may fold into a generated class name. */\n readableName: string;\n}\n\n/** Dotted path into a pack's theme tokens, e.g. `colors.text.subdued`. */\nexport type ThemeTokenPath = string;\n\n/**\n * The sdk's own render context, and {@link DefaultPackTypes.context}.\n *\n * A pack with real theme tokens or a richer style-handle type declares its\n * own context in its {@link PackTypes}; {@link StyledRenderContext} is the\n * sdk's own extension. The bag is what lets a pack narrow without\n * re-declaring everything that mentions a context.\n */\nexport interface PrimitiveRenderContext {\n /**\n * The progressive enhancements this render may assume, by id. A set rather\n * than a field per feature so adding an enhancement costs no plumbing:\n * containers forward the whole context, and a renderer asks\n * `context.enhancements?.has('tableSort')`.\n *\n * Empty or absent is the baseline every host can render, so a renderer must\n * still answer the question on its own. See `docs/rendering.md`.\n */\n enhancements?: ReadonlySet<string>;\n /** Turns on `nodeAnchor` outside an HTML surface render, on the React and `snapshot` surfaces; inside one, the surface decides. */\n anchors?: boolean;\n /** Raises an interaction for the host to route. Absent means render non-interactively. */\n onEvent?: (event: ActionEventRef) => void;\n}\n\n/**\n * The render-context argument, optional only when omitting it is sound.\n *\n * The sdk's own {@link PrimitiveRenderContext} has no required field, so `{}`\n * is a complete value and a caller may leave it out. A pack that narrows the\n * context with a required member makes the argument mandatory.\n */\nexport type ReactContextArg<TContext> =\n Record<string, never> extends TContext\n ? [context?: TContext]\n : [context: TContext];\n\n/**\n * {@link PrimitiveRenderContext} plus the CSS-in-JS hooks an HTML style adapter\n * supplies. A pack that styles differently uses its own `TContext` instead.\n */\nexport interface StyledRenderContext extends PrimitiveRenderContext {\n /** Resolves handles to a `className`. Absent means the host supplies no styling. */\n resolveClassName?: (...handles: StyleHandle[]) => string;\n /** Resolves a theme token to a CSS variable reference. Absent means inline the literal value. */\n cssVarRef?: (path: ThemeTokenPath) => `var(--${string})`;\n}\n\n/** Passed to a primitive's style collector so it can vary CSS by layout mode. */\nexport interface PrimitiveStyleCollectionContext {\n /** The render fills its container rather than sitting at a fixed width. */\n fluid?: boolean;\n}\n\n/** A pack's collected styles, opaque to the SDK. */\nexport type PrimitiveStyleCollector = object;\n\n/**\n * The types a pack binds once and writes every primitive against: the palette\n * its frames supply, the context its `react` renderers receive, the collector\n * its `collectStyles` hooks mutate, and the Slack payload and collector types.\n *\n * Extend {@link DefaultPackTypes} and narrow only what the pack needs:\n *\n * ```ts\n * interface SlidesPackTypes extends DefaultPackTypes {\n * theme: SlideTheme;\n * context: SlideRenderContext;\n * }\n * ```\n */\nexport interface PackTypes {\n theme: unknown;\n context: unknown;\n collector: PrimitiveStyleCollector;\n slackBlock: unknown;\n slackCollector: unknown;\n}\n\n/** {@link PackTypes} as the sdk itself binds them, and the default everywhere. */\nexport interface DefaultPackTypes extends PackTypes {\n theme: unknown;\n context: PrimitiveRenderContext;\n collector: PrimitiveStyleCollector;\n slackBlock: SlackBlock;\n slackCollector: SlackAssetCollector;\n}\n\n/**\n * Each surface's renderer signature: the env bag it receives beyond the node,\n * and what it returns.\n *\n * Written out per surface rather than derived through an indexed access. A bag\n * is additive: a new extra on a surface is not an arity break. {@link Renderer}\n * indexes this table for the dispatcher cast; {@link Renderers} does not.\n */\nexport interface SurfaceMap<T extends PackTypes = DefaultPackTypes> {\n react: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /**\n * The frame's resolved palette, when this render is reached through the\n * `snapshot` surface. A bare `react`/`html` render has no {@link Frame} to\n * resolve one from, so it is absent there — a pack that needs a\n * literal color outside `snapshot` still goes through `context`.\n */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n /**\n * Identical to `react`, and served by the same renderer: an image backend\n * lays out the pack's DOM tree and stylesheet rather than a second tree\n * authored for it. The surface stays separate so a node can be hidden from\n * snapshots alone, and so a {@link Frame} has something to draw inside.\n */\n snapshot: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** The frame's resolved palette for this render's mode; see `react.env.theme`. */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n text: {\n env: {\n scope: RenderScope<T>;\n };\n output: string;\n };\n /** Content built with `md`, escaped where it lands; authored Markdown source goes through `md.authored`. */\n markdown: {\n env: {\n scope: RenderScope<T>;\n };\n output: MarkdownContent;\n };\n /**\n * Returns one payload or several, so a primitive need not wrap a single\n * payload in an array.\n */\n slack: {\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n };\n output: T['slackBlock'] | readonly T['slackBlock'][];\n };\n}\n\n/**\n * The dispatcher a renderer is given so a container can recurse into a child\n * owned by another pack. Erased to {@link PrimitiveNode}: a heterogeneous\n * inventory has no single node type to name.\n *\n * Passed as `scope` on every renderer's env bag. The dispatcher's own named\n * methods stay positional.\n */\nexport interface RenderScope<T extends PackTypes = DefaultPackTypes> {\n readonly definitions: readonly AnyPrimitiveDefinition[];\n /** Throws for an unknown node type; a missing primitive is a bug, not a degradation. */\n getDefinition(node: PrimitiveNode): AnyPrimitiveDefinition;\n /** `undefined` when the node is hidden from `surface`, `sanitize` drops it, or its primitive declares no renderer for `surface`. */\n renderOn<S extends SurfaceName>(\n surface: S,\n node: PrimitiveNode,\n extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>\n ): SurfaceMap<T>[S]['output'] | undefined;\n renderReact(node: PrimitiveNode, context?: T['context']): ReactNode;\n collectStyles(\n node: PrimitiveNode,\n styles: PrimitiveStyleCollector,\n context: PrimitiveStyleCollectionContext\n ): void;\n renderText(node: PrimitiveNode): string;\n renderMarkdown(node: PrimitiveNode): string;\n /** A child as content, for a container building with `md`. */\n renderMarkdownContent(node: PrimitiveNode): MarkdownContent;\n /** Empty when the node is hidden from `slack`, `sanitize` drops it, or its renderer returns nothing; a node with no `slack` renderer degrades through its markdown. */\n renderSlack(\n node: PrimitiveNode,\n collector?: T['slackCollector']\n ): readonly T['slackBlock'][];\n /** `0` when the node is hidden from `snapshot` or its primitive declares no `metrics.snapshotHeight`. */\n estimateSnapshotHeight(node: PrimitiveNode): number;\n /** Appends schema failures under `path` to `errors`, each naming `node`'s type. */\n validate(node: PrimitiveNode, path: string, errors: ValidationError[]): void;\n}\n\n/**\n * One surface's renderer for one node type, per {@link SurfaceMap}.\n *\n * Indexes the env bag. Do not use this to type the renderers map: the\n * written-out signatures on {@link Renderers} are what keep the bags checked\n * per surface.\n */\nexport type Renderer<\n TNode extends PrimitiveNode,\n S extends SurfaceName,\n T extends PackTypes = DefaultPackTypes,\n> = (node: TNode, env: SurfaceMap<T>[S]['env']) => SurfaceMap<T>[S]['output'];\n\n/**\n * The surface a pack may declare beyond the mandatory three.\n *\n * Only `slack`, and even that stays optional per primitive: the dispatcher\n * converts the mandatory markdown to Block Kit, so a missing Slack renderer\n * degrades rather than disappearing. `snapshot` is not here because no primitive\n * implements it — the surface reuses `react`.\n */\nexport const OPTIONAL_SURFACES = [\n 'slack',\n] as const satisfies readonly SurfaceName[];\n\n/** One of the {@link OPTIONAL_SURFACES}. */\nexport type OptionalSurface = (typeof OPTIONAL_SURFACES)[number];\n\n/**\n * One renderer per surface a primitive implements.\n *\n * `react`, `text`, and `markdown` are always required: those three are what\n * make \"every composition degrades\" true. `react` serves the `snapshot` surface\n * too, so targeting images costs a primitive nothing.\n *\n * `slack` is declared method-style deliberately: method parameters are checked\n * bivariantly, which is what lets a pack narrow the collector's node type.\n */\nexport interface Renderers<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n> {\n react(\n node: TNode,\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** See {@link SurfaceMap.react}'s `env.theme`. */\n theme?: T['theme'];\n }\n ): ReactNode;\n text(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): string;\n markdown(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): MarkdownContent;\n slack?(\n node: TNode,\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n }\n ): T['slackBlock'] | readonly T['slackBlock'][];\n}\n\n/**\n * Measurements a frame can ask of a node before drawing it.\n *\n * `snapshotHeight` is optional. The height estimate is `0` when it is missing, so\n * a frame that sums node heights sizes short.\n */\nexport interface PrimitiveMetrics<TNode extends PrimitiveNode> {\n /** The node's drawn height in pixels at the frame's width. */\n snapshotHeight?: (node: TNode) => number;\n}\n\n/**\n * Every primitive's schema is an object schema, because {@link definePrimitive}\n * extends it with `id` and `surfaces` and the composition builds a\n * `z.discriminatedUnion('type', …)` over them. Typed as `ZodObject` rather\n * than `ZodType<unknown>` so a union or intersection schema is a compile\n * error at the definition, not a runtime failure at the first `.extend()`.\n * Zod 4 types `z.object().superRefine(…)` as a `ZodObject` and preserves the\n * refinement through `.extend()`, so top-level refinements are unaffected.\n */\nexport type PrimitiveSchema = ZodObject;\n\n/**\n * The child-ref shape a primitive definition's own `children` returns.\n *\n * {@link ChildNodeRef} stays erased (`node: unknown`) because\n * `createChildNodeWalker` mixes children from every primitive type in the\n * runtime into one map and cannot name a single node type for them. A single\n * definition has no such excuse: its `children` should not type-check\n * against `unknown` and let something that is not a {@link PrimitiveNode} —\n * `null`, for instance — silently disappear from every tree walk.\n */\nexport interface PrimitiveChildRef extends ChildNodeRef {\n node: PrimitiveNode;\n}\n\n/**\n * One primitive: its node type, schema, catalog entry, and a renderer per\n * surface. The unit of vocabulary, and what {@link definePrimitive} takes.\n *\n * `T` is the pack's {@link PackTypes}, bound once with\n * {@link definePrimitiveFor} so each primitive names only `TNode`.\n */\nexport interface PrimitiveDefinition<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n> {\n /** The node's discriminant, and the key this primitive occupies in an inventory. */\n type: TNode['type'];\n /** How the authoring prompt describes this primitive to the model. */\n catalog: PrimitiveCatalogEntry;\n /** Host-facing glyph, never shown to the model. Absent means the host supplies its own. */\n icon?: PrimitiveIcon;\n /**\n * Driven by the conformance harness, bare or named; read them with\n * `exampleNodes` or `primitiveExamples`. The catalog `example` is what the\n * prompt shows.\n */\n examples: readonly (TNode | PrimitiveExample<TNode>)[];\n /**\n * This primitive on its own. A container declares\n * {@link PrimitiveDefinition.schemaFor} as well, and uses\n * {@link unresolvedBodyNodeSchema} in the child slot here.\n */\n schema: TSchema;\n /**\n * A container's schema, bound to the body-node union of the composition it is\n * being built into.\n *\n * Declaring the shape and letting each composition supply its own union is\n * what lets one primitive appear in two runtimes with different inventories:\n * `z.lazy` memoizes per instance, and an instance built here belongs to\n * exactly one union.\n */\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n /** One function per surface; `react` serves `snapshot` as well. */\n renderers: Renderers<TNode, T>;\n /** Sizing a frame can ask for before drawing. Absent means it cannot be measured. */\n metrics?: PrimitiveMetrics<TNode>;\n /**\n * Render-time URL trust, the second of the two layers in `validate/url.ts`.\n *\n * Returning `null` drops the node. Applied even to an unvalidated node, so a\n * renderer invoked directly still cannot emit an unsafe URL.\n */\n sanitize?: (node: TNode) => TNode | null;\n /**\n * Nested nodes, for containers, in the order the `react` renderer draws\n * them; `findNodeElementPairs` relies on it. Absent means a leaf.\n */\n children?: (node: TNode) => readonly PrimitiveChildRef[];\n /**\n * True when this node produces surface output of its own, not only via\n * {@link PrimitiveDefinition.children}. A non-empty `children` result is\n * otherwise the complete source of rendered content, so a hybrid container\n * that still owns string fields returns true to keep rendering when every\n * nested node is hidden from the surface.\n */\n hasOwnContent?: (node: TNode) => boolean;\n /** Contributes this node's CSS by mutating `styles`, once per node per render. */\n collectStyles?: (\n node: TNode,\n env: { styles: T['collector']; context: PrimitiveStyleCollectionContext }\n ) => void;\n}\n\n/**\n * {@link PrimitiveDefinition} with every type parameter erased, and the form an\n * inventory is stored in.\n *\n * A heterogeneous pack has no single `TNode` to be generic over, so the\n * renderers degrade to `unknown` here.\n *\n * Each field carries the same contract as its {@link PrimitiveDefinition}\n * counterpart; only the types are erased.\n */\nexport interface AnyPrimitiveDefinition {\n type: string;\n catalog: PrimitiveCatalogEntry;\n icon?: PrimitiveIcon;\n examples: readonly (PrimitiveNode | PrimitiveExample)[];\n schema: PrimitiveSchema;\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n renderers: Record<'react' | 'text' | 'markdown', unknown> &\n Partial<Record<'slack', unknown>>;\n metrics?: {\n snapshotHeight?: unknown;\n };\n sanitize?: unknown;\n children?: unknown;\n hasOwnContent?: unknown;\n collectStyles?: unknown;\n}\n\n/** Parses `node` against `schema`, appending path-prefixed messages to `errors`. */\nexport const validateWithSchema = (\n schema: PrimitiveSchema,\n node: unknown,\n path: string,\n errors: ValidationError[]\n): void => {\n const result = schema.safeParse(node, { reportInput: true });\n if (!result.success) {\n errors.push(...formatZodIssues(result.error.issues, path));\n }\n};\n\n/** The `id` every node may carry, unique within a composition. */\nexport const bodyNodeIdSchema = requiredString('must be a non-empty string');\n\n/** The `surfaces` allowlist on a node. Absent means every surface; empty is rejected. */\nexport const bodyNodeSurfacesSchema = z\n .array(\n z.enum(SURFACE_NAMES, {\n error: () => oneOf(SURFACE_NAMES),\n })\n )\n .min(1, { error: 'must contain at least one surface' });\n\n/**\n * The child slot in a container's standalone {@link PrimitiveDefinition.schema},\n * where no body-node union is available.\n *\n * Deliberately permissive rather than `z.unknown()`: it still rejects a child\n * that is not a node at all, which is the error worth catching without an\n * inventory. Anything that depends on *which* types are legal — the validator,\n * the parser, the JSON Schema projection — goes through\n * {@link PrimitiveDefinition.schemaFor} and sees the real union.\n */\nexport const unresolvedBodyNodeSchema = z.looseObject({\n type: requiredString('must be a non-empty string'),\n});\n\n/**\n * Declares one primitive, extending its schema with the `id` and `surfaces`\n * fields every node carries, and closing it to unknown keys so a node is held\n * to the same rule as the composition root and the JSON Schema an agent reads.\n * A schema with its own catchall (`z.looseObject`) keeps it.\n *\n * A pack normally calls the form {@link definePrimitiveFor} binds to its own\n * {@link PackTypes}, so each primitive names only `TNode`.\n */\nexport const definePrimitive = <\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n>(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> => {\n const { schemaFor, schema, catalog } = definition;\n const described =\n catalog.description === undefined ? schema.description : undefined;\n return {\n ...definition,\n ...(described === undefined\n ? {}\n : { catalog: { ...catalog, description: described } }),\n schema: withNodeFields(schema),\n // Both forms get the node fields, or a container would accept `id` and\n // `surfaces` standalone and reject them inside a composition.\n ...(schemaFor\n ? {\n schemaFor: (bodyNodeSchema: ZodType<unknown>) =>\n withNodeFields(schemaFor(bodyNodeSchema)),\n }\n : {}),\n };\n};\n\n/**\n * {@link definePrimitive} bound to one pack's {@link PackTypes}.\n *\n * ```ts\n * const define = definePrimitiveFor<SlidesPackTypes>();\n * export const note = define({ type: 'note', … });\n * ```\n */\nexport const definePrimitiveFor =\n <T extends PackTypes>() =>\n <\n TNode extends PrimitiveNode,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n >(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n ): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> =>\n definePrimitive<TNode, T, TSchema>(definition);\n\n/**\n * `.extend()` on a generic `ZodObject` widens the shape to `any`, so the\n * return type is rebuilt from `TSchema`'s shape. The brand on a field schema\n * stays on that same object at runtime.\n */\nexport type WithNodeFields<TSchema extends PrimitiveSchema> =\n TSchema extends ZodObject<infer Shape>\n ? ZodObject<\n Shape & {\n id: ReturnType<typeof bodyNodeIdSchema.optional>;\n surfaces: ReturnType<typeof bodyNodeSurfacesSchema.optional>;\n }\n >\n : PrimitiveSchema;\n\n// Marks the field schemas `definePrimitive` adds. A schema derived from a\n// defined one shares them by reference, and `Symbol.for` matches across ESM and\n// CommonJS copies of the SDK.\nconst NODE_FIELD = Symbol.for('elastic.isomer.node_field');\n\nconst nodeField = <T extends ZodType>(schema: T): T =>\n Object.defineProperty(schema, NODE_FIELD, { value: true });\n\nconst NODE_FIELDS = {\n id: nodeField(bodyNodeIdSchema.optional()),\n surfaces: nodeField(bodyNodeSurfacesSchema.optional()),\n};\n\nconst isNodeField = (schema: unknown): boolean => {\n let current = schema;\n while (current && typeof current === 'object') {\n if (Object.hasOwn(current, NODE_FIELD)) {\n return true;\n }\n const { def } = current as {\n def?: { type?: string; innerType?: unknown };\n };\n if (def?.type !== 'optional') {\n return false;\n }\n current = def.innerType;\n }\n return false;\n};\n\nconst withNodeFields = <TSchema extends PrimitiveSchema>(\n schema: TSchema\n): WithNodeFields<TSchema> => {\n const reserved = Object.keys(NODE_FIELDS).find(\n (field) =>\n Object.hasOwn(schema.shape, field) && !isNodeField(schema.shape[field])\n );\n if (reserved) {\n throw new IsomerError(\n ISOMER_ERROR_CODES.RESERVED_NODE_FIELD,\n `definePrimitive: a primitive schema cannot declare \\`${reserved}\\`; every body node has it.`\n );\n }\n const extended = schema.extend(NODE_FIELDS);\n return (\n schema.def.catchall === undefined ? extended.strict() : extended\n ) as WithNodeFields<TSchema>;\n};\n"]}
@@ -6,8 +6,8 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.buildCompositionJsonSchema = exports.buildAuthoringJsonSchema = exports.authoringSchemaSubset = exports.assetUrl = exports.NAVIGATION_HREF_RULE = exports.NAVIGATION_HREF_MESSAGE = exports.MAX_INPUT_VALUES = exports.MAX_INPUT_DEPTH = exports.MAX_INPUT_CHARACTERS = exports.BLOCKED_HREF = exports.ASSET_URL_RULE = exports.ASSET_URL_MESSAGE = exports.withoutAnchors = exports.withNodeAnchors = exports.rawDisplayValue = exports.nodeAnchor = exports.layoutRoom = exports.isStructuredValue = exports.formatDisplayValue = exports.createPrimitiveDispatcher = exports.checkLayout = exports.NODE_ANCHOR_ATTRIBUTE = exports.LAYOUT_ROOM_ATTRIBUTE = exports.scopeScript = exports.describeCapabilities = exports.definePrimitivePack = exports.composePacks = exports.z = exports.unresolvedBodyNodeSchema = exports.requiredString = exports.primitiveExamples = exports.formatZodIssues = exports.exampleNodes = exports.definePrimitiveFor = exports.definePrimitive = exports.bindFrame = exports.OPTIONAL_SURFACES = exports.ICON_VARS = exports.someBodyNode = exports.mapCompositionNodes = exports.isVisibleOnSurface = exports.IsomerError = exports.formatValidationError = exports.createChildNodeWalker = exports.CompositionValidationError = exports.SURFACE_NAMES = exports.STRUCTURED_VALUE_FORMATS = exports.ISOMER_ERROR_CODES = exports.BODY_NODE_SURFACES = exports.ALL_NAMED_COLORS = void 0;
10
- exports.warningsForSurface = exports.structuredValueSchema = exports.sanitizeNavigationHref = exports.sanitizeAssetUrl = exports.renderThemeSchema = exports.navigationHref = exports.namedColorSchema = exports.isInputRefusal = exports.getCompositionSchemaForDefinitions = exports.displayValueSchema = exports.createCompositionValidator = exports.createCompositionParser = exports.compositionToRender = exports.checkInputBudget = void 0;
9
+ exports.buildAuthoringJsonSchema = exports.authoringSchemaSubset = exports.assetUrl = exports.NAVIGATION_HREF_RULE = exports.NAVIGATION_HREF_MESSAGE = exports.MAX_INPUT_VALUES = exports.MAX_INPUT_DEPTH = exports.MAX_INPUT_CHARACTERS = exports.BLOCKED_HREF = exports.ASSET_URL_RULE = exports.ASSET_URL_MESSAGE = exports.withoutAnchors = exports.withNodeAnchors = exports.rawDisplayValue = exports.nodeAnchor = exports.layoutRoom = exports.isStructuredValue = exports.formatDisplayValue = exports.createPrimitiveDispatcher = exports.checkLayout = exports.NODE_ANCHOR_ATTRIBUTE = exports.LAYOUT_ROOM_ATTRIBUTE = exports.scopeScript = exports.describeCapabilities = exports.definePrimitivePack = exports.composePacks = exports.UNCATEGORIZED_GROUP_TITLE = exports.z = exports.unresolvedBodyNodeSchema = exports.requiredString = exports.primitiveExamples = exports.formatZodIssues = exports.exampleNodes = exports.definePrimitiveFor = exports.definePrimitive = exports.bindFrame = exports.OPTIONAL_SURFACES = exports.ICON_VARS = exports.someBodyNode = exports.mapCompositionNodes = exports.isVisibleOnSurface = exports.IsomerError = exports.formatValidationError = exports.createChildNodeWalker = exports.CompositionValidationError = exports.SURFACE_NAMES = exports.STRUCTURED_VALUE_FORMATS = exports.ISOMER_ERROR_CODES = exports.BODY_NODE_SURFACES = exports.ALL_NAMED_COLORS = void 0;
10
+ exports.warningsForSurface = exports.structuredValueSchema = exports.sanitizeNavigationHref = exports.sanitizeAssetUrl = exports.renderThemeSchema = exports.navigationHref = exports.namedColorSchema = exports.isInputRefusal = exports.getCompositionSchemaForDefinitions = exports.displayValueSchema = exports.createCompositionValidator = exports.createCompositionParser = exports.compositionToRender = exports.checkInputBudget = exports.buildCompositionJsonSchema = void 0;
11
11
  var composition_1 = require("../composition");
12
12
  Object.defineProperty(exports, "ALL_NAMED_COLORS", { enumerable: true, get: function () { return composition_1.ALL_NAMED_COLORS; } });
13
13
  Object.defineProperty(exports, "BODY_NODE_SURFACES", { enumerable: true, get: function () { return composition_1.BODY_NODE_SURFACES; } });
@@ -34,6 +34,7 @@ Object.defineProperty(exports, "requiredString", { enumerable: true, get: functi
34
34
  Object.defineProperty(exports, "unresolvedBodyNodeSchema", { enumerable: true, get: function () { return define_1.unresolvedBodyNodeSchema; } });
35
35
  Object.defineProperty(exports, "z", { enumerable: true, get: function () { return define_1.z; } });
36
36
  var pack_1 = require("../pack");
37
+ Object.defineProperty(exports, "UNCATEGORIZED_GROUP_TITLE", { enumerable: true, get: function () { return pack_1.UNCATEGORIZED_GROUP_TITLE; } });
37
38
  Object.defineProperty(exports, "composePacks", { enumerable: true, get: function () { return pack_1.composePacks; } });
38
39
  Object.defineProperty(exports, "definePrimitivePack", { enumerable: true, get: function () { return pack_1.definePrimitivePack; } });
39
40
  Object.defineProperty(exports, "describeCapabilities", { enumerable: true, get: function () { return pack_1.describeCapabilities; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/entries/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,8CA6BwB;AAZtB,+GAAA,gBAAgB,OAAA;AAChB,iHAAA,kBAAkB,OAAA;AAClB,iHAAA,kBAAkB,OAAA;AAClB,uHAAA,wBAAwB,OAAA;AACxB,4GAAA,aAAa,OAAA;AACb,yHAAA,0BAA0B,OAAA;AAC1B,oHAAA,qBAAqB,OAAA;AACrB,oHAAA,qBAAqB,OAAA;AACrB,0GAAA,WAAW,OAAA;AACX,iHAAA,kBAAkB,OAAA;AAClB,kHAAA,mBAAmB,OAAA;AACnB,2GAAA,YAAY,OAAA;AAEd,oCA6CmB;AAXjB,mGAAA,SAAS,OAAA;AACT,2GAAA,iBAAiB,OAAA;AACjB,mGAAA,SAAS,OAAA;AACT,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,sGAAA,YAAY,OAAA;AACZ,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AACd,kHAAA,wBAAwB,OAAA;AACxB,2FAAA,CAAC,OAAA;AAEH,gCAgBiB;AAJf,oGAAA,YAAY,OAAA;AACZ,2GAAA,mBAAmB,OAAA;AACnB,4GAAA,oBAAoB,OAAA;AACpB,mGAAA,WAAW,OAAA;AAEb,oCAmBmB;AAXjB,+GAAA,qBAAqB,OAAA;AACrB,+GAAA,qBAAqB,OAAA;AACrB,qGAAA,WAAW,OAAA;AACX,mHAAA,yBAAyB,OAAA;AACzB,4GAAA,kBAAkB,OAAA;AAClB,2GAAA,iBAAiB,OAAA;AACjB,oGAAA,UAAU,OAAA;AACV,oGAAA,UAAU,OAAA;AACV,yGAAA,eAAe,OAAA;AACf,yGAAA,eAAe,OAAA;AACf,wGAAA,cAAc,OAAA;AAEhB,wCAwCqB;AA1BnB,6GAAA,iBAAiB,OAAA;AACjB,0GAAA,cAAc,OAAA;AACd,wGAAA,YAAY,OAAA;AACZ,gHAAA,oBAAoB,OAAA;AACpB,2GAAA,eAAe,OAAA;AACf,4GAAA,gBAAgB,OAAA;AAChB,mHAAA,uBAAuB,OAAA;AACvB,gHAAA,oBAAoB,OAAA;AACpB,oGAAA,QAAQ,OAAA;AACR,iHAAA,qBAAqB,OAAA;AACrB,oHAAA,wBAAwB,OAAA;AACxB,sHAAA,0BAA0B,OAAA;AAC1B,4GAAA,gBAAgB,OAAA;AAChB,+GAAA,mBAAmB,OAAA;AACnB,mHAAA,uBAAuB,OAAA;AACvB,sHAAA,0BAA0B,OAAA;AAC1B,8GAAA,kBAAkB,OAAA;AAClB,8HAAA,kCAAkC,OAAA;AAClC,0GAAA,cAAc,OAAA;AACd,4GAAA,gBAAgB,OAAA;AAChB,0GAAA,cAAc,OAAA;AACd,6GAAA,iBAAiB,OAAA;AACjB,4GAAA,gBAAgB,OAAA;AAChB,kHAAA,sBAAsB,OAAA;AACtB,iHAAA,qBAAqB,OAAA;AACrB,8GAAA,kBAAkB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type ActionEventRef,\n type BodyNodeBase,\n type ChildNodeRef,\n type ChildNodeWalker,\n type Composition,\n type CompositionMeta,\n type DisplayValue,\n type IsomerErrorCode,\n type NamedColor,\n type NamedColorPalette,\n type PrimitiveNode,\n type RenderTheme,\n type StructuredValue,\n type StructuredValueFormat,\n type SurfaceName,\n type ValidationError,\n ALL_NAMED_COLORS,\n BODY_NODE_SURFACES,\n ISOMER_ERROR_CODES,\n STRUCTURED_VALUE_FORMATS,\n SURFACE_NAMES,\n CompositionValidationError,\n createChildNodeWalker,\n formatValidationError,\n IsomerError,\n isVisibleOnSurface,\n mapCompositionNodes,\n someBodyNode,\n} from '../composition';\nexport {\n type AnyPrimitiveDefinition,\n type BoundFrame,\n type DefaultPackTypes,\n type ExampleNode,\n type Frame,\n type FrameBody,\n type FrameComposition,\n type FrameDispatcher,\n type FrameHeader,\n type FrameViewport,\n type NormalizedPrimitiveExample,\n type OptionalSurface,\n type PackTypes,\n type PrimitiveCatalogEntry,\n type PrimitiveChildRef,\n type PrimitiveDefinition,\n type PrimitiveExample,\n type PrimitiveIcon,\n type PrimitiveMetrics,\n type PrimitiveRenderContext,\n type PrimitiveSchema,\n type PrimitiveStyleCollectionContext,\n type PrimitiveStyleCollector,\n type ReactContextArg,\n type Renderer,\n type Renderers,\n type RenderScope,\n type StyledRenderContext,\n type StyleHandle,\n type SurfaceMap,\n type ThemePair,\n type ThemeTokenPath,\n type WithNodeFields,\n ICON_VARS,\n OPTIONAL_SURFACES,\n bindFrame,\n definePrimitive,\n definePrimitiveFor,\n exampleNodes,\n formatZodIssues,\n primitiveExamples,\n requiredString,\n unresolvedBodyNodeSchema,\n z,\n} from '../define';\nexport {\n type AnyPrimitivePack,\n type CapabilitySources,\n type ComposedPacks,\n type EnhancementDefinition,\n type HostCapabilities,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n type SurfaceSupport,\n composePacks,\n definePrimitivePack,\n describeCapabilities,\n scopeScript,\n} from '../pack';\nexport {\n type FormatDisplayValueOptions,\n type LayoutBox,\n type LayoutFinding,\n type LayoutRect,\n type PayloadMeasurement,\n type PrimitiveDispatcher,\n type PrimitiveDispatcherOptions,\n LAYOUT_ROOM_ATTRIBUTE,\n NODE_ANCHOR_ATTRIBUTE,\n checkLayout,\n createPrimitiveDispatcher,\n formatDisplayValue,\n isStructuredValue,\n layoutRoom,\n nodeAnchor,\n rawDisplayValue,\n withNodeAnchors,\n withoutAnchors,\n} from '../render';\nexport {\n type AuthoringJsonSchemaOptions,\n type CheckedComposition,\n type CheckedValidationResult,\n type CompositionJsonSchemaOptions,\n type CompositionSchemaOptions,\n type CompositionValidatorOptions,\n type InputBudget,\n type InputBudgetCheck,\n type ParsedComposition,\n type UrlSchemaOptions,\n type ValidationErrorMode,\n type ValidationResult,\n type ValidationWarning,\n ASSET_URL_MESSAGE,\n ASSET_URL_RULE,\n BLOCKED_HREF,\n MAX_INPUT_CHARACTERS,\n MAX_INPUT_DEPTH,\n MAX_INPUT_VALUES,\n NAVIGATION_HREF_MESSAGE,\n NAVIGATION_HREF_RULE,\n assetUrl,\n authoringSchemaSubset,\n buildAuthoringJsonSchema,\n buildCompositionJsonSchema,\n checkInputBudget,\n compositionToRender,\n createCompositionParser,\n createCompositionValidator,\n displayValueSchema,\n getCompositionSchemaForDefinitions,\n isInputRefusal,\n namedColorSchema,\n navigationHref,\n renderThemeSchema,\n sanitizeAssetUrl,\n sanitizeNavigationHref,\n structuredValueSchema,\n warningsForSurface,\n} from '../validate';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/entries/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,8CA6BwB;AAZtB,+GAAA,gBAAgB,OAAA;AAChB,iHAAA,kBAAkB,OAAA;AAClB,iHAAA,kBAAkB,OAAA;AAClB,uHAAA,wBAAwB,OAAA;AACxB,4GAAA,aAAa,OAAA;AACb,yHAAA,0BAA0B,OAAA;AAC1B,oHAAA,qBAAqB,OAAA;AACrB,oHAAA,qBAAqB,OAAA;AACrB,0GAAA,WAAW,OAAA;AACX,iHAAA,kBAAkB,OAAA;AAClB,kHAAA,mBAAmB,OAAA;AACnB,2GAAA,YAAY,OAAA;AAEd,oCA6CmB;AAXjB,mGAAA,SAAS,OAAA;AACT,2GAAA,iBAAiB,OAAA;AACjB,mGAAA,SAAS,OAAA;AACT,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,sGAAA,YAAY,OAAA;AACZ,yGAA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;AACtB,iHAAA,qBAAqB,OAAA;AACrB,8GAAA,kBAAkB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type ActionEventRef,\n type BodyNodeBase,\n type ChildNodeRef,\n type ChildNodeWalker,\n type Composition,\n type CompositionMeta,\n type DisplayValue,\n type IsomerErrorCode,\n type NamedColor,\n type NamedColorPalette,\n type PrimitiveNode,\n type RenderTheme,\n type StructuredValue,\n type StructuredValueFormat,\n type SurfaceName,\n type ValidationError,\n ALL_NAMED_COLORS,\n BODY_NODE_SURFACES,\n ISOMER_ERROR_CODES,\n STRUCTURED_VALUE_FORMATS,\n SURFACE_NAMES,\n CompositionValidationError,\n createChildNodeWalker,\n formatValidationError,\n IsomerError,\n isVisibleOnSurface,\n mapCompositionNodes,\n someBodyNode,\n} from '../composition';\nexport {\n type AnyPrimitiveDefinition,\n type BoundFrame,\n type DefaultPackTypes,\n type ExampleNode,\n type Frame,\n type FrameBody,\n type FrameComposition,\n type FrameDispatcher,\n type FrameHeader,\n type FrameViewport,\n type NormalizedPrimitiveExample,\n type OptionalSurface,\n type PackTypes,\n type PrimitiveCatalogEntry,\n type PrimitiveChildRef,\n type PrimitiveDefinition,\n type PrimitiveExample,\n type PrimitiveIcon,\n type PrimitiveMetrics,\n type PrimitiveRenderContext,\n type PrimitiveSchema,\n type PrimitiveStyleCollectionContext,\n type PrimitiveStyleCollector,\n type ReactContextArg,\n type Renderer,\n type Renderers,\n type RenderScope,\n type StyledRenderContext,\n type StyleHandle,\n type SurfaceMap,\n type ThemePair,\n type ThemeTokenPath,\n type WithNodeFields,\n ICON_VARS,\n OPTIONAL_SURFACES,\n bindFrame,\n definePrimitive,\n definePrimitiveFor,\n exampleNodes,\n formatZodIssues,\n primitiveExamples,\n requiredString,\n unresolvedBodyNodeSchema,\n z,\n} from '../define';\nexport {\n type AnyPrimitivePack,\n type CapabilitySources,\n type ComposedPacks,\n type EnhancementDefinition,\n type HostCapabilities,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n type SurfaceSupport,\n UNCATEGORIZED_GROUP_TITLE,\n composePacks,\n definePrimitivePack,\n describeCapabilities,\n scopeScript,\n} from '../pack';\nexport {\n type FormatDisplayValueOptions,\n type LayoutBox,\n type LayoutFinding,\n type LayoutRect,\n type PayloadMeasurement,\n type PrimitiveDispatcher,\n type PrimitiveDispatcherOptions,\n LAYOUT_ROOM_ATTRIBUTE,\n NODE_ANCHOR_ATTRIBUTE,\n checkLayout,\n createPrimitiveDispatcher,\n formatDisplayValue,\n isStructuredValue,\n layoutRoom,\n nodeAnchor,\n rawDisplayValue,\n withNodeAnchors,\n withoutAnchors,\n} from '../render';\nexport {\n type AuthoringJsonSchemaOptions,\n type CheckedComposition,\n type CheckedValidationResult,\n type CompositionJsonSchemaOptions,\n type CompositionSchemaOptions,\n type CompositionValidatorOptions,\n type InputBudget,\n type InputBudgetCheck,\n type ParsedComposition,\n type UrlSchemaOptions,\n type ValidationErrorMode,\n type ValidationResult,\n type ValidationWarning,\n ASSET_URL_MESSAGE,\n ASSET_URL_RULE,\n BLOCKED_HREF,\n MAX_INPUT_CHARACTERS,\n MAX_INPUT_DEPTH,\n MAX_INPUT_VALUES,\n NAVIGATION_HREF_MESSAGE,\n NAVIGATION_HREF_RULE,\n assetUrl,\n authoringSchemaSubset,\n buildAuthoringJsonSchema,\n buildCompositionJsonSchema,\n checkInputBudget,\n compositionToRender,\n createCompositionParser,\n createCompositionValidator,\n displayValueSchema,\n getCompositionSchemaForDefinitions,\n isInputRefusal,\n namedColorSchema,\n navigationHref,\n renderThemeSchema,\n sanitizeAssetUrl,\n sanitizeNavigationHref,\n structuredValueSchema,\n warningsForSurface,\n} from '../validate';\n"]}
@@ -6,9 +6,10 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.serializeMarkdown = exports.renderMarkdownEnvelope = exports.md = void 0;
9
+ exports.splitAuthoredMarkdown = exports.serializeMarkdown = exports.renderMarkdownEnvelope = exports.md = void 0;
10
10
  var markdown_1 = require("../render/markdown");
11
11
  Object.defineProperty(exports, "md", { enumerable: true, get: function () { return markdown_1.md; } });
12
12
  Object.defineProperty(exports, "renderMarkdownEnvelope", { enumerable: true, get: function () { return markdown_1.renderMarkdownEnvelope; } });
13
13
  Object.defineProperty(exports, "serializeMarkdown", { enumerable: true, get: function () { return markdown_1.serializeMarkdown; } });
14
+ Object.defineProperty(exports, "splitAuthoredMarkdown", { enumerable: true, get: function () { return markdown_1.splitAuthoredMarkdown; } });
14
15
  //# sourceMappingURL=markdown.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../src/entries/markdown.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AASH,+CAM4B;AAH1B,8FAAA,EAAE,OAAA;AACF,kHAAA,sBAAsB,OAAA;AACtB,6GAAA,iBAAiB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type MarkdownBlock,\n type MarkdownContent,\n type MarkdownInline,\n type MarkdownInlineInput,\n} from '../define';\n\nexport {\n type MarkdownEnvelopeDispatcher,\n type MarkdownEnvelopeOptions,\n md,\n renderMarkdownEnvelope,\n serializeMarkdown,\n} from '../render/markdown';\n"]}
1
+ {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../src/entries/markdown.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AASH,+CAS4B;AAJ1B,8FAAA,EAAE,OAAA;AACF,kHAAA,sBAAsB,OAAA;AACtB,6GAAA,iBAAiB,OAAA;AACjB,iHAAA,qBAAqB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type MarkdownBlock,\n type MarkdownContent,\n type MarkdownInline,\n type MarkdownInlineInput,\n} from '../define';\n\nexport {\n type AuthoredMarkdownSegment,\n type MarkdownEnvelopeDispatcher,\n type MarkdownEnvelopeOptions,\n type SplitAuthoredMarkdownOptions,\n md,\n renderMarkdownEnvelope,\n serializeMarkdown,\n splitAuthoredMarkdown,\n} from '../render/markdown';\n"]}
@@ -6,7 +6,7 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.definePrimitivePack = exports.scopeScript = exports.composePacks = exports.describeCapabilities = void 0;
9
+ exports.definePrimitivePack = exports.UNCATEGORIZED_GROUP_TITLE = exports.scopeScript = exports.composePacks = exports.describeCapabilities = void 0;
10
10
  var capabilities_1 = require("./capabilities");
11
11
  Object.defineProperty(exports, "describeCapabilities", { enumerable: true, get: function () { return capabilities_1.describeCapabilities; } });
12
12
  var compose_1 = require("./compose");
@@ -14,5 +14,6 @@ Object.defineProperty(exports, "composePacks", { enumerable: true, get: function
14
14
  var enhancements_1 = require("./enhancements");
15
15
  Object.defineProperty(exports, "scopeScript", { enumerable: true, get: function () { return enhancements_1.scopeScript; } });
16
16
  var primitive_pack_1 = require("./primitive_pack");
17
+ Object.defineProperty(exports, "UNCATEGORIZED_GROUP_TITLE", { enumerable: true, get: function () { return primitive_pack_1.UNCATEGORIZED_GROUP_TITLE; } });
17
18
  Object.defineProperty(exports, "definePrimitivePack", { enumerable: true, get: function () { return primitive_pack_1.definePrimitivePack; } });
18
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pack/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+CAKwB;AADtB,oHAAA,oBAAoB,OAAA;AAEtB,qCAA6D;AAAhC,uGAAA,YAAY,OAAA;AACzC,+CAAyE;AAApC,2GAAA,WAAW,OAAA;AAChD,mDAQ0B;AADxB,qHAAA,mBAAmB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type CapabilitySources,\n type HostCapabilities,\n type SurfaceSupport,\n describeCapabilities,\n} from './capabilities';\nexport { type ComposedPacks, composePacks } from './compose';\nexport { type EnhancementDefinition, scopeScript } from './enhancements';\nexport {\n type AnyPrimitivePack,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n definePrimitivePack,\n} from './primitive_pack';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pack/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+CAKwB;AADtB,oHAAA,oBAAoB,OAAA;AAEtB,qCAA6D;AAAhC,uGAAA,YAAY,OAAA;AACzC,+CAAyE;AAApC,2GAAA,WAAW,OAAA;AAChD,mDAS0B;AAFxB,2HAAA,yBAAyB,OAAA;AACzB,qHAAA,mBAAmB,OAAA","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type CapabilitySources,\n type HostCapabilities,\n type SurfaceSupport,\n describeCapabilities,\n} from './capabilities';\nexport { type ComposedPacks, composePacks } from './compose';\nexport { type EnhancementDefinition, scopeScript } from './enhancements';\nexport {\n type AnyPrimitivePack,\n type PackAuthoringOptions,\n type PackStyleAdapter,\n type PrimitiveGroup,\n type PrimitivePack,\n type PrimitivePackInput,\n UNCATEGORIZED_GROUP_TITLE,\n definePrimitivePack,\n} from './primitive_pack';\n"]}
@@ -6,11 +6,13 @@
6
6
  * 2.0.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.iconsByType = exports.definePrimitivePack = void 0;
9
+ exports.iconsByType = exports.definePrimitivePack = exports.UNCATEGORIZED_GROUP_TITLE = void 0;
10
10
  // A primitive pack as a value: a vocabulary, and the optional surfaces every
11
11
  // primitive in it implements. Additive: a runtime composes any number of packs,
12
12
  // and nothing about a pack decides how a composition is framed.
13
13
  const error_1 = require("../composition/error");
14
+ /** The index heading for primitives in no group. A pack cannot declare a group with this title. */
15
+ exports.UNCATEGORIZED_GROUP_TITLE = 'Uncategorized';
14
16
  /**
15
17
  * Builds a {@link PrimitivePack}.
16
18
  *
@@ -25,7 +27,7 @@ const definePrimitivePack = (input) => {
25
27
  assertUniquePrimitiveTypes(input.id, input.primitives);
26
28
  assertUniqueEnhancementIds(input.id, input.enhancements ?? []);
27
29
  const types = new Set(input.primitives.map((definition) => definition.type));
28
- assertGroupedOnce(input.id, input.authoring?.groups ?? [], types);
30
+ assertValidGroups(input.id, input.authoring?.groups ?? [], types);
29
31
  for (const type of input.slackAssetTypes ?? []) {
30
32
  if (!types.has(type)) {
31
33
  throw new error_1.IsomerError('UNKNOWN_PRIMITIVE_TYPE', `primitive pack "${input.id}": slackAssetTypes names primitive type "${type}", which the pack does not register`);
@@ -69,10 +71,18 @@ const assertUniquePrimitiveTypes = (id, primitives) => {
69
71
  seen.add(type);
70
72
  }
71
73
  };
72
- /** Throws if a group names a type outside `types`, or two groups share a type. */
73
- const assertGroupedOnce = (id, groups, types) => {
74
+ /** Throws if a group repeats or reserves a title, names a type outside `types`, or shares a type with another. */
75
+ const assertValidGroups = (id, groups, types) => {
76
+ const titles = new Set();
74
77
  const grouped = new Set();
75
78
  for (const { title, types: members } of groups) {
79
+ if (title === exports.UNCATEGORIZED_GROUP_TITLE) {
80
+ throw new error_1.IsomerError('INVALID_PACK_GROUPS', `primitive pack "${id}": group title "${title}" is reserved for primitives in no group`);
81
+ }
82
+ if (titles.has(title)) {
83
+ throw new error_1.IsomerError('INVALID_PACK_GROUPS', `primitive pack "${id}": group title "${title}" is used twice`);
84
+ }
85
+ titles.add(title);
76
86
  for (const type of members) {
77
87
  if (!types.has(type)) {
78
88
  throw new error_1.IsomerError('UNKNOWN_PRIMITIVE_TYPE', `primitive pack "${id}": group "${title}" names primitive type "${type}", which the pack does not register`);
@@ -1 +1 @@
1
- {"version":3,"file":"primitive_pack.js","sourceRoot":"","sources":["../../../src/pack/primitive_pack.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,6EAA6E;AAC7E,gFAAgF;AAChF,gEAAgE;AAEhE,gDAAmD;AAsKnD;;;;;;GAMG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAyB,EACF,EAAE;IACzB,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,mBAAW,CACnB,YAAY,EACZ,mBAAmB,KAAK,CAAC,EAAE,uCAAuC,CACnE,CAAC;IACJ,CAAC;IACD,0BAA0B,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACvD,0BAA0B,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7E,iBAAiB,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IAClE,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,eAAe,IAAI,EAAE,EAAE,CAAC;QAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAA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OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,mEAAmE;AACnE,MAAM,0BAA0B,GAAG,CACjC,EAAU,EACV,YAA8C,EACxC,EAAE;IACR,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,mBAAW,CACnB,uBAAuB,EACvB,mBAAmB,EAAE,mBAAmB,UAAU,CAAC,EAAE,oBAAoB,CAC1E,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// A primitive pack as a value: a vocabulary, and the optional surfaces every\n// primitive in it implements. Additive: a runtime composes any number of packs,\n// and nothing about a pack decides how a composition is framed.\n\nimport { IsomerError } from '../composition/error';\nimport type { PrimitiveIcon } from '../define/primitive_icon';\nimport type {\n AnyPrimitiveDefinition,\n OptionalSurface,\n StyleHandle,\n} from '../define/primitive_module';\n\nimport type { EnhancementDefinition } from './enhancements';\n\n/**\n * The authoring-schema material a pack contributes for its own primitives.\n *\n * A subset of `AuthoringJsonSchemaOptions`: `$id`, `title`, `description`, and\n * `composition` describe the whole authoring schema a runtime builds, which is\n * a host decision, not a pack one. `pack/` does not import `validate/` for\n * this, so the shape is declared here rather than reused by reference.\n */\nexport interface PackAuthoringOptions {\n /** `$def` id to `description`, for this pack's own primitives. */\n describe?: Readonly<Record<string, string>>;\n /** `$defId.property` paths to drop, from this pack's own primitives. */\n omitProperties?: readonly string[];\n /** Headings an index catalog sorts this pack's primitives under, in order. */\n groups?: readonly PrimitiveGroup[];\n}\n\n/** A titled set of primitive types, listed together in an index catalog. */\nexport interface PrimitiveGroup {\n title: string;\n types: readonly string[];\n}\n\n/**\n * The HTML style-adapter hooks a pack may declare. Typed loosely here so `pack/` does not import `render/`.\n */\nexport type PackStyleAdapter = {\n /** See {@link PrimitivePackInput.styleCollector}. */\n styleCollector?: string;\n /** The hooks of `HTMLStyleAdapter` from `./html`, erased: a fresh collector per render, the context renderers receive, and the stylesheet the collector produced. */\n createCollector: (...args: never[]) => object;\n createRenderContext: (...args: never[]) => unknown;\n renderStyles: (...args: never[]) => string;\n /**\n * Whether `handle` belongs to this adapter's stylesheet. Required for a runtime to combine several packs' CSS: without it their handles cannot be routed and the host must pick one adapter.\n */\n ownsHandle?: (handle: StyleHandle) => boolean;\n};\n\n/** What a pack author passes to {@link definePrimitivePack}. */\nexport interface PrimitivePackInput {\n /** Stable identifier, used in capability reports and error messages. */\n id: string;\n /**\n * The optional surfaces this pack's primitives implement.\n *\n * Only `slack`, and it stays optional per primitive: the dispatcher converts\n * the mandatory markdown to Block Kit, so declaring it reports an intent\n * rather than imposing a requirement. Omit it entirely for a pack that\n * renders Slack through that fallback.\n */\n surfaces?: readonly OptionalSurface[];\n /** This pack's vocabulary. Node types must be unique within it, or construction throws. */\n primitives: readonly AnyPrimitiveDefinition[];\n /**\n * Progressive enhancements this pack's primitives can apply, by id.\n *\n * Declared by the pack because an enhancement is a fact about its\n * vocabulary — a sortable table, a copyable code block — and a host\n * composing packs it did not write cannot be expected to know the ids.\n * The runtime flattens these across packs; duplicate ids are rejected.\n */\n enhancements?: readonly EnhancementDefinition[];\n /**\n * Types that render as a self-contained picture rather than as text.\n *\n * A channel that cannot draw them inline uploads an image instead: the Slack\n * dispatcher swaps such a node for an `image` block and an upload request, so\n * a chart arrives as a PNG rather than as a markdown approximation of one.\n *\n * Declared by the pack because it is a fact about the vocabulary, and a host\n * composing packs it did not write cannot be expected to know it.\n */\n slackAssetTypes?: readonly string[];\n /**\n * Default HTML style adapter for this pack. A runtime that omits\n * `styleAdapter` runs the packs' own adapters, combined when more than one\n * pack declares one and each answers `ownsHandle`. Pass `styleAdapter` on\n * the runtime to replace them all.\n */\n styleAdapter?: PackStyleAdapter;\n /**\n * Names the collector shape this pack's `collectStyles` hooks mutate, so a\n * runtime can reject a pack paired with an adapter of a different tag.\n * Defaults to `styleAdapter.styleCollector`; a pack with neither opts out of\n * the check.\n */\n styleCollector?: string;\n /**\n * This pack's own contribution to the runtime's authoring JSON Schema.\n *\n * Merged across every composed pack, so a host does not hand-merge each\n * pack's `describe`/`omitProperties` into one options object itself. The\n * runtime-level `authoring` option is merged in last and wins on conflict.\n */\n authoring?: PackAuthoringOptions;\n}\n\n/**\n * A pack as the runtime sees it.\n *\n * `TTheme` is the palette this pack's `react` renderers read as `env.theme`\n * when drawn through the `snapshot` surface — a *lower bound* on whatever theme\n * the runtime holding it supplies. It is carried by\n * {@link PrimitivePack.__theme} rather than by any real field, because\n * `primitives` is erased to `AnyPrimitiveDefinition[]` and a heterogeneous\n * inventory has no single node type to be generic over.\n *\n * The bound is declared, not derived: nothing checks it against what the\n * renderers actually read. State it at the definition as\n * `definePrimitivePack<T>(input)`.\n * Bare `PrimitivePack` requires nothing and fits any runtime; a slot that must\n * hold packs of every palette is typed {@link AnyPrimitivePack}.\n */\nexport interface PrimitivePack<TTheme = unknown> {\n /** Unique among the packs a runtime composes, and used in error messages. */\n readonly id: string;\n /** See {@link PrimitivePackInput.surfaces}. */\n readonly surfaces: readonly OptionalSurface[];\n /** See {@link PrimitivePackInput.primitives}. */\n readonly primitives: readonly AnyPrimitiveDefinition[];\n /** Node types this pack owns, for duplicate detection across packs. */\n readonly types: ReadonlySet<string>;\n /**\n * Each primitive's `icon` by type, for the primitives that declare one, so a host listing them need not walk `primitives`.\n *\n * A frozen null-prototype dictionary: an absent type reads `undefined`, even `constructor`. Absent on a pack built by an SDK that predates icons; {@link iconsByType} derives it from `primitives`.\n */\n readonly icons?: Readonly<Record<string, PrimitiveIcon>>;\n /** See {@link PrimitivePackInput.enhancements}. */\n readonly enhancements: readonly EnhancementDefinition[];\n /** See {@link PrimitivePackInput.slackAssetTypes}. */\n readonly slackAssetTypes: ReadonlySet<string>;\n /** See {@link PrimitivePackInput.styleAdapter}. */\n readonly styleAdapter?: PackStyleAdapter;\n /** See {@link PrimitivePackInput.styleCollector}. */\n readonly styleCollector?: string;\n /** See {@link PrimitivePackInput.authoring}. */\n readonly authoring?: PackAuthoringOptions;\n /**\n * Phantom: never present at runtime, never read.\n *\n * A property rather than a method so `strictFunctionTypes` checks it\n * contravariantly. A method signature is bivariant, which would let a pack\n * needing richer tokens sit in a slot supplying fewer and then read a field\n * nothing supplies — the exact failure this marker exists to prevent.\n */\n readonly __theme?: (theme: TTheme) => void;\n}\n\n/**\n * A pack of any palette, for storage positions: `never` is assignable to every\n * requirement, so a slot typed this way holds every pack.\n */\nexport type AnyPrimitivePack = PrimitivePack<never>;\n\n/**\n * Builds a {@link PrimitivePack}.\n *\n * `TTheme` is the palette a frame must supply for this pack's nodes to be drawn\n * on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is\n * `unknown`, which requires nothing.\n */\nexport const definePrimitivePack = <TTheme = unknown>(\n input: PrimitivePackInput\n): PrimitivePack<TTheme> => {\n if (input.primitives.length === 0) {\n throw new IsomerError(\n 'EMPTY_PACK',\n `primitive pack \"${input.id}\": at least one primitive is required`\n );\n }\n assertUniquePrimitiveTypes(input.id, input.primitives);\n assertUniqueEnhancementIds(input.id, input.enhancements ?? []);\n const types = new Set(input.primitives.map((definition) => definition.type));\n assertGroupedOnce(input.id, input.authoring?.groups ?? [], types);\n for (const type of input.slackAssetTypes ?? []) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${input.id}\": slackAssetTypes names primitive type \"${type}\", which the pack does not register`\n );\n }\n }\n const styleCollector =\n input.styleCollector ?? input.styleAdapter?.styleCollector;\n\n return {\n id: input.id,\n surfaces: input.surfaces ?? [],\n primitives: input.primitives,\n types,\n icons: iconsByType(input.primitives),\n enhancements: input.enhancements ?? [],\n slackAssetTypes: new Set(input.slackAssetTypes ?? []),\n ...(input.styleAdapter !== undefined\n ? { styleAdapter: input.styleAdapter }\n : {}),\n ...(styleCollector !== undefined ? { styleCollector } : {}),\n ...(input.authoring !== undefined ? { authoring: input.authoring } : {}),\n };\n};\n\n/** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */\nexport const iconsByType = (\n primitives: readonly AnyPrimitiveDefinition[]\n): Readonly<Record<string, PrimitiveIcon>> => {\n const icons = Object.create(null) as Record<string, PrimitiveIcon>;\n for (const { type, icon } of primitives) {\n if (icon !== undefined) {\n icons[type] = icon;\n }\n }\n return Object.freeze(icons);\n};\n\n/** Throws if `primitives` repeats a type. */\nconst assertUniquePrimitiveTypes = (\n id: string,\n primitives: readonly AnyPrimitiveDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const { type } of primitives) {\n if (seen.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" registered twice`\n );\n }\n seen.add(type);\n }\n};\n\n/** Throws if a group names a type outside `types`, or two groups share a type. */\nconst assertGroupedOnce = (\n id: string,\n groups: readonly PrimitiveGroup[],\n types: ReadonlySet<string>\n): void => {\n const grouped = new Set<string>();\n for (const { title, types: members } of groups) {\n for (const type of members) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": group \"${title}\" names primitive type \"${type}\", which the pack does not register`\n );\n }\n if (grouped.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" is in two groups`\n );\n }\n grouped.add(type);\n }\n }\n};\n\n/** Throws if this pack registers the same enhancement id twice. */\nconst assertUniqueEnhancementIds = (\n id: string,\n enhancements: readonly EnhancementDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const definition of enhancements) {\n if (seen.has(definition.id)) {\n throw new IsomerError(\n 'DUPLICATE_ENHANCEMENT',\n `primitive pack \"${id}\": enhancement \"${definition.id}\" registered twice`\n );\n }\n seen.add(definition.id);\n }\n};\n"]}
1
+ {"version":3,"file":"primitive_pack.js","sourceRoot":"","sources":["../../../src/pack/primitive_pack.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,6EAA6E;AAC7E,gFAAgF;AAChF,gEAAgE;AAEhE,gDAAmD;AAiCnD,mGAAmG;AACtF,QAAA,yBAAyB,GAAG,eAAe,CAAC;AAuIzD;;;;;;GAMG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAyB,EACF,EAAE;IACzB,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,mBAAW,CACnB,YAAY,EACZ,mBAAmB,KAAK,CAAC,EAAE,uCAAuC,CACnE,CAAC;IACJ,CAAC;IACD,0BAA0B,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACvD,0BAA0B,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7E,iBAAiB,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IAClE,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,eAAe,IAAI,EAAE,EAAE,CAAC;QAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;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;QAClB,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,MAAM,IAAI,mBAAW,CACnB,wBAAwB,EACxB,mBAAmB,EAAE,aAAa,KAAK,2BAA2B,IAAI,qCAAqC,CAC5G,CAAC;YACJ,CAAC;YACD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtB,MAAM,IAAI,mBAAW,CACnB,0BAA0B,EAC1B,mBAAmB,EAAE,sBAAsB,IAAI,oBAAoB,CACpE,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,mEAAmE;AACnE,MAAM,0BAA0B,GAAG,CACjC,EAAU,EACV,YAA8C,EACxC,EAAE;IACR,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,mBAAW,CACnB,uBAAuB,EACvB,mBAAmB,EAAE,mBAAmB,UAAU,CAAC,EAAE,oBAAoB,CAC1E,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\n// A primitive pack as a value: a vocabulary, and the optional surfaces every\n// primitive in it implements. Additive: a runtime composes any number of packs,\n// and nothing about a pack decides how a composition is framed.\n\nimport { IsomerError } from '../composition/error';\nimport type { PrimitiveIcon } from '../define/primitive_icon';\nimport type {\n AnyPrimitiveDefinition,\n OptionalSurface,\n StyleHandle,\n} from '../define/primitive_module';\n\nimport type { EnhancementDefinition } from './enhancements';\n\n/**\n * The authoring-schema material a pack contributes for its own primitives.\n *\n * A subset of `AuthoringJsonSchemaOptions`: `$id`, `title`, `description`, and\n * `composition` describe the whole authoring schema a runtime builds, which is\n * a host decision, not a pack one. `pack/` does not import `validate/` for\n * this, so the shape is declared here rather than reused by reference.\n */\nexport interface PackAuthoringOptions {\n /** `$def` id to `description`, for this pack's own primitives. */\n describe?: Readonly<Record<string, string>>;\n /** `$defId.property` paths to drop, from this pack's own primitives. */\n omitProperties?: readonly string[];\n /** Headings an index catalog sorts this pack's primitives under, in order. A type in none is listed under {@link UNCATEGORIZED_GROUP_TITLE}. */\n groups?: readonly PrimitiveGroup[];\n}\n\n/** A titled set of primitive types, listed together in an index catalog. */\nexport interface PrimitiveGroup {\n title: string;\n types: readonly string[];\n}\n\n/** The index heading for primitives in no group. A pack cannot declare a group with this title. */\nexport const UNCATEGORIZED_GROUP_TITLE = 'Uncategorized';\n\n/**\n * The HTML style-adapter hooks a pack may declare. Typed loosely here so `pack/` does not import `render/`.\n */\nexport type PackStyleAdapter = {\n /** See {@link PrimitivePackInput.styleCollector}. */\n styleCollector?: string;\n /** The hooks of `HTMLStyleAdapter` from `./html`, erased: a fresh collector per render, the context renderers receive, and the stylesheet the collector produced. */\n createCollector: (...args: never[]) => object;\n createRenderContext: (...args: never[]) => unknown;\n renderStyles: (...args: never[]) => string;\n /**\n * Whether `handle` belongs to this adapter's stylesheet. Required for a runtime to combine several packs' CSS: without it their handles cannot be routed and the host must pick one adapter.\n */\n ownsHandle?: (handle: StyleHandle) => boolean;\n};\n\n/** What a pack author passes to {@link definePrimitivePack}. */\nexport interface PrimitivePackInput {\n /** Stable identifier, used in capability reports and error messages. */\n id: string;\n /**\n * The optional surfaces this pack's primitives implement.\n *\n * Only `slack`, and it stays optional per primitive: the dispatcher converts\n * the mandatory markdown to Block Kit, so declaring it reports an intent\n * rather than imposing a requirement. Omit it entirely for a pack that\n * renders Slack through that fallback.\n */\n surfaces?: readonly OptionalSurface[];\n /** This pack's vocabulary. Node types must be unique within it, or construction throws. */\n primitives: readonly AnyPrimitiveDefinition[];\n /**\n * Progressive enhancements this pack's primitives can apply, by id.\n *\n * Declared by the pack because an enhancement is a fact about its\n * vocabulary — a sortable table, a copyable code block — and a host\n * composing packs it did not write cannot be expected to know the ids.\n * The runtime flattens these across packs; duplicate ids are rejected.\n */\n enhancements?: readonly EnhancementDefinition[];\n /**\n * Types that render as a self-contained picture rather than as text.\n *\n * A channel that cannot draw them inline uploads an image instead: the Slack\n * dispatcher swaps such a node for an `image` block and an upload request, so\n * a chart arrives as a PNG rather than as a markdown approximation of one.\n *\n * Declared by the pack because it is a fact about the vocabulary, and a host\n * composing packs it did not write cannot be expected to know it.\n */\n slackAssetTypes?: readonly string[];\n /**\n * Default HTML style adapter for this pack. A runtime that omits\n * `styleAdapter` runs the packs' own adapters, combined when more than one\n * pack declares one and each answers `ownsHandle`. Pass `styleAdapter` on\n * the runtime to replace them all.\n */\n styleAdapter?: PackStyleAdapter;\n /**\n * Names the collector shape this pack's `collectStyles` hooks mutate, so a\n * runtime can reject a pack paired with an adapter of a different tag.\n * Defaults to `styleAdapter.styleCollector`; a pack with neither opts out of\n * the check.\n */\n styleCollector?: string;\n /**\n * This pack's own contribution to the runtime's authoring JSON Schema.\n *\n * Merged across every composed pack, so a host does not hand-merge each\n * pack's `describe`/`omitProperties` into one options object itself. The\n * runtime-level `authoring` option is merged in last and wins on conflict.\n */\n authoring?: PackAuthoringOptions;\n}\n\n/**\n * A pack as the runtime sees it.\n *\n * `TTheme` is the palette this pack's `react` renderers read as `env.theme`\n * when drawn through the `snapshot` surface — a *lower bound* on whatever theme\n * the runtime holding it supplies. It is carried by\n * {@link PrimitivePack.__theme} rather than by any real field, because\n * `primitives` is erased to `AnyPrimitiveDefinition[]` and a heterogeneous\n * inventory has no single node type to be generic over.\n *\n * The bound is declared, not derived: nothing checks it against what the\n * renderers actually read. State it at the definition as\n * `definePrimitivePack<T>(input)`.\n * Bare `PrimitivePack` requires nothing and fits any runtime; a slot that must\n * hold packs of every palette is typed {@link AnyPrimitivePack}.\n */\nexport interface PrimitivePack<TTheme = unknown> {\n /** Unique among the packs a runtime composes, and used in error messages. */\n readonly id: string;\n /** See {@link PrimitivePackInput.surfaces}. */\n readonly surfaces: readonly OptionalSurface[];\n /** See {@link PrimitivePackInput.primitives}. */\n readonly primitives: readonly AnyPrimitiveDefinition[];\n /** Node types this pack owns, for duplicate detection across packs. */\n readonly types: ReadonlySet<string>;\n /**\n * Each primitive's `icon` by type, for the primitives that declare one, so a host listing them need not walk `primitives`.\n *\n * A frozen null-prototype dictionary: an absent type reads `undefined`, even `constructor`. Absent on a pack built by an SDK that predates icons; {@link iconsByType} derives it from `primitives`.\n */\n readonly icons?: Readonly<Record<string, PrimitiveIcon>>;\n /** See {@link PrimitivePackInput.enhancements}. */\n readonly enhancements: readonly EnhancementDefinition[];\n /** See {@link PrimitivePackInput.slackAssetTypes}. */\n readonly slackAssetTypes: ReadonlySet<string>;\n /** See {@link PrimitivePackInput.styleAdapter}. */\n readonly styleAdapter?: PackStyleAdapter;\n /** See {@link PrimitivePackInput.styleCollector}. */\n readonly styleCollector?: string;\n /** See {@link PrimitivePackInput.authoring}. */\n readonly authoring?: PackAuthoringOptions;\n /**\n * Phantom: never present at runtime, never read.\n *\n * A property rather than a method so `strictFunctionTypes` checks it\n * contravariantly. A method signature is bivariant, which would let a pack\n * needing richer tokens sit in a slot supplying fewer and then read a field\n * nothing supplies — the exact failure this marker exists to prevent.\n */\n readonly __theme?: (theme: TTheme) => void;\n}\n\n/**\n * A pack of any palette, for storage positions: `never` is assignable to every\n * requirement, so a slot typed this way holds every pack.\n */\nexport type AnyPrimitivePack = PrimitivePack<never>;\n\n/**\n * Builds a {@link PrimitivePack}.\n *\n * `TTheme` is the palette a frame must supply for this pack's nodes to be drawn\n * on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is\n * `unknown`, which requires nothing.\n */\nexport const definePrimitivePack = <TTheme = unknown>(\n input: PrimitivePackInput\n): PrimitivePack<TTheme> => {\n if (input.primitives.length === 0) {\n throw new IsomerError(\n 'EMPTY_PACK',\n `primitive pack \"${input.id}\": at least one primitive is required`\n );\n }\n assertUniquePrimitiveTypes(input.id, input.primitives);\n assertUniqueEnhancementIds(input.id, input.enhancements ?? []);\n const types = new Set(input.primitives.map((definition) => definition.type));\n assertValidGroups(input.id, input.authoring?.groups ?? [], types);\n for (const type of input.slackAssetTypes ?? []) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${input.id}\": slackAssetTypes names primitive type \"${type}\", which the pack does not register`\n );\n }\n }\n const styleCollector =\n input.styleCollector ?? input.styleAdapter?.styleCollector;\n\n return {\n id: input.id,\n surfaces: input.surfaces ?? [],\n primitives: input.primitives,\n types,\n icons: iconsByType(input.primitives),\n enhancements: input.enhancements ?? [],\n slackAssetTypes: new Set(input.slackAssetTypes ?? []),\n ...(input.styleAdapter !== undefined\n ? { styleAdapter: input.styleAdapter }\n : {}),\n ...(styleCollector !== undefined ? { styleCollector } : {}),\n ...(input.authoring !== undefined ? { authoring: input.authoring } : {}),\n };\n};\n\n/** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */\nexport const iconsByType = (\n primitives: readonly AnyPrimitiveDefinition[]\n): Readonly<Record<string, PrimitiveIcon>> => {\n const icons = Object.create(null) as Record<string, PrimitiveIcon>;\n for (const { type, icon } of primitives) {\n if (icon !== undefined) {\n icons[type] = icon;\n }\n }\n return Object.freeze(icons);\n};\n\n/** Throws if `primitives` repeats a type. */\nconst assertUniquePrimitiveTypes = (\n id: string,\n primitives: readonly AnyPrimitiveDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const { type } of primitives) {\n if (seen.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" registered twice`\n );\n }\n seen.add(type);\n }\n};\n\n/** Throws if a group repeats or reserves a title, names a type outside `types`, or shares a type with another. */\nconst assertValidGroups = (\n id: string,\n groups: readonly PrimitiveGroup[],\n types: ReadonlySet<string>\n): void => {\n const titles = new Set<string>();\n const grouped = new Set<string>();\n for (const { title, types: members } of groups) {\n if (title === UNCATEGORIZED_GROUP_TITLE) {\n throw new IsomerError(\n 'INVALID_PACK_GROUPS',\n `primitive pack \"${id}\": group title \"${title}\" is reserved for primitives in no group`\n );\n }\n if (titles.has(title)) {\n throw new IsomerError(\n 'INVALID_PACK_GROUPS',\n `primitive pack \"${id}\": group title \"${title}\" is used twice`\n );\n }\n titles.add(title);\n for (const type of members) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": group \"${title}\" names primitive type \"${type}\", which the pack does not register`\n );\n }\n if (grouped.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" is in two groups`\n );\n }\n grouped.add(type);\n }\n }\n};\n\n/** Throws if this pack registers the same enhancement id twice. */\nconst assertUniqueEnhancementIds = (\n id: string,\n enhancements: readonly EnhancementDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const definition of enhancements) {\n if (seen.has(definition.id)) {\n throw new IsomerError(\n 'DUPLICATE_ENHANCEMENT',\n `primitive pack \"${id}\": enhancement \"${definition.id}\" registered twice`\n );\n }\n seen.add(definition.id);\n }\n};\n"]}
@@ -31,8 +31,9 @@ const trimDecimal = (value, precision) => Number.isInteger(value)
31
31
  const formatCompactNumber = (value, unit = '', precision = 1) => {
32
32
  const abs = Math.abs(value);
33
33
  let index = TIERS.findIndex(({ size }) => abs >= size);
34
- if (index === -1)
34
+ if (index === -1) {
35
35
  index = TIERS.length - 1;
36
+ }
36
37
  // A value that rounds up to the tier's next power, `999.96k`, reads as `1m`.
37
38
  if (index > 0 &&
38
39
  Math.abs(Number((value / TIERS[index].size).toFixed(precision))) >= 1_000) {