@open-core/framework 1.0.1-beta.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.
- package/LICENSE +373 -0
- package/README.md +350 -0
- package/dist/client/client-bootstrap.d.ts +1 -0
- package/dist/client/client-bootstrap.js +53 -0
- package/dist/client/client-container.d.ts +2 -0
- package/dist/client/client-container.js +6 -0
- package/dist/client/client-core.d.ts +18 -0
- package/dist/client/client-core.js +52 -0
- package/dist/client/decorators/controller.d.ts +3 -0
- package/dist/client/decorators/controller.js +14 -0
- package/dist/client/decorators/export.d.ts +7 -0
- package/dist/client/decorators/export.js +15 -0
- package/dist/client/decorators/gameEvent.d.ts +47 -0
- package/dist/client/decorators/gameEvent.js +54 -0
- package/dist/client/decorators/index.d.ts +10 -0
- package/dist/client/decorators/index.js +26 -0
- package/dist/client/decorators/interval.d.ts +7 -0
- package/dist/client/decorators/interval.js +15 -0
- package/dist/client/decorators/key.d.ts +2 -0
- package/dist/client/decorators/key.js +10 -0
- package/dist/client/decorators/localEvent.d.ts +7 -0
- package/dist/client/decorators/localEvent.js +15 -0
- package/dist/client/decorators/nui.d.ts +1 -0
- package/dist/client/decorators/nui.js +9 -0
- package/dist/client/decorators/onNet.d.ts +1 -0
- package/dist/client/decorators/onNet.js +9 -0
- package/dist/client/decorators/resourceLifecycle.d.ts +11 -0
- package/dist/client/decorators/resourceLifecycle.js +24 -0
- package/dist/client/decorators/tick.d.ts +1 -0
- package/dist/client/decorators/tick.js +9 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +22 -0
- package/dist/client/loaders/exports.loader.d.ts +1 -0
- package/dist/client/loaders/exports.loader.js +13 -0
- package/dist/client/player/player.d.ts +262 -0
- package/dist/client/player/player.js +480 -0
- package/dist/client/player/player.loader.d.ts +1 -0
- package/dist/client/player/player.loader.js +22 -0
- package/dist/client/services/core/index.d.ts +1 -0
- package/dist/client/services/core/index.js +17 -0
- package/dist/client/services/core/spawn.service.d.ts +20 -0
- package/dist/client/services/core/spawn.service.js +143 -0
- package/dist/client/services/index.d.ts +4 -0
- package/dist/client/services/index.js +24 -0
- package/dist/client/services/streaming/index.d.ts +1 -0
- package/dist/client/services/streaming/index.js +17 -0
- package/dist/client/services/streaming/streaming.service.d.ts +165 -0
- package/dist/client/services/streaming/streaming.service.js +341 -0
- package/dist/client/services/ui/index.d.ts +3 -0
- package/dist/client/services/ui/index.js +19 -0
- package/dist/client/services/ui/notification.service.d.ts +76 -0
- package/dist/client/services/ui/notification.service.js +111 -0
- package/dist/client/services/ui/progress.service.d.ts +82 -0
- package/dist/client/services/ui/progress.service.js +210 -0
- package/dist/client/services/ui/textui.service.d.ts +82 -0
- package/dist/client/services/ui/textui.service.js +156 -0
- package/dist/client/services/world/blip.service.d.ts +112 -0
- package/dist/client/services/world/blip.service.js +215 -0
- package/dist/client/services/world/index.d.ts +4 -0
- package/dist/client/services/world/index.js +20 -0
- package/dist/client/services/world/marker.service.d.ts +94 -0
- package/dist/client/services/world/marker.service.js +153 -0
- package/dist/client/services/world/ped.service.d.ts +182 -0
- package/dist/client/services/world/ped.service.js +302 -0
- package/dist/client/services/world/vehicle.service.d.ts +168 -0
- package/dist/client/services/world/vehicle.service.js +296 -0
- package/dist/client/system/metadata-client.keys.d.ts +13 -0
- package/dist/client/system/metadata-client.keys.js +16 -0
- package/dist/client/system/processors/export.processor.d.ts +7 -0
- package/dist/client/system/processors/export.processor.js +39 -0
- package/dist/client/system/processors/gameEvent.processor.d.ts +10 -0
- package/dist/client/system/processors/gameEvent.processor.js +58 -0
- package/dist/client/system/processors/interval.processor.d.ts +7 -0
- package/dist/client/system/processors/interval.processor.js +43 -0
- package/dist/client/system/processors/key.processor.d.ts +8 -0
- package/dist/client/system/processors/key.processor.js +27 -0
- package/dist/client/system/processors/localEvent.processor.d.ts +7 -0
- package/dist/client/system/processors/localEvent.processor.js +38 -0
- package/dist/client/system/processors/netEvent.processor.d.ts +7 -0
- package/dist/client/system/processors/netEvent.processor.js +38 -0
- package/dist/client/system/processors/nui.processor.d.ts +7 -0
- package/dist/client/system/processors/nui.processor.js +40 -0
- package/dist/client/system/processors/resourceLifecycle.processor.d.ts +9 -0
- package/dist/client/system/processors/resourceLifecycle.processor.js +69 -0
- package/dist/client/system/processors/tick.processor.d.ts +5 -0
- package/dist/client/system/processors/tick.processor.js +37 -0
- package/dist/client/system/processors.register.d.ts +1 -0
- package/dist/client/system/processors.register.js +27 -0
- package/dist/client/types/game-events.d.ts +126 -0
- package/dist/client/types/game-events.js +83 -0
- package/dist/client/types/index.d.ts +1 -0
- package/dist/client/types/index.js +17 -0
- package/dist/client/ui-bridge.d.ts +116 -0
- package/dist/client/ui-bridge.js +201 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +46 -0
- package/dist/server/bootstrap.d.ts +16 -0
- package/dist/server/bootstrap.js +57 -0
- package/dist/server/bus/core-event-bus.d.ts +6 -0
- package/dist/server/bus/core-event-bus.js +31 -0
- package/dist/server/configs/api.config.d.ts +71 -0
- package/dist/server/configs/api.config.js +81 -0
- package/dist/server/configs/config.base.d.ts +63 -0
- package/dist/server/configs/config.base.js +64 -0
- package/dist/server/configs/index.d.ts +2 -0
- package/dist/server/configs/index.js +18 -0
- package/dist/server/container.d.ts +2 -0
- package/dist/server/container.js +6 -0
- package/dist/server/controllers/chat.controller.d.ts +10 -0
- package/dist/server/controllers/chat.controller.js +50 -0
- package/dist/server/controllers/command.controller.d.ts +7 -0
- package/dist/server/controllers/command.controller.js +47 -0
- package/dist/server/core.d.ts +1 -0
- package/dist/server/core.js +7 -0
- package/dist/server/database/adapters/oxmysql.adapter.d.ts +89 -0
- package/dist/server/database/adapters/oxmysql.adapter.js +149 -0
- package/dist/server/database/database.contract.d.ts +128 -0
- package/dist/server/database/database.contract.js +29 -0
- package/dist/server/database/database.service.d.ts +216 -0
- package/dist/server/database/database.service.js +301 -0
- package/dist/server/database/index.d.ts +53 -0
- package/dist/server/database/index.js +70 -0
- package/dist/server/database/types.d.ts +67 -0
- package/dist/server/database/types.js +7 -0
- package/dist/server/database.d.ts +7 -0
- package/dist/server/database.js +23 -0
- package/dist/server/decorators/bind.d.ts +2 -0
- package/dist/server/decorators/bind.js +15 -0
- package/dist/server/decorators/command.d.ts +19 -0
- package/dist/server/decorators/command.js +18 -0
- package/dist/server/decorators/controller.d.ts +3 -0
- package/dist/server/decorators/controller.js +14 -0
- package/dist/server/decorators/coreEvent.d.ts +2 -0
- package/dist/server/decorators/coreEvent.js +9 -0
- package/dist/server/decorators/export.d.ts +1 -0
- package/dist/server/decorators/export.js +9 -0
- package/dist/server/decorators/guard.d.ts +5 -0
- package/dist/server/decorators/guard.js +39 -0
- package/dist/server/decorators/index.d.ts +10 -0
- package/dist/server/decorators/index.js +26 -0
- package/dist/server/decorators/netEvent.d.ts +36 -0
- package/dist/server/decorators/netEvent.js +40 -0
- package/dist/server/decorators/onTick.d.ts +1 -0
- package/dist/server/decorators/onTick.js +9 -0
- package/dist/server/decorators/public.d.ts +16 -0
- package/dist/server/decorators/public.js +25 -0
- package/dist/server/decorators/requiresState.d.ts +55 -0
- package/dist/server/decorators/requiresState.js +62 -0
- package/dist/server/decorators/throttle.d.ts +9 -0
- package/dist/server/decorators/throttle.js +36 -0
- package/dist/server/decorators/utils.d.ts +7 -0
- package/dist/server/decorators/utils.js +13 -0
- package/dist/server/entities/index.d.ts +1 -0
- package/dist/server/entities/index.js +17 -0
- package/dist/server/entities/player.d.ts +157 -0
- package/dist/server/entities/player.js +217 -0
- package/dist/server/error-handler.d.ts +2 -0
- package/dist/server/error-handler.js +43 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.js +29 -0
- package/dist/server/loaders/exports.loader.d.ts +0 -0
- package/dist/server/loaders/exports.loader.js +23 -0
- package/dist/server/loaders/playerSession.loader.d.ts +1 -0
- package/dist/server/loaders/playerSession.loader.js +42 -0
- package/dist/server/services/access-control.service.d.ts +56 -0
- package/dist/server/services/access-control.service.js +99 -0
- package/dist/server/services/chat.service.d.ts +7 -0
- package/dist/server/services/chat.service.js +31 -0
- package/dist/server/services/command.service.d.ts +15 -0
- package/dist/server/services/command.service.js +74 -0
- package/dist/server/services/config.service.d.ts +75 -0
- package/dist/server/services/config.service.js +116 -0
- package/dist/server/services/default/default-security.handler.d.ts +6 -0
- package/dist/server/services/default/default-security.handler.js +26 -0
- package/dist/server/services/http/http.service.d.ts +50 -0
- package/dist/server/services/http/http.service.js +126 -0
- package/dist/server/services/index.d.ts +10 -0
- package/dist/server/services/index.js +26 -0
- package/dist/server/services/parallel/index.d.ts +49 -0
- package/dist/server/services/parallel/index.js +67 -0
- package/dist/server/services/parallel/parallel-compute.service.d.ts +132 -0
- package/dist/server/services/parallel/parallel-compute.service.js +449 -0
- package/dist/server/services/parallel/types.d.ts +188 -0
- package/dist/server/services/parallel/types.js +7 -0
- package/dist/server/services/parallel/worker-pool.d.ts +83 -0
- package/dist/server/services/parallel/worker-pool.js +350 -0
- package/dist/server/services/parallel/worker.d.ts +19 -0
- package/dist/server/services/parallel/worker.js +49 -0
- package/dist/server/services/persistence.service.d.ts +59 -0
- package/dist/server/services/persistence.service.js +166 -0
- package/dist/server/services/player.service.d.ts +96 -0
- package/dist/server/services/player.service.js +132 -0
- package/dist/server/services/rate-limiter.service.d.ts +5 -0
- package/dist/server/services/rate-limiter.service.js +39 -0
- package/dist/server/services/registers.d.ts +1 -0
- package/dist/server/services/registers.js +18 -0
- package/dist/server/setup.d.ts +9 -0
- package/dist/server/setup.js +28 -0
- package/dist/server/system/metadata-server.keys.d.ts +9 -0
- package/dist/server/system/metadata-server.keys.js +12 -0
- package/dist/server/system/processors/command.processor.d.ts +9 -0
- package/dist/server/system/processors/command.processor.js +31 -0
- package/dist/server/system/processors/coreEvent.processor.d.ts +7 -0
- package/dist/server/system/processors/coreEvent.processor.js +38 -0
- package/dist/server/system/processors/export.processor.d.ts +7 -0
- package/dist/server/system/processors/export.processor.js +26 -0
- package/dist/server/system/processors/netEvent.processor.d.ts +11 -0
- package/dist/server/system/processors/netEvent.processor.js +100 -0
- package/dist/server/system/processors/tick.processor.d.ts +5 -0
- package/dist/server/system/processors/tick.processor.js +36 -0
- package/dist/server/system/processors.register.d.ts +1 -0
- package/dist/server/system/processors.register.js +21 -0
- package/dist/server/templates/admin/admin.controller-template.d.ts +10 -0
- package/dist/server/templates/admin/admin.controller-template.js +2 -0
- package/dist/server/templates/auth/auth-provider.contract.d.ts +58 -0
- package/dist/server/templates/auth/auth-provider.contract.js +23 -0
- package/dist/server/templates/index.d.ts +8 -0
- package/dist/server/templates/index.js +21 -0
- package/dist/server/templates/persistence/index.d.ts +30 -0
- package/dist/server/templates/persistence/index.js +34 -0
- package/dist/server/templates/persistence/player-persistence.contract.d.ts +86 -0
- package/dist/server/templates/persistence/player-persistence.contract.js +52 -0
- package/dist/server/templates/repository/index.d.ts +57 -0
- package/dist/server/templates/repository/index.js +61 -0
- package/dist/server/templates/repository/repository.contract.d.ts +224 -0
- package/dist/server/templates/repository/repository.contract.js +342 -0
- package/dist/server/templates/repository/repository.types.d.ts +51 -0
- package/dist/server/templates/repository/repository.types.js +7 -0
- package/dist/server/templates/security/permission.types.d.ts +32 -0
- package/dist/server/templates/security/permission.types.js +2 -0
- package/dist/server/templates/security/principal-provider.contract.d.ts +43 -0
- package/dist/server/templates/security/principal-provider.contract.js +19 -0
- package/dist/server/templates/security/security-handler.contract.d.ts +5 -0
- package/dist/server/templates/security/security-handler.contract.js +6 -0
- package/dist/server/types/core-events.d.ts +17 -0
- package/dist/server/types/core-events.js +2 -0
- package/dist/server/types/security.types.d.ts +7 -0
- package/dist/server/types/security.types.js +2 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +17 -0
- package/dist/shared/logger/core-logger.d.ts +35 -0
- package/dist/shared/logger/core-logger.js +52 -0
- package/dist/shared/logger/index.d.ts +11 -0
- package/dist/shared/logger/index.js +26 -0
- package/dist/shared/logger/logger.config.d.ts +47 -0
- package/dist/shared/logger/logger.config.js +33 -0
- package/dist/shared/logger/logger.service.d.ts +161 -0
- package/dist/shared/logger/logger.service.js +279 -0
- package/dist/shared/logger/logger.types.d.ts +85 -0
- package/dist/shared/logger/logger.types.js +74 -0
- package/dist/shared/logger/transports/buffered.transport.d.ts +88 -0
- package/dist/shared/logger/transports/buffered.transport.js +174 -0
- package/dist/shared/logger/transports/console.transport.d.ts +37 -0
- package/dist/shared/logger/transports/console.transport.js +134 -0
- package/dist/shared/logger/transports/index.d.ts +3 -0
- package/dist/shared/logger/transports/index.js +19 -0
- package/dist/shared/logger/transports/transport.interface.d.ts +40 -0
- package/dist/shared/logger/transports/transport.interface.js +2 -0
- package/dist/system/class-constructor.d.ts +1 -0
- package/dist/system/class-constructor.js +2 -0
- package/dist/system/decorator-processor.d.ts +4 -0
- package/dist/system/decorator-processor.js +2 -0
- package/dist/system/metadata.scanner.d.ts +7 -0
- package/dist/system/metadata.scanner.js +45 -0
- package/dist/utils/errors.d.ts +14 -0
- package/dist/utils/errors.js +25 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/result.d.ts +12 -0
- package/dist/utils/result.js +10 -0
- package/dist/utils/rgb.d.ts +5 -0
- package/dist/utils/rgb.js +2 -0
- package/dist/utils/vector3.d.ts +13 -0
- package/dist/utils/vector3.js +27 -0
- package/package.json +70 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Service
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for database operations. Acts as a factory/wrapper
|
|
5
|
+
* that delegates to the registered database adapter.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { DatabaseService } from '@open-core/framework/server'
|
|
10
|
+
* import { inject, injectable } from 'tsyringe'
|
|
11
|
+
*
|
|
12
|
+
* @injectable()
|
|
13
|
+
* class UserService {
|
|
14
|
+
* constructor(@inject(DatabaseService) private db: DatabaseService) {}
|
|
15
|
+
*
|
|
16
|
+
* async getUser(id: number) {
|
|
17
|
+
* return this.db.single<User>('SELECT * FROM users WHERE id = ?', [id])
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { DatabaseContract } from './database.contract';
|
|
23
|
+
import type { DatabaseConfig, ExecuteResult, InsertResult, TransactionInput, TransactionSharedParams } from './types';
|
|
24
|
+
/**
|
|
25
|
+
* Database Service
|
|
26
|
+
*
|
|
27
|
+
* Singleton service that provides database operations through
|
|
28
|
+
* a pluggable adapter system. Uses oxmysql by default.
|
|
29
|
+
*/
|
|
30
|
+
export declare class DatabaseService extends DatabaseContract {
|
|
31
|
+
private adapter;
|
|
32
|
+
private config;
|
|
33
|
+
private isInitialized;
|
|
34
|
+
/**
|
|
35
|
+
* Initialize the database service with optional configuration
|
|
36
|
+
*
|
|
37
|
+
* @param config - Database configuration options
|
|
38
|
+
*/
|
|
39
|
+
initialize(config?: DatabaseConfig): void;
|
|
40
|
+
/**
|
|
41
|
+
* Check if the service is initialized
|
|
42
|
+
*/
|
|
43
|
+
get initialized(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Register a custom database adapter
|
|
46
|
+
*
|
|
47
|
+
* @param adapter - Custom adapter implementing DatabaseContract
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* class CustomAdapter extends DatabaseContract {
|
|
52
|
+
* // Implementation
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* db.setAdapter(new CustomAdapter())
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
setAdapter(adapter: DatabaseContract): void;
|
|
59
|
+
/**
|
|
60
|
+
* Get the current adapter
|
|
61
|
+
*/
|
|
62
|
+
getAdapter(): DatabaseContract;
|
|
63
|
+
/**
|
|
64
|
+
* Ensure the service is initialized before operations
|
|
65
|
+
*/
|
|
66
|
+
private ensureInitialized;
|
|
67
|
+
/**
|
|
68
|
+
* Execute a query and return all matching rows
|
|
69
|
+
*/
|
|
70
|
+
query<T = any>(sql: string, params?: any[]): Promise<T[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Execute a query and return a single row
|
|
73
|
+
*/
|
|
74
|
+
single<T = any>(sql: string, params?: any[]): Promise<T | null>;
|
|
75
|
+
/**
|
|
76
|
+
* Execute a query and return a single scalar value
|
|
77
|
+
*/
|
|
78
|
+
scalar<T = any>(sql: string, params?: any[]): Promise<T | null>;
|
|
79
|
+
/**
|
|
80
|
+
* Execute an UPDATE or DELETE statement
|
|
81
|
+
*/
|
|
82
|
+
execute(sql: string, params?: any[]): Promise<ExecuteResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Execute an INSERT statement
|
|
85
|
+
*/
|
|
86
|
+
insert(sql: string, params?: any[]): Promise<InsertResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Execute multiple queries within a transaction
|
|
89
|
+
*/
|
|
90
|
+
transaction(queries: TransactionInput, sharedParams?: TransactionSharedParams): Promise<boolean>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the global DatabaseService instance
|
|
94
|
+
*
|
|
95
|
+
* @returns The singleton DatabaseService instance
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import { getDatabaseService } from '@open-core/framework/server'
|
|
100
|
+
*
|
|
101
|
+
* const db = getDatabaseService()
|
|
102
|
+
* const users = await db.query('SELECT * FROM users')
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function getDatabaseService(): DatabaseService;
|
|
106
|
+
/**
|
|
107
|
+
* Initialize the database service
|
|
108
|
+
*
|
|
109
|
+
* @param config - Database configuration options
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* import { initDatabase } from '@open-core/framework/server'
|
|
114
|
+
*
|
|
115
|
+
* // Initialize with default oxmysql adapter
|
|
116
|
+
* initDatabase()
|
|
117
|
+
*
|
|
118
|
+
* // Or with custom config
|
|
119
|
+
* initDatabase({ debug: true })
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function initDatabase(config?: DatabaseConfig): void;
|
|
123
|
+
/**
|
|
124
|
+
* Standalone query function
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import { query } from '@open-core/framework/server'
|
|
129
|
+
*
|
|
130
|
+
* const users = await query<User>('SELECT * FROM users WHERE active = ?', [true])
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function query<T = any>(sql: string, params?: any[]): Promise<T[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Standalone single function
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* import { single } from '@open-core/framework/server'
|
|
140
|
+
*
|
|
141
|
+
* const user = await single<User>('SELECT * FROM users WHERE id = ?', [userId])
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function single<T = any>(sql: string, params?: any[]): Promise<T | null>;
|
|
145
|
+
/**
|
|
146
|
+
* Standalone scalar function
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* import { scalar } from '@open-core/framework/server'
|
|
151
|
+
*
|
|
152
|
+
* const count = await scalar<number>('SELECT COUNT(*) FROM users')
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function scalar<T = any>(sql: string, params?: any[]): Promise<T | null>;
|
|
156
|
+
/**
|
|
157
|
+
* Standalone execute function
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* import { execute } from '@open-core/framework/server'
|
|
162
|
+
*
|
|
163
|
+
* const result = await execute('UPDATE users SET active = ? WHERE id = ?', [false, userId])
|
|
164
|
+
* console.log(`Updated ${result.affectedRows} rows`)
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function execute(sql: string, params?: any[]): Promise<ExecuteResult>;
|
|
168
|
+
/**
|
|
169
|
+
* Standalone insert function
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import { insert } from '@open-core/framework/server'
|
|
174
|
+
*
|
|
175
|
+
* const result = await insert('INSERT INTO users (name) VALUES (?)', ['John'])
|
|
176
|
+
* console.log(`Inserted with ID: ${result.insertId}`)
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function insert(sql: string, params?: any[]): Promise<InsertResult>;
|
|
180
|
+
/**
|
|
181
|
+
* Standalone transaction function
|
|
182
|
+
*
|
|
183
|
+
* Execute multiple queries atomically. All succeed or all fail.
|
|
184
|
+
*
|
|
185
|
+
* @example Specific format (each query has its own params)
|
|
186
|
+
* ```typescript
|
|
187
|
+
* import { transaction } from '@open-core/framework/server'
|
|
188
|
+
*
|
|
189
|
+
* const success = await transaction([
|
|
190
|
+
* { query: 'INSERT INTO users (name) VALUES (?)', values: ['John'] },
|
|
191
|
+
* { query: 'INSERT INTO logs (action) VALUES (?)', values: ['user_created'] },
|
|
192
|
+
* ])
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @example Tuple format
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const success = await transaction([
|
|
198
|
+
* ['INSERT INTO users (name) VALUES (?)', ['John']],
|
|
199
|
+
* ['INSERT INTO logs (action) VALUES (?)', ['user_created']],
|
|
200
|
+
* ])
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @example Shared format (named parameters)
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const success = await transaction(
|
|
206
|
+
* [
|
|
207
|
+
* 'INSERT INTO users (id, name) VALUES (@userid, @username)',
|
|
208
|
+
* 'INSERT INTO profiles (user_id) VALUES (@userid)',
|
|
209
|
+
* ],
|
|
210
|
+
* { userid: 1, username: 'John' }
|
|
211
|
+
* )
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @see https://coxdocs.dev/oxmysql/Functions/transaction
|
|
215
|
+
*/
|
|
216
|
+
export declare function transaction(queries: TransactionInput, sharedParams?: TransactionSharedParams): Promise<boolean>;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Database Service
|
|
4
|
+
*
|
|
5
|
+
* Main entry point for database operations. Acts as a factory/wrapper
|
|
6
|
+
* that delegates to the registered database adapter.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { DatabaseService } from '@open-core/framework/server'
|
|
11
|
+
* import { inject, injectable } from 'tsyringe'
|
|
12
|
+
*
|
|
13
|
+
* @injectable()
|
|
14
|
+
* class UserService {
|
|
15
|
+
* constructor(@inject(DatabaseService) private db: DatabaseService) {}
|
|
16
|
+
*
|
|
17
|
+
* async getUser(id: number) {
|
|
18
|
+
* return this.db.single<User>('SELECT * FROM users WHERE id = ?', [id])
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
24
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
25
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
26
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
27
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.DatabaseService = void 0;
|
|
31
|
+
exports.getDatabaseService = getDatabaseService;
|
|
32
|
+
exports.initDatabase = initDatabase;
|
|
33
|
+
exports.query = query;
|
|
34
|
+
exports.single = single;
|
|
35
|
+
exports.scalar = scalar;
|
|
36
|
+
exports.execute = execute;
|
|
37
|
+
exports.insert = insert;
|
|
38
|
+
exports.transaction = transaction;
|
|
39
|
+
const tsyringe_1 = require("tsyringe");
|
|
40
|
+
const database_contract_1 = require("./database.contract");
|
|
41
|
+
const oxmysql_adapter_1 = require("./adapters/oxmysql.adapter");
|
|
42
|
+
/**
|
|
43
|
+
* Database Service
|
|
44
|
+
*
|
|
45
|
+
* Singleton service that provides database operations through
|
|
46
|
+
* a pluggable adapter system. Uses oxmysql by default.
|
|
47
|
+
*/
|
|
48
|
+
let DatabaseService = class DatabaseService extends database_contract_1.DatabaseContract {
|
|
49
|
+
constructor() {
|
|
50
|
+
super(...arguments);
|
|
51
|
+
this.adapter = null;
|
|
52
|
+
this.config = {};
|
|
53
|
+
this.isInitialized = false;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Initialize the database service with optional configuration
|
|
57
|
+
*
|
|
58
|
+
* @param config - Database configuration options
|
|
59
|
+
*/
|
|
60
|
+
initialize(config = {}) {
|
|
61
|
+
if (this.isInitialized)
|
|
62
|
+
return;
|
|
63
|
+
this.config = config;
|
|
64
|
+
// Use oxmysql by default
|
|
65
|
+
if (!this.adapter) {
|
|
66
|
+
this.adapter = new oxmysql_adapter_1.OxMySQLAdapter();
|
|
67
|
+
}
|
|
68
|
+
this.isInitialized = true;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if the service is initialized
|
|
72
|
+
*/
|
|
73
|
+
get initialized() {
|
|
74
|
+
return this.isInitialized;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Register a custom database adapter
|
|
78
|
+
*
|
|
79
|
+
* @param adapter - Custom adapter implementing DatabaseContract
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* class CustomAdapter extends DatabaseContract {
|
|
84
|
+
* // Implementation
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* db.setAdapter(new CustomAdapter())
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
setAdapter(adapter) {
|
|
91
|
+
this.adapter = adapter;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the current adapter
|
|
95
|
+
*/
|
|
96
|
+
getAdapter() {
|
|
97
|
+
this.ensureInitialized();
|
|
98
|
+
return this.adapter;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Ensure the service is initialized before operations
|
|
102
|
+
*/
|
|
103
|
+
ensureInitialized() {
|
|
104
|
+
if (!this.adapter) {
|
|
105
|
+
// Auto-initialize with defaults if not initialized
|
|
106
|
+
this.initialize();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Execute a query and return all matching rows
|
|
111
|
+
*/
|
|
112
|
+
async query(sql, params) {
|
|
113
|
+
this.ensureInitialized();
|
|
114
|
+
return this.adapter.query(sql, params);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Execute a query and return a single row
|
|
118
|
+
*/
|
|
119
|
+
async single(sql, params) {
|
|
120
|
+
this.ensureInitialized();
|
|
121
|
+
return this.adapter.single(sql, params);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Execute a query and return a single scalar value
|
|
125
|
+
*/
|
|
126
|
+
async scalar(sql, params) {
|
|
127
|
+
this.ensureInitialized();
|
|
128
|
+
return this.adapter.scalar(sql, params);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Execute an UPDATE or DELETE statement
|
|
132
|
+
*/
|
|
133
|
+
async execute(sql, params) {
|
|
134
|
+
this.ensureInitialized();
|
|
135
|
+
return this.adapter.execute(sql, params);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Execute an INSERT statement
|
|
139
|
+
*/
|
|
140
|
+
async insert(sql, params) {
|
|
141
|
+
this.ensureInitialized();
|
|
142
|
+
return this.adapter.insert(sql, params);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Execute multiple queries within a transaction
|
|
146
|
+
*/
|
|
147
|
+
async transaction(queries, sharedParams) {
|
|
148
|
+
this.ensureInitialized();
|
|
149
|
+
return this.adapter.transaction(queries, sharedParams);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
exports.DatabaseService = DatabaseService;
|
|
153
|
+
exports.DatabaseService = DatabaseService = __decorate([
|
|
154
|
+
(0, tsyringe_1.injectable)()
|
|
155
|
+
], DatabaseService);
|
|
156
|
+
// Singleton instance for standalone usage
|
|
157
|
+
let databaseServiceInstance = null;
|
|
158
|
+
/**
|
|
159
|
+
* Get the global DatabaseService instance
|
|
160
|
+
*
|
|
161
|
+
* @returns The singleton DatabaseService instance
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import { getDatabaseService } from '@open-core/framework/server'
|
|
166
|
+
*
|
|
167
|
+
* const db = getDatabaseService()
|
|
168
|
+
* const users = await db.query('SELECT * FROM users')
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
function getDatabaseService() {
|
|
172
|
+
if (!databaseServiceInstance) {
|
|
173
|
+
databaseServiceInstance = new DatabaseService();
|
|
174
|
+
}
|
|
175
|
+
return databaseServiceInstance;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Initialize the database service
|
|
179
|
+
*
|
|
180
|
+
* @param config - Database configuration options
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* import { initDatabase } from '@open-core/framework/server'
|
|
185
|
+
*
|
|
186
|
+
* // Initialize with default oxmysql adapter
|
|
187
|
+
* initDatabase()
|
|
188
|
+
*
|
|
189
|
+
* // Or with custom config
|
|
190
|
+
* initDatabase({ debug: true })
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
function initDatabase(config = {}) {
|
|
194
|
+
getDatabaseService().initialize(config);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Standalone query function
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* import { query } from '@open-core/framework/server'
|
|
202
|
+
*
|
|
203
|
+
* const users = await query<User>('SELECT * FROM users WHERE active = ?', [true])
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
async function query(sql, params) {
|
|
207
|
+
return getDatabaseService().query(sql, params);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Standalone single function
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* import { single } from '@open-core/framework/server'
|
|
215
|
+
*
|
|
216
|
+
* const user = await single<User>('SELECT * FROM users WHERE id = ?', [userId])
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
async function single(sql, params) {
|
|
220
|
+
return getDatabaseService().single(sql, params);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Standalone scalar function
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* import { scalar } from '@open-core/framework/server'
|
|
228
|
+
*
|
|
229
|
+
* const count = await scalar<number>('SELECT COUNT(*) FROM users')
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
async function scalar(sql, params) {
|
|
233
|
+
return getDatabaseService().scalar(sql, params);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Standalone execute function
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* import { execute } from '@open-core/framework/server'
|
|
241
|
+
*
|
|
242
|
+
* const result = await execute('UPDATE users SET active = ? WHERE id = ?', [false, userId])
|
|
243
|
+
* console.log(`Updated ${result.affectedRows} rows`)
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
async function execute(sql, params) {
|
|
247
|
+
return getDatabaseService().execute(sql, params);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Standalone insert function
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* import { insert } from '@open-core/framework/server'
|
|
255
|
+
*
|
|
256
|
+
* const result = await insert('INSERT INTO users (name) VALUES (?)', ['John'])
|
|
257
|
+
* console.log(`Inserted with ID: ${result.insertId}`)
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
async function insert(sql, params) {
|
|
261
|
+
return getDatabaseService().insert(sql, params);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Standalone transaction function
|
|
265
|
+
*
|
|
266
|
+
* Execute multiple queries atomically. All succeed or all fail.
|
|
267
|
+
*
|
|
268
|
+
* @example Specific format (each query has its own params)
|
|
269
|
+
* ```typescript
|
|
270
|
+
* import { transaction } from '@open-core/framework/server'
|
|
271
|
+
*
|
|
272
|
+
* const success = await transaction([
|
|
273
|
+
* { query: 'INSERT INTO users (name) VALUES (?)', values: ['John'] },
|
|
274
|
+
* { query: 'INSERT INTO logs (action) VALUES (?)', values: ['user_created'] },
|
|
275
|
+
* ])
|
|
276
|
+
* ```
|
|
277
|
+
*
|
|
278
|
+
* @example Tuple format
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const success = await transaction([
|
|
281
|
+
* ['INSERT INTO users (name) VALUES (?)', ['John']],
|
|
282
|
+
* ['INSERT INTO logs (action) VALUES (?)', ['user_created']],
|
|
283
|
+
* ])
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @example Shared format (named parameters)
|
|
287
|
+
* ```typescript
|
|
288
|
+
* const success = await transaction(
|
|
289
|
+
* [
|
|
290
|
+
* 'INSERT INTO users (id, name) VALUES (@userid, @username)',
|
|
291
|
+
* 'INSERT INTO profiles (user_id) VALUES (@userid)',
|
|
292
|
+
* ],
|
|
293
|
+
* { userid: 1, username: 'John' }
|
|
294
|
+
* )
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @see https://coxdocs.dev/oxmysql/Functions/transaction
|
|
298
|
+
*/
|
|
299
|
+
async function transaction(queries, sharedParams) {
|
|
300
|
+
return getDatabaseService().transaction(queries, sharedParams);
|
|
301
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Module
|
|
3
|
+
*
|
|
4
|
+
* Provides a flexible database abstraction layer with pluggable adapters.
|
|
5
|
+
* Uses oxmysql by default for FiveM environments.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* DatabaseService,
|
|
11
|
+
* initDatabase,
|
|
12
|
+
* query,
|
|
13
|
+
* single,
|
|
14
|
+
* transaction,
|
|
15
|
+
* } from '@open-core/framework/server'
|
|
16
|
+
*
|
|
17
|
+
* // Option 1: Use standalone functions
|
|
18
|
+
* initDatabase()
|
|
19
|
+
* const users = await query<User>('SELECT * FROM users')
|
|
20
|
+
*
|
|
21
|
+
* // Option 2: Use DI
|
|
22
|
+
* @injectable()
|
|
23
|
+
* class UserService {
|
|
24
|
+
* constructor(@inject(DatabaseService) private db: DatabaseService) {}
|
|
25
|
+
*
|
|
26
|
+
* async findUser(id: number) {
|
|
27
|
+
* return this.db.single<User>('SELECT * FROM users WHERE id = ?', [id])
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* // Option 3: Use transactions (specific format)
|
|
32
|
+
* const success = await transaction([
|
|
33
|
+
* { query: 'INSERT INTO orders (user_id) VALUES (?)', values: [userId] },
|
|
34
|
+
* { query: 'INSERT INTO order_items (order_id, product_id) VALUES (?, ?)', values: [orderId, productId] },
|
|
35
|
+
* ])
|
|
36
|
+
*
|
|
37
|
+
* // Option 4: Use transactions (shared params format)
|
|
38
|
+
* const success = await transaction(
|
|
39
|
+
* [
|
|
40
|
+
* 'INSERT INTO orders (user_id) VALUES (@userid)',
|
|
41
|
+
* 'UPDATE users SET order_count = order_count + 1 WHERE id = @userid',
|
|
42
|
+
* ],
|
|
43
|
+
* { userid: userId }
|
|
44
|
+
* )
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @see https://coxdocs.dev/oxmysql/Functions/transaction
|
|
48
|
+
*/
|
|
49
|
+
export type { DatabaseConfig, ExecuteResult, InsertResult, TransactionQuery, TransactionQueryTuple, TransactionSharedParams, TransactionInput, DatabaseAdapterFactory, } from './types';
|
|
50
|
+
export { DatabaseContract } from './database.contract';
|
|
51
|
+
export { DatabaseService } from './database.service';
|
|
52
|
+
export { getDatabaseService, initDatabase, query, single, scalar, execute, insert, transaction, } from './database.service';
|
|
53
|
+
export { OxMySQLAdapter } from './adapters/oxmysql.adapter';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Database Module
|
|
4
|
+
*
|
|
5
|
+
* Provides a flexible database abstraction layer with pluggable adapters.
|
|
6
|
+
* Uses oxmysql by default for FiveM environments.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import {
|
|
11
|
+
* DatabaseService,
|
|
12
|
+
* initDatabase,
|
|
13
|
+
* query,
|
|
14
|
+
* single,
|
|
15
|
+
* transaction,
|
|
16
|
+
* } from '@open-core/framework/server'
|
|
17
|
+
*
|
|
18
|
+
* // Option 1: Use standalone functions
|
|
19
|
+
* initDatabase()
|
|
20
|
+
* const users = await query<User>('SELECT * FROM users')
|
|
21
|
+
*
|
|
22
|
+
* // Option 2: Use DI
|
|
23
|
+
* @injectable()
|
|
24
|
+
* class UserService {
|
|
25
|
+
* constructor(@inject(DatabaseService) private db: DatabaseService) {}
|
|
26
|
+
*
|
|
27
|
+
* async findUser(id: number) {
|
|
28
|
+
* return this.db.single<User>('SELECT * FROM users WHERE id = ?', [id])
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* // Option 3: Use transactions (specific format)
|
|
33
|
+
* const success = await transaction([
|
|
34
|
+
* { query: 'INSERT INTO orders (user_id) VALUES (?)', values: [userId] },
|
|
35
|
+
* { query: 'INSERT INTO order_items (order_id, product_id) VALUES (?, ?)', values: [orderId, productId] },
|
|
36
|
+
* ])
|
|
37
|
+
*
|
|
38
|
+
* // Option 4: Use transactions (shared params format)
|
|
39
|
+
* const success = await transaction(
|
|
40
|
+
* [
|
|
41
|
+
* 'INSERT INTO orders (user_id) VALUES (@userid)',
|
|
42
|
+
* 'UPDATE users SET order_count = order_count + 1 WHERE id = @userid',
|
|
43
|
+
* ],
|
|
44
|
+
* { userid: userId }
|
|
45
|
+
* )
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @see https://coxdocs.dev/oxmysql/Functions/transaction
|
|
49
|
+
*/
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.OxMySQLAdapter = exports.transaction = exports.insert = exports.execute = exports.scalar = exports.single = exports.query = exports.initDatabase = exports.getDatabaseService = exports.DatabaseService = exports.DatabaseContract = void 0;
|
|
52
|
+
// Contract
|
|
53
|
+
var database_contract_1 = require("./database.contract");
|
|
54
|
+
Object.defineProperty(exports, "DatabaseContract", { enumerable: true, get: function () { return database_contract_1.DatabaseContract; } });
|
|
55
|
+
// Service
|
|
56
|
+
var database_service_1 = require("./database.service");
|
|
57
|
+
Object.defineProperty(exports, "DatabaseService", { enumerable: true, get: function () { return database_service_1.DatabaseService; } });
|
|
58
|
+
// Standalone functions
|
|
59
|
+
var database_service_2 = require("./database.service");
|
|
60
|
+
Object.defineProperty(exports, "getDatabaseService", { enumerable: true, get: function () { return database_service_2.getDatabaseService; } });
|
|
61
|
+
Object.defineProperty(exports, "initDatabase", { enumerable: true, get: function () { return database_service_2.initDatabase; } });
|
|
62
|
+
Object.defineProperty(exports, "query", { enumerable: true, get: function () { return database_service_2.query; } });
|
|
63
|
+
Object.defineProperty(exports, "single", { enumerable: true, get: function () { return database_service_2.single; } });
|
|
64
|
+
Object.defineProperty(exports, "scalar", { enumerable: true, get: function () { return database_service_2.scalar; } });
|
|
65
|
+
Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return database_service_2.execute; } });
|
|
66
|
+
Object.defineProperty(exports, "insert", { enumerable: true, get: function () { return database_service_2.insert; } });
|
|
67
|
+
Object.defineProperty(exports, "transaction", { enumerable: true, get: function () { return database_service_2.transaction; } });
|
|
68
|
+
// Adapters
|
|
69
|
+
var oxmysql_adapter_1 = require("./adapters/oxmysql.adapter");
|
|
70
|
+
Object.defineProperty(exports, "OxMySQLAdapter", { enumerable: true, get: function () { return oxmysql_adapter_1.OxMySQLAdapter; } });
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Module Types
|
|
3
|
+
*
|
|
4
|
+
* Core types for the database abstraction layer.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Result of an execute/update operation
|
|
8
|
+
*/
|
|
9
|
+
export interface ExecuteResult {
|
|
10
|
+
/** Number of rows affected by the operation */
|
|
11
|
+
affectedRows: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Result of an insert operation
|
|
15
|
+
*/
|
|
16
|
+
export interface InsertResult {
|
|
17
|
+
/** The auto-generated ID of the inserted row */
|
|
18
|
+
insertId: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Configuration for database adapters
|
|
22
|
+
*/
|
|
23
|
+
export interface DatabaseConfig {
|
|
24
|
+
/** Adapter identifier (e.g., 'oxmysql', 'mysql-async') */
|
|
25
|
+
adapter?: string;
|
|
26
|
+
/** Enable debug logging */
|
|
27
|
+
debug?: boolean;
|
|
28
|
+
/** Connection timeout in milliseconds */
|
|
29
|
+
timeout?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Transaction query definition for oxmysql (specific format)
|
|
33
|
+
*
|
|
34
|
+
* @see https://coxdocs.dev/oxmysql/Functions/transaction
|
|
35
|
+
*/
|
|
36
|
+
export interface TransactionQuery {
|
|
37
|
+
query: string;
|
|
38
|
+
/** Parameter values for the query (oxmysql uses 'values') */
|
|
39
|
+
values?: any[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Transaction query as tuple format [query, values]
|
|
43
|
+
*/
|
|
44
|
+
export type TransactionQueryTuple = [string, any[]?];
|
|
45
|
+
/**
|
|
46
|
+
* Shared parameters for transaction queries (named parameters format)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const params: TransactionSharedParams = {
|
|
51
|
+
* someid: 2,
|
|
52
|
+
* somename: 'John Doe',
|
|
53
|
+
* newname: 'John Notdoe'
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export interface TransactionSharedParams {
|
|
58
|
+
[key: string]: any;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Transaction input - can be specific format, tuple format, or just strings
|
|
62
|
+
*/
|
|
63
|
+
export type TransactionInput = TransactionQuery[] | TransactionQueryTuple[] | string[];
|
|
64
|
+
/**
|
|
65
|
+
* Database adapter factory function type
|
|
66
|
+
*/
|
|
67
|
+
export type DatabaseAdapterFactory = () => import('./database.contract').DatabaseContract;
|