@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
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [1.2.13-alpha.0](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.13-alpha.0) (2023-01-13)
7
+
8
+ **Note:** Version bump only for package @squiz/dx-json-schema-lib
package/jest.config.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { Config } from 'jest';
2
+
3
+ import { config as configFunc } from 'dotenv';
4
+ configFunc();
5
+
6
+ // Sync object
7
+ const config: Config = {
8
+ preset: 'ts-jest',
9
+ testEnvironment: 'node',
10
+ testPathIgnorePatterns: [
11
+ '<rootDir>/lib/',
12
+ '<rootDir>/cdk.out/',
13
+ 'test.ts',
14
+ '/integration-tests/',
15
+ '.*\\.integration\\.spec\\.ts$',
16
+ ],
17
+ maxWorkers: '80%',
18
+ };
19
+
20
+ export default config;
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ import * as path from 'path';
3
+ import { compileFromFile } from 'json-schema-to-typescript';
4
+ import { writeFile } from 'fs/promises';
5
+
6
+ const files = ['src/manifest/v1/v1.json', 'src/formatted-text/v1/formattedText.json'];
7
+
8
+ (async function main() {
9
+ for (const file of files) {
10
+ const fullPath = path.resolve(__dirname, file);
11
+ const directory = path.dirname(fullPath);
12
+ const filename = path.basename(fullPath, '.json');
13
+
14
+ const output = await compileFromFile(fullPath, {
15
+ cwd: directory,
16
+ ignoreMinAndMaxItems: true,
17
+ style: { singleQuote: true },
18
+ });
19
+
20
+ await writeFile(path.join(directory, `${filename}.ts`), output);
21
+ }
22
+ })();
@@ -0,0 +1,9 @@
1
+ import Ajv, { AnySchemaObject, SchemaObject } from 'ajv';
2
+ export declare class JsonValidationService {
3
+ ajv: Ajv;
4
+ constructor();
5
+ validateManifest(manifest: unknown, version: 'v1'): true;
6
+ validateContentSchema(contentSchema: AnySchemaObject): true;
7
+ validateComponentInput(functionInputSchema: SchemaObject, inputValue: unknown): true;
8
+ private doValidate;
9
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.JsonValidationService = void 0;
7
+ const ajv_1 = __importDefault(require("ajv"));
8
+ const ajv_formats_1 = __importDefault(require("ajv-formats"));
9
+ const better_ajv_errors_1 = __importDefault(require("better-ajv-errors"));
10
+ const DxComponentInputSchema_json_1 = __importDefault(require("./manifest/v1/DxComponentInputSchema.json"));
11
+ const DxComponentIcons_json_1 = __importDefault(require("./manifest/v1/DxComponentIcons.json"));
12
+ const DxContentMetaSchema_json_1 = __importDefault(require("./manifest/v1/DxContentMetaSchema.json"));
13
+ const v1_json_1 = __importDefault(require("./manifest/v1/v1.json"));
14
+ const SchemaValidationError_1 = require("./errors/SchemaValidationError");
15
+ class JsonValidationService {
16
+ constructor() {
17
+ this.ajv = new ajv_1.default({
18
+ strict: true,
19
+ schemas: { DxContentMetaSchema: DxContentMetaSchema_json_1.default, v1: v1_json_1.default, DxComponentIcons: DxComponentIcons_json_1.default, DxComponentInputSchema: DxComponentInputSchema_json_1.default },
20
+ allowUnionTypes: true,
21
+ allErrors: true,
22
+ formats: {
23
+ 'multi-line': true,
24
+ },
25
+ });
26
+ (0, ajv_formats_1.default)(this.ajv);
27
+ }
28
+ validateManifest(manifest, version) {
29
+ switch (version) {
30
+ case 'v1':
31
+ return this.doValidate(v1_json_1.default, manifest);
32
+ default:
33
+ throw new Error('Invalid manifest version');
34
+ }
35
+ }
36
+ validateContentSchema(contentSchema) {
37
+ // This schema matches the input definition in the manifest
38
+ return this.doValidate(DxComponentInputSchema_json_1.default, contentSchema);
39
+ }
40
+ validateComponentInput(functionInputSchema, inputValue) {
41
+ return this.doValidate(functionInputSchema, inputValue);
42
+ }
43
+ doValidate(schema, value) {
44
+ const result = this.ajv.validate(schema, value);
45
+ if (!result) {
46
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
47
+ const betterErrors = (0, better_ajv_errors_1.default)(schema, value, this.ajv.errors, { format: 'js' });
48
+ throw new SchemaValidationError_1.SchemaValidationError(betterErrors);
49
+ }
50
+ return result;
51
+ }
52
+ }
53
+ exports.JsonValidationService = JsonValidationService;
54
+ //# sourceMappingURL=JsonValidationService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonValidationService.js","sourceRoot":"","sources":["../src/JsonValidationService.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAyD;AACzD,8DAAqC;AACrC,0EAAgD;AAEhD,4GAA+E;AAC/E,gGAAmE;AACnE,sGAAyE;AACzE,oEAAuC;AACvC,0EAAuE;AAEvE,MAAa,qBAAqB;IAEhC;QACE,IAAI,CAAC,GAAG,GAAG,IAAI,aAAG,CAAC;YACjB,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,EAAE,mBAAmB,EAAnB,kCAAmB,EAAE,EAAE,EAAF,iBAAE,EAAE,gBAAgB,EAAhB,+BAAgB,EAAE,sBAAsB,EAAtB,qCAAsB,EAAE;YAC9E,eAAe,EAAE,IAAI;YACrB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE;gBACP,YAAY,EAAE,IAAI;aACnB;SACF,CAAC,CAAC;QAEH,IAAA,qBAAU,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IACD,gBAAgB,CAAC,QAAiB,EAAE,OAAa;QAC/C,QAAQ,OAAO,EAAE;YACf,KAAK,IAAI;gBACP,OAAO,IAAI,CAAC,UAAU,CAAC,iBAAE,EAAE,QAAQ,CAAC,CAAC;YAEvC;gBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;SAC/C;IACH,CAAC;IAED,qBAAqB,CAAC,aAA8B;QAClD,2DAA2D;QAC3D,OAAO,IAAI,CAAC,UAAU,CAAC,qCAAsB,EAAE,aAAa,CAAC,CAAC;IAChE,CAAC;IAED,sBAAsB,CAAC,mBAAiC,EAAE,UAAmB;QAC3E,OAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;IAC1D,CAAC;IAEO,UAAU,CAAC,MAA6B,EAAE,KAAc;QAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,EAAE;YACX,oEAAoE;YACpE,MAAM,YAAY,GAAG,IAAA,2BAAe,EAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,MAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YACxF,MAAM,IAAI,6CAAqB,CAAC,YAAY,CAAC,CAAC;SAC/C;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA3CD,sDA2CC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const JsonValidationService_1 = require("./JsonValidationService");
7
+ const SchemaValidationError_1 = require("./errors/SchemaValidationError");
8
+ const validComponent_json_1 = __importDefault(require("./manifest/v1/__test__/schemas/validComponent.json"));
9
+ describe('JsonValidationService', () => {
10
+ let jsonValidationService;
11
+ beforeEach(() => {
12
+ jsonValidationService = new JsonValidationService_1.JsonValidationService();
13
+ });
14
+ describe('validateManifest', () => {
15
+ it('should return true for a valid manifest', () => {
16
+ const result = jsonValidationService.validateManifest(validComponent_json_1.default, 'v1');
17
+ expect(result).toBe(true);
18
+ });
19
+ it('should throw a SchemaValidationError for an invalid manifest', () => {
20
+ const invalidManifest = { ...validComponent_json_1.default };
21
+ delete invalidManifest.name;
22
+ expect(() => {
23
+ jsonValidationService.validateManifest(invalidManifest, 'v1');
24
+ }).toThrow(SchemaValidationError_1.SchemaValidationError);
25
+ expect(() => {
26
+ jsonValidationService.validateManifest(invalidManifest, 'v1');
27
+ }).toMatchInlineSnapshot(`[Function]`);
28
+ });
29
+ it('should throw an error for an invalid manifest version', () => {
30
+ expect(() => {
31
+ jsonValidationService.validateManifest(validComponent_json_1.default, 'invalid-version');
32
+ }).toThrow(Error);
33
+ });
34
+ });
35
+ describe('validateContentSchema', () => {
36
+ it('should return true for a valid content schema', () => {
37
+ const contentSchema = {
38
+ type: 'object',
39
+ properties: {
40
+ 'my-input': { type: 'number' },
41
+ },
42
+ required: ['my-input'],
43
+ };
44
+ const result = jsonValidationService.validateContentSchema(contentSchema);
45
+ expect(result).toBe(true);
46
+ });
47
+ // TODO DEVX-658
48
+ it.skip('should return false for an invalid content schema, where the required property is missed from a child object', () => {
49
+ const contentSchema = {
50
+ type: 'object',
51
+ properties: {
52
+ 'my-input': {
53
+ type: 'object',
54
+ properties: {
55
+ 'my-deep-input': { type: 'object' },
56
+ },
57
+ },
58
+ },
59
+ required: ['my-input'],
60
+ };
61
+ expect(() => {
62
+ jsonValidationService.validateContentSchema(contentSchema);
63
+ }).toThrow(SchemaValidationError_1.SchemaValidationError);
64
+ });
65
+ it('should throw a SchemaValidationError for an invalid content schema, top level type must be object', () => {
66
+ const contentSchema = {
67
+ type: 'array',
68
+ items: {
69
+ type: 'object',
70
+ properties: {
71
+ 'my-input': { type: 'number' },
72
+ },
73
+ required: ['my-input'],
74
+ },
75
+ };
76
+ expect(() => {
77
+ jsonValidationService.validateContentSchema(contentSchema);
78
+ }).toThrow(SchemaValidationError_1.SchemaValidationError);
79
+ });
80
+ // TODO DEVX-658
81
+ it.skip('should throw a SchemaValidationError for an invalid content schema missing the required property', () => {
82
+ const contentSchema = {
83
+ type: 'object',
84
+ properties: {
85
+ 'my-input': { type: 'number' },
86
+ },
87
+ };
88
+ expect(() => {
89
+ jsonValidationService.validateContentSchema(contentSchema);
90
+ }).toThrow(SchemaValidationError_1.SchemaValidationError);
91
+ });
92
+ });
93
+ describe('validateComponentInput', () => {
94
+ const functionInputSchema = {
95
+ type: 'object',
96
+ properties: {
97
+ 'my-input': { type: 'number' },
98
+ },
99
+ required: ['my-input'],
100
+ };
101
+ it('should return true for valid input values', () => {
102
+ const inputValue = {
103
+ 'my-input': 123,
104
+ };
105
+ const result = jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
106
+ expect(result).toBe(true);
107
+ });
108
+ it('should throw a SchemaValidationError for invalid input type', () => {
109
+ const inputValue = {
110
+ 'my-input': '123',
111
+ };
112
+ expect(() => {
113
+ jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
114
+ }).toThrow(SchemaValidationError_1.SchemaValidationError);
115
+ expect(() => {
116
+ jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
117
+ }).toMatchInlineSnapshot(`[Function]`);
118
+ });
119
+ it('should throw a SchemaValidationError for invalid input missing properties', () => {
120
+ const inputValue = {};
121
+ expect(() => {
122
+ jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
123
+ }).toThrow(SchemaValidationError_1.SchemaValidationError);
124
+ expect(() => {
125
+ jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
126
+ }).toMatchInlineSnapshot(`[Function]`);
127
+ });
128
+ // TODO DEVX-658
129
+ it.skip('should throw a SchemaValidationError for invalid input additional properties', () => {
130
+ const inputValue = {
131
+ 'my-input': 123,
132
+ 'my-input-2': 123,
133
+ };
134
+ expect(() => {
135
+ jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
136
+ }).toThrow(SchemaValidationError_1.SchemaValidationError);
137
+ expect(() => {
138
+ jsonValidationService.validateComponentInput(functionInputSchema, inputValue);
139
+ }).toMatchInlineSnapshot();
140
+ });
141
+ });
142
+ });
143
+ //# sourceMappingURL=JsonValidationService.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonValidationService.spec.js","sourceRoot":"","sources":["../src/JsonValidationService.spec.ts"],"names":[],"mappings":";;;;;AAAA,mEAAgE;AAChE,0EAAuE;AAEvE,6GAA+E;AAE/E,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,IAAI,qBAA4C,CAAC;IACjD,UAAU,CAAC,GAAG,EAAE;QACd,qBAAqB,GAAG,IAAI,6CAAqB,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAChC,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;YACjD,MAAM,MAAM,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,6BAAa,EAAE,IAAI,CAAC,CAAC;YAC3E,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;YACtE,MAAM,eAAe,GAAG,EAAE,GAAG,6BAAa,EAAE,CAAC;YAE7C,OAAQ,eAAuB,CAAC,IAAI,CAAC;YAErC,MAAM,CAAC,GAAG,EAAE;gBACV,qBAAqB,CAAC,gBAAgB,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;YAChE,CAAC,CAAC,CAAC,OAAO,CAAC,6CAAqB,CAAC,CAAC;YAClC,MAAM,CAAC,GAAG,EAAE;gBACV,qBAAqB,CAAC,gBAAgB,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;YAChE,CAAC,CAAC,CAAC,q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qB,CAAC,CAAC;YAClC,MAAM,CAAC,GAAG,EAAE;gBACV,qBAAqB,CAAC,sBAAsB,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;YAChF,CAAC,CAAC,CAAC,qBAAqB,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { IOutputError } from 'better-ajv-errors';
2
+ export declare class SchemaValidationError extends Error {
3
+ constructor(validationErrors: IOutputError[], error?: Error);
4
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaValidationError = void 0;
4
+ class SchemaValidationError extends Error {
5
+ constructor(validationErrors, error) {
6
+ super(`failed validation: ${validationErrors.map((e) => e.error).join(', ')}`);
7
+ this.stack = error === null || error === void 0 ? void 0 : error.stack;
8
+ this.name = 'SchemaValidationError';
9
+ }
10
+ }
11
+ exports.SchemaValidationError = SchemaValidationError;
12
+ //# sourceMappingURL=SchemaValidationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaValidationError.js","sourceRoot":"","sources":["../../src/errors/SchemaValidationError.ts"],"names":[],"mappings":";;;AAEA,MAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,gBAAgC,EAAE,KAAa;QACzD,KAAK,CAAC,sBAAsB,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,KAAK,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAND,sDAMC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * This file was automatically generated by json-schema-to-typescript.
3
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
+ * and run json-schema-to-typescript to regenerate this file.
5
+ */
6
+ export type FormattedNodes = HigherOrderFormattedNodes | BaseFormattedNodes;
7
+ export type HigherOrderFormattedNodes = FormattedTextLinkToMatrixAsset | FormattedTextMatrixImage;
8
+ export type FormattedTextLinkToMatrixAsset = FormattedNodeWithChildren & {
9
+ type: 'link-to-matrix-asset';
10
+ matrixIdentifier?: string;
11
+ matrixDomain: string;
12
+ matrixAssetId: string;
13
+ target: '_blank' | '_self' | '_parent' | '_top';
14
+ };
15
+ export type FormattedNodeWithChildren = FormattedNode & {
16
+ children: FormattedNodes[];
17
+ };
18
+ export type FormattedTextMatrixImage = FormattedNode & {
19
+ type: 'matrix-image';
20
+ matrixIdentifier?: string;
21
+ matrixDomain: string;
22
+ matrixAssetId: string;
23
+ };
24
+ export type BaseFormattedNodes = FormattedTextTag | TextNode;
25
+ export type FormattedTextTag = FormattedNodeWithChildren & {
26
+ type: 'tag';
27
+ tag: string;
28
+ attributes?: {
29
+ [k: string]: string;
30
+ };
31
+ font?: FormattedNodeFontProperties;
32
+ };
33
+ export type FormattedText = FormattedNodes[];
34
+ export interface FormattedNode {
35
+ type: string;
36
+ formattingOptions?: {
37
+ alignment?: 'center' | 'left' | 'right' | 'justify';
38
+ };
39
+ }
40
+ export interface FormattedNodeFontProperties {
41
+ bold?: boolean;
42
+ underline?: boolean;
43
+ italics?: boolean;
44
+ color?: string;
45
+ size?: string;
46
+ fontFamily?: string;
47
+ }
48
+ export interface TextNode {
49
+ type: 'text';
50
+ value: string;
51
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ /**
4
+ * This file was automatically generated by json-schema-to-typescript.
5
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
6
+ * and run json-schema-to-typescript to regenerate this file.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=formattedText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formattedText.js","sourceRoot":"","sources":["../../../src/formatted-text/v1/formattedText.ts"],"names":[],"mappings":";AAAA,oBAAoB;AACpB;;;;GAIG"}
@@ -0,0 +1,134 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "array",
4
+ "additionalProperties": false,
5
+ "title": "FormattedText",
6
+ "items": {
7
+ "$ref": "#/definitions/FormattedNodes"
8
+ },
9
+ "definitions": {
10
+ "FormattedNodes": {
11
+ "anyOf": [{ "$ref": "#/definitions/HigherOrderFormattedNodes" }, { "$ref": "#/definitions/BaseFormattedNodes" }]
12
+ },
13
+ "HigherOrderFormattedNodes": {
14
+ "anyOf": [
15
+ { "$ref": "#/definitions/FormattedTextLinkToMatrixAsset" },
16
+ { "$ref": "#/definitions/FormattedTextMatrixImage" }
17
+ ]
18
+ },
19
+ "BaseFormattedNodes": {
20
+ "anyOf": [{ "$ref": "#/definitions/FormattedTextTag" }, { "$ref": "#/definitions/TextNode" }]
21
+ },
22
+ "TextNode": {
23
+ "type": "object",
24
+ "additionalProperties": false,
25
+ "properties": {
26
+ "type": { "const": "text" },
27
+ "value": { "type": "string" }
28
+ },
29
+ "required": ["type", "value"]
30
+ },
31
+ "FormattedNode": {
32
+ "type": "object",
33
+ "properties": {
34
+ "type": { "type": "string" },
35
+ "formattingOptions": {
36
+ "type": "object",
37
+ "additionalProperties": false,
38
+ "properties": {
39
+ "alignment": {
40
+ "type": "string",
41
+ "enum": ["center", "left", "right", "justify"]
42
+ }
43
+ }
44
+ }
45
+ },
46
+ "required": ["type"],
47
+ "additionalProperties": false
48
+ },
49
+ "FormattedNodeWithChildren": {
50
+ "type": "object",
51
+ "additionalProperties": false,
52
+ "allOf": [
53
+ { "$ref": "#/definitions/FormattedNode" },
54
+ {
55
+ "type": "object",
56
+ "additionalProperties": false,
57
+ "properties": {
58
+ "children": {
59
+ "type": "array",
60
+ "items": {
61
+ "$ref": "#/definitions/FormattedNodes"
62
+ }
63
+ }
64
+ },
65
+ "required": ["children"]
66
+ }
67
+ ]
68
+ },
69
+ "FormattedTextTag": {
70
+ "allOf": [
71
+ { "$ref": "#/definitions/FormattedNodeWithChildren" },
72
+ {
73
+ "type": "object",
74
+ "additionalProperties": false,
75
+ "properties": {
76
+ "type": { "const": "tag" },
77
+ "tag": { "type": "string", "minLength": 1 },
78
+ "attributes": {
79
+ "type": "object",
80
+ "additionalProperties": { "type": "string" }
81
+ },
82
+ "font": {
83
+ "title": "FormattedNodeFontProperties",
84
+ "type": "object",
85
+ "additionalProperties": false,
86
+ "properties": {
87
+ "bold": { "type": "boolean" },
88
+ "underline": { "type": "boolean" },
89
+ "italics": { "type": "boolean" },
90
+ "color": { "type": "string" },
91
+ "size": { "type": "string" },
92
+ "fontFamily": { "type": "string" }
93
+ }
94
+ }
95
+ },
96
+ "required": ["type", "tag"]
97
+ }
98
+ ]
99
+ },
100
+ "FormattedTextLinkToMatrixAsset": {
101
+ "allOf": [
102
+ { "$ref": "#/definitions/FormattedNodeWithChildren" },
103
+ {
104
+ "type": "object",
105
+ "additionalProperties": false,
106
+ "properties": {
107
+ "type": { "const": "link-to-matrix-asset" },
108
+ "matrixIdentifier": { "type": "string", "minLength": 1 },
109
+ "matrixDomain": { "type": "string", "minLength": 1 },
110
+ "matrixAssetId": { "type": "string", "minLength": 1 },
111
+ "target": { "type": "string", "enum": ["_blank", "_self", "_parent", "_top"] }
112
+ },
113
+ "required": ["type", "matrixDomain", "matrixAssetId", "target"]
114
+ }
115
+ ]
116
+ },
117
+ "FormattedTextMatrixImage": {
118
+ "allOf": [
119
+ { "$ref": "#/definitions/FormattedNode" },
120
+ {
121
+ "type": "object",
122
+ "additionalProperties": false,
123
+ "properties": {
124
+ "type": { "const": "matrix-image" },
125
+ "matrixIdentifier": { "type": "string", "minLength": 1 },
126
+ "matrixDomain": { "type": "string", "minLength": 1 },
127
+ "matrixAssetId": { "type": "string", "minLength": 1 }
128
+ },
129
+ "required": ["type", "matrixDomain", "matrixAssetId"]
130
+ }
131
+ ]
132
+ }
133
+ }
134
+ }
@@ -0,0 +1 @@
1
+ export * as v1 from './formattedText';
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.v1 = void 0;
27
+ exports.v1 = __importStar(require("./formattedText"));
28
+ //# sourceMappingURL=formattedTextModels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formattedTextModels.js","sourceRoot":"","sources":["../../../src/formatted-text/v1/formattedTextModels.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAsC"}
@@ -0,0 +1,2 @@
1
+ import v1 from './formattedText.json';
2
+ export { v1 };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.v1 = void 0;
7
+ const formattedText_json_1 = __importDefault(require("./formattedText.json"));
8
+ exports.v1 = formattedText_json_1.default;
9
+ //# sourceMappingURL=formattedTextSchemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formattedTextSchemas.js","sourceRoot":"","sources":["../../../src/formatted-text/v1/formattedTextSchemas.ts"],"names":[],"mappings":";;;;;;AAAA,8EAAsC;AAE7B,aAFF,4BAAE,CAEE"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * as MANIFEST_MODELS from './manifest/v1/manifestModels';
2
+ export * as MANIFEST_SCHEMAS from './manifest/v1/manifestSchemas';
3
+ export * as FORMATTED_TEXT_MODELS from './formatted-text/v1/formattedTextModels';
4
+ export * as FORMATTED_TEXT_SCHEMAS from './formatted-text/v1/formattedTextSchemas';
5
+ export * as SUB_SCHEMAS from './manifest/v1/subSchemas';
6
+ export * from './JsonValidationService';
7
+ export * from './errors/SchemaValidationError';
package/lib/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.SUB_SCHEMAS = exports.FORMATTED_TEXT_SCHEMAS = exports.FORMATTED_TEXT_MODELS = exports.MANIFEST_SCHEMAS = exports.MANIFEST_MODELS = void 0;
30
+ exports.MANIFEST_MODELS = __importStar(require("./manifest/v1/manifestModels"));
31
+ exports.MANIFEST_SCHEMAS = __importStar(require("./manifest/v1/manifestSchemas"));
32
+ exports.FORMATTED_TEXT_MODELS = __importStar(require("./formatted-text/v1/formattedTextModels"));
33
+ exports.FORMATTED_TEXT_SCHEMAS = __importStar(require("./formatted-text/v1/formattedTextSchemas"));
34
+ exports.SUB_SCHEMAS = __importStar(require("./manifest/v1/subSchemas"));
35
+ __exportStar(require("./JsonValidationService"), exports);
36
+ __exportStar(require("./errors/SchemaValidationError"), exports);
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gFAAgE;AAChE,kFAAkE;AAElE,iGAAiF;AACjF,mGAAmF;AAEnF,wEAAwD;AAExD,0DAAwC;AACxC,iEAA+C"}