nmtjs 0.15.3 → 0.16.0-beta.10
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.map +1 -1
- package/dist/codegen.js.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/entrypoints/main.js.map +1 -1
- package/dist/entrypoints/thread.js.map +1 -1
- package/dist/entrypoints/worker.js.map +1 -1
- package/dist/index.d.ts +32 -21
- package/dist/index.js +8 -6
- 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 +3 -20
- 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 +3 -5
- package/dist/runtime/index.js +3 -5
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/injectables.d.ts +10 -10
- package/dist/runtime/injectables.js +6 -6
- package/dist/runtime/injectables.js.map +1 -1
- package/dist/runtime/jobs/job.d.ts +4 -4
- package/dist/runtime/jobs/job.js.map +1 -1
- package/dist/runtime/jobs/manager.js.map +1 -1
- package/dist/runtime/jobs/router.d.ts +31 -13
- package/dist/runtime/jobs/router.js +14 -11
- 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/step.js.map +1 -1
- package/dist/runtime/metrics/server.js +21 -9
- 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/scheduler/index.js.map +1 -1
- package/dist/runtime/server/applications.js.map +1 -1
- package/dist/runtime/server/config.d.ts +8 -19
- package/dist/runtime/server/config.js +2 -3
- package/dist/runtime/server/config.js.map +1 -1
- package/dist/runtime/server/environment.js.map +1 -1
- package/dist/runtime/server/error-policy.js.map +1 -1
- package/dist/runtime/server/hmr-coordinator.js.map +1 -1
- package/dist/runtime/server/jobs.d.ts +7 -11
- package/dist/runtime/server/jobs.js +45 -71
- package/dist/runtime/server/jobs.js.map +1 -1
- package/dist/runtime/server/lifecycle.js.map +1 -1
- package/dist/runtime/server/managed-worker.js.map +1 -1
- package/dist/runtime/server/pool-manager.js.map +1 -1
- package/dist/runtime/server/proxy.js.map +1 -1
- package/dist/runtime/server/server.js.map +1 -1
- package/dist/runtime/server/worker-pool.js.map +1 -1
- package/dist/runtime/store/index.js.map +1 -1
- package/dist/runtime/{pubsub → subscription}/manager.d.ts +15 -14
- package/dist/runtime/{pubsub → subscription}/manager.js +59 -8
- package/dist/runtime/subscription/manager.js.map +1 -0
- package/dist/runtime/subscription/redis.d.ts +18 -0
- package/dist/runtime/{pubsub → subscription}/redis.js +37 -14
- package/dist/runtime/subscription/redis.js.map +1 -0
- package/dist/runtime/types.d.ts +2 -10
- package/dist/runtime/workers/application.d.ts +4 -7
- package/dist/runtime/workers/application.js +9 -4
- package/dist/runtime/workers/application.js.map +1 -1
- package/dist/runtime/workers/base.d.ts +2 -2
- package/dist/runtime/workers/base.js +5 -5
- package/dist/runtime/workers/base.js.map +1 -1
- package/dist/runtime/workers/job.js +2 -1
- package/dist/runtime/workers/job.js.map +1 -1
- package/dist/vite/builder.js.map +1 -1
- package/dist/vite/config.js.map +1 -1
- package/dist/vite/plugins.js.map +1 -1
- package/dist/vite/runners/worker.js.map +1 -1
- package/dist/vite/server.js.map +1 -1
- package/dist/vite/servers/main.js.map +1 -1
- package/dist/vite/servers/worker.js.map +1 -1
- package/package.json +19 -23
- package/src/index.ts +14 -8
- 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 +4 -5
- package/src/runtime/injectables.ts +18 -20
- package/src/runtime/jobs/job.ts +1 -2
- package/src/runtime/jobs/router.ts +52 -24
- package/src/runtime/jobs/runner.ts +2 -2
- package/src/runtime/metrics/server.ts +21 -18
- package/src/runtime/plugin.ts +2 -13
- package/src/runtime/runtime.ts +2 -4
- package/src/runtime/server/config.ts +12 -18
- package/src/runtime/server/jobs.ts +59 -88
- package/src/runtime/{pubsub → subscription}/manager.ts +118 -26
- package/src/runtime/subscription/redis.ts +157 -0
- package/src/runtime/types.ts +2 -11
- package/src/runtime/workers/application.ts +29 -17
- package/src/runtime/workers/base.ts +7 -7
- package/src/runtime/workers/job.ts +3 -6
- package/dist/runtime/application/api/api.d.ts +0 -50
- package/dist/runtime/application/api/api.js +0 -196
- package/dist/runtime/application/api/api.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 -16
- package/dist/runtime/application/api/guards.js +0 -11
- package/dist/runtime/application/api/guards.js.map +0 -1
- package/dist/runtime/application/api/index.d.ts +0 -9
- package/dist/runtime/application/api/index.js +0 -10
- package/dist/runtime/application/api/index.js.map +0 -1
- package/dist/runtime/application/api/logging.d.ts +0 -19
- package/dist/runtime/application/api/logging.js +0 -77
- package/dist/runtime/application/api/logging.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 -67
- package/dist/runtime/application/api/procedure.js +0 -50
- package/dist/runtime/application/api/procedure.js.map +0 -1
- package/dist/runtime/application/api/router.d.ts +0 -80
- package/dist/runtime/application/api/router.js +0 -50
- 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 -26
- package/dist/runtime/application/config.js +0 -21
- 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/dist/runtime/jobs/ui.d.ts +0 -3
- package/dist/runtime/jobs/ui.js +0 -20
- package/dist/runtime/jobs/ui.js.map +0 -1
- package/dist/runtime/pubsub/manager.js.map +0 -1
- package/dist/runtime/pubsub/redis.d.ts +0 -16
- package/dist/runtime/pubsub/redis.js.map +0 -1
- package/src/runtime/application/api/api.ts +0 -274
- 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 -42
- package/src/runtime/application/api/index.ts +0 -9
- package/src/runtime/application/api/logging.ts +0 -110
- package/src/runtime/application/api/middlewares.ts +0 -37
- package/src/runtime/application/api/procedure.ts +0 -231
- package/src/runtime/application/api/router.ts +0 -220
- package/src/runtime/application/api/types.ts +0 -138
- package/src/runtime/application/config.ts +0 -69
- package/src/runtime/application/constants.ts +0 -4
- package/src/runtime/application/hook.ts +0 -51
- package/src/runtime/application/hooks.ts +0 -3
- package/src/runtime/jobs/ui.ts +0 -27
- package/src/runtime/pubsub/redis.ts +0 -106
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import EventEmitter, { on } from 'node:events'
|
|
2
|
+
|
|
3
|
+
import type { RuntimePlugin } from '@nmtjs/application'
|
|
4
|
+
import type { Logger } from '@nmtjs/core'
|
|
5
|
+
import { isAbortError } from '@nmtjs/common'
|
|
6
|
+
import { createFactoryInjectable } from '@nmtjs/core'
|
|
7
|
+
|
|
8
|
+
import type { Store } from '../types.ts'
|
|
9
|
+
import type {
|
|
10
|
+
SubscriptionAdapterEvent,
|
|
11
|
+
SubscriptionAdapterType,
|
|
12
|
+
} from './manager.ts'
|
|
13
|
+
import { storeConfig, subscriptionAdapter } from '../injectables.ts'
|
|
14
|
+
import { createStoreClient } from '../store/index.ts'
|
|
15
|
+
|
|
16
|
+
export class RedisSubscriptionAdapter implements SubscriptionAdapterType {
|
|
17
|
+
protected readonly events = new EventEmitter()
|
|
18
|
+
protected readonly listeners = new Map<string, number>()
|
|
19
|
+
protected readonly logger?: Logger
|
|
20
|
+
protected subscriberClient?: Store
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
protected readonly client: Store,
|
|
24
|
+
logger?: Logger,
|
|
25
|
+
) {
|
|
26
|
+
this.logger = logger?.child({ component: RedisSubscriptionAdapter.name })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async initialize() {
|
|
30
|
+
this.logger?.debug('Initializing Redis adapter')
|
|
31
|
+
|
|
32
|
+
// Create a dedicated subscriber client (Redis requires separate clients for pub/sub)
|
|
33
|
+
this.subscriberClient = this.client.duplicate()
|
|
34
|
+
|
|
35
|
+
// Set up message handler
|
|
36
|
+
this.subscriberClient.on('message', (channel: string, message: string) => {
|
|
37
|
+
try {
|
|
38
|
+
const parsed = JSON.parse(message)
|
|
39
|
+
this.logger?.trace({ channel }, 'Received Redis message')
|
|
40
|
+
this.events.emit(channel, parsed)
|
|
41
|
+
} catch (error) {
|
|
42
|
+
this.logger?.warn({ channel, error }, 'Failed to parse Redis message')
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
this.logger?.debug('Redis adapter initialized')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async dispose() {
|
|
50
|
+
this.logger?.debug('Disposing Redis adapter')
|
|
51
|
+
|
|
52
|
+
if (this.subscriberClient) {
|
|
53
|
+
await this.subscriberClient.quit()
|
|
54
|
+
this.subscriberClient = undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.logger?.debug('Redis adapter disposed')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async publish(channel: string, payload: any): Promise<boolean> {
|
|
61
|
+
this.logger?.trace({ channel }, 'Publishing Redis message')
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
await this.client.publish(channel, JSON.stringify(payload))
|
|
65
|
+
this.logger?.trace({ channel }, 'Published Redis message')
|
|
66
|
+
return true
|
|
67
|
+
} catch (error) {
|
|
68
|
+
this.logger?.warn({ channel, error }, 'Failed to publish Redis message')
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async *subscribe(
|
|
74
|
+
channel: string,
|
|
75
|
+
signal?: AbortSignal,
|
|
76
|
+
): AsyncGenerator<SubscriptionAdapterEvent> {
|
|
77
|
+
if (!this.subscriberClient) {
|
|
78
|
+
throw new Error('RedisSubscriptionAdapter not initialized')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.logger?.debug({ channel }, 'Opening Redis channel listener')
|
|
82
|
+
|
|
83
|
+
if (!this.listeners.has(channel)) {
|
|
84
|
+
await this.subscriberClient.subscribe(channel)
|
|
85
|
+
this.listeners.set(channel, 1)
|
|
86
|
+
this.logger?.debug({ channel, listeners: 1 }, 'Subscribed Redis channel')
|
|
87
|
+
} else {
|
|
88
|
+
const listeners = this.listeners.get(channel)! + 1
|
|
89
|
+
this.listeners.set(channel, listeners)
|
|
90
|
+
this.logger?.trace(
|
|
91
|
+
{ channel, listeners },
|
|
92
|
+
'Reusing Redis channel listener',
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
signal?.throwIfAborted()
|
|
98
|
+
for await (const [payload] of on(this.events, channel, { signal })) {
|
|
99
|
+
this.logger?.trace({ channel }, 'Delivering Redis message')
|
|
100
|
+
yield { channel, payload }
|
|
101
|
+
}
|
|
102
|
+
} catch (error: any) {
|
|
103
|
+
if (isAbortError(error)) {
|
|
104
|
+
this.logger?.trace({ channel }, 'Redis channel listener aborted')
|
|
105
|
+
throw error
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.logger?.warn({ channel, error }, 'Redis channel listener failed')
|
|
109
|
+
} finally {
|
|
110
|
+
const count = this.listeners.get(channel)
|
|
111
|
+
if (count !== undefined) {
|
|
112
|
+
if (count > 1) {
|
|
113
|
+
const listeners = count - 1
|
|
114
|
+
this.listeners.set(channel, listeners)
|
|
115
|
+
this.logger?.trace(
|
|
116
|
+
{ channel, listeners },
|
|
117
|
+
'Detached Redis channel listener',
|
|
118
|
+
)
|
|
119
|
+
} else {
|
|
120
|
+
await this.subscriberClient?.unsubscribe(channel)
|
|
121
|
+
this.listeners.delete(channel)
|
|
122
|
+
this.logger?.debug(
|
|
123
|
+
{ channel, listeners: 0 },
|
|
124
|
+
'Unsubscribed Redis channel',
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const RedisSubscriptionAdapterPlugin = (): RuntimePlugin => {
|
|
133
|
+
return {
|
|
134
|
+
name: 'redis-subscription-adapter',
|
|
135
|
+
hooks: {
|
|
136
|
+
'lifecycle:beforeInitialize': async (ctx) => {
|
|
137
|
+
const adapter = await ctx.container.resolve(
|
|
138
|
+
createFactoryInjectable({
|
|
139
|
+
dependencies: { config: storeConfig },
|
|
140
|
+
factory: async ({ config }) => {
|
|
141
|
+
const connection = await createStoreClient(config)
|
|
142
|
+
const adapter = new RedisSubscriptionAdapter(
|
|
143
|
+
connection,
|
|
144
|
+
ctx.logger,
|
|
145
|
+
)
|
|
146
|
+
await adapter.initialize()
|
|
147
|
+
return { adapter, connection }
|
|
148
|
+
},
|
|
149
|
+
pick: ({ adapter }) => adapter,
|
|
150
|
+
dispose: ({ connection }) => connection.quit(),
|
|
151
|
+
}),
|
|
152
|
+
)
|
|
153
|
+
ctx.container.provide(subscriptionAdapter, adapter)
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
}
|
package/src/runtime/types.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApplicationConfig } from '@nmtjs/application'
|
|
2
2
|
import type { ProxyableTransportType } from '@nmtjs/gateway'
|
|
3
3
|
import type { Redis, RedisOptions } from 'ioredis'
|
|
4
4
|
import type { Redis as Valkey, RedisOptions as ValkeyOptions } from 'iovalkey'
|
|
5
5
|
|
|
6
|
-
import type {
|
|
7
|
-
import type { LifecycleHook, StoreType } from './enums.ts'
|
|
8
|
-
import type { BaseRuntime } from './runtime.ts'
|
|
6
|
+
import type { StoreType } from './enums.ts'
|
|
9
7
|
|
|
10
8
|
export type WorkerThreadErrorOrigin = 'bootstrap' | 'start' | 'runtime'
|
|
11
9
|
|
|
@@ -66,13 +64,6 @@ export type JobTaskResultTypes = {
|
|
|
66
64
|
queue_job_not_found: {}
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
export interface LifecycleHookTypes extends HookTypes {
|
|
70
|
-
[LifecycleHook.BeforeInitialize]: (runtime: BaseRuntime) => any
|
|
71
|
-
[LifecycleHook.AfterInitialize]: (runtime: BaseRuntime) => any
|
|
72
|
-
[LifecycleHook.BeforeDispose]: (runtime: BaseRuntime) => any
|
|
73
|
-
[LifecycleHook.AfterDispose]: (runtime: BaseRuntime) => any
|
|
74
|
-
}
|
|
75
|
-
|
|
76
67
|
export type ApplicationDefinitionType =
|
|
77
68
|
| { type: 'neemata'; definition: ApplicationConfig<any, any> }
|
|
78
69
|
| { type: 'custom'; definition: any }
|
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import type { Dependant } from '@nmtjs/core'
|
|
2
|
-
import type { GatewayOptions, Transport } from '@nmtjs/gateway'
|
|
3
|
-
import { Gateway } from '@nmtjs/gateway'
|
|
4
|
-
import { JsonFormat } from '@nmtjs/json-format/server'
|
|
5
|
-
import { MsgpackFormat } from '@nmtjs/msgpack-format/server'
|
|
6
|
-
import { ProtocolFormats } from '@nmtjs/protocol/server'
|
|
7
|
-
|
|
8
|
-
import type { ApplicationConfig } from '../application/config.ts'
|
|
9
1
|
import type {
|
|
10
2
|
AnyFilter,
|
|
11
3
|
AnyGuard,
|
|
12
4
|
AnyMiddleware,
|
|
13
5
|
AnyProcedure,
|
|
14
6
|
AnyRouter,
|
|
7
|
+
ApplicationConfig,
|
|
8
|
+
ApplicationResolvedProcedure,
|
|
9
|
+
ApplicationTransport,
|
|
15
10
|
kDefaultProcedure as kDefaultProcedureKey,
|
|
16
|
-
} from '
|
|
17
|
-
import type {
|
|
18
|
-
import {
|
|
19
|
-
import { ApplicationHooks } from '../application/hooks.ts'
|
|
11
|
+
} from '@nmtjs/application'
|
|
12
|
+
import type { Dependant } from '@nmtjs/core'
|
|
13
|
+
import type { GatewayOptions } from '@nmtjs/gateway'
|
|
20
14
|
import {
|
|
15
|
+
ApplicationApi,
|
|
16
|
+
ApplicationHooks,
|
|
21
17
|
isProcedure,
|
|
22
18
|
isRootRouter,
|
|
23
19
|
isRouter,
|
|
24
20
|
kDefaultProcedure,
|
|
25
21
|
kRootRouter,
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
LifecycleHook,
|
|
23
|
+
} from '@nmtjs/application'
|
|
24
|
+
import { Gateway } from '@nmtjs/gateway'
|
|
25
|
+
import { JsonFormat } from '@nmtjs/json-format/server'
|
|
26
|
+
import { MsgpackFormat } from '@nmtjs/msgpack-format/server'
|
|
27
|
+
import { ProtocolFormats } from '@nmtjs/protocol/server'
|
|
28
|
+
|
|
29
|
+
import type { ServerConfig } from '../server/config.ts'
|
|
30
|
+
import { WorkerType } from '../enums.ts'
|
|
28
31
|
import { BaseWorkerRuntime } from './base.ts'
|
|
29
32
|
|
|
30
33
|
export interface ApplicationWorkerRuntimeOptions {
|
|
@@ -36,8 +39,8 @@ export interface ApplicationWorkerRuntimeOptions {
|
|
|
36
39
|
export class ApplicationWorkerRuntime extends BaseWorkerRuntime {
|
|
37
40
|
api!: ApplicationApi
|
|
38
41
|
applicationHooks!: ApplicationHooks
|
|
39
|
-
gateway!: Gateway
|
|
40
|
-
transports!: GatewayOptions['transports']
|
|
42
|
+
gateway!: Gateway<ApplicationResolvedProcedure>
|
|
43
|
+
transports!: GatewayOptions<ApplicationResolvedProcedure>['transports']
|
|
41
44
|
|
|
42
45
|
routers = new Map<string | kRootRouter, AnyRouter>()
|
|
43
46
|
procedures = new Map<
|
|
@@ -69,6 +72,7 @@ export class ApplicationWorkerRuntime extends BaseWorkerRuntime {
|
|
|
69
72
|
timeout: this.appConfig.api.timeout,
|
|
70
73
|
container: this.container,
|
|
71
74
|
logger: this.logger,
|
|
75
|
+
meta: this.appConfig.meta,
|
|
72
76
|
filters: this.filters,
|
|
73
77
|
middlewares: this.middlewares,
|
|
74
78
|
guards: this.guards,
|
|
@@ -83,11 +87,14 @@ export class ApplicationWorkerRuntime extends BaseWorkerRuntime {
|
|
|
83
87
|
|
|
84
88
|
for (const key in this.runtimeOptions.transports) {
|
|
85
89
|
const options = this.runtimeOptions.transports[key]
|
|
86
|
-
const { factory, proxyable } = this.appConfig.transports[
|
|
90
|
+
const { factory, proxyable } = this.appConfig.transports[
|
|
91
|
+
key
|
|
92
|
+
] as ApplicationTransport
|
|
87
93
|
this.transports[key] = { transport: await factory(options), proxyable }
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
this.gateway = new Gateway({
|
|
97
|
+
...this.appConfig.gateway,
|
|
91
98
|
logger: this.logger,
|
|
92
99
|
container: this.container,
|
|
93
100
|
hooks: this.lifecycleHooks,
|
|
@@ -150,9 +157,14 @@ export class ApplicationWorkerRuntime extends BaseWorkerRuntime {
|
|
|
150
157
|
yield* this.appConfig.filters
|
|
151
158
|
yield* this.appConfig.guards
|
|
152
159
|
yield* this.appConfig.middlewares
|
|
160
|
+
yield* this.appConfig.meta
|
|
153
161
|
yield* this.appConfig.hooks
|
|
162
|
+
for (const router of this.routers.values()) {
|
|
163
|
+
yield* router.meta
|
|
164
|
+
}
|
|
154
165
|
for (const { procedure } of this.procedures.values()) {
|
|
155
166
|
yield procedure
|
|
167
|
+
yield* procedure.meta
|
|
156
168
|
yield* procedure.guards
|
|
157
169
|
yield* procedure.middlewares
|
|
158
170
|
}
|
|
@@ -6,11 +6,11 @@ import type { BaseRuntimeOptions } from '../runtime.ts'
|
|
|
6
6
|
import type { ServerConfig } from '../server/config.ts'
|
|
7
7
|
import * as injectables from '../injectables.ts'
|
|
8
8
|
import { JobManager } from '../jobs/manager.ts'
|
|
9
|
-
import { PubSubManager } from '../pubsub/manager.ts'
|
|
10
9
|
import { BaseRuntime } from '../runtime.ts'
|
|
10
|
+
import { SubscriptionManager } from '../subscription/manager.ts'
|
|
11
11
|
|
|
12
12
|
export abstract class BaseWorkerRuntime extends BaseRuntime {
|
|
13
|
-
|
|
13
|
+
subscriptionManager: SubscriptionManager
|
|
14
14
|
jobManager?: JobManager
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
@@ -20,7 +20,7 @@ export abstract class BaseWorkerRuntime extends BaseRuntime {
|
|
|
20
20
|
) {
|
|
21
21
|
super(options)
|
|
22
22
|
|
|
23
|
-
this.
|
|
23
|
+
this.subscriptionManager = new SubscriptionManager({
|
|
24
24
|
logger: this.logger,
|
|
25
25
|
container: this.container,
|
|
26
26
|
})
|
|
@@ -38,12 +38,12 @@ export abstract class BaseWorkerRuntime extends BaseRuntime {
|
|
|
38
38
|
provision(CoreInjectables.logger, this.logger),
|
|
39
39
|
provision(injectables.workerType, this.workerType),
|
|
40
40
|
provision(
|
|
41
|
-
injectables.
|
|
42
|
-
this.
|
|
41
|
+
injectables.publish,
|
|
42
|
+
this.subscriptionManager.publish.bind(this.subscriptionManager),
|
|
43
43
|
),
|
|
44
44
|
provision(
|
|
45
|
-
injectables.
|
|
46
|
-
this.
|
|
45
|
+
injectables.subscribe,
|
|
46
|
+
this.subscriptionManager.subscribe.bind(this.subscriptionManager),
|
|
47
47
|
),
|
|
48
48
|
]
|
|
49
49
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { MessagePort } from 'node:worker_threads'
|
|
2
2
|
|
|
3
|
+
import { LifecycleHook } from '@nmtjs/application'
|
|
3
4
|
import { UnrecoverableError } from 'bullmq'
|
|
4
5
|
|
|
5
|
-
import type { JobWorkerPool } from '../enums.ts'
|
|
6
6
|
import type { JobProgressCheckpoint } from '../jobs/types.ts'
|
|
7
7
|
import type { ServerConfig } from '../server/config.ts'
|
|
8
8
|
import type { ServerPortMessage, ThreadPortMessage } from '../types.ts'
|
|
9
|
-
import {
|
|
9
|
+
import { WorkerType } from '../enums.ts'
|
|
10
10
|
import { jobWorkerPool } from '../injectables.ts'
|
|
11
11
|
import { ApplicationWorkerJobRunner } from '../jobs/runner.ts'
|
|
12
12
|
import { BaseWorkerRuntime } from './base.ts'
|
|
@@ -52,10 +52,7 @@ export class JobWorkerRuntime extends BaseWorkerRuntime {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
this.container.provide(
|
|
56
|
-
jobWorkerPool,
|
|
57
|
-
this.runtimeOptions.poolName as JobWorkerPool,
|
|
58
|
-
)
|
|
55
|
+
this.container.provide(jobWorkerPool, this.runtimeOptions.poolName)
|
|
59
56
|
await super.initialize()
|
|
60
57
|
}
|
|
61
58
|
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { Container, Logger } from '@nmtjs/core';
|
|
2
|
-
import type { GatewayApi, GatewayApiCallOptions, GatewayApiCallResult, GatewayConnection } from '@nmtjs/gateway';
|
|
3
|
-
import { ProtocolError } from '@nmtjs/protocol/server';
|
|
4
|
-
import type { kDefaultProcedure as kDefaultProcedureKey } from './constants.ts';
|
|
5
|
-
import type { AnyFilter } from './filters.ts';
|
|
6
|
-
import type { AnyGuard } from './guards.ts';
|
|
7
|
-
import type { AnyMiddleware } from './middlewares.ts';
|
|
8
|
-
import type { AnyProcedure } from './procedure.ts';
|
|
9
|
-
import type { AnyRouter } from './router.ts';
|
|
10
|
-
export type ApiCallOptions<T extends AnyProcedure = AnyProcedure> = Readonly<{
|
|
11
|
-
callId: string;
|
|
12
|
-
connection: GatewayConnection;
|
|
13
|
-
path: AnyRouter[];
|
|
14
|
-
procedure: T;
|
|
15
|
-
container: Container;
|
|
16
|
-
payload: any;
|
|
17
|
-
signal: AbortSignal;
|
|
18
|
-
}>;
|
|
19
|
-
export type ApiOptions = {
|
|
20
|
-
timeout?: number;
|
|
21
|
-
container: Container;
|
|
22
|
-
logger: Logger;
|
|
23
|
-
procedures: Map<string | kDefaultProcedureKey, {
|
|
24
|
-
procedure: AnyProcedure;
|
|
25
|
-
path: AnyRouter[];
|
|
26
|
-
}>;
|
|
27
|
-
guards: Set<AnyGuard>;
|
|
28
|
-
middlewares: Set<AnyMiddleware>;
|
|
29
|
-
filters: Set<AnyFilter>;
|
|
30
|
-
};
|
|
31
|
-
export declare class ApiError extends ProtocolError {
|
|
32
|
-
toString(): string;
|
|
33
|
-
}
|
|
34
|
-
export declare class ApplicationApi implements GatewayApi {
|
|
35
|
-
options: ApiOptions;
|
|
36
|
-
constructor(options: ApiOptions);
|
|
37
|
-
find(procedureName: string): {
|
|
38
|
-
procedure: AnyProcedure;
|
|
39
|
-
path: AnyRouter[];
|
|
40
|
-
};
|
|
41
|
-
call(options: GatewayApiCallOptions): Promise<GatewayApiCallResult>;
|
|
42
|
-
private createProcedureHandler;
|
|
43
|
-
private resolveMiddlewares;
|
|
44
|
-
private withTimeout;
|
|
45
|
-
private handleGuards;
|
|
46
|
-
private handleFilters;
|
|
47
|
-
private handleInput;
|
|
48
|
-
private handleIterableOutput;
|
|
49
|
-
private handleOutput;
|
|
50
|
-
}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { inspect } from 'node:util';
|
|
4
|
-
import { withTimeout } from '@nmtjs/common';
|
|
5
|
-
import { IsStreamProcedureContract } from '@nmtjs/contract';
|
|
6
|
-
import { Scope } from '@nmtjs/core';
|
|
7
|
-
import { isAsyncIterable, rpcStreamAbortSignal } from '@nmtjs/gateway';
|
|
8
|
-
import { ErrorCode } from '@nmtjs/protocol';
|
|
9
|
-
import { ProtocolError } from '@nmtjs/protocol/server';
|
|
10
|
-
import { NeemataTypeError, registerDefaultLocale, type } from '@nmtjs/type';
|
|
11
|
-
import { prettifyError } from 'zod/mini';
|
|
12
|
-
import { kDefaultProcedure } from './constants.js';
|
|
13
|
-
registerDefaultLocale();
|
|
14
|
-
export class ApiError extends ProtocolError {
|
|
15
|
-
toString() {
|
|
16
|
-
return `${this.code} ${this.message}: \n${inspect(this.data, true, 10, false)}`;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const NotFound = () => new ApiError(ErrorCode.NotFound, 'Procedure not found');
|
|
20
|
-
export class ApplicationApi {
|
|
21
|
-
options;
|
|
22
|
-
constructor(options) {
|
|
23
|
-
this.options = options;
|
|
24
|
-
}
|
|
25
|
-
find(procedureName) {
|
|
26
|
-
const procedure = this.options.procedures.get(procedureName);
|
|
27
|
-
if (procedure)
|
|
28
|
-
return procedure;
|
|
29
|
-
const fallback = this.options.procedures.get(kDefaultProcedure);
|
|
30
|
-
if (fallback)
|
|
31
|
-
return fallback;
|
|
32
|
-
throw NotFound();
|
|
33
|
-
}
|
|
34
|
-
async call(options) {
|
|
35
|
-
const callId = randomUUID();
|
|
36
|
-
const { payload, container, signal, connection } = options;
|
|
37
|
-
const { procedure, path } = this.find(options.procedure);
|
|
38
|
-
options.metadata?.(procedure.metadata);
|
|
39
|
-
const callOptions = Object.freeze({
|
|
40
|
-
callId,
|
|
41
|
-
payload,
|
|
42
|
-
container,
|
|
43
|
-
signal,
|
|
44
|
-
connection,
|
|
45
|
-
procedure,
|
|
46
|
-
path,
|
|
47
|
-
});
|
|
48
|
-
assert(container.scope === Scope.Call, 'Invalid container scope, expected to be Scope.Call');
|
|
49
|
-
const timeout = procedure.contract.timeout ?? this.options.timeout;
|
|
50
|
-
const streamTimeoutSignal = procedure.streamTimeout
|
|
51
|
-
? AbortSignal.timeout(procedure.streamTimeout)
|
|
52
|
-
: undefined;
|
|
53
|
-
if (streamTimeoutSignal) {
|
|
54
|
-
container.provide(rpcStreamAbortSignal, streamTimeoutSignal);
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
const handle = await this.createProcedureHandler(callOptions);
|
|
58
|
-
return timeout
|
|
59
|
-
? await this.withTimeout(handle(payload), timeout)
|
|
60
|
-
: await handle(payload);
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
const handled = await this.handleFilters(callOptions, error);
|
|
64
|
-
if (handled === error && error instanceof ProtocolError === false) {
|
|
65
|
-
const logError = new Error('Unhandled error', { cause: error });
|
|
66
|
-
this.options.logger.error(logError);
|
|
67
|
-
throw new ApiError(ErrorCode.InternalServerError, 'Internal Server Error');
|
|
68
|
-
}
|
|
69
|
-
throw handled;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async createProcedureHandler(callOptions) {
|
|
73
|
-
const { callId, connection, procedure, container, path } = callOptions;
|
|
74
|
-
const callCtx = Object.freeze({
|
|
75
|
-
callId,
|
|
76
|
-
connection,
|
|
77
|
-
container,
|
|
78
|
-
path,
|
|
79
|
-
procedure,
|
|
80
|
-
});
|
|
81
|
-
const isIterableProcedure = IsStreamProcedureContract(procedure.contract);
|
|
82
|
-
const middlewares = this.resolveMiddlewares(callOptions);
|
|
83
|
-
const handleProcedure = async (payload) => {
|
|
84
|
-
const middleware = (await middlewares).next().value;
|
|
85
|
-
if (middleware) {
|
|
86
|
-
const next = (...args) => handleProcedure(args.length === 0 ? payload : args[0]);
|
|
87
|
-
return middleware.handle(middleware.ctx, callCtx, next, payload);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
const input = this.handleInput(procedure, payload);
|
|
91
|
-
await this.handleGuards(callOptions, callCtx, input);
|
|
92
|
-
const { dependencies, handler } = procedure;
|
|
93
|
-
const context = await container.createContext(dependencies);
|
|
94
|
-
const result = await handler(context, input);
|
|
95
|
-
if (isIterableProcedure) {
|
|
96
|
-
return this.handleIterableOutput(procedure, result);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
return this.handleOutput(procedure, result);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
return handleProcedure;
|
|
104
|
-
}
|
|
105
|
-
async resolveMiddlewares(callOptions) {
|
|
106
|
-
const { path, procedure, container } = callOptions;
|
|
107
|
-
const middlewares = [
|
|
108
|
-
...this.options.middlewares,
|
|
109
|
-
...path.flatMap((router) => [...router.middlewares]),
|
|
110
|
-
...procedure.middlewares,
|
|
111
|
-
];
|
|
112
|
-
const result = await Promise.all(middlewares.map(async (middleware) => {
|
|
113
|
-
const ctx = await container.createContext(middleware.dependencies);
|
|
114
|
-
return { handle: middleware.handle, ctx };
|
|
115
|
-
}));
|
|
116
|
-
return result[Symbol.iterator]();
|
|
117
|
-
}
|
|
118
|
-
withTimeout(response, timeout) {
|
|
119
|
-
const applyTimeout = response instanceof Promise && timeout > 0;
|
|
120
|
-
if (!applyTimeout)
|
|
121
|
-
return response;
|
|
122
|
-
return withTimeout(response, timeout, new ApiError(ErrorCode.RequestTimeout, 'Request Timeout'));
|
|
123
|
-
}
|
|
124
|
-
async handleGuards(callOptions, callCtx, payload) {
|
|
125
|
-
const { path, procedure, container } = callOptions;
|
|
126
|
-
const guards = [
|
|
127
|
-
...this.options.guards,
|
|
128
|
-
...path.flatMap((router) => [...router.guards]),
|
|
129
|
-
...procedure.guards,
|
|
130
|
-
];
|
|
131
|
-
for (const guard of guards) {
|
|
132
|
-
const ctx = await container.createContext(guard.dependencies);
|
|
133
|
-
const result = await guard.can(ctx, Object.freeze({ ...callCtx, payload }));
|
|
134
|
-
if (result === false)
|
|
135
|
-
throw new ApiError(ErrorCode.Forbidden);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
async handleFilters({ container }, error) {
|
|
139
|
-
if (this.options.filters.size) {
|
|
140
|
-
for (const filter of this.options.filters) {
|
|
141
|
-
if (error instanceof filter.errorClass) {
|
|
142
|
-
const ctx = await container.createContext(filter.dependencies);
|
|
143
|
-
const handledError = await filter.catch(ctx, error);
|
|
144
|
-
if (!handledError || handledError instanceof ApiError === false)
|
|
145
|
-
continue;
|
|
146
|
-
return handledError;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return error;
|
|
151
|
-
}
|
|
152
|
-
handleInput(procedure, payload) {
|
|
153
|
-
if (procedure.contract.input instanceof type.NeverType === false) {
|
|
154
|
-
const type = procedure.contract.input;
|
|
155
|
-
try {
|
|
156
|
-
return type.decode(payload);
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
if (error instanceof NeemataTypeError)
|
|
160
|
-
throw new ApiError(ErrorCode.ValidationError, `Input validation error: \n${prettifyError(error)}`, error.issues);
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
handleIterableOutput(procedure, response) {
|
|
166
|
-
if (!isAsyncIterable(response))
|
|
167
|
-
throw new Error('Response is an async iterable');
|
|
168
|
-
const chunkType = procedure.contract.output;
|
|
169
|
-
if (chunkType instanceof type.NeverType)
|
|
170
|
-
throw new Error('Stream procedure must have a defined output type');
|
|
171
|
-
return async function* (onDone) {
|
|
172
|
-
try {
|
|
173
|
-
if (chunkType instanceof type.AnyType === false) {
|
|
174
|
-
for await (const chunk of response) {
|
|
175
|
-
const encoded = chunkType.encode(chunk);
|
|
176
|
-
yield encoded;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
yield* response;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
finally {
|
|
184
|
-
onDone?.();
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
handleOutput(procedure, response) {
|
|
189
|
-
if (procedure.contract.output instanceof type.NeverType === false) {
|
|
190
|
-
const type = procedure.contract.output;
|
|
191
|
-
return type.encode(response);
|
|
192
|
-
}
|
|
193
|
-
return undefined;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
//# sourceMappingURL=api.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/api.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AASnC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AASxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAElD,qBAAqB,EAAE,CAAA;AAyBvB,MAAM,OAAO,QAAS,SAAQ,aAAa;IACzC,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,CAAC,KAAK,CAAC,CAAA;wBACvC,MAAM,OAAO,CAAA;oBACf,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,KAAK,CAAC,CAAC,QAAQ,CAAA;gBACjB,CAAC;YACH,CAAC;oBAAS,CAAC;gBACT,MAAM,EAAE,EAAE,CAAA;YACZ,CAAC;QAAA,CACF,CAAA;IAAA,CACF;IAEO,YAAY,CAAC,SAAuB,EAAE,QAAa,EAAE;QAC3D,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,YAAY,IAAI,CAAC,SAAS,KAAK,KAAK,EAAE,CAAC;YAClE,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAA;YACtC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC9B,CAAC;QACD,OAAO,SAAS,CAAA;IAAA,CACjB;CACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const kProcedure: unique symbol;
|
|
2
|
-
export type kProcedure = typeof kProcedure;
|
|
3
|
-
export declare const kDefaultProcedure: unique symbol;
|
|
4
|
-
export type kDefaultProcedure = typeof kDefaultProcedure;
|
|
5
|
-
export declare const kRouter: unique symbol;
|
|
6
|
-
export type kRouter = typeof kRouter;
|
|
7
|
-
export declare const kRootRouter: unique symbol;
|
|
8
|
-
export type kRootRouter = typeof kRootRouter;
|
|
9
|
-
export declare const kMiddleware: unique symbol;
|
|
10
|
-
export type kMiddleware = typeof kMiddleware;
|
|
11
|
-
export declare const kGuard: unique symbol;
|
|
12
|
-
export type kGuard = typeof kGuard;
|
|
13
|
-
export declare const kFilter: unique symbol;
|
|
14
|
-
export type kFilter = typeof kFilter;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const kProcedure = Symbol.for('neemata:ProcedureKey');
|
|
2
|
-
export const kDefaultProcedure = Symbol.for('neemata:DefaultProcedureKey');
|
|
3
|
-
export const kRouter = Symbol.for('neemata:RouterKey');
|
|
4
|
-
export const kRootRouter = Symbol.for('neemata:RootRouterKey');
|
|
5
|
-
export const kMiddleware = Symbol.for('neemata:MiddlewareKey');
|
|
6
|
-
export const kGuard = Symbol.for('neemata:GuardKey');
|
|
7
|
-
export const kFilter = Symbol.for('neemata:FilterKey');
|
|
8
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAkB,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;AAG3E,MAAM,CAAC,MAAM,iBAAiB,GAAkB,MAAM,CAAC,GAAG,CACxD,6BAA6B,CAC9B,CAAA;AAGD,MAAM,CAAC,MAAM,OAAO,GAAkB,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAGrE,MAAM,CAAC,MAAM,WAAW,GAAkB,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;AAG7E,MAAM,CAAC,MAAM,WAAW,GAAkB,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;AAG7E,MAAM,CAAC,MAAM,MAAM,GAAkB,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;AAGnE,MAAM,CAAC,MAAM,OAAO,GAAkB,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ErrorClass, MaybePromise } from '@nmtjs/common';
|
|
2
|
-
import type { Dependant, Dependencies, DependencyContext } from '@nmtjs/core';
|
|
3
|
-
import { kFilter } from './constants.ts';
|
|
4
|
-
export interface Filter<FilterError extends ErrorClass = ErrorClass, Deps extends Dependencies = Dependencies> extends Dependant<Deps> {
|
|
5
|
-
[kFilter]: true;
|
|
6
|
-
errorClass: FilterError;
|
|
7
|
-
catch: (ctx: DependencyContext<Deps>, error: InstanceType<FilterError>) => MaybePromise<Error>;
|
|
8
|
-
}
|
|
9
|
-
export type AnyFilter<Error extends ErrorClass = ErrorClass> = Filter<Error, any>;
|
|
10
|
-
export declare function createFilter<FilterError extends ErrorClass, Deps extends Dependencies = {}>(params: {
|
|
11
|
-
errorClass: FilterError;
|
|
12
|
-
dependencies?: Deps;
|
|
13
|
-
catch: Filter<FilterError, Deps>['catch'];
|
|
14
|
-
}): Filter<FilterError, Deps>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { kFilter } from './constants.js';
|
|
2
|
-
export function createFilter(params) {
|
|
3
|
-
const { errorClass, catch: handler, dependencies = {} } = params;
|
|
4
|
-
return Object.freeze({
|
|
5
|
-
errorClass,
|
|
6
|
-
dependencies,
|
|
7
|
-
catch: handler,
|
|
8
|
-
[kFilter]: true,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=filters.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/filters.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAmBxC,MAAM,UAAU,YAAY,CAG1B,MAID,EAA6B;IAC5B,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,GAAG,EAAU,EAAE,GAAG,MAAM,CAAA;IAExE,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,UAAU;QACV,YAAY;QACZ,KAAK,EAAE,OAAO;QACd,CAAC,OAAO,CAAC,EAAE,IAAI;KAChB,CAA8B,CAAA;AAAA,CAChC"}
|