@financial-times/cp-content-pipeline-schema 2.6.0 → 2.6.2
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/CHANGELOG.md +15 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js.map +1 -1
- package/lib/model/Topper.js +1 -1
- package/lib/model/Topper.js.map +1 -1
- package/lib/resolvers/content-tree/bodyXMLToTree.js +15 -0
- package/lib/resolvers/content-tree/bodyXMLToTree.js.map +1 -1
- package/lib/resolvers/content-tree/bodyXMLToTree.test.js +30 -2
- package/lib/resolvers/content-tree/bodyXMLToTree.test.js.map +1 -1
- package/lib/resolvers/content-tree/nodePredicates.js +21 -28
- package/lib/resolvers/content-tree/nodePredicates.js.map +1 -1
- package/lib/resolvers/content-tree/tagMappings.js +2 -2
- package/lib/resolvers/content-tree/tagMappings.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +8 -0
- package/src/model/Topper.ts +1 -1
- package/src/resolvers/content-tree/bodyXMLToTree.test.ts +32 -3
- package/src/resolvers/content-tree/bodyXMLToTree.ts +18 -0
- package/src/resolvers/content-tree/nodePredicates.ts +24 -21
- package/src/resolvers/content-tree/tagMappings.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { OperationalError } from '@dotcom-reliability-kit/errors'
|
|
2
1
|
import { AnyNode } from './Workarounds'
|
|
3
|
-
import { QueryContext } from '../..'
|
|
2
|
+
import { QueryContext, BodyXMLToTreeError } from '../..'
|
|
4
3
|
|
|
5
4
|
type ValuesOfTuple<Tuple extends readonly string[]> = Tuple[number]
|
|
6
5
|
|
|
@@ -25,15 +24,14 @@ export const findChildOftype = <NodeType extends AnyNode>(
|
|
|
25
24
|
const child = nodes.find(predicate)
|
|
26
25
|
|
|
27
26
|
if (!child) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
error: new OperationalError({
|
|
31
|
-
code: 'BODY_XML_UNEXPECTED_STRUCTURE',
|
|
27
|
+
recordError(
|
|
28
|
+
{
|
|
32
29
|
message: `Didn't find expected child type in ${parentType}`,
|
|
33
30
|
expected: type,
|
|
34
31
|
actual: nodes.map((node) => node.type),
|
|
35
|
-
}
|
|
36
|
-
|
|
32
|
+
},
|
|
33
|
+
context
|
|
34
|
+
)
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
return child
|
|
@@ -49,15 +47,14 @@ export const everyChildIsType = <NodeType extends AnyNode>(
|
|
|
49
47
|
const allChildrenAreType = nodes.every(predicate)
|
|
50
48
|
|
|
51
49
|
if (!allChildrenAreType) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
error: new OperationalError({
|
|
55
|
-
code: 'BODY_XML_UNEXPECTED_STRUCTURE',
|
|
50
|
+
recordError(
|
|
51
|
+
{
|
|
56
52
|
message: `Unexpected children types for ${parentType}`,
|
|
57
53
|
expected: type,
|
|
58
54
|
actual: nodes.map((node) => node.type),
|
|
59
|
-
}
|
|
60
|
-
|
|
55
|
+
},
|
|
56
|
+
context
|
|
57
|
+
)
|
|
61
58
|
}
|
|
62
59
|
|
|
63
60
|
return nodes as NodeType[]
|
|
@@ -74,16 +71,22 @@ export const childrenOfTypes = <Types extends readonly AnyNode['type'][]>(
|
|
|
74
71
|
const allChildrenAreType = nodes.every(predicate)
|
|
75
72
|
|
|
76
73
|
if (!allChildrenAreType) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
error: new OperationalError({
|
|
80
|
-
code: 'BODY_XML_UNEXPECTED_STRUCTURE',
|
|
74
|
+
recordError(
|
|
75
|
+
{
|
|
81
76
|
message: `Unexpected ordered children types for ${parentType}`,
|
|
82
77
|
expected: types,
|
|
83
78
|
actual: nodes.map((node) => node.type),
|
|
84
|
-
}
|
|
85
|
-
|
|
79
|
+
},
|
|
80
|
+
context
|
|
81
|
+
)
|
|
86
82
|
}
|
|
87
|
-
|
|
88
83
|
return nodes as NodeOfType<ValuesOfTuple<Types>>[]
|
|
89
84
|
}
|
|
85
|
+
|
|
86
|
+
const recordError = (error: BodyXMLToTreeError, context?: QueryContext) => {
|
|
87
|
+
if (!context) return
|
|
88
|
+
|
|
89
|
+
context.aggregatedErrors ??= { bodyXMLToTree: [] }
|
|
90
|
+
|
|
91
|
+
context.aggregatedErrors.bodyXMLToTree.push(error)
|
|
92
|
+
}
|
|
@@ -247,7 +247,7 @@ const commonTagMappings: TagMappings = {
|
|
|
247
247
|
description: $description.text(),
|
|
248
248
|
}
|
|
249
249
|
},
|
|
250
|
-
'.n-content-layout': ($el, traverse, context) => {
|
|
250
|
+
'.n-content-layout, .layout': ($el, traverse, context) => {
|
|
251
251
|
//TODO: this is a bit gross??
|
|
252
252
|
const isValidWidth = (
|
|
253
253
|
str: string
|
|
@@ -292,7 +292,7 @@ const commonTagMappings: TagMappings = {
|
|
|
292
292
|
children: getChildren(traverse()),
|
|
293
293
|
}
|
|
294
294
|
},
|
|
295
|
-
'.n-content-layout__slot': ($el, traverse, context) => ({
|
|
295
|
+
'.n-content-layout__slot, .layout-slot': ($el, traverse, context) => ({
|
|
296
296
|
type: 'layout-slot',
|
|
297
297
|
children: childrenOfTypes(
|
|
298
298
|
['heading', 'paragraph', 'layout-image'],
|