@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,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;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Database Module Types
4
+ *
5
+ * Core types for the database abstraction layer.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Database Module Re-export
3
+ *
4
+ * This file re-exports the database module for backwards compatibility.
5
+ * Prefer importing directly from '@open-core/framework/server' or './database/index'
6
+ */
7
+ export * from './database/index';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * Database Module Re-export
19
+ *
20
+ * This file re-exports the database module for backwards compatibility.
21
+ * Prefer importing directly from '@open-core/framework/server' or './database/index'
22
+ */
23
+ __exportStar(require("./database/index"), exports);
@@ -0,0 +1,2 @@
1
+ export type BindingScope = 'singleton' | 'transient';
2
+ export declare function Bind(scope?: BindingScope): (target: any) => void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Bind = Bind;
4
+ const tsyringe_1 = require("tsyringe");
5
+ function Bind(scope = 'singleton') {
6
+ return function (target) {
7
+ (0, tsyringe_1.injectable)()(target);
8
+ if (scope === 'singleton') {
9
+ (0, tsyringe_1.singleton)()(target);
10
+ }
11
+ else {
12
+ (0, tsyringe_1.scoped)(tsyringe_1.Lifecycle.ResolutionScoped)(target);
13
+ }
14
+ };
15
+ }
@@ -0,0 +1,49 @@
1
+ import type { ClassConstructor } from '../../system/class-constructor';
2
+ import type z from 'zod';
3
+ import type { Player } from '../entities/player';
4
+ export interface CommandConfig {
5
+ /**
6
+ * The command name (e.g. "revive", "deposit"), used in chat "/revive"
7
+ */
8
+ command: string;
9
+ /**
10
+ * The command description, maybe "/help revive"
11
+ */
12
+ description?: string;
13
+ /**
14
+ * The command usage, maybe "/revive <player>"
15
+ */
16
+ usage?: string;
17
+ /**
18
+ * The command schema, used to validate the arguments, validated with zod
19
+ * @example
20
+ * ```ts
21
+ * Server.Command({
22
+ * command: 'revive',
23
+ * schema: z.object({
24
+ * player: z.string(),
25
+ * }),
26
+ * })
27
+ * ```
28
+ */
29
+ schema?: z.ZodType;
30
+ }
31
+ export interface CommandMetadata extends CommandConfig {
32
+ methodName: string;
33
+ target: ClassConstructor;
34
+ paramTypes?: any;
35
+ }
36
+ type ServerCommandHandler = (player: Player, ...args: any[]) => any;
37
+ /**
38
+ * Decorator used to mark a controller method as a command.
39
+ * This method will be registered and then executed by the command service.
40
+ * It will depend on the chat you have implemented following the dependency conventions.
41
+ *
42
+ * @param configOrName - The command name (e.g. "revive", "deposit")
43
+ * @validation zod schema
44
+ * @handlerSignature ```ts
45
+ * (player: Server.Player, args: any[]) => any
46
+ * ```
47
+ */
48
+ export declare function Command(configOrName: string | CommandConfig): <T extends ServerCommandHandler>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
49
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Command = Command;
4
+ const metadata_server_keys_1 = require("../system/metadata-server.keys");
5
+ /**
6
+ * Decorator used to mark a controller method as a command.
7
+ * This method will be registered and then executed by the command service.
8
+ * It will depend on the chat you have implemented following the dependency conventions.
9
+ *
10
+ * @param configOrName - The command name (e.g. "revive", "deposit")
11
+ * @validation zod schema
12
+ * @handlerSignature ```ts
13
+ * (player: Server.Player, args: any[]) => any
14
+ * ```
15
+ */
16
+ function Command(configOrName) {
17
+ return (target, propertyKey, descriptor) => {
18
+ const config = typeof configOrName === 'string' ? { command: configOrName } : configOrName;
19
+ const paramTypes = Reflect.getMetadata('design:paramtypes', target, propertyKey);
20
+ const metadata = Object.assign(Object.assign({}, config), { methodName: propertyKey, target: target.constructor, paramTypes });
21
+ Reflect.defineMetadata(metadata_server_keys_1.METADATA_KEYS.COMMAND, metadata, target, propertyKey);
22
+ };
23
+ }
@@ -0,0 +1,25 @@
1
+ import type { ClassConstructor } from '../../system/class-constructor';
2
+ export declare const serverControllerRegistry: ClassConstructor[];
3
+ /**
4
+ * Class decorator used to mark a class as a Server Controller.
5
+ *
6
+ * This decorator performs the following actions:
7
+ * 1. Marks the class as `@injectable` (via tsyringe) for dependency injection.
8
+ * 2. Defines metadata identifying the class as a 'server' type controller.
9
+ * 3. Automatically adds the class constructor to the `serverControllerRegistry`.
10
+ *
11
+ * @returns The decorator function to apply to the class.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { Controller } from '@core/server/decorators'
16
+ *
17
+ * @Server.Controller()
18
+ * export class PlayerController {
19
+ * constructor(private playerService: PlayerService) {
20
+ * // Dependency injection works automatically here
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ export declare function Controller(): (target: ClassConstructor) => void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serverControllerRegistry = void 0;
4
+ exports.Controller = Controller;
5
+ const tsyringe_1 = require("tsyringe");
6
+ const metadata_server_keys_1 = require("../system/metadata-server.keys");
7
+ exports.serverControllerRegistry = [];
8
+ /**
9
+ * Class decorator used to mark a class as a Server Controller.
10
+ *
11
+ * This decorator performs the following actions:
12
+ * 1. Marks the class as `@injectable` (via tsyringe) for dependency injection.
13
+ * 2. Defines metadata identifying the class as a 'server' type controller.
14
+ * 3. Automatically adds the class constructor to the `serverControllerRegistry`.
15
+ *
16
+ * @returns The decorator function to apply to the class.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { Controller } from '@core/server/decorators'
21
+ *
22
+ * @Server.Controller()
23
+ * export class PlayerController {
24
+ * constructor(private playerService: PlayerService) {
25
+ * // Dependency injection works automatically here
26
+ * }
27
+ * }
28
+ * ```
29
+ */
30
+ function Controller() {
31
+ return function (target) {
32
+ (0, tsyringe_1.injectable)()(target);
33
+ Reflect.defineMetadata(metadata_server_keys_1.METADATA_KEYS.CONTROLLER, { type: 'server' }, target);
34
+ exports.serverControllerRegistry.push(target);
35
+ };
36
+ }