@@ -2,7 +2,6 @@ package goja
22
33import (
44 "os"
5- "strings"
65
76 "github.com/dop251/goja"
87 "github.com/pkg/errors"
@@ -12,22 +11,21 @@ import (
1211
1312func KVInject (ctx core.FilterContext , jsCtx * goja.Runtime ) error {
1413 return jsCtx .GlobalObject ().Set ("kv" , map [string ]interface {}{
15- "repo" : func (group string ) (goja.Value , error ) {
16- return kvResult (ctx .RepoDB )(ctx , jsCtx , group )
14+ "repo" : func (group ... string ) (goja.Value , error ) {
15+ return kvResult (ctx .RepoDB )(ctx , jsCtx , group ... )
1716 },
18- "org" : func (group string ) (goja.Value , error ) {
19- return kvResult (ctx .OrgDB )(ctx , jsCtx , group )
17+ "org" : func (group ... string ) (goja.Value , error ) {
18+ return kvResult (ctx .OrgDB )(ctx , jsCtx , group ... )
2019 },
2120 })
2221}
2322
24- func kvResult (db kv.CursorPagedKV ) func (ctx core.FilterContext , jsCtx * goja.Runtime , group string ) (goja.Value , error ) {
25- return func (ctx core.FilterContext , jsCtx * goja.Runtime , group string ) (goja.Value , error ) {
26- group = strings .TrimSpace (group )
27- if group == "" {
23+ func kvResult (db kv.CursorPagedKV ) func (ctx core.FilterContext , jsCtx * goja.Runtime , group ... string ) (goja.Value , error ) {
24+ return func (ctx core.FilterContext , jsCtx * goja.Runtime , group ... string ) (goja.Value , error ) {
25+ if len (group ) == 0 {
2826 return goja .Undefined (), errors .New ("invalid group" )
2927 }
30- db := db .Child (group ).(kv.CursorPagedKV )
28+ db := db .Child (group ... ).(kv.CursorPagedKV )
3129 return jsCtx .ToValue (map [string ]interface {}{
3230 "get" : func (key string ) (goja.Value , error ) {
3331 get , err := db .Get (ctx , key )
0 commit comments