@tspvivek/baasix-sdk 0.1.0-alpha.3 → 0.1.0-alpha.5

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/README.md CHANGED
@@ -451,15 +451,54 @@ await baasix.schemas.create({
451
451
  primaryKey: true,
452
452
  defaultValue: { type: 'UUIDV4' },
453
453
  },
454
+ sku: {
455
+ type: 'SUID',
456
+ unique: true,
457
+ defaultValue: { type: 'SUID' },
458
+ },
454
459
  name: {
455
460
  type: 'String',
456
461
  allowNull: false,
457
462
  values: { length: 255 },
463
+ validate: {
464
+ notEmpty: true,
465
+ len: [3, 255],
466
+ },
458
467
  },
459
468
  price: {
460
469
  type: 'Decimal',
461
470
  values: { precision: 10, scale: 2 },
462
471
  defaultValue: 0,
472
+ validate: {
473
+ min: 0,
474
+ max: 999999.99,
475
+ },
476
+ },
477
+ quantity: {
478
+ type: 'Integer',
479
+ defaultValue: 0,
480
+ validate: {
481
+ isInt: true,
482
+ min: 0,
483
+ },
484
+ },
485
+ email: {
486
+ type: 'String',
487
+ validate: {
488
+ isEmail: true,
489
+ },
490
+ },
491
+ website: {
492
+ type: 'String',
493
+ validate: {
494
+ isUrl: true,
495
+ },
496
+ },
497
+ slug: {
498
+ type: 'String',
499
+ validate: {
500
+ matches: '^[a-z0-9-]+$',
501
+ },
463
502
  },
464
503
  tags: {
465
504
  type: 'Array',
@@ -470,11 +509,51 @@ await baasix.schemas.create({
470
509
  type: 'JSONB',
471
510
  defaultValue: {},
472
511
  },
512
+ status: {
513
+ type: 'String',
514
+ defaultValue: 'draft',
515
+ },
516
+ isActive: {
517
+ type: 'Boolean',
518
+ defaultValue: true,
519
+ },
520
+ sortOrder: {
521
+ type: 'Integer',
522
+ defaultValue: { type: 'AUTOINCREMENT' },
523
+ },
524
+ publishedAt: {
525
+ type: 'DateTime',
526
+ defaultValue: { type: 'NOW' },
527
+ },
473
528
  },
474
529
  },
475
530
  });
476
531
  ```
477
532
 
533
+ ### Validation Rules
534
+
535
+ | Rule | Type | Description |
536
+ |------|------|-------------|
537
+ | `min` | number | Minimum value for numeric fields |
538
+ | `max` | number | Maximum value for numeric fields |
539
+ | `isInt` | boolean | Validate as integer |
540
+ | `notEmpty` | boolean | String must not be empty |
541
+ | `isEmail` | boolean | Validate email format |
542
+ | `isUrl` | boolean | Validate URL format |
543
+ | `len` | [min, max] | String length range |
544
+ | `is` / `matches` | string | Pattern matching with regex |
545
+
546
+ ### Default Value Types
547
+
548
+ | Type | Description |
549
+ |------|-------------|
550
+ | `UUIDV4` | Random UUID v4 |
551
+ | `SUID` | Short unique ID (compact, URL-safe) |
552
+ | `NOW` | Current timestamp |
553
+ | `AUTOINCREMENT` | Auto-incrementing integer |
554
+ | `SQL` | Custom SQL expression |
555
+ | Static | Any constant value (`"active"`, `false`, `0`) |
556
+
478
557
  ### Relationships
479
558
 
480
559
  ```typescript
