raiton 1.1.1 → 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 +55 -0
- package/README.md +97 -1
- package/build/bin/index.mjs +7012 -47
- package/deno.json +9 -0
- package/package.json +28 -44
- 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-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-P2YCCBFR.mjs +0 -14
- 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.1.1.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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BuilderInterface,
|
|
3
|
+
RuntimeAdapterInterface,
|
|
4
|
+
RuntimeServerInterface,
|
|
5
|
+
ThreadInterface,
|
|
6
|
+
ThreadOptions,
|
|
7
|
+
ThreadSetupOptions,
|
|
8
|
+
ThreadWaitCallable,
|
|
9
|
+
} from "@/types";
|
|
10
|
+
import {EventMessageEnum, RuntimeType} from "@/sdk/enums";
|
|
11
|
+
import {ProcessUtility} from "@protorians/core";
|
|
12
|
+
import {until} from "./process.util";
|
|
13
|
+
import {ApplicationInterface} from "@/types/application";
|
|
14
|
+
import {Runtime} from "@/sdk/runtime";
|
|
15
|
+
import {LBadge, Logger} from "@protorians/logger";
|
|
16
|
+
import {ControllerBuilder} from "@/core/controller";
|
|
17
|
+
import {bodyParserPlugin} from "@/sdk/plugins/body-parser.plugin";
|
|
18
|
+
import {Injection} from "@/core/injection/injection";
|
|
19
|
+
import {Throwable} from "@/sdk/exceptions";
|
|
20
|
+
import os from "os";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export class RaitonThread implements ThreadInterface {
|
|
24
|
+
|
|
25
|
+
protected static instance: RaitonThread | null = null;
|
|
26
|
+
|
|
27
|
+
public static get current(): RaitonThread | null {
|
|
28
|
+
// if (!RaitonThread.instance) throw new Throwable('Thread not initialized')
|
|
29
|
+
return RaitonThread.instance;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public application: ApplicationInterface | null = null;
|
|
33
|
+
public runtime: RuntimeAdapterInterface | null = null;
|
|
34
|
+
public runtimeServer: RuntimeServerInterface | null = null;
|
|
35
|
+
|
|
36
|
+
readonly appDir: string;
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
public readonly builder: BuilderInterface,
|
|
40
|
+
protected _options: ThreadOptions = {}
|
|
41
|
+
) {
|
|
42
|
+
this.appDir = process.cwd();
|
|
43
|
+
RaitonThread.instance = this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public restart(): void {
|
|
47
|
+
process.send?.(EventMessageEnum.RESTART)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async stop(): Promise<void> {
|
|
51
|
+
await Injection.shutdown();
|
|
52
|
+
process.exit(0)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public async sleep(milliseconds: number): Promise<unknown> {
|
|
56
|
+
return await ProcessUtility.sleep(milliseconds);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public async wait(condition: ThreadWaitCallable): Promise<void> {
|
|
60
|
+
return await until(condition)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected getNetworkIp(): string | null {
|
|
64
|
+
const interfaces = os.networkInterfaces();
|
|
65
|
+
for (const name of Object.keys(interfaces)) {
|
|
66
|
+
for (const iface of interfaces[name] || []) {
|
|
67
|
+
if (iface.family === 'IPv4' && !iface.internal) {
|
|
68
|
+
return iface.address;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public setup({application, runtime}: ThreadSetupOptions): this {
|
|
76
|
+
const defaultRuntime = typeof Bun !== 'undefined' ? RuntimeType.Bun : RuntimeType.Node;
|
|
77
|
+
this.runtime = new Runtime(runtime || defaultRuntime);
|
|
78
|
+
this.application = application;
|
|
79
|
+
this.application.use(bodyParserPlugin())
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async run(): Promise<this> {
|
|
84
|
+
|
|
85
|
+
if (!this.application)
|
|
86
|
+
throw new Throwable('Application not defined');
|
|
87
|
+
|
|
88
|
+
if (!this.runtime)
|
|
89
|
+
throw new Throwable('Runtime not defined');
|
|
90
|
+
|
|
91
|
+
process.on('SIGINT', async () => {
|
|
92
|
+
await this.stop();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
process.on('SIGTERM', async () => {
|
|
96
|
+
await this.stop();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const port = this.application.config.port || 5712;
|
|
100
|
+
const hostname = this.application.config.hostname || '0.0.0.0';
|
|
101
|
+
const displayHostname = (hostname === '0.0.0.0') ? (this.getNetworkIp() || 'localhost') : hostname;
|
|
102
|
+
const prefix = this.application.config.prefix
|
|
103
|
+
|
|
104
|
+
this.runtimeServer = this.runtime.createServer(this.application.handle.bind(this.application))
|
|
105
|
+
|
|
106
|
+
await this.runtimeServer.listen(port, hostname)
|
|
107
|
+
if (this.builder.source) await ControllerBuilder.scan(this.builder.source)
|
|
108
|
+
|
|
109
|
+
Logger.log(LBadge.info('Server Started'), `http://${displayHostname}:${port}${prefix ?? ''}`)
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
}
|
package/source/env.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {EventBus, EventBusEnum} from "@protorians/events-bus";
|
|
4
|
+
|
|
5
|
+
dotenv.config({
|
|
6
|
+
path: path.join(process.cwd(), '.env'),
|
|
7
|
+
debug: false,
|
|
8
|
+
quiet: true,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
process.env.RAITON_NATURAL_MODE = !!process[Symbol.for("ts-node.register.instance")];
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Process Events caching
|
|
17
|
+
*/
|
|
18
|
+
process.on('beforeExit', (code) => EventBus.dispatch(EventBusEnum.SERVER_SHUTDOWN, {code}));
|
|
19
|
+
// process.on('exit', (code) => EventBus.dispatch(EventBusEnum.SYSTEM_SERVER_SHUTDOWN, {code}));
|
|
20
|
+
process.on('SIGINT', (code) => {
|
|
21
|
+
EventBus.dispatch(EventBusEnum.SERVER_STOPPED, {code})
|
|
22
|
+
process.exit(1);
|
|
23
|
+
});
|
|
24
|
+
process.on('SIGTERM', (code) => {
|
|
25
|
+
EventBus.dispatch(EventBusEnum.SERVER_STOPPED, {code})
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {Injection} from "@/core/injection";
|
|
2
|
+
import {Logger} from "@protorians/logger";
|
|
3
|
+
import type {IConstructor} from "@/types";
|
|
4
|
+
import {Raiton} from "@/core/raiton";
|
|
5
|
+
import {isArtifact, isControllerArtifact} from "@/sdk/utilities";
|
|
6
|
+
|
|
7
|
+
export class Artifacts {
|
|
8
|
+
|
|
9
|
+
static readonly types: Set<string> = new Set();
|
|
10
|
+
|
|
11
|
+
static readonly defaultTypes = [
|
|
12
|
+
'service',
|
|
13
|
+
'provider',
|
|
14
|
+
'type',
|
|
15
|
+
'repository',
|
|
16
|
+
'database',
|
|
17
|
+
'db',
|
|
18
|
+
'util',
|
|
19
|
+
'utility',
|
|
20
|
+
'source',
|
|
21
|
+
'controller',
|
|
22
|
+
'middleware',
|
|
23
|
+
'hook',
|
|
24
|
+
'event',
|
|
25
|
+
'listener',
|
|
26
|
+
'validator',
|
|
27
|
+
'strategy',
|
|
28
|
+
'strategy-provider',
|
|
29
|
+
'strategy-type',
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
static register(type: string) {
|
|
33
|
+
this.types.add(type)
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static registerMany(...types: string[]) {
|
|
38
|
+
for (const type of types) this.register(type)
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static is(filename: string) {
|
|
43
|
+
return [...this.types]
|
|
44
|
+
.map(type => isArtifact(filename, type))
|
|
45
|
+
.some(Boolean)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static reload(modulo: any, filename?: string) {
|
|
49
|
+
|
|
50
|
+
if (Raiton.thread?.builder.options.development === false)
|
|
51
|
+
return Logger.warn(
|
|
52
|
+
'Artifact reload is only available in development mode'
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
for (const mod of Object.values(modulo)) {
|
|
56
|
+
const name = (mod && typeof mod === 'object' && 'name' in mod) ? mod.name : (
|
|
57
|
+
typeof mod === 'function' ? mod.name ?? mod.constructor.name : undefined
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (typeof name === 'string' && Injection.has(name)) {
|
|
61
|
+
if (filename) Injection.registerArtifactPath(name, filename);
|
|
62
|
+
Injection.updateConstruct(name, mod as IConstructor)
|
|
63
|
+
|
|
64
|
+
const dependents = Injection.getDependents(name);
|
|
65
|
+
for (const dependent of dependents) {
|
|
66
|
+
const dependentPath = Injection.getArtifactPath(dependent);
|
|
67
|
+
if (dependentPath && isControllerArtifact(dependentPath)) {
|
|
68
|
+
Raiton.signals.dispatch('hmr:controller', {
|
|
69
|
+
filename: dependentPath,
|
|
70
|
+
timestamp: Date.now(),
|
|
71
|
+
version: 1
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const METADATA_KEYS = {
|
|
2
|
+
CONTROLLERS: Symbol('controller:meta'),
|
|
3
|
+
ROUTE_PARAMETERS: Symbol('route:meta'),
|
|
4
|
+
GRAFTS: Symbol('graft:meta'),
|
|
5
|
+
CONTAINER: Symbol('container:meta'),
|
|
6
|
+
INJECT_PARAMETERS: Symbol('inject:parameters'),
|
|
7
|
+
INJECT_PROPERTIES: Symbol('inject:properties'),
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {validate, validateOrReject, ValidationError} from "class-validator";
|
|
2
|
+
import {Logger} from "@protorians/logger";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export class DataTransferObject {
|
|
6
|
+
constructor(initial: Record<string, any>) {
|
|
7
|
+
for (const [key, value] of Object.entries(initial)) {
|
|
8
|
+
if (typeof value !== 'function') this[key as keyof typeof this] = value;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async validation(strict: boolean = true): Promise<void | ValidationError[]> {
|
|
13
|
+
return await ((strict ? validateOrReject : validate)(this))
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// import {IAccessGuardDeclaration} from "../../types";
|
|
2
|
+
// import {SYSTEM_DECORATORS_KEYS} from "../constants";
|
|
3
|
+
//
|
|
4
|
+
// export function AccessGuard(declaration: IAccessGuardDeclaration){
|
|
5
|
+
// return (target: any, methodKey: any)=> {
|
|
6
|
+
// const current: IAccessGuardDeclaration = {...(Reflect.getMetadata(SYSTEM_DECORATORS_KEYS.ACCESS_GUARD, target.constructor, methodKey) || {}), ...declaration};
|
|
7
|
+
// Reflect.defineMetadata(SYSTEM_DECORATORS_KEYS.ACCESS_GUARD, current, target.constructor, methodKey);
|
|
8
|
+
// }
|
|
9
|
+
// }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {getControllerMetadata} from "@/core/controller";
|
|
2
|
+
import {Injectable} from "@/sdk";
|
|
3
|
+
import {LifetimeEnum} from "@protorians/core";
|
|
4
|
+
import {ControllerDecoratorCallable} from "@/types";
|
|
5
|
+
|
|
6
|
+
export function Controllable(prefix = '') {
|
|
7
|
+
return (target: any) => {
|
|
8
|
+
const name = target.name;
|
|
9
|
+
Injectable(LifetimeEnum.TRANSIENT, name,)(target)
|
|
10
|
+
|
|
11
|
+
const meta = getControllerMetadata(target.prototype || target)
|
|
12
|
+
meta.prefix = prefix;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createControllerDecorator(callable: ControllerDecoratorCallable) {
|
|
17
|
+
return (target: any) => {
|
|
18
|
+
callable(getControllerMetadata(target.prototype || target))
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import type {IConstructor} from "@/types/contruct";
|
|
3
|
+
import {Injection} from "@/core/injection";
|
|
4
|
+
import {LifetimeEnum} from "@protorians/core";
|
|
5
|
+
import {Logger} from "@protorians/logger";
|
|
6
|
+
import {METADATA_KEYS} from "@/sdk/constants";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export function Injectable(lifetime?: LifetimeEnum, name?: string, scope?: any) {
|
|
10
|
+
return function <T extends IConstructor>(target: T) {
|
|
11
|
+
const metadata = {
|
|
12
|
+
name: name || target.name,
|
|
13
|
+
construct: target,
|
|
14
|
+
lifetime: lifetime || LifetimeEnum.TRANSIENT,
|
|
15
|
+
scope
|
|
16
|
+
};
|
|
17
|
+
Reflect.defineMetadata(METADATA_KEYS.CONTAINER, metadata, target);
|
|
18
|
+
Injection.registry(
|
|
19
|
+
metadata.name,
|
|
20
|
+
target,
|
|
21
|
+
metadata.lifetime,
|
|
22
|
+
scope
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function Inject(token?: any) {
|
|
28
|
+
return function (target: any, propertyKey: string | symbol | undefined, parameterIndex?: number) {
|
|
29
|
+
if (parameterIndex !== undefined) {
|
|
30
|
+
const parameters = Reflect.getMetadata(METADATA_KEYS.INJECT_PARAMETERS, target) || [];
|
|
31
|
+
parameters[parameterIndex] = token || true;
|
|
32
|
+
Reflect.defineMetadata(METADATA_KEYS.INJECT_PARAMETERS, parameters, target);
|
|
33
|
+
} else if (propertyKey !== undefined) {
|
|
34
|
+
const properties = Reflect.getMetadata(METADATA_KEYS.INJECT_PROPERTIES, target.constructor) || new Map();
|
|
35
|
+
const type = token || Reflect.getMetadata('design:type', target, propertyKey);
|
|
36
|
+
|
|
37
|
+
if (type === undefined || type === Object) {
|
|
38
|
+
Logger.warn(`Injection: impossible de déterminer le type pour la propriété "${String(propertyKey)}" de ${target.constructor.name}. Assurez-vous d'utiliser un token ou que le type est une classe.`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
properties.set(propertyKey, type);
|
|
42
|
+
Reflect.defineMetadata(METADATA_KEYS.INJECT_PROPERTIES, properties, target.constructor);
|
|
43
|
+
}
|
|
44
|
+
return target;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {MiddlewareCallable} from "@/types";
|
|
2
|
+
import {getControllerMetadata} from "@/core";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function Middleware(middleware: MiddlewareCallable) {
|
|
6
|
+
return (target: any, propertyKey?: string) => {
|
|
7
|
+
const meta = getControllerMetadata(target.prototype || target)
|
|
8
|
+
const segment = propertyKey ? propertyKey : '@'
|
|
9
|
+
meta.middlewares[segment] = [...(meta.middlewares[segment] || []), middleware];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createMiddlewareDecoration(middleware: MiddlewareCallable) {
|
|
14
|
+
return Middleware(middleware);
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import type {Context, ParamMetaInterface} from "@/types";
|
|
3
|
+
import {METADATA_KEYS, Parametrable} from "@/sdk";
|
|
4
|
+
|
|
5
|
+
function createRouteParametrableDecorator(type: ParamMetaInterface['type'], callable?: (context: Context) => any) {
|
|
6
|
+
return (key?: string) => {
|
|
7
|
+
return (target: any, propertyKey: string, index: number) => {
|
|
8
|
+
const params = Reflect.getMetadata(METADATA_KEYS.ROUTE_PARAMETERS, target.constructor) || {}
|
|
9
|
+
const metatypes = Reflect.getMetadata("design:paramtypes", target, propertyKey);
|
|
10
|
+
const metatype = metatypes ? metatypes[index] : undefined;
|
|
11
|
+
|
|
12
|
+
if (!params[propertyKey]) {
|
|
13
|
+
params[propertyKey] = []
|
|
14
|
+
}
|
|
15
|
+
params[propertyKey].push({index, type, key, callable, metatype})
|
|
16
|
+
Reflect.defineMetadata(METADATA_KEYS.ROUTE_PARAMETERS, params, target.constructor)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const Query = createRouteParametrableDecorator(Parametrable.QUERY)
|
|
22
|
+
export const Param = createRouteParametrableDecorator(Parametrable.PARAM)
|
|
23
|
+
export const Body = createRouteParametrableDecorator(Parametrable.BODY)
|
|
24
|
+
export const UploadedFile = createRouteParametrableDecorator(Parametrable.UPLOAD_FILE)
|
|
25
|
+
export const Headers = createRouteParametrableDecorator(Parametrable.HEADER)
|
|
26
|
+
export const Req = createRouteParametrableDecorator(Parametrable.REQ)
|
|
27
|
+
export const Reply = createRouteParametrableDecorator(Parametrable.REPLY)
|
|
28
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {getControllerMetadata} from "@/core";
|
|
2
|
+
import {HttpMethod} from "@/sdk";
|
|
3
|
+
import {ControllerMetaInterface, RouteDecoratorCallable, RouteMetaInterface} from "@/types";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
function stabilizeRoute(meta: ControllerMetaInterface, {path, method, propertyKey}: Partial<RouteMetaInterface>) {
|
|
7
|
+
return {
|
|
8
|
+
...meta.routes.filter(route => (route.path === path && route.method === method) || (route.propertyKey === propertyKey))[0] || {},
|
|
9
|
+
method,
|
|
10
|
+
path,
|
|
11
|
+
propertyKey,
|
|
12
|
+
} as RouteMetaInterface;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createRoutableDecorator(method: HttpMethod) {
|
|
16
|
+
return (path = '') =>
|
|
17
|
+
(target: any, propertyKey: string) => {
|
|
18
|
+
const meta: ControllerMetaInterface = getControllerMetadata(target);
|
|
19
|
+
const route = stabilizeRoute(meta, {
|
|
20
|
+
method,
|
|
21
|
+
path,
|
|
22
|
+
propertyKey,
|
|
23
|
+
});
|
|
24
|
+
meta.routes.push(route)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createRouteDecorator(callable: RouteDecoratorCallable) {
|
|
29
|
+
return (target: any, propertyKey: string) => {
|
|
30
|
+
const controller: ControllerMetaInterface = getControllerMetadata(target);
|
|
31
|
+
const route: RouteMetaInterface = stabilizeRoute(controller, {propertyKey})
|
|
32
|
+
const index = controller.routes.findIndex(route => route.propertyKey === propertyKey)
|
|
33
|
+
|
|
34
|
+
callable({controller, route, index})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const Get = createRoutableDecorator(HttpMethod.GET)
|
|
39
|
+
export const Post = createRoutableDecorator(HttpMethod.POST)
|
|
40
|
+
export const Put = createRoutableDecorator(HttpMethod.PUT)
|
|
41
|
+
export const Patch = createRoutableDecorator(HttpMethod.PATCH)
|
|
42
|
+
export const Options = createRoutableDecorator(HttpMethod.OPTIONS)
|
|
43
|
+
export const Trace = createRoutableDecorator(HttpMethod.TRACE)
|
|
44
|
+
export const Delete = createRoutableDecorator(HttpMethod.DELETE)
|
|
45
|
+
export const Head = createRoutableDecorator(HttpMethod.HEAD)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import argon2, {Options} from "argon2";
|
|
3
|
+
import {HashAlgoEnum, PasswordAlgoEnum} from "./enums";
|
|
4
|
+
import bcrypt from "bcrypt";
|
|
5
|
+
import {IDerivationOptions, IEncryptionResult, IScryptOptions} from "@/types";
|
|
6
|
+
|
|
7
|
+
export class Encryption {
|
|
8
|
+
static get algos() {
|
|
9
|
+
return HashAlgoEnum;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static randomAlgo(algo?: PasswordAlgoEnum[] | HashAlgoEnum[]) {
|
|
13
|
+
const algos = algo ?? Object.values(this.algos);
|
|
14
|
+
return algos[Math.floor(Math.random() * Object.values(algos).length)];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
constructor(public readonly algo: HashAlgoEnum | PasswordAlgoEnum) {
|
|
18
|
+
if (![...Object.values(HashAlgoEnum), ...Object.values(PasswordAlgoEnum)].includes(this.algo)) {
|
|
19
|
+
throw new Error(`Invalid hash algorithm: ${this.algo}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async compare(value: string, hash: string): Promise<boolean> {
|
|
24
|
+
return this.make(value).then(result => result === hash);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async make(value: string, options?: IDerivationOptions | IScryptOptions): Promise<IEncryptionResult> {
|
|
28
|
+
if (!value) {
|
|
29
|
+
throw new Error('Value cannot be empty');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
switch (this.algo) {
|
|
33
|
+
case HashAlgoEnum.SHA256:
|
|
34
|
+
return this.sha256(value);
|
|
35
|
+
case HashAlgoEnum.SHA512:
|
|
36
|
+
return this.sha512(value);
|
|
37
|
+
case HashAlgoEnum.MD5:
|
|
38
|
+
return this.md5(value);
|
|
39
|
+
case HashAlgoEnum.RIPEMD160:
|
|
40
|
+
return this.ripemd160(value);
|
|
41
|
+
case HashAlgoEnum.BLAKE2B:
|
|
42
|
+
return this.blake2b(value);
|
|
43
|
+
case HashAlgoEnum.SHA3_256:
|
|
44
|
+
return this.sha3_256(value);
|
|
45
|
+
case HashAlgoEnum.SHA3_512:
|
|
46
|
+
return this.sha3_512(value);
|
|
47
|
+
case HashAlgoEnum.PBKDF2:
|
|
48
|
+
return this.pbkdf2(value, options as IDerivationOptions | undefined);
|
|
49
|
+
case HashAlgoEnum.SCRYPT:
|
|
50
|
+
return this.scrypt(value, options as IScryptOptions | undefined);
|
|
51
|
+
case HashAlgoEnum.ARGON2ID:
|
|
52
|
+
case HashAlgoEnum.BCRYPT:
|
|
53
|
+
return this.password(value);
|
|
54
|
+
default:
|
|
55
|
+
throw new Error(`Unsupported algorithm: ${this.algo}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected sha256(value: string): IEncryptionResult {
|
|
60
|
+
return crypto.createHash("sha256").update(value).digest("hex");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected sha512(value: string): IEncryptionResult {
|
|
64
|
+
return crypto.createHash("sha512").update(value).digest("hex");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected md5(value: string): IEncryptionResult {
|
|
68
|
+
return crypto.createHash("md5").update(value).digest("hex");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected ripemd160(value: string): IEncryptionResult {
|
|
72
|
+
return crypto.createHash("ripemd160").update(value).digest("hex");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
protected blake2b(value: string): IEncryptionResult {
|
|
76
|
+
return crypto.createHash("blake2b512").update(value).digest("hex");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
protected sha3_256(value: string): IEncryptionResult {
|
|
80
|
+
return crypto.createHash("sha3-256").update(value).digest("hex");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected sha3_512(value: string): IEncryptionResult {
|
|
84
|
+
return crypto.createHash("sha3-512").update(value).digest("hex");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected pbkdf2(value: string, options?: IDerivationOptions): IEncryptionResult {
|
|
88
|
+
const {salt, iterations, keylen, digest} = options || {};
|
|
89
|
+
const usedSalt = salt ?? crypto.randomBytes(16).toString("hex");
|
|
90
|
+
const usedIterations = iterations ?? 100_000;
|
|
91
|
+
const usedKeylen = keylen ?? 64;
|
|
92
|
+
const usedDigest = digest ?? "sha512";
|
|
93
|
+
const derived = crypto
|
|
94
|
+
.pbkdf2Sync(value, Buffer.from(usedSalt, "hex"), usedIterations, usedKeylen, usedDigest)
|
|
95
|
+
.toString("hex");
|
|
96
|
+
return `pbkdf2$${usedDigest}$${usedIterations}$${usedSalt}$${derived}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected scrypt(value: string, options?: IScryptOptions): IEncryptionResult {
|
|
100
|
+
const {salt, keylen, cost, blockSize, parallelization} = options || {} as IScryptOptions;
|
|
101
|
+
const usedSalt = salt ?? crypto.randomBytes(16).toString("hex");
|
|
102
|
+
const usedKeylen = keylen ?? 64;
|
|
103
|
+
const usedCost = cost ?? 16384; // N
|
|
104
|
+
const usedBlockSize = blockSize ?? 8; // r
|
|
105
|
+
const usedParallel = parallelization ?? 1; // p
|
|
106
|
+
const derived = crypto
|
|
107
|
+
.scryptSync(value, Buffer.from(usedSalt, "hex"), usedKeylen, {
|
|
108
|
+
N: usedCost,
|
|
109
|
+
r: usedBlockSize,
|
|
110
|
+
p: usedParallel,
|
|
111
|
+
maxmem: 32 * 1024 * 1024,
|
|
112
|
+
})
|
|
113
|
+
.toString("hex");
|
|
114
|
+
return `scrypt$${usedCost}$${usedBlockSize}$${usedParallel}$${usedSalt}$${derived}`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
protected unsupported(): never {
|
|
118
|
+
throw new Error(`${this.algo} not supported without optional dependency`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async password(value: string, options?: (Options & {
|
|
122
|
+
raw?: boolean
|
|
123
|
+
}) | (string | number) | undefined): Promise<IEncryptionResult> {
|
|
124
|
+
switch (this.algo) {
|
|
125
|
+
case HashAlgoEnum.ARGON2ID: {
|
|
126
|
+
return await argon2.hash(value, {
|
|
127
|
+
...(typeof options === 'object' ? options : {}),
|
|
128
|
+
type: argon2.argon2id
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
case HashAlgoEnum.BCRYPT: {
|
|
132
|
+
try {
|
|
133
|
+
const saltRounds = 12;
|
|
134
|
+
return await bcrypt.hash(
|
|
135
|
+
value,
|
|
136
|
+
(typeof options === 'string' || typeof options === 'number') ? options : saltRounds
|
|
137
|
+
);
|
|
138
|
+
} catch (e) {
|
|
139
|
+
throw new Error(`BCRYPT not supported without optional dependency "bcrypt"`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
default:
|
|
143
|
+
throw new Error(`password() is only available for BCRYPT and ARGON2ID (current: ${this.algo})`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async checkPassword(hash: string, password: string): Promise<boolean> {
|
|
148
|
+
switch (this.algo) {
|
|
149
|
+
case HashAlgoEnum.ARGON2ID:
|
|
150
|
+
return await argon2.verify(hash, password);
|
|
151
|
+
case HashAlgoEnum.BCRYPT:
|
|
152
|
+
return await bcrypt.compare(password, hash);
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export enum HashAlgoEnum {
|
|
2
|
+
ARGON2ID = 'ARGON2ID',
|
|
3
|
+
BCRYPT = 'BCRYPT',
|
|
4
|
+
PBKDF2 = 'PBKDF2',
|
|
5
|
+
SCRYPT = 'SCRYPT',
|
|
6
|
+
SHA256 = 'SHA256',
|
|
7
|
+
SHA512 = 'SHA512',
|
|
8
|
+
MD5 = 'MD5',
|
|
9
|
+
RIPEMD160 = 'RIPEMD160',
|
|
10
|
+
BLAKE2B = 'BLAKE2B',
|
|
11
|
+
SHA3_256 = 'SHA3_256',
|
|
12
|
+
SHA3_512 = 'SHA3_512',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export enum CipherAlgoEnum {
|
|
16
|
+
AES_256_CBC = 'AES-256-CBC',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export enum PasswordAlgoEnum {
|
|
20
|
+
ARGON2ID = 'argon2id',
|
|
21
|
+
BCRYPT = 'BCRYPT',
|
|
22
|
+
SCRYPT = 'SCRYPT',
|
|
23
|
+
}
|
package/{build/sdk/enums/http-parameters.enum.d.ts → source/sdk/enums/http-parameters.enum.ts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export enum Parametrable {
|
|
2
2
|
PARAM = "param",
|
|
3
3
|
BODY = "body",
|
|
4
4
|
QUERY = "query",
|
|
@@ -6,7 +6,5 @@ declare enum Parametrable {
|
|
|
6
6
|
REQ = "req",
|
|
7
7
|
REPLY = "reply",
|
|
8
8
|
UPLOAD_FILE = "upload",
|
|
9
|
-
CUSTOM = "custom"
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { Parametrable };
|
|
9
|
+
CUSTOM = "custom",
|
|
10
|
+
}
|