@alwaysai/device-agent 1.0.0 → 1.3.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/lib/application-control/environment-variables.d.ts +1 -1
- package/lib/application-control/environment-variables.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +3 -2
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +81 -59
- package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +2 -4
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
- package/lib/cloud-connection/messages.js +6 -6
- package/lib/cloud-connection/messages.js.map +1 -1
- package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
- package/lib/cloud-connection/passthrough-handler.js +37 -11
- package/lib/cloud-connection/passthrough-handler.js.map +1 -1
- package/lib/cloud-connection/publisher.d.ts +5 -4
- package/lib/cloud-connection/publisher.d.ts.map +1 -1
- package/lib/cloud-connection/publisher.js +9 -8
- package/lib/cloud-connection/publisher.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.d.ts +5 -0
- package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
- package/lib/cloud-connection/shadow-handler.js +20 -5
- package/lib/cloud-connection/shadow-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.test.js +9 -0
- package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.d.ts +10 -0
- package/lib/cloud-connection/transaction-manager.d.ts.map +1 -0
- package/lib/cloud-connection/transaction-manager.js +41 -0
- package/lib/cloud-connection/transaction-manager.js.map +1 -0
- package/lib/cloud-connection/transaction-manager.test.d.ts +2 -0
- package/lib/cloud-connection/transaction-manager.test.d.ts.map +1 -0
- package/lib/cloud-connection/transaction-manager.test.js +63 -0
- package/lib/cloud-connection/transaction-manager.test.js.map +1 -0
- package/lib/device-control/device-control.d.ts +58 -3
- package/lib/device-control/device-control.d.ts.map +1 -1
- package/lib/device-control/device-control.js +141 -14
- package/lib/device-control/device-control.js.map +1 -1
- package/lib/subcommands/app/env-vars.d.ts.map +1 -1
- package/lib/subcommands/app/env-vars.js +15 -9
- package/lib/subcommands/app/env-vars.js.map +1 -1
- package/lib/subcommands/device/clean.d.ts.map +1 -1
- package/lib/subcommands/device/clean.js +14 -12
- package/lib/subcommands/device/clean.js.map +1 -1
- package/lib/subcommands/device/device.d.ts +1 -0
- package/lib/subcommands/device/device.d.ts.map +1 -1
- package/lib/subcommands/device/device.js +26 -7
- package/lib/subcommands/device/device.js.map +1 -1
- package/lib/subcommands/device/index.js +1 -1
- package/lib/subcommands/device/index.js.map +1 -1
- package/lib/util/logger.d.ts.map +1 -1
- package/lib/util/logger.js +1 -1
- package/lib/util/logger.js.map +1 -1
- package/lib/util/safe-rimraf.d.ts +2 -0
- package/lib/util/safe-rimraf.d.ts.map +1 -0
- package/lib/util/safe-rimraf.js +16 -0
- package/lib/util/safe-rimraf.js.map +1 -0
- package/package.json +4 -2
- package/readme.md +1 -0
- package/src/application-control/environment-variables.ts +1 -1
- package/src/cloud-connection/device-agent-cloud-connection.ts +125 -80
- package/src/cloud-connection/live-updates-handler.test.ts +2 -2
- package/src/cloud-connection/live-updates-handler.ts +2 -8
- package/src/cloud-connection/messages.ts +9 -9
- package/src/cloud-connection/passthrough-handler.ts +43 -10
- package/src/cloud-connection/publisher.ts +27 -10
- package/src/cloud-connection/shadow-handler.test.ts +9 -0
- package/src/cloud-connection/shadow-handler.ts +25 -11
- package/src/cloud-connection/transaction-manager.test.ts +73 -0
- package/src/cloud-connection/transaction-manager.ts +43 -0
- package/src/device-control/device-control.ts +142 -9
- package/src/subcommands/app/env-vars.ts +17 -10
- package/src/subcommands/device/clean.ts +22 -13
- package/src/subcommands/device/device.ts +36 -9
- package/src/subcommands/device/index.ts +2 -2
- package/src/util/logger.ts +15 -10
- package/src/util/safe-rimraf.ts +14 -0
- package/lib/cloud-connection/transaction-queue.d.ts +0 -12
- package/lib/cloud-connection/transaction-queue.d.ts.map +0 -1
- package/lib/cloud-connection/transaction-queue.js +0 -38
- package/lib/cloud-connection/transaction-queue.js.map +0 -1
- package/lib/cloud-connection/transaction-queue.test.d.ts +0 -2
- package/lib/cloud-connection/transaction-queue.test.d.ts.map +0 -1
- package/lib/cloud-connection/transaction-queue.test.js +0 -46
- package/lib/cloud-connection/transaction-queue.test.js.map +0 -1
- package/src/cloud-connection/transaction-queue.test.ts +0 -55
- package/src/cloud-connection/transaction-queue.ts +0 -40
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-queue.test.d.ts","sourceRoot":"","sources":["../../src/cloud-connection/transaction-queue.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const device_agent_schemas_1 = require("@alwaysai/device-agent-schemas");
|
|
4
|
-
const transaction_queue_1 = require("./transaction-queue");
|
|
5
|
-
describe('Test Transaction Queue', () => {
|
|
6
|
-
let txnQueue;
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
txnQueue = new transaction_queue_1.TransactionQueue();
|
|
9
|
-
jest.clearAllMocks();
|
|
10
|
-
});
|
|
11
|
-
test('Add new to transaction queue', async () => {
|
|
12
|
-
const txId = (0, device_agent_schemas_1.generateTxId)();
|
|
13
|
-
const projectId = '1241fad-agah-gfadg-2352dgzg';
|
|
14
|
-
txnQueue.addTxIdToQueue(txId, projectId);
|
|
15
|
-
expect(txnQueue.checkTxnInQueue(txId)).toBeTruthy();
|
|
16
|
-
});
|
|
17
|
-
test('Attempt to add existing to transaction queue, results in failure', async () => {
|
|
18
|
-
const txId = (0, device_agent_schemas_1.generateTxId)();
|
|
19
|
-
const projectId = '1241fad-agah-gfadg-2352dgzg';
|
|
20
|
-
txnQueue.addTxIdToQueue(txId, projectId);
|
|
21
|
-
expect(() => txnQueue.addTxIdToQueue(txId, projectId)).toThrow(`txId ${txId} is already added to the queue!`);
|
|
22
|
-
});
|
|
23
|
-
test('Check current transaction', async () => {
|
|
24
|
-
const txId = (0, device_agent_schemas_1.generateTxId)();
|
|
25
|
-
const projectId = '1241fad-agah-gfadg-2352dgzg';
|
|
26
|
-
txnQueue.addTxIdToQueue(txId, projectId);
|
|
27
|
-
const txId2 = (0, device_agent_schemas_1.generateTxId)();
|
|
28
|
-
const projectId2 = '1241faegta-agah-gagadg-2352dgzg';
|
|
29
|
-
txnQueue.addTxIdToQueue(txId2, projectId2);
|
|
30
|
-
expect(txnQueue.getCurrentTxId()).toEqual(txId);
|
|
31
|
-
});
|
|
32
|
-
test('Test remove transaction from queue', async () => {
|
|
33
|
-
const txId = (0, device_agent_schemas_1.generateTxId)();
|
|
34
|
-
const projectId = '1241fad-agah-gfadg-2352dgzg';
|
|
35
|
-
txnQueue.addTxIdToQueue(txId, projectId);
|
|
36
|
-
txnQueue.completeCurrentTxn();
|
|
37
|
-
expect(txnQueue.getCurrentTxId()).toBeUndefined();
|
|
38
|
-
});
|
|
39
|
-
test('Test get project ID for a given txId', async () => {
|
|
40
|
-
const txId = (0, device_agent_schemas_1.generateTxId)();
|
|
41
|
-
const projectId = '1241fad-agah-gfadg-2352dgzg';
|
|
42
|
-
txnQueue.addTxIdToQueue(txId, projectId);
|
|
43
|
-
expect(txnQueue.getProjectIdForTxnId(txId)).toEqual(projectId);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
//# sourceMappingURL=transaction-queue.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-queue.test.js","sourceRoot":"","sources":["../../src/cloud-connection/transaction-queue.test.ts"],"names":[],"mappings":";;AAAA,yEAA8D;AAC9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AAE,UAAU,CAAC,CAAC;QAC3C,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;QACpD,MAAM,IAAI,GAAG,IAAA,mCAAY,GAAE,CAAC;QAC5B,MAAM,SAAS,GAAG,6BAA6B,CAAC;QAChD,QAAQ,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACzC,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QAE9B,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC,aAAa,EAAE,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QACtD,MAAM,IAAI,GAAG,IAAA,mCAAY,GAAE,CAAC;QAC5B,MAAM,SAAS,GAAG,6BAA6B,CAAC;QAChD,QAAQ,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAEzC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { generateTxId } from '@alwaysai/device-agent-schemas';
|
|
2
|
-
import { TransactionQueue } from './transaction-queue';
|
|
3
|
-
|
|
4
|
-
describe('Test Transaction Queue', () => {
|
|
5
|
-
let txnQueue: TransactionQueue;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
txnQueue = new TransactionQueue();
|
|
9
|
-
jest.clearAllMocks();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('Add new to transaction queue', async () => {
|
|
13
|
-
const txId = generateTxId();
|
|
14
|
-
const projectId = '1241fad-agah-gfadg-2352dgzg';
|
|
15
|
-
txnQueue.addTxIdToQueue(txId, projectId);
|
|
16
|
-
expect(txnQueue.checkTxnInQueue(txId)).toBeTruthy();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('Attempt to add existing to transaction queue, results in failure', async () => {
|
|
20
|
-
const txId = generateTxId();
|
|
21
|
-
const projectId = '1241fad-agah-gfadg-2352dgzg';
|
|
22
|
-
txnQueue.addTxIdToQueue(txId, projectId);
|
|
23
|
-
expect(() => txnQueue.addTxIdToQueue(txId, projectId)).toThrow(
|
|
24
|
-
`txId ${txId} is already added to the queue!`
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('Check current transaction', async () => {
|
|
29
|
-
const txId = generateTxId();
|
|
30
|
-
const projectId = '1241fad-agah-gfadg-2352dgzg';
|
|
31
|
-
txnQueue.addTxIdToQueue(txId, projectId);
|
|
32
|
-
|
|
33
|
-
const txId2 = generateTxId();
|
|
34
|
-
const projectId2 = '1241faegta-agah-gagadg-2352dgzg';
|
|
35
|
-
txnQueue.addTxIdToQueue(txId2, projectId2);
|
|
36
|
-
expect(txnQueue.getCurrentTxId()).toEqual(txId);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('Test remove transaction from queue', async () => {
|
|
40
|
-
const txId = generateTxId();
|
|
41
|
-
const projectId = '1241fad-agah-gfadg-2352dgzg';
|
|
42
|
-
txnQueue.addTxIdToQueue(txId, projectId);
|
|
43
|
-
txnQueue.completeCurrentTxn();
|
|
44
|
-
|
|
45
|
-
expect(txnQueue.getCurrentTxId()).toBeUndefined();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('Test get project ID for a given txId', async () => {
|
|
49
|
-
const txId = generateTxId();
|
|
50
|
-
const projectId = '1241fad-agah-gfadg-2352dgzg';
|
|
51
|
-
txnQueue.addTxIdToQueue(txId, projectId);
|
|
52
|
-
|
|
53
|
-
expect(txnQueue.getProjectIdForTxnId(txId)).toEqual(projectId);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export class TransactionQueue {
|
|
2
|
-
private transactionList: string[];
|
|
3
|
-
private txIdToProjectIdMap: { [txId: string]: string } = {};
|
|
4
|
-
|
|
5
|
-
constructor() {
|
|
6
|
-
this.transactionList = [];
|
|
7
|
-
this.txIdToProjectIdMap = {};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public addTxIdToQueue(txId: string, projectId: string) {
|
|
11
|
-
if (!this.checkTxnInQueue(txId)) {
|
|
12
|
-
this.transactionList.push(txId);
|
|
13
|
-
this.txIdToProjectIdMap[txId] = projectId;
|
|
14
|
-
} else {
|
|
15
|
-
throw new Error(`txId ${txId} is already added to the queue!`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public getCurrentTxId() {
|
|
20
|
-
return this.transactionList[0];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public checkTxnInQueue(txId: string) {
|
|
24
|
-
return this.transactionList.includes(txId);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public getProjectIdForTxnId(txId: string) {
|
|
28
|
-
return this.txIdToProjectIdMap[txId];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public completeTxn(txId: string) {
|
|
32
|
-
delete this.txIdToProjectIdMap[txId];
|
|
33
|
-
this.transactionList.splice(this.transactionList.indexOf(txId), 1);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public completeCurrentTxn() {
|
|
37
|
-
delete this.txIdToProjectIdMap[this.transactionList[0]];
|
|
38
|
-
this.transactionList.shift();
|
|
39
|
-
}
|
|
40
|
-
}
|