create-fastify-flux 2.22.0 → 2.22.6

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.
@@ -17,28 +17,28 @@
17
17
  "author": "",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "@fastify/swagger": "8.1.0",
21
- "@fastify/swagger-ui": "^1.1.0",
22
- "@prisma/client": "^4.5.0",
23
- "fastify": "4.9.2",
20
+ "@fastify/swagger": "8.2.1",
21
+ "@fastify/swagger-ui": "^1.3.0",
22
+ "@prisma/client": "^4.8.0",
23
+ "fastify": "4.10.2",
24
24
  "fastify-flux": "*",
25
25
  "source-map-support": "0.5.21",
26
- "tsconfig-paths": "4.1.0"
26
+ "tsconfig-paths": "4.1.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@types/jest": "^29.2.0",
30
- "@types/node": "18.11.6",
31
- "@typescript-eslint/eslint-plugin": "^5.41.0",
32
- "@typescript-eslint/parser": "^5.41.0",
33
- "axios": "^1.1.3",
34
- "esbuild": "^0.15.12",
29
+ "@types/jest": "^29.2.4",
30
+ "@types/node": "18.11.18",
31
+ "@typescript-eslint/eslint-plugin": "^5.47.1",
32
+ "@typescript-eslint/parser": "^5.47.1",
33
+ "axios": "^1.2.2",
34
+ "esbuild": "^0.16.12",
35
35
  "esbuild-jest": "^0.5.0",
36
- "eslint": "^8.26.0",
36
+ "eslint": "^8.30.0",
37
37
  "fastify-flux-cli": "*",
38
- "jest": "^29.2.2",
38
+ "jest": "^29.3.1",
39
39
  "pino-pretty": "^9.1.1",
40
- "prisma": "^4.5.0",
41
- "typescript": "4.8.4"
40
+ "prisma": "^4.8.0",
41
+ "typescript": "4.9.4"
42
42
  },
