@docusaurus/utils-validation 2.0.0-beta.17 → 2.0.0-beta.18
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/lib/JoiFrontMatter.d.ts +2 -1
- package/lib/JoiFrontMatter.d.ts.map +1 -1
- package/lib/JoiFrontMatter.js +2 -1
- package/lib/JoiFrontMatter.js.map +1 -1
- package/lib/validationSchemas.d.ts.map +1 -1
- package/lib/validationSchemas.js +7 -2
- package/lib/validationSchemas.js.map +1 -1
- package/lib/validationUtils.d.ts +17 -2
- package/lib/validationUtils.d.ts.map +1 -1
- package/lib/validationUtils.js +21 -5
- package/lib/validationUtils.js.map +1 -1
- package/package.json +5 -4
- package/src/JoiFrontMatter.ts +3 -1
- package/src/validationSchemas.ts +7 -2
- package/src/validationUtils.ts +21 -6
package/lib/JoiFrontMatter.d.ts
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import Joi from './Joi';
|
|
8
8
|
/**
|
|
9
|
-
* Enhance the default Joi.string() type so that it can convert number to
|
|
9
|
+
* Enhance the default `Joi.string()` type so that it can convert number to
|
|
10
10
|
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
|
|
11
11
|
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
|
|
12
12
|
* to dates automatically.
|
|
13
|
+
*
|
|
13
14
|
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
14
15
|
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
15
16
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JoiFrontMatter.d.ts","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"JoiFrontMatter.d.ts","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AAcxB;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,GAAsC,CAAC"}
|
package/lib/JoiFrontMatter.js
CHANGED
|
@@ -21,10 +21,11 @@ const JoiFrontMatterString = {
|
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
* Enhance the default Joi.string() type so that it can convert number to
|
|
24
|
+
* Enhance the default `Joi.string()` type so that it can convert number to
|
|
25
25
|
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
|
|
26
26
|
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
|
|
27
27
|
* to dates automatically.
|
|
28
|
+
*
|
|
28
29
|
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
29
30
|
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
30
31
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JoiFrontMatter.js","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AAExB,MAAM,oBAAoB,GAAkB;IAC1C,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,aAAG,CAAC,MAAM,EAAE;IAClB,2EAA2E;IAC3E,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QACjB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,IAAI,EAAE;YACtD,OAAO,EAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAC,CAAC;SAClC;QACD,OAAO,EAAC,KAAK,EAAC,CAAC;IACjB,CAAC;CACF,CAAC;
|
|
1
|
+
{"version":3,"file":"JoiFrontMatter.js","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AAExB,MAAM,oBAAoB,GAAkB;IAC1C,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,aAAG,CAAC,MAAM,EAAE;IAClB,2EAA2E;IAC3E,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QACjB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,IAAI,EAAE;YACtD,OAAO,EAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAC,CAAC;SAClC;QACD,OAAO,EAAC,KAAK,EAAC,CAAC;IACjB,CAAC;CACF,CAAC;AAEF;;;;;;;;GAQG;AACU,QAAA,cAAc,GAAe,aAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationSchemas.d.ts","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AAKxB,eAAO,MAAM,cAAc,kBAKE,CAAC;
|
|
1
|
+
{"version":3,"file":"validationSchemas.d.ts","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AAKxB,eAAO,MAAM,cAAc,kBAKE,CAAC;AAe9B,eAAO,MAAM,mBAAmB,iBAAwB,CAAC;AACzD,eAAO,MAAM,mBAAmB,iBAAwB,CAAC;AAEzD,eAAO,MAAM,iBAAiB,uBAA2B,CAAC;AAI1D,eAAO,MAAM,SAAS,wBAgBpB,CAAC;AAEH,eAAO,MAAM,cAAc,kBASxB,CAAC;AAeJ,eAAO,MAAM,qBAAqB,iBAK9B,CAAC;AAEL,eAAO,MAAM,2BAA2B;;;CASvC,CAAC"}
|
package/lib/validationSchemas.js
CHANGED
|
@@ -12,11 +12,16 @@ const Joi_1 = tslib_1.__importDefault(require("./Joi"));
|
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
const JoiFrontMatter_1 = require("./JoiFrontMatter");
|
|
14
14
|
exports.PluginIdSchema = Joi_1.default.string()
|
|
15
|
-
.regex(/^[
|
|
15
|
+
.regex(/^[\w-]+$/)
|
|
16
16
|
.message('Illegal plugin ID value "{#value}": it should only contain alphanumerics, underscores, and dashes.')
|
|
17
17
|
.default(utils_1.DEFAULT_PLUGIN_ID);
|
|
18
18
|
const MarkdownPluginsSchema = Joi_1.default.array()
|
|
19
|
-
.items(Joi_1.default.array().ordered(Joi_1.default.function().required(), Joi_1.default.
|
|
19
|
+
.items(Joi_1.default.array().ordered(Joi_1.default.function().required(), Joi_1.default.any().required()), Joi_1.default.function(), Joi_1.default.object())
|
|
20
|
+
.messages({
|
|
21
|
+
'array.includes': `{#label} does not look like a valid MDX plugin config. A plugin config entry should be one of:
|
|
22
|
+
- A tuple, like \`[require("rehype-katex"), \\{ strict: false \\}]\`, or
|
|
23
|
+
- A simple module, like \`require("remark-math")\``,
|
|
24
|
+
})
|
|
20
25
|
.default([]);
|
|
21
26
|
exports.RemarkPluginsSchema = MarkdownPluginsSchema;
|
|
22
27
|
exports.RehypePluginsSchema = MarkdownPluginsSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationSchemas.js","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,6CAAqE;AAErE,qDAAgD;AAEnC,QAAA,cAAc,GAAG,aAAG,CAAC,MAAM,EAAE;KACvC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"validationSchemas.js","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,6CAAqE;AAErE,qDAAgD;AAEnC,QAAA,cAAc,GAAG,aAAG,CAAC,MAAM,EAAE;KACvC,KAAK,CAAC,UAAU,CAAC;KACjB,OAAO,CACN,oGAAoG,CACrG;KACA,OAAO,CAAC,yBAAiB,CAAC,CAAC;AAE9B,MAAM,qBAAqB,GAAG,aA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7
7
|
import type Joi from './Joi';
|
|
8
|
+
/** Print warnings returned from Joi validation. */
|
|
8
9
|
export declare function printWarning(warning?: Joi.ValidationError): void;
|
|
10
|
+
/**
|
|
11
|
+
* The callback that should be used to validate plugin options. Handles plugin
|
|
12
|
+
* IDs on a generic level: no matter what the schema declares, this callback
|
|
13
|
+
* would require a string ID or default to "default".
|
|
14
|
+
*/
|
|
9
15
|
export declare function normalizePluginOptions<T extends {
|
|
10
16
|
id?: string;
|
|
11
|
-
}>(schema: Joi.ObjectSchema<T>, options
|
|
17
|
+
}>(schema: Joi.ObjectSchema<T>, options?: Partial<T>): T;
|
|
18
|
+
/**
|
|
19
|
+
* The callback that should be used to validate theme config. No matter what the
|
|
20
|
+
* schema declares, this callback would allow unknown attributes.
|
|
21
|
+
*/
|
|
12
22
|
export declare function normalizeThemeConfig<T>(schema: Joi.ObjectSchema<T>, themeConfig: Partial<T>): T;
|
|
13
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Validate front matter with better error message
|
|
25
|
+
*/
|
|
26
|
+
export declare function validateFrontMatter<T>(frontMatter: {
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}, schema: Joi.ObjectSchema<T>): T;
|
|
14
29
|
//# sourceMappingURL=validationUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAK7B,mDAAmD;AACnD,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,eAAe,GAAG,IAAI,CAOhE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAC,EAC5D,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAE3B,OAAO,GAAE,OAAO,CAAC,CAAC,CAAM,GACvB,CAAC,CAiBH;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAC3B,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,GACtB,CAAC,CAgBH;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,WAAW,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,EACrC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,GAC1B,CAAC,CAuBH"}
|
package/lib/validationUtils.js
CHANGED
|
@@ -9,7 +9,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.validateFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
12
13
|
const validationSchemas_1 = require("./validationSchemas");
|
|
14
|
+
/** Print warnings returned from Joi validation. */
|
|
13
15
|
function printWarning(warning) {
|
|
14
16
|
if (warning) {
|
|
15
17
|
const warningMessages = warning.details
|
|
@@ -19,7 +21,14 @@ function printWarning(warning) {
|
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
exports.printWarning = printWarning;
|
|
22
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The callback that should be used to validate plugin options. Handles plugin
|
|
26
|
+
* IDs on a generic level: no matter what the schema declares, this callback
|
|
27
|
+
* would require a string ID or default to "default".
|
|
28
|
+
*/
|
|
29
|
+
function normalizePluginOptions(schema,
|
|
30
|
+
// This allows us to automatically normalize undefined to { id: "default" }
|
|
31
|
+
options = {}) {
|
|
23
32
|
// All plugins can be provided an "id" option (multi-instance support)
|
|
24
33
|
// we add schema validation automatically
|
|
25
34
|
const finalSchema = schema.append({
|
|
@@ -35,8 +44,12 @@ function normalizePluginOptions(schema, options) {
|
|
|
35
44
|
return value;
|
|
36
45
|
}
|
|
37
46
|
exports.normalizePluginOptions = normalizePluginOptions;
|
|
47
|
+
/**
|
|
48
|
+
* The callback that should be used to validate theme config. No matter what the
|
|
49
|
+
* schema declares, this callback would allow unknown attributes.
|
|
50
|
+
*/
|
|
38
51
|
function normalizeThemeConfig(schema, themeConfig) {
|
|
39
|
-
// A theme should only validate
|
|
52
|
+
// A theme should only validate its "slice" of the full themeConfig,
|
|
40
53
|
// not the whole object, so we allow unknown attributes
|
|
41
54
|
// otherwise one theme would fail validating the data of another theme
|
|
42
55
|
const finalSchema = schema.unknown();
|
|
@@ -50,6 +63,9 @@ function normalizeThemeConfig(schema, themeConfig) {
|
|
|
50
63
|
return value;
|
|
51
64
|
}
|
|
52
65
|
exports.normalizeThemeConfig = normalizeThemeConfig;
|
|
66
|
+
/**
|
|
67
|
+
* Validate front matter with better error message
|
|
68
|
+
*/
|
|
53
69
|
function validateFrontMatter(frontMatter, schema) {
|
|
54
70
|
const { value, error, warning } = schema.validate(frontMatter, {
|
|
55
71
|
convert: true,
|
|
@@ -58,12 +74,12 @@ function validateFrontMatter(frontMatter, schema) {
|
|
|
58
74
|
});
|
|
59
75
|
printWarning(warning);
|
|
60
76
|
if (error) {
|
|
61
|
-
const frontMatterString = JSON.stringify(frontMatter, null, 2);
|
|
62
77
|
const errorDetails = error.details;
|
|
63
78
|
const invalidFields = errorDetails.map(({ path }) => path).join(', ');
|
|
64
79
|
logger_1.default.error `The following front matter:
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
---
|
|
81
|
+
${js_yaml_1.default.dump(frontMatter)}---
|
|
82
|
+
contains invalid values for field(s): code=${invalidFields}.
|
|
67
83
|
${errorDetails.map(({ message }) => message)}
|
|
68
84
|
`;
|
|
69
85
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,wEAAwC;AACxC,2DAAmD;AAEnD,SAAgB,YAAY,CAAC,OAA6B;IACxD,IAAI,OAAO,EAAE;QACX,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO;aACpC,GAAG,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,OAAO,CAAC;aAC3B,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,gBAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;KAC9B;AACH,CAAC;AAPD,oCAOC;AAED,SAAgB,sBAAsB,CACpC,MAA2B,
|
|
1
|
+
{"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,wEAAwC;AACxC,8DAA2B;AAC3B,2DAAmD;AAEnD,mDAAmD;AACnD,SAAgB,YAAY,CAAC,OAA6B;IACxD,IAAI,OAAO,EAAE;QACX,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO;aACpC,GAAG,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,OAAO,CAAC;aAC3B,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,gBAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;KAC9B;AACH,CAAC;AAPD,oCAOC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CACpC,MAA2B;AAC3B,2EAA2E;AAC3E,UAAsB,EAAE;IAExB,sEAAsE;IACtE,yCAAyC;IACzC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;QAChC,EAAE,EAAE,kCAAc;KACnB,CAAC,CAAC;IACH,MAAM,EAAC,KAAK,EAAE,OA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I,CAAC,WAAW,CAAC;6CACqB,aAAa;EACxD,YAAY,CAAC,GAAG,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,OAAO,CAAC;CACzC,CAAC;QACE,MAAM,KAAK,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA1BD,kDA0BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils-validation",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.18",
|
|
4
4
|
"description": "Node validation utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,13 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "2.0.0-beta.
|
|
22
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
21
|
+
"@docusaurus/logger": "2.0.0-beta.18",
|
|
22
|
+
"@docusaurus/utils": "2.0.0-beta.18",
|
|
23
23
|
"joi": "^17.6.0",
|
|
24
|
+
"js-yaml": "^4.1.0",
|
|
24
25
|
"tslib": "^2.3.1"
|
|
25
26
|
},
|
|
26
27
|
"engines": {
|
|
27
28
|
"node": ">=14"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "1a945d06993d53376e61bed2c942799fe07dc336"
|
|
30
31
|
}
|
package/src/JoiFrontMatter.ts
CHANGED
|
@@ -18,11 +18,13 @@ const JoiFrontMatterString: Joi.Extension = {
|
|
|
18
18
|
return {value};
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
|
+
|
|
21
22
|
/**
|
|
22
|
-
* Enhance the default Joi.string() type so that it can convert number to
|
|
23
|
+
* Enhance the default `Joi.string()` type so that it can convert number to
|
|
23
24
|
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
|
|
24
25
|
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
|
|
25
26
|
* to dates automatically.
|
|
27
|
+
*
|
|
26
28
|
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
27
29
|
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
28
30
|
*/
|
package/src/validationSchemas.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type {Tag} from '@docusaurus/utils';
|
|
|
11
11
|
import {JoiFrontMatter} from './JoiFrontMatter';
|
|
12
12
|
|
|
13
13
|
export const PluginIdSchema = Joi.string()
|
|
14
|
-
.regex(/^[
|
|
14
|
+
.regex(/^[\w-]+$/)
|
|
15
15
|
.message(
|
|
16
16
|
'Illegal plugin ID value "{#value}": it should only contain alphanumerics, underscores, and dashes.',
|
|
17
17
|
)
|
|
@@ -19,10 +19,15 @@ export const PluginIdSchema = Joi.string()
|
|
|
19
19
|
|
|
20
20
|
const MarkdownPluginsSchema = Joi.array()
|
|
21
21
|
.items(
|
|
22
|
-
Joi.array().ordered(Joi.function().required(), Joi.
|
|
22
|
+
Joi.array().ordered(Joi.function().required(), Joi.any().required()),
|
|
23
23
|
Joi.function(),
|
|
24
24
|
Joi.object(),
|
|
25
25
|
)
|
|
26
|
+
.messages({
|
|
27
|
+
'array.includes': `{#label} does not look like a valid MDX plugin config. A plugin config entry should be one of:
|
|
28
|
+
- A tuple, like \`[require("rehype-katex"), \\{ strict: false \\}]\`, or
|
|
29
|
+
- A simple module, like \`require("remark-math")\``,
|
|
30
|
+
})
|
|
26
31
|
.default([]);
|
|
27
32
|
|
|
28
33
|
export const RemarkPluginsSchema = MarkdownPluginsSchema;
|
package/src/validationUtils.ts
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
import type Joi from './Joi';
|
|
9
9
|
import logger from '@docusaurus/logger';
|
|
10
|
+
import Yaml from 'js-yaml';
|
|
10
11
|
import {PluginIdSchema} from './validationSchemas';
|
|
11
12
|
|
|
13
|
+
/** Print warnings returned from Joi validation. */
|
|
12
14
|
export function printWarning(warning?: Joi.ValidationError): void {
|
|
13
15
|
if (warning) {
|
|
14
16
|
const warningMessages = warning.details
|
|
@@ -18,9 +20,15 @@ export function printWarning(warning?: Joi.ValidationError): void {
|
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
/**
|
|
24
|
+
* The callback that should be used to validate plugin options. Handles plugin
|
|
25
|
+
* IDs on a generic level: no matter what the schema declares, this callback
|
|
26
|
+
* would require a string ID or default to "default".
|
|
27
|
+
*/
|
|
21
28
|
export function normalizePluginOptions<T extends {id?: string}>(
|
|
22
29
|
schema: Joi.ObjectSchema<T>,
|
|
23
|
-
|
|
30
|
+
// This allows us to automatically normalize undefined to { id: "default" }
|
|
31
|
+
options: Partial<T> = {},
|
|
24
32
|
): T {
|
|
25
33
|
// All plugins can be provided an "id" option (multi-instance support)
|
|
26
34
|
// we add schema validation automatically
|
|
@@ -40,11 +48,15 @@ export function normalizePluginOptions<T extends {id?: string}>(
|
|
|
40
48
|
return value;
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
/**
|
|
52
|
+
* The callback that should be used to validate theme config. No matter what the
|
|
53
|
+
* schema declares, this callback would allow unknown attributes.
|
|
54
|
+
*/
|
|
43
55
|
export function normalizeThemeConfig<T>(
|
|
44
56
|
schema: Joi.ObjectSchema<T>,
|
|
45
57
|
themeConfig: Partial<T>,
|
|
46
58
|
): T {
|
|
47
|
-
// A theme should only validate
|
|
59
|
+
// A theme should only validate its "slice" of the full themeConfig,
|
|
48
60
|
// not the whole object, so we allow unknown attributes
|
|
49
61
|
// otherwise one theme would fail validating the data of another theme
|
|
50
62
|
const finalSchema = schema.unknown();
|
|
@@ -61,8 +73,11 @@ export function normalizeThemeConfig<T>(
|
|
|
61
73
|
return value;
|
|
62
74
|
}
|
|
63
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Validate front matter with better error message
|
|
78
|
+
*/
|
|
64
79
|
export function validateFrontMatter<T>(
|
|
65
|
-
frontMatter:
|
|
80
|
+
frontMatter: {[key: string]: unknown},
|
|
66
81
|
schema: Joi.ObjectSchema<T>,
|
|
67
82
|
): T {
|
|
68
83
|
const {value, error, warning} = schema.validate(frontMatter, {
|
|
@@ -74,13 +89,13 @@ export function validateFrontMatter<T>(
|
|
|
74
89
|
printWarning(warning);
|
|
75
90
|
|
|
76
91
|
if (error) {
|
|
77
|
-
const frontMatterString = JSON.stringify(frontMatter, null, 2);
|
|
78
92
|
const errorDetails = error.details;
|
|
79
93
|
const invalidFields = errorDetails.map(({path}) => path).join(', ');
|
|
80
94
|
|
|
81
95
|
logger.error`The following front matter:
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
---
|
|
97
|
+
${Yaml.dump(frontMatter)}---
|
|
98
|
+
contains invalid values for field(s): code=${invalidFields}.
|
|
84
99
|
${errorDetails.map(({message}) => message)}
|
|
85
100
|
`;
|
|
86
101
|
throw error;
|