kschema-fs-api-gen-get-actions 1.6.5 → 1.7.2
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/bin/v6/tasks/actions/FilterQuery/template/v1/controller.js +1 -1
- package/bin/v6/tasks/actions/FilterQuery/template/v1/service.js +3 -3
- package/bin/v7/tasks/actions/Filter/template/v1/service.js +13 -0
- package/bin/v7/tasks/actions/FilterQuery/template/v1/controller.js +28 -0
- package/bin/v7/tasks/actions/FilterQuery/template/v1/service.js +15 -0
- package/bin/v7/tasks/actions/Find/actions.json +26 -0
- package/bin/v7/tasks/actions/Find/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v7/tasks/actions/Find/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v7/tasks/actions/Find/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v7/tasks/actions/Find/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v7/tasks/actions/Find/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v7/tasks/actions/Find/steps/UpdateRoutesJs/updateImports/index.js +47 -0
- package/bin/v7/tasks/actions/Find/steps/UpdateRoutesJs/updateUse/buildUseLine.js +5 -0
- package/bin/v7/tasks/actions/Find/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +9 -0
- package/bin/v7/tasks/actions/Find/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v7/tasks/actions/Find/steps/UpdateRoutesJs/updateUse/index.js +56 -0
- package/bin/v7/tasks/actions/Find/steps/announce.js +9 -0
- package/bin/v7/tasks/actions/Find/steps/createFolder.js +7 -0
- package/bin/v7/tasks/actions/Find/steps/decideTemplate.js +3 -0
- package/bin/v7/tasks/actions/Find/steps/locateDestination.js +7 -0
- package/bin/v7/tasks/actions/Find/steps/locateSource.js +18 -0
- package/bin/v7/tasks/actions/Find/steps/resolveFolderName.js +20 -0
- package/bin/v7/tasks/actions/Find/steps/updateAppJs.js +7 -0
- package/bin/v7/tasks/actions/Find/steps/updateEndPointsFile.js +30 -0
- package/bin/v7/tasks/actions/Find/template/v2/controller.js +27 -0
- package/bin/v7/tasks/actions/Find/template/v2/errors.js +11 -0
- package/bin/v7/tasks/actions/Find/template/v2/getData.js +11 -0
- package/bin/v7/tasks/actions/LastRecord/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v7/tasks/actions/LastRecord/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v7/tasks/actions/LastRecord/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v7/tasks/actions/LastRecord/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v7/tasks/actions/LastRecord/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v7/tasks/actions/LastRecord/steps/UpdateRoutesJs/updateImports/index.js +47 -0
- package/bin/v7/tasks/actions/LastRecord/steps/UpdateRoutesJs/updateUse/buildUseLine.js +5 -0
- package/bin/v7/tasks/actions/LastRecord/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +9 -0
- package/bin/v7/tasks/actions/LastRecord/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v7/tasks/actions/LastRecord/steps/UpdateRoutesJs/updateUse/index.js +56 -0
- package/bin/v7/tasks/actions/LastRecord/steps/announce.js +9 -0
- package/bin/v7/tasks/actions/LastRecord/steps/createFolder.js +7 -0
- package/bin/v7/tasks/actions/LastRecord/steps/decideTemplate.js +3 -0
- package/bin/v7/tasks/actions/LastRecord/steps/locateDestination.js +7 -0
- package/bin/v7/tasks/actions/LastRecord/steps/locateSource.js +18 -0
- package/bin/v7/tasks/actions/LastRecord/steps/resolveFolderName.js +20 -0
- package/bin/v7/tasks/actions/LastRecord/steps/updateAppJs.js +7 -0
- package/bin/v7/tasks/actions/LastRecord/steps/updateEndPointsFile.js +30 -0
- package/bin/v7/tasks/actions/LastRecord/template/v1/errors.js +11 -0
- package/bin/v7/tasks/actions/LastRecord/template/v1/getData.js +11 -0
- package/bin/v7/tasks/actions/LastRecord/template/v1/service.js +10 -0
- package/bin/v7/tasks/actions/ShowAll/actions.json +26 -0
- package/bin/v7/tasks/actions/ShowAll/steps/UpdateRoutesJs/common/readFile.js +8 -0
- package/bin/v7/tasks/actions/ShowAll/steps/UpdateRoutesJs/common/writeFile.js +10 -0
- package/bin/v7/tasks/actions/ShowAll/steps/UpdateRoutesJs/updateImports/buildImport.js +9 -0
- package/bin/v7/tasks/actions/ShowAll/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +8 -0
- package/bin/v7/tasks/actions/ShowAll/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +10 -0
- package/bin/v7/tasks/actions/ShowAll/steps/UpdateRoutesJs/updateImports/index.js +47 -0
- package/bin/v7/tasks/actions/ShowAll/steps/UpdateRoutesJs/updateUse/buildUseLine.js +5 -0
- package/bin/v7/tasks/actions/ShowAll/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +9 -0
- package/bin/v7/tasks/actions/ShowAll/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +10 -0
- package/bin/v7/tasks/actions/ShowAll/steps/UpdateRoutesJs/updateUse/index.js +56 -0
- package/bin/v7/tasks/actions/ShowAll/steps/announce.js +9 -0
- package/bin/v7/tasks/actions/ShowAll/steps/createFolder.js +7 -0
- package/bin/v7/tasks/actions/ShowAll/steps/decideTemplate.js +3 -0
- package/bin/v7/tasks/actions/ShowAll/steps/locateDestination.js +7 -0
- package/bin/v7/tasks/actions/ShowAll/steps/locateSource.js +18 -0
- package/bin/v7/tasks/actions/ShowAll/steps/resolveFolderName.js +20 -0
- package/bin/v7/tasks/actions/ShowAll/steps/updateAppJs.js +7 -0
- package/bin/v7/tasks/actions/ShowAll/steps/updateEndPointsFile.js +30 -0
- package/bin/v7/tasks/actions/ShowAll/template/v2/controller.js +24 -0
- package/bin/v7/tasks/actions/ShowAll/template/v2/errors.js +11 -0
- package/bin/v7/tasks/actions/ShowAll/template/v2/getData.js +11 -0
- package/bin/v7/tasks/actions/filter.js +63 -0
- package/bin/v7/tasks/actions/filterQuery.js +63 -0
- package/bin/v7/tasks/actions/lastRecord.js +60 -0
- package/index.js +21 -8
- package/package.json +1 -1
- /package/bin/{v5 → v7}/core/createFolder.js +0 -0
- /package/bin/{v5 → v7}/core/parseInput.js +0 -0
- /package/bin/{v5 → v7}/core/resolveCommand.js +0 -0
- /package/bin/{v5 → v7}/core/showUsage.js +0 -0
- /package/bin/{v5 → v7}/start.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/actions.json +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/UpdateRoutesJs/common/readFile.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/UpdateRoutesJs/common/writeFile.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/UpdateRoutesJs/updateImports/buildImport.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/UpdateRoutesJs/updateImports/index.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/UpdateRoutesJs/updateUse/buildUseLine.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/UpdateRoutesJs/updateUse/index.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/announce.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/createFolder.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/decideTemplate.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/locateDestination.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/locateSource.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/resolveFolderName.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/updateAppJs.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/steps/updateEndPointsFile.js +0 -0
- /package/bin/{v5/tasks/actions/Find/template/v2 → v7/tasks/actions/Filter/template/v1}/controller.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/template/v1/errors.js +0 -0
- /package/bin/{v5/tasks/actions/Find → v7/tasks/actions/Filter}/template/v1/getData.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/actions.json +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/UpdateRoutesJs/common/readFile.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/UpdateRoutesJs/common/writeFile.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/UpdateRoutesJs/updateImports/buildImport.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/UpdateRoutesJs/updateImports/checkDuplicate.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/UpdateRoutesJs/updateImports/findInsertIndex.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/UpdateRoutesJs/updateImports/index.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/UpdateRoutesJs/updateUse/buildUseLine.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/UpdateRoutesJs/updateUse/checkDuplicate.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/UpdateRoutesJs/updateUse/findInsertIndex.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/UpdateRoutesJs/updateUse/index.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/announce.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/createFolder.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/decideTemplate.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/locateDestination.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/locateSource.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/resolveFolderName.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/updateAppJs.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll → v7/tasks/actions/FilterQuery}/steps/updateEndPointsFile.js +0 -0
- /package/bin/{v5/tasks/actions/Find/template/v2 → v7/tasks/actions/FilterQuery/template/v1}/errors.js +0 -0
- /package/bin/{v5/tasks/actions/Find/template/v2 → v7/tasks/actions/FilterQuery/template/v1}/getData.js +0 -0
- /package/bin/{v5 → v7}/tasks/actions/Find/template/v1/controller.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll/template/v2 → v7/tasks/actions/Find/template/v1}/errors.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll/template/v2 → v7/tasks/actions/Find/template/v1}/getData.js +0 -0
- /package/bin/{v5 → v7}/tasks/actions/Find/template/v1/service.js +0 -0
- /package/bin/{v5 → v7}/tasks/actions/Find/template/v2/service.js +0 -0
- /package/bin/{v5/tasks/actions/ShowAll/template/v2 → v7/tasks/actions/LastRecord/template/v1}/controller.js +0 -0
- /package/bin/{v5 → v7}/tasks/actions/ShowAll/template/v2/service.js +0 -0
- /package/bin/{v5 → v7}/tasks/actions/find.js +0 -0
- /package/bin/{v5 → v7}/tasks/actions/showAll.js +0 -0
- /package/bin/{v5 → v7}/tasks/core/createFolder.js +0 -0
- /package/bin/{v5 → v7}/tasks/core/parseInput.js +0 -0
- /package/bin/{v5 → v7}/tasks/core/resolveCommand.js +0 -0
- /package/bin/{v5 → v7}/tasks/core/showUsage.js +0 -0
|
@@ -3,13 +3,13 @@ import getData from "./getData.js";
|
|
|
3
3
|
const startFunc = async ({ inRequestQuery, inTablePath }) => {
|
|
4
4
|
const dataAsArray = await getData({ inTablePath });
|
|
5
5
|
|
|
6
|
-
const filteredRows =
|
|
6
|
+
const filteredRows = dataAsArray.filter(item => {
|
|
7
7
|
return Object.entries(inRequestQuery).every(
|
|
8
8
|
([key, value]) => item[key] === value
|
|
9
9
|
)
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
return await
|
|
12
|
+
return await filteredRows;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export default startFunc;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import getData from "./getData.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = async ({ inPk, inTablePath }) => {
|
|
4
|
+
const dataAsArray = await getData({ inTablePath });
|
|
5
|
+
|
|
6
|
+
const filterRows = dataAsArray.filter(element => {
|
|
7
|
+
return element.pk === inPk;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
return await filterRows;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { startFunc };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Service from "./service.js";
|
|
2
|
+
import { ConflictError, StorageError } from "./errors.js";
|
|
3
|
+
|
|
4
|
+
const getFunc = async ({ req, res, inTablePath }) => {
|
|
5
|
+
try {
|
|
6
|
+
// const requestPk = req.params.pk;
|
|
7
|
+
const requestQuery = req.query;
|
|
8
|
+
|
|
9
|
+
const fromService = await Service({
|
|
10
|
+
inRequestQuery: requestQuery,
|
|
11
|
+
inTablePath
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
res.type("application/json").send(fromService);
|
|
15
|
+
} catch (err) {
|
|
16
|
+
|
|
17
|
+
if (err instanceof ConflictError)
|
|
18
|
+
return res.status(409).send(err.message);
|
|
19
|
+
|
|
20
|
+
if (err instanceof StorageError)
|
|
21
|
+
return res.status(500).send("Failed to persist data");
|
|
22
|
+
|
|
23
|
+
console.error(err);
|
|
24
|
+
res.status(500).send("Unexpected error");
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default getFunc;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import getData from "./getData.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = async ({ inRequestQuery, inTablePath }) => {
|
|
4
|
+
const dataAsArray = await getData({ inTablePath });
|
|
5
|
+
|
|
6
|
+
const filteredRows = dataAsArray.filter(item => {
|
|
7
|
+
return Object.entries(inRequestQuery).every(
|
|
8
|
+
([key, value]) => item[key] === value
|
|
9
|
+
)
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
return await filteredRows;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default startFunc;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cmd": "WithMail",
|
|
3
|
+
"file": "withMail",
|
|
4
|
+
"exportFile": "WithMail",
|
|
5
|
+
"group": "PostMethods",
|
|
6
|
+
"description": "Generate WithMail POST action",
|
|
7
|
+
"endPointsJs": {
|
|
8
|
+
"importLines": {
|
|
9
|
+
"toInsertLine": "import funcFromWithMail from './WithMail/controller.js';",
|
|
10
|
+
"duplicationCheck": "from './WithMail/controller.js'",
|
|
11
|
+
"insertAfter": [
|
|
12
|
+
"import funcFrom",
|
|
13
|
+
"import express"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"useLines": {
|
|
17
|
+
"toInsertLine1": "router.get('/WithMail', (req, res) => funcFromWithMail({ res, inTablePath: tablePath }));",
|
|
18
|
+
"toInsertLine": "router.post('/WithMail', express.json(), (req, res) => funcFromWithMail({ req, res, inTablePath: tablePath, inConfigPath: configPath }));",
|
|
19
|
+
"duplicationCheck": "router.use('/WithMail'",
|
|
20
|
+
"insertAfter": [
|
|
21
|
+
"router.",
|
|
22
|
+
"const router = "
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -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,47 @@
|
|
|
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
|
+
const fromCheckDuplicate = checkDuplicate({ inContent: content, inFuncName });
|
|
20
|
+
|
|
21
|
+
if (fromCheckDuplicate) {
|
|
22
|
+
summary.import.skipped = true;
|
|
23
|
+
|
|
24
|
+
if (showLog) console.log(summary);
|
|
25
|
+
|
|
26
|
+
return summary;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const index = findInsertIndex(content);
|
|
30
|
+
|
|
31
|
+
const before = content.slice(0, index);
|
|
32
|
+
const lineNumber = before.split("\n").length + 1;
|
|
33
|
+
|
|
34
|
+
const updated =
|
|
35
|
+
before + "\n" + importLine + content.slice(index);
|
|
36
|
+
|
|
37
|
+
writeFile(appJsPath, updated);
|
|
38
|
+
|
|
39
|
+
summary.import.added = true;
|
|
40
|
+
summary.import.line = lineNumber;
|
|
41
|
+
|
|
42
|
+
if (showLog) console.log(summary);
|
|
43
|
+
|
|
44
|
+
return summary;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default updateImports;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const checkDuplicate = ({ inContent, inEndpoint, inAppOrRouter }) => {
|
|
2
|
+
const localContent = inContent;
|
|
3
|
+
const localEndpoint = inEndpoint;
|
|
4
|
+
const stringToSearch = `${inAppOrRouter}.get('/${localEndpoint}'`;
|
|
5
|
+
|
|
6
|
+
return localContent.includes(stringToSearch);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default checkDuplicate;
|
|
@@ -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;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import readFile from "../common/readFile.js";
|
|
2
|
+
import writeFile from "../common/writeFile.js";
|
|
3
|
+
|
|
4
|
+
import buildUseLine from "./buildUseLine.js";
|
|
5
|
+
import checkDuplicate from "./checkDuplicate.js";
|
|
6
|
+
import findUseInsertIndex from "./findInsertIndex.js";
|
|
7
|
+
|
|
8
|
+
const appOrRouter = "router";
|
|
9
|
+
|
|
10
|
+
const updateAppUse = ({ appJsPath, endpoint, showLog, inFuncName }) => {
|
|
11
|
+
const summary = {
|
|
12
|
+
use: { added: false, skipped: false, line: null }
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const content = readFile(appJsPath);
|
|
16
|
+
|
|
17
|
+
const useLine = buildUseLine({
|
|
18
|
+
inAppOrRouter: appOrRouter,
|
|
19
|
+
inEndpoint: endpoint,
|
|
20
|
+
inFuncName
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const fromCheckDuplicate = checkDuplicate({
|
|
24
|
+
inContent: content,
|
|
25
|
+
inEndpoint: endpoint,
|
|
26
|
+
inAppOrRouter: appOrRouter
|
|
27
|
+
});
|
|
28
|
+
console.log("fromCheckDuplicate : ", fromCheckDuplicate);
|
|
29
|
+
|
|
30
|
+
if (fromCheckDuplicate) {
|
|
31
|
+
summary.use.skipped = true;
|
|
32
|
+
|
|
33
|
+
if (showLog) console.log(summary);
|
|
34
|
+
|
|
35
|
+
return summary;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const index = findUseInsertIndex(content);
|
|
39
|
+
|
|
40
|
+
const before = content.slice(0, index);
|
|
41
|
+
const lineNumber = before.split("\n").length + 1;
|
|
42
|
+
|
|
43
|
+
const updated =
|
|
44
|
+
before + "\n" + useLine + content.slice(index);
|
|
45
|
+
|
|
46
|
+
writeFile(appJsPath, updated);
|
|
47
|
+
|
|
48
|
+
summary.use.added = true;
|
|
49
|
+
summary.use.line = lineNumber;
|
|
50
|
+
|
|
51
|
+
if (showLog) console.log(summary);
|
|
52
|
+
|
|
53
|
+
return summary;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default updateAppUse;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const announce = ({ inResolvedFolderName }) => {
|
|
2
|
+
console.log(`[keshavsoft] Folder created: ${inResolvedFolderName}`);
|
|
3
|
+
|
|
4
|
+
console.log("");
|
|
5
|
+
console.log("Next:");
|
|
6
|
+
console.log("");
|
|
7
|
+
console.log(`cd ${inResolvedFolderName}`);
|
|
8
|
+
console.log(`npx kschema-api-gen AddSubRoute`);
|
|
9
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
|
|
8
|
+
export const locateSource = () => {
|
|
9
|
+
const templatePath = path.join(__dirname, "..", "template");
|
|
10
|
+
|
|
11
|
+
const versions = fs.readdirSync(templatePath);
|
|
12
|
+
|
|
13
|
+
const maxVersion = Math.max(
|
|
14
|
+
...versions.map(v => Number(v.replace("v", "")))
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
return path.join(templatePath, `v${maxVersion}`);
|
|
18
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
|
|
3
|
+
export default function resolveFolderName({ name, inDefaultFolderName = "InsertGenPk" }) {
|
|
4
|
+
const defaultFolderName = inDefaultFolderName;
|
|
5
|
+
|
|
6
|
+
// case 1: force new → timestamp
|
|
7
|
+
if (name === null) {
|
|
8
|
+
name = defaultFolderName;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// case 2: user provided → strict
|
|
12
|
+
if (fs.existsSync(name)) {
|
|
13
|
+
return {
|
|
14
|
+
KTF: false,
|
|
15
|
+
KReason: `Folder already exists : ${name}`
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return name;
|
|
20
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import updateImports from "./UpdateRoutesJs/updateImports/index.js";
|
|
2
|
+
import updateAppUse from "./UpdateRoutesJs/updateUse/index.js";
|
|
3
|
+
|
|
4
|
+
export default ({ appJsPath, endpoint }) => {
|
|
5
|
+
updateImports({ appJsPath, endpoint });
|
|
6
|
+
updateAppUse({ appJsPath, endpoint });
|
|
7
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
|
|
3
|
+
function updateEndPointsFile({ filePath, inTableName }) {
|
|
4
|
+
try {
|
|
5
|
+
let content = readFile(filePath);
|
|
6
|
+
|
|
7
|
+
content = content.replace("<TABLE_NAME>", inTableName);
|
|
8
|
+
|
|
9
|
+
writeFile(filePath, content);
|
|
10
|
+
} catch (e) {
|
|
11
|
+
handleError(e);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// read
|
|
16
|
+
function readFile(filePath) {
|
|
17
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// write
|
|
21
|
+
function writeFile(filePath, content) {
|
|
22
|
+
fs.writeFileSync(filePath, content);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// error handler
|
|
26
|
+
function handleError(e) {
|
|
27
|
+
console.error("ROUTE USE ERROR:", e.message);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { updateEndPointsFile };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { startFunc as Service } from "./service.js";
|
|
2
|
+
import { ConflictError, StorageError } from "./errors.js";
|
|
3
|
+
|
|
4
|
+
const getFunc = async ({ req, res, inTablePath }) => {
|
|
5
|
+
try {
|
|
6
|
+
const requestPk = req.params.pk;
|
|
7
|
+
|
|
8
|
+
const fromService = await Service({
|
|
9
|
+
inPk: requestPk,
|
|
10
|
+
inTablePath
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
res.type("application/json").send(fromService);
|
|
14
|
+
} catch (err) {
|
|
15
|
+
|
|
16
|
+
if (err instanceof ConflictError)
|
|
17
|
+
return res.status(409).send(err.message);
|
|
18
|
+
|
|
19
|
+
if (err instanceof StorageError)
|
|
20
|
+
return res.status(500).send("Failed to persist data");
|
|
21
|
+
|
|
22
|
+
console.error(err);
|
|
23
|
+
res.status(500).send("Unexpected error");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default getFunc;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class AppError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = this.constructor.name;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class ConflictError extends AppError { }
|
|
9
|
+
class StorageError extends AppError { }
|
|
10
|
+
|
|
11
|
+
export { AppError, ConflictError, StorageError };
|
|
@@ -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,47 @@
|
|
|
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
|
+
const fromCheckDuplicate = checkDuplicate({ inContent: content, inFuncName });
|
|
20
|
+
|
|
21
|
+
if (fromCheckDuplicate) {
|
|
22
|
+
summary.import.skipped = true;
|
|
23
|
+
|
|
24
|
+
if (showLog) console.log(summary);
|
|
25
|
+
|
|
26
|
+
return summary;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const index = findInsertIndex(content);
|
|
30
|
+
|
|
31
|
+
const before = content.slice(0, index);
|
|
32
|
+
const lineNumber = before.split("\n").length + 1;
|
|
33
|
+
|
|
34
|
+
const updated =
|
|
35
|
+
before + "\n" + importLine + content.slice(index);
|
|
36
|
+
|
|
37
|
+
writeFile(appJsPath, updated);
|
|
38
|
+
|
|
39
|
+
summary.import.added = true;
|
|
40
|
+
summary.import.line = lineNumber;
|
|
41
|
+
|
|
42
|
+
if (showLog) console.log(summary);
|
|
43
|
+
|
|
44
|
+
return summary;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default updateImports;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const checkDuplicate = ({ inContent, inEndpoint, inAppOrRouter }) => {
|
|
2
|
+
const localContent = inContent;
|
|
3
|
+
const localEndpoint = inEndpoint;
|
|
4
|
+
const stringToSearch = `${inAppOrRouter}.get('/${localEndpoint}'`;
|
|
5
|
+
|
|
6
|
+
return localContent.includes(stringToSearch);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default checkDuplicate;
|
|
@@ -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;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import readFile from "../common/readFile.js";
|
|
2
|
+
import writeFile from "../common/writeFile.js";
|
|
3
|
+
|
|
4
|
+
import buildUseLine from "./buildUseLine.js";
|
|
5
|
+
import checkDuplicate from "./checkDuplicate.js";
|
|
6
|
+
import findUseInsertIndex from "./findInsertIndex.js";
|
|
7
|
+
|
|
8
|
+
const appOrRouter = "router";
|
|
9
|
+
|
|
10
|
+
const updateAppUse = ({ appJsPath, endpoint, showLog, inFuncName }) => {
|
|
11
|
+
const summary = {
|
|
12
|
+
use: { added: false, skipped: false, line: null }
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const content = readFile(appJsPath);
|
|
16
|
+
|
|
17
|
+
const useLine = buildUseLine({
|
|
18
|
+
inAppOrRouter: appOrRouter,
|
|
19
|
+
inEndpoint: endpoint,
|
|
20
|
+
inFuncName
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const fromCheckDuplicate = checkDuplicate({
|
|
24
|
+
inContent: content,
|
|
25
|
+
inEndpoint: endpoint,
|
|
26
|
+
inAppOrRouter: appOrRouter
|
|
27
|
+
});
|
|
28
|
+
console.log("fromCheckDuplicate : ", fromCheckDuplicate);
|
|
29
|
+
|
|
30
|
+
if (fromCheckDuplicate) {
|
|
31
|
+
summary.use.skipped = true;
|
|
32
|
+
|
|
33
|
+
if (showLog) console.log(summary);
|
|
34
|
+
|
|
35
|
+
return summary;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const index = findUseInsertIndex(content);
|
|
39
|
+
|
|
40
|
+
const before = content.slice(0, index);
|
|
41
|
+
const lineNumber = before.split("\n").length + 1;
|
|
42
|
+
|
|
43
|
+
const updated =
|
|
44
|
+
before + "\n" + useLine + content.slice(index);
|
|
45
|
+
|
|
46
|
+
writeFile(appJsPath, updated);
|
|
47
|
+
|
|
48
|
+
summary.use.added = true;
|
|
49
|
+
summary.use.line = lineNumber;
|
|
50
|
+
|
|
51
|
+
if (showLog) console.log(summary);
|
|
52
|
+
|
|
53
|
+
return summary;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default updateAppUse;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const announce = ({ inResolvedFolderName }) => {
|
|
2
|
+
console.log(`[keshavsoft] Folder created: ${inResolvedFolderName}`);
|
|
3
|
+
|
|
4
|
+
console.log("");
|
|
5
|
+
console.log("Next:");
|
|
6
|
+
console.log("");
|
|
7
|
+
console.log(`cd ${inResolvedFolderName}`);
|
|
8
|
+
console.log(`npx kschema-api-gen AddSubRoute`);
|
|
9
|
+
};
|