@stacks/api-toolkit 1.12.0 → 1.12.1

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 (82) hide show
  1. package/package.json +1 -1
  2. package/dist/fastify/cache.d.ts +0 -31
  3. package/dist/fastify/cache.js +0 -63
  4. package/dist/fastify/cache.js.map +0 -1
  5. package/dist/fastify/fastify.d.ts +0 -16
  6. package/dist/fastify/fastify.js +0 -46
  7. package/dist/fastify/fastify.js.map +0 -1
  8. package/dist/fastify/index.d.ts +0 -4
  9. package/dist/fastify/index.js +0 -21
  10. package/dist/fastify/index.js.map +0 -1
  11. package/dist/fastify/openapi.d.ts +0 -13
  12. package/dist/fastify/openapi.js +0 -23
  13. package/dist/fastify/openapi.js.map +0 -1
  14. package/dist/fastify/schemas.d.ts +0 -9
  15. package/dist/fastify/schemas.js +0 -16
  16. package/dist/fastify/schemas.js.map +0 -1
  17. package/dist/helpers/events.d.ts +0 -52
  18. package/dist/helpers/events.js +0 -93
  19. package/dist/helpers/events.js.map +0 -1
  20. package/dist/helpers/index.d.ts +0 -7
  21. package/dist/helpers/index.js +0 -25
  22. package/dist/helpers/index.js.map +0 -1
  23. package/dist/helpers/is-debugging.d.ts +0 -1
  24. package/dist/helpers/is-debugging.js +0 -15
  25. package/dist/helpers/is-debugging.js.map +0 -1
  26. package/dist/helpers/iterators.d.ts +0 -27
  27. package/dist/helpers/iterators.js +0 -74
  28. package/dist/helpers/iterators.js.map +0 -1
  29. package/dist/helpers/serialize-error.d.ts +0 -20
  30. package/dist/helpers/serialize-error.js +0 -135
  31. package/dist/helpers/serialize-error.js.map +0 -1
  32. package/dist/helpers/time.d.ts +0 -54
  33. package/dist/helpers/time.js +0 -121
  34. package/dist/helpers/time.js.map +0 -1
  35. package/dist/helpers/values.d.ts +0 -68
  36. package/dist/helpers/values.js +0 -165
  37. package/dist/helpers/values.js.map +0 -1
  38. package/dist/helpers/worker-thread-init.d.ts +0 -1
  39. package/dist/helpers/worker-thread-init.js +0 -67
  40. package/dist/helpers/worker-thread-init.js.map +0 -1
  41. package/dist/helpers/worker-thread-manager.d.ts +0 -53
  42. package/dist/helpers/worker-thread-manager.js +0 -148
  43. package/dist/helpers/worker-thread-manager.js.map +0 -1
  44. package/dist/index.d.ts +0 -7
  45. package/dist/index.js +0 -24
  46. package/dist/index.js.map +0 -1
  47. package/dist/logger/index.d.ts +0 -20
  48. package/dist/logger/index.js +0 -14
  49. package/dist/logger/index.js.map +0 -1
  50. package/dist/postgres/base-pg-store.d.ts +0 -68
  51. package/dist/postgres/base-pg-store.js +0 -109
  52. package/dist/postgres/base-pg-store.js.map +0 -1
  53. package/dist/postgres/connection.d.ts +0 -62
  54. package/dist/postgres/connection.js +0 -126
  55. package/dist/postgres/connection.js.map +0 -1
  56. package/dist/postgres/errors.d.ts +0 -5
  57. package/dist/postgres/errors.js +0 -71
  58. package/dist/postgres/errors.js.map +0 -1
  59. package/dist/postgres/index.d.ts +0 -5
  60. package/dist/postgres/index.js +0 -22
  61. package/dist/postgres/index.js.map +0 -1
  62. package/dist/postgres/migrations.d.ts +0 -47
  63. package/dist/postgres/migrations.js +0 -134
  64. package/dist/postgres/migrations.js.map +0 -1
  65. package/dist/postgres/types.d.ts +0 -14
  66. package/dist/postgres/types.js +0 -48
  67. package/dist/postgres/types.js.map +0 -1
  68. package/dist/profiler/index.d.ts +0 -2
  69. package/dist/profiler/index.js +0 -19
  70. package/dist/profiler/index.js.map +0 -1
  71. package/dist/profiler/inspector-util.d.ts +0 -29
  72. package/dist/profiler/inspector-util.js +0 -268
  73. package/dist/profiler/inspector-util.js.map +0 -1
  74. package/dist/profiler/server.d.ts +0 -6
  75. package/dist/profiler/server.js +0 -186
  76. package/dist/profiler/server.js.map +0 -1
  77. package/dist/server-version/index.d.ts +0 -8
  78. package/dist/server-version/index.js +0 -33
  79. package/dist/server-version/index.js.map +0 -1
  80. package/dist/shutdown-handler/index.d.ts +0 -17
  81. package/dist/shutdown-handler/index.js +0 -82
  82. package/dist/shutdown-handler/index.js.map +0 -1
