arkos 1.0.18-beta → 1.0.20-beta
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/dist/cjs/app.js +1 -1
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/exports/middlewares/index.js +7 -0
- package/dist/cjs/exports/middlewares/index.js.map +1 -0
- package/dist/cjs/exports/utils/index.js.map +1 -1
- package/dist/cjs/modules/auth/auth.controller.js +38 -37
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +4 -5
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/auth/auth.service.js +27 -24
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js +8 -12
- package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js.map +1 -1
- package/dist/cjs/modules/auth/utils/helpers/auth.helpers.js +19 -0
- package/dist/cjs/modules/auth/utils/helpers/auth.helpers.js.map +1 -0
- package/dist/cjs/modules/base/base.controller.js +2 -29
- package/dist/cjs/modules/base/base.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js +42 -1
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/base/base.router.js +2 -2
- package/dist/cjs/modules/base/base.router.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.helpers.js +183 -0
- package/dist/cjs/modules/base/utils/helpers/base.helpers.js.map +1 -0
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +2 -3
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js +9 -11
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/cjs/modules/error-handler/error-handler.controller.js +2 -0
- package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/catch-async.js +1 -1
- package/dist/cjs/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/cjs/modules/file-uploader/file-uploader.service.js +4 -4
- package/dist/cjs/modules/file-uploader/file-uploader.service.js.map +1 -1
- package/dist/cjs/modules/file-uploader/utils/helpers/file-uploader.helpers.js +7 -5
- package/dist/cjs/modules/file-uploader/utils/helpers/file-uploader.helpers.js.map +1 -1
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/types/arkos-config.js.map +1 -1
- package/dist/cjs/types/auth.js.map +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/prisma-model-router-config.js +3 -0
- package/dist/cjs/types/prisma-model-router-config.js.map +1 -0
- package/dist/cjs/utils/features/api.features.js +3 -2
- package/dist/cjs/utils/features/api.features.js.map +1 -1
- package/dist/cjs/utils/helpers/api.features.helpers.js +4 -3
- package/dist/cjs/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/base.controller.helpers.js +77 -35
- package/dist/cjs/utils/helpers/base.controller.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/change-case.helpers.js +3 -3
- package/dist/cjs/utils/helpers/change-case.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/fs.helpers.js +14 -45
- package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/models.helpers.js +35 -30
- package/dist/cjs/utils/helpers/models.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +5 -3
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/cjs/utils/scripts/export-prisma-types.js +3 -3
- package/dist/cjs/utils/scripts/export-prisma-types.js.map +1 -1
- package/dist/cjs/utils/scripts/generate-insomnia-collection.js +228 -0
- package/dist/cjs/utils/scripts/generate-insomnia-collection.js.map +1 -0
- package/dist/cjs/utils/scripts/generate-zod-schemas.js +4 -3
- package/dist/cjs/utils/scripts/generate-zod-schemas.js.map +1 -1
- package/dist/cjs/utils/scripts/index.js +12 -0
- package/dist/cjs/utils/scripts/index.js.map +1 -0
- package/dist/es2020/app.js +1 -1
- package/dist/es2020/app.js.map +1 -1
- package/dist/es2020/exports/middlewares/index.js +2 -0
- package/dist/es2020/exports/middlewares/index.js.map +1 -0
- package/dist/es2020/exports/utils/index.js.map +1 -1
- package/dist/es2020/modules/auth/auth.controller.js +39 -38
- package/dist/es2020/modules/auth/auth.controller.js.map +1 -1
- package/dist/es2020/modules/auth/auth.router.js +1 -2
- package/dist/es2020/modules/auth/auth.router.js.map +1 -1
- package/dist/es2020/modules/auth/auth.service.js +27 -24
- package/dist/es2020/modules/auth/auth.service.js.map +1 -1
- package/dist/es2020/modules/auth/utils/helpers/auth.controller.helpers.js +8 -12
- package/dist/es2020/modules/auth/utils/helpers/auth.controller.helpers.js.map +1 -1
- package/dist/es2020/modules/auth/utils/helpers/auth.helpers.js +12 -0
- package/dist/es2020/modules/auth/utils/helpers/auth.helpers.js.map +1 -0
- package/dist/es2020/modules/base/base.controller.js +2 -29
- package/dist/es2020/modules/base/base.controller.js.map +1 -1
- package/dist/es2020/modules/base/base.middlewares.js +38 -1
- package/dist/es2020/modules/base/base.middlewares.js.map +1 -1
- package/dist/es2020/modules/base/base.router.js +2 -2
- package/dist/es2020/modules/base/base.router.js.map +1 -1
- package/dist/es2020/modules/base/utils/helpers/base.helpers.js +177 -0
- package/dist/es2020/modules/base/utils/helpers/base.helpers.js.map +1 -0
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js +1 -2
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/es2020/modules/base/utils/helpers/base.service.helpers.js +9 -11
- package/dist/es2020/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/es2020/modules/error-handler/error-handler.controller.js +2 -0
- package/dist/es2020/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/es2020/modules/error-handler/utils/catch-async.js +1 -1
- package/dist/es2020/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/es2020/modules/file-uploader/file-uploader.service.js +4 -4
- package/dist/es2020/modules/file-uploader/file-uploader.service.js.map +1 -1
- package/dist/es2020/modules/file-uploader/utils/helpers/file-uploader.helpers.js +7 -5
- package/dist/es2020/modules/file-uploader/utils/helpers/file-uploader.helpers.js.map +1 -1
- package/dist/es2020/server.js +1 -1
- package/dist/es2020/server.js.map +1 -1
- package/dist/es2020/types/arkos-config.js.map +1 -1
- package/dist/es2020/types/auth.js.map +1 -1
- package/dist/es2020/types/index.js.map +1 -1
- package/dist/es2020/types/prisma-model-router-config.js +2 -0
- package/dist/es2020/types/prisma-model-router-config.js.map +1 -0
- package/dist/es2020/utils/features/api.features.js +3 -2
- package/dist/es2020/utils/features/api.features.js.map +1 -1
- package/dist/es2020/utils/helpers/api.features.helpers.js +4 -3
- package/dist/es2020/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/base.controller.helpers.js +75 -31
- package/dist/es2020/utils/helpers/base.controller.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/change-case.helpers.js +3 -3
- package/dist/es2020/utils/helpers/change-case.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/fs.helpers.js +13 -44
- package/dist/es2020/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/models.helpers.js +36 -31
- package/dist/es2020/utils/helpers/models.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/prisma.helpers.js +6 -4
- package/dist/es2020/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/es2020/utils/scripts/export-prisma-types.js +3 -3
- package/dist/es2020/utils/scripts/export-prisma-types.js.map +1 -1
- package/dist/es2020/utils/scripts/generate-insomnia-collection.js +189 -0
- package/dist/es2020/utils/scripts/generate-insomnia-collection.js.map +1 -0
- package/dist/es2020/utils/scripts/generate-zod-schemas.js +4 -3
- package/dist/es2020/utils/scripts/generate-zod-schemas.js.map +1 -1
- package/dist/es2020/utils/scripts/index.js +10 -0
- package/dist/es2020/utils/scripts/index.js.map +1 -0
- package/dist/types/exports/middlewares/index.d.ts +1 -0
- package/dist/types/exports/utils/index.d.ts +1 -0
- package/dist/types/modules/auth/auth.service.d.ts +3 -3
- package/dist/types/modules/auth/utils/helpers/auth.helpers.d.ts +2 -0
- package/dist/types/modules/base/base.middlewares.d.ts +6 -1
- package/dist/types/modules/base/utils/helpers/base.helpers.d.ts +5 -0
- package/dist/types/modules/base/utils/helpers/base.service.helpers.d.ts +1 -1
- package/dist/types/types/arkos-config.d.ts +5 -0
- package/dist/types/types/auth.d.ts +9 -8
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types/types/prisma-model-router-config.d.ts +18 -0
- package/dist/types/utils/helpers/base.controller.helpers.d.ts +4 -6
- package/dist/types/utils/helpers/fs.helpers.d.ts +2 -2
- package/dist/types/utils/scripts/generate-insomnia-collection.d.ts +1 -0
- package/dist/types/utils/scripts/index.d.ts +2 -0
- package/package.json +55 -34
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { kebabCase } from "../helpers/change-case.helpers";
|
|
11
|
+
import fs from "fs";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import pluralize from "pluralize";
|
|
14
|
+
import { getAppRoutes } from "../helpers/base.controller.helpers";
|
|
15
|
+
function generateInsomniaCollection() {
|
|
16
|
+
const routes = getAppRoutes();
|
|
17
|
+
const resourceTypes = [
|
|
18
|
+
...new Set(routes.map((route) => route.path.split("/")[1] || "root")),
|
|
19
|
+
];
|
|
20
|
+
const collection = {
|
|
21
|
+
_type: "export",
|
|
22
|
+
__export_format: 4,
|
|
23
|
+
__export_date: new Date().toISOString(),
|
|
24
|
+
__export_source: "script-generated",
|
|
25
|
+
resources: [],
|
|
26
|
+
};
|
|
27
|
+
collection.resources.push({
|
|
28
|
+
_id: "wrk_arkos",
|
|
29
|
+
parentId: null,
|
|
30
|
+
modified: new Date().toISOString(),
|
|
31
|
+
created: new Date().toISOString(),
|
|
32
|
+
name: "Project API",
|
|
33
|
+
description: "Automatically generated Arkos API collection",
|
|
34
|
+
_type: "workspace",
|
|
35
|
+
});
|
|
36
|
+
const routesByResource = resourceTypes.reduce((acc, resourceType) => {
|
|
37
|
+
if (resourceType === "root")
|
|
38
|
+
return acc;
|
|
39
|
+
acc[resourceType] = {
|
|
40
|
+
findMany: routes.find((r) => r.method === "GET" && r.path === `/${resourceType}`),
|
|
41
|
+
findOne: routes.find((r) => r.method === "GET" && r.path === `/${resourceType}/:id`),
|
|
42
|
+
createOne: routes.find((r) => r.method === "POST" && r.path === `/${resourceType}`),
|
|
43
|
+
createMany: routes.find((r) => r.method === "POST" && r.path === `/${resourceType}/many`),
|
|
44
|
+
updateOne: routes.find((r) => r.method === "PATCH" && r.path === `/${resourceType}/:id`),
|
|
45
|
+
updateMany: routes.find((r) => r.method === "PATCH" && r.path === `/${resourceType}/many`),
|
|
46
|
+
deleteOne: routes.find((r) => r.method === "DELETE" && r.path === `/${resourceType}/:id`),
|
|
47
|
+
deleteMany: routes.find((r) => r.method === "DELETE" && r.path === `/${resourceType}/many`),
|
|
48
|
+
};
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
Object.entries(routesByResource).forEach(([resourceType, resourceRoutes], index) => {
|
|
52
|
+
const folderId = `fld_${resourceType}`;
|
|
53
|
+
collection.resources.push({
|
|
54
|
+
_id: folderId,
|
|
55
|
+
parentId: "wrk_arkos",
|
|
56
|
+
modified: new Date().toISOString(),
|
|
57
|
+
created: new Date().toISOString(),
|
|
58
|
+
name: resourceType
|
|
59
|
+
.replace(/-/g, " ")
|
|
60
|
+
.replace(/\b\w/g, (l) => l.toUpperCase()),
|
|
61
|
+
description: `${resourceType
|
|
62
|
+
.replace(/-/g, " ")
|
|
63
|
+
.replace(/\b\w/g, (l) => l.toUpperCase())} endpoints`,
|
|
64
|
+
environment: {},
|
|
65
|
+
environmentPropertyOrder: null,
|
|
66
|
+
metaSortKey: -1000 + index * 100,
|
|
67
|
+
_type: "request_group",
|
|
68
|
+
});
|
|
69
|
+
const methodMappings = [
|
|
70
|
+
{ key: "findMany", name: "Find Many", method: "GET" },
|
|
71
|
+
{ key: "findOne", name: "Find One", method: "GET" },
|
|
72
|
+
{ key: "createOne", name: "Create One", method: "POST" },
|
|
73
|
+
{ key: "createMany", name: "Create Many", method: "POST" },
|
|
74
|
+
{ key: "updateOne", name: "Update One", method: "PATCH" },
|
|
75
|
+
{ key: "updateMany", name: "Update Many", method: "PATCH" },
|
|
76
|
+
{ key: "deleteOne", name: "Delete One", method: "DELETE" },
|
|
77
|
+
{ key: "deleteMany", name: "Delete Many", method: "DELETE" },
|
|
78
|
+
];
|
|
79
|
+
methodMappings.forEach((mapping, routeIndex) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const route = resourceRoutes[mapping.key];
|
|
81
|
+
if (!route)
|
|
82
|
+
return;
|
|
83
|
+
const modelName = kebabCase(pluralize.singular(mapping.key));
|
|
84
|
+
const reqId = `req_${resourceType}_${mapping.key}`;
|
|
85
|
+
const dtoPath = path.join(process.cwd(), `src/modules/${modelName}/dtos`);
|
|
86
|
+
const dotMapping = {
|
|
87
|
+
createOne: `create-${modelName}.dto.ts`,
|
|
88
|
+
updateOne: `create-${modelName}.dto.ts`,
|
|
89
|
+
};
|
|
90
|
+
const dto = yield import(path.join(dtoPath, dotMapping[mapping.key]));
|
|
91
|
+
collection.resources.push({
|
|
92
|
+
_id: reqId,
|
|
93
|
+
parentId: folderId,
|
|
94
|
+
modified: new Date().toISOString(),
|
|
95
|
+
created: new Date().toISOString(),
|
|
96
|
+
url: `{{BASE_URL}}/${route.path}`,
|
|
97
|
+
name: mapping.name,
|
|
98
|
+
description: `${mapping.method} request for ${route.path}`,
|
|
99
|
+
method: route.method,
|
|
100
|
+
body: route.method !== "GET"
|
|
101
|
+
? {
|
|
102
|
+
mimeType: "application/json",
|
|
103
|
+
text: route.method === "POST" || route.method === "PATCH"
|
|
104
|
+
? route.path.includes("/many")
|
|
105
|
+
? "[{}]"
|
|
106
|
+
: "{}"
|
|
107
|
+
: "[]",
|
|
108
|
+
}
|
|
109
|
+
: {},
|
|
110
|
+
parameters: route.path.includes(":")
|
|
111
|
+
? route.path
|
|
112
|
+
.split("/")
|
|
113
|
+
.filter((p) => p.startsWith(":"))
|
|
114
|
+
.map((param) => ({
|
|
115
|
+
id: `par_${param.slice(1)}`,
|
|
116
|
+
name: param.slice(1),
|
|
117
|
+
value: "",
|
|
118
|
+
description: `${param.slice(1)} parameter`,
|
|
119
|
+
disabled: false,
|
|
120
|
+
}))
|
|
121
|
+
: [],
|
|
122
|
+
headers: route.method !== "GET"
|
|
123
|
+
? [
|
|
124
|
+
{
|
|
125
|
+
name: "Content-Type",
|
|
126
|
+
value: "application/json",
|
|
127
|
+
},
|
|
128
|
+
]
|
|
129
|
+
: [],
|
|
130
|
+
authentication: {},
|
|
131
|
+
metaSortKey: -1000 + routeIndex * 10,
|
|
132
|
+
isPrivate: false,
|
|
133
|
+
settingStoreCookies: true,
|
|
134
|
+
settingSendCookies: true,
|
|
135
|
+
settingDisableRenderRequestBody: false,
|
|
136
|
+
settingEncodeUrl: true,
|
|
137
|
+
settingRebuildPath: true,
|
|
138
|
+
settingFollowRedirects: "global",
|
|
139
|
+
_type: "request",
|
|
140
|
+
});
|
|
141
|
+
}));
|
|
142
|
+
});
|
|
143
|
+
const rootFolderId = "fld_root";
|
|
144
|
+
collection.resources.push({
|
|
145
|
+
_id: rootFolderId,
|
|
146
|
+
parentId: "wrk_arkos",
|
|
147
|
+
modified: new Date().toISOString(),
|
|
148
|
+
created: new Date().toISOString(),
|
|
149
|
+
name: "Root",
|
|
150
|
+
description: "Root API endpoints",
|
|
151
|
+
environment: {},
|
|
152
|
+
environmentPropertyOrder: null,
|
|
153
|
+
metaSortKey: -100,
|
|
154
|
+
_type: "request_group",
|
|
155
|
+
});
|
|
156
|
+
const rootRoutes = routes.filter((route) => route.path === "/api" || route.path === "/available-routes");
|
|
157
|
+
rootRoutes.forEach((route, index) => {
|
|
158
|
+
collection.resources.push({
|
|
159
|
+
_id: `req_root_${route.path.slice(1)}`,
|
|
160
|
+
parentId: rootFolderId,
|
|
161
|
+
modified: new Date().toISOString(),
|
|
162
|
+
created: new Date().toISOString(),
|
|
163
|
+
url: `{{BASE_URL}}/${route.path}`,
|
|
164
|
+
name: route.path === "/api" ? "Welcome" : "Available Routes",
|
|
165
|
+
description: `${route.method} request for ${route.path}`,
|
|
166
|
+
method: route.method,
|
|
167
|
+
body: {},
|
|
168
|
+
parameters: [],
|
|
169
|
+
headers: [],
|
|
170
|
+
authentication: {},
|
|
171
|
+
metaSortKey: -1000 + index * 10,
|
|
172
|
+
isPrivate: false,
|
|
173
|
+
settingStoreCookies: true,
|
|
174
|
+
settingSendCookies: true,
|
|
175
|
+
settingDisableRenderRequestBody: false,
|
|
176
|
+
settingEncodeUrl: true,
|
|
177
|
+
settingRebuildPath: true,
|
|
178
|
+
settingFollowRedirects: "global",
|
|
179
|
+
_type: "request",
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
return collection;
|
|
183
|
+
}
|
|
184
|
+
export function writeInsomniaCollectionJson() {
|
|
185
|
+
const insomniaCollection = generateInsomniaCollection();
|
|
186
|
+
fs.writeFileSync(path.join(process.cwd(), ".cache", "insomnia-collection.json"), JSON.stringify(insomniaCollection, null, 2));
|
|
187
|
+
console.log("Insomnia collection generated successfully! .cache/insomnia-collection.json");
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=generate-insomnia-collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-insomnia-collection.js","sourceRoot":"","sources":["../../../../src/utils/scripts/generate-insomnia-collection.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAiElE,SAAS,0BAA0B;IACjC,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAG9B,MAAM,aAAa,GAAa;QAC9B,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;KACtE,CAAC;IAGF,MAAM,UAAU,GAAuB;QACrC,KAAK,EAAE,QAAQ;QACf,eAAe,EAAE,CAAC;QAClB,aAAa,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACvC,eAAe,EAAE,kBAAkB;QACnC,SAAS,EAAE,EAAE;KACd,CAAC;IAGF,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC;QACxB,GAAG,EAAE,WAAW;QAChB,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAClC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACjC,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,8CAA8C;QAC3D,KAAK,EAAE,WAAW;KACnB,CAAC,CAAC;IAGH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IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC,CAC5C,CAAC;IAEF,OAAO,CAAC,GAAG,CACT,6EAA6E,CAC9E,CAAC;AACJ,CAAC","sourcesContent":["// import { kebabCase } from \"change-case\";\nimport { kebabCase } from \"../helpers/change-case.helpers\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport pluralize from \"pluralize\";\n// import DtoParser from \"./dto-parser\";\nimport { getAppRoutes } from \"../helpers/base.controller.helpers\";\n\n// Define types for the routes and collection\ninterface Route {\n method: string;\n path: string;\n}\n\ninterface InsomniaResource {\n _id: string;\n parentId: string | null;\n modified: string;\n created: string;\n name: string;\n description?: string;\n _type: string;\n url?: string;\n method?: string;\n body?: {\n mimeType?: string;\n text?: string;\n };\n parameters?: Array<{\n id: string;\n name: string;\n value: string;\n description: string;\n disabled: boolean;\n }>;\n headers?: Array<{\n name: string;\n value: string;\n }>;\n authentication?: Record<string, unknown>;\n metaSortKey?: number;\n environment?: Record<string, unknown>;\n environmentPropertyOrder?: null;\n isPrivate?: boolean;\n settingStoreCookies?: boolean;\n settingSendCookies?: boolean;\n settingDisableRenderRequestBody?: boolean;\n settingEncodeUrl?: boolean;\n settingRebuildPath?: boolean;\n settingFollowRedirects?: string;\n}\n\ninterface InsomniaCollection {\n _type: string;\n __export_format: number;\n __export_date: string;\n __export_source: string;\n resources: InsomniaResource[];\n}\n\ninterface ResourceRoutes {\n findMany?: Route;\n findOne?: Route;\n createOne?: Route;\n createMany?: Route;\n updateOne?: Route;\n updateMany?: Route;\n deleteOne?: Route;\n deleteMany?: Route;\n}\n\nfunction generateInsomniaCollection(): InsomniaCollection {\n const routes = getAppRoutes();\n\n // Unique resource types\n const resourceTypes: string[] = [\n ...new Set(routes.map((route) => route.path.split(\"/\")[1] || \"root\")),\n ];\n\n // Base collection structure\n const collection: InsomniaCollection = {\n _type: \"export\",\n __export_format: 4,\n __export_date: new Date().toISOString(),\n __export_source: \"script-generated\",\n resources: [],\n };\n\n // Add workspace\n collection.resources.push({\n _id: \"wrk_arkos\",\n parentId: null,\n modified: new Date().toISOString(),\n created: new Date().toISOString(),\n name: \"Project API\",\n description: \"Automatically generated Arkos API collection\",\n _type: \"workspace\",\n });\n\n // Group routes by resource type\n const routesByResource: Record<string, ResourceRoutes> = resourceTypes.reduce(\n (acc, resourceType) => {\n if (resourceType === \"root\") return acc;\n\n acc[resourceType] = {\n findMany: routes.find(\n (r) => r.method === \"GET\" && r.path === `/${resourceType}`\n ),\n findOne: routes.find(\n (r) => r.method === \"GET\" && r.path === `/${resourceType}/:id`\n ),\n createOne: routes.find(\n (r) => r.method === \"POST\" && r.path === `/${resourceType}`\n ),\n createMany: routes.find(\n (r) => r.method === \"POST\" && r.path === `/${resourceType}/many`\n ),\n updateOne: routes.find(\n (r) => r.method === \"PATCH\" && r.path === `/${resourceType}/:id`\n ),\n updateMany: routes.find(\n (r) => r.method === \"PATCH\" && r.path === `/${resourceType}/many`\n ),\n deleteOne: routes.find(\n (r) => r.method === \"DELETE\" && r.path === `/${resourceType}/:id`\n ),\n deleteMany: routes.find(\n (r) => r.method === \"DELETE\" && r.path === `/${resourceType}/many`\n ),\n };\n\n return acc;\n },\n {} as Record<string, any>\n );\n\n // Create folders and requests for each resource type\n Object.entries(routesByResource).forEach(\n ([resourceType, resourceRoutes], index) => {\n // Main resource folder\n const folderId = `fld_${resourceType}`;\n collection.resources.push({\n _id: folderId,\n parentId: \"wrk_arkos\",\n modified: new Date().toISOString(),\n created: new Date().toISOString(),\n name: resourceType\n .replace(/-/g, \" \")\n .replace(/\\b\\w/g, (l) => l.toUpperCase()),\n description: `${resourceType\n .replace(/-/g, \" \")\n .replace(/\\b\\w/g, (l) => l.toUpperCase())} endpoints`,\n environment: {},\n environmentPropertyOrder: null,\n metaSortKey: -1000 + index * 100,\n _type: \"request_group\",\n });\n\n // Create specific method requests\n const methodMappings = [\n { key: \"findMany\", name: \"Find Many\", method: \"GET\" },\n { key: \"findOne\", name: \"Find One\", method: \"GET\" },\n { key: \"createOne\", name: \"Create One\", method: \"POST\" },\n { key: \"createMany\", name: \"Create Many\", method: \"POST\" },\n { key: \"updateOne\", name: \"Update One\", method: \"PATCH\" },\n { key: \"updateMany\", name: \"Update Many\", method: \"PATCH\" },\n { key: \"deleteOne\", name: \"Delete One\", method: \"DELETE\" },\n { key: \"deleteMany\", name: \"Delete Many\", method: \"DELETE\" },\n ];\n\n methodMappings.forEach(async (mapping, routeIndex) => {\n const route = resourceRoutes[mapping.key as keyof ResourceRoutes];\n if (!route) return;\n\n const modelName = kebabCase(pluralize.singular(mapping.key));\n const reqId = `req_${resourceType}_${mapping.key}`;\n const dtoPath = path.join(\n process.cwd(),\n `src/modules/${modelName}/dtos`\n );\n\n const dotMapping: Record<string, string> = {\n createOne: `create-${modelName}.dto.ts`,\n updateOne: `create-${modelName}.dto.ts`,\n };\n\n const dto = await import(path.join(dtoPath, dotMapping[mapping.key]));\n\n collection.resources.push({\n _id: reqId,\n parentId: folderId,\n modified: new Date().toISOString(),\n created: new Date().toISOString(),\n url: `{{BASE_URL}}/${route.path}`,\n name: mapping.name,\n description: `${mapping.method} request for ${route.path}`,\n method: route.method,\n body:\n route.method !== \"GET\"\n ? {\n mimeType: \"application/json\",\n text:\n route.method === \"POST\" || route.method === \"PATCH\"\n ? route.path.includes(\"/many\")\n ? \"[{}]\" // array for many\n : \"{}\" // object for single\n : \"[]\", // array for delete\n }\n : {},\n parameters: route.path.includes(\":\")\n ? route.path\n .split(\"/\")\n .filter((p) => p.startsWith(\":\"))\n .map((param) => ({\n id: `par_${param.slice(1)}`,\n name: param.slice(1),\n value: \"\",\n description: `${param.slice(1)} parameter`,\n disabled: false,\n }))\n : [],\n headers:\n route.method !== \"GET\"\n ? [\n {\n name: \"Content-Type\",\n value: \"application/json\",\n },\n ]\n : [],\n authentication: {},\n metaSortKey: -1000 + routeIndex * 10,\n isPrivate: false,\n settingStoreCookies: true,\n settingSendCookies: true,\n settingDisableRenderRequestBody: false,\n settingEncodeUrl: true,\n settingRebuildPath: true,\n settingFollowRedirects: \"global\",\n _type: \"request\",\n });\n });\n }\n );\n\n // Add root routes (api, available-routes)\n const rootFolderId = \"fld_root\";\n collection.resources.push({\n _id: rootFolderId,\n parentId: \"wrk_arkos\",\n modified: new Date().toISOString(),\n created: new Date().toISOString(),\n name: \"Root\",\n description: \"Root API endpoints\",\n environment: {},\n environmentPropertyOrder: null,\n metaSortKey: -100,\n _type: \"request_group\",\n });\n\n const rootRoutes = routes.filter(\n (route) => route.path === \"/api\" || route.path === \"/available-routes\"\n );\n rootRoutes.forEach((route, index) => {\n collection.resources.push({\n _id: `req_root_${route.path.slice(1)}`,\n parentId: rootFolderId,\n modified: new Date().toISOString(),\n created: new Date().toISOString(),\n url: `{{BASE_URL}}/${route.path}`,\n name: route.path === \"/api\" ? \"Welcome\" : \"Available Routes\",\n description: `${route.method} request for ${route.path}`,\n method: route.method,\n body: {},\n parameters: [],\n headers: [],\n authentication: {},\n metaSortKey: -1000 + index * 10,\n isPrivate: false,\n settingStoreCookies: true,\n settingSendCookies: true,\n settingDisableRenderRequestBody: false,\n settingEncodeUrl: true,\n settingRebuildPath: true,\n settingFollowRedirects: \"global\",\n _type: \"request\",\n });\n });\n\n return collection;\n}\n\n// Example usage\nexport function writeInsomniaCollectionJson() {\n // Generate the collection\n // const dtoParser = new DtoParser(\"./src/modules\");\n // const dtoBodies = dtoParser.parseAllDtos();\n\n const insomniaCollection = generateInsomniaCollection();\n\n // Write to file\n fs.writeFileSync(\n path.join(process.cwd(), \".cache\", \"insomnia-collection.json\"),\n JSON.stringify(insomniaCollection, null, 2)\n );\n\n console.log(\n \"Insomnia collection generated successfully! .cache/insomnia-collection.json\"\n );\n}\n"]}
|
|
@@ -24,7 +24,7 @@ function generateZodSchemas(inputContent) {
|
|
|
24
24
|
function typeToZodSchema(type, isOptional = false) {
|
|
25
25
|
type = type.trim();
|
|
26
26
|
const baseSchema = (() => {
|
|
27
|
-
if (type.includes("Date")) {
|
|
27
|
+
if (type === null || type === void 0 ? void 0 : type.includes("Date")) {
|
|
28
28
|
return `z.date().or(z.string()).refine((val) => val instanceof Date || !isNaN(Date.parse(val)), "Data inválida")`;
|
|
29
29
|
}
|
|
30
30
|
switch (type) {
|
|
@@ -37,7 +37,7 @@ function generateZodSchemas(inputContent) {
|
|
|
37
37
|
case "any":
|
|
38
38
|
return "z.any()";
|
|
39
39
|
default:
|
|
40
|
-
if (type.includes("[]")) {
|
|
40
|
+
if (type === null || type === void 0 ? void 0 : type.includes("[]")) {
|
|
41
41
|
const arrayType = type.replace("[]", "");
|
|
42
42
|
switch (arrayType) {
|
|
43
43
|
case "string":
|
|
@@ -74,8 +74,9 @@ function generateZodSchemas(inputContent) {
|
|
|
74
74
|
.map((line) => line.trim())
|
|
75
75
|
.filter((line) => line)
|
|
76
76
|
.map((line) => {
|
|
77
|
+
var _a;
|
|
77
78
|
const [propName, type] = line.split(":").map((part) => part.trim());
|
|
78
|
-
if (["createdAt", "updatedAt", "deletedAt"].includes(propName.replace("?", ""))) {
|
|
79
|
+
if ((_a = ["createdAt", "updatedAt", "deletedAt"]) === null || _a === void 0 ? void 0 : _a.includes(propName.replace("?", ""))) {
|
|
79
80
|
return null;
|
|
80
81
|
}
|
|
81
82
|
const isOptional = propName.endsWith("?");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-zod-schemas.js","sourceRoot":"","sources":["../../../../src/utils/scripts/generate-zod-schemas.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,SAAe,kBAAkB,CAAC,YAAoB;;QACpD,IAAI,MAAM,GAAG,8BAA8B,CAAC;QAG5C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC5B,MAAM,SAAS,GAAG,8BAA8B,CAAC;QACjD,IAAI,SAAS,CAAC;QACd,OAAO,CAAC,SAAS,GAAG,SAAS,CA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";\n\nasync function generateZodSchemas(inputContent: string): Promise<any> {\n let output = `import { z } from \"zod\";\\n\\n`;\n\n // Extract enum names first to help identify enum types later\n const enumNames = new Set();\n const enumRegex = /export enum (\\w+) {([^}]+)}/g;\n let enumMatch;\n while ((enumMatch = enumRegex.exec(inputContent)) !== null) {\n const enumName = enumMatch[1];\n const enumValues = enumMatch[2];\n enumNames.add(enumName);\n\n // Keep original enum definition\n output += `export enum ${enumName} {\\n${enumValues}\\n}\\n\\n`;\n }\n\n // Helper function to convert type to zod schema\n function typeToZodSchema(type: string, isOptional: boolean = false): string {\n type = type.trim();\n const baseSchema = (() => {\n if (type?.includes(\"Date\")) {\n return `z.date().or(z.string()).refine((val) => val instanceof Date || !isNaN(Date.parse(val)), \"Data inválida\")`;\n }\n switch (type) {\n case \"string\":\n return \"z.string()\";\n case \"number\":\n return \"z.number()\";\n case \"boolean\":\n return \"z.boolean()\";\n case \"any\":\n return \"z.any()\";\n default:\n // Handle arrays\n if (type?.includes(\"[]\")) {\n const arrayType = type.replace(\"[]\", \"\");\n // Handle primitive types in arrays\n switch (arrayType) {\n case \"string\":\n return \"z.array(z.string())\";\n case \"number\":\n return \"z.array(z.number())\";\n case \"boolean\":\n return \"z.array(z.boolean())\";\n default:\n // Check if it's an enum type\n if (enumNames.has(arrayType)) {\n return `z.array(z.nativeEnum(${arrayType}))`;\n }\n // Otherwise it's a relation/model type\n return `z.array(${arrayType}Schema)`;\n }\n }\n // Handle single types\n if (type.match(/^[A-Z]/)) {\n // Check if it's an enum type\n if (enumNames.has(type)) {\n return `z.nativeEnum(${type})`;\n }\n // Otherwise it's a relation/model type\n return `${type}Schema`;\n }\n return \"z.any()\";\n }\n })();\n\n return isOptional ? `${baseSchema}.optional()` : baseSchema;\n }\n\n // Extract and generate interface schemas\n const interfaceRegex = /export interface (\\w+) {([^}]+)}/g;\n let interfaceMatch;\n while ((interfaceMatch = interfaceRegex.exec(inputContent)) !== null) {\n const interfaceName = interfaceMatch[1];\n const interfaceBody = interfaceMatch[2];\n\n // Parse interface properties\n const properties = interfaceBody\n .split(\";\")\n .map((line) => line.trim())\n .filter((line) => line)\n .map((line) => {\n const [propName, type] = line.split(\":\").map((part) => part.trim());\n // Skip createdAt, updatedAt, and deletedAt\n if (\n [\"createdAt\", \"updatedAt\", \"deletedAt\"]?.includes(\n propName.replace(\"?\", \"\")\n )\n ) {\n return null;\n }\n const isOptional = propName.endsWith(\"?\");\n const cleanPropName = propName.replace(\"?\", \"\");\n return { name: cleanPropName, type, isOptional };\n })\n .filter((prop) => prop !== null);\n\n output += `export const ${interfaceName}Schema = z.object({\\n`;\n properties.forEach((prop, index) => {\n if (prop) {\n output += ` ${prop.name}: ${typeToZodSchema(\n prop.type,\n prop.isOptional\n )}`;\n if (index < properties.length - 1) output += \",\";\n output += \"\\n\";\n }\n });\n output += \"});\\n\\n\";\n }\n\n return output;\n}\n\n// Main execution\nasync function main() {\n try {\n const inputContent = await fs.readFile(\n path.join(process.cwd(), \".cache/types\", \"prisma.ts\"),\n \"utf-8\"\n );\n const generatedSchemas = await generateZodSchemas(inputContent);\n await fs.writeFile(\n path.join(process.cwd(), \".cache/generated-schemas.ts\"),\n generatedSchemas\n );\n console.info(\"Zod schemas generated successfully!\");\n } catch (error) {\n console.error(\"Error generating schemas:\", error);\n process.exit(1);\n }\n}\n\nmain();\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { writeInsomniaCollectionJson } from "./generate-insomnia-collection";
|
|
3
|
+
const args = process.argv.slice(2);
|
|
4
|
+
const command = args[0];
|
|
5
|
+
switch (command) {
|
|
6
|
+
case "generate-insomnia-collection":
|
|
7
|
+
writeInsomniaCollectionJson();
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/scripts/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAE7E,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAExB,QAAQ,OAAO,EAAE,CAAC;IAChB,KAAK,8BAA8B;QACjC,2BAA2B,EAAE,CAAC;QAC9B,MAAM;AACV,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { writeInsomniaCollectionJson } from \"./generate-insomnia-collection\";\n\nconst args = process.argv.slice(2);\nconst command = args[0];\n\nswitch (command) {\n case \"generate-insomnia-collection\":\n writeInsomniaCollectionJson();\n break;\n}\n\n// if (command === \"generate-something\") {\n// console.log(\"Hello World from arkos generate-something!\");\n// console.log(\"This is running from your installed arkos package.\");\n// } else {\n// console.log(\"Available commands:\");\n// console.log(\" generate-something - Prints a hello world message\");\n// console.log(\"\\nUsage: pnpm arkos [command]\");\n// }\n\n// // 3. Optional: Create an index.js file in the root:\n// // index.js\n\n// // This allows your package to be used programmatically\n// module.exports = {\n// generateSomething: () => {\n// console.log(\"Hello World from arkos generate-something!\");\n// console.log(\"This is running from your imported arkos package.\");\n// },\n// };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { addPrismaQueryOptionsToRequestQuery, handleRequestBodyValidationAndTransformation, } from "../../modules/base/base.middlewares";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { User } from "../../types";
|
|
2
2
|
import { ArkosRequest, ArkosResponse, ArkosNextFunction, ArkosRequestHandler } from "../../types";
|
|
3
|
-
import { AuthConfigs, AuthJwtPayload,
|
|
3
|
+
import { AuthConfigs, AuthJwtPayload, BaseControllerActions } from "../../types/auth";
|
|
4
4
|
import { MsDuration } from "./utils/helpers/auth.controller.helpers";
|
|
5
5
|
declare class AuthService {
|
|
6
6
|
signJwtToken(id: number | string, expiresIn?: MsDuration | number, secret?: string): string;
|
|
@@ -9,10 +9,10 @@ declare class AuthService {
|
|
|
9
9
|
isPasswordStrong(password: string): boolean;
|
|
10
10
|
userChangedPasswordAfter(user: User, JWTTimestamp: number): boolean;
|
|
11
11
|
verifyJwtToken(token: string, secret?: string): Promise<AuthJwtPayload>;
|
|
12
|
-
handleActionAccessControl(authConfigs: AuthConfigs, action:
|
|
12
|
+
handleActionAccessControl(authConfigs: AuthConfigs, action: BaseControllerActions, resourceName: string): ArkosRequestHandler;
|
|
13
13
|
getAuthenticatedUser(req: ArkosRequest): Promise<User | null>;
|
|
14
14
|
authenticate: (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => Promise<void>;
|
|
15
|
-
handleAuthenticationControl(authConfigs: AuthConfigs | undefined, action:
|
|
15
|
+
handleAuthenticationControl(authConfigs: AuthConfigs | undefined, action: BaseControllerActions): ArkosRequestHandler;
|
|
16
16
|
}
|
|
17
17
|
declare const authService: AuthService;
|
|
18
18
|
export default authService;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
|
-
import { PrismaQueryOptions } from "../../types";
|
|
2
|
+
import { PrismaQueryOptions, ArkosRequestHandler } from "../../types";
|
|
3
3
|
export declare function callNext(req: Request, res: Response, next: NextFunction): void;
|
|
4
4
|
export declare function sendResponse(req: Request, res: Response, next: NextFunction): void;
|
|
5
5
|
export declare function addRouteMiddlwaresAndConfigs(): void;
|
|
6
6
|
export declare function addPrismaQueryOptionsToRequestQuery<T>(prismaQueryOptions: PrismaQueryOptions<T>, action: keyof PrismaQueryOptions<T>): (req: Request, res: Response, next: NextFunction) => void;
|
|
7
7
|
export declare function handleRequestLogs(req: Request, res: Response, next: NextFunction): void;
|
|
8
|
+
type AuthActions = "signup" | "login" | "updateMe" | "updatePassword";
|
|
9
|
+
type DefaultActions = "create" | "update";
|
|
10
|
+
export declare function handleRequestBodyValidationAndTransformation(resourceName: "auth", action: AuthActions): ArkosRequestHandler;
|
|
11
|
+
export declare function handleRequestBodyValidationAndTransformation(resourceName: Exclude<string, "auth">, action: DefaultActions): ArkosRequestHandler;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RelationFields } from "../../../../utils/helpers/models.helpers";
|
|
2
|
+
export declare function isPrismaRelationFormat(obj: Record<string, any>): boolean;
|
|
3
|
+
export declare function handleRelationFieldsInBody(body: Record<string, any>, relationFields: RelationFields, ignoreActions?: string[]): Record<string, any>;
|
|
4
|
+
export declare function canBeUsedToConnect(modelName: string, bodyField: Record<string, any> | undefined | null): boolean;
|
|
5
|
+
export declare function isListFieldAnArray(field: any): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RelationFields } from "../../../../utils/helpers/models.helpers";
|
|
2
|
+
export declare function removeApiAction(obj: Record<string, any>): Record<string, any>;
|
|
2
3
|
export declare function isPrismaRelationFormat(obj: Record<string, any>): boolean;
|
|
3
4
|
export declare function handleRelationFieldsInBody(body: Record<string, any>, relationFields: RelationFields, ignoreActions?: string[]): Record<string, any>;
|
|
4
5
|
export declare function canBeUsedToConnect(modelName: string, bodyField: Record<string, any> | undefined | null): boolean;
|
|
5
|
-
export declare function isListFieldAnArray(field: any): boolean;
|
|
@@ -7,6 +7,11 @@ import { Options as QueryParserOptions } from "../utils/helpers/query-parser.hel
|
|
|
7
7
|
import { ValidatorOptions } from "class-validator";
|
|
8
8
|
import { MsDuration } from "../modules/auth/utils/helpers/auth.controller.helpers";
|
|
9
9
|
export type ArkosConfig = {
|
|
10
|
+
request?: {
|
|
11
|
+
parameters?: {
|
|
12
|
+
allowDangerousPrismaQueryOptions?: boolean;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
10
15
|
welcomeMessage?: string;
|
|
11
16
|
port?: number | undefined;
|
|
12
17
|
host?: string;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { JwtPayload } from "jsonwebtoken";
|
|
2
|
-
export type
|
|
3
|
-
export type
|
|
4
|
-
|
|
2
|
+
export type BaseControllerActions = "create" | "update" | "delete" | "view";
|
|
3
|
+
export type ExtendedControllerActions<T extends string = never> = BaseControllerActions | T;
|
|
4
|
+
export type AccessControlRules<T extends string = never> = {
|
|
5
|
+
[key in ExtendedControllerActions<T>]: any[];
|
|
5
6
|
};
|
|
6
|
-
export type AuthenticationControlRules = {
|
|
7
|
-
[key in
|
|
7
|
+
export type AuthenticationControlRules<T extends string = never> = {
|
|
8
|
+
[key in ExtendedControllerActions<T>]: boolean;
|
|
8
9
|
};
|
|
9
|
-
export type AuthConfigs = {
|
|
10
|
-
authenticationControl?: boolean | Partial<AuthenticationControlRules
|
|
11
|
-
accessControl?: any[] | Partial<AccessControlRules
|
|
10
|
+
export type AuthConfigs<T extends string = never> = {
|
|
11
|
+
authenticationControl?: boolean | Partial<AuthenticationControlRules<T>>;
|
|
12
|
+
accessControl?: any[] | Partial<AccessControlRules<T>>;
|
|
12
13
|
};
|
|
13
14
|
export interface AuthJwtPayload extends JwtPayload {
|
|
14
15
|
id?: number | string;
|
|
@@ -55,13 +55,14 @@ export interface User {
|
|
|
55
55
|
roles?: UserRole[] | any[];
|
|
56
56
|
role?: UserRole | any;
|
|
57
57
|
}
|
|
58
|
-
export interface ArkosRequest extends Request {
|
|
58
|
+
export interface ArkosRequest<Body = any, Query = any> extends Request {
|
|
59
59
|
user?: User & Record<string, any>;
|
|
60
60
|
relationFields?: Record<string, boolean>;
|
|
61
61
|
include?: Record<string, any>;
|
|
62
62
|
responseData?: Record<string, any> | null | undefined;
|
|
63
63
|
additionalData?: Record<string, any> | null | undefined;
|
|
64
64
|
responseStatus?: number | string | null | undefined;
|
|
65
|
+
body: Body;
|
|
65
66
|
}
|
|
66
67
|
export interface ArkosResponse extends Response {
|
|
67
68
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type AvailableEndpoints = "createOne" | "findOne" | "updateOne" | "deleteOne" | "findMany" | "createMany" | "udpateMany" | "deleteMany";
|
|
2
|
+
export type PrismaModelRouterConfig = {
|
|
3
|
+
parent?: {
|
|
4
|
+
model?: string;
|
|
5
|
+
referenceField?: string;
|
|
6
|
+
endpoints?: "*" | AvailableEndpoints | AvailableEndpoints[];
|
|
7
|
+
};
|
|
8
|
+
disable?: boolean | {
|
|
9
|
+
createOne?: boolean;
|
|
10
|
+
findOne?: boolean;
|
|
11
|
+
updateOne?: boolean;
|
|
12
|
+
deleteOne?: boolean;
|
|
13
|
+
createMany?: boolean;
|
|
14
|
+
findMany?: boolean;
|
|
15
|
+
updateMany?: boolean;
|
|
16
|
+
deleteMany?: boolean;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare function handleRequestBodyValidationAndTransformation(modelName: Exclude<string, "auth">, action: DefaultActions): ArkosRequestHandler;
|
|
6
|
-
export {};
|
|
1
|
+
export declare const getAppRoutes: () => {
|
|
2
|
+
method: string;
|
|
3
|
+
path: string;
|
|
4
|
+
}[];
|
|
@@ -2,5 +2,5 @@ import fs from "fs";
|
|
|
2
2
|
export declare const statAsync: typeof fs.stat.__promisify__;
|
|
3
3
|
export declare const accessAsync: typeof fs.access.__promisify__;
|
|
4
4
|
export declare const mkdirAsync: typeof fs.mkdir.__promisify__;
|
|
5
|
-
export declare
|
|
6
|
-
export declare const
|
|
5
|
+
export declare let userFileExtension: "ts" | "js" | undefined;
|
|
6
|
+
export declare const getUserFileExtension: () => "ts" | "js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeInsomniaCollectionJson(): void;
|
package/package.json
CHANGED
|
@@ -1,50 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arkos",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20-beta",
|
|
4
4
|
"description": "The Express & Prisma Framework For RESTful API",
|
|
5
5
|
"main": "dist/cjs/exports/index.js",
|
|
6
6
|
"module": "dist/es2020/exports/index.js",
|
|
7
7
|
"types": "dist/types/exports/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
+
"types": "./dist/types/exports/index.d.ts",
|
|
10
11
|
"import": "./dist/es2020/exports/index.js",
|
|
11
|
-
"require": "./dist/cjs/exports/index.js"
|
|
12
|
-
"types": "./dist/types/exports/index.d.ts"
|
|
12
|
+
"require": "./dist/cjs/exports/index.js"
|
|
13
13
|
},
|
|
14
14
|
"./prisma": {
|
|
15
|
+
"types": "./dist/types/exports/prisma/index.d.ts",
|
|
15
16
|
"import": "./dist/es2020/exports/prisma/index.js",
|
|
16
|
-
"require": "./dist/cjs/exports/prisma/index.js"
|
|
17
|
-
"types": "./dist/types/exports/prisma/index.d.ts"
|
|
17
|
+
"require": "./dist/cjs/exports/prisma/index.js"
|
|
18
18
|
},
|
|
19
19
|
"./auth": {
|
|
20
|
+
"types": "./dist/types/exports/auth/index.d.ts",
|
|
20
21
|
"import": "./dist/es2020/exports/auth/index.js",
|
|
21
|
-
"require": "./dist/cjs/exports/auth/index.js"
|
|
22
|
-
"types": "./dist/types/exports/auth/index.d.ts"
|
|
22
|
+
"require": "./dist/cjs/exports/auth/index.js"
|
|
23
23
|
},
|
|
24
24
|
"./services": {
|
|
25
|
+
"types": "./dist/types/exports/services/index.d.ts",
|
|
25
26
|
"import": "./dist/es2020/exports/services/index.js",
|
|
26
|
-
"require": "./dist/cjs/exports/services/index.js"
|
|
27
|
-
|
|
27
|
+
"require": "./dist/cjs/exports/services/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./middlewares": {
|
|
30
|
+
"types": "./dist/types/exports/middlewares/index.d.ts",
|
|
31
|
+
"import": "./dist/es2020/exports/middlewares/index.js",
|
|
32
|
+
"require": "./dist/cjs/exports/middlewares/index.js"
|
|
28
33
|
},
|
|
29
34
|
"./validation": {
|
|
35
|
+
"types": "./dist/types/exports/validation/index.d.ts",
|
|
30
36
|
"import": "./dist/es2020/exports/validation/index.js",
|
|
31
|
-
"require": "./dist/cjs/exports/validation/index.js"
|
|
32
|
-
"types": "./dist/types/exports/validation/index.d.ts"
|
|
37
|
+
"require": "./dist/cjs/exports/validation/index.js"
|
|
33
38
|
},
|
|
34
39
|
"./error-handler": {
|
|
40
|
+
"types": "./dist/types/exports/error-handler/index.d.ts",
|
|
35
41
|
"import": "./dist/es2020/exports/error-handler/index.js",
|
|
36
|
-
"require": "./dist/cjs/exports/error-handler/index.js"
|
|
37
|
-
"types": "./dist/types/exports/error-handler/index.d.ts"
|
|
42
|
+
"require": "./dist/cjs/exports/error-handler/index.js"
|
|
38
43
|
},
|
|
39
44
|
"./utils": {
|
|
45
|
+
"types": "./dist/types/exports/utils/index.d.ts",
|
|
40
46
|
"import": "./dist/es2020/exports/utils/index.js",
|
|
41
|
-
"require": "./dist/cjs/exports/utils/index.js"
|
|
42
|
-
"types": "./dist/types/exports/utils/index.d.ts"
|
|
47
|
+
"require": "./dist/cjs/exports/utils/index.js"
|
|
43
48
|
},
|
|
44
49
|
"./*": {
|
|
50
|
+
"types": "./dist/types/exports/*.d.ts",
|
|
45
51
|
"import": "./dist/es2020/exports/*.js",
|
|
46
|
-
"require": "./dist/cjs/exports/*.js"
|
|
47
|
-
"types": "./dist/types/exports/*.d.ts"
|
|
52
|
+
"require": "./dist/cjs/exports/*.js"
|
|
48
53
|
}
|
|
49
54
|
},
|
|
50
55
|
"typesVersions": {
|
|
@@ -66,6 +71,28 @@
|
|
|
66
71
|
]
|
|
67
72
|
}
|
|
68
73
|
},
|
|
74
|
+
"bin": {
|
|
75
|
+
"arkos": "./dist/src/utils/scripts/index.js",
|
|
76
|
+
"arkos-dev": "./src/utils/scripts/index.ts"
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build:es2020": "tsc -p tsconfig.es2020.json",
|
|
80
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
81
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
82
|
+
"postbuilda": "echo {\\\"type\":\"commonjs\\\"} > dist/cjs/package.json",
|
|
83
|
+
"build": "pnpm run build:cjs && pnpm run build:es2020 && pnpm run build:types && pnpm run minify",
|
|
84
|
+
"minify": "esbuild dist/**/*.js --minify --outdir=dist --allow-overwrite --log-limit=0 --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
85
|
+
"clean": "rm -r dist",
|
|
86
|
+
"dev": "ts-node --watch",
|
|
87
|
+
"lint": "eslint src --ext .ts",
|
|
88
|
+
"prepublishOnly": "pnpm run build",
|
|
89
|
+
"prelinkOnly": "npm run build",
|
|
90
|
+
"test": "jest",
|
|
91
|
+
"test:watch": "jest --watch",
|
|
92
|
+
"test:coverage": "jest --coverage",
|
|
93
|
+
"test:ui": "vitest --ui",
|
|
94
|
+
"test:create": "ts-node src/scripts/create-test.ts"
|
|
95
|
+
},
|
|
69
96
|
"keywords": [
|
|
70
97
|
"auto API routes",
|
|
71
98
|
"TypeScript package",
|
|
@@ -149,21 +176,15 @@
|
|
|
149
176
|
"engines": {
|
|
150
177
|
"node": ">=14.16"
|
|
151
178
|
},
|
|
152
|
-
"
|
|
153
|
-
"
|
|
154
|
-
"
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
"prelinkOnly": "npm run build",
|
|
163
|
-
"test": "jest",
|
|
164
|
-
"test:watch": "jest --watch",
|
|
165
|
-
"test:coverage": "jest --coverage",
|
|
166
|
-
"test:ui": "vitest --ui",
|
|
167
|
-
"test:create": "ts-node src/scripts/create-test.ts"
|
|
179
|
+
"pnpm": {
|
|
180
|
+
"overrides": {},
|
|
181
|
+
"onlyBuiltDependencies": [
|
|
182
|
+
"@prisma/client",
|
|
183
|
+
"@prisma/engines",
|
|
184
|
+
"bcrypt",
|
|
185
|
+
"esbuild",
|
|
186
|
+
"prisma",
|
|
187
|
+
"sharp"
|
|
188
|
+
]
|
|
168
189
|
}
|
|
169
|
-
}
|
|
190
|
+
}
|