-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
131 lines (114 loc) · 2.72 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import {
Server,
ServerRequest,
} from "https://deno.land/std@0.100.0/http/server.ts";
import { ConnectionParams } from "https://deno.land/x/postgres@v0.11.3/connection/connection_params.ts";
import { PoolClient } from "https://deno.land/x/postgres@v0.11.3/client.ts";
import { QueryArrayResult } from "https://deno.land/x/postgres@v0.11.3/query/query.ts";
import { RedisConnectOptions } from "https://deno.land/x/redis@v0.22.2/mod.ts";
export interface RunServerPropsType {
server: Server;
connections: {
postgres: {
connectionParams: string | ConnectionParams | undefined;
maxsize: number;
lazy?: boolean;
};
redis?: RedisConnectOptions;
};
logging?: boolean;
tables: Record<string, Table>;
}
export interface Table {
operations: Record<string, Operation>;
}
export interface Operation {
allowed: boolean;
onRequest?: () => void;
}
interface CreateQueryProps {
// create query props
fields?: Array<string>;
data?: Array<Array<number | string>>;
returning?: Array<string>;
}
interface UpdateQueryProps {
// update query props
new?: Record<string, string | number>;
where?: Array<WhereType>;
}
interface WhereType {
field: string;
operator: string;
input: string | number;
// boolean condition like OR and AND
nextCondition?: string;
}
interface ReadQueryProps {
distinct?: boolean;
join?: {
table: string;
cross?: boolean;
// Default join is inner;
outer?: {
// left, right or full
type: string;
};
natural?: boolean;
on?: string;
using?: Array<string>;
};
group?: Array<string>;
having?: Array<WhereType>;
order?: Array<{
by: string;
desc?: boolean;
nulls?: string;
}>;
limit?: number;
offset?: number;
}
export interface RequestBodyType
extends CreateQueryProps, UpdateQueryProps, ReadQueryProps {
cache?: {
key: string;
expiration: number;
};
}
export interface RouteExtractPropsType {
url: string;
}
export interface RouteExtractReturnType {
table: string;
operation: string;
}
export interface ParseRequestBodyPropsType {
request: ServerRequest;
}
export interface QueryPropsType {
request: ServerRequest;
reqBody: RequestBodyType;
table: string;
client: PoolClient;
}
export interface QueryRespondPropsType
extends QueryPropsType, RouteExtractReturnType {
queryFn: (props: QueryPropsType) => Promise<QueryArrayResult<undefined[]>>;
}
export interface SendResponsePropsType {
request: ServerRequest;
data?: unknown;
error?: {
status?: number;
message: string;
};
}
export interface WhereProps extends WhereReturn {
reqBody: RequestBodyType;
name: string;
}
export interface WhereReturn {
query: string;
param: number;
args: Array<string | number>;
}