@@ -21,12 +21,6 @@ predicate insert_statement($statement) {
21
21
pattern spin_fix_response() {
22
22
or {
23
23
object($properties) where {
24
- $properties <: contains bubble {
25
- pair($key, $value) where {
26
- $key <: "body",
27
- $value <: $old => js"encoder.encode($old).buffer"
28
- }
29
- },
30
24
$properties <: contains bubble {
31
25
pair($key, $value) where {
32
26
$key <: "statusCode",
@@ -37,7 +31,7 @@ pattern spin_fix_response() {
37
31
object() as $obj where {
38
32
$obj => js"{
39
33
status: 200,
40
- body: encoder.encode ($obj).buffer
34
+ body: JSON.stringify ($obj)
41
35
}"
42
36
}
43
37
}
@@ -98,16 +92,9 @@ pattern spin_main_fix_request() {
98
92
}
99
93
}
100
94
101
- pattern spin_add_encoder() {
102
- `encoder.encode` where {
103
- insert_statement(statement=js"const encoder = new TextEncoder('utf-8');")
104
- }
105
- }
106
-
107
95
sequential {
108
96
contains spin_main_fix_handler(),
109
97
maybe contains spin_main_fix_request(),
110
- maybe contains spin_add_encoder(),
111
98
maybe contains spin_remove_lambda(),
112
99
}
113
100
```
@@ -131,21 +118,17 @@ module.exports.handler = async (event) => {
131
118
```
132
119
133
120
``` js
134
- const encoder = new TextEncoder (' utf-8' );
135
-
136
121
export async function handleRequest (request ) {
137
122
return {
138
123
status: 200 ,
139
- body: encoder .encode (
140
- JSON .stringify (
141
- {
142
- message: ' Go Serverless v3.0! Your function executed successfully!' ,
143
- input: request,
144
- },
145
- null ,
146
- 2 ,
147
- ),
148
- ).buffer ,
124
+ body: JSON .stringify (
125
+ {
126
+ message: ' Go Serverless v3.0! Your function executed successfully!' ,
127
+ input: request,
128
+ },
129
+ null ,
130
+ 2 ,
131
+ ),
149
132
};
150
133
}
151
134
```
@@ -173,21 +156,17 @@ export const hello = async (event: APIGatewayProxyEvent): Promise<APIGatewayProx
173
156
``` ts
174
157
import { HttpRequest , HttpResponse } from ' @fermyon/spin-sdk' ;
175
158
176
- const encoder = new TextEncoder (' utf-8' );
177
-
178
159
export async function handleRequest(request : HttpRequest ): Promise <HttpResponse > {
179
160
return {
180
161
status: 200 ,
181
- body: encoder .encode (
182
- JSON .stringify (
183
- {
184
- message: ' Go Serverless v3.0! Your function executed successfully!' ,
185
- input: request ,
186
- },
187
- null ,
188
- 2 ,
189
- ),
190
- ).buffer ,
162
+ body: JSON .stringify (
163
+ {
164
+ message: ' Go Serverless v3.0! Your function executed successfully!' ,
165
+ input: request ,
166
+ },
167
+ null ,
168
+ 2 ,
169
+ ),
191
170
};
192
171
}
193
172
```
@@ -228,14 +207,12 @@ const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) +
228
207
229
208
const decoder = new TextDecoder (' utf-8' );
230
209
231
- const encoder = new TextEncoder (' utf-8' );
232
-
233
210
export async function handleRequest (request ) {
234
211
const upperLimit = JSON .parse (decoder .decode (request .body )).intent .slots .UpperLimit .value || 100 ;
235
212
const number = getRandomInt (0 , upperLimit);
236
213
const response = {
237
214
status: 200 ,
238
- body: encoder . encode ({
215
+ body: JSON . stringify ({
239
216
version: ' 1.0' ,
240
217
response: {
241
218
outputSpeech: {
@@ -244,7 +221,7 @@ export async function handleRequest(request) {
244
221
},
245
222
shouldEndSession: false ,
246
223
},
247
- }). buffer ,
224
+ }),
248
225
};
249
226
250
227
return response;
0 commit comments