@temboplus/tembo-dashboard 0.0.7 → 0.0.9

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.
@@ -1,10 +1,16 @@
1
1
  import { BaseRepository, PaginationDTO, WalletSummaryDTO } from "@/lib/api";
2
2
  import { collectionContract } from "./collection.api-contract";
3
- import { type CollectionQueryParamsDTO } from "./collection.dtos";
4
3
  import { Collection } from "./collection.model";
4
+ import { CollectionQueryBuilder } from "./collection.query-builder";
5
+ import { CollectionQueryParams } from "./collection.query-params.model";
6
+ /**
7
+ * Flexible query input type - supports the class, DTO, URL params, etc.
8
+ */
9
+ export type CollectionQueryInput = CollectionQueryParams | Parameters<typeof CollectionQueryParams.from>[0];
5
10
  /**
6
11
  * Repository class for managing collections through API interactions.
7
12
  * Handles collection operations, filtering, and summary data retrieval.
13
+ * Supports flexible query input types including URL search parameters and typed DTOs.
8
14
  */
9
15
  export declare class CollectionRepository extends BaseRepository<typeof collectionContract> {
10
16
  constructor(options?: {
@@ -12,9 +18,78 @@ export declare class CollectionRepository extends BaseRepository<typeof collecti
12
18
  root?: string;
13
19
  });
14
20
  /**
15
- * Get all collections with filtering and pagination
21
+ * Normalize query input to CollectionQueryParams class instance
22
+ * @param query - Any supported query input type
23
+ * @returns CollectionQueryParams instance
24
+ * @throws Error if validation fails
25
+ */
26
+ private normalizeQueryParams;
27
+ /**
28
+ * Get all collections with filtering and pagination.
29
+ * Supports flexible input types: typed DTO, URL search params, or string records.
30
+ *
31
+ * @param query - Query parameters in any supported format
32
+ * @returns Promise resolving to collections and pagination info
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // From API route with URL search params
37
+ * const { searchParams } = new URL(req.url);
38
+ * const stringParams = Object.fromEntries(searchParams.entries());
39
+ * const result = await repo.getCollections(stringParams);
40
+ *
41
+ * // From client with typed params
42
+ * const typedParams: CollectionQueryParamsDTO = { page: 1, limit: 20, status: 'PAYMENT_ACCEPTED' };
43
+ * const result2 = await repo.getCollections(typedParams);
44
+ *
45
+ * // With URLSearchParams directly
46
+ * const urlParams = new URLSearchParams(window.location.search);
47
+ * const result3 = await repo.getCollections(urlParams);
48
+ * ```
49
+ */
50
+ getCollections(query?: CollectionQueryInput): Promise<{
51
+ collections: Collection[];
52
+ pagination: PaginationDTO;
53
+ }>;
54
+ /**
55
+ * Convenience method to get collections from URL search params directly.
56
+ * Useful in API routes where you have direct access to search params.
57
+ *
58
+ * @param searchParams - URLSearchParams from request
59
+ * @returns Promise resolving to collections and pagination info
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * // In API route
64
+ * export async function GET(req: Request) {
65
+ * const { searchParams } = new URL(req.url);
66
+ * const repo = new CollectionRepository({ token });
67
+ * return repo.getCollectionsFromSearchParams(searchParams);
68
+ * }
69
+ * ```
70
+ */
71
+ getCollectionsFromSearchParams(searchParams: URLSearchParams): Promise<{
72
+ collections: Collection[];
73
+ pagination: PaginationDTO;
74
+ }>;
75
+ /**
76
+ * Convenience method to get collections from Next.js Request object.
77
+ * Extracts and processes search params automatically.
78
+ *
79
+ * @param req - Next.js Request object
80
+ * @returns Promise resolving to collections and pagination info
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * // In API route
85
+ * export async function GET(req: Request) {
86
+ * const repo = new CollectionRepository({ token });
87
+ * const result = await repo.getCollectionsFromRequest(req);
88
+ * return NextResponse.json(result);
89
+ * }
90
+ * ```
16
91
  */
17
- getCollections(query?: CollectionQueryParamsDTO): Promise<{
92
+ getCollectionsFromRequest(req: Request): Promise<{
18
93
  collections: Collection[];
19
94
  pagination: PaginationDTO;
20
95
  }>;
@@ -35,4 +110,40 @@ export declare class CollectionRepository extends BaseRepository<typeof collecti
35
110
  * Get account balance and summary information
36
111
  */
37
112
  getBalance(): Promise<WalletSummaryDTO>;
113
+ /**
114
+ * Build a query using the fluent query builder interface
115
+ * Returns a query builder instance for complex filtering scenarios.
116
+ *
117
+ * @returns CollectionQueryBuilder instance for method chaining
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * const collections = await repo.query()
122
+ * .whereSuccessful()
123
+ * .whereAmountBetween(100, 1000)
124
+ * .whereDateBetween('2024-01-01', '2024-01-31')
125
+ * .orderByDesc('amount')
126
+ * .paginate(1, 50)
127
+ * .execute(repo);
128
+ * ```
129
+ */
130
+ query(): CollectionQueryBuilderWithExecute;
131
+ }
132
+ /**
133
+ * Extended query builder that includes execute method for direct repository integration
134
+ */
135
+ declare class CollectionQueryBuilderWithExecute extends CollectionQueryBuilder {
136
+ private builder;
137
+ private repository;
138
+ constructor(builder: CollectionQueryBuilder, repository: CollectionRepository);
139
+ /**
140
+ * Execute the query and return results
141
+ *
142
+ * @returns Promise resolving to collections and pagination info
143
+ */
144
+ execute(): Promise<{
145
+ collections: Collection[];
146
+ pagination: PaginationDTO;
147
+ }>;
38
148
  }
149
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temboplus/tembo-dashboard",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "A foundational library for Temboplus-Dashboard projects providing type-safe data layer abstraction with API contracts, domain models, and repositories.",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",