@docusaurus/utils-validation 2.4.1 → 3.0.0-beta.0
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/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/validationSchemas.d.ts +15 -9
- package/lib/validationSchemas.d.ts.map +1 -1
- package/lib/validationSchemas.js +40 -13
- package/lib/validationSchemas.js.map +1 -1
- package/lib/validationUtils.d.ts +2 -3
- package/lib/validationUtils.d.ts.map +1 -1
- package/lib/validationUtils.js +2 -1
- package/lib/validationUtils.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +2 -0
- package/src/validationSchemas.ts +59 -14
- package/src/validationUtils.ts +4 -1
package/lib/index.d.ts
CHANGED
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
export { default as Joi } from './Joi';
|
|
8
8
|
export { JoiFrontMatter } from './JoiFrontMatter';
|
|
9
9
|
export { printWarning, normalizePluginOptions, normalizeThemeConfig, validateFrontMatter, } from './validationUtils';
|
|
10
|
-
export { PluginIdSchema, RemarkPluginsSchema, RehypePluginsSchema, AdmonitionsSchema, URISchema, PathnameSchema, FrontMatterTagsSchema, FrontMatterTOCHeadingLevels, } from './validationSchemas';
|
|
10
|
+
export { PluginIdSchema, RemarkPluginsSchema, RehypePluginsSchema, AdmonitionsSchema, RouteBasePathSchema, URISchema, PathnameSchema, FrontMatterTagsSchema, FrontMatterTOCHeadingLevels, ContentVisibilitySchema, } from './validationSchemas';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,mBAAmB,EACnB,SAAS,EACT,cAAc,EACd,qBAAqB,EACrB,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
9
|
+
exports.ContentVisibilitySchema = exports.FrontMatterTOCHeadingLevels = exports.FrontMatterTagsSchema = exports.PathnameSchema = exports.URISchema = exports.RouteBasePathSchema = exports.AdmonitionsSchema = exports.RehypePluginsSchema = exports.RemarkPluginsSchema = exports.PluginIdSchema = exports.validateFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning = exports.JoiFrontMatter = exports.Joi = void 0;
|
|
10
10
|
// /!\ don't remove this export, as we recommend plugin authors to use it
|
|
11
11
|
var Joi_1 = require("./Joi");
|
|
12
12
|
Object.defineProperty(exports, "Joi", { enumerable: true, get: function () { return __importDefault(Joi_1).default; } });
|
|
@@ -22,8 +22,10 @@ Object.defineProperty(exports, "PluginIdSchema", { enumerable: true, get: functi
|
|
|
22
22
|
Object.defineProperty(exports, "RemarkPluginsSchema", { enumerable: true, get: function () { return validationSchemas_1.RemarkPluginsSchema; } });
|
|
23
23
|
Object.defineProperty(exports, "RehypePluginsSchema", { enumerable: true, get: function () { return validationSchemas_1.RehypePluginsSchema; } });
|
|
24
24
|
Object.defineProperty(exports, "AdmonitionsSchema", { enumerable: true, get: function () { return validationSchemas_1.AdmonitionsSchema; } });
|
|
25
|
+
Object.defineProperty(exports, "RouteBasePathSchema", { enumerable: true, get: function () { return validationSchemas_1.RouteBasePathSchema; } });
|
|
25
26
|
Object.defineProperty(exports, "URISchema", { enumerable: true, get: function () { return validationSchemas_1.URISchema; } });
|
|
26
27
|
Object.defineProperty(exports, "PathnameSchema", { enumerable: true, get: function () { return validationSchemas_1.PathnameSchema; } });
|
|
27
28
|
Object.defineProperty(exports, "FrontMatterTagsSchema", { enumerable: true, get: function () { return validationSchemas_1.FrontMatterTagsSchema; } });
|
|
28
29
|
Object.defineProperty(exports, "FrontMatterTOCHeadingLevels", { enumerable: true, get: function () { return validationSchemas_1.FrontMatterTOCHeadingLevels; } });
|
|
30
|
+
Object.defineProperty(exports, "ContentVisibilitySchema", { enumerable: true, get: function () { return validationSchemas_1.ContentVisibilitySchema; } });
|
|
29
31
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +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,
|
|
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,yDAW6B;AAV3B,mHAAA,cAAc,OAAA;AACd,wHAAA,mBAAmB,OAAA;AACnB,wHAAA,mBAAmB,OAAA;AACnB,sHAAA,iBAAiB,OAAA;AACjB,wHAAA,mBAAmB,OAAA;AACnB,8GAAA,SAAS,OAAA;AACT,mHAAA,cAAc,OAAA;AACd,0HAAA,qBAAqB,OAAA;AACrB,gIAAA,2BAA2B,OAAA;AAC3B,4HAAA,uBAAuB,OAAA"}
|
|
@@ -5,15 +5,21 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import Joi from './Joi';
|
|
8
|
-
export declare const PluginIdSchema: Joi.StringSchema
|
|
9
|
-
export declare const RemarkPluginsSchema: Joi.ArraySchema
|
|
10
|
-
export declare const RehypePluginsSchema: Joi.ArraySchema
|
|
11
|
-
export declare const AdmonitionsSchema: Joi.AlternativesSchema
|
|
12
|
-
export declare const URISchema: Joi.AlternativesSchema
|
|
13
|
-
export declare const PathnameSchema: Joi.StringSchema
|
|
14
|
-
export declare const
|
|
8
|
+
export declare const PluginIdSchema: Joi.StringSchema<string>;
|
|
9
|
+
export declare const RemarkPluginsSchema: Joi.ArraySchema<any[]>;
|
|
10
|
+
export declare const RehypePluginsSchema: Joi.ArraySchema<any[]>;
|
|
11
|
+
export declare const AdmonitionsSchema: Joi.AlternativesSchema<any>;
|
|
12
|
+
export declare const URISchema: Joi.AlternativesSchema<any>;
|
|
13
|
+
export declare const PathnameSchema: Joi.StringSchema<string>;
|
|
14
|
+
export declare const RouteBasePathSchema: Joi.AlternativesSchema<any>;
|
|
15
|
+
export declare const FrontMatterTagsSchema: Joi.ArraySchema<any[]>;
|
|
15
16
|
export declare const FrontMatterTOCHeadingLevels: {
|
|
16
|
-
toc_min_heading_level: Joi.NumberSchema
|
|
17
|
-
toc_max_heading_level: Joi.NumberSchema
|
|
17
|
+
toc_min_heading_level: Joi.NumberSchema<number>;
|
|
18
|
+
toc_max_heading_level: Joi.NumberSchema<number>;
|
|
18
19
|
};
|
|
20
|
+
export type ContentVisibility = {
|
|
21
|
+
draft: boolean;
|
|
22
|
+
unlisted: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare const ContentVisibilitySchema: Joi.ObjectSchema<ContentVisibility>;
|
|
19
25
|
//# sourceMappingURL=validationSchemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationSchemas.d.ts","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"validationSchemas.d.ts","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,GAAG,MAAM,OAAO,CAAC;AAGxB,eAAO,MAAM,cAAc,0BAKE,CAAC;AAe9B,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AACzD,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD,eAAO,MAAM,iBAAiB,6BAqB1B,CAAC;AAIL,eAAO,MAAM,SAAS,6BAmBpB,CAAC;AAEH,eAAO,MAAM,cAAc,0BASxB,CAAC;AAaJ,eAAO,MAAM,mBAAmB,6BAO7B,CAAC;AAeJ,eAAO,MAAM,qBAAqB,wBAK9B,CAAC;AAEL,eAAO,MAAM,2BAA2B;;;CASvC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,uBAAuB,qCAgBxB,CAAC"}
|
package/lib/validationSchemas.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
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;
|
|
9
|
+
exports.ContentVisibilitySchema = exports.FrontMatterTOCHeadingLevels = exports.FrontMatterTagsSchema = exports.RouteBasePathSchema = exports.PathnameSchema = exports.URISchema = exports.AdmonitionsSchema = exports.RehypePluginsSchema = exports.RemarkPluginsSchema = exports.PluginIdSchema = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
12
|
const Joi_1 = tslib_1.__importDefault(require("./Joi"));
|
|
@@ -25,19 +25,14 @@ const MarkdownPluginsSchema = Joi_1.default.array()
|
|
|
25
25
|
.default([]);
|
|
26
26
|
exports.RemarkPluginsSchema = MarkdownPluginsSchema;
|
|
27
27
|
exports.RehypePluginsSchema = MarkdownPluginsSchema;
|
|
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
28
|
exports.AdmonitionsSchema = JoiFrontMatter_1.JoiFrontMatter.alternatives()
|
|
34
29
|
.try(JoiFrontMatter_1.JoiFrontMatter.boolean().required(), JoiFrontMatter_1.JoiFrontMatter.object({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// TODO Remove before
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
keywords: JoiFrontMatter_1.JoiFrontMatter.array().items(JoiFrontMatter_1.JoiFrontMatter.string()),
|
|
31
|
+
extendDefaults: JoiFrontMatter_1.JoiFrontMatter.boolean(),
|
|
32
|
+
// TODO Remove before 2024
|
|
33
|
+
tag: Joi_1.default.any().forbidden().messages({
|
|
34
|
+
'any.unknown': `It is not possible anymore to use a custom admonition tag. The only admonition tag supported is ':::' (Markdown Directive syntax)`,
|
|
35
|
+
}),
|
|
41
36
|
}).required())
|
|
42
37
|
.default(true)
|
|
43
38
|
.messages({
|
|
@@ -70,7 +65,25 @@ exports.PathnameSchema = Joi_1.default.string()
|
|
|
70
65
|
}
|
|
71
66
|
return val;
|
|
72
67
|
})
|
|
73
|
-
.message('{{#label}} is not a valid pathname. Pathname should start with slash and not contain any domain or query string.');
|
|
68
|
+
.message('{{#label}} ({{#value}}) is not a valid pathname. Pathname should start with slash and not contain any domain or query string.');
|
|
69
|
+
// Normalized schema for url path segments: baseUrl + routeBasePath...
|
|
70
|
+
// Note we only add a leading slash
|
|
71
|
+
// we don't always want to enforce a trailing slash on urls such as /docs
|
|
72
|
+
//
|
|
73
|
+
// Examples:
|
|
74
|
+
// '' => '/'
|
|
75
|
+
// 'docs' => '/docs'
|
|
76
|
+
// '/docs' => '/docs'
|
|
77
|
+
// 'docs/' => '/docs'
|
|
78
|
+
// 'prefix/docs' => '/prefix/docs'
|
|
79
|
+
// TODO tighter validation: not all strings are valid path segments
|
|
80
|
+
exports.RouteBasePathSchema = Joi_1.default
|
|
81
|
+
// Weird Joi trick needed, otherwise value '' is not normalized...
|
|
82
|
+
.alternatives()
|
|
83
|
+
.try(Joi_1.default.string().required().allow(''))
|
|
84
|
+
.custom((value) =>
|
|
85
|
+
// /!\ do not add trailing slash here
|
|
86
|
+
(0, utils_1.addLeadingSlash)(value));
|
|
74
87
|
const FrontMatterTagSchema = JoiFrontMatter_1.JoiFrontMatter.alternatives()
|
|
75
88
|
.try(JoiFrontMatter_1.JoiFrontMatter.string().required(), JoiFrontMatter_1.JoiFrontMatter.object({
|
|
76
89
|
label: JoiFrontMatter_1.JoiFrontMatter.string().required(),
|
|
@@ -95,4 +108,18 @@ exports.FrontMatterTOCHeadingLevels = {
|
|
|
95
108
|
}),
|
|
96
109
|
toc_max_heading_level: JoiFrontMatter_1.JoiFrontMatter.number().min(2).max(6),
|
|
97
110
|
};
|
|
111
|
+
exports.ContentVisibilitySchema = JoiFrontMatter_1.JoiFrontMatter.object({
|
|
112
|
+
draft: JoiFrontMatter_1.JoiFrontMatter.boolean(),
|
|
113
|
+
unlisted: JoiFrontMatter_1.JoiFrontMatter.boolean(),
|
|
114
|
+
})
|
|
115
|
+
.custom((frontMatter, helpers) => {
|
|
116
|
+
if (frontMatter.draft && frontMatter.unlisted) {
|
|
117
|
+
return helpers.error('frontMatter.draftAndUnlistedError');
|
|
118
|
+
}
|
|
119
|
+
return frontMatter;
|
|
120
|
+
})
|
|
121
|
+
.messages({
|
|
122
|
+
'frontMatter.draftAndUnlistedError': "Can't be draft and unlisted at the same time.",
|
|
123
|
+
})
|
|
124
|
+
.unknown();
|
|
98
125
|
//# sourceMappingURL=validationSchemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationSchemas.js","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,
|
|
1
|
+
{"version":3,"file":"validationSchemas.js","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[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AE;IAC/B,QAAQ,EAAE,+BAAc,CAAC,OAAO,EAAE;CACnC,CACF;KACE,MAAM,CAAC,CAAC,WAA8B,EAAE,OAAO,EAAE,EAAE;IAClD,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,QAAQ,EAAE;QAC7C,OAAO,OAAO,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;KAC3D;IACD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;KACD,QAAQ,CAAC;IACR,mCAAmC,EACjC,+CAA+C;CAClD,CAAC;KACD,OAAO,EAAE,CAAC"}
|
package/lib/validationUtils.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
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 type { ValidationOptions } from 'joi';
|
|
7
8
|
import type Joi from './Joi';
|
|
8
9
|
/** Print warnings returned from Joi validation. */
|
|
9
10
|
export declare function printWarning(warning?: Joi.ValidationError): void;
|
|
@@ -23,7 +24,5 @@ export declare function normalizeThemeConfig<T>(schema: Joi.ObjectSchema<T>, the
|
|
|
23
24
|
/**
|
|
24
25
|
* Validate front matter with better error message
|
|
25
26
|
*/
|
|
26
|
-
export declare function validateFrontMatter<T>(frontMatter:
|
|
27
|
-
[key: string]: unknown;
|
|
28
|
-
}, schema: Joi.ObjectSchema<T>): T;
|
|
27
|
+
export declare function validateFrontMatter<T>(frontMatter: unknown, schema: Joi.ObjectSchema<T>, options?: ValidationOptions): T;
|
|
29
28
|
//# sourceMappingURL=validationUtils.d.ts.map
|
|
@@ -1 +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,e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,CAAC,YAAY,CAAC,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,CAAC,CAwBH"}
|
package/lib/validationUtils.js
CHANGED
|
@@ -66,11 +66,12 @@ exports.normalizeThemeConfig = normalizeThemeConfig;
|
|
|
66
66
|
/**
|
|
67
67
|
* Validate front matter with better error message
|
|
68
68
|
*/
|
|
69
|
-
function validateFrontMatter(frontMatter, schema) {
|
|
69
|
+
function validateFrontMatter(frontMatter, schema, options) {
|
|
70
70
|
const { value, error, warning } = schema.validate(frontMatter, {
|
|
71
71
|
convert: true,
|
|
72
72
|
allowUnknown: true,
|
|
73
73
|
abortEarly: false,
|
|
74
|
+
...options,
|
|
74
75
|
});
|
|
75
76
|
printWarning(warning);
|
|
76
77
|
if (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wEAAwC;AACxC,8DAA2B;AAC3B,2DAAmD;
|
|
1
|
+
{"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wEAAwC;AACxC,8DAA2B;AAC3B,2DAAmD;AAInD,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,M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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;AA5BD,kDA4BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils-validation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
4
|
"description": "Node validation utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "
|
|
22
|
-
"@docusaurus/utils": "
|
|
23
|
-
"joi": "^17.
|
|
21
|
+
"@docusaurus/logger": "3.0.0-beta.0",
|
|
22
|
+
"@docusaurus/utils": "3.0.0-beta.0",
|
|
23
|
+
"joi": "^17.9.2",
|
|
24
24
|
"js-yaml": "^4.1.0",
|
|
25
|
-
"tslib": "^2.
|
|
25
|
+
"tslib": "^2.6.0"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=16.14"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "27a1e90d9fff88af90ecad35bea16d4d7230482a"
|
|
31
31
|
}
|
package/src/index.ts
CHANGED
|
@@ -20,8 +20,10 @@ export {
|
|
|
20
20
|
RemarkPluginsSchema,
|
|
21
21
|
RehypePluginsSchema,
|
|
22
22
|
AdmonitionsSchema,
|
|
23
|
+
RouteBasePathSchema,
|
|
23
24
|
URISchema,
|
|
24
25
|
PathnameSchema,
|
|
25
26
|
FrontMatterTagsSchema,
|
|
26
27
|
FrontMatterTOCHeadingLevels,
|
|
28
|
+
ContentVisibilitySchema,
|
|
27
29
|
} from './validationSchemas';
|
package/src/validationSchemas.ts
CHANGED
|
@@ -5,7 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
isValidPathname,
|
|
10
|
+
DEFAULT_PLUGIN_ID,
|
|
11
|
+
type Tag,
|
|
12
|
+
addLeadingSlash,
|
|
13
|
+
} from '@docusaurus/utils';
|
|
9
14
|
import Joi from './Joi';
|
|
10
15
|
import {JoiFrontMatter} from './JoiFrontMatter';
|
|
11
16
|
|
|
@@ -32,24 +37,21 @@ const MarkdownPluginsSchema = Joi.array()
|
|
|
32
37
|
export const RemarkPluginsSchema = MarkdownPluginsSchema;
|
|
33
38
|
export const RehypePluginsSchema = MarkdownPluginsSchema;
|
|
34
39
|
|
|
35
|
-
const LegacyAdmonitionConfigSchema = Joi.forbidden().messages({
|
|
36
|
-
'any.unknown': `The Docusaurus admonitions system has changed, and the option {#label} does not exist anymore.
|
|
37
|
-
You now need to swizzle the admonitions component to provide UI customizations such as icons.
|
|
38
|
-
Please refer to https://github.com/facebook/docusaurus/pull/7152 for detailed upgrade instructions.`,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
40
|
export const AdmonitionsSchema = JoiFrontMatter.alternatives()
|
|
42
41
|
.try(
|
|
43
42
|
JoiFrontMatter.boolean().required(),
|
|
44
43
|
JoiFrontMatter.object({
|
|
45
|
-
tag: JoiFrontMatter.string(),
|
|
46
44
|
keywords: JoiFrontMatter.array().items(
|
|
47
|
-
JoiFrontMatter.string()
|
|
45
|
+
JoiFrontMatter.string(),
|
|
46
|
+
// Apparently this is how we tell job to accept empty arrays...
|
|
47
|
+
// .required(),
|
|
48
48
|
),
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
extendDefaults: JoiFrontMatter.boolean(),
|
|
50
|
+
|
|
51
|
+
// TODO Remove before 2024
|
|
52
|
+
tag: Joi.any().forbidden().messages({
|
|
53
|
+
'any.unknown': `It is not possible anymore to use a custom admonition tag. The only admonition tag supported is ':::' (Markdown Directive syntax)`,
|
|
54
|
+
}),
|
|
53
55
|
}).required(),
|
|
54
56
|
)
|
|
55
57
|
.default(true)
|
|
@@ -89,7 +91,27 @@ export const PathnameSchema = Joi.string()
|
|
|
89
91
|
return val;
|
|
90
92
|
})
|
|
91
93
|
.message(
|
|
92
|
-
'{{#label}} is not a valid pathname. Pathname should start with slash and not contain any domain or query string.',
|
|
94
|
+
'{{#label}} ({{#value}}) is not a valid pathname. Pathname should start with slash and not contain any domain or query string.',
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// Normalized schema for url path segments: baseUrl + routeBasePath...
|
|
98
|
+
// Note we only add a leading slash
|
|
99
|
+
// we don't always want to enforce a trailing slash on urls such as /docs
|
|
100
|
+
//
|
|
101
|
+
// Examples:
|
|
102
|
+
// '' => '/'
|
|
103
|
+
// 'docs' => '/docs'
|
|
104
|
+
// '/docs' => '/docs'
|
|
105
|
+
// 'docs/' => '/docs'
|
|
106
|
+
// 'prefix/docs' => '/prefix/docs'
|
|
107
|
+
// TODO tighter validation: not all strings are valid path segments
|
|
108
|
+
export const RouteBasePathSchema = Joi
|
|
109
|
+
// Weird Joi trick needed, otherwise value '' is not normalized...
|
|
110
|
+
.alternatives()
|
|
111
|
+
.try(Joi.string().required().allow(''))
|
|
112
|
+
.custom((value: string) =>
|
|
113
|
+
// /!\ do not add trailing slash here
|
|
114
|
+
addLeadingSlash(value),
|
|
93
115
|
);
|
|
94
116
|
|
|
95
117
|
const FrontMatterTagSchema = JoiFrontMatter.alternatives()
|
|
@@ -122,3 +144,26 @@ export const FrontMatterTOCHeadingLevels = {
|
|
|
122
144
|
}),
|
|
123
145
|
toc_max_heading_level: JoiFrontMatter.number().min(2).max(6),
|
|
124
146
|
};
|
|
147
|
+
|
|
148
|
+
export type ContentVisibility = {
|
|
149
|
+
draft: boolean;
|
|
150
|
+
unlisted: boolean;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export const ContentVisibilitySchema = JoiFrontMatter.object<ContentVisibility>(
|
|
154
|
+
{
|
|
155
|
+
draft: JoiFrontMatter.boolean(),
|
|
156
|
+
unlisted: JoiFrontMatter.boolean(),
|
|
157
|
+
},
|
|
158
|
+
)
|
|
159
|
+
.custom((frontMatter: ContentVisibility, helpers) => {
|
|
160
|
+
if (frontMatter.draft && frontMatter.unlisted) {
|
|
161
|
+
return helpers.error('frontMatter.draftAndUnlistedError');
|
|
162
|
+
}
|
|
163
|
+
return frontMatter;
|
|
164
|
+
})
|
|
165
|
+
.messages({
|
|
166
|
+
'frontMatter.draftAndUnlistedError':
|
|
167
|
+
"Can't be draft and unlisted at the same time.",
|
|
168
|
+
})
|
|
169
|
+
.unknown();
|
package/src/validationUtils.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import logger from '@docusaurus/logger';
|
|
9
9
|
import Yaml from 'js-yaml';
|
|
10
10
|
import {PluginIdSchema} from './validationSchemas';
|
|
11
|
+
import type {ValidationOptions} from 'joi';
|
|
11
12
|
import type Joi from './Joi';
|
|
12
13
|
|
|
13
14
|
/** Print warnings returned from Joi validation. */
|
|
@@ -77,13 +78,15 @@ export function normalizeThemeConfig<T>(
|
|
|
77
78
|
* Validate front matter with better error message
|
|
78
79
|
*/
|
|
79
80
|
export function validateFrontMatter<T>(
|
|
80
|
-
frontMatter:
|
|
81
|
+
frontMatter: unknown,
|
|
81
82
|
schema: Joi.ObjectSchema<T>,
|
|
83
|
+
options?: ValidationOptions,
|
|
82
84
|
): T {
|
|
83
85
|
const {value, error, warning} = schema.validate(frontMatter, {
|
|
84
86
|
convert: true,
|
|
85
87
|
allowUnknown: true,
|
|
86
88
|
abortEarly: false,
|
|
89
|
+
...options,
|
|
87
90
|
});
|
|
88
91
|
|
|
89
92
|
printWarning(warning);
|