@ainias42/tanstack-ids 0.0.2 → 0.0.4

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.
Files changed (57) hide show
  1. package/.prettierrc +1 -1
  2. package/dist/QueryContext/QueriesContextProvider.d.ts +1 -1
  3. package/dist/QueryContext/QueriesContextProvider.js +1 -1
  4. package/dist/QueryContext/QueriesContextProvider.js.map +1 -1
  5. package/dist/QueryContext/SubQueriesContext.d.ts +1 -1
  6. package/dist/QueryContext/SubQueriesContext.js +2 -2
  7. package/dist/QueryContext/SubQueriesContext.js.map +1 -1
  8. package/dist/QueryContext/useGenerateQueriesContextId.js +1 -1
  9. package/dist/QueryContext/useGenerateQueriesContextId.js.map +1 -1
  10. package/dist/QueryContext/useQueriesError.js +1 -1
  11. package/dist/QueryContext/useQueriesError.js.map +1 -1
  12. package/dist/QueryContext/useQueriesIsFetching.js +1 -1
  13. package/dist/QueryContext/useQueriesIsFetching.js.map +1 -1
  14. package/dist/QueryContext/useQueriesReload.js +1 -1
  15. package/dist/QueryContext/useQueriesReload.js.map +1 -1
  16. package/dist/QueryContext/useQueriesStore.d.ts +2 -1
  17. package/dist/QueryContext/useQueriesStore.js +17 -17
  18. package/dist/QueryContext/useQueriesStore.js.map +1 -1
  19. package/dist/QueryContext/useQuerySubscribeToReload.js +5 -5
  20. package/dist/QueryContext/useQuerySubscribeToReload.js.map +1 -1
  21. package/dist/QueryContext/useScopedQueriesIsFetching.js +1 -1
  22. package/dist/QueryContext/useScopedQueriesIsFetching.js.map +1 -1
  23. package/dist/generateIdsQuery.d.ts +82 -7
  24. package/dist/generateIdsQuery.js +51 -32
  25. package/dist/generateIdsQuery.js.map +1 -1
  26. package/dist/generateNestedIdQuery.d.ts +83 -9
  27. package/dist/generateNestedIdQuery.js +2 -2
  28. package/dist/generateNestedIdQuery.js.map +1 -1
  29. package/dist/generateQuery.js +1 -1
  30. package/dist/generateQuery.js.map +1 -1
  31. package/dist/hooks/formatInitialPage.js +1 -1
  32. package/dist/hooks/useArrayData.js +1 -1
  33. package/dist/hooks/useArrayData.js.map +1 -1
  34. package/dist/noop.js +0 -1
  35. package/dist/noop.js.map +1 -1
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/eslint.config.js +3 -0
  38. package/package.json +12 -8
  39. package/src/QueryContext/QueriesContextProvider.tsx +2 -2
  40. package/src/QueryContext/SubQueriesContext.tsx +4 -4
  41. package/src/QueryContext/useGenerateQueriesContextId.ts +1 -1
  42. package/src/QueryContext/useQueriesError.ts +1 -1
  43. package/src/QueryContext/useQueriesIsFetching.ts +1 -1
  44. package/src/QueryContext/useQueriesReload.ts +1 -1
  45. package/src/QueryContext/useQueriesStore.ts +21 -21
  46. package/src/QueryContext/useQuerySubscribeToReload.ts +5 -5
  47. package/src/QueryContext/useScopedQueriesIsFetching.ts +1 -1
  48. package/src/generateIdsQuery.ts +172 -127
  49. package/src/generateNestedIdQuery.ts +6 -6
  50. package/src/generateQuery.ts +12 -13
  51. package/src/hoistReactQueryKitAttributes.ts +1 -1
  52. package/src/hooks/formatInitialPage.ts +1 -1
  53. package/src/hooks/useArrayData.ts +3 -3
  54. package/src/hooks/useIndexedData.ts +3 -3
  55. package/src/noop.ts +0 -1
  56. package/tsconfig.json +3 -12
  57. package/.eslintrc.cjs +0 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainias42/tanstack-ids",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,7 +14,9 @@
14
14
  "lint:noCache": "eslint \"src/{**/*,*}.{js,jsx,tsx,ts}\" --max-warnings 0",
