merge newui branch
This commit is contained in:
@@ -289,9 +289,13 @@ func wrapMiddlewares(executors *vmsPool, rawMiddlewares ...goja.Value) ([]*hook.
|
||||
return wrappedMiddlewares, nil
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
var cachedArrayOfTypes = store.New[reflect.Type, reflect.Type](nil)
|
||||
|
||||
func baseBinds(vm *goja.Runtime) {
|
||||
// BindCore registers common core objects and functions such as sleep,
|
||||
// toString, DynamicModel, etc. into the provided runtime.
|
||||
func BindCore(vm *goja.Runtime) {
|
||||
vm.SetFieldNameMapper(FieldMapper{})
|
||||
|
||||
// deprecated: use toString
|
||||
@@ -659,7 +663,10 @@ func baseBinds(vm *goja.Runtime) {
|
||||
})
|
||||
}
|
||||
|
||||
func dbxBinds(vm *goja.Runtime) {
|
||||
// BindDbx registers $dbx.* namespaced object with dbx database builder related methods.
|
||||
//
|
||||
// See https://pocketbase.io/jsvm/modules/_dbx.html.
|
||||
func BindDbx(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$dbx", obj)
|
||||
|
||||
@@ -682,7 +689,10 @@ func dbxBinds(vm *goja.Runtime) {
|
||||
obj.Set("notBetween", dbx.NotBetween)
|
||||
}
|
||||
|
||||
func mailsBinds(vm *goja.Runtime) {
|
||||
// BindMails registers $mail.* namespaced object with common mail related helpers.
|
||||
//
|
||||
// See https://pocketbase.io/jsvm/modules/_mails.html.
|
||||
func BindMails(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$mails", obj)
|
||||
|
||||
@@ -693,7 +703,10 @@ func mailsBinds(vm *goja.Runtime) {
|
||||
obj.Set("sendRecordAuthAlert", mails.SendRecordAuthAlert)
|
||||
}
|
||||
|
||||
func securityBinds(vm *goja.Runtime) {
|
||||
// BindSecurity registers $security.* namespaced object with common security related helpers.
|
||||
//
|
||||
// See https://pocketbase.io/jsvm/modules/_security.html.
|
||||
func BindSecurity(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$security", obj)
|
||||
|
||||
@@ -736,7 +749,11 @@ func securityBinds(vm *goja.Runtime) {
|
||||
})
|
||||
}
|
||||
|
||||
func filesystemBinds(vm *goja.Runtime) {
|
||||
// BindFilesystem registers $filesystem.* namespaced object with
|
||||
// common filesystem package related helpers.
|
||||
//
|
||||
// See https://pocketbase.io/jsvm/modules/_filesystem.html.
|
||||
func BindFilesystem(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$filesystem", obj)
|
||||
|
||||
@@ -757,7 +774,11 @@ func filesystemBinds(vm *goja.Runtime) {
|
||||
})
|
||||
}
|
||||
|
||||
func filepathBinds(vm *goja.Runtime) {
|
||||
// BindFilesystem registers $filepath.* namespaced object with
|
||||
// common std Go filepath package related exports.
|
||||
//
|
||||
// See https://pocketbase.io/jsvm/modules/_filepath.html.
|
||||
func BindFilepath(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$filepath", obj)
|
||||
|
||||
@@ -778,7 +799,11 @@ func filepathBinds(vm *goja.Runtime) {
|
||||
obj.Set("walkDir", filepath.WalkDir)
|
||||
}
|
||||
|
||||
func osBinds(vm *goja.Runtime) {
|
||||
// BindFilesystem registers $os.* namespaced object with
|
||||
// common std Go os package related exports.
|
||||
//
|
||||
// See https://pocketbase.io/jsvm/modules/_os.html.
|
||||
func BindOs(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$os", obj)
|
||||
|
||||
@@ -804,14 +829,20 @@ func osBinds(vm *goja.Runtime) {
|
||||
obj.Set("openInRoot", os.OpenInRoot)
|
||||
}
|
||||
|
||||
func formsBinds(vm *goja.Runtime) {
|
||||
// BindForms registers various application form constructors.
|
||||
// These bindings are mostly used internally and/or preserved for backward compatibility with earlier versions.
|
||||
func BindForms(vm *goja.Runtime) {
|
||||
registerFactoryAsConstructor(vm, "AppleClientSecretCreateForm", forms.NewAppleClientSecretCreate)
|
||||
registerFactoryAsConstructor(vm, "RecordUpsertForm", forms.NewRecordUpsert)
|
||||
registerFactoryAsConstructor(vm, "TestEmailSendForm", forms.NewTestEmailSend)
|
||||
registerFactoryAsConstructor(vm, "TestS3FilesystemForm", forms.NewTestS3Filesystem)
|
||||
}
|
||||
|
||||
func apisBinds(vm *goja.Runtime) {
|
||||
// BindApis registers $apis.* namespaced object with reusable Web API
|
||||
// handlers, middlewares and other related helpers.
|
||||
//
|
||||
// See https://pocketbase.io/jsvm/modules/_apis.html.
|
||||
func BindApis(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$apis", obj)
|
||||
|
||||
@@ -850,7 +881,11 @@ func apisBinds(vm *goja.Runtime) {
|
||||
registerFactoryAsConstructor(vm, "InternalServerError", router.NewInternalServerError)
|
||||
}
|
||||
|
||||
func httpClientBinds(vm *goja.Runtime) {
|
||||
// BindHttpClient registers $http.* namespaced object with common utils
|
||||
// for sending HTTP requests.
|
||||
//
|
||||
// See https://pocketbase.io/jsvm/modules/_http.html.
|
||||
func BindHttpClient(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$http", obj)
|
||||
|
||||
|
||||
@@ -43,16 +43,16 @@ func testBindsCount(vm *goja.Runtime, namespace string, count int, t *testing.T)
|
||||
|
||||
// note: this test is useful as a reminder to update the tests in case
|
||||
// a new base binding is added.
|
||||
func TestBaseBindsCount(t *testing.T) {
|
||||
func TestBindCoreCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
testBindsCount(vm, "this", 41, t)
|
||||
}
|
||||
|
||||
func TestBaseBindsSleep(t *testing.T) {
|
||||
func TestBindCoreSleep(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
vm.Set("reader", strings.NewReader("test"))
|
||||
|
||||
start := time.Now()
|
||||
@@ -69,9 +69,9 @@ func TestBaseBindsSleep(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsReaderToString(t *testing.T) {
|
||||
func TestBindCoreReaderToString(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
vm.Set("reader", strings.NewReader("test"))
|
||||
|
||||
_, err := vm.RunString(`
|
||||
@@ -86,9 +86,9 @@ func TestBaseBindsReaderToString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsToString(t *testing.T) {
|
||||
func TestBindCoreToString(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
vm.Set("scenarios", []struct {
|
||||
Name string
|
||||
Value any
|
||||
@@ -120,9 +120,9 @@ func TestBaseBindsToString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsToBytes(t *testing.T) {
|
||||
func TestBindCoreToBytes(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
vm.Set("bytesEqual", bytes.Equal)
|
||||
vm.Set("scenarios", []struct {
|
||||
Name string
|
||||
@@ -160,9 +160,9 @@ func TestBaseBindsToBytes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsUnmarshal(t *testing.T) {
|
||||
func TestBindCoreUnmarshal(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
vm.Set("data", &map[string]any{"a": 123})
|
||||
|
||||
_, err := vm.RunString(`
|
||||
@@ -181,9 +181,9 @@ func TestBaseBindsUnmarshal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsContext(t *testing.T) {
|
||||
func TestBindCoreContext(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
const base = new Context(null, "a", 123);
|
||||
@@ -205,9 +205,9 @@ func TestBaseBindsContext(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsCookie(t *testing.T) {
|
||||
func TestBindCoreCookie(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
const cookie = new Cookie({
|
||||
@@ -234,9 +234,9 @@ func TestBaseBindsCookie(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsSubscriptionMessage(t *testing.T) {
|
||||
func TestBindCoreSubscriptionMessage(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
vm.Set("bytesToString", func(b []byte) string {
|
||||
return string(b)
|
||||
})
|
||||
@@ -262,7 +262,7 @@ func TestBaseBindsSubscriptionMessage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsRecord(t *testing.T) {
|
||||
func TestBindCoreRecord(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
@@ -272,7 +272,7 @@ func TestBaseBindsRecord(t *testing.T) {
|
||||
}
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
vm.Set("collection", collection)
|
||||
|
||||
// without record data
|
||||
@@ -308,9 +308,9 @@ func TestBaseBindsRecord(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsCollection(t *testing.T) {
|
||||
func TestBindCoreCollection(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
v, err := vm.RunString(`new Collection({ name: "test", createRule: "@request.auth.id != ''", fields: [{name: "title", "type": "text"}] })`)
|
||||
if err != nil {
|
||||
@@ -336,9 +336,9 @@ func TestBaseBindsCollection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsFieldsList(t *testing.T) {
|
||||
func TestBindCoreFieldsList(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
v, err := vm.RunString(`new FieldsList([{name: "title", "type": "text"}])`)
|
||||
if err != nil {
|
||||
@@ -355,9 +355,9 @@ func TestBaseBindsFieldsList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsField(t *testing.T) {
|
||||
func TestBindCoreField(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
v, err := vm.RunString(`new Field({name: "test", "type": "bool"})`)
|
||||
if err != nil {
|
||||
@@ -379,11 +379,11 @@ func isType[T any](v any) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
func TestBaseBindsNamedFields(t *testing.T) {
|
||||
func TestBindCoreNamedFields(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
scenarios := []struct {
|
||||
js string
|
||||
@@ -470,9 +470,9 @@ func TestBaseBindsNamedFields(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsMailerMessage(t *testing.T) {
|
||||
func TestBindCoreMailerMessage(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
v, err := vm.RunString(`new MailerMessage({
|
||||
from: {name: "test_from", address: "test_from@example.com"},
|
||||
@@ -517,9 +517,9 @@ func TestBaseBindsMailerMessage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsCommand(t *testing.T) {
|
||||
func TestBindCoreCommand(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
let runCalls = 0;
|
||||
@@ -546,9 +546,9 @@ func TestBaseBindsCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsRequestInfo(t *testing.T) {
|
||||
func TestBindCoreRequestInfo(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
const info = new RequestInfo({
|
||||
@@ -564,9 +564,9 @@ func TestBaseBindsRequestInfo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsMiddleware(t *testing.T) {
|
||||
func TestBindCoreMiddleware(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
const m = new Middleware(
|
||||
@@ -584,9 +584,9 @@ func TestBaseBindsMiddleware(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsTimezone(t *testing.T) {
|
||||
func TestBindCoreTimezone(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
const v0 = (new Timezone()).string();
|
||||
@@ -609,9 +609,9 @@ func TestBaseBindsTimezone(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsDateTime(t *testing.T) {
|
||||
func TestBindCoreDateTime(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
const now = new DateTime();
|
||||
@@ -650,9 +650,9 @@ func TestBaseBindsDateTime(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsValidationError(t *testing.T) {
|
||||
func TestBindCoreValidationError(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
|
||||
scenarios := []struct {
|
||||
js string
|
||||
@@ -697,14 +697,14 @@ func TestBaseBindsValidationError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDbxBinds(t *testing.T) {
|
||||
func TestBindDbx(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
vm := goja.New()
|
||||
vm.Set("db", app.DB())
|
||||
baseBinds(vm)
|
||||
dbxBinds(vm)
|
||||
BindCore(vm)
|
||||
BindDbx(vm)
|
||||
|
||||
testBindsCount(vm, "$dbx", 15, t)
|
||||
|
||||
@@ -792,14 +792,14 @@ func TestDbxBinds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMailsBindsCount(t *testing.T) {
|
||||
func TestBindMailsCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
mailsBinds(vm)
|
||||
BindMails(vm)
|
||||
|
||||
testBindsCount(vm, "$mails", 5, t)
|
||||
}
|
||||
|
||||
func TestMailsBinds(t *testing.T) {
|
||||
func TestBindMails(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
@@ -809,8 +809,8 @@ func TestMailsBinds(t *testing.T) {
|
||||
}
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
mailsBinds(vm)
|
||||
BindCore(vm)
|
||||
BindMails(vm)
|
||||
vm.Set("$app", app)
|
||||
vm.Set("record", record)
|
||||
|
||||
@@ -845,17 +845,17 @@ func TestMailsBinds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecurityBindsCount(t *testing.T) {
|
||||
func TestBindSecurityCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
securityBinds(vm)
|
||||
BindSecurity(vm)
|
||||
|
||||
testBindsCount(vm, "$security", 16, t)
|
||||
}
|
||||
|
||||
func TestSecurityCryptoBinds(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
securityBinds(vm)
|
||||
BindCore(vm)
|
||||
BindSecurity(vm)
|
||||
|
||||
sceneraios := []struct {
|
||||
js string
|
||||
@@ -888,8 +888,8 @@ func TestSecurityCryptoBinds(t *testing.T) {
|
||||
|
||||
func TestSecurityRandomStringBinds(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
securityBinds(vm)
|
||||
BindCore(vm)
|
||||
BindSecurity(vm)
|
||||
|
||||
sceneraios := []struct {
|
||||
js string
|
||||
@@ -964,8 +964,8 @@ func TestSecurityJWTBinds(t *testing.T) {
|
||||
for _, s := range sceneraios {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
securityBinds(vm)
|
||||
BindCore(vm)
|
||||
BindSecurity(vm)
|
||||
|
||||
_, err := vm.RunString(s.js)
|
||||
if err != nil {
|
||||
@@ -977,8 +977,8 @@ func TestSecurityJWTBinds(t *testing.T) {
|
||||
|
||||
func TestSecurityEncryptAndDecryptBinds(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
securityBinds(vm)
|
||||
BindCore(vm)
|
||||
BindSecurity(vm)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
const key = "abcdabcdabcdabcdabcdabcdabcdabcd"
|
||||
@@ -996,7 +996,7 @@ func TestSecurityEncryptAndDecryptBinds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilesystemBinds(t *testing.T) {
|
||||
func TestBindFilesystem(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
@@ -1020,8 +1020,8 @@ func TestFilesystemBinds(t *testing.T) {
|
||||
vm.Set("tmpDir", tmpDir)
|
||||
vm.Set("testFile", filepath.Join(app.DataDir(), "data.db"))
|
||||
vm.Set("baseURL", srv.URL)
|
||||
baseBinds(vm)
|
||||
filesystemBinds(vm)
|
||||
BindCore(vm)
|
||||
BindFilesystem(vm)
|
||||
|
||||
testBindsCount(vm, "$filesystem", 6, t)
|
||||
|
||||
@@ -1116,24 +1116,24 @@ func TestFilesystemBinds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormsBinds(t *testing.T) {
|
||||
func TestBindForms(t *testing.T) {
|
||||
vm := goja.New()
|
||||
formsBinds(vm)
|
||||
BindForms(vm)
|
||||
|
||||
testBindsCount(vm, "this", 4, t)
|
||||
}
|
||||
|
||||
func TestApisBindsCount(t *testing.T) {
|
||||
func TestBindApisCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
apisBinds(vm)
|
||||
BindApis(vm)
|
||||
|
||||
testBindsCount(vm, "this", 8, t)
|
||||
testBindsCount(vm, "$apis", 11, t)
|
||||
}
|
||||
|
||||
func TestApisBindsApiError(t *testing.T) {
|
||||
func TestBindApisErrors(t *testing.T) {
|
||||
vm := goja.New()
|
||||
apisBinds(vm)
|
||||
BindApis(vm)
|
||||
|
||||
scenarios := []struct {
|
||||
js string
|
||||
@@ -1190,8 +1190,8 @@ func TestLoadingDynamicModel(t *testing.T) {
|
||||
defer app.Cleanup()
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
dbxBinds(vm)
|
||||
BindCore(vm)
|
||||
BindDbx(vm)
|
||||
vm.Set("$app", app)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
@@ -1291,8 +1291,8 @@ func TestDynamicModelMapFieldCaching(t *testing.T) {
|
||||
defer app.Cleanup()
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
dbxBinds(vm)
|
||||
BindCore(vm)
|
||||
BindDbx(vm)
|
||||
vm.Set("$app", app)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
@@ -1350,8 +1350,8 @@ func TestLoadingArrayOf(t *testing.T) {
|
||||
defer app.Cleanup()
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
dbxBinds(vm)
|
||||
BindCore(vm)
|
||||
BindDbx(vm)
|
||||
vm.Set("$app", app)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
@@ -1391,18 +1391,18 @@ func TestLoadingArrayOf(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHttpClientBindsCount(t *testing.T) {
|
||||
func TestBindHttpClientCount(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
vm := goja.New()
|
||||
httpClientBinds(vm)
|
||||
BindHttpClient(vm)
|
||||
|
||||
testBindsCount(vm, "this", 2, t) // + FormData
|
||||
testBindsCount(vm, "$http", 1, t)
|
||||
}
|
||||
|
||||
func TestHttpClientBindsSend(t *testing.T) {
|
||||
func TestBindHttpClientSend(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// start a test server
|
||||
@@ -1447,8 +1447,8 @@ func TestHttpClientBindsSend(t *testing.T) {
|
||||
defer server.Close()
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
httpClientBinds(vm)
|
||||
BindCore(vm)
|
||||
BindHttpClient(vm)
|
||||
vm.Set("testURL", server.URL)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
@@ -1626,7 +1626,7 @@ func TestHooksBinds(t *testing.T) {
|
||||
|
||||
vmFactory := func() *goja.Runtime {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
vm.Set("$app", app)
|
||||
vm.Set("result", result)
|
||||
return vm
|
||||
@@ -1712,7 +1712,7 @@ func TestHooksExceptionUnwrapping(t *testing.T) {
|
||||
|
||||
vmFactory := func() *goja.Runtime {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
BindCore(vm)
|
||||
vm.Set("$app", app)
|
||||
vm.Set("goErr", goErr)
|
||||
return vm
|
||||
@@ -1766,8 +1766,8 @@ func TestRouterBinds(t *testing.T) {
|
||||
|
||||
vmFactory := func() *goja.Runtime {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
apisBinds(vm)
|
||||
BindCore(vm)
|
||||
BindApis(vm)
|
||||
vm.Set("$app", app)
|
||||
vm.Set("result", result)
|
||||
return vm
|
||||
@@ -1855,16 +1855,16 @@ func TestRouterBinds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilepathBindsCount(t *testing.T) {
|
||||
func TestBindFilepathCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
filepathBinds(vm)
|
||||
BindFilepath(vm)
|
||||
|
||||
testBindsCount(vm, "$filepath", 15, t)
|
||||
}
|
||||
|
||||
func TestOsBindsCount(t *testing.T) {
|
||||
func TestBindOsCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
osBinds(vm)
|
||||
BindOs(vm)
|
||||
|
||||
testBindsCount(vm, "$os", 20, t)
|
||||
}
|
||||
|
||||
10616
plugins/jsvm/internal/types/generated/types.d.ts
vendored
10616
plugins/jsvm/internal/types/generated/types.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,9 @@
|
||||
// Package jsvm implements pluggable utilities for binding a JS goja runtime
|
||||
// to the PocketBase instance (loading migrations, attaching to app hooks, etc.).
|
||||
//
|
||||
// The package also exports several reusable bindings so that users
|
||||
// can utilize them as part of their own custom goja runtime setup.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// jsvm.MustRegister(app, jsvm.Config{
|
||||
@@ -200,15 +203,15 @@ func (p *plugin) registerMigrations() error {
|
||||
process.Enable(vm)
|
||||
buffer.Enable(vm)
|
||||
|
||||
baseBinds(vm)
|
||||
dbxBinds(vm)
|
||||
securityBinds(vm)
|
||||
osBinds(vm)
|
||||
filepathBinds(vm)
|
||||
httpClientBinds(vm)
|
||||
filesystemBinds(vm)
|
||||
formsBinds(vm)
|
||||
mailsBinds(vm)
|
||||
BindCore(vm)
|
||||
BindDbx(vm)
|
||||
BindSecurity(vm)
|
||||
BindOs(vm)
|
||||
BindFilepath(vm)
|
||||
BindHttpClient(vm)
|
||||
BindFilesystem(vm)
|
||||
BindForms(vm)
|
||||
BindMails(vm)
|
||||
|
||||
vm.Set("$template", templateRegistry)
|
||||
vm.Set("__hooks", absHooksDir)
|
||||
@@ -288,16 +291,16 @@ func (p *plugin) registerHooks() error {
|
||||
process.Enable(vm)
|
||||
buffer.Enable(vm)
|
||||
|
||||
baseBinds(vm)
|
||||
dbxBinds(vm)
|
||||
filesystemBinds(vm)
|
||||
securityBinds(vm)
|
||||
osBinds(vm)
|
||||
filepathBinds(vm)
|
||||
httpClientBinds(vm)
|
||||
formsBinds(vm)
|
||||
apisBinds(vm)
|
||||
mailsBinds(vm)
|
||||
BindCore(vm)
|
||||
BindDbx(vm)
|
||||
BindSecurity(vm)
|
||||
BindOs(vm)
|
||||
BindFilepath(vm)
|
||||
BindHttpClient(vm)
|
||||
BindFilesystem(vm)
|
||||
BindForms(vm)
|
||||
BindMails(vm)
|
||||
BindApis(vm)
|
||||
|
||||
vm.Set("$app", p.app)
|
||||
vm.Set("$template", templateRegistry)
|
||||
|
||||
@@ -50,6 +50,7 @@ migrate((app) => {
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "text@TEST_RANDOM",
|
||||
"max": 15,
|
||||
@@ -64,6 +65,7 @@ migrate((app) => {
|
||||
},
|
||||
{
|
||||
"cost": 0,
|
||||
"help": "",
|
||||
"hidden": true,
|
||||
"id": "password@TEST_RANDOM",
|
||||
"max": 0,
|
||||
@@ -77,6 +79,7 @@ migrate((app) => {
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "[a-zA-Z0-9]{50}",
|
||||
"help": "",
|
||||
"hidden": true,
|
||||
"id": "text@TEST_RANDOM",
|
||||
"max": 60,
|
||||
@@ -91,6 +94,7 @@ migrate((app) => {
|
||||
},
|
||||
{
|
||||
"exceptDomains": null,
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "email@TEST_RANDOM",
|
||||
"name": "email",
|
||||
@@ -101,6 +105,7 @@ migrate((app) => {
|
||||
"type": "email"
|
||||
},
|
||||
{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "bool@TEST_RANDOM",
|
||||
"name": "emailVisibility",
|
||||
@@ -110,6 +115,7 @@ migrate((app) => {
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "bool@TEST_RANDOM",
|
||||
"name": "verified",
|
||||
@@ -226,6 +232,7 @@ func init() {
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "text@TEST_RANDOM",
|
||||
"max": 15,
|
||||
@@ -240,6 +247,7 @@ func init() {
|
||||
},
|
||||
{
|
||||
"cost": 0,
|
||||
"help": "",
|
||||
"hidden": true,
|
||||
"id": "password@TEST_RANDOM",
|
||||
"max": 0,
|
||||
@@ -253,6 +261,7 @@ func init() {
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "[a-zA-Z0-9]{50}",
|
||||
"help": "",
|
||||
"hidden": true,
|
||||
"id": "text@TEST_RANDOM",
|
||||
"max": 60,
|
||||
@@ -267,6 +276,7 @@ func init() {
|
||||
},
|
||||
{
|
||||
"exceptDomains": null,
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "email@TEST_RANDOM",
|
||||
"name": "email",
|
||||
@@ -277,6 +287,7 @@ func init() {
|
||||
"type": "email"
|
||||
},
|
||||
{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "bool@TEST_RANDOM",
|
||||
"name": "emailVisibility",
|
||||
@@ -286,6 +297,7 @@ func init() {
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "bool@TEST_RANDOM",
|
||||
"name": "verified",
|
||||
@@ -491,6 +503,7 @@ migrate((app) => {
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "text@TEST_RANDOM",
|
||||
"max": 15,
|
||||
@@ -505,6 +518,7 @@ migrate((app) => {
|
||||
},
|
||||
{
|
||||
"cost": 0,
|
||||
"help": "",
|
||||
"hidden": true,
|
||||
"id": "password@TEST_RANDOM",
|
||||
"max": 0,
|
||||
@@ -518,6 +532,7 @@ migrate((app) => {
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "[a-zA-Z0-9]{50}",
|
||||
"help": "",
|
||||
"hidden": true,
|
||||
"id": "text@TEST_RANDOM",
|
||||
"max": 60,
|
||||
@@ -532,6 +547,7 @@ migrate((app) => {
|
||||
},
|
||||
{
|
||||
"exceptDomains": null,
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "email3885137012",
|
||||
"name": "email",
|
||||
@@ -542,6 +558,7 @@ migrate((app) => {
|
||||
"type": "email"
|
||||
},
|
||||
{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "bool@TEST_RANDOM",
|
||||
"name": "emailVisibility",
|
||||
@@ -551,6 +568,7 @@ migrate((app) => {
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "bool256245529",
|
||||
"name": "verified",
|
||||
@@ -670,6 +688,7 @@ func init() {
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "text@TEST_RANDOM",
|
||||
"max": 15,
|
||||
@@ -684,6 +703,7 @@ func init() {
|
||||
},
|
||||
{
|
||||
"cost": 0,
|
||||
"help": "",
|
||||
"hidden": true,
|
||||
"id": "password@TEST_RANDOM",
|
||||
"max": 0,
|
||||
@@ -697,6 +717,7 @@ func init() {
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "[a-zA-Z0-9]{50}",
|
||||
"help": "",
|
||||
"hidden": true,
|
||||
"id": "text@TEST_RANDOM",
|
||||
"max": 60,
|
||||
@@ -711,6 +732,7 @@ func init() {
|
||||
},
|
||||
{
|
||||
"exceptDomains": null,
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "email3885137012",
|
||||
"name": "email",
|
||||
@@ -721,6 +743,7 @@ func init() {
|
||||
"type": "email"
|
||||
},
|
||||
{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "bool@TEST_RANDOM",
|
||||
"name": "emailVisibility",
|
||||
@@ -730,6 +753,7 @@ func init() {
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "bool256245529",
|
||||
"name": "verified",
|
||||
@@ -923,6 +947,7 @@ migrate((app) => {
|
||||
// add field
|
||||
collection.fields.addAt(8, new Field({
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "f4_id",
|
||||
"max": 0,
|
||||
@@ -938,6 +963,7 @@ migrate((app) => {
|
||||
|
||||
// update field
|
||||
collection.fields.addAt(7, new Field({
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "f2_id",
|
||||
"max": null,
|
||||
@@ -976,6 +1002,7 @@ migrate((app) => {
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(8, new Field({
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "f3_id",
|
||||
"name": "f3_name",
|
||||
@@ -990,6 +1017,7 @@ migrate((app) => {
|
||||
|
||||
// update field
|
||||
collection.fields.addAt(7, new Field({
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "f2_id",
|
||||
"max": null,
|
||||
@@ -1054,6 +1082,7 @@ func init() {
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(8, []byte(` + "`" + `{
|
||||
"autogeneratePattern": "",
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "f4_id",
|
||||
"max": 0,
|
||||
@@ -1071,6 +1100,7 @@ func init() {
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(7, []byte(` + "`" + `{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "f2_id",
|
||||
"max": null,
|
||||
@@ -1116,6 +1146,7 @@ func init() {
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(8, []byte(` + "`" + `{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "f3_id",
|
||||
"name": "f3_name",
|
||||
@@ -1132,6 +1163,7 @@ func init() {
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(7, []byte(` + "`" + `{
|
||||
"help": "",
|
||||
"hidden": false,
|
||||
"id": "f2_id",
|
||||
"max": null,
|
||||
|
||||
Reference in New Issue
Block a user