@docusaurus/utils-validation 2.0.0-beta.fbdeefcac → 2.0.0-rc.1
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/Joi.d.ts +1 -0
- package/lib/Joi.d.ts.map +1 -0
- package/lib/Joi.js +1 -0
- package/lib/Joi.js.map +1 -0
- package/lib/JoiFrontMatter.d.ts +18 -0
- package/lib/JoiFrontMatter.d.ts.map +1 -0
- package/lib/JoiFrontMatter.js +33 -0
- package/lib/JoiFrontMatter.js.map +1 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +19 -5
- package/lib/index.js.map +1 -0
- package/lib/validationSchemas.d.ts +7 -1
- package/lib/validationSchemas.d.ts.map +1 -0
- package/lib/validationSchemas.js +67 -22
- package/lib/validationSchemas.js.map +1 -0
- package/lib/validationUtils.d.ts +19 -6
- package/lib/validationUtils.d.ts.map +1 -0
- package/lib/validationUtils.js +32 -63
- package/lib/validationUtils.js.map +1 -0
- package/package.json +8 -7
- package/src/JoiFrontMatter.ts +31 -0
- package/src/index.ts +17 -2
- package/src/validationSchemas.ts +82 -18
- package/src/validationUtils.ts +30 -78
- package/lib/.tsbuildinfo +0 -1
- package/src/__tests__/__snapshots__/validationSchemas.test.ts.snap +0 -63
- package/src/__tests__/validationSchemas.test.ts +0 -131
- package/src/__tests__/validationUtils.test.ts +0 -64
- package/tsconfig.json +0 -9
package/lib/Joi.d.ts
CHANGED
package/lib/Joi.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Joi.d.ts","sourceRoot":"","sources":["../src/Joi.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,KAAK,CAAC"}
|
package/lib/Joi.js
CHANGED
|
@@ -9,3 +9,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.default = void 0;
|
|
10
10
|
var joi_1 = require("joi");
|
|
11
11
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(joi_1).default; } });
|
|
12
|
+
//# sourceMappingURL=Joi.js.map
|
package/lib/Joi.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Joi.js","sourceRoot":"","sources":["../src/Joi.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2BAA4B;AAApB,+GAAA,OAAO,OAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import Joi from './Joi';
|
|
8
|
+
/**
|
|
9
|
+
* Enhance the default `Joi.string()` type so that it can convert number to
|
|
10
|
+
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
|
|
11
|
+
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
|
|
12
|
+
* to dates automatically.
|
|
13
|
+
*
|
|
14
|
+
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
15
|
+
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
16
|
+
*/
|
|
17
|
+
export declare const JoiFrontMatter: Joi.Root;
|
|
18
|
+
//# sourceMappingURL=JoiFrontMatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,UAAiD,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.JoiFrontMatter = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const Joi_1 = tslib_1.__importDefault(require("./Joi"));
|
|
12
|
+
const JoiFrontMatterString = {
|
|
13
|
+
type: 'string',
|
|
14
|
+
base: Joi_1.default.string(),
|
|
15
|
+
// Fix Yaml that tries to auto-convert many things to string out of the box
|
|
16
|
+
prepare: (value) => {
|
|
17
|
+
if (typeof value === 'number' || value instanceof Date) {
|
|
18
|
+
return { value: value.toString() };
|
|
19
|
+
}
|
|
20
|
+
return { value };
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Enhance the default `Joi.string()` type so that it can convert number to
|
|
25
|
+
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
|
|
26
|
+
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
|
|
27
|
+
* to dates automatically.
|
|
28
|
+
*
|
|
29
|
+
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
30
|
+
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
31
|
+
*/
|
|
32
|
+
exports.JoiFrontMatter = Joi_1.default.extend(JoiFrontMatterString);
|
|
33
|
+
//# sourceMappingURL=JoiFrontMatter.js.map
|
|
@@ -0,0 +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,KAAc,EAAE,EAAE;QAC1B,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,GAAG,aAAG,CAAC,MAAM,CAAC,oBAAoB,CAAe,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,5 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
export { default as Joi } from './Joi';
|
|
8
|
-
export
|
|
9
|
-
export
|
|
8
|
+
export { JoiFrontMatter } from './JoiFrontMatter';
|
|
9
|
+
export { printWarning, normalizePluginOptions, normalizeThemeConfig, validateFrontMatter, } from './validationUtils';
|
|
10
|
+
export { PluginIdSchema, RemarkPluginsSchema, RehypePluginsSchema, AdmonitionsSchema, URISchema, PathnameSchema, FrontMatterTagsSchema, FrontMatterTOCHeadingLevels, } from './validationSchemas';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAC,OAAO,IAAI,GAAG,EAAC,MAAM,OAAO,CAAC;AACrC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -6,10 +6,24 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.Joi = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
9
|
+
exports.FrontMatterTOCHeadingLevels = exports.FrontMatterTagsSchema = exports.PathnameSchema = exports.URISchema = exports.AdmonitionsSchema = exports.RehypePluginsSchema = exports.RemarkPluginsSchema = exports.PluginIdSchema = exports.validateFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning = exports.JoiFrontMatter = exports.Joi = void 0;
|
|
11
10
|
// /!\ don't remove this export, as we recommend plugin authors to use it
|
|
12
11
|
var Joi_1 = require("./Joi");
|
|
13
|
-
Object.defineProperty(exports, "Joi", { enumerable: true, get: function () { return
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
Object.defineProperty(exports, "Joi", { enumerable: true, get: function () { return __importDefault(Joi_1).default; } });
|
|
13
|
+
var JoiFrontMatter_1 = require("./JoiFrontMatter");
|
|
14
|
+
Object.defineProperty(exports, "JoiFrontMatter", { enumerable: true, get: function () { return JoiFrontMatter_1.JoiFrontMatter; } });
|
|
15
|
+
var validationUtils_1 = require("./validationUtils");
|
|
16
|
+
Object.defineProperty(exports, "printWarning", { enumerable: true, get: function () { return validationUtils_1.printWarning; } });
|
|
17
|
+
Object.defineProperty(exports, "normalizePluginOptions", { enumerable: true, get: function () { return validationUtils_1.normalizePluginOptions; } });
|
|
18
|
+
Object.defineProperty(exports, "normalizeThemeConfig", { enumerable: true, get: function () { return validationUtils_1.normalizeThemeConfig; } });
|
|
19
|
+
Object.defineProperty(exports, "validateFrontMatter", { enumerable: true, get: function () { return validationUtils_1.validateFrontMatter; } });
|
|
20
|
+
var validationSchemas_1 = require("./validationSchemas");
|
|
21
|
+
Object.defineProperty(exports, "PluginIdSchema", { enumerable: true, get: function () { return validationSchemas_1.PluginIdSchema; } });
|
|
22
|
+
Object.defineProperty(exports, "RemarkPluginsSchema", { enumerable: true, get: function () { return validationSchemas_1.RemarkPluginsSchema; } });
|
|
23
|
+
Object.defineProperty(exports, "RehypePluginsSchema", { enumerable: true, get: function () { return validationSchemas_1.RehypePluginsSchema; } });
|
|
24
|
+
Object.defineProperty(exports, "AdmonitionsSchema", { enumerable: true, get: function () { return validationSchemas_1.AdmonitionsSchema; } });
|
|
25
|
+
Object.defineProperty(exports, "URISchema", { enumerable: true, get: function () { return validationSchemas_1.URISchema; } });
|
|
26
|
+
Object.defineProperty(exports, "PathnameSchema", { enumerable: true, get: function () { return validationSchemas_1.PathnameSchema; } });
|
|
27
|
+
Object.defineProperty(exports, "FrontMatterTagsSchema", { enumerable: true, get: function () { return validationSchemas_1.FrontMatterTagsSchema; } });
|
|
28
|
+
Object.defineProperty(exports, "FrontMatterTOCHeadingLevels", { enumerable: true, get: function () { return validationSchemas_1.FrontMatterTOCHeadingLevels; } });
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yEAAyE;AACzE,6BAAqC;AAA7B,2GAAA,OAAO,OAAO;AACtB,mDAAgD;AAAxC,gHAAA,cAAc,OAAA;AAEtB,qDAK2B;AAJzB,+GAAA,YAAY,OAAA;AACZ,yHAAA,sBAAsB,OAAA;AACtB,uHAAA,oBAAoB,OAAA;AACpB,sHAAA,mBAAmB,OAAA;AAErB,yDAS6B;AAR3B,mHAAA,cAAc,OAAA;AACd,wHAAA,mBAAmB,OAAA;AACnB,wHAAA,mBAAmB,OAAA;AACnB,sHAAA,iBAAiB,OAAA;AACjB,8GAAA,SAAS,OAAA;AACT,mHAAA,cAAc,OAAA;AACd,0HAAA,qBAAqB,OAAA;AACrB,gIAAA,2BAA2B,OAAA"}
|
|
@@ -8,6 +8,12 @@ import Joi from './Joi';
|
|
|
8
8
|
export declare const PluginIdSchema: Joi.StringSchema;
|
|
9
9
|
export declare const RemarkPluginsSchema: Joi.ArraySchema;
|
|
10
10
|
export declare const RehypePluginsSchema: Joi.ArraySchema;
|
|
11
|
-
export declare const AdmonitionsSchema: Joi.
|
|
11
|
+
export declare const AdmonitionsSchema: Joi.AlternativesSchema;
|
|
12
12
|
export declare const URISchema: Joi.AlternativesSchema;
|
|
13
13
|
export declare const PathnameSchema: Joi.StringSchema;
|
|
14
|
+
export declare const FrontMatterTagsSchema: Joi.ArraySchema;
|
|
15
|
+
export declare const FrontMatterTOCHeadingLevels: {
|
|
16
|
+
toc_min_heading_level: Joi.NumberSchema;
|
|
17
|
+
toc_max_heading_level: Joi.NumberSchema;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=validationSchemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationSchemas.d.ts","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,GAAG,MAAM,OAAO,CAAC;AAGxB,eAAO,MAAM,cAAc,kBAKE,CAAC;AAe9B,eAAO,MAAM,mBAAmB,iBAAwB,CAAC;AACzD,eAAO,MAAM,mBAAmB,iBAAwB,CAAC;AAQzD,eAAO,MAAM,iBAAiB,wBAkB1B,CAAC;AAIL,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
|
@@ -1,50 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PathnameSchema = exports.URISchema = exports.AdmonitionsSchema = exports.RehypePluginsSchema = exports.RemarkPluginsSchema = exports.PluginIdSchema = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
2
|
/**
|
|
6
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
4
|
*
|
|
8
5
|
* This source code is licensed under the MIT license found in the
|
|
9
6
|
* LICENSE file in the root directory of this source tree.
|
|
10
7
|
*/
|
|
11
|
-
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.FrontMatterTOCHeadingLevels = exports.FrontMatterTagsSchema = exports.PathnameSchema = exports.URISchema = exports.AdmonitionsSchema = exports.RehypePluginsSchema = exports.RemarkPluginsSchema = exports.PluginIdSchema = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
12
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
|
+
const Joi_1 = tslib_1.__importDefault(require("./Joi"));
|
|
13
|
+
const JoiFrontMatter_1 = require("./JoiFrontMatter");
|
|
13
14
|
exports.PluginIdSchema = Joi_1.default.string()
|
|
14
|
-
.regex(/^[
|
|
15
|
-
|
|
16
|
-
.default(
|
|
15
|
+
.regex(/^[\w-]+$/)
|
|
16
|
+
.message('Illegal plugin ID value "{#value}": it should only contain alphanumerics, underscores, and dashes.')
|
|
17
|
+
.default(utils_1.DEFAULT_PLUGIN_ID);
|
|
17
18
|
const MarkdownPluginsSchema = Joi_1.default.array()
|
|
18
|
-
.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
|
+
})
|
|
19
25
|
.default([]);
|
|
20
26
|
exports.RemarkPluginsSchema = MarkdownPluginsSchema;
|
|
21
27
|
exports.RehypePluginsSchema = MarkdownPluginsSchema;
|
|
22
|
-
|
|
28
|
+
const LegacyAdmonitionConfigSchema = Joi_1.default.forbidden().messages({
|
|
29
|
+
'any.unknown': `The Docusaurus admonitions system has changed, and the option {#label} does not exist anymore.
|
|
30
|
+
You now need to swizzle the admonitions component to provide UI customizations such as icons.
|
|
31
|
+
Please refer to https://github.com/facebook/docusaurus/pull/7152 for detailed upgrade instructions.`,
|
|
32
|
+
});
|
|
33
|
+
exports.AdmonitionsSchema = JoiFrontMatter_1.JoiFrontMatter.alternatives()
|
|
34
|
+
.try(JoiFrontMatter_1.JoiFrontMatter.boolean().required(), JoiFrontMatter_1.JoiFrontMatter.object({
|
|
35
|
+
tag: JoiFrontMatter_1.JoiFrontMatter.string(),
|
|
36
|
+
keywords: JoiFrontMatter_1.JoiFrontMatter.array().items(JoiFrontMatter_1.JoiFrontMatter.string().required()),
|
|
37
|
+
// TODO Remove before 2023
|
|
38
|
+
customTypes: LegacyAdmonitionConfigSchema,
|
|
39
|
+
icons: LegacyAdmonitionConfigSchema,
|
|
40
|
+
infima: LegacyAdmonitionConfigSchema,
|
|
41
|
+
}).required())
|
|
42
|
+
.default(true)
|
|
43
|
+
.messages({
|
|
44
|
+
'alternatives.types': '{{#label}} does not look like a valid admonitions config',
|
|
45
|
+
});
|
|
23
46
|
// TODO how can we make this emit a custom error message :'(
|
|
24
47
|
// Joi is such a pain, good luck to annoying trying to improve this
|
|
25
48
|
exports.URISchema = Joi_1.default.alternatives(Joi_1.default.string().uri({ allowRelative: true }),
|
|
26
|
-
// This custom validation logic is required notably because Joi does not
|
|
49
|
+
// This custom validation logic is required notably because Joi does not
|
|
50
|
+
// accept paths like /a/b/c ...
|
|
27
51
|
Joi_1.default.custom((val, helpers) => {
|
|
28
52
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return helpers.error('any.invalid');
|
|
35
|
-
}
|
|
53
|
+
// eslint-disable-next-line no-new
|
|
54
|
+
new URL(String(val));
|
|
55
|
+
return val;
|
|
36
56
|
}
|
|
37
57
|
catch {
|
|
38
58
|
return helpers.error('any.invalid');
|
|
39
59
|
}
|
|
40
|
-
}))
|
|
60
|
+
})).messages({
|
|
61
|
+
'alternatives.match': "{{#label}} does not look like a valid url (value='{{.value}}')",
|
|
62
|
+
});
|
|
41
63
|
exports.PathnameSchema = Joi_1.default.string()
|
|
42
64
|
.custom((val) => {
|
|
43
|
-
if (!utils_1.isValidPathname(val)) {
|
|
65
|
+
if (!(0, utils_1.isValidPathname)(val)) {
|
|
44
66
|
throw new Error();
|
|
45
67
|
}
|
|
46
|
-
|
|
47
|
-
return val;
|
|
48
|
-
}
|
|
68
|
+
return val;
|
|
49
69
|
})
|
|
50
70
|
.message('{{#label}} is not a valid pathname. Pathname should start with slash and not contain any domain or query string.');
|
|
71
|
+
const FrontMatterTagSchema = JoiFrontMatter_1.JoiFrontMatter.alternatives()
|
|
72
|
+
.try(JoiFrontMatter_1.JoiFrontMatter.string().required(), JoiFrontMatter_1.JoiFrontMatter.object({
|
|
73
|
+
label: JoiFrontMatter_1.JoiFrontMatter.string().required(),
|
|
74
|
+
permalink: JoiFrontMatter_1.JoiFrontMatter.string().required(),
|
|
75
|
+
}).required())
|
|
76
|
+
.messages({
|
|
77
|
+
'alternatives.match': '{{#label}} does not look like a valid tag',
|
|
78
|
+
'alternatives.types': '{{#label}} does not look like a valid tag',
|
|
79
|
+
});
|
|
80
|
+
exports.FrontMatterTagsSchema = JoiFrontMatter_1.JoiFrontMatter.array()
|
|
81
|
+
.items(FrontMatterTagSchema)
|
|
82
|
+
.messages({
|
|
83
|
+
'array.base': '{{#label}} does not look like a valid front matter Yaml array.',
|
|
84
|
+
});
|
|
85
|
+
exports.FrontMatterTOCHeadingLevels = {
|
|
86
|
+
toc_min_heading_level: JoiFrontMatter_1.JoiFrontMatter.number().when('toc_max_heading_level', {
|
|
87
|
+
is: JoiFrontMatter_1.JoiFrontMatter.exist(),
|
|
88
|
+
then: JoiFrontMatter_1.JoiFrontMatter.number()
|
|
89
|
+
.min(2)
|
|
90
|
+
.max(JoiFrontMatter_1.JoiFrontMatter.ref('toc_max_heading_level')),
|
|
91
|
+
otherwise: JoiFrontMatter_1.JoiFrontMatter.number().min(2).max(6),
|
|
92
|
+
}),
|
|
93
|
+
toc_max_heading_level: JoiFrontMatter_1.JoiFrontMatter.number().min(2).max(6),
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=validationSchemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationSchemas.js","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":"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"}
|
package/lib/validationUtils.d.ts
CHANGED
|
@@ -4,13 +4,26 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import Joi from './Joi';
|
|
8
|
-
|
|
9
|
-
export declare const logValidationBugReportHint: () => void;
|
|
7
|
+
import type Joi from './Joi';
|
|
8
|
+
/** Print warnings returned from Joi validation. */
|
|
10
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
|
+
*/
|
|
11
15
|
export declare function normalizePluginOptions<T extends {
|
|
12
16
|
id?: string;
|
|
13
|
-
}>(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
|
+
*/
|
|
14
22
|
export declare function normalizeThemeConfig<T>(schema: Joi.ObjectSchema<T>, themeConfig: Partial<T>): T;
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
|
29
|
+
//# sourceMappingURL=validationUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAE7B,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
|
@@ -1,42 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateFrontMatter = exports.JoiFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning = exports.logValidationBugReportHint = exports.isValidationDisabledEscapeHatch = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
2
|
/**
|
|
6
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
4
|
*
|
|
8
5
|
* This source code is licensed under the MIT license found in the
|
|
9
6
|
* LICENSE file in the root directory of this source tree.
|
|
10
7
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
13
13
|
const validationSchemas_1 = require("./validationSchemas");
|
|
14
|
-
|
|
15
|
-
// Our validation schemas might be buggy at first
|
|
16
|
-
// will permit users to bypass validation until we fix all validation errors
|
|
17
|
-
// see for example: https://github.com/facebook/docusaurus/pull/3120
|
|
18
|
-
// Undocumented on purpose, as we don't want users to keep using it over time
|
|
19
|
-
// Maybe we'll make this escape hatch official some day, with a better api?
|
|
20
|
-
exports.isValidationDisabledEscapeHatch = process.env.DISABLE_DOCUSAURUS_VALIDATION === 'true';
|
|
21
|
-
if (exports.isValidationDisabledEscapeHatch) {
|
|
22
|
-
console.error(chalk_1.default.red('You should avoid using DISABLE_DOCUSAURUS_VALIDATION escape hatch, this will be removed.'));
|
|
23
|
-
}
|
|
24
|
-
const logValidationBugReportHint = () => {
|
|
25
|
-
console.log(`\n${chalk_1.default.red('A validation error occurred.')}${chalk_1.default.cyanBright('\nThe validation system was added recently to Docusaurus as an attempt to avoid user configuration errors.' +
|
|
26
|
-
'\nWe may have made some mistakes.' +
|
|
27
|
-
'\nIf you think your configuration is valid and should keep working, please open a bug report.')}\n`);
|
|
28
|
-
};
|
|
29
|
-
exports.logValidationBugReportHint = logValidationBugReportHint;
|
|
14
|
+
/** Print warnings returned from Joi validation. */
|
|
30
15
|
function printWarning(warning) {
|
|
31
16
|
if (warning) {
|
|
32
17
|
const warningMessages = warning.details
|
|
33
18
|
.map(({ message }) => message)
|
|
34
19
|
.join('\n');
|
|
35
|
-
|
|
20
|
+
logger_1.default.warn(warningMessages);
|
|
36
21
|
}
|
|
37
22
|
}
|
|
38
23
|
exports.printWarning = printWarning;
|
|
39
|
-
|
|
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 = {}) {
|
|
40
32
|
// All plugins can be provided an "id" option (multi-instance support)
|
|
41
33
|
// we add schema validation automatically
|
|
42
34
|
const finalSchema = schema.append({
|
|
@@ -47,20 +39,17 @@ function normalizePluginOptions(schema, options) {
|
|
|
47
39
|
});
|
|
48
40
|
printWarning(warning);
|
|
49
41
|
if (error) {
|
|
50
|
-
|
|
51
|
-
if (exports.isValidationDisabledEscapeHatch) {
|
|
52
|
-
console.error(error);
|
|
53
|
-
return options;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
42
|
+
throw error;
|
|
58
43
|
}
|
|
59
44
|
return value;
|
|
60
45
|
}
|
|
61
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
|
+
*/
|
|
62
51
|
function normalizeThemeConfig(schema, themeConfig) {
|
|
63
|
-
// A theme should only validate
|
|
52
|
+
// A theme should only validate its "slice" of the full themeConfig,
|
|
64
53
|
// not the whole object, so we allow unknown attributes
|
|
65
54
|
// otherwise one theme would fail validating the data of another theme
|
|
66
55
|
const finalSchema = schema.unknown();
|
|
@@ -69,35 +58,14 @@ function normalizeThemeConfig(schema, themeConfig) {
|
|
|
69
58
|
});
|
|
70
59
|
printWarning(warning);
|
|
71
60
|
if (error) {
|
|
72
|
-
|
|
73
|
-
if (exports.isValidationDisabledEscapeHatch) {
|
|
74
|
-
console.error(error);
|
|
75
|
-
return themeConfig;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
61
|
+
throw error;
|
|
80
62
|
}
|
|
81
63
|
return value;
|
|
82
64
|
}
|
|
83
65
|
exports.normalizeThemeConfig = normalizeThemeConfig;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// see https://github.com/facebook/docusaurus/issues/4642
|
|
88
|
-
// see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
89
|
-
const JoiFrontMatterString = {
|
|
90
|
-
type: 'string',
|
|
91
|
-
base: Joi_1.default.string(),
|
|
92
|
-
// Fix Yaml that tries to auto-convert many things to string out of the box
|
|
93
|
-
prepare: (value) => {
|
|
94
|
-
if (typeof value === 'number' || value instanceof Date) {
|
|
95
|
-
return { value: value.toString() };
|
|
96
|
-
}
|
|
97
|
-
return { value };
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
exports.JoiFrontMatter = Joi_1.default.extend(JoiFrontMatterString);
|
|
66
|
+
/**
|
|
67
|
+
* Validate front matter with better error message
|
|
68
|
+
*/
|
|
101
69
|
function validateFrontMatter(frontMatter, schema) {
|
|
102
70
|
const { value, error, warning } = schema.validate(frontMatter, {
|
|
103
71
|
convert: true,
|
|
@@ -106,16 +74,17 @@ function validateFrontMatter(frontMatter, schema) {
|
|
|
106
74
|
});
|
|
107
75
|
printWarning(warning);
|
|
108
76
|
if (error) {
|
|
109
|
-
const frontMatterString = JSON.stringify(frontMatter, null, 2);
|
|
110
77
|
const errorDetails = error.details;
|
|
111
78
|
const invalidFields = errorDetails.map(({ path }) => path).join(', ');
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
79
|
+
logger_1.default.error `The following front matter:
|
|
80
|
+
---
|
|
81
|
+
${js_yaml_1.default.dump(frontMatter)}---
|
|
82
|
+
contains invalid values for field(s): code=${invalidFields}.
|
|
83
|
+
${errorDetails.map(({ message }) => message)}
|
|
84
|
+
`;
|
|
117
85
|
throw error;
|
|
118
86
|
}
|
|
119
87
|
return value;
|
|
120
88
|
}
|
|
121
89
|
exports.validateFrontMatter = validateFrontMatter;
|
|
90
|
+
//# sourceMappingURL=validationUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wEAAwC;AACxC,8DAA2B;AAC3B,2DAAmD;AAGnD,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,OAAO,EAAE,KAAK,EAAC,GAAG,WAAW,CAAC,QAAQ,CAAC,OAAO,EAAE;QAC5D,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IAEH,YAAY,CAAC,OAAO,CAAC,CAAC;IAEtB,IAAI,KAAK,EAAE;QACT,MAAM,KAAK,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AArBD,wDAqBC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAClC,MAA2B,EAC3B,WAAuB;IAEvB,oEAAoE;IACpE,uDAAuD;IACvD,sEAAsE;IACtE,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAErC,MAAM,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAC,GAAG,WAAW,CAAC,QAAQ,CAAC,WAAW,EAAE;QAChE,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IAEH,YAAY,CAAC,OAAO,CAAC,CAAC;IAEtB,IAAI,KAAK,EAAE;QACT,MAAM,KAAK,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAnBD,oDAmBC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CACjC,WAAqC,EACrC,MAA2B;IAE3B,MAAM,EAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE;QAC3D,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,KAAK;KAClB,CAAC,CAAC;IAEH,YAAY,CAAC,OAAO,CAAC,CAAC;IAEtB,IAAI,KAAK,EAAE;QACT,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC;QACnC,MAAM,aAAa,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpE,gBAAM,CAAC,KAAK,CAAA;;EAEd,iBAAI,CAAC,IAAI,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-
|
|
3
|
+
"version": "2.0.0-rc.1",
|
|
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/
|
|
22
|
-
"
|
|
23
|
-
"joi": "^17.
|
|
24
|
-
"
|
|
21
|
+
"@docusaurus/logger": "2.0.0-rc.1",
|
|
22
|
+
"@docusaurus/utils": "2.0.0-rc.1",
|
|
23
|
+
"joi": "^17.6.0",
|
|
24
|
+
"js-yaml": "^4.1.0",
|
|
25
|
+
"tslib": "^2.4.0"
|
|
25
26
|
},
|
|
26
27
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
28
|
+
"node": ">=16.14"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "c8ddd02a8e68dfaf515c20465a049a83153bd205"
|
|
30
31
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import Joi from './Joi';
|
|
9
|
+
|
|
10
|
+
const JoiFrontMatterString: Joi.Extension = {
|
|
11
|
+
type: 'string',
|
|
12
|
+
base: Joi.string(),
|
|
13
|
+
// Fix Yaml that tries to auto-convert many things to string out of the box
|
|
14
|
+
prepare: (value: unknown) => {
|
|
15
|
+
if (typeof value === 'number' || value instanceof Date) {
|
|
16
|
+
return {value: value.toString()};
|
|
17
|
+
}
|
|
18
|
+
return {value};
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Enhance the default `Joi.string()` type so that it can convert number to
|
|
24
|
+
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
|
|
25
|
+
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
|
|
26
|
+
* to dates automatically.
|
|
27
|
+
*
|
|
28
|
+
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
29
|
+
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
30
|
+
*/
|
|
31
|
+
export const JoiFrontMatter = Joi.extend(JoiFrontMatterString) as typeof Joi;
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,21 @@
|
|
|
7
7
|
|
|
8
8
|
// /!\ don't remove this export, as we recommend plugin authors to use it
|
|
9
9
|
export {default as Joi} from './Joi';
|
|
10
|
+
export {JoiFrontMatter} from './JoiFrontMatter';
|
|
10
11
|
|
|
11
|
-
export
|
|
12
|
-
|
|
12
|
+
export {
|
|
13
|
+
printWarning,
|
|
14
|
+
normalizePluginOptions,
|
|
15
|
+
normalizeThemeConfig,
|
|
16
|
+
validateFrontMatter,
|
|
17
|
+
} from './validationUtils';
|
|
18
|
+
export {
|
|
19
|
+
PluginIdSchema,
|
|
20
|
+
RemarkPluginsSchema,
|
|
21
|
+
RehypePluginsSchema,
|
|
22
|
+
AdmonitionsSchema,
|
|
23
|
+
URISchema,
|
|
24
|
+
PathnameSchema,
|
|
25
|
+
FrontMatterTagsSchema,
|
|
26
|
+
FrontMatterTOCHeadingLevels,
|
|
27
|
+
} from './validationSchemas';
|