15
15
  "lint": "npm run lint:noCache -- --cache",
16
16
  "lint:fix": "npm run lint -- --fix",
17
- "typecheck": "tsc --noEmit"
17
+ "typecheck": "tsc --noEmit",
18
+ "prettier": "npm run prettier:list -- --write",
19
+ "prettier:list": "prettier --list-different \"src/**/*.{ts,tsx,js,jsx,json}\""
18
20
  },
19
21
  "type": "module",
20
22
  "author": "",
@@ -23,14 +25,16 @@
23
25
  "url": "gitea@git.silas.link:Ainias/libraries.git"
24
26
  },
25
27
  "dependencies": {
26
- "@ainias42/js-helper": ">=0.8.15",
27
- "@tanstack/react-query": "^5.8.9",
28
+ "@ainias42/config": "*",
29
+ "@types/react": "^19.1.11",
30
+ "@ainias42/js-helper": "^0.8.17",
31
+ "@tanstack/react-query": "^5.85.5",
28
32
  "@yornaath/batshit": "^0.10.1",
29
- "react-query-kit": "^3.3.0",
30
- "zustand": "^4.5.5"
33
+ "react-query-kit": "^3.3.2",
34
+ "zustand": "^5.0.8",
35
+ "react": "^19.1.1"
31
36
  },
32
37
  "devDependencies": {
33
- "ctix": "^2.6.4",
34
- "prettier": "^3.3.3"
38
+ "ctix": "^2.7.1"
35
39
  }
36
40
  }
@@ -7,8 +7,8 @@ import type { ReactNode } from 'react';
7
7
  export type QueriesContextProviderProps = { children: ReactNode };
8
8
 
