@dexto/storage 1.7.2 → 1.8.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 (87) hide show
  1. package/README.md +51 -38
  2. package/dist/blob/index.cjs +2 -7
  3. package/dist/blob/index.d.ts +3 -14
  4. package/dist/blob/index.d.ts.map +1 -1
  5. package/dist/blob/index.js +1 -4
  6. package/dist/cache/index.cjs +3 -5
  7. package/dist/cache/index.d.ts +4 -14
  8. package/dist/cache/index.d.ts.map +1 -1
  9. package/dist/cache/index.js +2 -3
  10. package/dist/cache/schemas.cjs +5 -5
  11. package/dist/cache/schemas.js +1 -1
  12. package/dist/database/index.cjs +8 -9
  13. package/dist/database/index.d.ts +5 -15
  14. package/dist/database/index.d.ts.map +1 -1
  15. package/dist/database/index.js +5 -9
  16. package/dist/database/memory-database-store.cjs +16 -0
  17. package/dist/database/memory-database-store.d.ts +4 -0
  18. package/dist/database/memory-database-store.d.ts.map +1 -1
  19. package/dist/database/memory-database-store.js +16 -0
  20. package/dist/database/postgres-store.cjs +25 -0
  21. package/dist/database/postgres-store.d.ts +4 -0
  22. package/dist/database/postgres-store.d.ts.map +1 -1
  23. package/dist/database/postgres-store.js +25 -0
  24. package/dist/database/schemas.cjs +6 -6
  25. package/dist/database/schemas.js +1 -1
  26. package/dist/database/sqlite-store.cjs +18 -0
  27. package/dist/database/sqlite-store.d.ts +4 -0
  28. package/dist/database/sqlite-store.d.ts.map +1 -1
  29. package/dist/database/sqlite-store.js +18 -0
  30. package/dist/index.cjs +12 -19
  31. package/dist/index.d.cts +17 -225
  32. package/dist/index.d.ts +4 -10
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +11 -15
  35. package/package.json +3 -3
  36. package/dist/blob/factories/index.cjs +0 -31
  37. package/dist/blob/factories/index.d.ts +0 -6
  38. package/dist/blob/factories/index.d.ts.map +0 -1
  39. package/dist/blob/factories/index.js +0 -6
  40. package/dist/blob/factories/local.cjs +0 -38
  41. package/dist/blob/factories/local.d.ts +0 -17
  42. package/dist/blob/factories/local.d.ts.map +0 -1
  43. package/dist/blob/factories/local.js +0 -14
  44. package/dist/blob/factories/memory.cjs +0 -44
  45. package/dist/blob/factories/memory.d.ts +0 -17
  46. package/dist/blob/factories/memory.d.ts.map +0 -1
  47. package/dist/blob/factories/memory.js +0 -20
  48. package/dist/blob/factory.cjs +0 -16
  49. package/dist/blob/factory.d.ts +0 -35
  50. package/dist/blob/factory.d.ts.map +0 -1
  51. package/dist/blob/factory.js +0 -0
  52. package/dist/cache/factories/index.cjs +0 -31
  53. package/dist/cache/factories/index.d.ts +0 -6
  54. package/dist/cache/factories/index.d.ts.map +0 -1
  55. package/dist/cache/factories/index.js +0 -6
  56. package/dist/cache/factories/memory.cjs +0 -39
  57. package/dist/cache/factories/memory.d.ts +0 -17
  58. package/dist/cache/factories/memory.d.ts.map +0 -1
  59. package/dist/cache/factories/memory.js +0 -15
  60. package/dist/cache/factories/redis.cjs +0 -65
  61. package/dist/cache/factories/redis.d.ts +0 -20
  62. package/dist/cache/factories/redis.d.ts.map +0 -1
  63. package/dist/cache/factories/redis.js +0 -31
  64. package/dist/cache/factory.cjs +0 -16
  65. package/dist/cache/factory.d.ts +0 -41
  66. package/dist/cache/factory.d.ts.map +0 -1
  67. package/dist/cache/factory.js +0 -0
  68. package/dist/database/factories/index.cjs +0 -34
  69. package/dist/database/factories/index.d.ts +0 -7
  70. package/dist/database/factories/index.d.ts.map +0 -1
  71. package/dist/database/factories/index.js +0 -8
  72. package/dist/database/factories/memory.cjs +0 -39
  73. package/dist/database/factories/memory.d.ts +0 -16
  74. package/dist/database/factories/memory.d.ts.map +0 -1
  75. package/dist/database/factories/memory.js +0 -15
  76. package/dist/database/factories/postgres.cjs +0 -61
  77. package/dist/database/factories/postgres.d.ts +0 -19
  78. package/dist/database/factories/postgres.d.ts.map +0 -1
  79. package/dist/database/factories/postgres.js +0 -27
  80. package/dist/database/factories/sqlite.cjs +0 -65
  81. package/dist/database/factories/sqlite.d.ts +0 -20
  82. package/dist/database/factories/sqlite.d.ts.map +0 -1
  83. package/dist/database/factories/sqlite.js +0 -31
  84. package/dist/database/factory.cjs +0 -16
  85. package/dist/database/factory.d.ts +0 -41
  86. package/dist/database/factory.d.ts.map +0 -1
  87. package/dist/database/factory.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"sqlite-store.d.ts","sourceRoot":"","sources":["../../src/database/sqlite-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAKzD;;;GAGG;AACH,qBAAa,WAAY,YAAW,QAAQ;IACxC,OAAO,CAAC,EAAE,CAAoB;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM;IAOxD,OAAO,CAAC,gBAAgB;IA8ClB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2ExB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC,WAAW,IAAI,OAAO;IAItB,YAAY,IAAI,MAAM;IAKhB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAgB3C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB5C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAelC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA0BvC,MAAM,CAAC,CAAC,EAAE,GAAG,EAA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C,IAAI,CAAC;IAkB5C,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IAwB/E,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAelC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA0BvC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB9C,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAqB1E,OAAO,CAAC,eAAe;IAOjB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAKvB,QAAQ,IAAI,OAAO,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;KAClB,CAAC;CAqBL"}
