This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

21
node_modules/@docusaurus/utils-validation/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) Facebook, Inc. and its affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3
node_modules/@docusaurus/utils-validation/README.md generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# `@docusaurus/utils-validation`
Node validation utility functions for Docusaurus packages.

View File

@@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export { default } from 'joi';
//# sourceMappingURL=Joi.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Joi.d.ts","sourceRoot":"","sources":["../src/Joi.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,KAAK,CAAC"}

12
node_modules/@docusaurus/utils-validation/lib/Joi.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = void 0;
var joi_1 = require("joi");
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(joi_1).default; } });
//# sourceMappingURL=Joi.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Joi.js","sourceRoot":"","sources":["../src/Joi.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2BAA4B;AAApB,+GAAA,OAAO,OAAA"}

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import Joi from './Joi';
/**
* Enhance the default `Joi.string()` type so that it can convert number to
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
* to dates automatically.
*
* @see https://github.com/facebook/docusaurus/issues/4642
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
*/
export declare const JoiFrontMatter: Joi.Root;
//# sourceMappingURL=JoiFrontMatter.d.ts.map

View File

@@ -0,0 +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"}

View File

@@ -0,0 +1,33 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.JoiFrontMatter = void 0;
const tslib_1 = require("tslib");
const Joi_1 = tslib_1.__importDefault(require("./Joi"));
const JoiFrontMatterString = {
type: 'string',
base: Joi_1.default.string(),
// Fix Yaml that tries to auto-convert many things to string out of the box
prepare: (value) => {
if (typeof value === 'number' || value instanceof Date) {
return { value: value.toString() };
}
return { value };
},
};
/**
* Enhance the default `Joi.string()` type so that it can convert number to
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
* to dates automatically.
*
* @see https://github.com/facebook/docusaurus/issues/4642
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
*/
exports.JoiFrontMatter = Joi_1.default.extend(JoiFrontMatterString);
//# sourceMappingURL=JoiFrontMatter.js.map

View File

@@ -0,0 +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"}

View File

@@ -0,0 +1,11 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export { default as Joi } from './Joi';
export { JoiFrontMatter } from './JoiFrontMatter';
export { printWarning, normalizePluginOptions, normalizeThemeConfig, validateFrontMatter, } from './validationUtils';
export { PluginIdSchema, RemarkPluginsSchema, RehypePluginsSchema, AdmonitionsSchema, RouteBasePathSchema, URISchema, PathnameSchema, FrontMatterTagsSchema, FrontMatterTOCHeadingLevels, ContentVisibilitySchema, } from './validationSchemas';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +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"}

