@tsproxy/js 0.0.1 → 0.0.3

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,62 @@
1
+ # @tsproxy/js
2
+
3
+ InstantSearch-compatible `searchClient` adapter for [tsproxy](https://github.com/akshitkrnagpal/tsproxy).
4
+
5
+ > **This project is under heavy development.**
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @tsproxy/js
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { createSearchClient } from "@tsproxy/js";
17
+
18
+ const searchClient = createSearchClient({
19
+ url: "http://localhost:3000",
20
+ locale: "en", // optional
21
+ cache: true, // optional (default: true)
22
+ });
23
+ ```
24
+
25
+ ### With react-instantsearch
26
+
27
+ ```tsx
28
+ import { InstantSearch } from "react-instantsearch";
29
+ import { createSearchClient } from "@tsproxy/js";
30
+
31
+ const searchClient = createSearchClient({ url: "http://localhost:3000" });
32
+
33
+ <InstantSearch searchClient={searchClient} indexName="products">
34
+ {/* widgets */}
35
+ </InstantSearch>
36
+ ```
37
+
38
+ ### Standalone
39
+
40
+ ```ts
41
+ const results = await searchClient.search([
42
+ { indexName: "products", params: { query: "keyboard", hitsPerPage: 10 } },
43
+ ]);
44
+ ```
45
+
46
+ ## API
47
+
48
+ ### `createSearchClient(options)`
49
+
50
+ | Option | Type | Default | Description |
51
+ |--------|------|---------|-------------|
52
+ | `url` | `string` | — | Proxy server URL (required) |
53
+ | `locale` | `string` | — | Locale for multilingual search |
54
+ | `cache` | `boolean` | `true` | Enable client-side result caching |
55
+
56
+ ## Documentation
57
+
58
+ [tsproxy.akshit.io](https://tsproxy.akshit.io)
59
+
60
+ ## License
61
+
62
+ MIT
package/dist/index.js CHANGED
@@ -33,7 +33,11 @@ function createSearchClient(options) {
33
33
  }
34
34
  const data = await response.json();
35
35
  if (enableCache) {
36
- resultCache.set(cacheKey, data);
36
+ const hasResults = data.results?.some((r) => r.nbHits > 0 || r.hits?.length > 0);
37
+ const hasErrors = data._errors?.length > 0;
38
+ if (hasResults && !hasErrors) {
39
+ resultCache.set(cacheKey, data);
40
+ }
37
41
  }
38
42
  return data;
39
43
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsproxy/js",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "InstantSearch-compatible searchClient adapter for tsproxy",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -12,7 +12,8 @@
12
12
  }
13
13
  },
14
14
  "files": [
15
- "dist"
15
+ "dist",
16
+ "README.md"
16
17
  ],
17
18
  "publishConfig": {
18
19
  "access": "public"
@@ -29,12 +30,12 @@
29
30
  "search",
30
31
  "proxy"
31
32
  ],
32
- "devDependencies": {
33
- "tsup": "^8.4.0",
34
- "typescript": "^5.5.3"
35
- },
36
33
  "scripts": {
37
34
  "build": "tsup src/index.ts --format esm --dts",
38
35
  "typecheck": "tsc --noEmit"
36
+ },
37
+ "devDependencies": {
38
+ "tsup": "^8.4.0",
39
+ "typescript": "^5.5.3"
39
40
  }
40
- }
41
+ }