@gasket/preset-api 7.5.4 → 7.5.5

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.
Files changed (2) hide show
  1. package/EXAMPLES.md +210 -0
  2. package/package.json +27 -28
package/EXAMPLES.md ADDED
@@ -0,0 +1,210 @@
1
+ # @gasket/preset-api Examples
2
+
3
+ This document provides examples of using the `@gasket/preset-api` preset and understanding its hooks.
4
+
5
+ ## Using the Preset
6
+
7
+ ### Creating a new API project
8
+
9
+ ```bash
10
+ # Create a new API project using the preset
11
+ npx create-gasket-app@latest my-api --presets @gasket/preset-api
12
+
13
+ # Or with yarn
14
+ yarn create gasket-app my-api --presets @gasket/preset-api
15
+
16
+ # With config to skip prompts
17
+ npx create-gasket-app@latest my-api \
18
+ --presets @gasket/preset-api \
19
+ --config '{"server": "express", "typescript": true, "useSwagger": true}'
20
+ ```
21
+
22
+ ## Generated Project Structure
23
+
24
+ ### JavaScript Project
25
+
26
+ ```
27
+ my-api/
28
+ ├── server.js # Server entry point
29
+ ├── gasket.js # Gasket configuration
30
+ ├── package.json # Project configuration
31
+ └── README.md # Project documentation
32
+ ```
33
+
34
+ ### TypeScript Project
35
+
36
+ ```
37
+ my-api/
38
+ ├── gasket.ts # Gasket configuration (TypeScript)
39
+ ├── package.json # Project configuration
40
+ └── README.md # Project documentation
41
+ ```
42
+
43
+ ## Server Framework Examples
44
+
45
+ ### Express Server
46
+
47
+ ```js
48
+ // When server: 'express' is selected
49
+ // gasket.js
50
+ import { makeGasket } from '@gasket/core';
51
+ import pluginExpress from '@gasket/plugin-express';
52
+ import pluginHttps from '@gasket/plugin-https';
53
+
54
+ export default makeGasket({
55
+ plugins: [
56
+ pluginExpress,
57
+ pluginHttps,
58
+ // ... other plugins
59
+ ]
60
+ });
61
+
62
+ // Your route definitions
63
+ export default {
64
+ name: 'my-routes',
65
+ hooks: {
66
+ express(gasket, app) {
67
+ app.get('/api/health', (req, res) => {
68
+ res.json({ status: 'healthy' });
69
+ });
70
+
71
+ app.get('/api/users', (req, res) => {
72
+ res.json({ users: [] });
73
+ });
74
+ }
75
+ }
76
+ };
77
+ ```
78
+
79
+ ### Fastify Server
80
+
81
+ ```js
82
+ // When server: 'fastify' is selected
83
+ // gasket.js
84
+ import { makeGasket } from '@gasket/core';
85
+ import pluginFastify from '@gasket/plugin-fastify';
86
+ import pluginHttps from '@gasket/plugin-https';
87
+
88
+ export default makeGasket({
89
+ plugins: [
90
+ pluginFastify,
91
+ pluginHttps,
92
+ // ... other plugins
93
+ ]
94
+ });
95
+
96
+ // Your route definitions
97
+ export default {
98
+ name: 'my-routes',
99
+ hooks: {
100
+ fastify(gasket, app) {
101
+ app.get('/api/health', async (request, reply) => {
102
+ return { status: 'healthy' };
103
+ });
104
+
105
+ app.get('/api/users', async (request, reply) => {
106
+ return { users: [] };
107
+ });
108
+ }
109
+ }
110
+ };
111
+ ```
112
+
113
+ ## Integration Examples
114
+
115
+ ### With TypeScript
116
+
117
+ ```typescript
118
+ // gasket.ts
119
+ import { makeGasket } from '@gasket/core';
120
+ import pluginExpress from '@gasket/plugin-express';
121
+ import pluginTypescript from '@gasket/plugin-typescript';
122
+
123
+ export default makeGasket({
124
+ plugins: [
125
+ pluginExpress
126
+ // ... other plugins
127
+ ]
128
+ });
129
+
130
+ // types/api.ts
131
+ export interface User {
132
+ id: number;
133
+ name: string;
134
+ email: string;
135
+ }
136
+
137
+ // routes/users.ts
138
+ import type { User } from '../types/api.js';
139
+
140
+ export default {
141
+ name: 'user-routes',
142
+ hooks: {
143
+ express(gasket, app) {
144
+ app.get('/api/users', (req, res) => {
145
+ const users: User[] = [
146
+ { id: 1, name: 'John', email: 'john@example.com' }
147
+ ];
148
+ res.json({ users });
149
+ });
150
+ }
151
+ }
152
+ };
153
+ ```
154
+
155
+ ### With Swagger
156
+
157
+ ```js
158
+ // gasket.js - when useSwagger: true
159
+ import { makeGasket } from '@gasket/core';
160
+ import pluginSwagger from '@gasket/plugin-swagger';
161
+
162
+ export default makeGasket({
163
+ plugins: [
164
+ pluginSwagger,
165
+ // ... other plugins
166
+ ],
167
+ swagger: {
168
+ jsdoc: {
169
+ definition: {
170
+ openapi: '3.0.0',
171
+ info: {
172
+ title: 'My API',
173
+ version: '1.0.0'
174
+ }
175
+ },
176
+ apis: ['./routes/*.js']
177
+ }
178
+ }
179
+ });
180
+
181
+ // routes/users.js
182
+ /**
183
+ * @swagger
184
+ * /api/users:
185
+ * get:
186
+ * summary: Get all users
187
+ * responses:
188
+ * 200:
189
+ * description: List of users
190
+ * content:
191
+ * application/json:
192
+ * schema:
193
+ * type: object
194
+ * properties:
195
+ * users:
196
+ * type: array
197
+ * items:
198
+ * type: object
199
+ */
200
+ export default {
201
+ name: 'user-routes',
202
+ hooks: {
203
+ express(gasket, app) {
204
+ app.get('/api/users', (req, res) => {
205
+ res.json({ users: [] });
206
+ });
207
+ }
208
+ }
209
+ };
210
+ ```
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@gasket/preset-api",
3
- "version": "7.5.4",
3
+ "version": "7.5.5",
4
4
  "description": "Create Express-based API with Gasket",
