@spooky-sync/client-solid 0.0.1-canary.9 → 0.0.1-canary.91

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spooky-sync/client-solid",
3
- "version": "0.0.1-canary.9",
3
+ "version": "0.0.1-canary.91",
4
4
  "type": "module",
5
5
  "description": "SurrealDB client with local and remote database support for browser applications",
6
6
  "main": "./dist/index.cjs",
@@ -27,13 +27,14 @@
27
27
  "database",
28
28
  "browser",
29
29
  "offline",
30
- "sync"
30
+ "sync",
31
+ "tanstack-intent"
31
32
  ],
32
33
  "author": "",
33
34
  "license": "MIT",
34
35
  "repository": {
35
36
  "type": "git",
36
- "url": "https://github.com/mono424/spooky.git",
37
+ "url": "https://github.com/mono424/sp00ky.git",
37
38
  "directory": "packages/client-solid"
38
39
  },
39
40
  "publishConfig": {
@@ -41,10 +42,10 @@
41
42
  },
42
43
  "packageManager": "pnpm@9.0.0",
43
44
  "dependencies": {
44
- "@spooky-sync/query-builder": "workspace:*",
45
- "@spooky-sync/core": "workspace:*",
46
- "@surrealdb/wasm": "^3.0.0",
47
- "surrealdb": "2.0.0",
45
+ "@spooky-sync/query-builder": "0.0.1-canary.91",
46
+ "@spooky-sync/core": "0.0.1-canary.91",
47
+ "@surrealdb/wasm": "^3.0.3",
48
+ "surrealdb": "2.0.3",
48
49
  "valtio": "^2.1.8"
49
50
  },
