@mrxsys/mrx-core 2.11.0-2-and-276-20251029 → 2.11.0-2-and-277-20251030

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 (147) hide show
  1. package/dist/chunk-0d0zd2yg.js +8 -0
  2. package/dist/chunk-12qzn7jw.js +7 -0
  3. package/dist/chunk-441xs5k1.js +53 -0
  4. package/dist/chunk-4v86f7gp.js +59 -0
  5. package/dist/chunk-6w9ja96e.js +9 -0
  6. package/dist/chunk-7t524zqh.js +26 -0
  7. package/dist/chunk-8tffnbpn.js +7 -0
  8. package/dist/chunk-9cgzhc50.js +15 -0
  9. package/dist/chunk-9d3zvgp6.js +9 -0
  10. package/dist/chunk-9dzsj7f2.js +23 -0
  11. package/dist/chunk-9r5anep5.js +11 -0
  12. package/dist/chunk-afd82epa.js +201 -0
  13. package/dist/chunk-afyz8rg5.js +209 -0
  14. package/dist/chunk-dre2fgj0.js +7 -0
  15. package/dist/chunk-e30paw8a.js +101 -0
  16. package/dist/chunk-eeb7yskp.js +61 -0
  17. package/dist/chunk-fs3wm3p4.js +32 -0
  18. package/dist/chunk-grfyngq0.js +39 -0
  19. package/dist/chunk-gtn1kn0z.js +79 -0
  20. package/dist/chunk-jksb9ers.js +7 -0
  21. package/dist/chunk-m3grz32t.js +27 -0
  22. package/dist/chunk-mvrxngm7.js +41 -0
  23. package/dist/chunk-n0n14mf8.js +7 -0
  24. package/dist/chunk-p14h6jfs.js +365 -0
  25. package/dist/chunk-pjv1ekwr.js +284 -0
  26. package/dist/chunk-rz5p4j3p.js +13 -0
  27. package/dist/chunk-spnh9dzk.js +10 -0
  28. package/dist/chunk-sqts8vyk.js +60 -0
  29. package/dist/chunk-w7h898m3.js +14 -0
  30. package/dist/chunk-xhhj1gvj.js +9 -0
  31. package/dist/chunk-z0ct35ft.js +8 -0
  32. package/dist/errors/enums/index.js +7 -0
  33. package/dist/errors/index.js +12 -0
  34. package/dist/errors/utils/index.js +16 -0
  35. package/dist/errors/utils/is-nowarajs-error.ts.d.ts +2 -2
  36. package/dist/modules/data/enums/index.js +7 -0
  37. package/dist/modules/data/index.js +17 -0
  38. package/dist/modules/data/transformers/camel-case.d.ts +2 -2
  39. package/dist/modules/data/transformers/index.js +32 -0
  40. package/dist/modules/data/transformers/kebab-case.d.ts +2 -2
  41. package/dist/modules/data/transformers/pascal-case.d.ts +2 -2
  42. package/dist/modules/data/transformers/snake-case.d.ts +2 -2
  43. package/dist/modules/data/types/index.js +1 -0
  44. package/dist/modules/data/types/transform-object-keys.d.ts +4 -4
  45. package/dist/modules/database/enums/index.js +9 -0
  46. package/dist/modules/database/events/index.js +1 -0
  47. package/dist/modules/database/events/mssql-event-map.d.ts +1 -1
  48. package/dist/modules/database/events/table-event-map.d.ts +1 -1
  49. package/dist/modules/database/index.js +16 -0
  50. package/dist/modules/database/mssql.d.ts +2 -2
  51. package/dist/modules/database/table.d.ts +2 -2
  52. package/dist/modules/database/types/index.js +1 -0
  53. package/dist/modules/elysia/cache/cache.d.ts +1 -1
  54. package/dist/modules/elysia/cache/index.js +90 -0
  55. package/dist/modules/elysia/cache/types/index.js +1 -0
  56. package/dist/modules/elysia/crud/crud.d.ts +2 -2
  57. package/dist/modules/elysia/crud/enums/index.js +7 -0
  58. package/dist/modules/elysia/crud/index.js +153 -0
  59. package/dist/modules/elysia/crud/operations/count.d.ts +3 -3
  60. package/dist/modules/elysia/crud/operations/delete.d.ts +3 -3
  61. package/dist/modules/elysia/crud/operations/deleteOne.d.ts +3 -3
  62. package/dist/modules/elysia/crud/operations/find.d.ts +3 -3
  63. package/dist/modules/elysia/crud/operations/findOne.d.ts +3 -3
  64. package/dist/modules/elysia/crud/operations/index.js +34 -0
  65. package/dist/modules/elysia/crud/operations/insert.d.ts +3 -3
  66. package/dist/modules/elysia/crud/operations/update.d.ts +3 -3
  67. package/dist/modules/elysia/crud/operations/updateOne.d.ts +3 -3
  68. package/dist/modules/elysia/crud/operations/utils/get-db-injection.d.ts +1 -1
  69. package/dist/modules/elysia/crud/types/crud-options.d.ts +1 -1
  70. package/dist/modules/elysia/crud/types/crud-schema-models-type.d.ts +9 -9
  71. package/dist/modules/elysia/crud/types/delete-schema.d.ts +2 -2
  72. package/dist/modules/elysia/crud/types/find-schema.d.ts +3 -3
  73. package/dist/modules/elysia/crud/types/index.js +1 -0
  74. package/dist/modules/elysia/crud/types/insert-schema.d.ts +1 -1
  75. package/dist/modules/elysia/crud/types/properties-schema.d.ts +1 -1
  76. package/dist/modules/elysia/crud/types/response-200-schema.d.ts +1 -1
  77. package/dist/modules/elysia/crud/types/update-schema.d.ts +2 -2
  78. package/dist/modules/elysia/crud/utils/create-adaptive-where-clause-schema.d.ts +1 -1
  79. package/dist/modules/elysia/crud/utils/create-count-response-200-schema.d.ts +1 -1
  80. package/dist/modules/elysia/crud/utils/create-count-schema.d.ts +1 -1
  81. package/dist/modules/elysia/crud/utils/create-delete-schema.d.ts +1 -1
  82. package/dist/modules/elysia/crud/utils/create-filters-schema.d.ts +1 -1
  83. package/dist/modules/elysia/crud/utils/create-find-schema.d.ts +1 -1
  84. package/dist/modules/elysia/crud/utils/create-id-param-schema.d.ts +1 -1
  85. package/dist/modules/elysia/crud/utils/create-insert-schema.d.ts +1 -1
  86. package/dist/modules/elysia/crud/utils/create-order-schema.d.ts +1 -1
  87. package/dist/modules/elysia/crud/utils/create-properties-schema.d.ts +1 -1
  88. package/dist/modules/elysia/crud/utils/create-q-schema.d.ts +1 -1
  89. package/dist/modules/elysia/crud/utils/create-response-200-schema.d.ts +1 -1
  90. package/dist/modules/elysia/crud/utils/create-selected-fields-schema.d.ts +1 -1
  91. package/dist/modules/elysia/crud/utils/create-update-one-schema.d.ts +1 -1
  92. package/dist/modules/elysia/crud/utils/create-update-schema.d.ts +1 -1
  93. package/dist/modules/elysia/crud/utils/index.js +41 -0
  94. package/dist/modules/elysia/db-resolver/db-resolver.d.ts +2 -2
  95. package/dist/modules/elysia/db-resolver/enums/index.js +7 -0
  96. package/dist/modules/elysia/db-resolver/index.js +18 -0
  97. package/dist/modules/elysia/error/enums/index.js +7 -0
  98. package/dist/modules/elysia/error/error.d.ts +51 -0
  99. package/dist/modules/elysia/error/index.js +76 -0
  100. package/dist/modules/elysia/microservice/enums/index.js +7 -0
  101. package/dist/modules/elysia/microservice/index.js +100 -0
  102. package/dist/modules/elysia/rate-limit/enums/index.js +7 -0
  103. package/dist/modules/elysia/rate-limit/index.js +81 -0
  104. package/dist/modules/elysia/rate-limit/rate-limit.d.ts +1 -1
  105. package/dist/modules/elysia/rate-limit/types/index.js +1 -0
  106. package/dist/modules/jwt/enums/index.js +11 -0
  107. package/dist/modules/jwt/index.js +51 -0
  108. package/dist/modules/jwt/utils/index.js +9 -0
  109. package/dist/modules/kv-store/bun-redis/bun-redis-store.d.ts +1 -1
  110. package/dist/modules/kv-store/bun-redis/index.js +84 -0
  111. package/dist/modules/kv-store/enums/index.js +7 -0
  112. package/dist/modules/kv-store/ioredis/index.js +86 -0
  113. package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +1 -1
  114. package/dist/modules/kv-store/memory/index.js +9 -0
  115. package/dist/modules/kv-store/memory/memory-store.d.ts +1 -1
  116. package/dist/modules/kv-store/types/index.js +1 -0
  117. package/dist/modules/logger/enums/index.js +7 -0
  118. package/dist/modules/logger/events/index.js +1 -0
  119. package/dist/modules/logger/events/logger-events.d.ts +1 -1
  120. package/dist/modules/logger/index.js +282 -0
  121. package/dist/modules/logger/logger.d.ts +1 -1
  122. package/dist/modules/logger/sinks/console-logger.d.ts +2 -2
  123. package/dist/modules/logger/sinks/devnull-logger.d.ts +1 -1
  124. package/dist/modules/logger/sinks/file-logger/file-logger.d.ts +2 -2
  125. package/dist/modules/logger/sinks/index.js +66 -0
  126. package/dist/modules/logger/types/index.js +1 -0
  127. package/dist/modules/logger/worker-logger.d.ts +1 -0
  128. package/dist/modules/mailer/enums/index.js +7 -0
  129. package/dist/modules/mailer/index.js +55 -0
  130. package/dist/modules/mailer/types/index.js +1 -0
  131. package/dist/modules/repository/index.js +12 -0
  132. package/dist/modules/repository/repository.d.ts +2 -2
  133. package/dist/modules/repository/types/index.js +1 -0
  134. package/dist/modules/repository/types/query-options.d.ts +1 -1
  135. package/dist/modules/singleton-manager/enums/index.js +7 -0
  136. package/dist/modules/singleton-manager/index.js +9 -0
  137. package/dist/modules/totp/enums/index.js +7 -0
  138. package/dist/modules/totp/index.js +104 -0
  139. package/dist/modules/totp/types/index.js +1 -0
  140. package/dist/modules/totp/utils/index.js +76 -0
  141. package/dist/modules/typed-event-emitter/index.js +7 -0
  142. package/dist/modules/typed-event-emitter/types/index.js +1 -0
  143. package/dist/shared/enums/index.js +7 -0
  144. package/dist/shared/types/index.js +1 -0
  145. package/dist/shared/utils/flatten.d.ts +1 -1
  146. package/dist/shared/utils/index.js +30 -0
  147. package/package.json +1 -1
