@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 CHANGED
@@ -8,7 +8,7 @@ const { Shape, One, Skip } = require('shape')
8
8
 
9
9
  const { SdkGen } = require('../dist/sdkgen.js')
10
10
 
11
- const VERSION = '4.32.0'
11
+ const VERSION = '4.32.1'
12
12
  const KONSOLE = console
13
13
 
14
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxgig/sdkgen",
3
- "version": "4.32.0",
3
+ "version": "4.32.1",
4
4
  "main": "dist/sdkgen.js",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -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 = resmap.json ? resmap.json.bind(resmap) : async () => undefined
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 = resmap.json ? resmap.json.bind(resmap) : async () => undefined
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,
@@ -3,7 +3,7 @@
3
3
  "package": 1
4
4
  },
5
5
  "name": "@voxgig/sdkgen",
6
- "version": "4.32.0",
6
+ "version": "4.32.1",
7
7
  "provides": {
8
8
  "target": [
9
9
  "c",