31
node_modules/@docusaurus/utils-validation/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,31 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
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;
// /!\ don't remove this export, as we recommend plugin authors to use it
var Joi_1 = require("./Joi");
Object.defineProperty(exports, "Joi", { enumerable: true, get: function () { return __importDefault(Joi_1).default; } });
var JoiFrontMatter_1 = require("./JoiFrontMatter");
Object.defineProperty(exports, "JoiFrontMatter", { enumerable: true, get: function () { return JoiFrontMatter_1.JoiFrontMatter; } });
var validationUtils_1 = require("./validationUtils");
Object.defineProperty(exports, "printWarning", { enumerable: true, get: function () { return validationUtils_1.printWarning; } });
Object.defineProperty(exports, "normalizePluginOptions", { enumerable: true, get: function () { return validationUtils_1.normalizePluginOptions; } });
Object.defineProperty(exports, "normalizeThemeConfig", { enumerable: true, get: function () { return validationUtils_1.normalizeThemeConfig; } });
Object.defineProperty(exports, "validateFrontMatter", { enumerable: true, get: function () { return validationUtils_1.validateFrontMatter; } });
var validationSchemas_1 = require("./validationSchemas");
Object.defineProperty(exports, "PluginIdSchema", { enumerable: true, get: function () { return validationSchemas_1.PluginIdSchema; } });
Object.defineProperty(exports, "RemarkPluginsSchema", { enumerable: true, get: function () { return validationSchemas_1.RemarkPluginsSchema; } });
Object.defineProperty(exports, "RehypePluginsSchema", { enumerable: true, get: function () { return validationSchemas_1.RehypePluginsSchema; } });
Object.defineProperty(exports, "AdmonitionsSchema", { enumerable: true, get: function () { return validationSchemas_1.AdmonitionsSchema; } });
Object.defineProperty(exports, "RouteBasePathSchema", { enumerable: true, get: function () { return validationSchemas_1.RouteBasePathSchema; } });
Object.defineProperty(exports, "URISchema", { enumerable: true, get: function () { return validationSchemas_1.URISchema; } });
Object.defineProperty(exports, "PathnameSchema", { enumerable: true, get: function () { return validationSchemas_1.PathnameSchema; } });
Object.defineProperty(exports, "FrontMatterTagsSchema", { enumerable: true, get: function () { return validationSchemas_1.FrontMatterTagsSchema; } });
Object.defineProperty(exports, "FrontMatterTOCHeadingLevels", { enumerable: true, get: function () { return validationSchemas_1.FrontMatterTOCHeadingLevels; } });
Object.defineProperty(exports, "ContentVisibilitySchema", { enumerable: true, get: function () { return validationSchemas_1.ContentVisibilitySchema; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +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"}

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import Joi from './Joi';
export declare const PluginIdSchema: Joi.StringSchema<string>;
export declare const RemarkPluginsSchema: Joi.ArraySchema<any[]>;
export declare const RehypePluginsSchema: Joi.ArraySchema<any[]>;
export declare const AdmonitionsSchema: Joi.AlternativesSchema<any>;
export declare const URISchema: Joi.AlternativesSchema<any>;
export declare const PathnameSchema: Joi.StringSchema<string>;
export declare const RouteBasePathSchema: Joi.AlternativesSchema<any>;
export declare const FrontMatterTagsSchema: Joi.ArraySchema<any[]>;
export declare const FrontMatterTOCHeadingLevels: {
toc_min_heading_level: Joi.NumberSchema<number>;
toc_max_heading_level: Joi.NumberSchema<number>;
};
export type ContentVisibility = {
draft: boolean;
unlisted: boolean;
};
export declare const ContentVisibilitySchema: Joi.ObjectSchema<ContentVisibility>;
//# sourceMappingURL=validationSchemas.d.ts.map

View File

@@ -0,0 +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"}

View File

@@ -0,0 +1,125 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentVisibilitySchema = exports.FrontMatterTOCHeadingLevels = exports.FrontMatterTagsSchema = exports.RouteBasePathSchema = exports.PathnameSchema = exports.URISchema = exports.AdmonitionsSchema = exports.RehypePluginsSchema = exports.RemarkPluginsSchema = exports.PluginIdSchema = void 0;
const tslib_1 = require("tslib");
const utils_1 = require("@docusaurus/utils");
const Joi_1 = tslib_1.__importDefault(require("./Joi"));
const JoiFrontMatter_1 = require("./JoiFrontMatter");
exports.PluginIdSchema = Joi_1.default.string()
.regex(/^[\w-]+$/)
.message('Illegal plugin ID value "{#value}": it should only contain alphanumerics, underscores, and dashes.')
.default(utils_1.DEFAULT_PLUGIN_ID);
const MarkdownPluginsSchema = Joi_1.default.array()
.items(Joi_1.default.array().ordered(Joi_1.default.function().required(), Joi_1.default.any().required()), Joi_1.default.function(), Joi_1.default.object())
.messages({
'array.includes': `{#label} does not look like a valid MDX plugin config. A plugin config entry should be one of:
- A tuple, like \`[require("rehype-katex"), \\{ strict: false \\}]\`, or
- A simple module, like \`require("remark-math")\``,
})
.default([]);
exports.RemarkPluginsSchema = MarkdownPluginsSchema;
exports.RehypePluginsSchema = MarkdownPluginsSchema;
exports.AdmonitionsSchema = JoiFrontMatter_1.JoiFrontMatter.alternatives()
.try(JoiFrontMatter_1.JoiFrontMatter.boolean().required(), JoiFrontMatter_1.JoiFrontMatter.object({
keywords: JoiFrontMatter_1.JoiFrontMatter.array().items(JoiFrontMatter_1.JoiFrontMatter.string()),
extendDefaults: JoiFrontMatter_1.JoiFrontMatter.boolean(),
// TODO Remove before 2024
tag: Joi_1.default.any().forbidden().messages({
'any.unknown': `It is not possible anymore to use a custom admonition tag. The only admonition tag supported is ':::' (Markdown Directive syntax)`,
}),
}).required())
.default(true)
.messages({
'alternatives.types': '{{#label}} does not look like a valid admonitions config',
});
// TODO how can we make this emit a custom error message :'(
// Joi is such a pain, good luck to annoying trying to improve this
exports.URISchema = Joi_1.default.alternatives(Joi_1.default.string().uri({ allowRelative: true }),
// This custom validation logic is required notably because Joi does not
// accept paths like /a/b/c ...
Joi_1.default.custom((val, helpers) => {
if (typeof val !== 'string') {
return helpers.error('any.invalid');
}
try {
// eslint-disable-next-line no-new
new URL(String(val));
return val;
}
catch {
return helpers.error('any.invalid');
}
})).messages({
'alternatives.match': "{{#label}} does not look like a valid url (value='{{.value}}')",
});
exports.PathnameSchema = Joi_1.default.string()
.custom((val) => {
if (!(0, utils_1.isValidPathname)(val)) {
throw new Error();
}
return val;
})
.message('{{#label}} ({{#value}}) is not a valid pathname. Pathname should start with slash and not contain any domain or query string.');
// Normalized schema for url path segments: baseUrl + routeBasePath...
// Note we only add a leading slash
// we don't always want to enforce a trailing slash on urls such as /docs
//
// Examples:
// '' => '/'
// 'docs' => '/docs'
// '/docs' => '/docs'
// 'docs/' => '/docs'
// 'prefix/docs' => '/prefix/docs'
// TODO tighter validation: not all strings are valid path segments
exports.RouteBasePathSchema = Joi_1.default
// Weird Joi trick needed, otherwise value '' is not normalized...
.alternatives()
.try(Joi_1.default.string().required().allow(''))
.custom((value) =>
// /!\ do not add trailing slash here
(0, utils_1.addLeadingSlash)(value));
const FrontMatterTagSchema = JoiFrontMatter_1.JoiFrontMatter.alternatives()
.try(JoiFrontMatter_1.JoiFrontMatter.string().required(), JoiFrontMatter_1.JoiFrontMatter.object({
label: JoiFrontMatter_1.JoiFrontMatter.string().required(),
permalink: JoiFrontMatter_1.JoiFrontMatter.string().required(),
}).required())
.messages({
'alternatives.match': '{{#label}} does not look like a valid tag',
'alternatives.types': '{{#label}} does not look like a valid tag',
});
exports.FrontMatterTagsSchema = JoiFrontMatter_1.JoiFrontMatter.array()
.items(FrontMatterTagSchema)
.messages({
'array.base': '{{#label}} does not look like a valid front matter Yaml array.',
});
exports.FrontMatterTOCHeadingLevels = {
toc_min_heading_level: JoiFrontMatter_1.JoiFrontMatter.number().when('toc_max_heading_level', {
is: JoiFrontMatter_1.JoiFrontMatter.exist(),
then: JoiFrontMatter_1.JoiFrontMatter.number()
.min(2)
.max(JoiFrontMatter_1.JoiFrontMatter.ref('toc_max_heading_level')),
otherwise: JoiFrontMatter_1.JoiFrontMatter.number().min(2).max(6),
}),
toc_max_heading_level: JoiFrontMatter_1.JoiFrontMatter.number().min(2).max(6),
};
exports.ContentVisibilitySchema = JoiFrontMatter_1.JoiFrontMatter.object({
draft: JoiFrontMatter_1.JoiFrontMatter.boolean(),
unlisted: JoiFrontMatter_1.JoiFrontMatter.boolean(),
})
.custom((frontMatter, helpers) => {
if (frontMatter.draft && frontMatter.unlisted) {
return helpers.error('frontMatter.draftAndUnlistedError');
}
return frontMatter;
})
.messages({
'frontMatter.draftAndUnlistedError': "Can't be draft and unlisted at the same time.",
})
.unknown();
//# sourceMappingURL=validationSchemas.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"validationSchemas.js","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6CAK2B;AAC3B,wDAAwB;AACxB,qDAAgD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AAC,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"}

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { ValidationOptions } from 'joi';
import type Joi from './Joi';
/** Print warnings returned from Joi validation. */
export declare function printWarning(warning?: Joi.ValidationError): void;
/**
* The callback that should be used to validate plugin options. Handles plugin
* IDs on a generic level: no matter what the schema declares, this callback
* would require a string ID or default to "default".
*/
export declare function normalizePluginOptions<T extends {
id?: string;
}>(schema: Joi.ObjectSchema<T>, options?: Partial<T>): T;
/**
* The callback that should be used to validate theme config. No matter what the
* schema declares, this callback would allow unknown attributes.
*/
export declare function normalizeThemeConfig<T>(schema: Joi.ObjectSchema<T>, themeConfig: Partial<T>): T;
/**
* Validate front matter with better error message
*/
export declare function validateFrontMatter<T>(frontMatter: unknown, schema: Joi.ObjectSchema<T>, options?: ValidationOptions): T;
//# sourceMappingURL=validationUtils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,KAAK,CAAC;AAC3C,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,OAAO,EACpB,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,CAAC,CAwBH"}

View File

@@ -0,0 +1,91 @@
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning = void 0;
const tslib_1 = require("tslib");
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
const validationSchemas_1 = require("./validationSchemas");
/** Print warnings returned from Joi validation. */
function printWarning(warning) {
if (warning) {
const warningMessages = warning.details
.map(({ message }) => message)
.join('\n');
logger_1.default.warn(warningMessages);
}
}
exports.printWarning = printWarning;
/**
* The callback that should be used to validate plugin options. Handles plugin
* IDs on a generic level: no matter what the schema declares, this callback
* would require a string ID or default to "default".
*/
function normalizePluginOptions(schema,
// This allows us to automatically normalize undefined to { id: "default" }
options = {}) {
// All plugins can be provided an "id" option (multi-instance support)
// we add schema validation automatically
const finalSchema = schema.append({
id: validationSchemas_1.PluginIdSchema,
});
const { error, warning, value } = finalSchema.validate(options, {
convert: false,
});
printWarning(warning);
if (error) {
throw error;
}
return value;
}
exports.normalizePluginOptions = normalizePluginOptions;
/**
* The callback that should be used to validate theme config. No matter what the
* schema declares, this callback would allow unknown attributes.
*/
function normalizeThemeConfig(schema, themeConfig) {
// A theme should only validate its "slice" of the full themeConfig,
// not the whole object, so we allow unknown attributes
// otherwise one theme would fail validating the data of another theme
const finalSchema = schema.unknown();
const { error, warning, value } = finalSchema.validate(themeConfig, {
convert: false,
});
printWarning(warning);
if (error) {
throw error;
}
return value;
}
exports.normalizeThemeConfig = normalizeThemeConfig;
/**
* Validate front matter with better error message
*/
function validateFrontMatter(frontMatter, schema, options) {
const { value, error, warning } = schema.validate(frontMatter, {
convert: true,
allowUnknown: true,
abortEarly: false,
...options,
});
printWarning(warning);
if (error) {
const errorDetails = error.details;
const invalidFields = errorDetails.map(({ path }) => path).join(', ');
logger_1.default.error `The following front matter:
---
${js_yaml_1.default.dump(frontMatter)}---
contains invalid values for field(s): code=${invalidFields}.
${errorDetails.map(({ message }) => message)}
`;
throw error;
}
return value;
}
exports.validateFrontMatter = validateFrontMatter;
//# sourceMappingURL=validationUtils.js.map

View File

@@ -0,0 +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,sEAA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,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;AA5BD,kDA4BC"}

31
node_modules/@docusaurus/utils-validation/package.json generated vendored Normal file
View File

@@ -0,0 +1,31 @@
{
"name": "@docusaurus/utils-validation",
"version": "3.1.1",
"description": "Node validation utility functions for Docusaurus packages.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/docusaurus.git",
"directory": "packages/docusaurus-utils-validation"
},
"license": "MIT",
"dependencies": {
"@docusaurus/logger": "3.1.1",
"@docusaurus/utils": "3.1.1",
"joi": "^17.9.2",
"js-yaml": "^4.1.0",
"tslib": "^2.6.0"
},
"engines": {
"node": ">=18.0"
},
"gitHead": "8017f6a6776ba1bd7065e630a52fe2c2654e2f1b"
}

8
node_modules/@docusaurus/utils-validation/src/Joi.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export {default} from 'joi';

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import Joi from './Joi';
const JoiFrontMatterString: Joi.Extension = {
type: 'string',
base: Joi.string(),
// Fix Yaml that tries to auto-convert many things to string out of the box
prepare: (value: unknown) => {
if (typeof value === 'number' || value instanceof Date) {
return {value: value.toString()};
}
return {value};
},
};
/**
* Enhance the default `Joi.string()` type so that it can convert number to
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
* to dates automatically.
*
* @see https://github.com/facebook/docusaurus/issues/4642
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
*/
export const JoiFrontMatter = Joi.extend(JoiFrontMatterString) as typeof Joi;

29
node_modules/@docusaurus/utils-validation/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1,29 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// /!\ don't remove this export, as we recommend plugin authors to use it
export {default as Joi} from './Joi';
export {JoiFrontMatter} from './JoiFrontMatter';
export {
printWarning,
normalizePluginOptions,
normalizeThemeConfig,
validateFrontMatter,
} from './validationUtils';
export {
PluginIdSchema,
RemarkPluginsSchema,
RehypePluginsSchema,
AdmonitionsSchema,
RouteBasePathSchema,
URISchema,
PathnameSchema,
FrontMatterTagsSchema,
FrontMatterTOCHeadingLevels,
ContentVisibilitySchema,
} from './validationSchemas';

View File

@@ -0,0 +1,169 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {
isValidPathname,
DEFAULT_PLUGIN_ID,
type Tag,
addLeadingSlash,
} from '@docusaurus/utils';
import Joi from './Joi';
import {JoiFrontMatter} from './JoiFrontMatter';
export const PluginIdSchema = Joi.string()
.regex(/^[\w-]+$/)
.message(
'Illegal plugin ID value "{#value}": it should only contain alphanumerics, underscores, and dashes.',
)
.default(DEFAULT_PLUGIN_ID);
const MarkdownPluginsSchema = Joi.array()
.items(
Joi.array().ordered(Joi.function().required(), Joi.any().required()),
Joi.function(),
Joi.object(),
)
.messages({
'array.includes': `{#label} does not look like a valid MDX plugin config. A plugin config entry should be one of:
- A tuple, like \`[require("rehype-katex"), \\{ strict: false \\}]\`, or
- A simple module, like \`require("remark-math")\``,
})
.default([]);
export const RemarkPluginsSchema = MarkdownPluginsSchema;
export const RehypePluginsSchema = MarkdownPluginsSchema;
export const AdmonitionsSchema = JoiFrontMatter.alternatives()
.try(
JoiFrontMatter.boolean().required(),
JoiFrontMatter.object({
keywords: JoiFrontMatter.array().items(
JoiFrontMatter.string(),
// Apparently this is how we tell job to accept empty arrays...
// .required(),
),
extendDefaults: JoiFrontMatter.boolean(),
// TODO Remove before 2024
tag: Joi.any().forbidden().messages({
'any.unknown': `It is not possible anymore to use a custom admonition tag. The only admonition tag supported is ':::' (Markdown Directive syntax)`,
}),
}).required(),
)
.default(true)
.messages({
'alternatives.types':
'{{#label}} does not look like a valid admonitions config',
});
// TODO how can we make this emit a custom error message :'(
// Joi is such a pain, good luck to annoying trying to improve this
export const URISchema = Joi.alternatives(
Joi.string().uri({allowRelative: true}),
// This custom validation logic is required notably because Joi does not
// accept paths like /a/b/c ...
Joi.custom((val: unknown, helpers) => {
if (typeof val !== 'string') {
return helpers.error('any.invalid');
}
try {
// eslint-disable-next-line no-new
new URL(String(val));
return val;
} catch {
return helpers.error('any.invalid');
}
}),
).messages({
'alternatives.match':
"{{#label}} does not look like a valid url (value='{{.value}}')",
});
export const PathnameSchema = Joi.string()
.custom((val: string) => {
if (!isValidPathname(val)) {
throw new Error();
}
return val;
})
.message(
'{{#label}} ({{#value}}) is not a valid pathname. Pathname should start with slash and not contain any domain or query string.',
);
// Normalized schema for url path segments: baseUrl + routeBasePath...
// Note we only add a leading slash
// we don't always want to enforce a trailing slash on urls such as /docs
//
// Examples:
// '' => '/'
// 'docs' => '/docs'
// '/docs' => '/docs'
// 'docs/' => '/docs'
// 'prefix/docs' => '/prefix/docs'
// TODO tighter validation: not all strings are valid path segments
export const RouteBasePathSchema = Joi
// Weird Joi trick needed, otherwise value '' is not normalized...
.alternatives()
.try(Joi.string().required().allow(''))
.custom((value: string) =>
// /!\ do not add trailing slash here
addLeadingSlash(value),
);
const FrontMatterTagSchema = JoiFrontMatter.alternatives()
.try(
JoiFrontMatter.string().required(),
JoiFrontMatter.object<Tag>({
label: JoiFrontMatter.string().required(),
permalink: JoiFrontMatter.string().required(),
}).required(),
)
.messages({
'alternatives.match': '{{#label}} does not look like a valid tag',
'alternatives.types': '{{#label}} does not look like a valid tag',
});
export const FrontMatterTagsSchema = JoiFrontMatter.array()
.items(FrontMatterTagSchema)
.messages({
'array.base':
'{{#label}} does not look like a valid front matter Yaml array.',
});
export const FrontMatterTOCHeadingLevels = {
toc_min_heading_level: JoiFrontMatter.number().when('toc_max_heading_level', {
is: JoiFrontMatter.exist(),
then: JoiFrontMatter.number()
.min(2)
.max(JoiFrontMatter.ref('toc_max_heading_level')),
otherwise: JoiFrontMatter.number().min(2).max(6),
}),
toc_max_heading_level: JoiFrontMatter.number().min(2).max(6),
};
export type ContentVisibility = {
draft: boolean;
unlisted: boolean;
};
export const ContentVisibilitySchema = JoiFrontMatter.object<ContentVisibility>(
{
draft: JoiFrontMatter.boolean(),
unlisted: JoiFrontMatter.boolean(),
},
)
.custom((frontMatter: ContentVisibility, helpers) => {
if (frontMatter.draft && frontMatter.unlisted) {
return helpers.error('frontMatter.draftAndUnlistedError');
}
return frontMatter;
})
.messages({
'frontMatter.draftAndUnlistedError':
"Can't be draft and unlisted at the same time.",
})
.unknown();

View File

@@ -0,0 +1,108 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import logger from '@docusaurus/logger';
import Yaml from 'js-yaml';
import {PluginIdSchema} from './validationSchemas';
import type {ValidationOptions} from 'joi';
import type Joi from './Joi';
/** Print warnings returned from Joi validation. */
export function printWarning(warning?: Joi.ValidationError): void {
if (warning) {
const warningMessages = warning.details
.map(({message}) => message)
.join('\n');
logger.warn(warningMessages);
}
}
/**
* The callback that should be used to validate plugin options. Handles plugin
* IDs on a generic level: no matter what the schema declares, this callback
* would require a string ID or default to "default".
*/
export function normalizePluginOptions<T extends {id?: string}>(
schema: Joi.ObjectSchema<T>,
// This allows us to automatically normalize undefined to { id: "default" }
options: Partial<T> = {},
): T {
// All plugins can be provided an "id" option (multi-instance support)
// we add schema validation automatically
const finalSchema = schema.append({
id: PluginIdSchema,
});
const {error, warning, value} = finalSchema.validate(options, {
convert: false,
});
printWarning(warning);
if (error) {
throw error;
}
return value;
}
/**
* The callback that should be used to validate theme config. No matter what the
* schema declares, this callback would allow unknown attributes.
*/
export function normalizeThemeConfig<T>(
schema: Joi.ObjectSchema<T>,
themeConfig: Partial<T>,
): T {
// A theme should only validate its "slice" of the full themeConfig,
// not the whole object, so we allow unknown attributes
// otherwise one theme would fail validating the data of another theme
const finalSchema = schema.unknown();
const {error, warning, value} = finalSchema.validate(themeConfig, {
convert: false,
});
printWarning(warning);
if (error) {
throw error;
}
return value;
}
/**
* Validate front matter with better error message
*/
export function validateFrontMatter<T>(
frontMatter: unknown,
schema: Joi.ObjectSchema<T>,
options?: ValidationOptions,
): T {
const {value, error, warning} = schema.validate(frontMatter, {
convert: true,
allowUnknown: true,
abortEarly: false,
...options,
});
printWarning(warning);
if (error) {
const errorDetails = error.details;
const invalidFields = errorDetails.map(({path}) => path).join(', ');
logger.error`The following front matter:
---
${Yaml.dump(frontMatter)}---
contains invalid values for field(s): code=${invalidFields}.
${errorDetails.map(({message}) => message)}
`;
throw error;
}
return value;
}