1
- import { createResponse } from './utils'
1
+ import { createResponse , getFeatureFromConfig } from './utils'
2
2
import { StarbaseDB , StarbaseDBConfiguration } from './handler'
3
3
import { DataSource , RegionLocationHint } from './types'
4
4
import { createRemoteJWKSet , jwtVerify } from 'jose'
@@ -31,6 +31,14 @@ export interface Env {
31
31
32
32
ENABLE_ALLOWLIST ?: boolean
33
33
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
34
42
35
43
// External database source details
36
44
OUTERBASE_API_KEY ?: string
@@ -171,43 +179,63 @@ export default {
171
179
features : {
172
180
allowlist : env . ENABLE_ALLOWLIST ,
173
181
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 ,
174
190
} ,
175
191
}
176
192
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 ( {
180
209
stub,
181
210
broadcastAllEvents : false ,
182
211
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 [ ] = [
196
218
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 ,
206
222
cdcPlugin ,
207
223
cronPlugin ,
208
- new StatsPlugin ( ) ,
224
+ statsPlugin ,
209
225
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
+ }
211
239
212
240
const starbase = new StarbaseDB ( {
213
241
dataSource,
@@ -227,7 +255,10 @@ export default {
227
255
// next authentication checks happen. If a page is meant to have any
228
256
// sort of authentication, it can provide Basic Auth itself or expose
229
257
// itself in another plugin.
230
- if ( interfacePlugin . matchesRoute ( url . pathname ) ) {
258
+ if (
259
+ getFeature ( 'interface' ) &&
260
+ interfacePlugin ?. matchesRoute ( url . pathname )
261
+ ) {
231
262
return await starbase . handle ( request , ctx )
232
263
}
233
264
0 commit comments