@nestia/fetcher 1.2.2 → 1.3.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/README.md CHANGED
@@ -1,121 +1,60 @@
1
- # Nestia Fetcher
2
- ## Outline
3
- [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/@nestia/fetcher/blob/master/LICENSE)
4
- [![npm version](https://badge.fury.io/js/@nestia/fetcher.svg)](https://www.npmjs.com/package/@nestia/fetcher)
5
- [![Downloads](https://img.shields.io/npm/dm/@nestia/fetcher.svg)](https://www.npmjs.com/package/@nestia/fetcher)
6
- [![Build Status](https://github.com/samchon/@nestia/fetcher/workflows/build/badge.svg)](https://github.com/samchon/@nestia/fetcher/actions?query=workflow%3Abuild)
7
-
8
- ```bash
9
- npm install --save @nestia/fetcher
10
- ```
11
-
12
- `@nestia/fetcher` is a fetcher library of [**Nestia**](https://github.com/samchon/nestia) SDK.
13
-
14
- When you build an SDK (Software Development Kit) library interacting with remote HTTP server through the [`@nestia/sdk`](https://github.com/samchon/nestia), the SDK library would be dependent on this `@nestia/fetcher`. Therefore, if you publish the SDK library on the NPM module, you have to add this `@nestia/fetcher` in the `dependencies` field of the `package.json`.
15
-
16
- Also, if you're a client developer who've installed an SDK library which has been generated by the [`@nestia/sdk`](https://github.com/samchon/nestia), you also need to install this `@nestia/fetcher` module. With the `IConnection` and `HttpError` instances provided by this `@nestia/fetcher`, you can enjoy the SDK library much conveniently.
17
-
18
-
19
-
20
-
21
- ## Example
22
- ### `package.json`
23
- When you build an SDK library who've been generated by the [`@nestia/sdk`](https://github.com/samchon/nestia), you have to add this `@nestia/fetcher` in the `dependencies` field of the `package.json`. If your project had installed the [`@nestia/sdk`](https://github.com/samchon/nestia), you can write the `dependencies`' property by writing the `npx nestia dependencies` command on your console.
24
-
25
- ```json
26
- {
27
- "name": "payments-server-api",
28
- "dependencies": {
29
- "typia": "^3.4.9",
30
- "@nestia/fetcher": "^1.0.0"
31
- }
32
- }
33
- ```
34
-
35
- ### SDK Library
36
- When you open a source file generated by the [`@nestia/sdk`](https://github.com/samchon/nestia), you can find the SDK library is importing this `@nestia/fetcher` module in every `functional` files. Therefore, I repeat that you have to put this `@nestia/fetcher` down into the `dependencies` field of the `package.json`.
37
-
38
- ```typescript
39
- import { Fetcher, IConnection, Primitive } from "@nestia/fetcher";
40
-
41
- /**
42
- * 결제 내역 발행하기.
43
- *
44
- * @param connection connection information
45
- * @param input 결제 내역 입력 정보
46
- * @returns 결제 내역
47
- *
48
- * @nestia Generated by Nestia - https://github.com/samchon/nestia
49
- * @controller PaymentHistoriesController.store()
50
- * @path POST /histories
51
- */
52
- export function store
53
- (
54
- connection: IConnection,
55
- input: Primitive<store.Input>
56
- ): Promise<store.Output>
57
- {
58
- return Fetcher.fetch
59
- (
60
- connection,
61
- store.CONFIG,
62
- store.METHOD,
63
- store.path(),
64
- input
65
- );
66
- }
67
- export namespace store
68
- {
69
- export type Input = Primitive<IPaymentHistory.IStore>;
70
- export type Output = Primitive<IPaymentHistory>;
71
-
72
- export const METHOD = "POST" as const;
73
- export const PATH: string = "/histories";
74
- export const CONFIG: IConnection.IEncrypted = {
75
- input_encrypted: true,
76
- output_encrypted: true,
77
- };
78
-
79
- export function path(): string
80
- {
81
- return `/histories`;
82
- }
83
- }
84
- ```
85
-
86
- ### Utilization Code
87
- After you've published the SDK library and let client developers to install the SDK library, the client developers would import this `@nestia/fetcher` module, too. They would utilize the `IConnection` and `HttpError` instances like below.
88
-
89
- ```typescript
90
- import payments from "payments-server-api";
91
- import { IPaymentHistory } from "payments-server-api/lib/structures/IPaymentHistory";
92
- import { IConnection, HttpError } from "@nestia/fetcher";
93
-
94
- export async function main(): Promise<void>
95
- {
96
- // CONNECTION INFO OF THE REMOTE HTTP SERVER
97
- const connection: IConnection = {
98
- host: "http://payments.somewhere.com",
99
- encryption: {
100
- key: "SqwHmmXm1fZteI3URPtoyBWFJDMQ7FBQ",
101
- iv: "9eSfjygAClnE1JJs"
102
- }
103
- };
104
-
105
- try
106
- {
107
- const input: IPaymentHistory.IStore = { ...SOME_DATA };
108
- const history: IPaymentHistory = await payments.functional.histories.store
109
- (
110
- connection,
111
- input
112
- );
113
- }
114
- catch (exp)
115
- {
116
- // HTTP-ERRROR
117
- if (exp instanceof HttpError)
118
- console.log(exp);
119
- }
120
- }
121
- ```
1
+ # Nestia
2
+ ![Nestia Logo](https://nestia.io/logo.png)
3
+
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/nestia/blob/master/LICENSE)
5
+ [![npm version](https://img.shields.io/npm/v/@nestia/core.svg)](https://www.npmjs.com/package/@nestia/core)
6
+ [![Downloads](https://img.shields.io/npm/dm/nestia.svg)](https://www.npmjs.com/package/nestia)
7
+ [![Build Status](https://github.com/samchon/nestia/workflows/build/badge.svg)](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)
8
+ [![Guide Documents](https://img.shields.io/badge/guide-documents-forestgreen)](https://nestia.io/docs/)
9
+
10
+ Nestia is a set of helper libraries for NestJS, supporting below features:
11
+
12
+ - `@nestia/core`: super-fast decorators
13
+ - `@nestia/sdk`:
14
+ - SDK generator for clients
15
+ - Swagger generator evolved than ever
16
+ - Automatic E2E test functions generator
17
+ - `nestia`: just CLI (command line interface) tool
18
+
19
+ > **Note**
20
+ >
21
+ > - **Only one line** required, with pure TypeScript type
22
+ > - Runtime validator is **20,000x faster** than `class-validator`
23
+ > - JSON serialization is **200x faster** than `class-transformer`
24
+ > - SDK is similar with [tRPC](https://trpc.io), but much advanced
25
+
26
+ ![nestia-sdk-demo](https://user-images.githubusercontent.com/13158709/215004990-368c589d-7101-404e-b81b-fbc936382f05.gif)
27
+
28
+ > Left is server code, and right is client code utilizing SDK
29
+
30
+
31
+
32
+
33
+ ## Sponsors and Backers
34
+ Thanks for your support.
35
+
36
+ Your donation would encourage `nestia` development.
37
+
38
+ [![Backers](https://opencollective.com/nestia/backers.svg?avatarHeight=75&width=600)](https://opencollective.com/nestia)
39
+
40
+
41
+
42
+
43
+ ## Guide Documents
44
+ Check out the document in the [website](https://nestia.io/docs/):
45
+
46
+ ### 🏠 Home
47
+ - [Introduction](https://nestia.io/docs/)
48
+ - [Setup](https://nestia.io/docs/setup/)
49
+
50
+ ### 📖 Features
51
+ - [Pure TypeScript](https://nestia.io/docs/pure)
52
+ - Core Library
53
+ - [TypedRoute](https://nestia.io/docs/core/TypedRoute/)
54
+ - [TypedBody](https://nestia.io/docs/core/TypedBody/)
55
+ - [TypedParam](https://nestia.io/docs/core/TypedParam/)
56
+ - [TypedQuery](https://nestia.io/docs/core/TypedRoute/)
57
+ - Generators
58
+ - [Swagger Documents](https://nestia.io/docs/sdk/swagger/)
59
+ - [SDK Library](https://nestia.io/docs/sdk/sdk/)
60
+ - [E2E Functions](https://nestia.io/docs/sdk/e2e/)
@@ -18,6 +18,21 @@ export interface IConnection {
18
18
  * Host address of the remote HTTP server.
19
19
  */
20
20
  host: string;
21
+ /**
22
+ * Use `typia.random<T>()` function instead.
23
+ *
24
+ * If you configure this property to be `true`, your SDK library does not send
25
+ * any request to remote backend server, but just returns a random data generated
26
+ * by `typia.random<T>()` function.
27
+ *
28
+ * By the way, to utilize this random property, SDK library must be generated with
29
+ * `random` option, too. Open `nestia.config.ts` file, and configure `random: true`
30
+ * property in the top level. Then newly generated SDK library would have a
31
+ * built-in random generator.
32
+ *
33
+ * @default false
34
+ */
35
+ random?: boolean;
21
36
  /**
22
37
  * Header values delivered to the remote HTTP server.
23
38
  */
@@ -34,7 +34,7 @@ type PrimitiveMain<Instance> = ValueOf<Instance> extends object ? Instance exten
34
34
  type PrimitiveObject<Instance extends object> = Instance extends Array<infer T> ? IsTuple<Instance> extends true ? PrimitiveTuple<Instance> : PrimitiveMain<T>[] : {
35
35
  [P in keyof Instance]: Instance[P] extends Function ? never : PrimitiveMain<Instance[P]>;
36
36
  };
37
- type PrimitiveTuple<T extends readonly any[]> = T extends [infer F] ? [PrimitiveMain<F>] : T extends [infer F, ...infer Rest extends readonly any[]] ? [PrimitiveMain<F>, ...PrimitiveTuple<Rest>] : T extends [(infer F)?] ? [PrimitiveMain<F>?] : T extends [(infer F)?, ...infer Rest extends readonly any[]] ? [PrimitiveMain<F>?, ...PrimitiveTuple<Rest>] : [];
37
+ type PrimitiveTuple<T extends readonly any[]> = T extends [] ? [] : T extends [infer F] ? [PrimitiveMain<F>] : T extends [infer F, ...infer Rest extends readonly any[]] ? [PrimitiveMain<F>, ...PrimitiveTuple<Rest>] : T extends [(infer F)?] ? [PrimitiveMain<F>?] : T extends [(infer F)?, ...infer Rest extends readonly any[]] ? [PrimitiveMain<F>?, ...PrimitiveTuple<Rest>] : [];
38
38
  type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true ? boolean : IsValueOf<Instance, Number> extends true ? number : IsValueOf<Instance, String> extends true ? string : Instance;
39
39
  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;
40
40
  type IsTuple<T extends readonly any[] | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/fetcher",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "Fetcher library of Nestia SDK",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "bugs": {
26
26
  "url": "https://github.com/samchon/nestia/issues"
27
27
  },
28
- "homepage": "https://github.com/samchon/nestia",
28
+ "homepage": "https://nestia.io",
29
29
  "devDependencies": {
30
30
  "@types/node": "^18.11.14",
31
31
  "@typescript-eslint/eslint-plugin": "^5.46.1",
@@ -20,6 +20,22 @@ export interface IConnection {
20
20
  */
21
21
  host: string;
22
22
 
23
+ /**
24
+ * Use `typia.random<T>()` function instead.
25
+ *
26
+ * If you configure this property to be `true`, your SDK library does not send
27
+ * any request to remote backend server, but just returns a random data generated
28
+ * by `typia.random<T>()` function.
29
+ *
30
+ * By the way, to utilize this random property, SDK library must be generated with
31
+ * `random` option, too. Open `nestia.config.ts` file, and configure `random: true`
32
+ * property in the top level. Then newly generated SDK library would have a
33
+ * built-in random generator.
34
+ *
35
+ * @default false
36
+ */
37
+ random?: boolean;
38
+
23
39
  /**
24
40
  * Header values delivered to the remote HTTP server.
25
41
  */
package/src/Primitive.ts CHANGED
@@ -58,7 +58,9 @@ type PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
58
58
  : PrimitiveMain<Instance[P]>;
59
59
  };
60
60
 
61
- type PrimitiveTuple<T extends readonly any[]> = T extends [infer F]
61
+ type PrimitiveTuple<T extends readonly any[]> = T extends []
62
+ ? []
63
+ : T extends [infer F]
62
64
  ? [PrimitiveMain<F>]
63
65
  : T extends [infer F, ...infer Rest extends readonly any[]]
64
66
  ? [PrimitiveMain<F>, ...PrimitiveTuple<Rest>]