@mrxsys/mrx-core 2.11.0-2-and-276-20251029 → 2.11.0-2-and-279-20251103

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 (148) hide show
  1. package/CHANGELOG.md +0 -407
  2. package/dist/chunk-0d0zd2yg.js +8 -0
  3. package/dist/chunk-12qzn7jw.js +7 -0
  4. package/dist/chunk-441xs5k1.js +53 -0
  5. package/dist/chunk-4v86f7gp.js +59 -0
  6. package/dist/chunk-6w9ja96e.js +9 -0
  7. package/dist/chunk-7t524zqh.js +26 -0
  8. package/dist/chunk-8tffnbpn.js +7 -0
  9. package/dist/chunk-9cgzhc50.js +15 -0
  10. package/dist/chunk-9d3zvgp6.js +9 -0
  11. package/dist/chunk-9dzsj7f2.js +23 -0
  12. package/dist/chunk-9r5anep5.js +11 -0
  13. package/dist/chunk-afd82epa.js +201 -0
  14. package/dist/chunk-afyz8rg5.js +209 -0
  15. package/dist/chunk-dre2fgj0.js +7 -0
  16. package/dist/chunk-e30paw8a.js +101 -0
  17. package/dist/chunk-eeb7yskp.js +61 -0
  18. package/dist/chunk-fs3wm3p4.js +32 -0
  19. package/dist/chunk-grfyngq0.js +39 -0
  20. package/dist/chunk-gtn1kn0z.js +79 -0
  21. package/dist/chunk-jksb9ers.js +7 -0
  22. package/dist/chunk-m3grz32t.js +27 -0
  23. package/dist/chunk-mvrxngm7.js +41 -0
  24. package/dist/chunk-n0n14mf8.js +7 -0
  25. package/dist/chunk-p14h6jfs.js +365 -0
  26. package/dist/chunk-pjv1ekwr.js +284 -0
  27. package/dist/chunk-rz5p4j3p.js +13 -0
  28. package/dist/chunk-spnh9dzk.js +10 -0
  29. package/dist/chunk-sqts8vyk.js +60 -0
  30. package/dist/chunk-w7h898m3.js +14 -0
  31. package/dist/chunk-xhhj1gvj.js +9 -0
  32. package/dist/chunk-z0ct35ft.js +8 -0
  33. package/dist/errors/enums/index.js +7 -0
  34. package/dist/errors/index.js +12 -0
  35. package/dist/errors/utils/index.js +16 -0
  36. package/dist/errors/utils/is-nowarajs-error.ts.d.ts +2 -2
  37. package/dist/modules/data/enums/index.js +7 -0
  38. package/dist/modules/data/index.js +17 -0
  39. package/dist/modules/data/transformers/camel-case.d.ts +2 -2
  40. package/dist/modules/data/transformers/index.js +32 -0
  41. package/dist/modules/data/transformers/kebab-case.d.ts +2 -2
  42. package/dist/modules/data/transformers/pascal-case.d.ts +2 -2
  43. package/dist/modules/data/transformers/snake-case.d.ts +2 -2
  44. package/dist/modules/data/types/index.js +1 -0
  45. package/dist/modules/data/types/transform-object-keys.d.ts +4 -4
  46. package/dist/modules/database/enums/index.js +9 -0
  47. package/dist/modules/database/events/index.js +1 -0
  48. package/dist/modules/database/events/mssql-event-map.d.ts +1 -1
  49. package/dist/modules/database/events/table-event-map.d.ts +1 -1
  50. package/dist/modules/database/index.js +16 -0
  51. package/dist/modules/database/mssql.d.ts +2 -2
  52. package/dist/modules/database/table.d.ts +2 -2
  53. package/dist/modules/database/types/index.js +1 -0
  54. package/dist/modules/elysia/cache/cache.d.ts +152 -4
  55. package/dist/modules/elysia/cache/index.js +90 -0
  56. package/dist/modules/elysia/cache/types/index.js +1 -0
  57. package/dist/modules/elysia/crud/crud.d.ts +2 -2
  58. package/dist/modules/elysia/crud/enums/index.js +7 -0
  59. package/dist/modules/elysia/crud/index.js +153 -0
  60. package/dist/modules/elysia/crud/operations/count.d.ts +175 -7
  61. package/dist/modules/elysia/crud/operations/delete.d.ts +175 -7
  62. package/dist/modules/elysia/crud/operations/deleteOne.d.ts +175 -7
  63. package/dist/modules/elysia/crud/operations/find.d.ts +175 -7
  64. package/dist/modules/elysia/crud/operations/findOne.d.ts +175 -7
  65. package/dist/modules/elysia/crud/operations/index.js +34 -0
  66. package/dist/modules/elysia/crud/operations/insert.d.ts +175 -7
  67. package/dist/modules/elysia/crud/operations/update.d.ts +175 -7
  68. package/dist/modules/elysia/crud/operations/updateOne.d.ts +175 -7
  69. package/dist/modules/elysia/crud/operations/utils/get-db-injection.d.ts +1 -1
  70. package/dist/modules/elysia/crud/types/crud-options.d.ts +1 -1
  71. package/dist/modules/elysia/crud/types/crud-schema-models-type.d.ts +9 -9
  72. package/dist/modules/elysia/crud/types/delete-schema.d.ts +2 -2
  73. package/dist/modules/elysia/crud/types/find-schema.d.ts +3 -3
  74. package/dist/modules/elysia/crud/types/index.js +1 -0
  75. package/dist/modules/elysia/crud/types/insert-schema.d.ts +1 -1
  76. package/dist/modules/elysia/crud/types/properties-schema.d.ts +1 -1
  77. package/dist/modules/elysia/crud/types/response-200-schema.d.ts +1 -1
  78. package/dist/modules/elysia/crud/types/update-schema.d.ts +2 -2
  79. package/dist/modules/elysia/crud/utils/create-adaptive-where-clause-schema.d.ts +1 -1
  80. package/dist/modules/elysia/crud/utils/create-count-response-200-schema.d.ts +1 -1
  81. package/dist/modules/elysia/crud/utils/create-count-schema.d.ts +1 -1
  82. package/dist/modules/elysia/crud/utils/create-delete-schema.d.ts +1 -1
  83. package/dist/modules/elysia/crud/utils/create-filters-schema.d.ts +1 -1
  84. package/dist/modules/elysia/crud/utils/create-find-schema.d.ts +1 -1
  85. package/dist/modules/elysia/crud/utils/create-id-param-schema.d.ts +1 -1
  86. package/dist/modules/elysia/crud/utils/create-insert-schema.d.ts +1 -1
  87. package/dist/modules/elysia/crud/utils/create-order-schema.d.ts +1 -1
  88. package/dist/modules/elysia/crud/utils/create-properties-schema.d.ts +1 -1
  89. package/dist/modules/elysia/crud/utils/create-q-schema.d.ts +1 -1
  90. package/dist/modules/elysia/crud/utils/create-response-200-schema.d.ts +1 -1
  91. package/dist/modules/elysia/crud/utils/create-selected-fields-schema.d.ts +1 -1
  92. package/dist/modules/elysia/crud/utils/create-update-one-schema.d.ts +1 -1
  93. package/dist/modules/elysia/crud/utils/create-update-schema.d.ts +1 -1
  94. package/dist/modules/elysia/crud/utils/index.js +41 -0
  95. package/dist/modules/elysia/db-resolver/db-resolver.d.ts +158 -6
  96. package/dist/modules/elysia/db-resolver/enums/index.js +7 -0
  97. package/dist/modules/elysia/db-resolver/index.js +18 -0
  98. package/dist/modules/elysia/error/enums/index.js +7 -0
  99. package/dist/modules/elysia/error/error.d.ts +51 -0
  100. package/dist/modules/elysia/error/index.js +76 -0
  101. package/dist/modules/elysia/microservice/enums/index.js +7 -0
  102. package/dist/modules/elysia/microservice/index.js +100 -0
  103. package/dist/modules/elysia/rate-limit/enums/index.js +7 -0
  104. package/dist/modules/elysia/rate-limit/index.js +81 -0
  105. package/dist/modules/elysia/rate-limit/rate-limit.d.ts +293 -4
  106. package/dist/modules/elysia/rate-limit/types/index.js +1 -0
  107. package/dist/modules/jwt/enums/index.js +11 -0
  108. package/dist/modules/jwt/index.js +51 -0
  109. package/dist/modules/jwt/utils/index.js +9 -0
  110. package/dist/modules/kv-store/bun-redis/bun-redis-store.d.ts +1 -1
  111. package/dist/modules/kv-store/bun-redis/index.js +84 -0
  112. package/dist/modules/kv-store/enums/index.js +7 -0
  113. package/dist/modules/kv-store/ioredis/index.js +86 -0
  114. package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +1 -1
  115. package/dist/modules/kv-store/memory/index.js +9 -0
  116. package/dist/modules/kv-store/memory/memory-store.d.ts +1 -1
  117. package/dist/modules/kv-store/types/index.js +1 -0
  118. package/dist/modules/logger/enums/index.js +7 -0
  119. package/dist/modules/logger/events/index.js +1 -0
  120. package/dist/modules/logger/events/logger-events.d.ts +1 -1
  121. package/dist/modules/logger/index.js +282 -0
  122. package/dist/modules/logger/logger.d.ts +1 -1
  123. package/dist/modules/logger/sinks/console-logger.d.ts +2 -2
  124. package/dist/modules/logger/sinks/devnull-logger.d.ts +1 -1
  125. package/dist/modules/logger/sinks/file-logger/file-logger.d.ts +2 -2
  126. package/dist/modules/logger/sinks/index.js +66 -0
  127. package/dist/modules/logger/types/index.js +1 -0
  128. package/dist/modules/logger/worker-logger.d.ts +1 -0
  129. package/dist/modules/mailer/enums/index.js +7 -0
  130. package/dist/modules/mailer/index.js +55 -0
  131. package/dist/modules/mailer/types/index.js +1 -0
  132. package/dist/modules/repository/index.js +12 -0
  133. package/dist/modules/repository/repository.d.ts +2 -2
  134. package/dist/modules/repository/types/index.js +1 -0
  135. package/dist/modules/repository/types/query-options.d.ts +1 -1
  136. package/dist/modules/singleton-manager/enums/index.js +7 -0
  137. package/dist/modules/singleton-manager/index.js +9 -0
  138. package/dist/modules/totp/enums/index.js +7 -0
  139. package/dist/modules/totp/index.js +104 -0
  140. package/dist/modules/totp/types/index.js +1 -0
  141. package/dist/modules/totp/utils/index.js +76 -0
  142. package/dist/modules/typed-event-emitter/index.js +7 -0
  143. package/dist/modules/typed-event-emitter/types/index.js +1 -0
  144. package/dist/shared/enums/index.js +7 -0
  145. package/dist/shared/types/index.js +1 -0
  146. package/dist/shared/utils/flatten.d.ts +1 -1
  147. package/dist/shared/utils/index.js +30 -0
  148. package/package.json +3 -3
