geonix 1.10.7 → 1.10.9

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/index.d.ts CHANGED
@@ -61,7 +61,7 @@ declare class Connection {
61
61
  }
62
62
  export {};
63
63
  export class Gateway {
64
- static start(): Gateway;
64
+ static start(opts: any): Gateway;
65
65
  #private;
66
66
  }
67
67
  export const registry: Registry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geonix",
3
- "version": "1.10.7",
3
+ "version": "1.10.9",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "bin": {
package/src/Gateway.js CHANGED
@@ -27,12 +27,18 @@ const stats = {
27
27
  debug_requests: 0
28
28
  }
29
29
 
30
+ const defaultOpts = {
31
+ afterRequest: (req, res) => { },
32
+ }
33
+
34
+
30
35
  export class Gateway {
31
36
 
32
- static start() {
33
- return new Gateway()
37
+ static start(opts) {
38
+ return new Gateway(opts)
34
39
  }
35
40
 
41
+ #opts = defaultOpts
36
42
  #api = express()
37
43
  #router = (req, res, next) => next()
38
44
  #activeServers = []
@@ -47,6 +53,8 @@ export class Gateway {
47
53
  constructor() {
48
54
  expressWs(this.#api)
49
55
 
56
+ this.#opts = { ...this.#opts, ...opts }
57
+
50
58
  this.#start()
51
59
  }
52
60
 
@@ -92,6 +100,13 @@ export class Gateway {
92
100
  next()
93
101
  })
94
102
 
103
+ this.#api.use((req, res, next) => {
104
+ if (this.#opts.afterRequest) {
105
+ this.#opts.afterRequest(req, res)
106
+ }
107
+ next()
108
+ })
109
+
95
110
  // config
96
111
  this.#api.disable('x-powered-by')
97
112
  this.#api.disable('etag')
package/src/Request.js CHANGED
@@ -69,7 +69,7 @@ export async function Request(service, method, args = [], context = [], options)
69
69
  // get service instance identifier and wait for it if it's not available
70
70
  const registryTimeout = options?.timeout ?? REGISTRY_TIMEOUT
71
71
  const delay = 5
72
- let retries = Math.floor(REGISTRY_TIMEOUT / delay)
72
+ let retries = Math.floor(registryTimeout / delay)
73
73
  while (identifier == null && retries-- > 0) {
74
74
  identifier = registry.getIdentifier(name, version, id)
75
75
  if (!identifier)
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "test",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "stream.js",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "geonix": "file:.."
15
+ }
16
+ }
package/test/stream.js ADDED
@@ -0,0 +1,38 @@
1
+ import { randomBytes } from 'node:crypto'
2
+ import { Stream, getReadable, connection } from 'geonix'
3
+ import { createWriteStream, readFileSync } from 'node:fs'
4
+ import { createHash } from 'node:crypto'
5
+ import { pipeline } from 'node:stream/promises'
6
+
7
+ await connection.waitUntilReady()
8
+
9
+ const hash = data => createHash('sha512').update(data).digest('base64')
10
+
11
+ const PAYLOAD_SIZE = 1024 * 1024 * 1024
12
+ const TEMP_FILE = '/tmp/geonix.stream_test'
13
+
14
+ console.time('test')
15
+ try {
16
+ const payload = randomBytes(PAYLOAD_SIZE)
17
+ const sourceHash = hash(payload)
18
+
19
+ const source = await getReadable(Stream(payload))
20
+ const dest = createWriteStream(TEMP_FILE)
21
+
22
+ await pipeline(source, dest)
23
+
24
+ const check = readFileSync(TEMP_FILE)
25
+ const destHash = hash(check)
26
+
27
+ if (sourceHash == destHash) {
28
+ console.log('MATCH')
29
+ } else {
30
+ console.error('Destination does not match the source!')
31
+ console.log(payload)
32
+ console.log(check)
33
+ }
34
+ } catch (e) {
35
+ console.error(e)
36
+ } finally {
37
+ console.timeEnd('test')
38
+ }