@@ -144,6 +144,24 @@ class SQLiteStore {
144
144
  );
145
145
  }
146
146
  }
147
+ async setIfAbsent(key, value) {
148
+ this.checkConnection();
149
+ try {
150
+ const serialized = JSON.stringify(value);
151
+ const result = this.db.prepare("INSERT OR IGNORE INTO kv_store (key, value, updated_at) VALUES (?, ?, ?)").run(key, serialized, Date.now());
152
+ const row = this.db.prepare("SELECT value FROM kv_store WHERE key = ?").get(key);
153
+ return {
154
+ value: row ? JSON.parse(row.value) : value,
155
+ inserted: result.changes > 0
156
+ };
157
+ } catch (error) {
158
+ throw StorageError.writeFailed(
159
+ "setIfAbsent",
160
+ error instanceof Error ? error.message : String(error),
161
+ { key }
162
+ );
163
+ }
164
+ }
147
165
  async delete(key) {
148
166
  this.checkConnection();
149
167
  try {
package/dist/index.cjs CHANGED
@@ -25,33 +25,28 @@ __export(index_exports, {
25
25
  DATABASE_TYPES: () => import_schemas.DATABASE_TYPES,
26
26
  DatabaseConfigSchema: () => import_schemas.DatabaseConfigSchema,
27
27
  InMemoryBlobStoreSchema: () => import_schemas.InMemoryBlobStoreSchema,
28
+ InMemoryCacheSchema: () => import_schemas.InMemoryCacheSchema,
29
+ InMemoryDatabaseSchema: () => import_schemas.InMemoryDatabaseSchema,
28
30
  LocalBlobStore: () => import_local_blob_store.LocalBlobStore,
29
31
  LocalBlobStoreSchema: () => import_schemas.LocalBlobStoreSchema,
30
32
  MemoryBlobStore: () => import_memory_blob_store.MemoryBlobStore,
31
33
  MemoryCacheStore: () => import_memory_cache_store.MemoryCacheStore,
32
34
  MemoryDatabaseStore: () => import_memory_database_store.MemoryDatabaseStore,
35
+ PostgresDatabaseSchema: () => import_schemas.PostgresDatabaseSchema,
33
36
  PostgresStore: () => import_postgres_store.PostgresStore,
37
+ RedisCacheSchema: () => import_schemas.RedisCacheSchema,
34
38
  RedisStore: () => import_redis_store.RedisStore,
35
39
  SQLiteStore: () => import_sqlite_store.SQLiteStore,
36
- StorageSchema: () => import_schemas.StorageSchema,
37
- inMemoryBlobStoreFactory: () => import_factories3.inMemoryBlobStoreFactory,
38
- inMemoryCacheFactory: () => import_factories.inMemoryCacheFactory,
39
- inMemoryDatabaseFactory: () => import_factories2.inMemoryDatabaseFactory,
40
- localBlobStoreFactory: () => import_factories3.localBlobStoreFactory,
41
- postgresDatabaseFactory: () => import_factories2.postgresDatabaseFactory,
42
- redisCacheFactory: () => import_factories.redisCacheFactory,
43
- sqliteDatabaseFactory: () => import_factories2.sqliteDatabaseFactory
40
+ SqliteDatabaseSchema: () => import_schemas.SqliteDatabaseSchema,
41
+ StorageSchema: () => import_schemas.StorageSchema
44
42
  });
45
43
  module.exports = __toCommonJS(index_exports);
46
44
  var import_schemas = require("./schemas.js");
47
- var import_factories = require("./cache/factories/index.js");
48
45
  var import_memory_cache_store = require("./cache/memory-cache-store.js");
49
46
  var import_redis_store = require("./cache/redis-store.js");
50
- var import_factories2 = require("./database/factories/index.js");
51
47
  var import_memory_database_store = require("./database/memory-database-store.js");
52
48
  var import_sqlite_store = require("./database/sqlite-store.js");
53
49
  var import_postgres_store = require("./database/postgres-store.js");
54
- var import_factories3 = require("./blob/factories/index.js");
55
50
  var import_local_blob_store = require("./blob/local-blob-store.js");
56
51
  var import_memory_blob_store = require("./blob/memory-blob-store.js");
57
52
  // Annotate the CommonJS export names for ESM import in node:
@@ -63,20 +58,18 @@ var import_memory_blob_store = require("./blob/memory-blob-store.js");
63
58
  DATABASE_TYPES,
64
59
  DatabaseConfigSchema,
65
60
  InMemoryBlobStoreSchema,
61
+ InMemoryCacheSchema,
62
+ InMemoryDatabaseSchema,
66
63
  LocalBlobStore,
67
64
  LocalBlobStoreSchema,
68
65
  MemoryBlobStore,
69
66
  MemoryCacheStore,
70
67
  MemoryDatabaseStore,
68
+ PostgresDatabaseSchema,
71
69
  PostgresStore,
70
+ RedisCacheSchema,
72
71
  RedisStore,
73
72
  SQLiteStore,
74
- StorageSchema,
75
- inMemoryBlobStoreFactory,
76
- inMemoryCacheFactory,
77
- inMemoryDatabaseFactory,
78
- localBlobStoreFactory,
79
- postgresDatabaseFactory,
80
- redisCacheFactory,
81
- sqliteDatabaseFactory
73
+ SqliteDatabaseSchema,
74
+ StorageSchema
82
75
  });
