Skip to content

Commit e880b9f

Browse files
authored
Merge branch 'master' into master
2 parents 80db2de + 8ca034c commit e880b9f

23 files changed

+267
-203
lines changed

src/server/routes/column-privileges.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
postgresColumnPrivilegesRevokeSchema,
77
postgresColumnPrivilegesSchema,
88
} from '../../lib/types.js'
9-
import { DEFAULT_POOL_CONFIG } from '../constants.js'
9+
import { createConnectionConfig } from '../utils.js'
1010
import { extractRequestForLogging, translateErrorToResponseCode } from '../utils.js'
1111

1212
const route: FastifyPluginAsyncTypebox = async (fastify) => {
@@ -16,6 +16,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
1616
schema: {
1717
headers: Type.Object({
1818
pg: Type.String(),
19+
'x-pg-application-name': Type.Optional(Type.String()),
1920
}),
2021
querystring: Type.Object({
2122
include_system_schemas: Type.Optional(Type.Boolean()),
@@ -34,14 +35,14 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
3435
},
3536
},
3637
async (request, reply) => {
37-
const connectionString = request.headers.pg
38+
const config = createConnectionConfig(request)
3839
const includeSystemSchemas = request.query.include_system_schemas
3940
const includedSchemas = request.query.included_schemas?.split(',')
4041
const excludedSchemas = request.query.excluded_schemas?.split(',')
4142
const limit = request.query.limit
4243
const offset = request.query.offset
4344

44-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
45+
const pgMeta = new PostgresMeta(config)
4546
const { data, error } = await pgMeta.columnPrivileges.list({
4647
includeSystemSchemas,
4748
includedSchemas,
@@ -66,6 +67,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
6667
schema: {
6768
headers: Type.Object({
6869
pg: Type.String(),
70+
'x-pg-application-name': Type.Optional(Type.String()),
6971
}),
7072
body: Type.Array(postgresColumnPrivilegesGrantSchema),
7173
response: {
@@ -77,9 +79,9 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
7779
},
7880
},
7981
async (request, reply) => {
80-
const connectionString = request.headers.pg
82+
const config = createConnectionConfig(request)
8183

82-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
84+
const pgMeta = new PostgresMeta(config)
8385
const { data, error } = await pgMeta.columnPrivileges.grant(request.body)
8486
await pgMeta.end()
8587
if (error) {
@@ -98,6 +100,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
98100
schema: {
99101
headers: Type.Object({
100102
pg: Type.String(),
103+
'x-pg-application-name': Type.Optional(Type.String()),
101104
}),
102105
body: Type.Array(postgresColumnPrivilegesRevokeSchema),
103106
response: {
@@ -112,9 +115,9 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
112115
},
113116
},
114117
async (request, reply) => {
115-
const connectionString = request.headers.pg
118+
const config = createConnectionConfig(request)
116119

117-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
120+
const pgMeta = new PostgresMeta(config)
118121
const { data, error } = await pgMeta.columnPrivileges.revoke(request.body)
119122
await pgMeta.end()
120123
if (error) {

src/server/routes/columns.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { PostgresMeta } from '../../lib/index.js'
2-
import { DEFAULT_POOL_CONFIG } from '../constants.js'
3-
import { extractRequestForLogging } from '../utils.js'
2+
import { createConnectionConfig, extractRequestForLogging } from '../utils.js'
43
import { Type } from '@sinclair/typebox'
54
import {
65
postgresColumnCreateSchema,
@@ -16,6 +15,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
1615
schema: {
1716
headers: Type.Object({
1817
pg: Type.String(),
18+
'x-pg-application-name': Type.Optional(Type.String()),
1919
}),
2020
querystring: Type.Object({
2121
include_system_schemas: Type.Optional(Type.Boolean()),
@@ -33,14 +33,14 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
3333
},
3434
},
3535
async (request, reply) => {
36-
const connectionString = request.headers.pg
3736
const includeSystemSchemas = request.query.include_system_schemas
3837
const includedSchemas = request.query.included_schemas?.split(',')
3938
const excludedSchemas = request.query.excluded_schemas?.split(',')
4039
const limit = request.query.limit
4140
const offset = request.query.offset
4241

43-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
42+
const config = createConnectionConfig(request)
43+
const pgMeta = new PostgresMeta(config)
4444
const { data, error } = await pgMeta.columns.list({
4545
includeSystemSchemas,
4646
includedSchemas,
@@ -65,6 +65,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
6565
schema: {
6666
headers: Type.Object({
6767
pg: Type.String(),
68+
'x-pg-application-name': Type.Optional(Type.String()),
6869
}),
6970
params: Type.Object({
7071
tableId: Type.String(),
@@ -86,13 +87,13 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
8687
async (request, reply) => {
8788
if (request.params.ordinalPosition === '') {
8889
const {
89-
headers: { pg: connectionString },
9090
query: { limit, offset },
9191
params: { tableId },
9292
} = request
9393
const includeSystemSchemas = request.query.include_system_schemas
9494

95-
const pgMeta: PostgresMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
95+
const config = createConnectionConfig(request)
96+
const pgMeta: PostgresMeta = new PostgresMeta(config)
9697
const { data, error } = await pgMeta.columns.list({
9798
tableId: Number(tableId),
9899
includeSystemSchemas,
@@ -109,12 +110,12 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
109110
return data[0]
110111
} else if (/^\.\d+$/.test(request.params.ordinalPosition)) {
111112
const {
112-
headers: { pg: connectionString },
113113
params: { tableId, ordinalPosition: ordinalPositionWithDot },
114114
} = request
115115
const ordinalPosition = ordinalPositionWithDot.slice(1)
116116

117-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
117+
const config = createConnectionConfig(request)
118+
const pgMeta = new PostgresMeta(config)
118119
const { data, error } = await pgMeta.columns.retrieve({
119120
id: `${tableId}.${ordinalPosition}`,
120121
})
@@ -139,6 +140,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
139140
schema: {
140141
headers: Type.Object({
141142
pg: Type.String(),
143+
'x-pg-application-name': Type.Optional(Type.String()),
142144
}),
143145
body: postgresColumnCreateSchema,
144146
response: {
@@ -150,9 +152,8 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
150152
},
151153
},
152154
async (request, reply) => {
153-
const connectionString = request.headers.pg
154-
155-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
155+
const config = createConnectionConfig(request)
156+
const pgMeta = new PostgresMeta(config)
156157
const { data, error } = await pgMeta.columns.create(request.body)
157158
await pgMeta.end()
158159
if (error) {
@@ -172,6 +173,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
172173
schema: {
173174
headers: Type.Object({
174175
pg: Type.String(),
176+
'x-pg-application-name': Type.Optional(Type.String()),
175177
}),
176178
params: Type.Object({
177179
id: Type.String(),
@@ -186,9 +188,8 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
186188
},
187189
},
188190
async (request, reply) => {
189-
const connectionString = request.headers.pg
190-
191-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
191+
const config = createConnectionConfig(request)
192+
const pgMeta = new PostgresMeta(config)
192193
const { data, error } = await pgMeta.columns.update(request.params.id, request.body)
193194
await pgMeta.end()
194195
if (error) {
@@ -208,6 +209,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
208209
schema: {
209210
headers: Type.Object({
210211
pg: Type.String(),
212+
'x-pg-application-name': Type.Optional(Type.String()),
211213
}),
212214
params: Type.Object({
213215
id: Type.String(),
@@ -224,10 +226,10 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
224226
},
225227
},
226228
async (request, reply) => {
227-
const connectionString = request.headers.pg
228229
const cascade = request.query.cascade === 'true'
229230

230-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
231+
const config = createConnectionConfig(request)
232+
const pgMeta = new PostgresMeta(config)
231233
const { data, error } = await pgMeta.columns.remove(request.params.id, { cascade })
232234
await pgMeta.end()
233235
if (error) {

src/server/routes/config.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { FastifyInstance } from 'fastify'
22
import { PostgresMeta } from '../../lib/index.js'
3-
import { DEFAULT_POOL_CONFIG } from '../constants.js'
3+
import { createConnectionConfig } from '../utils.js'
44
import { extractRequestForLogging } from '../utils.js'
55

66
export default async (fastify: FastifyInstance) => {
77
fastify.get<{
8-
Headers: { pg: string }
8+
Headers: { pg: string; 'x-pg-application-name'?: string }
99
Querystring: {
1010
limit?: number
1111
offset?: number
1212
}
1313
}>('/', async (request, reply) => {
14-
const connectionString = request.headers.pg
14+
const config = createConnectionConfig(request)
1515
const limit = request.query.limit
1616
const offset = request.query.offset
1717

18-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
18+
const pgMeta = new PostgresMeta(config)
1919
const { data, error } = await pgMeta.config.list({ limit, offset })
2020
await pgMeta.end()
2121
if (error) {
@@ -28,11 +28,11 @@ export default async (fastify: FastifyInstance) => {
2828
})
2929

3030
fastify.get<{
31-
Headers: { pg: string }
31+
Headers: { pg: string; 'x-pg-application-name'?: string }
3232
}>('/version', async (request, reply) => {
33-
const connectionString = request.headers.pg
33+
const config = createConnectionConfig(request)
3434

35-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
35+
const pgMeta = new PostgresMeta(config)
3636
const { data, error } = await pgMeta.version.retrieve()
3737
await pgMeta.end()
3838
if (error) {

src/server/routes/extensions.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { FastifyInstance } from 'fastify'
22
import { PostgresMeta } from '../../lib/index.js'
3-
import { DEFAULT_POOL_CONFIG } from '../constants.js'
3+
import { createConnectionConfig } from '../utils.js'
44
import { extractRequestForLogging } from '../utils.js'
55

66
export default async (fastify: FastifyInstance) => {
77
fastify.get<{
8-
Headers: { pg: string }
8+
Headers: { pg: string; 'x-pg-application-name'?: string }
99
Querystring: {
1010
limit?: number
1111
offset?: number
1212
}
1313
}>('/', async (request, reply) => {
14-
const connectionString = request.headers.pg
14+
const config = createConnectionConfig(request)
1515
const limit = request.query.limit
1616
const offset = request.query.offset
1717

18-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
18+
const pgMeta = new PostgresMeta(config)
1919
const { data, error } = await pgMeta.extensions.list({ limit, offset })
2020
await pgMeta.end()
2121
if (error) {
@@ -28,14 +28,14 @@ export default async (fastify: FastifyInstance) => {
2828
})
2929

3030
fastify.get<{
31-
Headers: { pg: string }
31+
Headers: { pg: string; 'x-pg-application-name'?: string }
3232
Params: {
3333
name: string
3434
}
3535
}>('/:name', async (request, reply) => {
36-
const connectionString = request.headers.pg
36+
const config = createConnectionConfig(request)
3737

38-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
38+
const pgMeta = new PostgresMeta(config)
3939
const { data, error } = await pgMeta.extensions.retrieve({ name: request.params.name })
4040
await pgMeta.end()
4141
if (error) {
@@ -48,12 +48,12 @@ export default async (fastify: FastifyInstance) => {
4848
})
4949

5050
fastify.post<{
51-
Headers: { pg: string }
51+
Headers: { pg: string; 'x-pg-application-name'?: string }
5252
Body: any
5353
}>('/', async (request, reply) => {
54-
const connectionString = request.headers.pg
54+
const config = createConnectionConfig(request)
5555

56-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
56+
const pgMeta = new PostgresMeta(config)
5757
const { data, error } = await pgMeta.extensions.create(request.body as any)
5858
await pgMeta.end()
5959
if (error) {
@@ -66,15 +66,15 @@ export default async (fastify: FastifyInstance) => {
6666
})
6767

6868
fastify.patch<{
69-
Headers: { pg: string }
69+
Headers: { pg: string; 'x-pg-application-name'?: string }
7070
Params: {
7171
name: string
7272
}
7373
Body: any
7474
}>('/:name', async (request, reply) => {
75-
const connectionString = request.headers.pg
75+
const config = createConnectionConfig(request)
7676

77-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
77+
const pgMeta = new PostgresMeta(config)
7878
const { data, error } = await pgMeta.extensions.update(request.params.name, request.body as any)
7979
await pgMeta.end()
8080
if (error) {
@@ -88,18 +88,18 @@ export default async (fastify: FastifyInstance) => {
8888
})
8989

9090
fastify.delete<{
91-
Headers: { pg: string }
91+
Headers: { pg: string; 'x-pg-application-name'?: string }
9292
Params: {
9393
name: string
9494
}
9595
Querystring: {
9696
cascade?: string
9797
}
9898
}>('/:name', async (request, reply) => {
99-
const connectionString = request.headers.pg
99+
const config = createConnectionConfig(request)
100100
const cascade = request.query.cascade === 'true'
101101

102-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
102+
const pgMeta = new PostgresMeta(config)
103103
const { data, error } = await pgMeta.extensions.remove(request.params.name, { cascade })
104104
await pgMeta.end()
105105
if (error) {

0 commit comments

Comments
 (0)