@keetanetwork/anchor 0.0.14 → 0.0.16
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/lib/certificates.d.ts.map +1 -1
- package/lib/certificates.js +20 -100
- package/lib/certificates.js.map +1 -1
- package/lib/http-server.js +1 -1
- package/lib/http-server.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/log/index.d.ts +6 -57
- package/lib/log/index.d.ts.map +1 -1
- package/lib/log/index.js +5 -205
- package/lib/log/index.js.map +1 -1
- package/lib/log/target_console.d.ts +3 -11
- package/lib/log/target_console.d.ts.map +1 -1
- package/lib/log/target_console.js +3 -42
- package/lib/log/target_console.js.map +1 -1
- package/lib/resolver.js +22 -22
- package/lib/uri.d.ts +28 -0
- package/lib/uri.d.ts.map +1 -0
- package/lib/uri.js +100 -0
- package/lib/uri.js.map +1 -0
- package/lib/utils/asn1.d.ts +9 -1
- package/lib/utils/asn1.d.ts.map +1 -1
- package/lib/utils/asn1.js +1413 -0
- package/lib/utils/asn1.js.map +1 -1
- package/lib/utils/buffer.d.ts +1 -1
- package/lib/utils/buffer.d.ts.map +1 -1
- package/lib/utils/buffer.js +8 -2
- package/lib/utils/buffer.js.map +1 -1
- package/lib/utils/external.d.ts +43 -0
- package/lib/utils/external.d.ts.map +1 -0
- package/lib/utils/external.js +115 -0
- package/lib/utils/external.js.map +1 -0
- package/npm-shrinkwrap.json +9 -9
- package/package.json +2 -2
- package/services/asset-movement/common.js +7 -7
- package/services/kyc/iso20022.generated.d.ts +89 -28
- package/services/kyc/iso20022.generated.d.ts.map +1 -1
- package/services/kyc/iso20022.generated.js +191 -88
- package/services/kyc/iso20022.generated.js.map +1 -1
- package/services/kyc/oids.generated.d.ts +24 -9
- package/services/kyc/oids.generated.d.ts.map +1 -1
- package/services/kyc/oids.generated.js +38 -15
- package/services/kyc/oids.generated.js.map +1 -1
- package/services/kyc/utils/generate-kyc-schema.js +305 -75
- package/services/kyc/utils/generate-kyc-schema.js.map +1 -1
- package/lib/log/common.d.ts +0 -35
- package/lib/log/common.d.ts.map +0 -1
- package/lib/log/common.js +0 -19
- package/lib/log/common.js.map +0 -1
package/lib/http-server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-server.js","sourceRoot":"","sources":["../../src/lib/http-server.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EACN,oBAAoB,EACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,MAAM,CAAC,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAmK,CAAC;AAEpM;;GAEG;AACH,MAAM,gBAAgB,GAAG,IAAI,GAAG,GAAG,CAAC;AAgBnC,CAAC;AAEF,MAAM,OAAgB,wBAAwB;IACpC,IAAI,CAAmD;IACvD,MAAM,CAAqD;IACpE,cAAc,CAAiB;IAC/B,OAAO,CAAe;IACb,OAAO,CAAa;IAE7B,YAAY,MAAkB;QAC7B,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;IAC1C,CAAC;IAIO,MAAM,CAAC,UAAU,CAAC,UAAe,EAAE,QAAa;QACvD,MAAM,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvD,MAAM,aAAa,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEnD,IA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AC/B,2EAA2E;gBAC3E,MAAM,CAAC,KAAK,CAAC,CAAC;YACf,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACT,MAAM,IAAI,CAAC,cAAc,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACT,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QACtB,aAAa;QACb,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,IAAI,GAAG;QACN,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACnD,MAAK,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC;QACxC,CAAC;QAED,OAAM,CAAC,oBAAoB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,CAAC,MAAM,CAAC,YAAY,CAAC;QACpB,OAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACrB,CAAC;CACD","sourcesContent":["import * as http from 'http';\nimport {\n\tKeetaAnchorUserError\n} from './error.js';\nimport type { JSONSerializable } from './utils/json.js';\nimport type { Logger } from './log/index.js';\nimport { Log } from './log/index.js';\nimport { createAssert } from 'typia';\n\nexport const AssertHTTPErrorData: (input: unknown) => { error: string; statusCode?: number; contentType?: string; } = createAssert<{ error: string; statusCode?: number; contentType?: string; }>();\n\n/**\n * The maximum size of a request (128KiB)\n */\nconst MAX_REQUEST_SIZE = 1024 * 128;\n\nexport type Routes = {\n\t[route: string]: (urlParams: Map<string, string>, postData: JSONSerializable | undefined, requestHeaders: http.IncomingHttpHeaders) => Promise<{ output: string; statusCode?: number; contentType?: string; headers?: { [headerName: string]: string; }; }>;\n};\n\nexport interface KeetaAnchorHTTPServerConfig {\n\t/**\n\t * The port for the HTTP server to listen on (default is an ephemeral port).\n\t */\n\tport?: number;\n\n\t/**\n\t * Enable debug logging\n\t */\n\tlogger?: Logger;\n};\n\nexport abstract class KeetaNetAnchorHTTPServer<ConfigType extends KeetaAnchorHTTPServerConfig = KeetaAnchorHTTPServerConfig> implements Required<KeetaAnchorHTTPServerConfig> {\n\treadonly port: NonNullable<KeetaAnchorHTTPServerConfig['port']>;\n\treadonly logger: NonNullable<KeetaAnchorHTTPServerConfig['logger']>;\n\t#serverPromise?: Promise<void>;\n\t#server?: http.Server;\n\treadonly #config: ConfigType;\n\n\tconstructor(config: ConfigType) {\n\t\tthis.#config = { ...config };\n\t\tthis.port = config.port ?? 0;\n\t\tthis.logger = config.logger ?? new Log();\n\t}\n\n\tprotected abstract initRoutes(config: ConfigType): Promise<Routes>;\n\n\tprivate static routeMatch(requestURL: URL, routeURL: URL): ({ match: true; params: Map<string, string> } | { match: false }) {\n\t\tconst requestURLPaths = requestURL.pathname.split('/');\n\t\tconst routeURLPaths = routeURL.pathname.split('/');\n\n\t\tif (requestURLPaths.length !== routeURLPaths.length) {\n\t\t\treturn({ match: false });\n\t\t}\n\n\t\tconst params = new Map<string, string>();\n\t\tfor (let partIndex = 0; partIndex < requestURLPaths.length; partIndex++) {\n\t\t\tconst requestPath = requestURLPaths[partIndex];\n\t\t\tconst routePath = routeURLPaths[partIndex];\n\n\t\t\tif (routePath === undefined || requestPath === undefined) {\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\n\t\t\tif (routePath.startsWith(':')) {\n\t\t\t\tparams.set(routePath.slice(1), requestPath);\n\t\t\t} else if (requestPath !== routePath) {\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\t\t}\n\n\t\treturn({ match: true, params: params });\n\t}\n\n\tprivate static routeFind(method: string, requestURL: URL, routes: Routes): { route: Routes[keyof Routes]; params: Map<string, string> } | null {\n\t\tfor (const routeKey in routes) {\n\t\t\tconst route = routes[routeKey];\n\t\t\tif (route === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst [routeMethod, ...routePathParts] = routeKey.split(' ');\n\t\t\tconst routePath = `/${routePathParts.join(' ')}`.replace(/^\\/+/, '/');\n\n\t\t\tif (method !== routeMethod) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst routeURL = new URL(routePath, 'http://localhost');\n\t\t\tconst matchResult = this.routeMatch(requestURL, routeURL);\n\t\t\tif (matchResult.match) {\n\t\t\t\treturn({\n\t\t\t\t\troute: route,\n\t\t\t\t\tparams: matchResult.params\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn(null);\n\t}\n\n\tprivate static addCORS(routes: Routes): Routes {\n\t\tconst newRoutes: Routes = {};\n\n\t\tconst validMethods = new Set(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']);\n\n\t\tconst methodsByPath: { [key: string]: Set<string>; } = {};\n\t\tfor (const routeKey in routes) {\n\t\t\tconst methodAndPath = routeKey.split(' ');\n\t\t\tconst method = methodAndPath[0];\n\t\t\tconst path = methodAndPath.slice(1).join(' ');\n\n\t\t\tif (method === undefined || path === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!validMethods.has(method)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!(path in methodsByPath)) {\n\t\t\t\tmethodsByPath[path] = new Set<string>();\n\t\t\t}\n\n\t\t\tif (methodsByPath[path] === undefined) {\n\t\t\t\tthrow(new Error(`internal error: methodsByPath missing path for ${path}`));\n\t\t\t}\n\n\t\t\tmethodsByPath[path].add(method);\n\t\t}\n\n\t\tconst seenPaths = new Set<string>();\n\t\tfor (const routeKey in routes) {\n\t\t\tconst methodAndPath = routeKey.split(' ');\n\t\t\tconst method = methodAndPath[0];\n\t\t\tconst path = methodAndPath.slice(1).join(' ');\n\n\t\t\tconst routeHandler = routes[routeKey];\n\t\t\tif (routeHandler === undefined) {\n\t\t\t\tthrow(new Error(`internal error: routeHandler missing for routeKey ${routeKey}`));\n\t\t\t}\n\n\t\t\tif (method !== 'ERROR') {\n\t\t\t\tif (method === undefined || path === undefined) {\n\t\t\t\t\tnewRoutes[routeKey] = routeHandler;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (!validMethods.has(method)) {\n\t\t\t\t\tnewRoutes[routeKey] = routeHandler;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst validMethodsForPath = methodsByPath[path];\n\n\t\t\tlet validMethodsForPathParts: string[] = [];\n\t\t\tif (validMethodsForPath !== undefined) {\n\t\t\t\tvalidMethodsForPath.add('OPTIONS');\n\t\t\t\tvalidMethodsForPathParts = Array.from(validMethodsForPath);\n\t\t\t} else {\n\t\t\t\tvalidMethodsForPathParts = [...Array.from(validMethods), 'OPTIONS'];\n\t\t\t}\n\n\t\t\tnewRoutes[routeKey] = async function(...args: Parameters<typeof routes[keyof typeof routes]>) {\n\t\t\t\tconst retval = await routeHandler(...args);\n\n\t\t\t\t/* Add CORS headers to the response for the original route handler */\n\t\t\t\tif (retval.contentType === 'application/json' || retval.contentType === undefined) {\n\t\t\t\t\tif (!('headers' in retval) || retval.headers === undefined) {\n\t\t\t\t\t\tretval.headers = {};\n\t\t\t\t\t}\n\t\t\t\t\tretval.headers['Access-Control-Allow-Origin'] = '*';\n\t\t\t\t}\n\n\t\t\t\treturn(retval);\n\t\t\t};\n\n\t\t\tif (!seenPaths.has(path) && path !== '' && path !== undefined) {\n\t\t\t\tconst corsRouteKey = `OPTIONS ${path}`;\n\n\t\t\t\tnewRoutes[corsRouteKey] = async function() {\n\t\t\t\t\treturn({\n\t\t\t\t\t\toutput: '',\n\t\t\t\t\t\tstatusCode: 204,\n\t\t\t\t\t\tcontentType: 'text/plain',\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t'Access-Control-Allow-Origin': '*',\n\t\t\t\t\t\t\t'Access-Control-Allow-Methods': validMethodsForPathParts.join(', '),\n\t\t\t\t\t\t\t'Access-Control-Allow-Headers': 'Content-Type',\n\t\t\t\t\t\t\t'Access-Control-Max-Age': '86400'\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t};\n\t\t\t\tseenPaths.add(path);\n\t\t\t}\n\t\t}\n\n\t\treturn(newRoutes);\n\t}\n\n\tprivate async main(onSetPort?: (port: number) => void): Promise<void> {\n\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Starting HTTP server...');\n\n\t\tconst port = this.port;\n\n\t\tconst routes = KeetaNetAnchorHTTPServer.addCORS({\n\t\t\tERROR: async function(_ignore_params, postData) {\n\t\t\t\tconst errorInfo = AssertHTTPErrorData(postData);\n\n\t\t\t\tconst retval = {\n\t\t\t\t\toutput: errorInfo.error,\n\t\t\t\t\tstatusCode: errorInfo.statusCode ?? 400,\n\t\t\t\t\tcontentType: errorInfo.contentType ?? 'text/plain'\n\t\t\t\t};\n\n\t\t\t\treturn(retval);\n\t\t\t},\n\t\t\t...(await this.initRoutes(this.#config))\n\t\t});\n\n\t\tconst server = new http.Server(async (request, response) => {\n\t\t\tconst url = new URL(request.url ?? '/', `http://${request.headers.host ?? 'localhost'}`);\n\t\t\tconst method = request.method ?? 'GET';\n\n\t\t\t/*\n\t\t\t * Lookup the route based on the request\n\t\t\t */\n\t\t\tconst requestedRouteAndParams = KeetaNetAnchorHTTPServer.routeFind(method, url, routes);\n\t\t\tif (requestedRouteAndParams === null) {\n\t\t\t\tresponse.statusCode = 404;\n\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\tresponse.write('Not Found');\n\t\t\t\tresponse.end();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Extract the route handler and the parameters from\n\t\t\t * the request\n\t\t\t */\n\t\t\tconst { route, params } = requestedRouteAndParams;\n\n\t\t\t/**\n\t\t\t * Attempt to run the route, catch any errors\n\t\t\t */\n\t\t\tlet result: Awaited<ReturnType<typeof route>> | undefined = undefined;\n\t\t\tlet generatedResult = false;\n\t\t\ttry {\n\t\t\t\t/**\n\t\t\t\t * If POST'ing, read and parse the POST data\n\t\t\t\t */\n\t\t\t\tlet postData: JSONSerializable | undefined;\n\t\t\t\tif (request.method === 'POST') {\n\t\t\t\t\tconst data = await request.map(function(chunk) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\t\t\t\treturn(Buffer.from(chunk));\n\t\t\t\t\t}).reduce(function(prev, curr) {\n\t\t\t\t\t\tif (prev.length > MAX_REQUEST_SIZE) {\n\t\t\t\t\t\t\tthrow(new Error('Request too large'));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!Buffer.isBuffer(curr)) {\n\t\t\t\t\t\t\tthrow(new Error(`internal error: Current item is not a buffer -- ${typeof curr}`));\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn(Buffer.concat([prev, curr]));\n\t\t\t\t\t}, Buffer.from(''));\n\n\t\t\t\t\tif (request.headers['content-type'] === 'application/json') {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\t\t\t\tpostData = JSON.parse(data.toString('utf-8'));\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tthrow(new Error('Invalid JSON data'));\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Unsupported content type'));\n\t\t\t\t\t}\n\t\t\t\t\t/**\n\t\t\t\t\t * Call the route handler\n\t\t\t\t\t */\n\t\t\t\t\tresult = await route(params, postData, request.headers);\n\t\t\t\t} else {\n\t\t\t\t\tresult = await route(params, undefined, request.headers);\n\t\t\t\t}\n\n\t\t\t\tgeneratedResult = true;\n\t\t\t} catch (err) {\n\t\t\t\t/**\n\t\t\t\t * If an error occurs, log it and return an error page\n\t\t\t\t */\n\t\t\t\tthis.logger?.error('KeetaAnchorHTTP.Server', err);\n\n\t\t\t\t/**\n\t\t\t\t * If it is a user error, provide a user-friendly error page\n\t\t\t\t */\n\t\t\t\tconst errorHandlerRoute = routes['ERROR'];\n\t\t\t\tif (errorHandlerRoute !== undefined) {\n\t\t\t\t\tif (KeetaAnchorUserError.isInstance(err)) {\n\t\t\t\t\t\tresult = await errorHandlerRoute(new Map(), err.asErrorResponse('application/json'), request.headers);\n\t\t\t\t\t\tgeneratedResult = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult = await errorHandlerRoute(new Map(), {\n\t\t\t\t\t\t\terror: JSON.stringify({ ok: false, error: 'Internal Server Error' }),\n\t\t\t\t\t\t\tstatusCode: 500,\n\t\t\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t\t\t}, request.headers);\n\t\t\t\t\t\tgeneratedResult = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!generatedResult) {\n\t\t\t\t\t/**\n\t\t\t\t\t * Otherwise provide a generic error page\n\t\t\t\t\t */\n\t\t\t\t\tresponse.statusCode = 500;\n\t\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\t\tresponse.write('Internal Server Error');\n\t\t\t\t\tresponse.end();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (result === undefined) {\n\t\t\t\tthrow(new Error('internal error: No result'));\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Write the response to the client\n\t\t\t */\n\t\t\tresponse.statusCode = result.statusCode ?? 200;\n\n\t\t\tfor (const headerKey in result.headers ?? {}) {\n\t\t\t\tconst headerValue = result.headers?.[headerKey];\n\t\t\t\tif (headerValue !== undefined) {\n\t\t\t\t\tresponse.setHeader(headerKey, headerValue);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresponse.setHeader('Content-Type', result.contentType ?? 'application/json');\n\t\t\tresponse.write(result.output);\n\t\t\tresponse.end();\n\t\t});\n\t\tthis.#server = server;\n\n\t\t/**\n\t\t * Create a promise to wait for the server to close\n\t\t */\n\t\tconst waiter = new Promise<void>((resolve) => {\n\t\t\tserver.on('close', () => {\n\t\t\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Server closed');\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\n\t\t/**\n\t\t * Start listening on the port\n\t\t */\n\t\tserver.listen(port, () => {\n\t\t\tconst address = server.address();\n\t\t\tif (address !== null && typeof address === 'object') {\n\t\t\t\t// @ts-ignore\n\t\t\t\tthis.port = address.port;\n\t\t\t\tonSetPort?.(this.port);\n\t\t\t}\n\t\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Listening on port:', this.port);\n\t\t});\n\n\t\t/**\n\t\t * Wait for the server to close\n\t\t */\n\t\tawait waiter;\n\t}\n\n\t/**\n\t * Start the HTTP server and wait for it to be fully initialized.\n\t */\n\tasync start(): Promise<void> {\n\t\t/*\n\t\t * Start the server and wait for it to be initialized before returning\n\t\t */\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.#serverPromise = this.main(function() {\n\t\t\t\tresolve();\n\t\t\t}).catch(function(error: unknown) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n\t\t\t\treject(error);\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Wait for the server to terminate. This will only resolve once the\n\t * server has been stopped.\n\t */\n\tasync wait(): Promise<void> {\n\t\tawait this.#serverPromise;\n\t}\n\n\t/**\n\t * Stop the HTTP server and wait for it to be fully terminated.\n\t */\n\tasync stop(): Promise<void> {\n\t\tthis.#server?.close();\n\t\t// @ts-ignore\n\t\tthis.#server = undefined;\n\t\tawait this.wait();\n\t}\n\n\t/**\n\t * Get the URL of the server, which can be used to make requests to\n\t * it. This will use \"localhost\" as the hostname and the port that\n\t * the server is listening on.\n\t */\n\tget url(): string {\n\t\tif (this.port === 0 || this.#server === undefined) {\n\t\t\tthrow(new Error('Server not started'));\n\t\t}\n\n\t\treturn(`http://localhost:${this.port}`);\n\t}\n\n\t[Symbol.asyncDispose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,IAAI,CAAC,cAAc,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACT,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QACtB,aAAa;QACb,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,IAAI,GAAG;QACN,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACnD,MAAK,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC;QACxC,CAAC;QAED,OAAM,CAAC,oBAAoB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,CAAC,MAAM,CAAC,YAAY,CAAC;QACpB,OAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACrB,CAAC;CACD","sourcesContent":["import * as http from 'http';\nimport {\n\tKeetaAnchorUserError\n} from './error.js';\nimport type { JSONSerializable } from './utils/json.js';\nimport type { Logger } from './log/index.js';\nimport { Log } from './log/index.js';\nimport { createAssert } from 'typia';\n\nexport const AssertHTTPErrorData: (input: unknown) => { error: string; statusCode?: number; contentType?: string; } = createAssert<{ error: string; statusCode?: number; contentType?: string; }>();\n\n/**\n * The maximum size of a request (128KiB)\n */\nconst MAX_REQUEST_SIZE = 1024 * 128;\n\nexport type Routes = {\n\t[route: string]: (urlParams: Map<string, string>, postData: JSONSerializable | undefined, requestHeaders: http.IncomingHttpHeaders) => Promise<{ output: string; statusCode?: number; contentType?: string; headers?: { [headerName: string]: string; }; }>;\n};\n\nexport interface KeetaAnchorHTTPServerConfig {\n\t/**\n\t * The port for the HTTP server to listen on (default is an ephemeral port).\n\t */\n\tport?: number;\n\n\t/**\n\t * Enable debug logging\n\t */\n\tlogger?: Logger;\n};\n\nexport abstract class KeetaNetAnchorHTTPServer<ConfigType extends KeetaAnchorHTTPServerConfig = KeetaAnchorHTTPServerConfig> implements Required<KeetaAnchorHTTPServerConfig> {\n\treadonly port: NonNullable<KeetaAnchorHTTPServerConfig['port']>;\n\treadonly logger: NonNullable<KeetaAnchorHTTPServerConfig['logger']>;\n\t#serverPromise?: Promise<void>;\n\t#server?: http.Server;\n\treadonly #config: ConfigType;\n\n\tconstructor(config: ConfigType) {\n\t\tthis.#config = { ...config };\n\t\tthis.port = config.port ?? 0;\n\t\tthis.logger = config.logger ?? Log.Legacy('ANCHOR');\n\t}\n\n\tprotected abstract initRoutes(config: ConfigType): Promise<Routes>;\n\n\tprivate static routeMatch(requestURL: URL, routeURL: URL): ({ match: true; params: Map<string, string> } | { match: false }) {\n\t\tconst requestURLPaths = requestURL.pathname.split('/');\n\t\tconst routeURLPaths = routeURL.pathname.split('/');\n\n\t\tif (requestURLPaths.length !== routeURLPaths.length) {\n\t\t\treturn({ match: false });\n\t\t}\n\n\t\tconst params = new Map<string, string>();\n\t\tfor (let partIndex = 0; partIndex < requestURLPaths.length; partIndex++) {\n\t\t\tconst requestPath = requestURLPaths[partIndex];\n\t\t\tconst routePath = routeURLPaths[partIndex];\n\n\t\t\tif (routePath === undefined || requestPath === undefined) {\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\n\t\t\tif (routePath.startsWith(':')) {\n\t\t\t\tparams.set(routePath.slice(1), requestPath);\n\t\t\t} else if (requestPath !== routePath) {\n\t\t\t\treturn({ match: false });\n\t\t\t}\n\t\t}\n\n\t\treturn({ match: true, params: params });\n\t}\n\n\tprivate static routeFind(method: string, requestURL: URL, routes: Routes): { route: Routes[keyof Routes]; params: Map<string, string> } | null {\n\t\tfor (const routeKey in routes) {\n\t\t\tconst route = routes[routeKey];\n\t\t\tif (route === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst [routeMethod, ...routePathParts] = routeKey.split(' ');\n\t\t\tconst routePath = `/${routePathParts.join(' ')}`.replace(/^\\/+/, '/');\n\n\t\t\tif (method !== routeMethod) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst routeURL = new URL(routePath, 'http://localhost');\n\t\t\tconst matchResult = this.routeMatch(requestURL, routeURL);\n\t\t\tif (matchResult.match) {\n\t\t\t\treturn({\n\t\t\t\t\troute: route,\n\t\t\t\t\tparams: matchResult.params\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn(null);\n\t}\n\n\tprivate static addCORS(routes: Routes): Routes {\n\t\tconst newRoutes: Routes = {};\n\n\t\tconst validMethods = new Set(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']);\n\n\t\tconst methodsByPath: { [key: string]: Set<string>; } = {};\n\t\tfor (const routeKey in routes) {\n\t\t\tconst methodAndPath = routeKey.split(' ');\n\t\t\tconst method = methodAndPath[0];\n\t\t\tconst path = methodAndPath.slice(1).join(' ');\n\n\t\t\tif (method === undefined || path === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!validMethods.has(method)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!(path in methodsByPath)) {\n\t\t\t\tmethodsByPath[path] = new Set<string>();\n\t\t\t}\n\n\t\t\tif (methodsByPath[path] === undefined) {\n\t\t\t\tthrow(new Error(`internal error: methodsByPath missing path for ${path}`));\n\t\t\t}\n\n\t\t\tmethodsByPath[path].add(method);\n\t\t}\n\n\t\tconst seenPaths = new Set<string>();\n\t\tfor (const routeKey in routes) {\n\t\t\tconst methodAndPath = routeKey.split(' ');\n\t\t\tconst method = methodAndPath[0];\n\t\t\tconst path = methodAndPath.slice(1).join(' ');\n\n\t\t\tconst routeHandler = routes[routeKey];\n\t\t\tif (routeHandler === undefined) {\n\t\t\t\tthrow(new Error(`internal error: routeHandler missing for routeKey ${routeKey}`));\n\t\t\t}\n\n\t\t\tif (method !== 'ERROR') {\n\t\t\t\tif (method === undefined || path === undefined) {\n\t\t\t\t\tnewRoutes[routeKey] = routeHandler;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (!validMethods.has(method)) {\n\t\t\t\t\tnewRoutes[routeKey] = routeHandler;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst validMethodsForPath = methodsByPath[path];\n\n\t\t\tlet validMethodsForPathParts: string[] = [];\n\t\t\tif (validMethodsForPath !== undefined) {\n\t\t\t\tvalidMethodsForPath.add('OPTIONS');\n\t\t\t\tvalidMethodsForPathParts = Array.from(validMethodsForPath);\n\t\t\t} else {\n\t\t\t\tvalidMethodsForPathParts = [...Array.from(validMethods), 'OPTIONS'];\n\t\t\t}\n\n\t\t\tnewRoutes[routeKey] = async function(...args: Parameters<typeof routes[keyof typeof routes]>) {\n\t\t\t\tconst retval = await routeHandler(...args);\n\n\t\t\t\t/* Add CORS headers to the response for the original route handler */\n\t\t\t\tif (retval.contentType === 'application/json' || retval.contentType === undefined) {\n\t\t\t\t\tif (!('headers' in retval) || retval.headers === undefined) {\n\t\t\t\t\t\tretval.headers = {};\n\t\t\t\t\t}\n\t\t\t\t\tretval.headers['Access-Control-Allow-Origin'] = '*';\n\t\t\t\t}\n\n\t\t\t\treturn(retval);\n\t\t\t};\n\n\t\t\tif (!seenPaths.has(path) && path !== '' && path !== undefined) {\n\t\t\t\tconst corsRouteKey = `OPTIONS ${path}`;\n\n\t\t\t\tnewRoutes[corsRouteKey] = async function() {\n\t\t\t\t\treturn({\n\t\t\t\t\t\toutput: '',\n\t\t\t\t\t\tstatusCode: 204,\n\t\t\t\t\t\tcontentType: 'text/plain',\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t'Access-Control-Allow-Origin': '*',\n\t\t\t\t\t\t\t'Access-Control-Allow-Methods': validMethodsForPathParts.join(', '),\n\t\t\t\t\t\t\t'Access-Control-Allow-Headers': 'Content-Type',\n\t\t\t\t\t\t\t'Access-Control-Max-Age': '86400'\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t};\n\t\t\t\tseenPaths.add(path);\n\t\t\t}\n\t\t}\n\n\t\treturn(newRoutes);\n\t}\n\n\tprivate async main(onSetPort?: (port: number) => void): Promise<void> {\n\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Starting HTTP server...');\n\n\t\tconst port = this.port;\n\n\t\tconst routes = KeetaNetAnchorHTTPServer.addCORS({\n\t\t\tERROR: async function(_ignore_params, postData) {\n\t\t\t\tconst errorInfo = AssertHTTPErrorData(postData);\n\n\t\t\t\tconst retval = {\n\t\t\t\t\toutput: errorInfo.error,\n\t\t\t\t\tstatusCode: errorInfo.statusCode ?? 400,\n\t\t\t\t\tcontentType: errorInfo.contentType ?? 'text/plain'\n\t\t\t\t};\n\n\t\t\t\treturn(retval);\n\t\t\t},\n\t\t\t...(await this.initRoutes(this.#config))\n\t\t});\n\n\t\tconst server = new http.Server(async (request, response) => {\n\t\t\tconst url = new URL(request.url ?? '/', `http://${request.headers.host ?? 'localhost'}`);\n\t\t\tconst method = request.method ?? 'GET';\n\n\t\t\t/*\n\t\t\t * Lookup the route based on the request\n\t\t\t */\n\t\t\tconst requestedRouteAndParams = KeetaNetAnchorHTTPServer.routeFind(method, url, routes);\n\t\t\tif (requestedRouteAndParams === null) {\n\t\t\t\tresponse.statusCode = 404;\n\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\tresponse.write('Not Found');\n\t\t\t\tresponse.end();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Extract the route handler and the parameters from\n\t\t\t * the request\n\t\t\t */\n\t\t\tconst { route, params } = requestedRouteAndParams;\n\n\t\t\t/**\n\t\t\t * Attempt to run the route, catch any errors\n\t\t\t */\n\t\t\tlet result: Awaited<ReturnType<typeof route>> | undefined = undefined;\n\t\t\tlet generatedResult = false;\n\t\t\ttry {\n\t\t\t\t/**\n\t\t\t\t * If POST'ing, read and parse the POST data\n\t\t\t\t */\n\t\t\t\tlet postData: JSONSerializable | undefined;\n\t\t\t\tif (request.method === 'POST') {\n\t\t\t\t\tconst data = await request.map(function(chunk) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\t\t\t\treturn(Buffer.from(chunk));\n\t\t\t\t\t}).reduce(function(prev, curr) {\n\t\t\t\t\t\tif (prev.length > MAX_REQUEST_SIZE) {\n\t\t\t\t\t\t\tthrow(new Error('Request too large'));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!Buffer.isBuffer(curr)) {\n\t\t\t\t\t\t\tthrow(new Error(`internal error: Current item is not a buffer -- ${typeof curr}`));\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn(Buffer.concat([prev, curr]));\n\t\t\t\t\t}, Buffer.from(''));\n\n\t\t\t\t\tif (request.headers['content-type'] === 'application/json') {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\t\t\t\tpostData = JSON.parse(data.toString('utf-8'));\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tthrow(new Error('Invalid JSON data'));\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow(new KeetaAnchorUserError('Unsupported content type'));\n\t\t\t\t\t}\n\t\t\t\t\t/**\n\t\t\t\t\t * Call the route handler\n\t\t\t\t\t */\n\t\t\t\t\tresult = await route(params, postData, request.headers);\n\t\t\t\t} else {\n\t\t\t\t\tresult = await route(params, undefined, request.headers);\n\t\t\t\t}\n\n\t\t\t\tgeneratedResult = true;\n\t\t\t} catch (err) {\n\t\t\t\t/**\n\t\t\t\t * If an error occurs, log it and return an error page\n\t\t\t\t */\n\t\t\t\tthis.logger?.error('KeetaAnchorHTTP.Server', err);\n\n\t\t\t\t/**\n\t\t\t\t * If it is a user error, provide a user-friendly error page\n\t\t\t\t */\n\t\t\t\tconst errorHandlerRoute = routes['ERROR'];\n\t\t\t\tif (errorHandlerRoute !== undefined) {\n\t\t\t\t\tif (KeetaAnchorUserError.isInstance(err)) {\n\t\t\t\t\t\tresult = await errorHandlerRoute(new Map(), err.asErrorResponse('application/json'), request.headers);\n\t\t\t\t\t\tgeneratedResult = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult = await errorHandlerRoute(new Map(), {\n\t\t\t\t\t\t\terror: JSON.stringify({ ok: false, error: 'Internal Server Error' }),\n\t\t\t\t\t\t\tstatusCode: 500,\n\t\t\t\t\t\t\tcontentType: 'application/json'\n\t\t\t\t\t\t}, request.headers);\n\t\t\t\t\t\tgeneratedResult = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!generatedResult) {\n\t\t\t\t\t/**\n\t\t\t\t\t * Otherwise provide a generic error page\n\t\t\t\t\t */\n\t\t\t\t\tresponse.statusCode = 500;\n\t\t\t\t\tresponse.setHeader('Content-Type', 'text/plain');\n\t\t\t\t\tresponse.write('Internal Server Error');\n\t\t\t\t\tresponse.end();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (result === undefined) {\n\t\t\t\tthrow(new Error('internal error: No result'));\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Write the response to the client\n\t\t\t */\n\t\t\tresponse.statusCode = result.statusCode ?? 200;\n\n\t\t\tfor (const headerKey in result.headers ?? {}) {\n\t\t\t\tconst headerValue = result.headers?.[headerKey];\n\t\t\t\tif (headerValue !== undefined) {\n\t\t\t\t\tresponse.setHeader(headerKey, headerValue);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresponse.setHeader('Content-Type', result.contentType ?? 'application/json');\n\t\t\tresponse.write(result.output);\n\t\t\tresponse.end();\n\t\t});\n\t\tthis.#server = server;\n\n\t\t/**\n\t\t * Create a promise to wait for the server to close\n\t\t */\n\t\tconst waiter = new Promise<void>((resolve) => {\n\t\t\tserver.on('close', () => {\n\t\t\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Server closed');\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\n\t\t/**\n\t\t * Start listening on the port\n\t\t */\n\t\tserver.listen(port, () => {\n\t\t\tconst address = server.address();\n\t\t\tif (address !== null && typeof address === 'object') {\n\t\t\t\t// @ts-ignore\n\t\t\t\tthis.port = address.port;\n\t\t\t\tonSetPort?.(this.port);\n\t\t\t}\n\t\t\tthis.logger?.debug('KeetaAnchorHTTP.Server', 'Listening on port:', this.port);\n\t\t});\n\n\t\t/**\n\t\t * Wait for the server to close\n\t\t */\n\t\tawait waiter;\n\t}\n\n\t/**\n\t * Start the HTTP server and wait for it to be fully initialized.\n\t */\n\tasync start(): Promise<void> {\n\t\t/*\n\t\t * Start the server and wait for it to be initialized before returning\n\t\t */\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.#serverPromise = this.main(function() {\n\t\t\t\tresolve();\n\t\t\t}).catch(function(error: unknown) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n\t\t\t\treject(error);\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Wait for the server to terminate. This will only resolve once the\n\t * server has been stopped.\n\t */\n\tasync wait(): Promise<void> {\n\t\tawait this.#serverPromise;\n\t}\n\n\t/**\n\t * Stop the HTTP server and wait for it to be fully terminated.\n\t */\n\tasync stop(): Promise<void> {\n\t\tthis.#server?.close();\n\t\t// @ts-ignore\n\t\tthis.#server = undefined;\n\t\tawait this.wait();\n\t}\n\n\t/**\n\t * Get the URL of the server, which can be used to make requests to\n\t * it. This will use \"localhost\" as the hostname and the port that\n\t * the server is listening on.\n\t */\n\tget url(): string {\n\t\tif (this.port === 0 || this.#server === undefined) {\n\t\t\tthrow(new Error('Server not started'));\n\t\t}\n\n\t\treturn(`http://localhost:${this.port}`);\n\t}\n\n\t[Symbol.asyncDispose](): Promise<void> {\n\t\treturn(this.stop());\n\t}\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Certificates from './certificates.js';
|
|
2
2
|
import { EncryptedContainer } from './encrypted-container.js';
|
|
3
|
+
import * as URI from './uri.js';
|
|
3
4
|
import Resolver from './resolver.js';
|
|
4
|
-
export { Certificates, EncryptedContainer, Resolver };
|
|
5
|
+
export { Certificates, EncryptedContainer, Resolver, URI };
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,GAAG,EACH,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Certificates from './certificates.js';
|
|
2
2
|
import { EncryptedContainer } from './encrypted-container.js';
|
|
3
|
+
import * as URI from './uri.js';
|
|
3
4
|
import Resolver from './resolver.js';
|
|
4
|
-
export { Certificates, EncryptedContainer, Resolver };
|
|
5
|
+
export { Certificates, EncryptedContainer, Resolver, URI };
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,GAAG,EACH,CAAA","sourcesContent":["import * as Certificates from './certificates.js';\nimport { EncryptedContainer } from './encrypted-container.js';\nimport * as URI from './uri.js';\n\nimport Resolver from './resolver.js';\nexport {\n\tCertificates,\n\tEncryptedContainer,\n\tResolver,\n\tURI\n}\n"]}
|
package/lib/log/index.d.ts
CHANGED
|
@@ -1,59 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
export type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Whether to generate debug tracing information for each log entry
|
|
9
|
-
*/
|
|
10
|
-
logDebugTracing?: boolean;
|
|
11
|
-
};
|
|
12
|
-
type LogOptionsParam = LogEntry['options'];
|
|
13
|
-
type LogTargetID = symbol & {
|
|
14
|
-
_branded: 'LogTargetID';
|
|
15
|
-
};
|
|
16
|
-
export declare class Log implements Logger {
|
|
17
|
-
#private;
|
|
18
|
-
/**
|
|
19
|
-
* The default log level, used for new instances of the logger
|
|
20
|
-
*/
|
|
21
|
-
static readonly defaultLevel: LogTargetLevel;
|
|
22
|
-
constructor(options?: LogOptions);
|
|
23
|
-
log(options: LogOptionsParam, from: string, ...args: unknown[]): void;
|
|
24
|
-
log(from: string, ...args: unknown[]): void;
|
|
25
|
-
info(options: LogOptionsParam, from: string, ...args: unknown[]): void;
|
|
26
|
-
info(from: string, ...args: unknown[]): void;
|
|
27
|
-
debug(options: LogOptionsParam, from: string, ...args: unknown[]): void;
|
|
28
|
-
debug(from: string, ...args: unknown[]): void;
|
|
29
|
-
warn(options: LogOptionsParam, from: string, ...args: unknown[]): void;
|
|
30
|
-
warn(from: string, ...args: unknown[]): void;
|
|
31
|
-
error(options: LogOptionsParam, from: string, ...args: unknown[]): void;
|
|
32
|
-
error(from: string, ...args: unknown[]): void;
|
|
33
|
-
/**
|
|
34
|
-
* Register a new logging target (sink) to send logs to
|
|
35
|
-
*/
|
|
36
|
-
registerTarget(target: LogTarget): LogTargetID;
|
|
37
|
-
/**
|
|
38
|
-
* Unregister a logging target (sink) to stop sending logs to
|
|
39
|
-
*/
|
|
40
|
-
unregisterTarget(id: LogTargetID): void;
|
|
41
|
-
/**
|
|
42
|
-
* Emit a set of logs to all registered targets
|
|
43
|
-
*/
|
|
44
|
-
private emitLogs;
|
|
45
|
-
/**
|
|
46
|
-
* Start a timer to periodically sync logs to all targets
|
|
47
|
-
*/
|
|
48
|
-
startAutoSync(rate?: number): void;
|
|
49
|
-
/**
|
|
50
|
-
* If a timer was started with `startAutoSync()`, stop it
|
|
51
|
-
*/
|
|
52
|
-
stopAutoSync(): void;
|
|
53
|
-
/**
|
|
54
|
-
* Sync all currently enqueued logs to all targets
|
|
55
|
-
*/
|
|
56
|
-
sync(): Promise<void>;
|
|
57
|
-
}
|
|
1
|
+
import { lib } from '@keetanetwork/keetanet-client';
|
|
2
|
+
export type * from '@keetanetwork/keetanet-client/lib/log/index.js';
|
|
3
|
+
declare const Log: typeof lib.Log;
|
|
4
|
+
declare const LegacyLog: typeof Log.Legacy;
|
|
5
|
+
declare const NullLog: typeof Log.Null;
|
|
6
|
+
export { Log, LegacyLog, NullLog };
|
|
58
7
|
export default Log;
|
|
59
8
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/log/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/log/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/log/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACpD,mBAAmB,gDAAgD,CAAC;AAEpE,QAAA,MAAM,GAAG,EAAE,OAAO,GAAG,CAAC,GAAa,CAAC;AACpC,QAAA,MAAM,SAAS,EAAE,OAAO,GAAG,CAAC,MAA6B,CAAC;AAC1D,QAAA,MAAM,OAAO,EAAE,OAAO,GAAG,CAAC,IAAyB,CAAC;AAEpD,OAAO,EACN,GAAG,EACH,SAAS,EACT,OAAO,EACP,CAAC;AACF,eAAe,GAAG,CAAC"}
|
package/lib/log/index.js
CHANGED
|
@@ -1,207 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
const MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS = 131072;
|
|
8
|
-
const assertLogOptionsParam = (() => { const _io0 = input => (undefined === input.userVisible || "boolean" === typeof input.userVisible) && (undefined === input.currentRequestInfo || "object" === typeof input.currentRequestInfo && null !== input.currentRequestInfo && _io1(input.currentRequestInfo)); const _io1 = input => "string" === typeof input.id; const _ao0 = (input, _path, _exceptionable = true) => (undefined === input.userVisible || "boolean" === typeof input.userVisible || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
9
|
-
method: "createAssert",
|
|
10
|
-
path: _path + ".userVisible",
|
|
11
|
-
expected: "(boolean | undefined)",
|
|
12
|
-
value: input.userVisible
|
|
13
|
-
}, _errorFactory)) && (undefined === input.currentRequestInfo || ("object" === typeof input.currentRequestInfo && null !== input.currentRequestInfo || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
14
|
-
method: "createAssert",
|
|
15
|
-
path: _path + ".currentRequestInfo",
|
|
16
|
-
expected: "(LogCurrentRequest | undefined)",
|
|
17
|
-
value: input.currentRequestInfo
|
|
18
|
-
}, _errorFactory)) && _ao1(input.currentRequestInfo, _path + ".currentRequestInfo", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
19
|
-
method: "createAssert",
|
|
20
|
-
path: _path + ".currentRequestInfo",
|
|
21
|
-
expected: "(LogCurrentRequest | undefined)",
|
|
22
|
-
value: input.currentRequestInfo
|
|
23
|
-
}, _errorFactory)); const _ao1 = (input, _path, _exceptionable = true) => "string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
24
|
-
method: "createAssert",
|
|
25
|
-
path: _path + ".id",
|
|
26
|
-
expected: "string",
|
|
27
|
-
value: input.id
|
|
28
|
-
}, _errorFactory); const __is = input => "object" === typeof input && null !== input && false === Array.isArray(input) && _io0(input); let _errorFactory; return (input, errorFactory) => {
|
|
29
|
-
if (false === __is(input)) {
|
|
30
|
-
_errorFactory = errorFactory;
|
|
31
|
-
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input && false === Array.isArray(input) || __typia_transform__assertGuard._assertGuard(true, {
|
|
32
|
-
method: "createAssert",
|
|
33
|
-
path: _path + "",
|
|
34
|
-
expected: "__type",
|
|
35
|
-
value: input
|
|
36
|
-
}, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
37
|
-
method: "createAssert",
|
|
38
|
-
path: _path + "",
|
|
39
|
-
expected: "__type",
|
|
40
|
-
value: input
|
|
41
|
-
}, _errorFactory))(input, "$input", true);
|
|
42
|
-
}
|
|
43
|
-
return input;
|
|
44
|
-
}; })();
|
|
45
|
-
export class Log {
|
|
46
|
-
/**
|
|
47
|
-
* The default log level, used for new instances of the logger
|
|
48
|
-
*/
|
|
49
|
-
static defaultLevel = 'DEBUG';
|
|
50
|
-
/**
|
|
51
|
-
* Queued logs to be sent
|
|
52
|
-
*/
|
|
53
|
-
#logs = [];
|
|
54
|
-
/**
|
|
55
|
-
* Interval holding the current autoSync process
|
|
56
|
-
*/
|
|
57
|
-
#autoSyncInterval = undefined;
|
|
58
|
-
/**
|
|
59
|
-
* Keep track of whether or not we are currently syncing
|
|
60
|
-
*/
|
|
61
|
-
#isSyncing = false;
|
|
62
|
-
/**
|
|
63
|
-
* If `sync()` is called while we are syncing, we should sync again
|
|
64
|
-
* to ensure all logs are sent
|
|
65
|
-
*/
|
|
66
|
-
#shouldSyncAgain = false;
|
|
67
|
-
#logDebugTracing = false;
|
|
68
|
-
#targets = new Map();
|
|
69
|
-
constructor(options) {
|
|
70
|
-
if (options?.logDebugTracing !== undefined) {
|
|
71
|
-
this.#logDebugTracing = options.logDebugTracing;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
#log(level, options, from, ...args) {
|
|
75
|
-
const log = { options, level, from, args };
|
|
76
|
-
if (this.#logDebugTracing) {
|
|
77
|
-
log.trace = new Error().stack?.split('\n').slice(2).join('\n') ?? '[No stack trace available]';
|
|
78
|
-
}
|
|
79
|
-
this.#logs.push(log);
|
|
80
|
-
}
|
|
81
|
-
#extractArguments(args) {
|
|
82
|
-
const options = assertLogOptionsParam((args[0] instanceof Object ? args.shift() : {}));
|
|
83
|
-
const from = args.shift();
|
|
84
|
-
if (typeof from !== 'string') {
|
|
85
|
-
throw (new Error(`Expected string for 'from', got ${typeof from}`));
|
|
86
|
-
}
|
|
87
|
-
return ({ options, from });
|
|
88
|
-
}
|
|
89
|
-
log(...args) {
|
|
90
|
-
const { options, from } = this.#extractArguments(args);
|
|
91
|
-
this.#log('INFO', options, from, ...args);
|
|
92
|
-
}
|
|
93
|
-
info(...args) {
|
|
94
|
-
const { options, from } = this.#extractArguments(args);
|
|
95
|
-
this.#log('INFO', options, from, ...args);
|
|
96
|
-
}
|
|
97
|
-
debug(...args) {
|
|
98
|
-
const { options, from } = this.#extractArguments(args);
|
|
99
|
-
this.#log('DEBUG', options, from, ...args);
|
|
100
|
-
}
|
|
101
|
-
warn(...args) {
|
|
102
|
-
const { options, from } = this.#extractArguments(args);
|
|
103
|
-
this.#log('WARN', options, from, ...args);
|
|
104
|
-
}
|
|
105
|
-
error(...args) {
|
|
106
|
-
const { options, from } = this.#extractArguments(args);
|
|
107
|
-
this.#log('ERROR', options, from, ...args);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Register a new logging target (sink) to send logs to
|
|
111
|
-
*/
|
|
112
|
-
registerTarget(target) {
|
|
113
|
-
const id = Symbol('LogTargetID');
|
|
114
|
-
this.#targets.set(id, target);
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
116
|
-
return id;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Unregister a logging target (sink) to stop sending logs to
|
|
120
|
-
*/
|
|
121
|
-
unregisterTarget(id) {
|
|
122
|
-
this.#targets.delete(id);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Emit a set of logs to all registered targets
|
|
126
|
-
*/
|
|
127
|
-
async emitLogs(logs, targets) {
|
|
128
|
-
await Promise.allSettled(targets.map(async function (target) {
|
|
129
|
-
await target.emitLogs(logs);
|
|
130
|
-
}));
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Start a timer to periodically sync logs to all targets
|
|
134
|
-
*/
|
|
135
|
-
startAutoSync(rate = 100) {
|
|
136
|
-
if (this.#autoSyncInterval) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
this.#autoSyncInterval = setInterval(async () => {
|
|
140
|
-
try {
|
|
141
|
-
await this.sync();
|
|
142
|
-
}
|
|
143
|
-
catch {
|
|
144
|
-
/* Ignored */
|
|
145
|
-
}
|
|
146
|
-
}, rate);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* If a timer was started with `startAutoSync()`, stop it
|
|
150
|
-
*/
|
|
151
|
-
stopAutoSync() {
|
|
152
|
-
if (!this.#autoSyncInterval) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
clearInterval(this.#autoSyncInterval);
|
|
156
|
-
this.#autoSyncInterval = undefined;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Sync all currently enqueued logs to all targets
|
|
160
|
-
*/
|
|
161
|
-
async sync() {
|
|
162
|
-
/*
|
|
163
|
-
* If there are currently no targets, do not dequeue logs
|
|
164
|
-
* in case a target is added later; However, if there are
|
|
165
|
-
* too many logs, drop the oldest ones
|
|
166
|
-
*/
|
|
167
|
-
if (this.#targets.size === 0) {
|
|
168
|
-
if (this.#logs.length > MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS) {
|
|
169
|
-
this.#logs.splice(0, this.#logs.length - MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS);
|
|
170
|
-
}
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
/*
|
|
174
|
-
* If we are already syncing, set a flag to sync again after the current sync is done
|
|
175
|
-
*/
|
|
176
|
-
if (this.#isSyncing) {
|
|
177
|
-
this.#shouldSyncAgain = true;
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
this.#isSyncing = true;
|
|
181
|
-
/*
|
|
182
|
-
* Create a copy of the currently registered targets in case
|
|
183
|
-
* they are modified while a sync is on-going, we use the
|
|
184
|
-
* same targets until the sync is complete
|
|
185
|
-
*
|
|
186
|
-
* This ensures no messages are lost if all targets are removed
|
|
187
|
-
* while a sync is in progress -- they will continue to be sent
|
|
188
|
-
* to the registered targets at the time of the sync
|
|
189
|
-
*/
|
|
190
|
-
const targets = Array.from(this.#targets.values());
|
|
191
|
-
do {
|
|
192
|
-
try {
|
|
193
|
-
while (this.#logs.length > 0) {
|
|
194
|
-
this.#shouldSyncAgain = false;
|
|
195
|
-
const logs = this.#logs.splice(0, 10);
|
|
196
|
-
await this.emitLogs(logs, targets);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
catch {
|
|
200
|
-
/* Ignore errors */
|
|
201
|
-
}
|
|
202
|
-
} while (this.#shouldSyncAgain);
|
|
203
|
-
this.#isSyncing = false;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
1
|
+
import { lib } from '@keetanetwork/keetanet-client';
|
|
2
|
+
const Log = lib.Log;
|
|
3
|
+
const LegacyLog = Log.Legacy.bind(Log);
|
|
4
|
+
const NullLog = Log.Null.bind(Log);
|
|
5
|
+
export { Log, LegacyLog, NullLog };
|
|
206
6
|
export default Log;
|
|
207
7
|
//# sourceMappingURL=index.js.map
|
package/lib/log/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/log/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAGrC;;;GAGG;AACH,MAAM,mCAAmC,GAAG,MAAM,CAAC;AAanD,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAkC,CAAC;AAI9D,MAAM,OAAO,GAAG;IACf;;OAEG;IACH,MAAM,CAAU,YAAY,GAAmB,OAAO,CAAC;IAEvD;;OAEG;IACH,KAAK,GAAe,EAAE,CAAC;IAEvB;;OAEG;IACH,iBAAiB,GAA+B,SAAS,CAAC;IAE1D;;OAEG;IACH,UAAU,GAAG,KAAK,CAAC;IAEnB;;;OAGG;IACH,gBAAgB,GAAG,KAAK,CAAC;IAEzB,gBAAgB,GAAG,KAAK,CAAC;IACzB,QAAQ,GAAG,IAAI,GAAG,EAAqB,CAAC;IAExC,YAAY,OAAoB;QAC/B,IAAI,OAAO,EAAE,eAAe,KAAK,SAAS,EAAE,CAAC;YAC5C,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;QACjD,CAAC;IACF,CAAC;IAED,IAAI,CAAC,KAAe,EAAE,OAAwB,EAAE,IAAY,EAAE,GAAG,IAAe;QAC/E,MAAM,GAAG,GAAa,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACrD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC3B,GAAG,CAAC,KAAK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C;oBAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBAEtC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBACpC,CAAC;YACF,CAAC;YAAC,MAAM,CAAC;gBACR,mBAAmB;YACpB,CAAC;QACF,CAAC,QAAQ,IAAI,CAAC,gBAAgB,EAAE;QAEhC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IACzB,CAAC;;AAGF,eAAe,GAAG,CAAC","sourcesContent":["import type { LogLevel, LogTargetLevel, LogEntry, Logger, LogTarget } from './common.js';\nimport { createAssert } from 'typia';\nexport type { Logger };\n\n/**\n * Maximum number of logs to enqueue when there are no targets assigned to a\n * Log instance\n */\nconst MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS = 131072;\n\n/**\n * Options for a Log instance\n */\ntype LogOptions = {\n\t/**\n\t * Whether to generate debug tracing information for each log entry\n\t */\n\tlogDebugTracing?: boolean;\n};\n\ntype LogOptionsParam = LogEntry['options'];\nconst assertLogOptionsParam = createAssert<LogOptionsParam>();\n\ntype LogTargetID = symbol & { _branded: 'LogTargetID' };\n\nexport class Log implements Logger {\n\t/**\n\t * The default log level, used for new instances of the logger\n\t */\n\tstatic readonly defaultLevel: LogTargetLevel = 'DEBUG';\n\n\t/**\n\t * Queued logs to be sent\n\t */\n\t#logs: LogEntry[] = [];\n\n\t/**\n\t * Interval holding the current autoSync process\n\t */\n\t#autoSyncInterval: NodeJS.Timeout | undefined = undefined;\n\n\t/**\n\t * Keep track of whether or not we are currently syncing\n\t */\n\t#isSyncing = false;\n\n\t/**\n\t * If `sync()` is called while we are syncing, we should sync again\n\t * to ensure all logs are sent\n\t */\n\t#shouldSyncAgain = false;\n\n\t#logDebugTracing = false;\n\t#targets = new Map<symbol, LogTarget>();\n\n\tconstructor(options?: LogOptions) {\n\t\tif (options?.logDebugTracing !== undefined) {\n\t\t\tthis.#logDebugTracing = options.logDebugTracing;\n\t\t}\n\t}\n\n\t#log(level: LogLevel, options: LogOptionsParam, from: string, ...args: unknown[]): void {\n\t\tconst log: LogEntry = { options, level, from, args };\n\t\tif (this.#logDebugTracing) {\n\t\t\tlog.trace = new Error().stack?.split('\\n').slice(2).join('\\n') ?? '[No stack trace available]';\n\t\t}\n\t\tthis.#logs.push(log);\n\t}\n\n\t#extractArguments(args: unknown[]): { options: LogOptionsParam, from: string } {\n\t\tconst options = assertLogOptionsParam((args[0] instanceof Object ? args.shift() : {}));\n\t\tconst from = args.shift();\n\t\tif (typeof from !== 'string') {\n\t\t\tthrow(new Error(`Expected string for 'from', got ${typeof from}`));\n\t\t}\n\n\t\treturn({ options, from });\n\t}\n\n\tlog(options: LogOptionsParam, from: string, ...args: unknown[]): void;\n\tlog(from: string, ...args: unknown[]): void;\n\tlog(...args: unknown[]) {\n\t\tconst { options, from } = this.#extractArguments(args);\n\n\t\tthis.#log('INFO', options, from, ...args);\n\t}\n\n\tinfo(options: LogOptionsParam, from: string, ...args: unknown[]): void;\n\tinfo(from: string, ...args: unknown[]): void;\n\tinfo(...args: unknown[]) {\n\t\tconst { options, from } = this.#extractArguments(args);\n\n\t\tthis.#log('INFO', options, from, ...args);\n\t}\n\n\tdebug(options: LogOptionsParam, from: string, ...args: unknown[]): void;\n\tdebug(from: string, ...args: unknown[]): void;\n\tdebug(...args: unknown[]) {\n\t\tconst { options, from } = this.#extractArguments(args);\n\n\t\tthis.#log('DEBUG', options, from, ...args);\n\t}\n\n\twarn(options: LogOptionsParam, from: string, ...args: unknown[]): void;\n\twarn(from: string, ...args: unknown[]): void;\n\twarn(...args: unknown[]) {\n\t\tconst { options, from } = this.#extractArguments(args);\n\n\t\tthis.#log('WARN', options, from, ...args);\n\t}\n\n\terror(options: LogOptionsParam, from: string, ...args: unknown[]): void;\n\terror(from: string, ...args: unknown[]): void;\n\terror(...args: unknown[]) {\n\t\tconst { options, from } = this.#extractArguments(args);\n\n\t\tthis.#log('ERROR', options, from, ...args);\n\t}\n\n\t/**\n\t * Register a new logging target (sink) to send logs to\n\t */\n\tregisterTarget(target: LogTarget): LogTargetID {\n\t\tconst id = Symbol('LogTargetID');\n\n\t\tthis.#targets.set(id, target);\n\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn(id as unknown as LogTargetID);\n\t}\n\n\t/**\n\t * Unregister a logging target (sink) to stop sending logs to\n\t */\n\tunregisterTarget(id: LogTargetID): void {\n\t\tthis.#targets.delete(id);\n\t}\n\n\t/**\n\t * Emit a set of logs to all registered targets\n\t */\n\tprivate async emitLogs(logs: LogEntry[], targets: LogTarget[]) {\n\t\tawait Promise.allSettled(targets.map(async function(target) {\n\t\t\tawait target.emitLogs(logs);\n\t\t}));\n\t}\n\n\t/**\n\t * Start a timer to periodically sync logs to all targets\n\t */\n\tstartAutoSync(rate = 100): void {\n\t\tif (this.#autoSyncInterval) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#autoSyncInterval = setInterval(async () => {\n\t\t\ttry {\n\t\t\t\tawait this.sync();\n\t\t\t} catch {\n\t\t\t\t/* Ignored */\n\t\t\t}\n\t\t}, rate);\n\t}\n\n\t/**\n\t * If a timer was started with `startAutoSync()`, stop it\n\t */\n\tstopAutoSync(): void {\n\t\tif (!this.#autoSyncInterval) {\n\t\t\treturn;\n\t\t}\n\n\t\tclearInterval(this.#autoSyncInterval);\n\t\tthis.#autoSyncInterval = undefined;\n\t}\n\n\t/**\n\t * Sync all currently enqueued logs to all targets\n\t */\n\tasync sync(): Promise<void> {\n\t\t/*\n\t\t * If there are currently no targets, do not dequeue logs\n\t\t * in case a target is added later; However, if there are\n\t\t * too many logs, drop the oldest ones\n\t\t */\n\t\tif (this.#targets.size === 0) {\n\t\t\tif (this.#logs.length > MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS) {\n\t\t\t\tthis.#logs.splice(0, this.#logs.length - MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\t/*\n\t\t * If we are already syncing, set a flag to sync again after the current sync is done\n\t\t */\n\t\tif (this.#isSyncing) {\n\t\t\tthis.#shouldSyncAgain = true;\n\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#isSyncing = true;\n\n\t\t/*\n\t\t * Create a copy of the currently registered targets in case\n\t\t * they are modified while a sync is on-going, we use the\n\t\t * same targets until the sync is complete\n\t\t *\n\t\t * This ensures no messages are lost if all targets are removed\n\t\t * while a sync is in progress -- they will continue to be sent\n\t\t * to the registered targets at the time of the sync\n\t\t */\n\t\tconst targets = Array.from(this.#targets.values());\n\n\t\tdo {\n\t\t\ttry {\n\t\t\t\twhile (this.#logs.length > 0) {\n\t\t\t\t\tthis.#shouldSyncAgain = false;\n\t\t\t\t\tconst logs = this.#logs.splice(0, 10);\n\n\t\t\t\t\tawait this.emitLogs(logs, targets);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t/* Ignore errors */\n\t\t\t}\n\t\t} while (this.#shouldSyncAgain);\n\n\t\tthis.#isSyncing = false;\n\t}\n}\n\nexport default Log;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/log/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAGpD,MAAM,GAAG,GAAmB,GAAG,CAAC,GAAG,CAAC;AACpC,MAAM,SAAS,GAAsB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1D,MAAM,OAAO,GAAoB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEpD,OAAO,EACN,GAAG,EACH,SAAS,EACT,OAAO,EACP,CAAC;AACF,eAAe,GAAG,CAAC","sourcesContent":["import { lib } from '@keetanetwork/keetanet-client';\nexport type * from '@keetanetwork/keetanet-client/lib/log/index.js';\n\nconst Log: typeof lib.Log = lib.Log;\nconst LegacyLog: typeof Log.Legacy = Log.Legacy.bind(Log);\nconst NullLog: typeof Log.Null = Log.Null.bind(Log);\n\nexport {\n\tLog,\n\tLegacyLog,\n\tNullLog\n};\nexport default Log;\n"]}
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
console?: Pick<typeof console, 'debug' | 'info' | 'warn' | 'error'>;
|
|
5
|
-
};
|
|
6
|
-
export declare class LogTargetConsole implements LogTarget {
|
|
7
|
-
#private;
|
|
8
|
-
readonly logLevel: LogTargetLevel;
|
|
9
|
-
constructor(config?: LogTargetConsoleConfig);
|
|
10
|
-
emitLogs(logs: LogEntry[]): Promise<void>;
|
|
11
|
-
}
|
|
1
|
+
import { lib } from '@keetanetwork/keetanet-client';
|
|
2
|
+
declare const LogTargetConsole: typeof lib.Log.ConsoleTarget;
|
|
3
|
+
export { LogTargetConsole };
|
|
12
4
|
export default LogTargetConsole;
|
|
13
5
|
//# sourceMappingURL=target_console.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"target_console.d.ts","sourceRoot":"","sources":["../../../src/lib/log/target_console.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"target_console.d.ts","sourceRoot":"","sources":["../../../src/lib/log/target_console.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAEpD,QAAA,MAAM,gBAAgB,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,aAAqC,CAAC;AAE7E,OAAO,EACN,gBAAgB,EAChB,CAAC;AACF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,44 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
logLevel;
|
|
5
|
-
#console;
|
|
6
|
-
constructor(config) {
|
|
7
|
-
this.logLevel = config?.logLevel ?? 'ALL';
|
|
8
|
-
this.#console = config?.console ?? console;
|
|
9
|
-
}
|
|
10
|
-
async emitLogs(logs) {
|
|
11
|
-
for (const log of logs) {
|
|
12
|
-
if (!canLogForTargetLevel(log.level, this.logLevel)) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
let method;
|
|
16
|
-
switch (log.level) {
|
|
17
|
-
case 'ERROR':
|
|
18
|
-
method = 'error';
|
|
19
|
-
break;
|
|
20
|
-
case 'WARN':
|
|
21
|
-
method = 'warn';
|
|
22
|
-
break;
|
|
23
|
-
case 'INFO':
|
|
24
|
-
method = 'info';
|
|
25
|
-
break;
|
|
26
|
-
case 'DEBUG':
|
|
27
|
-
method = 'debug';
|
|
28
|
-
break;
|
|
29
|
-
default:
|
|
30
|
-
assertNever(log.level);
|
|
31
|
-
}
|
|
32
|
-
let requestID = log.options?.currentRequestInfo?.id;
|
|
33
|
-
if (requestID === undefined) {
|
|
34
|
-
requestID = '<NO_REQUEST_ID>';
|
|
35
|
-
}
|
|
36
|
-
this.#console[method](`[${requestID}] ${log.level} ${log.from}:`, ...log.args);
|
|
37
|
-
if (log.trace !== undefined) {
|
|
38
|
-
this.#console[method](`[${requestID}] ${log.level} ${log.from} TRACE:`, log.trace);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
import { lib } from '@keetanetwork/keetanet-client';
|
|
2
|
+
const LogTargetConsole = lib.Log.ConsoleTarget;
|
|
3
|
+
export { LogTargetConsole };
|
|
43
4
|
export default LogTargetConsole;
|
|
44
5
|
//# sourceMappingURL=target_console.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"target_console.js","sourceRoot":"","sources":["../../../src/lib/log/target_console.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"target_console.js","sourceRoot":"","sources":["../../../src/lib/log/target_console.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAEpD,MAAM,gBAAgB,GAAiC,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC;AAE7E,OAAO,EACN,gBAAgB,EAChB,CAAC;AACF,eAAe,gBAAgB,CAAC","sourcesContent":["import { lib } from '@keetanetwork/keetanet-client';\n\nconst LogTargetConsole: typeof lib.Log.ConsoleTarget = lib.Log.ConsoleTarget;\n\nexport {\n\tLogTargetConsole\n};\nexport default LogTargetConsole;\n"]}
|