@procedures/splay 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +21 -0
  3. package/README.md +408 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/components/define.d.ts +134 -0
  6. package/dist/components/define.d.ts.map +1 -0
  7. package/dist/components/define.js +486 -0
  8. package/dist/components/define.js.map +1 -0
  9. package/dist/components/index.d.ts +39 -0
  10. package/dist/components/index.d.ts.map +1 -0
  11. package/dist/components/index.js +38 -0
  12. package/dist/components/index.js.map +1 -0
  13. package/dist/components/types.d.ts +264 -0
  14. package/dist/components/types.d.ts.map +1 -0
  15. package/dist/components/types.js +46 -0
  16. package/dist/components/types.js.map +1 -0
  17. package/dist/hydrate.d.ts +126 -0
  18. package/dist/hydrate.d.ts.map +1 -0
  19. package/dist/hydrate.js +226 -0
  20. package/dist/hydrate.js.map +1 -0
  21. package/dist/index.d.ts +40 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +54 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/module.d.ts +16 -0
  26. package/dist/module.d.ts.map +1 -0
  27. package/dist/module.js +58 -0
  28. package/dist/module.js.map +1 -0
  29. package/dist/register.d.ts +8 -0
  30. package/dist/register.d.ts.map +1 -0
  31. package/dist/register.js +15 -0
  32. package/dist/register.js.map +1 -0
  33. package/dist/registry.d.ts +60 -0
  34. package/dist/registry.d.ts.map +1 -0
  35. package/dist/registry.js +191 -0
  36. package/dist/registry.js.map +1 -0
  37. package/dist/streaming.d.ts +94 -0
  38. package/dist/streaming.d.ts.map +1 -0
  39. package/dist/streaming.js +422 -0
  40. package/dist/streaming.js.map +1 -0
  41. package/dist/types.d.ts +85 -0
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/types.js +7 -0
  44. package/dist/types.js.map +1 -0
  45. package/package.json +73 -3
  46. package/src/components/define.ts +600 -0
  47. package/src/components/index.ts +78 -0
  48. package/src/components/types.ts +357 -0
  49. package/src/hydrate.ts +355 -0
  50. package/src/index.ts +111 -0
  51. package/src/module.ts +81 -0
  52. package/src/register.ts +18 -0
  53. package/src/registry.ts +257 -0
  54. package/src/streaming.ts +554 -0
  55. package/src/types.ts +114 -0
