@xrystal/core 3.32.1 → 3.37.3

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 (262) hide show
  1. package/README.md +651 -136
  2. package/package.json +27 -24
  3. package/tsconfig.base.json +15 -0
  4. package/x/bin/commands/create.mjs +34 -5
  5. package/x/bin/commands/doctor.mjs +115 -25
  6. package/x/bin/commands/hooks.mjs +55 -0
  7. package/x/bin/commands/project.mjs +75 -42
  8. package/x/bin/commands/release.mjs +8 -3
  9. package/x/bin/commands/sync-toolchain.mjs +43 -0
  10. package/x/bin/commands/tmp.mjs +13 -4
  11. package/x/bin/helpers/.generated/.generated-from +1 -0
  12. package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
  13. package/x/bin/helpers/banner.mjs +66 -12
  14. package/x/bin/helpers/build-config.mjs +342 -0
  15. package/x/bin/helpers/cli-help.mjs +164 -0
  16. package/x/bin/helpers/create-target.mjs +18 -2
  17. package/x/bin/helpers/project-artifacts.mjs +140 -0
  18. package/x/bin/helpers/runtime-info.mjs +172 -0
  19. package/x/bin/helpers/tmp-config.mjs +11 -10
  20. package/x/bin/helpers/tmp-layout.mjs +10 -16
  21. package/x/bin/helpers/tmp-schema.mjs +9 -0
  22. package/x/bin/helpers/toolchain-config.mjs +233 -0
  23. package/x/bin/main-cli.js +31 -3
  24. package/x/bin/scripts/clean-source-types.mjs +19 -0
  25. package/x/bin/scripts/fix-dist-imports.mjs +80 -0
  26. package/x/bin/scripts/install-git-hooks.mjs +86 -0
  27. package/x/bin/scripts/minify-dist.mjs +50 -0
  28. package/x/bin/scripts/prepare-npm-publish.mjs +49 -0
  29. package/x/bin/scripts/unpublish-leaked-versions.mjs +62 -0
  30. package/x/bin/scripts/verify-npm-pack.mjs +45 -0
  31. package/x/bin/scripts/verify-version-bump.mjs +27 -0
  32. package/x/bin/scripts/version-check.mjs +173 -0
  33. package/x/dist/index.d.ts +3 -0
  34. package/x/dist/index.js +1 -0
  35. package/x/dist/loader/clients/index.js +1 -0
  36. package/x/dist/loader/configs/index.js +1 -0
  37. package/{source → x/dist}/loader/controller/index.d.ts +20 -17
  38. package/x/dist/loader/controller/index.js +1 -0
  39. package/x/dist/loader/dto/index.js +1 -0
  40. package/x/dist/loader/events/index.js +1 -0
  41. package/x/dist/loader/index.d.ts +11 -0
  42. package/x/dist/loader/index.js +1 -0
  43. package/{source → x/dist}/loader/kafka/index.d.ts +1 -0
  44. package/x/dist/loader/kafka/index.js +1 -0
  45. package/x/dist/loader/localizations/index.js +1 -0
  46. package/{source → x/dist}/loader/logger/index.d.ts +1 -0
  47. package/x/dist/loader/logger/index.js +2 -0
  48. package/x/dist/loader/service/index.js +1 -0
  49. package/x/dist/loader/system/index.js +1 -0
  50. package/x/dist/project/index.js +1 -0
  51. package/x/dist/utils/constants/defaults.json +44 -0
  52. package/x/dist/utils/constants/index.js +1 -0
  53. package/x/dist/utils/helpers/configs/index.js +1 -0
  54. package/x/dist/utils/helpers/context/controller-store.js +1 -0
  55. package/x/dist/utils/helpers/context/index.js +1 -0
  56. package/{source → x/dist}/utils/helpers/core/index.d.ts +1 -1
  57. package/x/dist/utils/helpers/core/index.js +1 -0
  58. package/x/dist/utils/helpers/core/paths.js +1 -0
  59. package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
  60. package/x/dist/utils/helpers/date/index.js +1 -0
  61. package/x/dist/utils/helpers/dispatch/index.js +1 -0
  62. package/x/dist/utils/helpers/dto/index.js +1 -0
  63. package/x/dist/utils/helpers/filters/index.js +1 -0
  64. package/x/dist/utils/helpers/framework/index.js +1 -0
  65. package/x/dist/utils/helpers/handlers/adapters.js +1 -0
  66. package/x/dist/utils/helpers/handlers/execute.js +1 -0
  67. package/x/dist/utils/helpers/handlers/index.js +1 -0
  68. package/x/dist/utils/helpers/hash/crypto.js +1 -0
  69. package/x/dist/utils/helpers/id/index.js +1 -0
  70. package/x/dist/utils/helpers/index.js +1 -0
  71. package/x/dist/utils/helpers/ip/index.js +1 -0
  72. package/x/dist/utils/helpers/is/index.js +1 -0
  73. package/x/dist/utils/helpers/locales/index.js +1 -0
  74. package/x/dist/utils/helpers/math/index.js +1 -0
  75. package/{source → x/dist}/utils/helpers/middleware/index.d.ts +2 -2
  76. package/x/dist/utils/helpers/middleware/index.js +1 -0
  77. package/x/dist/utils/helpers/objects/index.js +1 -0
  78. package/x/dist/utils/helpers/path/index.js +1 -0
  79. package/{source → x/dist}/utils/helpers/protocol/index.d.ts +2 -10
  80. package/x/dist/utils/helpers/protocol/index.js +1 -0
  81. package/x/dist/utils/helpers/protocol/options.js +1 -0
  82. package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
  83. package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
  84. package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
  85. package/{source → x/dist}/utils/helpers/runtime/index.d.ts +1 -0
  86. package/x/dist/utils/helpers/runtime/index.js +1 -0
  87. package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
  88. package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
  89. package/x/dist/utils/helpers/state/index.js +1 -0
  90. package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
  91. package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
  92. package/x/dist/utils/helpers/state/scopes.js +1 -0
  93. package/x/dist/utils/helpers/string/index.js +1 -0
  94. package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
  95. package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
  96. package/x/dist/utils/helpers/timer/index.js +1 -0
  97. package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
  98. package/x/dist/utils/helpers/tmp/index.js +1 -0
  99. package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
  100. package/{source → x/dist}/utils/helpers/tmp/runtime-tmp.d.ts +2 -6
  101. package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
  102. package/{source → x/dist}/utils/helpers/tmp/tmp-loader.d.ts +1 -0
  103. package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
  104. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
  105. package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
  106. package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
  107. package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
  108. package/x/dist/utils/helpers/validates/index.js +1 -0
  109. package/x/dist/utils/index.js +1 -0
  110. package/x/dist/utils/models/classes/class.clients.js +1 -0
  111. package/x/dist/utils/models/classes/class.interfaces.js +1 -0
  112. package/x/dist/utils/models/classes/class.service-locator.js +1 -0
  113. package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
  114. package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
  115. package/x/dist/utils/models/classes/class.x.js +1 -0
  116. package/x/dist/utils/models/enums/index.js +1 -0
  117. package/x/dist/utils/models/index.js +1 -0
  118. package/x/dist/utils/models/types/index.js +1 -0
  119. package/x/dist/utils/package-root.js +1 -0
  120. package/x/tmp.yml +51 -42
  121. package/source/index.js +0 -11
  122. package/source/loader/clients/index.js +0 -22
  123. package/source/loader/configs/index.js +0 -88
  124. package/source/loader/controller/index.js +0 -236
  125. package/source/loader/dto/index.js +0 -92
  126. package/source/loader/events/index.js +0 -44
  127. package/source/loader/index.d.ts +0 -11
  128. package/source/loader/index.js +0 -11
  129. package/source/loader/kafka/index.js +0 -137
  130. package/source/loader/localizations/index.js +0 -46
  131. package/source/loader/logger/index.js +0 -217
  132. package/source/loader/service/index.js +0 -7
  133. package/source/loader/system/index.js +0 -25
  134. package/source/project/index.js +0 -70
  135. package/source/utils/constants/defaults.json +0 -15
  136. package/source/utils/constants/defaults.mjs +0 -10
  137. package/source/utils/constants/index.js +0 -22
  138. package/source/utils/helpers/configs/index.js +0 -1
  139. package/source/utils/helpers/context/controller-store.js +0 -12
  140. package/source/utils/helpers/context/index.js +0 -24
  141. package/source/utils/helpers/core/index.js +0 -58
  142. package/source/utils/helpers/core/paths.js +0 -78
  143. package/source/utils/helpers/core/tmp-layout.js +0 -241
  144. package/source/utils/helpers/date/index.js +0 -48
  145. package/source/utils/helpers/dispatch/index.js +0 -53
  146. package/source/utils/helpers/dto/index.js +0 -10
  147. package/source/utils/helpers/filters/index.js +0 -44
  148. package/source/utils/helpers/framework/index.js +0 -17
  149. package/source/utils/helpers/handlers/adapters.js +0 -40
  150. package/source/utils/helpers/handlers/execute.js +0 -82
  151. package/source/utils/helpers/handlers/index.js +0 -31
  152. package/source/utils/helpers/hash/crypto.js +0 -22
  153. package/source/utils/helpers/id/index.js +0 -24
  154. package/source/utils/helpers/index.js +0 -26
  155. package/source/utils/helpers/ip/index.js +0 -21
  156. package/source/utils/helpers/is/index.js +0 -35
  157. package/source/utils/helpers/locales/index.js +0 -82
  158. package/source/utils/helpers/math/index.js +0 -14
  159. package/source/utils/helpers/middleware/index.js +0 -36
  160. package/source/utils/helpers/objects/index.js +0 -55
  161. package/source/utils/helpers/path/index.js +0 -4
  162. package/source/utils/helpers/protocol/index.js +0 -99
  163. package/source/utils/helpers/protocol/options.js +0 -13
  164. package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
  165. package/source/utils/helpers/runtime/dto-access.js +0 -5
  166. package/source/utils/helpers/runtime/index.js +0 -1
  167. package/source/utils/helpers/state/index.js +0 -185
  168. package/source/utils/helpers/state/props-from-tmp.js +0 -44
  169. package/source/utils/helpers/state/request-key-guard.js +0 -42
  170. package/source/utils/helpers/state/scopes.js +0 -69
  171. package/source/utils/helpers/string/index.js +0 -9
  172. package/source/utils/helpers/timer/index.js +0 -5
  173. package/source/utils/helpers/tmp/index.d.ts +0 -3
  174. package/source/utils/helpers/tmp/index.js +0 -3
  175. package/source/utils/helpers/tmp/loader-tmp-sync.js +0 -13
  176. package/source/utils/helpers/tmp/runtime-tmp.js +0 -30
  177. package/source/utils/helpers/tmp/tmp-loader.js +0 -48
  178. package/source/utils/helpers/validates/index.js +0 -20
  179. package/source/utils/index.js +0 -3
  180. package/source/utils/models/classes/class.clients.js +0 -142
  181. package/source/utils/models/classes/class.interfaces.js +0 -10
  182. package/source/utils/models/classes/class.service-locator.js +0 -16
  183. package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
  184. package/source/utils/models/classes/class.x.js +0 -180
  185. package/source/utils/models/enums/index.js +0 -148
  186. package/source/utils/models/index.js +0 -9
  187. package/source/utils/models/types/index.js +0 -2
  188. package/source/utils/models/types/shims.d.ts +0 -123
  189. package/source/utils/package-root.js +0 -5
  190. package/x/tests/cli.test.ts +0 -85
  191. package/x/tests/context.test.ts +0 -25
  192. package/x/tests/dispatch.test.ts +0 -84
  193. package/x/tests/fixtures/locales/en/translation.json +0 -8
  194. package/x/tests/fixtures/locales/tr/translation.json +0 -8
  195. package/x/tests/frameworks.integration.test.ts +0 -185
  196. package/x/tests/helpers/i18n-setup.ts +0 -52
  197. package/x/tests/helpers/middleware.ts +0 -23
  198. package/x/tests/helpers/register-test-dto.ts +0 -52
  199. package/x/tests/i18n.integration.test.ts +0 -77
  200. package/x/tests/i18n.test.ts +0 -96
  201. package/x/tests/middleware.test.ts +0 -83
  202. package/x/tests/project-layout.test.ts +0 -65
  203. package/x/tests/protocol.test.ts +0 -75
  204. package/x/tests/realtime.examples.test.ts +0 -198
  205. package/x/tests/runtime-tmp.test.ts +0 -49
  206. package/x/tests/socket.integration.test.ts +0 -174
  207. package/x/tests/state.test.ts +0 -183
  208. package/x/tests/tmp-layout-guard.test.ts +0 -40
  209. /package/{source → x/dist}/loader/clients/index.d.ts +0 -0
  210. /package/{source → x/dist}/loader/configs/index.d.ts +0 -0
  211. /package/{source → x/dist}/loader/dto/index.d.ts +0 -0
  212. /package/{source → x/dist}/loader/events/index.d.ts +0 -0
  213. /package/{source → x/dist}/loader/localizations/index.d.ts +0 -0
  214. /package/{source → x/dist}/loader/service/index.d.ts +0 -0
  215. /package/{source → x/dist}/loader/system/index.d.ts +0 -0
  216. /package/{source → x/dist}/project/index.d.ts +0 -0
  217. /package/{source → x/dist}/utils/constants/index.d.ts +0 -0
  218. /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
  219. /package/{source → x/dist}/utils/helpers/context/controller-store.d.ts +0 -0
  220. /package/{source → x/dist}/utils/helpers/context/index.d.ts +0 -0
  221. /package/{source → x/dist}/utils/helpers/core/paths.d.ts +0 -0
  222. /package/{source → x/dist}/utils/helpers/core/tmp-layout.d.ts +0 -0
  223. /package/{source → x/dist}/utils/helpers/date/index.d.ts +0 -0
  224. /package/{source → x/dist}/utils/helpers/dispatch/index.d.ts +0 -0
  225. /package/{source → x/dist}/utils/helpers/dto/index.d.ts +0 -0
  226. /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
  227. /package/{source → x/dist}/utils/helpers/framework/index.d.ts +0 -0
  228. /package/{source → x/dist}/utils/helpers/handlers/adapters.d.ts +0 -0
  229. /package/{source → x/dist}/utils/helpers/handlers/execute.d.ts +0 -0
  230. /package/{source → x/dist}/utils/helpers/handlers/index.d.ts +0 -0
  231. /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
  232. /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
  233. /package/{source → x/dist}/utils/helpers/index.d.ts +0 -0
  234. /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
  235. /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
  236. /package/{source → x/dist}/utils/helpers/locales/index.d.ts +0 -0
  237. /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
  238. /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
  239. /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
  240. /package/{source → x/dist}/utils/helpers/protocol/options.d.ts +0 -0
  241. /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
  242. /package/{source → x/dist}/utils/helpers/runtime/dto-access.d.ts +0 -0
  243. /package/{source → x/dist}/utils/helpers/runtime/dto-types.d.ts +0 -0
  244. /package/{source → x/dist}/utils/helpers/state/index.d.ts +0 -0
  245. /package/{source → x/dist}/utils/helpers/state/props-from-tmp.d.ts +0 -0
  246. /package/{source → x/dist}/utils/helpers/state/request-key-guard.d.ts +0 -0
  247. /package/{source → x/dist}/utils/helpers/state/scopes.d.ts +0 -0
  248. /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
  249. /package/{source/index.d.ts → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
  250. /package/{source/utils/helpers/runtime/dto-types.js → x/dist/utils/helpers/tests/tmp-watch.test.d.ts} +0 -0
  251. /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
  252. /package/{source → x/dist}/utils/helpers/tmp/loader-tmp-sync.d.ts +0 -0
  253. /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
  254. /package/{source → x/dist}/utils/index.d.ts +0 -0
  255. /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
  256. /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
  257. /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
  258. /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
  259. /package/{source → x/dist}/utils/models/enums/index.d.ts +0 -0
  260. /package/{source → x/dist}/utils/models/index.d.ts +0 -0
  261. /package/{source → x/dist}/utils/models/types/index.d.ts +0 -0
  262. /package/{source → x/dist}/utils/package-root.d.ts +0 -0
@@ -1,75 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
- import { ProtocolEnum } from '@/utils/models'
3
- import {
4
- detectSocketProtocol,
5
- getConfiguredProtocols,
6
- isHttpProtocol,
7
- isRealtimeProtocol,
8
- parseProtocol,
9
- resolveProtocolsFromConfig,
10
- defaultRealtimeProtocolFromConfig,
11
- resolveRealtimeMiddlewareProtocol,
12
- REALTIME_MIDDLEWARE_HINT,
13
- } from '@/utils/helpers/protocol'
14
-
15
- describe('parseProtocol', () => {
16
- test('tmp.yml aliases', () => {
17
- expect(parseProtocol('http')).toBe(ProtocolEnum.HTTP)
18
- expect(parseProtocol('ws')).toBe(ProtocolEnum.WEBSOCKET)
19
- expect(parseProtocol('socketio')).toBe(ProtocolEnum.SOCKETIO)
20
- })
21
- })
22
-
23
- describe('detectSocketProtocol', () => {
24
- test('default ws — emit ile otomatik socketio yok', () => {
25
- expect(detectSocketProtocol({ emit() {} })).toBe(ProtocolEnum.WEBSOCKET)
26
- })
27
-
28
- test('send only → websocket', () => {
29
- expect(detectSocketProtocol({ send() {} })).toBe(ProtocolEnum.WEBSOCKET)
30
- })
31
-
32
- test('explicit overrides', () => {
33
- expect(detectSocketProtocol({ emit() {} }, ProtocolEnum.SOCKETIO)).toBe(ProtocolEnum.SOCKETIO)
34
- })
35
- })
36
-
37
- describe('resolveRealtimeMiddlewareProtocol', () => {
38
- test('tek realtime tmp.yml → otomatik', () => {
39
- expect(resolveRealtimeMiddlewareProtocol(undefined, { protocols: ['http', 'ws'] })).toBe(ProtocolEnum.WEBSOCKET)
40
- })
41
-
42
- test('ws + socketio → arg zorunlu', () => {
43
- expect(() => resolveRealtimeMiddlewareProtocol(undefined, { protocols: ['http', 'ws', 'socketio'] }))
44
- .toThrow(REALTIME_MIDDLEWARE_HINT)
45
- })
46
-
47
- test('ws + socketio → explicit socketio', () => {
48
- expect(resolveRealtimeMiddlewareProtocol('socketio', { protocols: ['http', 'ws', 'socketio'] }))
49
- .toBe(ProtocolEnum.SOCKETIO)
50
- })
51
-
52
- test('fallback ws when no realtime in config', () => {
53
- expect(resolveRealtimeMiddlewareProtocol(undefined, { protocols: ['http'] })).toBe(ProtocolEnum.WEBSOCKET)
54
- })
55
- })
56
-
57
- describe('protocol helpers', () => {
58
- test('isRealtimeProtocol', () => {
59
- expect(isRealtimeProtocol(ProtocolEnum.WEBSOCKET)).toBe(true)
60
- expect(isHttpProtocol(ProtocolEnum.HTTP)).toBe(true)
61
- })
62
-
63
- test('getConfiguredProtocols fallback without System', () => {
64
- const protocols = getConfiguredProtocols()
65
- expect(protocols.length).toBeGreaterThan(0)
66
- })
67
-
68
- test('defaultRealtimeProtocolFromConfig — tek realtime ise ws', () => {
69
- expect(defaultRealtimeProtocolFromConfig({ protocols: ['http', 'ws'] })).toBe(ProtocolEnum.WEBSOCKET)
70
- })
71
-
72
- test('defaultRealtimeProtocolFromConfig — iki realtime ise undefined (middleware arg zorunlu)', () => {
73
- expect(defaultRealtimeProtocolFromConfig({ protocols: ['http', 'ws', 'socketio'] })).toBeUndefined()
74
- })
75
- })
@@ -1,198 +0,0 @@
1
- import { beforeEach, describe, expect, test } from 'bun:test'
2
- import { DTO } from '@xrystal/dto'
3
- import Controller from '@/loader/controller'
4
- import {
5
- realtimeMiddleware,
6
- runAction,
7
- toRealtimeHandler,
8
- } from '@/utils/helpers/handlers'
9
- import { ProtocolEnum } from '@/utils/models'
10
- import { registerTestDto, registerTestRuntime } from './helpers/register-test-dto'
11
-
12
- function mockWsSocket() {
13
- const sent: string[] = []
14
- const socket: any = { send(data: string) { sent.push(data) } }
15
- return { socket, sent, read: () => JSON.parse(sent[0]) }
16
- }
17
-
18
- function mockSioSocket() {
19
- const emitted: Array<{ event: string; data: unknown }> = []
20
- const socket: any = {
21
- emit(event: string, data: unknown) { emitted.push({ event, data }) },
22
- }
23
- return { socket, emitted, last: () => emitted[emitted.length - 1] }
24
- }
25
-
26
- describe('TARİF 0 — realtimeMiddleware() tmp.yml\'den otomatik', () => {
27
- test('protocols: [http, ws] → arg vermeden ws attach', async () => {
28
- registerTestRuntime({ tmp: { protocols: ['http', 'ws'] } })
29
- const { socket, sent } = mockWsSocket()
30
-
31
- await new Promise<void>((resolve) => {
32
- realtimeMiddleware()(socket, () => {
33
- expect(socket.builder).toBeDefined()
34
- socket.builder.as.ok({ auto: true }).build()
35
- resolve()
36
- })
37
- })
38
-
39
- expect((socket as any).__xrystalProtocol).toBe(ProtocolEnum.WEBSOCKET)
40
- })
41
-
42
- test('protocols: [http, ws, socketio] → arg olmadan hata, explicit socketio ile ok', () => {
43
- registerTestRuntime({ tmp: { protocols: ['http', 'ws', 'socketio'] } })
44
- const { socket } = mockSioSocket()
45
-
46
- expect(() => realtimeMiddleware()(socket, () => {})).toThrow(/ws and socketio/)
47
-
48
- realtimeMiddleware('socketio')(socket, () => {})
49
- expect((socket as any).__xrystalProtocol).toBe(ProtocolEnum.SOCKETIO)
50
- })
51
- })
52
-
53
- describe('TARİF 1 — Native WebSocket + ctr (3 adım)', () => {
54
- beforeEach(() => registerTestRuntime({ tmp: { protocols: ['http', 'ws'] } }))
55
-
56
- test('realtimeMiddleware → ctr.with(socket) → socket.send(JSON)', async () => {
57
- const { socket, sent } = mockWsSocket()
58
- const onMessage = toRealtimeHandler(async () =>
59
- socket.builder.as.ok({ pong: true }, 'ok').build(),
60
- ProtocolEnum.WEBSOCKET)
61
-
62
- await new Promise<void>((resolve) => {
63
- realtimeMiddleware('ws')(socket, () => {
64
- onMessage.with(socket)().then(() => {
65
- expect(sent).toHaveLength(1)
66
- expect(JSON.parse(sent[0]).body.payload.data).toEqual({ pong: true })
67
- resolve()
68
- })
69
- })
70
- })
71
- })
72
- })
73
-
74
- describe('TARİF 2 — Socket.IO + ctr (3 adım)', () => {
75
- beforeEach(() => registerTestDto())
76
-
77
- test('realtimeMiddleware → ctr.with(socket) → socket.emit(response)', async () => {
78
- const { socket, emitted } = mockSioSocket()
79
- const onChat = toRealtimeHandler(async () =>
80
- socket.builder.as.ok({ room: 'general' }, 'joined').build(),
81
- ProtocolEnum.SOCKETIO)
82
-
83
- await new Promise<void>((resolve) => {
84
- realtimeMiddleware('socketio')(socket, () => {
85
- onChat.with(socket)().then(() => {
86
- expect(emitted[0].event).toBe('response')
87
- expect((emitted[0].data as any).body.payload.data).toEqual({ room: 'general' })
88
- resolve()
89
- })
90
- })
91
- })
92
- })
93
- })
94
-
95
- describe('TARİF 3 — WebSocket, Controller YOK (runAction)', () => {
96
- beforeEach(() => registerTestDto())
97
-
98
- test('runAction + protocol ws — checks/i18n yok', async () => {
99
- const { socket, read } = mockWsSocket()
100
- realtimeMiddleware('ws')(socket, () => {})
101
-
102
- await runAction({ protocol: ProtocolEnum.WEBSOCKET, socket }, async () =>
103
- socket.builder.as.ok({ ping: 1 }, 'pong').build(),
104
- )
105
-
106
- expect(read().body.message).toBe('pong')
107
- expect(read().body.payload.data).toEqual({ ping: 1 })
108
- })
109
- })
110
-
111
- describe('TARİF 4 — Socket.IO, Controller YOK (runAction)', () => {
112
- beforeEach(() => registerTestDto())
113
-
114
- test('runAction + protocol socketio → emit', async () => {
115
- const { socket, last } = mockSioSocket()
116
- realtimeMiddleware('socketio')(socket, () => {})
117
-
118
- await runAction({ protocol: ProtocolEnum.SOCKETIO, socket }, async () =>
119
- socket.builder.as.ok([], 'hi').build(),
120
- )
121
-
122
- expect(last().event).toBe('response')
123
- expect((last().data as any).body.message).toBe('hi')
124
- })
125
- })
126
-
127
- describe('TARİF 5 — Aynı logic, farklı protocol', () => {
128
- beforeEach(() => registerTestDto())
129
-
130
- test('onWs send + onSio emit — aynı payload', async () => {
131
- const ws = mockWsSocket()
132
- const sio = mockSioSocket()
133
- realtimeMiddleware('ws')(ws.socket, () => {})
134
- realtimeMiddleware('socketio')(sio.socket, () => {})
135
-
136
- const logic = async () => ({ echo: 'same' })
137
- const onWs = toRealtimeHandler(async () => ws.socket.builder.as.ok(await logic()).build(), ProtocolEnum.WEBSOCKET)
138
- const onSio = toRealtimeHandler(async () => sio.socket.builder.as.ok(await logic()).build(), ProtocolEnum.SOCKETIO)
139
-
140
- await onWs.with(ws.socket)()
141
- await onSio.with(sio.socket)()
142
-
143
- expect(ws.read().body.payload.data).toEqual({ echo: 'same' })
144
- expect((sio.last().data as any).body.payload.data).toEqual({ echo: 'same' })
145
- })
146
- })
147
-
148
- describe('TARİF 6 — Gerçek Controller + ctr({ protocol })', () => {
149
- beforeEach(() => registerTestRuntime())
150
-
151
- test('ChatController.onMessage ws → send', async () => {
152
- class ChatController extends Controller {
153
- onMessage = this.ctr({
154
- logic: async () => ({ data: { from: 'controller' } }),
155
- }, { protocol: 'ws' })
156
- }
157
-
158
- const { socket, read } = mockWsSocket()
159
- const ctrl = new ChatController()
160
- realtimeMiddleware('ws')(socket, () => {})
161
- await ctrl.onMessage.with(socket)()
162
- expect(read().body.payload.data).toEqual({ from: 'controller' })
163
- })
164
-
165
- test('ChatController.onChat socketio → emit', async () => {
166
- class ChatController extends Controller {
167
- onChat = this.ctr({
168
- logic: async () => ({ data: { channel: 'lobby' } }),
169
- }, { protocol: 'socketio' })
170
- }
171
-
172
- const { socket, last } = mockSioSocket()
173
- const ctrl = new ChatController()
174
- realtimeMiddleware('socketio')(socket, () => {})
175
- await ctrl.onChat.with(socket)()
176
- expect((last().data as any).body.payload.data).toEqual({ channel: 'lobby' })
177
- })
178
- })
179
-
180
- describe('WS vs Socket.IO — transport farkı', () => {
181
- beforeEach(() => registerTestDto())
182
-
183
- test('aynı FinalResult; ws=string, sio=object', async () => {
184
- const runtime = new DTO({ withDefaultHeaders: false })
185
- const ws = mockWsSocket()
186
- const sio = mockSioSocket()
187
- runtime.attachWebSocket(ws.socket)
188
- runtime.attachSocketIo(sio.socket)
189
-
190
- const result = ws.socket.builder.as.ok({ id: 1 }, 'same').build()
191
- await runAction({ protocol: ProtocolEnum.WEBSOCKET, socket: ws.socket }, async () => result)
192
- await runAction({ protocol: ProtocolEnum.SOCKETIO, socket: sio.socket }, async () => result)
193
-
194
- expect(typeof ws.sent[0]).toBe('string')
195
- expect(typeof sio.emitted[0].data).toBe('object')
196
- expect(ws.read().body).toEqual((sio.emitted[0].data as any).body)
197
- })
198
- })
@@ -1,49 +0,0 @@
1
- import { beforeEach, describe, expect, test } from 'bun:test'
2
- import { G } from '@/utils/helpers/state'
3
- import {
4
- onRuntimeTmpChange,
5
- notifyRuntimeTmpChange,
6
- setRuntimeTmpConfigs,
7
- clearRuntimeTmpConfigs,
8
- } from '@/utils/helpers/tmp/runtime-tmp'
9
-
10
- beforeEach(() => {
11
- clearRuntimeTmpConfigs()
12
- G.configureFromTmp({ configs: { loaders: { system: { gStore: { vars: {} } } } } })
13
- })
14
-
15
- describe('runtime tmp — System sync', () => {
16
- test('notifyRuntimeTmpChange runs listeners in order', async () => {
17
- const order: string[] = []
18
- const offA = onRuntimeTmpChange(async () => { order.push('a') })
19
- const offB = onRuntimeTmpChange(async () => { order.push('b') })
20
-
21
- await notifyRuntimeTmpChange({ framework: 'express', protocols: ['http'] })
22
- offA()
23
- offB()
24
-
25
- expect(order).toEqual(['a', 'b'])
26
- })
27
-
28
- test('applyTmp pattern — G + runtime together', () => {
29
- const tmp = {
30
- configs: {
31
- framework: 'elysia',
32
- protocols: ['http', 'ws'],
33
- loaders: {
34
- system: {
35
- gStore: {
36
- options: { bootstrap: true, autoCreateProps: false },
37
- vars: { maintenance: false },
38
- },
39
- },
40
- },
41
- },
42
- }
43
-
44
- setRuntimeTmpConfigs(tmp.configs)
45
- G.configureFromTmp(tmp)
46
-
47
- expect(G.get('maintenance')).toBe(false)
48
- })
49
- })
@@ -1,174 +0,0 @@
1
- import { beforeEach, describe, expect, test } from 'bun:test'
2
- import { DTO } from '@xrystal/dto'
3
- import { runController, type ControllerContext } from '@/loader/controller'
4
- import { dispatchResult } from '@/utils/helpers/dispatch'
5
- import { toSocketIo, toWebSocket } from '@/utils/helpers/handlers'
6
- import { socketMiddleware } from './helpers/middleware'
7
- import { runWithRequestId } from '@/utils/helpers/context'
8
- import { parseResponseMessage } from '@/utils/helpers/locales'
9
- import { FrameworkEnum, ProtocolEnum } from '@/utils/models'
10
- import { registerTestDto } from './helpers/register-test-dto'
11
-
12
- const en = (key: string) => ({
13
- 'responseMessage.successfully': 'Operation completed successfully',
14
- }[key] ?? key)
15
-
16
- async function runSocketAction(
17
- store: ControllerContext,
18
- action: () => Promise<unknown>,
19
- ) {
20
- return runWithRequestId(store.requestId ?? 'ws-test', () =>
21
- runController(store, async () => dispatchResult(await action(), store)),
22
- 'ws',
23
- )
24
- }
25
-
26
- describe('WebSocket pipeline', () => {
27
- beforeEach(() => registerTestDto())
28
-
29
- test('middleware attaches builder → dispatch sends JSON via ws.send', async () => {
30
- const runtime = new DTO({ withDefaultHeaders: false })
31
- const sent: string[] = []
32
- const socket: any = { send(data: string) { sent.push(data) } }
33
-
34
- await new Promise<void>((resolve) => {
35
- socketMiddleware(runtime, 'websocket')(socket, async () => {
36
- const store: ControllerContext = {
37
- socket,
38
- ctx: { ws: socket },
39
- protocol: ProtocolEnum.WEBSOCKET,
40
- requestId: 'ws-1',
41
- metadata: { locals: {} },
42
- }
43
-
44
- await runSocketAction(store, async () => {
45
- const message = parseResponseMessage('@successfully user', en, false)
46
- return socket.builder.as.ok({ connected: true }, message).build()
47
- })
48
-
49
- const payload = JSON.parse(sent[0])
50
- expect(payload.body.status).toBe(true)
51
- expect(payload.body.message).toContain('user')
52
- expect(payload.body.payload.data).toEqual({ connected: true })
53
- resolve()
54
- })
55
- })
56
- })
57
-
58
- test('toWebSocket helper runs full ctr-style flow', async () => {
59
- registerTestDto()
60
- const sent: string[] = []
61
- const socket: any = { send(data: string) { sent.push(data) } }
62
-
63
- await toWebSocket(socket, async () => {
64
- const message = parseResponseMessage('@successfully user', en, false)
65
- return socket.builder.as.ok([], message).build()
66
- })
67
-
68
- expect(sent.length).toBe(1)
69
- expect(JSON.parse(sent[0]).body.message).toContain('Operation completed successfully')
70
- })
71
- })
72
-
73
- describe('Socket.IO pipeline', () => {
74
- beforeEach(() => registerTestDto())
75
-
76
- test('middleware attaches builder → dispatch emits on default event', async () => {
77
- const runtime = new DTO({ withDefaultHeaders: false })
78
- const emitted: Array<{ event: string; data: unknown }> = []
79
- const socket: any = {
80
- emit(event: string, data: unknown) { emitted.push({ event, data }) },
81
- }
82
-
83
- await new Promise<void>((resolve) => {
84
- socketMiddleware(runtime, 'socketio')(socket, async () => {
85
- const store: ControllerContext = {
86
- socket,
87
- ctx: { ws: socket },
88
- protocol: ProtocolEnum.SOCKETIO,
89
- requestId: 'sio-1',
90
- metadata: { locals: {} },
91
- }
92
-
93
- await runSocketAction(store, async () =>
94
- socket.builder.as.ok({ room: 'lobby' }, 'OK').build(),
95
- )
96
-
97
- expect(emitted).toHaveLength(1)
98
- expect(emitted[0].event).toBe('response')
99
- expect((emitted[0].data as any).body.payload.data).toEqual({ room: 'lobby' })
100
- resolve()
101
- })
102
- })
103
- })
104
-
105
- test('custom socket.event from DtoRuntime config', async () => {
106
- registerTestDto({ socketEvent: 'api:response' })
107
- const emitted: Array<{ event: string; data: unknown }> = []
108
- const socket: any = {
109
- emit(event: string, data: unknown) { emitted.push({ event, data }) },
110
- }
111
- const runtime = new DTO({ withDefaultHeaders: false })
112
-
113
- await new Promise<void>((resolve) => {
114
- socketMiddleware(runtime, 'socketio')(socket, async () => {
115
- const store: ControllerContext = {
116
- socket,
117
- ctx: { ws: socket },
118
- protocol: ProtocolEnum.SOCKETIO,
119
- metadata: { locals: {} },
120
- }
121
-
122
- await runSocketAction(store, async () =>
123
- socket.builder.as.ok({ ping: 1 }).build(),
124
- )
125
-
126
- expect(emitted[0].event).toBe('api:response')
127
- resolve()
128
- })
129
- })
130
- })
131
-
132
- test('toSocketIo helper runs full flow', async () => {
133
- registerTestDto()
134
- const emitted: Array<{ event: string; data: unknown }> = []
135
- const socket: any = {
136
- emit(event: string, data: unknown) { emitted.push({ event, data }) },
137
- }
138
-
139
- await toSocketIo(socket, async () =>
140
- socket.builder.as.ok({ ok: true }, 'done').build(),
141
- )
142
-
143
- expect(emitted[0].event).toBe('response')
144
- expect((emitted[0].data as any).body.message).toBe('done')
145
- })
146
-
147
- test('websocket and socketio sinks produce different transport shapes', async () => {
148
- registerTestDto()
149
- const wsSent: string[] = []
150
- const sioEmitted: unknown[] = []
151
-
152
- const wsSocket: any = { send: (d: string) => wsSent.push(d) }
153
- const sioSocket: any = { emit: (_: string, d: unknown) => sioEmitted.push(d) }
154
-
155
- const runtime = new DTO({ withDefaultHeaders: false })
156
- runtime.attachWebSocket(wsSocket)
157
- runtime.attachSocketIo(sioSocket)
158
-
159
- const result = wsSocket.builder.as.ok({ id: 1 }).build()
160
-
161
- await runSocketAction(
162
- { socket: wsSocket, ctx: { ws: wsSocket }, protocol: ProtocolEnum.WEBSOCKET },
163
- async () => result,
164
- )
165
- await runSocketAction(
166
- { socket: sioSocket, ctx: { ws: sioSocket }, protocol: ProtocolEnum.SOCKETIO },
167
- async () => result,
168
- )
169
-
170
- expect(typeof wsSent[0]).toBe('string')
171
- expect(typeof sioEmitted[0]).toBe('object')
172
- expect(JSON.parse(wsSent[0]).body).toEqual((sioEmitted[0] as any).body)
173
- })
174
- })
@@ -1,183 +0,0 @@
1
- import { beforeEach, describe, expect, test } from 'bun:test'
2
- import { runWithRequestId, runControllerStore } from '@/utils/helpers/context'
3
- import { G, G_PROP_NOT_ALLOWED, G_REQUEST_KEY_WARN, GStoreScopeEnum, looksLikeRequestScopedKey, propsFromTmp, resolveGStoreBoot } from '@/utils/helpers/state'
4
-
5
- const gStoreTmp = (gStore: Record<string, unknown>) => ({
6
- configs: { loaders: { system: { gStore } } },
7
- })
8
-
9
- beforeEach(() => {
10
- G.configureFromTmp({
11
- configs: {
12
- loaders: {
13
- system: {
14
- gStore: {
15
- options: { bootstrap: true, autoCreateProps: true },
16
- vars: {},
17
- },
18
- },
19
- },
20
- },
21
- })
22
- })
23
-
24
- describe('G flat props', () => {
25
- test('set / get / reset', () => {
26
- G.set('feature', true)
27
- expect(G.get('feature')).toBe(true)
28
- G.reset()
29
- expect(G.get('feature')).toBeUndefined()
30
- })
31
-
32
- test('merge / remove / snapshot', () => {
33
- G.merge({ a: 1, b: 2 })
34
- expect(G.snapshot()).toEqual({ a: 1, b: 2 })
35
- G.remove('a')
36
- expect(G.has('a')).toBe(false)
37
- })
38
-
39
- test('fallback default', () => {
40
- expect(G.get('missing', 'default')).toBe('default')
41
- })
42
- })
43
-
44
- describe('G options — bootstrap vs autoCreateProps', () => {
45
- test('vars from tmp.yml when bootstrap: true', () => {
46
- G.configureFromTmp(gStoreTmp({
47
- options: { bootstrap: true, autoCreateProps: false },
48
- vars: { test: false, region: 'eu-west' },
49
- }))
50
-
51
- expect(G.get('test')).toBe(false)
52
- expect(G.get('region')).toBe('eu-west')
53
- expect(G.declaredKeys()).toEqual(['test', 'region'])
54
- })
55
-
56
- test('bootstrap: false — tmp vars not loaded', () => {
57
- G.configureFromTmp(gStoreTmp({
58
- options: { bootstrap: false, autoCreateProps: true },
59
- vars: { test: true },
60
- }))
61
-
62
- expect(G.get('test')).toBeUndefined()
63
- G.set('test', false)
64
- expect(G.get('test')).toBe(false)
65
- })
66
-
67
- test('autoCreateProps: false — unknown runtime key throws', () => {
68
- G.configureFromTmp(gStoreTmp({
69
- options: { bootstrap: true, autoCreateProps: false },
70
- vars: { test: false },
71
- }))
72
-
73
- G.set('test', true)
74
- expect(() => G.set('runtimeOnly', 42)).toThrow(G_PROP_NOT_ALLOWED)
75
- })
76
-
77
- test('autoCreateProps: false — declared key update ok', () => {
78
- G.configureFromTmp(gStoreTmp({
79
- options: { autoCreateProps: false },
80
- vars: { test: false },
81
- }))
82
-
83
- G.set('test', true)
84
- expect(G.get('test')).toBe(true)
85
- })
86
-
87
- test('x/tmp.yml shape', () => {
88
- expect(propsFromTmp({
89
- configs: {
90
- loaders: {
91
- system: {
92
- gStore: {
93
- options: { bootstrap: true, autoCreateProps: false },
94
- vars: { test: false },
95
- },
96
- },
97
- },
98
- },
99
- })).toEqual({ test: false })
100
- })
101
-
102
- test('subscribeKey on declared prop', () => {
103
- G.configureFromTmp(gStoreTmp({
104
- options: { autoCreateProps: false },
105
- vars: { test: false },
106
- }))
107
-
108
- const seen: unknown[] = []
109
- const off = G.subscribeKey('test', (value) => seen.push(value))
110
- G.set('test', true)
111
- G.set('test', false)
112
- off()
113
- expect(seen).toEqual([true, false])
114
- })
115
-
116
- test('warnOnRequestKeys — request-scoped key warns', () => {
117
- const warn = console.warn
118
- const messages: unknown[] = []
119
- console.warn = (...args: unknown[]) => messages.push(args[0])
120
-
121
- try {
122
- G.configureFromTmp(gStoreTmp({
123
- options: { warnOnRequestKeys: true },
124
- vars: { maintenance: false },
125
- }))
126
- G.set('requestId', 'bad')
127
- expect(messages.some((m) => String(m).includes(G_REQUEST_KEY_WARN))).toBe(true)
128
- } finally {
129
- console.warn = warn
130
- }
131
- })
132
-
133
- test('warnOnRequestKeys: false — silent', () => {
134
- const warn = console.warn
135
- let called = false
136
- console.warn = () => { called = true }
137
-
138
- try {
139
- G.configureFromTmp(gStoreTmp({
140
- options: { warnOnRequestKeys: false },
141
- vars: {},
142
- }))
143
- G.set('cookies', {})
144
- expect(called).toBe(false)
145
- } finally {
146
- console.warn = warn
147
- }
148
- })
149
-
150
- test('looksLikeRequestScopedKey', () => {
151
- expect(looksLikeRequestScopedKey('requestId')).toBe(true)
152
- expect(looksLikeRequestScopedKey('maintenance')).toBe(false)
153
- })
154
- })
155
-
156
- describe('G stores — cross-context', () => {
157
- test('stores() lists global, run, controller', () => {
158
- G.set('test', false)
159
- const all = G.list()
160
-
161
- expect(all.map((s) => s.name)).toEqual([
162
- GStoreScopeEnum.GLOBAL,
163
- GStoreScopeEnum.RUN,
164
- GStoreScopeEnum.CONTROLLER,
165
- ])
166
- expect(all[0].active).toBe(true)
167
- expect(all[1].active).toBe(false)
168
- })
169
-
170
- test('scope(run) active inside runWithRequestId', () => {
171
- runWithRequestId('req-1', () => {
172
- const run = G.scope(GStoreScopeEnum.RUN)
173
- expect(run.active).toBe(true)
174
- expect(run.get('requestId')).toBe('req-1')
175
- })
176
- })
177
-
178
- test('scope(controller) active inside runController', () => {
179
- runControllerStore({ protocol: 'http' as any, requestId: 'c-1', metadata: { locals: {} } }, () => {
180
- expect(G.scope(GStoreScopeEnum.CONTROLLER).active).toBe(true)
181
- })
182
- })
183
- })