@sylphx/lens-solid 1.2.5 → 1.2.16

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/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @sylphx/lens-solid
2
+
3
+ Solid.js primitives for the Lens API framework.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @sylphx/lens-solid
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { createQuery, createMutation } from "@sylphx/lens-solid";
15
+ import { client } from "./client";
16
+
17
+ function UserProfile() {
18
+ const user = createQuery(() => client.user.get({ id: "1" }));
19
+ const createUser = createMutation(client.user.create);
20
+
21
+ return (
22
+ <Show when={!user.loading} fallback={<div>Loading...</div>}>
23
+ <div>{user.data?.name}</div>
24
+ </Show>
25
+ );
26
+ }
27
+ ```
28
+
29
+ ## License
30
+
31
+ MIT
32
+
33
+ ---
34
+
35
+ Built with [@sylphx/lens-client](https://github.com/SylphxAI/Lens).
36
+
37
+ ✨ Powered by Sylphx
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,KAAK,eAAe,EAA6B,MAAM,UAAU,CAAC;AAa3E,MAAM,WAAW,iBAAiB;IACjC,2BAA2B;IAE3B,MAAM,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,iBAAiB,CAI3D,CAAC;AAMF;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,aAAa,CAAC,OAAO,GAAG,GAAG,KAAK,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,OAAO,CAY7E"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAiB,KAAK,eAAe,EAAc,MAAM,UAAU,CAAC;AAY3E,MAAM,WAAW,iBAAiB;IACjC,2BAA2B;IAC3B,MAAM,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,iBAAiB,CAI3D,CAAC;AAMF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAG,GAAG,KAAK,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,OAAO,CAW7E"}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,6 @@
4
4
  * SolidJS bindings for Lens API framework.
5
5
  * Reactive primitives that integrate with SolidJS fine-grained reactivity.
6
6
  */
7
- export { LensProvider, useLensClient, type LensProviderProps } from "./context";
8
- export { createQuery, createLazyQuery, createMutation, type QueryInput, type CreateQueryResult, type CreateMutationResult, type CreateLazyQueryResult, type CreateQueryOptions, type MutationFn, } from "./primitives";
7
+ export { LensProvider, type LensProviderProps, useLensClient } from "./context";
8
+ export { type CreateLazyQueryResult, type CreateMutationResult, type CreateQueryOptions, type CreateQueryResult, createLazyQuery, createMutation, createQuery, type MutationFn, type QueryInput, } 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,UAAU,EACf,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,KAAK,iBAAiB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAMhF,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,eAAe,EAEf,cAAc,EAEd,WAAW,EACX,KAAK,UAAU,EAEf,KAAK,UAAU,GACf,MAAM,cAAc,CAAC"}
package/package.json CHANGED
@@ -1,43 +1,44 @@
1
1
  {
2
- "name": "@sylphx/lens-solid",
3
- "version": "1.2.5",
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.9"
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.16",
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
+ "prepack": "bun run build"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "src"
23
+ ],
24
+ "keywords": [
25
+ "lens",
26
+ "solid",
27
+ "solidjs",
28
+ "reactive",
29
+ "signals"
30
+ ],
31
+ "author": "SylphxAI",
32
+ "license": "MIT",
33
+ "dependencies": {
34
+ "@sylphx/lens-client": "^1.6.0"
35
+ },
36
+ "peerDependencies": {
37
+ "solid-js": ">=1.8.0"
38
+ },
39
+ "devDependencies": {
40
+ "@solidjs/testing-library": "^0.8.10",
41
+ "solid-js": "^1.9.5",
42
+ "typescript": "^5.9.3"
43
+ }
43
44
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Tests for SolidJS Context
3
+ *
4
+ * Basic tests to verify exports and types.
5
+ * Tests LensProvider and useLensClient exports via the index.
6
+ *
7
+ * Note: Context tests are limited because context.tsx uses JSX
8
+ * and requires a SolidJS render context. Full integration tests
9
+ * would require @solidjs/testing-library.
10
+ */
11
+
12
+ import { describe, expect, test } from "bun:test";
13
+ // Import from index to test public API
14
+ // The context.tsx file uses JSX which requires special handling
15
+ import type { LensProviderProps } from "./index";
16
+
17
+ // =============================================================================
18
+ // Tests: Types (compile-time verification)
19
+ // =============================================================================
20
+
21
+ describe("@sylphx/lens-solid context types", () => {
22
+ test("LensProviderProps has client property", () => {
23
+ // Type assertion test - if this compiles, types are correct
24
+ type HasClient = LensProviderProps["client"];
25
+
26
+ // Runtime check that the type exists
27
+ const _checkClient: HasClient = null as unknown as HasClient;
28
+
29
+ expect(true).toBe(true);
30
+ });
31
+ });
package/src/context.tsx CHANGED
@@ -5,13 +5,12 @@
5
5
  */
6
6
 
7
7
  import type { LensClient } from "@sylphx/lens-client";
8
- import { type ParentComponent, createContext, useContext } from "solid-js";
8
+ import { createContext, type ParentComponent, useContext } from "solid-js";
9
9
 
10
10
  // =============================================================================
11
11
  // Context
12
12
  // =============================================================================
13
13
 
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
14
  const LensClientContext = createContext<LensClient<any, any>>();
16
15
 
17
16
  // =============================================================================
@@ -20,7 +19,6 @@ const LensClientContext = createContext<LensClient<any, any>>();
20
19
 
21
20
  export interface LensProviderProps {
22
21
  /** Lens client instance */
23
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
22
  client: LensClient<any, any>;
25
23
  }
26
24
 
@@ -70,7 +68,6 @@ export const LensProvider: ParentComponent<LensProviderProps> = (props) => {
70
68
  * }
71
69
  * ```
