create-fastify-flux 2.19.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2021 Jakob Niggel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/cli.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require('path');
4
+ const { version } = require(path.join(__dirname, 'package.json'));
5
+ process.env.version = version;
6
+
7
+ require('source-map-support/register');
8
+ require('./dist/index');
package/dist/action.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.actionHandler = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ async function updatePackageJson(file, options) {
10
+ const content = await fs_extra_1.default.readJSON(file);
11
+ if (options.name) {
12
+ content.name = options.name;
13
+ }
14
+ const version = process.env.version;
15
+ content.dependencies['@fluxapi/common'] = version;
16
+ content.dependencies['@fluxapi/plugins'] = version;
17
+ content.devDependencies['@fluxapi/cli'] = version;
18
+ await fs_extra_1.default.writeJSON(file, content, { spaces: 2 });
19
+ }
20
+ async function actionHandler(options) {
21
+ let source = path_1.default.join(__dirname, `/template-${options.template}/`);
22
+ if (!(await fs_extra_1.default.pathExists(source))) {
23
+ source = path_1.default.join(__dirname, `/../../../playground/template-${options.template}/`);
24
+ }
25
+ const target = path_1.default.join(process.cwd(), options.name);
26
+ await fs_extra_1.default.copy(source, target, {
27
+ recursive: true,
28
+ });
29
+ await updatePackageJson(path_1.default.join(target, 'package.json'), options);
30
+ console.log(`
31
+ Creating project in ${target}...
32
+
33
+ Done. Now run:
34
+
35
+ cd ${options.name}
36
+ npm install
37
+ npm run prisma migrate deploy
38
+ npm run dev
39
+ `);
40
+ }
41
+ exports.actionHandler = actionHandler;
42
+ //# sourceMappingURL=action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.js","sourceRoot":"","sources":["../src/action.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,wDAA0B;AAE1B,KAAK,UAAU,iBAAiB,CAAC,IAAY,EAAE,OAAyB;IACtE,MAAM,OAAO,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAExC,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;KAC7B;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IACpC,OAAO,CAAC,YAAY,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC;IAClD,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC;IACnD,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC;IAElD,MAAM,kBAAE,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;AACnD,CAAC;AAEM,KAAK,UAAU,aAAa,CAAC,OAGnC;IACC,IAAI,MAAM,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACpE,IAAI,CAAC,CAAC,MAAM,kBAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE;QAClC,MAAM,GAAG,cAAI,CAAC,IAAI,CAChB,SAAS,EACT,iCAAiC,OAAO,CAAC,QAAQ,GAAG,CACrD,CAAC;KACH;IAED,MAAM,MAAM,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,MAAM,kBAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE;QAC5B,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;IAEH,MAAM,iBAAiB,CAAC,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC;IAEpE,OAAO,CAAC,GAAG,CAAC;sBACQ,MAAM;;;;OAIrB,OAAO,CAAC,IAAI;;;;CAIlB,CAAC,CAAC;AACH,CAAC;AA7BD,sCA6BC"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const enquirer_1 = __importDefault(require("enquirer"));
7
+ const action_1 = require("./action");
8
+ (async () => {
9
+ const enquirer = new enquirer_1.default();
10
+ const response = await enquirer.prompt([
11
+ {
12
+ type: 'input',
13
+ name: 'name',
14
+ message: 'What is the name of your project?',
15
+ },
16
+ {
17
+ type: 'select',
18
+ name: 'template',
19
+ message: 'Which template should be used?',
20
+ choices: ['prisma'],
21
+ },
22
+ ]);
23
+ await (0, action_1.actionHandler)(response);
24
+ })();
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,wDAAgC;AAChC,qCAAyC;AAEzC,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,QAAQ,GAAG,IAAI,kBAAQ,EAAsC,CAAC;IACpE,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;QACrC;YACE,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,mCAAmC;SAC7C;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,gCAAgC;YACzC,OAAO,EAAE,CAAC,QAAQ,CAAC;SACpB;KACF,CAAC,CAAC;IAEH,MAAM,IAAA,sBAAa,EAAC,QAAQ,CAAC,CAAC;AAChC,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1,26 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ project: 'tsconfig.json',
5
+ sourceType: 'module',
6
+ },
7
+ plugins: ['@typescript-eslint/eslint-plugin'],
8
+ extends: ['plugin:@typescript-eslint/recommended'],
9
+ root: true,
10
+ env: {
11
+ node: true,
12
+ jest: true,
13
+ },
14
+ ignorePatterns: ['.eslintrc.js'],
15
+ rules: {
16
+ '@typescript-eslint/interface-name-prefix': 'off',
17
+ '@typescript-eslint/explicit-function-return-type': 'off',
18
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
19
+ '@typescript-eslint/no-explicit-any': 'off',
20
+ '@typescript-eslint/no-empty-interface': 'off',
21
+ '@typescript-eslint/no-unused-vars': [
22
+ 1,
23
+ { argsIgnorePattern: 'reply|request' },
24
+ ],
25
+ },
26
+ };
@@ -0,0 +1,5 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "printWidth": 120
5
+ }
@@ -0,0 +1,17 @@
1
+ /** @type {import('@fluxapi/cli').FluxCliConfig} */
2
+ const config = {
3
+ entry: './src/',
4
+ outdir: './dist/',
5
+ tasks: [
6
+ {
7
+ run: ['node', 'server.js'],
8
+ sdk: {
9
+ name: 'GeneratedApi.ts',
10
+ output: './tests-e2e/api/',
11
+ moduleNameIndex: 0,
12
+ },
13
+ },
14
+ ],
15
+ };
16
+
17
+ module.exports = config;
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "standard",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "private": true,
6
+ "scripts": {
7
+ "start": "node server.js",
8
+ "build": "flux build --typecheck",
9
+ "dev": "flux start --watch --sdk",
10
+ "dev:typecheck": "flux start --watch --typecheck",
11
+ "debug": "flux start --watch --sdk --debug",
12
+ "sdk": "flux sdk",
13
+ "jest": "jest",
14
+ "lint": "eslint src/",
15
+ "prisma": "prisma"
16
+ },
17
+ "author": "",
18
+ "license": "ISC",
19
+ "dependencies": {
20
+ "@fluxapi/common": "*",
21
+ "@fluxapi/plugins": "*",
22
+ "@prisma/client": "^4.1.0",
23
+ "fastify": "4.2.1",
24
+ "fastify-swagger": "5.2.0",
25
+ "source-map-support": "0.5.21",
26
+ "tsconfig-paths": "4.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@fluxapi/cli": "*",
30
+ "@types/jest": "^28.1.6",
31
+ "@types/node": "18.0.6",
32
+ "@typescript-eslint/eslint-plugin": "^5.30.7",
33
+ "@typescript-eslint/parser": "^5.30.7",
34
+ "axios": "^0.27.2",
35
+ "esbuild": "^0.14.49",
36
+ "esbuild-jest": "^0.5.0",
37
+ "eslint": "^8.20.0",
38
+ "jest": "^28.1.3",
39
+ "pino-pretty": "^8.1.0",
40
+ "prisma": "^4.1.0",
41
+ "typescript": "4.7.4"
42
+ },
43
+ "jest": {
44
+ "transform": {
45
+ "^.+\\.tsx?$": "esbuild-jest"
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,8 @@
1
+ -- CreateTable
2
+ CREATE TABLE "todos" (
3
+ "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
4
+ "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
5
+ "text" TEXT NOT NULL,
6
+ "priority" INTEGER NOT NULL,
7
+ "done" BOOLEAN NOT NULL DEFAULT false
8
+ );
@@ -0,0 +1,3 @@
1
+ # Please do not edit this file manually
2
+ # It should be added in your version-control system (i.e. Git)
3
+ provider = "sqlite"
@@ -0,0 +1,19 @@
1
+ // This is your Prisma schema file,
2
+ // learn more about it in the docs: https://pris.ly/d/prisma-schema
3
+
4
+ generator client {
5
+ provider = "prisma-client-js"
6
+ }
7
+
8
+ datasource db {
9
+ provider = "sqlite"
10
+ url = "file:./dev.db"
11
+ }
12
+
13
+ model todos {
14
+ id Int @id @default(autoincrement())
15
+ createdAt DateTime @default(now())
16
+ text String
17
+ priority Int
18
+ done Boolean @default(false)
19
+ }
@@ -0,0 +1,15 @@
1
+ require('source-map-support/register');
2
+ require('tsconfig-paths').register({
3
+ baseUrl: '.',
4
+ paths: {
5
+ '~/*': ['./dist/*'],
6
+ },
7
+ });
8
+ const fs = require('fs');
9
+
10
+ if (!fs.existsSync('./dist/index.js')) {
11
+ console.error('Please run npm run build first.');
12
+ process.exit(1);
13
+ }
14
+
15
+ require('./dist/index');
@@ -0,0 +1,57 @@
1
+ import { Controller, Delete, Get, Post, Status } from '@fluxapi/common';
2
+ import { CreateTodo, ListTodoQuery, TodoResponse, UpdateTodo } from './Todo.schema';
3
+ import { HttpException } from '~/helper/exceptions';
4
+ import { PrismaClient } from '@prisma/client';
5
+
6
+ const prisma = new PrismaClient();
7
+
8
+ @Controller('/todos', { tags: ['todos'] })
9
+ export class TodoController {
10
+ @Get()
11
+ async list(query: ListTodoQuery): Promise<TodoResponse[]> {
12
+ const done = query.includeDone ? undefined : false;
13
+
14
+ return prisma.todos.findMany({ where: { done } });
15
+ }
16
+
17
+ @Post()
18
+ async create(body: CreateTodo): Promise<TodoResponse> {
19
+ const result = await prisma.todos.create({ data: body });
20
+
21
+ return result;
22
+ }
23
+
24
+ @Get('/:id')
25
+ async get(id: number): Promise<TodoResponse> {
26
+ const found = await prisma.todos.findUnique({ where: { id } });
27
+
28
+ if (!found) {
29
+ throw new HttpException(404, 'todo not found');
30
+ }
31
+
32
+ return found;
33
+ }
34
+
35
+ @Post('/:id')
36
+ async update(id: number, body: UpdateTodo): Promise<TodoResponse> {
37
+ const found = await prisma.todos.findUnique({ where: { id } });
38
+
39
+ if (!found) {
40
+ throw new HttpException(404, 'todo not found');
41
+ }
42
+
43
+ return prisma.todos.update({ where: { id }, data: body });
44
+ }
45
+
46
+ @Delete('/:id')
47
+ @Status(204)
48
+ async remove(id: number): Promise<void> {
49
+ const found = await prisma.todos.findUnique({ where: { id } });
50
+
51
+ if (!found) {
52
+ throw new HttpException(404, 'todo not found');
53
+ }
54
+
55
+ await prisma.todos.delete({ where: { id } });
56
+ }
57
+ }
@@ -0,0 +1,11 @@
1
+ import { todos } from '@prisma/client';
2
+
3
+ export interface TodoResponse extends todos {}
4
+
5
+ export interface CreateTodo extends Omit<TodoResponse, 'id' | 'done' | 'createdAt'> {}
6
+
7
+ export interface UpdateTodo extends Partial<Omit<TodoResponse, 'id'>> {}
8
+
9
+ export interface ListTodoQuery {
10
+ includeDone?: boolean;
11
+ }
@@ -0,0 +1,10 @@
1
+ export class HttpException extends Error {
2
+ public status: number;
3
+ public message: string;
4
+
5
+ constructor(status: number, message: string) {
6
+ super(message);
7
+ this.status = status;
8
+ this.message = message;
9
+ }
10
+ }
@@ -0,0 +1,16 @@
1
+ import { createFastifyInstance, FluxController, FluxOpenapi } from '@fluxapi/common';
2
+ import { TodoController } from '~/controllers/Todo.controller';
3
+
4
+ const fastify = createFastifyInstance();
5
+
6
+ fastify.register(FluxOpenapi);
7
+ fastify.register(FluxController, {
8
+ controllers: [TodoController],
9
+ });
10
+
11
+ fastify.listen({ port: 8080, host: '127.0.0.1' }, (err, address) => {
12
+ if (err) {
13
+ console.error(err);
14
+ process.exit(1);
15
+ }
16
+ });
@@ -0,0 +1,264 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+ /*
4
+ * ---------------------------------------------------------------
5
+ * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
6
+ * ## ##
7
+ * ## AUTHOR: acacode ##
8
+ * ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
9
+ * ---------------------------------------------------------------
10
+ */
11
+
12
+ export interface ListTodoQuery {
13
+ includeDone?: boolean;
14
+ }
15
+
16
+ export interface TodoResponse {
17
+ id: number;
18
+
19
+ /** @format date-time */
20
+ createdAt: string;
21
+ text: string;
22
+ priority: number;
23
+ done: boolean;
24
+ }
25
+
26
+ export interface CreateTodo {
27
+ text: string;
28
+ priority: number;
29
+ }
30
+
31
+ export interface UpdateTodo {
32
+ /** @format date-time */
33
+ createdAt?: string;
34
+ text?: string;
35
+ priority?: number;
36
+ done?: boolean;
37
+ }
38
+
39
+ import axios, { AxiosInstance, AxiosRequestConfig, ResponseType } from 'axios';
40
+
41
+ export type QueryParamsType = Record<string | number, any>;
42
+
43
+ export interface FullRequestParams extends Omit<AxiosRequestConfig, 'data' | 'params' | 'url' | 'responseType'> {
44
+ /** set parameter to `true` for call `securityWorker` for this request */
45
+ secure?: boolean;
46
+ /** request path */
47
+ path: string;
48
+ /** content type of request body */
49
+ type?: ContentType;
50
+ /** query params */
51
+ query?: QueryParamsType;
52
+ /** format of response (i.e. response.json() -> format: "json") */
53
+ format?: ResponseType;
54
+ /** request body */
55
+ body?: unknown;
56
+ }
57
+
58
+ export type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
59
+
60
+ 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
+ format?: ResponseType;
66
+ }
67
+
68
+ export enum ContentType {
69
+ Json = 'application/json',
70
+ FormData = 'multipart/form-data',
71
+ UrlEncoded = 'application/x-www-form-urlencoded',
72
+ }
73
+
74
+ export class HttpClient<SecurityDataType = unknown> {
75
+ public instance: AxiosInstance;
76
+ private securityData: SecurityDataType | null = null;
77
+ private securityWorker?: ApiConfig<SecurityDataType>['securityWorker'];
78
+ private secure?: boolean;
79
+ private format?: ResponseType;
80
+
81
+ constructor({ securityWorker, secure, format, ...axiosConfig }: ApiConfig<SecurityDataType> = {}) {
82
+ this.instance = axios.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || '' });
83
+ this.secure = secure;
84
+ 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
+ }
118
+
119
+ public request = async <T = any, _E = any>({
120
+ secure,
121
+ path,
122
+ type,
123
+ query,
124
+ format,
125
+ body,
126
+ ...params
127
+ }: 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);
134
+ const responseFormat = (format && this.format) || void 0;
135
+
136
+ if (type === ContentType.FormData && body && body !== null && typeof body === 'object') {
137
+ body = this.createFormData(body as Record<string, unknown>);
138
+ }
139
+
140
+ if (!type) {
141
+ type = ContentType.Json;
142
+ }
143
+
144
+ if (!body) {
145
+ body = {};
146
+ }
147
+
148
+ try {
149
+ const result: any = await this.instance.request({
150
+ ...requestParams,
151
+ headers: {
152
+ ...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {}),
153
+ ...(requestParams.headers || {}),
154
+ },
155
+ params: query,
156
+ responseType: responseFormat,
157
+ data: body,
158
+ url: path,
159
+ });
160
+
161
+ return result.data;
162
+ } catch (err) {
163
+ if (axios.isAxiosError(err)) {
164
+ err.message += ` [${err.config.method}] ${err.config.url}`;
165
+ if (err.response) {
166
+ (err as any).data = err.response.data;
167
+ }
168
+ }
169
+
170
+ throw err;
171
+ }
172
+ };
173
+ }
174
+
175
+ /**
176
+ * @title Api
177
+ */
178
+ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
179
+ todos = {
180
+ /**
181
+ * No description
182
+ *
183
+ * @tags todos
184
+ * @name List
185
+ * @request GET:/todos
186
+ */
187
+ list: (query?: { includeDone?: boolean }, params: RequestParams = {}) =>
188
+ this.request<{ id: number; createdAt: string; text: string; priority: number; done: boolean }[], any>({
189
+ path: `/todos`,
190
+ method: 'GET',
191
+ query: query,
192
+ format: 'json',
193
+ ...params,
194
+ }),
195
+
196
+ /**
197
+ * No description
198
+ *
199
+ * @tags todos
200
+ * @name Create
201
+ * @request POST:/todos
202
+ */
203
+ create: (data: { text: string; priority: number }, params: RequestParams = {}) =>
204
+ this.request<{ id: number; createdAt: string; text: string; priority: number; done: boolean }, any>({
205
+ path: `/todos`,
206
+ method: 'POST',
207
+ body: data,
208
+ type: ContentType.Json,
209
+ format: 'json',
210
+ ...params,
211
+ }),
212
+
213
+ /**
214
+ * No description
215
+ *
216
+ * @tags todos
217
+ * @name Get
218
+ * @request GET:/todos/{id}
219
+ */
220
+ get: (id: number, params: RequestParams = {}) =>
221
+ this.request<{ id: number; createdAt: string; text: string; priority: number; done: boolean }, any>({
222
+ path: `/todos/${id}`,
223
+ method: 'GET',
224
+ format: 'json',
225
+ ...params,
226
+ }),
227
+
228
+ /**
229
+ * No description
230
+ *
231
+ * @tags todos
232
+ * @name Update
233
+ * @request POST:/todos/{id}
234
+ */
235
+ update: (
236
+ id: number,
237
+ data: { createdAt?: string; text?: string; priority?: number; done?: boolean },
238
+ params: RequestParams = {},
239
+ ) =>
240
+ this.request<{ id: number; createdAt: string; text: string; priority: number; done: boolean }, any>({
241
+ path: `/todos/${id}`,
242
+ method: 'POST',
243
+ body: data,
244
+ type: ContentType.Json,
245
+ format: 'json',
246
+ ...params,
247
+ }),
248
+
249
+ /**
250
+ * No description
251
+ *
252
+ * @tags todos
253
+ * @name Remove
254
+ * @request DELETE:/todos/{id}
255
+ */
256
+ remove: (id: number, params: RequestParams = {}) =>
257
+ this.request<object, any>({
258
+ path: `/todos/${id}`,
259
+ method: 'DELETE',
260
+ format: 'json',
261
+ ...params,
262
+ }),
263
+ };
264
+ }
@@ -0,0 +1,3 @@
1
+ import { Api } from './GeneratedApi';
2
+
3
+ export const client = new Api({ baseURL: 'http://127.0.0.1:8080' });
@@ -0,0 +1,19 @@
1
+ import { client } from './api';
2
+
3
+ test('list todo', async () => {
4
+ await client.todos.list();
5
+ });
6
+
7
+ test('create todo', async () => {
8
+ await client.todos.create({ text: 'foobar', priority: 1 });
9
+ });
10
+
11
+ test('get todo', async () => {
12
+ const result = await client.todos.create({ text: 'foobar', priority: 1 });
13
+ await client.todos.get(result.id);
14
+ });
15
+
16
+ test('remove todo', async () => {
17
+ const result = await client.todos.create({ text: 'foobar', priority: 1 });
18
+ await client.todos.remove(result.id);
19
+ });
@@ -0,0 +1,73 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
+
5
+ /* Basic Options */
6
+ "target": "es2019" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */,
7
+ "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
8
+ // "lib": [], /* Specify library files to be included in the compilation. */
9
+ // "allowJs": true, /* Allow javascript files to be compiled. */
10
+ // "checkJs": true, /* Report errors in .js files. */
11
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
12
+ // "declaration": true, /* Generates corresponding '.d.ts' file. */
13
+ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
14
+ // "sourceMap": true, /* Generates corresponding '.map' file. */
15
+ // "outFile": "./", /* Concatenate and emit output to single file. */
16
+ "outDir": "./dist/" /* Redirect output structure to the directory. */,
17
+ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
18
+ // "composite": true, /* Enable project compilation */
19
+ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
20
+ // "removeComments": true, /* Do not emit comments to output. */
21
+ // "noEmit": true, /* Do not emit outputs. */
22
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
23
+ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
24
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
25
+
26
+ /* Strict Type-Checking Options */
27
+ "strict": true /* Enable all strict type-checking options. */,
28
+ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
29
+ // "strictNullChecks": true, /* Enable strict null checks. */
30
+ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
31
+ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
32
+ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
33
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
34
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
35
+
36
+ /* Additional Checks */
37
+ // "noUnusedLocals": true, /* Report errors on unused locals. */
38
+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
39
+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
40
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
41
+ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
42
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
43
+ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
44
+
45
+ /* Module Resolution Options */
46
+ // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
47
+ "baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
48
+ "paths": {
49
+ "~/*": ["src/*"]
50
+ } /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */,
51
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
52
+ // "typeRoots": [], /* List of folders to include type definitions from. */
53
+ // "types": [], /* Type declaration files to be included in compilation. */
54
+ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
55
+ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
56
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
57
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
58
+
59
+ /* Source Map Options */
60
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
61
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
62
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
63
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
64
+
65
+ /* Experimental Options */
66
+ "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
67
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
68
+
69
+ /* Advanced Options */
70
+ "skipLibCheck": true /* Skip type checking of declaration files. */,
71
+ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
72
+ }
73
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "create-fastify-flux",
3
+ "version": "2.19.0",
4
+ "description": "",
5
+ "main": "./dist/index.js",
6
+ "bin": {
7
+ "create--fastify-flux": "./cli.js"
8
+ },
9
+ "author": "",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "chalk": "^5.0.1",
13
+ "commander": "^9.4.0",
14
+ "enquirer": "^2.3.6",
15
+ "fs-extra": "^10.1.0",
16
+ "source-map-support": "^0.5.21"
17
+ },
18
+ "devDependencies": {
19
+ "@types/fs-extra": "^9.0.13",
20
+ "@types/jest": "^28.1.6",
21
+ "@types/node": "^18.0.6",
22
+ "jest": "^28.1.3",
23
+ "ts-jest": "^28.0.7",
24
+ "typescript": "4.7.4"
25
+ },
26
+ "files": [
27
+ "cli.js",
28
+ "dist/",
29
+ "templates/"
30
+ ],
31
+ "scripts": {
32
+ "clean": "rm -rf dist/",
33
+ "test": "exit 0",
34
+ "dev": "tsc --watch",
35
+ "build": "npm run clean && tsc"
36
+ }
37
+ }