Skip to content

Commit

Permalink
refactor(core): maybeUnwrapSubscriptionReturnType function
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-sa committed Nov 28, 2023
1 parent 6dc0554 commit c87472a
Showing 1 changed file with 18 additions and 38 deletions.
56 changes: 18 additions & 38 deletions packages/core/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ export function filterReflectionParametersMetaAnnotationsForArguments(
getParentMetaAnnotationReflectionParameterIndex(argsParameters);

if (parentIndex !== -1) {
// eslint-disable-next-line functional/immutable-data
argsParameters.splice(parentIndex, 1);
}

const contextIndex =
getContextMetaAnnotationReflectionParameterIndex(argsParameters);

if (contextIndex !== -1) {
// eslint-disable-next-line functional/immutable-data
argsParameters.splice(contextIndex, 1);
}

Expand All @@ -102,67 +100,49 @@ export function excludeNullAndUndefinedTypes(
}

export function maybeUnwrapSubscriptionReturnType(type: Type): Type {
switch (type.typeName) {
case 'Generator': {
switch (true) {
case type.typeName === 'Generator': {
const typeArgument = type.typeArguments?.[0];
if (!typeArgument) {
throw new Error('Missing type argument for Generator<T>');
}
return typeArgument;
}

case 'AsyncGenerator': {
case type.typeName === 'AsyncGenerator': {
const typeArgument = type.typeArguments?.[0];
if (!typeArgument) {
throw new Error('Missing type argument for AsyncGenerator<T>');
}
return typeArgument;
}

case 'AsyncIterable': {
case type.typeName === 'AsyncIterable': {
const typeArgument = type.typeArguments?.[0];
if (!typeArgument) {
throw new Error('Missing type argument for AsyncIterable<T>');
}
return typeArgument;
}

// TODO: will be available next version of deepkit
// case BrokerBus.name: {
// const typeArgument = (type as TypeClass).typeArguments?.[0];
// if (!typeArgument) {
// throw new Error('Missing type argument for BrokerBus<T>');
// }
// return typeArgument;
// }

// TODO: will be available next version of deepkit
// case Observable.name: {
// const typeArgument = (type as TypeClass).typeArguments?.[0];
// if (!typeArgument) {
// throw new Error('Missing type argument for Observable<T>');
// }
// return typeArgument;
// }

default:
// TODO: remove when next version of deepkit is released
if ((type as TypeClass).classType === BrokerBusChannel) {
const typeArgument = type.typeArguments?.[0];
if (!typeArgument) {
throw new Error('Missing type argument for BrokerBusChannel<T>');
}
return typeArgument;
case (type as TypeClass).classType === BrokerBusChannel: {
const typeArgument = type.typeArguments?.[0];
if (!typeArgument) {
throw new Error('Missing type argument for BrokerBusChannel<T>');
}
// TODO: remove when next version of deepkit is released
if ((type as TypeClass).classType === Observable) {
const typeArgument = type.typeArguments?.[0];
if (!typeArgument) {
throw new Error('Missing type argument for Observable<T>');
}
return typeArgument;
return typeArgument;
}

case ((type as TypeClass).classType === Observable): {
const typeArgument = type.typeArguments?.[0];
if (!typeArgument) {
throw new Error('Missing type argument for Observable<T>');
}
return typeArgument;
}

default:
return type;
}
}
Expand Down

0 comments on commit c87472a

Please sign in to comment.