@nmtjs/http-transport 0.0.2 → 0.1.0
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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/injectables.js +2 -0
- package/dist/lib/injectables.js.map +1 -0
- package/dist/lib/server.js +4 -4
- package/dist/lib/server.js.map +1 -1
- package/index.ts +1 -1
- package/lib/injectables.ts +11 -0
- package/lib/server.ts +4 -4
- package/package.json +6 -5
- package/dist/lib/providers.js +0 -2
- package/dist/lib/providers.js.map +0 -1
- package/lib/providers.ts +0 -5
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"sourcesContent":["export * from './lib/server.ts'\nexport * from './lib/transport.ts'\nexport * from './lib/types.ts'\nexport * from './lib/utils.ts'\nexport * from './lib/
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["export * from './lib/server.ts'\nexport * from './lib/transport.ts'\nexport * from './lib/types.ts'\nexport * from './lib/utils.ts'\nexport * from './lib/injectables.ts'\n"],"names":[],"mappings":"AAAA,cAAc,kBAAiB;AAC/B,cAAc,qBAAoB;AAClC,cAAc,iBAAgB;AAC9B,cAAc,iBAAgB;AAC9B,cAAc,uBAAsB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../lib/injectables.ts"],"sourcesContent":["import {\n type LazyInjectable,\n type Scope,\n injectables,\n} from '@nmtjs/application'\nimport type { HttpConnectionData } from './types.ts'\n\nexport const connectionData = injectables.connectionData as LazyInjectable<\n HttpConnectionData,\n Scope.Connection\n>\n"],"names":["injectables","connectionData"],"mappings":"AAAA,SAGEA,WAAW,QACN,qBAAoB;AAG3B,OAAO,MAAMC,iBAAiBD,YAAYC,cAAc,CAGvD"}
|
package/dist/lib/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ApiError, Scope,
|
|
1
|
+
import { ApiError, Scope, injectables } from '@nmtjs/application';
|
|
2
2
|
import { TransportType } from '@nmtjs/common';
|
|
3
3
|
import { App, SSLApp } from 'uWebSockets.js';
|
|
4
|
-
import { connectionData } from "./
|
|
4
|
+
import { connectionData } from "./injectables.js";
|
|
5
5
|
import { InternalError, getFormat, getRequestData } from "./utils.js";
|
|
6
6
|
export class HttpTransportServer {
|
|
7
7
|
application;
|
|
@@ -53,8 +53,8 @@ export class HttpTransportServer {
|
|
|
53
53
|
remoteAddress: Buffer.from(res.getRemoteAddressAsText()).toString(),
|
|
54
54
|
responseHeaders
|
|
55
55
|
});
|
|
56
|
-
container.provide(
|
|
57
|
-
container.provide(
|
|
56
|
+
container.provide(injectables.connection, connection);
|
|
57
|
+
container.provide(injectables.callSignal, ac.signal);
|
|
58
58
|
const { procedure } = this.api.find(serviceName, procedureName, this.transportType);
|
|
59
59
|
try {
|
|
60
60
|
const response = await this.handleRPC({
|
package/dist/lib/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/server.ts"],"sourcesContent":["import {\n type AnyProcedure,\n ApiError,\n type ApplicationContext,\n type Connection,\n type Container,\n Scope,\n type Service,\n providers,\n} from '@nmtjs/application'\nimport { TransportType } from '@nmtjs/common'\nimport {\n App,\n type HttpResponse,\n SSLApp,\n type TemplatedApp,\n} from 'uWebSockets.js'\nimport { connectionData } from './providers.ts'\nimport type { HttpTransportOptions } from './types.ts'\nimport { InternalError, getFormat, getRequestData } from './utils.ts'\n\nexport class HttpTransportServer {\n protected server!: TemplatedApp\n protected readonly transportType = TransportType.HTTP\n\n constructor(\n protected readonly application: ApplicationContext,\n protected readonly options: HttpTransportOptions,\n ) {\n this.server = this.options.tls ? SSLApp(options.tls!) : App()\n\n this.server\n .get('/healthy', (res) => {\n res.cork(() => {\n // cors\n res.writeHeader('Access-Control-Allow-Origin', '*')\n res.writeHeader('Access-Control-Allow-Headers', 'Content-Type')\n res.writeHeader('Access-Control-Allow-Methods', 'GET')\n res.writeHeader('Content-Type', 'text/plain')\n res.end('OK')\n })\n })\n .post('/api/:service/:procudure', async (res, req) => {\n const ac = new AbortController()\n res.onAborted(() => ac.abort())\n const tryEnd = (cb) => {\n if (!ac.signal.aborted) res.cork(cb)\n }\n\n try {\n const requestData = getRequestData(req)\n\n const serviceName = req.getParameter(0)!\n const procedureName = req.getParameter(1)!\n\n const service = this.application.registry.services.get(serviceName)\n\n if (!service) throw new Error(`Service ${serviceName} not found`)\n if (this.transportType in service.contract.transports === false)\n throw new Error(`Service ${serviceName} not supported`)\n\n const format = getFormat(requestData, this.application.format)\n const body = await this.getBody(res)\n const container = this.application.container.createScope(Scope.Call)\n const payload = body.byteLength ? format.decoder.decode(body) : null\n const connection = this.application.connections.add({\n services: [serviceName],\n type: this.transportType,\n subscriptions: new Map(),\n })\n\n const responseHeaders = new Headers()\n\n container.provide(connectionData, {\n query: requestData.query,\n headers: requestData.headers,\n proxiedRemoteAddress: Buffer.from(\n res.getProxiedRemoteAddressAsText(),\n ).toString(),\n remoteAddress: Buffer.from(res.getRemoteAddressAsText()).toString(),\n responseHeaders,\n })\n container.provide(providers.connection, connection)\n container.provide(providers.signal, ac.signal)\n\n const { procedure } = this.api.find(\n serviceName,\n procedureName,\n this.transportType,\n )\n\n try {\n const response = await this.handleRPC({\n connection,\n service,\n procedure,\n container,\n signal: ac.signal,\n payload,\n })\n\n tryEnd(() => {\n res\n .writeStatus('200 OK')\n .writeHeader('Content-Type', format.encoder.contentType)\n responseHeaders.forEach((v, k) => res.writeHeader(k, v))\n res.end(format.encoder.encode({ error: null, result: response }))\n })\n } catch (error: any) {\n if (error instanceof ApiError) {\n tryEnd(() =>\n res\n .writeStatus('200 OK')\n .end(format.encoder.encode({ error, result: null })),\n )\n } else {\n tryEnd(() =>\n res.writeStatus('200 OK').end(\n format.encoder.encode({\n error: InternalError(),\n result: null,\n }),\n ),\n )\n }\n this.logError(error)\n } finally {\n this.application.connections.remove(connection)\n this.handleContainerDisposal(container)\n }\n } catch (error: any) {\n this.logError(error)\n tryEnd(() =>\n res.writeStatus('500 Internal Server Error').endWithoutBody(),\n )\n }\n })\n }\n\n async start() {\n return new Promise<void>((resolve, reject) => {\n const hostname = this.options.hostname ?? '127.0.0.1'\n this.server.listen(hostname, this.options.port!, (socket) => {\n if (socket) {\n this.logger.info(\n 'Server started on %s:%s',\n hostname,\n this.options.port!,\n )\n resolve()\n } else {\n reject(new Error('Failed to start server'))\n }\n })\n })\n }\n\n async stop() {\n this.server.close()\n }\n\n protected get api() {\n return this.application.api\n }\n\n protected get logger() {\n return this.application.logger\n }\n\n protected async logError(\n cause: Error,\n message = 'Unknown error while processing request',\n ) {\n this.logger.error(new Error(message, { cause }))\n }\n\n protected handleContainerDisposal(container: Container) {\n container.dispose()\n }\n\n protected async handleRPC(options: {\n connection: Connection\n service: Service\n procedure: AnyProcedure\n container: Container\n signal: AbortSignal\n payload: any\n }) {\n return await this.api.call({\n ...options,\n transport: this.transportType,\n })\n }\n\n protected async getBody(res: HttpResponse) {\n return new Promise<Buffer>((resolve) => {\n const chunks: Buffer[] = []\n res.onData((chunk, isLast) => {\n chunks.push(Buffer.from(chunk))\n if (isLast) {\n resolve(Buffer.concat(chunks))\n }\n })\n })\n }\n}\n"],"names":["ApiError","Scope","providers","TransportType","App","SSLApp","connectionData","InternalError","getFormat","getRequestData","HttpTransportServer","server","transportType","constructor","application","options","HTTP","tls","get","res","cork","writeHeader","end","post","req","ac","AbortController","onAborted","abort","tryEnd","cb","signal","aborted","requestData","serviceName","getParameter","procedureName","service","registry","services","Error","contract","transports","format","body","getBody","container","createScope","Call","payload","byteLength","decoder","decode","connection","connections","add","type","subscriptions","Map","responseHeaders","Headers","provide","query","headers","proxiedRemoteAddress","Buffer","from","getProxiedRemoteAddressAsText","toString","remoteAddress","getRemoteAddressAsText","procedure","api","find","response","handleRPC","writeStatus","encoder","contentType","forEach","v","k","encode","error","result","logError","remove","handleContainerDisposal","endWithoutBody","start","Promise","resolve","reject","hostname","listen","port","socket","logger","info","stop","close","cause","message","dispose","call","transport","chunks","onData","chunk","isLast","push","concat"],"mappings":"AAAA,SAEEA,QAAQ,EAIRC,KAAK,EAELC,SAAS,QACJ,qBAAoB;AAC3B,SAASC,aAAa,QAAQ,gBAAe;AAC7C,SACEC,GAAG,EAEHC,MAAM,QAED,iBAAgB;AACvB,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,aAAa,EAAEC,SAAS,EAAEC,cAAc,QAAQ,aAAY;AAErE,OAAO,MAAMC;;;IACDC,OAAqB;IACZC,cAAkC;IAErDC,YACE,AAAmBC,WAA+B,EAClD,AAAmBC,OAA6B,CAChD;aAFmBD,cAAAA;aACAC,UAAAA;aAJFH,gBAAgBT,cAAca,IAAI;QAMnD,IAAI,CAACL,MAAM,GAAG,IAAI,CAACI,OAAO,CAACE,GAAG,GAAGZ,OAAOU,QAAQE,GAAG,IAAKb;QAExD,IAAI,CAACO,MAAM,CACRO,GAAG,CAAC,YAAY,CAACC;YAChBA,IAAIC,IAAI,CAAC;gBAEPD,IAAIE,WAAW,CAAC,+BAA+B;gBAC/CF,IAAIE,WAAW,CAAC,gCAAgC;gBAChDF,IAAIE,WAAW,CAAC,gCAAgC;gBAChDF,IAAIE,WAAW,CAAC,gBAAgB;gBAChCF,IAAIG,GAAG,CAAC;YACV;QACF,GACCC,IAAI,CAAC,4BAA4B,OAAOJ,KAAKK;YAC5C,MAAMC,KAAK,IAAIC;YACfP,IAAIQ,SAAS,CAAC,IAAMF,GAAGG,KAAK;YAC5B,MAAMC,SAAS,CAACC;gBACd,IAAI,CAACL,GAAGM,MAAM,CAACC,OAAO,EAAEb,IAAIC,IAAI,CAACU;YACnC;YAEA,IAAI;gBACF,MAAMG,cAAcxB,eAAee;gBAEnC,MAAMU,cAAcV,IAAIW,YAAY,CAAC;gBACrC,MAAMC,gBAAgBZ,IAAIW,YAAY,CAAC;gBAEvC,MAAME,UAAU,IAAI,CAACv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AACD,UAAU,IAAI,CAAC9E,OAAO,CAACgF,IAAI,EAAG,CAACC;gBAChD,IAAIA,QAAQ;oBACV,IAAI,CAACC,MAAM,CAACC,IAAI,CACd,2BACAL,UACA,IAAI,CAAC9E,OAAO,CAACgF,IAAI;oBAEnBJ;gBACF,OAAO;oBACLC,OAAO,IAAIpD,MAAM;gBACnB;YACF;QACF;IACF;IAEA,MAAM2D,OAAO;QACX,IAAI,CAACxF,MAAM,CAACyF,KAAK;IACnB;IAEA,IAAc5B,MAAM;QAClB,OAAO,IAAI,CAAC1D,WAAW,CAAC0D,GAAG;IAC7B;IAEA,IAAcyB,SAAS;QACrB,OAAO,IAAI,CAACnF,WAAW,CAACmF,MAAM;IAChC;IAEA,MAAgBZ,SACdgB,KAAY,EACZC,UAAU,wCAAwC,EAClD;QACA,IAAI,CAACL,MAAM,CAACd,KAAK,CAAC,IAAI3C,MAAM8D,SAAS;YAAED;QAAM;IAC/C;IAEUd,wBAAwBzC,SAAoB,EAAE;QACtDA,UAAUyD,OAAO;IACnB;IAEA,MAAgB5B,UAAU5D,OAOzB,EAAE;QACD,OAAO,MAAM,IAAI,CAACyD,GAAG,CAACgC,IAAI,CAAC;YACzB,GAAGzF,OAAO;YACV0F,WAAW,IAAI,CAAC7F,aAAa;QAC/B;IACF;IAEA,MAAgBiC,QAAQ1B,GAAiB,EAAE;QACzC,OAAO,IAAIuE,QAAgB,CAACC;YAC1B,MAAMe,SAAmB,EAAE;YAC3BvF,IAAIwF,MAAM,CAAC,CAACC,OAAOC;gBACjBH,OAAOI,IAAI,CAAC7C,OAAOC,IAAI,CAAC0C;gBACxB,IAAIC,QAAQ;oBACVlB,QAAQ1B,OAAO8C,MAAM,CAACL;gBACxB;YACF;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../lib/server.ts"],"sourcesContent":["import {\n type AnyProcedure,\n ApiError,\n type ApplicationContext,\n type Connection,\n type Container,\n Scope,\n type Service,\n injectables,\n} from '@nmtjs/application'\nimport { TransportType } from '@nmtjs/common'\nimport {\n App,\n type HttpResponse,\n SSLApp,\n type TemplatedApp,\n} from 'uWebSockets.js'\nimport { connectionData } from './injectables.ts'\nimport type { HttpTransportOptions } from './types.ts'\nimport { InternalError, getFormat, getRequestData } from './utils.ts'\n\nexport class HttpTransportServer {\n protected server!: TemplatedApp\n protected readonly transportType = TransportType.HTTP\n\n constructor(\n protected readonly application: ApplicationContext,\n protected readonly options: HttpTransportOptions,\n ) {\n this.server = this.options.tls ? SSLApp(options.tls!) : App()\n\n this.server\n .get('/healthy', (res) => {\n res.cork(() => {\n // cors\n res.writeHeader('Access-Control-Allow-Origin', '*')\n res.writeHeader('Access-Control-Allow-Headers', 'Content-Type')\n res.writeHeader('Access-Control-Allow-Methods', 'GET')\n res.writeHeader('Content-Type', 'text/plain')\n res.end('OK')\n })\n })\n .post('/api/:service/:procudure', async (res, req) => {\n const ac = new AbortController()\n res.onAborted(() => ac.abort())\n const tryEnd = (cb) => {\n if (!ac.signal.aborted) res.cork(cb)\n }\n\n try {\n const requestData = getRequestData(req)\n\n const serviceName = req.getParameter(0)!\n const procedureName = req.getParameter(1)!\n\n const service = this.application.registry.services.get(serviceName)\n\n if (!service) throw new Error(`Service ${serviceName} not found`)\n if (this.transportType in service.contract.transports === false)\n throw new Error(`Service ${serviceName} not supported`)\n\n const format = getFormat(requestData, this.application.format)\n const body = await this.getBody(res)\n const container = this.application.container.createScope(Scope.Call)\n const payload = body.byteLength ? format.decoder.decode(body) : null\n const connection = this.application.connections.add({\n services: [serviceName],\n type: this.transportType,\n subscriptions: new Map(),\n })\n\n const responseHeaders = new Headers()\n\n container.provide(connectionData, {\n query: requestData.query,\n headers: requestData.headers,\n proxiedRemoteAddress: Buffer.from(\n res.getProxiedRemoteAddressAsText(),\n ).toString(),\n remoteAddress: Buffer.from(res.getRemoteAddressAsText()).toString(),\n responseHeaders,\n })\n container.provide(injectables.connection, connection)\n container.provide(injectables.callSignal, ac.signal)\n\n const { procedure } = this.api.find(\n serviceName,\n procedureName,\n this.transportType,\n )\n\n try {\n const response = await this.handleRPC({\n connection,\n service,\n procedure,\n container,\n signal: ac.signal,\n payload,\n })\n\n tryEnd(() => {\n res\n .writeStatus('200 OK')\n .writeHeader('Content-Type', format.encoder.contentType)\n responseHeaders.forEach((v, k) => res.writeHeader(k, v))\n res.end(format.encoder.encode({ error: null, result: response }))\n })\n } catch (error: any) {\n if (error instanceof ApiError) {\n tryEnd(() =>\n res\n .writeStatus('200 OK')\n .end(format.encoder.encode({ error, result: null })),\n )\n } else {\n tryEnd(() =>\n res.writeStatus('200 OK').end(\n format.encoder.encode({\n error: InternalError(),\n result: null,\n }),\n ),\n )\n }\n this.logError(error)\n } finally {\n this.application.connections.remove(connection)\n this.handleContainerDisposal(container)\n }\n } catch (error: any) {\n this.logError(error)\n tryEnd(() =>\n res.writeStatus('500 Internal Server Error').endWithoutBody(),\n )\n }\n })\n }\n\n async start() {\n return new Promise<void>((resolve, reject) => {\n const hostname = this.options.hostname ?? '127.0.0.1'\n this.server.listen(hostname, this.options.port!, (socket) => {\n if (socket) {\n this.logger.info(\n 'Server started on %s:%s',\n hostname,\n this.options.port!,\n )\n resolve()\n } else {\n reject(new Error('Failed to start server'))\n }\n })\n })\n }\n\n async stop() {\n this.server.close()\n }\n\n protected get api() {\n return this.application.api\n }\n\n protected get logger() {\n return this.application.logger\n }\n\n protected async logError(\n cause: Error,\n message = 'Unknown error while processing request',\n ) {\n this.logger.error(new Error(message, { cause }))\n }\n\n protected handleContainerDisposal(container: Container) {\n container.dispose()\n }\n\n protected async handleRPC(options: {\n connection: Connection\n service: Service\n procedure: AnyProcedure\n container: Container\n signal: AbortSignal\n payload: any\n }) {\n return await this.api.call({\n ...options,\n transport: this.transportType,\n })\n }\n\n protected async getBody(res: HttpResponse) {\n return new Promise<Buffer>((resolve) => {\n const chunks: Buffer[] = []\n res.onData((chunk, isLast) => {\n chunks.push(Buffer.from(chunk))\n if (isLast) {\n resolve(Buffer.concat(chunks))\n }\n })\n })\n }\n}\n"],"names":["ApiError","Scope","injectables","TransportType","App","SSLApp","connectionData","InternalError","getFormat","getRequestData","HttpTransportServer","server","transportType","constructor","application","options","HTTP","tls","get","res","cork","writeHeader","end","post","req","ac","AbortController","onAborted","abort","tryEnd","cb","signal","aborted","requestData","serviceName","getParameter","procedureName","service","registry","services","Error","contract","transports","format","body","getBody","container","createScope","Call","payload","byteLength","decoder","decode","connection","connections","add","type","subscriptions","Map","responseHeaders","Headers","provide","query","headers","proxiedRemoteAddress","Buffer","from","getProxiedRemoteAddressAsText","toString","remoteAddress","getRemoteAddressAsText","callSignal","procedure","api","find","response","handleRPC","writeStatus","encoder","contentType","forEach","v","k","encode","error","result","logError","remove","handleContainerDisposal","endWithoutBody","start","Promise","resolve","reject","hostname","listen","port","socket","logger","info","stop","close","cause","message","dispose","call","transport","chunks","onData","chunk","isLast","push","concat"],"mappings":"AAAA,SAEEA,QAAQ,EAIRC,KAAK,EAELC,WAAW,QACN,qBAAoB;AAC3B,SAASC,aAAa,QAAQ,gBAAe;AAC7C,SACEC,GAAG,EAEHC,MAAM,QAED,iBAAgB;AACvB,SAASC,cAAc,QAAQ,mBAAkB;AAEjD,SAASC,aAAa,EAAEC,SAAS,EAAEC,cAAc,QAAQ,aAAY;AAErE,OAAO,MAAMC;;;IACDC,OAAqB;IACZC,cAAkC;IAErDC,YACE,AAAmBC,WAA+B,EAClD,AAAmBC,OAA6B,CAChD;aAFmBD,cAAAA;aACAC,UAAAA;aAJFH,gBAAgBT,cAAca,IAAI;QAMnD,IAAI,CAACL,MAAM,GAAG,IAAI,CAACI,OAAO,CAACE,GAAG,GAAGZ,OAAOU,QAAQE,GAAG,IAAKb;QAExD,IAAI,CAACO,MAAM,CACRO,GAAG,CAAC,YAAY,CAACC;YAChBA,IAAIC,IAAI,CAAC;gBAEPD,IAAIE,WAAW,CAAC,+BAA+B;gBAC/CF,IAAIE,WAAW,CAAC,gCAAgC;gBAChDF,IAAIE,WAAW,CAAC,gCAAg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I,CAAC9F,aAAa;QAC/B;IACF;IAEA,MAAgBiC,QAAQ1B,GAAiB,EAAE;QACzC,OAAO,IAAIwE,QAAgB,CAACC;YAC1B,MAAMe,SAAmB,EAAE;YAC3BxF,IAAIyF,MAAM,CAAC,CAACC,OAAOC;gBACjBH,OAAOI,IAAI,CAAC9C,OAAOC,IAAI,CAAC2C;gBACxB,IAAIC,QAAQ;oBACVlB,QAAQ3B,OAAO+C,MAAM,CAACL;gBACxB;YACF;QACF;IACF;AACF"}
|
package/index.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type LazyInjectable,
|
|
3
|
+
type Scope,
|
|
4
|
+
injectables,
|
|
5
|
+
} from '@nmtjs/application'
|
|
6
|
+
import type { HttpConnectionData } from './types.ts'
|
|
7
|
+
|
|
8
|
+
export const connectionData = injectables.connectionData as LazyInjectable<
|
|
9
|
+
HttpConnectionData,
|
|
10
|
+
Scope.Connection
|
|
11
|
+
>
|
package/lib/server.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type Container,
|
|
7
7
|
Scope,
|
|
8
8
|
type Service,
|
|
9
|
-
|
|
9
|
+
injectables,
|
|
10
10
|
} from '@nmtjs/application'
|
|
11
11
|
import { TransportType } from '@nmtjs/common'
|
|
12
12
|
import {
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
SSLApp,
|
|
16
16
|
type TemplatedApp,
|
|
17
17
|
} from 'uWebSockets.js'
|
|
18
|
-
import { connectionData } from './
|
|
18
|
+
import { connectionData } from './injectables.ts'
|
|
19
19
|
import type { HttpTransportOptions } from './types.ts'
|
|
20
20
|
import { InternalError, getFormat, getRequestData } from './utils.ts'
|
|
21
21
|
|
|
@@ -80,8 +80,8 @@ export class HttpTransportServer {
|
|
|
80
80
|
remoteAddress: Buffer.from(res.getRemoteAddressAsText()).toString(),
|
|
81
81
|
responseHeaders,
|
|
82
82
|
})
|
|
83
|
-
container.provide(
|
|
84
|
-
container.provide(
|
|
83
|
+
container.provide(injectables.connection, connection)
|
|
84
|
+
container.provide(injectables.callSignal, ac.signal)
|
|
85
85
|
|
|
86
86
|
const { procedure } = this.api.find(
|
|
87
87
|
serviceName,
|
package/package.json
CHANGED
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.47.0"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@nmtjs/application": "^0.
|
|
15
|
-
"@nmtjs/common": "^0.
|
|
14
|
+
"@nmtjs/application": "^0.2.1",
|
|
15
|
+
"@nmtjs/common": "^0.2.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@nmtjs/application": "^0.
|
|
19
|
-
"@nmtjs/common": "^0.
|
|
18
|
+
"@nmtjs/application": "^0.2.1",
|
|
19
|
+
"@nmtjs/common": "^0.2.1",
|
|
20
|
+
"@types/node": "^18.0.0"
|
|
20
21
|
},
|
|
21
22
|
"engines": {
|
|
22
23
|
"node": ">=18.9.0"
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"LICENSE.md",
|
|
30
31
|
"README.md"
|
|
31
32
|
],
|
|
32
|
-
"version": "0.0
|
|
33
|
+
"version": "0.1.0",
|
|
33
34
|
"scripts": {
|
|
34
35
|
"build": "neemata-build ./index.ts './lib/**/*.ts'",
|
|
35
36
|
"type-check": "tsc --noEmit"
|
package/dist/lib/providers.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/providers.ts"],"sourcesContent":["import { providers } from '@nmtjs/application'\nimport type { HttpConnectionData } from './types.ts'\n\nexport const connectionData =\n providers.connectionData.$withType<HttpConnectionData>()\n"],"names":["providers","connectionData","$withType"],"mappings":"AAAA,SAASA,SAAS,QAAQ,qBAAoB;AAG9C,OAAO,MAAMC,iBACXD,UAAUC,cAAc,CAACC,SAAS,GAAsB"}
|