ServerChildRoute.fromMeta constructor

ServerChildRoute.fromMeta(
  1. MetaMethod method
)

Implementation

factory ServerChildRoute.fromMeta(MetaMethod method) {
  ServerStatusCode? httpCode;
  ServerMimic? redirect;

  method.annotationsMapper(
    onMatch: [
      OnMatch(
        classType: StatusCode,
        package: 'revali_router_annotations',
        convert: (annotation, source) {
          if (httpCode != null) {
            throw ArgumentError(
              'Only one HttpCode annotation is allowed per method',
            );
          }

          httpCode = ServerStatusCode.fromDartObject(annotation);
        },
      ),
      OnMatch(
        classType: Redirect,
        package: 'revali_router_core',
        convert: (annotation, source) {
          if (redirect != null) {
            throw ArgumentError(
              'Only one Redirect annotation is allowed per method',
            );
          }

          redirect = ServerMimic.fromDartObject(annotation, source);
        },
      ),
    ],
  );

  final serverRoute = ServerRoute.fromMeta(method);

  if (method.isWebSocket) {
    serverRoute.annotations.removeResponseHandler();
  }

  return ServerChildRoute(
    method: method.method,
    path: method.path ?? '',
    returnType: ServerReturnType.fromMeta(method.returnType),
    httpCode: httpCode,
    redirect: redirect,
    annotations: serverRoute.annotations,
    handlerName: serverRoute.handlerName,
    params: serverRoute.params,
    webSocket: method.webSocketMethod,
    isSse: method.isSse,
  );
}