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,68 @@ 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 ( {
180- stub,
181- broadcastAllEvents : false ,
182- 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 )
193+ const getFeature = getFeatureFromConfig ( config . features )
194+ const plugins : StarbasePlugin [ ] = [ ]
192195
193- const interfacePlugin = new InterfacePlugin ( )
196+ if ( getFeature ( 'websocket' ) ) {
197+ const webSocketPlugin = new WebSocketPlugin ( )
198+ plugins . push ( webSocketPlugin )
199+ }
194200
195- const plugins = [
196- webSocketPlugin ,
197- new StudioPlugin ( {
201+ if ( getFeature ( 'studio' ) ) {
202+ const studioPlugin = new StudioPlugin ( {
198203 username : env . STUDIO_USER ,
199204 password : env . STUDIO_PASS ,
200205 apiKey : env . ADMIN_AUTHORIZATION_TOKEN ,
201- } ) ,
206+ } )
207+ plugins . push ( studioPlugin )
208+ }
209+
210+ plugins . push (
202211 new SqlMacrosPlugin ( {
203212 preventSelectStar : false ,
204213 } ) ,
205- new QueryLogPlugin ( { ctx } ) ,
206- cdcPlugin ,
207- cronPlugin ,
208- new StatsPlugin ( ) ,
209- interfacePlugin ,
210- ] satisfies StarbasePlugin [ ]
214+ new QueryLogPlugin ( { ctx } )
215+ )
216+
217+ if ( getFeature ( 'cdc' ) ) {
218+ const cdcPlugin = new ChangeDataCapturePlugin ( {
219+ stub,
220+ broadcastAllEvents : false ,
221+ events : [ ] ,
222+ } )
223+ plugins . push ( cdcPlugin )
224+ cdcPlugin . onEvent ( async ( { action, schema, table, data } ) => {
225+ // Include change data capture code here
226+ } , ctx )
227+ }
228+
229+ if ( getFeature ( 'cron' ) ) {
230+ const cronPlugin = new CronPlugin ( )
231+ plugins . push ( cronPlugin )
232+ cronPlugin . onEvent ( async ( { name, cron_tab, payload } ) => {
233+ // Include cron event code here
234+ } , ctx )
235+ }
236+
237+ plugins . push ( new StatsPlugin ( ) )
238+
239+ let interfacePlugin : InterfacePlugin | undefined
240+ if ( getFeature ( 'interface' ) ) {
241+ interfacePlugin = new InterfacePlugin ( )
242+ plugins . push ( interfacePlugin )
243+ }
211244
212245 const starbase = new StarbaseDB ( {
213246 dataSource,
@@ -227,7 +260,10 @@ export default {
227260 // next authentication checks happen. If a page is meant to have any
228261 // sort of authentication, it can provide Basic Auth itself or expose
229262 // itself in another plugin.
230- if ( interfacePlugin . matchesRoute ( url . pathname ) ) {
263+ if (
264+ getFeature ( 'interface' ) &&
265+ interfacePlugin ?. matchesRoute ( url . pathname )
266+ ) {
231267 return await starbase . handle ( request , ctx )
232268 }
233269
0 commit comments