@elastic/isomer-sdk 0.1.0 → 0.2.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 (222) hide show
  1. package/README.md +13 -2
  2. package/dist/author/authored_fields.d.ts +61 -11
  3. package/dist/author/authored_fields.d.ts.map +1 -1
  4. package/dist/author/authored_fields.js +73 -29
  5. package/dist/author/authored_fields.js.map +1 -1
  6. package/dist/author/authoring_input.d.ts +7 -0
  7. package/dist/author/authoring_input.d.ts.map +1 -0
  8. package/dist/author/authoring_input.js +60 -0
  9. package/dist/author/authoring_input.js.map +1 -0
  10. package/dist/author/authoring_model.d.ts +27 -0
  11. package/dist/author/authoring_model.d.ts.map +1 -0
  12. package/dist/author/authoring_model.js +98 -0
  13. package/dist/author/authoring_model.js.map +1 -0
  14. package/dist/author/declarations.d.ts +13 -0
  15. package/dist/author/declarations.d.ts.map +1 -0
  16. package/dist/author/declarations.js +277 -0
  17. package/dist/author/declarations.js.map +1 -0
  18. package/dist/author/index.d.ts +3 -1
  19. package/dist/author/index.d.ts.map +1 -1
  20. package/dist/author/index.js +3 -1
  21. package/dist/author/index.js.map +1 -1
  22. package/dist/author/jsx_shim.d.ts +6 -5
  23. package/dist/author/jsx_shim.d.ts.map +1 -1
  24. package/dist/author/jsx_shim.js +28 -111
  25. package/dist/author/jsx_shim.js.map +1 -1
  26. package/dist/author/schema_to_typescript.d.ts +37 -0
  27. package/dist/author/schema_to_typescript.d.ts.map +1 -0
  28. package/dist/author/schema_to_typescript.js +286 -0
  29. package/dist/author/schema_to_typescript.js.map +1 -0
  30. package/dist/cjs/author/authored_fields.js +77 -33
  31. package/dist/cjs/author/authored_fields.js.map +1 -1
  32. package/dist/cjs/author/authoring_input.js +64 -0
  33. package/dist/cjs/author/authoring_input.js.map +1 -0
  34. package/dist/cjs/author/authoring_model.js +104 -0
  35. package/dist/cjs/author/authoring_model.js.map +1 -0
  36. package/dist/cjs/author/declarations.js +281 -0
  37. package/dist/cjs/author/declarations.js.map +1 -0
  38. package/dist/cjs/author/index.js +6 -1
  39. package/dist/cjs/author/index.js.map +1 -1
  40. package/dist/cjs/author/jsx_shim.js +31 -114
  41. package/dist/cjs/author/jsx_shim.js.map +1 -1
  42. package/dist/cjs/author/schema_to_typescript.js +295 -0
  43. package/dist/cjs/author/schema_to_typescript.js.map +1 -0
  44. package/dist/cjs/composition/body_node_base.js +11 -4
  45. package/dist/cjs/composition/body_node_base.js.map +1 -1
  46. package/dist/cjs/composition/error.js +1 -0
  47. package/dist/cjs/composition/error.js.map +1 -1
  48. package/dist/cjs/composition/index.js +2 -1
  49. package/dist/cjs/composition/index.js.map +1 -1
  50. package/dist/cjs/define/frame.js +2 -3
  51. package/dist/cjs/define/frame.js.map +1 -1
  52. package/dist/cjs/define/index.js +7 -1
  53. package/dist/cjs/define/index.js.map +1 -1
  54. package/dist/cjs/define/primitive_example.js +26 -0
  55. package/dist/cjs/define/primitive_example.js.map +1 -0
  56. package/dist/cjs/define/primitive_icon.js +17 -0
  57. package/dist/cjs/define/primitive_icon.js.map +1 -0
  58. package/dist/cjs/define/primitive_module.js +14 -3
  59. package/dist/cjs/define/primitive_module.js.map +1 -1
  60. package/dist/cjs/define/slack_assets.js.map +1 -1
  61. package/dist/cjs/entries/index.js +7 -2
  62. package/dist/cjs/entries/index.js.map +1 -1
  63. package/dist/cjs/entries/slack.js +1 -2
  64. package/dist/cjs/entries/slack.js.map +1 -1
  65. package/dist/cjs/pack/capabilities.js +17 -11
  66. package/dist/cjs/pack/capabilities.js.map +1 -1
  67. package/dist/cjs/pack/compose.js +4 -1
  68. package/dist/cjs/pack/compose.js.map +1 -1
  69. package/dist/cjs/pack/index.js.map +1 -1
  70. package/dist/cjs/pack/primitive_pack.js +14 -2
  71. package/dist/cjs/pack/primitive_pack.js.map +1 -1
  72. package/dist/cjs/render/anchors.js +1 -1
  73. package/dist/cjs/render/anchors.js.map +1 -1
  74. package/dist/cjs/render/html/envelope.js.map +1 -1
  75. package/dist/cjs/render/layout_check.js.map +1 -1
  76. package/dist/cjs/render/markdown/builder.js +14 -8
  77. package/dist/cjs/render/markdown/builder.js.map +1 -1
  78. package/dist/cjs/render/markdown/format.js +30 -12
  79. package/dist/cjs/render/markdown/format.js.map +1 -1
  80. package/dist/cjs/render/primitive_dispatch.js +11 -25
  81. package/dist/cjs/render/primitive_dispatch.js.map +1 -1
  82. package/dist/cjs/render/slack/format.js +1 -601
  83. package/dist/cjs/render/slack/format.js.map +1 -1
  84. package/dist/cjs/render/slack/index.js +1 -2
  85. package/dist/cjs/render/slack/index.js.map +1 -1
  86. package/dist/cjs/render/slack/markdown_content.js +166 -115
  87. package/dist/cjs/render/slack/markdown_content.js.map +1 -1
  88. package/dist/cjs/testing/conformance.js +40 -24
  89. package/dist/cjs/testing/conformance.js.map +1 -1
  90. package/dist/cjs/testing/icon.js +248 -0
  91. package/dist/cjs/testing/icon.js.map +1 -0
  92. package/dist/cjs/testing/index.js +3 -1
  93. package/dist/cjs/testing/index.js.map +1 -1
  94. package/dist/cjs/testing/registration.js +5 -3
  95. package/dist/cjs/testing/registration.js.map +1 -1
  96. package/dist/cjs/validate/authoring_schema.js +17 -1
  97. package/dist/cjs/validate/authoring_schema.js.map +1 -1
  98. package/dist/cjs/validate/index.js +2 -1
  99. package/dist/cjs/validate/index.js.map +1 -1
  100. package/dist/cjs/validate/validation.js +2 -45
  101. package/dist/cjs/validate/validation.js.map +1 -1
  102. package/dist/composition/body_node_base.d.ts +7 -6
  103. package/dist/composition/body_node_base.d.ts.map +1 -1
  104. package/dist/composition/body_node_base.js +10 -3
  105. package/dist/composition/body_node_base.js.map +1 -1
  106. package/dist/composition/error.d.ts +1 -0
  107. package/dist/composition/error.d.ts.map +1 -1
  108. package/dist/composition/error.js +1 -0
  109. package/dist/composition/error.js.map +1 -1
  110. package/dist/composition/index.d.ts +1 -1
  111. package/dist/composition/index.d.ts.map +1 -1
  112. package/dist/composition/index.js +1 -1
  113. package/dist/composition/index.js.map +1 -1
  114. package/dist/define/frame.d.ts +9 -20
  115. package/dist/define/frame.d.ts.map +1 -1
  116. package/dist/define/frame.js +2 -3
  117. package/dist/define/frame.js.map +1 -1
  118. package/dist/define/index.d.ts +3 -1
  119. package/dist/define/index.d.ts.map +1 -1
  120. package/dist/define/index.js +3 -1
  121. package/dist/define/index.js.map +1 -1
  122. package/dist/define/primitive_example.d.ts +30 -0
  123. package/dist/define/primitive_example.d.ts.map +1 -0
  124. package/dist/define/primitive_example.js +21 -0
  125. package/dist/define/primitive_example.js.map +1 -0
  126. package/dist/define/primitive_icon.d.ts +11 -0
  127. package/dist/define/primitive_icon.d.ts.map +1 -0
  128. package/dist/define/primitive_icon.js +14 -0
  129. package/dist/define/primitive_icon.js.map +1 -0
  130. package/dist/define/primitive_module.d.ts +38 -24
  131. package/dist/define/primitive_module.d.ts.map +1 -1
  132. package/dist/define/primitive_module.js +14 -3
  133. package/dist/define/primitive_module.js.map +1 -1
  134. package/dist/define/slack_assets.d.ts +1 -1
  135. package/dist/define/slack_assets.d.ts.map +1 -1
  136. package/dist/define/slack_assets.js.map +1 -1
  137. package/dist/entries/index.d.ts +3 -3
  138. package/dist/entries/index.d.ts.map +1 -1
  139. package/dist/entries/index.js +2 -2
  140. package/dist/entries/index.js.map +1 -1
  141. package/dist/entries/slack.d.ts +1 -1
  142. package/dist/entries/slack.d.ts.map +1 -1
  143. package/dist/entries/slack.js +1 -1
  144. package/dist/entries/slack.js.map +1 -1
  145. package/dist/pack/capabilities.d.ts +24 -10
  146. package/dist/pack/capabilities.d.ts.map +1 -1
  147. package/dist/pack/capabilities.js +17 -11
  148. package/dist/pack/capabilities.js.map +1 -1
  149. package/dist/pack/compose.d.ts +4 -1
  150. package/dist/pack/compose.d.ts.map +1 -1
  151. package/dist/pack/compose.js +4 -1
  152. package/dist/pack/compose.js.map +1 -1
  153. package/dist/pack/index.d.ts +1 -1
  154. package/dist/pack/index.d.ts.map +1 -1
  155. package/dist/pack/index.js +1 -1
  156. package/dist/pack/index.js.map +1 -1
  157. package/dist/pack/primitive_pack.d.ts +11 -2
  158. package/dist/pack/primitive_pack.d.ts.map +1 -1
  159. package/dist/pack/primitive_pack.js +12 -1
  160. package/dist/pack/primitive_pack.js.map +1 -1
  161. package/dist/render/anchors.d.ts +2 -2
  162. package/dist/render/anchors.d.ts.map +1 -1
  163. package/dist/render/anchors.js +1 -1
  164. package/dist/render/anchors.js.map +1 -1
  165. package/dist/render/html/envelope.d.ts +3 -3
  166. package/dist/render/html/envelope.js.map +1 -1
  167. package/dist/render/layout_check.d.ts +1 -1
  168. package/dist/render/layout_check.d.ts.map +1 -1
  169. package/dist/render/layout_check.js.map +1 -1
  170. package/dist/render/markdown/builder.d.ts +2 -4
  171. package/dist/render/markdown/builder.d.ts.map +1 -1
  172. package/dist/render/markdown/builder.js +14 -7
  173. package/dist/render/markdown/builder.js.map +1 -1
  174. package/dist/render/markdown/format.d.ts +7 -0
  175. package/dist/render/markdown/format.d.ts.map +1 -1
  176. package/dist/render/markdown/format.js +27 -11
  177. package/dist/render/markdown/format.js.map +1 -1
  178. package/dist/render/primitive_dispatch.d.ts +6 -6
  179. package/dist/render/primitive_dispatch.d.ts.map +1 -1
  180. package/dist/render/primitive_dispatch.js +12 -26
  181. package/dist/render/primitive_dispatch.js.map +1 -1
  182. package/dist/render/slack/format.d.ts +0 -25
  183. package/dist/render/slack/format.d.ts.map +1 -1
  184. package/dist/render/slack/format.js +1 -599
  185. package/dist/render/slack/format.js.map +1 -1
  186. package/dist/render/slack/index.d.ts +1 -1
  187. package/dist/render/slack/index.d.ts.map +1 -1
  188. package/dist/render/slack/index.js +1 -1
  189. package/dist/render/slack/index.js.map +1 -1
  190. package/dist/render/slack/markdown_content.d.ts +10 -4
  191. package/dist/render/slack/markdown_content.d.ts.map +1 -1
  192. package/dist/render/slack/markdown_content.js +163 -113
  193. package/dist/render/slack/markdown_content.js.map +1 -1
  194. package/dist/testing/conformance.d.ts +19 -14
  195. package/dist/testing/conformance.d.ts.map +1 -1
  196. package/dist/testing/conformance.js +40 -24
  197. package/dist/testing/conformance.js.map +1 -1
  198. package/dist/testing/icon.d.ts +11 -0
  199. package/dist/testing/icon.d.ts.map +1 -0
  200. package/dist/testing/icon.js +244 -0
  201. package/dist/testing/icon.js.map +1 -0
  202. package/dist/testing/index.d.ts +2 -1
  203. package/dist/testing/index.d.ts.map +1 -1
  204. package/dist/testing/index.js +1 -0
  205. package/dist/testing/index.js.map +1 -1
  206. package/dist/testing/registration.d.ts +1 -1
  207. package/dist/testing/registration.d.ts.map +1 -1
  208. package/dist/testing/registration.js +6 -4
  209. package/dist/testing/registration.js.map +1 -1
  210. package/dist/validate/authoring_schema.d.ts +6 -0
  211. package/dist/validate/authoring_schema.d.ts.map +1 -1
  212. package/dist/validate/authoring_schema.js +15 -0
  213. package/dist/validate/authoring_schema.js.map +1 -1
  214. package/dist/validate/index.d.ts +1 -1
  215. package/dist/validate/index.d.ts.map +1 -1
  216. package/dist/validate/index.js +1 -1
  217. package/dist/validate/index.js.map +1 -1
  218. package/dist/validate/validation.d.ts +1 -11
  219. package/dist/validate/validation.d.ts.map +1 -1
  220. package/dist/validate/validation.js +3 -46
  221. package/dist/validate/validation.js.map +1 -1
  222. package/package.json +3 -2
