Skip to content

Commit c280001

Browse files
committed
refactor: 💩 Refactors tables from JS file to TS
This is more of a kaizen - setting up a basic type for the tables. It's missing the "subitems" like columns typings.
1 parent 7ae2999 commit c280001

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

dist/lib/interfaces/tables.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

src/api/tables.js renamed to src/api/tables.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ const router = new Router()
33
const { tables } = require('../lib/sql')
44
const RunQuery = require('../lib/connectionPool')
55
import { DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants/schemas'
6+
import { Tables } from '../lib/interfaces/tables'
67

78
router.get('/', async (req, res) => {
89
try {
910
const { data } = await RunQuery(req.headers.pg, tables.list)
10-
const query = req.query
11-
let payload = data
11+
const query: Fetch.QueryParams = req.query
12+
let payload: Tables.Table[] = data
1213
if (!query?.includeSystemSchemas) payload = removeSystemSchemas(data)
1314
return res.status(200).json(payload)
1415
} catch (error) {
@@ -19,6 +20,19 @@ router.get('/', async (req, res) => {
1920

2021
module.exports = router
2122

22-
const removeSystemSchemas = (data) => {
23+
const removeSystemSchemas = (data: Tables.Table[]) => {
2324
return data.filter((x) => !DEFAULT_SYSTEM_SCHEMAS.includes(x.schema))
25+
}
26+
27+
/**
28+
* Types
29+
*/
30+
31+
namespace Fetch {
32+
/**
33+
* @param {boolean} [includeSystemSchemas=false] - Return system schemas as well as user schemas
34+
*/
35+
export interface QueryParams {
36+
includeSystemSchemas: boolean
37+
}
2438
}

src/lib/interfaces/tables.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export namespace Tables {
2+
3+
export interface Table {
4+
table_id: string
5+
catalog: string
6+
schema: string
7+
name: string
8+
is_insertable_into: boolean
9+
is_typed: boolean
10+
bytes: number
11+
size: string
12+
}
13+
14+
}
15+

0 commit comments

Comments
 (0)