@tspvivek/baasix-sdk 0.1.0-alpha.2 → 0.1.0-alpha.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.
package/dist/index.d.cts CHANGED
@@ -341,6 +341,30 @@ declare class SettingsModule {
341
341
  interface ReportsModuleConfig {
342
342
  client: HttpClient;
343
343
  }
344
+ /**
345
+ * Stats query for the stats endpoint
346
+ */
347
+ interface StatsQuery {
348
+ /** Unique name for this stats query */
349
+ name: string;
350
+ /** Collection to query */
351
+ collection: string;
352
+ /** Query parameters including aggregate, groupBy, filter, fields */
353
+ query: {
354
+ aggregate?: Aggregate;
355
+ groupBy?: string[];
356
+ filter?: Filter;
357
+ fields?: string[];
358
+ };
359
+ }
360
+ /**
361
+ * Stats result from a single query
362
+ */
363
+ interface StatsResult {
364
+ name: string;
365
+ collection: string;
366
+ data: Record<string, unknown>[];
367
+ }
344
368
  /**
345
369
  * Reports module for generating analytics and reports.
346
370
  *
@@ -367,7 +391,7 @@ declare class ReportsModule {
367
391
  private client;
368
392
  constructor(config: ReportsModuleConfig);
369
393
  /**
370
- * Generate a report for a collection
394
+ * Generate a report for a collection using POST method
371
395
  *
372
396
  * @example
373
397
  * ```typescript
@@ -377,7 +401,7 @@ declare class ReportsModule {
377
401
  * revenue: { function: 'sum', field: 'total' },
378
402
  * orders: { function: 'count', field: 'id' }
379
403
  * },
380
- * groupBy: 'month',
404
+ * groupBy: ['month'],
381
405
  * dateRange: {
382
406
  * start: '2025-01-01',
383
407
  * end: '2025-12-31'
@@ -387,22 +411,51 @@ declare class ReportsModule {
387
411
  */
388
412
  generate(collection: string, config: Omit<ReportConfig, "collection">): Promise<ReportResult>;
389
413
  /**
390
- * Get collection statistics
414
+ * Query a report for a collection using GET method with query params
391
415
  *
392
416
  * @example
393
417
  * ```typescript
394
- * const stats = await baasix.reports.getStats('products');
395
- * console.log(stats.totalCount, stats.recentCount);
418
+ * const report = await baasix.reports.query('orders', {
419
+ * aggregate: {
420
+ * total: { function: 'sum', field: 'amount' }
421
+ * },
422
+ * groupBy: ['status']
423
+ * });
396
424
  * ```
397
425
  */
398
- getStats(collection: string, options?: {
399
- timeframe?: "24h" | "7d" | "30d" | "90d" | "1y";
400
- }): Promise<{
401
- totalCount: number;
402
- recentCount: number;
403
- deletedCount?: number;
404
- byDate?: Record<string, number>;
405
- }>;
426
+ query(collection: string, params?: {
427
+ aggregate?: Aggregate;
428
+ groupBy?: string[];
429
+ filter?: Filter;
430
+ fields?: string[];
431
+ }): Promise<ReportResult>;
432
+ /**
433
+ * Get statistics for multiple collections in a single request
434
+ *
435
+ * @example
436
+ * ```typescript
437
+ * const stats = await baasix.reports.getStats([
438
+ * {
439
+ * name: 'total_products',
440
+ * collection: 'products',
441
+ * query: {
442
+ * aggregate: { count: { function: 'count', field: '*' } }
443
+ * }
444
+ * },
445
+ * {
446
+ * name: 'total_orders',
447
+ * collection: 'orders',
448
+ * query: {
449
+ * aggregate: {
450
+ * count: { function: 'count', field: '*' },
451
+ * total_amount: { function: 'sum', field: 'amount' }
452
+ * }
453
+ * }
454
+ * }
455
+ * ]);
456
+ * ```
457
+ */
458
+ getStats(stats: StatsQuery[]): Promise<StatsResult[]>;
406
459
  /**
407
460
  * Generate an aggregation query
408
461
  *
@@ -1629,4 +1682,4 @@ declare class Baasix {
1629
1682
  */
1630
1683
  declare function createBaasix(config: BaasixConfig): Baasix;
1631
1684
 
1632
- export { Aggregate, AuthMode, AuthModule, Baasix, BaasixConfig, BaseItem, type CreateMigrationOptions, CreatePermissionData, type CreateRoleData, type CreateUserData, FilesModule, Filter, HttpClient, ItemsModule, type Migration, type MigrationRunOptions, type MigrationRunResult, type MigrationStatus, MigrationsModule, Notification, NotificationsModule, PaginatedResponse, type PendingMigration, Permission, PermissionsModule, RealtimeChannel, type RealtimeConfig, RealtimeModule, ReportConfig, ReportResult, ReportsModule, type Role, RolesModule, type RollbackResult, SchemasModule, SendNotificationData, Settings, SettingsModule, StorageAdapter, type SubscriptionCallback, type SubscriptionEvent, type SubscriptionPayload, type UpdateUserData, type UserQueryOptions, UsersModule, Workflow, WorkflowExecution, type WorkflowExecutionUpdate, WorkflowsModule, createBaasix };
1685
+ export { Aggregate, AuthMode, AuthModule, Baasix, BaasixConfig, BaseItem, type CreateMigrationOptions, CreatePermissionData, type CreateRoleData, type CreateUserData, FilesModule, Filter, HttpClient, ItemsModule, type Migration, type MigrationRunOptions, type MigrationRunResult, type MigrationStatus, MigrationsModule, Notification, NotificationsModule, PaginatedResponse, type PendingMigration, Permission, PermissionsModule, RealtimeChannel, type RealtimeConfig, RealtimeModule, ReportConfig, ReportResult, ReportsModule, type Role, RolesModule, type RollbackResult, SchemasModule, SendNotificationData, Settings, SettingsModule, type StatsQuery, type StatsResult, StorageAdapter, type SubscriptionCallback, type SubscriptionEvent, type SubscriptionPayload, type UpdateUserData, type UserQueryOptions, UsersModule, Workflow, WorkflowExecution, type WorkflowExecutionUpdate, WorkflowsModule, createBaasix };
package/dist/index.d.ts CHANGED
@@ -341,6 +341,30 @@ declare class SettingsModule {
341
341
  interface ReportsModuleConfig {
342
342
  client: HttpClient;
343
343
  }
344
+ /**
345
+ * Stats query for the stats endpoint
346
+ */
347
+ interface StatsQuery {
348
+ /** Unique name for this stats query */
349
+ name: string;
350
+ /** Collection to query */
351
+ collection: string;
352
+ /** Query parameters including aggregate, groupBy, filter, fields */
353
+ query: {
354
+ aggregate?: Aggregate;
355
+ groupBy?: string[];
356
+ filter?: Filter;
357
+ fields?: string[];
358
+ };
359
+ }
360
+ /**
361
+ * Stats result from a single query
362
+ */
363
+ interface StatsResult {
364
+ name: string;
365
+ collection: string;
366
+ data: Record<string, unknown>[];
367
+ }
344
368
  /**
345
369
  * Reports module for generating analytics and reports.
346
370
  *
@@ -367,7 +391,7 @@ declare class ReportsModule {
367
391
  private client;
368
392
  constructor(config: ReportsModuleConfig);
369
393
  /**
370
- * Generate a report for a collection
394
+ * Generate a report for a collection using POST method
371
395
  *
372
396
  * @example
373
397
  * ```typescript
@@ -377,7 +401,7 @@ declare class ReportsModule {
377
401
  * revenue: { function: 'sum', field: 'total' },
378
402
  * orders: { function: 'count', field: 'id' }
379
403
  * },
380
- * groupBy: 'month',
404
+ * groupBy: ['month'],
381
405
  * dateRange: {
382
406
  * start: '2025-01-01',
383
407
  * end: '2025-12-31'
@@ -387,22 +411,51 @@ declare class ReportsModule {
387
411
  */
388
412
  generate(collection: string, config: Omit<ReportConfig, "collection">): Promise<ReportResult>;
389
413
  /**
390
- * Get collection statistics
414
+ * Query a report for a collection using GET method with query params
391
415
  *
392
416
  * @example
393
417
  * ```typescript
394
- * const stats = await baasix.reports.getStats('products');
395
- * console.log(stats.totalCount, stats.recentCount);
418
+ * const report = await baasix.reports.query('orders', {
419
+ * aggregate: {
420
+ * total: { function: 'sum', field: 'amount' }
421
+ * },
422
+ * groupBy: ['status']
423
+ * });
396
424
  * ```
397
425
  */
398
- getStats(collection: string, options?: {
399
- timeframe?: "24h" | "7d" | "30d" | "90d" | "1y";
400
- }): Promise<{
401
- totalCount: number;
402
- recentCount: number;
403
- deletedCount?: number;
404
- byDate?: Record<string, number>;
405
- }>;
426
+ query(collection: string, params?: {
427
+ aggregate?: Aggregate;
428
+ groupBy?: string[];
429
+ filter?: Filter;
430
+ fields?: string[];
431
+ }): Promise<ReportResult>;
432
+ /**
433
+ * Get statistics for multiple collections in a single request
434
+ *
435
+ * @example
436
+ * ```typescript
437
+ * const stats = await baasix.reports.getStats([
438
+ * {
439
+ * name: 'total_products',
440
+ * collection: 'products',
441
+ * query: {
442
+ * aggregate: { count: { function: 'count', field: '*' } }
443
+ * }
444
+ * },
445
+ * {
446
+ * name: 'total_orders',
447
+ * collection: 'orders',
448
+ * query: {
449
+ * aggregate: {
450
+ * count: { function: 'count', field: '*' },
451
+ * total_amount: { function: 'sum', field: 'amount' }
452
+ * }
453
+ * }
454
+ * }
455
+ * ]);
456
+ * ```
457
+ */
458
+ getStats(stats: StatsQuery[]): Promise<StatsResult[]>;
406
459
  /**
407
460
  * Generate an aggregation query
408
461
  *
@@ -1629,4 +1682,4 @@ declare class Baasix {
1629
1682
  */
1630
1683
  declare function createBaasix(config: BaasixConfig): Baasix;
1631
1684
 
1632
- export { Aggregate, AuthMode, AuthModule, Baasix, BaasixConfig, BaseItem, type CreateMigrationOptions, CreatePermissionData, type CreateRoleData, type CreateUserData, FilesModule, Filter, HttpClient, ItemsModule, type Migration, type MigrationRunOptions, type MigrationRunResult, type MigrationStatus, MigrationsModule, Notification, NotificationsModule, PaginatedResponse, type PendingMigration, Permission, PermissionsModule, RealtimeChannel, type RealtimeConfig, RealtimeModule, ReportConfig, ReportResult, ReportsModule, type Role, RolesModule, type RollbackResult, SchemasModule, SendNotificationData, Settings, SettingsModule, StorageAdapter, type SubscriptionCallback, type SubscriptionEvent, type SubscriptionPayload, type UpdateUserData, type UserQueryOptions, UsersModule, Workflow, WorkflowExecution, type WorkflowExecutionUpdate, WorkflowsModule, createBaasix };
1685
+ export { Aggregate, AuthMode, AuthModule, Baasix, BaasixConfig, BaseItem, type CreateMigrationOptions, CreatePermissionData, type CreateRoleData, type CreateUserData, FilesModule, Filter, HttpClient, ItemsModule, type Migration, type MigrationRunOptions, type MigrationRunResult, type MigrationStatus, MigrationsModule, Notification, NotificationsModule, PaginatedResponse, type PendingMigration, Permission, PermissionsModule, RealtimeChannel, type RealtimeConfig, RealtimeModule, ReportConfig, ReportResult, ReportsModule, type Role, RolesModule, type RollbackResult, SchemasModule, SendNotificationData, Settings, SettingsModule, type StatsQuery, type StatsResult, StorageAdapter, type SubscriptionCallback, type SubscriptionEvent, type SubscriptionPayload, type UpdateUserData, type UserQueryOptions, UsersModule, Workflow, WorkflowExecution, type WorkflowExecutionUpdate, WorkflowsModule, createBaasix };
package/dist/index.js CHANGED
@@ -1974,6 +1974,35 @@ var FilesModule = class {
1974
1974
  }
1975
1975
  };
1976
1976
 
1977
+ // src/utils/sort.ts
1978
+ function normalizeSort(sort) {
1979
+ if (!sort) return void 0;
1980
+ if (typeof sort === "string") {
1981
+ return sort;
1982
+ }
1983
+ if (Array.isArray(sort)) {
1984
+ if (sort.length === 0) return void 0;
1985
+ if (typeof sort[0] === "object" && "column" in sort[0]) {
1986
+ return sort.map((s) => `${s.column}:${s.order.toLowerCase()}`).join(",");
1987
+ }
1988
+ return sort.map((s) => {
1989
+ if (s.startsWith("-")) {
1990
+ return `${s.substring(1)}:desc`;
1991
+ }
1992
+ if (s.includes(":")) {
1993
+ return s;
1994
+ }
1995
+ return `${s}:asc`;
1996
+ }).join(",");
1997
+ }
1998
+ if (typeof sort === "object") {
1999
+ const entries = Object.entries(sort);
2000
+ if (entries.length === 0) return void 0;
2001
+ return entries.map(([field, direction]) => `${field}:${direction.toLowerCase()}`).join(",");
2002
+ }
2003
+ return void 0;
2004
+ }
2005
+
1977
2006
  // src/modules/schemas.ts
1978
2007
  var SchemasModule = class {
1979
2008
  client;
@@ -1993,7 +2022,11 @@ var SchemasModule = class {
1993
2022
  * ```
1994
2023
  */
1995
2024
  async find(params) {
1996
- return this.client.get("/schemas", { params });
2025
+ const normalizedParams = params ? {
2026
+ ...params,
2027
+ sort: normalizeSort(params.sort)
2028
+ } : void 0;
2029
+ return this.client.get("/schemas", { params: normalizedParams });
1997
2030
  }
1998
2031
  /**
1999
2032
  * Get schema for a specific collection
@@ -2615,7 +2648,7 @@ var ReportsModule = class {
2615
2648
  this.client = config.client;
2616
2649
  }
2617
2650
  /**
2618
- * Generate a report for a collection
2651
+ * Generate a report for a collection using POST method
2619
2652
  *
2620
2653
  * @example
2621
2654
  * ```typescript
@@ -2625,7 +2658,7 @@ var ReportsModule = class {
2625
2658
  * revenue: { function: 'sum', field: 'total' },
2626
2659
  * orders: { function: 'count', field: 'id' }
2627
2660
  * },
2628
- * groupBy: 'month',
2661
+ * groupBy: ['month'],
2629
2662
  * dateRange: {
2630
2663
  * start: '2025-01-01',
2631
2664
  * end: '2025-12-31'
@@ -2641,19 +2674,56 @@ var ReportsModule = class {
2641
2674
  return response;
2642
2675
  }
2643
2676
  /**
2644
- * Get collection statistics
2677
+ * Query a report for a collection using GET method with query params
2645
2678
  *
2646
2679
  * @example
2647
2680
  * ```typescript
2648
- * const stats = await baasix.reports.getStats('products');
2649
- * console.log(stats.totalCount, stats.recentCount);
2681
+ * const report = await baasix.reports.query('orders', {
2682
+ * aggregate: {
2683
+ * total: { function: 'sum', field: 'amount' }
2684
+ * },
2685
+ * groupBy: ['status']
2686
+ * });
2650
2687
  * ```
2651
2688
  */
2652
- async getStats(collection, options) {
2653
- const response = await this.client.get(`/reports/${collection}/stats`, {
2654
- params: options
2689
+ async query(collection, params) {
2690
+ const response = await this.client.get(
2691
+ `/reports/${collection}`,
2692
+ { params }
2693
+ );
2694
+ return response;
2695
+ }
2696
+ /**
2697
+ * Get statistics for multiple collections in a single request
2698
+ *
2699
+ * @example
2700
+ * ```typescript
2701
+ * const stats = await baasix.reports.getStats([
2702
+ * {
2703
+ * name: 'total_products',
2704
+ * collection: 'products',
2705
+ * query: {
2706
+ * aggregate: { count: { function: 'count', field: '*' } }
2707
+ * }
2708
+ * },
2709
+ * {
2710
+ * name: 'total_orders',
2711
+ * collection: 'orders',
2712
+ * query: {
2713
+ * aggregate: {
2714
+ * count: { function: 'count', field: '*' },
2715
+ * total_amount: { function: 'sum', field: 'amount' }
2716
+ * }
2717
+ * }
2718
+ * }
2719
+ * ]);
2720
+ * ```
2721
+ */
2722
+ async getStats(stats) {
2723
+ const response = await this.client.post(`/reports/stats`, {
2724
+ stats
2655
2725
  });
2656
- return response.data;
2726
+ return response;
2657
2727
  }
2658
2728
  /**
2659
2729
  * Generate an aggregation query