@keshavsoft/kschema-api-gen-actions 1.14.1
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 +21 -0
- package/README.md +320 -0
- package/bin/cli.js +12 -0
- package/bin/core/getLatestVersion.js +13 -0
- package/bin/core/loadRunner.js +9 -0
- package/bin/v13/commands/loadCommand.js +11 -0
- package/bin/v13/config/actions.json +20 -0
- package/bin/v13/core/createFolder.js +34 -0
- package/bin/v13/core/parseInput.js +8 -0
- package/bin/v13/core/resolveCommand.js +11 -0
- package/bin/v13/core/showUsage.js +50 -0
- package/bin/v13/start.js +22 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateImports/index.js +45 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateUse/buildUseLine.js +9 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateUse/index.js +46 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/announce.js +9 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/createFolder.js +7 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/createHttpFile.js +12 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/decideTemplate.js +3 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/locateDestination.js +7 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/locateSource.js +13 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/resolveFolderName.js +20 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/updateAppJs.js +7 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/updateEndPointsFile.js +30 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/steps/updateEndPointsJs.js +16 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/template/controller.js +21 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/template/errors.js +11 -0
- package/bin/v13/tasks/actions/GetMethods/Distinct/template/service.js +9 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/index.js +45 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/buildUseLine.js +9 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/index.js +46 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/announce.js +9 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/createFolder.js +7 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/createHttpFile.js +12 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/decideTemplate.js +3 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/locateDestination.js +7 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/locateSource.js +13 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/resolveFolderName.js +20 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/updateAppJs.js +7 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/updateEndPointsFile.js +30 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/steps/updateEndPointsJs.js +16 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/template/controller.js +21 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/template/errors.js +11 -0
- package/bin/v13/tasks/actions/GetMethods/ShowAll/template/service.js +9 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/index.js +47 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/buildUseLine.js +5 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +9 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/index.js +56 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/announce.js +9 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/createFolder.js +7 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/createHttpFile.js +12 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/decideTemplate.js +3 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/locateDestination.js +7 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/locateSource.js +13 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/resolveFolderName.js +20 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/updateAppJs.js +7 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/updateEndPointsFile.js +30 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/steps/updateEndPointsJs.js +16 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/template/controller.js +24 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/template/errors.js +11 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/template/middleware.js +19 -0
- package/bin/v13/tasks/actions/PostMethods/Insert/template/service.js +11 -0
- package/bin/v13/tasks/actions/distinct.js +59 -0
- package/bin/v13/tasks/actions/insert.js +59 -0
- package/bin/v13/tasks/actions/showAll.js +59 -0
- package/bin/v13/tasks/core/createFolder.js +34 -0
- package/bin/v13/tasks/core/parseInput.js +12 -0
- package/bin/v13/tasks/core/resolveCommand.js +24 -0
- package/bin/v13/tasks/core/showUsage.js +43 -0
- package/bin/v14/commands/loadCommand.js +11 -0
- package/bin/v14/config/actions.json +23 -0
- package/bin/v14/config/actionsV1.json +20 -0
- package/bin/v14/core/createFolder.js +34 -0
- package/bin/v14/core/parseInput.js +8 -0
- package/bin/v14/core/resolveCommand.js +11 -0
- package/bin/v14/core/showUsage.js +49 -0
- package/bin/v14/start.js +22 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateImports/index.js +45 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateUse/buildUseLine.js +9 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateUse/index.js +46 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/announce.js +9 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/createFolder.js +7 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/createHttpFile.js +12 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/decideTemplate.js +3 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/locateDestination.js +7 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/locateSource.js +13 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/resolveFolderName.js +20 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/updateAppJs.js +7 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/updateEndPointsFile.js +30 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/steps/updateEndPointsJs.js +16 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/template/controller.js +21 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/template/errors.js +11 -0
- package/bin/v14/tasks/actions/GetMethods/Distinct/template/service.js +9 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateImports/index.js +45 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/buildUseLine.js +9 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +8 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/UpdateRoutesJs/updateUse/index.js +46 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/announce.js +9 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/createFolder.js +7 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/createHttpFile.js +12 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/decideTemplate.js +3 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/locateDestination.js +7 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/locateSource.js +13 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/resolveFolderName.js +20 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/updateAppJs.js +7 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/updateEndPointsFile.js +30 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/steps/updateEndPointsJs.js +16 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/template/controller.js +21 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/template/errors.js +11 -0
- package/bin/v14/tasks/actions/GetMethods/ShowAll/template/service.js +9 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateImports/index.js +47 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/buildUseLine.js +5 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +9 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/UpdateRoutesJs/updateUse/index.js +56 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/announce.js +9 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/createFolder.js +7 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/createHttpFile.js +12 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/decideTemplate.js +3 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/locateDestination.js +7 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/locateSource.js +13 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/resolveFolderName.js +20 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/updateAppJs.js +7 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/updateEndPointsFile.js +30 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/steps/updateEndPointsJs.js +16 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/template/controller.js +24 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/template/errors.js +11 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/template/middleware.js +19 -0
- package/bin/v14/tasks/actions/PostMethods/Insert/template/service.js +11 -0
- package/bin/v14/tasks/actions/distinct.js +59 -0
- package/bin/v14/tasks/actions/insert.js +59 -0
- package/bin/v14/tasks/actions/showAll.js +59 -0
- package/bin/v14/tasks/core/createFolder.js +34 -0
- package/bin/v14/tasks/core/parseInput.js +12 -0
- package/bin/v14/tasks/core/resolveCommand.js +24 -0
- package/bin/v14/tasks/core/showUsage.js +43 -0
- package/index.js +8 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 KeshavSoft
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to do so, subject to the
|
|
10
|
+
following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
# @keshavsoft/kschema-api-gen-actions
|
|
2
|
+
|
|
3
|
+
> Generate Express.js API action boilerplate instantly.
|
|
4
|
+
|
|
5
|
+
A lightweight developer-first CLI that scaffolds API action modules for Express.js applications with automatic route registration and structured architecture.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Features
|
|
10
|
+
|
|
11
|
+
- ⚡ Generate API actions in seconds
|
|
12
|
+
- 📁 Auto-create folders and files
|
|
13
|
+
- 🛣 Auto-register routes in `end-points.js`
|
|
14
|
+
- 🧠 Convention-based code generation
|
|
15
|
+
- 🔥 Minimal setup
|
|
16
|
+
- 📦 ESM-first architecture
|
|
17
|
+
- 🚀 Optimized for rapid backend development
|
|
18
|
+
- 🧩 Scalable folder structure
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
# Installation
|
|
23
|
+
|
|
24
|
+
## Global Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g @keshavsoft/kschema-api-gen-actions
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Using NPX
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx @keshavsoft/kschema-api-gen-actions
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
# Quick Start
|
|
41
|
+
|
|
42
|
+
Assume your current project contains:
|
|
43
|
+
|
|
44
|
+
```txt
|
|
45
|
+
end-points.js
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Example:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import express from 'express';
|
|
52
|
+
|
|
53
|
+
const tableName = "journals";
|
|
54
|
+
|
|
55
|
+
const router = express.Router();
|
|
56
|
+
|
|
57
|
+
export { router };
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
# Generate ShowAll Action
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npx kschema-api-gen ShowAll
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Generated:
|
|
69
|
+
|
|
70
|
+
```txt
|
|
71
|
+
ShowAll/
|
|
72
|
+
├── controller.js
|
|
73
|
+
├── dal.js
|
|
74
|
+
├── route.js
|
|
75
|
+
└── validation.js
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
And updates:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
import { getFunc } from "./ShowAll/controller.js";
|
|
82
|
+
|
|
83
|
+
router.get('/ShowAll', (req, res) =>
|
|
84
|
+
getFunc({
|
|
85
|
+
res,
|
|
86
|
+
inTableName: tableName
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
# Generate Insert Action
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx kschema-api-gen Insert
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Generated:
|
|
100
|
+
|
|
101
|
+
```txt
|
|
102
|
+
Insert/
|
|
103
|
+
├── controller.js
|
|
104
|
+
├── dal.js
|
|
105
|
+
├── route.js
|
|
106
|
+
└── validation.js
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
And updates:
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
import { postFunc } from "./Insert/controller.js";
|
|
113
|
+
|
|
114
|
+
router.post('/Insert', express.json(), (req, res) =>
|
|
115
|
+
postFunc({
|
|
116
|
+
req,
|
|
117
|
+
res,
|
|
118
|
+
inTableName: tableName
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
# Final Result Example
|
|
126
|
+
|
|
127
|
+
```txt
|
|
128
|
+
project/
|
|
129
|
+
├── end-points.js
|
|
130
|
+
├── Insert/
|
|
131
|
+
│ ├── controller.js
|
|
132
|
+
│ ├── dal.js
|
|
133
|
+
│ ├── route.js
|
|
134
|
+
│ └── validation.js
|
|
135
|
+
│
|
|
136
|
+
├── ShowAll/
|
|
137
|
+
│ ├── controller.js
|
|
138
|
+
│ ├── dal.js
|
|
139
|
+
│ ├── route.js
|
|
140
|
+
│ └── validation.js
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
# CLI Usage
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
npx kschema-api-gen <ActionName>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
# Supported Actions
|
|
154
|
+
|
|
155
|
+
| Action | Method | Description |
|
|
156
|
+
|---|---|---|
|
|
157
|
+
| ShowAll | GET | Fetch all records |
|
|
158
|
+
| Insert | POST | Insert new record |
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
# Example Workflow
|
|
163
|
+
|
|
164
|
+
## Step 1
|
|
165
|
+
|
|
166
|
+
Create route container:
|
|
167
|
+
|
|
168
|
+
```js
|
|
169
|
+
import express from 'express';
|
|
170
|
+
|
|
171
|
+
const tableName = "journals";
|
|
172
|
+
|
|
173
|
+
const router = express.Router();
|
|
174
|
+
|
|
175
|
+
export { router };
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Step 2
|
|
181
|
+
|
|
182
|
+
Run:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
npx kschema-api-gen ShowAll
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Step 3
|
|
191
|
+
|
|
192
|
+
Run:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
npx kschema-api-gen Insert
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Step 4
|
|
201
|
+
|
|
202
|
+
Your routes become:
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
import express from 'express';
|
|
206
|
+
|
|
207
|
+
import { postFunc } from "./Insert/controller.js";
|
|
208
|
+
import { getFunc } from "./ShowAll/controller.js";
|
|
209
|
+
|
|
210
|
+
const tableName = "journals";
|
|
211
|
+
|
|
212
|
+
const router = express.Router();
|
|
213
|
+
|
|
214
|
+
router.get('/ShowAll', (req, res) =>
|
|
215
|
+
getFunc({
|
|
216
|
+
res,
|
|
217
|
+
inTableName: tableName
|
|
218
|
+
})
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
router.post('/Insert', express.json(), (req, res) =>
|
|
222
|
+
postFunc({
|
|
223
|
+
req,
|
|
224
|
+
res,
|
|
225
|
+
inTableName: tableName
|
|
226
|
+
})
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
export { router };
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
# Philosophy
|
|
235
|
+
|
|
236
|
+
This package is designed around:
|
|
237
|
+
|
|
238
|
+
- Convention over configuration
|
|
239
|
+
- Fast backend development
|
|
240
|
+
- Predictable architecture
|
|
241
|
+
- Reduced boilerplate
|
|
242
|
+
- Clean scalable Express.js APIs
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
# Tech Stack
|
|
247
|
+
|
|
248
|
+
- Node.js
|
|
249
|
+
- Express.js
|
|
250
|
+
- JavaScript
|
|
251
|
+
- ESM Modules
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
# Local Development
|
|
256
|
+
|
|
257
|
+
Clone repository:
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
git clone <repo-url>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Install dependencies:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
npm install
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Run locally:
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
node ./bin/cli.js ShowAll
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
# Package Structure
|
|
278
|
+
|
|
279
|
+
```txt
|
|
280
|
+
bin/
|
|
281
|
+
├── cli.js
|
|
282
|
+
├── v11/
|
|
283
|
+
│ ├── commands/
|
|
284
|
+
│ ├── core/
|
|
285
|
+
│ └── tasks/
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
# Roadmap
|
|
291
|
+
|
|
292
|
+
- [ ] Update action generation
|
|
293
|
+
- [ ] Delete action generation
|
|
294
|
+
- [ ] Validation schema generation
|
|
295
|
+
- [ ] TypeScript support
|
|
296
|
+
- [ ] Swagger/OpenAPI support
|
|
297
|
+
- [ ] Prisma templates
|
|
298
|
+
- [ ] Sequelize templates
|
|
299
|
+
- [ ] MongoDB templates
|
|
300
|
+
- [ ] Custom middleware generation
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
# Contributing
|
|
305
|
+
|
|
306
|
+
Pull requests are welcome.
|
|
307
|
+
|
|
308
|
+
For major changes, please open an issue first to discuss proposed improvements.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
# License
|
|
313
|
+
|
|
314
|
+
MIT
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
# Author
|
|
319
|
+
|
|
320
|
+
Created by KeshavSoft.
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import getLatestVersion from "./core/getLatestVersion.js";
|
|
4
|
+
import loadRunner from "./core/loadRunner.js";
|
|
5
|
+
|
|
6
|
+
const run = async () => {
|
|
7
|
+
const version = getLatestVersion();
|
|
8
|
+
const runner = await loadRunner(version);
|
|
9
|
+
await runner();
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
run();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
|
|
7
|
+
export default function getLatestVersion() {
|
|
8
|
+
const versions = fs.readdirSync(path.join(__dirname, ".."))
|
|
9
|
+
.filter(n => /^v\d+$/.test(n))
|
|
10
|
+
.sort((a, b) => parseInt(a.slice(1)) - parseInt(b.slice(1)));
|
|
11
|
+
|
|
12
|
+
return versions.at(-1);
|
|
13
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import actions from "../config/actions.json" with { type: "json" };
|
|
2
|
+
|
|
3
|
+
export default async function loadCommand(name) {
|
|
4
|
+
const matched = actions.find(x => x.exportFile === name);
|
|
5
|
+
|
|
6
|
+
if (!matched) return null;
|
|
7
|
+
|
|
8
|
+
const module = await import(`../tasks/actions/${matched.file}.js`);
|
|
9
|
+
|
|
10
|
+
return module.default;
|
|
11
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"cmd": "showAll",
|
|
4
|
+
"file": "showAll",
|
|
5
|
+
"exportFile": "ShowAll",
|
|
6
|
+
"group": "GetMethods"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"cmd": "insert",
|
|
10
|
+
"file": "insert",
|
|
11
|
+
"exportFile": "Insert",
|
|
12
|
+
"group": "PostMethods"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"cmd": "distinct",
|
|
16
|
+
"file": "distinct",
|
|
17
|
+
"exportFile": "Distinct",
|
|
18
|
+
"group": "GetMethods"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
|
|
3
|
+
export const createFolder = ({ source, destination, checkBeforeCreate = false, isAnnounce = true }) => {
|
|
4
|
+
if (checkBeforeCreate) {
|
|
5
|
+
return createFolderWithCheck({ source, destination, isAnnounce });
|
|
6
|
+
} else {
|
|
7
|
+
return createOnly({ source, destination });
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const createOnly = ({ source, destination }) => {
|
|
12
|
+
fs.mkdirSync(destination, { recursive: true });
|
|
13
|
+
|
|
14
|
+
fs.cpSync(source, destination, { recursive: true });
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
KTF: true
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const createFolderWithCheck = ({ source, destination, isAnnounce }) => {
|
|
22
|
+
if (fs.existsSync(destination)) {
|
|
23
|
+
if (isAnnounce) console.log("Folder already exists :", destination);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
KTF: false,
|
|
27
|
+
KReason: "Folder already exists"
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (isAnnounce) console.log("Folder created :", destination);
|
|
32
|
+
|
|
33
|
+
return createOnly({ source, destination });
|
|
34
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import actions from "../config/actions.json" with { type: "json" };
|
|
2
|
+
|
|
3
|
+
export default async function resolveCommand(cmd) {
|
|
4
|
+
const matched = actions.find(x => x.cmd === cmd);
|
|
5
|
+
|
|
6
|
+
if (!matched) return null;
|
|
7
|
+
|
|
8
|
+
const module = await import(`../tasks/actions/${matched.file}.js`);
|
|
9
|
+
|
|
10
|
+
return module.default;
|
|
11
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
KSchema CLI – Entry Flow
|
|
3
|
+
|
|
4
|
+
1. Read user input from terminal (parseInput)
|
|
5
|
+
2. If no command → show usage (first-time user safety)
|
|
6
|
+
3. If help flags → show usage (quick guidance)
|
|
7
|
+
4. Resolve command dynamically (no hardcoding logic)
|
|
8
|
+
5. If command not found → inform + guide back to usage
|
|
9
|
+
6. Execute command with parsed input
|
|
10
|
+
|
|
11
|
+
Goal:
|
|
12
|
+
- Zero confusion for user
|
|
13
|
+
- Single source of truth (showUsage)
|
|
14
|
+
- Easy to extend (just add commands, no core changes)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export default function showUsage(version) {
|
|
18
|
+
const g = "\x1b[32m";
|
|
19
|
+
const y = "\x1b[33m";
|
|
20
|
+
const c = "\x1b[36m";
|
|
21
|
+
const gray = "\x1b[90m";
|
|
22
|
+
const r = "\x1b[0m";
|
|
23
|
+
|
|
24
|
+
console.log(`
|
|
25
|
+
${c}🚀 KSchema Api Generator v${version}${r}
|
|
26
|
+
|
|
27
|
+
${y}Usage:${r}
|
|
28
|
+
${g}npx @keshavsoft/kschema-api-gen${r} <command> [options]
|
|
29
|
+
|
|
30
|
+
${y}Commands:${r}
|
|
31
|
+
${g}StartEndPoint${r} Initialize a new folder and files
|
|
32
|
+
${g}AddSubRoute${r} Initialize a new folder and files
|
|
33
|
+
${g}AddTableName${r} Initialize a new folder and files for TableName
|
|
34
|
+
${g}ShowAll${r} Initialize a new folder and files for action
|
|
35
|
+
|
|
36
|
+
${g}CreateApi${r} Creates new end point and hooks to app.js
|
|
37
|
+
${g}InsertApi${r} Creates new InsertApi end point and hooks to app.js
|
|
38
|
+
|
|
39
|
+
${y}Examples:${r}
|
|
40
|
+
${gray}npx @keshavsoft/kschema-api-gen StartEndPoint${r}
|
|
41
|
+
${gray}npx @keshavsoft/kschema-api-gen AddSubRoute${r}
|
|
42
|
+
${gray}npx @keshavsoft/kschema-api-gen AddTableName${r}
|
|
43
|
+
${gray}npx @keshavsoft/kschema-api-gen ShowAll${r}
|
|
44
|
+
${gray}npx @keshavsoft/kschema-api-gen CreateApi Api/V1/journals/ShowAll${r}
|
|
45
|
+
${gray}npx @keshavsoft/kschema-api-gen InsertApi Api/V1/journals/Insert${r}
|
|
46
|
+
|
|
47
|
+
${y}Tip:${r}
|
|
48
|
+
${gray}npm i -g @keshavsoft/kschema-api-gen${r}
|
|
49
|
+
`);
|
|
50
|
+
}
|
package/bin/v13/start.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import parseInput from "./core/parseInput.js";
|
|
2
|
+
import resolveCommand from "./core/resolveCommand.js";
|
|
3
|
+
import showUsage from './core/showUsage.js';
|
|
4
|
+
import pkg from '../../package.json' with { type: 'json' };
|
|
5
|
+
|
|
6
|
+
const version = pkg.version;
|
|
7
|
+
|
|
8
|
+
const run = async () => {
|
|
9
|
+
const input = parseInput();
|
|
10
|
+
|
|
11
|
+
if (!input.cmd) return showUsage(version);
|
|
12
|
+
|
|
13
|
+
if (input.cmd === "--help" || input.cmd === "-h" || input.cmd === "help") return showUsage(version);
|
|
14
|
+
|
|
15
|
+
const command = resolveCommand(input.cmd);
|
|
16
|
+
|
|
17
|
+
if (!command) return (console.log(`Unknown command: ${input.cmd}\n`), showUsage(version));
|
|
18
|
+
|
|
19
|
+
await command(input);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default run;
|
package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateImports/buildImport.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const buildImport = ({ inFuncName, inEndpoint }) => {
|
|
2
|
+
const localEndpoint = inEndpoint;
|
|
3
|
+
|
|
4
|
+
const safeName = localEndpoint.replace(/[^a-zA-Z0-9]/g, "_");
|
|
5
|
+
|
|
6
|
+
return `import { ${inFuncName} } from "./${localEndpoint}/controller.js";`;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default buildImport;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const findInsertIndex = (inContent) => {
|
|
2
|
+
const localContent = inContent;
|
|
3
|
+
|
|
4
|
+
const matches = [...localContent.matchAll(/^\s*import.*$/gm)];
|
|
5
|
+
const last = matches.at(-1);
|
|
6
|
+
|
|
7
|
+
return last ? last.index + last[0].length : 0;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default findInsertIndex;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import readFile from "../common/readFile.js";
|
|
2
|
+
import buildImport from "./buildImport.js";
|
|
3
|
+
import checkDuplicate from "./checkDuplicate.js";
|
|
4
|
+
import findInsertIndex from "./findInsertIndex.js";
|
|
5
|
+
import writeFile from "../common/writeFile.js";
|
|
6
|
+
|
|
7
|
+
const updateImports = ({ appJsPath, endpoint, showLog, inFuncName }) => {
|
|
8
|
+
const summary = {
|
|
9
|
+
import: { added: false, line: null },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const content = readFile(appJsPath);
|
|
13
|
+
|
|
14
|
+
const importLine = buildImport({
|
|
15
|
+
inEndpoint: endpoint,
|
|
16
|
+
inFuncName
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (checkDuplicate(content, endpoint)) {
|
|
20
|
+
summary.import.skipped = true;
|
|
21
|
+
|
|
22
|
+
if (showLog) console.log(summary);
|
|
23
|
+
|
|
24
|
+
return summary;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const index = findInsertIndex(content);
|
|
28
|
+
|
|
29
|
+
const before = content.slice(0, index);
|
|
30
|
+
const lineNumber = before.split("\n").length + 1;
|
|
31
|
+
|
|
32
|
+
const updated =
|
|
33
|
+
before + "\n" + importLine + content.slice(index);
|
|
34
|
+
|
|
35
|
+
writeFile(appJsPath, updated);
|
|
36
|
+
|
|
37
|
+
summary.import.added = true;
|
|
38
|
+
summary.import.line = lineNumber;
|
|
39
|
+
|
|
40
|
+
if (showLog) console.log(summary);
|
|
41
|
+
|
|
42
|
+
return summary;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default updateImports;
|
package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateUse/buildUseLine.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const appOrRouter = "router";
|
|
2
|
+
|
|
3
|
+
const buildUseLine = ({ inEndpoint, inFuncName }) => {
|
|
4
|
+
return `${appOrRouter}.get('/${inEndpoint}', (req, res) => ${inFuncName}({ res, inTableName : tableName}));`;
|
|
5
|
+
|
|
6
|
+
// return `${appOrRouter}.use("/${inEndpoint}", ${inFuncName});`;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default buildUseLine;
|
package/bin/v13/tasks/actions/GetMethods/Distinct/steps/UpdateRoutesJs/updateUse/findInsertIndex.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const findUseInsertIndex = (inContent) => {
|
|
2
|
+
const localContent = inContent;
|
|
3
|
+
|
|
4
|
+
const matches = [...localContent.matchAll(/const\s+router\s*=\s*express\.Router\(\)/g)];
|
|
5
|
+
const match = matches.at(0);
|
|
6
|
+
|
|
7
|
+
return match ? match.index + match[0].length : localContent.length;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default findUseInsertIndex;
|