50
51
  "peerDependencies": {
@@ -0,0 +1,264 @@
1
+ ---
2
+ name: sp00ky-solid
3
+ description: >-
4
+ SolidJS integration for the Sp00ky reactive local-first SurrealDB framework.
5
+ Use when setting up Sp00kyProvider, using useQuery for reactive data, building
6
+ queries with QueryBuilder in SolidJS components, handling mutations, auth,
7
+ file uploads/downloads, or working with Sp00ky types like Model and RecordId.
8
+ metadata:
9
+ author: sp00ky-sync
10
+ version: "0.0.1"
11
+ ---
12
+
13
+ # Sp00ky SolidJS Client
14
+
15
+ `@spooky-sync/client-solid` provides SolidJS bindings for the Sp00ky framework. It wraps `@spooky-sync/core` with a context provider, reactive `useQuery` hook, and file operation hooks.
16
+
17
+ ## Setup
18
+
19
+ ```tsx
20
+ import { Sp00kyProvider } from '@spooky-sync/client-solid';
21
+ import { schema } from './generated/schema';
22
+ import schemaSurql from './generated/schema.surql?raw';
23
+
24
+ function App() {
25
+ return (
26
+ <Sp00kyProvider
27
+ config={{
28
+ database: {
29
+ endpoint: 'ws://localhost:8000',
30
+ namespace: 'my_ns',
31
+ database: 'my_db',
32
+ store: 'indexeddb',
33
+ },
34
+ schema,
35
+ schemaSurql,
36
+ logLevel: 'info',
37
+ }}
38
+ fallback={<div>Loading database...</div>}
39
+ onReady={(db) => console.log('DB ready')}
40
+ onError={(err) => console.error('DB failed', err)}
41
+ >
42
+ <MyApp />
43
+ </Sp00kyProvider>
44
+ );
45
+ }
46
+ ```
47
+
48
+ ### Sp00kyProvider Props
49
+
50
+ | Prop | Type | Description |
51
+ |------|------|-------------|
52
+ | `config` | `SyncedDbConfig<S>` | Same as `Sp00kyConfig` from core |
53
+ | `fallback` | `JSX.Element` | Shown while the database is initializing |
54
+ | `onReady` | `(db: SyncedDb<S>) => void` | Called when initialization succeeds |
55
+ | `onError` | `(error: Error) => void` | Called if initialization fails |
56
+ | `children` | `JSX.Element` | App content, rendered after init |
57
+
58
+ ## useQuery
59
+
60
+ The primary hook for reactive data fetching. Queries automatically re-subscribe when inputs change.
61
+
62
+ ### Context-based usage (recommended)
63
+
64
+ ```tsx
65
+ import { useQuery } from '@spooky-sync/client-solid';
66
+ import { QueryBuilder } from '@spooky-sync/query-builder';
67
+ import { schema } from './generated/schema';
68
+
69
+ function PostList() {
70
+ const db = useDb();
71
+
72
+ // Static query
73
+ const posts = useQuery(
74
+ db.query('post').orderBy('createdAt', 'desc').limit(20).build()
75
+ );
76
+
77
+ return (
78
+ <Show when={!posts.isLoading()} fallback={<div>Loading...</div>}>
79
+ <For each={posts.data()}>
80
+ {(post) => <div>{post.title}</div>}
81
+ </For>
82
+ </Show>
83
+ );
84
+ }
85
+ ```
86
+
87
+ ### Reactive queries (function form)
88
+
89
+ Wrap the query in a function to make it reactive to signal changes:
90
+
91
+ ```tsx
92
+ function UserPosts(props: { userId: string }) {
93
+ const db = useDb();
94
+
95
+ // Query re-runs when props.userId changes
96
+ const posts = useQuery(
97
+ () => db.query('post')
98
+ .where({ author: props.userId })
99
+ .related('author')
100
+ .build()
101
+ );
102
+
103
+ return <For each={posts.data()}>{(post) => <div>{post.title}</div>}</For>;
104
+ }
105
+ ```
106
+
107
+ ### Conditional queries
108
+
109
+ Use the `enabled` option to conditionally run queries:
110
+
111
+ ```tsx
112
+ const [userId, setUserId] = createSignal<string | null>(null);
113
+
114
+ const user = useQuery(
115
+ () => userId()
116
+ ? db.query('user').where({ id: userId()! }).one().build()
117
+ : undefined,
118
+ { enabled: () => userId() !== null }
119
+ );
120
+ ```
121
+
122
+ ### Return value
123
+
124
+ | Property | Type | Description |
125
+ |----------|------|-------------|
126
+ | `data` | `() => T \| undefined` | Reactive accessor for query results |
127
+ | `error` | `() => Error \| undefined` | Reactive accessor for errors |
128
+ | `isLoading` | `() => boolean` | `true` until first data arrives |
129
+
130
+ ### Explicit db overload
131
+
132
+ You can also pass the `SyncedDb` instance directly (legacy):
133
+
134
+ ```tsx
135
+ const posts = useQuery(db, db.query('post').build());
136
+ ```
137
+
138
+ ## useDb
139
+
140
+ Access the `SyncedDb` instance from context:
141
+
142
+ ```tsx
143
+ import { useDb } from '@spooky-sync/client-solid';
144
+
145
+ function MyComponent() {
146
+ const db = useDb();
147
+ // db.query(), db.create(), db.update(), db.delete(), db.auth, etc.
148
+ }
149
+ ```
150
+
151
+ ## Mutations
152
+
153
+ Use the `SyncedDb` instance (from `useDb()`) for mutations:
154
+
155
+ ```tsx
156
+ const db = useDb();
157
+
158
+ // Create
159
+ await db.create('post:abc', { title: 'Hello', body: 'World', author: 'user:alice' });
160
+
161
+ // Update
162
+ await db.update('post', 'post:abc', { title: 'Updated' });
163
+
164
+ // Update with debounce
165
+ await db.update('post', 'post:abc', { body: newText }, {
166
+ debounced: { key: 'recordId_x_fields', delay: 300 },
167
+ });
168
+
169
+ // Delete
170
+ await db.delete('post', 'post:abc');
171
+ ```
172
+
173
+ ## Authentication
174
+
175
+ ```tsx
176
+ const db = useDb();
177
+
178
+ await db.auth.signUp('user_access', { email, password, name });
179
+ await db.auth.signIn('user_access', { email, password });
180
+ await db.auth.signOut();
181
+
182
+ // Subscribe to auth state
183
+ const unsub = db.auth.subscribe((userId) => { ... });
184
+ ```
185
+
186
+ ## File Upload & Download
187
+
188
+ See [references/file-hooks.md](references/file-hooks.md) for details.
189
+
190
+ ```tsx
191
+ import { useFileUpload, useDownloadFile } from '@spooky-sync/client-solid';
192
+
193
+ // Upload
194
+ const { upload, isUploading, error } = useFileUpload('avatars');
195
+ await upload('alice/photo.png', file);
196
+
197
+ // Download (reactive)
198
+ const { url, isLoading } = useDownloadFile('avatars', () => user()?.avatarPath);
199
+ ```
200
+
201
+ ## Backend Runs
202
+
203
+ Use `db.run()` to trigger server-side operations via the outbox pattern. See the `sp00ky-core` skill for full details on `db.run()` and how it works.
204
+
205
+ ### Basic Usage
206
+
207
+ ```tsx
208
+ const db = useDb();
209
+ await db.run('api', '/spookify', { id: threadId });
210
+ ```
211
+
212
+ ### Entity Linking with `assignedTo`
213
+
214
+ Pass `assignedTo` to link the job to an entity. This enables permission scoping and lets you query job status via relationships:
215
+
216
+ ```tsx
217
+ const db = useDb();
218
+
219
+ // Trigger backend run linked to a thread
220
+ await db.run('api', '/spookify', { id: threadData.id }, {
221
+ assignedTo: threadData.id, // Links the job record to this thread
222
+ });
223
+ ```
224
+
225
+ ### Tracking Job Status Reactively
226
+
227
+ Use `.related()` to include jobs in your query, then reactively track their status:
228
+
229
+ ```tsx
230
+ // Query a thread with its latest spookify job
231
+ const threadResult = useQuery(() =>
232
+ db.query('thread')
233
+ .where({ id: `thread:${threadId}` })
234
+ .related('jobs', (q) =>
235
+ q.where({ path: '/spookify' }).orderBy('created_at', 'desc').limit(1)
236
+ )
237
+ .one()
238
+ .build()
239
+ );
240
+
241
+ const thread = () => threadResult.data();
242
+
243
+ // Check if a job is in progress
244
+ const isJobLoading = () =>
245
+ ['pending', 'processing'].includes(thread()?.jobs?.[0]?.status ?? '');
246
+
247
+ // Use in UI
248
+ <Show when={isJobLoading()}>
249
+ <span>Processing...</span>
250
+ </Show>
251
+ ```
252
+
253
+ The job's `status` field transitions through: `pending` → `processing` → `success` | `failed`. Since the job record syncs reactively, your UI updates automatically as the backend processes the job.
254
+
255
+ ## Key Re-exports
256
+
257
+ The package re-exports commonly needed types:
258
+
259
+ ```typescript
260
+ import { RecordId, Uuid } from '@spooky-sync/client-solid';
261
+ import type {
262
+ Model, GenericModel, QueryResult, TableModel, TableNames, GetTable,
263
+ } from '@spooky-sync/client-solid';
264
+ ```
@@ -0,0 +1,112 @@
1
+ # File Hooks Reference
2
+
3
+ ## useFileUpload
4
+
5
+ Upload, download, and manage files in a SurrealDB bucket.
6
+
7
+ ### Signatures
8
+
9
+ ```typescript
10
+ // Context-based (inside Sp00kyProvider)
11
+ useFileUpload<S>(bucketName: BucketNames<S>): FileUploadResult;
12
+
13
+ // Explicit db
14
+ useFileUpload<S>(db: SyncedDb<S>, bucketName: BucketNames<S>): FileUploadResult;
15
+ ```
16
+
17
+ ### Return Value
18
+
19
+ ```typescript
20
+ interface FileUploadResult {
21
+ isUploading: () => boolean;
22
+ error: () => Error | null;
23
+ clearError: () => void;
24
+ upload: (path: string, file: File | Blob) => Promise<void>;
25
+ download: (path: string) => Promise<string | null>; // Returns object URL
26
+ remove: (path: string) => Promise<void>;
27
+ exists: (path: string) => Promise<boolean>;
28
+ }
29
+ ```
30
+
31
+ ### Validation
32
+
33
+ If the bucket has `maxSize` or `allowedExtensions` configured in the schema, the hook validates files before upload and sets `error()` on failure.
34
+
35
+ ### Example
36
+
37
+ ```tsx
38
+ function AvatarUpload() {
39
+ const { upload, isUploading, error, clearError } = useFileUpload('avatars');
40
+
41
+ const handleFile = async (e: Event) => {
42
+ const file = (e.target as HTMLInputElement).files?.[0];
43
+ if (file) {
44
+ await upload(`user/${userId()}/avatar.png`, file);
45
+ }
46
+ };
47
+
48
+ return (
49
+ <div>
50
+ <input type="file" onChange={handleFile} disabled={isUploading()} />
51
+ <Show when={error()}>
52
+ <p class="error">{error()!.message}</p>
53
+ <button onClick={clearError}>Dismiss</button>
54
+ </Show>
55
+ </div>
56
+ );
57
+ }
58
+ ```
59
+
60
+ ## useDownloadFile
61
+
62
+ Reactively download a file from a bucket. Re-fetches when the path changes.
63
+
64
+ ### Signatures
65
+
66
+ ```typescript
67
+ // Context-based
68
+ useDownloadFile<S>(
69
+ bucketName: BucketNames<S>,
70
+ path: Accessor<string | null | undefined>,
71
+ options?: { cache?: boolean },
72
+ ): UseDownloadFileResult;
73
+
74
+ // Explicit db
75
+ useDownloadFile<S>(
76
+ db: SyncedDb<S>,
77
+ bucketName: BucketNames<S>,
78
+ path: Accessor<string | null | undefined>,
79
+ options?: { cache?: boolean },
80
+ ): UseDownloadFileResult;
81
+ ```
82
+
83
+ ### Return Value
84
+
85
+ ```typescript
86
+ interface UseDownloadFileResult {
87
+ url: Accessor<string | null>; // Object URL for the file
88
+ isLoading: Accessor<boolean>;
89
+ error: Accessor<Error | null>;
90
+ refetch: () => void; // Force re-download (evicts cache)
91
+ }
92
+ ```
93
+
94
+ ### Caching
95
+
96
+ By default, downloads are cached by `bucket:path` key with reference counting. Object URLs are revoked when no component references them. Set `cache: false` to disable.
97
+
98
+ ### Example
99
+
100
+ ```tsx
101
+ function Avatar(props: { path: string | null }) {
102
+ const { url, isLoading } = useDownloadFile('avatars', () => props.path);
103
+
104
+ return (
105
+ <Show when={!isLoading()} fallback={<Spinner />}>
106
+ <Show when={url()}>
107
+ <img src={url()!} alt="Avatar" />
108
+ </Show>
109
+ </Show>
110
+ );
111
+ }
112
+ ```
@@ -1,6 +1,6 @@
1
1
  export { SurrealDBWasmFactory } from './surrealdb-wasm-factory';
2
2
 
3
- import { Surreal } from 'surrealdb';
3
+ import type { Surreal } from 'surrealdb';
4
4
  import type { CacheStrategy } from '../types';
5
5
 
6
6
  /**
@@ -1,9 +1,11 @@
1
- import { Diagnostic, Surreal, applyDiagnostics } from 'surrealdb';
1
+ import type { Diagnostic} from 'surrealdb';
2
+ import { Surreal, applyDiagnostics } from 'surrealdb';
2
3
  import { createWasmEngines } from '@surrealdb/wasm';
3
4
  import type { CacheStrategy } from '../types';
4
5
 
5
6
  const printDiagnostic = ({ key, type, phase, ...other }: Diagnostic) => {
6
7
  if (phase === 'progress' || phase === 'after') {
8
+ // oxlint-disable-next-line no-console -- intentional diagnostic logging
7
9
  console.log(`[SurrealDB_WASM] [${key}] ${type}:${phase}\n${JSON.stringify(other, null, 2)}`);
8
10
  }
9
11
  };
@@ -11,6 +13,7 @@ const printDiagnostic = ({ key, type, phase, ...other }: Diagnostic) => {
11
13
  /**
12
14
  * SurrealDB WASM client factory for different storage strategies
13
15
  */
16
+ // oxlint-disable-next-line no-extraneous-class -- factory pattern groups related static methods
14
17
  export class SurrealDBWasmFactory {
15
18
  /**
16
19
  * Creates a SurrealDB WASM instance with the specified storage strategy