@dexto/storage 1.6.0

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 (158) hide show
  1. package/LICENSE +44 -0
  2. package/README.md +80 -0
  3. package/dist/blob/factories/index.cjs +31 -0
  4. package/dist/blob/factories/index.d.cts +6 -0
  5. package/dist/blob/factories/index.d.ts +6 -0
  6. package/dist/blob/factories/index.d.ts.map +1 -0
  7. package/dist/blob/factories/index.js +6 -0
  8. package/dist/blob/factories/local.cjs +38 -0
  9. package/dist/blob/factories/local.d.cts +21 -0
  10. package/dist/blob/factories/local.d.ts +17 -0
  11. package/dist/blob/factories/local.d.ts.map +1 -0
  12. package/dist/blob/factories/local.js +14 -0
  13. package/dist/blob/factories/memory.cjs +44 -0
  14. package/dist/blob/factories/memory.d.cts +21 -0
  15. package/dist/blob/factories/memory.d.ts +17 -0
  16. package/dist/blob/factories/memory.d.ts.map +1 -0
  17. package/dist/blob/factories/memory.js +20 -0
  18. package/dist/blob/factory.cjs +16 -0
  19. package/dist/blob/factory.d.cts +36 -0
  20. package/dist/blob/factory.d.ts +35 -0
  21. package/dist/blob/factory.d.ts.map +1 -0
  22. package/dist/blob/factory.js +0 -0
  23. package/dist/blob/index.cjs +45 -0
  24. package/dist/blob/index.d.cts +8 -0
  25. package/dist/blob/index.d.ts +26 -0
  26. package/dist/blob/index.d.ts.map +1 -0
  27. package/dist/blob/index.js +19 -0
  28. package/dist/blob/local-blob-store.cjs +532 -0
  29. package/dist/blob/local-blob-store.d.cts +56 -0
  30. package/dist/blob/local-blob-store.d.ts +54 -0
  31. package/dist/blob/local-blob-store.d.ts.map +1 -0
  32. package/dist/blob/local-blob-store.js +498 -0
  33. package/dist/blob/memory-blob-store.cjs +327 -0
  34. package/dist/blob/memory-blob-store.d.cts +69 -0
  35. package/dist/blob/memory-blob-store.d.ts +67 -0
  36. package/dist/blob/memory-blob-store.d.ts.map +1 -0
  37. package/dist/blob/memory-blob-store.js +303 -0
  38. package/dist/blob/schemas.cjs +52 -0
  39. package/dist/blob/schemas.d.cts +87 -0
  40. package/dist/blob/schemas.d.ts +86 -0
  41. package/dist/blob/schemas.d.ts.map +1 -0
  42. package/dist/blob/schemas.js +25 -0
  43. package/dist/blob/types.cjs +16 -0
  44. package/dist/blob/types.d.cts +1 -0
  45. package/dist/blob/types.d.ts +2 -0
  46. package/dist/blob/types.d.ts.map +1 -0
  47. package/dist/blob/types.js +0 -0
  48. package/dist/cache/factories/index.cjs +31 -0
  49. package/dist/cache/factories/index.d.cts +6 -0
  50. package/dist/cache/factories/index.d.ts +6 -0
  51. package/dist/cache/factories/index.d.ts.map +1 -0
  52. package/dist/cache/factories/index.js +6 -0
  53. package/dist/cache/factories/memory.cjs +39 -0
  54. package/dist/cache/factories/memory.d.cts +21 -0
  55. package/dist/cache/factories/memory.d.ts +17 -0
  56. package/dist/cache/factories/memory.d.ts.map +1 -0
  57. package/dist/cache/factories/memory.js +15 -0
  58. package/dist/cache/factories/redis.cjs +65 -0
  59. package/dist/cache/factories/redis.d.cts +24 -0
  60. package/dist/cache/factories/redis.d.ts +20 -0
  61. package/dist/cache/factories/redis.d.ts.map +1 -0
  62. package/dist/cache/factories/redis.js +31 -0
  63. package/dist/cache/factory.cjs +16 -0
  64. package/dist/cache/factory.d.cts +42 -0
  65. package/dist/cache/factory.d.ts +41 -0
  66. package/dist/cache/factory.d.ts.map +1 -0
  67. package/dist/cache/factory.js +0 -0
  68. package/dist/cache/index.cjs +42 -0
  69. package/dist/cache/index.d.cts +7 -0
  70. package/dist/cache/index.d.ts +25 -0
  71. package/dist/cache/index.d.ts.map +1 -0
  72. package/dist/cache/index.js +17 -0
  73. package/dist/cache/memory-cache-store.cjs +106 -0
  74. package/dist/cache/memory-cache-store.d.cts +27 -0
  75. package/dist/cache/memory-cache-store.d.ts +25 -0
  76. package/dist/cache/memory-cache-store.d.ts.map +1 -0
  77. package/dist/cache/memory-cache-store.js +82 -0
  78. package/dist/cache/redis-store.cjs +176 -0
  79. package/dist/cache/redis-store.d.cts +34 -0
  80. package/dist/cache/redis-store.d.ts +32 -0
  81. package/dist/cache/redis-store.d.ts.map +1 -0
  82. package/dist/cache/redis-store.js +152 -0
  83. package/dist/cache/schemas.cjs +70 -0
  84. package/dist/cache/schemas.d.cts +93 -0
  85. package/dist/cache/schemas.d.ts +91 -0
  86. package/dist/cache/schemas.d.ts.map +1 -0
  87. package/dist/cache/schemas.js +43 -0
  88. package/dist/cache/types.cjs +16 -0
  89. package/dist/cache/types.d.cts +1 -0
  90. package/dist/cache/types.d.ts +2 -0
  91. package/dist/cache/types.d.ts.map +1 -0
  92. package/dist/cache/types.js +0 -0
  93. package/dist/database/factories/index.cjs +34 -0
  94. package/dist/database/factories/index.d.cts +7 -0
  95. package/dist/database/factories/index.d.ts +7 -0
  96. package/dist/database/factories/index.d.ts.map +1 -0
  97. package/dist/database/factories/index.js +8 -0
  98. package/dist/database/factories/memory.cjs +39 -0
  99. package/dist/database/factories/memory.d.cts +20 -0
  100. package/dist/database/factories/memory.d.ts +16 -0
  101. package/dist/database/factories/memory.d.ts.map +1 -0
  102. package/dist/database/factories/memory.js +15 -0
  103. package/dist/database/factories/postgres.cjs +61 -0
  104. package/dist/database/factories/postgres.d.cts +23 -0
  105. package/dist/database/factories/postgres.d.ts +19 -0
  106. package/dist/database/factories/postgres.d.ts.map +1 -0
  107. package/dist/database/factories/postgres.js +27 -0
  108. package/dist/database/factories/sqlite.cjs +65 -0
  109. package/dist/database/factories/sqlite.d.cts +24 -0
  110. package/dist/database/factories/sqlite.d.ts +20 -0
  111. package/dist/database/factories/sqlite.d.ts.map +1 -0
  112. package/dist/database/factories/sqlite.js +31 -0
  113. package/dist/database/factory.cjs +16 -0
  114. package/dist/database/factory.d.cts +42 -0
  115. package/dist/database/factory.d.ts +41 -0
  116. package/dist/database/factory.d.ts.map +1 -0
  117. package/dist/database/factory.js +0 -0
  118. package/dist/database/index.cjs +46 -0
  119. package/dist/database/index.d.cts +8 -0
  120. package/dist/database/index.d.ts +26 -0
  121. package/dist/database/index.d.ts.map +1 -0
  122. package/dist/database/index.js +24 -0
  123. package/dist/database/memory-database-store.cjs +121 -0
  124. package/dist/database/memory-database-store.d.cts +30 -0
  125. package/dist/database/memory-database-store.d.ts +28 -0
  126. package/dist/database/memory-database-store.d.ts.map +1 -0
  127. package/dist/database/memory-database-store.js +97 -0
  128. package/dist/database/postgres-store.cjs +342 -0
  129. package/dist/database/postgres-store.d.cts +57 -0
  130. package/dist/database/postgres-store.d.ts +55 -0
  131. package/dist/database/postgres-store.d.ts.map +1 -0
  132. package/dist/database/postgres-store.js +318 -0
  133. package/dist/database/schemas.cjs +82 -0
  134. package/dist/database/schemas.d.cts +127 -0
  135. package/dist/database/schemas.d.ts +125 -0
  136. package/dist/database/schemas.d.ts.map +1 -0
  137. package/dist/database/schemas.js +54 -0
  138. package/dist/database/sqlite-store.cjs +270 -0
  139. package/dist/database/sqlite-store.d.cts +35 -0
  140. package/dist/database/sqlite-store.d.ts +33 -0
  141. package/dist/database/sqlite-store.d.ts.map +1 -0
  142. package/dist/database/sqlite-store.js +236 -0
  143. package/dist/database/types.cjs +16 -0
  144. package/dist/database/types.d.cts +1 -0
  145. package/dist/database/types.d.ts +2 -0
  146. package/dist/database/types.d.ts.map +1 -0
  147. package/dist/database/types.js +0 -0
  148. package/dist/index.cjs +82 -0
  149. package/dist/index.d.cts +24 -0
  150. package/dist/index.d.ts +25 -0
  151. package/dist/index.d.ts.map +1 -0
  152. package/dist/index.js +50 -0
  153. package/dist/schemas.cjs +67 -0
  154. package/dist/schemas.d.cts +72 -0
  155. package/dist/schemas.d.ts +70 -0
  156. package/dist/schemas.d.ts.map +1 -0
  157. package/dist/schemas.js +46 -0
  158. package/package.json +55 -0
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var memory_exports = {};
20
+ __export(memory_exports, {
21
+ inMemoryCacheFactory: () => inMemoryCacheFactory
22
+ });
23
+ module.exports = __toCommonJS(memory_exports);
24
+ var import_schemas = require("../schemas.js");
25
+ var import_memory_cache_store = require("../memory-cache-store.js");
26
+ const inMemoryCacheFactory = {
27
+ configSchema: import_schemas.InMemoryCacheSchema,
28
+ create: (_config, _logger) => new import_memory_cache_store.MemoryCacheStore(),
29
+ metadata: {
30
+ displayName: "In-Memory",
31
+ description: "Store cache data in RAM (ephemeral, for testing and development)",
32
+ requiresNetwork: false,
33
+ supportsTTL: true
34
+ }
35
+ };
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ inMemoryCacheFactory
39
+ });
@@ -0,0 +1,21 @@
1
+ import { InMemoryCacheConfig } from '../schemas.cjs';
2
+ import { CacheFactory } from '../factory.cjs';
3
+ import 'zod';
4
+ import '@dexto/core';
5
+
6
+ /**
7
+ * Factory for in-memory cache storage.
8
+ *
9
+ * This factory stores data in RAM and is ideal for development,
10
+ * testing, and ephemeral use cases where persistence is not required.
11
+ *
12
+ * Features:
13
+ * - Zero external dependencies
14
+ * - Fast in-memory operations
15
+ * - TTL support for automatic expiration
16
+ * - No network required
17
+ * - Data is lost on restart
18
+ */
19
+ declare const inMemoryCacheFactory: CacheFactory<InMemoryCacheConfig>;
20
+
21
+ export { inMemoryCacheFactory };
@@ -0,0 +1,17 @@
1
+ import type { InMemoryCacheConfig } from '../schemas.js';
2
+ import type { CacheFactory } from '../factory.js';
3
+ /**
4
+ * Factory for in-memory cache storage.
5
+ *
6
+ * This factory stores data in RAM and is ideal for development,
7
+ * testing, and ephemeral use cases where persistence is not required.
8
+ *
9
+ * Features:
10
+ * - Zero external dependencies
11
+ * - Fast in-memory operations
12
+ * - TTL support for automatic expiration
13
+ * - No network required
14
+ * - Data is lost on restart
15
+ */
16
+ export declare const inMemoryCacheFactory: CacheFactory<InMemoryCacheConfig>;
17
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/cache/factories/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,EAAE,YAAY,CAAC,mBAAmB,CASlE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { InMemoryCacheSchema } from "../schemas.js";
2
+ import { MemoryCacheStore } from "../memory-cache-store.js";
3
+ const inMemoryCacheFactory = {
4
+ configSchema: InMemoryCacheSchema,
5
+ create: (_config, _logger) => new MemoryCacheStore(),
6
+ metadata: {
7
+ displayName: "In-Memory",
8
+ description: "Store cache data in RAM (ephemeral, for testing and development)",
9
+ requiresNetwork: false,
10
+ supportsTTL: true
11
+ }
12
+ };
13
+ export {
14
+ inMemoryCacheFactory
15
+ };
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var redis_exports = {};
30
+ __export(redis_exports, {
31
+ redisCacheFactory: () => redisCacheFactory
32
+ });
33
+ module.exports = __toCommonJS(redis_exports);
34
+ var import_schemas = require("../schemas.js");
35
+ var import_core = require("@dexto/core");
36
+ const redisCacheFactory = {
37
+ configSchema: import_schemas.RedisCacheSchema,
38
+ create: async (config, logger) => {
39
+ try {
40
+ const module2 = await import("../redis-store.js");
41
+ logger.info(`Connecting to Redis at ${config.host || config.url}`);
42
+ return new module2.RedisStore(config, logger);
43
+ } catch (error) {
44
+ const err = error;
45
+ if (err.code === "ERR_MODULE_NOT_FOUND") {
46
+ throw import_core.StorageError.dependencyNotInstalled(
47
+ "Redis",
48
+ "ioredis",
49
+ "npm install ioredis"
50
+ );
51
+ }
52
+ throw error;
53
+ }
54
+ },
55
+ metadata: {
56
+ displayName: "Redis",
57
+ description: "Production Redis cache with TTL and pub/sub support",
58
+ requiresNetwork: true,
59
+ supportsTTL: true
60
+ }
61
+ };
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ redisCacheFactory
65
+ });
@@ -0,0 +1,24 @@
1
+ import { RedisCacheConfig } from '../schemas.cjs';
2
+ import { CacheFactory } from '../factory.cjs';
3
+ import 'zod';
4
+ import '@dexto/core';
5
+
6
+ /**
7
+ * Factory for Redis cache storage.
8
+ *
9
+ * This factory stores data in a Redis server using the ioredis package.
10
+ * It's ideal for production deployments requiring scalability, persistence,
11
+ * and multi-machine access.
12
+ *
13
+ * Features:
14
+ * - Native TTL support
15
+ * - Connection pooling
16
+ * - Pub/sub capabilities (via additional methods)
17
+ * - Suitable for distributed deployments
18
+ *
19
+ * Note: ioredis is an optional dependency. Install it with:
20
+ * npm install ioredis
21
+ */
22
+ declare const redisCacheFactory: CacheFactory<RedisCacheConfig>;
23
+
24
+ export { redisCacheFactory };
@@ -0,0 +1,20 @@
1
+ import type { RedisCacheConfig } from '../schemas.js';
2
+ import type { CacheFactory } from '../factory.js';
3
+ /**
4
+ * Factory for Redis cache storage.
5
+ *
6
+ * This factory stores data in a Redis server using the ioredis package.
7
+ * It's ideal for production deployments requiring scalability, persistence,
8
+ * and multi-machine access.
9
+ *
10
+ * Features:
11
+ * - Native TTL support
12
+ * - Connection pooling
13
+ * - Pub/sub capabilities (via additional methods)
14
+ * - Suitable for distributed deployments
15
+ *
16
+ * Note: ioredis is an optional dependency. Install it with:
17
+ * npm install ioredis
18
+ */
19
+ export declare const redisCacheFactory: CacheFactory<RedisCacheConfig>;
20
+ //# sourceMappingURL=redis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../src/cache/factories/redis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,EAAE,YAAY,CAAC,gBAAgB,CAyB5D,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { RedisCacheSchema } from "../schemas.js";
2
+ import { StorageError } from "@dexto/core";
3
+ const redisCacheFactory = {
4
+ configSchema: RedisCacheSchema,
5
+ create: async (config, logger) => {
6
+ try {
7
+ const module = await import("../redis-store.js");
8
+ logger.info(`Connecting to Redis at ${config.host || config.url}`);
9
+ return new module.RedisStore(config, logger);
10
+ } catch (error) {
11
+ const err = error;
12
+ if (err.code === "ERR_MODULE_NOT_FOUND") {
13
+ throw StorageError.dependencyNotInstalled(
14
+ "Redis",
15
+ "ioredis",
16
+ "npm install ioredis"
17
+ );
18
+ }
19
+ throw error;
20
+ }
21
+ },
22
+ metadata: {
23
+ displayName: "Redis",
24
+ description: "Production Redis cache with TTL and pub/sub support",
25
+ requiresNetwork: true,
26
+ supportsTTL: true
27
+ }
28
+ };
29
+ export {
30
+ redisCacheFactory
31
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var factory_exports = {};
16
+ module.exports = __toCommonJS(factory_exports);
@@ -0,0 +1,42 @@
1
+ import { Logger, Cache } from '@dexto/core';
2
+ import { z } from 'zod';
3
+
4
+ /**
5
+ * Factory interface for creating cache instances.
6
+ *
7
+ * Factories are plain exports (no global registries). Images decide which factories are
8
+ * available by including them in `image.storage.cache`.
9
+ */
10
+ interface CacheFactory<TConfig = unknown> {
11
+ /**
12
+ * Zod schema for validating factory-specific configuration.
13
+ * The schema must output the `TConfig` type.
14
+ */
15
+ configSchema: z.ZodType<TConfig, z.ZodTypeDef, unknown>;
16
+ /**
17
+ * Factory function to create a Cache instance.
18
+ *
19
+ * Cache factories may return a Promise to support lazy loading of optional
20
+ * dependencies (e.g., `ioredis`).
21
+ *
22
+ * @param config - Validated configuration specific to this backend
23
+ * @param logger - Logger instance for the cache
24
+ * @returns A Cache implementation (or Promise for async backends)
25
+ */
26
+ create(config: TConfig, logger: Logger): Cache | Promise<Cache>;
27
+ /**
28
+ * Optional metadata for documentation, UIs, and discovery.
29
+ */
30
+ metadata?: {
31
+ /** Human-readable name (e.g., "Redis", "Memcached") */
32
+ displayName: string;
33
+ /** Brief description of this cache backend */
34
+ description: string;
35
+ /** Whether this backend requires network connectivity */
36
+ requiresNetwork?: boolean;
37
+ /** Whether this backend supports TTL (time-to-live) */
38
+ supportsTTL?: boolean;
39
+ };
40
+ }
41
+
42
+ export type { CacheFactory };
@@ -0,0 +1,41 @@
1
+ import type { Cache } from './types.js';
2
+ import type { Logger } from '@dexto/core';
3
+ import type { z } from 'zod';
4
+ /**
5
+ * Factory interface for creating cache instances.
6
+ *
7
+ * Factories are plain exports (no global registries). Images decide which factories are
8
+ * available by including them in `image.storage.cache`.
9
+ */
10
+ export interface CacheFactory<TConfig = unknown> {
11
+ /**
12
+ * Zod schema for validating factory-specific configuration.
13
+ * The schema must output the `TConfig` type.
14
+ */
15
+ configSchema: z.ZodType<TConfig, z.ZodTypeDef, unknown>;
16
+ /**
17
+ * Factory function to create a Cache instance.
18
+ *
19
+ * Cache factories may return a Promise to support lazy loading of optional
20
+ * dependencies (e.g., `ioredis`).
21
+ *
22
+ * @param config - Validated configuration specific to this backend
23
+ * @param logger - Logger instance for the cache
24
+ * @returns A Cache implementation (or Promise for async backends)
25
+ */
26
+ create(config: TConfig, logger: Logger): Cache | Promise<Cache>;
27
+ /**
28
+ * Optional metadata for documentation, UIs, and discovery.
29
+ */
30
+ metadata?: {
31
+ /** Human-readable name (e.g., "Redis", "Memcached") */
32
+ displayName: string;
33
+ /** Brief description of this cache backend */
34
+ description: string;
35
+ /** Whether this backend requires network connectivity */
36
+ requiresNetwork?: boolean;
37
+ /** Whether this backend supports TTL (time-to-live) */
38
+ supportsTTL?: boolean;
39
+ };
40
+ }
41
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/cache/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,WAAW,YAAY,CAAC,OAAO,GAAG,OAAO;IAC3C;;;OAGG;IACH,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAExD;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAEhE;;OAEG;IACH,QAAQ,CAAC,EAAE;QACP,uDAAuD;QACvD,WAAW,EAAE,MAAM,CAAC;QACpB,8CAA8C;QAC9C,WAAW,EAAE,MAAM,CAAC;QACpB,yDAAyD;QACzD,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,uDAAuD;QACvD,WAAW,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;CACL"}
File without changes
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var cache_exports = {};
20
+ __export(cache_exports, {
21
+ CACHE_TYPES: () => import_schemas.CACHE_TYPES,
22
+ CacheConfigSchema: () => import_schemas.CacheConfigSchema,
23
+ InMemoryCacheSchema: () => import_schemas.InMemoryCacheSchema,
24
+ MemoryCacheStore: () => import_memory_cache_store.MemoryCacheStore,
25
+ RedisCacheSchema: () => import_schemas.RedisCacheSchema,
26
+ inMemoryCacheFactory: () => import_factories.inMemoryCacheFactory,
27
+ redisCacheFactory: () => import_factories.redisCacheFactory
28
+ });
29
+ module.exports = __toCommonJS(cache_exports);
30
+ var import_factories = require("./factories/index.js");
31
+ var import_schemas = require("./schemas.js");
32
+ var import_memory_cache_store = require("./memory-cache-store.js");
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ CACHE_TYPES,
36
+ CacheConfigSchema,
37
+ InMemoryCacheSchema,
38
+ MemoryCacheStore,
39
+ RedisCacheSchema,
40
+ inMemoryCacheFactory,
41
+ redisCacheFactory
42
+ });
@@ -0,0 +1,7 @@
1
+ export { CacheFactory } from './factory.cjs';
2
+ export { Cache } from '@dexto/core';
3
+ export { inMemoryCacheFactory } from './factories/memory.cjs';
4
+ export { redisCacheFactory } from './factories/redis.cjs';
5
+ export { CACHE_TYPES, CacheConfig, CacheConfigSchema, CacheType, InMemoryCacheConfig, InMemoryCacheSchema, RedisCacheConfig, RedisCacheSchema } from './schemas.cjs';
6
+ export { MemoryCacheStore } from './memory-cache-store.cjs';
7
+ import 'zod';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Cache Module
3
+ *
4
+ * This module provides a flexible caching system with support for
5
+ * multiple backends through a factory pattern.
6
+ *
7
+ * ## Built-in Factories
8
+ * - `in-memory`: Store data in RAM (for testing/development)
9
+ * - `redis`: Store data in Redis server
10
+ *
11
+ * ## Custom Factories
12
+ * Product layers (CLI/server/platform) decide which factories are available by including them
13
+ * in images (`DextoImage.storage.cache`).
14
+ *
15
+ * ## Usage
16
+ * Cache backends are typically constructed by the product-layer resolver (`@dexto/agent-config`)
17
+ * via image-provided factory maps. For direct usage, call a factory's `create()` after validating
18
+ * config with its `configSchema`.
19
+ */
20
+ export type { CacheFactory } from './factory.js';
21
+ export type { Cache } from './types.js';
22
+ export { inMemoryCacheFactory, redisCacheFactory } from './factories/index.js';
23
+ export { CACHE_TYPES, CacheConfigSchema, InMemoryCacheSchema, RedisCacheSchema, type CacheType, type CacheConfig, type InMemoryCacheConfig, type RedisCacheConfig, } from './schemas.js';
24
+ export { MemoryCacheStore } from './memory-cache-store.js';
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG/E,OAAO,EACH,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACxB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { inMemoryCacheFactory, redisCacheFactory } from "./factories/index.js";
2
+ import {
3
+ CACHE_TYPES,
4
+ CacheConfigSchema,
5
+ InMemoryCacheSchema,
6
+ RedisCacheSchema
7
+ } from "./schemas.js";
8
+ import { MemoryCacheStore } from "./memory-cache-store.js";
9
+ export {
10
+ CACHE_TYPES,
11
+ CacheConfigSchema,
12
+ InMemoryCacheSchema,
13
+ MemoryCacheStore,
14
+ RedisCacheSchema,
15
+ inMemoryCacheFactory,
16
+ redisCacheFactory
17
+ };
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var memory_cache_store_exports = {};
20
+ __export(memory_cache_store_exports, {
21
+ MemoryCacheStore: () => MemoryCacheStore
22
+ });
23
+ module.exports = __toCommonJS(memory_cache_store_exports);
24
+ var import_core = require("@dexto/core");
25
+ class MemoryCacheStore {
26
+ data = /* @__PURE__ */ new Map();
27
+ ttls = /* @__PURE__ */ new Map();
28
+ connected = false;
29
+ async connect() {
30
+ if (this.connected) return;
31
+ this.connected = true;
32
+ }
33
+ async disconnect() {
34
+ this.connected = false;
35
+ this.data.clear();
36
+ this.ttls.clear();
37
+ }
38
+ isConnected() {
39
+ return this.connected;
40
+ }
41
+ getStoreType() {
42
+ return "in-memory";
43
+ }
44
+ async get(key) {
45
+ this.checkConnection();
46
+ try {
47
+ this.checkTTL(key);
48
+ return this.data.get(key);
49
+ } catch (error) {
50
+ throw import_core.StorageError.readFailed(
51
+ "get",
52
+ error instanceof Error ? error.message : String(error),
53
+ { key }
54
+ );
55
+ }
56
+ }
57
+ async set(key, value, ttlSeconds) {
58
+ this.checkConnection();
59
+ try {
60
+ this.data.set(key, value);
61
+ if (ttlSeconds) {
62
+ this.ttls.set(key, Date.now() + ttlSeconds * 1e3);
63
+ } else {
64
+ this.ttls.delete(key);
65
+ }
66
+ } catch (error) {
67
+ throw import_core.StorageError.writeFailed(
68
+ "set",
69
+ error instanceof Error ? error.message : String(error),
70
+ { key }
71
+ );
72
+ }
73
+ }
74
+ async delete(key) {
75
+ this.checkConnection();
76
+ this.data.delete(key);
77
+ this.ttls.delete(key);
78
+ }
79
+ // Helper methods
80
+ checkConnection() {
81
+ if (!this.connected) {
82
+ throw import_core.StorageError.notConnected("MemoryCacheStore");
83
+ }
84
+ }
85
+ checkTTL(key) {
86
+ const expiry = this.ttls.get(key);
87
+ if (expiry && Date.now() > expiry) {
88
+ this.data.delete(key);
89
+ this.ttls.delete(key);
90
+ }
91
+ }
92
+ // Development helpers
93
+ async clear() {
94
+ this.data.clear();
95
+ this.ttls.clear();
96
+ }
97
+ async dump() {
98
+ return {
99
+ data: Object.fromEntries(this.data.entries())
100
+ };
101
+ }
102
+ }
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ MemoryCacheStore
106
+ });
@@ -0,0 +1,27 @@
1
+ import { Cache } from '@dexto/core';
2
+
3
+ /**
4
+ * In-memory cache store for development and testing.
5
+ * Supports TTL for automatic cleanup of temporary data.
6
+ * Data is lost when the process restarts.
7
+ */
8
+ declare class MemoryCacheStore implements Cache {
9
+ private data;
10
+ private ttls;
11
+ private connected;
12
+ connect(): Promise<void>;
13
+ disconnect(): Promise<void>;
14
+ isConnected(): boolean;
15
+ getStoreType(): string;
16
+ get<T>(key: string): Promise<T | undefined>;
17
+ set<T>(key: string, value: T, ttlSeconds?: number): Promise<void>;
18
+ delete(key: string): Promise<void>;
19
+ private checkConnection;
20
+ private checkTTL;
21
+ clear(): Promise<void>;
22
+ dump(): Promise<{
23
+ data: Record<string, unknown>;
24
+ }>;
25
+ }
26
+
27
+ export { MemoryCacheStore };
@@ -0,0 +1,25 @@
1
+ import type { Cache } from './types.js';
2
+ /**
3
+ * In-memory cache store for development and testing.
4
+ * Supports TTL for automatic cleanup of temporary data.
5
+ * Data is lost when the process restarts.
6
+ */
7
+ export declare class MemoryCacheStore implements Cache {
8
+ private data;
9
+ private ttls;
10
+ private connected;
11
+ connect(): Promise<void>;
12
+ disconnect(): Promise<void>;
13
+ isConnected(): boolean;
14
+ getStoreType(): string;
15
+ get<T>(key: string): Promise<T | undefined>;
16
+ set<T>(key: string, value: T, ttlSeconds?: number): Promise<void>;
17
+ delete(key: string): Promise<void>;
18
+ private checkConnection;
19
+ private checkTTL;
20
+ clear(): Promise<void>;
21
+ dump(): Promise<{
22
+ data: Record<string, unknown>;
23
+ }>;
24
+ }
25
+ //# sourceMappingURL=memory-cache-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-cache-store.d.ts","sourceRoot":"","sources":["../../src/cache/memory-cache-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,KAAK;IAC1C,OAAO,CAAC,IAAI,CAA8B;IAC1C,OAAO,CAAC,IAAI,CAA6B;IACzC,OAAO,CAAC,SAAS,CAAS;IAEpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAKxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC,WAAW,IAAI,OAAO;IAItB,YAAY,IAAI,MAAM;IAIhB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAc3C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBjE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOxC,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,QAAQ;IASV,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,IAAI,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;CAK3D"}