Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
cool
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Sep 30, 2023
1 parent b64f5a5 commit 1a47eaf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
11 changes: 3 additions & 8 deletions src/tson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,17 @@ export function tsonStringifier(opts: TsonOptions): TsonStringifyFn {

export function tsonSerializer(opts: TsonOptions): TsonSerializeFn {
const handlers = (() => {
// warmup the type handlers
const types = opts.types.map((handler) => {
const key = handler.key as TsonTypeHandlerKey | undefined;
const serialize = handler.serialize;

type Serializer = (
value: unknown,
nonce: TsonNonce,
walk: WalkFn,
) => TsonSerializedValue;

const $serialize: Serializer = serialize
const $serialize: Serializer = handler.serialize
? (value, nonce, walk): TsonTuple => [
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
key!,
walk(serialize(value)),
handler.key as TsonTypeHandlerKey,
walk(handler.serialize(value)),
nonce,
]
: (value, _nonce, walk) => walk(value);
Expand Down
9 changes: 0 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ export interface TsonTransformerNone {
*/
key?: never;
serialize?: never;

/**
* Won't be deserialized nor serialized
*/
transform: false;
}
export interface TsonTransformerSerializeDeserialize<
TValue,
Expand All @@ -59,10 +54,6 @@ export interface TsonTransformerSerializeDeserialize<
* JSON-serializable value
*/
serialize: (v: TValue) => TSerializedType;
/**
* Use a transformer to serialize and deserialize the value?
*/
transform?: true;
}

export type TsonTransformer<TValue, TSerializedType extends SerializedType> =
Expand Down

0 comments on commit 1a47eaf

Please sign in to comment.