@@ -0,0 +1,282 @@
1
+ // @bun
2
+ import {
3
+ LOGGER_ERROR_KEYS
4
+ } from "../../chunk-rz5p4j3p.js";
5
+ import {
6
+ TypedEventEmitter
7
+ } from "../../chunk-mvrxngm7.js";
8
+ import {
9
+ BaseError
10
+ } from "../../chunk-9cgzhc50.js";
11
+
12
+ // source/modules/logger/worker-logger.ts
13
+ var workerFunction = () => {
14
+ const sinks = {};
15
+ const self = globalThis;
16
+ const processLogEntry = async (log) => {
17
+ await Promise.all(log.sinkNames.map(async (sinkName) => {
18
+ const sink = sinks[sinkName];
19
+ if (!sink)
20
+ return;
21
+ try {
22
+ await sink.log(log.level, log.timestamp, log.object);
23
+ } catch (error) {
24
+ self.postMessage({
25
+ type: "SINK_LOG_ERROR",
26
+ sinkName,
27
+ error,
28
+ object: log.object
29
+ });
30
+ }
31
+ }));
32
+ };
33
+ self.addEventListener("message", async (event) => {
34
+ switch (event.data.type) {
35
+ case "REGISTER_SINK": {
36
+ const {
37
+ sinkName,
38
+ sinkClassName,
39
+ sinkClassString,
40
+ sinkArgs
41
+ } = event.data;
42
+ try {
43
+ const factory = new Function("sinkArgs", `
44
+ ${sinkClassString}
45
+ return new ${sinkClassName}(...sinkArgs);
46
+ `);
47
+ sinks[sinkName] = factory(sinkArgs);
48
+ } catch (error) {
49
+ self.postMessage({
50
+ type: "REGISTER_SINK_ERROR",
51
+ sinkName,
52
+ error
53
+ });
54
+ }
55
+ break;
56
+ }
57
+ case "LOG_BATCH": {
58
+ const { logs } = event.data;
59
+ try {
60
+ for (const log of logs)
61
+ await processLogEntry(log);
62
+ } finally {
63
+ self.postMessage({ type: "BATCH_COMPLETE" });
64
+ }
65
+ break;
66
+ }
67
+ case "CLOSE": {
68
+ await Promise.all(Object.entries(sinks).map(async ([name, sink]) => {
69
+ try {
70
+ await sink.close?.();
71
+ } catch (error) {
72
+ self.postMessage({
73
+ type: "SINK_CLOSE_ERROR",
74
+ sinkName: name,
75
+ error
76
+ });
77
+ }
78
+ }));
79
+ self.postMessage({ type: "CLOSE_COMPLETE" });
80
+ break;
81
+ }
82
+ }
83
+ });
84
+ };
85
+
86
+ // source/modules/logger/logger.ts
87
+ class Logger extends TypedEventEmitter {
88
+ _sinks;
89
+ _sinkKeys = [];
90
+ _worker;
91
+ _maxPendingLogs;
92
+ _maxMessagesInFlight;
93
+ _batchSize;
94
+ _batchTimeout;
95
+ _autoEnd;
96
+ _flushOnBeforeExit;
97
+ _pendingLogs = [];
98
+ _messagesInFlight = 0;
99
+ _batchTimer = null;
100
+ _isWriting = false;
101
+ _flushResolvers = [];
102
+ _closeResolver = null;
103
+ _backpressureResolver = null;
104
+ _handleExit = () => {
105
+ this._worker.terminate();
106
+ };
107
+ _handleWorkerClose = () => {
108
+ process.off("beforeExit", this._handleBeforeExit);
109
+ process.off("exit", this._handleExit);
110
+ };
111
+ constructor(options) {
112
+ super();
113
+ const {
114
+ autoEnd = true,
115
+ batchSize = 50,
116
+ batchTimeout = 0.1,
117
+ flushOnBeforeExit = true,
118
+ maxMessagesInFlight = 100,
119
+ maxPendingLogs = 1e4
120
+ } = options ?? {};
121
+ this._sinks = {};
122
+ this._maxPendingLogs = maxPendingLogs;
123
+ this._maxMessagesInFlight = maxMessagesInFlight;
124
+ this._batchSize = batchSize;
125
+ this._batchTimeout = batchTimeout;
126
+ this._autoEnd = autoEnd;
127
+ this._flushOnBeforeExit = flushOnBeforeExit;
128
+ this._worker = new Worker(URL.createObjectURL(new Blob([`(${workerFunction.toString()})()`], { type: "application/javascript" })), { type: "module" });
129
+ this._setupWorkerMessages();
130
+ if (this._autoEnd)
131
+ this._setupAutoEnd();
132
+ }
133
+ registerSink(sinkName, sinkConstructor, ...sinkArgs) {
134
+ if (this._sinks[sinkName])
135
+ throw new BaseError(LOGGER_ERROR_KEYS.SINK_ALREADY_ADDED);
136
+ this._worker.postMessage({
137
+ type: "REGISTER_SINK",
138
+ sinkName,
139
+ sinkClassName: sinkConstructor.name,
140
+ sinkClassString: sinkConstructor.toString(),
141
+ sinkArgs
142
+ });
143
+ this._sinks[sinkName] = sinkConstructor;
144
+ this._sinkKeys.push(sinkName);
145
+ return this;
146
+ }
147
+ error(object, sinkNames = this._sinkKeys) {
148
+ this._enqueue("ERROR", object, sinkNames);
149
+ }
150
+ warn(object, sinkNames = this._sinkKeys) {
151
+ this._enqueue("WARN", object, sinkNames);
152
+ }
153
+ info(object, sinkNames = this._sinkKeys) {
154
+ this._enqueue("INFO", object, sinkNames);
155
+ }
156
+ debug(object, sinkNames = this._sinkKeys) {
157
+ this._enqueue("DEBUG", object, sinkNames);
158
+ }
159
+ log(object, sinkNames = this._sinkKeys) {
160
+ this._enqueue("LOG", object, sinkNames);
161
+ }
162
+ async flush() {
163
+ if (this._pendingLogs.length === 0 && this._messagesInFlight === 0)
164
+ return;
165
+ return new Promise((resolve) => {
166
+ this._flushResolvers.push(resolve);
167
+ if (!this._isWriting && this._pendingLogs.length > 0) {
168
+ this._isWriting = true;
169
+ this._processPendingLogs();
170
+ }
171
+ });
172
+ }
173
+ async close() {
174
+ await this.flush();
175
+ return new Promise((resolve) => {
176
+ this._closeResolver = resolve;
177
+ this._worker.postMessage({ type: "CLOSE" });
178
+ });
179
+ }
180
+ _enqueue(level, object, sinkNames) {
181
+ if (this._sinkKeys.length === 0)
182
+ throw new BaseError(LOGGER_ERROR_KEYS.NO_SINKS_PROVIDED, { level, object });
183
+ if (this._pendingLogs.length >= this._maxPendingLogs)
184
+ return;
185
+ this._pendingLogs.push({
186
+ sinkNames: sinkNames ?? this._sinkKeys,
187
+ level,
188
+ timestamp: Date.now(),
189
+ object
190
+ });
191
+ if (this._pendingLogs.length >= this._batchSize) {
192
+ if (this._batchTimer !== null) {
193
+ clearTimeout(this._batchTimer);
194
+ this._batchTimer = null;
195
+ }
196
+ this._triggerProcessing();
197
+ } else if (this._batchTimeout > 0 && this._batchTimer === null) {
198
+ this._batchTimer = setTimeout(() => {
199
+ this._batchTimer = null;
200
+ this._triggerProcessing();
201
+ }, this._batchTimeout);
202
+ }
203
+ }
204
+ _triggerProcessing() {
205
+ if (this._isWriting)
206
+ return;
207
+ this._isWriting = true;
208
+ this._processPendingLogs();
209
+ }
210
+ async _processPendingLogs() {
211
+ while (this._pendingLogs.length > 0) {
212
+ if (this._messagesInFlight >= this._maxMessagesInFlight)
213
+ await new Promise((resolve) => {
214
+ this._backpressureResolver = resolve;
215
+ });
216
+ const batch = this._pendingLogs.splice(0, this._batchSize);
217
+ this._messagesInFlight++;
218
+ this._worker.postMessage({
219
+ type: "LOG_BATCH",
220
+ logs: batch
221
+ });
222
+ }
223
+ this._isWriting = false;
224
+ this.emit("drained");
225
+ }
226
+ _releaseBatch() {
227
+ this._messagesInFlight--;
228
+ if (this._backpressureResolver !== null) {
229
+ this._backpressureResolver();
230
+ this._backpressureResolver = null;
231
+ }
232
+ }
233
+ _setupWorkerMessages() {
234
+ this._worker.addEventListener("message", (event) => {
235
+ switch (event.data.type) {
236
+ case "BATCH_COMPLETE":
237
+ this._releaseBatch();
238
+ if (this._messagesInFlight === 0 && this._pendingLogs.length === 0 && this._flushResolvers.length > 0) {
239
+ for (const resolve of this._flushResolvers)
240
+ resolve();
241
+ this._flushResolvers.length = 0;
242
+ }
243
+ break;
244
+ case "SINK_LOG_ERROR":
245
+ this.emit("sinkError", new BaseError(LOGGER_ERROR_KEYS.SINK_LOG_ERROR, event.data));
246
+ this._releaseBatch();
247
+ break;
248
+ case "SINK_CLOSE_ERROR":
249
+ this.emit("sinkError", new BaseError(LOGGER_ERROR_KEYS.SINK_CLOSE_ERROR, event.data));
250
+ break;
251
+ case "REGISTER_SINK_ERROR":
252
+ this.emit("registerSinkError", new BaseError(LOGGER_ERROR_KEYS.REGISTER_SINK_ERROR, event.data));
253
+ break;
254
+ case "CLOSE_COMPLETE":
255
+ this._worker.terminate();
256
+ if (this._closeResolver) {
257
+ this._closeResolver();
258
+ this._closeResolver = null;
259
+ }
260
+ break;
261
+ }
262
+ });
263
+ }
264
+ _setupAutoEnd() {
265
+ process.on("beforeExit", this._handleBeforeExit);
266
+ process.on("exit", this._handleExit);
267
+ this._worker.addEventListener("close", this._handleWorkerClose);
268
+ }
269
+ _handleBeforeExit = () => {
270
+ if (this._flushOnBeforeExit)
271
+ this.flush().then(() => this.close()).catch((error) => {
272
+ this.emit("onBeforeExitError", new BaseError(LOGGER_ERROR_KEYS.BEFORE_EXIT_FLUSH_ERROR, { error }));
273
+ });
274
+ else
275
+ this.close().catch((error) => {
276
+ this.emit("onBeforeExitError", new BaseError(LOGGER_ERROR_KEYS.BEFORE_EXIT_CLOSE_ERROR, { error }));
277
+ });
278
+ };
279
+ }
280
+ export {
281
+ Logger
282
+ };
@@ -1,4 +1,4 @@
1
- import { TypedEventEmitter } from '#/modules/typed-event-emitter/typed-event-emitter';
1
+ import { TypedEventEmitter } from '../../modules/typed-event-emitter/typed-event-emitter';
2
2
  import type { LoggerEvent } from './events/logger-events';
