@squiz/dx-json-schema-lib 1.39.1-alpha.9 → 1.40.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,125 +2,40 @@
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
3
  "type": "object",
4
4
  "properties": {
5
- "rule": {
6
- "$ref": "#/definitions/rule"
5
+ "id": {
6
+ "type": "string"
7
7
  },
8
- "containers": {
8
+ "name": {
9
+ "type": "string"
10
+ },
11
+ "layouts": {
9
12
  "type": "array",
10
13
  "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
14
+ "$ref": "#/definitions/layout"
15
+ }
25
16
  }
26
17
  },
27
- "required": ["containers"],
18
+ "required": ["name", "layouts"],
28
19
  "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
20
  "layout": {
46
21
  "type": "object",
47
22
  "properties": {
48
- "name": {
23
+ "schemaName": {
49
24
  "type": "string"
50
25
  },
51
- "type": {
52
- "type": "string",
53
- "enum": ["inline", "external-reference"]
54
- },
55
- "value": {
56
- "type": "string"
26
+ "content": {
27
+ "type": "object",
28
+ "properties": {
29
+ "contentItemId": {
30
+ "type": "string"
31
+ }
32
+ },
33
+ "required": ["contentItemId"],
34
+ "additionalProperties": false
57
35
  }
58
36
  },
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
- }
37
+ "required": ["schemaName", "content"],
38
+ "additionalProperties": false
124
39
  }
125
40
  },
126
41
  "additionalProperties": false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dx-json-schema-lib",
3
- "version": "1.39.1-alpha.9",
3
+ "version": "1.40.1-alpha.0",
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": "947f8ee7b28d83be28cd8f83e919911d5ca07f2c"
34
+ "gitHead": "81931ba6a9e9e62f6a5a9e8aac73b3c50418f478"
35
35
  }
