@alwatr/nanotron-api-server 4.9.1 → 4.9.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/CHANGELOG.md +28 -0
- package/dist/main.cjs +3 -3
- package/dist/main.cjs.map +2 -2
- package/dist/main.mjs +3 -3
- package/dist/main.mjs.map +2 -2
- package/package.json +37 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
# Change Log
|
|
2
|
+
# Changelog
|
|
3
|
+
|
|
4
|
+
All notable changes to this project will be documented in this file.
|
|
2
5
|
|
|
3
6
|
All notable changes to this project will be documented in this file.
|
|
4
7
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
8
|
|
|
9
|
+
## [4.9.4](https://github.com/Alwatr/nanotron/compare/v4.9.3...v4.9.4) (2025-08-23)
|
|
10
|
+
|
|
11
|
+
### 🔨 Code Refactoring
|
|
12
|
+
|
|
13
|
+
* reorganize package.json files for consistency and clarity ([bde116e](https://github.com/Alwatr/nanotron/commit/bde116e21f9d9bd6084940e257438916d2c3d312)) by @alimd
|
|
14
|
+
|
|
15
|
+
### 🔗 Dependencies update
|
|
16
|
+
|
|
17
|
+
* downgrade @types/node version to 22.17.2 in all package.json files ([4f01e14](https://github.com/Alwatr/nanotron/commit/4f01e1408d8d0954865eb9d20f90178f13e98719)) by @alimd
|
|
18
|
+
* update dependencies for eslint-config, lerna-lite, typescript, and nanolib ([de16a71](https://github.com/Alwatr/nanotron/commit/de16a718bb1c0fa569d39c824ec39a1e67ef8dfe)) by @alimd
|
|
19
|
+
|
|
20
|
+
## [4.9.3](https://github.com/Alwatr/nanotron/compare/v4.9.2...v4.9.3) (2025-07-23)
|
|
21
|
+
|
|
22
|
+
**Note:** Version bump only for package @alwatr/nanotron-api-server
|
|
23
|
+
|
|
24
|
+
## [4.9.2](https://github.com/Alwatr/nanotron/compare/v4.9.1...v4.9.2) (2025-07-23)
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* correct route matching logic in NanotronApiServer ([509b46f](https://github.com/Alwatr/nanotron/commit/509b46fd478b55cce6aa2f564c051d4b36044649)) by @alimd
|
|
29
|
+
|
|
30
|
+
### Dependencies update
|
|
31
|
+
|
|
32
|
+
* update dependencies to latest versions ([353d048](https://github.com/Alwatr/nanotron/commit/353d0485a5c21ab219d84cd0a6c35f62b46c2da9)) by @alimd
|
|
33
|
+
|
|
6
34
|
## [4.9.1](https://github.com/Alwatr/nanotron/compare/v4.9.0...v4.9.1) (2025-03-06)
|
|
7
35
|
|
|
8
36
|
### Dependencies update
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @alwatr/nanotron-api-server v4.9.
|
|
1
|
+
/* @alwatr/nanotron-api-server v4.9.4 */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -638,7 +638,7 @@ _NanotronUrl.versionPattern_ = new RegExp("^/v[0-9]+/");
|
|
|
638
638
|
var NanotronUrl = _NanotronUrl;
|
|
639
639
|
|
|
640
640
|
// src/api-server.ts
|
|
641
|
-
__dev_mode__: import_nanolib3.packageTracer.add("@alwatr/nanotron-api-server", "4.9.
|
|
641
|
+
__dev_mode__: import_nanolib3.packageTracer.add("@alwatr/nanotron-api-server", "4.9.4");
|
|
642
642
|
var _NanotronApiServer = class _NanotronApiServer {
|
|
643
643
|
constructor(config) {
|
|
644
644
|
this.config_ = {
|
|
@@ -687,7 +687,7 @@ var _NanotronApiServer = class _NanotronApiServer {
|
|
|
687
687
|
if (Object.hasOwn(this.routeHandlerList__.startsWith, url.method)) {
|
|
688
688
|
const routeList = this.routeHandlerList__.startsWith[url.method];
|
|
689
689
|
for (const pathname in routeList) {
|
|
690
|
-
if (pathname.indexOf(
|
|
690
|
+
if (url.pathname.indexOf(pathname) === 0) {
|
|
691
691
|
return routeList[pathname];
|
|
692
692
|
}
|
|
693
693
|
}
|
package/dist/main.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts", "../src/api-server.ts", "../src/api-client-request.ts", "../src/api-server-response.ts", "../src/const.ts", "../src/url.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './api-server.js';\nexport * from './type.js';\nexport * from './const.js';\n\nexport type {NanotronClientRequest} from './api-client-request.js';\nexport type {NanotronServerResponse} from './api-server-response.js';\nexport type {NanotronUrl} from './url.js';\n", "import {createServer} from 'node:http';\n\nimport {createLogger, packageTracer} from '@alwatr/nanolib';\n\nimport {NanotronClientRequest} from './api-client-request.js';\nimport {HttpStatusCodes, HttpStatusMessages} from './const.js';\nimport {NanotronUrl} from './url.js';\n\nimport type {DefineRouteOption, MatchType, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {Duplex} from 'node:stream';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Configuration options for the NanotronApiServer.\n */\nexport interface NanotronApiServerConfig {\n /**\n * The port number to listen on.\n *\n * @default 80\n */\n port?: number;\n\n /**\n * The hostname to listen on.\n *\n * @default '0.0.0.0'\n */\n host?: string;\n\n /**\n * Sets the timeout (ms) for receiving the entire request from the client.\n *\n * @default 10_000 ms\n */\n requestTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * This should be bigger than `keepAliveTimeout + your server's expected response time`.\n *\n * @default 130_000 ms\n */\n headersTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * @default 120_000 ms\n */\n keepAliveTimeout?: number;\n\n /**\n * Add /health route.\n *\n * @default true\n */\n healthRoute?: boolean;\n\n /**\n * Add OPTIONS route for preflight requests to allow access origins.\n *\n * @default {enable: false, origin: '*', methods: '*', headers: '*', maxAge: 86_400}\n */\n crossOrigin?: {\n enable: boolean;\n origin: string;\n methods: string;\n headers: string;\n maxAge: string | number;\n },\n\n /**\n * A prefix to be added to the beginning of the `url` of all defined routes.\n *\n * @default '/api/'\n */\n prefix?: `/${string}/` | '/';\n\n /**\n * The maximum size of the request body in bytes.\n *\n * @default `1_048_576` (1MiB)\n */\n bodyLimit?: number;\n}\n\nexport class NanotronApiServer {\n protected static readonly defaultConfig_: Readonly<Required<NanotronApiServerConfig>> = {\n host: '0.0.0.0',\n port: 80,\n requestTimeout: 10_000,\n headersTimeout: 130_000,\n keepAliveTimeout: 120_000,\n healthRoute: true,\n crossOrigin: {\n enable: false,\n origin: '*',\n methods: '*',\n headers: '*',\n maxAge: 86_400, // 24h\n },\n prefix: '/api/',\n bodyLimit: 1_048_576, // 1MiB\n };\n\n readonly config_: Required<NanotronApiServerConfig>;\n protected readonly logger_;\n\n readonly httpServer;\n\n protected readonly routeHandlerList__: Record<MatchType, DictionaryOpt<DictionaryOpt<Required<DefineRouteOption>>>>;\n\n constructor(config?: Partial<NanotronApiServerConfig>) {\n // Merge the config with the default config.\n this.config_ = {\n ...NanotronApiServer.defaultConfig_,\n ...config,\n };\n\n // Create logger.\n this.logger_ = createLogger('nt-api-server' + (this.config_.port !== 80 ? ':' + this.config_.port : ''));\n this.logger_.logMethodArgs?.('new', {config: this.config_});\n\n // Bind methods.\n this.handleClientRequest_ = this.handleClientRequest_.bind(this);\n this.handleServerError_ = this.handleServerError_.bind(this);\n this.handleClientError_ = this.handleClientError_.bind(this);\n\n // Initialize route handler list.\n this.routeHandlerList__ = {\n exact: {},\n startsWith: {},\n };\n\n // Create the HTTP server.\n this.httpServer = createServer(\n {\n keepAlive: true,\n keepAliveInitialDelay: 0,\n noDelay: true,\n },\n this.handleClientRequest_,\n );\n\n // Configure the server.\n this.httpServer.requestTimeout = this.config_.requestTimeout;\n this.httpServer.keepAliveTimeout = this.config_.keepAliveTimeout;\n this.httpServer.headersTimeout = this.config_.headersTimeout;\n\n // Start the server.\n this.httpServer.listen(this.config_.port, this.config_.host, () => {\n this.logger_.logOther?.(`listening on ${this.config_.host}:${this.config_.port}`);\n });\n\n // Handle server errors.\n this.httpServer.on('error', this.handleServerError_);\n this.httpServer.on('clientError', this.handleClientError_);\n\n this.defineCorsRoute_();\n\n if (this.config_.healthRoute) {\n this.defineHealthRoute_();\n }\n }\n\n close(): void {\n this.logger_.logMethod?.('close');\n this.httpServer.close();\n }\n\n protected getRouteOption_(url: NanotronUrl): Required<DefineRouteOption> | null {\n this.logger_.logMethod?.('getRouteOption_');\n\n if (\n Object.hasOwn(this.routeHandlerList__.exact, url.method) &&\n Object.hasOwn(this.routeHandlerList__.exact[url.method]!, url.pathname)\n ) {\n return this.routeHandlerList__.exact[url.method]![url.pathname]!;\n }\n\n if (Object.hasOwn(this.routeHandlerList__.startsWith, url.method)) {\n const routeList = this.routeHandlerList__.startsWith[url.method];\n for (const pathname in routeList) {\n if (pathname.indexOf(url.pathname) === 0) {\n return routeList[pathname]!;\n }\n }\n }\n\n this.logger_.incident?.('getRouteOption_', 'route_not_found', {method: url.method, url: url.pathname});\n return null;\n }\n\n protected setRouteOption_(option: Required<DefineRouteOption>): void {\n this.logger_.logMethodArgs?.('setRouteOption_', option);\n\n const routeHandlerList = this.routeHandlerList__[option.matchType];\n\n routeHandlerList[option.method] ??= {};\n\n if (Object.hasOwn(routeHandlerList[option.method]!, option.url)) {\n this.logger_.error('defineRoute', 'route_already_exists', option);\n throw new Error('route_already_exists');\n }\n\n routeHandlerList[option.method]![option.url] = option;\n }\n\n defineRoute<TSharedMeta extends DictionaryOpt = DictionaryOpt>(option: DefineRouteOption<TSharedMeta>): void {\n const option_: Required<DefineRouteOption<TSharedMeta>> = {\n matchType: 'exact',\n preHandlers: [],\n postHandlers: [],\n bodyLimit: this.config_.bodyLimit,\n crossOrigin: this.config_.crossOrigin,\n ...option,\n };\n this.logger_.logMethodArgs?.('defineRoute', option_);\n this.setRouteOption_(option_ as Required<DefineRouteOption>);\n }\n\n protected handleServerError_(error: NodeJS.ErrnoException): void {\n if (error.code === 'EADDRINUSE') {\n this.logger_.error('handleServerError_', 'address_in_use', error);\n }\n else {\n this.logger_.error('handleServerError_', 'http_server_error', error);\n }\n }\n\n protected handleClientError_(err: NodeJS.ErrnoException, socket: Duplex): void {\n this.logger_.accident('handleClientError_', 'http_server_client_error', {\n errCode: err.code,\n errMessage: err.message,\n });\n\n const errorCode = err.code?.toLowerCase() ?? `error_${HttpStatusCodes.Error_Client_400_Bad_Request}`;\n const errorMessage = err.message ?? HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request];\n const errorResponse = `{\"ok\":false,\"errorCode\":\"${errorCode}\",\"errorMessage\":\"${errorMessage}\"}`;\n\n const responseHeaders = [\n `HTTP/1.1 ${HttpStatusCodes.Error_Client_400_Bad_Request} ${HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request]}`,\n 'content-type: application/json',\n `content-length: ${Buffer.byteLength(errorResponse)}`,\n '\\r\\n',\n ].join('\\r\\n');\n\n socket.end(responseHeaders + errorResponse);\n }\n\n protected async handleClientRequest_(\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n ): Promise<void> {\n this.logger_.logMethod?.('handleClientRequest_');\n\n if (nativeClientRequest.url === undefined) {\n this.logger_.accident('handleClientRequest_', 'http_server_url_undefined');\n return;\n }\n\n const url = new NanotronUrl(nativeClientRequest, this.config_.prefix);\n\n const routeOption = this.getRouteOption_(url);\n\n const connection = new NanotronClientRequest(url, nativeClientRequest, nativeServerResponse, routeOption);\n\n if (routeOption === null) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Client_404_Not_Found;\n connection.serverResponse.replyError();\n return;\n }\n\n try {\n for (const handler of routeOption.preHandlers) {\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n if (connection.terminatedHandlers === true) return; // must check after each pre-handler.\n }\n\n await routeOption.handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n\n for (const handler of routeOption.postHandlers) {\n if (connection.terminatedHandlers === true) return; // must check before each post-handler.\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n }\n }\n catch (error) {\n this.logger_.error('handleClientRequest_', 'route_handler_error', error, url.debugId);\n\n if (connection.serverResponse.statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n }\n connection.serverResponse.replyError(error);\n }\n\n // TODO: handled open remained connections.\n }\n\n protected defineHealthRoute_(): void {\n this.logger_.logMethod?.('defineHealthRoute_');\n\n this.defineRoute({\n method: 'GET',\n url: '/health',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.statusCode = HttpStatusCodes.Success_200_OK;\n res.setHeader('server', 'Alwatr Nanotron');\n res.setHeader('content-type', 'application/json');\n res.end('{\"ok\":true}');\n },\n });\n }\n\n protected defineCorsRoute_(): void {\n this.logger_.logMethod?.('defineCorsRoute_');\n const crossOrigin = this.config_.crossOrigin;\n if (crossOrigin?.enable !== true) return;\n this.defineRoute({\n method: 'OPTIONS',\n matchType: 'startsWith',\n url: '/',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.writeHead(HttpStatusCodes.Success_204_No_Content, {\n 'access-control-allow-origin': crossOrigin.origin,\n 'access-control-allow-methods': crossOrigin.methods,\n 'access-control-allow-headers': crossOrigin.headers,\n 'access-control-max-age': crossOrigin.maxAge + '',\n 'content-length': 0,\n });\n res.end();\n },\n });\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {NanotronServerResponse} from './api-server-response.js';\nimport {HttpStatusCodes} from './const.js';\n\nimport type {DefineRouteOption, HttpRequestHeaders, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {NanotronUrl} from './url.js';\n\nexport class NanotronClientRequest<TSharedMeta extends DictionaryOpt = DictionaryOpt> {\n readonly url: NanotronUrl;\n\n readonly serverResponse: NanotronServerResponse;\n\n readonly routeOption: Required<DefineRouteOption> | null;\n\n /**\n * A flag to indicate if the running handlers queue has been terminated.\n * This can occur due to an error being thrown or by explicitly calling the `replyError` method.\n *\n * When `terminatedHandlers` is set to `true`, it signifies that the execution of the current\n * sequence of handlers (including pre, main, and post handlers) has been halted and no further\n * handlers in the queue will be executed.\n *\n * Usage:\n * - Check this flag to determine if the handlers queue has been interrupted.\n * - Set this flag to `true` to manually stop the execution of subsequent handlers.\n */\n terminatedHandlers?: true;\n\n readonly sharedMeta: TSharedMeta = {} as TSharedMeta;\n\n readonly raw_: NativeClientRequest;\n\n protected readonly logger_;\n\n readonly remoteAddress: string | null;\n\n get headers(): HttpRequestHeaders {\n return this.raw_.headers;\n }\n\n private queryParams__?: DictionaryOpt<string>;\n get queryParams(): DictionaryOpt<string> {\n if (this.queryParams__ === undefined) {\n this.queryParams__ = {};\n for (const [key, value] of this.url.searchParams.entries()) {\n this.queryParams__[key] = value;\n }\n }\n return this.queryParams__;\n }\n\n constructor(\n url: NanotronUrl,\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n routeOption: Required<DefineRouteOption> | null,\n ) {\n // Store public properties.\n this.raw_ = nativeClientRequest;\n this.url = url;\n this.routeOption = routeOption;\n\n // Get and store remote address.\n this.remoteAddress = this.getRemoteAddress__();\n\n // Create logger.\n this.logger_ = createLogger(`nt-client-request(${this.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', url.debugId);\n\n // Create server response.\n this.serverResponse = new NanotronServerResponse(this, nativeServerResponse);\n }\n\n getBodyRaw(): Promise<Buffer> {\n return new Promise((resolve, reject) => {\n // method must be POST or PUT or PATCH\n const method = this.url.method;\n if (!(method === 'POST' || method === 'PUT' || method === 'PATCH')) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_405_Method_Not_Allowed;\n return reject(new Error('body_not_allowed'));\n }\n\n const contentLength = +this.raw_.headers['content-length']!;\n\n if (Number.isNaN(contentLength) || contentLength === 0) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_411_Length_Required;\n return reject(new Error('body_length_required'));\n }\n\n if (contentLength > this.routeOption!.bodyLimit) {\n // TODO: routeOption when null?!\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const dataChunks: Uint8Array[] = [];\n let receivedLength = 0;\n\n const onData = (chunk: Uint8Array) => {\n receivedLength += chunk.length;\n dataChunks.push(chunk);\n\n if (receivedLength > this.routeOption!.bodyLimit) {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n dataChunks.length = 0; // free memory\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n };\n\n const onEnd = (err?: Error) => {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n\n if (err !== undefined) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_400_Bad_Request;\n return reject(err);\n }\n\n if (receivedLength !== contentLength) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const body = Buffer.concat(dataChunks);\n\n resolve(body);\n };\n\n this.raw_.on('data', onData);\n this.raw_.on('end', onEnd);\n this.raw_.on('error', onEnd);\n this.raw_.resume();\n });\n }\n\n private getRemoteAddress__(): string | null {\n return this.raw_.headers['x-forwarded-for']?.split(',').pop()?.trim() || this.raw_.socket.remoteAddress || null;\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {type HttpStatusCode, HttpStatusCodes, HttpStatusMessages} from './const.js';\n\nimport type {NanotronClientRequest} from './api-client-request.js';\nimport type {HttpResponseHeaders, ErrorResponse, NativeServerResponse} from './type.js';\n\n/**\n * Configuration options for the Nanotron Api Server Response.\n */\nexport interface NanotronServerResponseConfig {\n clientRequest: NanotronClientRequest;\n}\n\nexport class NanotronServerResponse {\n readonly clientRequest: NanotronClientRequest;\n\n readonly raw_: NativeServerResponse;\n\n readonly headers: HttpResponseHeaders;\n\n protected readonly logger_;\n\n protected hasBeenSent_ = false;\n get hasBeenSent(): boolean {\n return this.hasBeenSent_;\n }\n\n constructor(nanotronClientRequest: NanotronClientRequest, nativeServerResponse: NativeServerResponse) {\n // Store public properties.\n this.clientRequest = nanotronClientRequest;\n this.raw_ = nativeServerResponse;\n\n // Create logger.\n this.logger_ = createLogger(`nt-server-response(${this.clientRequest.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', this.clientRequest.url.debugId);\n\n // Set default reply headers.\n this.headers = {\n server: 'Alwatr Nanotron',\n 'content-type': 'text/plain charset=UTF-8',\n };\n\n const crossOrigin = this.clientRequest.routeOption?.crossOrigin;\n if (crossOrigin?.enable === true) {\n this.headers['access-control-allow-origin'] = crossOrigin.origin;\n this.headers['access-control-allow-methods'] = crossOrigin.methods;\n this.headers['access-control-allow-headers'] = crossOrigin.headers;\n this.headers['access-control-max-age'] = crossOrigin.maxAge;\n }\n }\n\n get statusCode(): HttpStatusCode {\n return this.raw_.statusCode as HttpStatusCode;\n }\n\n set statusCode(value: HttpStatusCode) {\n this.raw_.statusCode = value;\n }\n\n protected applyHeaders_() {\n this.logger_.logMethodArgs?.('applyHeaders_', this.headers);\n for (const key in this.headers) {\n this.raw_.setHeader(key, this.headers[key as Lowercase<string>]!);\n }\n }\n\n replyErrorResponse(errorResponse: ErrorResponse): void {\n this.logger_.logMethod?.('replyErrorResponse');\n this.clientRequest.terminatedHandlers = true;\n this.headers['content-type'] = 'application/json';\n let meta = '';\n if (errorResponse.meta !== undefined) {\n const metaType = typeof errorResponse.meta;\n if (\n metaType === 'string' ||\n metaType === 'number' ||\n metaType === 'boolean' ||\n errorResponse.meta === null) {\n meta = `,\"meta\":\"${errorResponse.meta}\"`;\n }\n else if (metaType === 'object') {\n meta = `,\"meta\":${JSON.stringify(errorResponse.meta)}`;\n }\n }\n const responseString = `{\"ok\":false,\"errorCode\":\"${errorResponse.errorCode}\",\"errorMessage\":\"${errorResponse.errorMessage}\"${meta}}`;\n this.reply(responseString);\n }\n\n replyError(error?: Error | string | Json | unknown): void {\n this.logger_.logMethodArgs?.('replyError', {error});\n\n this.clientRequest.terminatedHandlers = true;\n let statusCode = this.statusCode;\n\n if (statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n this.statusCode = statusCode = 500;\n }\n\n if (error instanceof Error) {\n this.replyErrorResponse({\n ok: false,\n errorCode: (error.name === 'Error' ? 'error_' + statusCode : (error.name + '').toLowerCase()) as Lowercase<string>,\n errorMessage: error.message,\n });\n }\n else if (typeof error === 'string') {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: error,\n });\n }\n else if (typeof error === 'object' && error !== null) {\n this.replyJson(error as Json);\n }\n else {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: HttpStatusMessages[statusCode],\n });\n }\n }\n\n replyJson(responseJson: Json): void {\n this.logger_.logMethodArgs?.('replyJson', {responseJson});\n\n let responseString: string;\n try {\n responseString = JSON.stringify(responseJson);\n }\n catch (error) {\n this.logger_.error('replyJson', 'reply_json_stringify_failed', error, this.clientRequest.url.debugId);\n this.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n this.replyErrorResponse({\n ok: false,\n errorCode: 'reply_json_stringify_failed',\n errorMessage: 'Failed to stringify response JSON.',\n });\n return;\n }\n\n this.headers['content-type'] = 'application/json';\n this.reply(responseString);\n }\n\n reply(context: string | Buffer): void {\n this.logger_.logMethodArgs?.('reply', this.clientRequest.url.debugId);\n\n if (this.raw_.writableFinished && this.hasBeenSent_ === false) {\n // The response has already been sent by direct access to the server api.\n this.logger_.accident('reply', 'server_response_writable_finished_directly');\n this.hasBeenSent_ = true;\n }\n\n if (this.hasBeenSent_) {\n this.logger_.accident('reply', 'reply_already_sent', {\n url: this.clientRequest.url.debugId,\n replySent: this.hasBeenSent_,\n writableFinished: this.raw_.writableFinished,\n });\n return;\n }\n\n this.hasBeenSent_ = true;\n\n try {\n if (typeof context === 'string') {\n context = Buffer.from(context);\n }\n\n this.headers['content-length'] = context.byteLength;\n\n this.applyHeaders_();\n this.raw_.end(context, 'binary');\n }\n catch (error) {\n this.logger_.error('reply', 'server_response_error', error, this.clientRequest.url.debugId);\n this.hasBeenSent_ = false;\n }\n }\n}\n", "/**\n * Object representing standard HTTP methods.\n */\nexport const HttpMethods = {\n /**\n * GET: Requests a representation of the specified resource.\n */\n GET: 'GET',\n\n /**\n * HEAD: Asks for a response identical to that of a GET request, but without the response body.\n */\n HEAD: 'HEAD',\n\n /**\n * POST: Submits data to be processed (e.g., from an HTML form) to the identified resource.\n */\n POST: 'POST',\n\n /**\n * PUT: Uploads a representation of the specified URI.\n */\n PUT: 'PUT',\n\n /**\n * DELETE: Deletes the specified resource.\n */\n DELETE: 'DELETE',\n\n /**\n * CONNECT: Establishes a tunnel to the server identified by the target resource.\n */\n CONNECT: 'CONNECT',\n\n /**\n * OPTIONS: Describes the communication options for the target resource.\n */\n OPTIONS: 'OPTIONS',\n\n /**\n * TRACE: Performs a message loop-back test along the path to the target resource.\n */\n TRACE: 'TRACE',\n\n /**\n * PATCH: Applies partial modifications to a resource.\n */\n PATCH: 'PATCH'\n} as const;\n\n/**\n * Object representing standard HTTP status codes.\n */\nexport const HttpStatusCodes = {\n /**\n * 100 Continue: The server has received the request headers and the client should proceed to send the request body.\n */\n Info_100_Continue: 100,\n\n /**\n * 101 Switching Protocols: The server understands and is willing to comply with the clients request to switch protocols.\n */\n Info_101_Switching_Protocols: 101,\n\n /**\n * 102 Processing: The server has received and is processing the request, but no response is available yet.\n */\n Info_102_Processing: 102,\n\n /**\n * 103 Early Hints: The server is sending some response headers before the final HTTP message.\n */\n Info_103_Early_Hints: 103,\n\n /**\n * 200 OK: The request has succeeded.\n */\n Success_200_OK: 200,\n\n /**\n * 201 Created: The request has been fulfilled and resulted in a new resource being created.\n */\n Success_201_Created: 201,\n\n /**\n * 202 Accepted: The request has been accepted for processing, but the processing has not been completed.\n */\n Success_202_Accepted: 202,\n\n /**\n * 203 Non-Authoritative Information: The server is a transforming proxy that received a 200 OK\n * from the origin server but is returning a modified version of the origins response.\n */\n Success_203_Non_Authoritative_Information: 203,\n\n /**\n * 204 No Content: The server successfully processed the request and is not returning any content.\n */\n Success_204_No_Content: 204,\n\n /**\n * 205 Reset Content: The server successfully processed the request,\n * asks that the client reset its document view, and is not returning any content.\n */\n Success_205_Reset_Content: 205,\n\n /**\n * 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.\n */\n Success_206_Partial_Content: 206,\n\n /**\n * 207 Multi-Status: The message body that follows is an XML message\n * and can contain a number of separate response codes, depending on how many sub-requests were made.\n */\n Success_207_Multi_Status: 207,\n\n /**\n * 208 Already Reported: The members of a DAV binding have already been enumerated\n * in a preceding part of the (multi-status) response, and are not being included again.\n */\n Success_208_Already_Reported: 208,\n\n /**\n * 226 IM Used: The server has fulfilled a request for the resource, and the response is a representation\n * of the result of one or more instance-manipulations applied to the current instance.\n */\n Success_226_IM_Used: 226,\n\n /**\n * 300 Multiple Choices: The request has more than one possible response.\n */\n Redirect_300_Multiple_Choices: 300,\n\n /**\n * 301 Moved Permanently: The URL of the requested resource has been changed permanently.\n */\n Redirect_301_Moved_Permanently: 301,\n\n /**\n * 302 Found: The URL of the requested resource has been changed temporarily.\n */\n Redirect_302_Found: 302,\n\n /**\n * 303 See Other: The response to the request can be found under another URI using a GET method.\n */\n Redirect_303_See_Other: 303,\n\n /**\n * 304 Not Modified: The resource has not been modified since the version specified\n * by the request headers If-Modified-Since or If-None-Match.\n */\n Redirect_304_Not_Modified: 304,\n\n /**\n * 305 Use Proxy: The requested resource is only available through a proxy, the address for which is provided in the response.\n */\n Redirect_305_Use_Proxy: 305,\n\n /**\n * 306 Switch Proxy: No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"\n */\n Redirect_306_Switch_Proxy: 306,\n\n /**\n * 307 Temporary Redirect: The server sends this response to direct the client\n * to get the requested resource at another URI with the same method that was used in the prior request.\n */\n Redirect_307_Temporary_Redirect: 307,\n\n /**\n * 308 Permanent Redirect: This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header.\n */\n Redirect_308_Permanent_Redirect: 308,\n\n /**\n * 400 Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error.\n */\n Error_Client_400_Bad_Request: 400,\n\n /**\n * 401 Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource.\n */\n Error_Client_401_Unauthorized: 401,\n\n /**\n * 402 Payment Required: Reserved for future use.\n */\n Error_Client_402_Payment_Required: 402,\n\n /**\n * 403 Forbidden: The client does not have access rights to the content, so the server is refusing to give the requested resource.\n */\n Error_Client_403_Forbidden: 403,\n\n /**\n * 404 Not Found: The server can not find the requested resource.\n */\n Error_Client_404_Not_Found: 404,\n\n /**\n * 405 Method Not Allowed: The request method is known by the server but is not supported by the target resource.\n */\n Error_Client_405_Method_Not_Allowed: 405,\n\n /**\n * 406 Not Acceptable: The target resource does not have a current representation that would be acceptable\n * to the user agent, according to the proactive negotiation header fields received in the request,\n * and the server is unwilling to supply a default representation.\n */\n Error_Client_406_Not_Acceptable: 406,\n\n /**\n * 407 Proxy Authentication Required: Similar to 401 Unauthorized,\n * but it indicates that the client needs to authenticate itself in order to use a proxy.\n */\n Error_Client_407_Proxy_Authentication_Required: 407,\n\n /**\n * 408 Request Timeout: The server timed out waiting for the request.\n */\n Error_Client_408_Request_Timeout: 408,\n\n /**\n * 409 Conflict: The request could not be processed because of conflict in the request, such as an edit conflict.\n */\n Error_Client_409_Conflict: 409,\n\n /**\n * 410 Gone: The requested resource is no longer available and will not be available again.\n */\n Error_Client_410_Gone: 410,\n\n /**\n * 411 Length Required: The server refuses to accept the request without a defined Content-Length header.\n */\n Error_Client_411_Length_Required: 411,\n\n /**\n * 412 Precondition Failed: One or more conditions given in the request header fields evaluated to false when tested on the server.\n */\n Error_Client_412_Precondition_Failed: 412,\n\n /**\n * 413 Payload Too Large: The server is refusing to process a request because the request payload is larger\n * than the server is willing or able to process.\n */\n Error_Client_413_Payload_Too_Large: 413,\n\n /**\n * 414 URI Too Long: The server is refusing to service the request because the URI is longer than the server is willing to interpret.\n */\n Error_Client_414_URI_Too_Long: 414,\n\n /**\n * 415 Unsupported Media Type: The server is refusing to service the request\n * because the entity of the request is in a format not supported by the requested resource for the requested method.\n */\n Error_Client_415_Unsupported_Media_Type: 415,\n\n /**\n * 416 Range Not Satisfiable: The client has asked for a portion of the file, but the server cannot supply that portion.\n */\n Error_Client_416_Range_Not_Satisfiable: 416,\n\n /**\n * 417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field.\n */\n Error_Client_417_Expectation_Failed: 417,\n\n /**\n * 421 Misdirected Request: The request was directed at a server that is not able to produce a response.\n */\n Error_Client_421_Misdirected_Request: 421,\n\n /**\n * 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.\n */\n Error_Client_422_Unprocessable_Entity: 422,\n\n /**\n * 423 Locked: The resource that is being accessed is locked.\n */\n Error_Client_423_Locked: 423,\n\n /**\n * 424 Failed Dependency: The request failed due to a failure of a previous request.\n */\n Error_Client_424_Failed_Dependency: 424,\n\n /**\n * 425 Too Early: The server is unwilling to risk processing a request that might be replayed.\n */\n Error_Client_425_Too_Early: 425,\n\n /**\n * 426 Upgrade Required: The server refuses to perform the request using the current protocol\n * but might be willing to do so after the client upgrades to a different protocol.\n */\n Error_Client_426_Upgrade_Required: 426,\n\n /**\n * 428 Precondition Required: The origin server requires the request to be conditional.\n */\n Error_Client_428_Precondition_Required: 428,\n\n /**\n * 429 Too Many Requests: The user has sent too many requests in a given amount of time (\"rate limiting\").\n */\n Error_Client_429_Too_Many_Requests: 429,\n\n /**\n * 431 Request Header Fields Too Large: The server is unwilling to process the request because its header fields are too large.\n */\n Error_Client_431_Request_Header_Fields_Too_Large: 431,\n\n /**\n * 451 Unavailable For Legal Reasons: The user requests an illegal resource, such as a web page censored by a government.\n */\n Error_Client_451_Unavailable_For_Legal_Reasons: 451,\n\n /**\n * 500 Internal Server Error: A generic error message, given when no more specific message is suitable.\n */\n Error_Server_500_Internal_Server_Error: 500,\n\n /**\n * 501 Not Implemented: The server either does not recognize the request method, or it lacks the ability to fulfill the request.\n */\n Error_Server_501_Not_Implemented: 501,\n\n /**\n * 502 Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server.\n */\n Error_Server_502_Bad_Gateway: 502,\n\n /**\n * 503 Service Unavailable: The server is currently unavailable (because it is overloaded or down for maintenance).\n */\n Error_Server_503_Service_Unavailable: 503,\n\n /**\n * 504 Gateway Timeout: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\n */\n Error_Server_504_Gateway_Timeout: 504,\n\n /**\n * 505 HTTP Version Not Supported: The server does not support the HTTP protocol version used in the request.\n */\n Error_Server_505_HTTP_Version_Not_Supported: 505,\n\n /**\n * 506 Variant Also Negotiates: Transparent content negotiation for the request results in a circular reference.\n */\n Error_Server_506_Variant_Also_Negotiates: 506,\n\n /**\n * 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.\n */\n Error_Server_507_Insufficient_Storage: 507,\n\n /**\n * 508 Loop Detected: The server detected an infinite loop while processing the request.\n */\n Error_Server_508_Loop_Detected: 508,\n\n /**\n * 510 Not Extended: Further extensions to the request are required for the server to fulfill it.\n */\n Error_Server_510_Not_Extended: 510,\n\n /**\n * 511 Network Authentication Required: The client needs to authenticate to gain network access.\n */\n Error_Server_511_Network_Authentication_Required: 511\n} as const;\n\nexport const HttpStatusMessages = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 208: 'Already Reported',\n 226: 'IM Used',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 305: 'Use Proxy',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: 'I\\'m a Teapot',\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 509: 'Bandwidth Limit Exceeded',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n};\n\nexport type HttpStatusCode = keyof typeof HttpStatusMessages;\n", "import {URL} from 'node:url';\n\nimport type {HttpMethod, NativeClientRequest} from './type.js';\n\nexport class NanotronUrl extends URL {\n protected static versionPattern_ = new RegExp('^/v[0-9]+/');\n\n readonly method: HttpMethod;\n readonly debugId: string;\n\n constructor(clientRequest: NativeClientRequest, prefix: `/${string}/` | '/') {\n let url = clientRequest.url ?? '';\n if (prefix !== '/' && url.indexOf(prefix) === 0) {\n url = url.slice(prefix.length - 1); // include `/`\n }\n url = url.replace(NanotronUrl.versionPattern_, '/');\n\n super(url, 'http://hostname/');\n\n this.method = (clientRequest.method ?? 'GET').toUpperCase() as HttpMethod;\n\n this.debugId = `[${this.method}]${this.pathname}`;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAA2B;AAE3B,IAAAA,kBAA0C;;;ACF1C,IAAAC,kBAA2B;;;ACA3B,qBAA2B;;;ACGpB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA,EAIzB,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,QAAQ;AAAA;AAAA;AAAA;AAAA,EAKR,SAAS;AAAA;AAAA;AAAA;AAAA,EAKT,SAAS;AAAA;AAAA;AAAA;AAAA,EAKT,OAAO;AAAA;AAAA;AAAA;AAAA,EAKP,OAAO;AACT;AAKO,IAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAI7B,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAKnB,8BAA8B;AAAA;AAAA;AAAA;AAAA,EAK9B,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB,sBAAsB;AAAA;AAAA;AAAA;AAAA,EAKtB,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtB,2CAA2C;AAAA;AAAA;AAAA;AAAA,EAK3C,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxB,2BAA2B;AAAA;AAAA;AAAA;AAAA,EAK3B,6BAA6B;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7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,IACX,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,IACT,QAAQ;AAAA;AAAA,EACV;AAAA,EACA,QAAQ;AAAA,EACR,WAAW;AAAA;AACb;AAjBK,IAAM,oBAAN;",
|
|
4
|
+
"sourcesContent": ["export * from './api-server.js';\nexport * from './type.js';\nexport * from './const.js';\n\nexport type {NanotronClientRequest} from './api-client-request.js';\nexport type {NanotronServerResponse} from './api-server-response.js';\nexport type {NanotronUrl} from './url.js';\n", "import {createServer} from 'node:http';\n\nimport {createLogger, packageTracer} from '@alwatr/nanolib';\n\nimport {NanotronClientRequest} from './api-client-request.js';\nimport {HttpStatusCodes, HttpStatusMessages} from './const.js';\nimport {NanotronUrl} from './url.js';\n\nimport type {DefineRouteOption, MatchType, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {Duplex} from 'node:stream';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Configuration options for the NanotronApiServer.\n */\nexport interface NanotronApiServerConfig {\n /**\n * The port number to listen on.\n *\n * @default 80\n */\n port?: number;\n\n /**\n * The hostname to listen on.\n *\n * @default '0.0.0.0'\n */\n host?: string;\n\n /**\n * Sets the timeout (ms) for receiving the entire request from the client.\n *\n * @default 10_000 ms\n */\n requestTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * This should be bigger than `keepAliveTimeout + your server's expected response time`.\n *\n * @default 130_000 ms\n */\n headersTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * @default 120_000 ms\n */\n keepAliveTimeout?: number;\n\n /**\n * Add /health route.\n *\n * @default true\n */\n healthRoute?: boolean;\n\n /**\n * Add OPTIONS route for preflight requests to allow access origins.\n *\n * @default {enable: false, origin: '*', methods: '*', headers: '*', maxAge: 86_400}\n */\n crossOrigin?: {\n enable: boolean;\n origin: string;\n methods: string;\n headers: string;\n maxAge: string | number;\n },\n\n /**\n * A prefix to be added to the beginning of the `url` of all defined routes.\n *\n * @default '/api/'\n */\n prefix?: `/${string}/` | '/';\n\n /**\n * The maximum size of the request body in bytes.\n *\n * @default `1_048_576` (1MiB)\n */\n bodyLimit?: number;\n}\n\nexport class NanotronApiServer {\n protected static readonly defaultConfig_: Readonly<Required<NanotronApiServerConfig>> = {\n host: '0.0.0.0',\n port: 80,\n requestTimeout: 10_000,\n headersTimeout: 130_000,\n keepAliveTimeout: 120_000,\n healthRoute: true,\n crossOrigin: {\n enable: false,\n origin: '*',\n methods: '*',\n headers: '*',\n maxAge: 86_400, // 24h\n },\n prefix: '/api/',\n bodyLimit: 1_048_576, // 1MiB\n };\n\n readonly config_: Required<NanotronApiServerConfig>;\n protected readonly logger_;\n\n readonly httpServer;\n\n protected readonly routeHandlerList__: Record<MatchType, DictionaryOpt<DictionaryOpt<Required<DefineRouteOption>>>>;\n\n constructor(config?: Partial<NanotronApiServerConfig>) {\n // Merge the config with the default config.\n this.config_ = {\n ...NanotronApiServer.defaultConfig_,\n ...config,\n };\n\n // Create logger.\n this.logger_ = createLogger('nt-api-server' + (this.config_.port !== 80 ? ':' + this.config_.port : ''));\n this.logger_.logMethodArgs?.('new', {config: this.config_});\n\n // Bind methods.\n this.handleClientRequest_ = this.handleClientRequest_.bind(this);\n this.handleServerError_ = this.handleServerError_.bind(this);\n this.handleClientError_ = this.handleClientError_.bind(this);\n\n // Initialize route handler list.\n this.routeHandlerList__ = {\n exact: {},\n startsWith: {},\n };\n\n // Create the HTTP server.\n this.httpServer = createServer(\n {\n keepAlive: true,\n keepAliveInitialDelay: 0,\n noDelay: true,\n },\n this.handleClientRequest_,\n );\n\n // Configure the server.\n this.httpServer.requestTimeout = this.config_.requestTimeout;\n this.httpServer.keepAliveTimeout = this.config_.keepAliveTimeout;\n this.httpServer.headersTimeout = this.config_.headersTimeout;\n\n // Start the server.\n this.httpServer.listen(this.config_.port, this.config_.host, () => {\n this.logger_.logOther?.(`listening on ${this.config_.host}:${this.config_.port}`);\n });\n\n // Handle server errors.\n this.httpServer.on('error', this.handleServerError_);\n this.httpServer.on('clientError', this.handleClientError_);\n\n this.defineCorsRoute_();\n\n if (this.config_.healthRoute) {\n this.defineHealthRoute_();\n }\n }\n\n close(): void {\n this.logger_.logMethod?.('close');\n this.httpServer.close();\n }\n\n protected getRouteOption_(url: NanotronUrl): Required<DefineRouteOption> | null {\n this.logger_.logMethod?.('getRouteOption_');\n\n if (\n Object.hasOwn(this.routeHandlerList__.exact, url.method) &&\n Object.hasOwn(this.routeHandlerList__.exact[url.method]!, url.pathname)\n ) {\n return this.routeHandlerList__.exact[url.method]![url.pathname]!;\n }\n\n if (Object.hasOwn(this.routeHandlerList__.startsWith, url.method)) {\n const routeList = this.routeHandlerList__.startsWith[url.method];\n for (const pathname in routeList) {\n if (url.pathname.indexOf(pathname) === 0) {\n return routeList[pathname]!;\n }\n }\n }\n\n this.logger_.incident?.('getRouteOption_', 'route_not_found', {method: url.method, url: url.pathname});\n return null;\n }\n\n protected setRouteOption_(option: Required<DefineRouteOption>): void {\n this.logger_.logMethodArgs?.('setRouteOption_', option);\n\n const routeHandlerList = this.routeHandlerList__[option.matchType];\n\n routeHandlerList[option.method] ??= {};\n\n if (Object.hasOwn(routeHandlerList[option.method]!, option.url)) {\n this.logger_.error('defineRoute', 'route_already_exists', option);\n throw new Error('route_already_exists');\n }\n\n routeHandlerList[option.method]![option.url] = option;\n }\n\n defineRoute<TSharedMeta extends DictionaryOpt = DictionaryOpt>(option: DefineRouteOption<TSharedMeta>): void {\n const option_: Required<DefineRouteOption<TSharedMeta>> = {\n matchType: 'exact',\n preHandlers: [],\n postHandlers: [],\n bodyLimit: this.config_.bodyLimit,\n crossOrigin: this.config_.crossOrigin,\n ...option,\n };\n this.logger_.logMethodArgs?.('defineRoute', option_);\n this.setRouteOption_(option_ as Required<DefineRouteOption>);\n }\n\n protected handleServerError_(error: NodeJS.ErrnoException): void {\n if (error.code === 'EADDRINUSE') {\n this.logger_.error('handleServerError_', 'address_in_use', error);\n }\n else {\n this.logger_.error('handleServerError_', 'http_server_error', error);\n }\n }\n\n protected handleClientError_(err: NodeJS.ErrnoException, socket: Duplex): void {\n this.logger_.accident('handleClientError_', 'http_server_client_error', {\n errCode: err.code,\n errMessage: err.message,\n });\n\n const errorCode = err.code?.toLowerCase() ?? `error_${HttpStatusCodes.Error_Client_400_Bad_Request}`;\n const errorMessage = err.message ?? HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request];\n const errorResponse = `{\"ok\":false,\"errorCode\":\"${errorCode}\",\"errorMessage\":\"${errorMessage}\"}`;\n\n const responseHeaders = [\n `HTTP/1.1 ${HttpStatusCodes.Error_Client_400_Bad_Request} ${HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request]}`,\n 'content-type: application/json',\n `content-length: ${Buffer.byteLength(errorResponse)}`,\n '\\r\\n',\n ].join('\\r\\n');\n\n socket.end(responseHeaders + errorResponse);\n }\n\n protected async handleClientRequest_(\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n ): Promise<void> {\n this.logger_.logMethod?.('handleClientRequest_');\n\n if (nativeClientRequest.url === undefined) {\n this.logger_.accident('handleClientRequest_', 'http_server_url_undefined');\n return;\n }\n\n const url = new NanotronUrl(nativeClientRequest, this.config_.prefix);\n\n const routeOption = this.getRouteOption_(url);\n\n const connection = new NanotronClientRequest(url, nativeClientRequest, nativeServerResponse, routeOption);\n\n if (routeOption === null) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Client_404_Not_Found;\n connection.serverResponse.replyError();\n return;\n }\n\n try {\n for (const handler of routeOption.preHandlers) {\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n if (connection.terminatedHandlers === true) return; // must check after each pre-handler.\n }\n\n await routeOption.handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n\n for (const handler of routeOption.postHandlers) {\n if (connection.terminatedHandlers === true) return; // must check before each post-handler.\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n }\n }\n catch (error) {\n this.logger_.error('handleClientRequest_', 'route_handler_error', error, url.debugId);\n\n if (connection.serverResponse.statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n }\n connection.serverResponse.replyError(error);\n }\n\n // TODO: handled open remained connections.\n }\n\n protected defineHealthRoute_(): void {\n this.logger_.logMethod?.('defineHealthRoute_');\n\n this.defineRoute({\n method: 'GET',\n url: '/health',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.statusCode = HttpStatusCodes.Success_200_OK;\n res.setHeader('server', 'Alwatr Nanotron');\n res.setHeader('content-type', 'application/json');\n res.end('{\"ok\":true}');\n },\n });\n }\n\n protected defineCorsRoute_(): void {\n this.logger_.logMethod?.('defineCorsRoute_');\n const crossOrigin = this.config_.crossOrigin;\n if (crossOrigin?.enable !== true) return;\n this.defineRoute({\n method: 'OPTIONS',\n matchType: 'startsWith',\n url: '/',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.writeHead(HttpStatusCodes.Success_204_No_Content, {\n 'access-control-allow-origin': crossOrigin.origin,\n 'access-control-allow-methods': crossOrigin.methods,\n 'access-control-allow-headers': crossOrigin.headers,\n 'access-control-max-age': crossOrigin.maxAge + '',\n 'content-length': 0,\n });\n res.end();\n },\n });\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {NanotronServerResponse} from './api-server-response.js';\nimport {HttpStatusCodes} from './const.js';\n\nimport type {DefineRouteOption, HttpRequestHeaders, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {NanotronUrl} from './url.js';\n\nexport class NanotronClientRequest<TSharedMeta extends DictionaryOpt = DictionaryOpt> {\n readonly url: NanotronUrl;\n\n readonly serverResponse: NanotronServerResponse;\n\n readonly routeOption: Required<DefineRouteOption> | null;\n\n /**\n * A flag to indicate if the running handlers queue has been terminated.\n * This can occur due to an error being thrown or by explicitly calling the `replyError` method.\n *\n * When `terminatedHandlers` is set to `true`, it signifies that the execution of the current\n * sequence of handlers (including pre, main, and post handlers) has been halted and no further\n * handlers in the queue will be executed.\n *\n * Usage:\n * - Check this flag to determine if the handlers queue has been interrupted.\n * - Set this flag to `true` to manually stop the execution of subsequent handlers.\n */\n terminatedHandlers?: true;\n\n readonly sharedMeta: TSharedMeta = {} as TSharedMeta;\n\n readonly raw_: NativeClientRequest;\n\n protected readonly logger_;\n\n readonly remoteAddress: string | null;\n\n get headers(): HttpRequestHeaders {\n return this.raw_.headers;\n }\n\n private queryParams__?: DictionaryOpt<string>;\n get queryParams(): DictionaryOpt<string> {\n if (this.queryParams__ === undefined) {\n this.queryParams__ = {};\n for (const [key, value] of this.url.searchParams.entries()) {\n this.queryParams__[key] = value;\n }\n }\n return this.queryParams__;\n }\n\n constructor(\n url: NanotronUrl,\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n routeOption: Required<DefineRouteOption> | null,\n ) {\n // Store public properties.\n this.raw_ = nativeClientRequest;\n this.url = url;\n this.routeOption = routeOption;\n\n // Get and store remote address.\n this.remoteAddress = this.getRemoteAddress__();\n\n // Create logger.\n this.logger_ = createLogger(`nt-client-request(${this.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', url.debugId);\n\n // Create server response.\n this.serverResponse = new NanotronServerResponse(this, nativeServerResponse);\n }\n\n getBodyRaw(): Promise<Buffer> {\n return new Promise((resolve, reject) => {\n // method must be POST or PUT or PATCH\n const method = this.url.method;\n if (!(method === 'POST' || method === 'PUT' || method === 'PATCH')) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_405_Method_Not_Allowed;\n return reject(new Error('body_not_allowed'));\n }\n\n const contentLength = +this.raw_.headers['content-length']!;\n\n if (Number.isNaN(contentLength) || contentLength === 0) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_411_Length_Required;\n return reject(new Error('body_length_required'));\n }\n\n if (contentLength > this.routeOption!.bodyLimit) {\n // TODO: routeOption when null?!\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const dataChunks: Uint8Array[] = [];\n let receivedLength = 0;\n\n const onData = (chunk: Uint8Array) => {\n receivedLength += chunk.length;\n dataChunks.push(chunk);\n\n if (receivedLength > this.routeOption!.bodyLimit) {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n dataChunks.length = 0; // free memory\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n };\n\n const onEnd = (err?: Error) => {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n\n if (err !== undefined) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_400_Bad_Request;\n return reject(err);\n }\n\n if (receivedLength !== contentLength) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const body = Buffer.concat(dataChunks);\n\n resolve(body);\n };\n\n this.raw_.on('data', onData);\n this.raw_.on('end', onEnd);\n this.raw_.on('error', onEnd);\n this.raw_.resume();\n });\n }\n\n private getRemoteAddress__(): string | null {\n return this.raw_.headers['x-forwarded-for']?.split(',').pop()?.trim() || this.raw_.socket.remoteAddress || null;\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {type HttpStatusCode, HttpStatusCodes, HttpStatusMessages} from './const.js';\n\nimport type {NanotronClientRequest} from './api-client-request.js';\nimport type {HttpResponseHeaders, ErrorResponse, NativeServerResponse} from './type.js';\n\n/**\n * Configuration options for the Nanotron Api Server Response.\n */\nexport interface NanotronServerResponseConfig {\n clientRequest: NanotronClientRequest;\n}\n\nexport class NanotronServerResponse {\n readonly clientRequest: NanotronClientRequest;\n\n readonly raw_: NativeServerResponse;\n\n readonly headers: HttpResponseHeaders;\n\n protected readonly logger_;\n\n protected hasBeenSent_ = false;\n get hasBeenSent(): boolean {\n return this.hasBeenSent_;\n }\n\n constructor(nanotronClientRequest: NanotronClientRequest, nativeServerResponse: NativeServerResponse) {\n // Store public properties.\n this.clientRequest = nanotronClientRequest;\n this.raw_ = nativeServerResponse;\n\n // Create logger.\n this.logger_ = createLogger(`nt-server-response(${this.clientRequest.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', this.clientRequest.url.debugId);\n\n // Set default reply headers.\n this.headers = {\n server: 'Alwatr Nanotron',\n 'content-type': 'text/plain charset=UTF-8',\n };\n\n const crossOrigin = this.clientRequest.routeOption?.crossOrigin;\n if (crossOrigin?.enable === true) {\n this.headers['access-control-allow-origin'] = crossOrigin.origin;\n this.headers['access-control-allow-methods'] = crossOrigin.methods;\n this.headers['access-control-allow-headers'] = crossOrigin.headers;\n this.headers['access-control-max-age'] = crossOrigin.maxAge;\n }\n }\n\n get statusCode(): HttpStatusCode {\n return this.raw_.statusCode as HttpStatusCode;\n }\n\n set statusCode(value: HttpStatusCode) {\n this.raw_.statusCode = value;\n }\n\n protected applyHeaders_() {\n this.logger_.logMethodArgs?.('applyHeaders_', this.headers);\n for (const key in this.headers) {\n this.raw_.setHeader(key, this.headers[key as Lowercase<string>]!);\n }\n }\n\n replyErrorResponse(errorResponse: ErrorResponse): void {\n this.logger_.logMethod?.('replyErrorResponse');\n this.clientRequest.terminatedHandlers = true;\n this.headers['content-type'] = 'application/json';\n let meta = '';\n if (errorResponse.meta !== undefined) {\n const metaType = typeof errorResponse.meta;\n if (\n metaType === 'string' ||\n metaType === 'number' ||\n metaType === 'boolean' ||\n errorResponse.meta === null) {\n meta = `,\"meta\":\"${errorResponse.meta}\"`;\n }\n else if (metaType === 'object') {\n meta = `,\"meta\":${JSON.stringify(errorResponse.meta)}`;\n }\n }\n const responseString = `{\"ok\":false,\"errorCode\":\"${errorResponse.errorCode}\",\"errorMessage\":\"${errorResponse.errorMessage}\"${meta}}`;\n this.reply(responseString);\n }\n\n replyError(error?: Error | string | Json | unknown): void {\n this.logger_.logMethodArgs?.('replyError', {error});\n\n this.clientRequest.terminatedHandlers = true;\n let statusCode = this.statusCode;\n\n if (statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n this.statusCode = statusCode = 500;\n }\n\n if (error instanceof Error) {\n this.replyErrorResponse({\n ok: false,\n errorCode: (error.name === 'Error' ? 'error_' + statusCode : (error.name + '').toLowerCase()) as Lowercase<string>,\n errorMessage: error.message,\n });\n }\n else if (typeof error === 'string') {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: error,\n });\n }\n else if (typeof error === 'object' && error !== null) {\n this.replyJson(error as Json);\n }\n else {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: HttpStatusMessages[statusCode],\n });\n }\n }\n\n replyJson(responseJson: Json): void {\n this.logger_.logMethodArgs?.('replyJson', {responseJson});\n\n let responseString: string;\n try {\n responseString = JSON.stringify(responseJson);\n }\n catch (error) {\n this.logger_.error('replyJson', 'reply_json_stringify_failed', error, this.clientRequest.url.debugId);\n this.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n this.replyErrorResponse({\n ok: false,\n errorCode: 'reply_json_stringify_failed',\n errorMessage: 'Failed to stringify response JSON.',\n });\n return;\n }\n\n this.headers['content-type'] = 'application/json';\n this.reply(responseString);\n }\n\n reply(context: string | Buffer): void {\n this.logger_.logMethodArgs?.('reply', this.clientRequest.url.debugId);\n\n if (this.raw_.writableFinished && this.hasBeenSent_ === false) {\n // The response has already been sent by direct access to the server api.\n this.logger_.accident('reply', 'server_response_writable_finished_directly');\n this.hasBeenSent_ = true;\n }\n\n if (this.hasBeenSent_) {\n this.logger_.accident('reply', 'reply_already_sent', {\n url: this.clientRequest.url.debugId,\n replySent: this.hasBeenSent_,\n writableFinished: this.raw_.writableFinished,\n });\n return;\n }\n\n this.hasBeenSent_ = true;\n\n try {\n if (typeof context === 'string') {\n context = Buffer.from(context);\n }\n\n this.headers['content-length'] = context.byteLength;\n\n this.applyHeaders_();\n this.raw_.end(context, 'binary');\n }\n catch (error) {\n this.logger_.error('reply', 'server_response_error', error, this.clientRequest.url.debugId);\n this.hasBeenSent_ = false;\n }\n }\n}\n", "/**\n * Object representing standard HTTP methods.\n */\nexport const HttpMethods = {\n /**\n * GET: Requests a representation of the specified resource.\n */\n GET: 'GET',\n\n /**\n * HEAD: Asks for a response identical to that of a GET request, but without the response body.\n */\n HEAD: 'HEAD',\n\n /**\n * POST: Submits data to be processed (e.g., from an HTML form) to the identified resource.\n */\n POST: 'POST',\n\n /**\n * PUT: Uploads a representation of the specified URI.\n */\n PUT: 'PUT',\n\n /**\n * DELETE: Deletes the specified resource.\n */\n DELETE: 'DELETE',\n\n /**\n * CONNECT: Establishes a tunnel to the server identified by the target resource.\n */\n CONNECT: 'CONNECT',\n\n /**\n * OPTIONS: Describes the communication options for the target resource.\n */\n OPTIONS: 'OPTIONS',\n\n /**\n * TRACE: Performs a message loop-back test along the path to the target resource.\n */\n TRACE: 'TRACE',\n\n /**\n * PATCH: Applies partial modifications to a resource.\n */\n PATCH: 'PATCH'\n} as const;\n\n/**\n * Object representing standard HTTP status codes.\n */\nexport const HttpStatusCodes = {\n /**\n * 100 Continue: The server has received the request headers and the client should proceed to send the request body.\n */\n Info_100_Continue: 100,\n\n /**\n * 101 Switching Protocols: The server understands and is willing to comply with the clients request to switch protocols.\n */\n Info_101_Switching_Protocols: 101,\n\n /**\n * 102 Processing: The server has received and is processing the request, but no response is available yet.\n */\n Info_102_Processing: 102,\n\n /**\n * 103 Early Hints: The server is sending some response headers before the final HTTP message.\n */\n Info_103_Early_Hints: 103,\n\n /**\n * 200 OK: The request has succeeded.\n */\n Success_200_OK: 200,\n\n /**\n * 201 Created: The request has been fulfilled and resulted in a new resource being created.\n */\n Success_201_Created: 201,\n\n /**\n * 202 Accepted: The request has been accepted for processing, but the processing has not been completed.\n */\n Success_202_Accepted: 202,\n\n /**\n * 203 Non-Authoritative Information: The server is a transforming proxy that received a 200 OK\n * from the origin server but is returning a modified version of the origins response.\n */\n Success_203_Non_Authoritative_Information: 203,\n\n /**\n * 204 No Content: The server successfully processed the request and is not returning any content.\n */\n Success_204_No_Content: 204,\n\n /**\n * 205 Reset Content: The server successfully processed the request,\n * asks that the client reset its document view, and is not returning any content.\n */\n Success_205_Reset_Content: 205,\n\n /**\n * 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.\n */\n Success_206_Partial_Content: 206,\n\n /**\n * 207 Multi-Status: The message body that follows is an XML message\n * and can contain a number of separate response codes, depending on how many sub-requests were made.\n */\n Success_207_Multi_Status: 207,\n\n /**\n * 208 Already Reported: The members of a DAV binding have already been enumerated\n * in a preceding part of the (multi-status) response, and are not being included again.\n */\n Success_208_Already_Reported: 208,\n\n /**\n * 226 IM Used: The server has fulfilled a request for the resource, and the response is a representation\n * of the result of one or more instance-manipulations applied to the current instance.\n */\n Success_226_IM_Used: 226,\n\n /**\n * 300 Multiple Choices: The request has more than one possible response.\n */\n Redirect_300_Multiple_Choices: 300,\n\n /**\n * 301 Moved Permanently: The URL of the requested resource has been changed permanently.\n */\n Redirect_301_Moved_Permanently: 301,\n\n /**\n * 302 Found: The URL of the requested resource has been changed temporarily.\n */\n Redirect_302_Found: 302,\n\n /**\n * 303 See Other: The response to the request can be found under another URI using a GET method.\n */\n Redirect_303_See_Other: 303,\n\n /**\n * 304 Not Modified: The resource has not been modified since the version specified\n * by the request headers If-Modified-Since or If-None-Match.\n */\n Redirect_304_Not_Modified: 304,\n\n /**\n * 305 Use Proxy: The requested resource is only available through a proxy, the address for which is provided in the response.\n */\n Redirect_305_Use_Proxy: 305,\n\n /**\n * 306 Switch Proxy: No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"\n */\n Redirect_306_Switch_Proxy: 306,\n\n /**\n * 307 Temporary Redirect: The server sends this response to direct the client\n * to get the requested resource at another URI with the same method that was used in the prior request.\n */\n Redirect_307_Temporary_Redirect: 307,\n\n /**\n * 308 Permanent Redirect: This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header.\n */\n Redirect_308_Permanent_Redirect: 308,\n\n /**\n * 400 Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error.\n */\n Error_Client_400_Bad_Request: 400,\n\n /**\n * 401 Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource.\n */\n Error_Client_401_Unauthorized: 401,\n\n /**\n * 402 Payment Required: Reserved for future use.\n */\n Error_Client_402_Payment_Required: 402,\n\n /**\n * 403 Forbidden: The client does not have access rights to the content, so the server is refusing to give the requested resource.\n */\n Error_Client_403_Forbidden: 403,\n\n /**\n * 404 Not Found: The server can not find the requested resource.\n */\n Error_Client_404_Not_Found: 404,\n\n /**\n * 405 Method Not Allowed: The request method is known by the server but is not supported by the target resource.\n */\n Error_Client_405_Method_Not_Allowed: 405,\n\n /**\n * 406 Not Acceptable: The target resource does not have a current representation that would be acceptable\n * to the user agent, according to the proactive negotiation header fields received in the request,\n * and the server is unwilling to supply a default representation.\n */\n Error_Client_406_Not_Acceptable: 406,\n\n /**\n * 407 Proxy Authentication Required: Similar to 401 Unauthorized,\n * but it indicates that the client needs to authenticate itself in order to use a proxy.\n */\n Error_Client_407_Proxy_Authentication_Required: 407,\n\n /**\n * 408 Request Timeout: The server timed out waiting for the request.\n */\n Error_Client_408_Request_Timeout: 408,\n\n /**\n * 409 Conflict: The request could not be processed because of conflict in the request, such as an edit conflict.\n */\n Error_Client_409_Conflict: 409,\n\n /**\n * 410 Gone: The requested resource is no longer available and will not be available again.\n */\n Error_Client_410_Gone: 410,\n\n /**\n * 411 Length Required: The server refuses to accept the request without a defined Content-Length header.\n */\n Error_Client_411_Length_Required: 411,\n\n /**\n * 412 Precondition Failed: One or more conditions given in the request header fields evaluated to false when tested on the server.\n */\n Error_Client_412_Precondition_Failed: 412,\n\n /**\n * 413 Payload Too Large: The server is refusing to process a request because the request payload is larger\n * than the server is willing or able to process.\n */\n Error_Client_413_Payload_Too_Large: 413,\n\n /**\n * 414 URI Too Long: The server is refusing to service the request because the URI is longer than the server is willing to interpret.\n */\n Error_Client_414_URI_Too_Long: 414,\n\n /**\n * 415 Unsupported Media Type: The server is refusing to service the request\n * because the entity of the request is in a format not supported by the requested resource for the requested method.\n */\n Error_Client_415_Unsupported_Media_Type: 415,\n\n /**\n * 416 Range Not Satisfiable: The client has asked for a portion of the file, but the server cannot supply that portion.\n */\n Error_Client_416_Range_Not_Satisfiable: 416,\n\n /**\n * 417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field.\n */\n Error_Client_417_Expectation_Failed: 417,\n\n /**\n * 421 Misdirected Request: The request was directed at a server that is not able to produce a response.\n */\n Error_Client_421_Misdirected_Request: 421,\n\n /**\n * 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.\n */\n Error_Client_422_Unprocessable_Entity: 422,\n\n /**\n * 423 Locked: The resource that is being accessed is locked.\n */\n Error_Client_423_Locked: 423,\n\n /**\n * 424 Failed Dependency: The request failed due to a failure of a previous request.\n */\n Error_Client_424_Failed_Dependency: 424,\n\n /**\n * 425 Too Early: The server is unwilling to risk processing a request that might be replayed.\n */\n Error_Client_425_Too_Early: 425,\n\n /**\n * 426 Upgrade Required: The server refuses to perform the request using the current protocol\n * but might be willing to do so after the client upgrades to a different protocol.\n */\n Error_Client_426_Upgrade_Required: 426,\n\n /**\n * 428 Precondition Required: The origin server requires the request to be conditional.\n */\n Error_Client_428_Precondition_Required: 428,\n\n /**\n * 429 Too Many Requests: The user has sent too many requests in a given amount of time (\"rate limiting\").\n */\n Error_Client_429_Too_Many_Requests: 429,\n\n /**\n * 431 Request Header Fields Too Large: The server is unwilling to process the request because its header fields are too large.\n */\n Error_Client_431_Request_Header_Fields_Too_Large: 431,\n\n /**\n * 451 Unavailable For Legal Reasons: The user requests an illegal resource, such as a web page censored by a government.\n */\n Error_Client_451_Unavailable_For_Legal_Reasons: 451,\n\n /**\n * 500 Internal Server Error: A generic error message, given when no more specific message is suitable.\n */\n Error_Server_500_Internal_Server_Error: 500,\n\n /**\n * 501 Not Implemented: The server either does not recognize the request method, or it lacks the ability to fulfill the request.\n */\n Error_Server_501_Not_Implemented: 501,\n\n /**\n * 502 Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server.\n */\n Error_Server_502_Bad_Gateway: 502,\n\n /**\n * 503 Service Unavailable: The server is currently unavailable (because it is overloaded or down for maintenance).\n */\n Error_Server_503_Service_Unavailable: 503,\n\n /**\n * 504 Gateway Timeout: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\n */\n Error_Server_504_Gateway_Timeout: 504,\n\n /**\n * 505 HTTP Version Not Supported: The server does not support the HTTP protocol version used in the request.\n */\n Error_Server_505_HTTP_Version_Not_Supported: 505,\n\n /**\n * 506 Variant Also Negotiates: Transparent content negotiation for the request results in a circular reference.\n */\n Error_Server_506_Variant_Also_Negotiates: 506,\n\n /**\n * 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.\n */\n Error_Server_507_Insufficient_Storage: 507,\n\n /**\n * 508 Loop Detected: The server detected an infinite loop while processing the request.\n */\n Error_Server_508_Loop_Detected: 508,\n\n /**\n * 510 Not Extended: Further extensions to the request are required for the server to fulfill it.\n */\n Error_Server_510_Not_Extended: 510,\n\n /**\n * 511 Network Authentication Required: The client needs to authenticate to gain network access.\n */\n Error_Server_511_Network_Authentication_Required: 511\n} as const;\n\nexport const HttpStatusMessages = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 208: 'Already Reported',\n 226: 'IM Used',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 305: 'Use Proxy',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: 'I\\'m a Teapot',\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 509: 'Bandwidth Limit Exceeded',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n};\n\nexport type HttpStatusCode = keyof typeof HttpStatusMessages;\n", "import {URL} from 'node:url';\n\nimport type {HttpMethod, NativeClientRequest} from './type.js';\n\nexport class NanotronUrl extends URL {\n protected static versionPattern_ = new RegExp('^/v[0-9]+/');\n\n readonly method: HttpMethod;\n readonly debugId: string;\n\n constructor(clientRequest: NativeClientRequest, prefix: `/${string}/` | '/') {\n let url = clientRequest.url ?? '';\n if (prefix !== '/' && url.indexOf(prefix) === 0) {\n url = url.slice(prefix.length - 1); // include `/`\n }\n url = url.replace(NanotronUrl.versionPattern_, '/');\n\n super(url, 'http://hostname/');\n\n this.method = (clientRequest.method ?? 'GET').toUpperCase() as HttpMethod;\n\n this.debugId = `[${this.method}]${this.pathname}`;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAA2B;AAE3B,IAAAA,kBAA0C;;;ACF1C,IAAAC,kBAA2B;;;ACA3B,qBAA2B;;;ACGpB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA,EAIzB,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,QAAQ;AAAA;AAAA;AAAA;AAAA,EAKR,SAAS;AAAA;AAAA;AAAA;AAAA,EAKT,SAAS;AAAA;AAAA;AAAA;AAAA,EAKT,OAAO;AAAA;AAAA;AAAA;AAAA,EAKP,OAAO;AACT;AAKO,IAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAI7B,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAKnB,8BAA8B;AAAA;AAAA;AAAA;AAAA,EAK9B,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB,sBAAsB;AAAA;AAAA;AAAA;AAAA,EAKtB,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAKhB,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtB,2CAA2C;AAAA;AAAA;AAAA;AAAA,EAK3C,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxB,2BAA2B;AAAA;AAAA;AAAA;AAAA,EAK3B,6BAA6B;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7B,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1B,8BAA8B;AAAA;AAAA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AA,IACT,QAAQ;AAAA;AAAA,EACV;AAAA,EACA,QAAQ;AAAA,EACR,WAAW;AAAA;AACb;AAjBK,IAAM,oBAAN;",
|
|
6
6
|
"names": ["import_nanolib", "import_nanolib"]
|
|
7
7
|
}
|
package/dist/main.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @alwatr/nanotron-api-server v4.9.
|
|
1
|
+
/* @alwatr/nanotron-api-server v4.9.4 */
|
|
2
2
|
|
|
3
3
|
// src/api-server.ts
|
|
4
4
|
import { createServer } from "node:http";
|
|
@@ -610,7 +610,7 @@ _NanotronUrl.versionPattern_ = new RegExp("^/v[0-9]+/");
|
|
|
610
610
|
var NanotronUrl = _NanotronUrl;
|
|
611
611
|
|
|
612
612
|
// src/api-server.ts
|
|
613
|
-
__dev_mode__: packageTracer.add("@alwatr/nanotron-api-server", "4.9.
|
|
613
|
+
__dev_mode__: packageTracer.add("@alwatr/nanotron-api-server", "4.9.4");
|
|
614
614
|
var _NanotronApiServer = class _NanotronApiServer {
|
|
615
615
|
constructor(config) {
|
|
616
616
|
this.config_ = {
|
|
@@ -659,7 +659,7 @@ var _NanotronApiServer = class _NanotronApiServer {
|
|
|
659
659
|
if (Object.hasOwn(this.routeHandlerList__.startsWith, url.method)) {
|
|
660
660
|
const routeList = this.routeHandlerList__.startsWith[url.method];
|
|
661
661
|
for (const pathname in routeList) {
|
|
662
|
-
if (pathname.indexOf(
|
|
662
|
+
if (url.pathname.indexOf(pathname) === 0) {
|
|
663
663
|
return routeList[pathname];
|
|
664
664
|
}
|
|
665
665
|
}
|
package/dist/main.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/api-server.ts", "../src/api-client-request.ts", "../src/api-server-response.ts", "../src/const.ts", "../src/url.ts"],
|
|
4
|
-
"sourcesContent": ["import {createServer} from 'node:http';\n\nimport {createLogger, packageTracer} from '@alwatr/nanolib';\n\nimport {NanotronClientRequest} from './api-client-request.js';\nimport {HttpStatusCodes, HttpStatusMessages} from './const.js';\nimport {NanotronUrl} from './url.js';\n\nimport type {DefineRouteOption, MatchType, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {Duplex} from 'node:stream';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Configuration options for the NanotronApiServer.\n */\nexport interface NanotronApiServerConfig {\n /**\n * The port number to listen on.\n *\n * @default 80\n */\n port?: number;\n\n /**\n * The hostname to listen on.\n *\n * @default '0.0.0.0'\n */\n host?: string;\n\n /**\n * Sets the timeout (ms) for receiving the entire request from the client.\n *\n * @default 10_000 ms\n */\n requestTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * This should be bigger than `keepAliveTimeout + your server's expected response time`.\n *\n * @default 130_000 ms\n */\n headersTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * @default 120_000 ms\n */\n keepAliveTimeout?: number;\n\n /**\n * Add /health route.\n *\n * @default true\n */\n healthRoute?: boolean;\n\n /**\n * Add OPTIONS route for preflight requests to allow access origins.\n *\n * @default {enable: false, origin: '*', methods: '*', headers: '*', maxAge: 86_400}\n */\n crossOrigin?: {\n enable: boolean;\n origin: string;\n methods: string;\n headers: string;\n maxAge: string | number;\n },\n\n /**\n * A prefix to be added to the beginning of the `url` of all defined routes.\n *\n * @default '/api/'\n */\n prefix?: `/${string}/` | '/';\n\n /**\n * The maximum size of the request body in bytes.\n *\n * @default `1_048_576` (1MiB)\n */\n bodyLimit?: number;\n}\n\nexport class NanotronApiServer {\n protected static readonly defaultConfig_: Readonly<Required<NanotronApiServerConfig>> = {\n host: '0.0.0.0',\n port: 80,\n requestTimeout: 10_000,\n headersTimeout: 130_000,\n keepAliveTimeout: 120_000,\n healthRoute: true,\n crossOrigin: {\n enable: false,\n origin: '*',\n methods: '*',\n headers: '*',\n maxAge: 86_400, // 24h\n },\n prefix: '/api/',\n bodyLimit: 1_048_576, // 1MiB\n };\n\n readonly config_: Required<NanotronApiServerConfig>;\n protected readonly logger_;\n\n readonly httpServer;\n\n protected readonly routeHandlerList__: Record<MatchType, DictionaryOpt<DictionaryOpt<Required<DefineRouteOption>>>>;\n\n constructor(config?: Partial<NanotronApiServerConfig>) {\n // Merge the config with the default config.\n this.config_ = {\n ...NanotronApiServer.defaultConfig_,\n ...config,\n };\n\n // Create logger.\n this.logger_ = createLogger('nt-api-server' + (this.config_.port !== 80 ? ':' + this.config_.port : ''));\n this.logger_.logMethodArgs?.('new', {config: this.config_});\n\n // Bind methods.\n this.handleClientRequest_ = this.handleClientRequest_.bind(this);\n this.handleServerError_ = this.handleServerError_.bind(this);\n this.handleClientError_ = this.handleClientError_.bind(this);\n\n // Initialize route handler list.\n this.routeHandlerList__ = {\n exact: {},\n startsWith: {},\n };\n\n // Create the HTTP server.\n this.httpServer = createServer(\n {\n keepAlive: true,\n keepAliveInitialDelay: 0,\n noDelay: true,\n },\n this.handleClientRequest_,\n );\n\n // Configure the server.\n this.httpServer.requestTimeout = this.config_.requestTimeout;\n this.httpServer.keepAliveTimeout = this.config_.keepAliveTimeout;\n this.httpServer.headersTimeout = this.config_.headersTimeout;\n\n // Start the server.\n this.httpServer.listen(this.config_.port, this.config_.host, () => {\n this.logger_.logOther?.(`listening on ${this.config_.host}:${this.config_.port}`);\n });\n\n // Handle server errors.\n this.httpServer.on('error', this.handleServerError_);\n this.httpServer.on('clientError', this.handleClientError_);\n\n this.defineCorsRoute_();\n\n if (this.config_.healthRoute) {\n this.defineHealthRoute_();\n }\n }\n\n close(): void {\n this.logger_.logMethod?.('close');\n this.httpServer.close();\n }\n\n protected getRouteOption_(url: NanotronUrl): Required<DefineRouteOption> | null {\n this.logger_.logMethod?.('getRouteOption_');\n\n if (\n Object.hasOwn(this.routeHandlerList__.exact, url.method) &&\n Object.hasOwn(this.routeHandlerList__.exact[url.method]!, url.pathname)\n ) {\n return this.routeHandlerList__.exact[url.method]![url.pathname]!;\n }\n\n if (Object.hasOwn(this.routeHandlerList__.startsWith, url.method)) {\n const routeList = this.routeHandlerList__.startsWith[url.method];\n for (const pathname in routeList) {\n if (pathname.indexOf(url.pathname) === 0) {\n return routeList[pathname]!;\n }\n }\n }\n\n this.logger_.incident?.('getRouteOption_', 'route_not_found', {method: url.method, url: url.pathname});\n return null;\n }\n\n protected setRouteOption_(option: Required<DefineRouteOption>): void {\n this.logger_.logMethodArgs?.('setRouteOption_', option);\n\n const routeHandlerList = this.routeHandlerList__[option.matchType];\n\n routeHandlerList[option.method] ??= {};\n\n if (Object.hasOwn(routeHandlerList[option.method]!, option.url)) {\n this.logger_.error('defineRoute', 'route_already_exists', option);\n throw new Error('route_already_exists');\n }\n\n routeHandlerList[option.method]![option.url] = option;\n }\n\n defineRoute<TSharedMeta extends DictionaryOpt = DictionaryOpt>(option: DefineRouteOption<TSharedMeta>): void {\n const option_: Required<DefineRouteOption<TSharedMeta>> = {\n matchType: 'exact',\n preHandlers: [],\n postHandlers: [],\n bodyLimit: this.config_.bodyLimit,\n crossOrigin: this.config_.crossOrigin,\n ...option,\n };\n this.logger_.logMethodArgs?.('defineRoute', option_);\n this.setRouteOption_(option_ as Required<DefineRouteOption>);\n }\n\n protected handleServerError_(error: NodeJS.ErrnoException): void {\n if (error.code === 'EADDRINUSE') {\n this.logger_.error('handleServerError_', 'address_in_use', error);\n }\n else {\n this.logger_.error('handleServerError_', 'http_server_error', error);\n }\n }\n\n protected handleClientError_(err: NodeJS.ErrnoException, socket: Duplex): void {\n this.logger_.accident('handleClientError_', 'http_server_client_error', {\n errCode: err.code,\n errMessage: err.message,\n });\n\n const errorCode = err.code?.toLowerCase() ?? `error_${HttpStatusCodes.Error_Client_400_Bad_Request}`;\n const errorMessage = err.message ?? HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request];\n const errorResponse = `{\"ok\":false,\"errorCode\":\"${errorCode}\",\"errorMessage\":\"${errorMessage}\"}`;\n\n const responseHeaders = [\n `HTTP/1.1 ${HttpStatusCodes.Error_Client_400_Bad_Request} ${HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request]}`,\n 'content-type: application/json',\n `content-length: ${Buffer.byteLength(errorResponse)}`,\n '\\r\\n',\n ].join('\\r\\n');\n\n socket.end(responseHeaders + errorResponse);\n }\n\n protected async handleClientRequest_(\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n ): Promise<void> {\n this.logger_.logMethod?.('handleClientRequest_');\n\n if (nativeClientRequest.url === undefined) {\n this.logger_.accident('handleClientRequest_', 'http_server_url_undefined');\n return;\n }\n\n const url = new NanotronUrl(nativeClientRequest, this.config_.prefix);\n\n const routeOption = this.getRouteOption_(url);\n\n const connection = new NanotronClientRequest(url, nativeClientRequest, nativeServerResponse, routeOption);\n\n if (routeOption === null) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Client_404_Not_Found;\n connection.serverResponse.replyError();\n return;\n }\n\n try {\n for (const handler of routeOption.preHandlers) {\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n if (connection.terminatedHandlers === true) return; // must check after each pre-handler.\n }\n\n await routeOption.handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n\n for (const handler of routeOption.postHandlers) {\n if (connection.terminatedHandlers === true) return; // must check before each post-handler.\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n }\n }\n catch (error) {\n this.logger_.error('handleClientRequest_', 'route_handler_error', error, url.debugId);\n\n if (connection.serverResponse.statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n }\n connection.serverResponse.replyError(error);\n }\n\n // TODO: handled open remained connections.\n }\n\n protected defineHealthRoute_(): void {\n this.logger_.logMethod?.('defineHealthRoute_');\n\n this.defineRoute({\n method: 'GET',\n url: '/health',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.statusCode = HttpStatusCodes.Success_200_OK;\n res.setHeader('server', 'Alwatr Nanotron');\n res.setHeader('content-type', 'application/json');\n res.end('{\"ok\":true}');\n },\n });\n }\n\n protected defineCorsRoute_(): void {\n this.logger_.logMethod?.('defineCorsRoute_');\n const crossOrigin = this.config_.crossOrigin;\n if (crossOrigin?.enable !== true) return;\n this.defineRoute({\n method: 'OPTIONS',\n matchType: 'startsWith',\n url: '/',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.writeHead(HttpStatusCodes.Success_204_No_Content, {\n 'access-control-allow-origin': crossOrigin.origin,\n 'access-control-allow-methods': crossOrigin.methods,\n 'access-control-allow-headers': crossOrigin.headers,\n 'access-control-max-age': crossOrigin.maxAge + '',\n 'content-length': 0,\n });\n res.end();\n },\n });\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {NanotronServerResponse} from './api-server-response.js';\nimport {HttpStatusCodes} from './const.js';\n\nimport type {DefineRouteOption, HttpRequestHeaders, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {NanotronUrl} from './url.js';\n\nexport class NanotronClientRequest<TSharedMeta extends DictionaryOpt = DictionaryOpt> {\n readonly url: NanotronUrl;\n\n readonly serverResponse: NanotronServerResponse;\n\n readonly routeOption: Required<DefineRouteOption> | null;\n\n /**\n * A flag to indicate if the running handlers queue has been terminated.\n * This can occur due to an error being thrown or by explicitly calling the `replyError` method.\n *\n * When `terminatedHandlers` is set to `true`, it signifies that the execution of the current\n * sequence of handlers (including pre, main, and post handlers) has been halted and no further\n * handlers in the queue will be executed.\n *\n * Usage:\n * - Check this flag to determine if the handlers queue has been interrupted.\n * - Set this flag to `true` to manually stop the execution of subsequent handlers.\n */\n terminatedHandlers?: true;\n\n readonly sharedMeta: TSharedMeta = {} as TSharedMeta;\n\n readonly raw_: NativeClientRequest;\n\n protected readonly logger_;\n\n readonly remoteAddress: string | null;\n\n get headers(): HttpRequestHeaders {\n return this.raw_.headers;\n }\n\n private queryParams__?: DictionaryOpt<string>;\n get queryParams(): DictionaryOpt<string> {\n if (this.queryParams__ === undefined) {\n this.queryParams__ = {};\n for (const [key, value] of this.url.searchParams.entries()) {\n this.queryParams__[key] = value;\n }\n }\n return this.queryParams__;\n }\n\n constructor(\n url: NanotronUrl,\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n routeOption: Required<DefineRouteOption> | null,\n ) {\n // Store public properties.\n this.raw_ = nativeClientRequest;\n this.url = url;\n this.routeOption = routeOption;\n\n // Get and store remote address.\n this.remoteAddress = this.getRemoteAddress__();\n\n // Create logger.\n this.logger_ = createLogger(`nt-client-request(${this.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', url.debugId);\n\n // Create server response.\n this.serverResponse = new NanotronServerResponse(this, nativeServerResponse);\n }\n\n getBodyRaw(): Promise<Buffer> {\n return new Promise((resolve, reject) => {\n // method must be POST or PUT or PATCH\n const method = this.url.method;\n if (!(method === 'POST' || method === 'PUT' || method === 'PATCH')) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_405_Method_Not_Allowed;\n return reject(new Error('body_not_allowed'));\n }\n\n const contentLength = +this.raw_.headers['content-length']!;\n\n if (Number.isNaN(contentLength) || contentLength === 0) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_411_Length_Required;\n return reject(new Error('body_length_required'));\n }\n\n if (contentLength > this.routeOption!.bodyLimit) {\n // TODO: routeOption when null?!\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const dataChunks: Uint8Array[] = [];\n let receivedLength = 0;\n\n const onData = (chunk: Uint8Array) => {\n receivedLength += chunk.length;\n dataChunks.push(chunk);\n\n if (receivedLength > this.routeOption!.bodyLimit) {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n dataChunks.length = 0; // free memory\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n };\n\n const onEnd = (err?: Error) => {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n\n if (err !== undefined) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_400_Bad_Request;\n return reject(err);\n }\n\n if (receivedLength !== contentLength) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const body = Buffer.concat(dataChunks);\n\n resolve(body);\n };\n\n this.raw_.on('data', onData);\n this.raw_.on('end', onEnd);\n this.raw_.on('error', onEnd);\n this.raw_.resume();\n });\n }\n\n private getRemoteAddress__(): string | null {\n return this.raw_.headers['x-forwarded-for']?.split(',').pop()?.trim() || this.raw_.socket.remoteAddress || null;\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {type HttpStatusCode, HttpStatusCodes, HttpStatusMessages} from './const.js';\n\nimport type {NanotronClientRequest} from './api-client-request.js';\nimport type {HttpResponseHeaders, ErrorResponse, NativeServerResponse} from './type.js';\n\n/**\n * Configuration options for the Nanotron Api Server Response.\n */\nexport interface NanotronServerResponseConfig {\n clientRequest: NanotronClientRequest;\n}\n\nexport class NanotronServerResponse {\n readonly clientRequest: NanotronClientRequest;\n\n readonly raw_: NativeServerResponse;\n\n readonly headers: HttpResponseHeaders;\n\n protected readonly logger_;\n\n protected hasBeenSent_ = false;\n get hasBeenSent(): boolean {\n return this.hasBeenSent_;\n }\n\n constructor(nanotronClientRequest: NanotronClientRequest, nativeServerResponse: NativeServerResponse) {\n // Store public properties.\n this.clientRequest = nanotronClientRequest;\n this.raw_ = nativeServerResponse;\n\n // Create logger.\n this.logger_ = createLogger(`nt-server-response(${this.clientRequest.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', this.clientRequest.url.debugId);\n\n // Set default reply headers.\n this.headers = {\n server: 'Alwatr Nanotron',\n 'content-type': 'text/plain charset=UTF-8',\n };\n\n const crossOrigin = this.clientRequest.routeOption?.crossOrigin;\n if (crossOrigin?.enable === true) {\n this.headers['access-control-allow-origin'] = crossOrigin.origin;\n this.headers['access-control-allow-methods'] = crossOrigin.methods;\n this.headers['access-control-allow-headers'] = crossOrigin.headers;\n this.headers['access-control-max-age'] = crossOrigin.maxAge;\n }\n }\n\n get statusCode(): HttpStatusCode {\n return this.raw_.statusCode as HttpStatusCode;\n }\n\n set statusCode(value: HttpStatusCode) {\n this.raw_.statusCode = value;\n }\n\n protected applyHeaders_() {\n this.logger_.logMethodArgs?.('applyHeaders_', this.headers);\n for (const key in this.headers) {\n this.raw_.setHeader(key, this.headers[key as Lowercase<string>]!);\n }\n }\n\n replyErrorResponse(errorResponse: ErrorResponse): void {\n this.logger_.logMethod?.('replyErrorResponse');\n this.clientRequest.terminatedHandlers = true;\n this.headers['content-type'] = 'application/json';\n let meta = '';\n if (errorResponse.meta !== undefined) {\n const metaType = typeof errorResponse.meta;\n if (\n metaType === 'string' ||\n metaType === 'number' ||\n metaType === 'boolean' ||\n errorResponse.meta === null) {\n meta = `,\"meta\":\"${errorResponse.meta}\"`;\n }\n else if (metaType === 'object') {\n meta = `,\"meta\":${JSON.stringify(errorResponse.meta)}`;\n }\n }\n const responseString = `{\"ok\":false,\"errorCode\":\"${errorResponse.errorCode}\",\"errorMessage\":\"${errorResponse.errorMessage}\"${meta}}`;\n this.reply(responseString);\n }\n\n replyError(error?: Error | string | Json | unknown): void {\n this.logger_.logMethodArgs?.('replyError', {error});\n\n this.clientRequest.terminatedHandlers = true;\n let statusCode = this.statusCode;\n\n if (statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n this.statusCode = statusCode = 500;\n }\n\n if (error instanceof Error) {\n this.replyErrorResponse({\n ok: false,\n errorCode: (error.name === 'Error' ? 'error_' + statusCode : (error.name + '').toLowerCase()) as Lowercase<string>,\n errorMessage: error.message,\n });\n }\n else if (typeof error === 'string') {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: error,\n });\n }\n else if (typeof error === 'object' && error !== null) {\n this.replyJson(error as Json);\n }\n else {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: HttpStatusMessages[statusCode],\n });\n }\n }\n\n replyJson(responseJson: Json): void {\n this.logger_.logMethodArgs?.('replyJson', {responseJson});\n\n let responseString: string;\n try {\n responseString = JSON.stringify(responseJson);\n }\n catch (error) {\n this.logger_.error('replyJson', 'reply_json_stringify_failed', error, this.clientRequest.url.debugId);\n this.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n this.replyErrorResponse({\n ok: false,\n errorCode: 'reply_json_stringify_failed',\n errorMessage: 'Failed to stringify response JSON.',\n });\n return;\n }\n\n this.headers['content-type'] = 'application/json';\n this.reply(responseString);\n }\n\n reply(context: string | Buffer): void {\n this.logger_.logMethodArgs?.('reply', this.clientRequest.url.debugId);\n\n if (this.raw_.writableFinished && this.hasBeenSent_ === false) {\n // The response has already been sent by direct access to the server api.\n this.logger_.accident('reply', 'server_response_writable_finished_directly');\n this.hasBeenSent_ = true;\n }\n\n if (this.hasBeenSent_) {\n this.logger_.accident('reply', 'reply_already_sent', {\n url: this.clientRequest.url.debugId,\n replySent: this.hasBeenSent_,\n writableFinished: this.raw_.writableFinished,\n });\n return;\n }\n\n this.hasBeenSent_ = true;\n\n try {\n if (typeof context === 'string') {\n context = Buffer.from(context);\n }\n\n this.headers['content-length'] = context.byteLength;\n\n this.applyHeaders_();\n this.raw_.end(context, 'binary');\n }\n catch (error) {\n this.logger_.error('reply', 'server_response_error', error, this.clientRequest.url.debugId);\n this.hasBeenSent_ = false;\n }\n }\n}\n", "/**\n * Object representing standard HTTP methods.\n */\nexport const HttpMethods = {\n /**\n * GET: Requests a representation of the specified resource.\n */\n GET: 'GET',\n\n /**\n * HEAD: Asks for a response identical to that of a GET request, but without the response body.\n */\n HEAD: 'HEAD',\n\n /**\n * POST: Submits data to be processed (e.g., from an HTML form) to the identified resource.\n */\n POST: 'POST',\n\n /**\n * PUT: Uploads a representation of the specified URI.\n */\n PUT: 'PUT',\n\n /**\n * DELETE: Deletes the specified resource.\n */\n DELETE: 'DELETE',\n\n /**\n * CONNECT: Establishes a tunnel to the server identified by the target resource.\n */\n CONNECT: 'CONNECT',\n\n /**\n * OPTIONS: Describes the communication options for the target resource.\n */\n OPTIONS: 'OPTIONS',\n\n /**\n * TRACE: Performs a message loop-back test along the path to the target resource.\n */\n TRACE: 'TRACE',\n\n /**\n * PATCH: Applies partial modifications to a resource.\n */\n PATCH: 'PATCH'\n} as const;\n\n/**\n * Object representing standard HTTP status codes.\n */\nexport const HttpStatusCodes = {\n /**\n * 100 Continue: The server has received the request headers and the client should proceed to send the request body.\n */\n Info_100_Continue: 100,\n\n /**\n * 101 Switching Protocols: The server understands and is willing to comply with the clients request to switch protocols.\n */\n Info_101_Switching_Protocols: 101,\n\n /**\n * 102 Processing: The server has received and is processing the request, but no response is available yet.\n */\n Info_102_Processing: 102,\n\n /**\n * 103 Early Hints: The server is sending some response headers before the final HTTP message.\n */\n Info_103_Early_Hints: 103,\n\n /**\n * 200 OK: The request has succeeded.\n */\n Success_200_OK: 200,\n\n /**\n * 201 Created: The request has been fulfilled and resulted in a new resource being created.\n */\n Success_201_Created: 201,\n\n /**\n * 202 Accepted: The request has been accepted for processing, but the processing has not been completed.\n */\n Success_202_Accepted: 202,\n\n /**\n * 203 Non-Authoritative Information: The server is a transforming proxy that received a 200 OK\n * from the origin server but is returning a modified version of the origins response.\n */\n Success_203_Non_Authoritative_Information: 203,\n\n /**\n * 204 No Content: The server successfully processed the request and is not returning any content.\n */\n Success_204_No_Content: 204,\n\n /**\n * 205 Reset Content: The server successfully processed the request,\n * asks that the client reset its document view, and is not returning any content.\n */\n Success_205_Reset_Content: 205,\n\n /**\n * 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.\n */\n Success_206_Partial_Content: 206,\n\n /**\n * 207 Multi-Status: The message body that follows is an XML message\n * and can contain a number of separate response codes, depending on how many sub-requests were made.\n */\n Success_207_Multi_Status: 207,\n\n /**\n * 208 Already Reported: The members of a DAV binding have already been enumerated\n * in a preceding part of the (multi-status) response, and are not being included again.\n */\n Success_208_Already_Reported: 208,\n\n /**\n * 226 IM Used: The server has fulfilled a request for the resource, and the response is a representation\n * of the result of one or more instance-manipulations applied to the current instance.\n */\n Success_226_IM_Used: 226,\n\n /**\n * 300 Multiple Choices: The request has more than one possible response.\n */\n Redirect_300_Multiple_Choices: 300,\n\n /**\n * 301 Moved Permanently: The URL of the requested resource has been changed permanently.\n */\n Redirect_301_Moved_Permanently: 301,\n\n /**\n * 302 Found: The URL of the requested resource has been changed temporarily.\n */\n Redirect_302_Found: 302,\n\n /**\n * 303 See Other: The response to the request can be found under another URI using a GET method.\n */\n Redirect_303_See_Other: 303,\n\n /**\n * 304 Not Modified: The resource has not been modified since the version specified\n * by the request headers If-Modified-Since or If-None-Match.\n */\n Redirect_304_Not_Modified: 304,\n\n /**\n * 305 Use Proxy: The requested resource is only available through a proxy, the address for which is provided in the response.\n */\n Redirect_305_Use_Proxy: 305,\n\n /**\n * 306 Switch Proxy: No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"\n */\n Redirect_306_Switch_Proxy: 306,\n\n /**\n * 307 Temporary Redirect: The server sends this response to direct the client\n * to get the requested resource at another URI with the same method that was used in the prior request.\n */\n Redirect_307_Temporary_Redirect: 307,\n\n /**\n * 308 Permanent Redirect: This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header.\n */\n Redirect_308_Permanent_Redirect: 308,\n\n /**\n * 400 Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error.\n */\n Error_Client_400_Bad_Request: 400,\n\n /**\n * 401 Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource.\n */\n Error_Client_401_Unauthorized: 401,\n\n /**\n * 402 Payment Required: Reserved for future use.\n */\n Error_Client_402_Payment_Required: 402,\n\n /**\n * 403 Forbidden: The client does not have access rights to the content, so the server is refusing to give the requested resource.\n */\n Error_Client_403_Forbidden: 403,\n\n /**\n * 404 Not Found: The server can not find the requested resource.\n */\n Error_Client_404_Not_Found: 404,\n\n /**\n * 405 Method Not Allowed: The request method is known by the server but is not supported by the target resource.\n */\n Error_Client_405_Method_Not_Allowed: 405,\n\n /**\n * 406 Not Acceptable: The target resource does not have a current representation that would be acceptable\n * to the user agent, according to the proactive negotiation header fields received in the request,\n * and the server is unwilling to supply a default representation.\n */\n Error_Client_406_Not_Acceptable: 406,\n\n /**\n * 407 Proxy Authentication Required: Similar to 401 Unauthorized,\n * but it indicates that the client needs to authenticate itself in order to use a proxy.\n */\n Error_Client_407_Proxy_Authentication_Required: 407,\n\n /**\n * 408 Request Timeout: The server timed out waiting for the request.\n */\n Error_Client_408_Request_Timeout: 408,\n\n /**\n * 409 Conflict: The request could not be processed because of conflict in the request, such as an edit conflict.\n */\n Error_Client_409_Conflict: 409,\n\n /**\n * 410 Gone: The requested resource is no longer available and will not be available again.\n */\n Error_Client_410_Gone: 410,\n\n /**\n * 411 Length Required: The server refuses to accept the request without a defined Content-Length header.\n */\n Error_Client_411_Length_Required: 411,\n\n /**\n * 412 Precondition Failed: One or more conditions given in the request header fields evaluated to false when tested on the server.\n */\n Error_Client_412_Precondition_Failed: 412,\n\n /**\n * 413 Payload Too Large: The server is refusing to process a request because the request payload is larger\n * than the server is willing or able to process.\n */\n Error_Client_413_Payload_Too_Large: 413,\n\n /**\n * 414 URI Too Long: The server is refusing to service the request because the URI is longer than the server is willing to interpret.\n */\n Error_Client_414_URI_Too_Long: 414,\n\n /**\n * 415 Unsupported Media Type: The server is refusing to service the request\n * because the entity of the request is in a format not supported by the requested resource for the requested method.\n */\n Error_Client_415_Unsupported_Media_Type: 415,\n\n /**\n * 416 Range Not Satisfiable: The client has asked for a portion of the file, but the server cannot supply that portion.\n */\n Error_Client_416_Range_Not_Satisfiable: 416,\n\n /**\n * 417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field.\n */\n Error_Client_417_Expectation_Failed: 417,\n\n /**\n * 421 Misdirected Request: The request was directed at a server that is not able to produce a response.\n */\n Error_Client_421_Misdirected_Request: 421,\n\n /**\n * 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.\n */\n Error_Client_422_Unprocessable_Entity: 422,\n\n /**\n * 423 Locked: The resource that is being accessed is locked.\n */\n Error_Client_423_Locked: 423,\n\n /**\n * 424 Failed Dependency: The request failed due to a failure of a previous request.\n */\n Error_Client_424_Failed_Dependency: 424,\n\n /**\n * 425 Too Early: The server is unwilling to risk processing a request that might be replayed.\n */\n Error_Client_425_Too_Early: 425,\n\n /**\n * 426 Upgrade Required: The server refuses to perform the request using the current protocol\n * but might be willing to do so after the client upgrades to a different protocol.\n */\n Error_Client_426_Upgrade_Required: 426,\n\n /**\n * 428 Precondition Required: The origin server requires the request to be conditional.\n */\n Error_Client_428_Precondition_Required: 428,\n\n /**\n * 429 Too Many Requests: The user has sent too many requests in a given amount of time (\"rate limiting\").\n */\n Error_Client_429_Too_Many_Requests: 429,\n\n /**\n * 431 Request Header Fields Too Large: The server is unwilling to process the request because its header fields are too large.\n */\n Error_Client_431_Request_Header_Fields_Too_Large: 431,\n\n /**\n * 451 Unavailable For Legal Reasons: The user requests an illegal resource, such as a web page censored by a government.\n */\n Error_Client_451_Unavailable_For_Legal_Reasons: 451,\n\n /**\n * 500 Internal Server Error: A generic error message, given when no more specific message is suitable.\n */\n Error_Server_500_Internal_Server_Error: 500,\n\n /**\n * 501 Not Implemented: The server either does not recognize the request method, or it lacks the ability to fulfill the request.\n */\n Error_Server_501_Not_Implemented: 501,\n\n /**\n * 502 Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server.\n */\n Error_Server_502_Bad_Gateway: 502,\n\n /**\n * 503 Service Unavailable: The server is currently unavailable (because it is overloaded or down for maintenance).\n */\n Error_Server_503_Service_Unavailable: 503,\n\n /**\n * 504 Gateway Timeout: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\n */\n Error_Server_504_Gateway_Timeout: 504,\n\n /**\n * 505 HTTP Version Not Supported: The server does not support the HTTP protocol version used in the request.\n */\n Error_Server_505_HTTP_Version_Not_Supported: 505,\n\n /**\n * 506 Variant Also Negotiates: Transparent content negotiation for the request results in a circular reference.\n */\n Error_Server_506_Variant_Also_Negotiates: 506,\n\n /**\n * 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.\n */\n Error_Server_507_Insufficient_Storage: 507,\n\n /**\n * 508 Loop Detected: The server detected an infinite loop while processing the request.\n */\n Error_Server_508_Loop_Detected: 508,\n\n /**\n * 510 Not Extended: Further extensions to the request are required for the server to fulfill it.\n */\n Error_Server_510_Not_Extended: 510,\n\n /**\n * 511 Network Authentication Required: The client needs to authenticate to gain network access.\n */\n Error_Server_511_Network_Authentication_Required: 511\n} as const;\n\nexport const HttpStatusMessages = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 208: 'Already Reported',\n 226: 'IM Used',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 305: 'Use Proxy',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: 'I\\'m a Teapot',\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 509: 'Bandwidth Limit Exceeded',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n};\n\nexport type HttpStatusCode = keyof typeof HttpStatusMessages;\n", "import {URL} from 'node:url';\n\nimport type {HttpMethod, NativeClientRequest} from './type.js';\n\nexport class NanotronUrl extends URL {\n protected static versionPattern_ = new RegExp('^/v[0-9]+/');\n\n readonly method: HttpMethod;\n readonly debugId: string;\n\n constructor(clientRequest: NativeClientRequest, prefix: `/${string}/` | '/') {\n let url = clientRequest.url ?? '';\n if (prefix !== '/' && url.indexOf(prefix) === 0) {\n url = url.slice(prefix.length - 1); // include `/`\n }\n url = url.replace(NanotronUrl.versionPattern_, '/');\n\n super(url, 'http://hostname/');\n\n this.method = (clientRequest.method ?? 'GET').toUpperCase() as HttpMethod;\n\n this.debugId = `[${this.method}]${this.pathname}`;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;AAAA,SAAQ,oBAAmB;AAE3B,SAAQ,gBAAAA,eAAc,qBAAoB;;;ACF1C,SAAQ,gBAAAC,qBAAmB;;;ACA3B,SAAQ,oBAAmB;;;ACGpB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA,EAIzB,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,MAAM;AAAA;AAAA;AA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iB;AACzC,YAAI,UAAU,gBAAgB,kBAAkB;AAChD,YAAI,IAAI,aAAa;AAAA,MACvB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEU,mBAAyB;AACjC,SAAK,QAAQ,YAAY,kBAAkB;AAC3C,UAAM,cAAc,KAAK,QAAQ;AACjC,QAAI,aAAa,WAAW,KAAM;AAClC,SAAK,YAAY;AAAA,MACf,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,KAAK;AAAA,MACL,SAAS,WAAY;AACnB,cAAM,MAAM,KAAK,eAAe;AAChC,YAAI,UAAU,gBAAgB,wBAAwB;AAAA,UACpD,+BAA+B,YAAY;AAAA,UAC3C,gCAAgC,YAAY;AAAA,UAC5C,gCAAgC,YAAY;AAAA,UAC5C,0BAA0B,YAAY,SAAS;AAAA,UAC/C,kBAAkB;AAAA,QACpB,CAAC;AACD,YAAI,IAAI;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAzPa,mBACe,iBAA8D;AAAA,EACtF,MAAM;AAAA,EACN,MAAM;AAAA,EACN,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,aAAa;AAAA,IACX,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,IACT,QAAQ;AAAA;AAAA,EACV;AAAA,EACA,QAAQ;AAAA,EACR,WAAW;AAAA;AACb;AAjBK,IAAM,oBAAN;",
|
|
4
|
+
"sourcesContent": ["import {createServer} from 'node:http';\n\nimport {createLogger, packageTracer} from '@alwatr/nanolib';\n\nimport {NanotronClientRequest} from './api-client-request.js';\nimport {HttpStatusCodes, HttpStatusMessages} from './const.js';\nimport {NanotronUrl} from './url.js';\n\nimport type {DefineRouteOption, MatchType, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {Duplex} from 'node:stream';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Configuration options for the NanotronApiServer.\n */\nexport interface NanotronApiServerConfig {\n /**\n * The port number to listen on.\n *\n * @default 80\n */\n port?: number;\n\n /**\n * The hostname to listen on.\n *\n * @default '0.0.0.0'\n */\n host?: string;\n\n /**\n * Sets the timeout (ms) for receiving the entire request from the client.\n *\n * @default 10_000 ms\n */\n requestTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * This should be bigger than `keepAliveTimeout + your server's expected response time`.\n *\n * @default 130_000 ms\n */\n headersTimeout?: number;\n\n /**\n * Sets the timeout (ms) for receiving the complete HTTP headers from the client.\n *\n * @default 120_000 ms\n */\n keepAliveTimeout?: number;\n\n /**\n * Add /health route.\n *\n * @default true\n */\n healthRoute?: boolean;\n\n /**\n * Add OPTIONS route for preflight requests to allow access origins.\n *\n * @default {enable: false, origin: '*', methods: '*', headers: '*', maxAge: 86_400}\n */\n crossOrigin?: {\n enable: boolean;\n origin: string;\n methods: string;\n headers: string;\n maxAge: string | number;\n },\n\n /**\n * A prefix to be added to the beginning of the `url` of all defined routes.\n *\n * @default '/api/'\n */\n prefix?: `/${string}/` | '/';\n\n /**\n * The maximum size of the request body in bytes.\n *\n * @default `1_048_576` (1MiB)\n */\n bodyLimit?: number;\n}\n\nexport class NanotronApiServer {\n protected static readonly defaultConfig_: Readonly<Required<NanotronApiServerConfig>> = {\n host: '0.0.0.0',\n port: 80,\n requestTimeout: 10_000,\n headersTimeout: 130_000,\n keepAliveTimeout: 120_000,\n healthRoute: true,\n crossOrigin: {\n enable: false,\n origin: '*',\n methods: '*',\n headers: '*',\n maxAge: 86_400, // 24h\n },\n prefix: '/api/',\n bodyLimit: 1_048_576, // 1MiB\n };\n\n readonly config_: Required<NanotronApiServerConfig>;\n protected readonly logger_;\n\n readonly httpServer;\n\n protected readonly routeHandlerList__: Record<MatchType, DictionaryOpt<DictionaryOpt<Required<DefineRouteOption>>>>;\n\n constructor(config?: Partial<NanotronApiServerConfig>) {\n // Merge the config with the default config.\n this.config_ = {\n ...NanotronApiServer.defaultConfig_,\n ...config,\n };\n\n // Create logger.\n this.logger_ = createLogger('nt-api-server' + (this.config_.port !== 80 ? ':' + this.config_.port : ''));\n this.logger_.logMethodArgs?.('new', {config: this.config_});\n\n // Bind methods.\n this.handleClientRequest_ = this.handleClientRequest_.bind(this);\n this.handleServerError_ = this.handleServerError_.bind(this);\n this.handleClientError_ = this.handleClientError_.bind(this);\n\n // Initialize route handler list.\n this.routeHandlerList__ = {\n exact: {},\n startsWith: {},\n };\n\n // Create the HTTP server.\n this.httpServer = createServer(\n {\n keepAlive: true,\n keepAliveInitialDelay: 0,\n noDelay: true,\n },\n this.handleClientRequest_,\n );\n\n // Configure the server.\n this.httpServer.requestTimeout = this.config_.requestTimeout;\n this.httpServer.keepAliveTimeout = this.config_.keepAliveTimeout;\n this.httpServer.headersTimeout = this.config_.headersTimeout;\n\n // Start the server.\n this.httpServer.listen(this.config_.port, this.config_.host, () => {\n this.logger_.logOther?.(`listening on ${this.config_.host}:${this.config_.port}`);\n });\n\n // Handle server errors.\n this.httpServer.on('error', this.handleServerError_);\n this.httpServer.on('clientError', this.handleClientError_);\n\n this.defineCorsRoute_();\n\n if (this.config_.healthRoute) {\n this.defineHealthRoute_();\n }\n }\n\n close(): void {\n this.logger_.logMethod?.('close');\n this.httpServer.close();\n }\n\n protected getRouteOption_(url: NanotronUrl): Required<DefineRouteOption> | null {\n this.logger_.logMethod?.('getRouteOption_');\n\n if (\n Object.hasOwn(this.routeHandlerList__.exact, url.method) &&\n Object.hasOwn(this.routeHandlerList__.exact[url.method]!, url.pathname)\n ) {\n return this.routeHandlerList__.exact[url.method]![url.pathname]!;\n }\n\n if (Object.hasOwn(this.routeHandlerList__.startsWith, url.method)) {\n const routeList = this.routeHandlerList__.startsWith[url.method];\n for (const pathname in routeList) {\n if (url.pathname.indexOf(pathname) === 0) {\n return routeList[pathname]!;\n }\n }\n }\n\n this.logger_.incident?.('getRouteOption_', 'route_not_found', {method: url.method, url: url.pathname});\n return null;\n }\n\n protected setRouteOption_(option: Required<DefineRouteOption>): void {\n this.logger_.logMethodArgs?.('setRouteOption_', option);\n\n const routeHandlerList = this.routeHandlerList__[option.matchType];\n\n routeHandlerList[option.method] ??= {};\n\n if (Object.hasOwn(routeHandlerList[option.method]!, option.url)) {\n this.logger_.error('defineRoute', 'route_already_exists', option);\n throw new Error('route_already_exists');\n }\n\n routeHandlerList[option.method]![option.url] = option;\n }\n\n defineRoute<TSharedMeta extends DictionaryOpt = DictionaryOpt>(option: DefineRouteOption<TSharedMeta>): void {\n const option_: Required<DefineRouteOption<TSharedMeta>> = {\n matchType: 'exact',\n preHandlers: [],\n postHandlers: [],\n bodyLimit: this.config_.bodyLimit,\n crossOrigin: this.config_.crossOrigin,\n ...option,\n };\n this.logger_.logMethodArgs?.('defineRoute', option_);\n this.setRouteOption_(option_ as Required<DefineRouteOption>);\n }\n\n protected handleServerError_(error: NodeJS.ErrnoException): void {\n if (error.code === 'EADDRINUSE') {\n this.logger_.error('handleServerError_', 'address_in_use', error);\n }\n else {\n this.logger_.error('handleServerError_', 'http_server_error', error);\n }\n }\n\n protected handleClientError_(err: NodeJS.ErrnoException, socket: Duplex): void {\n this.logger_.accident('handleClientError_', 'http_server_client_error', {\n errCode: err.code,\n errMessage: err.message,\n });\n\n const errorCode = err.code?.toLowerCase() ?? `error_${HttpStatusCodes.Error_Client_400_Bad_Request}`;\n const errorMessage = err.message ?? HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request];\n const errorResponse = `{\"ok\":false,\"errorCode\":\"${errorCode}\",\"errorMessage\":\"${errorMessage}\"}`;\n\n const responseHeaders = [\n `HTTP/1.1 ${HttpStatusCodes.Error_Client_400_Bad_Request} ${HttpStatusMessages[HttpStatusCodes.Error_Client_400_Bad_Request]}`,\n 'content-type: application/json',\n `content-length: ${Buffer.byteLength(errorResponse)}`,\n '\\r\\n',\n ].join('\\r\\n');\n\n socket.end(responseHeaders + errorResponse);\n }\n\n protected async handleClientRequest_(\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n ): Promise<void> {\n this.logger_.logMethod?.('handleClientRequest_');\n\n if (nativeClientRequest.url === undefined) {\n this.logger_.accident('handleClientRequest_', 'http_server_url_undefined');\n return;\n }\n\n const url = new NanotronUrl(nativeClientRequest, this.config_.prefix);\n\n const routeOption = this.getRouteOption_(url);\n\n const connection = new NanotronClientRequest(url, nativeClientRequest, nativeServerResponse, routeOption);\n\n if (routeOption === null) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Client_404_Not_Found;\n connection.serverResponse.replyError();\n return;\n }\n\n try {\n for (const handler of routeOption.preHandlers) {\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n if (connection.terminatedHandlers === true) return; // must check after each pre-handler.\n }\n\n await routeOption.handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n\n for (const handler of routeOption.postHandlers) {\n if (connection.terminatedHandlers === true) return; // must check before each post-handler.\n await handler.call(connection, connection, connection.serverResponse, connection.sharedMeta);\n }\n }\n catch (error) {\n this.logger_.error('handleClientRequest_', 'route_handler_error', error, url.debugId);\n\n if (connection.serverResponse.statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n connection.serverResponse.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n }\n connection.serverResponse.replyError(error);\n }\n\n // TODO: handled open remained connections.\n }\n\n protected defineHealthRoute_(): void {\n this.logger_.logMethod?.('defineHealthRoute_');\n\n this.defineRoute({\n method: 'GET',\n url: '/health',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.statusCode = HttpStatusCodes.Success_200_OK;\n res.setHeader('server', 'Alwatr Nanotron');\n res.setHeader('content-type', 'application/json');\n res.end('{\"ok\":true}');\n },\n });\n }\n\n protected defineCorsRoute_(): void {\n this.logger_.logMethod?.('defineCorsRoute_');\n const crossOrigin = this.config_.crossOrigin;\n if (crossOrigin?.enable !== true) return;\n this.defineRoute({\n method: 'OPTIONS',\n matchType: 'startsWith',\n url: '/',\n handler: function () {\n const res = this.serverResponse.raw_;\n res.writeHead(HttpStatusCodes.Success_204_No_Content, {\n 'access-control-allow-origin': crossOrigin.origin,\n 'access-control-allow-methods': crossOrigin.methods,\n 'access-control-allow-headers': crossOrigin.headers,\n 'access-control-max-age': crossOrigin.maxAge + '',\n 'content-length': 0,\n });\n res.end();\n },\n });\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {NanotronServerResponse} from './api-server-response.js';\nimport {HttpStatusCodes} from './const.js';\n\nimport type {DefineRouteOption, HttpRequestHeaders, NativeClientRequest, NativeServerResponse} from './type.js';\nimport type {NanotronUrl} from './url.js';\n\nexport class NanotronClientRequest<TSharedMeta extends DictionaryOpt = DictionaryOpt> {\n readonly url: NanotronUrl;\n\n readonly serverResponse: NanotronServerResponse;\n\n readonly routeOption: Required<DefineRouteOption> | null;\n\n /**\n * A flag to indicate if the running handlers queue has been terminated.\n * This can occur due to an error being thrown or by explicitly calling the `replyError` method.\n *\n * When `terminatedHandlers` is set to `true`, it signifies that the execution of the current\n * sequence of handlers (including pre, main, and post handlers) has been halted and no further\n * handlers in the queue will be executed.\n *\n * Usage:\n * - Check this flag to determine if the handlers queue has been interrupted.\n * - Set this flag to `true` to manually stop the execution of subsequent handlers.\n */\n terminatedHandlers?: true;\n\n readonly sharedMeta: TSharedMeta = {} as TSharedMeta;\n\n readonly raw_: NativeClientRequest;\n\n protected readonly logger_;\n\n readonly remoteAddress: string | null;\n\n get headers(): HttpRequestHeaders {\n return this.raw_.headers;\n }\n\n private queryParams__?: DictionaryOpt<string>;\n get queryParams(): DictionaryOpt<string> {\n if (this.queryParams__ === undefined) {\n this.queryParams__ = {};\n for (const [key, value] of this.url.searchParams.entries()) {\n this.queryParams__[key] = value;\n }\n }\n return this.queryParams__;\n }\n\n constructor(\n url: NanotronUrl,\n nativeClientRequest: NativeClientRequest,\n nativeServerResponse: NativeServerResponse,\n routeOption: Required<DefineRouteOption> | null,\n ) {\n // Store public properties.\n this.raw_ = nativeClientRequest;\n this.url = url;\n this.routeOption = routeOption;\n\n // Get and store remote address.\n this.remoteAddress = this.getRemoteAddress__();\n\n // Create logger.\n this.logger_ = createLogger(`nt-client-request(${this.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', url.debugId);\n\n // Create server response.\n this.serverResponse = new NanotronServerResponse(this, nativeServerResponse);\n }\n\n getBodyRaw(): Promise<Buffer> {\n return new Promise((resolve, reject) => {\n // method must be POST or PUT or PATCH\n const method = this.url.method;\n if (!(method === 'POST' || method === 'PUT' || method === 'PATCH')) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_405_Method_Not_Allowed;\n return reject(new Error('body_not_allowed'));\n }\n\n const contentLength = +this.raw_.headers['content-length']!;\n\n if (Number.isNaN(contentLength) || contentLength === 0) {\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_411_Length_Required;\n return reject(new Error('body_length_required'));\n }\n\n if (contentLength > this.routeOption!.bodyLimit) {\n // TODO: routeOption when null?!\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const dataChunks: Uint8Array[] = [];\n let receivedLength = 0;\n\n const onData = (chunk: Uint8Array) => {\n receivedLength += chunk.length;\n dataChunks.push(chunk);\n\n if (receivedLength > this.routeOption!.bodyLimit) {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n dataChunks.length = 0; // free memory\n this.serverResponse.headers.connection = 'close';\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n };\n\n const onEnd = (err?: Error) => {\n this.raw_.removeListener('data', onData);\n this.raw_.removeListener('end', onEnd);\n this.raw_.removeListener('error', onEnd);\n\n if (err !== undefined) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_400_Bad_Request;\n return reject(err);\n }\n\n if (receivedLength !== contentLength) {\n dataChunks.length = 0; // free memory\n this.serverResponse.statusCode = HttpStatusCodes.Error_Client_413_Payload_Too_Large;\n return reject(new Error('body_too_large'));\n }\n\n const body = Buffer.concat(dataChunks);\n\n resolve(body);\n };\n\n this.raw_.on('data', onData);\n this.raw_.on('end', onEnd);\n this.raw_.on('error', onEnd);\n this.raw_.resume();\n });\n }\n\n private getRemoteAddress__(): string | null {\n return this.raw_.headers['x-forwarded-for']?.split(',').pop()?.trim() || this.raw_.socket.remoteAddress || null;\n }\n}\n", "import {createLogger} from '@alwatr/nanolib';\n\nimport {type HttpStatusCode, HttpStatusCodes, HttpStatusMessages} from './const.js';\n\nimport type {NanotronClientRequest} from './api-client-request.js';\nimport type {HttpResponseHeaders, ErrorResponse, NativeServerResponse} from './type.js';\n\n/**\n * Configuration options for the Nanotron Api Server Response.\n */\nexport interface NanotronServerResponseConfig {\n clientRequest: NanotronClientRequest;\n}\n\nexport class NanotronServerResponse {\n readonly clientRequest: NanotronClientRequest;\n\n readonly raw_: NativeServerResponse;\n\n readonly headers: HttpResponseHeaders;\n\n protected readonly logger_;\n\n protected hasBeenSent_ = false;\n get hasBeenSent(): boolean {\n return this.hasBeenSent_;\n }\n\n constructor(nanotronClientRequest: NanotronClientRequest, nativeServerResponse: NativeServerResponse) {\n // Store public properties.\n this.clientRequest = nanotronClientRequest;\n this.raw_ = nativeServerResponse;\n\n // Create logger.\n this.logger_ = createLogger(`nt-server-response(${this.clientRequest.remoteAddress})`);\n this.logger_.logMethodArgs?.('new', this.clientRequest.url.debugId);\n\n // Set default reply headers.\n this.headers = {\n server: 'Alwatr Nanotron',\n 'content-type': 'text/plain charset=UTF-8',\n };\n\n const crossOrigin = this.clientRequest.routeOption?.crossOrigin;\n if (crossOrigin?.enable === true) {\n this.headers['access-control-allow-origin'] = crossOrigin.origin;\n this.headers['access-control-allow-methods'] = crossOrigin.methods;\n this.headers['access-control-allow-headers'] = crossOrigin.headers;\n this.headers['access-control-max-age'] = crossOrigin.maxAge;\n }\n }\n\n get statusCode(): HttpStatusCode {\n return this.raw_.statusCode as HttpStatusCode;\n }\n\n set statusCode(value: HttpStatusCode) {\n this.raw_.statusCode = value;\n }\n\n protected applyHeaders_() {\n this.logger_.logMethodArgs?.('applyHeaders_', this.headers);\n for (const key in this.headers) {\n this.raw_.setHeader(key, this.headers[key as Lowercase<string>]!);\n }\n }\n\n replyErrorResponse(errorResponse: ErrorResponse): void {\n this.logger_.logMethod?.('replyErrorResponse');\n this.clientRequest.terminatedHandlers = true;\n this.headers['content-type'] = 'application/json';\n let meta = '';\n if (errorResponse.meta !== undefined) {\n const metaType = typeof errorResponse.meta;\n if (\n metaType === 'string' ||\n metaType === 'number' ||\n metaType === 'boolean' ||\n errorResponse.meta === null) {\n meta = `,\"meta\":\"${errorResponse.meta}\"`;\n }\n else if (metaType === 'object') {\n meta = `,\"meta\":${JSON.stringify(errorResponse.meta)}`;\n }\n }\n const responseString = `{\"ok\":false,\"errorCode\":\"${errorResponse.errorCode}\",\"errorMessage\":\"${errorResponse.errorMessage}\"${meta}}`;\n this.reply(responseString);\n }\n\n replyError(error?: Error | string | Json | unknown): void {\n this.logger_.logMethodArgs?.('replyError', {error});\n\n this.clientRequest.terminatedHandlers = true;\n let statusCode = this.statusCode;\n\n if (statusCode < HttpStatusCodes.Error_Client_400_Bad_Request) {\n this.statusCode = statusCode = 500;\n }\n\n if (error instanceof Error) {\n this.replyErrorResponse({\n ok: false,\n errorCode: (error.name === 'Error' ? 'error_' + statusCode : (error.name + '').toLowerCase()) as Lowercase<string>,\n errorMessage: error.message,\n });\n }\n else if (typeof error === 'string') {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: error,\n });\n }\n else if (typeof error === 'object' && error !== null) {\n this.replyJson(error as Json);\n }\n else {\n this.replyErrorResponse({\n ok: false,\n errorCode: ('error_' + statusCode) as Lowercase<string>,\n errorMessage: HttpStatusMessages[statusCode],\n });\n }\n }\n\n replyJson(responseJson: Json): void {\n this.logger_.logMethodArgs?.('replyJson', {responseJson});\n\n let responseString: string;\n try {\n responseString = JSON.stringify(responseJson);\n }\n catch (error) {\n this.logger_.error('replyJson', 'reply_json_stringify_failed', error, this.clientRequest.url.debugId);\n this.statusCode = HttpStatusCodes.Error_Server_500_Internal_Server_Error;\n this.replyErrorResponse({\n ok: false,\n errorCode: 'reply_json_stringify_failed',\n errorMessage: 'Failed to stringify response JSON.',\n });\n return;\n }\n\n this.headers['content-type'] = 'application/json';\n this.reply(responseString);\n }\n\n reply(context: string | Buffer): void {\n this.logger_.logMethodArgs?.('reply', this.clientRequest.url.debugId);\n\n if (this.raw_.writableFinished && this.hasBeenSent_ === false) {\n // The response has already been sent by direct access to the server api.\n this.logger_.accident('reply', 'server_response_writable_finished_directly');\n this.hasBeenSent_ = true;\n }\n\n if (this.hasBeenSent_) {\n this.logger_.accident('reply', 'reply_already_sent', {\n url: this.clientRequest.url.debugId,\n replySent: this.hasBeenSent_,\n writableFinished: this.raw_.writableFinished,\n });\n return;\n }\n\n this.hasBeenSent_ = true;\n\n try {\n if (typeof context === 'string') {\n context = Buffer.from(context);\n }\n\n this.headers['content-length'] = context.byteLength;\n\n this.applyHeaders_();\n this.raw_.end(context, 'binary');\n }\n catch (error) {\n this.logger_.error('reply', 'server_response_error', error, this.clientRequest.url.debugId);\n this.hasBeenSent_ = false;\n }\n }\n}\n", "/**\n * Object representing standard HTTP methods.\n */\nexport const HttpMethods = {\n /**\n * GET: Requests a representation of the specified resource.\n */\n GET: 'GET',\n\n /**\n * HEAD: Asks for a response identical to that of a GET request, but without the response body.\n */\n HEAD: 'HEAD',\n\n /**\n * POST: Submits data to be processed (e.g., from an HTML form) to the identified resource.\n */\n POST: 'POST',\n\n /**\n * PUT: Uploads a representation of the specified URI.\n */\n PUT: 'PUT',\n\n /**\n * DELETE: Deletes the specified resource.\n */\n DELETE: 'DELETE',\n\n /**\n * CONNECT: Establishes a tunnel to the server identified by the target resource.\n */\n CONNECT: 'CONNECT',\n\n /**\n * OPTIONS: Describes the communication options for the target resource.\n */\n OPTIONS: 'OPTIONS',\n\n /**\n * TRACE: Performs a message loop-back test along the path to the target resource.\n */\n TRACE: 'TRACE',\n\n /**\n * PATCH: Applies partial modifications to a resource.\n */\n PATCH: 'PATCH'\n} as const;\n\n/**\n * Object representing standard HTTP status codes.\n */\nexport const HttpStatusCodes = {\n /**\n * 100 Continue: The server has received the request headers and the client should proceed to send the request body.\n */\n Info_100_Continue: 100,\n\n /**\n * 101 Switching Protocols: The server understands and is willing to comply with the clients request to switch protocols.\n */\n Info_101_Switching_Protocols: 101,\n\n /**\n * 102 Processing: The server has received and is processing the request, but no response is available yet.\n */\n Info_102_Processing: 102,\n\n /**\n * 103 Early Hints: The server is sending some response headers before the final HTTP message.\n */\n Info_103_Early_Hints: 103,\n\n /**\n * 200 OK: The request has succeeded.\n */\n Success_200_OK: 200,\n\n /**\n * 201 Created: The request has been fulfilled and resulted in a new resource being created.\n */\n Success_201_Created: 201,\n\n /**\n * 202 Accepted: The request has been accepted for processing, but the processing has not been completed.\n */\n Success_202_Accepted: 202,\n\n /**\n * 203 Non-Authoritative Information: The server is a transforming proxy that received a 200 OK\n * from the origin server but is returning a modified version of the origins response.\n */\n Success_203_Non_Authoritative_Information: 203,\n\n /**\n * 204 No Content: The server successfully processed the request and is not returning any content.\n */\n Success_204_No_Content: 204,\n\n /**\n * 205 Reset Content: The server successfully processed the request,\n * asks that the client reset its document view, and is not returning any content.\n */\n Success_205_Reset_Content: 205,\n\n /**\n * 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.\n */\n Success_206_Partial_Content: 206,\n\n /**\n * 207 Multi-Status: The message body that follows is an XML message\n * and can contain a number of separate response codes, depending on how many sub-requests were made.\n */\n Success_207_Multi_Status: 207,\n\n /**\n * 208 Already Reported: The members of a DAV binding have already been enumerated\n * in a preceding part of the (multi-status) response, and are not being included again.\n */\n Success_208_Already_Reported: 208,\n\n /**\n * 226 IM Used: The server has fulfilled a request for the resource, and the response is a representation\n * of the result of one or more instance-manipulations applied to the current instance.\n */\n Success_226_IM_Used: 226,\n\n /**\n * 300 Multiple Choices: The request has more than one possible response.\n */\n Redirect_300_Multiple_Choices: 300,\n\n /**\n * 301 Moved Permanently: The URL of the requested resource has been changed permanently.\n */\n Redirect_301_Moved_Permanently: 301,\n\n /**\n * 302 Found: The URL of the requested resource has been changed temporarily.\n */\n Redirect_302_Found: 302,\n\n /**\n * 303 See Other: The response to the request can be found under another URI using a GET method.\n */\n Redirect_303_See_Other: 303,\n\n /**\n * 304 Not Modified: The resource has not been modified since the version specified\n * by the request headers If-Modified-Since or If-None-Match.\n */\n Redirect_304_Not_Modified: 304,\n\n /**\n * 305 Use Proxy: The requested resource is only available through a proxy, the address for which is provided in the response.\n */\n Redirect_305_Use_Proxy: 305,\n\n /**\n * 306 Switch Proxy: No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"\n */\n Redirect_306_Switch_Proxy: 306,\n\n /**\n * 307 Temporary Redirect: The server sends this response to direct the client\n * to get the requested resource at another URI with the same method that was used in the prior request.\n */\n Redirect_307_Temporary_Redirect: 307,\n\n /**\n * 308 Permanent Redirect: This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header.\n */\n Redirect_308_Permanent_Redirect: 308,\n\n /**\n * 400 Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error.\n */\n Error_Client_400_Bad_Request: 400,\n\n /**\n * 401 Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource.\n */\n Error_Client_401_Unauthorized: 401,\n\n /**\n * 402 Payment Required: Reserved for future use.\n */\n Error_Client_402_Payment_Required: 402,\n\n /**\n * 403 Forbidden: The client does not have access rights to the content, so the server is refusing to give the requested resource.\n */\n Error_Client_403_Forbidden: 403,\n\n /**\n * 404 Not Found: The server can not find the requested resource.\n */\n Error_Client_404_Not_Found: 404,\n\n /**\n * 405 Method Not Allowed: The request method is known by the server but is not supported by the target resource.\n */\n Error_Client_405_Method_Not_Allowed: 405,\n\n /**\n * 406 Not Acceptable: The target resource does not have a current representation that would be acceptable\n * to the user agent, according to the proactive negotiation header fields received in the request,\n * and the server is unwilling to supply a default representation.\n */\n Error_Client_406_Not_Acceptable: 406,\n\n /**\n * 407 Proxy Authentication Required: Similar to 401 Unauthorized,\n * but it indicates that the client needs to authenticate itself in order to use a proxy.\n */\n Error_Client_407_Proxy_Authentication_Required: 407,\n\n /**\n * 408 Request Timeout: The server timed out waiting for the request.\n */\n Error_Client_408_Request_Timeout: 408,\n\n /**\n * 409 Conflict: The request could not be processed because of conflict in the request, such as an edit conflict.\n */\n Error_Client_409_Conflict: 409,\n\n /**\n * 410 Gone: The requested resource is no longer available and will not be available again.\n */\n Error_Client_410_Gone: 410,\n\n /**\n * 411 Length Required: The server refuses to accept the request without a defined Content-Length header.\n */\n Error_Client_411_Length_Required: 411,\n\n /**\n * 412 Precondition Failed: One or more conditions given in the request header fields evaluated to false when tested on the server.\n */\n Error_Client_412_Precondition_Failed: 412,\n\n /**\n * 413 Payload Too Large: The server is refusing to process a request because the request payload is larger\n * than the server is willing or able to process.\n */\n Error_Client_413_Payload_Too_Large: 413,\n\n /**\n * 414 URI Too Long: The server is refusing to service the request because the URI is longer than the server is willing to interpret.\n */\n Error_Client_414_URI_Too_Long: 414,\n\n /**\n * 415 Unsupported Media Type: The server is refusing to service the request\n * because the entity of the request is in a format not supported by the requested resource for the requested method.\n */\n Error_Client_415_Unsupported_Media_Type: 415,\n\n /**\n * 416 Range Not Satisfiable: The client has asked for a portion of the file, but the server cannot supply that portion.\n */\n Error_Client_416_Range_Not_Satisfiable: 416,\n\n /**\n * 417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field.\n */\n Error_Client_417_Expectation_Failed: 417,\n\n /**\n * 421 Misdirected Request: The request was directed at a server that is not able to produce a response.\n */\n Error_Client_421_Misdirected_Request: 421,\n\n /**\n * 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.\n */\n Error_Client_422_Unprocessable_Entity: 422,\n\n /**\n * 423 Locked: The resource that is being accessed is locked.\n */\n Error_Client_423_Locked: 423,\n\n /**\n * 424 Failed Dependency: The request failed due to a failure of a previous request.\n */\n Error_Client_424_Failed_Dependency: 424,\n\n /**\n * 425 Too Early: The server is unwilling to risk processing a request that might be replayed.\n */\n Error_Client_425_Too_Early: 425,\n\n /**\n * 426 Upgrade Required: The server refuses to perform the request using the current protocol\n * but might be willing to do so after the client upgrades to a different protocol.\n */\n Error_Client_426_Upgrade_Required: 426,\n\n /**\n * 428 Precondition Required: The origin server requires the request to be conditional.\n */\n Error_Client_428_Precondition_Required: 428,\n\n /**\n * 429 Too Many Requests: The user has sent too many requests in a given amount of time (\"rate limiting\").\n */\n Error_Client_429_Too_Many_Requests: 429,\n\n /**\n * 431 Request Header Fields Too Large: The server is unwilling to process the request because its header fields are too large.\n */\n Error_Client_431_Request_Header_Fields_Too_Large: 431,\n\n /**\n * 451 Unavailable For Legal Reasons: The user requests an illegal resource, such as a web page censored by a government.\n */\n Error_Client_451_Unavailable_For_Legal_Reasons: 451,\n\n /**\n * 500 Internal Server Error: A generic error message, given when no more specific message is suitable.\n */\n Error_Server_500_Internal_Server_Error: 500,\n\n /**\n * 501 Not Implemented: The server either does not recognize the request method, or it lacks the ability to fulfill the request.\n */\n Error_Server_501_Not_Implemented: 501,\n\n /**\n * 502 Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server.\n */\n Error_Server_502_Bad_Gateway: 502,\n\n /**\n * 503 Service Unavailable: The server is currently unavailable (because it is overloaded or down for maintenance).\n */\n Error_Server_503_Service_Unavailable: 503,\n\n /**\n * 504 Gateway Timeout: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\n */\n Error_Server_504_Gateway_Timeout: 504,\n\n /**\n * 505 HTTP Version Not Supported: The server does not support the HTTP protocol version used in the request.\n */\n Error_Server_505_HTTP_Version_Not_Supported: 505,\n\n /**\n * 506 Variant Also Negotiates: Transparent content negotiation for the request results in a circular reference.\n */\n Error_Server_506_Variant_Also_Negotiates: 506,\n\n /**\n * 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.\n */\n Error_Server_507_Insufficient_Storage: 507,\n\n /**\n * 508 Loop Detected: The server detected an infinite loop while processing the request.\n */\n Error_Server_508_Loop_Detected: 508,\n\n /**\n * 510 Not Extended: Further extensions to the request are required for the server to fulfill it.\n */\n Error_Server_510_Not_Extended: 510,\n\n /**\n * 511 Network Authentication Required: The client needs to authenticate to gain network access.\n */\n Error_Server_511_Network_Authentication_Required: 511\n} as const;\n\nexport const HttpStatusMessages = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 208: 'Already Reported',\n 226: 'IM Used',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 305: 'Use Proxy',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: 'I\\'m a Teapot',\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 509: 'Bandwidth Limit Exceeded',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n};\n\nexport type HttpStatusCode = keyof typeof HttpStatusMessages;\n", "import {URL} from 'node:url';\n\nimport type {HttpMethod, NativeClientRequest} from './type.js';\n\nexport class NanotronUrl extends URL {\n protected static versionPattern_ = new RegExp('^/v[0-9]+/');\n\n readonly method: HttpMethod;\n readonly debugId: string;\n\n constructor(clientRequest: NativeClientRequest, prefix: `/${string}/` | '/') {\n let url = clientRequest.url ?? '';\n if (prefix !== '/' && url.indexOf(prefix) === 0) {\n url = url.slice(prefix.length - 1); // include `/`\n }\n url = url.replace(NanotronUrl.versionPattern_, '/');\n\n super(url, 'http://hostname/');\n\n this.method = (clientRequest.method ?? 'GET').toUpperCase() as HttpMethod;\n\n this.debugId = `[${this.method}]${this.pathname}`;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;AAAA,SAAQ,oBAAmB;AAE3B,SAAQ,gBAAAA,eAAc,qBAAoB;;;ACF1C,SAAQ,gBAAAC,qBAAmB;;;ACA3B,SAAQ,oBAAmB;;;ACGpB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA,EAIzB,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,MAAM;AAAA;AAAA;AAAA;AAAA,EAKN,KAAK;AAAA;AAAA;AAAA;AAAA,EAKL,QAAQ;AAAA;AAAA;AAAA;AAAA,EAKR,SAAS;AAAA;AAAA;AAAA;AAAA,EAKT,SAAS;AAAA;AAAA;AAAA;AAAA,EAKT,OAAO;AAAA;AAAA;AAAA;AAAA,EAKP,O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Y;AAAA,MACf,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,KAAK;AAAA,MACL,SAAS,WAAY;AACnB,cAAM,MAAM,KAAK,eAAe;AAChC,YAAI,UAAU,gBAAgB,wBAAwB;AAAA,UACpD,+BAA+B,YAAY;AAAA,UAC3C,gCAAgC,YAAY;AAAA,UAC5C,gCAAgC,YAAY;AAAA,UAC5C,0BAA0B,YAAY,SAAS;AAAA,UAC/C,kBAAkB;AAAA,QACpB,CAAC;AACD,YAAI,IAAI;AAAA,MACV;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAzPa,mBACe,iBAA8D;AAAA,EACtF,MAAM;AAAA,EACN,MAAM;AAAA,EACN,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,aAAa;AAAA,IACX,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,IACT,QAAQ;AAAA;AAAA,EACV;AAAA,EACA,QAAQ;AAAA,EACR,WAAW;AAAA;AACb;AAjBK,IAAM,oBAAN;",
|
|
6
6
|
"names": ["createLogger", "createLogger", "createLogger", "createLogger"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/nanotron-api-server",
|
|
3
|
-
"version": "4.9.1",
|
|
4
3
|
"description": "Nanotron: Your Lightweight, High-Performance Micro/Nano Service Framework. Nanotron is designed for building blazingly fast and efficient microservices and APIs. Its minimalist approach and focus on performance make it ideal for resource-constrained environments and scenarios where every millisecond counts.",
|
|
4
|
+
"version": "4.9.4",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"alwatr"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
"bugs": "https://github.com/Alwatr/nanotron/issues",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@alwatr/nanolib": "^5.6.6"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@alwatr/nano-build": "^5.5.4",
|
|
12
|
+
"@alwatr/prettier-config": "^5.0.0",
|
|
13
|
+
"@alwatr/tsconfig-base": "^5.0.0",
|
|
14
|
+
"@alwatr/type-helper": "^5.4.2",
|
|
15
|
+
"@types/node": "^22.17.2",
|
|
16
|
+
"jest": "^30.0.5",
|
|
17
|
+
"typescript": "^5.9.2"
|
|
18
|
+
},
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|
|
20
21
|
"types": "./dist/main.d.ts",
|
|
@@ -22,11 +23,23 @@
|
|
|
22
23
|
"require": "./dist/main.cjs"
|
|
23
24
|
}
|
|
24
25
|
},
|
|
25
|
-
"license": "AGPL-3.0-only",
|
|
26
26
|
"files": [
|
|
27
27
|
"**/*.{js,mjs,cjs,map,d.ts,html,md}",
|
|
28
28
|
"!demo/**/*"
|
|
29
29
|
],
|
|
30
|
+
"homepage": "https://github.com/Alwatr/nanotron/tree/next/packages/api-server#readme",
|
|
31
|
+
"keywords": [
|
|
32
|
+
"alwatr",
|
|
33
|
+
"api",
|
|
34
|
+
"esm",
|
|
35
|
+
"nanoservice",
|
|
36
|
+
"server",
|
|
37
|
+
"typescript"
|
|
38
|
+
],
|
|
39
|
+
"license": "AGPL-3.0-only",
|
|
40
|
+
"main": "./dist/main.cjs",
|
|
41
|
+
"module": "./dist/main.mjs",
|
|
42
|
+
"prettier": "@alwatr/prettier-config",
|
|
30
43
|
"publishConfig": {
|
|
31
44
|
"access": "public"
|
|
32
45
|
},
|
|
@@ -35,38 +48,23 @@
|
|
|
35
48
|
"url": "https://github.com/Alwatr/nanotron",
|
|
36
49
|
"directory": "packages/api-server"
|
|
37
50
|
},
|
|
38
|
-
"homepage": "https://github.com/Alwatr/nanotron/tree/next/packages/api-server#readme",
|
|
39
|
-
"bugs": {
|
|
40
|
-
"url": "https://github.com/Alwatr/nanotron/issues"
|
|
41
|
-
},
|
|
42
|
-
"prettier": "@alwatr/prettier-config",
|
|
43
51
|
"scripts": {
|
|
44
52
|
"b": "yarn run build",
|
|
45
|
-
"t": "yarn run test",
|
|
46
|
-
"w": "yarn run watch",
|
|
47
|
-
"c": "yarn run clean",
|
|
48
|
-
"cb": "yarn run clean && yarn run build",
|
|
49
|
-
"d": "yarn run build:es && yarn node --enable-source-maps --trace-warnings",
|
|
50
53
|
"build": "yarn run build:ts & yarn run build:es",
|
|
51
54
|
"build:es": "nano-build --preset=module",
|
|
52
55
|
"build:ts": "tsc --build",
|
|
56
|
+
"c": "yarn run clean",
|
|
57
|
+
"cb": "yarn run clean && yarn run build",
|
|
58
|
+
"clean": "rm -rfv dist *.tsbuildinfo",
|
|
59
|
+
"d": "yarn run build:es && yarn node --enable-source-maps --trace-warnings",
|
|
60
|
+
"t": "yarn run test",
|
|
53
61
|
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --enable-source-maps --experimental-vm-modules\" jest",
|
|
62
|
+
"w": "yarn run watch",
|
|
54
63
|
"watch": "yarn run watch:ts & yarn run watch:es",
|
|
55
64
|
"watch:es": "yarn run build:es --watch",
|
|
56
|
-
"watch:ts": "yarn run build:ts --watch --preserveWatchOutput"
|
|
57
|
-
"clean": "rm -rfv dist *.tsbuildinfo"
|
|
58
|
-
},
|
|
59
|
-
"dependencies": {
|
|
60
|
-
"@alwatr/nanolib": "^5.5.0"
|
|
65
|
+
"watch:ts": "yarn run build:ts --watch --preserveWatchOutput"
|
|
61
66
|
},
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"@alwatr/tsconfig-base": "^5.0.0",
|
|
66
|
-
"@alwatr/type-helper": "^5.4.0",
|
|
67
|
-
"@types/node": "^22.13.9",
|
|
68
|
-
"jest": "^29.7.0",
|
|
69
|
-
"typescript": "^5.8.2"
|
|
70
|
-
},
|
|
71
|
-
"gitHead": "837fa8308cc3ba69a73c5cbe4ea03563adf0d56d"
|
|
67
|
+
"type": "module",
|
|
68
|
+
"types": "./dist/main.d.ts",
|
|
69
|
+
"gitHead": "d225632fac937bbf0faeb6db7eb9796e6ff0f00a"
|
|
72
70
|
}
|