ClientMethod.fromMeta constructor

ClientMethod.fromMeta(
  1. MetaMethod route,
  2. String parentPath,
  3. List<ClientLifecycleComponent> parentComponents
)

Implementation

factory ClientMethod.fromMeta(
  MetaMethod route,
  String parentPath,
  List<ClientLifecycleComponent> parentComponents,
) {
  final lifecycleComponents = <ClientLifecycleComponent>[...parentComponents];
  var isExcluded = false;

  route.annotationsFor(
    onMatch: [
      OnMatch(
        classType: LifecycleComponent,
        package: 'revali_router_annotations',
        convert: (object, annotation) {
          final component = ClientLifecycleComponent.fromDartObject(
            annotation,
          );

          lifecycleComponents.add(component);
        },
      ),
      OnMatch(
        classType: ExcludeFromClient,
        package: 'revali_client',
        convert: (object, annotation) {
          isExcluded = true;
        },
      ),
    ],
  );

  return ClientMethod(
    name: route.name,
    parentPath: parentPath,
    method: route.method,
    returnType: ClientType.fromMeta(route.returnType),
    parameters: ClientParam.fromMetas(route.params),
    websocketType: switch (route.webSocketMethod) {
      null => WebsocketType.none,
      final w when w.mode.isReceiveOnly => WebsocketType.canSendOnly,
      final w when w.mode.isSendOnly => WebsocketType.canReceiveOnly,
      final w when w.mode.isTwoWay => WebsocketType.canSendAndReceive,
      _ => WebsocketType.none,
    },
    isSse: route.isSse,
    path: route.path,
    lifecycleComponents: lifecycleComponents,
    isExcluded: isExcluded,
  );
}