package/README.md CHANGED
@@ -1,4 +1,15 @@
1
- # `@elastic/isomer-sdk`
1
+ <!-- markdownlint-disable MD033 -->
2
+ <p align="center">
3
+ <img src="https://raw.githubusercontent.com/elastic/isomer/main/docs/logo.svg" alt="Isomer" width="96" height="96">
4
+ </p>
5
+ <h1 align="center">@elastic/isomer-sdk</h1>
6
+ <p align="center"><strong>isomer</strong> <i>n.</i> — one formula, many forms; the same composition rendered to every surface.</p>
7
+ <p align="center">
8
+ <a href="https://www.npmjs.com/package/@elastic/isomer-sdk"><img src="https://img.shields.io/npm/v/@elastic/isomer-sdk.svg" alt="npm version"></a>
9
+ <a href="https://github.com/elastic/isomer/actions/workflows/ci.yml"><img src="https://github.com/elastic/isomer/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
10
+ <a href="https://github.com/elastic/isomer/blob/main/LICENSE.txt"><img src="https://img.shields.io/badge/License-Elastic%202.0-blue.svg" alt="License: Elastic License 2.0"></a>
11
+ </p>
12
+ <!-- markdownlint-enable MD033 -->
2
13
 
3
14
  The contracts every other Isomer package is written against: what a primitive is, what a pack is, the `Composition` schema, the validator and parser, the dispatcher, the envelopes for text, Markdown, Slack, and HTML, the URL trust policy, the authoring front ends, and the pack conformance harness. `@elastic/isomer-runtime` assembles packs into complete render surfaces; hosts own data, authorization, routing, and side effects.
4
15
 
