@sudobility/starter_lib 0.0.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/dist/business/hooks/index.d.ts +2 -0
- package/dist/business/hooks/index.d.ts.map +1 -0
- package/dist/business/hooks/index.js +2 -0
- package/dist/business/hooks/index.js.map +1 -0
- package/dist/business/hooks/useHistoriesManager.d.ts +24 -0
- package/dist/business/hooks/useHistoriesManager.d.ts.map +1 -0
- package/dist/business/hooks/useHistoriesManager.js +88 -0
- package/dist/business/hooks/useHistoriesManager.js.map +1 -0
- package/dist/business/index.d.ts +3 -0
- package/dist/business/index.d.ts.map +1 -0
- package/dist/business/index.js +3 -0
- package/dist/business/index.js.map +1 -0
- package/dist/business/stores/historiesStore.d.ts +18 -0
- package/dist/business/stores/historiesStore.d.ts.map +1 -0
- package/dist/business/stores/historiesStore.js +73 -0
- package/dist/business/stores/historiesStore.js.map +1 -0
- package/dist/business/stores/index.d.ts +2 -0
- package/dist/business/stores/index.d.ts.map +1 -0
- package/dist/business/stores/index.js +2 -0
- package/dist/business/stores/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/business/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,GAC/B,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/business/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAGpB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { History, HistoryCreateRequest, HistoryUpdateRequest, NetworkClient, Optional } from '@sudobility/starter_types';
|
|
2
|
+
import type { FirebaseIdToken } from '@sudobility/starter_client';
|
|
3
|
+
export interface UseHistoriesManagerConfig {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
networkClient: NetworkClient;
|
|
6
|
+
userId: Optional<string>;
|
|
7
|
+
token: Optional<FirebaseIdToken>;
|
|
8
|
+
autoFetch?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface UseHistoriesManagerReturn {
|
|
11
|
+
histories: History[];
|
|
12
|
+
total: number;
|
|
13
|
+
percentage: number;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
error: Optional<string>;
|
|
16
|
+
isCached: boolean;
|
|
17
|
+
cachedAt: Optional<number>;
|
|
18
|
+
createHistory: (data: HistoryCreateRequest) => Promise<void>;
|
|
19
|
+
updateHistory: (historyId: string, data: HistoryUpdateRequest) => Promise<void>;
|
|
20
|
+
deleteHistory: (historyId: string) => Promise<void>;
|
|
21
|
+
refresh: () => void;
|
|
22
|
+
}
|
|
23
|
+
export declare const useHistoriesManager: ({ baseUrl, networkClient, userId, token, autoFetch, }: UseHistoriesManagerConfig) => UseHistoriesManagerReturn;
|
|
24
|
+
//# sourceMappingURL=useHistoriesManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHistoriesManager.d.ts","sourceRoot":"","sources":["../../../src/business/hooks/useHistoriesManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EACP,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,QAAQ,EACT,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAQlE,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACzB,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,OAAO,EAAE,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3B,aAAa,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,aAAa,EAAE,CACb,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,oBAAoB,KACvB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,mBAAmB,GAAI,uDAMjC,yBAAyB,KAAG,yBAiJ9B,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { useHistories, useHistoriesTotal, useHistoryMutations, } from '@sudobility/starter_client';
|
|
3
|
+
import { useHistoriesStore } from '../stores/historiesStore';
|
|
4
|
+
export const useHistoriesManager = ({ baseUrl, networkClient, userId, token, autoFetch = true, }) => {
|
|
5
|
+
const { histories: clientHistories, isLoading: historiesLoading, error: historiesError, refetch, } = useHistories(networkClient, baseUrl, userId ?? null, token ?? null);
|
|
6
|
+
const { total, isLoading: totalLoading, error: totalError, } = useHistoriesTotal(networkClient, baseUrl);
|
|
7
|
+
const { createHistory: clientCreate, updateHistory: clientUpdate, deleteHistory: clientDelete, isCreating, isUpdating, isDeleting, error: mutationError, } = useHistoryMutations(networkClient, baseUrl, userId ?? null, token ?? null);
|
|
8
|
+
const cacheEntry = useHistoriesStore(useCallback(state => (userId ? state.cache[userId] : undefined), [userId]));
|
|
9
|
+
const setHistories = useHistoriesStore(state => state.setHistories);
|
|
10
|
+
const addHistoryToStore = useHistoriesStore(state => state.addHistory);
|
|
11
|
+
const updateHistoryInStore = useHistoriesStore(state => state.updateHistory);
|
|
12
|
+
const removeHistoryFromStore = useHistoriesStore(state => state.removeHistory);
|
|
13
|
+
const cachedHistories = cacheEntry?.histories;
|
|
14
|
+
const cachedAt = cacheEntry?.cachedAt;
|
|
15
|
+
const histories = useMemo(() => clientHistories.length > 0 ? clientHistories : (cachedHistories ?? []), [clientHistories, cachedHistories]);
|
|
16
|
+
const isCached = clientHistories.length === 0 && (cachedHistories?.length ?? 0) > 0;
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (clientHistories.length > 0 && userId) {
|
|
19
|
+
setHistories(userId, clientHistories);
|
|
20
|
+
}
|
|
21
|
+
}, [clientHistories, userId, setHistories]);
|
|
22
|
+
const percentage = useMemo(() => {
|
|
23
|
+
if (total <= 0)
|
|
24
|
+
return 0;
|
|
25
|
+
const userSum = histories.reduce((sum, h) => sum + h.value, 0);
|
|
26
|
+
return (userSum / total) * 100;
|
|
27
|
+
}, [histories, total]);
|
|
28
|
+
const createHistory = useCallback(async (data) => {
|
|
29
|
+
const response = await clientCreate(data);
|
|
30
|
+
if (response.success && response.data && userId) {
|
|
31
|
+
addHistoryToStore(userId, response.data);
|
|
32
|
+
}
|
|
33
|
+
}, [clientCreate, userId, addHistoryToStore]);
|
|
34
|
+
const updateHistory = useCallback(async (historyId, data) => {
|
|
35
|
+
const response = await clientUpdate(historyId, data);
|
|
36
|
+
if (response.success && response.data && userId) {
|
|
37
|
+
updateHistoryInStore(userId, historyId, response.data);
|
|
38
|
+
}
|
|
39
|
+
}, [clientUpdate, userId, updateHistoryInStore]);
|
|
40
|
+
const deleteHistory = useCallback(async (historyId) => {
|
|
41
|
+
const response = await clientDelete(historyId);
|
|
42
|
+
if (response.success && userId) {
|
|
43
|
+
removeHistoryFromStore(userId, historyId);
|
|
44
|
+
}
|
|
45
|
+
}, [clientDelete, userId, removeHistoryFromStore]);
|
|
46
|
+
const isLoading = historiesLoading || totalLoading || isCreating || isUpdating || isDeleting;
|
|
47
|
+
const error = historiesError ?? totalError ?? mutationError ?? null;
|
|
48
|
+
const hasAttemptedFetchRef = useRef(false);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (autoFetch &&
|
|
51
|
+
token &&
|
|
52
|
+
userId &&
|
|
53
|
+
histories.length === 0 &&
|
|
54
|
+
!hasAttemptedFetchRef.current) {
|
|
55
|
+
hasAttemptedFetchRef.current = true;
|
|
56
|
+
refetch();
|
|
57
|
+
}
|
|
58
|
+
}, [autoFetch, token, userId, histories.length, refetch]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
hasAttemptedFetchRef.current = false;
|
|
61
|
+
}, [token]);
|
|
62
|
+
return useMemo(() => ({
|
|
63
|
+
histories,
|
|
64
|
+
total,
|
|
65
|
+
percentage,
|
|
66
|
+
isLoading,
|
|
67
|
+
error,
|
|
68
|
+
isCached,
|
|
69
|
+
cachedAt: cachedAt ?? null,
|
|
70
|
+
createHistory,
|
|
71
|
+
updateHistory,
|
|
72
|
+
deleteHistory,
|
|
73
|
+
refresh: refetch,
|
|
74
|
+
}), [
|
|
75
|
+
histories,
|
|
76
|
+
total,
|
|
77
|
+
percentage,
|
|
78
|
+
isLoading,
|
|
79
|
+
error,
|
|
80
|
+
isCached,
|
|
81
|
+
cachedAt,
|
|
82
|
+
createHistory,
|
|
83
|
+
updateHistory,
|
|
84
|
+
deleteHistory,
|
|
85
|
+
refetch,
|
|
86
|
+
]);
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=useHistoriesManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHistoriesManager.js","sourceRoot":"","sources":["../../../src/business/hooks/useHistoriesManager.ts"],"names":[],"mappings":"AAAA,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UAAU,CAAC;IAC7E,MAAM,KAAK,GAAG,cAAc,IAAI,UAAU,IAAI,aAAa,IAAI,IAAI,CAAC;IAEpE,MAAM,oBAAoB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE3C,SAAS,CAAC,GAAG,EAAE;QACb,IACE,SAAS;YACT,KAAK;YACL,MAAM;YACN,SAAS,CAAC,MAAM,KAAK,CAAC;YACtB,CAAC,oBAAoB,CAAC,OAAO,EAC7B,CAAC;YACD,oBAAoB,CAAC,OAAO,GAAG,IAAI,CAAC;YACpC,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAE1D,SAAS,CAAC,GAAG,EAAE;QACb,oBAAoB,CAAC,OAAO,GAAG,KAAK,CAAC;IACvC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,SAAS;QACT,KAAK;QACL,UAAU;QACV,SAAS;QACT,KAAK;QACL,QAAQ;QACR,QAAQ,EAAE,QAAQ,IAAI,IAAI;QAC1B,aAAa;QACb,aAAa;QACb,aAAa;QACb,OAAO,EAAE,OAAO;KACjB,CAAC,EACF;QACE,SAAS;QACT,KAAK;QACL,UAAU;QACV,SAAS;QACT,KAAK;QACL,QAAQ;QACR,QAAQ;QACR,aAAa;QACb,aAAa;QACb,aAAa;QACb,OAAO;KACR,CACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/business/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/business/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { History } from '@sudobility/starter_types';
|
|
2
|
+
interface HistoriesCacheEntry {
|
|
3
|
+
histories: History[];
|
|
4
|
+
cachedAt: number;
|
|
5
|
+
}
|
|
6
|
+
interface HistoriesStoreState {
|
|
7
|
+
cache: Record<string, HistoriesCacheEntry>;
|
|
8
|
+
setHistories: (userId: string, histories: History[]) => void;
|
|
9
|
+
getHistories: (userId: string) => History[] | undefined;
|
|
10
|
+
getCacheEntry: (userId: string) => HistoriesCacheEntry | undefined;
|
|
11
|
+
addHistory: (userId: string, history: History) => void;
|
|
12
|
+
updateHistory: (userId: string, historyId: string, history: History) => void;
|
|
13
|
+
removeHistory: (userId: string, historyId: string) => void;
|
|
14
|
+
clearAll: () => void;
|
|
15
|
+
}
|
|
16
|
+
export declare const useHistoriesStore: import("zustand").UseBoundStore<import("zustand").StoreApi<HistoriesStoreState>>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=historiesStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"historiesStore.d.ts","sourceRoot":"","sources":["../../../src/business/stores/historiesStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD,UAAU,mBAAmB;IAC3B,SAAS,EAAE,OAAO,EAAE,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,mBAAmB;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC3C,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC7D,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,EAAE,GAAG,SAAS,CAAC;IACxD,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,mBAAmB,GAAG,SAAS,CAAC;IACnE,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvD,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7E,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,iBAAiB,kFAiF3B,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
export const useHistoriesStore = create((set, get) => ({
|
|
3
|
+
cache: {},
|
|
4
|
+
setHistories: (userId, histories) => set(state => ({
|
|
5
|
+
cache: {
|
|
6
|
+
...state.cache,
|
|
7
|
+
[userId]: {
|
|
8
|
+
histories,
|
|
9
|
+
cachedAt: Date.now(),
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
})),
|
|
13
|
+
getHistories: (userId) => {
|
|
14
|
+
const entry = get().cache[userId];
|
|
15
|
+
return entry?.histories;
|
|
16
|
+
},
|
|
17
|
+
getCacheEntry: (userId) => {
|
|
18
|
+
return get().cache[userId];
|
|
19
|
+
},
|
|
20
|
+
addHistory: (userId, history) => set(state => {
|
|
21
|
+
const existing = state.cache[userId];
|
|
22
|
+
if (!existing) {
|
|
23
|
+
return {
|
|
24
|
+
cache: {
|
|
25
|
+
...state.cache,
|
|
26
|
+
[userId]: {
|
|
27
|
+
histories: [history],
|
|
28
|
+
cachedAt: Date.now(),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
cache: {
|
|
35
|
+
...state.cache,
|
|
36
|
+
[userId]: {
|
|
37
|
+
histories: [...existing.histories, history],
|
|
38
|
+
cachedAt: Date.now(),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}),
|
|
43
|
+
updateHistory: (userId, historyId, history) => set(state => {
|
|
44
|
+
const existing = state.cache[userId];
|
|
45
|
+
if (!existing)
|
|
46
|
+
return state;
|
|
47
|
+
return {
|
|
48
|
+
cache: {
|
|
49
|
+
...state.cache,
|
|
50
|
+
[userId]: {
|
|
51
|
+
histories: existing.histories.map(h => h.id === historyId ? history : h),
|
|
52
|
+
cachedAt: Date.now(),
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
removeHistory: (userId, historyId) => set(state => {
|
|
58
|
+
const existing = state.cache[userId];
|
|
59
|
+
if (!existing)
|
|
60
|
+
return state;
|
|
61
|
+
return {
|
|
62
|
+
cache: {
|
|
63
|
+
...state.cache,
|
|
64
|
+
[userId]: {
|
|
65
|
+
histories: existing.histories.filter(h => h.id !== historyId),
|
|
66
|
+
cachedAt: Date.now(),
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}),
|
|
71
|
+
clearAll: () => set({ cache: {} }),
|
|
72
|
+
}));
|
|
73
|
+
//# sourceMappingURL=historiesStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"historiesStore.js","sourceRoot":"","sources":["../../../src/business/stores/historiesStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAmBjC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IAC1E,KAAK,EAAE,EAAE;IAET,YAAY,EAAE,CAAC,MAAc,EAAE,SAAoB,EAAE,EAAE,CACrD,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACZ,KAAK,EAAE;YACL,GAAG,KAAK,CAAC,KAAK;YACd,CAAC,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KAAK,CAAC;QAC5B,OAAO;YACL,KAAK,EAAE;gBACL,GAAG,KAAK,CAAC,KAAK;gBACd,CAAC,MAAM,CAAC,EAAE;oBACR,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACpC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CACjC;oBACD,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE;iBACrB;aACF;SACF,CAAC;IACJ,CAAC,CAAC;IAEJ,aAAa,EAAE,CAAC,MAAc,EAAE,SAAiB,EAAE,EAAE,CACnD,GAAG,CAAC,KAAK,CAAC,EAAE;QACV,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC5B,OAAO;YACL,KAAK,EAAE;gBACL,GAAG,KAAK,CAAC,KAAK;gBACd,CAAC,MAAM,CAAC,EAAE;oBACR,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC;oBAC7D,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE;iBACrB;aACF;SACF,CAAC;IACJ,CAAC,CAAC;IAEJ,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;CACnC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/business/stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/business/stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sudobility/starter_lib",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Business logic library for Starter with Zustand stores",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "restricted"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**/*"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "bunx tsc -p tsconfig.build.json",
|
|
16
|
+
"build:watch": "bunx tsc --watch",
|
|
17
|
+
"clean": "rm -rf dist",
|
|
18
|
+
"prepublishOnly": "bun run clean && bun run build",
|
|
19
|
+
"typecheck": "bunx tsc --noEmit",
|
|
20
|
+
"lint": "bunx eslint src/",
|
|
21
|
+
"lint:fix": "bunx eslint src/ --fix",
|
|
22
|
+
"format": "bunx prettier --write \"src/**/*.ts\"",
|
|
23
|
+
"format:check": "bunx prettier --check \"src/**/*.ts\"",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"verify": "bun run typecheck && bun run lint && bun run test && bun run build"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"starter",
|
|
30
|
+
"business-logic",
|
|
31
|
+
"zustand",
|
|
32
|
+
"react",
|
|
33
|
+
"typescript"
|
|
34
|
+
],
|
|
35
|
+
"author": "Sudobility",
|
|
36
|
+
"license": "BUSL-1.1",
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@sudobility/types": "^1.9.50",
|
|
39
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
40
|
+
"react": ">=18.0.0",
|
|
41
|
+
"zustand": ">=5.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@sudobility/starter_client": "^0.0.1",
|
|
45
|
+
"@sudobility/starter_types": "^0.0.1",
|
|
46
|
+
"@sudobility/types": "^1.9.50",
|
|
47
|
+
"@tanstack/react-query": "^5.90.5",
|
|
48
|
+
"@types/react": "^19.2.2",
|
|
49
|
+
"react": "^19.2.1",
|
|
50
|
+
"zustand": "^5.0.8",
|
|
51
|
+
"@eslint/js": "^9.38.0",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
53
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
54
|
+
"eslint": "^9.39.2",
|
|
55
|
+
"eslint-config-prettier": "^10.1.5",
|
|
56
|
+
"eslint-plugin-prettier": "^5.4.1",
|
|
57
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
58
|
+
"globals": "^16.4.0",
|
|
59
|
+
"prettier": "^3.7.4",
|
|
60
|
+
"typescript": "~5.9.3",
|
|
61
|
+
"vitest": "^4.0.15"
|
|
62
|
+
}
|
|
63
|
+
}
|