@sylphx/lens-solid 2.1.4 → 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 +17 -26
- package/package.json +1 -1
- package/src/create.ts +49 -31
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,
|
|
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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AsC;IACtC,cAAc,EAAE,CACf,OAAO,CAAC,EAAE,wBAAwB,CAAC,OAAO,CAAC,KACvC,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9C;AAED,2CAA2C;AAC3C,KAAK,gBAAgB,CAAC,OAAO,SAAS,YAAY,IAAI;KACpD,CAAC,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,aAAa,CAAC,GACpE,gBAAgB,CAAC,aAAa,CAAC,GAC/B,OAAO,CAAC,CAAC,CAAC,SAAS,QAAQ,CAAC,MAAM,MAAM,EAAE,MAAM,OAAO,CAAC,GACvD,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,MAAM,EAAE,MAAM,OAAO,CAAC,GAC1D,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,KAAK;CACV,CAAC;AAEF,+BAA+B;AAC/B,MAAM,MAAM,WAAW,CAAC,OAAO,SAAS,SAAS,IAChD,OAAO,SAAS,SAAS,CAAC,MAAM,OAAO,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;AAiK9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,YAAY,CAAC,OAAO,SAAS,SAAS,EACrD,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,GAC/D,WAAW,CAAC,OAAO,CAAC,CAoEtB"}
|
package/dist/index.js
CHANGED
|
@@ -1104,7 +1104,7 @@ class SubscriptionRegistry {
|
|
|
1104
1104
|
}
|
|
1105
1105
|
|
|
1106
1106
|
// src/create.ts
|
|
1107
|
-
import { createSignal, onCleanup } from "solid-js";
|
|
1107
|
+
import { createEffect, createSignal, on, onCleanup } from "solid-js";
|
|
1108
1108
|
function createQueryPrimitiveFactory(getEndpoint) {
|
|
1109
1109
|
return function createQuery(options) {
|
|
1110
1110
|
const [data, setData] = createSignal(null);
|
|
@@ -1114,6 +1114,7 @@ function createQueryPrimitiveFactory(getEndpoint) {
|
|
|
1114
1114
|
const executeQuery = () => {
|
|
1115
1115
|
if (unsubscribe) {
|
|
1116
1116
|
unsubscribe();
|
|
1117
|
+
options?.debug?.onUnsubscribe?.();
|
|
1117
1118
|
unsubscribe = null;
|
|
1118
1119
|
}
|
|
1119
1120
|
if (options?.skip) {
|
|
@@ -1126,52 +1127,42 @@ 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();
|
|
1150
|
+
createEffect(on(() => ({
|
|
1151
|
+
inputKey: JSON.stringify(options?.input),
|
|
1152
|
+
selectKey: JSON.stringify(options?.select),
|
|
1153
|
+
skip: options?.skip
|
|
1154
|
+
}), () => {
|
|
1155
|
+
executeQuery();
|
|
1156
|
+
}, { defer: true }));
|
|
1145
1157
|
onCleanup(() => {
|
|
1146
1158
|
if (unsubscribe) {
|
|
1147
1159
|
unsubscribe();
|
|
1160
|
+
options?.debug?.onUnsubscribe?.();
|
|
1148
1161
|
unsubscribe = null;
|
|
1149
1162
|
}
|
|
1150
1163
|
});
|
|
1151
1164
|
const refetch = () => {
|
|
1152
|
-
|
|
1153
|
-
unsubscribe();
|
|
1154
|
-
unsubscribe = null;
|
|
1155
|
-
}
|
|
1156
|
-
setLoading(true);
|
|
1157
|
-
setError(null);
|
|
1158
|
-
const endpoint = getEndpoint();
|
|
1159
|
-
const query = endpoint({ input: options?.input, select: options?.select });
|
|
1160
|
-
if (query) {
|
|
1161
|
-
unsubscribe = query.subscribe((value) => {
|
|
1162
|
-
setData(() => value);
|
|
1163
|
-
setLoading(false);
|
|
1164
|
-
setError(null);
|
|
1165
|
-
});
|
|
1166
|
-
query.then((value) => {
|
|
1167
|
-
setData(() => value);
|
|
1168
|
-
setLoading(false);
|
|
1169
|
-
}, (err) => {
|
|
1170
|
-
const queryError = err instanceof Error ? err : new Error(String(err));
|
|
1171
|
-
setError(queryError);
|
|
1172
|
-
setLoading(false);
|
|
1173
|
-
});
|
|
1174
|
-
}
|
|
1165
|
+
executeQuery();
|
|
1175
1166
|
};
|
|
1176
1167
|
return { data, loading, error, refetch };
|
|
1177
1168
|
};
|
|
@@ -1286,7 +1277,7 @@ function useLensClient() {
|
|
|
1286
1277
|
return client;
|
|
1287
1278
|
}
|
|
1288
1279
|
// src/primitives.ts
|
|
1289
|
-
import { createEffect, createSignal as createSignal2, onCleanup as onCleanup2 } from "solid-js";
|
|
1280
|
+
import { createEffect as createEffect2, createSignal as createSignal2, onCleanup as onCleanup2 } from "solid-js";
|
|
1290
1281
|
function resolveQuery(input) {
|
|
1291
1282
|
return typeof input === "function" ? input() : input;
|
|
1292
1283
|
}
|
|
@@ -1325,7 +1316,7 @@ function createQuery(queryInput, options) {
|
|
|
1325
1316
|
};
|
|
1326
1317
|
const initialQuery = resolveQuery(queryInput);
|
|
1327
1318
|
executeQuery(initialQuery);
|
|
1328
|
-
|
|
1319
|
+
createEffect2(() => {
|
|
1329
1320
|
const queryResult = resolveQuery(queryInput);
|
|
1330
1321
|
if (queryResult !== initialQuery) {
|
|
1331
1322
|
executeQuery(queryResult);
|
package/package.json
CHANGED
package/src/create.ts
CHANGED
|
@@ -33,20 +33,40 @@ import {
|
|
|
33
33
|
type TypedClientConfig,
|
|
34
34
|
} from "@sylphx/lens-client";
|
|
35
35
|
import type { MutationDef, QueryDef, RouterDef, RouterRoutes } from "@sylphx/lens-core";
|
|
36
|
-
import { type Accessor, createSignal, onCleanup } from "solid-js";
|
|
36
|
+
import { type Accessor, createEffect, createSignal, on, onCleanup } from "solid-js";
|
|
37
37
|
|
|
38
38
|
// =============================================================================
|
|
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
|
};
|
|
@@ -185,40 +210,33 @@ function createQueryPrimitiveFactory<TInput, TOutput>(
|
|
|
185
210
|
// Execute initial query
|
|
186
211
|
executeQuery();
|
|
187
212
|
|
|
213
|
+
// Watch for input/select changes using JSON.stringify for stable comparison
|
|
214
|
+
// This prevents re-fetching when object reference changes but content is the same
|
|
215
|
+
// Using on() with defer: true to skip initial run (already executed above)
|
|
216
|
+
createEffect(
|
|
217
|
+
on(
|
|
218
|
+
() => ({
|
|
219
|
+
inputKey: JSON.stringify(options?.input),
|
|
220
|
+
selectKey: JSON.stringify(options?.select),
|
|
221
|
+
skip: options?.skip,
|
|
222
|
+
}),
|
|
223
|
+
() => {
|
|
224
|
+
executeQuery();
|
|
225
|
+
},
|
|
226
|
+
{ defer: true },
|
|
227
|
+
),
|
|
228
|
+
);
|
|
229
|
+
|
|
188
230
|
onCleanup(() => {
|
|
189
231
|
if (unsubscribe) {
|
|
190
232
|
unsubscribe();
|
|
233
|
+
options?.debug?.onUnsubscribe?.();
|
|
191
234
|
unsubscribe = null;
|
|
192
235
|
}
|
|
193
236
|
});
|
|
194
237
|
|
|
195
238
|
const refetch = () => {
|
|
196
|
-
|
|
197
|
-
unsubscribe();
|
|
198
|
-
unsubscribe = null;
|
|
199
|
-
}
|
|
200
|
-
setLoading(true);
|
|
201
|
-
setError(null);
|
|
202
|
-
const endpoint = getEndpoint();
|
|
203
|
-
const query = endpoint({ input: options?.input, select: options?.select });
|
|
204
|
-
if (query) {
|
|
205
|
-
unsubscribe = query.subscribe((value) => {
|
|
206
|
-
setData(() => value);
|
|
207
|
-
setLoading(false);
|
|
208
|
-
setError(null);
|
|
209
|
-
});
|
|
210
|
-
query.then(
|
|
211
|
-
(value) => {
|
|
212
|
-
setData(() => value);
|
|
213
|
-
setLoading(false);
|
|
214
|
-
},
|
|
215
|
-
(err) => {
|
|
216
|
-
const queryError = err instanceof Error ? err : new Error(String(err));
|
|
217
|
-
setError(queryError);
|
|
218
|
-
setLoading(false);
|
|
219
|
-
},
|
|
220
|
-
);
|
|
221
|
-
}
|
|
239
|
+
executeQuery();
|
|
222
240
|
};
|
|
223
241
|
|
|
224
242
|
return { data, loading, error, refetch };
|