@ainias42/tanstack-ids 0.1.2 → 0.1.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 (61) hide show
  1. package/agents/queries.md +13 -0
  2. package/dist/NotFoundError.js.map +1 -1
  3. package/dist/QueryContext/QueriesContext.js.map +1 -1
  4. package/dist/QueryContext/QueriesContextProvider.js.map +1 -1
  5. package/dist/QueryContext/SubQueriesContext.js.map +1 -1
  6. package/dist/QueryContext/useGenerateQueriesContextId.js.map +1 -1
  7. package/dist/QueryContext/useQueriesError.js.map +1 -1
  8. package/dist/QueryContext/useQueriesIsFetching.js.map +1 -1
  9. package/dist/QueryContext/useQueriesReload.js.map +1 -1
  10. package/dist/QueryContext/useQueriesStore.js.map +1 -1
  11. package/dist/QueryContext/useQuerySubscribeToReload.js.map +1 -1
  12. package/dist/QueryContext/useScopedQueriesIsFetching.js.map +1 -1
  13. package/dist/generateIdsQuery.d.ts +5 -2
  14. package/dist/generateIdsQuery.js +22 -8
  15. package/dist/generateIdsQuery.js.map +1 -1
  16. package/dist/generateNestedIdQuery.d.ts +4 -1
  17. package/dist/generateNestedIdQuery.js.map +1 -1
  18. package/dist/generateQuery.js.map +1 -1
  19. package/dist/hoistReactQueryKitAttributes.js.map +1 -1
  20. package/dist/hooks/formatInitialPage.js.map +1 -1
  21. package/dist/hooks/useArrayData.js.map +1 -1
  22. package/dist/hooks/useIndexedData.js.map +1 -1
  23. package/dist/hooks/useInfiniteScrolling.d.ts +1 -0
  24. package/dist/hooks/useInfiniteScrolling.js +31 -0
  25. package/dist/hooks/useInfiniteScrolling.js.map +1 -0
  26. package/dist/hooks/useInitialData.js.map +1 -1
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.js +1 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/noop.js.map +1 -1
  31. package/dist/types/DeepPartial.js.map +1 -1
  32. package/package.json +9 -3
  33. package/.ctirc +0 -112
  34. package/.prettierrc +0 -1
  35. package/bin/release.sh +0 -3
  36. package/bin/updatePackages.sh +0 -3
  37. package/eslint.config.js +0 -3
  38. package/src/NotFoundError.ts +0 -6
  39. package/src/QueryContext/QueriesContext.ts +0 -3
  40. package/src/QueryContext/QueriesContextProvider.tsx +0 -28
  41. package/src/QueryContext/SubQueriesContext.tsx +0 -38
  42. package/src/QueryContext/useGenerateQueriesContextId.ts +0 -7
  43. package/src/QueryContext/useQueriesError.ts +0 -8
  44. package/src/QueryContext/useQueriesIsFetching.ts +0 -8
  45. package/src/QueryContext/useQueriesReload.ts +0 -14
  46. package/src/QueryContext/useQueriesStore.ts +0 -150
  47. package/src/QueryContext/useQuerySubscribeToReload.ts +0 -24
  48. package/src/QueryContext/useScopedQueriesIsFetching.ts +0 -9
  49. package/src/generateIdsQuery.ts +0 -452
  50. package/src/generateNestedIdQuery.ts +0 -38
  51. package/src/generateQuery.ts +0 -58
  52. package/src/hoistReactQueryKitAttributes.ts +0 -16
  53. package/src/hooks/formatInitialPage.ts +0 -12
  54. package/src/hooks/useArrayData.ts +0 -20
  55. package/src/hooks/useIndexedData.ts +0 -24
  56. package/src/hooks/useInitialData.ts +0 -13
  57. package/src/index.ts +0 -21
  58. package/src/noop.ts +0 -2
  59. package/src/types/DeepPartial.ts +0 -5
  60. package/stylelint.config.mjs +0 -4
  61. package/tsconfig.json +0 -11
