@nestia/fetcher 2.0.0-dev.20230908-5 → 2.0.0-dev.20230909

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.
@@ -1,6 +1,35 @@
1
+ import { Primitive } from "./Primitive";
1
2
  /**
2
3
  * Propagation type.
3
4
  *
5
+ * `IPropagation` is a type gathering all possible status codes and their body
6
+ * data types as a discriminated union type. You can specify the status code and
7
+ * its body data type just by using conditional statement like below.
8
+ *
9
+ * ```typescript
10
+ * type Output = IPropagation<{
11
+ * 200: ISeller.IAuthorized;
12
+ * 400: TypeGuardError.IProps;
13
+ * >};
14
+ *
15
+ * const output: Output = await sdk.sellers.authenticate.join(input);
16
+ * if (output.success) {
17
+ * // automatically casted to "ISeller.IAuthorized" type
18
+ * const authorized: ISeller.IAuthorized = output.data;
19
+ * } else if (output.status === 400) {
20
+ * // automatically casted to "TypeGuardError.IProps" type
21
+ * const error: TypeGuardError.IProps = output.data;
22
+ * } else {
23
+ * // unknown type when out of pre-defined status codes
24
+ * const result: unknown = output.data;
25
+ * }
26
+ * ```
27
+ *
28
+ * For reference, this `IPropagation` type is utilized by SDK library generated by
29
+ * `@nestia/sdk`, when you've configured {@link INestiaConfig.propagate} to be `true`.
30
+ * In that case, SDK functions generated by `@nestia/sdk` no more returns response DTO
31
+ * typed data directly, but returns this `IPropagation` typed object instead.
32
+ *
4
33
  * @template StatusMap Map of status code and its body data type.
5
34
  * @template Success Default success status code.
6
35
  * @author Jeongho Nam - https://github.com/samchon
@@ -9,7 +38,7 @@ export type IPropagation<StatusMap extends {
9
38
  [P in IPropagation.Status]?: any;
10
39
  }, Success extends number = 200 | 201> = {
11
40
  [P in keyof StatusMap]: IPropagation.IBranch<P extends Success ? true : false, P, StatusMap[P]>;
12
- }[keyof StatusMap] | IPropagation.IBranch<false, number, any>;
41
+ }[keyof StatusMap] | IPropagation.IBranch<false, unknown, unknown>;
13
42
  export declare namespace IPropagation {
14
43
  /**
15
44
  * Type of configurable status codes.
@@ -29,7 +58,7 @@ export declare namespace IPropagation {
29
58
  export interface IBranch<Success extends boolean, StatusValue, BodyData> {
30
59
  success: Success;
31
60
  status: StatusValue extends "2XX" | "3XX" | "4XX" | "5XX" ? StatusRange<StatusValue> : StatusValue extends number ? StatusValue : never;
32
- data: BodyData;
61
+ data: Primitive<BodyData>;
33
62
  headers: Record<string, string | string[]>;
34
63
  }
35
64
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/fetcher",
3
- "version": "2.0.0-dev.20230908-5",
3
+ "version": "2.0.0-dev.20230909",
4
4
  "description": "Fetcher library of Nestia SDK",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -1,6 +1,36 @@
1
+ import { Primitive } from "./Primitive";
2
+
1
3
  /**
2
4
  * Propagation type.
3
5
  *
6
+ * `IPropagation` is a type gathering all possible status codes and their body
7
+ * data types as a discriminated union type. You can specify the status code and
8
+ * its body data type just by using conditional statement like below.
9
+ *
10
+ * ```typescript
11
+ * type Output = IPropagation<{
12
+ * 200: ISeller.IAuthorized;
13
+ * 400: TypeGuardError.IProps;
14
+ * >};
15
+ *
16
+ * const output: Output = await sdk.sellers.authenticate.join(input);
17
+ * if (output.success) {
18
+ * // automatically casted to "ISeller.IAuthorized" type
19
+ * const authorized: ISeller.IAuthorized = output.data;
20
+ * } else if (output.status === 400) {
21
+ * // automatically casted to "TypeGuardError.IProps" type
22
+ * const error: TypeGuardError.IProps = output.data;
23
+ * } else {
24
+ * // unknown type when out of pre-defined status codes
25
+ * const result: unknown = output.data;
26
+ * }
27
+ * ```
28
+ *
29
+ * For reference, this `IPropagation` type is utilized by SDK library generated by
30
+ * `@nestia/sdk`, when you've configured {@link INestiaConfig.propagate} to be `true`.
31
+ * In that case, SDK functions generated by `@nestia/sdk` no more returns response DTO
32
+ * typed data directly, but returns this `IPropagation` typed object instead.
33
+ *
4
34
  * @template StatusMap Map of status code and its body data type.
5
35
  * @template Success Default success status code.
6
36
  * @author Jeongho Nam - https://github.com/samchon
@@ -18,7 +48,7 @@ export type IPropagation<
18
48
  StatusMap[P]
19
49
  >;
20
50
  }[keyof StatusMap]
21
- | IPropagation.IBranch<false, number, any>;
51
+ | IPropagation.IBranch<false, unknown, unknown>;
22
52
  export namespace IPropagation {
23
53
  /**
24
54
  * Type of configurable status codes.
@@ -43,7 +73,7 @@ export namespace IPropagation {
43
73
  : StatusValue extends number
44
74
  ? StatusValue
45
75
  : never;
46
- data: BodyData;
76
+ data: Primitive<BodyData>;
47
77
  headers: Record<string, string | string[]>;
48
78
  }
49
79