@povio/openapi-codegen-cli 2.0.7 → 2.0.8-rc.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/openapi-codegen-cli",
3
- "version": "2.0.7",
3
+ "version": "2.0.8-rc.2",
4
4
  "keywords": [
5
5
  "codegen",
6
6
  "openapi",
@@ -63,39 +63,39 @@
63
63
  "dev:check": "yarn start check --config ./test/config.ts"
64
64
  },
65
65
  "dependencies": {
66
- "i18next": "^25.7.3",
66
+ "i18next": "^25.8.10",
67
67
  "import-fresh": "^3.3.1"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@apidevtools/swagger-parser": "^10.1.0",
71
- "@casl/ability": "^6.7.3",
72
- "@casl/react": "^5.0.0",
71
+ "@casl/ability": "^6.8.0",
72
+ "@casl/react": "^5.0.1",
73
73
  "@tanstack/react-query": "~5.90.21",
74
- "@types/node": "^20.12.12",
74
+ "@types/node": "^20.19.33",
75
75
  "@types/prompt-sync": "^4.2.3",
76
- "@types/react": "^19.1.0",
77
- "@types/yargs": "^17.0.32",
78
- "@vitejs/plugin-react": "^5.1.3",
79
- "axios": "^1.13.1",
80
- "esbuild": "0.25.0",
76
+ "@types/react": "^19.2.14",
77
+ "@types/yargs": "^17.0.35",
78
+ "@vitejs/plugin-react": "^5.1.4",
79
+ "axios": "^1.13.5",
80
+ "esbuild": "0.25.12",
81
81
  "handlebars": "^4.7.8",
82
82
  "openapi-types": "^12.1.3",
83
- "oxfmt": "^0.27.0",
84
- "oxlint": "^1.41.0",
85
- "oxlint-tsgolint": "^0.11.4",
83
+ "oxfmt": "^0.33.0",
84
+ "oxlint": "^1.48.0",
85
+ "oxlint-tsgolint": "^0.14.0",
86
86
  "prompt-sync": "^4.2.0",
87
- "react": "^19.1.0",
87
+ "react": "^19.2.4",
88
88
  "reflect-metadata": "^0.2.2",
89
89
  "ts-node": "^10.9.2",
90
- "ts-pattern": "^5.3.1",
91
- "tsx": "^4.10.5",
92
- "type-fest": "^4.26.0",
90
+ "ts-pattern": "^5.9.0",
91
+ "tsx": "^4.21.0",
92
+ "type-fest": "^4.41.0",
93
93
  "typescript": "^5.9.3",
94
94
  "vite": "^7.3.1",
95
95
  "vite-plugin-dts": "^4.5.4",
96
- "vitest": "^2.0.5",
96
+ "vitest": "3.2.4",
97
97
  "yargs": "^17.7.2",
98
- "zod": "^4.1.12"
98
+ "zod": "^4.3.6"
99
99
  },
