mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-09-20 13:30:50 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e51e393a2 | ||
|
|
ea5ca009de | ||
|
|
34fed679fd | ||
|
|
b7a49efa88 | ||
|
|
01e8c0f9f7 | ||
|
|
94253f0dd5 | ||
|
|
6cfaf343ac | ||
|
|
9c562294ff | ||
|
|
3c5409d607 | ||
|
|
8868fa9ae6 | ||
|
|
c0fa53a2ab | ||
|
|
007b6a04ff | ||
|
|
731383a915 | ||
|
|
866d38caf9 | ||
|
|
1f6ab24b34 | ||
|
|
01e33c07fe | ||
|
|
69983bff5e | ||
|
|
2567659696 | ||
|
|
3e487f7e9d | ||
|
|
ca1a395628 | ||
|
|
1a47c70ccf | ||
|
|
1f4bdfb867 | ||
|
|
eae16cc42c | ||
|
|
1527b5ea4f | ||
|
|
ba6e17b3be | ||
|
|
b8219af941 | ||
|
|
8865cc1431 | ||
|
|
20b6ce4b84 | ||
|
|
e2f806d8bb | ||
|
|
49e3f4ad93 | ||
|
|
6d672348e7 | ||
|
|
80d774a8ef | ||
|
|
5a5125383a | ||
|
|
7fa1ff53c9 | ||
|
|
0f4e27a11f | ||
|
|
9997223923 | ||
|
|
632ade795f | ||
|
|
91bd739b71 | ||
|
|
957064d70b | ||
|
|
609792a355 | ||
|
|
2f5cfcfe87 | ||
|
|
5732bc38e3 | ||
|
|
d69181cfef | ||
|
|
8908d03b8c | ||
|
|
ebf73f5602 | ||
|
|
8416f03bcf | ||
|
|
5d87385170 | ||
|
|
837134559f | ||
|
|
fadd12cd22 | ||
|
|
469769d270 | ||
|
|
e4b7303a5d | ||
|
|
e1fb5d26a5 | ||
|
|
4f396ca439 | ||
|
|
ff08fc0fa4 | ||
|
|
4b511475ff | ||
|
|
2550a9de54 | ||
|
|
0f5dad7ede | ||
|
|
d0b1c9d998 | ||
|
|
fd9e120434 | ||
|
|
92731ddd50 | ||
|
|
4b4aaf2112 | ||
|
|
6013d14bc6 | ||
|
|
f3bcd7d3df | ||
|
|
71f9be3cb0 | ||
|
|
f605521208 | ||
|
|
4927583790 | ||
|
|
6e80cb8136 | ||
|
|
bb0a2dd698 | ||
|
|
2608efb56c | ||
|
|
eb2aa1cfc6 | ||
|
|
e1528aedac | ||
|
|
22b0a2b586 | ||
|
|
0ca86a0c87 | ||
|
|
b2c8f394af | ||
|
|
56b2641469 | ||
|
|
f266621a0f | ||
|
|
ca136c5dc1 | ||
|
|
abfe18bcce | ||
|
|
f3fc7f78d7 | ||
|
|
26fd069d11 | ||
|
|
62bde9e1f3 | ||
|
|
b945cd2fdf | ||
|
|
89a0520f7d | ||
|
|
a88b3c5db3 | ||
|
|
a37d9cfb84 | ||
|
|
5b084bbbfd | ||
|
|
322508f6d1 | ||
|
|
78e70bd52b | ||
|
|
58401459bf | ||
|
|
f172754775 | ||
|
|
31670ab3e1 | ||
|
|
baacf4913b | ||
|
|
8a94ccea42 | ||
|
|
b2bab9573a | ||
|
|
e5b5c1f76f | ||
|
|
ccb1c42220 | ||
|
|
a394777264 | ||
|
|
7d10b3c502 | ||
|
|
64ffb308bb | ||
|
|
916c74c218 | ||
|
|
17974d534e | ||
|
|
bde7a86b30 | ||
|
|
f7f8f09336 | ||
|
|
2a6b891a9b | ||
|
|
b4cb35483b | ||
|
|
1606cfd6e2 | ||
|
|
08f97ef0bb | ||
|
|
0dc263a40c | ||
|
|
824031e1a4 | ||
|
|
311bc74b7e | ||
|
|
4f3d1682de | ||
|
|
ef73052546 | ||
|
|
c89c68a4dc | ||
|
|
02495554cf | ||
|
|
cdbe6d78d3 | ||
|
|
ff6904f1f8 | ||
|
|
bc0222dcb4 | ||
|
|
04826ba588 | ||
|
|
6ca1f5c431 | ||
|
|
2863763a27 | ||
|
|
9c0d952543 | ||
|
|
ed4f7c7358 | ||
|
|
49f1c869c0 | ||
|
|
f0af24d78f | ||
|
|
26fd3d48df | ||
|
|
864bbe7e12 | ||
|
|
1e995552c8 | ||
|
|
6baae97b5d | ||
|
|
bcfbbc53f8 | ||
|
|
8a916cd636 | ||
|
|
75f58a28ac | ||
|
|
e87ef431c5 | ||
|
|
b2ac538580 | ||
|
|
53b20ec104 | ||
|
|
c8ef3c4050 | ||
|
|
9113d30103 | ||
|
|
fef6e584b7 | ||
|
|
67fa47b1bb | ||
|
|
5f21c4119f | ||
|
|
734f35c504 | ||
|
|
8f10c66160 | ||
|
|
5960dc5f2d |
@@ -21,7 +21,7 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '>=1.21.0'
|
||||
go-version: '>=1.21.3'
|
||||
|
||||
# This step usually is not needed because the /ui/dist is pregenerated locally
|
||||
# but its here to ensure that each release embeds the latest admin ui artifacts.
|
||||
|
||||
+1
-8
@@ -7,6 +7,7 @@ before:
|
||||
- go mod tidy
|
||||
|
||||
builds:
|
||||
# used only for tests
|
||||
- id: build_cgo
|
||||
main: ./examples/base
|
||||
binary: pocketbase
|
||||
@@ -46,14 +47,6 @@ release:
|
||||
draft: true
|
||||
|
||||
archives:
|
||||
- id: archive_cgo
|
||||
builds: [build_cgo]
|
||||
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}_cgo'
|
||||
format: zip
|
||||
files:
|
||||
- LICENSE*
|
||||
- CHANGELOG*
|
||||
|
||||
- id: archive_noncgo
|
||||
builds: [build_noncgo]
|
||||
format: zip
|
||||
|
||||
+263
-5
@@ -1,3 +1,261 @@
|
||||
## v0.19.2
|
||||
|
||||
- Updated the JSVM generated types ([#3627](https://github.com/pocketbase/pocketbase/issues/3627), [#3662](https://github.com/pocketbase/pocketbase/issues/3662)).
|
||||
|
||||
|
||||
## v0.19.1
|
||||
|
||||
- Fixed `tokenizer.Scan()/ScanAll()` to ignore the separators from the default trim cutset.
|
||||
An option to return also the empty found tokens was also added via `Tokenizer.KeepEmptyTokens(true)`.
|
||||
_This should fix the parsing of whitespace charactes around view query column names when no quotes are used ([#3616](https://github.com/pocketbase/pocketbase/discussions/3616#discussioncomment-7398564))._
|
||||
|
||||
- Fixed the `:excerpt(max, withEllipsis?)` `field` query param modifier to properly add space to the generated text fragment after block tags.
|
||||
|
||||
|
||||
## v0.19.0
|
||||
|
||||
- Added Patreon OAuth2 provider ([#3323](https://github.com/pocketbase/pocketbase/pull/3323); thanks @ghostdevv).
|
||||
|
||||
- Added mailcow OAuth2 provider ([#3364](https://github.com/pocketbase/pocketbase/pull/3364); thanks @thisni1s).
|
||||
|
||||
- Added support for `:excerpt(max, withEllipsis?)` `fields` modifier that will return a short plain text version of any string value (html tags are stripped).
|
||||
This could be used to minimize the downloaded json data when listing records with large `editor` html values.
|
||||
```js
|
||||
await pb.collection("example").getList(1, 20, {
|
||||
"fields": "*,description:excerpt(100)"
|
||||
})
|
||||
```
|
||||
|
||||
- Several Admin UI improvements:
|
||||
- Count the total records separately to speed up the query execution for large datasets ([#3344](https://github.com/pocketbase/pocketbase/issues/3344)).
|
||||
- Enclosed the listing scrolling area within the table so that the horizontal scrollbar and table header are always reachable ([#2505](https://github.com/pocketbase/pocketbase/issues/2505)).
|
||||
- Allowed opening the record preview/update form via direct URL ([#2682](https://github.com/pocketbase/pocketbase/discussions/2682)).
|
||||
- Reintroduced the local `date` field tooltip on hover.
|
||||
- Speed up the listing loading times for records with large `editor` field values by initially fetching only a partial of the records data (the complete record data is loaded on record preview/update).
|
||||
- Added "Media library" (collection images picker) support for the TinyMCE `editor` field.
|
||||
- Added support to "pin" collections in the sidebar.
|
||||
- Added support to manually resize the collections sidebar.
|
||||
- More clear "Nonempty" field label style.
|
||||
- Removed the legacy `.woff` and `.ttf` fonts and keep only `.woff2`.
|
||||
|
||||
- Removed the explicit `Content-Type` charset from the realtime response due to compatibility 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._
|
||||
|
||||
- Added new JSVM bindings:
|
||||
- `new Cookie({ ... })` constructor for creating `*http.Cookie` equivalent value.
|
||||
- `new SubscriptionMessage({ ... })` constructor for creating a custom realtime subscription payload.
|
||||
- Soft-deprecated `$os.exec()` in favour of `$os.cmd()` to make it more clear that the call only prepares the command and doesn't execute it.
|
||||
|
||||
- ⚠️ Bumped the min required Go version to 1.19.
|
||||
|
||||
|
||||
## v0.18.10
|
||||
|
||||
- Added global `raw` template function to allow outputting raw/verbatim HTML content in the JSVM templates ([#3476](https://github.com/pocketbase/pocketbase/discussions/3476)).
|
||||
```
|
||||
{{.description|raw}}
|
||||
```
|
||||
|
||||
- Trimmed view query semicolon and allowed single quotes for column aliases ([#3450](https://github.com/pocketbase/pocketbase/issues/3450#issuecomment-1748044641)).
|
||||
_Single quotes are usually [not a valid identifier quote characters](https://www.sqlite.org/lang_keywords.html), but for resilience and compatibility reasons SQLite allows them in some contexts where only an identifier is expected._
|
||||
|
||||
- Bumped the GitHub action to use [min Go 1.21.2](https://github.com/golang/go/issues?q=milestone%3AGo1.21.2) (_the fixed issues are not critical as they are mostly related to the compiler/build tools_).
|
||||
|
||||
|
||||
## v0.18.9
|
||||
|
||||
- Fixed empty thumbs directories not getting deleted on Windows after deleting a record img file ([#3382](https://github.com/pocketbase/pocketbase/issues/3382)).
|
||||
|
||||
- Updated the generated JSVM typings to silent the TS warnings when trying to access a field/method in a Go->TS interface.
|
||||
|
||||
|
||||
## v0.18.8
|
||||
|
||||
- Minor fix for the View collections API Preview and Admin UI listings incorrectly showing the `created` and `updated` fields as `N/A` when the view query doesn't have them.
|
||||
|
||||
|
||||
## v0.18.7
|
||||
|
||||
- Fixed JS error in the Admin UI when listing records with invalid `relation` field value ([#3372](https://github.com/pocketbase/pocketbase/issues/3372)).
|
||||
_This could happen usually only during custom SQL import scripts or when directly modifying the record field value without data validations._
|
||||
|
||||
- Updated Go deps and the generated JSVM types.
|
||||
|
||||
|
||||
## v0.18.6
|
||||
|
||||
- Return the response headers and cookies in the `$http.send()` result ([#3310](https://github.com/pocketbase/pocketbase/discussions/3310)).
|
||||
|
||||
- Added more descriptive internal error message for missing user/admin email on password reset requests.
|
||||
|
||||
- Updated Go deps.
|
||||
|
||||
|
||||
## v0.18.5
|
||||
|
||||
- Fixed minor Admin UI JS error in the auth collection options panel introduced with the change from v0.18.4.
|
||||
|
||||
|
||||
## v0.18.4
|
||||
|
||||
- Added escape character (`\`) support in the Admin UI to allow using `select` field values with comma ([#2197](https://github.com/pocketbase/pocketbase/discussions/2197)).
|
||||
|
||||
|
||||
## v0.18.3
|
||||
|
||||
- Exposed a global JSVM `readerToString(reader)` helper function to allow reading Go `io.Reader` values ([#3273](https://github.com/pocketbase/pocketbase/discussions/3273)).
|
||||
|
||||
- Bumped the GitHub action to use [min Go 1.21.1](https://github.com/golang/go/issues?q=milestone%3AGo1.21.1+label%3ACherryPickApproved) for the prebuilt executable since it contains some minor `html/template` and `net/http` security fixes.
|
||||
|
||||
|
||||
## v0.18.2
|
||||
|
||||
- Prevent breaking the record form in the Admin UI in case the browser's localStorage quota has been exceeded when uploading or storing large `editor` values ([#3265](https://github.com/pocketbase/pocketbase/issues/3265)).
|
||||
|
||||
- Updated docs and missing JSVM typings.
|
||||
|
||||
- Exposed additional crypto primitives under the `$security.*` JSVM namespace ([#3273](https://github.com/pocketbase/pocketbase/discussions/3273)):
|
||||
```js
|
||||
// HMAC with SHA256
|
||||
$security.hs256("hello", "secret")
|
||||
|
||||
// HMAC with SHA512
|
||||
$security.hs512("hello", "secret")
|
||||
|
||||
// compare 2 strings with a constant time
|
||||
$security.equal(hash1, hash2)
|
||||
```
|
||||
|
||||
|
||||
## v0.18.1
|
||||
|
||||
- Excluded the local temp dir from the backups ([#3261](https://github.com/pocketbase/pocketbase/issues/3261)).
|
||||
|
||||
|
||||
## v0.18.0
|
||||
|
||||
- Simplified the `serve` command to accept domain name(s) as argument to reduce any additional manual hosts setup that sometimes previously was needed when deploying on production ([#3190](https://github.com/pocketbase/pocketbase/discussions/3190)).
|
||||
```sh
|
||||
./pocketbase serve yourdomain.com
|
||||
```
|
||||
|
||||
- Added `fields` wildcard (`*`) support.
|
||||
|
||||
- Added option to upload a backup file from the Admin UI ([#2599](https://github.com/pocketbase/pocketbase/issues/2599)).
|
||||
|
||||
- Registered a custom Deflate compressor to speedup (_nearly 2-3x_) the backups generation for the sake of a small zip size increase.
|
||||
_Based on several local tests, `pb_data` of ~500MB (from which ~350MB+ are several hundred small files) results in a ~280MB zip generated for ~11s (previously it resulted in ~250MB zip but for ~35s)._
|
||||
|
||||
- Added the application name as part of the autogenerated backup name for easier identification ([#3066](https://github.com/pocketbase/pocketbase/issues/3066)).
|
||||
|
||||
- Added new `SmtpConfig.LocalName` option to specify a custom domain name (or IP address) for the initial EHLO/HELO exchange ([#3097](https://github.com/pocketbase/pocketbase/discussions/3097)).
|
||||
_This is usually required for verification purposes only by some SMTP providers, such as on-premise [Gmail SMTP-relay](https://support.google.com/a/answer/2956491)._
|
||||
|
||||
- Added `NoDecimal` `number` field option.
|
||||
|
||||
- `editor` field improvements:
|
||||
- Added new "Strip urls domain" option to allow controlling the default TinyMCE urls behavior (_default to `false` for new content_).
|
||||
- Normalized pasted text while still preserving links, lists, tables, etc. formatting ([#3257](https://github.com/pocketbase/pocketbase/issues/3257)).
|
||||
|
||||
- Added option to auto generate admin and auth record passwords from the Admin UI.
|
||||
|
||||
- Added JSON validation and syntax highlight for the `json` field in the Admin UI ([#3191](https://github.com/pocketbase/pocketbase/issues/3191)).
|
||||
|
||||
- Added datetime filter macros:
|
||||
```
|
||||
// all macros are UTC based
|
||||
@second - @now second number (0-59)
|
||||
@minute - @now minute number (0-59)
|
||||
@hour - @now hour number (0-23)
|
||||
@weekday - @now weekday number (0-6)
|
||||
@day - @now day number
|
||||
@month - @now month number
|
||||
@year - @now year number
|
||||
@todayStart - beginning of the current day as datetime string
|
||||
@todayEnd - end of the current day as datetime string
|
||||
@monthStart - beginning of the current month as datetime string
|
||||
@monthEnd - end of the current month as datetime string
|
||||
@yearStart - beginning of the current year as datetime string
|
||||
@yearEnd - end of the current year as datetime string
|
||||
```
|
||||
|
||||
- Added cron expression macros ([#3132](https://github.com/pocketbase/pocketbase/issues/3132)):
|
||||
```
|
||||
@yearly - "0 0 1 1 *"
|
||||
@annually - "0 0 1 1 *"
|
||||
@monthly - "0 0 1 * *"
|
||||
@weekly - "0 0 * * 0"
|
||||
@daily - "0 0 * * *"
|
||||
@midnight - "0 0 * * *"
|
||||
@hourly - "0 * * * *"
|
||||
```
|
||||
|
||||
- ⚠️ Added offset argument `Dao.FindRecordsByFilter(collection, filter, sort, limit, offset, [params...])`.
|
||||
_If you don't need an offset, you can set it to `0`._
|
||||
|
||||
- To minimize the footguns with `Dao.FindFirstRecordByFilter()` and `Dao.FindRecordsByFilter()`, the functions now supports an optional placeholder params argument that is safe to be populated with untrusted user input.
|
||||
The placeholders are in the same format as when binding regular SQL parameters.
|
||||
```go
|
||||
// unsanitized and untrusted filter variables
|
||||
status := "..."
|
||||
author := "..."
|
||||
|
||||
app.Dao().FindFirstRecordByFilter("articles", "status={:status} && author={:author}", dbx.Params{
|
||||
"status": status,
|
||||
"author": author,
|
||||
})
|
||||
|
||||
app.Dao().FindRecordsByFilter("articles", "status={:status} && author={:author}", "-created", 10, 0, dbx.Params{
|
||||
"status": status,
|
||||
"author": author,
|
||||
})
|
||||
```
|
||||
|
||||
- Added JSVM `$mails.*` binds for the corresponding Go [mails package](https://pkg.go.dev/github.com/pocketbase/pocketbase/mails) functions.
|
||||
|
||||
- Added JSVM helper crypto primitives under the `$security.*` namespace:
|
||||
```js
|
||||
$security.md5(text)
|
||||
$security.sha256(text)
|
||||
$security.sha512(text)
|
||||
```
|
||||
|
||||
- ⚠️ Deprecated `RelationOptions.DisplayFields` in favor of the new `SchemaField.Presentable` option to avoid the duplication when a single collection is referenced more than once and/or by multiple other collections.
|
||||
|
||||
- ⚠️ Fill the `LastVerificationSentAt` and `LastResetSentAt` fields only after a successfull email send ([#3121](https://github.com/pocketbase/pocketbase/issues/3121)).
|
||||
|
||||
- ⚠️ Skip API `fields` json transformations for non 20x responses ([#3176](https://github.com/pocketbase/pocketbase/issues/3176)).
|
||||
|
||||
- ⚠️ Changes to `tests.ApiScenario` struct:
|
||||
|
||||
- The `ApiScenario.AfterTestFunc` now receive as 3rd argument `*http.Response` pointer instead of `*echo.Echo` as the latter is not really useful in this context.
|
||||
```go
|
||||
// old
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo)
|
||||
|
||||
// new
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response)
|
||||
```
|
||||
|
||||
- The `ApiScenario.TestAppFactory` now accept the test instance as argument and no longer expect an error as return result ([#3025](https://github.com/pocketbase/pocketbase/discussions/3025#discussioncomment-6592272)).
|
||||
```go
|
||||
// old
|
||||
TestAppFactory: func() (*tests.TestApp, error)
|
||||
|
||||
// new
|
||||
TestAppFactory: func(t *testing.T) *tests.TestApp
|
||||
```
|
||||
_Returning a `nil` app instance from the factory results in test failure. You can enforce a custom test failure by calling `t.Fatal(err)` inside the factory._
|
||||
|
||||
- Bumped the min required TLS version to 1.2 in order to improve the cert reputation score.
|
||||
|
||||
- Reduced the default JSVM prewarmed pool size to 25 to reduce the initial memory consumptions (_you can manually adjust the pool size with `--hooksPool=50` if you need to, but the default should suffice for most cases_).
|
||||
|
||||
- Update `gocloud.dev` dependency to v0.34 and explicitly set the new `NoTempDir` fileblob option to prevent the cross-device link error introduced with v0.33.
|
||||
|
||||
- Other minor Admin UI and docs improvements.
|
||||
|
||||
|
||||
## v0.17.7
|
||||
|
||||
- Fixed the autogenerated `down` migrations to properly revert the old collection rules in case a change was made in `up` ([#3192](https://github.com/pocketbase/pocketbase/pull/3192); thanks @impact-merlinmarek).
|
||||
@@ -739,7 +997,7 @@
|
||||
|
||||
_Note2: The old index (`"field.0":null`) and filename (`"field.filename.png":null`) based suffixed syntax for deleting files is still supported._
|
||||
|
||||
- ! Added support for multi-match/match-all request data and collection multi-valued fields (`select`, `relation`) conditions.
|
||||
- ⚠️ Added support for multi-match/match-all request data and collection multi-valued fields (`select`, `relation`) conditions.
|
||||
If you want a "at least one of" type of condition, you can prefix the operator with `?`.
|
||||
```js
|
||||
// for each someRelA.someRelB record require the "status" field to be "active"
|
||||
@@ -819,7 +1077,7 @@
|
||||
|
||||
## v0.10.3
|
||||
|
||||
- ! Renamed the metadata key `original_filename` to `original-filename` due to an S3 file upload error caused by the underscore character ([#1343](https://github.com/pocketbase/pocketbase/pull/1343); thanks @yuxiang-gao).
|
||||
- ⚠️ Renamed the metadata key `original_filename` to `original-filename` due to an S3 file upload error caused by the underscore character ([#1343](https://github.com/pocketbase/pocketbase/pull/1343); thanks @yuxiang-gao).
|
||||
|
||||
- Fixed request verification docs api url ([#1332](https://github.com/pocketbase/pocketbase/pull/1332); thanks @JoyMajumdar2001)
|
||||
|
||||
@@ -855,7 +1113,7 @@
|
||||
|
||||
- Refactored the `core.app.Bootstrap()` to be called before starting the cobra commands ([#1267](https://github.com/pocketbase/pocketbase/discussions/1267)).
|
||||
|
||||
- ! Changed `pocketbase.NewWithConfig(config Config)` to `pocketbase.NewWithConfig(config *Config)` and added 4 new config settings:
|
||||
- ⚠️ Changed `pocketbase.NewWithConfig(config Config)` to `pocketbase.NewWithConfig(config *Config)` and added 4 new config settings:
|
||||
```go
|
||||
DataMaxOpenConns int // default to core.DefaultDataMaxOpenConns
|
||||
DataMaxIdleConns int // default to core.DefaultDataMaxIdleConns
|
||||
@@ -865,9 +1123,9 @@
|
||||
|
||||
- Added new helper method `core.App.IsBootstrapped()` to check the current app bootstrap state.
|
||||
|
||||
- ! Changed `core.NewBaseApp(dir, encryptionEnv, isDebug)` to `NewBaseApp(config *BaseAppConfig)`.
|
||||
- ⚠️ Changed `core.NewBaseApp(dir, encryptionEnv, isDebug)` to `NewBaseApp(config *BaseAppConfig)`.
|
||||
|
||||
- ! Removed `rest.UploadedFile` struct (see below `filesystem.File`).
|
||||
- ⚠️ Removed `rest.UploadedFile` struct (see below `filesystem.File`).
|
||||
|
||||
- Added generic file resource struct that allows loading and uploading file content from
|
||||
different sources (at the moment multipart/form-data requests and from the local filesystem).
|
||||
|
||||
+21
-19
@@ -1,5 +1,4 @@
|
||||
Contributing to PocketBase
|
||||
======================================================================
|
||||
# Contributing to PocketBase
|
||||
|
||||
Thanks for taking the time to improve PocketBase!
|
||||
|
||||
@@ -9,26 +8,26 @@ This document describes how to prepare a PR for a change in the main repository.
|
||||
- [Making changes in the Go code](#making-changes-in-the-go-code)
|
||||
- [Making changes in the Admin UI](#making-changes-in-the-admin-ui)
|
||||
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Go 1.18+ (for making changes in the Go code)
|
||||
- Go 1.19+ (for making changes in the Go code)
|
||||
- Node 16+ (for making changes in the Admin UI)
|
||||
|
||||
If you haven't already, you can fork the main repository and clone your fork so that you can work locally:
|
||||
|
||||
```
|
||||
git clone https://github.com/your_username/pocketbase.git
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> It is recommended to create a new branch from master for each of your bugfixes and features.
|
||||
> This is required if you are planning to submit multiple PRs in order to keep the changes separate for review until they eventually get merged.
|
||||
|
||||
|
||||
## Making changes in the Go code
|
||||
|
||||
PocketBase is distributed as a Go package, which means that in order to run the project you'll have to create a Go `main` program that imports the package.
|
||||
|
||||
The repository already includes such program, located in `/examples/base`, that is also used for the prebuilt executables.
|
||||
The repository already includes such program, located in `examples/base`, that is also used for the prebuilt executables.
|
||||
|
||||
So, let's assume that you already done some changes in the PocketBase Go code and you want now to run them:
|
||||
|
||||
@@ -41,20 +40,22 @@ This will start a web server on `http://localhost:8090` with the embedded prebui
|
||||
|
||||
- Add unit/integration tests for your changes (we are using the standard `testing` go package).
|
||||
To run the tests, you could execute (while in the root project directory):
|
||||
```sh
|
||||
go test ./...
|
||||
|
||||
# or using the Makefile
|
||||
make test
|
||||
```
|
||||
```sh
|
||||
go test ./...
|
||||
|
||||
# or using the Makefile
|
||||
make test
|
||||
```
|
||||
|
||||
- Run the linter - **golangci** ([see how to install](https://golangci-lint.run/usage/install/#local-installation)):
|
||||
```sh
|
||||
golangci-lint run -c ./golangci.yml ./...
|
||||
|
||||
# or using the Makefile
|
||||
make lint
|
||||
```
|
||||
```sh
|
||||
golangci-lint run -c ./golangci.yml ./...
|
||||
|
||||
# or using the Makefile
|
||||
make lint
|
||||
```
|
||||
|
||||
## Making changes in the Admin UI
|
||||
|
||||
@@ -65,14 +66,15 @@ To start the Admin UI:
|
||||
1. Navigate to the `ui` project directory
|
||||
2. Run `npm install` to install the node dependencies
|
||||
3. Start vite's dev server
|
||||
```sh
|
||||
npm run dev
|
||||
```
|
||||
```sh
|
||||
npm run dev
|
||||
```
|
||||
|
||||
You could open the browser and access the running Admin UI at `http://localhost:3000`.
|
||||
|
||||
Since the Admin UI is just a client-side application, you need to have the PocketBase backend server also running in the background (either manually running the `examples/base/main.go` or download a prebuilt executable).
|
||||
|
||||
> [!NOTE]
|
||||
> By default, the Admin UI is expecting the backend server to be started at `http://localhost:8090`, but you could change that by creating a new `ui/.env.development.local` file with `PB_BACKEND_URL = YOUR_ADDRESS` variable inside it.
|
||||
|
||||
Every change you make in the Admin UI should be automatically reflected in the browser at `http://localhost:3000` without reloading the page.
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
|
||||
**For documentation and examples, please visit https://pocketbase.io/docs.**
|
||||
|
||||
> ⚠️ Please keep in mind that PocketBase is still under active development
|
||||
> [!WARNING]
|
||||
> Please keep in mind that PocketBase is still under active development
|
||||
> and therefore full backward compatibility is not guaranteed before reaching v1.0.0.
|
||||
|
||||
|
||||
## API SDK clients
|
||||
|
||||
The easiest way to interact with the API is to use one of the official SDK clients:
|
||||
@@ -30,7 +30,6 @@ The easiest way to interact with the API is to use one of the official SDK clien
|
||||
- **JavaScript - [pocketbase/js-sdk](https://github.com/pocketbase/js-sdk)** (_browser and node_)
|
||||
- **Dart - [pocketbase/dart-sdk](https://github.com/pocketbase/dart-sdk)** (_web, mobile, desktop_)
|
||||
|
||||
|
||||
## Overview
|
||||
|
||||
PocketBase could be [downloaded directly as a standalone app](https://github.com/pocketbase/pocketbase/releases) or it could be used as a Go framework/toolkit which allows you to build
|
||||
@@ -39,10 +38,9 @@ your own custom app specific business logic and still have a single portable exe
|
||||
### Installation
|
||||
|
||||
```sh
|
||||
# go 1.18+
|
||||
# go 1.19+
|
||||
go get github.com/pocketbase/pocketbase
|
||||
```
|
||||
> For Windows, you may have to use go 1.19+ due to an incorrect js mime type in the Windows Registry (see [issue#6](https://github.com/pocketbase/pocketbase/issues/6)).
|
||||
|
||||
### Example
|
||||
|
||||
@@ -95,14 +93,15 @@ Enable CGO only if you really need to squeeze the read/write query performance a
|
||||
|
||||
To build the minimal standalone executable, like the prebuilt ones in the releases page, you can simply run `go build` inside the `examples/base` directory:
|
||||
|
||||
0. [Install Go 1.18+](https://go.dev/doc/install) (_if you haven't already_)
|
||||
0. [Install Go 1.19+](https://go.dev/doc/install) (_if you haven't already_)
|
||||
1. Clone/download the repo
|
||||
2. Navigate to `examples/base`
|
||||
3. Run `GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build`
|
||||
(_https://go.dev/doc/install/source#environment_)
|
||||
(_https://go.dev/doc/install/source#environment_)
|
||||
4. Start the created executable by running `./base serve`.
|
||||
|
||||
The supported build targets by the non-cgo driver at the moment are:
|
||||
|
||||
```
|
||||
darwin amd64
|
||||
darwin arm64
|
||||
@@ -114,6 +113,7 @@ linux arm
|
||||
linux arm64
|
||||
linux ppc64le
|
||||
linux riscv64
|
||||
linux s390x
|
||||
windows amd64
|
||||
windows arm64
|
||||
```
|
||||
@@ -122,6 +122,7 @@ windows arm64
|
||||
|
||||
PocketBase comes with mixed bag of unit and integration tests.
|
||||
To run them, use the default `go test` command:
|
||||
|
||||
```sh
|
||||
go test ./...
|
||||
```
|
||||
@@ -134,7 +135,6 @@ If you discover a security vulnerability within PocketBase, please send an e-mai
|
||||
|
||||
All reports will be promptly addressed, and you'll be credited accordingly.
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
PocketBase is free and open source project licensed under the [MIT License](LICENSE.md).
|
||||
@@ -154,5 +154,6 @@ PocketBase has a [roadmap](https://github.com/orgs/pocketbase/projects/2) and I
|
||||
Don't get upset if I close your PR, even if it is well executed and tested. This doesn't mean that it will never be merged.
|
||||
Later we can always refer to it and/or take pieces of your implementation when the time comes to work on the issue (don't worry you'll be credited in the release notes).
|
||||
|
||||
_Please also note that PocketBase was initially created to serve as a new backend for my other open source project - [Presentator](https://presentator.io) (see [#183](https://github.com/presentator/presentator/issues/183)),
|
||||
so all feature requests will be first aligned with what we need for Presentator v3._
|
||||
> [!NOTE]
|
||||
> PocketBase was initially created to serve as a new backend for my other open source project - [Presentator](https://presentator.io) (see [#183](https://github.com/presentator/presentator/issues/183)),
|
||||
> so all feature requests will be first aligned with what we need for Presentator v3.
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/forms"
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/tools/filesystem"
|
||||
"github.com/pocketbase/pocketbase/tools/rest"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
@@ -24,6 +26,7 @@ func bindBackupApi(app core.App, rg *echo.Group) {
|
||||
subGroup := rg.Group("/backups", ActivityLogger(app))
|
||||
subGroup.GET("", api.list, RequireAdminAuth())
|
||||
subGroup.POST("", api.create, RequireAdminAuth())
|
||||
subGroup.POST("/upload", api.upload, RequireAdminAuth())
|
||||
subGroup.GET("/:key", api.download)
|
||||
subGroup.DELETE("/:key", api.delete, RequireAdminAuth())
|
||||
subGroup.POST("/:key/restore", api.restore, RequireAdminAuth())
|
||||
@@ -88,6 +91,28 @@ func (api *backupApi) create(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (api *backupApi) upload(c echo.Context) error {
|
||||
files, err := rest.FindUploadedFiles(c.Request(), "file")
|
||||
if err != nil {
|
||||
return NewBadRequestError("Missing or invalid uploaded file.", err)
|
||||
}
|
||||
|
||||
form := forms.NewBackupUpload(api.app)
|
||||
form.File = files[0]
|
||||
|
||||
return form.Submit(func(next forms.InterceptorNextFunc[*filesystem.File]) forms.InterceptorNextFunc[*filesystem.File] {
|
||||
return func(file *filesystem.File) error {
|
||||
if err := next(file); err != nil {
|
||||
return NewBadRequestError("Failed to upload backup.", err)
|
||||
}
|
||||
|
||||
// we don't retrieve the generated backup file because it may not be
|
||||
// available yet due to the eventually consistent nature of some S3 providers
|
||||
return c.NoContent(http.StatusNoContent)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (api *backupApi) download(c echo.Context) error {
|
||||
fileToken := c.QueryParam("token")
|
||||
|
||||
|
||||
+148
-12
@@ -1,7 +1,11 @@
|
||||
package apis_test
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -85,7 +89,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||
Name: "unauthorized",
|
||||
Method: http.MethodPost,
|
||||
Url: "/api/backups",
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
ensureNoBackups(t, app)
|
||||
},
|
||||
ExpectedStatus: 401,
|
||||
@@ -98,7 +102,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||
RequestHeaders: map[string]string{
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyMjA4OTg1MjYxfQ.UwD8JvkbQtXpymT09d7J6fdA0aP9g4FJ1GPh_ggEkzc",
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
ensureNoBackups(t, app)
|
||||
},
|
||||
ExpectedStatus: 401,
|
||||
@@ -114,7 +118,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
app.Cache().Set(core.CacheKeyActiveBackup, "")
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
ensureNoBackups(t, app)
|
||||
},
|
||||
ExpectedStatus: 400,
|
||||
@@ -127,7 +131,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||
RequestHeaders: map[string]string{
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
files, err := getBackupFiles(app)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -152,7 +156,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||
RequestHeaders: map[string]string{
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
ensureNoBackups(t, app)
|
||||
},
|
||||
ExpectedStatus: 400,
|
||||
@@ -169,7 +173,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||
RequestHeaders: map[string]string{
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
files, err := getBackupFiles(app)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -193,6 +197,138 @@ func TestBackupsCreate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackupsUpload(t *testing.T) {
|
||||
// create dummy form data bodies
|
||||
type body struct {
|
||||
buffer io.Reader
|
||||
contentType string
|
||||
}
|
||||
bodies := make([]body, 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
func() {
|
||||
zb := new(bytes.Buffer)
|
||||
zw := zip.NewWriter(zb)
|
||||
if err := zw.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b := new(bytes.Buffer)
|
||||
mw := multipart.NewWriter(b)
|
||||
|
||||
mfw, err := mw.CreateFormFile("file", "test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := io.Copy(mfw, zb); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mw.Close()
|
||||
|
||||
bodies[i] = body{
|
||||
buffer: b,
|
||||
contentType: mw.FormDataContentType(),
|
||||
}
|
||||
}()
|
||||
}
|
||||
// ---
|
||||
|
||||
scenarios := []tests.ApiScenario{
|
||||
{
|
||||
Name: "unauthorized",
|
||||
Method: http.MethodPost,
|
||||
Url: "/api/backups/upload",
|
||||
Body: bodies[0].buffer,
|
||||
RequestHeaders: map[string]string{
|
||||
"Content-Type": bodies[0].contentType,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
ensureNoBackups(t, app)
|
||||
},
|
||||
ExpectedStatus: 401,
|
||||
ExpectedContent: []string{`"data":{}`},
|
||||
},
|
||||
{
|
||||
Name: "authorized as auth record",
|
||||
Method: http.MethodPost,
|
||||
Url: "/api/backups/upload",
|
||||
Body: bodies[1].buffer,
|
||||
RequestHeaders: map[string]string{
|
||||
"Content-Type": bodies[1].contentType,
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyMjA4OTg1MjYxfQ.UwD8JvkbQtXpymT09d7J6fdA0aP9g4FJ1GPh_ggEkzc",
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
ensureNoBackups(t, app)
|
||||
},
|
||||
ExpectedStatus: 401,
|
||||
ExpectedContent: []string{`"data":{}`},
|
||||
},
|
||||
{
|
||||
Name: "authorized as admin (missing file)",
|
||||
Method: http.MethodPost,
|
||||
Url: "/api/backups/upload",
|
||||
RequestHeaders: map[string]string{
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
ensureNoBackups(t, app)
|
||||
},
|
||||
ExpectedStatus: 400,
|
||||
ExpectedContent: []string{`"data":{`},
|
||||
},
|
||||
{
|
||||
Name: "authorized as admin (existing backup name)",
|
||||
Method: http.MethodPost,
|
||||
Url: "/api/backups/upload",
|
||||
Body: bodies[3].buffer,
|
||||
RequestHeaders: map[string]string{
|
||||
"Content-Type": bodies[3].contentType,
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
fsys, err := app.NewBackupsFilesystem()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fsys.Close()
|
||||
// create a dummy backup file to simulate existing backups
|
||||
if err := fsys.Upload([]byte("123"), "test"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
files, _ := getBackupFiles(app)
|
||||
if total := len(files); total != 1 {
|
||||
t.Fatalf("Expected %d backup file, got %d", 1, total)
|
||||
}
|
||||
},
|
||||
ExpectedStatus: 400,
|
||||
ExpectedContent: []string{`"data":{"file":{`},
|
||||
},
|
||||
{
|
||||
Name: "authorized as admin (valid file)",
|
||||
Method: http.MethodPost,
|
||||
Url: "/api/backups/upload",
|
||||
Body: bodies[4].buffer,
|
||||
RequestHeaders: map[string]string{
|
||||
"Content-Type": bodies[4].contentType,
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
files, _ := getBackupFiles(app)
|
||||
if total := len(files); total != 1 {
|
||||
t.Fatalf("Expected %d backup file, got %d", 1, total)
|
||||
}
|
||||
},
|
||||
ExpectedStatus: 204,
|
||||
},
|
||||
}
|
||||
|
||||
for _, scenario := range scenarios {
|
||||
scenario.Test(t)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackupsDownload(t *testing.T) {
|
||||
scenarios := []tests.ApiScenario{
|
||||
{
|
||||
@@ -371,7 +507,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
noTestBackupFilesChanges(t, app)
|
||||
},
|
||||
ExpectedStatus: 401,
|
||||
@@ -389,7 +525,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
noTestBackupFilesChanges(t, app)
|
||||
},
|
||||
ExpectedStatus: 401,
|
||||
@@ -407,7 +543,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
noTestBackupFilesChanges(t, app)
|
||||
},
|
||||
ExpectedStatus: 400,
|
||||
@@ -428,7 +564,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||
// mock active backup with the same name to delete
|
||||
app.Cache().Set(core.CacheKeyActiveBackup, "test1.zip")
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
noTestBackupFilesChanges(t, app)
|
||||
},
|
||||
ExpectedStatus: 400,
|
||||
@@ -449,7 +585,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||
// mock active backup with different name
|
||||
app.Cache().Set(core.CacheKeyActiveBackup, "new.zip")
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
files, err := getBackupFiles(app)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -481,7 +617,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
files, err := getBackupFiles(app)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
+12
-95
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
"github.com/pocketbase/pocketbase/tests"
|
||||
"github.com/pocketbase/pocketbase/tools/list"
|
||||
)
|
||||
@@ -246,7 +245,7 @@ func TestCollectionDelete(t *testing.T) {
|
||||
"OnCollectionBeforeDeleteRequest": 1,
|
||||
"OnCollectionAfterDeleteRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
ensureDeletedFiles(app, "9n89pl5vkct6330")
|
||||
},
|
||||
},
|
||||
@@ -265,7 +264,7 @@ func TestCollectionDelete(t *testing.T) {
|
||||
"OnCollectionBeforeDeleteRequest": 1,
|
||||
"OnCollectionAfterDeleteRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
ensureDeletedFiles(app, "9n89pl5vkct6330")
|
||||
},
|
||||
},
|
||||
@@ -401,7 +400,7 @@ func TestCollectionCreate(t *testing.T) {
|
||||
`"name":"new"`,
|
||||
`"type":"base"`,
|
||||
`"system":false`,
|
||||
`"schema":[{"system":false,"id":"12345789","name":"test","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`,
|
||||
`"schema":[{"system":false,"id":"12345789","name":"test","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`,
|
||||
`"options":{}`,
|
||||
},
|
||||
ExpectedEvents: map[string]int{
|
||||
@@ -425,7 +424,7 @@ func TestCollectionCreate(t *testing.T) {
|
||||
`"name":"new"`,
|
||||
`"type":"auth"`,
|
||||
`"system":false`,
|
||||
`"schema":[{"system":false,"id":"12345789","name":"test","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`,
|
||||
`"schema":[{"system":false,"id":"12345789","name":"test","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`,
|
||||
`"options":{"allowEmailAuth":false,"allowOAuth2Auth":false,"allowUsernameAuth":false,"exceptEmailDomains":null,"manageRule":null,"minPasswordLength":0,"onlyEmailDomains":null,"requireEmail":false}`,
|
||||
},
|
||||
ExpectedEvents: map[string]int{
|
||||
@@ -694,7 +693,7 @@ func TestCollectionCreate(t *testing.T) {
|
||||
"OnCollectionBeforeCreateRequest": 1,
|
||||
"OnCollectionAfterCreateRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
indexes, err := app.Dao().TableIndexes("new")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -824,7 +823,7 @@ func TestCollectionUpdate(t *testing.T) {
|
||||
"OnCollectionBeforeUpdateRequest": 1,
|
||||
"OnCollectionAfterUpdateRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
// check if the record table was renamed
|
||||
if !app.Dao().HasTable("new") {
|
||||
t.Fatal("Couldn't find record table 'new'.")
|
||||
@@ -960,88 +959,6 @@ func TestCollectionUpdate(t *testing.T) {
|
||||
},
|
||||
},
|
||||
|
||||
// rel field change displayFields propagation
|
||||
// -----------------------------------------------------------
|
||||
{
|
||||
Name: "renaming a display field should also update the referenced displayFields value",
|
||||
Method: http.MethodPatch,
|
||||
Url: "/api/collections/demo3",
|
||||
Body: strings.NewReader(`{
|
||||
"schema":[
|
||||
{
|
||||
"id": "w5z2x0nq",
|
||||
"type": "text",
|
||||
"name": "title_change"
|
||||
}
|
||||
]
|
||||
}`),
|
||||
RequestHeaders: map[string]string{
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
ExpectedStatus: 200,
|
||||
ExpectedContent: []string{
|
||||
`"name":"title_change"`,
|
||||
},
|
||||
ExpectedEvents: map[string]int{
|
||||
"OnModelBeforeUpdate": 2,
|
||||
"OnModelAfterUpdate": 2,
|
||||
"OnCollectionBeforeUpdateRequest": 1,
|
||||
"OnCollectionAfterUpdateRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
collection, err := app.Dao().FindCollectionByNameOrId("demo4")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
relField := collection.Schema.GetFieldByName("rel_many_no_cascade_required")
|
||||
options := relField.Options.(*schema.RelationOptions)
|
||||
expectedDisplayFields := []string{"title_change", "id"}
|
||||
if len(list.SubtractSlice(options.DisplayFields, expectedDisplayFields)) != 0 {
|
||||
t.Fatalf("Expected displayFields %v, got %v", expectedDisplayFields, options.DisplayFields)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "deleting a display field should also update the referenced displayFields value",
|
||||
Method: http.MethodPatch,
|
||||
Url: "/api/collections/demo3",
|
||||
Body: strings.NewReader(`{
|
||||
"schema":[
|
||||
{
|
||||
"type": "text",
|
||||
"name": "new_field"
|
||||
}
|
||||
]
|
||||
}`),
|
||||
RequestHeaders: map[string]string{
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
ExpectedStatus: 200,
|
||||
ExpectedContent: []string{
|
||||
`"name":"new_field"`,
|
||||
},
|
||||
ExpectedEvents: map[string]int{
|
||||
"OnModelBeforeUpdate": 2,
|
||||
"OnModelAfterUpdate": 2,
|
||||
"OnCollectionBeforeUpdateRequest": 1,
|
||||
"OnCollectionAfterUpdateRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
collection, err := app.Dao().FindCollectionByNameOrId("demo4")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
relField := collection.Schema.GetFieldByName("rel_many_no_cascade_required")
|
||||
options := relField.Options.(*schema.RelationOptions)
|
||||
expectedDisplayFields := []string{"id"}
|
||||
if len(list.SubtractSlice(options.DisplayFields, expectedDisplayFields)) != 0 {
|
||||
t.Fatalf("Expected displayFields %v, got %v", expectedDisplayFields, options.DisplayFields)
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
// view
|
||||
// -----------------------------------------------------------
|
||||
{
|
||||
@@ -1143,7 +1060,7 @@ func TestCollectionUpdate(t *testing.T) {
|
||||
"OnCollectionBeforeUpdateRequest": 1,
|
||||
"OnCollectionAfterUpdateRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
indexes, err := app.Dao().TableIndexes("new")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1198,7 +1115,7 @@ func TestCollectionsImport(t *testing.T) {
|
||||
`"data":{`,
|
||||
`"collections":{"code":"validation_required"`,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
collections := []*models.Collection{}
|
||||
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1226,7 +1143,7 @@ func TestCollectionsImport(t *testing.T) {
|
||||
"OnCollectionsBeforeImportRequest": 1,
|
||||
"OnModelBeforeDelete": 4,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
collections := []*models.Collection{}
|
||||
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1268,7 +1185,7 @@ func TestCollectionsImport(t *testing.T) {
|
||||
"OnCollectionsBeforeImportRequest": 1,
|
||||
"OnModelBeforeCreate": 2,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
collections := []*models.Collection{}
|
||||
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1324,7 +1241,7 @@ func TestCollectionsImport(t *testing.T) {
|
||||
"OnModelBeforeCreate": 3,
|
||||
"OnModelAfterCreate": 3,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
collections := []*models.Collection{}
|
||||
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1429,7 +1346,7 @@ func TestCollectionsImport(t *testing.T) {
|
||||
"OnModelBeforeCreate": 1,
|
||||
"OnModelAfterCreate": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
collections := []*models.Collection{}
|
||||
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
+2
-3
@@ -56,9 +56,8 @@ func (api *realtimeApi) connect(c echo.Context) error {
|
||||
api.app.SubscriptionsBroker().Unregister(client.Id())
|
||||
}()
|
||||
|
||||
c.Response().Header().Set("Content-Type", "text/event-stream; charset=UTF-8")
|
||||
c.Response().Header().Set("Content-Type", "text/event-stream")
|
||||
c.Response().Header().Set("Cache-Control", "no-store")
|
||||
c.Response().Header().Set("Connection", "keep-alive")
|
||||
// https://github.com/pocketbase/pocketbase/discussions/480#discussioncomment-3657640
|
||||
// https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering
|
||||
c.Response().Header().Set("X-Accel-Buffering", "no")
|
||||
@@ -371,8 +370,8 @@ func (api *realtimeApi) canAccessRecord(client subscriptions.Client, record *mod
|
||||
}
|
||||
|
||||
type recordData struct {
|
||||
Action string `json:"action"`
|
||||
Record *models.Record `json:"record"`
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
func (api *realtimeApi) broadcastRecord(action string, record *models.Record, dryCache bool) error {
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestRealtimeConnect(t *testing.T) {
|
||||
"OnRealtimeAfterMessageSend": 1,
|
||||
"OnRealtimeDisconnectRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
if len(app.SubscriptionsBroker().Clients()) != 0 {
|
||||
t.Errorf("Expected the subscribers to be removed after connection close, found %d", len(app.SubscriptionsBroker().Clients()))
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func TestRealtimeConnect(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
if len(app.SubscriptionsBroker().Clients()) != 0 {
|
||||
t.Errorf("Expected the subscribers to be removed after connection close, found %d", len(app.SubscriptionsBroker().Clients()))
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func TestRealtimeConnect(t *testing.T) {
|
||||
return hook.StopPropagation
|
||||
})
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
if len(app.SubscriptionsBroker().Clients()) != 0 {
|
||||
t.Errorf("Expected the subscribers to be removed after connection close, found %d", len(app.SubscriptionsBroker().Clients()))
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func TestRealtimeSubscribe(t *testing.T) {
|
||||
client.Subscribe("test0")
|
||||
app.SubscriptionsBroker().Register(client)
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
if len(client.Subscriptions()) != 0 {
|
||||
t.Errorf("Expected no subscriptions, got %v", client.Subscriptions())
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func TestRealtimeSubscribe(t *testing.T) {
|
||||
client.Subscribe("test0")
|
||||
app.SubscriptionsBroker().Register(client)
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
expectedSubs := []string{"test1", "test2"}
|
||||
if len(expectedSubs) != len(client.Subscriptions()) {
|
||||
t.Errorf("Expected subscriptions %v, got %v", expectedSubs, client.Subscriptions())
|
||||
@@ -175,7 +175,7 @@ func TestRealtimeSubscribe(t *testing.T) {
|
||||
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
app.SubscriptionsBroker().Register(client)
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
admin, _ := client.Get(apis.ContextAdminKey).(*models.Admin)
|
||||
if admin == nil {
|
||||
t.Errorf("Expected admin auth model, got nil")
|
||||
@@ -199,7 +199,7 @@ func TestRealtimeSubscribe(t *testing.T) {
|
||||
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
app.SubscriptionsBroker().Register(client)
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
authRecord, _ := client.Get(apis.ContextAuthRecordKey).(*models.Record)
|
||||
if authRecord == nil {
|
||||
t.Errorf("Expected auth record model, got nil")
|
||||
@@ -224,7 +224,7 @@ func TestRealtimeSubscribe(t *testing.T) {
|
||||
|
||||
app.SubscriptionsBroker().Register(client)
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
authRecord, _ := client.Get(apis.ContextAuthRecordKey).(*models.Record)
|
||||
if authRecord == nil {
|
||||
t.Errorf("Expected auth record model, got nil")
|
||||
|
||||
@@ -1188,7 +1188,7 @@ func TestRecordAuthUnlinkExternalsAuth(t *testing.T) {
|
||||
"OnRecordAfterUnlinkExternalAuthRequest": 1,
|
||||
"OnRecordBeforeUnlinkExternalAuthRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
record, err := app.Dao().FindRecordById("users", "4q1xlclmfloku33")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1234,7 +1234,7 @@ func TestRecordAuthUnlinkExternalsAuth(t *testing.T) {
|
||||
"OnRecordAfterUnlinkExternalAuthRequest": 1,
|
||||
"OnRecordBeforeUnlinkExternalAuthRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
record, err := app.Dao().FindRecordById("users", "4q1xlclmfloku33")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -903,7 +903,7 @@ func TestRecordCrudDelete(t *testing.T) {
|
||||
"OnRecordAfterDeleteRequest": 1,
|
||||
"OnRecordBeforeDeleteRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
ensureDeletedFiles(app, "_pb_users_auth_", "4q1xlclmfloku33")
|
||||
|
||||
// check if all the external auths records were deleted
|
||||
@@ -990,7 +990,7 @@ func TestRecordCrudDelete(t *testing.T) {
|
||||
"OnRecordBeforeDeleteRequest": 1,
|
||||
"OnRecordAfterDeleteRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
recId := "84nmscqy84lsi1t"
|
||||
rec, _ := app.Dao().FindRecordById("demo1", recId, nil)
|
||||
if rec != nil {
|
||||
@@ -2032,7 +2032,7 @@ func TestRecordCrudUpdate(t *testing.T) {
|
||||
"OnRecordAfterUpdateRequest": 1,
|
||||
"OnRecordBeforeUpdateRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
record, _ := app.Dao().FindRecordById("nologin", "phhq3wr65cap535")
|
||||
if !record.ValidatePassword("12345678") {
|
||||
t.Fatal("Password update failed.")
|
||||
@@ -2075,7 +2075,7 @@ func TestRecordCrudUpdate(t *testing.T) {
|
||||
"OnRecordAfterUpdateRequest": 1,
|
||||
"OnRecordBeforeUpdateRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
record, _ := app.Dao().FindRecordById("users", "oap640cot4yru2s")
|
||||
if !record.ValidatePassword("12345678") {
|
||||
t.Fatal("Password update failed.")
|
||||
@@ -2137,7 +2137,7 @@ func TestRecordCrudUpdate(t *testing.T) {
|
||||
"OnRecordAfterUpdateRequest": 1,
|
||||
"OnRecordBeforeUpdateRequest": 1,
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
record, _ := app.Dao().FindRecordById("nologin", "dc49k6jgejn40h3")
|
||||
if !record.ValidatePassword("123456789") {
|
||||
t.Fatal("Password update failed.")
|
||||
|
||||
+70
-7
@@ -11,11 +11,13 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/labstack/echo/v5/middleware"
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/migrations/logs"
|
||||
"github.com/pocketbase/pocketbase/tools/list"
|
||||
"github.com/pocketbase/pocketbase/tools/migrate"
|
||||
"golang.org/x/crypto/acme"
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
@@ -26,17 +28,35 @@ type ServeConfig struct {
|
||||
// ShowStartBanner indicates whether to show or hide the server start console message.
|
||||
ShowStartBanner bool
|
||||
|
||||
// HttpAddr is the HTTP server address to bind (eg. `127.0.0.1:80`).
|
||||
// HttpAddr is the TCP address to listen for the HTTP server (eg. `127.0.0.1:80`).
|
||||
HttpAddr string
|
||||
|
||||
// HttpsAddr is the HTTPS server address to bind (eg. `127.0.0.1:443`).
|
||||
// HttpsAddr is the TCP address to listen for the HTTPS server (eg. `127.0.0.1:443`).
|
||||
HttpsAddr string
|
||||
|
||||
// Optional domains list to use when issuing the TLS certificate.
|
||||
//
|
||||
// If not set, the host from the bound server address will be used.
|
||||
//
|
||||
// For convenience, for each "non-www" domain a "www" entry and
|
||||
// redirect will be automatically added.
|
||||
CertificateDomains []string
|
||||
|
||||
// AllowedOrigins is an optional list of CORS origins (default to "*").
|
||||
AllowedOrigins []string
|
||||
}
|
||||
|
||||
// Serve starts a new app web server.
|
||||
//
|
||||
// NB! The app should be bootstrapped before starting the web server.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// app.Bootstrap()
|
||||
// apis.Serve(app, apis.ServeConfig{
|
||||
// HttpAddr: "127.0.0.1:8080",
|
||||
// ShowStartBanner: false,
|
||||
// })
|
||||
func Serve(app core.App, config ServeConfig) (*http.Server, error) {
|
||||
if len(config.AllowedOrigins) == 0 {
|
||||
config.AllowedOrigins = []string{"*"}
|
||||
@@ -75,16 +95,53 @@ func Serve(app core.App, config ServeConfig) (*http.Server, error) {
|
||||
mainAddr = config.HttpsAddr
|
||||
}
|
||||
|
||||
mainHost, _, _ := net.SplitHostPort(mainAddr)
|
||||
var wwwRedirects []string
|
||||
|
||||
// extract the host names for the certificate host policy
|
||||
hostNames := config.CertificateDomains
|
||||
if len(hostNames) == 0 {
|
||||
host, _, _ := net.SplitHostPort(mainAddr)
|
||||
hostNames = append(hostNames, host)
|
||||
}
|
||||
for _, host := range hostNames {
|
||||
if strings.HasPrefix(host, "www.") {
|
||||
continue // explicitly set www host
|
||||
}
|
||||
|
||||
wwwHost := "www." + host
|
||||
if !list.ExistInSlice(wwwHost, hostNames) {
|
||||
hostNames = append(hostNames, wwwHost)
|
||||
wwwRedirects = append(wwwRedirects, wwwHost)
|
||||
}
|
||||
}
|
||||
|
||||
// implicit www->non-www redirect(s)
|
||||
if len(wwwRedirects) > 0 {
|
||||
router.Pre(func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
host := c.Request().Host
|
||||
|
||||
if strings.HasPrefix(host, "www.") && list.ExistInSlice(host, wwwRedirects) {
|
||||
return c.Redirect(
|
||||
http.StatusTemporaryRedirect,
|
||||
(c.Scheme() + "://" + host[4:] + c.Request().RequestURI),
|
||||
)
|
||||
}
|
||||
|
||||
return next(c)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
certManager := &autocert.Manager{
|
||||
Prompt: autocert.AcceptTOS,
|
||||
Cache: autocert.DirCache(filepath.Join(app.DataDir(), ".autocert_cache")),
|
||||
HostPolicy: autocert.HostWhitelist(mainHost, "www."+mainHost),
|
||||
HostPolicy: autocert.HostWhitelist(hostNames...),
|
||||
}
|
||||
|
||||
server := &http.Server{
|
||||
TLSConfig: &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
GetCertificate: certManager.GetCertificate,
|
||||
NextProtos: []string{acme.ALPNProto},
|
||||
},
|
||||
@@ -107,8 +164,14 @@ func Serve(app core.App, config ServeConfig) (*http.Server, error) {
|
||||
|
||||
if config.ShowStartBanner {
|
||||
schema := "http"
|
||||
addr := server.Addr
|
||||
|
||||
if config.HttpsAddr != "" {
|
||||
schema = "https"
|
||||
|
||||
if len(config.CertificateDomains) > 0 {
|
||||
addr = config.CertificateDomains[0]
|
||||
}
|
||||
}
|
||||
|
||||
date := new(strings.Builder)
|
||||
@@ -118,12 +181,12 @@ func Serve(app core.App, config ServeConfig) (*http.Server, error) {
|
||||
bold.Printf(
|
||||
"%s Server started at %s\n",
|
||||
strings.TrimSpace(date.String()),
|
||||
color.CyanString("%s://%s", schema, server.Addr),
|
||||
color.CyanString("%s://%s", schema, addr),
|
||||
)
|
||||
|
||||
regular := color.New()
|
||||
regular.Printf("├─ REST API: %s\n", color.CyanString("%s://%s/api/", schema, server.Addr))
|
||||
regular.Printf("└─ Admin UI: %s\n", color.CyanString("%s://%s/_/", schema, server.Addr))
|
||||
regular.Printf("├─ REST API: %s\n", color.CyanString("%s://%s/api/", schema, addr))
|
||||
regular.Printf("└─ Admin UI: %s\n", color.CyanString("%s://%s/_/", schema, addr))
|
||||
}
|
||||
|
||||
// try to gracefully shutdown the server on app termination
|
||||
|
||||
@@ -80,6 +80,8 @@ func TestSettingsList(t *testing.T) {
|
||||
`"instagramAuth":{`,
|
||||
`"vkAuth":{`,
|
||||
`"yandexAuth":{`,
|
||||
`"patreonAuth":{`,
|
||||
`"mailcowAuth":{`,
|
||||
`"secret":"******"`,
|
||||
`"clientSecret":"******"`,
|
||||
},
|
||||
@@ -161,6 +163,8 @@ func TestSettingsSet(t *testing.T) {
|
||||
`"instagramAuth":{`,
|
||||
`"vkAuth":{`,
|
||||
`"yandexAuth":{`,
|
||||
`"patreonAuth":{`,
|
||||
`"mailcowAuth":{`,
|
||||
`"secret":"******"`,
|
||||
`"clientSecret":"******"`,
|
||||
`"appName":"acme_test"`,
|
||||
@@ -231,6 +235,8 @@ func TestSettingsSet(t *testing.T) {
|
||||
`"instagramAuth":{`,
|
||||
`"vkAuth":{`,
|
||||
`"yandexAuth":{`,
|
||||
`"patreonAuth":{`,
|
||||
`"mailcowAuth":{`,
|
||||
`"secret":"******"`,
|
||||
`"clientSecret":"******"`,
|
||||
`"appName":"update_test"`,
|
||||
@@ -400,7 +406,7 @@ func TestSettingsTestEmail(t *testing.T) {
|
||||
RequestHeaders: map[string]string{
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
if app.TestMailer.TotalSend != 1 {
|
||||
t.Fatalf("[verification] Expected 1 sent email, got %d", app.TestMailer.TotalSend)
|
||||
}
|
||||
@@ -435,7 +441,7 @@ func TestSettingsTestEmail(t *testing.T) {
|
||||
RequestHeaders: map[string]string{
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
if app.TestMailer.TotalSend != 1 {
|
||||
t.Fatalf("[password-reset] Expected 1 sent email, got %d", app.TestMailer.TotalSend)
|
||||
}
|
||||
@@ -470,7 +476,7 @@ func TestSettingsTestEmail(t *testing.T) {
|
||||
RequestHeaders: map[string]string{
|
||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||
},
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||
if app.TestMailer.TotalSend != 1 {
|
||||
t.Fatalf("[email-change] Expected 1 sent email, got %d", app.TestMailer.TotalSend)
|
||||
}
|
||||
|
||||
+25
-9
@@ -17,14 +17,30 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command {
|
||||
var httpsAddr string
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "serve",
|
||||
Short: "Starts the web server (default to 127.0.0.1:8090)",
|
||||
Use: "serve [domain(s)]",
|
||||
Args: cobra.ArbitraryArgs,
|
||||
Short: "Starts the web server (default to 127.0.0.1:8090 if no domain is specified)",
|
||||
Run: func(command *cobra.Command, args []string) {
|
||||
// set default listener addresses if at least one domain is specified
|
||||
if len(args) > 0 {
|
||||
if httpAddr == "" {
|
||||
httpAddr = "0.0.0.0:80"
|
||||
}
|
||||
if httpsAddr == "" {
|
||||
httpsAddr = "0.0.0.0:443"
|
||||
}
|
||||
} else {
|
||||
if httpAddr == "" {
|
||||
httpAddr = "127.0.0.1:8090"
|
||||
}
|
||||
}
|
||||
|
||||
_, err := apis.Serve(app, apis.ServeConfig{
|
||||
HttpAddr: httpAddr,
|
||||
HttpsAddr: httpsAddr,
|
||||
ShowStartBanner: showStartBanner,
|
||||
AllowedOrigins: allowedOrigins,
|
||||
HttpAddr: httpAddr,
|
||||
HttpsAddr: httpsAddr,
|
||||
ShowStartBanner: showStartBanner,
|
||||
AllowedOrigins: allowedOrigins,
|
||||
CertificateDomains: args,
|
||||
})
|
||||
|
||||
if err != http.ErrServerClosed {
|
||||
@@ -43,15 +59,15 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command {
|
||||
command.PersistentFlags().StringVar(
|
||||
&httpAddr,
|
||||
"http",
|
||||
"127.0.0.1:8090",
|
||||
"api HTTP server address",
|
||||
"",
|
||||
"TCP address to listen for the HTTP server\n(if domain args are specified - default to 0.0.0.0:80, otherwise - default to 127.0.0.1:8090)",
|
||||
)
|
||||
|
||||
command.PersistentFlags().StringVar(
|
||||
&httpsAddr,
|
||||
"https",
|
||||
"",
|
||||
"api HTTPS server address (auto TLS via Let's Encrypt)\nthe incoming --http address traffic also will be redirected to this address",
|
||||
"TCP address to listen for the HTTPS server\n(if domain args are specified - default to 0.0.0.0:443, otherwise - default to empty string, aka. no TLS)\nThe incoming HTTP traffic also will be auto redirected to the HTTPS version",
|
||||
)
|
||||
|
||||
return command
|
||||
|
||||
+1
-1
@@ -375,7 +375,6 @@ func (app *BaseApp) ResetBootstrapState() error {
|
||||
|
||||
app.dao = nil
|
||||
app.logsDao = nil
|
||||
app.settings = nil
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -471,6 +470,7 @@ func (app *BaseApp) NewMailClient() mailer.Mailer {
|
||||
Password: app.Settings().Smtp.Password,
|
||||
Tls: app.Settings().Smtp.Tls,
|
||||
AuthMethod: app.Settings().Smtp.AuthMethod,
|
||||
LocalName: app.Settings().Smtp.LocalName,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-14
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/pocketbase/pocketbase/tools/archive"
|
||||
"github.com/pocketbase/pocketbase/tools/cron"
|
||||
"github.com/pocketbase/pocketbase/tools/filesystem"
|
||||
"github.com/pocketbase/pocketbase/tools/inflector"
|
||||
"github.com/pocketbase/pocketbase/tools/osutils"
|
||||
"github.com/pocketbase/pocketbase/tools/security"
|
||||
)
|
||||
@@ -46,17 +47,16 @@ func (app *BaseApp) CreateBackup(ctx context.Context, name string) error {
|
||||
return errors.New("try again later - another backup/restore operation has already been started")
|
||||
}
|
||||
|
||||
// auto generate backup name
|
||||
if name == "" {
|
||||
name = fmt.Sprintf(
|
||||
"pb_backup_%s.zip",
|
||||
time.Now().UTC().Format("20060102150405"),
|
||||
)
|
||||
name = app.generateBackupName("pb_backup_")
|
||||
}
|
||||
|
||||
app.Cache().Set(CacheKeyActiveBackup, name)
|
||||
defer app.Cache().Remove(CacheKeyActiveBackup)
|
||||
|
||||
// root dir entries to exclude from the backup generation
|
||||
exclude := []string{LocalBackupsDirName, LocalTempDirName}
|
||||
|
||||
// make sure that the special temp directory exists
|
||||
// note: it needs to be inside the current pb_data to avoid "cross-device link" errors
|
||||
localTempDir := filepath.Join(app.DataDir(), LocalTempDirName)
|
||||
@@ -64,14 +64,14 @@ func (app *BaseApp) CreateBackup(ctx context.Context, name string) error {
|
||||
return fmt.Errorf("failed to create a temp dir: %w", err)
|
||||
}
|
||||
|
||||
// Archive pb_data in a temp directory, exluding the "backups" dir itself (if exist).
|
||||
// Archive pb_data in a temp directory, exluding the "backups" and the temp dirs.
|
||||
//
|
||||
// Run in transaction to temporary block other writes (transactions uses the NonconcurrentDB connection).
|
||||
// ---
|
||||
tempPath := filepath.Join(localTempDir, "pb_backup_"+security.PseudorandomString(4))
|
||||
createErr := app.Dao().RunInTransaction(func(txDao *daos.Dao) error {
|
||||
// @todo consider experimenting with temp switching the readonly pragma after the db interface change
|
||||
return archive.Create(app.DataDir(), tempPath, LocalBackupsDirName)
|
||||
return archive.Create(app.DataDir(), tempPath, exclude...)
|
||||
})
|
||||
if createErr != nil {
|
||||
return createErr
|
||||
@@ -234,7 +234,6 @@ func (app *BaseApp) RestoreBackup(ctx context.Context, name string) error {
|
||||
}
|
||||
|
||||
// initAutobackupHooks registers the autobackup app serve hooks.
|
||||
// @todo add tests
|
||||
func (app *BaseApp) initAutobackupHooks() error {
|
||||
c := cron.New()
|
||||
isServe := false
|
||||
@@ -248,13 +247,9 @@ func (app *BaseApp) initAutobackupHooks() error {
|
||||
}
|
||||
|
||||
c.Add("@autobackup", rawSchedule, func() {
|
||||
autoPrefix := "@auto_pb_backup_"
|
||||
const autoPrefix = "@auto_pb_backup_"
|
||||
|
||||
name := fmt.Sprintf(
|
||||
"%s%s.zip",
|
||||
autoPrefix,
|
||||
time.Now().UTC().Format("20060102150405"),
|
||||
)
|
||||
name := app.generateBackupName(autoPrefix)
|
||||
|
||||
if err := app.CreateBackup(context.Background(), name); err != nil && app.IsDebug() {
|
||||
// @todo replace after logs generalization
|
||||
@@ -333,3 +328,17 @@ func (app *BaseApp) initAutobackupHooks() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (app *BaseApp) generateBackupName(prefix string) string {
|
||||
appName := inflector.Snakecase(app.Settings().Meta.AppName)
|
||||
if len(appName) > 50 {
|
||||
appName = appName[:50]
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"%s%s_%s.zip",
|
||||
prefix,
|
||||
appName,
|
||||
time.Now().UTC().Format("20060102150405"),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,11 @@ func TestCreateBackup(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
// set some long app name with spaces and special characters
|
||||
app.Settings().Meta.AppName = "test @! " + strings.Repeat("a", 100)
|
||||
|
||||
expectedAppNamePrefix := "test_" + strings.Repeat("a", 45)
|
||||
|
||||
// test pending error
|
||||
app.Cache().Set(core.CacheKeyActiveBackup, "")
|
||||
if err := app.CreateBackup(context.Background(), "test.zip"); err == nil {
|
||||
@@ -49,8 +54,8 @@ func TestCreateBackup(t *testing.T) {
|
||||
}
|
||||
|
||||
expectedFiles := []string{
|
||||
`^pb_backup_\w+\.zip$`,
|
||||
`^pb_backup_\w+\.zip.attrs$`,
|
||||
`^pb_backup_` + expectedAppNamePrefix + `_\w+\.zip$`,
|
||||
`^pb_backup_` + expectedAppNamePrefix + `_\w+\.zip.attrs$`,
|
||||
"custom",
|
||||
"custom.attrs",
|
||||
}
|
||||
@@ -127,7 +132,6 @@ func verifyBackupContent(app core.App, path string) error {
|
||||
"logs.db-shm",
|
||||
"logs.db-wal",
|
||||
".gitignore",
|
||||
".pb_temp_to_delete",
|
||||
}
|
||||
|
||||
entries, err := os.ReadDir(dir)
|
||||
|
||||
@@ -118,10 +118,6 @@ func TestBaseAppBootstrap(t *testing.T) {
|
||||
if app.logsDao != nil {
|
||||
t.Fatalf("Expected app.logsDao to be nil, got %v.", app.logsDao)
|
||||
}
|
||||
|
||||
if app.settings != nil {
|
||||
t.Fatalf("Expected app.settings to be nil, got %v.", app.settings)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseAppGetters(t *testing.T) {
|
||||
|
||||
@@ -402,6 +402,8 @@ func (dao *Dao) saveViewCollection(newCollection, oldCollection *models.Collecti
|
||||
// currently we don't support non-string model ids
|
||||
// (see https://github.com/pocketbase/pocketbase/issues/3110).
|
||||
func (dao *Dao) normalizeViewQueryId(query string) (string, error) {
|
||||
query = strings.Trim(strings.TrimSpace(query), ";")
|
||||
|
||||
parsed, err := dao.parseQueryToFields(query)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
+25
-10
@@ -252,23 +252,31 @@ func (dao *Dao) FindFirstRecordByData(
|
||||
// FindRecordsByFilter returns limit number of records matching the
|
||||
// provided string filter.
|
||||
//
|
||||
// NB! Use the last "params" argument to bind untrusted user variables!
|
||||
//
|
||||
// The sort argument is optional and can be empty string OR the same format
|
||||
// used in the web APIs, eg. "-created,title".
|
||||
//
|
||||
// If the limit argument is <= 0, no limit is applied to the query and
|
||||
// all matching records are returned.
|
||||
//
|
||||
// NB! Don't put untrusted user input in the filter string as it
|
||||
// practically would allow the users to inject their own custom filter.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// dao.FindRecordsByFilter("posts", "title ~ 'lorem ipsum' && visible = true", "-created", 10)
|
||||
// dao.FindRecordsByFilter(
|
||||
// "posts",
|
||||
// "title ~ {:title} && visible = {:visible}",
|
||||
// "-created",
|
||||
// 10,
|
||||
// 0,
|
||||
// dbx.Params{"title": "lorem ipsum", "visible": true}
|
||||
// )
|
||||
func (dao *Dao) FindRecordsByFilter(
|
||||
collectionNameOrId string,
|
||||
filter string,
|
||||
sort string,
|
||||
limit int,
|
||||
offset int,
|
||||
params ...dbx.Params,
|
||||
) ([]*models.Record, error) {
|
||||
collection, err := dao.FindCollectionByNameOrId(collectionNameOrId)
|
||||
if err != nil {
|
||||
@@ -286,7 +294,7 @@ func (dao *Dao) FindRecordsByFilter(
|
||||
true, // allow searching hidden/protected fields like "email"
|
||||
)
|
||||
|
||||
expr, err := search.FilterData(filter).BuildExpr(resolver)
|
||||
expr, err := search.FilterData(filter).BuildExpr(resolver, params...)
|
||||
if err != nil || expr == nil {
|
||||
return nil, errors.New("invalid or empty filter expression")
|
||||
}
|
||||
@@ -307,6 +315,10 @@ func (dao *Dao) FindRecordsByFilter(
|
||||
resolver.UpdateQuery(q) // attaches any adhoc joins and aliases
|
||||
// ---
|
||||
|
||||
if offset > 0 {
|
||||
q.Offset(int64(offset))
|
||||
}
|
||||
|
||||
if limit > 0 {
|
||||
q.Limit(int64(limit))
|
||||
}
|
||||
@@ -322,14 +334,17 @@ func (dao *Dao) FindRecordsByFilter(
|
||||
|
||||
// FindFirstRecordByFilter returns the first available record matching the provided filter.
|
||||
//
|
||||
// NB! Don't put untrusted user input in the filter string as it
|
||||
// practically would allow the users to inject their own custom filter.
|
||||
// NB! Use the last params argument to bind untrusted user variables!
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// dao.FindFirstRecordByFilter("posts", "slug='test'")
|
||||
func (dao *Dao) FindFirstRecordByFilter(collectionNameOrId string, filter string) (*models.Record, error) {
|
||||
result, err := dao.FindRecordsByFilter(collectionNameOrId, filter, "", 1)
|
||||
// dao.FindFirstRecordByFilter("posts", "slug={:slug} && status='public'", dbx.Params{"slug": "test"})
|
||||
func (dao *Dao) FindFirstRecordByFilter(
|
||||
collectionNameOrId string,
|
||||
filter string,
|
||||
params ...dbx.Params,
|
||||
) (*models.Record, error) {
|
||||
result, err := dao.FindRecordsByFilter(collectionNameOrId, filter, "", 1, 0, params...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
"github.com/pocketbase/pocketbase/tools/dbutils"
|
||||
"github.com/pocketbase/pocketbase/tools/list"
|
||||
"github.com/pocketbase/pocketbase/tools/security"
|
||||
)
|
||||
|
||||
@@ -159,10 +158,6 @@ func (dao *Dao) SyncRecordTableSchema(newCollection *models.Collection, oldColle
|
||||
return err
|
||||
}
|
||||
|
||||
if err := txDao.syncRelationDisplayFieldsChanges(newCollection, renamedFieldNames, deletedFieldNames); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return txDao.createCollectionIndexes(newCollection)
|
||||
})
|
||||
}
|
||||
@@ -294,50 +289,6 @@ func (dao *Dao) normalizeSingleVsMultipleFieldChanges(newCollection, oldCollecti
|
||||
})
|
||||
}
|
||||
|
||||
func (dao *Dao) syncRelationDisplayFieldsChanges(collection *models.Collection, renamedFieldNames map[string]string, deletedFieldNames []string) error {
|
||||
if len(renamedFieldNames) == 0 && len(deletedFieldNames) == 0 {
|
||||
return nil // nothing to sync
|
||||
}
|
||||
|
||||
refs, err := dao.FindCollectionReferences(collection)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for refCollection, refFields := range refs {
|
||||
for _, refField := range refFields {
|
||||
options, _ := refField.Options.(*schema.RelationOptions)
|
||||
if options == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// remove deleted (if any)
|
||||
newDisplayFields := list.SubtractSlice(options.DisplayFields, deletedFieldNames)
|
||||
|
||||
for old, new := range renamedFieldNames {
|
||||
for i, name := range newDisplayFields {
|
||||
if name == old {
|
||||
newDisplayFields[i] = new
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// has changes
|
||||
if len(list.SubtractSlice(options.DisplayFields, newDisplayFields)) > 0 {
|
||||
options.DisplayFields = newDisplayFields
|
||||
|
||||
// direct collection save to prevent self-referencing
|
||||
// recursion and unnecessary records table sync checks
|
||||
if err := dao.Save(refCollection); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dao *Dao) dropCollectionIndex(collection *models.Collection) error {
|
||||
if collection.IsView() {
|
||||
return nil // views don't have indexes
|
||||
|
||||
+71
-28
@@ -436,6 +436,8 @@ func TestFindRecordsByFilter(t *testing.T) {
|
||||
filter string
|
||||
sort string
|
||||
limit int
|
||||
offset int
|
||||
params []dbx.Params
|
||||
expectError bool
|
||||
expectRecordIds []string
|
||||
}{
|
||||
@@ -445,6 +447,8 @@ func TestFindRecordsByFilter(t *testing.T) {
|
||||
"id != ''",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
nil,
|
||||
true,
|
||||
nil,
|
||||
},
|
||||
@@ -454,6 +458,8 @@ func TestFindRecordsByFilter(t *testing.T) {
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
nil,
|
||||
true,
|
||||
nil,
|
||||
},
|
||||
@@ -463,6 +469,8 @@ func TestFindRecordsByFilter(t *testing.T) {
|
||||
"someMissingField > 1",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
nil,
|
||||
true,
|
||||
nil,
|
||||
},
|
||||
@@ -472,6 +480,8 @@ func TestFindRecordsByFilter(t *testing.T) {
|
||||
"id != ''",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
nil,
|
||||
false,
|
||||
[]string{
|
||||
"llvuca81nly1qls",
|
||||
@@ -485,6 +495,8 @@ func TestFindRecordsByFilter(t *testing.T) {
|
||||
"id != '' && active=true",
|
||||
"-created,title",
|
||||
-1, // should behave the same as 0
|
||||
0,
|
||||
nil,
|
||||
false,
|
||||
[]string{
|
||||
"0yxhwia2amd8gec",
|
||||
@@ -492,47 +504,64 @@ func TestFindRecordsByFilter(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
"with limit",
|
||||
"with limit and offset",
|
||||
"demo2",
|
||||
"id != ''",
|
||||
"title",
|
||||
2,
|
||||
1,
|
||||
nil,
|
||||
false,
|
||||
[]string{
|
||||
"achvryl401bhse3",
|
||||
"0yxhwia2amd8gec",
|
||||
},
|
||||
},
|
||||
{
|
||||
"with placeholder params",
|
||||
"demo2",
|
||||
"active = {:active}",
|
||||
"",
|
||||
10,
|
||||
0,
|
||||
[]dbx.Params{{"active": false}},
|
||||
false,
|
||||
[]string{
|
||||
"llvuca81nly1qls",
|
||||
"achvryl401bhse3",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
records, err := app.Dao().FindRecordsByFilter(
|
||||
s.collectionIdOrName,
|
||||
s.filter,
|
||||
s.sort,
|
||||
s.limit,
|
||||
)
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
records, err := app.Dao().FindRecordsByFilter(
|
||||
s.collectionIdOrName,
|
||||
s.filter,
|
||||
s.sort,
|
||||
s.limit,
|
||||
s.offset,
|
||||
s.params...,
|
||||
)
|
||||
|
||||
hasErr := err != nil
|
||||
if hasErr != s.expectError {
|
||||
t.Errorf("[%s] Expected hasErr to be %v, got %v (%v)", s.name, s.expectError, hasErr, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if hasErr {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(records) != len(s.expectRecordIds) {
|
||||
t.Errorf("[%s] Expected %d records, got %d", s.name, len(s.expectRecordIds), len(records))
|
||||
continue
|
||||
}
|
||||
|
||||
for i, id := range s.expectRecordIds {
|
||||
if id != records[i].Id {
|
||||
t.Errorf("[%s] Expected record with id %q, got %q at index %d", s.name, id, records[i].Id, i)
|
||||
hasErr := err != nil
|
||||
if hasErr != s.expectError {
|
||||
t.Fatalf("[%s] Expected hasErr to be %v, got %v (%v)", s.name, s.expectError, hasErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
if hasErr {
|
||||
return
|
||||
}
|
||||
|
||||
if len(records) != len(s.expectRecordIds) {
|
||||
t.Fatalf("[%s] Expected %d records, got %d", s.name, len(s.expectRecordIds), len(records))
|
||||
}
|
||||
|
||||
for i, id := range s.expectRecordIds {
|
||||
if id != records[i].Id {
|
||||
t.Fatalf("[%s] Expected record with id %q, got %q at index %d", s.name, id, records[i].Id, i)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,6 +573,7 @@ func TestFindFirstRecordByFilter(t *testing.T) {
|
||||
name string
|
||||
collectionIdOrName string
|
||||
filter string
|
||||
params []dbx.Params
|
||||
expectError bool
|
||||
expectRecordId string
|
||||
}{
|
||||
@@ -551,6 +581,7 @@ func TestFindFirstRecordByFilter(t *testing.T) {
|
||||
"missing collection",
|
||||
"missing",
|
||||
"id != ''",
|
||||
nil,
|
||||
true,
|
||||
"",
|
||||
},
|
||||
@@ -558,6 +589,7 @@ func TestFindFirstRecordByFilter(t *testing.T) {
|
||||
"missing filter",
|
||||
"demo2",
|
||||
"",
|
||||
nil,
|
||||
true,
|
||||
"",
|
||||
},
|
||||
@@ -565,6 +597,7 @@ func TestFindFirstRecordByFilter(t *testing.T) {
|
||||
"invalid filter",
|
||||
"demo2",
|
||||
"someMissingField > 1",
|
||||
nil,
|
||||
true,
|
||||
"",
|
||||
},
|
||||
@@ -572,6 +605,7 @@ func TestFindFirstRecordByFilter(t *testing.T) {
|
||||
"valid filter but no matches",
|
||||
"demo2",
|
||||
"id = 'test'",
|
||||
nil,
|
||||
true,
|
||||
"",
|
||||
},
|
||||
@@ -579,13 +613,22 @@ func TestFindFirstRecordByFilter(t *testing.T) {
|
||||
"valid filter and multiple matches",
|
||||
"demo2",
|
||||
"id != ''",
|
||||
nil,
|
||||
false,
|
||||
"llvuca81nly1qls",
|
||||
},
|
||||
{
|
||||
"with placeholder params",
|
||||
"demo2",
|
||||
"active = {:active}",
|
||||
[]dbx.Params{{"active": false}},
|
||||
false,
|
||||
"llvuca81nly1qls",
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
record, err := app.Dao().FindFirstRecordByFilter(s.collectionIdOrName, s.filter)
|
||||
record, err := app.Dao().FindFirstRecordByFilter(s.collectionIdOrName, s.filter, s.params...)
|
||||
|
||||
hasErr := err != nil
|
||||
if hasErr != s.expectError {
|
||||
|
||||
+14
-7
@@ -43,10 +43,10 @@ func (dao *Dao) SaveView(name string, selectQuery string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
trimmed := strings.Trim(selectQuery, ";")
|
||||
selectQuery = strings.Trim(strings.TrimSpace(selectQuery), ";")
|
||||
|
||||
// try to eagerly detect multiple inline statements
|
||||
tk := tokenizer.NewFromString(trimmed)
|
||||
tk := tokenizer.NewFromString(selectQuery)
|
||||
tk.Separators(';')
|
||||
if queryParts, _ := tk.ScanAll(); len(queryParts) > 1 {
|
||||
return errors.New("multiple statements are not supported")
|
||||
@@ -56,7 +56,7 @@ func (dao *Dao) SaveView(name string, selectQuery string) error {
|
||||
//
|
||||
// note: the query is wrapped in a secondary SELECT as a rudimentary
|
||||
// measure to discourage multiple inline sql statements execution.
|
||||
viewQuery := fmt.Sprintf("CREATE VIEW {{%s}} AS SELECT * FROM (%s)", name, trimmed)
|
||||
viewQuery := fmt.Sprintf("CREATE VIEW {{%s}} AS SELECT * FROM (%s)", name, selectQuery)
|
||||
if _, err := txDao.DB().NewQuery(viewQuery).Execute(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -458,7 +458,7 @@ type identifiersParser struct {
|
||||
}
|
||||
|
||||
func (p *identifiersParser) parse(selectQuery string) error {
|
||||
str := strings.Trim(selectQuery, ";")
|
||||
str := strings.Trim(strings.TrimSpace(selectQuery), ";")
|
||||
str = joinReplaceRegex.ReplaceAllString(str, " _join_ ")
|
||||
str = discardReplaceRegex.ReplaceAllString(str, " _discard_ ")
|
||||
str = commentsReplaceRegex.ReplaceAllString(str, "")
|
||||
@@ -599,13 +599,20 @@ func identifierFromParts(parts []string) (identifier, error) {
|
||||
}
|
||||
|
||||
result.original = trimRawIdentifier(result.original)
|
||||
result.alias = trimRawIdentifier(result.alias)
|
||||
|
||||
// we trim the single quote even though it is not a valid column quote character
|
||||
// because SQLite allows it if the context expects an identifier and not string literal
|
||||
// (https://www.sqlite.org/lang_keywords.html)
|
||||
result.alias = trimRawIdentifier(result.alias, "'")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func trimRawIdentifier(rawIdentifier string) string {
|
||||
const trimChars = "`\"[];"
|
||||
func trimRawIdentifier(rawIdentifier string, extraTrimChars ...string) string {
|
||||
trimChars := "`\"[];"
|
||||
if len(extraTrimChars) > 0 {
|
||||
trimChars += strings.Join(extraTrimChars, "")
|
||||
}
|
||||
|
||||
parts := strings.Split(rawIdentifier, ".")
|
||||
|
||||
|
||||
+41
-40
@@ -147,34 +147,33 @@ func TestSaveView(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
err := app.Dao().SaveView(s.viewName, s.query)
|
||||
t.Run(s.scenarioName, func(t *testing.T) {
|
||||
err := app.Dao().SaveView(s.viewName, s.query)
|
||||
|
||||
hasErr := err != nil
|
||||
if hasErr != s.expectError {
|
||||
t.Errorf("[%s] Expected hasErr %v, got %v (%v)", s.scenarioName, s.expectError, hasErr, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if hasErr {
|
||||
continue
|
||||
}
|
||||
|
||||
infoRows, err := app.Dao().TableInfo(s.viewName)
|
||||
if err != nil {
|
||||
t.Errorf("[%s] Failed to fetch table info for %s: %v", s.scenarioName, s.viewName, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if len(s.expectColumns) != len(infoRows) {
|
||||
t.Errorf("[%s] Expected %d columns, got %d", s.scenarioName, len(s.expectColumns), len(infoRows))
|
||||
continue
|
||||
}
|
||||
|
||||
for _, row := range infoRows {
|
||||
if !list.ExistInSlice(row.Name, s.expectColumns) {
|
||||
t.Errorf("[%s] Missing %q column in %v", s.scenarioName, row.Name, s.expectColumns)
|
||||
hasErr := err != nil
|
||||
if hasErr != s.expectError {
|
||||
t.Fatalf("Expected hasErr %v, got %v (%v)", s.expectError, hasErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
if hasErr {
|
||||
return
|
||||
}
|
||||
|
||||
infoRows, err := app.Dao().TableInfo(s.viewName)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to fetch table info for %s: %v", s.viewName, err)
|
||||
}
|
||||
|
||||
if len(s.expectColumns) != len(infoRows) {
|
||||
t.Fatalf("Expected %d columns, got %d", len(s.expectColumns), len(infoRows))
|
||||
}
|
||||
|
||||
for _, row := range infoRows {
|
||||
if !list.ExistInSlice(row.Name, s.expectColumns) {
|
||||
t.Fatalf("Missing %q column in %v", row.Name, s.expectColumns)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ensureNoTempViews(app, t)
|
||||
@@ -272,24 +271,26 @@ func TestCreateViewSchema(t *testing.T) {
|
||||
"datetime",
|
||||
"json",
|
||||
"rel_one",
|
||||
"rel_many"
|
||||
"rel_many",
|
||||
'single_quoted_custom_literal' as 'single_quoted_column'
|
||||
from demo1
|
||||
`,
|
||||
false,
|
||||
map[string]string{
|
||||
"text": schema.FieldTypeText,
|
||||
"bool": schema.FieldTypeBool,
|
||||
"url": schema.FieldTypeUrl,
|
||||
"select_one": schema.FieldTypeSelect,
|
||||
"select_many": schema.FieldTypeSelect,
|
||||
"file_one": schema.FieldTypeFile,
|
||||
"file_many": schema.FieldTypeFile,
|
||||
"number_alias": schema.FieldTypeNumber,
|
||||
"email": schema.FieldTypeEmail,
|
||||
"datetime": schema.FieldTypeDate,
|
||||
"json": schema.FieldTypeJson,
|
||||
"rel_one": schema.FieldTypeRelation,
|
||||
"rel_many": schema.FieldTypeRelation,
|
||||
"text": schema.FieldTypeText,
|
||||
"bool": schema.FieldTypeBool,
|
||||
"url": schema.FieldTypeUrl,
|
||||
"select_one": schema.FieldTypeSelect,
|
||||
"select_many": schema.FieldTypeSelect,
|
||||
"file_one": schema.FieldTypeFile,
|
||||
"file_many": schema.FieldTypeFile,
|
||||
"number_alias": schema.FieldTypeNumber,
|
||||
"email": schema.FieldTypeEmail,
|
||||
"datetime": schema.FieldTypeDate,
|
||||
"json": schema.FieldTypeJson,
|
||||
"rel_one": schema.FieldTypeRelation,
|
||||
"rel_many": schema.FieldTypeRelation,
|
||||
"single_quoted_column": schema.FieldTypeJson,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ func main() {
|
||||
app.RootCmd.PersistentFlags().IntVar(
|
||||
&hooksPool,
|
||||
"hooksPool",
|
||||
50,
|
||||
25,
|
||||
"the total prewarm goja.Runtime instances for the JS app hooks execution",
|
||||
)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package forms
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
@@ -66,7 +67,7 @@ func (form *AdminPasswordResetRequest) Submit(interceptors ...InterceptorFunc[*m
|
||||
|
||||
admin, err := form.dao.FindAdminByEmail(form.Email)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("Failed to fetch admin with email %s: %w", form.Email, err)
|
||||
}
|
||||
|
||||
now := time.Now().UTC()
|
||||
@@ -75,14 +76,14 @@ func (form *AdminPasswordResetRequest) Submit(interceptors ...InterceptorFunc[*m
|
||||
return errors.New("You have already requested a password reset.")
|
||||
}
|
||||
|
||||
// update last sent timestamp
|
||||
admin.LastResetSentAt = types.NowDateTime()
|
||||
|
||||
return runInterceptors(admin, func(m *models.Admin) error {
|
||||
if err := mails.SendAdminPasswordReset(form.app, m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update last sent timestamp
|
||||
m.LastResetSentAt = types.NowDateTime()
|
||||
|
||||
return form.dao.SaveAdmin(m)
|
||||
}, interceptors...)
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func TestAdminPasswordResetRequestInterceptors(t *testing.T) {
|
||||
t.Fatalf("Expected interceptor2 to be called")
|
||||
}
|
||||
|
||||
if interceptorLastResetSentAt.String() == admin.LastResetSentAt.String() {
|
||||
t.Fatalf("Expected the form model to be filled before calling the interceptors")
|
||||
if interceptorLastResetSentAt.String() != admin.LastResetSentAt.String() {
|
||||
t.Fatalf("Expected the form model to NOT be filled before calling the interceptors")
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -38,7 +38,7 @@ func TestBackupCreateValidateAndSubmit(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
func() {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
@@ -56,47 +56,47 @@ func TestBackupCreateValidateAndSubmit(t *testing.T) {
|
||||
// parse errors
|
||||
errs, ok := result.(validation.Errors)
|
||||
if !ok && result != nil {
|
||||
t.Errorf("[%s] Failed to parse errors %v", s.name, result)
|
||||
t.Fatalf("Failed to parse errors %v", result)
|
||||
return
|
||||
}
|
||||
|
||||
// check errors
|
||||
if len(errs) > len(s.expectedErrors) {
|
||||
t.Errorf("[%s] Expected error keys %v, got %v", s.name, s.expectedErrors, errs)
|
||||
t.Fatalf("Expected error keys %v, got %v", s.expectedErrors, errs)
|
||||
}
|
||||
for _, k := range s.expectedErrors {
|
||||
if _, ok := errs[k]; !ok {
|
||||
t.Errorf("[%s] Missing expected error key %q in %v", s.name, k, errs)
|
||||
t.Fatalf("Missing expected error key %q in %v", k, errs)
|
||||
}
|
||||
}
|
||||
|
||||
// retrieve all created backup files
|
||||
files, err := fsys.List("")
|
||||
if err != nil {
|
||||
t.Errorf("[%s] Failed to retrieve backup files", s.name)
|
||||
t.Fatal("Failed to retrieve backup files")
|
||||
return
|
||||
}
|
||||
|
||||
if result != nil {
|
||||
if total := len(files); total != 0 {
|
||||
t.Errorf("[%s] Didn't expected backup files, found %d", s.name, total)
|
||||
t.Fatalf("Didn't expected backup files, found %d", total)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if total := len(files); total != 1 {
|
||||
t.Errorf("[%s] Expected 1 backup file, got %d", s.name, total)
|
||||
t.Fatalf("Expected 1 backup file, got %d", total)
|
||||
return
|
||||
}
|
||||
|
||||
if s.backupName == "" {
|
||||
prefix := "pb_backup_"
|
||||
if !strings.HasPrefix(files[0].Key, prefix) {
|
||||
t.Errorf("[%s] Expected the backup file, to have prefix %q: %q", s.name, prefix, files[0].Key)
|
||||
t.Fatalf("Expected the backup file, to have prefix %q: %q", prefix, files[0].Key)
|
||||
}
|
||||
} else if s.backupName != files[0].Key {
|
||||
t.Errorf("[%s] Expected backup file %q, got %q", s.name, s.backupName, files[0].Key)
|
||||
t.Fatalf("Expected backup file %q, got %q", s.backupName, files[0].Key)
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package forms
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/forms/validators"
|
||||
"github.com/pocketbase/pocketbase/tools/filesystem"
|
||||
)
|
||||
|
||||
// BackupUpload is a request form for uploading a new app backup.
|
||||
type BackupUpload struct {
|
||||
app core.App
|
||||
ctx context.Context
|
||||
|
||||
File *filesystem.File `json:"file"`
|
||||
}
|
||||
|
||||
// NewBackupUpload creates new BackupUpload request form.
|
||||
func NewBackupUpload(app core.App) *BackupUpload {
|
||||
return &BackupUpload{
|
||||
app: app,
|
||||
ctx: context.Background(),
|
||||
}
|
||||
}
|
||||
|
||||
// SetContext replaces the default form upload context with the provided one.
|
||||
func (form *BackupUpload) SetContext(ctx context.Context) {
|
||||
form.ctx = ctx
|
||||
}
|
||||
|
||||
// Validate makes the form validatable by implementing [validation.Validatable] interface.
|
||||
func (form *BackupUpload) Validate() error {
|
||||
return validation.ValidateStruct(form,
|
||||
validation.Field(
|
||||
&form.File,
|
||||
validation.Required,
|
||||
validation.By(validators.UploadedFileMimeType([]string{"application/zip"})),
|
||||
validation.By(form.checkUniqueName),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func (form *BackupUpload) checkUniqueName(value any) error {
|
||||
v, _ := value.(*filesystem.File)
|
||||
if v == nil {
|
||||
return nil // nothing to check
|
||||
}
|
||||
|
||||
fsys, err := form.app.NewBackupsFilesystem()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fsys.Close()
|
||||
|
||||
fsys.SetContext(form.ctx)
|
||||
|
||||
if exists, err := fsys.Exists(v.OriginalName); err != nil || exists {
|
||||
return validation.NewError("validation_backup_name_exists", "Backup file with the specified name already exists.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Submit validates the form and upload the backup file.
|
||||
//
|
||||
// You can optionally provide a list of InterceptorFunc to further
|
||||
// modify the form behavior before uploading the backup.
|
||||
func (form *BackupUpload) Submit(interceptors ...InterceptorFunc[*filesystem.File]) error {
|
||||
if err := form.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return runInterceptors(form.File, func(file *filesystem.File) error {
|
||||
fsys, err := form.app.NewBackupsFilesystem()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fsys.SetContext(form.ctx)
|
||||
|
||||
return fsys.UploadFile(file, file.OriginalName)
|
||||
}, interceptors...)
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package forms_test
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/pocketbase/pocketbase/forms"
|
||||
"github.com/pocketbase/pocketbase/tests"
|
||||
"github.com/pocketbase/pocketbase/tools/filesystem"
|
||||
)
|
||||
|
||||
func TestBackupUploadValidateAndSubmit(t *testing.T) {
|
||||
var zb bytes.Buffer
|
||||
zw := zip.NewWriter(&zb)
|
||||
if err := zw.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
f0, _ := filesystem.NewFileFromBytes([]byte("test"), "existing")
|
||||
f1, _ := filesystem.NewFileFromBytes([]byte("456"), "nozip")
|
||||
f2, _ := filesystem.NewFileFromBytes(zb.Bytes(), "existing")
|
||||
f3, _ := filesystem.NewFileFromBytes(zb.Bytes(), "zip")
|
||||
|
||||
scenarios := []struct {
|
||||
name string
|
||||
file *filesystem.File
|
||||
expectedErrors []string
|
||||
}{
|
||||
{
|
||||
"missing file",
|
||||
nil,
|
||||
[]string{"file"},
|
||||
},
|
||||
{
|
||||
"non-zip file",
|
||||
f1,
|
||||
[]string{"file"},
|
||||
},
|
||||
{
|
||||
"zip file with non-unique name",
|
||||
f2,
|
||||
[]string{"file"},
|
||||
},
|
||||
{
|
||||
"zip file with unique name",
|
||||
f3,
|
||||
[]string{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
fsys, err := app.NewBackupsFilesystem()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fsys.Close()
|
||||
// create a dummy backup file to simulate existing backups
|
||||
if err := fsys.UploadFile(f0, f0.OriginalName); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
form := forms.NewBackupUpload(app)
|
||||
form.File = s.file
|
||||
|
||||
result := form.Submit()
|
||||
|
||||
// parse errors
|
||||
errs, ok := result.(validation.Errors)
|
||||
if !ok && result != nil {
|
||||
t.Fatalf("Failed to parse errors %v", result)
|
||||
}
|
||||
|
||||
// check errors
|
||||
if len(errs) > len(s.expectedErrors) {
|
||||
t.Fatalf("Expected error keys %v, got %v", s.expectedErrors, errs)
|
||||
}
|
||||
for _, k := range s.expectedErrors {
|
||||
if _, ok := errs[k]; !ok {
|
||||
t.Fatalf("Missing expected error key %q in %v", k, errs)
|
||||
}
|
||||
}
|
||||
|
||||
expectedFiles := []*filesystem.File{f0}
|
||||
if result == nil {
|
||||
expectedFiles = append(expectedFiles, s.file)
|
||||
}
|
||||
|
||||
// retrieve all uploaded backup files
|
||||
files, err := fsys.List("")
|
||||
if err != nil {
|
||||
t.Fatal("Failed to retrieve backup files")
|
||||
}
|
||||
|
||||
if len(files) != len(expectedFiles) {
|
||||
t.Fatalf("Expected %d files, got %d", len(expectedFiles), len(files))
|
||||
}
|
||||
|
||||
for _, ef := range expectedFiles {
|
||||
exists := false
|
||||
for _, f := range files {
|
||||
if f.Key == ef.OriginalName {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
t.Fatalf("Missing expected backup file %v", ef.OriginalName)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -229,14 +229,6 @@ func (form *CollectionUpsert) ensureNoFieldsTypeChange(value any) error {
|
||||
func (form *CollectionUpsert) checkRelationFields(value any) error {
|
||||
v, _ := value.(schema.Schema)
|
||||
|
||||
systemDisplayFields := schema.BaseModelFieldNames()
|
||||
systemDisplayFields = append(systemDisplayFields,
|
||||
schema.FieldNameUsername,
|
||||
schema.FieldNameEmail,
|
||||
schema.FieldNameEmailVisibility,
|
||||
schema.FieldNameVerified,
|
||||
)
|
||||
|
||||
for i, field := range v.Fields() {
|
||||
if field.Type != schema.FieldTypeRelation {
|
||||
continue
|
||||
@@ -294,20 +286,6 @@ func (form *CollectionUpsert) checkRelationFields(value any) error {
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
// validate displayFields (if any)
|
||||
for _, name := range options.DisplayFields {
|
||||
if relCollection.Schema.GetFieldByName(name) == nil && !list.ExistInSlice(name, systemDisplayFields) {
|
||||
return validation.Errors{fmt.Sprint(i): validation.Errors{
|
||||
"options": validation.Errors{
|
||||
"displayFields": validation.NewError(
|
||||
"validation_field_invalid_relation_displayFields",
|
||||
fmt.Sprintf("%q does not exist in the related %q collection.", name, relCollection.Name),
|
||||
),
|
||||
}},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -171,25 +171,6 @@ func TestCollectionUpsertValidateAndSubmit(t *testing.T) {
|
||||
}`,
|
||||
[]string{"schema"},
|
||||
},
|
||||
{
|
||||
"create failure - missing relation display field",
|
||||
"",
|
||||
`{
|
||||
"name": "test_new",
|
||||
"type": "base",
|
||||
"schema": [
|
||||
{
|
||||
"name":"test",
|
||||
"type":"relation",
|
||||
"options":{
|
||||
"collectionId":"wsmn24bux7wo113",
|
||||
"displayFields":["text", "missing"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}`,
|
||||
[]string{"schema"},
|
||||
},
|
||||
{
|
||||
"create failure - check auth options validators",
|
||||
"",
|
||||
@@ -605,7 +586,7 @@ func TestCollectionUpsertValidateAndSubmit(t *testing.T) {
|
||||
}
|
||||
|
||||
if form.Name != collection.Name {
|
||||
t.Errorf("Expected Name %q, got %q", collection.Name, form.Name)
|
||||
t.Fatalf("Expected Name %q, got %q", collection.Name, form.Name)
|
||||
}
|
||||
|
||||
if form.Type != collection.Type {
|
||||
|
||||
@@ -2,6 +2,7 @@ package forms
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
@@ -69,7 +70,7 @@ func (form *RecordPasswordResetRequest) Submit(interceptors ...InterceptorFunc[*
|
||||
|
||||
authRecord, err := form.dao.FindAuthRecordByEmail(form.collection.Id, form.Email)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("Failed to fetch %s record with email %s: %w", form.collection.Id, form.Email, err)
|
||||
}
|
||||
|
||||
now := time.Now().UTC()
|
||||
@@ -78,14 +79,14 @@ func (form *RecordPasswordResetRequest) Submit(interceptors ...InterceptorFunc[*
|
||||
return errors.New("You've already requested a password reset.")
|
||||
}
|
||||
|
||||
// update last sent timestamp
|
||||
authRecord.Set(schema.FieldNameLastResetSentAt, types.NowDateTime())
|
||||
|
||||
return runInterceptors(authRecord, func(m *models.Record) error {
|
||||
if err := mails.SendRecordPasswordReset(form.app, m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update last sent timestamp
|
||||
m.Set(schema.FieldNameLastResetSentAt, types.NowDateTime())
|
||||
|
||||
return form.dao.SaveRecord(m)
|
||||
}, interceptors...)
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func TestRecordPasswordResetRequestInterceptors(t *testing.T) {
|
||||
t.Fatalf("Expected interceptor2 to be called")
|
||||
}
|
||||
|
||||
if interceptorLastResetSentAt.String() == authRecord.LastResetSentAt().String() {
|
||||
t.Fatalf("Expected the form model to be filled before calling the interceptors")
|
||||
if interceptorLastResetSentAt.String() != authRecord.LastResetSentAt().String() {
|
||||
t.Fatalf("Expected the form model to NOT be filled before calling the interceptors")
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -117,7 +117,7 @@ func (form *RecordUpsert) getContentType(r *http.Request) string {
|
||||
return t
|
||||
}
|
||||
|
||||
func (form *RecordUpsert) extractRequestInfo(
|
||||
func (form *RecordUpsert) extractRequestData(
|
||||
r *http.Request,
|
||||
keyPrefix string,
|
||||
) (map[string]any, map[string][]*filesystem.File, error) {
|
||||
@@ -219,12 +219,12 @@ func (form *RecordUpsert) extractMultipartFormData(
|
||||
//
|
||||
// File upload is supported only via multipart/form-data.
|
||||
func (form *RecordUpsert) LoadRequest(r *http.Request, keyPrefix string) error {
|
||||
requestInfo, uploadedFiles, err := form.extractRequestInfo(r, keyPrefix)
|
||||
requestData, uploadedFiles, err := form.extractRequestData(r, keyPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := form.LoadData(requestInfo); err != nil {
|
||||
if err := form.LoadData(requestData); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -349,39 +349,39 @@ func (form *RecordUpsert) RemoveFiles(key string, toDelete ...string) error {
|
||||
}
|
||||
|
||||
// LoadData loads and normalizes the provided regular record data fields into the form.
|
||||
func (form *RecordUpsert) LoadData(requestInfo map[string]any) error {
|
||||
func (form *RecordUpsert) LoadData(requestData map[string]any) error {
|
||||
// load base system fields
|
||||
if v, ok := requestInfo[schema.FieldNameId]; ok {
|
||||
if v, ok := requestData[schema.FieldNameId]; ok {
|
||||
form.Id = cast.ToString(v)
|
||||
}
|
||||
|
||||
// load auth system fields
|
||||
if form.record.Collection().IsAuth() {
|
||||
if v, ok := requestInfo[schema.FieldNameUsername]; ok {
|
||||
if v, ok := requestData[schema.FieldNameUsername]; ok {
|
||||
form.Username = cast.ToString(v)
|
||||
}
|
||||
if v, ok := requestInfo[schema.FieldNameEmail]; ok {
|
||||
if v, ok := requestData[schema.FieldNameEmail]; ok {
|
||||
form.Email = cast.ToString(v)
|
||||
}
|
||||
if v, ok := requestInfo[schema.FieldNameEmailVisibility]; ok {
|
||||
if v, ok := requestData[schema.FieldNameEmailVisibility]; ok {
|
||||
form.EmailVisibility = cast.ToBool(v)
|
||||
}
|
||||
if v, ok := requestInfo[schema.FieldNameVerified]; ok {
|
||||
if v, ok := requestData[schema.FieldNameVerified]; ok {
|
||||
form.Verified = cast.ToBool(v)
|
||||
}
|
||||
if v, ok := requestInfo["password"]; ok {
|
||||
if v, ok := requestData["password"]; ok {
|
||||
form.Password = cast.ToString(v)
|
||||
}
|
||||
if v, ok := requestInfo["passwordConfirm"]; ok {
|
||||
if v, ok := requestData["passwordConfirm"]; ok {
|
||||
form.PasswordConfirm = cast.ToString(v)
|
||||
}
|
||||
if v, ok := requestInfo["oldPassword"]; ok {
|
||||
if v, ok := requestData["oldPassword"]; ok {
|
||||
form.OldPassword = cast.ToString(v)
|
||||
}
|
||||
}
|
||||
|
||||
// replace modifiers (if any)
|
||||
requestInfo = form.record.ReplaceModifers(requestInfo)
|
||||
requestData = form.record.ReplaceModifers(requestData)
|
||||
|
||||
// create a shallow copy of form.data
|
||||
var extendedData = make(map[string]any, len(form.data))
|
||||
@@ -390,7 +390,7 @@ func (form *RecordUpsert) LoadData(requestInfo map[string]any) error {
|
||||
}
|
||||
|
||||
// extend form.data with the request data
|
||||
rawData, err := json.Marshal(requestInfo)
|
||||
rawData, err := json.Marshal(requestData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -82,9 +82,6 @@ func (form *RecordVerificationRequest) Submit(interceptors ...InterceptorFunc[*m
|
||||
if (now.Sub(lastVerificationSentAt)).Seconds() < form.resendThreshold {
|
||||
return errors.New("A verification email was already sent.")
|
||||
}
|
||||
|
||||
// update last sent timestamp
|
||||
record.SetLastVerificationSentAt(types.NowDateTime())
|
||||
}
|
||||
|
||||
return runInterceptors(record, func(m *models.Record) error {
|
||||
@@ -96,6 +93,9 @@ func (form *RecordVerificationRequest) Submit(interceptors ...InterceptorFunc[*m
|
||||
return err
|
||||
}
|
||||
|
||||
// update last sent timestamp
|
||||
m.SetLastVerificationSentAt(types.NowDateTime())
|
||||
|
||||
return form.dao.SaveRecord(m)
|
||||
}, interceptors...)
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ func TestRecordVerificationRequestInterceptors(t *testing.T) {
|
||||
t.Fatalf("Expected interceptor2 to be called")
|
||||
}
|
||||
|
||||
if interceptorLastVerificationSentAt.String() == authRecord.LastVerificationSentAt().String() {
|
||||
t.Fatalf("Expected the form model to be filled before calling the interceptors")
|
||||
if interceptorLastVerificationSentAt.String() != authRecord.LastVerificationSentAt().String() {
|
||||
t.Fatalf("Expected the form model to NOT be filled before calling the interceptors")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +158,10 @@ func (validator *RecordDataValidator) checkNumberValue(field *schema.SchemaField
|
||||
|
||||
options, _ := field.Options.(*schema.NumberOptions)
|
||||
|
||||
if options.NoDecimal && val != float64(int64(val)) {
|
||||
return validation.NewError("validation_no_decimal_constraint", "Decimal numbers are not allowed")
|
||||
}
|
||||
|
||||
if options.Min != nil && val < *options.Min {
|
||||
return validation.NewError("validation_min_number_constraint", fmt.Sprintf("Must be larger than %f", *options.Min))
|
||||
}
|
||||
|
||||
@@ -180,6 +180,13 @@ func TestRecordDataValidatorValidateNumber(t *testing.T) {
|
||||
Max: &max,
|
||||
},
|
||||
},
|
||||
&schema.SchemaField{
|
||||
Name: "field4",
|
||||
Type: schema.FieldTypeNumber,
|
||||
Options: &schema.NumberOptions{
|
||||
NoDecimal: true,
|
||||
},
|
||||
},
|
||||
)
|
||||
if err := app.Dao().SaveCollection(collection); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -201,6 +208,7 @@ func TestRecordDataValidatorValidateNumber(t *testing.T) {
|
||||
"field1": nil,
|
||||
"field2": nil,
|
||||
"field3": nil,
|
||||
"field4": nil,
|
||||
},
|
||||
nil,
|
||||
[]string{"field2"},
|
||||
@@ -211,6 +219,7 @@ func TestRecordDataValidatorValidateNumber(t *testing.T) {
|
||||
"field1": "invalid",
|
||||
"field2": "invalid",
|
||||
"field3": "invalid",
|
||||
"field4": "invalid",
|
||||
},
|
||||
nil,
|
||||
[]string{"field2"},
|
||||
@@ -244,6 +253,15 @@ func TestRecordDataValidatorValidateNumber(t *testing.T) {
|
||||
nil,
|
||||
[]string{"field3"},
|
||||
},
|
||||
{
|
||||
"(number) check NoDecimal",
|
||||
map[string]any{
|
||||
"field2": 1,
|
||||
"field4": 456.789,
|
||||
},
|
||||
nil,
|
||||
[]string{"field4"},
|
||||
},
|
||||
{
|
||||
"(number) valid data (only required)",
|
||||
map[string]any{
|
||||
@@ -258,6 +276,7 @@ func TestRecordDataValidatorValidateNumber(t *testing.T) {
|
||||
"field1": nil,
|
||||
"field2": 123, // test value cast
|
||||
"field3": max,
|
||||
"field4": 456,
|
||||
},
|
||||
nil,
|
||||
[]string{},
|
||||
|
||||
@@ -1,95 +1,96 @@
|
||||
module github.com/pocketbase/pocketbase
|
||||
|
||||
go 1.18
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/AlecAivazis/survey/v2 v2.3.7
|
||||
github.com/aws/aws-sdk-go v1.44.318
|
||||
github.com/aws/aws-sdk-go v1.46.6
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/domodwyer/mailyak/v3 v3.6.2
|
||||
github.com/dop251/goja v0.0.0-20230707174833-636fdf960de1
|
||||
github.com/dop251/goja_nodejs v0.0.0-20230821135201-94e508132562
|
||||
github.com/dop251/goja v0.0.0-20230919151941-fc55792775de
|
||||
github.com/dop251/goja_nodejs v0.0.0-20230914102007-198ba9a8b098
|
||||
github.com/fatih/color v1.15.0
|
||||
github.com/fsnotify/fsnotify v1.6.0
|
||||
github.com/gabriel-vasile/mimetype v1.4.2
|
||||
github.com/gabriel-vasile/mimetype v1.4.3
|
||||
github.com/ganigeorgiev/fexpr v0.3.0
|
||||
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
|
||||
github.com/goccy/go-json v0.10.2
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0
|
||||
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61
|
||||
github.com/mattn/go-sqlite3 v1.14.17
|
||||
github.com/pocketbase/dbx v1.10.1
|
||||
github.com/pocketbase/tygoja v0.0.0-20230618203136-2f8d57768be1
|
||||
github.com/pocketbase/tygoja v0.0.0-20231028133025-25a94364de58
|
||||
github.com/spf13/cast v1.5.1
|
||||
github.com/spf13/cobra v1.7.0
|
||||
gocloud.dev v0.32.0
|
||||
golang.org/x/crypto v0.12.0
|
||||
golang.org/x/net v0.14.0
|
||||
golang.org/x/oauth2 v0.11.0
|
||||
golang.org/x/sync v0.3.0
|
||||
modernc.org/sqlite v1.25.0
|
||||
gocloud.dev v0.34.0
|
||||
golang.org/x/crypto v0.14.0
|
||||
golang.org/x/net v0.17.0
|
||||
golang.org/x/oauth2 v0.13.0
|
||||
golang.org/x/sync v0.4.0
|
||||
modernc.org/sqlite v1.26.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2 v1.20.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.12 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/config v1.18.33 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.13.32 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.8 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.77 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.38 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.32 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.39 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.13 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.33 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.32 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.13.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.21.2 // indirect
|
||||
github.com/aws/smithy-go v1.14.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2 v1.21.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/config v1.19.1 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.13.43 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.92 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.38 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.6 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 // indirect
|
||||
github.com/aws/smithy-go v1.15.0 // indirect
|
||||
github.com/dlclark/regexp2 v1.10.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/google/pprof v0.0.0-20230912144702-c363fe2c2ed8 // indirect
|
||||
github.com/google/uuid v1.4.0 // indirect
|
||||
github.com/google/wire v0.5.0 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
golang.org/x/image v0.11.0 // indirect
|
||||
golang.org/x/mod v0.12.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
golang.org/x/term v0.11.0 // indirect
|
||||
golang.org/x/text v0.12.0 // indirect
|
||||
golang.org/x/image v0.13.0 // indirect
|
||||
golang.org/x/mod v0.13.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
golang.org/x/term v0.13.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
golang.org/x/tools v0.12.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||
google.golang.org/api v0.135.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect
|
||||
google.golang.org/grpc v1.57.0 // indirect
|
||||
golang.org/x/tools v0.14.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
|
||||
google.golang.org/api v0.148.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
|
||||
google.golang.org/grpc v1.59.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
lukechampine.com/uint128 v1.3.0 // indirect
|
||||
modernc.org/cc/v3 v3.41.0 // indirect
|
||||
modernc.org/ccgo/v3 v3.16.14 // indirect
|
||||
modernc.org/libc v1.24.1 // indirect
|
||||
modernc.org/ccgo/v3 v3.16.15 // indirect
|
||||
modernc.org/libc v1.28.0 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.6.0 // indirect
|
||||
modernc.org/memory v1.7.2 // indirect
|
||||
modernc.org/opt v0.1.3 // indirect
|
||||
modernc.org/strutil v1.1.3 // indirect
|
||||
modernc.org/strutil v1.2.0 // indirect
|
||||
modernc.org/token v1.1.0 // indirect
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.110.6 h1:8uYAkj3YHTP/1iwReuHPxLSbdcyc+dSBbzFMrVwDR6Q=
|
||||
cloud.google.com/go/compute v1.22.0 h1:cB8R6FtUtT1TYGl5R3xuxnW6OUIc/DrT2aiR16TTG7Y=
|
||||
cloud.google.com/go v0.110.7 h1:rJyC7nWRg2jWGZ4wSJ5nY65GTdYJkg0cd/uXb+ACI6o=
|
||||
cloud.google.com/go/compute v1.23.0 h1:tP41Zoavr8ptEqaW6j+LQOnyBBhO7OkOMAGrgLopTwY=
|
||||
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
|
||||
cloud.google.com/go/iam v1.1.1 h1:lW7fzj15aVIXYHREOqjRBV9PsH0Z6u8Y46a1YGvQP4Y=
|
||||
cloud.google.com/go/storage v1.31.0 h1:+S3LjjEN2zZ+L5hOwj4+1OkGCsLVe0NzpXKQ1pSdTCI=
|
||||
@@ -12,46 +12,52 @@ github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDe
|
||||
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg=
|
||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
|
||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
|
||||
github.com/aws/aws-sdk-go v1.44.318 h1:Yl66rpbQHFUbxe9JBKLcvOvRivhVgP6+zH0b9KzARX8=
|
||||
github.com/aws/aws-sdk-go v1.44.318/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
|
||||
github.com/aws/aws-sdk-go-v2 v1.20.1 h1:rZBf5DWr7YGrnlTK4kgDQGn1ltqOg5orCYb/UhOFZkg=
|
||||
github.com/aws/aws-sdk-go-v2 v1.20.1/go.mod h1:NU06lETsFm8fUC6ZjhgDpVBcGZTFQ6XM+LZWZxMI4ac=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.12 h1:lN6L3LrYHeZ6xCxaIYtoWCx4GMLk4nRknsh29OMSqHY=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.12/go.mod h1:TDCkEAkMTXxTs0oLBGBKpBZbk3NLh8EvAfF0Q3x8/0c=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.18.33 h1:JKcw5SFxFW/rpM4mOPjv0VQ11E2kxW13F3exWOy7VZU=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.18.33/go.mod h1:hXO/l9pgY3K5oZJldamP0pbZHdPqqk+4/maa7DSD3cA=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.13.32 h1:lIH1eKPcCY1ylR4B6PkBGRWMHO3aVenOKJHWiS4/G2w=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.13.32/go.mod h1:lL8U3v/Y79YRG69WlAho0OHIKUXCyFvSXaIvfo81sls=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.8 h1:DK/9C+UN/X+1+Wm8pqaDksQr2tSLzq+8X1/rI/ZxKEQ=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.8/go.mod h1:ce7BgLQfYr5hQFdy67oX2svto3ufGtm6oBvmsHScI1Q=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.77 h1:oWSNL9oQy+do911sXpJyIc2J7RiUrbm9BecyaGy1wHo=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.77/go.mod h1:xvOdc97VpScJqB10YAI8r/cKuU7d9Ls/as03KROO2qY=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.38 h1:c8ed/T9T2K5I+h/JzmF5tpI46+OODQ74dzmdo+QnaMg=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.38/go.mod h1:qggunOChCMu9ZF/UkAfhTz25+U2rLVb3ya0Ua6TTfCA=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.32 h1:hNeAAymUY5gu11WrrmFb3CVIp9Dar9hbo44yzzcQpzA=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.32/go.mod h1:0ZXSqrty4FtQ7p8TEuRde/SZm9X05KT18LAUlR40Ln0=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.39 h1:fc0ukRAiP1syoSGZYu+DaE+FulSYhTiJ8WpVu5jElU4=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.39/go.mod h1:WLAW8PT7+JhjZfLSWe7WEJaJu0GNo0cKc2Zyo003RBs=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.1 h1:vUh7dBFNS3oFCtVv6CiYKh5hP9ls8+kIpKLeFruIBLk=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.1/go.mod h1:sFMeinkhj/SZKQM8BxtvNtSPjJEo0Xrz+w3g2e4FSKI=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.13 h1:iV/W5OMBys+66OeXJi/7xIRrKZNsu0ylsLGu+6nbmQE=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.13/go.mod h1:ReJb6xYmtGyu9KoFtRreWegbN9dZqvZIIv4vWnhcsyI=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.33 h1:QviNkc+vGSuEHx8P+pVNKOdWLXBPIwMFv7p0fphgE4U=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.33/go.mod h1:fABTUmOrAgAalG2i9WJpjBvlnk7UK8YmnYaxN+Q2CwE=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.32 h1:dGAseBFEYxth10V23b5e2mAS+tX7oVbfYHD6dnDdAsg=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.32/go.mod h1:4jwAWKEkCR0anWk5+1RbfSg1R5Gzld7NLiuaq5bTR/Y=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.1 h1:PT6PBCycRwhpEW5hJnRiceCeoWJ+r3bdgXtV+VKG7Pk=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.1/go.mod h1:TqoxCLwT2nrxrBGA+z7t6OWM7LBkgRckK3gOjYE+7JA=
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.2 h1:v346f1h8sUBKXnEbrv43L37MTBlFHyKXQPIZHNAaghA=
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.2/go.mod h1:cwCATiyNrXK9P2FsWdZ89g9mpsYv2rhk0UA/KByl5fY=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.13.2 h1:A2RlEMo4SJSwbNoUUgkxTAEMduAy/8wG3eB2b2lP4gY=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.13.2/go.mod h1:ju+nNXUunfIFamXUIZQiICjnO/TPlOmWcYhZcSy7xaE=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.2 h1:OJELEgyaT2kmaBGZ+myyZbTTLobfe3ox3FSh5eYK9Qs=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.2/go.mod h1:ubDBBaDFs1GHijSOTi8ljppML15GLG0HxhILtbjNNYQ=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.21.2 h1:ympg1+Lnq33XLhcK/xTG4yZHPs1Oyxu+6DEWbl7qOzA=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.21.2/go.mod h1:FQ/DQcOfESELfJi5ED+IPPAjI5xC6nxtSolVVB773jM=
|
||||
github.com/aws/smithy-go v1.14.1 h1:EFKMUmH/iHMqLiwoEDx2rRjRQpI1YCn5jTysoaDujFs=
|
||||
github.com/aws/smithy-go v1.14.1/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
|
||||
github.com/aws/aws-sdk-go v1.45.25 h1:c4fLlh5sLdK2DCRTY1z0hyuJZU4ygxX8m1FswL6/nF4=
|
||||
github.com/aws/aws-sdk-go v1.45.25/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
|
||||
github.com/aws/aws-sdk-go v1.46.6 h1:6wFnNC9hETIZLMf6SOTN7IcclrOGwp/n9SLp8Pjt6E8=
|
||||
github.com/aws/aws-sdk-go v1.46.6/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
|
||||
github.com/aws/aws-sdk-go-v2 v1.21.2 h1:+LXZ0sgo8quN9UOKXXzAWRT3FWd4NxeXWOZom9pE7GA=
|
||||
github.com/aws/aws-sdk-go-v2 v1.21.2/go.mod h1:ErQhvNuEMhJjweavOYhxVkn2RUx7kQXVATHrjKtxIpM=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 h1:Sc82v7tDQ/vdU1WtuSyzZ1I7y/68j//HJ6uozND1IDs=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14/go.mod h1:9NCTOURS8OpxvoAVHq79LK81/zC78hfRWFn+aL0SPcY=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.18.45 h1:Aka9bI7n8ysuwPeFdm77nfbyHCAKQ3z9ghB3S/38zes=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.18.45/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.90 h1:mtJRt80k1oGw7QQPluAx8AZ6u16MyCA2di/lMhagZ7I=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.90/go.mod h1:lYwZTkeMQWPvNU+u7oYArdNhQ8EKiSGU76jVv0w2GH4=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.92 h1:nLA7dGFC6v4P6b+hzqt5GqIGmIuN+jTJzojfdOLXWFE=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.92/go.mod h1:h+ei9z19AhoN+Dac92DwkzfbJ4mFUea92xgl5pKSG0Q=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 h1:nFBQlGtkbPzp/NjZLuFxRqmT91rLJkgvsEQs68h962Y=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43/go.mod h1:auo+PiyLl0n1l8A0e8RIeR8tOzYPfZZH/JNlrJ8igTQ=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 h1:JRVhO25+r3ar2mKGP7E0LDl8K9/G36gjlqca5iQbaqc=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37/go.mod h1:Qe+2KtKml+FEsQF/DHmDV+xjtche/hwoF75EG4UlHW8=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6 h1:wmGLw2i8ZTlHLw7a9ULGfQbuccw8uIiNr6sol5bFzc8=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6/go.mod h1:Q0Hq2X/NuL7z8b1Dww8rmOFl+jzusKEcyvkKspwdpyc=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 h1:7R8uRYyXzdD71KWVCL78lJZltah6VVznXBazvKjfH58=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15/go.mod h1:26SQUPcTNgV1Tapwdt4a1rOsYRsnBsJHLMPoxK2b0d8=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.38 h1:skaFGzv+3kA+v2BPKhuekeb1Hbb105+44r8ASC+q5SE=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.38/go.mod h1:epIZoRSSbRIwLPJU5F+OldHhwZPBdpDeQkRdCeY3+00=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.6 h1:9ulSU5ClouoPIYhDQdg9tpl83d5Yb91PXTKK+17q+ow=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.6/go.mod h1:lnc2taBsR9nTlz9meD+lhFZZ9EWY712QHrRflWpTcOA=
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2 h1:Ll5/YVCOzRB+gxPqs2uD0R7/MyATC0w85626glSKmp4=
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2/go.mod h1:Zjfqt7KhQK+PO1bbOsFNzKgaq7TcxzmEoDWN8lM0qzQ=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ=
|
||||
github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8=
|
||||
github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
|
||||
github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic=
|
||||
@@ -74,15 +80,13 @@ github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cn
|
||||
github.com/domodwyer/mailyak/v3 v3.6.2 h1:x3tGMsyFhTCaxp6ycgR0FE/bu5QiNp+hetUuCOBXMn8=
|
||||
github.com/domodwyer/mailyak/v3 v3.6.2/go.mod h1:lOm/u9CyCVWHeaAmHIdF4RiKVxKUT/H5XX10lIKAL6c=
|
||||
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
|
||||
github.com/dop251/goja v0.0.0-20230531210528-d7324b2d74f7/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4=
|
||||
github.com/dop251/goja v0.0.0-20230707174833-636fdf960de1 h1:sC/DYk3eEi5cKkpJX1vl+CpAM138dmuW7rutje9Eo4E=
|
||||
github.com/dop251/goja v0.0.0-20230707174833-636fdf960de1/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4=
|
||||
github.com/dop251/goja v0.0.0-20230626124041-ba8a63e79201/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4=
|
||||
github.com/dop251/goja v0.0.0-20230919151941-fc55792775de h1:lA38Xtzr1Wo+iQdkN2E11ziKXJYRxLlzK/e2/fdxoEI=
|
||||
github.com/dop251/goja v0.0.0-20230919151941-fc55792775de/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4=
|
||||
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
|
||||
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
|
||||
github.com/dop251/goja_nodejs v0.0.0-20230731184339-9ba67d720a81 h1:1e6KLyFnVS5BAENTnqll6IezpFqTDAmIsL0hkjBuMcY=
|
||||
github.com/dop251/goja_nodejs v0.0.0-20230731184339-9ba67d720a81/go.mod h1:X2TOTJ+Uamd454RFp7ig2tmP3hQg0Z2Qk8gbVQmU0mk=
|
||||
github.com/dop251/goja_nodejs v0.0.0-20230821135201-94e508132562 h1:ObbB2tzHWWAxzsG5futqeq2Ual2zYlo/+eMkSc5sn8w=
|
||||
github.com/dop251/goja_nodejs v0.0.0-20230821135201-94e508132562/go.mod h1:X2TOTJ+Uamd454RFp7ig2tmP3hQg0Z2Qk8gbVQmU0mk=
|
||||
github.com/dop251/goja_nodejs v0.0.0-20230914102007-198ba9a8b098 h1:MdrnfFPrfMfxiwnoJU2vnJ9ucskslblk7UhNWZTO2Qo=
|
||||
github.com/dop251/goja_nodejs v0.0.0-20230914102007-198ba9a8b098/go.mod h1:phKgRwmVpHQiW0mh9HNXILv/e2MfH7kqAnDANHnpXdU=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
@@ -94,8 +98,8 @@ github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBD
|
||||
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/ganigeorgiev/fexpr v0.3.0 h1:RwSyJBME+g/XdzlUW0paH/4VXhLHPg+rErtLeC7K8Ew=
|
||||
github.com/ganigeorgiev/fexpr v0.3.0/go.mod h1:RyGiGqmeXhEQ6+mlGdnUleLHgtzzu/VGO2WtJkF5drE=
|
||||
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead57VkAEY4V+Es=
|
||||
@@ -104,6 +108,8 @@ github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyL
|
||||
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
|
||||
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
@@ -122,6 +128,7 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
@@ -133,20 +140,23 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-replayers/grpcreplay v1.1.0 h1:S5+I3zYyZ+GQz68OfbURDdt/+cSMqCK1wrvNx7WBzTE=
|
||||
github.com/google/go-replayers/httpreplay v1.2.0 h1:VM1wEyyjaoU53BwrOnaf9VhAyQQEEioJvFYxYcLRKzk=
|
||||
github.com/google/martian/v3 v3.3.2 h1:IqNFLAmvJOgVlpdEBiQbDc2EwKW77amAycfTuWKdfvw=
|
||||
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
|
||||
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 h1:n6vlPhxsA+BW/XsS5+uqi7GyzaLa5MH7qlSLBZtRdiA=
|
||||
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA=
|
||||
github.com/google/s2a-go v0.1.4 h1:1kZ/sQM3srePvKs3tXAvQzo66XfcReoqFpIpIccE7Oc=
|
||||
github.com/google/pprof v0.0.0-20230912144702-c363fe2c2ed8 h1:gpptm606MZYGaMHMsB4Srmb6EbW/IVHnt04rcMXnkBQ=
|
||||
github.com/google/pprof v0.0.0-20230912144702-c363fe2c2ed8/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
|
||||
github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o=
|
||||
github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
|
||||
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/wire v0.5.0 h1:I7ELFeVBr3yfPIcc8+MWvrjk+3VjbcSzoXm3JVa+jD8=
|
||||
github.com/google/wire v0.5.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1EoU=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.2.5 h1:UR4rDjcgpgEnqpIEvkiqTYKBCKLNmlge2eVjoZfySzM=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.1 h1:SBWmZhjUDRorQxrN0nwzf+AHBxnbFjViHQS4P0yVpmQ=
|
||||
github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56etFpas=
|
||||
github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU=
|
||||
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
|
||||
@@ -177,6 +187,8 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
|
||||
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
@@ -185,12 +197,14 @@ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyex
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pocketbase/dbx v1.10.0 h1:58VIT7r6T+BnVbYVosvGBsPjQEic3/VFRYGT823vWSQ=
|
||||
github.com/pocketbase/dbx v1.10.0/go.mod h1:xXRCIAKTHMgUCyCKZm55pUOdvFziJjQfXaWKhu2vhMs=
|
||||
github.com/pocketbase/dbx v1.10.1 h1:cw+vsyfCJD8YObOVeqb93YErnlxwYMkNZ4rwN0G0AaA=
|
||||
github.com/pocketbase/dbx v1.10.1/go.mod h1:xXRCIAKTHMgUCyCKZm55pUOdvFziJjQfXaWKhu2vhMs=
|
||||
github.com/pocketbase/tygoja v0.0.0-20230618203136-2f8d57768be1 h1:0FQXnhUhBeF/z6UDj9Zm8GQHFHJSUtqLr1h4/YXf3vc=
|
||||
github.com/pocketbase/tygoja v0.0.0-20230618203136-2f8d57768be1/go.mod h1:dOJ+pCyqm/jRn5kO/TX598J0e5xGDcJAZerK5atCrKI=
|
||||
github.com/pocketbase/tygoja v0.0.0-20231014201019-43707ad269de h1:7Zg82unjBJq9/pUKf206UWzoGvjtaPwDXlqIAoYMG/U=
|
||||
github.com/pocketbase/tygoja v0.0.0-20231014201019-43707ad269de/go.mod h1:dOJ+pCyqm/jRn5kO/TX598J0e5xGDcJAZerK5atCrKI=
|
||||
github.com/pocketbase/tygoja v0.0.0-20231028131333-2278fd471632 h1:5R+G0Gy05vPxuOVP9Q7Oy4rSIyfcQG5B5FPosnfOTN0=
|
||||
github.com/pocketbase/tygoja v0.0.0-20231028131333-2278fd471632/go.mod h1:dOJ+pCyqm/jRn5kO/TX598J0e5xGDcJAZerK5atCrKI=
|
||||
github.com/pocketbase/tygoja v0.0.0-20231028133025-25a94364de58 h1:1Hu0uwRZrgpQchMEMXz+ZAJxV5l+o06L00svTqeP2RQ=
|
||||
github.com/pocketbase/tygoja v0.0.0-20231028133025-25a94364de58/go.mod h1:dOJ+pCyqm/jRn5kO/TX598J0e5xGDcJAZerK5atCrKI=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
@@ -219,24 +233,24 @@ github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||
gocloud.dev v0.32.0 h1:jHf8WSkByuAuXcvFt04OiiQH+N0zaRtxI6iEph8Bq8Y=
|
||||
gocloud.dev v0.32.0/go.mod h1:m/x/N9cRjDF5MD0i5TLFbKbqkGffl/qayXA9FcMT5Oc=
|
||||
gocloud.dev v0.34.0 h1:LzlQY+4l2cMtuNfwT2ht4+fiXwWf/NmPTnXUlLmGif4=
|
||||
gocloud.dev v0.34.0/go.mod h1:psKOachbnvY3DAOPbsFVmLIErwsbWPUG2H5i65D38vE=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
|
||||
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
|
||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo=
|
||||
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
|
||||
golang.org/x/image v0.13.0 h1:3cge/F/QTkNLauhf2QoE9zp+7sr+ZcL4HnoZmdwg9sg=
|
||||
golang.org/x/image v0.13.0/go.mod h1:6mmbMOeV28HuMTgA6OSRkdXKYw/t5W9Uwn2Yv1r3Yxk=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
|
||||
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@@ -250,18 +264,18 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
|
||||
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
|
||||
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU=
|
||||
golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk=
|
||||
golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY=
|
||||
golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
|
||||
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -278,15 +292,15 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
|
||||
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
|
||||
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
|
||||
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
@@ -296,8 +310,8 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
|
||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@@ -309,33 +323,39 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
|
||||
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
|
||||
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
|
||||
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
|
||||
google.golang.org/api v0.135.0 h1:6Vgfj6uPMXcyy66waYWBwmkeNB+9GmUlJDOzkukPQYQ=
|
||||
google.golang.org/api v0.135.0/go.mod h1:Bp77uRFgwsSKI0BWH573F5Q6wSlznwI2NFayLOp/7mQ=
|
||||
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
|
||||
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
|
||||
google.golang.org/api v0.147.0 h1:Can3FaQo9LlVqxJCodNmeZW/ib3/qKAY3rFeXiHo5gc=
|
||||
google.golang.org/api v0.147.0/go.mod h1:pQ/9j83DcmPd/5C9e2nFOdjjNkDZ1G+zkbK2uvdkJMs=
|
||||
google.golang.org/api v0.148.0 h1:HBq4TZlN4/1pNcu0geJZ/Q50vIwIXT532UIMYoo0vOs=
|
||||
google.golang.org/api v0.148.0/go.mod h1:8/TBgwaKjfqTdacOJrOv2+2Q6fBDU1uHKK06oGSkxzU=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
|
||||
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20230717213848-3f92550aa753 h1:lCbbUxUDD+DiXx9Q6F/ttL0aAu7N2pz8XnmMm8ZW4NE=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 h1:wukfNtZmZUurLN/atp2hiIeTKn7QJWIQdHzqmsOnAOk=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
|
||||
google.golang.org/genproto v0.0.0-20231002182017-d307bd883b97 h1:SeZZZx0cP0fqUyA+oRzP9k7cSwJlvDFiROO72uwD6i0=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 h1:W18sezcAYs+3tDZX4F80yctqa12jcP1PUS2gQu1zTPU=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a h1:a2MQQVoTo96JC9PMGtGBymLp7+/RzpFc2yX/9WfFg1c=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a/go.mod h1:4cYg8o5yUbm77w8ZX00LhMVNl/YVBFJRYWDc0uYWMs0=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
|
||||
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
|
||||
google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ=
|
||||
google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
|
||||
google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
|
||||
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
@@ -366,22 +386,24 @@ lukechampine.com/uint128 v1.3.0 h1:cDdUVfRwDUDovz610ABgFD17nXD4/uDgVHl2sC3+sbo=
|
||||
lukechampine.com/uint128 v1.3.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
||||
modernc.org/cc/v3 v3.41.0 h1:QoR1Sn3YWlmA1T4vLaKZfawdVtSiGx8H+cEojbC7v1Q=
|
||||
modernc.org/cc/v3 v3.41.0/go.mod h1:Ni4zjJYJ04CDOhG7dn640WGfwBzfE0ecX8TyMB0Fv0Y=
|
||||
modernc.org/ccgo/v3 v3.16.14 h1:af6KNtFgsVmnDYrWk3PQCS9XT6BXe7o3ZFJKkIKvXNQ=
|
||||
modernc.org/ccgo/v3 v3.16.14/go.mod h1:mPDSujUIaTNWQSG4eqKw+atqLOEbma6Ncsa94WbC9zo=
|
||||
modernc.org/ccgo/v3 v3.16.15 h1:KbDR3ZAVU+wiLyMESPtbtE/Add4elztFyfsWoNTgxS0=
|
||||
modernc.org/ccgo/v3 v3.16.15/go.mod h1:yT7B+/E2m43tmMOT51GMoM98/MtHIcQQSleGnddkUNI=
|
||||
modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
|
||||
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
|
||||
modernc.org/libc v1.24.1 h1:uvJSeCKL/AgzBo2yYIPPTy82v21KgGnizcGYfBHaNuM=
|
||||
modernc.org/libc v1.24.1/go.mod h1:FmfO1RLrU3MHJfyi9eYYmZBfi/R+tqZ6+hQ3yQQUkak=
|
||||
modernc.org/libc v1.28.0 h1:kHB6LtDBV8DEAK7aZT1vWvP92abW9fb8cjb1P9UTpUE=
|
||||
modernc.org/libc v1.28.0/go.mod h1:DaG/4Q3LRRdqpiLyP0C2m1B8ZMGkQ+cCgOIjEtQlYhQ=
|
||||
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
|
||||
modernc.org/memory v1.6.0 h1:i6mzavxrE9a30whzMfwf7XWVODx2r5OYXvU46cirX7o=
|
||||
modernc.org/memory v1.6.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
|
||||
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
|
||||
modernc.org/memory v1.7.2/go.mod h1:NO4NVCQy0N7ln+T9ngWqOQfi7ley4vpwvARR+Hjw95E=
|
||||
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
|
||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/sqlite v1.25.0 h1:AFweiwPNd/b3BoKnBOfFm+Y260guGMF+0UFk0savqeA=
|
||||
modernc.org/sqlite v1.25.0/go.mod h1:FL3pVXie73rg3Rii6V/u5BoHlSoyeZeIgKZEgHARyCU=
|
||||
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
|
||||
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
|
||||
modernc.org/sqlite v1.26.0 h1:SocQdLRSYlA8W99V8YH0NES75thx19d9sB/aFc4R8Lw=
|
||||
modernc.org/sqlite v1.26.0/go.mod h1:FL3pVXie73rg3Rii6V/u5BoHlSoyeZeIgKZEgHARyCU=
|
||||
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
|
||||
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
|
||||
modernc.org/tcl v1.15.2 h1:C4ybAYCGJw968e+Me18oW55kD/FexcHbqH2xak1ROSY=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
|
||||
@@ -100,7 +100,7 @@ func init() {
|
||||
return err
|
||||
}
|
||||
|
||||
// inserts the system profiles collection
|
||||
// inserts the system users collection
|
||||
// -----------------------------------------------------------
|
||||
usersCollection := &models.Collection{}
|
||||
usersCollection.MarkAsNew()
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
)
|
||||
|
||||
// Copy the now deprecated RelationOptions.DisplayFields values from
|
||||
// all relation fields and register its value as Presentable under
|
||||
// the specific field in the related collection.
|
||||
//
|
||||
// If there is more than one relation to a single collection with explicitly
|
||||
// set DisplayFields only one of the configuration will be copied.
|
||||
func init() {
|
||||
AppMigrations.Register(func(db dbx.Builder) error {
|
||||
dao := daos.New(db)
|
||||
|
||||
collections := []*models.Collection{}
|
||||
if err := dao.CollectionQuery().All(&collections); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
indexedCollections := make(map[string]*models.Collection, len(collections))
|
||||
for _, collection := range collections {
|
||||
indexedCollections[collection.Id] = collection
|
||||
}
|
||||
|
||||
for _, collection := range indexedCollections {
|
||||
for _, f := range collection.Schema.Fields() {
|
||||
if f.Type != schema.FieldTypeRelation {
|
||||
continue
|
||||
}
|
||||
|
||||
options, ok := f.Options.(*schema.RelationOptions)
|
||||
if !ok || len(options.DisplayFields) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
relCollection, ok := indexedCollections[options.CollectionId]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, name := range options.DisplayFields {
|
||||
relField := relCollection.Schema.GetFieldByName(name)
|
||||
if relField != nil {
|
||||
relField.Presentable = true
|
||||
}
|
||||
}
|
||||
|
||||
// only raw model save
|
||||
if err := dao.Save(relCollection); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}, nil)
|
||||
}
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
// RequestInfo defines a HTTP request data struct, usually used
|
||||
// as part of the `@request.*` filter resolver.
|
||||
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"`
|
||||
Admin *Admin `json:"admin"`
|
||||
Method string `json:"method"`
|
||||
}
|
||||
|
||||
// HasModifierDataKeys loosely checks if the current struct has any modifier Data keys.
|
||||
|
||||
@@ -132,6 +132,10 @@ type SchemaField struct {
|
||||
Type string `form:"type" json:"type"`
|
||||
Required bool `form:"required" json:"required"`
|
||||
|
||||
// Presentable indicates whether the field is suitable for
|
||||
// visualization purposes (eg. in the Admin UI relation views).
|
||||
Presentable bool `form:"presentable" json:"presentable"`
|
||||
|
||||
// Deprecated: This field is no-op and will be removed in future versions.
|
||||
// Please use the collection.Indexes field to define a unique constraint.
|
||||
Unique bool `form:"unique" json:"unique"`
|
||||
@@ -452,21 +456,36 @@ func (o *TextOptions) checkRegex(value any) error {
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
type NumberOptions struct {
|
||||
Min *float64 `form:"min" json:"min"`
|
||||
Max *float64 `form:"max" json:"max"`
|
||||
Min *float64 `form:"min" json:"min"`
|
||||
Max *float64 `form:"max" json:"max"`
|
||||
NoDecimal bool `form:"noDecimal" json:"noDecimal"`
|
||||
}
|
||||
|
||||
func (o NumberOptions) Validate() error {
|
||||
var maxRules []validation.Rule
|
||||
if o.Min != nil && o.Max != nil {
|
||||
maxRules = append(maxRules, validation.Min(*o.Min))
|
||||
maxRules = append(maxRules, validation.Min(*o.Min), validation.By(o.checkNoDecimal))
|
||||
}
|
||||
|
||||
return validation.ValidateStruct(&o,
|
||||
validation.Field(&o.Min, validation.By(o.checkNoDecimal)),
|
||||
validation.Field(&o.Max, maxRules...),
|
||||
)
|
||||
}
|
||||
|
||||
func (o *NumberOptions) checkNoDecimal(value any) error {
|
||||
v, _ := value.(*float64)
|
||||
if v == nil || !o.NoDecimal {
|
||||
return nil // nothing to check
|
||||
}
|
||||
|
||||
if *v != float64(int64(*v)) {
|
||||
return validation.NewError("validation_no_decimal_constraint", "Decimal numbers are not allowed.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
type BoolOptions struct {
|
||||
@@ -519,6 +538,12 @@ func (o UrlOptions) Validate() error {
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
type EditorOptions struct {
|
||||
// ConvertUrls is usually used to instruct the editor whether to
|
||||
// apply url conversion (eg. stripping the domain name in case the
|
||||
// urls are using the same domain as the one where the editor is loaded).
|
||||
//
|
||||
// (see also https://www.tiny.cloud/docs/tinymce/6/url-handling/#convert_urls)
|
||||
ConvertUrls bool `form:"convertUrls" json:"convertUrls"`
|
||||
}
|
||||
|
||||
func (o EditorOptions) Validate() error {
|
||||
@@ -645,7 +670,8 @@ type RelationOptions struct {
|
||||
// If nil no limits are applied.
|
||||
MaxSelect *int `form:"maxSelect" json:"maxSelect"`
|
||||
|
||||
// DisplayFields is optional slice of collection field names used for UI purposes.
|
||||
// Deprecated: This field is no-op and will be removed in future versions.
|
||||
// Instead use the individula SchemaField.Presentable option for each field in the relation collection.
|
||||
DisplayFields []string `form:"displayFields" json:"displayFields"`
|
||||
}
|
||||
|
||||
|
||||
@@ -129,19 +129,19 @@ func TestSchemaFieldColDefinition(t *testing.T) {
|
||||
|
||||
func TestSchemaFieldString(t *testing.T) {
|
||||
f := schema.SchemaField{
|
||||
Id: "abc",
|
||||
Name: "test",
|
||||
Type: schema.FieldTypeText,
|
||||
Required: true,
|
||||
Unique: false,
|
||||
System: true,
|
||||
Id: "abc",
|
||||
Name: "test",
|
||||
Type: schema.FieldTypeText,
|
||||
Required: true,
|
||||
Presentable: true,
|
||||
System: true,
|
||||
Options: &schema.TextOptions{
|
||||
Pattern: "test",
|
||||
},
|
||||
}
|
||||
|
||||
result := f.String()
|
||||
expected := `{"system":true,"id":"abc","name":"test","type":"text","required":true,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`
|
||||
expected := `{"system":true,"id":"abc","name":"test","type":"text","required":true,"presentable":true,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected \n%v, got \n%v", expected, result)
|
||||
@@ -156,19 +156,19 @@ func TestSchemaFieldMarshalJSON(t *testing.T) {
|
||||
// empty
|
||||
{
|
||||
schema.SchemaField{},
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
// without defined options
|
||||
{
|
||||
schema.SchemaField{
|
||||
Id: "abc",
|
||||
Name: "test",
|
||||
Type: schema.FieldTypeText,
|
||||
Required: true,
|
||||
Unique: false,
|
||||
System: true,
|
||||
Id: "abc",
|
||||
Name: "test",
|
||||
Type: schema.FieldTypeText,
|
||||
Required: true,
|
||||
Presentable: true,
|
||||
System: true,
|
||||
},
|
||||
`{"system":true,"id":"abc","name":"test","type":"text","required":true,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
`{"system":true,"id":"abc","name":"test","type":"text","required":true,"presentable":true,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
},
|
||||
// with defined options
|
||||
{
|
||||
@@ -182,7 +182,7 @@ func TestSchemaFieldMarshalJSON(t *testing.T) {
|
||||
Pattern: "test",
|
||||
},
|
||||
},
|
||||
`{"system":true,"id":"","name":"test","type":"text","required":true,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
`{"system":true,"id":"","name":"test","type":"text","required":true,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -207,32 +207,32 @@ func TestSchemaFieldUnmarshalJSON(t *testing.T) {
|
||||
{
|
||||
nil,
|
||||
true,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
[]byte{},
|
||||
true,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
[]byte(`{"system": true}`),
|
||||
true,
|
||||
`{"system":true,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":true,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
[]byte(`{"invalid"`),
|
||||
true,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
[]byte(`{"type":"text","system":true}`),
|
||||
false,
|
||||
`{"system":true,"id":"","name":"","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
`{"system":true,"id":"","name":"","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
},
|
||||
{
|
||||
[]byte(`{"type":"text","options":{"pattern":"test"}}`),
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -470,72 +470,72 @@ func TestSchemaFieldInitOptions(t *testing.T) {
|
||||
{
|
||||
schema.SchemaField{},
|
||||
true,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: "unknown"},
|
||||
true,
|
||||
`{"system":false,"id":"","name":"","type":"unknown","required":false,"unique":false,"options":null}`,
|
||||
`{"system":false,"id":"","name":"","type":"unknown","required":false,"presentable":false,"unique":false,"options":null}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeText},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeNumber},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"number","required":false,"unique":false,"options":{"min":null,"max":null}}`,
|
||||
`{"system":false,"id":"","name":"","type":"number","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"noDecimal":false}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeBool},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"bool","required":false,"unique":false,"options":{}}`,
|
||||
`{"system":false,"id":"","name":"","type":"bool","required":false,"presentable":false,"unique":false,"options":{}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeEmail},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"email","required":false,"unique":false,"options":{"exceptDomains":null,"onlyDomains":null}}`,
|
||||
`{"system":false,"id":"","name":"","type":"email","required":false,"presentable":false,"unique":false,"options":{"exceptDomains":null,"onlyDomains":null}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeUrl},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"url","required":false,"unique":false,"options":{"exceptDomains":null,"onlyDomains":null}}`,
|
||||
`{"system":false,"id":"","name":"","type":"url","required":false,"presentable":false,"unique":false,"options":{"exceptDomains":null,"onlyDomains":null}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeEditor},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"editor","required":false,"unique":false,"options":{}}`,
|
||||
`{"system":false,"id":"","name":"","type":"editor","required":false,"presentable":false,"unique":false,"options":{"convertUrls":false}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeDate},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"date","required":false,"unique":false,"options":{"min":"","max":""}}`,
|
||||
`{"system":false,"id":"","name":"","type":"date","required":false,"presentable":false,"unique":false,"options":{"min":"","max":""}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeSelect},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"select","required":false,"unique":false,"options":{"maxSelect":0,"values":null}}`,
|
||||
`{"system":false,"id":"","name":"","type":"select","required":false,"presentable":false,"unique":false,"options":{"maxSelect":0,"values":null}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeJson},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"json","required":false,"unique":false,"options":{}}`,
|
||||
`{"system":false,"id":"","name":"","type":"json","required":false,"presentable":false,"unique":false,"options":{}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeFile},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"file","required":false,"unique":false,"options":{"maxSelect":0,"maxSize":0,"mimeTypes":null,"thumbs":null,"protected":false}}`,
|
||||
`{"system":false,"id":"","name":"","type":"file","required":false,"presentable":false,"unique":false,"options":{"maxSelect":0,"maxSize":0,"mimeTypes":null,"thumbs":null,"protected":false}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeRelation},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"relation","required":false,"unique":false,"options":{"collectionId":"","cascadeDelete":false,"minSelect":null,"maxSelect":null,"displayFields":null}}`,
|
||||
`{"system":false,"id":"","name":"","type":"relation","required":false,"presentable":false,"unique":false,"options":{"collectionId":"","cascadeDelete":false,"minSelect":null,"maxSelect":null,"displayFields":null}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{Type: schema.FieldTypeUser},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"user","required":false,"unique":false,"options":{"maxSelect":0,"cascadeDelete":false}}`,
|
||||
`{"system":false,"id":"","name":"","type":"user","required":false,"presentable":false,"unique":false,"options":{"maxSelect":0,"cascadeDelete":false}}`,
|
||||
},
|
||||
{
|
||||
schema.SchemaField{
|
||||
@@ -543,7 +543,7 @@ func TestSchemaFieldInitOptions(t *testing.T) {
|
||||
Options: &schema.TextOptions{Pattern: "test"},
|
||||
},
|
||||
false,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
`{"system":false,"id":"","name":"","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1743,8 +1743,12 @@ func TestTextOptionsValidate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNumberOptionsValidate(t *testing.T) {
|
||||
number1 := 10.0
|
||||
number2 := 20.0
|
||||
int1 := 10.0
|
||||
int2 := 20.0
|
||||
|
||||
decimal1 := 10.5
|
||||
decimal2 := 20.5
|
||||
|
||||
scenarios := []fieldOptionsScenario{
|
||||
{
|
||||
"empty",
|
||||
@@ -1754,23 +1758,41 @@ func TestNumberOptionsValidate(t *testing.T) {
|
||||
{
|
||||
"max - without min",
|
||||
schema.NumberOptions{
|
||||
Max: &number1,
|
||||
Max: &int1,
|
||||
},
|
||||
[]string{},
|
||||
},
|
||||
{
|
||||
"max - failure with min",
|
||||
schema.NumberOptions{
|
||||
Min: &number2,
|
||||
Max: &number1,
|
||||
Min: &int2,
|
||||
Max: &int1,
|
||||
},
|
||||
[]string{"max"},
|
||||
},
|
||||
{
|
||||
"max - success with min",
|
||||
schema.NumberOptions{
|
||||
Min: &number1,
|
||||
Max: &number2,
|
||||
Min: &int1,
|
||||
Max: &int2,
|
||||
},
|
||||
[]string{},
|
||||
},
|
||||
{
|
||||
"NoDecimal range failure",
|
||||
schema.NumberOptions{
|
||||
Min: &decimal1,
|
||||
Max: &decimal2,
|
||||
NoDecimal: true,
|
||||
},
|
||||
[]string{"min", "max"},
|
||||
},
|
||||
{
|
||||
"NoDecimal range success",
|
||||
schema.NumberOptions{
|
||||
Min: &int1,
|
||||
Max: &int2,
|
||||
NoDecimal: true,
|
||||
},
|
||||
[]string{},
|
||||
},
|
||||
|
||||
@@ -286,7 +286,7 @@ func TestSchemaMarshalJSON(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := `[{"system":false,"id":"f1id","name":"test1","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}},{"system":false,"id":"f2id","name":"test2","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`
|
||||
expected := `[{"system":false,"id":"f1id","name":"test1","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}},{"system":false,"id":"f2id","name":"test2","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`
|
||||
|
||||
if string(result) != expected {
|
||||
t.Fatalf("Expected %s, got %s", expected, string(result))
|
||||
@@ -354,7 +354,7 @@ func TestSchemaValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := `[{"system":false,"id":"f1id","name":"test1","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`
|
||||
expected := `[{"system":false,"id":"f1id","name":"test1","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`
|
||||
|
||||
if v2 != expected {
|
||||
t.Fatalf("Expected %v, got %v", expected, v2)
|
||||
@@ -377,21 +377,21 @@ func TestSchemaScan(t *testing.T) {
|
||||
{`[{}]`, true, `[]`},
|
||||
// unknown field type
|
||||
{
|
||||
`[{"system":false,"id":"123","name":"test1","type":"unknown","required":false,"unique":false}]`,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"unknown","required":false,"presentable":false,"unique":false}]`,
|
||||
true,
|
||||
`[]`,
|
||||
},
|
||||
// without options
|
||||
{
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"unique":false}]`,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"presentable":false,"unique":false}]`,
|
||||
false,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":""}}]`,
|
||||
},
|
||||
// with options
|
||||
{
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`,
|
||||
false,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`,
|
||||
`[{"system":false,"id":"123","name":"test1","type":"text","required":false,"presentable":false,"unique":false,"options":{"min":null,"max":null,"pattern":"test"}}]`,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,8 @@ type Settings struct {
|
||||
InstagramAuth AuthProviderConfig `form:"instagramAuth" json:"instagramAuth"`
|
||||
VKAuth AuthProviderConfig `form:"vkAuth" json:"vkAuth"`
|
||||
YandexAuth AuthProviderConfig `form:"yandexAuth" json:"yandexAuth"`
|
||||
PatreonAuth AuthProviderConfig `form:"patreonAuth" json:"patreonAuth"`
|
||||
MailcowAuth AuthProviderConfig `form:"mailcowAuth" json:"mailcowAuth"`
|
||||
}
|
||||
|
||||
// New creates and returns a new default Settings instance.
|
||||
@@ -187,6 +189,12 @@ func New() *Settings {
|
||||
YandexAuth: AuthProviderConfig{
|
||||
Enabled: false,
|
||||
},
|
||||
PatreonAuth: AuthProviderConfig{
|
||||
Enabled: false,
|
||||
},
|
||||
MailcowAuth: AuthProviderConfig{
|
||||
Enabled: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +238,8 @@ func (s *Settings) Validate() error {
|
||||
validation.Field(&s.InstagramAuth),
|
||||
validation.Field(&s.VKAuth),
|
||||
validation.Field(&s.YandexAuth),
|
||||
validation.Field(&s.PatreonAuth),
|
||||
validation.Field(&s.MailcowAuth),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -296,6 +306,8 @@ func (s *Settings) RedactClone() (*Settings, error) {
|
||||
&clone.InstagramAuth.ClientSecret,
|
||||
&clone.VKAuth.ClientSecret,
|
||||
&clone.YandexAuth.ClientSecret,
|
||||
&clone.PatreonAuth.ClientSecret,
|
||||
&clone.MailcowAuth.ClientSecret,
|
||||
}
|
||||
|
||||
// mask all sensitive fields
|
||||
@@ -336,6 +348,8 @@ func (s *Settings) NamedAuthProviderConfigs() map[string]AuthProviderConfig {
|
||||
auth.NameInstagram: s.InstagramAuth,
|
||||
auth.NameVK: s.VKAuth,
|
||||
auth.NameYandex: s.YandexAuth,
|
||||
auth.NamePatreon: s.PatreonAuth,
|
||||
auth.NameMailcow: s.MailcowAuth,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,6 +385,12 @@ type SmtpConfig struct {
|
||||
// When set to false StartTLS command is send, leaving the server
|
||||
// to decide whether to upgrade the connection or not.
|
||||
Tls bool `form:"tls" json:"tls"`
|
||||
|
||||
// LocalName is optional domain name or IP address used for the
|
||||
// EHLO/HELO exchange (if not explicitly set, defaults to "localhost").
|
||||
//
|
||||
// This is required only by some SMTP servers, such as Gmail SMTP-relay.
|
||||
LocalName string `form:"localName" json:"localName"`
|
||||
}
|
||||
|
||||
// Validate makes SmtpConfig validatable by implementing [validation.Validatable] interface.
|
||||
@@ -393,6 +413,7 @@ func (c SmtpConfig) Validate() error {
|
||||
// validation.When(c.Enabled, validation.Required),
|
||||
validation.In(mailer.SmtpAuthLogin, mailer.SmtpAuthPlain),
|
||||
),
|
||||
validation.Field(&c.LocalName, is.Host),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,10 @@ func TestSettingsValidate(t *testing.T) {
|
||||
s.VKAuth.ClientId = ""
|
||||
s.YandexAuth.Enabled = true
|
||||
s.YandexAuth.ClientId = ""
|
||||
s.PatreonAuth.Enabled = true
|
||||
s.PatreonAuth.ClientId = ""
|
||||
s.MailcowAuth.Enabled = true
|
||||
s.MailcowAuth.ClientId = ""
|
||||
|
||||
// check if Validate() is triggering the members validate methods.
|
||||
err := s.Validate()
|
||||
@@ -114,6 +118,8 @@ func TestSettingsValidate(t *testing.T) {
|
||||
`"instagramAuth":{`,
|
||||
`"vkAuth":{`,
|
||||
`"yandexAuth":{`,
|
||||
`"patreonAuth":{`,
|
||||
`"mailcowAuth":{`,
|
||||
}
|
||||
|
||||
errBytes, _ := json.Marshal(err)
|
||||
@@ -187,6 +193,10 @@ func TestSettingsMerge(t *testing.T) {
|
||||
s2.VKAuth.ClientId = "vk_test"
|
||||
s2.YandexAuth.Enabled = true
|
||||
s2.YandexAuth.ClientId = "yandex_test"
|
||||
s2.PatreonAuth.Enabled = true
|
||||
s2.PatreonAuth.ClientId = "patreon_test"
|
||||
s2.MailcowAuth.Enabled = true
|
||||
s2.MailcowAuth.ClientId = "mailcow_test"
|
||||
|
||||
if err := s1.Merge(s2); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -277,6 +287,8 @@ func TestSettingsRedactClone(t *testing.T) {
|
||||
s1.InstagramAuth.ClientSecret = testSecret
|
||||
s1.VKAuth.ClientSecret = testSecret
|
||||
s1.YandexAuth.ClientSecret = testSecret
|
||||
s1.PatreonAuth.ClientSecret = testSecret
|
||||
s1.MailcowAuth.ClientSecret = testSecret
|
||||
|
||||
s1Bytes, err := json.Marshal(s1)
|
||||
if err != nil {
|
||||
@@ -335,6 +347,8 @@ func TestNamedAuthProviderConfigs(t *testing.T) {
|
||||
s.InstagramAuth.ClientId = "instagram_test"
|
||||
s.VKAuth.ClientId = "vk_test"
|
||||
s.YandexAuth.ClientId = "yandex_test"
|
||||
s.PatreonAuth.ClientId = "patreon_test"
|
||||
s.MailcowAuth.ClientId = "mailcow_test"
|
||||
|
||||
result := s.NamedAuthProviderConfigs()
|
||||
|
||||
@@ -366,6 +380,8 @@ func TestNamedAuthProviderConfigs(t *testing.T) {
|
||||
`"instagram":{"enabled":false,"clientId":"instagram_test"`,
|
||||
`"vk":{"enabled":false,"clientId":"vk_test"`,
|
||||
`"yandex":{"enabled":false,"clientId":"yandex_test"`,
|
||||
`"patreon":{"enabled":false,"clientId":"patreon_test"`,
|
||||
`"mailcow":{"enabled":false,"clientId":"mailcow_test"`,
|
||||
}
|
||||
for _, p := range expectedParts {
|
||||
if !strings.Contains(encodedStr, p) {
|
||||
@@ -477,6 +493,26 @@ func TestSmtpConfigValidate(t *testing.T) {
|
||||
},
|
||||
false,
|
||||
},
|
||||
// invalid ehlo/helo name
|
||||
{
|
||||
settings.SmtpConfig{
|
||||
Enabled: true,
|
||||
Host: "example.com",
|
||||
Port: 100,
|
||||
LocalName: "invalid!",
|
||||
},
|
||||
true,
|
||||
},
|
||||
// valid ehlo/helo name
|
||||
{
|
||||
settings.SmtpConfig{
|
||||
Enabled: true,
|
||||
Host: "example.com",
|
||||
Port: 100,
|
||||
LocalName: "example.com",
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, scenario := range scenarios {
|
||||
|
||||
+72
-5
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -22,6 +23,7 @@ import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
"github.com/pocketbase/pocketbase/forms"
|
||||
"github.com/pocketbase/pocketbase/mails"
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
"github.com/pocketbase/pocketbase/tokens"
|
||||
@@ -31,7 +33,9 @@ import (
|
||||
"github.com/pocketbase/pocketbase/tools/inflector"
|
||||
"github.com/pocketbase/pocketbase/tools/list"
|
||||
"github.com/pocketbase/pocketbase/tools/mailer"
|
||||
"github.com/pocketbase/pocketbase/tools/rest"
|
||||
"github.com/pocketbase/pocketbase/tools/security"
|
||||
"github.com/pocketbase/pocketbase/tools/subscriptions"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -111,10 +115,14 @@ func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
pr := goja.MustCompile("", "{("+handler+").apply(undefined)}", true)
|
||||
|
||||
err := scheduler.Add(jobId, cronExpr, func() {
|
||||
executors.run(func(executor *goja.Runtime) error {
|
||||
err := executors.run(func(executor *goja.Runtime) error {
|
||||
_, err := executor.RunProgram(pr)
|
||||
return err
|
||||
})
|
||||
|
||||
if err != nil && app.IsDebug() {
|
||||
fmt.Println("[cronAdd] failed to execute cron job " + jobId + ": " + err.Error())
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
panic("[cronAdd] failed to register cron job " + jobId + ": " + err.Error())
|
||||
@@ -272,6 +280,21 @@ func wrapMiddlewares(executors *vmsPool, rawMiddlewares ...goja.Value) ([]echo.M
|
||||
func baseBinds(vm *goja.Runtime) {
|
||||
vm.SetFieldNameMapper(FieldMapper{})
|
||||
|
||||
vm.Set("readerToString", func(r io.Reader, maxBytes int) (string, error) {
|
||||
if maxBytes == 0 {
|
||||
maxBytes = rest.DefaultMaxMemory
|
||||
}
|
||||
|
||||
limitReader := io.LimitReader(r, int64(maxBytes))
|
||||
|
||||
bodyBytes, readErr := io.ReadAll(limitReader)
|
||||
if readErr != nil {
|
||||
return "", readErr
|
||||
}
|
||||
|
||||
return string(bodyBytes), nil
|
||||
})
|
||||
|
||||
vm.Set("arrayOf", func(model any) any {
|
||||
mt := reflect.TypeOf(model)
|
||||
st := reflect.SliceOf(mt)
|
||||
@@ -390,6 +413,16 @@ func baseBinds(vm *goja.Runtime) {
|
||||
|
||||
return instanceValue
|
||||
})
|
||||
|
||||
vm.Set("Cookie", func(call goja.ConstructorCall) *goja.Object {
|
||||
instance := &http.Cookie{}
|
||||
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) {
|
||||
@@ -415,6 +448,19 @@ func dbxBinds(vm *goja.Runtime) {
|
||||
obj.Set("notBetween", dbx.NotBetween)
|
||||
}
|
||||
|
||||
func mailsBinds(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$mails", obj)
|
||||
|
||||
// admin
|
||||
obj.Set("sendAdminPasswordReset", mails.SendAdminPasswordReset)
|
||||
|
||||
// record
|
||||
obj.Set("sendRecordPasswordReset", mails.SendRecordPasswordReset)
|
||||
obj.Set("sendRecordVerification", mails.SendRecordVerification)
|
||||
obj.Set("sendRecordChangeEmail", mails.SendRecordChangeEmail)
|
||||
}
|
||||
|
||||
func tokensBinds(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$tokens", obj)
|
||||
@@ -436,6 +482,14 @@ func securityBinds(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$security", obj)
|
||||
|
||||
// crypto
|
||||
obj.Set("md5", security.MD5)
|
||||
obj.Set("sha256", security.SHA256)
|
||||
obj.Set("sha512", security.SHA512)
|
||||
obj.Set("hs256", security.HS256)
|
||||
obj.Set("hs512", security.HS512)
|
||||
obj.Set("equal", security.Equal)
|
||||
|
||||
// random
|
||||
obj.Set("randomString", security.RandomString)
|
||||
obj.Set("randomStringWithAlphabet", security.RandomStringWithAlphabet)
|
||||
@@ -495,7 +549,8 @@ func osBinds(vm *goja.Runtime) {
|
||||
vm.Set("$os", obj)
|
||||
|
||||
obj.Set("args", os.Args)
|
||||
obj.Set("exec", exec.Command)
|
||||
obj.Set("exec", exec.Command) // @deprecated
|
||||
obj.Set("cmd", exec.Command)
|
||||
obj.Set("exit", os.Exit)
|
||||
obj.Set("getenv", os.Getenv)
|
||||
obj.Set("dirFS", os.DirFS)
|
||||
@@ -570,9 +625,11 @@ func httpClientBinds(vm *goja.Runtime) {
|
||||
vm.Set("$http", obj)
|
||||
|
||||
type sendResult struct {
|
||||
StatusCode int
|
||||
Raw string
|
||||
Json any
|
||||
StatusCode int `json:"statusCode"`
|
||||
Headers map[string][]string `json:"headers"`
|
||||
Cookies map[string]*http.Cookie `json:"cookies"`
|
||||
Raw string `json:"raw"`
|
||||
Json any `json:"json"`
|
||||
}
|
||||
|
||||
type sendConfig struct {
|
||||
@@ -643,9 +700,19 @@ func httpClientBinds(vm *goja.Runtime) {
|
||||
|
||||
result := &sendResult{
|
||||
StatusCode: res.StatusCode,
|
||||
Headers: map[string][]string{},
|
||||
Cookies: map[string]*http.Cookie{},
|
||||
Raw: string(bodyRaw),
|
||||
}
|
||||
|
||||
for k, v := range res.Header {
|
||||
result.Headers[k] = v
|
||||
}
|
||||
|
||||
for _, v := range res.Cookies() {
|
||||
result.Cookies[v.Name] = v
|
||||
}
|
||||
|
||||
if len(result.Raw) != 0 {
|
||||
// try as map
|
||||
result.Json = map[string]any{}
|
||||
|
||||
+211
-24
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/pocketbase/pocketbase/tools/filesystem"
|
||||
"github.com/pocketbase/pocketbase/tools/mailer"
|
||||
"github.com/pocketbase/pocketbase/tools/security"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func testBindsCount(vm *goja.Runtime, namespace string, count int, t *testing.T) {
|
||||
@@ -45,7 +46,90 @@ func TestBaseBindsCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
|
||||
testBindsCount(vm, "this", 13, t)
|
||||
testBindsCount(vm, "this", 16, t)
|
||||
}
|
||||
|
||||
func TestBaseBindsReaderToString(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
vm.Set("reader", strings.NewReader("test"))
|
||||
|
||||
_, err := vm.RunString(`
|
||||
let result = readerToString(reader)
|
||||
|
||||
if (result != "test") {
|
||||
throw new Error('Expected "test", got ' + result);
|
||||
}
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsCookie(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
|
||||
_, err := vm.RunString(`
|
||||
const cookie = new Cookie({
|
||||
name: "example_name",
|
||||
value: "example_value",
|
||||
path: "/example_path",
|
||||
domain: "example.com",
|
||||
maxAge: 10,
|
||||
secure: true,
|
||||
httpOnly: true,
|
||||
sameSite: 3,
|
||||
});
|
||||
|
||||
const result = cookie.string();
|
||||
|
||||
const expected = "example_name=example_value; Path=/example_path; Domain=example.com; Max-Age=10; HttpOnly; Secure; SameSite=Strict";
|
||||
|
||||
if (expected != result) {
|
||||
throw new("Expected \n" + expected + "\ngot\n" + result);
|
||||
}
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -484,6 +568,60 @@ func TestDbxBinds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMailsBindsCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
mailsBinds(vm)
|
||||
|
||||
testBindsCount(vm, "$mails", 4, t)
|
||||
}
|
||||
|
||||
func TestMailsBinds(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
admin, err := app.Dao().FindAdminByEmail("test@example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
record, err := app.Dao().FindAuthRecordByEmail("users", "test@example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
mailsBinds(vm)
|
||||
vm.Set("$app", app)
|
||||
vm.Set("admin", admin)
|
||||
vm.Set("record", record)
|
||||
|
||||
_, vmErr := vm.RunString(`
|
||||
$mails.sendAdminPasswordReset($app, admin);
|
||||
if (!$app.testMailer.lastMessage.html.includes("/_/#/confirm-password-reset/")) {
|
||||
throw new Error("Expected admin password reset email")
|
||||
}
|
||||
|
||||
$mails.sendRecordPasswordReset($app, record);
|
||||
if (!$app.testMailer.lastMessage.html.includes("/_/#/auth/confirm-password-reset/")) {
|
||||
throw new Error("Expected record password reset email")
|
||||
}
|
||||
|
||||
$mails.sendRecordVerification($app, record);
|
||||
if (!$app.testMailer.lastMessage.html.includes("/_/#/auth/confirm-verification/")) {
|
||||
throw new Error("Expected record verification email")
|
||||
}
|
||||
|
||||
$mails.sendRecordChangeEmail($app, record, "new@example.com");
|
||||
if (!$app.testMailer.lastMessage.html.includes("/_/#/auth/confirm-email-change/")) {
|
||||
throw new Error("Expected record email change email")
|
||||
}
|
||||
`)
|
||||
if vmErr != nil {
|
||||
t.Fatal(vmErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTokensBindsCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
tokensBinds(vm)
|
||||
@@ -506,11 +644,11 @@ func TestTokensBinds(t *testing.T) {
|
||||
}
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
tokensBinds(vm)
|
||||
vm.Set("$app", app)
|
||||
vm.Set("admin", admin)
|
||||
vm.Set("record", record)
|
||||
baseBinds(vm)
|
||||
tokensBinds(vm)
|
||||
|
||||
sceneraios := []struct {
|
||||
js string
|
||||
@@ -568,7 +706,44 @@ func TestSecurityBindsCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
securityBinds(vm)
|
||||
|
||||
testBindsCount(vm, "$security", 9, t)
|
||||
testBindsCount(vm, "$security", 15, t)
|
||||
}
|
||||
|
||||
func TestSecurityCryptoBinds(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
securityBinds(vm)
|
||||
|
||||
sceneraios := []struct {
|
||||
js string
|
||||
expected string
|
||||
}{
|
||||
{`$security.md5("123")`, "202cb962ac59075b964b07152d234b70"},
|
||||
{`$security.sha256("123")`, "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3"},
|
||||
{`$security.sha512("123")`, "3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2"},
|
||||
{`$security.hs256("hello", "test")`, "f151ea24bda91a18e89b8bb5793ef324b2a02133cce15a28a719acbd2e58a986"},
|
||||
{`$security.hs512("hello", "test")`, "44f280e11103e295c26cd61dd1cdd8178b531b860466867c13b1c37a26b6389f8af110efbe0bb0717b9d9c87f6fe1c97b3b1690936578890e5669abf279fe7fd"},
|
||||
{`$security.equal("abc", "abc")`, "true"},
|
||||
{`$security.equal("abc", "abcd")`, "false"},
|
||||
}
|
||||
|
||||
for _, s := range sceneraios {
|
||||
t.Run(s.js, func(t *testing.T) {
|
||||
result, err := vm.RunString(s.js)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to execute js script, got %v", err)
|
||||
}
|
||||
|
||||
v := cast.ToString(result.Export())
|
||||
|
||||
if v != s.expected {
|
||||
t.Fatalf("Expected %v \ngot \n%v", s.expected, v)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecurityRandomStringBinds(t *testing.T) {
|
||||
@@ -590,16 +765,18 @@ func TestSecurityRandomStringBinds(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, s := range sceneraios {
|
||||
result, err := vm.RunString(s.js)
|
||||
if err != nil {
|
||||
t.Fatalf("[%s] Failed to execute js script, got %v", s.js, err)
|
||||
}
|
||||
t.Run(s.js, func(t *testing.T) {
|
||||
result, err := vm.RunString(s.js)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to execute js script, got %v", err)
|
||||
}
|
||||
|
||||
v, _ := result.Export().(string)
|
||||
v, _ := result.Export().(string)
|
||||
|
||||
if len(v) != s.length {
|
||||
t.Fatalf("[%s] Expected %d length string, \ngot \n%v", s.js, s.length, v)
|
||||
}
|
||||
if len(v) != s.length {
|
||||
t.Fatalf("Expected %d length string, \ngot \n%v", s.length, v)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,16 +807,18 @@ func TestSecurityJWTBinds(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, s := range sceneraios {
|
||||
result, err := vm.RunString(s.js)
|
||||
if err != nil {
|
||||
t.Fatalf("[%s] Failed to execute js script, got %v", s.js, err)
|
||||
}
|
||||
t.Run(s.js, func(t *testing.T) {
|
||||
result, err := vm.RunString(s.js)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to execute js script, got %v", err)
|
||||
}
|
||||
|
||||
raw, _ := json.Marshal(result.Export())
|
||||
raw, _ := json.Marshal(result.Export())
|
||||
|
||||
if string(raw) != s.expected {
|
||||
t.Fatalf("[%s] Expected \n%s, \ngot \n%s", s.js, s.expected, raw)
|
||||
}
|
||||
if string(raw) != s.expected {
|
||||
t.Fatalf("Expected \n%s, \ngot \n%s", s.expected, raw)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -907,9 +1086,9 @@ func TestHttpClientBindsCount(t *testing.T) {
|
||||
|
||||
func TestHttpClientBindsSend(t *testing.T) {
|
||||
// start a test server
|
||||
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.Query().Get("testError") != "" {
|
||||
rw.WriteHeader(400)
|
||||
res.WriteHeader(400)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -936,10 +1115,14 @@ func TestHttpClientBindsSend(t *testing.T) {
|
||||
"body": string(bodyRaw),
|
||||
}
|
||||
|
||||
// add custom headers and cookies
|
||||
res.Header().Add("X-Custom", "custom_header")
|
||||
res.Header().Add("Set-Cookie", "sessionId=123456")
|
||||
|
||||
infoRaw, _ := json.Marshal(info)
|
||||
|
||||
// write back the submitted request
|
||||
rw.Write(infoRaw)
|
||||
res.Write(infoRaw)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -1006,6 +1189,8 @@ func TestHttpClientBindsSend(t *testing.T) {
|
||||
}],
|
||||
[test1, {
|
||||
"statusCode": "200",
|
||||
"headers.X-Custom.0": "custom_header",
|
||||
"cookies.sessionId.value": "123456",
|
||||
"json.method": "POST",
|
||||
"json.headers.header1": "123",
|
||||
"json.headers.header2": "456",
|
||||
@@ -1014,6 +1199,8 @@ func TestHttpClientBindsSend(t *testing.T) {
|
||||
}],
|
||||
[test2, {
|
||||
"statusCode": "200",
|
||||
"headers.X-Custom.0": "custom_header",
|
||||
"cookies.sessionId.value": "123456",
|
||||
"json.method": "GET",
|
||||
"json.headers.content_type": "text/plain",
|
||||
}],
|
||||
@@ -1248,5 +1435,5 @@ func TestOsBindsCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
osBinds(vm)
|
||||
|
||||
testBindsCount(vm, "$os", 16, t)
|
||||
testBindsCount(vm, "$os", 17, t)
|
||||
}
|
||||
|
||||
+7222
-6630
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 * * * *", () => {
|
||||
* console.log("Hello world!")
|
||||
* })
|
||||
* ` + "```" + `
|
||||
@@ -144,8 +144,19 @@ declare function routerPre(...middlewares: Array<string|echo.MiddlewareFunc>): v
|
||||
*/
|
||||
declare var __hooks: string
|
||||
|
||||
// skip on* hook methods as they are registered via the global on* method
|
||||
type appWithoutHooks = Omit<pocketbase.PocketBase, ` + "`on${string}`" + `>
|
||||
// Utility type to exclude the on* hook methods from a type
|
||||
// (hooks are separately generated as global methods).
|
||||
//
|
||||
// See https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#key-remapping-via-as
|
||||
type excludeHooks<Type> = {
|
||||
[Property in keyof Type as Exclude<Property, ` + "`on${string}`" + `>]: Type[Property]
|
||||
};
|
||||
|
||||
// core.App without the on* hook methods
|
||||
type CoreApp = excludeHooks<ORIGINAL_CORE_APP>
|
||||
|
||||
// pocketbase.PocketBase without the on* hook methods
|
||||
type PocketBase = excludeHooks<ORIGINAL_POCKETBASE>
|
||||
|
||||
/**
|
||||
* ` + "`$app`" + ` is the current running PocketBase instance that is globally
|
||||
@@ -156,7 +167,7 @@ type appWithoutHooks = Omit<pocketbase.PocketBase, ` + "`on${string}`" + `>
|
||||
* @namespace
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare var $app: appWithoutHooks
|
||||
declare var $app: PocketBase
|
||||
|
||||
/**
|
||||
* ` + "`$template`" + ` is a global helper to load and cache HTML templates on the fly.
|
||||
@@ -180,6 +191,24 @@ declare var $app: appWithoutHooks
|
||||
*/
|
||||
declare var $template: template.Registry
|
||||
|
||||
/**
|
||||
* readerToString reads the content of the specified io.Reader until
|
||||
* EOF or maxBytes are reached.
|
||||
*
|
||||
* If maxBytes is not specified it will read up to 32MB.
|
||||
*
|
||||
* Note that after this call the reader can't be used anymore.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ` + "```" + `js
|
||||
* const rawBody = readerToString(c.request().body)
|
||||
* ` + "```" + `
|
||||
*
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare function readerToString(reader: any, maxBytes?: number): string;
|
||||
|
||||
/**
|
||||
* arrayOf creates a placeholder array of the specified models.
|
||||
* Usually used to populate DB result into an array of models.
|
||||
@@ -421,6 +450,57 @@ declare class Dao implements daos.Dao {
|
||||
constructor(concurrentDB?: dbx.Builder, nonconcurrentDB?: dbx.Builder)
|
||||
}
|
||||
|
||||
interface Cookie extends http.Cookie{} // merge
|
||||
/**
|
||||
* A Cookie represents an HTTP cookie as sent in the Set-Cookie header of an
|
||||
* HTTP response.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ` + "```" + `js
|
||||
* routerAdd("POST", "/example", (c) => {
|
||||
* c.setCookie(new Cookie({
|
||||
* name: "example_name",
|
||||
* value: "example_value",
|
||||
* path: "/",
|
||||
* domain: "example.com",
|
||||
* maxAge: 10,
|
||||
* secure: true,
|
||||
* httpOnly: true,
|
||||
* sameSite: 3,
|
||||
* }))
|
||||
*
|
||||
* return c.redirect(200, "/");
|
||||
* })
|
||||
* ` + "```" + `
|
||||
*
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class Cookie implements 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
|
||||
// -------------------------------------------------------------------
|
||||
@@ -498,6 +578,12 @@ declare namespace $security {
|
||||
let createJWT: security.newJWT
|
||||
let encrypt: security.encrypt
|
||||
let decrypt: security.decrypt
|
||||
let hs256: security.hs256
|
||||
let hs512: security.hs512
|
||||
let equal: security.equal
|
||||
let md5: security.md5
|
||||
let sha256: security.sha256
|
||||
let sha512: security.sha512
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
@@ -555,7 +641,26 @@ declare namespace $filepath {
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare namespace $os {
|
||||
export let exec: exec.command
|
||||
/**
|
||||
* Legacy alias for $os.cmd().
|
||||
*/
|
||||
export let exec: exec.command
|
||||
|
||||
/**
|
||||
* Prepares an external OS command.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ` + "```" + `js
|
||||
* // prepare the command to execute
|
||||
* const cmd = $os.cmd('ls', '-sl')
|
||||
*
|
||||
* // execute the command and return its standard output as string
|
||||
* const output = String.fromCharCode(...cmd.output());
|
||||
* ` + "```" + `
|
||||
*/
|
||||
export let cmd: exec.command
|
||||
|
||||
export let args: os.args
|
||||
export let exit: os.exit
|
||||
export let getenv: os.getenv
|
||||
@@ -583,7 +688,7 @@ interface AdminLoginForm extends forms.AdminLogin{} // merge
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class AdminLoginForm implements forms.AdminLogin {
|
||||
constructor(app: core.App)
|
||||
constructor(app: CoreApp)
|
||||
}
|
||||
|
||||
interface AdminPasswordResetConfirmForm extends forms.AdminPasswordResetConfirm{} // merge
|
||||
@@ -592,7 +697,7 @@ interface AdminPasswordResetConfirmForm extends forms.AdminPasswordResetConfirm{
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class AdminPasswordResetConfirmForm implements forms.AdminPasswordResetConfirm {
|
||||
constructor(app: core.App)
|
||||
constructor(app: CoreApp)
|
||||
}
|
||||
|
||||
interface AdminPasswordResetRequestForm extends forms.AdminPasswordResetRequest{} // merge
|
||||
@@ -601,7 +706,7 @@ interface AdminPasswordResetRequestForm extends forms.AdminPasswordResetRequest{
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class AdminPasswordResetRequestForm implements forms.AdminPasswordResetRequest {
|
||||
constructor(app: core.App)
|
||||
constructor(app: CoreApp)
|
||||
}
|
||||
|
||||
interface AdminUpsertForm extends forms.AdminUpsert{} // merge
|
||||
@@ -610,7 +715,7 @@ interface AdminUpsertForm extends forms.AdminUpsert{} // merge
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class AdminUpsertForm implements forms.AdminUpsert {
|
||||
constructor(app: core.App, admin: models.Admin)
|
||||
constructor(app: CoreApp, admin: models.Admin)
|
||||
}
|
||||
|
||||
interface AppleClientSecretCreateForm extends forms.AppleClientSecretCreate{} // merge
|
||||
@@ -619,7 +724,7 @@ interface AppleClientSecretCreateForm extends forms.AppleClientSecretCreate{} //
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class AppleClientSecretCreateForm implements forms.AppleClientSecretCreate {
|
||||
constructor(app: core.App)
|
||||
constructor(app: CoreApp)
|
||||
}
|
||||
|
||||
interface CollectionUpsertForm extends forms.CollectionUpsert{} // merge
|
||||
@@ -628,7 +733,7 @@ interface CollectionUpsertForm extends forms.CollectionUpsert{} // merge
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class CollectionUpsertForm implements forms.CollectionUpsert {
|
||||
constructor(app: core.App, collection: models.Collection)
|
||||
constructor(app: CoreApp, collection: models.Collection)
|
||||
}
|
||||
|
||||
interface CollectionsImportForm extends forms.CollectionsImport{} // merge
|
||||
@@ -637,7 +742,7 @@ interface CollectionsImportForm extends forms.CollectionsImport{} // merge
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class CollectionsImportForm implements forms.CollectionsImport {
|
||||
constructor(app: core.App)
|
||||
constructor(app: CoreApp)
|
||||
}
|
||||
|
||||
interface RealtimeSubscribeForm extends forms.RealtimeSubscribe{} // merge
|
||||
@@ -653,7 +758,7 @@ interface RecordEmailChangeConfirmForm extends forms.RecordEmailChangeConfirm{}
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class RecordEmailChangeConfirmForm implements forms.RecordEmailChangeConfirm {
|
||||
constructor(app: core.App, collection: models.Collection)
|
||||
constructor(app: CoreApp, collection: models.Collection)
|
||||
}
|
||||
|
||||
interface RecordEmailChangeRequestForm extends forms.RecordEmailChangeRequest{} // merge
|
||||
@@ -662,7 +767,7 @@ interface RecordEmailChangeRequestForm extends forms.RecordEmailChangeRequest{}
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class RecordEmailChangeRequestForm implements forms.RecordEmailChangeRequest {
|
||||
constructor(app: core.App, record: models.Record)
|
||||
constructor(app: CoreApp, record: models.Record)
|
||||
}
|
||||
|
||||
interface RecordOAuth2LoginForm extends forms.RecordOAuth2Login{} // merge
|
||||
@@ -671,7 +776,7 @@ interface RecordOAuth2LoginForm extends forms.RecordOAuth2Login{} // merge
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class RecordOAuth2LoginForm implements forms.RecordOAuth2Login {
|
||||
constructor(app: core.App, collection: models.Collection, optAuthRecord?: models.Record)
|
||||
constructor(app: CoreApp, collection: models.Collection, optAuthRecord?: models.Record)
|
||||
}
|
||||
|
||||
interface RecordPasswordLoginForm extends forms.RecordPasswordLogin{} // merge
|
||||
@@ -680,7 +785,7 @@ interface RecordPasswordLoginForm extends forms.RecordPasswordLogin{} // merge
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class RecordPasswordLoginForm implements forms.RecordPasswordLogin {
|
||||
constructor(app: core.App, collection: models.Collection)
|
||||
constructor(app: CoreApp, collection: models.Collection)
|
||||
}
|
||||
|
||||
interface RecordPasswordResetConfirmForm extends forms.RecordPasswordResetConfirm{} // merge
|
||||
@@ -689,7 +794,7 @@ interface RecordPasswordResetConfirmForm extends forms.RecordPasswordResetConfir
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class RecordPasswordResetConfirmForm implements forms.RecordPasswordResetConfirm {
|
||||
constructor(app: core.App, collection: models.Collection)
|
||||
constructor(app: CoreApp, collection: models.Collection)
|
||||
}
|
||||
|
||||
interface RecordPasswordResetRequestForm extends forms.RecordPasswordResetRequest{} // merge
|
||||
@@ -698,7 +803,7 @@ interface RecordPasswordResetRequestForm extends forms.RecordPasswordResetReques
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class RecordPasswordResetRequestForm implements forms.RecordPasswordResetRequest {
|
||||
constructor(app: core.App, collection: models.Collection)
|
||||
constructor(app: CoreApp, collection: models.Collection)
|
||||
}
|
||||
|
||||
interface RecordUpsertForm extends forms.RecordUpsert{} // merge
|
||||
@@ -707,7 +812,7 @@ interface RecordUpsertForm extends forms.RecordUpsert{} // merge
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class RecordUpsertForm implements forms.RecordUpsert {
|
||||
constructor(app: core.App, record: models.Record)
|
||||
constructor(app: CoreApp, record: models.Record)
|
||||
}
|
||||
|
||||
interface RecordVerificationConfirmForm extends forms.RecordVerificationConfirm{} // merge
|
||||
@@ -716,7 +821,7 @@ interface RecordVerificationConfirmForm extends forms.RecordVerificationConfirm{
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class RecordVerificationConfirmForm implements forms.RecordVerificationConfirm {
|
||||
constructor(app: core.App, collection: models.Collection)
|
||||
constructor(app: CoreApp, collection: models.Collection)
|
||||
}
|
||||
|
||||
interface RecordVerificationRequestForm extends forms.RecordVerificationRequest{} // merge
|
||||
@@ -725,7 +830,7 @@ interface RecordVerificationRequestForm extends forms.RecordVerificationRequest{
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class RecordVerificationRequestForm implements forms.RecordVerificationRequest {
|
||||
constructor(app: core.App, collection: models.Collection)
|
||||
constructor(app: CoreApp, collection: models.Collection)
|
||||
}
|
||||
|
||||
interface SettingsUpsertForm extends forms.SettingsUpsert{} // merge
|
||||
@@ -734,7 +839,7 @@ interface SettingsUpsertForm extends forms.SettingsUpsert{} // merge
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class SettingsUpsertForm implements forms.SettingsUpsert {
|
||||
constructor(app: core.App)
|
||||
constructor(app: CoreApp)
|
||||
}
|
||||
|
||||
interface TestEmailSendForm extends forms.TestEmailSend{} // merge
|
||||
@@ -743,7 +848,7 @@ interface TestEmailSendForm extends forms.TestEmailSend{} // merge
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class TestEmailSendForm implements forms.TestEmailSend {
|
||||
constructor(app: core.App)
|
||||
constructor(app: CoreApp)
|
||||
}
|
||||
|
||||
interface TestS3FilesystemForm extends forms.TestS3Filesystem{} // merge
|
||||
@@ -752,7 +857,7 @@ interface TestS3FilesystemForm extends forms.TestS3Filesystem{} // merge
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare class TestS3FilesystemForm implements forms.TestS3Filesystem {
|
||||
constructor(app: core.App)
|
||||
constructor(app: CoreApp)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
@@ -857,9 +962,11 @@ declare namespace $http {
|
||||
* method: "post",
|
||||
* })
|
||||
*
|
||||
* console.log(res.statusCode)
|
||||
* console.log(res.raw)
|
||||
* console.log(res.json)
|
||||
* console.log(res.statusCode) // the response HTTP status code
|
||||
* console.log(res.headers) // the response headers (eg. res.headers['X-Custom'][0])
|
||||
* console.log(res.cookies) // the response cookies (eg. res.cookies.sessionId.value)
|
||||
* console.log(res.raw) // the response body as plain text
|
||||
* console.log(res.json) // the response body as parsed json array or map
|
||||
* ` + "```" + `
|
||||
*/
|
||||
function send(config: {
|
||||
@@ -872,9 +979,11 @@ declare namespace $http {
|
||||
// deprecated, please use body instead
|
||||
data?: { [key:string]: any },
|
||||
}): {
|
||||
statusCode: number
|
||||
raw: string
|
||||
json: any
|
||||
statusCode: number,
|
||||
headers: { [key:string]: Array<string> },
|
||||
cookies: { [key:string]: http.Cookie },
|
||||
raw: string,
|
||||
json: any,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -953,6 +1062,12 @@ func main() {
|
||||
log.Fatal("Failed to get the current docs directory")
|
||||
}
|
||||
|
||||
// replace the original app interfaces with their non-"on*"" hooks equivalents
|
||||
result = strings.ReplaceAll(result, "core.App", "CoreApp")
|
||||
result = strings.ReplaceAll(result, "pocketbase.PocketBase", "PocketBase")
|
||||
result = strings.ReplaceAll(result, "ORIGINAL_CORE_APP", "core.App")
|
||||
result = strings.ReplaceAll(result, "ORIGINAL_POCKETBASE", "pocketbase.PocketBase")
|
||||
|
||||
parentDir := filepath.Dir(filename)
|
||||
typesFile := filepath.Join(parentDir, "generated", "types.d.ts")
|
||||
|
||||
|
||||
@@ -161,12 +161,9 @@ func (p *plugin) registerMigrations() error {
|
||||
dbxBinds(vm)
|
||||
tokensBinds(vm)
|
||||
securityBinds(vm)
|
||||
// note: disallow for now and give the authors of custom SaaS offerings
|
||||
// some time to adjust their code to avoid eventual security issues
|
||||
//
|
||||
// osBinds(vm)
|
||||
// filepathBinds(vm)
|
||||
// httpClientBinds(vm)
|
||||
osBinds(vm)
|
||||
filepathBinds(vm)
|
||||
httpClientBinds(vm)
|
||||
|
||||
vm.Set("migrate", func(up, down func(db dbx.Builder) error) {
|
||||
m.AppMigrations.Register(up, down, file)
|
||||
@@ -236,6 +233,7 @@ func (p *plugin) registerHooks() error {
|
||||
requireRegistry.Enable(vm)
|
||||
console.Enable(vm)
|
||||
process.Enable(vm)
|
||||
|
||||
baseBinds(vm)
|
||||
dbxBinds(vm)
|
||||
filesystemBinds(vm)
|
||||
@@ -246,6 +244,8 @@ func (p *plugin) registerHooks() error {
|
||||
httpClientBinds(vm)
|
||||
formsBinds(vm)
|
||||
apisBinds(vm)
|
||||
mailsBinds(vm)
|
||||
|
||||
vm.Set("$app", p.app)
|
||||
vm.Set("$template", templateRegistry)
|
||||
vm.Set("__hooks", absHooksDir)
|
||||
|
||||
@@ -400,6 +400,7 @@ migrate((db) => {
|
||||
"name": "f4_name",
|
||||
"type": "text",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
@@ -415,10 +416,12 @@ migrate((db) => {
|
||||
"name": "f2_name_new",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": true,
|
||||
"options": {
|
||||
"min": 10,
|
||||
"max": null
|
||||
"max": null,
|
||||
"noDecimal": false
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -454,6 +457,7 @@ migrate((db) => {
|
||||
"name": "f3_name",
|
||||
"type": "bool",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {}
|
||||
}))
|
||||
@@ -468,10 +472,12 @@ migrate((db) => {
|
||||
"name": "f2_name",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": true,
|
||||
"options": {
|
||||
"min": 10,
|
||||
"max": null
|
||||
"max": null,
|
||||
"noDecimal": false
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -534,6 +540,7 @@ func init() {
|
||||
"name": "f4_name",
|
||||
"type": "text",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
@@ -551,10 +558,12 @@ func init() {
|
||||
"name": "f2_name_new",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": true,
|
||||
"options": {
|
||||
"min": 10,
|
||||
"max": null
|
||||
"max": null,
|
||||
"noDecimal": false
|
||||
}
|
||||
}` + "`" + `), edit_f2_name_new)
|
||||
collection.Schema.AddField(edit_f2_name_new)
|
||||
@@ -605,6 +614,7 @@ func init() {
|
||||
"name": "f3_name",
|
||||
"type": "bool",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {}
|
||||
}` + "`" + `), del_f3_name)
|
||||
@@ -621,10 +631,12 @@ func init() {
|
||||
"name": "f2_name",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": true,
|
||||
"options": {
|
||||
"min": 10,
|
||||
"max": null
|
||||
"max": null,
|
||||
"noDecimal": false
|
||||
}
|
||||
}` + "`" + `), edit_f2_name_new)
|
||||
collection.Schema.AddField(edit_f2_name_new)
|
||||
|
||||
+12
-11
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -37,9 +38,9 @@ type ApiScenario struct {
|
||||
|
||||
// test hooks
|
||||
// ---
|
||||
TestAppFactory func() (*TestApp, error)
|
||||
TestAppFactory func(t *testing.T) *TestApp
|
||||
BeforeTestFunc func(t *testing.T, app *TestApp, e *echo.Echo)
|
||||
AfterTestFunc func(t *testing.T, app *TestApp, e *echo.Echo)
|
||||
AfterTestFunc func(t *testing.T, app *TestApp, res *http.Response)
|
||||
}
|
||||
|
||||
// Test executes the test scenario.
|
||||
@@ -54,16 +55,17 @@ func (scenario *ApiScenario) Test(t *testing.T) {
|
||||
|
||||
func (scenario *ApiScenario) test(t *testing.T) {
|
||||
var testApp *TestApp
|
||||
var testAppErr error
|
||||
if scenario.TestAppFactory != nil {
|
||||
// @todo consider passing the testing instance to the factory and maybe remove the error from the declaration
|
||||
// (see https://github.com/pocketbase/pocketbase/discussions/3025)
|
||||
testApp, testAppErr = scenario.TestAppFactory()
|
||||
testApp = scenario.TestAppFactory(t)
|
||||
if testApp == nil {
|
||||
t.Fatal("TestAppFactory must return a non-nill app instance")
|
||||
}
|
||||
} else {
|
||||
var testAppErr error
|
||||
testApp, testAppErr = NewTestApp()
|
||||
}
|
||||
if testAppErr != nil {
|
||||
t.Fatalf("Failed to initialize the test app instance: %v", testAppErr)
|
||||
if testAppErr != nil {
|
||||
t.Fatalf("Failed to initialize the test app instance: %v", testAppErr)
|
||||
}
|
||||
}
|
||||
defer testApp.Cleanup()
|
||||
|
||||
@@ -172,8 +174,7 @@ func (scenario *ApiScenario) test(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// @todo consider adding the response body to the AfterTestFunc args
|
||||
if scenario.AfterTestFunc != nil {
|
||||
scenario.AfterTestFunc(t, testApp, e)
|
||||
scenario.AfterTestFunc(t, testApp, res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package archive
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"compress/flate"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
@@ -27,6 +28,11 @@ func Create(src string, dest string, skipPaths ...string) error {
|
||||
zw := zip.NewWriter(zf)
|
||||
defer zw.Close()
|
||||
|
||||
// register a custom Deflate compressor
|
||||
zw.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
|
||||
return flate.NewWriter(out, flate.BestSpeed)
|
||||
})
|
||||
|
||||
if err := zipAddFS(zw, os.DirFS(src), skipPaths...); err != nil {
|
||||
// try to cleanup at least the created zip file
|
||||
os.Remove(dest)
|
||||
|
||||
@@ -135,6 +135,10 @@ func NewProviderByName(name string) (Provider, error) {
|
||||
return NewVKProvider(), nil
|
||||
case NameYandex:
|
||||
return NewYandexProvider(), nil
|
||||
case NamePatreon:
|
||||
return NewPatreonProvider(), nil
|
||||
case NameMailcow:
|
||||
return NewMailcowProvider(), nil
|
||||
default:
|
||||
return nil, errors.New("Missing provider " + name)
|
||||
}
|
||||
|
||||
+19
-1
@@ -205,6 +205,24 @@ func TestNewProviderByName(t *testing.T) {
|
||||
t.Errorf("Expected nil, got error %v", err)
|
||||
}
|
||||
if _, ok := p.(*auth.Yandex); !ok {
|
||||
t.Error("Expected to be instance of *auth.yandex")
|
||||
t.Error("Expected to be instance of *auth.Yandex")
|
||||
}
|
||||
|
||||
// patreon
|
||||
p, err = auth.NewProviderByName(auth.NamePatreon)
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil, got error %v", err)
|
||||
}
|
||||
if _, ok := p.(*auth.Patreon); !ok {
|
||||
t.Error("Expected to be instance of *auth.Patreon")
|
||||
}
|
||||
|
||||
// mailcow
|
||||
p, err = auth.NewProviderByName(auth.NameMailcow)
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil, got error %v", err)
|
||||
}
|
||||
if _, ok := p.(*auth.Mailcow); !ok {
|
||||
t.Error("Expected to be instance of *auth.Mailcow")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
var _ Provider = (*Mailcow)(nil)
|
||||
|
||||
// NameMailcow is the unique name of the mailcow provider.
|
||||
const NameMailcow string = "mailcow"
|
||||
|
||||
// Mailcow allows authentication via mailcow OAuth2.
|
||||
type Mailcow struct {
|
||||
*baseProvider
|
||||
}
|
||||
|
||||
// NewMailcowProvider creates a new mailcow provider instance with some defaults.
|
||||
func NewMailcowProvider() *Mailcow {
|
||||
return &Mailcow{&baseProvider{
|
||||
ctx: context.Background(),
|
||||
scopes: []string{"profile"},
|
||||
}}
|
||||
}
|
||||
|
||||
// FetchAuthUser returns an AuthUser instance based on mailcow's user api.
|
||||
//
|
||||
// API reference: https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/oauth/profile.php
|
||||
func (p *Mailcow) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) {
|
||||
data, err := p.FetchRawUserData(token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rawUser := map[string]any{}
|
||||
if err := json.Unmarshal(data, &rawUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
extracted := struct {
|
||||
Id string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
FullName string `json:"full_name"`
|
||||
Active int `json:"active"`
|
||||
}{}
|
||||
if err := json.Unmarshal(data, &extracted); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if extracted.Active != 1 {
|
||||
return nil, errors.New("the mailcow user is not active")
|
||||
}
|
||||
|
||||
user := &AuthUser{
|
||||
Id: extracted.Id,
|
||||
Name: extracted.FullName,
|
||||
Username: extracted.Username,
|
||||
Email: extracted.Email,
|
||||
RawUser: rawUser,
|
||||
AccessToken: token.AccessToken,
|
||||
RefreshToken: token.RefreshToken,
|
||||
}
|
||||
|
||||
// mailcow usernames are usually just the email adresses, so we just take the part in front of the @
|
||||
if strings.Contains(user.Username, "@") {
|
||||
user.Username = strings.Split(user.Username, "@")[0]
|
||||
}
|
||||
|
||||
return user, nil
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
var _ Provider = (*Patreon)(nil)
|
||||
|
||||
// NamePatreon is the unique name of the Patreon provider.
|
||||
const NamePatreon string = "patreon"
|
||||
|
||||
// Patreon allows authentication via Patreon OAuth2.
|
||||
type Patreon struct {
|
||||
*baseProvider
|
||||
}
|
||||
|
||||
// NewPatreonProvider creates new Patreon provider instance with some defaults.
|
||||
func NewPatreonProvider() *Patreon {
|
||||
return &Patreon{&baseProvider{
|
||||
ctx: context.Background(),
|
||||
scopes: []string{"identity", "identity[email]"},
|
||||
authUrl: "https://www.patreon.com/oauth2/authorize",
|
||||
tokenUrl: "https://www.patreon.com/api/oauth2/token",
|
||||
userApiUrl: "https://www.patreon.com/api/oauth2/v2/identity?fields%5Buser%5D=full_name,email,vanity,image_url,is_email_verified",
|
||||
}}
|
||||
}
|
||||
|
||||
// FetchAuthUser returns an AuthUser instance based on the Patreons's identity api.
|
||||
//
|
||||
// API reference:
|
||||
// https://docs.patreon.com/#get-api-oauth2-v2-identity
|
||||
// https://docs.patreon.com/#user-v2
|
||||
func (p *Patreon) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) {
|
||||
data, err := p.FetchRawUserData(token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rawUser := map[string]any{}
|
||||
if err := json.Unmarshal(data, &rawUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
extracted := struct {
|
||||
Data struct {
|
||||
Id string `json:"id"`
|
||||
Attributes struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"full_name"`
|
||||
Username string `json:"vanity"`
|
||||
AvatarUrl string `json:"image_url"`
|
||||
IsEmailVerified bool `json:"is_email_verified"`
|
||||
} `json:"attributes"`
|
||||
} `json:"data"`
|
||||
}{}
|
||||
if err := json.Unmarshal(data, &extracted); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
user := &AuthUser{
|
||||
Id: extracted.Data.Id,
|
||||
Username: extracted.Data.Attributes.Username,
|
||||
Name: extracted.Data.Attributes.Name,
|
||||
AvatarUrl: extracted.Data.Attributes.AvatarUrl,
|
||||
RawUser: rawUser,
|
||||
AccessToken: token.AccessToken,
|
||||
RefreshToken: token.RefreshToken,
|
||||
}
|
||||
|
||||
if extracted.Data.Attributes.IsEmailVerified {
|
||||
user.Email = extracted.Data.Attributes.Email
|
||||
}
|
||||
|
||||
return user, nil
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
@@ -22,6 +23,7 @@ type Yandex struct {
|
||||
// Docs: https://yandex.ru/dev/id/doc/en/
|
||||
func NewYandexProvider() *Yandex {
|
||||
return &Yandex{&baseProvider{
|
||||
ctx: context.Background(),
|
||||
scopes: []string{"login:email", "login:avatar", "login:info"},
|
||||
authUrl: yandex.Endpoint.AuthURL,
|
||||
tokenUrl: yandex.Endpoint.TokenURL,
|
||||
|
||||
+24
-3
@@ -62,20 +62,41 @@ func (s *Schedule) IsDue(m *Moment) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
var macros = map[string]string{
|
||||
"@yearly": "0 0 1 1 *",
|
||||
"@annually": "0 0 1 1 *",
|
||||
"@monthly": "0 0 1 * *",
|
||||
"@weekly": "0 0 * * 0",
|
||||
"@daily": "0 0 * * *",
|
||||
"@midnight": "0 0 * * *",
|
||||
"@hourly": "0 * * * *",
|
||||
}
|
||||
|
||||
// NewSchedule creates a new Schedule from a cron expression.
|
||||
//
|
||||
// A cron expression is consisted of 5 segments separated by space,
|
||||
// A cron expression could be a macro OR 5 segments separated by space,
|
||||
// representing: minute, hour, day of the month, month and day of the week.
|
||||
//
|
||||
// Each segment could be in the following formats:
|
||||
// The following segment formats are supported:
|
||||
// - wildcard: *
|
||||
// - range: 1-30
|
||||
// - step: */n or 1-30/n
|
||||
// - list: 1,2,3,10-20/n
|
||||
//
|
||||
// The following macros are supported:
|
||||
// - @yearly (or @annually)
|
||||
// - @monthly
|
||||
// - @weekly
|
||||
// - @daily (or @midnight)
|
||||
// - @hourly
|
||||
func NewSchedule(cronExpr string) (*Schedule, error) {
|
||||
if v, ok := macros[cronExpr]; ok {
|
||||
cronExpr = v
|
||||
}
|
||||
|
||||
segments := strings.Split(cronExpr, " ")
|
||||
if len(segments) != 5 {
|
||||
return nil, errors.New("invalid cron expression - must have exactly 5 space separated segments")
|
||||
return nil, errors.New("invalid cron expression - must be a valid macro or to have exactly 5 space separated segments")
|
||||
}
|
||||
|
||||
minutes, err := parseCronSegment(segments[0], 0, 59)
|
||||
|
||||
@@ -208,6 +208,43 @@ func TestNewSchedule(t *testing.T) {
|
||||
false,
|
||||
`{"minutes":{"0":{},"1":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{},"16":{},"17":{},"18":{},"19":{},"2":{},"20":{},"21":{},"22":{},"23":{},"24":{},"25":{},"26":{},"27":{},"28":{},"29":{},"3":{},"30":{},"31":{},"32":{},"33":{},"34":{},"35":{},"36":{},"37":{},"38":{},"39":{},"4":{},"40":{},"41":{},"42":{},"43":{},"44":{},"45":{},"46":{},"47":{},"48":{},"49":{},"5":{},"50":{},"51":{},"52":{},"53":{},"54":{},"55":{},"56":{},"57":{},"58":{},"59":{},"6":{},"7":{},"8":{},"9":{}},"hours":{"0":{},"1":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{},"16":{},"17":{},"18":{},"19":{},"2":{},"20":{},"21":{},"22":{},"23":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"days":{"1":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{},"16":{},"17":{},"18":{},"19":{},"2":{},"20":{},"21":{},"22":{},"23":{},"24":{},"25":{},"26":{},"27":{},"28":{},"29":{},"3":{},"30":{},"31":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"months":{"1":{},"10":{},"11":{},"12":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"daysOfWeek":{"1":{},"2":{},"4":{}}}`,
|
||||
},
|
||||
|
||||
// macros
|
||||
{
|
||||
"@yearly",
|
||||
false,
|
||||
`{"minutes":{"0":{}},"hours":{"0":{}},"days":{"1":{}},"months":{"1":{}},"daysOfWeek":{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{}}}`,
|
||||
},
|
||||
{
|
||||
"@annually",
|
||||
false,
|
||||
`{"minutes":{"0":{}},"hours":{"0":{}},"days":{"1":{}},"months":{"1":{}},"daysOfWeek":{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{}}}`,
|
||||
},
|
||||
{
|
||||
"@monthly",
|
||||
false,
|
||||
`{"minutes":{"0":{}},"hours":{"0":{}},"days":{"1":{}},"months":{"1":{},"10":{},"11":{},"12":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"daysOfWeek":{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{}}}`,
|
||||
},
|
||||
{
|
||||
"@weekly",
|
||||
false,
|
||||
`{"minutes":{"0":{}},"hours":{"0":{}},"days":{"1":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{},"16":{},"17":{},"18":{},"19":{},"2":{},"20":{},"21":{},"22":{},"23":{},"24":{},"25":{},"26":{},"27":{},"28":{},"29":{},"3":{},"30":{},"31":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"months":{"1":{},"10":{},"11":{},"12":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"daysOfWeek":{"0":{}}}`,
|
||||
},
|
||||
{
|
||||
"@daily",
|
||||
false,
|
||||
`{"minutes":{"0":{}},"hours":{"0":{}},"days":{"1":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{},"16":{},"17":{},"18":{},"19":{},"2":{},"20":{},"21":{},"22":{},"23":{},"24":{},"25":{},"26":{},"27":{},"28":{},"29":{},"3":{},"30":{},"31":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"months":{"1":{},"10":{},"11":{},"12":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"daysOfWeek":{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{}}}`,
|
||||
},
|
||||
{
|
||||
"@midnight",
|
||||
false,
|
||||
`{"minutes":{"0":{}},"hours":{"0":{}},"days":{"1":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{},"16":{},"17":{},"18":{},"19":{},"2":{},"20":{},"21":{},"22":{},"23":{},"24":{},"25":{},"26":{},"27":{},"28":{},"29":{},"3":{},"30":{},"31":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"months":{"1":{},"10":{},"11":{},"12":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"daysOfWeek":{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{}}}`,
|
||||
},
|
||||
{
|
||||
"@hourly",
|
||||
false,
|
||||
`{"minutes":{"0":{}},"hours":{"0":{},"1":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{},"16":{},"17":{},"18":{},"19":{},"2":{},"20":{},"21":{},"22":{},"23":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"days":{"1":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{},"16":{},"17":{},"18":{},"19":{},"2":{},"20":{},"21":{},"22":{},"23":{},"24":{},"25":{},"26":{},"27":{},"28":{},"29":{},"3":{},"30":{},"31":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"months":{"1":{},"10":{},"11":{},"12":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}},"daysOfWeek":{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{}}}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
@@ -74,7 +75,9 @@ func NewLocal(dirPath string) (*System, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bucket, err := fileblob.OpenBucket(dirPath, nil)
|
||||
bucket, err := fileblob.OpenBucket(dirPath, &fileblob.Options{
|
||||
NoTempDir: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -273,7 +276,7 @@ func (s *System) DeletePrefix(prefix string) []error {
|
||||
if err := s.Delete(obj.Key); err != nil {
|
||||
failed = append(failed, err)
|
||||
} else {
|
||||
dirsMap[filepath.Dir(obj.Key)] = struct{}{}
|
||||
dirsMap[path.Dir(obj.Key)] = struct{}{}
|
||||
}
|
||||
}
|
||||
// ---
|
||||
|
||||
+19
-6
@@ -39,12 +39,21 @@ func NewSmtpClient(
|
||||
// SmtpClient defines a SMTP mail client structure that implements
|
||||
// `mailer.Mailer` interface.
|
||||
type SmtpClient struct {
|
||||
Host string
|
||||
Port int
|
||||
Username string
|
||||
Password string
|
||||
Tls bool
|
||||
AuthMethod string // default to "PLAIN"
|
||||
Host string
|
||||
Port int
|
||||
Username string
|
||||
Password string
|
||||
Tls bool
|
||||
|
||||
// SMTP auth method to use
|
||||
// (if not explicitly set, defaults to "PLAIN")
|
||||
AuthMethod string
|
||||
|
||||
// LocalName is optional domain name used for the EHLO/HELO exchange
|
||||
// (if not explicitly set, defaults to "localhost").
|
||||
//
|
||||
// This is required only by some SMTP servers, such as Gmail SMTP-relay.
|
||||
LocalName string
|
||||
}
|
||||
|
||||
// Send implements `mailer.Mailer` interface.
|
||||
@@ -71,6 +80,10 @@ func (c *SmtpClient) Send(m *Message) error {
|
||||
yak = mailyak.New(fmt.Sprintf("%s:%d", c.Host, c.Port), smtpAuth)
|
||||
}
|
||||
|
||||
if c.LocalName != "" {
|
||||
yak.LocalName(c.LocalName)
|
||||
}
|
||||
|
||||
if m.From.Name != "" {
|
||||
yak.FromName(m.From.Name)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/pocketbase/pocketbase/tools/list"
|
||||
"github.com/spf13/cast"
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
var whitespaceRegex = regexp.MustCompile(`\s+`)
|
||||
|
||||
var excludeTags = []string{
|
||||
"head", "style", "script", "iframe", "embed", "applet", "object",
|
||||
"svg", "img", "picture", "dialog", "template", "button", "form",
|
||||
"textarea", "input", "select", "option",
|
||||
}
|
||||
|
||||
var inlineTags = []string{
|
||||
"a", "abbr", "acronym", "b", "bdo", "big", "br", "button",
|
||||
"cite", "code", "em", "i", "label", "q", "small", "span",
|
||||
"strong", "strike", "sub", "sup", "time",
|
||||
}
|
||||
|
||||
var _ FieldModifier = (*excerptModifier)(nil)
|
||||
|
||||
type excerptModifier struct {
|
||||
max int // approximate max excerpt length
|
||||
withEllipsis bool // if enabled will add ellipsis when the plain text length > max
|
||||
}
|
||||
|
||||
// newExcerptModifier validates the specified raw string arguments and
|
||||
// initializes a new excerptModifier.
|
||||
//
|
||||
// This method is usually invoked in initModifer().
|
||||
func newExcerptModifier(args ...string) (*excerptModifier, error) {
|
||||
totalArgs := len(args)
|
||||
|
||||
if totalArgs == 0 {
|
||||
return nil, errors.New("max argument is required - expected (max, withEllipsis?)")
|
||||
}
|
||||
|
||||
if totalArgs > 2 {
|
||||
return nil, errors.New("too many arguments - expected (max, withEllipsis?)")
|
||||
}
|
||||
|
||||
max := cast.ToInt(args[0])
|
||||
if max == 0 {
|
||||
return nil, errors.New("max argument must be > 0")
|
||||
}
|
||||
|
||||
var withEllipsis bool
|
||||
if totalArgs > 1 {
|
||||
withEllipsis = cast.ToBool(args[1])
|
||||
}
|
||||
|
||||
return &excerptModifier{max, withEllipsis}, nil
|
||||
}
|
||||
|
||||
// Modify implements the [FieldModifier.Modify] interface method.
|
||||
//
|
||||
// It returns a plain text excerpt/short-description from a formatted
|
||||
// html string (non-string values are kept untouched).
|
||||
func (m *excerptModifier) Modify(value any) (any, error) {
|
||||
strValue, ok := value.(string)
|
||||
if !ok {
|
||||
// not a string -> return as it is without applying the modifier
|
||||
// (we don't throw an error because the modifier could be applied for a missing expand field)
|
||||
return value, nil
|
||||
}
|
||||
|
||||
var builder strings.Builder
|
||||
|
||||
doc, err := html.Parse(strings.NewReader(strValue))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var hasPrevSpace bool
|
||||
|
||||
// for all node types and more details check
|
||||
// https://pkg.go.dev/golang.org/x/net/html#Parse
|
||||
var stripTags func(*html.Node)
|
||||
stripTags = func(n *html.Node) {
|
||||
switch n.Type {
|
||||
case html.TextNode:
|
||||
// collapse multiple spaces into one
|
||||
txt := whitespaceRegex.ReplaceAllString(n.Data, " ")
|
||||
|
||||
if hasPrevSpace {
|
||||
txt = strings.TrimLeft(txt, " ")
|
||||
}
|
||||
|
||||
if txt != "" {
|
||||
hasPrevSpace = strings.HasSuffix(txt, " ")
|
||||
|
||||
builder.WriteString(txt)
|
||||
}
|
||||
}
|
||||
|
||||
// excerpt max has been reached => no need to further iterate
|
||||
// (+2 for the extra whitespace suffix/prefix that will be trimmed later)
|
||||
if builder.Len() > m.max+2 {
|
||||
return
|
||||
}
|
||||
|
||||
for c := n.FirstChild; c != nil; c = c.NextSibling {
|
||||
if c.Type != html.ElementNode || !list.ExistInSlice(c.Data, excludeTags) {
|
||||
isBlock := c.Type == html.ElementNode && !list.ExistInSlice(c.Data, inlineTags)
|
||||
|
||||
if isBlock && !hasPrevSpace {
|
||||
builder.WriteString(" ")
|
||||
hasPrevSpace = true
|
||||
}
|
||||
|
||||
stripTags(c)
|
||||
|
||||
if isBlock && !hasPrevSpace {
|
||||
builder.WriteString(" ")
|
||||
hasPrevSpace = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stripTags(doc)
|
||||
|
||||
result := strings.TrimSpace(builder.String())
|
||||
|
||||
if len(result) > m.max {
|
||||
result = strings.TrimSpace(result[:m.max])
|
||||
|
||||
if m.withEllipsis {
|
||||
result += "..."
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func TestNewExcerptModifier(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
"no arguments",
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"too many arguments",
|
||||
[]string{"12", "false", "something"},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"non-numeric max argument",
|
||||
[]string{"something"}, // should fallback to 0 which is not allowed
|
||||
true,
|
||||
},
|
||||
{
|
||||
"numeric max argument",
|
||||
[]string{"12"},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"non-bool withEllipsis argument",
|
||||
[]string{"12", "something"}, // should fallback to false which is allowed
|
||||
false,
|
||||
},
|
||||
{
|
||||
"truthy withEllipsis argument",
|
||||
[]string{"12", "t"},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
m, err := newExcerptModifier(s.args...)
|
||||
|
||||
hasErr := err != nil
|
||||
if hasErr != s.expectError {
|
||||
t.Fatalf("Expected hasErr %v, got %v (%v)", s.expectError, hasErr, err)
|
||||
}
|
||||
|
||||
if hasErr {
|
||||
if m != nil {
|
||||
t.Fatalf("Expected nil modifier, got %v", m)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var argMax int
|
||||
if len(s.args) > 0 {
|
||||
argMax = cast.ToInt(s.args[0])
|
||||
}
|
||||
|
||||
var argWithEllipsis bool
|
||||
if len(s.args) > 1 {
|
||||
argWithEllipsis = cast.ToBool(s.args[1])
|
||||
}
|
||||
|
||||
if m.max != argMax {
|
||||
t.Fatalf("Expected max %d, got %d", argMax, m.max)
|
||||
}
|
||||
|
||||
if m.withEllipsis != argWithEllipsis {
|
||||
t.Fatalf("Expected withEllipsis %v, got %v", argWithEllipsis, m.withEllipsis)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExcerptModifierModify(t *testing.T) {
|
||||
html := ` <script>var a = 123;</script> <p>Hello</p><div id="test_id">t est<b>12
|
||||
3</b><span>456</span></div><span>word <b>7</b> 89<span>!<b>?</b><b> a </b><b>b </b>c</span>#<h1>title</h1>`
|
||||
|
||||
plainText := "Hello t est12 3456 word 7 89!? a b c# title"
|
||||
|
||||
scenarios := []struct {
|
||||
name string
|
||||
args []string
|
||||
value string
|
||||
expected string
|
||||
}{
|
||||
// without ellipsis
|
||||
{
|
||||
"only max < len(plainText)",
|
||||
[]string{"2"},
|
||||
html,
|
||||
plainText[:2],
|
||||
},
|
||||
{
|
||||
"only max = len(plainText)",
|
||||
[]string{fmt.Sprint(len(plainText))},
|
||||
html,
|
||||
plainText,
|
||||
},
|
||||
{
|
||||
"only max > len(plainText)",
|
||||
[]string{fmt.Sprint(len(plainText) + 5)},
|
||||
html,
|
||||
plainText,
|
||||
},
|
||||
|
||||
// with ellipsis
|
||||
{
|
||||
"with ellipsis and max < len(plainText)",
|
||||
[]string{"2", "t"},
|
||||
html,
|
||||
plainText[:2] + "...",
|
||||
},
|
||||
{
|
||||
"with ellipsis and max = len(plainText)",
|
||||
[]string{fmt.Sprint(len(plainText)), "t"},
|
||||
html,
|
||||
plainText,
|
||||
},
|
||||
{
|
||||
"with ellipsis and max > len(plainText)",
|
||||
[]string{fmt.Sprint(len(plainText) + 5), "t"},
|
||||
html,
|
||||
plainText,
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
m, err := newExcerptModifier(s.args...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
raw, err := m.Modify(s.value)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if v := cast.ToString(raw); v != s.expected {
|
||||
t.Fatalf("Expected %q, got %q", s.expected, v)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+149
-28
@@ -2,12 +2,22 @@ package rest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
// experimental! (need more tests before replacing encoding/json entirely)
|
||||
goccy "github.com/goccy/go-json"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
"github.com/pocketbase/pocketbase/tools/search"
|
||||
"github.com/pocketbase/pocketbase/tools/tokenizer"
|
||||
)
|
||||
|
||||
type FieldModifier interface {
|
||||
// Modify executes the modifier and returns a new modified value.
|
||||
Modify(value any) (any, error)
|
||||
}
|
||||
|
||||
// Serializer represents custom REST JSON serializer based on echo.DefaultJSONSerializer,
|
||||
// with support for additional generic response data transformation (eg. fields picker).
|
||||
type Serializer struct {
|
||||
@@ -19,35 +29,45 @@ type Serializer struct {
|
||||
// Serialize converts an interface into a json and writes it to the response.
|
||||
//
|
||||
// It also provides a generic response data fields picker via the FieldsParam query parameter (default to "fields").
|
||||
//
|
||||
// Note: for the places where it is safe, the std encoding/json is replaced
|
||||
// with goccy due to its slightly better Unmarshal/Marshal performance.
|
||||
func (s *Serializer) Serialize(c echo.Context, i any, indent string) error {
|
||||
fieldsParam := s.FieldsParam
|
||||
if fieldsParam == "" {
|
||||
fieldsParam = "fields"
|
||||
}
|
||||
|
||||
param := c.QueryParam(fieldsParam)
|
||||
if param == "" {
|
||||
statusCode := c.Response().Status
|
||||
|
||||
rawFields := c.QueryParam(fieldsParam)
|
||||
if rawFields == "" || statusCode < 200 || statusCode > 299 {
|
||||
return s.DefaultJSONSerializer.Serialize(c, i, indent)
|
||||
}
|
||||
|
||||
fields := strings.Split(param, ",")
|
||||
for i, f := range fields {
|
||||
fields[i] = strings.TrimSpace(f)
|
||||
parsedFields, err := parseFields(rawFields)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
encoded, err := json.Marshal(i)
|
||||
// marshalize the provided data to ensure that the related json.Marshaler
|
||||
// implementations are invoked, and then convert it back to a plain
|
||||
// json value that we can further operate on.
|
||||
//
|
||||
// @todo research other approaches to avoid the double serialization
|
||||
// ---
|
||||
encoded, err := json.Marshal(i) // use the std json since goccy has several bugs reported with struct marshaling and it is not safe
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var decoded any
|
||||
|
||||
if err := json.Unmarshal(encoded, &decoded); err != nil {
|
||||
if err := goccy.Unmarshal(encoded, &decoded); err != nil {
|
||||
return err
|
||||
}
|
||||
// ---
|
||||
|
||||
var isSearchResult bool
|
||||
|
||||
switch i.(type) {
|
||||
case search.Result, *search.Result:
|
||||
isSearchResult = true
|
||||
@@ -55,49 +75,134 @@ func (s *Serializer) Serialize(c echo.Context, i any, indent string) error {
|
||||
|
||||
if isSearchResult {
|
||||
if decodedMap, ok := decoded.(map[string]any); ok {
|
||||
pickFields(decodedMap["items"], fields)
|
||||
pickFields(decodedMap["items"], parsedFields)
|
||||
}
|
||||
} else {
|
||||
pickFields(decoded, fields)
|
||||
pickFields(decoded, parsedFields)
|
||||
}
|
||||
|
||||
return s.DefaultJSONSerializer.Serialize(c, decoded, indent)
|
||||
enc := goccy.NewEncoder(c.Response())
|
||||
if indent != "" {
|
||||
enc.SetIndent("", indent)
|
||||
}
|
||||
|
||||
return enc.Encode(decoded)
|
||||
}
|
||||
|
||||
func pickFields(data any, fields []string) {
|
||||
func parseFields(rawFields string) (map[string]FieldModifier, error) {
|
||||
t := tokenizer.NewFromString(rawFields)
|
||||
|
||||
fields, err := t.ScanAll()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(map[string]FieldModifier, len(fields))
|
||||
|
||||
for _, f := range fields {
|
||||
parts := strings.SplitN(strings.TrimSpace(f), ":", 2)
|
||||
|
||||
if len(parts) > 1 {
|
||||
m, err := initModifer(parts[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result[parts[0]] = m
|
||||
} else {
|
||||
result[parts[0]] = nil
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func initModifer(rawModifier string) (FieldModifier, error) {
|
||||
t := tokenizer.NewFromString(rawModifier)
|
||||
t.Separators('(', ')', ',', ' ')
|
||||
t.IgnoreParenthesis(true)
|
||||
|
||||
parts, err := t.ScanAll()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(parts) == 0 {
|
||||
return nil, fmt.Errorf("invalid or empty modifier expression %q", rawModifier)
|
||||
}
|
||||
|
||||
name := parts[0]
|
||||
args := parts[1:]
|
||||
|
||||
switch name {
|
||||
case "excerpt":
|
||||
m, err := newExcerptModifier(args...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid excerpt modifier: %w", err)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("missing or invalid modifier %q", name)
|
||||
}
|
||||
|
||||
func pickFields(data any, fields map[string]FieldModifier) error {
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
pickMapFields(v, fields)
|
||||
case []map[string]any:
|
||||
for _, item := range v {
|
||||
pickMapFields(item, fields)
|
||||
if err := pickMapFields(item, fields); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case []any:
|
||||
if len(v) == 0 {
|
||||
return // nothing to pick
|
||||
return nil // nothing to pick
|
||||
}
|
||||
|
||||
if _, ok := v[0].(map[string]any); !ok {
|
||||
return // for now ignore non-map values
|
||||
return nil // for now ignore non-map values
|
||||
}
|
||||
|
||||
for _, item := range v {
|
||||
pickMapFields(item.(map[string]any), fields)
|
||||
if err := pickMapFields(item.(map[string]any), fields); err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func pickMapFields(data map[string]any, fields []string) {
|
||||
func pickMapFields(data map[string]any, fields map[string]FieldModifier) error {
|
||||
if len(fields) == 0 {
|
||||
return // nothing to pick
|
||||
return nil // nothing to pick
|
||||
}
|
||||
|
||||
if m, ok := fields["*"]; ok {
|
||||
// append all missing root level data keys
|
||||
for k := range data {
|
||||
var exists bool
|
||||
|
||||
for f := range fields {
|
||||
if strings.HasPrefix(f+".", k+".") {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !exists {
|
||||
fields[k] = m
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DataLoop:
|
||||
for k := range data {
|
||||
matchingFields := make([]string, 0, len(fields))
|
||||
for _, f := range fields {
|
||||
matchingFields := make(map[string]FieldModifier, len(fields))
|
||||
for f, m := range fields {
|
||||
if strings.HasPrefix(f+".", k+".") {
|
||||
matchingFields = append(matchingFields, f)
|
||||
matchingFields[f] = m
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -107,15 +212,31 @@ DataLoop:
|
||||
continue DataLoop
|
||||
}
|
||||
|
||||
// trim the key from the fields
|
||||
for i, v := range matchingFields {
|
||||
trimmed := strings.TrimSuffix(strings.TrimPrefix(v+".", k+"."), ".")
|
||||
if trimmed == "" {
|
||||
// remove the current key from the matching fields path
|
||||
for f, m := range matchingFields {
|
||||
remains := strings.TrimSuffix(strings.TrimPrefix(f+".", k+"."), ".")
|
||||
|
||||
// final key
|
||||
if remains == "" {
|
||||
if m != nil {
|
||||
var err error
|
||||
data[k], err = m.Modify(data[k])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
continue DataLoop
|
||||
}
|
||||
matchingFields[i] = trimmed
|
||||
|
||||
// cleanup the old field key and continue with the rest of the field path
|
||||
delete(matchingFields, f)
|
||||
matchingFields[remains] = m
|
||||
}
|
||||
|
||||
pickFields(data[k], matchingFields)
|
||||
if err := pickFields(data[k], matchingFields); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestSerialize(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
name string
|
||||
serializer rest.Serializer
|
||||
statusCode int
|
||||
data any
|
||||
query string
|
||||
expected string
|
||||
@@ -23,6 +24,7 @@ func TestSerialize(t *testing.T) {
|
||||
{
|
||||
"empty query",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
map[string]any{"a": 1, "b": 2, "c": "test"},
|
||||
"",
|
||||
`{"a":1,"b":2,"c":"test"}`,
|
||||
@@ -30,6 +32,7 @@ func TestSerialize(t *testing.T) {
|
||||
{
|
||||
"empty fields",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
map[string]any{"a": 1, "b": 2, "c": "test"},
|
||||
"fields=",
|
||||
`{"a":1,"b":2,"c":"test"}`,
|
||||
@@ -37,6 +40,7 @@ func TestSerialize(t *testing.T) {
|
||||
{
|
||||
"missing fields",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
map[string]any{"a": 1, "b": 2, "c": "test"},
|
||||
"fields=missing",
|
||||
`{}`,
|
||||
@@ -44,6 +48,7 @@ func TestSerialize(t *testing.T) {
|
||||
{
|
||||
"non map response",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
"test",
|
||||
"fields=a,b,test",
|
||||
`"test"`,
|
||||
@@ -51,13 +56,39 @@ func TestSerialize(t *testing.T) {
|
||||
{
|
||||
"non slice of map response",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
[]any{"a", "b", "test"},
|
||||
"fields=a,test",
|
||||
`["a","b","test"]`,
|
||||
},
|
||||
{
|
||||
"map with no matching field",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
map[string]any{"a": 1, "b": 2, "c": "test"},
|
||||
"fields=missing", // test individual fields trim
|
||||
`{}`,
|
||||
},
|
||||
{
|
||||
">299 response",
|
||||
rest.Serializer{},
|
||||
300,
|
||||
map[string]any{"a": 1, "b": 2, "c": "test"},
|
||||
"fields=missing",
|
||||
`{"a":1,"b":2,"c":"test"}`,
|
||||
},
|
||||
{
|
||||
"<200 response",
|
||||
rest.Serializer{},
|
||||
199,
|
||||
map[string]any{"a": 1, "b": 2, "c": "test"},
|
||||
"fields=missing",
|
||||
`{"a":1,"b":2,"c":"test"}`,
|
||||
},
|
||||
{
|
||||
"map with existing and missing fields",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
map[string]any{"a": 1, "b": 2, "c": "test"},
|
||||
"fields=a, c ,missing", // test individual fields trim
|
||||
`{"a":1,"c":"test"}`,
|
||||
@@ -65,6 +96,7 @@ func TestSerialize(t *testing.T) {
|
||||
{
|
||||
"custom fields param",
|
||||
rest.Serializer{FieldsParam: "custom"},
|
||||
200,
|
||||
map[string]any{"a": 1, "b": 2, "c": "test"},
|
||||
"custom=a, c ,missing", // test individual fields trim
|
||||
`{"a":1,"c":"test"}`,
|
||||
@@ -72,6 +104,7 @@ func TestSerialize(t *testing.T) {
|
||||
{
|
||||
"slice of maps with existing and missing fields",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
[]any{
|
||||
map[string]any{"a": 11, "b": 11, "c": "test1"},
|
||||
map[string]any{"a": 22, "b": 22, "c": "test2"},
|
||||
@@ -82,6 +115,7 @@ func TestSerialize(t *testing.T) {
|
||||
{
|
||||
"nested fields with mixed map and any slices",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
map[string]any{
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
@@ -139,6 +173,7 @@ func TestSerialize(t *testing.T) {
|
||||
{
|
||||
"SearchResult",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
search.Result{
|
||||
Page: 1,
|
||||
PerPage: 10,
|
||||
@@ -155,6 +190,7 @@ func TestSerialize(t *testing.T) {
|
||||
{
|
||||
"*SearchResult",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
&search.Result{
|
||||
Page: 1,
|
||||
PerPage: 10,
|
||||
@@ -168,28 +204,127 @@ func TestSerialize(t *testing.T) {
|
||||
"fields=a,c",
|
||||
`{"items":[{"a":11,"c":"test1"},{"a":22,"c":"test2"}],"page":1,"perPage":10,"totalItems":20,"totalPages":30}`,
|
||||
},
|
||||
{
|
||||
"root wildcard",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
&search.Result{
|
||||
Page: 1,
|
||||
PerPage: 10,
|
||||
TotalItems: 20,
|
||||
TotalPages: 30,
|
||||
Items: []any{
|
||||
map[string]any{"a": 11, "b": 11, "c": "test1"},
|
||||
map[string]any{"a": 22, "b": 22, "c": "test2"},
|
||||
},
|
||||
},
|
||||
"fields=*",
|
||||
`{"items":[{"a":11,"b":11,"c":"test1"},{"a":22,"b":22,"c":"test2"}],"page":1,"perPage":10,"totalItems":20,"totalPages":30}`,
|
||||
},
|
||||
{
|
||||
"root wildcard with nested exception",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
map[string]any{
|
||||
"id": "123",
|
||||
"title": "lorem",
|
||||
"rel": map[string]any{
|
||||
"id": "456",
|
||||
"title": "rel_title",
|
||||
},
|
||||
},
|
||||
"fields=*,rel.id",
|
||||
`{"id":"123","rel":{"id":"456"},"title":"lorem"}`,
|
||||
},
|
||||
{
|
||||
"sub wildcard",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
map[string]any{
|
||||
"id": "123",
|
||||
"title": "lorem",
|
||||
"rel": map[string]any{
|
||||
"id": "456",
|
||||
"title": "rel_title",
|
||||
"sub": map[string]any{
|
||||
"id": "789",
|
||||
"title": "sub_title",
|
||||
},
|
||||
},
|
||||
},
|
||||
"fields=id,rel.*",
|
||||
`{"id":"123","rel":{"id":"456","sub":{"id":"789","title":"sub_title"},"title":"rel_title"}}`,
|
||||
},
|
||||
{
|
||||
"sub wildcard with nested exception",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
map[string]any{
|
||||
"id": "123",
|
||||
"title": "lorem",
|
||||
"rel": map[string]any{
|
||||
"id": "456",
|
||||
"title": "rel_title",
|
||||
"sub": map[string]any{
|
||||
"id": "789",
|
||||
"title": "sub_title",
|
||||
},
|
||||
},
|
||||
},
|
||||
"fields=id,rel.*,rel.sub.id",
|
||||
`{"id":"123","rel":{"id":"456","sub":{"id":"789"},"title":"rel_title"}}`,
|
||||
},
|
||||
{
|
||||
"invalid excerpt modifier",
|
||||
rest.Serializer{},
|
||||
400,
|
||||
map[string]any{"a": 1, "b": 2, "c": "test"},
|
||||
"fields=*:excerpt",
|
||||
`{"a":1,"b":2,"c":"test"}`,
|
||||
},
|
||||
{
|
||||
"valid excerpt modifier",
|
||||
rest.Serializer{},
|
||||
200,
|
||||
map[string]any{
|
||||
"id": "123",
|
||||
"title": "lorem",
|
||||
"rel": map[string]any{
|
||||
"id": "456",
|
||||
"title": "<p>rel_title</p>",
|
||||
"sub": map[string]any{
|
||||
"id": "789",
|
||||
"title": "sub_title",
|
||||
},
|
||||
},
|
||||
},
|
||||
"fields=*:excerpt(2),rel.title:excerpt(3, true)",
|
||||
`{"id":"12","rel":{"title":"rel..."},"title":"lo"}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
e := echo.New()
|
||||
req := httptest.NewRequest(http.MethodPost, "/", nil)
|
||||
req.URL.RawQuery = s.query
|
||||
rec := httptest.NewRecorder()
|
||||
c := e.NewContext(req, rec)
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodPost, "/", nil)
|
||||
req.URL.RawQuery = s.query
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
if err := s.serializer.Serialize(c, s.data, ""); err != nil {
|
||||
t.Errorf("[%s] Serialize failure: %v", s.name, err)
|
||||
continue
|
||||
}
|
||||
e := echo.New()
|
||||
c := e.NewContext(req, rec)
|
||||
c.Response().Status = s.statusCode
|
||||
|
||||
rawBody, err := io.ReadAll(rec.Result().Body)
|
||||
if err != nil {
|
||||
t.Errorf("[%s] Failed to read request body: %v", s.name, err)
|
||||
continue
|
||||
}
|
||||
if err := s.serializer.Serialize(c, s.data, ""); err != nil {
|
||||
t.Fatalf("Serialize failure: %v", err)
|
||||
}
|
||||
|
||||
if v := strings.TrimSpace(string(rawBody)); v != s.expected {
|
||||
t.Fatalf("[%s] Expected body\n%v \ngot: \n%v", s.name, s.expected, v)
|
||||
}
|
||||
rawBody, err := io.ReadAll(rec.Result().Body)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to read request body: %v", err)
|
||||
}
|
||||
|
||||
if v := strings.TrimSpace(string(rawBody)); v != s.expected {
|
||||
t.Fatalf("Expected body\n%v \ngot: \n%v", s.expected, v)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
//
|
||||
// This is similar to `echo.BindBody()`, but for JSON requests uses
|
||||
// custom json reader that **copies** the request body, allowing multiple reads.
|
||||
func BindBody(c echo.Context, i interface{}) error {
|
||||
func BindBody(c echo.Context, i any) error {
|
||||
req := c.Request()
|
||||
if req.ContentLength == 0 {
|
||||
return nil
|
||||
@@ -40,7 +40,7 @@ func BindBody(c echo.Context, i interface{}) error {
|
||||
|
||||
// CopyJsonBody reads the request body into i by
|
||||
// creating a copy of `r.Body` to allow multiple reads.
|
||||
func CopyJsonBody(r *http.Request, i interface{}) error {
|
||||
func CopyJsonBody(r *http.Request, i any) error {
|
||||
body := r.Body
|
||||
|
||||
// this usually shouldn't be needed because the Server calls close for us
|
||||
@@ -66,7 +66,7 @@ func CopyJsonBody(r *http.Request, i interface{}) error {
|
||||
// when a map destination is used.
|
||||
//
|
||||
// It should be replaced with echo.BindBody(c, i) once the issue is fixed in echo.
|
||||
func bindFormData(c echo.Context, i interface{}) error {
|
||||
func bindFormData(c echo.Context, i any) error {
|
||||
if i == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
+59
-19
@@ -1,25 +1,29 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/ganigeorgiev/fexpr"
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/tools/security"
|
||||
"github.com/pocketbase/pocketbase/tools/store"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// FilterData is a filter expression string following the `fexpr` package grammar.
|
||||
//
|
||||
// The filter string can also contain dbx placeholder parameters (eg. "title = {:name}"),
|
||||
// that will be safely replaced and properly quoted inplace with the placeholderReplacements values.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var filter FilterData = "id = null || (name = 'test' && status = true)"
|
||||
// var filter FilterData = "id = null || (name = 'test' && status = true) || (total >= {:min} && total <= {:max})"
|
||||
// resolver := search.NewSimpleFieldResolver("id", "name", "status")
|
||||
// expr, err := filter.BuildExpr(resolver)
|
||||
// expr, err := filter.BuildExpr(resolver, dbx.Params{"min": 100, "max": 200})
|
||||
type FilterData string
|
||||
|
||||
// parsedFilterData holds a cache with previously parsed filter data expressions
|
||||
@@ -27,10 +31,41 @@ type FilterData string
|
||||
var parsedFilterData = store.New(make(map[string][]fexpr.ExprGroup, 50))
|
||||
|
||||
// BuildExpr parses the current filter data and returns a new db WHERE expression.
|
||||
func (f FilterData) BuildExpr(fieldResolver FieldResolver) (dbx.Expression, error) {
|
||||
//
|
||||
// The filter string can also contain dbx placeholder parameters (eg. "title = {:name}"),
|
||||
// that will be safely replaced and properly quoted inplace with the placeholderReplacements values.
|
||||
func (f FilterData) BuildExpr(
|
||||
fieldResolver FieldResolver,
|
||||
placeholderReplacements ...dbx.Params,
|
||||
) (dbx.Expression, error) {
|
||||
raw := string(f)
|
||||
|
||||
// replace the placeholder params in the raw string filter
|
||||
for _, p := range placeholderReplacements {
|
||||
for key, value := range p {
|
||||
var replacement string
|
||||
switch v := value.(type) {
|
||||
case nil:
|
||||
replacement = "null"
|
||||
case bool, float64, float32, int, int64, int32, int16, int8, uint, uint64, uint32, uint16, uint8:
|
||||
replacement = cast.ToString(v)
|
||||
default:
|
||||
replacement = cast.ToString(v)
|
||||
|
||||
// try to json serialize as fallback
|
||||
if replacement == "" {
|
||||
raw, _ := json.Marshal(v)
|
||||
replacement = string(raw)
|
||||
}
|
||||
|
||||
replacement = strconv.Quote(replacement)
|
||||
}
|
||||
raw = strings.ReplaceAll(raw, "{:"+key+"}", replacement)
|
||||
}
|
||||
}
|
||||
|
||||
if parsedFilterData.Has(raw) {
|
||||
return f.build(parsedFilterData.Get(raw), fieldResolver)
|
||||
return buildParsedFilterExpr(parsedFilterData.Get(raw), fieldResolver)
|
||||
}
|
||||
data, err := fexpr.Parse(raw)
|
||||
if err != nil {
|
||||
@@ -39,10 +74,10 @@ func (f FilterData) BuildExpr(fieldResolver FieldResolver) (dbx.Expression, erro
|
||||
// store in cache
|
||||
// (the limit size is arbitrary and it is there to prevent the cache growing too big)
|
||||
parsedFilterData.SetIfLessThanLimit(raw, data, 500)
|
||||
return f.build(data, fieldResolver)
|
||||
return buildParsedFilterExpr(data, fieldResolver)
|
||||
}
|
||||
|
||||
func (f FilterData) build(data []fexpr.ExprGroup, fieldResolver FieldResolver) (dbx.Expression, error) {
|
||||
func buildParsedFilterExpr(data []fexpr.ExprGroup, fieldResolver FieldResolver) (dbx.Expression, error) {
|
||||
if len(data) == 0 {
|
||||
return nil, errors.New("empty filter expression")
|
||||
}
|
||||
@@ -55,11 +90,11 @@ func (f FilterData) build(data []fexpr.ExprGroup, fieldResolver FieldResolver) (
|
||||
|
||||
switch item := group.Item.(type) {
|
||||
case fexpr.Expr:
|
||||
expr, exprErr = f.resolveTokenizedExpr(item, fieldResolver)
|
||||
expr, exprErr = resolveTokenizedExpr(item, fieldResolver)
|
||||
case fexpr.ExprGroup:
|
||||
expr, exprErr = f.build([]fexpr.ExprGroup{item}, fieldResolver)
|
||||
expr, exprErr = buildParsedFilterExpr([]fexpr.ExprGroup{item}, fieldResolver)
|
||||
case []fexpr.ExprGroup:
|
||||
expr, exprErr = f.build(item, fieldResolver)
|
||||
expr, exprErr = buildParsedFilterExpr(item, fieldResolver)
|
||||
default:
|
||||
exprErr = errors.New("unsupported expression item")
|
||||
}
|
||||
@@ -84,7 +119,7 @@ func (f FilterData) build(data []fexpr.ExprGroup, fieldResolver FieldResolver) (
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (f FilterData) resolveTokenizedExpr(expr fexpr.Expr, fieldResolver FieldResolver) (dbx.Expression, error) {
|
||||
func resolveTokenizedExpr(expr fexpr.Expr, fieldResolver FieldResolver) (dbx.Expression, error) {
|
||||
lResult, lErr := resolveToken(expr.Left, fieldResolver)
|
||||
if lErr != nil || lResult.Identifier == "" {
|
||||
return nil, fmt.Errorf("invalid left operand %q - %v", expr.Left.Literal, lErr)
|
||||
@@ -95,10 +130,10 @@ func (f FilterData) resolveTokenizedExpr(expr fexpr.Expr, fieldResolver FieldRes
|
||||
return nil, fmt.Errorf("invalid right operand %q - %v", expr.Right.Literal, rErr)
|
||||
}
|
||||
|
||||
return buildExpr(lResult, expr.Op, rResult)
|
||||
return buildResolversExpr(lResult, expr.Op, rResult)
|
||||
}
|
||||
|
||||
func buildExpr(
|
||||
func buildResolversExpr(
|
||||
left *ResolverResult,
|
||||
op fexpr.SignOp,
|
||||
right *ResolverResult,
|
||||
@@ -182,14 +217,19 @@ func buildExpr(
|
||||
func resolveToken(token fexpr.Token, fieldResolver FieldResolver) (*ResolverResult, error) {
|
||||
switch token.Type {
|
||||
case fexpr.TokenIdentifier:
|
||||
// current datetime constant
|
||||
// check for macros
|
||||
// ---
|
||||
if token.Literal == "@now" {
|
||||
if macroFunc, ok := identifierMacros[token.Literal]; ok {
|
||||
placeholder := "t" + security.PseudorandomString(5)
|
||||
|
||||
macroValue, err := macroFunc()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ResolverResult{
|
||||
Identifier: "{:" + placeholder + "}",
|
||||
Params: dbx.Params{placeholder: types.NowDateTime().String()},
|
||||
Params: dbx.Params{placeholder: macroValue},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -469,7 +509,7 @@ func (e *manyVsManyExpr) Build(db *dbx.DB, params dbx.Params) string {
|
||||
lAlias := "__ml" + security.PseudorandomString(5)
|
||||
rAlias := "__mr" + security.PseudorandomString(5)
|
||||
|
||||
whereExpr, buildErr := buildExpr(
|
||||
whereExpr, buildErr := buildResolversExpr(
|
||||
&ResolverResult{
|
||||
Identifier: "[[" + lAlias + ".multiMatchValue]]",
|
||||
},
|
||||
@@ -536,9 +576,9 @@ func (e *manyVsOneExpr) Build(db *dbx.DB, params dbx.Params) string {
|
||||
var buildErr error
|
||||
|
||||
if e.inverse {
|
||||
whereExpr, buildErr = buildExpr(r2, e.op, r1)
|
||||
whereExpr, buildErr = buildResolversExpr(r2, e.op, r1)
|
||||
} else {
|
||||
whereExpr, buildErr = buildExpr(r1, e.op, r2)
|
||||
whereExpr, buildErr = buildResolversExpr(r1, e.op, r2)
|
||||
}
|
||||
|
||||
if buildErr != nil {
|
||||
|
||||
+128
-86
@@ -1,15 +1,19 @@
|
||||
package search_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/tools/search"
|
||||
)
|
||||
|
||||
func TestFilterDataBuildExpr(t *testing.T) {
|
||||
resolver := search.NewSimpleFieldResolver("test1", "test2", "test3", "test4.sub")
|
||||
resolver := search.NewSimpleFieldResolver("test1", "test2", "test3", `^test4.\w+$`)
|
||||
|
||||
scenarios := []struct {
|
||||
name string
|
||||
@@ -25,7 +29,10 @@ func TestFilterDataBuildExpr(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid format",
|
||||
"(test1 > 1", true, ""},
|
||||
"(test1 > 1",
|
||||
true,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"invalid operator",
|
||||
"test1 + 123",
|
||||
@@ -42,11 +49,7 @@ func TestFilterDataBuildExpr(t *testing.T) {
|
||||
"simple expression",
|
||||
"test1 > 1",
|
||||
false,
|
||||
"^" +
|
||||
regexp.QuoteMeta("[[test1]] > {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("}") +
|
||||
"$",
|
||||
"[[test1]] > {:TEST}",
|
||||
},
|
||||
{
|
||||
"empty string vs null",
|
||||
@@ -58,135 +61,174 @@ func TestFilterDataBuildExpr(t *testing.T) {
|
||||
"like with 2 columns",
|
||||
"test1 ~ test2",
|
||||
false,
|
||||
"^" +
|
||||
regexp.QuoteMeta("[[test1]] LIKE ('%' || [[test2]] || '%') ESCAPE '\\'") +
|
||||
"$",
|
||||
"[[test1]] LIKE ('%' || [[test2]] || '%') ESCAPE '\\'",
|
||||
},
|
||||
{
|
||||
"like with right column operand",
|
||||
"'lorem' ~ test1",
|
||||
false,
|
||||
"^" +
|
||||
regexp.QuoteMeta("{:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} LIKE ('%' || [[test1]] || '%') ESCAPE '\\'") +
|
||||
"$",
|
||||
"{:TEST} LIKE ('%' || [[test1]] || '%') ESCAPE '\\'",
|
||||
},
|
||||
{
|
||||
"like with left column operand and text as right operand",
|
||||
"test1 ~ 'lorem'",
|
||||
false,
|
||||
"^" +
|
||||
regexp.QuoteMeta("[[test1]] LIKE {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} ESCAPE '\\'") +
|
||||
"$",
|
||||
"[[test1]] LIKE {:TEST} ESCAPE '\\'",
|
||||
},
|
||||
{
|
||||
"not like with 2 columns",
|
||||
"test1 !~ test2",
|
||||
false,
|
||||
"^" +
|
||||
regexp.QuoteMeta("[[test1]] NOT LIKE ('%' || [[test2]] || '%') ESCAPE '\\'") +
|
||||
"$",
|
||||
"[[test1]] NOT LIKE ('%' || [[test2]] || '%') ESCAPE '\\'",
|
||||
},
|
||||
{
|
||||
"not like with right column operand",
|
||||
"'lorem' !~ test1",
|
||||
false,
|
||||
"^" +
|
||||
regexp.QuoteMeta("{:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} NOT LIKE ('%' || [[test1]] || '%') ESCAPE '\\'") +
|
||||
"$",
|
||||
"{:TEST} NOT LIKE ('%' || [[test1]] || '%') ESCAPE '\\'",
|
||||
},
|
||||
{
|
||||
"like with left column operand and text as right operand",
|
||||
"test1 !~ 'lorem'",
|
||||
false,
|
||||
"^" +
|
||||
regexp.QuoteMeta("[[test1]] NOT LIKE {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} ESCAPE '\\'") +
|
||||
"$",
|
||||
"[[test1]] NOT LIKE {:TEST} ESCAPE '\\'",
|
||||
},
|
||||
{
|
||||
"current datetime constant",
|
||||
"test1 > @now",
|
||||
"macros",
|
||||
`
|
||||
test4.1 > @now &&
|
||||
test4.2 > @second &&
|
||||
test4.3 > @minute &&
|
||||
test4.4 > @hour &&
|
||||
test4.5 > @day &&
|
||||
test4.6 > @year &&
|
||||
test4.7 > @month &&
|
||||
test4.9 > @weekday &&
|
||||
test4.9 > @todayStart &&
|
||||
test4.10 > @todayEnd &&
|
||||
test4.11 > @monthStart &&
|
||||
test4.12 > @monthEnd &&
|
||||
test4.13 > @yearStart &&
|
||||
test4.14 > @yearEnd
|
||||
`,
|
||||
false,
|
||||
"^" +
|
||||
regexp.QuoteMeta("[[test1]] > {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("}") +
|
||||
"$",
|
||||
"([[test4.1]] > {:TEST} AND [[test4.2]] > {:TEST} AND [[test4.3]] > {:TEST} AND [[test4.4]] > {:TEST} AND [[test4.5]] > {:TEST} AND [[test4.6]] > {:TEST} AND [[test4.7]] > {:TEST} AND [[test4.9]] > {:TEST} AND [[test4.9]] > {:TEST} AND [[test4.10]] > {:TEST} AND [[test4.11]] > {:TEST} AND [[test4.12]] > {:TEST} AND [[test4.13]] > {:TEST} AND [[test4.14]] > {:TEST})",
|
||||
},
|
||||
{
|
||||
"complex expression",
|
||||
"((test1 > 1) || (test2 != 2)) && test3 ~ '%%example' && test4.sub = null",
|
||||
false,
|
||||
"^" +
|
||||
regexp.QuoteMeta("(([[test1]] > {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} OR [[test2]] != {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("}) AND [[test3]] LIKE {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} ESCAPE '\\' AND ([[test4.sub]] = '' OR [[test4.sub]] IS NULL))") +
|
||||
"$",
|
||||
"(([[test1]] > {:TEST} OR [[test2]] != {:TEST}) AND [[test3]] LIKE {:TEST} ESCAPE '\\' AND ([[test4.sub]] = '' OR [[test4.sub]] IS NULL))",
|
||||
},
|
||||
{
|
||||
"combination of special literals (null, true, false)",
|
||||
"test1=true && test2 != false && null = test3 || null != test4.sub",
|
||||
false,
|
||||
"^" + regexp.QuoteMeta("([[test1]] = 1 AND [[test2]] != 0 AND ('' = [[test3]] OR [[test3]] IS NULL) OR ('' != [[test4.sub]] AND [[test4.sub]] IS NOT NULL))") + "$",
|
||||
"([[test1]] = 1 AND [[test2]] != 0 AND ('' = [[test3]] OR [[test3]] IS NULL) OR ('' != [[test4.sub]] AND [[test4.sub]] IS NOT NULL))",
|
||||
},
|
||||
{
|
||||
"all operators",
|
||||
"(test1 = test2 || test2 != test3) && (test2 ~ 'example' || test2 !~ '%%abc') && 'switch1%%' ~ test1 && 'switch2' !~ test2 && test3 > 1 && test3 >= 0 && test3 <= 4 && 2 < 5",
|
||||
false,
|
||||
"^" +
|
||||
regexp.QuoteMeta("((COALESCE([[test1]], '') = COALESCE([[test2]], '') OR COALESCE([[test2]], '') != COALESCE([[test3]], '')) AND ([[test2]] LIKE {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} ESCAPE '\\' OR [[test2]] NOT LIKE {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} ESCAPE '\\') AND {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} LIKE ('%' || [[test1]] || '%') ESCAPE '\\' AND {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} NOT LIKE ('%' || [[test2]] || '%') ESCAPE '\\' AND [[test3]] > {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} AND [[test3]] >= {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} AND [[test3]] <= {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} AND {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("} < {:") +
|
||||
".+" +
|
||||
regexp.QuoteMeta("})") +
|
||||
"$",
|
||||
"((COALESCE([[test1]], '') = COALESCE([[test2]], '') OR COALESCE([[test2]], '') != COALESCE([[test3]], '')) AND ([[test2]] LIKE {:TEST} ESCAPE '\\' OR [[test2]] NOT LIKE {:TEST} ESCAPE '\\') AND {:TEST} LIKE ('%' || [[test1]] || '%') ESCAPE '\\' AND {:TEST} NOT LIKE ('%' || [[test2]] || '%') ESCAPE '\\' AND [[test3]] > {:TEST} AND [[test3]] >= {:TEST} AND [[test3]] <= {:TEST} AND {:TEST} < {:TEST})",
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
expr, err := s.filterData.BuildExpr(resolver)
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
expr, err := s.filterData.BuildExpr(resolver)
|
||||
|
||||
hasErr := err != nil
|
||||
if hasErr != s.expectError {
|
||||
t.Errorf("[%s] Expected hasErr %v, got %v (%v)", s.name, s.expectError, hasErr, err)
|
||||
continue
|
||||
}
|
||||
hasErr := err != nil
|
||||
if hasErr != s.expectError {
|
||||
t.Fatalf("[%s] Expected hasErr %v, got %v (%v)", s.name, s.expectError, hasErr, err)
|
||||
}
|
||||
|
||||
if hasErr {
|
||||
continue
|
||||
}
|
||||
if hasErr {
|
||||
return
|
||||
}
|
||||
|
||||
dummyDB := &dbx.DB{}
|
||||
rawSql := expr.Build(dummyDB, map[string]any{})
|
||||
dummyDB := &dbx.DB{}
|
||||
|
||||
pattern := regexp.MustCompile(s.expectPattern)
|
||||
if !pattern.MatchString(rawSql) {
|
||||
t.Errorf("[%s] Pattern %v don't match with expression: \n%v", s.name, s.expectPattern, rawSql)
|
||||
}
|
||||
rawSql := expr.Build(dummyDB, dbx.Params{})
|
||||
|
||||
// replace TEST placeholder with .+ regex pattern
|
||||
expectPattern := strings.ReplaceAll(
|
||||
"^"+regexp.QuoteMeta(s.expectPattern)+"$",
|
||||
"TEST",
|
||||
`\w+`,
|
||||
)
|
||||
|
||||
pattern := regexp.MustCompile(expectPattern)
|
||||
if !pattern.MatchString(rawSql) {
|
||||
t.Fatalf("[%s] Pattern %v don't match with expression: \n%v", s.name, expectPattern, rawSql)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterDataBuildExprWithParams(t *testing.T) {
|
||||
// create a dummy db
|
||||
sqlDB, err := sql.Open("sqlite", "file::memory:?cache=shared")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db := dbx.NewFromDB(sqlDB, "sqlite")
|
||||
|
||||
calledQueries := []string{}
|
||||
db.QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {
|
||||
calledQueries = append(calledQueries, sql)
|
||||
}
|
||||
db.ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) {
|
||||
calledQueries = append(calledQueries, sql)
|
||||
}
|
||||
|
||||
date, err := time.Parse("2006-01-02", "2023-01-01")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
resolver := search.NewSimpleFieldResolver(`^test\w+$`)
|
||||
|
||||
filter := search.FilterData(`
|
||||
test1 = {:test1} ||
|
||||
test2 = {:test2} ||
|
||||
test3a = {:test3} ||
|
||||
test3b = {:test3} ||
|
||||
test4 = {:test4} ||
|
||||
test5 = {:test5} ||
|
||||
test6 = {:test6} ||
|
||||
test7 = {:test7} ||
|
||||
test8 = {:test8} ||
|
||||
test9 = {:test9} ||
|
||||
test10 = {:test10} ||
|
||||
test11 = {:test11} ||
|
||||
test12 = {:test12}
|
||||
`)
|
||||
|
||||
replacements := []dbx.Params{
|
||||
{"test1": true},
|
||||
{"test2": false},
|
||||
{"test3": 123.456},
|
||||
{"test4": nil},
|
||||
{"test5": "", "test6": "simple", "test7": `'single_quotes'`, "test8": `"double_quotes"`, "test9": `escape\"quote`},
|
||||
{"test10": date},
|
||||
{"test11": []string{"a", "b", `"quote`}},
|
||||
{"test12": map[string]any{"a": 123, "b": `quote"`}},
|
||||
}
|
||||
|
||||
expr, err := filter.BuildExpr(resolver, replacements...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
db.Select().Where(expr).Build().Execute()
|
||||
|
||||
if len(calledQueries) != 1 {
|
||||
t.Fatalf("Expected 1 query, got %d", len(calledQueries))
|
||||
}
|
||||
|
||||
expectedQuery := `SELECT * WHERE ([[test1]] = 1 OR [[test2]] = 0 OR [[test3a]] = 123.456 OR [[test3b]] = 123.456 OR ([[test4]] = '' OR [[test4]] IS NULL) OR [[test5]] = '""' OR [[test6]] = 'simple' OR [[test7]] = '''single_quotes''' OR [[test8]] = '"double_quotes"' OR [[test9]] = 'escape\\"quote' OR [[test10]] = '2023-01-01 00:00:00 +0000 UTC' OR [[test11]] = '["a","b","\\"quote"]' OR [[test12]] = '{"a":123,"b":"quote\\""}')`
|
||||
if expectedQuery != calledQueries[0] {
|
||||
t.Fatalf("Expected query \n%s, \ngot \n%s", expectedQuery, calledQueries[0])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
)
|
||||
|
||||
// note: used primarily for the tests
|
||||
var timeNow = func() time.Time {
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
var identifierMacros = map[string]func() (any, error){
|
||||
"@now": func() (any, error) {
|
||||
today := timeNow().UTC()
|
||||
|
||||
d, err := types.ParseDateTime(today)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("@now: %w", err)
|
||||
}
|
||||
|
||||
return d.String(), nil
|
||||
},
|
||||
"@second": func() (any, error) {
|
||||
return int(timeNow().UTC().Second()), nil
|
||||
},
|
||||
"@minute": func() (any, error) {
|
||||
return int(timeNow().UTC().Minute()), nil
|
||||
},
|
||||
"@hour": func() (any, error) {
|
||||
return int(timeNow().UTC().Hour()), nil
|
||||
},
|
||||
"@day": func() (any, error) {
|
||||
return int(timeNow().UTC().Day()), nil
|
||||
},
|
||||
"@month": func() (any, error) {
|
||||
return int(timeNow().UTC().Month()), nil
|
||||
},
|
||||
"@weekday": func() (any, error) {
|
||||
return int(timeNow().UTC().Weekday()), nil
|
||||
},
|
||||
"@year": func() (any, error) {
|
||||
return int(timeNow().UTC().Year()), nil
|
||||
},
|
||||
"@todayStart": func() (any, error) {
|
||||
today := timeNow().UTC()
|
||||
start := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, time.UTC)
|
||||
|
||||
d, err := types.ParseDateTime(start)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("@todayStart: %w", err)
|
||||
}
|
||||
|
||||
return d.String(), nil
|
||||
},
|
||||
"@todayEnd": func() (any, error) {
|
||||
today := timeNow().UTC()
|
||||
|
||||
start := time.Date(today.Year(), today.Month(), today.Day(), 23, 59, 59, 999999999, time.UTC)
|
||||
|
||||
d, err := types.ParseDateTime(start)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("@todayEnd: %w", err)
|
||||
}
|
||||
|
||||
return d.String(), nil
|
||||
},
|
||||
"@monthStart": func() (any, error) {
|
||||
today := timeNow().UTC()
|
||||
start := time.Date(today.Year(), today.Month(), 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
d, err := types.ParseDateTime(start)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("@monthStart: %w", err)
|
||||
}
|
||||
|
||||
return d.String(), nil
|
||||
},
|
||||
"@monthEnd": func() (any, error) {
|
||||
today := timeNow().UTC()
|
||||
start := time.Date(today.Year(), today.Month(), 1, 23, 59, 59, 999999999, time.UTC)
|
||||
end := start.AddDate(0, 1, -1)
|
||||
|
||||
d, err := types.ParseDateTime(end)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("@monthEnd: %w", err)
|
||||
}
|
||||
|
||||
return d.String(), nil
|
||||
},
|
||||
"@yearStart": func() (any, error) {
|
||||
today := timeNow().UTC()
|
||||
start := time.Date(today.Year(), 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
d, err := types.ParseDateTime(start)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("@yearStart: %w", err)
|
||||
}
|
||||
|
||||
return d.String(), nil
|
||||
},
|
||||
"@yearEnd": func() (any, error) {
|
||||
today := timeNow().UTC()
|
||||
end := time.Date(today.Year(), 12, 31, 23, 59, 59, 999999999, time.UTC)
|
||||
|
||||
d, err := types.ParseDateTime(end)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("@yearEnd: %w", err)
|
||||
}
|
||||
|
||||
return d.String(), nil
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestIdentifierMacros(t *testing.T) {
|
||||
originalTimeNow := timeNow
|
||||
|
||||
timeNow = func() time.Time {
|
||||
return time.Date(2023, 2, 3, 4, 5, 6, 7, time.UTC)
|
||||
}
|
||||
|
||||
testMacros := map[string]any{
|
||||
"@now": "2023-02-03 04:05:06.000Z",
|
||||
"@second": 6,
|
||||
"@minute": 5,
|
||||
"@hour": 4,
|
||||
"@day": 3,
|
||||
"@month": 2,
|
||||
"@weekday": 5,
|
||||
"@year": 2023,
|
||||
"@todayStart": "2023-02-03 00:00:00.000Z",
|
||||
"@todayEnd": "2023-02-03 23:59:59.999Z",
|
||||
"@monthStart": "2023-02-01 00:00:00.000Z",
|
||||
"@monthEnd": "2023-02-28 23:59:59.999Z",
|
||||
"@yearStart": "2023-01-01 00:00:00.000Z",
|
||||
"@yearEnd": "2023-12-31 23:59:59.999Z",
|
||||
}
|
||||
|
||||
if len(testMacros) != len(identifierMacros) {
|
||||
t.Fatalf("Expected %d macros, got %d", len(testMacros), len(identifierMacros))
|
||||
}
|
||||
|
||||
for key, expected := range testMacros {
|
||||
t.Run(key, func(t *testing.T) {
|
||||
macro, ok := identifierMacros[key]
|
||||
if !ok {
|
||||
t.Fatalf("Missing macro %s", key)
|
||||
}
|
||||
|
||||
result, err := macro()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if result != expected {
|
||||
t.Fatalf("Expected %q, got %q", expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// restore
|
||||
timeNow = originalTimeNow
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/md5"
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"crypto/subtle"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// S256Challenge creates base64 encoded sha256 challenge string derived from code.
|
||||
// The padding of the result base64 string is stripped per [RFC 7636].
|
||||
//
|
||||
// [RFC 7636]: https://datatracker.ietf.org/doc/html/rfc7636#section-4.2
|
||||
func S256Challenge(code string) string {
|
||||
h := sha256.New()
|
||||
h.Write([]byte(code))
|
||||
return strings.TrimRight(base64.URLEncoding.EncodeToString(h.Sum(nil)), "=")
|
||||
}
|
||||
|
||||
// MD5 creates md5 hash from the provided plain text.
|
||||
func MD5(text string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(text))
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
// SHA256 creates sha256 hash as defined in FIPS 180-4 from the provided text.
|
||||
func SHA256(text string) string {
|
||||
h := sha256.New()
|
||||
h.Write([]byte(text))
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
// SHA512 creates sha512 hash as defined in FIPS 180-4 from the provided text.
|
||||
func SHA512(text string) string {
|
||||
h := sha512.New()
|
||||
h.Write([]byte(text))
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
// HS256 creates a HMAC hash with sha256 digest algorithm.
|
||||
func HS256(text string, secret string) string {
|
||||
h := hmac.New(sha256.New, []byte(secret))
|
||||
h.Write([]byte(text))
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
// HS512 creates a HMAC hash with sha512 digest algorithm.
|
||||
func HS512(text string, secret string) string {
|
||||
h := hmac.New(sha512.New, []byte(secret))
|
||||
h.Write([]byte(text))
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
// Equal compares two hash strings for equality without leaking timing information.
|
||||
func Equal(hash1 string, hash2 string) bool {
|
||||
return subtle.ConstantTimeCompare([]byte(hash1), []byte(hash2)) == 1
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package security_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/pocketbase/pocketbase/tools/security"
|
||||
)
|
||||
|
||||
func TestS256Challenge(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
code string
|
||||
expected string
|
||||
}{
|
||||
{"", "47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU"},
|
||||
{"123", "pmWkWSBCL51Bfkhn79xPuKBKHz__H6B-mY6G9_eieuM"},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.code, func(t *testing.T) {
|
||||
result := security.S256Challenge(s.code)
|
||||
|
||||
if result != s.expected {
|
||||
t.Fatalf("Expected %q, got %q", s.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMD5(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
code string
|
||||
expected string
|
||||
}{
|
||||
{"", "d41d8cd98f00b204e9800998ecf8427e"},
|
||||
{"123", "202cb962ac59075b964b07152d234b70"},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.code, func(t *testing.T) {
|
||||
result := security.MD5(s.code)
|
||||
|
||||
if result != s.expected {
|
||||
t.Fatalf("Expected %v, got %v", s.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSHA256(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
code string
|
||||
expected string
|
||||
}{
|
||||
{"", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
|
||||
{"123", "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3"},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.code, func(t *testing.T) {
|
||||
result := security.SHA256(s.code)
|
||||
|
||||
if result != s.expected {
|
||||
t.Fatalf("Expected %v, got %v", s.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSHA512(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
code string
|
||||
expected string
|
||||
}{
|
||||
{"", "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"},
|
||||
{"123", "3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2"},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.code, func(t *testing.T) {
|
||||
result := security.SHA512(s.code)
|
||||
|
||||
if result != s.expected {
|
||||
t.Fatalf("Expected %v, got %v", s.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHS256(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
text string
|
||||
secret string
|
||||
expected string
|
||||
}{
|
||||
{" ", "test", "9fb4e4a12d50728683a222b4fc466a69ee977332cfcdd6b9ebb44c7121dbd99f"},
|
||||
{" ", "test2", "d792417a504716e22805d940125ec12e68e8cb18fc84674703bd96c59f1e1228"},
|
||||
{"hello", "test", "f151ea24bda91a18e89b8bb5793ef324b2a02133cce15a28a719acbd2e58a986"},
|
||||
{"hello", "test2", "16436e8dcbf3d7b5b0455573b27e6372699beb5bfe94e6a2a371b14b4ae068f4"},
|
||||
}
|
||||
|
||||
for i, s := range scenarios {
|
||||
t.Run(fmt.Sprintf("%d-%s", i, s.text), func(t *testing.T) {
|
||||
result := security.HS256(s.text, s.secret)
|
||||
|
||||
if result != s.expected {
|
||||
t.Fatalf("Expected \n%v, \ngot \n%v", s.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHS512(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
text string
|
||||
secret string
|
||||
expected string
|
||||
}{
|
||||
{" ", "test", "eb3bdb0352c95c38880c1f645fc7e1d1332644f938f50de0d73876e42d6f302e599bb526531ba79940e8b314369aaef3675322d8d851f9fc6ea9ed121286d196"},
|
||||
{" ", "test2", "8b69e84e9252af78ae8b1c4bed3c9f737f69a3df33064cfbefe76b36d19d1827285e543cdf066cdc8bd556cc0cd0e212d52e9c12a50cd16046181ff127f4cf7f"},
|
||||
{"hello", "test", "44f280e11103e295c26cd61dd1cdd8178b531b860466867c13b1c37a26b6389f8af110efbe0bb0717b9d9c87f6fe1c97b3b1690936578890e5669abf279fe7fd"},
|
||||
{"hello", "test2", "d7f10b1b66941b20817689b973ca9dfc971090e28cfb8becbddd6824569b323eca6a0cdf2c387aa41e15040007dca5a011dd4e4bb61cfd5011aa7354d866f6ef"},
|
||||
}
|
||||
|
||||
for i, s := range scenarios {
|
||||
t.Run(fmt.Sprintf("%d-%q", i, s.text), func(t *testing.T) {
|
||||
result := security.HS512(s.text, s.secret)
|
||||
|
||||
if result != s.expected {
|
||||
t.Fatalf("Expected \n%v, \ngot \n%v", s.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqual(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
hash1 string
|
||||
hash2 string
|
||||
expected bool
|
||||
}{
|
||||
{"", "", true},
|
||||
{"abc", "abd", false},
|
||||
{"abc", "abc", true},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(fmt.Sprintf("%qVS%q", s.hash1, s.hash2), func(t *testing.T) {
|
||||
result := security.Equal(s.hash1, s.hash2)
|
||||
|
||||
if result != s.expected {
|
||||
t.Fatalf("Expected %v, got %v", s.expected, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -4,22 +4,10 @@ import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
crand "crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// S256Challenge creates base64 encoded sha256 challenge string derived from code.
|
||||
// The padding of the result base64 string is stripped per [RFC 7636].
|
||||
//
|
||||
// [RFC 7636]: https://datatracker.ietf.org/doc/html/rfc7636#section-4.2
|
||||
func S256Challenge(code string) string {
|
||||
h := sha256.New()
|
||||
h.Write([]byte(code))
|
||||
return strings.TrimRight(base64.URLEncoding.EncodeToString(h.Sum(nil)), "=")
|
||||
}
|
||||
|
||||
// Encrypt encrypts data with key (must be valid 32 char aes key).
|
||||
func Encrypt(data []byte, key string) (string, error) {
|
||||
block, err := aes.NewCipher([]byte(key))
|
||||
|
||||
@@ -6,24 +6,6 @@ import (
|
||||
"github.com/pocketbase/pocketbase/tools/security"
|
||||
)
|
||||
|
||||
func TestS256Challenge(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
code string
|
||||
expected string
|
||||
}{
|
||||
{"", "47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU"},
|
||||
{"123", "pmWkWSBCL51Bfkhn79xPuKBKHz__H6B-mY6G9_eieuM"},
|
||||
}
|
||||
|
||||
for i, scenario := range scenarios {
|
||||
result := security.S256Challenge(scenario.code)
|
||||
|
||||
if result != scenario.expected {
|
||||
t.Errorf("(%d) Expected %q, got %q", i, scenario.expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncrypt(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
data string
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
// Broker defines a struct for managing subscriptions clients.
|
||||
type Broker struct {
|
||||
mux sync.RWMutex
|
||||
clients map[string]Client
|
||||
mux sync.RWMutex
|
||||
}
|
||||
|
||||
// NewBroker initializes and returns a new Broker instance.
|
||||
|
||||
@@ -60,12 +60,12 @@ var _ Client = (*DefaultClient)(nil)
|
||||
|
||||
// DefaultClient defines a generic subscription client.
|
||||
type DefaultClient struct {
|
||||
mux sync.RWMutex
|
||||
isDiscarded bool
|
||||
id string
|
||||
store map[string]any
|
||||
channel chan Message
|
||||
subscriptions map[string]struct{}
|
||||
id string
|
||||
mux sync.RWMutex
|
||||
isDiscarded bool
|
||||
}
|
||||
|
||||
// NewDefaultClient creates and returns a new DefaultClient instance.
|
||||
|
||||
@@ -25,17 +25,24 @@ import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pocketbase/pocketbase/tools/store"
|
||||
)
|
||||
|
||||
// NewRegistry creates and initializes a new blank templates registry.
|
||||
// NewRegistry creates and initializes a new templates registry with
|
||||
// some defaults (eg. global "raw" template function for unescaped HTML).
|
||||
//
|
||||
// Use the Registry.Load* methods to load templates into the registry.
|
||||
func NewRegistry() *Registry {
|
||||
return &Registry{
|
||||
cache: store.New[*Renderer](nil),
|
||||
funcs: template.FuncMap{
|
||||
"raw": func(str string) template.HTML {
|
||||
return template.HTML(str)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +51,31 @@ func NewRegistry() *Registry {
|
||||
// Use the Registry.Load* methods to load templates into the registry.
|
||||
type Registry struct {
|
||||
cache *store.Store[*Renderer]
|
||||
funcs template.FuncMap
|
||||
}
|
||||
|
||||
// AddFuncs registers new global template functions.
|
||||
//
|
||||
// The key of each map entry is the function name that will be used in the templates.
|
||||
// If a function with the map entry name already exists it will be replaced with the new one.
|
||||
//
|
||||
// The value of each map entry is a function that must have either a
|
||||
// single return value, or two return values of which the second has type error.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// r.AddFuncs(map[string]any{
|
||||
// "toUpper": func(str string) string {
|
||||
// return strings.ToUppser(str)
|
||||
// },
|
||||
// ...
|
||||
// })
|
||||
func (r *Registry) AddFuncs(funcs map[string]any) *Registry {
|
||||
for name, f := range funcs {
|
||||
r.funcs[name] = f
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadFiles caches (if not already) the specified filenames set as a
|
||||
@@ -57,7 +89,7 @@ func (r *Registry) LoadFiles(filenames ...string) *Renderer {
|
||||
|
||||
if found == nil {
|
||||
// parse and cache
|
||||
tpl, err := template.ParseFiles(filenames...)
|
||||
tpl, err := template.New(filepath.Base(filenames[0])).Funcs(r.funcs).ParseFiles(filenames...)
|
||||
found = &Renderer{template: tpl, parseError: err}
|
||||
r.cache.Set(key, found)
|
||||
}
|
||||
@@ -72,7 +104,7 @@ func (r *Registry) LoadString(text string) *Renderer {
|
||||
|
||||
if found == nil {
|
||||
// parse and cache (using the text as key)
|
||||
tpl, err := template.New("").Parse(text)
|
||||
tpl, err := template.New("").Funcs(r.funcs).Parse(text)
|
||||
found = &Renderer{template: tpl, parseError: err}
|
||||
r.cache.Set(text, found)
|
||||
}
|
||||
@@ -80,19 +112,27 @@ func (r *Registry) LoadString(text string) *Renderer {
|
||||
return found
|
||||
}
|
||||
|
||||
// LoadString caches (if not already) the specified fs and globPatterns
|
||||
// LoadFS caches (if not already) the specified fs and globPatterns
|
||||
// pair as single template and returns a ready to use Renderer instance.
|
||||
//
|
||||
// There must be at least 1 file matching the provided globPattern(s)
|
||||
// (note that most file names serves as glob patterns matching themselves).
|
||||
func (r *Registry) LoadFS(fs fs.FS, globPatterns ...string) *Renderer {
|
||||
key := fmt.Sprintf("%v%v", fs, globPatterns)
|
||||
func (r *Registry) LoadFS(fsys fs.FS, globPatterns ...string) *Renderer {
|
||||
key := fmt.Sprintf("%v%v", fsys, globPatterns)
|
||||
|
||||
found := r.cache.Get(key)
|
||||
|
||||
if found == nil {
|
||||
// parse and cache
|
||||
tpl, err := template.ParseFS(fs, globPatterns...)
|
||||
// find the first file to use as template name (it is required when specifying Funcs)
|
||||
var firstFilename string
|
||||
if len(globPatterns) > 0 {
|
||||
list, _ := fs.Glob(fsys, globPatterns[0])
|
||||
if len(list) > 0 {
|
||||
firstFilename = filepath.Base(list[0])
|
||||
}
|
||||
}
|
||||
|
||||
tpl, err := template.New(firstFilename).Funcs(r.funcs).ParseFS(fsys, globPatterns...)
|
||||
found = &Renderer{template: tpl, parseError: err}
|
||||
r.cache.Set(key, found)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,18 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func checkRegistryFuncs(t *testing.T, r *Registry, expectedFuncs ...string) {
|
||||
if v := len(r.funcs); v != len(expectedFuncs) {
|
||||
t.Fatalf("Expected total %d funcs, got %d", len(expectedFuncs), v)
|
||||
}
|
||||
|
||||
for _, name := range expectedFuncs {
|
||||
if _, ok := r.funcs[name]; !ok {
|
||||
t.Fatalf("Missing %q func", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRegistry(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
|
||||
@@ -18,6 +30,28 @@ func TestNewRegistry(t *testing.T) {
|
||||
if v := r.cache.Length(); v != 0 {
|
||||
t.Fatalf("Expected cache store length to be 0, got %d", v)
|
||||
}
|
||||
|
||||
checkRegistryFuncs(t, r, "raw")
|
||||
}
|
||||
|
||||
func TestRegistryAddFuncs(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
|
||||
r.AddFuncs(map[string]any{
|
||||
"test": func(a string) string { return a + "-TEST" },
|
||||
})
|
||||
|
||||
checkRegistryFuncs(t, r, "raw", "test")
|
||||
|
||||
result, err := r.LoadString(`{{.|test}}`).Render("example")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected Render() error, got %v", err)
|
||||
}
|
||||
|
||||
expected := "example-TEST"
|
||||
if result != expected {
|
||||
t.Fatalf("Expected Render() result %q, got %q", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistryLoadFiles(t *testing.T) {
|
||||
@@ -48,10 +82,10 @@ func TestRegistryLoadFiles(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "base.html"), []byte(`Base:{{template "content"}}`), 0644); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(dir, "base.html"), []byte(`Base:{{template "content" .}}`), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "content.html"), []byte(`{{define "content"}}Content:123{{end}}`), 0644); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(dir, "content.html"), []byte(`{{define "content"}}Content:{{.|raw}}{{end}}`), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
@@ -74,12 +108,12 @@ func TestRegistryLoadFiles(t *testing.T) {
|
||||
t.Fatalf("Expected renderer parseError to be nil, got %v", renderer.parseError)
|
||||
}
|
||||
|
||||
result, err := renderer.Render(nil)
|
||||
result, err := renderer.Render("<h1>123</h1>")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected Render() error, got %v", err)
|
||||
}
|
||||
|
||||
expected := "Base:Content:123"
|
||||
expected := "Base:Content:<h1>123</h1>"
|
||||
if result != expected {
|
||||
t.Fatalf("Expected Render() result %q, got %q", expected, result)
|
||||
}
|
||||
@@ -110,7 +144,7 @@ func TestRegistryLoadString(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("valid template string", func(t *testing.T) {
|
||||
txt := `test {{.}}`
|
||||
txt := `test {{.|raw}}`
|
||||
|
||||
r.LoadString(txt)
|
||||
|
||||
@@ -128,12 +162,12 @@ func TestRegistryLoadString(t *testing.T) {
|
||||
t.Fatalf("Expected renderer parseError to be nil, got %v", renderer.parseError)
|
||||
}
|
||||
|
||||
result, err := renderer.Render(123)
|
||||
result, err := renderer.Render("<h1>123</h1>")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected Render() error, got %v", err)
|
||||
}
|
||||
|
||||
expected := "test 123"
|
||||
expected := "test <h1>123</h1>"
|
||||
if result != expected {
|
||||
t.Fatalf("Expected Render() result %q, got %q", expected, result)
|
||||
}
|
||||
@@ -173,10 +207,10 @@ func TestRegistryLoadFS(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "base.html"), []byte(`Base:{{template "content"}}`), 0644); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(dir, "base.html"), []byte(`Base:{{template "content" .}}`), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "content.html"), []byte(`{{define "content"}}Content:123{{end}}`), 0644); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(dir, "content.html"), []byte(`{{define "content"}}Content:{{.|raw}}{{end}}`), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
@@ -203,12 +237,12 @@ func TestRegistryLoadFS(t *testing.T) {
|
||||
t.Fatalf("Expected renderer parseError to be nil, got %v", renderer.parseError)
|
||||
}
|
||||
|
||||
result, err := renderer.Render(nil)
|
||||
result, err := renderer.Render("<h1>123</h1>")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected Render() error, got %v", err)
|
||||
}
|
||||
|
||||
expected := "Base:Content:123"
|
||||
expected := "Base:Content:<h1>123</h1>"
|
||||
if result != expected {
|
||||
t.Fatalf("Expected Render() result %q, got %q", expected, result)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ const eof = rune(0)
|
||||
// DefaultSeparators is a list with the default token separator characters.
|
||||
var DefaultSeparators = []rune{','}
|
||||
|
||||
var whitespaceChars = []rune{'\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0}
|
||||
|
||||
// NewFromString creates new Tokenizer from the provided string.
|
||||
func NewFromString(str string) *Tokenizer {
|
||||
return New(strings.NewReader(str))
|
||||
@@ -33,11 +35,11 @@ func NewFromBytes(b []byte) *Tokenizer {
|
||||
|
||||
// New creates new Tokenizer from the provided reader with DefaultSeparators.
|
||||
func New(r io.Reader) *Tokenizer {
|
||||
return &Tokenizer{
|
||||
r: bufio.NewReader(r),
|
||||
separators: DefaultSeparators,
|
||||
keepSeparator: false,
|
||||
}
|
||||
t := &Tokenizer{r: bufio.NewReader(r)}
|
||||
|
||||
t.Separators(DefaultSeparators...)
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
// Tokenizer defines a struct that parses a reader into tokens while
|
||||
@@ -45,54 +47,67 @@ func New(r io.Reader) *Tokenizer {
|
||||
type Tokenizer struct {
|
||||
r *bufio.Reader
|
||||
|
||||
separators []rune
|
||||
keepSeparator bool
|
||||
trimCutset string
|
||||
separators []rune
|
||||
keepSeparator bool
|
||||
keepEmptyTokens bool
|
||||
ignoreParenthesis bool
|
||||
}
|
||||
|
||||
// Separators defines the provided separatos of the current Tokenizer.
|
||||
func (s *Tokenizer) Separators(separators ...rune) {
|
||||
s.separators = separators
|
||||
func (t *Tokenizer) Separators(separators ...rune) {
|
||||
t.separators = separators
|
||||
|
||||
t.rebuildTrimCutset()
|
||||
}
|
||||
|
||||
// KeepSeparator defines whether to keep the separator rune as part
|
||||
// of the token (default to false).
|
||||
func (s *Tokenizer) KeepSeparator(state bool) {
|
||||
s.keepSeparator = state
|
||||
func (t *Tokenizer) KeepSeparator(state bool) {
|
||||
t.keepSeparator = state
|
||||
}
|
||||
|
||||
// Scan reads and returns the next available token from the Tokenizer's buffer (trimmed).
|
||||
// KeepEmptyTokens defines whether to keep empty tokens on Scan() (default to false).
|
||||
func (t *Tokenizer) KeepEmptyTokens(state bool) {
|
||||
t.keepEmptyTokens = state
|
||||
}
|
||||
|
||||
// IgnoreParenthesis defines whether to ignore the parenthesis boundaries
|
||||
// and to treat the '(' and ')' as regular characters.
|
||||
func (t *Tokenizer) IgnoreParenthesis(state bool) {
|
||||
t.ignoreParenthesis = state
|
||||
}
|
||||
|
||||
// Scan reads and returns the next available token from the Tokenizer's buffer (trimmed!).
|
||||
//
|
||||
// Empty tokens are skipped if t.keepEmptyTokens is not set (which is the default).
|
||||
//
|
||||
// Returns [io.EOF] error when there are no more tokens to scan.
|
||||
func (s *Tokenizer) Scan() (string, error) {
|
||||
ch := s.read()
|
||||
|
||||
func (t *Tokenizer) Scan() (string, error) {
|
||||
ch := t.read()
|
||||
if ch == eof {
|
||||
return "", io.EOF
|
||||
}
|
||||
t.unread()
|
||||
|
||||
if isWhitespaceRune(ch) {
|
||||
s.readWhiteSpaces()
|
||||
} else {
|
||||
s.unread()
|
||||
}
|
||||
|
||||
token, err := s.readToken()
|
||||
token, err := t.readToken()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// read all remaining whitespaces
|
||||
s.readWhiteSpaces()
|
||||
if !t.keepEmptyTokens && token == "" {
|
||||
return t.Scan()
|
||||
}
|
||||
|
||||
return token, err
|
||||
}
|
||||
|
||||
// ScanAll reads the entire Tokenizer's buffer and return all found tokens.
|
||||
func (s *Tokenizer) ScanAll() ([]string, error) {
|
||||
func (t *Tokenizer) ScanAll() ([]string, error) {
|
||||
tokens := []string{}
|
||||
|
||||
for {
|
||||
token, err := s.Scan()
|
||||
token, err := t.Scan()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
@@ -108,35 +123,35 @@ func (s *Tokenizer) ScanAll() ([]string, error) {
|
||||
}
|
||||
|
||||
// readToken reads a single token from the buffer and returns it.
|
||||
func (s *Tokenizer) readToken() (string, error) {
|
||||
func (t *Tokenizer) readToken() (string, error) {
|
||||
var buf bytes.Buffer
|
||||
var parenthesis int
|
||||
var quoteCh rune
|
||||
var prevCh rune
|
||||
|
||||
for {
|
||||
ch := s.read()
|
||||
ch := t.read()
|
||||
|
||||
if ch == eof {
|
||||
break
|
||||
}
|
||||
|
||||
if !isEscapeRune(prevCh) {
|
||||
if ch == '(' && quoteCh == eof {
|
||||
parenthesis++
|
||||
} else if ch == ')' && parenthesis > 0 && quoteCh == eof {
|
||||
parenthesis--
|
||||
} else if isQuoteRune(ch) {
|
||||
if !t.isEscapeRune(prevCh) {
|
||||
if !t.ignoreParenthesis && ch == '(' && quoteCh == eof {
|
||||
parenthesis++ // opening parenthesis
|
||||
} else if !t.ignoreParenthesis && ch == ')' && parenthesis > 0 && quoteCh == eof {
|
||||
parenthesis-- // closing parenthesis
|
||||
} else if t.isQuoteRune(ch) {
|
||||
if quoteCh == ch {
|
||||
quoteCh = eof // reached closing quote
|
||||
quoteCh = eof // closing quote
|
||||
} else if quoteCh == eof {
|
||||
quoteCh = ch // opening quote
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if s.isSeperatorRune(ch) && parenthesis == 0 && quoteCh == eof {
|
||||
if s.keepSeparator {
|
||||
if t.isSeperatorRune(ch) && parenthesis == 0 && quoteCh == eof {
|
||||
if t.keepSeparator {
|
||||
buf.WriteRune(ch)
|
||||
}
|
||||
break
|
||||
@@ -150,20 +165,20 @@ func (s *Tokenizer) readToken() (string, error) {
|
||||
return "", fmt.Errorf("unbalanced parenthesis or quoted expression: %q", buf.String())
|
||||
}
|
||||
|
||||
return buf.String(), nil
|
||||
return strings.Trim(buf.String(), t.trimCutset), nil
|
||||
}
|
||||
|
||||
// readWhiteSpaces consumes all contiguous whitespace runes.
|
||||
func (s *Tokenizer) readWhiteSpaces() {
|
||||
func (t *Tokenizer) readWhiteSpaces() {
|
||||
for {
|
||||
ch := s.read()
|
||||
ch := t.read()
|
||||
|
||||
if ch == eof {
|
||||
break
|
||||
}
|
||||
|
||||
if !s.isSeperatorRune(ch) {
|
||||
s.unread()
|
||||
if !t.isWhitespaceRune(ch) {
|
||||
t.unread()
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -171,8 +186,8 @@ func (s *Tokenizer) readWhiteSpaces() {
|
||||
|
||||
// read reads the next rune from the buffered reader.
|
||||
// Returns the `rune(0)` if an error or `io.EOF` occurs.
|
||||
func (s *Tokenizer) read() rune {
|
||||
ch, _, err := s.r.ReadRune()
|
||||
func (t *Tokenizer) read() rune {
|
||||
ch, _, err := t.r.ReadRune()
|
||||
if err != nil {
|
||||
return eof
|
||||
}
|
||||
@@ -181,13 +196,27 @@ func (s *Tokenizer) read() rune {
|
||||
}
|
||||
|
||||
// unread places the previously read rune back on the reader.
|
||||
func (s *Tokenizer) unread() error {
|
||||
return s.r.UnreadRune()
|
||||
func (t *Tokenizer) unread() error {
|
||||
return t.r.UnreadRune()
|
||||
}
|
||||
|
||||
// rebuildTrimCutset rebuilds the tokenizer trimCutset based on its separator runes.
|
||||
func (t *Tokenizer) rebuildTrimCutset() {
|
||||
var cutset strings.Builder
|
||||
|
||||
for _, w := range whitespaceChars {
|
||||
if t.isSeperatorRune(w) {
|
||||
continue
|
||||
}
|
||||
cutset.WriteRune(w)
|
||||
}
|
||||
|
||||
t.trimCutset = cutset.String()
|
||||
}
|
||||
|
||||
// isSeperatorRune checks if a rune is a token part separator.
|
||||
func (s *Tokenizer) isSeperatorRune(ch rune) bool {
|
||||
for _, r := range s.separators {
|
||||
func (t *Tokenizer) isSeperatorRune(ch rune) bool {
|
||||
for _, r := range t.separators {
|
||||
if ch == r {
|
||||
return true
|
||||
}
|
||||
@@ -196,17 +225,23 @@ func (s *Tokenizer) isSeperatorRune(ch rune) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// isWhitespaceRune checks if a rune is a space, tab, or newline.
|
||||
func isWhitespaceRune(ch rune) bool {
|
||||
return ch == ' ' || ch == '\t' || ch == '\n'
|
||||
// isWhitespaceRune checks if a rune is a space character (eg. space, tab, new line).
|
||||
func (t *Tokenizer) isWhitespaceRune(ch rune) bool {
|
||||
for _, c := range whitespaceChars {
|
||||
if c == ch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// isQuoteRune checks if a rune is a quote.
|
||||
func isQuoteRune(ch rune) bool {
|
||||
func (t *Tokenizer) isQuoteRune(ch rune) bool {
|
||||
return ch == '\'' || ch == '"' || ch == '`'
|
||||
}
|
||||
|
||||
// isEscapeRune checks if a rune is an escape character.
|
||||
func isEscapeRune(ch rune) bool {
|
||||
func (t *Tokenizer) isEscapeRune(ch rune) bool {
|
||||
return ch == '\\'
|
||||
}
|
||||
|
||||
+190
-120
@@ -28,32 +28,38 @@ func TestFactories(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
content, _ := s.tk.r.ReadString(0)
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
content, _ := s.tk.r.ReadString(0)
|
||||
|
||||
if content != expectedContent {
|
||||
t.Fatalf("[%s] Expected reader with content %q, got %q", s.name, expectedContent, content)
|
||||
}
|
||||
if content != expectedContent {
|
||||
t.Fatalf("Expected reader with content %q, got %q", expectedContent, content)
|
||||
}
|
||||
|
||||
if s.tk.keepSeparator != false {
|
||||
t.Fatalf("[%s] Expected false, got true", s.name)
|
||||
}
|
||||
if s.tk.keepSeparator != false {
|
||||
t.Fatal("Expected keepSeparator false, got true")
|
||||
}
|
||||
|
||||
if len(s.tk.separators) != len(DefaultSeparators) {
|
||||
t.Fatalf("[%s] Expected \n%v, \ngot \n%v", s.name, DefaultSeparators, s.tk.separators)
|
||||
}
|
||||
if s.tk.ignoreParenthesis != false {
|
||||
t.Fatal("Expected ignoreParenthesis false, got true")
|
||||
}
|
||||
|
||||
for _, r := range s.tk.separators {
|
||||
exists := false
|
||||
for _, def := range s.tk.separators {
|
||||
if r == def {
|
||||
exists = true
|
||||
break
|
||||
if len(s.tk.separators) != len(DefaultSeparators) {
|
||||
t.Fatalf("Expected \n%v, \ngot \n%v", DefaultSeparators, s.tk.separators)
|
||||
}
|
||||
|
||||
for _, r := range s.tk.separators {
|
||||
exists := false
|
||||
for _, def := range s.tk.separators {
|
||||
if r == def {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
t.Fatalf("Unexpected sepator %s", string(r))
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
t.Fatalf("[%s] Unexpected sepator %s", s.name, string(r))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,54 +91,65 @@ func TestScan(t *testing.T) {
|
||||
|
||||
func TestScanAll(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
name string
|
||||
content string
|
||||
separators []rune
|
||||
keepSeparator bool
|
||||
expectError bool
|
||||
expectTokens []string
|
||||
name string
|
||||
content string
|
||||
separators []rune
|
||||
keepSeparator bool
|
||||
keepEmptyTokens bool
|
||||
ignoreParenthesis bool
|
||||
expectError bool
|
||||
expectTokens []string
|
||||
}{
|
||||
{
|
||||
"empty string",
|
||||
"",
|
||||
DefaultSeparators,
|
||||
false,
|
||||
false,
|
||||
nil,
|
||||
name: "empty string",
|
||||
content: "",
|
||||
separators: DefaultSeparators,
|
||||
keepSeparator: false,
|
||||
keepEmptyTokens: false,
|
||||
ignoreParenthesis: false,
|
||||
expectError: false,
|
||||
expectTokens: nil,
|
||||
},
|
||||
{
|
||||
"unbalanced parenthesis",
|
||||
`(a,b() c`,
|
||||
DefaultSeparators,
|
||||
false,
|
||||
true,
|
||||
[]string{},
|
||||
name: "unbalanced parenthesis",
|
||||
content: `(a,b() c`,
|
||||
separators: DefaultSeparators,
|
||||
keepSeparator: false,
|
||||
keepEmptyTokens: false,
|
||||
ignoreParenthesis: false,
|
||||
expectError: true,
|
||||
expectTokens: []string{},
|
||||
},
|
||||
{
|
||||
"unmatching quotes",
|
||||
`'asd"`,
|
||||
DefaultSeparators,
|
||||
false,
|
||||
true,
|
||||
[]string{},
|
||||
name: "unmatching quotes",
|
||||
content: `'asd"`,
|
||||
separators: DefaultSeparators,
|
||||
keepSeparator: false,
|
||||
keepEmptyTokens: false,
|
||||
ignoreParenthesis: false,
|
||||
expectError: true,
|
||||
expectTokens: []string{},
|
||||
},
|
||||
{
|
||||
"no separators",
|
||||
`a, b, c, d, e 123, "abc"`,
|
||||
nil,
|
||||
false,
|
||||
false,
|
||||
[]string{
|
||||
`a, b, c, d, e 123, "abc"`,
|
||||
},
|
||||
name: "no separators",
|
||||
content: `a, b, c, d, e 123, "abc"`,
|
||||
separators: nil,
|
||||
keepSeparator: false,
|
||||
keepEmptyTokens: false,
|
||||
ignoreParenthesis: false,
|
||||
expectError: false,
|
||||
expectTokens: []string{`a, b, c, d, e 123, "abc"`},
|
||||
},
|
||||
{
|
||||
"default separators",
|
||||
`a, b, c, d e, "a,b, c ", (123, 456)`,
|
||||
DefaultSeparators,
|
||||
false,
|
||||
false,
|
||||
[]string{
|
||||
name: "default separators",
|
||||
content: `a, b , c , d e , "a,b, c " , ,, , (123, 456)
|
||||
`,
|
||||
separators: DefaultSeparators,
|
||||
keepSeparator: false,
|
||||
keepEmptyTokens: false,
|
||||
ignoreParenthesis: false,
|
||||
expectError: false,
|
||||
expectTokens: []string{
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
@@ -142,92 +159,145 @@ func TestScanAll(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
"default separators (with preserve)",
|
||||
`a, b, c, d e, "a,b, c ", (123, 456)`,
|
||||
DefaultSeparators,
|
||||
true,
|
||||
false,
|
||||
[]string{
|
||||
name: "keep separators",
|
||||
content: `a, b, c, d e, "a,b, c ", (123, 456)`,
|
||||
separators: []rune{',', ' '}, // the space should be removed from the cutset
|
||||
keepSeparator: true,
|
||||
keepEmptyTokens: true,
|
||||
ignoreParenthesis: false,
|
||||
expectError: false,
|
||||
expectTokens: []string{
|
||||
"a,",
|
||||
" ",
|
||||
"b,",
|
||||
" ",
|
||||
"c,",
|
||||
"d e,",
|
||||
" ",
|
||||
"d ",
|
||||
" ",
|
||||
"e,",
|
||||
" ",
|
||||
`"a,b, c ",`,
|
||||
`(123, 456)`,
|
||||
},
|
||||
},
|
||||
{
|
||||
"custom separators",
|
||||
` a , 123.456, b, c d, (
|
||||
test (a,b,c) " 123 "
|
||||
),"(abc d", "abc) d", "(abc) d \" " 'abc "'`,
|
||||
[]rune{',', ' ', '\t', '\n'},
|
||||
false,
|
||||
false,
|
||||
[]string{
|
||||
name: "custom separators",
|
||||
content: `a | b c d &(e + f) & "g & h" & & &`,
|
||||
separators: []rune{'|', '&'},
|
||||
keepSeparator: false,
|
||||
keepEmptyTokens: false,
|
||||
ignoreParenthesis: false,
|
||||
expectError: false,
|
||||
expectTokens: []string{
|
||||
"a",
|
||||
"123.456",
|
||||
"b",
|
||||
"c",
|
||||
"d",
|
||||
"(\n\t\t\t\ttest (a,b,c) \" 123 \"\n\t\t\t)",
|
||||
`"(abc d"`,
|
||||
`"abc) d"`,
|
||||
`"(abc) d \" "`,
|
||||
`'abc "'`,
|
||||
"b c d",
|
||||
"(e + f)",
|
||||
`"g & h"`,
|
||||
},
|
||||
},
|
||||
{
|
||||
"custom separators (with preserve)",
|
||||
` a , 123.456, b, c d, (
|
||||
test (a,b,c) " 123 "
|
||||
),"(abc d", "abc) d", "(abc) d \" " 'abc "'`,
|
||||
[]rune{',', ' ', '\t', '\n'},
|
||||
true,
|
||||
false,
|
||||
[]string{
|
||||
"a ",
|
||||
"123.456,",
|
||||
"b,",
|
||||
"c ",
|
||||
"d,",
|
||||
"(\n\t\t\t\ttest (a,b,c) \" 123 \"\n\t\t\t),",
|
||||
`"(abc d",`,
|
||||
`"abc) d",`,
|
||||
`"(abc) d \" " `,
|
||||
`'abc "'`,
|
||||
name: "ignoring parenthesis",
|
||||
content: `a, b, (c,d)`,
|
||||
separators: DefaultSeparators,
|
||||
keepSeparator: false,
|
||||
keepEmptyTokens: false,
|
||||
ignoreParenthesis: true,
|
||||
expectError: false,
|
||||
expectTokens: []string{
|
||||
"a",
|
||||
"b",
|
||||
"(c",
|
||||
"d)",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "keep empty tokens",
|
||||
content: `a, b, (c, d), ,, , e, , f`,
|
||||
separators: DefaultSeparators,
|
||||
keepSeparator: false,
|
||||
keepEmptyTokens: true,
|
||||
ignoreParenthesis: false,
|
||||
expectError: false,
|
||||
expectTokens: []string{
|
||||
"a",
|
||||
"b",
|
||||
"(c, d)",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"e",
|
||||
"",
|
||||
"f",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
tk := NewFromString(s.content)
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
tk := NewFromString(s.content)
|
||||
|
||||
tk.Separators(s.separators...)
|
||||
tk.KeepSeparator(s.keepSeparator)
|
||||
tk.Separators(s.separators...)
|
||||
tk.KeepSeparator(s.keepSeparator)
|
||||
tk.KeepEmptyTokens(s.keepEmptyTokens)
|
||||
tk.IgnoreParenthesis(s.ignoreParenthesis)
|
||||
|
||||
tokens, err := tk.ScanAll()
|
||||
tokens, err := tk.ScanAll()
|
||||
|
||||
hasErr := err != nil
|
||||
if hasErr != s.expectError {
|
||||
t.Fatalf("[%s] Expected hasErr %v, got %v (%v)", s.name, s.expectError, hasErr, err)
|
||||
}
|
||||
hasErr := err != nil
|
||||
if hasErr != s.expectError {
|
||||
t.Fatalf("Expected hasErr %v, got %v (%v)", s.expectError, hasErr, err)
|
||||
}
|
||||
|
||||
if len(tokens) != len(s.expectTokens) {
|
||||
t.Fatalf("[%s] Expected \n%v (%d), \ngot \n%v (%d)", s.name, s.expectTokens, len(s.expectTokens), tokens, len(tokens))
|
||||
}
|
||||
if len(tokens) != len(s.expectTokens) {
|
||||
t.Fatalf("Expected \n%v (%d), \ngot \n%v (%d)", s.expectTokens, len(s.expectTokens), tokens, len(tokens))
|
||||
}
|
||||
|
||||
for _, tok := range tokens {
|
||||
exists := false
|
||||
for _, def := range s.expectTokens {
|
||||
if tok == def {
|
||||
exists = true
|
||||
break
|
||||
for _, tok := range tokens {
|
||||
exists := false
|
||||
for _, def := range s.expectTokens {
|
||||
if tok == def {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
t.Fatalf("Unexpected token %q", tok)
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
t.Fatalf("[%s] Unexpected token %s", s.name, tok)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrimCutset(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
name string
|
||||
separators []rune
|
||||
expectedCutset string
|
||||
}{
|
||||
{
|
||||
"default factory separators",
|
||||
nil,
|
||||
"\t\n\v\f\r \u0085\u00a0",
|
||||
},
|
||||
{
|
||||
"custom separators",
|
||||
[]rune{'\t', ' ', '\r', ','},
|
||||
"\n\v\f\u0085\u00a0",
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
tk := NewFromString("")
|
||||
|
||||
if len(s.separators) > 0 {
|
||||
tk.Separators(s.separators...)
|
||||
}
|
||||
}
|
||||
|
||||
if tk.trimCutset != s.expectedCutset {
|
||||
t.Fatalf("Expected cutset %q, got %q", s.expectedCutset, tk.trimCutset)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func (j JsonRaw) Value() (driver.Value, error) {
|
||||
|
||||
// Scan implements [sql.Scanner] interface to scan the provided value
|
||||
// into the current JsonRaw instance.
|
||||
func (j *JsonRaw) Scan(value interface{}) error {
|
||||
func (j *JsonRaw) Scan(value any) error {
|
||||
var data []byte
|
||||
|
||||
switch v := value.(type) {
|
||||
|
||||
@@ -9,4 +9,4 @@ PB_DOCS_URL = "https://pocketbase.io/docs/"
|
||||
PB_JS_SDK_URL = "https://github.com/pocketbase/js-sdk"
|
||||
PB_DART_SDK_URL = "https://github.com/pocketbase/dart-sdk"
|
||||
PB_RELEASES = "https://github.com/pocketbase/pocketbase/releases"
|
||||
PB_VERSION = "v0.17.7"
|
||||
PB_VERSION = "v0.19.2"
|
||||
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
import{S as $e,i as Se,s as ye,e as c,w,b as k,c as oe,f as h,g as d,h as a,m as se,x as G,N as we,P as Te,k as je,Q as Ae,n as Be,t as U,a as W,o as u,d as ae,T as Fe,C as Oe,p as Qe,r as V,u as Ne,M as He}from"./index-42f47088.js";import{S as Ke}from"./SdkTabs-81470834.js";import{F as qe}from"./FieldsQueryParam-582f34bb.js";function ve(n,l,o){const s=n.slice();return s[5]=l[o],s}function Ce(n,l,o){const s=n.slice();return s[5]=l[o],s}function Pe(n,l){let o,s=l[5].code+"",_,p,i,f;function m(){return l[4](l[5])}return{key:n,first:null,c(){o=c("button"),_=w(s),p=k(),h(o,"class","tab-item"),V(o,"active",l[1]===l[5].code),this.first=o},m(v,C){d(v,o,C),a(o,_),a(o,p),i||(f=Ne(o,"click",m),i=!0)},p(v,C){l=v,C&4&&s!==(s=l[5].code+"")&&G(_,s),C&6&&V(o,"active",l[1]===l[5].code)},d(v){v&&u(o),i=!1,f()}}}function Me(n,l){let o,s,_,p;return s=new He({props:{content:l[5].body}}),{key:n,first:null,c(){o=c("div"),oe(s.$$.fragment),_=k(),h(o,"class","tab-item"),V(o,"active",l[1]===l[5].code),this.first=o},m(i,f){d(i,o,f),se(s,o,null),a(o,_),p=!0},p(i,f){l=i;const m={};f&4&&(m.content=l[5].body),s.$set(m),(!p||f&6)&&V(o,"active",l[1]===l[5].code)},i(i){p||(U(s.$$.fragment,i),p=!0)},o(i){W(s.$$.fragment,i),p=!1},d(i){i&&u(o),ae(s)}}}function ze(n){var _e,be;let l,o,s=n[0].name+"",_,p,i,f,m,v,C,H=n[0].name+"",L,ne,E,P,I,j,J,M,K,ie,q,A,ce,Y,z=n[0].name+"",X,re,R,B,Z,$,x,de,ee,T,te,F,le,S,O,g=[],ue=new Map,fe,Q,b=[],me=new Map,y;P=new Ke({props:{js:`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${n[3]}');
|
||||
|
||||
...
|
||||
|
||||
const result = await pb.collection('${(_e=n[0])==null?void 0:_e.name}').listAuthMethods();
|
||||
`,dart:`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${n[3]}');
|
||||
|
||||
...
|
||||
|
||||
final result = await pb.collection('${(be=n[0])==null?void 0:be.name}').listAuthMethods();
|
||||
`}}),T=new qe({});let D=n[2];const pe=e=>e[5].code;for(let e=0;e<D.length;e+=1){let t=Ce(n,D,e),r=pe(t);ue.set(r,g[e]=Pe(r,t))}let N=n[2];const he=e=>e[5].code;for(let e=0;e<N.length;e+=1){let t=ve(n,N,e),r=he(t);me.set(r,b[e]=Me(r,t))}return{c(){l=c("h3"),o=w("List auth methods ("),_=w(s),p=w(")"),i=k(),f=c("div"),m=c("p"),v=w("Returns a public list with all allowed "),C=c("strong"),L=w(H),ne=w(" authentication methods."),E=k(),oe(P.$$.fragment),I=k(),j=c("h6"),j.textContent="API details",J=k(),M=c("div"),K=c("strong"),K.textContent="GET",ie=k(),q=c("div"),A=c("p"),ce=w("/api/collections/"),Y=c("strong"),X=w(z),re=w("/auth-methods"),R=k(),B=c("div"),B.textContent="Query parameters",Z=k(),$=c("table"),x=c("thead"),x.innerHTML=`<tr><th>Param</th>
|
||||
<th>Type</th>
|
||||
<th width="50%">Description</th></tr>`,de=k(),ee=c("tbody"),oe(T.$$.fragment),te=k(),F=c("div"),F.textContent="Responses",le=k(),S=c("div"),O=c("div");for(let e=0;e<g.length;e+=1)g[e].c();fe=k(),Q=c("div");for(let e=0;e<b.length;e+=1)b[e].c();h(l,"class","m-b-sm"),h(f,"class","content txt-lg m-b-sm"),h(j,"class","m-b-xs"),h(K,"class","label label-primary"),h(q,"class","content"),h(M,"class","alert alert-info"),h(B,"class","section-title"),h($,"class","table-compact table-border m-b-base"),h(F,"class","section-title"),h(O,"class","tabs-header compact left"),h(Q,"class","tabs-content"),h(S,"class","tabs")},m(e,t){d(e,l,t),a(l,o),a(l,_),a(l,p),d(e,i,t),d(e,f,t),a(f,m),a(m,v),a(m,C),a(C,L),a(m,ne),d(e,E,t),se(P,e,t),d(e,I,t),d(e,j,t),d(e,J,t),d(e,M,t),a(M,K),a(M,ie),a(M,q),a(q,A),a(A,ce),a(A,Y),a(Y,X),a(A,re),d(e,R,t),d(e,B,t),d(e,Z,t),d(e,$,t),a($,x),a($,de),a($,ee),se(T,ee,null),d(e,te,t),d(e,F,t),d(e,le,t),d(e,S,t),a(S,O);for(let r=0;r<g.length;r+=1)g[r]&&g[r].m(O,null);a(S,fe),a(S,Q);for(let r=0;r<b.length;r+=1)b[r]&&b[r].m(Q,null);y=!0},p(e,[t]){var ke,ge;(!y||t&1)&&s!==(s=e[0].name+"")&&G(_,s),(!y||t&1)&&H!==(H=e[0].name+"")&&G(L,H);const r={};t&9&&(r.js=`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
const result = await pb.collection('${(ke=e[0])==null?void 0:ke.name}').listAuthMethods();
|
||||
`),t&9&&(r.dart=`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
final result = await pb.collection('${(ge=e[0])==null?void 0:ge.name}').listAuthMethods();
|
||||
`),P.$set(r),(!y||t&1)&&z!==(z=e[0].name+"")&&G(X,z),t&6&&(D=e[2],g=we(g,t,pe,1,e,D,ue,O,Te,Pe,null,Ce)),t&6&&(N=e[2],je(),b=we(b,t,he,1,e,N,me,Q,Ae,Me,null,ve),Be())},i(e){if(!y){U(P.$$.fragment,e),U(T.$$.fragment,e);for(let t=0;t<N.length;t+=1)U(b[t]);y=!0}},o(e){W(P.$$.fragment,e),W(T.$$.fragment,e);for(let t=0;t<b.length;t+=1)W(b[t]);y=!1},d(e){e&&u(l),e&&u(i),e&&u(f),e&&u(E),ae(P,e),e&&u(I),e&&u(j),e&&u(J),e&&u(M),e&&u(R),e&&u(B),e&&u(Z),e&&u($),ae(T),e&&u(te),e&&u(F),e&&u(le),e&&u(S);for(let t=0;t<g.length;t+=1)g[t].d();for(let t=0;t<b.length;t+=1)b[t].d()}}}function De(n,l,o){let s,{collection:_=new Fe}=l,p=200,i=[];const f=m=>o(1,p=m.code);return n.$$set=m=>{"collection"in m&&o(0,_=m.collection)},o(3,s=Oe.getApiExampleUrl(Qe.baseUrl)),o(2,i=[{code:200,body:`
|
||||
{
|
||||
"usernamePassword": true,
|
||||
"emailPassword": true,
|
||||
"authProviders": [
|
||||
{
|
||||
"name": "github",
|
||||
"state": "3Yd8jNkK_6PJG6hPWwBjLqKwse6Ejd",
|
||||
"codeVerifier": "KxFDWz1B3fxscCDJ_9gHQhLuh__ie7",
|
||||
"codeChallenge": "NM1oVexB6Q6QH8uPtOUfK7tq4pmu4Jz6lNDIwoxHZNE=",
|
||||
"codeChallengeMethod": "S256",
|
||||
"authUrl": "https://github.com/login/oauth/authorize?client_id=demo&code_challenge=NM1oVexB6Q6QH8uPtOUfK7tq4pmu4Jz6lNDIwoxHZNE%3D&code_challenge_method=S256&response_type=code&scope=user&state=3Yd8jNkK_6PJG6hPWwBjLqKwse6Ejd&redirect_uri="
|
||||
},
|
||||
{
|
||||
"name": "gitlab",
|
||||
"state": "NeQSbtO5cShr_mk5__3CUukiMnymeb",
|
||||
"codeVerifier": "ahTFHOgua8mkvPAlIBGwCUJbWKR_xi",
|
||||
"codeChallenge": "O-GATkTj4eXDCnfonsqGLCd6njvTixlpCMvy5kjgOOg=",
|
||||
"codeChallengeMethod": "S256",
|
||||
"authUrl": "https://gitlab.com/oauth/authorize?client_id=demo&code_challenge=O-GATkTj4eXDCnfonsqGLCd6njvTixlpCMvy5kjgOOg%3D&code_challenge_method=S256&response_type=code&scope=read_user&state=NeQSbtO5cShr_mk5__3CUukiMnymeb&redirect_uri="
|
||||
},
|
||||
{
|
||||
"name": "google",
|
||||
"state": "zB3ZPifV1TW2GMuvuFkamSXfSNkHPQ",
|
||||
"codeVerifier": "t3CmO5VObGzdXqieakvR_fpjiW0zdO",
|
||||
"codeChallenge": "KChwoQPKYlz2anAdqtgsSTdIo8hdwtc1fh2wHMwW2Yk=",
|
||||
"codeChallengeMethod": "S256",
|
||||
"authUrl": "https://accounts.google.com/o/oauth2/auth?client_id=demo&code_challenge=KChwoQPKYlz2anAdqtgsSTdIo8hdwtc1fh2wHMwW2Yk%3D&code_challenge_method=S256&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&state=zB3ZPifV1TW2GMuvuFkamSXfSNkHPQ&redirect_uri="
|
||||
}
|
||||
]
|
||||
}
|
||||
`}]),[_,p,i,s,f]}class Ve extends $e{constructor(l){super(),Se(this,l,De,ze,ye,{collection:0})}}export{Ve as default};
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
import{S as Se,i as ye,s as Te,O as G,e as c,w,b as k,c as se,f as p,g as d,h as a,m as ae,x as U,P as ve,Q as je,k as Ae,R as Be,n as Oe,t as W,a as V,o as u,d as ne,C as Fe,p as Qe,r as L,u as Ne,N as He}from"./index-fd9da555.js";import{S as Ke}from"./SdkTabs-9e15e9a4.js";import{F as qe}from"./FieldsQueryParam-3fb2414b.js";function Ce(n,l,o){const s=n.slice();return s[5]=l[o],s}function Pe(n,l,o){const s=n.slice();return s[5]=l[o],s}function $e(n,l){let o,s=l[5].code+"",_,f,i,h;function m(){return l[4](l[5])}return{key:n,first:null,c(){o=c("button"),_=w(s),f=k(),p(o,"class","tab-item"),L(o,"active",l[1]===l[5].code),this.first=o},m(v,C){d(v,o,C),a(o,_),a(o,f),i||(h=Ne(o,"click",m),i=!0)},p(v,C){l=v,C&4&&s!==(s=l[5].code+"")&&U(_,s),C&6&&L(o,"active",l[1]===l[5].code)},d(v){v&&u(o),i=!1,h()}}}function Me(n,l){let o,s,_,f;return s=new He({props:{content:l[5].body}}),{key:n,first:null,c(){o=c("div"),se(s.$$.fragment),_=k(),p(o,"class","tab-item"),L(o,"active",l[1]===l[5].code),this.first=o},m(i,h){d(i,o,h),ae(s,o,null),a(o,_),f=!0},p(i,h){l=i;const m={};h&4&&(m.content=l[5].body),s.$set(m),(!f||h&6)&&L(o,"active",l[1]===l[5].code)},i(i){f||(W(s.$$.fragment,i),f=!0)},o(i){V(s.$$.fragment,i),f=!1},d(i){i&&u(o),ne(s)}}}function ze(n){var be,ke;let l,o,s=n[0].name+"",_,f,i,h,m,v,C,H=n[0].name+"",E,ie,I,P,J,j,Y,$,K,ce,q,A,re,R,z=n[0].name+"",X,de,Z,B,x,M,ee,ue,te,T,le,O,oe,S,F,g=[],he=new Map,me,Q,b=[],fe=new Map,y;P=new Ke({props:{js:`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${n[3]}');
|
||||
|
||||
...
|
||||
|
||||
const result = await pb.collection('${(be=n[0])==null?void 0:be.name}').listAuthMethods();
|
||||
`,dart:`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${n[3]}');
|
||||
|
||||
...
|
||||
|
||||
final result = await pb.collection('${(ke=n[0])==null?void 0:ke.name}').listAuthMethods();
|
||||
`}}),T=new qe({});let D=G(n[2]);const pe=e=>e[5].code;for(let e=0;e<D.length;e+=1){let t=Pe(n,D,e),r=pe(t);he.set(r,g[e]=$e(r,t))}let N=G(n[2]);const _e=e=>e[5].code;for(let e=0;e<N.length;e+=1){let t=Ce(n,N,e),r=_e(t);fe.set(r,b[e]=Me(r,t))}return{c(){l=c("h3"),o=w("List auth methods ("),_=w(s),f=w(")"),i=k(),h=c("div"),m=c("p"),v=w("Returns a public list with all allowed "),C=c("strong"),E=w(H),ie=w(" authentication methods."),I=k(),se(P.$$.fragment),J=k(),j=c("h6"),j.textContent="API details",Y=k(),$=c("div"),K=c("strong"),K.textContent="GET",ce=k(),q=c("div"),A=c("p"),re=w("/api/collections/"),R=c("strong"),X=w(z),de=w("/auth-methods"),Z=k(),B=c("div"),B.textContent="Query parameters",x=k(),M=c("table"),ee=c("thead"),ee.innerHTML='<tr><th>Param</th> <th>Type</th> <th width="50%">Description</th></tr>',ue=k(),te=c("tbody"),se(T.$$.fragment),le=k(),O=c("div"),O.textContent="Responses",oe=k(),S=c("div"),F=c("div");for(let e=0;e<g.length;e+=1)g[e].c();me=k(),Q=c("div");for(let e=0;e<b.length;e+=1)b[e].c();p(l,"class","m-b-sm"),p(h,"class","content txt-lg m-b-sm"),p(j,"class","m-b-xs"),p(K,"class","label label-primary"),p(q,"class","content"),p($,"class","alert alert-info"),p(B,"class","section-title"),p(M,"class","table-compact table-border m-b-base"),p(O,"class","section-title"),p(F,"class","tabs-header compact combined left"),p(Q,"class","tabs-content"),p(S,"class","tabs")},m(e,t){d(e,l,t),a(l,o),a(l,_),a(l,f),d(e,i,t),d(e,h,t),a(h,m),a(m,v),a(m,C),a(C,E),a(m,ie),d(e,I,t),ae(P,e,t),d(e,J,t),d(e,j,t),d(e,Y,t),d(e,$,t),a($,K),a($,ce),a($,q),a(q,A),a(A,re),a(A,R),a(R,X),a(A,de),d(e,Z,t),d(e,B,t),d(e,x,t),d(e,M,t),a(M,ee),a(M,ue),a(M,te),ae(T,te,null),d(e,le,t),d(e,O,t),d(e,oe,t),d(e,S,t),a(S,F);for(let r=0;r<g.length;r+=1)g[r]&&g[r].m(F,null);a(S,me),a(S,Q);for(let r=0;r<b.length;r+=1)b[r]&&b[r].m(Q,null);y=!0},p(e,[t]){var ge,we;(!y||t&1)&&s!==(s=e[0].name+"")&&U(_,s),(!y||t&1)&&H!==(H=e[0].name+"")&&U(E,H);const r={};t&9&&(r.js=`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
const result = await pb.collection('${(ge=e[0])==null?void 0:ge.name}').listAuthMethods();
|
||||
`),t&9&&(r.dart=`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
final result = await pb.collection('${(we=e[0])==null?void 0:we.name}').listAuthMethods();
|
||||
`),P.$set(r),(!y||t&1)&&z!==(z=e[0].name+"")&&U(X,z),t&6&&(D=G(e[2]),g=ve(g,t,pe,1,e,D,he,F,je,$e,null,Pe)),t&6&&(N=G(e[2]),Ae(),b=ve(b,t,_e,1,e,N,fe,Q,Be,Me,null,Ce),Oe())},i(e){if(!y){W(P.$$.fragment,e),W(T.$$.fragment,e);for(let t=0;t<N.length;t+=1)W(b[t]);y=!0}},o(e){V(P.$$.fragment,e),V(T.$$.fragment,e);for(let t=0;t<b.length;t+=1)V(b[t]);y=!1},d(e){e&&(u(l),u(i),u(h),u(I),u(J),u(j),u(Y),u($),u(Z),u(B),u(x),u(M),u(le),u(O),u(oe),u(S)),ne(P,e),ne(T);for(let t=0;t<g.length;t+=1)g[t].d();for(let t=0;t<b.length;t+=1)b[t].d()}}}function De(n,l,o){let s,{collection:_}=l,f=200,i=[];const h=m=>o(1,f=m.code);return n.$$set=m=>{"collection"in m&&o(0,_=m.collection)},o(3,s=Fe.getApiExampleUrl(Qe.baseUrl)),o(2,i=[{code:200,body:`
|
||||
{
|
||||
"usernamePassword": true,
|
||||
"emailPassword": true,
|
||||
"authProviders": [
|
||||
{
|
||||
"name": "github",
|
||||
"state": "3Yd8jNkK_6PJG6hPWwBjLqKwse6Ejd",
|
||||
"codeVerifier": "KxFDWz1B3fxscCDJ_9gHQhLuh__ie7",
|
||||
"codeChallenge": "NM1oVexB6Q6QH8uPtOUfK7tq4pmu4Jz6lNDIwoxHZNE=",
|
||||
"codeChallengeMethod": "S256",
|
||||
"authUrl": "https://github.com/login/oauth/authorize?client_id=demo&code_challenge=NM1oVexB6Q6QH8uPtOUfK7tq4pmu4Jz6lNDIwoxHZNE%3D&code_challenge_method=S256&response_type=code&scope=user&state=3Yd8jNkK_6PJG6hPWwBjLqKwse6Ejd&redirect_uri="
|
||||
},
|
||||
{
|
||||
"name": "gitlab",
|
||||
"state": "NeQSbtO5cShr_mk5__3CUukiMnymeb",
|
||||
"codeVerifier": "ahTFHOgua8mkvPAlIBGwCUJbWKR_xi",
|
||||
"codeChallenge": "O-GATkTj4eXDCnfonsqGLCd6njvTixlpCMvy5kjgOOg=",
|
||||
"codeChallengeMethod": "S256",
|
||||
"authUrl": "https://gitlab.com/oauth/authorize?client_id=demo&code_challenge=O-GATkTj4eXDCnfonsqGLCd6njvTixlpCMvy5kjgOOg%3D&code_challenge_method=S256&response_type=code&scope=read_user&state=NeQSbtO5cShr_mk5__3CUukiMnymeb&redirect_uri="
|
||||
},
|
||||
{
|
||||
"name": "google",
|
||||
"state": "zB3ZPifV1TW2GMuvuFkamSXfSNkHPQ",
|
||||
"codeVerifier": "t3CmO5VObGzdXqieakvR_fpjiW0zdO",
|
||||
"codeChallenge": "KChwoQPKYlz2anAdqtgsSTdIo8hdwtc1fh2wHMwW2Yk=",
|
||||
"codeChallengeMethod": "S256",
|
||||
"authUrl": "https://accounts.google.com/o/oauth2/auth?client_id=demo&code_challenge=KChwoQPKYlz2anAdqtgsSTdIo8hdwtc1fh2wHMwW2Yk%3D&code_challenge_method=S256&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&state=zB3ZPifV1TW2GMuvuFkamSXfSNkHPQ&redirect_uri="
|
||||
}
|
||||
]
|
||||
}
|
||||
`}]),[_,f,i,s,h]}class Ve extends Se{constructor(l){super(),ye(this,l,De,ze,Te,{collection:0})}}export{Ve as default};
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import{S as je,i as xe,s as Je,N as Ue,O as J,e as s,w as k,b as p,c as K,f as b,g as d,h as o,m as I,x as de,P as Ee,Q as Ke,k as Ie,R as We,n as Ge,t as N,a as V,o as u,d as W,C as Le,p as Xe,r as G,u as Ye}from"./index-fd9da555.js";import{S as Ze}from"./SdkTabs-9e15e9a4.js";import{F as et}from"./FieldsQueryParam-3fb2414b.js";function Ne(r,l,a){const n=r.slice();return n[5]=l[a],n}function Ve(r,l,a){const n=r.slice();return n[5]=l[a],n}function ze(r,l){let a,n=l[5].code+"",m,_,i,h;function g(){return l[4](l[5])}return{key:r,first:null,c(){a=s("button"),m=k(n),_=p(),b(a,"class","tab-item"),G(a,"active",l[1]===l[5].code),this.first=a},m(v,w){d(v,a,w),o(a,m),o(a,_),i||(h=Ye(a,"click",g),i=!0)},p(v,w){l=v,w&4&&n!==(n=l[5].code+"")&&de(m,n),w&6&&G(a,"active",l[1]===l[5].code)},d(v){v&&u(a),i=!1,h()}}}function Qe(r,l){let a,n,m,_;return n=new Ue({props:{content:l[5].body}}),{key:r,first:null,c(){a=s("div"),K(n.$$.fragment),m=p(),b(a,"class","tab-item"),G(a,"active",l[1]===l[5].code),this.first=a},m(i,h){d(i,a,h),I(n,a,null),o(a,m),_=!0},p(i,h){l=i;const g={};h&4&&(g.content=l[5].body),n.$set(g),(!_||h&6)&&G(a,"active",l[1]===l[5].code)},i(i){_||(N(n.$$.fragment,i),_=!0)},o(i){V(n.$$.fragment,i),_=!1},d(i){i&&u(a),W(n)}}}function tt(r){var De,Fe;let l,a,n=r[0].name+"",m,_,i,h,g,v,w,M,X,S,z,ue,Q,q,pe,Y,U=r[0].name+"",Z,he,fe,j,ee,D,te,T,oe,be,F,C,le,me,ae,_e,f,ke,R,ge,ve,$e,se,ye,ne,Se,we,Te,re,Ce,Pe,A,ie,O,ce,P,H,y=[],Re=new Map,Ae,E,$=[],Be=new Map,B;v=new Ze({props:{js:`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${r[3]}');
|
||||
|
||||
...
|
||||
|
||||
const authData = await pb.collection('${(De=r[0])==null?void 0:De.name}').authRefresh();
|
||||
|
||||
// after the above you can also access the refreshed auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
`,dart:`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${r[3]}');
|
||||
|
||||
...
|
||||
|
||||
final authData = await pb.collection('${(Fe=r[0])==null?void 0:Fe.name}').authRefresh();
|
||||
|
||||
// after the above you can also access the refreshed auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
`}}),R=new Ue({props:{content:"?expand=relField1,relField2.subRelField"}}),A=new et({});let x=J(r[2]);const Me=e=>e[5].code;for(let e=0;e<x.length;e+=1){let t=Ve(r,x,e),c=Me(t);Re.set(c,y[e]=ze(c,t))}let L=J(r[2]);const qe=e=>e[5].code;for(let e=0;e<L.length;e+=1){let t=Ne(r,L,e),c=qe(t);Be.set(c,$[e]=Qe(c,t))}return{c(){l=s("h3"),a=k("Auth refresh ("),m=k(n),_=k(")"),i=p(),h=s("div"),h.innerHTML=`<p>Returns a new auth response (token and record data) for an
|
||||
<strong>already authenticated record</strong>.</p> <p><em>This method is usually called by users on page/screen reload to ensure that the previously stored
|
||||
data in <code>pb.authStore</code> is still valid and up-to-date.</em></p>`,g=p(),K(v.$$.fragment),w=p(),M=s("h6"),M.textContent="API details",X=p(),S=s("div"),z=s("strong"),z.textContent="POST",ue=p(),Q=s("div"),q=s("p"),pe=k("/api/collections/"),Y=s("strong"),Z=k(U),he=k("/auth-refresh"),fe=p(),j=s("p"),j.innerHTML="Requires record <code>Authorization:TOKEN</code> header",ee=p(),D=s("div"),D.textContent="Query parameters",te=p(),T=s("table"),oe=s("thead"),oe.innerHTML='<tr><th>Param</th> <th>Type</th> <th width="60%">Description</th></tr>',be=p(),F=s("tbody"),C=s("tr"),le=s("td"),le.textContent="expand",me=p(),ae=s("td"),ae.innerHTML='<span class="label">String</span>',_e=p(),f=s("td"),ke=k(`Auto expand record relations. Ex.:
|
||||
`),K(R.$$.fragment),ge=k(`
|
||||
Supports up to 6-levels depth nested relations expansion. `),ve=s("br"),$e=k(`
|
||||
The expanded relations will be appended to the record under the
|
||||
`),se=s("code"),se.textContent="expand",ye=k(" property (eg. "),ne=s("code"),ne.textContent='"expand": {"relField1": {...}, ...}',Se=k(`).
|
||||
`),we=s("br"),Te=k(`
|
||||
Only the relations to which the request user has permissions to `),re=s("strong"),re.textContent="view",Ce=k(" will be expanded."),Pe=p(),K(A.$$.fragment),ie=p(),O=s("div"),O.textContent="Responses",ce=p(),P=s("div"),H=s("div");for(let e=0;e<y.length;e+=1)y[e].c();Ae=p(),E=s("div");for(let e=0;e<$.length;e+=1)$[e].c();b(l,"class","m-b-sm"),b(h,"class","content txt-lg m-b-sm"),b(M,"class","m-b-xs"),b(z,"class","label label-primary"),b(Q,"class","content"),b(j,"class","txt-hint txt-sm txt-right"),b(S,"class","alert alert-success"),b(D,"class","section-title"),b(T,"class","table-compact table-border m-b-base"),b(O,"class","section-title"),b(H,"class","tabs-header compact combined left"),b(E,"class","tabs-content"),b(P,"class","tabs")},m(e,t){d(e,l,t),o(l,a),o(l,m),o(l,_),d(e,i,t),d(e,h,t),d(e,g,t),I(v,e,t),d(e,w,t),d(e,M,t),d(e,X,t),d(e,S,t),o(S,z),o(S,ue),o(S,Q),o(Q,q),o(q,pe),o(q,Y),o(Y,Z),o(q,he),o(S,fe),o(S,j),d(e,ee,t),d(e,D,t),d(e,te,t),d(e,T,t),o(T,oe),o(T,be),o(T,F),o(F,C),o(C,le),o(C,me),o(C,ae),o(C,_e),o(C,f),o(f,ke),I(R,f,null),o(f,ge),o(f,ve),o(f,$e),o(f,se),o(f,ye),o(f,ne),o(f,Se),o(f,we),o(f,Te),o(f,re),o(f,Ce),o(F,Pe),I(A,F,null),d(e,ie,t),d(e,O,t),d(e,ce,t),d(e,P,t),o(P,H);for(let c=0;c<y.length;c+=1)y[c]&&y[c].m(H,null);o(P,Ae),o(P,E);for(let c=0;c<$.length;c+=1)$[c]&&$[c].m(E,null);B=!0},p(e,[t]){var Oe,He;(!B||t&1)&&n!==(n=e[0].name+"")&&de(m,n);const c={};t&9&&(c.js=`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
const authData = await pb.collection('${(Oe=e[0])==null?void 0:Oe.name}').authRefresh();
|
||||
|
||||
// after the above you can also access the refreshed auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
`),t&9&&(c.dart=`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
final authData = await pb.collection('${(He=e[0])==null?void 0:He.name}').authRefresh();
|
||||
|
||||
// after the above you can also access the refreshed auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
`),v.$set(c),(!B||t&1)&&U!==(U=e[0].name+"")&&de(Z,U),t&6&&(x=J(e[2]),y=Ee(y,t,Me,1,e,x,Re,H,Ke,ze,null,Ve)),t&6&&(L=J(e[2]),Ie(),$=Ee($,t,qe,1,e,L,Be,E,We,Qe,null,Ne),Ge())},i(e){if(!B){N(v.$$.fragment,e),N(R.$$.fragment,e),N(A.$$.fragment,e);for(let t=0;t<L.length;t+=1)N($[t]);B=!0}},o(e){V(v.$$.fragment,e),V(R.$$.fragment,e),V(A.$$.fragment,e);for(let t=0;t<$.length;t+=1)V($[t]);B=!1},d(e){e&&(u(l),u(i),u(h),u(g),u(w),u(M),u(X),u(S),u(ee),u(D),u(te),u(T),u(ie),u(O),u(ce),u(P)),W(v,e),W(R),W(A);for(let t=0;t<y.length;t+=1)y[t].d();for(let t=0;t<$.length;t+=1)$[t].d()}}}function ot(r,l,a){let n,{collection:m}=l,_=200,i=[];const h=g=>a(1,_=g.code);return r.$$set=g=>{"collection"in g&&a(0,m=g.collection)},r.$$.update=()=>{r.$$.dirty&1&&a(2,i=[{code:200,body:JSON.stringify({token:"JWT_TOKEN",record:Le.dummyCollectionRecord(m)},null,2)},{code:401,body:`
|
||||
{
|
||||
"code": 401,
|
||||
"message": "The request requires valid record authorization token to be set.",
|
||||
"data": {}
|
||||
}
|
||||
`},{code:403,body:`
|
||||
{
|
||||
"code": 403,
|
||||
"message": "The authorized record model is not allowed to perform this action.",
|
||||
"data": {}
|
||||
}
|
||||
`},{code:404,body:`
|
||||
{
|
||||
"code": 404,
|
||||
"message": "Missing auth record context.",
|
||||
"data": {}
|
||||
}
|
||||
`}])},a(3,n=Le.getApiExampleUrl(Xe.baseUrl)),[m,_,i,n,h]}class nt extends je{constructor(l){super(),xe(this,l,ot,tt,Je,{collection:0})}}export{nt as default};
|
||||
-82
@@ -1,82 +0,0 @@
|
||||
import{S as Ue,i as je,s as xe,M as Qe,e as s,w as k,b as p,c as J,f as b,g as d,h as o,m as K,x as ce,N as Oe,P as Je,k as Ke,Q as Ie,n as We,t as N,a as V,o as u,d as I,T as Ge,C as Ee,p as Xe,r as W,u as Ye}from"./index-42f47088.js";import{S as Ze}from"./SdkTabs-81470834.js";import{F as et}from"./FieldsQueryParam-582f34bb.js";function Le(r,l,a){const n=r.slice();return n[5]=l[a],n}function Ne(r,l,a){const n=r.slice();return n[5]=l[a],n}function Ve(r,l){let a,n=l[5].code+"",m,_,i,f;function v(){return l[4](l[5])}return{key:r,first:null,c(){a=s("button"),m=k(n),_=p(),b(a,"class","tab-item"),W(a,"active",l[1]===l[5].code),this.first=a},m($,w){d($,a,w),o(a,m),o(a,_),i||(f=Ye(a,"click",v),i=!0)},p($,w){l=$,w&4&&n!==(n=l[5].code+"")&&ce(m,n),w&6&&W(a,"active",l[1]===l[5].code)},d($){$&&u(a),i=!1,f()}}}function ze(r,l){let a,n,m,_;return n=new Qe({props:{content:l[5].body}}),{key:r,first:null,c(){a=s("div"),J(n.$$.fragment),m=p(),b(a,"class","tab-item"),W(a,"active",l[1]===l[5].code),this.first=a},m(i,f){d(i,a,f),K(n,a,null),o(a,m),_=!0},p(i,f){l=i;const v={};f&4&&(v.content=l[5].body),n.$set(v),(!_||f&6)&&W(a,"active",l[1]===l[5].code)},i(i){_||(N(n.$$.fragment,i),_=!0)},o(i){V(n.$$.fragment,i),_=!1},d(i){i&&u(a),I(n)}}}function tt(r){var qe,De;let l,a,n=r[0].name+"",m,_,i,f,v,$,w,B,G,S,z,de,Q,q,ue,X,U=r[0].name+"",Y,pe,fe,j,Z,D,ee,T,te,he,F,C,oe,be,le,me,h,_e,R,ke,ve,$e,ae,ge,se,ye,Se,we,ne,Te,Ce,M,re,H,ie,P,O,y=[],Pe=new Map,Re,E,g=[],Me=new Map,A;$=new Ze({props:{js:`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${r[3]}');
|
||||
|
||||
...
|
||||
|
||||
const authData = await pb.collection('${(qe=r[0])==null?void 0:qe.name}').authRefresh();
|
||||
|
||||
// after the above you can also access the refreshed auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
`,dart:`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${r[3]}');
|
||||
|
||||
...
|
||||
|
||||
final authData = await pb.collection('${(De=r[0])==null?void 0:De.name}').authRefresh();
|
||||
|
||||
// after the above you can also access the refreshed auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
`}}),R=new Qe({props:{content:"?expand=relField1,relField2.subRelField"}}),M=new et({});let x=r[2];const Ae=e=>e[5].code;for(let e=0;e<x.length;e+=1){let t=Ne(r,x,e),c=Ae(t);Pe.set(c,y[e]=Ve(c,t))}let L=r[2];const Be=e=>e[5].code;for(let e=0;e<L.length;e+=1){let t=Le(r,L,e),c=Be(t);Me.set(c,g[e]=ze(c,t))}return{c(){l=s("h3"),a=k("Auth refresh ("),m=k(n),_=k(")"),i=p(),f=s("div"),f.innerHTML=`<p>Returns a new auth response (token and record data) for an
|
||||
<strong>already authenticated record</strong>.</p>
|
||||
<p><em>This method is usually called by users on page/screen reload to ensure that the previously stored
|
||||
data in <code>pb.authStore</code> is still valid and up-to-date.</em></p>`,v=p(),J($.$$.fragment),w=p(),B=s("h6"),B.textContent="API details",G=p(),S=s("div"),z=s("strong"),z.textContent="POST",de=p(),Q=s("div"),q=s("p"),ue=k("/api/collections/"),X=s("strong"),Y=k(U),pe=k("/auth-refresh"),fe=p(),j=s("p"),j.innerHTML="Requires record <code>Authorization:TOKEN</code> header",Z=p(),D=s("div"),D.textContent="Query parameters",ee=p(),T=s("table"),te=s("thead"),te.innerHTML=`<tr><th>Param</th>
|
||||
<th>Type</th>
|
||||
<th width="60%">Description</th></tr>`,he=p(),F=s("tbody"),C=s("tr"),oe=s("td"),oe.textContent="expand",be=p(),le=s("td"),le.innerHTML='<span class="label">String</span>',me=p(),h=s("td"),_e=k(`Auto expand record relations. Ex.:
|
||||
`),J(R.$$.fragment),ke=k(`
|
||||
Supports up to 6-levels depth nested relations expansion. `),ve=s("br"),$e=k(`
|
||||
The expanded relations will be appended to the record under the
|
||||
`),ae=s("code"),ae.textContent="expand",ge=k(" property (eg. "),se=s("code"),se.textContent='"expand": {"relField1": {...}, ...}',ye=k(`).
|
||||
`),Se=s("br"),we=k(`
|
||||
Only the relations to which the request user has permissions to `),ne=s("strong"),ne.textContent="view",Te=k(" will be expanded."),Ce=p(),J(M.$$.fragment),re=p(),H=s("div"),H.textContent="Responses",ie=p(),P=s("div"),O=s("div");for(let e=0;e<y.length;e+=1)y[e].c();Re=p(),E=s("div");for(let e=0;e<g.length;e+=1)g[e].c();b(l,"class","m-b-sm"),b(f,"class","content txt-lg m-b-sm"),b(B,"class","m-b-xs"),b(z,"class","label label-primary"),b(Q,"class","content"),b(j,"class","txt-hint txt-sm txt-right"),b(S,"class","alert alert-success"),b(D,"class","section-title"),b(T,"class","table-compact table-border m-b-base"),b(H,"class","section-title"),b(O,"class","tabs-header compact left"),b(E,"class","tabs-content"),b(P,"class","tabs")},m(e,t){d(e,l,t),o(l,a),o(l,m),o(l,_),d(e,i,t),d(e,f,t),d(e,v,t),K($,e,t),d(e,w,t),d(e,B,t),d(e,G,t),d(e,S,t),o(S,z),o(S,de),o(S,Q),o(Q,q),o(q,ue),o(q,X),o(X,Y),o(q,pe),o(S,fe),o(S,j),d(e,Z,t),d(e,D,t),d(e,ee,t),d(e,T,t),o(T,te),o(T,he),o(T,F),o(F,C),o(C,oe),o(C,be),o(C,le),o(C,me),o(C,h),o(h,_e),K(R,h,null),o(h,ke),o(h,ve),o(h,$e),o(h,ae),o(h,ge),o(h,se),o(h,ye),o(h,Se),o(h,we),o(h,ne),o(h,Te),o(F,Ce),K(M,F,null),d(e,re,t),d(e,H,t),d(e,ie,t),d(e,P,t),o(P,O);for(let c=0;c<y.length;c+=1)y[c]&&y[c].m(O,null);o(P,Re),o(P,E);for(let c=0;c<g.length;c+=1)g[c]&&g[c].m(E,null);A=!0},p(e,[t]){var Fe,He;(!A||t&1)&&n!==(n=e[0].name+"")&&ce(m,n);const c={};t&9&&(c.js=`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
const authData = await pb.collection('${(Fe=e[0])==null?void 0:Fe.name}').authRefresh();
|
||||
|
||||
// after the above you can also access the refreshed auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
`),t&9&&(c.dart=`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
final authData = await pb.collection('${(He=e[0])==null?void 0:He.name}').authRefresh();
|
||||
|
||||
// after the above you can also access the refreshed auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
`),$.$set(c),(!A||t&1)&&U!==(U=e[0].name+"")&&ce(Y,U),t&6&&(x=e[2],y=Oe(y,t,Ae,1,e,x,Pe,O,Je,Ve,null,Ne)),t&6&&(L=e[2],Ke(),g=Oe(g,t,Be,1,e,L,Me,E,Ie,ze,null,Le),We())},i(e){if(!A){N($.$$.fragment,e),N(R.$$.fragment,e),N(M.$$.fragment,e);for(let t=0;t<L.length;t+=1)N(g[t]);A=!0}},o(e){V($.$$.fragment,e),V(R.$$.fragment,e),V(M.$$.fragment,e);for(let t=0;t<g.length;t+=1)V(g[t]);A=!1},d(e){e&&u(l),e&&u(i),e&&u(f),e&&u(v),I($,e),e&&u(w),e&&u(B),e&&u(G),e&&u(S),e&&u(Z),e&&u(D),e&&u(ee),e&&u(T),I(R),I(M),e&&u(re),e&&u(H),e&&u(ie),e&&u(P);for(let t=0;t<y.length;t+=1)y[t].d();for(let t=0;t<g.length;t+=1)g[t].d()}}}function ot(r,l,a){let n,{collection:m=new Ge}=l,_=200,i=[];const f=v=>a(1,_=v.code);return r.$$set=v=>{"collection"in v&&a(0,m=v.collection)},r.$$.update=()=>{r.$$.dirty&1&&a(2,i=[{code:200,body:JSON.stringify({token:"JWT_TOKEN",record:Ee.dummyCollectionRecord(m)},null,2)},{code:401,body:`
|
||||
{
|
||||
"code": 401,
|
||||
"message": "The request requires valid record authorization token to be set.",
|
||||
"data": {}
|
||||
}
|
||||
`},{code:403,body:`
|
||||
{
|
||||
"code": 403,
|
||||
"message": "The authorized record model is not allowed to perform this action.",
|
||||
"data": {}
|
||||
}
|
||||
`},{code:404,body:`
|
||||
{
|
||||
"code": 404,
|
||||
"message": "Missing auth record context.",
|
||||
"data": {}
|
||||
}
|
||||
`}])},a(3,n=Ee.getApiExampleUrl(Xe.baseUrl)),[m,_,i,n,f]}class nt extends Ue{constructor(l){super(),je(this,l,ot,tt,xe,{collection:0})}}export{nt as default};
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
import{S as Le,i as Ee,s as Je,N as Ve,O as z,e as s,w as k,b as h,c as I,f as p,g as r,h as a,m as K,x as pe,P as We,Q as Ne,k as Qe,R as ze,n as Ie,t as V,a as L,o as c,d as G,C as Ue,p as Ke,r as X,u as Ge}from"./index-fd9da555.js";import{S as Xe}from"./SdkTabs-9e15e9a4.js";import{F as Ye}from"./FieldsQueryParam-3fb2414b.js";function Be(i,l,o){const n=i.slice();return n[5]=l[o],n}function Fe(i,l,o){const n=i.slice();return n[5]=l[o],n}function He(i,l){let o,n=l[5].code+"",f,g,d,b;function _(){return l[4](l[5])}return{key:i,first:null,c(){o=s("button"),f=k(n),g=h(),p(o,"class","tab-item"),X(o,"active",l[1]===l[5].code),this.first=o},m(v,A){r(v,o,A),a(o,f),a(o,g),d||(b=Ge(o,"click",_),d=!0)},p(v,A){l=v,A&4&&n!==(n=l[5].code+"")&&pe(f,n),A&6&&X(o,"active",l[1]===l[5].code)},d(v){v&&c(o),d=!1,b()}}}function je(i,l){let o,n,f,g;return n=new Ve({props:{content:l[5].body}}),{key:i,first:null,c(){o=s("div"),I(n.$$.fragment),f=h(),p(o,"class","tab-item"),X(o,"active",l[1]===l[5].code),this.first=o},m(d,b){r(d,o,b),K(n,o,null),a(o,f),g=!0},p(d,b){l=d;const _={};b&4&&(_.content=l[5].body),n.$set(_),(!g||b&6)&&X(o,"active",l[1]===l[5].code)},i(d){g||(V(n.$$.fragment,d),g=!0)},o(d){L(n.$$.fragment,d),g=!1},d(d){d&&c(o),G(n)}}}function Ze(i){let l,o,n=i[0].name+"",f,g,d,b,_,v,A,P,Y,S,E,be,J,R,me,Z,N=i[0].name+"",ee,fe,te,M,ae,x,le,W,oe,y,se,ge,U,$,ne,ke,ie,_e,m,ve,C,we,Oe,Ae,re,Se,ce,ye,$e,Te,de,Ce,qe,q,ue,B,he,T,F,O=[],De=new Map,Pe,H,w=[],Re=new Map,D;v=new Xe({props:{js:`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${i[3]}');
|
||||
|
||||
...
|
||||
|
||||
// OAuth2 authentication with a single realtime call.
|
||||
//
|
||||
// Make sure to register ${i[3]}/api/oauth2-redirect as redirect url.
|
||||
const authData = await pb.collection('users').authWithOAuth2({ provider: 'google' });
|
||||
|
||||
// OR authenticate with manual OAuth2 code exchange
|
||||
// const authData = await pb.collection('users').authWithOAuth2Code(...);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated model
|
||||
pb.authStore.clear();
|
||||
`,dart:`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
final pb = PocketBase('${i[3]}');
|
||||
|
||||
...
|
||||
|
||||
// OAuth2 authentication with a single realtime call.
|
||||
//
|
||||
// Make sure to register ${i[3]}/api/oauth2-redirect as redirect url.
|
||||
final authData = await pb.collection('users').authWithOAuth2('google', (url) async {
|
||||
await launchUrl(url);
|
||||
});
|
||||
|
||||
// OR authenticate with manual OAuth2 code exchange
|
||||
// final authData = await pb.collection('users').authWithOAuth2Code(...);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated model
|
||||
pb.authStore.clear();
|
||||
`}}),C=new Ve({props:{content:"?expand=relField1,relField2.subRelField"}}),q=new Ye({});let Q=z(i[2]);const Me=e=>e[5].code;for(let e=0;e<Q.length;e+=1){let t=Fe(i,Q,e),u=Me(t);De.set(u,O[e]=He(u,t))}let j=z(i[2]);const xe=e=>e[5].code;for(let e=0;e<j.length;e+=1){let t=Be(i,j,e),u=xe(t);Re.set(u,w[e]=je(u,t))}return{c(){l=s("h3"),o=k("Auth with OAuth2 ("),f=k(n),g=k(")"),d=h(),b=s("div"),b.innerHTML=`<p>Authenticate with an OAuth2 provider and returns a new auth token and record data.</p> <p>For more details please check the
|
||||
<a href="https://pocketbase.io/docs/authentication/#oauth2-integration" target="_blank" rel="noopener noreferrer">OAuth2 integration documentation
|
||||
</a>.</p>`,_=h(),I(v.$$.fragment),A=h(),P=s("h6"),P.textContent="API details",Y=h(),S=s("div"),E=s("strong"),E.textContent="POST",be=h(),J=s("div"),R=s("p"),me=k("/api/collections/"),Z=s("strong"),ee=k(N),fe=k("/auth-with-oauth2"),te=h(),M=s("div"),M.textContent="Body Parameters",ae=h(),x=s("table"),x.innerHTML=`<thead><tr><th>Param</th> <th>Type</th> <th width="50%">Description</th></tr></thead> <tbody><tr><td><div class="inline-flex"><span class="label label-success">Required</span> <span>provider</span></div></td> <td><span class="label">String</span></td> <td>The name of the OAuth2 client provider (eg. "google").</td></tr> <tr><td><div class="inline-flex"><span class="label label-success">Required</span> <span>code</span></div></td> <td><span class="label">String</span></td> <td>The authorization code returned from the initial request.</td></tr> <tr><td><div class="inline-flex"><span class="label label-success">Required</span> <span>codeVerifier</span></div></td> <td><span class="label">String</span></td> <td>The code verifier sent with the initial request as part of the code_challenge.</td></tr> <tr><td><div class="inline-flex"><span class="label label-success">Required</span> <span>redirectUrl</span></div></td> <td><span class="label">String</span></td> <td>The redirect url sent with the initial request.</td></tr> <tr><td><div class="inline-flex"><span class="label label-warning">Optional</span> <span>createData</span></div></td> <td><span class="label">Object</span></td> <td><p>Optional data that will be used when creating the auth record on OAuth2 sign-up.</p> <p>The created auth record must comply with the same requirements and validations in the
|
||||
regular <strong>create</strong> action.
|
||||
<br/> <em>The data can only be in <code>json</code>, aka. <code>multipart/form-data</code> and files
|
||||
upload currently are not supported during OAuth2 sign-ups.</em></p></td></tr></tbody>`,le=h(),W=s("div"),W.textContent="Query parameters",oe=h(),y=s("table"),se=s("thead"),se.innerHTML='<tr><th>Param</th> <th>Type</th> <th width="60%">Description</th></tr>',ge=h(),U=s("tbody"),$=s("tr"),ne=s("td"),ne.textContent="expand",ke=h(),ie=s("td"),ie.innerHTML='<span class="label">String</span>',_e=h(),m=s("td"),ve=k(`Auto expand record relations. Ex.:
|
||||
`),I(C.$$.fragment),we=k(`
|
||||
Supports up to 6-levels depth nested relations expansion. `),Oe=s("br"),Ae=k(`
|
||||
The expanded relations will be appended to the record under the
|
||||
`),re=s("code"),re.textContent="expand",Se=k(" property (eg. "),ce=s("code"),ce.textContent='"expand": {"relField1": {...}, ...}',ye=k(`).
|
||||
`),$e=s("br"),Te=k(`
|
||||
Only the relations to which the request user has permissions to `),de=s("strong"),de.textContent="view",Ce=k(" will be expanded."),qe=h(),I(q.$$.fragment),ue=h(),B=s("div"),B.textContent="Responses",he=h(),T=s("div"),F=s("div");for(let e=0;e<O.length;e+=1)O[e].c();Pe=h(),H=s("div");for(let e=0;e<w.length;e+=1)w[e].c();p(l,"class","m-b-sm"),p(b,"class","content txt-lg m-b-sm"),p(P,"class","m-b-xs"),p(E,"class","label label-primary"),p(J,"class","content"),p(S,"class","alert alert-success"),p(M,"class","section-title"),p(x,"class","table-compact table-border m-b-base"),p(W,"class","section-title"),p(y,"class","table-compact table-border m-b-base"),p(B,"class","section-title"),p(F,"class","tabs-header compact combined left"),p(H,"class","tabs-content"),p(T,"class","tabs")},m(e,t){r(e,l,t),a(l,o),a(l,f),a(l,g),r(e,d,t),r(e,b,t),r(e,_,t),K(v,e,t),r(e,A,t),r(e,P,t),r(e,Y,t),r(e,S,t),a(S,E),a(S,be),a(S,J),a(J,R),a(R,me),a(R,Z),a(Z,ee),a(R,fe),r(e,te,t),r(e,M,t),r(e,ae,t),r(e,x,t),r(e,le,t),r(e,W,t),r(e,oe,t),r(e,y,t),a(y,se),a(y,ge),a(y,U),a(U,$),a($,ne),a($,ke),a($,ie),a($,_e),a($,m),a(m,ve),K(C,m,null),a(m,we),a(m,Oe),a(m,Ae),a(m,re),a(m,Se),a(m,ce),a(m,ye),a(m,$e),a(m,Te),a(m,de),a(m,Ce),a(U,qe),K(q,U,null),r(e,ue,t),r(e,B,t),r(e,he,t),r(e,T,t),a(T,F);for(let u=0;u<O.length;u+=1)O[u]&&O[u].m(F,null);a(T,Pe),a(T,H);for(let u=0;u<w.length;u+=1)w[u]&&w[u].m(H,null);D=!0},p(e,[t]){(!D||t&1)&&n!==(n=e[0].name+"")&&pe(f,n);const u={};t&8&&(u.js=`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
// OAuth2 authentication with a single realtime call.
|
||||
//
|
||||
// Make sure to register ${e[3]}/api/oauth2-redirect as redirect url.
|
||||
const authData = await pb.collection('users').authWithOAuth2({ provider: 'google' });
|
||||
|
||||
// OR authenticate with manual OAuth2 code exchange
|
||||
// const authData = await pb.collection('users').authWithOAuth2Code(...);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated model
|
||||
pb.authStore.clear();
|
||||
`),t&8&&(u.dart=`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
final pb = PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
// OAuth2 authentication with a single realtime call.
|
||||
//
|
||||
// Make sure to register ${e[3]}/api/oauth2-redirect as redirect url.
|
||||
final authData = await pb.collection('users').authWithOAuth2('google', (url) async {
|
||||
await launchUrl(url);
|
||||
});
|
||||
|
||||
// OR authenticate with manual OAuth2 code exchange
|
||||
// final authData = await pb.collection('users').authWithOAuth2Code(...);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated model
|
||||
pb.authStore.clear();
|
||||
`),v.$set(u),(!D||t&1)&&N!==(N=e[0].name+"")&&pe(ee,N),t&6&&(Q=z(e[2]),O=We(O,t,Me,1,e,Q,De,F,Ne,He,null,Fe)),t&6&&(j=z(e[2]),Qe(),w=We(w,t,xe,1,e,j,Re,H,ze,je,null,Be),Ie())},i(e){if(!D){V(v.$$.fragment,e),V(C.$$.fragment,e),V(q.$$.fragment,e);for(let t=0;t<j.length;t+=1)V(w[t]);D=!0}},o(e){L(v.$$.fragment,e),L(C.$$.fragment,e),L(q.$$.fragment,e);for(let t=0;t<w.length;t+=1)L(w[t]);D=!1},d(e){e&&(c(l),c(d),c(b),c(_),c(A),c(P),c(Y),c(S),c(te),c(M),c(ae),c(x),c(le),c(W),c(oe),c(y),c(ue),c(B),c(he),c(T)),G(v,e),G(C),G(q);for(let t=0;t<O.length;t+=1)O[t].d();for(let t=0;t<w.length;t+=1)w[t].d()}}}function et(i,l,o){let n,{collection:f}=l,g=200,d=[];const b=_=>o(1,g=_.code);return i.$$set=_=>{"collection"in _&&o(0,f=_.collection)},i.$$.update=()=>{i.$$.dirty&1&&o(2,d=[{code:200,body:JSON.stringify({token:"JWT_AUTH_TOKEN",record:Ue.dummyCollectionRecord(f),meta:{id:"abc123",name:"John Doe",username:"john.doe",email:"test@example.com",avatarUrl:"https://example.com/avatar.png",accessToken:"...",refreshToken:"...",rawUser:{}}},null,2)},{code:400,body:`
|
||||
{
|
||||
"code": 400,
|
||||
"message": "An error occurred while submitting the form.",
|
||||
"data": {
|
||||
"provider": {
|
||||
"code": "validation_required",
|
||||
"message": "Missing required value."
|
||||
}
|
||||
}
|
||||
}
|
||||
`}])},o(3,n=Ue.getApiExampleUrl(Ke.baseUrl)),[f,g,d,n,b]}class ot extends Le{constructor(l){super(),Ee(this,l,et,Ze,Je,{collection:0})}}export{ot as default};
|
||||
-144
@@ -1,144 +0,0 @@
|
||||
import{S as Ve,i as Le,s as Ee,M as je,e as s,w as k,b as h,c as z,f as p,g as r,h as a,m as I,x as he,N as xe,P as Je,k as Ne,Q as Qe,n as ze,t as V,a as L,o as c,d as K,T as Ie,C as We,p as Ke,r as G,u as Ge}from"./index-42f47088.js";import{S as Xe}from"./SdkTabs-81470834.js";import{F as Ye}from"./FieldsQueryParam-582f34bb.js";function Ue(i,l,o){const n=i.slice();return n[5]=l[o],n}function Be(i,l,o){const n=i.slice();return n[5]=l[o],n}function Fe(i,l){let o,n=l[5].code+"",m,g,u,b;function _(){return l[4](l[5])}return{key:i,first:null,c(){o=s("button"),m=k(n),g=h(),p(o,"class","tab-item"),G(o,"active",l[1]===l[5].code),this.first=o},m(v,A){r(v,o,A),a(o,m),a(o,g),u||(b=Ge(o,"click",_),u=!0)},p(v,A){l=v,A&4&&n!==(n=l[5].code+"")&&he(m,n),A&6&&G(o,"active",l[1]===l[5].code)},d(v){v&&c(o),u=!1,b()}}}function He(i,l){let o,n,m,g;return n=new je({props:{content:l[5].body}}),{key:i,first:null,c(){o=s("div"),z(n.$$.fragment),m=h(),p(o,"class","tab-item"),G(o,"active",l[1]===l[5].code),this.first=o},m(u,b){r(u,o,b),I(n,o,null),a(o,m),g=!0},p(u,b){l=u;const _={};b&4&&(_.content=l[5].body),n.$set(_),(!g||b&6)&&G(o,"active",l[1]===l[5].code)},i(u){g||(V(n.$$.fragment,u),g=!0)},o(u){L(n.$$.fragment,u),g=!1},d(u){u&&c(o),K(n)}}}function Ze(i){let l,o,n=i[0].name+"",m,g,u,b,_,v,A,P,X,S,E,pe,J,M,be,Y,N=i[0].name+"",Z,fe,ee,R,te,x,ae,W,le,y,oe,me,U,$,se,ge,ne,ke,f,_e,C,ve,we,Oe,ie,Ae,re,Se,ye,$e,ce,Te,Ce,q,ue,B,de,T,F,O=[],qe=new Map,De,H,w=[],Pe=new Map,D;v=new Xe({props:{js:`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${i[3]}');
|
||||
|
||||
...
|
||||
|
||||
// OAuth2 authentication with a single realtime call.
|
||||
//
|
||||
// Make sure to register ${i[3]}/api/oauth2-redirect as redirect url.
|
||||
const authData = await pb.collection('users').authWithOAuth2({ provider: 'google' });
|
||||
|
||||
// OR authenticate with manual OAuth2 code exchange
|
||||
// const authData = await pb.collection('users').authWithOAuth2Code(...);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated model
|
||||
pb.authStore.clear();
|
||||
`,dart:`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
final pb = PocketBase('${i[3]}');
|
||||
|
||||
...
|
||||
|
||||
// OAuth2 authentication with a single realtime call.
|
||||
//
|
||||
// Make sure to register ${i[3]}/api/oauth2-redirect as redirect url.
|
||||
final authData = await pb.collection('users').authWithOAuth2('google', (url) async {
|
||||
await launchUrl(url);
|
||||
});
|
||||
|
||||
// OR authenticate with manual OAuth2 code exchange
|
||||
// final authData = await pb.collection('users').authWithOAuth2Code(...);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated model
|
||||
pb.authStore.clear();
|
||||
`}}),C=new je({props:{content:"?expand=relField1,relField2.subRelField"}}),q=new Ye({});let Q=i[2];const Me=e=>e[5].code;for(let e=0;e<Q.length;e+=1){let t=Be(i,Q,e),d=Me(t);qe.set(d,O[e]=Fe(d,t))}let j=i[2];const Re=e=>e[5].code;for(let e=0;e<j.length;e+=1){let t=Ue(i,j,e),d=Re(t);Pe.set(d,w[e]=He(d,t))}return{c(){l=s("h3"),o=k("Auth with OAuth2 ("),m=k(n),g=k(")"),u=h(),b=s("div"),b.innerHTML=`<p>Authenticate with an OAuth2 provider and returns a new auth token and record data.</p>
|
||||
<p>For more details please check the
|
||||
<a href="https://pocketbase.io/docs/authentication/#oauth2-integration" target="_blank" rel="noopener noreferrer">OAuth2 integration documentation
|
||||
</a>.</p>`,_=h(),z(v.$$.fragment),A=h(),P=s("h6"),P.textContent="API details",X=h(),S=s("div"),E=s("strong"),E.textContent="POST",pe=h(),J=s("div"),M=s("p"),be=k("/api/collections/"),Y=s("strong"),Z=k(N),fe=k("/auth-with-oauth2"),ee=h(),R=s("div"),R.textContent="Body Parameters",te=h(),x=s("table"),x.innerHTML=`<thead><tr><th>Param</th>
|
||||
<th>Type</th>
|
||||
<th width="50%">Description</th></tr></thead>
|
||||
<tbody><tr><td><div class="inline-flex"><span class="label label-success">Required</span>
|
||||
<span>provider</span></div></td>
|
||||
<td><span class="label">String</span></td>
|
||||
<td>The name of the OAuth2 client provider (eg. "google").</td></tr>
|
||||
<tr><td><div class="inline-flex"><span class="label label-success">Required</span>
|
||||
<span>code</span></div></td>
|
||||
<td><span class="label">String</span></td>
|
||||
<td>The authorization code returned from the initial request.</td></tr>
|
||||
<tr><td><div class="inline-flex"><span class="label label-success">Required</span>
|
||||
<span>codeVerifier</span></div></td>
|
||||
<td><span class="label">String</span></td>
|
||||
<td>The code verifier sent with the initial request as part of the code_challenge.</td></tr>
|
||||
<tr><td><div class="inline-flex"><span class="label label-success">Required</span>
|
||||
<span>redirectUrl</span></div></td>
|
||||
<td><span class="label">String</span></td>
|
||||
<td>The redirect url sent with the initial request.</td></tr>
|
||||
<tr><td><div class="inline-flex"><span class="label label-warning">Optional</span>
|
||||
<span>createData</span></div></td>
|
||||
<td><span class="label">Object</span></td>
|
||||
<td><p>Optional data that will be used when creating the auth record on OAuth2 sign-up.</p>
|
||||
<p>The created auth record must comply with the same requirements and validations in the
|
||||
regular <strong>create</strong> action.
|
||||
<br/>
|
||||
<em>The data can only be in <code>json</code>, aka. <code>multipart/form-data</code> and files
|
||||
upload currently are not supported during OAuth2 sign-ups.</em></p></td></tr></tbody>`,ae=h(),W=s("div"),W.textContent="Query parameters",le=h(),y=s("table"),oe=s("thead"),oe.innerHTML=`<tr><th>Param</th>
|
||||
<th>Type</th>
|
||||
<th width="60%">Description</th></tr>`,me=h(),U=s("tbody"),$=s("tr"),se=s("td"),se.textContent="expand",ge=h(),ne=s("td"),ne.innerHTML='<span class="label">String</span>',ke=h(),f=s("td"),_e=k(`Auto expand record relations. Ex.:
|
||||
`),z(C.$$.fragment),ve=k(`
|
||||
Supports up to 6-levels depth nested relations expansion. `),we=s("br"),Oe=k(`
|
||||
The expanded relations will be appended to the record under the
|
||||
`),ie=s("code"),ie.textContent="expand",Ae=k(" property (eg. "),re=s("code"),re.textContent='"expand": {"relField1": {...}, ...}',Se=k(`).
|
||||
`),ye=s("br"),$e=k(`
|
||||
Only the relations to which the request user has permissions to `),ce=s("strong"),ce.textContent="view",Te=k(" will be expanded."),Ce=h(),z(q.$$.fragment),ue=h(),B=s("div"),B.textContent="Responses",de=h(),T=s("div"),F=s("div");for(let e=0;e<O.length;e+=1)O[e].c();De=h(),H=s("div");for(let e=0;e<w.length;e+=1)w[e].c();p(l,"class","m-b-sm"),p(b,"class","content txt-lg m-b-sm"),p(P,"class","m-b-xs"),p(E,"class","label label-primary"),p(J,"class","content"),p(S,"class","alert alert-success"),p(R,"class","section-title"),p(x,"class","table-compact table-border m-b-base"),p(W,"class","section-title"),p(y,"class","table-compact table-border m-b-base"),p(B,"class","section-title"),p(F,"class","tabs-header compact left"),p(H,"class","tabs-content"),p(T,"class","tabs")},m(e,t){r(e,l,t),a(l,o),a(l,m),a(l,g),r(e,u,t),r(e,b,t),r(e,_,t),I(v,e,t),r(e,A,t),r(e,P,t),r(e,X,t),r(e,S,t),a(S,E),a(S,pe),a(S,J),a(J,M),a(M,be),a(M,Y),a(Y,Z),a(M,fe),r(e,ee,t),r(e,R,t),r(e,te,t),r(e,x,t),r(e,ae,t),r(e,W,t),r(e,le,t),r(e,y,t),a(y,oe),a(y,me),a(y,U),a(U,$),a($,se),a($,ge),a($,ne),a($,ke),a($,f),a(f,_e),I(C,f,null),a(f,ve),a(f,we),a(f,Oe),a(f,ie),a(f,Ae),a(f,re),a(f,Se),a(f,ye),a(f,$e),a(f,ce),a(f,Te),a(U,Ce),I(q,U,null),r(e,ue,t),r(e,B,t),r(e,de,t),r(e,T,t),a(T,F);for(let d=0;d<O.length;d+=1)O[d]&&O[d].m(F,null);a(T,De),a(T,H);for(let d=0;d<w.length;d+=1)w[d]&&w[d].m(H,null);D=!0},p(e,[t]){(!D||t&1)&&n!==(n=e[0].name+"")&&he(m,n);const d={};t&8&&(d.js=`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
// OAuth2 authentication with a single realtime call.
|
||||
//
|
||||
// Make sure to register ${e[3]}/api/oauth2-redirect as redirect url.
|
||||
const authData = await pb.collection('users').authWithOAuth2({ provider: 'google' });
|
||||
|
||||
// OR authenticate with manual OAuth2 code exchange
|
||||
// const authData = await pb.collection('users').authWithOAuth2Code(...);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated model
|
||||
pb.authStore.clear();
|
||||
`),t&8&&(d.dart=`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
final pb = PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
// OAuth2 authentication with a single realtime call.
|
||||
//
|
||||
// Make sure to register ${e[3]}/api/oauth2-redirect as redirect url.
|
||||
final authData = await pb.collection('users').authWithOAuth2('google', (url) async {
|
||||
await launchUrl(url);
|
||||
});
|
||||
|
||||
// OR authenticate with manual OAuth2 code exchange
|
||||
// final authData = await pb.collection('users').authWithOAuth2Code(...);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated model
|
||||
pb.authStore.clear();
|
||||
`),v.$set(d),(!D||t&1)&&N!==(N=e[0].name+"")&&he(Z,N),t&6&&(Q=e[2],O=xe(O,t,Me,1,e,Q,qe,F,Je,Fe,null,Be)),t&6&&(j=e[2],Ne(),w=xe(w,t,Re,1,e,j,Pe,H,Qe,He,null,Ue),ze())},i(e){if(!D){V(v.$$.fragment,e),V(C.$$.fragment,e),V(q.$$.fragment,e);for(let t=0;t<j.length;t+=1)V(w[t]);D=!0}},o(e){L(v.$$.fragment,e),L(C.$$.fragment,e),L(q.$$.fragment,e);for(let t=0;t<w.length;t+=1)L(w[t]);D=!1},d(e){e&&c(l),e&&c(u),e&&c(b),e&&c(_),K(v,e),e&&c(A),e&&c(P),e&&c(X),e&&c(S),e&&c(ee),e&&c(R),e&&c(te),e&&c(x),e&&c(ae),e&&c(W),e&&c(le),e&&c(y),K(C),K(q),e&&c(ue),e&&c(B),e&&c(de),e&&c(T);for(let t=0;t<O.length;t+=1)O[t].d();for(let t=0;t<w.length;t+=1)w[t].d()}}}function et(i,l,o){let n,{collection:m=new Ie}=l,g=200,u=[];const b=_=>o(1,g=_.code);return i.$$set=_=>{"collection"in _&&o(0,m=_.collection)},i.$$.update=()=>{i.$$.dirty&1&&o(2,u=[{code:200,body:JSON.stringify({token:"JWT_AUTH_TOKEN",record:We.dummyCollectionRecord(m),meta:{id:"abc123",name:"John Doe",username:"john.doe",email:"test@example.com",avatarUrl:"https://example.com/avatar.png",accessToken:"...",refreshToken:"...",rawUser:{}}},null,2)},{code:400,body:`
|
||||
{
|
||||
"code": 400,
|
||||
"message": "An error occurred while submitting the form.",
|
||||
"data": {
|
||||
"provider": {
|
||||
"code": "validation_required",
|
||||
"message": "Missing required value."
|
||||
}
|
||||
}
|
||||
}
|
||||
`}])},o(3,n=We.getApiExampleUrl(Ke.baseUrl)),[m,g,u,n,b]}class ot extends Ve{constructor(l){super(),Le(this,l,et,Ze,Ee,{collection:0})}}export{ot as default};
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
import{S as we,i as ye,s as $e,N as ve,O as ot,e as n,w as p,b as d,c as nt,f as m,g as r,h as e,m as st,x as Dt,P as pe,Q as Pe,k as Re,R as Ce,n as Oe,t as Z,a as x,o as c,d as it,C as fe,p as Ae,r as rt,u as Te}from"./index-fd9da555.js";import{S as Ue}from"./SdkTabs-9e15e9a4.js";import{F as Me}from"./FieldsQueryParam-3fb2414b.js";function he(s,l,a){const i=s.slice();return i[8]=l[a],i}function be(s,l,a){const i=s.slice();return i[8]=l[a],i}function De(s){let l;return{c(){l=p("email")},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function Ee(s){let l;return{c(){l=p("username")},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function We(s){let l;return{c(){l=p("username/email")},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function me(s){let l;return{c(){l=n("strong"),l.textContent="username"},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function _e(s){let l;return{c(){l=p("or")},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function ke(s){let l;return{c(){l=n("strong"),l.textContent="email"},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function ge(s,l){let a,i=l[8].code+"",g,b,f,u;function _(){return l[7](l[8])}return{key:s,first:null,c(){a=n("button"),g=p(i),b=d(),m(a,"class","tab-item"),rt(a,"active",l[3]===l[8].code),this.first=a},m(R,C){r(R,a,C),e(a,g),e(a,b),f||(u=Te(a,"click",_),f=!0)},p(R,C){l=R,C&16&&i!==(i=l[8].code+"")&&Dt(g,i),C&24&&rt(a,"active",l[3]===l[8].code)},d(R){R&&c(a),f=!1,u()}}}function Se(s,l){let a,i,g,b;return i=new ve({props:{content:l[8].body}}),{key:s,first:null,c(){a=n("div"),nt(i.$$.fragment),g=d(),m(a,"class","tab-item"),rt(a,"active",l[3]===l[8].code),this.first=a},m(f,u){r(f,a,u),st(i,a,null),e(a,g),b=!0},p(f,u){l=f;const _={};u&16&&(_.content=l[8].body),i.$set(_),(!b||u&24)&&rt(a,"active",l[3]===l[8].code)},i(f){b||(Z(i.$$.fragment,f),b=!0)},o(f){x(i.$$.fragment,f),b=!1},d(f){f&&c(a),it(i)}}}function Le(s){var re,ce;let l,a,i=s[0].name+"",g,b,f,u,_,R,C,O,B,Et,ct,T,dt,N,ut,U,tt,Wt,et,I,Lt,pt,lt=s[0].name+"",ft,Bt,ht,V,bt,M,mt,qt,Q,D,_t,Ft,kt,Ht,$,Yt,gt,St,vt,Nt,wt,yt,j,$t,E,Pt,It,J,W,Rt,Vt,Ct,Qt,k,jt,q,Jt,Kt,zt,Ot,Gt,At,Xt,Zt,xt,Tt,te,ee,F,Ut,K,Mt,L,z,A=[],le=new Map,ae,G,S=[],oe=new Map,H;function ne(t,o){if(t[1]&&t[2])return We;if(t[1])return Ee;if(t[2])return De}let Y=ne(s),P=Y&&Y(s);T=new Ue({props:{js:`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${s[6]}');
|
||||
|
||||
...
|
||||
|
||||
const authData = await pb.collection('${(re=s[0])==null?void 0:re.name}').authWithPassword(
|
||||
'${s[5]}',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated account
|
||||
pb.authStore.clear();
|
||||
`,dart:`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${s[6]}');
|
||||
|
||||
...
|
||||
|
||||
final authData = await pb.collection('${(ce=s[0])==null?void 0:ce.name}').authWithPassword(
|
||||
'${s[5]}',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated account
|
||||
pb.authStore.clear();
|
||||
`}});let v=s[1]&&me(),w=s[1]&&s[2]&&_e(),y=s[2]&&ke();q=new ve({props:{content:"?expand=relField1,relField2.subRelField"}}),F=new Me({});let at=ot(s[4]);const se=t=>t[8].code;for(let t=0;t<at.length;t+=1){let o=be(s,at,t),h=se(o);le.set(h,A[t]=ge(h,o))}let X=ot(s[4]);const ie=t=>t[8].code;for(let t=0;t<X.length;t+=1){let o=he(s,X,t),h=ie(o);oe.set(h,S[t]=Se(h,o))}return{c(){l=n("h3"),a=p("Auth with password ("),g=p(i),b=p(")"),f=d(),u=n("div"),_=n("p"),R=p(`Returns new auth token and account data by a combination of
|
||||
`),C=n("strong"),P&&P.c(),O=p(`
|
||||
and `),B=n("strong"),B.textContent="password",Et=p("."),ct=d(),nt(T.$$.fragment),dt=d(),N=n("h6"),N.textContent="API details",ut=d(),U=n("div"),tt=n("strong"),tt.textContent="POST",Wt=d(),et=n("div"),I=n("p"),Lt=p("/api/collections/"),pt=n("strong"),ft=p(lt),Bt=p("/auth-with-password"),ht=d(),V=n("div"),V.textContent="Body Parameters",bt=d(),M=n("table"),mt=n("thead"),mt.innerHTML='<tr><th>Param</th> <th>Type</th> <th width="50%">Description</th></tr>',qt=d(),Q=n("tbody"),D=n("tr"),_t=n("td"),_t.innerHTML='<div class="inline-flex"><span class="label label-success">Required</span> <span>identity</span></div>',Ft=d(),kt=n("td"),kt.innerHTML='<span class="label">String</span>',Ht=d(),$=n("td"),Yt=p(`The
|
||||
`),v&&v.c(),gt=d(),w&&w.c(),St=d(),y&&y.c(),vt=p(`
|
||||
of the record to authenticate.`),Nt=d(),wt=n("tr"),wt.innerHTML='<td><div class="inline-flex"><span class="label label-success">Required</span> <span>password</span></div></td> <td><span class="label">String</span></td> <td>The auth record password.</td>',yt=d(),j=n("div"),j.textContent="Query parameters",$t=d(),E=n("table"),Pt=n("thead"),Pt.innerHTML='<tr><th>Param</th> <th>Type</th> <th width="60%">Description</th></tr>',It=d(),J=n("tbody"),W=n("tr"),Rt=n("td"),Rt.textContent="expand",Vt=d(),Ct=n("td"),Ct.innerHTML='<span class="label">String</span>',Qt=d(),k=n("td"),jt=p(`Auto expand record relations. Ex.:
|
||||
`),nt(q.$$.fragment),Jt=p(`
|
||||
Supports up to 6-levels depth nested relations expansion. `),Kt=n("br"),zt=p(`
|
||||
The expanded relations will be appended to the record under the
|
||||
`),Ot=n("code"),Ot.textContent="expand",Gt=p(" property (eg. "),At=n("code"),At.textContent='"expand": {"relField1": {...}, ...}',Xt=p(`).
|
||||
`),Zt=n("br"),xt=p(`
|
||||
Only the relations to which the request user has permissions to `),Tt=n("strong"),Tt.textContent="view",te=p(" will be expanded."),ee=d(),nt(F.$$.fragment),Ut=d(),K=n("div"),K.textContent="Responses",Mt=d(),L=n("div"),z=n("div");for(let t=0;t<A.length;t+=1)A[t].c();ae=d(),G=n("div");for(let t=0;t<S.length;t+=1)S[t].c();m(l,"class","m-b-sm"),m(u,"class","content txt-lg m-b-sm"),m(N,"class","m-b-xs"),m(tt,"class","label label-primary"),m(et,"class","content"),m(U,"class","alert alert-success"),m(V,"class","section-title"),m(M,"class","table-compact table-border m-b-base"),m(j,"class","section-title"),m(E,"class","table-compact table-border m-b-base"),m(K,"class","section-title"),m(z,"class","tabs-header compact combined left"),m(G,"class","tabs-content"),m(L,"class","tabs")},m(t,o){r(t,l,o),e(l,a),e(l,g),e(l,b),r(t,f,o),r(t,u,o),e(u,_),e(_,R),e(_,C),P&&P.m(C,null),e(_,O),e(_,B),e(_,Et),r(t,ct,o),st(T,t,o),r(t,dt,o),r(t,N,o),r(t,ut,o),r(t,U,o),e(U,tt),e(U,Wt),e(U,et),e(et,I),e(I,Lt),e(I,pt),e(pt,ft),e(I,Bt),r(t,ht,o),r(t,V,o),r(t,bt,o),r(t,M,o),e(M,mt),e(M,qt),e(M,Q),e(Q,D),e(D,_t),e(D,Ft),e(D,kt),e(D,Ht),e(D,$),e($,Yt),v&&v.m($,null),e($,gt),w&&w.m($,null),e($,St),y&&y.m($,null),e($,vt),e(Q,Nt),e(Q,wt),r(t,yt,o),r(t,j,o),r(t,$t,o),r(t,E,o),e(E,Pt),e(E,It),e(E,J),e(J,W),e(W,Rt),e(W,Vt),e(W,Ct),e(W,Qt),e(W,k),e(k,jt),st(q,k,null),e(k,Jt),e(k,Kt),e(k,zt),e(k,Ot),e(k,Gt),e(k,At),e(k,Xt),e(k,Zt),e(k,xt),e(k,Tt),e(k,te),e(J,ee),st(F,J,null),r(t,Ut,o),r(t,K,o),r(t,Mt,o),r(t,L,o),e(L,z);for(let h=0;h<A.length;h+=1)A[h]&&A[h].m(z,null);e(L,ae),e(L,G);for(let h=0;h<S.length;h+=1)S[h]&&S[h].m(G,null);H=!0},p(t,[o]){var de,ue;(!H||o&1)&&i!==(i=t[0].name+"")&&Dt(g,i),Y!==(Y=ne(t))&&(P&&P.d(1),P=Y&&Y(t),P&&(P.c(),P.m(C,null)));const h={};o&97&&(h.js=`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${t[6]}');
|
||||
|
||||
...
|
||||
|
||||
const authData = await pb.collection('${(de=t[0])==null?void 0:de.name}').authWithPassword(
|
||||
'${t[5]}',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated account
|
||||
pb.authStore.clear();
|
||||
`),o&97&&(h.dart=`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${t[6]}');
|
||||
|
||||
...
|
||||
|
||||
final authData = await pb.collection('${(ue=t[0])==null?void 0:ue.name}').authWithPassword(
|
||||
'${t[5]}',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated account
|
||||
pb.authStore.clear();
|
||||
`),T.$set(h),(!H||o&1)&<!==(lt=t[0].name+"")&&Dt(ft,lt),t[1]?v||(v=me(),v.c(),v.m($,gt)):v&&(v.d(1),v=null),t[1]&&t[2]?w||(w=_e(),w.c(),w.m($,St)):w&&(w.d(1),w=null),t[2]?y||(y=ke(),y.c(),y.m($,vt)):y&&(y.d(1),y=null),o&24&&(at=ot(t[4]),A=pe(A,o,se,1,t,at,le,z,Pe,ge,null,be)),o&24&&(X=ot(t[4]),Re(),S=pe(S,o,ie,1,t,X,oe,G,Ce,Se,null,he),Oe())},i(t){if(!H){Z(T.$$.fragment,t),Z(q.$$.fragment,t),Z(F.$$.fragment,t);for(let o=0;o<X.length;o+=1)Z(S[o]);H=!0}},o(t){x(T.$$.fragment,t),x(q.$$.fragment,t),x(F.$$.fragment,t);for(let o=0;o<S.length;o+=1)x(S[o]);H=!1},d(t){t&&(c(l),c(f),c(u),c(ct),c(dt),c(N),c(ut),c(U),c(ht),c(V),c(bt),c(M),c(yt),c(j),c($t),c(E),c(Ut),c(K),c(Mt),c(L)),P&&P.d(),it(T,t),v&&v.d(),w&&w.d(),y&&y.d(),it(q),it(F);for(let o=0;o<A.length;o+=1)A[o].d();for(let o=0;o<S.length;o+=1)S[o].d()}}}function Be(s,l,a){let i,g,b,f,{collection:u}=l,_=200,R=[];const C=O=>a(3,_=O.code);return s.$$set=O=>{"collection"in O&&a(0,u=O.collection)},s.$$.update=()=>{var O,B;s.$$.dirty&1&&a(2,g=(O=u==null?void 0:u.options)==null?void 0:O.allowEmailAuth),s.$$.dirty&1&&a(1,b=(B=u==null?void 0:u.options)==null?void 0:B.allowUsernameAuth),s.$$.dirty&6&&a(5,f=b&&g?"YOUR_USERNAME_OR_EMAIL":b?"YOUR_USERNAME":"YOUR_EMAIL"),s.$$.dirty&1&&a(4,R=[{code:200,body:JSON.stringify({token:"JWT_TOKEN",record:fe.dummyCollectionRecord(u)},null,2)},{code:400,body:`
|
||||
{
|
||||
"code": 400,
|
||||
"message": "Failed to authenticate.",
|
||||
"data": {
|
||||
"identity": {
|
||||
"code": "validation_required",
|
||||
"message": "Missing required value."
|
||||
}
|
||||
}
|
||||
}
|
||||
`}])},a(6,i=fe.getApiExampleUrl(Ae.baseUrl)),[u,b,g,_,R,f,i,C]}class Ye extends we{constructor(l){super(),ye(this,l,Be,Le,$e,{collection:0})}}export{Ye as default};
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
import{S as ve,i as ye,s as ge,M as we,e as s,w as f,b as d,c as ot,f as h,g as r,h as e,m as st,x as Ut,N as ue,P as $e,k as Pe,Q as Re,n as Ce,t as Z,a as x,o as c,d as nt,T as Te,C as fe,p as Ae,r as it,u as Oe}from"./index-42f47088.js";import{S as Me}from"./SdkTabs-81470834.js";import{F as Ue}from"./FieldsQueryParam-582f34bb.js";function pe(n,l,a){const i=n.slice();return i[8]=l[a],i}function be(n,l,a){const i=n.slice();return i[8]=l[a],i}function De(n){let l;return{c(){l=f("email")},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function Ee(n){let l;return{c(){l=f("username")},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function We(n){let l;return{c(){l=f("username/email")},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function me(n){let l;return{c(){l=s("strong"),l.textContent="username"},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function he(n){let l;return{c(){l=f("or")},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function _e(n){let l;return{c(){l=s("strong"),l.textContent="email"},m(a,i){r(a,l,i)},d(a){a&&c(l)}}}function ke(n,l){let a,i=l[8].code+"",S,m,p,u;function _(){return l[7](l[8])}return{key:n,first:null,c(){a=s("button"),S=f(i),m=d(),h(a,"class","tab-item"),it(a,"active",l[3]===l[8].code),this.first=a},m(R,C){r(R,a,C),e(a,S),e(a,m),p||(u=Oe(a,"click",_),p=!0)},p(R,C){l=R,C&16&&i!==(i=l[8].code+"")&&Ut(S,i),C&24&&it(a,"active",l[3]===l[8].code)},d(R){R&&c(a),p=!1,u()}}}function Se(n,l){let a,i,S,m;return i=new we({props:{content:l[8].body}}),{key:n,first:null,c(){a=s("div"),ot(i.$$.fragment),S=d(),h(a,"class","tab-item"),it(a,"active",l[3]===l[8].code),this.first=a},m(p,u){r(p,a,u),st(i,a,null),e(a,S),m=!0},p(p,u){l=p;const _={};u&16&&(_.content=l[8].body),i.$set(_),(!m||u&24)&&it(a,"active",l[3]===l[8].code)},i(p){m||(Z(i.$$.fragment,p),m=!0)},o(p){x(i.$$.fragment,p),m=!1},d(p){p&&c(a),nt(i)}}}function Le(n){var ie,re;let l,a,i=n[0].name+"",S,m,p,u,_,R,C,T,B,Dt,rt,O,ct,N,dt,M,tt,Et,et,I,Wt,ut,lt=n[0].name+"",ft,Lt,pt,V,bt,U,mt,Bt,Q,D,ht,qt,_t,Ft,$,Ht,kt,St,wt,Yt,vt,yt,j,gt,E,$t,Nt,J,W,Pt,It,Rt,Vt,k,Qt,q,jt,Jt,Kt,Ct,zt,Tt,Gt,Xt,Zt,At,xt,te,F,Ot,K,Mt,L,z,A=[],ee=new Map,le,G,w=[],ae=new Map,H;function oe(t,o){if(t[1]&&t[2])return We;if(t[1])return Ee;if(t[2])return De}let Y=oe(n),P=Y&&Y(n);O=new Me({props:{js:`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${n[6]}');
|
||||
|
||||
...
|
||||
|
||||
const authData = await pb.collection('${(ie=n[0])==null?void 0:ie.name}').authWithPassword(
|
||||
'${n[5]}',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated account
|
||||
pb.authStore.clear();
|
||||
`,dart:`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${n[6]}');
|
||||
|
||||
...
|
||||
|
||||
final authData = await pb.collection('${(re=n[0])==null?void 0:re.name}').authWithPassword(
|
||||
'${n[5]}',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated account
|
||||
pb.authStore.clear();
|
||||
`}});let v=n[1]&&me(),y=n[1]&&n[2]&&he(),g=n[2]&&_e();q=new we({props:{content:"?expand=relField1,relField2.subRelField"}}),F=new Ue({});let at=n[4];const se=t=>t[8].code;for(let t=0;t<at.length;t+=1){let o=be(n,at,t),b=se(o);ee.set(b,A[t]=ke(b,o))}let X=n[4];const ne=t=>t[8].code;for(let t=0;t<X.length;t+=1){let o=pe(n,X,t),b=ne(o);ae.set(b,w[t]=Se(b,o))}return{c(){l=s("h3"),a=f("Auth with password ("),S=f(i),m=f(")"),p=d(),u=s("div"),_=s("p"),R=f(`Returns new auth token and account data by a combination of
|
||||
`),C=s("strong"),P&&P.c(),T=f(`
|
||||
and `),B=s("strong"),B.textContent="password",Dt=f("."),rt=d(),ot(O.$$.fragment),ct=d(),N=s("h6"),N.textContent="API details",dt=d(),M=s("div"),tt=s("strong"),tt.textContent="POST",Et=d(),et=s("div"),I=s("p"),Wt=f("/api/collections/"),ut=s("strong"),ft=f(lt),Lt=f("/auth-with-password"),pt=d(),V=s("div"),V.textContent="Body Parameters",bt=d(),U=s("table"),mt=s("thead"),mt.innerHTML=`<tr><th>Param</th>
|
||||
<th>Type</th>
|
||||
<th width="50%">Description</th></tr>`,Bt=d(),Q=s("tbody"),D=s("tr"),ht=s("td"),ht.innerHTML=`<div class="inline-flex"><span class="label label-success">Required</span>
|
||||
<span>identity</span></div>`,qt=d(),_t=s("td"),_t.innerHTML='<span class="label">String</span>',Ft=d(),$=s("td"),Ht=f(`The
|
||||
`),v&&v.c(),kt=d(),y&&y.c(),St=d(),g&&g.c(),wt=f(`
|
||||
of the record to authenticate.`),Yt=d(),vt=s("tr"),vt.innerHTML=`<td><div class="inline-flex"><span class="label label-success">Required</span>
|
||||
<span>password</span></div></td>
|
||||
<td><span class="label">String</span></td>
|
||||
<td>The auth record password.</td>`,yt=d(),j=s("div"),j.textContent="Query parameters",gt=d(),E=s("table"),$t=s("thead"),$t.innerHTML=`<tr><th>Param</th>
|
||||
<th>Type</th>
|
||||
<th width="60%">Description</th></tr>`,Nt=d(),J=s("tbody"),W=s("tr"),Pt=s("td"),Pt.textContent="expand",It=d(),Rt=s("td"),Rt.innerHTML='<span class="label">String</span>',Vt=d(),k=s("td"),Qt=f(`Auto expand record relations. Ex.:
|
||||
`),ot(q.$$.fragment),jt=f(`
|
||||
Supports up to 6-levels depth nested relations expansion. `),Jt=s("br"),Kt=f(`
|
||||
The expanded relations will be appended to the record under the
|
||||
`),Ct=s("code"),Ct.textContent="expand",zt=f(" property (eg. "),Tt=s("code"),Tt.textContent='"expand": {"relField1": {...}, ...}',Gt=f(`).
|
||||
`),Xt=s("br"),Zt=f(`
|
||||
Only the relations to which the request user has permissions to `),At=s("strong"),At.textContent="view",xt=f(" will be expanded."),te=d(),ot(F.$$.fragment),Ot=d(),K=s("div"),K.textContent="Responses",Mt=d(),L=s("div"),z=s("div");for(let t=0;t<A.length;t+=1)A[t].c();le=d(),G=s("div");for(let t=0;t<w.length;t+=1)w[t].c();h(l,"class","m-b-sm"),h(u,"class","content txt-lg m-b-sm"),h(N,"class","m-b-xs"),h(tt,"class","label label-primary"),h(et,"class","content"),h(M,"class","alert alert-success"),h(V,"class","section-title"),h(U,"class","table-compact table-border m-b-base"),h(j,"class","section-title"),h(E,"class","table-compact table-border m-b-base"),h(K,"class","section-title"),h(z,"class","tabs-header compact left"),h(G,"class","tabs-content"),h(L,"class","tabs")},m(t,o){r(t,l,o),e(l,a),e(l,S),e(l,m),r(t,p,o),r(t,u,o),e(u,_),e(_,R),e(_,C),P&&P.m(C,null),e(_,T),e(_,B),e(_,Dt),r(t,rt,o),st(O,t,o),r(t,ct,o),r(t,N,o),r(t,dt,o),r(t,M,o),e(M,tt),e(M,Et),e(M,et),e(et,I),e(I,Wt),e(I,ut),e(ut,ft),e(I,Lt),r(t,pt,o),r(t,V,o),r(t,bt,o),r(t,U,o),e(U,mt),e(U,Bt),e(U,Q),e(Q,D),e(D,ht),e(D,qt),e(D,_t),e(D,Ft),e(D,$),e($,Ht),v&&v.m($,null),e($,kt),y&&y.m($,null),e($,St),g&&g.m($,null),e($,wt),e(Q,Yt),e(Q,vt),r(t,yt,o),r(t,j,o),r(t,gt,o),r(t,E,o),e(E,$t),e(E,Nt),e(E,J),e(J,W),e(W,Pt),e(W,It),e(W,Rt),e(W,Vt),e(W,k),e(k,Qt),st(q,k,null),e(k,jt),e(k,Jt),e(k,Kt),e(k,Ct),e(k,zt),e(k,Tt),e(k,Gt),e(k,Xt),e(k,Zt),e(k,At),e(k,xt),e(J,te),st(F,J,null),r(t,Ot,o),r(t,K,o),r(t,Mt,o),r(t,L,o),e(L,z);for(let b=0;b<A.length;b+=1)A[b]&&A[b].m(z,null);e(L,le),e(L,G);for(let b=0;b<w.length;b+=1)w[b]&&w[b].m(G,null);H=!0},p(t,[o]){var ce,de;(!H||o&1)&&i!==(i=t[0].name+"")&&Ut(S,i),Y!==(Y=oe(t))&&(P&&P.d(1),P=Y&&Y(t),P&&(P.c(),P.m(C,null)));const b={};o&97&&(b.js=`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${t[6]}');
|
||||
|
||||
...
|
||||
|
||||
const authData = await pb.collection('${(ce=t[0])==null?void 0:ce.name}').authWithPassword(
|
||||
'${t[5]}',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
console.log(pb.authStore.isValid);
|
||||
console.log(pb.authStore.token);
|
||||
console.log(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated account
|
||||
pb.authStore.clear();
|
||||
`),o&97&&(b.dart=`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${t[6]}');
|
||||
|
||||
...
|
||||
|
||||
final authData = await pb.collection('${(de=t[0])==null?void 0:de.name}').authWithPassword(
|
||||
'${t[5]}',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
|
||||
// after the above you can also access the auth data from the authStore
|
||||
print(pb.authStore.isValid);
|
||||
print(pb.authStore.token);
|
||||
print(pb.authStore.model.id);
|
||||
|
||||
// "logout" the last authenticated account
|
||||
pb.authStore.clear();
|
||||
`),O.$set(b),(!H||o&1)&<!==(lt=t[0].name+"")&&Ut(ft,lt),t[1]?v||(v=me(),v.c(),v.m($,kt)):v&&(v.d(1),v=null),t[1]&&t[2]?y||(y=he(),y.c(),y.m($,St)):y&&(y.d(1),y=null),t[2]?g||(g=_e(),g.c(),g.m($,wt)):g&&(g.d(1),g=null),o&24&&(at=t[4],A=ue(A,o,se,1,t,at,ee,z,$e,ke,null,be)),o&24&&(X=t[4],Pe(),w=ue(w,o,ne,1,t,X,ae,G,Re,Se,null,pe),Ce())},i(t){if(!H){Z(O.$$.fragment,t),Z(q.$$.fragment,t),Z(F.$$.fragment,t);for(let o=0;o<X.length;o+=1)Z(w[o]);H=!0}},o(t){x(O.$$.fragment,t),x(q.$$.fragment,t),x(F.$$.fragment,t);for(let o=0;o<w.length;o+=1)x(w[o]);H=!1},d(t){t&&c(l),t&&c(p),t&&c(u),P&&P.d(),t&&c(rt),nt(O,t),t&&c(ct),t&&c(N),t&&c(dt),t&&c(M),t&&c(pt),t&&c(V),t&&c(bt),t&&c(U),v&&v.d(),y&&y.d(),g&&g.d(),t&&c(yt),t&&c(j),t&&c(gt),t&&c(E),nt(q),nt(F),t&&c(Ot),t&&c(K),t&&c(Mt),t&&c(L);for(let o=0;o<A.length;o+=1)A[o].d();for(let o=0;o<w.length;o+=1)w[o].d()}}}function Be(n,l,a){let i,S,m,p,{collection:u=new Te}=l,_=200,R=[];const C=T=>a(3,_=T.code);return n.$$set=T=>{"collection"in T&&a(0,u=T.collection)},n.$$.update=()=>{var T,B;n.$$.dirty&1&&a(2,S=(T=u==null?void 0:u.options)==null?void 0:T.allowEmailAuth),n.$$.dirty&1&&a(1,m=(B=u==null?void 0:u.options)==null?void 0:B.allowUsernameAuth),n.$$.dirty&6&&a(5,p=m&&S?"YOUR_USERNAME_OR_EMAIL":m?"YOUR_USERNAME":"YOUR_EMAIL"),n.$$.dirty&1&&a(4,R=[{code:200,body:JSON.stringify({token:"JWT_TOKEN",record:fe.dummyCollectionRecord(u)},null,2)},{code:400,body:`
|
||||
{
|
||||
"code": 400,
|
||||
"message": "Failed to authenticate.",
|
||||
"data": {
|
||||
"identity": {
|
||||
"code": "validation_required",
|
||||
"message": "Missing required value."
|
||||
}
|
||||
}
|
||||
}
|
||||
`}])},a(6,i=fe.getApiExampleUrl(Ae.baseUrl)),[u,m,S,_,R,p,i,C]}class Ye extends ve{constructor(l){super(),ye(this,l,Be,Le,ge,{collection:0})}}export{Ye as default};
|
||||
+14
File diff suppressed because one or more lines are too long
-14
File diff suppressed because one or more lines are too long
@@ -1,66 +0,0 @@
|
||||
import{S as Ce,i as $e,s as we,e as r,w as g,b as h,c as he,f as b,g as f,h as n,m as ve,x as Y,N as pe,P as Pe,k as Se,Q as Oe,n as Te,t as Z,a as x,o as m,d as ge,T as Re,C as Ee,p as ye,r as j,u as Be,M as qe}from"./index-42f47088.js";import{S as Ae}from"./SdkTabs-81470834.js";function ue(o,l,s){const a=o.slice();return a[5]=l[s],a}function be(o,l,s){const a=o.slice();return a[5]=l[s],a}function _e(o,l){let s,a=l[5].code+"",_,u,i,d;function p(){return l[4](l[5])}return{key:o,first:null,c(){s=r("button"),_=g(a),u=h(),b(s,"class","tab-item"),j(s,"active",l[1]===l[5].code),this.first=s},m(C,$){f(C,s,$),n(s,_),n(s,u),i||(d=Be(s,"click",p),i=!0)},p(C,$){l=C,$&4&&a!==(a=l[5].code+"")&&Y(_,a),$&6&&j(s,"active",l[1]===l[5].code)},d(C){C&&m(s),i=!1,d()}}}function ke(o,l){let s,a,_,u;return a=new qe({props:{content:l[5].body}}),{key:o,first:null,c(){s=r("div"),he(a.$$.fragment),_=h(),b(s,"class","tab-item"),j(s,"active",l[1]===l[5].code),this.first=s},m(i,d){f(i,s,d),ve(a,s,null),n(s,_),u=!0},p(i,d){l=i;const p={};d&4&&(p.content=l[5].body),a.$set(p),(!u||d&6)&&j(s,"active",l[1]===l[5].code)},i(i){u||(Z(a.$$.fragment,i),u=!0)},o(i){x(a.$$.fragment,i),u=!1},d(i){i&&m(s),ge(a)}}}function Ue(o){var re,fe;let l,s,a=o[0].name+"",_,u,i,d,p,C,$,D=o[0].name+"",H,ee,F,w,I,T,L,P,M,te,N,R,le,Q,K=o[0].name+"",z,se,G,E,J,y,V,B,X,S,q,v=[],ae=new Map,oe,A,k=[],ne=new Map,O;w=new Ae({props:{js:`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${o[3]}');
|
||||
|
||||
...
|
||||
|
||||
await pb.collection('${(re=o[0])==null?void 0:re.name}').confirmEmailChange(
|
||||
'TOKEN',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
`,dart:`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${o[3]}');
|
||||
|
||||
...
|
||||
|
||||
await pb.collection('${(fe=o[0])==null?void 0:fe.name}').confirmEmailChange(
|
||||
'TOKEN',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
`}});let W=o[2];const ie=e=>e[5].code;for(let e=0;e<W.length;e+=1){let t=be(o,W,e),c=ie(t);ae.set(c,v[e]=_e(c,t))}let U=o[2];const ce=e=>e[5].code;for(let e=0;e<U.length;e+=1){let t=ue(o,U,e),c=ce(t);ne.set(c,k[e]=ke(c,t))}return{c(){l=r("h3"),s=g("Confirm email change ("),_=g(a),u=g(")"),i=h(),d=r("div"),p=r("p"),C=g("Confirms "),$=r("strong"),H=g(D),ee=g(" email change request."),F=h(),he(w.$$.fragment),I=h(),T=r("h6"),T.textContent="API details",L=h(),P=r("div"),M=r("strong"),M.textContent="POST",te=h(),N=r("div"),R=r("p"),le=g("/api/collections/"),Q=r("strong"),z=g(K),se=g("/confirm-email-change"),G=h(),E=r("div"),E.textContent="Body Parameters",J=h(),y=r("table"),y.innerHTML=`<thead><tr><th>Param</th>
|
||||
<th>Type</th>
|
||||
<th width="50%">Description</th></tr></thead>
|
||||
<tbody><tr><td><div class="inline-flex"><span class="label label-success">Required</span>
|
||||
<span>token</span></div></td>
|
||||
<td><span class="label">String</span></td>
|
||||
<td>The token from the change email request email.</td></tr>
|
||||
<tr><td><div class="inline-flex"><span class="label label-success">Required</span>
|
||||
<span>password</span></div></td>
|
||||
<td><span class="label">String</span></td>
|
||||
<td>The account password to confirm the email change.</td></tr></tbody>`,V=h(),B=r("div"),B.textContent="Responses",X=h(),S=r("div"),q=r("div");for(let e=0;e<v.length;e+=1)v[e].c();oe=h(),A=r("div");for(let e=0;e<k.length;e+=1)k[e].c();b(l,"class","m-b-sm"),b(d,"class","content txt-lg m-b-sm"),b(T,"class","m-b-xs"),b(M,"class","label label-primary"),b(N,"class","content"),b(P,"class","alert alert-success"),b(E,"class","section-title"),b(y,"class","table-compact table-border m-b-base"),b(B,"class","section-title"),b(q,"class","tabs-header compact left"),b(A,"class","tabs-content"),b(S,"class","tabs")},m(e,t){f(e,l,t),n(l,s),n(l,_),n(l,u),f(e,i,t),f(e,d,t),n(d,p),n(p,C),n(p,$),n($,H),n(p,ee),f(e,F,t),ve(w,e,t),f(e,I,t),f(e,T,t),f(e,L,t),f(e,P,t),n(P,M),n(P,te),n(P,N),n(N,R),n(R,le),n(R,Q),n(Q,z),n(R,se),f(e,G,t),f(e,E,t),f(e,J,t),f(e,y,t),f(e,V,t),f(e,B,t),f(e,X,t),f(e,S,t),n(S,q);for(let c=0;c<v.length;c+=1)v[c]&&v[c].m(q,null);n(S,oe),n(S,A);for(let c=0;c<k.length;c+=1)k[c]&&k[c].m(A,null);O=!0},p(e,[t]){var me,de;(!O||t&1)&&a!==(a=e[0].name+"")&&Y(_,a),(!O||t&1)&&D!==(D=e[0].name+"")&&Y(H,D);const c={};t&9&&(c.js=`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
await pb.collection('${(me=e[0])==null?void 0:me.name}').confirmEmailChange(
|
||||
'TOKEN',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
`),t&9&&(c.dart=`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
await pb.collection('${(de=e[0])==null?void 0:de.name}').confirmEmailChange(
|
||||
'TOKEN',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
`),w.$set(c),(!O||t&1)&&K!==(K=e[0].name+"")&&Y(z,K),t&6&&(W=e[2],v=pe(v,t,ie,1,e,W,ae,q,Pe,_e,null,be)),t&6&&(U=e[2],Se(),k=pe(k,t,ce,1,e,U,ne,A,Oe,ke,null,ue),Te())},i(e){if(!O){Z(w.$$.fragment,e);for(let t=0;t<U.length;t+=1)Z(k[t]);O=!0}},o(e){x(w.$$.fragment,e);for(let t=0;t<k.length;t+=1)x(k[t]);O=!1},d(e){e&&m(l),e&&m(i),e&&m(d),e&&m(F),ge(w,e),e&&m(I),e&&m(T),e&&m(L),e&&m(P),e&&m(G),e&&m(E),e&&m(J),e&&m(y),e&&m(V),e&&m(B),e&&m(X),e&&m(S);for(let t=0;t<v.length;t+=1)v[t].d();for(let t=0;t<k.length;t+=1)k[t].d()}}}function De(o,l,s){let a,{collection:_=new Re}=l,u=204,i=[];const d=p=>s(1,u=p.code);return o.$$set=p=>{"collection"in p&&s(0,_=p.collection)},s(3,a=Ee.getApiExampleUrl(ye.baseUrl)),s(2,i=[{code:204,body:"null"},{code:400,body:`
|
||||
{
|
||||
"code": 400,
|
||||
"message": "Failed to authenticate.",
|
||||
"data": {
|
||||
"token": {
|
||||
"code": "validation_required",
|
||||
"message": "Missing required value."
|
||||
}
|
||||
}
|
||||
}
|
||||
`}]),[_,u,i,a,d]}class Ke extends Ce{constructor(l){super(),$e(this,l,De,Ue,we,{collection:0})}}export{Ke as default};
|
||||
@@ -0,0 +1,56 @@
|
||||
import{S as $e,i as Pe,s as Se,O as Y,e as r,w as v,b as k,c as ge,f as b,g as d,h as o,m as ve,x as j,P as ue,Q as we,k as Oe,R as Re,n as Te,t as x,a as ee,o as m,d as Ce,C as ye,p as Ee,r as H,u as Be,N as qe}from"./index-fd9da555.js";import{S as Ae}from"./SdkTabs-9e15e9a4.js";function be(n,l,s){const a=n.slice();return a[5]=l[s],a}function _e(n,l,s){const a=n.slice();return a[5]=l[s],a}function he(n,l){let s,a=l[5].code+"",_,u,i,p;function f(){return l[4](l[5])}return{key:n,first:null,c(){s=r("button"),_=v(a),u=k(),b(s,"class","tab-item"),H(s,"active",l[1]===l[5].code),this.first=s},m(C,$){d(C,s,$),o(s,_),o(s,u),i||(p=Be(s,"click",f),i=!0)},p(C,$){l=C,$&4&&a!==(a=l[5].code+"")&&j(_,a),$&6&&H(s,"active",l[1]===l[5].code)},d(C){C&&m(s),i=!1,p()}}}function ke(n,l){let s,a,_,u;return a=new qe({props:{content:l[5].body}}),{key:n,first:null,c(){s=r("div"),ge(a.$$.fragment),_=k(),b(s,"class","tab-item"),H(s,"active",l[1]===l[5].code),this.first=s},m(i,p){d(i,s,p),ve(a,s,null),o(s,_),u=!0},p(i,p){l=i;const f={};p&4&&(f.content=l[5].body),a.$set(f),(!u||p&6)&&H(s,"active",l[1]===l[5].code)},i(i){u||(x(a.$$.fragment,i),u=!0)},o(i){ee(a.$$.fragment,i),u=!1},d(i){i&&m(s),Ce(a)}}}function Ue(n){var de,me;let l,s,a=n[0].name+"",_,u,i,p,f,C,$,D=n[0].name+"",F,te,I,P,L,R,Q,S,N,le,K,T,se,z,M=n[0].name+"",G,ae,J,y,V,E,X,B,Z,w,q,g=[],ne=new Map,oe,A,h=[],ie=new Map,O;P=new Ae({props:{js:`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${n[3]}');
|
||||
|
||||
...
|
||||
|
||||
await pb.collection('${(de=n[0])==null?void 0:de.name}').confirmEmailChange(
|
||||
'TOKEN',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
`,dart:`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${n[3]}');
|
||||
|
||||
...
|
||||
|
||||
await pb.collection('${(me=n[0])==null?void 0:me.name}').confirmEmailChange(
|
||||
'TOKEN',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
`}});let W=Y(n[2]);const ce=e=>e[5].code;for(let e=0;e<W.length;e+=1){let t=_e(n,W,e),c=ce(t);ne.set(c,g[e]=he(c,t))}let U=Y(n[2]);const re=e=>e[5].code;for(let e=0;e<U.length;e+=1){let t=be(n,U,e),c=re(t);ie.set(c,h[e]=ke(c,t))}return{c(){l=r("h3"),s=v("Confirm email change ("),_=v(a),u=v(")"),i=k(),p=r("div"),f=r("p"),C=v("Confirms "),$=r("strong"),F=v(D),te=v(" email change request."),I=k(),ge(P.$$.fragment),L=k(),R=r("h6"),R.textContent="API details",Q=k(),S=r("div"),N=r("strong"),N.textContent="POST",le=k(),K=r("div"),T=r("p"),se=v("/api/collections/"),z=r("strong"),G=v(M),ae=v("/confirm-email-change"),J=k(),y=r("div"),y.textContent="Body Parameters",V=k(),E=r("table"),E.innerHTML='<thead><tr><th>Param</th> <th>Type</th> <th width="50%">Description</th></tr></thead> <tbody><tr><td><div class="inline-flex"><span class="label label-success">Required</span> <span>token</span></div></td> <td><span class="label">String</span></td> <td>The token from the change email request email.</td></tr> <tr><td><div class="inline-flex"><span class="label label-success">Required</span> <span>password</span></div></td> <td><span class="label">String</span></td> <td>The account password to confirm the email change.</td></tr></tbody>',X=k(),B=r("div"),B.textContent="Responses",Z=k(),w=r("div"),q=r("div");for(let e=0;e<g.length;e+=1)g[e].c();oe=k(),A=r("div");for(let e=0;e<h.length;e+=1)h[e].c();b(l,"class","m-b-sm"),b(p,"class","content txt-lg m-b-sm"),b(R,"class","m-b-xs"),b(N,"class","label label-primary"),b(K,"class","content"),b(S,"class","alert alert-success"),b(y,"class","section-title"),b(E,"class","table-compact table-border m-b-base"),b(B,"class","section-title"),b(q,"class","tabs-header compact combined left"),b(A,"class","tabs-content"),b(w,"class","tabs")},m(e,t){d(e,l,t),o(l,s),o(l,_),o(l,u),d(e,i,t),d(e,p,t),o(p,f),o(f,C),o(f,$),o($,F),o(f,te),d(e,I,t),ve(P,e,t),d(e,L,t),d(e,R,t),d(e,Q,t),d(e,S,t),o(S,N),o(S,le),o(S,K),o(K,T),o(T,se),o(T,z),o(z,G),o(T,ae),d(e,J,t),d(e,y,t),d(e,V,t),d(e,E,t),d(e,X,t),d(e,B,t),d(e,Z,t),d(e,w,t),o(w,q);for(let c=0;c<g.length;c+=1)g[c]&&g[c].m(q,null);o(w,oe),o(w,A);for(let c=0;c<h.length;c+=1)h[c]&&h[c].m(A,null);O=!0},p(e,[t]){var pe,fe;(!O||t&1)&&a!==(a=e[0].name+"")&&j(_,a),(!O||t&1)&&D!==(D=e[0].name+"")&&j(F,D);const c={};t&9&&(c.js=`
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const pb = new PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
await pb.collection('${(pe=e[0])==null?void 0:pe.name}').confirmEmailChange(
|
||||
'TOKEN',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
`),t&9&&(c.dart=`
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
|
||||
final pb = PocketBase('${e[3]}');
|
||||
|
||||
...
|
||||
|
||||
await pb.collection('${(fe=e[0])==null?void 0:fe.name}').confirmEmailChange(
|
||||
'TOKEN',
|
||||
'YOUR_PASSWORD',
|
||||
);
|
||||
`),P.$set(c),(!O||t&1)&&M!==(M=e[0].name+"")&&j(G,M),t&6&&(W=Y(e[2]),g=ue(g,t,ce,1,e,W,ne,q,we,he,null,_e)),t&6&&(U=Y(e[2]),Oe(),h=ue(h,t,re,1,e,U,ie,A,Re,ke,null,be),Te())},i(e){if(!O){x(P.$$.fragment,e);for(let t=0;t<U.length;t+=1)x(h[t]);O=!0}},o(e){ee(P.$$.fragment,e);for(let t=0;t<h.length;t+=1)ee(h[t]);O=!1},d(e){e&&(m(l),m(i),m(p),m(I),m(L),m(R),m(Q),m(S),m(J),m(y),m(V),m(E),m(X),m(B),m(Z),m(w)),Ce(P,e);for(let t=0;t<g.length;t+=1)g[t].d();for(let t=0;t<h.length;t+=1)h[t].d()}}}function De(n,l,s){let a,{collection:_}=l,u=204,i=[];const p=f=>s(1,u=f.code);return n.$$set=f=>{"collection"in f&&s(0,_=f.collection)},s(3,a=ye.getApiExampleUrl(Ee.baseUrl)),s(2,i=[{code:204,body:"null"},{code:400,body:`
|
||||
{
|
||||
"code": 400,
|
||||
"message": "Failed to authenticate.",
|
||||
"data": {
|
||||
"token": {
|
||||
"code": "validation_required",
|
||||
"message": "Missing required value."
|
||||
}
|
||||
}
|
||||
}
|
||||
`}]),[_,u,i,a,p]}class Me extends $e{constructor(l){super(),Pe(this,l,De,Ue,Se,{collection:0})}}export{Me as default};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user