@elastic/isomer-sdk 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/dist/author/authored_fields.d.ts +61 -11
- package/dist/author/authored_fields.d.ts.map +1 -1
- package/dist/author/authored_fields.js +73 -29
- 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 +60 -0
- package/dist/author/authoring_input.js.map +1 -0
- package/dist/author/authoring_model.d.ts +27 -0
- package/dist/author/authoring_model.d.ts.map +1 -0
- package/dist/author/authoring_model.js +98 -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 +277 -0
- package/dist/author/declarations.js.map +1 -0
- package/dist/author/index.d.ts +3 -1
- package/dist/author/index.d.ts.map +1 -1
- package/dist/author/index.js +3 -1
- package/dist/author/index.js.map +1 -1
- package/dist/author/jsx_shim.d.ts +6 -5
- package/dist/author/jsx_shim.d.ts.map +1 -1
- package/dist/author/jsx_shim.js +28 -111
- package/dist/author/jsx_shim.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 +286 -0
- package/dist/author/schema_to_typescript.js.map +1 -0
- package/dist/cjs/author/authored_fields.js +77 -33
- package/dist/cjs/author/authored_fields.js.map +1 -1
- package/dist/cjs/author/authoring_input.js +64 -0
- package/dist/cjs/author/authoring_input.js.map +1 -0
- package/dist/cjs/author/authoring_model.js +104 -0
- package/dist/cjs/author/authoring_model.js.map +1 -0
- package/dist/cjs/author/declarations.js +281 -0
- package/dist/cjs/author/declarations.js.map +1 -0
- package/dist/cjs/author/index.js +6 -1
- package/dist/cjs/author/index.js.map +1 -1
- package/dist/cjs/author/jsx_shim.js +31 -114
- package/dist/cjs/author/jsx_shim.js.map +1 -1
- package/dist/cjs/author/schema_to_typescript.js +295 -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 +1 -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/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 +14 -3
- 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 +7 -2
- package/dist/cjs/entries/index.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.map +1 -1
- package/dist/cjs/pack/primitive_pack.js +14 -2
- 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/html/envelope.js.map +1 -1
- package/dist/cjs/render/layout_check.js.map +1 -1
- package/dist/cjs/render/markdown/builder.js +14 -8
- package/dist/cjs/render/markdown/builder.js.map +1 -1
- package/dist/cjs/render/markdown/format.js +30 -12
- package/dist/cjs/render/markdown/format.js.map +1 -1
- package/dist/cjs/render/primitive_dispatch.js +11 -25
- package/dist/cjs/render/primitive_dispatch.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 +166 -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/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 +1 -0
- package/dist/composition/error.d.ts.map +1 -1
- package/dist/composition/error.js +1 -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/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 +38 -24
- package/dist/define/primitive_module.d.ts.map +1 -1
- package/dist/define/primitive_module.js +14 -3
- 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 +2 -2
- package/dist/entries/index.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 +1 -1
- package/dist/pack/index.d.ts.map +1 -1
- package/dist/pack/index.js +1 -1
- package/dist/pack/index.js.map +1 -1
- package/dist/pack/primitive_pack.d.ts +11 -2
- package/dist/pack/primitive_pack.d.ts.map +1 -1
- package/dist/pack/primitive_pack.js +12 -1
- 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/html/envelope.d.ts +3 -3
- 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 +2 -4
- package/dist/render/markdown/builder.d.ts.map +1 -1
- package/dist/render/markdown/builder.js +14 -7
- package/dist/render/markdown/builder.js.map +1 -1
- package/dist/render/markdown/format.d.ts +7 -0
- package/dist/render/markdown/format.d.ts.map +1 -1
- package/dist/render/markdown/format.js +27 -11
- package/dist/render/markdown/format.js.map +1 -1
- 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/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 +163 -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/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
|
@@ -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":"A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|
* 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,CA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,CAAC;QACD,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,IAAwC,CAAC;QAC9D,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC3B,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,IAAI,CAAC;oBACV,IAAI,EAAE,GAAG,IAAI,KAAK;oBAClB,OAAO,EAAE,iBAAiB,SAAS,CAAC,EAAE,CAAC,kBAAkB,KAAK,EAAE;oBAChE,GAAG,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACxD,CAAC,CAAC;YACL,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,E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Q,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACxD,CAAC,CAAC;YACL,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 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.2.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"
|