vike-solid-query 0.0.1-commit-dc7c4d4 → 0.0.1-commit-483edf8

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.
@@ -1,5 +1,5 @@
1
- import { QueryClientConfig } from '@tanstack/solid-query';
2
-
1
+ import type { QueryClientConfig } from "@tanstack/solid-query";
2
+ import "vike-solid/config";
3
3
  declare const _default: {
4
4
  name: string;
5
5
  require: {
@@ -22,7 +22,7 @@ declare const _default: {
22
22
  };
23
23
  };
24
24
  };
25
-
25
+ export default _default;
26
26
  declare global {
27
27
  namespace Vike {
28
28
  interface Config {
@@ -30,5 +30,3 @@ declare global {
30
30
  }
31
31
  }
32
32
  }
33
-
34
- export { _default as default };
@@ -1,24 +1,23 @@
1
- var _config = {
2
- name: "vike-solid-query",
3
- require: {
4
- "vike-solid": ">=0.7.3"
5
- },
6
- Wrapper: "import:vike-solid-query/__internal/integration/Wrapper:default",
7
- queryClientConfig: {
8
- defaultOptions: {
9
- queries: {
10
- staleTime: 5000
11
- }
12
- }
13
- },
14
- meta: {
1
+ import "vike-solid/config"; // Needed for declaration merging of Config
2
+ export default {
3
+ name: "vike-solid-query",
4
+ require: {
5
+ "vike-solid": ">=0.7.4",
6
+ },
7
+ Wrapper: "import:vike-solid-query/__internal/integration/Wrapper:default",
15
8
  queryClientConfig: {
16
- env: {
17
- server: true,
18
- client: true
19
- }
20
- }
21
- }
9
+ defaultOptions: {
10
+ queries: {
11
+ staleTime: 5000,
12
+ },
13
+ },
14
+ },
15
+ meta: {
16
+ queryClientConfig: {
17
+ env: {
18
+ server: true,
19
+ client: true,
20
+ },
21
+ },
22
+ },
22
23
  };
23
-
24
- export { _config as default };
@@ -1,7 +1,4 @@
1
- import { JSX } from 'solid-js';
2
-
3
- declare function Wrapper(props: {
4
- children: JSX.Element;
1
+ import type { JSX } from "solid-js";
2
+ export default function Wrapper(props: {
3
+ children?: JSX.Element;
5
4
  }): JSX.Element;
6
-
7
- export { Wrapper as default };
@@ -0,0 +1,7 @@
1
+ import { QueryClient, QueryClientProvider } from "@tanstack/solid-query";
2
+ import { usePageContext } from "vike-solid/usePageContext";
3
+ export default function Wrapper(props) {
4
+ const pageContext = usePageContext();
5
+ const queryClient = new QueryClient(pageContext.config.queryClientConfig);
6
+ return <QueryClientProvider client={queryClient}>{props.children}</QueryClientProvider>;
7
+ }
@@ -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,11 +1,28 @@
1
1
  {
2
2
  "name": "vike-solid-query",
3
- "version": "0.0.1-commit-dc7c4d4",
3
+ "version": "0.0.1-commit-483edf8",
4
4
  "type": "module",
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": "./dist/integration/Wrapper.jsx"
21
+ },
5
22
  "peerDependencies": {
6
23
  "@tanstack/solid-query": ">=5.0.0",
7
24
  "solid-js": "^1.8.7",
8
- "vike-solid": "^0.7.5"
25
+ "vike-solid": "0.7.4"
9
26
  },
10
27
  "devDependencies": {
11
28
  "@brillout/release-me": "^0.4.2",
@@ -18,14 +35,8 @@
18
35
  "solid-js": "^1.8.22",
19
36
  "typescript": "^5.6.2",
20
37
  "vike": "^0.4.196",
21
- "vite": "^5.4.7",
22
38
  "vike-solid": "0.7.5"
23
39
  },
24
- "exports": {
25
- ".": "./dist/src/index.js",
26
- "./config": "./dist/integration/+config.js",
27
- "./__internal/integration/Wrapper": "./dist/integration/Wrapper.js"
28
- },
29
40
  "typesVersions": {
30
41
  "*": {
31
42
  "config": [
@@ -1,16 +0,0 @@
1
- import { createComponent } from 'solid-js/web';
2
- import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';
3
- import { usePageContext } from 'vike-solid/usePageContext';
4
-
5
- function Wrapper(props) {
6
- const pageContext = usePageContext();
7
- const queryClient = new QueryClient(pageContext.config.queryClientConfig);
8
- return createComponent(QueryClientProvider, {
9
- client: queryClient,
10
- get children() {
11
- return props.children;
12
- }
13
- });
14
- }
15
-
16
- export { Wrapper as default };
@@ -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
- }