@@ -0,0 +1,9 @@
1
+ // @bun
2
+ // source/modules/jwt/enums/jwt-error-keys.ts
3
+ var JWT_ERROR_KEYS = {
4
+ JWT_EXPIRATION_PASSED: "mrx-core.jwt.error.expiration_passed",
5
+ JWT_SECRET_NOT_FOUND: "mrx-core.jwt.error.secret_not_found",
6
+ JWT_SIGN_ERROR: "mrx-core.jwt.error.sign_error"
7
+ };
8
+
9
+ export { JWT_ERROR_KEYS };
@@ -0,0 +1,23 @@
1
+ // @bun
2
+ // source/shared/utils/flatten.ts
3
+ import { KindGuard } from "@sinclair/typebox";
4
+ import { t } from "elysia";
5
+ var _flattenInto = (type, result) => {
6
+ if (KindGuard.IsUnion(type))
7
+ for (const subType of type.anyOf)
8
+ _flattenInto(subType, result);
9
+ else
10
+ result.push(type);
11
+ };
12
+ var flatten = (type) => {
13
+ if (!KindGuard.IsUnion(type))
14
+ return type;
15
+ const isAlreadyFlat = type.anyOf.every((subType) => !KindGuard.IsUnion(subType));
16
+ if (isAlreadyFlat)
17
+ return type;
18
+ const result = [];
19
+ _flattenInto(type, result);
20
+ return t.Union(result);
21
+ };
22
+
23
+ export { flatten };
@@ -0,0 +1,11 @@
1
+ // @bun
2
+ // source/modules/totp/enums/totp-error-keys.ts
3
+ var TOTP_ERROR_KEYS = {
4
+ INVALID_ALGORITHM: "mrx-core.totp.error.invalid_algorithm",
5
+ INVALID_BASE32_CHARACTER: "mrx-core.totp.error.invalid_base32_character",
6
+ INVALID_OTP_AUTH_URI: "mrx-core.totp.error.invalid_otp_auth_uri",
7
+ INVALID_SECRET_LENGTH: "mrx-core.totp.error.invalid_secret_length",
8
+ MISSING_SECRET: "mrx-core.totp.error.missing_secret"
9
+ };
10
+
11
+ export { TOTP_ERROR_KEYS };
@@ -0,0 +1,201 @@
1
+ // @bun
2
+ import {
3
+ Repository
4
+ } from "./chunk-afyz8rg5.js";
5
+ import {
6
+ TypedEventEmitter
7
+ } from "./chunk-mvrxngm7.js";
8
+ import {
9
+ DATABASE_ERROR_KEYS
10
+ } from "./chunk-4v86f7gp.js";
11
+ import {
12
+ BaseError
13
+ } from "./chunk-9cgzhc50.js";
14
+
15
+ // source/modules/database/table.ts
16
+ class Table extends TypedEventEmitter {
17
+ _databaseName;
18
+ _fields = [];
19
+ _name;
20
+ _primaryKey;
21
+ constructor(databaseName, tableName, fields, primaryKey) {
22
+ super();
23
+ this._databaseName = databaseName;
24
+ this._name = tableName;
25
+ this._fields = fields;
26
+ this._primaryKey = primaryKey;
27
+ }
28
+ get databaseName() {
29
+ return this._databaseName;
30
+ }
31
+ get name() {
32
+ return this._name;
33
+ }
34
+ get fields() {
35
+ return this._fields;
36
+ }
37
+ get primaryKey() {
38
+ return this._primaryKey;
39
+ }
40
+ }
41
+
42
+ // source/modules/database/mssql.ts
43
+ import knex from "knex";
44
+ class MSSQL extends TypedEventEmitter {
45
+ _isConnected = false;
46
+ _databaseName;
47
+ _tables = new Map;
48
+ _repositories = new Map;
49
+ _db;
50
+ _isEventEnabled;
51
+ constructor(options) {
52
+ super();
53
+ this._databaseName = options.databaseName;
54
+ this._isEventEnabled = options.isEventEnabled ?? false;
55
+ this._db = knex({
56
+ client: "mssql",
57
+ acquireConnectionTimeout: options.connectionTimeout ?? 20000,
58
+ compileSqlOnError: true,
59
+ connection: {
60
+ database: options.databaseName,
61
+ host: options.host,
62
+ port: options.port,
63
+ user: options.user,
64
+ password: options.password,
65
+ options: {
66
+ encrypt: options.encrypt ?? true
67
+ },
68
+ bigNumberStrings: false
69
+ },
70
+ pool: {
71
+ min: options.poolMin ?? 2,
72
+ max: options.poolMax ?? 10
73
+ }
74
+ });
75
+ }
76
+ async connect() {
77
+ try {
78
+ await this._introspectDatabase();
79
+ this._isConnected = true;
80
+ if (this._isEventEnabled)
81
+ this._addEventKnex();
82
+ } catch (error) {
83
+ throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_CONNECTION_ERROR, {
84
+ databaseName: this._databaseName,
85
+ error
86
+ });
87
+ }
88
+ }
89
+ async disconnect() {
90
+ if (!this._isConnected)
91
+ throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_NOT_CONNECTED, {
92
+ databaseName: this._databaseName
93
+ });
94
+ try {
95
+ await this._db.destroy();
96
+ this._isConnected = false;
97
+ } catch (error) {
98
+ throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_DISCONNECT_ERROR, {
99
+ databaseName: this._databaseName,
100
+ error
101
+ });
102
+ }
103
+ }
104
+ getRepository(tableName, customRepository) {
105
+ if (!this._isConnected)
106
+ throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_NOT_CONNECTED, { databaseName: this._databaseName });
107
+ if (!this._tables.has(tableName))
108
+ throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_TABLE_NOT_FOUND, { table: tableName });
109
+ let repo = this._repositories.get(tableName);
110
+ if (customRepository) {
111
+ const table = this._tables.get(tableName);
112
+ if (repo && repo instanceof customRepository)
113
+ return repo;
114
+ repo = new customRepository(this._db, table);
115
+ this._repositories.set(tableName, repo);
116
+ return repo;
117
+ }
118
+ return this._repositories.get(tableName);
119
+ }
120
+ getTable(tableName) {
121
+ if (!this._isConnected)
122
+ throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_NOT_CONNECTED, { databaseName: this._databaseName });
123
+ if (!this._tables.has(tableName))
124
+ throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_TABLE_NOT_FOUND, { table: tableName });
125
+ return this._tables.get(tableName);
126
+ }
127
+ get databaseName() {
128
+ return this._databaseName;
129
+ }
130
+ get tables() {
131
+ return this._tables;
132
+ }
133
+ get repositories() {
134
+ return this._repositories;
135
+ }
136
+ get isConnected() {
137
+ return this._isConnected;
138
+ }
139
+ get db() {
140
+ if (!this._isConnected)
141
+ throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_NOT_CONNECTED, { databaseName: this._databaseName });
142
+ return this._db;
143
+ }
144
+ async _introspectDatabase() {
145
+ const result = await this._db.from({ c: "information_schema.columns" }).select("c.table_name as tableName").select(this._db.raw("STRING_AGG(c.column_name, ',') AS fields")).select("pk.primaryKeyColumn as primaryKeyColumn").select("pk.primaryKeyType as primaryKeyType").leftJoin(this._db.from({ tc: "information_schema.table_constraints" }).join({ kcu: "information_schema.key_column_usage" }, "tc.constraint_name", "kcu.constraint_name").join({ col: "information_schema.columns" }, (builder) => {
146
+ builder.on("col.table_name", "=", "kcu.table_name").andOn("col.column_name", "=", "kcu.column_name");
147
+ }).where("tc.constraint_type", "PRIMARY KEY").groupBy("tc.table_name", "kcu.column_name", "col.data_type").select("tc.table_name as tableName").select("kcu.column_name as primaryKeyColumn").select("col.data_type as primaryKeyType").as("pk"), "c.table_name", "pk.tableName").groupBy("c.table_name", "pk.primaryKeyColumn", "pk.primaryKeyType");
148
+ const fieldsByTable = result.reduce((acc, { tableName, fields, primaryKeyColumn, primaryKeyType }) => {
149
+ const primaryKeyTypeTs = primaryKeyType === "int" ? "NUMBER" : "STRING";
150
+ acc.set(tableName, {
151
+ fields: fields.split(","),
152
+ primaryKey: [primaryKeyColumn, primaryKeyTypeTs]
153
+ });
154
+ return acc;
155
+ }, new Map);
156
+ fieldsByTable.forEach((desc, tableName) => {
157
+ const table = new Table(this._databaseName, tableName, desc.fields, desc.primaryKey);
158
+ this._tables.set(tableName, table);
159
+ this._repositories.set(tableName, new Repository(this._db, table));
160
+ });
161
+ }
162
+ _extractTablesFromSqlQuery(sql) {
163
+ const tableRegex = /(?:update|insert\s+into|delete\s+from|from|join|with)\s+\[?([^\]\s]+)\]?/gi;
164
+ const matches = [...sql.matchAll(tableRegex)].map((match) => match[1]);
165
+ return Array.from(new Set(matches));
166
+ }
167
+ _handleQueryResponse(response, queryContext) {
168
+ const tables = this._extractTablesFromSqlQuery(queryContext.sql);
169
+ const table = this._tables.get(tables[0]);
170
+ switch (queryContext.method) {
171
+ case "select":
172
+ table?.emit("selected", response, queryContext);
173
+ break;
174
+ case "insert":
175
+ table?.emit("inserted", response, queryContext);
176
+ break;
177
+ case "update":
178
+ table?.emit("updated", response, queryContext);
179
+ break;
180
+ case "del":
181
+ table?.emit("deleted", response, queryContext);
182
+ break;
183
+ default:
184
+ break;
185
+ }
186
+ }
187
+ _addEventKnex() {
188
+ this._db.on("query", (queryContext) => {
189
+ this.emit("query", queryContext);
190
+ });
191
+ this._db.on("query-error", (error, queryContext) => {
192
+ this.emit("query:error", error, queryContext);
193
+ });
194
+ this._db.on("query-response", (response, queryContext) => {
195
+ this.emit("query:response", response, queryContext);
196
+ this._handleQueryResponse(response, queryContext);
197
+ });
198
+ }
199
+ }
200
+
201
+ export { Table, MSSQL };
@@ -0,0 +1,209 @@
1
+ // @bun
2
+ import {
3
+ isDateString,
4
+ makeStreamAsyncIterable
5
+ } from "./chunk-grfyngq0.js";
6
+ import {
7
+ DATABASE_ERROR_KEYS,
8
+ MSSQL_ERROR_CODE
9
+ } from "./chunk-4v86f7gp.js";
10
+ import {
11
+ HttpError
12
+ } from "./chunk-7t524zqh.js";
13
+
14
+ // source/modules/repository/repository.ts
15
+ import { PassThrough } from "stream";
16
+ var _operators = {
17
+ $eq: (q, c, v) => q.where(c, v),
18
+ $neq: (q, c, v) => q.whereNot(c, v),
19
+ $lt: (q, c, v) => q.where(c, "<", v),
20
+ $lte: (q, c, v) => q.where(c, "<=", v),
21
+ $gt: (q, c, v) => q.where(c, ">", v),
22
+ $gte: (q, c, v) => q.where(c, ">=", v),
23
+ $in: (q, c, v) => q.whereIn(c, v),
24
+ $nin: (q, c, v) => q.whereNotIn(c, v),
25
+ $between: (q, c, v) => q.whereBetween(c, v),
26
+ $nbetween: (q, c, v) => q.whereNotBetween(c, v),
27
+ $like: (q, c, v) => {
28
+ const likeValue = `%${v}%`;
29
+ if (isDateString(v))
30
+ return q.whereRaw(`CONVERT(VARCHAR, ${c}, 23) LIKE ?`, [likeValue]);
31
+ return q.where(c, "LIKE", likeValue);
32
+ },
33
+ $nlike: (q, c, v) => {
34
+ const likeValue = `%${v}%`;
35
+ if (isDateString(v))
36
+ return q.whereRaw(`CONVERT(VARCHAR, ${c}, 23) NOT LIKE ?`, [likeValue]);
37
+ return q.whereRaw(`${c} NOT LIKE ?`, [likeValue]);
38
+ },
39
+ $isNull: (q, c, v) => v ? q.whereNull(c) : q.whereNotNull(c)
40
+ };
41
+ var _validOperatorKeys = new Set([
42
+ "$eq",
43
+ "$neq",
44
+ "$lt",
45
+ "$lte",
46
+ "$gt",
47
+ "$gte",
48
+ "$in",
49
+ "$nin",
50
+ "$between",
51
+ "$nbetween",
52
+ "$like",
53
+ "$nlike",
54
+ "$isNull"
55
+ ]);
56
+ var _DEFAULT_LIMIT = 100;
57
+ var _DEFAULT_OFFSET = 0;
58
+
59
+ class Repository {
60
+ _knex;
61
+ _table;
62
+ constructor(knex, table) {
63
+ this._knex = knex;
64
+ this._table = table;
65
+ }
66
+ findStream(options) {
67
+ const query = this._knex(this._table.name);
68
+ this._applyQueryOptions(query, options);
69
+ const kStream = query.stream();
70
+ const passThrough = new PassThrough({
71
+ objectMode: true,
72
+ ...options?.transform && { transform: options.transform }
73
+ });
74
+ const cleanup = () => {
75
+ if (!kStream.destroyed)
76
+ kStream.destroy();
77
+ if (!passThrough.destroyed)
78
+ passThrough.destroy();
79
+ };
80
+ kStream.on("error", (error) => {
81
+ const code = error?.number || 0;
82
+ passThrough.emit("error", new HttpError(MSSQL_ERROR_CODE[code] ?? DATABASE_ERROR_KEYS.MSSQL_QUERY_ERROR, {
83
+ query: query.toSQL().sql,
84
+ error
85
+ }));
86
+ });
87
+ passThrough.on("close", cleanup);
88
+ passThrough.on("error", cleanup);
89
+ kStream.pipe(passThrough);
90
+ return makeStreamAsyncIterable(passThrough);
91
+ }
92
+ async find(options) {
93
+ const query = this._knex(this._table.name);
94
+ this._applyQueryOptions(query, options);
95
+ const limit = options?.limit || _DEFAULT_LIMIT;
96
+ const offset = options?.offset || _DEFAULT_OFFSET;
97
+ query.limit(limit).offset(offset);
98
+ return this._executeQuery(query, options?.throwIfNoResult);
99
+ }
100
+ async count(options) {
101
+ const query = this._knex(this._table.name).count({ count: "*" });
102
+ this._applyFilter(query, options?.filters);
103
+ if (options?.transaction)
104
+ query.transacting(options.transaction);
105
+ return this._executeQuery(query, options?.throwIfNoResult).then((result) => result[0].count);
106
+ }
107
+ async insert(data, options) {
108
+ const query = this._knex(this._table.name).insert(data).returning(options?.selectedFields ?? "*");
109
+ if (options?.transaction)
110
+ query.transacting(options.transaction);
111
+ return this._executeQuery(query);
112
+ }
113
+ async update(data, options) {
114
+ const query = this._knex(this._table.name).update(data);
115
+ this._applyQueryOptions(query, options);
116
+ return this._executeQuery(query, options?.throwIfNoResult);
117
+ }
118
+ async delete(options) {
119
+ const query = this._knex(this._table.name).delete();
120
+ this._applyQueryOptions(query, options);
121
+ return this._executeQuery(query, options?.throwIfNoResult);
122
+ }
123
+ _applySelectedFields(query, selectedFields) {
124
+ const qMethod = query._method;
125
+ const sanitizedFields = selectedFields ? selectedFields === "*" ? "*" : Array.isArray(selectedFields) ? selectedFields.map((selectedField) => `${selectedField} as ${selectedField}`) : `${selectedFields} as ${selectedFields}` : "*";
126
+ if (qMethod === "del" || qMethod === "update" || qMethod === "insert")
127
+ query.returning(sanitizedFields, { includeTriggerModifications: true });
128
+ else
129
+ query.select(sanitizedFields);
130
+ }
131
+ _applyFilter(query, search) {
132
+ const processing = (query2, search2) => {
133
+ for (const key in search2) {
134
+ const prop = search2[key];
135
+ if (this._filterIsAdaptiveWhereClause(prop)) {
136
+ for (const operator in prop)
137
+ if (operator in _operators && prop[operator] !== undefined)
138
+ _operators[operator](query2, key, prop[operator]);
139
+ } else if (key === "$q" && prop !== null && (typeof prop === "string" || typeof prop === "number")) {
140
+ for (const field of this._table.fields)
141
+ if (prop)
142
+ query2.orWhere(field, "like", `%${prop}%`);
143
+ } else if (key === "$q" && prop !== null && typeof prop === "object" && "selectedFields" in prop && "value" in prop) {
144
+ const { selectedFields, value } = prop;
145
+ if (Array.isArray(selectedFields))
146
+ for (const field of selectedFields)
147
+ query2.orWhere(field, "like", `%${value}%`);
148
+ else
149
+ query2.orWhere(selectedFields, "like", `%${value}%`);
150
+ } else {
151
+ if (prop !== null && typeof prop === "object" && Object.keys(prop).length === 0)
152
+ continue;
153
+ if (prop !== undefined)
154
+ query2.where(key, prop);
155
+ }
156
+ }
157
+ };
158
+ if (search && Array.isArray(search))
159
+ search.reduce((acc, item) => acc.orWhere((q) => this._applyFilter(q, item)), query);
160
+ else if (search)
161
+ processing(query, search);
162
+ }
163
+ _applyOrderBy(query, orderBy) {
164
+ const qMethod = query._method;
165
+ if (!(qMethod === "select"))
166
+ return;
167
+ if (!orderBy)
168
+ query.orderBy(`[${this._table.name}].${this._table.primaryKey[0]}`, "asc");
169
+ else if (Array.isArray(orderBy))
170
+ orderBy.forEach((item) => {
171
+ query.orderBy(`[${this._table.name}].${item.selectedField}`, item.direction);
172
+ });
173
+ else
174
+ query.orderBy(`[${this._table.name}].${orderBy.selectedField}`, orderBy.direction);
175
+ }
176
+ _applyQueryOptions(query, options) {
177
+ this._applyFilter(query, options?.filters);
178
+ this._applyOrderBy(query, options?.orderBy);
179
+ this._applySelectedFields(query, options?.selectedFields);
180
+ if (options?.transaction)
181
+ query.transacting(options.transaction);
182
+ }
183
+ _handleError(error, query) {
184
+ if (error instanceof HttpError)
185
+ throw error;
186
+ const code = error?.number || 0;
187
+ throw new HttpError(MSSQL_ERROR_CODE[code] ?? DATABASE_ERROR_KEYS.MSSQL_QUERY_ERROR, {
188
+ query: query.toSQL().sql,
189
+ error
190
+ });
191
+ }
192
+ _filterIsAdaptiveWhereClause(data) {
193
+ return Boolean(data && typeof data === "object" && !Array.isArray(data) && Object.keys(data).some((key) => _validOperatorKeys.has(key)));
194
+ }
195
+ async _executeQuery(query, throwIfNoResult = false) {
196
+ try {
197
+ const result = await query;
198
+ if (throwIfNoResult && result.length === 0)
199
+ throw new HttpError(typeof throwIfNoResult === "object" && throwIfNoResult.message ? throwIfNoResult.message : DATABASE_ERROR_KEYS.MSSQL_NO_RESULT, typeof throwIfNoResult === "object" && throwIfNoResult.httpStatusCode ? throwIfNoResult.httpStatusCode : 404, {
200
+ query: query.toSQL().sql
201
+ });
202
+ return result;
203
+ } catch (error) {
204
+ return this._handleError(error, query);
205
+ }
206
+ }
207
+ }
208
+
209
+ export { Repository };
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ // source/modules/elysia/rate-limit/enums/rate-limit-error-keys.ts
3
+ var RATE_LIMIT_ERROR_KEYS = {
4
+ RATE_LIMIT_EXCEEDED: "mrx-core.elysia.rate-limit.error.exceeded"
5
+ };
6
+
7
+ export { RATE_LIMIT_ERROR_KEYS };
@@ -0,0 +1,101 @@
1
+ // @bun
2
+ import {
3
+ KV_STORE_ERROR_KEYS
4
+ } from "./chunk-xhhj1gvj.js";
5
+ import {
6
+ BaseError
7
+ } from "./chunk-9cgzhc50.js";
8
+
9
+ // source/modules/kv-store/memory/memory-store.ts
10
+ class MemoryStore {
11
+ _store = new Map;
12
+ _cleanupInterval;
13
+ _cleanupTimer = null;
14
+ constructor(cleanupIntervalMs) {
15
+ this._cleanupInterval = cleanupIntervalMs ?? 300000;
16
+ this._startCleanup();
17
+ }
18
+ get(key) {
19
+ const entry = this._store.get(key);
20
+ if (!entry)
21
+ return null;
22
+ const now = Date.now();
23
+ if (now > entry.expiresAt && entry.expiresAt !== -1) {
24
+ this._store.delete(key);
25
+ return null;
26
+ }
27
+ return entry.value;
28
+ }
29
+ set(key, value, ttlSec) {
30
+ const expiresAt = ttlSec ? Date.now() + ttlSec * 1000 : -1;
31
+ this._store.set(key, { value, expiresAt });
32
+ }
33
+ increment(key, amount = 1) {
34
+ const current = this.get(key);
35
+ const entry = this._store.get(key);
36
+ if (current !== null && typeof current !== "number")
37
+ throw new BaseError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
38
+ const currentValue = current ?? 0;
39
+ const newValue = currentValue + amount;
40
+ const expiresAt = entry ? entry.expiresAt : -1;
41
+ this._store.set(key, { value: newValue, expiresAt });
42
+ return newValue;
43
+ }
44
+ decrement(key, amount = 1) {
45
+ const current = this.get(key);
46
+ const entry = this._store.get(key);
47
+ if (current !== null && typeof current !== "number")
48
+ throw new BaseError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
49
+ const currentValue = current ?? 0;
50
+ const newValue = currentValue - amount;
51
+ const expiresAt = entry ? entry.expiresAt : -1;
52
+ this._store.set(key, { value: newValue, expiresAt });
53
+ return newValue;
54
+ }
55
+ del(key) {
56
+ return this._store.delete(key);
57
+ }
58
+ expire(key, ttlSec) {
59
+ const entry = this._store.get(key);
60
+ if (!entry)
61
+ return false;
62
+ entry.expiresAt = Date.now() + ttlSec * 1000;
63
+ return true;
64
+ }
65
+ ttl(key) {
66
+ const entry = this._store.get(key);
67
+ if (!entry)
68
+ return -1;
69
+ if (entry.expiresAt === -1)
70
+ return -1;
71
+ const remaining = entry.expiresAt - Date.now();
72
+ return remaining > 0 ? Math.ceil(remaining / 1000) : -1;
73
+ }
74
+ clean() {
75
+ const sizeBefore = this._store.size;
76
+ this._store.clear();
77
+ return sizeBefore;
78
+ }
79
+ _startCleanup() {
80
+ if (this._cleanupTimer)
81
+ return;
82
+ this._cleanupTimer = setInterval(() => {
83
+ this._removeExpiredEntries();
84
+ }, this._cleanupInterval);
85
+ }
86
+ _removeExpiredEntries() {
87
+ const now = Date.now();
88
+ for (const [key, entry] of this._store.entries())
89
+ if (entry.expiresAt !== -1 && now > entry.expiresAt)
90
+ this._store.delete(key);
91
+ }
92
+ destroy() {
93
+ if (this._cleanupTimer) {
94
+ clearInterval(this._cleanupTimer);
95
+ this._cleanupTimer = null;
96
+ }
97
+ this._store.clear();
98
+ }
99
+ }
100
+
101
+ export { MemoryStore };
@@ -0,0 +1,61 @@
1
+ // @bun
2
+ import {
3
+ PARSE_HUMAN_TIME_TO_SECONDS_ERROR_KEYS
4
+ } from "./chunk-12qzn7jw.js";
5
+ import {
6
+ BaseError
7
+ } from "./chunk-9cgzhc50.js";
8
+
9
+ // source/modules/jwt/utils/parse-human-time-to-seconds.ts
10
+ var TIME_UNITS = {
11
+ SECOND: 1,
12
+ MINUTE: 60,
13
+ HOUR: 60 * 60,
14
+ DAY: 60 * 60 * 24,
15
+ WEEK: 60 * 60 * 24 * 7,
16
+ YEAR: 60 * 60 * 24 * 365.25
17
+ };
18
+ var TIME_EXPRESSION_REGEX = /^(\+|-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
19
+ var UNIT_MAPPINGS = {
20
+ s: TIME_UNITS.SECOND,
21
+ sec: TIME_UNITS.SECOND,
22
+ secs: TIME_UNITS.SECOND,
23
+ second: TIME_UNITS.SECOND,
24
+ seconds: TIME_UNITS.SECOND,
25
+ m: TIME_UNITS.MINUTE,
26
+ min: TIME_UNITS.MINUTE,
27
+ mins: TIME_UNITS.MINUTE,
28
+ minute: TIME_UNITS.MINUTE,
29
+ minutes: TIME_UNITS.MINUTE,
30
+ h: TIME_UNITS.HOUR,
31
+ hr: TIME_UNITS.HOUR,
32
+ hrs: TIME_UNITS.HOUR,
33
+ hour: TIME_UNITS.HOUR,
34
+ hours: TIME_UNITS.HOUR,
35
+ d: TIME_UNITS.DAY,
36
+ day: TIME_UNITS.DAY,
37
+ days: TIME_UNITS.DAY,
38
+ w: TIME_UNITS.WEEK,
39
+ week: TIME_UNITS.WEEK,
40
+ weeks: TIME_UNITS.WEEK,
41
+ y: TIME_UNITS.YEAR,
42
+ yr: TIME_UNITS.YEAR,
43
+ yrs: TIME_UNITS.YEAR,
44
+ year: TIME_UNITS.YEAR,
45
+ years: TIME_UNITS.YEAR
46
+ };
47
+ var parseHumanTimeToSeconds = (timeExpression) => {
48
+ const match = TIME_EXPRESSION_REGEX.exec(timeExpression);
49
+ if (!match || match[4] && match[1])
50
+ throw new BaseError(PARSE_HUMAN_TIME_TO_SECONDS_ERROR_KEYS.INVALID_TIME_EXPRESSION);
51
+ const [, sign, valueStr, unitStr, direction] = match;
52
+ const value = parseFloat(valueStr);
53
+ const unit = unitStr.toLowerCase();
54
+ const multiplier = UNIT_MAPPINGS[unit];
55
+ const seconds = Math.round(value * multiplier);
56
+ if (sign === "-" || direction === "ago")
57
+ return -seconds;
58
+ return seconds;
59
+ };
60
+
61
+ export { parseHumanTimeToSeconds };
@@ -0,0 +1,32 @@
1
+ // @bun
2
+ import {
3
+ SINGLETON_MANAGER_ERROR_KEYS
4
+ } from "./chunk-z0ct35ft.js";
5
+ import {
6
+ BaseError
7
+ } from "./chunk-9cgzhc50.js";
8
+
9
+ // source/modules/singleton-manager/singleton-manager.ts
10
+ class SingletonManager {
11
+ static _registry = new Map;
12
+ static register(name, instance) {
13
+ if (this._registry.has(name))
14
+ throw new BaseError(SINGLETON_MANAGER_ERROR_KEYS.CLASS_INSTANCE_ALREADY_REGISTERED, { name });
15
+ this._registry.set(name, instance);
16
+ }
17
+ static unregister(name) {
18
+ if (!this._registry.has(name))
19
+ throw new BaseError(SINGLETON_MANAGER_ERROR_KEYS.CLASS_INSTANCE_NOT_REGISTERED, { name });
20
+ this._registry.delete(name);
21
+ }
22
+ static get(name) {
23
+ if (!this._registry.has(name))
24
+ throw new BaseError(SINGLETON_MANAGER_ERROR_KEYS.CLASS_INSTANCE_NOT_REGISTERED, { name });
25
+ return this._registry.get(name);
26
+ }
27
+ static has(name) {
28
+ return this._registry.has(name);
29
+ }
30
+ }
31
+
32
+ export { SingletonManager };