package/dist/index.d.cts CHANGED
@@ -1,79 +1,8 @@
1
- import { InMemoryCacheConfig, RedisCacheConfig, InMemoryDatabaseConfig, SqliteDatabaseConfig, PostgresDatabaseConfig, LocalBlobStoreConfig, InMemoryBlobStoreConfig, InMemoryBlobStoreConfigInput } from './schemas.cjs';
2
- export { BLOB_STORE_TYPES, BlobStoreConfig, BlobStoreConfigSchema, BlobStoreType, CACHE_TYPES, CacheConfig, CacheConfigSchema, CacheType, DATABASE_TYPES, DatabaseConfig, DatabaseConfigSchema, DatabaseType, InMemoryBlobStoreSchema, LocalBlobStoreConfigInput, LocalBlobStoreSchema, StorageConfig, StorageSchema, ValidatedStorageConfig } from './schemas.cjs';
3
- import { Logger, Cache, Database, BlobStore, BlobInput, BlobMetadata, BlobReference, BlobData, BlobStats } from '@dexto/core';
4
- import { z } from 'zod';
1
+ import { RedisCacheConfig, SqliteDatabaseConfig, PostgresDatabaseConfig, LocalBlobStoreConfig, InMemoryBlobStoreConfigInput } from './schemas.cjs';
2
+ export { BLOB_STORE_TYPES, BlobStoreConfig, BlobStoreConfigSchema, BlobStoreType, CACHE_TYPES, CacheConfig, CacheConfigSchema, CacheType, DATABASE_TYPES, DatabaseConfig, DatabaseConfigSchema, DatabaseType, InMemoryBlobStoreConfig, InMemoryBlobStoreSchema, InMemoryCacheConfig, InMemoryCacheSchema, InMemoryDatabaseConfig, InMemoryDatabaseSchema, LocalBlobStoreConfigInput, LocalBlobStoreSchema, PostgresDatabaseSchema, RedisCacheSchema, SqliteDatabaseSchema, StorageConfig, StorageSchema, ValidatedStorageConfig } from './schemas.cjs';
3
+ import { Cache, Logger, Database, BlobStore, BlobInput, BlobMetadata, BlobReference, BlobData, BlobStats } from '@dexto/core';
5
4
  import { PoolClient } from 'pg';
