@open-norantec/herbal 1.0.2-alpha.9 → 1.0.2

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/core.d.ts CHANGED
@@ -1,18 +1,68 @@
1
1
  import 'reflect-metadata';
2
2
  import { HeaderUtil } from '@open-norantec/utilities/dist/header-util.class';
3
3
  import { z } from 'zod';
4
- import { Request } from './types/request.type';
4
+ import { Request, RequestContext } from './types/request.type';
5
+ import 'reflect-metadata';
6
+ import { Request as ExpressRequest } from 'express';
7
+ import { Constructor } from 'type-fest';
8
+ import { AuthAdapter } from './abstracts/auth-adapter.abstract.class';
9
+ import { PathsObject } from 'zod-openapi/dist/openapi3-ts/dist/model/openapi31';
5
10
  export * from '@nestjs/core';
6
- export interface MethodContext<IS extends z.Schema<any>> {
7
- headers: ReturnType<typeof HeaderUtil.parse>;
8
- input: z.infer<IS>;
9
- request: Request;
10
- }
11
11
  export type MethodHandler<IS extends z.Schema<any>, OS extends z.Schema<any>> = (request: Request, input: unknown, headers: ReturnType<typeof HeaderUtil.parse>) => Promise<{
12
12
  request: z.infer<IS>;
13
13
  response: z.infer<OS>;
14
14
  }>;
15
- export declare class HerbalController {
16
- protected registerMethod: <IS extends z.ZodType<any, z.ZodTypeDef, any>, OS extends z.ZodType<any, z.ZodTypeDef, any>>(inputSchema: IS, outputSchema: OS, callback: (context: MethodContext<IS>) => Promise<z.TypeOf<OS>>) => MethodHandler<IS, OS>;
17
- private handler;
15
+ type ClientGroups = Array<string> | null | undefined;
16
+ type ClienttGroupsFactory = (defaultGroupName: string) => ClientGroups;
17
+ export interface MethodRegisterOptions<IS extends z.Schema<any>, OS extends z.Schema<any>> {
18
+ inputSchema: IS;
19
+ outputSchema: OS;
20
+ authAdapters?: Constructor<AuthAdapter>[];
21
+ clientGroups?: ClientGroups | ClienttGroupsFactory;
22
+ disableTransaction?: boolean;
23
+ }
24
+ export type MethodRegisterFn<C> = <IS extends z.Schema<any>, OS extends z.Schema<any>>(name: string, options: MethodRegisterOptions<IS, OS>, callback: MethodCallback<IS, OS, C>) => void;
25
+ export interface MethodContext<IS extends z.Schema<any>> extends RequestContext {
26
+ headers: ReturnType<typeof HeaderUtil.parse>;
27
+ input: z.infer<IS>;
28
+ url: string;
29
+ }
30
+ export type MethodCallContext<IS extends z.Schema<any>> = Omit<MethodContext<IS>, 'input'>;
31
+ export type MethodCallback<IS extends z.Schema<any>, OS extends z.Schema<any>, C> = (this: C, context: MethodContext<IS>) => Promise<z.infer<OS>>;
32
+ declare class MethodConfig<IS extends z.Schema<any>, OS extends z.Schema<any>, C> {
33
+ readonly name: string;
34
+ readonly options: MethodRegisterOptions<IS, OS>;
35
+ protected readonly callback: MethodCallback<IS, OS, C>;
36
+ constructor(name: string, options: MethodRegisterOptions<IS, OS>, callback: MethodCallback<IS, OS, C>);
37
+ call(controller: C, callContext: MethodCallContext<IS>): Promise<z.TypeOf<OS>>;
38
+ }
39
+ declare class MethodPool {
40
+ protected readonly methods: Map<string, MethodConfig<any, any, any>>;
41
+ registerMethod<IS extends z.Schema<any>, OS extends z.Schema<any>, C>(name: string, options: MethodRegisterOptions<IS, OS>, callback: MethodCallback<IS, OS, C>): void;
42
+ transactionDisabled(name: string): boolean | undefined;
43
+ getCallFn(name: string): ((controller: any, callContext: MethodCallContext<any>) => Promise<any>) | null;
44
+ getAuthAdapters(name: string): Constructor<AuthAdapter>[] | null | undefined;
45
+ getOpenAPIPathsObject(group?: string): PathsObject;
46
+ }
47
+ export declare function isHerbalController(target: Function): boolean;
48
+ export declare function getControllerName(target: Function): any;
49
+ export interface HerbalControllerOptions<C> {
50
+ ignoreControllerNamePostfix?: boolean;
51
+ prefix?: string;
52
+ useHeadGuards?: Constructor<any>[];
53
+ useTailGuards?: Constructor<any>[];
54
+ methods?: (register: MethodRegisterFn<C>) => void;
55
+ }
56
+ export interface ControllerUtilCreateOptions {
57
+ prefix?: string;
58
+ useGuards?: Constructor<any>[];
59
+ getTraceId?: (request: ExpressRequest) => string;
60
+ }
61
+ export declare function getMethodPool(targetPrototype: object): MethodPool | null;
62
+ export declare class ControllerUtil {
63
+ static create(createOptions?: ControllerUtilCreateOptions): {
64
+ <C>(options?: HerbalControllerOptions<C> | undefined): ClassDecorator;
65
+ isHerbalController: typeof isHerbalController;
66
+ getControllerName: typeof getControllerName;
67
+ };
18
68
  }