raiton 1.0.0-alpha.2 → 1.0.0-alpha.3
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 +19 -0
- package/README.md +1 -2
- package/build/bin/index.mjs +3798 -3644
- package/build/raiton-1.0.0-alpha.3.tgz +0 -0
- package/deno.json +9 -0
- package/package.json +2 -1
- package/source/bin/cli-tools.ts +1 -6
- package/source/bin/constants.ts +5 -0
- package/source/bin/index.ts +1 -1
- package/source/commands/develop.command.ts +3 -3
- package/source/commands/start.command.ts +1 -1
- package/source/core/application.ts +66 -18
- package/source/core/builder.ts +27 -21
- package/source/core/controller/builder.ts +8 -5
- package/source/core/controller/metadata.ts +1 -1
- package/source/core/directories.ts +1 -1
- package/source/core/index.ts +0 -1
- package/source/core/injection/injection.ts +67 -5
- package/source/core/middleware/compose.ts +1 -1
- package/source/core/raiton.ts +2 -3
- package/source/core/router/handler.ts +100 -44
- package/source/core/thread.ts +18 -8
- package/source/sdk/artifacts.ts +65 -41
- package/source/sdk/constants/decorators.constant.ts +1 -0
- package/source/sdk/data-transfer-object.ts +11 -3
- package/source/sdk/decorators/parametrable.ts +19 -15
- package/source/sdk/decorators/routable.decorator.ts +0 -3
- package/source/sdk/encryption.ts +5 -6
- package/source/sdk/enums/encrypted.enum.ts +10 -0
- package/source/sdk/enums/http-status.enum.ts +73 -0
- package/source/sdk/enums/index.ts +2 -1
- package/source/sdk/exceptions/http-exception.ts +28 -0
- package/source/sdk/exceptions/index.ts +2 -0
- package/source/sdk/index.ts +7 -0
- package/source/sdk/parameter-bag.ts +55 -0
- package/source/sdk/repositories.ts +1 -1
- package/source/sdk/responses/error.ts +52 -0
- package/source/sdk/responses/helpers.ts +28 -0
- package/source/sdk/responses/http-throwable.ts +28 -0
- package/source/sdk/responses/http.ts +48 -0
- package/source/sdk/responses/index.ts +4 -0
- package/source/sdk/runtime/bun/server.ts +2 -1
- package/source/sdk/runtime/deno/server.ts +2 -2
- package/source/sdk/runtime/node/server.ts +2 -2
- package/source/sdk/utilities/artifact.util.ts +18 -0
- package/source/sdk/utilities/index.ts +1 -3
- package/source/types/application.ts +3 -3
- package/source/types/artifact.ts +36 -32
- package/source/types/builder.ts +0 -4
- package/source/types/config.ts +2 -2
- package/source/types/controller.ts +1 -2
- package/source/types/index.ts +2 -3
- package/source/types/lifecycle.ts +11 -0
- package/source/types/responses.ts +17 -7
- package/source/types/runtime.ts +1 -1
- package/build/raiton-1.0.0-alpha.2.tgz +0 -0
- package/source/core/artifacts/artifact.ts +0 -109
- package/source/core/artifacts/artifacts.ts +0 -10
- package/source/core/artifacts/index.ts +0 -1
- package/source/core/artifacts/runner.ts +0 -3
- package/source/core/hmr.ts +0 -106
- package/source/sdk/decorators/payload.decorator.ts +0 -77
- package/source/sdk/json.ts +0 -55
- package/source/sdk/request.ts +0 -3
- package/source/sdk/responses.ts +0 -45
- package/source/sdk/schemes.ts +0 -178
- package/source/sdk/utilities/artifacts.util.ts +0 -62
- package/source/sdk/utilities/controller.util.ts +0 -8
- package/source/types/data-transfer-object.ts +0 -4
- package/source/types/hmr.ts +0 -39
- /package/source/sdk/enums/{http.enum.ts → http-method.enum.ts} +0 -0
- /package/source/sdk/{throwable.ts → exceptions/throwable.ts} +0 -0
package/source/core/hmr.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import {HmrInterface, HMRMetadataInterface} from "@/types";
|
|
2
|
-
import {Logger} from "@protorians/logger";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export class Hmr implements HmrInterface {
|
|
6
|
-
protected files: Map<string, HMRMetadataInterface> = new Map();
|
|
7
|
-
|
|
8
|
-
set(file: string, filename: string, size: number = 0) {
|
|
9
|
-
|
|
10
|
-
if(!filename.endsWith('.js')) return this;
|
|
11
|
-
|
|
12
|
-
this.files.set(file, {
|
|
13
|
-
filename,
|
|
14
|
-
size,
|
|
15
|
-
version: 1,
|
|
16
|
-
timestamp: Date.now(),
|
|
17
|
-
});
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
clear(): this {
|
|
22
|
-
this.files.clear();
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
entries(): Record<string, HMRMetadataInterface> {
|
|
27
|
-
return Object.fromEntries(this.files.entries());
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
has(key: string): boolean {
|
|
31
|
-
return this.files.has(key);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async refresh(): Promise<this> {
|
|
35
|
-
await this.each(async (file, key) => await this.upsert(key, file.filename));
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async load<T>(key: string): Promise<T | undefined> {
|
|
40
|
-
const file = this.files.get(key);
|
|
41
|
-
Logger.log('HMR', file)
|
|
42
|
-
|
|
43
|
-
const mod = file ? await import(`${file.filename}?t=${file.timestamp}&v=${file.version}`) : undefined;
|
|
44
|
-
return mod as T | undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async reload<T>(key: string): Promise<T | undefined> {
|
|
48
|
-
const file = this.files.get(key);
|
|
49
|
-
|
|
50
|
-
if (!file) return undefined;
|
|
51
|
-
|
|
52
|
-
file.version++
|
|
53
|
-
file.timestamp = Date.now();
|
|
54
|
-
this.files.set(key, file);
|
|
55
|
-
|
|
56
|
-
return await import(`${file.filename}?t=${file.timestamp}&v=${file.version}`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
unset(key: string): this {
|
|
60
|
-
this.files.delete(key);
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
size(): number {
|
|
65
|
-
return this.files.size;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async each(callable: (value: HMRMetadataInterface, key: string, map: Map<string, HMRMetadataInterface>) => void | Promise<void>): Promise<this> {
|
|
69
|
-
await Promise.all([...this.files.entries()].map(async ([key, value]) => await callable(value, key, this.files)));
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get(key: string): HMRMetadataInterface | undefined {
|
|
74
|
-
return this.files.get(key);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getEntries(): Array<[string, HMRMetadataInterface]> {
|
|
78
|
-
return [...this.files.entries()];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
getKeys(): string[] {
|
|
82
|
-
return [...this.files.keys()];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getValues(): Array<HMRMetadataInterface> {
|
|
86
|
-
return [...this.files.values()];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async upsert<T>(key: string, filename: string, size: number = 0): Promise<T | undefined> {
|
|
90
|
-
let file: HMRMetadataInterface | undefined = this.files.get(key);
|
|
91
|
-
|
|
92
|
-
if (!file) {
|
|
93
|
-
this.set(key, filename);
|
|
94
|
-
file = this.files.get(key);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!file) return undefined;
|
|
98
|
-
if (file.size === size) return undefined;
|
|
99
|
-
|
|
100
|
-
file.version++;
|
|
101
|
-
file.timestamp = Date.now();
|
|
102
|
-
file.size = size;
|
|
103
|
-
|
|
104
|
-
return await this.set(key, filename, size).load(key);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// import {IPayload} from "@/types";
|
|
2
|
-
// import {SYSTEM_DECORATORS_KEYS} from "@/sdk/constants";
|
|
3
|
-
//
|
|
4
|
-
// /**
|
|
5
|
-
// * A decorator function that combines and assigns schema-related metadata
|
|
6
|
-
// * to a specific property in the target constructor using reflective metadata.
|
|
7
|
-
// *
|
|
8
|
-
// * @param {IPayload} payload - The schema-related payload to be merged and assigned as metadata.
|
|
9
|
-
// * @return {Function} A decorator function that applies the merged metadata to the property.
|
|
10
|
-
// */
|
|
11
|
-
// export function Schemeable(payload: IPayload): (target: any, propertyKey: (string | symbol)) => void {
|
|
12
|
-
// return (target: any, propertyKey: string | symbol,) => {
|
|
13
|
-
// const current: IPayload = {...(Reflect.getMetadata(SYSTEM_DECORATORS_KEYS.ROUTES_SCHEMES, target.constructor, propertyKey) || {}), ...payload};
|
|
14
|
-
// Reflect.defineMetadata(SYSTEM_DECORATORS_KEYS.ROUTES_SCHEMES, current, target.constructor, propertyKey);
|
|
15
|
-
// };
|
|
16
|
-
// }
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
// /**
|
|
20
|
-
// * Constructs a schematizable object for the provided payload body.
|
|
21
|
-
// *
|
|
22
|
-
// * @param {IPayload['body']} payload - The body of the payload to be schematized.
|
|
23
|
-
// * @return {object} Returns a schematized object containing the provided payload body.
|
|
24
|
-
// */
|
|
25
|
-
// export function BodySchemeable(payload: IPayload['body']): (target: any, propertyKey: (string | symbol)) => void {
|
|
26
|
-
// return Schemeable({
|
|
27
|
-
// body: payload
|
|
28
|
-
// });
|
|
29
|
-
// }
|
|
30
|
-
//
|
|
31
|
-
// /**
|
|
32
|
-
// * Transforms the provided headers payload into a schematizable format.
|
|
33
|
-
// *
|
|
34
|
-
// * @param {IPayload['headers']} payload - The headers payload to be processed and transformed.
|
|
35
|
-
// * @return {object} The transformed schematizable object containing the headers.
|
|
36
|
-
// */
|
|
37
|
-
// export function HeadersSchemeable(payload: IPayload['headers']): (target: any, propertyKey: (string | symbol)) => void {
|
|
38
|
-
// return Schemeable({
|
|
39
|
-
// headers: payload
|
|
40
|
-
// });
|
|
41
|
-
// }
|
|
42
|
-
//
|
|
43
|
-
// /**
|
|
44
|
-
// * Constructs a schematizable object using the given query string payload.
|
|
45
|
-
// *
|
|
46
|
-
// * @param {IPayload['querystring']} payload - The query string object to be included in the schematizable configuration.
|
|
47
|
-
// * @return {object} The resulting schematizable object containing the query string.
|
|
48
|
-
// */
|
|
49
|
-
// export function QuerySchemeable(payload: IPayload['querystring']): (target: any, propertyKey: (string | symbol)) => void {
|
|
50
|
-
// return Schemeable({
|
|
51
|
-
// querystring: payload
|
|
52
|
-
// });
|
|
53
|
-
// }
|
|
54
|
-
//
|
|
55
|
-
// /**
|
|
56
|
-
// * Creates a schematizable object using the provided parameters.
|
|
57
|
-
// *
|
|
58
|
-
// * @param {IPayload['params']} payload - The parameters to be used for creating the schematizable object.
|
|
59
|
-
// * @return {Object} The resulting schematizable object containing the specified parameters.
|
|
60
|
-
// */
|
|
61
|
-
// export function ParamsSchemeable(payload: IPayload['params']): (target: any, propertyKey: (string | symbol)) => void {
|
|
62
|
-
// return Schemeable({
|
|
63
|
-
// params: payload
|
|
64
|
-
// });
|
|
65
|
-
// }
|
|
66
|
-
//
|
|
67
|
-
// /**
|
|
68
|
-
// * Constructs a schematized response payload.
|
|
69
|
-
// *
|
|
70
|
-
// * @param {IPayload['response']} payload - The response payload to be schematized.
|
|
71
|
-
// * @return {object} The schematized response object.
|
|
72
|
-
// */
|
|
73
|
-
// export function ResponseSchemeable(payload: IPayload['response']): (target: any, propertyKey: (string | symbol)) => void {
|
|
74
|
-
// return Schemeable({
|
|
75
|
-
// response: payload
|
|
76
|
-
// });
|
|
77
|
-
// }
|
package/source/sdk/json.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {ParseableEntriesType, ParseablePrimitiveType} from "../types/parseable";
|
|
2
|
-
import {stabilizeJson} from "./utilities";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export class Json<T extends ParseableEntriesType> {
|
|
6
|
-
|
|
7
|
-
public readonly stack: Map<keyof T, T[keyof T]> = new Map();
|
|
8
|
-
|
|
9
|
-
constructor(json: ParseablePrimitiveType<T>) {
|
|
10
|
-
this.records(stabilizeJson<T>(json));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
records(data: T): this {
|
|
14
|
-
for (const [key, value] of Object.entries(data))
|
|
15
|
-
this.stack.set(key as keyof T, value as T[keyof T]);
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get<K extends keyof T>(key: K): T[K] {
|
|
20
|
-
return this.stack.get(key) as T[K];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
set<K extends keyof T>(key: K, value: T[K]): this {
|
|
24
|
-
this.stack.set(key, value);
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
remove<K extends keyof T>(key: K): this {
|
|
29
|
-
this.stack.delete(key);
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
clear(): this {
|
|
34
|
-
this.stack.clear();
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
render(): T {
|
|
39
|
-
return Object.fromEntries(this.stack) as any as T;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static stabilize<T>(json: string | T | null): T {
|
|
43
|
-
return stabilizeJson<T>(json);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static from<T extends ParseableEntriesType>(data: T): Json<T> {
|
|
47
|
-
const json = new Json<T>(null);
|
|
48
|
-
json.records(data);
|
|
49
|
-
return json;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static records<T extends ParseableEntriesType>(support: Json<T>, data: ParseablePrimitiveType<T>): Json<T> {
|
|
53
|
-
return support.records(this.stabilize(data));
|
|
54
|
-
}
|
|
55
|
-
}
|
package/source/sdk/request.ts
DELETED
package/source/sdk/responses.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type {IHttpResponse, ParseableType, ResponseParameters} from "@/types";
|
|
2
|
-
import {RequestContext} from "@/core/context";
|
|
3
|
-
|
|
4
|
-
export function httpResponse<T extends ParseableType>(
|
|
5
|
-
statusCode: number,
|
|
6
|
-
message?: string,
|
|
7
|
-
data?: T,
|
|
8
|
-
error?: any,
|
|
9
|
-
): IHttpResponse<T> {
|
|
10
|
-
return {
|
|
11
|
-
statusCode,
|
|
12
|
-
message,
|
|
13
|
-
data,
|
|
14
|
-
error,
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function successResponse<T extends ParseableType>(
|
|
19
|
-
message?: string,
|
|
20
|
-
data?: T,
|
|
21
|
-
error?: any,
|
|
22
|
-
): IHttpResponse<T> {
|
|
23
|
-
return httpResponse<T>(200, message, data, error);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function errorResponse<T extends ParseableType>(
|
|
27
|
-
message?: string,
|
|
28
|
-
data?: T,
|
|
29
|
-
error?: any,
|
|
30
|
-
): IHttpResponse<T> {
|
|
31
|
-
return httpResponse<T>(500, message, data, error);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export class RaitonResponse {
|
|
36
|
-
constructor(
|
|
37
|
-
public readonly parameters: ResponseParameters,
|
|
38
|
-
public readonly context: RequestContext,
|
|
39
|
-
) {
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
parse(){
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}
|
package/source/sdk/schemes.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import {TSchema, Static, TProperties, Type} from "@sinclair/typebox";
|
|
2
|
-
import {ISchemeConfig, ISchemeOptions, IScheme} from "@/types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export * from "@sinclair/typebox"
|
|
6
|
-
|
|
7
|
-
export function scheme() {
|
|
8
|
-
return new Scheme({});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A utility type for casting and inferring a type based on the provided `Schematic` generic structure.
|
|
14
|
-
* It checks if the given type `T` extends from the `Schematic` type and applies the inference logic
|
|
15
|
-
* defined by the `Schematic.infer` function. If the condition is not met, the type resolves to `never`.
|
|
16
|
-
*
|
|
17
|
-
* @template T - The generic type to evaluate and potentially infer from the `Schematic` structure.
|
|
18
|
-
*
|
|
19
|
-
* If `T` is an instance of `Schematic` with defined type parameters, this utility resolves to the
|
|
20
|
-
* result returned by the `Schematic.infer` method applied to `T`. Otherwise, it will resolve to `never`.
|
|
21
|
-
*/
|
|
22
|
-
export type SchematicCast<T> = T extends Scheme<any, any, any, any>
|
|
23
|
-
? ReturnType<typeof Scheme.infer<T>>
|
|
24
|
-
: never;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Represents a schema configuration that can be used with type-safe operations
|
|
28
|
-
* and is compatible with route options.
|
|
29
|
-
*
|
|
30
|
-
* @template TBody - Optional schema type for the request body.
|
|
31
|
-
* @template TParams - Optional schema type for the route parameters.
|
|
32
|
-
* @template TQuery - Optional schema type for the query string parameters.
|
|
33
|
-
* @template TResponse - Optional schema type for the response, where each status code can have its own schema.
|
|
34
|
-
*/
|
|
35
|
-
export class Scheme<
|
|
36
|
-
TBody extends TSchema | undefined = undefined,
|
|
37
|
-
TParams extends TSchema | undefined = undefined,
|
|
38
|
-
TQuery extends TSchema | undefined = undefined,
|
|
39
|
-
TResponse extends Record<number, TSchema> | undefined = undefined
|
|
40
|
-
> implements IScheme<TBody, TParams, TQuery, TResponse> {
|
|
41
|
-
protected _$body?: TBody;
|
|
42
|
-
protected _$params?: TParams;
|
|
43
|
-
protected _$querystring?: TQuery;
|
|
44
|
-
protected _$response?: TResponse;
|
|
45
|
-
|
|
46
|
-
constructor(config: ISchemeConfig<TBody, TParams, TQuery, TResponse>) {
|
|
47
|
-
this._$body = config.body;
|
|
48
|
-
// this._$body = config.body;
|
|
49
|
-
this._$params = config.params;
|
|
50
|
-
this._$querystring = config.querystring;
|
|
51
|
-
this._$response = config.response;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Retrieves the current value of the $body property.
|
|
56
|
-
*
|
|
57
|
-
* @return {TBody | undefined} The value of the $body property, or undefined if it is not set.
|
|
58
|
-
*/
|
|
59
|
-
get $body(): TBody | undefined {
|
|
60
|
-
return this._$body;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Adds or updates a key-value pair in the body object.
|
|
65
|
-
*
|
|
66
|
-
* @param {string} key - The key to set or update in the body object.
|
|
67
|
-
* @param {TProperties} value - The value to associate with the specified key.
|
|
68
|
-
* @return {this} The current instance with the updated body object.
|
|
69
|
-
*/
|
|
70
|
-
body(key: string, value: TProperties): this {
|
|
71
|
-
this._$body = {...(this._$body || {}), [key]: value} as TBody;
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Retrieves the current value of the `$params` property.
|
|
77
|
-
*
|
|
78
|
-
* @return {TParams | undefined} The value of `$params` if set, otherwise undefined.
|
|
79
|
-
*/
|
|
80
|
-
get $params(): TParams | undefined {
|
|
81
|
-
return this._$params;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Adds or updates a parameter with the specified key and value.
|
|
86
|
-
*
|
|
87
|
-
* @param {string} key - The key associated with the parameter to set or update.
|
|
88
|
-
* @param {TProperties} value - The value to associate with the specified key.
|
|
89
|
-
* @return {this} The current instance with the updated parameters.
|
|
90
|
-
*/
|
|
91
|
-
params(key: string, value: TProperties): this {
|
|
92
|
-
this._$params = {...(this._$params || {}), [key]: value} as TParams;
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Retrieves the current query string.
|
|
98
|
-
*
|
|
99
|
-
* @return {TQuery | undefined} The query string object if available, otherwise undefined.
|
|
100
|
-
*/
|
|
101
|
-
get $querystring(): TQuery | undefined {
|
|
102
|
-
return this._$querystring;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Updates the query string parameters by setting the specified key-value pair.
|
|
107
|
-
*
|
|
108
|
-
* @param {string} key - The key of the query string parameter to set or update.
|
|
109
|
-
* @param {TProperties} value - The value associated with the specified key.
|
|
110
|
-
* @return {this} The current instance of the class for method chaining.
|
|
111
|
-
*/
|
|
112
|
-
querystring(key: string, value: TProperties): this {
|
|
113
|
-
this._$querystring = {...(this._$querystring || {}), [key]: value} as TQuery;
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Retrieves the current response object.
|
|
119
|
-
*
|
|
120
|
-
* @return {TResponse | undefined} The response object if available; otherwise, undefined.
|
|
121
|
-
*/
|
|
122
|
-
get $response(): TResponse | undefined {
|
|
123
|
-
return this._$response;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Adds or updates a response key-value pair in the internal response object.
|
|
128
|
-
*
|
|
129
|
-
* @param {number} key - The key to be added or updated in the response object.
|
|
130
|
-
* @param {TProperties} value - The value associated with the given key.
|
|
131
|
-
* @return {this} The current instance to allow method chaining.
|
|
132
|
-
*/
|
|
133
|
-
response(key: number, value: TProperties): this {
|
|
134
|
-
this._$response = {...(this._$response || {}), [key]: value} as TResponse;
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Generates a schema object for validating different parts of an HTTP request.
|
|
140
|
-
*
|
|
141
|
-
* @return {Object} An object containing the schema definitions for `body`, `params`, `querystring`, and `response`. Each property returns a corresponding schema object.
|
|
142
|
-
*/
|
|
143
|
-
schema(): ISchemeOptions<TBody, TParams, TQuery, TResponse> {
|
|
144
|
-
const schema: ISchemeOptions<TBody, TParams, TQuery, TResponse> = {}
|
|
145
|
-
|
|
146
|
-
if (this._$body) schema.body = Type.Object(this._$body);
|
|
147
|
-
if (this._$params) schema.params = Type.Object(this._$params);
|
|
148
|
-
if (this._$querystring) schema.querystring = Type.Object(this._$querystring);
|
|
149
|
-
if (this._$response) schema.response = Type.Object(this._$response);
|
|
150
|
-
|
|
151
|
-
return schema;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Infers and extracts static types from a given schema object.
|
|
156
|
-
*
|
|
157
|
-
* @param {T extends Schematic<any, any, any, any>} schema - The schema to infer types from. This should extend the Schematic type.
|
|
158
|
-
* @return {Object} An object containing inferred types including:
|
|
159
|
-
* - Body: The static type of the request body if defined in the schema, otherwise undefined.
|
|
160
|
-
* - Params: The static type of the request parameters if defined in the schema, otherwise undefined.
|
|
161
|
-
* - Query: The static type of the query string if defined in the schema, otherwise undefined.
|
|
162
|
-
* - Reply: The response type mappings if defined in the schema, otherwise undefined.
|
|
163
|
-
*/
|
|
164
|
-
static infer<T extends Scheme<any, any, any, any>>(schema: T) {
|
|
165
|
-
return {
|
|
166
|
-
Body: schema._$body ? ({} as Static<NonNullable<T["$body"]>>) : undefined,
|
|
167
|
-
Params: schema._$params
|
|
168
|
-
? ({} as Static<NonNullable<T["$params"]>>)
|
|
169
|
-
: undefined,
|
|
170
|
-
Query: schema._$querystring
|
|
171
|
-
? ({} as Static<NonNullable<T["$querystring"]>>)
|
|
172
|
-
: undefined,
|
|
173
|
-
Reply: schema._$response
|
|
174
|
-
? schema._$response as ({ [K in keyof NonNullable<T["$response"]>]: Static<NonNullable<T["$response"]>[K]> })
|
|
175
|
-
: undefined,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import {LBadge, Logger} from "@protorians/logger";
|
|
4
|
-
import {RaitonDirectories} from "@/core";
|
|
5
|
-
import {Raiton} from "@/core/raiton";
|
|
6
|
-
import {ArtifactFactory} from "@/sdk/artifacts";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export function generateArtifacts(
|
|
10
|
-
artifact: string,
|
|
11
|
-
interfaceName: string,
|
|
12
|
-
decoratorSyntax: RegExp,
|
|
13
|
-
verbose: boolean = false,
|
|
14
|
-
) {
|
|
15
|
-
const artifacts = RaitonDirectories.artifacts(Raiton.thread.builder.workdir)
|
|
16
|
-
const dir = Raiton.thread.builder.source;
|
|
17
|
-
const outputFile = path.join(artifacts, `${artifact}.d.ts`);
|
|
18
|
-
|
|
19
|
-
if (!dir) return;
|
|
20
|
-
|
|
21
|
-
const files = fs.readdirSync(dir, {recursive: true})
|
|
22
|
-
.filter(f => [`.ts`, `.js`, `.mjs`, `.cjs`,].some(ext => f.toString().endsWith(ext)))
|
|
23
|
-
.map(f => f.toString())
|
|
24
|
-
;
|
|
25
|
-
|
|
26
|
-
let mappings = "";
|
|
27
|
-
for (const file of files) {
|
|
28
|
-
|
|
29
|
-
const filename = path.join(dir, file);
|
|
30
|
-
const content = fs.readFileSync(filename, "utf-8");
|
|
31
|
-
const match = content.match(decoratorSyntax);
|
|
32
|
-
|
|
33
|
-
if (!match) continue;
|
|
34
|
-
|
|
35
|
-
let name = match[3] || match[1] || "";
|
|
36
|
-
if (!name) {
|
|
37
|
-
const classMatch = content.match(/export\s+default\s+class\s+([A-Za-z0-9_]+)/);
|
|
38
|
-
name = classMatch?.[1] || path.parse(filename).name;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
mappings += ` ${name}: InstanceType<typeof import("@/${file}").default>;\n`;
|
|
42
|
-
|
|
43
|
-
if (verbose) Logger.info(LBadge.debug(name), `artifact detected`);
|
|
44
|
-
ArtifactFactory.add(artifact, {
|
|
45
|
-
file,
|
|
46
|
-
dir,
|
|
47
|
-
relative: file,
|
|
48
|
-
absolute: filename
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const content = `// AUTO-GENERATED FILE — DO NOT EDIT MANUALLY
|
|
53
|
-
declare global {
|
|
54
|
-
interface ${interfaceName} {
|
|
55
|
-
${mappings} }
|
|
56
|
-
}
|
|
57
|
-
export {};`;
|
|
58
|
-
fs.writeFileSync(outputFile, content, "utf-8");
|
|
59
|
-
if (!ArtifactFactory.save(artifact)) Logger.error(`Failed to save artifacts for ${artifact}`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
package/source/types/hmr.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export interface HMRMetadataInterface {
|
|
2
|
-
version: number;
|
|
3
|
-
timestamp: number;
|
|
4
|
-
filename: string;
|
|
5
|
-
size: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface HmrInterface {
|
|
9
|
-
entries(): Record<string, HMRMetadataInterface>;
|
|
10
|
-
|
|
11
|
-
set(key: string, filename: string, size: number): this;
|
|
12
|
-
|
|
13
|
-
get(key: string): HMRMetadataInterface | undefined;
|
|
14
|
-
|
|
15
|
-
getKeys(): string[];
|
|
16
|
-
|
|
17
|
-
getValues(): Array<HMRMetadataInterface>;
|
|
18
|
-
|
|
19
|
-
getEntries(): Array<[string, HMRMetadataInterface]>;
|
|
20
|
-
|
|
21
|
-
each(callable: (value: HMRMetadataInterface, key: string, map: Map<string, HMRMetadataInterface>) => void| Promise<void>): Promise<this>
|
|
22
|
-
|
|
23
|
-
unset(key: string): this;
|
|
24
|
-
|
|
25
|
-
clear(): this;
|
|
26
|
-
|
|
27
|
-
load<T>(key: string): Promise<T | undefined>;
|
|
28
|
-
|
|
29
|
-
reload<T>(key: string): Promise<T | undefined>;
|
|
30
|
-
|
|
31
|
-
has(key: string): boolean;
|
|
32
|
-
|
|
33
|
-
upsert<T>(key: string, filename: string, size: number): Promise<T | undefined>;
|
|
34
|
-
|
|
35
|
-
size(): number;
|
|
36
|
-
|
|
37
|
-
refresh(): Promise<this>;
|
|
38
|
-
|
|
39
|
-
}
|
|
File without changes
|
|
File without changes
|