6
-
7
- /**
8
- * Factory interface for creating cache instances.
9
- *
10
- * Factories are plain exports (no global registries). Images decide which factories are
11
- * available by including them in `image.storage.cache`.
12
- */
13
- interface CacheFactory<TConfig = unknown> {
14
- /**
15
- * Zod schema for validating factory-specific configuration.
16
- * The schema must output the `TConfig` type.
17
- */
18
- configSchema: z.ZodType<TConfig, unknown>;
19
- /**
20
- * Factory function to create a Cache instance.
21
- *
22
- * Cache factories may return a Promise to support lazy loading of optional
23
- * dependencies (e.g., `ioredis`).
24
- *
25
- * @param config - Validated configuration specific to this backend
26
- * @param logger - Logger instance for the cache
27
- * @returns A Cache implementation (or Promise for async backends)
28
- */
29
- create(config: TConfig, logger: Logger): Cache | Promise<Cache>;
30
- /**
31
- * Optional metadata for documentation, UIs, and discovery.
32
- */
33
- metadata?: {
34
- /** Human-readable name (e.g., "Redis", "Memcached") */
35
- displayName: string;
36
- /** Brief description of this cache backend */
37
- description: string;
38
- /** Whether this backend requires network connectivity */
39
- requiresNetwork?: boolean;
40
- /** Whether this backend supports TTL (time-to-live) */
41
- supportsTTL?: boolean;
42
- };
43
- }
44
-
45
- /**
46
- * Factory for in-memory cache storage.
47
- *
48
- * This factory stores data in RAM and is ideal for development,
49
- * testing, and ephemeral use cases where persistence is not required.
50
- *
51
- * Features:
52
- * - Zero external dependencies
53
- * - Fast in-memory operations
54
- * - TTL support for automatic expiration
55
- * - No network required
56
- * - Data is lost on restart
57
- */
58
- declare const inMemoryCacheFactory: CacheFactory<InMemoryCacheConfig>;
59
-
60
- /**
61
- * Factory for Redis cache storage.
62
- *
63
- * This factory stores data in a Redis server using the ioredis package.
64
- * It's ideal for production deployments requiring scalability, persistence,
65
- * and multi-machine access.
66
- *
67
- * Features:
68
- * - Native TTL support
69
- * - Connection pooling
70
- * - Pub/sub capabilities (via additional methods)
71
- * - Suitable for distributed deployments
72
- *
73
- * Note: ioredis is an optional dependency. Install it with:
74
- * npm install ioredis
75
- */
76
- declare const redisCacheFactory: CacheFactory<RedisCacheConfig>;
5
+ import 'zod';
77
6
 