@@ -507,27 +586,111 @@ await baasix.schemas.createIndex('products', {
507
586
 
508
587
  ## Reports & Analytics
509
588
 
589
+ ### Generate Report (POST)
590
+
591
+ Use `generate()` to create a report with a POST request, sending the query in the request body:
592
+
510
593
  ```typescript
511
- // Generate report
512
594
  const report = await baasix.reports.generate('orders', {
513
595
  aggregate: {
514
596
  revenue: { function: 'sum', field: 'total' },
515
597
  orders: { function: 'count', field: 'id' },
516
598
  },
517
- groupBy: 'category',
599
+ groupBy: ['category'],
518
600
  filter: { status: { eq: 'completed' } },
519
601
  dateRange: {
520
602
  start: '2025-01-01',
521
603
  end: '2025-12-31',
522
604
  },
523
605
  });
606
+ ```
607
+
608
+ ### Query Report (GET)
609
+
610
+ Use `query()` to fetch a report with a GET request, sending parameters as query strings:
611
+
612
+ ```typescript
613
+ const report = await baasix.reports.query('orders', {
614
+ aggregate: {
615
+ total: { function: 'sum', field: 'amount' },
616
+ },
617
+ groupBy: ['status'],
618
+ filter: { createdAt: { gte: '$NOW-DAYS_30' } },
619
+ });
620
+ ```
621
+
622
+ ### Multi-Collection Stats
623
+
624
+ Get statistics for multiple collections in a single request:
625
+
626
+ ```typescript
627
+ const stats = await baasix.reports.getStats([
628
+ {
629
+ name: 'total_products',
630
+ collection: 'products',
631
+ query: {
632
+ aggregate: { count: { function: 'count', field: '*' } },
633
+ },
634
+ },
635
+ {
636
+ name: 'total_orders',
637
+ collection: 'orders',
638
+ query: {
639
+ aggregate: {
640
+ count: { function: 'count', field: '*' },
641
+ total_amount: { function: 'sum', field: 'amount' },
642
+ },
643
+ },
644
+ },
645
+ {
646
+ name: 'products_by_category',
647
+ collection: 'products',
648
+ query: {
649
+ groupBy: ['categoryId'],
650
+ aggregate: {
651
+ count: { function: 'count', field: 'id' },
652
+ avg_price: { function: 'avg', field: 'price' },
653
+ },
654
+ fields: ['categoryId', 'category.name'],
655
+ },
656
+ },
657
+ ]);
658
+ // Returns: [{ name: 'total_products', collection: 'products', data: [...] }, ...]
659
+ ```
660
+
661
+ ### Aggregation Query
662
+
663
+ Run aggregation queries directly on a collection (uses items endpoint):
664
+
665
+ ```typescript
666
+ const results = await baasix.reports.aggregate('orders', {
667
+ aggregate: {
668
+ total: { function: 'sum', field: 'amount' },
669
+ count: { function: 'count', field: 'id' },
670
+ min: { function: 'min', field: 'amount' },
671
+ max: { function: 'max', field: 'amount' },
672
+ avg: { function: 'avg', field: 'amount' },
673
+ },
674
+ groupBy: ['status', 'paymentMethod'],
675
+ filter: { createdAt: { gte: '$NOW-DAYS_30' } },
676
+ });
677
+ ```
678
+
679
+ ### Quick Count
524
680
 
525
- // Quick count
681
+ ```typescript
526
682
  const activeUsers = await baasix.reports.count('users', {
527
683
  status: { eq: 'active' },
528
684
  });
529
685
  ```
530
686
 
687
+ ### Distinct Values
688
+
689
+ ```typescript
690
+ const categories = await baasix.reports.distinct('products', 'category');
691
+ // Returns: ['Electronics', 'Clothing', 'Books', ...]
692
+ ```
693
+
531
694
  ## Workflows
532
695
 
533
696
  ```typescript
@@ -296,13 +296,49 @@ interface BulkResponse<T = string[]> {
296
296
  error: string;
297
297
  }>;
298
298
  }
299
- type FieldType = "String" | "Text" | "Integer" | "BigInt" | "Float" | "Double" | "Decimal" | "Boolean" | "Date" | "DateTime" | "Time" | "UUID" | "JSON" | "JSONB" | "Array" | "Geometry" | "Point" | "LineString" | "Polygon" | "Enum";
299
+ type FieldType = "String" | "Text" | "Integer" | "BigInt" | "Float" | "Real" | "Double" | "Decimal" | "Boolean" | "Date" | "DateTime" | "Time" | "UUID" | "SUID" | "JSON" | "JSONB" | "Array" | "Geometry" | "Point" | "LineString" | "Polygon" | "Enum";
300
+ /**
301
+ * Default value types supported by Baasix
302
+ */
303
+ type DefaultValueType = {
304
+ type: "UUIDV4";
305
+ } | {
306
+ type: "SUID";
307
+ } | {
308
+ type: "NOW";
309
+ } | {
310
+ type: "AUTOINCREMENT";
311
+ } | {
312
+ type: "SQL";
313
+ value: string;
314
+ } | {
315
+ type: "CURRENT_USER";
316
+ } | {
317
+ type: "CURRENT_TENANT";
318
+ };
300
319
  interface FieldDefinition {
301
320
  type: FieldType;
302
321
  primaryKey?: boolean;
303
322
  allowNull?: boolean;
304
323
  unique?: boolean;
305
- defaultValue?: unknown;
324
+ /**
325
+ * Default value for the field
326
+ * Can be a static value or a dynamic type
327
+ * @example
328
+ * // Static values
329
+ * defaultValue: "active"
330
+ * defaultValue: 0
331
+ * defaultValue: false
332
+ * defaultValue: []
333
+ *
334
+ * // Dynamic types
335
+ * defaultValue: { type: "UUIDV4" }
336
+ * defaultValue: { type: "SUID" }
337
+ * defaultValue: { type: "NOW" }
338
+ * defaultValue: { type: "AUTOINCREMENT" }
339
+ * defaultValue: { type: "SQL", value: "CURRENT_DATE" }
340
+ */
341
+ defaultValue?: DefaultValueType | string | number | boolean | null | unknown[] | Record<string, unknown>;
306
342
  values?: {
307
343
  length?: number;
308
344
  precision?: number;
@@ -311,11 +347,25 @@ interface FieldDefinition {
311
347
  values?: string[];
312
348
  };
313
349
  validate?: {
350
+ /** Minimum value for numeric fields */
314
351
  min?: number;
352
+ /** Maximum value for numeric fields */
315
353
  max?: number;
316
- len?: [number, number];
354
+ /** Validate as integer */
355
+ isInt?: boolean;
356
+ /** String must not be empty */
357
+ notEmpty?: boolean;
358
+ /** Validate email format */
317
359
  isEmail?: boolean;
360
+ /** Validate URL format */
318
361
  isUrl?: boolean;
362
+ /** String length range [min, max] */
363
+ len?: [number, number];
364
+ /** Pattern matching with regex (alias: matches) */
365
+ is?: string;
366
+ /** Pattern matching with regex (alias: is) */
367
+ matches?: string;
368
+ /** @deprecated Use 'is' or 'matches' instead */
319
369
  regex?: string;
320
370
  };
321
371
  comment?: string;
@@ -611,4 +661,4 @@ declare class HttpClient {
611
661
  }): Promise<T>;
612
662
  }
613
663
 
614
- export { type WorkflowTrigger as $, type AuthMode as A, type BaseItem as B, type CreatePermissionData as C, type DeleteResponse as D, type FilterValue as E, type Filter as F, type FilterCondition as G, HttpClient as H, type IndexDefinition as I, type LogicalFilter as J, type SortDirection as K, type LoginCredentials as L, type MagicLinkOptions as M, type Notification as N, type AggregateFunction as O, type PasswordResetOptions as P, type QueryParams as Q, type RegisterData as R, type Sort as S, type Tenant as T, type User as U, type AggregateConfig as V, type Workflow as W, type FieldType as X, type FieldDefinition as Y, type RelationshipType as Z, type PermissionAction as _, type AuthStateEvent as a, type WorkflowNode as a0, type WorkflowEdge as a1, type BaasixErrorDetails as a2, BaasixError as a3, type DeepPartial as a4, type CollectionItem as a5, type AuthResponse as b, type AuthTokens as c, type AuthState as d, type PaginatedResponse as e, type BulkResponse as f, type MutationResponse as g, type SingleResponse as h, type UploadOptions as i, type FileMetadata as j, type AssetTransformOptions as k, type SchemaInfo as l, type SchemaDefinition as m, type RelationshipDefinition as n, type SendNotificationData as o, type Permission as p, type Role as q, type Settings as r, type ReportConfig as s, type ReportResult as t, type Aggregate as u, type WorkflowExecution as v, type BaasixConfig as w, type RequestOptions as x, type HttpClientConfig as y, type FilterOperator as z };
664
+ export { type PermissionAction as $, type AuthMode as A, type BaseItem as B, type CreatePermissionData as C, type DeleteResponse as D, type FilterValue as E, type Filter as F, type FilterCondition as G, HttpClient as H, type IndexDefinition as I, type LogicalFilter as J, type SortDirection as K, type LoginCredentials as L, type MagicLinkOptions as M, type Notification as N, type AggregateFunction as O, type PasswordResetOptions as P, type QueryParams as Q, type RegisterData as R, type Sort as S, type Tenant as T, type User as U, type AggregateConfig as V, type Workflow as W, type FieldType as X, type DefaultValueType as Y, type FieldDefinition as Z, type RelationshipType as _, type AuthStateEvent as a, type WorkflowTrigger as a0, type WorkflowNode as a1, type WorkflowEdge as a2, type BaasixErrorDetails as a3, BaasixError as a4, type DeepPartial as a5, type CollectionItem as a6, type AuthResponse as b, type AuthTokens as c, type AuthState as d, type PaginatedResponse as e, type BulkResponse as f, type MutationResponse as g, type SingleResponse as h, type UploadOptions as i, type FileMetadata as j, type AssetTransformOptions as k, type SchemaInfo as l, type SchemaDefinition as m, type RelationshipDefinition as n, type SendNotificationData as o, type Permission as p, type Role as q, type Settings as r, type ReportConfig as s, type ReportResult as t, type Aggregate as u, type WorkflowExecution as v, type BaasixConfig as w, type RequestOptions as x, type HttpClientConfig as y, type FilterOperator as z };
@@ -296,13 +296,49 @@ interface BulkResponse<T = string[]> {
296
296
  error: string;
297
297
  }>;
298
298
  }
299
- type FieldType = "String" | "Text" | "Integer" | "BigInt" | "Float" | "Double" | "Decimal" | "Boolean" | "Date" | "DateTime" | "Time" | "UUID" | "JSON" | "JSONB" | "Array" | "Geometry" | "Point" | "LineString" | "Polygon" | "Enum";
299
+ type FieldType = "String" | "Text" | "Integer" | "BigInt" | "Float" | "Real" | "Double" | "Decimal" | "Boolean" | "Date" | "DateTime" | "Time" | "UUID" | "SUID" | "JSON" | "JSONB" | "Array" | "Geometry" | "Point" | "LineString" | "Polygon" | "Enum";
300
+ /**
301
+ * Default value types supported by Baasix
302
+ */
303
+ type DefaultValueType = {
304
+ type: "UUIDV4";
305
+ } | {
306
+ type: "SUID";
307
+ } | {
308
+ type: "NOW";
309
+ } | {
310
+ type: "AUTOINCREMENT";
311
+ } | {
312
+ type: "SQL";
313
+ value: string;
314
+ } | {
315
+ type: "CURRENT_USER";
316
+ } | {
317
+ type: "CURRENT_TENANT";
318
+ };
300
319
  interface FieldDefinition {
301
320
  type: FieldType;
302
321
  primaryKey?: boolean;
303
322
  allowNull?: boolean;
304
323
  unique?: boolean;
305
- defaultValue?: unknown;
324
+ /**
325
+ * Default value for the field
326
+ * Can be a static value or a dynamic type
327
+ * @example
328
+ * // Static values
329
+ * defaultValue: "active"
330
+ * defaultValue: 0
331
+ * defaultValue: false
332
+ * defaultValue: []
333
+ *
334
+ * // Dynamic types
335
+ * defaultValue: { type: "UUIDV4" }
336
+ * defaultValue: { type: "SUID" }
337
+ * defaultValue: { type: "NOW" }
338
+ * defaultValue: { type: "AUTOINCREMENT" }
339
+ * defaultValue: { type: "SQL", value: "CURRENT_DATE" }
340
+ */
341
+ defaultValue?: DefaultValueType | string | number | boolean | null | unknown[] | Record<string, unknown>;
306
342
  values?: {
307
343
  length?: number;
308
344
  precision?: number;
@@ -311,11 +347,25 @@ interface FieldDefinition {
311
347
  values?: string[];
312
348
  };
313
349
  validate?: {
350
+ /** Minimum value for numeric fields */
314
351
  min?: number;
352
+ /** Maximum value for numeric fields */
315
353
  max?: number;
316
- len?: [number, number];
354
+ /** Validate as integer */
355
+ isInt?: boolean;
356
+ /** String must not be empty */
357
+ notEmpty?: boolean;
358
+ /** Validate email format */
317
359
  isEmail?: boolean;
360
+ /** Validate URL format */
318
361
  isUrl?: boolean;
362
+ /** String length range [min, max] */
363
+ len?: [number, number];
364
+ /** Pattern matching with regex (alias: matches) */
365
+ is?: string;
366
+ /** Pattern matching with regex (alias: is) */
367
+ matches?: string;
368
+ /** @deprecated Use 'is' or 'matches' instead */
319
369
  regex?: string;
320
370
  };
321
371
  comment?: string;
@@ -611,4 +661,4 @@ declare class HttpClient {
611
661
  }): Promise<T>;
612
662
  }
613
663
 
614
- export { type WorkflowTrigger as $, type AuthMode as A, type BaseItem as B, type CreatePermissionData as C, type DeleteResponse as D, type FilterValue as E, type Filter as F, type FilterCondition as G, HttpClient as H, type IndexDefinition as I, type LogicalFilter as J, type SortDirection as K, type LoginCredentials as L, type MagicLinkOptions as M, type Notification as N, type AggregateFunction as O, type PasswordResetOptions as P, type QueryParams as Q, type RegisterData as R, type Sort as S, type Tenant as T, type User as U, type AggregateConfig as V, type Workflow as W, type FieldType as X, type FieldDefinition as Y, type RelationshipType as Z, type PermissionAction as _, type AuthStateEvent as a, type WorkflowNode as a0, type WorkflowEdge as a1, type BaasixErrorDetails as a2, BaasixError as a3, type DeepPartial as a4, type CollectionItem as a5, type AuthResponse as b, type AuthTokens as c, type AuthState as d, type PaginatedResponse as e, type BulkResponse as f, type MutationResponse as g, type SingleResponse as h, type UploadOptions as i, type FileMetadata as j, type AssetTransformOptions as k, type SchemaInfo as l, type SchemaDefinition as m, type RelationshipDefinition as n, type SendNotificationData as o, type Permission as p, type Role as q, type Settings as r, type ReportConfig as s, type ReportResult as t, type Aggregate as u, type WorkflowExecution as v, type BaasixConfig as w, type RequestOptions as x, type HttpClientConfig as y, type FilterOperator as z };
664
+ export { type PermissionAction as $, type AuthMode as A, type BaseItem as B, type CreatePermissionData as C, type DeleteResponse as D, type FilterValue as E, type Filter as F, type FilterCondition as G, HttpClient as H, type IndexDefinition as I, type LogicalFilter as J, type SortDirection as K, type LoginCredentials as L, type MagicLinkOptions as M, type Notification as N, type AggregateFunction as O, type PasswordResetOptions as P, type QueryParams as Q, type RegisterData as R, type Sort as S, type Tenant as T, type User as U, type AggregateConfig as V, type Workflow as W, type FieldType as X, type DefaultValueType as Y, type FieldDefinition as Z, type RelationshipType as _, type AuthStateEvent as a, type WorkflowTrigger as a0, type WorkflowNode as a1, type WorkflowEdge as a2, type BaasixErrorDetails as a3, BaasixError as a4, type DeepPartial as a5, type CollectionItem as a6, type AuthResponse as b, type AuthTokens as c, type AuthState as d, type PaginatedResponse as e, type BulkResponse as f, type MutationResponse as g, type SingleResponse as h, type UploadOptions as i, type FileMetadata as j, type AssetTransformOptions as k, type SchemaInfo as l, type SchemaDefinition as m, type RelationshipDefinition as n, type SendNotificationData as o, type Permission as p, type Role as q, type Settings as r, type ReportConfig as s, type ReportResult as t, type Aggregate as u, type WorkflowExecution as v, type BaasixConfig as w, type RequestOptions as x, type HttpClientConfig as y, type FilterOperator as z };
package/dist/index.cjs CHANGED
@@ -1082,35 +1082,6 @@ var AuthModule = class {
1082
1082
  }
1083
1083
  };
1084
1084
 
1085
- // src/utils/sort.ts
1086
- function normalizeSort(sort) {
1087
- if (!sort) return void 0;
1088
- if (typeof sort === "string") {
1089
- return sort;
1090
- }
1091
- if (Array.isArray(sort)) {
1092
- if (sort.length === 0) return void 0;
1093
- if (typeof sort[0] === "object" && "column" in sort[0]) {
1094
- return sort.map((s) => `${s.column}:${s.order.toLowerCase()}`).join(",");
1095
- }
1096
- return sort.map((s) => {
1097
- if (s.startsWith("-")) {
1098
- return `${s.substring(1)}:desc`;
1099
- }
1100
- if (s.includes(":")) {
1101
- return s;
1102
- }
1103
- return `${s}:asc`;
1104
- }).join(",");
1105
- }
1106
- if (typeof sort === "object") {
1107
- const entries = Object.entries(sort);
1108
- if (entries.length === 0) return void 0;
1109
- return entries.map(([field, direction]) => `${field}:${direction.toLowerCase()}`).join(",");
1110
- }
1111
- return void 0;
1112
- }
1113
-
1114
1085
  // src/modules/items.ts
1115
1086
  var QueryBuilder = class {
1116
1087
  collection;
@@ -1418,12 +1389,8 @@ var ItemsModule = class {
1418
1389
  * ```
1419
1390
  */
1420
1391
  async find(params) {
1421
- const normalizedParams = params ? {
1422
- ...params,
1423
- sort: normalizeSort(params.sort)
1424
- } : void 0;
1425
1392
  return this.client.get(`/items/${this.collection}`, {
1426
- params: normalizedParams
1393
+ params
1427
1394
  });
1428
1395
  }
1429
1396
  /**
@@ -1839,12 +1806,8 @@ var FilesModule = class {
1839
1806
  * ```
1840
1807
  */
1841
1808
  async find(params) {
1842
- const normalizedParams = params ? {
1843
- ...params,
1844
- sort: normalizeSort(params.sort)
1845
- } : void 0;
1846
1809
  return this.client.get("/files", {
1847
- params: normalizedParams
1810
+ params
1848
1811
  });
1849
1812
  }
1850
1813
  /**
@@ -2013,6 +1976,35 @@ var FilesModule = class {
2013
1976
  }
2014
1977
  };
2015
1978
 
1979
+ // src/utils/sort.ts
1980
+ function normalizeSort(sort) {
1981
+ if (!sort) return void 0;
1982
+ if (typeof sort === "string") {
1983
+ return sort;
1984
+ }
1985
+ if (Array.isArray(sort)) {
1986
+ if (sort.length === 0) return void 0;
1987
+ if (typeof sort[0] === "object" && "column" in sort[0]) {
1988
+ return sort.map((s) => `${s.column}:${s.order.toLowerCase()}`).join(",");
1989
+ }
1990
+ return sort.map((s) => {
1991
+ if (s.startsWith("-")) {
1992
+ return `${s.substring(1)}:desc`;
1993
+ }
1994
+ if (s.includes(":")) {
1995
+ return s;
1996
+ }
1997
+ return `${s}:asc`;
1998
+ }).join(",");
1999
+ }
2000
+ if (typeof sort === "object") {
2001
+ const entries = Object.entries(sort);
2002
+ if (entries.length === 0) return void 0;
2003
+ return entries.map(([field, direction]) => `${field}:${direction.toLowerCase()}`).join(",");
2004
+ }
2005
+ return void 0;
2006
+ }
2007
+
2016
2008
  // src/modules/schemas.ts
2017
2009
  var SchemasModule = class {
2018
2010
  client;
@@ -2658,7 +2650,7 @@ var ReportsModule = class {
2658
2650
  this.client = config.client;
2659
2651
  }
2660
2652
  /**
2661
- * Generate a report for a collection
2653
+ * Generate a report for a collection using POST method
2662
2654
  *
2663
2655
  * @example
2664
2656
  * ```typescript
@@ -2668,7 +2660,7 @@ var ReportsModule = class {
2668
2660
  * revenue: { function: 'sum', field: 'total' },
2669
2661
  * orders: { function: 'count', field: 'id' }
2670
2662
  * },
2671
- * groupBy: 'month',
2663
+ * groupBy: ['month'],
2672
2664
  * dateRange: {
2673
2665
  * start: '2025-01-01',
2674
2666
  * end: '2025-12-31'
@@ -2684,19 +2676,56 @@ var ReportsModule = class {
2684
2676
  return response;
2685
2677
  }
2686
2678
  /**
2687
- * Get collection statistics
2679
+ * Query a report for a collection using GET method with query params
2680
+ *
2681
+ * @example
2682
+ * ```typescript
2683
+ * const report = await baasix.reports.query('orders', {
2684
+ * aggregate: {
2685
+ * total: { function: 'sum', field: 'amount' }
2686
+ * },
2687
+ * groupBy: ['status']
2688
+ * });
2689
+ * ```
2690
+ */
2691
+ async query(collection, params) {
2692
+ const response = await this.client.get(
2693
+ `/reports/${collection}`,
2694
+ { params }
2695
+ );
2696
+ return response;
2697
+ }
2698
+ /**
2699
+ * Get statistics for multiple collections in a single request
2688
2700
  *
2689
2701
  * @example
2690
2702
  * ```typescript
2691
- * const stats = await baasix.reports.getStats('products');
2692
- * console.log(stats.totalCount, stats.recentCount);
2703
+ * const stats = await baasix.reports.getStats([
2704
+ * {
2705
+ * name: 'total_products',
2706
+ * collection: 'products',
2707
+ * query: {
2708
+ * aggregate: { count: { function: 'count', field: '*' } }
2709
+ * }
2710
+ * },
2711
+ * {
2712
+ * name: 'total_orders',
2713
+ * collection: 'orders',
2714
+ * query: {
2715
+ * aggregate: {
2716
+ * count: { function: 'count', field: '*' },
2717
+ * total_amount: { function: 'sum', field: 'amount' }
2718
+ * }
2719
+ * }
2720
+ * }
2721
+ * ]);
2693
2722
  * ```
2694
2723
  */
2695
- async getStats(collection, options) {
2696
- const response = await this.client.get(`/reports/${collection}/stats`, {
2697
- params: options
2724
+ async getStats(stats) {
2725
+ const response = await this.client.post(`/reports/stats`, {
2726
+ stats
2698
2727
  });
2699
- return response.data;
2728
+ return response;
2700
2729
  }
2701
2730
  /**
2702
2731
  * Generate an aggregation query