72
70
  */
73
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
71
  export function useLensClient<TRouter = any>(): LensClient<any, any> & TRouter {
75
72
  const client = useContext(LensClientContext);
76
73
 
@@ -81,6 +78,5 @@ export function useLensClient<TRouter = any>(): LensClient<any, any> & TRouter {
81
78
  );
82
79
  }
83
80
 
84
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
81
  return client as LensClient<any, any> & TRouter;
86
82
  }
package/src/index.ts CHANGED
@@ -9,23 +9,23 @@
9
9
  // Context & Provider
10
10
  // =============================================================================
11
11
 
12
- export { LensProvider, useLensClient, type LensProviderProps } from "./context";
12
+ export { LensProvider, type LensProviderProps, useLensClient } from "./context";
13
13
 
14
14
  // =============================================================================
15
15
  // Reactive Primitives
16
16
  // =============================================================================
17
17
 
18
18
  export {
19
- // Query primitives
20
- createQuery,
19
+ type CreateLazyQueryResult,
20
+ type CreateMutationResult,
21
+ type CreateQueryOptions,
22
+ type CreateQueryResult,
21
23
  createLazyQuery,
22
24
  // Mutation primitive
23
25
  createMutation,
26
+ // Query primitives
27
+ createQuery,
28
+ type MutationFn,
24
29
  // Types
25
30
  type QueryInput,
26
- type CreateQueryResult,
27
- type CreateMutationResult,
28
- type CreateLazyQueryResult,
29
- type CreateQueryOptions,
30
- type MutationFn,
31
31
  } from "./primitives";
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Tests for SolidJS Primitives
3
+ *
4
+ * Basic tests to verify exports and types.
5
+ * Tests createQuery, createMutation, createLazyQuery exports.
6
+ */
7
+
8
+ import { describe, expect, test } from "bun:test";
9
+ import {
10
+ type CreateLazyQueryResult,
11
+ type CreateMutationResult,
12
+ type CreateQueryOptions,
13
+ type CreateQueryResult,
14
+ createLazyQuery,
15
+ createMutation,
16
+ createQuery,
17
+ type MutationFn,
18
+ type QueryInput,
19
+ } from "./primitives";
20
+
21
+ // =============================================================================
22
+ // Tests: Exports
23
+ // =============================================================================
24
+
25
+ describe("@sylphx/lens-solid primitives exports", () => {
26
+ test("createQuery is exported", () => {
27
+ expect(typeof createQuery).toBe("function");
28
+ });
29
+
30
+ test("createLazyQuery is exported", () => {
31
+ expect(typeof createLazyQuery).toBe("function");
32
+ });
33
+
34
+ test("createMutation is exported", () => {
35
+ expect(typeof createMutation).toBe("function");
36
+ });
37
+ });
38
+
39
+ // =============================================================================
40
+ // Tests: Types (compile-time verification)
41
+ // =============================================================================
42
+
43
+ describe("primitives types", () => {
44
+ test("QueryInput type accepts QueryResult, null, undefined, or accessor", () => {
45
+ // This is a compile-time test - if it compiles, types are correct
46
+ const _testNull: QueryInput<string> = null;
47
+ const _testUndefined: QueryInput<string> = undefined;
48
+ const _testAccessor: QueryInput<string> = () => null;
49
+
50
+ expect(true).toBe(true);
51
+ });
52
+
53
+ test("CreateQueryResult has correct shape", () => {
54
+ // Type assertion test - SolidJS uses Accessor functions
55
+ type ExpectedShape = {
56
+ data: () => { id: string } | null;
57
+ loading: () => boolean;
58
+ error: () => Error | null;
59
+ refetch: () => void;
60
+ };
61
+
62
+ // If this compiles, CreateQueryResult has the correct shape
63
+ const _typeCheck: CreateQueryResult<{ id: string }> extends ExpectedShape ? true : false = true;
64
+ expect(_typeCheck).toBe(true);
65
+ });
66
+
67
+ test("CreateLazyQueryResult has correct shape", () => {
68
+ type ExpectedShape = {
69
+ data: () => { id: string } | null;
70
+ loading: () => boolean;
71
+ error: () => Error | null;
72
+ execute: () => Promise<{ id: string }>;
73
+ reset: () => void;
74
+ };
75
+
76
+ const _typeCheck: CreateLazyQueryResult<{ id: string }> extends ExpectedShape ? true : false = true;
77
+ expect(_typeCheck).toBe(true);
78
+ });
79
+
80
+ test("CreateMutationResult has correct shape", () => {
81
+ type ExpectedShape = {
82
+ data: () => { id: string } | null;
83
+ loading: () => boolean;
84
+ error: () => Error | null;
85
+ mutate: (input: { name: string }) => Promise<{ data: { id: string } }>;
86
+ reset: () => void;
87
+ };
88
+
89
+ const _typeCheck: CreateMutationResult<{ name: string }, { id: string }> extends ExpectedShape ? true : false =
90
+ true;
91
+ expect(_typeCheck).toBe(true);
92
+ });
93
+
94
+ test("CreateQueryOptions has skip property", () => {
95
+ const options: CreateQueryOptions = { skip: true };
96
+ expect(options.skip).toBe(true);
97
+ });
98
+
99
+ test("MutationFn type is correct", () => {
100
+ const fn: MutationFn<{ name: string }, { id: string }> = async (input) => ({
101
+ data: { id: input.name },
102
+ });
103
+
104
+ expect(typeof fn).toBe("function");
105
+ });
106
+ });
107
+
108
+ // =============================================================================
109
+ // Tests: Basic Functionality
110
+ // =============================================================================
111
+
112
+ describe("primitive functions", () => {
113
+ test("createMutation returns object with correct methods", () => {
114
+ const mockMutation = async (input: { name: string }) => ({
115
+ data: { id: "123", name: input.name },
116
+ });
117
+
118
+ const mutation = createMutation(mockMutation);
119
+
120
+ // Verify structure
121
+ expect(typeof mutation.data).toBe("function");
122
+ expect(typeof mutation.loading).toBe("function");
123
+ expect(typeof mutation.error).toBe("function");
124
+ expect(typeof mutation.mutate).toBe("function");
125
+ expect(typeof mutation.reset).toBe("function");
126
+
127
+ // Check initial state
128
+ expect(mutation.data()).toBe(null);
129
+ expect(mutation.loading()).toBe(false);
130
+ expect(mutation.error()).toBe(null);
131
+ });
132
+
133
+ test("createLazyQuery returns object with correct methods for null input", () => {
134
+ const query = createLazyQuery(null);
135
+
136
+ // Verify structure
137
+ expect(typeof query.data).toBe("function");
138
+ expect(typeof query.loading).toBe("function");
139
+ expect(typeof query.error).toBe("function");
140
+ expect(typeof query.execute).toBe("function");
141
+ expect(typeof query.reset).toBe("function");
142
+
143
+ // Check initial state
144
+ expect(query.data()).toBe(null);
145
+ expect(query.loading()).toBe(false);
146
+ expect(query.error()).toBe(null);
147
+ });
148
+
149
+ test("createMutation reset clears state", () => {
150
+ const mockMutation = async (input: { name: string }) => ({
151
+ data: { id: "123", name: input.name },
152
+ });
153
+
154
+ const mutation = createMutation(mockMutation);
155
+
156
+ // Reset should maintain initial cleared state
157
+ mutation.reset();
158
+
159
+ expect(mutation.loading()).toBe(false);
160
+ expect(mutation.error()).toBe(null);
161
+ expect(mutation.data()).toBe(null);
162
+ });
163
+
164
+ test("createLazyQuery reset clears state", () => {
165
+ const query = createLazyQuery(null);
166
+
167
+ // Reset should maintain initial cleared state
168
+ query.reset();
169
+
170
+ expect(query.loading()).toBe(false);
171
+ expect(query.error()).toBe(null);
172
+ expect(query.data()).toBe(null);
173
+ });
174
+
175
+ test("createLazyQuery execute returns null for null input", async () => {
176
+ const query = createLazyQuery(null);
177
+
178
+ const result = await query.execute();
179
+
180
+ expect(result).toBe(null);
181
+ expect(query.data()).toBe(null);
182
+ expect(query.loading()).toBe(false);
183
+ });
184
+ });
@@ -61,7 +61,7 @@ function createMockQueryResult<T>(initialValue: T | null = null): QueryResult<T>
61
61
  // Test helpers