78
7
  /**
79
8
  * In-memory cache store for development and testing.
@@ -128,93 +57,6 @@ declare class RedisStore implements Cache {
128
57
  info(): Promise<string>;
129
58
  }
130
59
 
131
- /**
132
- * Factory interface for creating database instances.
133
- *
134
- * Factories are plain exports (no global registries). Images decide which factories are
135
- * available by including them in `image.storage.database`.
136
- */
137
- interface DatabaseFactory<TConfig = unknown> {
138
- /**
139
- * Zod schema for validating factory-specific configuration.
140
- * The schema must output the `TConfig` type.
141
- */
142
- configSchema: z.ZodType<TConfig, unknown>;
143
- /**
144
- * Factory function to create a Database instance.
145
- *
146
- * Database factories may return a Promise to support lazy loading of optional
147
- * dependencies (e.g., `better-sqlite3`, `pg`).
148
- *
149
- * @param config - Validated configuration specific to this backend
150
- * @param logger - Logger instance for the database
151
- * @returns A Database implementation (or Promise for async backends)
152
- */
153
- create(config: TConfig, logger: Logger): Database | Promise<Database>;
154
- /**
155
- * Optional metadata for documentation, UIs, and discovery.
156
- */
157
- metadata?: {
158
- /** Human-readable name (e.g., "SQLite", "PostgreSQL") */
159
- displayName: string;
160
- /** Brief description of this storage backend */
161
- description: string;
162
- /** Whether this backend requires network connectivity */
163
- requiresNetwork?: boolean;
164
- /** Whether this backend supports list operations (append/getRange) */
165
- supportsListOperations?: boolean;
166
- };
167
- }
168
-
169
- /**
170
- * Factory for in-memory database storage.
171
- *
172
- * This factory stores data in RAM and is ideal for development,
173
- * testing, and ephemeral use cases where persistence is not required.
174
- *
175
- * Features:
176
- * - Zero external dependencies
177
- * - Fast in-memory operations
178
- * - No network required
179
- * - Data is lost on restart
180
- */
181
- declare const inMemoryDatabaseFactory: DatabaseFactory<InMemoryDatabaseConfig>;
182
-
183
- /**
184
- * Factory for SQLite database storage.
185
- *
186
- * This factory stores data in a local SQLite database file using better-sqlite3.
187
- * It's ideal for single-machine deployments and development scenarios where
188
- * persistence is required without the overhead of a database server.
189
- *
190
- * Features:
191
- * - Uses better-sqlite3 for synchronous, fast operations
192
- * - WAL mode enabled for better concurrency
193
- * - No external server required
194
- * - Persistent storage survives restarts
195
- *
196
- * Note: better-sqlite3 is an optional dependency. Install it with:
197
- * npm install better-sqlite3
198
- */
199
- declare const sqliteDatabaseFactory: DatabaseFactory<SqliteDatabaseConfig>;
200
-
201
- /**
202
- * Factory for PostgreSQL database storage.
203
- *
204
- * This factory stores data in a PostgreSQL database server using the pg package.
205
- * It's ideal for production deployments requiring scalability and multi-machine access.
206
- *
207
- * Features:
208
- * - Connection pooling for efficient resource usage
209
- * - JSONB storage for flexible data types
210
- * - Transaction support
211
- * - Suitable for distributed deployments
212
- *
213
- * Note: pg is an optional dependency. Install it with:
214
- * npm install pg
215
- */
216
- declare const postgresDatabaseFactory: DatabaseFactory<PostgresDatabaseConfig>;
217
-
218
60
  /**
219
61
  * In-memory database store for development and testing.
220
62
  * Supports list operations for message history and enumeration for settings.
@@ -230,6 +72,10 @@ declare class MemoryDatabaseStore implements Database {
230
72
  getStoreType(): string;
231
73
  get<T>(key: string): Promise<T | undefined>;
232
74
  set<T>(key: string, value: T): Promise<void>;
75
+ setIfAbsent<T>(key: string, value: T): Promise<{
76
+ value: T;
77
+ inserted: boolean;
78
+ }>;
233
79
  delete(key: string): Promise<void>;
234
80
  list(prefix: string): Promise<string[]>;
235
81
  append<T>(key: string, item: T): Promise<void>;
@@ -259,6 +105,10 @@ declare class SQLiteStore implements Database {
259
105
  getStoreType(): string;
260
106
  get<T>(key: string): Promise<T | undefined>;
261
107
  set<T>(key: string, value: T): Promise<void>;
108
+ setIfAbsent<T>(key: string, value: T): Promise<{
109
+ value: T;
110
+ inserted: boolean;
111
+ }>;
262
112
  delete(key: string): Promise<void>;
263
113
  list(prefix: string): Promise<string[]>;
264
114
  append<T>(key: string, item: T): Promise<void>;
@@ -293,6 +143,10 @@ declare class PostgresStore implements Database {
293
143
  getStoreType(): string;
294
144
  get<T>(key: string): Promise<T | undefined>;
295
145
  set<T>(key: string, value: T): Promise<void>;
146
+ setIfAbsent<T>(key: string, value: T): Promise<{
147
+ value: T;
148
+ inserted: boolean;
149
+ }>;
296
150
  delete(key: string): Promise<void>;
297
151
  list(prefix: string): Promise<string[]>;
298
152
  append<T>(key: string, item: T): Promise<void>;
@@ -323,68 +177,6 @@ declare class PostgresStore implements Database {
323
177
  vacuum(): Promise<void>;
324
178
  }
325
179
 
326
- /**
327
- * Factory interface for creating blob store instances.
328
- *
329
- * Factories are plain exports (no global registries). Images decide which factories are
330
- * available by including them in `image.storage.blob`.
331
- */
332
- interface BlobStoreFactory<TConfig = unknown> {
333
- /**
334
- * Zod schema for validating factory-specific configuration.
335
- * The schema must output the `TConfig` type.
336
- */
337
- configSchema: z.ZodType<TConfig, unknown>;
338
- /**
339
- * Factory function to create a BlobStore instance.
340
- * @param config - Validated configuration specific to this backend
341
- * @param logger - Logger instance for the blob store
342
- * @returns A BlobStore implementation
343
- */
344
- create(config: TConfig, logger: Logger): BlobStore | Promise<BlobStore>;
345
- /**
346
- * Optional metadata for documentation, UIs, and discovery.
347
- */
348
- metadata?: {
349
- /** Human-readable name (e.g., "Local Filesystem", "Amazon S3") */
350
- displayName: string;
351
- /** Brief description of this storage backend */
352
- description: string;
353
- /** Whether this backend requires network connectivity */
354
- requiresNetwork?: boolean;
355
- };
356
- }
357
-
358
- /**
359
- * Factory for local filesystem blob storage.
360
- *
361
- * This factory stores blobs on the local filesystem with content-based
362
- * deduplication and metadata tracking. It's ideal for development and
363
- * single-machine deployments.
364
- *
365
- * Features:
366
- * - Zero external dependencies (uses Node.js fs module)
367
- * - Content-based deduplication (same hash = same blob)
368
- * - Automatic cleanup of old blobs
369
- * - No network required
370
- */
371
- declare const localBlobStoreFactory: BlobStoreFactory<LocalBlobStoreConfig>;
372
-
373
- /**
374
- * Factory for in-memory blob storage.
375
- *
376
- * This factory stores blobs in RAM, making it ideal for testing and
377
- * development. All data is lost when the process exits.
378
- *
379
- * Features:
380
- * - Zero dependencies
381
- * - Extremely fast (no I/O)
382
- * - Configurable size limits
383
- * - No network required
384
- * - Perfect for unit tests
385
- */
386
- declare const inMemoryBlobStoreFactory: BlobStoreFactory<InMemoryBlobStoreConfig>;
387
-
388
180
  /**
389
181
  * Local filesystem blob store implementation.
390
182
  *
@@ -500,4 +292,4 @@ declare class MemoryBlobStore implements BlobStore {
500
292
  private isTextBuffer;
501
293
  }
502
294
 
503
- export { type BlobStoreFactory, type CacheFactory, type DatabaseFactory, InMemoryBlobStoreConfig, InMemoryBlobStoreConfigInput, InMemoryCacheConfig, InMemoryDatabaseConfig, LocalBlobStore, LocalBlobStoreConfig, MemoryBlobStore, MemoryCacheStore, MemoryDatabaseStore, PostgresDatabaseConfig, PostgresStore, RedisCacheConfig, RedisStore, SQLiteStore, SqliteDatabaseConfig, inMemoryBlobStoreFactory, inMemoryCacheFactory, inMemoryDatabaseFactory, localBlobStoreFactory, postgresDatabaseFactory, redisCacheFactory, sqliteDatabaseFactory };
295
+ export { InMemoryBlobStoreConfigInput, LocalBlobStore, LocalBlobStoreConfig, MemoryBlobStore, MemoryCacheStore, MemoryDatabaseStore, PostgresDatabaseConfig, PostgresStore, RedisCacheConfig, RedisStore, SQLiteStore, SqliteDatabaseConfig };
package/dist/index.d.ts CHANGED
@@ -1,25 +1,19 @@
1
1
  /**
2
2
  * @dexto/storage
3
3
  *
4
- * Concrete storage backends + config schemas + factory objects.
4
+ * Concrete storage backends + config schemas.
5
5
  *
6
- * Core keeps only the storage *interfaces* (`BlobStore`, `Database`, `Cache`) and `StorageManager`.
7
- * Product layers (CLI/server/platform) choose which factories to include via images.
6
+ * Core keeps typed domain store contracts. This package provides backend implementations that
7
+ * image/config resolution can compose into `DextoStores`.
8
8
  */
