@kunk/server 3.0.2 → 3.0.5
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/dist/index.d.mts +520 -0
- package/dist/index.mjs +1 -0
- package/package.json +11 -1
- package/.turbo/turbo-deploy.log +0 -0
- package/.turbo/turbo-version$colon$patch.log +0 -4
- package/CHANGELOG.md +0 -13
- package/src/command.ts +0 -57
- package/src/configs/+.ts +0 -1
- package/src/configs/DatabaseConfig.ts +0 -12
- package/src/context.ts +0 -97
- package/src/contracts/+.ts +0 -5
- package/src/contracts/Auth.ts +0 -73
- package/src/contracts/Database.ts +0 -40
- package/src/contracts/Query.ts +0 -3
- package/src/index.ts +0 -11
- package/src/interfaces/+.ts +0 -9
- package/src/interfaces/IApplication.ts +0 -6
- package/src/interfaces/IContainer.ts +0 -1
- package/src/interfaces/IContext.ts +0 -31
- package/src/interfaces/IContextCommand.ts +0 -7
- package/src/interfaces/IContextHandler.ts +0 -6
- package/src/interfaces/IMiddleware.ts +0 -6
- package/src/interfaces/IService.ts +0 -1
- package/src/middleware.ts +0 -13
- package/src/registry.ts +0 -11
- package/src/server.ts +0 -87
- package/src/services/+.ts +0 -4
- package/src/services/BunGenerator.ts +0 -13
- package/src/services/DizzleDatabase.ts +0 -142
- package/src/services/DrizzleQuery.ts +0 -1
- package/src/services/PinoLogger.ts +0 -36
- package/src/setup.ts +0 -26
- package/src/utils/+.ts +0 -2
- package/src/utils/SERVER_ERROR.ts +0 -41
- package/src/utils/config.ts +0 -70
- package/tsconfig.json +0 -19
- package/tsdown.config.ts +0 -15
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from "@standard-schema/spec"
|
|
2
|
-
import { Throwable, type IThrowable } from "@kunk/api"
|
|
3
|
-
import { getTableUniqueName, Table } from "drizzle-orm"
|
|
4
|
-
|
|
5
|
-
export namespace SERVER_ERROR {
|
|
6
|
-
|
|
7
|
-
export function RESOURCE_ID_NOT_FOUND(resource: string, id: string) {
|
|
8
|
-
return Throwable.create("RESOURCE_ID_NOT_FOUND", 404, { resource, id })
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function RESOURCE_NOT_FOUND(resource: string) {
|
|
12
|
-
return Throwable.create("RESOURCE_NOT_FOUND", 404, { resource })
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function BAD_REQUEST(type: string, args: Record<string, any>) {
|
|
16
|
-
return Throwable.create(type, 400, args)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function RESOURCE_ID_ALREADY_EXISTS(resource: string, id: string) {
|
|
20
|
-
return Throwable.create("RESOURCE_ID_ALREADY_EXISTS", 400, { resource, id })
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function VALIDATION(...issues: IThrowable[]) {
|
|
24
|
-
return Throwable.create("VALIDATION_ERROR", 422, { issues })
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function SCHEMA_VALIDATION(issues: readonly StandardSchemaV1.Issue[]) {
|
|
28
|
-
return Throwable.create("SCHEMA_VALIDATION_ERROR", 422, { issues })
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function UNEXPECTED(type: string, args: Record<string, any>) {
|
|
32
|
-
return Throwable.create(type, 500, args)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const FORWARD = Throwable.forward
|
|
36
|
-
|
|
37
|
-
export function GET_ENTITY_NOT_FOUND<T extends Table>(entity: T, id: string) {
|
|
38
|
-
return SERVER_ERROR.RESOURCE_ID_NOT_FOUND(getTableUniqueName(entity), id)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}
|
package/src/utils/config.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { SERVER_ERROR } from "./SERVER_ERROR";
|
|
2
|
-
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
import type { I } from "@kunk/api";
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
|
|
6
|
-
function interpolateEnvVars<T>(obj: T): T {
|
|
7
|
-
if (typeof obj === 'string') {
|
|
8
|
-
return obj.replace(
|
|
9
|
-
/\${([^:-]+)(?:-([^}]+))?}/g,
|
|
10
|
-
(_, key, defaultValue) => Bun.env[key] || defaultValue || ''
|
|
11
|
-
) as T;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (typeof obj === 'object' && obj !== null) {
|
|
15
|
-
const result = (Array.isArray(obj) ? [] : {}) as T;
|
|
16
|
-
for (const key in obj) {
|
|
17
|
-
result[key] = interpolateEnvVars(obj[key]);
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function loadFromFile<T extends StandardSchemaV1>(name: string, schema: T): Promise<I.Output<T>> {
|
|
26
|
-
let rawConfig = {}
|
|
27
|
-
const filePath = path.resolve(process.cwd(), `./config/${name}.yaml`)
|
|
28
|
-
|
|
29
|
-
if (await Bun.file(filePath).exists()) {
|
|
30
|
-
rawConfig = await import(filePath).then(module => module.default?.[Bun.env.NODE_ENV || "local"]);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const validated = await schema["~standard"].validate(rawConfig);
|
|
34
|
-
if (validated.issues) {
|
|
35
|
-
throw SERVER_ERROR.SCHEMA_VALIDATION(validated.issues)
|
|
36
|
-
}
|
|
37
|
-
return interpolateEnvVars(validated.value) as I.Output<T>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export class Config<T extends StandardSchemaV1> {
|
|
42
|
-
|
|
43
|
-
private constructor(
|
|
44
|
-
private readonly schema: T,
|
|
45
|
-
private values: I.Output<T>
|
|
46
|
-
) {}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
public get() {
|
|
50
|
-
return this.values;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public async set(values: I.Input<T>): Promise<void> {
|
|
54
|
-
const validated = await this.schema["~standard"].validate(values);
|
|
55
|
-
if (validated.issues) {
|
|
56
|
-
throw SERVER_ERROR.SCHEMA_VALIDATION(validated.issues)
|
|
57
|
-
}
|
|
58
|
-
this.values = validated.value as I.Output<T>;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
static async create<T extends StandardSchemaV1>(options: { name: string, schema: T }) {
|
|
62
|
-
const values = await loadFromFile(options.name, options.schema);
|
|
63
|
-
return new Config(options.schema, values as I.Output<T>);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public static set<T extends StandardSchemaV1>(config: Config<T>, values: I.Input<T>) {
|
|
67
|
-
config.set(values);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"rootDir": ".",
|
|
4
|
-
"baseUrl": ".",
|
|
5
|
-
"paths": {
|
|
6
|
-
"@/*": ["./src/*"]
|
|
7
|
-
},
|
|
8
|
-
"strict": true,
|
|
9
|
-
"module": "Preserve",
|
|
10
|
-
"target": "ESNext"
|
|
11
|
-
},
|
|
12
|
-
"include": [
|
|
13
|
-
"src/**/*.ts"
|
|
14
|
-
],
|
|
15
|
-
"exclude": [
|
|
16
|
-
"node_modules",
|
|
17
|
-
"dist"
|
|
18
|
-
]
|
|
19
|
-
}
|