11import { pgMeta } from './utils'
22
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+
320test ( 'list' , async ( ) => {
421 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 ( `
824 {
925 "columns": [
1026 {
@@ -13,7 +29,6 @@ test('list', async () => {
1329 "default_value": null,
1430 "enums": [],
1531 "format": "int8",
16- "id": "16434.1",
1732 "identity_generation": null,
1833 "is_generated": false,
1934 "is_identity": false,
@@ -24,15 +39,13 @@ test('list', async () => {
2439 "ordinal_position": 1,
2540 "schema": "public",
2641 "table": "foreign_table",
27- "table_id": 16434,
2842 },
2943 {
3044 "comment": null,
3145 "data_type": "text",
3246 "default_value": null,
3347 "enums": [],
3448 "format": "text",
35- "id": "16434.2",
3649 "identity_generation": null,
3750 "is_generated": false,
3851 "is_identity": false,
@@ -43,7 +56,6 @@ test('list', async () => {
4356 "ordinal_position": 2,
4457 "schema": "public",
4558 "table": "foreign_table",
46- "table_id": 16434,
4759 },
4860 {
4961 "comment": null,
@@ -54,7 +66,6 @@ test('list', async () => {
5466 "INACTIVE",
5567 ],
5668 "format": "user_status",
57- "id": "16434.3",
5869 "identity_generation": null,
5970 "is_generated": false,
6071 "is_identity": false,
@@ -65,40 +76,30 @@ test('list', async () => {
6576 "ordinal_position": 3,
6677 "schema": "public",
6778 "table": "foreign_table",
68- "table_id": 16434,
6979 },
7080 ],
7181 "comment": null,
72- "id": Any<Number>,
7382 "name": "foreign_table",
7483 "schema": "public",
7584 }
76- `
77- )
85+ ` )
7886} )
7987
8088test ( 'list without columns' , async ( ) => {
8189 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 ( `
8792 {
8893 "comment": null,
89- "id": Any<Number>,
9094 "name": "foreign_table",
9195 "schema": "public",
9296 }
93- `
94- )
97+ ` )
9598} )
9699
97100test ( 'retrieve' , async ( ) => {
98101 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 ( `
102103 {
103104 "data": {
104105 "columns": [
@@ -108,7 +109,6 @@ test('retrieve', async () => {
108109 "default_value": null,
109110 "enums": [],
110111 "format": "int8",
111- "id": "16434.1",
112112 "identity_generation": null,
113113 "is_generated": false,
114114 "is_identity": false,
@@ -119,15 +119,13 @@ test('retrieve', async () => {
119119 "ordinal_position": 1,
120120 "schema": "public",
121121 "table": "foreign_table",
122- "table_id": 16434,
123122 },
124123 {
125124 "comment": null,
126125 "data_type": "text",
127126 "default_value": null,
128127 "enums": [],
129128 "format": "text",
130- "id": "16434.2",
131129 "identity_generation": null,
132130 "is_generated": false,
133131 "is_identity": false,
@@ -138,7 +136,6 @@ test('retrieve', async () => {
138136 "ordinal_position": 2,
139137 "schema": "public",
140138 "table": "foreign_table",
141- "table_id": 16434,
142139 },
143140 {
144141 "comment": null,
@@ -149,7 +146,6 @@ test('retrieve', async () => {
149146 "INACTIVE",
150147 ],
151148 "format": "user_status",
152- "id": "16434.3",
153149 "identity_generation": null,
154150 "is_generated": false,
155151 "is_identity": false,
@@ -160,16 +156,13 @@ test('retrieve', async () => {
160156 "ordinal_position": 3,
161157 "schema": "public",
162158 "table": "foreign_table",
163- "table_id": 16434,
164159 },
165160 ],
166161 "comment": null,
167- "id": Any<Number>,
168162 "name": "foreign_table",
169163 "schema": "public",
170164 },
171165 "error": null,
172166 }
173- `
174- )
167+ ` )
175168} )
0 commit comments