Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
340 changes: 103 additions & 237 deletions crates/bindings-typescript/src/lib/algebraic_type.ts

Large diffs are not rendered by default.

3,624 changes: 3,084 additions & 540 deletions crates/bindings-typescript/src/lib/autogen/types.ts

Large diffs are not rendered by default.

36 changes: 35 additions & 1 deletion crates/bindings-typescript/src/lib/type_builders.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { AlgebraicType, type AlgebraicTypeVariants } from './algebraic_type';
import {
AlgebraicType,
registerSerde,
type AlgebraicTypeVariants,
type Deserializer,
type Serializer,
} from './algebraic_type';
import type BinaryReader from './binary_reader';
import type BinaryWriter from './binary_writer';
import { ConnectionId, type ConnectionIdAlgebraicType } from './connection_id';
Expand All @@ -12,6 +18,10 @@ import { Timestamp, type TimestampAlgebraicType } from './timestamp';
import { set, type Prettify, type SetField } from './type_util';
import { Uuid, type UuidAlgebraicType } from './uuid';

// Re-export the wrapper classes used by codegen-emitted static
// serializers/deserializers (e.g. `new __Identity(reader.readU256())`).
export { ConnectionId, Identity, TimeDuration, Timestamp, Uuid };

// Used in codegen files
export { type AlgebraicTypeType } from './algebraic_type';

Expand Down Expand Up @@ -190,6 +200,30 @@ export class TypeBuilder<Type, SpacetimeType extends AlgebraicType>
));
return deserialize(reader);
}

/**
* Install a precomputed serializer/deserializer for this type builder.
*
* Code generation calls this for named compound types (`Product` and `Sum`)
* so that the runtime never has to build serializers via a tree walker. The
* provided functions are both attached to this builder *and* registered in
* the shared {@link registerSerde} cache keyed by `this.algebraicType.value`,
* so direct callers of `AlgebraicType.makeSerializer` / `makeDeserializer`
* (e.g. the client SDK looking up a table row deserializer) pick them up
* automatically.
*/
withSerde(
serialize: Serializer<Type>,
deserialize: Deserializer<Type>
): this {
this.serialize = serialize as (writer: BinaryWriter, value: Type) => void;
this.deserialize = deserialize as (reader: BinaryReader) => Type;
const at: AlgebraicType = this.algebraicType;
if (at.tag === 'Product' || at.tag === 'Sum') {
registerSerde(at.value, serialize, deserialize);
}
return this;
}
}

/**
Expand Down
11 changes: 9 additions & 2 deletions crates/bindings-typescript/src/sdk/client_api/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading