pbtsdb 0.0.1

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/llms.txt ADDED
@@ -0,0 +1,91 @@
1
+ # pbtsdb
2
+
3
+ > Type-safe PocketBase integration with TanStack Query and TanStack DB for React applications. Provides reactive collections with automatic real-time subscriptions, full TypeScript type safety, and minimal boilerplate.
4
+
5
+ This library connects PocketBase (backend-as-a-service) to TanStack's reactive database tools. Use it when building React applications that need real-time data synchronization with PocketBase while maintaining strict type safety.
6
+
7
+ ## Core Pattern
8
+
9
+ ```typescript
10
+ // 1. Define schema with type and relations properties
11
+ export type Schema = {
12
+ books: {
13
+ type: Book;
14
+ relations: {
15
+ author?: Author;
16
+ };
17
+ };
18
+ }
19
+
20
+ // 2. Create factory (once per app)
21
+ const factory = new CollectionFactory<Schema>(pb, queryClient);
22
+
23
+ // 3. Create collections with optional expand for type-safe relations
24
+ const booksCollection = factory.create('books', {
25
+ expand: 'author' as const // Use 'as const' for type inference
26
+ });
27
+
28
+ // 4. Use in React components with automatic subscriptions
29
+ const { data } = useLiveQuery((q) => q.from({ books: booksCollection }));
30
+ // Subscriptions start/stop automatically with component lifecycle
31
+ ```
32
+
33
+ ## Key Concepts
34
+
35
+ - **CollectionFactory**: Create ONE factory per app, use it to create multiple collections
36
+ - **Collections are lazy**: No network activity until first query
37
+ - **Subscriptions are automatic**: Start when component mounts, stop 5s after unmount
38
+ - **Type-safe expand**: Use `as const` on expand strings for full TypeScript inference
39
+ - **Schema structure**: Use `type` and `relations` properties (not `Row`/`Relations`)
40
+
41
+ ## Testing
42
+
43
+ ```bash
44
+ npm test # Auto-resets DB, starts server, runs tests, stops server
45
+ ```
46
+
47
+ Tests use real PocketBase instance (not mocked). Server infrastructure is fully automated.
48
+
49
+ ## Documentation
50
+
51
+ - [AGENTS.md](AGENTS.md): Complete development guide with architecture, patterns, and testing
52
+ - [README.md](README.md): User-facing API reference with examples
53
+ - [test/schema.ts](test/schema.ts): Reference schema implementation
54
+
55
+ ## Common Patterns
56
+
57
+ **Approach 1: Type-Safe Expand (Recommended)**
58
+ ```typescript
59
+ const jobs = factory.create('jobs', { expand: 'customer,address' as const });
60
+ // Single PocketBase query, server-side join, fully typed expand property
61
+ ```
62
+
63
+ **Approach 2: TanStack Joins (Advanced)**
64
+ ```typescript
65
+ const jobs = factory.create('jobs', { relations: { customer: customersCollection }});
66
+ // Client-side joins with full type safety, supports inner/left/right/full joins
67
+ ```
68
+
69
+ ## Critical Rules
70
+
71
+ - NEVER use `any` types - defeats the purpose of this library
72
+ - ALWAYS use `as const` on expand strings for type inference
73
+ - Create ONE CollectionFactory instance per PocketBase connection
74
+ - Schema must match actual PocketBase collection structure
75
+ - Code should be self-documenting - avoid obvious comments
76
+
77
+ ## Optional
78
+
79
+ ### When NOT to Use
80
+
81
+ - Non-React environments (use PocketBase SDK directly)
82
+ - Simple CRUD without real-time (PocketBase SDK is simpler)
83
+ - Very large collections (>10k records - use pagination)
84
+ - Non-PocketBase backends (use TanStack Query directly)
85
+
86
+ ### Package Details
87
+
88
+ - Requires React 18+, TypeScript 5.0+, PocketBase 0.21.0+
89
+ - Collections use TanStack Query for caching and TanStack DB for reactivity
90
+ - Real-time via PocketBase Server-Sent Events (SSE)
91
+ - Automatic reconnection with exponential backoff on subscription failures
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "pbtsdb",
3
+ "version": "0.0.1",
4
+ "description": "Type-safe PocketBase integration with TanStack Query and TanStack DB",
5
+ "keywords": [
6
+ "pocketbase",
7
+ "tanstack",
8
+ "tanstack-query",
9
+ "tanstack-db",
10
+ "database",
11
+ "react",
12
+ "typescript",
13
+ "real-time",
14
+ "subscriptions",
15
+ "backend-as-a-service"
16
+ ],
17
+ "license": "MIT",
18
+ "author": "Nathan Stitt <nathan@stitt.org>",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/nathanstitt/pbtsdb.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/nathanstitt/pbtsdb/issues"
25
+ },
26
+ "homepage": "https://github.com/nathanstitt/pbtsdb#readme",
27
+ "type": "module",
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "import": "./dist/index.js",
33
+ "types": "./dist/index.d.ts"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "llms.txt",
40
+ "LICENSE"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "prepublishOnly": "npm run checks && npm test && npm run build",
45
+ "db:reset": "rm -rf ./pb_data && pocketbase migrate up",
46
+ "checks": "run-p typecheck lint",
47
+ "lint": "biome check .",
48
+ "lint:fix": "biome check . --write",
49
+ "typecheck": "tsc --noEmit --skipLibCheck",
50
+ "test": "start-server-and-test test:server http://127.0.0.1:8210/api/health test:run",
51
+ "test:run": "vitest",
52
+ "test:server": "./scripts/start-test-server.sh",
53
+ "test:server:migrate": "pocketbase migrate --dir ./pb_data"
54
+ },
55
+ "peerDependencies": {
56
+ "@tanstack/query-db-collection": ">=1.0.0",
57
+ "@tanstack/react-db": ">=0.1.0",
58
+ "@tanstack/react-query": ">=5.0.0",
59
+ "pocketbase": ">=0.21.0",
60
+ "react": ">=18.0.0",
61
+ "react-dom": ">=18.0.0"
62
+ },
63
+ "devDependencies": {
64
+ "@tanstack/query-db-collection": ">=1.0.0",
65
+ "@tanstack/react-db": ">=0.1.0",
66
+ "@tanstack/react-query": ">=5.0.0",
67
+ "@testing-library/react": ">=14.0.0",
68
+ "@types/node": ">=18.0.0",
69
+ "@types/react": ">=18.0.0",
70
+ "biome": ">=0.3.0",
71
+ "dotenv": ">=16.0.0",
72
+ "eventsource": ">=2.0.0",
73
+ "jsdom": ">=20.0.0",
74
+ "npm-run-all": ">=4.0.0",
75
+ "pocketbase": ">=0.21.0",
76
+ "react": ">=18.0.0",
77
+ "react-dom": ">=18.0.0",
78
+ "start-server-and-test": ">=2.0.0",
79
+ "tsup": "^8.5.1",
80
+ "tsx": ">=4.0.0",
81
+ "typescript": ">=5.0.0",
82
+ "vitest": ">=1.0.0"
83
+ }
84
+ }