9
9
  export const QueriesContextProvider = withMemo(function QueriesContextProvider({
10
- children
11
- }: QueriesContextProviderProps) {
10
+ children,
11
+ }: QueriesContextProviderProps) {
12
12
  // Refs
13
13
 
14
14
  // States/Variables/Selectors
@@ -7,15 +7,15 @@ import React, { type ReactNode, useContext } from 'react';
7
7
  export type SubQueriesContextProps = { children: ReactNode; subContextId?: number };
8
8
 
9
9
  export const SubQueriesContext = withMemo(function SubQueriesContext({
10
- children,
11
- subContextId
12
- }: SubQueriesContextProps) {
10
+ children,
11
+ subContextId,
12
+ }: SubQueriesContextProps) {
13
13
  // Refs
14
14
 
15
15
  // States/Variables/Selectors
16
16
  const parentId = useContext(QueriesContext);
17
17
 
18
- const [addSubContext, removeSubContext] = useQueriesStore(s => [s.addSubContext, s.removeSubContext]);
18
+ const [addSubContext, removeSubContext] = useQueriesStore((s) => [s.addSubContext, s.removeSubContext]);
19
19
 
20
20
  const id = useGenerateQueriesContextId();
21
21
  const usedId = subContextId ?? id;
@@ -2,6 +2,6 @@ import { useMemo } from 'react';
2
2
  import { useQueriesStore } from '@/QueryContext/useQueriesStore';
3
3
 
4
4
  export function useGenerateQueriesContextId() {
5
- const generateId = useQueriesStore(s => s.generateContextId);
5
+ const generateId = useQueriesStore((s) => s.generateContextId);
6
6
  return useMemo(() => generateId(), [generateId]);
7
7
  }
@@ -4,5 +4,5 @@ import { useQueriesStore } from '@/QueryContext/useQueriesStore';
4
4
 
5
5
  export function useQueriesError(contextId?: number) {
6
6
  const context = useContext(QueriesContext);
7
- return useQueriesStore(s => s.getError(contextId ?? context));
7
+ return useQueriesStore((s) => s.getError(contextId ?? context));
8
8
  }
@@ -4,5 +4,5 @@ import { useQueriesStore } from '@/QueryContext/useQueriesStore';
4
4
 
5
5
  export function useQueriesIsFetching(contextId?: number) {
6
6
  const context = useContext(QueriesContext);
7
- return useQueriesStore(s => s.isFetching(contextId ?? context));
7
+ return useQueriesStore((s) => s.isFetching(contextId ?? context));
8
8
  }
@@ -5,7 +5,7 @@ import { useQueryClient } from '@tanstack/react-query';
5
5
 
6
6
  export function useQueriesReload(contextId?: number) {
7
7
  const context = useContext(QueriesContext);
8
- const reloadContext = useQueriesStore(s => s.reload);
8
+ const reloadContext = useQueriesStore((s) => s.reload);
9
9
  const queryClient = useQueryClient();
10
10
 
11
11
  return useCallback(async () => {
@@ -21,14 +21,14 @@ function initialState() {
21
21
  items: URecord<number, QueryItem>;
22
22
  }
23
23
  >,
24
- subContexts: {} as URecord<number, number[]>
24
+ subContexts: {} as URecord<number, number[]>,
25
25
  };
26
26
  }
27
27
 
28
28
  export type QueriesStoreState = ReturnType<typeof actionsGenerator> & ReturnType<typeof initialState>;
29
29
  type SetState = (
30
30
  newState: Partial<QueriesStoreState> | QueriesStoreState | ((state: QueriesStoreState) => QueriesStoreState | void),
31
- replace?: boolean
31
+ replace?: boolean,
32
32
  ) => void;
33
33
  type GetState = () => Readonly<QueriesStoreState>;
34
34
  const actionsGenerator = (set: SetState, get: GetState) => ({
@@ -38,11 +38,11 @@ const actionsGenerator = (set: SetState, get: GetState) => ({
38
38
  },
39
39
  generateContextId() {
40
40
  let id = 0;
41
- set(state => {
41
+ set((state) => {
42
42
  state.lastContextId++;
43
43
  state.contexts[state.lastContextId] = {
44
44
  lastId: 0,
45
- items: {}
45
+ items: {},
46
46
  };
47
47
  id = state.lastContextId;
48
48
  });
@@ -50,7 +50,7 @@ const actionsGenerator = (set: SetState, get: GetState) => ({
50
50
  },
51
51
  setItem(contextId: number, itemId: number | undefined, item: QueryItem) {
52
52
  let id = itemId;
53
- set(state => {
53
+ set((state) => {
54
54
  const contextData = state.contexts[contextId];
55
55
  if (!contextData) {
56
56
  return;
@@ -68,34 +68,34 @@ const actionsGenerator = (set: SetState, get: GetState) => ({
68
68
  if (!itemId) {
69
69
  return;
70
70
  }
71
- set(state => {
71
+ set((state) => {
72
72
  delete state.contexts[contextId]?.items[itemId];
73
73
  });
74
74
  },
75
75
  isFetching(contextId: number): boolean {
76
76
  const state = get();
77
77
  return (
78
- ObjectHelper.values(state.contexts[contextId]?.items ?? {}).some(item => item.isFetching) ||
79
- (state.subContexts[contextId]?.some(id => state.isFetching(id)) ?? false)
78
+ ObjectHelper.values(state.contexts[contextId]?.items ?? {}).some((item) => item.isFetching) ||
79
+ (state.subContexts[contextId]?.some((id) => state.isFetching(id)) ?? false)
80
80
  );
81
81
  },
82
82
  isFetchingByScope(contextId: number, scope: { global: boolean; subContexts: boolean }): boolean {
83
83
  const state = get();
84
84
  return (
85
85
  ((scope.global &&
86
- ObjectHelper.values(state.contexts[contextId]?.items ?? {}).some(item => item.isFetching)) ||
87
- (scope.subContexts && state.subContexts[contextId]?.some(id => state.isFetching(id)))) ??
86
+ ObjectHelper.values(state.contexts[contextId]?.items ?? {}).some((item) => item.isFetching)) ||
87
+ (scope.subContexts && state.subContexts[contextId]?.some((id) => state.isFetching(id)))) ??
88
88
  false
89
89
  );
90
90
  },
91
91
  getError(contextId: number): any {
92
92
  const state = get();
93
93
 
94
- const error = ObjectHelper.values(state.contexts[contextId]?.items ?? {}).find(item => item.error)?.error;
94
+ const error = ObjectHelper.values(state.contexts[contextId]?.items ?? {}).find((item) => item.error)?.error;
95
95
  if (error) {
96
96
  return error;
97
97
  }
98
- const subContextWithError = state.subContexts[contextId]?.find(childId => state.getError(childId));
98
+ const subContextWithError = state.subContexts[contextId]?.find((childId) => state.getError(childId));
99
99
  if (subContextWithError) {
100
100
  return state.getError(subContextWithError);
101
101
  }
@@ -104,7 +104,7 @@ const actionsGenerator = (set: SetState, get: GetState) => ({
104
104
  getAllKeys(contextId: number): Set<string> {
105
105
  const state = get();
106
106
 
107
- const keys = new Set(ObjectHelper.values(state.contexts[contextId]?.items ?? {}).flatMap(item => item.keys));
107
+ const keys = new Set(ObjectHelper.values(state.contexts[contextId]?.items ?? {}).flatMap((item) => item.keys));
108
108
 
109
109
  const subContext = state.subContexts[contextId];
110
110
  if (subContext) {
@@ -123,28 +123,28 @@ const actionsGenerator = (set: SetState, get: GetState) => ({
123
123
 
124
124
  const keys = state.getAllKeys(contextId);
125
125
  return queryClient.refetchQueries({
126
- predicate: query => keys.has(query.queryHash)
126
+ predicate: (query) => keys.has(query.queryHash),
127
127
  });
128
128
  },
129
129
  addSubContext(parent: number, child: number) {
130
- set(state => {
130
+ set((state) => {
131
131
  const newChildren = state.subContexts[parent] ?? [];
132
132
  newChildren.push(child);
133
133
  state.subContexts[parent] = newChildren;
134
134
  });
135
135
  },
136
136
  removeSubContext(parent: number, child: number) {
137
- set(state => {
138
- state.subContexts[parent] = state.subContexts[parent]?.filter(id => id !== child);
137
+ set((state) => {
138
+ state.subContexts[parent] = state.subContexts[parent]?.filter((id) => id !== child);
139
139
  });
140
- }
140
+ },
141
141
  });
142
142
 
143
143
  export const useQueriesStore = create<QueriesStoreState>()(
144
144
  subscribeWithSelector(
145
145
  immer((set, get) => ({
146
146
  ...initialState(),
147
- ...actionsGenerator(set, get)
148
- }))
149
- )
147
+ ...actionsGenerator(set, get),
148
+ })),
149
+ ),
150
150
  );
@@ -1,19 +1,19 @@
1
1
  import { QueriesContext } from '@/QueryContext/QueriesContext';
2
- import { useClientLayoutEffect } from "@ainias42/react-bootstrap-mobile";
2
+ import { useClientLayoutEffect } from '@ainias42/react-bootstrap-mobile';
3
3
  import { useContext, useRef } from 'react';
4
4
  import { useQueriesStore } from '@/QueryContext/useQueriesStore';
5
5
 
6
6
  export function useQueriesSubscribeToReload(keys: string[], isFetching: boolean, error: any) {
7
7
  const contextId = useContext(QueriesContext);
8
- const setItem = useQueriesStore(s => s.setItem);
9
- const removeItem = useQueriesStore(s => s.removeItem);
10
- const id = useRef<number | undefined>();
8
+ const setItem = useQueriesStore((s) => s.setItem);
9
+ const removeItem = useQueriesStore((s) => s.removeItem);
10
+ const id = useRef<number | undefined>(undefined);
11
11
 
12
12
  useClientLayoutEffect(() => {
13
13
  id.current = setItem(contextId, id.current, {
14
14
  keys,
15
15
  error,
16
- isFetching
16
+ isFetching,
17
17
  });
18
18
  // eslint-disable-next-line react-hooks/exhaustive-deps
19
19
  }, [contextId, error, isFetching, setItem, ...keys]);
@@ -5,5 +5,5 @@ import { useQueriesStore } from '@/QueryContext/useQueriesStore';
5
5
  export function useScopedQueriesIsFetching(scope: { global: boolean; subContexts: boolean }, contextId?: number) {
6
6
  const context = useContext(QueriesContext);
7
7
 
8
- return useQueriesStore(s => s.isFetchingByScope(contextId ?? context, scope));
8
+ return useQueriesStore((s) => s.isFetchingByScope(contextId ?? context, scope));
9
9
  }