@cequrebackends/cequre-ts 0.11.4
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/adapters/bun/bun-cron.d.ts +20 -0
- package/dist/adapters/bun/bun-media.d.ts +9 -0
- package/dist/adapters/bun/bun-redis-cache.d.ts +33 -0
- package/dist/adapters/bun/bun-response.d.ts +13 -0
- package/dist/adapters/bun/bun-server.d.ts +6 -0
- package/dist/adapters/bun/bun-storage.d.ts +10 -0
- package/dist/adapters/bun/bun-websocket.d.ts +104 -0
- package/dist/adapters/bun/index.d.ts +9 -0
- package/dist/adapters/bun/index.js +547 -0
- package/dist/adapters/node/index.d.ts +9 -0
- package/dist/adapters/node/index.js +902 -0
- package/dist/adapters/node/node-cron.d.ts +20 -0
- package/dist/adapters/node/node-media.d.ts +9 -0
- package/dist/adapters/node/node-redis-cache.d.ts +32 -0
- package/dist/adapters/node/node-response.d.ts +13 -0
- package/dist/adapters/node/node-server.d.ts +6 -0
- package/dist/adapters/node/node-storage.d.ts +10 -0
- package/dist/adapters/node/node-websocket.d.ts +102 -0
- package/dist/index-17yswtmg.js +175 -0
- package/dist/index-kyvy0s1x.js +2662 -0
- package/dist/index-mfqj7cwr.js +165 -0
- package/dist/index-rf1kdn5b.js +732 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +3152 -0
- package/dist/interface-map.d.ts +175 -0
- package/dist/shared/core/adapter.d.ts +84 -0
- package/dist/shared/core/base-sql-adapter.d.ts +34 -0
- package/dist/shared/core/cache.d.ts +8 -0
- package/dist/shared/core/email.d.ts +53 -0
- package/dist/shared/core/index.d.ts +12 -0
- package/dist/shared/core/index.js +47 -0
- package/dist/shared/core/openapi.d.ts +24 -0
- package/dist/shared/core/plugins.d.ts +2 -0
- package/dist/shared/core/request.d.ts +32 -0
- package/dist/shared/core/sdk.d.ts +3 -0
- package/dist/shared/core/stream.d.ts +24 -0
- package/dist/shared/core/types-generator.d.ts +0 -0
- package/dist/shared/core/types.d.ts +304 -0
- package/dist/shared/core/ulid.d.ts +5 -0
- package/dist/shared/core/validator.d.ts +32 -0
- package/dist/shared/main/access-evaluator.d.ts +13 -0
- package/dist/shared/main/access.d.ts +34 -0
- package/dist/shared/main/aot.d.ts +3 -0
- package/dist/shared/main/hooks.d.ts +76 -0
- package/dist/shared/main/population.d.ts +13 -0
- package/dist/shared/main/router.d.ts +112 -0
- package/dist/shared/main/runtime.d.ts +195 -0
- package/dist/shared/main/sse.d.ts +87 -0
- package/dist/shared/utils/crypto.d.ts +23 -0
- package/dist/shared/utils/durable-queue.d.ts +20 -0
- package/dist/shared/utils/duration.d.ts +15 -0
- package/dist/shared/utils/error.d.ts +52 -0
- package/dist/shared/utils/kv/adapters/memory.d.ts +20 -0
- package/dist/shared/utils/kv/adapters/sqlite.d.ts +32 -0
- package/dist/shared/utils/kv/index.d.ts +37 -0
- package/dist/shared/utils/kv/types.d.ts +38 -0
- package/dist/shared/utils/logger.d.ts +42 -0
- package/dist/shared/utils/queue-manager.d.ts +64 -0
- package/dist/shared/utils/url.d.ts +13 -0
- package/package.json +63 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CronProvider } from "../../shared/core/types";
|
|
2
|
+
export declare class NodeCronProvider implements CronProvider {
|
|
3
|
+
private localJobs;
|
|
4
|
+
private useBullMQ;
|
|
5
|
+
constructor();
|
|
6
|
+
registerJob(name: string, schedule: string, handler: () => void | Promise<void>): void;
|
|
7
|
+
/**
|
|
8
|
+
* Stops a specific cron job by name
|
|
9
|
+
*/
|
|
10
|
+
stop(name: string): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Safely stops all running cron jobs
|
|
13
|
+
*/
|
|
14
|
+
stopAll(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a list of all currently running cron job names
|
|
17
|
+
*/
|
|
18
|
+
list(): Promise<string[]>;
|
|
19
|
+
startAll(): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CequreStreamMediaOptions {
|
|
2
|
+
provider?: "local" | "s3";
|
|
3
|
+
maxChunkSize?: number;
|
|
4
|
+
s3Config?: {
|
|
5
|
+
bucket?: string;
|
|
6
|
+
expiresIn?: number;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare function CequreStreamMedia(request: Request, absolutePathOrUrl: string, options?: CequreStreamMediaOptions): Response;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { KVAdapter } from "../../shared/utils/kv/types";
|
|
2
|
+
/**
|
|
3
|
+
* Redis KV adapter using `ioredis`.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { CequreKV } from "@cequrebackends/cequre-ts";
|
|
8
|
+
* const kv = new CequreKV({ driver: "redis", redis: { url: "redis://localhost:6379" } });
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare class RedisAdapter implements KVAdapter {
|
|
12
|
+
private redis;
|
|
13
|
+
constructor(options?: {
|
|
14
|
+
url?: string;
|
|
15
|
+
});
|
|
16
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
17
|
+
getMany<T = unknown>(keys: string[]): Promise<Map<string, T>>;
|
|
18
|
+
set(key: string, value: unknown, ttl?: number): Promise<void>;
|
|
19
|
+
setMany(entries: Array<{
|
|
20
|
+
key: string;
|
|
21
|
+
value: unknown;
|
|
22
|
+
ttl?: number;
|
|
23
|
+
}>): Promise<void>;
|
|
24
|
+
delete(key: string): Promise<boolean>;
|
|
25
|
+
deleteMany(keys: string[]): Promise<number>;
|
|
26
|
+
has(key: string): Promise<boolean>;
|
|
27
|
+
keys(prefix?: string): Promise<string[]>;
|
|
28
|
+
count(): Promise<number>;
|
|
29
|
+
clear(): Promise<void>;
|
|
30
|
+
cleanup(): number;
|
|
31
|
+
close(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SerializableResponseBody = string | number | boolean | null | undefined | Record<string, unknown> | unknown[];
|
|
2
|
+
export declare const UPGRADED: unique symbol;
|
|
3
|
+
export type BunRouteResult<T = SerializableResponseBody> = Response | T | typeof UPGRADED;
|
|
4
|
+
export declare function json(data: unknown, init?: ResponseInit): Response;
|
|
5
|
+
export declare function empty(status?: number, init?: ResponseInit): Response;
|
|
6
|
+
export declare function redirect(location: string, status?: number, init?: ResponseInit): Response;
|
|
7
|
+
export declare function error(message: string, status?: number, code?: string, init?: ResponseInit): Response;
|
|
8
|
+
export declare function notFound(message?: string): Response;
|
|
9
|
+
export declare function methodNotAllowed(allowedMethods: string[]): Response;
|
|
10
|
+
export declare function file(file: Blob | ArrayBuffer | Uint8Array | string, init?: ResponseInit): Response;
|
|
11
|
+
export declare function stream(data: ReadableStream | AsyncIterable<unknown> | Iterable<unknown>, init?: ResponseInit): Response;
|
|
12
|
+
export declare function toResponse(result: BunRouteResult): Response | undefined;
|
|
13
|
+
export declare function routeErrorToResponse(errorValue: unknown, request?: Request): Response;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StorageProvider, UploadedFile } from '../../shared/core/types';
|
|
2
|
+
export declare class NodeLocalStorageProvider implements StorageProvider {
|
|
3
|
+
private readonly uploadDir;
|
|
4
|
+
private readonly apiPrefix;
|
|
5
|
+
constructor(uploadDir?: string, apiPrefix?: string);
|
|
6
|
+
saveFile(file: File, options?: {
|
|
7
|
+
filename?: string;
|
|
8
|
+
}): Promise<UploadedFile>;
|
|
9
|
+
deleteFile(filename: string): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export interface CequreServerWebSocket {
|
|
2
|
+
id: string;
|
|
3
|
+
data: Record<string, unknown>;
|
|
4
|
+
send(message: string | ArrayBuffer | Uint8Array, compress?: boolean): number;
|
|
5
|
+
}
|
|
6
|
+
export interface CequreWebSocketData {
|
|
7
|
+
id: string;
|
|
8
|
+
path: string;
|
|
9
|
+
handler: CequreWebSocketHandler;
|
|
10
|
+
}
|
|
11
|
+
type BroadcastOptions = {
|
|
12
|
+
exclude?: string[];
|
|
13
|
+
};
|
|
14
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
15
|
+
export interface CequreWebSocketHandler {
|
|
16
|
+
open?(ws: CequreServerWebSocket): void | Promise<void>;
|
|
17
|
+
message?(ws: CequreServerWebSocket, message: string | Buffer): void | Promise<void>;
|
|
18
|
+
close?(ws: CequreServerWebSocket, code: number, reason: string): void | Promise<void>;
|
|
19
|
+
drain?(ws: CequreServerWebSocket): void | Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare class NodeWebSocketManager {
|
|
22
|
+
private connections;
|
|
23
|
+
private rooms;
|
|
24
|
+
private connectionRooms;
|
|
25
|
+
private metadata;
|
|
26
|
+
private lastPong;
|
|
27
|
+
private heartbeatTimer;
|
|
28
|
+
register(ws: CequreServerWebSocket): void;
|
|
29
|
+
remove(wsOrId: CequreServerWebSocket | string): void;
|
|
30
|
+
pong(id: string): void;
|
|
31
|
+
startHeartbeat(intervalMs?: number, timeoutMs?: number): void;
|
|
32
|
+
stopHeartbeat(): void;
|
|
33
|
+
joinRoom(id: string, room: string): void;
|
|
34
|
+
leaveRoom(id: string, room: string): void;
|
|
35
|
+
getRoomMembers(room: string): string[];
|
|
36
|
+
getConnectionRooms(id: string): string[];
|
|
37
|
+
listRooms(): string[];
|
|
38
|
+
sendTo(id: string, payload: unknown): boolean;
|
|
39
|
+
broadcastToRoom(room: string, payload: unknown, { exclude }?: BroadcastOptions): number;
|
|
40
|
+
broadcastAll(payload: unknown, { exclude }?: BroadcastOptions): number;
|
|
41
|
+
setMeta(id: string, key: string, value: unknown): void;
|
|
42
|
+
getMeta(id: string, key: string): unknown;
|
|
43
|
+
get connectionCount(): number;
|
|
44
|
+
get roomCount(): number;
|
|
45
|
+
getStats(): {
|
|
46
|
+
connections: number;
|
|
47
|
+
rooms: {
|
|
48
|
+
[k: string]: number;
|
|
49
|
+
};
|
|
50
|
+
heartbeatActive: boolean;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export declare const wsManager: NodeWebSocketManager;
|
|
54
|
+
export declare function createWebSocketHandler({ heartbeat, onJoinRoom, }?: {
|
|
55
|
+
heartbeat?: {
|
|
56
|
+
interval?: number;
|
|
57
|
+
timeout?: number;
|
|
58
|
+
} | false;
|
|
59
|
+
onJoinRoom?: (room: string, ws: CequreServerWebSocket) => MaybePromise<boolean>;
|
|
60
|
+
}): CequreWebSocketHandler;
|
|
61
|
+
export declare function createNodeWebSocketRoute({ path, heartbeat, onJoinRoom, }?: {
|
|
62
|
+
path?: string;
|
|
63
|
+
heartbeat?: {
|
|
64
|
+
interval?: number;
|
|
65
|
+
timeout?: number;
|
|
66
|
+
} | false;
|
|
67
|
+
onJoinRoom?: (room: string, ws: CequreServerWebSocket) => MaybePromise<boolean>;
|
|
68
|
+
}): (request: Request, server: any) => Promise<Response>;
|
|
69
|
+
export declare class CequreWebsocket {
|
|
70
|
+
static get manager(): NodeWebSocketManager;
|
|
71
|
+
static route(options?: Parameters<typeof createNodeWebSocketRoute>[0]): (request: Request, server: any) => Promise<Response>;
|
|
72
|
+
static handler(options?: Parameters<typeof createWebSocketHandler>[0]): CequreWebSocketHandler;
|
|
73
|
+
static register(ws: CequreServerWebSocket): void;
|
|
74
|
+
static remove(wsOrId: CequreServerWebSocket | string): void;
|
|
75
|
+
static pong(id: string): void;
|
|
76
|
+
static startHeartbeat(intervalMs?: number, timeoutMs?: number): void;
|
|
77
|
+
static stopHeartbeat(): void;
|
|
78
|
+
static joinRoom(id: string, room: string): void;
|
|
79
|
+
static leaveRoom(id: string, room: string): void;
|
|
80
|
+
static getRoomMembers(room: string): string[];
|
|
81
|
+
static getConnectionRooms(id: string): string[];
|
|
82
|
+
static listRooms(): string[];
|
|
83
|
+
static sendTo(id: string, payload: unknown): boolean;
|
|
84
|
+
static broadcastToRoom(room: string, payload: unknown, opts?: {
|
|
85
|
+
exclude?: string[];
|
|
86
|
+
}): number;
|
|
87
|
+
static broadcastAll(payload: unknown, opts?: {
|
|
88
|
+
exclude?: string[];
|
|
89
|
+
}): number;
|
|
90
|
+
static setMeta(id: string, key: string, value: unknown): void;
|
|
91
|
+
static getMeta(id: string, key: string): unknown;
|
|
92
|
+
static get connectionCount(): number;
|
|
93
|
+
static get roomCount(): number;
|
|
94
|
+
static getStats(): {
|
|
95
|
+
connections: number;
|
|
96
|
+
rooms: {
|
|
97
|
+
[k: string]: number;
|
|
98
|
+
};
|
|
99
|
+
heartbeatActive: boolean;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
function __accessProp(key) {
|
|
7
|
+
return this[key];
|
|
8
|
+
}
|
|
9
|
+
var __toCommonJS = (from) => {
|
|
10
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
11
|
+
if (entry)
|
|
12
|
+
return entry;
|
|
13
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (var key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(entry, key))
|
|
17
|
+
__defProp(entry, key, {
|
|
18
|
+
get: __accessProp.bind(from, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
__moduleCache.set(from, entry);
|
|
23
|
+
return entry;
|
|
24
|
+
};
|
|
25
|
+
var __moduleCache;
|
|
26
|
+
var __returnValue = (v) => v;
|
|
27
|
+
function __exportSetter(name, newValue) {
|
|
28
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
29
|
+
}
|
|
30
|
+
var __export = (target, all) => {
|
|
31
|
+
for (var name in all)
|
|
32
|
+
__defProp(target, name, {
|
|
33
|
+
get: all[name],
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
set: __exportSetter.bind(all, name)
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
40
|
+
var __require = import.meta.require;
|
|
41
|
+
|
|
42
|
+
// shared/core/ulid.ts
|
|
43
|
+
var ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
44
|
+
var TIME_LEN = 10;
|
|
45
|
+
var RANDOM_LEN = 16;
|
|
46
|
+
function ulid(seedTime = Date.now()) {
|
|
47
|
+
let str = "";
|
|
48
|
+
let now = seedTime;
|
|
49
|
+
for (let len = TIME_LEN;len > 0; len--) {
|
|
50
|
+
const mod = now % 32;
|
|
51
|
+
str = ENCODING.charAt(mod) + str;
|
|
52
|
+
now = (now - mod) / 32;
|
|
53
|
+
}
|
|
54
|
+
const randomBytes = new Uint8Array(RANDOM_LEN);
|
|
55
|
+
crypto.getRandomValues(randomBytes);
|
|
56
|
+
for (let i = 0;i < RANDOM_LEN; i++) {
|
|
57
|
+
str += ENCODING.charAt(randomBytes[i] & 31);
|
|
58
|
+
}
|
|
59
|
+
return str;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// shared/utils/url.ts
|
|
63
|
+
function extractPathname(url) {
|
|
64
|
+
const protocolIndex = url.indexOf("://");
|
|
65
|
+
const pathStart = protocolIndex === -1 ? 0 : url.indexOf("/", protocolIndex + 3);
|
|
66
|
+
if (pathStart === -1)
|
|
67
|
+
return "/";
|
|
68
|
+
const queryStart = url.indexOf("?", pathStart);
|
|
69
|
+
return queryStart === -1 ? url.slice(pathStart) : url.slice(pathStart, queryStart);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// shared/utils/error.ts
|
|
73
|
+
class CequreError extends Error {
|
|
74
|
+
code;
|
|
75
|
+
status;
|
|
76
|
+
constructor(message, code = "INTERNAL_ERROR", status = 500) {
|
|
77
|
+
super(message);
|
|
78
|
+
this.name = this.constructor.name;
|
|
79
|
+
this.code = code;
|
|
80
|
+
this.status = status;
|
|
81
|
+
}
|
|
82
|
+
toJSON() {
|
|
83
|
+
return {
|
|
84
|
+
error: this.code,
|
|
85
|
+
message: this.message
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
static BadRequest = (message = "Bad request") => new CequreError(message, "BAD_REQUEST", 400);
|
|
89
|
+
static Unauthorized = (message = "Unauthorized") => new CequreError(message, "UNAUTHORIZED", 401);
|
|
90
|
+
static NotImplemented = (message = "Not implemented") => new CequreError(message, "NOT_IMPLEMENTED", 501);
|
|
91
|
+
static NotConfigured = (message = "Not configured") => new CequreError(message, "NOT_CONFIGURED", 428);
|
|
92
|
+
static Forbidden = (message = "Forbidden") => new CequreError(message, "FORBIDDEN", 403);
|
|
93
|
+
static NotFound = (message = "Not found") => new CequreError(message, "NOT_FOUND", 404);
|
|
94
|
+
static Conflict = (message = "Conflict") => new CequreError(message, "CONFLICT", 409);
|
|
95
|
+
static TooManyRequests = (message = "Too many requests") => new CequreError(message, "TOO_MANY_REQUESTS", 429);
|
|
96
|
+
static SubscriptionRequired = (message = "Subscription required") => new CequreError(message, "SUBSCRIPTION_REQUIRED", 402);
|
|
97
|
+
static Internal = (message = "An unexpected error occurred. Please try again later.") => new CequreError(message, "INTERNAL_ERROR", 500);
|
|
98
|
+
}
|
|
99
|
+
function parseConstraintError(error, adapter) {
|
|
100
|
+
if (adapter?.parseConstraintError) {
|
|
101
|
+
return adapter.parseConstraintError(error);
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
function getConstraintErrorMessage(parsed) {
|
|
106
|
+
switch (parsed.type) {
|
|
107
|
+
case "foreign_key":
|
|
108
|
+
if (parsed.referencedTable) {
|
|
109
|
+
return `The value "${parsed.column}" references a non-existent record in "${parsed.referencedTable}". Please ensure the referenced record exists.`;
|
|
110
|
+
}
|
|
111
|
+
return "This operation violates a foreign key constraint. The referenced record does not exist.";
|
|
112
|
+
case "unique":
|
|
113
|
+
if (parsed.column) {
|
|
114
|
+
return `A record with this "${parsed.column}" value already exists. Please use a different value.`;
|
|
115
|
+
}
|
|
116
|
+
return "A record with this value already exists. Please use a different value.";
|
|
117
|
+
case "not_null":
|
|
118
|
+
return `The field "${parsed.column}" is required and cannot be empty.`;
|
|
119
|
+
case "check":
|
|
120
|
+
return `The value violates a validation rule (constraint: ${parsed.constraint}).`;
|
|
121
|
+
case "exclusion":
|
|
122
|
+
return "This value conflicts with an existing record.";
|
|
123
|
+
default:
|
|
124
|
+
return parsed.rawMessage;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function getConstraintErrorStatus(type) {
|
|
128
|
+
switch (type) {
|
|
129
|
+
case "foreign_key":
|
|
130
|
+
case "unique":
|
|
131
|
+
case "check":
|
|
132
|
+
case "exclusion":
|
|
133
|
+
return 409;
|
|
134
|
+
case "not_null":
|
|
135
|
+
return 400;
|
|
136
|
+
default:
|
|
137
|
+
return 500;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function buildErrorResponse(error, request, adapter) {
|
|
141
|
+
const timestamp = new Date().toISOString();
|
|
142
|
+
const path = request ? extractPathname(request.url) : undefined;
|
|
143
|
+
let statusCode = 500;
|
|
144
|
+
let code = "INTERNAL_ERROR";
|
|
145
|
+
let message = "An unexpected error occurred. Please try again later.";
|
|
146
|
+
if (error instanceof CequreError) {
|
|
147
|
+
statusCode = error.status;
|
|
148
|
+
code = error.code;
|
|
149
|
+
message = error.message;
|
|
150
|
+
} else if (error instanceof Error) {
|
|
151
|
+
const parsedConstraint = adapter ? parseConstraintError(error, adapter) : null;
|
|
152
|
+
if (parsedConstraint) {
|
|
153
|
+
statusCode = getConstraintErrorStatus(parsedConstraint.type);
|
|
154
|
+
code = `CONSTRAINT_${parsedConstraint.type.toUpperCase()}`;
|
|
155
|
+
message = getConstraintErrorMessage(parsedConstraint);
|
|
156
|
+
if (true) {
|
|
157
|
+
message += ` (${parsedConstraint.rawMessage})`;
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
if (true) {
|
|
161
|
+
message = error.message;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return { code, message, statusCode, timestamp, ...path ? { path } : {} };
|
|
166
|
+
}
|
|
167
|
+
function toErrorResponse(error, request, adapter) {
|
|
168
|
+
const body = buildErrorResponse(error, request, adapter);
|
|
169
|
+
return new Response(JSON.stringify(body), {
|
|
170
|
+
status: body.statusCode,
|
|
171
|
+
headers: { "Content-Type": "application/json" }
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { __toCommonJS, __export, __esm, __require, ulid, extractPathname, CequreError, parseConstraintError, getConstraintErrorMessage, getConstraintErrorStatus, buildErrorResponse, toErrorResponse };
|