@pbvision/fastify-firestore-service 0.0.30 → 0.0.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pbvision/fastify-firestore-service",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "Web Framework using Fastify and Firestore ORM",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/api/db-api.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import db from '@pbvision/firestore-orm'
2
2
 
3
3
  import API from './api.js'
4
+ import { __RequestDone } from './exception.js'
4
5
 
5
6
  /**
6
7
  * Thrown to avoid committing a transaction when an error occurs.
7
8
  * @access private
8
9
  */
9
- class TransactionAborted extends Error {
10
- constructor (respData) {
11
- super()
12
- this.respData = respData
10
+ export class RequestDoneAbortTransaction extends __RequestDone {
11
+ constructor (code = 200, data = '') {
12
+ super(undefined, data, code)
13
13
  this.retryable = false
14
14
  }
15
15
  }
@@ -53,12 +53,13 @@ class DatabaseAPI extends API {
53
53
  }
54
54
  // if the response code indicates an error, then don't commit
55
55
  if (this.__reply.statusCode >= 400) {
56
- throw new TransactionAborted(respData)
56
+ throw new RequestDoneAbortTransaction(
57
+ this.__reply.statusCode, respData)
57
58
  }
58
59
  return respData
59
60
  })
60
61
  } catch (e) {
61
- if (e instanceof TransactionAborted) {
62
+ if (e instanceof RequestDoneAbortTransaction) {
62
63
  return e.respData
63
64
  } else {
64
65
  throw e
@@ -301,6 +301,7 @@ class ServiceUnavailableException extends RequestError {
301
301
 
302
302
  export {
303
303
  // Base exceptions
304
+ __RequestDone,
304
305
  RequestError,
305
306
  RequestDone,
306
307
 
@@ -1,5 +1,4 @@
1
1
  import querystring from 'node:querystring'
2
- import zlib from 'node:zlib'
3
2
 
4
3
  import realFetch from 'node-fetch'
5
4
 
@@ -8,16 +7,10 @@ async function fetchWrapper (request, mockedFetch) {
8
7
  let { body, headers } = request
9
8
  headers = { ...headers } // copy the headers before we change them
10
9
 
11
- // compress the body using brotli
12
10
  if (json) {
13
11
  headers['content-type'] = 'application/json'
14
12
  body = JSON.stringify(request.json)
15
13
  }
16
- if (body && compress) {
17
- body = zlib.brotliCompressSync(body)
18
- headers['content-encoding'] = 'br'
19
- }
20
-
21
14
  const fetch = (mockedFetch === false)
22
15
  ? realFetch
23
16
  : (mockedFetch ?? fetchWrapper.__mock ?? realFetch)
@@ -30,7 +23,7 @@ async function fetchWrapper (request, mockedFetch) {
30
23
  fullURL += `?${qsStr}`
31
24
  }
32
25
  }
33
- const options = { body, headers, method, compress: false }
26
+ const options = { body, headers, method, compress }
34
27
  return fetch(fullURL, options)
35
28
  }
36
29
 
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import API from './api/api.js'
2
- import DatabaseAPI from './api/db-api.js'
2
+ import DatabaseAPI, { RequestDoneAbortTransaction } from './api/db-api.js'
3
3
  import * as EXCEPTIONS from './api/exception.js'
4
4
  import RESPONSES from './api/response.js'
5
5
  import ComponentRegistrar from './component-registrar.js'
@@ -8,5 +8,6 @@ import makeService from './make-app.js'
8
8
  export {
9
9
  API, DatabaseAPI, EXCEPTIONS, RESPONSES,
10
10
  makeService,
11
- ComponentRegistrar
11
+ ComponentRegistrar,
12
+ RequestDoneAbortTransaction
12
13
  }
package/test/base-test.js CHANGED
@@ -152,10 +152,6 @@ function mockNodeFetch () {
152
152
  }
153
153
  delete request.headers['content-encoding']
154
154
  const body = options.body
155
- ? (request.compress
156
- ? zlib.brotliDecompressSync(options.body)
157
- : options.body)
158
- : options.body
159
155
  if (options.headers['content-type'] === 'application/json') {
160
156
  delete options.headers['content-type']
161
157
  request.json = JSON.parse(body)