@sylphx/lens-solid 2.1.5 → 2.2.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/dist/create.d.ts +21 -2
- package/dist/create.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/package.json +1 -1
- package/src/create.ts +30 -4
package/dist/create.d.ts
CHANGED
|
@@ -27,14 +27,33 @@
|
|
|
27
27
|
import { type LensClientConfig, type QueryResult, type SelectionObject, type TypedClientConfig } from "@sylphx/lens-client";
|
|
28
28
|
import type { MutationDef, QueryDef, RouterDef, RouterRoutes } from "@sylphx/lens-core";
|
|
29
29
|
import { type Accessor } from "solid-js";
|
|
30
|
+
/**
|
|
31
|
+
* Debug callbacks for query primitives.
|
|
32
|
+
* @internal For debugging purposes only - not recommended for production use.
|
|
33
|
+
*/
|
|
34
|
+
export interface QueryDebugOptions<T> {
|
|
35
|
+
/** Called when data is received */
|
|
36
|
+
onData?: (data: T) => void;
|
|
37
|
+
/** Called when an error occurs */
|
|
38
|
+
onError?: (error: Error) => void;
|
|
39
|
+
/** Called when subscription starts */
|
|
40
|
+
onSubscribe?: () => void;
|
|
41
|
+
/** Called when subscription ends */
|
|
42
|
+
onUnsubscribe?: () => void;
|
|
43
|
+
}
|
|
30
44
|
/** Query primitive options */
|
|
31
|
-
export interface QueryPrimitiveOptions<TInput> {
|
|
45
|
+
export interface QueryPrimitiveOptions<TInput, TOutput = unknown> {
|
|
32
46
|
/** Query input parameters */
|
|
33
47
|
input?: TInput;
|
|
34
48
|
/** Field selection */
|
|
35
49
|
select?: SelectionObject;
|
|
36
50
|
/** Skip query execution */
|
|
37
51
|
skip?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Debug callbacks for development.
|
|
54
|
+
* @internal For debugging purposes only - not recommended for production use.
|
|
55
|
+
*/
|
|
56
|
+
debug?: QueryDebugOptions<TOutput>;
|
|
38
57
|
}
|
|
39
58
|
/** Query primitive result */
|
|
40
59
|
export interface QueryPrimitiveResult<T> {
|
|
@@ -80,7 +99,7 @@ export interface QueryEndpoint<TInput, TOutput> {
|
|
|
80
99
|
select?: SelectionObject;
|
|
81
100
|
}): QueryResult<TOutput>;
|
|
82
101
|
/** SolidJS primitive for reactive queries */
|
|
83
|
-
createQuery: (options?: TInput extends void ? QueryPrimitiveOptions<void> | void : QueryPrimitiveOptions<TInput>) => QueryPrimitiveResult<TOutput>;
|
|
102
|
+
createQuery: (options?: TInput extends void ? QueryPrimitiveOptions<void, TOutput> | void : QueryPrimitiveOptions<TInput, TOutput>) => QueryPrimitiveResult<TOutput>;
|
|
84
103
|
}
|
|
85
104
|
/** Mutation endpoint with SolidJS primitives */
|
|
86
105
|
export interface MutationEndpoint<TInput, TOutput> {
|
package/dist/create.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,KAAK,QAAQ,EAA6C,MAAM,UAAU,CAAC;AAMpF,8BAA8B;AAC9B,MAAM,WAAW,qBAAqB,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,E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
|
unsubscribe();
|
|
1117
|
+
options?.debug?.onUnsubscribe?.();
|
|
1117
1118
|
unsubscribe = null;
|
|
1118
1119
|
}
|
|
1119
1120
|
if (options?.skip) {
|
|
@@ -1126,19 +1127,23 @@ function createQueryPrimitiveFactory(getEndpoint) {
|
|
|
1126
1127
|
const query = endpoint({ input: options?.input, select: options?.select });
|
|
1127
1128
|
setLoading(true);
|
|
1128
1129
|
setError(null);
|
|
1130
|
+
options?.debug?.onSubscribe?.();
|
|
1129
1131
|
unsubscribe = query.subscribe((value) => {
|
|
1130
1132
|
setData(() => value);
|
|
1131
1133
|
setLoading(false);
|
|
1132
1134
|
setError(null);
|
|
1135
|
+
options?.debug?.onData?.(value);
|
|
1133
1136
|
});
|
|
1134
1137
|
query.then((value) => {
|
|
1135
1138
|
setData(() => value);
|
|
1136
1139
|
setLoading(false);
|
|
1137
1140
|
setError(null);
|
|
1141
|
+
options?.debug?.onData?.(value);
|
|
1138
1142
|
}, (err) => {
|
|
1139
1143
|
const queryError = err instanceof Error ? err : new Error(String(err));
|
|
1140
1144
|
setError(queryError);
|
|
1141
1145
|
setLoading(false);
|
|
1146
|
+
options?.debug?.onError?.(queryError);
|
|
1142
1147
|
});
|
|
1143
1148
|
};
|
|
1144
1149
|
executeQuery();
|
|
@@ -1152,6 +1157,7 @@ function createQueryPrimitiveFactory(getEndpoint) {
|
|
|
1152
1157
|
onCleanup(() => {
|
|
1153
1158
|
if (unsubscribe) {
|
|
1154
1159
|
unsubscribe();
|
|
1160
|
+
options?.debug?.onUnsubscribe?.();
|
|
1155
1161
|
unsubscribe = null;
|
|
1156
1162
|
}
|
|
1157
1163
|
});
|
package/package.json
CHANGED
package/src/create.ts
CHANGED
|
@@ -39,14 +39,34 @@ import { type Accessor, createEffect, createSignal, on, onCleanup } from "solid-
|
|
|
39
39
|
// Types
|
|
40
40
|
// =============================================================================
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Debug callbacks for query primitives.
|
|
44
|
+
* @internal For debugging purposes only - not recommended for production use.
|
|
45
|
+
*/
|
|
46
|
+
export interface QueryDebugOptions<T> {
|
|
47
|
+
/** Called when data is received */
|
|
48
|
+
onData?: (data: T) => void;
|
|
49
|
+
/** Called when an error occurs */
|
|
50
|
+
onError?: (error: Error) => void;
|
|
51
|
+
/** Called when subscription starts */
|
|
52
|
+
onSubscribe?: () => void;
|
|
53
|
+
/** Called when subscription ends */
|
|
54
|
+
onUnsubscribe?: () => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
/** Query primitive options */
|
|
43
|
-
export interface QueryPrimitiveOptions<TInput> {
|
|
58
|
+
export interface QueryPrimitiveOptions<TInput, TOutput = unknown> {
|
|
44
59
|
/** Query input parameters */
|
|
45
60
|
input?: TInput;
|
|
46
61
|
/** Field selection */
|
|
47
62
|
select?: SelectionObject;
|
|
48
63
|
/** Skip query execution */
|
|
49
64
|
skip?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Debug callbacks for development.
|
|
67
|
+
* @internal For debugging purposes only - not recommended for production use.
|
|
68
|
+
*/
|
|
69
|
+
debug?: QueryDebugOptions<TOutput>;
|
|
50
70
|
}
|
|
51
71
|
|
|
52
72
|
/** Query primitive result */
|
|
@@ -93,8 +113,8 @@ export interface QueryEndpoint<TInput, TOutput> {
|
|
|
93
113
|
/** SolidJS primitive for reactive queries */
|
|
94
114
|
createQuery: (
|
|
95
115
|
options?: TInput extends void
|
|
96
|
-
? QueryPrimitiveOptions<void> | void
|
|
97
|
-
: QueryPrimitiveOptions<TInput>,
|
|
116
|
+
? QueryPrimitiveOptions<void, TOutput> | void
|
|
117
|
+
: QueryPrimitiveOptions<TInput, TOutput>,
|
|
98
118
|
) => QueryPrimitiveResult<TOutput>;
|
|
99
119
|
}
|
|
100
120
|
|
|
@@ -135,7 +155,7 @@ function createQueryPrimitiveFactory<TInput, TOutput>(
|
|
|
135
155
|
getEndpoint: () => (options: unknown) => QueryResult<TOutput>,
|
|
136
156
|
) {
|
|
137
157
|
return function createQuery(
|
|
138
|
-
options?: QueryPrimitiveOptions<TInput>,
|
|
158
|
+
options?: QueryPrimitiveOptions<TInput, TOutput>,
|
|
139
159
|
): QueryPrimitiveResult<TOutput> {
|
|
140
160
|
const [data, setData] = createSignal<TOutput | null>(null);
|
|
141
161
|
const [loading, setLoading] = createSignal(!options?.skip);
|
|
@@ -146,6 +166,7 @@ function createQueryPrimitiveFactory<TInput, TOutput>(
|
|
|
146
166
|
const executeQuery = () => {
|
|
147
167
|
if (unsubscribe) {
|
|
148
168
|
unsubscribe();
|
|
169
|
+
options?.debug?.onUnsubscribe?.();
|
|
149
170
|
unsubscribe = null;
|
|
150
171
|
}
|
|
151
172
|
|
|
@@ -161,11 +182,13 @@ function createQueryPrimitiveFactory<TInput, TOutput>(
|
|
|
161
182
|
|
|
162
183
|
setLoading(true);
|
|
163
184
|
setError(null);
|
|
185
|
+
options?.debug?.onSubscribe?.();
|
|
164
186
|
|
|
165
187
|
unsubscribe = query.subscribe((value) => {
|
|
166
188
|
setData(() => value);
|
|
167
189
|
setLoading(false);
|
|
168
190
|
setError(null);
|
|
191
|
+
options?.debug?.onData?.(value);
|
|
169
192
|
});
|
|
170
193
|
|
|
171
194
|
query.then(
|
|
@@ -173,11 +196,13 @@ function createQueryPrimitiveFactory<TInput, TOutput>(
|
|
|
173
196
|
setData(() => value);
|
|
174
197
|
setLoading(false);
|
|
175
198
|
setError(null);
|
|
199
|
+
options?.debug?.onData?.(value);
|
|
176
200
|
},
|
|
177
201
|
(err) => {
|
|
178
202
|
const queryError = err instanceof Error ? err : new Error(String(err));
|
|
179
203
|
setError(queryError);
|
|
180
204
|
setLoading(false);
|
|
205
|
+
options?.debug?.onError?.(queryError);
|
|
181
206
|
},
|
|
182
207
|
);
|
|
183
208
|
};
|
|
@@ -205,6 +230,7 @@ function createQueryPrimitiveFactory<TInput, TOutput>(
|
|
|
205
230
|
onCleanup(() => {
|
|
206
231
|
if (unsubscribe) {
|
|
207
232
|
unsubscribe();
|
|
233
|
+
options?.debug?.onUnsubscribe?.();
|
|
208
234
|
unsubscribe = null;
|
|
209
235
|
}
|
|
210
236
|
});
|