@open-core/framework 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +360 -0
  3. package/dist/client/client-bootstrap.d.ts +1 -0
  4. package/dist/client/client-bootstrap.js +50 -0
  5. package/dist/client/client-container.d.ts +2 -0
  6. package/dist/client/client-container.js +6 -0
  7. package/dist/client/client-core.d.ts +1 -0
  8. package/dist/client/client-core.js +7 -0
  9. package/dist/client/controllers/spawner.controller.d.ts +12 -0
  10. package/dist/client/controllers/spawner.controller.js +51 -0
  11. package/dist/client/decorators/controller.d.ts +3 -0
  12. package/dist/client/decorators/controller.js +14 -0
  13. package/dist/client/decorators/export.d.ts +7 -0
  14. package/dist/client/decorators/export.js +15 -0
  15. package/dist/client/decorators/gameEvent.d.ts +47 -0
  16. package/dist/client/decorators/gameEvent.js +54 -0
  17. package/dist/client/decorators/index.d.ts +10 -0
  18. package/dist/client/decorators/index.js +26 -0
  19. package/dist/client/decorators/interval.d.ts +7 -0
  20. package/dist/client/decorators/interval.js +15 -0
  21. package/dist/client/decorators/key.d.ts +2 -0
  22. package/dist/client/decorators/key.js +10 -0
  23. package/dist/client/decorators/localEvent.d.ts +7 -0
  24. package/dist/client/decorators/localEvent.js +15 -0
  25. package/dist/client/decorators/nui.d.ts +1 -0
  26. package/dist/client/decorators/nui.js +9 -0
  27. package/dist/client/decorators/onNet.d.ts +1 -0
  28. package/dist/client/decorators/onNet.js +9 -0
  29. package/dist/client/decorators/resourceLifecycle.d.ts +11 -0
  30. package/dist/client/decorators/resourceLifecycle.js +24 -0
  31. package/dist/client/decorators/tick.d.ts +1 -0
  32. package/dist/client/decorators/tick.js +9 -0
  33. package/dist/client/index.d.ts +7 -0
  34. package/dist/client/index.js +23 -0
  35. package/dist/client/interfaces/appearance.interface.d.ts +19 -0
  36. package/dist/client/interfaces/appearance.interface.js +2 -0
  37. package/dist/client/player/player.d.ts +262 -0
  38. package/dist/client/player/player.js +480 -0
  39. package/dist/client/player/player.loader.d.ts +1 -0
  40. package/dist/client/player/player.loader.js +22 -0
  41. package/dist/client/services/appearance.service.d.ts +6 -0
  42. package/dist/client/services/appearance.service.js +89 -0
  43. package/dist/client/services/blip.service.d.ts +112 -0
  44. package/dist/client/services/blip.service.js +215 -0
  45. package/dist/client/services/index.d.ts +9 -0
  46. package/dist/client/services/index.js +25 -0
  47. package/dist/client/services/marker.service.d.ts +94 -0
  48. package/dist/client/services/marker.service.js +153 -0
  49. package/dist/client/services/notification.service.d.ts +76 -0
  50. package/dist/client/services/notification.service.js +111 -0
  51. package/dist/client/services/ped.service.d.ts +182 -0
  52. package/dist/client/services/ped.service.js +302 -0
  53. package/dist/client/services/progress.service.d.ts +82 -0
  54. package/dist/client/services/progress.service.js +210 -0
  55. package/dist/client/services/spawn.service.d.ts +73 -0
  56. package/dist/client/services/spawn.service.js +261 -0
  57. package/dist/client/services/streaming.service.d.ts +165 -0
  58. package/dist/client/services/streaming.service.js +341 -0
  59. package/dist/client/services/textui.service.d.ts +82 -0
  60. package/dist/client/services/textui.service.js +156 -0
  61. package/dist/client/services/vehicle.service.d.ts +168 -0
  62. package/dist/client/services/vehicle.service.js +296 -0
  63. package/dist/client/system/metadata-client.keys.d.ts +13 -0
  64. package/dist/client/system/metadata-client.keys.js +16 -0
  65. package/dist/client/system/processors/export.processor.d.ts +7 -0
  66. package/dist/client/system/processors/export.processor.js +39 -0
  67. package/dist/client/system/processors/gameEvent.processor.d.ts +10 -0
  68. package/dist/client/system/processors/gameEvent.processor.js +58 -0
  69. package/dist/client/system/processors/interval.processor.d.ts +7 -0
  70. package/dist/client/system/processors/interval.processor.js +43 -0
  71. package/dist/client/system/processors/key.processor.d.ts +8 -0
  72. package/dist/client/system/processors/key.processor.js +27 -0
  73. package/dist/client/system/processors/localEvent.processor.d.ts +7 -0
  74. package/dist/client/system/processors/localEvent.processor.js +38 -0
  75. package/dist/client/system/processors/netEvent.processor.d.ts +7 -0
  76. package/dist/client/system/processors/netEvent.processor.js +38 -0
  77. package/dist/client/system/processors/nui.processor.d.ts +7 -0
  78. package/dist/client/system/processors/nui.processor.js +40 -0
  79. package/dist/client/system/processors/resourceLifecycle.processor.d.ts +9 -0
  80. package/dist/client/system/processors/resourceLifecycle.processor.js +69 -0
  81. package/dist/client/system/processors/tick.processor.d.ts +5 -0
  82. package/dist/client/system/processors/tick.processor.js +37 -0
  83. package/dist/client/system/processors.register.d.ts +1 -0
  84. package/dist/client/system/processors.register.js +27 -0
  85. package/dist/client/types/game-events.d.ts +126 -0
  86. package/dist/client/types/game-events.js +83 -0
  87. package/dist/client/types/index.d.ts +1 -0
  88. package/dist/client/types/index.js +17 -0
  89. package/dist/client/ui-bridge.d.ts +116 -0
  90. package/dist/client/ui-bridge.js +201 -0
  91. package/dist/index.d.ts +5 -0
  92. package/dist/index.js +41 -0
  93. package/dist/server/bootstrap.d.ts +16 -0
  94. package/dist/server/bootstrap.js +57 -0
  95. package/dist/server/bus/core-event-bus.d.ts +6 -0
  96. package/dist/server/bus/core-event-bus.js +31 -0
  97. package/dist/server/configs/api.config.d.ts +71 -0
  98. package/dist/server/configs/api.config.js +81 -0
  99. package/dist/server/configs/config.base.d.ts +63 -0
  100. package/dist/server/configs/config.base.js +64 -0
  101. package/dist/server/configs/index.d.ts +2 -0
  102. package/dist/server/configs/index.js +18 -0
  103. package/dist/server/container.d.ts +2 -0
  104. package/dist/server/container.js +6 -0
  105. package/dist/server/controllers/chat.controller.d.ts +10 -0
  106. package/dist/server/controllers/chat.controller.js +50 -0
  107. package/dist/server/controllers/command.controller.d.ts +7 -0
  108. package/dist/server/controllers/command.controller.js +47 -0
  109. package/dist/server/controllers/session.controller.d.ts +9 -0
  110. package/dist/server/controllers/session.controller.js +70 -0
  111. package/dist/server/core.d.ts +1 -0
  112. package/dist/server/core.js +7 -0
  113. package/dist/server/database/adapters/oxmysql.adapter.d.ts +89 -0
  114. package/dist/server/database/adapters/oxmysql.adapter.js +149 -0
  115. package/dist/server/database/database.contract.d.ts +128 -0
  116. package/dist/server/database/database.contract.js +29 -0
  117. package/dist/server/database/database.service.d.ts +216 -0
  118. package/dist/server/database/database.service.js +301 -0
  119. package/dist/server/database/index.d.ts +53 -0
  120. package/dist/server/database/index.js +70 -0
  121. package/dist/server/database/types.d.ts +67 -0
  122. package/dist/server/database/types.js +7 -0
  123. package/dist/server/database.d.ts +7 -0
  124. package/dist/server/database.js +23 -0
  125. package/dist/server/decorators/bind.d.ts +2 -0
  126. package/dist/server/decorators/bind.js +15 -0
  127. package/dist/server/decorators/command.d.ts +49 -0
  128. package/dist/server/decorators/command.js +23 -0
  129. package/dist/server/decorators/controller.d.ts +25 -0
  130. package/dist/server/decorators/controller.js +36 -0
  131. package/dist/server/decorators/export.d.ts +39 -0
  132. package/dist/server/decorators/export.js +47 -0
  133. package/dist/server/decorators/guard.d.ts +56 -0
  134. package/dist/server/decorators/guard.js +82 -0
  135. package/dist/server/decorators/index.d.ts +10 -0
  136. package/dist/server/decorators/index.js +29 -0
  137. package/dist/server/decorators/onFiveMEvent.d.ts +6 -0
  138. package/dist/server/decorators/onFiveMEvent.js +14 -0
  139. package/dist/server/decorators/onFrameworkEvent.d.ts +22 -0
  140. package/dist/server/decorators/onFrameworkEvent.js +29 -0
  141. package/dist/server/decorators/onNet.d.ts +58 -0
  142. package/dist/server/decorators/onNet.js +57 -0
  143. package/dist/server/decorators/onTick.d.ts +32 -0
  144. package/dist/server/decorators/onTick.js +40 -0
  145. package/dist/server/decorators/public.d.ts +27 -0
  146. package/dist/server/decorators/public.js +36 -0
  147. package/dist/server/decorators/requiresState.d.ts +56 -0
  148. package/dist/server/decorators/requiresState.js +63 -0
  149. package/dist/server/decorators/throttle.d.ts +48 -0
  150. package/dist/server/decorators/throttle.js +63 -0
  151. package/dist/server/decorators/utils.d.ts +57 -0
  152. package/dist/server/decorators/utils.js +63 -0
  153. package/dist/server/entities/index.d.ts +1 -0
  154. package/dist/server/entities/index.js +17 -0
  155. package/dist/server/entities/player.d.ts +157 -0
  156. package/dist/server/entities/player.js +217 -0
  157. package/dist/server/error-handler.d.ts +2 -0
  158. package/dist/server/error-handler.js +43 -0
  159. package/dist/server/helpers/resolve-method.d.ts +5 -0
  160. package/dist/server/helpers/resolve-method.js +18 -0
  161. package/dist/server/index.d.ts +10 -0
  162. package/dist/server/index.js +31 -0
  163. package/dist/server/loaders/exports.loader.d.ts +0 -0
  164. package/dist/server/loaders/exports.loader.js +23 -0
  165. package/dist/server/loaders/playerSession.loader.d.ts +1 -0
  166. package/dist/server/loaders/playerSession.loader.js +51 -0
  167. package/dist/server/services/access-control.service.d.ts +56 -0
  168. package/dist/server/services/access-control.service.js +99 -0
  169. package/dist/server/services/chat.service.d.ts +7 -0
  170. package/dist/server/services/chat.service.js +31 -0
  171. package/dist/server/services/command.service.d.ts +15 -0
  172. package/dist/server/services/command.service.js +77 -0
  173. package/dist/server/services/config.service.d.ts +75 -0
  174. package/dist/server/services/config.service.js +116 -0
  175. package/dist/server/services/default/default-security.handler.d.ts +6 -0
  176. package/dist/server/services/default/default-security.handler.js +26 -0
  177. package/dist/server/services/http/http.service.d.ts +50 -0
  178. package/dist/server/services/http/http.service.js +126 -0
  179. package/dist/server/services/index.d.ts +10 -0
  180. package/dist/server/services/index.js +26 -0
  181. package/dist/server/services/parallel/index.d.ts +49 -0
  182. package/dist/server/services/parallel/index.js +67 -0
  183. package/dist/server/services/parallel/parallel-compute.service.d.ts +132 -0
  184. package/dist/server/services/parallel/parallel-compute.service.js +449 -0
  185. package/dist/server/services/parallel/types.d.ts +188 -0
  186. package/dist/server/services/parallel/types.js +7 -0
  187. package/dist/server/services/parallel/worker-pool.d.ts +83 -0
  188. package/dist/server/services/parallel/worker-pool.js +350 -0
  189. package/dist/server/services/parallel/worker.d.ts +19 -0
  190. package/dist/server/services/parallel/worker.js +49 -0
  191. package/dist/server/services/persistence.service.d.ts +59 -0
  192. package/dist/server/services/persistence.service.js +166 -0
  193. package/dist/server/services/player.service.d.ts +96 -0
  194. package/dist/server/services/player.service.js +132 -0
  195. package/dist/server/services/rate-limiter.service.d.ts +5 -0
  196. package/dist/server/services/rate-limiter.service.js +39 -0
  197. package/dist/server/services/registers.d.ts +1 -0
  198. package/dist/server/services/registers.js +18 -0
  199. package/dist/server/setup.d.ts +9 -0
  200. package/dist/server/setup.js +28 -0
  201. package/dist/server/system/metadata-server.keys.d.ts +10 -0
  202. package/dist/server/system/metadata-server.keys.js +13 -0
  203. package/dist/server/system/processors/command.processor.d.ts +9 -0
  204. package/dist/server/system/processors/command.processor.js +30 -0
  205. package/dist/server/system/processors/coreEvent.processor.d.ts +7 -0
  206. package/dist/server/system/processors/coreEvent.processor.js +41 -0
  207. package/dist/server/system/processors/export.processor.d.ts +7 -0
  208. package/dist/server/system/processors/export.processor.js +30 -0
  209. package/dist/server/system/processors/fivemEvent.processor.d.ts +7 -0
  210. package/dist/server/system/processors/fivemEvent.processor.js +40 -0
  211. package/dist/server/system/processors/netEvent.processor.d.ts +11 -0
  212. package/dist/server/system/processors/netEvent.processor.js +103 -0
  213. package/dist/server/system/processors/tick.processor.d.ts +5 -0
  214. package/dist/server/system/processors/tick.processor.js +36 -0
  215. package/dist/server/system/processors.register.d.ts +1 -0
  216. package/dist/server/system/processors.register.js +23 -0
  217. package/dist/server/system/schema-generator.d.ts +2 -0
  218. package/dist/server/system/schema-generator.js +34 -0
  219. package/dist/server/templates/admin/admin.controller-template.d.ts +12 -0
  220. package/dist/server/templates/admin/admin.controller-template.js +2 -0
  221. package/dist/server/templates/auth/auth-provider.contract.d.ts +58 -0
  222. package/dist/server/templates/auth/auth-provider.contract.js +23 -0
  223. package/dist/server/templates/index.d.ts +8 -0
  224. package/dist/server/templates/index.js +21 -0
  225. package/dist/server/templates/persistence/index.d.ts +30 -0
  226. package/dist/server/templates/persistence/index.js +34 -0
  227. package/dist/server/templates/persistence/player-persistence.contract.d.ts +86 -0
  228. package/dist/server/templates/persistence/player-persistence.contract.js +52 -0
  229. package/dist/server/templates/repository/index.d.ts +57 -0
  230. package/dist/server/templates/repository/index.js +61 -0
  231. package/dist/server/templates/repository/repository.contract.d.ts +224 -0
  232. package/dist/server/templates/repository/repository.contract.js +342 -0
  233. package/dist/server/templates/repository/repository.types.d.ts +51 -0
  234. package/dist/server/templates/repository/repository.types.js +7 -0
  235. package/dist/server/templates/security/permission.types.d.ts +32 -0
  236. package/dist/server/templates/security/permission.types.js +2 -0
  237. package/dist/server/templates/security/principal-provider.contract.d.ts +43 -0
  238. package/dist/server/templates/security/principal-provider.contract.js +19 -0
  239. package/dist/server/templates/security/security-handler.contract.d.ts +5 -0
  240. package/dist/server/templates/security/security-handler.contract.js +6 -0
  241. package/dist/server/types/core-events.d.ts +22 -0
  242. package/dist/server/types/core-events.js +2 -0
  243. package/dist/server/types/security.types.d.ts +7 -0
  244. package/dist/server/types/security.types.js +2 -0
  245. package/dist/shared/index.d.ts +1 -0
  246. package/dist/shared/index.js +17 -0
  247. package/dist/shared/logger/core-logger.d.ts +35 -0
  248. package/dist/shared/logger/core-logger.js +52 -0
  249. package/dist/shared/logger/index.d.ts +11 -0
  250. package/dist/shared/logger/index.js +26 -0
  251. package/dist/shared/logger/logger.config.d.ts +47 -0
  252. package/dist/shared/logger/logger.config.js +33 -0
  253. package/dist/shared/logger/logger.service.d.ts +161 -0
  254. package/dist/shared/logger/logger.service.js +279 -0
  255. package/dist/shared/logger/logger.types.d.ts +85 -0
  256. package/dist/shared/logger/logger.types.js +74 -0
  257. package/dist/shared/logger/transports/buffered.transport.d.ts +88 -0
  258. package/dist/shared/logger/transports/buffered.transport.js +174 -0
  259. package/dist/shared/logger/transports/console.transport.d.ts +37 -0
  260. package/dist/shared/logger/transports/console.transport.js +134 -0
  261. package/dist/shared/logger/transports/index.d.ts +3 -0
  262. package/dist/shared/logger/transports/index.js +19 -0
  263. package/dist/shared/logger/transports/transport.interface.d.ts +40 -0
  264. package/dist/shared/logger/transports/transport.interface.js +2 -0
  265. package/dist/system/class-constructor.d.ts +1 -0
  266. package/dist/system/class-constructor.js +2 -0
  267. package/dist/system/decorator-processor.d.ts +4 -0
  268. package/dist/system/decorator-processor.js +2 -0
  269. package/dist/system/metadata.scanner.d.ts +7 -0
  270. package/dist/system/metadata.scanner.js +45 -0
  271. package/dist/utils/errors.d.ts +14 -0
  272. package/dist/utils/errors.js +25 -0
  273. package/dist/utils/index.d.ts +4 -0
  274. package/dist/utils/index.js +20 -0
  275. package/dist/utils/result.d.ts +12 -0
  276. package/dist/utils/result.js +10 -0
  277. package/dist/utils/rgb.d.ts +5 -0
  278. package/dist/utils/rgb.js +2 -0
  279. package/dist/utils/vector3.d.ts +13 -0
  280. package/dist/utils/vector3.js +27 -0
  281. package/package.json +98 -0
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ /**
3
+ * OxMySQL Adapter
4
+ *
5
+ * Default database adapter using oxmysql resource for FiveM.
6
+ * Requires oxmysql to be installed and running on the server.
7
+ *
8
+ * @see https://github.com/overextended/oxmysql
9
+ * @see https://coxdocs.dev/oxmysql/Functions/transaction
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OxMySQLAdapter = void 0;
13
+ const database_contract_1 = require("../database.contract");
14
+ /**
15
+ * Get the oxmysql export from FiveM
16
+ */
17
+ function getOxMySQL() {
18
+ const ox = exports['oxmysql'];
19
+ if (!ox) {
20
+ throw new Error('[OpenCore] oxmysql is not available. Make sure oxmysql resource is started before your resource.');
21
+ }
22
+ return ox;
23
+ }
24
+ /**
25
+ * Normalize transaction input to oxmysql format
26
+ */
27
+ function normalizeQueries(queries) {
28
+ if (queries.length === 0)
29
+ return [];
30
+ const first = queries[0];
31
+ // String array - used with shared params
32
+ if (typeof first === 'string') {
33
+ return queries;
34
+ }
35
+ // Tuple format: [query, values]
36
+ if (Array.isArray(first)) {
37
+ return queries.map(([query, values]) => ({
38
+ query,
39
+ values,
40
+ }));
41
+ }
42
+ // Already in TransactionQuery format
43
+ return queries;
44
+ }
45
+ /**
46
+ * OxMySQL Database Adapter
47
+ *
48
+ * Implements DatabaseContract using oxmysql exports.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { OxMySQLAdapter } from '@open-core/framework/server'
53
+ *
54
+ * // Usually you don't need to instantiate directly,
55
+ * // use DatabaseService instead
56
+ * const adapter = new OxMySQLAdapter()
57
+ * const users = await adapter.query('SELECT * FROM users')
58
+ * ```
59
+ */
60
+ class OxMySQLAdapter extends database_contract_1.DatabaseContract {
61
+ constructor() {
62
+ super();
63
+ this.ox = getOxMySQL();
64
+ }
65
+ /**
66
+ * Execute a query and return all matching rows
67
+ */
68
+ async query(sql, params) {
69
+ const result = await this.ox.query_async(sql, params);
70
+ return result !== null && result !== void 0 ? result : [];
71
+ }
72
+ /**
73
+ * Execute a query and return a single row
74
+ */
75
+ async single(sql, params) {
76
+ const result = await this.ox.single_async(sql, params);
77
+ return result !== null && result !== void 0 ? result : null;
78
+ }
79
+ /**
80
+ * Execute a query and return a single scalar value
81
+ */
82
+ async scalar(sql, params) {
83
+ const result = await this.ox.scalar_async(sql, params);
84
+ return result !== null && result !== void 0 ? result : null;
85
+ }
86
+ /**
87
+ * Execute an UPDATE or DELETE statement
88
+ */
89
+ async execute(sql, params) {
90
+ const affectedRows = await this.ox.update_async(sql, params);
91
+ return { affectedRows: affectedRows !== null && affectedRows !== void 0 ? affectedRows : 0 };
92
+ }
93
+ /**
94
+ * Execute an INSERT statement
95
+ */
96
+ async insert(sql, params) {
97
+ const insertId = await this.ox.insert_async(sql, params);
98
+ return { insertId: insertId !== null && insertId !== void 0 ? insertId : 0 };
99
+ }
100
+ /**
101
+ * Execute multiple queries within a transaction.
102
+ *
103
+ * Supports three formats:
104
+ *
105
+ * **1. Specific format (object)**
106
+ * ```typescript
107
+ * await db.transaction([
108
+ * { query: 'INSERT INTO test (id) VALUES (?)', values: [1] },
109
+ * { query: 'INSERT INTO test (id, name) VALUES (?, ?)', values: [2, 'bob'] },
110
+ * ])
111
+ * ```
112
+ *
113
+ * **2. Specific format (tuple)**
114
+ * ```typescript
115
+ * await db.transaction([
116
+ * ['INSERT INTO test (id) VALUES (?)', [1]],
117
+ * ['INSERT INTO test (id, name) VALUES (?, ?)', [2, 'bob']],
118
+ * ])
119
+ * ```
120
+ *
121
+ * **3. Shared format (named parameters)**
122
+ * ```typescript
123
+ * await db.transaction(
124
+ * [
125
+ * 'INSERT INTO test (id, name) VALUES (@someid, @somename)',
126
+ * 'UPDATE test SET name = @newname WHERE id = @someid',
127
+ * ],
128
+ * {
129
+ * someid: 2,
130
+ * somename: 'John Doe',
131
+ * newname: 'John Notdoe',
132
+ * }
133
+ * )
134
+ * ```
135
+ *
136
+ * @see https://coxdocs.dev/oxmysql/Functions/transaction
137
+ */
138
+ async transaction(queries, sharedParams) {
139
+ if (queries.length === 0)
140
+ return true;
141
+ const normalizedQueries = normalizeQueries(queries);
142
+ // Use shared params format if provided
143
+ if (sharedParams) {
144
+ return await this.ox.transaction_async(normalizedQueries, sharedParams);
145
+ }
146
+ return await this.ox.transaction_async(normalizedQueries);
147
+ }
148
+ }
149
+ exports.OxMySQLAdapter = OxMySQLAdapter;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Database Contract
3
+ *
4
+ * Abstract base class that defines the interface for all database adapters.
5
+ * Implement this contract to create custom database adapters.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * class MyDatabaseAdapter extends DatabaseContract {
10
+ * async query<T>(sql: string, params?: any[]): Promise<T[]> {
11
+ * // Implementation
12
+ * }
13
+ * // ... other methods
14
+ * }
15
+ * ```
16
+ */
17
+ import type { ExecuteResult, InsertResult, TransactionInput, TransactionSharedParams } from './types';
18
+ /**
19
+ * Abstract contract for database adapters.
20
+ *
21
+ * All database adapters must extend this class and implement
22
+ * all abstract methods to ensure consistent behavior across
23
+ * different database backends.
24
+ */
25
+ export declare abstract class DatabaseContract {
26
+ /**
27
+ * Execute a query and return all matching rows.
28
+ *
29
+ * @param sql - The SQL query string
30
+ * @param params - Optional parameters for prepared statement
31
+ * @returns Array of results
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const users = await db.query<User>('SELECT * FROM users WHERE active = ?', [true])
36
+ * ```
37
+ */
38
+ abstract query<T = any>(sql: string, params?: any[]): Promise<T[]>;
39
+ /**
40
+ * Execute a query and return a single row.
41
+ *
42
+ * @param sql - The SQL query string
43
+ * @param params - Optional parameters for prepared statement
44
+ * @returns Single result or null if not found
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const user = await db.single<User>('SELECT * FROM users WHERE id = ?', [userId])
49
+ * if (user) {
50
+ * console.log(user.name)
51
+ * }
52
+ * ```
53
+ */
54
+ abstract single<T = any>(sql: string, params?: any[]): Promise<T | null>;
55
+ /**
56
+ * Execute a query and return a single scalar value.
57
+ *
58
+ * @param sql - The SQL query string
59
+ * @param params - Optional parameters for prepared statement
60
+ * @returns Scalar value or null if not found
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const count = await db.scalar<number>('SELECT COUNT(*) FROM users')
65
+ * const name = await db.scalar<string>('SELECT name FROM users WHERE id = ?', [userId])
66
+ * ```
67
+ */
68
+ abstract scalar<T = any>(sql: string, params?: any[]): Promise<T | null>;
69
+ /**
70
+ * Execute an UPDATE or DELETE statement.
71
+ *
72
+ * @param sql - The SQL statement
73
+ * @param params - Optional parameters for prepared statement
74
+ * @returns Object containing affected rows count
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const result = await db.execute('UPDATE users SET active = ? WHERE id = ?', [false, userId])
79
+ * console.log(`Updated ${result.affectedRows} rows`)
80
+ * ```
81
+ */
82
+ abstract execute(sql: string, params?: any[]): Promise<ExecuteResult>;
83
+ /**
84
+ * Execute an INSERT statement.
85
+ *
86
+ * @param sql - The SQL insert statement
87
+ * @param params - Optional parameters for prepared statement
88
+ * @returns Object containing the inserted row ID
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const result = await db.insert('INSERT INTO users (name, email) VALUES (?, ?)', ['John', 'john@example.com'])
93
+ * console.log(`Inserted user with ID: ${result.insertId}`)
94
+ * ```
95
+ */
96
+ abstract insert(sql: string, params?: any[]): Promise<InsertResult>;
97
+ /**
98
+ * Execute multiple queries within a transaction.
99
+ *
100
+ * All queries are committed together if all succeed, or rolled back if any fails.
101
+ *
102
+ * **Specific format** - Each query has its own parameters:
103
+ * ```typescript
104
+ * await db.transaction([
105
+ * { query: 'INSERT INTO users (name) VALUES (?)', values: ['John'] },
106
+ * { query: 'INSERT INTO logs (action) VALUES (?)', values: ['user_created'] },
107
+ * ])
108
+ * ```
109
+ *
110
+ * **Shared format** - All queries share named parameters:
111
+ * ```typescript
112
+ * await db.transaction(
113
+ * [
114
+ * 'INSERT INTO users (id, name) VALUES (@userid, @username)',
115
+ * 'INSERT INTO profiles (user_id) VALUES (@userid)',
116
+ * ],
117
+ * { userid: 1, username: 'John' }
118
+ * )
119
+ * ```
120
+ *
121
+ * @param queries - Array of queries to execute
122
+ * @param sharedParams - Optional shared parameters for all queries (named params format)
123
+ * @returns true if transaction succeeded, false otherwise
124
+ *
125
+ * @see https://coxdocs.dev/oxmysql/Functions/transaction
126
+ */
127
+ abstract transaction(queries: TransactionInput, sharedParams?: TransactionSharedParams): Promise<boolean>;
128
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /**
3
+ * Database Contract
4
+ *
5
+ * Abstract base class that defines the interface for all database adapters.
6
+ * Implement this contract to create custom database adapters.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * class MyDatabaseAdapter extends DatabaseContract {
11
+ * async query<T>(sql: string, params?: any[]): Promise<T[]> {
12
+ * // Implementation
13
+ * }
14
+ * // ... other methods
15
+ * }
16
+ * ```
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.DatabaseContract = void 0;
20
+ /**
21
+ * Abstract contract for database adapters.
22
+ *
23
+ * All database adapters must extend this class and implement
24
+ * all abstract methods to ensure consistent behavior across
25
+ * different database backends.
26
+ */
27
+ class DatabaseContract {
28
+ }
29
+ exports.DatabaseContract = DatabaseContract;
@@ -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>;