@kurdel/core 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +54 -0
- package/lib/app/app-config.d.ts +9 -0
- package/lib/app/app-config.js +2 -0
- package/lib/app/app-config.js.map +1 -0
- package/lib/app/app-module.d.ts +75 -0
- package/lib/app/app-module.js +2 -0
- package/lib/app/app-module.js.map +1 -0
- package/lib/app/app-tokens.d.ts +4 -0
- package/lib/app/app-tokens.js +6 -0
- package/lib/app/app-tokens.js.map +1 -0
- package/lib/app/application.d.ts +23 -0
- package/lib/app/application.js +2 -0
- package/lib/app/application.js.map +1 -0
- package/lib/app/index.d.ts +6 -0
- package/lib/app/index.js +7 -0
- package/lib/app/index.js.map +1 -0
- package/lib/app/lifecycle.d.ts +3 -0
- package/lib/app/lifecycle.js +2 -0
- package/lib/app/lifecycle.js.map +1 -0
- package/lib/app/module-priority.d.ts +33 -0
- package/lib/app/module-priority.js +35 -0
- package/lib/app/module-priority.js.map +1 -0
- package/lib/db/index.d.ts +1 -0
- package/lib/db/index.js +2 -0
- package/lib/db/index.js.map +1 -0
- package/lib/db/model.d.ts +23 -0
- package/lib/db/model.js +17 -0
- package/lib/db/model.js.map +1 -0
- package/lib/http/errors/http-error.d.ts +5 -0
- package/lib/http/errors/http-error.js +9 -0
- package/lib/http/errors/http-error.js.map +1 -0
- package/lib/http/errors/index.d.ts +2 -0
- package/lib/http/errors/index.js +3 -0
- package/lib/http/errors/index.js.map +1 -0
- package/lib/http/errors/validation-error.d.ts +9 -0
- package/lib/http/errors/validation-error.js +12 -0
- package/lib/http/errors/validation-error.js.map +1 -0
- package/lib/http/http-context.d.ts +107 -0
- package/lib/http/http-context.js +2 -0
- package/lib/http/http-context.js.map +1 -0
- package/lib/http/http-module.d.ts +61 -0
- package/lib/http/http-module.js +2 -0
- package/lib/http/http-module.js.map +1 -0
- package/lib/http/http-tokens.d.ts +10 -0
- package/lib/http/http-tokens.js +11 -0
- package/lib/http/http-tokens.js.map +1 -0
- package/lib/http/index.d.ts +9 -0
- package/lib/http/index.js +10 -0
- package/lib/http/index.js.map +1 -0
- package/lib/http/middleware/index.d.ts +3 -0
- package/lib/http/middleware/index.js +4 -0
- package/lib/http/middleware/index.js.map +1 -0
- package/lib/http/middleware/middleware-registration.d.ts +25 -0
- package/lib/http/middleware/middleware-registration.js +2 -0
- package/lib/http/middleware/middleware-registration.js.map +1 -0
- package/lib/http/middleware/middleware-registry.d.ts +15 -0
- package/lib/http/middleware/middleware-registry.js +2 -0
- package/lib/http/middleware/middleware-registry.js.map +1 -0
- package/lib/http/middleware/middleware.d.ts +2 -0
- package/lib/http/middleware/middleware.js +2 -0
- package/lib/http/middleware/middleware.js.map +1 -0
- package/lib/http/response/action-result.d.ts +69 -0
- package/lib/http/response/action-result.js +2 -0
- package/lib/http/response/action-result.js.map +1 -0
- package/lib/http/response/http-results.d.ts +17 -0
- package/lib/http/response/http-results.js +46 -0
- package/lib/http/response/http-results.js.map +1 -0
- package/lib/http/response/index.d.ts +3 -0
- package/lib/http/response/index.js +4 -0
- package/lib/http/response/index.js.map +1 -0
- package/lib/http/response/response-renderer.d.ts +6 -0
- package/lib/http/response/response-renderer.js +2 -0
- package/lib/http/response/response-renderer.js.map +1 -0
- package/lib/http/routing/controller-config.d.ts +24 -0
- package/lib/http/routing/controller-config.js +2 -0
- package/lib/http/routing/controller-config.js.map +1 -0
- package/lib/http/routing/controller-resolver.d.ts +5 -0
- package/lib/http/routing/controller-resolver.js +2 -0
- package/lib/http/routing/controller-resolver.js.map +1 -0
- package/lib/http/routing/controller.d.ts +22 -0
- package/lib/http/routing/controller.js +47 -0
- package/lib/http/routing/controller.js.map +1 -0
- package/lib/http/routing/index.d.ts +7 -0
- package/lib/http/routing/index.js +8 -0
- package/lib/http/routing/index.js.map +1 -0
- package/lib/http/routing/route-match.d.ts +27 -0
- package/lib/http/routing/route-match.js +2 -0
- package/lib/http/routing/route-match.js.map +1 -0
- package/lib/http/routing/route-schema.d.ts +16 -0
- package/lib/http/routing/route-schema.js +2 -0
- package/lib/http/routing/route-schema.js.map +1 -0
- package/lib/http/routing/route.d.ts +112 -0
- package/lib/http/routing/route.js +21 -0
- package/lib/http/routing/route.js.map +1 -0
- package/lib/http/routing/router.d.ts +27 -0
- package/lib/http/routing/router.js +2 -0
- package/lib/http/routing/router.js.map +1 -0
- package/lib/http/server/index.d.ts +2 -0
- package/lib/http/server/index.js +3 -0
- package/lib/http/server/index.js.map +1 -0
- package/lib/http/server/running-server.d.ts +8 -0
- package/lib/http/server/running-server.js +2 -0
- package/lib/http/server/running-server.js.map +1 -0
- package/lib/http/server/server-adapter.d.ts +82 -0
- package/lib/http/server/server-adapter.js +2 -0
- package/lib/http/server/server-adapter.js.map +1 -0
- package/lib/http/types.d.ts +10 -0
- package/lib/http/types.js +2 -0
- package/lib/http/types.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/template/index.d.ts +2 -0
- package/lib/template/index.js +3 -0
- package/lib/template/index.js.map +1 -0
- package/lib/template/template-engine.d.ts +3 -0
- package/lib/template/template-engine.js +2 -0
- package/lib/template/template-engine.js.map +1 -0
- package/lib/template/template-tokens.d.ts +2 -0
- package/lib/template/template-tokens.js +3 -0
- package/lib/template/template-tokens.js.map +1 -0
- package/lib/tokens/index.d.ts +1 -0
- package/lib/tokens/index.js +2 -0
- package/lib/tokens/index.js.map +1 -0
- package/lib/tokens/tokens.d.ts +12 -0
- package/lib/tokens/tokens.js +9 -0
- package/lib/tokens/tokens.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Andrii Sorokin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @kurdel/core
|
|
2
|
+
|
|
3
|
+
Core **contracts** and **interfaces** for the Kurdel framework.
|
|
4
|
+
Contains stable, runtime-independent API definitions used by all other packages.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 📦 Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @kurdel/core
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 📘 Purpose
|
|
17
|
+
|
|
18
|
+
* Framework-agnostic HTTP contracts (`Controller`, `ActionResult`, `HttpContext`)
|
|
19
|
+
* Tokens and metadata utilities
|
|
20
|
+
* Base abstractions for routers, modules, and middlewares
|
|
21
|
+
* Type-safe route definitions (no decorators)
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 🔧 Example
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Controller, route, Ok, type HttpContext } from '@kurdel/core/http';
|
|
29
|
+
|
|
30
|
+
export class UserController extends Controller {
|
|
31
|
+
readonly routes = {
|
|
32
|
+
list: route({ method: 'GET', path: '/users' })(this.list),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
async list(_ctx: HttpContext) {
|
|
36
|
+
return Ok([{ id: 1, name: 'Ada Lovelace' }]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 🔗 Used by
|
|
44
|
+
|
|
45
|
+
* `@kurdel/runtime`
|
|
46
|
+
* `@kurdel/runtime-node`
|
|
47
|
+
* `@kurdel/facade`
|
|
48
|
+
* `@kurdel/template-ejs`
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 📄 License
|
|
53
|
+
|
|
54
|
+
MIT © Andrii Sorokin
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Newable } from '@kurdel/common';
|
|
2
|
+
import type { Model } from '../db/index.js';
|
|
3
|
+
import type { HttpModule } from '../http/index.js';
|
|
4
|
+
import type { AppModule } from '../app/index.js';
|
|
5
|
+
export interface AppConfig {
|
|
6
|
+
db?: boolean;
|
|
7
|
+
models?: Newable<Model>[];
|
|
8
|
+
modules?: (AppModule | HttpModule)[];
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-config.js","sourceRoot":"","sources":["../../src/app/app-config.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Identifier, Container } from '@kurdel/ioc';
|
|
2
|
+
import type { AppConfig } from '../app/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* ## ClassProviderConfig
|
|
5
|
+
*
|
|
6
|
+
* Registers a class constructor as a provider.
|
|
7
|
+
* Instances are created by the IoC container, optionally with:
|
|
8
|
+
* - explicit `deps` mapping for constructor injection
|
|
9
|
+
* - lifecycle mode (`singleton` or per-scope)
|
|
10
|
+
*/
|
|
11
|
+
export type ClassProviderConfig<T = any> = {
|
|
12
|
+
provide: Identifier<T>;
|
|
13
|
+
useClass: new (...args: any[]) => T;
|
|
14
|
+
deps?: Record<string, Identifier<unknown>>;
|
|
15
|
+
singleton?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* ## InstanceProviderConfig
|
|
19
|
+
*
|
|
20
|
+
* Registers a pre-constructed instance.
|
|
21
|
+
* No lifecycle or dependency metadata — the provided instance is used as-is.
|
|
22
|
+
*/
|
|
23
|
+
export type InstanceProviderConfig<T = any> = {
|
|
24
|
+
provide: Identifier<T>;
|
|
25
|
+
useInstance: T;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* ## FactoryProviderConfig
|
|
29
|
+
*
|
|
30
|
+
* Registers a factory function.
|
|
31
|
+
* The function receives the IoC container and must produce a value.
|
|
32
|
+
* Can optionally opt into singleton mode.
|
|
33
|
+
*/
|
|
34
|
+
export type FactoryProviderConfig<T = any> = {
|
|
35
|
+
provide: Identifier<T>;
|
|
36
|
+
useFactory: (ioc: Container) => T | Promise<T>;
|
|
37
|
+
singleton?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* ## ProviderConfig
|
|
41
|
+
*
|
|
42
|
+
* Unified provider registration type for feature modules.
|
|
43
|
+
* Covers:
|
|
44
|
+
* - class providers
|
|
45
|
+
* - instance providers
|
|
46
|
+
* - factory providers
|
|
47
|
+
*/
|
|
48
|
+
export type ProviderConfig<T = any> = ClassProviderConfig<T> | InstanceProviderConfig<T> | FactoryProviderConfig<T>;
|
|
49
|
+
/**
|
|
50
|
+
* ## AppModule
|
|
51
|
+
*
|
|
52
|
+
* Feature module — a self-contained composition unit.
|
|
53
|
+
*
|
|
54
|
+
* Provides:
|
|
55
|
+
* - dependency tokens
|
|
56
|
+
* - configuration-driven providers
|
|
57
|
+
* - optional setup logic via `register()`
|
|
58
|
+
*
|
|
59
|
+
* Modules define what they export and what dependencies they require.
|
|
60
|
+
*/
|
|
61
|
+
export interface AppModule<TConfig = AppConfig> {
|
|
62
|
+
/** Determines initialization order (lower = earlier). */
|
|
63
|
+
readonly priority?: number;
|
|
64
|
+
/** Tokens or modules this one depends on. */
|
|
65
|
+
readonly imports?: Identifier<any>[] | Record<string, Identifier<any>>;
|
|
66
|
+
/** Tokens this module exports for other modules. */
|
|
67
|
+
readonly exports?: Identifier<any>[] | Record<string, Identifier<any>>;
|
|
68
|
+
/** Declarative provider registrations. */
|
|
69
|
+
readonly providers?: ProviderConfig[];
|
|
70
|
+
/**
|
|
71
|
+
* Imperative setup hook.
|
|
72
|
+
* Called once during application initialization.
|
|
73
|
+
*/
|
|
74
|
+
register?(ioc: Container, config: TConfig): Promise<void> | void;
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-module.js","sourceRoot":"","sources":["../../src/app/app-module.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-tokens.js","sourceRoot":"","sources":["../../src/app/app-tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhD,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,iBAAiB,CAAgB,2BAA2B,CAAC;IACtE,UAAU,EAAE,iBAAiB,CAAmB,8BAA8B,CAAC;CAChF,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Container } from '@kurdel/ioc';
|
|
2
|
+
import type { RunningServer } from '../http/index.js';
|
|
3
|
+
import type { AppModule } from '../app/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Public application contract.
|
|
6
|
+
* Exposes a DI container (by interface), allows composing modules,
|
|
7
|
+
* and starting the HTTP server via a façade in the runtime.
|
|
8
|
+
*/
|
|
9
|
+
export interface Application {
|
|
10
|
+
/** DI container exposed by interface type (implementation is hidden). */
|
|
11
|
+
readonly container: Container;
|
|
12
|
+
/** Register additional modules before startup. */
|
|
13
|
+
use(...modules: AppModule[]): void;
|
|
14
|
+
/**
|
|
15
|
+
* Start the server and get a handle for tests and shutdown.
|
|
16
|
+
* Kept compatible with previous signature by making callback optional.
|
|
17
|
+
*/
|
|
18
|
+
listen(port: number, callback?: () => void): RunningServer;
|
|
19
|
+
/**
|
|
20
|
+
* Expose underlying IoC container for advanced use cases.
|
|
21
|
+
*/
|
|
22
|
+
getContainer(): Container;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application.js","sourceRoot":"","sources":["../../src/app/application.ts"],"names":[],"mappings":""}
|
package/lib/app/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/app/lifecycle.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## ModulePriority
|
|
3
|
+
*
|
|
4
|
+
* Standard initialization weights for Kurdel application modules.
|
|
5
|
+
*
|
|
6
|
+
* Lower number → earlier initialization.
|
|
7
|
+
*
|
|
8
|
+
* Recommended lifecycle:
|
|
9
|
+
*
|
|
10
|
+
* 10 Lifecycle — framework boot logic, configuration preparation
|
|
11
|
+
* 20 Database — database clients/drivers
|
|
12
|
+
* 30 User — user-defined modules (default fallback)
|
|
13
|
+
* 40 Model — model definition + schema registration
|
|
14
|
+
* 50 Middleware — global middleware registry
|
|
15
|
+
* 60 Auth — authentication/authorization middleware hookup
|
|
16
|
+
* 70 Controller — controller registration + route table build
|
|
17
|
+
* 80 Platform — platform-specific bindings (Node/Express/Fastify/etc.)
|
|
18
|
+
* 90 Server — server start module
|
|
19
|
+
*
|
|
20
|
+
* 100 Custom — fallback for modules without explicit priority
|
|
21
|
+
*/
|
|
22
|
+
export declare enum ModulePriority {
|
|
23
|
+
Lifecycle = 10,
|
|
24
|
+
Database = 20,
|
|
25
|
+
User = 30,
|
|
26
|
+
Model = 40,
|
|
27
|
+
Middleware = 50,
|
|
28
|
+
Auth = 60,
|
|
29
|
+
Controller = 70,
|
|
30
|
+
Platform = 80,
|
|
31
|
+
Server = 90,
|
|
32
|
+
Custom = 100
|
|
33
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## ModulePriority
|
|
3
|
+
*
|
|
4
|
+
* Standard initialization weights for Kurdel application modules.
|
|
5
|
+
*
|
|
6
|
+
* Lower number → earlier initialization.
|
|
7
|
+
*
|
|
8
|
+
* Recommended lifecycle:
|
|
9
|
+
*
|
|
10
|
+
* 10 Lifecycle — framework boot logic, configuration preparation
|
|
11
|
+
* 20 Database — database clients/drivers
|
|
12
|
+
* 30 User — user-defined modules (default fallback)
|
|
13
|
+
* 40 Model — model definition + schema registration
|
|
14
|
+
* 50 Middleware — global middleware registry
|
|
15
|
+
* 60 Auth — authentication/authorization middleware hookup
|
|
16
|
+
* 70 Controller — controller registration + route table build
|
|
17
|
+
* 80 Platform — platform-specific bindings (Node/Express/Fastify/etc.)
|
|
18
|
+
* 90 Server — server start module
|
|
19
|
+
*
|
|
20
|
+
* 100 Custom — fallback for modules without explicit priority
|
|
21
|
+
*/
|
|
22
|
+
export var ModulePriority;
|
|
23
|
+
(function (ModulePriority) {
|
|
24
|
+
ModulePriority[ModulePriority["Lifecycle"] = 10] = "Lifecycle";
|
|
25
|
+
ModulePriority[ModulePriority["Database"] = 20] = "Database";
|
|
26
|
+
ModulePriority[ModulePriority["User"] = 30] = "User";
|
|
27
|
+
ModulePriority[ModulePriority["Model"] = 40] = "Model";
|
|
28
|
+
ModulePriority[ModulePriority["Middleware"] = 50] = "Middleware";
|
|
29
|
+
ModulePriority[ModulePriority["Auth"] = 60] = "Auth";
|
|
30
|
+
ModulePriority[ModulePriority["Controller"] = 70] = "Controller";
|
|
31
|
+
ModulePriority[ModulePriority["Platform"] = 80] = "Platform";
|
|
32
|
+
ModulePriority[ModulePriority["Server"] = 90] = "Server";
|
|
33
|
+
ModulePriority[ModulePriority["Custom"] = 100] = "Custom";
|
|
34
|
+
})(ModulePriority || (ModulePriority = {}));
|
|
35
|
+
//# sourceMappingURL=module-priority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-priority.js","sourceRoot":"","sources":["../../src/app/module-priority.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAN,IAAY,cAWX;AAXD,WAAY,cAAc;IACxB,8DAAc,CAAA;IACd,4DAAa,CAAA;IACb,oDAAS,CAAA;IACT,sDAAU,CAAA;IACV,gEAAe,CAAA;IACf,oDAAS,CAAA;IACT,gEAAe,CAAA;IACf,4DAAa,CAAA;IACb,wDAAW,CAAA;IACX,yDAAY,CAAA;AACd,CAAC,EAXW,cAAc,KAAd,cAAc,QAWzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './model.js';
|
package/lib/db/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Newable } from '@kurdel/common';
|
|
2
|
+
import type { Identifier } from '@kurdel/ioc';
|
|
3
|
+
import type { IDatabase } from '@kurdel/db';
|
|
4
|
+
interface ModelDeps {
|
|
5
|
+
db: IDatabase;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class Model {
|
|
8
|
+
private db;
|
|
9
|
+
private builder;
|
|
10
|
+
protected abstract table: string;
|
|
11
|
+
constructor(deps: ModelDeps);
|
|
12
|
+
create(data: Record<string, any>): Promise<void>;
|
|
13
|
+
find(field: string, values: any[]): Promise<any>;
|
|
14
|
+
findAll(): Promise<any>;
|
|
15
|
+
}
|
|
16
|
+
export interface ModelConfig {
|
|
17
|
+
/** Controller class */
|
|
18
|
+
use: Newable<Model>;
|
|
19
|
+
/** Dependencies to be injected from IoC */
|
|
20
|
+
deps?: Record<string, Identifier>;
|
|
21
|
+
}
|
|
22
|
+
export type ModelList = (Newable<Model> | ModelConfig)[];
|
|
23
|
+
export {};
|
package/lib/db/model.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { QueryBuilder } from '@kurdel/db';
|
|
2
|
+
export class Model {
|
|
3
|
+
constructor(deps) {
|
|
4
|
+
this.db = deps.db;
|
|
5
|
+
this.builder = new QueryBuilder();
|
|
6
|
+
}
|
|
7
|
+
async create(data) {
|
|
8
|
+
return this.db.run(this.builder.insert(this.table, data).build());
|
|
9
|
+
}
|
|
10
|
+
async find(field, values) {
|
|
11
|
+
return this.db.get(this.builder.select('*').from(this.table).where(`${field} = ?`, values).build());
|
|
12
|
+
}
|
|
13
|
+
async findAll() {
|
|
14
|
+
return this.db.all(this.builder.select('*').from(this.table).build());
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/db/model.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM1C,MAAM,OAAgB,KAAK;IAKzB,YAAY,IAAe;QACzB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;IACpC,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,IAAyB;QAC3C,OAAO,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IACpE,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,KAAa,EAAE,MAAa;QAC5C,OAAO,IAAI,CAAC,EAAE,CAAC,GAAG,CAChB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,KAAK,MAAM,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,CAChF,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,OAAO,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IACxE,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-error.js","sourceRoot":"","sources":["../../../src/http/errors/http-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAU,SAAQ,KAAK;IAIlC,YAAY,MAAc,EAAE,OAAe,EAAE,OAAiB;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/http/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JsonValue } from '../../http/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Error raised when schema validation fails.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ValidationError extends Error {
|
|
6
|
+
readonly field?: string | undefined;
|
|
7
|
+
readonly details?: JsonValue;
|
|
8
|
+
constructor(message: string, field?: string | undefined, details?: JsonValue);
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error raised when schema validation fails.
|
|
3
|
+
*/
|
|
4
|
+
export class ValidationError extends Error {
|
|
5
|
+
constructor(message, field, details) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.field = field;
|
|
8
|
+
this.details = details;
|
|
9
|
+
this.name = 'ValidationError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=validation-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../../../src/http/errors/validation-error.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YACE,OAAe,EACN,KAAc,EACd,OAAmB;QAE5B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,UAAK,GAAL,KAAK,CAAS;QACd,YAAO,GAAP,OAAO,CAAY;QAG5B,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { AuthContext, AuthUser, HttpRequest, HttpResponse } from '@kurdel/common';
|
|
2
|
+
import type { Container } from '@kurdel/ioc';
|
|
3
|
+
import type { JsonValue, Query, ActionResult, RouteMatch } from '../http/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* ## HttpContext
|
|
6
|
+
*
|
|
7
|
+
* Immutable per-request execution context for Kurdel runtime.
|
|
8
|
+
*
|
|
9
|
+
* Each incoming request produces a unique `HttpContext` instance,
|
|
10
|
+
* which travels through middleware and controller pipelines.
|
|
11
|
+
*
|
|
12
|
+
* It encapsulates parsed HTTP data, route metadata, and helper
|
|
13
|
+
* methods for constructing `ActionResult` responses.
|
|
14
|
+
*/
|
|
15
|
+
export interface HttpContext<
|
|
16
|
+
/** Parsed request body type */
|
|
17
|
+
TBody = unknown,
|
|
18
|
+
/** URL parameters extracted from route */
|
|
19
|
+
TParams extends Record<string, string> = Record<string, string>,
|
|
20
|
+
/** Streamable response type (e.g. for SSR or files) */
|
|
21
|
+
TReadable = unknown> {
|
|
22
|
+
/**
|
|
23
|
+
* Request-scoped dependency container.
|
|
24
|
+
*
|
|
25
|
+
* Allows middleware and controllers to resolve:
|
|
26
|
+
* - auth registry
|
|
27
|
+
* - user service
|
|
28
|
+
* - db session/transaction
|
|
29
|
+
* - logger
|
|
30
|
+
* - anything else bound in this scope
|
|
31
|
+
*/
|
|
32
|
+
readonly scope: Container;
|
|
33
|
+
/**
|
|
34
|
+
* Underlying HTTP request abstraction provided by the active adapter.
|
|
35
|
+
*/
|
|
36
|
+
readonly req: HttpRequest;
|
|
37
|
+
/**
|
|
38
|
+
* Underlying HTTP response abstraction provided by the active adapter.
|
|
39
|
+
* Used by the renderer to send the actual response.
|
|
40
|
+
*/
|
|
41
|
+
readonly res: HttpResponse;
|
|
42
|
+
/**
|
|
43
|
+
* Fully parsed request URL including pathname and query string.
|
|
44
|
+
*/
|
|
45
|
+
readonly url: URL;
|
|
46
|
+
/**
|
|
47
|
+
* Parsed query parameters of the current request.
|
|
48
|
+
*/
|
|
49
|
+
query: Query;
|
|
50
|
+
/**
|
|
51
|
+
* Path parameters extracted from the matched route.
|
|
52
|
+
*/
|
|
53
|
+
params: TParams;
|
|
54
|
+
/**
|
|
55
|
+
* Parsed request body (if available and supported by middleware).
|
|
56
|
+
*/
|
|
57
|
+
body?: TBody;
|
|
58
|
+
/**
|
|
59
|
+
* Matched route information, including schema and controller metadata.
|
|
60
|
+
* Useful for validation or dynamic response generation.
|
|
61
|
+
*/
|
|
62
|
+
route?: RouteMatch;
|
|
63
|
+
/**
|
|
64
|
+
* Authenticated user associated with this request.
|
|
65
|
+
*
|
|
66
|
+
* Populated by authentication middleware (auth zone).
|
|
67
|
+
* Undefined for public routes or when authentication is not required.
|
|
68
|
+
*/
|
|
69
|
+
user?: AuthUser;
|
|
70
|
+
/** Full authentication result, including strategy and credential metadata. */
|
|
71
|
+
auth?: AuthContext;
|
|
72
|
+
/**
|
|
73
|
+
* The last computed {@link ActionResult} for this request.
|
|
74
|
+
*
|
|
75
|
+
* Populated by the orchestrator or renderer after a middleware
|
|
76
|
+
* or controller produces a result.
|
|
77
|
+
*
|
|
78
|
+
* Logging / metrics middleware may rely on this value even if
|
|
79
|
+
* the pipeline was short-circuited (e.g., by authentication).
|
|
80
|
+
*/
|
|
81
|
+
result?: ActionResult<TReadable>;
|
|
82
|
+
/**
|
|
83
|
+
* Constructs a JSON response with the given HTTP status code.
|
|
84
|
+
*
|
|
85
|
+
* @param status - HTTP status code
|
|
86
|
+
* @param body - JSON-serializable object
|
|
87
|
+
*/
|
|
88
|
+
json(status: number, body: JsonValue): ActionResult<TReadable>;
|
|
89
|
+
/**
|
|
90
|
+
* Constructs a plain-text response with the given status and message.
|
|
91
|
+
*
|
|
92
|
+
* @param status - HTTP status code
|
|
93
|
+
* @param body - Text content
|
|
94
|
+
*/
|
|
95
|
+
text(status: number, body: string): ActionResult<TReadable>;
|
|
96
|
+
/**
|
|
97
|
+
* Constructs a redirect response to the given location.
|
|
98
|
+
*
|
|
99
|
+
* @param status - HTTP redirect status (3xx)
|
|
100
|
+
* @param location - Target URL or path
|
|
101
|
+
*/
|
|
102
|
+
redirect(status: number, location: string): ActionResult<TReadable>;
|
|
103
|
+
/**
|
|
104
|
+
* Constructs a 204 "No Content" response.
|
|
105
|
+
*/
|
|
106
|
+
noContent(): ActionResult<TReadable>;
|
|
107
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-context.js","sourceRoot":"","sources":["../../src/http/http-context.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ModelList } from '../db/model.js';
|
|
2
|
+
import type { AppModule } from '../app/app-module.js';
|
|
3
|
+
import type { AppConfig } from '../app/app-config.js';
|
|
4
|
+
import type { Middleware, ControllerConfig, MiddlewareRegistration } from '../http/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* HttpModule
|
|
7
|
+
*
|
|
8
|
+
* Extension of the base AppModule contract for modules
|
|
9
|
+
* that operate in an HTTP context.
|
|
10
|
+
*
|
|
11
|
+
* Purpose:
|
|
12
|
+
* - Declare a list of middleware provided by this module
|
|
13
|
+
* - Declare a list of controllers provided by this module
|
|
14
|
+
* - Declare a list of middleware provided by this module
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* export class UserModule implements HttpModule {
|
|
19
|
+
* readonly models = [UserModel];
|
|
20
|
+
* readonly controllers = [UserController];
|
|
21
|
+
* readonly middlewares = [AuthMiddleware];
|
|
22
|
+
*
|
|
23
|
+
* readonly providers = [
|
|
24
|
+
* { provide: UserService, useClass: UserService, isSingleton: true }
|
|
25
|
+
* ];
|
|
26
|
+
*
|
|
27
|
+
* async register(ioc: IoCContainer) {
|
|
28
|
+
* // everything else is handled via providers
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export interface HttpModule<TConfig = AppConfig, out TReadable = unknown> extends AppModule<TConfig> {
|
|
34
|
+
/**
|
|
35
|
+
* Models that should be registered
|
|
36
|
+
* through the ModelModule
|
|
37
|
+
*/
|
|
38
|
+
readonly models?: ModelList;
|
|
39
|
+
/**
|
|
40
|
+
* Controllers that should be registered
|
|
41
|
+
* through the ControllerModule
|
|
42
|
+
*/
|
|
43
|
+
readonly controllers?: ControllerConfig[];
|
|
44
|
+
/**
|
|
45
|
+
* Global middlewares provided by this module.
|
|
46
|
+
*
|
|
47
|
+
* Middlewares may be defined either as raw functions:
|
|
48
|
+
* ```ts
|
|
49
|
+
* readonly middlewares = [loggingMiddleware];
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* or as structured registrations with zone and priority:
|
|
53
|
+
* ```ts
|
|
54
|
+
* readonly middlewares = [
|
|
55
|
+
* { use: loggingMiddleware, zone: 'post', priority: 10 },
|
|
56
|
+
* { use: corsMiddleware, zone: 'pre', priority: 0 },
|
|
57
|
+
* ];
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
readonly middlewares?: Array<Middleware<unknown, TReadable> | MiddlewareRegistration>;
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-module.js","sourceRoot":"","sources":["../../src/http/http-module.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ServerAdapter, Router, Controller, ControllerConfig, MiddlewareRegistry, ControllerResolver, ResponseRenderer } from '../http/index.js';
|
|
2
|
+
export declare const HTTP_TOKENS: {
|
|
3
|
+
ServerAdapter: import("@kurdel/ioc").InjectionToken<ServerAdapter<import("@kurdel/common").HttpRequest, import("@kurdel/common").HttpResponse>>;
|
|
4
|
+
Router: import("@kurdel/ioc").InjectionToken<Router>;
|
|
5
|
+
ControllerClasses: import("@kurdel/ioc").InjectionToken<Controller<{}>[]>;
|
|
6
|
+
ControllerConfigs: import("@kurdel/ioc").InjectionToken<ControllerConfig[]>;
|
|
7
|
+
MiddlewareRegistry: import("@kurdel/ioc").InjectionToken<MiddlewareRegistry>;
|
|
8
|
+
ControllerResolver: import("@kurdel/ioc").InjectionToken<ControllerResolver>;
|
|
9
|
+
ResponseRenderer: import("@kurdel/ioc").InjectionToken<ResponseRenderer>;
|
|
10
|
+
};
|