nmtjs 0.16.0-beta.9 → 0.16.0
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/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/entrypoints/worker.js +9 -9
- package/dist/entrypoints/worker.js.map +1 -1
- package/dist/index.d.ts +14 -11
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime/application/index.d.ts +1 -5
- package/dist/runtime/application/index.js +1 -5
- package/dist/runtime/application/index.js.map +1 -1
- package/dist/runtime/enums.d.ts +1 -12
- package/dist/runtime/enums.js +1 -14
- package/dist/runtime/enums.js.map +1 -1
- package/dist/runtime/hooks.d.ts +1 -4
- package/dist/runtime/hooks.js +1 -3
- package/dist/runtime/hooks.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -3
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/injectables.d.ts +3 -3
- package/dist/runtime/jobs/job.d.ts +1 -2
- package/dist/runtime/jobs/job.js.map +1 -1
- package/dist/runtime/jobs/router.d.ts +2 -5
- package/dist/runtime/jobs/router.js +2 -3
- package/dist/runtime/jobs/router.js.map +1 -1
- package/dist/runtime/jobs/runner.d.ts +1 -1
- package/dist/runtime/jobs/runner.js +1 -1
- package/dist/runtime/jobs/runner.js.map +1 -1
- package/dist/runtime/jobs/types.d.ts +1 -1
- package/dist/runtime/metrics/metric.d.ts +2 -2
- package/dist/runtime/metrics/metric.js +1 -1
- package/dist/runtime/metrics/metric.js.map +1 -1
- package/dist/runtime/metrics/registry.d.ts +3 -3
- package/dist/runtime/metrics/registry.js +1 -1
- package/dist/runtime/metrics/registry.js.map +1 -1
- package/dist/runtime/metrics/server.js +1 -1
- package/dist/runtime/metrics/server.js.map +1 -1
- package/dist/runtime/plugin.d.ts +2 -8
- package/dist/runtime/plugin.js +1 -3
- package/dist/runtime/plugin.js.map +1 -1
- package/dist/runtime/runtime.d.ts +2 -2
- package/dist/runtime/runtime.js +1 -2
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/server/applications.js +3 -0
- package/dist/runtime/server/applications.js.map +1 -1
- package/dist/runtime/server/config.d.ts +15 -12
- package/dist/runtime/server/config.js.map +1 -1
- package/dist/runtime/server/jobs.d.ts +6 -7
- package/dist/runtime/server/jobs.js +44 -30
- package/dist/runtime/server/jobs.js.map +1 -1
- package/dist/runtime/subscription/redis.d.ts +1 -1
- package/dist/runtime/subscription/redis.js.map +1 -1
- package/dist/runtime/types.d.ts +3 -11
- package/dist/runtime/workers/application.d.ts +15 -33
- package/dist/runtime/workers/application.js +46 -139
- package/dist/runtime/workers/application.js.map +1 -1
- package/dist/runtime/workers/job.js +2 -1
- package/dist/runtime/workers/job.js.map +1 -1
- package/dist/vite/server.js +1 -1
- package/dist/vite/server.js.map +1 -1
- package/package.json +19 -14
- package/src/cli.ts +2 -3
- package/src/entrypoints/worker.ts +11 -9
- package/src/index.ts +12 -5
- package/src/runtime/application/index.ts +1 -5
- package/src/runtime/enums.ts +2 -14
- package/src/runtime/hooks.ts +1 -5
- package/src/runtime/index.ts +2 -3
- package/src/runtime/injectables.ts +2 -2
- package/src/runtime/jobs/job.ts +1 -2
- package/src/runtime/jobs/router.ts +12 -15
- package/src/runtime/jobs/runner.ts +2 -2
- package/src/runtime/jobs/types.ts +1 -1
- package/src/runtime/metrics/metric.ts +2 -2
- package/src/runtime/metrics/registry.ts +5 -1
- package/src/runtime/metrics/server.ts +1 -1
- package/src/runtime/plugin.ts +2 -13
- package/src/runtime/runtime.ts +2 -4
- package/src/runtime/server/applications.ts +6 -0
- package/src/runtime/server/config.ts +27 -21
- package/src/runtime/server/jobs.ts +58 -34
- package/src/runtime/subscription/redis.ts +1 -1
- package/src/runtime/types.ts +3 -12
- package/src/runtime/workers/application.ts +76 -160
- package/src/runtime/workers/job.ts +3 -6
- package/src/vite/server.ts +1 -1
- package/dist/runtime/application/api/api.d.ts +0 -55
- package/dist/runtime/application/api/api.js +0 -252
- package/dist/runtime/application/api/api.js.map +0 -1
- package/dist/runtime/application/api/config.d.ts +0 -14
- package/dist/runtime/application/api/config.js +0 -6
- package/dist/runtime/application/api/config.js.map +0 -1
- package/dist/runtime/application/api/constants.d.ts +0 -14
- package/dist/runtime/application/api/constants.js +0 -8
- package/dist/runtime/application/api/constants.js.map +0 -1
- package/dist/runtime/application/api/filters.d.ts +0 -14
- package/dist/runtime/application/api/filters.js +0 -11
- package/dist/runtime/application/api/filters.js.map +0 -1
- package/dist/runtime/application/api/guards.d.ts +0 -15
- package/dist/runtime/application/api/guards.js +0 -8
- package/dist/runtime/application/api/guards.js.map +0 -1
- package/dist/runtime/application/api/index.d.ts +0 -23
- package/dist/runtime/application/api/index.js +0 -17
- package/dist/runtime/application/api/index.js.map +0 -1
- package/dist/runtime/application/api/logging.d.ts +0 -14
- package/dist/runtime/application/api/logging.js +0 -77
- package/dist/runtime/application/api/logging.js.map +0 -1
- package/dist/runtime/application/api/meta.d.ts +0 -21
- package/dist/runtime/application/api/meta.js +0 -2
- package/dist/runtime/application/api/meta.js.map +0 -1
- package/dist/runtime/application/api/middlewares.d.ts +0 -14
- package/dist/runtime/application/api/middlewares.js +0 -12
- package/dist/runtime/application/api/middlewares.js.map +0 -1
- package/dist/runtime/application/api/procedure.d.ts +0 -71
- package/dist/runtime/application/api/procedure.js +0 -41
- package/dist/runtime/application/api/procedure.js.map +0 -1
- package/dist/runtime/application/api/router.d.ts +0 -93
- package/dist/runtime/application/api/router.js +0 -55
- package/dist/runtime/application/api/router.js.map +0 -1
- package/dist/runtime/application/api/types.d.ts +0 -38
- package/dist/runtime/application/api/types.js +0 -2
- package/dist/runtime/application/api/types.js.map +0 -1
- package/dist/runtime/application/config.d.ts +0 -28
- package/dist/runtime/application/config.js +0 -25
- package/dist/runtime/application/config.js.map +0 -1
- package/dist/runtime/application/constants.d.ts +0 -2
- package/dist/runtime/application/constants.js +0 -2
- package/dist/runtime/application/constants.js.map +0 -1
- package/dist/runtime/application/hook.d.ts +0 -19
- package/dist/runtime/application/hook.js +0 -11
- package/dist/runtime/application/hook.js.map +0 -1
- package/dist/runtime/application/hooks.d.ts +0 -3
- package/dist/runtime/application/hooks.js +0 -4
- package/dist/runtime/application/hooks.js.map +0 -1
- package/src/runtime/application/api/api.ts +0 -406
- package/src/runtime/application/api/config.ts +0 -18
- package/src/runtime/application/api/constants.ts +0 -22
- package/src/runtime/application/api/filters.ts +0 -39
- package/src/runtime/application/api/guards.ts +0 -33
- package/src/runtime/application/api/index.ts +0 -69
- package/src/runtime/application/api/logging.ts +0 -110
- package/src/runtime/application/api/meta.ts +0 -37
- package/src/runtime/application/api/middlewares.ts +0 -37
- package/src/runtime/application/api/procedure.ts +0 -224
- package/src/runtime/application/api/router.ts +0 -247
- package/src/runtime/application/api/types.ts +0 -138
- package/src/runtime/application/config.ts +0 -82
- package/src/runtime/application/constants.ts +0 -4
- package/src/runtime/application/hook.ts +0 -51
- package/src/runtime/application/hooks.ts +0 -3
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import type { Callback } from '@nmtjs/common'
|
|
2
|
-
import type {
|
|
3
|
-
TAnyProcedureContract,
|
|
4
|
-
TAnyRouterContract,
|
|
5
|
-
TProcedureContract,
|
|
6
|
-
TRouteContract,
|
|
7
|
-
TRouterContract,
|
|
8
|
-
} from '@nmtjs/contract'
|
|
9
|
-
import type { BaseTypeAny, t } from '@nmtjs/type'
|
|
10
|
-
import type { AnyType } from '@nmtjs/type/any'
|
|
11
|
-
import { c, IsRouterContract } from '@nmtjs/contract'
|
|
12
|
-
import { assertUniqueMetaBindings } from '@nmtjs/core'
|
|
13
|
-
|
|
14
|
-
import type { AnyGuard } from './guards.ts'
|
|
15
|
-
import type { AnyCompatibleMetaBinding, CompatibleMetaBinding } from './meta.ts'
|
|
16
|
-
import type { AnyMiddleware } from './middlewares.ts'
|
|
17
|
-
import type { AnyProcedure } from './procedure.ts'
|
|
18
|
-
import { kRootRouter, kRouter } from './constants.ts'
|
|
19
|
-
|
|
20
|
-
export type RouterMetaBinding<Input> = CompatibleMetaBinding<Input>
|
|
21
|
-
export type AnyRouterMetaBinding = AnyCompatibleMetaBinding
|
|
22
|
-
|
|
23
|
-
export type AnyRouterRoutes = Record<string, AnyProcedure<any> | AnyRouter>
|
|
24
|
-
export type AnyRouterContractRoutes = Record<
|
|
25
|
-
string,
|
|
26
|
-
TAnyProcedureContract | TAnyRouterContract
|
|
27
|
-
>
|
|
28
|
-
|
|
29
|
-
export interface AnyRouter {
|
|
30
|
-
contract: TAnyRouterContract
|
|
31
|
-
routes: AnyRouterRoutes
|
|
32
|
-
guards: Set<AnyGuard>
|
|
33
|
-
middlewares: Set<AnyMiddleware>
|
|
34
|
-
meta: readonly AnyRouterMetaBinding[]
|
|
35
|
-
timeout?: number
|
|
36
|
-
[kRouter]: any
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface AnyRootRouter extends AnyRouter {
|
|
40
|
-
[kRootRouter]: any
|
|
41
|
-
contract: TAnyRouterContract<Record<string, TRouteContract>, undefined>
|
|
42
|
-
default?: AnyProcedure<any>
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface Router<Contract extends TAnyRouterContract> extends AnyRouter {
|
|
46
|
-
contract: Contract
|
|
47
|
-
routes: {
|
|
48
|
-
[K in keyof Contract['routes']]: Contract['routes'][K] extends TAnyRouterContract
|
|
49
|
-
? Router<Contract['routes'][K]>
|
|
50
|
-
: Contract['routes'][K] extends TAnyProcedureContract
|
|
51
|
-
? AnyProcedure<
|
|
52
|
-
TProcedureContract<
|
|
53
|
-
Contract['routes'][K]['input'],
|
|
54
|
-
Contract['routes'][K]['output'],
|
|
55
|
-
Contract['routes'][K]['stream'],
|
|
56
|
-
Contract['routes'][K]['name']
|
|
57
|
-
>
|
|
58
|
-
>
|
|
59
|
-
: never
|
|
60
|
-
}
|
|
61
|
-
guards: Set<AnyGuard>
|
|
62
|
-
middlewares: Set<AnyMiddleware>
|
|
63
|
-
meta: readonly AnyRouterMetaBinding[]
|
|
64
|
-
timeout?: number
|
|
65
|
-
[kRouter]: any
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface RootRouter<
|
|
69
|
-
Contract extends TAnyRouterContract<
|
|
70
|
-
Record<string, TRouteContract>,
|
|
71
|
-
undefined
|
|
72
|
-
>,
|
|
73
|
-
> extends Router<Contract> {
|
|
74
|
-
[kRootRouter]: any
|
|
75
|
-
default?: AnyProcedure<any>
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export type MergeRoutersRoutesContracts<
|
|
79
|
-
Routers extends readonly TAnyRouterContract[],
|
|
80
|
-
> = Routers extends [
|
|
81
|
-
infer First extends TAnyRouterContract,
|
|
82
|
-
...infer Rest extends TAnyRouterContract[],
|
|
83
|
-
]
|
|
84
|
-
? {
|
|
85
|
-
[K in keyof First['routes']]: First['routes'][K]
|
|
86
|
-
} & MergeRoutersRoutesContracts<Rest>
|
|
87
|
-
: Routers extends [infer First extends TAnyRouterContract]
|
|
88
|
-
? {
|
|
89
|
-
[K in keyof First['routes']]: First['routes'][K]
|
|
90
|
-
}
|
|
91
|
-
: {}
|
|
92
|
-
|
|
93
|
-
export type ExtractRouterContracts<
|
|
94
|
-
Routers extends readonly { contract: TAnyRouterContract }[],
|
|
95
|
-
> = Routers extends [
|
|
96
|
-
infer First extends { contract: TAnyRouterContract },
|
|
97
|
-
...infer Rest extends { contract: TAnyRouterContract }[],
|
|
98
|
-
]
|
|
99
|
-
? [First['contract'], ...ExtractRouterContracts<Rest>]
|
|
100
|
-
: []
|
|
101
|
-
|
|
102
|
-
export type RouterContractsFromRoutes<Routes extends AnyRouterRoutes> = {
|
|
103
|
-
[K in keyof Routes]: Routes[K] extends AnyRouter
|
|
104
|
-
? Routes[K]['contract']
|
|
105
|
-
: Routes[K] extends AnyProcedure<any>
|
|
106
|
-
? Routes[K]['contract']
|
|
107
|
-
: never
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export type RouterContractFromRoutes<
|
|
111
|
-
Routes extends AnyRouterRoutes,
|
|
112
|
-
Name extends string | undefined = undefined,
|
|
113
|
-
> = TRouterContract<RouterContractsFromRoutes<Routes>, Name>
|
|
114
|
-
|
|
115
|
-
export function createRootRouter<Routers extends readonly AnyRouter[]>(
|
|
116
|
-
routers: Routers,
|
|
117
|
-
defaultProcedure?: AnyProcedure<
|
|
118
|
-
TProcedureContract<AnyType, AnyType, true | undefined, string | undefined>
|
|
119
|
-
>,
|
|
120
|
-
): RootRouter<
|
|
121
|
-
TRouterContract<
|
|
122
|
-
MergeRoutersRoutesContracts<ExtractRouterContracts<[...Routers]>>,
|
|
123
|
-
undefined
|
|
124
|
-
>
|
|
125
|
-
> {
|
|
126
|
-
const routes: Record<string, any> = {}
|
|
127
|
-
for (const router of routers) Object.assign(routes, router.routes)
|
|
128
|
-
const router = createRouter({ routes, name: undefined })
|
|
129
|
-
return Object.freeze({
|
|
130
|
-
...router,
|
|
131
|
-
default: defaultProcedure,
|
|
132
|
-
[kRootRouter]: true,
|
|
133
|
-
}) as any
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export type FlattenRouterContractInput<Routes extends AnyRouterContractRoutes> =
|
|
137
|
-
{
|
|
138
|
-
[K in keyof Routes]: Routes[K] extends TAnyRouterContract
|
|
139
|
-
? FlattenRouterContractInput<Routes[K]['routes']>
|
|
140
|
-
: Routes[K] extends TAnyProcedureContract
|
|
141
|
-
? Routes[K]['input']
|
|
142
|
-
: never
|
|
143
|
-
}[keyof Routes]
|
|
144
|
-
|
|
145
|
-
export type FlattenRouterDecodedInput<Routes extends AnyRouterContractRoutes> =
|
|
146
|
-
t.infer.decode.output<
|
|
147
|
-
Extract<FlattenRouterContractInput<Routes>, BaseTypeAny>
|
|
148
|
-
>
|
|
149
|
-
|
|
150
|
-
export type RouterDecodedInput<Routes extends AnyRouterRoutes> =
|
|
151
|
-
FlattenRouterDecodedInput<RouterContractsFromRoutes<Routes>>
|
|
152
|
-
|
|
153
|
-
export type RouterContractDecodedInput<Contract extends TAnyRouterContract> =
|
|
154
|
-
FlattenRouterDecodedInput<Contract['routes']>
|
|
155
|
-
|
|
156
|
-
export interface CreateRouterParams<
|
|
157
|
-
Routes extends AnyRouterRoutes,
|
|
158
|
-
Name extends string | undefined = undefined,
|
|
159
|
-
> {
|
|
160
|
-
routes: Routes
|
|
161
|
-
name?: Name
|
|
162
|
-
guards?: AnyGuard[]
|
|
163
|
-
middlewares?: AnyMiddleware[]
|
|
164
|
-
meta?: RouterMetaBinding<RouterDecodedInput<Routes>>[]
|
|
165
|
-
hooks?: Record<string, Callback[]>
|
|
166
|
-
timeout?: number
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export interface CreateContractRouterParams<
|
|
170
|
-
Contract extends TAnyRouterContract,
|
|
171
|
-
> {
|
|
172
|
-
routes: {
|
|
173
|
-
[K in keyof Contract['routes']]: Contract['routes'][K] extends TAnyRouterContract
|
|
174
|
-
? Router<Contract['routes'][K]>
|
|
175
|
-
: Contract['routes'][K] extends TAnyProcedureContract
|
|
176
|
-
? AnyProcedure<Contract['routes'][K]>
|
|
177
|
-
: never
|
|
178
|
-
}
|
|
179
|
-
guards?: AnyGuard[]
|
|
180
|
-
middlewares?: AnyMiddleware[]
|
|
181
|
-
meta?: RouterMetaBinding<RouterContractDecodedInput<Contract>>[]
|
|
182
|
-
timeout?: number
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function createRouter<
|
|
186
|
-
const Routes extends AnyRouterRoutes,
|
|
187
|
-
const Name extends string | undefined = undefined,
|
|
188
|
-
>(
|
|
189
|
-
params: CreateRouterParams<Routes, Name>,
|
|
190
|
-
): Router<RouterContractFromRoutes<Routes, Name>> {
|
|
191
|
-
const { routes, name, guards, middlewares, meta, timeout } = params
|
|
192
|
-
|
|
193
|
-
const routesContracts: any = {}
|
|
194
|
-
for (const [name, route] of Object.entries(routes)) {
|
|
195
|
-
routesContracts[name] = route.contract
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const contract = c.router({ routes: routesContracts, timeout, name })
|
|
199
|
-
|
|
200
|
-
assignRouteContracts(routes, contract)
|
|
201
|
-
|
|
202
|
-
return createContractRouter(contract, {
|
|
203
|
-
routes: routes as any,
|
|
204
|
-
guards,
|
|
205
|
-
middlewares,
|
|
206
|
-
meta,
|
|
207
|
-
timeout,
|
|
208
|
-
}) as any
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export function createContractRouter<Contract extends TAnyRouterContract>(
|
|
212
|
-
contract: Contract,
|
|
213
|
-
params: CreateContractRouterParams<Contract>,
|
|
214
|
-
): Router<Contract> {
|
|
215
|
-
const guards = new Set(params.guards ?? [])
|
|
216
|
-
const middlewares = new Set(params.middlewares ?? [])
|
|
217
|
-
const meta = Object.freeze([...(params.meta ?? [])])
|
|
218
|
-
|
|
219
|
-
assertUniqueMetaBindings(meta, 'router config')
|
|
220
|
-
|
|
221
|
-
return {
|
|
222
|
-
contract,
|
|
223
|
-
routes: params.routes,
|
|
224
|
-
guards,
|
|
225
|
-
middlewares,
|
|
226
|
-
meta,
|
|
227
|
-
timeout: params.timeout,
|
|
228
|
-
[kRouter]: true,
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export const isRouter = (value: any): value is AnyRouter =>
|
|
233
|
-
Boolean(value?.[kRouter])
|
|
234
|
-
|
|
235
|
-
export const isRootRouter = (value: any): value is AnyRootRouter =>
|
|
236
|
-
Boolean(value?.[kRootRouter])
|
|
237
|
-
|
|
238
|
-
function assignRouteContracts(
|
|
239
|
-
routes: Record<string, any>,
|
|
240
|
-
contract: TAnyRouterContract,
|
|
241
|
-
) {
|
|
242
|
-
for (const [key, routeContract] of Object.entries(contract.routes)) {
|
|
243
|
-
routes[key] = { ...routes[key], contract: routeContract }
|
|
244
|
-
if (IsRouterContract(routeContract))
|
|
245
|
-
assignRouteContracts(routes[key].routes, routeContract)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { TProcedureContract } from '@nmtjs/contract'
|
|
2
|
-
import type { Container } from '@nmtjs/core'
|
|
3
|
-
import type { GatewayConnection } from '@nmtjs/gateway'
|
|
4
|
-
import type { AnyCompatibleType, BaseTypeAny } from '@nmtjs/type'
|
|
5
|
-
|
|
6
|
-
import type { Procedure } from './procedure.ts'
|
|
7
|
-
import type { AnyRouter } from './router.ts'
|
|
8
|
-
|
|
9
|
-
export type ApiCallContext<Payload = unknown> = Readonly<{
|
|
10
|
-
callId: string
|
|
11
|
-
connection: GatewayConnection
|
|
12
|
-
container: Container
|
|
13
|
-
path: AnyRouter[]
|
|
14
|
-
procedure: Procedure<
|
|
15
|
-
TProcedureContract<
|
|
16
|
-
AnyCompatibleType<any, Payload>,
|
|
17
|
-
BaseTypeAny,
|
|
18
|
-
true | undefined,
|
|
19
|
-
string | undefined
|
|
20
|
-
>,
|
|
21
|
-
any
|
|
22
|
-
>
|
|
23
|
-
}>
|
|
24
|
-
|
|
25
|
-
export type ApiGuardContext<Payload = unknown> = ApiCallContext<Payload> &
|
|
26
|
-
Readonly<{ payload: Payload }>
|
|
27
|
-
|
|
28
|
-
export type JsonPrimitive<T> =
|
|
29
|
-
Equal<T, JsonPrimitiveMain<T>> extends true ? T : JsonPrimitiveMain<T>
|
|
30
|
-
|
|
31
|
-
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false
|
|
32
|
-
|
|
33
|
-
type JsonPrimitiveMain<
|
|
34
|
-
Instance,
|
|
35
|
-
InArray extends boolean = false,
|
|
36
|
-
> = Instance extends [never]
|
|
37
|
-
? never
|
|
38
|
-
: ValueOf<Instance> extends bigint
|
|
39
|
-
? never
|
|
40
|
-
: ValueOf<Instance> extends boolean | number | string
|
|
41
|
-
? ValueOf<Instance>
|
|
42
|
-
: Instance extends Function
|
|
43
|
-
? InArray extends true
|
|
44
|
-
? null
|
|
45
|
-
: never
|
|
46
|
-
: ValueOf<Instance> extends object
|
|
47
|
-
? Instance extends object
|
|
48
|
-
? Instance extends NativeClass
|
|
49
|
-
? {}
|
|
50
|
-
: Instance extends IJsonable<infer Raw>
|
|
51
|
-
? ValueOf<Raw> extends object
|
|
52
|
-
? Raw extends object
|
|
53
|
-
? PrimitiveObject<Raw>
|
|
54
|
-
: never
|
|
55
|
-
: ValueOf<Raw>
|
|
56
|
-
: PrimitiveObject<Instance>
|
|
57
|
-
: never
|
|
58
|
-
: ValueOf<Instance>
|
|
59
|
-
|
|
60
|
-
type PrimitiveObject<Instance extends object> =
|
|
61
|
-
Instance extends Array<infer T>
|
|
62
|
-
? IsTuple<Instance> extends true
|
|
63
|
-
? PrimitiveTuple<Instance>
|
|
64
|
-
: JsonPrimitiveMain<T, true>[]
|
|
65
|
-
: {
|
|
66
|
-
-readonly [P in keyof Instance as JsonPrimitiveMain<
|
|
67
|
-
Instance[P]
|
|
68
|
-
> extends never
|
|
69
|
-
? never
|
|
70
|
-
: P]: JsonPrimitiveMain<Instance[P]>
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
type PrimitiveTuple<T extends readonly any[]> = T extends []
|
|
74
|
-
? []
|
|
75
|
-
: T extends [infer F]
|
|
76
|
-
? [JsonPrimitiveMain<F, true>]
|
|
77
|
-
: T extends [infer F, ...infer Rest extends readonly any[]]
|
|
78
|
-
? [JsonPrimitiveMain<F, true>, ...PrimitiveTuple<Rest>]
|
|
79
|
-
: T extends [(infer F)?]
|
|
80
|
-
? [JsonPrimitiveMain<F, true>?]
|
|
81
|
-
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
|
|
82
|
-
? [JsonPrimitiveMain<F, true>?, ...PrimitiveTuple<Rest>]
|
|
83
|
-
: []
|
|
84
|
-
|
|
85
|
-
type ValueOf<Instance> =
|
|
86
|
-
IsValueOf<Instance, boolean> extends true
|
|
87
|
-
? boolean
|
|
88
|
-
: IsValueOf<Instance, number> extends true
|
|
89
|
-
? number
|
|
90
|
-
: IsValueOf<Instance, string> extends true
|
|
91
|
-
? string
|
|
92
|
-
: Instance
|
|
93
|
-
|
|
94
|
-
type NativeClass =
|
|
95
|
-
| Set<any>
|
|
96
|
-
| Map<any, any>
|
|
97
|
-
| WeakSet<any>
|
|
98
|
-
| WeakMap<any, any>
|
|
99
|
-
| Uint8Array
|
|
100
|
-
| Uint8ClampedArray
|
|
101
|
-
| Uint16Array
|
|
102
|
-
| Uint32Array
|
|
103
|
-
| BigUint64Array
|
|
104
|
-
| Int8Array
|
|
105
|
-
| Int16Array
|
|
106
|
-
| Int32Array
|
|
107
|
-
| BigInt64Array
|
|
108
|
-
| Float32Array
|
|
109
|
-
| Float64Array
|
|
110
|
-
| ArrayBuffer
|
|
111
|
-
| SharedArrayBuffer
|
|
112
|
-
| DataView
|
|
113
|
-
|
|
114
|
-
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
115
|
-
never,
|
|
116
|
-
]
|
|
117
|
-
? false
|
|
118
|
-
: T extends readonly any[]
|
|
119
|
-
? number extends T['length']
|
|
120
|
-
? false
|
|
121
|
-
: true
|
|
122
|
-
: false
|
|
123
|
-
|
|
124
|
-
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
|
|
125
|
-
? Object extends IValueOf<infer U>
|
|
126
|
-
? Instance extends U
|
|
127
|
-
? false
|
|
128
|
-
: true
|
|
129
|
-
: false
|
|
130
|
-
: false
|
|
131
|
-
|
|
132
|
-
interface IValueOf<T> {
|
|
133
|
-
valueOf(): T
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
interface IJsonable<T> {
|
|
137
|
-
toJSON(): T
|
|
138
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ConnectionIdentity,
|
|
3
|
-
GatewayOptions,
|
|
4
|
-
Transport,
|
|
5
|
-
} from '@nmtjs/gateway'
|
|
6
|
-
import { assertUniqueMetaBindings } from '@nmtjs/core'
|
|
7
|
-
|
|
8
|
-
import type { LifecycleHooks } from '../hooks.ts'
|
|
9
|
-
import type { RuntimePlugin } from '../plugin.ts'
|
|
10
|
-
import type { ApiOptions } from './api/api.ts'
|
|
11
|
-
import type { AnyFilter } from './api/filters.ts'
|
|
12
|
-
import type { AnyGuard } from './api/guards.ts'
|
|
13
|
-
import type { AnyMiddleware } from './api/middlewares.ts'
|
|
14
|
-
import type { AnyRootRouter, AnyRouterMetaBinding } from './api/router.ts'
|
|
15
|
-
import type { AnyHook } from './hook.ts'
|
|
16
|
-
import { kApplicationConfig } from './constants.ts'
|
|
17
|
-
|
|
18
|
-
export type AnyApplicationConfig = ApplicationConfig<AnyRootRouter>
|
|
19
|
-
|
|
20
|
-
export interface ApplicationConfig<
|
|
21
|
-
Router extends AnyRootRouter = AnyRootRouter,
|
|
22
|
-
Transports extends Record<string, Transport> = Record<string, Transport>,
|
|
23
|
-
> {
|
|
24
|
-
[kApplicationConfig]: any
|
|
25
|
-
router: Router
|
|
26
|
-
api: Pick<ApiOptions, 'timeout'>
|
|
27
|
-
gateway: Pick<GatewayOptions, 'streamTimeouts' | 'heartbeat'>
|
|
28
|
-
transports: Transports
|
|
29
|
-
identity?: ConnectionIdentity
|
|
30
|
-
plugins: RuntimePlugin[]
|
|
31
|
-
filters: AnyFilter[]
|
|
32
|
-
middlewares: AnyMiddleware[]
|
|
33
|
-
guards: AnyGuard[]
|
|
34
|
-
meta: AnyRouterMetaBinding[]
|
|
35
|
-
hooks: AnyHook[]
|
|
36
|
-
lifecycleHooks: LifecycleHooks['_']['config']
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function defineApplication<
|
|
40
|
-
R extends AnyRootRouter,
|
|
41
|
-
T extends Record<string, Transport> = Record<string, Transport>,
|
|
42
|
-
>(
|
|
43
|
-
options: Pick<ApplicationConfig<R, T>, 'router'> &
|
|
44
|
-
Partial<Omit<ApplicationConfig<R, T>, 'router'>>,
|
|
45
|
-
) {
|
|
46
|
-
const {
|
|
47
|
-
router,
|
|
48
|
-
transports = {},
|
|
49
|
-
guards = [],
|
|
50
|
-
middlewares = [],
|
|
51
|
-
meta = [],
|
|
52
|
-
plugins = [],
|
|
53
|
-
api = {} as ApplicationConfig['api'],
|
|
54
|
-
filters = [] as ApplicationConfig['filters'],
|
|
55
|
-
hooks = [] as ApplicationConfig['hooks'],
|
|
56
|
-
lifecycleHooks = {},
|
|
57
|
-
gateway = {},
|
|
58
|
-
identity: identityResolver,
|
|
59
|
-
} = options
|
|
60
|
-
|
|
61
|
-
assertUniqueMetaBindings(meta, 'application config')
|
|
62
|
-
|
|
63
|
-
return Object.freeze({
|
|
64
|
-
[kApplicationConfig]: true,
|
|
65
|
-
router,
|
|
66
|
-
transports,
|
|
67
|
-
api,
|
|
68
|
-
gateway,
|
|
69
|
-
filters,
|
|
70
|
-
plugins,
|
|
71
|
-
guards,
|
|
72
|
-
middlewares,
|
|
73
|
-
meta,
|
|
74
|
-
hooks,
|
|
75
|
-
lifecycleHooks,
|
|
76
|
-
identity: identityResolver,
|
|
77
|
-
} satisfies AnyApplicationConfig) as ApplicationConfig<R, T>
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function isApplicationConfig(value: any): value is ApplicationConfig {
|
|
81
|
-
return Boolean(value?.[kApplicationConfig])
|
|
82
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { MaybePromise } from '@nmtjs/common'
|
|
2
|
-
import type {
|
|
3
|
-
Dependant,
|
|
4
|
-
Dependencies,
|
|
5
|
-
DependencyContext,
|
|
6
|
-
HookTypes,
|
|
7
|
-
} from '@nmtjs/core'
|
|
8
|
-
import { kHook } from '@nmtjs/core'
|
|
9
|
-
|
|
10
|
-
export type AnyHook = Hook<HookTypes, string, any>
|
|
11
|
-
|
|
12
|
-
export interface Hook<
|
|
13
|
-
T extends HookTypes = HookTypes,
|
|
14
|
-
H extends string = string,
|
|
15
|
-
Deps extends Dependencies = {},
|
|
16
|
-
> extends Dependant<Deps> {
|
|
17
|
-
[kHook]: any
|
|
18
|
-
name: H
|
|
19
|
-
handler: (
|
|
20
|
-
ctx: DependencyContext<Deps>,
|
|
21
|
-
...args: H extends keyof T ? Parameters<T[H]> : unknown[]
|
|
22
|
-
) => MaybePromise<any>
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function createHook<
|
|
26
|
-
Types extends HookTypes = HookTypes,
|
|
27
|
-
Name extends Extract<keyof Types, string> | (object & string) = object &
|
|
28
|
-
string,
|
|
29
|
-
Deps extends Dependencies = {},
|
|
30
|
-
>(params: {
|
|
31
|
-
name: Name
|
|
32
|
-
dependencies?: Deps
|
|
33
|
-
handler: Hook<Types, Name, Deps>['handler']
|
|
34
|
-
}): Hook<Types, Name, Deps> {
|
|
35
|
-
const { name, handler, dependencies = {} as Deps } = params
|
|
36
|
-
return Object.freeze({ [kHook]: true, name, handler, dependencies }) as any
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function createApplicationHookFactory<Types extends HookTypes>() {
|
|
40
|
-
return <
|
|
41
|
-
Name extends Extract<keyof Types, string> | (object & string) = object &
|
|
42
|
-
string,
|
|
43
|
-
Deps extends Dependencies = {},
|
|
44
|
-
>(params: {
|
|
45
|
-
name: Name
|
|
46
|
-
dependencies?: Deps
|
|
47
|
-
handler: Hook<Types, Name, Deps>['handler']
|
|
48
|
-
}): Hook<Types, Name, Deps> => {
|
|
49
|
-
return createHook<Types, Name, Deps>(params)
|
|
50
|
-
}
|
|
51
|
-
}
|