@docusaurus/utils-validation 2.0.0-beta.15d451942 → 2.0.0-beta.16
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 +17 -0
- package/lib/JoiFrontMatter.d.ts.map +1 -0
- package/lib/JoiFrontMatter.js +32 -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 +6 -0
- package/lib/validationSchemas.d.ts.map +1 -0
- package/lib/validationSchemas.js +48 -21
- package/lib/validationSchemas.js.map +1 -0
- package/lib/validationUtils.d.ts +3 -4
- package/lib/validationUtils.d.ts.map +1 -0
- package/lib/validationUtils.js +28 -69
- package/lib/validationUtils.js.map +1 -0
- package/package.json +7 -7
- package/src/JoiFrontMatter.ts +29 -0
- package/src/index.ts +17 -2
- package/src/validationSchemas.ts +53 -14
- package/src/validationUtils.ts +30 -83
- package/lib/.tsbuildinfo +0 -3989
- 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,17 @@
|
|
|
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
|
+
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
14
|
+
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
15
|
+
*/
|
|
16
|
+
export declare const JoiFrontMatter: typeof Joi;
|
|
17
|
+
//# 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;AAaxB;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,GAAsC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 = (0, 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
|
+
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
29
|
+
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
30
|
+
*/
|
|
31
|
+
exports.JoiFrontMatter = Joi_1.default.extend(JoiFrontMatterString);
|
|
32
|
+
//# sourceMappingURL=JoiFrontMatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JoiFrontMatter.js","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6DAAwB;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;AACF;;;;;;;GAOG;AACU,QAAA,cAAc,GAAe,aAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,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"}
|
|
@@ -11,3 +11,9 @@ export declare const RehypePluginsSchema: Joi.ArraySchema;
|
|
|
11
11
|
export declare const AdmonitionsSchema: Joi.ObjectSchema<any>;
|
|
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;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AAKxB,eAAO,MAAM,cAAc,kBAKE,CAAC;AAU9B,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
|
@@ -1,46 +1,73 @@
|
|
|
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");
|
|
11
|
+
const Joi_1 = (0, tslib_1.__importDefault)(require("./Joi"));
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
const JoiFrontMatter_1 = require("./JoiFrontMatter");
|
|
13
14
|
exports.PluginIdSchema = Joi_1.default.string()
|
|
14
|
-
.regex(/^[a-zA-
|
|
15
|
-
|
|
16
|
-
.default(
|
|
15
|
+
.regex(/^[a-zA-Z0-9_-]+$/)
|
|
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
19
|
.items(Joi_1.default.array().ordered(Joi_1.default.function().required(), Joi_1.default.object().required()), Joi_1.default.function(), Joi_1.default.object())
|
|
19
20
|
.default([]);
|
|
20
21
|
exports.RemarkPluginsSchema = MarkdownPluginsSchema;
|
|
21
22
|
exports.RehypePluginsSchema = MarkdownPluginsSchema;
|
|
22
23
|
exports.AdmonitionsSchema = Joi_1.default.object().default({});
|
|
23
|
-
|
|
24
|
+
// TODO how can we make this emit a custom error message :'(
|
|
25
|
+
// Joi is such a pain, good luck to annoying trying to improve this
|
|
26
|
+
exports.URISchema = Joi_1.default.alternatives(Joi_1.default.string().uri({ allowRelative: true }),
|
|
27
|
+
// This custom validation logic is required notably because Joi does not
|
|
28
|
+
// accept paths like /a/b/c ...
|
|
29
|
+
Joi_1.default.custom((val, helpers) => {
|
|
24
30
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return helpers.error('any.invalid');
|
|
31
|
-
}
|
|
31
|
+
// eslint-disable-next-line no-new
|
|
32
|
+
new URL(val);
|
|
33
|
+
return val;
|
|
32
34
|
}
|
|
33
35
|
catch {
|
|
34
36
|
return helpers.error('any.invalid');
|
|
35
37
|
}
|
|
36
|
-
}))
|
|
38
|
+
})).messages({
|
|
39
|
+
'alternatives.match': "{{#label}} does not look like a valid url (value='{{.value}}')",
|
|
40
|
+
});
|
|
37
41
|
exports.PathnameSchema = Joi_1.default.string()
|
|
38
42
|
.custom((val) => {
|
|
39
|
-
if (!utils_1.isValidPathname(val)) {
|
|
43
|
+
if (!(0, utils_1.isValidPathname)(val)) {
|
|
40
44
|
throw new Error();
|
|
41
45
|
}
|
|
42
|
-
|
|
43
|
-
return val;
|
|
44
|
-
}
|
|
46
|
+
return val;
|
|
45
47
|
})
|
|
46
|
-
.message('{{#label}} is not a valid pathname. Pathname should start with
|
|
48
|
+
.message('{{#label}} is not a valid pathname. Pathname should start with slash and not contain any domain or query string.');
|
|
49
|
+
const FrontMatterTagSchema = JoiFrontMatter_1.JoiFrontMatter.alternatives()
|
|
50
|
+
.try(JoiFrontMatter_1.JoiFrontMatter.string().required(), JoiFrontMatter_1.JoiFrontMatter.object({
|
|
51
|
+
label: JoiFrontMatter_1.JoiFrontMatter.string().required(),
|
|
52
|
+
permalink: JoiFrontMatter_1.JoiFrontMatter.string().required(),
|
|
53
|
+
}).required())
|
|
54
|
+
.messages({
|
|
55
|
+
'alternatives.match': '{{#label}} does not look like a valid tag',
|
|
56
|
+
'alternatives.types': '{{#label}} does not look like a valid tag',
|
|
57
|
+
});
|
|
58
|
+
exports.FrontMatterTagsSchema = JoiFrontMatter_1.JoiFrontMatter.array()
|
|
59
|
+
.items(FrontMatterTagSchema)
|
|
60
|
+
.messages({
|
|
61
|
+
'array.base': '{{#label}} does not look like a valid FrontMatter Yaml array.',
|
|
62
|
+
});
|
|
63
|
+
exports.FrontMatterTOCHeadingLevels = {
|
|
64
|
+
toc_min_heading_level: JoiFrontMatter_1.JoiFrontMatter.number().when('toc_max_heading_level', {
|
|
65
|
+
is: JoiFrontMatter_1.JoiFrontMatter.exist(),
|
|
66
|
+
then: JoiFrontMatter_1.JoiFrontMatter.number()
|
|
67
|
+
.min(2)
|
|
68
|
+
.max(JoiFrontMatter_1.JoiFrontMatter.ref('toc_max_heading_level')),
|
|
69
|
+
otherwise: JoiFrontMatter_1.JoiFrontMatter.number().min(2).max(6),
|
|
70
|
+
}),
|
|
71
|
+
toc_max_heading_level: JoiFrontMatter_1.JoiFrontMatter.number().min(2).max(6),
|
|
72
|
+
};
|
|
73
|
+
//# 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,12 +4,11 @@
|
|
|
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
|
-
export declare
|
|
9
|
-
export declare const logValidationBugReportHint: () => void;
|
|
7
|
+
import type Joi from './Joi';
|
|
8
|
+
export declare function printWarning(warning?: Joi.ValidationError): void;
|
|
10
9
|
export declare function normalizePluginOptions<T extends {
|
|
11
10
|
id?: string;
|
|
12
11
|
}>(schema: Joi.ObjectSchema<T>, options: Partial<T>): T;
|
|
13
12
|
export declare function normalizeThemeConfig<T>(schema: Joi.ObjectSchema<T>, themeConfig: Partial<T>): T;
|
|
14
|
-
export declare const JoiFrontMatter: typeof Joi;
|
|
15
13
|
export declare function validateFrontMatter<T>(frontMatter: Record<string, unknown>, schema: Joi.ObjectSchema<T>): T;
|
|
14
|
+
//# sourceMappingURL=validationUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAI7B,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,eAAe,GAAG,IAAI,CAOhE;AAED,wBAAgB,sBAAsB,CAAC,CAAC,SAAS;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAC,EAC5D,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAC3B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAClB,CAAC,CAiBH;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAC3B,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,GACtB,CAAC,CAgBH;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,GAC1B,CAAC,CAuBH"}
|
package/lib/validationUtils.js
CHANGED
|
@@ -1,52 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateFrontMatter = exports.JoiFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = 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 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
13
12
|
const validationSchemas_1 = require("./validationSchemas");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (exports.isValidationDisabledEscapeHatch) {
|
|
22
|
-
console.error(chalk_1.default.red('You should avoid using DISABLE_DOCUSAURUS_VALIDATION escape hatch, this will be removed'));
|
|
13
|
+
function printWarning(warning) {
|
|
14
|
+
if (warning) {
|
|
15
|
+
const warningMessages = warning.details
|
|
16
|
+
.map(({ message }) => message)
|
|
17
|
+
.join('\n');
|
|
18
|
+
logger_1.default.warn(warningMessages);
|
|
19
|
+
}
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
console.log(`\n${chalk_1.default.red('A validation error occured.')}${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;
|
|
21
|
+
exports.printWarning = printWarning;
|
|
30
22
|
function normalizePluginOptions(schema, options) {
|
|
31
23
|
// All plugins can be provided an "id" option (multi-instance support)
|
|
32
24
|
// we add schema validation automatically
|
|
33
25
|
const finalSchema = schema.append({
|
|
34
26
|
id: validationSchemas_1.PluginIdSchema,
|
|
35
27
|
});
|
|
36
|
-
const { error, value } = finalSchema.validate(options, {
|
|
28
|
+
const { error, warning, value } = finalSchema.validate(options, {
|
|
37
29
|
convert: false,
|
|
38
30
|
});
|
|
31
|
+
printWarning(warning);
|
|
39
32
|
if (error) {
|
|
40
|
-
|
|
41
|
-
if (exports.isValidationDisabledEscapeHatch) {
|
|
42
|
-
console.error(error);
|
|
43
|
-
return options;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
33
|
+
throw error;
|
|
48
34
|
}
|
|
49
|
-
return value;
|
|
35
|
+
return value; // TODO remove this ! in TS 4.6, see https://twitter.com/sebastienlorber/status/1481950042277793793
|
|
50
36
|
}
|
|
51
37
|
exports.normalizePluginOptions = normalizePluginOptions;
|
|
52
38
|
function normalizeThemeConfig(schema, themeConfig) {
|
|
@@ -54,62 +40,35 @@ function normalizeThemeConfig(schema, themeConfig) {
|
|
|
54
40
|
// not the whole object, so we allow unknown attributes
|
|
55
41
|
// otherwise one theme would fail validating the data of another theme
|
|
56
42
|
const finalSchema = schema.unknown();
|
|
57
|
-
const { error, value } = finalSchema.validate(themeConfig, {
|
|
43
|
+
const { error, warning, value } = finalSchema.validate(themeConfig, {
|
|
58
44
|
convert: false,
|
|
59
45
|
});
|
|
46
|
+
printWarning(warning);
|
|
60
47
|
if (error) {
|
|
61
|
-
|
|
62
|
-
if (exports.isValidationDisabledEscapeHatch) {
|
|
63
|
-
console.error(error);
|
|
64
|
-
return themeConfig;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
48
|
+
throw error;
|
|
69
49
|
}
|
|
70
|
-
return value;
|
|
50
|
+
return value; // TODO remove this ! in TS 4.6
|
|
71
51
|
}
|
|
72
52
|
exports.normalizeThemeConfig = normalizeThemeConfig;
|
|
73
|
-
// Enhance the default Joi.string() type so that it can convert number to strings
|
|
74
|
-
// If user use frontmatter "tag: 2021", we shouldn't need to ask the user to write "tag: '2021'"
|
|
75
|
-
// Also yaml tries to convert patterns like "2019-01-01" to dates automatically
|
|
76
|
-
// see https://github.com/facebook/docusaurus/issues/4642
|
|
77
|
-
// see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
78
|
-
const JoiFrontMatterString = {
|
|
79
|
-
type: 'string',
|
|
80
|
-
base: Joi_1.default.string(),
|
|
81
|
-
// Fix Yaml that tries to auto-convert many things to string out of the box
|
|
82
|
-
prepare: (value) => {
|
|
83
|
-
if (typeof value === 'number' || value instanceof Date) {
|
|
84
|
-
return { value: value.toString() };
|
|
85
|
-
}
|
|
86
|
-
return { value };
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
exports.JoiFrontMatter = Joi_1.default.extend(JoiFrontMatterString);
|
|
90
53
|
function validateFrontMatter(frontMatter, schema) {
|
|
91
54
|
const { value, error, warning } = schema.validate(frontMatter, {
|
|
92
55
|
convert: true,
|
|
93
56
|
allowUnknown: true,
|
|
94
57
|
abortEarly: false,
|
|
95
58
|
});
|
|
59
|
+
printWarning(warning);
|
|
96
60
|
if (error) {
|
|
97
61
|
const frontMatterString = JSON.stringify(frontMatter, null, 2);
|
|
98
62
|
const errorDetails = error.details;
|
|
99
63
|
const invalidFields = errorDetails.map(({ path }) => path).join(', ');
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
64
|
+
logger_1.default.error `The following front matter:
|
|
65
|
+
${logger_1.default.yellow(frontMatterString)}
|
|
66
|
+
contains invalid values for field(s): ${logger_1.default.yellow(invalidFields)}.
|
|
67
|
+
${errorDetails.map(({ message }) => message)}
|
|
68
|
+
`;
|
|
105
69
|
throw error;
|
|
106
70
|
}
|
|
107
|
-
|
|
108
|
-
const warningMessages = warning.details
|
|
109
|
-
.map(({ message }) => message)
|
|
110
|
-
.join('\n');
|
|
111
|
-
console.log(chalk_1.default.yellow(warningMessages));
|
|
112
|
-
}
|
|
113
|
-
return value;
|
|
71
|
+
return value; // TODO remove this ! in TS 4.6
|
|
114
72
|
}
|
|
115
73
|
exports.validateFrontMatter = validateFrontMatter;
|
|
74
|
+
//# sourceMappingURL=validationUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,6EAAwC;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,EAC3B,OAAmB;IAEnB,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,KAAM,CAAC,CAAC,mGAAmG;AACpH,CAAC;AApBD,wDAoBC;AAED,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,KAAM,CAAC,CAAC,+BAA+B;AAChD,CAAC;AAnBD,oDAmBC;AAED,SAAgB,mBAAmB,CACjC,WAAoC,EACpC,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,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC/D,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;EACd,gBAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC;wCACM,gBAAM,CAAC,MAAM,CAAC,aAAa,CAAC;EAClE,YAAY,CAAC,GAAG,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,OAAO,CAAC;CACzC,CAAC;QACE,MAAM,KAAK,CAAC;KACb;IAED,OAAO,KAAM,CAAC,CAAC,+BAA+B;AAChD,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.16",
|
|
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,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/
|
|
22
|
-
"
|
|
23
|
-
"joi": "^17.
|
|
24
|
-
"tslib": "^2.1
|
|
21
|
+
"@docusaurus/logger": "2.0.0-beta.16",
|
|
22
|
+
"@docusaurus/utils": "2.0.0-beta.16",
|
|
23
|
+
"joi": "^17.6.0",
|
|
24
|
+
"tslib": "^2.3.1"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
27
|
+
"node": ">=14"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
|
|
30
30
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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) => {
|
|
15
|
+
if (typeof value === 'number' || value instanceof Date) {
|
|
16
|
+
return {value: value.toString()};
|
|
17
|
+
}
|
|
18
|
+
return {value};
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Enhance the default Joi.string() type so that it can convert number to
|
|
23
|
+
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
|
|
24
|
+
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
|
|
25
|
+
* to dates automatically.
|
|
26
|
+
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
27
|
+
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
28
|
+
*/
|
|
29
|
+
export const JoiFrontMatter: typeof Joi = Joi.extend(JoiFrontMatterString);
|
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';
|
package/src/validationSchemas.ts
CHANGED
|
@@ -4,13 +4,18 @@
|
|
|
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
|
+
|
|
7
8
|
import Joi from './Joi';
|
|
8
|
-
import {isValidPathname} from '@docusaurus/utils';
|
|
9
|
+
import {isValidPathname, DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
|
|
10
|
+
import type {Tag} from '@docusaurus/utils';
|
|
11
|
+
import {JoiFrontMatter} from './JoiFrontMatter';
|
|
9
12
|
|
|
10
13
|
export const PluginIdSchema = Joi.string()
|
|
11
|
-
.regex(/^[a-zA-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
.regex(/^[a-zA-Z0-9_-]+$/)
|
|
15
|
+
.message(
|
|
16
|
+
'Illegal plugin ID value "{#value}": it should only contain alphanumerics, underscores, and dashes.',
|
|
17
|
+
)
|
|
18
|
+
.default(DEFAULT_PLUGIN_ID);
|
|
14
19
|
|
|
15
20
|
const MarkdownPluginsSchema = Joi.array()
|
|
16
21
|
.items(
|
|
@@ -25,30 +30,64 @@ export const RehypePluginsSchema = MarkdownPluginsSchema;
|
|
|
25
30
|
|
|
26
31
|
export const AdmonitionsSchema = Joi.object().default({});
|
|
27
32
|
|
|
33
|
+
// TODO how can we make this emit a custom error message :'(
|
|
34
|
+
// Joi is such a pain, good luck to annoying trying to improve this
|
|
28
35
|
export const URISchema = Joi.alternatives(
|
|
29
36
|
Joi.string().uri({allowRelative: true}),
|
|
37
|
+
// This custom validation logic is required notably because Joi does not
|
|
38
|
+
// accept paths like /a/b/c ...
|
|
30
39
|
Joi.custom((val, helpers) => {
|
|
31
40
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} else {
|
|
36
|
-
return helpers.error('any.invalid');
|
|
37
|
-
}
|
|
41
|
+
// eslint-disable-next-line no-new
|
|
42
|
+
new URL(val);
|
|
43
|
+
return val;
|
|
38
44
|
} catch {
|
|
39
45
|
return helpers.error('any.invalid');
|
|
40
46
|
}
|
|
41
47
|
}),
|
|
42
|
-
)
|
|
48
|
+
).messages({
|
|
49
|
+
'alternatives.match':
|
|
50
|
+
"{{#label}} does not look like a valid url (value='{{.value}}')",
|
|
51
|
+
});
|
|
43
52
|
|
|
44
53
|
export const PathnameSchema = Joi.string()
|
|
45
54
|
.custom((val) => {
|
|
46
55
|
if (!isValidPathname(val)) {
|
|
47
56
|
throw new Error();
|
|
48
|
-
} else {
|
|
49
|
-
return val;
|
|
50
57
|
}
|
|
58
|
+
return val;
|
|
51
59
|
})
|
|
52
60
|
.message(
|
|
53
|
-
'{{#label}} is not a valid pathname. Pathname should start with
|
|
61
|
+
'{{#label}} is not a valid pathname. Pathname should start with slash and not contain any domain or query string.',
|
|
54
62
|
);
|
|
63
|
+
|
|
64
|
+
const FrontMatterTagSchema = JoiFrontMatter.alternatives()
|
|
65
|
+
.try(
|
|
66
|
+
JoiFrontMatter.string().required(),
|
|
67
|
+
JoiFrontMatter.object<Tag>({
|
|
68
|
+
label: JoiFrontMatter.string().required(),
|
|
69
|
+
permalink: JoiFrontMatter.string().required(),
|
|
70
|
+
}).required(),
|
|
71
|
+
)
|
|
72
|
+
.messages({
|
|
73
|
+
'alternatives.match': '{{#label}} does not look like a valid tag',
|
|
74
|
+
'alternatives.types': '{{#label}} does not look like a valid tag',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const FrontMatterTagsSchema = JoiFrontMatter.array()
|
|
78
|
+
.items(FrontMatterTagSchema)
|
|
79
|
+
.messages({
|
|
80
|
+
'array.base':
|
|
81
|
+
'{{#label}} does not look like a valid FrontMatter Yaml array.',
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export const FrontMatterTOCHeadingLevels = {
|
|
85
|
+
toc_min_heading_level: JoiFrontMatter.number().when('toc_max_heading_level', {
|
|
86
|
+
is: JoiFrontMatter.exist(),
|
|
87
|
+
then: JoiFrontMatter.number()
|
|
88
|
+
.min(2)
|
|
89
|
+
.max(JoiFrontMatter.ref('toc_max_heading_level')),
|
|
90
|
+
otherwise: JoiFrontMatter.number().min(2).max(6),
|
|
91
|
+
}),
|
|
92
|
+
toc_max_heading_level: JoiFrontMatter.number().min(2).max(6),
|
|
93
|
+
};
|