9
9
  export type { StorageConfig, ValidatedStorageConfig } from './schemas.js';
10
- export { StorageSchema, CACHE_TYPES, DATABASE_TYPES, BLOB_STORE_TYPES, CacheConfigSchema, DatabaseConfigSchema, BlobStoreConfigSchema, InMemoryBlobStoreSchema, LocalBlobStoreSchema, } from './schemas.js';
10
+ export { StorageSchema, CACHE_TYPES, DATABASE_TYPES, BLOB_STORE_TYPES, CacheConfigSchema, InMemoryCacheSchema, RedisCacheSchema, DatabaseConfigSchema, InMemoryDatabaseSchema, SqliteDatabaseSchema, PostgresDatabaseSchema, BlobStoreConfigSchema, InMemoryBlobStoreSchema, LocalBlobStoreSchema, } from './schemas.js';
11
11
  export type { CacheType, DatabaseType, BlobStoreType, CacheConfig, InMemoryCacheConfig, RedisCacheConfig, DatabaseConfig, InMemoryDatabaseConfig, SqliteDatabaseConfig, PostgresDatabaseConfig, BlobStoreConfig, InMemoryBlobStoreConfigInput, InMemoryBlobStoreConfig, LocalBlobStoreConfigInput, LocalBlobStoreConfig, } from './schemas.js';