package/.ctirc DELETED
@@ -1,112 +0,0 @@
1
- {
2
- // Stream of cli spinner, you can pass stdout or stderr
3
- //
4
- // @mode all
5
- // @default stdout
6
- "spinnerStream": "stdout",
7
- // Stream of cli progress, you can pass stdout or stderr
8
- //
9
- // @mode all
10
- // @default stdout
11
- "progressStream": "stdout",
12
- // Stream of cli reasoner. Reasoner show name conflict error and already exist index.ts file error.
13
- // You can pass stdout or stderr
14
- //
15
- // @mode all
16
- // @default stderr
17
- "reasonerStream": "stderr",
18
- "options": [
19
- {
20
- // build mode
21
- // - create: create an `index.ts` file in each directory
22
- // - bundle: bundle all export information in one `index.ts` file
23
- "mode": "bundle",
24
- // tsconfig.json path: you must pass path with filename, like this "./tsconfig.json"
25
- // only work root directory or cli parameter
26
- //
27
- // @mode all
28
- "project": "tsconfig.json",
29
- // Export filename, if you not pass this field that use "index.ts" or "index.d.ts"
30
- //
31
- // @mode create, bundle, remove
32
- // @default index.ts
33
- "exportFilename": "index.ts",
34
- // add ctix comment at first line of creted index.ts file, that remark created from ctix
35
- //
36
- // @mode create, bundle
37
- // @default false
38
- "useSemicolon": true,
39
- // add ctix comment at first line of creted index.ts file, that remark created from ctix
40
- //
41
- // @mode create, bundle
42
- // @default false
43
- "useBanner": false,
44
- // If specified as true, adds the created date to the top of the `index.ts` file,
45
- // this option only works if the `useBanner` option is enabled
46
- //
47
- // @mode create, bundle
48
- // @default false
49
- "useTimestamp": false,
50
- // quote mark " or '
51
- // @mode create, bundle
52
- //
53
- // @default '
54
- "quote": "'",
55
- // Use to add a literal like `"use strict"` to the top. It will be added before the banner.
56
- //
57
- // @mode create, bundle
58
- "directive": "",
59
- // keep file extension in export statement path
60
- //
61
- // if this option set true that see below
62
- // export * from './test.ts'
63
- //
64
- // @mode create, bundle
65
- // @default none
66
- "fileExt": "none",
67
- // overwrite each index.ts file
68
- // @mode create, bundle
69
- // @default false
70
- "overwrite": true,
71
- // Create a backup file if the `index.ts` file already exists.
72
- // This option only works if the `overwrite` option is enabled.
73
- //
74
- // @mode create, bundle
75
- // @default true
76
- "backup": false,
77
- // When generating the `index.ts` file, decide how you want to generate it
78
- //
79
- // @mode create, bundle
80
- // @default auto
81
- "generationStyle": "auto",
82
- // A list of files to use when generating the index.ts file. If no value is set,
83
- // the value of the include setting set in the tsconfig.json file will be used
84
- //
85
- // @mode create, bundle
86
- "include": [
87
- "src/**/*.tsx",
88
- "src/**/*.ts"
89
- ],
90
- // A list of files to exclude when generating the index.ts file. If no value is set,
91
- // the value of the exclude setting set in the tsconfig.json file is used
92
- //
93
- // @mode create, bundle
94
- "exclude": [
95
- "../../node_modules",
96
- "dist/**/*",
97
- "dist/src/**/*"
98
- ],
99
- // Output directory. Default value is same project directory
100
- // @mode bundle
101
- "output": "./src",
102
- // remove with backup file
103
- // @mode remove
104
- // @default false
105
- "removeBackup": false,
106
- // answer `yes` to all questions
107
- // @mode remove
108
- // @default false
109
- "forceYes": false
110
- }
111
- ]
112
- }
package/.prettierrc DELETED
@@ -1 +0,0 @@
1
- "@ainias42/config/prettierrc.js"
package/bin/release.sh DELETED
@@ -1,3 +0,0 @@
1
- #! /bin/bash
2
-
3
- ../../bin/release.sh $1 tanstack-ids
@@ -1,3 +0,0 @@
1
- #! /bin/bash
2
-
3
- ../../bin/updatePackages.sh tanstack-ids
package/eslint.config.js DELETED
@@ -1,3 +0,0 @@
1
- import defaultConfig from '@ainias42/config/eslint.config.js';
2
-
3
- export default defaultConfig;
@@ -1,6 +0,0 @@
1
- export class NotFoundError extends Error {
2
- constructor(id: number | string | symbol) {
3
- super(`Item with id ${String(id)} not found`);
4
- this.name = 'NotFoundError';
5
- }
6
- }
@@ -1,3 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- export const QueriesContext = createContext<number>(0);
@@ -1,28 +0,0 @@
1
- import { QueriesContext } from './QueriesContext';
2
- import { useGenerateQueriesContextId } from './useGenerateQueriesContextId';
3
- import { withMemo } from '@ainias42/react-bootstrap-mobile';
4
- import React from 'react';
5
- import type { ReactNode } from 'react';
6
-
7
- export type QueriesContextProviderProps = { children: ReactNode };
8
-
9
- export const QueriesContextProvider = withMemo(function QueriesContextProviderComponent({
10
- children,
11
- }: QueriesContextProviderProps) {
12
- // Refs
13
-
14
- // States/Variables/Selectors
15
- const id = useGenerateQueriesContextId();
16
-
17
- // Dispatch
18
-
19
- // Callbacks
20
-
21
- // Effects
22
-
23
- // Other
24
-
25
- // RenderFunctions
26
-
27
- return <QueriesContext.Provider value={id}>{children}</QueriesContext.Provider>;
28
- });
@@ -1,38 +0,0 @@
1
- import { QueriesContext } from './QueriesContext';
2
- import { useClientLayoutEffect, withMemo } from '@ainias42/react-bootstrap-mobile';
3
- import { useGenerateQueriesContextId } from './useGenerateQueriesContextId';
4
- import { useQueriesStore } from './useQueriesStore';
5
- import React, { type ReactNode, useContext } from 'react';
6
-
7
- export type SubQueriesContextProps = { children: ReactNode; subContextId?: number };
8
-
9
- export const SubQueriesContext = withMemo(function SubQueriesContextComponent({
10
- children,
11
- subContextId,
12
- }: SubQueriesContextProps) {
13
- // Refs
14
-
15
- // States/Variables/Selectors
16
- const parentId = useContext(QueriesContext);
17
-
18
- const [addSubContext, removeSubContext] = useQueriesStore((s) => [s.addSubContext, s.removeSubContext]);
19
-
20
- const id = useGenerateQueriesContextId();
21
- const usedId = subContextId ?? id;
22
-
23
- // Dispatch
24
-
25
- // Callbacks
26
-
27
- // Effects
28
- useClientLayoutEffect(() => {
29
- addSubContext(parentId, usedId);
30
- return () => removeSubContext(parentId, usedId);
31
- }, [addSubContext, usedId, parentId, removeSubContext]);
32
-
33
- // Other
34
-
35
- // RenderFunctions
36
-
37
- return <QueriesContext.Provider value={usedId}>{children}</QueriesContext.Provider>;
38
- });
@@ -1,7 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { useQueriesStore } from './useQueriesStore';
3
-
4
- export function useGenerateQueriesContextId() {
5
- const generateId = useQueriesStore((s) => s.generateContextId);
6
- return useMemo(() => generateId(), [generateId]);
7
- }
@@ -1,8 +0,0 @@
1
- import { QueriesContext } from './QueriesContext';
2
- import { useContext } from 'react';
3
- import { useQueriesStore } from './useQueriesStore';
4
-
5
- export function useQueriesError(contextId?: number) {
6
- const context = useContext(QueriesContext);
7
- return useQueriesStore((s) => s.getError(contextId ?? context));
8
- }
@@ -1,8 +0,0 @@
1
- import { QueriesContext } from './QueriesContext';
2
- import { useContext } from 'react';
3
- import { useQueriesStore } from './useQueriesStore';
4
-
5
- export function useQueriesIsFetching(contextId?: number) {
6
- const context = useContext(QueriesContext);
7
- return useQueriesStore((s) => s.isFetching(contextId ?? context));
8
- }
@@ -1,14 +0,0 @@
1
- import { QueriesContext } from './QueriesContext';
2
- import { useCallback, useContext } from 'react';
3
- import { useQueriesStore } from './useQueriesStore';
4
- import { useQueryClient } from '@tanstack/react-query';
5
-
6
- export function useQueriesReload(contextId?: number) {
7
- const context = useContext(QueriesContext);
8
- const reloadContext = useQueriesStore((s) => s.reload);
9
- const queryClient = useQueryClient();
10
-
11
- return useCallback(async () => {
12
- return reloadContext(queryClient, contextId ?? context);
13
- }, [context, contextId, queryClient, reloadContext]);
14
- }
@@ -1,150 +0,0 @@
1
- import { ObjectHelper } from '@ainias42/js-helper';
2
- import { create } from 'zustand';
3
- import { immer } from 'zustand/middleware/immer';
4
- import { subscribeWithSelector } from 'zustand/middleware';
5
- import type { QueryClient } from '@tanstack/react-query';
6
- import type { URecord } from '@ainias42/js-helper';
7
-
8
- type QueryItem = {
9
- keys: string[];
10
- isFetching: boolean;
11
- error: any;
12
- };
13
-
14
- function initialState() {
15
- return {
16
- lastContextId: 0,
17
- contexts: {} as URecord<
18
- number,
19
- {
20
- lastId: number;
21
- items: URecord<number, QueryItem>;
22
- }
23
- >,
24
- subContexts: {} as URecord<number, number[]>,
25
- };
26
- }
27
-
28
- export type QueriesStoreState = ReturnType<typeof actionsGenerator> & ReturnType<typeof initialState>;
29
- type SetState = (
30
- newState: Partial<QueriesStoreState> | QueriesStoreState | ((state: QueriesStoreState) => QueriesStoreState | void),
31
- replace?: boolean,
32
- ) => void;
33
- type GetState = () => Readonly<QueriesStoreState>;
34
- const actionsGenerator = (set: SetState, get: GetState) => ({
35
- get,
36
- clear() {
37
- set({ ...initialState(), ...actionsGenerator(set, get) }, true);
38
- },
39
- generateContextId() {
40
- let id = 0;
41
- set((state) => {
42
- state.lastContextId++;
43
- state.contexts[state.lastContextId] = {
44
- lastId: 0,
45
- items: {},
46
- };
47
- id = state.lastContextId;
48
- });
49
- return id;
50
- },
51
- setItem(contextId: number, itemId: number | undefined, item: QueryItem) {
52
- let id = itemId;
53
- set((state) => {
54
- const contextData = state.contexts[contextId];
55
- if (!contextData) {
56
- return;
57
- }
58
-
59
- if (!id) {
60
- contextData.lastId++;
61
- id = contextData.lastId;
62
- }
63
- contextData.items[id] = item;
64
- });
65
- return id;
66
- },
67
- removeItem(contextId: number, itemId: number | undefined) {
68
- if (!itemId) {
69
- return;
70
- }
71
- set((state) => {
72
- delete state.contexts[contextId]?.items[itemId];
73
- });
74
- },
75
- isFetching(contextId: number): boolean {
76
- const state = get();
77
- return (
78
- ObjectHelper.values(state.contexts[contextId]?.items ?? {}).some((item) => item.isFetching) ||
79
- (state.subContexts[contextId]?.some((id) => state.isFetching(id)) ?? false)
80
- );
81
- },
82
- isFetchingByScope(contextId: number, scope: { global: boolean; subContexts: boolean }): boolean {
83
- const state = get();
84
- return (
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)))) ??
88
- false
89
- );
90
- },
91
- getError(contextId: number): any {
92
- const state = get();
93
-
94
- const error = ObjectHelper.values(state.contexts[contextId]?.items ?? {}).find((item) => item.error)?.error;
95
- if (error) {
96
- return error;
97
- }
98
- const subContextWithError = state.subContexts[contextId]?.find((childId) => state.getError(childId));
99
- if (subContextWithError) {
100
- return state.getError(subContextWithError);
101
- }
102
- return undefined;
103
- },
104
- getAllKeys(contextId: number): Set<string> {
105
- const state = get();
106
-
107
- const keys = new Set(ObjectHelper.values(state.contexts[contextId]?.items ?? {}).flatMap((item) => item.keys));
108
-
109
- const subContext = state.subContexts[contextId];
110
- if (subContext) {
111
- for (const childId of subContext) {
112
- const subKeys = state.getAllKeys(childId);
113
- for (const key of subKeys) {
114
- keys.add(key);
115
- }
116
- }
117
- }
118
-
119
- return keys;
120
- },
121
- reload(queryClient: QueryClient, contextId: number) {
122
- const state = get();
123
-
124
- const keys = state.getAllKeys(contextId);
125
- return queryClient.refetchQueries({
126
- predicate: (query) => keys.has(query.queryHash),
127
- });
128
- },
129
- addSubContext(parent: number, child: number) {
130
- set((state) => {
131
- const newChildren = state.subContexts[parent] ?? [];
132
- newChildren.push(child);
133
- state.subContexts[parent] = newChildren;
134
- });
135
- },
136
- removeSubContext(parent: number, child: number) {
137
- set((state) => {
138
- state.subContexts[parent] = state.subContexts[parent]?.filter((id) => id !== child);
139
- });
140
- },
141
- });
142
-
143
- export const useQueriesStore = create<QueriesStoreState>()(
144
- subscribeWithSelector(
145
- immer((set, get) => ({
146
- ...initialState(),
147
- ...actionsGenerator(set, get),
148
- })),
149
- ),
150
- );
@@ -1,24 +0,0 @@
1
- import { QueriesContext } from './QueriesContext';
2
- import { useClientLayoutEffect } from '@ainias42/react-bootstrap-mobile';
3
- import { useContext, useRef } from 'react';
4
- import { useQueriesStore } from './useQueriesStore';
5
-
6
- export function useQueriesSubscribeToReload(keys: string[], isFetching: boolean, error: any) {
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>(undefined);
11
-
12
- useClientLayoutEffect(() => {
13
- id.current = setItem(contextId, id.current, {
14
- keys,
15
- error,
16
- isFetching,
17
- });
18
- // eslint-disable-next-line react-hooks/exhaustive-deps
19
- }, [contextId, error, isFetching, setItem, ...keys]);
20
-
21
- useClientLayoutEffect(() => {
22
- return () => removeItem(contextId, id.current);
23
- }, [contextId, removeItem]);
24
- }
@@ -1,9 +0,0 @@
1
- import { QueriesContext } from './QueriesContext';
2
- import { useContext } from 'react';
3
- import { useQueriesStore } from './useQueriesStore';
4
-
5
- export function useScopedQueriesIsFetching(scope: { global: boolean; subContexts: boolean }, contextId?: number) {
6
- const context = useContext(QueriesContext);
7
-
8
- return useQueriesStore((s) => s.isFetchingByScope(contextId ?? context, scope));
9
- }