@machhub-dev/sdk-ts 0.0.13 → 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");
@@ -97,7 +109,17 @@ class Collection {
97
109
  throw new Error("ID must be provided");
98
110
  }
99
111
  try {
100
- return await this.httpService.request.withJSON(data).put(id);
112
+ const formData = new FormData();
113
+ for (const [key, value] of Object.entries(data)) {
114
+ if (value instanceof File) {
115
+ formData.append(key, value, value.name);
116
+ data[key] = value.name;
117
+ }
118
+ }
119
+ formData.append("record", JSON.stringify(data));
120
+ return await this.httpService.request
121
+ .withBody(formData)
122
+ .put(id);
101
123
  }
102
124
  catch (error) {
103
125
  throw new CollectionError('update', 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", 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");
@@ -93,7 +105,17 @@ export class Collection {
93
105
  throw new Error("ID must be provided");
94
106
  }
95
107
  try {
96
- return await this.httpService.request.withJSON(data).put(id);
108
+ const formData = new FormData();
109
+ for (const [key, value] of Object.entries(data)) {
110
+ if (value instanceof File) {
111
+ formData.append(key, value, value.name);
112
+ data[key] = value.name;
113
+ }
114
+ }
115
+ formData.append("record", JSON.stringify(data));
116
+ return await this.httpService.request
117
+ .withBody(formData)
118
+ .put(id);
97
119
  }
98
120
  catch (error) {
99
121
  throw new CollectionError('update', this.collectionName, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/sdk-ts",
3
- "version": "0.0.13",
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");
@@ -115,7 +129,19 @@ export class Collection {
115
129
  throw new Error("ID must be provided");
116
130
  }
117
131
  try {
118
- return await this.httpService.request.withJSON(data).put(id);
132
+ const formData = new FormData();
133
+
134
+ for (const [key, value] of Object.entries(data)) {
135
+ if (value instanceof File) {
136
+ formData.append(key, value, value.name);
137
+ data[key] = value.name;
138
+ }
139
+ }
140
+ formData.append("record", JSON.stringify(data));
141
+
142
+ return await this.httpService.request
143
+ .withBody(formData)
144
+ .put(id);
119
145
  } catch (error) {
120
146
  throw new CollectionError('update', this.collectionName, error as Error);
121
147
  }