forked from supabase/postgres-meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
120 lines (104 loc) · 2.59 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
import { expect, test } from 'vitest'
import { pgMeta } from './utils'
test('list', async () => {
const res = await pgMeta.types.list()
expect(res.data?.find(({ name }) => name === 'user_status')).toMatchInlineSnapshot(
{ id: expect.any(Number) },
`
{
"attributes": [],
"comment": null,
"enums": [
"ACTIVE",
"INACTIVE",
],
"format": "user_status",
"id": Any<Number>,
"name": "user_status",
"schema": "public",
}
`
)
})
test('list types with included schemas', async () => {
let res = await pgMeta.types.list({
includedSchemas: ['public'],
})
expect(res.data?.length).toBeGreaterThan(0)
res.data?.forEach((type) => {
expect(type.schema).toBe('public')
})
})
test('list types with excluded schemas', async () => {
let res = await pgMeta.types.list({
excludedSchemas: ['public'],
})
res.data?.forEach((type) => {
expect(type.schema).not.toBe('public')
})
})
test('list types with excluded schemas and include System Schemas', async () => {
let res = await pgMeta.types.list({
excludedSchemas: ['public'],
includeSystemSchemas: true,
})
expect(res.data?.length).toBeGreaterThan(0)
res.data?.forEach((type) => {
expect(type.schema).not.toBe('public')
})
})
test('list types with include Table Types', async () => {
const res = await pgMeta.types.list({
includeTableTypes: true,
})
expect(res.data?.find(({ name }) => name === 'todos')).toMatchInlineSnapshot(
{ id: expect.any(Number) },
`
{
"attributes": [],
"comment": null,
"enums": [],
"format": "todos",
"id": Any<Number>,
"name": "todos",
"schema": "public",
}
`
)
})
test('list types without Table Types', async () => {
const res = await pgMeta.types.list({
includeTableTypes: false,
})
res.data?.forEach((type) => {
expect(type.name).not.toBe('todos')
})
})
test('composite type attributes', async () => {
await pgMeta.query(`create type test_composite as (id int8, data text);`)
const res = await pgMeta.types.list()
expect(res.data?.find(({ name }) => name === 'test_composite')).toMatchInlineSnapshot(
{ id: expect.any(Number) },
`
{
"attributes": [
{
"name": "id",
"type_id": 20,
},
{
"name": "data",
"type_id": 25,
},
],
"comment": null,
"enums": [],
"format": "test_composite",
"id": Any<Number>,
"name": "test_composite",
"schema": "public",
}
`
)
await pgMeta.query(`drop type test_composite;`)
})