@navios/core 0.1.6 → 0.1.8

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.
@@ -21,6 +21,7 @@ import { ResolveFastifyRequestType } from 'fastify/types/type-provider.js';
21
21
  import { RouteGenericInterface } from 'fastify';
22
22
  import { ServerResponse } from 'http';
23
23
  import { z } from 'zod';
24
+ import { ZodDiscriminatedUnion } from 'zod';
24
25
  import { ZodOptional } from 'zod';
25
26
  import type { ZodType } from 'zod';
26
27
 
@@ -406,7 +407,7 @@ export { ControllerOptions as ControllerOptions_alias_2 }
406
407
 
407
408
  declare function Endpoint<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType>(endpoint: {
408
409
  config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
409
- }): (target: (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => z.input<ResponseSchema>, context: ClassMethodDecoratorContext) => (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => z.input<ResponseSchema>;
410
+ }): (target: (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => Promise<z.input<ResponseSchema>>, context: ClassMethodDecoratorContext) => (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => Promise<z.input<ResponseSchema>>;
410
411
  export { Endpoint }
411
412
  export { Endpoint as Endpoint_alias_1 }
412
413
  export { Endpoint as Endpoint_alias_2 }
@@ -438,6 +439,13 @@ export { EndpointParams }
438
439
  export { EndpointParams as EndpointParams_alias_1 }
439
440
  export { EndpointParams as EndpointParams_alias_2 }
440
441
 
442
+ declare type EndpointResult<EndpointDeclaration extends {
443
+ config: BaseEndpointConfig<any, any, any, any, any>;
444
+ }> = EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<any, infer Options> ? Promise<z.input<Options[number]>> : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>;
445
+ export { EndpointResult }
446
+ export { EndpointResult as EndpointResult_alias_1 }
447
+ export { EndpointResult as EndpointResult_alias_2 }
448
+
441
449
  declare enum EndpointType {
442
450
  Unknown = "unknown",
443
451
  Config = "config",
@@ -21,6 +21,7 @@ import { ResolveFastifyRequestType } from 'fastify/types/type-provider.js';
21
21
  import { RouteGenericInterface } from 'fastify';
22
22
  import { ServerResponse } from 'http';
23
23
  import { z } from 'zod';
24
+ import { ZodDiscriminatedUnion } from 'zod';
24
25
  import { ZodOptional } from 'zod';
25
26
  import type { ZodType } from 'zod';
26
27
 
@@ -406,7 +407,7 @@ export { ControllerOptions as ControllerOptions_alias_2 }
406
407
 
407
408
  declare function Endpoint<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType>(endpoint: {
408
409
  config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
409
- }): (target: (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => z.input<ResponseSchema>, context: ClassMethodDecoratorContext) => (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => z.input<ResponseSchema>;
410
+ }): (target: (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => Promise<z.input<ResponseSchema>>, context: ClassMethodDecoratorContext) => (params: QuerySchema extends AnyZodObject ? RequestSchema extends ZodType ? EndpointFunctionArgs<Url, QuerySchema, RequestSchema> : EndpointFunctionArgs<Url, QuerySchema, undefined> : RequestSchema extends ZodType ? EndpointFunctionArgs<Url, undefined, RequestSchema> : EndpointFunctionArgs<Url, undefined, undefined>) => Promise<z.input<ResponseSchema>>;
410
411
  export { Endpoint }
411
412
  export { Endpoint as Endpoint_alias_1 }
412
413
  export { Endpoint as Endpoint_alias_2 }
@@ -438,6 +439,13 @@ export { EndpointParams }
438
439
  export { EndpointParams as EndpointParams_alias_1 }
439
440
  export { EndpointParams as EndpointParams_alias_2 }
440
441
 
442
+ declare type EndpointResult<EndpointDeclaration extends {
443
+ config: BaseEndpointConfig<any, any, any, any, any>;
444
+ }> = EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<any, infer Options> ? Promise<z.input<Options[number]>> : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>;
445
+ export { EndpointResult }
446
+ export { EndpointResult as EndpointResult_alias_1 }
447
+ export { EndpointResult as EndpointResult_alias_2 }
448
+
441
449
  declare enum EndpointType {
442
450
  Unknown = "unknown",
443
451
  Config = "config",
package/dist/index.d.mts CHANGED
@@ -14,6 +14,7 @@ export { Controller } from './_tsup-dts-rollup.mjs';
14
14
  export { ControllerOptions } from './_tsup-dts-rollup.mjs';
15
15
  export { Endpoint } from './_tsup-dts-rollup.mjs';
16
16
  export { EndpointParams } from './_tsup-dts-rollup.mjs';
17
+ export { EndpointResult } from './_tsup-dts-rollup.mjs';
17
18
  export { Header } from './_tsup-dts-rollup.mjs';
18
19
  export { HttpCode } from './_tsup-dts-rollup.mjs';
19
20
  export { Module } from './_tsup-dts-rollup.mjs';
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export { Controller } from './_tsup-dts-rollup.js';
14
14
  export { ControllerOptions } from './_tsup-dts-rollup.js';
15
15
  export { Endpoint } from './_tsup-dts-rollup.js';
16
16
  export { EndpointParams } from './_tsup-dts-rollup.js';
17
+ export { EndpointResult } from './_tsup-dts-rollup.js';
17
18
  export { Header } from './_tsup-dts-rollup.js';
18
19
  export { HttpCode } from './_tsup-dts-rollup.js';
19
20
  export { Module } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -1944,6 +1944,7 @@ function Controller({ guards } = {}) {
1944
1944
  }
1945
1945
 
1946
1946
  // packages/core/src/decorators/endpoint.decorator.mts
1947
+ var import_zod4 = require("zod");
1947
1948
  function Endpoint(endpoint) {
1948
1949
  return (target, context) => {
1949
1950
  if (typeof target !== "function") {
package/dist/index.mjs CHANGED
@@ -1815,6 +1815,7 @@ function Controller({ guards } = {}) {
1815
1815
  }
1816
1816
 
1817
1817
  // packages/core/src/decorators/endpoint.decorator.mts
1818
+ import "zod";
1818
1819
  function Endpoint(endpoint) {
1819
1820
  return (target, context) => {
1820
1821
  if (typeof target !== "function") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navios/core",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "author": {
5
5
  "name": "Oleksandr Hanzha",
6
6
  "email": "alex@granted.name"
@@ -36,14 +36,14 @@ describe('Controller decorator', () => {
36
36
  @Controller()
37
37
  class Test {
38
38
  @Endpoint(endpoint)
39
- getBar(params: EndpointParams<typeof endpoint>) {
39
+ async getBar(params: EndpointParams<typeof endpoint>) {
40
40
  return {
41
41
  foo: 'bar',
42
42
  }
43
43
  }
44
44
 
45
45
  @Endpoint(endpoint2)
46
- postBar(params: EndpointParams<typeof endpoint2>) {
46
+ async postBar(params: EndpointParams<typeof endpoint2>) {
47
47
  return {
48
48
  foo: params.data.test,
49
49
  }
@@ -5,6 +5,8 @@ import type {
5
5
  } from '@navios/common'
6
6
  import type { AnyZodObject, z, ZodType } from 'zod'
7
7
 
8
+ import { ZodDiscriminatedUnion } from 'zod'
9
+
8
10
  import { EndpointType, getEndpointMetadata } from '../metadata/index.mjs'
9
11
 
10
12
  export type EndpointParams<
@@ -29,6 +31,18 @@ export type EndpointParams<
29
31
  >
30
32
  : EndpointFunctionArgs<Url, undefined, undefined>
31
33
 
34
+ export type EndpointResult<
35
+ EndpointDeclaration extends {
36
+ config: BaseEndpointConfig<any, any, any, any, any>
37
+ },
38
+ > =
39
+ EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<
40
+ any,
41
+ infer Options
42
+ >
43
+ ? Promise<z.input<Options[number]>>
44
+ : Promise<z.input<EndpointDeclaration['config']['responseSchema']>>
45
+
32
46
  export function Endpoint<
33
47
  Method extends HttpMethod = HttpMethod,
34
48
  Url extends string = string,
@@ -53,7 +67,7 @@ export function Endpoint<
53
67
  : RequestSchema extends ZodType
54
68
  ? EndpointFunctionArgs<Url, undefined, RequestSchema>
55
69
  : EndpointFunctionArgs<Url, undefined, undefined>,
56
- ) => z.input<ResponseSchema>,
70
+ ) => Promise<z.input<ResponseSchema>>,
57
71
  context: ClassMethodDecoratorContext,
58
72
  ) => {
59
73
  if (typeof target !== 'function') {