@geekmidas/audit 10.0.0-alpha.16 → 10.0.0-alpha.161

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.
package/README.md CHANGED
@@ -464,6 +464,16 @@ const endpoint = api
464
464
  4. **Add request context**: Include request IDs, endpoints, and IPs in metadata
465
465
  5. **Use meaningful types**: Name audit types with domain context (e.g., `order.shipped` not `update`)
466
466
 
467
+ ## Optional peers
468
+
469
+ <!-- optional-peers:start -->
470
+
471
+ <!-- Generated by `node scripts/check-optional-peers.mjs --write-docs`; CI fails when it drifts. -->
472
+
473
+ No entry imports an optional peer when it loads. `@geekmidas/cache`, `@geekmidas/schema`, `knex`, `kysely` are loaded only when a feature that uses one runs (an `import()` inside a `try`, whose error names the package to install), or named only in types.
474
+
475
+ <!-- optional-peers:end -->
476
+
467
477
  ## License
468
478
 
469
479
  MIT
package/dist/memory.cjs CHANGED
@@ -1,10 +1,29 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_cache = require("./cache.cjs");
3
- let _geekmidas_cache_memory = require("@geekmidas/cache/memory");
4
3
  //#region src/memory.ts
5
4
  /**
5
+ * A `Map` behind the `Cache` interface, so the in-memory store needs no
6
+ * `@geekmidas/cache` — an optional peer — at run time. Records never expire:
7
+ * they live as long as the process.
8
+ */
9
+ var MapCache = class {
10
+ store = /* @__PURE__ */ new Map();
11
+ async get(key) {
12
+ return this.store.get(key);
13
+ }
14
+ async set(key, value) {
15
+ this.store.set(key, value);
16
+ }
17
+ async delete(key) {
18
+ this.store.delete(key);
19
+ }
20
+ async ttl(key) {
21
+ return this.store.has(key) ? Number.POSITIVE_INFINITY : 0;
22
+ }
23
+ };
24
+ /**
6
25
  * In-memory audit storage implementation.
7
- * Convenience wrapper around CacheAuditStorage with InMemoryCache.
26
+ * Convenience wrapper around CacheAuditStorage with an in-process map.
8
27
  *
9
28
  * Useful for testing, development, and applications that don't need persistent audit logs.
10
29
  *
@@ -36,10 +55,7 @@ let _geekmidas_cache_memory = require("@geekmidas/cache/memory");
36
55
  */
37
56
  var InMemoryAuditStorage = class extends require_cache.CacheAuditStorage {
38
57
  constructor() {
39
- super({
40
- cache: new _geekmidas_cache_memory.InMemoryCache(),
41
- ttl: 31536e3
42
- });
58
+ super({ cache: new MapCache() });
43
59
  }
44
60
  };
