nmtjs 0.16.0-beta.9 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +58 -15
- 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 +48 -7
- package/dist/runtime/injectables.js +19 -3
- package/dist/runtime/injectables.js.map +1 -1
- 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/manager.d.ts +3 -3
- package/dist/runtime/subscription/manager.js +8 -8
- package/dist/runtime/subscription/manager.js.map +1 -1
- package/dist/runtime/subscription/redis.d.ts +1 -1
- package/dist/runtime/subscription/redis.js +16 -17
- 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/base.d.ts +0 -2
- package/dist/runtime/workers/base.js +3 -8
- 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/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 +35 -6
- 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/manager.ts +11 -14
- package/src/runtime/subscription/redis.ts +25 -23
- package/src/runtime/types.ts +3 -12
- package/src/runtime/workers/application.ts +76 -160
- package/src/runtime/workers/base.ts +9 -15
- 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
|
@@ -7,10 +7,8 @@ import type { ServerConfig } from '../server/config.ts'
|
|
|
7
7
|
import * as injectables from '../injectables.ts'
|
|
8
8
|
import { JobManager } from '../jobs/manager.ts'
|
|
9
9
|
import { BaseRuntime } from '../runtime.ts'
|
|
10
|
-
import { SubscriptionManager } from '../subscription/manager.ts'
|
|
11
10
|
|
|
12
11
|
export abstract class BaseWorkerRuntime extends BaseRuntime {
|
|
13
|
-
subscriptionManager: SubscriptionManager
|
|
14
12
|
jobManager?: JobManager
|
|
15
13
|
|
|
16
14
|
constructor(
|
|
@@ -20,11 +18,6 @@ export abstract class BaseWorkerRuntime extends BaseRuntime {
|
|
|
20
18
|
) {
|
|
21
19
|
super(options)
|
|
22
20
|
|
|
23
|
-
this.subscriptionManager = new SubscriptionManager({
|
|
24
|
-
logger: this.logger,
|
|
25
|
-
container: this.container,
|
|
26
|
-
})
|
|
27
|
-
|
|
28
21
|
if (this.config.store) {
|
|
29
22
|
this.jobManager = new JobManager(
|
|
30
23
|
this.config.store,
|
|
@@ -37,20 +30,21 @@ export abstract class BaseWorkerRuntime extends BaseRuntime {
|
|
|
37
30
|
const injections: Provision[] = [
|
|
38
31
|
provision(CoreInjectables.logger, this.logger),
|
|
39
32
|
provision(injectables.workerType, this.workerType),
|
|
40
|
-
provision(
|
|
41
|
-
injectables.publish,
|
|
42
|
-
this.subscriptionManager.publish.bind(this.subscriptionManager),
|
|
43
|
-
),
|
|
44
|
-
provision(
|
|
45
|
-
injectables.subscribe,
|
|
46
|
-
this.subscriptionManager.subscribe.bind(this.subscriptionManager),
|
|
47
|
-
),
|
|
48
33
|
]
|
|
49
34
|
|
|
50
35
|
if (this.config.store) {
|
|
51
36
|
injections.push(provision(injectables.storeConfig, this.config.store))
|
|
52
37
|
}
|
|
53
38
|
|
|
39
|
+
if (this.config.subscription) {
|
|
40
|
+
injections.push(
|
|
41
|
+
provision(
|
|
42
|
+
injectables.subscriptionAdapter,
|
|
43
|
+
this.config.subscription.adapter,
|
|
44
|
+
),
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
54
48
|
if (this.jobManager) {
|
|
55
49
|
injections.push(
|
|
56
50
|
provision(injectables.jobManager, this.jobManager.publicInstance),
|
|
@@ -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
|
|
package/src/vite/server.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { ViteConfigOptions } from './config.ts'
|
|
|
7
7
|
// When externalized, Vite's ModuleRunner uses native Node import() which has
|
|
8
8
|
// a separate module cache from Vite's cache, causing the same module to be
|
|
9
9
|
// loaded twice with different object references.
|
|
10
|
-
const noExternalPackages = ['nmtjs', /^@nmtjs
|
|
10
|
+
const noExternalPackages = ['nmtjs', /^@nmtjs\/(?!prom-client$)/]
|
|
11
11
|
|
|
12
12
|
export function createServer(
|
|
13
13
|
options: ViteConfigOptions,
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { AnyMetaBinding, Container, Logger } from '@nmtjs/core';
|
|
2
|
-
import type { GatewayApi, GatewayApiCallOptions, GatewayApiCallResult, GatewayConnection, GatewayResolvedProcedure, GatewayResolveOptions } 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
|
-
meta: readonly AnyMetaBinding[];
|
|
28
|
-
guards: Set<AnyGuard>;
|
|
29
|
-
middlewares: Set<AnyMiddleware>;
|
|
30
|
-
filters: Set<AnyFilter>;
|
|
31
|
-
};
|
|
32
|
-
export declare class ApiError extends ProtocolError {
|
|
33
|
-
toString(): string;
|
|
34
|
-
}
|
|
35
|
-
export declare class ApplicationApi implements GatewayApi {
|
|
36
|
-
options: ApiOptions;
|
|
37
|
-
constructor(options: ApiOptions);
|
|
38
|
-
find(procedureName: string): {
|
|
39
|
-
procedure: AnyProcedure;
|
|
40
|
-
path: AnyRouter[];
|
|
41
|
-
};
|
|
42
|
-
resolve(options: GatewayResolveOptions): Promise<GatewayResolvedProcedure>;
|
|
43
|
-
call(options: GatewayApiCallOptions): Promise<GatewayApiCallResult>;
|
|
44
|
-
private createProcedureHandler;
|
|
45
|
-
private resolveMetaBindings;
|
|
46
|
-
private applyStaticMetaBindings;
|
|
47
|
-
private applyFactoryMetaBindings;
|
|
48
|
-
private resolveMiddlewares;
|
|
49
|
-
private withTimeout;
|
|
50
|
-
private handleGuards;
|
|
51
|
-
private handleFilters;
|
|
52
|
-
private handleInput;
|
|
53
|
-
private handleIterableOutput;
|
|
54
|
-
private handleOutput;
|
|
55
|
-
}
|
|
@@ -1,252 +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 { getMetaBindingMeta, getStaticMetaValue, isStaticMetaBinding, Scope, } from '@nmtjs/core';
|
|
7
|
-
import { createGatewayStaticMetaView, 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 { config, defaultRuntimeConfig } from './config.js';
|
|
13
|
-
import { kDefaultProcedure } from './constants.js';
|
|
14
|
-
registerDefaultLocale();
|
|
15
|
-
export class ApiError extends ProtocolError {
|
|
16
|
-
toString() {
|
|
17
|
-
return `${this.code} ${this.message}: \n${inspect(this.data, true, 10, false)}`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const NotFound = () => new ApiError(ErrorCode.NotFound, 'Procedure not found');
|
|
21
|
-
export class ApplicationApi {
|
|
22
|
-
options;
|
|
23
|
-
constructor(options) {
|
|
24
|
-
this.options = options;
|
|
25
|
-
}
|
|
26
|
-
find(procedureName) {
|
|
27
|
-
const procedure = this.options.procedures.get(procedureName);
|
|
28
|
-
if (procedure)
|
|
29
|
-
return procedure;
|
|
30
|
-
const fallback = this.options.procedures.get(kDefaultProcedure);
|
|
31
|
-
if (fallback)
|
|
32
|
-
return fallback;
|
|
33
|
-
throw NotFound();
|
|
34
|
-
}
|
|
35
|
-
async resolve(options) {
|
|
36
|
-
const { procedure, path } = this.find(options.procedure);
|
|
37
|
-
const metaBindings = this.resolveMetaBindings(path, procedure);
|
|
38
|
-
return Object.freeze({
|
|
39
|
-
stream: IsStreamProcedureContract(procedure.contract),
|
|
40
|
-
meta: createGatewayStaticMetaView(metaBindings.static),
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async call(options) {
|
|
44
|
-
const callId = randomUUID();
|
|
45
|
-
const { payload, container, signal, connection } = options;
|
|
46
|
-
assert(container.scope === Scope.Call, 'Invalid container scope, expected to be Scope.Call');
|
|
47
|
-
const { procedure, path } = this.find(options.procedure);
|
|
48
|
-
const metaBindings = this.resolveMetaBindings(path, procedure);
|
|
49
|
-
const callOptions = Object.freeze({
|
|
50
|
-
callId,
|
|
51
|
-
payload,
|
|
52
|
-
container,
|
|
53
|
-
signal,
|
|
54
|
-
connection,
|
|
55
|
-
procedure,
|
|
56
|
-
path,
|
|
57
|
-
});
|
|
58
|
-
const timeout = procedure.contract.timeout ?? this.options.timeout;
|
|
59
|
-
const streamTimeoutSignal = procedure.streamTimeout
|
|
60
|
-
? AbortSignal.timeout(procedure.streamTimeout)
|
|
61
|
-
: undefined;
|
|
62
|
-
if (streamTimeoutSignal) {
|
|
63
|
-
container.provide(rpcStreamAbortSignal, streamTimeoutSignal);
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
const handle = await this.createProcedureHandler(callOptions, metaBindings);
|
|
67
|
-
return timeout
|
|
68
|
-
? await this.withTimeout(handle(payload), timeout)
|
|
69
|
-
: await handle(payload);
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
const handled = await this.handleFilters(callOptions, error);
|
|
73
|
-
if (handled === error && error instanceof ProtocolError === false) {
|
|
74
|
-
const logError = new Error('Unhandled error', { cause: error });
|
|
75
|
-
this.options.logger.error(logError);
|
|
76
|
-
throw new ApiError(ErrorCode.InternalServerError, 'Internal Server Error');
|
|
77
|
-
}
|
|
78
|
-
throw handled;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async createProcedureHandler(callOptions, metaBindings) {
|
|
82
|
-
const { callId, connection, procedure, container, path } = callOptions;
|
|
83
|
-
const callCtx = Object.freeze({
|
|
84
|
-
callId,
|
|
85
|
-
connection,
|
|
86
|
-
container,
|
|
87
|
-
path,
|
|
88
|
-
procedure,
|
|
89
|
-
});
|
|
90
|
-
const isIterableProcedure = IsStreamProcedureContract(procedure.contract);
|
|
91
|
-
this.applyStaticMetaBindings(container, metaBindings.static);
|
|
92
|
-
const middlewares = this.resolveMiddlewares(callOptions);
|
|
93
|
-
const handleProcedure = async (payload) => {
|
|
94
|
-
const middleware = (await middlewares).next().value;
|
|
95
|
-
if (middleware) {
|
|
96
|
-
const next = (...args) => handleProcedure(args.length === 0 ? payload : args[0]);
|
|
97
|
-
return middleware.handle(middleware.ctx, callCtx, next, payload);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
await this.applyFactoryMetaBindings(container, metaBindings.beforeDecode, callCtx, payload);
|
|
101
|
-
const input = this.handleInput(procedure, payload);
|
|
102
|
-
await this.applyFactoryMetaBindings(container, metaBindings.afterDecode, callCtx, input);
|
|
103
|
-
await this.handleGuards(callOptions, callCtx, input);
|
|
104
|
-
const { dependencies, handler } = procedure;
|
|
105
|
-
const context = await container.createContext(dependencies);
|
|
106
|
-
const result = await handler(context, input);
|
|
107
|
-
if (isIterableProcedure) {
|
|
108
|
-
return this.handleIterableOutput(procedure, result, metaBindings.config);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
return this.handleOutput(procedure, result, metaBindings.config);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
return handleProcedure;
|
|
116
|
-
}
|
|
117
|
-
resolveMetaBindings(path, procedure) {
|
|
118
|
-
const bindings = [
|
|
119
|
-
...this.options.meta,
|
|
120
|
-
...path.flatMap((router) => router.meta),
|
|
121
|
-
...procedure.meta,
|
|
122
|
-
];
|
|
123
|
-
const staticBindings = [];
|
|
124
|
-
const beforeDecode = [];
|
|
125
|
-
const afterDecode = [];
|
|
126
|
-
for (const binding of bindings) {
|
|
127
|
-
if (isStaticMetaBinding(binding)) {
|
|
128
|
-
staticBindings.push(binding);
|
|
129
|
-
}
|
|
130
|
-
else if (binding.phase === 'afterDecode') {
|
|
131
|
-
afterDecode.push(binding);
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
beforeDecode.push(binding);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
const runtimeConfig = getStaticMetaValue(staticBindings, config);
|
|
138
|
-
return Object.freeze({
|
|
139
|
-
static: Object.freeze(staticBindings),
|
|
140
|
-
beforeDecode: Object.freeze(beforeDecode),
|
|
141
|
-
afterDecode: Object.freeze(afterDecode),
|
|
142
|
-
config: Object.freeze({ ...defaultRuntimeConfig, ...runtimeConfig }),
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
applyStaticMetaBindings(container, bindings) {
|
|
146
|
-
for (const binding of bindings) {
|
|
147
|
-
container.provide(getMetaBindingMeta(binding), binding.value);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
async applyFactoryMetaBindings(container, bindings, callCtx, input) {
|
|
151
|
-
for (const binding of bindings) {
|
|
152
|
-
const context = await container.createContext(binding.dependencies);
|
|
153
|
-
const value = await binding.resolve(context, callCtx, input);
|
|
154
|
-
container.provide(getMetaBindingMeta(binding), value);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
async resolveMiddlewares(callOptions) {
|
|
158
|
-
const { path, procedure, container } = callOptions;
|
|
159
|
-
const middlewares = [
|
|
160
|
-
...this.options.middlewares,
|
|
161
|
-
...path.flatMap((router) => [...router.middlewares]),
|
|
162
|
-
...procedure.middlewares,
|
|
163
|
-
];
|
|
164
|
-
const result = await Promise.all(middlewares.map(async (middleware) => {
|
|
165
|
-
const ctx = await container.createContext(middleware.dependencies);
|
|
166
|
-
return { handle: middleware.handle, ctx };
|
|
167
|
-
}));
|
|
168
|
-
return result[Symbol.iterator]();
|
|
169
|
-
}
|
|
170
|
-
withTimeout(response, timeout) {
|
|
171
|
-
const applyTimeout = response instanceof Promise && timeout > 0;
|
|
172
|
-
if (!applyTimeout)
|
|
173
|
-
return response;
|
|
174
|
-
return withTimeout(response, timeout, new ApiError(ErrorCode.RequestTimeout, 'Request Timeout'));
|
|
175
|
-
}
|
|
176
|
-
async handleGuards(callOptions, callCtx, payload) {
|
|
177
|
-
const { path, procedure, container } = callOptions;
|
|
178
|
-
const guards = [
|
|
179
|
-
...this.options.guards,
|
|
180
|
-
...path.flatMap((router) => [...router.guards]),
|
|
181
|
-
...procedure.guards,
|
|
182
|
-
];
|
|
183
|
-
for (const guard of guards) {
|
|
184
|
-
const ctx = await container.createContext(guard.dependencies);
|
|
185
|
-
const result = await guard.can(ctx, Object.freeze({ ...callCtx, payload }));
|
|
186
|
-
if (result === false)
|
|
187
|
-
throw new ApiError(ErrorCode.Forbidden);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
async handleFilters({ container }, error) {
|
|
191
|
-
if (this.options.filters.size) {
|
|
192
|
-
for (const filter of this.options.filters) {
|
|
193
|
-
if (error instanceof filter.errorClass) {
|
|
194
|
-
const ctx = await container.createContext(filter.dependencies);
|
|
195
|
-
const handledError = await filter.catch(ctx, error);
|
|
196
|
-
if (!handledError || handledError instanceof ApiError === false)
|
|
197
|
-
continue;
|
|
198
|
-
return handledError;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return error;
|
|
203
|
-
}
|
|
204
|
-
handleInput(procedure, payload) {
|
|
205
|
-
if (procedure.contract.input instanceof type.NeverType === false) {
|
|
206
|
-
const type = procedure.contract.input;
|
|
207
|
-
try {
|
|
208
|
-
return type.decode(payload);
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
if (error instanceof NeemataTypeError)
|
|
212
|
-
throw new ApiError(ErrorCode.ValidationError, `Input validation error: \n${prettifyError(error)}`, error.issues);
|
|
213
|
-
throw error;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
handleIterableOutput(procedure, response, runtimeConfig) {
|
|
218
|
-
if (!isAsyncIterable(response))
|
|
219
|
-
throw new Error('Response is an async iterable');
|
|
220
|
-
const chunkType = procedure.contract.output;
|
|
221
|
-
if (chunkType instanceof type.NeverType)
|
|
222
|
-
throw new Error('Stream procedure must have a defined output type');
|
|
223
|
-
return async function* (onDone) {
|
|
224
|
-
try {
|
|
225
|
-
if (runtimeConfig.serializeOutput === false) {
|
|
226
|
-
yield* response;
|
|
227
|
-
}
|
|
228
|
-
else if (chunkType instanceof type.AnyType === false) {
|
|
229
|
-
for await (const chunk of response) {
|
|
230
|
-
yield chunkType.encode(chunk);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
yield* response;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
finally {
|
|
238
|
-
onDone?.();
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
handleOutput(procedure, response, runtimeConfig) {
|
|
243
|
-
if (procedure.contract.output instanceof type.NeverType === false) {
|
|
244
|
-
if (runtimeConfig.serializeOutput === false)
|
|
245
|
-
return response;
|
|
246
|
-
const type = procedure.contract.output;
|
|
247
|
-
return type.encode(response);
|
|
248
|
-
}
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
//# 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,EA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,CAAA;YAC5D,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAA;YACtC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC9B,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;CACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { MetadataKind } from '@nmtjs/core';
|
|
2
|
-
export interface RuntimeConfig {
|
|
3
|
-
serializeOutput?: boolean;
|
|
4
|
-
}
|
|
5
|
-
export declare const config: import("@nmtjs/core").Meta<RuntimeConfig, MetadataKind.STATIC, Readonly<{
|
|
6
|
-
callId: string;
|
|
7
|
-
connection: import("@nmtjs/gateway").GatewayConnection;
|
|
8
|
-
container: import("@nmtjs/core").Container;
|
|
9
|
-
path: readonly import("./meta.ts").ApiMetaRouteContext[];
|
|
10
|
-
procedure: import("./meta.ts").ApiMetaProcedureContext;
|
|
11
|
-
}>>;
|
|
12
|
-
export declare const defaultRuntimeConfig: Readonly<{
|
|
13
|
-
serializeOutput: true;
|
|
14
|
-
}>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAQxC,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,EAI7B,CAAA;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC;IAChD,eAAe,EAAE,IAAI;CACY,CAAC,CAAA"}
|
|
@@ -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;IACC,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;AACjC,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { MaybePromise } from '@nmtjs/common';
|
|
2
|
-
import type { Dependant, Dependencies, DependencyContext } from '@nmtjs/core';
|
|
3
|
-
import type { ApiGuardContext } from './types.ts';
|
|
4
|
-
import { kGuard } from './constants.ts';
|
|
5
|
-
export type GuardCanFn<Deps extends Dependencies> = (ctx: DependencyContext<Deps>, call: ApiGuardContext) => MaybePromise<boolean>;
|
|
6
|
-
export type GuardParams<Deps extends Dependencies> = {
|
|
7
|
-
dependencies?: Deps;
|
|
8
|
-
can: GuardCanFn<Deps>;
|
|
9
|
-
} | GuardCanFn<Deps>;
|
|
10
|
-
export interface Guard<Deps extends Dependencies = Dependencies> extends Dependant<Deps> {
|
|
11
|
-
[kGuard]: true;
|
|
12
|
-
can: GuardCanFn<Deps>;
|
|
13
|
-
}
|
|
14
|
-
export type AnyGuard = Guard<any>;
|
|
15
|
-
export declare function createGuard<Deps extends Dependencies = {}>(paramsOrHandler: GuardParams<Deps>): Guard<Deps>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { kGuard } from './constants.js';
|
|
2
|
-
export function createGuard(paramsOrHandler) {
|
|
3
|
-
const { dependencies = {}, can } = typeof paramsOrHandler === 'function'
|
|
4
|
-
? { can: paramsOrHandler }
|
|
5
|
-
: paramsOrHandler;
|
|
6
|
-
return Object.freeze({ dependencies, can, [kGuard]: true });
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=guards.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/guards.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAmBvC,MAAM,UAAU,WAAW,CACzB,eAAkC;IAElC,MAAM,EAAE,YAAY,GAAG,EAAU,EAAE,GAAG,EAAE,GACtC,OAAO,eAAe,KAAK,UAAU;QACnC,CAAC,CAAC,EAAE,GAAG,EAAE,eAAe,EAAE;QAC1B,CAAC,CAAC,eAAe,CAAA;IAErB,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAgB,CAAA;AAC5E,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { AnyMeta, AfterDecodeMetaBinding as CoreAfterDecodeMetaBinding, AnyFactoryMetaBinding as CoreAnyFactoryMetaBinding, BeforeDecodeMetaBinding as CoreBeforeDecodeMetaBinding, Meta as CoreMeta, MetaFactoryBinding as CoreMetaFactoryBinding, Dependencies, MetaPhase, StaticMetaBinding } from '@nmtjs/core';
|
|
2
|
-
import { MetadataKind } from '@nmtjs/core';
|
|
3
|
-
import type { ApiMetaContext } from './meta.ts';
|
|
4
|
-
export type { AnyMeta, MetaPhase, StaticMetaBinding };
|
|
5
|
-
export { MetadataKind };
|
|
6
|
-
export type Meta<Value, Kind extends MetadataKind = MetadataKind> = CoreMeta<Value, Kind, ApiMetaContext>;
|
|
7
|
-
export type BeforeDecodeMetaBinding<T extends AnyMeta = AnyMeta, Deps extends Dependencies = {}> = CoreBeforeDecodeMetaBinding<T, Deps, ApiMetaContext>;
|
|
8
|
-
export type AfterDecodeMetaBinding<T extends AnyMeta = AnyMeta, Deps extends Dependencies = {}, Input = unknown> = CoreAfterDecodeMetaBinding<T, Deps, ApiMetaContext, Input>;
|
|
9
|
-
export type MetaFactoryBinding<T extends AnyMeta = AnyMeta, Deps extends Dependencies = {}, Phase extends MetaPhase = MetaPhase, Input = unknown> = CoreMetaFactoryBinding<T, Deps, Phase, ApiMetaContext, Input>;
|
|
10
|
-
export type AnyFactoryMetaBinding<T extends AnyMeta = AnyMeta, Deps extends Dependencies = Dependencies, Phase extends MetaPhase = MetaPhase, Input = unknown> = CoreAnyFactoryMetaBinding<T, Deps, Phase, ApiMetaContext, Input>;
|
|
11
|
-
export type AnyMetaBinding = StaticMetaBinding | AnyFactoryMetaBinding;
|
|
12
|
-
export declare function createMeta<Value, Kind extends MetadataKind = MetadataKind>(): Meta<Value, Kind>;
|
|
13
|
-
export * from './api.ts';
|
|
14
|
-
export * from './config.ts';
|
|
15
|
-
export * from './constants.ts';
|
|
16
|
-
export * from './filters.ts';
|
|
17
|
-
export * from './guards.ts';
|
|
18
|
-
export * from './logging.ts';
|
|
19
|
-
export * from './meta.ts';
|
|
20
|
-
export * from './middlewares.ts';
|
|
21
|
-
export * from './procedure.ts';
|
|
22
|
-
export * from './router.ts';
|
|
23
|
-
export * from './types.ts';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createMeta as createCoreMeta, MetadataKind } from '@nmtjs/core';
|
|
2
|
-
export { MetadataKind };
|
|
3
|
-
export function createMeta() {
|
|
4
|
-
return createCoreMeta();
|
|
5
|
-
}
|
|
6
|
-
export * from './api.js';
|
|
7
|
-
export * from './config.js';
|
|
8
|
-
export * from './constants.js';
|
|
9
|
-
export * from './filters.js';
|
|
10
|
-
export * from './guards.js';
|
|
11
|
-
export * from './logging.js';
|
|
12
|
-
export * from './meta.js';
|
|
13
|
-
export * from './middlewares.js';
|
|
14
|
-
export * from './procedure.js';
|
|
15
|
-
export * from './router.js';
|
|
16
|
-
export * from './types.js';
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAKxE,OAAO,EAAE,YAAY,EAAE,CAAA;AAmCvB,MAAM,UAAU,UAAU;IAIxB,OAAO,cAAc,EAAoD,CAAA;AAC3E,CAAC;AAED,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { MaybePromise } from '@nmtjs/common';
|
|
2
|
-
import type { ApiCallContext } from './types.ts';
|
|
3
|
-
export declare const LoggingCallContextMiddleware: (cb?: (options: ApiCallContext, payload: unknown) => MaybePromise<object>) => import("./middlewares.ts").Middleware<{}>;
|
|
4
|
-
export declare const LoggingCallMiddleware: (options?: {
|
|
5
|
-
level?: 'info' | 'debug' | 'trace';
|
|
6
|
-
errorLevel?: 'warn' | 'error' | 'fatal';
|
|
7
|
-
includePayload?: boolean;
|
|
8
|
-
includeResponse?: boolean;
|
|
9
|
-
includeStreamChunks?: boolean;
|
|
10
|
-
}) => import("./middlewares.ts").Middleware<{
|
|
11
|
-
logger: import("@nmtjs/core").FactoryInjectable<import("pino").Logger, {
|
|
12
|
-
logger: import("@nmtjs/core").LazyInjectable<import("pino").Logger>;
|
|
13
|
-
}, import("@nmtjs/core").Scope.Global, import("pino").Logger>;
|
|
14
|
-
}>;
|