@plyaz/types 1.18.0 → 1.18.2

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 (53) hide show
  1. package/dist/api/endpoints/featureFlags/endpoints.d.ts +83 -0
  2. package/dist/api/endpoints/featureFlags/index.d.ts +8 -0
  3. package/dist/api/endpoints/featureFlags/types.d.ts +153 -0
  4. package/dist/api/endpoints/index.d.ts +1 -0
  5. package/dist/api/endpoints/types.d.ts +2 -1
  6. package/dist/api/index.cjs +52 -0
  7. package/dist/api/index.cjs.map +1 -1
  8. package/dist/api/index.d.ts +1 -0
  9. package/dist/api/index.js +52 -0
  10. package/dist/api/index.js.map +1 -1
  11. package/dist/core/events/index.d.ts +4 -0
  12. package/dist/core/events/payloads.d.ts +168 -0
  13. package/dist/core/featureFlag/enums.d.ts +11 -6
  14. package/dist/core/featureFlag/types.d.ts +146 -1
  15. package/dist/core/index.d.ts +3 -0
  16. package/dist/core/modules.d.ts +408 -0
  17. package/dist/db/audit.types.d.ts +22 -0
  18. package/dist/db/config.types.d.ts +21 -1
  19. package/dist/db/database.types.d.ts +2 -0
  20. package/dist/db/databaseAdapter.d.ts +13 -3
  21. package/dist/db/databaseService.d.ts +21 -48
  22. package/dist/db/dbEnums.d.ts +33 -5
  23. package/dist/db/extensions.types.d.ts +35 -0
  24. package/dist/db/features-config.types.d.ts +28 -2
  25. package/dist/db/health.types.d.ts +16 -0
  26. package/dist/db/index.cjs +20 -3
  27. package/dist/db/index.cjs.map +1 -1
  28. package/dist/db/index.d.ts +5 -0
  29. package/dist/db/index.js +20 -4
  30. package/dist/db/index.js.map +1 -1
  31. package/dist/db/migrations.types.d.ts +60 -0
  32. package/dist/db/seeds.types.d.ts +49 -0
  33. package/dist/db/tenant.types.d.ts +14 -0
  34. package/dist/errors/codes.d.ts +8 -0
  35. package/dist/errors/enums.d.ts +3 -0
  36. package/dist/errors/index.cjs +55 -0
  37. package/dist/errors/index.cjs.map +1 -1
  38. package/dist/errors/index.js +55 -0
  39. package/dist/errors/index.js.map +1 -1
  40. package/dist/examples/index.cjs +76 -0
  41. package/dist/examples/index.cjs.map +1 -0
  42. package/dist/examples/index.d.ts +17 -0
  43. package/dist/examples/index.js +68 -0
  44. package/dist/examples/index.js.map +1 -0
  45. package/dist/examples/schemas.d.ts +119 -0
  46. package/dist/examples/types.d.ts +103 -0
  47. package/dist/features/feature-flag/types.d.ts +62 -32
  48. package/dist/index.cjs +107 -14
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.ts +5 -1
  51. package/dist/index.js +103 -14
  52. package/dist/index.js.map +1 -1
  53. package/package.json +6 -1
