@symbo.ls/fetch 3.14.285 → 3.14.403

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +84 -6
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @symbo.ls/fetch
2
2
 
3
+ ## 3.14.403
4
+
5
+ ### Patch Changes
6
+
7
+ - Auto-generated cross-repo patch release.
8
+
9
+ ## 3.14.402
10
+
11
+ ### Patch Changes
12
+
13
+ - Auto-generated cross-repo patch release.
14
+
3
15
  ## 3.14.285
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -4,17 +4,17 @@ Declarative data fetching for DOMQL with pluggable adapters. Supports caching, s
4
4
 
5
5
  ## Setup
6
6
 
7
- Add `db` to `config.js`:
7
+ Add `fetch` to `config.js` — this is the connection/adapter config (distinct from the per-element `fetch` query declaration; the runtime resolves it onto `context.fetch`):
8
8
 
9
9
  ```js
10
10
  // Supabase
11
- db: { adapter: 'supabase', projectId: '...', key: '...' }
11
+ fetch: { adapter: 'supabase', projectId: '...', key: '...' }
12
12
 
13
13
  // Supabase — config from state
14
- db: { adapter: 'supabase', state: 'supabase' } // merges root state.supabase
14
+ fetch: { adapter: 'supabase', state: 'supabase' } // merges root state.supabase
15
15
 
16
16
  // REST
17
- db: {
17
+ fetch: {
18
18
  adapter: 'rest',
19
19
  url: 'https://api.example.com',
20
20
  headers: { Authorization: 'Bearer token' },
@@ -28,9 +28,14 @@ db: {
28
28
  }
29
29
 
30
30
  // Local
31
- db: { adapter: 'local', data: { articles: [] }, persist: true }
31
+ fetch: { adapter: 'local', data: { articles: [] }, persist: true }
32
+
33
+ // Custom/registered adapter (see Registering a named adapter)
34
+ fetch: { adapter: 'sdk', sdk: getSDK() }
32
35
  ```
33
36
 
37
+ > `db` is **not** a config key — it's the local name for the resolved adapter you get from `await this.getDB()` (`db.select(...)`, `db.insert(...)`, …).
38
+
34
39
  ## Declarative `fetch`
35
40
 
36
41
  ```js
@@ -99,6 +104,20 @@ Like TanStack's `select`, pick or reshape data before it hits state. Runs after
99
104
  }
100
105
  ```
101
106
 
107
+ 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:
108
+
109
+ ```js
110
+ {
111
+ tag: 'form',
112
+ fetch: {
113
+ method: 'rpc',
114
+ from: 'submit_application',
115
+ on: 'submit',
116
+ transformParams: (formData, el, state) => ({ p_payload: formData })
117
+ }
118
+ }
119
+ ```
120
+
102
121
  ### Array fetch (parallel)
103
122
 
104
123
  ```js
@@ -130,6 +149,12 @@ Like TanStack's `select`, pick or reshape data before it hits state. Runs after
130
149
  { fetch: { from: 'profile', enabled: (el, state) => !!state.userId } }
131
150
  ```
132
151
 
152
+ `skip` is the inverse alias — `skip: true` (or a function returning `true`) suppresses the fetch:
153
+
154
+ ```js
155
+ { fetch: { from: 'profile', skip: (el, state) => !state.userId } }
156
+ ```
157
+
133
158
  ## Cache
134
159
 
135
160
  Default: all queries cache with `staleTime: 1m`, `gcTime: 5m`.
@@ -308,6 +333,9 @@ Prevent UI flicker during page changes — keep showing current data while the n
308
333
  page: { cursor: 'abc123', limit: 20 }
309
334
  }
310
335
  }
336
+
337
+ // Top-level `cursor` is also accepted — passed through to params.cursor
338
+ { fetch: { from: 'articles', cursor: 'abc123' } }
311
339
  ```
312
340
 
313
341
  ## Infinite queries
@@ -504,6 +532,21 @@ queryClient.removeQueries('articles')
504
532
  queryClient.removeQueries() // clear all
505
533
  ```
506
534
 
