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'
@@ -32,6 +32,14 @@ export interface Env {
3232
3333 ENABLE_ALLOWLIST ?: boolean
3434 ENABLE_RLS ?: boolean
35+ ENABLE_REST ?: boolean
36+ ENABLE_WEBSOCKET ?: boolean
37+ ENABLE_EXPORT ?: boolean
38+ ENABLE_IMPORT ?: boolean
39+ ENABLE_CRON ?: boolean
40+ ENABLE_CDC ?: boolean
41+ ENABLE_INTERFACE ?: boolean
42+ ENABLE_STUDIO ?: boolean
3543
3644 // External database source details
3745 OUTERBASE_API_KEY ?: string
@@ -172,43 +180,63 @@ export default {
172180 features : {
173181 allowlist : env . ENABLE_ALLOWLIST ,
174182 rls : env . ENABLE_RLS ,
183+ rest : env . ENABLE_REST ,
184+ websocket : env . ENABLE_WEBSOCKET ,
185+ export : env . ENABLE_EXPORT ,
186+ import : env . ENABLE_IMPORT ,
187+ cron : env . ENABLE_CRON ,
188+ cdc : env . ENABLE_CDC ,
189+ interface : env . ENABLE_INTERFACE ,
190+ studio : env . ENABLE_STUDIO ,
175191 } ,
176192 }
177193
178- const webSocketPlugin = new WebSocketPlugin ( )
179- const cronPlugin = new CronPlugin ( )
180- const cdcPlugin = new ChangeDataCapturePlugin ( {
194+ const getFeature = getFeatureFromConfig ( config . features )
195+
196+ /**
197+ * Plugins
198+ */
199+ const webSocketPlugin = getFeature ( 'websocket' ) ? new WebSocketPlugin ( ) : undefined
200+ const studioPlugin = getFeature ( 'studio' ) ? new StudioPlugin ( {
201+ username : env . STUDIO_USER ,
202+ password : env . STUDIO_PASS ,
203+ apiKey : env . ADMIN_AUTHORIZATION_TOKEN ,
204+ } ) : undefined
205+ const sqlMacrosPlugin = new SqlMacrosPlugin ( {
206+ preventSelectStar : false ,
207+ } )
208+ const queryLogPlugin = new QueryLogPlugin ( { ctx } )
209+ const cdcPlugin = getFeature ( 'cdc' ) ? new ChangeDataCapturePlugin ( {
181210 stub,
182211 broadcastAllEvents : false ,
183212 events : [ ] ,
184- } )
185-
186- cdcPlugin . onEvent ( async ( { action, schema, table, data } ) => {
187- // Include change data capture code here
188- } , ctx )
189-
190- cronPlugin . onEvent ( async ( { name, cron_tab, payload } ) => {
191- // Include cron event code here
192- } , ctx )
193-
194- const interfacePlugin = new InterfacePlugin ( )
195-
196- const plugins = [
213+ } ) : undefined
214+ const cronPlugin = getFeature ( 'cron' ) ? new CronPlugin ( ) : undefined
215+ const statsPlugin = new StatsPlugin ( )
216+ const interfacePlugin = getFeature ( 'interface' ) ? new InterfacePlugin ( ) : undefined
217+
218+ const plugins : StarbasePlugin [ ] = [
197219 webSocketPlugin ,
198- new StudioPlugin ( {
199- username : env . STUDIO_USER ,
200- password : env . STUDIO_PASS ,
201- apiKey : env . ADMIN_AUTHORIZATION_TOKEN ,
202- } ) ,
203- new SqlMacrosPlugin ( {
204- preventSelectStar : false ,
205- } ) ,
206- new QueryLogPlugin ( { ctx } ) ,
220+ studioPlugin ,
221+ sqlMacrosPlugin ,
222+ queryLogPlugin ,
207223 cdcPlugin ,
208224 cronPlugin ,
209- new StatsPlugin ( ) ,
225+ statsPlugin ,
210226 interfacePlugin ,
211- ] satisfies StarbasePlugin [ ]
227+ ] . filter ( plugin => ! ! plugin )
228+
229+ if ( getFeature ( 'cdc' ) ) {
230+ cdcPlugin ?. onEvent ( async ( { action, schema, table, data } ) => {
231+ // Include change data capture code here
232+ } , ctx )
233+ }
234+
235+ if ( getFeature ( 'cron' ) ) {
236+ cronPlugin ?. onEvent ( async ( { name, cron_tab, payload } ) => {
237+ // Include cron event code here
238+ } , ctx )
239+ }
212240
213241 const starbase = new StarbaseDB ( {
214242 dataSource,
@@ -228,7 +256,10 @@ export default {
228256 // next authentication checks happen. If a page is meant to have any
229257 // sort of authentication, it can provide Basic Auth itself or expose
230258 // itself in another plugin.
231- if ( interfacePlugin . matchesRoute ( url . pathname ) ) {
259+ if (
260+ getFeature ( 'interface' ) &&
261+ interfacePlugin ?. matchesRoute ( url . pathname )
262+ ) {
232263 return await starbase . handle ( request , ctx )
233264 }
234265
0 commit comments