geonix 1.22.1 → 1.22.2

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
@@ -227,6 +227,7 @@ export function parseMultipart(req: Request, _options: any): Promise<{
227
227
  }[]>;
228
228
  export function tempFilename(): any;
229
229
  export function randomSafeId(size?: number): string;
230
+ export function deepMerge(target: any, ...source: any[]): any;
230
231
  export function sleep(delay: number): Promise<any>;
231
232
  export function nextTick(): Promise<any>;
232
233
  export function picoid(size?: number): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geonix",
3
- "version": "1.22.1",
3
+ "version": "1.22.2",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "bin": {
package/src/Service.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { connection } from "./Connection.js";
2
- import { picoid, sleep, hash, getSecondsSinceMidnight, OverlayObject, GeonixVersion, getFirstItemFromAsyncIterable, getNetworkAddresses } from "./Util.js";
2
+ import { picoid, sleep, hash, getSecondsSinceMidnight, OverlayObject, GeonixVersion, getFirstItemFromAsyncIterable, getNetworkAddresses, deepMerge } from "./Util.js";
3
3
  import { webserver } from "./WebServer.js";
4
4
  import { createConnection } from "net";
5
5
  import { EOL } from "os";
@@ -54,7 +54,7 @@ export class Service {
54
54
  #options = defaultServiceOptions;
55
55
 
56
56
  async #start(options = {}) {
57
- this.#options = { ...this.#options, ...options };
57
+ this.#options = deepMerge(this.#options, options); // { ...this.#options, ...options };
58
58
 
59
59
  await webserver.waitUntilReady();
60
60
  await connection.waitUntilReady();
package/src/Util.js CHANGED
@@ -383,4 +383,22 @@ export function randomSafeId(size = 12) {
383
383
  }
384
384
 
385
385
  return result;
386
+ }
387
+
388
+ export function deepMerge(target, ...source) {
389
+ for (const src of source) {
390
+ for (const key in src) {
391
+ if (src[key] instanceof Object) {
392
+ if (!target[key]) {
393
+ target[key] = {};
394
+ }
395
+
396
+ deepMerge(target[key], src[key]);
397
+ } else {
398
+ target[key] = src[key];
399
+ }
400
+ }
401
+ }
402
+
403
+ return target;
386
404
  }
@@ -1,24 +1,26 @@
1
- import { Router } from "express";
2
1
  import { ServeStatic, Service } from "../exports.js";
3
2
 
4
- function special(req, res) {
5
- console.log("THIS:", this);
3
+ class First extends Service {
6
4
 
7
- res.send(`Hello ${this.value}`);
8
- };
5
+ "GET /first"(req, res) {
6
+ res.end(JSON.stringify(req.cookies));
7
+ }
9
8
 
10
- class ApplicationService extends Service {
9
+ }
11
10
 
12
- value = "World!";
11
+ class Second extends Service {
13
12
 
14
- async onStart() {
13
+ "GET /second"(req, res) {
14
+ res.end(JSON.stringify(req.cookies));
15
15
  }
16
+ }
16
17
 
17
- "GET *" = [special, ServeStatic("test/static", { indexOn404: true })];
18
- // "GET *" = [(req, res) => {
19
- // res.send(`Hello ${this.value}`);
20
- // }];
21
-
18
+ class Third extends Service {
19
+ "GET /third"(req, res) {
20
+ res.end(JSON.stringify(req.cookies));
21
+ }
22
22
  }
23
23
 
24
- ApplicationService.start();
24
+ Third.start();
25
+ First.start({ middleware: { raw: true } });
26
+ Second.start();