@machhub-dev/sdk-ts 0.0.16 → 1.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/sdk-ts",
3
- "version": "0.0.16",
3
+ "version": "1.0.0",
4
4
  "description": "MACHHUB TYPESCRIPT SDK",
5
5
  "keywords": [
6
6
  "machhub",
@@ -1,5 +1,6 @@
1
1
  import { HTTPService } from "../services/http.service.js";
2
2
  import { MQTTService } from "../services/mqtt.service.js";
3
+ import { Operator } from "../types/operator.models.js";
3
4
 
4
5
  export class CollectionError extends Error {
5
6
  public operation: string;
@@ -28,7 +29,7 @@ export class Collection {
28
29
  }
29
30
 
30
31
 
31
- filter(fieldName: string, operator: "=" | ">" | "<" | "<=" | ">=" | "!=" | "CONTAINS" | "IN", value: any): Collection {
32
+ filter(fieldName: string, operator: Operator, value: any): Collection {
32
33
  this.queryParams[`filter[${fieldName}][${operator}][${typeof value}]`] = value;
33
34
  return this;
34
35
  }
@@ -68,11 +69,14 @@ export class Collection {
68
69
  return results[0] ?? null
69
70
  }
70
71
 
71
- async getAll(options?: { expand?: string | string[] }): Promise<any[]> {
72
+ async getAll(options?: { expand?: string | string[], fields?: string | string[] }): Promise<any[]> {
72
73
  try {
73
74
  this.applyOptions(options)
74
75
  if (options?.expand) {
75
- this.queryParams.expand = Array.isArray(options.expand) ? options.expand.join() : options.expand
76
+ this.queryParams.expand = Array.isArray(options.expand) ? options.expand.join(",") : options.expand
77
+ }
78
+ if (options?.fields) {
79
+ this.queryParams.fields = Array.isArray(options.fields) ? options.fields.join(",") : options.fields
76
80
  }
77
81
  return await this.httpService.request.get(this.collectionName + "/all", this.queryParams);
78
82
  } catch (error) {
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export { SDK, type SDKConfig } from './sdk-ts.js';
2
2
 
3
3
  // Export individual types
4
4
  export type { LoginResponse, PermissionResponse, User, Group, Feature, Permission, ActionResponse, Action, Scope } from './types/auth.models.js';
5
+ export type { Operator } from './types/operator.models.js';
5
6
  export type { BaseResponse } from './types/response.models.js';
6
7
  export type { RecordID } from './types/recordID.models.js';
7
8
  export type { HistorizedData } from './types/tag.models.js';
@@ -0,0 +1,68 @@
1
+ /**
2
+ * SurrealDB Operators
3
+ * Reference: https://surrealdb.com/docs/surrealql/operators
4
+ */
5
+
6
+ /**
7
+ * Comparison operators
8
+ */
9
+ export type ComparisonOperator =
10
+ | "=" // Equal to
11
+ | "!=" // Not equal to
12
+ | "==" // Exact equality
13
+ | "?=" // Matches a condition
14
+ | "*=" // All match a condition
15
+ | "~" // Contains / matches regex
16
+ | "!~" // Does not contain / match regex
17
+ | "?~" // Matches a condition (fuzzy)
18
+ | "*~" // All match a condition (fuzzy)
19
+ | "<" // Less than
20
+ | "<=" // Less than or equal to
21
+ | ">" // Greater than
22
+ | ">=" // Greater than or equal to;
23
+
24
+ /**
25
+ * Containment operators
26
+ */
27
+ export type ContainmentOperator =
28
+ | "CONTAINS" // Contains a value
29
+ | "CONTAINSNOT" // Does not contain a value
30
+ | "CONTAINSALL" // Contains all values
31
+ | "CONTAINSANY" // Contains any value
32
+ | "CONTAINSNONE" // Contains none of the values
33
+ | "INSIDE" // Value is inside
34
+ | "NOTINSIDE" // Value is not inside
35
+ | "ALLINSIDE" // All values are inside
36
+ | "ANYINSIDE" // Any value is inside
37
+ | "NONEINSIDE"; // No values are inside
38
+
39
+ /**
40
+ * String operators
41
+ */
42
+ export type StringOperator =
43
+ | "@@" // Matches a condition (full-text search)
44
+ | "@0@" // Matches a condition (exact match)
45
+ | "@1@" // Matches a condition (fuzzy match level 1)
46
+ | "@2@" // Matches a condition (fuzzy match level 2)
47
+ | "@3@"; // Matches a condition (fuzzy match level 3)
48
+
49
+ /**
50
+ * Array operators
51
+ */
52
+ export type ArrayOperator =
53
+ | "IN" // Value is in array
54
+ | "NOT IN"; // Value is not in array
55
+
56
+ /**
57
+ * All available operators in SurrealDB
58
+ */
59
+ export type Operator =
60
+ | ComparisonOperator
61
+ | ContainmentOperator
62
+ | StringOperator
63
+ | ArrayOperator;
64
+
65
+ /**
66
+ * Common operators for basic queries
67
+ */
68
+ export type BasicOperator = "=" | "!=" | "<" | "<=" | ">" | ">=" | "CONTAINS" | "IN";