@xrystal/core 3.32.1 → 3.37.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +676 -136
- package/package.json +27 -24
- package/tsconfig.base.json +15 -0
- package/x/bin/commands/create.mjs +34 -5
- package/x/bin/commands/doctor.mjs +115 -25
- package/x/bin/commands/hooks.mjs +55 -0
- package/x/bin/commands/project.mjs +75 -42
- package/x/bin/commands/release.mjs +8 -3
- package/x/bin/commands/sync-toolchain.mjs +43 -0
- package/x/bin/commands/tmp.mjs +13 -4
- package/x/bin/helpers/.generated/.generated-from +1 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
- package/x/bin/helpers/banner.mjs +66 -12
- package/x/bin/helpers/build-config.mjs +342 -0
- package/x/bin/helpers/cli-help.mjs +164 -0
- package/x/bin/helpers/create-target.mjs +18 -2
- package/x/bin/helpers/project-artifacts.mjs +142 -0
- package/x/bin/helpers/runtime-info.mjs +172 -0
- package/x/bin/helpers/tmp-config.mjs +11 -10
- package/x/bin/helpers/tmp-layout.mjs +10 -16
- package/x/bin/helpers/tmp-schema.mjs +9 -0
- package/x/bin/helpers/toolchain-config.mjs +233 -0
- package/x/bin/main-cli.js +31 -3
- package/x/bin/scripts/clean-source-types.mjs +19 -0
- package/x/bin/scripts/fix-dist-imports.mjs +80 -0
- package/x/bin/scripts/install-git-hooks.mjs +86 -0
- package/x/bin/scripts/minify-dist.mjs +50 -0
- package/x/bin/scripts/prepare-npm-publish.mjs +39 -0
- package/x/bin/scripts/publish-guard.mjs +113 -0
- package/x/bin/scripts/verify-npm-pack.mjs +12 -0
- package/x/bin/scripts/verify-publish-config.mjs +10 -0
- package/x/bin/scripts/verify-version-bump.mjs +27 -0
- package/x/bin/scripts/version-check.mjs +173 -0
- package/x/dist/index.js +1 -0
- package/x/dist/loader/clients/index.js +1 -0
- package/x/dist/loader/configs/index.js +1 -0
- package/{source → x/dist}/loader/controller/index.d.ts +20 -17
- package/x/dist/loader/controller/index.js +1 -0
- package/x/dist/loader/dto/index.js +1 -0
- package/x/dist/loader/events/index.js +1 -0
- package/x/dist/loader/index.d.ts +11 -0
- package/x/dist/loader/index.js +1 -0
- package/{source → x/dist}/loader/kafka/index.d.ts +1 -0
- package/x/dist/loader/kafka/index.js +1 -0
- package/x/dist/loader/localizations/index.js +1 -0
- package/{source → x/dist}/loader/logger/index.d.ts +1 -0
- package/x/dist/loader/logger/index.js +2 -0
- package/x/dist/loader/service/index.js +1 -0
- package/x/dist/loader/system/index.js +1 -0
- package/x/dist/project/index.d.ts +12 -0
- package/x/dist/project/index.js +1 -0
- package/x/dist/utils/constants/defaults.json +44 -0
- package/x/dist/utils/constants/index.js +1 -0
- package/x/dist/utils/helpers/configs/index.js +1 -0
- package/x/dist/utils/helpers/context/controller-store.js +1 -0
- package/x/dist/utils/helpers/context/index.js +1 -0
- package/{source → x/dist}/utils/helpers/core/index.d.ts +1 -1
- package/x/dist/utils/helpers/core/index.js +1 -0
- package/x/dist/utils/helpers/core/paths.js +1 -0
- package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
- package/x/dist/utils/helpers/date/index.js +1 -0
- package/x/dist/utils/helpers/dispatch/index.js +1 -0
- package/x/dist/utils/helpers/dto/index.js +1 -0
- package/x/dist/utils/helpers/filters/index.js +1 -0
- package/x/dist/utils/helpers/framework/index.js +1 -0
- package/x/dist/utils/helpers/handlers/adapters.js +1 -0
- package/x/dist/utils/helpers/handlers/execute.js +1 -0
- package/x/dist/utils/helpers/handlers/index.js +1 -0
- package/x/dist/utils/helpers/hash/crypto.js +1 -0
- package/x/dist/utils/helpers/id/index.js +1 -0
- package/x/dist/utils/helpers/index.js +1 -0
- package/x/dist/utils/helpers/ip/index.js +1 -0
- package/x/dist/utils/helpers/is/index.js +1 -0
- package/x/dist/utils/helpers/locales/index.js +1 -0
- package/x/dist/utils/helpers/math/index.js +1 -0
- package/{source → x/dist}/utils/helpers/middleware/index.d.ts +2 -2
- package/x/dist/utils/helpers/middleware/index.js +1 -0
- package/x/dist/utils/helpers/objects/index.js +1 -0
- package/x/dist/utils/helpers/path/index.js +1 -0
- package/{source → x/dist}/utils/helpers/protocol/index.d.ts +2 -10
- package/x/dist/utils/helpers/protocol/index.js +1 -0
- package/x/dist/utils/helpers/protocol/options.js +1 -0
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
- package/{source → x/dist}/utils/helpers/runtime/index.d.ts +1 -0
- package/x/dist/utils/helpers/runtime/index.js +1 -0
- package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
- package/x/dist/utils/helpers/state/index.js +1 -0
- package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
- package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
- package/x/dist/utils/helpers/state/scopes.js +1 -0
- package/x/dist/utils/helpers/string/index.js +1 -0
- package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
- package/x/dist/utils/helpers/tests/tmp-watch.test.d.ts +1 -0
- package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
- package/x/dist/utils/helpers/timer/index.js +1 -0
- package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
- package/{source → x/dist}/utils/helpers/tmp/runtime-tmp.d.ts +2 -6
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
- package/{source → x/dist}/utils/helpers/tmp/tmp-loader.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
- package/x/dist/utils/helpers/validates/index.js +1 -0
- package/x/dist/utils/index.js +1 -0
- package/x/dist/utils/models/classes/class.clients.js +1 -0
- package/x/dist/utils/models/classes/class.interfaces.js +1 -0
- package/x/dist/utils/models/classes/class.service-locator.js +1 -0
- package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
- package/x/dist/utils/models/classes/class.x.js +1 -0
- package/x/dist/utils/models/enums/index.js +1 -0
- package/x/dist/utils/models/index.js +1 -0
- package/x/dist/utils/models/types/index.js +1 -0
- package/x/dist/utils/package-root.js +1 -0
- package/x/tmp.yml +51 -42
- package/source/index.js +0 -11
- package/source/loader/clients/index.js +0 -22
- package/source/loader/configs/index.js +0 -88
- package/source/loader/controller/index.js +0 -236
- package/source/loader/dto/index.js +0 -92
- package/source/loader/events/index.js +0 -44
- package/source/loader/index.d.ts +0 -11
- package/source/loader/index.js +0 -11
- package/source/loader/kafka/index.js +0 -137
- package/source/loader/localizations/index.js +0 -46
- package/source/loader/logger/index.js +0 -217
- package/source/loader/service/index.js +0 -7
- package/source/loader/system/index.js +0 -25
- package/source/project/index.d.ts +0 -8
- package/source/project/index.js +0 -70
- package/source/utils/constants/defaults.json +0 -15
- package/source/utils/constants/defaults.mjs +0 -10
- package/source/utils/constants/index.js +0 -22
- package/source/utils/helpers/configs/index.js +0 -1
- package/source/utils/helpers/context/controller-store.js +0 -12
- package/source/utils/helpers/context/index.js +0 -24
- package/source/utils/helpers/core/index.js +0 -58
- package/source/utils/helpers/core/paths.js +0 -78
- package/source/utils/helpers/core/tmp-layout.js +0 -241
- package/source/utils/helpers/date/index.js +0 -48
- package/source/utils/helpers/dispatch/index.js +0 -53
- package/source/utils/helpers/dto/index.js +0 -10
- package/source/utils/helpers/filters/index.js +0 -44
- package/source/utils/helpers/framework/index.js +0 -17
- package/source/utils/helpers/handlers/adapters.js +0 -40
- package/source/utils/helpers/handlers/execute.js +0 -82
- package/source/utils/helpers/handlers/index.js +0 -31
- package/source/utils/helpers/hash/crypto.js +0 -22
- package/source/utils/helpers/id/index.js +0 -24
- package/source/utils/helpers/index.js +0 -26
- package/source/utils/helpers/ip/index.js +0 -21
- package/source/utils/helpers/is/index.js +0 -35
- package/source/utils/helpers/locales/index.js +0 -82
- package/source/utils/helpers/math/index.js +0 -14
- package/source/utils/helpers/middleware/index.js +0 -36
- package/source/utils/helpers/objects/index.js +0 -55
- package/source/utils/helpers/path/index.js +0 -4
- package/source/utils/helpers/protocol/index.js +0 -99
- package/source/utils/helpers/protocol/options.js +0 -13
- package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
- package/source/utils/helpers/runtime/dto-access.js +0 -5
- package/source/utils/helpers/runtime/index.js +0 -1
- package/source/utils/helpers/state/index.js +0 -185
- package/source/utils/helpers/state/props-from-tmp.js +0 -44
- package/source/utils/helpers/state/request-key-guard.js +0 -42
- package/source/utils/helpers/state/scopes.js +0 -69
- package/source/utils/helpers/string/index.js +0 -9
- package/source/utils/helpers/timer/index.js +0 -5
- package/source/utils/helpers/tmp/index.d.ts +0 -3
- package/source/utils/helpers/tmp/index.js +0 -3
- package/source/utils/helpers/tmp/loader-tmp-sync.js +0 -13
- package/source/utils/helpers/tmp/runtime-tmp.js +0 -30
- package/source/utils/helpers/tmp/tmp-loader.js +0 -48
- package/source/utils/helpers/validates/index.js +0 -20
- package/source/utils/index.js +0 -3
- package/source/utils/models/classes/class.clients.js +0 -142
- package/source/utils/models/classes/class.interfaces.js +0 -10
- package/source/utils/models/classes/class.service-locator.js +0 -16
- package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
- package/source/utils/models/classes/class.x.js +0 -180
- package/source/utils/models/enums/index.js +0 -148
- package/source/utils/models/index.js +0 -9
- package/source/utils/models/types/index.js +0 -2
- package/source/utils/models/types/shims.d.ts +0 -123
- package/source/utils/package-root.js +0 -5
- package/x/tests/cli.test.ts +0 -85
- package/x/tests/context.test.ts +0 -25
- package/x/tests/dispatch.test.ts +0 -84
- package/x/tests/fixtures/locales/en/translation.json +0 -8
- package/x/tests/fixtures/locales/tr/translation.json +0 -8
- package/x/tests/frameworks.integration.test.ts +0 -185
- package/x/tests/helpers/i18n-setup.ts +0 -52
- package/x/tests/helpers/middleware.ts +0 -23
- package/x/tests/helpers/register-test-dto.ts +0 -52
- package/x/tests/i18n.integration.test.ts +0 -77
- package/x/tests/i18n.test.ts +0 -96
- package/x/tests/middleware.test.ts +0 -83
- package/x/tests/project-layout.test.ts +0 -65
- package/x/tests/protocol.test.ts +0 -75
- package/x/tests/realtime.examples.test.ts +0 -198
- package/x/tests/runtime-tmp.test.ts +0 -49
- package/x/tests/socket.integration.test.ts +0 -174
- package/x/tests/state.test.ts +0 -183
- package/x/tests/tmp-layout-guard.test.ts +0 -40
- /package/{source → x/dist}/index.d.ts +0 -0
- /package/{source → x/dist}/loader/clients/index.d.ts +0 -0
- /package/{source → x/dist}/loader/configs/index.d.ts +0 -0
- /package/{source → x/dist}/loader/dto/index.d.ts +0 -0
- /package/{source → x/dist}/loader/events/index.d.ts +0 -0
- /package/{source → x/dist}/loader/localizations/index.d.ts +0 -0
- /package/{source → x/dist}/loader/service/index.d.ts +0 -0
- /package/{source → x/dist}/loader/system/index.d.ts +0 -0
- /package/{source → x/dist}/utils/constants/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/context/controller-store.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/context/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/core/paths.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/core/tmp-layout.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/date/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/dispatch/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/dto/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/framework/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/handlers/adapters.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/handlers/execute.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/handlers/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/locales/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/protocol/options.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/runtime/dto-access.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/runtime/dto-types.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/props-from-tmp.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/request-key-guard.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/scopes.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
- /package/{source/utils/helpers/runtime/dto-types.js → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
- /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/tmp/loader-tmp-sync.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
- /package/{source → x/dist}/utils/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
- /package/{source → x/dist}/utils/models/enums/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/types/index.d.ts +0 -0
- /package/{source → x/dist}/utils/package-root.d.ts +0 -0
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { DTO } from '@xrystal/dto'
|
|
3
|
-
import { Elysia } from 'elysia'
|
|
4
|
-
import { runController, type ControllerContext } from '@/loader/controller'
|
|
5
|
-
import { runWithRequestId } from '@/utils/helpers/context'
|
|
6
|
-
import { dispatchResult } from '@/utils/helpers/dispatch'
|
|
7
|
-
import { createDtoMiddleware, normalizeFrameworkKind, resolveDtoAdapter } from '@/utils/helpers/middleware'
|
|
8
|
-
import { httpMiddleware } from './helpers/middleware'
|
|
9
|
-
import { FrameworkEnum } from '@/utils/models'
|
|
10
|
-
import { parseResponseMessage } from '@/utils/helpers/locales'
|
|
11
|
-
|
|
12
|
-
const en = (key: string) => ({
|
|
13
|
-
'responseMessage.successfully': 'Operation completed successfully',
|
|
14
|
-
}[key] ?? key)
|
|
15
|
-
|
|
16
|
-
async function runAction(store: ControllerContext, action: () => Promise<unknown>, res?: any) {
|
|
17
|
-
return runWithRequestId(store.requestId ?? 'test-id', () =>
|
|
18
|
-
runController(store, async () => dispatchResult(await action(), store, res)),
|
|
19
|
-
store.protocol === 'ws' ? 'ws' : 'http',
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
describe('framework pipeline — express', () => {
|
|
24
|
-
test('middleware + ctr simulation + dispatch JSON', async () => {
|
|
25
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
26
|
-
const req: any = { headers: { 'accept-language': 'en' } }
|
|
27
|
-
const res: any = {
|
|
28
|
-
headersSent: false,
|
|
29
|
-
statusCode: 0,
|
|
30
|
-
body: undefined as unknown,
|
|
31
|
-
setHeader() {},
|
|
32
|
-
status(code: number) { this.statusCode = code; return this },
|
|
33
|
-
json(body: unknown) { this.body = body; return this },
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await new Promise<void>((resolve) => {
|
|
37
|
-
httpMiddleware(runtime, 'express')(req, res, async () => {
|
|
38
|
-
const store: ControllerContext = {
|
|
39
|
-
framework: FrameworkEnum.EXPRESS,
|
|
40
|
-
req,
|
|
41
|
-
res,
|
|
42
|
-
requestId: req.ctx.requestId,
|
|
43
|
-
metadata: { locals: {} },
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
await runAction(store, async () => {
|
|
47
|
-
const message = parseResponseMessage('@successfully user', en, false)
|
|
48
|
-
return res.builder.as.ok([{ id: 1 }], message).build()
|
|
49
|
-
}, res)
|
|
50
|
-
|
|
51
|
-
expect(res.statusCode).toBe(200)
|
|
52
|
-
expect(res.body.status).toBe(true)
|
|
53
|
-
expect(res.body.message).toContain('user')
|
|
54
|
-
expect(res.body.payload.data).toEqual([{ id: 1 }])
|
|
55
|
-
resolve()
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
describe('framework pipeline — fetch', () => {
|
|
62
|
-
test('forRequest + dispatch returns Response', async () => {
|
|
63
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
64
|
-
const request = new Request('https://api.test/users', {
|
|
65
|
-
headers: { 'x-request-id': 'fetch-1', 'accept-language': 'en' },
|
|
66
|
-
})
|
|
67
|
-
const derived = runtime.forRequest(request)
|
|
68
|
-
|
|
69
|
-
const store: ControllerContext = {
|
|
70
|
-
framework: FrameworkEnum.FETCH,
|
|
71
|
-
req: request,
|
|
72
|
-
ctx: { ...derived, request },
|
|
73
|
-
requestId: derived.requestId,
|
|
74
|
-
metadata: { locals: {} },
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const out = await runAction(store, async () => {
|
|
78
|
-
const message = parseResponseMessage('@successfully user', en, false)
|
|
79
|
-
return derived.builder.as.ok([], message).build()
|
|
80
|
-
}) as Response
|
|
81
|
-
|
|
82
|
-
expect(out).toBeInstanceOf(Response)
|
|
83
|
-
expect(out.status).toBe(200)
|
|
84
|
-
const json = await out.json() as any
|
|
85
|
-
expect(json.message).toContain('Operation completed successfully')
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
describe('framework pipeline — elysia', () => {
|
|
90
|
-
test('real Elysia app: plugin + route + dispatch JSON', async () => {
|
|
91
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
92
|
-
const plugin = createDtoMiddleware(runtime, 'elysia')
|
|
93
|
-
|
|
94
|
-
const app = new Elysia()
|
|
95
|
-
.use(plugin as any)
|
|
96
|
-
.get('/users', async (ctx: any) => {
|
|
97
|
-
const store: ControllerContext = {
|
|
98
|
-
framework: FrameworkEnum.ELYSIA,
|
|
99
|
-
ctx,
|
|
100
|
-
requestId: ctx.requestId,
|
|
101
|
-
metadata: { locals: {} },
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return runWithRequestId(store.requestId ?? 'elysia-1', () =>
|
|
105
|
-
runController(store, async () => {
|
|
106
|
-
const message = parseResponseMessage('@successfully user', en, false)
|
|
107
|
-
return ctx.builder.as.ok([{ id: 1 }], message).build()
|
|
108
|
-
}),
|
|
109
|
-
).then((result) => dispatchResult(result, store))
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
const res = await app.handle(new Request('http://localhost/users'))
|
|
113
|
-
expect(res.status).toBe(200)
|
|
114
|
-
|
|
115
|
-
const json = await res.json() as any
|
|
116
|
-
expect(json.status).toBe(true)
|
|
117
|
-
expect(json.message).toContain('user')
|
|
118
|
-
expect(json.payload.data).toEqual([{ id: 1 }])
|
|
119
|
-
})
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
describe('framework pipeline — node http', () => {
|
|
123
|
-
test('nodeSink writes JSON to ServerResponse-like object', async () => {
|
|
124
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
125
|
-
let ended = ''
|
|
126
|
-
const res: any = {
|
|
127
|
-
headersSent: false,
|
|
128
|
-
statusCode: 0,
|
|
129
|
-
headers: {} as Record<string, string>,
|
|
130
|
-
setHeader(name: string, value: string) { this.headers[name.toLowerCase()] = value },
|
|
131
|
-
getHeader(name: string) { return this.headers[name.toLowerCase()] },
|
|
132
|
-
end(body?: string) { ended = body ?? '' },
|
|
133
|
-
}
|
|
134
|
-
const req: any = { headers: {} }
|
|
135
|
-
|
|
136
|
-
await new Promise<void>((resolve) => {
|
|
137
|
-
httpMiddleware(runtime, 'node')(req, res, async () => {
|
|
138
|
-
const store: ControllerContext = {
|
|
139
|
-
framework: FrameworkEnum.NODE,
|
|
140
|
-
req,
|
|
141
|
-
res,
|
|
142
|
-
requestId: req.ctx?.requestId,
|
|
143
|
-
metadata: { locals: {} },
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
await runAction(store, async () => {
|
|
147
|
-
return res.builder.as.ok({ ok: true }, 'OK').build()
|
|
148
|
-
}, res)
|
|
149
|
-
|
|
150
|
-
const parsed = JSON.parse(ended)
|
|
151
|
-
expect(parsed.status).toBe(true)
|
|
152
|
-
expect(res.statusCode).toBe(200)
|
|
153
|
-
resolve()
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
describe('framework adapter map', () => {
|
|
160
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
161
|
-
|
|
162
|
-
test.each([
|
|
163
|
-
['express', FrameworkEnum.EXPRESS],
|
|
164
|
-
['elysia', FrameworkEnum.ELYSIA],
|
|
165
|
-
['node', FrameworkEnum.NODE],
|
|
166
|
-
['fetch', FrameworkEnum.FETCH],
|
|
167
|
-
['websocket', FrameworkEnum.WEBSOCKET],
|
|
168
|
-
['socketio', FrameworkEnum.SOCKETIO],
|
|
169
|
-
['socketIo', FrameworkEnum.SOCKETIO],
|
|
170
|
-
] as const)('normalizeFrameworkKind(%s)', (input, expected) => {
|
|
171
|
-
expect(normalizeFrameworkKind(input)).toBe(expected)
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
test('elysia adapter is a plugin (object)', () => {
|
|
175
|
-
const plugin = resolveDtoAdapter(runtime, FrameworkEnum.ELYSIA)
|
|
176
|
-
expect(plugin).toBeDefined()
|
|
177
|
-
expect(typeof plugin).toBe('object')
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
test('socketio and websocket adapters differ', () => {
|
|
181
|
-
expect(resolveDtoAdapter(runtime, FrameworkEnum.SOCKETIO)).not.toBe(
|
|
182
|
-
resolveDtoAdapter(runtime, FrameworkEnum.WEBSOCKET),
|
|
183
|
-
)
|
|
184
|
-
})
|
|
185
|
-
})
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { fileURLToPath } from 'node:url'
|
|
3
|
-
import i18next from 'i18next'
|
|
4
|
-
import Backend from 'i18next-fs-backend'
|
|
5
|
-
import i18nextMiddleware from 'i18next-http-middleware'
|
|
6
|
-
|
|
7
|
-
const fixturesDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '../fixtures/locales')
|
|
8
|
-
|
|
9
|
-
let ready: Promise<typeof i18next> | null = null
|
|
10
|
-
|
|
11
|
-
export function initTestI18n() {
|
|
12
|
-
if (!ready) {
|
|
13
|
-
ready = i18next
|
|
14
|
-
.use(Backend)
|
|
15
|
-
.use(i18nextMiddleware.LanguageDetector)
|
|
16
|
-
.init({
|
|
17
|
-
initAsync: true,
|
|
18
|
-
lng: 'en',
|
|
19
|
-
fallbackLng: 'en',
|
|
20
|
-
preload: ['en', 'tr'],
|
|
21
|
-
ns: ['translation'],
|
|
22
|
-
defaultNS: 'translation',
|
|
23
|
-
backend: {
|
|
24
|
-
loadPath: path.join(fixturesDir, '{{lng}}/translation.json'),
|
|
25
|
-
},
|
|
26
|
-
detection: {
|
|
27
|
-
order: ['header'],
|
|
28
|
-
lookupHeader: 'accept-language',
|
|
29
|
-
},
|
|
30
|
-
})
|
|
31
|
-
.then(() => i18next)
|
|
32
|
-
}
|
|
33
|
-
return ready
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function i18nExpressMiddleware() {
|
|
37
|
-
return i18nextMiddleware.handle(i18next)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function attachI18n(req: { headers?: Record<string, string> }, res: Record<string, unknown> = {}) {
|
|
41
|
-
await initTestI18n()
|
|
42
|
-
const headers = req.headers ?? {}
|
|
43
|
-
const expressLike = {
|
|
44
|
-
...req,
|
|
45
|
-
headers,
|
|
46
|
-
get(name: string) { return headers[name.toLowerCase()] ?? headers[name] },
|
|
47
|
-
header(name: string) { return this.get(name) },
|
|
48
|
-
}
|
|
49
|
-
await new Promise<void>((resolve) => i18nExpressMiddleware()(expressLike as any, res as any, resolve))
|
|
50
|
-
Object.assign(req, expressLike)
|
|
51
|
-
return req as typeof req & { t: (key: string) => string; language: string }
|
|
52
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createDtoMiddleware,
|
|
3
|
-
type DtoMiddlewareConfig,
|
|
4
|
-
type HttpMiddleware,
|
|
5
|
-
type SocketMiddleware,
|
|
6
|
-
} from '@/utils/helpers/middleware'
|
|
7
|
-
import type { DTO } from '@xrystal/dto'
|
|
8
|
-
|
|
9
|
-
export function httpMiddleware(runtime: DTO, config?: DtoMiddlewareConfig): HttpMiddleware {
|
|
10
|
-
const adapter = createDtoMiddleware(runtime, config)
|
|
11
|
-
if (!adapter || typeof adapter !== 'function') {
|
|
12
|
-
throw new Error(`Expected HTTP middleware, got ${String(config)}`)
|
|
13
|
-
}
|
|
14
|
-
return adapter as HttpMiddleware
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function socketMiddleware(runtime: DTO, config?: DtoMiddlewareConfig): SocketMiddleware {
|
|
18
|
-
const adapter = createDtoMiddleware(runtime, config)
|
|
19
|
-
if (!adapter || typeof adapter !== 'function') {
|
|
20
|
-
throw new Error(`Expected socket middleware, got ${String(config)}`)
|
|
21
|
-
}
|
|
22
|
-
return adapter as SocketMiddleware
|
|
23
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { DTO } from '@xrystal/dto'
|
|
2
|
-
import DtoRuntime from '@/loader/dto'
|
|
3
|
-
import Logger from '@/loader/logger'
|
|
4
|
-
import System from '@/loader/system'
|
|
5
|
-
import { setRuntimeTmpConfigs } from '@/utils/helpers/tmp/runtime-tmp'
|
|
6
|
-
import { G } from '@/utils/helpers/state'
|
|
7
|
-
import { x } from '@/utils/models'
|
|
8
|
-
|
|
9
|
-
export type TestDtoOptions = {
|
|
10
|
-
socketEvent?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type TestRuntimeOptions = TestDtoOptions & {
|
|
14
|
-
tmp?: Record<string, unknown>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function registerTestRuntime(options: TestRuntimeOptions = {}) {
|
|
18
|
-
registerTestDto(options)
|
|
19
|
-
|
|
20
|
-
const configs = {
|
|
21
|
-
framework: 'elysia',
|
|
22
|
-
protocols: ['http', 'ws'],
|
|
23
|
-
...(options.tmp ?? {}),
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
setRuntimeTmpConfigs(configs)
|
|
27
|
-
G.configureFromTmp({ configs })
|
|
28
|
-
|
|
29
|
-
x.registerInstance(System, {
|
|
30
|
-
tmp: { configs },
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
x.registerInstance(Logger, {
|
|
34
|
-
log: () => {},
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function registerTestDto(options: TestDtoOptions = {}) {
|
|
39
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
40
|
-
x.registerInstance(DtoRuntime, {
|
|
41
|
-
config: { socket: { event: options.socketEvent ?? 'response' } },
|
|
42
|
-
attachWebSocket: (socket: unknown, requestId?: string) => runtime.attachWebSocket(socket, requestId),
|
|
43
|
-
attachSocketIo: (socket: unknown) => runtime.attachSocketIo(socket),
|
|
44
|
-
forRequest: (request: Request) => runtime.forRequest(request),
|
|
45
|
-
express: () => runtime.express(),
|
|
46
|
-
elysia: () => runtime.elysia(),
|
|
47
|
-
node: () => runtime.node(),
|
|
48
|
-
websocket: () => runtime.websocket(),
|
|
49
|
-
socketIo: () => runtime.socketIo(),
|
|
50
|
-
})
|
|
51
|
-
return runtime
|
|
52
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { beforeAll, describe, expect, test } from 'bun:test'
|
|
2
|
-
import { DTO } from '@xrystal/dto'
|
|
3
|
-
import { runController, type ControllerContext } from '@/loader/controller'
|
|
4
|
-
import { parseResponseMessage } from '@/utils/helpers/locales'
|
|
5
|
-
import { createDtoMiddleware } from '@/utils/helpers/middleware'
|
|
6
|
-
import { dispatchResult } from '@/utils/helpers/dispatch'
|
|
7
|
-
import { runWithRequestId } from '@/utils/helpers/context'
|
|
8
|
-
import { FrameworkEnum } from '@/utils/models'
|
|
9
|
-
import { attachI18n, initTestI18n } from './helpers/i18n-setup'
|
|
10
|
-
|
|
11
|
-
beforeAll(() => initTestI18n())
|
|
12
|
-
|
|
13
|
-
async function runExpressWithLocale(acceptLanguage: string) {
|
|
14
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
15
|
-
const req: any = { headers: { 'accept-language': acceptLanguage, 'x-request-id': 'i18n-test' } }
|
|
16
|
-
const res: any = {
|
|
17
|
-
headersSent: false,
|
|
18
|
-
statusCode: 0,
|
|
19
|
-
body: undefined as unknown,
|
|
20
|
-
setHeader() {},
|
|
21
|
-
status(code: number) { this.statusCode = code; return this },
|
|
22
|
-
json(body: unknown) { this.body = body; return this },
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
await attachI18n(req, res)
|
|
26
|
-
|
|
27
|
-
await new Promise<void>((resolve) => {
|
|
28
|
-
createDtoMiddleware(runtime, 'express')(req, res, async () => {
|
|
29
|
-
const store: ControllerContext = {
|
|
30
|
-
framework: FrameworkEnum.EXPRESS,
|
|
31
|
-
req,
|
|
32
|
-
res,
|
|
33
|
-
requestId: req.ctx.requestId,
|
|
34
|
-
metadata: { locals: {} },
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
await runWithRequestId(store.requestId!, () =>
|
|
38
|
-
runController(store, async () => {
|
|
39
|
-
const message = parseResponseMessage('@successfully user', req.t, false)
|
|
40
|
-
const result = res.builder.as.ok([{ id: 1 }], message).build()
|
|
41
|
-
dispatchResult(result, store, res)
|
|
42
|
-
}),
|
|
43
|
-
)
|
|
44
|
-
resolve()
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
return res.body as { message: string; payload: { data: unknown[] } }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
describe('i18n loader integration (i18next + JSON fixtures)', () => {
|
|
52
|
-
test('accept-language: en → English responseMessage from translation.json', async () => {
|
|
53
|
-
const body = await runExpressWithLocale('en')
|
|
54
|
-
expect(body.message).toContain('user')
|
|
55
|
-
expect(body.message).toContain('Operation completed successfully')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test('accept-language: tr → Turkish responseMessage from translation.json', async () => {
|
|
59
|
-
const body = await runExpressWithLocale('tr')
|
|
60
|
-
expect(body.message).toContain('user')
|
|
61
|
-
expect(body.message).toContain('İşlem başarıyla tamamlandı')
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
test('req.t resolves nested responseMessage.notFound key', async () => {
|
|
65
|
-
const req: any = { headers: { 'accept-language': 'tr' } }
|
|
66
|
-
await attachI18n(req)
|
|
67
|
-
const msg = parseResponseMessage('@notFound user - profile', req.t, false)
|
|
68
|
-
expect(msg).toContain('user profile')
|
|
69
|
-
expect(msg).toContain('Bulunamadı')
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
test('i18next-fs-backend loads both en and tr namespaces', async () => {
|
|
73
|
-
const i18n = await initTestI18n()
|
|
74
|
-
expect(i18n.t('responseMessage.successfully', { lng: 'en' })).toBe('Operation completed successfully')
|
|
75
|
-
expect(i18n.t('responseMessage.successfully', { lng: 'tr' })).toBe('İşlem başarıyla tamamlandı')
|
|
76
|
-
})
|
|
77
|
-
})
|
package/x/tests/i18n.test.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { parseResponseMessage, responseMessageHelper } from '@/utils/helpers/locales'
|
|
3
|
-
|
|
4
|
-
const en = (key: string) => ({
|
|
5
|
-
'responseMessage.successfully': 'Operation completed successfully',
|
|
6
|
-
'responseMessage.unsuccessful': 'Operation failed',
|
|
7
|
-
'responseMessage.notFound': 'Not found',
|
|
8
|
-
'responseMessage.process': 'Process completed',
|
|
9
|
-
}[key] ?? key)
|
|
10
|
-
|
|
11
|
-
const tr = (key: string) => ({
|
|
12
|
-
'responseMessage.successfully': 'İşlem başarıyla tamamlandı',
|
|
13
|
-
'responseMessage.unsuccessful': 'İşlem başarısız',
|
|
14
|
-
'responseMessage.notFound': 'Bulunamadı',
|
|
15
|
-
'responseMessage.process': 'İşlem tamamlandı',
|
|
16
|
-
}[key] ?? key)
|
|
17
|
-
|
|
18
|
-
describe('responseMessageHelper', () => {
|
|
19
|
-
test('successfully with English t()', () => {
|
|
20
|
-
const msg = responseMessageHelper.successfully('user', '', en)
|
|
21
|
-
expect(msg).toContain('user')
|
|
22
|
-
expect(msg).toContain('Operation completed successfully')
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
test('successfully with Turkish t()', () => {
|
|
26
|
-
const msg = responseMessageHelper.successfully('kullanıcı', '', tr)
|
|
27
|
-
expect(msg).toContain('kullanıcı')
|
|
28
|
-
expect(msg).toContain('İşlem başarıyla tamamlandı')
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('notFound with params', () => {
|
|
32
|
-
const msg = responseMessageHelper.notFound('User', 'id 42', en)
|
|
33
|
-
expect(msg).toContain('User id 42')
|
|
34
|
-
expect(msg).toContain('Not found')
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
describe('parseResponseMessage (@ syntax)', () => {
|
|
39
|
-
test('@successfully user → helper + i18n', () => {
|
|
40
|
-
const msg = parseResponseMessage('@successfully user', en, false)
|
|
41
|
-
expect(msg).toContain('user')
|
|
42
|
-
expect(msg).toContain('Operation completed successfully')
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
test('@successfully user in Turkish', () => {
|
|
46
|
-
const msg = parseResponseMessage('@successfully user', tr, false)
|
|
47
|
-
expect(msg).toContain('user')
|
|
48
|
-
expect(msg).toContain('İşlem başarıyla tamamlandı')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('@unsuccessful auth → error path', () => {
|
|
52
|
-
const msg = parseResponseMessage('@unsuccessful auth', en, true)
|
|
53
|
-
expect(msg).toContain('auth')
|
|
54
|
-
expect(msg).toContain('Operation failed')
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('@notFound user - profile', () => {
|
|
58
|
-
const msg = parseResponseMessage('@notFound user - profile', en, false)
|
|
59
|
-
expect(msg).toContain('user profile')
|
|
60
|
-
expect(msg).toContain('Not found')
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
test('success_process default key uses process helper via ok path simulation', () => {
|
|
64
|
-
const msg = parseResponseMessage('success_process', en, false)
|
|
65
|
-
expect(msg).toContain('success_process')
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
test('empty message falls back to successfully', () => {
|
|
69
|
-
const msg = parseResponseMessage('', en, false)
|
|
70
|
-
expect(msg).toContain('Operation completed successfully')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
test('unknown @method uses proxy fallback label', () => {
|
|
74
|
-
const msg = parseResponseMessage('@unknownKey item', en, false)
|
|
75
|
-
expect(msg).toContain('item')
|
|
76
|
-
expect(msg).toContain('unknownKey')
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
describe('parseResponseMessage in response body (simulated ctr flow)', () => {
|
|
81
|
-
test('message lands in FinalResult.body.message', async () => {
|
|
82
|
-
const { DTO } = await import('@xrystal/dto')
|
|
83
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
84
|
-
const req: any = { headers: {} }
|
|
85
|
-
const res: any = { setHeader() {}, builder: undefined }
|
|
86
|
-
|
|
87
|
-
const middleware = runtime.express() as (req: any, res: any, next: () => void) => void
|
|
88
|
-
middleware(req, res, () => {
|
|
89
|
-
const message = parseResponseMessage('@successfully user', en, false)
|
|
90
|
-
const result = res.builder.as.ok({ id: 1 }, message).build()
|
|
91
|
-
expect(result.body.message).toContain('user')
|
|
92
|
-
expect(result.body.message).toContain('Operation completed successfully')
|
|
93
|
-
expect(result.body.status).toBe(true)
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
})
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { DTO } from '@xrystal/dto'
|
|
3
|
-
import { createDtoMiddleware, normalizeFrameworkKind, resolveDtoAdapter } from '@/utils/helpers/middleware'
|
|
4
|
-
import { FrameworkEnum } from '@/utils/models'
|
|
5
|
-
|
|
6
|
-
describe('normalizeFrameworkKind', () => {
|
|
7
|
-
test('maps string aliases', () => {
|
|
8
|
-
expect(normalizeFrameworkKind('express')).toBe(FrameworkEnum.EXPRESS)
|
|
9
|
-
expect(normalizeFrameworkKind('elysia')).toBe(FrameworkEnum.ELYSIA)
|
|
10
|
-
expect(normalizeFrameworkKind('socketIo')).toBe(FrameworkEnum.SOCKETIO)
|
|
11
|
-
expect(normalizeFrameworkKind('socket-io')).toBe(FrameworkEnum.SOCKETIO)
|
|
12
|
-
expect(normalizeFrameworkKind('websocket')).toBe(FrameworkEnum.WEBSOCKET)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('reads framework from config object', () => {
|
|
16
|
-
expect(normalizeFrameworkKind({ framework: 'elysia' })).toBe(FrameworkEnum.ELYSIA)
|
|
17
|
-
})
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
describe('resolveDtoAdapter', () => {
|
|
21
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
22
|
-
|
|
23
|
-
test('express framework', () => {
|
|
24
|
-
expect(typeof resolveDtoAdapter(runtime, FrameworkEnum.EXPRESS)).toBe('function')
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
test('elysia framework', () => {
|
|
28
|
-
expect(resolveDtoAdapter(runtime, FrameworkEnum.ELYSIA)).toBeDefined()
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('fetch returns null — per-request forRequest instead', () => {
|
|
32
|
-
expect(resolveDtoAdapter(runtime, FrameworkEnum.FETCH)).toBeNull()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('socketio → socketIo(), websocket → websocket()', () => {
|
|
36
|
-
const ws = resolveDtoAdapter(runtime, FrameworkEnum.WEBSOCKET)
|
|
37
|
-
const io = resolveDtoAdapter(runtime, FrameworkEnum.SOCKETIO)
|
|
38
|
-
expect(typeof ws).toBe('function')
|
|
39
|
-
expect(typeof io).toBe('function')
|
|
40
|
-
expect(ws).not.toBe(io)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('createDtoMiddleware', () => {
|
|
45
|
-
test('config string selects adapter', () => {
|
|
46
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
47
|
-
expect(typeof createDtoMiddleware(runtime, 'express')).toBe('function')
|
|
48
|
-
expect(createDtoMiddleware(runtime, 'fetch')).toBeNull()
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
describe('express middleware wiring', () => {
|
|
53
|
-
test('attaches builder and requestId on req/res', async () => {
|
|
54
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
55
|
-
const middleware = createDtoMiddleware(runtime, 'express') as (
|
|
56
|
-
req: any, res: any, next: () => void,
|
|
57
|
-
) => void
|
|
58
|
-
|
|
59
|
-
const req: any = { headers: { 'x-request-id': 'trace-from-header' } }
|
|
60
|
-
const res: any = { setHeader() {}, builder: undefined }
|
|
61
|
-
|
|
62
|
-
await new Promise<void>((resolve) => {
|
|
63
|
-
middleware(req, res, () => {
|
|
64
|
-
expect(req.ctx.requestId).toBe('trace-from-header')
|
|
65
|
-
expect(res.builder).toBeDefined()
|
|
66
|
-
expect(typeof res.builder.as.ok).toBe('function')
|
|
67
|
-
resolve()
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
describe('fetch forRequest wiring', () => {
|
|
74
|
-
test('attaches builder per request', () => {
|
|
75
|
-
const runtime = new DTO({ withDefaultHeaders: false })
|
|
76
|
-
const request = new Request('https://api.test/health', {
|
|
77
|
-
headers: { 'x-correlation-id': 'fetch-trace-1' },
|
|
78
|
-
})
|
|
79
|
-
const derived = runtime.forRequest(request)
|
|
80
|
-
expect(derived.requestId).toBe('fetch-trace-1')
|
|
81
|
-
expect(derived.builder).toBeDefined()
|
|
82
|
-
})
|
|
83
|
-
})
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import fs from 'node:fs'
|
|
3
|
-
import os from 'node:os'
|
|
4
|
-
import path from 'node:path'
|
|
5
|
-
|
|
6
|
-
describe('tmp layout resolver', () => {
|
|
7
|
-
test('reads rootFolderPath and paths from x/tmp.yml in core repo', async () => {
|
|
8
|
-
const { resolveTmpLayout } = await import('../bin/helpers/tmp-layout.mjs')
|
|
9
|
-
|
|
10
|
-
const layout = resolveTmpLayout(process.cwd())
|
|
11
|
-
expect(layout.rootFolderPath).toBe('x')
|
|
12
|
-
expect(layout.tmpFilePath?.endsWith(`${path.sep}x${path.sep}tmp.yml`)).toBe(true)
|
|
13
|
-
expect(layout.paths.tests).toBe('tests')
|
|
14
|
-
expect(layout.paths.environments).toBe('environments')
|
|
15
|
-
expect(layout.paths.dist).toBe('dist')
|
|
16
|
-
expect(layout.pathsAbs.tests.endsWith(`${path.sep}x${path.sep}tests`)).toBe(true)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test('custom rootFolderPath in tmp.yml for services', async () => {
|
|
20
|
-
const {
|
|
21
|
-
buildTmpLayout,
|
|
22
|
-
resolveRootFolderPath,
|
|
23
|
-
resolveLayoutPaths,
|
|
24
|
-
} = await import('../bin/helpers/tmp-layout.mjs')
|
|
25
|
-
|
|
26
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xrystal-layout-'))
|
|
27
|
-
const tmpFile = path.join(tmpDir, 'infra', 'tmp.yml')
|
|
28
|
-
fs.mkdirSync(path.dirname(tmpFile), { recursive: true })
|
|
29
|
-
fs.writeFileSync(
|
|
30
|
-
tmpFile,
|
|
31
|
-
[
|
|
32
|
-
'project:',
|
|
33
|
-
' name: infra',
|
|
34
|
-
'configs:',
|
|
35
|
-
' rootFolderPath: infra',
|
|
36
|
-
' paths:',
|
|
37
|
-
' tests: specs',
|
|
38
|
-
' environments: env',
|
|
39
|
-
' dist: out',
|
|
40
|
-
].join('\n'),
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
const tmp = {
|
|
44
|
-
project: { name: 'infra' },
|
|
45
|
-
configs: {
|
|
46
|
-
rootFolderPath: 'infra',
|
|
47
|
-
paths: { tests: 'specs', environments: 'env', dist: 'out' },
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
expect(resolveRootFolderPath(tmp, tmpFile, tmpDir)).toBe('infra')
|
|
52
|
-
expect(resolveLayoutPaths(tmp.configs)).toEqual({
|
|
53
|
-
tests: 'specs',
|
|
54
|
-
environments: 'env',
|
|
55
|
-
dist: 'out',
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
const layout = buildTmpLayout(tmpDir, tmp, tmpFile)
|
|
59
|
-
expect(layout.pathsAbs.tests).toBe(path.join(tmpDir, 'infra', 'specs'))
|
|
60
|
-
expect(layout.pathsAbs.environments).toBe(path.join(tmpDir, 'infra', 'env'))
|
|
61
|
-
expect(layout.pathsAbs.dist).toBe(path.join(tmpDir, 'infra', 'out'))
|
|
62
|
-
|
|
63
|
-
fs.rmSync(tmpDir, { recursive: true, force: true })
|
|
64
|
-
})
|
|
65
|
-
})
|