43
43
  "jest": {
44
44
  "transform": {
@@ -15,7 +15,6 @@ export interface ListTodoQuery {
15
15
 
16
16
  export interface TodoResponse {
17
17
  id: number;
18
-
19
18
  /** @format date-time */
20
19
  createdAt: string;
21
20
  text: string;
@@ -58,10 +57,6 @@ export interface FullRequestParams extends Omit<AxiosRequestConfig, 'data' | 'pa
58
57
  export type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
59
58
 
60
59
  export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, 'data' | 'cancelToken'> {
61
- securityWorker?: (
62
- securityData: SecurityDataType | null,
63
- ) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
64
- secure?: boolean;
65
60
  format?: ResponseType;
66
61
  }
67
62
 
@@ -73,51 +68,14 @@ export enum ContentType {
73
68
 
74
69
  export class HttpClient<SecurityDataType = unknown> {
75
70
  public instance: AxiosInstance;
76
- private securityData: SecurityDataType | null = null;
77
- private securityWorker?: ApiConfig<SecurityDataType>['securityWorker'];
78
- private secure?: boolean;
79
71
  private format?: ResponseType;
80
72
 
81
- constructor({ securityWorker, secure, format, ...axiosConfig }: ApiConfig<SecurityDataType> = {}) {
73
+ constructor({ format, ...axiosConfig }: ApiConfig<SecurityDataType> = {}) {
82
74
  this.instance = axios.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || '' });
83
- this.secure = secure;
84
75
  this.format = format;
85
- this.securityWorker = securityWorker;
86
- }
87
-
88
- public setSecurityData = (data: SecurityDataType | null) => {
89
- this.securityData = data;
90
- };
91
-
92
- private mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig {
93
- return {
94
- ...this.instance.defaults,
95
- ...params1,
96
- ...(params2 || {}),
97
- headers: {
98
- ...(params1.headers || {}),
99
- ...((params2 && params2.headers) || {}),
100
- },
101
- };
102
- }
103
-
104
- private createFormData(input: Record<string, unknown>): FormData {
105
- return Object.keys(input || {}).reduce((formData, key) => {
106
- const property = input[key];
107
- formData.append(
108
- key,
109
- property instanceof Blob
110
- ? property
111
- : typeof property === 'object' && property !== null
112
- ? JSON.stringify(property)
113
- : `${property}`,
114
- );
115
- return formData;
116
- }, new FormData());
117
76
  }
118
77
 
119
78
  public request = async <T = any, _E = any>({
120
- secure,
121
79
  path,
122
80
  type,
123
81
  query,
@@ -125,18 +83,9 @@ export class HttpClient<SecurityDataType = unknown> {
125
83
  body,
126
84
  ...params
127
85
  }: FullRequestParams): Promise<T> => {
128
- const secureParams =
129
- ((typeof secure === 'boolean' ? secure : this.secure) &&
130
- this.securityWorker &&
131
- (await this.securityWorker(this.securityData))) ||
132
- {};
133
- const requestParams = this.mergeRequestParams(params, secureParams);
86
+ const requestParams = params;
134
87
  const responseFormat = (format && this.format) || void 0;
135
88
 
136
- if (type === ContentType.FormData && body && body !== null && typeof body === 'object') {
137
- body = this.createFormData(body as Record<string, unknown>);
138
- }
139
-
140
89
  if (!type) {
141
90
  type = ContentType.Json;
142
91
  }
@@ -151,7 +100,7 @@ export class HttpClient<SecurityDataType = unknown> {
151
100
  headers: {
152
101
  ...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {}),
153
102
  ...(requestParams.headers || {}),
154
- },
103
+ } as any,
155
104
  params: query,
156
105
  responseType: responseFormat,
157
106
  data: body,
@@ -159,8 +108,8 @@ export class HttpClient<SecurityDataType = unknown> {
159
108
  });
160
109
 
161
110
  return result.data;
162
- } catch (err) {
163
- if (axios.isAxiosError(err)) {
111
+ } catch (err: any) /* istanbul ignore next */ {
112
+ if (axios.isAxiosError(err) && err.config) {
164
113
  err.message += ` [${err.config.method}] ${err.config.url}`;
165
114
  if (err.response) {
166
115
  (err as any).data = err.response.data;
@@ -184,8 +133,23 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
184
133
  * @name List
185
134
  * @request GET:/todos
186
135
  */
187
- list: (query?: { includeDone?: boolean }, params: RequestParams = {}) =>
188
- this.request<{ id: number; createdAt: string; text: string; priority: number; done: boolean }[], any>({
136
+ list: (
137
+ query?: {
138
+ includeDone?: boolean;
139
+ },
140
+ params: RequestParams = {},
141
+ ) =>
142
+ this.request<
143
+ {
144
+ id: number;
145
+ /** @format date-time */
146
+ createdAt: string;
147
+ text: string;
148
+ priority: number;
149
+ done: boolean;
150
+ }[],
151
+ any
152
+ >({
189
153
  path: `/todos`,
190
154
  method: 'GET',
191
155
  query: query,
@@ -200,8 +164,24 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
200
164
  * @name Create
201
165
  * @request POST:/todos
202
166
  */
203
- create: (data: { text: string; priority: number }, params: RequestParams = {}) =>
204
- this.request<{ id: number; createdAt: string; text: string; priority: number; done: boolean }, any>({
167
+ create: (
168
+ data: {
169
+ text: string;
170
+ priority: number;
171
+ },
172
+ params: RequestParams = {},
173
+ ) =>
174
+ this.request<
175
+ {
176
+ id: number;
177
+ /** @format date-time */
178
+ createdAt: string;
179
+ text: string;
180
+ priority: number;
181
+ done: boolean;
182
+ },
183
+ any
184
+ >({
205
185
  path: `/todos`,
206
186
  method: 'POST',
207
187
  body: data,
@@ -218,7 +198,17 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
218
198
  * @request GET:/todos/{id}
219
199
  */
220
200
  get: (id: number, params: RequestParams = {}) =>
221
- this.request<{ id: number; createdAt: string; text: string; priority: number; done: boolean }, any>({
201
+ this.request<
202
+ {
203
+ id: number;
204
+ /** @format date-time */
205
+ createdAt: string;
206
+ text: string;
207
+ priority: number;
208
+ done: boolean;
209
+ },
210
+ any
211
+ >({
222
212
  path: `/todos/${id}`,
223
213
  method: 'GET',
224
214
  format: 'json',
@@ -234,10 +224,26 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
234
224
  */
235
225
  update: (
236
226
  id: number,
237
- data: { createdAt?: string; text?: string; priority?: number; done?: boolean },
227
+ data: {
228
+ /** @format date-time */
229
+ createdAt?: string;
230
+ text?: string;
231
+ priority?: number;
232
+ done?: boolean;
233
+ },
238
234
  params: RequestParams = {},
239
235
  ) =>
240
- this.request<{ id: number; createdAt: string; text: string; priority: number; done: boolean }, any>({
236
+ this.request<
237
+ {
238
+ id: number;
239
+ /** @format date-time */
240
+ createdAt: string;
241
+ text: string;
242
+ priority: number;
243
+ done: boolean;
244
+ },
245
+ any
246
+ >({
241
247
  path: `/todos/${id}`,
242
248
  method: 'POST',
243
249
  body: data,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fastify-flux",
3
- "version": "2.22.0",
3
+ "version": "2.22.6",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {
@@ -9,19 +9,19 @@
9
9
  "author": "",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
- "chalk": "^5.1.2",
12
+ "chalk": "^5.2.0",
13
13
  "commander": "^9.4.1",
14
14
  "enquirer": "^2.3.6",
15
- "fs-extra": "^10.1.0",
15
+ "fs-extra": "^11.1.0",
16
16
  "source-map-support": "^0.5.21"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/fs-extra": "^9.0.13",
20
- "@types/jest": "^29.2.0",
21
- "@types/node": "^18.11.6",
22
- "jest": "^29.2.2",
20
+ "@types/jest": "^29.2.4",
21
+ "@types/node": "^18.11.18",
22
+ "jest": "^29.3.1",
23
23
  "ts-jest": "^29.0.3",
24
- "typescript": "4.8.4"
24
+ "typescript": "4.9.4"
25
25
  },
26
26
  "files": [
27
27
  "cli.js",