diff --git a/examples/schedule.js b/examples/schedule.js index 109fa28..889d4ce 100644 --- a/examples/schedule.js +++ b/examples/schedule.js @@ -2,11 +2,23 @@ import { SchedulerClient } from '../index.js' export const createSchedule = ({ log }) => - async (scheduleName) => { + async (scheduleName, arn, roleArn) => { const client = new SchedulerClient({ log }) - return client.createSchedule(scheduleName, {}) + return client.createSchedule(scheduleName, { + scheduleExpression: 'rate(1 minute)', + flexibleTimeWindow: { mode: 'OFF' }, + input: { foo: 'bar' }, + target: { + arn, + roleArn, + eventBridgeParameters: { + detailType: 'example', + source: 'example' + } + } + }) } export const deleteSchedule = diff --git a/lib/clients/scheduler.js b/lib/clients/scheduler.js index b0873f3..c9eb0bb 100644 --- a/lib/clients/scheduler.js +++ b/lib/clients/scheduler.js @@ -7,6 +7,16 @@ import { } from '@aws-sdk/client-scheduler' import { v4 as uuidv4 } from 'uuid' import { createLogger } from '@meltwater/mlabs-logger' +import { + has, + identity, + ifElse, + isObjLike, + isObjectLike, + map, + mapPath, + pipe +} from '@meltwater/phi' import { createCache } from '../cache.js' import { keysToCamelCase, keysToPascalCase } from '../case.js' @@ -134,5 +144,34 @@ export class SchedulerClient { } } -const formatReq = keysToPascalCase -const formatRes = keysToCamelCase +const formatReq = pipe( + keysToPascalCase, + map(ifElse(isObjectLike, keysToPascalCase, identity)), + ifElse( + has('Target'), + mapPath( + ['Target'], + pipe( + keysToPascalCase, + map(ifElse(isObjectLike, keysToPascalCase, identity)) + ) + ), + identity + ) +) + +const formatRes = pipe( + keysToCamelCase, + map(ifElse(isObjectLike, keysToCamelCase, identity)), + ifElse( + has('Target'), + mapPath( + ['Target'], + pipe( + keysToCamelCase, + map(ifElse(isObjectLike, keysToCamelCase, identity)) + ) + ), + identity + ) +)