100
100
  "peerDependencies": {
101
101
  "@casl/ability": "^6.7.3",
@@ -0,0 +1,40 @@
1
+ import type { QueryClient, QueryKey } from "@tanstack/react-query";
2
+
3
+ const CROSS_TAB_INVALIDATE_KEY = "__rq_invalidate__";
4
+
5
+ /**
6
+ * Broadcasts a query invalidation event to all other open tabs via localStorage.
7
+ *
8
+ * @param queryKeys - An array of query keys to invalidate (array of arrays).
9
+ *
10
+ * NOTE: The `storage` event only fires in *other* tabs — the calling tab
11
+ * must invalidate its own queryClient separately if needed.
12
+ */
13
+ export const broadcastQueryInvalidation = (queryKeys: QueryKey[]) => {
14
+ localStorage.setItem(CROSS_TAB_INVALIDATE_KEY, JSON.stringify({ keys: queryKeys, timestamp: Date.now() }));
15
+ };
16
+
17
+ /**
18
+ * Registers a one-time global `storage` event listener that reacts to
19
+ * cross-tab invalidation broadcasts. Safe to call from multiple hooks —
20
+ * only the first call sets up the listener.
21
+ */
22
+ let isListenerSetUp = false;
23
+
24
+ export const setupCrossTabListener = (queryClient: QueryClient) => {
25
+ if (isListenerSetUp) return;
26
+ isListenerSetUp = true;
27
+
28
+ window.addEventListener("storage", (e: StorageEvent) => {
29
+ if (e.key !== CROSS_TAB_INVALIDATE_KEY || !e.newValue) return;
30
+
31
+ try {
32
+ const { keys } = JSON.parse(e.newValue) as { keys: QueryKey[] };
33
+ for (const queryKey of keys) {
34
+ queryClient.invalidateQueries({ queryKey });
35
+ }
36
+ } catch {
37
+ // Ignore malformed payloads
38
+ }
39
+ });
40
+ };
@@ -1,12 +1,14 @@
1
- import { useCallback } from "react";
1
+ import { useCallback, useEffect } from "react";
2
2
 
3
- import { OpenApiQueryConfig } from "@povio/openapi-codegen-cli";
4
3
  import { QueryKey, useQueryClient } from "@tanstack/react-query";
5
4
 
6
- import { QueryModule } from "./queryModules";
5
+ import { OpenApiQueryConfig, QueryModule, InvalidationMap } from "../lib/config/queryConfig.context";
6
+ import { broadcastQueryInvalidation, setupCrossTabListener } from "./useCrossTabQueryInvalidation";
7
7
 
8
8
  export interface MutationEffectsOptions {
9
9
  invalidateCurrentModule?: boolean;
10
+ crossTabInvalidation?: boolean;
11
+ invalidationMap?: InvalidationMap;
10
12
  invalidateModules?: QueryModule[];
11
13
  invalidateKeys?: QueryKey[];
12
14
  preferUpdate?: boolean;
@@ -20,9 +22,25 @@ export function useMutationEffects({ currentModule }: UseMutationEffectsProps) {
20
22
  const queryClient = useQueryClient();
21
23
  const config = OpenApiQueryConfig.useConfig();
22
24
 
25
+ useEffect(() => {
26
+ if (!config.crossTabInvalidation) return;
27
+ setupCrossTabListener(queryClient);
28
+ }, [queryClient, config.crossTabInvalidation]);
29
+
23
30
  const runMutationEffects = useCallback(
24
- async <TData>(data: TData, options: MutationEffectsOptions = {}, updateKeys?: QueryKey[]) => {
25
- const { invalidateCurrentModule = true, invalidateModules, invalidateKeys, preferUpdate } = options;
31
+ async <TData, TVariables>(
32
+ data: TData,
33
+ variables: TVariables,
34
+ options: MutationEffectsOptions = {},
35
+ updateKeys?: QueryKey[],
36
+ ) => {
37
+ const {
38
+ invalidateCurrentModule = true,
39
+ invalidateModules,
40
+ invalidateKeys,
41
+ preferUpdate,
42
+ invalidationMap,
43
+ } = options;
26
44
  const shouldUpdate = preferUpdate || (preferUpdate === undefined && config.preferUpdate);
27
45
  const shouldInvalidateCurrentModule =
28
46
  invalidateCurrentModule || (invalidateCurrentModule === undefined && config.invalidateCurrentModule);
@@ -30,6 +48,8 @@ export function useMutationEffects({ currentModule }: UseMutationEffectsProps) {
30
48
  const isQueryKeyEqual = (keyA: QueryKey, keyB: QueryKey) =>
31
49
  keyA.length === keyB.length && keyA.every((item, index) => item === keyB[index]);
32
50
 
51
+ const invalidatedQueryKeys: QueryKey[] = [];
52
+
33
53
  queryClient.invalidateQueries({
34
54
  predicate: ({ queryKey }) => {
35
55
  const isUpdateKey = updateKeys?.some((key) => isQueryKeyEqual(queryKey, key));
@@ -40,15 +60,29 @@ export function useMutationEffects({ currentModule }: UseMutationEffectsProps) {
40
60
  const isCurrentModule = shouldInvalidateCurrentModule && queryKey[0] === currentModule;
41
61
  const isInvalidateModule = !!invalidateModules && invalidateModules.some((module) => queryKey[0] === module);
42
62
  const isInvalidateKey = !!invalidateKeys && invalidateKeys.some((key) => isQueryKeyEqual(queryKey, key));
43
- return isCurrentModule || isInvalidateModule || isInvalidateKey;
63
+
64
+ const map = (invalidationMap || config.invalidationMap)?.[currentModule]?.(data, variables);
65
+ const isMappedKey = !!map && map.some((key) => isQueryKeyEqual(queryKey, key));
66
+
67
+ const shouldInvalidate = isCurrentModule || isInvalidateModule || isInvalidateKey || isMappedKey;
68
+
69
+ if (shouldInvalidate && config.crossTabInvalidation) {
70
+ invalidatedQueryKeys.push([...queryKey]);
71
+ }
72
+
73
+ return shouldInvalidate;
44
74
  },
45
75
  });
46
76
 
77
+ if (config.crossTabInvalidation && invalidatedQueryKeys.length > 0) {
78
+ broadcastQueryInvalidation(invalidatedQueryKeys);
79
+ }
80
+
47
81
  if (shouldUpdate && updateKeys) {
48
82
  updateKeys.map((queryKey) => queryClient.setQueryData(queryKey, data));
49
83
  }
50
84
  },
51
- [queryClient, currentModule, config.preferUpdate],
85
+ [queryClient, currentModule, config.preferUpdate, config.invalidationMap, config.crossTabInvalidation],
52
86
  );
53
87
 
54
88
  return { runMutationEffects };
@@ -47,7 +47,7 @@ export const {{queryName endpoint mutation=true}} = (options?: AppMutationOption
47
47
  {{#if destructuredVariables}}const { {{commaSeparated destructuredVariables }} } = variables;{{/if}}
48
48
  const updateKeys = [{{#each updateQueryEndpoints as | endpoint |}}keys.{{endpointName endpoint}}({{{endpointArgs endpoint includeOnlyRequiredParams=true}}}), {{/each}}];
49
49
  {{/if}}
50
- await runMutationEffects(resData, options{{#if updateQueryEndpoints}}, updateKeys{{/if}});
50
+ await runMutationEffects(resData, variables, options{{#if updateQueryEndpoints}}, updateKeys{{/if}});
51
51
  options?.onSuccess?.(resData, variables, onMutateResult, context);
52
52
  },{{/if}}
53
53
  });
@@ -1,5 +1,9 @@
1
+ import { QueryModule as BaseQueryModule } from "../lib/config/queryConfig.context";
2
+
1
3
  export const enum QueryModule {
2
4
  {{#each modules as | module |}}
3
5
  {{module.tag}} = "{{module.namespace}}",
4
6
  {{/each}}
5
- }
7
+ }
8
+
9
+ export type QueryModuleType = QueryModule | BaseQueryModule;