@voxgig/sdkgen 4.32.0 → 4.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/voxgig-sdkgen +1 -1
- package/package.json +1 -1
- package/project/.sdk/tm/js/src/Response.js +14 -1
- package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +25 -0
- package/project/.sdk/tm/ts/src/Response.ts +14 -1
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +25 -0
- package/project/sdkgen-package.json +1 -1
package/bin/voxgig-sdkgen
CHANGED
package/package.json
CHANGED
|
@@ -7,13 +7,26 @@ class Response {
|
|
|
7
7
|
this.status = getprop(resmap, 'status', -1)
|
|
8
8
|
this.statusText = getprop(resmap, 'statusText', '')
|
|
9
9
|
this.headers = getprop(resmap, 'headers')
|
|
10
|
-
this.json =
|
|
10
|
+
this.json = readJson(resmap)
|
|
11
11
|
this.body = getprop(resmap, 'body')
|
|
12
12
|
this.err = getprop(resmap, 'err')
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
// An empty body, such as the one an accepted delete answers with, is no
|
|
18
|
+
// body: parsing it as JSON would throw after the call has succeeded.
|
|
19
|
+
function readJson(resmap) {
|
|
20
|
+
if ('function' === typeof resmap.text) {
|
|
21
|
+
return async () => {
|
|
22
|
+
const text = await resmap.text()
|
|
23
|
+
return '' === text.trim() ? undefined : JSON.parse(text)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return resmap.json ? resmap.json.bind(resmap) : async () => undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
17
30
|
module.exports = {
|
|
18
31
|
Response,
|
|
19
32
|
}
|
|
@@ -246,6 +246,31 @@ describe('PrimaryUtility', async () => {
|
|
|
246
246
|
})
|
|
247
247
|
|
|
248
248
|
|
|
249
|
+
// An accepted delete answers 202 with an empty body, which is no body.
|
|
250
|
+
test('resbody-empty', async () => {
|
|
251
|
+
const read = async (res) => {
|
|
252
|
+
const reqClient = new SDK({
|
|
253
|
+
base: 'http://localhost:8080',
|
|
254
|
+
system: { fetch: async () => res },
|
|
255
|
+
})
|
|
256
|
+
const reqUtility = reqClient.utility()
|
|
257
|
+
const ctx = reqUtility.makeContext({
|
|
258
|
+
opname: 'remove',
|
|
259
|
+
spec: {
|
|
260
|
+
alias: {}, base: 'http://localhost/', headers: {}, method: 'DELETE',
|
|
261
|
+
params: {}, path: '/p0', prefix: '', query: {}, suffix: '',
|
|
262
|
+
},
|
|
263
|
+
}, reqClient._rootctx)
|
|
264
|
+
ctx.client = reqClient
|
|
265
|
+
await reqUtility.makeRequest(ctx)
|
|
266
|
+
return reqUtility.resultBody(ctx)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
equal((await read(new Response('', { status: 202 }))).body, undefined)
|
|
270
|
+
deepStrictEqual((await read(new Response('{"a":1}', { status: 200 }))).body, { a: 1 })
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
|
|
249
274
|
test('request-basic', async () => {
|
|
250
275
|
const mockFetch = async (url, init) => ({
|
|
251
276
|
status: 200,
|
|
@@ -14,13 +14,26 @@ class Response {
|
|
|
14
14
|
this.status = getprop(resmap, 'status', -1)
|
|
15
15
|
this.statusText = getprop(resmap, 'statusText', '')
|
|
16
16
|
this.headers = getprop(resmap, 'headers')
|
|
17
|
-
this.json =
|
|
17
|
+
this.json = readJson(resmap)
|
|
18
18
|
this.body = getprop(resmap, 'body')
|
|
19
19
|
this.err = getprop(resmap, 'err')
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
// An empty body, such as the one an accepted delete answers with, is no
|
|
25
|
+
// body: parsing it as JSON would throw after the call has succeeded.
|
|
26
|
+
function readJson(resmap: Record<string, any>): Function {
|
|
27
|
+
if ('function' === typeof resmap.text) {
|
|
28
|
+
return async () => {
|
|
29
|
+
const text = await resmap.text()
|
|
30
|
+
return '' === text.trim() ? undefined : JSON.parse(text)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return resmap.json ? resmap.json.bind(resmap) : async () => undefined
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
24
37
|
export {
|
|
25
38
|
Response,
|
|
26
39
|
}
|
|
@@ -259,6 +259,31 @@ describe('PrimaryUtility', async () => {
|
|
|
259
259
|
})
|
|
260
260
|
|
|
261
261
|
|
|
262
|
+
// An accepted delete answers 202 with an empty body, which is no body.
|
|
263
|
+
test('resbody-empty', async () => {
|
|
264
|
+
const read = async (res: any) => {
|
|
265
|
+
const reqClient = new (SDK as any)({
|
|
266
|
+
base: 'http://localhost:8080',
|
|
267
|
+
system: { fetch: async () => res },
|
|
268
|
+
})
|
|
269
|
+
const reqUtility = reqClient.utility()
|
|
270
|
+
const ctx = reqUtility.makeContext({
|
|
271
|
+
opname: 'remove',
|
|
272
|
+
spec: {
|
|
273
|
+
alias: {}, base: 'http://localhost/', headers: {}, method: 'DELETE',
|
|
274
|
+
params: {}, path: '/p0', prefix: '', query: {}, suffix: '',
|
|
275
|
+
},
|
|
276
|
+
}, reqClient._rootctx)
|
|
277
|
+
ctx.client = reqClient
|
|
278
|
+
await reqUtility.makeRequest(ctx)
|
|
279
|
+
return reqUtility.resultBody(ctx)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
equal((await read(new Response('', { status: 202 }))).body, undefined)
|
|
283
|
+
deepStrictEqual((await read(new Response('{"a":1}', { status: 200 }))).body, { a: 1 })
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
|
|
262
287
|
test('request-basic', async () => {
|
|
263
288
|
const mockFetch = async (url: string, init: any) => ({
|
|
264
289
|
status: 200,
|