@squiz/dx-json-schema-lib 1.85.1 → 1.85.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 +6 -0
- package/README.md +11 -0
- package/jest.integration.config.ts +26 -0
- package/jsonCompiler.ts +35 -2
- package/lib/JsonSchemaService.js +8 -7
- package/lib/JsonSchemaService.js.map +1 -1
- package/lib/JsonValidationService.d.ts +3 -2
- package/lib/JsonValidationService.js +21 -91
- package/lib/JsonValidationService.js.map +1 -1
- package/lib/defaultDraftConfig.d.ts +2 -0
- package/lib/defaultDraftConfig.js +81 -0
- package/lib/defaultDraftConfig.js.map +1 -0
- package/lib/formatted-text/v1/formattedTextConstants.d.ts +2 -0
- package/lib/formatted-text/v1/formattedTextConstants.js +6 -0
- package/lib/formatted-text/v1/formattedTextConstants.js.map +1 -0
- package/lib/formatted-text/v1/resolveFormattedTextNodes.d.ts +2 -2
- package/lib/formatted-text/v1/resolveFormattedTextNodes.js +3 -2
- package/lib/formatted-text/v1/resolveFormattedTextNodes.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/manifest/userApi/v1/UserApiManifestV1.d.ts +48 -0
- package/lib/manifest/userApi/v1/UserApiManifestV1.js +9 -0
- package/lib/manifest/userApi/v1/UserApiManifestV1.js.map +1 -0
- package/lib/manifest/userApi/v1/UserApiManifestV1.json +76 -0
- package/lib/manifest/userApi/v1/index.d.ts +2 -0
- package/lib/manifest/userApi/v1/index.js +8 -0
- package/lib/manifest/userApi/v1/index.js.map +1 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-endpoint-extra-public.manifest.json +10 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-endpoint-handler-hyphen.manifest.json +9 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-endpoint-handler-leading-digit.manifest.json +9 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-endpoint-method-invalid.manifest.json +9 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-endpoint-missing-method.manifest.json +8 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-endpoint-missing-path.manifest.json +8 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-full-displayName-empty.manifest.json +16 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-full-manifest-not-object.manifest.json +8 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-full-missing-manifest.manifest.json +7 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-full-missing-schema.manifest.json +15 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-full-name-empty.manifest.json +16 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-full-root-extra-property.manifest.json +17 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-nested-manifest-handlerMap.manifest.json +12 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-nested-manifest-name.manifest.json +10 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-resolved-empty-endpoints.manifest.json +4 -0
- package/lib/manifest/userApi/v1/integration-fixtures/invalid-resolved-no-leading-slash.manifest.json +11 -0
- package/lib/manifest/userApi/v1/integration-fixtures/valid-full-each-http-method.manifest.json +18 -0
- package/lib/manifest/userApi/v1/integration-fixtures/valid-full-no-description.manifest.json +16 -0
- package/lib/manifest/userApi/v1/integration-fixtures/valid-full.manifest.json +22 -0
- package/lib/manifest/userApi/v1/integration-fixtures/valid-resolved-slash-path.manifest.json +14 -0
- package/lib/manifest/userApi/v1/integration-fixtures/valid-resolved.manifest.json +14 -0
- package/lib/manifest/userApi/v1/userApiManifest.integration.spec.d.ts +1 -0
- package/lib/manifest/userApi/v1/userApiManifest.integration.spec.js +201 -0
- package/lib/manifest/userApi/v1/userApiManifest.integration.spec.js.map +1 -0
- package/lib/manifest/userApi/v1/userApiManifestValidation.d.ts +16 -0
- package/lib/manifest/userApi/v1/userApiManifestValidation.js +88 -0
- package/lib/manifest/userApi/v1/userApiManifestValidation.js.map +1 -0
- package/lib/manifest/userApi/v1/userApiManifestValidation.spec.d.ts +1 -0
- package/lib/manifest/userApi/v1/userApiManifestValidation.spec.js +237 -0
- package/lib/manifest/userApi/v1/userApiManifestValidation.spec.js.map +1 -0
- package/package.json +11 -1
- package/src/JsonSchemaService.ts +2 -1
- package/src/JsonValidationService.ts +9 -96
- package/src/defaultDraftConfig.ts +89 -0
- package/src/formatted-text/v1/formattedTextConstants.ts +2 -0
- package/src/formatted-text/v1/resolveFormattedTextNodes.ts +3 -2
- package/src/index.ts +2 -0
- package/src/manifest/userApi/v1/UserApiManifestV1.json +76 -0
- package/src/manifest/userApi/v1/UserApiManifestV1.ts +50 -0
- package/src/manifest/userApi/v1/index.ts +6 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-endpoint-extra-public.manifest.json +10 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-endpoint-handler-hyphen.manifest.json +9 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-endpoint-handler-leading-digit.manifest.json +9 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-endpoint-method-invalid.manifest.json +9 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-endpoint-missing-method.manifest.json +8 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-endpoint-missing-path.manifest.json +8 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-full-displayName-empty.manifest.json +16 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-full-manifest-not-object.manifest.json +8 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-full-missing-manifest.manifest.json +7 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-full-missing-schema.manifest.json +15 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-full-name-empty.manifest.json +16 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-full-root-extra-property.manifest.json +17 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-nested-manifest-handlerMap.manifest.json +12 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-nested-manifest-name.manifest.json +10 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-resolved-empty-endpoints.manifest.json +4 -0
- package/src/manifest/userApi/v1/integration-fixtures/invalid-resolved-no-leading-slash.manifest.json +11 -0
- package/src/manifest/userApi/v1/integration-fixtures/valid-full-each-http-method.manifest.json +18 -0
- package/src/manifest/userApi/v1/integration-fixtures/valid-full-no-description.manifest.json +16 -0
- package/src/manifest/userApi/v1/integration-fixtures/valid-full.manifest.json +22 -0
- package/src/manifest/userApi/v1/integration-fixtures/valid-resolved-slash-path.manifest.json +14 -0
- package/src/manifest/userApi/v1/integration-fixtures/valid-resolved.manifest.json +14 -0
- package/src/manifest/userApi/v1/userApiManifest.integration.spec.ts +265 -0
- package/src/manifest/userApi/v1/userApiManifestValidation.spec.ts +311 -0
- package/src/manifest/userApi/v1/userApiManifestValidation.ts +54 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.USER_API_FULL_MANIFEST_SCHEMA = exports.USER_API_MANIFEST_SCHEMA_URL = void 0;
|
|
40
|
+
exports.validateUserApiFullManifest = validateUserApiFullManifest;
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const Draft_07_json_1 = __importDefault(require("../../v1/Draft-07.json"));
|
|
44
|
+
const UserApiManifestV1_json_1 = __importDefault(require("./UserApiManifestV1.json"));
|
|
45
|
+
const JsonSchemaService_1 = require("../../../JsonSchemaService");
|
|
46
|
+
const TypeResolverBuilder_1 = require("../../../jsonTypeResolution/TypeResolverBuilder");
|
|
47
|
+
const pkgVersion = (() => {
|
|
48
|
+
try {
|
|
49
|
+
const pkgPath = path.join(__dirname, '..', '..', '..', '..', 'package.json');
|
|
50
|
+
const raw = fs.readFileSync(pkgPath, 'utf8');
|
|
51
|
+
return JSON.parse(raw).version;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
const draft07Remotes = {
|
|
58
|
+
'http://json-schema.org/draft-07/schema': Draft_07_json_1.default,
|
|
59
|
+
'http://json-schema.org/draft-07/schema#': Draft_07_json_1.default,
|
|
60
|
+
};
|
|
61
|
+
const fullManifestMetaSchema = {
|
|
62
|
+
root: UserApiManifestV1_json_1.default,
|
|
63
|
+
remotes: draft07Remotes,
|
|
64
|
+
};
|
|
65
|
+
const resolver = TypeResolverBuilder_1.TypeResolverBuilder.new().build();
|
|
66
|
+
const fullManifestValidator = new JsonSchemaService_1.JSONSchemaService(resolver, fullManifestMetaSchema);
|
|
67
|
+
/**
|
|
68
|
+
* Recommended `$schema` URL for the top-level DXP User API `manifest.json`.
|
|
69
|
+
*
|
|
70
|
+
* Published at {@link USER_API_FULL_MANIFEST_SCHEMA} under `lib/manifest/userApiManifest/UserApiManifestV1.json`.
|
|
71
|
+
*/
|
|
72
|
+
exports.USER_API_MANIFEST_SCHEMA_URL = typeof pkgVersion === 'string'
|
|
73
|
+
? `https://unpkg.com/@squiz/dx-json-schema-lib@${pkgVersion}/lib/manifest/userApiManifest/UserApiManifestV1.json`
|
|
74
|
+
: 'https://unpkg.com/@squiz/dx-json-schema-lib@latest/lib/manifest/userApiManifest/UserApiManifestV1.json';
|
|
75
|
+
/**
|
|
76
|
+
* JSON Schema bundle validating the full on-disk manifest (CLI / zip upload).
|
|
77
|
+
*/
|
|
78
|
+
var UserApiManifestV1_json_2 = require("./UserApiManifestV1.json");
|
|
79
|
+
Object.defineProperty(exports, "USER_API_FULL_MANIFEST_SCHEMA", { enumerable: true, get: function () { return __importDefault(UserApiManifestV1_json_2).default; } });
|
|
80
|
+
/**
|
|
81
|
+
* Validate the User API manifest before upload.
|
|
82
|
+
*
|
|
83
|
+
* @throws {SchemaValidationError} when validation fails.
|
|
84
|
+
*/
|
|
85
|
+
function validateUserApiFullManifest(input) {
|
|
86
|
+
return fullManifestValidator.validateInput(input);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=userApiManifestValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userApiManifestValidation.js","sourceRoot":"","sources":["../../../../src/manifest/userApi/v1/userApiManifestValidation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,kEAEC;AArDD,uCAAyB;AACzB,2CAA6B;AAC7B,2EAAmD;AACnD,sFAAyD;AACzD,kEAA+D;AAC/D,yFAAsF;AAEtF,MAAM,UAAU,GAAG,CAAC,GAAuB,EAAE;IAC3C,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QAC7E,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7C,OAAQ,IAAI,CAAC,KAAK,CAAC,GAAG,CAA0B,CAAC,OAAO,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC,EAAE,CAAC;AAEL,MAAM,cAAc,GAAG;IACrB,wCAAwC,EAAE,uBAAa;IACvD,yCAAyC,EAAE,uBAAa;CAChD,CAAC;AAEX,MAAM,sBAAsB,GAAG;IAC7B,IAAI,EAAE,gCAAiB;IACvB,OAAO,EAAE,cAAc;CACf,CAAC;AAEX,MAAM,QAAQ,GAAG,yCAAmB,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC;AAEnD,MAAM,qBAAqB,GAAG,IAAI,qCAAiB,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;AAEtF;;;;GAIG;AACU,QAAA,4BAA4B,GACvC,OAAO,UAAU,KAAK,QAAQ;IAC5B,CAAC,CAAC,+CAA+C,UAAU,sDAAsD;IACjH,CAAC,CAAC,wGAAwG,CAAC;AAE/G;;GAEG;AACH,mEAAoF;AAA3E,wJAAA,OAAO,OAAiC;AAEjD;;;;GAIG;AACH,SAAgB,2BAA2B,CAAC,KAAc;IACxD,OAAO,qBAAqB,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const userApiManifestValidation_1 = require("./userApiManifestValidation");
|
|
4
|
+
const SchemaValidationError_1 = require("../../../errors/SchemaValidationError");
|
|
5
|
+
describe('user API manifest validation', () => {
|
|
6
|
+
const validResolved = {
|
|
7
|
+
endpoints: [{ path: '/hello', method: 'GET', handler: 'index.hello' }],
|
|
8
|
+
};
|
|
9
|
+
const validFull = {
|
|
10
|
+
$schema: userApiManifestValidation_1.USER_API_MANIFEST_SCHEMA_URL,
|
|
11
|
+
name: 'api',
|
|
12
|
+
displayName: 'API',
|
|
13
|
+
description: '',
|
|
14
|
+
filesDir: 'src',
|
|
15
|
+
entry: 'index.ts',
|
|
16
|
+
manifest: validResolved,
|
|
17
|
+
};
|
|
18
|
+
/** Resolves `#/definitions/resolvedApiManifest` via the full-manifest root schema only. */
|
|
19
|
+
const wrapResolved = (manifestNested) => ({
|
|
20
|
+
...validFull,
|
|
21
|
+
manifest: manifestNested,
|
|
22
|
+
});
|
|
23
|
+
const endpoint = (overrides = {}) => ({
|
|
24
|
+
path: '/r',
|
|
25
|
+
method: 'GET',
|
|
26
|
+
handler: 'handler',
|
|
27
|
+
...overrides,
|
|
28
|
+
});
|
|
29
|
+
const expectResolvedNestedThrows = (manifestNested) => {
|
|
30
|
+
expect(() => (0, userApiManifestValidation_1.validateUserApiFullManifest)(wrapResolved(manifestNested))).toThrow(SchemaValidationError_1.SchemaValidationError);
|
|
31
|
+
};
|
|
32
|
+
const expectFullThrows = (input) => {
|
|
33
|
+
expect(() => (0, userApiManifestValidation_1.validateUserApiFullManifest)(input)).toThrow(SchemaValidationError_1.SchemaValidationError);
|
|
34
|
+
};
|
|
35
|
+
it('surfaces bundled full manifest schema for CDN / tooling', () => {
|
|
36
|
+
expect(userApiManifestValidation_1.USER_API_FULL_MANIFEST_SCHEMA.type).toBe('object');
|
|
37
|
+
expect(typeof userApiManifestValidation_1.USER_API_MANIFEST_SCHEMA_URL).toBe('string');
|
|
38
|
+
expect(userApiManifestValidation_1.USER_API_MANIFEST_SCHEMA_URL).toContain('dx-json-schema-lib');
|
|
39
|
+
expect(userApiManifestValidation_1.USER_API_MANIFEST_SCHEMA_URL).toContain('manifest/userApiManifest');
|
|
40
|
+
});
|
|
41
|
+
describe('nested resolvedApiManifest rules (validated only through validateUserApiFullManifest)', () => {
|
|
42
|
+
it('accepts canonical resolved manifest when nested under manifest', () => {
|
|
43
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)(wrapResolved(validResolved))).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
it.each(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'])('accepts HTTP method %s', (method) => {
|
|
46
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)(wrapResolved({
|
|
47
|
+
endpoints: [endpoint({ path: `/m-${method}`, method })],
|
|
48
|
+
}))).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
it('accepts multiple endpoints without extra endpoint fields', () => {
|
|
51
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)(wrapResolved({
|
|
52
|
+
endpoints: [
|
|
53
|
+
{ path: '/a', method: 'GET', handler: 'a' },
|
|
54
|
+
{ path: '/b', method: 'POST', handler: 'mod.b' },
|
|
55
|
+
],
|
|
56
|
+
}))).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
it('rejects handlerMap on nested manifest (endpoints only)', () => {
|
|
59
|
+
expectResolvedNestedThrows({
|
|
60
|
+
endpoints: [endpoint()],
|
|
61
|
+
handlerMap: { 'index.hello': './handlers/hello.ts' },
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
it('accepts handlers using $ and nested module paths', () => {
|
|
65
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)(wrapResolved({
|
|
66
|
+
endpoints: [
|
|
67
|
+
endpoint({ handler: '$default' }),
|
|
68
|
+
endpoint({ handler: 'ns.deep_export' }),
|
|
69
|
+
endpoint({ handler: '_private' }),
|
|
70
|
+
],
|
|
71
|
+
}))).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
it('accepts path with only slash', () => {
|
|
74
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)(wrapResolved({ endpoints: [endpoint({ path: '/' })] }))).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
it('accepts api-builder prototype document (alternate $schema, endpoints-only nested manifest)', () => {
|
|
77
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)({
|
|
78
|
+
$schema: 'https://raw.githubusercontent.com/user/api-builder-prototype/main/schemas/api-builder.schema.json',
|
|
79
|
+
name: 'test-api',
|
|
80
|
+
displayName: 'Test Api',
|
|
81
|
+
description: 'An API to test the proxy endpoint',
|
|
82
|
+
entry: 'index.ts',
|
|
83
|
+
filesDir: 'src',
|
|
84
|
+
manifest: {
|
|
85
|
+
endpoints: [
|
|
86
|
+
{ path: '/hello/*', method: 'GET', handler: 'hello' },
|
|
87
|
+
{ path: '/add', method: 'GET', handler: 'add' },
|
|
88
|
+
{ path: '/user/:id/:type', method: 'GET', handler: 'user' },
|
|
89
|
+
{ path: '/proxy', method: 'GET', handler: 'proxy' },
|
|
90
|
+
{ path: '/health', method: 'GET', handler: 'health' },
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
})).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
it('rejects empty endpoints array', () => {
|
|
96
|
+
expectResolvedNestedThrows({ endpoints: [] });
|
|
97
|
+
expectFullThrows({
|
|
98
|
+
...validFull,
|
|
99
|
+
manifest: { endpoints: [] },
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
it('accepts nested manifest with only endpoints (no nested name)', () => {
|
|
103
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)(wrapResolved({
|
|
104
|
+
endpoints: [endpoint()],
|
|
105
|
+
}))).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
it('rejects nested manifest name property (nested root allows only endpoints)', () => {
|
|
108
|
+
expectResolvedNestedThrows({ name: 'nested-id', endpoints: [endpoint()] });
|
|
109
|
+
expectResolvedNestedThrows({ name: '', endpoints: [endpoint()] });
|
|
110
|
+
});
|
|
111
|
+
it('rejects missing endpoints on nested manifest', () => {
|
|
112
|
+
expectResolvedNestedThrows({ name: 'only-name' });
|
|
113
|
+
});
|
|
114
|
+
it('rejects non-array endpoints on nested manifest', () => {
|
|
115
|
+
expectResolvedNestedThrows({ endpoints: {} });
|
|
116
|
+
});
|
|
117
|
+
it('rejects nested manifest root additionalProperties', () => {
|
|
118
|
+
expectResolvedNestedThrows({ ...validResolved, extraKey: true });
|
|
119
|
+
});
|
|
120
|
+
it('rejects extra properties on an endpoint object', () => {
|
|
121
|
+
expectResolvedNestedThrows({
|
|
122
|
+
endpoints: [{ ...endpoint(), unknownFlag: true }],
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
it.each(['path', 'method', 'handler'])('rejects endpoint missing required field %s', (field) => {
|
|
126
|
+
const ep = endpoint();
|
|
127
|
+
const partial = Object.fromEntries(Object.entries(ep).filter(([k]) => k !== field));
|
|
128
|
+
expectResolvedNestedThrows({
|
|
129
|
+
endpoints: [partial],
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
it('accepts minimal endpoint objects (only path/method/handler)', () => {
|
|
133
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)(wrapResolved({
|
|
134
|
+
endpoints: [{ path: '/x', method: 'GET', handler: 'h' }],
|
|
135
|
+
}))).toBe(true);
|
|
136
|
+
});
|
|
137
|
+
it('rejects paths without a leading slash', () => {
|
|
138
|
+
expectResolvedNestedThrows({
|
|
139
|
+
endpoints: [endpoint({ path: 'no-leading-slash' })],
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
it('rejects invalid HTTP methods', () => {
|
|
143
|
+
expectResolvedNestedThrows({
|
|
144
|
+
endpoints: [endpoint({ method: 'TRACE' })],
|
|
145
|
+
});
|
|
146
|
+
expectResolvedNestedThrows({
|
|
147
|
+
endpoints: [endpoint({ method: 'get' })],
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
it.each([
|
|
151
|
+
{ handler: '', reason: 'empty handler' },
|
|
152
|
+
{ handler: '9start', reason: 'leading digit' },
|
|
153
|
+
{ handler: 'bad-handler', reason: 'hyphen' },
|
|
154
|
+
{ handler: 'a b', reason: 'space' },
|
|
155
|
+
{ handler: '😀', reason: 'non-ASCII' },
|
|
156
|
+
])('rejects invalid handler ($reason)', ({ handler }) => {
|
|
157
|
+
expectResolvedNestedThrows({
|
|
158
|
+
endpoints: [endpoint({ handler })],
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
it('rejects invalid nested manifest object shapes', () => {
|
|
162
|
+
expectFullThrows(wrapResolved({}));
|
|
163
|
+
expectFullThrows({
|
|
164
|
+
...validFull,
|
|
165
|
+
manifest: [],
|
|
166
|
+
});
|
|
167
|
+
expectFullThrows({
|
|
168
|
+
...validFull,
|
|
169
|
+
manifest: 'nested',
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe('validateUserApiFullManifest (root document)', () => {
|
|
174
|
+
it('accepts canonical full manifest', () => {
|
|
175
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)(validFull)).toBe(true);
|
|
176
|
+
});
|
|
177
|
+
it('accepts omission of optional description', () => {
|
|
178
|
+
const { description: _d, ...noDesc } = validFull;
|
|
179
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)(noDesc)).toBe(true);
|
|
180
|
+
});
|
|
181
|
+
it('accepts endpoints-only nested manifest when root declares name', () => {
|
|
182
|
+
expect((0, userApiManifestValidation_1.validateUserApiFullManifest)({
|
|
183
|
+
...validFull,
|
|
184
|
+
name: 'root-name',
|
|
185
|
+
manifest: {
|
|
186
|
+
endpoints: [{ path: '/e', method: 'GET', handler: 'eh' }],
|
|
187
|
+
},
|
|
188
|
+
})).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
it('rejects missing root $schema', () => {
|
|
191
|
+
const { $schema: _drop, ...withoutSchema } = validFull;
|
|
192
|
+
expectFullThrows(withoutSchema);
|
|
193
|
+
});
|
|
194
|
+
it('rejects empty $schema string', () => {
|
|
195
|
+
expectFullThrows({ ...validFull, $schema: '' });
|
|
196
|
+
});
|
|
197
|
+
it.each([['name'], ['displayName'], ['filesDir'], ['entry'], ['manifest']])('rejects full manifest missing required field %s', (field) => {
|
|
198
|
+
const { [field]: _removed, ...rest } = validFull;
|
|
199
|
+
expectFullThrows(rest);
|
|
200
|
+
});
|
|
201
|
+
it.each([
|
|
202
|
+
['name', ''],
|
|
203
|
+
['displayName', ''],
|
|
204
|
+
['filesDir', ''],
|
|
205
|
+
['entry', ''],
|
|
206
|
+
])('rejects empty string for %s (minLength 1)', (field, value) => {
|
|
207
|
+
expectFullThrows({
|
|
208
|
+
...validFull,
|
|
209
|
+
[field]: value,
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
it('rejects root additionalProperties on full manifest', () => {
|
|
213
|
+
expectFullThrows({ ...validFull, version: '1' });
|
|
214
|
+
});
|
|
215
|
+
it('rejects nested manifest validation failures (delegates to resolved definition)', () => {
|
|
216
|
+
expectFullThrows({
|
|
217
|
+
...validFull,
|
|
218
|
+
manifest: {
|
|
219
|
+
endpoints: [endpoint(), endpoint({ handler: '$default', path: '/other' })],
|
|
220
|
+
badRootKey: true,
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
expectFullThrows({
|
|
224
|
+
...validFull,
|
|
225
|
+
manifest: { endpoints: [] },
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
it('rejects primitives instead of manifest object root', () => {
|
|
229
|
+
expectFullThrows(null);
|
|
230
|
+
expectFullThrows(undefined);
|
|
231
|
+
expectFullThrows([]);
|
|
232
|
+
expectFullThrows('manifest');
|
|
233
|
+
expectFullThrows({});
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
//# sourceMappingURL=userApiManifestValidation.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userApiManifestValidation.spec.js","sourceRoot":"","sources":["../../../../src/manifest/userApi/v1/userApiManifestValidation.spec.ts"],"names":[],"mappings":";;AAAA,2EAIqC;AACrC,iFAA8E;AAE9E,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,MAAM,aAAa,GAAG;QACpB,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;KACvE,CAAC;IAEF,MAAM,SAAS,GAAG;QAChB,OAAO,EAAE,wDAA4B;QACrC,IAAI,EAAE,KAAK;QACX,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,EAAE;QACf,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,aAAa;KACxB,CAAC;IAEF,2FAA2F;IAC3F,MAAM,YAAY,GAAG,CAAC,cAAuC,EAAE,EAAE,CAAC,CAAC;QACjE,GAAG,SAAS;QACZ,QAAQ,EAAE,cAAc;KACzB,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,CACf,YAIK,EAAE,EACP,EAAE,CAAC,CAAC;QACJ,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,SAAS;QAClB,GAAG,SAAS;KACb,CAAC,CAAC;IAEH,MAAM,0BAA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AAC,CAAC,CAAC;QAEH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;YAC5D,gBAAgB,CAAC,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gFAAgF,EAAE,GAAG,EAAE;YACxF,gBAAgB,CAAC;gBACf,GAAG,SAAS;gBACZ,QAAQ,EAAE;oBACR,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;oBAC1E,UAAU,EAAE,IAAI;iBACjB;aACF,CAAC,CAAC;YACH,gBAAgB,CAAC;gBACf,GAAG,SAAS;gBACZ,QAAQ,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;aAC5B,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;YAC5D,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvB,gBAAgB,CAAC,SAAS,CAAC,CAAC;YAC5B,gBAAgB,CAAC,EAAE,CAAC,CAAC;YACrB,gBAAgB,CAAC,UAAU,CAAC,CAAC;YAC7B,gBAAgB,CAAC,EAAE,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squiz/dx-json-schema-lib",
|
|
3
|
-
"version": "1.85.
|
|
3
|
+
"version": "1.85.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./lib/index.d.ts",
|
|
9
|
+
"default": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./lib/*": "./lib/*",
|
|
12
|
+
"./src/*": "./src/*",
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
6
15
|
"private": false,
|
|
7
16
|
"publishConfig": {
|
|
8
17
|
"access": "public"
|
|
@@ -11,6 +20,7 @@
|
|
|
11
20
|
"compile": "tsc",
|
|
12
21
|
"precompile": "ts-node jsonCompiler.ts",
|
|
13
22
|
"test": "jest -c jest.config.ts",
|
|
23
|
+
"test:integration": "jest -c jest.integration.config.ts",
|
|
14
24
|
"test:update-snapshots": "jest -c jest.config.ts --updateSnapshot",
|
|
15
25
|
"clean": "rimraf \"tsconfig.tsbuildinfo\" \"./lib\""
|
|
16
26
|
},
|
package/src/JsonSchemaService.ts
CHANGED
|
@@ -16,7 +16,8 @@ import { draft07Config } from '@squiz/json-schema-library';
|
|
|
16
16
|
import { AnyPrimitiveType, AnyResolvableType, ResolverContext, TypeResolver } from './jsonTypeResolution/TypeResolver';
|
|
17
17
|
import { JsonResolutionError } from './errors/JsonResolutionError';
|
|
18
18
|
import { processValidationResult } from './processValidationResult';
|
|
19
|
-
import { defaultConfig
|
|
19
|
+
import { defaultConfig } from './defaultDraftConfig';
|
|
20
|
+
import { FORMATTED_TEXT_SCHEMA_ID } from './formatted-text/v1/formattedTextConstants';
|
|
20
21
|
|
|
21
22
|
export const ComponentInputMetaSchema: MetaSchemaInput = {
|
|
22
23
|
root: DxComponentInputSchema,
|
|
@@ -3,111 +3,24 @@ import DxContentMetaSchema from './manifest/v1/DxContentMetaSchema.json';
|
|
|
3
3
|
import FormattedText from './formatted-text/v1/formattedText.json';
|
|
4
4
|
|
|
5
5
|
import { SchemaValidationError } from './errors/SchemaValidationError';
|
|
6
|
-
import { Draft07, JSONSchema, Draft
|
|
6
|
+
import { Draft07, JSONSchema, Draft } from '@squiz/json-schema-library';
|
|
7
7
|
|
|
8
8
|
import { draft07Config } from '@squiz/json-schema-library';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
SquizLinkType,
|
|
16
|
-
TypeResolverBuilder,
|
|
17
|
-
} from '.';
|
|
18
|
-
import { customFormatValidators } from './validators/customFormatValidators';
|
|
19
|
-
import { customKeywordValidators } from './validators/customKeywordValidators';
|
|
9
|
+
import { FORMATTED_TEXT_SCHEMA_ID } from './formatted-text/v1/formattedTextConstants';
|
|
10
|
+
import * as MANIFEST_MODELS from './manifest/v1/manifestModels';
|
|
11
|
+
import { BaseFormattedTextType, ComponentInputFormattedTextType } from './primitiveTypes/FormattedText';
|
|
12
|
+
import { SquizImageType } from './primitiveTypes/SquizImage';
|
|
13
|
+
import { SquizLinkType } from './primitiveTypes/SquizLink';
|
|
14
|
+
import { TypeResolverBuilder } from './jsonTypeResolution/TypeResolverBuilder';
|
|
20
15
|
import {
|
|
21
16
|
ComponentInputMetaSchema,
|
|
22
17
|
JobV1MetaSchema,
|
|
23
18
|
JSONSchemaService,
|
|
24
19
|
ManifestV1MetaSchema,
|
|
25
20
|
} from './JsonSchemaService';
|
|
21
|
+
import { defaultConfig } from './defaultDraftConfig';
|
|
26
22
|
|
|
27
|
-
export
|
|
28
|
-
...draft07Config,
|
|
29
|
-
validateFormat: {
|
|
30
|
-
...draft07Config.validateFormat,
|
|
31
|
-
...customFormatValidators,
|
|
32
|
-
},
|
|
33
|
-
typeKeywords: {
|
|
34
|
-
...draft07Config.typeKeywords,
|
|
35
|
-
array: draft07Config.typeKeywords.array.concat('ui:metadata'),
|
|
36
|
-
object: draft07Config.typeKeywords.object.concat('ui:metadata'),
|
|
37
|
-
boolean: draft07Config.typeKeywords.boolean.concat('ui:metadata'),
|
|
38
|
-
string: draft07Config.typeKeywords.string.concat('ui:metadata'),
|
|
39
|
-
number: draft07Config.typeKeywords.number.concat('ui:metadata'),
|
|
40
|
-
},
|
|
41
|
-
validateKeyword: {
|
|
42
|
-
...draft07Config.validateKeyword,
|
|
43
|
-
...customKeywordValidators,
|
|
44
|
-
},
|
|
45
|
-
errors: {
|
|
46
|
-
...draft07Config.errors,
|
|
47
|
-
enumError(data) {
|
|
48
|
-
let values = '[]';
|
|
49
|
-
|
|
50
|
-
if (data.values && Array.isArray(data.values)) {
|
|
51
|
-
if (data.values.length < 5) {
|
|
52
|
-
values = `[${data.values.join(', ')}]`;
|
|
53
|
-
} else {
|
|
54
|
-
const firstFiveValues = data.values.slice(0, 5);
|
|
55
|
-
values = `[${firstFiveValues.join(', ')}, ... ${data.values.length - 5} more]`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
type: 'error',
|
|
61
|
-
name: 'EnumError',
|
|
62
|
-
code: 'enum-error',
|
|
63
|
-
message: `Expected given value \`${data.value}\` in ${data.pointer}\` to be one of \`${values}\``,
|
|
64
|
-
data,
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
anyOfError(data) {
|
|
69
|
-
let value = `Value \`${data.value}\` at`;
|
|
70
|
-
|
|
71
|
-
if (typeof data.value == 'object') {
|
|
72
|
-
value = 'Object at';
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (Array.isArray(data.value)) {
|
|
76
|
-
value = 'Array at';
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
type: 'error',
|
|
81
|
-
name: 'AnyOfError',
|
|
82
|
-
code: 'any-of-error',
|
|
83
|
-
message: `${value} \`${data.pointer}\` does not match any schema`,
|
|
84
|
-
data,
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
typeError(data) {
|
|
89
|
-
let value = `${data.value}`;
|
|
90
|
-
|
|
91
|
-
if (data.received == 'object') {
|
|
92
|
-
value = `Object ${JSON.stringify(data.value)}`;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (data.received == 'array') {
|
|
96
|
-
value = `Array ${JSON.stringify(data.value)}`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const expected = JSON.stringify(data.expected).replace(/"/g, '`');
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
type: 'error',
|
|
103
|
-
name: 'TypeError',
|
|
104
|
-
code: 'type-error',
|
|
105
|
-
message: `Expected \`${value}\` (${data.received}) in \`${data.pointer}\` to be of type ${expected}`,
|
|
106
|
-
data,
|
|
107
|
-
};
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
};
|
|
23
|
+
export { defaultConfig };
|
|
111
24
|
|
|
112
25
|
const FTSchema = new Draft07(FormattedText, defaultConfig);
|
|
113
26
|
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { draft07Config, DraftConfig } from '@squiz/json-schema-library';
|
|
2
|
+
|
|
3
|
+
import { customFormatValidators } from './validators/customFormatValidators';
|
|
4
|
+
import { customKeywordValidators } from './validators/customKeywordValidators';
|
|
5
|
+
|
|
6
|
+
export const defaultConfig: DraftConfig = {
|
|
7
|
+
...draft07Config,
|
|
8
|
+
validateFormat: {
|
|
9
|
+
...draft07Config.validateFormat,
|
|
10
|
+
...customFormatValidators,
|
|
11
|
+
},
|
|
12
|
+
typeKeywords: {
|
|
13
|
+
...draft07Config.typeKeywords,
|
|
14
|
+
array: draft07Config.typeKeywords.array.concat('ui:metadata'),
|
|
15
|
+
object: draft07Config.typeKeywords.object.concat('ui:metadata'),
|
|
16
|
+
boolean: draft07Config.typeKeywords.boolean.concat('ui:metadata'),
|
|
17
|
+
string: draft07Config.typeKeywords.string.concat('ui:metadata'),
|
|
18
|
+
number: draft07Config.typeKeywords.number.concat('ui:metadata'),
|
|
19
|
+
},
|
|
20
|
+
validateKeyword: {
|
|
21
|
+
...draft07Config.validateKeyword,
|
|
22
|
+
...customKeywordValidators,
|
|
23
|
+
},
|
|
24
|
+
errors: {
|
|
25
|
+
...draft07Config.errors,
|
|
26
|
+
enumError(data) {
|
|
27
|
+
let values = '[]';
|
|
28
|
+
|
|
29
|
+
if (data.values && Array.isArray(data.values)) {
|
|
30
|
+
if (data.values.length < 5) {
|
|
31
|
+
values = `[${data.values.join(', ')}]`;
|
|
32
|
+
} else {
|
|
33
|
+
const firstFiveValues = data.values.slice(0, 5);
|
|
34
|
+
values = `[${firstFiveValues.join(', ')}, ... ${data.values.length - 5} more]`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
type: 'error',
|
|
40
|
+
name: 'EnumError',
|
|
41
|
+
code: 'enum-error',
|
|
42
|
+
message: `Expected given value \`${data.value}\` in ${data.pointer}\` to be one of \`${values}\``,
|
|
43
|
+
data,
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
anyOfError(data) {
|
|
48
|
+
let value = `Value \`${data.value}\` at`;
|
|
49
|
+
|
|
50
|
+
if (typeof data.value == 'object') {
|
|
51
|
+
value = 'Object at';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (Array.isArray(data.value)) {
|
|
55
|
+
value = 'Array at';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
type: 'error',
|
|
60
|
+
name: 'AnyOfError',
|
|
61
|
+
code: 'any-of-error',
|
|
62
|
+
message: `${value} \`${data.pointer}\` does not match any schema`,
|
|
63
|
+
data,
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
typeError(data) {
|
|
68
|
+
let value = `${data.value}`;
|
|
69
|
+
|
|
70
|
+
if (data.received == 'object') {
|
|
71
|
+
value = `Object ${JSON.stringify(data.value)}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (data.received == 'array') {
|
|
75
|
+
value = `Array ${JSON.stringify(data.value)}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const expected = JSON.stringify(data.expected).replace(/"/g, '`');
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
type: 'error',
|
|
82
|
+
name: 'TypeError',
|
|
83
|
+
code: 'type-error',
|
|
84
|
+
message: `Expected \`${value}\` (${data.received}) in \`${data.pointer}\` to be of type ${expected}`,
|
|
85
|
+
data,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
@@ -10,6 +10,9 @@ import {
|
|
|
10
10
|
HigherOrderFormattedNodes,
|
|
11
11
|
TextNode,
|
|
12
12
|
} from './formattedText';
|
|
13
|
+
import { FORMATTED_TEXT_SCHEMA_ID } from './formattedTextConstants';
|
|
14
|
+
|
|
15
|
+
export { FORMATTED_TEXT_SCHEMA_ID };
|
|
13
16
|
|
|
14
17
|
export interface FormattedNodeWithChildren {
|
|
15
18
|
children: FormattedNode[];
|
|
@@ -25,8 +28,6 @@ export type ResolverConfig<Nodes extends FormattedNode, Output extends Resolutio
|
|
|
25
28
|
[N in Nodes as N['type']]: Resolver<N, Output>;
|
|
26
29
|
} & { default?: Resolver<FormattedNode, Output> };
|
|
27
30
|
|
|
28
|
-
export const FORMATTED_TEXT_SCHEMA_ID = 'SquizFormattedTextSchema.json';
|
|
29
|
-
|
|
30
31
|
export type ResolvedChildNode<
|
|
31
32
|
DEFAULT_NODES extends FormattedNode,
|
|
32
33
|
CHILD_NODE extends ResolutionOutput<FormattedNode>,
|