@@ -0,0 +1,408 @@
1
+ /**
2
+ * Core Module System Types
3
+ *
4
+ * Framework-agnostic module interface for @plyaz/core.
5
+ * Modules implement this contract to integrate with Core.
6
+ */
7
+ import type { DatabaseServiceInterface } from '../db/databaseService';
8
+ import type { HttpMethod } from '../api/config/types';
9
+ export type { HttpMethod };
10
+ /**
11
+ * Core services available to modules
12
+ */
13
+ export interface CoreServices {
14
+ db: DatabaseServiceInterface;
15
+ env: Record<string, string | undefined>;
16
+ }
17
+ /**
18
+ * Route handler context
19
+ */
20
+ export interface CoreRouteContext {
21
+ params: Record<string, string>;
22
+ query: Record<string, string | string[]>;
23
+ body: unknown;
24
+ headers: Record<string, string>;
25
+ services: CoreServices;
26
+ }
27
+ /**
28
+ * Route handler function
29
+ */
30
+ export type CoreRouteHandler = (ctx: CoreRouteContext) => Promise<{
31
+ status?: number;
32
+ body?: unknown;
33
+ headers?: Record<string, string>;
34
+ }>;
35
+ /**
36
+ * Route definition - framework agnostic
37
+ */
38
+ export interface CoreRouteDefinition {
39
+ method: HttpMethod;
40
+ path: string;
41
+ handler: CoreRouteHandler;
42
+ middleware?: string[];
43
+ description?: string;
44
+ }
45
+ /**
46
+ * Module configuration schema (optional)
47
+ */
48
+ export interface CoreModuleConfigSchema<T = unknown> {
49
+ parse: (config: unknown) => T;
50
+ safeParse: (config: unknown) => {
51
+ success: boolean;
52
+ data?: T;
53
+ error?: Error;
54
+ };
55
+ }
56
+ /**
57
+ * Service factory for creating module services
58
+ */
59
+ export type CoreServiceFactory<T = unknown> = (services: CoreServices, config?: unknown) => T | Promise<T>;
60
+ /**
61
+ * Module lifecycle hooks
62
+ */
63
+ export interface CoreModuleLifecycle {
64
+ /**
65
+ * Called when module is initialized
66
+ * Use for setup, connections, etc.
67
+ */
68
+ onInit?(services: CoreServices): Promise<void>;
69
+ /**
70
+ * Called when module is being destroyed
71
+ * Use for cleanup, closing connections, etc.
72
+ */
73
+ onDestroy?(): Promise<void>;
74
+ /**
75
+ * Called when Core is fully initialized (all modules loaded)
76
+ */
77
+ onReady?(services: CoreServices): Promise<void>;
78
+ }
79
+ /**
80
+ * Core module definition - framework agnostic contract
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const FeatureFlagModule: CoreModuleDefinition = {
85
+ * name: 'featureFlags',
86
+ * version: '1.0.0',
87
+ * dependencies: ['db'],
88
+ *
89
+ * routes: [
90
+ * { method: 'GET', path: '/flags', handler: listFlags },
91
+ * { method: 'GET', path: '/flags/:key', handler: getFlag },
92
+ * ],
93
+ *
94
+ * services: {
95
+ * featureFlagService: (core) => new FeatureFlagService(core.db),
96
+ * },
97
+ *
98
+ * async onInit(services) {
99
+ * // Initialize feature flag provider
100
+ * },
101
+ * };
102
+ * ```
103
+ */
104
+ export interface CoreModuleDefinition<TConfig = unknown> extends CoreModuleLifecycle {
105
+ /**
106
+ * Unique module name (used for registration and access)
107
+ */
108
+ name: string;
109
+ /**
110
+ * Module version
111
+ */
112
+ version?: string;
113
+ /**
114
+ * Core services this module depends on
115
+ */
116
+ dependencies?: ('db' | 'api' | 'cache' | 'logger')[];
117
+ /**
118
+ * HTTP routes provided by this module
119
+ */
120
+ routes?: CoreRouteDefinition[];
121
+ /**
122
+ * Services exposed by this module
123
+ */
124
+ services?: Record<string, CoreServiceFactory>;
125
+ /**
126
+ * Configuration schema for validation
127
+ */
128
+ configSchema?: CoreModuleConfigSchema<TConfig>;
129
+ /**
130
+ * Default configuration
131
+ */
132
+ defaultConfig?: Partial<TConfig>;
133
+ }
134
+ /**
135
+ * Registered module instance (after initialization)
136
+ */
137
+ export interface CoreRegisteredModule<TConfig = unknown> {
138
+ definition: CoreModuleDefinition<TConfig>;
139
+ config: TConfig;
140
+ services: Record<string, unknown>;
141
+ initialized: boolean;
142
+ }
143
+ /**
144
+ * Module with configuration (result of .forRoot())
145
+ */
146
+ export interface CoreConfiguredModule<TConfig = unknown> {
147
+ definition: CoreModuleDefinition<TConfig>;
148
+ config: TConfig;
149
+ }
150
+ /**
151
+ * Helper to create a module definition with forRoot pattern
152
+ */
153
+ export interface CoreModuleFactory<TConfig = unknown> {
154
+ /**
155
+ * Module definition
156
+ */
157
+ definition: CoreModuleDefinition<TConfig>;
158
+ /**
159
+ * Configure module with options
160
+ */
161
+ forRoot(config?: Partial<TConfig>): CoreConfiguredModule<TConfig>;
162
+ /**
163
+ * Use module with default config
164
+ */
165
+ default: CoreConfiguredModule<TConfig>;
166
+ }
167
+ /**
168
+ * Supported HTTP frameworks for server mode
169
+ */
170
+ export type CoreFrameworkType = 'node' | 'express' | 'nestjs' | 'nextjs';
171
+ /**
172
+ * Server configuration
173
+ */
174
+ export interface CoreServerConfig {
175
+ port: number;
176
+ host?: string;
177
+ framework?: CoreFrameworkType;
178
+ prefix?: string;
179
+ cors?: {
180
+ enabled: boolean;
181
+ origins?: string[];
182
+ };
183
+ }
184
+ /**
185
+ * Framework adapter interface
186
+ */
187
+ export interface CoreFrameworkAdapter {
188
+ /**
189
+ * Framework name
190
+ */
191
+ name: CoreFrameworkType;
192
+ /**
193
+ * Register routes from modules
194
+ */
195
+ registerRoutes(routes: Array<{
196
+ moduleName: string;
197
+ routes: CoreRouteDefinition[];
198
+ }>, services: CoreServices): void | Promise<void>;
199
+ /**
200
+ * Start the server
201
+ */
202
+ start(config: CoreServerConfig): Promise<void>;
203
+ /**
204
+ * Stop the server
205
+ */
206
+ stop(): Promise<void>;
207
+ /**
208
+ * Get the underlying framework instance (express app, fastify instance, etc.)
209
+ */
210
+ getInstance(): unknown;
211
+ }
212
+ /**
213
+ * Adapter factory function
214
+ */
215
+ export type CoreAdapterFactory = () => CoreFrameworkAdapter;
216
+ /**
217
+ * Runtime environment detection
218
+ */
219
+ export type CoreRuntimeEnvironment = 'node' | 'nestjs' | 'express' | 'nuxt' | 'nextjs' | 'browser' | 'edge' | 'deno' | 'bun' | 'unknown';
220
+ /**
221
+ * Runtime context type
222
+ */
223
+ export type CoreRuntimeContext = 'backend' | 'frontend' | 'universal';
224
+ /**
225
+ * Backend runtimes - always server-side
226
+ */
227
+ export declare const BACKEND_RUNTIMES: readonly CoreRuntimeEnvironment[];
228
+ /**
229
+ * Frontend runtimes - always client-side
230
+ */
231
+ export declare const FRONTEND_RUNTIMES: readonly CoreRuntimeEnvironment[];
232
+ /**
233
+ * Universal runtimes - can be either (SSR)
234
+ */
235
+ export declare const UNIVERSAL_RUNTIMES: readonly CoreRuntimeEnvironment[];
236
+ /**
237
+ * Handler context for Next.js API routes
238
+ * Provides services and parsed request data
239
+ */
240
+ export interface CoreNextJsHandlerContext {
241
+ /** Database service */
242
+ db: unknown;
243
+ /** URL parameters (from dynamic routes like [id]) */
244
+ params: Record<string, string>;
245
+ /** Query string parameters */
246
+ query: Record<string, string | string[]>;
247
+ /** Request body (parsed JSON) */
248
+ body: unknown;
249
+ /** Request headers */
250
+ headers: Record<string, string>;
251
+ /** Original Request object */
252
+ request: Request;
253
+ }
254
+ /**
255
+ * Handler return type for Next.js API routes
256
+ */
257
+ export interface CoreNextJsHandlerResult {
258
+ /** Response body (will be JSON serialized) */
259
+ [key: string]: unknown;
260
+ /** HTTP status code (default: 200) */
261
+ status?: number;
262
+ /** Response headers */
263
+ headers?: Record<string, string>;
264
+ }
265
+ /**
266
+ * Handler function type for Next.js API routes
267
+ */
268
+ export type CoreNextJsHandler = (ctx: CoreNextJsHandlerContext) => Promise<CoreNextJsHandlerResult | Response>;
269
+ /**
270
+ * Options for Next.js createHandler
271
+ */
272
+ export interface CoreNextJsHandlerOptions {
273
+ /** Core initialization options (used on first request) */
274
+ coreOptions?: Record<string, unknown>;
275
+ }
276
+ /**
277
+ * Core environment variables
278
+ */
279
+ export interface CoreEnvVars {
280
+ DATABASE_URL?: string;
281
+ SUPABASE_URL?: string;
282
+ SUPABASE_SERVICE_ROLE_KEY?: string;
283
+ SUPABASE_ANON_PUBLIC_KEY?: string;
284
+ ENCRYPTION_KEY?: string;
285
+ API_BASE_URL?: string;
286
+ API_TIMEOUT?: string;
287
+ NODE_ENV?: string;
288
+ [key: string]: string | undefined;
289
+ }
290
+ /**
291
+ * Application environment type
292
+ */
293
+ export type CoreAppEnvironment = 'development' | 'staging' | 'production' | 'test';
294
+ /**
295
+ * API client initialization options
296
+ * Extends ApiClientOptions with Core-specific settings
297
+ */
298
+ export interface CoreApiInitOptions {
299
+ /** Environment for API client configuration */
300
+ env?: CoreAppEnvironment;
301
+ /** Set this client as the default */
302
+ setAsDefault?: boolean;
303
+ /** Base URL for API requests */
304
+ baseURL?: string;
305
+ /** Request timeout in milliseconds */
306
+ timeout?: number;
307
+ /** Additional options passed to ApiClientService */
308
+ [key: string]: unknown;
309
+ }
310
+ /**
311
+ * Core initialization options
312
+ */
313
+ export interface CoreInitOptions<TDbConfig = unknown, TApiConfig = CoreApiInitOptions> {
314
+ /** Path to .env file */
315
+ envPath?: string;
316
+ /** Global application environment */
317
+ environment?: CoreAppEnvironment;
318
+ /** Application context (webapp, backoffice, mobile, etc.) */
319
+ appContext?: CoreAppContext;
320
+ /** Explicit environment variables */
321
+ env?: CoreEnvVars;
322
+ /** Database configuration */
323
+ db?: TDbConfig;
324
+ /** API client configuration */
325
+ api?: TApiConfig;
326
+ /** Skip database initialization */
327
+ skipDb?: boolean;
328
+ /** Skip API client initialization */
329
+ skipApi?: boolean;
330
+ /** Enable verbose logging */
331
+ verbose?: boolean;
332
+ }
333
+ /**
334
+ * Core initialization result
335
+ */
336
+ export interface CoreServicesResult<TDb = unknown, TApi = unknown> {
337
+ db: TDb | null;
338
+ api: TApi | null;
339
+ env: CoreEnvVars;
340
+ runtime: CoreRuntimeEnvironment;
341
+ appContext: CoreAppContext;
342
+ }
343
+ /**
344
+ * Core module options for NestJS
345
+ */
346
+ export interface CoreNestJsModuleOptions {
347
+ /** Path to .env file */
348
+ envPath?: string;
349
+ /** Database configuration */
350
+ db?: Record<string, unknown>;
351
+ /** Whether to make Core services globally available */
352
+ isGlobal?: boolean;
353
+ }
354
+ /**
355
+ * Async options for NestJS CoreModule
356
+ */
357
+ export interface CoreNestJsModuleAsyncOptions {
358
+ imports?: unknown[];
359
+ inject?: unknown[];
360
+ useFactory: (...args: unknown[]) => CoreNestJsModuleOptions | Promise<CoreNestJsModuleOptions>;
361
+ isGlobal?: boolean;
362
+ }
363
+ /**
364
+ * Application context type
365
+ *
366
+ * Identifies which type of application is running.
367
+ * Different apps may have different feature flags, API endpoints, or UI behaviors.
368
+ */
369
+ export type CoreAppContext = 'webapp' | 'backoffice' | 'mobile' | 'microapp' | 'cli';
370
+ /**
371
+ * App context constants for type-safe comparisons
372
+ */
373
+ export declare const APP_CONTEXTS: readonly CoreAppContext[];
374
+ /**
375
+ * Service runtime compatibility
376
+ *
377
+ * Declares which runtimes a service can execute on.
378
+ * Services can be restricted to specific runtimes for security
379
+ * (e.g., backend-only services should never be bundled for frontend).
380
+ */
381
+ export type CoreServiceRuntime = 'frontend' | 'backend' | 'universal';
382
+ /**
383
+ * Domain service configuration
384
+ *
385
+ * Declares service metadata including runtime compatibility
386
+ * and feature flag requirements.
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * class CampaignDomainService {
391
+ * static readonly config: CoreDomainServiceConfig = {
392
+ * name: 'CampaignDomainService',
393
+ * runtimes: ['frontend', 'backend'],
394
+ * requiresFeatureFlag: 'campaigns:enabled',
395
+ * };
396
+ * }
397
+ * ```
398
+ */
399
+ export interface CoreDomainServiceConfig {
400
+ /** Service name for logging and debugging */
401
+ name: string;
402
+ /** Runtimes this service can run on */
403
+ runtimes: readonly CoreServiceRuntime[];
404
+ /** Feature flag required to use this service (optional) */
405
+ requiresFeatureFlag?: string;
406
+ /** App contexts this service is available in (optional, all if not specified) */
407
+ appContexts?: readonly CoreAppContext[];
408
+ }
@@ -7,6 +7,19 @@ export interface AuditContext {
7
7
  ipAddress?: string;
8
8
  userAgent?: string;
9
9
  }
