mirror of
https://github.com/pocketbase/pocketbase.git
synced 2024-11-21 13:35:49 +02:00
updated cron jsvm bindings and generated types
This commit is contained in:
parent
6179864828
commit
2d1ad16b4f
4
.github/workflows/release.yaml
vendored
4
.github/workflows/release.yaml
vendored
@ -29,10 +29,10 @@ jobs:
|
||||
- name: Build Admin dashboard UI
|
||||
run: npm --prefix=./ui ci && npm --prefix=./ui run build
|
||||
|
||||
# Similar to the above, the jsvm docs are pregenerated locally
|
||||
# Similar to the above, the jsvm types are pregenerated locally
|
||||
# but its here to ensure that it wasn't forgotten to be executed.
|
||||
- name: Generate jsvm types
|
||||
run: go run ./plugins/jsvm/internal/docs/docs.go
|
||||
run: go run ./plugins/jsvm/internal/types/types.go
|
||||
|
||||
# The prebuilt golangci-lint doesn't support go 1.18+ yet
|
||||
# https://github.com/golangci/golangci-lint/issues/2649
|
||||
|
12
CHANGELOG.md
12
CHANGELOG.md
@ -38,14 +38,14 @@
|
||||
|
||||
- **!** Renamed `*Options` to `*Config` for consistency and replaced the unnecessary pointers with their value equivalent to keep the applied configuration defaults isolated within their function calls:
|
||||
```go
|
||||
old: pocketbase.NewWithConfig(config *pocketbase.Config)
|
||||
new: pocketbase.NewWithConfig(config pocketbase.Config)
|
||||
old: pocketbase.NewWithConfig(config *pocketbase.Config) *pocketbase.PocketBase
|
||||
new: pocketbase.NewWithConfig(config pocketbase.Config) *pocketbase.PocketBase
|
||||
|
||||
old: core.NewBaseApp(config *core.BaseAppConfig)
|
||||
new: core.NewBaseApp(config core.BaseAppConfig)
|
||||
old: core.NewBaseApp(config *core.BaseAppConfig) *core.BaseApp
|
||||
new: core.NewBaseApp(config core.BaseAppConfig) *core.BaseApp
|
||||
|
||||
old: apis.Serve(app core.App, options *apis.ServeOptions)
|
||||
new: apis.Serve(app core.App, config apis.ServeConfig)
|
||||
old: apis.Serve(app core.App, options *apis.ServeOptions) (*http.Server, error)
|
||||
new: apis.Serve(app core.App, config apis.ServeConfig) error
|
||||
|
||||
old: jsvm.MustRegisterMigrations(app core.App, options *jsvm.MigrationsOptions)
|
||||
new: jsvm.MustRegister(app core.App, config jsvm.Config)
|
||||
|
4
Makefile
4
Makefile
@ -4,8 +4,8 @@ lint:
|
||||
test:
|
||||
go test ./... -v --cover
|
||||
|
||||
jsvmdocs:
|
||||
go run ./plugins/jsvm/internal/docs/docs.go
|
||||
jstypes:
|
||||
go run ./plugins/jsvm/internal/types/types.go
|
||||
|
||||
test-report:
|
||||
go test ./... -v --cover -coverprofile=coverage.out
|
||||
|
@ -42,7 +42,7 @@ func main() {
|
||||
app.RootCmd.PersistentFlags().IntVar(
|
||||
&hooksPool,
|
||||
"hooksPool",
|
||||
100,
|
||||
50,
|
||||
"the total prewarm goja.Runtime instances for the JS app hooks execution",
|
||||
)
|
||||
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"reflect"
|
||||
@ -104,12 +103,12 @@ func hooksBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
}
|
||||
|
||||
func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
jobs := cron.New()
|
||||
scheduler := cron.New()
|
||||
|
||||
loader.Set("cronAdd", func(jobId, cronExpr, handler string) {
|
||||
pr := goja.MustCompile("", "{("+handler+").apply(undefined)}", true)
|
||||
|
||||
err := jobs.Add(jobId, cronExpr, func() {
|
||||
err := scheduler.Add(jobId, cronExpr, func() {
|
||||
executors.run(func(executor *goja.Runtime) error {
|
||||
_, err := executor.RunProgram(pr)
|
||||
return err
|
||||
@ -120,19 +119,28 @@ func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
}
|
||||
|
||||
// start the ticker (if not already)
|
||||
if jobs.Total() > 0 && !jobs.HasStarted() {
|
||||
jobs.Start()
|
||||
if app.IsBootstrapped() && scheduler.Total() > 0 && !scheduler.HasStarted() {
|
||||
scheduler.Start()
|
||||
}
|
||||
})
|
||||
|
||||
loader.Set("cronRemove", func(jobId string) {
|
||||
jobs.Remove(jobId)
|
||||
scheduler.Remove(jobId)
|
||||
|
||||
// stop the ticker if there are no other jobs
|
||||
if jobs.Total() == 0 {
|
||||
jobs.Stop()
|
||||
if scheduler.Total() == 0 {
|
||||
scheduler.Stop()
|
||||
}
|
||||
})
|
||||
|
||||
app.OnAfterBootstrap().Add(func(e *core.BootstrapEvent) error {
|
||||
// start the ticker (if not already)
|
||||
if scheduler.Total() > 0 && !scheduler.HasStarted() {
|
||||
scheduler.Start()
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func routerBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
@ -534,10 +542,6 @@ func httpClientBinds(vm *goja.Runtime) {
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode < 200 || res.StatusCode >= 400 {
|
||||
return nil, fmt.Errorf("request failed with status %d", res.StatusCode)
|
||||
}
|
||||
|
||||
bodyRaw, _ := io.ReadAll(res.Body)
|
||||
|
||||
result := &sendResult{
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -29,7 +29,7 @@ const heading = `
|
||||
*
|
||||
* ` + "```" + `js
|
||||
* // prints "Hello world!" on every 30 minutes
|
||||
* cronAdd("hello", "*/30 * * * *", (c) => {
|
||||
* cronAdd("hello", "*\/30 * * * *", (c) => {
|
||||
* console.log("Hello world!")
|
||||
* })
|
||||
* ` + "```" + `
|
||||
@ -45,7 +45,7 @@ declare function cronAdd(
|
||||
): void;
|
||||
|
||||
/**
|
||||
* CronRemove removes previously registerd cron job by its name.
|
||||
* CronRemove removes a single registered cron job by its name.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
@ -162,7 +162,7 @@ declare var $app: appWithoutHooks
|
||||
* ` + "```" + `js
|
||||
* const records = arrayOf(new Record)
|
||||
*
|
||||
* $app.dao().recordQuery(collection).limit(10).all(records)
|
||||
* $app.dao().recordQuery("articles").limit(10).all(records)
|
||||
* ` + "```" + `
|
||||
*
|
||||
* @group PocketBase
|
||||
@ -700,13 +700,30 @@ declare namespace $apis {
|
||||
// httpClientBinds
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
declare namespace $http {
|
||||
/**
|
||||
* Sends a single HTTP request (_currently only json and plain text requests_).
|
||||
/**
|
||||
* ` + "`" + `$http` + "`" + ` defines common methods for working with HTTP requests.
|
||||
*
|
||||
* @group PocketBase
|
||||
*/
|
||||
function send(params: {
|
||||
declare namespace $http {
|
||||
/**
|
||||
* Sends a single HTTP request.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ` + "```" + `js
|
||||
* const res = $http.send({
|
||||
* url: "https://example.com",
|
||||
* data: {"title": "test"}
|
||||
* method: "post",
|
||||
* })
|
||||
*
|
||||
* console.log(res.statusCode)
|
||||
* console.log(res.raw)
|
||||
* console.log(res.json)
|
||||
* ` + "```" + `
|
||||
*/
|
||||
function send(config: {
|
||||
url: string,
|
||||
method?: string, // default to "GET"
|
||||
data?: { [key:string]: any },
|
@ -25,7 +25,7 @@ import (
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/plugins/jsvm/internal/docs/generated"
|
||||
"github.com/pocketbase/pocketbase/plugins/jsvm/internal/types/generated"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -57,7 +57,6 @@ func (h *Hook[T]) Add(fn Handler[T]) string {
|
||||
return id
|
||||
}
|
||||
|
||||
// @todo add also to TaggedHook
|
||||
// Remove removes a single hook handler by its id.
|
||||
func (h *Hook[T]) Remove(id string) {
|
||||
h.mux.Lock()
|
||||
@ -71,7 +70,6 @@ func (h *Hook[T]) Remove(id string) {
|
||||
}
|
||||
}
|
||||
|
||||
// @todo add also to TaggedHook
|
||||
// RemoveAll removes all registered handlers.
|
||||
func (h *Hook[T]) RemoveAll() {
|
||||
h.mux.Lock()
|
||||
|
Loading…
Reference in New Issue
Block a user