-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathapi.v1.query.schema.ts
More file actions
58 lines (52 loc) · 1.4 KB
/
api.v1.query.schema.ts
File metadata and controls
58 lines (52 loc) · 1.4 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
import { json } from "@remix-run/server-runtime";
import type { ColumnSchema, TableSchema } from "@internal/tsql";
import { createLoaderApiRoute } from "~/services/routeBuilders/apiBuilder.server";
import { querySchemas } from "~/v3/querySchemas";
function serializeColumn(col: ColumnSchema) {
const result: Record<string, unknown> = {
name: col.name,
type: col.type,
};
if (col.description) {
result.description = col.description;
}
if (col.example) {
result.example = col.example;
}
if (col.allowedValues && col.allowedValues.length > 0) {
if (col.valueMap) {
result.allowedValues = Object.values(col.valueMap);
} else {
result.allowedValues = col.allowedValues;
}
}
if (col.coreColumn) {
result.coreColumn = true;
}
return result;
}
function serializeTable(table: TableSchema) {
const columns = Object.values(table.columns).map(serializeColumn);
return {
name: table.name,
description: table.description,
timeColumn: table.timeConstraint,
columns,
};
}
export const loader = createLoaderApiRoute(
{
allowJWT: true,
corsStrategy: "all",
findResource: async () => 1,
authorization: {
action: "read",
resource: () => ({ query: "schema" }),
superScopes: ["read:query", "read:all", "admin"],
},
},
async () => {
const tables = querySchemas.map(serializeTable);
return json({ tables });
}
);