File size: 645 Bytes
b39afbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
 * Copyright (c) 2023 MERCENARIES.AI PTE. LTD.
 * All rights reserved.
 */

import CustomSocket from './CustomSocket';
import { type WorkerContext } from '../openapi/types';

class PrimitiveSocket extends CustomSocket {
  async handleInput(ctx: WorkerContext, value: any): Promise<any | null> {
    if (Array.isArray(value)) {
      value = value[0]; // If array is passed in, just take the first element.
    }
    return value;
  }

  async handleOutput(ctx: WorkerContext, value: any): Promise<any | null> {
    return await this.handleInput(ctx, value); // Use the same logic for input and output.
  }
}

export default PrimitiveSocket;