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