@@ -1,135 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.addKnownErrorConstructor = addKnownErrorConstructor;
7
- exports.isErrorLike = isErrorLike;
8
- exports.serializeError = serializeError;
9
- exports.deserializeError = deserializeError;
10
- const errorConstructors = new Map([
11
- // Native ES errors https://262.ecma-international.org/12.0/#sec-well-known-intrinsic-objects
12
- Error,
13
- EvalError,
14
- RangeError,
15
- ReferenceError,
16
- SyntaxError,
17
- TypeError,
18
- URIError,
19
- AggregateError,
20
- // Built-in errors
21
- globalThis.DOMException,
22
- // Node-specific errors https://nodejs.org/api/errors.html
23
- globalThis.AssertionError,
24
- globalThis.SystemError,
25
- ]
26
- // Non-native Errors are used with `globalThis` because they might be missing. This filter drops them when undefined.
27
- .filter(Boolean)
28
- .map(constructor => [constructor.name, constructor]));
29
- /**
30
- * Custom errors can only be deserialized correctly if they are registered here.
31
- */
32
- function addKnownErrorConstructor(constructor) {
33
- try {
34
- new constructor();
35
- }
36
- catch (error) {
37
- throw new Error(`The error constructor "${constructor.name}" is not compatible`, {
38
- cause: error,
39
- });
40
- }
41
- errorConstructors.set(constructor.name, constructor);
42
- }
43
- const commonProperties = {
44
- name: false,
45
- message: false,
46
- stack: false,
47
- code: true,
48
- cause: false,
49
- errors: false,
50
- };
51
- function isErrorLike(value) {
52
- return (typeof value === 'object' &&
53
- value !== null &&
54
- 'name' in value &&
55
- 'message' in value &&
56
- 'stack' in value &&
57
- typeof value.name === 'string' &&
58
- typeof value.message === 'string' &&
59
- typeof value.stack === 'string');
60
- }
61
- function serializeError(subject) {
62
- if (!isErrorLike(subject)) {
63
- // If the subject is not an error, for example `throw "boom", then we throw.
64
- // This function should only be passed error objects, callers can use `isErrorLike`.
65
- throw new TypeError('Failed to serialize error, expected an error object');
66
- }
67
- const data = {
68
- constructorName: subject.constructor.name ?? 'Error', // new field
69
- name: subject.name,
70
- message: '',
71
- stack: '',
72
- };
73
- for (const key of Object.keys(commonProperties)) {
74
- if (key in subject)
75
- data[key] = deepSerialize(subject[key]);
76
- }
77
- // Include any other enumerable own properties
78
- for (const key of Object.keys(subject)) {
79
- if (!(key in data))
80
- data[key] = deepSerialize(subject[key]);
81
- }
82
- return data;
83
- }
84
- function deserializeError(subject) {
85
- if (!isErrorLike(subject)) {
86
- // If the subject is not an error, for example `throw "boom", then we throw.
87
- // This function should only be passed error objects, callers can use `isErrorLike`.
88
- throw new TypeError('Failed to desserialize error, expected an error object');
89
- }
90
- let con = errorConstructors.get(subject.constructorName ?? subject.name);
91
- if (!con) {
92
- // If the constructor is not found, use the generic Error constructor
93
- con = Error;
94
- console.error(`Error constructor "${subject.name}" not found during worker error deserialization, using generic Error constructor`);
95
- }
96
- const output = Object.create(con.prototype);
97
- for (const [key, enumerable] of Object.entries(commonProperties)) {
98
- if (key in subject) {
99
- Object.defineProperty(output, key, {
100
- enumerable,
101
- configurable: true,
102
- writable: true,
103
- value: deepDeserialize(subject[key]),
104
- });
105
- }
106
- }
107
- // Add any other properties (custom props not in commonProperties)
108
- for (const key of Object.keys(subject)) {
109
- if (!(key in commonProperties)) {
110
- output[key] = deepDeserialize(subject[key]);
111
- }
112
- }
113
- return output;
114
- }
115
- function deepSerialize(value) {
116
- if (Array.isArray(value))
117
- return value.map(deepSerialize);
118
- if (isErrorLike(value))
119
- return serializeError(value);
120
- if (value && typeof value === 'object') {
121
- return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, deepSerialize(v)]));
122
- }
123
- return value;
124
- }
125
- function deepDeserialize(value) {
126
- if (Array.isArray(value))
127
- return value.map(deepDeserialize);
128
- if (isErrorLike(value))
129
- return deserializeError(value);
130
- if (value && typeof value === 'object') {
131
- return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, deepDeserialize(v)]));
132
- }
133
- return value;
134
- }
135
- //# sourceMappingURL=serialize-error.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialize-error.js","sourceRoot":"","sources":["../../src/helpers/serialize-error.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,uDAAuD;AACvD,4DAA4D;;AA6B5D,4DAWC;AAyBD,kCAWC;AAED,wCAwBC;AAED,4CAoCC;AA1ID,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAC/B;IACE,6FAA6F;IAC7F,KAAK;IACL,SAAS;IACT,UAAU;IACV,cAAc;IACd,WAAW;IACX,SAAS;IACT,QAAQ;IACR,cAAc;IAEd,kBAAkB;IAClB,UAAU,CAAC,YAAY;IAEvB,0DAA0D;IACzD,UAAkB,CAAC,cAAuB;IAC1C,UAAkB,CAAC,WAAoB;CACzC;IACC,qHAAqH;KACpH,MAAM,CAAC,OAAO,CAAC;KACf,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,WAA+B,CAAU,CAAC,CACpF,CAAC;AAEF;;GAEG;AACH,SAAgB,wBAAwB,CACtC,WAAsE;IAEtE,IAAI,CAAC;QACH,IAAI,WAAW,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,0BAA0B,WAAW,CAAC,IAAI,qBAAqB,EAAE;YAC/E,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IACD,iBAAiB,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,WAA+B,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,gBAAgB,GAA4B;IAChD,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE,KAAK;CACd,CAAC;AAgBF,SAAgB,WAAW,CAAC,KAAc;IACxC,O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IAC1D,IAAI,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IACrD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC5D,IAAI,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACvD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,54 +0,0 @@
1
- /**
2
- * Wait a set amount of milliseconds or until the timer is aborted.
3
- * @param ms - Number of milliseconds to wait
4
- * @param abort - Abort controller
5
- * @returns Promise
6
- */
7
- export declare function timeout(ms: number, abort?: AbortController | AbortSignal): Promise<void>;
8
- /**
9
- * Time the execution of an async function.
10
- * @param fn - Async function
11
- * @param onFinish - Callback with elapsed milliseconds
12
- * @returns Promise
13
- */
14
- export declare function time<T>(fn: () => Promise<T>, onFinish: (elapsedMs: number) => void): Promise<T>;
15
- /**
16
- * Set an execution time limit for a promise.
17
- * @param promise - The promise being capped to `timeoutMs` max execution time
18
- * @param timeoutMs - Timeout limit in milliseconds
19
- * @param wait - If we should wait another `timeoutMs` period for `promise` to resolve
20
- * @param waitHandler - If `wait` is `true`, this closure will be executed before waiting another
21
- * `timeoutMs` cycle
22
- * @returns `true` if `promise` ended gracefully, `false` if timeout was reached
23
- */
24
- export declare function resolveOrTimeout(promise: Promise<void>, timeoutMs: number, wait?: boolean, waitHandler?: () => void): Promise<unknown>;
25
- export interface Stopwatch {
26
- /** Milliseconds since stopwatch was created. */
27
- getElapsed: () => number;
28
- /** Seconds since stopwatch was created. */
29
- getElapsedSeconds: () => number;
30
- getElapsedAndRestart: () => number;
31
- restart(): void;
32
- }
33
- /**
34
- * Start a `Stopwatch` that measures elapsed time based on `process.hrtime`.
35
- * @returns Stopwatch
36
- */
37
- export declare function stopwatch(): Stopwatch;
38
- export type Waiter<T = void, E = Error> = Promise<T> & {
39
- /** Alias for `resolve` */
40
- finish: (result: T) => void;
41
- resolve: (result: T) => void;
42
- reject: (error: E) => void;
43
- /** True if the promise is resolved or rejected */
44
- isFinished: boolean;
45
- /** True only if the promise is resolved */
46
- isResolved: boolean;
47
- /** True only if the promise is rejected */
48
- isRejected: boolean;
49
- };
50
- /**
51
- * Creates a `Waiter` promise that can be resolved or rejected at a later time.
52
- * @returns Waiter
53
- */
54
- export declare function waiter<T = void, E = Error>(): Waiter<T, E>;
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.timeout = timeout;
4
- exports.time = time;
5
- exports.resolveOrTimeout = resolveOrTimeout;
6
- exports.stopwatch = stopwatch;
7
- exports.waiter = waiter;
8
- const promises_1 = require("node:timers/promises");
9
- /**
10
- * Wait a set amount of milliseconds or until the timer is aborted.
11
- * @param ms - Number of milliseconds to wait
12
- * @param abort - Abort controller
13
- * @returns Promise
14
- */
15
- function timeout(ms, abort) {
16
- const signal = abort && (abort instanceof AbortSignal ? abort : abort.signal);
17
- return (0, promises_1.setTimeout)(ms, undefined, { signal });
18
- }
19
- /**
20
- * Time the execution of an async function.
21
- * @param fn - Async function
22
- * @param onFinish - Callback with elapsed milliseconds
23
- * @returns Promise
24
- */
25
- async function time(fn, onFinish) {
26
- const watch = stopwatch();
27
- try {
28
- return await fn();
29
- }
30
- finally {
31
- onFinish(watch.getElapsed());
32
- }
33
- }
34
- /**
35
- * Set an execution time limit for a promise.
36
- * @param promise - The promise being capped to `timeoutMs` max execution time
37
- * @param timeoutMs - Timeout limit in milliseconds
38
- * @param wait - If we should wait another `timeoutMs` period for `promise` to resolve
39
- * @param waitHandler - If `wait` is `true`, this closure will be executed before waiting another
40
- * `timeoutMs` cycle
41
- * @returns `true` if `promise` ended gracefully, `false` if timeout was reached
42
- */
43
- async function resolveOrTimeout(promise, timeoutMs, wait = false, waitHandler) {
44
- let timer;
45
- const result = await Promise.race([
46
- new Promise((resolve, reject) => {
47
- promise
48
- .then(() => resolve(true))
49
- .catch(error => reject(error))
50
- .finally(() => clearTimeout(timer));
51
- }),
52
- new Promise((resolve, _) => {
53
- timer = setInterval(() => {
54
- if (!wait) {
55
- clearTimeout(timer);
56
- resolve(false);
57
- return;
58
- }
59
- if (waitHandler) {
60
- waitHandler();
61
- }
62
- }, timeoutMs);
63
- }),
64
- ]);
65
- return result;
66
- }
67
- /**
68
- * Start a `Stopwatch` that measures elapsed time based on `process.hrtime`.
69
- * @returns Stopwatch
70
- */
71
- function stopwatch() {
72
- let start = process.hrtime.bigint();
73
- const result = {
74
- getElapsedSeconds: () => {
75
- const elapsedMs = result.getElapsed();
76
- return elapsedMs / 1000;
77
- },
78
- getElapsed: () => {
79
- const end = process.hrtime.bigint();
80
- return Number((end - start) / 1000000n);
81
- },
82
- getElapsedAndRestart: () => {
83
- const end = process.hrtime.bigint();
84
- const result = Number((end - start) / 1000000n);
85
- start = process.hrtime.bigint();
86
- return result;
87
- },
88
- restart: () => {
89
- start = process.hrtime.bigint();
90
- },
91
- };
92
- return result;
93
- }
94
- /**
95
- * Creates a `Waiter` promise that can be resolved or rejected at a later time.
96
- * @returns Waiter
97
- */
98
- function waiter() {
99
- let resolveFn;
100
- let rejectFn;
101
- const promise = new Promise((resolve, reject) => {
102
- resolveFn = resolve;
103
- rejectFn = reject;
104
- });
105
- const completer = {
106
- finish: (result) => completer.resolve(result),
107
- resolve: (result) => {
108
- void Object.assign(promise, { isFinished: true, isResolved: true });
109
- resolveFn(result);
110
- },
111
- reject: (error) => {
112
- void Object.assign(promise, { isFinished: true, isRejected: true });
113
- rejectFn(error);
114
- },
115
- isFinished: false,
116
- isResolved: false,
117
- isRejected: false,
118
- };
119
- return Object.assign(promise, completer);
120
- }
121
- //# sourceMappingURL=time.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/helpers/time.ts"],"names":[],"mappings":";;AAQA,0BAGC;AAQD,oBAUC;AAWD,4CA4BC;AAeD,8BAsBC;AAmBD,wBAsBC;AAlJD,mDAAqE;AAErE;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,EAAU,EAAE,KAAqC;IACvE,MAAM,MAAM,GAAG,KAAK,IAAI,CAAC,KAAK,YAAY,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9E,OAAO,IAAA,qBAAe,EAAC,EAAE,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,IAAI,CACxB,EAAoB,EACpB,QAAqC;IAErC,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,QAAQ,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC;AAED;;;;;;;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,CAAC,CAAC;YACpE,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;QACD,UAAU,EAAE,KAAK;QACjB,UAAU,EAAE,KAAK;QACjB,UAAU,EAAE,KAAK;KAClB,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAC3C,CAAC"}
@@ -1,68 +0,0 @@
1
- export declare const isDevEnv: boolean;
2
- export declare const isTestEnv: boolean;
3
- export declare const isProdEnv: boolean;
4
- /**
5
- * Digests a string value into a SHA256 hash.
6
- * @param content - String input
7
- * @returns Hashed value
8
- */
9
- export declare function sha256(content: string): string;
10
- /**
11
- * Parses a boolean string using conventions from CLI arguments, URL query params, and environmental
12
- * variables. If the input is defined but empty string then true is returned. If the input is
13
- * undefined or null than false is returned. For example, if the input comes from a CLI arg like
14
- * `--enable_thing` or URL query param like `?enable_thing`, then this function expects to receive a
15
- * defined but empty string, and returns true. Otherwise, it checks or values like `true`, `1`,
16
- * `on`, `yes` (and the inverses). Throws if an unexpected input value is provided.
17
- */
18
- export declare function parseBoolean(val: string | undefined | null): boolean;
19
- /**
20
- * Encodes a buffer as a `0x` prefixed lower-case hex string. Returns an empty string if the buffer
21
- * is zero length.
22
- */
23
- export declare function bufferToHex(buff: Buffer, prefix?: boolean): string;
24
- /**
25
- * Decodes a `0x` prefixed hex string to a buffer.
26
- * @param hex - A hex string with a `0x` prefix.
27
- */
28
- export declare function hexToBuffer(hex: string): Buffer;
29
- /**
30
- * Decodes a hex string to a Buffer, trims the 0x-prefix if exists.
31
- * If already a buffer, returns the input immediately.
32
- */
33
- export declare function coerceToBuffer(hex: string | Buffer | ArrayBufferView): Buffer;
34
- /**
35
- * Converts a hex string into a UTF-8 string.
36
- * @param hex - Hex string
37
- * @returns UTF-8 string
38
- */
39
- export declare function hexToUtf8String(hex: string): string;
40
- /**
41
- * Converts a number to a hex string.
42
- * @param number - Number
43
- * @param paddingBytes - Padding bytes
44
- * @returns Hex string
45
- */
46
- export declare function numberToHex(number: number, paddingBytes?: number): string;
47
- /**
48
- * Checks if a string has `0x` prefix.
49
- * @param val - Hex string
50
- * @returns Boolean
51
- */
52
- export declare const has0xPrefix: (val: string) => boolean;
53
- /**
54
- * Converts a string to an enum value.
55
- * @param enumType - The enum type
56
- * @param value - The string value to convert
57
- * @returns Enum item or undefined
58
- */
59
- export declare function toEnumValue<T>(enm: {
60
- [s: string]: T;
61
- }, value: string): T | undefined;
62
- /**
63
- * Unwraps a value that may be undefined or null.
64
- * @param val - The value to unwrap
65
- * @param onNullish - Callback to throw an error if the value is null or undefined
66
- * @returns The unwrapped value
67
- */
68
- export declare function unwrap<T>(val: T | null, onNullish?: () => string): Exclude<T, undefined | null>;
@@ -1,165 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.has0xPrefix = exports.isProdEnv = exports.isTestEnv = exports.isDevEnv = void 0;
4
- exports.sha256 = sha256;
5
- exports.parseBoolean = parseBoolean;
6
- exports.bufferToHex = bufferToHex;
7
- exports.hexToBuffer = hexToBuffer;
8
- exports.coerceToBuffer = coerceToBuffer;
9
- exports.hexToUtf8String = hexToUtf8String;
10
- exports.numberToHex = numberToHex;
11
- exports.toEnumValue = toEnumValue;
12
- exports.unwrap = unwrap;
13
- const node_crypto_1 = require("node:crypto");
14
- const types_1 = require("node:util/types");
15
- exports.isDevEnv = process.env.NODE_ENV === 'development';
16
- exports.isTestEnv = process.env.NODE_ENV === 'test';
17
- exports.isProdEnv = process.env.NODE_ENV === 'production' ||
18
- process.env.NODE_ENV === 'prod' ||
19
- !process.env.NODE_ENV ||
20
- (!exports.isTestEnv && !exports.isDevEnv);
21
- /**
22
- * Digests a string value into a SHA256 hash.
23
- * @param content - String input
24
- * @returns Hashed value
25
- */
26
- function sha256(content) {
27
- return (0, node_crypto_1.createHash)('sha256').update(content).digest('hex');
28
- }
29
- /**
30
- * Parses a boolean string using conventions from CLI arguments, URL query params, and environmental
31
- * variables. If the input is defined but empty string then true is returned. If the input is
32
- * undefined or null than false is returned. For example, if the input comes from a CLI arg like
33
- * `--enable_thing` or URL query param like `?enable_thing`, then this function expects to receive a
34
- * defined but empty string, and returns true. Otherwise, it checks or values like `true`, `1`,
35
- * `on`, `yes` (and the inverses). Throws if an unexpected input value is provided.
36
- */
37
- function parseBoolean(val) {
38
- if (typeof val === 'undefined' || val === null) {
39
- return false;
40
- }
41
- switch (val.trim().toLowerCase()) {
42
- case '':
43
- case 'true':
44
- case '1':
45
- case 'on':
46
- case 'yes':
47
- return true;
48
- case 'false':
49
- case '0':
50
- case 'off':
51
- case 'no':
52
- return false;
53
- default:
54
- throw new Error(`Cannot parse boolean`);
55
- }
56
- }
57
- /**
58
- * Encodes a buffer as a `0x` prefixed lower-case hex string. Returns an empty string if the buffer
59
- * is zero length.
60
- */
61
- function bufferToHex(buff, prefix = true) {
62
- return buff.length === 0 ? '' : (prefix ? '0x' : '') + buff.toString('hex');
63
- }
64
- /**
65
- * Decodes a `0x` prefixed hex string to a buffer.
66
- * @param hex - A hex string with a `0x` prefix.
67
- */
68
- function hexToBuffer(hex) {
69
- if (hex.length === 0) {
70
- return Buffer.alloc(0);
71
- }
72
- if (!hex.startsWith('0x')) {
73
- throw new Error(`Hex string is missing the "0x" prefix`);
74
- }
75
- if (hex.length % 2 !== 0) {
76
- throw new Error(`Hex string is an odd number of digits`);
77
- }
78
- return Buffer.from(hex.substring(2), 'hex');
79
- }
80
- /**
81
- * Decodes a hex string to a Buffer, trims the 0x-prefix if exists.
82
- * If already a buffer, returns the input immediately.
83
- */
84
- function coerceToBuffer(hex) {
85
- if (typeof hex === 'string') {
86
- if (hex.startsWith('0x')) {
87
- hex = hex.substring(2);
88
- }
89
- if (hex.length % 2 !== 0) {
90
- throw new Error(`Hex string is an odd number of characters`);
91
- }
92
- if (!/^[0-9a-fA-F]*$/.test(hex)) {
93
- throw new Error(`Hex string contains non-hexadecimal characters`);
94
- }
95
- return Buffer.from(hex, 'hex');
96
- }
97
- else if (Buffer.isBuffer(hex)) {
98
- return hex;
99
- }
100
- else if ((0, types_1.isArrayBufferView)(hex)) {
101
- return Buffer.from(hex.buffer, hex.byteOffset, hex.byteLength);
102
- }
103
- else {
104
- throw new Error(`Cannot convert to Buffer, unexpected type: ${hex.constructor.name}`);
105
- }
106
- }
107
- /**
108
- * Converts a hex string into a UTF-8 string.
109
- * @param hex - Hex string
110
- * @returns UTF-8 string
111
- */
112
- function hexToUtf8String(hex) {
113
- const buffer = hexToBuffer(hex);
114
- return buffer.toString('utf8');
115
- }
116
- /**
117
- * Converts a number to a hex string.
118
- * @param number - Number
119
- * @param paddingBytes - Padding bytes
120
- * @returns Hex string
121
- */
122
- function numberToHex(number, paddingBytes = 4) {
123
- let result = number.toString(16);
124
- if (result.length % 2 > 0) {
125
- result = '0' + result;
126
- }
127
- if (paddingBytes && result.length / 2 < paddingBytes) {
128
- result = '00'.repeat(paddingBytes - result.length / 2) + result;
129
- }
130
- return '0x' + result;
131
- }
132
- /**
133
- * Checks if a string has `0x` prefix.
134
- * @param val - Hex string
135
- * @returns Boolean
136
- */
137
- const has0xPrefix = (val) => val.substring(0, 2).toLowerCase() === '0x';
138
- exports.has0xPrefix = has0xPrefix;
139
- /**
140
- * Converts a string to an enum value.
141
- * @param enumType - The enum type
142
- * @param value - The string value to convert
143
- * @returns Enum item or undefined
144
- */
145
- function toEnumValue(enm, value) {
146
- return Object.values(enm).includes(value)
147
- ? value
148
- : undefined;
149
- }
150
- /**
151
- * Unwraps a value that may be undefined or null.
152
- * @param val - The value to unwrap
153
- * @param onNullish - Callback to throw an error if the value is null or undefined
154
- * @returns The unwrapped value
155
- */
156
- function unwrap(val, onNullish) {
157
- if (val === undefined) {
158
- throw new Error(onNullish?.() ?? 'value is undefined');
159
- }
160
- if (val === null) {
161
- throw new Error(onNullish?.() ?? 'value is null');
162
- }
163
- return val;
164
- }
165
- //# sourceMappingURL=values.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"values.js","sourceRoot":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;AACvB,CAAC;AAED;;;;GAIG;AACI,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC;AAA1E,QAAA,WAAW,eAA+D;AAEvF;;;;;GAKG;AACH,SAAgB,WAAW,CAAI,GAAuB,EAAE,KAAa;IACnE,OAAQ,MAAM,CAAC,MAAM,CAAC,GAAG,CAAyB,CAAC,QAAQ,CAAC,KAAK,CAAC;QAChE,CAAC,CAAE,KAAsB;QACzB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,MAAM,CAAI,GAAa,EAAE,SAAwB;IAC/D,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,IAAI,oBAAoB,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,IAAI,eAAe,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,GAAmC,CAAC;AAC7C,CAAC"}
@@ -1 +0,0 @@
1
- export declare const filename: string;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filename = void 0;
4
- const WorkerThreads = require("node:worker_threads");
5
- const serialize_error_1 = require("./serialize-error");
6
- // Minimal worker thread initialization code. This file is the entry point for worker threads
7
- // and is responsible for setting up the worker environment and handling messages from the main thread.
8
- // Imports should be kept to a minimum to avoid in worker thread init overhead and memory usage.
9
- exports.filename = __filename;
10
- /**
11
- * Invokes a function that may return a value or a promise, and passes the result
12
- * to a callback in a consistent format. Handles both synchronous and asynchronous cases,
13
- * ensuring type safety and avoiding unnecessary async transitions for sync functions.
14
- */
15
- function getMaybePromiseResult(fn, cb) {
16
- try {
17
- const maybePromise = fn();
18
- if (maybePromise instanceof Promise) {
19
- maybePromise.then(ok => cb({ ok }), (err) => cb({ err }));
20
- }
21
- else {
22
- cb({ ok: maybePromise });
23
- }
24
- }
25
- catch (err) {
26
- cb({ err });
27
- }
28
- }
29
- // Check if this file is being run in a worker thread. If so, it will set up the worker environment.
30
- if (!WorkerThreads.isMainThread && WorkerThreads.workerData?.workerFile) {
31
- const { workerFile } = WorkerThreads.workerData;
32
- // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
33
- const workerModule = require(workerFile);
34
- const parentPort = WorkerThreads.parentPort;
35
- // Determine if the worker module `processTask` function is a default export or a named export.
36
- const processTask = 'default' in workerModule ? workerModule.default.processTask : workerModule.processTask;
37
- parentPort.on('messageerror', err => {
38
- console.error(`Worker thread message error`, err);
39
- });
40
- parentPort.on('message', (message) => {
41
- const msg = message;
42
- getMaybePromiseResult(() => processTask(...msg.req), result => {
43
- try {
44
- let reply;
45
- if (result.ok) {
46
- reply = {
47
- msgId: msg.msgId,
48
- resp: result.ok,
49
- };
50
- }
51
- else {
52
- const error = (0, serialize_error_1.isErrorLike)(result.err) ? (0, serialize_error_1.serializeError)(result.err) : result.err;
53
- reply = {
54
- msgId: msg.msgId,
55
- error,
56
- };
57
- }
58
- parentPort.postMessage(reply);
59
- }
60
- catch (err) {
61
- console.error(`Critical bug in work task processing`, err);
62
- }
63
- });
64
- });
65
- parentPort.postMessage('ready');
66
- }
67
- //# sourceMappingURL=worker-thread-init.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker-thread-init.js","sourceRoot":"","sources":["../../src/helpers/worker-thread-init.ts"],"names":[],"mappings":";;;AAAA,qDAAqD;AAOrD,uDAAgE;AAEhE,6FAA6F;AAC7F,uGAAuG;AACvG,gGAAgG;AAEnF,QAAA,QAAQ,GAAG,UAAU,CAAC;AAEnC;;;;GAIG;AACH,SAAS,qBAAqB,CAC5B,EAAwB,EACxB,EAAyE;IAEzE,IAAI,CAAC;QACH,MAAM,YAA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