@iquji-web/web-query 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Iquji contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # Web query
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@iquji-web/web-query` 只提供通用 query 能力,JavaScript、类型声明、必要样式及功能测试随源码交付。
4
+
5
+ 安装使用本目录锁文件,运行 `bun install --frozen-lockfile` 和 `bun run check`。正式入口只导出 `dist` 中的 JavaScript、类型声明,不要求消费者编译本包源码。
@@ -0,0 +1,25 @@
1
+ import { QueryClient, type QueryClientConfig } from "@tanstack/react-query";
2
+ import { type ReactNode } from "react";
3
+ export declare function isAuthorizationQueryError(error: unknown): boolean;
4
+ export declare function shouldRetryIqujiQuery(failureCount: number, error: unknown): boolean;
5
+ export declare const iqujiQueryClientDefaults: {
6
+ defaultOptions: {
7
+ queries: {
8
+ gcTime: number;
9
+ refetchOnReconnect: true;
10
+ refetchOnWindowFocus: false;
11
+ retry: typeof shouldRetryIqujiQuery;
12
+ staleTime: number;
13
+ };
14
+ mutations: {
15
+ retry: false;
16
+ };
17
+ };
18
+ };
19
+ export declare function createIqujiQueryClient(config?: QueryClientConfig): QueryClient;
20
+ export type IqujiQueryProviderProps = {
21
+ children: ReactNode;
22
+ client?: QueryClient;
23
+ clientConfig?: QueryClientConfig;
24
+ };
25
+ export declare function IqujiQueryProvider({ children, client, clientConfig, }: IqujiQueryProviderProps): import("react/jsx-runtime").JSX.Element;
package/dist/index.js ADDED
@@ -0,0 +1,76 @@
1
+ // src/index.tsx
2
+ import {
3
+ QueryClient,
4
+ QueryClientProvider
5
+ } from "@tanstack/react-query";
6
+ import { useState } from "react";
7
+ import { jsx } from "react/jsx-runtime";
8
+ function errorStatus(error) {
9
+ if (!error || typeof error !== "object") {
10
+ return;
11
+ }
12
+ if ("status" in error && typeof error.status === "number") {
13
+ return error.status;
14
+ }
15
+ if ("response" in error && error.response && typeof error.response === "object" && "status" in error.response && typeof error.response.status === "number") {
16
+ return error.response.status;
17
+ }
18
+ return;
19
+ }
20
+ function isAuthorizationQueryError(error) {
21
+ const status = errorStatus(error);
22
+ return status === 401 || status === 403;
23
+ }
24
+ function shouldRetryIqujiQuery(failureCount, error) {
25
+ return !isAuthorizationQueryError(error) && failureCount < 2;
26
+ }
27
+ var iqujiQueryClientDefaults = {
28
+ defaultOptions: {
29
+ queries: {
30
+ gcTime: 5 * 60000,
31
+ refetchOnReconnect: true,
32
+ refetchOnWindowFocus: false,
33
+ retry: shouldRetryIqujiQuery,
34
+ staleTime: 30000
35
+ },
36
+ mutations: {
37
+ retry: false
38
+ }
39
+ }
40
+ };
41
+ function createIqujiQueryClient(config = {}) {
42
+ return new QueryClient({
43
+ ...iqujiQueryClientDefaults,
44
+ ...config,
45
+ defaultOptions: {
46
+ ...iqujiQueryClientDefaults.defaultOptions,
47
+ ...config.defaultOptions,
48
+ queries: {
49
+ ...iqujiQueryClientDefaults.defaultOptions?.queries,
50
+ ...config.defaultOptions?.queries
51
+ },
52
+ mutations: {
53
+ ...iqujiQueryClientDefaults.defaultOptions?.mutations,
54
+ ...config.defaultOptions?.mutations
55
+ }
56
+ }
57
+ });
58
+ }
59
+ function IqujiQueryProvider({
60
+ children,
61
+ client,
62
+ clientConfig
63
+ }) {
64
+ const [ownedClient] = useState(() => client ?? createIqujiQueryClient(clientConfig));
65
+ return /* @__PURE__ */ jsx(QueryClientProvider, {
66
+ client: ownedClient,
67
+ children
68
+ });
69
+ }
70
+ export {
71
+ shouldRetryIqujiQuery,
72
+ isAuthorizationQueryError,
73
+ iqujiQueryClientDefaults,
74
+ createIqujiQueryClient,
75
+ IqujiQueryProvider
76
+ };
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@iquji-web/web-query",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "README.md",
9
+ "LICENSE"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "sideEffects": false,
18
+ "peerDependencies": {
19
+ "react": "19.2.4",
20
+ "@tanstack/react-query": "5.99.2"
21
+ },
22
+ "description": "React Query 客户端、查询和重试策略。",
23
+ "publishConfig": {
24
+ "access": "public",
25
+ "registry": "https://registry.npmjs.org/"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/haydardsx/iquji-community-web.git",
30
+ "directory": "query"
31
+ },
32
+ "homepage": "https://community-web.iquji.com",
33
+ "bugs": {
34
+ "url": "https://github.com/haydardsx/iquji-community-web/issues"
35
+ }
36
+ }