@plyaz/types 1.13.10 → 1.13.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.cjs +5241 -508
- package/dist/api/index.cjs.map +1 -1
- package/dist/db/audit.types.d.ts +24 -0
- package/dist/db/backup.types.d.ts +54 -0
- package/dist/db/database.types.d.ts +132 -36
- package/dist/db/databsePagination.d.ts +46 -0
- package/dist/db/features-config.types.d.ts +2 -28
- package/dist/db/index.cjs +10 -0
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.d.ts +6 -4
- package/dist/db/index.js +10 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/replica.types.d.ts +26 -0
- package/dist/db/replicaStrategy.d.ts +13 -0
- package/dist/db/shard.d.ts +28 -0
- package/dist/errors/index.cjs +5301 -566
- package/dist/errors/index.cjs.map +1 -1
- package/dist/index.cjs +1149 -603
- package/dist/index.cjs.map +1 -1
- package/package.json +1 -1
- package/dist/db/DatabaseAdapter.d.ts +0 -182
- package/dist/db/DatabaseService.d.ts +0 -268
- package/dist/db/EventEmitter.d.ts +0 -68
- package/dist/db/config.types.d.ts +0 -57
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit context for tracking user actions
|
|
3
|
+
*/
|
|
4
|
+
export interface AuditContext {
|
|
5
|
+
userId?: string;
|
|
6
|
+
requestId?: string;
|
|
7
|
+
ipAddress?: string;
|
|
8
|
+
userAgent?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AuditEvent {
|
|
11
|
+
operation: string;
|
|
12
|
+
table: string;
|
|
13
|
+
recordId?: string;
|
|
14
|
+
userId?: string;
|
|
15
|
+
requestId?: string;
|
|
16
|
+
changes: {
|
|
17
|
+
before?: Record<string, string | number | boolean | Date>;
|
|
18
|
+
after?: Record<string, string | number | boolean | Date>;
|
|
19
|
+
fields?: string[];
|
|
20
|
+
};
|
|
21
|
+
timestamp: Date;
|
|
22
|
+
ipAddress?: string;
|
|
23
|
+
userAgent?: string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for backup service.
|
|
3
|
+
*/
|
|
4
|
+
export interface BackupConfig {
|
|
5
|
+
/** Database connection string */
|
|
6
|
+
connectionString: string;
|
|
7
|
+
/** Directory to store backup files */
|
|
8
|
+
backupDir: string;
|
|
9
|
+
/** Number of days to retain backups */
|
|
10
|
+
retentionDays: number;
|
|
11
|
+
/** Cron expression for scheduled backups */
|
|
12
|
+
schedule?: string;
|
|
13
|
+
/** Whether to compress backup files */
|
|
14
|
+
compression?: boolean;
|
|
15
|
+
/** Encryption configuration */
|
|
16
|
+
encryption?: {
|
|
17
|
+
/** Whether encryption is enabled */
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
/** Encryption key */
|
|
20
|
+
key: string;
|
|
21
|
+
};
|
|
22
|
+
/** S3 configuration for cloud storage */
|
|
23
|
+
s3?: {
|
|
24
|
+
/** Whether S3 upload is enabled */
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
/** S3 bucket name */
|
|
27
|
+
bucket: string;
|
|
28
|
+
/** AWS region */
|
|
29
|
+
region: string;
|
|
30
|
+
/** AWS access key */
|
|
31
|
+
accessKey: string;
|
|
32
|
+
/** AWS secret key */
|
|
33
|
+
secretKey: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Information about a backup file.
|
|
38
|
+
*/
|
|
39
|
+
export interface BackupInfo {
|
|
40
|
+
/** Unique backup identifier */
|
|
41
|
+
id: string;
|
|
42
|
+
/** Backup filename */
|
|
43
|
+
filename: string;
|
|
44
|
+
/** Backup file size in bytes */
|
|
45
|
+
size: number;
|
|
46
|
+
/** When the backup was created */
|
|
47
|
+
createdAt: Date;
|
|
48
|
+
/** When the backup expires */
|
|
49
|
+
expiresAt: Date;
|
|
50
|
+
/** Backup status */
|
|
51
|
+
status: 'created' | 'uploading' | 'uploaded' | 'failed';
|
|
52
|
+
/** Backup location */
|
|
53
|
+
location: 'local' | 's3';
|
|
54
|
+
}
|
|
@@ -51,10 +51,8 @@
|
|
|
51
51
|
* console.error('Error:', result.error.message);
|
|
52
52
|
* }
|
|
53
53
|
* ```
|
|
54
|
-
*
|
|
55
|
-
* @author Plyaz Engineering Team
|
|
56
|
-
* @since 1.0.0
|
|
57
54
|
*/
|
|
55
|
+
import type { PaginationOptions } from "./databsePagination";
|
|
58
56
|
/**
|
|
59
57
|
* Input type for creating records
|
|
60
58
|
*/
|
|
@@ -105,39 +103,6 @@ export interface SortOptions<TRecord extends object = object> {
|
|
|
105
103
|
/** Sort direction */
|
|
106
104
|
direction: 'asc' | 'desc';
|
|
107
105
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Pagination options for queries
|
|
110
|
-
*/
|
|
111
|
-
export interface PaginationOptions {
|
|
112
|
-
/** Number of items to return */
|
|
113
|
-
limit?: number;
|
|
114
|
-
/** Number of items to skip */
|
|
115
|
-
offset?: number;
|
|
116
|
-
/** Cursor for cursor-based pagination */
|
|
117
|
-
cursor?: string;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Paginated result type
|
|
121
|
-
*/
|
|
122
|
-
export interface PaginatedResult<T> {
|
|
123
|
-
/** Array of results */
|
|
124
|
-
data: T[];
|
|
125
|
-
/** Total count of items */
|
|
126
|
-
total: number;
|
|
127
|
-
/** Pagination metadata */
|
|
128
|
-
pagination: {
|
|
129
|
-
/** Current page number */
|
|
130
|
-
page?: number;
|
|
131
|
-
/** Number of items per page */
|
|
132
|
-
limit?: number;
|
|
133
|
-
/** Total number of pages */
|
|
134
|
-
totalPages?: number;
|
|
135
|
-
/** Next cursor for cursor-based pagination */
|
|
136
|
-
nextCursor?: string;
|
|
137
|
-
/** Previous cursor for cursor-based pagination */
|
|
138
|
-
prevCursor?: string;
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
106
|
/**
|
|
142
107
|
* Database health status
|
|
143
108
|
*/
|
|
@@ -160,3 +125,134 @@ export interface DatabaseResult<T> {
|
|
|
160
125
|
/** The error if unsuccessful */
|
|
161
126
|
error?: Error | null;
|
|
162
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Options for the @Cacheable decorator.
|
|
130
|
+
*/
|
|
131
|
+
export interface CacheableOptions {
|
|
132
|
+
/** Time to live in seconds */
|
|
133
|
+
ttl?: number;
|
|
134
|
+
/** Custom cache key (auto-generated if not specified) */
|
|
135
|
+
key?: string;
|
|
136
|
+
/** Condition function to determine if result should be cached */
|
|
137
|
+
condition?: <T>(result: T) => boolean;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Options for the @CacheEvict decorator.
|
|
141
|
+
*/
|
|
142
|
+
export interface CacheEvictOptions {
|
|
143
|
+
/** Specific cache key to evict */
|
|
144
|
+
key?: string;
|
|
145
|
+
/** Cache pattern to evict (e.g., 'users:*') */
|
|
146
|
+
pattern?: string;
|
|
147
|
+
/** Whether to evict all cache entries */
|
|
148
|
+
allEntries?: boolean;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Configuration options for dynamic connection pool.
|
|
152
|
+
*/
|
|
153
|
+
export interface DynamicPoolConfig {
|
|
154
|
+
/** Minimum number of connections in the pool */
|
|
155
|
+
min: number;
|
|
156
|
+
/** Maximum number of connections in the pool */
|
|
157
|
+
max: number;
|
|
158
|
+
/** Time in milliseconds after which idle connections are closed */
|
|
159
|
+
idleTimeoutMillis: number;
|
|
160
|
+
/** Time in milliseconds to wait for a connection to become available */
|
|
161
|
+
acquireTimeoutMillis: number;
|
|
162
|
+
/** Auto-scaling configuration */
|
|
163
|
+
scaling: {
|
|
164
|
+
/** Whether auto-scaling is enabled */
|
|
165
|
+
enabled: boolean;
|
|
166
|
+
/** Percentage threshold for scaling up (default: 80) */
|
|
167
|
+
scaleUpThreshold: number;
|
|
168
|
+
/** Percentage threshold for scaling down (default: 20) */
|
|
169
|
+
scaleDownThreshold: number;
|
|
170
|
+
/** Interval in milliseconds for scaling checks (default: 30000) */
|
|
171
|
+
scaleInterval: number;
|
|
172
|
+
/** Maximum number of connections to add/remove at once */
|
|
173
|
+
maxScale: number;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Database alert with detailed information.
|
|
178
|
+
*/
|
|
179
|
+
export interface Alert {
|
|
180
|
+
/** Unique alert identifier */
|
|
181
|
+
id: string;
|
|
182
|
+
/** Alert message */
|
|
183
|
+
message: string;
|
|
184
|
+
/** Alert severity level */
|
|
185
|
+
severity: 'info' | 'warning' | 'error' | 'critical';
|
|
186
|
+
/** When the alert was triggered */
|
|
187
|
+
timestamp: Date;
|
|
188
|
+
/** Whether the alert has been resolved */
|
|
189
|
+
resolved: boolean;
|
|
190
|
+
/** When the alert was resolved (if applicable) */
|
|
191
|
+
resolvedAt?: Date;
|
|
192
|
+
/** Source of the alert */
|
|
193
|
+
source: 'database' | 'pool' | 'replica' | 'cache' | 'backup';
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Rule for generating alerts based on metrics.
|
|
197
|
+
*/
|
|
198
|
+
export interface AlertRule {
|
|
199
|
+
/** Unique rule identifier */
|
|
200
|
+
id: string;
|
|
201
|
+
/** Condition function that returns true if alert should be triggered */
|
|
202
|
+
condition: (metrics: Record<string, object>) => boolean;
|
|
203
|
+
/** Function that generates alert message */
|
|
204
|
+
message: (metrics: Record<string, object>) => string;
|
|
205
|
+
/** Alert severity level */
|
|
206
|
+
severity: 'info' | 'warning' | 'error' | 'critical';
|
|
207
|
+
/** Alert source category */
|
|
208
|
+
source: 'database' | 'pool' | 'replica' | 'cache' | 'backup';
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Metrics collected for database queries.
|
|
212
|
+
*/
|
|
213
|
+
export interface QueryMetrics {
|
|
214
|
+
/** SQL query string */
|
|
215
|
+
query: string;
|
|
216
|
+
/** Query execution time in milliseconds */
|
|
217
|
+
duration: number;
|
|
218
|
+
/** Timestamp when query was executed */
|
|
219
|
+
timestamp: Date;
|
|
220
|
+
/** Whether query was successful */
|
|
221
|
+
success: boolean;
|
|
222
|
+
/** Error message if query failed */
|
|
223
|
+
error?: string;
|
|
224
|
+
/** Database table name */
|
|
225
|
+
table?: string;
|
|
226
|
+
/** Database operation type */
|
|
227
|
+
operation?: string;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Metrics collected for connection pool.
|
|
231
|
+
*/
|
|
232
|
+
export interface PoolMetrics {
|
|
233
|
+
totalReleased: number;
|
|
234
|
+
totalAcquired: number;
|
|
235
|
+
/** Total number of connections */
|
|
236
|
+
totalConnections: number;
|
|
237
|
+
/** Number of active connections */
|
|
238
|
+
activeConnections: number;
|
|
239
|
+
/** Number of idle connections */
|
|
240
|
+
idleConnections: number;
|
|
241
|
+
/** Number of requests waiting for connections */
|
|
242
|
+
waitingRequests: number;
|
|
243
|
+
/** Average time to acquire a connection */
|
|
244
|
+
averageAcquisitionTime: number;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Information about the current tenant.
|
|
248
|
+
*/
|
|
249
|
+
export interface TenantInfo {
|
|
250
|
+
/** Unique tenant identifier */
|
|
251
|
+
id: string;
|
|
252
|
+
/** Tenant display name */
|
|
253
|
+
name: string;
|
|
254
|
+
/** Database schema for the tenant (optional) */
|
|
255
|
+
schema?: string;
|
|
256
|
+
/** Tenant role for permissions (optional) */
|
|
257
|
+
role?: string;
|
|
258
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pagination options for queries
|
|
3
|
+
*/
|
|
4
|
+
export interface PaginationOptions {
|
|
5
|
+
/** Number of items to return */
|
|
6
|
+
limit?: number;
|
|
7
|
+
/** Number of items to skip */
|
|
8
|
+
offset?: number;
|
|
9
|
+
/** Cursor for cursor-based pagination */
|
|
10
|
+
cursor?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Paginated result type
|
|
14
|
+
*/
|
|
15
|
+
export interface PaginatedResult<T> {
|
|
16
|
+
/** Array of results */
|
|
17
|
+
data: T[];
|
|
18
|
+
/** Total count of items */
|
|
19
|
+
total: number;
|
|
20
|
+
/** Pagination metadata */
|
|
21
|
+
pagination: {
|
|
22
|
+
/** Current page number */
|
|
23
|
+
page?: number;
|
|
24
|
+
/** Number of items per page */
|
|
25
|
+
limit?: number;
|
|
26
|
+
/** Total number of pages */
|
|
27
|
+
totalPages?: number;
|
|
28
|
+
/** Next cursor for cursor-based pagination */
|
|
29
|
+
nextCursor?: string;
|
|
30
|
+
/** Previous cursor for cursor-based pagination */
|
|
31
|
+
prevCursor?: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Pagination information
|
|
36
|
+
*/
|
|
37
|
+
export interface PaginationInfo {
|
|
38
|
+
/** Current page number */
|
|
39
|
+
page?: number;
|
|
40
|
+
/** Number of items per page */
|
|
41
|
+
limit?: number;
|
|
42
|
+
/** Number of items skipped (offset) */
|
|
43
|
+
offset: number;
|
|
44
|
+
/** Total number of pages */
|
|
45
|
+
totalPages?: number;
|
|
46
|
+
}
|
|
@@ -69,6 +69,8 @@
|
|
|
69
69
|
* };
|
|
70
70
|
* ```
|
|
71
71
|
*/
|
|
72
|
+
import type { AuditEvent } from "./audit.types";
|
|
73
|
+
import type { ReadReplicaConfig } from "./replica.types";
|
|
72
74
|
/**
|
|
73
75
|
* Configuration for soft delete functionality
|
|
74
76
|
*/
|
|
@@ -136,19 +138,6 @@ export interface DBCacheConfig {
|
|
|
136
138
|
/** Cache invalidation strategy */
|
|
137
139
|
invalidation?: 'write' | 'ttl' | 'manual';
|
|
138
140
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Configuration for read replicas
|
|
141
|
-
*/
|
|
142
|
-
export interface ReadReplicaConfig {
|
|
143
|
-
/** Whether read replicas are enabled */
|
|
144
|
-
enabled: boolean;
|
|
145
|
-
/** Replica connection configs */
|
|
146
|
-
replicas: AdapterConfig[];
|
|
147
|
-
/** Load balancing strategy */
|
|
148
|
-
strategy?: 'round-robin' | 'random' | 'least-connections';
|
|
149
|
-
/** Fallback to primary if all replicas unhealthy */
|
|
150
|
-
fallbackToPrimary?: boolean;
|
|
151
|
-
}
|
|
152
141
|
/**
|
|
153
142
|
* Connection pool configuration
|
|
154
143
|
*/
|
|
@@ -207,21 +196,6 @@ export interface AfterReadEvent {
|
|
|
207
196
|
duration: number;
|
|
208
197
|
timestamp: Date;
|
|
209
198
|
}
|
|
210
|
-
export interface AuditEvent {
|
|
211
|
-
operation: string;
|
|
212
|
-
table: string;
|
|
213
|
-
recordId?: string;
|
|
214
|
-
userId?: string;
|
|
215
|
-
requestId?: string;
|
|
216
|
-
changes: {
|
|
217
|
-
before?: Record<string, string | number | boolean | Date>;
|
|
218
|
-
after?: Record<string, string | number | boolean | Date>;
|
|
219
|
-
fields?: string[];
|
|
220
|
-
};
|
|
221
|
-
timestamp: Date;
|
|
222
|
-
ipAddress?: string;
|
|
223
|
-
userAgent?: string;
|
|
224
|
-
}
|
|
225
199
|
/**
|
|
226
200
|
* Adapter-specific configuration types
|
|
227
201
|
*/
|
package/dist/db/index.cjs
CHANGED
|
@@ -11,6 +11,16 @@ var ADAPTERS = /* @__PURE__ */ ((ADAPTERS2) => {
|
|
|
11
11
|
return ADAPTERS2;
|
|
12
12
|
})(ADAPTERS || {});
|
|
13
13
|
|
|
14
|
+
// src/db/replicaStrategy.ts
|
|
15
|
+
var REPLICA_STRATEGY = /* @__PURE__ */ ((REPLICA_STRATEGY2) => {
|
|
16
|
+
REPLICA_STRATEGY2["PRIMARY"] = "primary";
|
|
17
|
+
REPLICA_STRATEGY2["REPLICA"] = "replica";
|
|
18
|
+
REPLICA_STRATEGY2["CLOSEST"] = "closest";
|
|
19
|
+
REPLICA_STRATEGY2["FASTEST"] = "fastest";
|
|
20
|
+
return REPLICA_STRATEGY2;
|
|
21
|
+
})(REPLICA_STRATEGY || {});
|
|
22
|
+
|
|
14
23
|
exports.ADAPTERS = ADAPTERS;
|
|
24
|
+
exports.REPLICA_STRATEGY = REPLICA_STRATEGY;
|
|
15
25
|
//# sourceMappingURL=index.cjs.map
|
|
16
26
|
//# sourceMappingURL=index.cjs.map
|
package/dist/db/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/db/adapter.ts"],"names":["ADAPTERS"],"mappings":";;;;;AAiFO,IAAK,QAAA,qBAAAA,SAAAA,KAAL;AAEL,EAAAA,UAAA,UAAA,CAAA,GAAW,UAAA;AAGX,EAAAA,UAAA,SAAA,CAAA,GAAU,SAAA;AAGV,EAAAA,UAAA,UAAA,CAAA,GAAW,UAAA;AAGX,EAAAA,UAAA,KAAA,CAAA,GAAM,KAAA;AAXI,EAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA","file":"index.cjs","sourcesContent":["/**\n * @fileoverview Database adapter type definitions\n *\n * Defines the enumeration of supported database adapter types used throughout\n * the database package. This enum provides type-safe identification of different\n * database integrations and is used in configuration, factory methods, and\n * adapter selection logic.\n *\n * **Application Flow Context:**\n * ```\n * Configuration → ADAPTERS Enum → AdapterFactory → Concrete Adapter\n * ↓ ↓ ↓ ↓\n * User Config → Type Safety → Adapter Creation → Database Connection\n * ```\n *\n * **Adapter Types:**\n * - **DRIZZLE**: Type-safe ORM with excellent TypeScript support\n * - **SUPABASE**: Hosted PostgreSQL with real-time capabilities\n * - **SQL**: Raw SQL execution for maximum control\n * - **DATABASE**: Generic fallback adapter\n *\n * @example\n * ```typescript\n * // Adapter selection in configuration\n * const config = {\n * adapter: ADAPTERS.DRIZZLE,\n * connectionString: process.env.DATABASE_URL\n * };\n *\n * // Type-safe adapter factory usage\n * const adapter = AdapterFactory.create(ADAPTERS.SUPABASE, supabaseConfig);\n *\n * // Switch statement with exhaustive checking\n * switch (config.adapter) {\n * case ADAPTERS.DRIZZLE:\n * // Handle Drizzle-specific logic\n * break;\n * case ADAPTERS.SUPABASE:\n * // Handle Supabase-specific logic\n * break;\n * case ADAPTERS.SQL:\n * // Handle SQL-specific logic\n * break;\n * default:\n * // TypeScript ensures all cases are handled\n * throw new Error(`Unsupported adapter: ${config.adapter}`);\n * }\n * ```\n *\n */\n/**\n * @enum ADAPTERS\n * @description\n * Enumeration of supported database adapter types.\n *\n * This enum provides type-safe identification of different database integrations\n * and is used throughout the package for configuration, factory methods, and\n * adapter selection. Each adapter type represents a different approach to\n * database connectivity and operations.\n *\n * **Adapter Characteristics:**\n * - **DATABASE**: Generic fallback, minimal functionality\n * - **DRIZZLE**: Full ORM with type safety and query building\n * - **SUPABASE**: Hosted solution with real-time and auth features\n * - **SQL**: Raw SQL for performance-critical applications\n *\n * @example\n * ```typescript\n * // Configuration with adapter selection\n * const configs = {\n * development: { adapter: ADAPTERS.DRIZZLE },\n * production: { adapter: ADAPTERS.SUPABASE },\n * performance: { adapter: ADAPTERS.SQL }\n * };\n *\n * // Type-safe adapter validation\n * function validateAdapter(adapter: ADAPTERS): boolean {\n * return Object.values(ADAPTERS).includes(adapter);\n * }\n * ```\n */\nexport enum ADAPTERS {\n /** Generic database adapter (default when no specific integration is set) */\n DATABASE = 'database',\n\n /** Drizzle ORM adapter (PostgreSQL, MySQL, SQLite, etc.) */\n DRIZZLE = 'drizzle',\n\n /** Supabase adapter (PostgreSQL backend with REST + Realtime APIs) */\n SUPABASE = 'supabase',\n\n /** Raw SQL adapter (direct database queries without ORM) */\n SQL = 'sql',\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/db/adapter.ts","../../src/db/replicaStrategy.ts"],"names":["ADAPTERS","REPLICA_STRATEGY"],"mappings":";;;;;AAiFO,IAAK,QAAA,qBAAAA,SAAAA,KAAL;AAEL,EAAAA,UAAA,UAAA,CAAA,GAAW,UAAA;AAGX,EAAAA,UAAA,SAAA,CAAA,GAAU,SAAA;AAGV,EAAAA,UAAA,UAAA,CAAA,GAAW,UAAA;AAGX,EAAAA,UAAA,KAAA,CAAA,GAAM,KAAA;AAXI,EAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;;;AC9EL,IAAK,gBAAA,qBAAAC,iBAAAA,KAAL;AAEL,EAAAA,kBAAA,SAAA,CAAA,GAAU,SAAA;AAEV,EAAAA,kBAAA,SAAA,CAAA,GAAU,SAAA;AAEV,EAAAA,kBAAA,SAAA,CAAA,GAAU,SAAA;AAEV,EAAAA,kBAAA,SAAA,CAAA,GAAU,SAAA;AARA,EAAA,OAAAA,iBAAAA;AAAA,CAAA,EAAA,gBAAA,IAAA,EAAA","file":"index.cjs","sourcesContent":["/**\n * @fileoverview Database adapter type definitions\n *\n * Defines the enumeration of supported database adapter types used throughout\n * the database package. This enum provides type-safe identification of different\n * database integrations and is used in configuration, factory methods, and\n * adapter selection logic.\n *\n * **Application Flow Context:**\n * ```\n * Configuration → ADAPTERS Enum → AdapterFactory → Concrete Adapter\n * ↓ ↓ ↓ ↓\n * User Config → Type Safety → Adapter Creation → Database Connection\n * ```\n *\n * **Adapter Types:**\n * - **DRIZZLE**: Type-safe ORM with excellent TypeScript support\n * - **SUPABASE**: Hosted PostgreSQL with real-time capabilities\n * - **SQL**: Raw SQL execution for maximum control\n * - **DATABASE**: Generic fallback adapter\n *\n * @example\n * ```typescript\n * // Adapter selection in configuration\n * const config = {\n * adapter: ADAPTERS.DRIZZLE,\n * connectionString: process.env.DATABASE_URL\n * };\n *\n * // Type-safe adapter factory usage\n * const adapter = AdapterFactory.create(ADAPTERS.SUPABASE, supabaseConfig);\n *\n * // Switch statement with exhaustive checking\n * switch (config.adapter) {\n * case ADAPTERS.DRIZZLE:\n * // Handle Drizzle-specific logic\n * break;\n * case ADAPTERS.SUPABASE:\n * // Handle Supabase-specific logic\n * break;\n * case ADAPTERS.SQL:\n * // Handle SQL-specific logic\n * break;\n * default:\n * // TypeScript ensures all cases are handled\n * throw new Error(`Unsupported adapter: ${config.adapter}`);\n * }\n * ```\n *\n */\n/**\n * @enum ADAPTERS\n * @description\n * Enumeration of supported database adapter types.\n *\n * This enum provides type-safe identification of different database integrations\n * and is used throughout the package for configuration, factory methods, and\n * adapter selection. Each adapter type represents a different approach to\n * database connectivity and operations.\n *\n * **Adapter Characteristics:**\n * - **DATABASE**: Generic fallback, minimal functionality\n * - **DRIZZLE**: Full ORM with type safety and query building\n * - **SUPABASE**: Hosted solution with real-time and auth features\n * - **SQL**: Raw SQL for performance-critical applications\n *\n * @example\n * ```typescript\n * // Configuration with adapter selection\n * const configs = {\n * development: { adapter: ADAPTERS.DRIZZLE },\n * production: { adapter: ADAPTERS.SUPABASE },\n * performance: { adapter: ADAPTERS.SQL }\n * };\n *\n * // Type-safe adapter validation\n * function validateAdapter(adapter: ADAPTERS): boolean {\n * return Object.values(ADAPTERS).includes(adapter);\n * }\n * ```\n */\nexport enum ADAPTERS {\n /** Generic database adapter (default when no specific integration is set) */\n DATABASE = 'database',\n\n /** Drizzle ORM adapter (PostgreSQL, MySQL, SQLite, etc.) */\n DRIZZLE = 'drizzle',\n\n /** Supabase adapter (PostgreSQL backend with REST + Realtime APIs) */\n SUPABASE = 'supabase',\n\n /** Raw SQL adapter (direct database queries without ORM) */\n SQL = 'sql',\n}\n","/**\n * Strategy options for replica selection.\n */\nexport enum REPLICA_STRATEGY {\n /** Always use primary database */\n PRIMARY = 'primary',\n /** Use any available replica */\n REPLICA = 'replica',\n /** Use geographically closest replica */\n CLOSEST = 'closest',\n /** Use fastest responding replica */\n FASTEST = 'fastest'\n}"]}
|
package/dist/db/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export type * from './DatabaseService';
|
|
2
|
-
export type * from './EventEmitter';
|
|
3
|
-
export type * from './config.types';
|
|
4
|
-
export type * from './DatabaseAdapter';
|
|
5
1
|
export type * from './features-config.types';
|
|
6
2
|
export type * from './database.types';
|
|
7
3
|
export * from './adapter';
|
|
8
4
|
export type * from './Transaction';
|
|
9
5
|
export type * from './event.types';
|
|
6
|
+
export * from './replicaStrategy';
|
|
7
|
+
export type * from './databsePagination';
|
|
8
|
+
export type * from './shard';
|
|
9
|
+
export type * from './audit.types';
|
|
10
|
+
export type * from './backup.types';
|
|
11
|
+
export type * from './replica.types';
|
package/dist/db/index.js
CHANGED
|
@@ -9,6 +9,15 @@ var ADAPTERS = /* @__PURE__ */ ((ADAPTERS2) => {
|
|
|
9
9
|
return ADAPTERS2;
|
|
10
10
|
})(ADAPTERS || {});
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
// src/db/replicaStrategy.ts
|
|
13
|
+
var REPLICA_STRATEGY = /* @__PURE__ */ ((REPLICA_STRATEGY2) => {
|
|
14
|
+
REPLICA_STRATEGY2["PRIMARY"] = "primary";
|
|
15
|
+
REPLICA_STRATEGY2["REPLICA"] = "replica";
|
|
16
|
+
REPLICA_STRATEGY2["CLOSEST"] = "closest";
|
|
17
|
+
REPLICA_STRATEGY2["FASTEST"] = "fastest";
|
|
18
|
+
return REPLICA_STRATEGY2;
|
|
19
|
+
})(REPLICA_STRATEGY || {});
|
|
20
|
+
|
|
21
|
+
export { ADAPTERS, REPLICA_STRATEGY };
|
|
13
22
|
//# sourceMappingURL=index.js.map
|
|
14
23
|
//# sourceMappingURL=index.js.map
|
package/dist/db/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/db/adapter.ts"],"names":["ADAPTERS"],"mappings":";;;AAiFO,IAAK,QAAA,qBAAAA,SAAAA,KAAL;AAEL,EAAAA,UAAA,UAAA,CAAA,GAAW,UAAA;AAGX,EAAAA,UAAA,SAAA,CAAA,GAAU,SAAA;AAGV,EAAAA,UAAA,UAAA,CAAA,GAAW,UAAA;AAGX,EAAAA,UAAA,KAAA,CAAA,GAAM,KAAA;AAXI,EAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA","file":"index.js","sourcesContent":["/**\n * @fileoverview Database adapter type definitions\n *\n * Defines the enumeration of supported database adapter types used throughout\n * the database package. This enum provides type-safe identification of different\n * database integrations and is used in configuration, factory methods, and\n * adapter selection logic.\n *\n * **Application Flow Context:**\n * ```\n * Configuration → ADAPTERS Enum → AdapterFactory → Concrete Adapter\n * ↓ ↓ ↓ ↓\n * User Config → Type Safety → Adapter Creation → Database Connection\n * ```\n *\n * **Adapter Types:**\n * - **DRIZZLE**: Type-safe ORM with excellent TypeScript support\n * - **SUPABASE**: Hosted PostgreSQL with real-time capabilities\n * - **SQL**: Raw SQL execution for maximum control\n * - **DATABASE**: Generic fallback adapter\n *\n * @example\n * ```typescript\n * // Adapter selection in configuration\n * const config = {\n * adapter: ADAPTERS.DRIZZLE,\n * connectionString: process.env.DATABASE_URL\n * };\n *\n * // Type-safe adapter factory usage\n * const adapter = AdapterFactory.create(ADAPTERS.SUPABASE, supabaseConfig);\n *\n * // Switch statement with exhaustive checking\n * switch (config.adapter) {\n * case ADAPTERS.DRIZZLE:\n * // Handle Drizzle-specific logic\n * break;\n * case ADAPTERS.SUPABASE:\n * // Handle Supabase-specific logic\n * break;\n * case ADAPTERS.SQL:\n * // Handle SQL-specific logic\n * break;\n * default:\n * // TypeScript ensures all cases are handled\n * throw new Error(`Unsupported adapter: ${config.adapter}`);\n * }\n * ```\n *\n */\n/**\n * @enum ADAPTERS\n * @description\n * Enumeration of supported database adapter types.\n *\n * This enum provides type-safe identification of different database integrations\n * and is used throughout the package for configuration, factory methods, and\n * adapter selection. Each adapter type represents a different approach to\n * database connectivity and operations.\n *\n * **Adapter Characteristics:**\n * - **DATABASE**: Generic fallback, minimal functionality\n * - **DRIZZLE**: Full ORM with type safety and query building\n * - **SUPABASE**: Hosted solution with real-time and auth features\n * - **SQL**: Raw SQL for performance-critical applications\n *\n * @example\n * ```typescript\n * // Configuration with adapter selection\n * const configs = {\n * development: { adapter: ADAPTERS.DRIZZLE },\n * production: { adapter: ADAPTERS.SUPABASE },\n * performance: { adapter: ADAPTERS.SQL }\n * };\n *\n * // Type-safe adapter validation\n * function validateAdapter(adapter: ADAPTERS): boolean {\n * return Object.values(ADAPTERS).includes(adapter);\n * }\n * ```\n */\nexport enum ADAPTERS {\n /** Generic database adapter (default when no specific integration is set) */\n DATABASE = 'database',\n\n /** Drizzle ORM adapter (PostgreSQL, MySQL, SQLite, etc.) */\n DRIZZLE = 'drizzle',\n\n /** Supabase adapter (PostgreSQL backend with REST + Realtime APIs) */\n SUPABASE = 'supabase',\n\n /** Raw SQL adapter (direct database queries without ORM) */\n SQL = 'sql',\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/db/adapter.ts","../../src/db/replicaStrategy.ts"],"names":["ADAPTERS","REPLICA_STRATEGY"],"mappings":";;;AAiFO,IAAK,QAAA,qBAAAA,SAAAA,KAAL;AAEL,EAAAA,UAAA,UAAA,CAAA,GAAW,UAAA;AAGX,EAAAA,UAAA,SAAA,CAAA,GAAU,SAAA;AAGV,EAAAA,UAAA,UAAA,CAAA,GAAW,UAAA;AAGX,EAAAA,UAAA,KAAA,CAAA,GAAM,KAAA;AAXI,EAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;;;AC9EL,IAAK,gBAAA,qBAAAC,iBAAAA,KAAL;AAEL,EAAAA,kBAAA,SAAA,CAAA,GAAU,SAAA;AAEV,EAAAA,kBAAA,SAAA,CAAA,GAAU,SAAA;AAEV,EAAAA,kBAAA,SAAA,CAAA,GAAU,SAAA;AAEV,EAAAA,kBAAA,SAAA,CAAA,GAAU,SAAA;AARA,EAAA,OAAAA,iBAAAA;AAAA,CAAA,EAAA,gBAAA,IAAA,EAAA","file":"index.js","sourcesContent":["/**\n * @fileoverview Database adapter type definitions\n *\n * Defines the enumeration of supported database adapter types used throughout\n * the database package. This enum provides type-safe identification of different\n * database integrations and is used in configuration, factory methods, and\n * adapter selection logic.\n *\n * **Application Flow Context:**\n * ```\n * Configuration → ADAPTERS Enum → AdapterFactory → Concrete Adapter\n * ↓ ↓ ↓ ↓\n * User Config → Type Safety → Adapter Creation → Database Connection\n * ```\n *\n * **Adapter Types:**\n * - **DRIZZLE**: Type-safe ORM with excellent TypeScript support\n * - **SUPABASE**: Hosted PostgreSQL with real-time capabilities\n * - **SQL**: Raw SQL execution for maximum control\n * - **DATABASE**: Generic fallback adapter\n *\n * @example\n * ```typescript\n * // Adapter selection in configuration\n * const config = {\n * adapter: ADAPTERS.DRIZZLE,\n * connectionString: process.env.DATABASE_URL\n * };\n *\n * // Type-safe adapter factory usage\n * const adapter = AdapterFactory.create(ADAPTERS.SUPABASE, supabaseConfig);\n *\n * // Switch statement with exhaustive checking\n * switch (config.adapter) {\n * case ADAPTERS.DRIZZLE:\n * // Handle Drizzle-specific logic\n * break;\n * case ADAPTERS.SUPABASE:\n * // Handle Supabase-specific logic\n * break;\n * case ADAPTERS.SQL:\n * // Handle SQL-specific logic\n * break;\n * default:\n * // TypeScript ensures all cases are handled\n * throw new Error(`Unsupported adapter: ${config.adapter}`);\n * }\n * ```\n *\n */\n/**\n * @enum ADAPTERS\n * @description\n * Enumeration of supported database adapter types.\n *\n * This enum provides type-safe identification of different database integrations\n * and is used throughout the package for configuration, factory methods, and\n * adapter selection. Each adapter type represents a different approach to\n * database connectivity and operations.\n *\n * **Adapter Characteristics:**\n * - **DATABASE**: Generic fallback, minimal functionality\n * - **DRIZZLE**: Full ORM with type safety and query building\n * - **SUPABASE**: Hosted solution with real-time and auth features\n * - **SQL**: Raw SQL for performance-critical applications\n *\n * @example\n * ```typescript\n * // Configuration with adapter selection\n * const configs = {\n * development: { adapter: ADAPTERS.DRIZZLE },\n * production: { adapter: ADAPTERS.SUPABASE },\n * performance: { adapter: ADAPTERS.SQL }\n * };\n *\n * // Type-safe adapter validation\n * function validateAdapter(adapter: ADAPTERS): boolean {\n * return Object.values(ADAPTERS).includes(adapter);\n * }\n * ```\n */\nexport enum ADAPTERS {\n /** Generic database adapter (default when no specific integration is set) */\n DATABASE = 'database',\n\n /** Drizzle ORM adapter (PostgreSQL, MySQL, SQLite, etc.) */\n DRIZZLE = 'drizzle',\n\n /** Supabase adapter (PostgreSQL backend with REST + Realtime APIs) */\n SUPABASE = 'supabase',\n\n /** Raw SQL adapter (direct database queries without ORM) */\n SQL = 'sql',\n}\n","/**\n * Strategy options for replica selection.\n */\nexport enum REPLICA_STRATEGY {\n /** Always use primary database */\n PRIMARY = 'primary',\n /** Use any available replica */\n REPLICA = 'replica',\n /** Use geographically closest replica */\n CLOSEST = 'closest',\n /** Use fastest responding replica */\n FASTEST = 'fastest'\n}"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AdapterConfig } from "./features-config.types";
|
|
2
|
+
import type { REPLICA_STRATEGY } from "./replicaStrategy";
|
|
3
|
+
/**
|
|
4
|
+
* Options for the @UseReplica decorator.
|
|
5
|
+
*/
|
|
6
|
+
export interface UseReplicaOptions {
|
|
7
|
+
/** Replica selection strategy */
|
|
8
|
+
strategy?: REPLICA_STRATEGY;
|
|
9
|
+
/** Specific replica index to use */
|
|
10
|
+
replicaIndex?: number;
|
|
11
|
+
/** Whether to fallback to primary if replicas are unavailable */
|
|
12
|
+
fallbackToPrimary?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for read replicas
|
|
16
|
+
*/
|
|
17
|
+
export interface ReadReplicaConfig {
|
|
18
|
+
/** Whether read replicas are enabled */
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
/** Replica connection configs */
|
|
21
|
+
replicas: AdapterConfig[];
|
|
22
|
+
/** Load balancing strategy */
|
|
23
|
+
strategy?: 'round-robin' | 'random' | 'least-connections';
|
|
24
|
+
/** Fallback to primary if all replicas unhealthy */
|
|
25
|
+
fallbackToPrimary?: boolean;
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy options for replica selection.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum REPLICA_STRATEGY {
|
|
5
|
+
/** Always use primary database */
|
|
6
|
+
PRIMARY = "primary",
|
|
7
|
+
/** Use any available replica */
|
|
8
|
+
REPLICA = "replica",
|
|
9
|
+
/** Use geographically closest replica */
|
|
10
|
+
CLOSEST = "closest",
|
|
11
|
+
/** Use fastest responding replica */
|
|
12
|
+
FASTEST = "fastest"
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for a shard key.
|
|
3
|
+
*/
|
|
4
|
+
export interface ShardKey {
|
|
5
|
+
/** Name of the shard key */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Type of sharding strategy */
|
|
8
|
+
type: 'hash' | 'range' | 'consistent_hash';
|
|
9
|
+
/** Columns that make up the shard key */
|
|
10
|
+
columns: string[];
|
|
11
|
+
/** Sharding strategy to use */
|
|
12
|
+
strategy: 'modulus' | 'hash' | 'range';
|
|
13
|
+
/** Number of shards */
|
|
14
|
+
shardCount: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for a database shard.
|
|
18
|
+
*/
|
|
19
|
+
export interface ShardConfig {
|
|
20
|
+
/** Unique shard identifier */
|
|
21
|
+
id: number;
|
|
22
|
+
/** Database connection string */
|
|
23
|
+
connectionString: string;
|
|
24
|
+
/** Whether this is the primary shard */
|
|
25
|
+
isPrimary: boolean;
|
|
26
|
+
/** Geographic region of the shard (optional) */
|
|
27
|
+
region?: string;
|
|
28
|
+
}
|