diff --git a/eventbridge.go b/eventbridge.go index 59a4065..4ba428b 100644 --- a/eventbridge.go +++ b/eventbridge.go @@ -53,7 +53,12 @@ func (c *EventBridgeClient) {{ .Name }}({{ .FunctionCall }}) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } {{ end }} ` diff --git a/eventbridge_gen.go b/eventbridge_gen.go index 221a496..7bc6f97 100644 --- a/eventbridge_gen.go +++ b/eventbridge_gen.go @@ -38,7 +38,12 @@ func (c *EventBridgeClient) ActivateEventSource(obj *sobek.Object,) sobek.Value panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) CancelReplay(obj *sobek.Object,) sobek.Value { @@ -52,7 +57,12 @@ func (c *EventBridgeClient) CancelReplay(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) CreateApiDestination(obj *sobek.Object,) sobek.Value { @@ -66,7 +76,12 @@ func (c *EventBridgeClient) CreateApiDestination(obj *sobek.Object,) sobek.Value panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) CreateArchive(obj *sobek.Object,) sobek.Value { @@ -80,7 +95,12 @@ func (c *EventBridgeClient) CreateArchive(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) CreateConnection(obj *sobek.Object,) sobek.Value { @@ -94,7 +114,12 @@ func (c *EventBridgeClient) CreateConnection(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) CreateEndpoint(obj *sobek.Object,) sobek.Value { @@ -108,7 +133,12 @@ func (c *EventBridgeClient) CreateEndpoint(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) CreateEventBus(obj *sobek.Object,) sobek.Value { @@ -122,7 +152,12 @@ func (c *EventBridgeClient) CreateEventBus(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) CreatePartnerEventSource(obj *sobek.Object,) sobek.Value { @@ -136,7 +171,12 @@ func (c *EventBridgeClient) CreatePartnerEventSource(obj *sobek.Object,) sobek.V panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DeactivateEventSource(obj *sobek.Object,) sobek.Value { @@ -150,7 +190,12 @@ func (c *EventBridgeClient) DeactivateEventSource(obj *sobek.Object,) sobek.Valu panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DeauthorizeConnection(obj *sobek.Object,) sobek.Value { @@ -164,7 +209,12 @@ func (c *EventBridgeClient) DeauthorizeConnection(obj *sobek.Object,) sobek.Valu panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DeleteApiDestination(obj *sobek.Object,) sobek.Value { @@ -178,7 +228,12 @@ func (c *EventBridgeClient) DeleteApiDestination(obj *sobek.Object,) sobek.Value panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DeleteArchive(obj *sobek.Object,) sobek.Value { @@ -192,7 +247,12 @@ func (c *EventBridgeClient) DeleteArchive(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DeleteConnection(obj *sobek.Object,) sobek.Value { @@ -206,7 +266,12 @@ func (c *EventBridgeClient) DeleteConnection(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DeleteEndpoint(obj *sobek.Object,) sobek.Value { @@ -220,7 +285,12 @@ func (c *EventBridgeClient) DeleteEndpoint(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DeleteEventBus(obj *sobek.Object,) sobek.Value { @@ -234,7 +304,12 @@ func (c *EventBridgeClient) DeleteEventBus(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DeletePartnerEventSource(obj *sobek.Object,) sobek.Value { @@ -248,7 +323,12 @@ func (c *EventBridgeClient) DeletePartnerEventSource(obj *sobek.Object,) sobek.V panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DeleteRule(obj *sobek.Object,) sobek.Value { @@ -262,7 +342,12 @@ func (c *EventBridgeClient) DeleteRule(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DescribeApiDestination(obj *sobek.Object,) sobek.Value { @@ -276,7 +361,12 @@ func (c *EventBridgeClient) DescribeApiDestination(obj *sobek.Object,) sobek.Val panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DescribeArchive(obj *sobek.Object,) sobek.Value { @@ -290,7 +380,12 @@ func (c *EventBridgeClient) DescribeArchive(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DescribeConnection(obj *sobek.Object,) sobek.Value { @@ -304,7 +399,12 @@ func (c *EventBridgeClient) DescribeConnection(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DescribeEndpoint(obj *sobek.Object,) sobek.Value { @@ -318,7 +418,12 @@ func (c *EventBridgeClient) DescribeEndpoint(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DescribeEventBus(obj *sobek.Object,) sobek.Value { @@ -332,7 +437,12 @@ func (c *EventBridgeClient) DescribeEventBus(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DescribeEventSource(obj *sobek.Object,) sobek.Value { @@ -346,7 +456,12 @@ func (c *EventBridgeClient) DescribeEventSource(obj *sobek.Object,) sobek.Value panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DescribePartnerEventSource(obj *sobek.Object,) sobek.Value { @@ -360,7 +475,12 @@ func (c *EventBridgeClient) DescribePartnerEventSource(obj *sobek.Object,) sobek panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DescribeReplay(obj *sobek.Object,) sobek.Value { @@ -374,7 +494,12 @@ func (c *EventBridgeClient) DescribeReplay(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DescribeRule(obj *sobek.Object,) sobek.Value { @@ -388,7 +513,12 @@ func (c *EventBridgeClient) DescribeRule(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) DisableRule(obj *sobek.Object,) sobek.Value { @@ -402,7 +532,12 @@ func (c *EventBridgeClient) DisableRule(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) EnableRule(obj *sobek.Object,) sobek.Value { @@ -416,7 +551,12 @@ func (c *EventBridgeClient) EnableRule(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListApiDestinations(obj *sobek.Object,) sobek.Value { @@ -430,7 +570,12 @@ func (c *EventBridgeClient) ListApiDestinations(obj *sobek.Object,) sobek.Value panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListArchives(obj *sobek.Object,) sobek.Value { @@ -444,7 +589,12 @@ func (c *EventBridgeClient) ListArchives(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListConnections(obj *sobek.Object,) sobek.Value { @@ -458,7 +608,12 @@ func (c *EventBridgeClient) ListConnections(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListEndpoints(obj *sobek.Object,) sobek.Value { @@ -472,7 +627,12 @@ func (c *EventBridgeClient) ListEndpoints(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListEventBuses(obj *sobek.Object,) sobek.Value { @@ -486,7 +646,12 @@ func (c *EventBridgeClient) ListEventBuses(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListEventSources(obj *sobek.Object,) sobek.Value { @@ -500,7 +665,12 @@ func (c *EventBridgeClient) ListEventSources(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListPartnerEventSourceAccounts(obj *sobek.Object,) sobek.Value { @@ -514,7 +684,12 @@ func (c *EventBridgeClient) ListPartnerEventSourceAccounts(obj *sobek.Object,) s panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListPartnerEventSources(obj *sobek.Object,) sobek.Value { @@ -528,7 +703,12 @@ func (c *EventBridgeClient) ListPartnerEventSources(obj *sobek.Object,) sobek.Va panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListReplays(obj *sobek.Object,) sobek.Value { @@ -542,7 +722,12 @@ func (c *EventBridgeClient) ListReplays(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListRuleNamesByTarget(obj *sobek.Object,) sobek.Value { @@ -556,7 +741,12 @@ func (c *EventBridgeClient) ListRuleNamesByTarget(obj *sobek.Object,) sobek.Valu panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListRules(obj *sobek.Object,) sobek.Value { @@ -570,7 +760,12 @@ func (c *EventBridgeClient) ListRules(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListTagsForResource(obj *sobek.Object,) sobek.Value { @@ -584,7 +779,12 @@ func (c *EventBridgeClient) ListTagsForResource(obj *sobek.Object,) sobek.Value panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) ListTargetsByRule(obj *sobek.Object,) sobek.Value { @@ -598,7 +798,12 @@ func (c *EventBridgeClient) ListTargetsByRule(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) PutEvents(obj *sobek.Object,) sobek.Value { @@ -612,7 +817,12 @@ func (c *EventBridgeClient) PutEvents(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) PutPartnerEvents(obj *sobek.Object,) sobek.Value { @@ -626,7 +836,12 @@ func (c *EventBridgeClient) PutPartnerEvents(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) PutPermission(obj *sobek.Object,) sobek.Value { @@ -640,7 +855,12 @@ func (c *EventBridgeClient) PutPermission(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) PutRule(obj *sobek.Object,) sobek.Value { @@ -654,7 +874,12 @@ func (c *EventBridgeClient) PutRule(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) PutTargets(obj *sobek.Object,) sobek.Value { @@ -668,7 +893,12 @@ func (c *EventBridgeClient) PutTargets(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) RemovePermission(obj *sobek.Object,) sobek.Value { @@ -682,7 +912,12 @@ func (c *EventBridgeClient) RemovePermission(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) RemoveTargets(obj *sobek.Object,) sobek.Value { @@ -696,7 +931,12 @@ func (c *EventBridgeClient) RemoveTargets(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) StartReplay(obj *sobek.Object,) sobek.Value { @@ -710,7 +950,12 @@ func (c *EventBridgeClient) StartReplay(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) TagResource(obj *sobek.Object,) sobek.Value { @@ -724,7 +969,12 @@ func (c *EventBridgeClient) TagResource(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) TestEventPattern(obj *sobek.Object,) sobek.Value { @@ -738,7 +988,12 @@ func (c *EventBridgeClient) TestEventPattern(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) UntagResource(obj *sobek.Object,) sobek.Value { @@ -752,7 +1007,12 @@ func (c *EventBridgeClient) UntagResource(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) UpdateApiDestination(obj *sobek.Object,) sobek.Value { @@ -766,7 +1026,12 @@ func (c *EventBridgeClient) UpdateApiDestination(obj *sobek.Object,) sobek.Value panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) UpdateArchive(obj *sobek.Object,) sobek.Value { @@ -780,7 +1045,12 @@ func (c *EventBridgeClient) UpdateArchive(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) UpdateConnection(obj *sobek.Object,) sobek.Value { @@ -794,7 +1064,12 @@ func (c *EventBridgeClient) UpdateConnection(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) UpdateEndpoint(obj *sobek.Object,) sobek.Value { @@ -808,7 +1083,12 @@ func (c *EventBridgeClient) UpdateEndpoint(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *EventBridgeClient) UpdateEventBus(obj *sobek.Object,) sobek.Value { @@ -822,6 +1102,11 @@ func (c *EventBridgeClient) UpdateEventBus(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } diff --git a/kinesis.go b/kinesis.go index 715335c..eb7285a 100644 --- a/kinesis.go +++ b/kinesis.go @@ -53,7 +53,12 @@ func (c *KinesisClient) {{ .Name }}({{ .FunctionCall }}) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } {{ end }} ` diff --git a/kinesis_gen.go b/kinesis_gen.go index 89e9465..956fd16 100644 --- a/kinesis_gen.go +++ b/kinesis_gen.go @@ -38,7 +38,12 @@ func (c *KinesisClient) AddTagsToStream(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) CreateStream(obj *sobek.Object,) sobek.Value { @@ -52,7 +57,12 @@ func (c *KinesisClient) CreateStream(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) DecreaseStreamRetentionPeriod(obj *sobek.Object,) sobek.Value { @@ -66,7 +76,12 @@ func (c *KinesisClient) DecreaseStreamRetentionPeriod(obj *sobek.Object,) sobek. panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) DeleteResourcePolicy(obj *sobek.Object,) sobek.Value { @@ -80,7 +95,12 @@ func (c *KinesisClient) DeleteResourcePolicy(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) DeleteStream(obj *sobek.Object,) sobek.Value { @@ -94,7 +114,12 @@ func (c *KinesisClient) DeleteStream(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) DeregisterStreamConsumer(obj *sobek.Object,) sobek.Value { @@ -108,7 +133,12 @@ func (c *KinesisClient) DeregisterStreamConsumer(obj *sobek.Object,) sobek.Value panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) DescribeLimits(obj *sobek.Object,) sobek.Value { @@ -122,7 +152,12 @@ func (c *KinesisClient) DescribeLimits(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) DescribeStream(obj *sobek.Object,) sobek.Value { @@ -136,7 +171,12 @@ func (c *KinesisClient) DescribeStream(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) DescribeStreamConsumer(obj *sobek.Object,) sobek.Value { @@ -150,7 +190,12 @@ func (c *KinesisClient) DescribeStreamConsumer(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) DescribeStreamSummary(obj *sobek.Object,) sobek.Value { @@ -164,7 +209,12 @@ func (c *KinesisClient) DescribeStreamSummary(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) DisableEnhancedMonitoring(obj *sobek.Object,) sobek.Value { @@ -178,7 +228,12 @@ func (c *KinesisClient) DisableEnhancedMonitoring(obj *sobek.Object,) sobek.Valu panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) EnableEnhancedMonitoring(obj *sobek.Object,) sobek.Value { @@ -192,7 +247,12 @@ func (c *KinesisClient) EnableEnhancedMonitoring(obj *sobek.Object,) sobek.Value panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) GetRecords(obj *sobek.Object,) sobek.Value { @@ -206,7 +266,12 @@ func (c *KinesisClient) GetRecords(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) GetResourcePolicy(obj *sobek.Object,) sobek.Value { @@ -220,7 +285,12 @@ func (c *KinesisClient) GetResourcePolicy(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) GetShardIterator(obj *sobek.Object,) sobek.Value { @@ -234,7 +304,12 @@ func (c *KinesisClient) GetShardIterator(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) IncreaseStreamRetentionPeriod(obj *sobek.Object,) sobek.Value { @@ -248,7 +323,12 @@ func (c *KinesisClient) IncreaseStreamRetentionPeriod(obj *sobek.Object,) sobek. panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) ListShards(obj *sobek.Object,) sobek.Value { @@ -262,7 +342,12 @@ func (c *KinesisClient) ListShards(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) ListStreamConsumers(obj *sobek.Object,) sobek.Value { @@ -276,7 +361,12 @@ func (c *KinesisClient) ListStreamConsumers(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) ListStreams(obj *sobek.Object,) sobek.Value { @@ -290,7 +380,12 @@ func (c *KinesisClient) ListStreams(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) ListTagsForStream(obj *sobek.Object,) sobek.Value { @@ -304,7 +399,12 @@ func (c *KinesisClient) ListTagsForStream(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) MergeShards(obj *sobek.Object,) sobek.Value { @@ -318,7 +418,12 @@ func (c *KinesisClient) MergeShards(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) PutRecord(obj *sobek.Object,) sobek.Value { @@ -332,7 +437,12 @@ func (c *KinesisClient) PutRecord(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) PutRecords(obj *sobek.Object,) sobek.Value { @@ -346,7 +456,12 @@ func (c *KinesisClient) PutRecords(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) PutResourcePolicy(obj *sobek.Object,) sobek.Value { @@ -360,7 +475,12 @@ func (c *KinesisClient) PutResourcePolicy(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) RegisterStreamConsumer(obj *sobek.Object,) sobek.Value { @@ -374,7 +494,12 @@ func (c *KinesisClient) RegisterStreamConsumer(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) RemoveTagsFromStream(obj *sobek.Object,) sobek.Value { @@ -388,7 +513,12 @@ func (c *KinesisClient) RemoveTagsFromStream(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) SplitShard(obj *sobek.Object,) sobek.Value { @@ -402,7 +532,12 @@ func (c *KinesisClient) SplitShard(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) StartStreamEncryption(obj *sobek.Object,) sobek.Value { @@ -416,7 +551,12 @@ func (c *KinesisClient) StartStreamEncryption(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) StopStreamEncryption(obj *sobek.Object,) sobek.Value { @@ -430,7 +570,12 @@ func (c *KinesisClient) StopStreamEncryption(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) SubscribeToShard(obj *sobek.Object,) sobek.Value { @@ -444,7 +589,12 @@ func (c *KinesisClient) SubscribeToShard(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) UpdateShardCount(obj *sobek.Object,) sobek.Value { @@ -458,7 +608,12 @@ func (c *KinesisClient) UpdateShardCount(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *KinesisClient) UpdateStreamMode(obj *sobek.Object,) sobek.Value { @@ -472,6 +627,11 @@ func (c *KinesisClient) UpdateStreamMode(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } diff --git a/s3.go b/s3.go index 5409281..e832a18 100644 --- a/s3.go +++ b/s3.go @@ -55,7 +55,12 @@ func (c *S3Client) {{ .Name }}({{ .FunctionCall }}) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } {{ end }} ` diff --git a/s3_gen.go b/s3_gen.go index da4c1b0..e9894e4 100644 --- a/s3_gen.go +++ b/s3_gen.go @@ -40,7 +40,12 @@ func (c *S3Client) ListBuckets(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } func (c *S3Client) ListObjects(obj *sobek.Object,) sobek.Value { @@ -54,6 +59,11 @@ func (c *S3Client) ListObjects(obj *sobek.Object,) sobek.Value { panic(err) } - return c.vu.Runtime().ToValue(out) + val, err := toSobekObject(c.vu.Runtime(), out) + if err != nil { + panic(err) + } + + return val } diff --git a/sobek.go b/sobek.go index d88032b..d95f3c5 100644 --- a/sobek.go +++ b/sobek.go @@ -2,6 +2,8 @@ package aws import ( "errors" + "fmt" + "io" "reflect" "strconv" "strings" @@ -141,6 +143,138 @@ func fromSobekObject(rt *sobek.Runtime, obj *sobek.Object, to any) error { return nil } +// Translates the given struct [from] to a [sobek.Value]. +func toSobekObject(rt *sobek.Runtime, from any) (val sobek.Value, err error) { + rv := reflect.ValueOf(from) + if rv.Kind() == reflect.Ptr { + if rv.IsNil() { + return sobek.Null(), nil + } + rv = rv.Elem() + } + + // Validate that 'from' is a struct or a pointer to a struct. + if rv.Kind() != reflect.Struct { + return nil, errors.New("[from] parameter must be a struct or a pointer to a struct") + } + + // Get the struct value and type. + structType := rv.Type() + + // Create a new *sobek.Object. + obj := rt.NewObject() + + // Iterate over the fields of the struct. + for i := 0; i < rv.NumField(); i++ { + field := rv.Field(i) + fieldType := structType.Field(i) + fieldName := pascalToSnake(fieldType.Name) + + // Skip unexported fields. + if !field.CanInterface() { + continue + } + + // Depending on the field type, we need to convert the Go value to a sobek.Value. + var jsValue sobek.Value + + switch field.Kind() { + case reflect.Ptr: + if field.IsNil() { + jsValue = sobek.Null() + break + } + + elem := field.Elem() + switch elem.Kind() { + case reflect.Struct: + jsValue, err = toSobekObject(rt, elem.Addr().Interface()) + case reflect.String: + jsValue = rt.ToValue(elem.String()) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + jsValue = rt.ToValue(elem.Int()) + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + jsValue = rt.ToValue(elem.Uint()) + case reflect.Float32, reflect.Float64: + jsValue = rt.ToValue(elem.Float()) + case reflect.Bool: + jsValue = rt.ToValue(elem.Bool()) + default: + err = fmt.Errorf("unsupported field type: %s", elem.Kind()) + } + + case reflect.Slice: + length := field.Len() + elems := make([]interface{}, length) + for j := 0; j < length; j++ { + elem := field.Index(j) + var elemVal sobek.Value + switch elem.Kind() { + case reflect.Ptr: + elemVal, err = toSobekObject(rt, elem.Interface()) + case reflect.Struct: + elemVal, err = toSobekObject(rt, elem.Interface()) + case reflect.String: + elemVal = rt.ToValue(elem.String()) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + elemVal = rt.ToValue(elem.Int()) + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + elemVal = rt.ToValue(elem.Uint()) + case reflect.Float32, reflect.Float64: + elemVal = rt.ToValue(elem.Float()) + case reflect.Bool: + elemVal = rt.ToValue(elem.Bool()) + default: + err = fmt.Errorf("unsupported field type: %s", elem.Kind()) + } + + // If there was any error while parsing the field, + // we early stop the array population. + if err != nil { + break + } + + elems[j] = elemVal + } + + jsValue = rt.NewArray(elems...) + + case reflect.Struct: + if fieldType.Type == reflect.TypeOf((*io.ReadCloser)(nil)).Elem() { + // Custom logic for io.ReadCloser. + // jsValue = handleReadCloser(rt, field.Interface().(io.ReadCloser)). + } else { + jsValue, err = toSobekObject(rt, field.Addr().Interface()) + } + case reflect.String: + jsValue = rt.ToValue(field.String()) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + jsValue = rt.ToValue(field.Int()) + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + case reflect.Float32, reflect.Float64: + jsValue = rt.ToValue(field.Float()) + case reflect.Bool: + jsValue = rt.ToValue(field.Bool()) + default: + jsValue = rt.ToValue(field.Interface()) + } + + // If there was any error while parsing the field, + // we early stop and return the error. + if err != nil { + return nil, err + } + + // The same if there is any error setting the field. + if err := obj.Set(fieldName, jsValue); err != nil { + return nil, err + } + } + + val = rt.ToValue(obj) + return val, err +} + // pascalToSnake converts a PascalCase string to snake_case. func pascalToSnake(s string) string { var snakeCase strings.Builder