@@ -344,26 +344,16 @@ describe('JsonValidationService', () => {
344
344
  describe('validatePageContents', () => {
345
345
  const validPageContents: PageContents[] = [
346
346
  {
347
- containers: [],
348
- },
349
- {
350
- containers: [
347
+ layouts: [
351
348
  {
352
- layout: {
353
- name: 'chris-custom-2-col-layout',
354
- type: 'inline',
355
- value: '<div>[area://output/1]</div>',
349
+ schemaName: 'content-item-schema',
350
+ content: {
351
+ contentItemId: '123',
356
352
  },
357
- items: [
358
- {
359
- type: 'component',
360
- content: 'content-store://asdfkjashdfkjhwek234j234',
361
- component: 'namespace/componentname/version',
362
- layout_area: 1,
363
- },
364
- ],
365
353
  },
366
354
  ],
355
+ name: 'test',
356
+ id: ' 1',
367
357
  },
368
358
  ];
369
359
  it.each(validPageContents)('should validate valid page contents', (input) => {
@@ -377,13 +367,11 @@ describe('JsonValidationService', () => {
377
367
  jsonValidationService.validatePageContents(input);
378
368
  },
379
369
  SchemaValidationError,
380
- 'failed validation: The required property `containers` is missing at `#`',
370
+ 'failed validation: The required property `name` is missing at `#`,\nThe required property `layouts` is missing at `#`',
381
371
  {
382
372
  '#': [
383
- {
384
- data: { key: 'containers', pointer: '#' },
385
- message: 'The required property `containers` is missing at `#`',
386
- },
373
+ { data: { key: 'name', pointer: '#' }, message: 'The required property `name` is missing at `#`' },
374
+ { data: { key: 'layouts', pointer: '#' }, message: 'The required property `layouts` is missing at `#`' },
387
375
  ],
388
376
  },
389
377
  );
@@ -414,22 +402,19 @@ describe('JsonValidationService', () => {
414
402
  jsonValidationService.validatePageContents(input);
415
403
  },
416
404
  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]`',
405
+ 'failed validation: Additional property `containers` in `#` is not allowed,\nThe required property `name` is missing at `#`,\nThe required property `layouts` is missing at `#`',
420
406
  {
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': [
407
+ '#': [
429
408
  {
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`',
409
+ data: {
410
+ pointer: '#',
411
+ properties: ['id', 'name', 'layouts'],
412
+ property: 'containers',
413
+ },
414
+ message: 'Additional property `containers` in `#` is not allowed',
432
415
  },
416
+ { data: { key: 'name', pointer: '#' }, message: 'The required property `name` is missing at `#`' },
417
+ { data: { key: 'layouts', pointer: '#' }, message: 'The required property `layouts` is missing at `#`' },
433
418
  ],
434
419
  },
435
420
  );
@@ -21,7 +21,11 @@
21
21
  },
22
22
 
23
23
  "BaseFormattedNodes": {
24
- "anyOf": [{ "$ref": "#/definitions/FormattedTextTag" }, { "$ref": "#/definitions/TextNode" }]
24
+ "anyOf": [
25
+ { "$ref": "#/definitions/FormattedTextTag" },
26
+ { "$ref": "#/definitions/TextNode" },
27
+ { "$ref": "#/definitions/ComponentNode" }
28
+ ]
25
29
  },
26
30
 
27
31
  "TextNode": {
@@ -87,6 +91,27 @@
87
91
  "required": ["type", "tag", "children"]
88
92
  },
89
93
 
94
+ "ComponentNode": {
95
+ "type": "object",
96
+ "additionalProperties": false,
97
+
98
+ "properties": {
99
+ "type": { "const": "component" },
100
+ "schemaName": { "type": "string" },
101
+ "componentSet": { "type": "string" },
102
+ "content": {
103
+ "type": "object",
104
+ "title": "ContentItemReference",
105
+ "properties": {
106
+ "contentItemId": { "type": "string" }
107
+ },
108
+ "required": ["contentItemId"],
109
+ "additionalProperties": false
110
+ }
111
+ },
112
+ "required": ["type", "schemaName", "componentSet"]
113
+ },
114
+
90
115
  "FormattedTextLinkToMatrixAsset": {
91
116
  "type": "object",
92
117
  "additionalProperties": false,
@@ -8,7 +8,7 @@
8
8
  export type FormattedNodes = HigherOrderFormattedNodes | BaseFormattedNodes;
9
9
  export type HigherOrderFormattedNodes = FormattedTextLinkToMatrixAsset | FormattedTextMatrixImage;
10
10
  export type WithChildrenNode = FormattedNodes[];
11
- export type BaseFormattedNodes = FormattedTextTag | TextNode;
11
+ export type BaseFormattedNodes = FormattedTextTag | TextNode | ComponentNode;
12
12
  export type FormattedText = FormattedNodes[];
13
13
 
14
14
  export interface FormattedTextLinkToMatrixAsset {
@@ -54,3 +54,12 @@ export interface TextNode {
54
54
  type: 'text';
55
55
  value: string;
56
56
  }
57
+ export interface ComponentNode {
58
+ type: 'component';
59
+ schemaName: string;
60
+ componentSet: string;
61
+ content?: ContentItemReference;
62
+ }
63
+ export interface ContentItemReference {
64
+ contentItemId: string;
65
+ }
@@ -3,6 +3,7 @@ import { JSONSchema } from '@squiz/json-schema-library';
3
3
  import { ComponentInputSchema } from '../..';
4
4
  import {
5
5
  BaseFormattedNodes,
6
+ ComponentNode,
6
7
  FormattedText,
7
8
  FormattedTextTag,
8
9
  HigherOrderFormattedNodes,
@@ -33,7 +34,7 @@ export type ResolvedChildNode<
33
34
  ? Omit<DEFAULT_NODES, 'children'> & { children: CHILD_NODE[] }
34
35
  : DEFAULT_NODES;
35
36
 
36
- export type FullyResolvedNodes = ResolvedChildNode<TextNode | FormattedTextTag, string>;
37
+ export type FullyResolvedNodes = ResolvedChildNode<TextNode | FormattedTextTag | ComponentNode, string>;
37
38
  export type BaseResolvedNodes = ResolvedChildNode<BaseFormattedNodes, BaseFormattedNodes>;
38
39
  export type HigherOrderResolvedNodes = ResolvedChildNode<HigherOrderFormattedNodes, BaseResolvedNodes>;
39
40
 
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
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';
4
+ export * as PAGE_CONTENTS_MODELS from './pageContents/pageContentsModels';
5
+ export * as PAGE_CONTENT_SCHEMAS from './pageContents/pageContentsSchemas';
6
6
 
7
7
  export * as FORMATTED_TEXT_MODELS from './formatted-text/v1/formattedTextModels';
8
8
  export * as FORMATTED_TEXT_SCHEMAS from './formatted-text/v1/formattedTextSchemas';
@@ -2,125 +2,40 @@
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
3
  "type": "object",
4
4
  "properties": {
5
- "rule": {
6
- "$ref": "#/definitions/rule"
5
+ "id": {
6
+ "type": "string"
7
7
  },
8
- "containers": {
8
+ "name": {
9
+ "type": "string"
10
+ },
11
+ "layouts": {
9
12
  "type": "array",
10
13
  "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
14
+ "$ref": "#/definitions/layout"
15
+ }
25
16
  }
26
17
  },
27
- "required": ["containers"],
18
+ "required": ["name", "layouts"],
28
19
  "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
20
  "layout": {
46
21
  "type": "object",
47
22
  "properties": {
48
- "name": {
23
+ "schemaName": {
49
24
  "type": "string"
50
25
  },
51
- "type": {
52
- "type": "string",
53
- "enum": ["inline", "external-reference"]
54
- },
55
- "value": {
56
- "type": "string"
26
+ "content": {
27
+ "type": "object",
28
+ "properties": {
29
+ "contentItemId": {
30
+ "type": "string"
31
+ }
32
+ },
33
+ "required": ["contentItemId"],
34
+ "additionalProperties": false
57
35
  }
58
36
  },
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
- }
37
+ "required": ["schemaName", "content"],
38
+ "additionalProperties": false
124
39
  }
125
40
  },
126
41
  "additionalProperties": false
@@ -5,48 +5,14 @@
5
5
  * and run json-schema-to-typescript to regenerate this file.
6
6
  */
7
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
8
  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;
9
+ id?: string;
10
+ name: string;
11
+ layouts: Layout[];
46
12
  }
47
13
  export interface Layout {
48
- name: string;
49
- type: 'inline' | 'external-reference';
50
- value: string;
51
- [k: string]: unknown;
14
+ schemaName: string;
15
+ content: {
16
+ contentItemId: string;
17
+ };
52
18
  }