@squiz/dx-json-schema-lib 1.2.13-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/jest.config.ts +20 -0
  3. package/jsonCompiler.ts +22 -0
  4. package/lib/JsonValidationService.d.ts +9 -0
  5. package/lib/JsonValidationService.js +54 -0
  6. package/lib/JsonValidationService.js.map +1 -0
  7. package/lib/JsonValidationService.spec.d.ts +1 -0
  8. package/lib/JsonValidationService.spec.js +143 -0
  9. package/lib/JsonValidationService.spec.js.map +1 -0
  10. package/lib/errors/SchemaValidationError.d.ts +4 -0
  11. package/lib/errors/SchemaValidationError.js +12 -0
  12. package/lib/errors/SchemaValidationError.js.map +1 -0
  13. package/lib/formatted-text/v1/formattedText.d.ts +51 -0
  14. package/lib/formatted-text/v1/formattedText.js +9 -0
  15. package/lib/formatted-text/v1/formattedText.js.map +1 -0
  16. package/lib/formatted-text/v1/formattedText.json +134 -0
  17. package/lib/formatted-text/v1/formattedTextModels.d.ts +1 -0
  18. package/lib/formatted-text/v1/formattedTextModels.js +28 -0
  19. package/lib/formatted-text/v1/formattedTextModels.js.map +1 -0
  20. package/lib/formatted-text/v1/formattedTextSchemas.d.ts +2 -0
  21. package/lib/formatted-text/v1/formattedTextSchemas.js +9 -0
  22. package/lib/formatted-text/v1/formattedTextSchemas.js.map +1 -0
  23. package/lib/index.d.ts +7 -0
  24. package/lib/index.js +37 -0
  25. package/lib/index.js.map +1 -0
  26. package/lib/manifest/v1/DxComponentIcons.json +2279 -0
  27. package/lib/manifest/v1/DxComponentInputSchema.json +20 -0
  28. package/lib/manifest/v1/DxComponentInputSchema.spec.d.ts +1 -0
  29. package/lib/manifest/v1/DxComponentInputSchema.spec.js +113 -0
  30. package/lib/manifest/v1/DxComponentInputSchema.spec.js.map +1 -0
  31. package/lib/manifest/v1/DxContentMetaSchema.json +165 -0
  32. package/lib/manifest/v1/__test__/schemas/badFunctionInputComponent.json +39 -0
  33. package/lib/manifest/v1/__test__/schemas/badNestedFunctionInput.json +39 -0
  34. package/lib/manifest/v1/__test__/schemas/nonObjectFunctionInputComponent.json +39 -0
  35. package/lib/manifest/v1/__test__/schemas/validComponent.json +40 -0
  36. package/lib/manifest/v1/manifestModels.d.ts +1 -0
  37. package/lib/manifest/v1/manifestModels.js +28 -0
  38. package/lib/manifest/v1/manifestModels.js.map +1 -0
  39. package/lib/manifest/v1/manifestSchemas.d.ts +2 -0
  40. package/lib/manifest/v1/manifestSchemas.js +9 -0
  41. package/lib/manifest/v1/manifestSchemas.js.map +1 -0
  42. package/lib/manifest/v1/subSchemas.d.ts +4 -0
  43. package/lib/manifest/v1/subSchemas.js +13 -0
  44. package/lib/manifest/v1/subSchemas.js.map +1 -0
  45. package/lib/manifest/v1/v1.d.ts +460 -0
  46. package/lib/manifest/v1/v1.js +9 -0
  47. package/lib/manifest/v1/v1.js.map +1 -0
  48. package/lib/manifest/v1/v1.json +362 -0
  49. package/lib/manifest/v1/v1.spec.d.ts +1 -0
  50. package/lib/manifest/v1/v1.spec.js +35 -0
  51. package/lib/manifest/v1/v1.spec.js.map +1 -0
  52. package/package.json +36 -0
  53. package/src/JsonValidationService.spec.ts +162 -0
  54. package/src/JsonValidationService.ts +54 -0
  55. package/src/errors/SchemaValidationError.ts +9 -0
  56. package/src/formatted-text/v1/formattedText.json +145 -0
  57. package/src/formatted-text/v1/formattedText.ts +54 -0
  58. package/src/formatted-text/v1/formattedTextModels.ts +1 -0
  59. package/src/formatted-text/v1/formattedTextSchemas.ts +3 -0
  60. package/src/index.ts +10 -0
  61. package/src/manifest/v1/DxComponentIcons.json +2279 -0
  62. package/src/manifest/v1/DxComponentInputSchema.json +20 -0
  63. package/src/manifest/v1/DxComponentInputSchema.spec.ts +136 -0
  64. package/src/manifest/v1/DxContentMetaSchema.json +165 -0
  65. package/src/manifest/v1/__test__/schemas/badFunctionInputComponent.json +39 -0
  66. package/src/manifest/v1/__test__/schemas/badNestedFunctionInput.json +39 -0
  67. package/src/manifest/v1/__test__/schemas/nonObjectFunctionInputComponent.json +39 -0
  68. package/src/manifest/v1/__test__/schemas/validComponent.json +40 -0
  69. package/src/manifest/v1/manifestModels.ts +1 -0
  70. package/src/manifest/v1/manifestSchemas.ts +3 -0
  71. package/src/manifest/v1/subSchemas.ts +5 -0
  72. package/src/manifest/v1/v1.json +369 -0
  73. package/src/manifest/v1/v1.spec.ts +39 -0
  74. package/src/manifest/v1/v1.ts +2731 -0
  75. package/tsconfig.json +16 -0
  76. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "DxComponentInputSchema.json",