@@ -0,0 +1,357 @@
1
+ /**
2
+ * Component Types
3
+ *
4
+ * Components are procedures that return serializable UI descriptors.
5
+ * This enables SSR, caching, and transport over wire.
6
+ *
7
+ * Components integrate with splay's rendering model where a renderer
8
+ * produces output based on data, size, and path context.
9
+ */
10
+
11
+ import type { ZodLike } from "@procedures/client/client";
12
+ import type { ProcedureMetadata, ProcedurePath } from "@procedures/client";
13
+ import type { IEventBus as EventBus } from "@procedures/client";
14
+
15
+ // =============================================================================
16
+ // Component Output (Serializable Descriptor)
17
+ // =============================================================================
18
+
19
+ /**
20
+ * Serializable component output descriptor.
21
+ * Can be transported over wire, cached, and hydrated by any framework.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const descriptor: ComponentOutput = {
26
+ * type: "user-card",
27
+ * props: {
28
+ * name: "John Doe",
29
+ * avatar: "/images/john.png",
30
+ * },
31
+ * children: [
32
+ * { type: "badge", props: { label: "Admin" } },
33
+ * ],
34
+ * };
35
+ * ```
36
+ */
37
+ export interface ComponentOutput {
38
+ /** Component type identifier (maps to registered component) */
39
+ type: string;
40
+
41
+ /** Serializable props for the component */
42
+ props: Record<string, unknown>;
43
+
44
+ /** Nested child descriptors (optional) */
45
+ children?: ComponentOutput[];
46
+
47
+ /** Component key for reconciliation (optional) */
48
+ key?: string;
49
+ }
50
+
51
+ /**
52
+ * Fragment output - multiple components without wrapper.
53
+ */
54
+ export interface FragmentOutput {
55
+ type: "__fragment__";
56
+ children: ComponentOutput[];
57
+ }
58
+
59
+ /**
60
+ * Null output - render nothing.
61
+ */
62
+ export interface NullOutput {
63
+ type: "__null__";
64
+ }
65
+
66
+ /**
67
+ * Any valid component output.
68
+ */
69
+ export type AnyComponentOutput = ComponentOutput | FragmentOutput | NullOutput;
70
+
71
+ // =============================================================================
72
+ // Component Context (splay-compatible)
73
+ // =============================================================================
74
+
75
+ /**
76
+ * Size information for responsive rendering.
77
+ */
78
+ export interface Size {
79
+ width: number;
80
+ height: number;
81
+ }
82
+
83
+ /**
84
+ * Context passed to component factories.
85
+ * Compatible with splay's RenderContext.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * factory: (ctx) => ({
90
+ * type: "user-card",
91
+ * props: {
92
+ * user: ctx.data,
93
+ * compact: ctx.size.width < 400,
94
+ * },
95
+ * children: ctx.data.posts?.map((post, i) =>
96
+ * ctx.render(post, ctx.size, `${ctx.path}.posts[${i}]`)
97
+ * ),
98
+ * })
99
+ * ```
100
+ */
101
+ export interface ComponentContext<TData = unknown> {
102
+ /** Input data for the component */
103
+ data: TData;
104
+
105
+ /** Available rendering size */
106
+ size: Size;
107
+
108
+ /** Path in the render tree (for debugging and keys) */
109
+ path: string;
110
+
111
+ /** Current depth in the render tree */
112
+ depth: number;
113
+
114
+ /**
115
+ * Render a child component.
116
+ * Delegates to the renderer to produce a ComponentOutput.
117
+ *
118
+ * @param data - Data for the child component
119
+ * @param size - Size available for the child
120
+ * @param path - Path for the child (for keys and debugging)
121
+ * @returns ComponentOutput from the child render
122
+ */
123
+ render: (data: unknown, size: Size, path: string) => ComponentOutput | Promise<ComponentOutput>;
124
+
125
+ /**
126
+ * Event bus for streaming coordination.
127
+ * Available when executing in a procedure context.
128
+ */
129
+ bus?: EventBus;
130
+
131
+ /**
132
+ * Additional metadata from the procedure context.
133
+ */
134
+ metadata?: Record<string, unknown>;
135
+ }
136
+
137
+ // =============================================================================
138
+ // Component Definition
139
+ // =============================================================================
140
+
141
+ /**
142
+ * Component factory function (single output).
143
+ * Returns a serializable component descriptor.
144
+ */
145
+ export type ComponentFactory<TData = unknown> = (
146
+ ctx: ComponentContext<TData>
147
+ ) => ComponentOutput | Promise<ComponentOutput>;
148
+
149
+ /**
150
+ * Streaming component factory (multi-yield).
151
+ * Yields descriptors over time for live updates.
152
+ */
153
+ export type StreamingComponentFactory<TData = unknown> = (
154
+ ctx: ComponentContext<TData>
155
+ ) => AsyncGenerator<ComponentOutput, void, unknown>;
156
+
157
+ /**
158
+ * Any component factory (single or streaming).
159
+ */
160
+ export type AnyComponentFactory<TData = unknown> =
161
+ | ComponentFactory<TData>
162
+ | StreamingComponentFactory<TData>;
163
+
164
+ /**
165
+ * Component metadata (extends ProcedureMetadata).
166
+ */
167
+ export interface ComponentMetadata extends ProcedureMetadata {
168
+ /** Component category for organization */
169
+ category?: string;
170
+
171
+ /** Whether the component supports streaming updates */
172
+ streaming?: boolean;
173
+
174
+ /** Default size constraints */
175
+ defaultSize?: Size;
176
+
177
+ /** Minimum size constraints */
178
+ minSize?: Size;
179
+
180
+ /** Maximum size constraints */
181
+ maxSize?: Size;
182
+ }
183
+
184
+ /**
185
+ * Component definition.
186
+ * Wraps a factory function with type information and metadata.
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const userCard: ComponentDefinition<User> = {
191
+ * type: "user-card",
192
+ * namespace: "ui",
193
+ * input: userSchema,
194
+ * metadata: {
195
+ * description: "Displays user information",
196
+ * category: "profile",
197
+ * },
198
+ * factory: (ctx) => ({
199
+ * type: "user-card",
200
+ * props: { user: ctx.data },
201
+ * }),
202
+ * };
203
+ * ```
204
+ */
205
+ export interface ComponentDefinition<TData = unknown> {
206
+ /** Component type identifier */
207
+ type: string;
208
+
209
+ /**
210
+ * Namespace for the component (optional).
211
+ * Results in path: ["components", namespace, type]
212
+ *
213
+ * @example
214
+ * namespace: "ui" → ["components", "ui", "user-card"]
215
+ */
216
+ namespace?: string;
217
+
218
+ /**
219
+ * Input schema for validating component data.
220
+ * Optional - if not provided, accepts any data.
221
+ */
222
+ input?: ZodLike<TData>;
223
+
224
+ /**
225
+ * Component metadata for documentation and tooling.
226
+ */
227
+ metadata?: ComponentMetadata;
228
+
229
+ /**
230
+ * Whether this component streams updates.
231
+ * When true, factory is expected to be a generator.
232
+ */
233
+ streaming?: boolean;
234
+
235
+ /**
236
+ * Component factory function.
237
+ * Can be a regular function (single output) or generator (streaming).
238
+ */
239
+ factory: AnyComponentFactory<TData>;
240
+ }
241
+
242
+ /**
243
+ * Any component definition (type-erased for storage).
244
+ */
245
+ export type AnyComponentDefinition = ComponentDefinition<unknown>;
246
+
247
+ // =============================================================================
248
+ // Component Registry Types
249
+ // =============================================================================
250
+
251
+ /**
252
+ * Registered component with resolved path.
253
+ */
254
+ export interface RegisteredComponent<TData = unknown> {
255
+ /** Full procedure path */
256
+ path: ProcedurePath;
257
+
258
+ /** Original component definition */
259
+ definition: ComponentDefinition<TData>;
260
+ }
261
+
262
+ /**
263
+ * Component bundle - collection of components with shared namespace.
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * const uiComponents: ComponentBundle = {
268
+ * namespace: "ui",
269
+ * components: [
270
+ * buttonComponent,
271
+ * cardComponent,
272
+ * modalComponent,
273
+ * ],
274
+ * };
275
+ * ```
276
+ */
277
+ export interface ComponentBundle {
278
+ /** Shared namespace for all components in bundle */
279
+ namespace: string;
280
+
281
+ /** Component definitions */
282
+ components: AnyComponentDefinition[];
283
+
284
+ /** Bundle metadata */
285
+ metadata?: {
286
+ /** Bundle name */
287
+ name?: string;
288
+ /** Bundle description */
289
+ description?: string;
290
+ /** Bundle version */
291
+ version?: string;
292
+ };
293
+ }
294
+
295
+ // =============================================================================
296
+ // Type Inference Utilities
297
+ // =============================================================================
298
+
299
+ /**
300
+ * Infer input type from a component definition.
301
+ */
302
+ export type InferComponentInput<T> = T extends ComponentDefinition<infer TData>
303
+ ? TData
304
+ : unknown;
305
+
306
+ /**
307
+ * Infer whether a component is streaming.
308
+ */
309
+ export type IsStreamingComponent<T> = T extends ComponentDefinition<unknown>
310
+ ? T["streaming"] extends true
311
+ ? true
312
+ : false
313
+ : false;
314
+
315
+ // =============================================================================
316
+ // Output Helpers
317
+ // =============================================================================
318
+
319
+ /**
320
+ * Create a null output (render nothing).
321
+ */
322
+ export function nullOutput(): NullOutput {
323
+ return { type: "__null__" };
324
+ }
325
+
326
+ /**
327
+ * Create a fragment output (multiple children without wrapper).
328
+ */
329
+ export function fragment(...children: ComponentOutput[]): FragmentOutput {
330
+ return { type: "__fragment__", children };
331
+ }
332
+
333
+ /**
334
+ * Check if output is a fragment.
335
+ */
336
+ export function isFragment(output: AnyComponentOutput): output is FragmentOutput {
337
+ return output.type === "__fragment__";
338
+ }
339
+
340
+ /**
341
+ * Check if output is null.
342
+ */
343
+ export function isNullOutput(output: AnyComponentOutput): output is NullOutput {
344
+ return output.type === "__null__";
345
+ }
346
+
347
+ /**
348
+ * Check if a factory is a streaming generator.
349
+ */
350
+ export function isStreamingFactory<TData>(
351
+ factory: AnyComponentFactory<TData>
352
+ ): factory is StreamingComponentFactory<TData> {
353
+ // The tag of the prototype, not `constructor.name`: an own `constructor` property, or a
354
+ // bundler that renames classes, does not change it. A plain function that returns a
355
+ // generator is not detected here: the handler of a component streams its result anyway.
356
+ return Object.prototype.toString.call(factory) === "[object AsyncGeneratorFunction]";
357
+ }
package/src/hydrate.ts ADDED
@@ -0,0 +1,355 @@
1
+ /**
2
+ * Hydration
3
+ *
4
+ * Converts serializable ComponentOutput descriptors into framework-specific
5
+ * components (React, Vue, Svelte, etc.).
6
+ *
7
+ * This enables the following flow:
8
+ * 1. Server renders ComponentOutput (serializable)
9
+ * 2. Output is sent over wire (JSON)
10
+ * 3. Client hydrates to React/Vue/Svelte components
11
+ */
12
+
13
+ import type { ComponentOutput } from "./components/index.js";
14
+ import type { ComponentMap, HydrateOptions } from "./types.js";
15
+
16
+ // Portable console access (works in Node and browser)
17
+ type ConsoleType = {
18
+ warn(message: string): void;
19
+ log(message: string): void;
20
+ error(message: string): void;
21
+ };
22
+ const log = (globalThis as unknown as { console: ConsoleType }).console;
23
+
24
+ // =============================================================================
25
+ // Hydration Core
26
+ // =============================================================================
27
+
28
+ /**
29
+ * Create a hydrate function for a specific framework.
30
+ *
31
+ * @param options - Hydration options including component map
32
+ * @returns Hydrate function that converts descriptors to framework components
33
+ *
34
+ * @example React:
35
+ * ```typescript
36
+ * import { createElement } from "react";
37
+ * import { createHydrate } from "@procedures/splay";
38
+ *
39
+ * const hydrate = createHydrate({
40
+ * components: {
41
+ * "user-card": UserCard,
42
+ * "badge": Badge,
43
+ * },
44
+ * fallback: UnknownComponent,
45
+ * });
46
+ *
47
+ * // Use with React
48
+ * function App({ descriptor }) {
49
+ * return hydrate(descriptor, createElement);
50
+ * }
51
+ * ```
52
+ */
53
+ export function createHydrate<TComponent>(
54
+ options: HydrateOptions<TComponent>
55
+ ): (
56
+ descriptor: ComponentOutput | null,
57
+ createElement: CreateElement<TComponent>
58
+ ) => TComponent | null {
59
+ const { components, fallback, onNull, onFragment } = options;
60
+
61
+ return function hydrate(
62
+ descriptor: ComponentOutput | null,
63
+ createElement: CreateElement<TComponent>
64
+ ): TComponent | null {
65
+ // Handle null
66
+ if (descriptor === null) {
67
+ return onNull?.() ?? null;
68
+ }
69
+
70
+ // Handle null output type
71
+ if (descriptor.type === "__null__") {
72
+ return onNull?.() ?? null;
73
+ }
74
+
75
+ // Handle fragment
76
+ if (descriptor.type === "__fragment__") {
77
+ const children = (descriptor.children ?? []).map((child) =>
78
+ hydrate(child, createElement)
79
+ );
80
+
81
+ if (onFragment) {
82
+ return onFragment(children.filter((c): c is TComponent => c !== null));
83
+ }
84
+
85
+ // Default: return first child or null
86
+ return children[0] ?? null;
87
+ }
88
+
89
+ // Look up component
90
+ const Component = components[descriptor.type] ?? fallback;
91
+
92
+ if (!Component) {
93
+ log.warn(`Unknown component type: ${descriptor.type}`);
94
+ return null;
95
+ }
96
+
97
+ // Hydrate children recursively
98
+ const hydratedChildren = descriptor.children?.map((child) =>
99
+ hydrate(child, createElement)
100
+ );
101
+
102
+ // Create the component
103
+ return createElement(
104
+ Component,
105
+ { ...descriptor.props, key: descriptor.key },
106
+ hydratedChildren
107
+ );
108
+ };
109
+ }
110
+
111
+ /**
112
+ * createElement function signature (React-compatible).
113
+ */
114
+ export type CreateElement<TComponent> = (
115
+ type: TComponent,
116
+ props: Record<string, unknown> | null,
117
+ children?: (TComponent | null)[]
118
+ ) => TComponent;
119
+
120
+ // =============================================================================
121
+ // React-Specific Hydration
122
+ // =============================================================================
123
+
124
+ /**
125
+ * Generic React-like component type (works with any framework that has createElement).
126
+ */
127
+ type ReactLikeComponent = (props: Record<string, unknown>) => unknown;
128
+
129
+ /**
130
+ * React-specific hydration options.
131
+ */
132
+ export interface ReactHydrateOptions {
133
+ /** Map of component types to React components */
134
+ components: ComponentMap<ReactLikeComponent>;
135
+ /** Fallback component for unknown types */
136
+ fallback?: ReactLikeComponent;
137
+ }
138
+
139
+ /**
140
+ * React-like module interface.
141
+ */
142
+ interface ReactLike {
143
+ createElement(
144
+ type: ReactLikeComponent | symbol,
145
+ props: Record<string, unknown> | null,
146
+ ...children: unknown[]
147
+ ): unknown;
148
+ Fragment: symbol;
149
+ }
150
+
151
+ /**
152
+ * Create a React-specific hydrate function.
153
+ *
154
+ * @param react - React module (import * as React from "react")
155
+ * @param options - Hydration options
156
+ * @returns Hydrate function for React
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * import * as React from "react";
161
+ * import { createReactHydrate } from "@procedures/splay";
162
+ *
163
+ * const hydrate = createReactHydrate(React, {
164
+ * components: {
165
+ * "user-card": UserCard,
166
+ * "badge": Badge,
167
+ * },
168
+ * });
169
+ *
170
+ * function App({ descriptor }) {
171
+ * return hydrate(descriptor);
172
+ * }
173
+ * ```
174
+ */
175
+ export function createReactHydrate(
176
+ react: ReactLike,
177
+ options: ReactHydrateOptions
178
+ ): (descriptor: ComponentOutput | null) => unknown {
179
+ const { components, fallback } = options;
180
+
181
+ function hydrate(descriptor: ComponentOutput | null): unknown {
182
+ if (descriptor === null) {
183
+ return null;
184
+ }
185
+
186
+ if (descriptor.type === "__null__") {
187
+ return null;
188
+ }
189
+
190
+ if (descriptor.type === "__fragment__") {
191
+ const children = (descriptor.children ?? []).map((child: ComponentOutput) => hydrate(child));
192
+ return react.createElement(react.Fragment, null, ...children);
193
+ }
194
+
195
+ const Component = components[descriptor.type];
196
+
197
+ if (!Component) {
198
+ if (fallback) {
199
+ return react.createElement(fallback, {
200
+ type: descriptor.type,
201
+ props: descriptor.props,
202
+ });
203
+ }
204
+ log.warn(`Unknown component type: ${descriptor.type}`);
205
+ return null;
206
+ }
207
+
208
+ const hydratedChildren = descriptor.children?.map((child: ComponentOutput) => hydrate(child));
209
+
210
+ return react.createElement(
211
+ Component,
212
+ { ...descriptor.props, key: descriptor.key },
213
+ ...(hydratedChildren ?? [])
214
+ );
215
+ }
216
+
217
+ return hydrate;
218
+ }
219
+
220
+ // =============================================================================
221
+ // Descriptor Utilities
222
+ // =============================================================================
223
+
224
+ /**
225
+ * Walk a descriptor tree and apply a visitor to each node.
226
+ */
227
+ export function walkDescriptor(
228
+ descriptor: ComponentOutput,
229
+ visitor: (node: ComponentOutput, path: string[]) => void,
230
+ path: string[] = []
231
+ ): void {
232
+ visitor(descriptor, path);
233
+
234
+ if (descriptor.children) {
235
+ descriptor.children.forEach((child: ComponentOutput, index: number) => {
236
+ walkDescriptor(child, visitor, [...path, `children[${index}]`]);
237
+ });
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Transform a descriptor tree.
243
+ */
244
+ export function transformDescriptor(
245
+ descriptor: ComponentOutput,
246
+ transform: (node: ComponentOutput) => ComponentOutput
247
+ ): ComponentOutput {
248
+ const transformed = transform(descriptor);
249
+
250
+ if (transformed.children) {
251
+ return {
252
+ ...transformed,
253
+ children: transformed.children.map((child: ComponentOutput) =>
254
+ transformDescriptor(child, transform)
255
+ ),
256
+ };
257
+ }
258
+
259
+ return transformed;
260
+ }
261
+
262
+ /**
263
+ * Find all nodes in a descriptor tree matching a predicate.
264
+ */
265
+ export function findInDescriptor(
266
+ descriptor: ComponentOutput,
267
+ predicate: (node: ComponentOutput) => boolean
268
+ ): ComponentOutput[] {
269
+ const results: ComponentOutput[] = [];
270
+
271
+ walkDescriptor(descriptor, (node) => {
272
+ if (predicate(node)) {
273
+ results.push(node);
274
+ }
275
+ });
276
+
277
+ return results;
278
+ }
279
+
280
+ /**
281
+ * Get all component types used in a descriptor tree.
282
+ */
283
+ export function getUsedTypes(descriptor: ComponentOutput): Set<string> {
284
+ const types = new Set<string>();
285
+
286
+ walkDescriptor(descriptor, (node) => {
287
+ if (node.type !== "__null__" && node.type !== "__fragment__") {
288
+ types.add(node.type);
289
+ }
290
+ });
291
+
292
+ return types;
293
+ }
294
+
295
+ /**
296
+ * Validate that all component types in a descriptor are known.
297
+ */
298
+ export function validateDescriptor(
299
+ descriptor: ComponentOutput,
300
+ knownTypes: Set<string> | string[]
301
+ ): { valid: boolean; unknownTypes: string[] } {
302
+ const known = knownTypes instanceof Set ? knownTypes : new Set(knownTypes);
303
+ const used = getUsedTypes(descriptor);
304
+ const unknownTypes: string[] = [];
305
+
306
+ for (const type of used) {
307
+ if (!known.has(type)) {
308
+ unknownTypes.push(type);
309
+ }
310
+ }
311
+
312
+ return {
313
+ valid: unknownTypes.length === 0,
314
+ unknownTypes,
315
+ };
316
+ }
317
+
318
+ // =============================================================================
319
+ // Serialization Helpers
320
+ // =============================================================================
321
+
322
+ /**
323
+ * Serialize a descriptor to JSON string.
324
+ */
325
+ export function serializeDescriptor(descriptor: ComponentOutput): string {
326
+ return JSON.stringify(descriptor);
327
+ }
328
+
329
+ /**
330
+ * Parse a descriptor from JSON string.
331
+ */
332
+ export function parseDescriptor(json: string): ComponentOutput {
333
+ return JSON.parse(json) as ComponentOutput;
334
+ }
335
+
336
+ /**
337
+ * Create a compact representation of a descriptor.
338
+ * Removes undefined values and empty arrays.
339
+ */
340
+ export function compactDescriptor(descriptor: ComponentOutput): ComponentOutput {
341
+ const result: ComponentOutput = {
342
+ type: descriptor.type,
343
+ props: descriptor.props,
344
+ };
345
+
346
+ if (descriptor.children && descriptor.children.length > 0) {
347
+ result.children = descriptor.children.map(compactDescriptor);
348
+ }
349
+
350
+ if (descriptor.key !== undefined) {
351
+ result.key = descriptor.key;
352
+ }
353
+
354
+ return result;
355
+ }