@symbo.ls/fetch 3.14.201 → 3.14.402
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +74 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -99,6 +99,20 @@ Like TanStack's `select`, pick or reshape data before it hits state. Runs after
|
|
|
99
99
|
}
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
For an RPC bound to `on: 'submit'`, collected form data is used as the RPC params. Use `transformParams` to reshape the form data before it's sent:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
{
|
|
106
|
+
tag: 'form',
|
|
107
|
+
fetch: {
|
|
108
|
+
method: 'rpc',
|
|
109
|
+
from: 'submit_application',
|
|
110
|
+
on: 'submit',
|
|
111
|
+
transformParams: (formData, el, state) => ({ p_payload: formData })
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
102
116
|
### Array fetch (parallel)
|
|
103
117
|
|
|
104
118
|
```js
|
|
@@ -130,6 +144,12 @@ Like TanStack's `select`, pick or reshape data before it hits state. Runs after
|
|
|
130
144
|
{ fetch: { from: 'profile', enabled: (el, state) => !!state.userId } }
|
|
131
145
|
```
|
|
132
146
|
|
|
147
|
+
`skip` is the inverse alias — `skip: true` (or a function returning `true`) suppresses the fetch:
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
{ fetch: { from: 'profile', skip: (el, state) => !state.userId } }
|
|
151
|
+
```
|
|
152
|
+
|
|
133
153
|
## Cache
|
|
134
154
|
|
|
135
155
|
Default: all queries cache with `staleTime: 1m`, `gcTime: 5m`.
|
|
@@ -308,6 +328,9 @@ Prevent UI flicker during page changes — keep showing current data while the n
|
|
|
308
328
|
page: { cursor: 'abc123', limit: 20 }
|
|
309
329
|
}
|
|
310
330
|
}
|
|
331
|
+
|
|
332
|
+
// Top-level `cursor` is also accepted — passed through to params.cursor
|
|
333
|
+
{ fetch: { from: 'articles', cursor: 'abc123' } }
|
|
311
334
|
```
|
|
312
335
|
|
|
313
336
|
## Infinite queries
|
|
@@ -504,6 +527,21 @@ queryClient.removeQueries('articles')
|
|
|
504
527
|
queryClient.removeQueries() // clear all
|
|
505
528
|
```
|
|
506
529
|
|
|
530
|
+
### Raw cache access
|
|
531
|
+
|
|
532
|
+
```js
|
|
533
|
+
queryClient.getCache() // the underlying Map of cache entries
|
|
534
|
+
queryClient.clear() // remove every entry
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### Language eviction
|
|
538
|
+
|
|
539
|
+
`dropNonLang(keepLang)` removes every cache entry whose language suffix isn't `keepLang`, leaving entries with no language suffix untouched. Used when the active language changes to flush stale-locale responses while keeping the fallback locale (typically `'en'`) warm:
|
|
540
|
+
|
|
541
|
+
```js
|
|
542
|
+
queryClient.dropNonLang('en') // keep English + lang-less entries, drop the rest
|
|
543
|
+
```
|
|
544
|
+
|
|
507
545
|
### Prefetch
|
|
508
546
|
|
|
509
547
|
Prefetch data before it's needed (e.g. on hover):
|
|
@@ -636,9 +674,13 @@ db.update({ from, data, params, method, headers, baseUrl }) // method: 'PUT' |
|
|
|
636
674
|
db.delete({ from, params, headers, baseUrl })
|
|
637
675
|
db.rpc({ from, params, headers, baseUrl })
|
|
638
676
|
|
|
677
|
+
// Supabase select/insert/update/upsert also accept `schema` to target a
|
|
678
|
+
// non-public Postgres schema: db.select({ from: 'users', schema: 'auth' })
|
|
679
|
+
|
|
639
680
|
// Auth
|
|
640
681
|
db.getSession()
|
|
641
|
-
db.
|
|
682
|
+
db.getUser() // Supabase
|
|
683
|
+
db.signIn({ email, password }) // also: { provider } (OAuth) | { token } (id token)
|
|
642
684
|
db.signOut()
|
|
643
685
|
db.setToken(jwt) // REST
|
|
644
686
|
db.signUp({ email, password }) // Supabase
|
|
@@ -682,6 +724,32 @@ const db = createAdapter({
|
|
|
682
724
|
})
|
|
683
725
|
```
|
|
684
726
|
|
|
727
|
+
### Registering a named adapter
|
|
728
|
+
|
|
729
|
+
For adapters with optional/peer deps (so they aren't bundled until used), register a lazy loader by name. A registered loader can then be selected with `db: { adapter: 'name', ... }`:
|
|
730
|
+
|
|
731
|
+
```js
|
|
732
|
+
import { registerAdapter } from '@symbo.ls/fetch'
|
|
733
|
+
|
|
734
|
+
// loader resolves to a module exporting `setup(options) => adapter`
|
|
735
|
+
registerAdapter('sdk', () => import('./adapters/sdk.js'))
|
|
736
|
+
|
|
737
|
+
// elsewhere
|
|
738
|
+
db: { adapter: 'sdk', /* ...options passed to setup() */ }
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
The registry lives on `globalThis` (`Symbol.for`-keyed) so a registration from any bundle copy is visible to every resolver — and resolution tolerates a boot-time race: an element created before its custom adapter registers waits briefly (up to 5s) for the registration rather than throwing. Custom registrations shadow the built-ins (`supabase`, `rest`, `local`), so `registerAdapter('supabase', …)` overrides the bundled one.
|
|
742
|
+
|
|
743
|
+
### Direct adapter imports
|
|
744
|
+
|
|
745
|
+
The built-in adapters are also exposed as subpath exports — import a `setup` directly to build an adapter without going through `db.adapter`:
|
|
746
|
+
|
|
747
|
+
```js
|
|
748
|
+
import { setup as supabase } from '@symbo.ls/fetch/supabase'
|
|
749
|
+
import { setup as rest } from '@symbo.ls/fetch/rest'
|
|
750
|
+
import { setup as local } from '@symbo.ls/fetch/local'
|
|
751
|
+
```
|
|
752
|
+
|
|
685
753
|
## Language / i18n
|
|
686
754
|
|
|
687
755
|
Fetch automatically injects the current language into every request — both as a `lang` query parameter and as an `Accept-Language` header.
|
|
@@ -756,10 +824,12 @@ When used as a plugin, fetch hooks into the `create` lifecycle to auto-execute f
|
|
|
756
824
|
| `as` | string | — | Target state key |
|
|
757
825
|
| `on` | string | `'create'` | Trigger: `create`, `click`, `submit`, `stateChange` |
|
|
758
826
|
| `enabled` | boolean/function | `true` | Enable/disable query |
|
|
827
|
+
| `skip` | boolean/function | `false` | Inverse of `enabled` — suppress the query |
|
|
759
828
|
| `placeholderData` | any/function | — | Temporary data while loading |
|
|
760
829
|
| `initialData` | any/function | — | Pre-populate cache |
|
|
761
830
|
| `keepPreviousData` | boolean | `false` | Keep current data during refetch |
|
|
762
831
|
| `page` | number/object | — | Pagination: page number or `{ offset, limit, cursor }` |
|
|
832
|
+
| `cursor` | string | — | Cursor passed through to `params.cursor` |
|
|
763
833
|
| `pageSize` | number | `limit` or `20` | Items per page |
|
|
764
834
|
| `infinite` | boolean | `false` | Enable infinite query mode |
|
|
765
835
|
| `getNextPageParam` | function | — | `(lastPage, allPages) => cursor \| null` |
|
|
@@ -776,6 +846,9 @@ When used as a plugin, fetch hooks into the `create` lifecycle to auto-execute f
|
|
|
776
846
|
| `onSettled` | function | — | After mutation completes (success or error) |
|
|
777
847
|
| `auth` | boolean | `false` | Require authentication |
|
|
778
848
|
| `fields` | boolean/array | — | Collect form fields for mutations |
|
|
849
|
+
| `transformParams` | function | — | Reshape collected form data for `on: 'submit'` RPC |
|
|
850
|
+
| `subscribeOn` | string | `'*'` | Realtime event filter for `method: 'subscribe'` (`INSERT`, `UPDATE`, `DELETE`) |
|
|
851
|
+
| `schema` | string | `'public'` | Postgres schema (Supabase) |
|
|
779
852
|
| `single` | boolean | `false` | Return single row |
|
|
780
853
|
| `limit` | number | — | Row limit |
|
|
781
854
|
| `offset` | number | — | Row offset |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/fetch",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.402",
|
|
4
4
|
"license": "CC-BY-NC-4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@symbo.ls/utils": "^3.14.105"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@supabase/supabase-js": "^2.
|
|
47
|
+
"@supabase/supabase-js": "^2.108.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"@supabase/supabase-js": {
|