@datastax/astra-db-ts
Version:
Data API TypeScript client
22 lines (21 loc) • 1.19 kB
JavaScript
// Copyright Datastax, Inc
// SPDX-License-Identifier: Apache-2.0
import { either, exact, nullish, oneOf, optional, record } from 'decoders';
import { serDesDecoders, serdesMonoidSchema, serDesTransform, } from '../../../lib/api/ser-des/cfg-handler.js';
import { MonoidalOptionsHandler, monoids } from '../../../lib/opts-handlers.js';
import { function_ } from '../../../lib/utils.js';
const CollNumCoercions = ['number', 'strict_number', 'bigint', 'bignumber', 'string', 'number_or_string'];
const monoid = monoids.object({
...serdesMonoidSchema,
enableBigNumbers: monoids.optional(),
});
const collNumCoercionCfg = record(either(oneOf(CollNumCoercions), function_))
.refine((cfg) => '*' in cfg, 'The configuration must contain a "*" key to represent the default numerical type for an unspecified path');
const decoder = nullish(exact({
...serDesDecoders,
enableBigNumbers: optional(either(function_, collNumCoercionCfg)),
}));
const transformer = decoder.transform((input) => (input)
? { ...serDesTransform(input), enableBigNumbers: input.enableBigNumbers }
: monoid.empty);
export const CollSerDesCfgHandler = new MonoidalOptionsHandler(transformer, monoid);