@envelop/core
Advanced tools
Comparing version 5.0.1 to 5.0.2-alpha-20240820115508-6d2d9e8f0ae9bc143dfbb61da9176712731212ce
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.errorAsyncIterator = exports.finalAsyncIterator = exports.handleStreamOrSingleExecutionResult = exports.isAsyncIterable = exports.makeExecute = exports.mapAsyncIterator = exports.makeSubscribe = exports.isIntrospectionOperationString = exports.envelopIsIntrospectionSymbol = void 0; | ||
exports.mapMaybePromise = exports.isPromise = exports.errorAsyncIterator = exports.finalAsyncIterator = exports.handleStreamOrSingleExecutionResult = exports.isAsyncIterable = exports.makeExecute = exports.mapAsyncIterator = exports.makeSubscribe = exports.isIntrospectionOperationString = exports.envelopIsIntrospectionSymbol = void 0; | ||
exports.envelopIsIntrospectionSymbol = Symbol('ENVELOP_IS_INTROSPECTION'); | ||
@@ -189,1 +189,28 @@ function isIntrospectionOperationString(operation) { | ||
exports.errorAsyncIterator = errorAsyncIterator; | ||
function isPromise(value) { | ||
return value?.then !== undefined; | ||
} | ||
exports.isPromise = isPromise; | ||
function mapMaybePromise(value, mapper, errorMapper) { | ||
if (isPromise(value)) { | ||
if (errorMapper) { | ||
try { | ||
return value.then(mapper, errorMapper); | ||
} | ||
catch (e) { | ||
return errorMapper(e); | ||
} | ||
} | ||
return value.then(mapper); | ||
} | ||
if (errorMapper) { | ||
try { | ||
return mapper(value); | ||
} | ||
catch (e) { | ||
return errorMapper(e); | ||
} | ||
} | ||
return mapper(value); | ||
} | ||
exports.mapMaybePromise = mapMaybePromise; |
@@ -178,1 +178,26 @@ export const envelopIsIntrospectionSymbol = Symbol('ENVELOP_IS_INTROSPECTION'); | ||
} | ||
export function isPromise(value) { | ||
return value?.then !== undefined; | ||
} | ||
export function mapMaybePromise(value, mapper, errorMapper) { | ||
if (isPromise(value)) { | ||
if (errorMapper) { | ||
try { | ||
return value.then(mapper, errorMapper); | ||
} | ||
catch (e) { | ||
return errorMapper(e); | ||
} | ||
} | ||
return value.then(mapper); | ||
} | ||
if (errorMapper) { | ||
try { | ||
return mapper(value); | ||
} | ||
catch (e) { | ||
return errorMapper(e); | ||
} | ||
} | ||
return mapper(value); | ||
} |
{ | ||
"name": "@envelop/core", | ||
"version": "5.0.1", | ||
"version": "5.0.2-alpha-20240820115508-6d2d9e8f0ae9bc143dfbb61da9176712731212ce", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -30,1 +30,3 @@ import { AsyncIterableIteratorOrValue, DefaultContext, ExecuteFunction, ExecutionArgs, OnExecuteDoneEventPayload, OnExecuteDoneHookResult, OnExecuteDoneHookResultOnNextHook, PromiseOrValue, SubscribeFunction } from '@envelop/types'; | ||
export declare function errorAsyncIterator<TInput>(source: AsyncIterable<TInput>, onError: (err: unknown) => void): AsyncGenerator<TInput>; | ||
export declare function isPromise<T>(value: any): value is Promise<T>; | ||
export declare function mapMaybePromise<T, R>(value: PromiseOrValue<T>, mapper: (v: T) => PromiseOrValue<R>, errorMapper?: (e: any) => PromiseOrValue<R>): PromiseOrValue<R>; |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
91970
2125
2