vike-solid-query 0.0.1 → 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Joël Charles
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -20,6 +20,7 @@ Enables your Solid components to fetch data using [TanStack Query](https://tanst
20
20
 
21
21
  1. `npm install @tanstack/solid-query vike-solid-query`
22
22
  2. Extend `+config.js`:
23
+
23
24
  ```js
24
25
  // pages/+config.js
25
26
 
@@ -36,7 +37,7 @@ Enables your Solid components to fetch data using [TanStack Query](https://tanst
36
37
 
37
38
  ## Basic usage
38
39
 
39
- ```jsx
40
+ ```tsx
40
41
  import { createQuery } from "@tanstack/solid-query";
41
42
  import { Suspense } from "solid-js";
42
43
 
@@ -58,29 +59,33 @@ const Movie = (props: { id }) => {
58
59
 
59
60
  ## `QueryBoundary`
60
61
 
61
- ```jsx
62
- // Define loading fallback
62
+ ```tsx
63
+ // Define the loading fallback
63
64
  <QueryBoundary query={query} loadingFallback={Loading}>
64
65
  {(data) => <div>{data.something}</div>}
65
66
  </QueryBoundary>
66
- // Define loading and error fallback
67
+ // Define the loading and error fallback
67
68
  <QueryBoundary query={query} loadingFallback={Loading} errorFallback={Error}>
68
69
  {(data) => <div>{data.something}</div>}
69
70
  </QueryBoundary>
70
- // Define loading, error and not found fallback
71
+ // Define the loading, error and not found fallback
71
72
  <QueryBoundary query={query} loadingFallback={Loading} errorFallback={Error} notFoundFallback={NotFound}>
72
73
  {(data) => <div>{data.something}</div>}
73
74
  </QueryBoundary>
74
75
  ```
75
76
 
76
- > [!NOTE] Types
77
- > `query: CreateQueryResult<T, Error>;`
78
- > `loadingFallback?: JSX.Element;`
79
- > `notFoundFallback?: JSX.Element;`
80
- > `errorFallback?: JSX.Element | ((err: any, reset: () => void) => JSX.Element);`
81
- > `children: (data: Exclude<T, null | false | undefined>) => JSX.Element;`
77
+ **Types :**
78
+ ```js
79
+ query: CreateQueryResult<T, Error>;
80
+ loadingFallback?: JSX.Element;
81
+ notFoundFallback?: JSX.Element;
82
+ errorFallback?: JSX.Element | ((err: any, reset: () => void) => JSX.Element);
83
+ children: (data: Exclude<T, null | false | undefined>) => JSX.Element;
84
+ ```
82
85
 
83
86
  ```tsx
87
+ // Movie.tsx
88
+
84
89
  import { createQuery } from "@tanstack/solid-query";
85
90
  import { QueryBoundary } from "vike-solid-query";
86
91
 
@@ -124,7 +129,7 @@ function Movie(props: { id: string }) {
124
129
 
125
130
  To set tags such as `<title>` and `<meta name="description">` based on fetched data, you can use [`<Config>`, `<Head>`, and `useConfig()`](https://vike.dev/useConfig).
126
131
 
127
- ```js
132
+ ```tsx
128
133
  import { createQuery } from "@tanstack/solid-query";
129
134
  import { Config } from 'vike-solid/Config'
130
135
  import { Head } from 'vike-solid/Head'
@@ -1,7 +1,7 @@
1
1
  var _config = {
2
2
  name: "vike-solid-query",
3
3
  require: {
4
- "vike-solid": ">=0.7.3"
4
+ "vike-solid": ">=0.7.4"
5
5
  },
6
6
  Wrapper: "import:vike-solid-query/__internal/integration/Wrapper:default",
7
7
  queryClientConfig: {
@@ -1,7 +1,7 @@
1
1
  import { JSX } from 'solid-js';
2
2
 
3
3
  declare function Wrapper(props: {
4
- children: JSX.Element;
4
+ children?: JSX.Element;
5
5
  }): JSX.Element;
6
6
 
7
7
  export { Wrapper as default };
@@ -1 +1,29 @@
1
- export { QueryBoundary } from "./QueryBoundary";
1
+ import { CreateQueryResult } from '@tanstack/solid-query';
2
+ import { JSX } from 'solid-js';
3
+
4
+ interface QueryBoundaryProps<T = unknown> {
5
+ query: CreateQueryResult<T, Error>;
6
+ /**
7
+ * Triggered when the data is initially loading.
8
+ */
9
+ loadingFallback?: JSX.Element;
10
+ /**
11
+ * Triggered when fetching is complete, but the returned data was falsey.
12
+ */
13
+ notFoundFallback?: JSX.Element;
14
+ /**
15
+ * Triggered when the query results in an error.
16
+ */
17
+ errorFallback?: JSX.Element | ((err: any, reset: () => void) => JSX.Element);
18
+ /**
19
+ * Triggered when fetching is complete, and the returned data is not falsey.
20
+ */
21
+ children: (data: Exclude<T, null | false | undefined>) => JSX.Element;
22
+ }
23
+ /**
24
+ * Convenience wrapper that handles suspense and errors for queries. Makes the results of query.data available to
25
+ * children (as a render prop) in a type-safe way.
26
+ */
27
+ declare function QueryBoundary<T>(props: QueryBoundaryProps<T>): JSX.Element;
28
+
29
+ export { QueryBoundary, type QueryBoundaryProps };
package/dist/src/index.js CHANGED
@@ -1 +1,66 @@
1
- export { QueryBoundary } from "./QueryBoundary";
1
+ import { delegateEvents, createComponent, getNextElement, insert, runHydrationEvents, memo, template } from 'solid-js/web';
2
+ import { ErrorBoundary, Suspense, Switch, Match } from 'solid-js';
3
+
4
+ var _tmpl$ = /*#__PURE__*/template(`<div><div class=query-boundary-error></div><button>Retry`),
5
+ _tmpl$2 = /*#__PURE__*/template(`<div>Not Found,`),
6
+ _tmpl$3 = /*#__PURE__*/template(`<button>Refetch`);
7
+ /**
8
+ * Convenience wrapper that handles suspense and errors for queries. Makes the results of query.data available to
9
+ * children (as a render prop) in a type-safe way.
10
+ */
11
+ function QueryBoundary(props) {
12
+ return createComponent(ErrorBoundary, {
13
+ get fallback() {
14
+ return props.errorFallback ? props.errorFallback : (err, reset) => (() => {
15
+ var _el$ = getNextElement(_tmpl$),
16
+ _el$2 = _el$.firstChild,
17
+ _el$3 = _el$2.nextSibling;
18
+ insert(_el$2, () => err.toString());
19
+ _el$3.$$click = async () => {
20
+ reset();
21
+ await props.query.refetch();
22
+ };
23
+ runHydrationEvents();
24
+ return _el$;
25
+ })();
26
+ },
27
+ get children() {
28
+ return createComponent(Suspense, {
29
+ get fallback() {
30
+ return props.loadingFallback;
31
+ },
32
+ get children() {
33
+ return createComponent(Switch, {
34
+ get children() {
35
+ return [createComponent(Match, {
36
+ get when() {
37
+ return !props.query.isFetching && !props.query.data;
38
+ },
39
+ get children() {
40
+ return memo(() => !!props.notFoundFallback)() ? props.notFoundFallback : [getNextElement(_tmpl$2), (() => {
41
+ var _el$5 = getNextElement(_tmpl$3);
42
+ _el$5.$$click = async () => {
43
+ await props.query.refetch();
44
+ };
45
+ runHydrationEvents();
46
+ return _el$5;
47
+ })()];
48
+ }
49
+ }), createComponent(Match, {
50
+ get when() {
51
+ return props.query.data;
52
+ },
53
+ get children() {
54
+ return props.children(props.query.data);
55
+ }
56
+ })];
57
+ }
58
+ });
59
+ }
60
+ });
61
+ }
62
+ });
63
+ }
64
+ delegateEvents(["click"]);
65
+
66
+ export { QueryBoundary };
@@ -0,0 +1,47 @@
1
+ import { createComponent, ssr, ssrHydrationKey, escape } from 'solid-js/web';
2
+ import { ErrorBoundary, Suspense, Switch, Match } from 'solid-js';
3
+
4
+ var _tmpl$ = ["<div", "><div class=\"query-boundary-error\">", "</div><button>Retry</button></div>"],
5
+ _tmpl$2 = ["<div", ">Not Found,</div>"],
6
+ _tmpl$3 = ["<button", ">Refetch</button>"];
7
+ /**
8
+ * Convenience wrapper that handles suspense and errors for queries. Makes the results of query.data available to
9
+ * children (as a render prop) in a type-safe way.
10
+ */
11
+ function QueryBoundary(props) {
12
+ return createComponent(ErrorBoundary, {
13
+ get fallback() {
14
+ return props.errorFallback ? props.errorFallback : (err, reset) => ssr(_tmpl$, ssrHydrationKey(), escape(err.toString()));
15
+ },
16
+ get children() {
17
+ return createComponent(Suspense, {
18
+ get fallback() {
19
+ return props.loadingFallback;
20
+ },
21
+ get children() {
22
+ return createComponent(Switch, {
23
+ get children() {
24
+ return [createComponent(Match, {
25
+ get when() {
26
+ return !props.query.isFetching && !props.query.data;
27
+ },
28
+ get children() {
29
+ return props.notFoundFallback ? props.notFoundFallback : [ssr(_tmpl$2, ssrHydrationKey()), ssr(_tmpl$3, ssrHydrationKey())];
30
+ }
31
+ }), createComponent(Match, {
32
+ get when() {
33
+ return props.query.data;
34
+ },
35
+ get children() {
36
+ return props.children(props.query.data);
37
+ }
38
+ })];
39
+ }
40
+ });
41
+ }
42
+ });
43
+ }
44
+ });
45
+ }
46
+
47
+ export { QueryBoundary };
package/package.json CHANGED
@@ -1,39 +1,46 @@
1
1
  {
2
2
  "name": "vike-solid-query",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
- "scripts": {
6
- "dev": "rollup -c rollup.config.js --watch",
7
- "dev:typecheck": "tsc --noEmit --watch",
8
- "build": "rollup -c rollup.config.js && tsc",
9
- "release": "LANG=en_US release-me patch",
10
- "release:minor": "LANG=en_US release-me minor",
11
- "release:commit": "LANG=en_US release-me commit"
5
+ "main": "./dist/src/server.js",
6
+ "typings": "dist/src/index.d.ts",
7
+ "module": "./dist/src/server.js",
8
+ "types": "./dist/src/index.d.ts",
9
+ "browser": {
10
+ "./dist/src/server.js": "./dist/src/index.js"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "browser": "./dist/src/index.js",
15
+ "node": "./dist/src/server.js",
16
+ "default": "./dist/src/index.js",
17
+ "types": "./dist/src/index.d.ts"
18
+ },
19
+ "./config": "./dist/integration/+config.js",
20
+ "./__internal/integration/Wrapper": {
21
+ "solid": "./dist/integration/Wrapper.js",
22
+ "import": {
23
+ "types": "./dist/integration/Wrapper.d.ts",
24
+ "default": "./dist/integration/Wrapper.js"
25
+ }
26
+ }
12
27
  },
13
28
  "peerDependencies": {
14
29
  "@tanstack/solid-query": ">=5.0.0",
15
30
  "solid-js": "^1.8.7",
16
- "vike-solid": ">=0.7.3"
31
+ "vike-solid": "^0.7.6"
17
32
  },
18
33
  "devDependencies": {
19
- "@brillout/release-me": "^0.4.0",
20
- "@rollup/plugin-babel": "6.0.4",
21
- "@rollup/plugin-node-resolve": "15.2.3",
22
- "@tanstack/solid-query": "^5.52.2",
23
- "rimraf": "^6.0.1",
24
- "rollup": "^4.21.2",
25
- "rollup-plugin-dts": "6.1.1",
34
+ "@brillout/release-me": "^0.4.2",
35
+ "@rollup/plugin-babel": "^6.0.4",
36
+ "@rollup/plugin-node-resolve": "^15.2.4",
37
+ "@tanstack/solid-query": "^5.56.2",
38
+ "rollup": "^4.22.4",
39
+ "rollup-plugin-dts": "^6.1.1",
26
40
  "solid-js": "^1.8.22",
27
- "tsup": "^8.2.4",
28
- "typescript": "^5.5.4",
29
- "vike": "^0.4.193",
30
- "vike-solid": "^0.7.3",
31
- "vite": "5.4.2"
32
- },
33
- "exports": {
34
- ".": "./dist/src/index.js",
35
- "./config": "./dist/integration/+config.js",
36
- "./__internal/integration/Wrapper": "./dist/integration/Wrapper.js"
41
+ "typescript": "^5.6.2",
42
+ "vike": "^0.4.197",
43
+ "vike-solid": "0.7.6"
37
44
  },
38
45
  "typesVersions": {
39
46
  "*": {
@@ -49,5 +56,13 @@
49
56
  "dist/"
50
57
  ],
51
58
  "repository": "github:vikejs/vike-solid",
52
- "license": "MIT"
53
- }
59
+ "license": "MIT",
60
+ "scripts": {
61
+ "dev": "rollup -c rollup.config.js --watch",
62
+ "dev:typecheck": "tsc --noEmit --watch",
63
+ "build": "tsc --noEmit && rollup -c rollup.config.js",
64
+ "release": "LANG=en_US release-me patch",
65
+ "release:minor": "LANG=en_US release-me minor",
66
+ "release:commit": "LANG=en_US release-me commit"
67
+ }
68
+ }
@@ -1,26 +0,0 @@
1
- import type { CreateQueryResult } from "@tanstack/solid-query";
2
- import type { JSX } from "solid-js";
3
- export interface QueryBoundaryProps<T = unknown> {
4
- query: CreateQueryResult<T, Error>;
5
- /**
6
- * Triggered when the data is initially loading.
7
- */
8
- loadingFallback?: JSX.Element;
9
- /**
10
- * Triggered when fetching is complete, but the returned data was falsey.
11
- */
12
- notFoundFallback?: JSX.Element;
13
- /**
14
- * Triggered when the query results in an error.
15
- */
16
- errorFallback?: JSX.Element | ((err: any, reset: () => void) => JSX.Element);
17
- /**
18
- * Triggered when fetching is complete, and the returned data is not falsey.
19
- */
20
- children: (data: Exclude<T, null | false | undefined>) => JSX.Element;
21
- }
22
- /**
23
- * Convenience wrapper that handles suspense and errors for queries. Makes the results of query.data available to
24
- * children (as a render prop) in a type-safe way.
25
- */
26
- export declare function QueryBoundary<T>(props: QueryBoundaryProps<T>): JSX.Element;
@@ -1,37 +0,0 @@
1
- import { ErrorBoundary, Match, Suspense, Switch } from "solid-js";
2
- /**
3
- * Convenience wrapper that handles suspense and errors for queries. Makes the results of query.data available to
4
- * children (as a render prop) in a type-safe way.
5
- */
6
- export function QueryBoundary(props) {
7
- return (<ErrorBoundary fallback={props.errorFallback
8
- ? props.errorFallback
9
- : (err, reset) => (<div>
10
- <div class="query-boundary-error">{err.toString()}</div>
11
- <button onClick={async () => {
12
- reset();
13
- await props.query.refetch();
14
- }}>
15
- Retry
16
- </button>
17
- </div>)}>
18
- <Suspense fallback={props.loadingFallback}>
19
- <Switch>
20
- <Match when={!props.query.isFetching && !props.query.data}>
21
- {props.notFoundFallback ? (props.notFoundFallback) : (<>
22
- <div>Not Found,</div>
23
- <button onClick={async () => {
24
- await props.query.refetch();
25
- }}>
26
- Refetch
27
- </button>
28
- </>)}
29
- </Match>
30
-
31
- <Match when={props.query.data}>
32
- {props.children(props.query.data)}
33
- </Match>
34
- </Switch>
35
- </Suspense>
36
- </ErrorBoundary>);
37
- }