@plyaz/db 0.0.1 → 0.1.1

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 (62) hide show
  1. package/README.md +98 -134
  2. package/dist/adapters/drizzle/DrizzleAdapter.d.ts +109 -9
  3. package/dist/adapters/drizzle/DrizzleAdapter.d.ts.map +1 -1
  4. package/dist/adapters/index.d.ts +5 -0
  5. package/dist/adapters/index.d.ts.map +1 -1
  6. package/dist/adapters/mock/MockAdapter.d.ts +88 -0
  7. package/dist/adapters/mock/MockAdapter.d.ts.map +1 -0
  8. package/dist/adapters/sql/SQLAdapter.d.ts +28 -6
  9. package/dist/adapters/sql/SQLAdapter.d.ts.map +1 -1
  10. package/dist/adapters/supabase/SupabaseAdapter.d.ts +11 -6
  11. package/dist/adapters/supabase/SupabaseAdapter.d.ts.map +1 -1
  12. package/dist/advanced/multi-tenancy/TenantRepository.d.ts +1 -7
  13. package/dist/advanced/multi-tenancy/TenantRepository.d.ts.map +1 -1
  14. package/dist/advanced/read-replica/ReadReplicaAdapter.d.ts +3 -2
  15. package/dist/advanced/read-replica/ReadReplicaAdapter.d.ts.map +1 -1
  16. package/dist/cli/index.d.ts +27 -0
  17. package/dist/cli/index.d.ts.map +1 -0
  18. package/dist/cli/index.js +8420 -0
  19. package/dist/cli/index.js.map +1 -0
  20. package/dist/extensions/AuditExtension.d.ts +56 -9
  21. package/dist/extensions/AuditExtension.d.ts.map +1 -1
  22. package/dist/extensions/CachingAdapter.d.ts +5 -4
  23. package/dist/extensions/CachingAdapter.d.ts.map +1 -1
  24. package/dist/extensions/EncryptionExtension.d.ts +5 -4
  25. package/dist/extensions/EncryptionExtension.d.ts.map +1 -1
  26. package/dist/extensions/MultiReadExtension.d.ts +95 -0
  27. package/dist/extensions/MultiReadExtension.d.ts.map +1 -0
  28. package/dist/extensions/MultiWriteExtension.d.ts +67 -0
  29. package/dist/extensions/MultiWriteExtension.d.ts.map +1 -0
  30. package/dist/extensions/ReadReplicaAdapter.d.ts +4 -3
  31. package/dist/extensions/ReadReplicaAdapter.d.ts.map +1 -1
  32. package/dist/extensions/SoftDeleteExtension.d.ts +5 -4
  33. package/dist/extensions/SoftDeleteExtension.d.ts.map +1 -1
  34. package/dist/extensions/index.d.ts +4 -0
  35. package/dist/extensions/index.d.ts.map +1 -1
  36. package/dist/factory/AdapterFactory.d.ts.map +1 -1
  37. package/dist/factory/createDatabaseService.d.ts.map +1 -1
  38. package/dist/index.cjs +3017 -401
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.ts +6 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.mjs +3443 -850
  43. package/dist/index.mjs.map +1 -1
  44. package/dist/migrations/MigrationManager.d.ts +106 -0
  45. package/dist/migrations/MigrationManager.d.ts.map +1 -0
  46. package/dist/migrations/generateDownMigration.d.ts +25 -0
  47. package/dist/migrations/generateDownMigration.d.ts.map +1 -0
  48. package/dist/migrations/index.d.ts +10 -0
  49. package/dist/migrations/index.d.ts.map +1 -0
  50. package/dist/repository/BaseRepository.d.ts +109 -23
  51. package/dist/repository/BaseRepository.d.ts.map +1 -1
  52. package/dist/seeds/SeedManager.d.ts +96 -0
  53. package/dist/seeds/SeedManager.d.ts.map +1 -0
  54. package/dist/seeds/index.d.ts +10 -0
  55. package/dist/seeds/index.d.ts.map +1 -0
  56. package/dist/service/DatabaseService.d.ts +89 -13
  57. package/dist/service/DatabaseService.d.ts.map +1 -1
  58. package/dist/service/EventEmitter.d.ts +3 -14
  59. package/dist/service/EventEmitter.d.ts.map +1 -1
  60. package/dist/service/HealthManager.d.ts +42 -3
  61. package/dist/service/HealthManager.d.ts.map +1 -1
  62. package/package.json +6 -2
