tanstack-query-callbacks 0.1.0 → 0.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/README.md CHANGED
@@ -3,11 +3,17 @@
3
3
  [![npm version][npm-version-src]][npm-version-href]
4
4
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
5
  [![bundle][bundle-src]][bundle-href]
6
+ [![coverage][coverage-src]][coverage-href]
6
7
 
7
8
  Use callbacks of query in the usual way, as before.
8
9
 
9
10
  The tanstack/query has removed `onSuccess`, `onError` and `onSettled` from useQuery in v5. You can find more information in the [RFC](https://github.com/TanStack/query/discussions/5279).
10
11
 
12
+ # Features
13
+
14
+ - Support Tanstack/Query v4, v5
15
+ - Support Vue, React
16
+
11
17
  ## Instanll
12
18
 
13
19
  ```shell
@@ -21,7 +27,7 @@ pnpm add tanstack-query-callbacks
21
27
  ## Usage (Vue)
22
28
 
23
29
  ```vue
24
- <script setup lang=ts>
30
+ <script setup lang="ts">
25
31
  import { useQuery } from '@tanstack/vue-query'
26
32
  import { useQueryCallbacks } from 'tanstack-query-callbacks/vue'
27
33
  const queryKey = ['foo']
@@ -72,3 +78,5 @@ useQueryCallbacks({
72
78
  [npm-downloads-href]: https://npmjs.com/package/tanstack-query-callbacks
73
79
  [bundle-src]: https://img.shields.io/bundlephobia/minzip/tanstack-query-callbacks?style=flat&colorA=18181B&colorB=F0DB4F
74
80
  [bundle-href]: https://bundlephobia.com/result?p=tanstack-query-callbacks
81
+ [coverage-src]: https://img.shields.io/codecov/c/gh/aa900031/tanstack-query-callbacks?token=AG56Z6EP8U&logo=codecov&color=F0DB4F
82
+ [coverage-href]: https://codecov.io/gh/aa900031/tanstack-query-callbacks
@@ -2,13 +2,16 @@
2
2
 
3
3
  const react = require('react');
4
4
  const reactQuery = require('@tanstack/react-query');
5
- const index = require('../index.cjs');
5
+ const core_index = require('../core/index.cjs');
6
6
  require('@tanstack/query-core');
7
7
 
8
8
  function useQueryCallbacks(props) {
9
- const queryClient = reactQuery.useQueryClient(props.queryClient);
9
+ const queryClient = reactQuery.useQueryClient(
10
+ props.context ? { context: props.context } : props.queryClient
11
+ // for v5
12
+ );
10
13
  react.useEffect(() => {
11
- return index.subscribeQueryCallbacks({
14
+ return core_index.subscribeQueryCallbacks({
12
15
  queryClient,
13
16
  queryKey: props.queryKey,
14
17
  onSuccess: props.onSuccess,
@@ -1,5 +1,6 @@
1
+ import { Context } from 'react';
1
2
  import { QueryKey, QueryClient } from '@tanstack/react-query';
2
- import { QueryCallbacks } from '../index.cjs';
3
+ import { QueryCallbacks } from '../core/index.cjs';
3
4
  import '@tanstack/query-core';
4
5
 
5
6
  interface UseQueryCallbacksProps<TQueryFnData, TError> extends QueryCallbacks<TQueryFnData, TError> {
@@ -8,6 +9,10 @@ interface UseQueryCallbacksProps<TQueryFnData, TError> extends QueryCallbacks<TQ
8
9
  * QueryClient instance
9
10
  */
10
11
  queryClient?: QueryClient;
12
+ /**
13
+ * QueryClient context for v4
14
+ */
15
+ context?: Context<QueryClient | undefined>;
11
16
  }
12
17
  declare function useQueryCallbacks<TQueryFnData = unknown, TError = unknown>(props: UseQueryCallbacksProps<TQueryFnData, TError>): void;
13
18
 
@@ -1,5 +1,6 @@
1
+ import { Context } from 'react';
1
2
  import { QueryKey, QueryClient } from '@tanstack/react-query';
2
- import { QueryCallbacks } from '../index.mjs';
3
+ import { QueryCallbacks } from '../core/index.mjs';
3
4
  import '@tanstack/query-core';
4
5
 
5
6
  interface UseQueryCallbacksProps<TQueryFnData, TError> extends QueryCallbacks<TQueryFnData, TError> {
@@ -8,6 +9,10 @@ interface UseQueryCallbacksProps<TQueryFnData, TError> extends QueryCallbacks<TQ
8
9
  * QueryClient instance
9
10
  */
10
11
  queryClient?: QueryClient;
12
+ /**
13
+ * QueryClient context for v4
14
+ */
15
+ context?: Context<QueryClient | undefined>;
11
16
  }
12
17
  declare function useQueryCallbacks<TQueryFnData = unknown, TError = unknown>(props: UseQueryCallbacksProps<TQueryFnData, TError>): void;
13
18
 
@@ -1,5 +1,6 @@
1
+ import { Context } from 'react';
1
2
  import { QueryKey, QueryClient } from '@tanstack/react-query';
2
- import { QueryCallbacks } from '../index.js';
3
+ import { QueryCallbacks } from '../core/index.js';
3
4
  import '@tanstack/query-core';
4
5
 
5
6
  interface UseQueryCallbacksProps<TQueryFnData, TError> extends QueryCallbacks<TQueryFnData, TError> {
@@ -8,6 +9,10 @@ interface UseQueryCallbacksProps<TQueryFnData, TError> extends QueryCallbacks<TQ
8
9
  * QueryClient instance
9
10
  */
10
11
  queryClient?: QueryClient;
12
+ /**
13
+ * QueryClient context for v4
14
+ */
15
+ context?: Context<QueryClient | undefined>;
11
16
  }
12
17
  declare function useQueryCallbacks<TQueryFnData = unknown, TError = unknown>(props: UseQueryCallbacksProps<TQueryFnData, TError>): void;
13
18
 
@@ -1,10 +1,13 @@
1
1
  import { useEffect } from 'react';
2
2
  import { useQueryClient } from '@tanstack/react-query';
3
- import { subscribeQueryCallbacks } from '../index.mjs';
3
+ import { subscribeQueryCallbacks } from '../core/index.mjs';
4
4
  import '@tanstack/query-core';
5
5
 
6
6
  function useQueryCallbacks(props) {
7
- const queryClient = useQueryClient(props.queryClient);
7
+ const queryClient = useQueryClient(
8
+ props.context ? { context: props.context } : props.queryClient
9
+ // for v5
10
+ );
8
11
  useEffect(() => {
9
12
  return subscribeQueryCallbacks({
10
13
  queryClient,
@@ -2,7 +2,7 @@
2
2
 
3
3
  const vueDemi = require('vue-demi');
4
4
  const vueQuery = require('@tanstack/vue-query');
5
- const index = require('../index.cjs');
5
+ const core_index = require('../core/index.cjs');
6
6
  require('@tanstack/query-core');
7
7
 
8
8
  function useQueryCallbacks(props) {
@@ -10,7 +10,7 @@ function useQueryCallbacks(props) {
10
10
  vueDemi.watch(
11
11
  () => vueDemi.unref(props.queryKey),
12
12
  (queryKey, _oldVal, onCleanup) => {
13
- const unsubscribe = index.subscribeQueryCallbacks({
13
+ const unsubscribe = core_index.subscribeQueryCallbacks({
14
14
  queryClient,
15
15
  queryKey,
16
16
  onSuccess: props.onSuccess,
@@ -1,6 +1,6 @@
1
1
  import { MaybeRef } from 'vue-demi';
2
2
  import { QueryKey, QueryClient } from '@tanstack/vue-query';
3
- import { QueryCallbacks } from '../index.cjs';
3
+ import { QueryCallbacks } from '../core/index.cjs';
4
4
  import '@tanstack/query-core';
5
5
 
6
6
  interface UseQueryCallbacksProps<TQueryFnData, TError> extends QueryCallbacks<TQueryFnData, TError> {
@@ -1,6 +1,6 @@
1
1
  import { MaybeRef } from 'vue-demi';
2
2
  import { QueryKey, QueryClient } from '@tanstack/vue-query';
3
- import { QueryCallbacks } from '../index.mjs';
3
+ import { QueryCallbacks } from '../core/index.mjs';
4
4
  import '@tanstack/query-core';
5
5
 
6
6
  interface UseQueryCallbacksProps<TQueryFnData, TError> extends QueryCallbacks<TQueryFnData, TError> {
@@ -1,6 +1,6 @@
1
1
  import { MaybeRef } from 'vue-demi';
2
2
  import { QueryKey, QueryClient } from '@tanstack/vue-query';
3
- import { QueryCallbacks } from '../index.js';
3
+ import { QueryCallbacks } from '../core/index.js';
4
4
  import '@tanstack/query-core';
5
5
 
6
6
  interface UseQueryCallbacksProps<TQueryFnData, TError> extends QueryCallbacks<TQueryFnData, TError> {
@@ -1,6 +1,6 @@
1
1
  import { inject, watch, unref } from 'vue-demi';
2
2
  import { useQueryClient } from '@tanstack/vue-query';
3
- import { subscribeQueryCallbacks } from '../index.mjs';
3
+ import { subscribeQueryCallbacks } from '../core/index.mjs';
4
4
  import '@tanstack/query-core';
5
5
 
6
6
  function useQueryCallbacks(props) {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "tanstack-query-callbacks",
3
3
  "type": "module",
4
- "version": "0.1.0",
5
- "packageManager": "pnpm@8.10.0",
4
+ "version": "0.2.0",
5
+ "packageManager": "pnpm@8.15.1",
6
6
  "author": "zhong666 <hi@zhong666.me>",
7
7
  "license": "MIT",
8
8
  "keywords": [
@@ -15,12 +15,12 @@
15
15
  "exports": {
16
16
  ".": {
17
17
  "import": {
18
- "types": "./dist/index.d.mts",
19
- "default": "./dist/index.mjs"
18
+ "types": "./dist/core/index.d.mts",
19
+ "default": "./dist/core/index.mjs"
20
20
  },
21
21
  "require": {
22
- "types": "./dist/index.d.cts",
23
- "default": "./dist/index.cjs"
22
+ "types": "./dist/core/index.d.cts",
23
+ "default": "./dist/core/index.cjs"
24
24
  }
25
25
  },
26
26
  "./vue": {
@@ -32,72 +32,84 @@
32
32
  "require": "./dist/react/index.cjs"
33
33
  }
34
34
  },
35
- "main": "dist/index.cjs",
36
- "module": "dist/index.mjs",
37
- "types": "dist/index.d.ts",
35
+ "main": "dist/core/index.cjs",
36
+ "module": "dist/core/index.mjs",
37
+ "types": "dist/core/index.d.ts",
38
38
  "files": [
39
39
  "dist",
40
- "vue.d.ts",
41
- "react.d.ts"
40
+ "react.d.ts",
41
+ "vue.d.ts"
42
42
  ],
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  },
46
46
  "peerDependencies": {
47
- "@tanstack/query-core": "^5.*",
48
- "@tanstack/react-query": "^5.*",
49
- "@tanstack/vue-query": "^5.*",
47
+ "@tanstack/query-core": "^4.* || ^5.*",
48
+ "@tanstack/react-query": "^4.* || ^5.*",
49
+ "@tanstack/vue-query": "^4.* || ^5.*",
50
50
  "@vue/composition-api": "^1.1.0",
51
51
  "react": "^18.0.0",
52
52
  "vue": "^2.6.12 || ^3.2.0"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
- "@tanstack/vue-query": {
55
+ "@tanstack/react-query": {
56
56
  "optional": true
57
57
  },
58
- "@tanstack/react-query": {
58
+ "@tanstack/vue-query": {
59
59
  "optional": true
60
60
  },
61
61
  "@vue/composition-api": {
62
62
  "optional": true
63
63
  },
64
- "vue": {
64
+ "react": {
65
65
  "optional": true
66
66
  },
67
- "react": {
67
+ "vue": {
68
68
  "optional": true
69
69
  }
70
70
  },
71
71
  "devDependencies": {
72
- "@aa900031/eslint-config": "^1.0.1",
72
+ "@aa900031/eslint-config": "^1.3.0",
73
73
  "@release-it/conventional-changelog": "^7.0.2",
74
- "@tanstack/query-core": "^5.14.2",
75
- "@tanstack/react-query": "^5.14.2",
76
- "@tanstack/vue-query": "^5.14.2",
77
- "@testing-library/react": "14.1.2",
74
+ "@tanstack/query-core": "^5.18.1",
75
+ "@tanstack/query-core-v4": "npm:@tanstack/query-core@^4.36.1",
76
+ "@tanstack/react-query": "^5.18.1",
77
+ "@tanstack/react-query-v4": "npm:@tanstack/react-query@^4.36.1",
78
+ "@tanstack/vue-query": "^5.18.1",
79
+ "@tanstack/vue-query-v4": "npm:@tanstack/vue-query@^4.37.1",
80
+ "@testing-library/react": "14.2.1",
78
81
  "@testing-library/vue": "^8.0.1",
79
82
  "@tsconfig/node18": "^18.2.2",
80
- "@types/node": "^18.18.7",
81
- "@types/react": "^18.2.45",
83
+ "@types/node": "^18.19.14",
84
+ "@types/react": "^18.2.51",
82
85
  "@types/react-dom": "^18.2.18",
83
- "@vitest/coverage-istanbul": "^1.1.0",
84
- "@vitest/ui": "^1.1.0",
85
- "conventional-changelog-unjs": "^0.1.0",
86
- "eslint": "^8.52.0",
86
+ "@vitest/coverage-istanbul": "^1.2.2",
87
+ "@vitest/ui": "^1.2.2",
88
+ "@vue/composition-api": "^1.7.2",
89
+ "conventional-changelog-unjs": "^0.1.1",
90
+ "eslint": "^8.56.0",
87
91
  "happy-dom": "^12.10.3",
92
+ "npm-run-all2": "^6.1.2",
88
93
  "react": "^18.2.0",
89
94
  "react-dom": "^18.2.0",
90
- "release-it": "^16.2.1",
91
- "typescript": "^5.2.2",
95
+ "release-it": "^16.3.0",
96
+ "typescript": "^5.3.3",
92
97
  "unbuild": "^2.0.0",
93
- "vitest": "^1.1.0",
94
- "vue": "^3.3.13"
98
+ "vitest": "^1.2.2",
99
+ "vue": "^3.4.15",
100
+ "vue-2": "npm:vue@2.7",
101
+ "vue-2.7": "npm:vue@2.7"
95
102
  },
96
103
  "scripts": {
97
104
  "build": "unbuild",
98
105
  "test": "vitest run --coverage",
106
+ "test:vue": "vue-demi-switch 3 && vitest run --dir ./src/vue",
107
+ "test:vue-2": "vue-demi-switch 2 vue-2 && vitest run --dir ./src/vue",
108
+ "test:vue-2.7": "vue-demi-switch 2.7 vue-2.7 && vitest run --dir ./src/vue",
99
109
  "dev:test": "vitest",
100
110
  "release": "release-it --ci",
101
- "lint": "eslint . --cache --cache-location ./node_modules/.cache/eslint"
111
+ "lint": "eslint . --cache --cache-location ./node_modules/.cache/eslint",
112
+ "posttest:vue-2": "vue-demi-switch 3",
113
+ "posttest:vue-2.7": "vue-demi-switch 3"
102
114
  }
103
115
  }
File without changes
File without changes
File without changes
File without changes
File without changes