@squiz/dx-json-schema-lib 1.34.1-alpha.1 → 1.34.1-alpha.3
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/.npm/_logs/{2023-05-18T02_09_56_858Z-debug-0.log → 2023-05-23T01_36_55_443Z-debug-0.log} +15 -15
- package/jsonCompiler.ts +5 -1
- package/lib/JsonValidationService.d.ts +3 -1
- package/lib/JsonValidationService.js +6 -1
- package/lib/JsonValidationService.js.map +1 -1
- package/lib/JsonValidationService.spec.js +81 -0
- package/lib/JsonValidationService.spec.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/pageContents/pageContentsModels.d.ts +1 -0
- package/lib/pageContents/pageContentsModels.js +28 -0
- package/lib/pageContents/pageContentsModels.js.map +1 -0
- package/lib/pageContents/pageContentsSchemas.d.ts +2 -0
- package/lib/pageContents/pageContentsSchemas.js +9 -0
- package/lib/pageContents/pageContentsSchemas.js.map +1 -0
- package/lib/pageContents/v1/pageContents.d.ts +45 -0
- package/lib/pageContents/v1/pageContents.js +9 -0
- package/lib/pageContents/v1/pageContents.js.map +1 -0
- package/lib/pageContents/v1/pageContents.json +127 -0
- package/package.json +2 -2
- package/src/JsonValidationService.spec.ts +96 -0
- package/src/JsonValidationService.ts +7 -0
- package/src/index.ts +3 -0
- package/src/pageContents/pageContentsModels.ts +1 -0
- package/src/pageContents/pageContentsSchemas.ts +3 -0
- package/src/pageContents/v1/pageContents.json +127 -0
- package/src/pageContents/v1/pageContents.ts +52 -0
- package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,127 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
3
|
+
"type": "object",
|
4
|
+
"properties": {
|
5
|
+
"rule": {
|
6
|
+
"$ref": "#/definitions/rule"
|
7
|
+
},
|
8
|
+
"containers": {
|
9
|
+
"type": "array",
|
10
|
+
"items": {
|
11
|
+
"type": "object",
|
12
|
+
"properties": {
|
13
|
+
"layout": {
|
14
|
+
"$ref": "#/definitions/layout"
|
15
|
+
},
|
16
|
+
"rule": {
|
17
|
+
"$ref": "#/definitions/rule"
|
18
|
+
},
|
19
|
+
"items": {
|
20
|
+
"$ref": "#/definitions/items"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
},
|
24
|
+
"additionalProperties": false
|
25
|
+
}
|
26
|
+
},
|
27
|
+
"required": ["containers"],
|
28
|
+
"definitions": {
|
29
|
+
"rule": {
|
30
|
+
"type": "object",
|
31
|
+
"properties": {
|
32
|
+
"type": {
|
33
|
+
"type": "string",
|
34
|
+
"enum": ["language", "segment", "split"]
|
35
|
+
},
|
36
|
+
"values": {
|
37
|
+
"type": "array",
|
38
|
+
"items": {
|
39
|
+
"type": "string"
|
40
|
+
}
|
41
|
+
}
|
42
|
+
},
|
43
|
+
"required": ["type", "values"]
|
44
|
+
},
|
45
|
+
"layout": {
|
46
|
+
"type": "object",
|
47
|
+
"properties": {
|
48
|
+
"name": {
|
49
|
+
"type": "string"
|
50
|
+
},
|
51
|
+
"type": {
|
52
|
+
"type": "string",
|
53
|
+
"enum": ["inline", "external-reference"]
|
54
|
+
},
|
55
|
+
"value": {
|
56
|
+
"type": "string"
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"required": ["name", "type", "value"]
|
60
|
+
},
|
61
|
+
"items": {
|
62
|
+
"type": "array",
|
63
|
+
"items": {
|
64
|
+
"properties": {
|
65
|
+
"rule": {
|
66
|
+
"$ref": "#/definitions/rule"
|
67
|
+
},
|
68
|
+
"type": {
|
69
|
+
"type": "string",
|
70
|
+
"enum": ["component", "rich-text"]
|
71
|
+
},
|
72
|
+
"component": {
|
73
|
+
"type": "string"
|
74
|
+
},
|
75
|
+
"layout-area": {
|
76
|
+
"type": "number"
|
77
|
+
},
|
78
|
+
"content": {
|
79
|
+
"oneOf": [
|
80
|
+
{
|
81
|
+
"type": "object",
|
82
|
+
"patternProperties": {
|
83
|
+
"^.*$": {
|
84
|
+
"oneOf": [
|
85
|
+
{
|
86
|
+
"type": "object",
|
87
|
+
"properties": {
|
88
|
+
"html": {
|
89
|
+
"type": "array",
|
90
|
+
"items": {
|
91
|
+
"type": "object",
|
92
|
+
"properties": {
|
93
|
+
"tag": {
|
94
|
+
"type": "string"
|
95
|
+
},
|
96
|
+
"content": {
|
97
|
+
"type": "string"
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
},
|
103
|
+
"description": "NOTE : This is a temp object, will be a reference to FT schema",
|
104
|
+
"additionalProperties": false
|
105
|
+
},
|
106
|
+
{
|
107
|
+
"type": "string",
|
108
|
+
"additionalProperties": {
|
109
|
+
"type": "string"
|
110
|
+
}
|
111
|
+
}
|
112
|
+
]
|
113
|
+
}
|
114
|
+
}
|
115
|
+
},
|
116
|
+
{
|
117
|
+
"type": "string"
|
118
|
+
}
|
119
|
+
]
|
120
|
+
}
|
121
|
+
},
|
122
|
+
"required": ["type", "content", "layout_area"]
|
123
|
+
}
|
124
|
+
}
|
125
|
+
},
|
126
|
+
"additionalProperties": false
|
127
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/dx-json-schema-lib",
|
3
|
-
"version": "1.34.1-alpha.
|
3
|
+
"version": "1.34.1-alpha.3",
|
4
4
|
"description": "",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"scripts": {
|
@@ -31,5 +31,5 @@
|
|
31
31
|
"@squiz/json-schema-library": "7.4.7",
|
32
32
|
"ts-brand": "0.0.2"
|
33
33
|
},
|
34
|
-
"gitHead": "
|
34
|
+
"gitHead": "c7360adacee0d77cdef12576f51a23fd228bc501"
|
35
35
|
}
|
@@ -17,6 +17,7 @@ import { FormattedTextType, SquizImageType, SquizLinkType } from './primitiveTyp
|
|
17
17
|
import { TypeResolverBuilder } from './jsonTypeResolution/TypeResolverBuilder';
|
18
18
|
import { MatrixAssetUri } from './validators/utils/matrixAssetValidator';
|
19
19
|
import { MatrixAssetType } from './resolvableTypes';
|
20
|
+
import { PageContents } from './pageContents/v1/pageContents';
|
20
21
|
|
21
22
|
function expectToThrowErrorMatchingTypeAndMessage(
|
22
23
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
@@ -339,6 +340,101 @@ describe('JsonValidationService', () => {
|
|
339
340
|
expect(jsonValidationService.validateRenderInput(schema, otherValue)).toEqual(true);
|
340
341
|
});
|
341
342
|
});
|
343
|
+
|
344
|
+
describe('validatePageContents', () => {
|
345
|
+
const validPageContents: PageContents[] = [
|
346
|
+
{
|
347
|
+
containers: [],
|
348
|
+
},
|
349
|
+
{
|
350
|
+
containers: [
|
351
|
+
{
|
352
|
+
layout: {
|
353
|
+
name: 'chris-custom-2-col-layout',
|
354
|
+
type: 'inline',
|
355
|
+
value: '<div>[area://output/1]</div>',
|
356
|
+
},
|
357
|
+
items: [
|
358
|
+
{
|
359
|
+
type: 'component',
|
360
|
+
content: 'content-store://asdfkjashdfkjhwek234j234',
|
361
|
+
component: 'namespace/componentname/version',
|
362
|
+
layout_area: 1,
|
363
|
+
},
|
364
|
+
],
|
365
|
+
},
|
366
|
+
],
|
367
|
+
},
|
368
|
+
];
|
369
|
+
it.each(validPageContents)('should validate valid page contents', (input) => {
|
370
|
+
expect(jsonValidationService.validatePageContents(input)).toEqual(true);
|
371
|
+
});
|
372
|
+
|
373
|
+
it('should throw error for empty page contents', () => {
|
374
|
+
const input = {};
|
375
|
+
expectToThrowErrorMatchingTypeAndMessage(
|
376
|
+
() => {
|
377
|
+
jsonValidationService.validatePageContents(input);
|
378
|
+
},
|
379
|
+
SchemaValidationError,
|
380
|
+
'failed validation: The required property `containers` is missing at `#`',
|
381
|
+
{
|
382
|
+
'#': [
|
383
|
+
{
|
384
|
+
data: { key: 'containers', pointer: '#' },
|
385
|
+
message: 'The required property `containers` is missing at `#`',
|
386
|
+
},
|
387
|
+
],
|
388
|
+
},
|
389
|
+
);
|
390
|
+
});
|
391
|
+
|
392
|
+
it('should throw error for invalid page contents with multiple errors', () => {
|
393
|
+
const input = {
|
394
|
+
containers: [
|
395
|
+
{
|
396
|
+
layout: {
|
397
|
+
name: 'chris-custom-2-col-layout',
|
398
|
+
type: 'inline',
|
399
|
+
value: 123,
|
400
|
+
},
|
401
|
+
items: [
|
402
|
+
{
|
403
|
+
type: 'bad-type',
|
404
|
+
content: 'content-store://asdfkjashdfkjhwek234j234',
|
405
|
+
component: 'namespace/componentname/version',
|
406
|
+
layout_area: 1,
|
407
|
+
},
|
408
|
+
],
|
409
|
+
},
|
410
|
+
],
|
411
|
+
};
|
412
|
+
expectToThrowErrorMatchingTypeAndMessage(
|
413
|
+
() => {
|
414
|
+
jsonValidationService.validatePageContents(input);
|
415
|
+
},
|
416
|
+
SchemaValidationError,
|
417
|
+
'failed validation: Expected `123` (number) in `#/containers/0/layout/value` to be of type `string`,' +
|
418
|
+
'\n' +
|
419
|
+
'Expected given value `bad-type` in #/containers/0/items/0/type` to be one of `[component, rich-text]`',
|
420
|
+
{
|
421
|
+
'#/containers/0/items/0/type': [
|
422
|
+
{
|
423
|
+
data: { pointer: '#/containers/0/items/0/type', value: 'bad-type', values: ['component', 'rich-text'] },
|
424
|
+
message:
|
425
|
+
'Expected given value `bad-type` in #/containers/0/items/0/type` to be one of `[component, rich-text]`',
|
426
|
+
},
|
427
|
+
],
|
428
|
+
'#/containers/0/layout/value': [
|
429
|
+
{
|
430
|
+
data: { pointer: '#/containers/0/layout/value', expected: 'string', received: 'number', value: 123 },
|
431
|
+
message: 'Expected `123` (number) in `#/containers/0/layout/value` to be of type `string`',
|
432
|
+
},
|
433
|
+
],
|
434
|
+
},
|
435
|
+
);
|
436
|
+
});
|
437
|
+
});
|
342
438
|
});
|
343
439
|
|
344
440
|
const defaultSchema: JSONSchema = {
|
@@ -8,6 +8,7 @@ import MatrixAssetSchema from './manifest/v1/MatrixAssetSchema.json';
|
|
8
8
|
import Draft07Schema from './manifest/v1/Draft-07.json';
|
9
9
|
|
10
10
|
import FormattedText from './formatted-text/v1/formattedText.json';
|
11
|
+
import PageContentsSchema from './pageContents/v1/pageContents.json';
|
11
12
|
|
12
13
|
import v1 from './manifest/v1/v1.json';
|
13
14
|
import { SchemaValidationError, ValidationData, ValidationDataMap } from './errors/SchemaValidationError';
|
@@ -162,6 +163,8 @@ export const RenderInputMetaSchema: MetaSchemaInput = {
|
|
162
163
|
root: Draft07Schema,
|
163
164
|
};
|
164
165
|
|
166
|
+
export const PageContentsMetaSchema = new Draft07(PageContentsSchema, defaultConfig);
|
167
|
+
|
165
168
|
export const ManifestV1MetaSchema: MetaSchemaInput = {
|
166
169
|
root: v1,
|
167
170
|
remotes: {
|
@@ -306,6 +309,10 @@ export class JsonValidationService {
|
|
306
309
|
|
307
310
|
return processValidationResult(errors);
|
308
311
|
}
|
312
|
+
|
313
|
+
validatePageContents(pageContents: JSONSchema) {
|
314
|
+
return processValidationResult(PageContentsMetaSchema.validate(pageContents));
|
315
|
+
}
|
309
316
|
}
|
310
317
|
|
311
318
|
function processValidationResult(errors: JSONError[]): true {
|
package/src/index.ts
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
export * as MANIFEST_MODELS from './manifest/v1/manifestModels';
|
2
2
|
export * as MANIFEST_SCHEMAS from './manifest/v1/manifestSchemas';
|
3
3
|
|
4
|
+
export * as PAGE_CONTENTS_MODELS from './manifest/v1/manifestModels';
|
5
|
+
export * as PAGE_CONTENT_SCHEMAS from './manifest/v1/manifestSchemas';
|
6
|
+
|
4
7
|
export * as FORMATTED_TEXT_MODELS from './formatted-text/v1/formattedTextModels';
|
5
8
|
export * as FORMATTED_TEXT_SCHEMAS from './formatted-text/v1/formattedTextSchemas';
|
6
9
|
export * from './formatted-text/v1/resolveFormattedTextNodes';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * as v1 from './v1/pageContents';
|
@@ -0,0 +1,127 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
3
|
+
"type": "object",
|
4
|
+
"properties": {
|
5
|
+
"rule": {
|
6
|
+
"$ref": "#/definitions/rule"
|
7
|
+
},
|
8
|
+
"containers": {
|
9
|
+
"type": "array",
|
10
|
+
"items": {
|
11
|
+
"type": "object",
|
12
|
+
"properties": {
|
13
|
+
"layout": {
|
14
|
+
"$ref": "#/definitions/layout"
|
15
|
+
},
|
16
|
+
"rule": {
|
17
|
+
"$ref": "#/definitions/rule"
|
18
|
+
},
|
19
|
+
"items": {
|
20
|
+
"$ref": "#/definitions/items"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
},
|
24
|
+
"additionalProperties": false
|
25
|
+
}
|
26
|
+
},
|
27
|
+
"required": ["containers"],
|
28
|
+
"definitions": {
|
29
|
+
"rule": {
|
30
|
+
"type": "object",
|
31
|
+
"properties": {
|
32
|
+
"type": {
|
33
|
+
"type": "string",
|
34
|
+
"enum": ["language", "segment", "split"]
|
35
|
+
},
|
36
|
+
"values": {
|
37
|
+
"type": "array",
|
38
|
+
"items": {
|
39
|
+
"type": "string"
|
40
|
+
}
|
41
|
+
}
|
42
|
+
},
|
43
|
+
"required": ["type", "values"]
|
44
|
+
},
|
45
|
+
"layout": {
|
46
|
+
"type": "object",
|
47
|
+
"properties": {
|
48
|
+
"name": {
|
49
|
+
"type": "string"
|
50
|
+
},
|
51
|
+
"type": {
|
52
|
+
"type": "string",
|
53
|
+
"enum": ["inline", "external-reference"]
|
54
|
+
},
|
55
|
+
"value": {
|
56
|
+
"type": "string"
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"required": ["name", "type", "value"]
|
60
|
+
},
|
61
|
+
"items": {
|
62
|
+
"type": "array",
|
63
|
+
"items": {
|
64
|
+
"properties": {
|
65
|
+
"rule": {
|
66
|
+
"$ref": "#/definitions/rule"
|
67
|
+
},
|
68
|
+
"type": {
|
69
|
+
"type": "string",
|
70
|
+
"enum": ["component", "rich-text"]
|
71
|
+
},
|
72
|
+
"component": {
|
73
|
+
"type": "string"
|
74
|
+
},
|
75
|
+
"layout-area": {
|
76
|
+
"type": "number"
|
77
|
+
},
|
78
|
+
"content": {
|
79
|
+
"oneOf": [
|
80
|
+
{
|
81
|
+
"type": "object",
|
82
|
+
"patternProperties": {
|
83
|
+
"^.*$": {
|
84
|
+
"oneOf": [
|
85
|
+
{
|
86
|
+
"type": "object",
|
87
|
+
"properties": {
|
88
|
+
"html": {
|
89
|
+
"type": "array",
|
90
|
+
"items": {
|
91
|
+
"type": "object",
|
92
|
+
"properties": {
|
93
|
+
"tag": {
|
94
|
+
"type": "string"
|
95
|
+
},
|
96
|
+
"content": {
|
97
|
+
"type": "string"
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
},
|
103
|
+
"description": "NOTE : This is a temp object, will be a reference to FT schema",
|
104
|
+
"additionalProperties": false
|
105
|
+
},
|
106
|
+
{
|
107
|
+
"type": "string",
|
108
|
+
"additionalProperties": {
|
109
|
+
"type": "string"
|
110
|
+
}
|
111
|
+
}
|
112
|
+
]
|
113
|
+
}
|
114
|
+
}
|
115
|
+
},
|
116
|
+
{
|
117
|
+
"type": "string"
|
118
|
+
}
|
119
|
+
]
|
120
|
+
}
|
121
|
+
},
|
122
|
+
"required": ["type", "content", "layout_area"]
|
123
|
+
}
|
124
|
+
}
|
125
|
+
},
|
126
|
+
"additionalProperties": false
|
127
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/* eslint-disable */
|
2
|
+
/**
|
3
|
+
* This file was automatically generated by json-schema-to-typescript.
|
4
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
5
|
+
* and run json-schema-to-typescript to regenerate this file.
|
6
|
+
*/
|
7
|
+
|
8
|
+
export type Items = {
|
9
|
+
rule?: Rule;
|
10
|
+
type: 'component' | 'rich-text';
|
11
|
+
component?: string;
|
12
|
+
'layout-area'?: number;
|
13
|
+
content:
|
14
|
+
| {
|
15
|
+
/**
|
16
|
+
* This interface was referenced by `undefined`'s JSON-Schema definition
|
17
|
+
* via the `patternProperty` "^.*$".
|
18
|
+
*/
|
19
|
+
[k: string]:
|
20
|
+
| {
|
21
|
+
html?: {
|
22
|
+
tag?: string;
|
23
|
+
content?: string;
|
24
|
+
[k: string]: unknown;
|
25
|
+
}[];
|
26
|
+
}
|
27
|
+
| string;
|
28
|
+
}
|
29
|
+
| string;
|
30
|
+
[k: string]: unknown;
|
31
|
+
}[];
|
32
|
+
|
33
|
+
export interface PageContents {
|
34
|
+
rule?: Rule;
|
35
|
+
containers: {
|
36
|
+
layout?: Layout;
|
37
|
+
rule?: Rule;
|
38
|
+
items?: Items;
|
39
|
+
[k: string]: unknown;
|
40
|
+
}[];
|
41
|
+
}
|
42
|
+
export interface Rule {
|
43
|
+
type: 'language' | 'segment' | 'split';
|
44
|
+
values: string[];
|
45
|
+
[k: string]: unknown;
|
46
|
+
}
|
47
|
+
export interface Layout {
|
48
|
+
name: string;
|
49
|
+
type: 'inline' | 'external-reference';
|
50
|
+
value: string;
|
51
|
+
[k: string]: unknown;
|
52
|
+
}
|