geonix 1.10.0 → 1.10.4

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "editor.codeActionsOnSave": {
3
- "source.fixAll.eslint": true
3
+ "source.fixAll.eslint": "explicit"
4
4
  },
5
5
  "eslint.validate": [
6
6
  "javascript"
package/exports.js CHANGED
@@ -38,4 +38,6 @@ export { connection, stopConnection } from './src/Connection.js'
38
38
  export { registry } from './src/Registry.js'
39
39
  export { Request, Subscribe, Publish } from './src/Request.js'
40
40
  export { RequestOptions } from './src/RequestOptions.js'
41
- export { picoid as randomID } from './src/Util.js'
41
+ export { picoid as randomID } from './src/Util.js'
42
+
43
+ export { stats as StreamStats } from './src/Stream.js'
package/index.d.ts CHANGED
@@ -15,13 +15,39 @@ declare class Connection {
15
15
  */
16
16
  start(transport?: string): Promise<void>;
17
17
  monitorStatus(): Promise<void>;
18
+ /**
19
+ * Wait for the connection to be safely closed
20
+ */
18
21
  waitUntilClosed(): Promise<void>;
22
+ /**
23
+ * Wait for the connection to be fully established
24
+ */
19
25
  waitUntilReady(): Promise<void>;
20
- publish(subject: any, json: any): Promise<void>;
21
- publishRaw(subject: any, data: any): Promise<void>;
22
- request(subject: any, json: any, options?: {
23
- timeout: number;
24
- }): Promise<unknown>;
26
+ /**
27
+ * Publish JSON
28
+ *
29
+ * @param {string} subject
30
+ * @param {object} json
31
+ * @returns void
32
+ */
33
+ publish(subject: string, json: object): Promise<void>;
34
+ /**
35
+ * Publish RAW
36
+ *
37
+ * @param {string} subject
38
+ * @param {string | Buffer} data
39
+ * @returns void
40
+ */
41
+ publishRaw(subject: string, data: string | Buffer): Promise<void>;
42
+ /**
43
+ * Request/Reply pattern on top of pub/sub
44
+ *
45
+ * @param {string} subject
46
+ * @param {object} json
47
+ * @param {object} options
48
+ * @returns any
49
+ */
50
+ request(subject: string, json: object, options?: object): Promise<unknown>;
25
51
  subscribe(subject: any, options: any): Promise<any>;
26
52
  unsubscribe(subscription: any): Promise<void>;
27
53
  /**
@@ -38,18 +64,15 @@ export class Gateway {
38
64
  static start(): Gateway;
39
65
  #private;
40
66
  }
41
- /// <reference types="node" />
42
67
  export const registry: Registry;
43
68
  /**
44
69
  * Registry maintains a local list of available services and their versions.
45
70
  */
46
- declare class Registry extends EventEmitter {
47
- constructor();
71
+ declare class Registry {
48
72
  getEntries(): {};
49
73
  getIdentifier(service: any, version: any, id: any): any;
50
74
  #private;
51
75
  }
52
- import EventEmitter from "events";
53
76
  export {};
54
77
  export function Remote(service: string, ...context: (string | Stream | Object)[]): string | Stream | Object;
55
78
  /**
@@ -89,14 +112,14 @@ export class Service {
89
112
  SYS_getEnv(): Promise<{
90
113
  geonix: string;
91
114
  node: {
92
- version: string;
93
- platform: NodeJS.Platform;
94
- arch: NodeJS.Architecture;
115
+ version: any;
116
+ platform: any;
117
+ arch: any;
95
118
  };
96
- env: NodeJS.ProcessEnv;
97
- mem: NodeJS.MemoryUsage;
98
- rss: number;
99
- cpu: NodeJS.CpuUsage;
119
+ env: any;
120
+ mem: any;
121
+ rss: any;
122
+ cpu: any;
100
123
  }>;
101
124
  #private;
102
125
  }
@@ -107,15 +130,12 @@ export class Service {
107
130
  * @param {*} automated
108
131
  * @returns
109
132
  */
110
- export function Stream(data: any): {
111
- $: string;
112
- id: string;
113
- };
133
+ export function Stream(data: any, tag?: string): any;
114
134
  export function isStream(object: any): any;
115
- export function getReadable(object: any): Promise<Readable | null>;
116
- export function streamToBuffer(object: any): Promise<Buffer>;
117
- export function streamToString(object: any): Promise<string>;
118
- import { Readable } from "stream";
135
+ export function getReadable(object: any): Promise<any>;
136
+ export function streamToBuffer(object: any): Promise<any>;
137
+ export function streamToString(object: any): Promise<any>;
138
+ export const stats: {};
119
139
  /**
120
140
  * Parse nats:// URL
121
141
  * @param {string} url
@@ -123,13 +143,13 @@ import { Readable } from "stream";
123
143
  */
124
144
  export function parseURL(url: string): {
125
145
  servers: string;
126
- user: string;
127
- pass: string;
128
- token: string | undefined;
146
+ user: any;
147
+ pass: any;
148
+ token: any;
129
149
  };
130
150
  export function sleep(delay: number): Promise<any>;
131
- export function picoid(size?: number): string;
132
- export function hash(data: string | Buffer): string;
151
+ export function picoid(size?: number): any;
152
+ export function hash(data: string | Buffer): any;
133
153
  export function createServerAtPort(port: number, pkg: Object, handler: Function): Promise<any>;
134
154
  export function createServerAtFreePort(pkg: Object, handler: Function, start?: number, poolSize?: number): Promise<any>;
135
155
  export function createTCPServer(handler: Function, start?: number, poolSize?: number): Promise<any>;
@@ -139,14 +159,13 @@ export function getFunctionParams(fn: any): any;
139
159
  export function proxyHttp(target: any, req: any, res: any): Promise<any>;
140
160
  export function OverlayObject(object: any, overlay: any): any;
141
161
  export const GeonixVersion: string;
142
- export function StreamChunker(chunkSize?: number): Transform;
143
- import { Transform } from "stream";
162
+ export function StreamChunker(chunkSize?: number): any;
144
163
  export const HEALTH_CHECK_ENDPOINT: "/pA4vY7fT9oG5aI8cA4yV3qW5fP9qR1vI";
145
164
  export function ServeStatic(root: any, options?: {}): any;
146
165
  export const webserver: WebServer;
147
166
  declare class WebServer {
148
167
  start(): Promise<void>;
149
- getAddresses(): string[];
168
+ getAddresses(): any[];
150
169
  getPort(): any;
151
170
  router(): any;
152
171
  waitUntilReady(): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geonix",
3
- "version": "1.10.0",
3
+ "version": "1.10.4",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "bin": {
package/src/Stream.js CHANGED
@@ -4,6 +4,8 @@ import { picoid, StreamChunker } from './Util.js'
4
4
 
5
5
  const CHUNK_SIZE = 1024 * 128
6
6
 
7
+ export const stats = {}
8
+
7
9
  /**
8
10
  * Converts data to stream
9
11
  *
@@ -11,7 +13,7 @@ const CHUNK_SIZE = 1024 * 128
11
13
  * @param {*} automated
12
14
  * @returns
13
15
  */
14
- export function Stream(data) {
16
+ export function Stream(data, tag = '_') {
15
17
  if (isStream(data))
16
18
  return data
17
19
 
@@ -27,13 +29,18 @@ export function Stream(data) {
27
29
  readable.pipe(transform)
28
30
  readable = transform
29
31
 
32
+ stats[tag] = stats[tag] !== undefined ? stats[tag] + 1 : 1
33
+
30
34
  const controlHandler = async () => {
31
35
  const control = await connection.subscribe(`gx2.stream.${id}.a`, { max: 1 })
32
36
 
33
37
  for await (const event of control)
34
38
  if (event.data.length === 0) {
35
39
  readable.on('data', chunk => connection.publishRaw(`gx2.stream.${id}.b`, chunk))
36
- readable.on('close', () => connection.publishRaw(`gx2.stream.${id}.b`))
40
+ readable.on('close', () => {
41
+ connection.publishRaw(`gx2.stream.${id}.b`)
42
+ stats[tag]--
43
+ })
37
44
  }
38
45
  }
39
46
 
@@ -48,7 +55,7 @@ export function isStream(object) {
48
55
 
49
56
  export async function getReadable(object) {
50
57
  if (!isStream(object))
51
- return null
58
+ return object
52
59
 
53
60
  const readable = new Readable({ read: () => null })
54
61
  const subscription = await connection.subscribe(`gx2.stream.${object.id}.b`)