12
- export type { CacheFactory } from './cache/index.js';
13
- export { inMemoryCacheFactory, redisCacheFactory } from './cache/factories/index.js';
14
12
  export { MemoryCacheStore } from './cache/memory-cache-store.js';
15
13
  export { RedisStore } from './cache/redis-store.js';
16
- export type { DatabaseFactory } from './database/index.js';
17
- export { inMemoryDatabaseFactory, sqliteDatabaseFactory, postgresDatabaseFactory, } from './database/factories/index.js';
18
14
  export { MemoryDatabaseStore } from './database/memory-database-store.js';
19
15
  export { SQLiteStore } from './database/sqlite-store.js';
20
16
  export { PostgresStore } from './database/postgres-store.js';
21
- export type { BlobStoreFactory } from './blob/index.js';
22
- export { localBlobStoreFactory, inMemoryBlobStoreFactory } from './blob/factories/index.js';
23
17
  export { LocalBlobStore } from './blob/local-blob-store.js';
24
18
  export { MemoryBlobStore } from './blob/memory-blob-store.js';
25
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EACH,aAAa,EACb,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACvB,MAAM,cAAc,CAAC;AACtB,YAAY,EACR,SAAS,EACT,YAAY,EACZ,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,EACf,4BAA4B,EAC5B,uBAAuB,EACvB,yBAAyB,EACzB,oBAAoB,GACvB,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,UA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EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC"}
package/dist/index.js CHANGED
@@ -4,23 +4,21 @@ import {
4
4
  DATABASE_TYPES,
5
5
  BLOB_STORE_TYPES,
6
6
  CacheConfigSchema,
7
+ InMemoryCacheSchema,
8
+ RedisCacheSchema,
7
9
  DatabaseConfigSchema,
10
+ InMemoryDatabaseSchema,
11
+ SqliteDatabaseSchema,
12
+ PostgresDatabaseSchema,
8
13
  BlobStoreConfigSchema,
9
14
  InMemoryBlobStoreSchema,
10
15
  LocalBlobStoreSchema
11
16
  } from "./schemas.js";
12
- import { inMemoryCacheFactory, redisCacheFactory } from "./cache/factories/index.js";
13
17
  import { MemoryCacheStore } from "./cache/memory-cache-store.js";
14
18
  import { RedisStore } from "./cache/redis-store.js";
15
- import {
16
- inMemoryDatabaseFactory,
17
- sqliteDatabaseFactory,
18
- postgresDatabaseFactory
19
- } from "./database/factories/index.js";
20
19
  import { MemoryDatabaseStore } from "./database/memory-database-store.js";
21
20
  import { SQLiteStore } from "./database/sqlite-store.js";
22
21
  import { PostgresStore } from "./database/postgres-store.js";
23
- import { localBlobStoreFactory, inMemoryBlobStoreFactory } from "./blob/factories/index.js";
24
22
  import { LocalBlobStore } from "./blob/local-blob-store.js";
25
23
  import { MemoryBlobStore } from "./blob/memory-blob-store.js";
