@envelop/core
Version:
This is the core package for Envelop. You can find a complete documentation here: https://github.com/n1ru4l/envelop
31 lines (30 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.envelop = envelop;
const instruments_1 = require("@envelop/instruments");
const orchestrator_js_1 = require("./orchestrator.js");
function notEmpty(value) {
return value != null;
}
function envelop(options) {
const plugins = options.plugins.filter(notEmpty);
const orchestrator = (0, orchestrator_js_1.createEnvelopOrchestrator)({
plugins,
});
const instruments = orchestrator.instruments;
const getEnveloped = (context = {}) => {
const instrumented = (0, instruments_1.getInstrumented)({ context });
const typedOrchestrator = orchestrator;
instrumented.fn(instruments?.init, orchestrator.init)(context);
return {
parse: instrumented.fn(instruments?.parse, typedOrchestrator.parse(context)),
validate: instrumented.fn(instruments?.validate, typedOrchestrator.validate(context)),
contextFactory: instrumented.fn(instruments?.context, typedOrchestrator.contextFactory(context)),
execute: instrumented.asyncFn(instruments?.execute, typedOrchestrator.execute),
subscribe: instrumented.asyncFn(instruments?.subscribe, typedOrchestrator.subscribe),
schema: typedOrchestrator.getCurrentSchema(),
};
};
getEnveloped._plugins = plugins;
return getEnveloped;
}