4
+ "title": "DxComponentInputSchema",
5
+ "description": "Input schema for a DxComponent",
6
+ "type": "object",
7
+ "properties": {
8
+ "type": {
9
+ "const": "object"
10
+ },
11
+ "additionalProperties": {
12
+ "default": false
13
+ }
14
+ },
15
+ "allOf": [
16
+ {
17
+ "$ref": "DxContentMetaSchema.json"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,136 @@
1
+ import { JsonValidationService } from '../../JsonValidationService';
2
+
3
+ describe('DxComponentInputSchema', () => {
4
+ let jsonValidationService: JsonValidationService;
5
+ beforeAll(() => {
6
+ jsonValidationService = new JsonValidationService();
7
+ });
8
+
9
+ it('should allow empty object', () => {
10
+ expect(() => jsonValidationService.validateContentSchema({})).not.toThrowError();
11
+ });
12
+
13
+ it('should require required if properties is specified', () => {
14
+ expect(() =>
15
+ jsonValidationService.validateContentSchema({
16
+ properties: {
17
+ foo: {
18
+ type: 'string',
19
+ },
20
+ },
21
+ }),
22
+ ).toThrowError();
23
+ });
24
+
25
+ it('should pass if required and properties are specified', () => {
26
+ expect(() =>
27
+ jsonValidationService.validateContentSchema({
28
+ required: ['foo'],
29
+ properties: {
30
+ foo: {
31
+ type: 'string',
32
+ },
33
+ },
34
+ }),
35
+ ).not.toThrowError();
36
+ });
37
+
38
+ it('should error if type is not "object"', () => {
39
+ expect(() =>
40
+ jsonValidationService.validateContentSchema({
41
+ type: 'string',
42
+ }),
43
+ ).toThrowError();
44
+ });
45
+
46
+ it('should allow a nested type to be "FormattedText"', () => {
47
+ expect(() =>
48
+ jsonValidationService.validateContentSchema({
49
+ type: 'object',
50
+ properties: {
51
+ foo: {
52
+ type: 'FormattedText',
53
+ },
54
+ },
55
+ required: ['foo'],
56
+ }),
57
+ ).not.toThrowError();
58
+ });
59
+
60
+ it('should error on unknown keywords', () => {
61
+ expect(() =>
62
+ jsonValidationService.validateContentSchema({
63
+ type: 'object',
64
+ foo: 'bar',
65
+ }),
66
+ ).toThrowError();
67
+ });
68
+
69
+ it('should allow a nested property to be an array of of objects which have a property of type to be "FormattedText" that is required', () => {
70
+ expect(() =>
71
+ jsonValidationService.validateContentSchema({
72
+ type: 'object',
73
+ properties: {
74
+ foo: {
75
+ type: 'array',
76
+ items: {
77
+ type: 'object',
78
+ properties: {
79
+ bar: {
80
+ type: 'FormattedText',
81
+ },
82
+ },
83
+ required: ['bar'],
84
+ },
85
+ },
86
+ },
87
+ required: ['foo'],
88
+ }),
89
+ ).not.toThrowError();
90
+ });
91
+
92
+ it('should error if any nested object does not have a required property', () => {
93
+ expect(() =>
94
+ jsonValidationService.validateContentSchema({
95
+ type: 'object',
96
+ properties: {
97
+ foo: {
98
+ type: 'array',
99
+ items: {
100
+ type: 'object',
101
+ properties: {
102
+ bar: {
103
+ type: 'FormattedText',
104
+ },
105
+ },
106
+ },
107
+ },
108
+ },
109
+ required: ['foo'],
110
+ }),
111
+ ).toThrowError();
112
+ });
113
+
114
+ it('should succeed if required is on every nested object', () => {
115
+ expect(() =>
116
+ jsonValidationService.validateContentSchema({
117
+ type: 'object',
118
+ properties: {
119
+ foo: {
120
+ type: 'array',
121
+ items: {
122
+ type: 'object',
123
+ properties: {
124
+ bar: {
125
+ type: 'FormattedText',
126
+ },
127
+ },
128
+ required: ['bar'],
129
+ },
130
+ },
131
+ },
132
+ required: ['foo'],
133
+ }),
134
+ ).not.toThrowError();
135
+ });
136
+ });
@@ -0,0 +1,165 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "DxContentMetaSchema.json",
4
+ "title": "Core schema meta-schema",
5
+ "definitions": {
6
+ "schemaArray": {
7
+ "type": "array",
8
+ "minItems": 1,
9
+ "items": { "$ref": "#" }
10
+ },
11
+ "nonNegativeInteger": {
12
+ "type": "integer",
13
+ "minimum": 0
14
+ },
15
+ "nonNegativeIntegerDefault0": {
16
+ "allOf": [{ "$ref": "#/definitions/nonNegativeInteger" }, { "default": 0 }]
17
+ },
18
+ "simpleTypes": {
19
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string", "FormattedText"]
20
+ },
21
+ "stringArray": {
22
+ "type": "array",
23
+ "items": { "type": "string" },
24
+ "uniqueItems": true,
25
+ "default": []
26
+ }
27
+ },
28
+ "type": ["object", "boolean"],
29
+ "properties": {
30
+ "$id": {
31
+ "type": "string",
32
+ "format": "uri-reference"
33
+ },
34
+ "$schema": {
35
+ "type": "string",
36
+ "format": "uri"
37
+ },
38
+ "$ref": {
39
+ "type": "string",
40
+ "format": "uri-reference"
41
+ },
42
+ "$comment": {
43
+ "type": "string"
44
+ },
45
+ "title": {
46
+ "type": "string"
47
+ },
48
+ "description": {
49
+ "type": "string"
50
+ },
51
+ "default": true,
52
+ "readOnly": {
53
+ "type": "boolean",
54
+ "default": false
55
+ },
56
+ "writeOnly": {
57
+ "type": "boolean",
58
+ "default": false
59
+ },
60
+ "examples": {
61
+ "type": "array",
62
+ "items": true
63
+ },
64
+ "multipleOf": {
65
+ "type": "number",
66
+ "exclusiveMinimum": 0
67
+ },
68
+ "maximum": {
69
+ "type": "number"
70
+ },
71
+ "exclusiveMaximum": {
72
+ "type": "number"
73
+ },
74
+ "minimum": {
75
+ "type": "number"
76
+ },
77
+ "exclusiveMinimum": {
78
+ "type": "number"
79
+ },
80
+ "maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
81
+ "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
82
+ "pattern": {
83
+ "type": "string",
84
+ "format": "regex"
85
+ },
86
+ "additionalItems": { "$ref": "#" },
87
+ "items": {
88
+ "anyOf": [{ "$ref": "#" }, { "$ref": "#/definitions/schemaArray" }],
89
+ "default": true
90
+ },
91
+ "maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
92
+ "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
93
+ "uniqueItems": {
94
+ "type": "boolean",
95
+ "default": false
96
+ },
97
+ "contains": { "$ref": "#" },
98
+ "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
99
+ "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
100
+ "required": { "$ref": "#/definitions/stringArray" },
101
+ "additionalProperties": { "$ref": "#" },
102
+ "definitions": {
103
+ "type": "object",
104
+ "additionalProperties": { "$ref": "#" },
105
+ "default": {}
106
+ },
107
+ "properties": {
108
+ "type": "object",
109
+ "additionalProperties": { "$ref": "#" },
110
+ "default": {}
111
+ },
112
+ "patternProperties": {
113
+ "type": "object",
114
+ "additionalProperties": { "$ref": "#" },
115
+ "propertyNames": { "format": "regex" },
116
+ "default": {}
117
+ },
118
+ "dependencies": {
119
+ "type": "object",
120
+ "additionalProperties": {
121
+ "anyOf": [{ "$ref": "#" }, { "$ref": "#/definitions/stringArray" }]
122
+ }
123
+ },
124
+ "propertyNames": { "$ref": "#" },
125
+ "const": true,
126
+ "enum": {
127
+ "type": "array",
128
+ "items": true,
129
+ "minItems": 1,
130
+ "uniqueItems": true
131
+ },
132
+ "type": {
133
+ "anyOf": [
134
+ { "$ref": "#/definitions/simpleTypes" },
135
+ {
136
+ "type": "array",
137
+ "items": { "$ref": "#/definitions/simpleTypes" },
138
+ "minItems": 1,
139
+ "uniqueItems": true
140
+ }
141
+ ]
142
+ },
143
+ "format": { "type": "string" },
144
+ "contentMediaType": { "type": "string" },
145
+ "contentEncoding": { "type": "string" },
146
+ "if": { "$ref": "#" },
147
+ "then": { "$ref": "#" },
148
+ "else": { "$ref": "#" },
149
+ "allOf": { "$ref": "#/definitions/schemaArray" },
150
+ "anyOf": { "$ref": "#/definitions/schemaArray" },
151
+ "oneOf": { "$ref": "#/definitions/schemaArray" },
152
+ "not": { "$ref": "#" }
153
+ },
154
+ "additionalProperties": false,
155
+ "dependencies": {
156
+ "properties": {
157
+ "properties": {
158
+ "required": {
159
+ "$ref": "#/definitions/stringArray"
160
+ }
161
+ },
162
+ "required": ["required"]
163
+ }
164
+ }
165
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "$schema": "../../v1.json",
3
+ "description": "t",
4
+ "displayName": "t",
5
+ "name": "test",
6
+ "namespace": "other",
7
+ "mainFunction": "main",
8
+ "version": "1.0.4",
9
+ "environment": [],
10
+ "functions": [
11
+ {
12
+ "entry": "main.js",
13
+ "name": "main",
14
+ "output": {
15
+ "responseType": "html"
16
+ },
17
+ "input": {
18
+ "type": "object",
19
+ "properties": {
20
+ "textValue": {
21
+ "type": "badInputType"
22
+ },
23
+ "anotherValue": {
24
+ "type": "object",
25
+ "properties": {
26
+ "xt": {
27
+ "type": "FormattedText"
28
+ }
29
+ },
30
+ "additionalProperties": {
31
+ "type": "FormattedText"
32
+ }
33
+ }
34
+ },
35
+ "required": []
36
+ }
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "$schema": "../../v1.json",
3
+ "description": "t",
4
+ "displayName": "t",
5
+ "name": "test",
6
+ "namespace": "other",
7
+ "mainFunction": "main",
8
+ "version": "1.0.4",
9
+ "environment": [],
10
+ "functions": [
11
+ {
12
+ "entry": "main.js",
13
+ "name": "main",
14
+ "output": {
15
+ "responseType": "html"
16
+ },
17
+ "input": {
18
+ "type": "object",
19
+ "properties": {
20
+ "textValue": {
21
+ "type": "string"
22
+ },
23
+ "anotherValue": {
24
+ "type": "object",
25
+ "properties": {
26
+ "xt": {
27
+ "type": "astd"
28
+ }
29
+ },
30
+ "additionalProperties": {
31
+ "type": "FormattedText"
32
+ }
33
+ }
34
+ },
35
+ "required": []
36
+ }
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "$schema": "../../v1.json",
3
+ "description": "t",
4
+ "displayName": "t",
5
+ "name": "test",
6
+ "namespace": "other",
7
+ "mainFunction": "main",
8
+ "version": "1.0.4",
9
+ "environment": [],
10
+ "functions": [
11
+ {
12
+ "entry": "main.js",
13
+ "name": "main",
14
+ "output": {
15
+ "responseType": "html"
16
+ },
17
+ "input": {
18
+ "type": "string",
19
+ "properties": {
20
+ "textValue": {
21
+ "type": "FormattedText"
22
+ },
23
+ "anotherValue": {
24
+ "type": "object",
25
+ "properties": {
26
+ "xt": {
27
+ "type": "FormattedText"
28
+ }
29
+ },
30
+ "additionalProperties": {
31
+ "type": "FormattedText"
32
+ }
33
+ }
34
+ },
35
+ "required": []
36
+ }
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "$schema": "../../v1.json",
3
+ "description": "t",
4
+ "displayName": "t",
5
+ "name": "test",
6
+ "namespace": "other",
7
+ "mainFunction": "main",
8
+ "version": "1.0.4",
9
+ "environment": [],
10
+ "functions": [
11
+ {
12
+ "entry": "main.js",
13
+ "name": "main",
14
+ "output": {
15
+ "responseType": "html"
16
+ },
17
+ "input": {
18
+ "type": "object",
19
+ "properties": {
20
+ "textValue": {
21
+ "type": "FormattedText"
22
+ },
23
+ "anotherValue": {
24
+ "type": "object",
25
+ "properties": {
26
+ "xt": {
27
+ "type": "FormattedText"
28
+ }
29
+ },
30
+ "required": [],
31
+ "additionalProperties": {
32
+ "type": "FormattedText"
33
+ }
34
+ }
35
+ },
36
+ "required": []
37
+ }
38
+ }
39
+ ]
40
+ }
@@ -0,0 +1 @@
1
+ export * as v1 from './v1';
@@ -0,0 +1,3 @@
1
+ import v1 from './v1.json';
2
+
3
+ export { v1 };
@@ -0,0 +1,5 @@
1
+ import DxComponentIcons from './DxComponentIcons.json';
2
+ import DxComponentInputSchema from './DxComponentInputSchema.json';
3
+ import DxContentMetaSchema from './DxContentMetaSchema.json';
4
+
5
+ export { DxComponentIcons, DxComponentInputSchema, DxContentMetaSchema };