UNPKG

1.26 kBPlain TextView Raw
1import type { AsyncCallOptions } from '../Async-Call'
2import { isBoolean } from './constants'
3const undefinedToTrue = (x: undefined | boolean) => (x === void 0 ? true : x)
4type NormalizedLogOptions = readonly [
5 beCalled: boolean,
6 localError: boolean,
7 remoteError: boolean,
8 isPretty?: boolean,
9 requestReplay?: boolean,
10 sendLocalStack?: boolean,
11]
12
13export const normalizeLogOptions = (log: NonNullable<AsyncCallOptions['log']>): NormalizedLogOptions | [] => {
14 if (log === 'all') return [true, true, true, true, true, true]
15 if (!isBoolean(log)) {
16 const { beCalled, localError, remoteError, type, requestReplay, sendLocalStack } = log
17 return [
18 undefinedToTrue(beCalled),
19 undefinedToTrue(localError),
20 undefinedToTrue(remoteError),
21 type !== 'basic',
22 requestReplay,
23 sendLocalStack,
24 ]
25 }
26 if (log) return [true, true, true, true] as const
27 return []
28}
29
30export const normalizeStrictOptions = (strict: NonNullable<AsyncCallOptions['strict']>) => {
31 if (!isBoolean(strict)) {
32 const { methodNotFound, unknownMessage } = strict
33 return [methodNotFound, unknownMessage] as const
34 }
35 return [strict, strict] as const
36}