@@ -32,7 +43,7 @@ const kpi = definePrimitive({
32
43
  export const metricsPack = definePrimitivePack({ id: 'metrics', primitives: [kpi] });
33
44
  ```
34
45
 
35
- `react`, `text`, and `markdown` are mandatory, which is what makes every composition degrade. `slack` is optional and falls back through Markdown. There is no `svg` renderer: the image surface reuses `react`. Hand the pack to `createIsomerRuntime` from `@elastic/isomer-runtime` and every surface renders it.
46
+ `react`, `text`, and `markdown` are mandatory, which is what makes every composition degrade. `slack` is optional and falls back through Markdown. There is no `snapshot` renderer: the `snapshot` surface reuses `react`. Hand the pack to `createIsomerRuntime` from `@elastic/isomer-runtime` and every surface renders it.
36
47
 
37
48
  ## Docs
38
49
 
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
- import type { ZodType } from 'zod';
2
+ import { type ZodType } from 'zod';
3
3
  import type { PrimitiveNode } from '../define/primitive_module.js';
4
4
  /**
5
5
  * Child-element type a schema field is filled from.
@@ -11,6 +11,8 @@ export declare const authoredChild: unique symbol;
11
11
  export declare const authoredProps: unique symbol;
12
12
  /** Set when a field is filled from text children. */
13
13
  export declare const authoredText: unique symbol;
14
+ /** Holds a {@link fromChildren} brand's `toItem`. */
15
+ export declare const authoredToItem: unique symbol;
14
16
  /**
15
17
  * A field filled from child elements of `TName`.
16
18
  *
@@ -21,6 +23,10 @@ export interface AuthoredChildBrand<TName extends string, TProps> {
21
23
  readonly [authoredChild]: TName;
22
24
  readonly [authoredProps]: TProps;
23
25
  }
26
+ /** A child field whose `toItem` builds each item, so the shim fills none of the item's own brands. */
27
+ export interface AuthoredToItemBrand {
28
+ readonly [authoredToItem]: (props: never, context: AuthorChildContext) => unknown;
29
+ }
24
30
  /** A field filled from text children. */
25
31
  export interface AuthoredTextBrand {
26
32
  readonly [authoredText]: true;
@@ -31,17 +37,43 @@ export interface AuthorChildContext {
31
37
  parseChildren: (children: ReactNode) => PrimitiveNode[];
32
38
  }
33
39
  type ArrayItem<TSchema extends ZodType> = NonNullable<zOutput<TSchema>> extends readonly (infer Item)[] ? Item : NonNullable<zOutput<TSchema>>;
40
+ type zInput<TSchema> = TSchema extends {
41
+ _zod: {
42
+ input: infer Input;
43
+ };
44
+ } ? Input : never;
34
45
  type zOutput<TSchema> = TSchema extends {
35
46
  _zod: {
36
47
  output: infer Output;
37
48
  };
38
49
  } ? Output : never;
39
- /** `TText` is optional on the child props because leftover text fills it. */
40
- type ChildProps<TItem, TText extends string | undefined> = [TText] extends [
41
- string
42
- ] ? Omit<TItem, TText> & Partial<Pick<TItem, Extract<TText, keyof TItem>>> & {
50
+ type WrapperOf<TInner> = {
51
+ _zod: {
52
+ def: {
53
+ type: 'optional' | 'nullable' | 'default' | 'readonly';
54
+ innerType: TInner;
55
+ };
56
+ };
57
+ };
58
+ type Unwrapped<TSchema> = TSchema extends WrapperOf<infer Inner> ? Unwrapped<Inner> : TSchema;
59
+ /** Whether `F`, or a wrapper layer of it, carries a {@link fromChildren} brand. */
60
+ type IsChildBranded<F> = F extends AuthoredChildBrand<string, unknown> ? true : F extends WrapperOf<infer Inner> ? IsChildBranded<Inner> : false;
61
+ /** A branded field's item schema: the array element through any wrapper, or the unwrapped schema. */
62
+ export type ItemSchema<TSchema> = Unwrapped<TSchema> extends {
63
+ element: infer Element;
64
+ } ? Element : Unwrapped<TSchema>;
65
+ /** Item fields a nested {@link fromChildren} brand fills from child elements. */
66
+ type ChildBrandedKeys<TItemSchema> = TItemSchema extends {
67
+ shape: infer Shape;
68
+ } ? string extends keyof Shape ? never : {
69
+ [K in keyof Shape]: IsChildBranded<Shape[K]> extends true ? K : never;
70
+ }[keyof Shape] : never;
71
+ /** `TOptional` is optional on the child props because text or child elements fill it. */
72
+ type ChildProps<TItem, TOptional extends PropertyKey> = [TOptional] extends [
73
+ never
74
+ ] ? TItem & {
43
75
  children?: ReactNode;
44
- } : TItem & {
76
+ } : Omit<TItem, TOptional> & Partial<Pick<TItem, Extract<TOptional, keyof TItem>>> & {
45
77
  children?: ReactNode;
46
78
  };
47
79
  /**
@@ -53,14 +85,25 @@ type ChildProps<TItem, TText extends string | undefined> = [TText] extends [
53
85
  * `.readonly()`; any other method clones without it, so call it on `schema`
54
86
  * before passing it in.
55
87
  */
56
- export declare function fromChildren<const TName extends string, TSchema extends ZodType>(childType: TName, schema: TSchema): TSchema & AuthoredChildBrand<TName, ChildProps<ArrayItem<TSchema>, undefined>>;
88
+ export declare function fromChildren<const TName extends string, TSchema extends ZodType>(childType: TName, schema: TSchema): TSchema & AuthoredChildBrand<TName, ChildProps<ArrayItem<TSchema>, ChildBrandedKeys<ItemSchema<TSchema>>>>;
57
89
  export declare function fromChildren<const TName extends string, TSchema extends ZodType, const TText extends string>(childType: TName, schema: TSchema, options: {
58
90
  text: TText;
59
- }): TSchema & AuthoredChildBrand<TName, ChildProps<ArrayItem<TSchema>, TText>>;
91
+ toItem?: never;
92
+ }): TSchema & AuthoredChildBrand<TName, ChildProps<ArrayItem<TSchema>, TText | ChildBrandedKeys<ItemSchema<TSchema>>>>;
93
+ export declare function fromChildren<const TName extends string, TSchema extends ZodType, TPropsSchema extends ZodType>(childType: TName, schema: TSchema, options: {
94
+ text?: string;
95
+ propsSchema: TPropsSchema;
96
+ toItem(props: zInput<TPropsSchema> & {
97
+ children?: ReactNode;
98
+ }, context: AuthorChildContext): unknown;
99
+ }): TSchema & AuthoredChildBrand<TName, zInput<TPropsSchema> & {
100
+ children?: ReactNode;
101
+ }> & AuthoredToItemBrand;
60
102
  export declare function fromChildren<const TName extends string, TSchema extends ZodType, TProps>(childType: TName, schema: TSchema, options: {
61
103
  text?: string;
62
104
  toItem(props: TProps, context: AuthorChildContext): unknown;
63
- }): TSchema & AuthoredChildBrand<TName, TProps>;
105
+ propsSchema?: never;
106
+ }): TSchema & AuthoredChildBrand<TName, TProps> & AuthoredToItemBrand;
64
107
  /**
65
108
  * Brands `schema` as text children.
66
109
  *
@@ -79,9 +122,13 @@ export interface AuthoredChildField {
79
122
  toItem?: (props: object, context: AuthorChildContext) => unknown;
80
123
  /** The array element schema, or the field schema itself when it is not an array. */
81
124
  itemSchema: ZodType;
125
+ /** Input props for a custom `toItem`, excluding JSX children. */
126
+ propsSchema?: ZodType;
127
+ /** Whether the field holds an array of items rather than one item. */
128
+ array: boolean;
82
129
  /** Whether the field accepts `undefined`, so children may be omitted. */
83
130
  optional: boolean;
84
- /** Structural fingerprint of `itemSchema`; every field branding one child type must share it. */
131
+ /** Structural input-schema fingerprint shared by fields branding one child type. */
85
132
  signature: string;
86
133
  }
87
134
  /** One {@link fromTextChildren} field as the shim reads it. */
@@ -97,7 +144,10 @@ export interface AuthoredSpec {
97
144
  children: AuthoredChildField[];
98
145
  text: AuthoredTextField[];
99
146
  }
100
- /** Top-level branded fields on an object schema. Nested brands stay on the item schema. */
147
+ /**
148
+ * The branded fields on an object schema, top level only: read a child's own
149
+ * brands from its {@link AuthoredChildField.itemSchema}.
150
+ */
101
151
  export declare const readAuthoredSpec: (schema: ZodType) => AuthoredSpec;
102
152
  export {};
103
153
  //# sourceMappingURL=authored_fields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authored_fields.d.ts","sourceRoot":"","sources":["../../src/author/authored_fields.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAGnC,OAAO,KAAK,EAAE,aAAa,EAAE,MA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,EAAE,OAAO,CAAC;CACnB;AAED,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,IAAI,EAAE,iBAAiB,EAAE,CAAC;CAC3B;AA6KD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,OAAO,KAAG,YAoBlD,CAAC"}
@@ -4,7 +4,9 @@
4
4
  * 2.0; you may not use this file except in compliance with the Elastic License
5
5
  * 2.0.
6
6
  */
7
+ import { z } from 'zod';
7
8
  import { ISOMER_ERROR_CODES, IsomerError } from '../composition/error.js';
9
+ import { prepareAuthoringInput } from './authoring_input.js';
8
10
  /**
9
11
  * Child-element type a schema field is filled from.
10
12
  *
@@ -15,15 +17,18 @@ export const authoredChild = Symbol.for('elastic.isomer.authored_child');
15
17
  export const authoredProps = Symbol.for('elastic.isomer.authored_props');
16
18
  /** Set when a field is filled from text children. */
17
19
  export const authoredText = Symbol.for('elastic.isomer.authored_text');
18
- const authoredToItem = Symbol.for('elastic.isomer.authored_to_item');
20
+ /** Holds a {@link fromChildren} brand's `toItem`. */
21
+ export const authoredToItem = Symbol.for('elastic.isomer.authored_to_item');
19
22
  const authoredTextField = Symbol.for('elastic.isomer.authored_text_field');
20
23
  const authoredCollapse = Symbol.for('elastic.isomer.authored_collapse');
24
+ const authoredPropsSchema = Symbol.for('elastic.isomer.authored_props_schema');
21
25
  const BRANDS = [
22
26
  authoredChild,
23
27
  authoredTextField,
24
28
  authoredToItem,
25
29
  authoredText,
26
30
  authoredCollapse,
31
+ authoredPropsSchema,
27
32
  ];
28
33
  // Applies a complete branding. Branding an instance again is allowed only with
29
34
  // the same configuration, absent options included, since both fields share it.
@@ -48,6 +53,7 @@ export function fromChildren(childType, schema, options) {
48
53
  [authoredChild]: childType,
49
54
  [authoredTextField]: options?.text,
50
55
  [authoredToItem]: options?.toItem,
56
+ [authoredPropsSchema]: options?.propsSchema,
51
57
  });
52
58
  return schema;
53
59
  }
@@ -97,34 +103,63 @@ const isOptionalSchema = (schema) => {
97
103
  const type = zodDefType(schema);
98
104
  return type === 'optional' || type === 'default';
99
105
  };
100
- const schemaSignature = (schema, seen = new Set()) => {
101
- if (seen.has(schema)) {
102
- return 'cycle';
103
- }
104
- seen.add(schema);
105
- const type = zodDefType(schema) ?? '?';
106
- if (type === 'object' && 'shape' in schema) {
107
- const shape = schema.shape;
108
- const fields = Object.keys(shape)
109
- .sort()
110
- .map((key) => `${key}:${schemaSignature(shape[key], seen)}`);
111
- return `{${fields.join(',')}}`;
112
- }
113
- if (type === 'array' && 'element' in schema) {
114
- return `[${schemaSignature(schema.element, seen)}]`;
115
- }
116
- const inner = innerSchema(schema);
117
- if (inner) {
118
- return `${type}(${schemaSignature(inner, seen)})`;
119
- }
120
- return type;
106
+ const UNORDERED_SCHEMA_ARRAYS = new Set([
107
+ 'allOf',
108
+ 'anyOf',
109
+ 'enum',
110
+ 'oneOf',
111
+ 'required',
112
+ 'type',
113
+ ]);
114
+ const schemaSignature = (schema) => {
115
+ const { schema: input } = prepareAuthoringInput(schema);
116
+ const projected = z.toJSONSchema(input, {
117
+ io: 'input',
118
+ target: 'draft-2020-12',
119
+ cycles: 'ref',
120
+ reused: 'inline',
121
+ unrepresentable: 'any',
122
+ metadata: z.registry(),
123
+ });
124
+ const active = new Map();
125
+ const canonical = (value, key = '') => {
126
+ if (Array.isArray(value)) {
127
+ const members = value.map((member) => canonical(member));
128
+ if (UNORDERED_SCHEMA_ARRAYS.has(key))
129
+ members.sort();
130
+ return `[${members.join(',')}]`;
131
+ }
132
+ if (typeof value !== 'object' || value === null) {
133
+ return JSON.stringify(value) ?? 'undefined';
134
+ }
135
+ const cycle = active.get(value);
136
+ if (cycle !== undefined)
137
+ return `cycle:${cycle}`;
138
+ const object = value;
139
+ const ref = object.$ref;
140
+ const target = ref === '#'
141
+ ? projected
142
+ : typeof ref === 'string' && ref.startsWith('#/$defs/')
143
+ ? projected.$defs?.[ref.slice('#/$defs/'.length)]
144
+ : undefined;
145
+ if (target && Object.keys(object).length === 1)
146
+ return canonical(target);
147
+ active.set(value, active.size);
148
+ const result = `{${Object.entries(object)
149
+ .filter(([key]) => value !== projected || key !== '$defs')
150
+ .sort(([first], [second]) => first.localeCompare(second))
151
+ .map(([key, member]) => `${JSON.stringify(key)}:${canonical(key === '$ref' && target ? target : member, key)}`)
152
+ .join(',')}}`;
153
+ active.delete(value);
154
+ return result;
155
+ };
156
+ return canonical(projected);
121
157
  };
122
158
  const arrayElement = (schema) => {
123
159
  const inner = unwrapAll(schema);
124
- if (zodDefType(inner) === 'array' && 'element' in inner) {
125
- return inner.element;
126
- }
127
- return inner;
160
+ return zodDefType(inner) === 'array' && 'element' in inner
161
+ ? inner.element
162
+ : undefined;
128
163
  };
129
164
  const readChild = (field, schema) => {
130
165
  const holder = brandHolder(schema, authoredChild);
@@ -134,13 +169,19 @@ const readChild = (field, schema) => {
134
169
  }
135
170
  const textField = holder[authoredTextField];
136
171
  const toItem = holder[authoredToItem];
172
+ const propsSchema = holder[authoredPropsSchema];
173
+ const element = arrayElement(holder);
174
+ const itemSchema = element ?? unwrapAll(holder);
137
175
  const child = {
138
176
  field,
139
177
  childType,
140
- itemSchema: arrayElement(holder),
178
+ itemSchema,
179
+ array: element !== undefined,
141
180
  optional: optionalThrough(schema),
142
- signature: schemaSignature(arrayElement(holder)),
181
+ signature: `${schemaSignature(itemSchema)}|${typeof textField === 'string' ? textField : ''}|${propsSchema ? schemaSignature(propsSchema) : ''}`,
143
182
  };
183
+ if (propsSchema)
184
+ child.propsSchema = propsSchema;
144
185
  if (typeof textField === 'string') {
145
186
  child.textField = textField;
146
187
  }
@@ -160,7 +201,10 @@ const readText = (field, schema) => {
160
201
  optional: optionalThrough(schema),
161
202
  };
162
203
  };
163
- /** Top-level branded fields on an object schema. Nested brands stay on the item schema. */
204
+ /**
205
+ * The branded fields on an object schema, top level only: read a child's own
206
+ * brands from its {@link AuthoredChildField.itemSchema}.
207
+ */
164
208
  export const readAuthoredSpec = (schema) => {
165
209
  if (zodDefType(schema) !== 'object' || !('shape' in schema)) {
166
210
  return { children: [], text: [] };
@@ -1 +1 @@
1
- {"version":3,"file":"authored_fields.js","sourceRoot":"","sources":["../../src/author/authored_fields.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGvE;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAEzE,sEAAsE;AACtE,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAEzE,qDAAqD;AACrD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAEvE,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AACrE,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAC3E,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AA2CxE,MAAM,MAAM,GAAG;IACb,aAAa;IACb,iBAAiB;IACjB,cAAc;IACd,YAAY;IACZ,gBAAgB;CACR,CAAC;AAEX,+EAA+E;AAC/E,+EAA+E;AAC/E,MAAM,KAAK,GAAG,CACZ,MAA2C,EAC3C,MAAc,EACd,MAAyD,EACnD,EAAE;IACR,MAAM,MAAM,GAAG,MAAiC,CAAC;IACjD,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;QACrD,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,GA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,YAAY,CAAC,CAAC;IACjD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO;QACL,KAAK;QACL,kBAAkB,EACf,MAA2C,CAAC,gBAAgB,CAAC,KAAK,KAAK;QAC1E,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC;KAClC,CAAC;AACJ,CAAC,CAAC;AAEF,2FAA2F;AAC3F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAe,EAAgB,EAAE;IAChE,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC,EAAE,CAAC;QAC5D,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IACpC,CAAC;IACD,MAAM,QAAQ,GAAyB,EAAE,CAAC;IAC1C,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,KAAK,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAC/C,MAAM,CAAC,KAAgC,CACxC,EAAE,CAAC;QACF,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAC5C,IAAI,KAAK,EAAE,CAAC;YACV,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,SAAS;QACX,CAAC;QACD,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAC/C,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAC5B,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 type { ZodType } from 'zod';\n\nimport { ISOMER_ERROR_CODES, IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../define/primitive_module';\n\n/**\n * Child-element type a schema field is filled from.\n *\n * `Symbol.for`: ESM and CJS builds must agree, same as `authorType`.\n */\nexport const authoredChild = Symbol.for('elastic.isomer.authored_child');\n\n/** Phantom props type for the child component. Not set at runtime. */\nexport const authoredProps = Symbol.for('elastic.isomer.authored_props');\n\n/** Set when a field is filled from text children. */\nexport const authoredText = Symbol.for('elastic.isomer.authored_text');\n\nconst authoredToItem = Symbol.for('elastic.isomer.authored_to_item');\nconst authoredTextField = Symbol.for('elastic.isomer.authored_text_field');\nconst authoredCollapse = Symbol.for('elastic.isomer.authored_collapse');\n\n/**\n * A field filled from child elements of `TName`.\n *\n * Phantom: `z.infer` still reads the underlying schema. The shim reads `TName`\n * and `TProps` off the field type, and the symbols off the schema value.\n */\nexport interface AuthoredChildBrand<TName extends string, TProps> {\n readonly [authoredChild]: TName;\n readonly [authoredProps]: TProps;\n}\n\n/** A field filled from text children. */\nexport interface AuthoredTextBrand {\n readonly [authoredText]: true;\n}\n\n/** What {@link fromChildren}'s `toItem` receives. */\nexport interface AuthorChildContext {\n /** Nested elements, parsed as body nodes. */\n parseChildren: (children: ReactNode) => PrimitiveNode[];\n}\n\ntype ArrayItem<TSchema extends ZodType> =\n NonNullable<zOutput<TSchema>> extends readonly (infer Item)[]\n ? Item\n : NonNullable<zOutput<TSchema>>;\n\ntype zOutput<TSchema> = TSchema extends { _zod: { output: infer Output } }\n ? Output\n : never;\n\n/** `TText` is optional on the child props because leftover text fills it. */\ntype ChildProps<TItem, TText extends string | undefined> = [TText] extends [\n string,\n]\n ? Omit<TItem, TText> &\n Partial<Pick<TItem, Extract<TText, keyof TItem>>> & {\n children?: ReactNode;\n }\n : TItem & { children?: ReactNode };\n\nconst BRANDS = [\n authoredChild,\n authoredTextField,\n authoredToItem,\n authoredText,\n authoredCollapse,\n] as const;\n\n// Applies a complete branding. Branding an instance again is allowed only with\n// the same configuration, absent options included, since both fields share it.\nconst brand = (\n caller: 'fromChildren' | 'fromTextChildren',\n schema: object,\n config: Partial<Record<(typeof BRANDS)[number], unknown>>\n): void => {\n const record = schema as Record<symbol, unknown>;\n if (BRANDS.some((key) => Object.hasOwn(schema, key))) {\n if (BRANDS.every((key) => record[key] === config[key])) return;\n throw new IsomerError(\n ISOMER_ERROR_CODES.AUTHORED_SCHEMA_REUSED,\n `${caller}: this schema instance is already branded another way; pass each field its own schema.`\n );\n }\n for (const key of BRANDS) {\n if (config[key] !== undefined) {\n Object.defineProperty(schema, key, {\n value: config[key],\n enumerable: false,\n });\n }\n }\n};\n\n/**\n * Brands `schema` as JSX children of `childType`.\n *\n * `options.text` copies leftover text onto that field. `options.toItem` replaces\n * the default prop copy; its props annotation is the child component's props.\n * The brand is read through `.optional()`, `.nullable()`, `.default()`, and\n * `.readonly()`; any other method clones without it, so call it on `schema`\n * before passing it in.\n */\nexport function fromChildren<\n const TName extends string,\n TSchema extends ZodType,\n>(\n childType: TName,\n schema: TSchema\n): TSchema &\n AuthoredChildBrand<TName, ChildProps<ArrayItem<TSchema>, undefined>>;\nexport function fromChildren<\n const TName extends string,\n TSchema extends ZodType,\n const TText extends string,\n>(\n childType: TName,\n schema: TSchema,\n options: { text: TText }\n): TSchema & AuthoredChildBrand<TName, ChildProps<ArrayItem<TSchema>, TText>>;\nexport function fromChildren<\n const TName extends string,\n TSchema extends ZodType,\n TProps,\n>(\n childType: TName,\n schema: TSchema,\n options: {\n text?: string;\n toItem(props: TProps, context: AuthorChildContext): unknown;\n }\n): TSchema & AuthoredChildBrand<TName, TProps>;\nexport function fromChildren(\n childType: string,\n schema: ZodType,\n options?: {\n text?: string;\n toItem?: (this: void, props: never, context: AuthorChildContext) => unknown;\n }\n): ZodType {\n brand('fromChildren', schema, {\n [authoredChild]: childType,\n [authoredTextField]: options?.text,\n [authoredToItem]: options?.toItem,\n });\n return schema;\n}\n\n/**\n * Brands `schema` as text children.\n *\n * Whitespace collapses unless `collapseWhitespace` is `false`.\n */\nexport const fromTextChildren = <TSchema extends ZodType>(\n schema: TSchema,\n options?: { collapseWhitespace?: boolean }\n): TSchema & AuthoredTextBrand => {\n brand('fromTextChildren', schema, {\n [authoredText]: true,\n [authoredCollapse]:\n options?.collapseWhitespace === false ? false : undefined,\n });\n return schema as TSchema & AuthoredTextBrand;\n};\n\n/** One {@link fromChildren} field as the shim reads it. */\nexport interface AuthoredChildField {\n field: string;\n childType: string;\n /** Field leftover text children fill. */\n textField?: string;\n /** Replaces the default prop copy. */\n toItem?: (props: object, context: AuthorChildContext) => unknown;\n /** The array element schema, or the field schema itself when it is not an array. */\n itemSchema: ZodType;\n /** Whether the field accepts `undefined`, so children may be omitted. */\n optional: boolean;\n /** Structural fingerprint of `itemSchema`; every field branding one child type must share it. */\n signature: string;\n}\n\n/** One {@link fromTextChildren} field as the shim reads it. */\nexport interface AuthoredTextField {\n field: string;\n /** `true` unless the brand was given `collapseWhitespace: false`. */\n collapseWhitespace: boolean;\n /** Whether the field accepts `undefined`, so text children may be omitted. */\n optional: boolean;\n}\n\n/** The branded fields found on one object schema. */\nexport interface AuthoredSpec {\n children: AuthoredChildField[];\n text: AuthoredTextField[];\n}\n\nconst zodDefType = (schema: object): string | undefined =>\n (schema as { _zod?: { def?: { type?: string } } })._zod?.def?.type;\n\nconst WRAPPER_TYPES = new Set(['optional', 'nullable', 'default', 'readonly']);\n\ninterface WrapperDef {\n type?: string;\n innerType?: ZodType;\n}\n\nconst innerSchema = (schema: ZodType): ZodType | undefined => {\n const def: WrapperDef | undefined = (\n schema as { _zod?: { def?: WrapperDef } }\n )._zod?.def;\n return def?.type && WRAPPER_TYPES.has(def.type) ? def.innerType : undefined;\n};\n\n// The schema holding `brand`: `schema` or one it wraps.\nconst brandHolder = (schema: ZodType, key: symbol): ZodType | undefined => {\n let current: ZodType | undefined = schema;\n while (current && !Object.hasOwn(current, key)) {\n current = innerSchema(current);\n }\n return current;\n};\n\n// Whether any wrapper layer of `schema` accepts `undefined`.\nconst optionalThrough = (schema: ZodType): boolean => {\n for (\n let current: ZodType | undefined = schema;\n current;\n current = innerSchema(current)\n ) {\n if (isOptionalSchema(current)) return true;\n }\n return false;\n};\n\nconst unwrapAll = (schema: ZodType): ZodType => {\n let current = schema;\n for (let inner = innerSchema(current); inner; inner = innerSchema(current)) {\n current = inner;\n }\n return current;\n};\n\n/** `undefined` is a valid value, so children may be omitted. */\nconst isOptionalSchema = (schema: ZodType): boolean => {\n const type = zodDefType(schema);\n return type === 'optional' || type === 'default';\n};\n\nconst schemaSignature = (\n schema: ZodType,\n seen: Set<object> = new Set()\n): string => {\n if (seen.has(schema)) {\n return 'cycle';\n }\n seen.add(schema);\n const type = zodDefType(schema) ?? '?';\n if (type === 'object' && 'shape' in schema) {\n const shape = schema.shape as Record<string, ZodType>;\n const fields = Object.keys(shape)\n .sort()\n .map((key) => `${key}:${schemaSignature(shape[key] as ZodType, seen)}`);\n return `{${fields.join(',')}}`;\n }\n if (type === 'array' && 'element' in schema) {\n return `[${schemaSignature((schema as { element: ZodType }).element, seen)}]`;\n }\n const inner = innerSchema(schema);\n if (inner) {\n return `${type}(${schemaSignature(inner, seen)})`;\n }\n return type;\n};\n\nconst arrayElement = (schema: ZodType): ZodType => {\n const inner = unwrapAll(schema);\n if (zodDefType(inner) === 'array' && 'element' in inner) {\n return (inner as { element: ZodType }).element;\n }\n return inner;\n};\n\nconst readChild = (\n field: string,\n schema: ZodType\n): AuthoredChildField | undefined => {\n const holder = brandHolder(schema, authoredChild);\n const childType = (holder as { [authoredChild]?: unknown } | undefined)?.[\n authoredChild\n ];\n if (!holder || typeof childType !== 'string') {\n return undefined;\n }\n const textField = (holder as { [authoredTextField]?: unknown })[\n authoredTextField\n ];\n const toItem = (holder as { [authoredToItem]?: unknown })[authoredToItem];\n const child: AuthoredChildField = {\n field,\n childType,\n itemSchema: arrayElement(holder),\n optional: optionalThrough(schema),\n signature: schemaSignature(arrayElement(holder)),\n };\n if (typeof textField === 'string') {\n child.textField = textField;\n }\n if (typeof toItem === 'function') {\n child.toItem = toItem as (\n props: object,\n context: AuthorChildContext\n ) => unknown;\n }\n return child;\n};\n\nconst readText = (\n field: string,\n schema: ZodType\n): AuthoredTextField | undefined => {\n const holder = brandHolder(schema, authoredText);\n if (!holder) {\n return undefined;\n }\n return {\n field,\n collapseWhitespace:\n (holder as { [authoredCollapse]?: unknown })[authoredCollapse] !== false,\n optional: optionalThrough(schema),\n };\n};\n\n/** Top-level branded fields on an object schema. Nested brands stay on the item schema. */\nexport const readAuthoredSpec = (schema: ZodType): AuthoredSpec => {\n if (zodDefType(schema) !== 'object' || !('shape' in schema)) {\n return { children: [], text: [] };\n }\n const children: AuthoredChildField[] = [];\n const text: AuthoredTextField[] = [];\n for (const [field, fieldSchema] of Object.entries(\n schema.shape as Record<string, ZodType>\n )) {\n const child = readChild(field, fieldSchema);\n if (child) {\n children.push(child);\n continue;\n }\n const textField = readText(field, fieldSchema);\n if (textField) {\n text.push(textField);\n }\n }\n return { children, text };\n};\n"]}
1
+ {"version":3,"file":"authored_fields.js","sourceRoot":"","sources":["../../src/author/authored_fields.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,CAAC,EAAgB,MAAM,KAAK,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAEzE,sEAAsE;AACtE,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAEzE,qDAAqD;AACrD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,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YACd,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAC5B,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 ZodType } from 'zod';\n\nimport { ISOMER_ERROR_CODES, IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../define/primitive_module';\n\nimport { prepareAuthoringInput } from './authoring_input';\n\n/**\n * Child-element type a schema field is filled from.\n *\n * `Symbol.for`: ESM and CJS builds must agree, same as `authorType`.\n */\nexport const authoredChild = Symbol.for('elastic.isomer.authored_child');\n\n/** Phantom props type for the child component. Not set at runtime. */\nexport const authoredProps = Symbol.for('elastic.isomer.authored_props');\n\n/** Set when a field is filled from text children. */\nexport const authoredText = Symbol.for('elastic.isomer.authored_text');\n\n/** Holds a {@link fromChildren} brand's `toItem`. */\nexport const authoredToItem = Symbol.for('elastic.isomer.authored_to_item');\nconst authoredTextField = Symbol.for('elastic.isomer.authored_text_field');\nconst authoredCollapse = Symbol.for('elastic.isomer.authored_collapse');\nconst authoredPropsSchema = Symbol.for('elastic.isomer.authored_props_schema');\n\n/**\n * A field filled from child elements of `TName`.\n *\n * Phantom: `z.infer` still reads the underlying schema. The shim reads `TName`\n * and `TProps` off the field type, and the symbols off the schema value.\n */\nexport interface AuthoredChildBrand<TName extends string, TProps> {\n readonly [authoredChild]: TName;\n readonly [authoredProps]: TProps;\n}\n\n/** A child field whose `toItem` builds each item, so the shim fills none of the item's own brands. */\nexport interface AuthoredToItemBrand {\n readonly [authoredToItem]: (\n props: never,\n context: AuthorChildContext\n ) => unknown;\n}\n\n/** A field filled from text children. */\nexport interface AuthoredTextBrand {\n readonly [authoredText]: true;\n}\n\n/** What {@link fromChildren}'s `toItem` receives. */\nexport interface AuthorChildContext {\n /** Nested elements, parsed as body nodes. */\n parseChildren: (children: ReactNode) => PrimitiveNode[];\n}\n\ntype ArrayItem<TSchema extends ZodType> =\n NonNullable<zOutput<TSchema>> extends readonly (infer Item)[]\n ? Item\n : NonNullable<zOutput<TSchema>>;\n\ntype zInput<TSchema> = TSchema extends { _zod: { input: infer Input } }\n ? Input\n : never;\n\ntype zOutput<TSchema> = TSchema extends { _zod: { output: infer Output } }\n ? Output\n : never;\n\ntype WrapperOf<TInner> = {\n _zod: {\n def: {\n type: 'optional' | 'nullable' | 'default' | 'readonly';\n innerType: TInner;\n };\n };\n};\n\ntype Unwrapped<TSchema> =\n TSchema extends WrapperOf<infer Inner> ? Unwrapped<Inner> : TSchema;\n\n/** Whether `F`, or a wrapper layer of it, carries a {@link fromChildren} brand. */\ntype IsChildBranded<F> =\n F extends AuthoredChildBrand<string, unknown>\n ? true\n : F extends WrapperOf<infer Inner>\n ? IsChildBranded<Inner>\n : false;\n\n/** A branded field's item schema: the array element through any wrapper, or the unwrapped schema. */\nexport type ItemSchema<TSchema> =\n Unwrapped<TSchema> extends { element: infer Element }\n ? Element\n : Unwrapped<TSchema>;\n\n/** Item fields a nested {@link fromChildren} brand fills from child elements. */\ntype ChildBrandedKeys<TItemSchema> = TItemSchema extends {\n shape: infer Shape;\n}\n ? string extends keyof Shape\n ? never\n : {\n [K in keyof Shape]: IsChildBranded<Shape[K]> extends true ? K : never;\n }[keyof Shape]\n : never;\n\n/** `TOptional` is optional on the child props because text or child elements fill it. */\ntype ChildProps<TItem, TOptional extends PropertyKey> = [TOptional] extends [\n never,\n]\n ? TItem & { children?: ReactNode }\n : Omit<TItem, TOptional> &\n Partial<Pick<TItem, Extract<TOptional, keyof TItem>>> & {\n children?: ReactNode;\n };\n\nconst BRANDS = [\n authoredChild,\n authoredTextField,\n authoredToItem,\n authoredText,\n authoredCollapse,\n authoredPropsSchema,\n] as const;\n\n// Applies a complete branding. Branding an instance again is allowed only with\n// the same configuration, absent options included, since both fields share it.\nconst brand = (\n caller: 'fromChildren' | 'fromTextChildren',\n schema: object,\n config: Partial<Record<(typeof BRANDS)[number], unknown>>\n): void => {\n const record = schema as Record<symbol, unknown>;\n if (BRANDS.some((key) => Object.hasOwn(schema, key))) {\n if (BRANDS.every((key) => record[key] === config[key])) return;\n throw new IsomerError(\n ISOMER_ERROR_CODES.AUTHORED_SCHEMA_REUSED,\n `${caller}: this schema instance is already branded another way; pass each field its own schema.`\n );\n }\n for (const key of BRANDS) {\n if (config[key] !== undefined) {\n Object.defineProperty(schema, key, {\n value: config[key],\n enumerable: false,\n });\n }\n }\n};\n\n/**\n * Brands `schema` as JSX children of `childType`.\n *\n * `options.text` copies leftover text onto that field. `options.toItem` replaces\n * the default prop copy; its props annotation is the child component's props.\n * The brand is read through `.optional()`, `.nullable()`, `.default()`, and\n * `.readonly()`; any other method clones without it, so call it on `schema`\n * before passing it in.\n */\nexport function fromChildren<\n const TName extends string,\n TSchema extends ZodType,\n>(\n childType: TName,\n schema: TSchema\n): TSchema &\n AuthoredChildBrand<\n TName,\n ChildProps<ArrayItem<TSchema>, ChildBrandedKeys<ItemSchema<TSchema>>>\n >;\nexport function fromChildren<\n const TName extends string,\n TSchema extends ZodType,\n const TText extends string,\n>(\n childType: TName,\n schema: TSchema,\n options: { text: TText; toItem?: never }\n): TSchema &\n AuthoredChildBrand<\n TName,\n ChildProps<\n ArrayItem<TSchema>,\n TText | ChildBrandedKeys<ItemSchema<TSchema>>\n >\n >;\nexport function fromChildren<\n const TName extends string,\n TSchema extends ZodType,\n TPropsSchema extends ZodType,\n>(\n childType: TName,\n schema: TSchema,\n options: {\n text?: string;\n propsSchema: TPropsSchema;\n toItem(\n props: zInput<TPropsSchema> & { children?: ReactNode },\n context: AuthorChildContext\n ): unknown;\n }\n): TSchema &\n AuthoredChildBrand<TName, zInput<TPropsSchema> & { children?: ReactNode }> &\n AuthoredToItemBrand;\nexport function fromChildren<\n const TName extends string,\n TSchema extends ZodType,\n TProps,\n>(\n childType: TName,\n schema: TSchema,\n options: {\n text?: string;\n toItem(props: TProps, context: AuthorChildContext): unknown;\n propsSchema?: never;\n }\n): TSchema & AuthoredChildBrand<TName, TProps> & AuthoredToItemBrand;\nexport function fromChildren(\n childType: string,\n schema: ZodType,\n options?: {\n text?: string;\n toItem?: (this: void, props: never, context: AuthorChildContext) => unknown;\n propsSchema?: ZodType;\n }\n): ZodType {\n brand('fromChildren', schema, {\n [authoredChild]: childType,\n [authoredTextField]: options?.text,\n [authoredToItem]: options?.toItem,\n [authoredPropsSchema]: options?.propsSchema,\n });\n return schema;\n}\n\n/**\n * Brands `schema` as text children.\n *\n * Whitespace collapses unless `collapseWhitespace` is `false`.\n */\nexport const fromTextChildren = <TSchema extends ZodType>(\n schema: TSchema,\n options?: { collapseWhitespace?: boolean }\n): TSchema & AuthoredTextBrand => {\n brand('fromTextChildren', schema, {\n [authoredText]: true,\n [authoredCollapse]:\n options?.collapseWhitespace === false ? false : undefined,\n });\n return schema as TSchema & AuthoredTextBrand;\n};\n\n/** One {@link fromChildren} field as the shim reads it. */\nexport interface AuthoredChildField {\n field: string;\n childType: string;\n /** Field leftover text children fill. */\n textField?: string;\n /** Replaces the default prop copy. */\n toItem?: (props: object, context: AuthorChildContext) => unknown;\n /** The array element schema, or the field schema itself when it is not an array. */\n itemSchema: ZodType;\n /** Input props for a custom `toItem`, excluding JSX children. */\n propsSchema?: ZodType;\n /** Whether the field holds an array of items rather than one item. */\n array: boolean;\n /** Whether the field accepts `undefined`, so children may be omitted. */\n optional: boolean;\n /** Structural input-schema fingerprint shared by fields branding one child type. */\n signature: string;\n}\n\n/** One {@link fromTextChildren} field as the shim reads it. */\nexport interface AuthoredTextField {\n field: string;\n /** `true` unless the brand was given `collapseWhitespace: false`. */\n collapseWhitespace: boolean;\n /** Whether the field accepts `undefined`, so text children may be omitted. */\n optional: boolean;\n}\n\n/** The branded fields found on one object schema. */\nexport interface AuthoredSpec {\n children: AuthoredChildField[];\n text: AuthoredTextField[];\n}\n\nconst zodDefType = (schema: object): string | undefined =>\n (schema as { _zod?: { def?: { type?: string } } })._zod?.def?.type;\n\nconst WRAPPER_TYPES = new Set(['optional', 'nullable', 'default', 'readonly']);\n\ninterface WrapperDef {\n type?: string;\n innerType?: ZodType;\n}\n\nconst innerSchema = (schema: ZodType): ZodType | undefined => {\n const def: WrapperDef | undefined = (\n schema as { _zod?: { def?: WrapperDef } }\n )._zod?.def;\n return def?.type && WRAPPER_TYPES.has(def.type) ? def.innerType : undefined;\n};\n\n// The schema holding `brand`: `schema` or one it wraps.\nconst brandHolder = (schema: ZodType, key: symbol): ZodType | undefined => {\n let current: ZodType | undefined = schema;\n while (current && !Object.hasOwn(current, key)) {\n current = innerSchema(current);\n }\n return current;\n};\n\n// Whether any wrapper layer of `schema` accepts `undefined`.\nconst optionalThrough = (schema: ZodType): boolean => {\n for (\n let current: ZodType | undefined = schema;\n current;\n current = innerSchema(current)\n ) {\n if (isOptionalSchema(current)) return true;\n }\n return false;\n};\n\nconst unwrapAll = (schema: ZodType): ZodType => {\n let current = schema;\n for (let inner = innerSchema(current); inner; inner = innerSchema(current)) {\n current = inner;\n }\n return current;\n};\n\n/** `undefined` is a valid value, so children may be omitted. */\nconst isOptionalSchema = (schema: ZodType): boolean => {\n const type = zodDefType(schema);\n return type === 'optional' || type === 'default';\n};\n\nconst UNORDERED_SCHEMA_ARRAYS = new Set([\n 'allOf',\n 'anyOf',\n 'enum',\n 'oneOf',\n 'required',\n 'type',\n]);\n\nconst schemaSignature = (schema: ZodType): string => {\n const { schema: input } = prepareAuthoringInput(schema);\n const projected = z.toJSONSchema(input, {\n io: 'input',\n target: 'draft-2020-12',\n cycles: 'ref',\n reused: 'inline',\n unrepresentable: 'any',\n metadata: z.registry(),\n });\n const active = new Map<object, number>();\n const canonical = (value: unknown, key = ''): string => {\n if (Array.isArray(value)) {\n const members = value.map((member) => canonical(member));\n if (UNORDERED_SCHEMA_ARRAYS.has(key)) members.sort();\n return `[${members.join(',')}]`;\n }\n if (typeof value !== 'object' || value === null) {\n return JSON.stringify(value) ?? 'undefined';\n }\n const cycle = active.get(value);\n if (cycle !== undefined) return `cycle:${cycle}`;\n const object = value as Record<string, unknown>;\n const ref = object.$ref;\n const target =\n ref === '#'\n ? projected\n : typeof ref === 'string' && ref.startsWith('#/$defs/')\n ? projected.$defs?.[ref.slice('#/$defs/'.length)]\n : undefined;\n if (target && Object.keys(object).length === 1) return canonical(target);\n active.set(value, active.size);\n const result = `{${Object.entries(object)\n .filter(([key]) => value !== projected || key !== '$defs')\n .sort(([first], [second]) => first.localeCompare(second))\n .map(\n ([key, member]) =>\n `${JSON.stringify(key)}:${canonical(key === '$ref' && target ? target : member, key)}`\n )\n .join(',')}}`;\n active.delete(value);\n return result;\n };\n return canonical(projected);\n};\n\nconst arrayElement = (schema: ZodType): ZodType | undefined => {\n const inner = unwrapAll(schema);\n return zodDefType(inner) === 'array' && 'element' in inner\n ? (inner as { element: ZodType }).element\n : undefined;\n};\n\nconst readChild = (\n field: string,\n schema: ZodType\n): AuthoredChildField | undefined => {\n const holder = brandHolder(schema, authoredChild);\n const childType = (holder as { [authoredChild]?: unknown } | undefined)?.[\n authoredChild\n ];\n if (!holder || typeof childType !== 'string') {\n return undefined;\n }\n const textField = (holder as { [authoredTextField]?: unknown })[\n authoredTextField\n ];\n const toItem = (holder as { [authoredToItem]?: unknown })[authoredToItem];\n const propsSchema = (holder as { [authoredPropsSchema]?: ZodType })[\n authoredPropsSchema\n ];\n const element = arrayElement(holder);\n const itemSchema = element ?? unwrapAll(holder);\n const child: AuthoredChildField = {\n field,\n childType,\n itemSchema,\n array: element !== undefined,\n optional: optionalThrough(schema),\n signature: `${schemaSignature(itemSchema)}|${typeof textField === 'string' ? textField : ''}|${propsSchema ? schemaSignature(propsSchema) : ''}`,\n };\n if (propsSchema) child.propsSchema = propsSchema;\n if (typeof textField === 'string') {\n child.textField = textField;\n }\n if (typeof toItem === 'function') {\n child.toItem = toItem as (\n props: object,\n context: AuthorChildContext\n ) => unknown;\n }\n return child;\n};\n\nconst readText = (\n field: string,\n schema: ZodType\n): AuthoredTextField | undefined => {\n const holder = brandHolder(schema, authoredText);\n if (!holder) {\n return undefined;\n }\n return {\n field,\n collapseWhitespace:\n (holder as { [authoredCollapse]?: unknown })[authoredCollapse] !== false,\n optional: optionalThrough(schema),\n };\n};\n\n/**\n * The branded fields on an object schema, top level only: read a child's own\n * brands from its {@link AuthoredChildField.itemSchema}.\n */\nexport const readAuthoredSpec = (schema: ZodType): AuthoredSpec => {\n if (zodDefType(schema) !== 'object' || !('shape' in schema)) {\n return { children: [], text: [] };\n }\n const children: AuthoredChildField[] = [];\n const text: AuthoredTextField[] = [];\n for (const [field, fieldSchema] of Object.entries(\n schema.shape as Record<string, ZodType>\n )) {\n const child = readChild(field, fieldSchema);\n if (child) {\n children.push(child);\n continue;\n }\n const textField = readText(field, fieldSchema);\n if (textField) {\n text.push(textField);\n }\n }\n return { children, text };\n};\n"]}
@@ -0,0 +1,7 @@
1
+ import { z, type ZodType } from 'zod';
2
+ /** Input-schema copy without executable defaults or catch values. */
3
+ export declare const prepareAuthoringInput: (schema: ZodType) => {
4
+ schema: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
5
+ metadata: z.core.$ZodRegistry<z.core.GlobalMeta, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
6
+ };
7
+ //# sourceMappingURL=authoring_input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authoring_input.d.ts","sourceRoot":"","sources":["../../src/author/authoring_input.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAQtC,qEAAqE;AACrE,eAAO,MAAM,qBAAqB,GAAI,QAAQ,OAAO;;;CA6CpD,CAAC"}
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { z } from 'zod';
8
+ const isSchema = (value) => typeof value === 'object' &&
9
+ value !== null &&
10
+ '_zod' in value &&
11
+ typeof value._zod?.def?.type === 'string';
12
+ /** Input-schema copy without executable defaults or catch values. */
13
+ export const prepareAuthoringInput = (schema) => {
14
+ const copies = new Map();
15
+ const metadata = z.registry();
16
+ const copyValue = (value) => {
17
+ if (isSchema(value))
18
+ return copySchema(value);
19
+ if (Array.isArray(value))
20
+ return value.map(copyValue);
21
+ if (typeof value !== 'object' || value === null)
22
+ return value;
23
+ const prototype = Object.getPrototypeOf(value);
24
+ if (prototype !== Object.prototype && prototype !== null)
25
+ return value;
26
+ return Object.fromEntries(Object.entries(value).map(([key, member]) => [key, copyValue(member)]));
27
+ };
28
+ const copySchema = (source) => {
29
+ const cached = copies.get(source);
30
+ if (cached)
31
+ return cached;
32
+ let result;
33
+ copies.set(source, z.lazy(() => result));
34
+ const { def } = source._zod;
35
+ if (def.type === 'default' ||
36
+ def.type === 'prefault' ||
37
+ def.type === 'catch') {
38
+ const { innerType } = def;
39
+ const inner = copySchema(innerType);
40
+ result =
41
+ def.type === 'catch'
42
+ ? z.clone(inner, inner._zod.def)
43
+ : z.optional(inner);
44
+ }
45
+ else if (def.type === 'lazy') {
46
+ const { getter } = def;
47
+ result = z.lazy(() => copySchema(getter()));
48
+ }
49
+ else {
50
+ result = z.clone(source, copyValue(def));
51
+ }
52
+ copies.set(source, result);
53
+ const meta = z.globalRegistry.get(source);
54
+ if (meta)
55
+ metadata.add(result, meta);
56
+ return result;
57
+ };
58
+ return { schema: copySchema(schema), metadata };
59
+ };
60
+ //# sourceMappingURL=authoring_input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authoring_input.js","sourceRoot":"","sources":["../../src/author/authoring_input.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;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,EAAE,IAAI,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;AAClD,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 { z, type ZodType } from 'zod';\n\nconst isSchema = (value: unknown): value is ZodType =>\n typeof value === 'object' &&\n value !== null &&\n '_zod' in value &&\n typeof (value as ZodType)._zod?.def?.type === 'string';\n\n/** Input-schema copy without executable defaults or catch values. */\nexport const prepareAuthoringInput = (schema: ZodType) => {\n const copies = new Map<ZodType, ZodType>();\n const metadata = z.registry<z.GlobalMeta>();\n const copyValue = (value: unknown): unknown => {\n if (isSchema(value)) return copySchema(value);\n if (Array.isArray(value)) return value.map(copyValue);\n if (typeof value !== 'object' || value === null) return value;\n const prototype: unknown = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) return value;\n return Object.fromEntries(\n Object.entries(value).map(([key, member]) => [key, copyValue(member)])\n );\n };\n const copySchema = (source: ZodType): ZodType => {\n const cached = copies.get(source);\n if (cached) return cached;\n let result: ZodType;\n copies.set(\n source,\n z.lazy(() => result)\n );\n const { def } = source._zod;\n if (\n def.type === 'default' ||\n def.type === 'prefault' ||\n def.type === 'catch'\n ) {\n const { innerType } = def as { type: string; innerType: ZodType };\n const inner = copySchema(innerType);\n result =\n def.type === 'catch'\n ? z.clone(inner, inner._zod.def)\n : z.optional(inner);\n } else if (def.type === 'lazy') {\n const { getter } = def as { type: string; getter: () => ZodType };\n result = z.lazy(() => copySchema(getter()));\n } else {\n result = z.clone(source, copyValue(def) as typeof def);\n }\n copies.set(source, result);\n const meta = z.globalRegistry.get(source);\n if (meta) metadata.add(result, meta);\n return result;\n };\n return { schema: copySchema(schema), metadata };\n};\n"]}
@@ -0,0 +1,27 @@
1
+ import { type AuthoredChildField, type AuthoredSpec } from './authored_fields.js';
2
+ export interface ChildSlot {
3
+ array: boolean;
4
+ field: string;
5
+ }
6
+ export interface AuthoringChild {
7
+ field: AuthoredChildField;
8
+ primitiveType: string;
9
+ path: readonly AuthoredChildField[];
10
+ }
11
+ export declare const createAuthoringModel: (primitives: readonly {
12
+ type: string;
13
+ schema?: unknown;
14
+ children?: unknown;
15
+ }[]) => {
16
+ authoredByType: Map<string, AuthoredSpec>;
17
+ children: Map<string, AuthoringChild>;
18
+ childSlotsByType: Map<string, readonly ChildSlot[]>;
19
+ };
20
+ /**
21
+ * Reads {@link PrimitiveDefinition.children} against a probe node so JSX can
22
+ * fill the same fields a tree walk would visit. Paths like `body[0]` are array
23
+ * slots; a bare `header` is a single nested node.
24
+ */
25
+ export declare const inferChildSlots: (children: unknown) => readonly ChildSlot[];
26
+ export declare const capitalize: (value: string) => string;
27
+ //# sourceMappingURL=authoring_model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authoring_model.d.ts","sourceRoot":"","sources":["../../src/author/authoring_model.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,YAAY,EAElB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,SAAS,kBAAkB,EAAE,CAAC;CACrC;AAED,eAAO,MAAM,oBAAoB,GAC/B,YAAY,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE;;;;CAwD9E,CAAC;AAKF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,OAAO,KAAG,SAAS,SAAS,EAuCrE,CAAC;AAQF,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,MACY,CAAC"}