@vibeflui/react-query 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VibeFlui 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 ADDED
@@ -0,0 +1,45 @@
1
+ # @vibeflui/react-query
2
+
3
+ Optional TanStack Query-compatible provider plugin for VibeFlui / FluiKit.
4
+
5
+ This package does not make TanStack Query mandatory in `@vibeflui/core`. It accepts a QueryClient-like object and registers a FluiKit provider.
6
+
7
+ ```tsx
8
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
9
+ import { FluiKit, FluiKitProvider } from "@vibeflui/core"
10
+ import { createReactQueryPlugin } from "@vibeflui/react-query"
11
+
12
+ const queryClient = new QueryClient()
13
+ const reactQueryPlugin = createReactQueryPlugin({ queryClient })
14
+
15
+ export function UsersPage() {
16
+ return (
17
+ <QueryClientProvider client={queryClient}>
18
+ <FluiKitProvider plugins={[reactQueryPlugin]}>
19
+ <FluiKit schema={usersSchema} />
20
+ </FluiKitProvider>
21
+ </QueryClientProvider>
22
+ )
23
+ }
24
+ ```
25
+
26
+ Use the registered provider from schema:
27
+
28
+ ```ts
29
+ export const usersSchema = {
30
+ resource: "users",
31
+ endpoint: "/api/users",
32
+ provider: {
33
+ type: "custom",
34
+ name: "reactQuery"
35
+ },
36
+ table: {
37
+ columns: ["name", "email", "role.name", "status"]
38
+ },
39
+ form: {
40
+ fields: ["name", "email"]
41
+ }
42
+ }
43
+ ```
44
+
45
+ Default query keys are `["fluikit", resource, operation, ...]`. Mutations invalidate `["fluikit", resource]` by default.
@@ -0,0 +1,47 @@
1
+ import type { FluiKitActionExecutionContext, FluiKitDataProvider, FluiKitPlugin } from "@vibeflui/core";
2
+ export type FluiKitQueryKey = readonly unknown[];
3
+ export type FluiKitReactQueryOperation = "list" | "detail" | "create" | "update" | "delete" | "action" | string;
4
+ export type FluiKitFetchQueryOptions = {
5
+ queryKey: FluiKitQueryKey;
6
+ queryFn: () => Promise<unknown>;
7
+ staleTime?: number;
8
+ gcTime?: number;
9
+ cacheTime?: number;
10
+ meta?: Record<string, unknown>;
11
+ };
12
+ export type FluiKitQueryFilters = {
13
+ queryKey?: FluiKitQueryKey;
14
+ exact?: boolean;
15
+ type?: "active" | "inactive" | "all";
16
+ predicate?: (query: unknown) => boolean;
17
+ [key: string]: unknown;
18
+ };
19
+ export type FluiKitReactQueryClient = {
20
+ fetchQuery?: (options: FluiKitFetchQueryOptions) => unknown | Promise<unknown>;
21
+ ensureQueryData?: (options: FluiKitFetchQueryOptions) => unknown | Promise<unknown>;
22
+ getQueryData?: (queryKey: FluiKitQueryKey) => unknown;
23
+ setQueryData?: (queryKey: FluiKitQueryKey, updater: unknown) => unknown;
24
+ invalidateQueries?: (filters?: FluiKitQueryFilters) => unknown | Promise<unknown>;
25
+ refetchQueries?: (filters?: FluiKitQueryFilters) => unknown | Promise<unknown>;
26
+ };
27
+ export type FluiKitReactQueryKeyResolver = (context: FluiKitActionExecutionContext, operation: FluiKitReactQueryOperation) => FluiKitQueryKey;
28
+ export type CreateReactQueryPluginOptions = {
29
+ queryClient?: FluiKitReactQueryClient;
30
+ providerName?: string;
31
+ baseProvider?: FluiKitDataProvider;
32
+ queryKey?: FluiKitReactQueryKeyResolver;
33
+ invalidateKey?: FluiKitReactQueryKeyResolver;
34
+ invalidateOnMutation?: boolean;
35
+ refetchOnMutation?: boolean;
36
+ staleTime?: number;
37
+ gcTime?: number;
38
+ cacheTime?: number;
39
+ pluginName?: string;
40
+ version?: string;
41
+ };
42
+ export declare function createReactQueryPlugin(options?: CreateReactQueryPluginOptions): FluiKitPlugin;
43
+ export declare function createReactQueryProvider(options?: CreateReactQueryPluginOptions): FluiKitDataProvider;
44
+ export declare function defaultReactQueryKey(context: FluiKitActionExecutionContext, operation: FluiKitReactQueryOperation): FluiKitQueryKey;
45
+ export declare function defaultReactQueryInvalidationKey(context: FluiKitActionExecutionContext): FluiKitQueryKey;
46
+ export declare const ReactQueryPlugin: typeof createReactQueryPlugin;
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEvG,MAAM,MAAM,eAAe,GAAG,SAAS,OAAO,EAAE,CAAA;AAEhD,MAAM,MAAM,0BAA0B,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAA;AAE/G,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,EAAE,eAAe,CAAA;IACzB,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/B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AAW,CAAC,EAAE,uBAAuB,CAAA;IACrC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,mBAAmB,CAAA;IAClC,QAAQ,CAAC,EAAE,4BAA4B,CAAA;IACvC,aAAa,CAAC,EAAE,4BAA4B,CAAA;IAC5C,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,6BAAkC,GAAG,aAAa,CA0BjG;AAED,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,6BAAkC,GAAG,mBAAmB,CAWzG;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,6BAA6B,EACtC,SAAS,EAAE,0BAA0B,GACpC,eAAe,CAYjB;AAED,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,6BAA6B,GAAG,eAAe,CAExG;AAED,eAAO,MAAM,gBAAgB,+BAAyB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,109 @@
1
+ import { createEndpointProvider, createFluiKitPlugin } from "@vibeflui/core";
2
+ export function createReactQueryPlugin(options = {}) {
3
+ const providerName = options.providerName ?? "reactQuery";
4
+ return createFluiKitPlugin({
5
+ name: options.pluginName ?? "@vibeflui/react-query",
6
+ version: options.version ?? "1.0.0",
7
+ packageName: "@vibeflui/react-query",
8
+ description: "Optional TanStack Query-compatible provider plugin for FluiKit.",
9
+ compatibility: {
10
+ core: ">=1.0.0"
11
+ },
12
+ providers: {
13
+ [providerName]: createReactQueryProvider(options)
14
+ },
15
+ messages: {
16
+ loadError: "Unable to load data.",
17
+ submitError: "Unable to submit the form."
18
+ },
19
+ inspectorPanels: [
20
+ {
21
+ key: "react-query",
22
+ label: "React Query",
23
+ renderer: "ReactQueryInspectorPanel"
24
+ }
25
+ ]
26
+ });
27
+ }
28
+ export function createReactQueryProvider(options = {}) {
29
+ const baseProvider = options.baseProvider ?? createEndpointProvider();
30
+ return {
31
+ list: (context) => executeRead(context, "list", () => baseProvider.list?.(context) ?? baseProvider.action?.(context), options),
32
+ detail: (context) => executeRead(context, "detail", () => baseProvider.detail?.(context) ?? baseProvider.action?.(context), options),
33
+ create: (context) => executeMutation(context, "create", () => baseProvider.create?.(context) ?? baseProvider.action?.(context), options),
34
+ update: (context) => executeMutation(context, "update", () => baseProvider.update?.(context) ?? baseProvider.action?.(context), options),
35
+ delete: (context) => executeMutation(context, "delete", () => baseProvider.delete?.(context) ?? baseProvider.action?.(context), options),
36
+ action: (context) => executeMutation(context, context.operation, () => baseProvider.action?.(context), options)
37
+ };
38
+ }
39
+ export function defaultReactQueryKey(context, operation) {
40
+ const resource = context.schema.resource;
41
+ if (operation === "list") {
42
+ return ["fluikit", resource, "list", context.query ?? {}];
43
+ }
44
+ if (operation === "detail" || operation === "view") {
45
+ return ["fluikit", resource, "detail", context.params];
46
+ }
47
+ return ["fluikit", resource, operation, context.params];
48
+ }
49
+ export function defaultReactQueryInvalidationKey(context) {
50
+ return ["fluikit", context.schema.resource];
51
+ }
52
+ export const ReactQueryPlugin = createReactQueryPlugin;
53
+ async function executeRead(context, operation, run, options) {
54
+ const queryClient = options.queryClient;
55
+ const queryKey = resolveQueryKey(context, operation, options.queryKey);
56
+ const queryFn = async () => run();
57
+ if (queryClient?.ensureQueryData) {
58
+ return queryClient.ensureQueryData({
59
+ queryKey,
60
+ queryFn,
61
+ staleTime: options.staleTime,
62
+ gcTime: options.gcTime,
63
+ cacheTime: options.cacheTime,
64
+ meta: queryMeta(context, operation)
65
+ });
66
+ }
67
+ if (queryClient?.fetchQuery) {
68
+ return queryClient.fetchQuery({
69
+ queryKey,
70
+ queryFn,
71
+ staleTime: options.staleTime,
72
+ gcTime: options.gcTime,
73
+ cacheTime: options.cacheTime,
74
+ meta: queryMeta(context, operation)
75
+ });
76
+ }
77
+ return queryFn();
78
+ }
79
+ async function executeMutation(context, operation, run, options) {
80
+ const data = await run();
81
+ if (options.invalidateOnMutation !== false) {
82
+ await invalidateReactQuery(context, operation, options);
83
+ }
84
+ return data;
85
+ }
86
+ async function invalidateReactQuery(context, operation, options) {
87
+ const queryClient = options.queryClient;
88
+ if (!queryClient)
89
+ return;
90
+ const filters = {
91
+ queryKey: resolveQueryKey(context, operation, options.invalidateKey ?? defaultReactQueryInvalidationKey)
92
+ };
93
+ if (queryClient.invalidateQueries) {
94
+ await queryClient.invalidateQueries(filters);
95
+ }
96
+ if (options.refetchOnMutation && queryClient.refetchQueries) {
97
+ await queryClient.refetchQueries(filters);
98
+ }
99
+ }
100
+ function resolveQueryKey(context, operation, resolver) {
101
+ return resolver?.(context, operation) ?? defaultReactQueryKey(context, operation);
102
+ }
103
+ function queryMeta(context, operation) {
104
+ return {
105
+ resource: context.schema.resource,
106
+ operation,
107
+ endpoint: context.endpoint
108
+ };
109
+ }
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@vibeflui/react-query",
3
+ "version": "1.0.0",
4
+ "description": "Optional TanStack Query-compatible provider plugin for VibeFlui / FluiKit.",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "heloconia",
8
+ "url": "https://github.com/heloconia"
9
+ },
10
+ "homepage": "https://github.com/heloconia/vibeflui#readme",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/heloconia/vibeflui.git",
14
+ "directory": "packages/react-query"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/heloconia/vibeflui/issues"
18
+ },
19
+ "funding": [
20
+ { "type": "ko-fi", "url": "https://ko-fi.com/heloconia" },
21
+ { "type": "trakteer", "url": "https://trakteer.id/heloconia" },
22
+ { "type": "saweria", "url": "https://saweria.co/heloconia" }
23
+ ],
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js"
33
+ }
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "engines": {
39
+ "node": ">=18.18.0"
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "README.md"
44
+ ],
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.json",
47
+ "prepack": "test -f ../core/dist/index.d.ts || npm --prefix ../core run build && npm run build",
48
+ "typecheck": "tsc -p tsconfig.local.json --noEmit"
49
+ },
50
+ "keywords": [
51
+ "vibeflui",
52
+ "fluikit",
53
+ "form generator",
54
+ "table list generator",
55
+ "ui generator",
56
+ "json to ui",
57
+ "react-query",
58
+ "tanstack-query",
59
+ "schema-driven"
60
+ ],
61
+ "peerDependencies": {
62
+ "@tanstack/react-query": ">=5.0.0",
63
+ "@vibeflui/core": ">=1.0.0"
64
+ },
65
+ "peerDependenciesMeta": {
66
+ "@tanstack/react-query": {
67
+ "optional": true
68
+ }
69
+ },
70
+ "devDependencies": {
71
+ "typescript": "^5.4.5"
72
+ }
73
+ }