@@ -0,0 +1,106 @@
1
+ /**
2
+ * MigrationManager - Database schema migrations with version control
3
+ *
4
+ * Manages database schema migrations with support for versioning,
5
+ * rollback, and migration history tracking. Automatically discovers
6
+ * migration files from a specified directory and applies them in order.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const migrationManager = new MigrationManager({
11
+ * adapter: sqlAdapter,
12
+ * migrationsPath: './migrations', // default
13
+ * tableName: 'schema_migrations' // default
14
+ * });
15
+ *
16
+ * // Run all pending migrations
17
+ * await migrationManager.up();
18
+ *
19
+ * // Rollback last migration
20
+ * await migrationManager.down();
21
+ *
22
+ * // Get migration status
23
+ * const status = await migrationManager.status();
24
+ * ```
25
+ */
26
+ import type { DatabaseResult, MigrationManagerConfig, MigrationStatus } from "@plyaz/types/db";
27
+ /**
28
+ * MigrationManager - Handles database schema migrations
29
+ *
30
+ * Discovers migration files, tracks migration history, and applies
31
+ * migrations in order with support for rollback.
32
+ */
33
+ export declare class MigrationManager {
34
+ private adapter;
35
+ private migrationsPath;
36
+ private tableName;
37
+ private schema;
38
+ constructor(config: MigrationManagerConfig);
39
+ /**
40
+ * Initialize migrations table if it doesn't exist
41
+ */
42
+ initialize(): Promise<DatabaseResult<void>>;
43
+ /**
44
+ * Discover migration files from migrations directory (including subdirectories)
45
+ */
46
+ private discoverMigrations;
47
+ /**
48
+ * Parse SQL content to extract UP and DOWN sections
49
+ */
50
+ private parseSqlSections;
51
+ /**
52
+ * Load SQL migration from file
53
+ */
54
+ private loadSqlMigration;
55
+ /**
56
+ * Load TypeScript/JavaScript migration from file
57
+ */
58
+ private loadJsMigration;
59
+ /**
60
+ * Load migration from file
61
+ */
62
+ private loadMigration;
63
+ /**
64
+ * Get applied migrations from database
65
+ */
66
+ private getAppliedMigrations;
67
+ /**
68
+ * Record migration as applied
69
+ */
70
+ private recordMigration;
71
+ /**
72
+ * Remove migration record (for rollback)
73
+ */
74
+ private unrecordMigration;
75
+ /**
76
+ * Get migration status (applied and pending)
77
+ */
78
+ status(): Promise<DatabaseResult<MigrationStatus>>;
79
+ /**
80
+ * Run all pending migrations
81
+ */
82
+ up(targetVersion?: string): Promise<DatabaseResult<number>>;
83
+ /**
84
+ * Rollback last migration or rollback to specific version
85
+ */
86
+ down(steps?: number): Promise<DatabaseResult<number>>;
87
+ /**
88
+ * Reset database (rollback all migrations)
89
+ */
90
+ reset(): Promise<DatabaseResult<number>>;
91
+ /**
92
+ * Clear migration history (delete all records from tracking table)
93
+ *
94
+ * Use this to force fresh migrations in test/development environments
95
+ * without rolling back actual database changes.
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * // Clear history and re-run all migrations
100
+ * await migrationManager.clearHistory();
101
+ * await migrationManager.up();
102
+ * ```
103
+ */
104
+ clearHistory(): Promise<DatabaseResult<void>>;
105
+ }
106
+ //# sourceMappingURL=MigrationManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MigrationManager.d.ts","sourceRoot":"","sources":["../../src/migrations/MigrationManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAEV,cAAc,EAId,sBAAsB,EACtB,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAOzB;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,sBAAsB;IAW1C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAkDjD;;OAEG;YACW,kBAAkB;IAsChC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA0BxB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAwBxB;;OAEG;YACW,eAAe;IAgB7B;;OAEG;YACW,aAAa;IAoB3B;;OAEG;YACW,oBAAoB;IAkBlC;;OAEG;YACW,eAAe;IAmB7B;;OAEG;YACW,iBAAiB;IAS/B;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IA2BxD;;OAEG;IACG,EAAE,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAiEjE;;OAEG;IACG,IAAI,CAAC,KAAK,GAAE,MAAU,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAiE9D;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAK9C;;;;;;;;;;;;OAYG;IACG,YAAY,IAAI,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;CAgBpD"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Utility to help generate DOWN migrations from SQL files
3
+ *
4
+ * This is a helper script to analyze SQL migrations and suggest
5
+ * appropriate DOWN statements for rollback support.
6
+ */
7
+ interface DownSuggestion {
8
+ file: string;
9
+ upStatements: string[];
10
+ downSuggestions: string[];
11
+ }
12
+ /**
13
+ * Parse SQL migration and suggest DOWN statements
14
+ */
15
+ export declare function suggestDownMigration(sqlContent: string, filename: string): DownSuggestion;
16
+ /**
17
+ * Add DOWN section to a migration file
18
+ */
19
+ export declare function addDownSection(filePath: string): string;
20
+ /**
21
+ * Process all migrations in a directory and add DOWN sections
22
+ */
23
+ export declare function processDirectory(migrationsPath: string, dryRun?: boolean): void;
24
+ export {};
25
+ //# sourceMappingURL=generateDownMigration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateDownMigration.d.ts","sourceRoot":"","sources":["../../src/migrations/generateDownMigration.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AA4FD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,cAAc,CAuBhB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAevD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,IAAI,CAwC5E"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Database Migrations Module
3
+ *
4
+ * Provides migration management for database schema versioning,
5
+ * rollback support, and migration history tracking.
6
+ *
7
+ * @module migrations
8
+ */
9
+ export { MigrationManager } from "./MigrationManager";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -6,7 +6,7 @@
6
6
  * CRUD operations and consistent interface patterns.
