@machhub-dev/sdk-ts 0.0.15 → 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: "=" | ">" | "<" | "<=" | ">=" | "!=" | "CONTAINS", 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;
@@ -25,7 +25,9 @@ export declare class Collection {
25
25
  count(options?: {
26
26
  filter?: any;
27
27
  }): Promise<number>;
28
- getOne(id: string): Promise<any>;
28
+ getOne(id: string, options?: {
29
+ expand?: string | string[];
30
+ }): Promise<any>;
29
31
  create(data: Record<string, any>): Promise<any>;
30
32
  update(id: string, data: Record<string, any>): Promise<any>;
31
33
  delete(id: string): Promise<any>;
@@ -75,12 +75,19 @@ class Collection {
75
75
  throw new CollectionError('count', this.collectionName, error);
76
76
  }
77
77
  }
78
- async getOne(id) {
78
+ async getOne(id, options) {
79
79
  if (!id) {
80
80
  throw new Error("ID must be provided");
81
81
  }
82
82
  try {
83
- 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);
84
91
  }
85
92
  catch (error) {
86
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: "=" | ">" | "<" | "<=" | ">=" | "!=" | "CONTAINS", 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;
@@ -25,7 +25,9 @@ export declare class Collection {
25
25
  count(options?: {
26
26
  filter?: any;
27
27
  }): Promise<number>;
28
- getOne(id: string): Promise<any>;
28
+ getOne(id: string, options?: {
29
+ expand?: string | string[];
30
+ }): Promise<any>;
29
31
  create(data: Record<string, any>): Promise<any>;
30
32
  update(id: string, data: Record<string, any>): Promise<any>;
31
33
  delete(id: string): Promise<any>;
@@ -71,12 +71,19 @@ export class Collection {
71
71
  throw new CollectionError('count', this.collectionName, error);
72
72
  }
73
73
  }
74
- async getOne(id) {
74
+ async getOne(id, options) {
75
75
  if (!id) {
76
76
  throw new Error("ID must be provided");
77
77
  }
78
78
  try {
79
- 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);
80
87
  }
81
88
  catch (error) {
82
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.15",
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: "=" | ">" | "<" | "<=" | ">=" | "!=" | "CONTAINS", 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
  }
@@ -93,18 +93,26 @@ export class Collection {
93
93
  throw new CollectionError('count', this.collectionName, error as Error);
94
94
  }
95
95
  }
96
-
97
- async getOne(id: string): Promise<any> {
96
+
97
+ async getOne(id: string, options?: { expand?: string | string[] }): Promise<any> {
98
98
  if (!id) {
99
99
  throw new Error("ID must be provided");
100
100
  }
101
101
  try {
102
- 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);
103
112
  } catch (error) {
104
113
  throw new CollectionError('getOne', this.collectionName, error as Error);
105
114
  }
106
115
  }
107
-
108
116
  async create(data: Record<string, any>): Promise<any> {
109
117
  try {
110
118
  const formData = new FormData();