@hpcc-js/comms 3.12.0 → 3.13.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": "@hpcc-js/comms",
3
- "version": "3.12.0",
3
+ "version": "3.13.0",
4
4
  "description": "hpcc-js - Communications",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.cjs",
@@ -74,15 +74,15 @@
74
74
  "wsdl-all": "npm-run-all --aggregate-output -c --serial build --parallel wsdl-*"
75
75
  },
76
76
  "dependencies": {
77
- "@hpcc-js/util": "^3.4.2",
77
+ "@hpcc-js/util": "^3.4.4",
78
78
  "@xmldom/xmldom": "0.9.8",
79
79
  "abort-controller": "3.0.0",
80
80
  "node-fetch": "3.3.2",
81
81
  "undici": "7.16.0"
82
82
  },
83
83
  "devDependencies": {
84
- "@hpcc-js/ddl-shim": "^3.2.2",
85
- "@hpcc-js/esbuild-plugins": "^1.7.0",
84
+ "@hpcc-js/ddl-shim": "^3.2.3",
85
+ "@hpcc-js/esbuild-plugins": "^1.8.0",
86
86
  "@kubernetes/client-node": "1.4.0",
87
87
  "@types/d3-request": "1.0.9",
88
88
  "@types/d3-time-format": "2.3.4",
@@ -112,5 +112,5 @@
112
112
  "esp",
113
113
  "HPCC-Platform"
114
114
  ],
115
- "gitHead": "5e5fc8d746e6a42c58da2ec4f55f2f7cbaeff611"
115
+ "gitHead": "70194f16ed27ea1167af126b35cbf4af5f181be9"
116
116
  }
package/src/connection.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { join, promiseTimeout, scopedLogger } from "@hpcc-js/util";
1
+ import { join, promiseTimeout, scopedLogger, utf8ToBase64 } from "@hpcc-js/util";
2
2
 
3
3
  const logger = scopedLogger("comms/connection.ts");
4
4
 
@@ -137,7 +137,7 @@ export function jsonp(opts: IOptions, action: string, request: any = {}, respons
137
137
  }
138
138
 
139
139
  function authHeader(opts: IOptions): object {
140
- return opts.userID ? { Authorization: `Basic ${btoa(`${opts.userID}:${opts.password}`)}` } : {};
140
+ return opts.userID ? { Authorization: `Basic ${utf8ToBase64(`${opts.userID}:${opts.password}`)}` } : {};
141
141
  }
142
142
 
143
143
  // _omitMap is a workaround for older HPCC-Platform instances without credentials ---
@@ -1,5 +1,4 @@
1
1
  export * from "./__package__.ts";
2
-
3
2
  export * from "./services/fileSpray.ts";
4
3
  export * from "./services/wsAccess.ts";
5
4
  export * from "./services/wsAccount.ts";
package/src/index.node.ts CHANGED
@@ -7,6 +7,7 @@ root.DOMParser = DOMParser;
7
7
  import fetch, { Headers, Request, Response, } from "node-fetch";
8
8
 
9
9
  import * as https from "node:https";
10
+ import { Buffer } from "node:buffer";
10
11
  import { Agent, setGlobalDispatcher } from "undici";
11
12
 
