added jsvm subscriptions.Message binding
This commit is contained in:
parent
49e3f4ad93
commit
e2f806d8bb
|
@ -21,6 +21,10 @@
|
||||||
- Removed the explicit charset from the realtime response due to compatability issues with IIS ([#3461](https://github.com/pocketbase/pocketbase/issues/3461)).
|
- Removed the explicit charset from the realtime response due to compatability issues with IIS ([#3461](https://github.com/pocketbase/pocketbase/issues/3461)).
|
||||||
_The `Connection:keep-alive` realtime response header was also removed as it is not really used with HTTP2 anyway._
|
_The `Connection:keep-alive` realtime response header was also removed as it is not really used with HTTP2 anyway._
|
||||||
|
|
||||||
|
- Added new JSVM bindings:
|
||||||
|
- `new Cookie({ ... })` constructor for creating `*http.Cookie` equivalent value.
|
||||||
|
- `new SubscriptionMessage({ ... })` constructor for creating a realtime subscription payload.
|
||||||
|
|
||||||
|
|
||||||
## v0.18.9
|
## v0.18.9
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ import (
|
||||||
"github.com/pocketbase/pocketbase/tools/mailer"
|
"github.com/pocketbase/pocketbase/tools/mailer"
|
||||||
"github.com/pocketbase/pocketbase/tools/rest"
|
"github.com/pocketbase/pocketbase/tools/rest"
|
||||||
"github.com/pocketbase/pocketbase/tools/security"
|
"github.com/pocketbase/pocketbase/tools/security"
|
||||||
|
"github.com/pocketbase/pocketbase/tools/subscriptions"
|
||||||
"github.com/pocketbase/pocketbase/tools/types"
|
"github.com/pocketbase/pocketbase/tools/types"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -417,6 +418,11 @@ func baseBinds(vm *goja.Runtime) {
|
||||||
instance := &http.Cookie{}
|
instance := &http.Cookie{}
|
||||||
return structConstructor(vm, call, instance)
|
return structConstructor(vm, call, instance)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
vm.Set("SubscriptionMessage", func(call goja.ConstructorCall) *goja.Object {
|
||||||
|
instance := &subscriptions.Message{}
|
||||||
|
return structConstructor(vm, call, instance)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func dbxBinds(vm *goja.Runtime) {
|
func dbxBinds(vm *goja.Runtime) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ func TestBaseBindsCount(t *testing.T) {
|
||||||
vm := goja.New()
|
vm := goja.New()
|
||||||
baseBinds(vm)
|
baseBinds(vm)
|
||||||
|
|
||||||
testBindsCount(vm, "this", 15, t)
|
testBindsCount(vm, "this", 16, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBaseBindsReaderToString(t *testing.T) {
|
func TestBaseBindsReaderToString(t *testing.T) {
|
||||||
|
@ -101,6 +101,37 @@ func TestBaseBindsCookie(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBaseBindsSubscriptionMessage(t *testing.T) {
|
||||||
|
app, _ := tests.NewTestApp()
|
||||||
|
defer app.Cleanup()
|
||||||
|
|
||||||
|
vm := goja.New()
|
||||||
|
baseBinds(vm)
|
||||||
|
vm.Set("bytesToString", func(b []byte) string {
|
||||||
|
return string(b)
|
||||||
|
})
|
||||||
|
|
||||||
|
_, err := vm.RunString(`
|
||||||
|
const payload = {
|
||||||
|
name: "test",
|
||||||
|
data: '{"test":123}'
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = new SubscriptionMessage(payload);
|
||||||
|
|
||||||
|
if (result.name != payload.name) {
|
||||||
|
throw new("Expected name " + payload.name + ", got " + result.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytesToString(result.data) != payload.data) {
|
||||||
|
throw new("Expected data '" + payload.data + "', got '" + bytesToString(result.data) + "'");
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBaseBindsRecord(t *testing.T) {
|
func TestBaseBindsRecord(t *testing.T) {
|
||||||
app, _ := tests.NewTestApp()
|
app, _ := tests.NewTestApp()
|
||||||
defer app.Cleanup()
|
defer app.Cleanup()
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -480,6 +480,27 @@ declare class Cookie implements http.Cookie {
|
||||||
constructor(options?: Partial<http.Cookie>)
|
constructor(options?: Partial<http.Cookie>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SubscriptionMessage extends subscriptions.Message{} // merge
|
||||||
|
/**
|
||||||
|
* SubscriptionMessage defines a realtime subscription payload.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* ` + "```" + `js
|
||||||
|
* onRealtimeConnectRequest((e) => {
|
||||||
|
* e.client.send(new SubscriptionMessage({
|
||||||
|
* name: "example",
|
||||||
|
* data: '{"greeting": "Hello world"}'
|
||||||
|
* }))
|
||||||
|
* })
|
||||||
|
* ` + "```" + `
|
||||||
|
*
|
||||||
|
* @group PocketBase
|
||||||
|
*/
|
||||||
|
declare class SubscriptionMessage implements subscriptions.Message {
|
||||||
|
constructor(options?: Partial<subscriptions.Message>)
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// dbxBinds
|
// dbxBinds
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
|
|
||||||
// Broker defines a struct for managing subscriptions clients.
|
// Broker defines a struct for managing subscriptions clients.
|
||||||
type Broker struct {
|
type Broker struct {
|
||||||
mux sync.RWMutex
|
|
||||||
clients map[string]Client
|
clients map[string]Client
|
||||||
|
mux sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBroker initializes and returns a new Broker instance.
|
// NewBroker initializes and returns a new Broker instance.
|
||||||
|
|
Loading…
Reference in New Issue