@spooky-sync/client-solid 0.0.1-canary.4 → 0.0.1-canary.41
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/dist/index.cjs +53 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -21
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +21 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -55
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/skills/sp00ky-solid/SKILL.md +264 -0
- package/skills/sp00ky-solid/references/file-hooks.md +112 -0
- package/src/cache/index.ts +1 -1
- package/src/cache/surrealdb-wasm-factory.ts +4 -1
- package/src/index.ts +59 -52
- package/src/lib/{SpookyProvider.ts → Sp00kyProvider.ts} +9 -7
- package/src/lib/context.ts +3 -3
- package/src/lib/models.ts +1 -1
- package/src/lib/use-download-file.ts +2 -2
- package/src/lib/use-file-upload.ts +2 -1
- package/src/lib/use-query.ts +14 -14
- package/src/types/index.ts +3 -4
package/src/lib/context.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { createContext, useContext } from 'solid-js';
|
|
|
2
2
|
import type { SchemaStructure } from '@spooky/query-builder';
|
|
3
3
|
import type { SyncedDb } from '../index';
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const Sp00kyContext = createContext<SyncedDb<any> | undefined>();
|
|
6
6
|
|
|
7
7
|
export function useDb<S extends SchemaStructure>(): SyncedDb<S> {
|
|
8
|
-
const db = useContext(
|
|
8
|
+
const db = useContext(Sp00kyContext);
|
|
9
9
|
if (!db) {
|
|
10
|
-
throw new Error('useDb must be used within a <
|
|
10
|
+
throw new Error('useDb must be used within a <Sp00kyProvider>. Wrap your app in <Sp00kyProvider config={...}>.');
|
|
11
11
|
}
|
|
12
12
|
return db as SyncedDb<S>;
|
|
13
13
|
}
|
package/src/lib/models.ts
CHANGED
|
@@ -78,9 +78,8 @@ export function useDownloadFile<S extends SchemaStructure>(
|
|
|
78
78
|
|
|
79
79
|
let currentKey: string | null = null;
|
|
80
80
|
let privateUrl: string | null = null;
|
|
81
|
-
let refetchTrigger: () => void;
|
|
82
81
|
const [refetchSignal, setRefetchSignal] = createSignal(0);
|
|
83
|
-
refetchTrigger = () => setRefetchSignal((n) => n + 1);
|
|
82
|
+
const refetchTrigger = () => setRefetchSignal((n) => n + 1);
|
|
84
83
|
|
|
85
84
|
async function doDownload(key: string, filePath: string): Promise<string | null> {
|
|
86
85
|
if (useCache) {
|
|
@@ -184,6 +183,7 @@ export function useDownloadFile<S extends SchemaStructure>(
|
|
|
184
183
|
setUrl(result);
|
|
185
184
|
setIsLoading(false);
|
|
186
185
|
}
|
|
186
|
+
return undefined;
|
|
187
187
|
},
|
|
188
188
|
(err) => {
|
|
189
189
|
if (!cancelled) {
|
|
@@ -33,6 +33,7 @@ export function useFileUpload<S extends SchemaStructure>(
|
|
|
33
33
|
bucketName = dbOrBucketName as BucketNames<S>;
|
|
34
34
|
} else {
|
|
35
35
|
db = dbOrBucketName as SyncedDb<S>;
|
|
36
|
+
// oxlint-disable-next-line no-non-null-assertion
|
|
36
37
|
bucketName = maybeBucketName!;
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -52,7 +53,7 @@ export function useFileUpload<S extends SchemaStructure>(
|
|
|
52
53
|
const config = db.getBucketConfig(bucketName as string);
|
|
53
54
|
if (!config) return;
|
|
54
55
|
|
|
55
|
-
if (config.maxSize
|
|
56
|
+
if (config.maxSize !== null && config.maxSize !== undefined && file.size > config.maxSize) {
|
|
56
57
|
const maxMB = (config.maxSize / (1024 * 1024)).toFixed(1);
|
|
57
58
|
throw new Error(`File exceeds maximum size of ${maxMB} MB.`);
|
|
58
59
|
}
|
package/src/lib/use-query.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
ColumnSchema,
|
|
3
3
|
FinalQuery,
|
|
4
4
|
SchemaStructure,
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
} from '@spooky-sync/query-builder';
|
|
8
8
|
import { createEffect, createSignal, onCleanup, useContext } from 'solid-js';
|
|
9
9
|
import { SyncedDb } from '..';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import type { Sp00kyQueryResultPromise } from '@spooky-sync/core';
|
|
11
|
+
import { Sp00kyContext } from './context';
|
|
12
12
|
|
|
13
13
|
type QueryArg<
|
|
14
14
|
S extends SchemaStructure,
|
|
@@ -17,9 +17,9 @@ type QueryArg<
|
|
|
17
17
|
RelatedFields extends Record<string, any>,
|
|
18
18
|
IsOne extends boolean,
|
|
19
19
|
> =
|
|
20
|
-
| FinalQuery<S, TableName, T, RelatedFields, IsOne,
|
|
20
|
+
| FinalQuery<S, TableName, T, RelatedFields, IsOne, Sp00kyQueryResultPromise>
|
|
21
21
|
| (() =>
|
|
22
|
-
| FinalQuery<S, TableName, T, RelatedFields, IsOne,
|
|
22
|
+
| FinalQuery<S, TableName, T, RelatedFields, IsOne, Sp00kyQueryResultPromise>
|
|
23
23
|
| null
|
|
24
24
|
| undefined);
|
|
25
25
|
|
|
@@ -82,11 +82,11 @@ export function useQuery<
|
|
|
82
82
|
options = maybeOptions;
|
|
83
83
|
} else {
|
|
84
84
|
// Context-based overload: useQuery(query, options?)
|
|
85
|
-
const contextDb = useContext(
|
|
85
|
+
const contextDb = useContext(Sp00kyContext);
|
|
86
86
|
if (!contextDb) {
|
|
87
87
|
throw new Error(
|
|
88
|
-
'useQuery: No db argument provided and no
|
|
89
|
-
'Either pass a SyncedDb instance or wrap your app in <
|
|
88
|
+
'useQuery: No db argument provided and no Sp00kyContext found. ' +
|
|
89
|
+
'Either pass a SyncedDb instance or wrap your app in <Sp00kyProvider>.'
|
|
90
90
|
);
|
|
91
91
|
}
|
|
92
92
|
db = contextDb as SyncedDb<S>;
|
|
@@ -100,23 +100,23 @@ export function useQuery<
|
|
|
100
100
|
const [unsubscribe, setUnsubscribe] = createSignal<(() => void) | undefined>(undefined);
|
|
101
101
|
let prevQueryString: string | undefined;
|
|
102
102
|
|
|
103
|
-
const
|
|
103
|
+
const sp00ky = db.getSp00ky();
|
|
104
104
|
|
|
105
105
|
const initQuery = async (
|
|
106
|
-
query: FinalQuery<S, TableName, T, RelatedFields, IsOne,
|
|
106
|
+
query: FinalQuery<S, TableName, T, RelatedFields, IsOne, Sp00kyQueryResultPromise>
|
|
107
107
|
) => {
|
|
108
108
|
const { hash } = await query.run();
|
|
109
109
|
setError(undefined);
|
|
110
110
|
|
|
111
111
|
let isFirstCall = true;
|
|
112
|
-
const unsub = await
|
|
112
|
+
const unsub = await sp00ky.subscribe(
|
|
113
113
|
hash,
|
|
114
114
|
(e) => {
|
|
115
|
-
const
|
|
116
|
-
setData(() =>
|
|
115
|
+
const queryData = (query.isOne ? e[0] : e) as TData;
|
|
116
|
+
setData(() => queryData);
|
|
117
117
|
// The first (immediate) callback with no data likely means the local DB
|
|
118
118
|
// hasn't synced yet — don't mark as fetched so UI shows loading state
|
|
119
|
-
const hasData = query.isOne ?
|
|
119
|
+
const hasData = query.isOne ? queryData !== null && queryData !== undefined : (e as any[]).length > 0;
|
|
120
120
|
if (!isFirstCall || hasData) {
|
|
121
121
|
setIsFetched(true);
|
|
122
122
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Surreal } from 'surrealdb';
|
|
2
1
|
import type { SyncedDb } from '../index';
|
|
3
|
-
import { GenericSchema } from '../lib/models';
|
|
4
|
-
import type {
|
|
2
|
+
import type { GenericSchema } from '../lib/models';
|
|
3
|
+
import type { Sp00kyConfig } from '@spooky-sync/core';
|
|
5
4
|
import type { SchemaStructure, TableNames, GetTable, TableModel } from '@spooky-sync/query-builder';
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -44,7 +43,7 @@ export type InferRelationshipsFromConst<S extends SchemaStructure, Schema extend
|
|
|
44
43
|
// Prettify helper expands types for better intellisense
|
|
45
44
|
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
46
45
|
|
|
47
|
-
export type SyncedDbConfig<S extends SchemaStructure> = Prettify<
|
|
46
|
+
export type SyncedDbConfig<S extends SchemaStructure> = Prettify<Sp00kyConfig<S>>;
|
|
48
47
|
|
|
49
48
|
// export interface LocalDbConfig {
|
|
50
49
|
// name: string;
|