3
3
  import type { LoggerOptions } from './types/logger-options';
4
4
  import type { LoggerSink } from './types/logger-sink';
@@ -1,5 +1,5 @@
1
- import type { LogLevels } from '#/modules/logger/types/log-levels';
2
- import type { LoggerSink } from '#/modules/logger/types/logger-sink';
1
+ import type { LogLevels } from '../../../modules/logger/types/log-levels';
2
+ import type { LoggerSink } from '../../../modules/logger/types/logger-sink';
3
3
  /**
4
4
  * ConsoleLoggerSink implements LoggerSink to provide logging functionality to the console.
5
5
  */
@@ -1,4 +1,4 @@
1
- import type { LoggerSink } from '#/modules/logger/types/logger-sink';
1
+ import type { LoggerSink } from '../../../modules/logger/types/logger-sink';
2
2
  /**
3
3
  * DevNullLoggerSink implements LoggerSink to discard all logs (like /dev/null).
4
4
  * Useful for benchmarking the logger overhead without I/O.
@@ -1,5 +1,5 @@
1
- import type { LogLevels } from '#/modules/logger/types/log-levels';
2
- import type { LoggerSink } from '#/modules/logger/types/logger-sink';
1
+ import type { LogLevels } from '../../../../modules/logger/types/log-levels';
2
+ import type { LoggerSink } from '../../../../modules/logger/types/logger-sink';
3
3
  export interface FileLoggerConfig {
4
4
  /**
5
5
  * Path to the file to log to.
@@ -0,0 +1,66 @@
1
+ // @bun
2
+ import {
3
+ BaseError
4
+ } from "../../../chunk-9cgzhc50.js";
5
+
6
+ // source/modules/logger/sinks/console-logger.ts
7
+ class ConsoleLoggerSink {
8
+ async log(level, timestamp, object) {
9
+ const logEntry = { timestamp, level, content: object };
10
+ await Bun.write(Bun.stdout, JSON.stringify(logEntry) + `
11
+ `);
12
+ }
13
+ }
14
+ // source/modules/logger/sinks/devnull-logger.ts
15
+ class DevNullLoggerSink {
16
+ log() {}
17
+ }
18
+ // source/modules/logger/sinks/file-logger/enums/file-logger-error-keys.ts
19
+ var FILE_LOGGER_ERROR_KEYS = {
20
+ FAILED_TO_CLOSE_STREAM: "mrx-core.file_logger.error.failed_to_close_stream"
21
+ };
22
+ // source/modules/logger/sinks/file-logger/file-logger.ts
23
+ import { createWriteStream } from "fs";
24
+ class FileLoggerSink {
25
+ config;
26
+ _stream;
27
+ _isClosed = false;
28
+ constructor(config) {
29
+ this.config = config;
30
+ this._stream = createWriteStream(config.path, {
31
+ flags: "a",
32
+ encoding: "utf8",
33
+ highWaterMark: config.bufferSize ?? 16 * 1024
34
+ });
35
+ }
36
+ async log(level, timestamp, object) {
37
+ if (this._isClosed)
38
+ return;
39
+ const logEntry = JSON.stringify({ timestamp, level, content: object }) + `
40
+ `;
41
+ const canContinue = this._stream.write(logEntry);
42
+ if (!canContinue)
43
+ await new Promise((resolve) => {
44
+ this._stream.once("drain", resolve);
45
+ });
46
+ }
47
+ async close() {
48
+ if (this._isClosed)
49
+ return;
50
+ this._isClosed = true;
51
+ return new Promise((resolve, reject) => {
52
+ this._stream.end((err) => {
53
+ if (err)
54
+ reject(new BaseError(FILE_LOGGER_ERROR_KEYS.FAILED_TO_CLOSE_STREAM, err.message));
55
+ else
56
+ resolve();
57
+ });
58
+ });
59
+ }
60
+ }
61
+ export {
62
+ FileLoggerSink,
63
+ FILE_LOGGER_ERROR_KEYS,
64
+ DevNullLoggerSink,
65
+ ConsoleLoggerSink
66
+ };
@@ -0,0 +1 @@
1
+ // @bun
@@ -0,0 +1 @@
1
+ export declare const workerFunction: () => void;
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ import {
3
+ MAILER_ERROR_KEYS
4
+ } from "../../../chunk-6w9ja96e.js";
5
+ export {
6
+ MAILER_ERROR_KEYS
7
+ };
@@ -0,0 +1,55 @@
1
+ // @bun
2
+ import {
3
+ MAILER_ERROR_KEYS
4
+ } from "../../chunk-6w9ja96e.js";
5
+ import {
6
+ BaseError
7
+ } from "../../chunk-9cgzhc50.js";
8
+
9
+ // source/modules/mailer/smtp.ts
10
+ import { createTransport } from "nodemailer";
11
+ class SMTP {
12
+ _config;
13
+ _transporter = null;
14
+ constructor(config) {
15
+ this._config = {
16
+ port: 587,
17
+ secure: false,
18
+ ...config
19
+ };
20
+ }
21
+ async connect() {
22
+ if (this._transporter)
23
+ throw new BaseError(MAILER_ERROR_KEYS.SMTP_ALREADY_CONNECTED);
24
+ this._transporter = createTransport({
25
+ host: this._config.host,
26
+ port: this._config.port,
27
+ secure: this._config.secure,
28
+ auth: {
29
+ user: this._config.credentials.user,
30
+ pass: this._config.credentials.pass
31
+ },
32
+ pool: true,
33
+ maxConnections: this._config.pool?.maxConnections ?? 5
34
+ });
35
+ try {
36
+ await this._transporter.verify();
37
+ } catch (error) {
38
+ throw new BaseError(MAILER_ERROR_KEYS.SMTP_CONNECTION_ERROR, error);
39
+ }
40
+ }
41
+ disconnect() {
42
+ if (this._transporter) {
43
+ this._transporter.close();
44
+ this._transporter = null;
45
+ }
46
+ }
47
+ async sendMail(options) {
48
+ if (!this._transporter)
49
+ throw new BaseError(MAILER_ERROR_KEYS.SMTP_NOT_CONNECTED);
50
+ return this._transporter.sendMail(options);
51
+ }
52
+ }
53
+ export {
54
+ SMTP
55
+ };
@@ -0,0 +1 @@
1
+ // @bun
@@ -0,0 +1,12 @@
1
+ // @bun
2
+ import {
3
+ Repository
4
+ } from "../../chunk-afyz8rg5.js";
5
+ import"../../chunk-grfyngq0.js";
6
+ import"../../chunk-4v86f7gp.js";
7
+ import"../../chunk-7t524zqh.js";
8
+ import"../../chunk-sqts8vyk.js";
9
+ import"../../chunk-9cgzhc50.js";
10
+ export {
11
+ Repository
12
+ };
@@ -1,6 +1,6 @@
1
1
  import type { Knex } from 'knex';
2
- import type { Table } from '#/modules/database/table';
3
- import type { StreamWithAsyncIterable } from '#/shared/types/stream-with-async-iterable';
2
+ import type { Table } from '../../modules/database/table';
3
+ import type { StreamWithAsyncIterable } from '../../shared/types/stream-with-async-iterable';
4
4
  import type { Filter } from './types/filter';
5
5
  import type { OrderByItem } from './types/order-by-item';
6
6
  import type { QueryOptions } from './types/query-options';
@@ -0,0 +1 @@
1
+ // @bun
@@ -1,4 +1,4 @@
1
- import type { HTTP_STATUS_CODES } from '#/errors/enums/http-status-codes';
1
+ import type { HTTP_STATUS_CODES } from '../../../errors/enums/http-status-codes';
2
2
  import type { Filter } from './filter';
3
3
  import type { OrderByItem } from './order-by-item';
4
4
  import type { SelectedFields } from './selected-fields';
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ import {
3
+ SINGLETON_MANAGER_ERROR_KEYS
4
+ } from "../../../chunk-z0ct35ft.js";
5
+ export {
6
+ SINGLETON_MANAGER_ERROR_KEYS
7
+ };
@@ -0,0 +1,9 @@
1
+ // @bun
2
+ import {
3
+ SingletonManager
4
+ } from "../../chunk-fs3wm3p4.js";
5
+ import"../../chunk-z0ct35ft.js";
6
+ import"../../chunk-9cgzhc50.js";
7
+ export {
8
+ SingletonManager
9
+ };
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ import {
3
+ TOTP_ERROR_KEYS
4
+ } from "../../../chunk-9r5anep5.js";
5
+ export {
6
+ TOTP_ERROR_KEYS
7
+ };
@@ -0,0 +1,104 @@
1
+ // @bun
2
+ import {
3
+ createCounterBuffer,
4
+ dynamicTruncation,
5
+ generateHmac
6
+ } from "../../chunk-m3grz32t.js";
7
+ import {
8
+ TOTP_ERROR_KEYS
9
+ } from "../../chunk-9r5anep5.js";
10
+ import {
11
+ BaseError
12
+ } from "../../chunk-9cgzhc50.js";
13
+
14
+ // source/modules/totp/hotp.ts
15
+ import { webcrypto } from "crypto";
16
+ var hotp = async (secret, counter, {
17
+ algorithm = "SHA-1",
18
+ digits = 6
19
+ } = {}) => {
20
+ const counterBuffer = createCounterBuffer(counter);
21
+ const key = await webcrypto.subtle.importKey("raw", secret, { name: "HMAC", hash: algorithm }, false, ["sign"]);
22
+ const hmacArray = await generateHmac(key, counterBuffer);
23
+ return dynamicTruncation(hmacArray, digits);
24
+ };
25
+ // source/modules/totp/otp-auth-uri.ts
26
+ var buildOtpAuthUri = ({
27
+ secretBase32,
28
+ label,
29
+ issuer,
30
+ algorithm = "SHA-1",
31
+ digits = 6,
32
+ period = 30
33
+ }) => {
34
+ const encodedLabel = encodeURIComponent(label);
35
+ const encodedIssuer = issuer ? encodeURIComponent(issuer) : undefined;
36
+ let uri = `otpauth://totp/${encodedLabel}?secret=${secretBase32}`;
37
+ if (encodedIssuer)
38
+ uri += `&issuer=${encodedIssuer}`;
39
+ if (algorithm !== "SHA-1")
40
+ uri += `&algorithm=${algorithm}`;
41
+ if (digits !== 6)
42
+ uri += `&digits=${digits}`;
43
+ if (period !== 30)
44
+ uri += `&period=${period}`;
45
+ return uri;
46
+ };
47
+ var parseOtpAuthUri = (uri) => {
48
+ const url = new URL(uri);
49
+ if (url.protocol !== "otpauth:")
50
+ throw new BaseError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
51
+ if (url.hostname !== "totp")
52
+ throw new BaseError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
53
+ const label = decodeURIComponent(url.pathname.slice(1));
54
+ const secretBase32 = url.searchParams.get("secret");
55
+ if (!secretBase32)
56
+ throw new BaseError(TOTP_ERROR_KEYS.MISSING_SECRET);
57
+ const issuerParam = url.searchParams.get("issuer");
58
+ const issuer = issuerParam ? decodeURIComponent(issuerParam) : undefined;
59
+ const algorithm = url.searchParams.get("algorithm") || "SHA-1";
60
+ const digits = parseInt(url.searchParams.get("digits") || "6", 10);
61
+ const period = parseInt(url.searchParams.get("period") || "30", 10);
62
+ const result = {
63
+ secretBase32,
64
+ label,
65
+ algorithm,
66
+ digits,
67
+ period,
68
+ ...issuer && { issuer }
69
+ };
70
+ return result;
71
+ };
72
+ // source/modules/totp/totp.ts
73
+ var totp = async (secret, {
74
+ algorithm = "SHA-1",
75
+ digits = 6,
76
+ period = 30,
77
+ now = Date.now()
78
+ } = {}) => {
79
+ const timeStep = Math.floor(now / 1000 / period);
80
+ return hotp(secret, timeStep, { algorithm, digits });
81
+ };
82
+ var verifyTotp = async (secret, code, {
83
+ algorithm = "SHA-1",
84
+ digits = 6,
85
+ period = 30,
86
+ window = 0,
87
+ now = Date.now()
88
+ } = {}) => {
89
+ const currentTimeStep = Math.floor(now / 1000 / period);
90
+ for (let i = -window;i <= window; ++i) {
91
+ const timeStep = currentTimeStep + i;
92
+ const expectedCode = await hotp(secret, timeStep, { algorithm, digits });
93
+ if (expectedCode === code)
94
+ return true;
95
+ }
96
+ return false;
97
+ };
98
+ export {
99
+ verifyTotp,
100
+ totp,
101
+ parseOtpAuthUri,
102
+ hotp,
103
+ buildOtpAuthUri
104
+ };
@@ -0,0 +1 @@
1
+ // @bun