arkos 2.0.0-next.13 → 2.0.0-next.16
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/README.md +144 -145
- package/cli.js +1 -0
- package/dist/cjs/app.js +7 -0
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/exports/error-handler/index.js +15 -0
- package/dist/cjs/exports/error-handler/index.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +3 -0
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/auth/auth.service.js +2 -0
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/base/base.controller.js +15 -3
- package/dist/cjs/modules/base/base.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js +19 -12
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/base/base.service.js +5 -1
- package/dist/cjs/modules/base/base.service.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js +9 -0
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/cjs/modules/error-handler/error-handler.controller.js +25 -42
- package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/app-error.js +0 -1
- package/dist/cjs/modules/error-handler/utils/app-error.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js +8 -9
- package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/errors.js +158 -0
- package/dist/cjs/modules/error-handler/utils/errors.js.map +1 -0
- package/dist/cjs/modules/error-handler/utils/multer-error-handler.js +39 -0
- package/dist/cjs/modules/error-handler/utils/multer-error-handler.js.map +1 -0
- package/dist/cjs/modules/file-upload/file-upload.controller.js +10 -14
- package/dist/cjs/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js +2 -0
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/cjs/modules/swagger/swagger.router.js +8 -2
- package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/get-open-api-login-html.js +18 -0
- package/dist/cjs/modules/swagger/utils/get-open-api-login-html.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js +5 -5
- package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/openapi-schema-converter.js +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/openapi-schema-converter.js.map +1 -1
- package/dist/cjs/types/arkos-prisma-input.js.map +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/new-arkos-config.js.map +1 -1
- package/dist/cjs/types/router-config.js.map +1 -1
- package/dist/cjs/utils/arkos-router/arkos-router-openapi-manager.js +86 -28
- package/dist/cjs/utils/arkos-router/arkos-router-openapi-manager.js.map +1 -1
- package/dist/cjs/utils/arkos-router/index.js +11 -7
- package/dist/cjs/utils/arkos-router/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/types/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/types/upload-config.js.map +1 -1
- package/dist/cjs/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js +34 -28
- package/dist/cjs/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js.map +1 -1
- package/dist/cjs/utils/arkos-router/utils/helpers/index.js +9 -6
- package/dist/cjs/utils/arkos-router/utils/helpers/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/utils/helpers/upload-manager.js +334 -77
- package/dist/cjs/utils/arkos-router/utils/helpers/upload-manager.js.map +1 -1
- package/dist/cjs/utils/bundler.js.map +1 -1
- package/dist/cjs/utils/cli/build.js +2 -3
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js +11 -6
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/export-auth-action.js +5 -4
- package/dist/cjs/utils/cli/export-auth-action.js.map +1 -1
- package/dist/cjs/utils/cli/generate.js +6 -8
- package/dist/cjs/utils/cli/generate.js.map +1 -1
- package/dist/cjs/utils/cli/index.js +22 -19
- package/dist/cjs/utils/cli/index.js.map +1 -1
- package/dist/cjs/utils/cli/start.js +4 -2
- package/dist/cjs/utils/cli/start.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js +19 -7
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-multiple-components.js +7 -6
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-multiple-components.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/policy-template.js +4 -4
- package/dist/cjs/utils/cli/utils/template-generator/templates/policy-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generators.js +0 -6
- package/dist/cjs/utils/cli/utils/template-generators.js.map +1 -1
- package/dist/cjs/utils/define-config.js +5 -0
- package/dist/cjs/utils/define-config.js.map +1 -1
- package/dist/cjs/utils/dotenv.helpers.js +0 -6
- package/dist/cjs/utils/dotenv.helpers.js.map +1 -1
- package/dist/cjs/utils/features/api.features.js +23 -5
- package/dist/cjs/utils/features/api.features.js.map +1 -1
- package/dist/cjs/utils/helpers/arkos-config.helpers.js +22 -2
- package/dist/cjs/utils/helpers/arkos-config.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/exit-error.js +1 -0
- package/dist/cjs/utils/helpers/exit-error.js.map +1 -1
- package/dist/cjs/utils/helpers/fs.helpers.js +25 -24
- package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/global.helpers.js +3 -2
- package/dist/cjs/utils/helpers/global.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +4 -5
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/url-helpers.js +14 -0
- package/dist/cjs/utils/helpers/url-helpers.js.map +1 -0
- package/dist/cjs/utils/initialize-app.js +35 -6
- package/dist/cjs/utils/initialize-app.js.map +1 -1
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js +12 -6
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/dist/cjs/utils/prisma/prisma-schema-parser.js +10 -3
- package/dist/cjs/utils/prisma/prisma-schema-parser.js.map +1 -1
- package/dist/cjs/utils/setup-app.js +58 -41
- package/dist/cjs/utils/setup-app.js.map +1 -1
- package/dist/esm/app.js +6 -0
- package/dist/esm/app.js.map +1 -1
- package/dist/esm/exports/error-handler/index.js +1 -0
- package/dist/esm/exports/error-handler/index.js.map +1 -1
- package/dist/esm/modules/auth/auth.router.js +3 -0
- package/dist/esm/modules/auth/auth.router.js.map +1 -1
- package/dist/esm/modules/auth/auth.service.js +2 -0
- package/dist/esm/modules/auth/auth.service.js.map +1 -1
- package/dist/esm/modules/base/base.controller.js +15 -3
- package/dist/esm/modules/base/base.controller.js.map +1 -1
- package/dist/esm/modules/base/base.middlewares.js +19 -12
- package/dist/esm/modules/base/base.middlewares.js.map +1 -1
- package/dist/esm/modules/base/base.service.js +5 -1
- package/dist/esm/modules/base/base.service.js.map +1 -1
- package/dist/esm/modules/base/utils/helpers/base.service.helpers.js +9 -0
- package/dist/esm/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/esm/modules/error-handler/error-handler.controller.js +22 -42
- package/dist/esm/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/app-error.js +0 -1
- package/dist/esm/modules/error-handler/utils/app-error.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/error-handler.helpers.js +8 -9
- package/dist/esm/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/errors.js +127 -0
- package/dist/esm/modules/error-handler/utils/errors.js.map +1 -0
- package/dist/esm/modules/error-handler/utils/multer-error-handler.js +34 -0
- package/dist/esm/modules/error-handler/utils/multer-error-handler.js.map +1 -0
- package/dist/esm/modules/file-upload/file-upload.controller.js +10 -14
- package/dist/esm/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.router.js +2 -0
- package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/esm/modules/swagger/swagger.router.js +8 -2
- package/dist/esm/modules/swagger/swagger.router.js.map +1 -1
- package/dist/esm/modules/swagger/utils/get-open-api-login-html.js +18 -0
- package/dist/esm/modules/swagger/utils/get-open-api-login-html.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js +5 -5
- package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/openapi-schema-converter.js +1 -1
- package/dist/esm/modules/swagger/utils/helpers/openapi-schema-converter.js.map +1 -1
- package/dist/esm/types/arkos-prisma-input.js.map +1 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/new-arkos-config.js.map +1 -1
- package/dist/esm/types/router-config.js.map +1 -1
- package/dist/esm/utils/arkos-router/arkos-router-openapi-manager.js +86 -28
- package/dist/esm/utils/arkos-router/arkos-router-openapi-manager.js.map +1 -1
- package/dist/esm/utils/arkos-router/index.js +11 -7
- package/dist/esm/utils/arkos-router/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/types/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/types/upload-config.js.map +1 -1
- package/dist/esm/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js +34 -28
- package/dist/esm/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js.map +1 -1
- package/dist/esm/utils/arkos-router/utils/helpers/index.js +9 -6
- package/dist/esm/utils/arkos-router/utils/helpers/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/utils/helpers/upload-manager.js +334 -77
- package/dist/esm/utils/arkos-router/utils/helpers/upload-manager.js.map +1 -1
- package/dist/esm/utils/bundler.js.map +1 -1
- package/dist/esm/utils/cli/build.js +3 -4
- package/dist/esm/utils/cli/build.js.map +1 -1
- package/dist/esm/utils/cli/dev.js +12 -7
- package/dist/esm/utils/cli/dev.js.map +1 -1
- package/dist/esm/utils/cli/export-auth-action.js +5 -4
- package/dist/esm/utils/cli/export-auth-action.js.map +1 -1
- package/dist/esm/utils/cli/generate.js +6 -8
- package/dist/esm/utils/cli/generate.js.map +1 -1
- package/dist/esm/utils/cli/index.js +22 -19
- package/dist/esm/utils/cli/index.js.map +1 -1
- package/dist/esm/utils/cli/start.js +4 -2
- package/dist/esm/utils/cli/start.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js +16 -7
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-multiple-components.js +7 -6
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-multiple-components.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/policy-template.js +4 -4
- package/dist/esm/utils/cli/utils/template-generator/templates/policy-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generators.js +0 -6
- package/dist/esm/utils/cli/utils/template-generators.js.map +1 -1
- package/dist/esm/utils/define-config.js +5 -0
- package/dist/esm/utils/define-config.js.map +1 -1
- package/dist/esm/utils/dotenv.helpers.js +0 -6
- package/dist/esm/utils/dotenv.helpers.js.map +1 -1
- package/dist/esm/utils/features/api.features.js +23 -5
- package/dist/esm/utils/features/api.features.js.map +1 -1
- package/dist/esm/utils/helpers/arkos-config.helpers.js +20 -2
- package/dist/esm/utils/helpers/arkos-config.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/exit-error.js +1 -0
- package/dist/esm/utils/helpers/exit-error.js.map +1 -1
- package/dist/esm/utils/helpers/fs.helpers.js +25 -24
- package/dist/esm/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/global.helpers.js +1 -1
- package/dist/esm/utils/helpers/global.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/prisma.helpers.js +4 -5
- package/dist/esm/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/url-helpers.js +11 -0
- package/dist/esm/utils/helpers/url-helpers.js.map +1 -0
- package/dist/esm/utils/initialize-app.js +35 -6
- package/dist/esm/utils/initialize-app.js.map +1 -1
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js +12 -6
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/dist/esm/utils/prisma/prisma-schema-parser.js +10 -3
- package/dist/esm/utils/prisma/prisma-schema-parser.js.map +1 -1
- package/dist/esm/utils/setup-app.js +59 -42
- package/dist/esm/utils/setup-app.js.map +1 -1
- package/dist/types/app.d.ts +5 -6
- package/dist/types/exports/error-handler/index.d.ts +1 -0
- package/dist/types/modules/auth/auth.service.d.ts +2 -6
- package/dist/types/modules/base/base.service.d.ts +2 -1
- package/dist/types/modules/error-handler/utils/app-error.d.ts +0 -2
- package/dist/types/modules/error-handler/utils/error-handler.helpers.d.ts +1 -1
- package/dist/types/modules/error-handler/utils/errors.d.ts +176 -0
- package/dist/types/modules/error-handler/utils/multer-error-handler.d.ts +7 -0
- package/dist/types/modules/file-upload/file-upload.controller.d.ts +0 -1
- package/dist/types/modules/swagger/utils/helpers/get-swagger-default-configs.d.ts +48 -2
- package/dist/types/types/arkos-prisma-input.d.ts +3 -2
- package/dist/types/types/index.d.ts +0 -21
- package/dist/types/types/new-arkos-config.d.ts +183 -14
- package/dist/types/types/router-config.d.ts +1 -1
- package/dist/types/utils/arkos-router/arkos-router-openapi-manager.d.ts +14 -1
- package/dist/types/utils/arkos-router/index.d.ts +76 -8
- package/dist/types/utils/arkos-router/types/index.d.ts +19 -6
- package/dist/types/utils/arkos-router/types/upload-config.d.ts +63 -7
- package/dist/types/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.d.ts +1 -1
- package/dist/types/utils/arkos-router/utils/helpers/index.d.ts +2 -0
- package/dist/types/utils/arkos-router/utils/helpers/upload-manager.d.ts +0 -36
- package/dist/types/utils/bundler.d.ts +1 -1
- package/dist/types/utils/cli/generate.d.ts +0 -1
- package/dist/types/utils/cli/start.d.ts +1 -1
- package/dist/types/utils/helpers/arkos-config.helpers.d.ts +2 -0
- package/dist/types/utils/helpers/fs.helpers.d.ts +1 -1
- package/dist/types/utils/helpers/global.helpers.d.ts +1 -0
- package/dist/types/utils/helpers/url-helpers.d.ts +1 -0
- package/dist/types/utils/prisma/prisma-schema-parser.d.ts +1 -0
- package/package.json +15 -15
- package/dist/cjs/utils/cli/utils/template-generator/templates/route-hook.template.js +0 -39
- package/dist/cjs/utils/cli/utils/template-generator/templates/route-hook.template.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/service-hook.template.js +0 -32
- package/dist/cjs/utils/cli/utils/template-generator/templates/service-hook.template.js.map +0 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/route-hook.template.js +0 -36
- package/dist/esm/utils/cli/utils/template-generator/templates/route-hook.template.js.map +0 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/service-hook.template.js +0 -29
- package/dist/esm/utils/cli/utils/template-generator/templates/service-hook.template.js.map +0 -1
- package/dist/types/utils/cli/utils/template-generator/templates/route-hook.template.d.ts +0 -2
- package/dist/types/utils/cli/utils/template-generator/templates/service-hook.template.d.ts +0 -2
|
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const deepmerge_helper_1 = __importDefault(require("../helpers/deepmerge.helper.js"));
|
|
7
7
|
class ArkosRouterOpenAPIManager {
|
|
8
|
+
resolveSchemaFieldName(name) {
|
|
9
|
+
return name.replace(/\[\]/g, "[0]");
|
|
10
|
+
}
|
|
8
11
|
addUploadFields(uploadConfig, existingSchema = {}) {
|
|
9
12
|
const uploadSchema = {
|
|
10
13
|
type: "object",
|
|
@@ -12,48 +15,51 @@ class ArkosRouterOpenAPIManager {
|
|
|
12
15
|
required: [],
|
|
13
16
|
};
|
|
14
17
|
if (uploadConfig.type === "single") {
|
|
15
|
-
|
|
18
|
+
const schemaKey = this.resolveSchemaFieldName(uploadConfig.field);
|
|
19
|
+
uploadSchema.properties[schemaKey] = {
|
|
16
20
|
type: "string",
|
|
17
21
|
format: "binary",
|
|
18
22
|
...(uploadConfig.maxSize && {
|
|
19
23
|
description: `Max size: ${uploadConfig.maxSize} bytes`,
|
|
20
24
|
}),
|
|
25
|
+
...(uploadConfig.description && {
|
|
26
|
+
description: uploadConfig.description,
|
|
27
|
+
}),
|
|
21
28
|
};
|
|
22
|
-
if (uploadConfig.required) {
|
|
23
|
-
uploadSchema.required.push(
|
|
29
|
+
if (uploadConfig.required !== false) {
|
|
30
|
+
uploadSchema.required.push(schemaKey);
|
|
24
31
|
}
|
|
25
32
|
}
|
|
26
33
|
else if (uploadConfig.type === "array") {
|
|
27
|
-
|
|
34
|
+
const schemaKey = this.resolveSchemaFieldName(uploadConfig.field);
|
|
35
|
+
uploadSchema.properties[schemaKey] = {
|
|
28
36
|
type: "array",
|
|
29
37
|
items: {
|
|
30
38
|
type: "string",
|
|
31
39
|
format: "binary",
|
|
32
40
|
},
|
|
33
41
|
...(uploadConfig.maxCount && { maxItems: uploadConfig.maxCount }),
|
|
42
|
+
...(uploadConfig.minCount && { minItems: uploadConfig.minCount }),
|
|
34
43
|
...(uploadConfig.maxSize && {
|
|
35
44
|
description: `Max size per file: ${uploadConfig.maxSize} bytes`,
|
|
36
45
|
}),
|
|
46
|
+
...(uploadConfig.description && {
|
|
47
|
+
description: uploadConfig.description,
|
|
48
|
+
}),
|
|
37
49
|
};
|
|
38
|
-
if (uploadConfig.required) {
|
|
39
|
-
uploadSchema.required.push(
|
|
50
|
+
if (uploadConfig.required !== false) {
|
|
51
|
+
uploadSchema.required.push(schemaKey);
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
else if (uploadConfig.type === "fields") {
|
|
43
55
|
for (const field of uploadConfig.fields) {
|
|
44
|
-
uploadSchema.properties[field.name] =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
...(uploadConfig.maxSize && {
|
|
52
|
-
description: `Max size per file: ${uploadConfig.maxSize} bytes`,
|
|
53
|
-
}),
|
|
54
|
-
};
|
|
55
|
-
if (uploadConfig.required) {
|
|
56
|
-
uploadSchema.required.push(field.name);
|
|
56
|
+
uploadSchema.properties[this.resolveSchemaFieldName(field.name)] =
|
|
57
|
+
this.buildFieldSchema(field, uploadConfig);
|
|
58
|
+
const isRequired = field.type === undefined
|
|
59
|
+
? uploadConfig.required !== false
|
|
60
|
+
: field.required !== false;
|
|
61
|
+
if (isRequired) {
|
|
62
|
+
uploadSchema.required.push(this.resolveSchemaFieldName(field.name));
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
65
|
}
|
|
@@ -61,6 +67,45 @@ class ArkosRouterOpenAPIManager {
|
|
|
61
67
|
delete uploadSchema.required;
|
|
62
68
|
return (0, deepmerge_helper_1.default)(existingSchema, uploadSchema);
|
|
63
69
|
}
|
|
70
|
+
buildFieldSchema(field, config) {
|
|
71
|
+
if (field.type === "single") {
|
|
72
|
+
return {
|
|
73
|
+
type: "string",
|
|
74
|
+
format: "binary",
|
|
75
|
+
...(field.maxSize &&
|
|
76
|
+
!config.maxSize && {
|
|
77
|
+
description: `Max size: ${field.maxSize} bytes`,
|
|
78
|
+
}),
|
|
79
|
+
...(config.maxSize &&
|
|
80
|
+
!field.maxSize && {
|
|
81
|
+
description: `Max size: ${config.maxSize} bytes`,
|
|
82
|
+
}),
|
|
83
|
+
...(field.description && { description: field.description }),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
type: "array",
|
|
88
|
+
items: {
|
|
89
|
+
type: "string",
|
|
90
|
+
format: "binary",
|
|
91
|
+
},
|
|
92
|
+
...(field.maxCount && { maxItems: field.maxCount }),
|
|
93
|
+
...(field.type === "array" &&
|
|
94
|
+
field.minCount && { minItems: field.minCount }),
|
|
95
|
+
...((field.maxSize &&
|
|
96
|
+
!config.maxSize && {
|
|
97
|
+
description: `Max size per file: ${field.maxSize} bytes`,
|
|
98
|
+
}) ||
|
|
99
|
+
(config.maxSize &&
|
|
100
|
+
!field.maxSize && {
|
|
101
|
+
description: `Max size per file: ${config.maxSize} bytes`,
|
|
102
|
+
})),
|
|
103
|
+
...(field.type === "array" &&
|
|
104
|
+
field.description && {
|
|
105
|
+
description: field.description,
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
64
109
|
validateMultipartFormDocs(userDefinedMultipartSchema, routePath, uploadConfig) {
|
|
65
110
|
const errors = [];
|
|
66
111
|
const properties = userDefinedMultipartSchema?.properties || {};
|
|
@@ -69,28 +114,41 @@ class ArkosRouterOpenAPIManager {
|
|
|
69
114
|
if (uploadConfig?.type === "single") {
|
|
70
115
|
expectedFields.push({
|
|
71
116
|
name: uploadConfig.field,
|
|
72
|
-
required: uploadConfig.required
|
|
117
|
+
required: uploadConfig.required !== false,
|
|
73
118
|
expectedType: "single",
|
|
74
119
|
});
|
|
75
120
|
}
|
|
76
121
|
else if (uploadConfig?.type === "array") {
|
|
77
122
|
expectedFields.push({
|
|
78
123
|
name: uploadConfig.field,
|
|
79
|
-
required: uploadConfig.required
|
|
124
|
+
required: uploadConfig.required !== false,
|
|
80
125
|
expectedType: "array",
|
|
81
126
|
});
|
|
82
127
|
}
|
|
83
128
|
else if (uploadConfig?.type === "fields") {
|
|
84
129
|
for (const field of uploadConfig.fields) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
130
|
+
if (!("type" in field)) {
|
|
131
|
+
expectedFields.push({
|
|
132
|
+
name: field.name,
|
|
133
|
+
required: uploadConfig.required ===
|
|
134
|
+
undefined
|
|
135
|
+
? true
|
|
136
|
+
: uploadConfig
|
|
137
|
+
.required,
|
|
138
|
+
expectedType: "array",
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else if (field.type)
|
|
142
|
+
expectedFields.push({
|
|
143
|
+
name: field.name,
|
|
144
|
+
required: field.type === undefined ? true : field.required !== false,
|
|
145
|
+
expectedType: field.type ?? "array",
|
|
146
|
+
});
|
|
90
147
|
}
|
|
91
148
|
}
|
|
92
149
|
for (const { name, required, expectedType } of expectedFields) {
|
|
93
|
-
const
|
|
150
|
+
const schemaKey = this.resolveSchemaFieldName(name);
|
|
151
|
+
const fieldSchema = properties[schemaKey];
|
|
94
152
|
if (!fieldSchema) {
|
|
95
153
|
errors.push(`Missing upload field '${name}' in multipart/form-data schema`);
|
|
96
154
|
continue;
|
|
@@ -110,7 +168,7 @@ class ArkosRouterOpenAPIManager {
|
|
|
110
168
|
fieldSchema.items.format !== "binary")
|
|
111
169
|
errors.push(`Upload field '${name}' must have items with type 'string' and format 'binary'`);
|
|
112
170
|
}
|
|
113
|
-
const isMarkedRequired = requiredFields.includes(
|
|
171
|
+
const isMarkedRequired = requiredFields.includes(schemaKey);
|
|
114
172
|
if (required && !isMarkedRequired)
|
|
115
173
|
errors.push(`Upload field '${name}' is required in config but not marked as required in schema`);
|
|
116
174
|
if (!required && isMarkedRequired)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arkos-router-openapi-manager.js","sourceRoot":"","sources":["../../../../src/utils/arkos-router/arkos-router-openapi-manager.ts"],"names":[],"mappings":";;;;;AACA,mFAAoD;AAGpD,MAAM,yBAAyB;IAsB7B,eAAe,CACb,YAA0B,EAC1B,iBAAyC,EAAE;QAE3C,MAAM,YAAY,GAAQ;YACxB,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE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oBAClB,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ;oBACnC,WAAW,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ;oBAErC,MAAM,CAAC,IAAI,CACT,iBAAiB,IAAI,0DAA0D,CAChF,CAAC;YACN,CAAC;YAED,MAAM,gBAAgB,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACvD,IAAI,QAAQ,IAAI,CAAC,gBAAgB;gBAC/B,MAAM,CAAC,IAAI,CACT,iBAAiB,IAAI,8DAA8D,CACpF,CAAC;YAEJ,IAAI,CAAC,QAAQ,IAAI,gBAAgB;gBAC/B,MAAM,CAAC,IAAI,CACT,iBAAiB,IAAI,8DAA8D,CACpF,CAAC;QACN,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACb,kEAAkE,SAAS,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC7H,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,MAAM,yBAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;AAElE,kBAAe,yBAAyB,CAAC","sourcesContent":["import { OpenAPIV3 } from \"openapi-types\";\nimport deepmerge from \"../helpers/deepmerge.helper\";\nimport { UploadConfig } from \"./types/upload-config\";\n\nclass ArkosRouterOpenAPIManager {\n /**\n * Generates OpenAPI schema for file upload fields in multipart/form-data requests.\n * Converts upload configuration into OpenAPI-compliant schema and merges with existing body schema.\n *\n * @param {UploadConfig} uploadConfig - The upload configuration from config.experimental.uploads\n * @param {any} existingSchema - Existing JSON schema from config.validation.body (optional)\n * @returns {{ schema: any }} OpenAPI schema object for multipart/form-data content type\n *\n * @example\n * // Single file upload\n * addUploadFields({ type: 'single', field: 'avatar', maxSize: 5242880 })\n * // Returns: { schema: { type: 'object', properties: { avatar: { type: 'string', format: 'binary' } } } }\n *\n * @example\n * // Array file upload\n * addUploadFields({ type: 'array', field: 'gallery', maxCount: 10 })\n *\n * @example\n * // Multiple fields upload\n * addUploadFields({ type: 'fields', fields: [{ name: 'avatar', maxCount: 1 }, { name: 'resume', maxCount: 1 }] })\n */\n addUploadFields(\n uploadConfig: UploadConfig,\n existingSchema: OpenAPIV3.SchemaObject = {}\n ): OpenAPIV3.SchemaObject {\n const uploadSchema: any = {\n type: \"object\",\n properties: {},\n required: [],\n };\n\n if (uploadConfig.type === \"single\") {\n uploadSchema.properties[uploadConfig.field] = {\n type: \"string\",\n format: \"binary\",\n ...(uploadConfig.maxSize && {\n description: `Max size: ${uploadConfig.maxSize} bytes`,\n }),\n };\n if (uploadConfig.required) {\n uploadSchema.required.push(uploadConfig.field);\n }\n } else if (uploadConfig.type === \"array\") {\n uploadSchema.properties[uploadConfig.field] = {\n type: \"array\",\n items: {\n type: \"string\",\n format: \"binary\",\n },\n ...(uploadConfig.maxCount && { maxItems: uploadConfig.maxCount }),\n ...(uploadConfig.maxSize && {\n description: `Max size per file: ${uploadConfig.maxSize} bytes`,\n }),\n };\n if (uploadConfig.required) {\n uploadSchema.required.push(uploadConfig.field);\n }\n } else if (uploadConfig.type === \"fields\") {\n for (const field of uploadConfig.fields) {\n uploadSchema.properties[field.name] = {\n type: \"array\",\n items: {\n type: \"string\",\n format: \"binary\",\n },\n ...(field.maxCount && { maxItems: field.maxCount }),\n ...(uploadConfig.maxSize && {\n description: `Max size per file: ${uploadConfig.maxSize} bytes`,\n }),\n };\n if (uploadConfig.required) {\n uploadSchema.required.push(field.name);\n }\n }\n }\n\n // Clean up empty required array\n if (uploadSchema.required.length === 0) delete uploadSchema.required;\n\n return deepmerge(existingSchema as any, uploadSchema);\n }\n\n /**\n * Validates that a user-defined multipart/form-data schema includes all required upload fields\n * with correct types, formats, and required flags.\n *\n * @param {any} userDefinedMultipartSchema - The schema object from openapi.requestBody.content['multipart/form-data'].schema\n * @param {UploadConfig} uploadConfig - The upload configuration from config.experimental.uploads\n * @param {string} routePath - The route path for error context\n * @throws {Error} If upload fields are missing or incorrectly defined\n *\n * @example\n * validateMultipartFormDocs(\n * { type: 'object', properties: { avatar: { type: 'string', format: 'binary' } } },\n * { type: 'single', field: 'avatar', required: true },\n * '/users/:id/avatar'\n * )\n */\n validateMultipartFormDocs(\n userDefinedMultipartSchema: any,\n routePath: string,\n uploadConfig?: UploadConfig\n ): void {\n const errors: string[] = [];\n const properties = userDefinedMultipartSchema?.properties || {};\n const requiredFields = userDefinedMultipartSchema?.required || [];\n\n const expectedFields: Array<{\n name: string;\n required: boolean;\n expectedType: \"single\" | \"array\";\n }> = [];\n\n if (uploadConfig?.type === \"single\") {\n expectedFields.push({\n name: uploadConfig.field,\n required: uploadConfig.required || false,\n expectedType: \"single\",\n });\n } else if (uploadConfig?.type === \"array\") {\n expectedFields.push({\n name: uploadConfig.field,\n required: uploadConfig.required || false,\n expectedType: \"array\",\n });\n } else if (uploadConfig?.type === \"fields\") {\n for (const field of uploadConfig.fields) {\n expectedFields.push({\n name: field.name,\n required: uploadConfig.required || false,\n expectedType: \"array\",\n });\n }\n }\n\n for (const { name, required, expectedType } of expectedFields) {\n const fieldSchema = properties[name];\n\n if (!fieldSchema) {\n errors.push(\n `Missing upload field '${name}' in multipart/form-data schema`\n );\n continue;\n }\n\n if (expectedType === \"single\") {\n if (fieldSchema.type !== \"string\")\n errors.push(\n `Upload field '${name}' must have type 'string', got '${fieldSchema.type}'`\n );\n\n if (fieldSchema.format !== \"binary\")\n errors.push(\n `Upload field '${name}' must have format 'binary', got '${fieldSchema.format || \"undefined\"}'`\n );\n } else if (expectedType === \"array\") {\n if (fieldSchema.type !== \"array\") {\n errors.push(\n `Upload field '${name}' must have type 'array', got '${fieldSchema.type}'`\n );\n } else if (\n !fieldSchema.items ||\n fieldSchema.items.type !== \"string\" ||\n fieldSchema.items.format !== \"binary\"\n )\n errors.push(\n `Upload field '${name}' must have items with type 'string' and format 'binary'`\n );\n }\n\n const isMarkedRequired = requiredFields.includes(name);\n if (required && !isMarkedRequired)\n errors.push(\n `Upload field '${name}' is required in config but not marked as required in schema`\n );\n\n if (!required && isMarkedRequired)\n errors.push(\n `Upload field '${name}' is not required in config but marked as required in schema`\n );\n }\n\n if (errors.length > 0) {\n throw new Error(\n `ValidationError: Invalid multipart/form-data schema for route '${routePath}':\\n${errors.map((e) => ` - ${e}`).join(\"\\n\")}`\n );\n }\n }\n}\n\nconst arkosRouterOpenApiManager = new ArkosRouterOpenAPIManager();\n\nexport default arkosRouterOpenApiManager;\n"]}
|
|
1
|
+
{"version":3,"file":"arkos-router-openapi-manager.js","sourceRoot":"","sources":["../../../../src/utils/arkos-router/arkos-router-openapi-manager.ts"],"names":[],"mappings":";;;;;AACA,mFAAoD;AAOpD,MAAM,yBAAyB;IACrB,sBAAsB,CAAC,IAAY;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;IA6BD,eAAe,CACb,YAA0B,EAC1B,iBAAyC,EAAE;QAE3C,MAAM,YAAY,GAAQ;YACxB,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE,EAAE;SACb,CAAC;QAEF,IAAI,YAAY,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnC,MAAM,SAAS,GAAG,IAAI,CAAC,sBAAsB,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAClE,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG;gBACnC,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,QAAQ;gBAChB,GAAG,CAAC,YAAY,CAAC,OAAO,IAAI;oBAC1B,WAAW,EAAE,aAAa,YAAY,CAAC,OAAO,QAAQ;iBACvD,CAAC;gBACF,GAAG,CAAC,YAAY,CAAC,WAAW,IAAI;oBAC9B,WAAW,EAAE,YAAY,CAAC,WAAW;iBACtC,CAAC;aACH,CAAC;YAC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AAM,yBAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;AAElE,kBAAe,yBAAyB,CAAC","sourcesContent":["import { OpenAPIV3 } from \"openapi-types\";\nimport deepmerge from \"../helpers/deepmerge.helper\";\nimport {\n ArkosRouterBaseUploadConfig,\n UploadConfig,\n UploadConfigFieldEntry,\n} from \"./types/upload-config\";\n\nclass ArkosRouterOpenAPIManager {\n private resolveSchemaFieldName(name: string): string {\n return name.replace(/\\[\\]/g, \"[0]\");\n }\n /**\n * Generates OpenAPI schema for file upload fields in multipart/form-data requests.\n * Converts upload configuration into OpenAPI-compliant schema and merges with existing body schema.\n *\n * @param {UploadConfig} uploadConfig - The upload configuration from config.experimental.uploads\n * @param {any} existingSchema - Existing JSON schema from config.validation.body (optional)\n * @returns {{ schema: any }} OpenAPI schema object for multipart/form-data content type\n *\n * @example\n * // Single file upload\n * addUploadFields({ type: 'single', field: 'avatar', maxSize: 5242880 })\n * // Returns: { schema: { type: 'object', properties: { avatar: { type: 'string', format: 'binary' } } } }\n *\n * @example\n * // Array file upload\n * addUploadFields({ type: 'array', field: 'gallery', maxCount: 10 })\n *\n * @example\n * // Multiple fields upload\n * addUploadFields({\n * type: 'fields',\n * fields: [\n * { name: 'avatar', type: 'single', uploadDir: 'images' },\n * { name: 'gallery', type: 'array', maxCount: 6, uploadDir: 'gallery' },\n * { name: 'banners[][images]', type: 'array', maxCount: 5, uploadDir: 'banners' }\n * ]\n * })\n */\n addUploadFields(\n uploadConfig: UploadConfig,\n existingSchema: OpenAPIV3.SchemaObject = {}\n ): OpenAPIV3.SchemaObject {\n const uploadSchema: any = {\n type: \"object\",\n properties: {},\n required: [],\n };\n\n if (uploadConfig.type === \"single\") {\n const schemaKey = this.resolveSchemaFieldName(uploadConfig.field);\n uploadSchema.properties[schemaKey] = {\n type: \"string\",\n format: \"binary\",\n ...(uploadConfig.maxSize && {\n description: `Max size: ${uploadConfig.maxSize} bytes`,\n }),\n ...(uploadConfig.description && {\n description: uploadConfig.description,\n }),\n };\n if (uploadConfig.required !== false) {\n uploadSchema.required.push(schemaKey);\n }\n } else if (uploadConfig.type === \"array\") {\n const schemaKey = this.resolveSchemaFieldName(uploadConfig.field);\n uploadSchema.properties[schemaKey] = {\n type: \"array\",\n items: {\n type: \"string\",\n format: \"binary\",\n },\n ...(uploadConfig.maxCount && { maxItems: uploadConfig.maxCount }),\n ...(uploadConfig.minCount && { minItems: uploadConfig.minCount }),\n ...(uploadConfig.maxSize && {\n description: `Max size per file: ${uploadConfig.maxSize} bytes`,\n }),\n ...(uploadConfig.description && {\n description: uploadConfig.description,\n }),\n };\n if (uploadConfig.required !== false) {\n uploadSchema.required.push(schemaKey);\n }\n } else if (uploadConfig.type === \"fields\") {\n for (const field of uploadConfig.fields) {\n uploadSchema.properties[this.resolveSchemaFieldName(field.name)] =\n this.buildFieldSchema(field, uploadConfig);\n\n // legacy shape has no type and no required — default to required\n const isRequired =\n (field as any).type === undefined\n ? (uploadConfig as any).required !== false\n : (field as any).required !== false;\n\n if (isRequired) {\n uploadSchema.required.push(this.resolveSchemaFieldName(field.name));\n }\n }\n }\n\n // Clean up empty required array\n if (uploadSchema.required.length === 0) delete uploadSchema.required;\n\n return deepmerge(existingSchema as any, uploadSchema);\n }\n\n /**\n * Builds the OpenAPI property schema for a single field entry.\n * Legacy entries (no type) are treated as array.\n */\n private buildFieldSchema(\n field: UploadConfigFieldEntry,\n config: ArkosRouterBaseUploadConfig\n ): object {\n if (field.type === \"single\") {\n return {\n type: \"string\",\n format: \"binary\",\n ...(field.maxSize &&\n !config.maxSize && {\n description: `Max size: ${field.maxSize} bytes`,\n }),\n ...(config.maxSize &&\n !field.maxSize && {\n description: `Max size: ${config.maxSize} bytes`,\n }),\n ...(field.description && { description: field.description }),\n };\n }\n\n // type === \"array\" or legacy (no type) — both produce array schema\n return {\n type: \"array\",\n items: {\n type: \"string\",\n format: \"binary\",\n },\n ...(field.maxCount && { maxItems: field.maxCount }),\n ...(field.type === \"array\" &&\n field.minCount && { minItems: field.minCount }),\n ...((field.maxSize &&\n !config.maxSize && {\n description: `Max size per file: ${field.maxSize} bytes`,\n }) ||\n (config.maxSize &&\n !field.maxSize && {\n description: `Max size per file: ${config.maxSize} bytes`,\n })),\n ...(field.type === \"array\" &&\n field.description && {\n description: field.description,\n }),\n };\n }\n\n /**\n * Validates that a user-defined multipart/form-data schema includes all required upload fields\n * with correct types, formats, and required flags.\n *\n * @param {any} userDefinedMultipartSchema - The schema object from openapi.requestBody.content['multipart/form-data'].schema\n * @param {UploadConfig} uploadConfig - The upload configuration from config.experimental.uploads\n * @param {string} routePath - The route path for error context\n * @throws {Error} If upload fields are missing or incorrectly defined\n *\n * @example\n * validateMultipartFormDocs(\n * { type: 'object', properties: { avatar: { type: 'string', format: 'binary' } } },\n * { type: 'single', field: 'avatar', required: true },\n * '/users/:id/avatar'\n * )\n */\n validateMultipartFormDocs(\n userDefinedMultipartSchema: any,\n routePath: string,\n uploadConfig?: UploadConfig\n ): void {\n const errors: string[] = [];\n const properties = userDefinedMultipartSchema?.properties || {};\n const requiredFields = userDefinedMultipartSchema?.required || [];\n\n const expectedFields: Array<{\n name: string;\n required: boolean;\n expectedType: \"single\" | \"array\";\n }> = [];\n\n if (uploadConfig?.type === \"single\") {\n expectedFields.push({\n name: uploadConfig.field,\n required: uploadConfig.required !== false,\n expectedType: \"single\",\n });\n } else if (uploadConfig?.type === \"array\") {\n expectedFields.push({\n name: uploadConfig.field,\n required: uploadConfig.required !== false,\n expectedType: \"array\",\n });\n } else if (uploadConfig?.type === \"fields\") {\n for (const field of uploadConfig.fields) {\n if (!(\"type\" in field)) {\n expectedFields.push({\n name: field.name,\n // legacy shape has no type and no required — default to required\n required:\n (uploadConfig as ArkosRouterBaseUploadConfig).required ===\n undefined\n ? true\n : ((uploadConfig as ArkosRouterBaseUploadConfig)\n .required as boolean),\n expectedType: \"array\",\n });\n } else if (field.type)\n expectedFields.push({\n name: field.name,\n required:\n field.type === undefined ? true : field.required !== false,\n expectedType: field.type ?? \"array\",\n });\n }\n }\n\n for (const { name, required, expectedType } of expectedFields) {\n const schemaKey = this.resolveSchemaFieldName(name);\n const fieldSchema = properties[schemaKey];\n\n if (!fieldSchema) {\n errors.push(\n `Missing upload field '${name}' in multipart/form-data schema`\n );\n continue;\n }\n\n if (expectedType === \"single\") {\n if (fieldSchema.type !== \"string\")\n errors.push(\n `Upload field '${name}' must have type 'string', got '${fieldSchema.type}'`\n );\n\n if (fieldSchema.format !== \"binary\")\n errors.push(\n `Upload field '${name}' must have format 'binary', got '${fieldSchema.format || \"undefined\"}'`\n );\n } else if (expectedType === \"array\") {\n if (fieldSchema.type !== \"array\") {\n errors.push(\n `Upload field '${name}' must have type 'array', got '${fieldSchema.type}'`\n );\n } else if (\n !fieldSchema.items ||\n fieldSchema.items.type !== \"string\" ||\n fieldSchema.items.format !== \"binary\"\n )\n errors.push(\n `Upload field '${name}' must have items with type 'string' and format 'binary'`\n );\n }\n\n const isMarkedRequired = requiredFields.includes(schemaKey);\n if (required && !isMarkedRequired)\n errors.push(\n `Upload field '${name}' is required in config but not marked as required in schema`\n );\n\n if (!required && isMarkedRequired)\n errors.push(\n `Upload field '${name}' is not required in config but marked as required in schema`\n );\n }\n\n if (errors.length > 0) {\n throw new Error(\n `ValidationError: Invalid multipart/form-data schema for route '${routePath}':\\n${errors.map((e) => ` - ${e}`).join(\"\\n\")}`\n );\n }\n }\n}\n\nconst arkosRouterOpenApiManager = new ArkosRouterOpenAPIManager();\n\nexport default arkosRouterOpenApiManager;\n"]}
|
|
@@ -17,12 +17,13 @@ function ArkosRouter(options) {
|
|
|
17
17
|
const router = (0, express_1.Router)(options);
|
|
18
18
|
return (0, apply_arkos_router_proxy_1.applyArkosRouterProxy)(router, options);
|
|
19
19
|
}
|
|
20
|
+
const hasDuplicatedPath = (path) => /^(\/.+)\1/.test(path);
|
|
20
21
|
function generateOpenAPIFromApp(app) {
|
|
21
22
|
const routes = (0, helpers_1.extractArkosRoutes)(app);
|
|
22
23
|
const arkosConfig = (0, exports_1.getArkosConfig)();
|
|
23
24
|
let paths = {};
|
|
24
|
-
routes.forEach(({ path, method, config }) => {
|
|
25
|
-
if (config?.experimental?.openapi === false)
|
|
25
|
+
routes.forEach(({ path, method, config, routeOptions }) => {
|
|
26
|
+
if (config?.experimental?.openapi === false || hasDuplicatedPath(path))
|
|
26
27
|
return;
|
|
27
28
|
const originalPath = path;
|
|
28
29
|
const pathParatemersFromRoutePath = (0, helpers_1.extractPathParams)(path);
|
|
@@ -101,7 +102,12 @@ function generateOpenAPIFromApp(app) {
|
|
|
101
102
|
...convertedOpenAPI,
|
|
102
103
|
summary: openapi?.summary || `${path}`,
|
|
103
104
|
description: openapi?.description || `${method} ${path}`,
|
|
104
|
-
|
|
105
|
+
servers: openapi?.servers || routeOptions?.openapi?.servers || undefined,
|
|
106
|
+
security: openapi?.security || routeOptions?.openapi?.security || undefined,
|
|
107
|
+
externalDocs: openapi?.externalDocs ||
|
|
108
|
+
routeOptions?.openapi?.externalDocs ||
|
|
109
|
+
undefined,
|
|
110
|
+
tags: openapi?.tags || routeOptions?.openapi?.tags || ["Defaults"],
|
|
105
111
|
operationId: openapi.operationId || `${method.toLowerCase()}:${path}`,
|
|
106
112
|
parameters: allParameters,
|
|
107
113
|
...(!convertedOpenAPI.requestBody &&
|
|
@@ -124,15 +130,13 @@ function generateOpenAPIFromApp(app) {
|
|
|
124
130
|
})(),
|
|
125
131
|
},
|
|
126
132
|
}),
|
|
127
|
-
...(
|
|
128
|
-
?.schema &&
|
|
129
|
-
!multipartFormSchema &&
|
|
133
|
+
...(!multipartFormSchema &&
|
|
130
134
|
!config?.validation?.body &&
|
|
131
135
|
hasUploadFields && {
|
|
132
136
|
requestBody: {
|
|
133
137
|
content: (() => {
|
|
134
138
|
const schema = convertedOpenAPI?.requestBody?.content?.["application/json"]
|
|
135
|
-
?.schema;
|
|
139
|
+
?.schema || {};
|
|
136
140
|
return {
|
|
137
141
|
"multipart/form-data": {
|
|
138
142
|
schema: openapi_schema_converter_1.default.flattenSchema(arkos_router_openapi_manager_1.default.addUploadFields(config?.experimental?.uploads || {}, schema)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/arkos-router/index.ts"],"names":[],"mappings":";;;;;AAmCA,8BAQC;AAED,wDAyLC;AAtOD,qCAAgD;AAGhD,6CAAwE;AACxE,2CAA+C;AAC/C,4EAAiD;AACjD,wIAA4G;AAC5G,4HAAkG;AAClG,kGAAuE;AACvE,uFAAiF;AA0BjF,SAAwB,WAAW,CACjC,OAGC;IAED,MAAM,MAAM,GAAG,IAAA,gBAAM,EAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,IAAA,gDAAqB,EAAC,MAAM,EAAE,OAAO,CAAiB,CAAC;AAChE,CAAC;AAED,SAAgB,sBAAsB,CAAC,GAAQ;IAC7C,MAAM,MAAM,GAAG,IAAA,4BAAkB,EAAC,GAAG,CAAC,CAAC;IACvC,MAAM,WAAW,GAAG,IAAA,wBAAc,GAAE,CAAC;IAErC,IAAI,KAAK,GAGL,EAAE,CAAC;IAEP,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;QAC1C,IAAI,MAAM,EAAE,YAAY,EAAE,OAAO,KAAK,KAAK;YAAE,OAAO;QACpD,MAAM,YAAY,GAAG,IAAI,CAAC;QAE1B,MAAM,2BAA2B,GAAG,IAAA,2BAAiB,EAAC,IAAI,CAAC,CAAC;QAC5D,KAAK,MAAM,SAAS,IAAI,2BAA2B,EAAE,CAAC;YACpD,IAAI,GAAG,IAAI,CAAC,UAAU,CACpB,IAAI,SAAS,EAAE,EACf,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,IAAI,CAAC,CAAC,CAAC,IAAI,SAAS,GAAG,CAC/D,CAAC;QACJ,CAAC;QAED,IAAI,aAAa,GAAG,CAAC,IAAI,CA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GAAG,EAAE;wBACb,MAAM,MAAM,GAAG,qBAAqB,CAClC,MAAM,EAAE,UAAU,EAAE,IAAW,CAChC,CAAC;wBAEF,OAAO;4BACL,GAAG,gBAAgB,EAAE,WAAW,EAAE,OAAO;4BACzC,GAAG,CAAC,eAAe,IAAI;gCACrB,qBAAqB,EAAE;oCACrB,MAAM,EAAE,kCAAsB,CAAC,aAAa,CAC1C,sCAAyB,CAAC,eAAe,CACvC,MAAM,CAAC,YAAY,EAAE,OAAQ,EAC7B,MAAM,CACP,CACF;iCACF;6BACF,CAAC;4BACF,kBAAkB,EAAE;gCAClB,MAAM;6BACP;yBACF,CAAC;oBACJ,CAAC,CAAC,EAAE;iBACL;aACF,CAAC;YACJ,GAAG,CAAC,gBAAgB,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,kBAAkB,CAAC;gBAC9D,EAAE,MAAM;gBACR,CAAC,mBAAmB;gBACpB,CAAE,MAAc,EAAE,UAAU,EAAE,IAAI;gBAClC,eAAe,IAAI;gBACjB,WAAW,EAAE;oBACX,OAAO,EAAE,CAAC,GAAG,EAAE;wBACb,MAAM,MAAM,GACV,gBAAgB,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,kBAAkB,CAAC;4BAC1D,EAAE,MAAM,CAAC;wBAEb,OAAO;4BACL,qBAAqB,EAAE;gCACrB,MAAM,EAAE,kCAAsB,CAAC,aAAa,CAC1C,sCAAyB,CAAC,eAAe,CACvC,MAAM,EAAE,YAAY,EAAE,OAAQ,IAAI,EAAE,EACpC,MAAM,CACP,CACF;6BACF;4BACD,GAAG,gBAAgB,EAAE,WAAW,EAAE,OAAO;yBAC1C,CAAC;oBACJ,CAAC,CAAC,EAAE;iBACL;aACF,CAAC;SACL,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { Router, RouterOptions } from \"express\";\nimport { IArkosRouter, ArkosRouteConfig } from \"./types\";\nimport { OpenAPIV3 } from \"openapi-types\";\nimport { extractArkosRoutes, extractPathParams } from \"./utils/helpers\";\nimport { getArkosConfig } from \"../../exports\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport classValidatorToJsonSchema from \"../../modules/swagger/utils/helpers/class-validator-to-json-schema\";\nimport openApiSchemaConverter from \"../../modules/swagger/utils/helpers/openapi-schema-converter\";\nimport arkosRouterOpenApiManager from \"./arkos-router-openapi-manager\";\nimport { applyArkosRouterProxy } from \"./utils/helpers/apply-arkos-router-proxy\";\n\n/**\n * Creates an enhanced Express Router with features like OpenAPI documentation capabilities and smart data validation.\n *\n * The ArkosRouter extends the standard Express Router with the ability to\n * automatically capture OpenAPI metadata from route configurations.\n *\n * @example\n * const router = ArkosRouter();\n *\n * router.get(\n * {\n * path: \"/users/:id\",\n * openapi: {\n * summary: \"Get user by ID\",\n * tags: [\"Users\"]\n * }\n * },\n * (req, res) => { ... }\n * );\n *\n * @returns {IArkosRouter} A proxied Express Router instance with enhanced OpenAPI capabilities\n *\n * @see {@link ArkosRouteConfig} for configuration options\n */\nexport default function ArkosRouter(\n options?: RouterOptions & {\n prefix?: string | RegExp | Array<string | RegExp>;\n openapi?: { tags?: string[] };\n }\n): IArkosRouter {\n const router = Router(options);\n return applyArkosRouterProxy(router, options) as IArkosRouter;\n}\n\nexport function generateOpenAPIFromApp(app: any) {\n const routes = extractArkosRoutes(app);\n const arkosConfig = getArkosConfig();\n\n let paths: Record<\n string,\n Record<string, Partial<OpenAPIV3.OperationObject>>\n > = {};\n\n routes.forEach(({ path, method, config }) => {\n if (config?.experimental?.openapi === false) return;\n const originalPath = path;\n\n const pathParatemersFromRoutePath = extractPathParams(path);\n for (const parameter of pathParatemersFromRoutePath) {\n path = path.replaceAll(\n `:${parameter}`,\n parameter.endsWith(\"?\") ? `{${parameter}}?` : `{${parameter}}`\n );\n }\n\n let wildcardCount = (path.match(/\\*/g) || []).length;\n let wildcardIndex = 0;\n path = path.replace(/\\*/g, () => {\n wildcardIndex++;\n return wildcardCount === 1 ? \"{path}\" : `{path${wildcardIndex}}`;\n });\n\n if (!paths[path]) paths[path] = {};\n\n if (typeof config?.experimental?.openapi === \"boolean\") {\n config = {\n ...config,\n experimental: {\n ...config.experimental,\n openapi: {},\n },\n };\n }\n\n const openapi =\n typeof config?.experimental?.openapi === \"object\" &&\n config.experimental.openapi !== null\n ? config.experimental.openapi\n : {};\n\n const validatorToJsonSchema =\n arkosConfig?.validation?.resolver === \"zod\"\n ? zodToJsonSchema\n : classValidatorToJsonSchema;\n\n let parameters = [];\n const validationToParameterMapping = {\n query: \"query\",\n params: \"path\",\n headers: \"header\",\n cookies: \"cookie\",\n };\n\n if (typeof config?.validation !== \"boolean\" && config?.validation) {\n for (const [key, val] of Object.entries(config?.validation)) {\n if ([\"body\"].includes(key)) continue;\n if ((config?.validation as any)[key]) {\n const jsonSchema = validatorToJsonSchema(val as any);\n const params = openApiSchemaConverter.jsonSchemaToOpenApiParameters(\n (validationToParameterMapping as any)[key],\n jsonSchema\n );\n parameters.push(...params);\n }\n }\n }\n\n const convertedOpenAPI =\n openApiSchemaConverter.convertOpenAPIConfig(openapi);\n\n const allParameters: OpenAPIV3.ParameterObject[] = [\n ...(convertedOpenAPI.parameters || []),\n ...parameters,\n ];\n\n for (const parameter of pathParatemersFromRoutePath) {\n if (\n !allParameters.find(\n ({ name, in: paramIn }) =>\n name === parameter.replace(\"?\", \"\") && paramIn === \"path\"\n )\n )\n allParameters.push({\n name: parameter,\n in: \"path\",\n required: !parameter.includes(\"?\"),\n schema: { type: \"string\" },\n });\n }\n\n for (const param of allParameters) {\n if (\n !pathParatemersFromRoutePath.includes(param.name) &&\n !pathParatemersFromRoutePath.includes(`${param.name}?`) &&\n param.in === \"path\" &&\n param.name !== \"*\"\n )\n throw new Error(\n `ValidationError: Trying to define path parameter '${param.name}' but it is not present in your pathname ${originalPath}`\n );\n }\n\n delete convertedOpenAPI.parameters;\n const hasUploadFields =\n Object.keys(config?.experimental?.uploads || {}).length > 0;\n const multipartFormSchema =\n convertedOpenAPI?.requestBody?.content?.[\"multipart/form-data\"];\n\n if (hasUploadFields && multipartFormSchema)\n arkosRouterOpenApiManager.validateMultipartFormDocs(\n multipartFormSchema,\n path,\n config?.experimental?.uploads\n );\n\n (paths as any)[path][method.toLowerCase()] = {\n ...convertedOpenAPI,\n summary: openapi?.summary || `${path}`,\n description: openapi?.description || `${method} ${path}`,\n tags: openapi?.tags || [\"Defaults\"],\n operationId: openapi.operationId || `${method.toLowerCase()}:${path}`,\n parameters: allParameters,\n ...(!convertedOpenAPI.requestBody &&\n config?.validation &&\n config?.validation?.body && {\n requestBody: {\n content: (() => {\n const schema = validatorToJsonSchema(\n config?.validation?.body as any\n );\n\n return {\n ...convertedOpenAPI?.requestBody?.content,\n ...(hasUploadFields && {\n \"multipart/form-data\": {\n schema: openApiSchemaConverter.flattenSchema(\n arkosRouterOpenApiManager.addUploadFields(\n config.experimental?.uploads!,\n schema\n )\n ),\n },\n }),\n \"application/json\": {\n schema,\n },\n };\n })(),\n },\n }),\n ...(convertedOpenAPI?.requestBody?.content?.[\"application/json\"]\n ?.schema &&\n !multipartFormSchema &&\n !(config as any)?.validation?.body &&\n hasUploadFields && {\n requestBody: {\n content: (() => {\n const schema =\n convertedOpenAPI?.requestBody?.content?.[\"application/json\"]\n ?.schema;\n\n return {\n \"multipart/form-data\": {\n schema: openApiSchemaConverter.flattenSchema(\n arkosRouterOpenApiManager.addUploadFields(\n config?.experimental?.uploads! || {},\n schema\n )\n ),\n },\n ...convertedOpenAPI?.requestBody?.content,\n };\n })(),\n },\n }),\n };\n });\n\n return paths;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/arkos-router/index.ts"],"names":[],"mappings":";;;;;AA8GA,8BAKC;AAID,wDA+LC;AAtTD,qCAAgD;AAGhD,6CAAwE;AACxE,2CAA+C;AAC/C,4EAAiD;AACjD,wIAA4G;AAC5G,4HAAkG;AAClG,kGAAuE;AACvE,uFAAiF;AAqGj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EAAE,UAAU;gBAClB,MAAM,EAAE,UAAU,EAAE,IAAI,IAAI;gBAC1B,WAAW,EAAE;oBACX,OAAO,EAAE,CAAC,GAAG,EAAE;wBACb,MAAM,MAAM,GAAG,qBAAqB,CAClC,MAAM,EAAE,UAAU,EAAE,IAAW,CAChC,CAAC;wBAEF,OAAO;4BACL,GAAG,gBAAgB,EAAE,WAAW,EAAE,OAAO;4BACzC,GAAG,CAAC,eAAe,IAAI;gCACrB,qBAAqB,EAAE;oCACrB,MAAM,EAAE,kCAAsB,CAAC,aAAa,CAC1C,sCAAyB,CAAC,eAAe,CACvC,MAAM,CAAC,YAAY,EAAE,OAAQ,EAC7B,MAAM,CACP,CACF;iCACF;6BACF,CAAC;4BACF,kBAAkB,EAAE;gCAClB,MAAM;6BACP;yBACF,CAAC;oBACJ,CAAC,CAAC,EAAE;iBACL;aACF,CAAC;YACJ,GAAG,CAAC,CAAC,mBAAmB;gBACtB,CAAE,MAAc,EAAE,UAAU,EAAE,IAAI;gBAClC,eAAe,IAAI;gBACjB,WAAW,EAAE;oBACX,OAAO,EAAE,CAAC,GAAG,EAAE;wBACb,MAAM,MAAM,GACV,gBAAgB,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,kBAAkB,CAAC;4BAC1D,EAAE,MAAM,IAAI,EAAE,CAAC;wBAEnB,OAAO;4BACL,qBAAqB,EAAE;gCACrB,MAAM,EAAE,kCAAsB,CAAC,aAAa,CAC1C,sCAAyB,CAAC,eAAe,CACvC,MAAM,EAAE,YAAY,EAAE,OAAQ,IAAI,EAAE,EACpC,MAAM,CACP,CACF;6BACF;4BACD,GAAG,gBAAgB,EAAE,WAAW,EAAE,OAAO;yBAC1C,CAAC;oBACJ,CAAC,CAAC,EAAE;iBACL;aACF,CAAC;SACuB,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { Router, RouterOptions } from \"express\";\nimport { IArkosRouter } from \"./types\";\nimport { OpenAPIV3 } from \"openapi-types\";\nimport { extractArkosRoutes, extractPathParams } from \"./utils/helpers\";\nimport { getArkosConfig } from \"../../exports\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport classValidatorToJsonSchema from \"../../modules/swagger/utils/helpers/class-validator-to-json-schema\";\nimport openApiSchemaConverter from \"../../modules/swagger/utils/helpers/openapi-schema-converter\";\nimport arkosRouterOpenApiManager from \"./arkos-router-openapi-manager\";\nimport { applyArkosRouterProxy } from \"./utils/helpers/apply-arkos-router-proxy\";\nimport { Arkos } from \"../../types/arkos\";\n\nexport type ArkosRouterOptions = {\n /**\n * Prefix to apply to all routes in this router.\n * Nested routers inherit and concatenate prefixes from parent routers.\n *\n * @since 1.5.0-beta\n * @example\n * // All routes in this router will be prefixed with \"/api\"\n * prefix: \"/api\"\n */\n prefix?: string | RegExp | Array<string | RegExp>;\n /**\n * OpenAPI metadata to apply to all routes in this router.\n * Nested routers inherit from parent routers unless explicitly overridden.\n * Route-level openapi config fully replaces inherited values when defined.\n *\n * @since 1.6.0-beta\n * @example\n * openapi: {\n * tags: [\"Users\"],\n * security: [{ bearerAuth: [] }]\n * }\n */\n openapi?: {\n /**\n * Tags to apply to all routes in this router, used to group them in OpenAPI documentation.\n * Route-level tags fully replaces this value when defined.\n *\n * @since 1.6.0-beta\n * @example\n * // Group all routes in this router under \"Users\"\n * tags: [\"Users\"]\n */\n tags?: string[];\n /**\n * Security requirements to apply to all routes in this router.\n * Route-level security fully replaces this value when defined.\n *\n * @since 1.6.2-canary.1\n * @example\n * // Require bearer auth for all routes in this router\n * security: [{ bearerAuth: [] }]\n *\n * // Explicitly make all routes public (overridable per route)\n * security: []\n */\n security?: OpenAPIV3.SecurityRequirementObject[];\n\n /**\n * Server definitions to apply to all routes in this router.\n * Follows the OpenAPI 3.0 Server Object specification.\n * Route-level servers fully replaces this value when defined.\n *\n * @since 1.6.2-canary.1\n * @example\n * servers: [{ url: \"https://api.example.com/v2\", description: \"V2 API\" }]\n */\n servers?: OpenAPIV3.ServerObject[];\n /**\n * External documentation to apply to all routes in this router.\n * Route-level externalDocs fully replaces this value when defined.\n *\n * @since 1.6.2-canary.1\n * @example\n * externalDocs: {\n * description: \"Find more information here\",\n * url: \"https://docs.example.com/users\"\n * }\n */\n externalDocs?: OpenAPIV3.ExternalDocumentationObject;\n };\n};\n\n/**\n * Creates an enhanced Express Router with features like OpenAPI documentation capabilities and smart data validation.\n *\n * The ArkosRouter extends the standard Express Router with the ability to\n * automatically capture OpenAPI metadata from route configurations.\n *\n * @example\n * const router = ArkosRouter();\n *\n * router.get(\n * {\n * path: \"/users/:id\",\n * openapi: {\n * summary: \"Get user by ID\",\n * tags: [\"Users\"]\n * }\n * },\n * (req, res) => { ... }\n * );\n *\n * @returns {IArkosRouter} A proxied Express Router instance with enhanced OpenAPI capabilities\n *\n * @see {@link https://www.arkosjs.com/docs/reference/arkos-router} for configuration options\n * @since 1.4.0-beta\n */\nexport default function ArkosRouter(\n options?: RouterOptions & ArkosRouterOptions\n): IArkosRouter {\n const router = Router(options);\n return applyArkosRouterProxy(router, options) as IArkosRouter;\n}\n\nconst hasDuplicatedPath = (path: string) => /^(\\/.+)\\1/.test(path);\n\nexport function generateOpenAPIFromApp(app: Arkos) {\n const routes = extractArkosRoutes(app);\n const arkosConfig = getArkosConfig();\n\n let paths: Record<\n string,\n Record<string, Partial<OpenAPIV3.OperationObject>>\n > = {};\n\n routes.forEach(({ path, method, config, routeOptions }) => {\n if (config?.experimental?.openapi === false || hasDuplicatedPath(path))\n return;\n const originalPath = path;\n\n const pathParatemersFromRoutePath = extractPathParams(path);\n for (const parameter of pathParatemersFromRoutePath) {\n path = path.replaceAll(\n `:${parameter}`,\n parameter.endsWith(\"?\") ? `{${parameter}}?` : `{${parameter}}`\n );\n }\n\n let wildcardCount = (path.match(/\\*/g) || []).length;\n let wildcardIndex = 0;\n path = path.replace(/\\*/g, () => {\n wildcardIndex++;\n return wildcardCount === 1 ? \"{path}\" : `{path${wildcardIndex}}`;\n });\n\n if (!paths[path]) paths[path] = {};\n\n if (typeof config?.experimental?.openapi === \"boolean\") {\n config = {\n ...config,\n experimental: {\n ...config.experimental,\n openapi: {},\n },\n };\n }\n\n const openapi =\n typeof config?.experimental?.openapi === \"object\" &&\n config.experimental.openapi !== null\n ? config.experimental.openapi\n : {};\n\n const validatorToJsonSchema =\n arkosConfig?.validation?.resolver === \"zod\"\n ? zodToJsonSchema\n : classValidatorToJsonSchema;\n\n let parameters = [];\n const validationToParameterMapping = {\n query: \"query\",\n params: \"path\",\n headers: \"header\",\n cookies: \"cookie\",\n };\n\n if (typeof config?.validation !== \"boolean\" && config?.validation) {\n for (const [key, val] of Object.entries(config?.validation)) {\n if ([\"body\"].includes(key)) continue;\n if ((config?.validation as any)[key]) {\n const jsonSchema = validatorToJsonSchema(val as any);\n const params = openApiSchemaConverter.jsonSchemaToOpenApiParameters(\n (validationToParameterMapping as any)[key],\n jsonSchema\n );\n parameters.push(...params);\n }\n }\n }\n\n const convertedOpenAPI =\n openApiSchemaConverter.convertOpenAPIConfig(openapi);\n\n const allParameters: OpenAPIV3.ParameterObject[] = [\n ...(convertedOpenAPI.parameters || []),\n ...parameters,\n ];\n\n for (const parameter of pathParatemersFromRoutePath) {\n if (\n !allParameters.find(\n ({ name, in: paramIn }) =>\n name === parameter.replace(\"?\", \"\") && paramIn === \"path\"\n )\n )\n allParameters.push({\n name: parameter,\n in: \"path\",\n required: !parameter.includes(\"?\"),\n schema: { type: \"string\" },\n });\n }\n\n for (const param of allParameters) {\n if (\n !pathParatemersFromRoutePath.includes(param.name) &&\n !pathParatemersFromRoutePath.includes(`${param.name}?`) &&\n param.in === \"path\" &&\n param.name !== \"*\"\n )\n throw new Error(\n `ValidationError: Trying to define path parameter '${param.name}' but it is not present in your pathname ${originalPath}`\n );\n }\n\n delete convertedOpenAPI.parameters;\n const hasUploadFields =\n Object.keys(config?.experimental?.uploads || {}).length > 0;\n const multipartFormSchema =\n convertedOpenAPI?.requestBody?.content?.[\"multipart/form-data\"];\n\n if (hasUploadFields && multipartFormSchema)\n arkosRouterOpenApiManager.validateMultipartFormDocs(\n multipartFormSchema,\n path,\n config?.experimental?.uploads\n );\n\n (paths as any)[path][method.toLowerCase()] = {\n ...convertedOpenAPI,\n summary: openapi?.summary || `${path}`,\n description: openapi?.description || `${method} ${path}`,\n servers: openapi?.servers || routeOptions?.openapi?.servers || undefined,\n security:\n openapi?.security || routeOptions?.openapi?.security || undefined,\n externalDocs:\n openapi?.externalDocs ||\n routeOptions?.openapi?.externalDocs ||\n undefined,\n tags: openapi?.tags || routeOptions?.openapi?.tags || [\"Defaults\"],\n operationId: openapi.operationId || `${method.toLowerCase()}:${path}`,\n parameters: allParameters,\n ...(!convertedOpenAPI.requestBody &&\n config?.validation &&\n config?.validation?.body && {\n requestBody: {\n content: (() => {\n const schema = validatorToJsonSchema(\n config?.validation?.body as any\n );\n\n return {\n ...convertedOpenAPI?.requestBody?.content,\n ...(hasUploadFields && {\n \"multipart/form-data\": {\n schema: openApiSchemaConverter.flattenSchema(\n arkosRouterOpenApiManager.addUploadFields(\n config.experimental?.uploads!,\n schema\n )\n ),\n },\n }),\n \"application/json\": {\n schema,\n },\n };\n })(),\n },\n }),\n ...(!multipartFormSchema &&\n !(config as any)?.validation?.body &&\n hasUploadFields && {\n requestBody: {\n content: (() => {\n const schema =\n convertedOpenAPI?.requestBody?.content?.[\"application/json\"]\n ?.schema || {};\n\n return {\n \"multipart/form-data\": {\n schema: openApiSchemaConverter.flattenSchema(\n arkosRouterOpenApiManager.addUploadFields(\n config?.experimental?.uploads! || {},\n schema\n )\n ),\n },\n ...convertedOpenAPI?.requestBody?.content,\n };\n })(),\n },\n }),\n } as OpenAPIV3.PathItemObject;\n });\n\n return paths;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/utils/arkos-router/types/index.ts"],"names":[],"mappings":"","sourcesContent":["import {\n IRoute,\n IRouter,\n IRouterHandler,\n IRouterMatcher,\n Locals,\n} from \"express\";\nimport { z, ZodSchema } from \"zod\";\nimport { Options as RateLimitOptions } from \"express-rate-limit\";\nimport { Options as QueryParserOptions } from \"../../../utils/helpers/query-parser.helpers\";\nimport { DetailedAccessControlRule } from \"../../../types/auth\";\nimport { ArkosErrorRequestHandler, ArkosRequestHandler } from \"../../../types\";\nimport compression from \"compression\";\nimport { OpenApiConfig } from \"./openapi-config\";\nimport { UploadConfig } from \"./upload-config\";\nimport { BodyParserConfig } from \"./body-parser-config\";\n\nexport type ArkosUseConfig = Pick<\n ArkosRouteConfig,\n | \"authentication\"\n | \"rateLimit\"\n | \"compression\"\n | \"queryParser\"\n | \"bodyParser\"\n | \"disabled\"\n> & {\n path?: PathParams; // optional unlike ArkosRouteConfig where path is required\n};\n\ntype InferValidationType<T, Fallback> = T extends ZodSchema\n ? z.infer<T>\n : T extends new (...args: any[]) => infer I\n ? I\n : Fallback;\n\nexport type PathParams = string | RegExp | Array<string | RegExp>;\n\nexport type ArkosAnyRequestHandler =\n | ArkosRequestHandler\n | ArkosErrorRequestHandler\n | Array<ArkosRequestHandler | ArkosErrorRequestHandler>;\n\n/**\n * Handler function for HTTP methods that accepts route configuration and request handlers.\n *\n * @param {ArkosRouteConfig} config - The route configuration object.\n * @param {...(ArkosRequestHandler | ArkosErrorRequestHandler)[]} handlers - Request and error handlers for the route.\n * @returns {IRouter} The Express router instance.\n */\ntype RouterMethodHandler<T> = IRouterHandler<T> &\n IRouterMatcher<T> & {\n (config: PathParams, ...handlers: Array<ArkosAnyRequestHandler>): T;\n <\n TQuery extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n TBody extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n TParams extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n >(\n config: ArkosRouteConfig<TQuery, TBody, TParams>,\n ...handlers: Array<\n | ArkosRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n any\n >\n | Array<\n ArkosRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n any\n >\n >\n >\n ): T;\n <\n TQuery extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n TBody extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n TParams extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n >(\n config: ArkosRouteConfig<TQuery, TBody, TParams>,\n ...handlers: Array<\n | ArkosErrorRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n any\n >\n | Array<\n ArkosErrorRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n any\n >\n >\n >\n ): T;\n };\n\nexport type ArkosRouteMethodHandler<T> = {\n (\n config: ArkosAnyRequestHandler | Omit<ArkosRouteConfig, \"path\">,\n ...handlers: Array<\n | ArkosRequestHandler\n | ArkosErrorRequestHandler\n | Array<ArkosRequestHandler | ArkosErrorRequestHandler>\n >\n ): T;\n <\n TQuery extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n TBody extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n TParams extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n >(\n config: Omit<ArkosRouteConfig<TQuery, TBody, TParams>, \"path\">,\n ...handlers: Array<\n | ArkosRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n Locals\n >\n | Array<\n ArkosRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n Locals\n >\n >\n >\n ): T;\n\n <\n TQuery extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n TBody extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n TParams extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n >(\n config: Omit<ArkosRouteConfig<TQuery, TBody, TParams>, \"path\">,\n ...handlers: Array<\n | ArkosErrorRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n Locals\n >\n | Array<\n ArkosErrorRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n Locals\n >\n >\n >\n ): T;\n};\n\n/**\n * Handler function for `use` that accepts route configuration and middleware handlers.\n *\n * @param {ArkosUseConfig} config - The use configuration object or path.\n * @param {...ArkosAnyRequestHandler} handlers - Middleware handlers.\n * @returns {T} The router instance.\n */\n\nexport type UseMethodHandler<T> = IRouterHandler<T> &\n IRouterMatcher<T> & {\n (\n config: ArkosUseConfig,\n ...handlers: Array<ArkosRequestHandler | Array<ArkosRequestHandler>>\n ): T;\n (\n config: ArkosUseConfig,\n ...handlers: Array<\n ArkosErrorRequestHandler | Array<ArkosErrorRequestHandler>\n >\n ): T;\n };\n\nexport interface IArkosRoute extends IRoute {\n /** GET method handler with route configuration support */\n get: ArkosRouteMethodHandler<this>;\n /** POST method handler with route configuration support */\n post: ArkosRouteMethodHandler<this>;\n /** PUT method handler with route configuration support */\n put: ArkosRouteMethodHandler<this>;\n /** PATCH method handler with route configuration support */\n patch: ArkosRouteMethodHandler<this>;\n /** DELETE method handler with route configuration support */\n delete: ArkosRouteMethodHandler<this>;\n /** OPTIONS method handler with route configuration support */\n options: ArkosRouteMethodHandler<this>;\n /** HEAD method handler with route configuration support */\n head: ArkosRouteMethodHandler<this>;\n // /** TRACE method handler with route configuration support */\n trace: ArkosRouteMethodHandler<this>;\n /** ALL methods handler with route configuration support */\n all: ArkosRouteMethodHandler<this>;\n}\n\n/**\n * Creates an enhanced Express Router with features like OpenAPI documentation capabilities and smart data validation.\n *\n * The ArkosRouter extends the standard Express Router with the ability to\n * automatically capture OpenAPI metadata from route configurations.\n *\n * @example\n * const router = ArkosRouter();\n *\n * router.get(\n * {\n * path: \"/users/:id\",\n * openapi: {\n * summary: \"Get user by ID\",\n * tags: [\"Users\"]\n * }\n * },\n * (req, res) => { ... }\n * );\n *\n * @returns {IArkosRouter} A proxied Express Router instance with enhanced OpenAPI capabilities\n *\n * @see {@link ArkosRouteConfig} for configuration options\n */\nexport interface IArkosRouter extends IRouter {\n /** GET method handler with route configuration support */\n get: RouterMethodHandler<this>;\n /** POST method handler with route configuration support */\n post: RouterMethodHandler<this>;\n /** PUT method handler with route configuration support */\n put: RouterMethodHandler<this>;\n /** PATCH method handler with route configuration support */\n patch: RouterMethodHandler<this>;\n /** DELETE method handler with route configuration support */\n delete: RouterMethodHandler<this>;\n /** OPTIONS method handler with route configuration support */\n options: RouterMethodHandler<this>;\n /** HEAD method handler with route configuration support */\n head: RouterMethodHandler<this>;\n // /** TRACE method handler with route configuration support */\n trace: RouterMethodHandler<this>;\n /** ALL methods handler with route configuration support */\n all: RouterMethodHandler<this>;\n use: UseMethodHandler<this>;\n\n route<T extends string>(prefix: T): IArkosRoute;\n route(prefix: PathParams): IArkosRoute;\n}\n\n/**\n * Configuration object for defining routes in Arkos.js.\n */\nexport type ArkosRouteConfig<\n TQuery extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n TBody extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n TParams extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | false\n | undefined = any,\n> = {\n /**\n * Disables the route by not mounting it internally.\n */\n disabled?: boolean;\n /**\n * The URL path pattern for the route.\n *\n * @example \"/api/users/:id\"\n */\n path: PathParams;\n /**\n * Authentication and authorization configuration.\n *\n * @remarks\n * - Set to `true` to require authentication without specific permissions.\n * - Set to `false` or omit to allow unauthenticated access.\n * - Provide an object to specify resource-based access control with resource name, action, and optional custom rules.\n */\n authentication?:\n | boolean\n | {\n resource: string;\n action: string;\n rule?: DetailedAccessControlRule | string[] | \"*\";\n };\n /**\n * Request validation configuration using Zod schemas or class constructors.\n *\n * @remarks\n * - Set to `false` to disable all validation.\n * - Provide an object with `query`, `body`, and/or `params` properties to validate specific parts of the request.\n * - Each property accepts a Zod schema, a class constructor, or `false` to disable validation for that part.\n */\n validation?:\n | false\n | {\n query?: TQuery;\n body?: TBody;\n params?: TParams;\n };\n /**\n * Rate limiting configuration for this route.\n *\n * @see {@link https://www.npmjs.com/package/express-rate-limit express-rate-limit} for available options.\n */\n rateLimit?: Partial<RateLimitOptions>;\n\n /**\n * Allows to define options for npm package compression.\n * Nothing is passed by default.\n *\n * @see {@link https://www.npmjs.com/package/compression compression} for further details.\n */\n compression?: compression.CompressionOptions;\n /**\n * Options to define how query must be parsed.\n *\n * @example\n * ```\n * GET /api/product?saleId=null\n * ```\n *\n * Normally would parsed to { saleId: \"null\" } so query parser\n * trough setting option `parseNull` will transform { saleId: null }\n *\n * @default\n * ```\n * {\n * parseNull: true,\n * parseUndefined: true,\n * parseBoolean: true,\n * }\n * ```\n *\n * @remarks\n * parseNumber may convert fields that are string but you only passed\n * numbers to query pay attention to this.\n *\n * Soon a feature to converted the query to the end prisma type will be added.\n */\n queryParser?: QueryParserOptions;\n /**\n * Configuration for request body parsing.\n *\n * @property {(\"json\" | \"urlencoded\" | \"raw\" | \"text\")} parser - The type of body parser to use.\n * @property {object} [options] - Parser-specific options passed to the corresponding Express body parser middleware.\n *\n * @remarks\n * - When `parser` is `\"json\"`, options are passed to `express.json()`.\n * - When `parser` is `\"urlencoded\"`, options are passed to `express.urlencoded()`.\n * - When `parser` is `\"raw\"`, options are passed to `express.raw()`.\n * - When `parser` is `\"text\"`, options are passed to `express.text()`.\n * - Set to `false` to disable body parsing for this route.\n *\n * @see {@link https://expressjs.com/en/api.html#express.json Express body parser documentation}\n */\n bodyParser?: BodyParserConfig | BodyParserConfig[] | false;\n /**\n * Experimental features to be battled tested before being stable\n *\n * PS: These features may be changed without any previous warning.\n */\n experimental?: {\n /**\n * OpenAPI specification for this route.\n *\n * @remarks\n * - Set to `false` to exclude this route from OpenAPI documentation.\n * - Provide a partial OpenAPI operation object to document the route.\n */\n openapi?: false | OpenApiConfig;\n /**\n * Configuration for file upload handling in routes.\n * Supports single file, multiple files from same field, or multiple fields with files.\n */\n uploads?: UploadConfig;\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/utils/arkos-router/types/index.ts"],"names":[],"mappings":"","sourcesContent":["import {\n IRoute,\n IRouter,\n IRouterHandler,\n IRouterMatcher,\n Locals,\n} from \"express\";\nimport { z, ZodSchema } from \"zod\";\nimport { Options as RateLimitOptions } from \"express-rate-limit\";\nimport { Options as QueryParserOptions } from \"../../../utils/helpers/query-parser.helpers\";\nimport { DetailedAccessControlRule } from \"../../../types/auth\";\nimport { ArkosErrorRequestHandler, ArkosRequestHandler } from \"../../../types\";\nimport compression from \"compression\";\nimport { OpenApiConfig } from \"./openapi-config\";\nimport { UploadConfig } from \"./upload-config\";\nimport { BodyParserConfig } from \"./body-parser-config\";\nimport { ArkosRouterOptions } from \"..\";\n\nexport type ArkosUseConfig = Pick<\n ArkosRouteConfig,\n | \"authentication\"\n | \"rateLimit\"\n | \"compression\"\n | \"queryParser\"\n | \"bodyParser\"\n | \"disabled\"\n> & {\n path?: PathParams; // optional unlike ArkosRouteConfig where path is required\n};\n\ntype InferValidationType<T, Fallback> = T extends ZodSchema\n ? z.infer<T>\n : T extends new (...args: any[]) => infer I\n ? I\n : Fallback;\n\nexport type PathParams = string | RegExp | Array<string | RegExp>;\n\nexport type InternalIArkosRouter = IArkosRouter & {\n _arkos: {\n options?: ArkosRouterOptions;\n routes: Array<{\n handler: ArkosAnyRequestHandler;\n config: ArkosRouteConfig;\n method: string;\n }>;\n };\n};\n\nexport type ArkosAnyRequestHandler =\n | ArkosRequestHandler\n | ArkosErrorRequestHandler\n | Array<ArkosRequestHandler | ArkosErrorRequestHandler>;\n\n/**\n * Handler function for HTTP methods that accepts route configuration and request handlers.\n *\n * @param {ArkosRouteConfig} config - The route configuration object.\n * @param {...(ArkosRequestHandler | ArkosErrorRequestHandler)[]} handlers - Request and error handlers for the route.\n * @returns {IRouter} The Express router instance.\n */\ntype RouterMethodHandler<T> = IRouterHandler<T> &\n IRouterMatcher<T> & {\n (config: PathParams, ...handlers: Array<ArkosAnyRequestHandler>): T;\n <\n TQuery extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | false\n | undefined = any,\n TBody extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | false\n | undefined = any,\n TParams extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | false\n | undefined = any,\n >(\n config: ArkosRouteConfig<TQuery, TBody, TParams>,\n ...handlers: Array<\n | ArkosRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n any\n >\n | Array<\n ArkosRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n any\n >\n >\n >\n ): T;\n <\n TQuery extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | false\n | undefined = any,\n TBody extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | false\n | undefined = any,\n TParams extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | false\n | undefined = any,\n >(\n config: ArkosRouteConfig<TQuery, TBody, TParams>,\n ...handlers: Array<\n | ArkosErrorRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n any\n >\n | Array<\n ArkosErrorRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n any\n >\n >\n >\n ): T;\n };\n\nexport type ArkosRouteMethodHandler<T> = {\n (\n config: ArkosAnyRequestHandler | Omit<ArkosRouteConfig, \"path\">,\n ...handlers: Array<\n | ArkosRequestHandler\n | ArkosErrorRequestHandler\n | Array<ArkosRequestHandler | ArkosErrorRequestHandler>\n >\n ): T;\n <\n TQuery extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | null\n | false\n | undefined = any,\n TBody extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | null\n | false\n | undefined = any,\n TParams extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | null\n | false\n | undefined = any,\n >(\n config: Omit<ArkosRouteConfig<TQuery, TBody, TParams>, \"path\">,\n ...handlers: Array<\n | ArkosRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n Locals\n >\n | Array<\n ArkosRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n Locals\n >\n >\n >\n ): T;\n\n <\n TQuery extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | null\n | false\n | undefined = any,\n TBody extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | null\n | false\n | undefined = any,\n TParams extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | null\n | false\n | undefined = any,\n >(\n config: Omit<ArkosRouteConfig<TQuery, TBody, TParams>, \"path\">,\n ...handlers: Array<\n | ArkosErrorRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n Locals\n >\n | Array<\n ArkosErrorRequestHandler<\n InferValidationType<TParams, Record<string, string>>,\n any,\n InferValidationType<TBody, any>,\n InferValidationType<TQuery, qs.ParsedQs>,\n Locals\n >\n >\n >\n ): T;\n};\n\n/**\n * Handler function for `use` that accepts route configuration and middleware handlers.\n *\n * @param {ArkosUseConfig} config - The use configuration object or path.\n * @param {...ArkosAnyRequestHandler} handlers - Middleware handlers.\n * @returns {T} The router instance.\n */\n\nexport type UseMethodHandler<T> = IRouterHandler<T> &\n IRouterMatcher<T> & {\n (\n config: ArkosUseConfig,\n ...handlers: Array<ArkosRequestHandler | Array<ArkosRequestHandler>>\n ): T;\n (\n config: ArkosUseConfig,\n ...handlers: Array<\n ArkosErrorRequestHandler | Array<ArkosErrorRequestHandler>\n >\n ): T;\n (...handlers: Array<ArkosRequestHandler | Array<ArkosRequestHandler>>): T;\n };\n\nexport interface IArkosRoute extends IRoute {\n /** GET method handler with route configuration support */\n get: ArkosRouteMethodHandler<this>;\n /** POST method handler with route configuration support */\n post: ArkosRouteMethodHandler<this>;\n /** PUT method handler with route configuration support */\n put: ArkosRouteMethodHandler<this>;\n /** PATCH method handler with route configuration support */\n patch: ArkosRouteMethodHandler<this>;\n /** DELETE method handler with route configuration support */\n delete: ArkosRouteMethodHandler<this>;\n /** OPTIONS method handler with route configuration support */\n options: ArkosRouteMethodHandler<this>;\n /** HEAD method handler with route configuration support */\n head: ArkosRouteMethodHandler<this>;\n // /** TRACE method handler with route configuration support */\n trace: ArkosRouteMethodHandler<this>;\n /** ALL methods handler with route configuration support */\n all: ArkosRouteMethodHandler<this>;\n}\n\n/**\n * Creates an enhanced Express Router with features like OpenAPI documentation capabilities and smart data validation.\n *\n * The ArkosRouter extends the standard Express Router with the ability to\n * automatically capture OpenAPI metadata from route configurations.\n *\n * @example\n * const router = ArkosRouter();\n *\n * router.get(\n * {\n * path: \"/users/:id\",\n * openapi: {\n * summary: \"Get user by ID\",\n * tags: [\"Users\"]\n * }\n * },\n * (req, res) => { ... }\n * );\n *\n * @returns {IArkosRouter} A proxied Express Router instance with enhanced OpenAPI capabilities\n *\n * @see {@link ArkosRouteConfig} for configuration options\n */\nexport interface IArkosRouter extends IRouter {\n /** GET method handler with route configuration support */\n get: RouterMethodHandler<this>;\n /** POST method handler with route configuration support */\n post: RouterMethodHandler<this>;\n /** PUT method handler with route configuration support */\n put: RouterMethodHandler<this>;\n /** PATCH method handler with route configuration support */\n patch: RouterMethodHandler<this>;\n /** DELETE method handler with route configuration support */\n delete: RouterMethodHandler<this>;\n /** OPTIONS method handler with route configuration support */\n options: RouterMethodHandler<this>;\n /** HEAD method handler with route configuration support */\n head: RouterMethodHandler<this>;\n // /** TRACE method handler with route configuration support */\n trace: RouterMethodHandler<this>;\n /** ALL methods handler with route configuration support */\n all: RouterMethodHandler<this>;\n use: UseMethodHandler<this>;\n\n route<T extends string>(prefix: T): IArkosRoute;\n route(prefix: PathParams): IArkosRoute;\n}\n\n/**\n * Configuration object for defining routes in Arkos.js.\n */\nexport type ArkosRouteConfig<\n TQuery extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | false\n | null\n | undefined = any,\n TBody extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | false\n | null\n | undefined = any,\n TParams extends\n | ZodSchema\n | (new (...args: any[]) => object)\n | null\n | false\n | null\n | undefined = any,\n> = {\n /**\n * Disables the route by not mounting it internally.\n */\n disabled?: boolean;\n /**\n * The URL path pattern for the route.\n *\n * @example \"/api/users/:id\"\n */\n path: PathParams;\n /**\n * Authentication and authorization configuration.\n *\n * @remarks\n * - Set to `true` to require authentication without specific permissions.\n * - Set to `false` or omit to allow unauthenticated access.\n * - Provide an object to specify resource-based access control with resource name, action, and optional custom rules.\n */\n authentication?:\n | boolean\n | {\n resource: string;\n action: string;\n rule?: DetailedAccessControlRule | string[] | \"*\";\n };\n /**\n * Request validation configuration using Zod schemas or class constructors.\n *\n * @remarks\n * - Set to `false` to disable all validation.\n * - Set to `null` to forbidden all request inputs.\n * - Provide an object with `query`, `body`, and/or `params` properties to validate specific parts of the request.\n * - Each property accepts a Zod schema, a class constructor, or `false` to disable validation for that part.\n */\n validation?:\n | false\n | null\n | {\n query?: TQuery;\n body?: TBody;\n params?: TParams;\n };\n /**\n * Rate limiting configuration for this route.\n *\n * @see {@link https://www.npmjs.com/package/express-rate-limit express-rate-limit} for available options.\n */\n rateLimit?: Partial<RateLimitOptions>;\n\n /**\n * Allows to define options for npm package compression.\n * Nothing is passed by default.\n *\n * @see {@link https://www.npmjs.com/package/compression compression} for further details.\n */\n compression?: compression.CompressionOptions;\n /**\n * Options to define how query must be parsed.\n *\n * @example\n * ```\n * GET /api/product?saleId=null\n * ```\n *\n * Normally would parsed to { saleId: \"null\" } so query parser\n * trough setting option `parseNull` will transform { saleId: null }\n *\n * @default\n * ```\n * {\n * parseNull: true,\n * parseUndefined: true,\n * parseBoolean: true,\n * }\n * ```\n *\n * @remarks\n * parseNumber may convert fields that are string but you only passed\n * numbers to query pay attention to this.\n *\n * Soon a feature to converted the query to the end prisma type will be added.\n */\n queryParser?: QueryParserOptions;\n /**\n * Configuration for request body parsing.\n *\n * @property {(\"json\" | \"urlencoded\" | \"raw\" | \"text\")} parser - The type of body parser to use.\n * @property {object} [options] - Parser-specific options passed to the corresponding Express body parser middleware.\n *\n * @remarks\n * - When `parser` is `\"json\"`, options are passed to `express.json()`.\n * - When `parser` is `\"urlencoded\"`, options are passed to `express.urlencoded()`.\n * - When `parser` is `\"raw\"`, options are passed to `express.raw()`.\n * - When `parser` is `\"text\"`, options are passed to `express.text()`.\n * - Set to `false` to disable body parsing for this route.\n *\n * @see {@link https://expressjs.com/en/api.html#express.json Express body parser documentation}\n */\n bodyParser?: BodyParserConfig | BodyParserConfig[] | false;\n /**\n * Experimental features to be battled tested before being stable\n *\n * PS: These features may be changed without any previous warning.\n */\n experimental?: {\n /**\n * OpenAPI specification for this route.\n *\n * @remarks\n * - Set to `false` to exclude this route from OpenAPI documentation.\n * - Provide a partial OpenAPI operation object to document the route.\n */\n openapi?: false | OpenApiConfig;\n /**\n * Configuration for file upload handling in routes.\n * Supports single file, multiple files from same field, or multiple fields with files.\n */\n uploads?: UploadConfig;\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-config.js","sourceRoot":"","sources":["../../../../../src/utils/arkos-router/types/upload-config.ts"],"names":[],"mappings":"","sourcesContent":["export type UploadConfig =\n /**\n * Creates middleware that processes a single file associated with the\n * given form field.\n *\n * The `Request` object will be populated with a `file` object containing\n * information about the processed file.\n *\n * @example\n * uploads: {\n * type: \"single\",\n * field: \"avatar\",\n * uploadDir: \"images\",\n * maxSize: 1024 * 1024 * 5 // 5MB\n * }\n */\n | ({\n type: \"single\";\n /** Name of the multipart form field to process */\n field: string;\n } & ArkosRouterBaseUploadConfig)\n /**\n * Returns middleware that processes multiple files sharing the same field\n * name.\n *\n * The `Request` object will be populated with a `files` array containing\n * an information object for each processed file.\n *\n * @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName`\n *\n * @example\n * uploads: {\n * type: \"array\",\n * field: \"gallery\",\n * maxCount: 10,\n * minCount: 1,\n * uploadDir: \"images\"\n * }\n */\n | ({\n type: \"array\";\n /** Shared name of the multipart form fields to process */\n field: string;\n /** Maximum number of files to process (defaults to framework config) */\n maxCount?: number;\n /** Minimum number of files required */\n
|
|
1
|
+
{"version":3,"file":"upload-config.js","sourceRoot":"","sources":["../../../../../src/utils/arkos-router/types/upload-config.ts"],"names":[],"mappings":"","sourcesContent":["export type UploadConfig =\n /**\n * Creates middleware that processes a single file associated with the\n * given form field.\n *\n * The `Request` object will be populated with a `file` object containing\n * information about the processed file.\n *\n * @example\n * uploads: {\n * type: \"single\",\n * field: \"avatar\",\n * uploadDir: \"images\",\n * maxSize: 1024 * 1024 * 5 // 5MB\n * }\n */\n | ({\n type: \"single\";\n /** Name of the multipart form field to process. Supports bracket notation, including nested array paths (e.g. \"banners[][image]\") */\n field: string;\n } & ArkosRouterBaseUploadConfig)\n /**\n * Returns middleware that processes multiple files sharing the same field\n * name.\n *\n * The `Request` object will be populated with a `files` array containing\n * an information object for each processed file.\n *\n * @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName`\n *\n * @example\n * uploads: {\n * type: \"array\",\n * field: \"gallery\",\n * maxCount: 10,\n * minCount: 1,\n * uploadDir: \"images\"\n * }\n */\n | ({\n type: \"array\";\n /** Shared name of the multipart form fields to process. Supports bracket notation, including nested array paths (e.g. \"banners[][images]\") */\n field: string;\n /** Maximum number of files to process (defaults to framework config) */\n maxCount?: number;\n /** Minimum number of files required */\n minCount?: number;\n } & ArkosRouterBaseUploadConfig)\n /**\n * Creates middleware that processes multiple files associated with the\n * given form fields.\n *\n * The `Request` object will be populated with a `files` object which\n * maps each field name to an array of the associated file information\n * objects.\n *\n * Each field entry is a full single or array upload config with a `name`\n * property. Field names support bracket notation, including nested array\n * paths (e.g. \"banners[][images]\").\n *\n * @example\n * uploads: {\n * type: \"fields\",\n * fields: [\n * { name: \"avatar\", type: \"single\", uploadDir: \"images\" },\n * { name: \"resume\", type: \"single\", uploadDir: \"documents\" },\n * { name: \"banners[][images]\", type: \"array\", maxCount: 5, uploadDir: \"banners\" }\n * ]\n * }\n */\n | ({\n type: \"fields\";\n /** Array of field configurations describing multipart form fields to process */\n fields: UploadConfigFieldEntry[];\n } & Pick<ArkosRouterBaseUploadConfig, \"deleteOnError\">)\n | ({\n type: \"fields\";\n /** Array of field configurations describing multipart form fields to process */\n fields: {\n /** Name of the form field */\n name: string;\n /** Maximum number of files for this field (defaults to framework config) */\n maxCount?: number;\n // /** Minimum number of files required for this field */\n minCount?: number;\n }[];\n } & ArkosRouterBaseUploadConfig);\n\n/**\n * A single field entry inside a `fields` upload config.\n * Each entry is a full single or array upload config with an additional\n * `name` property identifying the form field.\n *\n * Field names support bracket notation, including nested array paths\n * (e.g. \"banners[][images]\"). For nested array paths, multer validation\n * is bypassed and constraints (allowedFileTypes, maxSize, minCount, maxCount)\n * are enforced per group after upload.\n */\nexport type UploadConfigFieldEntry =\n /**\n * A single-file field entry.\n *\n * @example\n * { name: \"avatar\", type: \"single\", uploadDir: \"images\", required: true }\n *\n * @example\n * // nested array path — one image per banner\n * { name: \"banners[][image]\", type: \"single\", uploadDir: \"banners\" }\n */\n | ({\n /** Name of the form field. Supports bracket notation including nested array paths. */\n name: string;\n type: \"single\";\n } & Omit<ArkosRouterBaseUploadConfig, \"deleteOnError\">)\n /**\n * A multi-file field entry.\n *\n * @example\n * { name: \"gallery\", type: \"array\", maxCount: 6, uploadDir: \"gallery\" }\n *\n * @example\n * // nested array path — multiple images per banner, min 1 max 5\n * { name: \"banners[][images]\", type: \"array\", minCount: 1, maxCount: 5, uploadDir: \"banners\" }\n */\n | ({\n /** Name of the form field. Supports bracket notation including nested array paths. */\n name: string;\n type?: \"array\";\n /** Maximum number of files for this field (defaults to framework config) */\n maxCount?: number;\n /** Minimum number of files required for this field */\n minCount?: number;\n } & Omit<ArkosRouterBaseUploadConfig, \"deleteOnError\">); /**\n\n/**\n * Base configuration options for file uploads.\n * These settings can override framework-level defaults for specific routes.\n */\nexport type ArkosRouterBaseUploadConfig = {\n /**\n * Directory category where files will be stored.\n * Each category has its own default restrictions defined in framework config.\n *\n * @remarks Do not include the `baseUploadDir` defined under your arkos config\n * @default Depends on the file type which is descovered by the file mimetype, otherwise falls to files.\n */\n uploadDir?: string;\n /**\n * Whether to automatically delete uploaded files if an error occurs during request processing.\n * Cleanup happens when errors are thrown and not caught within the route handler.\n *\n * @default false\n */\n deleteOnError?: boolean;\n /**\n * How to attach file information to req.body for easier access in handlers and validation.\n * - \"pathname\": Just the relative path (e.g., \"images/avatar-123.jpg\")\n * - \"url\": Complete URL (e.g., \"https://api.com/uploads/images/avatar-123.jpg\")\n * - \"file\": The complete Multer file object with all metadata\n *\n * @default \"pathname\"\n *\n * @remarks\n * When using validation, the attached format will be available in your validated body.\n * For array/fields uploads, an array of the specified format will be attached.\n */\n attachToBody?: \"pathname\" | \"url\" | \"file\" | false;\n /**\n * Maximum file size in bytes.\n * Overrides the framework-level default for this uploadDir category.\n *\n * @example\n * maxSize: 1024 * 1024 * 5 // 5MB\n * maxSize: 1024 * 1024 * 50 // 50MB\n */\n maxSize?: number;\n /**\n * Allowed file types/extensions.\n * Can be an array of extensions/MIME types or a RegExp pattern.\n * Overrides the framework-level default for this uploadDir category.\n *\n * @example\n * // Array of extensions\n * allowedFileTypes: [\".jpg\", \".png\", \".gif\"]\n *\n * @example\n * // Array of MIME types\n * allowedFileTypes: [\"image/jpeg\", \"image/png\"]\n *\n * @example\n * // RegExp pattern\n * allowedFileTypes: /jpeg|jpg|png|gif/\n */\n allowedFileTypes?: string[] | RegExp;\n /**\n * Defines if this file field is required\n *\n * @default true\n */\n required?: boolean;\n /**\n * Open API field description\n */\n description?: string;\n};\n"]}
|