1
1
import { pgMeta } from './utils'
2
2
3
+ const cleanNondetFromResponse = < T > ( x : T ) => {
4
+ const { data, ...rest } = x as any
5
+
6
+ const cleanNondetFromData = ( { id, columns, ...rest } : any ) => {
7
+ const cleaned = rest
8
+ if ( columns ) {
9
+ cleaned . columns = columns . map ( ( { id, table_id, ...rest } : any ) => rest )
10
+ }
11
+ return cleaned
12
+ }
13
+
14
+ return {
15
+ data : Array . isArray ( data ) ? data . map ( cleanNondetFromData ) : cleanNondetFromData ( data ) ,
16
+ ...rest ,
17
+ } as T
18
+ }
19
+
3
20
test ( 'list' , async ( ) => {
4
21
const res = await pgMeta . foreignTables . list ( )
5
- expect ( res . data ?. find ( ( { name } ) => name === 'foreign_table' ) ) . toMatchInlineSnapshot (
6
- { id : expect . any ( Number ) } ,
7
- `
22
+ expect ( cleanNondetFromResponse ( res ) . data ?. find ( ( { name } ) => name === 'foreign_table' ) )
23
+ . toMatchInlineSnapshot ( `
8
24
{
9
25
"columns": [
10
26
{
@@ -13,7 +29,6 @@ test('list', async () => {
13
29
"default_value": null,
14
30
"enums": [],
15
31
"format": "int8",
16
- "id": "16434.1",
17
32
"identity_generation": null,
18
33
"is_generated": false,
19
34
"is_identity": false,
@@ -24,15 +39,13 @@ test('list', async () => {
24
39
"ordinal_position": 1,
25
40
"schema": "public",
26
41
"table": "foreign_table",
27
- "table_id": 16434,
28
42
},
29
43
{
30
44
"comment": null,
31
45
"data_type": "text",
32
46
"default_value": null,
33
47
"enums": [],
34
48
"format": "text",
35
- "id": "16434.2",
36
49
"identity_generation": null,
37
50
"is_generated": false,
38
51
"is_identity": false,
@@ -43,7 +56,6 @@ test('list', async () => {
43
56
"ordinal_position": 2,
44
57
"schema": "public",
45
58
"table": "foreign_table",
46
- "table_id": 16434,
47
59
},
48
60
{
49
61
"comment": null,
@@ -54,7 +66,6 @@ test('list', async () => {
54
66
"INACTIVE",
55
67
],
56
68
"format": "user_status",
57
- "id": "16434.3",
58
69
"identity_generation": null,
59
70
"is_generated": false,
60
71
"is_identity": false,
@@ -65,40 +76,30 @@ test('list', async () => {
65
76
"ordinal_position": 3,
66
77
"schema": "public",
67
78
"table": "foreign_table",
68
- "table_id": 16434,
69
79
},
70
80
],
71
81
"comment": null,
72
- "id": Any<Number>,
73
82
"name": "foreign_table",
74
83
"schema": "public",
75
84
}
76
- `
77
- )
85
+ ` )
78
86
} )
79
87
80
88
test ( 'list without columns' , async ( ) => {
81
89
const res = await pgMeta . foreignTables . list ( { includeColumns : false } )
82
- expect ( res . data ?. find ( ( { name } ) => name === 'foreign_table' ) ) . toMatchInlineSnapshot (
83
- {
84
- id : expect . any ( Number ) ,
85
- } ,
86
- `
90
+ expect ( cleanNondetFromResponse ( res ) . data ?. find ( ( { name } ) => name === 'foreign_table' ) )
91
+ . toMatchInlineSnapshot ( `
87
92
{
88
93
"comment": null,
89
- "id": Any<Number>,
90
94
"name": "foreign_table",
91
95
"schema": "public",
92
96
}
93
- `
94
- )
97
+ ` )
95
98
} )
96
99
97
100
test ( 'retrieve' , async ( ) => {
98
101
const res = await pgMeta . foreignTables . retrieve ( { schema : 'public' , name : 'foreign_table' } )
99
- expect ( res ) . toMatchInlineSnapshot (
100
- { data : { id : expect . any ( Number ) } } ,
101
- `
102
+ expect ( cleanNondetFromResponse ( res ) ) . toMatchInlineSnapshot ( `
102
103
{
103
104
"data": {
104
105
"columns": [
@@ -108,7 +109,6 @@ test('retrieve', async () => {
108
109
"default_value": null,
109
110
"enums": [],
110
111
"format": "int8",
111
- "id": "16434.1",
112
112
"identity_generation": null,
113
113
"is_generated": false,
114
114
"is_identity": false,
@@ -119,15 +119,13 @@ test('retrieve', async () => {
119
119
"ordinal_position": 1,
120
120
"schema": "public",
121
121
"table": "foreign_table",
122
- "table_id": 16434,
123
122
},
124
123
{
125
124
"comment": null,
126
125
"data_type": "text",
127
126
"default_value": null,
128
127
"enums": [],
129
128
"format": "text",
130
- "id": "16434.2",
131
129
"identity_generation": null,
132
130
"is_generated": false,
133
131
"is_identity": false,
@@ -138,7 +136,6 @@ test('retrieve', async () => {
138
136
"ordinal_position": 2,
139
137
"schema": "public",
140
138
"table": "foreign_table",
141
- "table_id": 16434,
142
139
},
143
140
{
144
141
"comment": null,
@@ -149,7 +146,6 @@ test('retrieve', async () => {
149
146
"INACTIVE",
150
147
],
151
148
"format": "user_status",
152
- "id": "16434.3",
153
149
"identity_generation": null,
154
150
"is_generated": false,
155
151
"is_identity": false,
@@ -160,16 +156,13 @@ test('retrieve', async () => {
160
156
"ordinal_position": 3,
161
157
"schema": "public",
162
158
"table": "foreign_table",
163
- "table_id": 16434,
164
159
},
165
160
],
166
161
"comment": null,
167
- "id": Any<Number>,
168
162
"name": "foreign_table",
169
163
"schema": "public",
170
164
},
171
165
"error": null,
172
166
}
173
- `
174
- )
167
+ ` )
175
168
} )
0 commit comments