12
13
  if (typeof root.fetch === "undefined") {
@@ -57,14 +58,6 @@ root.fetch.__trustwaveAgent = new https.Agent({
57
58
  ca: globalCA + trustwave
58
59
  });
59
60
 
60
- // btoa polyfill ---
61
- import { Buffer } from "node:buffer";
62
- if (typeof root.btoa === "undefined") {
63
- root.btoa = function (str: string) {
64
- return Buffer.from(str || "", "utf8").toString("base64");
65
- };
66
- }
67
-
68
61
  export * from "./index.common.ts";
69
62
 
70
63
  // Client Tools ---
@@ -1,3 +1,4 @@
1
+ import { timeParse } from "d3-time-format";
1
2
  import { SMCServiceBase, WsSMC } from "./wsdl/WsSMC/v1.28/WsSMC.ts";
2
3
  import { IOptions } from "../connection.ts";
3
4
 
@@ -5,6 +6,20 @@ export {
5
6
  WsSMC
6
7
  };
7
8
 
9
+ const dateParser = timeParse("%Y%m%d%H");
10
+
11
+ function isNumeric(value: any): boolean {
12
+ return typeof value === "number" || (typeof value === "string" && value.trim() !== "" && !isNaN(+value));
13
+ }
14
+
15
+ export interface NormalisedGlobalMetric {
16
+ Category: string;
17
+ Start: Date;
18
+ End: Date;
19
+ dimensions: { [key: string]: any };
20
+ stats: { [key: string]: any };
21
+ }
22
+
8
23
  export class SMCService extends SMCServiceBase {
9
24
 
10
25
  connectionOptions(): IOptions {
@@ -21,4 +36,45 @@ export class SMCService extends SMCServiceBase {
21
36
  };
22
37
  });
23
38
  }
39
+
40
+ protected parseGlobalMetric(name: string, value: any): any {
41
+ // Known Prefixes: Cost, Critical, Definition, Disk, Distribute, Ecl, Enum, Id, Interface, Is, Library, Load, Match, Meta, Num, Original, Output, Patch, Per, Persist, Predicted, Record, Section, Service, Signed, Size, Source, Spill, Target, Time, Updated, When
42
+ if (name.startsWith("Cost")) {
43
+ return +value / 1000000;
44
+ } else if (name.startsWith("Date")) {
45
+ return dateParser(value);
46
+ } else if (name.startsWith("Num")) {
47
+ return +value;
48
+ } else if (name.startsWith("Time")) {
49
+ return +value / 1000000000;
50
+ } else if (name.startsWith("When")) {
51
+ return new Date(+value / 1000).toISOString();
52
+ } else if (isNumeric(value)) {
53
+ return +value;
54
+ }
55
+ return value;
56
+ }
57
+
58
+ GetNormalisedGlobalMetrics(request: Partial<WsSMC.GetGlobalMetrics>): Promise<NormalisedGlobalMetric[]> {
59
+ return super.GetGlobalMetrics(request).then(response => {
60
+ const retVal: NormalisedGlobalMetric[] = [];
61
+ for (const metric of response?.GlobalMetrics?.GlobalMetric || []) {
62
+ const row: NormalisedGlobalMetric = {
63
+ Category: metric.Category,
64
+ Start: this.parseGlobalMetric("Date", metric.DateTimeRange?.Start),
65
+ End: this.parseGlobalMetric("Date", metric.DateTimeRange?.End),
66
+ dimensions: {},
67
+ stats: {}
68
+ };
69
+ for (const dimension of metric.Dimensions?.Dimension || []) {
70
+ row.dimensions[dimension.Name] = dimension.Value;
71
+ }
72
+ for (const stat of metric.Stats?.Stat || []) {
73
+ row.stats[stat.Name] = this.parseGlobalMetric(stat.Name, stat.Value);
74
+ }
75
+ retVal.push(row);
76
+ }
77
+ return retVal;
78
+ });
79
+ }
24
80
  }
@@ -1,7 +1,20 @@
1
1
  import { SMCServiceBase, WsSMC } from "./wsdl/WsSMC/v1.28/WsSMC.ts";
2
2
  import { IOptions } from "../connection.ts";
3
3
  export { WsSMC };
4
+ export interface NormalisedGlobalMetric {
5
+ Category: string;
6
+ Start: Date;
7
+ End: Date;
8
+ dimensions: {
9
+ [key: string]: any;
10
+ };
11
+ stats: {
12
+ [key: string]: any;
13
+ };
14
+ }
4
15
  export declare class SMCService extends SMCServiceBase {
5
16
  connectionOptions(): IOptions;
6
17
  Activity(request: WsSMC.Activity): Promise<WsSMC.ActivityResponse>;
18
+ protected parseGlobalMetric(name: string, value: any): any;
19
+ GetNormalisedGlobalMetrics(request: Partial<WsSMC.GetGlobalMetrics>): Promise<NormalisedGlobalMetric[]>;
7
20
  }