45
61
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"memory.cjs","names":["CacheAuditStorage","InMemoryCache"],"sources":["../src/memory.ts"],"sourcesContent":["import { InMemoryCache } from '@geekmidas/cache/memory';\nimport { CacheAuditStorage } from './cache';\nimport type { AuditableAction } from './types';\n\n/**\n * In-memory audit storage implementation.\n * Convenience wrapper around CacheAuditStorage with InMemoryCache.\n *\n * Useful for testing, development, and applications that don't need persistent audit logs.\n *\n * @template TAuditAction - Optional type parameter for type-safe audit actions.\n *\n * @example\n * ```typescript\n * import { InMemoryAuditStorage } from '@geekmidas/audit/memory';\n * import { DefaultAuditor } from '@geekmidas/audit';\n *\n * const storage = new InMemoryAuditStorage();\n * const auditor = new DefaultAuditor({\n * actor: { id: 'user-123', type: 'user' },\n * storage,\n * });\n *\n * auditor.audit('user.created', { userId: '789', email: 'test@example.com' });\n * await auditor.flush();\n *\n * // Query stored records\n * const records = await storage.query({ type: 'user.created' });\n *\n * // Get all records (for testing)\n * const all = await storage.getRecords();\n *\n * // Clear for next test\n * await storage.clear();\n * ```\n */\nexport class InMemoryAuditStorage<\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> extends CacheAuditStorage<TAuditAction> {\n\tconstructor() {\n\t\tsuper({\n\t\t\tcache: new InMemoryCache(),\n\t\t\t// Use a long TTL since in-memory cache expires items\n\t\t\tttl: 86400 * 365, // 1 year\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,uBAAb,cAKUA,cAAAA,kBAAgC;CACzC,cAAc;EACb,MAAM;GACL,OAAO,IAAIC,wBAAAA,cAAc;GAEzB,KAAK;EACN,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"memory.cjs","names":["CacheAuditStorage"],"sources":["../src/memory.ts"],"sourcesContent":["import type { Cache } from '@geekmidas/cache';\nimport { CacheAuditStorage } from './cache';\nimport type { AuditableAction } from './types';\n\n/**\n * A `Map` behind the `Cache` interface, so the in-memory store needs no\n * `@geekmidas/cache` — an optional peer — at run time. Records never expire:\n * they live as long as the process.\n */\nclass MapCache implements Cache {\n\tprivate readonly store = new Map<string, unknown>();\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\treturn this.store.get(key) as T | undefined;\n\t}\n\n\tasync set<T>(key: string, value: T): Promise<void> {\n\t\tthis.store.set(key, value);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tthis.store.delete(key);\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\treturn this.store.has(key) ? Number.POSITIVE_INFINITY : 0;\n\t}\n}\n\n/**\n * In-memory audit storage implementation.\n * Convenience wrapper around CacheAuditStorage with an in-process map.\n *\n * Useful for testing, development, and applications that don't need persistent audit logs.\n *\n * @template TAuditAction - Optional type parameter for type-safe audit actions.\n *\n * @example\n * ```typescript\n * import { InMemoryAuditStorage } from '@geekmidas/audit/memory';\n * import { DefaultAuditor } from '@geekmidas/audit';\n *\n * const storage = new InMemoryAuditStorage();\n * const auditor = new DefaultAuditor({\n * actor: { id: 'user-123', type: 'user' },\n * storage,\n * });\n *\n * auditor.audit('user.created', { userId: '789', email: 'test@example.com' });\n * await auditor.flush();\n *\n * // Query stored records\n * const records = await storage.query({ type: 'user.created' });\n *\n * // Get all records (for testing)\n * const all = await storage.getRecords();\n *\n * // Clear for next test\n * await storage.clear();\n * ```\n */\nexport class InMemoryAuditStorage<\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> extends CacheAuditStorage<TAuditAction> {\n\tconstructor() {\n\t\tsuper({ cache: new MapCache() });\n\t}\n}\n"],"mappings":";;;;;;;;AASA,IAAM,WAAN,MAAgC;CAC/B,wBAAyB,IAAI,IAAqB;CAElD,MAAM,IAAO,KAAqC;EACjD,OAAO,KAAK,MAAM,IAAI,GAAG;CAC1B;CAEA,MAAM,IAAO,KAAa,OAAyB;EAClD,KAAK,MAAM,IAAI,KAAK,KAAK;CAC1B;CAEA,MAAM,OAAO,KAA4B;EACxC,KAAK,MAAM,OAAO,GAAG;CACtB;CAEA,MAAM,IAAI,KAA8B;EACvC,OAAO,KAAK,MAAM,IAAI,GAAG,IAAI,OAAO,oBAAoB;CACzD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,uBAAb,cAKUA,cAAAA,kBAAgC;CACzC,cAAc;EACb,MAAM,EAAE,OAAO,IAAI,SAAS,EAAE,CAAC;CAChC;AACD"}
package/dist/memory.d.cts CHANGED
@@ -3,7 +3,7 @@ import { CacheAuditStorage } from "./cache.cjs";
3
3
  //#region src/memory.d.ts
