raiton 1.0.0 → 3.0.0
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/CHANGELOG.md +39 -0
- package/README.md +97 -1
- package/build/bin/index.mjs +7012 -47
- package/deno.json +9 -0
- package/package.json +22 -43
- package/scripts/update-version.ts +97 -0
- package/source/bin/bootstrapper.ts +15 -0
- package/source/bin/cli-tools.ts +68 -0
- package/source/bin/cli.ts +12 -0
- package/source/bin/constants.ts +5 -0
- package/source/bin/index.ts +6 -0
- package/source/commands/artifact.command.ts +28 -0
- package/source/commands/build.command.ts +31 -0
- package/source/commands/develop.command.ts +47 -0
- package/source/commands/grafts.command.ts +27 -0
- package/source/commands/start.command.ts +28 -0
- package/source/core/application.ts +163 -0
- package/source/core/builder.ts +144 -0
- package/source/core/bytes.util.ts +17 -0
- package/source/core/command.ts +24 -0
- package/source/core/commands.ts +44 -0
- package/source/core/config/config.ts +51 -0
- package/source/core/config/define.ts +13 -0
- package/source/core/config/index.ts +2 -0
- package/source/core/context.ts +33 -0
- package/source/core/controller/builder.ts +41 -0
- package/source/core/controller/compiler.ts +22 -0
- package/source/core/controller/index.ts +3 -0
- package/source/core/controller/metadata.ts +13 -0
- package/source/core/directories.ts +30 -0
- package/source/core/helpers/index.ts +1 -0
- package/source/core/helpers/raiton.ts +3 -0
- package/source/core/hooks.ts +28 -0
- package/source/core/index.ts +14 -0
- package/source/core/injection/index.ts +1 -0
- package/source/core/injection/injection.ts +219 -0
- package/source/core/middleware/compose.ts +40 -0
- package/source/core/middleware/index.ts +2 -0
- package/source/core/middleware/pipeline.ts +27 -0
- package/source/core/plugins/index.ts +2 -0
- package/source/core/plugins/plugin.ts +8 -0
- package/source/core/plugins/scope.ts +46 -0
- package/source/core/process.util.ts +12 -0
- package/source/core/raiton.ts +20 -0
- package/source/core/router/handler.ts +115 -0
- package/source/core/router/index.ts +4 -0
- package/source/core/router/matcher.ts +51 -0
- package/source/core/router/route.ts +63 -0
- package/source/core/router/router.ts +31 -0
- package/source/core/server.ts +26 -0
- package/source/core/thread.ts +112 -0
- package/source/env.d.ts +3 -0
- package/source/requirements.ts +27 -0
- package/source/sdk/artifacts.ts +79 -0
- package/source/sdk/constants/decorators.constant.ts +8 -0
- package/source/sdk/constants/index.ts +2 -0
- package/source/sdk/constants/microservices.constant.ts +4 -0
- package/source/sdk/controllers.ts +4 -0
- package/source/sdk/data-transfer-object.ts +15 -0
- package/source/sdk/decorators/access-guard.decorator.ts +9 -0
- package/source/sdk/decorators/controllable.decorator.ts +20 -0
- package/source/sdk/decorators/index.ts +5 -0
- package/source/sdk/decorators/injection.decorator.ts +46 -0
- package/source/sdk/decorators/middleware.decorator.ts +15 -0
- package/source/sdk/decorators/parametrable.ts +28 -0
- package/source/sdk/decorators/routable.decorator.ts +45 -0
- package/source/sdk/encryption.ts +157 -0
- package/source/sdk/enums/encrypted.enum.ts +23 -0
- package/source/sdk/enums/event.message.enum.ts +4 -0
- package/source/sdk/enums/http-method.enum.ts +10 -0
- package/{build/sdk/enums/http-parameters.enum.d.ts → source/sdk/enums/http-parameters.enum.ts} +3 -5
- package/source/sdk/enums/http-status.enum.ts +73 -0
- package/source/sdk/enums/index.ts +7 -0
- package/{build/sdk/enums/runtime.enum.d.ts → source/sdk/enums/runtime.enum.ts} +2 -4
- package/{build/sdk/enums/timestamp.enum.d.ts → source/sdk/enums/timestamp.enum.ts} +2 -4
- package/source/sdk/env.ts +40 -0
- package/source/sdk/exceptions/http-exception.ts +28 -0
- package/source/sdk/exceptions/index.ts +2 -0
- package/{build/sdk/throwable.d.ts → source/sdk/exceptions/throwable.ts} +35 -12
- package/source/sdk/index.ts +14 -0
- package/source/sdk/parameter-bag.ts +55 -0
- package/source/sdk/plugins/body-parser.plugin.ts +160 -0
- package/source/sdk/plugins/index.ts +2 -0
- package/source/sdk/plugins/security/body-limit.ts +19 -0
- package/source/sdk/plugins/security/cors.ts +44 -0
- package/source/sdk/plugins/security/headers.ts +14 -0
- package/source/sdk/plugins/security/index.ts +13 -0
- package/source/sdk/plugins/security/method-guard.ts +14 -0
- package/source/sdk/plugins/security/rate-limit.ts +42 -0
- package/source/sdk/repositories.ts +14 -0
- package/source/sdk/responses/error.ts +52 -0
- package/source/sdk/responses/helpers.ts +28 -0
- package/source/sdk/responses/http-throwable.ts +28 -0
- package/source/sdk/responses/http.ts +48 -0
- package/source/sdk/responses/index.ts +4 -0
- package/source/sdk/runtime/bun/server.ts +73 -0
- package/source/sdk/runtime/deno/server.ts +53 -0
- package/source/sdk/runtime/index.ts +47 -0
- package/source/sdk/runtime/node/server.ts +60 -0
- package/source/sdk/runtime/web/server.ts +57 -0
- package/source/sdk/services.ts +9 -0
- package/source/sdk/utilities/alias-path.util.ts +49 -0
- package/source/sdk/utilities/artifact.util.ts +18 -0
- package/source/sdk/utilities/callable.util.ts +27 -0
- package/source/sdk/utilities/index.ts +5 -0
- package/source/sdk/utilities/json.util.ts +21 -0
- package/source/sdk/utilities/path.util.ts +19 -0
- package/source/sdk/utilities/url.ts +5 -0
- package/source/sdk/utilities/utilities.util.ts +25 -0
- package/source/types/access-guards.ts +4 -0
- package/{build/types/application.d.ts → source/types/application.ts} +23 -7
- package/source/types/artifact.ts +44 -0
- package/source/types/builder.ts +44 -0
- package/source/types/config.ts +7 -0
- package/source/types/controller.ts +33 -0
- package/source/types/contruct.ts +3 -0
- package/source/types/core.ts +28 -0
- package/{build/types/directory.d.ts → source/types/directory.ts} +4 -4
- package/source/types/encryption.ts +17 -0
- package/source/types/generic.ts +3 -0
- package/source/types/http-responses.ts +8 -0
- package/source/types/index.ts +25 -0
- package/source/types/injection.ts +13 -0
- package/source/types/lifecycle.ts +11 -0
- package/source/types/middleware.ts +18 -0
- package/source/types/parseable.ts +7 -0
- package/source/types/plugin.ts +10 -0
- package/source/types/raiton.ts +7 -0
- package/source/types/responses.ts +20 -0
- package/source/types/router.ts +11 -0
- package/source/types/runtime.ts +56 -0
- package/{build/types/scheme.d.ts → source/types/scheme.ts} +33 -8
- package/source/types/server.ts +12 -0
- package/source/types/thread.ts +31 -0
- package/source/types/utilities.ts +4 -0
- package/source/types/values.ts +3 -0
- package/.releaserc.json +0 -39
- package/build/bin/bootstrapper.d.ts +0 -5
- package/build/bin/bootstrapper.mjs +0 -46
- package/build/bin/cli.d.ts +0 -5
- package/build/bin/cli.mjs +0 -6
- package/build/bin/index.d.ts +0 -1
- package/build/chunk-3PWMRP6G.mjs +0 -16
- package/build/chunk-52JR26TI.mjs +0 -29
- package/build/chunk-5LNOA4SK.mjs +0 -16
- package/build/chunk-AUGL35CF.mjs +0 -24
- package/build/chunk-BEV2YOPG.mjs +0 -14
- package/build/chunk-BYYJRCB4.mjs +0 -10
- package/build/chunk-FFRJ4AUA.mjs +0 -16
- package/build/chunk-GPJSLV3Q.mjs +0 -50
- package/build/chunk-HVFHDVAH.mjs +0 -20
- package/build/chunk-IOCHNQMF.mjs +0 -13
- package/build/chunk-JATYBWHL.mjs +0 -36
- package/build/chunk-JWNBO7XV.mjs +0 -53
- package/build/chunk-K4IQQ2KF.mjs +0 -55
- package/build/chunk-K4KLOLSO.mjs +0 -645
- package/build/chunk-M2RZZJQR.mjs +0 -27
- package/build/chunk-MLFGBJDV.mjs +0 -12
- package/build/chunk-NB62GSFI.mjs +0 -27
- package/build/chunk-O7R3NJQN.mjs +0 -19
- package/build/chunk-P3IRIFPT.mjs +0 -53
- package/build/chunk-QFSXFOEN.mjs +0 -56
- package/build/chunk-QHCQ4AUA.mjs +0 -14
- package/build/chunk-QI7OFSXB.mjs +0 -37
- package/build/chunk-RVH2YBNU.mjs +0 -111
- package/build/chunk-RXG7754R.mjs +0 -25
- package/build/chunk-S3ONGVNZ.mjs +0 -11
- package/build/chunk-SRR4467I.mjs +0 -29
- package/build/chunk-T6L55AUG.mjs +0 -32
- package/build/chunk-TOJFTPAY.mjs +0 -83
- package/build/chunk-UAPCBU3J.mjs +0 -12
- package/build/chunk-UCHBN3DV.mjs +0 -52
- package/build/chunk-UWM46HLZ.mjs +0 -18
- package/build/chunk-UZFCGVHP.mjs +0 -8
- package/build/chunk-VQINCGLQ.mjs +0 -59
- package/build/chunk-VRL4S7UF.mjs +0 -74
- package/build/chunk-WAWFDMOH.mjs +0 -72
- package/build/chunk-X3JFRRRQ.mjs +0 -45
- package/build/chunk-XFBLELHI.mjs +0 -34
- package/build/chunk-XIGE72LC.mjs +0 -34
- package/build/chunk-XW7EPAD7.mjs +0 -0
- package/build/chunk-YGIZFKLJ.mjs +0 -20
- package/build/chunk-YRVIAORI.mjs +0 -8
- package/build/chunk-YXU5W2CB.mjs +0 -12
- package/build/commands/artifact.command.d.ts +0 -14
- package/build/commands/artifact.command.mjs +0 -59
- package/build/commands/build.command.d.ts +0 -14
- package/build/commands/build.command.mjs +0 -65
- package/build/commands/develop.command.d.ts +0 -13
- package/build/commands/develop.command.mjs +0 -75
- package/build/commands/grafts.command.d.ts +0 -12
- package/build/commands/grafts.command.mjs +0 -58
- package/build/commands/start.command.d.ts +0 -12
- package/build/commands/start.command.mjs +0 -64
- package/build/core/application.d.ts +0 -27
- package/build/core/application.mjs +0 -124
- package/build/core/artifact.d.ts +0 -19
- package/build/core/artifact.mjs +0 -133
- package/build/core/builder.d.ts +0 -35
- package/build/core/builder.mjs +0 -45
- package/build/core/bytes.util.d.ts +0 -6
- package/build/core/bytes.util.mjs +0 -8
- package/build/core/command.d.ts +0 -15
- package/build/core/command.mjs +0 -6
- package/build/core/commands.d.ts +0 -13
- package/build/core/commands.mjs +0 -7
- package/build/core/config.d.ts +0 -10
- package/build/core/config.mjs +0 -7
- package/build/core/context.d.ts +0 -15
- package/build/core/context.mjs +0 -6
- package/build/core/controller/builder.d.ts +0 -10
- package/build/core/controller/builder.mjs +0 -45
- package/build/core/controller/compiler.d.ts +0 -6
- package/build/core/controller/compiler.mjs +0 -45
- package/build/core/controller/index.d.ts +0 -13
- package/build/core/controller/index.mjs +0 -50
- package/build/core/controller/metadata.d.ts +0 -10
- package/build/core/controller/metadata.mjs +0 -6
- package/build/core/directories.d.ts +0 -11
- package/build/core/directories.mjs +0 -8
- package/build/core/hmr.d.ts +0 -22
- package/build/core/hmr.mjs +0 -6
- package/build/core/hooks.d.ts +0 -12
- package/build/core/hooks.mjs +0 -6
- package/build/core/index.d.ts +0 -41
- package/build/core/index.mjs +0 -100
- package/build/core/middleware/compose.d.ts +0 -8
- package/build/core/middleware/compose.mjs +0 -6
- package/build/core/middleware/index.d.ts +0 -6
- package/build/core/middleware/index.mjs +0 -11
- package/build/core/middleware/pipeline.d.ts +0 -14
- package/build/core/middleware/pipeline.mjs +0 -7
- package/build/core/plugins/index.d.ts +0 -14
- package/build/core/plugins/index.mjs +0 -48
- package/build/core/plugins/plugin.d.ts +0 -17
- package/build/core/plugins/plugin.mjs +0 -6
- package/build/core/plugins/scope.d.ts +0 -24
- package/build/core/plugins/scope.mjs +0 -45
- package/build/core/process.util.d.ts +0 -3
- package/build/core/process.util.mjs +0 -6
- package/build/core/raiton.d.ts +0 -20
- package/build/core/raiton.mjs +0 -6
- package/build/core/router/handler.d.ts +0 -10
- package/build/core/router/handler.mjs +0 -45
- package/build/core/router/index.d.ts +0 -12
- package/build/core/router/index.mjs +0 -54
- package/build/core/router/matcher.d.ts +0 -21
- package/build/core/router/matcher.mjs +0 -6
- package/build/core/router/route.d.ts +0 -20
- package/build/core/router/route.mjs +0 -6
- package/build/core/router/router.d.ts +0 -16
- package/build/core/router/router.mjs +0 -8
- package/build/core/thread.d.ts +0 -30
- package/build/core/thread.mjs +0 -45
- package/build/env.d.d.ts +0 -2
- package/build/env.d.mjs +0 -0
- package/build/raiton-1.0.0.tgz +0 -0
- package/build/requirements.d.ts +0 -2
- package/build/requirements.mjs +0 -19
- package/build/sdk/artifacts.d.ts +0 -13
- package/build/sdk/artifacts.mjs +0 -45
- package/build/sdk/constants/decorators.constant.d.ts +0 -11
- package/build/sdk/constants/decorators.constant.mjs +0 -6
- package/build/sdk/constants/index.d.ts +0 -2
- package/build/sdk/constants/index.mjs +0 -11
- package/build/sdk/constants/microservices.constant.d.ts +0 -5
- package/build/sdk/constants/microservices.constant.mjs +0 -6
- package/build/sdk/controllers.d.ts +0 -4
- package/build/sdk/controllers.mjs +0 -6
- package/build/sdk/data-transfer-object.d.ts +0 -7
- package/build/sdk/data-transfer-object.mjs +0 -7
- package/build/sdk/decorators/access-guard.decorator.d.ts +0 -2
- package/build/sdk/decorators/access-guard.decorator.mjs +0 -0
- package/build/sdk/decorators/controllable.d.ts +0 -3
- package/build/sdk/decorators/controllable.mjs +0 -45
- package/build/sdk/decorators/controllers.decorator.d.ts +0 -2
- package/build/sdk/decorators/controllers.decorator.mjs +0 -0
- package/build/sdk/decorators/grafts.decorator.d.ts +0 -2
- package/build/sdk/decorators/grafts.decorator.mjs +0 -0
- package/build/sdk/decorators/index.d.ts +0 -3
- package/build/sdk/decorators/index.mjs +0 -75
- package/build/sdk/decorators/parameters.decorator.d.ts +0 -2
- package/build/sdk/decorators/parameters.decorator.mjs +0 -0
- package/build/sdk/decorators/parametrable.d.ts +0 -9
- package/build/sdk/decorators/parametrable.mjs +0 -57
- package/build/sdk/decorators/payload.decorator.d.ts +0 -2
- package/build/sdk/decorators/payload.decorator.mjs +0 -0
- package/build/sdk/decorators/routable.d.ts +0 -10
- package/build/sdk/decorators/routable.mjs +0 -59
- package/build/sdk/dependency-container.d.ts +0 -19
- package/build/sdk/dependency-container.mjs +0 -46
- package/build/sdk/encryption.d.ts +0 -27
- package/build/sdk/encryption.mjs +0 -141
- package/build/sdk/enums/encrypted.enum.d.ts +0 -15
- package/build/sdk/enums/encrypted.enum.mjs +0 -6
- package/build/sdk/enums/event.message.enum.d.ts +0 -6
- package/build/sdk/enums/event.message.enum.mjs +0 -6
- package/build/sdk/enums/http-parameters.enum.mjs +0 -6
- package/build/sdk/enums/http.enum.d.ts +0 -12
- package/build/sdk/enums/http.enum.mjs +0 -6
- package/build/sdk/enums/index.d.ts +0 -6
- package/build/sdk/enums/index.mjs +0 -27
- package/build/sdk/enums/runtime.enum.mjs +0 -6
- package/build/sdk/enums/timestamp.enum.mjs +0 -6
- package/build/sdk/env.d.ts +0 -6
- package/build/sdk/env.mjs +0 -74
- package/build/sdk/fastify.d.ts +0 -11
- package/build/sdk/fastify.mjs +0 -9
- package/build/sdk/grafts.d.ts +0 -15
- package/build/sdk/grafts.mjs +0 -71
- package/build/sdk/index.d.ts +0 -34
- package/build/sdk/index.mjs +0 -126
- package/build/sdk/json.d.ts +0 -17
- package/build/sdk/json.mjs +0 -87
- package/build/sdk/plugins/body-parser.plugin.d.ts +0 -17
- package/build/sdk/plugins/body-parser.plugin.mjs +0 -7
- package/build/sdk/plugins/index.d.ts +0 -17
- package/build/sdk/plugins/index.mjs +0 -48
- package/build/sdk/plugins/security/body-limit.d.ts +0 -17
- package/build/sdk/plugins/security/body-limit.mjs +0 -45
- package/build/sdk/plugins/security/cors.d.ts +0 -22
- package/build/sdk/plugins/security/cors.mjs +0 -45
- package/build/sdk/plugins/security/headers.d.ts +0 -17
- package/build/sdk/plugins/security/headers.mjs +0 -45
- package/build/sdk/plugins/security/index.d.ts +0 -25
- package/build/sdk/plugins/security/index.mjs +0 -45
- package/build/sdk/plugins/security/method-guard.d.ts +0 -17
- package/build/sdk/plugins/security/method-guard.mjs +0 -45
- package/build/sdk/plugins/security/rate-limit.d.ts +0 -21
- package/build/sdk/plugins/security/rate-limit.mjs +0 -45
- package/build/sdk/repositories.d.ts +0 -7
- package/build/sdk/repositories.mjs +0 -17
- package/build/sdk/request.d.ts +0 -4
- package/build/sdk/request.mjs +0 -6
- package/build/sdk/responses.d.ts +0 -8
- package/build/sdk/responses.mjs +0 -20
- package/build/sdk/routes.d.ts +0 -7
- package/build/sdk/routes.mjs +0 -61
- package/build/sdk/runtime/bun/server.d.ts +0 -6
- package/build/sdk/runtime/bun/server.mjs +0 -6
- package/build/sdk/runtime/deno/server.d.ts +0 -6
- package/build/sdk/runtime/deno/server.mjs +0 -6
- package/build/sdk/runtime/index.d.ts +0 -15
- package/build/sdk/runtime/index.mjs +0 -11
- package/build/sdk/runtime/node/reply.d.ts +0 -2
- package/build/sdk/runtime/node/reply.mjs +0 -0
- package/build/sdk/runtime/node/request.d.ts +0 -2
- package/build/sdk/runtime/node/request.mjs +0 -0
- package/build/sdk/runtime/node/server.d.ts +0 -6
- package/build/sdk/runtime/node/server.mjs +0 -6
- package/build/sdk/runtime/web/server.d.ts +0 -6
- package/build/sdk/runtime/web/server.mjs +0 -6
- package/build/sdk/schemes.d.ts +0 -120
- package/build/sdk/schemes.mjs +0 -129
- package/build/sdk/services.d.ts +0 -8
- package/build/sdk/services.mjs +0 -10
- package/build/sdk/throwable.mjs +0 -14
- package/build/sdk/utilities/alias-path.util.d.ts +0 -9
- package/build/sdk/utilities/alias-path.util.mjs +0 -6
- package/build/sdk/utilities/artifacts.util.d.ts +0 -3
- package/build/sdk/utilities/artifacts.util.mjs +0 -45
- package/build/sdk/utilities/callable.util.d.ts +0 -3
- package/build/sdk/utilities/callable.util.mjs +0 -6
- package/build/sdk/utilities/controller.util.d.ts +0 -3
- package/build/sdk/utilities/controller.util.mjs +0 -6
- package/build/sdk/utilities/index.d.ts +0 -7
- package/build/sdk/utilities/index.mjs +0 -62
- package/build/sdk/utilities/json.util.d.ts +0 -3
- package/build/sdk/utilities/json.util.mjs +0 -6
- package/build/sdk/utilities/parameters-arguments.util.d.ts +0 -2
- package/build/sdk/utilities/parameters-arguments.util.mjs +0 -0
- package/build/sdk/utilities/url.d.ts +0 -3
- package/build/sdk/utilities/url.mjs +0 -7
- package/build/sdk/utilities/utilities.util.d.ts +0 -6
- package/build/sdk/utilities/utilities.util.mjs +0 -8
- package/build/types/access-guards.d.ts +0 -6
- package/build/types/access-guards.mjs +0 -0
- package/build/types/application.mjs +0 -0
- package/build/types/artifact.d.ts +0 -21
- package/build/types/artifact.mjs +0 -0
- package/build/types/builder.d.ts +0 -32
- package/build/types/builder.mjs +0 -0
- package/build/types/config.d.ts +0 -6
- package/build/types/config.mjs +0 -0
- package/build/types/controller.d.ts +0 -25
- package/build/types/controller.mjs +0 -0
- package/build/types/contruct.d.ts +0 -3
- package/build/types/contruct.mjs +0 -0
- package/build/types/core.d.ts +0 -15
- package/build/types/core.mjs +0 -0
- package/build/types/data-transfer-object.d.ts +0 -5
- package/build/types/data-transfer-object.mjs +0 -0
- package/build/types/dependency-container.d.ts +0 -20
- package/build/types/dependency-container.mjs +0 -0
- package/build/types/directory.mjs +0 -0
- package/build/types/encryption.d.ts +0 -16
- package/build/types/encryption.mjs +0 -0
- package/build/types/generic.d.ts +0 -4
- package/build/types/generic.mjs +0 -0
- package/build/types/hmr.d.ts +0 -25
- package/build/types/hmr.mjs +0 -0
- package/build/types/http-responses.d.ts +0 -10
- package/build/types/http-responses.mjs +0 -0
- package/build/types/index.d.ts +0 -45
- package/build/types/index.mjs +0 -0
- package/build/types/middleware.d.ts +0 -12
- package/build/types/middleware.mjs +0 -0
- package/build/types/parameters.d.ts +0 -19
- package/build/types/parameters.mjs +0 -0
- package/build/types/parseable.d.ts +0 -5
- package/build/types/parseable.mjs +0 -0
- package/build/types/payload.d.ts +0 -6
- package/build/types/payload.mjs +0 -0
- package/build/types/plugin.d.ts +0 -20
- package/build/types/plugin.mjs +0 -0
- package/build/types/raiton.d.ts +0 -12
- package/build/types/raiton.mjs +0 -0
- package/build/types/repositories.d.ts +0 -8
- package/build/types/repositories.mjs +0 -0
- package/build/types/router.d.ts +0 -14
- package/build/types/router.mjs +0 -0
- package/build/types/runtime.d.ts +0 -37
- package/build/types/runtime.mjs +0 -0
- package/build/types/scheme.mjs +0 -0
- package/build/types/server.d.ts +0 -57
- package/build/types/server.mjs +0 -0
- package/build/types/services.d.ts +0 -8
- package/build/types/services.mjs +0 -0
- package/build/types/thread.d.ts +0 -24
- package/build/types/thread.mjs +0 -0
- package/build/types/utilities.d.ts +0 -6
- package/build/types/utilities.mjs +0 -0
- package/build/types/values.d.ts +0 -4
- package/build/types/values.mjs +0 -0
- /package/{build/chunk-4OWCGDUD.mjs → source/sdk/runtime/node/reply.ts} +0 -0
- /package/{build/chunk-DIWD7ZCJ.mjs → source/sdk/runtime/node/request.ts} +0 -0
package/deno.json
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "raiton",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Protorians Raiton Development Kit",
|
|
7
|
+
"main": "./source/core/index.ts",
|
|
8
|
+
"module": "./source/core/index.ts",
|
|
9
|
+
"types": "./source/core/index.d.ts",
|
|
7
10
|
"bin": {
|
|
8
|
-
"raiton": "
|
|
11
|
+
"raiton": "source/bin/index.ts"
|
|
9
12
|
},
|
|
10
13
|
"keywords": [
|
|
11
14
|
"protorians",
|
|
@@ -14,6 +17,8 @@
|
|
|
14
17
|
"kit",
|
|
15
18
|
"typescript",
|
|
16
19
|
"node",
|
|
20
|
+
"bun",
|
|
21
|
+
"deno",
|
|
17
22
|
"backend"
|
|
18
23
|
],
|
|
19
24
|
"author": "Y. Yannick GOBOU",
|
|
@@ -23,36 +28,21 @@
|
|
|
23
28
|
"url": "git+https://github.com/protorians/raiton.git"
|
|
24
29
|
},
|
|
25
30
|
"exports": {
|
|
26
|
-
"./core
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
"./commands/*": {
|
|
35
|
-
"types": "./build/commands/*.d.ts",
|
|
36
|
-
"import": "./build/commands/*.mjs"
|
|
37
|
-
},
|
|
38
|
-
"./sdk/*": {
|
|
39
|
-
"types": "./build/sdk/*.d.ts",
|
|
40
|
-
"import": "./build/sdk/*.mjs"
|
|
41
|
-
},
|
|
42
|
-
"./sdk": {
|
|
43
|
-
"types": "./build/sdk/index.d.ts",
|
|
44
|
-
"import": "./build/sdk/index.mjs"
|
|
45
|
-
},
|
|
46
|
-
"./types/*": {
|
|
47
|
-
"types": "./build/types/index.d.ts",
|
|
48
|
-
"import": "./build/types/index.mjs"
|
|
49
|
-
}
|
|
31
|
+
".": "./source/core/index.ts",
|
|
32
|
+
"./core/*": "./source/core/*.ts",
|
|
33
|
+
"./commands/*": "./source/commands/*.ts",
|
|
34
|
+
"./sdk": "./source/sdk/index.ts",
|
|
35
|
+
"./sdk/*": "./source/sdk/*.ts",
|
|
36
|
+
"./types": "./source/types/index.ts",
|
|
37
|
+
"./types/*": "./source/types/*.ts"
|
|
50
38
|
},
|
|
51
39
|
"scripts": {
|
|
52
|
-
"dev": "
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
40
|
+
"dev": "bun run --hot source/bin/index.ts",
|
|
41
|
+
"start": "bun run build/bin/index.mjs",
|
|
42
|
+
"build": "bun build source/bin/index.ts --target=node --format=esm --outfile=build/bin/index.mjs",
|
|
43
|
+
"version": "bun run scripts/update-version.ts",
|
|
44
|
+
"postinstall": "chmod +x source/bin/index.ts",
|
|
45
|
+
"prepublishOnly": "npm run build"
|
|
56
46
|
},
|
|
57
47
|
"dependencies": {
|
|
58
48
|
"@protorians/core": "^0.6.13",
|
|
@@ -63,26 +53,15 @@
|
|
|
63
53
|
"@types/node": "^25.0.3",
|
|
64
54
|
"argon2": "^0.44.0",
|
|
65
55
|
"bcrypt": "^6.0.0",
|
|
56
|
+
"class-validator": "^0.14.3",
|
|
66
57
|
"commander": "^14.0.2",
|
|
67
58
|
"dotenv": "^17.2.3",
|
|
68
|
-
"esbuild": "^0.27.1",
|
|
69
|
-
"fastify": "^5.6.2",
|
|
70
|
-
"fastify-plugin": "^5.1.0",
|
|
71
59
|
"reflect-metadata": "^0.2.2"
|
|
72
60
|
},
|
|
73
61
|
"devDependencies": {
|
|
74
|
-
"@semantic-release/changelog": "^6.0.3",
|
|
75
|
-
"@semantic-release/git": "^10.0.1",
|
|
76
|
-
"@semantic-release/github": "^12.0.2",
|
|
77
|
-
"@semantic-release/npm": "^13.1.2",
|
|
78
62
|
"@types/bcrypt": "^6.0.0",
|
|
79
63
|
"@types/bun": "^1.3.5",
|
|
80
64
|
"@types/deno": "^2.5.0",
|
|
81
|
-
"commitizen": "^4.3.1",
|
|
82
|
-
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
83
|
-
"cz-conventional-changelog": "^3.3.0",
|
|
84
|
-
"semantic-release": "^25.0.2",
|
|
85
|
-
"tsup": "^8.3.0",
|
|
86
65
|
"typescript": "^5.9.3"
|
|
87
66
|
},
|
|
88
67
|
"config": {
|
|
@@ -92,7 +71,7 @@
|
|
|
92
71
|
},
|
|
93
72
|
"compilerOptions": {
|
|
94
73
|
"types": [
|
|
95
|
-
"
|
|
74
|
+
"bun"
|
|
96
75
|
]
|
|
97
76
|
},
|
|
98
77
|
"publishConfig": {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
function getLatestTag() {
|
|
6
|
+
try {
|
|
7
|
+
return execSync("git describe --tags --abbrev=0").toString().trim();
|
|
8
|
+
} catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getCommitsSince(tag: string | null) {
|
|
14
|
+
const range = tag ? `${tag}..HEAD` : "HEAD";
|
|
15
|
+
try {
|
|
16
|
+
const output = execSync(`git log ${range} --format=%s`).toString().trim();
|
|
17
|
+
return output ? output.split("\n") : [];
|
|
18
|
+
} catch {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function determineIncrement(commits: string[]) {
|
|
24
|
+
let increment: "major" | "minor" | "patch" | null = null;
|
|
25
|
+
|
|
26
|
+
for (let commit of commits) {
|
|
27
|
+
commit = commit.trim();
|
|
28
|
+
if (
|
|
29
|
+
commit.includes("BREAKING CHANGE") ||
|
|
30
|
+
commit.includes("!") ||
|
|
31
|
+
commit.toLowerCase().startsWith("release") ||
|
|
32
|
+
commit.toLowerCase().startsWith("upgrade") ||
|
|
33
|
+
commit.toLowerCase().startsWith("remove")
|
|
34
|
+
) {
|
|
35
|
+
return "major";
|
|
36
|
+
}
|
|
37
|
+
if (
|
|
38
|
+
commit.startsWith("feat") ||
|
|
39
|
+
commit.startsWith("add")
|
|
40
|
+
) {
|
|
41
|
+
increment = "minor";
|
|
42
|
+
} else if (
|
|
43
|
+
!increment &&
|
|
44
|
+
commit.startsWith("fix") ||
|
|
45
|
+
commit.startsWith("update")
|
|
46
|
+
) {
|
|
47
|
+
increment = "patch";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return increment;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function updateVersion(increment: "major" | "minor" | "patch") {
|
|
55
|
+
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
56
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
57
|
+
const currentVersion = packageJson.version;
|
|
58
|
+
const [major, minor, patch] = currentVersion.split(".").map(Number);
|
|
59
|
+
|
|
60
|
+
let nextVersion = "";
|
|
61
|
+
if (increment === "major") {
|
|
62
|
+
nextVersion = `${major + 1}.0.0`;
|
|
63
|
+
} else if (increment === "minor") {
|
|
64
|
+
nextVersion = `${major}.${minor + 1}.0`;
|
|
65
|
+
} else {
|
|
66
|
+
nextVersion = `${major}.${minor}.${patch + 1}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
packageJson.version = nextVersion;
|
|
70
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n");
|
|
71
|
+
console.log(`Version updated from ${currentVersion} to ${nextVersion}`);
|
|
72
|
+
return nextVersion;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function main() {
|
|
76
|
+
const latestTag = getLatestTag();
|
|
77
|
+
console.log(`Latest tag: ${latestTag || "None"}`);
|
|
78
|
+
|
|
79
|
+
const commits = getCommitsSince(latestTag);
|
|
80
|
+
console.log(`Commits since last tag: ${commits.length}`);
|
|
81
|
+
|
|
82
|
+
if (commits.length === 0) {
|
|
83
|
+
console.log("No new commits. Skipping version update.");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const increment = determineIncrement(commits);
|
|
88
|
+
if (!increment) {
|
|
89
|
+
console.log("No version-triggering commits found (feat, fix, BREAKING CHANGE). Skipping version update.");
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
console.log(`Determined increment: ${increment}`);
|
|
94
|
+
updateVersion(increment);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
main();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {Command} from 'commander';
|
|
2
|
+
import {RaitonCommands, RaitonConfig} from "@/core";
|
|
3
|
+
import {getPackageRoot} from "@/sdk";
|
|
4
|
+
import {CliTools} from "@/bin/cli-tools";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export default async function bootstrapper(cli: Command) {
|
|
8
|
+
const appdir = getPackageRoot(import.meta.url);
|
|
9
|
+
const workdir = `${CliTools.cwd || './'}`;
|
|
10
|
+
const capabilities = new RaitonCommands(cli, appdir, workdir)
|
|
11
|
+
|
|
12
|
+
await RaitonConfig.sync(workdir);
|
|
13
|
+
await capabilities.harvest();
|
|
14
|
+
return cli.parse(process.argv)
|
|
15
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {spawn} from 'node:child_process';
|
|
2
|
+
import {isBunUsed, isDenoUsed} from "@/bin/constants";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export class CliTools {
|
|
6
|
+
static get cwd() {
|
|
7
|
+
return `${isDenoUsed ? (globalThis as any).Deno.cwd() : process.cwd()}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static set cwd(value: string) {
|
|
11
|
+
if (isDenoUsed) {
|
|
12
|
+
(globalThis as any).Deno.chdir(value);
|
|
13
|
+
} else {
|
|
14
|
+
process.chdir(value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static get argv() {
|
|
19
|
+
if (isBunUsed) return (globalThis as any).Bun.argv;
|
|
20
|
+
if (isDenoUsed) return (globalThis as any).Deno.args;
|
|
21
|
+
return process.argv;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static get process() {
|
|
25
|
+
if (isBunUsed) return (globalThis as any).Bun;
|
|
26
|
+
if (isDenoUsed) return (globalThis as any).Deno;
|
|
27
|
+
return process;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static spawn(command: string | string[], args: string[] = [], options?: Record<string, any>) {
|
|
31
|
+
if (isBunUsed) {
|
|
32
|
+
const cmdArray = [
|
|
33
|
+
...(typeof command == 'string' ? [command] : (Array.isArray(command) ? command : [])),
|
|
34
|
+
...args
|
|
35
|
+
];
|
|
36
|
+
if (typeof command === 'string' && command.endsWith('.ts')) {
|
|
37
|
+
cmdArray.unshift('bun');
|
|
38
|
+
}
|
|
39
|
+
return Bun.spawn(cmdArray, options);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (isDenoUsed) {
|
|
43
|
+
const cmd = typeof command == 'string' ? command : command[0];
|
|
44
|
+
const cmdArgs = typeof command == 'string' ? args : [...command.slice(1), ...args];
|
|
45
|
+
|
|
46
|
+
if (cmd.endsWith('.ts')) {
|
|
47
|
+
return new Deno.Command('deno', {
|
|
48
|
+
args: ['run', '-A', cmd, ...cmdArgs],
|
|
49
|
+
...options
|
|
50
|
+
}).spawn();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return new Deno.Command(cmd, {
|
|
54
|
+
args: cmdArgs,
|
|
55
|
+
...options
|
|
56
|
+
}).spawn();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const cmd = typeof command == 'string' ? command : command[0];
|
|
60
|
+
const cmdArgs = typeof command == 'string' ? args : [...command.slice(1), ...args];
|
|
61
|
+
|
|
62
|
+
if (cmd.endsWith('.ts')) {
|
|
63
|
+
return spawn('node', ['--loader', 'ts-node/register', cmd, ...cmdArgs], options);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return spawn(cmd, cmdArgs, options);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Command} from "commander";
|
|
2
|
+
import {version} from '../../package.json';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const CLI = new Command();
|
|
6
|
+
|
|
7
|
+
CLI
|
|
8
|
+
.name('raiton')
|
|
9
|
+
.description('Protorians Raiton development kit for backend microservice')
|
|
10
|
+
.version(version);
|
|
11
|
+
|
|
12
|
+
export default CLI;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {RaitonCommand, RaitonBuilder} from "@/core";
|
|
2
|
+
import {Logger} from "@protorians/logger";
|
|
3
|
+
import type {BuildCommandOptions} from "@/types";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export default class ArtifactCommand extends RaitonCommand {
|
|
7
|
+
public readonly name: string = 'artifact';
|
|
8
|
+
public readonly description: string = 'Manage artifacts';
|
|
9
|
+
|
|
10
|
+
public register(): void {
|
|
11
|
+
this.cli
|
|
12
|
+
.command(this.name)
|
|
13
|
+
.alias("art")
|
|
14
|
+
.description(this.description)
|
|
15
|
+
.option("--dump, -d", "Dump the application artifacts configured")
|
|
16
|
+
.option("--create, -c", "Create an artifact")
|
|
17
|
+
.option("--remove, -r", "Remove an artifact")
|
|
18
|
+
.option("--clear", "Clear all artifacts")
|
|
19
|
+
.action(this.run.bind(this));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected async run(options: BuildCommandOptions): Promise<void> {
|
|
23
|
+
|
|
24
|
+
Logger.notice("Artifact management is not yet implemented");
|
|
25
|
+
Logger.debug('Options:', options, '')
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {RaitonCommand, RaitonBuilder} from "@/core";
|
|
2
|
+
import {LBadge, Logger} from "@protorians/logger";
|
|
3
|
+
import type {BuildCommandOptions} from "@/types";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export default class BuildCommand extends RaitonCommand {
|
|
7
|
+
public readonly name: string = 'build';
|
|
8
|
+
public readonly description: string = 'Build the application';
|
|
9
|
+
|
|
10
|
+
public register(): void {
|
|
11
|
+
this.cli
|
|
12
|
+
.command(this.name)
|
|
13
|
+
.alias("b")
|
|
14
|
+
.description("Build the application")
|
|
15
|
+
.option("--develop, -d", "Build in development mode")
|
|
16
|
+
.option("--bootstrap, -b", "Bootstrap the application")
|
|
17
|
+
.action(this.run.bind(this));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected async run(options: BuildCommandOptions): Promise<void> {
|
|
21
|
+
if (options.develop) Logger.warn(LBadge.log("Dev Mode"),);
|
|
22
|
+
|
|
23
|
+
const builder = new RaitonBuilder(this.workdir, {
|
|
24
|
+
development: options.develop
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await builder.prepare()
|
|
28
|
+
await builder.boot()
|
|
29
|
+
// await builder.start(async () => (options.develop || options.bootstrap) ? await builder.boot() : void (0))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {Raiton, RaitonCommand} from "@/core";
|
|
2
|
+
import {ChildProcess, ChildProcessWithoutNullStreams} from 'node:child_process';
|
|
3
|
+
import {Logger} from "@protorians/logger";
|
|
4
|
+
import {EventMessageEnum} from "@/sdk";
|
|
5
|
+
import {CliTools} from "@/bin/cli-tools";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
export default class DevelopCommand extends RaitonCommand {
|
|
9
|
+
public readonly name: string = 'develop';
|
|
10
|
+
public readonly description: string = 'Run the application in development mode';
|
|
11
|
+
|
|
12
|
+
private child: Bun.Subprocess<"ignore", "pipe", "inherit"> | ChildProcess | Deno.ChildProcess | ChildProcessWithoutNullStreams | null = null;
|
|
13
|
+
|
|
14
|
+
public register(): void {
|
|
15
|
+
this.cli
|
|
16
|
+
.command(this.name)
|
|
17
|
+
.alias("dev")
|
|
18
|
+
.description("Start the application in development mode")
|
|
19
|
+
.action(this.run.bind(this));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected async restart(): Promise<void> {
|
|
23
|
+
Logger.info('Reloading...');
|
|
24
|
+
console.clear();
|
|
25
|
+
this.child?.kill('SIGTERM');
|
|
26
|
+
|
|
27
|
+
if (this.child && 'on' in this.child)
|
|
28
|
+
this.child?.on('exit', () => this.run());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected async run(): Promise<void> {
|
|
32
|
+
// Logger.info('Workdir', this.workdir);
|
|
33
|
+
|
|
34
|
+
const entryPoint = path.join(this.appdir, 'bin/index.ts');
|
|
35
|
+
this.child = CliTools.spawn(entryPoint, ['build', '-d'], {
|
|
36
|
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
37
|
+
cwd: this.workdir
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (this.child && 'on' in this.child)
|
|
41
|
+
this.child.on('message', (msg) => {
|
|
42
|
+
if (msg === EventMessageEnum.RESTART) this.restart()
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
Logger.log('PID', this.child?.pid)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {RaitonCommand} from "@/core";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export default class GraftsCommand extends RaitonCommand {
|
|
5
|
+
|
|
6
|
+
public readonly name: string = 'grafts';
|
|
7
|
+
public readonly description: string = 'Generates typings grafts';
|
|
8
|
+
public readonly version: string = '0.0.1';
|
|
9
|
+
|
|
10
|
+
public register(): void {
|
|
11
|
+
this.cli
|
|
12
|
+
.command(this.name)
|
|
13
|
+
.description("Generates typings grafts")
|
|
14
|
+
.action(this.generates.bind(this))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected async generates(): Promise<void> {
|
|
18
|
+
console.log("Running grafts generator command");
|
|
19
|
+
// generateArtifacts(
|
|
20
|
+
// "graft",
|
|
21
|
+
// "IGlobalGrafts",
|
|
22
|
+
// /@Graftable\(\s*(?:([A-Za-z0-9_.]+)\s*,\s*)?(?:(["'`])(.*?)\2)?\s*\)/,
|
|
23
|
+
// true,
|
|
24
|
+
// )
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {RaitonCommand} from "@/core";
|
|
2
|
+
import {ChildProcess} from 'node:child_process';
|
|
3
|
+
import {Raiton} from "@/core/raiton";
|
|
4
|
+
import {CliTools} from "@/bin/cli-tools";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
export default class StartCommand extends RaitonCommand {
|
|
8
|
+
public readonly name: string = 'start';
|
|
9
|
+
public readonly description: string = 'Run the application in production mode';
|
|
10
|
+
|
|
11
|
+
private child: Bun.Subprocess<"ignore", "pipe", "inherit"> | ChildProcess | Deno.ChildProcess | null = null;
|
|
12
|
+
|
|
13
|
+
public register(): void {
|
|
14
|
+
this.cli
|
|
15
|
+
.command(this.name)
|
|
16
|
+
.alias("run")
|
|
17
|
+
.description("Start the application in production mode")
|
|
18
|
+
.action(this.run.bind(this));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected async run(): Promise<void> {
|
|
22
|
+
const entryPoint = path.join(this.appdir, 'bin/index.ts');
|
|
23
|
+
this.child = CliTools.spawn(entryPoint, ['build', '--bootstrap'], {
|
|
24
|
+
stdio: 'inherit',
|
|
25
|
+
cwd: this.workdir
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {PluginScope} from '@/core/plugins/scope'
|
|
2
|
+
import {RequestContext} from './context'
|
|
3
|
+
import {ApplicationConfig, ApplicationInterface} from "@/types/application";
|
|
4
|
+
import {HttpMethod} from "@/sdk";
|
|
5
|
+
import {RouteHandler} from "@/types";
|
|
6
|
+
import {Logger} from "@protorians/logger";
|
|
7
|
+
import {RaitonConfig} from "@/core/config";
|
|
8
|
+
import {Artifacts} from "@/sdk/artifacts";
|
|
9
|
+
|
|
10
|
+
export class Application implements ApplicationInterface {
|
|
11
|
+
private root: PluginScope
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
readonly config: ApplicationConfig
|
|
15
|
+
) {
|
|
16
|
+
this.root = new PluginScope()
|
|
17
|
+
if (this.config.workdir) {
|
|
18
|
+
process.chdir(this.config.workdir)
|
|
19
|
+
}
|
|
20
|
+
this.initialize()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected initialize(): this {
|
|
24
|
+
const artifacts = RaitonConfig.get('artifacts')
|
|
25
|
+
const artifactTypes = [...artifacts?.types || [], ...Artifacts.defaultTypes]
|
|
26
|
+
|
|
27
|
+
Artifacts.registerMany(...artifactTypes)
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public get hostname(): string {
|
|
32
|
+
return `${
|
|
33
|
+
this.config.protocole || 'http'
|
|
34
|
+
}://${
|
|
35
|
+
this.config.hostname || 'localhost'
|
|
36
|
+
}${
|
|
37
|
+
this.config.port ? `:${this.config.port}` : ''
|
|
38
|
+
}${
|
|
39
|
+
this.config.pathname || '/'
|
|
40
|
+
}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public setOption<K extends keyof ApplicationConfig>(key: K, value: ApplicationConfig[K]): this {
|
|
44
|
+
this.config[key] = value;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public setOptions(options: ApplicationConfig): this {
|
|
49
|
+
Object.assign(this.config, options);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
register(plugin: any): this {
|
|
54
|
+
this.root.register(plugin)
|
|
55
|
+
return this
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
use(mw: any): this {
|
|
59
|
+
this.root.use(mw)
|
|
60
|
+
return this
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
route(method: HttpMethod, path: string, handler: RouteHandler, version?: string): this {
|
|
64
|
+
const prefix = this.config.prefix ?? ''
|
|
65
|
+
const fullPath = `${prefix}${path}`.replace(/\/+/g, '/') || '/'
|
|
66
|
+
this.root.route(method, fullPath, handler, version)
|
|
67
|
+
return this
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get(path: string, handler: RouteHandler, version?: string): this {
|
|
71
|
+
return this.route(HttpMethod.GET, path, handler, version)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
post(path: string, handler: RouteHandler, version?: string): this {
|
|
75
|
+
return this.route(HttpMethod.POST, path, handler, version)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
patch(path: string, handler: RouteHandler, version?: string): this {
|
|
79
|
+
return this.route(HttpMethod.PATCH, path, handler, version)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
put(path: string, handler: RouteHandler, version?: string): this {
|
|
83
|
+
return this.route(HttpMethod.PUT, path, handler, version)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
delete(path: string, handler: RouteHandler, version?: string): this {
|
|
87
|
+
return this.route(HttpMethod.DELETE, path, handler, version)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
options(path: string, handler: RouteHandler, version?: string): this {
|
|
91
|
+
return this.route(HttpMethod.OPTIONS, path, handler, version)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
head(path: string, handler: RouteHandler, version?: string): this {
|
|
95
|
+
return this.route(HttpMethod.HEAD, path, handler, version)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
trace(path: string, handler: RouteHandler, version?: string): this {
|
|
99
|
+
return this.route(HttpMethod.TRACE, path, handler, version)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async handle(req: any, reply: any): Promise<any> {
|
|
103
|
+
const ctx = new RequestContext(req, reply)
|
|
104
|
+
|
|
105
|
+
if (this.config.verbose) {
|
|
106
|
+
Logger.info(
|
|
107
|
+
`Incoming request: ${req.method} ${req.url}`
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
await this.root.hooks.run('onRequest', ctx)
|
|
112
|
+
|
|
113
|
+
const url = new URL(req.url, this.hostname)
|
|
114
|
+
let pathname = url.pathname
|
|
115
|
+
|
|
116
|
+
if (this.config.pathname && this.config.pathname !== '/') {
|
|
117
|
+
const appPathname = this.config.pathname.endsWith('/') ? this.config.pathname : `${this.config.pathname}/`
|
|
118
|
+
if (pathname.startsWith(appPathname)) {
|
|
119
|
+
pathname = pathname.substring(appPathname.length - 1) || '/'
|
|
120
|
+
} else if (pathname === this.config.pathname) {
|
|
121
|
+
pathname = '/'
|
|
122
|
+
} else {
|
|
123
|
+
// Requête hors du pathname de l'application
|
|
124
|
+
if (this.config.verbose) {
|
|
125
|
+
Logger.warn(`Request out of application pathname: ${pathname} (expected prefix: ${this.config.pathname})`)
|
|
126
|
+
}
|
|
127
|
+
reply.status(404)
|
|
128
|
+
return reply.send({error: false, statusCode: 404})
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const route = this.root.router.match(
|
|
133
|
+
req.method,
|
|
134
|
+
pathname
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
if (!route) {
|
|
138
|
+
if (this.config.verbose) {
|
|
139
|
+
Logger.warn(`Route not found: ${req.method} ${pathname}`)
|
|
140
|
+
}
|
|
141
|
+
reply.status(404)
|
|
142
|
+
return reply.send({error: false, statusCode: 404})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const pipeline = this.root.middleware.clone()
|
|
146
|
+
pipeline.use(async ({context}) => {
|
|
147
|
+
try {
|
|
148
|
+
(context as any).params = route.parameters;
|
|
149
|
+
let responses = await route.handler(context)
|
|
150
|
+
|
|
151
|
+
context.reply.send(responses)
|
|
152
|
+
} catch (e: any) {
|
|
153
|
+
Logger.error('Failed to handle request', e.message ?? e)
|
|
154
|
+
if (this.config.develop) {
|
|
155
|
+
console.error(e)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
await pipeline.run(ctx)
|
|
161
|
+
await this.root.hooks.run('onResponse', ctx)
|
|
162
|
+
}
|
|
163
|
+
}
|