diff --git a/sdks/typescript/packages/sdk/src/schedule_at.ts b/sdks/typescript/packages/sdk/src/schedule_at.ts index e31dd692f5e..0cbbac29448 100644 --- a/sdks/typescript/packages/sdk/src/schedule_at.ts +++ b/sdks/typescript/packages/sdk/src/schedule_at.ts @@ -4,37 +4,47 @@ import type { AlgebraicValue } from './algebraic_value'; export namespace ScheduleAt { export function getAlgebraicType(): AlgebraicType { return AlgebraicType.createSumType([ - new SumTypeVariant('Interval', AlgebraicType.createU64Type()), - new SumTypeVariant('Time', AlgebraicType.createU64Type()), + new SumTypeVariant('Interval', AlgebraicType.createTimeDurationType()), + new SumTypeVariant('Time', AlgebraicType.createTimestampType()), ]); } - export function serialize(value: ScheduleAt): object { - switch (value.tag) { - case 'Interval': - return { Interval: value.value }; - case 'Time': - return { Time: value.value }; - default: - throw 'unreachable'; - } - } - - export type Interval = { tag: 'Interval'; value: BigInt }; + export type Interval = { + tag: 'Interval'; + value: { __time_duration_micros__: BigInt }; + }; export const Interval = (value: BigInt): Interval => ({ tag: 'Interval', - value, + value: { __time_duration_micros__: value }, + }); + export type Time = { + tag: 'Time'; + value: { __timestamp_micros_since_unix_epoch__: BigInt }; + }; + export const Time = (value: BigInt): Time => ({ + tag: 'Time', + value: { __timestamp_micros_since_unix_epoch__: value }, }); - export type Time = { tag: 'Time'; value: BigInt }; - export const Time = (value: BigInt): Time => ({ tag: 'Time', value }); export function fromValue(value: AlgebraicValue): ScheduleAt { let sumValue = value.asSumValue(); switch (sumValue.tag) { case 0: - return { tag: 'Interval', value: sumValue.value.asBigInt() }; + return { + tag: 'Interval', + value: { + __time_duration_micros__: sumValue.value + .asProductValue() + .elements[0].asBigInt(), + }, + }; case 1: - return { tag: 'Time', value: sumValue.value.asBigInt() }; + return { + tag: 'Time', + value: { + __timestamp_micros_since_unix_epoch__: sumValue.value.asBigInt(), + }, + }; default: throw 'unreachable'; }