@machhub-dev/sdk-ts 0.0.14 → 0.0.15

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.
@@ -12,7 +12,7 @@ export declare class Collection {
12
12
  protected collectionName: string;
13
13
  protected queryParams: Record<string, any>;
14
14
  constructor(httpService: HTTPService, mqttService: MQTTService | null, collectionName: string);
15
- filter(fieldName: string, operator: "=" | ">" | "<" | "<=" | ">=" | "!=", value: any): Collection;
15
+ filter(fieldName: string, operator: "=" | ">" | "<" | "<=" | ">=" | "!=" | "CONTAINS", value: any): Collection;
16
16
  sort(field: string, direction?: "asc" | "desc"): Collection;
17
17
  limit(limit: number): Collection;
18
18
  offset(offset: number): Collection;
@@ -22,6 +22,9 @@ export declare class Collection {
22
22
  getAll(options?: {
23
23
  expand?: string | string[];
24
24
  }): Promise<any[]>;
25
+ count(options?: {
26
+ filter?: any;
27
+ }): Promise<number>;
25
28
  getOne(id: string): Promise<any>;
26
29
  create(data: Record<string, any>): Promise<any>;
27
30
  update(id: string, data: Record<string, any>): Promise<any>;
@@ -63,6 +63,18 @@ class Collection {
63
63
  throw new CollectionError('getAll', this.collectionName, error);
64
64
  }
65
65
  }
66
+ async count(options) {
67
+ try {
68
+ this.applyOptions(options);
69
+ // Build query parameters for filters
70
+ const response = await this.httpService.request.get(`${this.collectionName}/count`, this.queryParams);
71
+ // Extract count from response
72
+ return response.count;
73
+ }
74
+ catch (error) {
75
+ throw new CollectionError('count', this.collectionName, error);
76
+ }
77
+ }
66
78
  async getOne(id) {
67
79
  if (!id) {
68
80
  throw new Error("ID must be provided");
@@ -12,7 +12,7 @@ export declare class Collection {
12
12
  protected collectionName: string;
13
13
  protected queryParams: Record<string, any>;
14
14
  constructor(httpService: HTTPService, mqttService: MQTTService | null, collectionName: string);
15
- filter(fieldName: string, operator: "=" | ">" | "<" | "<=" | ">=" | "!=", value: any): Collection;
15
+ filter(fieldName: string, operator: "=" | ">" | "<" | "<=" | ">=" | "!=" | "CONTAINS", value: any): Collection;
16
16
  sort(field: string, direction?: "asc" | "desc"): Collection;
17
17
  limit(limit: number): Collection;
18
18
  offset(offset: number): Collection;
@@ -22,6 +22,9 @@ export declare class Collection {
22
22
  getAll(options?: {
23
23
  expand?: string | string[];
24
24
  }): Promise<any[]>;
25
+ count(options?: {
26
+ filter?: any;
27
+ }): Promise<number>;
25
28
  getOne(id: string): Promise<any>;
26
29
  create(data: Record<string, any>): Promise<any>;
27
30
  update(id: string, data: Record<string, any>): Promise<any>;
@@ -59,6 +59,18 @@ export class Collection {
59
59
  throw new CollectionError('getAll', this.collectionName, error);
60
60
  }
61
61
  }
62
+ async count(options) {
63
+ try {
64
+ this.applyOptions(options);
65
+ // Build query parameters for filters
66
+ const response = await this.httpService.request.get(`${this.collectionName}/count`, this.queryParams);
67
+ // Extract count from response
68
+ return response.count;
69
+ }
70
+ catch (error) {
71
+ throw new CollectionError('count', this.collectionName, error);
72
+ }
73
+ }
62
74
  async getOne(id) {
63
75
  if (!id) {
64
76
  throw new Error("ID must be provided");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/sdk-ts",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "MACHHUB TYPESCRIPT SDK",
5
5
  "keywords": [
6
6
  "machhub",
@@ -28,7 +28,7 @@ export class Collection {
28
28
  }
29
29
 
30
30
 
31
- filter(fieldName: string, operator: "=" | ">" | "<" | "<=" | ">=" | "!=", value: any): Collection {
31
+ filter(fieldName: string, operator: "=" | ">" | "<" | "<=" | ">=" | "!=" | "CONTAINS", value: any): Collection {
32
32
  this.queryParams[`filter[${fieldName}][${operator}][${typeof value}]`] = value;
33
33
  return this;
34
34
  }
@@ -80,6 +80,20 @@ export class Collection {
80
80
  }
81
81
  }
82
82
 
83
+ async count(options?: { filter?: any }): Promise<number> {
84
+ try {
85
+ this.applyOptions(options);
86
+
87
+ // Build query parameters for filters
88
+ const response: { count: number } = await this.httpService.request.get(`${this.collectionName}/count`, this.queryParams);
89
+
90
+ // Extract count from response
91
+ return response.count;
92
+ } catch (error) {
93
+ throw new CollectionError('count', this.collectionName, error as Error);
94
+ }
95
+ }
96
+
83
97
  async getOne(id: string): Promise<any> {
84
98
  if (!id) {
85
99
  throw new Error("ID must be provided");