Interface BaseSerDesConfig<SerCtx, DesCtx>

interface BaseSerDesConfig<SerCtx, DesCtx> {
    codecs?: (readonly RawCodec<SerCtx, DesCtx>[])[];
    mutateInPlace?: boolean;
}

Type Parameters

Hierarchy (view full)

Properties

codecs?: (readonly RawCodec<SerCtx, DesCtx>[])[]
Overview (Alpha)

Provides a structured interface for integrating custom serialization/deserialization logic for documents/rows, filters, ids, etc.

You may create implementations of these codecs through the TableCodecs and CollectionCodecs classes.

See TableSerDesConfig.codecs & CollectionSerDesConfig.codecs for much more information.

Disclaimer

Codecs are a powerful feature, but should be used with caution. It's possible to break the client's behavior by using the features incorrectly.

Always test your codecs with a variety of documents to ensure that they behave as expected, before using them on real data.

mutateInPlace?: boolean
Overview

Enables an optimization which allows inserted rows/documents to be mutated in-place when serializing.

The feature is stable; however, the state of any document after being serialized is not guaranteed.

This will mutate filters and update filters as well.

Context

For example, when you insert a record like so:

import { uuid } from '@datastax/astra-db-ts';
await collection.insertOne({ name: 'Alice', friends: { john: uuid('...') } });

The document is internally serialized as such:

{ name: 'Alice', friends: { john: { $uuid: '...' } } }

To avoid mutating a user-provided object, the client will be forced to clone any objects that contain a custom datatype, as well as their parents (which looks something like this):

{ ...original, friends: { ...original.friends, john: { $uuid: '...' } } }
Enabling this option

This can be a minor performance hit, especially for large objects, so if you're confident that you won't be needing the object after it's inserted, you can enable this option to avoid the cloning, and instead mutate the object in-place.

Example

// Before
const collection = db.collection<User>('users');

const doc = { name: 'Alice', friends: { john: uuid(4) } };
await collection.insertOne(doc);

console.log(doc); // { name: 'Alice', friends: { john: UUID<4>('...') } }

// After
const collection = db.collection<User>('users', {
  serdes: { mutateInPlace: true },
});

const doc = { name: 'Alice', friends: { john: UUID.v4() } };
await collection.insertOne(doc);

console.log(doc); // { name: 'Alice', friends: { john: { $uuid: '...' } } }

Default Value

false