@sylphx/lens-solid 1.0.4 → 1.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/index.d.ts CHANGED
@@ -5,5 +5,5 @@
5
5
  * Reactive primitives that integrate with SolidJS fine-grained reactivity.
6
6
  */
7
7
  export { LensProvider, useLensClient, type LensProviderProps } from "./context";
8
- export { createQuery, createLazyQuery, createMutation, type CreateQueryResult, type CreateMutationResult, type CreateLazyQueryResult, type CreateQueryOptions, type MutationFn, } from "./primitives";
8
+ export { createQuery, createLazyQuery, createMutation, type QueryInput, type CreateQueryResult, type CreateMutationResult, type CreateLazyQueryResult, type CreateQueryOptions, type MutationFn, } from "./primitives";
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAMhF,OAAO,EAEN,WAAW,EACX,eAAe,EAEf,cAAc,EAEd,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,UAAU,GACf,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAMhF,OAAO,EAEN,WAAW,EACX,eAAe,EAEf,cAAc,EAEd,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,UAAU,GACf,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -15,17 +15,24 @@ function useLensClient() {
15
15
  }
16
16
  // src/primitives.ts
17
17
  import { createSignal, onCleanup } from "solid-js";
18
- function createQuery(queryFn, options) {
18
+ function resolveQuery(input) {
19
+ return typeof input === "function" ? input() : input;
20
+ }
21
+ function createQuery(queryInput, options) {
19
22
  const [data, setData] = createSignal(null);
20
23
  const [loading, setLoading] = createSignal(!options?.skip);
21
24
  const [error, setError] = createSignal(null);
22
25
  let unsubscribe = null;
23
26
  const executeQuery = () => {
24
- if (options?.skip) {
27
+ const queryResult = resolveQuery(queryInput);
28
+ if (options?.skip || queryResult == null) {
29
+ setData(null);
25
30
  setLoading(false);
31
+ setError(null);
26
32
  return;
27
33
  }
28
- const queryResult = queryFn();
34
+ setLoading(true);
35
+ setError(null);
29
36
  unsubscribe = queryResult.subscribe((value) => {
30
37
  setData(() => value);
31
38
  setLoading(false);
@@ -96,15 +103,20 @@ function createMutation(mutationFn) {
96
103
  reset
97
104
  };
98
105
  }
99
- function createLazyQuery(queryFn) {
106
+ function createLazyQuery(queryInput) {
100
107
  const [data, setData] = createSignal(null);
101
108
  const [loading, setLoading] = createSignal(false);
102
109
  const [error, setError] = createSignal(null);
103
110
  const execute = async () => {
111
+ const queryResult = resolveQuery(queryInput);
112
+ if (queryResult == null) {
113
+ setData(null);
114
+ setLoading(false);
115
+ return null;
116
+ }
104
117
  setLoading(true);
105
118
  setError(null);
106
119
  try {
107
- const queryResult = queryFn();
108
120
  const result = await queryResult;
109
121
  setData(() => result);
110
122
  setLoading(false);
@@ -6,6 +6,8 @@
6
6
  */
7
7
  import type { MutationResult, QueryResult } from "@sylphx/lens-client";
8
8
  import { type Accessor } from "solid-js";
9
+ /** Query input - can be a query, null/undefined, or an accessor function */
10
+ export type QueryInput<T> = QueryResult<T> | null | undefined | (() => QueryResult<T> | null | undefined);
9
11
  /** Query result with reactive signals */
10
12
  export interface CreateQueryResult<T> {
11
13
  /** Reactive data accessor */
@@ -69,9 +71,17 @@ export type MutationFn<TInput, TOutput> = (input: TInput) => Promise<MutationRes
69
71
  * </Show>
70
72
  * );
71
73
  * }
74
+ *
75
+ * // Conditional query (null when condition not met)
76
+ * function SessionInfo(props: { sessionId: string | null }) {
77
+ * const session = createQuery(() =>
78
+ * props.sessionId ? client.session.get({ id: props.sessionId }) : null
79
+ * );
80
+ * return <span>{session.data()?.totalTokens}</span>;
81
+ * }
72
82
  * ```
73
83
  */
74
- export declare function createQuery<T>(queryFn: () => QueryResult<T>, options?: CreateQueryOptions): CreateQueryResult<T>;
84
+ export declare function createQuery<T>(queryInput: QueryInput<T>, options?: CreateQueryOptions): CreateQueryResult<T>;
75
85
  /**
76
86
  * Create a reactive mutation with loading/error state.
77
87
  *
@@ -145,7 +155,12 @@ export declare function createMutation<TInput, TOutput>(mutationFn: MutationFn<T
145
155
  * </div>
146
156
  * );
147
157
  * }
158
+ *
159
+ * // Conditional query (null when condition not met)
160
+ * const lazySession = createLazyQuery(() =>
161
+ * sessionId() ? client.session.get({ id: sessionId() }) : null
162
+ * );
148
163
  * ```
149
164
  */
150
- export declare function createLazyQuery<T>(queryFn: () => QueryResult<T>): CreateLazyQueryResult<T>;
165
+ export declare function createLazyQuery<T>(queryInput: QueryInput<T>): CreateLazyQueryResult<T>;
151
166
  //# sourceMappingURL=primitives.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../src/primitives.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,KAAK,QAAQ,EAA2B,MAAM,UAAU,CAAC;AAMlE,yCAAyC;AACzC,MAAM,WAAW,iBAAiB,CAAC,CAAC;IACnC,6BAA6B;IAC7B,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACzB,6BAA6B;IAC7B,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC3B,2BAA2B;IAC3B,KAAK,EAAE,Q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AE,UAAU,CAAC,CAAC,CAAC,EACzB,OAAO,CAAC,EAAE,kBAAkB,GAC1B,iBAAiB,CAAC,CAAC,CAAC,CAsEtB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,EAC7C,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,CAmCvC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CA2CtF"}
package/package.json CHANGED
@@ -1,43 +1,43 @@
1
1
  {
2
- "name": "@sylphx/lens-solid",
3
- "version": "1.0.4",
4
- "description": "SolidJS bindings for Lens API framework",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
- }
13
- },
14
- "scripts": {
15
- "build": "bun build ./src/index.ts --outdir ./dist --target browser --external solid-js && tsc --emitDeclarationOnly --declaration --outDir ./dist",
16
- "typecheck": "tsc --noEmit",
17
- "test": "bun test"
18
- },
19
- "files": [
20
- "dist",
21
- "src"
22
- ],
23
- "keywords": [
24
- "lens",
25
- "solid",
26
- "solidjs",
27
- "reactive",
28
- "signals"
29
- ],
30
- "author": "SylphxAI",
31
- "license": "MIT",
32
- "dependencies": {
33
- "@sylphx/lens-client": "workspace:*"
34
- },
35
- "peerDependencies": {
36
- "solid-js": ">=1.8.0"
37
- },
38
- "devDependencies": {
39
- "@solidjs/testing-library": "^0.8.10",
40
- "solid-js": "^1.9.5",
41
- "typescript": "^5.9.3"
42
- }
2
+ "name": "@sylphx/lens-solid",
3
+ "version": "1.2.0",
4
+ "description": "SolidJS bindings for Lens API framework",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "bun build ./src/index.ts --outdir ./dist --target browser --external solid-js && tsc --emitDeclarationOnly --declaration --outDir ./dist",
16
+ "typecheck": "tsc --noEmit",
17
+ "test": "bun test"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "src"
22
+ ],
23
+ "keywords": [
24
+ "lens",
25
+ "solid",
26
+ "solidjs",
27
+ "reactive",
28
+ "signals"
29
+ ],
30
+ "author": "SylphxAI",
31
+ "license": "MIT",
32
+ "dependencies": {
33
+ "@sylphx/lens-client": "^1.0.4"
34
+ },
35
+ "peerDependencies": {
36
+ "solid-js": ">=1.8.0"
37
+ },
38
+ "devDependencies": {
39
+ "@solidjs/testing-library": "^0.8.10",
40
+ "solid-js": "^1.9.5",
41
+ "typescript": "^5.9.3"
42
+ }
43
43
  }
package/src/index.ts CHANGED
@@ -22,6 +22,7 @@ export {
22
22
  // Mutation primitive
23
23
  createMutation,
24
24
  // Types
25
+ type QueryInput,
25
26
  type CreateQueryResult,
26
27
  type CreateMutationResult,
27
28
  type CreateLazyQueryResult,
package/src/primitives.ts CHANGED
@@ -8,6 +8,22 @@
8
8
  import type { MutationResult, QueryResult } from "@sylphx/lens-client";
9
9
  import { type Accessor, createSignal, onCleanup } from "solid-js";
10
10
 
11
+ // =============================================================================
12
+ // Query Input Types
13
+ // =============================================================================
14
+
15
+ /** Query input - can be a query, null/undefined, or an accessor function */
16
+ export type QueryInput<T> =
17
+ | QueryResult<T>
18
+ | null
19
+ | undefined
20
+ | (() => QueryResult<T> | null | undefined);
21
+
22
+ /** Helper to resolve query input (handles accessor functions) */
23
+ function resolveQuery<T>(input: QueryInput<T>): QueryResult<T> | null | undefined {
24
+ return typeof input === "function" ? input() : input;
25
+ }
26
+
11
27
  // =============================================================================
12
28
  // Types
13
29
  // =============================================================================
@@ -84,10 +100,18 @@ export type MutationFn<TInput, TOutput> = (input: TInput) => Promise<MutationRes
84
100
  * </Show>
85
101
  * );
86
102
  * }
103
+ *
104
+ * // Conditional query (null when condition not met)
105
+ * function SessionInfo(props: { sessionId: string | null }) {
106
+ * const session = createQuery(() =>
107
+ * props.sessionId ? client.session.get({ id: props.sessionId }) : null
108
+ * );
109
+ * return <span>{session.data()?.totalTokens}</span>;
110
+ * }
87
111
  * ```
88
112
  */
89
113
  export function createQuery<T>(
90
- queryFn: () => QueryResult<T>,
114
+ queryInput: QueryInput<T>,
91
115
  options?: CreateQueryOptions,
92
116
  ): CreateQueryResult<T> {
93
117
  const [data, setData] = createSignal<T | null>(null);
@@ -97,12 +121,18 @@ export function createQuery<T>(
97
121
  let unsubscribe: (() => void) | null = null;
98
122
 
99
123
  const executeQuery = () => {
100
- if (options?.skip) {
124
+ const queryResult = resolveQuery(queryInput);
125
+
126
+ // Handle null/undefined query or skip
127
+ if (options?.skip || queryResult == null) {
128
+ setData(null);
101
129
  setLoading(false);
130
+ setError(null);
102
131
  return;
103
132
  }
104
133
 
105
- const queryResult = queryFn();
134
+ setLoading(true);
135
+ setError(null);
106
136
 
107
137
  // Subscribe to updates
108
138
  unsubscribe = queryResult.subscribe((value) => {
@@ -274,19 +304,31 @@ export function createMutation<TInput, TOutput>(
274
304
  * </div>
275
305
  * );
276
306
  * }
307
+ *
308
+ * // Conditional query (null when condition not met)
309
+ * const lazySession = createLazyQuery(() =>
310
+ * sessionId() ? client.session.get({ id: sessionId() }) : null
311
+ * );
277
312
  * ```
278
313
  */
279
- export function createLazyQuery<T>(queryFn: () => QueryResult<T>): CreateLazyQueryResult<T> {
314
+ export function createLazyQuery<T>(queryInput: QueryInput<T>): CreateLazyQueryResult<T> {
280
315
  const [data, setData] = createSignal<T | null>(null);
281
316
  const [loading, setLoading] = createSignal(false);
282
317
  const [error, setError] = createSignal<Error | null>(null);
283
318
 
284
319
  const execute = async (): Promise<T> => {
320
+ const queryResult = resolveQuery(queryInput);
321
+
322
+ if (queryResult == null) {
323
+ setData(null);
324
+ setLoading(false);
325
+ return null as T;
326
+ }
327
+
285
328
  setLoading(true);
286
329
  setError(null);
287
330
 
288
331
  try {
289
- const queryResult = queryFn();
290
332
  const result = await queryResult;
291
333
  setData(() => result);
292
334
  setLoading(false);