adorn-api 1.0.22 → 1.0.24
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/.eslintignore +3 -0
- package/.eslintrc.cjs +30 -0
- package/README.md +375 -531
- package/dist/core/express-adapter.d.ts +27 -0
- package/dist/core/express-adapter.d.ts.map +1 -0
- package/dist/core/express-adapter.js +146 -0
- package/dist/core/express-adapter.js.map +1 -0
- package/dist/core/http-error.d.ts +7 -0
- package/dist/core/http-error.d.ts.map +1 -0
- package/dist/core/http-error.js +14 -0
- package/dist/core/http-error.js.map +1 -0
- package/dist/decorators/controller.decorator.d.ts +2 -0
- package/dist/decorators/controller.decorator.d.ts.map +1 -0
- package/dist/decorators/controller.decorator.js +26 -0
- package/dist/decorators/controller.decorator.js.map +1 -0
- package/dist/decorators/create.decorator.d.ts +8 -0
- package/dist/decorators/create.decorator.d.ts.map +1 -0
- package/dist/decorators/create.decorator.js +67 -0
- package/dist/decorators/create.decorator.js.map +1 -0
- package/dist/decorators/http-method.decorator.d.ts +16 -0
- package/dist/decorators/http-method.decorator.d.ts.map +1 -0
- package/dist/decorators/http-method.decorator.js +117 -0
- package/dist/decorators/http-method.decorator.js.map +1 -0
- package/dist/decorators/http-params.d.ts +17 -0
- package/dist/decorators/http-params.d.ts.map +1 -0
- package/dist/decorators/http-params.js +26 -0
- package/dist/decorators/http-params.js.map +1 -0
- package/dist/decorators/index.d.ts +10 -5
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +14 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/list.decorator.d.ts +18 -0
- package/dist/decorators/list.decorator.d.ts.map +1 -0
- package/dist/decorators/list.decorator.js +99 -0
- package/dist/decorators/list.decorator.js.map +1 -0
- package/dist/decorators/middleware.decorator.d.ts +4 -0
- package/dist/decorators/middleware.decorator.d.ts.map +1 -0
- package/dist/decorators/middleware.decorator.js +34 -0
- package/dist/decorators/middleware.decorator.js.map +1 -0
- package/dist/decorators/response.decorator.d.ts +8 -0
- package/dist/decorators/response.decorator.d.ts.map +1 -0
- package/dist/decorators/response.decorator.js +44 -0
- package/dist/decorators/response.decorator.js.map +1 -0
- package/dist/decorators/route-options.d.ts +14 -0
- package/dist/decorators/route-options.d.ts.map +1 -0
- package/dist/decorators/route-options.js +22 -0
- package/dist/decorators/route-options.js.map +1 -0
- package/dist/decorators/schema.decorator.d.ts +82 -0
- package/dist/decorators/schema.decorator.d.ts.map +1 -0
- package/dist/decorators/schema.decorator.js +123 -0
- package/dist/decorators/schema.decorator.js.map +1 -0
- package/dist/decorators/update.decorator.d.ts +8 -0
- package/dist/decorators/update.decorator.d.ts.map +1 -0
- package/dist/decorators/update.decorator.js +63 -0
- package/dist/decorators/update.decorator.js.map +1 -0
- package/dist/index.d.ts +11 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -637
- package/dist/index.js.map +1 -1
- package/dist/metadata/metadata-storage.d.ts +38 -0
- package/dist/metadata/metadata-storage.d.ts.map +1 -0
- package/dist/metadata/metadata-storage.js +102 -0
- package/dist/metadata/metadata-storage.js.map +1 -0
- package/dist/metal-orm-integration/dto-helper.d.ts +5 -0
- package/dist/metal-orm-integration/dto-helper.d.ts.map +1 -0
- package/dist/metal-orm-integration/dto-helper.js +48 -0
- package/dist/metal-orm-integration/dto-helper.js.map +1 -0
- package/dist/metal-orm-integration/dto-response.decorator.d.ts +4 -0
- package/dist/metal-orm-integration/dto-response.decorator.d.ts.map +1 -0
- package/dist/metal-orm-integration/dto-response.decorator.js +69 -0
- package/dist/metal-orm-integration/dto-response.decorator.js.map +1 -0
- package/dist/metal-orm-integration/entity-schema-builder.d.ts +20 -0
- package/dist/metal-orm-integration/entity-schema-builder.d.ts.map +1 -0
- package/dist/metal-orm-integration/entity-schema-builder.js +356 -0
- package/dist/metal-orm-integration/entity-schema-builder.js.map +1 -0
- package/dist/metal-orm-integration/index.d.ts +5 -0
- package/dist/metal-orm-integration/index.d.ts.map +1 -0
- package/dist/metal-orm-integration/index.js +5 -0
- package/dist/metal-orm-integration/index.js.map +1 -0
- package/dist/metal-orm-integration/schema-modifier.d.ts +11 -0
- package/dist/metal-orm-integration/schema-modifier.d.ts.map +1 -0
- package/dist/metal-orm-integration/schema-modifier.js +62 -0
- package/dist/metal-orm-integration/schema-modifier.js.map +1 -0
- package/dist/openapi/index.d.ts +4 -0
- package/dist/openapi/index.d.ts.map +1 -0
- package/dist/openapi/index.js +4 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi/openapi-generator.d.ts +22 -0
- package/dist/openapi/openapi-generator.d.ts.map +1 -0
- package/dist/openapi/openapi-generator.js +428 -0
- package/dist/openapi/openapi-generator.js.map +1 -0
- package/dist/openapi/swagger-ui.d.ts +11 -0
- package/dist/openapi/swagger-ui.d.ts.map +1 -0
- package/dist/openapi/swagger-ui.js +20 -0
- package/dist/openapi/swagger-ui.js.map +1 -0
- package/dist/openapi/zod-to-openapi.d.ts +4 -0
- package/dist/openapi/zod-to-openapi.d.ts.map +1 -0
- package/dist/openapi/zod-to-openapi.js +184 -0
- package/dist/openapi/zod-to-openapi.js.map +1 -0
- package/dist/types/common.d.ts +4 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +2 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/controller.d.ts +14 -0
- package/dist/types/controller.d.ts.map +1 -0
- package/dist/types/controller.js +2 -0
- package/dist/types/controller.js.map +1 -0
- package/dist/types/metadata.d.ts +48 -0
- package/dist/types/metadata.d.ts.map +1 -0
- package/dist/types/metadata.js +2 -0
- package/dist/types/metadata.js.map +1 -0
- package/dist/types/openapi.d.ts +30 -0
- package/dist/types/openapi.d.ts.map +1 -0
- package/dist/types/openapi.js +2 -0
- package/dist/types/openapi.js.map +1 -0
- package/dist/validation/zod-adapter.d.ts +15 -0
- package/dist/validation/zod-adapter.d.ts.map +1 -0
- package/dist/validation/zod-adapter.js +61 -0
- package/dist/validation/zod-adapter.js.map +1 -0
- package/examples/basic/app.ts +15 -0
- package/examples/basic/index.ts +6 -0
- package/examples/basic/user.controller.ts +35 -0
- package/examples/basic/user.dtos.ts +23 -0
- package/examples/metal-orm-sqlite/app.ts +18 -0
- package/examples/metal-orm-sqlite/db.ts +90 -0
- package/examples/metal-orm-sqlite/index.ts +6 -0
- package/examples/metal-orm-sqlite/post.controller.ts +209 -0
- package/examples/metal-orm-sqlite/post.dtos.ts +78 -0
- package/examples/metal-orm-sqlite/post.entity.ts +24 -0
- package/examples/metal-orm-sqlite/user.controller.helpers.ts +305 -0
- package/examples/metal-orm-sqlite/user.controller.ts +231 -0
- package/examples/metal-orm-sqlite/user.dtos.ts +88 -0
- package/examples/metal-orm-sqlite/user.entity.ts +21 -0
- package/examples/metal-orm-sqlite-music/album.controller.ts +278 -0
- package/examples/metal-orm-sqlite-music/album.dtos.ts +85 -0
- package/examples/metal-orm-sqlite-music/album.entity.ts +28 -0
- package/examples/metal-orm-sqlite-music/app.ts +19 -0
- package/examples/metal-orm-sqlite-music/artist.controller.ts +272 -0
- package/examples/metal-orm-sqlite-music/artist.dtos.ts +68 -0
- package/examples/metal-orm-sqlite-music/artist.entity.ts +27 -0
- package/examples/metal-orm-sqlite-music/db.ts +148 -0
- package/examples/metal-orm-sqlite-music/index.ts +6 -0
- package/examples/metal-orm-sqlite-music/track.controller.ts +221 -0
- package/examples/metal-orm-sqlite-music/track.dtos.ts +82 -0
- package/examples/metal-orm-sqlite-music/track.entity.ts +27 -0
- package/examples/openapi/health.controller.ts +11 -0
- package/examples/openapi/health.dto.ts +7 -0
- package/examples/openapi/index.ts +12 -0
- package/examples/restful/app.ts +15 -0
- package/examples/restful/index.ts +9 -0
- package/examples/restful/task.controller.ts +118 -0
- package/examples/restful/task.dtos.ts +66 -0
- package/examples/restful/task.store.ts +95 -0
- package/examples/tsconfig.json +8 -0
- package/examples/utils/start-server.ts +56 -0
- package/package.json +33 -97
- package/scripts/run-example.js +29 -0
- package/src/adapter/express.ts +589 -0
- package/src/adapter/metal-orm/convention-overrides.ts +115 -0
- package/src/adapter/metal-orm/crud-dtos.ts +141 -0
- package/src/adapter/metal-orm/dto.ts +20 -0
- package/src/adapter/metal-orm/error-dtos.ts +51 -0
- package/src/adapter/metal-orm/field-builder.ts +185 -0
- package/src/adapter/metal-orm/filters.ts +52 -0
- package/src/adapter/metal-orm/index.ts +66 -0
- package/src/adapter/metal-orm/paged-dtos.ts +94 -0
- package/src/adapter/metal-orm/pagination.ts +28 -0
- package/src/adapter/metal-orm/types.ts +250 -0
- package/src/adapter/metal-orm/utils.ts +36 -0
- package/src/adapter/metal-orm.test.ts +439 -0
- package/src/core/__tests__/coerce.test.ts +39 -0
- package/src/core/__tests__/dto-compose.test.ts +68 -0
- package/src/core/__tests__/schema-builder.test.ts +82 -0
- package/src/core/coerce.ts +190 -0
- package/src/core/decorators.ts +645 -0
- package/src/core/errors.ts +55 -0
- package/src/core/metadata.ts +110 -0
- package/src/core/openapi.ts +282 -0
- package/src/core/schema-builder.ts +287 -0
- package/src/core/schema.ts +400 -0
- package/src/core/types.ts +14 -0
- package/src/e2e/http-error.e2e.test.ts +52 -0
- package/src/e2e/sqlite-metal-orm.e2e.test.ts +174 -0
- package/src/e2e/sqlite.e2e.test.ts +126 -0
- package/src/index.ts +8 -0
- package/tsconfig.eslint.json +7 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +8 -0
- package/dist/adapter/express/auth.d.ts +0 -13
- package/dist/adapter/express/auth.d.ts.map +0 -1
- package/dist/adapter/express/bootstrap.d.ts +0 -40
- package/dist/adapter/express/bootstrap.d.ts.map +0 -1
- package/dist/adapter/express/coercion.d.ts +0 -102
- package/dist/adapter/express/coercion.d.ts.map +0 -1
- package/dist/adapter/express/index.d.ts +0 -6
- package/dist/adapter/express/index.d.ts.map +0 -1
- package/dist/adapter/express/merge.d.ts +0 -45
- package/dist/adapter/express/merge.d.ts.map +0 -1
- package/dist/adapter/express/openapi.d.ts +0 -66
- package/dist/adapter/express/openapi.d.ts.map +0 -1
- package/dist/adapter/express/router.d.ts +0 -10
- package/dist/adapter/express/router.d.ts.map +0 -1
- package/dist/adapter/express/swagger.d.ts +0 -18
- package/dist/adapter/express/swagger.d.ts.map +0 -1
- package/dist/adapter/express/types.d.ts +0 -110
- package/dist/adapter/express/types.d.ts.map +0 -1
- package/dist/adapter/express/validation.d.ts +0 -27
- package/dist/adapter/express/validation.d.ts.map +0 -1
- package/dist/cli/progress.d.ts +0 -122
- package/dist/cli/progress.d.ts.map +0 -1
- package/dist/cli.cjs +0 -4390
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -4371
- package/dist/cli.js.map +0 -1
- package/dist/compiler/analyze/index.d.ts +0 -5
- package/dist/compiler/analyze/index.d.ts.map +0 -1
- package/dist/compiler/analyze/scanControllers.d.ts +0 -88
- package/dist/compiler/analyze/scanControllers.d.ts.map +0 -1
- package/dist/compiler/cache/isStale.d.ts +0 -46
- package/dist/compiler/cache/isStale.d.ts.map +0 -1
- package/dist/compiler/cache/loadArtifacts.d.ts +0 -149
- package/dist/compiler/cache/loadArtifacts.d.ts.map +0 -1
- package/dist/compiler/cache/schema.d.ts +0 -32
- package/dist/compiler/cache/schema.d.ts.map +0 -1
- package/dist/compiler/cache/writeCache.d.ts +0 -14
- package/dist/compiler/cache/writeCache.d.ts.map +0 -1
- package/dist/compiler/gems.d.ts +0 -75
- package/dist/compiler/gems.d.ts.map +0 -1
- package/dist/compiler/generator/index.d.ts +0 -7
- package/dist/compiler/generator/index.d.ts.map +0 -1
- package/dist/compiler/generator/manifest.d.ts +0 -23
- package/dist/compiler/generator/manifest.d.ts.map +0 -1
- package/dist/compiler/generator/openapi.d.ts +0 -118
- package/dist/compiler/generator/openapi.d.ts.map +0 -1
- package/dist/compiler/graph/builder.d.ts +0 -24
- package/dist/compiler/graph/builder.d.ts.map +0 -1
- package/dist/compiler/graph/index.d.ts +0 -7
- package/dist/compiler/graph/index.d.ts.map +0 -1
- package/dist/compiler/graph/schemaGraph.d.ts +0 -67
- package/dist/compiler/graph/schemaGraph.d.ts.map +0 -1
- package/dist/compiler/graph/types.d.ts +0 -203
- package/dist/compiler/graph/types.d.ts.map +0 -1
- package/dist/compiler/index.d.ts +0 -12
- package/dist/compiler/index.d.ts.map +0 -1
- package/dist/compiler/ir/index.d.ts +0 -7
- package/dist/compiler/ir/index.d.ts.map +0 -1
- package/dist/compiler/ir/pipeline.d.ts +0 -82
- package/dist/compiler/ir/pipeline.d.ts.map +0 -1
- package/dist/compiler/ir/stages.d.ts +0 -40
- package/dist/compiler/ir/stages.d.ts.map +0 -1
- package/dist/compiler/ir/visitor.d.ts +0 -98
- package/dist/compiler/ir/visitor.d.ts.map +0 -1
- package/dist/compiler/manifest/emit.d.ts +0 -21
- package/dist/compiler/manifest/emit.d.ts.map +0 -1
- package/dist/compiler/manifest/format.d.ts +0 -119
- package/dist/compiler/manifest/format.d.ts.map +0 -1
- package/dist/compiler/manifest/index.d.ts +0 -6
- package/dist/compiler/manifest/index.d.ts.map +0 -1
- package/dist/compiler/runner/createProgram.d.ts +0 -24
- package/dist/compiler/runner/createProgram.d.ts.map +0 -1
- package/dist/compiler/runner/index.d.ts +0 -5
- package/dist/compiler/runner/index.d.ts.map +0 -1
- package/dist/compiler/schema/extractAnnotations.d.ts +0 -57
- package/dist/compiler/schema/extractAnnotations.d.ts.map +0 -1
- package/dist/compiler/schema/index.d.ts +0 -8
- package/dist/compiler/schema/index.d.ts.map +0 -1
- package/dist/compiler/schema/intersectionHandler.d.ts +0 -44
- package/dist/compiler/schema/intersectionHandler.d.ts.map +0 -1
- package/dist/compiler/schema/objectHandler.d.ts +0 -146
- package/dist/compiler/schema/objectHandler.d.ts.map +0 -1
- package/dist/compiler/schema/openapi.d.ts +0 -71
- package/dist/compiler/schema/openapi.d.ts.map +0 -1
- package/dist/compiler/schema/parameters.d.ts +0 -90
- package/dist/compiler/schema/parameters.d.ts.map +0 -1
- package/dist/compiler/schema/partitioner.d.ts +0 -85
- package/dist/compiler/schema/partitioner.d.ts.map +0 -1
- package/dist/compiler/schema/primitives.d.ts +0 -68
- package/dist/compiler/schema/primitives.d.ts.map +0 -1
- package/dist/compiler/schema/queryBuilderAnalyzer.d.ts +0 -76
- package/dist/compiler/schema/queryBuilderAnalyzer.d.ts.map +0 -1
- package/dist/compiler/schema/queryBuilderSchemaBuilder.d.ts +0 -13
- package/dist/compiler/schema/queryBuilderSchemaBuilder.d.ts.map +0 -1
- package/dist/compiler/schema/splitOpenapi.d.ts +0 -46
- package/dist/compiler/schema/splitOpenapi.d.ts.map +0 -1
- package/dist/compiler/schema/typeToJsonSchema.d.ts +0 -26
- package/dist/compiler/schema/typeToJsonSchema.d.ts.map +0 -1
- package/dist/compiler/schema/types.d.ts +0 -70
- package/dist/compiler/schema/types.d.ts.map +0 -1
- package/dist/compiler/schema/unionHandler.d.ts +0 -70
- package/dist/compiler/schema/unionHandler.d.ts.map +0 -1
- package/dist/compiler/transform/dedup.d.ts +0 -35
- package/dist/compiler/transform/dedup.d.ts.map +0 -1
- package/dist/compiler/transform/flatten.d.ts +0 -50
- package/dist/compiler/transform/flatten.d.ts.map +0 -1
- package/dist/compiler/transform/index.d.ts +0 -7
- package/dist/compiler/transform/index.d.ts.map +0 -1
- package/dist/compiler/transform/inline.d.ts +0 -46
- package/dist/compiler/transform/inline.d.ts.map +0 -1
- package/dist/compiler/validation/emitPrecompiledValidators.d.ts +0 -62
- package/dist/compiler/validation/emitPrecompiledValidators.d.ts.map +0 -1
- package/dist/compiler/validation/index.d.ts +0 -5
- package/dist/compiler/validation/index.d.ts.map +0 -1
- package/dist/decorators/Auth.d.ts +0 -22
- package/dist/decorators/Auth.d.ts.map +0 -1
- package/dist/decorators/Controller.d.ts +0 -17
- package/dist/decorators/Controller.d.ts.map +0 -1
- package/dist/decorators/Public.d.ts +0 -15
- package/dist/decorators/Public.d.ts.map +0 -1
- package/dist/decorators/Use.d.ts +0 -23
- package/dist/decorators/Use.d.ts.map +0 -1
- package/dist/decorators/methods.d.ts +0 -26
- package/dist/decorators/methods.d.ts.map +0 -1
- package/dist/express.cjs +0 -1186
- package/dist/express.cjs.map +0 -1
- package/dist/express.d.ts +0 -8
- package/dist/express.d.ts.map +0 -1
- package/dist/express.js +0 -1150
- package/dist/express.js.map +0 -1
- package/dist/http.d.ts +0 -33
- package/dist/http.d.ts.map +0 -1
- package/dist/index.cjs +0 -724
- package/dist/index.cjs.map +0 -1
- package/dist/metal/applyListQuery.d.ts +0 -100
- package/dist/metal/applyListQuery.d.ts.map +0 -1
- package/dist/metal/index.cjs +0 -278
- package/dist/metal/index.cjs.map +0 -1
- package/dist/metal/index.d.ts +0 -15
- package/dist/metal/index.d.ts.map +0 -1
- package/dist/metal/index.js +0 -243
- package/dist/metal/index.js.map +0 -1
- package/dist/metal/listQuery.d.ts +0 -26
- package/dist/metal/listQuery.d.ts.map +0 -1
- package/dist/metal/queryOptions.d.ts +0 -16
- package/dist/metal/queryOptions.d.ts.map +0 -1
- package/dist/metal/readMetalBag.d.ts +0 -69
- package/dist/metal/readMetalBag.d.ts.map +0 -1
- package/dist/metal/registerMetalEntities.d.ts +0 -26
- package/dist/metal/registerMetalEntities.d.ts.map +0 -1
- package/dist/metal/schemaFromEntity.d.ts +0 -41
- package/dist/metal/schemaFromEntity.d.ts.map +0 -1
- package/dist/metal/searchWhere.d.ts +0 -97
- package/dist/metal/searchWhere.d.ts.map +0 -1
- package/dist/metal/symbolMetadata.d.ts +0 -8
- package/dist/metal/symbolMetadata.d.ts.map +0 -1
- package/dist/runtime/auth/runtime.d.ts +0 -183
- package/dist/runtime/auth/runtime.d.ts.map +0 -1
- package/dist/runtime/metadata/bucket.d.ts +0 -2
- package/dist/runtime/metadata/bucket.d.ts.map +0 -1
- package/dist/runtime/metadata/key.d.ts +0 -2
- package/dist/runtime/metadata/key.d.ts.map +0 -1
- package/dist/runtime/metadata/read.d.ts +0 -2
- package/dist/runtime/metadata/read.d.ts.map +0 -1
- package/dist/runtime/metadata/types.d.ts +0 -95
- package/dist/runtime/metadata/types.d.ts.map +0 -1
- package/dist/runtime/polyfill.d.ts +0 -2
- package/dist/runtime/polyfill.d.ts.map +0 -1
- package/dist/runtime/upload.d.ts +0 -44
- package/dist/runtime/upload.d.ts.map +0 -1
- package/dist/runtime/validation/ajv.d.ts +0 -120
- package/dist/runtime/validation/ajv.d.ts.map +0 -1
- package/dist/runtime/validation/index.d.ts +0 -11
- package/dist/runtime/validation/index.d.ts.map +0 -1
- package/dist/schema/decorators.d.ts +0 -37
- package/dist/schema/decorators.d.ts.map +0 -1
- package/dist/schema/index.cjs +0 -214
- package/dist/schema/index.cjs.map +0 -1
- package/dist/schema/index.d.ts +0 -2
- package/dist/schema/index.d.ts.map +0 -1
- package/dist/schema/index.js +0 -163
- package/dist/schema/index.js.map +0 -1
- package/dist/scripts/adorn-example.cjs +0 -404
- package/dist/scripts/adorn-example.cjs.map +0 -1
- package/dist/utils/operationId.d.ts +0 -2
- package/dist/utils/operationId.d.ts.map +0 -1
- package/dist/utils/path.d.ts +0 -2
- package/dist/utils/path.d.ts.map +0 -1
- package/dist/utils/port.d.ts +0 -9
- package/dist/utils/port.d.ts.map +0 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
export function zodToOpenApi(schema) {
|
|
2
|
+
return convertZodType(schema);
|
|
3
|
+
}
|
|
4
|
+
function convertZodType(schema) {
|
|
5
|
+
if (!schema || !schema._def) {
|
|
6
|
+
return { type: "object" };
|
|
7
|
+
}
|
|
8
|
+
const def = schema._def;
|
|
9
|
+
const typeName = def.typeName;
|
|
10
|
+
switch (typeName) {
|
|
11
|
+
case "ZodString":
|
|
12
|
+
return convertZodString(def);
|
|
13
|
+
case "ZodNumber":
|
|
14
|
+
return convertZodNumber(def);
|
|
15
|
+
case "ZodBoolean":
|
|
16
|
+
return { type: "boolean" };
|
|
17
|
+
case "ZodArray":
|
|
18
|
+
return {
|
|
19
|
+
type: "array",
|
|
20
|
+
items: convertZodType(def.type),
|
|
21
|
+
};
|
|
22
|
+
case "ZodObject":
|
|
23
|
+
return convertZodObject(schema);
|
|
24
|
+
case "ZodOptional":
|
|
25
|
+
return convertZodType(def.innerType);
|
|
26
|
+
case "ZodNullable":
|
|
27
|
+
const inner = convertZodType(def.innerType);
|
|
28
|
+
if (inner?.type) {
|
|
29
|
+
const types = Array.isArray(inner.type) ? inner.type : [inner.type];
|
|
30
|
+
return { ...inner, type: [...new Set([...types, "null"])] };
|
|
31
|
+
}
|
|
32
|
+
return { anyOf: [inner, { type: "null" }] };
|
|
33
|
+
case "ZodDefault":
|
|
34
|
+
const defaultSchema = convertZodType(def.innerType);
|
|
35
|
+
defaultSchema.default = def.defaultValue();
|
|
36
|
+
return defaultSchema;
|
|
37
|
+
case "ZodEnum":
|
|
38
|
+
return {
|
|
39
|
+
type: "string",
|
|
40
|
+
enum: def.values,
|
|
41
|
+
};
|
|
42
|
+
case "ZodLiteral":
|
|
43
|
+
return {
|
|
44
|
+
type: typeof def.value,
|
|
45
|
+
enum: [def.value],
|
|
46
|
+
};
|
|
47
|
+
case "ZodUnion":
|
|
48
|
+
return {
|
|
49
|
+
oneOf: def.options.map((opt) => convertZodType(opt)),
|
|
50
|
+
};
|
|
51
|
+
case "ZodEffects":
|
|
52
|
+
return convertZodType(def.schema);
|
|
53
|
+
case "ZodDate":
|
|
54
|
+
return { type: "string", format: "date-time" };
|
|
55
|
+
case "ZodAny":
|
|
56
|
+
return {};
|
|
57
|
+
case "ZodRecord":
|
|
58
|
+
return {
|
|
59
|
+
type: "object",
|
|
60
|
+
additionalProperties: convertZodType(def.valueType),
|
|
61
|
+
};
|
|
62
|
+
case "ZodTuple":
|
|
63
|
+
return {
|
|
64
|
+
type: "array",
|
|
65
|
+
items: def.items.map((item) => convertZodType(item)),
|
|
66
|
+
minItems: def.items.length,
|
|
67
|
+
maxItems: def.items.length,
|
|
68
|
+
};
|
|
69
|
+
default:
|
|
70
|
+
return { type: "object" };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function convertZodString(def) {
|
|
74
|
+
const result = { type: "string" };
|
|
75
|
+
if (def.checks) {
|
|
76
|
+
for (const check of def.checks) {
|
|
77
|
+
switch (check.kind) {
|
|
78
|
+
case "email":
|
|
79
|
+
result.format = "email";
|
|
80
|
+
break;
|
|
81
|
+
case "url":
|
|
82
|
+
result.format = "uri";
|
|
83
|
+
break;
|
|
84
|
+
case "uuid":
|
|
85
|
+
result.format = "uuid";
|
|
86
|
+
break;
|
|
87
|
+
case "datetime":
|
|
88
|
+
result.format = "date-time";
|
|
89
|
+
break;
|
|
90
|
+
case "min":
|
|
91
|
+
result.minLength = check.value;
|
|
92
|
+
break;
|
|
93
|
+
case "max":
|
|
94
|
+
result.maxLength = check.value;
|
|
95
|
+
break;
|
|
96
|
+
case "regex":
|
|
97
|
+
result.pattern = check.regex.source;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
function convertZodNumber(def) {
|
|
105
|
+
const result = { type: "number" };
|
|
106
|
+
if (!def.checks) {
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
const hasInt = def.checks.some((c) => c.kind === "int");
|
|
110
|
+
const hasPositive = def.checks.some((c) => c.kind === "positive");
|
|
111
|
+
const hasNegative = def.checks.some((c) => c.kind === "negative");
|
|
112
|
+
const hasMin = def.checks.some((c) => c.kind === "min");
|
|
113
|
+
const hasMax = def.checks.some((c) => c.kind === "max");
|
|
114
|
+
if (hasInt) {
|
|
115
|
+
result.type = "integer";
|
|
116
|
+
}
|
|
117
|
+
if (hasPositive) {
|
|
118
|
+
result.exclusiveMinimum = 0;
|
|
119
|
+
if (hasInt) {
|
|
120
|
+
result.type = "integer";
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
if (hasNegative) {
|
|
125
|
+
result.exclusiveMaximum = 0;
|
|
126
|
+
if (hasInt) {
|
|
127
|
+
result.type = "integer";
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
if (hasMin) {
|
|
132
|
+
const minCheck = def.checks.find((c) => c.kind === "min");
|
|
133
|
+
if (minCheck && !minCheck.inclusive) {
|
|
134
|
+
result.exclusiveMinimum = minCheck.value;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
result.minimum = minCheck.value;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (hasMax) {
|
|
141
|
+
const maxCheck = def.checks.find((c) => c.kind === "max");
|
|
142
|
+
if (maxCheck && !maxCheck.inclusive) {
|
|
143
|
+
result.exclusiveMaximum = maxCheck.value;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
result.maximum = maxCheck.value;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
function convertZodObject(schema) {
|
|
152
|
+
const shape = schema.shape;
|
|
153
|
+
const properties = {};
|
|
154
|
+
const required = [];
|
|
155
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
156
|
+
const zodValue = value;
|
|
157
|
+
properties[key] = convertZodType(zodValue);
|
|
158
|
+
if (!isOptional(zodValue)) {
|
|
159
|
+
required.push(key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const result = {
|
|
163
|
+
type: "object",
|
|
164
|
+
properties,
|
|
165
|
+
};
|
|
166
|
+
if (required.length > 0) {
|
|
167
|
+
result.required = required;
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
export function isOptional(schema) {
|
|
172
|
+
if (!schema || !schema._def)
|
|
173
|
+
return false;
|
|
174
|
+
const def = schema._def;
|
|
175
|
+
const typeName = def.typeName;
|
|
176
|
+
if (typeName === "ZodOptional")
|
|
177
|
+
return true;
|
|
178
|
+
if (typeName === "ZodDefault")
|
|
179
|
+
return true;
|
|
180
|
+
if (typeName === "ZodNullable")
|
|
181
|
+
return isOptional(def.innerType);
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=zod-to-openapi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-to-openapi.js","sourceRoot":"","sources":["../../src/openapi/zod-to-openapi.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,YAAY,CAAC,MAAsB;IACjD,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,cAAc,CAAC,MAAsB;IAC5C,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC5B,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,IAAW,CAAC;IAC/B,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAkB,CAAC;IAExC,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,WAAW;YACd,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAE/B,KAAK,WAAW;YACd,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAE/B,KAAK,YAAY;YACf,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAE7B,KAAK,UAAU;YACb,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC;aAChC,CAAC;QAEJ,KAAK,WAAW;YACd,OAAO,gBAAgB,CAAC,MAA0B,CAAC,CAAC;QAEtD,KAAK,aAAa;YAChB,OAAO,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEvC,KAAK,aAAa;YAChB,MAAM,KAAK,GAAG,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAC5C,IAAI,KAAK,EAAE,IAAI,EAAE,CAAC;gBAChB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC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|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
export interface ControllerClass {
|
|
3
|
+
new (...args: any[]): any;
|
|
4
|
+
}
|
|
5
|
+
export interface RouteHandler {
|
|
6
|
+
(...args: any[]): any;
|
|
7
|
+
}
|
|
8
|
+
export interface MiddlewareFunction {
|
|
9
|
+
(req: Request, res: Response, next: NextFunction): void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface GuardFunction {
|
|
12
|
+
(req: Request, res: Response, next: NextFunction): boolean | Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/types/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzE;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/types/controller.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface ControllerMetadata {
|
|
2
|
+
path: string;
|
|
3
|
+
middlewares: Function[];
|
|
4
|
+
guards: Function[];
|
|
5
|
+
}
|
|
6
|
+
export interface RouteMetadata {
|
|
7
|
+
path: string;
|
|
8
|
+
method: HttpMethod;
|
|
9
|
+
handlerName: string;
|
|
10
|
+
summary?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
tags?: string[];
|
|
13
|
+
middlewares: Function[];
|
|
14
|
+
guards: Function[];
|
|
15
|
+
parameters: ParameterMetadata[];
|
|
16
|
+
response?: ResponseMetadata;
|
|
17
|
+
schemas?: SchemaConfig;
|
|
18
|
+
entity?: any;
|
|
19
|
+
schema?: any;
|
|
20
|
+
isArray?: boolean;
|
|
21
|
+
includeRelations?: string[];
|
|
22
|
+
relationsDepth?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ParameterMetadata {
|
|
25
|
+
name: string;
|
|
26
|
+
type: "query" | "body" | "params" | "combined";
|
|
27
|
+
index: number;
|
|
28
|
+
schema?: any;
|
|
29
|
+
required?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ResponseMetadata {
|
|
32
|
+
status: number;
|
|
33
|
+
description?: string;
|
|
34
|
+
schema?: any;
|
|
35
|
+
isArray?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
38
|
+
export interface SchemaConfig {
|
|
39
|
+
params?: any;
|
|
40
|
+
body?: any;
|
|
41
|
+
query?: any;
|
|
42
|
+
}
|
|
43
|
+
export interface ValidatedInput<P = unknown, B = unknown, Q = unknown> {
|
|
44
|
+
params: P;
|
|
45
|
+
body: B;
|
|
46
|
+
query: Q;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1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AAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO;IACnE,MAAM,EAAE,CAAC,CAAC;IACV,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,CAAC,CAAC;CACV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/types/metadata.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
export interface OpenApiOptions {
|
|
3
|
+
info: {
|
|
4
|
+
title: string;
|
|
5
|
+
version: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
};
|
|
8
|
+
servers?: Array<{
|
|
9
|
+
url: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
}>;
|
|
12
|
+
tags?: Array<{
|
|
13
|
+
name: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
}>;
|
|
16
|
+
components?: OpenAPIV3_1.ComponentsObject;
|
|
17
|
+
}
|
|
18
|
+
export type OpenApiSpec = {
|
|
19
|
+
openapi: '3.1.0';
|
|
20
|
+
info: {
|
|
21
|
+
title: string;
|
|
22
|
+
version: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
};
|
|
25
|
+
paths?: Record<string, OpenAPIV3_1.PathItemObject>;
|
|
26
|
+
components?: OpenAPIV3_1.ComponentsObject;
|
|
27
|
+
tags?: OpenAPIV3_1.TagObject[];
|
|
28
|
+
servers?: OpenAPIV3_1.ServerObject[];
|
|
29
|
+
} & Omit<OpenAPIV3_1.Document, 'openapi' | 'info' | 'paths' | 'components' | 'tags' | 'servers'>;
|
|
30
|
+
//# sourceMappingURL=openapi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/types/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,CAAC;IACH,IAAI,CAAC,EAAE,KAAK,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,CAAC;IACH,UAAU,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC;CAC3C;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;IACnD,UAAU,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC;IAC1C,IAAI,CAAC,EAAE,WAAW,CAAC,SAAS,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,WAAW,CAAC,YAAY,EAAE,CAAC;CACtC,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../../src/types/openapi.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
3
|
+
/**
|
|
4
|
+
* Format Zod errors into readable strings
|
|
5
|
+
*/
|
|
6
|
+
export declare function formatZodErrors(error: z.ZodError): string[];
|
|
7
|
+
/**
|
|
8
|
+
* Create an Express middleware that validates a specific request property using Zod
|
|
9
|
+
*/
|
|
10
|
+
export declare function createZodValidationMiddleware(source: 'params' | 'body' | 'query', schema: z.ZodType<any>): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Type helper for inferring schema types
|
|
13
|
+
*/
|
|
14
|
+
export type InferSchema<T> = T extends z.ZodType<infer U> ? U : never;
|
|
15
|
+
//# sourceMappingURL=zod-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-adapter.d.ts","sourceRoot":"","sources":["../../src/validation/zod-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE/D;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,GAAG,MAAM,EAAE,CAK3D;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CACzC,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,EACnC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAER,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,mBAiBhE;AAuCD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format Zod errors into readable strings
|
|
3
|
+
*/
|
|
4
|
+
export function formatZodErrors(error) {
|
|
5
|
+
return error.errors.map((err) => {
|
|
6
|
+
const path = err.path.join('.');
|
|
7
|
+
return path ? `${path}: ${err.message}` : err.message;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create an Express middleware that validates a specific request property using Zod
|
|
12
|
+
*/
|
|
13
|
+
export function createZodValidationMiddleware(source, schema) {
|
|
14
|
+
return async (req, res, next) => {
|
|
15
|
+
const data = getRequestData(req, source);
|
|
16
|
+
const result = await schema.safeParseAsync(data);
|
|
17
|
+
if (!result.success) {
|
|
18
|
+
res.status(400).json({
|
|
19
|
+
error: 'Validation failed',
|
|
20
|
+
source,
|
|
21
|
+
errors: formatZodErrors(result.error),
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Replace with validated/transformed data
|
|
26
|
+
setRequestData(req, source, result.data);
|
|
27
|
+
return next();
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get data from request based on source
|
|
32
|
+
*/
|
|
33
|
+
function getRequestData(req, source) {
|
|
34
|
+
switch (source) {
|
|
35
|
+
case 'params':
|
|
36
|
+
return req.params;
|
|
37
|
+
case 'body':
|
|
38
|
+
return req.body;
|
|
39
|
+
case 'query':
|
|
40
|
+
return req.query;
|
|
41
|
+
default:
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Set validated data back to request
|
|
47
|
+
*/
|
|
48
|
+
function setRequestData(req, source, data) {
|
|
49
|
+
switch (source) {
|
|
50
|
+
case 'params':
|
|
51
|
+
req.params = data;
|
|
52
|
+
break;
|
|
53
|
+
case 'body':
|
|
54
|
+
req.body = data;
|
|
55
|
+
break;
|
|
56
|
+
case 'query':
|
|
57
|
+
req.query = data;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=zod-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-adapter.js","sourceRoot":"","sources":["../../src/validation/zod-adapter.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC7C,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAC5B,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1D,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B,CACzC,MAAmC,EACnC,MAAsB;IAEtB,OAAO,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAC7D,MAAM,IAAI,GAAG,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAEjD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAClB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACjB,KAAK,EAAE,mBAAmB;gBAC1B,MAAM;gBACN,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC;aACxC,CAAC,CAAC;YACH,OAAO;QACX,CAAC;QAED,0CAA0C;QAC1C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,IAAI,EAAE,CAAC;IAClB,CAAC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,GAAY,EAAE,MAAmC;IACrE,QAAQ,MAAM,EAAE,CAAC;QACb,KAAK,QAAQ;YACT,OAAO,GAAG,CAAC,MAAM,CAAC;QACtB,KAAK,MAAM;YACP,OAAO,GAAG,CAAC,IAAI,CAAC;QACpB,KAAK,OAAO;YACR,OAAO,GAAG,CAAC,KAAK,CAAC;QACrB;YACI,OAAO,SAAS,CAAC;IACzB,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CACnB,GAAY,EACZ,MAAmC,EACnC,IAAS;IAET,QAAQ,MAAM,EAAE,CAAC;QACb,KAAK,QAAQ;YACT,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC;YAClB,MAAM;QACV,KAAK,MAAM;YACP,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;YAChB,MAAM;QACV,KAAK,OAAO;YACP,GAAW,CAAC,KAAK,GAAG,IAAI,CAAC;YAC1B,MAAM;IACd,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createExpressApp } from "../../src";
|
|
2
|
+
import { UserController } from "./user.controller";
|
|
3
|
+
|
|
4
|
+
export function createApp() {
|
|
5
|
+
return createExpressApp({
|
|
6
|
+
controllers: [UserController],
|
|
7
|
+
openApi: {
|
|
8
|
+
info: {
|
|
9
|
+
title: "Adorn API",
|
|
10
|
+
version: "1.0.0"
|
|
11
|
+
},
|
|
12
|
+
docs: true
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Body,
|
|
3
|
+
Controller,
|
|
4
|
+
Get,
|
|
5
|
+
Params,
|
|
6
|
+
Post,
|
|
7
|
+
Returns,
|
|
8
|
+
type RequestContext
|
|
9
|
+
} from "../../src";
|
|
10
|
+
import { CreateUserDto, UserDto, UserParamsDto } from "./user.dtos";
|
|
11
|
+
|
|
12
|
+
@Controller("/users")
|
|
13
|
+
export class UserController {
|
|
14
|
+
@Get("/:id")
|
|
15
|
+
@Params(UserParamsDto)
|
|
16
|
+
@Returns(UserDto)
|
|
17
|
+
async getOne(ctx: RequestContext<unknown, undefined, { id: string }>) {
|
|
18
|
+
return {
|
|
19
|
+
id: ctx.params.id,
|
|
20
|
+
name: "Ada Lovelace",
|
|
21
|
+
nickname: "Ada"
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Post("/")
|
|
26
|
+
@Body(CreateUserDto)
|
|
27
|
+
@Returns({ status: 201, schema: UserDto, description: "Created" })
|
|
28
|
+
async create(ctx: RequestContext<CreateUserDto>) {
|
|
29
|
+
return {
|
|
30
|
+
id: "3f0f4d0f-1cb1-4cf1-9c32-3d4bce1b3f36",
|
|
31
|
+
name: ctx.body.name,
|
|
32
|
+
nickname: ctx.body.nickname
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Dto, Field, OmitDto, PickDto, t } from "../../src";
|
|
2
|
+
|
|
3
|
+
@Dto({ description: "User record returned by the API." })
|
|
4
|
+
export class UserDto {
|
|
5
|
+
@Field(t.uuid({ description: "User identifier." }))
|
|
6
|
+
id!: string;
|
|
7
|
+
|
|
8
|
+
@Field(t.string({ minLength: 1 }))
|
|
9
|
+
name!: string;
|
|
10
|
+
|
|
11
|
+
@Field(t.optional(t.string()))
|
|
12
|
+
nickname?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CreateUserDto extends Omit<UserDto, "id"> {}
|
|
16
|
+
|
|
17
|
+
@OmitDto(UserDto, ["id"])
|
|
18
|
+
export class CreateUserDto {}
|
|
19
|
+
|
|
20
|
+
export interface UserParamsDto extends Pick<UserDto, "id"> {}
|
|
21
|
+
|
|
22
|
+
@PickDto(UserDto, ["id"])
|
|
23
|
+
export class UserParamsDto {}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createExpressApp } from "../../src";
|
|
2
|
+
import { initializeDatabase } from "./db";
|
|
3
|
+
import { PostController } from "./post.controller";
|
|
4
|
+
import { UserController } from "./user.controller";
|
|
5
|
+
import { startExampleServer } from "../utils/start-server";
|
|
6
|
+
|
|
7
|
+
export async function start() {
|
|
8
|
+
await initializeDatabase();
|
|
9
|
+
|
|
10
|
+
const app = createExpressApp({
|
|
11
|
+
controllers: [UserController, PostController],
|
|
12
|
+
openApi: {
|
|
13
|
+
info: { title: "SQLite + MetalORM REST example", version: "1.0.0" },
|
|
14
|
+
docs: true
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
startExampleServer(app, { name: "SQLite + MetalORM REST example" });
|
|
18
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import sqlite3 from "sqlite3";
|
|
2
|
+
import {
|
|
3
|
+
Orm,
|
|
4
|
+
SqliteDialect,
|
|
5
|
+
createSqliteExecutor,
|
|
6
|
+
type SqliteClientLike
|
|
7
|
+
} from "metal-orm";
|
|
8
|
+
|
|
9
|
+
let db: sqlite3.Database | null = null;
|
|
10
|
+
let orm: Orm | null = null;
|
|
11
|
+
|
|
12
|
+
function execSql(database: sqlite3.Database, sql: string): Promise<void> {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
database.exec(sql, (err) => {
|
|
15
|
+
if (err) {
|
|
16
|
+
reject(err);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
resolve();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function createSqliteClient(database: sqlite3.Database): SqliteClientLike {
|
|
25
|
+
return {
|
|
26
|
+
all(sql, params = []) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
database.all(sql, params, (err, rows) => {
|
|
29
|
+
if (err) {
|
|
30
|
+
reject(err);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
resolve(rows as Record<string, unknown>[]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
beginTransaction() {
|
|
38
|
+
return execSql(database, "BEGIN");
|
|
39
|
+
},
|
|
40
|
+
commitTransaction() {
|
|
41
|
+
return execSql(database, "COMMIT");
|
|
42
|
+
},
|
|
43
|
+
rollbackTransaction() {
|
|
44
|
+
return execSql(database, "ROLLBACK");
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function initializeDatabase() {
|
|
50
|
+
db = new sqlite3.Database(":memory:");
|
|
51
|
+
await execSql(db, "pragma foreign_keys = ON");
|
|
52
|
+
await execSql(
|
|
53
|
+
db,
|
|
54
|
+
"create table users (id integer primary key autoincrement, name text not null, email text, createdAt text not null)"
|
|
55
|
+
);
|
|
56
|
+
await execSql(
|
|
57
|
+
db,
|
|
58
|
+
"create table posts (id integer primary key autoincrement, title text not null, body text, userId integer not null, createdAt text not null, foreign key(userId) references users(id))"
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
await execSql(db, `
|
|
62
|
+
INSERT INTO users (name, email, createdAt) VALUES
|
|
63
|
+
('Alice', 'alice@example.com', '2026-01-17T00:00:00.000Z'),
|
|
64
|
+
('Bob', 'bob@example.com', '2026-01-17T00:00:00.000Z')
|
|
65
|
+
`);
|
|
66
|
+
|
|
67
|
+
await execSql(db, `
|
|
68
|
+
INSERT INTO posts (title, body, userId, createdAt) VALUES
|
|
69
|
+
('First Post', 'This is the first post content', 1, '2026-01-17T00:00:00.000Z'),
|
|
70
|
+
('Second Post', 'Another post here', 2, '2026-01-17T00:00:00.000Z'),
|
|
71
|
+
('Third Post', 'Yet another post', 1, '2026-01-17T00:00:00.000Z')
|
|
72
|
+
`);
|
|
73
|
+
|
|
74
|
+
const executor = createSqliteExecutor(createSqliteClient(db));
|
|
75
|
+
orm = new Orm({
|
|
76
|
+
dialect: new SqliteDialect(),
|
|
77
|
+
executorFactory: {
|
|
78
|
+
createExecutor: () => executor,
|
|
79
|
+
createTransactionalExecutor: () => executor,
|
|
80
|
+
dispose: async () => {}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function createSession() {
|
|
86
|
+
if (!orm) {
|
|
87
|
+
throw new Error("ORM not initialized");
|
|
88
|
+
}
|
|
89
|
+
return orm.createSession();
|
|
90
|
+
}
|