@mrxsys/mrx-core 2.11.0-1-and-275-20251029 → 2.11.0-1-and-277-20251029

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.
@@ -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 };
@@ -1,5 +1,5 @@
1
1
  import { Elysia } from 'elysia';
2
- import type { KvStore } from '../../../modules/kv-store/types';
2
+ import type { KvStore } from '../../../modules/kv-store/types/kv-store';
3
3
  import type { CacheOptions } from './types/cache-options';
4
4
  export declare const cache: (store?: KvStore) => Elysia<"", {
5
5
  decorator: {};
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  MemoryStore
4
- } from "../../kv-store/memory/index.js";
4
+ } from "../../../chunk-e30paw8a.js";
5
5
  import"../../../chunk-xhhj1gvj.js";
6
6
  import"../../../chunk-9cgzhc50.js";
7
7
 
@@ -4,7 +4,7 @@ import {
4
4
  } from "../../../chunk-dre2fgj0.js";
5
5
  import {
6
6
  MemoryStore
7
- } from "../../kv-store/memory/index.js";
7
+ } from "../../../chunk-e30paw8a.js";
8
8
  import"../../../chunk-xhhj1gvj.js";
9
9
  import {
10
10
  HttpError
@@ -14,8 +14,9 @@ import"../../../chunk-9cgzhc50.js";
14
14
 
15
15
  // source/modules/elysia/rate-limit/rate-limit.ts
16
16
  import { Elysia } from "elysia";
17
- var rateLimit = (store = new MemoryStore) => {
17
+ var rateLimit = (store) => {
18
18
  const restrictedRoutes = new Map;
19
+ store = store || new MemoryStore;
19
20
  const rateLimitCheck = async (key, limit, window, set) => {
20
21
  if (set.headers["X-RateLimit-Limit"])
21
22
  return;
@@ -1,4 +1,4 @@
1
- import type { KvStore } from '../../../modules/kv-store/types';
1
+ import type { KvStore } from '../../../modules/kv-store/types/kv-store';
2
2
  import { Elysia, type HTTPHeaders, type StatusMap } from 'elysia';
3
3
  import type { RateLimitOptions } from './types/rate-limit-options';
4
4
  /**
@@ -1,103 +1,9 @@
1
1
  // @bun
2
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
- }
3
+ MemoryStore
4
+ } from "../../../chunk-e30paw8a.js";
5
+ import"../../../chunk-xhhj1gvj.js";
6
+ import"../../../chunk-9cgzhc50.js";
100
7
  export {
101
8
  MemoryStore
102
9
  };
103
- export { MemoryStore };
@@ -51,7 +51,7 @@ class Logger extends TypedEventEmitter {
51
51
  this._batchTimeout = batchTimeout;
52
52
  this._autoEnd = autoEnd;
53
53
  this._flushOnBeforeExit = flushOnBeforeExit;
54
- this._worker = new Worker(new URL("worker-logger.ts", import.meta.url).href, { type: "module" });
54
+ this._worker = new Worker(new URL("worker-logger.js", import.meta.url).href, { type: "module" });
55
55
  this._setupWorkerMessages();
56
56
  if (this._autoEnd)
57
57
  this._setupAutoEnd();
@@ -0,0 +1,72 @@
1
+ // @bun
2
+ // source/modules/logger/worker-logger.ts
3
+ var sinks = {};
4
+ var self = globalThis;
5
+ var processLogEntry = async (log) => {
6
+ await Promise.all(log.sinkNames.map(async (sinkName) => {
7
+ const sink = sinks[sinkName];
8
+ if (!sink)
9
+ return;
10
+ try {
11
+ await sink.log(log.level, log.timestamp, log.object);
12
+ } catch (error) {
13
+ self.postMessage({
14
+ type: "SINK_LOG_ERROR",
15
+ sinkName,
16
+ error,
17
+ object: log.object
18
+ });
19
+ }
20
+ }));
21
+ };
22
+ self.addEventListener("message", async (event) => {
23
+ switch (event.data.type) {
24
+ case "REGISTER_SINK": {
25
+ const {
26
+ sinkName,
27
+ sinkClassName,
28
+ sinkClassString,
29
+ sinkArgs
30
+ } = event.data;
31
+ try {
32
+ const factory = new Function("sinkArgs", `
33
+ ${sinkClassString}
34
+ return new ${sinkClassName}(...sinkArgs);
35
+ `);
36
+ sinks[sinkName] = factory(sinkArgs);
37
+ } catch (error) {
38
+ self.postMessage({
39
+ type: "REGISTER_SINK_ERROR",
40
+ sinkName,
41
+ error
42
+ });
43
+ }
44
+ break;
45
+ }
46
+ case "LOG_BATCH": {
47
+ const { logs } = event.data;
48
+ try {
49
+ for (const log of logs)
50
+ await processLogEntry(log);
51
+ } finally {
52
+ self.postMessage({ type: "BATCH_COMPLETE" });
53
+ }
54
+ break;
55
+ }
56
+ case "CLOSE": {
57
+ await Promise.all(Object.entries(sinks).map(async ([name, sink]) => {
58
+ try {
59
+ await sink.close?.();
60
+ } catch (error) {
61
+ self.postMessage({
62
+ type: "SINK_CLOSE_ERROR",
63
+ sinkName: name,
64
+ error
65
+ });
66
+ }
67
+ }));
68
+ self.postMessage({ type: "CLOSE_COMPLETE" });
69
+ break;
70
+ }
71
+ }
72
+ });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@mrxsys/mrx-core",
3
- "version": "2.11.0-1-and-275-20251029",
3
+ "version": "2.11.0-1-and-277-20251029",
4
4
  "author": "Ruby",
5
5
  "devDependencies": {
6
6
  "@eslint/js": "^9.38.0",
7
7
  "@sinclair/typebox": "0.34.41",
8
8
  "@stylistic/eslint-plugin": "^5.5.0",
9
- "@types/bun": "^1.3.0",
10
- "@types/nodemailer": "^7.0.2",
9
+ "@types/bun": "^1.3.1",
10
+ "@types/nodemailer": "^7.0.3",
11
11
  "elysia": "1.4.13",
12
12
  "eslint": "^9.38.0",
13
13
  "globals": "^16.4.0",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@sinclair/typebox": "0.34.41",
23
- "elysia": "^1.4.12",
23
+ "elysia": "^1.4.13",
24
24
  "ioredis": "^5.8.2",
25
25
  "jose": "^6.1.0",
26
26
  "mssql": "^12.0.0",