4
4
  /**
5
5
  * In-memory audit storage implementation.
6
- * Convenience wrapper around CacheAuditStorage with InMemoryCache.
6
+ * Convenience wrapper around CacheAuditStorage with an in-process map.
7
7
  *
8
8
  * Useful for testing, development, and applications that don't need persistent audit logs.
9
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.cts","names":[],"sources":["../src/memory.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAoCa,qBACZ,qBAAqB,mCAAmC,0CAI/C,kBAAkB;EAC3B"}
1
+ {"version":3,"file":"memory.d.cts","names":[],"sources":["../src/memory.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA6Da,qBACZ,qBAAqB,mCAAmC,0CAI/C,kBAAkB;EAC3B"}
package/dist/memory.d.mts CHANGED
@@ -3,7 +3,7 @@ import { CacheAuditStorage } from "./cache.mjs";
3
3
  //#region src/memory.d.ts
4
4
  /**
5
5
  * In-memory audit storage implementation.
6
- * Convenience wrapper around CacheAuditStorage with InMemoryCache.
6
+ * Convenience wrapper around CacheAuditStorage with an in-process map.
7
7
  *
8
8
  * Useful for testing, development, and applications that don't need persistent audit logs.
9
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.mts","names":[],"sources":["../src/memory.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAoCa,qBACZ,qBAAqB,mCAAmC,0CAI/C,kBAAkB;EAC3B"}
1
+ {"version":3,"file":"memory.d.mts","names":[],"sources":["../src/memory.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA6Da,qBACZ,qBAAqB,mCAAmC,0CAI/C,kBAAkB;EAC3B"}
package/dist/memory.mjs CHANGED
@@ -1,9 +1,28 @@
1
1
  import { CacheAuditStorage } from "./cache.mjs";
2
- import { InMemoryCache } from "@geekmidas/cache/memory";
3
2
  //#region src/memory.ts
4
3
  /**
4
+ * A `Map` behind the `Cache` interface, so the in-memory store needs no
5
+ * `@geekmidas/cache` — an optional peer — at run time. Records never expire:
6
+ * they live as long as the process.
7
+ */
8
+ var MapCache = class {
9
+ store = /* @__PURE__ */ new Map();
10
+ async get(key) {
11
+ return this.store.get(key);
12
+ }
13
+ async set(key, value) {
14
+ this.store.set(key, value);
15
+ }
16
+ async delete(key) {
17
+ this.store.delete(key);
18
+ }
19
+ async ttl(key) {
20
+ return this.store.has(key) ? Number.POSITIVE_INFINITY : 0;
21
+ }
22
+ };
23
+ /**
5
24
  * In-memory audit storage implementation.
6
- * Convenience wrapper around CacheAuditStorage with InMemoryCache.
25
+ * Convenience wrapper around CacheAuditStorage with an in-process map.
7
26
  *
8
27
  * Useful for testing, development, and applications that don't need persistent audit logs.
9
28
  *
@@ -35,10 +54,7 @@ import { InMemoryCache } from "@geekmidas/cache/memory";
35
54
  */
36
55
  var InMemoryAuditStorage = class extends CacheAuditStorage {
37
56
  constructor() {
38
- super({
39
- cache: new InMemoryCache(),
40
- ttl: 31536e3
41
- });
57
+ super({ cache: new MapCache() });
42
58
  }
43
59
  };
