raiton 3.0.2 → 3.1.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 +15 -15
- package/README.md +1 -1
- package/build/bin/index.mjs +240 -2
- package/package.json +3 -4
- package/scripts/update-version.ts +5 -5
- package/source/bin/cli.ts +1 -1
- package/source/commands/artifact.command.ts +2 -2
- package/source/commands/build.command.ts +2 -2
- package/source/core/application.ts +19 -14
- package/source/core/builder.ts +2 -2
- package/source/core/bytes.util.ts +2 -2
- package/source/core/config/config.ts +7 -7
- package/source/core/config/define.ts +3 -3
- package/source/core/controller/builder.ts +2 -2
- package/source/core/guards.ts +43 -0
- package/source/core/hooks.ts +4 -4
- package/source/core/injection/injection.ts +6 -5
- package/source/core/plugins/plugin.ts +3 -3
- package/source/core/raiton.ts +2 -2
- package/source/core/router/route.ts +3 -3
- package/source/core/router/router.ts +2 -2
- package/source/core/server.ts +3 -3
- package/source/core/thread.ts +6 -5
- package/source/sdk/artifacts.ts +2 -2
- package/source/sdk/decorators/guard.decorator.ts +23 -0
- package/source/sdk/decorators/index.ts +2 -1
- package/source/sdk/decorators/injection.decorator.ts +2 -2
- package/source/sdk/decorators/parametrable.ts +2 -2
- package/source/sdk/encryption.ts +15 -15
- package/source/sdk/env.ts +5 -5
- package/source/sdk/plugins/body-parser.plugin.ts +3 -3
- package/source/sdk/plugins/security/body-limit.ts +2 -2
- package/source/sdk/plugins/security/cors.ts +2 -2
- package/source/sdk/plugins/security/headers.ts +2 -2
- package/source/sdk/plugins/security/method-guard.ts +2 -2
- package/source/sdk/plugins/security/rate-limit.ts +2 -2
- package/source/sdk/utilities/utilities.util.ts +2 -2
- package/source/types/application.ts +4 -4
- package/source/types/artifact.ts +2 -43
- package/source/types/builder.ts +5 -5
- package/source/types/config.ts +3 -3
- package/source/types/controller.ts +4 -4
- package/source/types/contruct.ts +1 -1
- package/source/types/core.ts +3 -5
- package/source/types/directory.ts +1 -1
- package/source/types/encryption.ts +21 -12
- package/source/types/generic.ts +2 -2
- package/source/types/guard.ts +12 -0
- package/source/types/index.ts +1 -3
- package/source/types/injection.ts +2 -2
- package/source/types/lifecycle.ts +3 -3
- package/source/types/middleware.ts +4 -4
- package/source/types/plugin.ts +3 -5
- package/source/types/raiton.ts +3 -3
- package/source/types/responses.ts +9 -6
- package/source/types/router.ts +3 -3
- package/source/types/server.ts +3 -3
- package/source/types/thread.ts +3 -3
- package/source/types/utilities.ts +1 -1
- package/source/types/values.ts +2 -2
- package/source/types/access-guards.ts +0 -4
- package/source/types/http-responses.ts +0 -8
- package/source/types/scheme.ts +0 -153
package/CHANGELOG.md
CHANGED
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
|
|
20
20
|
* add `IGlobalGrafts` interface definition ([72585ed](https://github.com/protorians/raiton/commit/72585ed24c3c1b4e84626fca92ad9d9303a33061))
|
|
21
21
|
* add CLI commands and bootstrap logic for the `Raiton` framework ([61d6565](https://github.com/protorians/raiton/commit/61d6565e6b6f4f2eaeaf65e2878c0f24936bfd68))
|
|
22
|
-
* add constants for
|
|
23
|
-
* add enums for
|
|
22
|
+
* add constants for framework modularization ([98bae11](https://github.com/protorians/raiton/commit/98bae1177e2b458a1e1925e151f1844db50b78c5))
|
|
23
|
+
* add enums for framework modularization ([087864f](https://github.com/protorians/raiton/commit/087864f89f8a5d87746f5595ca3c148145473044))
|
|
24
24
|
* add process event handling and environment configuration setup ([93fc142](https://github.com/protorians/raiton/commit/93fc142bde480cd166e1f2681644768692fcecf7))
|
|
25
25
|
* add Swagger HTML page plugin for API documentation ([d287757](https://github.com/protorians/raiton/commit/d2877576d7a310ba814aa7c4b7790271582a20bf))
|
|
26
26
|
* add type definitions for core application structures ([c756482](https://github.com/protorians/raiton/commit/c75648245c7f7e2f2d25350c04e2dc0e4f5e3109))
|
|
27
|
-
* add utility functions for
|
|
27
|
+
* add utility functions for framework ([b947207](https://github.com/protorians/raiton/commit/b947207afe37e9a876fe6f86facc081ce4fbb0de))
|
|
28
28
|
* implement core modules for `Raiton` framework ([89c1288](https://github.com/protorians/raiton/commit/89c12886a300015da603cda57f9dbbcd5394962a))
|
|
29
|
-
* implement
|
|
29
|
+
* implement framework core modules and utilities ([085da37](https://github.com/protorians/raiton/commit/085da37d03399f1732d463763302d67df85848b1))
|
|
30
30
|
* integrate `bodyParserPlugin` into application setup, refine `ControllerMeta` structure, and clean up router handler logging ([3dc29b9](https://github.com/protorians/raiton/commit/3dc29b9d203fd1d56cd22de65f58dc6c9353566a))
|
|
31
|
-
* introduce decorators for
|
|
31
|
+
* introduce decorators for framework modularization ([e90e5fb](https://github.com/protorians/raiton/commit/e90e5fb017325115594985844328ac4d0542ccc5))
|
|
32
32
|
|
|
33
33
|
## [0.0.2](https://github.com/protorians/raiton/compare/v0.0.1...v0.0.2) (2025-12-30)
|
|
34
34
|
|
|
@@ -90,16 +90,16 @@
|
|
|
90
90
|
|
|
91
91
|
* add `IGlobalGrafts` interface definition ([72585ed](https://github.com/protorians/raiton/commit/72585ed24c3c1b4e84626fca92ad9d9303a33061))
|
|
92
92
|
* add CLI commands and bootstrap logic for the `Raiton` framework ([61d6565](https://github.com/protorians/raiton/commit/61d6565e6b6f4f2eaeaf65e2878c0f24936bfd68))
|
|
93
|
-
* add constants for
|
|
94
|
-
* add enums for
|
|
93
|
+
* add constants for framework modularization ([98bae11](https://github.com/protorians/raiton/commit/98bae1177e2b458a1e1925e151f1844db50b78c5))
|
|
94
|
+
* add enums for framework modularization ([087864f](https://github.com/protorians/raiton/commit/087864f89f8a5d87746f5595ca3c148145473044))
|
|
95
95
|
* add process event handling and environment configuration setup ([93fc142](https://github.com/protorians/raiton/commit/93fc142bde480cd166e1f2681644768692fcecf7))
|
|
96
96
|
* add Swagger HTML page plugin for API documentation ([d287757](https://github.com/protorians/raiton/commit/d2877576d7a310ba814aa7c4b7790271582a20bf))
|
|
97
97
|
* add type definitions for core application structures ([c756482](https://github.com/protorians/raiton/commit/c75648245c7f7e2f2d25350c04e2dc0e4f5e3109))
|
|
98
|
-
* add utility functions for
|
|
98
|
+
* add utility functions for framework ([b947207](https://github.com/protorians/raiton/commit/b947207afe37e9a876fe6f86facc081ce4fbb0de))
|
|
99
99
|
* implement core modules for `Raiton` framework ([89c1288](https://github.com/protorians/raiton/commit/89c12886a300015da603cda57f9dbbcd5394962a))
|
|
100
|
-
* implement
|
|
100
|
+
* implement framework core modules and utilities ([085da37](https://github.com/protorians/raiton/commit/085da37d03399f1732d463763302d67df85848b1))
|
|
101
101
|
* integrate `bodyParserPlugin` into application setup, refine `ControllerMeta` structure, and clean up router handler logging ([3dc29b9](https://github.com/protorians/raiton/commit/3dc29b9d203fd1d56cd22de65f58dc6c9353566a))
|
|
102
|
-
* introduce decorators for
|
|
102
|
+
* introduce decorators for framework modularization ([e90e5fb](https://github.com/protorians/raiton/commit/e90e5fb017325115594985844328ac4d0542ccc5))
|
|
103
103
|
|
|
104
104
|
# [1.0.0-alpha.4](https://github.com/protorians/raiton/compare/v1.0.0-alpha.3...v1.0.0-alpha.4) (2025-12-30)
|
|
105
105
|
|
|
@@ -127,15 +127,15 @@
|
|
|
127
127
|
|
|
128
128
|
* add `IGlobalGrafts` interface definition ([72585ed](https://github.com/protorians/raiton/commit/72585ed24c3c1b4e84626fca92ad9d9303a33061))
|
|
129
129
|
* add CLI commands and bootstrap logic for the `Raiton` framework ([61d6565](https://github.com/protorians/raiton/commit/61d6565e6b6f4f2eaeaf65e2878c0f24936bfd68))
|
|
130
|
-
* add constants for
|
|
131
|
-
* add enums for
|
|
130
|
+
* add constants for framework modularization ([98bae11](https://github.com/protorians/raiton/commit/98bae1177e2b458a1e1925e151f1844db50b78c5))
|
|
131
|
+
* add enums for framework modularization ([087864f](https://github.com/protorians/raiton/commit/087864f89f8a5d87746f5595ca3c148145473044))
|
|
132
132
|
* add process event handling and environment configuration setup ([93fc142](https://github.com/protorians/raiton/commit/93fc142bde480cd166e1f2681644768692fcecf7))
|
|
133
133
|
* add Swagger HTML page plugin for API documentation ([d287757](https://github.com/protorians/raiton/commit/d2877576d7a310ba814aa7c4b7790271582a20bf))
|
|
134
134
|
* add type definitions for core application structures ([c756482](https://github.com/protorians/raiton/commit/c75648245c7f7e2f2d25350c04e2dc0e4f5e3109))
|
|
135
|
-
* add utility functions for
|
|
135
|
+
* add utility functions for framework ([b947207](https://github.com/protorians/raiton/commit/b947207afe37e9a876fe6f86facc081ce4fbb0de))
|
|
136
136
|
* implement core modules for `Raiton` framework ([89c1288](https://github.com/protorians/raiton/commit/89c12886a300015da603cda57f9dbbcd5394962a))
|
|
137
|
-
* implement
|
|
138
|
-
* introduce decorators for
|
|
137
|
+
* implement framework core modules and utilities ([085da37](https://github.com/protorians/raiton/commit/085da37d03399f1732d463763302d67df85848b1))
|
|
138
|
+
* introduce decorators for framework modularization ([e90e5fb](https://github.com/protorians/raiton/commit/e90e5fb017325115594985844328ac4d0542ccc5))
|
|
139
139
|
|
|
140
140
|
# 1.0.0-alpha.1 (2025-12-04)
|
|
141
141
|
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/raiton)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
**Protorians Raiton** est un
|
|
6
|
+
**Protorians Raiton** est un framework backend moderne et performant,
|
|
7
7
|
conçu pour construire des microservices TypeScript. Optimisé pour **Bun**,
|
|
8
8
|
il offre également un support complet pour **Node.js** et **Deno**.
|
|
9
9
|
|
package/build/bin/index.mjs
CHANGED
|
@@ -4817,11 +4817,11 @@ var {
|
|
|
4817
4817
|
Help
|
|
4818
4818
|
} = import__.default;
|
|
4819
4819
|
// package.json
|
|
4820
|
-
var version = "3.0
|
|
4820
|
+
var version = "3.1.0";
|
|
4821
4821
|
|
|
4822
4822
|
// source/bin/cli.ts
|
|
4823
4823
|
var CLI = new Command;
|
|
4824
|
-
CLI.name("raiton").description("Protorians Raiton
|
|
4824
|
+
CLI.name("raiton").description("Protorians Raiton framework for backend microservice").version(version);
|
|
4825
4825
|
var cli_default = CLI;
|
|
4826
4826
|
|
|
4827
4827
|
// source/core/config/config.ts
|
|
@@ -6369,6 +6369,7 @@ class Injection {
|
|
|
6369
6369
|
return this._classes.has(this.normalizeName(name));
|
|
6370
6370
|
}
|
|
6371
6371
|
static clear() {
|
|
6372
|
+
Logger.error("Clearing injection container");
|
|
6372
6373
|
this._classes.clear();
|
|
6373
6374
|
this._instances.clear();
|
|
6374
6375
|
this._dependents.clear();
|
|
@@ -6524,6 +6525,42 @@ class Injection {
|
|
|
6524
6525
|
return this.get(metadata.name);
|
|
6525
6526
|
}
|
|
6526
6527
|
}
|
|
6528
|
+
// source/core/guards.ts
|
|
6529
|
+
class RaitonGuards {
|
|
6530
|
+
static _map = new Map;
|
|
6531
|
+
static set(name, guard) {
|
|
6532
|
+
this._map.set(name, guard);
|
|
6533
|
+
return this;
|
|
6534
|
+
}
|
|
6535
|
+
static get(name) {
|
|
6536
|
+
return this._map.get(name);
|
|
6537
|
+
}
|
|
6538
|
+
static remove(name) {
|
|
6539
|
+
this._map.delete(name);
|
|
6540
|
+
return this;
|
|
6541
|
+
}
|
|
6542
|
+
static removeAll() {
|
|
6543
|
+
Logger.error("Removing all guards");
|
|
6544
|
+
this._map.clear();
|
|
6545
|
+
return this;
|
|
6546
|
+
}
|
|
6547
|
+
static enabled(name) {
|
|
6548
|
+
const guard = this.get(name);
|
|
6549
|
+
return !guard ? false : guard.enabled;
|
|
6550
|
+
}
|
|
6551
|
+
static enable(name) {
|
|
6552
|
+
const guard = this.get(name);
|
|
6553
|
+
if (guard)
|
|
6554
|
+
guard.enabled = true;
|
|
6555
|
+
return this;
|
|
6556
|
+
}
|
|
6557
|
+
static disable(name) {
|
|
6558
|
+
const guard = this.get(name);
|
|
6559
|
+
if (guard)
|
|
6560
|
+
guard.enabled = false;
|
|
6561
|
+
return this;
|
|
6562
|
+
}
|
|
6563
|
+
}
|
|
6527
6564
|
// source/sdk/responses/http.ts
|
|
6528
6565
|
class HttpResponse {
|
|
6529
6566
|
response;
|
|
@@ -6649,6 +6686,59 @@ class HookStore {
|
|
|
6649
6686
|
return store;
|
|
6650
6687
|
}
|
|
6651
6688
|
}
|
|
6689
|
+
|
|
6690
|
+
// source/core/middleware/compose.ts
|
|
6691
|
+
function middlewareCompose(middlewares) {
|
|
6692
|
+
return function(request) {
|
|
6693
|
+
let index = -1;
|
|
6694
|
+
return dispatch(0);
|
|
6695
|
+
async function dispatch(i) {
|
|
6696
|
+
if (i <= index) {
|
|
6697
|
+
return Promise.reject(new Throwable("next() called multiple times"));
|
|
6698
|
+
}
|
|
6699
|
+
index = i;
|
|
6700
|
+
const fn = middlewares[i];
|
|
6701
|
+
try {
|
|
6702
|
+
if (!fn)
|
|
6703
|
+
return Promise.resolve();
|
|
6704
|
+
if (typeof fn === "function") {
|
|
6705
|
+
return Promise.resolve(fn({ context: request, next: () => dispatch(i + 1) }));
|
|
6706
|
+
}
|
|
6707
|
+
if (typeof fn === "object" && "setup" in fn && typeof fn.setup == "function") {
|
|
6708
|
+
if (fn.setup.length === 1) {
|
|
6709
|
+
await Promise.resolve(fn.setup(request));
|
|
6710
|
+
return await dispatch(i + 1);
|
|
6711
|
+
}
|
|
6712
|
+
return Promise.resolve(fn.setup(request, () => dispatch(i + 1)));
|
|
6713
|
+
}
|
|
6714
|
+
return Promise.resolve();
|
|
6715
|
+
} catch (err) {
|
|
6716
|
+
return Promise.reject(err);
|
|
6717
|
+
}
|
|
6718
|
+
}
|
|
6719
|
+
};
|
|
6720
|
+
}
|
|
6721
|
+
// source/core/middleware/pipeline.ts
|
|
6722
|
+
class MiddlewarePipeline {
|
|
6723
|
+
stack = [];
|
|
6724
|
+
use(mw) {
|
|
6725
|
+
this.stack.push(mw);
|
|
6726
|
+
return this;
|
|
6727
|
+
}
|
|
6728
|
+
clear() {
|
|
6729
|
+
this.stack = [];
|
|
6730
|
+
return this;
|
|
6731
|
+
}
|
|
6732
|
+
run(ctx) {
|
|
6733
|
+
const fn = middlewareCompose(this.stack);
|
|
6734
|
+
return typeof fn == "function" ? fn(ctx) : undefined;
|
|
6735
|
+
}
|
|
6736
|
+
clone() {
|
|
6737
|
+
const pipeline = new MiddlewarePipeline;
|
|
6738
|
+
pipeline.stack = [...this.stack];
|
|
6739
|
+
return pipeline;
|
|
6740
|
+
}
|
|
6741
|
+
}
|
|
6652
6742
|
// source/core/router/route.ts
|
|
6653
6743
|
class Route {
|
|
6654
6744
|
method;
|
|
@@ -6764,6 +6854,37 @@ class Router {
|
|
|
6764
6854
|
this.matcher.clear();
|
|
6765
6855
|
}
|
|
6766
6856
|
}
|
|
6857
|
+
// source/core/plugins/scope.ts
|
|
6858
|
+
class PluginScope {
|
|
6859
|
+
hooks;
|
|
6860
|
+
middleware;
|
|
6861
|
+
router;
|
|
6862
|
+
constructor(parent) {
|
|
6863
|
+
this.hooks = parent ? parent.hooks.clone() : new HookStore;
|
|
6864
|
+
this.middleware = parent ? parent.middleware.clone() : new MiddlewarePipeline;
|
|
6865
|
+
this.router = parent ? parent.router : new Router;
|
|
6866
|
+
}
|
|
6867
|
+
addHook(name, fn) {
|
|
6868
|
+
this.hooks.add(name, fn);
|
|
6869
|
+
return this;
|
|
6870
|
+
}
|
|
6871
|
+
use(mw) {
|
|
6872
|
+
if (typeof mw === "object" && mw !== null && "setup" in mw && typeof mw.setup === "function" && mw.setup.length === 1) {
|
|
6873
|
+
mw.setup(this);
|
|
6874
|
+
return this;
|
|
6875
|
+
}
|
|
6876
|
+
this.middleware.use(mw);
|
|
6877
|
+
return this;
|
|
6878
|
+
}
|
|
6879
|
+
route(method, path5, handler2, version2) {
|
|
6880
|
+
return this.router.add(method, path5, handler2, version2);
|
|
6881
|
+
}
|
|
6882
|
+
register(plugin) {
|
|
6883
|
+
const child = new PluginScope(this);
|
|
6884
|
+
plugin.setup(child);
|
|
6885
|
+
return child;
|
|
6886
|
+
}
|
|
6887
|
+
}
|
|
6767
6888
|
// source/core/plugins/plugin.ts
|
|
6768
6889
|
function definePlugin(setup, name) {
|
|
6769
6890
|
return { setup, name };
|
|
@@ -6934,6 +7055,123 @@ class RequestContext {
|
|
|
6934
7055
|
this.reply.send(body);
|
|
6935
7056
|
}
|
|
6936
7057
|
}
|
|
7058
|
+
|
|
7059
|
+
// source/core/application.ts
|
|
7060
|
+
class Application {
|
|
7061
|
+
config;
|
|
7062
|
+
root;
|
|
7063
|
+
version = RaitonConfig.get("version") || "0.0.1";
|
|
7064
|
+
container = Injection;
|
|
7065
|
+
constructor(config2) {
|
|
7066
|
+
this.config = config2;
|
|
7067
|
+
this.root = new PluginScope;
|
|
7068
|
+
if (this.config.workdir) {
|
|
7069
|
+
process.chdir(this.config.workdir);
|
|
7070
|
+
}
|
|
7071
|
+
this.initialize();
|
|
7072
|
+
}
|
|
7073
|
+
initialize() {
|
|
7074
|
+
const artifacts = RaitonConfig.get("artifacts");
|
|
7075
|
+
const artifactTypes = [...artifacts?.types || [], ...Artifacts.defaultTypes];
|
|
7076
|
+
Artifacts.registerMany(...artifactTypes);
|
|
7077
|
+
return this;
|
|
7078
|
+
}
|
|
7079
|
+
get hostname() {
|
|
7080
|
+
return `${this.config.protocole || "http"}://${this.config.hostname || "localhost"}${this.config.port ? `:${this.config.port}` : ""}${this.config.pathname || "/"}`;
|
|
7081
|
+
}
|
|
7082
|
+
setOption(key, value) {
|
|
7083
|
+
this.config[key] = value;
|
|
7084
|
+
return this;
|
|
7085
|
+
}
|
|
7086
|
+
setOptions(options) {
|
|
7087
|
+
Object.assign(this.config, options);
|
|
7088
|
+
return this;
|
|
7089
|
+
}
|
|
7090
|
+
register(plugin2) {
|
|
7091
|
+
this.root.register(plugin2);
|
|
7092
|
+
return this;
|
|
7093
|
+
}
|
|
7094
|
+
use(mw) {
|
|
7095
|
+
this.root.use(mw);
|
|
7096
|
+
return this;
|
|
7097
|
+
}
|
|
7098
|
+
route(method, path6, handler2, version2) {
|
|
7099
|
+
const prefix = this.config.prefix ?? "";
|
|
7100
|
+
const fullPath = `${prefix}${path6}`.replace(/\/+/g, "/") || "/";
|
|
7101
|
+
this.root.route(method, fullPath, handler2, version2);
|
|
7102
|
+
return this;
|
|
7103
|
+
}
|
|
7104
|
+
get(path6, handler2, version2) {
|
|
7105
|
+
return this.route("GET" /* GET */, path6, handler2, version2);
|
|
7106
|
+
}
|
|
7107
|
+
post(path6, handler2, version2) {
|
|
7108
|
+
return this.route("POST" /* POST */, path6, handler2, version2);
|
|
7109
|
+
}
|
|
7110
|
+
patch(path6, handler2, version2) {
|
|
7111
|
+
return this.route("PATCH" /* PATCH */, path6, handler2, version2);
|
|
7112
|
+
}
|
|
7113
|
+
put(path6, handler2, version2) {
|
|
7114
|
+
return this.route("PUT" /* PUT */, path6, handler2, version2);
|
|
7115
|
+
}
|
|
7116
|
+
delete(path6, handler2, version2) {
|
|
7117
|
+
return this.route("DELETE" /* DELETE */, path6, handler2, version2);
|
|
7118
|
+
}
|
|
7119
|
+
options(path6, handler2, version2) {
|
|
7120
|
+
return this.route("OPTIONS" /* OPTIONS */, path6, handler2, version2);
|
|
7121
|
+
}
|
|
7122
|
+
head(path6, handler2, version2) {
|
|
7123
|
+
return this.route("HEAD" /* HEAD */, path6, handler2, version2);
|
|
7124
|
+
}
|
|
7125
|
+
trace(path6, handler2, version2) {
|
|
7126
|
+
return this.route("TRACE" /* TRACE */, path6, handler2, version2);
|
|
7127
|
+
}
|
|
7128
|
+
async handle(req, reply) {
|
|
7129
|
+
const ctx = new RequestContext(req, reply);
|
|
7130
|
+
if (this.config.verbose) {
|
|
7131
|
+
Logger.info(`Incoming request: ${req.method} ${req.url}`);
|
|
7132
|
+
}
|
|
7133
|
+
await this.root.hooks.run("onRequest", ctx);
|
|
7134
|
+
const url = new URL(req.url, this.hostname);
|
|
7135
|
+
let pathname = url.pathname;
|
|
7136
|
+
if (this.config.pathname && this.config.pathname !== "/") {
|
|
7137
|
+
const appPathname = this.config.pathname.endsWith("/") ? this.config.pathname : `${this.config.pathname}/`;
|
|
7138
|
+
if (pathname.startsWith(appPathname)) {
|
|
7139
|
+
pathname = pathname.substring(appPathname.length - 1) || "/";
|
|
7140
|
+
} else if (pathname === this.config.pathname) {
|
|
7141
|
+
pathname = "/";
|
|
7142
|
+
} else {
|
|
7143
|
+
if (this.config.verbose) {
|
|
7144
|
+
Logger.warn(`Request out of application pathname: ${pathname} (expected prefix: ${this.config.pathname})`);
|
|
7145
|
+
}
|
|
7146
|
+
reply.status(404);
|
|
7147
|
+
return reply.send({ error: false, statusCode: 404 });
|
|
7148
|
+
}
|
|
7149
|
+
}
|
|
7150
|
+
const route2 = this.root.router.match(req.method, pathname);
|
|
7151
|
+
if (!route2) {
|
|
7152
|
+
if (this.config.verbose) {
|
|
7153
|
+
Logger.warn(`Route not found: ${req.method} ${pathname}`);
|
|
7154
|
+
}
|
|
7155
|
+
reply.status(404);
|
|
7156
|
+
return reply.send({ error: false, statusCode: 404 });
|
|
7157
|
+
}
|
|
7158
|
+
const pipeline2 = this.root.middleware.clone();
|
|
7159
|
+
pipeline2.use(async ({ context }) => {
|
|
7160
|
+
try {
|
|
7161
|
+
context.params = route2.parameters;
|
|
7162
|
+
let responses2 = await route2.handler(context);
|
|
7163
|
+
context.reply.send(responses2);
|
|
7164
|
+
} catch (e) {
|
|
7165
|
+
Logger.error("Failed to handle request", e.message ?? e);
|
|
7166
|
+
if (this.config.develop) {
|
|
7167
|
+
console.error(e);
|
|
7168
|
+
}
|
|
7169
|
+
}
|
|
7170
|
+
});
|
|
7171
|
+
await pipeline2.run(ctx);
|
|
7172
|
+
await this.root.hooks.run("onResponse", ctx);
|
|
7173
|
+
}
|
|
7174
|
+
}
|
|
6937
7175
|
// source/bin/cli-tools.ts
|
|
6938
7176
|
import { spawn } from "node:child_process";
|
|
6939
7177
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "raiton",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "Modular TypeScript Backend Framework with Dependency Injection, Plugins, Controllers, Middleware and Hot Reloading.",
|
|
7
7
|
"main": "./source/core/index.ts",
|
|
8
8
|
"module": "./source/core/index.ts",
|
|
9
9
|
"types": "./source/core/index.d.ts",
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
"keywords": [
|
|
14
14
|
"protorians",
|
|
15
15
|
"raiton",
|
|
16
|
-
"
|
|
17
|
-
"kit",
|
|
16
|
+
"framework",
|
|
18
17
|
"typescript",
|
|
19
18
|
"node",
|
|
20
19
|
"bun",
|
|
@@ -24,12 +24,12 @@ function determineIncrement(commits: string[]) {
|
|
|
24
24
|
let increment: "major" | "minor" | "patch" | null = null;
|
|
25
25
|
|
|
26
26
|
for (let commit of commits) {
|
|
27
|
-
commit = commit.trim();
|
|
27
|
+
commit = commit.trim().toLowerCase();
|
|
28
28
|
if (
|
|
29
|
-
commit.includes("
|
|
29
|
+
commit.includes("breaking change") ||
|
|
30
30
|
commit.includes("!") ||
|
|
31
|
-
commit.
|
|
32
|
-
commit.
|
|
31
|
+
commit.startsWith("release") ||
|
|
32
|
+
commit.startsWith("upgrade")
|
|
33
33
|
) {
|
|
34
34
|
return "major";
|
|
35
35
|
}
|
|
@@ -42,7 +42,7 @@ function determineIncrement(commits: string[]) {
|
|
|
42
42
|
!increment &&
|
|
43
43
|
commit.startsWith("fix") ||
|
|
44
44
|
commit.startsWith("update") ||
|
|
45
|
-
commit.
|
|
45
|
+
commit.startsWith("remove")
|
|
46
46
|
) {
|
|
47
47
|
increment = "patch";
|
|
48
48
|
}
|
package/source/bin/cli.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {RaitonCommand, RaitonBuilder} from "../core";
|
|
2
2
|
import {Logger} from "@protorians/logger";
|
|
3
|
-
import type {
|
|
3
|
+
import type {BuildCommandOptionsInterface} from "../types";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export default class ArtifactCommand extends RaitonCommand {
|
|
@@ -19,7 +19,7 @@ export default class ArtifactCommand extends RaitonCommand {
|
|
|
19
19
|
.action(this.run.bind(this));
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
protected async run(options:
|
|
22
|
+
protected async run(options: BuildCommandOptionsInterface): Promise<void> {
|
|
23
23
|
|
|
24
24
|
Logger.notice("Artifact management is not yet implemented");
|
|
25
25
|
Logger.debug('Options:', options, '')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {RaitonCommand, RaitonBuilder} from "../core";
|
|
2
2
|
import {LBadge, Logger} from "@protorians/logger";
|
|
3
|
-
import type {
|
|
3
|
+
import type {BuildCommandOptionsInterface} from "../types";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export default class BuildCommand extends RaitonCommand {
|
|
@@ -17,7 +17,7 @@ export default class BuildCommand extends RaitonCommand {
|
|
|
17
17
|
.action(this.run.bind(this));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
protected async run(options:
|
|
20
|
+
protected async run(options: BuildCommandOptionsInterface): Promise<void> {
|
|
21
21
|
if (options.develop) Logger.warn(LBadge.log("Dev Mode"),);
|
|
22
22
|
|
|
23
23
|
const builder = new RaitonBuilder(this.workdir, {
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import {PluginScope} from './plugins/scope'
|
|
2
2
|
import {RequestContext} from './context'
|
|
3
|
-
import {
|
|
3
|
+
import {ApplicationConfigInterface, ApplicationInterface} from "../types/application";
|
|
4
4
|
import {HttpMethod} from "../sdk";
|
|
5
|
-
import {
|
|
5
|
+
import {RouteHandlerCallable} from "../types";
|
|
6
6
|
import {Logger} from "@protorians/logger";
|
|
7
7
|
import {RaitonConfig} from "./config";
|
|
8
8
|
import {Artifacts} from "../sdk/artifacts";
|
|
9
|
+
import {Injection} from "./injection";
|
|
9
10
|
|
|
10
11
|
export class Application implements ApplicationInterface {
|
|
11
12
|
private root: PluginScope
|
|
12
13
|
|
|
14
|
+
readonly version: string = RaitonConfig.get('version') || '0.0.1'
|
|
15
|
+
|
|
16
|
+
readonly container: Injection = Injection;
|
|
17
|
+
|
|
13
18
|
constructor(
|
|
14
|
-
readonly config:
|
|
19
|
+
readonly config: ApplicationConfigInterface
|
|
15
20
|
) {
|
|
16
21
|
this.root = new PluginScope()
|
|
17
22
|
if (this.config.workdir) {
|
|
@@ -40,12 +45,12 @@ export class Application implements ApplicationInterface {
|
|
|
40
45
|
}`
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
public setOption<K extends keyof
|
|
48
|
+
public setOption<K extends keyof ApplicationConfigInterface>(key: K, value: ApplicationConfigInterface[K]): this {
|
|
44
49
|
this.config[key] = value;
|
|
45
50
|
return this;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
public setOptions(options:
|
|
53
|
+
public setOptions(options: ApplicationConfigInterface): this {
|
|
49
54
|
Object.assign(this.config, options);
|
|
50
55
|
return this;
|
|
51
56
|
}
|
|
@@ -60,42 +65,42 @@ export class Application implements ApplicationInterface {
|
|
|
60
65
|
return this
|
|
61
66
|
}
|
|
62
67
|
|
|
63
|
-
route(method: HttpMethod, path: string, handler:
|
|
68
|
+
route(method: HttpMethod, path: string, handler: RouteHandlerCallable, version?: string): this {
|
|
64
69
|
const prefix = this.config.prefix ?? ''
|
|
65
70
|
const fullPath = `${prefix}${path}`.replace(/\/+/g, '/') || '/'
|
|
66
71
|
this.root.route(method, fullPath, handler, version)
|
|
67
72
|
return this
|
|
68
73
|
}
|
|
69
74
|
|
|
70
|
-
get(path: string, handler:
|
|
75
|
+
get(path: string, handler: RouteHandlerCallable, version?: string): this {
|
|
71
76
|
return this.route(HttpMethod.GET, path, handler, version)
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
post(path: string, handler:
|
|
79
|
+
post(path: string, handler: RouteHandlerCallable, version?: string): this {
|
|
75
80
|
return this.route(HttpMethod.POST, path, handler, version)
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
patch(path: string, handler:
|
|
83
|
+
patch(path: string, handler: RouteHandlerCallable, version?: string): this {
|
|
79
84
|
return this.route(HttpMethod.PATCH, path, handler, version)
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
put(path: string, handler:
|
|
87
|
+
put(path: string, handler: RouteHandlerCallable, version?: string): this {
|
|
83
88
|
return this.route(HttpMethod.PUT, path, handler, version)
|
|
84
89
|
}
|
|
85
90
|
|
|
86
|
-
delete(path: string, handler:
|
|
91
|
+
delete(path: string, handler: RouteHandlerCallable, version?: string): this {
|
|
87
92
|
return this.route(HttpMethod.DELETE, path, handler, version)
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
options(path: string, handler:
|
|
95
|
+
options(path: string, handler: RouteHandlerCallable, version?: string): this {
|
|
91
96
|
return this.route(HttpMethod.OPTIONS, path, handler, version)
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
head(path: string, handler:
|
|
99
|
+
head(path: string, handler: RouteHandlerCallable, version?: string): this {
|
|
95
100
|
return this.route(HttpMethod.HEAD, path, handler, version)
|
|
96
101
|
}
|
|
97
102
|
|
|
98
|
-
trace(path: string, handler:
|
|
103
|
+
trace(path: string, handler: RouteHandlerCallable, version?: string): this {
|
|
99
104
|
return this.route(HttpMethod.TRACE, path, handler, version)
|
|
100
105
|
}
|
|
101
106
|
|
package/source/core/builder.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {RaitonConfig} from "./config";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import {RaitonDirectories} from "./directories";
|
|
4
4
|
import fs, {WatchEventType} from "node:fs";
|
|
5
|
-
import type {
|
|
5
|
+
import type {BuilderConfigInterface, BuilderInterface,} from "../types";
|
|
6
6
|
import {RaitonThread} from "./thread";
|
|
7
7
|
import {Raiton} from "./raiton";
|
|
8
8
|
import {isControllerArtifact, isServiceArtifact} from "../sdk";
|
|
@@ -24,7 +24,7 @@ export class RaitonBuilder implements BuilderInterface {
|
|
|
24
24
|
|
|
25
25
|
constructor(
|
|
26
26
|
public readonly workdir: string,
|
|
27
|
-
public readonly options:
|
|
27
|
+
public readonly options: BuilderConfigInterface = {},
|
|
28
28
|
) {
|
|
29
29
|
|
|
30
30
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {FileSizeFormatedInterface} from "../types";
|
|
2
2
|
|
|
3
|
-
export function parseBytes(bytes: number, decimals = 2):
|
|
3
|
+
export function parseBytes(bytes: number, decimals = 2): FileSizeFormatedInterface {
|
|
4
4
|
if (bytes === 0) return {size: 0, unit: "o"};
|
|
5
5
|
|
|
6
6
|
const k = 1024;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import {ConfigurableInterface} from "../../types";
|
|
4
4
|
import {Logger} from "@protorians/logger";
|
|
5
5
|
import {Raiton} from "../raiton";
|
|
6
6
|
|
|
7
7
|
export class RaitonConfig {
|
|
8
|
-
static readonly current: Map<keyof
|
|
8
|
+
static readonly current: Map<keyof ConfigurableInterface, ConfigurableInterface[keyof ConfigurableInterface]> = new Map();
|
|
9
9
|
|
|
10
10
|
protected static _extensions: string[] = ['.js', '.mjs'];
|
|
11
11
|
|
|
12
|
-
static get<K extends keyof
|
|
13
|
-
return this.current.get(key) as
|
|
12
|
+
static get<K extends keyof ConfigurableInterface>(key: K): ConfigurableInterface[K] | undefined {
|
|
13
|
+
return this.current.get(key) as ConfigurableInterface[K];
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
static defaultConfig:
|
|
16
|
+
static defaultConfig: ConfigurableInterface = {
|
|
17
17
|
rootDir: '.',
|
|
18
18
|
version: '0.0.1'
|
|
19
19
|
}
|
|
@@ -26,7 +26,7 @@ export class RaitonConfig {
|
|
|
26
26
|
if (fs.existsSync(configJsonPath)) {
|
|
27
27
|
const configContent = fs.readFileSync(configJsonPath, 'utf-8');
|
|
28
28
|
for (const [key, value] of Object.entries({...this.defaultConfig, ...(JSON.parse(configContent) || {})}))
|
|
29
|
-
this.current.set(key as keyof
|
|
29
|
+
this.current.set(key as keyof ConfigurableInterface, value as ConfigurableInterface[keyof ConfigurableInterface]);
|
|
30
30
|
} else {
|
|
31
31
|
for (const ext of this._extensions) {
|
|
32
32
|
const configPath = path.join(workdir, `${Raiton.identifier}.config${ext}`);
|
|
@@ -34,7 +34,7 @@ export class RaitonConfig {
|
|
|
34
34
|
const configModule = await import(configPath);
|
|
35
35
|
const config = await configModule?.default || configModule;
|
|
36
36
|
for (const [key, value] of Object.entries(config)) {
|
|
37
|
-
this.current.set(key as keyof
|
|
37
|
+
this.current.set(key as keyof ConfigurableInterface, value as ConfigurableInterface[keyof ConfigurableInterface]);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {ConfigurableInterface} from "../../types/config";
|
|
2
2
|
import {JsonUtil} from "../../sdk/utilities";
|
|
3
3
|
|
|
4
|
-
export async function defineConfig(config?:
|
|
4
|
+
export async function defineConfig(config?: ConfigurableInterface) {
|
|
5
5
|
const workdir = process.cwd();
|
|
6
6
|
const pkg = JsonUtil.import(workdir + '/package.json');
|
|
7
7
|
|
|
8
|
-
config = {...config || {}, ...pkg.raitonConfig || {}} as
|
|
8
|
+
config = {...config || {}, ...pkg.raitonConfig || {}} as ConfigurableInterface;
|
|
9
9
|
config.rootDir = config.rootDir || './';
|
|
10
10
|
config.version = config.version || pkg.version || '0.0.1';
|
|
11
11
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import {BuilderHMRDeclarationInterface} from "../../types";
|
|
3
3
|
import {LBadge, Logger} from "@protorians/logger";
|
|
4
4
|
import {compileController} from "./compiler";
|
|
5
5
|
import {RaitonThread} from "../thread";
|
|
@@ -21,7 +21,7 @@ export class ControllerBuilder {
|
|
|
21
21
|
return output.filter(f => typeof f !== 'undefined');
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
static async build<T>({filename, version, timestamp}:
|
|
24
|
+
static async build<T>({filename, version, timestamp}: BuilderHMRDeclarationInterface): Promise<T | undefined> {
|
|
25
25
|
if (!isControllerArtifact(filename))
|
|
26
26
|
return undefined;
|
|
27
27
|
|