7
7
  *
8
8
  */
9
- import type { DatabaseResult, PaginatedResult, QueryOptions, Filter, DatabaseServiceType } from "@plyaz/types/db";
9
+ import type { DatabaseResult, PaginatedResult, QueryOptions, Filter, DatabaseServiceInterface, CreateInput, OperationConfig } from "@plyaz/types/db";
10
10
  /**
11
11
  * BASE REPOSITORY - Repository Layer Foundation
12
12
  *
@@ -14,13 +14,14 @@ import type { DatabaseResult, PaginatedResult, QueryOptions, Filter, DatabaseSer
14
14
  * All domain-specific repositories extend this class for type-safe database operations.
15
15
  *
16
16
  * **Application Flow Position:**
17
- * Service Layer **Repository Layer** DatabaseService Adapter Chain
17
+ * Service Layer **Repository Layer** DatabaseService Adapter Chain
18
18
  *
19
19
  * **What this class provides:**
20
20
  * - Type-safe CRUD operations for domain entities
21
21
  * - Consistent interface across all repositories
22
22
  * - Delegation to DatabaseService with proper table mapping
23
23
  * - Foundation for domain-specific repository methods
24
+ * - Default operation config (adapter, schema, etc.) that can be overridden per-query
24
25
  *
25
26
  * **Called by:** Service layer (UserService, OrderService, etc.)
26
27
  * **Calls:** DatabaseService methods (get, create, update, delete, etc.)
@@ -39,40 +40,62 @@ import type { DatabaseResult, PaginatedResult, QueryOptions, Filter, DatabaseSer
39
40
  * }
40
41
  *
41
42
  * class UserRepository extends BaseRepository<User> {
42
- * constructor(db: IDatabaseService) {
43
+ * constructor(db: DatabaseServiceInterface) {
43
44
  * super(db, Tables.USERS);
44
45
  * }
45
46
  *
46
47
  * // Domain-specific methods
47
48
  * async findByEmail(email: string) {
48
- * return this.db.query(this.tableName, {
49
- * filter: { field: 'email', operator: 'eq', value: email }
50
- * });
49
+ * return this.findOne({ field: 'email', operator: 'eq', value: email });
51
50
  * }
52
51
  * }
53
52
  * ```
54
53
  *
55
54
  * @example
55
+ * ### Repository with Default Adapter
56
+ * ```typescript
57
+ * // Analytics repository that always uses the 'analytics' adapter by default
58
+ * class AnalyticsRepository extends BaseRepository<Event> {
59
+ * constructor(db: DatabaseServiceInterface) {
60
+ * super(db, 'events', { adapter: 'analytics', schema: 'analytics' });
61
+ * }
62
+ * }
63
+ *
64
+ * // All queries use analytics adapter by default
65
+ * await analyticsRepo.findById('event-123'); // Uses 'analytics' adapter
66
+ *
67
+ * // But can still override per-query
68
+ * await analyticsRepo.findById('event-123', { adapter: 'primary' });
69
+ * ```
70
+ *
71
+ * @example
56
72
  * ### Usage in Service Layer
57
73
  * ```typescript
58
74
  * class UserService {
59
75
  * constructor(private userRepo: UserRepository) {}
60
76
  *
61
77
  * async getUserById(id: string) {
62
- * // Calls BaseRepository.findById() DatabaseService.get()
78
+ * // Calls BaseRepository.findById() DatabaseService.get()
63
79
  * return this.userRepo.findById(id);
64
80
  * }
65
81
  * }
66
82
  * ```
67
83
  */