44
60
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"memory.mjs","names":[],"sources":["../src/memory.ts"],"sourcesContent":["import { InMemoryCache } from '@geekmidas/cache/memory';\nimport { CacheAuditStorage } from './cache';\nimport type { AuditableAction } from './types';\n\n/**\n * In-memory audit storage implementation.\n * Convenience wrapper around CacheAuditStorage with InMemoryCache.\n *\n * Useful for testing, development, and applications that don't need persistent audit logs.\n *\n * @template TAuditAction - Optional type parameter for type-safe audit actions.\n *\n * @example\n * ```typescript\n * import { InMemoryAuditStorage } from '@geekmidas/audit/memory';\n * import { DefaultAuditor } from '@geekmidas/audit';\n *\n * const storage = new InMemoryAuditStorage();\n * const auditor = new DefaultAuditor({\n * actor: { id: 'user-123', type: 'user' },\n * storage,\n * });\n *\n * auditor.audit('user.created', { userId: '789', email: 'test@example.com' });\n * await auditor.flush();\n *\n * // Query stored records\n * const records = await storage.query({ type: 'user.created' });\n *\n * // Get all records (for testing)\n * const all = await storage.getRecords();\n *\n * // Clear for next test\n * await storage.clear();\n * ```\n */\nexport class InMemoryAuditStorage<\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> extends CacheAuditStorage<TAuditAction> {\n\tconstructor() {\n\t\tsuper({\n\t\t\tcache: new InMemoryCache(),\n\t\t\t// Use a long TTL since in-memory cache expires items\n\t\t\tttl: 86400 * 365, // 1 year\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,uBAAb,cAKU,kBAAgC;CACzC,cAAc;EACb,MAAM;GACL,OAAO,IAAI,cAAc;GAEzB,KAAK;EACN,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"memory.mjs","names":[],"sources":["../src/memory.ts"],"sourcesContent":["import type { Cache } from '@geekmidas/cache';\nimport { CacheAuditStorage } from './cache';\nimport type { AuditableAction } from './types';\n\n/**\n * A `Map` behind the `Cache` interface, so the in-memory store needs no\n * `@geekmidas/cache` — an optional peer — at run time. Records never expire:\n * they live as long as the process.\n */\nclass MapCache implements Cache {\n\tprivate readonly store = new Map<string, unknown>();\n\n\tasync get<T>(key: string): Promise<T | undefined> {\n\t\treturn this.store.get(key) as T | undefined;\n\t}\n\n\tasync set<T>(key: string, value: T): Promise<void> {\n\t\tthis.store.set(key, value);\n\t}\n\n\tasync delete(key: string): Promise<void> {\n\t\tthis.store.delete(key);\n\t}\n\n\tasync ttl(key: string): Promise<number> {\n\t\treturn this.store.has(key) ? Number.POSITIVE_INFINITY : 0;\n\t}\n}\n\n/**\n * In-memory audit storage implementation.\n * Convenience wrapper around CacheAuditStorage with an in-process map.\n *\n * Useful for testing, development, and applications that don't need persistent audit logs.\n *\n * @template TAuditAction - Optional type parameter for type-safe audit actions.\n *\n * @example\n * ```typescript\n * import { InMemoryAuditStorage } from '@geekmidas/audit/memory';\n * import { DefaultAuditor } from '@geekmidas/audit';\n *\n * const storage = new InMemoryAuditStorage();\n * const auditor = new DefaultAuditor({\n * actor: { id: 'user-123', type: 'user' },\n * storage,\n * });\n *\n * auditor.audit('user.created', { userId: '789', email: 'test@example.com' });\n * await auditor.flush();\n *\n * // Query stored records\n * const records = await storage.query({ type: 'user.created' });\n *\n * // Get all records (for testing)\n * const all = await storage.getRecords();\n *\n * // Clear for next test\n * await storage.clear();\n * ```\n */\nexport class InMemoryAuditStorage<\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> extends CacheAuditStorage<TAuditAction> {\n\tconstructor() {\n\t\tsuper({ cache: new MapCache() });\n\t}\n}\n"],"mappings":";;;;;;;AASA,IAAM,WAAN,MAAgC;CAC/B,wBAAyB,IAAI,IAAqB;CAElD,MAAM,IAAO,KAAqC;EACjD,OAAO,KAAK,MAAM,IAAI,GAAG;CAC1B;CAEA,MAAM,IAAO,KAAa,OAAyB;EAClD,KAAK,MAAM,IAAI,KAAK,KAAK;CAC1B;CAEA,MAAM,OAAO,KAA4B;EACxC,KAAK,MAAM,OAAO,GAAG;CACtB;CAEA,MAAM,IAAI,KAA8B;EACvC,OAAO,KAAK,MAAM,IAAI,GAAG,IAAI,OAAO,oBAAoB;CACzD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,uBAAb,cAKU,kBAAgC;CACzC,cAAc;EACb,MAAM,EAAE,OAAO,IAAI,SAAS,EAAE,CAAC;CAChC;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/audit",
3
- "version": "10.0.0-alpha.16",
3
+ "version": "10.0.0-alpha.161",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -72,8 +72,8 @@
72
72
  "peerDependencies": {
73
73
  "kysely": "~0.29.6",
74
74
  "knex": ">=3.3.0",
75
- "@geekmidas/cache": "^10.0.0-alpha.16",
76
- "@geekmidas/schema": "^10.0.0-alpha.16"
75
+ "@geekmidas/cache": ">=10.0.0-alpha.161 <10.0.0",
76
+ "@geekmidas/schema": ">=10.0.0-alpha.161 <10.0.0"
77
77
  },
78
78
  "peerDependenciesMeta": {
79
79
  "@geekmidas/cache": {
@@ -94,7 +94,10 @@
94
94
  "pg": "~8.23.0",
95
95
  "@types/pg": "~8.23.1",
96
96
  "knex": "~3.3.0",
97
- "@geekmidas/cache": "^10.0.0-alpha.16",
98
- "@geekmidas/schema": "^10.0.0-alpha.16"
97
+ "@geekmidas/schema": ">=10.0.0-alpha.161 <10.0.0",
98
+ "@geekmidas/cache": ">=10.0.0-alpha.161 <10.0.0"
99
+ },
100
+ "scripts": {
101
+ "build": "tsdown --config ../../tsdown.config.ts --filter ."
99
102
  }
100
103
  }