@htlkg/data 0.0.20 → 0.0.22

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 (69) hide show
  1. package/dist/hooks/index.d.ts +659 -66
  2. package/dist/hooks/index.js +711 -42
  3. package/dist/hooks/index.js.map +1 -1
  4. package/dist/index.d.ts +4 -3
  5. package/dist/index.js +1098 -51
  6. package/dist/index.js.map +1 -1
  7. package/dist/mutations/index.d.ts +338 -2
  8. package/dist/mutations/index.js +290 -4
  9. package/dist/mutations/index.js.map +1 -1
  10. package/dist/queries/index.d.ts +110 -2
  11. package/dist/queries/index.js +115 -6
  12. package/dist/queries/index.js.map +1 -1
  13. package/package.json +2 -2
  14. package/src/hooks/accounts/index.ts +2 -0
  15. package/src/hooks/{useAccounts.ts → accounts/useAccounts.ts} +48 -5
  16. package/src/hooks/accounts/usePaginatedAccounts.ts +166 -0
  17. package/src/hooks/brands/index.ts +2 -0
  18. package/src/hooks/{useBrands.ts → brands/useBrands.ts} +1 -1
  19. package/src/hooks/brands/usePaginatedBrands.ts +206 -0
  20. package/src/hooks/createPaginatedDataHook.ts +359 -0
  21. package/src/hooks/data-hook-errors.property.test.ts +4 -4
  22. package/src/hooks/data-hook-filters.property.test.ts +4 -4
  23. package/src/hooks/data-hooks.property.test.ts +4 -4
  24. package/src/hooks/index.ts +96 -7
  25. package/src/hooks/productInstances/index.ts +1 -0
  26. package/src/hooks/{useProductInstances.ts → productInstances/useProductInstances.ts} +9 -6
  27. package/src/hooks/products/index.ts +1 -0
  28. package/src/hooks/{useProducts.ts → products/useProducts.ts} +4 -5
  29. package/src/hooks/reservations/index.ts +2 -0
  30. package/src/hooks/reservations/usePaginatedReservations.ts +258 -0
  31. package/src/hooks/{useReservations.ts → reservations/useReservations.ts} +65 -10
  32. package/src/hooks/useContacts.test.ts +159 -0
  33. package/src/hooks/useContacts.ts +176 -0
  34. package/src/hooks/users/index.ts +2 -0
  35. package/src/hooks/users/usePaginatedUsers.ts +213 -0
  36. package/src/hooks/{useUsers.ts → users/useUsers.ts} +1 -1
  37. package/src/mutations/accounts/accounts.test.ts +287 -0
  38. package/src/mutations/{accounts.ts → accounts/accounts.ts} +2 -2
  39. package/src/mutations/accounts/index.ts +1 -0
  40. package/src/mutations/brands/brands.test.ts +292 -0
  41. package/src/mutations/{brands.ts → brands/brands.ts} +2 -2
  42. package/src/mutations/brands/index.ts +1 -0
  43. package/src/mutations/contacts.test.ts +604 -0
  44. package/src/mutations/contacts.ts +554 -0
  45. package/src/mutations/index.ts +18 -0
  46. package/src/mutations/reservations/index.ts +1 -0
  47. package/src/mutations/{reservations.test.ts → reservations/reservations.test.ts} +1 -1
  48. package/src/mutations/{reservations.ts → reservations/reservations.ts} +2 -2
  49. package/src/mutations/users/index.ts +1 -0
  50. package/src/mutations/users/users.test.ts +289 -0
  51. package/src/mutations/{users.ts → users/users.ts} +2 -2
  52. package/src/queries/accounts/accounts.test.ts +228 -0
  53. package/src/queries/accounts/index.ts +1 -0
  54. package/src/queries/brands/brands.test.ts +288 -0
  55. package/src/queries/brands/index.ts +1 -0
  56. package/src/queries/contacts.test.ts +505 -0
  57. package/src/queries/contacts.ts +237 -0
  58. package/src/queries/index.ts +10 -0
  59. package/src/queries/products/index.ts +1 -0
  60. package/src/queries/products/products.test.ts +347 -0
  61. package/src/queries/reservations/index.ts +1 -0
  62. package/src/queries/users/index.ts +1 -0
  63. package/src/queries/users/users.test.ts +301 -0
  64. /package/src/queries/{accounts.ts → accounts/accounts.ts} +0 -0
  65. /package/src/queries/{brands.ts → brands/brands.ts} +0 -0
  66. /package/src/queries/{products.ts → products/products.ts} +0 -0
  67. /package/src/queries/{reservations.test.ts → reservations/reservations.test.ts} +0 -0
  68. /package/src/queries/{reservations.ts → reservations/reservations.ts} +0 -0
  69. /package/src/queries/{users.ts → users/users.ts} +0 -0
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Paginated Accounts Hooks
3
+ *
4
+ * Vue composables for fetching accounts with server-side pagination.
5
+ * Provides separate hooks for active and deleted accounts to enable
6
+ * efficient tab-based filtering in large datasets.
7
+ */
8
+
9
+ import type { Ref, ComputedRef } from "vue";
10
+ import {
11
+ createPaginatedDataHook,
12
+ ACTIVE_FILTER,
13
+ DELETED_FILTER,
14
+ type PaginatedHookOptions,
15
+ type PaginationState,
16
+ } from "../createPaginatedDataHook";
17
+ import type { AccountWithBrands } from "./useAccounts";
18
+
19
+ export interface UsePaginatedAccountsOptions extends PaginatedHookOptions {
20
+ // Add any account-specific filters here if needed
21
+ }
22
+
23
+ export interface UsePaginatedAccountsReturn {
24
+ /** Reactive array of accounts with brands */
25
+ accounts: Ref<AccountWithBrands[]>;
26
+ /** Loading state (true during any fetch) */
27
+ loading: Ref<boolean>;
28
+ /** Loading state for initial fetch */
29
+ initialLoading: Ref<boolean>;
30
+ /** Loading state for loadMore */
31
+ loadingMore: Ref<boolean>;
32
+ /** Error state */
33
+ error: Ref<Error | null>;
34
+ /** Pagination state */
35
+ pagination: Ref<PaginationState>;
36
+ /** Whether there are more items to load */
37
+ hasMore: ComputedRef<boolean>;
38
+ /** Load next page of data */
39
+ loadMore: () => Promise<void>;
40
+ /** Refetch data (resets to first page) */
41
+ refetch: () => Promise<void>;
42
+ /** Reset data and pagination state */
43
+ reset: () => void;
44
+ /** Update search filter and refetch from server (searches ALL data) */
45
+ setSearchFilter: (filter: any) => Promise<void>;
46
+ /** Current search filter */
47
+ searchFilter: Ref<any>;
48
+ }
49
+
50
+ /**
51
+ * Transform account data to include brandCount
52
+ */
53
+ function transformAccount(account: any): AccountWithBrands {
54
+ const brands = account.brands || [];
55
+ return {
56
+ ...account,
57
+ brands,
58
+ brandCount: brands.length,
59
+ };
60
+ }
61
+
62
+ /**
63
+ * Selection set for account queries
64
+ */
65
+ const ACCOUNT_SELECTION_SET = [
66
+ "id",
67
+ "name",
68
+ "logo",
69
+ "subscription",
70
+ "settings",
71
+ "status",
72
+ "deletedAt",
73
+ "deletedBy",
74
+ "brands.id",
75
+ "brands.name",
76
+ "brands.status",
77
+ ];
78
+
79
+ /**
80
+ * Internal hook for active accounts
81
+ */
82
+ const useActiveAccountsInternal = createPaginatedDataHook<AccountWithBrands, UsePaginatedAccountsOptions>({
83
+ model: "Account",
84
+ dataPropertyName: "accounts",
85
+ defaultPageSize: 25,
86
+ selectionSet: ACCOUNT_SELECTION_SET,
87
+ transform: transformAccount,
88
+ baseFilter: ACTIVE_FILTER,
89
+ });
90
+
91
+ /**
92
+ * Internal hook for deleted accounts
93
+ */
94
+ const useDeletedAccountsInternal = createPaginatedDataHook<AccountWithBrands, UsePaginatedAccountsOptions>({
95
+ model: "Account",
96
+ dataPropertyName: "accounts",
97
+ defaultPageSize: 25,
98
+ selectionSet: ACCOUNT_SELECTION_SET,
99
+ transform: transformAccount,
100
+ baseFilter: DELETED_FILTER,
101
+ });
102
+
103
+ /**
104
+ * Composable for fetching active (non-deleted) accounts with pagination
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * import { useActiveAccounts } from '@htlkg/data/hooks';
109
+ *
110
+ * const { accounts, loading, hasMore, loadMore, refetch } = useActiveAccounts({
111
+ * pageSize: 25,
112
+ * });
113
+ *
114
+ * // Load more when user scrolls or clicks "Load More"
115
+ * async function onLoadMore() {
116
+ * await loadMore();
117
+ * }
118
+ * ```
119
+ */
120
+ export function useActiveAccounts(options: UsePaginatedAccountsOptions = {}): UsePaginatedAccountsReturn {
121
+ const result = useActiveAccountsInternal(options);
122
+ return {
123
+ accounts: result.accounts as Ref<AccountWithBrands[]>,
124
+ loading: result.loading,
125
+ initialLoading: result.initialLoading,
126
+ loadingMore: result.loadingMore,
127
+ error: result.error,
128
+ pagination: result.pagination,
129
+ hasMore: result.hasMore,
130
+ loadMore: result.loadMore,
131
+ refetch: result.refetch,
132
+ reset: result.reset,
133
+ setSearchFilter: result.setSearchFilter,
134
+ searchFilter: result.searchFilter,
135
+ };
136
+ }
137
+
138
+ /**
139
+ * Composable for fetching deleted accounts with pagination
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * import { useDeletedAccounts } from '@htlkg/data/hooks';
144
+ *
145
+ * const { accounts, loading, hasMore, loadMore, refetch } = useDeletedAccounts({
146
+ * pageSize: 25,
147
+ * });
148
+ * ```
149
+ */
150
+ export function useDeletedAccounts(options: UsePaginatedAccountsOptions = {}): UsePaginatedAccountsReturn {
151
+ const result = useDeletedAccountsInternal(options);
152
+ return {
153
+ accounts: result.accounts as Ref<AccountWithBrands[]>,
154
+ loading: result.loading,
155
+ initialLoading: result.initialLoading,
156
+ loadingMore: result.loadingMore,
157
+ error: result.error,
158
+ pagination: result.pagination,
159
+ hasMore: result.hasMore,
160
+ loadMore: result.loadMore,
161
+ refetch: result.refetch,
162
+ reset: result.reset,
163
+ setSearchFilter: result.setSearchFilter,
164
+ searchFilter: result.searchFilter,
165
+ };
166
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./useBrands";
2
+ export * from "./usePaginatedBrands";
@@ -7,7 +7,7 @@
7
7
 
8
8
  import type { Ref, ComputedRef } from "vue";
9
9
  import type { Brand } from "@htlkg/core/types";
10
- import { createDataHook, type BaseHookOptions } from "./createDataHook";
10
+ import { createDataHook, type BaseHookOptions } from "../createDataHook";
11
11
 
12
12
  export interface UseBrandsOptions extends BaseHookOptions {
13
13
  /** Filter criteria for brands */
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Paginated Brands Hooks
3
+ *
4
+ * Vue composables for fetching brands with server-side pagination.
5
+ * Provides separate hooks for active and deleted brands to enable
6
+ * efficient tab-based filtering in large datasets.
7
+ */
8
+
9
+ import type { Ref, ComputedRef } from "vue";
10
+ import type { Brand } from "@htlkg/core/types";
11
+ import {
12
+ createPaginatedDataHook,
13
+ ACTIVE_FILTER,
14
+ DELETED_FILTER,
15
+ type PaginatedHookOptions,
16
+ type PaginationState,
17
+ } from "../createPaginatedDataHook";
18
+
19
+ /** Extended Brand type with computed fields */
20
+ export type BrandWithCounts = Brand & {
21
+ accountName?: string;
22
+ enabledProductCount?: number;
23
+ totalProductCount?: number;
24
+ deletedAt?: string;
25
+ deletedBy?: string;
26
+ };
27
+
28
+ export interface UsePaginatedBrandsOptions extends PaginatedHookOptions {
29
+ /** Filter by account ID */
30
+ accountId?: string;
31
+ }
32
+
33
+ export interface UsePaginatedBrandsReturn {
34
+ /** Reactive array of brands */
35
+ brands: Ref<BrandWithCounts[]>;
36
+ /** Loading state (true during any fetch) */
37
+ loading: Ref<boolean>;
38
+ /** Loading state for initial fetch */
39
+ initialLoading: Ref<boolean>;
40
+ /** Loading state for loadMore */
41
+ loadingMore: Ref<boolean>;
42
+ /** Error state */
43
+ error: Ref<Error | null>;
44
+ /** Pagination state */
45
+ pagination: Ref<PaginationState>;
46
+ /** Whether there are more items to load */
47
+ hasMore: ComputedRef<boolean>;
48
+ /** Load next page of data */
49
+ loadMore: () => Promise<void>;
50
+ /** Refetch data (resets to first page) */
51
+ refetch: () => Promise<void>;
52
+ /** Reset data and pagination state */
53
+ reset: () => void;
54
+ /** Update search filter and refetch from server (searches ALL data) */
55
+ setSearchFilter: (filter: any) => Promise<void>;
56
+ /** Current search filter */
57
+ searchFilter: Ref<any>;
58
+ }
59
+
60
+ /**
61
+ * Build additional filter from hook options
62
+ */
63
+ function buildFilter(options: UsePaginatedBrandsOptions): any {
64
+ const conditions: any[] = [];
65
+
66
+ if (options.accountId) {
67
+ conditions.push({ accountId: { eq: options.accountId } });
68
+ }
69
+
70
+ if (options.filter && Object.keys(options.filter).length > 0) {
71
+ conditions.push(options.filter);
72
+ }
73
+
74
+ if (conditions.length === 0) {
75
+ return undefined;
76
+ }
77
+ if (conditions.length === 1) {
78
+ return conditions[0];
79
+ }
80
+ return { and: conditions };
81
+ }
82
+
83
+ /**
84
+ * Transform brand data
85
+ */
86
+ function transformBrand(brand: any): BrandWithCounts {
87
+ return {
88
+ ...brand,
89
+ accountName: brand.account?.name || "",
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Selection set for brand queries
95
+ */
96
+ const BRAND_SELECTION_SET = [
97
+ "id",
98
+ "name",
99
+ "accountId",
100
+ "logo",
101
+ "timezone",
102
+ "status",
103
+ "settings",
104
+ "deletedAt",
105
+ "deletedBy",
106
+ "account.name",
107
+ ];
108
+
109
+ /**
110
+ * Internal hook for active brands
111
+ */
112
+ const useActiveBrandsInternal = createPaginatedDataHook<BrandWithCounts, UsePaginatedBrandsOptions>({
113
+ model: "Brand",
114
+ dataPropertyName: "brands",
115
+ defaultPageSize: 25,
116
+ selectionSet: BRAND_SELECTION_SET,
117
+ transform: transformBrand,
118
+ buildFilter,
119
+ baseFilter: ACTIVE_FILTER,
120
+ });
121
+
122
+ /**
123
+ * Internal hook for deleted brands
124
+ */
125
+ const useDeletedBrandsInternal = createPaginatedDataHook<BrandWithCounts, UsePaginatedBrandsOptions>({
126
+ model: "Brand",
127
+ dataPropertyName: "brands",
128
+ defaultPageSize: 25,
129
+ selectionSet: BRAND_SELECTION_SET,
130
+ transform: transformBrand,
131
+ buildFilter,
132
+ baseFilter: DELETED_FILTER,
133
+ });
134
+
135
+ /**
136
+ * Composable for fetching active (non-deleted) brands with pagination
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * import { useActiveBrands } from '@htlkg/data/hooks';
141
+ *
142
+ * const { brands, loading, hasMore, loadMore, refetch } = useActiveBrands({
143
+ * pageSize: 25,
144
+ * });
145
+ *
146
+ * // Load more when user scrolls or clicks "Load More"
147
+ * async function onLoadMore() {
148
+ * await loadMore();
149
+ * }
150
+ * ```
151
+ *
152
+ * @example With account filter
153
+ * ```typescript
154
+ * const { brands, loading } = useActiveBrands({
155
+ * accountId: 'account-123',
156
+ * pageSize: 50
157
+ * });
158
+ * ```
159
+ */
160
+ export function useActiveBrands(options: UsePaginatedBrandsOptions = {}): UsePaginatedBrandsReturn {
161
+ const result = useActiveBrandsInternal(options);
162
+ return {
163
+ brands: result.brands as Ref<BrandWithCounts[]>,
164
+ loading: result.loading,
165
+ initialLoading: result.initialLoading,
166
+ loadingMore: result.loadingMore,
167
+ error: result.error,
168
+ pagination: result.pagination,
169
+ hasMore: result.hasMore,
170
+ loadMore: result.loadMore,
171
+ refetch: result.refetch,
172
+ reset: result.reset,
173
+ setSearchFilter: result.setSearchFilter,
174
+ searchFilter: result.searchFilter,
175
+ };
176
+ }
177
+
178
+ /**
179
+ * Composable for fetching deleted brands with pagination
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * import { useDeletedBrands } from '@htlkg/data/hooks';
184
+ *
185
+ * const { brands, loading, hasMore, loadMore, refetch } = useDeletedBrands({
186
+ * pageSize: 25,
187
+ * });
188
+ * ```
189
+ */
190
+ export function useDeletedBrands(options: UsePaginatedBrandsOptions = {}): UsePaginatedBrandsReturn {
191
+ const result = useDeletedBrandsInternal(options);
192
+ return {
193
+ brands: result.brands as Ref<BrandWithCounts[]>,
194
+ loading: result.loading,
195
+ initialLoading: result.initialLoading,
196
+ loadingMore: result.loadingMore,
197
+ error: result.error,
198
+ pagination: result.pagination,
199
+ hasMore: result.hasMore,
200
+ loadMore: result.loadMore,
201
+ refetch: result.refetch,
202
+ reset: result.reset,
203
+ setSearchFilter: result.setSearchFilter,
204
+ searchFilter: result.searchFilter,
205
+ };
206
+ }