bunderstack-sync 0.13.0 → 0.16.0

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/README.md CHANGED
@@ -23,6 +23,27 @@ ssr: {
23
23
  }
24
24
  ```
25
25
 
26
+ Because `exports` point straight at source, your TypeScript and bundler
27
+ resolve modules *inside this package's own directory* rather than a compiled
28
+ `dist`. That makes a stray `node_modules/bunderstack-sync/node_modules/`
29
+ uniquely dangerous: if one is ever present (e.g. left over from an earlier
30
+ `link:`/`file:` dependency on a local checkout, then never cleaned up after
31
+ switching to a registry version), both `tsc` and the bundler will resolve
32
+ peer packages like `@tanstack/db`, `@tanstack/react-query`, or `react` from
33
+ inside it instead of your app's own `node_modules`. Two copies of a
34
+ context-carrying package means two separate module instances at runtime —
35
+ collections, providers, or contexts from one copy become invisible to hooks
36
+ from the other. If you hit unexplained "not found"/mismatched-type errors,
37
+ check for nested `node_modules` under this package's install location before
38
+ assuming it's an application bug:
39
+
40
+ ```sh
41
+ find node_modules -path '*/bunderstack-sync/node_modules/@tanstack*'
42
+ ```
43
+
44
+ A clean `rm -rf node_modules && bun install` removes any that a normal
45
+ install wouldn't have produced on its own.
46
+
26
47
  ## License
27
48
 
28
49
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunderstack-sync",
3
- "version": "0.13.0",
3
+ "version": "0.16.0",
4
4
  "description": "TanStack DB collections synced live to a bunderstack backend: optimistic mutations with SSE-driven realtime sync.",
5
5
  "keywords": [
6
6
  "bun",
@@ -35,7 +35,7 @@
35
35
  "test": "bun test"
36
36
  },
37
37
  "dependencies": {
38
- "bunderstack-query": "^0.13.0"
38
+ "bunderstack-query": "^0.16.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@tanstack/db": "0.6.16",
package/src/collection.ts CHANGED
@@ -1,10 +1,11 @@
1
+ import type { QueryClient } from '@tanstack/react-query'
2
+
1
3
  import {
2
4
  createCollection,
3
5
  type Collection,
4
6
  type StandardSchema,
5
7
  } from '@tanstack/db'
6
8
  import { queryCollectionOptions } from '@tanstack/query-db-collection'
7
- import type { QueryClient } from '@tanstack/react-query'
8
9
  import {
9
10
  createTableClient,
10
11
  MAX_LIST_LIMIT,
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { QueryClient } from '@tanstack/react-query'
2
+
2
3
  import {
3
4
  createBunderstackQueryClient,
4
5
  type FilesQueryClient,
@@ -8,9 +9,10 @@ import {
8
9
  type UploadedFile,
9
10
  } from 'bunderstack-query'
10
11
 
12
+ import type { CreateFor, RowFor } from './sync-client'
13
+
11
14
  import { createTableCollection, type TableCollection } from './collection'
12
15
  import { createSyncRealtimeClient } from './realtime-sync'
13
- import type { CreateFor, RowFor } from './sync-client'
14
16
 
15
17
  type BaseOptions = {
16
18
  baseUrl?: string
@@ -70,32 +72,28 @@ export function createBunderstackSyncClient<
70
72
  })
71
73
 
72
74
  // Realtime needs a browser-side persistent connection; default off in SSR.
73
- const realtime =
74
- !(options.realtime ?? typeof window !== 'undefined')
75
- ? undefined
76
- : createSyncRealtimeClient({
77
- baseUrl,
78
- queryClient: options.queryClient,
79
- // `createSyncRealtimeClient` expects the ambient `typeof fetch`
80
- // (which includes Bun's `preconnect` static), while our public
81
- // options accept any plain fetch-shaped function — the two
82
- // signatures are otherwise call-compatible.
83
- fetch: fetchFn as typeof fetch,
84
- // Individual collections are typed against their own row shape
85
- // (inferred from `createTableCollection`'s constraint since
86
- // this loop can't carry a per-key TRow), which is narrower
87
- // than `SyncableCollection`'s `unknown`-typed utils. Safe here
88
- // because `realtime-sync.ts` only ever passes server-decoded
89
- // records through, matching each collection's own row shape.
90
- collections: Object.fromEntries(
91
- Object.entries(tablesClient).map(([k, v]) => [
92
- k,
93
- v.collection,
94
- ]),
95
- ) as unknown as NonNullable<
96
- Parameters<typeof createSyncRealtimeClient>[0]['collections']
97
- >,
98
- })
75
+ const realtime = !(options.realtime ?? typeof window !== 'undefined')
76
+ ? undefined
77
+ : createSyncRealtimeClient({
78
+ baseUrl,
79
+ queryClient: options.queryClient,
80
+ // `createSyncRealtimeClient` expects the ambient `typeof fetch`
81
+ // (which includes Bun's `preconnect` static), while our public
82
+ // options accept any plain fetch-shaped function the two
83
+ // signatures are otherwise call-compatible.
84
+ fetch: fetchFn as typeof fetch,
85
+ // Individual collections are typed against their own row shape
86
+ // (inferred from `createTableCollection`'s constraint since
87
+ // this loop can't carry a per-key TRow), which is narrower
88
+ // than `SyncableCollection`'s `unknown`-typed utils. Safe here
89
+ // because `realtime-sync.ts` only ever passes server-decoded
90
+ // records through, matching each collection's own row shape.
91
+ collections: Object.fromEntries(
92
+ Object.entries(tablesClient).map(([k, v]) => [k, v.collection]),
93
+ ) as unknown as NonNullable<
94
+ Parameters<typeof createSyncRealtimeClient>[0]['collections']
95
+ >,
96
+ })
99
97
 
100
98
  return {
101
99
  ...tablesClient,
@@ -1,6 +1,7 @@
1
- import { createRealtimeClient, type RealtimeEvent } from 'bunderstack-query'
2
1
  import type { QueryClient } from '@tanstack/react-query'
3
2
 
3
+ import { createRealtimeClient, type RealtimeEvent } from 'bunderstack-query'
4
+
4
5
  type SyncableCollection = {
5
6
  utils: {
6
7
  writeUpsert: (item: unknown) => void
@@ -1,4 +1,5 @@
1
1
  import type { QueryClient } from '@tanstack/react-query'
2
+
2
3
  import {
3
4
  attachBucketMutationOptions,
4
5
  createBucketClient,
@@ -24,8 +25,8 @@ export type RowFor<
24
25
  > = [InferSelect<TSchema[K]>] extends [never]
25
26
  ? { id: string | number }
26
27
  : InferSelect<TSchema[K]> extends { id: string | number }
27
- ? InferSelect<TSchema[K]>
28
- : { id: string | number }
28
+ ? InferSelect<TSchema[K]>
29
+ : { id: string | number }
29
30
 
30
31
  export type CreateFor<
31
32
  TSchema extends Record<string, unknown>,