68
- export declare abstract class BaseRepository<T> {
69
- protected readonly db: DatabaseServiceType;
84
+ export declare abstract class BaseRepository<T extends Record<string, unknown>> {
85
+ protected readonly db: DatabaseServiceInterface;
70
86
  protected readonly tableName: string;
71
- constructor(db: DatabaseServiceType, tableName: string);
87
+ protected readonly defaultConfig?: OperationConfig;
88
+ constructor(db: DatabaseServiceInterface, tableName: string, defaultConfig?: OperationConfig);
89
+ /**
90
+ * Merges default repository config with per-operation config
91
+ * Per-operation config takes precedence over default config
92
+ */
93
+ private mergeConfig;
72
94
  /**
73
95
  * Find a single entity by its primary key ID
74
96
  *
75
97
  * @param {string} id - The primary key ID of the entity to retrieve
98
+ * @param {OperationConfig} [config] - Optional per-operation configuration (adapter selection, schema override, etc.)
76
99
  * @returns {Promise<DatabaseResult<T | null>>} Promise resolving to the entity or null if not found
77
100
  *
78
101
  * @example
@@ -81,13 +104,19 @@ export declare abstract class BaseRepository<T> {
81
104
  * if (result.success && result.value) {
82
105
  * console.log('Found user:', result.value.name);
83
106
  * }
107
+ *
108
+ * // Use specific adapter for this query
109
+ * const analyticsResult = await userRepository.findById('user-123', {
110
+ * adapter: 'analytics'
111
+ * });
84
112
  * ```
85
113
  */
86
- findById(id: string): Promise<DatabaseResult<T | null>>;
114
+ findById(id: string, config?: OperationConfig): Promise<DatabaseResult<T | null>>;
87
115
  /**
88
116
  * Find multiple entities with optional filtering, sorting, and pagination
89
117
  *
90
- * @param {QueryOptions} [options] - Optional query configuration
118
+ * @param {QueryOptions<T>} [options] - Optional query configuration with type-safe fields
119
+ * @param {OperationConfig} [config] - Optional per-operation configuration (adapter selection, schema override, etc.)
91
120
  * @returns {Promise<DatabaseResult<PaginatedResult<T>>>} Promise resolving to paginated results
92
121
  *
93
122
  * @example
@@ -97,13 +126,19 @@ export declare abstract class BaseRepository<T> {
97
126
  * sort: [{ field: 'createdAt', direction: 'desc' }],
98
127
  * pagination: { limit: 20, offset: 0 }
99
128
  * });
129
+ *
130
+ * // Query from analytics database
131
+ * const analyticsResult = await userRepository.findMany({}, {
132
+ * adapter: 'analytics'
133
+ * });
100
134
  * ```
101
135
  */
102
- findMany(options?: QueryOptions): Promise<DatabaseResult<PaginatedResult<T>>>;
136
+ findMany(options?: QueryOptions<T>, config?: OperationConfig): Promise<DatabaseResult<PaginatedResult<T>>>;
103
137
  /**
104
138
  * Create a new entity in the database
105
139
  *
106
- * @param {T} data - The entity data to create
140
+ * @param {CreateInput<T>} data - The entity data to create (id is auto-generated)
141
+ * @param {OperationConfig} [config] - Optional per-operation configuration (adapter selection, schema override, etc.)
107
142
  * @returns {Promise<DatabaseResult<T>>} Promise resolving to the created entity
108
143
  *
109
144
  * @example
@@ -112,14 +147,23 @@ export declare abstract class BaseRepository<T> {
112
147
  * name: 'John Doe',
113
148
  * email: 'john@example.com'
114
149
  * });
150
+ *
151
+ * // Create in specific database/schema
152
+ * const result = await userRepository.create({
153
+ * name: 'Jane Doe'
154
+ * }, {
155
+ * adapter: 'secondary',
156
+ * schema: 'backoffice'
157
+ * });
115
158
  * ```
116
159
  */
117
- create(data: T): Promise<DatabaseResult<T>>;
160
+ create(data: CreateInput<T>, config?: OperationConfig): Promise<DatabaseResult<T>>;
118
161
  /**
119
162
  * Update an existing entity by ID
120
163
  *
121
164
  * @param {string} id - The primary key ID of the entity to update
122
165
  * @param {Partial<T>} data - Partial entity data containing fields to update
166
+ * @param {OperationConfig} [config] - Optional per-operation configuration (adapter selection, schema override, etc.)
123
167
  * @returns {Promise<DatabaseResult<T>>} Promise resolving to the updated entity
124
168
  *
125
169
  * @example
@@ -128,13 +172,22 @@ export declare abstract class BaseRepository<T> {
128
172
  * email: 'newemail@example.com',
129
173
  * updatedAt: new Date()
130
174
  * });
175
+ *
176
+ * // Update in specific adapter with custom ID column
177
+ * const result = await userRepository.update('flag-key', {
178
+ * value: true
179
+ * }, {
180
+ * adapter: 'config',
181
+ * idColumn: 'key'
182
+ * });
131
183
  * ```
132
184
  */
133
- update(id: string, data: Partial<T>): Promise<DatabaseResult<T>>;
185
+ update(id: string, data: Partial<T>, config?: OperationConfig): Promise<DatabaseResult<T>>;
134
186
  /**
135
187
  * Delete an entity by ID (hard delete)
136
188
  *
137
189
  * @param {string} id - The primary key ID of the entity to delete
190
+ * @param {OperationConfig} [config] - Optional per-operation configuration (adapter selection, schema override, etc.)
138
191
  * @returns {Promise<DatabaseResult<void>>} Promise resolving when deletion is complete
139
192
  *
140
193
  * @warning This is a permanent operation that cannot be undone
@@ -143,13 +196,19 @@ export declare abstract class BaseRepository<T> {
143
196
  * @example
144
197
  * ```typescript
145
198
  * const result = await userRepository.delete('user-123');
199
+ *
200
+ * // Delete from specific adapter
201
+ * const result = await userRepository.delete('user-123', {
202
+ * adapter: 'archive'
203
+ * });
146
204
  * ```
147
205
  */
148
- delete(id: string): Promise<DatabaseResult<void>>;
206
+ delete(id: string, config?: OperationConfig): Promise<DatabaseResult<void>>;
149
207
  /**
150
208
  * Count entities matching optional filter criteria
151
209
  *
152
- * @param {Filter} [filter] - Optional filter conditions
210
+ * @param {Filter<T>} [filter] - Optional filter conditions with type-safe fields
211
+ * @param {OperationConfig} [config] - Optional per-operation configuration (adapter selection, schema override, etc.)
153
212
  * @returns {Promise<DatabaseResult<number>>} Promise resolving to the count
154
213
  *
155
214
  * @example
@@ -158,13 +217,19 @@ export declare abstract class BaseRepository<T> {
158
217
  * const activeResult = await userRepository.count({
159
218
  * field: 'status', operator: 'eq', value: 'active'
160
219
  * });
220
+ *
221
+ * // Count in specific adapter
222
+ * const archiveCount = await userRepository.count(undefined, {
223
+ * adapter: 'archive'
224
+ * });
161
225
  * ```
162
226
  */
163
- count(filter?: Filter): Promise<DatabaseResult<number>>;
227
+ count(filter?: Filter<T>, config?: OperationConfig): Promise<DatabaseResult<number>>;
164
228
  /**
165
229
  * Check if an entity exists by ID
166
230
  *
167
231
  * @param {string} id - The primary key ID to check
232
+ * @param {OperationConfig} [config] - Optional per-operation configuration (adapter selection, schema override, etc.)
168
233
  * @returns {Promise<DatabaseResult<boolean>>} Promise resolving to existence status
169
234
  *
170
235
  * @example
@@ -173,13 +238,19 @@ export declare abstract class BaseRepository<T> {
173
238
  * if (existsResult.success && existsResult.value) {
174
239
  * console.log('User exists');
175
240
  * }
241
+ *
242
+ * // Check existence in specific adapter
243
+ * const existsInArchive = await userRepository.exists('user-123', {
244
+ * adapter: 'archive'
245
+ * });
176
246
  * ```
177
247
  */
178
- exists(id: string): Promise<DatabaseResult<boolean>>;
248
+ exists(id: string, config?: OperationConfig): Promise<DatabaseResult<boolean>>;
179
249
  /**
180
250
  * Find the first entity matching filter criteria
181
251
  *
182
- * @param {Filter} filter - Filter conditions to match
252
+ * @param {Filter<T>} filter - Filter conditions with type-safe fields
253
+ * @param {OperationConfig} [config] - Optional per-operation configuration (adapter selection, schema override, etc.)
183
254
  * @returns {Promise<DatabaseResult<T | null>>} Promise resolving to first match or null
184
255
  *
185
256
  * @example
@@ -187,13 +258,22 @@ export declare abstract class BaseRepository<T> {
187
258
  * const result = await userRepository.findOne({
188
259
  * field: 'email', operator: 'eq', value: 'john@example.com'
189
260
  * });
261
+ *
262
+ * // Find in specific adapter
263
+ * const archivedUser = await userRepository.findOne({
264
+ * field: 'email', operator: 'eq', value: 'john@example.com'
265
+ * }, {
266
+ * adapter: 'archive',
267
+ * includeSoftDeleted: true
268
+ * });
190
269
  * ```
191
270
  */
192
- findOne(filter: Filter): Promise<DatabaseResult<T | null>>;
271
+ findOne(filter: Filter<T>, config?: OperationConfig): Promise<DatabaseResult<T | null>>;
193
272
  /**
194
273
  * Soft delete an entity by ID (recoverable deletion)
195
274
  *
196
275
  * @param {string} id - The primary key ID of the entity to soft delete
276
+ * @param {OperationConfig} [config] - Optional per-operation configuration (adapter selection, schema override, etc.)
197
277
  * @returns {Promise<DatabaseResult<void>>} Promise resolving when soft deletion is complete
198
278
  *
199
279
  * @see {@link delete} For permanent deletion
@@ -202,8 +282,14 @@ export declare abstract class BaseRepository<T> {
202
282
  * ```typescript
203
283
  * const result = await userRepository.softDelete('user-123');
204
284
  * // User is hidden but can be recovered
285
+ *
286
+ * // Soft delete in specific adapter
287
+ * const result = await userRepository.softDelete('user-123', {
288
+ * adapter: 'primary',
289
+ * skipAudit: false
290
+ * });
205
291
  * ```
206
292
  */
207
- softDelete(id: string): Promise<DatabaseResult<void>>;
293
+ softDelete(id: string, config?: OperationConfig): Promise<DatabaseResult<void>>;
208
294
  }
209
295
  //# sourceMappingURL=BaseRepository.d.ts.map
@@ -1 +1 @@
1
-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ACV,MAAM,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;CAGjC"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * SeedManager - Database seeding for development and testing
3
+ *
4
+ * Manages database seeding with support for ordered execution,
5
+ * seed history tracking, and idempotent seed operations.
6
+ * Automatically discovers seed files from a specified directory.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const seedManager = new SeedManager({
11
+ * adapter: sqlAdapter,
12
+ * seedsPath: './seeds', // default
13
+ * tableName: 'seed_history' // default
14
+ * });
15
+ *
16
+ * // Run all seeds
17
+ * await seedManager.run();
18
+ *
19
+ * // Run specific seed
20
+ * await seedManager.run('users');
21
+ *
22
+ * // Clear all data (for testing)
23
+ * await seedManager.reset();
24
+ * ```
25
+ */
26
+ import type { DatabaseResult, SeedRecord, SeedManagerConfig } from "@plyaz/types/db";
27
+ /**
28
+ * SeedManager - Handles database seeding operations
29
+ *
30
+ * Discovers seed files, tracks seed history, and executes
31
+ * seeds in order with support for cleanup and reset.
32
+ */
33
+ export declare class SeedManager {
34
+ private adapter;
35
+ private seedsPath;
36
+ private tableName;
37
+ private schema;
38
+ private skipExisting;
39
+ constructor(config: SeedManagerConfig);
40
+ /**
41
+ * Initialize seeds tracking table if it doesn't exist
42
+ */
43
+ initialize(): Promise<DatabaseResult<void>>;
44
+ /**
45
+ * Discover seed files from seeds directory
46
+ */
47
+ private discoverSeeds;
48
+ /**
49
+ * Load seed from file
50
+ */
51
+ private loadSeed;
52
+ /**
53
+ * Get executed seeds from database
54
+ */
55
+ private getExecutedSeeds;
56
+ /**
57
+ * Record seed as executed
58
+ */
59
+ private recordSeed;
60
+ /**
61
+ * Remove seed record (for reset)
62
+ */
63
+ private unrecordSeed;
64
+ /**
65
+ * Execute a seed function with optional transaction support
66
+ */
67
+ private executeSeed;
68
+ /**
69
+ * Check if a seed should be skipped and log if applicable
70
+ */
71
+ private shouldSkipSeed;
72
+ /**
73
+ * Run all seeds or a specific seed
74
+ */
75
+ run(seedName?: string): Promise<DatabaseResult<number>>;
76
+ /**
77
+ * Execute cleanup function with optional transaction support
78
+ */
79
+ private executeCleanup;
80
+ /**
81
+ * Reset all seeds (run cleanup functions)
82
+ */
83
+ reset(): Promise<DatabaseResult<number>>;
84
+ /**
85
+ * Get seed execution status
86
+ */
87
+ status(): Promise<DatabaseResult<{
88
+ executed: SeedRecord[];
89
+ pending: string[];
90
+ }>>;
91
+ /**
92
+ * Clear seed history (doesn't clean data, just removes tracking records)
93
+ */
94
+ clearHistory(): Promise<DatabaseResult<void>>;
95
+ }
96
+ //# sourceMappingURL=SeedManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SeedManager.d.ts","sourceRoot":"","sources":["../../src/seeds/SeedManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAEV,cAAc,EAGd,UAAU,EACV,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAOzB;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAU;gBAElB,MAAM,EAAE,iBAAiB;IAYrC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAiDjD;;OAEG;YACW,aAAa;IA0B3B;;OAEG;YACW,QAAQ;IAkBtB;;OAEG;YACW,gBAAgB;IAkB9B;;OAEG;YACW,UAAU;IAmBxB;;OAEG;YACW,YAAY;IAS1B;;OAEG;YACW,WAAW;IAUzB;;OAEG;IACH,OAAO,CAAC,cAAc;IAetB;;OAEG;IACG,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IA2C7D;;OAEG;YACW,cAAc;IAY5B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAsC9C;;OAEG;IACG,MAAM,IAAI,OAAO,CACrB,cAAc,CAAC;QAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAC9D;IA2BD;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;CAgBpD"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Database Seeds Module
3
+ *
4
+ * Provides seeding management for populating database with
5
+ * initial or test data, with history tracking and cleanup support.
6
+ *
7
+ * @module seeds
8
+ */
9
+ export { SeedManager } from "./SeedManager";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/seeds/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}