@furystack/rest-service
Advanced tools
Comparing version 1.1.12 to 1.2.0
@@ -14,2 +14,3 @@ import { Disposable } from '@furystack/utils'; | ||
cors?: CorsOptions; | ||
deserializeQueryParams?: (param: string) => any; | ||
} | ||
@@ -33,2 +34,3 @@ export declare type CompiledApi = { | ||
supportedMethods: string[]; | ||
deserializeQueryParams?: (param: string) => any; | ||
}; | ||
@@ -41,3 +43,3 @@ export declare class ApiManager implements Disposable { | ||
private compileApi; | ||
addApi<T extends RestApi>({ api, hostName, port, root, cors, injector }: ImplementApiOptions<T>): Promise<void>; | ||
addApi<T extends RestApi>({ api, hostName, port, root, cors, injector, deserializeQueryParams, }: ImplementApiOptions<T>): Promise<void>; | ||
shouldExecRequest(options: { | ||
@@ -44,0 +46,0 @@ method?: string; |
@@ -36,3 +36,3 @@ "use strict"; | ||
} | ||
async addApi({ api, hostName, port, root, cors, injector }) { | ||
async addApi({ api, hostName, port, root, cors, injector, deserializeQueryParams, }) { | ||
const supportedMethods = this.getSuportedMethods(api); | ||
@@ -53,3 +53,13 @@ const rootApiPath = utils_1.PathHelper.normalize(root); | ||
}, | ||
onRequest: (msg) => this.onMessage({ ...msg, compiledApi, rootApiPath, port, supportedMethods, cors, injector, hostName }), | ||
onRequest: (msg) => this.onMessage({ | ||
...msg, | ||
compiledApi, | ||
rootApiPath, | ||
port, | ||
supportedMethods, | ||
cors, | ||
injector, | ||
hostName, | ||
deserializeQueryParams, | ||
}), | ||
}); | ||
@@ -69,3 +79,3 @@ } | ||
} | ||
async executeAction({ injector, req, res, fullUrl, action, regex, fullPath, }) { | ||
async executeAction({ injector, req, res, fullUrl, action, regex, fullPath, deserializeQueryParams, }) { | ||
await utils_1.usingAsync(injector.createChild(), async (i) => { | ||
@@ -81,4 +91,4 @@ const utils = i.getInstance(utils_2.Utils); | ||
return [...fullUrl.searchParams.keys()].reduce((last, current) => { | ||
; | ||
last[current] = fullUrl.searchParams.get(current); | ||
const currentValue = fullUrl.searchParams.get(current); | ||
last[current] = deserializeQueryParams ? deserializeQueryParams(currentValue) : currentValue; | ||
return last; | ||
@@ -85,0 +95,0 @@ }, {}); |
@@ -21,4 +21,5 @@ "use strict"; | ||
async dispose() { | ||
await this.listenLock.acquire(); | ||
this.openedSockets.forEach((s) => s.destroy()); | ||
await Promise.all([...this.servers.values()].map((s) => new Promise((resolve, reject) => { | ||
await Promise.allSettled([...this.servers.values()].map((s) => new Promise((resolve, reject) => { | ||
s.server.close((err) => (err ? reject(err) : resolve())); | ||
@@ -28,2 +29,3 @@ s.server.off('connection', this.onConnection); | ||
this.servers.clear(); | ||
this.listenLock.release(); | ||
} | ||
@@ -30,0 +32,0 @@ async getOrCreate(options) { |
{ | ||
"name": "@furystack/rest-service", | ||
"version": "1.1.12", | ||
"version": "1.2.0", | ||
"description": "Repository implementation for FuryStack", | ||
@@ -34,3 +34,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@furystack/core": "^8.0.12", | ||
"@furystack/core": "^8.0.13", | ||
"@furystack/inject": "^4.0.25", | ||
@@ -48,3 +48,3 @@ "@furystack/logging": "^2.0.32", | ||
"@types/jest": "^25.2.1", | ||
"@types/node": "^13.11.0", | ||
"@types/node": "^13.11.1", | ||
"@types/uuid": "^7.0.2", | ||
@@ -54,3 +54,3 @@ "got": "^10.7.0" | ||
"typings": "./dist/index.d.ts", | ||
"gitHead": "86ed76b9e1ff6d22d9b696356b4f5f1a6949611b" | ||
"gitHead": "4795377c6bddd53922037abf8237b58bdd804fef" | ||
} |
@@ -19,2 +19,3 @@ import { Disposable, PathHelper, usingAsync } from '@furystack/utils' | ||
cors?: CorsOptions | ||
deserializeQueryParams?: (param: string) => any | ||
} | ||
@@ -36,2 +37,3 @@ | ||
supportedMethods: string[] | ||
deserializeQueryParams?: (param: string) => any | ||
} | ||
@@ -66,3 +68,11 @@ | ||
public async addApi<T extends RestApi>({ api, hostName, port, root, cors, injector }: ImplementApiOptions<T>) { | ||
public async addApi<T extends RestApi>({ | ||
api, | ||
hostName, | ||
port, | ||
root, | ||
cors, | ||
injector, | ||
deserializeQueryParams, | ||
}: ImplementApiOptions<T>) { | ||
const supportedMethods = this.getSuportedMethods(api) | ||
@@ -82,3 +92,13 @@ const rootApiPath = PathHelper.normalize(root) | ||
onRequest: (msg) => | ||
this.onMessage({ ...msg, compiledApi, rootApiPath, port, supportedMethods, cors, injector, hostName }), | ||
this.onMessage({ | ||
...msg, | ||
compiledApi, | ||
rootApiPath, | ||
port, | ||
supportedMethods, | ||
cors, | ||
injector, | ||
hostName, | ||
deserializeQueryParams, | ||
}), | ||
}) | ||
@@ -120,2 +140,3 @@ } | ||
fullPath, | ||
deserializeQueryParams, | ||
}: OnRequestOptions & { | ||
@@ -137,3 +158,4 @@ fullUrl: URL | ||
return [...fullUrl.searchParams.keys()].reduce((last, current) => { | ||
;(last as any)[current] = fullUrl.searchParams.get(current) | ||
const currentValue = fullUrl.searchParams.get(current) as string | ||
;(last as any)[current] = deserializeQueryParams ? deserializeQueryParams(currentValue) : currentValue | ||
return last | ||
@@ -140,0 +162,0 @@ }, {}) |
@@ -42,4 +42,5 @@ import { Injectable, Injector } from '@furystack/inject' | ||
public async dispose() { | ||
await this.listenLock.acquire() | ||
this.openedSockets.forEach((s) => s.destroy()) | ||
await Promise.all( | ||
await Promise.allSettled( | ||
[...this.servers.values()].map( | ||
@@ -54,2 +55,3 @@ (s) => | ||
this.servers.clear() | ||
this.listenLock.release() | ||
} | ||
@@ -56,0 +58,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
240477
3536
Updated@furystack/core@^8.0.13