1- import { createResponse } from './utils'
1+ import { createResponse , getFeatureFromConfig } from './utils'
22import { StarbaseDB , StarbaseDBConfiguration } from './handler'
33import { DataSource , RegionLocationHint } from './types'
44import { createRemoteJWKSet , jwtVerify } from 'jose'
@@ -31,6 +31,14 @@ export interface Env {
3131
3232 ENABLE_ALLOWLIST ?: boolean
3333 ENABLE_RLS ?: boolean
34+ ENABLE_REST ?: boolean
35+ ENABLE_WEBSOCKET ?: boolean
36+ ENABLE_EXPORT ?: boolean
37+ ENABLE_IMPORT ?: boolean
38+ ENABLE_CRON ?: boolean
39+ ENABLE_CDC ?: boolean
40+ ENABLE_INTERFACE ?: boolean
41+ ENABLE_STUDIO ?: boolean
3442
3543 // External database source details
3644 OUTERBASE_API_KEY ?: string
@@ -171,43 +179,63 @@ export default {
171179 features : {
172180 allowlist : env . ENABLE_ALLOWLIST ,
173181 rls : env . ENABLE_RLS ,
182+ rest : env . ENABLE_REST ,
183+ websocket : env . ENABLE_WEBSOCKET ,
184+ export : env . ENABLE_EXPORT ,
185+ import : env . ENABLE_IMPORT ,
186+ cron : env . ENABLE_CRON ,
187+ cdc : env . ENABLE_CDC ,
188+ interface : env . ENABLE_INTERFACE ,
189+ studio : env . ENABLE_STUDIO ,
174190 } ,
175191 }
176192
177- const webSocketPlugin = new WebSocketPlugin ( )
178- const cronPlugin = new CronPlugin ( )
179- const cdcPlugin = new ChangeDataCapturePlugin ( {
193+ const getFeature = getFeatureFromConfig ( config . features )
194+
195+ /**
196+ * Plugins
197+ */
198+ const webSocketPlugin = getFeature ( 'websocket' ) ? new WebSocketPlugin ( ) : undefined
199+ const studioPlugin = getFeature ( 'studio' ) ? new StudioPlugin ( {
200+ username : env . STUDIO_USER ,
201+ password : env . STUDIO_PASS ,
202+ apiKey : env . ADMIN_AUTHORIZATION_TOKEN ,
203+ } ) : undefined
204+ const sqlMacrosPlugin = new SqlMacrosPlugin ( {
205+ preventSelectStar : false ,
206+ } )
207+ const queryLogPlugin = new QueryLogPlugin ( { ctx } )
208+ const cdcPlugin = getFeature ( 'cdc' ) ? new ChangeDataCapturePlugin ( {
180209 stub,
181210 broadcastAllEvents : false ,
182211 events : [ ] ,
183- } )
184-
185- cdcPlugin . onEvent ( async ( { action, schema, table, data } ) => {
186- // Include change data capture code here
187- } , ctx )
188-
189- cronPlugin . onEvent ( async ( { name, cron_tab, payload } ) => {
190- // Include cron event code here
191- } , ctx )
192-
193- const interfacePlugin = new InterfacePlugin ( )
194-
195- const plugins = [
212+ } ) : undefined
213+ const cronPlugin = getFeature ( 'cron' ) ? new CronPlugin ( ) : undefined
214+ const statsPlugin = new StatsPlugin ( )
215+ const interfacePlugin = getFeature ( 'interface' ) ? new InterfacePlugin ( ) : undefined
216+
217+ const plugins : StarbasePlugin [ ] = [
196218 webSocketPlugin ,
197- new StudioPlugin ( {
198- username : env . STUDIO_USER ,
199- password : env . STUDIO_PASS ,
200- apiKey : env . ADMIN_AUTHORIZATION_TOKEN ,
201- } ) ,
202- new SqlMacrosPlugin ( {
203- preventSelectStar : false ,
204- } ) ,
205- new QueryLogPlugin ( { ctx } ) ,
219+ studioPlugin ,
220+ sqlMacrosPlugin ,
221+ queryLogPlugin ,
206222 cdcPlugin ,
207223 cronPlugin ,
208- new StatsPlugin ( ) ,
224+ statsPlugin ,
209225 interfacePlugin ,
210- ] satisfies StarbasePlugin [ ]
226+ ] . filter ( plugin => ! ! plugin )
227+
228+ if ( getFeature ( 'cdc' ) ) {
229+ cdcPlugin ?. onEvent ( async ( { action, schema, table, data } ) => {
230+ // Include change data capture code here
231+ } , ctx )
232+ }
233+
234+ if ( getFeature ( 'cron' ) ) {
235+ cronPlugin ?. onEvent ( async ( { name, cron_tab, payload } ) => {
236+ // Include cron event code here
237+ } , ctx )
238+ }
211239
212240 const starbase = new StarbaseDB ( {
213241 dataSource,
@@ -227,7 +255,10 @@ export default {
227255 // next authentication checks happen. If a page is meant to have any
228256 // sort of authentication, it can provide Basic Auth itself or expose
229257 // itself in another plugin.
230- if ( interfacePlugin . matchesRoute ( url . pathname ) ) {
258+ if (
259+ getFeature ( 'interface' ) &&
260+ interfacePlugin ?. matchesRoute ( url . pathname )
261+ ) {
231262 return await starbase . handle ( request , ctx )
232263 }
233264
0 commit comments