raiton 0.0.2 → 1.0.0-alpha.1
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 +25 -0
- package/README.md +20 -0
- package/build/bin/index.mjs +6788 -47
- package/build/raiton-1.0.0-alpha.1.tgz +0 -0
- package/package.json +21 -36
- package/source/bin/bootstrapper.ts +15 -0
- package/source/bin/cli-tools.ts +43 -0
- package/source/bin/cli.ts +12 -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 +115 -0
- package/source/core/artifacts/artifact.ts +109 -0
- package/source/core/artifacts/artifacts.ts +10 -0
- package/source/core/artifacts/index.ts +1 -0
- package/source/core/artifacts/runner.ts +3 -0
- package/source/core/builder.ts +138 -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 +38 -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/hmr.ts +106 -0
- package/source/core/hooks.ts +28 -0
- package/source/core/index.ts +13 -0
- package/source/core/injection/index.ts +1 -0
- package/source/core/injection/injection.ts +157 -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 +21 -0
- package/source/core/router/handler.ts +59 -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 +87 -0
- package/source/env.d.ts +3 -0
- package/source/requirements.ts +27 -0
- package/source/sdk/artifacts.ts +55 -0
- package/source/sdk/constants/decorators.constant.ts +7 -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 +7 -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 +24 -0
- package/source/sdk/decorators/payload.decorator.ts +77 -0
- package/source/sdk/decorators/routable.decorator.ts +48 -0
- package/source/sdk/encryption.ts +155 -0
- package/source/sdk/enums/encrypted.enum.ts +13 -0
- package/source/sdk/enums/event.message.enum.ts +4 -0
- package/{build/sdk/enums/http-parameters.enum.d.ts → source/sdk/enums/http-parameters.enum.ts} +3 -5
- package/source/sdk/enums/http.enum.ts +10 -0
- package/source/sdk/enums/index.ts +6 -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/index.ts +6 -0
- package/source/sdk/json.ts +55 -0
- package/source/sdk/plugins/body-parser.plugin.ts +119 -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/request.ts +3 -0
- package/source/sdk/responses.ts +45 -0
- package/source/sdk/runtime/bun/server.ts +72 -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/{build/sdk/schemes.d.ts → source/sdk/schemes.ts} +91 -33
- package/source/sdk/services.ts +9 -0
- package/{build/sdk/throwable.d.ts → source/sdk/throwable.ts} +35 -12
- package/source/sdk/utilities/alias-path.util.ts +49 -0
- package/source/sdk/utilities/artifacts.util.ts +62 -0
- package/source/sdk/utilities/callable.util.ts +27 -0
- package/source/sdk/utilities/controller.util.ts +8 -0
- package/source/sdk/utilities/index.ts +7 -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 +40 -0
- package/source/types/builder.ts +48 -0
- package/source/types/config.ts +7 -0
- package/source/types/controller.ts +34 -0
- package/source/types/contruct.ts +3 -0
- package/source/types/core.ts +28 -0
- package/source/types/data-transfer-object.ts +4 -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/{build/types/hmr.d.ts → source/types/hmr.ts} +19 -5
- package/source/types/http-responses.ts +8 -0
- package/source/types/index.ts +26 -0
- package/source/types/injection.ts +13 -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 +9 -0
- package/source/types/responses.ts +10 -0
- package/source/types/router.ts +11 -0
- package/source/types/runtime.ts +53 -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 -45
- 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-BVILWYAP.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-0.0.2.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.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.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,157 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import type {IConstructor, ContainerDefinitionInterface} from "@/types";
|
|
3
|
+
import {Throwable} from "@/sdk/throwable";
|
|
4
|
+
import {LifetimeEnum, TextUtility} from "@protorians/core";
|
|
5
|
+
import {Logger} from "@protorians/logger";
|
|
6
|
+
import {METADATA_KEYS} from "@/sdk/constants";
|
|
7
|
+
import camelCase = TextUtility.camelCase;
|
|
8
|
+
|
|
9
|
+
export class Injection {
|
|
10
|
+
|
|
11
|
+
protected static _classes: Map<string, ContainerDefinitionInterface> = new Map();
|
|
12
|
+
protected static _instances: Map<string, Map<any, any>> = new Map();
|
|
13
|
+
protected static _resolutionStack: string[] = [];
|
|
14
|
+
|
|
15
|
+
static get classes(): Map<string, ContainerDefinitionInterface> {
|
|
16
|
+
return this._classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static defaultScope = Symbol('default');
|
|
20
|
+
|
|
21
|
+
static get instances(): Map<string, Map<any, any>> {
|
|
22
|
+
return this._instances;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static has(name: string): boolean {
|
|
26
|
+
return this._classes.has(this.normalizeName(name));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static clear(): void {
|
|
30
|
+
this._classes.clear();
|
|
31
|
+
this._instances.clear();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static normalizeName(name: string): string {
|
|
35
|
+
const stableName = camelCase(name);
|
|
36
|
+
return stableName[0].toLowerCase() + stableName.slice(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static registry(
|
|
40
|
+
name: string,
|
|
41
|
+
construct: IConstructor,
|
|
42
|
+
lifetime: LifetimeEnum = LifetimeEnum.SINGLETON,
|
|
43
|
+
scope?: Symbol
|
|
44
|
+
): typeof this {
|
|
45
|
+
if (!construct.name)
|
|
46
|
+
throw new Error('Le constructeur doit avoir un nom valide pour être enregistré dans le conteneur.');
|
|
47
|
+
|
|
48
|
+
this._classes.set(this.normalizeName(name), {name, construct, lifetime, scope});
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static resolveArguments(definition: ContainerDefinitionInterface, scope?: any): any[] {
|
|
53
|
+
try {
|
|
54
|
+
const parameters = Reflect.getMetadata(METADATA_KEYS.INJECT_PARAMETERS, definition.construct) || [];
|
|
55
|
+
const designParameters = Reflect.getMetadata('design:paramtypes', definition.construct) || [];
|
|
56
|
+
const effectiveScope = scope || definition.scope || this.defaultScope;
|
|
57
|
+
|
|
58
|
+
const maxLen = Math.max(parameters.length, designParameters.length);
|
|
59
|
+
const args = [];
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < maxLen; i++) {
|
|
62
|
+
const param = parameters[i];
|
|
63
|
+
const designParam = designParameters[i];
|
|
64
|
+
|
|
65
|
+
if (param && param !== true) {
|
|
66
|
+
const token = typeof param === 'function' ? (param.name || param) : param;
|
|
67
|
+
if (typeof token === 'string') {
|
|
68
|
+
args.push(this.get(token, effectiveScope));
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (typeof param === 'function') {
|
|
72
|
+
const metadata: ContainerDefinitionInterface = Reflect.getMetadata(METADATA_KEYS.CONTAINER, param);
|
|
73
|
+
args.push(this.get(metadata?.name || param.name, effectiveScope));
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (designParam && typeof designParam === 'function' && designParam.name) {
|
|
79
|
+
const metadata: ContainerDefinitionInterface = Reflect.getMetadata(METADATA_KEYS.CONTAINER, designParam);
|
|
80
|
+
args.push(this.get(metadata?.name || designParam.name, effectiveScope));
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
args.push(undefined);
|
|
85
|
+
}
|
|
86
|
+
return args;
|
|
87
|
+
} catch (e) {
|
|
88
|
+
Logger.error('Resolve', e);
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static get<T>(name: string, scope?: Symbol): T | undefined {
|
|
94
|
+
const name_ = this.normalizeName(name);
|
|
95
|
+
const cls = this._classes.get(name_);
|
|
96
|
+
if (!cls) throw new Throwable(`Dependency ${name} not registered`);
|
|
97
|
+
|
|
98
|
+
const effectiveScope = scope || cls.scope || this.defaultScope;
|
|
99
|
+
if (this._resolutionStack.includes(name_)) {
|
|
100
|
+
throw new Throwable(`Circular dependency detected: ${this._resolutionStack.join(' -> ')} -> ${name}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this._resolutionStack.push(name_);
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
let instance: any;
|
|
107
|
+
if (cls.lifetime === LifetimeEnum.SINGLETON) {
|
|
108
|
+
if (!this._instances.has(name_)) {
|
|
109
|
+
this._instances.set(name_, new Map());
|
|
110
|
+
}
|
|
111
|
+
const scopeInstances = this._instances.get(name_)!;
|
|
112
|
+
|
|
113
|
+
if (!scopeInstances.has(effectiveScope)) {
|
|
114
|
+
instance = new cls.construct(...this.resolveArguments(cls, effectiveScope));
|
|
115
|
+
scopeInstances.set(effectiveScope, instance);
|
|
116
|
+
this.injectProperties(instance, cls, effectiveScope);
|
|
117
|
+
}
|
|
118
|
+
return scopeInstances.get(effectiveScope);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (cls.lifetime === LifetimeEnum.TRANSIENT) {
|
|
122
|
+
instance = new cls.construct(...this.resolveArguments(cls, effectiveScope));
|
|
123
|
+
this.injectProperties(instance, cls, effectiveScope);
|
|
124
|
+
return instance as any;
|
|
125
|
+
}
|
|
126
|
+
} finally {
|
|
127
|
+
this._resolutionStack.pop();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
protected static injectProperties(instance: any, definition: ContainerDefinitionInterface, scope?: any): void {
|
|
134
|
+
const properties: Map<string | symbol, any> = Reflect.getMetadata(METADATA_KEYS.INJECT_PROPERTIES, definition.construct);
|
|
135
|
+
|
|
136
|
+
if (properties) {
|
|
137
|
+
for (const [propertyKey, type] of properties) {
|
|
138
|
+
const token = typeof type === 'function' ? (type.name || type) : type;
|
|
139
|
+
if (typeof token === 'string') {
|
|
140
|
+
instance[propertyKey] = this.get(token, scope);
|
|
141
|
+
} else if (typeof type === 'function') {
|
|
142
|
+
const metadata: ContainerDefinitionInterface = Reflect.getMetadata(METADATA_KEYS.CONTAINER, type);
|
|
143
|
+
instance[propertyKey] = this.get(metadata?.name || type.name, scope);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static resolve<T>(construct: IConstructor<T>): T {
|
|
150
|
+
const metadata: ContainerDefinitionInterface = Reflect.getMetadata(METADATA_KEYS.CONTAINER, construct);
|
|
151
|
+
|
|
152
|
+
if (!metadata)
|
|
153
|
+
throw new Throwable(`Cannot resolve ${construct.name} as dependency`);
|
|
154
|
+
|
|
155
|
+
return this.get(metadata.name) as T;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {MiddlewareType} from '@/types'
|
|
2
|
+
import {Throwable} from "@/sdk/throwable";
|
|
3
|
+
|
|
4
|
+
export function middlewareCompose(middlewares: MiddlewareType[]) {
|
|
5
|
+
return function (request: any) {
|
|
6
|
+
let index = -1
|
|
7
|
+
|
|
8
|
+
return dispatch(0)
|
|
9
|
+
|
|
10
|
+
async function dispatch(i: number): Promise<void> {
|
|
11
|
+
if (i <= index) {
|
|
12
|
+
return Promise.reject(
|
|
13
|
+
new Throwable('next() called multiple times')
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
index = i
|
|
18
|
+
const fn = middlewares[i];
|
|
19
|
+
try {
|
|
20
|
+
if (!fn) return Promise.resolve()
|
|
21
|
+
|
|
22
|
+
if (typeof fn === 'function') {
|
|
23
|
+
return Promise.resolve(fn({context: request, next: () => dispatch(i + 1)}))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeof fn === 'object' && 'setup' in fn && typeof fn.setup == 'function') {
|
|
27
|
+
if (fn.setup.length === 1) {
|
|
28
|
+
await Promise.resolve(fn.setup(request))
|
|
29
|
+
return await dispatch(i + 1)
|
|
30
|
+
}
|
|
31
|
+
return Promise.resolve(fn.setup(request, () => dispatch(i + 1)))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return Promise.resolve()
|
|
35
|
+
} catch (err) {
|
|
36
|
+
return Promise.reject(err)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MiddlewareType } from '@/types'
|
|
2
|
+
import { middlewareCompose } from '@/core'
|
|
3
|
+
|
|
4
|
+
export class MiddlewarePipeline {
|
|
5
|
+
private stack: MiddlewareType[] = []
|
|
6
|
+
|
|
7
|
+
use(mw: MiddlewareType): this {
|
|
8
|
+
this.stack.push(mw)
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
clear(): this {
|
|
13
|
+
this.stack = []
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
run(ctx: any) {
|
|
18
|
+
const fn = middlewareCompose(this.stack)
|
|
19
|
+
return typeof fn == 'function' ? fn(ctx) : undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
clone() {
|
|
23
|
+
const pipeline = new MiddlewarePipeline()
|
|
24
|
+
pipeline.stack = [...this.stack]
|
|
25
|
+
return pipeline
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {HookStore} from '@/core/hooks'
|
|
2
|
+
import {MiddlewarePipeline} from '@/core/middleware'
|
|
3
|
+
import {Route, Router} from '@/core/router'
|
|
4
|
+
|
|
5
|
+
export class PluginScope {
|
|
6
|
+
public hooks: HookStore
|
|
7
|
+
public middleware: MiddlewarePipeline
|
|
8
|
+
public router: Router
|
|
9
|
+
|
|
10
|
+
constructor(parent?: PluginScope) {
|
|
11
|
+
this.hooks = parent ? parent.hooks.clone() : new HookStore()
|
|
12
|
+
this.middleware = parent
|
|
13
|
+
? parent.middleware.clone()
|
|
14
|
+
: new MiddlewarePipeline()
|
|
15
|
+
this.router = parent ? parent.router : new Router()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
addHook(name: any, fn: any): this {
|
|
19
|
+
this.hooks.add(name, fn)
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
use(mw: any): this {
|
|
24
|
+
if (typeof mw === 'object' && mw !== null && 'setup' in mw && typeof mw.setup === 'function' && mw.setup.length === 1) {
|
|
25
|
+
mw.setup(this)
|
|
26
|
+
return this
|
|
27
|
+
}
|
|
28
|
+
this.middleware.use(mw)
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
route(
|
|
33
|
+
method: any,
|
|
34
|
+
path: string,
|
|
35
|
+
handler: any,
|
|
36
|
+
version?: string
|
|
37
|
+
): Route {
|
|
38
|
+
return this.router.add(method, path, handler, version)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
register(plugin: any): PluginScope {
|
|
42
|
+
const child = new PluginScope(this)
|
|
43
|
+
plugin.setup(child)
|
|
44
|
+
return child
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
export async function until(condition: () => boolean | Promise<boolean>, interval = 50): Promise<void> {
|
|
3
|
+
return new Promise<void>((resolve) => {
|
|
4
|
+
const check = () => {
|
|
5
|
+
const result = condition();
|
|
6
|
+
if (result instanceof Promise)
|
|
7
|
+
result.then((res) => res ? resolve() : setTimeout(check, interval));
|
|
8
|
+
else ((result) ? resolve() : setTimeout(check, interval))
|
|
9
|
+
}
|
|
10
|
+
check();
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {RaitonSignalMap, ThreadInterface} from "@/types";
|
|
2
|
+
import {ISignalStack, Signal} from "@protorians/core";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export class Raiton {
|
|
6
|
+
protected static _thread: ThreadInterface | undefined;
|
|
7
|
+
|
|
8
|
+
static readonly signals: ISignalStack<RaitonSignalMap> = new Signal.Stack<RaitonSignalMap>()
|
|
9
|
+
static title: string = 'Protorians Raiton';
|
|
10
|
+
static identifier: string = 'raiton';
|
|
11
|
+
|
|
12
|
+
static get thread(): ThreadInterface {
|
|
13
|
+
if (!this._thread)
|
|
14
|
+
throw new Error(`${Raiton.title} Thread instance not initialized`);
|
|
15
|
+
return this._thread;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static set thread(thread: ThreadInterface | undefined) {
|
|
19
|
+
this._thread = this._thread || thread;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {ControllerMetaInterface, MiddlewareCallable, RouteMetaInterface} from "@/types";
|
|
2
|
+
import {Parametrable} from "@/sdk";
|
|
3
|
+
import {Logger} from "@protorians/logger";
|
|
4
|
+
import {Throwable} from "@/sdk/throwable";
|
|
5
|
+
import {middlewareCompose} from "@/core";
|
|
6
|
+
|
|
7
|
+
export function createHandler(
|
|
8
|
+
instance: any,
|
|
9
|
+
routeMeta: RouteMetaInterface,
|
|
10
|
+
controllerMeta: ControllerMetaInterface,
|
|
11
|
+
) {
|
|
12
|
+
return async (ctx: any) => {
|
|
13
|
+
const args: any[] = []
|
|
14
|
+
|
|
15
|
+
for (const p of routeMeta.params) {
|
|
16
|
+
|
|
17
|
+
switch (p.type) {
|
|
18
|
+
case Parametrable.QUERY:
|
|
19
|
+
args[p.index] =
|
|
20
|
+
ctx.req.query?.[p.key!]
|
|
21
|
+
break
|
|
22
|
+
case Parametrable.PARAM:
|
|
23
|
+
args[p.index] =
|
|
24
|
+
ctx.req.params?.[p.key!] ?? ctx.params?.[p.key!]
|
|
25
|
+
break
|
|
26
|
+
case Parametrable.BODY:
|
|
27
|
+
args[p.index] = ctx.req.body
|
|
28
|
+
break
|
|
29
|
+
case Parametrable.HEADER:
|
|
30
|
+
args[p.index] = ctx.req.headers[p.key!.toLowerCase()] as any;
|
|
31
|
+
break
|
|
32
|
+
case Parametrable.REQ:
|
|
33
|
+
args[p.index] = ctx.req
|
|
34
|
+
break
|
|
35
|
+
case Parametrable.REPLY:
|
|
36
|
+
args[p.index] = ctx.REPLY
|
|
37
|
+
break
|
|
38
|
+
case Parametrable.UPLOAD_FILE:
|
|
39
|
+
args[p.index] = ctx.req.file
|
|
40
|
+
break
|
|
41
|
+
case Parametrable.CUSTOM:
|
|
42
|
+
args[p.index] = p.callable?.(ctx) ?? null;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!(routeMeta.propertyKey in instance))
|
|
48
|
+
throw new Throwable(`${routeMeta.propertyKey} does not exist`)
|
|
49
|
+
|
|
50
|
+
const middlewares: MiddlewareCallable[] = [
|
|
51
|
+
...controllerMeta.middlewares['@'] || [],
|
|
52
|
+
...controllerMeta.middlewares[routeMeta.propertyKey] || []
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
if (middlewares.length > 0) await middlewareCompose(middlewares)(ctx)
|
|
56
|
+
|
|
57
|
+
return instance[routeMeta.propertyKey](...args)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {Route} from '@/core/router'
|
|
2
|
+
|
|
3
|
+
export class RouteMatcher {
|
|
4
|
+
protected routes = new Map<string, Route>()
|
|
5
|
+
|
|
6
|
+
protected getKey(route: Route): string {
|
|
7
|
+
return `${route.method}:${route.path}`
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
add(route: Route): this {
|
|
11
|
+
this.routes.set(this.getKey(route), route)
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
has(route: Route): boolean {
|
|
16
|
+
return this.routes.has(this.getKey(route))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
find(route: Route): Route | undefined {
|
|
20
|
+
return this.routes.get(this.getKey(route))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
replace(route: Route): this {
|
|
24
|
+
if (this.has(route)) {
|
|
25
|
+
this.routes.set(this.getKey(route), route)
|
|
26
|
+
}
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
upsert(route: Route): this {
|
|
31
|
+
this.routes.set(this.getKey(route), route)
|
|
32
|
+
return this
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
remove(route: Route): this {
|
|
36
|
+
this.routes.delete(this.getKey(route))
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
match(method: string, url: string): Route | null {
|
|
41
|
+
for (const route of this.routes.values())
|
|
42
|
+
if (route.match(method, url))
|
|
43
|
+
return route.extractParams(url)
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
clear(): this {
|
|
48
|
+
this.routes.clear()
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type {RouteDefinition} from '@/types/router'
|
|
2
|
+
|
|
3
|
+
export class Route {
|
|
4
|
+
method: string
|
|
5
|
+
path: string
|
|
6
|
+
version?: string
|
|
7
|
+
handler: RouteDefinition['handler']
|
|
8
|
+
parameters: Record<string, string> = {}
|
|
9
|
+
|
|
10
|
+
constructor(def: RouteDefinition) {
|
|
11
|
+
this.method = def.method
|
|
12
|
+
this.path = def.path
|
|
13
|
+
this.version = def.version
|
|
14
|
+
this.handler = def.handler
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get params(): string[] {
|
|
18
|
+
const fullPath = this.version ? `/${this.version}${this.path}` : this.path
|
|
19
|
+
const matches = fullPath.match(/:[a-zA-Z0-9_]+/g)
|
|
20
|
+
return matches ? matches.map(m => m.substring(1)) : []
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get name(): string {
|
|
24
|
+
return this.handler.name
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
extractParams(url: string): this {
|
|
28
|
+
const fullPath = (this.version ? `/${this.version}${this.path}` : this.path)
|
|
29
|
+
.replace(/\/+$/, '')
|
|
30
|
+
const paramNames = this.params
|
|
31
|
+
if (paramNames.length === 0) return this
|
|
32
|
+
|
|
33
|
+
const regexPath = fullPath.replace(/:[a-zA-Z0-9_]+/g, '([^/]+)')
|
|
34
|
+
const regex = new RegExp(`^${regexPath || '/'}/?$`)
|
|
35
|
+
const matches = url.match(regex)
|
|
36
|
+
|
|
37
|
+
if (matches) {
|
|
38
|
+
const params: Record<string, string> = {}
|
|
39
|
+
paramNames.forEach((name, index) => {
|
|
40
|
+
params[name] = matches[index + 1]
|
|
41
|
+
})
|
|
42
|
+
this.parameters = params
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return this
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
match(method: string, url: string): boolean {
|
|
49
|
+
if (method !== this.method) return false
|
|
50
|
+
|
|
51
|
+
const fullPath = (this.version ? `/${this.version}${this.path}` : this.path)
|
|
52
|
+
.replace(/\/+$/, '')
|
|
53
|
+
const cleanUrl = url.replace(/\/+$/, '')
|
|
54
|
+
|
|
55
|
+
if (!fullPath.includes(':')) {
|
|
56
|
+
return (fullPath || '/') === (cleanUrl || '/')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const regexPath = fullPath.replace(/:[a-zA-Z0-9_]+/g, '([^/]+)')
|
|
60
|
+
const regex = new RegExp(`^${regexPath || '/'}/?$`)
|
|
61
|
+
return regex.test(url)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {RouteHandler} from '@/types'
|
|
2
|
+
import {HttpMethod} from "@/sdk/enums";
|
|
3
|
+
import {Route} from '@/core/router/route'
|
|
4
|
+
import {RouteMatcher} from '@/core/router/matcher'
|
|
5
|
+
|
|
6
|
+
export class Router {
|
|
7
|
+
private matcher = new RouteMatcher()
|
|
8
|
+
|
|
9
|
+
add(method: HttpMethod, path: string, handler: RouteHandler, version?: string) {
|
|
10
|
+
const route = new Route({
|
|
11
|
+
method,
|
|
12
|
+
path,
|
|
13
|
+
handler,
|
|
14
|
+
version
|
|
15
|
+
})
|
|
16
|
+
this.matcher.add(route)
|
|
17
|
+
return route
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
remove(route: Route) {
|
|
21
|
+
this.matcher.remove(route)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
match(method: string, url: string) {
|
|
25
|
+
return this.matcher.match(method, url)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
reset() {
|
|
29
|
+
this.matcher.clear()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {ServerInterface, ServerOptions} from "@/types";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export class Server implements ServerInterface {
|
|
5
|
+
|
|
6
|
+
protected static _instance?: Server;
|
|
7
|
+
|
|
8
|
+
static get instance(): Server | undefined {
|
|
9
|
+
return this._instance
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static set instance(value: Server) {
|
|
13
|
+
this._instance = this._instance || value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
public readonly options: ServerOptions
|
|
18
|
+
) {
|
|
19
|
+
Server.instance = this;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
option<K extends keyof ServerOptions>(key: K): ServerOptions[K] {
|
|
23
|
+
return this.options[key];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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 {Throwable} from "@/sdk/throwable";
|
|
17
|
+
import {ControllerBuilder} from "@/core/controller";
|
|
18
|
+
import {bodyParserPlugin} from "@/sdk/plugins/body-parser.plugin";
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export class RaitonThread implements ThreadInterface {
|
|
22
|
+
|
|
23
|
+
protected static instance: RaitonThread | null = null;
|
|
24
|
+
|
|
25
|
+
public static get current(): RaitonThread {
|
|
26
|
+
if (!RaitonThread.instance) throw new Throwable('Thread not initialized')
|
|
27
|
+
return RaitonThread.instance;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public application: ApplicationInterface | null = null;
|
|
31
|
+
public runtime: RuntimeAdapterInterface | null = null;
|
|
32
|
+
public runtimeServer: RuntimeServerInterface | null = null;
|
|
33
|
+
|
|
34
|
+
readonly appDir: string;
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
public readonly builder: BuilderInterface,
|
|
38
|
+
protected _options: ThreadOptions = {}
|
|
39
|
+
) {
|
|
40
|
+
this.appDir = process.cwd();
|
|
41
|
+
RaitonThread.instance = this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public restart(): void {
|
|
45
|
+
process.send?.(EventMessageEnum.RESTART)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public stop(): void {
|
|
49
|
+
process.exit(0)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public async sleep(milliseconds: number): Promise<unknown> {
|
|
53
|
+
return await ProcessUtility.sleep(milliseconds);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public async wait(condition: ThreadWaitCallable): Promise<void> {
|
|
57
|
+
return await until(condition)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public setup({application, runtime}: ThreadSetupOptions): this {
|
|
61
|
+
const defaultRuntime = typeof Bun !== 'undefined' ? RuntimeType.Bun : RuntimeType.Node;
|
|
62
|
+
this.runtime = new Runtime(runtime || defaultRuntime);
|
|
63
|
+
this.application = application;
|
|
64
|
+
this.application.use(bodyParserPlugin())
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async run(): Promise<this> {
|
|
69
|
+
|
|
70
|
+
if (!this.application)
|
|
71
|
+
throw new Throwable('Application not defined');
|
|
72
|
+
|
|
73
|
+
if (!this.runtime)
|
|
74
|
+
throw new Throwable('Runtime not defined');
|
|
75
|
+
|
|
76
|
+
const port = this.application.config.port || 5712;
|
|
77
|
+
|
|
78
|
+
this.runtimeServer = this.runtime.createServer(this.application.handle.bind(this.application))
|
|
79
|
+
|
|
80
|
+
await this.runtimeServer.listen(port)
|
|
81
|
+
if (this.builder.out)
|
|
82
|
+
await ControllerBuilder.scan(this.builder.out)
|
|
83
|
+
|
|
84
|
+
Logger.log(LBadge.info('Server Started'), `http://localhost:${port}`)
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
}
|
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
|
+
});
|