5
5
  "type": "module",
6
6
  "types": "lib/index.d.ts",
7
7
  "files": [
8
8
  "generator",
9
9
  "lib",
10
- "cjs"
10
+ "cjs",
11
+ "EXAMPLES.md"
11
12
  ],
12
13
  "exports": {
13
14
  ".": {
@@ -27,33 +28,31 @@
27
28
  "bugs": "https://github.com/godaddy/gasket/issues",
28
29
  "homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-preset-api",
29
30
  "dependencies": {
30
- "@gasket/plugin-cypress": "^7.5.2",
31
- "@gasket/plugin-docs": "^7.4.7",
32
- "@gasket/plugin-command": "^7.5.2",
33
- "@gasket/plugin-docusaurus": "^7.4.5",
34
- "@gasket/plugin-dynamic-plugins": "^7.4.1",
35
- "@gasket/plugin-express": "^7.4.3",
36
- "@gasket/plugin-fastify": "^7.4.5",
37
- "@gasket/plugin-git": "^7.4.6",
38
- "@gasket/plugin-https": "^7.3.11",
39
- "@gasket/plugin-jest": "^7.5.4",
40
- "@gasket/plugin-lint": "^7.4.3",
41
- "@gasket/plugin-logger": "^7.3.7",
31
+ "@gasket/plugin-command": "^7.5.3",
32
+ "@gasket/plugin-cypress": "^7.5.3",
33
+ "@gasket/plugin-docs": "^7.4.8",
34
+ "@gasket/plugin-docusaurus": "^7.4.6",
35
+ "@gasket/plugin-dynamic-plugins": "^7.4.2",
36
+ "@gasket/plugin-express": "^7.4.4",
37
+ "@gasket/plugin-fastify": "^7.4.6",
38
+ "@gasket/plugin-git": "^7.4.7",
39
+ "@gasket/plugin-https": "^7.3.12",
40
+ "@gasket/plugin-jest": "^7.5.5",
41
+ "@gasket/plugin-lint": "^7.4.4",
42
+ "@gasket/plugin-logger": "^7.3.8",
42
43
  "@gasket/plugin-mocha": "^7.5.4",
43
- "@gasket/plugin-swagger": "^7.3.9",
44
- "@gasket/plugin-typescript": "^7.4.5",
45
- "@gasket/plugin-vitest": "^7.1.1",
46
- "@gasket/plugin-winston": "^7.3.7"
44
+ "@gasket/plugin-swagger": "^7.3.10",
45
+ "@gasket/plugin-typescript": "^7.4.6",
46
+ "@gasket/plugin-vitest": "^7.1.2",
47
+ "@gasket/plugin-winston": "^7.3.8"
47
48
  },
48
49
  "devDependencies": {
49
- "jest": "^29.7.0",
50
+ "@vitest/coverage-v8": "^3.2.0",
50
51
  "nodemon": "^3.1.9",
51
- "@gasket/cjs": "^7.0.1",
52
- "@gasket/plugin-metadata": "^7.5.3",
53
- "create-gasket-app": "^7.4.12"
54
- },
55
- "jest": {
56
- "transform": {}
52
+ "vitest": "^3.2.0",
53
+ "@gasket/cjs": "^7.0.2",
54
+ "@gasket/plugin-metadata": "^7.5.4",
55
+ "create-gasket-app": "^7.4.13"
57
56
  },
58
57
  "scripts": {
59
58
  "build": "gasket-cjs ./lib",
@@ -61,8 +60,8 @@
61
60
  "lint": "eslint .",
62
61
  "lint:fix": "pnpm run lint --fix",
63
62
  "posttest": "pnpm run lint",
64
- "test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict --experimental-vm-modules' jest",
65
- "test:coverage": "jest --coverage",
66
- "test:watch": "pnpm run test --watch"
63
+ "test": "vitest run --globals",
64
+ "test:coverage": "vitest run --coverage",
65
+ "test:watch": "vitest"
67
66
  }
68
67
  }