@elastic/isomer-sdk 0.1.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.
- package/NOTICE.txt +0 -286
- package/README.md +13 -2
- package/THIRD_PARTY_LICENSES.md +1 -885
- package/dist/author/authored_fields.d.ts +93 -18
- package/dist/author/authored_fields.d.ts.map +1 -1
- package/dist/author/authored_fields.js +63 -43
- package/dist/author/authored_fields.js.map +1 -1
- package/dist/author/authoring_input.d.ts +7 -0
- package/dist/author/authoring_input.d.ts.map +1 -0
- package/dist/author/authoring_input.js +66 -0
- package/dist/author/authoring_input.js.map +1 -0
- package/dist/author/authoring_model.d.ts +33 -0
- package/dist/author/authoring_model.d.ts.map +1 -0
- package/dist/author/authoring_model.js +142 -0
- package/dist/author/authoring_model.js.map +1 -0
- package/dist/author/declarations.d.ts +13 -0
- package/dist/author/declarations.d.ts.map +1 -0
- package/dist/author/declarations.js +288 -0
- package/dist/author/declarations.js.map +1 -0
- package/dist/author/index.d.ts +4 -1
- package/dist/author/index.d.ts.map +1 -1
- package/dist/author/index.js +4 -1
- package/dist/author/index.js.map +1 -1
- package/dist/author/jsx_shim.d.ts +50 -30
- package/dist/author/jsx_shim.d.ts.map +1 -1
- package/dist/author/jsx_shim.js +146 -138
- package/dist/author/jsx_shim.js.map +1 -1
- package/dist/author/print_jsx.d.ts +19 -0
- package/dist/author/print_jsx.d.ts.map +1 -0
- package/dist/author/print_jsx.js +372 -0
- package/dist/author/print_jsx.js.map +1 -0
- package/dist/author/prompt.d.ts +2 -2
- package/dist/author/prompt.d.ts.map +1 -1
- package/dist/author/prompt.js +7 -2
- package/dist/author/prompt.js.map +1 -1
- package/dist/author/schema_to_typescript.d.ts +37 -0
- package/dist/author/schema_to_typescript.d.ts.map +1 -0
- package/dist/author/schema_to_typescript.js +289 -0
- package/dist/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/author/authored_fields.js +68 -47
- package/dist/cjs/author/authored_fields.js.map +1 -1
- package/dist/cjs/author/authoring_input.js +70 -0
- package/dist/cjs/author/authoring_input.js.map +1 -0
- package/dist/cjs/author/authoring_model.js +149 -0
- package/dist/cjs/author/authoring_model.js.map +1 -0
- package/dist/cjs/author/declarations.js +292 -0
- package/dist/cjs/author/declarations.js.map +1 -0
- package/dist/cjs/author/index.js +10 -1
- package/dist/cjs/author/index.js.map +1 -1
- package/dist/cjs/author/jsx_shim.js +148 -140
- package/dist/cjs/author/jsx_shim.js.map +1 -1
- package/dist/cjs/author/print_jsx.js +378 -0
- package/dist/cjs/author/print_jsx.js.map +1 -0
- package/dist/cjs/author/prompt.js +7 -2
- package/dist/cjs/author/prompt.js.map +1 -1
- package/dist/cjs/author/schema_to_typescript.js +298 -0
- package/dist/cjs/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/composition/body_node_base.js +11 -4
- package/dist/cjs/composition/body_node_base.js.map +1 -1
- package/dist/cjs/composition/error.js +2 -0
- package/dist/cjs/composition/error.js.map +1 -1
- package/dist/cjs/composition/index.js +2 -1
- package/dist/cjs/composition/index.js.map +1 -1
- package/dist/cjs/composition/structured_value.js.map +1 -1
- package/dist/cjs/define/frame.js +2 -3
- package/dist/cjs/define/frame.js.map +1 -1
- package/dist/cjs/define/index.js +7 -1
- package/dist/cjs/define/index.js.map +1 -1
- package/dist/cjs/define/primitive_example.js +26 -0
- package/dist/cjs/define/primitive_example.js.map +1 -0
- package/dist/cjs/define/primitive_icon.js +17 -0
- package/dist/cjs/define/primitive_icon.js.map +1 -0
- package/dist/cjs/define/primitive_module.js +24 -7
- package/dist/cjs/define/primitive_module.js.map +1 -1
- package/dist/cjs/define/slack_assets.js.map +1 -1
- package/dist/cjs/entries/index.js +8 -2
- package/dist/cjs/entries/index.js.map +1 -1
- package/dist/cjs/entries/markdown.js +2 -1
- package/dist/cjs/entries/markdown.js.map +1 -1
- package/dist/cjs/entries/slack.js +1 -2
- package/dist/cjs/entries/slack.js.map +1 -1
- package/dist/cjs/pack/capabilities.js +17 -11
- package/dist/cjs/pack/capabilities.js.map +1 -1
- package/dist/cjs/pack/compose.js +4 -1
- package/dist/cjs/pack/compose.js.map +1 -1
- package/dist/cjs/pack/index.js +2 -1
- package/dist/cjs/pack/index.js.map +1 -1
- package/dist/cjs/pack/primitive_pack.js +27 -5
- package/dist/cjs/pack/primitive_pack.js.map +1 -1
- package/dist/cjs/render/anchors.js +1 -1
- package/dist/cjs/render/anchors.js.map +1 -1
- package/dist/cjs/render/format_number.js +2 -1
- package/dist/cjs/render/format_number.js.map +1 -1
- package/dist/cjs/render/html/envelope.js +12 -6
- package/dist/cjs/render/html/envelope.js.map +1 -1
- package/dist/cjs/render/layout_check.js.map +1 -1
- package/dist/cjs/render/markdown/builder.js +18 -8
- package/dist/cjs/render/markdown/builder.js.map +1 -1
- package/dist/cjs/render/markdown/format.js +70 -30
- package/dist/cjs/render/markdown/format.js.map +1 -1
- package/dist/cjs/render/markdown/host_tags.js +67 -0
- package/dist/cjs/render/markdown/host_tags.js.map +1 -0
- package/dist/cjs/render/markdown/index.js +3 -1
- package/dist/cjs/render/markdown/index.js.map +1 -1
- package/dist/cjs/render/markdown/split.js +325 -0
- package/dist/cjs/render/markdown/split.js.map +1 -0
- package/dist/cjs/render/primitive_dispatch.js +11 -25
- package/dist/cjs/render/primitive_dispatch.js.map +1 -1
- package/dist/cjs/render/react/content.js +3 -1
- package/dist/cjs/render/react/content.js.map +1 -1
- package/dist/cjs/render/slack/format.js +1 -601
- package/dist/cjs/render/slack/format.js.map +1 -1
- package/dist/cjs/render/slack/index.js +1 -2
- package/dist/cjs/render/slack/index.js.map +1 -1
- package/dist/cjs/render/slack/markdown_content.js +172 -115
- package/dist/cjs/render/slack/markdown_content.js.map +1 -1
- package/dist/cjs/testing/conformance.js +40 -24
- package/dist/cjs/testing/conformance.js.map +1 -1
- package/dist/cjs/testing/icon.js +248 -0
- package/dist/cjs/testing/icon.js.map +1 -0
- package/dist/cjs/testing/index.js +3 -1
- package/dist/cjs/testing/index.js.map +1 -1
- package/dist/cjs/testing/registration.js +5 -3
- package/dist/cjs/testing/registration.js.map +1 -1
- package/dist/cjs/validate/authoring_schema.js +17 -1
- package/dist/cjs/validate/authoring_schema.js.map +1 -1
- package/dist/cjs/validate/index.js +2 -1
- package/dist/cjs/validate/index.js.map +1 -1
- package/dist/cjs/validate/json_schema.js +10 -3
- package/dist/cjs/validate/json_schema.js.map +1 -1
- package/dist/cjs/validate/url.js +2 -1
- package/dist/cjs/validate/url.js.map +1 -1
- package/dist/cjs/validate/validation.js +2 -45
- package/dist/cjs/validate/validation.js.map +1 -1
- package/dist/composition/body_node_base.d.ts +7 -6
- package/dist/composition/body_node_base.d.ts.map +1 -1
- package/dist/composition/body_node_base.js +10 -3
- package/dist/composition/body_node_base.js.map +1 -1
- package/dist/composition/error.d.ts +2 -0
- package/dist/composition/error.d.ts.map +1 -1
- package/dist/composition/error.js +2 -0
- package/dist/composition/error.js.map +1 -1
- package/dist/composition/index.d.ts +1 -1
- package/dist/composition/index.d.ts.map +1 -1
- package/dist/composition/index.js +1 -1
- package/dist/composition/index.js.map +1 -1
- package/dist/composition/structured_value.d.ts +3 -3
- package/dist/composition/structured_value.d.ts.map +1 -1
- package/dist/composition/structured_value.js.map +1 -1
- package/dist/define/frame.d.ts +9 -20
- package/dist/define/frame.d.ts.map +1 -1
- package/dist/define/frame.js +2 -3
- package/dist/define/frame.js.map +1 -1
- package/dist/define/index.d.ts +3 -1
- package/dist/define/index.d.ts.map +1 -1
- package/dist/define/index.js +3 -1
- package/dist/define/index.js.map +1 -1
- package/dist/define/primitive_example.d.ts +30 -0
- package/dist/define/primitive_example.d.ts.map +1 -0
- package/dist/define/primitive_example.js +21 -0
- package/dist/define/primitive_example.js.map +1 -0
- package/dist/define/primitive_icon.d.ts +11 -0
- package/dist/define/primitive_icon.d.ts.map +1 -0
- package/dist/define/primitive_icon.js +14 -0
- package/dist/define/primitive_icon.js.map +1 -0
- package/dist/define/primitive_module.d.ts +45 -24
- package/dist/define/primitive_module.d.ts.map +1 -1
- package/dist/define/primitive_module.js +24 -7
- package/dist/define/primitive_module.js.map +1 -1
- package/dist/define/slack_assets.d.ts +1 -1
- package/dist/define/slack_assets.d.ts.map +1 -1
- package/dist/define/slack_assets.js.map +1 -1
- package/dist/entries/index.d.ts +3 -3
- package/dist/entries/index.d.ts.map +1 -1
- package/dist/entries/index.js +3 -3
- package/dist/entries/index.js.map +1 -1
- package/dist/entries/markdown.d.ts +1 -1
- package/dist/entries/markdown.d.ts.map +1 -1
- package/dist/entries/markdown.js +1 -1
- package/dist/entries/markdown.js.map +1 -1
- package/dist/entries/slack.d.ts +1 -1
- package/dist/entries/slack.d.ts.map +1 -1
- package/dist/entries/slack.js +1 -1
- package/dist/entries/slack.js.map +1 -1
- package/dist/pack/capabilities.d.ts +24 -10
- package/dist/pack/capabilities.d.ts.map +1 -1
- package/dist/pack/capabilities.js +17 -11
- package/dist/pack/capabilities.js.map +1 -1
- package/dist/pack/compose.d.ts +4 -1
- package/dist/pack/compose.d.ts.map +1 -1
- package/dist/pack/compose.js +4 -1
- package/dist/pack/compose.js.map +1 -1
- package/dist/pack/index.d.ts +2 -2
- package/dist/pack/index.d.ts.map +1 -1
- package/dist/pack/index.js +2 -2
- package/dist/pack/index.js.map +1 -1
- package/dist/pack/primitive_pack.d.ts +14 -3
- package/dist/pack/primitive_pack.d.ts.map +1 -1
- package/dist/pack/primitive_pack.js +25 -4
- package/dist/pack/primitive_pack.js.map +1 -1
- package/dist/render/anchors.d.ts +2 -2
- package/dist/render/anchors.d.ts.map +1 -1
- package/dist/render/anchors.js +1 -1
- package/dist/render/anchors.js.map +1 -1
- package/dist/render/format_number.d.ts.map +1 -1
- package/dist/render/format_number.js +2 -1
- package/dist/render/format_number.js.map +1 -1
- package/dist/render/html/envelope.d.ts +3 -3
- package/dist/render/html/envelope.js +12 -6
- package/dist/render/html/envelope.js.map +1 -1
- package/dist/render/layout_check.d.ts +1 -1
- package/dist/render/layout_check.d.ts.map +1 -1
- package/dist/render/layout_check.js.map +1 -1
- package/dist/render/markdown/builder.d.ts +5 -4
- package/dist/render/markdown/builder.d.ts.map +1 -1
- package/dist/render/markdown/builder.js +16 -7
- package/dist/render/markdown/builder.js.map +1 -1
- package/dist/render/markdown/format.d.ts +9 -0
- package/dist/render/markdown/format.d.ts.map +1 -1
- package/dist/render/markdown/format.js +67 -31
- package/dist/render/markdown/format.js.map +1 -1
- package/dist/render/markdown/host_tags.d.ts +14 -0
- package/dist/render/markdown/host_tags.d.ts.map +1 -0
- package/dist/render/markdown/host_tags.js +63 -0
- package/dist/render/markdown/host_tags.js.map +1 -0
- package/dist/render/markdown/index.d.ts +1 -0
- package/dist/render/markdown/index.d.ts.map +1 -1
- package/dist/render/markdown/index.js +1 -0
- package/dist/render/markdown/index.js.map +1 -1
- package/dist/render/markdown/split.d.ts +32 -0
- package/dist/render/markdown/split.d.ts.map +1 -0
- package/dist/render/markdown/split.js +321 -0
- package/dist/render/markdown/split.js.map +1 -0
- package/dist/render/primitive_dispatch.d.ts +6 -6
- package/dist/render/primitive_dispatch.d.ts.map +1 -1
- package/dist/render/primitive_dispatch.js +12 -26
- package/dist/render/primitive_dispatch.js.map +1 -1
- package/dist/render/react/content.d.ts +1 -1
- package/dist/render/react/content.d.ts.map +1 -1
- package/dist/render/react/content.js +3 -1
- package/dist/render/react/content.js.map +1 -1
- package/dist/render/slack/format.d.ts +0 -25
- package/dist/render/slack/format.d.ts.map +1 -1
- package/dist/render/slack/format.js +1 -599
- package/dist/render/slack/format.js.map +1 -1
- package/dist/render/slack/index.d.ts +1 -1
- package/dist/render/slack/index.d.ts.map +1 -1
- package/dist/render/slack/index.js +1 -1
- package/dist/render/slack/index.js.map +1 -1
- package/dist/render/slack/markdown_content.d.ts +10 -4
- package/dist/render/slack/markdown_content.d.ts.map +1 -1
- package/dist/render/slack/markdown_content.js +169 -113
- package/dist/render/slack/markdown_content.js.map +1 -1
- package/dist/testing/conformance.d.ts +19 -14
- package/dist/testing/conformance.d.ts.map +1 -1
- package/dist/testing/conformance.js +40 -24
- package/dist/testing/conformance.js.map +1 -1
- package/dist/testing/icon.d.ts +11 -0
- package/dist/testing/icon.d.ts.map +1 -0
- package/dist/testing/icon.js +244 -0
- package/dist/testing/icon.js.map +1 -0
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/registration.d.ts +1 -1
- package/dist/testing/registration.d.ts.map +1 -1
- package/dist/testing/registration.js +6 -4
- package/dist/testing/registration.js.map +1 -1
- package/dist/validate/authoring_schema.d.ts +6 -0
- package/dist/validate/authoring_schema.d.ts.map +1 -1
- package/dist/validate/authoring_schema.js +15 -0
- package/dist/validate/authoring_schema.js.map +1 -1
- package/dist/validate/index.d.ts +1 -1
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +1 -1
- package/dist/validate/index.js.map +1 -1
- package/dist/validate/json_schema.d.ts.map +1 -1
- package/dist/validate/json_schema.js +10 -3
- package/dist/validate/json_schema.js.map +1 -1
- package/dist/validate/url.d.ts.map +1 -1
- package/dist/validate/url.js +2 -1
- package/dist/validate/url.js.map +1 -1
- package/dist/validate/validation.d.ts +1 -11
- package/dist/validate/validation.d.ts.map +1 -1
- package/dist/validate/validation.js +3 -46
- package/dist/validate/validation.js.map +1 -1
- package/package.json +3 -2
|
@@ -2,7 +2,7 @@ import type { ReactNode } from 'react';
|
|
|
2
2
|
import type { ZodType } from 'zod';
|
|
3
3
|
import type { PrimitiveNode } from '../define/primitive_module.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Member name of the child component a schema field is filled from.
|
|
6
6
|
*
|
|
7
7
|
* `Symbol.for`: ESM and CJS builds must agree, same as `authorType`.
|
|
8
8
|
*/
|
|
@@ -11,6 +11,10 @@ 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
|
+
/** Set when a field is filled from primitive elements no other field claims. */
|
|
15
|
+
export declare const authoredNodes: unique symbol;
|
|
16
|
+
/** Holds a {@link fromChildren} brand's `toItem`. */
|
|
17
|
+
export declare const authoredToItem: unique symbol;
|
|
14
18
|
/**
|
|
15
19
|
* A field filled from child elements of `TName`.
|
|
16
20
|
*
|
|
@@ -21,31 +25,67 @@ export interface AuthoredChildBrand<TName extends string, TProps> {
|
|
|
21
25
|
readonly [authoredChild]: TName;
|
|
22
26
|
readonly [authoredProps]: TProps;
|
|
23
27
|
}
|
|
28
|
+
/** A child field whose `toItem` builds each item, so the shim fills none of the item's own brands. */
|
|
29
|
+
export interface AuthoredToItemBrand {
|
|
30
|
+
readonly [authoredToItem]: (props: never, context: AuthorChildContext) => unknown;
|
|
31
|
+
}
|
|
24
32
|
/** A field filled from text children. */
|
|
25
33
|
export interface AuthoredTextBrand {
|
|
26
34
|
readonly [authoredText]: true;
|
|
27
35
|
}
|
|
36
|
+
/** A field filled from primitive elements, like a child slot the tree walk does not visit. */
|
|
37
|
+
export interface AuthoredNodesBrand {
|
|
38
|
+
readonly [authoredNodes]: true;
|
|
39
|
+
}
|
|
28
40
|
/** What {@link fromChildren}'s `toItem` receives. */
|
|
29
41
|
export interface AuthorChildContext {
|
|
30
42
|
/** Nested elements, parsed as body nodes. */
|
|
31
43
|
parseChildren: (children: ReactNode) => PrimitiveNode[];
|
|
32
44
|
}
|
|
33
45
|
type ArrayItem<TSchema extends ZodType> = NonNullable<zOutput<TSchema>> extends readonly (infer Item)[] ? Item : NonNullable<zOutput<TSchema>>;
|
|
46
|
+
type zInput<TSchema> = TSchema extends {
|
|
47
|
+
_zod: {
|
|
48
|
+
input: infer Input;
|
|
49
|
+
};
|
|
50
|
+
} ? Input : never;
|
|
34
51
|
type zOutput<TSchema> = TSchema extends {
|
|
35
52
|
_zod: {
|
|
36
53
|
output: infer Output;
|
|
37
54
|
};
|
|
38
55
|
} ? Output : never;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
56
|
+
type WrapperOf<TInner> = {
|
|
57
|
+
_zod: {
|
|
58
|
+
def: {
|
|
59
|
+
type: 'optional' | 'nullable' | 'default' | 'readonly';
|
|
60
|
+
innerType: TInner;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
type Unwrapped<TSchema> = TSchema extends WrapperOf<infer Inner> ? Unwrapped<Inner> : TSchema;
|
|
65
|
+
/** Whether `F`, or a wrapper layer of it, carries a {@link fromChildren} brand. */
|
|
66
|
+
type IsChildBranded<F> = F extends AuthoredChildBrand<string, unknown> ? true : F extends WrapperOf<infer Inner> ? IsChildBranded<Inner> : false;
|
|
67
|
+
/** A branded field's item schema: the array element through any wrapper, or the unwrapped schema. */
|
|
68
|
+
export type ItemSchema<TSchema> = Unwrapped<TSchema> extends {
|
|
69
|
+
element: infer Element;
|
|
70
|
+
} ? Element : Unwrapped<TSchema>;
|
|
71
|
+
/** Item fields a nested {@link fromChildren} brand fills from child elements. */
|
|
72
|
+
type ChildBrandedKeys<TItemSchema> = TItemSchema extends {
|
|
73
|
+
shape: infer Shape;
|
|
74
|
+
} ? string extends keyof Shape ? never : {
|
|
75
|
+
[K in keyof Shape]: IsChildBranded<Shape[K]> extends true ? K : never;
|
|
76
|
+
}[keyof Shape] : never;
|
|
77
|
+
/** `TOptional` is optional on the child props because text or child elements fill it. */
|
|
78
|
+
type ChildProps<TItem, TOptional extends PropertyKey> = [TOptional] extends [
|
|
79
|
+
never
|
|
80
|
+
] ? TItem & {
|
|
43
81
|
children?: ReactNode;
|
|
44
|
-
} : TItem & {
|
|
82
|
+
} : Omit<TItem, TOptional> & Partial<Pick<TItem, Extract<TOptional, keyof TItem>>> & {
|
|
45
83
|
children?: ReactNode;
|
|
46
84
|
};
|
|
47
85
|
/**
|
|
48
|
-
* Brands `schema` as JSX children of `
|
|
86
|
+
* Brands `schema` as JSX children of the member `name`, capitalized on the
|
|
87
|
+
* primitive's component: `fromChildren('item', …)` on `slideList` is
|
|
88
|
+
* `<SlideList.Item>`. Names are unique across a primitive's child tree.
|
|
49
89
|
*
|
|
50
90
|
* `options.text` copies leftover text onto that field. `options.toItem` replaces
|
|
51
91
|
* the default prop copy; its props annotation is the child component's props.
|
|
@@ -53,51 +93,86 @@ type ChildProps<TItem, TText extends string | undefined> = [TText] extends [
|
|
|
53
93
|
* `.readonly()`; any other method clones without it, so call it on `schema`
|
|
54
94
|
* before passing it in.
|
|
55
95
|
*/
|
|
56
|
-
export declare function fromChildren<const TName extends string, TSchema extends ZodType>(
|
|
57
|
-
export declare function fromChildren<const TName extends string, TSchema extends ZodType, const TText extends string>(
|
|
96
|
+
export declare function fromChildren<const TName extends string, TSchema extends ZodType>(name: TName, schema: TSchema): TSchema & AuthoredChildBrand<TName, ChildProps<ArrayItem<TSchema>, ChildBrandedKeys<ItemSchema<TSchema>>>>;
|
|
97
|
+
export declare function fromChildren<const TName extends string, TSchema extends ZodType, const TText extends string>(name: TName, schema: TSchema, options: {
|
|
58
98
|
text: TText;
|
|
59
|
-
|
|
60
|
-
|
|
99
|
+
toItem?: never;
|
|
100
|
+
}): TSchema & AuthoredChildBrand<TName, ChildProps<ArrayItem<TSchema>, TText | ChildBrandedKeys<ItemSchema<TSchema>>>>;
|
|
101
|
+
export declare function fromChildren<const TName extends string, TSchema extends ZodType, TPropsSchema extends ZodType>(name: TName, schema: TSchema, options: {
|
|
102
|
+
text?: string;
|
|
103
|
+
propsSchema: TPropsSchema;
|
|
104
|
+
toItem(props: zInput<TPropsSchema> & {
|
|
105
|
+
children?: ReactNode;
|
|
106
|
+
}, context: AuthorChildContext): unknown;
|
|
107
|
+
}): TSchema & AuthoredChildBrand<TName, zInput<TPropsSchema> & {
|
|
108
|
+
children?: ReactNode;
|
|
109
|
+
}> & AuthoredToItemBrand;
|
|
110
|
+
export declare function fromChildren<const TName extends string, TSchema extends ZodType, TProps>(name: TName, schema: TSchema, options: {
|
|
61
111
|
text?: string;
|
|
62
112
|
toItem(props: TProps, context: AuthorChildContext): unknown;
|
|
63
|
-
|
|
113
|
+
propsSchema?: never;
|
|
114
|
+
}): TSchema & AuthoredChildBrand<TName, TProps> & AuthoredToItemBrand;
|
|
64
115
|
/**
|
|
65
116
|
* Brands `schema` as text children.
|
|
66
117
|
*
|
|
67
|
-
* Whitespace collapses unless `collapseWhitespace` is `false`.
|
|
118
|
+
* Whitespace collapses unless `collapseWhitespace` is `false`. `dedent` keeps
|
|
119
|
+
* it and reads the text as source, as {@link textFromChildren} does.
|
|
68
120
|
*/
|
|
69
121
|
export declare const fromTextChildren: <TSchema extends ZodType>(schema: TSchema, options?: {
|
|
70
122
|
collapseWhitespace?: boolean;
|
|
123
|
+
dedent?: boolean;
|
|
71
124
|
}) => TSchema & AuthoredTextBrand;
|
|
125
|
+
/**
|
|
126
|
+
* Brands `schema`, a node or an array of nodes, as the primitive elements among
|
|
127
|
+
* the children that no other field claims. Use it for nodes the tree walk does
|
|
128
|
+
* not visit; a walked child slot fills from children already.
|
|
129
|
+
*/
|
|
130
|
+
export declare const fromNodeChildren: <TSchema extends ZodType>(schema: TSchema) => TSchema & AuthoredNodesBrand;
|
|
72
131
|
/** One {@link fromChildren} field as the shim reads it. */
|
|
73
132
|
export interface AuthoredChildField {
|
|
74
133
|
field: string;
|
|
75
|
-
|
|
134
|
+
/** The member name `fromChildren` was given, before capitalizing. */
|
|
135
|
+
name: string;
|
|
76
136
|
/** Field leftover text children fill. */
|
|
77
137
|
textField?: string;
|
|
78
138
|
/** Replaces the default prop copy. */
|
|
79
139
|
toItem?: (props: object, context: AuthorChildContext) => unknown;
|
|
80
140
|
/** The array element schema, or the field schema itself when it is not an array. */
|
|
81
141
|
itemSchema: ZodType;
|
|
142
|
+
/** Input props for a custom `toItem`, excluding JSX children. */
|
|
143
|
+
propsSchema?: ZodType;
|
|
144
|
+
/** Whether the field holds an array of items rather than one item. */
|
|
145
|
+
array: boolean;
|
|
82
146
|
/** Whether the field accepts `undefined`, so children may be omitted. */
|
|
83
147
|
optional: boolean;
|
|
84
|
-
/** Structural fingerprint of `itemSchema`; every field branding one child type must share it. */
|
|
85
|
-
signature: string;
|
|
86
148
|
}
|
|
87
149
|
/** One {@link fromTextChildren} field as the shim reads it. */
|
|
88
150
|
export interface AuthoredTextField {
|
|
89
151
|
field: string;
|
|
90
|
-
/** `true` unless the brand was given `collapseWhitespace: false`. */
|
|
152
|
+
/** `true` unless the brand was given `collapseWhitespace: false` or `dedent`. */
|
|
91
153
|
collapseWhitespace: boolean;
|
|
154
|
+
/** Set when the brand was given `dedent`. */
|
|
155
|
+
dedent?: true;
|
|
92
156
|
/** Whether the field accepts `undefined`, so text children may be omitted. */
|
|
93
157
|
optional: boolean;
|
|
94
158
|
}
|
|
159
|
+
/** One {@link fromNodeChildren} field as the shim reads it. */
|
|
160
|
+
export interface AuthoredNodesField {
|
|
161
|
+
field: string;
|
|
162
|
+
/** Whether the field holds an array of nodes rather than one. */
|
|
163
|
+
array: boolean;
|
|
164
|
+
}
|
|
95
165
|
/** The branded fields found on one object schema. */
|
|
96
166
|
export interface AuthoredSpec {
|
|
97
167
|
children: AuthoredChildField[];
|
|
98
168
|
text: AuthoredTextField[];
|
|
169
|
+
/** Absent on a spec built by hand; read as none. */
|
|
170
|
+
nodes?: AuthoredNodesField[];
|
|
99
171
|
}
|
|
100
|
-
/**
|
|
172
|
+
/**
|
|
173
|
+
* The branded fields on an object schema, top level only: read a child's own
|
|
174
|
+
* brands from its {@link AuthoredChildField.itemSchema}.
|
|
175
|
+
*/
|
|
101
176
|
export declare const readAuthoredSpec: (schema: ZodType) => AuthoredSpec;
|
|
102
177
|
export {};
|
|
103
178
|
//# 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,S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AO,CAAC;CAChB;AAED,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,IAAI,EAAE,iBAAiB,EAAE,CAAC;IAC1B,oDAAoD;IACpD,KAAK,CAAC,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AA6HD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,OAAO,KAAG,YA0BlD,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { ISOMER_ERROR_CODES, IsomerError } from '../composition/error.js';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Member name of the child component a schema field is filled from.
|
|
10
10
|
*
|
|
11
11
|
* `Symbol.for`: ESM and CJS builds must agree, same as `authorType`.
|
|
12
12
|
*/
|
|
@@ -15,23 +15,32 @@ export const authoredChild = Symbol.for('elastic.isomer.authored_child');
|
|
|
15
15
|
export const authoredProps = Symbol.for('elastic.isomer.authored_props');
|
|
16
16
|
/** Set when a field is filled from text children. */
|
|
17
17
|
export const authoredText = Symbol.for('elastic.isomer.authored_text');
|
|
18
|
-
|
|
18
|
+
/** Set when a field is filled from primitive elements no other field claims. */
|
|
19
|
+
export const authoredNodes = Symbol.for('elastic.isomer.authored_nodes');
|
|
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 authoredDedent = Symbol.for('elastic.isomer.authored_dedent');
|
|
25
|
+
const authoredPropsSchema = Symbol.for('elastic.isomer.authored_props_schema');
|
|
21
26
|
const BRANDS = [
|
|
22
27
|
authoredChild,
|
|
23
28
|
authoredTextField,
|
|
24
29
|
authoredToItem,
|
|
25
30
|
authoredText,
|
|
31
|
+
authoredNodes,
|
|
26
32
|
authoredCollapse,
|
|
33
|
+
authoredDedent,
|
|
34
|
+
authoredPropsSchema,
|
|
27
35
|
];
|
|
28
36
|
// Applies a complete branding. Branding an instance again is allowed only with
|
|
29
37
|
// the same configuration, absent options included, since both fields share it.
|
|
30
38
|
const brand = (caller, schema, config) => {
|
|
31
39
|
const record = schema;
|
|
32
40
|
if (BRANDS.some((key) => Object.hasOwn(schema, key))) {
|
|
33
|
-
if (BRANDS.every((key) => record[key] === config[key]))
|
|
41
|
+
if (BRANDS.every((key) => record[key] === config[key])) {
|
|
34
42
|
return;
|
|
43
|
+
}
|
|
35
44
|
throw new IsomerError(ISOMER_ERROR_CODES.AUTHORED_SCHEMA_REUSED, `${caller}: this schema instance is already branded another way; pass each field its own schema.`);
|
|
36
45
|
}
|
|
37
46
|
for (const key of BRANDS) {
|
|
@@ -43,26 +52,40 @@ const brand = (caller, schema, config) => {
|
|
|
43
52
|
}
|
|
44
53
|
}
|
|
45
54
|
};
|
|
46
|
-
export function fromChildren(
|
|
55
|
+
export function fromChildren(name, schema, options) {
|
|
47
56
|
brand('fromChildren', schema, {
|
|
48
|
-
[authoredChild]:
|
|
57
|
+
[authoredChild]: name,
|
|
49
58
|
[authoredTextField]: options?.text,
|
|
50
59
|
[authoredToItem]: options?.toItem,
|
|
60
|
+
[authoredPropsSchema]: options?.propsSchema,
|
|
51
61
|
});
|
|
52
62
|
return schema;
|
|
53
63
|
}
|
|
54
64
|
/**
|
|
55
65
|
* Brands `schema` as text children.
|
|
56
66
|
*
|
|
57
|
-
* Whitespace collapses unless `collapseWhitespace` is `false`.
|
|
67
|
+
* Whitespace collapses unless `collapseWhitespace` is `false`. `dedent` keeps
|
|
68
|
+
* it and reads the text as source, as {@link textFromChildren} does.
|
|
58
69
|
*/
|
|
59
70
|
export const fromTextChildren = (schema, options) => {
|
|
60
71
|
brand('fromTextChildren', schema, {
|
|
61
72
|
[authoredText]: true,
|
|
62
|
-
[authoredCollapse]: options?.collapseWhitespace === false
|
|
73
|
+
[authoredCollapse]: options?.collapseWhitespace === false || options?.dedent
|
|
74
|
+
? false
|
|
75
|
+
: undefined,
|
|
76
|
+
[authoredDedent]: options?.dedent ? true : undefined,
|
|
63
77
|
});
|
|
64
78
|
return schema;
|
|
65
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Brands `schema`, a node or an array of nodes, as the primitive elements among
|
|
82
|
+
* the children that no other field claims. Use it for nodes the tree walk does
|
|
83
|
+
* not visit; a walked child slot fills from children already.
|
|
84
|
+
*/
|
|
85
|
+
export const fromNodeChildren = (schema) => {
|
|
86
|
+
brand('fromNodeChildren', schema, { [authoredNodes]: true });
|
|
87
|
+
return schema;
|
|
88
|
+
};
|
|
66
89
|
const zodDefType = (schema) => schema._zod?.def?.type;
|
|
67
90
|
const WRAPPER_TYPES = new Set(['optional', 'nullable', 'default', 'readonly']);
|
|
68
91
|
const innerSchema = (schema) => {
|
|
@@ -80,8 +103,9 @@ const brandHolder = (schema, key) => {
|
|
|
80
103
|
// Whether any wrapper layer of `schema` accepts `undefined`.
|
|
81
104
|
const optionalThrough = (schema) => {
|
|
82
105
|
for (let current = schema; current; current = innerSchema(current)) {
|
|
83
|
-
if (isOptionalSchema(current))
|
|
106
|
+
if (isOptionalSchema(current)) {
|
|
84
107
|
return true;
|
|
108
|
+
}
|
|
85
109
|
}
|
|
86
110
|
return false;
|
|
87
111
|
};
|
|
@@ -97,50 +121,33 @@ const isOptionalSchema = (schema) => {
|
|
|
97
121
|
const type = zodDefType(schema);
|
|
98
122
|
return type === 'optional' || type === 'default';
|
|
99
123
|
};
|
|
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;
|
|
121
|
-
};
|
|
122
124
|
const arrayElement = (schema) => {
|
|
123
125
|
const inner = unwrapAll(schema);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return inner;
|
|
126
|
+
return zodDefType(inner) === 'array' && 'element' in inner
|
|
127
|
+
? inner.element
|
|
128
|
+
: undefined;
|
|
128
129
|
};
|
|
129
130
|
const readChild = (field, schema) => {
|
|
130
131
|
const holder = brandHolder(schema, authoredChild);
|
|
131
|
-
const
|
|
132
|
-
if (!holder || typeof
|
|
132
|
+
const name = holder?.[authoredChild];
|
|
133
|
+
if (!holder || typeof name !== 'string') {
|
|
133
134
|
return undefined;
|
|
134
135
|
}
|
|
135
136
|
const textField = holder[authoredTextField];
|
|
136
137
|
const toItem = holder[authoredToItem];
|
|
138
|
+
const propsSchema = holder[authoredPropsSchema];
|
|
139
|
+
const element = arrayElement(holder);
|
|
140
|
+
const itemSchema = element ?? unwrapAll(holder);
|
|
137
141
|
const child = {
|
|
138
142
|
field,
|
|
139
|
-
|
|
140
|
-
itemSchema
|
|
143
|
+
name,
|
|
144
|
+
itemSchema,
|
|
145
|
+
array: element !== undefined,
|
|
141
146
|
optional: optionalThrough(schema),
|
|
142
|
-
signature: schemaSignature(arrayElement(holder)),
|
|
143
147
|
};
|
|
148
|
+
if (propsSchema) {
|
|
149
|
+
child.propsSchema = propsSchema;
|
|
150
|
+
}
|
|
144
151
|
if (typeof textField === 'string') {
|
|
145
152
|
child.textField = textField;
|
|
146
153
|
}
|
|
@@ -154,19 +161,27 @@ const readText = (field, schema) => {
|
|
|
154
161
|
if (!holder) {
|
|
155
162
|
return undefined;
|
|
156
163
|
}
|
|
157
|
-
|
|
164
|
+
const text = {
|
|
158
165
|
field,
|
|
159
166
|
collapseWhitespace: holder[authoredCollapse] !== false,
|
|
160
167
|
optional: optionalThrough(schema),
|
|
161
168
|
};
|
|
169
|
+
if (holder[authoredDedent] === true) {
|
|
170
|
+
text.dedent = true;
|
|
171
|
+
}
|
|
172
|
+
return text;
|
|
162
173
|
};
|
|
163
|
-
/**
|
|
174
|
+
/**
|
|
175
|
+
* The branded fields on an object schema, top level only: read a child's own
|
|
176
|
+
* brands from its {@link AuthoredChildField.itemSchema}.
|
|
177
|
+
*/
|
|
164
178
|
export const readAuthoredSpec = (schema) => {
|
|
165
179
|
if (zodDefType(schema) !== 'object' || !('shape' in schema)) {
|
|
166
|
-
return { children: [], text: [] };
|
|
180
|
+
return { children: [], text: [], nodes: [] };
|
|
167
181
|
}
|
|
168
182
|
const children = [];
|
|
169
183
|
const text = [];
|
|
184
|
+
const nodes = [];
|
|
170
185
|
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
171
186
|
const child = readChild(field, fieldSchema);
|
|
172
187
|
if (child) {
|
|
@@ -176,8 +191,13 @@ export const readAuthoredSpec = (schema) => {
|
|
|
176
191
|
const textField = readText(field, fieldSchema);
|
|
177
192
|
if (textField) {
|
|
178
193
|
text.push(textField);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const holder = brandHolder(fieldSchema, authoredNodes);
|
|
197
|
+
if (holder) {
|
|
198
|
+
nodes.push({ field, array: arrayElement(holder) !== undefined });
|
|
179
199
|
}
|
|
180
200
|
}
|
|
181
|
-
return { children, text };
|
|
201
|
+
return { children, text, nodes };
|
|
182
202
|
};
|
|
183
203
|
//# sourceMappingURL=authored_fields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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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;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,gFAAgF;AAChF,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAEzE,qDAAqD;AACrD,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;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AC/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;YACrB,SAAS;QACX,CAAC;QACD,MAAM,MAAM,GAAG,WAAW,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QACvD,IAAI,MAAM,EAAE,CAAC;YACX,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACnC,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 * Member name of the child component 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/** Set when a field is filled from primitive elements no other field claims. */\nexport const authoredNodes = Symbol.for('elastic.isomer.authored_nodes');\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 authoredDedent = Symbol.for('elastic.isomer.authored_dedent');\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/** A field filled from primitive elements, like a child slot the tree walk does not visit. */\nexport interface AuthoredNodesBrand {\n readonly [authoredNodes]: 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 authoredNodes,\n authoredCollapse,\n authoredDedent,\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' | 'fromNodeChildren' | '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])) {\n return;\n }\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 the member `name`, capitalized on the\n * primitive's component: `fromChildren('item', …)` on `slideList` is\n * `<SlideList.Item>`. Names are unique across a primitive's child tree.\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 name: 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 name: 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 name: 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 name: 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 name: 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]: name,\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`. `dedent` keeps\n * it and reads the text as source, as {@link textFromChildren} does.\n */\nexport const fromTextChildren = <TSchema extends ZodType>(\n schema: TSchema,\n options?: { collapseWhitespace?: boolean; dedent?: boolean }\n): TSchema & AuthoredTextBrand => {\n brand('fromTextChildren', schema, {\n [authoredText]: true,\n [authoredCollapse]:\n options?.collapseWhitespace === false || options?.dedent\n ? false\n : undefined,\n [authoredDedent]: options?.dedent ? true : undefined,\n });\n return schema as TSchema & AuthoredTextBrand;\n};\n\n/**\n * Brands `schema`, a node or an array of nodes, as the primitive elements among\n * the children that no other field claims. Use it for nodes the tree walk does\n * not visit; a walked child slot fills from children already.\n */\nexport const fromNodeChildren = <TSchema extends ZodType>(\n schema: TSchema\n): TSchema & AuthoredNodesBrand => {\n brand('fromNodeChildren', schema, { [authoredNodes]: true });\n return schema as TSchema & AuthoredNodesBrand;\n};\n\n/** One {@link fromChildren} field as the shim reads it. */\nexport interface AuthoredChildField {\n field: string;\n /** The member name `fromChildren` was given, before capitalizing. */\n name: 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}\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` or `dedent`. */\n collapseWhitespace: boolean;\n /** Set when the brand was given `dedent`. */\n dedent?: true;\n /** Whether the field accepts `undefined`, so text children may be omitted. */\n optional: boolean;\n}\n\n/** One {@link fromNodeChildren} field as the shim reads it. */\nexport interface AuthoredNodesField {\n field: string;\n /** Whether the field holds an array of nodes rather than one. */\n array: boolean;\n}\n\n/** The branded fields found on one object schema. */\nexport interface AuthoredSpec {\n children: AuthoredChildField[];\n text: AuthoredTextField[];\n /** Absent on a spec built by hand; read as none. */\n nodes?: AuthoredNodesField[];\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)) {\n return true;\n }\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 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 name = (holder as { [authoredChild]?: unknown } | undefined)?.[\n authoredChild\n ];\n if (!holder || typeof name !== '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 name,\n itemSchema,\n array: element !== undefined,\n optional: optionalThrough(schema),\n };\n if (propsSchema) {\n child.propsSchema = propsSchema;\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 const text: AuthoredTextField = {\n field,\n collapseWhitespace:\n (holder as { [authoredCollapse]?: unknown })[authoredCollapse] !== false,\n optional: optionalThrough(schema),\n };\n if ((holder as { [authoredDedent]?: unknown })[authoredDedent] === true) {\n text.dedent = true;\n }\n return text;\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: [], nodes: [] };\n }\n const children: AuthoredChildField[] = [];\n const text: AuthoredTextField[] = [];\n const nodes: AuthoredNodesField[] = [];\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 continue;\n }\n const holder = brandHolder(fieldSchema, authoredNodes);\n if (holder) {\n nodes.push({ field, array: arrayElement(holder) !== undefined });\n }\n }\n return { children, text, nodes };\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;;;CAyDpD,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
}
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
return value.map(copyValue);
|
|
22
|
+
}
|
|
23
|
+
if (typeof value !== 'object' || value === null) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
const prototype = Object.getPrototypeOf(value);
|
|
27
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
return Object.fromEntries(Object.entries(value).map(([key, member]) => [key, copyValue(member)]));
|
|
31
|
+
};
|
|
32
|
+
const copySchema = (source) => {
|
|
33
|
+
const cached = copies.get(source);
|
|
34
|
+
if (cached) {
|
|
35
|
+
return cached;
|
|
36
|
+
}
|
|
37
|
+
let result;
|
|
38
|
+
copies.set(source, z.lazy(() => result));
|
|
39
|
+
const { def } = source._zod;
|
|
40
|
+
if (def.type === 'default' ||
|
|
41
|
+
def.type === 'prefault' ||
|
|
42
|
+
def.type === 'catch') {
|
|
43
|
+
const { innerType } = def;
|
|
44
|
+
const inner = copySchema(innerType);
|
|
45
|
+
result =
|
|
46
|
+
def.type === 'catch'
|
|
47
|
+
? z.clone(inner, inner._zod.def)
|
|
48
|
+
: z.optional(inner);
|
|
49
|
+
}
|
|
50
|
+
else if (def.type === 'lazy') {
|
|
51
|
+
const { getter } = def;
|
|
52
|
+
result = z.lazy(() => copySchema(getter()));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
result = z.clone(source, copyValue(def));
|
|
56
|
+
}
|
|
57
|
+
copies.set(source, result);
|
|
58
|
+
const meta = z.globalRegistry.get(source);
|
|
59
|
+
if (meta) {
|
|
60
|
+
metadata.add(result, meta);
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
};
|
|
64
|
+
return { schema: copySchema(schema), metadata };
|
|
65
|
+
};
|
|
66
|
+
//# 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;AAEH,OAAO,EAAE,CAAC,EAAgB,MAAM,KAAK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CAAC,CAAC;QAC1C,IAAI,IAAI,EAAE,CAAC;YACT,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7B,CAAC;QACD,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)) {\n return copySchema(value);\n }\n if (Array.isArray(value)) {\n return value.map(copyValue);\n }\n if (typeof value !== 'object' || value === null) {\n return value;\n }\n const prototype: unknown = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n return value;\n }\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) {\n return cached;\n }\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) {\n metadata.add(result, meta);\n }\n return result;\n };\n return { schema: copySchema(schema), metadata };\n};\n"]}
|