@keetanetwork/anchor 0.0.30 → 0.0.32

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.
Files changed (58) hide show
  1. package/lib/error.d.ts +5 -1
  2. package/lib/error.d.ts.map +1 -1
  3. package/lib/error.js +43 -4
  4. package/lib/error.js.map +1 -1
  5. package/npm-shrinkwrap.json +1376 -38
  6. package/package.json +1 -1
  7. package/services/asset-movement/client.d.ts +6 -1
  8. package/services/asset-movement/client.d.ts.map +1 -1
  9. package/services/asset-movement/client.js +94 -22
  10. package/services/asset-movement/client.js.map +1 -1
  11. package/services/asset-movement/common.d.ts +6 -1
  12. package/services/asset-movement/common.d.ts.map +1 -1
  13. package/services/asset-movement/common.js +59 -25
  14. package/services/asset-movement/common.js.map +1 -1
  15. package/lib/http-server-shared.d.ts +0 -14
  16. package/lib/http-server-shared.d.ts.map +0 -1
  17. package/lib/http-server-shared.js +0 -108
  18. package/lib/http-server-shared.js.map +0 -1
  19. package/lib/http-server.d.ts +0 -62
  20. package/lib/http-server.d.ts.map +0 -1
  21. package/lib/http-server.js +0 -431
  22. package/lib/http-server.js.map +0 -1
  23. package/lib/log/common.d.ts +0 -35
  24. package/lib/log/common.d.ts.map +0 -1
  25. package/lib/log/common.js +0 -19
  26. package/lib/log/common.js.map +0 -1
  27. package/lib/queue/common.d.ts +0 -23
  28. package/lib/queue/common.d.ts.map +0 -1
  29. package/lib/queue/common.js +0 -47
  30. package/lib/queue/common.js.map +0 -1
  31. package/lib/queue/drivers/queue_file.d.ts +0 -17
  32. package/lib/queue/drivers/queue_file.d.ts.map +0 -1
  33. package/lib/queue/drivers/queue_file.js +0 -100
  34. package/lib/queue/drivers/queue_file.js.map +0 -1
  35. package/lib/queue/drivers/queue_sqlite3.d.ts +0 -28
  36. package/lib/queue/drivers/queue_sqlite3.d.ts.map +0 -1
  37. package/lib/queue/drivers/queue_sqlite3.js +0 -379
  38. package/lib/queue/drivers/queue_sqlite3.js.map +0 -1
  39. package/lib/queue/index.d.ts +0 -341
  40. package/lib/queue/index.d.ts.map +0 -1
  41. package/lib/queue/index.js +0 -940
  42. package/lib/queue/index.js.map +0 -1
  43. package/lib/queue/internal.d.ts +0 -8
  44. package/lib/queue/internal.d.ts.map +0 -1
  45. package/lib/queue/internal.js +0 -28
  46. package/lib/queue/internal.js.map +0 -1
  47. package/lib/queue/pipeline.d.ts +0 -149
  48. package/lib/queue/pipeline.d.ts.map +0 -1
  49. package/lib/queue/pipeline.js +0 -296
  50. package/lib/queue/pipeline.js.map +0 -1
  51. package/lib/utils/asleep.d.ts +0 -2
  52. package/lib/utils/asleep.d.ts.map +0 -1
  53. package/lib/utils/asleep.js +0 -3
  54. package/lib/utils/asleep.js.map +0 -1
  55. package/lib/utils/defer.d.ts +0 -3
  56. package/lib/utils/defer.d.ts.map +0 -1
  57. package/lib/utils/defer.js +0 -3
  58. package/lib/utils/defer.js.map +0 -1
