nmtjs 0.16.0-beta.8 → 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 +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
|
-
}>;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { IsStreamProcedureContract } from '@nmtjs/contract';
|
|
2
|
-
import { CoreInjectables, loggerLocalStorage } from '@nmtjs/core';
|
|
3
|
-
import { createMiddleware } from './middlewares.js';
|
|
4
|
-
const defaultContext = (options, payload) => {
|
|
5
|
-
return {
|
|
6
|
-
callId: options.callId,
|
|
7
|
-
connection: {
|
|
8
|
-
id: options.connection.id,
|
|
9
|
-
type: options.connection.type,
|
|
10
|
-
transport: options.connection.transport,
|
|
11
|
-
protocol: options.connection.protocol,
|
|
12
|
-
identity: options.connection.identity,
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export const LoggingCallContextMiddleware = (cb = defaultContext) => createMiddleware({
|
|
17
|
-
handle: async (_, call, next, payload) => {
|
|
18
|
-
const loggingContext = await cb(call, payload);
|
|
19
|
-
return loggerLocalStorage.run(loggingContext, async () => {
|
|
20
|
-
return next();
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
export const LoggingCallMiddleware = (options = {}) => createMiddleware({
|
|
25
|
-
dependencies: { logger: CoreInjectables.logger('RPC') },
|
|
26
|
-
handle: async ({ logger }, call, next, payload) => {
|
|
27
|
-
const { includePayload, includeResponse, includeStreamChunks, level, errorLevel, } = {
|
|
28
|
-
level: 'info',
|
|
29
|
-
errorLevel: 'error',
|
|
30
|
-
includePayload: true,
|
|
31
|
-
includeResponse: true,
|
|
32
|
-
includeStreamChunks: true,
|
|
33
|
-
...options,
|
|
34
|
-
};
|
|
35
|
-
const logFn = logger[level].bind(logger);
|
|
36
|
-
const errorLogFn = logger[errorLevel].bind(logger);
|
|
37
|
-
logFn(includePayload
|
|
38
|
-
? { procedure: call.procedure.contract.name, payload: payload }
|
|
39
|
-
: { procedure: call.procedure.contract.name }, 'RPC call');
|
|
40
|
-
const isIterableProcedure = IsStreamProcedureContract(call.procedure.contract);
|
|
41
|
-
try {
|
|
42
|
-
const response = await next();
|
|
43
|
-
if (includeResponse) {
|
|
44
|
-
if (isIterableProcedure) {
|
|
45
|
-
logFn({ result: 'success', response: 'Stream' }, 'RPC response');
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
logFn({ result: 'success', response }, 'RPC response');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
logFn({ result: 'success' }, 'RPC response');
|
|
53
|
-
}
|
|
54
|
-
if (isIterableProcedure && includeStreamChunks) {
|
|
55
|
-
return async function* (...args) {
|
|
56
|
-
try {
|
|
57
|
-
for await (const chunk of response(...args)) {
|
|
58
|
-
logFn({ callId: call.callId, chunk }, 'RPC stream chunk');
|
|
59
|
-
yield chunk;
|
|
60
|
-
}
|
|
61
|
-
logFn({ callId: call.callId }, 'RPC stream end');
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
errorLogFn({ callId: call.callId, error }, 'RPC stream error');
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return response;
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
errorLogFn({ error }, 'RPC error');
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
//# sourceMappingURL=logging.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/logging.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEnD,MAAM,cAAc,GAAG,CAAC,OAAuB,EAAE,OAAgB,EAAE,EAAE;IACnE,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,UAAU,EAAE;YACV,EAAE,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE;YACzB,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI;YAC7B,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,SAAS;YACvC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ;YACrC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ;SACtC;KACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,4BAA4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CAAC;YAED,OAAO,QAAQ,CAAA;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,CAAC,CAAA;YAClC,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { TAnyProcedureContract, TAnyRouterContract } from '@nmtjs/contract';
|
|
2
|
-
import type { AfterDecodeMetaBinding, AnyMeta, BeforeDecodeMetaBinding, Container, StaticMetaBinding } from '@nmtjs/core';
|
|
3
|
-
import type { GatewayConnection } from '@nmtjs/gateway';
|
|
4
|
-
export type ApiMetaRouteContext = Readonly<{
|
|
5
|
-
contract: TAnyRouterContract;
|
|
6
|
-
timeout?: number;
|
|
7
|
-
}>;
|
|
8
|
-
export type ApiMetaProcedureContext = Readonly<{
|
|
9
|
-
contract: TAnyProcedureContract;
|
|
10
|
-
streamTimeout?: number;
|
|
11
|
-
}>;
|
|
12
|
-
export type ApiMetaContext = Readonly<{
|
|
13
|
-
callId: string;
|
|
14
|
-
connection: GatewayConnection;
|
|
15
|
-
container: Container;
|
|
16
|
-
path: readonly ApiMetaRouteContext[];
|
|
17
|
-
procedure: ApiMetaProcedureContext;
|
|
18
|
-
}>;
|
|
19
|
-
export type StaticOrBeforeDecodeMetaBinding = StaticMetaBinding | BeforeDecodeMetaBinding<AnyMeta, any, ApiMetaContext>;
|
|
20
|
-
export type CompatibleMetaBinding<Input> = StaticOrBeforeDecodeMetaBinding | AfterDecodeMetaBinding<AnyMeta, any, ApiMetaContext, Input>;
|
|
21
|
-
export type AnyCompatibleMetaBinding = CompatibleMetaBinding<any>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/meta.ts"],"names":[],"mappings":""}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { MaybePromise } from '@nmtjs/common';
|
|
2
|
-
import type { Dependant, Dependencies, DependencyContext } from '@nmtjs/core';
|
|
3
|
-
import type { ApiCallContext } from './types.ts';
|
|
4
|
-
import { kMiddleware } from './constants.ts';
|
|
5
|
-
export type MiddlewareNext = (payload?: any) => any;
|
|
6
|
-
export interface Middleware<Deps extends Dependencies = Dependencies> extends Dependant<Deps> {
|
|
7
|
-
[kMiddleware]: true;
|
|
8
|
-
handle: (ctx: DependencyContext<Deps>, call: ApiCallContext, next: MiddlewareNext, payload: any) => MaybePromise<any>;
|
|
9
|
-
}
|
|
10
|
-
export type AnyMiddleware = Middleware<any>;
|
|
11
|
-
export declare function createMiddleware<Deps extends Dependencies = {}>(paramsOrHandler: {
|
|
12
|
-
dependencies?: Deps;
|
|
13
|
-
handle: Middleware<Deps>['handle'];
|
|
14
|
-
} | Middleware<Deps>['handle']): Middleware<Deps>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { kMiddleware } from './constants.js';
|
|
2
|
-
export function createMiddleware(paramsOrHandler) {
|
|
3
|
-
const { dependencies = {}, handle } = typeof paramsOrHandler === 'function'
|
|
4
|
-
? { handle: paramsOrHandler }
|
|
5
|
-
: paramsOrHandler;
|
|
6
|
-
return Object.freeze({
|
|
7
|
-
dependencies,
|
|
8
|
-
handle,
|
|
9
|
-
[kMiddleware]: true,
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=middlewares.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/middlewares.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAiB5C,MAAM,UAAU,gBAAgB,CAC9B,eAE8B;IAE9B,MAAM,EAAE,YAAY,GAAG,EAAU,EAAE,MAAM,EAAE,GACzC,OAAO,eAAe,KAAK,UAAU;QACnC,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE;QAC7B,CAAC,CAAC,eAAe,CAAA;IAErB,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,YAAY;QACZ,MAAM;QACN,CAAC,WAAW,CAAC,EAAE,IAAI;KACpB,CAAqB,CAAA;AACxB,CAAC"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { MaybePromise } from '@nmtjs/common';
|
|
2
|
-
import type { TAnyProcedureContract, TProcedureContract } from '@nmtjs/contract';
|
|
3
|
-
import type { Dependant, Dependencies, DependencyContext } from '@nmtjs/core';
|
|
4
|
-
import type { BaseType } from '@nmtjs/type';
|
|
5
|
-
import type * as zod from 'zod/mini';
|
|
6
|
-
import { t } from '@nmtjs/type';
|
|
7
|
-
import type { AnyGuard } from './guards.ts';
|
|
8
|
-
import type { AnyCompatibleMetaBinding, CompatibleMetaBinding } from './meta.ts';
|
|
9
|
-
import type { AnyMiddleware } from './middlewares.ts';
|
|
10
|
-
import type { JsonPrimitive } from './types.ts';
|
|
11
|
-
import { kProcedure } from './constants.ts';
|
|
12
|
-
export type { AnyCompatibleMetaBinding, CompatibleMetaBinding, StaticOrBeforeDecodeMetaBinding, } from './meta.ts';
|
|
13
|
-
export type ProcedureMetaBinding<Input> = CompatibleMetaBinding<Input>;
|
|
14
|
-
export type AnyProcedureMetaBinding = AnyCompatibleMetaBinding;
|
|
15
|
-
export type ProcedureDecodedInput<Input extends BaseType | undefined> = Input extends BaseType ? t.infer.decode.output<Input> : never;
|
|
16
|
-
export type ProcedureContractDecodedInput<ProcedureContract extends TAnyProcedureContract> = t.infer.decode.output<ProcedureContract['input']>;
|
|
17
|
-
export interface BaseProcedure<ProcedureContract extends TAnyProcedureContract, ProcedureDeps extends Dependencies> extends Dependant<ProcedureDeps> {
|
|
18
|
-
contract: ProcedureContract;
|
|
19
|
-
handler: (...args: any[]) => any;
|
|
20
|
-
meta: readonly AnyProcedureMetaBinding[];
|
|
21
|
-
dependencies: ProcedureDeps;
|
|
22
|
-
guards: Set<AnyGuard>;
|
|
23
|
-
middlewares: Set<AnyMiddleware>;
|
|
24
|
-
streamTimeout?: number;
|
|
25
|
-
[kProcedure]: any;
|
|
26
|
-
}
|
|
27
|
-
export type ProcedureHandlerType<Input, Output, Deps extends Dependencies> = (ctx: DependencyContext<Deps>, data: Input) => MaybePromise<Output>;
|
|
28
|
-
export interface Procedure<ProcedureContract extends TAnyProcedureContract, ProcedureDeps extends Dependencies> extends BaseProcedure<ProcedureContract, ProcedureDeps> {
|
|
29
|
-
handler: ProcedureHandlerType<ProcedureContractDecodedInput<ProcedureContract>, ProcedureContract['stream'] extends true ? AsyncIterable<t.infer.encode.input<ProcedureContract['output']>> : t.infer.encode.input<ProcedureContract['output']>, ProcedureDeps>;
|
|
30
|
-
}
|
|
31
|
-
export type AnyProcedure<Contract extends TAnyProcedureContract = TAnyProcedureContract> = BaseProcedure<Contract, Dependencies>;
|
|
32
|
-
export type CreateProcedureParams<ProcedureContract extends TAnyProcedureContract, ProcedureDeps extends Dependencies> = {
|
|
33
|
-
dependencies?: ProcedureDeps;
|
|
34
|
-
guards?: AnyGuard[];
|
|
35
|
-
middlewares?: AnyMiddleware[];
|
|
36
|
-
meta?: ProcedureMetaBinding<ProcedureContractDecodedInput<ProcedureContract>>[];
|
|
37
|
-
streamTimeout?: number;
|
|
38
|
-
handler: ProcedureHandlerType<ProcedureContractDecodedInput<ProcedureContract>, ProcedureContract['stream'] extends undefined ? t.infer.encode.input<ProcedureContract['output']> : AsyncIterable<Exclude<ProcedureContract['stream'], undefined | boolean>>, ProcedureDeps>;
|
|
39
|
-
} | ProcedureHandlerType<ProcedureContractDecodedInput<ProcedureContract>, ProcedureContract['stream'] extends undefined ? t.infer.decode.input<ProcedureContract['output']> : AsyncIterable<Exclude<ProcedureContract['stream'], undefined | boolean>>, ProcedureDeps>;
|
|
40
|
-
export declare function _createBaseProcedure<ProcedureContract extends TAnyProcedureContract, ProcedureDeps extends Dependencies>(contract: ProcedureContract, params: {
|
|
41
|
-
dependencies?: ProcedureDeps;
|
|
42
|
-
middlewares?: AnyMiddleware[];
|
|
43
|
-
guards?: AnyGuard[];
|
|
44
|
-
meta?: AnyProcedureMetaBinding[];
|
|
45
|
-
streamTimeout?: number;
|
|
46
|
-
}): {
|
|
47
|
-
contract: ProcedureContract;
|
|
48
|
-
dependencies: ProcedureDeps;
|
|
49
|
-
middlewares: Set<AnyMiddleware>;
|
|
50
|
-
guards: Set<AnyGuard>;
|
|
51
|
-
meta: readonly AnyCompatibleMetaBinding[];
|
|
52
|
-
streamTimeout: number | undefined;
|
|
53
|
-
};
|
|
54
|
-
export declare function createContractProcedure<ProcedureContract extends TAnyProcedureContract, ProcedureDeps extends Dependencies>(contract: ProcedureContract, paramsOrHandler: CreateProcedureParams<ProcedureContract, ProcedureDeps>): Procedure<ProcedureContract, ProcedureDeps>;
|
|
55
|
-
export declare function createProcedure<Return, TInput extends BaseType | undefined = undefined, TOutput extends BaseType | undefined = undefined, TStream extends true | number | undefined = undefined, Deps extends Dependencies = {}>(paramsOrHandler: {
|
|
56
|
-
input?: TInput;
|
|
57
|
-
output?: TOutput;
|
|
58
|
-
/**
|
|
59
|
-
* Whether the procedure is a stream procedure.
|
|
60
|
-
* If set to `true`, the procedure handler should return an `AsyncIterable` of output items.
|
|
61
|
-
* If set to a number, it specifies an explicit stream timeout in milliseconds.
|
|
62
|
-
*/
|
|
63
|
-
stream?: TStream;
|
|
64
|
-
dependencies?: Deps;
|
|
65
|
-
guards?: AnyGuard[];
|
|
66
|
-
middlewares?: AnyMiddleware[];
|
|
67
|
-
meta?: ProcedureMetaBinding<ProcedureDecodedInput<TInput>>[];
|
|
68
|
-
timeout?: number;
|
|
69
|
-
handler: ProcedureHandlerType<ProcedureDecodedInput<TInput>, TStream extends true | number ? AsyncIterable<TOutput extends BaseType ? t.infer.encode.input<TOutput> : Return> : TOutput extends BaseType ? t.infer.encode.input<TOutput> : Return, Deps>;
|
|
70
|
-
} | ProcedureHandlerType<ProcedureDecodedInput<TInput>, Return, Deps>): Procedure<TProcedureContract<TInput extends undefined ? t.NeverType : TInput, TOutput extends undefined ? t.CustomType<JsonPrimitive<Return>, zod.ZodMiniCustom<JsonPrimitive<Return>, JsonPrimitive<Return>>> : TOutput, TStream extends true | number ? true : undefined>, Deps>;
|
|
71
|
-
export declare const isProcedure: (value: any) => value is AnyProcedure;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { c } from '@nmtjs/contract';
|
|
2
|
-
import { assertUniqueMetaBindings } from '@nmtjs/core';
|
|
3
|
-
import { t } from '@nmtjs/type';
|
|
4
|
-
import { kProcedure } from './constants.js';
|
|
5
|
-
export function _createBaseProcedure(contract, params) {
|
|
6
|
-
const dependencies = params.dependencies ?? {};
|
|
7
|
-
const middlewares = new Set(params.middlewares ?? []);
|
|
8
|
-
const guards = new Set(params.guards ?? []);
|
|
9
|
-
const meta = Object.freeze([...(params.meta ?? [])]);
|
|
10
|
-
const streamTimeout = params.streamTimeout;
|
|
11
|
-
if (typeof streamTimeout !== 'undefined' && streamTimeout <= 0) {
|
|
12
|
-
throw new Error('Stream timeout must be a positive integer');
|
|
13
|
-
}
|
|
14
|
-
assertUniqueMetaBindings(meta, 'procedure config');
|
|
15
|
-
return { contract, dependencies, middlewares, guards, meta, streamTimeout };
|
|
16
|
-
}
|
|
17
|
-
export function createContractProcedure(contract, paramsOrHandler) {
|
|
18
|
-
const { handler, ...params } = typeof paramsOrHandler === 'function'
|
|
19
|
-
? { handler: paramsOrHandler }
|
|
20
|
-
: paramsOrHandler;
|
|
21
|
-
return Object.assign(_createBaseProcedure(contract, params), {
|
|
22
|
-
handler,
|
|
23
|
-
[kProcedure]: true,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export function createProcedure(paramsOrHandler) {
|
|
27
|
-
const { input = t.never(), output = t.any(), stream = undefined, dependencies = {}, guards = [], middlewares = [], meta = [], handler, timeout, } = typeof paramsOrHandler === 'function'
|
|
28
|
-
? { handler: paramsOrHandler }
|
|
29
|
-
: paramsOrHandler;
|
|
30
|
-
// @ts-expect-error
|
|
31
|
-
return createContractProcedure(c.procedure({ input, output, stream, timeout }), {
|
|
32
|
-
dependencies,
|
|
33
|
-
handler: handler,
|
|
34
|
-
guards,
|
|
35
|
-
middlewares,
|
|
36
|
-
meta,
|
|
37
|
-
streamTimeout: typeof stream === 'number' ? stream : undefined,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
export const isProcedure = (value) => Boolean(value?.[kProcedure]);
|
|
41
|
-
//# sourceMappingURL=procedure.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"procedure.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/procedure.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AACnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAA;AAM/B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAqF3C,MAAM,UAAU,oBAAoB,CAIlC,QAA2B,EAC3B,MAMC;IAED,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,IAAK,EAAoB,CAAA;IACjE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAA;IACrD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;IAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;IACpD,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,CAAA;IAE1C,IAAI,OAAO,aAAa,KAAK,WAAW,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;IAC9D,CAAC;IAED,wBAAwB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,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAU,EAAyB,EAAE,CAC/D,OAAO,CAAC,KAAK,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { Callback } from '@nmtjs/common';
|
|
2
|
-
import type { TAnyProcedureContract, TAnyRouterContract, TProcedureContract, TRouteContract, TRouterContract } from '@nmtjs/contract';
|
|
3
|
-
import type { BaseTypeAny, t } from '@nmtjs/type';
|
|
4
|
-
import type { AnyType } from '@nmtjs/type/any';
|
|
5
|
-
import type { AnyGuard } from './guards.ts';
|
|
6
|
-
import type { AnyCompatibleMetaBinding, CompatibleMetaBinding } from './meta.ts';
|
|
7
|
-
import type { AnyMiddleware } from './middlewares.ts';
|
|
8
|
-
import type { AnyProcedure } from './procedure.ts';
|
|
9
|
-
import { kRootRouter, kRouter } from './constants.ts';
|
|
10
|
-
export type RouterMetaBinding<Input> = CompatibleMetaBinding<Input>;
|
|
11
|
-
export type AnyRouterMetaBinding = AnyCompatibleMetaBinding;
|
|
12
|
-
export type AnyRouterRoutes = Record<string, AnyProcedure<any> | AnyRouter>;
|
|
13
|
-
export type AnyRouterContractRoutes = Record<string, TAnyProcedureContract | TAnyRouterContract>;
|
|
14
|
-
export interface AnyRouter {
|
|
15
|
-
contract: TAnyRouterContract;
|
|
16
|
-
routes: AnyRouterRoutes;
|
|
17
|
-
guards: Set<AnyGuard>;
|
|
18
|
-
middlewares: Set<AnyMiddleware>;
|
|
19
|
-
meta: readonly AnyRouterMetaBinding[];
|
|
20
|
-
timeout?: number;
|
|
21
|
-
[kRouter]: any;
|
|
22
|
-
}
|
|
23
|
-
export interface AnyRootRouter extends AnyRouter {
|
|
24
|
-
[kRootRouter]: any;
|
|
25
|
-
contract: TAnyRouterContract<Record<string, TRouteContract>, undefined>;
|
|
26
|
-
default?: AnyProcedure<any>;
|
|
27
|
-
}
|
|
28
|
-
export interface Router<Contract extends TAnyRouterContract> extends AnyRouter {
|
|
29
|
-
contract: Contract;
|
|
30
|
-
routes: {
|
|
31
|
-
[K in keyof Contract['routes']]: Contract['routes'][K] extends TAnyRouterContract ? Router<Contract['routes'][K]> : Contract['routes'][K] extends TAnyProcedureContract ? AnyProcedure<TProcedureContract<Contract['routes'][K]['input'], Contract['routes'][K]['output'], Contract['routes'][K]['stream'], Contract['routes'][K]['name']>> : never;
|
|
32
|
-
};
|
|
33
|
-
guards: Set<AnyGuard>;
|
|
34
|
-
middlewares: Set<AnyMiddleware>;
|
|
35
|
-
meta: readonly AnyRouterMetaBinding[];
|
|
36
|
-
timeout?: number;
|
|
37
|
-
[kRouter]: any;
|
|
38
|
-
}
|
|
39
|
-
export interface RootRouter<Contract extends TAnyRouterContract<Record<string, TRouteContract>, undefined>> extends Router<Contract> {
|
|
40
|
-
[kRootRouter]: any;
|
|
41
|
-
default?: AnyProcedure<any>;
|
|
42
|
-
}
|
|
43
|
-
export type MergeRoutersRoutesContracts<Routers extends readonly TAnyRouterContract[]> = Routers extends [
|
|
44
|
-
infer First extends TAnyRouterContract,
|
|
45
|
-
...infer Rest extends TAnyRouterContract[]
|
|
46
|
-
] ? {
|
|
47
|
-
[K in keyof First['routes']]: First['routes'][K];
|
|
48
|
-
} & MergeRoutersRoutesContracts<Rest> : Routers extends [infer First extends TAnyRouterContract] ? {
|
|
49
|
-
[K in keyof First['routes']]: First['routes'][K];
|
|
50
|
-
} : {};
|
|
51
|
-
export type ExtractRouterContracts<Routers extends readonly {
|
|
52
|
-
contract: TAnyRouterContract;
|
|
53
|
-
}[]> = Routers extends [
|
|
54
|
-
infer First extends {
|
|
55
|
-
contract: TAnyRouterContract;
|
|
56
|
-
},
|
|
57
|
-
...infer Rest extends {
|
|
58
|
-
contract: TAnyRouterContract;
|
|
59
|
-
}[]
|
|
60
|
-
] ? [First['contract'], ...ExtractRouterContracts<Rest>] : [];
|
|
61
|
-
export type RouterContractsFromRoutes<Routes extends AnyRouterRoutes> = {
|
|
62
|
-
[K in keyof Routes]: Routes[K] extends AnyRouter ? Routes[K]['contract'] : Routes[K] extends AnyProcedure<any> ? Routes[K]['contract'] : never;
|
|
63
|
-
};
|
|
64
|
-
export type RouterContractFromRoutes<Routes extends AnyRouterRoutes, Name extends string | undefined = undefined> = TRouterContract<RouterContractsFromRoutes<Routes>, Name>;
|
|
65
|
-
export declare function createRootRouter<Routers extends readonly AnyRouter[]>(routers: Routers, defaultProcedure?: AnyProcedure<TProcedureContract<AnyType, AnyType, true | undefined, string | undefined>>): RootRouter<TRouterContract<MergeRoutersRoutesContracts<ExtractRouterContracts<[...Routers]>>, undefined>>;
|
|
66
|
-
export type FlattenRouterContractInput<Routes extends AnyRouterContractRoutes> = {
|
|
67
|
-
[K in keyof Routes]: Routes[K] extends TAnyRouterContract ? FlattenRouterContractInput<Routes[K]['routes']> : Routes[K] extends TAnyProcedureContract ? Routes[K]['input'] : never;
|
|
68
|
-
}[keyof Routes];
|
|
69
|
-
export type FlattenRouterDecodedInput<Routes extends AnyRouterContractRoutes> = t.infer.decode.output<Extract<FlattenRouterContractInput<Routes>, BaseTypeAny>>;
|
|
70
|
-
export type RouterDecodedInput<Routes extends AnyRouterRoutes> = FlattenRouterDecodedInput<RouterContractsFromRoutes<Routes>>;
|
|
71
|
-
export type RouterContractDecodedInput<Contract extends TAnyRouterContract> = FlattenRouterDecodedInput<Contract['routes']>;
|
|
72
|
-
export interface CreateRouterParams<Routes extends AnyRouterRoutes, Name extends string | undefined = undefined> {
|
|
73
|
-
routes: Routes;
|
|
74
|
-
name?: Name;
|
|
75
|
-
guards?: AnyGuard[];
|
|
76
|
-
middlewares?: AnyMiddleware[];
|
|
77
|
-
meta?: RouterMetaBinding<RouterDecodedInput<Routes>>[];
|
|
78
|
-
hooks?: Record<string, Callback[]>;
|
|
79
|
-
timeout?: number;
|
|
80
|
-
}
|
|
81
|
-
export interface CreateContractRouterParams<Contract extends TAnyRouterContract> {
|
|
82
|
-
routes: {
|
|
83
|
-
[K in keyof Contract['routes']]: Contract['routes'][K] extends TAnyRouterContract ? Router<Contract['routes'][K]> : Contract['routes'][K] extends TAnyProcedureContract ? AnyProcedure<Contract['routes'][K]> : never;
|
|
84
|
-
};
|
|
85
|
-
guards?: AnyGuard[];
|
|
86
|
-
middlewares?: AnyMiddleware[];
|
|
87
|
-
meta?: RouterMetaBinding<RouterContractDecodedInput<Contract>>[];
|
|
88
|
-
timeout?: number;
|
|
89
|
-
}
|
|
90
|
-
export declare function createRouter<const Routes extends AnyRouterRoutes, const Name extends string | undefined = undefined>(params: CreateRouterParams<Routes, Name>): Router<RouterContractFromRoutes<Routes, Name>>;
|
|
91
|
-
export declare function createContractRouter<Contract extends TAnyRouterContract>(contract: Contract, params: CreateContractRouterParams<Contract>): Router<Contract>;
|
|
92
|
-
export declare const isRouter: (value: any) => value is AnyRouter;
|
|
93
|
-
export declare const isRootRouter: (value: any) => value is AnyRootRouter;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { c, IsRouterContract } from '@nmtjs/contract';
|
|
2
|
-
import { assertUniqueMetaBindings } from '@nmtjs/core';
|
|
3
|
-
import { kRootRouter, kRouter } from './constants.js';
|
|
4
|
-
export function createRootRouter(routers, defaultProcedure) {
|
|
5
|
-
const routes = {};
|
|
6
|
-
for (const router of routers)
|
|
7
|
-
Object.assign(routes, router.routes);
|
|
8
|
-
const router = createRouter({ routes, name: undefined });
|
|
9
|
-
return Object.freeze({
|
|
10
|
-
...router,
|
|
11
|
-
default: defaultProcedure,
|
|
12
|
-
[kRootRouter]: true,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
export function createRouter(params) {
|
|
16
|
-
const { routes, name, guards, middlewares, meta, timeout } = params;
|
|
17
|
-
const routesContracts = {};
|
|
18
|
-
for (const [name, route] of Object.entries(routes)) {
|
|
19
|
-
routesContracts[name] = route.contract;
|
|
20
|
-
}
|
|
21
|
-
const contract = c.router({ routes: routesContracts, timeout, name });
|
|
22
|
-
assignRouteContracts(routes, contract);
|
|
23
|
-
return createContractRouter(contract, {
|
|
24
|
-
routes: routes,
|
|
25
|
-
guards,
|
|
26
|
-
middlewares,
|
|
27
|
-
meta,
|
|
28
|
-
timeout,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
export function createContractRouter(contract, params) {
|
|
32
|
-
const guards = new Set(params.guards ?? []);
|
|
33
|
-
const middlewares = new Set(params.middlewares ?? []);
|
|
34
|
-
const meta = Object.freeze([...(params.meta ?? [])]);
|
|
35
|
-
assertUniqueMetaBindings(meta, 'router config');
|
|
36
|
-
return {
|
|
37
|
-
contract,
|
|
38
|
-
routes: params.routes,
|
|
39
|
-
guards,
|
|
40
|
-
middlewares,
|
|
41
|
-
meta,
|
|
42
|
-
timeout: params.timeout,
|
|
43
|
-
[kRouter]: true,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export const isRouter = (value) => Boolean(value?.[kRouter]);
|
|
47
|
-
export const isRootRouter = (value) => Boolean(value?.[kRootRouter]);
|
|
48
|
-
function assignRouteContracts(routes, contract) {
|
|
49
|
-
for (const [key, routeContract] of Object.entries(contract.routes)) {
|
|
50
|
-
routes[key] = { ...routes[key], contract: routeContract };
|
|
51
|
-
if (IsRouterContract(routeContract))
|
|
52
|
-
assignRouteContracts(routes[key].routes, routeContract);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=router.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/router.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,CAAC,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAMtD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAiGrD,MAAM,UAAU,gBAAgB,CAC9B,OAAgB,EAChB,gBAEC;IAOD,MAAM,MAAM,GAAwB,EAA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