From 46ad7172739d47721e9790da299942b58013de02 Mon Sep 17 00:00:00 2001 From: Richard Rodger Date: Mon, 27 Nov 2023 02:49:38 +0000 Subject: [PATCH] v0.9.0 --- dist/gateway.d.ts | 1 + dist/gateway.js | 18 ++++++++++-------- dist/gateway.js.map | 2 +- package.json | 10 +++++----- src/gateway.ts | 20 ++++++++++++-------- test/gateway.test.ts | 22 ++++++++++------------ 6 files changed, 39 insertions(+), 34 deletions(-) diff --git a/dist/gateway.d.ts b/dist/gateway.d.ts index 9c4598f..d8c17ae 100644 --- a/dist/gateway.d.ts +++ b/dist/gateway.d.ts @@ -3,6 +3,7 @@ type GatewayResult = { meta$: any; error$: { name: string; + id: string; code?: string; message?: string; details?: any; diff --git a/dist/gateway.js b/dist/gateway.js index c7b5e53..b4ce34d 100644 --- a/dist/gateway.js +++ b/dist/gateway.js @@ -13,6 +13,7 @@ function gateway(options) { const Patrun = seneca.util.Patrun; const Jsonic = seneca.util.Jsonic; const allowed = new Patrun({ gex: true }); + const errid = seneca.util.Nid({ length: 9 }); const checkAllowed = null != options.allow; if (checkAllowed) { for (let patStr in options.allow) { @@ -93,6 +94,7 @@ function gateway(options) { if (!allowMsg) { let errdesc = { name: 'Error', + id: errid(), code: 'not-allowed', message: 'Message not allowed', details: undefined, @@ -154,15 +156,15 @@ function gateway(options) { delete out.gateway$; if (err) { result.error = true; - result.out = { + out.meta$.error = true; + result.out = nundef({ meta$: out.meta$, - error$: nundef({ - name: err.name, - code: err.code, - message: options.error.message ? err.message : undefined, - details: options.error.details ? err.details : undefined, - }) - }; + name: err.name, + id: err.id || errid(), + code: err.code, + message: options.error.message ? err.message : undefined, + details: options.error.details ? err.details : undefined, + }); } resolve(result); }); diff --git a/dist/gateway.js.map b/dist/gateway.js.map index 13f3a2d..eb92460 100644 --- a/dist/gateway.js.map +++ b/dist/gateway.js.map @@ -1 +1 @@ -{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":";AAAA,wDAAw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ACT;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE;YACP,OAAO;YACP,SAAS;SACV;KACF,CAAA;AACH,CAAC;AAGD,SAAS,MAAM,CAAC,CAAM;IACpB,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE;QACf,IAAI,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;YACtB,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;SACZ;KACF;IACD,OAAO,CAAC,CAAA;AACV,CAAC;AAGD,mBAAmB;AACnB,OAAO,CAAC,QAAQ,GAAI;IAElB,4BAA4B;IAC5B,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAErB,+BAA+B;IAC/B,MAAM,EAAE,IAAI,CAAC;QAEX,sDAAsD;QACtD,IAAI,EAAE,KAAK;KACZ,CAAC;IAEF,qCAAqC;IACrC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;IAEf,wEAAwE;IACxE,OAAO,EAAE;QAEP,oCAAoC;QACpC,MAAM,EAAE,KAAK;QAEb,uCAAuC;QACvC,sCAAsC;QACtC,GAAG,EAAE,CAAC,CAAC;KACR;IAED,KAAK,EAAE;QACL,yDAAyD;QACzD,OAAO,EAAE,KAAK;QAEd,yDAAyD;QACzD,OAAO,EAAE,KAAK;KACf;IAGD,wBAAwB;IACxB,KAAK,EAAE;QAEL,kEAAkE;QAClE,QAAQ,EAAE,KAAK;QAEf,kCAAkC;QAClC,GAAG,EAAE,KAAK;KACX;CACiB,CAAA;AAQpB,kBAAe,OAAO,CAAA;AAEtB,IAAI,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,EAAE;IACnC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAA;CACzB"} \ No newline at end of file +{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":";AAAA,wDAAwD;;;;;AAGxD,oDAA2B;AAE3B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,gBAAM,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C;QACvC,sCAAsC;QACtC,GAAG,EAAE,CAAC,CAAC;KACR;IAED,KAAK,EAAE;QACL,yDAAyD;QACzD,OAAO,EAAE,KAAK;QAEd,yDAAyD;QACzD,OAAO,EAAE,KAAK;KACf;IAGD,wBAAwB;IACxB,KAAK,EAAE;QAEL,kEAAkE;QAClE,QAAQ,EAAE,KAAK;QAEf,kCAAkC;QAClC,GAAG,EAAE,KAAK;KACX;CACiB,CAAA;AAQpB,kBAAe,OAAO,CAAA;AAEtB,IAAI,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;IACpC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAA;AAC1B,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index b6aacc6..308b9ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@seneca/gateway", - "version": "0.8.0", + "version": "0.9.0", "main": "dist/gateway.js", "type": "commonjs", "types": "dist/gateway.d.ts", @@ -38,13 +38,13 @@ }, "devDependencies": { "@seneca/maintain": "^0.1.0", - "@types/jest": "^29.5.7", - "@types/node": "^20.8.10", - "esbuild": "^0.19.5", + "@types/jest": "^29.5.10", + "@types/node": "^20.10.0", + "esbuild": "^0.19.8", "esbuild-jest": "^0.5.0", "jest": "^29.7.0", "seneca-msg-test": "^3.4.0", - "typescript": "^5.2.2" + "typescript": "^5.3.2" }, "peerDependencies": { "seneca": ">=3", diff --git a/src/gateway.ts b/src/gateway.ts index f191248..9c48e69 100644 --- a/src/gateway.ts +++ b/src/gateway.ts @@ -19,6 +19,7 @@ type GatewayResult = { // Extracted from Error object error$: { name: string + id: string code?: string message?: string details?: any @@ -65,6 +66,7 @@ function gateway(this: any, options: GatewayOptions) { const Patrun = seneca.util.Patrun const Jsonic = seneca.util.Jsonic const allowed = new Patrun({ gex: true }) + const errid = seneca.util.Nid({ length: 9 }) const checkAllowed = null != options.allow @@ -169,6 +171,7 @@ function gateway(this: any, options: GatewayOptions) { if (!allowMsg) { let errdesc: any = { name: 'Error', + id: errid(), code: 'not-allowed', message: 'Message not allowed', details: undefined, @@ -242,15 +245,16 @@ function gateway(this: any, options: GatewayOptions) { if (err) { result.error = true - result.out = { + out.meta$.error = true + + result.out = nundef({ meta$: out.meta$, - error$: nundef({ - name: err.name, - code: (err as any).code, - message: options.error.message ? err.message : undefined, - details: options.error.details ? err.details : undefined, - }) - } + name: err.name, + id: (err as any).id || errid(), + code: (err as any).code, + message: options.error.message ? err.message : undefined, + details: options.error.details ? err.details : undefined, + }) } resolve(result) diff --git a/test/gateway.test.ts b/test/gateway.test.ts index 9f8f746..a9876c3 100644 --- a/test/gateway.test.ts +++ b/test/gateway.test.ts @@ -109,25 +109,24 @@ describe('gateway', () => { result.out.meta$.id = 'METAID' result.meta = { pattern: result.meta.pattern } - expect(result).toEqual({ + expect(result).toMatchObject({ error: true, meta: { - pattern: 'bar:1' + pattern: 'bar:1', }, gateway$: {}, out: { - error$: { - name: 'Error', - message: 'bar', - }, + name: 'Error', + message: 'bar', meta$: { id: "METAID", + error: true, }, }, }) // undefs removed - expect(Object.keys(result.out.error$)).toEqual(['name', 'message']) + expect(Object.keys(result.out)).toEqual(['meta$', 'name', 'id', 'message']) const s1 = Seneca({ legacy: false }) .test() @@ -143,18 +142,17 @@ describe('gateway', () => { result.out.meta$.id = 'METAID' result.meta = { pattern: result.meta.pattern } - expect(result).toEqual({ + expect(result).toMatchObject({ error: true, meta: { - pattern: 'bar:1' + pattern: 'bar:1', }, gateway$: {}, out: { - error$: { - name: 'Error', - }, + name: 'Error', meta$: { id: "METAID", + error: true, }, }, })