@@ -1,62 +0,0 @@
1
- import * as http from 'http';
2
- import type { JSONSerializable } from './utils/json.js';
3
- import type { Logger } from './log/index.js';
4
- export declare const AssertHTTPErrorData: (input: unknown) => {
5
- error: string;
6
- statusCode?: number;
7
- contentType?: string;
8
- };
9
- export type Routes = {
10
- [route: string]: (urlParams: Map<string, string>, postData: JSONSerializable | undefined, requestHeaders: http.IncomingHttpHeaders) => Promise<{
11
- output: string | Buffer;
12
- statusCode?: number;
13
- contentType?: string;
14
- headers?: {
15
- [headerName: string]: string;
16
- };
17
- }>;
18
- };
19
- export interface KeetaAnchorHTTPServerConfig {
20
- /**
21
- * The port for the HTTP server to listen on (default is an ephemeral port).
22
- */
23
- port?: number;
24
- /**
25
- * Enable debug logging
26
- */
27
- logger?: Logger;
28
- }
29
- export declare abstract class KeetaNetAnchorHTTPServer<ConfigType extends KeetaAnchorHTTPServerConfig = KeetaAnchorHTTPServerConfig> implements Required<KeetaAnchorHTTPServerConfig> {
30
- #private;
31
- readonly port: NonNullable<KeetaAnchorHTTPServerConfig['port']>;
32
- readonly logger: NonNullable<KeetaAnchorHTTPServerConfig['logger']>;
33
- constructor(config: ConfigType);
34
- protected abstract initRoutes(config: ConfigType): Promise<Routes>;
35
- private static routeMatch;
36
- private static routeFind;
37
- private static addCORS;
38
- private main;
39
- /**
40
- * Start the HTTP server and wait for it to be fully initialized.
41
- */
42
- start(): Promise<void>;
43
- /**
44
- * Wait for the server to terminate. This will only resolve once the
45
- * server has been stopped.
46
- */
47
- wait(): Promise<void>;
48
- /**
49
- * Stop the HTTP server and wait for it to be fully terminated.
50
- */
51
- stop(): Promise<void>;
52
- /**
53
- * Get the URL of the server, which can be used to make requests to
54
- * it. This will use "localhost" as the hostname and the port that
55
- * the server is listening on by default but can be overridden by
56
- * setting a custom URL.
57
- */
58
- get url(): string;
59
- set url(value: string | URL | ((object: this) => string));
60
- [Symbol.asyncDispose](): Promise<void>;
61
- }
62
- //# sourceMappingURL=http-server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-server.d.ts","sourceRoot":"","sources":["../../src/lib/http-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAK7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAY,MAAM,gBAAgB,CAAC;AAKvD,eAAO,MAAM,mBAAmB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAAkF,CAAC;AAOpM,MAAM,MAAM,MAAM,GAAG;IACpB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,gBAAgB,GAAG,SAAS,EAAE,cAAc,EAAE,IAAI,CAAC,mBAAmB,KAAK,OAAO,CAAC;QAAE,MAAM,E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C,IAAI,OAAO,CAAC,IAAI,CAAC;CAGtC"}
@@ -1,431 +0,0 @@
1
- import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
2
- import * as http from 'http';
3
- import { KeetaAnchorError, KeetaAnchorUserError } from './error.js';
4
- import { Log } from './log/index.js';
5
- import { createAssert } from 'typia';
6
- import { assertNever } from './utils/never.js';
7
- export const AssertHTTPErrorData = (() => { const _io0 = input => "string" === typeof input.error && (undefined === input.statusCode || "number" === typeof input.statusCode) && (undefined === input.contentType || "string" === typeof input.contentType); const _ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.error || __typia_transform__assertGuard._assertGuard(_exceptionable, {
8
- method: "createAssert",
9
- path: _path + ".error",
10
- expected: "string",
11
- value: input.error
12
- }, _errorFactory)) && (undefined === input.statusCode || "number" === typeof input.statusCode || __typia_transform__assertGuard._assertGuard(_exceptionable, {
13
- method: "createAssert",
14
- path: _path + ".statusCode",
15
- expected: "(number | undefined)",
16
- value: input.statusCode
17
- }, _errorFactory)) && (undefined === input.contentType || "string" === typeof input.contentType || __typia_transform__assertGuard._assertGuard(_exceptionable, {
18
- method: "createAssert",
19
- path: _path + ".contentType",
20
- expected: "(string | undefined)",
21
- value: input.contentType
22
- }, _errorFactory)); const __is = input => "object" === typeof input && null !== input && _io0(input); let _errorFactory; return (input, errorFactory) => {
23
- if (false === __is(input)) {
24
- _errorFactory = errorFactory;
25
- ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
26
- method: "createAssert",
27
- path: _path + "",
28
- expected: "__type",
29
- value: input
30
- }, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
31
- method: "createAssert",
32
- path: _path + "",
33
- expected: "__type",
34
- value: input
35
- }, _errorFactory))(input, "$input", true);
36
- }
37
- return input;
38
- }; })();
39
- /**
40
- * The maximum size of a request (128KiB)
41
- */
42
- const MAX_REQUEST_SIZE = 1024 * 128;
43
- ;
44
- export class KeetaNetAnchorHTTPServer {
45
- port;
46
- logger;
47
- #serverPromise;
48
- #server;
49
- #url;
50
- #config;
51
- constructor(config) {
52
- this.#config = { ...config };
53
- this.port = config.port ?? 0;
54
- this.logger = config.logger ?? Log.Legacy('ANCHOR');
55
- }
56
- static routeMatch(requestURL, routeURL) {
57
- const requestURLPaths = requestURL.pathname.split('/');
58
- const routeURLPaths = routeURL.pathname.split('/');
59
- if (requestURLPaths.length !== routeURLPaths.length) {
60
- return ({ match: false });
61
- }
62
- const params = new Map();
63
- for (let partIndex = 0; partIndex < requestURLPaths.length; partIndex++) {
64
- const requestPath = requestURLPaths[partIndex];
65
- const routePath = routeURLPaths[partIndex];
66
- if (routePath === undefined || requestPath === undefined) {
67
- return ({ match: false });
68
- }
69
- if (routePath.startsWith(':')) {
70
- params.set(routePath.slice(1), requestPath);
71
- }
72
- else if (requestPath !== routePath) {
73
- return ({ match: false });
74
- }
75
- }
76
- return ({ match: true, params: params });
77
- }
78
- static routeFind(method, requestURL, routes) {
79
- for (const routeKey in routes) {
80
- const route = routes[routeKey];
81
- if (route === undefined) {
82
- continue;
83
- }
84
- const [routeMethod, ...routePathParts] = routeKey.split(' ');
85
- const routePath = `/${routePathParts.join(' ')}`.replace(/^\/+/, '/');
86
- if (method !== routeMethod) {
87
- continue;
88
- }
89
- const routeURL = new URL(routePath, 'http://localhost');
90
- const matchResult = this.routeMatch(requestURL, routeURL);
91
- if (matchResult.match) {
92
- return ({
93
- route: route,
94
- params: matchResult.params
95
- });
96
- }
97
- }
98
- return (null);
99
- }
100
- static addCORS(routes) {
101
- const newRoutes = {};
102
- const validMethods = new Set(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']);
103
- const methodsByPath = {};
104
- for (const routeKey in routes) {
105
- const methodAndPath = routeKey.split(' ');
106
- const method = methodAndPath[0];
107
- const path = methodAndPath.slice(1).join(' ');
108
- if (method === undefined || path === undefined) {
109
- continue;
110
- }
111
- if (!validMethods.has(method)) {
112
- continue;
113
- }
114
- if (!(path in methodsByPath)) {
115
- methodsByPath[path] = new Set();
116
- }
117
- if (methodsByPath[path] === undefined) {
118
- throw (new Error(`internal error: methodsByPath missing path for ${path}`));
119
- }
120
- methodsByPath[path].add(method);
121
- }
122
- const seenPaths = new Set();
123
- for (const routeKey in routes) {
124
- const methodAndPath = routeKey.split(' ');
125
- const method = methodAndPath[0];
126
- const path = methodAndPath.slice(1).join(' ');
127
- const routeHandler = routes[routeKey];
128
- if (routeHandler === undefined) {
129
- throw (new Error(`internal error: routeHandler missing for routeKey ${routeKey}`));
130
- }
131
- if (method !== 'ERROR') {
132
- if (method === undefined || path === undefined) {
133
- newRoutes[routeKey] = routeHandler;
134
- continue;
135
- }
136
- if (!validMethods.has(method)) {
137
- newRoutes[routeKey] = routeHandler;
138
- continue;
139
- }
140
- }
141
- const validMethodsForPath = methodsByPath[path];
142
- let validMethodsForPathParts = [];
143
- if (validMethodsForPath !== undefined) {
144
- validMethodsForPath.add('OPTIONS');
145
- validMethodsForPathParts = Array.from(validMethodsForPath);
146
- }
147
- else {
148
- validMethodsForPathParts = [...Array.from(validMethods), 'OPTIONS'];
149
- }
150
- newRoutes[routeKey] = async function (...args) {
151
- const retval = await routeHandler(...args);
152
- /* Add CORS headers to the response for the original route handler */
153
- if (retval.contentType === 'application/json' || retval.contentType === undefined) {
154
- if (!('headers' in retval) || retval.headers === undefined) {
155
- retval.headers = {};
156
- }
157
- retval.headers['Access-Control-Allow-Origin'] = '*';
158
- }
159
- return (retval);
160
- };
161
- if (!seenPaths.has(path) && path !== '' && path !== undefined) {
162
- const corsRouteKey = `OPTIONS ${path}`;
163
- newRoutes[corsRouteKey] = async function () {
164
- return ({
165
- output: '',
166
- statusCode: 204,
167
- contentType: 'text/plain',
168
- headers: {
169
- 'Access-Control-Allow-Origin': '*',
170
- 'Access-Control-Allow-Methods': validMethodsForPathParts.join(', '),
171
- 'Access-Control-Allow-Headers': 'Content-Type',
172
- 'Access-Control-Max-Age': '86400'
173
- }
174
- });
175
- };
176
- seenPaths.add(path);
177
- }
178
- }
179
- return (newRoutes);
180
- }
181
- async main(onSetPort) {
182
- this.logger?.debug('KeetaAnchorHTTP.Server', 'Starting HTTP server...');
183
- const port = this.port;
184
- const routes = KeetaNetAnchorHTTPServer.addCORS({
185
- ERROR: async function (_ignore_params, postData) {
186
- const errorInfo = AssertHTTPErrorData(postData);
187
- const retval = {
188
- output: errorInfo.error,
189
- statusCode: errorInfo.statusCode ?? 400,
190
- contentType: errorInfo.contentType ?? 'text/plain'
191
- };
192
- return (retval);
193
- },
194
- ...(await this.initRoutes(this.#config))
195
- });
196
- const server = new http.Server(async (request, response) => {
197
- const url = new URL(request.url ?? '/', `http://${request.headers.host ?? 'localhost'}`);
198
- const method = request.method ?? 'GET';
199
- /*
200
- * Finalize the response by syncing the logger and ending
201
- * the response.
202
- */
203
- const responseFinalize = async () => {
204
- if ('sync' in this.logger && typeof this.logger.sync === 'function') {
205
- try {
206
- await this.logger.sync();
207
- }
208
- catch {
209
- /* ignore errors */
210
- }
211
- }
212
- response.end();
213
- };
214
- /*
215
- * Lookup the route based on the request
216
- */
217
- const requestedRouteAndParams = KeetaNetAnchorHTTPServer.routeFind(method, url, routes);
218
- if (requestedRouteAndParams === null) {
219
- response.statusCode = 404;
220
- response.setHeader('Content-Type', 'text/plain');
221
- response.write('Not Found');
222
- await responseFinalize();
223
- return;
224
- }
225
- /*
226
- * Extract the route handler and the parameters from
227
- * the request
228
- */
229
- const { route, params } = requestedRouteAndParams;
230
- /**
231
- * Attempt to run the route, catch any errors
232
- */
233
- let result = undefined;
234
- let generatedResult = false;
235
- try {
236
- /**
237
- * If POST'ing, read and parse the POST data
238
- */
239
- let postData;
240
- if (request.method === 'POST') {
241
- const data = await request.map(function (chunk) {
242
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
243
- return (Buffer.from(chunk));
244
- }).reduce(function (prev, curr) {
245
- if (prev.length > MAX_REQUEST_SIZE) {
246
- throw (new Error('Request too large'));
247
- }
248
- if (!Buffer.isBuffer(curr)) {
249
- throw (new Error(`internal error: Current item is not a buffer -- ${typeof curr}`));
250
- }
251
- return (Buffer.concat([prev, curr]));
252
- }, Buffer.from(''));
253
- if (request.headers['content-type'] === 'application/json') {
254
- try {
255
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
256
- postData = JSON.parse(data.toString('utf-8'));
257
- }
258
- catch {
259
- throw (new Error('Invalid JSON data'));
260
- }
261
- }
262
- else {
263
- throw (new KeetaAnchorUserError('Unsupported content type'));
264
- }
265
- /**
266
- * Call the route handler
267
- */
268
- result = await route(params, postData, request.headers);
269
- }
270
- else {
271
- result = await route(params, undefined, request.headers);
272
- }
273
- generatedResult = true;
274
- }
275
- catch (err) {
276
- let logLevel = 'error';
277
- if (KeetaAnchorError.isInstance(err)) {
278
- /*
279
- * We're able to safely cast this here because the cast
280
- * duplicates the logic.
281
- */
282
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
283
- logLevel = err.logLevel.toLowerCase();
284
- }
285
- /**
286
- * If an error occurs, log it and return an error page
287
- */
288
- this.logger?.[logLevel]('KeetaAnchorHTTP.Server', err);
289
- /**
290
- * If it is a user error, provide a user-friendly error page
291
- */
292
- const errorHandlerRoute = routes['ERROR'];
293
- if (errorHandlerRoute !== undefined) {
294
- if (KeetaAnchorUserError.isInstance(err)) {
295
- result = await errorHandlerRoute(new Map(), err.asErrorResponse('application/json'), request.headers);
296
- }
297
- else {
298
- result = await errorHandlerRoute(new Map(), {
299
- error: JSON.stringify({ ok: false, error: 'Internal Server Error' }),
300
- statusCode: 500,
301
- contentType: 'application/json'
302
- }, request.headers);
303
- }
304
- generatedResult = true;
305
- }
306
- if (!generatedResult) {
307
- /**
308
- * Otherwise provide a generic error page
309
- */
310
- response.statusCode = 500;
311
- response.setHeader('Content-Type', 'text/plain');
312
- response.write('Internal Server Error');
313
- await responseFinalize();
314
- return;
315
- }
316
- }
317
- if (result === undefined) {
318
- throw (new Error('internal error: No result'));
319
- }
320
- /**
321
- * Write the response to the client
322
- */
323
- response.statusCode = result.statusCode ?? 200;
324
- for (const headerKey in result.headers ?? {}) {
325
- const headerValue = result.headers?.[headerKey];
326
- if (headerValue !== undefined) {
327
- response.setHeader(headerKey, headerValue);
328
- }
329
- }
330
- response.setHeader('Content-Type', result.contentType ?? 'application/json');
331
- response.write(result.output);
332
- await responseFinalize();
333
- });
334
- this.#server = server;
335
- /**
336
- * Create a promise to wait for the server to close
337
- */
338
- const waiter = new Promise((resolve) => {
339
- server.on('close', () => {
340
- this.logger?.debug('KeetaAnchorHTTP.Server', 'Server closed');
341
- resolve();
342
- });
343
- });
344
- /**
345
- * Start listening on the port
346
- */
347
- server.listen(port, () => {
348
- const address = server.address();
349
- if (address !== null && typeof address === 'object') {
350
- // @ts-ignore
351
- this.port = address.port;
352
- onSetPort?.(this.port);
353
- }
354
- this.logger?.debug('KeetaAnchorHTTP.Server', 'Listening on port:', this.port);
355
- });
356
- /**
357
- * Wait for the server to close
358
- */
359
- await waiter;
360
- }
361
- /**
362
- * Start the HTTP server and wait for it to be fully initialized.
363
- */
364
- async start() {
365
- /*
366
- * Start the server and wait for it to be initialized before returning
367
- */
368
- await new Promise((resolve, reject) => {
369
- this.#serverPromise = this.main(function () {
370
- resolve();
371
- }).catch(function (error) {
372
- // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
373
- reject(error);
374
- });
375
- });
376
- }
377
- /**
378
- * Wait for the server to terminate. This will only resolve once the
379
- * server has been stopped.
380
- */
381
- async wait() {
382
- await this.#serverPromise;
383
- }
384
- /**
385
- * Stop the HTTP server and wait for it to be fully terminated.
386
- */
387
- async stop() {
388
- this.#server?.close();
389
- // @ts-ignore
390
- this.#server = undefined;
391
- await this.wait();
392
- }
393
- /**
394
- * Get the URL of the server, which can be used to make requests to
395
- * it. This will use "localhost" as the hostname and the port that
396
- * the server is listening on by default but can be overridden by
397
- * setting a custom URL.
398
- */
399
- get url() {
400
- if (this.port === 0 || this.#server === undefined) {
401
- throw (new Error('Server not started'));
402
- }
403
- if (this.#url !== undefined) {
404
- let newURL;
405
- if (typeof this.#url === 'string') {
406
- newURL = this.#url;
407
- }
408
- else if (this.#url instanceof URL || ('port' in this.#url && 'hostname' in this.#url && 'toString' in this.#url)) {
409
- newURL = this.#url.toString();
410
- }
411
- else if (typeof this.#url === 'function') {
412
- newURL = this.#url(this);
413
- }
414
- else {
415
- assertNever(this.#url);
416
- }
417
- const newURLObj = new URL(newURL);
418
- newURLObj.pathname = '/';
419
- newURLObj.search = '';
420
- return (newURLObj.toString());
421
- }
422
- return (`http://localhost:${this.port}`);
423
- }
424
- set url(value) {
425
- this.#url = value;
426
- }
427
- [Symbol.asyncDispose]() {
428
- return (this.stop());
429
- }
430
- }
431
- //# sourceMappingURL=http-server.js.map
@@ -1 +0,0 @@
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,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,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;IACtB,IAAI,CAAwD;IACnD,OAAO,CAAa;IAE7B,YAAY,MAAkB;QAC7B,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;QAC7B,IAAI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;IAED,IAAI,GAAG,CAAC,KAAgD;QACvD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACnB,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\tKeetaAnchorError,\n\tKeetaAnchorUserError\n} from './error.js';\nimport type { JSONSerializable } from './utils/json.js';\nimport type { Logger, LogLevel } from './log/index.js';\nimport { Log } from './log/index.js';\nimport { createAssert } from 'typia';\nimport { assertNever } from './utils/never.js';\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 | Buffer; 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\t#url: undefined | string | URL | ((object: this) => string);\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 * Finalize the response by syncing the logger and ending\n\t\t\t * the response.\n\t\t\t */\n\t\t\tconst responseFinalize = async () => {\n\t\t\t\tif ('sync' in this.logger && typeof this.logger.sync === 'function') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this.logger.sync();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t/* ignore errors */\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tresponse.end();\n\t\t\t};\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\tawait responseFinalize();\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\tlet logLevel: Lowercase<LogLevel> = 'error';\n\t\t\t\tif (KeetaAnchorError.isInstance(err)) {\n\t\t\t\t\t/*\n\t\t\t\t\t * We're able to safely cast this here because the cast\n\t\t\t\t\t * duplicates the logic.\n\t\t\t\t\t */\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\tlogLevel = err.logLevel.toLowerCase() as Lowercase<typeof err.logLevel>;\n\t\t\t\t}\n\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?.[logLevel]('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} 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}\n\t\t\t\t\tgeneratedResult = true;\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\tawait responseFinalize();\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\tawait responseFinalize();\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 by default but can be overridden by\n\t * setting a custom URL.\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\tif (this.#url !== undefined) {\n\t\t\tlet newURL: string;\n\t\t\tif (typeof this.#url === 'string') {\n\t\t\t\tnewURL = this.#url;\n\t\t\t} else if (this.#url instanceof URL || ('port' in this.#url && 'hostname' in this.#url && 'toString' in this.#url)) {\n\t\t\t\tnewURL = this.#url.toString();\n\t\t\t} else if (typeof this.#url === 'function') {\n\t\t\t\tnewURL = this.#url(this);\n\t\t\t} else {\n\t\t\t\tassertNever(this.#url);\n\t\t\t}\n\n\t\t\tconst newURLObj = new URL(newURL);\n\t\t\tnewURLObj.pathname = '/';\n\t\t\tnewURLObj.search = '';\n\n\t\t\treturn(newURLObj.toString());\n\t\t}\n\n\t\treturn(`http://localhost:${this.port}`);\n\t}\n\n\tset url(value: string | URL | ((object: this) => string)) {\n\t\tthis.#url = value;\n\t}\n\n\t[Symbol.asyncDispose](): Promise<void> {\n\t\treturn(this.stop());\n\t}\n}\n"]}
@@ -1,35 +0,0 @@
1
- export type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
2
- export type LogTargetLevel = 'ALL' | LogLevel | 'NONE';
3
- type LogCurrentRequest = {
4
- id: string;
5
- };
6
- export type LogEntry = {
7
- options: {
8
- userVisible?: boolean;
9
- currentRequestInfo?: LogCurrentRequest;
10
- };
11
- level: LogLevel;
12
- from: string;
13
- args: unknown[];
14
- trace?: string;
15
- };
16
- export interface LogTarget {
17
- readonly logLevel: LogTargetLevel;
18
- emitLogs(logs: LogEntry[]): Promise<void>;
19
- }
20
- export interface Logger {
21
- log(options: LogEntry['options'], from: string, ...args: unknown[]): void;
22
- log(from: string, ...args: unknown[]): void;
23
- debug(options: LogEntry['options'], from: string, ...args: unknown[]): void;
24
- debug(from: string, ...args: unknown[]): void;
25
- info(options: LogEntry['options'], from: string, ...args: unknown[]): void;
26
- info(from: string, ...args: unknown[]): void;
27
- warn(options: LogEntry['options'], from: string, ...args: unknown[]): void;
28
- warn(from: string, ...args: unknown[]): void;
29
- error(options: LogEntry['options'], from: string, ...args: unknown[]): void;
30
- error(from: string, ...args: unknown[]): void;
31
- }
32
- export declare function canLogForLevel(level: LogLevel, currentLevel: LogLevel): boolean;
33
- export declare function canLogForTargetLevel(level: LogLevel, targetLevel: LogTargetLevel): boolean;
34
- export {};
35
- //# sourceMappingURL=common.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/lib/log/common.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAC3D,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAUvD,KAAK,iBAAiB,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACtB,OAAO,EAAE;QACR,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,kBAAkB,CAAC,EAAE,iBAAiB,CAAC;KACvC,CAAC;IACF,KAAK,EAAE,QAAQ,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,MAAM;IACtB,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC1E,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,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function canLogForLevel(level, currentLevel) {
8
- return (numericLogLevels[level] >= numericLogLevels[currentLevel]);
9
- }
10
- export function canLogForTargetLevel(level, targetLevel) {
11
- if (targetLevel === 'ALL') {
12
- return (true);
13
- }
14
- if (targetLevel === 'NONE') {
15
- return (false);
16
- }
17
- return (canLogForLevel(level, targetLevel));
18
- }
19
- //# sourceMappingURL=common.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/lib/log/common.ts"],"names":[],"mappings":"AAGA,MAAM,gBAAgB,GAAG;IACxB,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACC,CAAC;AAoCX,MAAM,UAAU,cAAc,CAAC,KAAe,EAAE,YAAsB;IACrE,OAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAe,EAAE,WAA2B;IAChF,IAAI,WAAW,KAAK,KAAK,EAAE,CAAC;QAC3B,OAAM,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAED,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;QAC5B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;IAED,OAAM,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["export type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';\nexport type LogTargetLevel = 'ALL' | LogLevel | 'NONE';\n\nconst numericLogLevels = {\n\tDEBUG: 0,\n\tINFO: 1,\n\tWARN: 2,\n\tERROR: 3\n} as const;\n\n/* XXX:TODO -- Do something with this */\ntype LogCurrentRequest = {\n\tid: string;\n};\n\nexport type LogEntry = {\n\toptions: {\n\t\tuserVisible?: boolean;\n\t\tcurrentRequestInfo?: LogCurrentRequest;\n\t};\n\tlevel: LogLevel;\n\tfrom: string;\n\targs: unknown[];\n\ttrace?: string;\n};\n\nexport interface LogTarget {\n\treadonly logLevel: LogTargetLevel;\n\temitLogs(logs: LogEntry[]): Promise<void>;\n}\n\nexport interface Logger {\n\tlog(options: LogEntry['options'], from: string, ...args: unknown[]): void;\n\tlog(from: string, ...args: unknown[]): void;\n\tdebug(options: LogEntry['options'], from: string, ...args: unknown[]): void;\n\tdebug(from: string, ...args: unknown[]): void;\n\tinfo(options: LogEntry['options'], from: string, ...args: unknown[]): void;\n\tinfo(from: string, ...args: unknown[]): void;\n\twarn(options: LogEntry['options'], from: string, ...args: unknown[]): void;\n\twarn(from: string, ...args: unknown[]): void;\n\terror(options: LogEntry['options'], from: string, ...args: unknown[]): void;\n\terror(from: string, ...args: unknown[]): void;\n}\n\nexport function canLogForLevel(level: LogLevel, currentLevel: LogLevel): boolean {\n\treturn(numericLogLevels[level] >= numericLogLevels[currentLevel]);\n}\n\nexport function canLogForTargetLevel(level: LogLevel, targetLevel: LogTargetLevel): boolean {\n\tif (targetLevel === 'ALL') {\n\t\treturn(true);\n\t}\n\n\tif (targetLevel === 'NONE') {\n\t\treturn(false);\n\t}\n\n\treturn(canLogForLevel(level, targetLevel));\n}\n"]}
@@ -1,23 +0,0 @@
1
- import { KeetaAnchorError } from '../error.js';
2
- import type { KeetaAnchorQueueRequestID, KeetaAnchorQueueStatus } from './index.js';
3
- declare class KeetaAnchorQueueIdempotentKeyExistsError extends KeetaAnchorError {
4
- static readonly name: string;
5
- private readonly KeetaAnchorQueueIdempotentExistsErrorObjectTypeID;
6
- private static readonly KeetaAnchorQueueIdempotentExistsErrorObjectTypeID;
7
- readonly idempotentIDsFound?: Set<KeetaAnchorQueueRequestID>;
8
- constructor(message?: string, idempotentIDsFound?: Set<KeetaAnchorQueueRequestID>);
9
- static isInstance(input: unknown): input is KeetaAnchorQueueIdempotentKeyExistsError;
10
- }
11
- declare class KeetaAnchorQueueIncorrectStateAssertedError extends KeetaAnchorError {
12
- static readonly name: string;
13
- private readonly KeetaAnchorQueueIncorrectStateAssertedErrorObjectTypeID;
14
- private static readonly KeetaAnchorQueueIncorrectStateAssertedErrorObjectTypeID;
15
- constructor(id: KeetaAnchorQueueRequestID, expectedStatus: KeetaAnchorQueueStatus, actualStatus: KeetaAnchorQueueStatus, message?: string);
16
- static isInstance(input: unknown): input is KeetaAnchorQueueIncorrectStateAssertedError;
17
- }
18
- export declare const Errors: {
19
- IdempotentExistsError: typeof KeetaAnchorQueueIdempotentKeyExistsError;
20
- IncorrectStateAssertedError: typeof KeetaAnchorQueueIncorrectStateAssertedError;
21
- };
22
- export {};
23
- //# sourceMappingURL=common.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/lib/queue/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpF,cAAM,wCAAyC,SAAQ,gBAAgB;IACtE,gBAAyB,IAAI,EAAE,MAAM,CAAsC;IAC3E,OAAO,CAAC,QAAQ,CAAC,iDAAiD,CAAU;IAC5E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iDAAiD,CAA0C;IACnH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,GAAG,CAAC,yBAAyB,CAAC,CAAC;gBAEjD,OAAO,CAAC,EAAE,MAAM,EAAE,kBAAkB,CAAC,EAAE,GAAG,CAAC,yBAAyB,CAAC;IAYjF,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,wCAAwC;CAGpF;AAED,cAAM,2CAA4C,SAAQ,gBAAgB;IACzE,gBAAyB,IAAI,EAAE,MAAM,CAAoC;IACzE,OAAO,CAAC,QAAQ,CAAC,uDAAuD,CAAU;IAClF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uDAAuD,CAA0C;gBAE7G,EAAE,EAAE,yBAAyB,EAAE,cAAc,EAAE,sBAAsB,EAAE,YAAY,EAAE,sBAAsB,EAAE,OAAO,CAAC,EAAE,MAAM;IAUzI,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,2CAA2C;CAGvF;AAED,eAAO,MAAM,MAAM,EAAE;IACpB,qBAAqB,EAAE,OAAO,wCAAwC,CAAC;IACvE,2BAA2B,EAAE,OAAO,2CAA2C,CAAC;CAWhF,CAAC"}