@tspvivek/baasix-sdk 0.1.0-alpha.3 → 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/README.md +87 -3
- package/dist/index.cjs +77 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -14
- package/dist/index.d.ts +67 -14
- package/dist/index.js +77 -48
- package/dist/index.js.map +1 -1
- package/dist/modules/files.cjs +1 -34
- package/dist/modules/files.cjs.map +1 -1
- package/dist/modules/files.js +1 -34
- package/dist/modules/files.js.map +1 -1
- package/dist/modules/items.cjs +1 -34
- package/dist/modules/items.cjs.map +1 -1
- package/dist/modules/items.js +1 -34
- package/dist/modules/items.js.map +1 -1
- package/package.json +1 -1
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
|
-
*
|
|
414
|
+
* Query a report for a collection using GET method with query params
|
|
391
415
|
*
|
|
392
416
|
* @example
|
|
393
417
|
* ```typescript
|
|
394
|
-
* const
|
|
395
|
-
*
|
|
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
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
|
-
*
|
|
414
|
+
* Query a report for a collection using GET method with query params
|
|
391
415
|
*
|
|
392
416
|
* @example
|
|
393
417
|
* ```typescript
|
|
394
|
-
* const
|
|
395
|
-
*
|
|
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
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
|
@@ -1080,35 +1080,6 @@ var AuthModule = class {
|
|
|
1080
1080
|
}
|
|
1081
1081
|
};
|
|
1082
1082
|
|
|
1083
|
-
// src/utils/sort.ts
|
|
1084
|
-
function normalizeSort(sort) {
|
|
1085
|
-
if (!sort) return void 0;
|
|
1086
|
-
if (typeof sort === "string") {
|
|
1087
|
-
return sort;
|
|
1088
|
-
}
|
|
1089
|
-
if (Array.isArray(sort)) {
|
|
1090
|
-
if (sort.length === 0) return void 0;
|
|
1091
|
-
if (typeof sort[0] === "object" && "column" in sort[0]) {
|
|
1092
|
-
return sort.map((s) => `${s.column}:${s.order.toLowerCase()}`).join(",");
|
|
1093
|
-
}
|
|
1094
|
-
return sort.map((s) => {
|
|
1095
|
-
if (s.startsWith("-")) {
|
|
1096
|
-
return `${s.substring(1)}:desc`;
|
|
1097
|
-
}
|
|
1098
|
-
if (s.includes(":")) {
|
|
1099
|
-
return s;
|
|
1100
|
-
}
|
|
1101
|
-
return `${s}:asc`;
|
|
1102
|
-
}).join(",");
|
|
1103
|
-
}
|
|
1104
|
-
if (typeof sort === "object") {
|
|
1105
|
-
const entries = Object.entries(sort);
|
|
1106
|
-
if (entries.length === 0) return void 0;
|
|
1107
|
-
return entries.map(([field, direction]) => `${field}:${direction.toLowerCase()}`).join(",");
|
|
1108
|
-
}
|
|
1109
|
-
return void 0;
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
1083
|
// src/modules/items.ts
|
|
1113
1084
|
var QueryBuilder = class {
|
|
1114
1085
|
collection;
|
|
@@ -1416,12 +1387,8 @@ var ItemsModule = class {
|
|
|
1416
1387
|
* ```
|
|
1417
1388
|
*/
|
|
1418
1389
|
async find(params) {
|
|
1419
|
-
const normalizedParams = params ? {
|
|
1420
|
-
...params,
|
|
1421
|
-
sort: normalizeSort(params.sort)
|
|
1422
|
-
} : void 0;
|
|
1423
1390
|
return this.client.get(`/items/${this.collection}`, {
|
|
1424
|
-
params
|
|
1391
|
+
params
|
|
1425
1392
|
});
|
|
1426
1393
|
}
|
|
1427
1394
|
/**
|
|
@@ -1837,12 +1804,8 @@ var FilesModule = class {
|
|
|
1837
1804
|
* ```
|
|
1838
1805
|
*/
|
|
1839
1806
|
async find(params) {
|
|
1840
|
-
const normalizedParams = params ? {
|
|
1841
|
-
...params,
|
|
1842
|
-
sort: normalizeSort(params.sort)
|
|
1843
|
-
} : void 0;
|
|
1844
1807
|
return this.client.get("/files", {
|
|
1845
|
-
params
|
|
1808
|
+
params
|
|
1846
1809
|
});
|
|
1847
1810
|
}
|
|
1848
1811
|
/**
|
|
@@ -2011,6 +1974,35 @@ var FilesModule = class {
|
|
|
2011
1974
|
}
|
|
2012
1975
|
};
|
|
2013
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
|
+
|
|
2014
2006
|
// src/modules/schemas.ts
|
|
2015
2007
|
var SchemasModule = class {
|
|
2016
2008
|
client;
|
|
@@ -2656,7 +2648,7 @@ var ReportsModule = class {
|
|
|
2656
2648
|
this.client = config.client;
|
|
2657
2649
|
}
|
|
2658
2650
|
/**
|
|
2659
|
-
* Generate a report for a collection
|
|
2651
|
+
* Generate a report for a collection using POST method
|
|
2660
2652
|
*
|
|
2661
2653
|
* @example
|
|
2662
2654
|
* ```typescript
|
|
@@ -2666,7 +2658,7 @@ var ReportsModule = class {
|
|
|
2666
2658
|
* revenue: { function: 'sum', field: 'total' },
|
|
2667
2659
|
* orders: { function: 'count', field: 'id' }
|
|
2668
2660
|
* },
|
|
2669
|
-
* groupBy: 'month',
|
|
2661
|
+
* groupBy: ['month'],
|
|
2670
2662
|
* dateRange: {
|
|
2671
2663
|
* start: '2025-01-01',
|
|
2672
2664
|
* end: '2025-12-31'
|
|
@@ -2682,19 +2674,56 @@ var ReportsModule = class {
|
|
|
2682
2674
|
return response;
|
|
2683
2675
|
}
|
|
2684
2676
|
/**
|
|
2685
|
-
*
|
|
2677
|
+
* Query a report for a collection using GET method with query params
|
|
2678
|
+
*
|
|
2679
|
+
* @example
|
|
2680
|
+
* ```typescript
|
|
2681
|
+
* const report = await baasix.reports.query('orders', {
|
|
2682
|
+
* aggregate: {
|
|
2683
|
+
* total: { function: 'sum', field: 'amount' }
|
|
2684
|
+
* },
|
|
2685
|
+
* groupBy: ['status']
|
|
2686
|
+
* });
|
|
2687
|
+
* ```
|
|
2688
|
+
*/
|
|
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
|
|
2686
2698
|
*
|
|
2687
2699
|
* @example
|
|
2688
2700
|
* ```typescript
|
|
2689
|
-
* const stats = await baasix.reports.getStats(
|
|
2690
|
-
*
|
|
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
|
+
* ]);
|
|
2691
2720
|
* ```
|
|
2692
2721
|
*/
|
|
2693
|
-
async getStats(
|
|
2694
|
-
const response = await this.client.
|
|
2695
|
-
|
|
2722
|
+
async getStats(stats) {
|
|
2723
|
+
const response = await this.client.post(`/reports/stats`, {
|
|
2724
|
+
stats
|
|
2696
2725
|
});
|
|
2697
|
-
return response
|
|
2726
|
+
return response;
|
|
2698
2727
|
}
|
|
2699
2728
|
/**
|
|
2700
2729
|
* Generate an aggregation query
|