-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
208 lines (178 loc) · 5.58 KB
/
types.ts
File metadata and controls
208 lines (178 loc) · 5.58 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
const aggregates = ["MAX", "MIN", "AVG", "COUNT", "SUM"] as const;
export const subJoins = ["RIGHT OUTER JOIN", "LEFT OUTER JOIN", "INNER JOIN" ] as const;
const joins = [...subJoins, "CROSS JOIN", "FULL OUTER JOIN"] as const;
const constraints = ["numericRange", "numericComparison", "stringFuzzyComparison", "stringComparison", "nullComparison"] as const;
const clauses = ["selectList", "tableList", "whereClause", "havingClause", "groupBy", "orderBy"] as const;
const cardinalities = ["1-n", "1-n?", "1?-n", "n-m", "n?-m", "n?-m?"] as const;
export const queryConstituents: Array<string> = [...aggregates, ...subJoins, ...constraints, ...clauses, "groupBy", "orderBy", "aggregates", ];
export type AggregateType = (typeof aggregates)[number] | null;
export type JoinType = (typeof joins)[number];
export type SubJoinType = (typeof subJoins)[number];
export type CardinalityType = (typeof cardinalities)[number];
export type ConstraintType = (typeof constraints)[number];
export type ClauseType = (typeof clauses)[number];
export type SQLConstituentType = AggregateType | SubJoinType | AggregateType | ConstraintType | ClauseType;
export type SubConstituentCounts = {
[key in SQLConstituentType]: number;
}
export interface ConstituentCounts extends SubConstituentCounts {
JOINS: number;
TABLES: number;
COLUMNS: number;
}
export const isQueryConstituent = (queryConstituent: string): queryConstituent is SQLConstituentType => {
return queryConstituents.includes(queryConstituent);
}
export const isInTypeArray = <T, A extends T>(
item: T,
array: ReadonlyArray<A>
): item is A => (array as ReadonlyArray<unknown>).includes(item as A);
export interface IOptions {
joinRange: Array<number>;
joinType: Array<JoinType>;
cardinalityType: Array<CardinalityType>;
columnRange: Array<number>;
constraintRange: Array<number>;
constraintType: Array<ConstraintType>;
allowAggregates: boolean;
aggregateType: Array<AggregateType>;
forceHavingClause: boolean;
forceOrderBy: boolean;
schema: string;
seed: string;
}
export type Await<T> = T extends {
then(onfulfilled?: (value: infer U) => unknown): unknown;
}
? U
: T;
export interface IReference {
columns: { target: string; source: string };
table: string;
selfJoin?: boolean;
}
export type numberType = "real" | "int" | "decimal" | "numeric" | "double" | "precision" | "serial";
export type stringType = "char"| "text";
export type dateType = "date" | "time" | "interval";
export type booleanType = "boolean";
export type uuidType = "uuid";
export type binaryType = "bytea";
export type currencyType = "money";
export interface ITypeMap {
number: Array<numberType>
string: Array<stringType>
date:Array<dateType>
boolean: Array<booleanType>;
uuid: Array<uuidType>;
binary: Array<binaryType>;
currency: Array<currencyType>;
};
export interface IParsedTable {
[tableName: string]: {
references: Array<IReference>;
columns: {
[columnName: string]: {
type: keyof ITypeMap | "unknown";
};
};
};
}
export interface IParsedForeignKeys {
source: {
table: any;
columns: {
source: any;
target: any;
};
};
target: {
table: any;
columns: {
source: any;
target: any;
};
};
}
export interface IParsedPrimaryKey {
[tableName: string]: {
keyColumns: Array<string>;
};
}
export interface IMetaData {
tables: IParsedTable;
foreignKeys: Array<IParsedForeignKeys>;
primaryKeys: IParsedPrimaryKey;
primaryTables?: Array<string>;
junctionTables?: Array<string>;
attributeTables?: Array<string>;
}
export interface IEdge {
table: keyof IParsedTable;
columns: { source: string; target: string };
type?: SubJoinType;
selfJoin?: boolean;
}
export type Path = Array<IEdge>;
export type Paths = Array<Path>;
export interface IJoinables {
[tableName: string]: Paths;
}
export interface IJoinInstruction {
table: string;
path: Path;
}
export interface IColumn {
name: string;
type: string;
aggregation?: AggregateType;
}
export interface IColumns {
[tableName: string]: Array<IColumn>;
}
export type ConstraintConjunction = "AND" | "OR";
export interface IConstraint {
operator: string | null;
values: Array<string | number | null>;
}
export interface IConstraintColumn extends IColumn {
constraint: IConstraint;
conjunction?: ConstraintConjunction | null;
}
export interface IConstraintColumns extends IColumns {
[tableName: string]: Array<IConstraintColumn>;
}
export interface IDestructuredColumn extends IColumn {
table: string;
constraint?: IConstraint;
aggregation?: AggregateType;
}
export interface IDestructuredColumns {
tables: { [key: string]: [] };
columns: Array<IDestructuredColumn>;
}
export interface IHavingClauseColumn extends IColumn {
constraint: IConstraint;
aggregation: AggregateType;
}
export interface IHavingClause extends IColumns {
[tableName: string]: Array<IHavingClauseColumn>;
}
export interface IAliasDictionary {
[tableName: string]: string;
}
export interface IOrderByColumn extends IColumn {
orderBy: string;
table: string;
}
export interface IOrderByColumns extends IColumns {
[tableName: string]: Array<IOrderByColumn>;
}
export interface IStructuredQuery {
columns: IColumns;
join: IJoinInstruction;
whereClause: IConstraintColumns;
groupBy: IColumns;
havingClause: IHavingClause;
orderBy: IOrderByColumns;
aliasDictionary: IAliasDictionary;
}