@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_schema.d.ts","sourceRoot":"","sources":["../../src/validate/json_schema.ts"],"names":[],"mappings":"AAOA,OAAO,EAAK,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAOzE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,sDAAsD;AACtD,MAAM,WAAW,4BAA4B;IAC3C,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACvD,4FAA4F;IAC5F,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACrC,aAAa,SAAS,sBAAsB,EAAE,EAC9C,UAAS,4BAAiC,KACzC,
|
|
1
|
+
{"version":3,"file":"json_schema.d.ts","sourceRoot":"","sources":["../../src/validate/json_schema.ts"],"names":[],"mappings":"AAOA,OAAO,EAAK,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAOzE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,sDAAsD;AACtD,MAAM,WAAW,4BAA4B;IAC3C,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACvD,4FAA4F;IAC5F,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACrC,aAAa,SAAS,sBAAsB,EAAE,EAC9C,UAAS,4BAAiC,KACzC,UAgEF,CAAC"}
|
|
@@ -26,18 +26,25 @@ export const buildCompositionJsonSchema = (definitions, options = {}) => {
|
|
|
26
26
|
// registration is recorded: a schema named twice (an `extraDefs` entry that
|
|
27
27
|
// is also a member) must restore its original entry, not the first id.
|
|
28
28
|
const previous = new Map();
|
|
29
|
-
const registerId = (schema, id) => {
|
|
29
|
+
const registerId = (schema, id, description) => {
|
|
30
30
|
if (!previous.has(schema)) {
|
|
31
31
|
previous.set(schema, z.globalRegistry.get(schema));
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
const current = z.globalRegistry.get(schema);
|
|
34
|
+
z.globalRegistry.add(schema, {
|
|
35
|
+
...current,
|
|
36
|
+
id,
|
|
37
|
+
...(description === undefined ? {} : { description }),
|
|
38
|
+
});
|
|
34
39
|
};
|
|
35
40
|
registerId(bodyNodeSchema, 'bodyNode');
|
|
36
41
|
for (const extra of options.extraDefs ?? []) {
|
|
37
42
|
registerId(extra.schema, extra.id);
|
|
38
43
|
}
|
|
44
|
+
// `schemaFor` returns a new schema, so the description is taken from the catalog.
|
|
45
|
+
const described = new Map(definitions.map(({ type, catalog }) => [type, catalog.description]));
|
|
39
46
|
for (const [type, schema] of members) {
|
|
40
|
-
registerId(schema, type);
|
|
47
|
+
registerId(schema, type, described.get(type));
|
|
41
48
|
}
|
|
42
49
|
try {
|
|
43
50
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_schema.js","sourceRoot":"","sources":["../../src/validate/json_schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAgB,MAAM,KAAK,CAAC;AAItC,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAqB9B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,WAA8C,EAC9C,UAAwC,EAAE,EAC9B,EAAE;IACd,qEAAqE;IACrE,sDAAsD;IACtD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAChD,MAAM,EAAE,cAAc,EAA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EAAE,OAAO,CAAC,KAAK,IAAI,MAAM;YAC9B,WAAW,EACT,OAAO,CAAC,WAAW;gBACnB,wDAAwD;SAC3D,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,QAAQ,EAAE,CAAC;YACvC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,KAAc,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { z, type ZodType } from 'zod';\n\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport {\n buildCompositionSchema,\n resolveVocabulary,\n} from './composition_schema';\n\ntype JsonSchema = Record<string, unknown>;\n\n/** Options for {@link buildCompositionJsonSchema}. */\nexport interface CompositionJsonSchemaOptions {\n /** Base URI for the emitted schema, which `$ref`s resolve against. */\n $id?: string;\n /** Reaches the model, so it keeps the word \"view\". Defaults to `'View'`. */\n title?: string;\n /** Reaches the model too, so write it as guidance rather than as a type note. */\n description?: string;\n /**\n * Extra schemas to name in `$defs`, for types a pack references by `$ref`.\n * Each `id` becomes the `$defs` key, so it must be unique.\n */\n extraDefs?: readonly { schema: ZodType; id: string }[];\n /** `ref` gives a repeated schema its own `$def`; `inline` repeats it. Defaults to `ref`. */\n reused?: 'ref' | 'inline';\n}\n\n/**\n * Projects the composition schema to JSON Schema draft 2020-12, for hosts\n * that validate outside TypeScript.\n *\n * `$defs` are named per primitive type, plus `bodyNode` for the union.\n * Agent-facing prompt text uses `buildAuthoringJsonSchema` instead.\n */\nexport const buildCompositionJsonSchema = (\n definitions: readonly AnyPrimitiveDefinition[],\n options: CompositionJsonSchemaOptions = {}\n): JsonSchema => {\n // Members, not `definition.schema`: a container's member is built by\n // `schemaFor`, and the registry is keyed on identity.\n const composed = resolveVocabulary(definitions);\n const { bodyNodeSchema, members } = composed;\n const compositionSchema = buildCompositionSchema({ bodyNodeSchema });\n\n // `metadata` replaces `z.toJSONSchema`'s default registry rather than\n // extending it, and `z.globalRegistry` is where every `.describe()` lives,\n // so ids are added to the global registry for the duration of this call\n // and the prior entries restored in `finally`. Only a schema's first\n // registration is recorded: a schema named twice (an `extraDefs` entry that\n // is also a member) must restore its original entry, not the first id.\n const previous = new Map<ZodType, unknown>();\n const registerId = (\n schema: ZodType,\n id: string,\n description?: string\n ): void => {\n if (!previous.has(schema)) {\n previous.set(schema, z.globalRegistry.get(schema));\n }\n const current = z.globalRegistry.get(schema);\n z.globalRegistry.add(schema, {\n ...current,\n id,\n ...(description === undefined ? {} : { description }),\n });\n };\n registerId(bodyNodeSchema, 'bodyNode');\n for (const extra of options.extraDefs ?? []) {\n registerId(extra.schema, extra.id);\n }\n // `schemaFor` returns a new schema, so the description is taken from the catalog.\n const described = new Map(\n definitions.map(({ type, catalog }) => [type, catalog.description])\n );\n for (const [type, schema] of members) {\n registerId(schema, type, described.get(type));\n }\n try {\n return {\n ...z.toJSONSchema(compositionSchema, {\n target: 'draft-2020-12',\n metadata: z.globalRegistry,\n reused: options.reused ?? 'ref',\n cycles: 'ref',\n unrepresentable: 'any',\n }),\n ...(options.$id ? { $id: options.$id } : {}),\n title: options.title ?? 'View',\n description:\n options.description ??\n 'A compact view that may include registered primitives.',\n };\n } finally {\n for (const [schema, entry] of previous) {\n if (entry === undefined) {\n z.globalRegistry.remove(schema);\n } else {\n z.globalRegistry.add(schema, entry as never);\n }\n }\n }\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/validate/url.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/validate/url.ts"],"names":[],"mappings":"AAwEA;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IACgB,CAAC;AAEhF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,IACgB,CAAC;AAEzE,gFAAgF;AAChF,eAAO,MAAM,4BAA4B,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAGpE,CAAC;AAEF,4DAA4D;AAC5D,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,IAG7D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,6EAA6E;AAC7E,eAAO,MAAM,oBAAoB,sDACoB,CAAC;AAEtD,uEAAuE;AACvE,eAAO,MAAM,cAAc,0DAC8B,CAAC;AAE1D,qDAAqD;AACrD,eAAO,MAAM,uBAAuB,8DAAoC,CAAC;AAEzE,+CAA+C;AAC/C,eAAO,MAAM,iBAAiB,kEAA8B,CAAC;AAE7D,+DAA+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAYD;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,UAAS,gBAAqB,4BAM1D,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,UAAS,gBAAqB,4BAMpD,CAAC"}
|
package/dist/validate/url.js
CHANGED
|
@@ -20,8 +20,9 @@ const NAMED_REFERENCES = {
|
|
|
20
20
|
// named ones that spell a scheme, path, or tag character.
|
|
21
21
|
const CHARACTER_REFERENCE_RE = /&(?:#x([0-9a-f]+);?|#([0-9]+);?|(bsol|colon|gt|lt|newline|sol|tab);)/gi;
|
|
22
22
|
const decodeReference = (match, hex, decimal, name) => {
|
|
23
|
-
if (name)
|
|
23
|
+
if (name) {
|
|
24
24
|
return NAMED_REFERENCES[name.toLowerCase()] ?? match;
|
|
25
|
+
}
|
|
25
26
|
const codePoint = Number.parseInt(hex ?? decimal ?? '', hex ? 16 : 10);
|
|
26
27
|
return codePoint > 0 && codePoint <= 0x10ffff
|
|
27
28
|
? String.fromCodePoint(codePoint)
|
package/dist/validate/url.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/validate/url.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,0EAA0E;AAC1E,6EAA6E;AAE7E,MAAM,gBAAgB,GAAqC;IACzD,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,GAAG;IACV,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,GAAG;IACP,OAAO,EAAE,IAAI;IACb,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,IAAI;CACV,CAAC;AAEF,4EAA4E;AAC5E,0DAA0D;AAC1D,MAAM,sBAAsB,GAC1B,wEAAwE,CAAC;AAE3E,MAAM,eAAe,GAAG,CACtB,KAAa,EACb,GAAuB,EACvB,OAA2B,EAC3B,IAAwB,EAChB,EAAE;IACV,IAAI,IAAI;
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/validate/url.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,0EAA0E;AAC1E,6EAA6E;AAE7E,MAAM,gBAAgB,GAAqC;IACzD,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,GAAG;IACV,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,GAAG;IACP,OAAO,EAAE,IAAI;IACb,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,IAAI;CACV,CAAC;AAEF,4EAA4E;AAC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.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 { requiredString } from '../define/zod_helpers';\n\n// The one URL trust policy every URL-bearing field goes through, as a Zod\n// refinement and again as render-time sanitization. See `docs/url-trust.md`.\n\nconst NAMED_REFERENCES: Readonly<Record<string, string>> = {\n bsol: '\\\\',\n colon: ':',\n gt: '>',\n lt: '<',\n newline: '\\n',\n sol: '/',\n tab: '\\t',\n};\n\n// Numeric references, which browsers decode without a trailing `;`, and the\n// named ones that spell a scheme, path, or tag character.\nconst CHARACTER_REFERENCE_RE =\n /&(?:#x([0-9a-f]+);?|#([0-9]+);?|(bsol|colon|gt|lt|newline|sol|tab);)/gi;\n\nconst decodeReference = (\n match: string,\n hex: string | undefined,\n decimal: string | undefined,\n name: string | undefined\n): string => {\n if (name) {\n return NAMED_REFERENCES[name.toLowerCase()] ?? match;\n }\n const codePoint = Number.parseInt(hex ?? decimal ?? '', hex ? 16 : 10);\n return codePoint > 0 && codePoint <= 0x10ffff\n ? String.fromCodePoint(codePoint)\n : '\\ufffd';\n};\n\n// The control characters browsers drop when parsing a URL.\nconst stripControls = (value: string): string =>\n // eslint-disable-next-line no-control-regex -- stripping control characters is the point.\n value.replace(/[\\u0000-\\u001f\\u007f]/g, '').trim();\n\n// The URL as a sink sees it: references decoded once, then controls stripped,\n// so an obfuscated scheme is checked as it would act. Only the decision reads\n// it; the policy returns the authored value, since a consumer that decodes\n// again must decode what was checked, not a decoded copy.\nconst decisionForm = (value: string): string =>\n stripControls(value.replace(CHARACTER_REFERENCE_RE, decodeReference));\n\n// `<` and `>` must be percent-encoded in a URL, so their unencoded presence\n// means the value is malformed or a parser-confusion attempt (an unterminated\n// `<dest` would otherwise read as a relative path). Reject rather than strip.\nconst HAS_ANGLE_BRACKET_RE = /[<>]/;\nconst HAS_SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i;\nconst NAVIGATION_SCHEME_RE = /^(?:https?|mailto):/i;\nconst ASSET_SCHEME_RE = /^(?:https?:|data:image\\/)/i;\n// `//host` — and the `\\` variants browsers fold into `/` — resolve against the\n// current protocol onto a foreign host, so they are not relative paths.\nconst PROTOCOL_RELATIVE_RE = /^[/\\\\][/\\\\]/;\n\n// Whether a URL in decision form passes, given which schemes are allowed.\nconst passes = (decided: string, schemes: RegExp): boolean =>\n decided !== '' &&\n !PROTOCOL_RELATIVE_RE.test(decided) &&\n !HAS_ANGLE_BRACKET_RE.test(decided) &&\n (!HAS_SCHEME_RE.test(decided) || schemes.test(decided));\n\n/**\n * Returns the URL, trimmed and with control characters stripped, when it\n * satisfies the navigation policy (`https:` / `http:` / `mailto:` / relative\n * path), `null` otherwise.\n */\nexport const sanitizeNavigationHref = (href: string): string | null =>\n passes(decisionForm(href), NAVIGATION_SCHEME_RE) ? stripControls(href) : null;\n\n/**\n * Returns the URL, trimmed and with control characters stripped, when it\n * satisfies the asset policy (`https:` / `http:` / relative path /\n * `data:image/*`), `null` otherwise.\n */\nexport const sanitizeAssetUrl = (url: string): string | null =>\n passes(decisionForm(url), ASSET_SCHEME_RE) ? stripControls(url) : null;\n\n/** Checks a Markdown parser's decoded destination without decoding it again. */\nexport const sanitizeParsedNavigationHref = (href: string): string | null => {\n const normalized = stripControls(href);\n return passes(normalized, NAVIGATION_SCHEME_RE) ? normalized : null;\n};\n\n/** Checks a Markdown parser's decoded image destination. */\nexport const sanitizeParsedAssetUrl = (url: string): string | null => {\n const normalized = stripControls(url);\n return passes(normalized, ASSET_SCHEME_RE) ? normalized : null;\n};\n\n/**\n * Render-time replacement for a navigation href that failed the policy: an\n * inert same-document link, so the label stays visible without a destination.\n */\nexport const BLOCKED_HREF = '#';\n\n/** What {@link navigationHref} accepts, for a field description to state. */\nexport const NAVIGATION_HREF_RULE =\n 'an https, http, or mailto URL, or a relative path';\n\n/** What {@link assetUrl} accepts, for a field description to state. */\nexport const ASSET_URL_RULE =\n 'an https, http, or data:image URL, or a relative path';\n\n/** Validation message for {@link navigationHref}. */\nexport const NAVIGATION_HREF_MESSAGE = `must be ${NAVIGATION_HREF_RULE}`;\n\n/** Validation message for {@link assetUrl}. */\nexport const ASSET_URL_MESSAGE = `must be ${ASSET_URL_RULE}`;\n\n/** Options for {@link navigationHref} and {@link assetUrl}. */\nexport interface UrlSchemaOptions {\n /** Longest accepted value, in characters. */\n max?: number;\n}\n\nconst urlSchema = (\n passes: (value: string) => boolean,\n rule: string,\n message: string,\n { max }: UrlSchemaOptions\n) =>\n (max === undefined ? requiredString() : requiredString().max(max))\n .refine(passes, { error: message })\n .describe(`${rule[0]!.toUpperCase()}${rule.slice(1)}.`);\n\n/**\n * Zod schema for an `href`-like field: the validation layer of the two-layer\n * policy, paired with {@link sanitizeNavigationHref} at render time.\n *\n * Its description states the rule, since a refinement's message does not\n * reach the authoring JSON Schema. A field that describes itself should end\n * with {@link NAVIGATION_HREF_RULE} so the model still reads it.\n */\nexport const navigationHref = (options: UrlSchemaOptions = {}) =>\n urlSchema(\n (value) => sanitizeNavigationHref(value) !== null,\n NAVIGATION_HREF_RULE,\n NAVIGATION_HREF_MESSAGE,\n options\n );\n\n/**\n * Zod schema for a `src`-like field, paired with {@link sanitizeAssetUrl} at\n * render time. Describes itself as {@link navigationHref} does, with\n * {@link ASSET_URL_RULE}.\n */\nexport const assetUrl = (options: UrlSchemaOptions = {}) =>\n urlSchema(\n (value) => sanitizeAssetUrl(value) !== null,\n ASSET_URL_RULE,\n ASSET_URL_MESSAGE,\n options\n );\n"]}
|
|
@@ -57,18 +57,8 @@ export { CompositionValidationError };
|
|
|
57
57
|
export declare const enforceValidationMode: (result: ValidationResult, mode?: ValidationErrorMode) => void;
|
|
58
58
|
/** The composition `result` checked, which is what a render draws. Throws {@link CompositionValidationError} when `mode` is `'throw'` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input. */
|
|
59
59
|
export declare const compositionToRender: <TNode extends PrimitiveNode>(result: CheckedValidationResult<TNode>, mode?: ValidationErrorMode) => CheckedComposition<TNode>;
|
|
60
|
-
/**
|
|
60
|
+
/** Options for {@link createCompositionValidator}. */
|
|
61
61
|
export interface CompositionValidatorOptions {
|
|
62
|
-
/**
|
|
63
|
-
* Whether any frame the runtime can draw with sizes itself from node heights,
|
|
64
|
-
* which is what makes a missing `metrics.svgHeight` matter.
|
|
65
|
-
*
|
|
66
|
-
* A runtime-wide question rather than a per-node one, because a frame is a
|
|
67
|
-
* runtime input: any node can be drawn under any frame, so the metric is
|
|
68
|
-
* load-bearing as soon as one frame consults it. Defaults to `false`, so a
|
|
69
|
-
* runtime with no frame at all reports nothing about a value nothing reads.
|
|
70
|
-
*/
|
|
71
|
-
sizesFromNodeHeights?: boolean;
|
|
72
62
|
/** Limits checked before the schema runs; see {@link checkInputBudget}. */
|
|
73
63
|
inputBudget?: InputBudget;
|
|
74
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validate/validation.ts"],"names":[],"mappings":"AAOA,OAAO,
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validate/validation.ts"],"names":[],"mappings":"AAOA,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EACL,0BAA0B,EAC1B,KAAK,eAAe,EACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGzE,OAAO,EAEL,KAAK,WAAW,EAEjB,MAAM,gBAAgB,CAAC;AAGxB;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,iFAAiF;IACjF,OAAO,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;I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AAW,CAAC;CAC3B;AAUD;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,GACrC,KAAK,SAAS,aAAa,GAAG,aAAa,EAE3C,aAAa,SAAS,sBAAsB,EAAE,EAC9C,UAAS,2BAAgC,KACxC,CAAC,CAAC,WAAW,EAAE,WAAW,CAAC,KAAK,CAAC,KAAK,uBAAuB,CAAC,KAAK,CAAC,CAkCtE,CAAC;AAEF,8BAA8B;AAC9B,MAAM,WAAW,iBAAiB;IAChC,gFAAgF;IAChF,KAAK,EAAE,OAAO,CAAC;IACf,2CAA2C;IAC3C,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,sDAAsD;IACtD,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAClC,aAAa,SAAS,sBAAsB,EAAE,EAC9C,kBAAiB,IAAI,CAAC,2BAA2B,EAAE,aAAa,CAAM,KACrE,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,iBAAiB,CAqBxC,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
5
|
* 2.0.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { childNodePath, createChildNodeWalker, rendersOnSurface, SURFACE_NAMES, } from '../composition/body_node_base.js';
|
|
8
8
|
import { quoteText } from '../composition/one_line.js';
|
|
9
9
|
import { CompositionValidationError, } from '../composition/validation_error.js';
|
|
10
10
|
import { getCompositionSchemaForDefinitions } from './composition_schema.js';
|
|
@@ -64,12 +64,7 @@ export const createCompositionValidator = (definitions, options = {}) => {
|
|
|
64
64
|
if (result.success) {
|
|
65
65
|
const { body } = plain;
|
|
66
66
|
const idErrors = collectDuplicateNodeIdErrors(body, walk);
|
|
67
|
-
const warnings =
|
|
68
|
-
...collectEmptySurfaceWarnings(body, walk),
|
|
69
|
-
...(options.sizesFromNodeHeights
|
|
70
|
-
? collectMissingSvgHeightWarnings(body, definitions, walk)
|
|
71
|
-
: []),
|
|
72
|
-
];
|
|
67
|
+
const warnings = collectEmptySurfaceWarnings(body, walk);
|
|
73
68
|
return {
|
|
74
69
|
valid: idErrors.length === 0,
|
|
75
70
|
errors: idErrors,
|
|
@@ -119,48 +114,10 @@ export const createCompositionParser = (definitions, { inputBudget } = {}) => {
|
|
|
119
114
|
};
|
|
120
115
|
};
|
|
121
116
|
/** Warns once per surface that the whole body renders nothing on. */
|
|
122
|
-
const collectEmptySurfaceWarnings = (body, walk) =>
|
|
117
|
+
const collectEmptySurfaceWarnings = (body, walk) => SURFACE_NAMES.filter((surface) => !body.some((node) => rendersOnSurface(node, surface, walk))).map((surface) => ({
|
|
123
118
|
surface,
|
|
124
119
|
message: `composition renders no nodes on surface "${surface}"`,
|
|
125
120
|
}));
|
|
126
|
-
/**
|
|
127
|
-
* Warns for each node that renders to `svg` but declares no `svgHeight`.
|
|
128
|
-
*
|
|
129
|
-
* `metrics.svgHeight` is optional, so `dispatcher.estimateSvgHeight` returns
|
|
130
|
-
* `0` for such a node and a frame that sums node heights sizes short.
|
|
131
|
-
*
|
|
132
|
-
* Whether a runtime consults the metric at all is the caller's to decide; see
|
|
133
|
-
* {@link CompositionValidatorOptions.sizesFromNodeHeights}. A fixed-size frame
|
|
134
|
-
* never does, and warning about a value nothing reads is how a warning channel
|
|
135
|
-
* gets ignored.
|
|
136
|
-
*/
|
|
137
|
-
const collectMissingSvgHeightWarnings = (body, definitions, walk) => {
|
|
138
|
-
const unmeasured = new Set(definitions
|
|
139
|
-
.filter((definition) => !definition.metrics?.svgHeight)
|
|
140
|
-
.map((definition) => definition.type));
|
|
141
|
-
if (unmeasured.size === 0) {
|
|
142
|
-
return [];
|
|
143
|
-
}
|
|
144
|
-
const warnings = [];
|
|
145
|
-
const visit = (node, path) => {
|
|
146
|
-
if (!node || typeof node !== 'object' || !isVisibleOnSurface(node, 'svg')) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const { type } = node;
|
|
150
|
-
if (typeof type === 'string' && unmeasured.has(type)) {
|
|
151
|
-
warnings.push({
|
|
152
|
-
surface: 'svg',
|
|
153
|
-
path,
|
|
154
|
-
message: `${path} type ${quoteText(type)} declares no svgHeight metric and will be measured as 0, sizing the frame short`,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
walk(node).forEach(({ node: child, path: field }) => {
|
|
158
|
-
visit(child, childNodePath(path, field));
|
|
159
|
-
});
|
|
160
|
-
};
|
|
161
|
-
body.forEach((node, index) => visit(node, `body[${index}]`));
|
|
162
|
-
return warnings;
|
|
163
|
-
};
|
|
164
121
|
/**
|
|
165
122
|
* Errors for each node whose `id` repeats one already seen, naming the first
|
|
166
123
|
* use.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validate/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EACL,0BAA0B,GAE3B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,kCAAkC,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EACL,gBAAgB,EAEhB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAkB,MAAM,eAAe,CAAC;AAsCzE,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAc5E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAwB,EACxB,OAAoB,EACC,EAAE,CACvB,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC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,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;YAClD,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC;IAC7D,OAAO,MAAM,CAAC;AAChB,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 {\n BODY_NODE_SURFACES,\n childNodePath,\n createChildNodeWalker,\n isVisibleOnSurface,\n rendersOnSurface,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport type { Composition } from '../composition/composition';\nimport type { PrimitiveNode } from '../composition/node';\nimport { quoteText } from '../composition/one_line';\nimport {\n CompositionValidationError,\n type ValidationError,\n} from '../composition/validation_error';\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport { getCompositionSchemaForDefinitions } from './composition_schema';\nimport {\n checkInputBudget,\n type InputBudget,\n isInputRefusal,\n} from './input_budget';\nimport { createNodeIssueFormatter, type IssueRoot } from './node_issues';\n\n/**\n * A non-fatal validation finding, scoped to the surface it concerns.\n *\n * Warnings carry `surface` because every one of them is a statement about one\n * render target — a composition that draws nothing on `slack` is not news to a\n * caller rendering HTML. Without the scope a host receives every surface's\n * findings on every call and learns to ignore the channel.\n * {@link warningsForSurface} is the filter.\n */\nexport interface ValidationWarning {\n /** The render target this finding concerns, never the composition as a whole. */\n surface: SurfaceName;\n /**\n * Path of the offending node within the composition, absent for\n * whole-composition findings.\n */\n path?: string;\n /** Safe to show a user, and phrased for whoever can act on it. */\n message: string;\n}\n\n/**\n * The outcome of `validate`: errors are fatal, warnings are advisory.\n *\n * `valid` tracks `errors` only — a composition can be valid and still carry\n * warnings, which is the normal case for a surface gap.\n */\nexport interface ValidationResult {\n /** True when `errors` is empty, regardless of `warnings`. */\n valid: boolean;\n /** Fatal findings. Empty when `valid`. */\n errors: ValidationError[];\n /** Advisory findings, empty when there are none. */\n warnings: ValidationWarning[];\n}\n\nconst checkedComposition = Symbol.for('elastic.isomer.checked_composition');\n\n/** The copy {@link createCompositionValidator} checked, which a validating render draws in place of the caller's value. The brand is type-only. */\nexport type CheckedComposition<TNode extends PrimitiveNode = PrimitiveNode> =\n Composition<TNode> & { readonly [checkedComposition]: true };\n\n/** A {@link ValidationResult} with the composition it describes. */\nexport interface CheckedValidationResult<\n TNode extends PrimitiveNode = PrimitiveNode,\n> extends ValidationResult {\n /** Undefined only when {@link checkInputBudget} refused the input. */\n composition: CheckedComposition<TNode> | undefined;\n}\n\n/** Narrows a result's warnings to the surface a caller is about to render. */\nexport const warningsForSurface = (\n result: ValidationResult,\n surface: SurfaceName\n): ValidationWarning[] =>\n result.warnings.filter((warning) => warning.surface === surface);\n\n/** Whether a render reports validation findings or raises on them. */\nexport type ValidationErrorMode = 'collect' | 'throw';\n\nexport { CompositionValidationError };\n\n/** Raises {@link CompositionValidationError} when `mode` is `throw` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input, which nothing can render. */\nexport const enforceValidationMode = (\n result: ValidationResult,\n mode?: ValidationErrorMode\n): void => {\n if (\n !result.valid &&\n (mode === 'throw' || result.errors.some(isInputRefusal))\n ) {\n throw new CompositionValidationError(result.errors);\n }\n};\n\n/** The composition `result` checked, which is what a render draws. Throws {@link CompositionValidationError} when `mode` is `'throw'` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input. */\nexport const compositionToRender = <TNode extends PrimitiveNode>(\n result: CheckedValidationResult<TNode>,\n mode?: ValidationErrorMode\n): CheckedComposition<TNode> => {\n enforceValidationMode(result, mode);\n const { composition } = result;\n if (composition === undefined) {\n throw new CompositionValidationError(result.errors);\n }\n return composition;\n};\n\n/** Runtime facts the semantic passes need beyond the primitive inventory. */\nexport interface CompositionValidatorOptions {\n /**\n * Whether any frame the runtime can draw with sizes itself from node heights,\n * which is what makes a missing `metrics.svgHeight` matter.\n *\n * A runtime-wide question rather than a per-node one, because a frame is a\n * runtime input: any node can be drawn under any frame, so the metric is\n * load-bearing as soon as one frame consults it. Defaults to `false`, so a\n * runtime with no frame at all reports nothing about a value nothing reads.\n */\n sizesFromNodeHeights?: boolean;\n /** Limits checked before the schema runs; see {@link checkInputBudget}. */\n inputBudget?: InputBudget;\n}\n\n/** The body's nodes, as {@link IssueRoot}s for a node issue formatter. */\nconst bodyRoots = (value: unknown): IssueRoot[] => {\n const { body } = (value ?? {}) as { body?: unknown };\n return Array.isArray(body)\n ? body.map((node, index) => [node, `body[${index}]`] as const)\n : [];\n};\n\n/**\n * Builds the trusted-input validator: {@link checkInputBudget}, then the schema and the semantic passes on its copy, which the result carries.\n *\n * `definitions` is memoized on array identity, so a caller that rebuilds the\n * array per call (`createCompositionValidator(packs.flatMap(…))`) resolves a\n * fresh discriminated union each time. Hold the array `composePacks` returns\n * and reuse it across the validator, the parser, and the authoring context.\n */\nexport const createCompositionValidator = <\n TNode extends PrimitiveNode = PrimitiveNode,\n>(\n definitions: readonly AnyPrimitiveDefinition[],\n options: CompositionValidatorOptions = {}\n): ((composition: Composition<TNode>) => CheckedValidationResult<TNode>) => {\n const schema = getCompositionSchemaForDefinitions(definitions);\n const walk = createChildNodeWalker(definitions);\n const formatIssues = createNodeIssueFormatter(definitions);\n return (composition) => {\n const checked = checkInputBudget(composition, options.inputBudget);\n if (!checked.valid) {\n return {\n valid: false,\n errors: [checked.error],\n warnings: [],\n composition: undefined,\n };\n }\n const plain = checked.value as CheckedComposition<TNode>;\n const result = schema.safeParse(plain, { reportInput: true });\n if (result.success) {\n const { body } = plain;\n const idErrors = collectDuplicateNodeIdErrors(body, walk);\n const warnings = [\n ...collectEmptySurfaceWarnings(body, walk),\n ...(options.sizesFromNodeHeights\n ? collectMissingSvgHeightWarnings(body, definitions, walk)\n : []),\n ];\n return {\n valid: idErrors.length === 0,\n errors: idErrors,\n warnings,\n composition: plain,\n };\n }\n return {\n valid: false,\n errors: formatIssues(bodyRoots(plain), result.error.issues),\n warnings: [],\n composition: plain,\n };\n };\n};\n\n/** The outcome of `parse`. */\nexport interface ParsedComposition {\n /** True when the value matched the schema. Says nothing about id uniqueness. */\n valid: boolean;\n /** Schema failures. Empty when `valid`. */\n errors: ValidationError[];\n /** The parsed document, present only when `valid`. */\n composition?: Composition;\n}\n\n/**\n * Builds the untrusted-input parser: {@link checkInputBudget}, then the schema only on its copy, reported rather than thrown.\n *\n * Deliberately narrower than {@link createCompositionValidator}. This answers\n * \"is this a `Composition`\", not \"is this a good one\" — it does not run the\n * duplicate-id pass or produce warnings, so a composition with two nodes\n * sharing an `id` parses as valid. Id uniqueness is a `validate` guarantee, so\n * a caller that wants the semantic checks runs `validate` on the result.\n *\n * Shares {@link createCompositionValidator}'s memoization identity requirement.\n */\nexport const createCompositionParser = (\n definitions: readonly AnyPrimitiveDefinition[],\n { inputBudget }: Pick<CompositionValidatorOptions, 'inputBudget'> = {}\n): ((value: unknown) => ParsedComposition) => {\n const schema = getCompositionSchemaForDefinitions(definitions);\n const formatIssues = createNodeIssueFormatter(definitions);\n return (value) => {\n const checked = checkInputBudget(value, inputBudget);\n if (!checked.valid) {\n return { valid: false, errors: [checked.error] };\n }\n const result = schema.safeParse(checked.value, { reportInput: true });\n if (result.success) {\n return {\n valid: true,\n errors: [],\n composition: result.data as unknown as Composition,\n };\n }\n return {\n valid: false,\n errors: formatIssues(bodyRoots(checked.value), result.error.issues),\n };\n };\n};\n\n/** Warns once per surface that the whole body renders nothing on. */\nconst collectEmptySurfaceWarnings = (\n body: readonly unknown[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationWarning[] =>\n BODY_NODE_SURFACES.filter(\n (surface) => !body.some((node) => rendersOnSurface(node, surface, walk))\n ).map((surface) => ({\n surface,\n message: `composition renders no nodes on surface \"${surface}\"`,\n }));\n\n/**\n * Warns for each node that renders to `svg` but declares no `svgHeight`.\n *\n * `metrics.svgHeight` is optional, so `dispatcher.estimateSvgHeight` returns\n * `0` for such a node and a frame that sums node heights sizes short.\n *\n * Whether a runtime consults the metric at all is the caller's to decide; see\n * {@link CompositionValidatorOptions.sizesFromNodeHeights}. A fixed-size frame\n * never does, and warning about a value nothing reads is how a warning channel\n * gets ignored.\n */\nconst collectMissingSvgHeightWarnings = (\n body: readonly unknown[],\n definitions: readonly AnyPrimitiveDefinition[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationWarning[] => {\n const unmeasured = new Set(\n definitions\n .filter((definition) => !definition.metrics?.svgHeight)\n .map((definition) => definition.type)\n );\n if (unmeasured.size === 0) {\n return [];\n }\n const warnings: ValidationWarning[] = [];\n const visit = (node: unknown, path: string): void => {\n if (!node || typeof node !== 'object' || !isVisibleOnSurface(node, 'svg')) {\n return;\n }\n const { type } = node as { type?: unknown };\n if (typeof type === 'string' && unmeasured.has(type)) {\n warnings.push({\n surface: 'svg',\n path,\n message: `${path} type ${quoteText(type)} declares no svgHeight metric and will be measured as 0, sizing the frame short`,\n });\n }\n walk(node).forEach(({ node: child, path: field }) => {\n visit(child, childNodePath(path, field));\n });\n };\n body.forEach((node, index) => visit(node, `body[${index}]`));\n return warnings;\n};\n\n/**\n * Errors for each node whose `id` repeats one already seen, naming the first\n * use.\n *\n * Errors rather than warnings, because ids are what a host addresses a node by.\n * Run by `validate` and deliberately not by `parse`; see\n * {@link createCompositionParser}.\n */\nconst collectDuplicateNodeIdErrors = (\n body: readonly unknown[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationError[] => {\n const errors: ValidationError[] = [];\n const seen = new Map<string, string>();\n const visit = (node: unknown, path: string): void => {\n if (!node || typeof node !== 'object') {\n return;\n }\n const { id, type } = node as { id?: unknown; type?: unknown };\n if (typeof id === 'string') {\n const first = seen.get(id);\n if (first) {\n errors.push({\n path: `${path}.id`,\n message: `duplicates id ${quoteText(id)} first used at ${first}`,\n ...(typeof type === 'string' ? { nodeType: type } : {}),\n });\n } else {\n seen.set(id, path);\n }\n }\n walk(node).forEach(({ node: child, path: field }) => {\n visit(child, childNodePath(path, field));\n });\n };\n body.forEach((node, index) => visit(node, `body[${index}]`));\n return errors;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validate/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,GAEd,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EACL,0BAA0B,GAE3B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,kCAAkC,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EACL,gBAAgB,EAEhB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAkB,MAAM,eAAe,CAAC;AAsCzE,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAc5E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAwB,EACxB,OAAoB,EACC,EAAE,CACvB,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;AAKnE,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAEtC,0LAA0L;AAC1L,MAAM,CAAC,MAA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EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC;IAC7D,OAAO,MAAM,CAAC;AAChB,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 {\n childNodePath,\n createChildNodeWalker,\n rendersOnSurface,\n SURFACE_NAMES,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport type { Composition } from '../composition/composition';\nimport type { PrimitiveNode } from '../composition/node';\nimport { quoteText } from '../composition/one_line';\nimport {\n CompositionValidationError,\n type ValidationError,\n} from '../composition/validation_error';\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport { getCompositionSchemaForDefinitions } from './composition_schema';\nimport {\n checkInputBudget,\n type InputBudget,\n isInputRefusal,\n} from './input_budget';\nimport { createNodeIssueFormatter, type IssueRoot } from './node_issues';\n\n/**\n * A non-fatal validation finding, scoped to the surface it concerns.\n *\n * Warnings carry `surface` because every one of them is a statement about one\n * render target — a composition that draws nothing on `slack` is not news to a\n * caller rendering HTML. Without the scope a host receives every surface's\n * findings on every call and learns to ignore the channel.\n * {@link warningsForSurface} is the filter.\n */\nexport interface ValidationWarning {\n /** The render target this finding concerns, never the composition as a whole. */\n surface: SurfaceName;\n /**\n * Path of the offending node within the composition, absent for\n * whole-composition findings.\n */\n path?: string;\n /** Safe to show a user, and phrased for whoever can act on it. */\n message: string;\n}\n\n/**\n * The outcome of `validate`: errors are fatal, warnings are advisory.\n *\n * `valid` tracks `errors` only — a composition can be valid and still carry\n * warnings, which is the normal case for a surface gap.\n */\nexport interface ValidationResult {\n /** True when `errors` is empty, regardless of `warnings`. */\n valid: boolean;\n /** Fatal findings. Empty when `valid`. */\n errors: ValidationError[];\n /** Advisory findings, empty when there are none. */\n warnings: ValidationWarning[];\n}\n\nconst checkedComposition = Symbol.for('elastic.isomer.checked_composition');\n\n/** The copy {@link createCompositionValidator} checked, which a validating render draws in place of the caller's value. The brand is type-only. */\nexport type CheckedComposition<TNode extends PrimitiveNode = PrimitiveNode> =\n Composition<TNode> & { readonly [checkedComposition]: true };\n\n/** A {@link ValidationResult} with the composition it describes. */\nexport interface CheckedValidationResult<\n TNode extends PrimitiveNode = PrimitiveNode,\n> extends ValidationResult {\n /** Undefined only when {@link checkInputBudget} refused the input. */\n composition: CheckedComposition<TNode> | undefined;\n}\n\n/** Narrows a result's warnings to the surface a caller is about to render. */\nexport const warningsForSurface = (\n result: ValidationResult,\n surface: SurfaceName\n): ValidationWarning[] =>\n result.warnings.filter((warning) => warning.surface === surface);\n\n/** Whether a render reports validation findings or raises on them. */\nexport type ValidationErrorMode = 'collect' | 'throw';\n\nexport { CompositionValidationError };\n\n/** Raises {@link CompositionValidationError} when `mode` is `throw` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input, which nothing can render. */\nexport const enforceValidationMode = (\n result: ValidationResult,\n mode?: ValidationErrorMode\n): void => {\n if (\n !result.valid &&\n (mode === 'throw' || result.errors.some(isInputRefusal))\n ) {\n throw new CompositionValidationError(result.errors);\n }\n};\n\n/** The composition `result` checked, which is what a render draws. Throws {@link CompositionValidationError} when `mode` is `'throw'` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input. */\nexport const compositionToRender = <TNode extends PrimitiveNode>(\n result: CheckedValidationResult<TNode>,\n mode?: ValidationErrorMode\n): CheckedComposition<TNode> => {\n enforceValidationMode(result, mode);\n const { composition } = result;\n if (composition === undefined) {\n throw new CompositionValidationError(result.errors);\n }\n return composition;\n};\n\n/** Options for {@link createCompositionValidator}. */\nexport interface CompositionValidatorOptions {\n /** Limits checked before the schema runs; see {@link checkInputBudget}. */\n inputBudget?: InputBudget;\n}\n\n/** The body's nodes, as {@link IssueRoot}s for a node issue formatter. */\nconst bodyRoots = (value: unknown): IssueRoot[] => {\n const { body } = (value ?? {}) as { body?: unknown };\n return Array.isArray(body)\n ? body.map((node, index) => [node, `body[${index}]`] as const)\n : [];\n};\n\n/**\n * Builds the trusted-input validator: {@link checkInputBudget}, then the schema and the semantic passes on its copy, which the result carries.\n *\n * `definitions` is memoized on array identity, so a caller that rebuilds the\n * array per call (`createCompositionValidator(packs.flatMap(…))`) resolves a\n * fresh discriminated union each time. Hold the array `composePacks` returns\n * and reuse it across the validator, the parser, and the authoring context.\n */\nexport const createCompositionValidator = <\n TNode extends PrimitiveNode = PrimitiveNode,\n>(\n definitions: readonly AnyPrimitiveDefinition[],\n options: CompositionValidatorOptions = {}\n): ((composition: Composition<TNode>) => CheckedValidationResult<TNode>) => {\n const schema = getCompositionSchemaForDefinitions(definitions);\n const walk = createChildNodeWalker(definitions);\n const formatIssues = createNodeIssueFormatter(definitions);\n return (composition) => {\n const checked = checkInputBudget(composition, options.inputBudget);\n if (!checked.valid) {\n return {\n valid: false,\n errors: [checked.error],\n warnings: [],\n composition: undefined,\n };\n }\n const plain = checked.value as CheckedComposition<TNode>;\n const result = schema.safeParse(plain, { reportInput: true });\n if (result.success) {\n const { body } = plain;\n const idErrors = collectDuplicateNodeIdErrors(body, walk);\n const warnings = collectEmptySurfaceWarnings(body, walk);\n return {\n valid: idErrors.length === 0,\n errors: idErrors,\n warnings,\n composition: plain,\n };\n }\n return {\n valid: false,\n errors: formatIssues(bodyRoots(plain), result.error.issues),\n warnings: [],\n composition: plain,\n };\n };\n};\n\n/** The outcome of `parse`. */\nexport interface ParsedComposition {\n /** True when the value matched the schema. Says nothing about id uniqueness. */\n valid: boolean;\n /** Schema failures. Empty when `valid`. */\n errors: ValidationError[];\n /** The parsed document, present only when `valid`. */\n composition?: Composition;\n}\n\n/**\n * Builds the untrusted-input parser: {@link checkInputBudget}, then the schema only on its copy, reported rather than thrown.\n *\n * Deliberately narrower than {@link createCompositionValidator}. This answers\n * \"is this a `Composition`\", not \"is this a good one\" — it does not run the\n * duplicate-id pass or produce warnings, so a composition with two nodes\n * sharing an `id` parses as valid. Id uniqueness is a `validate` guarantee, so\n * a caller that wants the semantic checks runs `validate` on the result.\n *\n * Shares {@link createCompositionValidator}'s memoization identity requirement.\n */\nexport const createCompositionParser = (\n definitions: readonly AnyPrimitiveDefinition[],\n { inputBudget }: Pick<CompositionValidatorOptions, 'inputBudget'> = {}\n): ((value: unknown) => ParsedComposition) => {\n const schema = getCompositionSchemaForDefinitions(definitions);\n const formatIssues = createNodeIssueFormatter(definitions);\n return (value) => {\n const checked = checkInputBudget(value, inputBudget);\n if (!checked.valid) {\n return { valid: false, errors: [checked.error] };\n }\n const result = schema.safeParse(checked.value, { reportInput: true });\n if (result.success) {\n return {\n valid: true,\n errors: [],\n composition: result.data as unknown as Composition,\n };\n }\n return {\n valid: false,\n errors: formatIssues(bodyRoots(checked.value), result.error.issues),\n };\n };\n};\n\n/** Warns once per surface that the whole body renders nothing on. */\nconst collectEmptySurfaceWarnings = (\n body: readonly unknown[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationWarning[] =>\n SURFACE_NAMES.filter(\n (surface) => !body.some((node) => rendersOnSurface(node, surface, walk))\n ).map((surface) => ({\n surface,\n message: `composition renders no nodes on surface \"${surface}\"`,\n }));\n\n/**\n * Errors for each node whose `id` repeats one already seen, naming the first\n * use.\n *\n * Errors rather than warnings, because ids are what a host addresses a node by.\n * Run by `validate` and deliberately not by `parse`; see\n * {@link createCompositionParser}.\n */\nconst collectDuplicateNodeIdErrors = (\n body: readonly unknown[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationError[] => {\n const errors: ValidationError[] = [];\n const seen = new Map<string, string>();\n const visit = (node: unknown, path: string): void => {\n if (!node || typeof node !== 'object') {\n return;\n }\n const { id, type } = node as { id?: unknown; type?: unknown };\n if (typeof id === 'string') {\n const first = seen.get(id);\n if (first) {\n errors.push({\n path: `${path}.id`,\n message: `duplicates id ${quoteText(id)} first used at ${first}`,\n ...(typeof type === 'string' ? { nodeType: type } : {}),\n });\n } else {\n seen.set(id, path);\n }\n }\n walk(node).forEach(({ node: child, path: field }) => {\n visit(child, childNodePath(path, field));\n });\n };\n body.forEach((node, index) => visit(node, `body[${index}]`));\n return errors;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elastic/isomer-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shared primitive-pack toolkit for Isomer: the composition contract, validation, and rendering.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"author": "Elastic",
|
|
@@ -111,7 +111,8 @@
|
|
|
111
111
|
"micromark-extension-gfm": "^3.0.0"
|
|
112
112
|
},
|
|
113
113
|
"devDependencies": {
|
|
114
|
-
"@types/mdast": "^4.0.4"
|
|
114
|
+
"@types/mdast": "^4.0.4",
|
|
115
|
+
"parse5": "^7.3.0"
|
|
115
116
|
},
|
|
116
117
|
"scripts": {
|
|
117
118
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|