@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,116 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ConfigService = void 0;
10
+ const decorators_1 = require("../decorators");
11
+ /**
12
+ * Generic configuration service for accessing FiveM Convars.
13
+ *
14
+ * Provides type-safe access to configuration values with automatic
15
+ * prefix handling and type conversion.
16
+ *
17
+ * All keys are automatically prefixed with `opencore_`.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const config = di.resolve(ConfigService)
22
+ *
23
+ * // Get string value
24
+ * const apiUrl = config.get('api_url', 'http://localhost:3000')
25
+ *
26
+ * // Get number value
27
+ * const timeout = config.getNumber('timeout', 5000)
28
+ *
29
+ * // Get boolean value
30
+ * const debug = config.getBoolean('debug', false)
31
+ *
32
+ * // Get required value (throws if not set)
33
+ * const secretKey = config.getRequired('secret_key')
34
+ *
35
+ * // Get JSON value
36
+ * const settings = config.getJson('settings', { enabled: true })
37
+ * ```
38
+ *
39
+ * @scope Singleton
40
+ */
41
+ let ConfigService = class ConfigService {
42
+ constructor() {
43
+ this.PREFIX = 'opencore_';
44
+ }
45
+ /**
46
+ * Gets a string configuration value.
47
+ *
48
+ * @param key - The configuration key (without prefix)
49
+ * @param defaultValue - Default value if not set
50
+ * @returns The configuration value or default
51
+ */
52
+ get(key, defaultValue) {
53
+ return GetConvar(this.PREFIX + key, defaultValue);
54
+ }
55
+ /**
56
+ * Gets a numeric configuration value.
57
+ *
58
+ * @param key - The configuration key (without prefix)
59
+ * @param defaultValue - Default value if not set or invalid
60
+ * @returns The configuration value as number
61
+ */
62
+ getNumber(key, defaultValue) {
63
+ const value = GetConvar(this.PREFIX + key, String(defaultValue));
64
+ const parsed = Number(value);
65
+ return isNaN(parsed) ? defaultValue : parsed;
66
+ }
67
+ /**
68
+ * Gets a boolean configuration value.
69
+ *
70
+ * Recognizes 'true', '1' as true, everything else as false.
71
+ *
72
+ * @param key - The configuration key (without prefix)
73
+ * @param defaultValue - Default value if not set
74
+ * @returns The configuration value as boolean
75
+ */
76
+ getBoolean(key, defaultValue) {
77
+ const value = GetConvar(this.PREFIX + key, String(defaultValue));
78
+ return value === 'true' || value === '1';
79
+ }
80
+ /**
81
+ * Gets a required configuration value.
82
+ *
83
+ * @param key - The configuration key (without prefix)
84
+ * @returns The configuration value
85
+ * @throws Error if the value is not set
86
+ */
87
+ getRequired(key) {
88
+ const value = GetConvar(this.PREFIX + key, '');
89
+ if (!value) {
90
+ throw new Error(`[OpenCore] Configuration '${this.PREFIX}${key}' is required but not set`);
91
+ }
92
+ return value;
93
+ }
94
+ /**
95
+ * Gets a JSON configuration value.
96
+ *
97
+ * @param key - The configuration key (without prefix)
98
+ * @param defaultValue - Default value if not set or invalid JSON
99
+ * @returns The parsed JSON value or default
100
+ */
101
+ getJson(key, defaultValue) {
102
+ const value = GetConvar(this.PREFIX + key, '');
103
+ if (!value)
104
+ return defaultValue;
105
+ try {
106
+ return JSON.parse(value);
107
+ }
108
+ catch (_a) {
109
+ return defaultValue;
110
+ }
111
+ }
112
+ };
113
+ exports.ConfigService = ConfigService;
114
+ exports.ConfigService = ConfigService = __decorate([
115
+ (0, decorators_1.Bind)('singleton')
116
+ ], ConfigService);
@@ -0,0 +1,6 @@
1
+ import { SecurityHandlerContract } from '../../templates/security/security-handler.contract';
2
+ import { Server } from '../../..';
3
+ import { SecurityError } from '../../../utils/errors';
4
+ export declare class DefaultSecurityHandler extends SecurityHandlerContract {
5
+ handleViolation(player: Server.Player, error: SecurityError): Promise<void>;
6
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DefaultSecurityHandler = void 0;
10
+ const tsyringe_1 = require("tsyringe");
11
+ const security_handler_contract_1 = require("../../templates/security/security-handler.contract");
12
+ const logger_1 = require("../../../shared/logger");
13
+ let DefaultSecurityHandler = class DefaultSecurityHandler extends security_handler_contract_1.SecurityHandlerContract {
14
+ async handleViolation(player, error) {
15
+ logger_1.loggers.security.warn(`Security violation detected`, {
16
+ playerName: player.name,
17
+ playerId: player.clientID,
18
+ message: error.message,
19
+ suggestedAction: error.action,
20
+ });
21
+ }
22
+ };
23
+ exports.DefaultSecurityHandler = DefaultSecurityHandler;
24
+ exports.DefaultSecurityHandler = DefaultSecurityHandler = __decorate([
25
+ (0, tsyringe_1.injectable)()
26
+ ], DefaultSecurityHandler);
@@ -0,0 +1,50 @@
1
+ export interface HttpOptions {
2
+ headers?: Record<string, string>;
3
+ timeoutMs?: number;
4
+ }
5
+ export declare class HttpService {
6
+ /**
7
+ * Performs an HTTP GET request to the specified URL.
8
+ *
9
+ * @template T - The expected return type of the response data.
10
+ * @param url - The endpoint URL to fetch data from.
11
+ * @param options - Optional configuration for the request (headers, timeout).
12
+ * @returns A Promise that resolves to the response data of type T.
13
+ * @throws {AppError} If the request fails, times out, or returns a non-2xx status code.
14
+ */
15
+ get<T = any>(url: string, options?: HttpOptions): Promise<T>;
16
+ /**
17
+ * Performs an HTTP POST request to the specified URL with a JSON payload.
18
+ *
19
+ * @template T - The expected return type of the response data.
20
+ * @param url - The endpoint URL to send data to.
21
+ * @param body - The data payload to be sent as the request body (will be stringified to JSON).
22
+ * @param options - Optional configuration for the request (headers, timeout).
23
+ * @returns A Promise that resolves to the response data of type T.
24
+ * @throws {AppError} If the request fails, times out, or returns a non-2xx status code.
25
+ */
26
+ post<T = any>(url: string, body: any, options?: HttpOptions): Promise<T>;
27
+ /**
28
+ * Performs an HTTP PUT request to the specified URL to update a resource.
29
+ *
30
+ * @template T - The expected return type of the response data.
31
+ * @param url - The endpoint URL to update.
32
+ * @param body - The data payload to be sent as the request body (will be stringified to JSON).
33
+ * @param options - Optional configuration for the request (headers, timeout).
34
+ * @returns A Promise that resolves to the response data of type T.
35
+ * @throws {AppError} If the request fails, times out, or returns a non-2xx status code.
36
+ */
37
+ put<T = any>(url: string, body: any, options?: HttpOptions): Promise<T>;
38
+ /**
39
+ * Performs an HTTP DELETE request to the specified URL.
40
+ *
41
+ * @template T - The expected return type of the response data (often void or the deleted entity).
42
+ * @param url - The endpoint URL to delete the resource from.
43
+ * @param options - Optional configuration for the request (headers, timeout).
44
+ * @returns A Promise that resolves to the response data of type T.
45
+ * @throws {AppError} If the request fails, times out, or returns a non-2xx status code.
46
+ */
47
+ delete<T = any>(url: string, options?: HttpOptions): Promise<T>;
48
+ private request;
49
+ private handleResponse;
50
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.HttpService = void 0;
10
+ const tsyringe_1 = require("tsyringe");
11
+ const utils_1 = require("../../../utils");
12
+ let HttpService = class HttpService {
13
+ /**
14
+ * Performs an HTTP GET request to the specified URL.
15
+ *
16
+ * @template T - The expected return type of the response data.
17
+ * @param url - The endpoint URL to fetch data from.
18
+ * @param options - Optional configuration for the request (headers, timeout).
19
+ * @returns A Promise that resolves to the response data of type T.
20
+ * @throws {AppError} If the request fails, times out, or returns a non-2xx status code.
21
+ */
22
+ async get(url, options = {}) {
23
+ return this.request(url, 'GET', undefined, options);
24
+ }
25
+ /**
26
+ * Performs an HTTP POST request to the specified URL with a JSON payload.
27
+ *
28
+ * @template T - The expected return type of the response data.
29
+ * @param url - The endpoint URL to send data to.
30
+ * @param body - The data payload to be sent as the request body (will be stringified to JSON).
31
+ * @param options - Optional configuration for the request (headers, timeout).
32
+ * @returns A Promise that resolves to the response data of type T.
33
+ * @throws {AppError} If the request fails, times out, or returns a non-2xx status code.
34
+ */
35
+ async post(url, body, options = {}) {
36
+ return this.request(url, 'POST', body, options);
37
+ }
38
+ /**
39
+ * Performs an HTTP PUT request to the specified URL to update a resource.
40
+ *
41
+ * @template T - The expected return type of the response data.
42
+ * @param url - The endpoint URL to update.
43
+ * @param body - The data payload to be sent as the request body (will be stringified to JSON).
44
+ * @param options - Optional configuration for the request (headers, timeout).
45
+ * @returns A Promise that resolves to the response data of type T.
46
+ * @throws {AppError} If the request fails, times out, or returns a non-2xx status code.
47
+ */
48
+ async put(url, body, options = {}) {
49
+ return this.request(url, 'PUT', body, options);
50
+ }
51
+ /**
52
+ * Performs an HTTP DELETE request to the specified URL.
53
+ *
54
+ * @template T - The expected return type of the response data (often void or the deleted entity).
55
+ * @param url - The endpoint URL to delete the resource from.
56
+ * @param options - Optional configuration for the request (headers, timeout).
57
+ * @returns A Promise that resolves to the response data of type T.
58
+ * @throws {AppError} If the request fails, times out, or returns a non-2xx status code.
59
+ */
60
+ async delete(url, options = {}) {
61
+ return this.request(url, 'DELETE', undefined, options);
62
+ }
63
+ async request(url, method, body, options) {
64
+ const { headers = {}, timeoutMs = 5000 } = options;
65
+ const finalHeaders = Object.assign({ 'Content-Type': 'application/json' }, headers);
66
+ const controller = new AbortController();
67
+ const id = setTimeout(() => controller.abort(), timeoutMs);
68
+ try {
69
+ const response = await fetch(url, {
70
+ method,
71
+ headers: finalHeaders,
72
+ body: body ? JSON.stringify(body) : undefined,
73
+ signal: controller.signal,
74
+ });
75
+ return await this.handleResponse(response, method, url);
76
+ }
77
+ catch (err) {
78
+ if (err instanceof utils_1.AppError)
79
+ throw err;
80
+ if (err instanceof DOMException && err.name === 'AbortError') {
81
+ throw new utils_1.AppError('NETWORK_ERROR', `${method} ${url} timed out after ${timeoutMs}ms`, 'external', { timeout: timeoutMs });
82
+ }
83
+ throw new utils_1.AppError('NETWORK_ERROR', `Network error calling ${method} ${url}`, 'external', {
84
+ endpoint: url,
85
+ method,
86
+ cause: err instanceof Error ? err.message : String(err),
87
+ });
88
+ }
89
+ finally {
90
+ clearTimeout(id);
91
+ }
92
+ }
93
+ async handleResponse(response, method, url) {
94
+ if (!response.ok) {
95
+ let code = 'API_ERROR';
96
+ let errorBody = null;
97
+ if (response.status === 401 || response.status === 403) {
98
+ code = 'UNAUTHORIZED';
99
+ }
100
+ try {
101
+ errorBody = await response.json();
102
+ }
103
+ catch (_) { }
104
+ throw new utils_1.AppError(code, `${method} ${url} failed with status ${response.status}`, 'external', {
105
+ status: response.status,
106
+ endpoint: url,
107
+ method,
108
+ body: errorBody,
109
+ });
110
+ }
111
+ if (response.status === 204) {
112
+ return undefined;
113
+ }
114
+ try {
115
+ return (await response.json());
116
+ }
117
+ catch (_) {
118
+ // TODO: define better behavior for non-JSON responses
119
+ return undefined;
120
+ }
121
+ }
122
+ };
123
+ exports.HttpService = HttpService;
124
+ exports.HttpService = HttpService = __decorate([
125
+ (0, tsyringe_1.injectable)()
126
+ ], HttpService);
@@ -0,0 +1,10 @@
1
+ export * from './player.service';
2
+ export * from './command.service';
3
+ export * from './http/http.service';
4
+ export * from './access-control.service';
5
+ export * from './chat.service';
6
+ export * from './rate-limiter.service';
7
+ export * from './persistence.service';
8
+ export * from './parallel';
9
+ export * from './config.service';
10
+ export * from '../database';
@@ -0,0 +1,26 @@
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
+ __exportStar(require("./player.service"), exports);
18
+ __exportStar(require("./command.service"), exports);
19
+ __exportStar(require("./http/http.service"), exports);
20
+ __exportStar(require("./access-control.service"), exports);
21
+ __exportStar(require("./chat.service"), exports);
22
+ __exportStar(require("./rate-limiter.service"), exports);
23
+ __exportStar(require("./persistence.service"), exports);
24
+ __exportStar(require("./parallel"), exports);
25
+ __exportStar(require("./config.service"), exports);
26
+ __exportStar(require("../database"), exports);
@@ -0,0 +1,49 @@
1
+ /**
2
+ * ParallelCompute Module
3
+ *
4
+ * Provides parallel computation capabilities using worker threads.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import {
9
+ * initParallelCompute,
10
+ * defineTask,
11
+ * filterByDistance,
12
+ * } from '@open-core/framework/server'
13
+ *
14
+ * // Initialize the worker pool (call once at startup)
15
+ * initParallelCompute({ maxWorkers: 4 })
16
+ *
17
+ * // Use built-in tasks
18
+ * const nearby = await filterByDistance.run({
19
+ * entities: allEntities,
20
+ * position: player.coords,
21
+ * radius: 100,
22
+ * })
23
+ *
24
+ * // Define custom tasks
25
+ * const processPlayers = defineTask({
26
+ * name: 'processPlayers',
27
+ * estimateCost: (input) => input.length * 10,
28
+ * workerThreshold: 500,
29
+ * compute: (players) => players.map(p => ({
30
+ * ...p,
31
+ * processed: true,
32
+ * })),
33
+ * })
34
+ *
35
+ * // Run with automatic mode selection
36
+ * const result = await processPlayers.run(players)
37
+ *
38
+ * // Force sync execution
39
+ * const resultSync = processPlayers.sync(players)
40
+ *
41
+ * // Force parallel execution
42
+ * const resultParallel = await processPlayers.parallel(players)
43
+ * ```
44
+ */
45
+ export type { ExecutionMode, WorkerPoolConfig, ParallelTaskOptions, ParallelTask, ParallelComputeMetrics, TaskResult, WorkerInfo, WorkerStatus, } from './types';
46
+ export { ParallelComputeService } from './parallel-compute.service';
47
+ export { getParallelComputeService, initParallelCompute, shutdownParallelCompute, defineTask, } from './parallel-compute.service';
48
+ export { filterByDistance, sortByDistance, findClosest, defineBatchTransform, defineBatchFilter, defineBatchReduce, type Vector3Like, } from './parallel-compute.service';
49
+ export { WorkerPool } from './worker-pool';
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * ParallelCompute Module
4
+ *
5
+ * Provides parallel computation capabilities using worker threads.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import {
10
+ * initParallelCompute,
11
+ * defineTask,
12
+ * filterByDistance,
13
+ * } from '@open-core/framework/server'
14
+ *
15
+ * // Initialize the worker pool (call once at startup)
16
+ * initParallelCompute({ maxWorkers: 4 })
17
+ *
18
+ * // Use built-in tasks
19
+ * const nearby = await filterByDistance.run({
20
+ * entities: allEntities,
21
+ * position: player.coords,
22
+ * radius: 100,
23
+ * })
24
+ *
25
+ * // Define custom tasks
26
+ * const processPlayers = defineTask({
27
+ * name: 'processPlayers',
28
+ * estimateCost: (input) => input.length * 10,
29
+ * workerThreshold: 500,
30
+ * compute: (players) => players.map(p => ({
31
+ * ...p,
32
+ * processed: true,
33
+ * })),
34
+ * })
35
+ *
36
+ * // Run with automatic mode selection
37
+ * const result = await processPlayers.run(players)
38
+ *
39
+ * // Force sync execution
40
+ * const resultSync = processPlayers.sync(players)
41
+ *
42
+ * // Force parallel execution
43
+ * const resultParallel = await processPlayers.parallel(players)
44
+ * ```
45
+ */
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.WorkerPool = exports.defineBatchReduce = exports.defineBatchFilter = exports.defineBatchTransform = exports.findClosest = exports.sortByDistance = exports.filterByDistance = exports.defineTask = exports.shutdownParallelCompute = exports.initParallelCompute = exports.getParallelComputeService = exports.ParallelComputeService = void 0;
48
+ // Service
49
+ var parallel_compute_service_1 = require("./parallel-compute.service");
50
+ Object.defineProperty(exports, "ParallelComputeService", { enumerable: true, get: function () { return parallel_compute_service_1.ParallelComputeService; } });
51
+ // Standalone functions
52
+ var parallel_compute_service_2 = require("./parallel-compute.service");
53
+ Object.defineProperty(exports, "getParallelComputeService", { enumerable: true, get: function () { return parallel_compute_service_2.getParallelComputeService; } });
54
+ Object.defineProperty(exports, "initParallelCompute", { enumerable: true, get: function () { return parallel_compute_service_2.initParallelCompute; } });
55
+ Object.defineProperty(exports, "shutdownParallelCompute", { enumerable: true, get: function () { return parallel_compute_service_2.shutdownParallelCompute; } });
56
+ Object.defineProperty(exports, "defineTask", { enumerable: true, get: function () { return parallel_compute_service_2.defineTask; } });
57
+ // Built-in tasks
58
+ var parallel_compute_service_3 = require("./parallel-compute.service");
59
+ Object.defineProperty(exports, "filterByDistance", { enumerable: true, get: function () { return parallel_compute_service_3.filterByDistance; } });
60
+ Object.defineProperty(exports, "sortByDistance", { enumerable: true, get: function () { return parallel_compute_service_3.sortByDistance; } });
61
+ Object.defineProperty(exports, "findClosest", { enumerable: true, get: function () { return parallel_compute_service_3.findClosest; } });
62
+ Object.defineProperty(exports, "defineBatchTransform", { enumerable: true, get: function () { return parallel_compute_service_3.defineBatchTransform; } });
63
+ Object.defineProperty(exports, "defineBatchFilter", { enumerable: true, get: function () { return parallel_compute_service_3.defineBatchFilter; } });
64
+ Object.defineProperty(exports, "defineBatchReduce", { enumerable: true, get: function () { return parallel_compute_service_3.defineBatchReduce; } });
65
+ // Worker pool (for advanced usage)
66
+ var worker_pool_1 = require("./worker-pool");
67
+ Object.defineProperty(exports, "WorkerPool", { enumerable: true, get: function () { return worker_pool_1.WorkerPool; } });
@@ -0,0 +1,132 @@
1
+ /**
2
+ * ParallelCompute Service
3
+ *
4
+ * Provides an ergonomic API for parallel computation.
5
+ * Uses virtual workers in FiveM environment, with async execution
6
+ * that yields to the event loop for better performance.
7
+ *
8
+ * Automatically decides whether to run synchronously or asynchronously
9
+ * based on estimated computational cost.
10
+ */
11
+ import type { ParallelTaskOptions, ParallelTask, WorkerPoolConfig, ParallelComputeMetrics, TaskResult } from './types';
12
+ /**
13
+ * Service for managing parallel computation
14
+ */
15
+ export declare class ParallelComputeService {
16
+ private pool;
17
+ private metrics;
18
+ private totalExecutionTime;
19
+ private isInitialized;
20
+ private poolConfig;
21
+ /**
22
+ * Initialize the worker pool
23
+ * Must be called before using parallel execution
24
+ */
25
+ initialize(config?: Partial<WorkerPoolConfig>): void;
26
+ /**
27
+ * Check if initialized
28
+ */
29
+ get initialized(): boolean;
30
+ /**
31
+ * Check if using native workers
32
+ */
33
+ get isNative(): boolean;
34
+ /**
35
+ * Shutdown the service and worker pool
36
+ */
37
+ shutdown(): Promise<void>;
38
+ /**
39
+ * Get current metrics
40
+ */
41
+ getMetrics(): ParallelComputeMetrics;
42
+ /**
43
+ * Get worker pool statistics
44
+ */
45
+ getPoolStats(): {
46
+ totalWorkers: number;
47
+ idleWorkers: number;
48
+ busyWorkers: number;
49
+ queuedTasks: number;
50
+ isNative: boolean;
51
+ } | null;
52
+ /**
53
+ * Reset metrics
54
+ */
55
+ resetMetrics(): void;
56
+ /**
57
+ * Execute a compute function with automatic mode selection
58
+ */
59
+ run<TInput, TOutput>(options: ParallelTaskOptions<TInput, TOutput>, input: TInput): Promise<TaskResult<TOutput>>;
60
+ /**
61
+ * Execute synchronously on main thread
62
+ */
63
+ sync<TInput, TOutput>(options: ParallelTaskOptions<TInput, TOutput>, input: TInput): TaskResult<TOutput>;
64
+ /**
65
+ * Execute on worker (async with yielding in FiveM)
66
+ */
67
+ parallel<TInput, TOutput>(options: ParallelTaskOptions<TInput, TOutput>, input: TInput): Promise<TaskResult<TOutput>>;
68
+ /**
69
+ * Execute distributed across multiple workers
70
+ */
71
+ distributed<TInput, TOutput>(options: ParallelTaskOptions<TInput, TOutput>, input: TInput, workerCount?: number): Promise<TaskResult<TOutput>>;
72
+ /**
73
+ * Update internal metrics
74
+ */
75
+ private updateMetrics;
76
+ }
77
+ /**
78
+ * Get or create the global ParallelCompute service instance
79
+ */
80
+ export declare function getParallelComputeService(): ParallelComputeService;
81
+ /**
82
+ * Initialize the global ParallelCompute service
83
+ */
84
+ export declare function initParallelCompute(config?: Partial<WorkerPoolConfig>): void;
85
+ /**
86
+ * Shutdown the global ParallelCompute service
87
+ */
88
+ export declare function shutdownParallelCompute(): Promise<void>;
89
+ /**
90
+ * Define a parallel task with the given options
91
+ * Returns a task object with run, sync, parallel, and distributed methods
92
+ */
93
+ export declare function defineTask<TInput, TOutput>(options: ParallelTaskOptions<TInput, TOutput>): ParallelTask<TInput, TOutput>;
94
+ export interface Vector3Like {
95
+ x: number;
96
+ y: number;
97
+ z: number;
98
+ }
99
+ /**
100
+ * Built-in task: Filter entities by distance from a position
101
+ */
102
+ export declare const filterByDistance: ParallelTask<{
103
+ entities: Vector3Like[];
104
+ position: Vector3Like;
105
+ radius: number;
106
+ }, Vector3Like[]>;
107
+ /**
108
+ * Built-in task: Sort entities by distance from a position
109
+ */
110
+ export declare const sortByDistance: ParallelTask<{
111
+ entities: Vector3Like[];
112
+ position: Vector3Like;
113
+ }, Vector3Like[]>;
114
+ /**
115
+ * Built-in task: Find closest entity to a position
116
+ */
117
+ export declare const findClosest: ParallelTask<{
118
+ entities: Vector3Like[];
119
+ position: Vector3Like;
120
+ }, Vector3Like | null>;
121
+ /**
122
+ * Built-in task: Batch transform items
123
+ */
124
+ export declare function defineBatchTransform<T, R>(name: string, transform: (item: T) => R, threshold?: number): ParallelTask<T[], R[]>;
125
+ /**
126
+ * Built-in task: Batch filter items
127
+ */
128
+ export declare function defineBatchFilter<T>(name: string, predicate: (item: T) => boolean, threshold?: number): ParallelTask<T[], T[]>;
129
+ /**
130
+ * Built-in task: Batch reduce items
131
+ */
132
+ export declare function defineBatchReduce<T, R>(name: string, reducer: (acc: R, item: T) => R, initial: R, merger: (results: R[]) => R, threshold?: number): ParallelTask<T[], R>;