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
|
@@ -1,16 +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<Payload> = (ctx: DependencyContext<any>, call: ApiGuardContext<Payload>) => MaybePromise<boolean>;
|
|
6
|
-
export type GuardParams<Payload, Deps extends Dependencies> = {
|
|
7
|
-
dependencies?: Deps;
|
|
8
|
-
can: GuardCanFn<Payload>;
|
|
9
|
-
} | GuardCanFn<Payload>;
|
|
10
|
-
export interface Guard<Payload, Deps extends Dependencies = Dependencies> extends Dependant<Deps> {
|
|
11
|
-
[kGuard]: true;
|
|
12
|
-
can: GuardCanFn<Payload>;
|
|
13
|
-
}
|
|
14
|
-
export type AnyGuard<Payload = any> = Guard<Payload, any>;
|
|
15
|
-
export declare function createGuard<Deps extends Dependencies = {}>(paramsOrHandler: GuardParams<unknown, Deps>): Guard<unknown, Deps>;
|
|
16
|
-
export declare function createGuardFactory<T>(): <Deps extends Dependencies = {}>(paramsOrHandler: GuardParams<T, Deps>) => Guard<T, Deps>;
|
|
@@ -1,11 +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
|
-
export function createGuardFactory() {
|
|
9
|
-
return createGuard;
|
|
10
|
-
}
|
|
11
|
-
//# 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,eAA2C,EACrB;IACtB,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,CAGzD,CAAA;AAAA,CACF;AAED,MAAM,UAAU,kBAAkB,GAEd;IAClB,OAAO,WAAkB,CAAA;AAAA,CAC1B"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './api.ts';
|
|
2
|
-
export * from './constants.ts';
|
|
3
|
-
export * from './filters.ts';
|
|
4
|
-
export * from './guards.ts';
|
|
5
|
-
export * from './logging.ts';
|
|
6
|
-
export * from './middlewares.ts';
|
|
7
|
-
export * from './procedure.ts';
|
|
8
|
-
export * from './router.ts';
|
|
9
|
-
export * from './types.ts';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './api.js';
|
|
2
|
-
export * from './constants.js';
|
|
3
|
-
export * from './filters.js';
|
|
4
|
-
export * from './guards.js';
|
|
5
|
-
export * from './logging.js';
|
|
6
|
-
export * from './middlewares.js';
|
|
7
|
-
export * from './procedure.js';
|
|
8
|
-
export * from './router.js';
|
|
9
|
-
export * from './types.js';
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { MaybePromise } from '@nmtjs/common';
|
|
2
|
-
export declare const LoggingCallContextMiddleware: (cb?: (options: Readonly<{
|
|
3
|
-
callId: string;
|
|
4
|
-
connection: import("@nmtjs/gateway").GatewayConnection;
|
|
5
|
-
container: import("@nmtjs/core").Container;
|
|
6
|
-
path: import("./router.ts").AnyRouter[];
|
|
7
|
-
procedure: import("./procedure.ts").Procedure<import("@nmtjs/contract").TProcedureContract<import("@nmtjs/type").AnyCompatibleType<any, unknown>, import("@nmtjs/type").BaseTypeAny, true | undefined, string | undefined>, any>;
|
|
8
|
-
}>, payload: unknown) => MaybePromise<object>) => import("./middlewares.ts").Middleware<{}>;
|
|
9
|
-
export declare const LoggingCallMiddleware: (options?: {
|
|
10
|
-
level?: "debug" | "info" | "trace" | undefined;
|
|
11
|
-
errorLevel?: "error" | "fatal" | "warn" | undefined;
|
|
12
|
-
includePayload?: boolean | undefined;
|
|
13
|
-
includeResponse?: boolean | undefined;
|
|
14
|
-
includeStreamChunks?: boolean | undefined;
|
|
15
|
-
}) => import("./middlewares.ts").Middleware<{
|
|
16
|
-
logger: import("@nmtjs/core").FactoryInjectable<import("pino").Logger, {
|
|
17
|
-
logger: import("@nmtjs/core").LazyInjectable<import("pino").Logger, import("@nmtjs/core").Scope.Global>;
|
|
18
|
-
}, import("@nmtjs/core").Scope.Global, import("pino").Logger>;
|
|
19
|
-
}>;
|
|
@@ -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,CAAC;IACpE,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;AAAA,CACF,CAAA;AAED,MAAM,CAAC,MAAM,4BAA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;gBAAA,CACF,CAAA;YACH,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;IAAA,CACF;CACF,CAAC,CAAA"}
|
|
@@ -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,EACZ;IAClB,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;AAAA,CACvB"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { MaybePromise } from '@nmtjs/common';
|
|
2
|
-
import type { TAnyProcedureContract, TProcedureContract } from '@nmtjs/contract';
|
|
3
|
-
import type { Dependant, Dependencies, DependencyContext, Metadata } from '@nmtjs/core';
|
|
4
|
-
import type { InputType } from '@nmtjs/protocol/server';
|
|
5
|
-
import type { BaseType } from '@nmtjs/type';
|
|
6
|
-
import type * as zod from 'zod/mini';
|
|
7
|
-
import { MetadataStore } from '@nmtjs/core';
|
|
8
|
-
import { t } from '@nmtjs/type';
|
|
9
|
-
import type { AnyGuard } from './guards.ts';
|
|
10
|
-
import type { AnyMiddleware } from './middlewares.ts';
|
|
11
|
-
import type { JsonPrimitive } from './types.ts';
|
|
12
|
-
import { kProcedure } from './constants.ts';
|
|
13
|
-
export interface BaseProcedure<ProcedureContract extends TAnyProcedureContract, ProcedureDeps extends Dependencies> extends Dependant<ProcedureDeps> {
|
|
14
|
-
contract: ProcedureContract;
|
|
15
|
-
handler: (...args: any[]) => any;
|
|
16
|
-
metadata: MetadataStore;
|
|
17
|
-
dependencies: ProcedureDeps;
|
|
18
|
-
guards: Set<AnyGuard>;
|
|
19
|
-
middlewares: Set<AnyMiddleware>;
|
|
20
|
-
streamTimeout?: number;
|
|
21
|
-
[kProcedure]: any;
|
|
22
|
-
}
|
|
23
|
-
export type ProcedureHandlerType<Input, Output, Deps extends Dependencies> = (ctx: DependencyContext<Deps>, data: Input) => MaybePromise<Output>;
|
|
24
|
-
export interface Procedure<ProcedureContract extends TAnyProcedureContract, ProcedureDeps extends Dependencies> extends BaseProcedure<ProcedureContract, ProcedureDeps> {
|
|
25
|
-
handler: ProcedureHandlerType<InputType<t.infer.decodeRaw.output<ProcedureContract['input']>>, ProcedureContract['stream'] extends true ? AsyncIterable<t.infer.encode.input<ProcedureContract['output']>> : t.infer.encode.input<ProcedureContract['output']>, ProcedureDeps>;
|
|
26
|
-
}
|
|
27
|
-
export type AnyProcedure<Contract extends TAnyProcedureContract = TAnyProcedureContract> = BaseProcedure<Contract, Dependencies>;
|
|
28
|
-
export type CreateProcedureParams<ProcedureContract extends TAnyProcedureContract, ProcedureDeps extends Dependencies> = {
|
|
29
|
-
dependencies?: ProcedureDeps;
|
|
30
|
-
guards?: AnyGuard<t.infer.decode.output<ProcedureContract['input']>>[];
|
|
31
|
-
middlewares?: AnyMiddleware[];
|
|
32
|
-
metadata?: Metadata[];
|
|
33
|
-
streamTimeout?: number;
|
|
34
|
-
handler: ProcedureHandlerType<InputType<t.infer.decodeRaw.output<ProcedureContract['input']>>, ProcedureContract['stream'] extends undefined ? t.infer.encode.input<ProcedureContract['output']> : AsyncIterable<Exclude<ProcedureContract['stream'], undefined | boolean>>, ProcedureDeps>;
|
|
35
|
-
} | ProcedureHandlerType<InputType<t.infer.decodeRaw.output<ProcedureContract['input']>>, ProcedureContract['stream'] extends undefined ? t.infer.decode.input<ProcedureContract['output']> : AsyncIterable<Exclude<ProcedureContract['stream'], undefined | boolean>>, ProcedureDeps>;
|
|
36
|
-
export declare function _createBaseProcedure<ProcedureContract extends TAnyProcedureContract, ProcedureDeps extends Dependencies>(contract: ProcedureContract, params: {
|
|
37
|
-
dependencies?: ProcedureDeps;
|
|
38
|
-
middlewares?: AnyMiddleware[];
|
|
39
|
-
guards?: AnyGuard[];
|
|
40
|
-
metadata?: Metadata[];
|
|
41
|
-
streamTimeout?: number;
|
|
42
|
-
}): {
|
|
43
|
-
contract: ProcedureContract;
|
|
44
|
-
dependencies: ProcedureDeps;
|
|
45
|
-
middlewares: Set<AnyMiddleware>;
|
|
46
|
-
guards: Set<AnyGuard>;
|
|
47
|
-
metadata: MetadataStore;
|
|
48
|
-
streamTimeout: number | undefined;
|
|
49
|
-
};
|
|
50
|
-
export declare function createContractProcedure<ProcedureContract extends TAnyProcedureContract, ProcedureDeps extends Dependencies>(contract: ProcedureContract, paramsOrHandler: CreateProcedureParams<ProcedureContract, ProcedureDeps>): Procedure<ProcedureContract, ProcedureDeps>;
|
|
51
|
-
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: {
|
|
52
|
-
input?: TInput;
|
|
53
|
-
output?: TOutput;
|
|
54
|
-
/**
|
|
55
|
-
* Whether the procedure is a stream procedure.
|
|
56
|
-
* If set to `true`, the procedure handler should return an `AsyncIterable` of output items.
|
|
57
|
-
* If set to a number, it specifies an explicit stream timeout in milliseconds.
|
|
58
|
-
*/
|
|
59
|
-
stream?: TStream;
|
|
60
|
-
dependencies?: Deps;
|
|
61
|
-
guards?: AnyGuard<TInput extends BaseType ? t.infer.decode.output<TInput> : any>[];
|
|
62
|
-
middlewares?: AnyMiddleware[];
|
|
63
|
-
metadata?: Metadata[];
|
|
64
|
-
timeout?: number;
|
|
65
|
-
handler: ProcedureHandlerType<TInput extends BaseType ? InputType<t.infer.decodeRaw.output<TInput>> : never, TStream extends true | number ? AsyncIterable<TOutput extends BaseType ? t.infer.encode.input<TOutput> : Return> : TOutput extends BaseType ? t.infer.encode.input<TOutput> : Return, Deps>;
|
|
66
|
-
} | ProcedureHandlerType<TInput extends BaseType ? InputType<t.infer.decodeRaw.output<TInput>> : never, 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>;
|
|
67
|
-
export declare const isProcedure: (value: any) => value is AnyProcedure<TAnyProcedureContract>;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { c } from '@nmtjs/contract';
|
|
2
|
-
import { MetadataStore } 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 metadata = new MetadataStore();
|
|
8
|
-
const middlewares = new Set(params.middlewares ?? []);
|
|
9
|
-
const guards = new Set(params.guards ?? []);
|
|
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
|
-
for (const meta of params.metadata ?? []) {
|
|
15
|
-
metadata.set(meta.key, meta.value);
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
contract,
|
|
19
|
-
dependencies,
|
|
20
|
-
middlewares,
|
|
21
|
-
guards,
|
|
22
|
-
metadata,
|
|
23
|
-
streamTimeout,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export function createContractProcedure(contract, paramsOrHandler) {
|
|
27
|
-
const { handler, ...params } = typeof paramsOrHandler === 'function'
|
|
28
|
-
? { handler: paramsOrHandler }
|
|
29
|
-
: paramsOrHandler;
|
|
30
|
-
return Object.assign(_createBaseProcedure(contract, params), {
|
|
31
|
-
handler,
|
|
32
|
-
[kProcedure]: true,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
export function createProcedure(paramsOrHandler) {
|
|
36
|
-
const { input = t.never(), output = t.any(), stream = undefined, dependencies = {}, guards = [], middlewares = [], metadata = [], handler, timeout, } = typeof paramsOrHandler === 'function'
|
|
37
|
-
? { handler: paramsOrHandler }
|
|
38
|
-
: paramsOrHandler;
|
|
39
|
-
// @ts-expect-error
|
|
40
|
-
return createContractProcedure(c.procedure({ input, output, stream, timeout }), {
|
|
41
|
-
dependencies,
|
|
42
|
-
handler: handler,
|
|
43
|
-
guards,
|
|
44
|
-
middlewares,
|
|
45
|
-
metadata,
|
|
46
|
-
streamTimeout: typeof stream === 'number' ? stream : undefined,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
export const isProcedure = (value) => Boolean(value?.[kProcedure]);
|
|
50
|
-
//# sourceMappingURL=procedure.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"procedure.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/procedure.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAA;AAK/B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAoE3C,MAAM,UAAU,oBAAoB,CAIlC,QAA2B,EAC3B,MAMC,EACD;IACA,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,IAAK,EAAoB,CAAA;IACjE,MAAM,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAA;IACpC,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,aAAa,GAAG,MAAM,CAAC,aAAa,CAAA;IAE1C,IAAI,OAAO,aAAa,KAAK,WAAW,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;QAC/D,MAA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C/C;QACE,YAAY;QACZ,OAAO,EAAE,OAAc;QACvB,MAAM;QACN,WAAW;QACX,QAAQ;QACR,aAAa,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;KAC/D,CACF,CAAA;AAAA,CACF;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAU,EAAyB,EAAE,CAC/D,OAAO,CAAC,KAAK,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { Callback } from '@nmtjs/common';
|
|
2
|
-
import type { TAnyProcedureContract, TAnyRouterContract, TProcedureContract, TRouteContract, TRouterContract } from '@nmtjs/contract';
|
|
3
|
-
import type { t } from '@nmtjs/type';
|
|
4
|
-
import type { AnyType } from '@nmtjs/type/any';
|
|
5
|
-
import type { AnyGuard } from './guards.ts';
|
|
6
|
-
import type { AnyMiddleware } from './middlewares.ts';
|
|
7
|
-
import type { AnyProcedure } from './procedure.ts';
|
|
8
|
-
import { kRootRouter, kRouter } from './constants.ts';
|
|
9
|
-
export interface AnyRouter {
|
|
10
|
-
contract: TAnyRouterContract;
|
|
11
|
-
routes: Record<string, AnyProcedure<TAnyProcedureContract> | AnyRouter>;
|
|
12
|
-
guards: Set<AnyGuard<any>>;
|
|
13
|
-
middlewares: Set<AnyMiddleware>;
|
|
14
|
-
timeout?: number;
|
|
15
|
-
[kRouter]: any;
|
|
16
|
-
}
|
|
17
|
-
export interface AnyRootRouter extends AnyRouter {
|
|
18
|
-
[kRootRouter]: any;
|
|
19
|
-
contract: TAnyRouterContract<Record<string, TRouteContract>, undefined>;
|
|
20
|
-
default?: AnyProcedure<any>;
|
|
21
|
-
}
|
|
22
|
-
export interface Router<Contract extends TAnyRouterContract> extends AnyRouter {
|
|
23
|
-
contract: Contract;
|
|
24
|
-
routes: {
|
|
25
|
-
[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;
|
|
26
|
-
};
|
|
27
|
-
guards: Set<AnyGuard<FlattenRouterContractInput<Contract['routes']>>>;
|
|
28
|
-
middlewares: Set<AnyMiddleware>;
|
|
29
|
-
timeout?: number;
|
|
30
|
-
[kRouter]: any;
|
|
31
|
-
}
|
|
32
|
-
export interface RootRouter<Contract extends TAnyRouterContract<Record<string, TRouteContract>, undefined>> extends Router<Contract> {
|
|
33
|
-
[kRootRouter]: any;
|
|
34
|
-
default?: AnyProcedure<any>;
|
|
35
|
-
}
|
|
36
|
-
export type MergeRoutersRoutesContracts<Routers extends readonly TAnyRouterContract[]> = Routers extends [
|
|
37
|
-
infer First extends TAnyRouterContract,
|
|
38
|
-
...infer Rest extends TAnyRouterContract[]
|
|
39
|
-
] ? {
|
|
40
|
-
[K in keyof First['routes']]: First['routes'][K];
|
|
41
|
-
} & MergeRoutersRoutesContracts<Rest> : Routers extends [infer First extends TAnyRouterContract] ? {
|
|
42
|
-
[K in keyof First['routes']]: First['routes'][K];
|
|
43
|
-
} : {};
|
|
44
|
-
export type ExtractRouterContracts<Routers extends readonly {
|
|
45
|
-
contract: TAnyRouterContract;
|
|
46
|
-
}[]> = Routers extends [
|
|
47
|
-
infer First extends {
|
|
48
|
-
contract: TAnyRouterContract;
|
|
49
|
-
},
|
|
50
|
-
...infer Rest extends {
|
|
51
|
-
contract: TAnyRouterContract;
|
|
52
|
-
}[]
|
|
53
|
-
] ? [First['contract'], ...ExtractRouterContracts<Rest>] : [];
|
|
54
|
-
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>>;
|
|
55
|
-
export type FlattenRouterInput<Routes extends Record<string, AnyProcedure<any> | AnyRouter>> = {
|
|
56
|
-
[K in keyof Routes]: Routes[K] extends AnyRouter ? FlattenRouterInput<Routes[K]['routes']> : Routes[K] extends AnyProcedure ? Routes[K]['contract']['input'] : never;
|
|
57
|
-
}[keyof Routes];
|
|
58
|
-
export type FlattenRouterContractInput<Routes extends Record<string, TAnyProcedureContract | TAnyRouterContract>> = {
|
|
59
|
-
[K in keyof Routes]: Routes[K] extends TAnyRouterContract ? FlattenRouterContractInput<Routes[K]['routes']> : Routes[K] extends TAnyProcedureContract ? Routes[K]['input'] : never;
|
|
60
|
-
}[keyof Routes];
|
|
61
|
-
export declare function createRouter<const Routes extends Record<string, AnyProcedure<any> | AnyRouter>, const Options extends {
|
|
62
|
-
routes: Routes;
|
|
63
|
-
name?: string;
|
|
64
|
-
guards?: AnyGuard<t.infer.decode.output<FlattenRouterInput<Options['routes']>>>[];
|
|
65
|
-
middlewares?: AnyMiddleware[];
|
|
66
|
-
hooks?: Record<string, Callback[]>;
|
|
67
|
-
timeout?: number;
|
|
68
|
-
}>(params: Options): Router<TRouterContract<Options['routes'] extends Record<string, AnyProcedure<any> | AnyRouter> ? {
|
|
69
|
-
[K in keyof Options['routes']]: Options['routes'][K] extends AnyRouter ? Options['routes'][K]['contract'] : Options['routes'][K] extends AnyProcedure<any> ? Options['routes'][K]['contract'] : never;
|
|
70
|
-
} : {}, null extends Options['name'] ? undefined : Options['name']>>;
|
|
71
|
-
export declare function createContractRouter<Contract extends TAnyRouterContract>(contract: Contract, params: {
|
|
72
|
-
routes: {
|
|
73
|
-
[K in keyof Contract['routes']]: Contract['routes'][K] extends TAnyRouterContract ? Router<Contract['routes'][K]> : Contract['routes'][K] extends TAnyProcedureContract ? AnyProcedure<Contract['routes'][K]> : never;
|
|
74
|
-
};
|
|
75
|
-
guards?: AnyGuard<FlattenRouterContractInput<Contract['routes']>>[];
|
|
76
|
-
middlewares?: AnyMiddleware[];
|
|
77
|
-
timeout?: number;
|
|
78
|
-
}): Router<Contract>;
|
|
79
|
-
export declare const isRouter: (value: any) => value is AnyRouter;
|
|
80
|
-
export declare const isRootRouter: (value: any) => value is AnyRootRouter;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { c, IsRouterContract } from '@nmtjs/contract';
|
|
2
|
-
import { kRootRouter, kRouter } from './constants.js';
|
|
3
|
-
export function createRootRouter(routers, defaultProcedure) {
|
|
4
|
-
const routes = {};
|
|
5
|
-
for (const router of routers)
|
|
6
|
-
Object.assign(routes, router.routes);
|
|
7
|
-
const router = createRouter({ routes, name: undefined });
|
|
8
|
-
return Object.freeze({
|
|
9
|
-
...router,
|
|
10
|
-
default: defaultProcedure,
|
|
11
|
-
[kRootRouter]: true,
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export function createRouter(params) {
|
|
15
|
-
const { routes, name, guards, middlewares, timeout } = params;
|
|
16
|
-
const routesContracts = {};
|
|
17
|
-
for (const [name, route] of Object.entries(routes)) {
|
|
18
|
-
routesContracts[name] = route.contract;
|
|
19
|
-
}
|
|
20
|
-
const contract = c.router({ routes: routesContracts, timeout, name });
|
|
21
|
-
assignRouteContracts(routes, contract);
|
|
22
|
-
return createContractRouter(contract, {
|
|
23
|
-
routes: routes,
|
|
24
|
-
guards,
|
|
25
|
-
middlewares,
|
|
26
|
-
timeout,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
export function createContractRouter(contract, params) {
|
|
30
|
-
const guards = new Set(params.guards ?? []);
|
|
31
|
-
const middlewares = new Set(params.middlewares ?? []);
|
|
32
|
-
return {
|
|
33
|
-
contract,
|
|
34
|
-
routes: params.routes,
|
|
35
|
-
guards,
|
|
36
|
-
middlewares,
|
|
37
|
-
timeout: params.timeout,
|
|
38
|
-
[kRouter]: true,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export const isRouter = (value) => Boolean(value?.[kRouter]);
|
|
42
|
-
export const isRootRouter = (value) => Boolean(value?.[kRootRouter]);
|
|
43
|
-
function assignRouteContracts(routes, contract) {
|
|
44
|
-
for (const [key, routeContract] of Object.entries(contract.routes)) {
|
|
45
|
-
routes[key] = { ...routes[key], contract: routeContract };
|
|
46
|
-
if (IsRouterContract(routeContract))
|
|
47
|
-
assignRouteContracts(routes[key].routes, routeContract);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
//# 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;AAKrD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAyErD,MAAM,UAAU,gBAAgB,CAC9B,OAAgB,EAChB,gBAEC,EAMD;IACA,MAAM,MAAM,GAAwB,EAAE,CAAA;IACtC,KAAK,MAAM,MAAM,IAAI,OAAO;QAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IAClE,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;IACxD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,GAAG,MAAM;QACT,OAAO,EAAE,gBAAgB;QACzB,CAAC,WAAW,CAAC,EAAE,IAAI;KACpB,CAAQ,CAAA;AAAA,CACV;AAsBD,MAAM,UAAU,YAAY,CAa1B,MAAe,EAcf;IACA,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAE7D,MAAM,eAAe,GAAQ,EAAE,CAAA;IAC/B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,eAAe,CA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AAG,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAA;QACzD,IAAI,gBAAgB,CAAC,aAAa,CAAC;YACjC,oBAAoB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3D,CAAC;AAAA,CACF"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { TProcedureContract } from '@nmtjs/contract';
|
|
2
|
-
import type { Container } from '@nmtjs/core';
|
|
3
|
-
import type { GatewayConnection } from '@nmtjs/gateway';
|
|
4
|
-
import type { AnyCompatibleType, BaseTypeAny } from '@nmtjs/type';
|
|
5
|
-
import type { Procedure } from './procedure.ts';
|
|
6
|
-
import type { AnyRouter } from './router.ts';
|
|
7
|
-
export type ApiCallContext<Payload = unknown> = Readonly<{
|
|
8
|
-
callId: string;
|
|
9
|
-
connection: GatewayConnection;
|
|
10
|
-
container: Container;
|
|
11
|
-
path: AnyRouter[];
|
|
12
|
-
procedure: Procedure<TProcedureContract<AnyCompatibleType<any, Payload>, BaseTypeAny, true | undefined, string | undefined>, any>;
|
|
13
|
-
}>;
|
|
14
|
-
export type ApiGuardContext<Payload = unknown> = ApiCallContext<Payload> & Readonly<{
|
|
15
|
-
payload: Payload;
|
|
16
|
-
}>;
|
|
17
|
-
export type JsonPrimitive<T> = Equal<T, JsonPrimitiveMain<T>> extends true ? T : JsonPrimitiveMain<T>;
|
|
18
|
-
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
19
|
-
type JsonPrimitiveMain<Instance, InArray extends boolean = false> = Instance extends [never] ? never : ValueOf<Instance> extends bigint ? never : ValueOf<Instance> extends boolean | number | string ? ValueOf<Instance> : Instance extends Function ? InArray extends true ? null : never : ValueOf<Instance> extends object ? Instance extends object ? Instance extends NativeClass ? {} : Instance extends IJsonable<infer Raw> ? ValueOf<Raw> extends object ? Raw extends object ? PrimitiveObject<Raw> : never : ValueOf<Raw> : PrimitiveObject<Instance> : never : ValueOf<Instance>;
|
|
20
|
-
type PrimitiveObject<Instance extends object> = Instance extends Array<infer T> ? IsTuple<Instance> extends true ? PrimitiveTuple<Instance> : JsonPrimitiveMain<T, true>[] : {
|
|
21
|
-
-readonly [P in keyof Instance as JsonPrimitiveMain<Instance[P]> extends never ? never : P]: JsonPrimitiveMain<Instance[P]>;
|
|
22
|
-
};
|
|
23
|
-
type PrimitiveTuple<T extends readonly any[]> = T extends [] ? [] : T extends [infer F] ? [JsonPrimitiveMain<F, true>] : T extends [infer F, ...infer Rest extends readonly any[]] ? [JsonPrimitiveMain<F, true>, ...PrimitiveTuple<Rest>] : T extends [(infer F)?] ? [JsonPrimitiveMain<F, true>?] : T extends [(infer F)?, ...infer Rest extends readonly any[]] ? [JsonPrimitiveMain<F, true>?, ...PrimitiveTuple<Rest>] : [];
|
|
24
|
-
type ValueOf<Instance> = IsValueOf<Instance, boolean> extends true ? boolean : IsValueOf<Instance, number> extends true ? number : IsValueOf<Instance, string> extends true ? string : Instance;
|
|
25
|
-
type NativeClass = Set<any> | Map<any, any> | WeakSet<any> | WeakMap<any, any> | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | BigUint64Array | Int8Array | Int16Array | Int32Array | BigInt64Array | Float32Array | Float64Array | ArrayBuffer | SharedArrayBuffer | DataView;
|
|
26
|
-
type IsTuple<T extends readonly any[] | {
|
|
27
|
-
length: number;
|
|
28
|
-
}> = [T] extends [
|
|
29
|
-
never
|
|
30
|
-
] ? false : T extends readonly any[] ? number extends T['length'] ? false : true : false;
|
|
31
|
-
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object ? Object extends IValueOf<infer U> ? Instance extends U ? false : true : false : false;
|
|
32
|
-
interface IValueOf<T> {
|
|
33
|
-
valueOf(): T;
|
|
34
|
-
}
|
|
35
|
-
interface IJsonable<T> {
|
|
36
|
-
toJSON(): T;
|
|
37
|
-
}
|
|
38
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/runtime/application/api/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ConnectionIdentity, Transport } from '@nmtjs/gateway';
|
|
2
|
-
import type { LifecycleHooks } from '../hooks.ts';
|
|
3
|
-
import type { RuntimePlugin } from '../plugin.ts';
|
|
4
|
-
import type { ApiOptions } from './api/api.ts';
|
|
5
|
-
import type { AnyFilter } from './api/filters.ts';
|
|
6
|
-
import type { AnyGuard } from './api/guards.ts';
|
|
7
|
-
import type { AnyMiddleware } from './api/middlewares.ts';
|
|
8
|
-
import type { AnyRootRouter } from './api/router.ts';
|
|
9
|
-
import type { AnyHook } from './hook.ts';
|
|
10
|
-
import { kApplicationConfig } from './constants.ts';
|
|
11
|
-
export type AnyApplicationConfig = ApplicationConfig<AnyRootRouter>;
|
|
12
|
-
export interface ApplicationConfig<Router extends AnyRootRouter = AnyRootRouter, Transports extends Record<string, Transport> = Record<string, Transport>> {
|
|
13
|
-
[kApplicationConfig]: any;
|
|
14
|
-
router: Router;
|
|
15
|
-
api: Pick<ApiOptions, 'timeout'>;
|
|
16
|
-
transports: Transports;
|
|
17
|
-
identity?: ConnectionIdentity;
|
|
18
|
-
plugins: RuntimePlugin[];
|
|
19
|
-
filters: AnyFilter[];
|
|
20
|
-
middlewares: AnyMiddleware[];
|
|
21
|
-
guards: AnyGuard<unknown>[];
|
|
22
|
-
hooks: AnyHook[];
|
|
23
|
-
lifecycleHooks: LifecycleHooks['_']['config'];
|
|
24
|
-
}
|
|
25
|
-
export declare function defineApplication<R extends AnyRootRouter, T extends Record<string, Transport> = Record<string, Transport>>(options: Pick<ApplicationConfig<R, T>, 'router'> & Partial<Omit<ApplicationConfig<R, T>, 'router'>>): ApplicationConfig<R, T>;
|
|
26
|
-
export declare function isApplicationConfig(value: any): value is ApplicationConfig;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { kApplicationConfig } from './constants.js';
|
|
2
|
-
export function defineApplication(options) {
|
|
3
|
-
const { router, transports = {}, guards = [], middlewares = [], plugins = [], api = {}, filters = [], hooks = [], lifecycleHooks = {}, identity: identityResolver, } = options;
|
|
4
|
-
return Object.freeze({
|
|
5
|
-
[kApplicationConfig]: true,
|
|
6
|
-
router,
|
|
7
|
-
transports,
|
|
8
|
-
api,
|
|
9
|
-
filters,
|
|
10
|
-
plugins,
|
|
11
|
-
guards,
|
|
12
|
-
middlewares,
|
|
13
|
-
hooks,
|
|
14
|
-
lifecycleHooks,
|
|
15
|
-
identity: identityResolver,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
export function isApplicationConfig(value) {
|
|
19
|
-
return Boolean(value?.[kApplicationConfig]);
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/runtime/application/config.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAqBnD,MAAM,UAAU,iBAAiB,CAI/B,OACkD,EAClD;IACA,MAAM,EACJ,MAAM,EACN,UAAU,GAAG,EAAE,EACf,MAAM,GAAG,EAAE,EACX,WAAW,GAAG,EAAE,EAChB,OAAO,GAAG,EAAE,EACZ,GAAG,GAAG,EAA8B,EACpC,OAAO,GAAG,EAAkC,EAC5C,KAAK,GAAG,EAAgC,EACxC,cAAc,GAAG,EAAE,EACnB,QAAQ,EAAE,gBAAgB,GAC3B,GAAG,OAAO,CAAA;IAEX,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,CAAC,kBAAkB,CAAC,EAAE,IAAI;QAC1B,MAAM;QACN,UAAU;QACV,GAAG;QACH,OAAO;QACP,OAAO;QACP,MAAM;QACN,WAAW;QACX,KAAK;QACL,cAAc;QACd,QAAQ,EAAE,gBAAgB;KACI,CAA4B,CAAA;AAAA,CAC7D;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAU,EAA8B;IAC1E,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAA;AAAA,CAC5C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/runtime/application/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAkB,MAAM,CAAC,GAAG,CACzD,2BAA2B,CAC5B,CAAA"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { MaybePromise } from '@nmtjs/common';
|
|
2
|
-
import type { Dependant, Dependencies, DependencyContext, HookTypes } from '@nmtjs/core';
|
|
3
|
-
import { kHook } from '@nmtjs/core';
|
|
4
|
-
export type AnyHook = Hook<HookTypes, string, any>;
|
|
5
|
-
export interface Hook<T extends HookTypes = HookTypes, H extends string = string, Deps extends Dependencies = {}> extends Dependant<Deps> {
|
|
6
|
-
[kHook]: any;
|
|
7
|
-
name: H;
|
|
8
|
-
handler: (ctx: DependencyContext<Deps>, ...args: H extends keyof T ? Parameters<T[H]> : unknown[]) => MaybePromise<any>;
|
|
9
|
-
}
|
|
10
|
-
export declare function createHook<Types extends HookTypes = HookTypes, Name extends Extract<keyof Types, string> | (object & string) = object & string, Deps extends Dependencies = {}>(params: {
|
|
11
|
-
name: Name;
|
|
12
|
-
dependencies?: Deps;
|
|
13
|
-
handler: Hook<Types, Name, Deps>['handler'];
|
|
14
|
-
}): Hook<Types, Name, Deps>;
|
|
15
|
-
export declare function createApplicationHookFactory<Types extends HookTypes>(): <Name extends Extract<keyof Types, string> = never, Deps extends Dependencies = {}>(params: {
|
|
16
|
-
name: Name;
|
|
17
|
-
dependencies?: Deps | undefined;
|
|
18
|
-
handler: (ctx: DependencyContext<Deps>, ...args: Name extends keyof Types ? Parameters<Types[Name]> : unknown[]) => any;
|
|
19
|
-
}) => Hook<Types, Name, Deps>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { kHook } from '@nmtjs/core';
|
|
2
|
-
export function createHook(params) {
|
|
3
|
-
const { name, handler, dependencies = {} } = params;
|
|
4
|
-
return Object.freeze({ [kHook]: true, name, handler, dependencies });
|
|
5
|
-
}
|
|
6
|
-
export function createApplicationHookFactory() {
|
|
7
|
-
return (params) => {
|
|
8
|
-
return createHook(params);
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=hook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../../src/runtime/application/hook.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAiBnC,MAAM,UAAU,UAAU,CAKxB,MAID,EAA2B;IAC1B,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,GAAG,EAAU,EAAE,GAAG,MAAM,CAAA;IAC3D,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,CAAQ,CAAA;AAAA,CAC5E;AAED,MAAM,UAAU,4BAA4B,GAA4B;IACtE,OAAO,CAIL,MAID,EAA2B,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAoB,MAAM,CAAC,CAAA;IAAA,CAC7C,CAAA;AAAA,CACF"}
|