@machhub-dev/sdk-ts 0.0.4 → 0.0.6

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.
@@ -9,4 +9,5 @@ export declare class Historian {
9
9
  getHistoricalData(topic: string, start_time: Date, range?: string): Promise<HistorizedData[]>;
10
10
  subscribeLiveData(topic: string, callback: (data: any) => void): Promise<any>;
11
11
  getLastNValues(topic: string, n: number): Promise<HistorizedData[]>;
12
+ query(SurrealQL: string): Promise<any>;
12
13
  }
@@ -36,5 +36,10 @@ class Historian {
36
36
  sort: "desc", // Fetch the latest values
37
37
  }).patch("historian/last");
38
38
  }
39
+ async query(SurrealQL) {
40
+ return this.httpService.request.withJSON({
41
+ query: SurrealQL
42
+ }).post("historian/query");
43
+ }
39
44
  }
40
45
  exports.Historian = Historian;
@@ -137,7 +137,7 @@ class SDK {
137
137
  */
138
138
  async Initialize(config) {
139
139
  try {
140
- console.log("Initializing SDK with config:", config);
140
+ // console.log("Initializing SDK with config:", config)
141
141
  // Methods to initialize config
142
142
  // 1. Via application_id + URLs + developer key passed in config parameter
143
143
  // 2. Via development server - Set via Extension/
@@ -146,9 +146,9 @@ class SDK {
146
146
  config = { application_id: "" };
147
147
  if (!config.application_id)
148
148
  config = { application_id: "" };
149
- console.log("Using application_id:", config.application_id);
149
+ // console.log("Using application_id:", config.application_id);
150
150
  const PORT = await getEnvPort();
151
- console.log("Using port:", PORT);
151
+ // console.log("Using port:", PORT);
152
152
  if (!config.httpUrl) {
153
153
  config.httpUrl = "http://localhost:" + PORT;
154
154
  }
@@ -159,7 +159,7 @@ class SDK {
159
159
  config.natsUrl = "ws://localhost:" + PORT + "/nats";
160
160
  }
161
161
  const { application_id, httpUrl, mqttUrl, natsUrl } = config;
162
- console.log("Final config:", { application_id, httpUrl, mqttUrl, natsUrl });
162
+ // console.log("Final config:", { application_id, httpUrl, mqttUrl, natsUrl });
163
163
  this.http = new HTTPClient(application_id, httpUrl, config.developer_key);
164
164
  this.mqtt = await MQTTClient.getInstance(application_id, mqttUrl, config.developer_key);
165
165
  this.nats = await NATSClient.getInstance(application_id, natsUrl);
@@ -235,7 +235,6 @@ class SDK {
235
235
  }
236
236
  exports.SDK = SDK;
237
237
  async function getEnvPort() {
238
- console.log(window.location.origin);
239
238
  try {
240
239
  const response = await fetchData(window.location.origin + "/_cfg");
241
240
  // console.log('Response:', response);
@@ -82,7 +82,7 @@ class MQTTService {
82
82
  }
83
83
  attachMessageListener() {
84
84
  this.client.on('connect', () => {
85
- console.log("MQTT connected to", this.url);
85
+ // console.log("MQTT connected to", this.url);
86
86
  });
87
87
  this.client.on('error', (error) => {
88
88
  console.error("MQTT connection error:", error);
@@ -9,4 +9,5 @@ export declare class Historian {
9
9
  getHistoricalData(topic: string, start_time: Date, range?: string): Promise<HistorizedData[]>;
10
10
  subscribeLiveData(topic: string, callback: (data: any) => void): Promise<any>;
11
11
  getLastNValues(topic: string, n: number): Promise<HistorizedData[]>;
12
+ query(SurrealQL: string): Promise<any>;
12
13
  }
@@ -33,4 +33,9 @@ export class Historian {
33
33
  sort: "desc", // Fetch the latest values
34
34
  }).patch("historian/last");
35
35
  }
36
+ async query(SurrealQL) {
37
+ return this.httpService.request.withJSON({
38
+ query: SurrealQL
39
+ }).post("historian/query");
40
+ }
36
41
  }
package/dist/sdk-ts.js CHANGED
@@ -134,7 +134,7 @@ export class SDK {
134
134
  */
135
135
  async Initialize(config) {
136
136
  try {
137
- console.log("Initializing SDK with config:", config);
137
+ // console.log("Initializing SDK with config:", config)
138
138
  // Methods to initialize config
139
139
  // 1. Via application_id + URLs + developer key passed in config parameter
140
140
  // 2. Via development server - Set via Extension/
@@ -143,9 +143,9 @@ export class SDK {
143
143
  config = { application_id: "" };
144
144
  if (!config.application_id)
145
145
  config = { application_id: "" };
146
- console.log("Using application_id:", config.application_id);
146
+ // console.log("Using application_id:", config.application_id);
147
147
  const PORT = await getEnvPort();
148
- console.log("Using port:", PORT);
148
+ // console.log("Using port:", PORT);
149
149
  if (!config.httpUrl) {
150
150
  config.httpUrl = "http://localhost:" + PORT;
151
151
  }
@@ -156,7 +156,7 @@ export class SDK {
156
156
  config.natsUrl = "ws://localhost:" + PORT + "/nats";
157
157
  }
158
158
  const { application_id, httpUrl, mqttUrl, natsUrl } = config;
159
- console.log("Final config:", { application_id, httpUrl, mqttUrl, natsUrl });
159
+ // console.log("Final config:", { application_id, httpUrl, mqttUrl, natsUrl });
160
160
  this.http = new HTTPClient(application_id, httpUrl, config.developer_key);
161
161
  this.mqtt = await MQTTClient.getInstance(application_id, mqttUrl, config.developer_key);
162
162
  this.nats = await NATSClient.getInstance(application_id, natsUrl);
@@ -231,7 +231,6 @@ export class SDK {
231
231
  }
232
232
  }
233
233
  async function getEnvPort() {
234
- console.log(window.location.origin);
235
234
  try {
236
235
  const response = await fetchData(window.location.origin + "/_cfg");
237
236
  // console.log('Response:', response);
@@ -76,7 +76,7 @@ export class MQTTService {
76
76
  }
77
77
  attachMessageListener() {
78
78
  this.client.on('connect', () => {
79
- console.log("MQTT connected to", this.url);
79
+ // console.log("MQTT connected to", this.url);
80
80
  });
81
81
  this.client.on('error', (error) => {
82
82
  console.error("MQTT connection error:", error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/sdk-ts",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "MACHHUB TYPESCRIPT SDK",
5
5
  "keywords": [
6
6
  "machhub",
@@ -23,11 +23,11 @@
23
23
  "mqtt": "^5.10.4",
24
24
  "safe-buffer": "^5.2.1",
25
25
  "typescript": "^5.8.3",
26
- "undici-types": "^7.4.0"
26
+ "undici-types": "^7.4.0",
27
+ "@nats-io/nats-core": "^3.0.2",
28
+ "@nats-io/transport-node": "^3.0.2"
27
29
  },
28
30
  "devDependencies": {
29
- "@nats-io/nats-core": "^3.0.2",
30
- "@nats-io/transport-node": "^3.0.2",
31
31
  "@types/node": "^22.13.5"
32
32
  }
33
- }
33
+ }
@@ -46,4 +46,10 @@ export class Historian {
46
46
  sort: "desc", // Fetch the latest values
47
47
  }).patch("historian/last");
48
48
  }
49
+
50
+ async query(SurrealQL:string): Promise<any> {
51
+ return this.httpService.request.withJSON({
52
+ query: SurrealQL
53
+ }).post("historian/query");
54
+ }
49
55
  }
package/src/sdk-ts.ts CHANGED
@@ -161,7 +161,7 @@ export class SDK {
161
161
  */
162
162
  public async Initialize(config?: SDKConfig): Promise<boolean> {
163
163
  try {
164
- console.log("Initializing SDK with config:", config)
164
+ // console.log("Initializing SDK with config:", config)
165
165
 
166
166
  // Methods to initialize config
167
167
  // 1. Via application_id + URLs + developer key passed in config parameter
@@ -170,11 +170,11 @@ export class SDK {
170
170
 
171
171
  if (config === undefined) config = { application_id: "" }
172
172
  if (!config.application_id) config = { application_id: "" }
173
- console.log("Using application_id:", config.application_id);
173
+ // console.log("Using application_id:", config.application_id);
174
174
 
175
175
 
176
176
  const PORT = await getEnvPort();
177
- console.log("Using port:", PORT);
177
+ // console.log("Using port:", PORT);
178
178
 
179
179
  if (!config.httpUrl) {
180
180
  config.httpUrl = "http://localhost:" + PORT;
@@ -190,8 +190,7 @@ export class SDK {
190
190
 
191
191
  const { application_id, httpUrl, mqttUrl, natsUrl } = config;
192
192
 
193
- console.log("Final config:", { application_id, httpUrl, mqttUrl, natsUrl });
194
-
193
+ // console.log("Final config:", { application_id, httpUrl, mqttUrl, natsUrl });
195
194
 
196
195
  this.http = new HTTPClient(application_id, httpUrl, config.developer_key);
197
196
  this.mqtt = await MQTTClient.getInstance(application_id, mqttUrl, config.developer_key);
@@ -275,7 +274,6 @@ export class SDK {
275
274
  }
276
275
 
277
276
  async function getEnvPort(): Promise<string> {
278
- console.log(window.location.origin)
279
277
  try {
280
278
  const response = await fetchData<{runtimeID:string, port:string}>(window.location.origin + "/_cfg");
281
279
  // console.log('Response:', response);
@@ -92,7 +92,7 @@ export class MQTTService {
92
92
 
93
93
  private attachMessageListener(): void {
94
94
  this.client.on('connect', () => {
95
- console.log("MQTT connected to", this.url);
95
+ // console.log("MQTT connected to", this.url);
96
96
  });
97
97
 
98
98
  this.client.on('error', (error: Error) => {