UNPKG

@envelop/core

Version:

This is the core package for Envelop. You can find a complete documentation here: https://github.com/n1ru4l/envelop

30 lines (29 loc) 1.1 kB
import { createEnvelopOrchestrator } from './orchestrator.js'; function notEmpty(value) { return value != null; } export function envelop(options) { const plugins = options.plugins.filter(notEmpty); const orchestrator = createEnvelopOrchestrator({ plugins, parse: options.parse, execute: options.execute, validate: options.validate, subscribe: options.subscribe, }); const getEnveloped = (initialContext = {}) => { const typedOrchestrator = orchestrator; typedOrchestrator.init(initialContext); return { parse: typedOrchestrator.parse(initialContext), validate: typedOrchestrator.validate(initialContext), contextFactory: typedOrchestrator.contextFactory(initialContext), execute: typedOrchestrator.execute, subscribe: typedOrchestrator.subscribe, schema: typedOrchestrator.getCurrentSchema(), perform: typedOrchestrator.perform(initialContext), }; }; getEnveloped._plugins = plugins; return getEnveloped; }