@monokle/validation
Advanced tools
Comparing version 0.23.0 to 0.23.1
@@ -43,5 +43,11 @@ import { ResourceParser } from './common/resourceParser.js'; | ||
default: | ||
return await customPluginLoader(pluginName, parser); | ||
try { | ||
const customPlugin = await customPluginLoader(pluginName, parser); | ||
return customPlugin; | ||
} | ||
catch (err) { | ||
throw new Error(err instanceof Error ? `plugin_not_found: ${err.message}` : `plugin_not_found: ${String(err)}`); | ||
} | ||
} | ||
}); | ||
} |
@@ -42,3 +42,9 @@ import fs from 'fs'; | ||
default: | ||
return await customPluginLoader(pluginName, parser); | ||
try { | ||
const customPlugin = await customPluginLoader(pluginName, parser); | ||
return customPlugin; | ||
} | ||
catch (err) { | ||
throw new Error(err instanceof Error ? `plugin_not_found: ${err.message}` : `plugin_not_found: ${String(err)}`); | ||
} | ||
} | ||
@@ -45,0 +51,0 @@ }); |
@@ -6,2 +6,3 @@ /** | ||
export * from './pluginLoaders/index.node.js'; | ||
export * from './utils/loadCustomPlugin.node.js'; | ||
export * from './createExtensibleMonokleValidator.node.js'; | ||
@@ -8,0 +9,0 @@ export * from './createDefaultMonokleValidator.node.js'; |
@@ -6,2 +6,3 @@ /** | ||
export * from './pluginLoaders/index.node.js'; | ||
export * from './utils/loadCustomPlugin.node.js'; | ||
export * from './createExtensibleMonokleValidator.node.js'; | ||
@@ -8,0 +9,0 @@ export * from './createDefaultMonokleValidator.node.js'; |
import { SimpleCustomValidator } from '../validators/custom/simpleValidator.js'; | ||
export const dynamicImportCustomPluginLoader = async (pluginName, parser) => { | ||
try { | ||
const url = `https://plugins.monokle.com/validation/${pluginName}/latest.js`; | ||
const customPlugin = await import(/* @vite-ignore */ url); | ||
return new SimpleCustomValidator(customPlugin.default, parser); | ||
} | ||
catch (err) { | ||
throw new Error(err instanceof Error ? `plugin_not_found: ${err.message}` : `plugin_not_found: ${String(err)}`); | ||
} | ||
const url = `https://plugins.monokle.com/validation/${pluginName}/latest.js`; | ||
const customPlugin = await import(/* @vite-ignore */ url); | ||
return new SimpleCustomValidator(customPlugin.default, parser); | ||
}; |
import { loadCustomPlugin } from '../utils/loadCustomPlugin.node.js'; | ||
import { SimpleCustomValidator } from '../validators/custom/simpleValidator.js'; | ||
export const requireFromStringCustomPluginLoader = async (pluginName, parser) => { | ||
try { | ||
const customPlugin = await loadCustomPlugin(pluginName); | ||
return new SimpleCustomValidator(customPlugin, parser); | ||
} | ||
catch (err) { | ||
throw new Error(`plugin_not_found: $err`); | ||
} | ||
const customPlugin = await loadCustomPlugin(pluginName); | ||
return new SimpleCustomValidator(customPlugin, parser); | ||
}; |
export declare function bundlePluginCode(code: string): Promise<string>; | ||
export declare function fetchCustomPluginCode(pluginName: string): Promise<string>; | ||
export declare function loadCustomPlugin(pluginName: string): Promise<any>; | ||
export declare function fetchBundleRequireCustomPlugin(pluginName: string): Promise<any>; |
@@ -20,2 +20,10 @@ import fs from 'fs'; | ||
} | ||
export async function fetchCustomPluginCode(pluginName) { | ||
const url = `https://plugins.monokle.com/validation/${pluginName}/latest.js`; | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error(`Error fetching ${url}: ${response.statusText}`); | ||
} | ||
return response.text(); | ||
} | ||
export async function loadCustomPlugin(pluginName) { | ||
@@ -25,10 +33,3 @@ const filePath = path.join(process.cwd(), '.monokle-plugins', `${pluginName}-plugin.js`); | ||
? fs.readFileSync(filePath, { encoding: 'utf-8' }) | ||
: await (async () => { | ||
const url = `https://plugins.monokle.com/validation/${pluginName}/latest.js`; | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error(`Error fetching ${url}: ${response.statusText}`); | ||
} | ||
return response.text(); | ||
})(); | ||
: await fetchCustomPluginCode(pluginName); | ||
const code = await bundlePluginCode(pluginCode); | ||
@@ -38,1 +39,7 @@ const customPlugin = requireFromString(code, filePath); | ||
} | ||
export async function fetchBundleRequireCustomPlugin(pluginName) { | ||
const pluginCode = await fetchCustomPluginCode(pluginName); | ||
const bundledCode = await bundlePluginCode(pluginCode); | ||
const customPlugin = requireFromString(bundledCode); | ||
return customPlugin; | ||
} |
{ | ||
"name": "@monokle/validation", | ||
"version": "0.23.0", | ||
"version": "0.23.1", | ||
"description": "Kubernetes resource validation", | ||
@@ -5,0 +5,0 @@ "author": "Kubeshop", |
490655
12167