62
62
  _setValue(value: T) {
63
63
  currentValue = value;
64
- subscribers.forEach((cb) => cb(value));
64
+ for (const cb of subscribers) cb(value);
65
65
  if (!resolved && resolvePromise) {
66
66
  resolved = true;
67
67
  resolvePromise(value);
@@ -143,9 +143,7 @@ describe("createMutation", () => {
143
143
  test("executes mutation and returns result", async () => {
144
144
  await new Promise<void>((resolve) => {
145
145
  createRoot(async (dispose) => {
146
- const mutationFn = async (input: { name: string }): Promise<
147
- MutationResult<{ id: string; name: string }>
148
- > => {
146
+ const mutationFn = async (input: { name: string }): Promise<MutationResult<{ id: string; name: string }>> => {
149
147
  return { data: { id: "new-id", name: input.name } };
150
148
  };
151
149
 
@@ -169,9 +167,7 @@ describe("createMutation", () => {
169
167
  test("handles mutation error", async () => {
170
168
  await new Promise<void>((resolve) => {
171
169
  createRoot(async (dispose) => {
172
- const mutationFn = async (_input: { name: string }): Promise<
173
- MutationResult<{ id: string }>
174
- > => {
170
+ const mutationFn = async (_input: { name: string }): Promise<MutationResult<{ id: string }>> => {
175
171
  throw new Error("Mutation failed");
176
172
  };
177
173
 
@@ -195,9 +191,7 @@ describe("createMutation", () => {
195
191
  test("reset clears mutation state", async () => {
196
192
  await new Promise<void>((resolve) => {
197
193
  createRoot(async (dispose) => {
198
- const mutationFn = async (input: { name: string }): Promise<
199
- MutationResult<{ id: string; name: string }>
200
- > => {
194
+ const mutationFn = async (input: { name: string }): Promise<MutationResult<{ id: string; name: string }>> => {
201
195
  return { data: { id: "new-id", name: input.name } };
202
196
  };
203
197