@xube/kit-aws-hooks 0.0.49 → 0.0.51

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/dist/generate.js CHANGED
@@ -18,7 +18,6 @@ const generateWebhookItems = (request) => {
18
18
  if (!webhookItems[aggregateKey]) {
19
19
  webhookItems[aggregateKey] = {
20
20
  s: Math.floor(time / 1000),
21
- us: time % 1000,
22
21
  type: constants_1.WEBHOOK_TYPE,
23
22
  account: request.account,
24
23
  endpoints: [endpoint],
package/dist/send.js CHANGED
@@ -22,6 +22,10 @@ const sendDataToEndpoints = async (webhookTableName, indexName, items, log = kit
22
22
  partitionKey: kit_aws_schema_1.SORT_KEY,
23
23
  });
24
24
  if (getWebhookEndpointsResponse.hasFailed()) {
25
+ if (getWebhookEndpointsResponse.statusCode === kit_constants_1.StatusCode.NotFound) {
26
+ log.info(`No webhook endpoints found for webhook endpoint ${item.id} and type ${types_1.WebhookTypes.data}`);
27
+ continue;
28
+ }
25
29
  log.error(`Failed to get webhook endpoints for webhook endpoint ${item.id} and type ${types_1.WebhookTypes.data}`);
26
30
  log.info(`${JSON.stringify(getWebhookEndpointsResponse, null, 2)}}`);
27
31
  return getWebhookEndpointsResponse.switchXubeResponseType();
@@ -55,6 +59,13 @@ const sendDataToEndpoints = async (webhookTableName, indexName, items, log = kit
55
59
  }
56
60
  }
57
61
  }
62
+ if (!endpointSends.length) {
63
+ log.info(`No endpoints found to send data to.`);
64
+ return new kit_request_1.XubeResponse({
65
+ statusCode: kit_constants_1.StatusCode.OK,
66
+ data: true,
67
+ });
68
+ }
58
69
  try {
59
70
  const responses = await Promise.all(endpointSends);
60
71
  const failedEndpointSendUrls = [];
package/dist/transform.js CHANGED
@@ -33,17 +33,25 @@ const getTimeSeriesDataFromData = (items) => {
33
33
  }
34
34
  else {
35
35
  const timeSeriesEntry = timeSeriesEntriesById[item.id];
36
- timeSeriesEntry.data.push(item.data);
37
36
  const timeDifference = Math.floor((microsSinceEpoch - previousMicroSecondsSinceEpochById?.[item.id]) /
38
37
  getDivisorByTimeUnit(timeSeriesEntry.dtt));
39
- if (timeDifference !== timeSeriesEntry.dt) {
38
+ timeSeriesEntry.data.push(item.data);
39
+ if (timeSeriesEntry.dt === 0) {
40
+ timeSeriesEntry.dt = timeDifference;
41
+ }
42
+ else if (timeDifference !== timeSeriesEntry.dt) {
40
43
  if (!timeSeriesEntry.dataT) {
41
- timeSeriesEntry.dataT = [];
44
+ timeSeriesEntry.dataT = [
45
+ {
46
+ i: timeSeriesEntry.data.length - 1,
47
+ dt: timeDifference,
48
+ },
49
+ ];
42
50
  }
43
51
  else {
44
52
  timeSeriesEntry.dataT.push({
45
53
  i: timeSeriesEntry.data.length - 1,
46
- dt: microsSinceEpoch - previousMicroSecondsSinceEpochById?.[item.id],
54
+ dt: timeDifference,
47
55
  });
48
56
  }
49
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xube/kit-aws-hooks",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -17,15 +17,15 @@
17
17
  },
18
18
  "homepage": "https://github.com/XubeLtd/dev-kit#readme",
19
19
  "devDependencies": {
20
- "@xube/kit-build": "^0.0.49"
20
+ "@xube/kit-build": "^0.0.51"
21
21
  },
22
22
  "dependencies": {
23
- "@xube/kit-aws": "^0.0.49",
24
- "@xube/kit-aws-schema": "^0.0.49",
25
- "@xube/kit-data-schema": "^0.0.49",
26
- "@xube/kit-log": "^0.0.49",
27
- "@xube/kit-request": "^0.0.49",
28
- "@xube/kit-schema": "^0.0.49",
23
+ "@xube/kit-aws": "^0.0.51",
24
+ "@xube/kit-aws-schema": "^0.0.51",
25
+ "@xube/kit-data-schema": "^0.0.51",
26
+ "@xube/kit-log": "^0.0.51",
27
+ "@xube/kit-request": "^0.0.51",
28
+ "@xube/kit-schema": "^0.0.51",
29
29
  "zod": "^3.22.4"
30
30
  }
31
31
  }
package/src/generate.ts CHANGED
@@ -24,7 +24,6 @@ export const generateWebhookItems = (
24
24
  if (!webhookItems[aggregateKey]) {
25
25
  webhookItems[aggregateKey] = {
26
26
  s: Math.floor(time / 1000),
27
- us: time % 1000,
28
27
  type: WEBHOOK_TYPE,
29
28
  account: request.account,
30
29
  endpoints: [endpoint],
package/src/send.ts CHANGED
@@ -39,6 +39,13 @@ export const sendDataToEndpoints = async (
39
39
  );
40
40
 
41
41
  if (getWebhookEndpointsResponse.hasFailed()) {
42
+ if (getWebhookEndpointsResponse.statusCode === StatusCode.NotFound) {
43
+ log.info(
44
+ `No webhook endpoints found for webhook endpoint ${item.id} and type ${WebhookTypes.data}`
45
+ );
46
+ continue;
47
+ }
48
+
42
49
  log.error(
43
50
  `Failed to get webhook endpoints for webhook endpoint ${item.id} and type ${WebhookTypes.data}`
44
51
  );
@@ -104,6 +111,14 @@ export const sendDataToEndpoints = async (
104
111
  }
105
112
  }
106
113
 
114
+ if (!endpointSends.length) {
115
+ log.info(`No endpoints found to send data to.`);
116
+ return new XubeResponse({
117
+ statusCode: StatusCode.OK,
118
+ data: true,
119
+ });
120
+ }
121
+
107
122
  try {
108
123
  const responses: Response[] = await Promise.all(endpointSends);
109
124
 
@@ -0,0 +1,89 @@
1
+ import { DATA_TYPE, ReadingV1 } from "@xube/kit-data-schema";
2
+ import { getTimeSeriesDataFromData, stageDataForSend } from "./transform";
3
+ import { TableItem } from "@xube/kit-aws-schema";
4
+ import { TimeSeries } from "@xube/kit-schema";
5
+
6
+ describe("getTimeSeriesDataFromData", () => {
7
+ it("should return an array of objects with the time series shape", () => {
8
+ const items: (ReadingV1 & TableItem)[] = [
9
+ {
10
+ PK: "",
11
+ SK: "",
12
+ data: "S,+000.30,+001.74,M,00,33",
13
+ s: 1697556567,
14
+ us: 136366,
15
+ type: DATA_TYPE,
16
+ id: "12345678",
17
+ },
18
+ {
19
+ PK: "",
20
+ SK: "",
21
+ data: "S,+000.35,+001.84,M,00,39",
22
+ s: 1697556567,
23
+ us: 336628,
24
+ type: DATA_TYPE,
25
+ id: "12345678",
26
+ },
27
+ {
28
+ PK: "",
29
+ SK: "",
30
+ data: "S,+000.26,+002.00,M,00,34",
31
+ s: 1697556567,
32
+ us: 539512,
33
+ type: DATA_TYPE,
34
+ id: "12345678",
35
+ },
36
+ {
37
+ PK: "",
38
+ SK: "",
39
+ data: "S,+000.34,+001.88,M,00,34",
40
+ s: 1697556567,
41
+ us: 736473,
42
+ type: DATA_TYPE,
43
+ id: "12345678",
44
+ },
45
+ {
46
+ PK: "",
47
+ SK: "",
48
+ data: "S,+000.35,+001.82,M,00,3F",
49
+ s: 1697556567,
50
+ us: 937183,
51
+ type: DATA_TYPE,
52
+ id: "12345678",
53
+ },
54
+ ];
55
+
56
+ const timeSeries: TimeSeries = getTimeSeriesDataFromData(items);
57
+
58
+ expect(timeSeries).toEqual([
59
+ {
60
+ v: "1",
61
+ m: {
62
+ id: "12345678",
63
+ trigger: DATA_TYPE,
64
+ source: "device",
65
+ },
66
+ t0: "2023-10-17T15:29:27.136366Z",
67
+ dtt: "ms",
68
+ dt: 200,
69
+ dataT: [
70
+ {
71
+ dt: 202,
72
+ i: 2,
73
+ },
74
+ {
75
+ dt: 196,
76
+ i: 3,
77
+ },
78
+ ],
79
+ data: [
80
+ "S,+000.30,+001.74,M,00,33",
81
+ "S,+000.35,+001.84,M,00,39",
82
+ "S,+000.26,+002.00,M,00,34",
83
+ "S,+000.34,+001.88,M,00,34",
84
+ "S,+000.35,+001.82,M,00,3F",
85
+ ],
86
+ },
87
+ ]);
88
+ });
89
+ });
package/src/transform.ts CHANGED
@@ -36,21 +36,27 @@ export const getTimeSeriesDataFromData = (items: TableItem[]): TimeSeries => {
36
36
  } else {
37
37
  const timeSeriesEntry = timeSeriesEntriesById[item.id];
38
38
 
39
- timeSeriesEntry.data.push(item.data);
40
-
41
39
  const timeDifference = Math.floor(
42
40
  (microsSinceEpoch - previousMicroSecondsSinceEpochById?.[item.id]) /
43
41
  getDivisorByTimeUnit(timeSeriesEntry.dtt)
44
42
  );
45
43
 
46
- if (timeDifference !== timeSeriesEntry.dt) {
44
+ timeSeriesEntry.data.push(item.data);
45
+
46
+ if (timeSeriesEntry.dt === 0) {
47
+ timeSeriesEntry.dt = timeDifference;
48
+ } else if (timeDifference !== timeSeriesEntry.dt) {
47
49
  if (!timeSeriesEntry.dataT) {
48
- timeSeriesEntry.dataT = [];
50
+ timeSeriesEntry.dataT = [
51
+ {
52
+ i: timeSeriesEntry.data.length - 1,
53
+ dt: timeDifference,
54
+ },
55
+ ];
49
56
  } else {
50
57
  timeSeriesEntry.dataT.push({
51
58
  i: timeSeriesEntry.data.length - 1,
52
- dt:
53
- microsSinceEpoch - previousMicroSecondsSinceEpochById?.[item.id],
59
+ dt: timeDifference,
54
60
  });
55
61
  }
56
62
  }