10
+ /**
11
+ * Failure details for failed operations
12
+ */
13
+ export interface AuditFailureDetails {
14
+ /** Which extension/layer caused the failure */
15
+ source: string;
16
+ /** Error type/name */
17
+ error_type: string;
18
+ /** Error message */
19
+ error_message: string;
20
+ /** Error code if available */
21
+ error_code?: string;
22
+ }
10
23
  export interface AuditEvent {
11
24
  operation: string;
12
25
  table: string;
@@ -14,9 +27,18 @@ export interface AuditEvent {
14
27
  userId?: string;
15
28
  requestId?: string;
16
29
  changes: {
30
+ /** State before the operation */
17
31
  before?: Record<string, string | number | boolean | Date>;
32
+ /** State after the operation (for successful operations) */
18
33
  after?: Record<string, string | number | boolean | Date>;
34
+ /** Fields that were modified */
19
35
  fields?: string[];
36
+ /** Data that was attempted to be written (for failed operations) */
37
+ attempted?: Record<string, string | number | boolean | Date>;
38
+ /** Failure details (for failed operations) */
39
+ failure?: AuditFailureDetails;
40
+ /** Fields that are encrypted at rest (values shown are decrypted for audit) */
41
+ encryptedFields?: string[];
20
42
  };
21
43
  timestamp: Date;
22
44
  ipAddress?: string;
@@ -28,6 +28,12 @@ export interface BaseAdapter {
28
28
  ssl?: boolean;
29
29
  /** Database schema name */
30
30
  schema?: string;
31
+ /**
32
+ * Custom ID column mappings for tables
33
+ * Example: { 'feature_flags': 'key', 'sessions': 'session_id' }
34
+ * Tables not specified will default to 'id'
35
+ */
36
+ tableIdColumns?: Record<string, string>;
31
37
  }
32
38
  /**
33
39
  * Drizzle adapter configuration
@@ -53,7 +59,21 @@ export interface SupabaseAdapterConfig extends BaseAdapter {
53
59
  export interface SQLAdapterConfig extends BaseAdapter {
54
60
  adapter: ADAPTERS.SQL;
55
61
  }
62
+ /**
63
+ * Mock adapter configuration for testing
64
+ */
65
+ export interface DbMockAdapterConfig extends BaseAdapter {
66
+ adapter: ADAPTERS.MOCK;
67
+ /** Initial data to populate the mock database */
68
+ initialData?: Record<string, Record<string, unknown>[]>;
69
+ /** Whether to auto-generate IDs for records without them */
70
+ autoGenerateIds?: boolean;
71
+ /** Simulated latency in milliseconds */
72
+ latency?: number;
73
+ /** Simulated failure rate (0-1) for chaos testing */
74
+ failRate?: number;
75
+ }
56
76
  /**
57
77
  * Database configuration as a union of all adapter configurations
58
78
  */
59
- export type DatabaseConfig = DrizzleAdapterConfig | SupabaseAdapterConfig | SQLAdapterConfig;
79
+ export type DatabaseConfig = DrizzleAdapterConfig | SupabaseAdapterConfig | SQLAdapterConfig | DbMockAdapterConfig;
@@ -80,6 +80,8 @@ export interface QueryOptions<TRecord extends object = object> {
80
80
  sort?: SortOptions<TRecord>[];
81
81
  /** Pagination options */
82
82
  pagination?: PaginationOptions;
83
+ /** Database schema to use (overrides adapter default) */
84
+ schema?: string;
83
85
  }
84
86
  /**
85
87
  * Filter conditions for queries
@@ -100,6 +100,11 @@ export interface DatabaseAdapterType {
100
100
  * @returns Promise that resolves when disconnected
101
101
  */
102
102
  disconnect(): Promise<void>;
103
+ /**
104
+ * Close the database connection and cleanup resources
105
+ * @returns Promise resolving to DatabaseResult indicating success or failure
106
+ */
107
+ close(): Promise<DatabaseResult<void>>;
103
108
  /**
104
109
  * Get the underlying database client
105
110
  * @returns The underlying database client
@@ -132,14 +137,14 @@ export interface DatabaseAdapterType {
132
137
  * @param options - Query options including filters, sorting, and pagination
133
138
  * @returns Promise resolving to DatabaseResult containing paginated data
134
139
  */
135
- findMany<T>(table: string, options?: QueryOptions): Promise<DatabaseResult<PaginatedResult<T>>>;
140
+ findMany<T extends Record<string, unknown>>(table: string, options?: QueryOptions<T>): Promise<DatabaseResult<PaginatedResult<T>>>;
136
141
  /**
137
142
  * Create a new record
138
143
  * @param table - Table name
139
144
  * @param data - Record data to create
140
145
  * @returns Promise resolving to DatabaseResult containing the created record
141
146
  */
142
- create<T>(table: string, data: T): Promise<DatabaseResult<T>>;
147
+ create<T extends Record<string, unknown>>(table: string, data: T): Promise<DatabaseResult<T>>;
143
148
  /**
144
149
  * Update an existing record
145
150
  * @param table - Table name
@@ -174,10 +179,15 @@ export interface DatabaseAdapterType {
174
179
  * @param filter - Filter conditions
175
180
  * @returns Promise resolving to DatabaseResult containing the count
176
181
  */
177
- count(table: string, filter?: Filter): Promise<DatabaseResult<number>>;
182
+ count<T extends Record<string, unknown> = Record<string, unknown>>(table: string, filter?: Filter<T>): Promise<DatabaseResult<number>>;
178
183
  /**
179
184
  * Perform health check on the database connection
180
185
  * @returns Promise resolving to DatabaseResult containing health status
181
186
  */
182
187
  healthCheck(): Promise<DatabaseResult<DatabaseHealthStatus>>;
188
+ /**
189
+ * Reference to the underlying adapter (for extension/decorator adapters)
190
+ * Used to unwrap nested adapters to access the base adapter
191
+ */
192
+ baseAdapter?: DatabaseAdapterType;
183
193
  }
@@ -8,6 +8,7 @@ import type { OperationConfig } from './features-config.types';
8
8
  import type { DatabaseEvent } from './event.types';
9
9
  import type { PaginatedResult } from './databsePagination';
10
10
  import type { AuditContext } from './audit.types';
11
+ import type { DatabaseAdapterType } from './databaseAdapter';
11
12
  /**
12
13
  * Table name type - centralized table constants
13
14
  */
@@ -90,15 +91,15 @@ export interface DatabaseServiceInterface {
90
91
  * @param config - Optional per-operation configuration overrides
91
92
  * @returns Promise resolving to the record or null
92
93
  */
93
- get<T>(table: TableName, id: string, config?: OperationConfig): Promise<DatabaseResult<T | null>>;
94
+ get<T extends Record<string, unknown>>(table: TableName, id: string, config?: OperationConfig): Promise<DatabaseResult<T | null>>;
94
95
  /**
95
96
  * List records with optional filtering, sorting, and pagination
96
97
  * @param table - Table name
97
- * @param options - Query options
98
+ * @param options - Query options with type-safe fields
98
99
  * @param config - Optional per-operation configuration overrides
99
100
  * @returns Promise resolving to paginated results
100
101
  */
101
- list<T>(table: TableName, options?: QueryOptions, config?: OperationConfig): Promise<DatabaseResult<PaginatedResult<T>>>;
102
+ list<T extends Record<string, unknown>>(table: TableName, options?: QueryOptions<T>, config?: OperationConfig): Promise<DatabaseResult<PaginatedResult<T>>>;
102
103
  /**
103
104
  * Create a new record
104
105
  * @param table - Table name
@@ -106,7 +107,7 @@ export interface DatabaseServiceInterface {
106
107
  * @param config - Optional per-operation configuration overrides
107
108
  * @returns Promise resolving to the created record
108
109
  */
109
- create<T>(table: TableName, input: CreateInput<T>, config?: OperationConfig): Promise<DatabaseResult<T>>;
110
+ create<T extends Record<string, unknown>>(table: TableName, input: CreateInput<T>, config?: OperationConfig): Promise<DatabaseResult<T>>;
110
111
  /**
111
112
  * Update an existing record
112
113
  * @param table - Table name
@@ -115,7 +116,7 @@ export interface DatabaseServiceInterface {
115
116
  * @param config - Optional per-operation configuration overrides
116
117
  * @returns Promise resolving to the updated record
117
118
  */
118
- update<T>(table: TableName, id: string, input: UpdateInput<T>, config?: OperationConfig): Promise<DatabaseResult<T>>;
119
+ update<T extends Record<string, unknown>>(table: TableName, id: string, input: UpdateInput<T>, config?: OperationConfig): Promise<DatabaseResult<T>>;
119
120
  /**
120
121
  * Delete a record
121
122
  * @param table - Table name
@@ -131,7 +132,7 @@ export interface DatabaseServiceInterface {
131
132
  * @param config - Optional per-operation configuration overrides
132
133
  * @returns Promise resolving to array of created records
133
134
  */
134
- batchCreate<T>(table: TableName, inputs: CreateInput<T>[], config?: OperationConfig): Promise<DatabaseResult<T[]>>;
135
+ batchCreate<T extends Record<string, unknown>>(table: TableName, inputs: CreateInput<T>[], config?: OperationConfig): Promise<DatabaseResult<T[]>>;
135
136
  /**
136
137
  * Update multiple records in a batch
137
138
  * @param table - Table name
@@ -139,7 +140,7 @@ export interface DatabaseServiceInterface {
139
140
  * @param config - Optional per-operation configuration overrides
140
141
  * @returns Promise resolving to array of updated records
141
142
  */
142
- batchUpdate<T>(table: TableName, updates: BatchUpdate<T>[], config?: OperationConfig): Promise<DatabaseResult<T[]>>;
143
+ batchUpdate<T extends Record<string, unknown>>(table: TableName, updates: BatchUpdate<T>[], config?: OperationConfig): Promise<DatabaseResult<T[]>>;
143
144
  /**
144
145
  * Delete multiple records in a batch
145
146
  * @param table - Table name
@@ -151,27 +152,27 @@ export interface DatabaseServiceInterface {
151
152
  /**
152
153
  * Execute a complex query with filters, sorting, and pagination
153
154
  * @param table - Table name
154
- * @param query - Query configuration
155
+ * @param query - Query configuration with type-safe fields
155
156
  * @param config - Optional per-operation configuration overrides
156
157
  * @returns Promise resolving to paginated results
157
158
  */
158
- query<T>(table: TableName, query: QueryOptions, config?: OperationConfig): Promise<DatabaseResult<PaginatedResult<T>>>;
159
+ query<T extends Record<string, unknown>>(table: TableName, query: QueryOptions<T>, config?: OperationConfig): Promise<DatabaseResult<PaginatedResult<T>>>;
159
160
  /**
160
161
  * Count records matching a filter
161
162
  * @param table - Table name
162
- * @param filter - Optional filter conditions
163
+ * @param filter - Optional filter conditions with type-safe fields
163
164
  * @param config - Optional per-operation configuration overrides
164
165
  * @returns Promise resolving to the count
165
166
  */
166
- count(table: TableName, filter?: Filter, config?: OperationConfig): Promise<DatabaseResult<number>>;
167
+ count<T extends Record<string, unknown> = Record<string, unknown>>(table: TableName, filter?: Filter<T>, config?: OperationConfig): Promise<DatabaseResult<number>>;
167
168
  /**
168
169
  * Find a single record by filter conditions
169
170
  * @param table - Table name
170
- * @param filter - Filter conditions
171
+ * @param filter - Filter conditions with type-safe fields
171
172
  * @param config - Optional per-operation configuration overrides
172
173
  * @returns Promise resolving to the first matching record or null
173
174
  */
174
- findOne<T>(table: TableName, filter: Filter, config?: OperationConfig): Promise<DatabaseResult<T | null>>;
175
+ findOne<T extends Record<string, unknown>>(table: TableName, filter: Filter<T>, config?: OperationConfig): Promise<DatabaseResult<T | null>>;
175
176
  /**
176
177
  * Soft delete a record (logical deletion)
177
178
  * @param table - Table name
@@ -219,43 +220,15 @@ export interface DatabaseServiceInterface {
219
220
  * @returns Current service status information
220
221
  */
221
222
  getStatus(): ServiceStatus;
222
- }
223
- /**
224
- * Legacy interface for backward compatibility
225
- * @deprecated Use DatabaseService instead
226
- */
227
- export interface DatabaseServiceType extends DatabaseServiceInterface {
228
- /**
229
- * @deprecated Use get() instead
230
- */
231
- findById<T>(table: string, id: string): Promise<DatabaseResult<T | null>>;
232
- /**
233
- * @deprecated Use list() instead
234
- */
235
- findMany<T>(table: string, options?: QueryOptions): Promise<DatabaseResult<PaginatedResult<T>>>;
236
223
  /**
237
- * Initialize the database service
238
- * @deprecated Initialization is handled by factory
224
+ * Close the database connection
225
+ * Gracefully shuts down the connection and releases resources.
226
+ * @returns Promise resolving to DatabaseResult indicating success or failure
239
227
  */
240
- initialize(): Promise<DatabaseResult<void>>;
228
+ close(): Promise<DatabaseResult<void>>;
241
229
  /**
242
- * Register a table with the adapter
243
- * @deprecated Tables are registered automatically
244
- */
245
- registerTable<T>(name: string, table: T, idColumn?: keyof T): void;
246
- /**
247
- * Check if a record exists
248
- * @deprecated Use count() with filter instead
249
- */
250
- exists(table: string, id: string): Promise<DatabaseResult<boolean>>;
251
- /**
252
- * Find a single record by filter conditions
253
- * @deprecated Use findOne() from main interface instead
254
- */
255
- findOne<T>(table: string, filter: Filter): Promise<DatabaseResult<T | null>>;
256
- /**
257
- * Soft delete a record (logical deletion)
258
- * @deprecated Use softDelete() from main interface instead
230
+ * The underlying database adapter
231
+ * Used for direct adapter access when needed (e.g., CLI operations)
259
232
  */
260
- softDelete(table: string, id: string): Promise<DatabaseResult<void>>;
233
+ adapter: DatabaseAdapterType;
261
234
  }