@machhub-dev/sdk-ts 0.0.14 → 0.0.16

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" | "IN", 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,7 +22,12 @@ export declare class Collection {
22
22
  getAll(options?: {
23
23
  expand?: string | string[];
24
24
  }): Promise<any[]>;
25
- getOne(id: string): Promise<any>;
25
+ count(options?: {
26
+ filter?: any;
27
+ }): Promise<number>;
28
+ getOne(id: string, options?: {
29
+ expand?: string | string[];
30
+ }): Promise<any>;
26
31
  create(data: Record<string, any>): Promise<any>;
27
32
  update(id: string, data: Record<string, any>): Promise<any>;
28
33
  delete(id: string): Promise<any>;
@@ -63,12 +63,31 @@ class Collection {
63
63
  throw new CollectionError('getAll', this.collectionName, error);
64
64
  }
65
65
  }
66
- async getOne(id) {
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
+ }
78
+ async getOne(id, options) {
67
79
  if (!id) {
68
80
  throw new Error("ID must be provided");
69
81
  }
70
82
  try {
71
- return await this.httpService.request.get(id);
83
+ const queryParams = {};
84
+ // Handle expand parameter
85
+ if (options?.expand) {
86
+ queryParams.expand = Array.isArray(options.expand)
87
+ ? options.expand.join(',')
88
+ : options.expand;
89
+ }
90
+ return await this.httpService.request.get(id, queryParams);
72
91
  }
73
92
  catch (error) {
74
93
  throw new CollectionError('getOne', this.collectionName, error);
@@ -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" | "IN", 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,7 +22,12 @@ export declare class Collection {
22
22
  getAll(options?: {
23
23
  expand?: string | string[];
24
24
  }): Promise<any[]>;
25
- getOne(id: string): Promise<any>;
25
+ count(options?: {
26
+ filter?: any;
27
+ }): Promise<number>;
28
+ getOne(id: string, options?: {
29
+ expand?: string | string[];
30
+ }): Promise<any>;
26
31
  create(data: Record<string, any>): Promise<any>;
27
32
  update(id: string, data: Record<string, any>): Promise<any>;
28
33
  delete(id: string): Promise<any>;
@@ -59,12 +59,31 @@ export class Collection {
59
59
  throw new CollectionError('getAll', this.collectionName, error);
60
60
  }
61
61
  }
62
- async getOne(id) {
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
+ }
74
+ async getOne(id, options) {
63
75
  if (!id) {
64
76
  throw new Error("ID must be provided");
65
77
  }
66
78
  try {
67
- return await this.httpService.request.get(id);
79
+ const queryParams = {};
80
+ // Handle expand parameter
81
+ if (options?.expand) {
82
+ queryParams.expand = Array.isArray(options.expand)
83
+ ? options.expand.join(',')
84
+ : options.expand;
85
+ }
86
+ return await this.httpService.request.get(id, queryParams);
68
87
  }
69
88
  catch (error) {
70
89
  throw new CollectionError('getOne', this.collectionName, error);
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.16",
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" | "IN", value: any): Collection {
32
32
  this.queryParams[`filter[${fieldName}][${operator}][${typeof value}]`] = value;
33
33
  return this;
34
34
  }
@@ -80,17 +80,39 @@ export class Collection {
80
80
  }
81
81
  }
82
82
 
83
- async getOne(id: string): Promise<any> {
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
+
97
+ async getOne(id: string, options?: { expand?: string | string[] }): Promise<any> {
84
98
  if (!id) {
85
99
  throw new Error("ID must be provided");
86
100
  }
87
101
  try {
88
- return await this.httpService.request.get(id);
102
+ const queryParams: any = {};
103
+
104
+ // Handle expand parameter
105
+ if (options?.expand) {
106
+ queryParams.expand = Array.isArray(options.expand)
107
+ ? options.expand.join(',')
108
+ : options.expand;
109
+ }
110
+
111
+ return await this.httpService.request.get(id, queryParams);
89
112
  } catch (error) {
90
113
  throw new CollectionError('getOne', this.collectionName, error as Error);
91
114
  }
92
115
  }
93
-
94
116
  async create(data: Record<string, any>): Promise<any> {
95
117
  try {
96
118
  const formData = new FormData();