UNPKG

@netlify/content-engine

Version:
45 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.testPluginOptionsSchema = testPluginOptionsSchema; const joi_1 = require("./joi"); const validate_1 = require("./validate"); async function testPluginOptionsSchema(pluginSchemaFunction, pluginOptions) { const pluginSchema = pluginSchemaFunction({ Joi: joi_1.Joi.extend((joi) => { return { type: `subPlugins`, base: joi .array() .items(joi.alternatives(joi.string(), joi.object({ resolve: joi_1.Joi.string(), options: joi_1.Joi.object({}).unknown(true), }))) .custom((arrayValue) => arrayValue.map((value) => { if (typeof value === `string`) { value = { resolve: value }; } return value; }), `Gatsby specific subplugin validation`) .default([]), }; }), }); try { const { warning } = await (0, validate_1.validateOptionsSchema)(pluginSchema, pluginOptions); const warnings = warning?.details?.map((detail) => detail.message) ?? []; if (warnings?.length > 0) { return { isValid: true, errors: [], hasWarnings: true, warnings, }; } } catch (e) { const errors = e?.details?.map((detail) => detail.message) ?? []; return { isValid: false, errors, hasWarnings: false, warnings: [] }; } return { isValid: true, errors: [], hasWarnings: false, warnings: [] }; } //# sourceMappingURL=test-plugin-options-schema.js.map