535
+ ### Raw cache access
536
+
537
+ ```js
538
+ queryClient.getCache() // the underlying Map of cache entries
539
+ queryClient.clear() // remove every entry
540
+ ```
541
+
542
+ ### Language eviction
543
+
544
+ `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:
545
+
546
+ ```js
547
+ queryClient.dropNonLang('en') // keep English + lang-less entries, drop the rest
548
+ ```
549
+
507
550
  ### Prefetch
508
551
 
509
552
  Prefetch data before it's needed (e.g. on hover):
@@ -636,9 +679,13 @@ db.update({ from, data, params, method, headers, baseUrl }) // method: 'PUT' |
636
679
  db.delete({ from, params, headers, baseUrl })
637
680
  db.rpc({ from, params, headers, baseUrl })
638
681
 
682
+ // Supabase select/insert/update/upsert also accept `schema` to target a
683
+ // non-public Postgres schema: db.select({ from: 'users', schema: 'auth' })
684
+
639
685
  // Auth
640
686
  db.getSession()
641
- db.signIn({ email, password })
687
+ db.getUser() // Supabase
688
+ db.signIn({ email, password }) // also: { provider } (OAuth) | { token } (id token)
642
689
  db.signOut()
643
690
  db.setToken(jwt) // REST
644
691
  db.signUp({ email, password }) // Supabase
@@ -682,6 +729,32 @@ const db = createAdapter({
682
729
  })
683
730
  ```
684
731
 
732
+ ### Registering a named adapter
733
+
734
+ 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', ... }`:
735
+
736
+ ```js
737
+ import { registerAdapter } from '@symbo.ls/fetch'
738
+
739
+ // loader resolves to a module exporting `setup(options) => adapter`
740
+ registerAdapter('sdk', () => import('./adapters/sdk.js'))
741
+
742
+ // elsewhere
743
+ db: { adapter: 'sdk', /* ...options passed to setup() */ }
744
+ ```
745
+
746
+ 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.
747
+
748
+ ### Direct adapter imports
749
+
750
+ The built-in adapters are also exposed as subpath exports — import a `setup` directly to build an adapter without going through `db.adapter`:
751
+
752
+ ```js
753
+ import { setup as supabase } from '@symbo.ls/fetch/supabase'
754
+ import { setup as rest } from '@symbo.ls/fetch/rest'
755
+ import { setup as local } from '@symbo.ls/fetch/local'
756
+ ```
757
+
685
758
  ## Language / i18n
686
759
 
687
760
  Fetch automatically injects the current language into every request — both as a `lang` query parameter and as an `Accept-Language` header.
@@ -756,10 +829,12 @@ When used as a plugin, fetch hooks into the `create` lifecycle to auto-execute f
756
829
  | `as` | string | — | Target state key |
757
830
  | `on` | string | `'create'` | Trigger: `create`, `click`, `submit`, `stateChange` |
758
831
  | `enabled` | boolean/function | `true` | Enable/disable query |
832
+ | `skip` | boolean/function | `false` | Inverse of `enabled` — suppress the query |
759
833
  | `placeholderData` | any/function | — | Temporary data while loading |
760
834
  | `initialData` | any/function | — | Pre-populate cache |
761
835
  | `keepPreviousData` | boolean | `false` | Keep current data during refetch |
762
836
  | `page` | number/object | — | Pagination: page number or `{ offset, limit, cursor }` |
837
+ | `cursor` | string | — | Cursor passed through to `params.cursor` |
763
838
  | `pageSize` | number | `limit` or `20` | Items per page |
764
839
  | `infinite` | boolean | `false` | Enable infinite query mode |
765
840
  | `getNextPageParam` | function | — | `(lastPage, allPages) => cursor \| null` |
@@ -776,6 +851,9 @@ When used as a plugin, fetch hooks into the `create` lifecycle to auto-execute f
776
851
  | `onSettled` | function | — | After mutation completes (success or error) |
777
852
  | `auth` | boolean | `false` | Require authentication |
778
853
  | `fields` | boolean/array | — | Collect form fields for mutations |
854
+ | `transformParams` | function | — | Reshape collected form data for `on: 'submit'` RPC |
855
+ | `subscribeOn` | string | `'*'` | Realtime event filter for `method: 'subscribe'` (`INSERT`, `UPDATE`, `DELETE`) |
856
+ | `schema` | string | `'public'` | Postgres schema (Supabase) |
779
857
  | `single` | boolean | `false` | Return single row |
780
858
  | `limit` | number | — | Row limit |
781
859
  | `offset` | number | — | Row offset |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/fetch",
3
- "version": "3.14.285",
3
+ "version": "3.14.403",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "type": "module",
6
6
  "module": "./dist/esm/index.js",