@gl-life/gl-life-database 1.0.0 → 1.1.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.
- package/API.md +249 -1
- package/README.md +67 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +21 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/cache/index.d.ts +0 -4
- package/dist/cache/index.d.ts.map +0 -1
- package/dist/cache/invalidation.d.ts +0 -156
- package/dist/cache/invalidation.d.ts.map +0 -1
- package/dist/cache/kv-cache.d.ts +0 -79
- package/dist/cache/kv-cache.d.ts.map +0 -1
- package/dist/cache/memory-cache.d.ts +0 -68
- package/dist/cache/memory-cache.d.ts.map +0 -1
- package/dist/cloudforge/d1-adapter.d.ts +0 -67
- package/dist/cloudforge/d1-adapter.d.ts.map +0 -1
- package/dist/cloudforge/do-storage.d.ts +0 -51
- package/dist/cloudforge/do-storage.d.ts.map +0 -1
- package/dist/cloudforge/index.d.ts +0 -4
- package/dist/cloudforge/index.d.ts.map +0 -1
- package/dist/cloudforge/r2-backup.d.ts +0 -38
- package/dist/cloudforge/r2-backup.d.ts.map +0 -1
- package/dist/connection/index.d.ts +0 -2
- package/dist/connection/index.d.ts.map +0 -1
- package/dist/connection/manager.d.ts +0 -54
- package/dist/connection/manager.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/migration/index.d.ts +0 -4
- package/dist/migration/index.d.ts.map +0 -1
- package/dist/migration/loader.d.ts +0 -88
- package/dist/migration/loader.d.ts.map +0 -1
- package/dist/migration/runner.d.ts +0 -91
- package/dist/migration/runner.d.ts.map +0 -1
- package/dist/migration/seeder.d.ts +0 -95
- package/dist/migration/seeder.d.ts.map +0 -1
- package/dist/query/builder.d.ts +0 -47
- package/dist/query/builder.d.ts.map +0 -1
- package/dist/query/index.d.ts +0 -3
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/raw.d.ts +0 -92
- package/dist/query/raw.d.ts.map +0 -1
- package/dist/tenant/context.d.ts +0 -52
- package/dist/tenant/context.d.ts.map +0 -1
- package/dist/tenant/index.d.ts +0 -4
- package/dist/tenant/index.d.ts.map +0 -1
- package/dist/tenant/query-wrapper.d.ts +0 -96
- package/dist/tenant/query-wrapper.d.ts.map +0 -1
- package/dist/tenant/schema-manager.d.ts +0 -185
- package/dist/tenant/schema-manager.d.ts.map +0 -1
- package/dist/transaction/index.d.ts +0 -2
- package/dist/transaction/index.d.ts.map +0 -1
- package/dist/transaction/transaction.d.ts +0 -51
- package/dist/transaction/transaction.d.ts.map +0 -1
- package/dist/types/cache.d.ts +0 -214
- package/dist/types/cache.d.ts.map +0 -1
- package/dist/types/cloudforge.d.ts +0 -753
- package/dist/types/cloudforge.d.ts.map +0 -1
- package/dist/types/connection.d.ts +0 -91
- package/dist/types/connection.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -10
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/migration.d.ts +0 -225
- package/dist/types/migration.d.ts.map +0 -1
- package/dist/types/plugin.d.ts +0 -432
- package/dist/types/plugin.d.ts.map +0 -1
- package/dist/types/query-builder.d.ts +0 -217
- package/dist/types/query-builder.d.ts.map +0 -1
- package/dist/types/seed.d.ts +0 -187
- package/dist/types/seed.d.ts.map +0 -1
- package/dist/types/tenant.d.ts +0 -140
- package/dist/types/tenant.d.ts.map +0 -1
- package/dist/types/transaction.d.ts +0 -144
- package/dist/types/transaction.d.ts.map +0 -1
package/dist/types/seed.d.ts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { Result } from '@gl-life/gl-life-core';
|
|
2
|
-
/**
|
|
3
|
-
* Seed environment type
|
|
4
|
-
*/
|
|
5
|
-
export type SeedEnvironment = 'development' | 'test' | 'staging' | 'production' | 'all';
|
|
6
|
-
/**
|
|
7
|
-
* Seed status
|
|
8
|
-
*/
|
|
9
|
-
export type SeedStatus = 'PENDING' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'SKIPPED';
|
|
10
|
-
/**
|
|
11
|
-
* Seed metadata
|
|
12
|
-
*/
|
|
13
|
-
export interface SeedMetadata {
|
|
14
|
-
/** Seed unique identifier */
|
|
15
|
-
id: string;
|
|
16
|
-
/** Seed name/description */
|
|
17
|
-
name: string;
|
|
18
|
-
/** Seed environment(s) */
|
|
19
|
-
environment: SeedEnvironment[];
|
|
20
|
-
/** Seed status */
|
|
21
|
-
status: SeedStatus;
|
|
22
|
-
/** Seed execution timestamp */
|
|
23
|
-
executedAt?: Date;
|
|
24
|
-
/** Seed execution duration in milliseconds */
|
|
25
|
-
executionTime?: number;
|
|
26
|
-
/** Seed error message if failed */
|
|
27
|
-
error?: string;
|
|
28
|
-
/** Seed checksum for integrity validation */
|
|
29
|
-
checksum?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Seed configuration options
|
|
33
|
-
*/
|
|
34
|
-
export interface SeedConfig {
|
|
35
|
-
/** Directory containing seed files */
|
|
36
|
-
seedsPath: string;
|
|
37
|
-
/** Table name for storing seed history */
|
|
38
|
-
seedTable: string;
|
|
39
|
-
/** Current environment */
|
|
40
|
-
environment: SeedEnvironment;
|
|
41
|
-
/** Whether to run seeds in a transaction */
|
|
42
|
-
transactional: boolean;
|
|
43
|
-
/** Whether to validate seed checksums */
|
|
44
|
-
validateChecksums: boolean;
|
|
45
|
-
/** Seed timeout in milliseconds */
|
|
46
|
-
timeout?: number;
|
|
47
|
-
/** Whether to create seed table if it doesn't exist */
|
|
48
|
-
autoCreateSeedTable?: boolean;
|
|
49
|
-
/** File naming pattern for seeds */
|
|
50
|
-
filePattern?: RegExp;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Seed error types
|
|
54
|
-
*/
|
|
55
|
-
export type SeedError = {
|
|
56
|
-
type: 'SEED_NOT_FOUND';
|
|
57
|
-
message: string;
|
|
58
|
-
seedId: string;
|
|
59
|
-
} | {
|
|
60
|
-
type: 'SEED_FAILED';
|
|
61
|
-
message: string;
|
|
62
|
-
seedId: string;
|
|
63
|
-
cause?: unknown;
|
|
64
|
-
} | {
|
|
65
|
-
type: 'CHECKSUM_MISMATCH';
|
|
66
|
-
message: string;
|
|
67
|
-
seedId: string;
|
|
68
|
-
} | {
|
|
69
|
-
type: 'ALREADY_SEEDED';
|
|
70
|
-
message: string;
|
|
71
|
-
seedId: string;
|
|
72
|
-
} | {
|
|
73
|
-
type: 'INVALID_SEED';
|
|
74
|
-
message: string;
|
|
75
|
-
cause?: unknown;
|
|
76
|
-
} | {
|
|
77
|
-
type: 'ENVIRONMENT_MISMATCH';
|
|
78
|
-
message: string;
|
|
79
|
-
seedId: string;
|
|
80
|
-
expected: string;
|
|
81
|
-
actual: string;
|
|
82
|
-
} | {
|
|
83
|
-
type: 'TIMEOUT';
|
|
84
|
-
message: string;
|
|
85
|
-
seedId: string;
|
|
86
|
-
} | {
|
|
87
|
-
type: 'UNKNOWN';
|
|
88
|
-
message: string;
|
|
89
|
-
cause?: unknown;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Seed execution context
|
|
93
|
-
*/
|
|
94
|
-
export interface SeedContext {
|
|
95
|
-
/** Database connection for executing seed */
|
|
96
|
-
execute<T = unknown>(sql: string, params?: unknown[]): Promise<Result<T, SeedError>>;
|
|
97
|
-
/** Logger for seed output */
|
|
98
|
-
log(message: string): void;
|
|
99
|
-
/** Seed metadata */
|
|
100
|
-
metadata: SeedMetadata;
|
|
101
|
-
/** Current environment */
|
|
102
|
-
environment: SeedEnvironment;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Seed definition
|
|
106
|
-
*/
|
|
107
|
-
export interface Seed {
|
|
108
|
-
/** Seed unique identifier */
|
|
109
|
-
id: string;
|
|
110
|
-
/** Seed name/description */
|
|
111
|
-
name: string;
|
|
112
|
-
/** Seed environment(s) */
|
|
113
|
-
environment: SeedEnvironment[];
|
|
114
|
-
/** Seed run function */
|
|
115
|
-
run(context: SeedContext): Promise<Result<void, SeedError>>;
|
|
116
|
-
/** Optional seed checksum */
|
|
117
|
-
checksum?: string;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Seeder interface
|
|
121
|
-
*
|
|
122
|
-
* Manages database seeding with environment support and idempotent execution.
|
|
123
|
-
* Provides safe data seeding for development and testing.
|
|
124
|
-
*/
|
|
125
|
-
export interface Seeder {
|
|
126
|
-
/**
|
|
127
|
-
* Seed configuration
|
|
128
|
-
*/
|
|
129
|
-
readonly config: SeedConfig;
|
|
130
|
-
/**
|
|
131
|
-
* Get all available seeds
|
|
132
|
-
*
|
|
133
|
-
* @returns Result with array of seeds or SeedError
|
|
134
|
-
*/
|
|
135
|
-
getSeeds(): Promise<Result<Seed[], SeedError>>;
|
|
136
|
-
/**
|
|
137
|
-
* Get seed history
|
|
138
|
-
*
|
|
139
|
-
* @returns Result with array of executed seed metadata or SeedError
|
|
140
|
-
*/
|
|
141
|
-
getHistory(): Promise<Result<SeedMetadata[], SeedError>>;
|
|
142
|
-
/**
|
|
143
|
-
* Get pending seeds for current environment
|
|
144
|
-
*
|
|
145
|
-
* @returns Result with array of pending seeds or SeedError
|
|
146
|
-
*/
|
|
147
|
-
getPending(): Promise<Result<Seed[], SeedError>>;
|
|
148
|
-
/**
|
|
149
|
-
* Run all pending seeds for current environment
|
|
150
|
-
*
|
|
151
|
-
* @returns Result with array of executed seed metadata or SeedError
|
|
152
|
-
*/
|
|
153
|
-
seed(): Promise<Result<SeedMetadata[], SeedError>>;
|
|
154
|
-
/**
|
|
155
|
-
* Run a specific seed by ID
|
|
156
|
-
*
|
|
157
|
-
* @param seedId - Seed identifier
|
|
158
|
-
* @returns Result with seed metadata or SeedError
|
|
159
|
-
*/
|
|
160
|
-
runSeed(seedId: string): Promise<Result<SeedMetadata, SeedError>>;
|
|
161
|
-
/**
|
|
162
|
-
* Reset all seeds (mark as not run)
|
|
163
|
-
*
|
|
164
|
-
* @returns Result with void on success or SeedError
|
|
165
|
-
*/
|
|
166
|
-
reset(): Promise<Result<void, SeedError>>;
|
|
167
|
-
/**
|
|
168
|
-
* Validate seed checksums
|
|
169
|
-
*
|
|
170
|
-
* @returns Result with true if all checksums are valid
|
|
171
|
-
*/
|
|
172
|
-
validateChecksums(): Promise<Result<boolean, SeedError>>;
|
|
173
|
-
/**
|
|
174
|
-
* Create seed table if it doesn't exist
|
|
175
|
-
*
|
|
176
|
-
* @returns Result with void on success or SeedError on failure
|
|
177
|
-
*/
|
|
178
|
-
createSeedTable(): Promise<Result<void, SeedError>>;
|
|
179
|
-
/**
|
|
180
|
-
* Load seed from file
|
|
181
|
-
*
|
|
182
|
-
* @param filePath - Seed file path
|
|
183
|
-
* @returns Result with Seed or SeedError
|
|
184
|
-
*/
|
|
185
|
-
loadSeed(filePath: string): Promise<Result<Seed, SeedError>>;
|
|
186
|
-
}
|
|
187
|
-
//# sourceMappingURL=seed.d.ts.map
|
package/dist/types/seed.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../src/types/seed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,KAAK,CAAC;AAExF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEpF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,kBAAkB;IAClB,MAAM,EAAE,UAAU,CAAC;IACnB,+BAA+B;IAC/B,UAAU,CAAC,E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AC,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IAE/C;;;;OAIG;IACH,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IAEzD;;;;OAIG;IACH,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IAEjD;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IAEnD;;;;;OAKG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;IAElE;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAE1C;;;;OAIG;IACH,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;IAEzD;;;;OAIG;IACH,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAEpD;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;CAC9D"}
|
package/dist/types/tenant.d.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Option } from '@gl-life/gl-life-core';
|
|
2
|
-
/**
|
|
3
|
-
* Tenant isolation strategy
|
|
4
|
-
*/
|
|
5
|
-
export type TenantIsolationStrategy = 'DATABASE' | 'SCHEMA' | 'ROW' | 'HYBRID';
|
|
6
|
-
/**
|
|
7
|
-
* Tenant metadata
|
|
8
|
-
*/
|
|
9
|
-
export interface TenantMetadata {
|
|
10
|
-
/** Tenant unique identifier */
|
|
11
|
-
id: string;
|
|
12
|
-
/** Tenant name */
|
|
13
|
-
name: string;
|
|
14
|
-
/** Tenant creation timestamp */
|
|
15
|
-
createdAt: Date;
|
|
16
|
-
/** Tenant last updated timestamp */
|
|
17
|
-
updatedAt: Date;
|
|
18
|
-
/** Whether tenant is active */
|
|
19
|
-
isActive: boolean;
|
|
20
|
-
/** Custom tenant attributes */
|
|
21
|
-
attributes?: Record<string, unknown>;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Tenant context configuration
|
|
25
|
-
*/
|
|
26
|
-
export interface TenantContextConfig {
|
|
27
|
-
/** Tenant isolation strategy */
|
|
28
|
-
isolationStrategy: TenantIsolationStrategy;
|
|
29
|
-
/** Whether to enforce tenant isolation on all queries */
|
|
30
|
-
enforceIsolation: boolean;
|
|
31
|
-
/** Database name for DATABASE strategy */
|
|
32
|
-
databaseName?: string;
|
|
33
|
-
/** Schema name for SCHEMA strategy */
|
|
34
|
-
schemaName?: string;
|
|
35
|
-
/** Tenant ID column name for ROW strategy */
|
|
36
|
-
tenantIdColumn?: string;
|
|
37
|
-
/** Tables to exclude from tenant isolation */
|
|
38
|
-
excludedTables?: string[];
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Tenant context interface
|
|
42
|
-
*
|
|
43
|
-
* Manages multi-tenancy context for database operations.
|
|
44
|
-
* Ensures proper tenant isolation and data segregation.
|
|
45
|
-
*/
|
|
46
|
-
export interface TenantContext {
|
|
47
|
-
/**
|
|
48
|
-
* Current tenant metadata
|
|
49
|
-
*/
|
|
50
|
-
readonly tenant: Option<TenantMetadata>;
|
|
51
|
-
/**
|
|
52
|
-
* Tenant context configuration
|
|
53
|
-
*/
|
|
54
|
-
readonly config: TenantContextConfig;
|
|
55
|
-
/**
|
|
56
|
-
* Whether a tenant is currently set
|
|
57
|
-
*/
|
|
58
|
-
readonly hasTenant: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Set the current tenant
|
|
61
|
-
*
|
|
62
|
-
* @param tenantId - Tenant identifier
|
|
63
|
-
* @returns Promise resolving when tenant is set
|
|
64
|
-
*/
|
|
65
|
-
setTenant(tenantId: string): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* Set the current tenant with metadata
|
|
68
|
-
*
|
|
69
|
-
* @param metadata - Complete tenant metadata
|
|
70
|
-
* @returns Promise resolving when tenant is set
|
|
71
|
-
*/
|
|
72
|
-
setTenantWithMetadata(metadata: TenantMetadata): Promise<void>;
|
|
73
|
-
/**
|
|
74
|
-
* Clear the current tenant context
|
|
75
|
-
*
|
|
76
|
-
* @returns Promise resolving when tenant is cleared
|
|
77
|
-
*/
|
|
78
|
-
clearTenant(): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Get the current tenant ID
|
|
81
|
-
*
|
|
82
|
-
* @returns Option with tenant ID or None
|
|
83
|
-
*/
|
|
84
|
-
getTenantId(): Option<string>;
|
|
85
|
-
/**
|
|
86
|
-
* Get the current tenant metadata
|
|
87
|
-
*
|
|
88
|
-
* @returns Option with tenant metadata or None
|
|
89
|
-
*/
|
|
90
|
-
getTenant(): Option<TenantMetadata>;
|
|
91
|
-
/**
|
|
92
|
-
* Check if a table should have tenant isolation
|
|
93
|
-
*
|
|
94
|
-
* @param table - Table name
|
|
95
|
-
* @returns True if table should be isolated
|
|
96
|
-
*/
|
|
97
|
-
shouldIsolateTable(table: string): boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Apply tenant isolation to a SQL query
|
|
100
|
-
*
|
|
101
|
-
* Modifies the query to include tenant filtering based on isolation strategy.
|
|
102
|
-
*
|
|
103
|
-
* @param sql - Original SQL query
|
|
104
|
-
* @param params - Query parameters
|
|
105
|
-
* @returns Modified query with tenant isolation
|
|
106
|
-
*/
|
|
107
|
-
applyTenantIsolation(sql: string, params?: unknown[]): {
|
|
108
|
-
sql: string;
|
|
109
|
-
params: unknown[];
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* Get the tenant-specific database name
|
|
113
|
-
*
|
|
114
|
-
* @returns Option with database name or None
|
|
115
|
-
*/
|
|
116
|
-
getTenantDatabase(): Option<string>;
|
|
117
|
-
/**
|
|
118
|
-
* Get the tenant-specific schema name
|
|
119
|
-
*
|
|
120
|
-
* @returns Option with schema name or None
|
|
121
|
-
*/
|
|
122
|
-
getTenantSchema(): Option<string>;
|
|
123
|
-
/**
|
|
124
|
-
* Execute a callback with a specific tenant context
|
|
125
|
-
*
|
|
126
|
-
* Temporarily sets the tenant, executes the callback, then restores previous tenant.
|
|
127
|
-
*
|
|
128
|
-
* @param tenantId - Tenant identifier
|
|
129
|
-
* @param callback - Callback function to execute
|
|
130
|
-
* @returns Promise with callback result
|
|
131
|
-
*/
|
|
132
|
-
withTenant<T>(tenantId: string, callback: () => Promise<T>): Promise<T>;
|
|
133
|
-
/**
|
|
134
|
-
* Clone the tenant context
|
|
135
|
-
*
|
|
136
|
-
* @returns New TenantContext instance with same configuration
|
|
137
|
-
*/
|
|
138
|
-
clone(): TenantContext;
|
|
139
|
-
}
|
|
140
|
-
//# sourceMappingURL=tenant.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tenant.d.ts","sourceRoot":"","sources":["../../src/types/tenant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAC/B,UAAU,GACV,QAAQ,GACR,KAAK,GACL,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,SAAS,EAAE,IAAI,CAAC;IAChB,oCAAoC;IACpC,SAAS,EAAE,IAAI,CAAC;IAChB,+BAA+B;IAC/B,QAAQ,EAAE,OAAO,CAAC;IAClB,+BAA+B;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EA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C;IAEtC;;;;OAIG;IACH,iBAAiB,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;IAEpC;;;;OAIG;IACH,eAAe,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;IAElC;;;;;;;;OAQG;IACH,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAExE;;;;OAIG;IACH,KAAK,IAAI,aAAa,CAAC;CACxB"}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { Result } from '@gl-life/gl-life-core';
|
|
2
|
-
import type { QueryBuilder } from './query-builder.js';
|
|
3
|
-
/**
|
|
4
|
-
* Transaction isolation levels
|
|
5
|
-
*/
|
|
6
|
-
export type TransactionIsolationLevel = 'READ UNCOMMITTED' | 'READ COMMITTED' | 'REPEATABLE READ' | 'SERIALIZABLE';
|
|
7
|
-
/**
|
|
8
|
-
* Transaction error types
|
|
9
|
-
*/
|
|
10
|
-
export type TransactionError = {
|
|
11
|
-
type: 'BEGIN_FAILED';
|
|
12
|
-
message: string;
|
|
13
|
-
cause?: unknown;
|
|
14
|
-
} | {
|
|
15
|
-
type: 'COMMIT_FAILED';
|
|
16
|
-
message: string;
|
|
17
|
-
cause?: unknown;
|
|
18
|
-
} | {
|
|
19
|
-
type: 'ROLLBACK_FAILED';
|
|
20
|
-
message: string;
|
|
21
|
-
cause?: unknown;
|
|
22
|
-
} | {
|
|
23
|
-
type: 'ALREADY_STARTED';
|
|
24
|
-
message: string;
|
|
25
|
-
} | {
|
|
26
|
-
type: 'NOT_STARTED';
|
|
27
|
-
message: string;
|
|
28
|
-
} | {
|
|
29
|
-
type: 'ALREADY_COMPLETED';
|
|
30
|
-
message: string;
|
|
31
|
-
} | {
|
|
32
|
-
type: 'DEADLOCK';
|
|
33
|
-
message: string;
|
|
34
|
-
} | {
|
|
35
|
-
type: 'TIMEOUT';
|
|
36
|
-
message: string;
|
|
37
|
-
} | {
|
|
38
|
-
type: 'UNKNOWN';
|
|
39
|
-
message: string;
|
|
40
|
-
cause?: unknown;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Transaction state
|
|
44
|
-
*/
|
|
45
|
-
export type TransactionState = 'PENDING' | 'ACTIVE' | 'COMMITTED' | 'ROLLED_BACK';
|
|
46
|
-
/**
|
|
47
|
-
* Transaction configuration options
|
|
48
|
-
*/
|
|
49
|
-
export interface TransactionConfig {
|
|
50
|
-
/** Transaction isolation level */
|
|
51
|
-
isolationLevel?: TransactionIsolationLevel;
|
|
52
|
-
/** Transaction timeout in milliseconds */
|
|
53
|
-
timeout?: number;
|
|
54
|
-
/** Whether to automatically rollback on error */
|
|
55
|
-
autoRollback?: boolean;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Transaction interface
|
|
59
|
-
*
|
|
60
|
-
* Provides ACID transaction support for database operations.
|
|
61
|
-
* Ensures data consistency through commit/rollback operations.
|
|
62
|
-
*/
|
|
63
|
-
export interface Transaction {
|
|
64
|
-
/**
|
|
65
|
-
* Unique transaction identifier
|
|
66
|
-
*/
|
|
67
|
-
readonly id: string;
|
|
68
|
-
/**
|
|
69
|
-
* Current transaction state
|
|
70
|
-
*/
|
|
71
|
-
readonly state: TransactionState;
|
|
72
|
-
/**
|
|
73
|
-
* Transaction configuration
|
|
74
|
-
*/
|
|
75
|
-
readonly config: TransactionConfig;
|
|
76
|
-
/**
|
|
77
|
-
* Whether the transaction is currently active
|
|
78
|
-
*/
|
|
79
|
-
readonly isActive: boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Begin the transaction
|
|
82
|
-
*
|
|
83
|
-
* @returns Result with void on success or TransactionError on failure
|
|
84
|
-
*/
|
|
85
|
-
begin(): Promise<Result<void, TransactionError>>;
|
|
86
|
-
/**
|
|
87
|
-
* Commit the transaction
|
|
88
|
-
*
|
|
89
|
-
* @returns Result with void on success or TransactionError on failure
|
|
90
|
-
*/
|
|
91
|
-
commit(): Promise<Result<void, TransactionError>>;
|
|
92
|
-
/**
|
|
93
|
-
* Rollback the transaction
|
|
94
|
-
*
|
|
95
|
-
* @returns Result with void on success or TransactionError on failure
|
|
96
|
-
*/
|
|
97
|
-
rollback(): Promise<Result<void, TransactionError>>;
|
|
98
|
-
/**
|
|
99
|
-
* Create a savepoint within the transaction
|
|
100
|
-
*
|
|
101
|
-
* @param name - Savepoint name
|
|
102
|
-
* @returns Result with savepoint name or TransactionError
|
|
103
|
-
*/
|
|
104
|
-
savepoint(name: string): Promise<Result<string, TransactionError>>;
|
|
105
|
-
/**
|
|
106
|
-
* Rollback to a specific savepoint
|
|
107
|
-
*
|
|
108
|
-
* @param name - Savepoint name
|
|
109
|
-
* @returns Result with void on success or TransactionError on failure
|
|
110
|
-
*/
|
|
111
|
-
rollbackToSavepoint(name: string): Promise<Result<void, TransactionError>>;
|
|
112
|
-
/**
|
|
113
|
-
* Release a savepoint
|
|
114
|
-
*
|
|
115
|
-
* @param name - Savepoint name
|
|
116
|
-
* @returns Result with void on success or TransactionError on failure
|
|
117
|
-
*/
|
|
118
|
-
releaseSavepoint(name: string): Promise<Result<void, TransactionError>>;
|
|
119
|
-
/**
|
|
120
|
-
* Execute a raw SQL query within the transaction
|
|
121
|
-
*
|
|
122
|
-
* @param sql - SQL query string
|
|
123
|
-
* @param params - Query parameters
|
|
124
|
-
* @returns Result with query result or TransactionError
|
|
125
|
-
*/
|
|
126
|
-
execute<T = unknown>(sql: string, params?: unknown[]): Promise<Result<T, TransactionError>>;
|
|
127
|
-
/**
|
|
128
|
-
* Get a query builder instance scoped to this transaction
|
|
129
|
-
*
|
|
130
|
-
* @param table - Table name
|
|
131
|
-
* @returns QueryBuilder instance
|
|
132
|
-
*/
|
|
133
|
-
queryBuilder<T = unknown>(table: string): QueryBuilder<T>;
|
|
134
|
-
/**
|
|
135
|
-
* Execute a callback function within the transaction
|
|
136
|
-
*
|
|
137
|
-
* Automatically commits on success or rolls back on error.
|
|
138
|
-
*
|
|
139
|
-
* @param callback - Async callback function
|
|
140
|
-
* @returns Result with callback return value or TransactionError
|
|
141
|
-
*/
|
|
142
|
-
run<T>(callback: (tx: Transaction) => Promise<Result<T, unknown>>): Promise<Result<T, TransactionError>>;
|
|
143
|
-
}
|
|
144
|
-
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/types/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACjC,kBAAkB,GAClB,gBAAgB,GAChB,iBAAiB,GACjB,cAAc,CAAC;AAEnB;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,SAAS,C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