Skip to content

Commit 2ea3ba3

Browse files
ParidelPooyaPooya Paridel
andauthored
refactor(sdk): add separate serdes to InvokeConfig (#77)
- Replace single serdes with payloadSerdes and resultSerdes for type safety - Change TimeoutSeconds to timeoutSeconds for naming consistency - Update InvokeConfig to be generic InvokeConfig<I, O> - Use payloadSerdes (Serdes<I>) for input serialization - Use resultSerdes (Serdes<O>) for output deserialization *Issue #, if available:* *Description of changes:* By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. Co-authored-by: Pooya Paridel <parpooya@amazon.com>
1 parent 6aebec9 commit 2ea3ba3

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

packages/aws-durable-execution-sdk-js/src/context/durable-context/durable-context.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe("Durable Context", () => {
159159
const funcId = "arn:aws:lambda:us-east-1:123456789012:function:test";
160160
const input = { test: "data" };
161161
const config = {
162-
serdes: { serialize: async () => "test", deserialize: async () => ({}) },
162+
payloadSerdes: { serialize: async () => "test", deserialize: async () => ({}) },
163163
};
164164

165165
durableContext.invoke("test-invoke", funcId, input, config);

packages/aws-durable-execution-sdk-js/src/context/durable-context/durable-context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export const createDurableContext = (
9797
const invoke: DurableContext["invoke"] = <I, O>(
9898
nameOrFuncId: string,
9999
funcIdOrInput?: string | I,
100-
inputOrConfig?: I | InvokeConfig,
101-
maybeConfig?: InvokeConfig,
100+
inputOrConfig?: I | InvokeConfig<I, O>,
101+
maybeConfig?: InvokeConfig<I, O>,
102102
) => {
103103
const invokeHandler = createInvokeHandler(
104104
executionContext,

packages/aws-durable-execution-sdk-js/src/handlers/invoke-handler/invoke-handler.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ describe("InvokeHandler", () => {
356356
);
357357

358358
const config = {
359-
serdes: {
359+
payloadSerdes: {
360360
serialize: async () => "custom",
361361
deserialize: async () => ({}),
362362
},
363-
TimeoutSeconds: 30,
363+
timeoutSeconds: 30,
364364
};
365365

366366
await expect(

packages/aws-durable-execution-sdk-js/src/handlers/invoke-handler/invoke-handler.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ export const createInvokeHandler = (
2424
function invokeHandler<I, O>(
2525
funcId: string,
2626
input: I,
27-
config?: InvokeConfig,
27+
config?: InvokeConfig<I, O>,
2828
): Promise<O>;
2929
function invokeHandler<I, O>(
3030
name: string,
3131
funcId: string,
3232
input: I,
33-
config?: InvokeConfig,
33+
config?: InvokeConfig<I, O>,
3434
): Promise<O>;
3535
async function invokeHandler<I, O>(
3636
nameOrFuncId: string,
3737
funcIdOrInput?: string | I,
38-
inputOrConfig?: I | InvokeConfig,
39-
maybeConfig?: InvokeConfig,
38+
inputOrConfig?: I | InvokeConfig<I, O>,
39+
maybeConfig?: InvokeConfig<I, O>,
4040
): Promise<O> {
4141
const isNameFirst = typeof funcIdOrInput === "string";
4242
const name = isNameFirst ? nameOrFuncId : undefined;
4343
const funcId = isNameFirst ? (funcIdOrInput as string) : nameOrFuncId;
4444
const input = isNameFirst ? (inputOrConfig as I) : (funcIdOrInput as I);
45-
const config = isNameFirst ? maybeConfig : (inputOrConfig as InvokeConfig);
45+
const config = isNameFirst ? maybeConfig : (inputOrConfig as InvokeConfig<I, O>);
4646

4747
const stepId = createStepId();
4848

@@ -55,7 +55,7 @@ export const createInvokeHandler = (
5555
// Return cached result - no need to check for errors in successful operations
5656
const invokeDetails = stepData.InvokeDetails;
5757
return await safeDeserialize(
58-
config?.serdes || defaultSerdes,
58+
config?.resultSerdes || defaultSerdes,
5959
invokeDetails?.Result,
6060
stepId,
6161
name,
@@ -92,7 +92,7 @@ export const createInvokeHandler = (
9292
).execute(name, async (): Promise<O> => {
9393
// Serialize the input payload
9494
const serializedPayload = await safeSerialize(
95-
config?.serdes || defaultSerdes,
95+
config?.payloadSerdes || defaultSerdes,
9696
input,
9797
stepId,
9898
name,
@@ -112,7 +112,7 @@ export const createInvokeHandler = (
112112
Payload: serializedPayload,
113113
InvokeOptions: {
114114
FunctionName: funcId,
115-
...(config?.TimeoutSeconds && { TimeoutSeconds: config.TimeoutSeconds }),
115+
...(config?.timeoutSeconds && { TimeoutSeconds: config.timeoutSeconds }),
116116
},
117117
});
118118

packages/aws-durable-execution-sdk-js/src/types/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export interface DurableContext extends Context {
9696
invoke: <I, O>(
9797
nameOrFuncId: string,
9898
funcIdOrInput?: string | I,
99-
inputOrConfig?: I | InvokeConfig,
100-
maybeConfig?: InvokeConfig,
99+
inputOrConfig?: I | InvokeConfig<I, O>,
100+
maybeConfig?: InvokeConfig<I, O>,
101101
) => Promise<O>;
102102
runInChildContext: <T>(
103103
nameOrFn: string | undefined | ChildFunc<T>,
@@ -211,9 +211,10 @@ export interface WaitForCallbackConfig {
211211
serdes?: Serdes<any>;
212212
}
213213

214-
export interface InvokeConfig {
215-
serdes?: Serdes<any>;
216-
TimeoutSeconds?: number | undefined;
214+
export interface InvokeConfig<I = any, O = any> {
215+
payloadSerdes?: Serdes<I>;
216+
resultSerdes?: Serdes<O>;
217+
timeoutSeconds?: number | undefined;
217218
}
218219

219220
export type CreateCallbackResult<T> = [Promise<T>, string]; // [promise, callbackId]

0 commit comments

Comments
 (0)