11import { getNodeEnv } from '@pgpmjs/env' ;
22import { Logger } from '@pgpmjs/logger' ;
33import { svcCache } from '@pgpmjs/server-utils' ;
4- import type { ConstructiveOptions } from '@constructive-io/graphql-types' ;
54import { parseUrl } from '@constructive-io/url-domains' ;
65import { NextFunction , Request , Response } from 'express' ;
76import { Pool } from 'pg' ;
87import { getPgPool } from 'pg-cache' ;
98
109import errorPage50x from '../errors/50x' ;
1110import errorPage404Message from '../errors/404-message' ;
12- import { ApiConfigResult , ApiError , ApiStructure , RlsModule } from '../types' ;
11+ import { ApiConfigResult , ApiError , ApiOptions , ApiStructure , RlsModule } from '../types' ;
1312import './types' ;
1413
1514const log = new Logger ( 'api' ) ;
@@ -123,7 +122,7 @@ interface ApiListRow {
123122}
124123
125124interface ResolveContext {
126- opts : ConstructiveOptions ;
125+ opts : ApiOptions ;
127126 pool : Pool ;
128127 domain : string ;
129128 subdomain : string | null ;
@@ -167,7 +166,7 @@ export const getSubdomain = (subdomains: string[]): string | null => {
167166 return filtered . length ? filtered . join ( '.' ) : null ;
168167} ;
169168
170- export const getSvcKey = ( opts : ConstructiveOptions , req : Request ) : string => {
169+ export const getSvcKey = ( opts : ApiOptions , req : Request ) : string => {
171170 const { domain, subdomains } = getUrlDomains ( req ) ;
172171 const baseKey = subdomains . filter ( ( n ) => n !== 'www' ) . concat ( domain ) . join ( '.' ) ;
173172
@@ -196,7 +195,7 @@ const toRlsModule = (row: RlsModuleRow | null): RlsModule | undefined => {
196195 } ;
197196} ;
198197
199- const toApiStructure = ( row : ApiRow , opts : ConstructiveOptions , rlsModuleRow ?: RlsModuleRow | null ) : ApiStructure => ( {
198+ const toApiStructure = ( row : ApiRow , opts : ApiOptions , rlsModuleRow ?: RlsModuleRow | null ) : ApiStructure => ( {
200199 apiId : row . api_id ,
201200 dbname : row . dbname || opts . pg ?. database || '' ,
202201 anonRole : row . anon_role || 'anon' ,
@@ -210,7 +209,7 @@ const toApiStructure = (row: ApiRow, opts: ConstructiveOptions, rlsModuleRow?: R
210209} ) ;
211210
212211const createAdminStructure = (
213- opts : ConstructiveOptions ,
212+ opts : ApiOptions ,
214213 schemas : string [ ] ,
215214 databaseId ?: string
216215) : ApiStructure => ( {
@@ -409,7 +408,7 @@ const buildDevFallbackError = async (
409408// =============================================================================
410409
411410export const getApiConfig = async (
412- opts : ConstructiveOptions ,
411+ opts : ApiOptions ,
413412 req : Request
414413) : Promise < ApiConfigResult > => {
415414 const pool = getPgPool ( opts . pg ) ;
@@ -501,7 +500,7 @@ export const getApiConfig = async (
501500// Express Middleware
502501// =============================================================================
503502
504- export const createApiMiddleware = ( opts : ConstructiveOptions ) => {
503+ export const createApiMiddleware = ( opts : ApiOptions ) => {
505504 return async ( req : Request , res : Response , next : NextFunction ) : Promise < void > => {
506505 log . debug ( `[api-middleware] ${ req . method } ${ req . path } ` ) ;
507506
0 commit comments