26
24
  export {
@@ -31,20 +29,18 @@ export {
31
29
  DATABASE_TYPES,
32
30
  DatabaseConfigSchema,
33
31
  InMemoryBlobStoreSchema,
32
+ InMemoryCacheSchema,
33
+ InMemoryDatabaseSchema,
34
34
  LocalBlobStore,
35
35
  LocalBlobStoreSchema,
36
36
  MemoryBlobStore,
37
37
  MemoryCacheStore,
38
38
  MemoryDatabaseStore,
39
+ PostgresDatabaseSchema,
39
40
  PostgresStore,
41
+ RedisCacheSchema,
40
42
  RedisStore,
41
43
  SQLiteStore,
42
- StorageSchema,
43
- inMemoryBlobStoreFactory,
44
- inMemoryCacheFactory,
45
- inMemoryDatabaseFactory,
46
- localBlobStoreFactory,
47
- postgresDatabaseFactory,
48
- redisCacheFactory,
49
- sqliteDatabaseFactory
44
+ SqliteDatabaseSchema,
45
+ StorageSchema
50
46
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dexto/storage",
3
- "version": "1.7.2",
4
- "description": "Storage backends and factories for Dexto agents",
3
+ "version": "1.8.0",
4
+ "description": "Storage backends and config schemas for Dexto agents",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "zod": "^4.3.6",
24
- "@dexto/core": "1.7.2"
24
+ "@dexto/core": "1.8.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "better-sqlite3": "^11.10.0",
@@ -1,31 +0,0 @@
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 factories_exports = {};
20
- __export(factories_exports, {
21
- inMemoryBlobStoreFactory: () => import_memory.inMemoryBlobStoreFactory,
22
- localBlobStoreFactory: () => import_local.localBlobStoreFactory
23
- });
24
- module.exports = __toCommonJS(factories_exports);
25
- var import_local = require("./local.js");
26
- var import_memory = require("./memory.js");
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- inMemoryBlobStoreFactory,
30
- localBlobStoreFactory
31
- });
@@ -1,6 +0,0 @@
1
- /**
2
- * Built-in blob store factories.
3
- */
4
- export { localBlobStoreFactory } from './local.js';
5
- export { inMemoryBlobStoreFactory } from './memory.js';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/blob/factories/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
@@ -1,6 +0,0 @@
1
- import { localBlobStoreFactory } from "./local.js";
2
- import { inMemoryBlobStoreFactory } from "./memory.js";
3
- export {
4
- inMemoryBlobStoreFactory,
5
- localBlobStoreFactory
6
- };
@@ -1,38 +0,0 @@
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 local_exports = {};
20
- __export(local_exports, {
21
- localBlobStoreFactory: () => localBlobStoreFactory
22
- });
23
- module.exports = __toCommonJS(local_exports);
24
- var import_schemas = require("../schemas.js");
25
- var import_local_blob_store = require("../local-blob-store.js");
26
- const localBlobStoreFactory = {
27
- configSchema: import_schemas.LocalBlobStoreSchema,
28
- create: (config, logger) => new import_local_blob_store.LocalBlobStore(config, logger),
29
- metadata: {
30
- displayName: "Local Filesystem",
31
- description: "Store blobs on the local filesystem with automatic deduplication",
32
- requiresNetwork: false
33
- }
34
- };
35
- // Annotate the CommonJS export names for ESM import in node:
36
- 0 && (module.exports = {
37
- localBlobStoreFactory
38
- });
@@ -1,17 +0,0 @@
1
- import type { LocalBlobStoreConfig } from '../schemas.js';
2
- import type { BlobStoreFactory } from '../factory.js';
3
- /**
4
- * Factory for local filesystem blob storage.
5
- *
6
- * This factory stores blobs on the local filesystem with content-based
7
- * deduplication and metadata tracking. It's ideal for development and
8
- * single-machine deployments.
9
- *
10
- * Features:
11
- * - Zero external dependencies (uses Node.js fs module)
12
- * - Content-based deduplication (same hash = same blob)
13
- * - Automatic cleanup of old blobs
14
- * - No network required
15
- */
16
- export declare const localBlobStoreFactory: BlobStoreFactory<LocalBlobStoreConfig>;
17
- //# sourceMappingURL=local.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../src/blob/factories/local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,EAAE,gBAAgB,CAAC,oBAAoB,CAQxE,CAAC"}
@@ -1,14 +0,0 @@
1
- import { LocalBlobStoreSchema } from "../schemas.js";
2
- import { LocalBlobStore } from "../local-blob-store.js";
3
- const localBlobStoreFactory = {
4
- configSchema: LocalBlobStoreSchema,
5
- create: (config, logger) => new LocalBlobStore(config, logger),
6
- metadata: {
7
- displayName: "Local Filesystem",
8
- description: "Store blobs on the local filesystem with automatic deduplication",
9
- requiresNetwork: false
10
- }
11
- };
12
- export {
13
- localBlobStoreFactory
14
- };