geonix 1.22.2 → 1.22.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.
package/dev.js ADDED
@@ -0,0 +1,62 @@
1
+ import { BasicAuth, HTTP, Transport, Unit } from "geonix";
2
+ import { Gateway } from "./src/Gateway.js";
3
+
4
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
5
+
6
+ const middleware = [
7
+ BasicAuth({ realm: "Test", username: "u", password: "pa" })
8
+ ];
9
+
10
+ class TimeService {
11
+
12
+ getTime() {
13
+ return new Date().toISOString();
14
+ }
15
+
16
+ [HTTP.GET("/time", middleware)] = async (req, res) => {
17
+ res.setHeader("X-Test", "Test");
18
+ return {
19
+ time: this.getTime(),
20
+ id: this.$meta.id
21
+ };
22
+ };
23
+
24
+ [HTTP.GET("/time2", middleware)] = async (req, res) => {
25
+ res.setHeader("X-Test", "Test2");
26
+ return {
27
+ time: this.getTime(),
28
+ id: this.$meta.id
29
+ };
30
+ };
31
+
32
+ [HTTP.filter] = async () => {
33
+
34
+ };
35
+
36
+ [HTTP.ERROR()] = async () => {
37
+ return {
38
+ error: "Unexpected error"
39
+ };
40
+ };
41
+
42
+ }
43
+
44
+ const transport = await Transport.start("nats://localhost:4222");
45
+
46
+ await Unit.start(TimeService, {
47
+ meta: {
48
+ id: "first",
49
+ },
50
+ transport,
51
+ port: 30000
52
+ });
53
+
54
+ await Unit.start(TimeService, {
55
+ meta: {
56
+ id: "second",
57
+ },
58
+ transport,
59
+ port: 30001
60
+ });
61
+
62
+ Gateway.start({ transport, gatewayPort: 8080 });
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export function encode(data: any): Uint8Array;
1
+ export function encode(data: any): Uint8Array<ArrayBuffer>;
2
2
  export function decode(data: any): unknown;
3
3
  export const codec: import("nats").Codec<unknown>;
4
4
  export const connection: Connection;
@@ -195,15 +195,24 @@ type ParsedMultiPart = {
195
195
  body: Readable;
196
196
  };
197
197
  type ServiceOptions = {
198
- middleware: {
199
- json: boolean;
200
- raw: boolean;
201
- cookies: boolean;
202
- };
198
+ middleware?: {
199
+ /**
200
+ * Enable JSON middleware
201
+ */
202
+ json?: boolean | undefined;
203
+ /**
204
+ * Enable RAW middleware
205
+ */
206
+ raw?: boolean | undefined;
207
+ /**
208
+ * Enable cookies middleware
209
+ */
210
+ cookies?: boolean | undefined;
211
+ } | undefined;
203
212
  /**
204
213
  * Enable full beacon
205
214
  */
206
- fullBeacon: boolean;
215
+ fullBeacon?: boolean | undefined;
207
216
  };
208
217
  /**
209
218
  * Parse nats:// URL
@@ -213,6 +222,7 @@ type ServiceOptions = {
213
222
  export function parseURL(url: string): any;
214
223
  export function getFirstItemFromAsyncIterable(asyncIterable: any): Promise<any>;
215
224
  export function getNetworkAddresses(): any[];
225
+ export function isIterable(obj: any): any;
216
226
  /**
217
227
  *
218
228
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geonix",
3
- "version": "1.22.2",
3
+ "version": "1.22.4",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "bin": {
package/src/Types.js CHANGED
@@ -16,9 +16,9 @@
16
16
 
17
17
  /**
18
18
  * @typedef {Object} ServiceOptions
19
- * @property {Object} middleware
20
- * @property {boolean} middleware.json Enable JSON middleware
21
- * @property {boolean} middleware.raw Enable RAW middleware
22
- * @property {boolean} middleware.cookies Enable cookies middleware
23
- * @property {boolean} fullBeacon Enable full beacon
19
+ * @property {Object} [middleware]
20
+ * @property {boolean} [middleware.json] Enable JSON middleware
21
+ * @property {boolean} [middleware.raw] Enable RAW middleware
22
+ * @property {boolean} [middleware.cookies] Enable cookies middleware
23
+ * @property {boolean} [fullBeacon] Enable full beacon
24
24
  */
package/src/Util.js CHANGED
@@ -241,6 +241,10 @@ export function getNetworkAddresses() {
241
241
  return list;
242
242
  }
243
243
 
244
+ export function isIterable(obj) {
245
+ return obj && (typeof obj[Symbol.iterator] === "function" || typeof obj[Symbol.asyncIterator] === "function");
246
+ }
247
+
244
248
  /**
245
249
  *
246
250
  *
@@ -263,7 +267,7 @@ export async function parseMultipart(req, _options) {
263
267
  let stream = req;
264
268
 
265
269
  // if body is present, create a stream from it and use memory
266
- if (req.body) {
270
+ if (req.body && isIterable(req.body)) {
267
271
  stream = Readable.from(req.body);
268
272
  options.useMemory = true;
269
273
  }
@@ -1,26 +1,24 @@
1
+ import { Router } from "express";
1
2
  import { ServeStatic, Service } from "../exports.js";
2
3
 
3
- class First extends Service {
4
+ function special(req, res) {
5
+ console.log("THIS:", this);
4
6
 
5
- "GET /first"(req, res) {
6
- res.end(JSON.stringify(req.cookies));
7
- }
7
+ res.send(`Hello ${this.value}`);
8
+ };
8
9
 
9
- }
10
+ class ApplicationService extends Service {
10
11
 
11
- class Second extends Service {
12
+ value = "World!";
12
13
 
13
- "GET /second"(req, res) {
14
- res.end(JSON.stringify(req.cookies));
14
+ async onStart() {
15
15
  }
16
- }
17
16
 
18
- class Third extends Service {
19
- "GET /third"(req, res) {
20
- res.end(JSON.stringify(req.cookies));
21
- }
17
+ "GET *" = [special, ServeStatic("test/static", { indexOn404: true })];
18
+ // "GET *" = [(req, res) => {
19
+ // res.send(`Hello ${this.value}`);
20
+ // }];
21
+
22
22
  }
23
23
 
24
- Third.start();
25
- First.start({ middleware: { raw: true } });
26
- Second.start();
24
+ ApplicationService.start();