diff --git a/packages/cli/src/plugins/constants.js b/packages/cli/src/plugins/constants.js deleted file mode 100644 index 37d0748979..0000000000 --- a/packages/cli/src/plugins/constants.js +++ /dev/null @@ -1,6 +0,0 @@ -exports.PluginTypes = { - COMPONENT: "component", - DATASOURCE: "datasource", -} - -exports.PLUGIN_TYPES_ARR = Object.values(exports.PluginTypes) diff --git a/packages/cli/src/plugins/index.js b/packages/cli/src/plugins/index.js index 643406bc4d..714187df56 100644 --- a/packages/cli/src/plugins/index.js +++ b/packages/cli/src/plugins/index.js @@ -3,8 +3,8 @@ const { CommandWords } = require("../constants") const { getSkeleton, fleshOutSkeleton } = require("./skeleton") const questions = require("../questions") const fs = require("fs") -const { PLUGIN_TYPES_ARR } = require("./constants") -const { validate } = require("./validate") +const { PLUGIN_TYPE_ARR } = require("@budibase/types") +const { validate } = require("@budibase/backend-core/plugins") const { runPkgCommand } = require("../exec") const { join } = require("path") const { success, error, info } = require("../utils") @@ -24,7 +24,7 @@ function checkInPlugin() { async function init(opts) { const type = opts["init"] || opts - if (!type || !PLUGIN_TYPES_ARR.includes(type)) { + if (!type || !PLUGIN_TYPE_ARR.includes(type)) { console.log( error( "Please provide a type to init, either 'component' or 'datasource'." diff --git a/packages/cli/src/plugins/validate.js b/packages/cli/src/plugins/validate.js deleted file mode 100644 index a6b4555cbd..0000000000 --- a/packages/cli/src/plugins/validate.js +++ /dev/null @@ -1,91 +0,0 @@ -const { PluginTypes } = require("./constants") -const { DatasourceFieldType, QueryType } = require("@budibase/types") -const joi = require("joi") - -const DATASOURCE_TYPES = [ - "Relational", - "Non-relational", - "Spreadsheet", - "Object store", - "Graph", - "API", -] - -function runJoi(validator, schema) { - const { error } = validator.validate(schema) - if (error) { - throw error - } -} - -function validateComponent(schema) { - const validator = joi.object({ - type: joi.string().allow("component").required(), - metadata: joi.object().unknown(true).required(), - hash: joi.string().optional(), - version: joi.string().optional(), - schema: joi - .object({ - name: joi.string().required(), - settings: joi.array().items(joi.object().unknown(true)).required(), - }) - .unknown(true), - }) - runJoi(validator, schema) -} - -function validateDatasource(schema) { - const fieldValidator = joi.object({ - type: joi - .string() - .allow(...Object.values(DatasourceFieldType)) - .required(), - required: joi.boolean().required(), - default: joi.any(), - display: joi.string(), - }) - - const queryValidator = joi - .object({ - type: joi.string().allow(...Object.values(QueryType)), - fields: joi.object().pattern(joi.string(), fieldValidator), - }) - .required() - - const validator = joi.object({ - type: joi.string().allow("datasource").required(), - metadata: joi.object().unknown(true).required(), - hash: joi.string().optional(), - version: joi.string().optional(), - schema: joi.object({ - docs: joi.string(), - friendlyName: joi.string().required(), - type: joi.string().allow(...DATASOURCE_TYPES), - description: joi.string().required(), - datasource: joi.object().pattern(joi.string(), fieldValidator).required(), - query: joi - .object({ - create: queryValidator, - read: queryValidator, - update: queryValidator, - delete: queryValidator, - }) - .unknown(true) - .required(), - }), - }) - runJoi(validator, schema) -} - -exports.validate = schema => { - switch (schema.type) { - case PluginTypes.COMPONENT: - validateComponent(schema) - break - case PluginTypes.DATASOURCE: - validateDatasource(schema) - break - default: - throw new Error(`Unknown plugin type - check schema.json: ${schema.type}`) - } -} diff --git a/packages/types/src/documents/plugin/index.ts b/packages/types/src/documents/plugin/index.ts index 8133e91523..2d7e480882 100644 --- a/packages/types/src/documents/plugin/index.ts +++ b/packages/types/src/documents/plugin/index.ts @@ -7,3 +7,5 @@ export interface FileType { path: string name: string } + +export const PLUGIN_TYPE_ARR = Object.values(exports.PluginType) \ No newline at end of file