soft deprecated apis.RequestData(c) in favor of apis.RequestInfo(c) and updated jsvm bindings

This commit is contained in:
Gani Georgiev
2023-07-17 23:13:39 +03:00
parent 7d4017225c
commit 0110869c89
22 changed files with 3158 additions and 2990 deletions
@@ -6,12 +6,11 @@ import (
"github.com/pocketbase/pocketbase/models/schema"
)
// RequestData defines a HTTP request data struct, usually used
// RequestInfo defines a HTTP request data struct, usually used
// as part of the `@request.*` filter resolver.
type RequestData struct {
Method string `json:"method"`
Query map[string]any `json:"query"`
// @todo consider changing to Body?
type RequestInfo struct {
Method string `json:"method"`
Query map[string]any `json:"query"`
Data map[string]any `json:"data"`
Headers map[string]any `json:"headers"`
AuthRecord *Record `json:"authRecord"`
@@ -19,7 +18,7 @@ type RequestData struct {
}
// HasModifierDataKeys loosely checks if the current struct has any modifier Data keys.
func (r *RequestData) HasModifierDataKeys() bool {
func (r *RequestInfo) HasModifierDataKeys() bool {
allModifiers := schema.FieldValueModifiers()
for key := range r.Data {
@@ -6,20 +6,20 @@ import (
"github.com/pocketbase/pocketbase/models"
)
func TestRequestDataHasModifierDataKeys(t *testing.T) {
func TestRequestInfoHasModifierDataKeys(t *testing.T) {
scenarios := []struct {
name string
requestData *models.RequestData
requestInfo *models.RequestInfo
expected bool
}{
{
"empty",
&models.RequestData{},
&models.RequestInfo{},
false,
},
{
"Data with regular fields",
&models.RequestData{
&models.RequestInfo{
Query: map[string]any{"data+": "demo"}, // should be ignored
Data: map[string]any{"a": 123, "b": "test", "c.d": false},
},
@@ -27,21 +27,21 @@ func TestRequestDataHasModifierDataKeys(t *testing.T) {
},
{
"Data with +modifier fields",
&models.RequestData{
&models.RequestInfo{
Data: map[string]any{"a+": 123, "b": "test", "c.d": false},
},
true,
},
{
"Data with -modifier fields",
&models.RequestData{
&models.RequestInfo{
Data: map[string]any{"a": 123, "b-": "test", "c.d": false},
},
true,
},
{
"Data with mixed modifier fields",
&models.RequestData{
&models.RequestInfo{
Data: map[string]any{"a": 123, "b-": "test", "c.d+": false},
},
true,
@@ -49,7 +49,7 @@ func TestRequestDataHasModifierDataKeys(t *testing.T) {
}
for _, s := range scenarios {
result := s.requestData.HasModifierDataKeys()
result := s.requestInfo.HasModifierDataKeys()
if result != s.expected {
t.Fatalf("[%s] Expected %v, got %v", s.name, s.expected, result)