@altronix/cli 0.5.0 → 0.6.2

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.
Files changed (67) hide show
  1. package/bin/atx +2 -2
  2. package/build/about.d.ts +3 -1
  3. package/build/about.js +37 -16
  4. package/build/about.js.map +1 -1
  5. package/build/cloud.d.ts +2 -2
  6. package/build/cloud.js +41 -19
  7. package/build/cloud.js.map +1 -1
  8. package/build/common.d.ts +5 -5
  9. package/build/common.js +48 -48
  10. package/build/common.js.map +1 -1
  11. package/build/confirmDevice.d.ts +5 -5
  12. package/build/confirmDevice.js +35 -35
  13. package/build/dhcp.d.ts +1 -1
  14. package/build/dhcp.js +9 -9
  15. package/build/dhcp.js.map +1 -1
  16. package/build/exe.d.ts +4 -0
  17. package/build/exe.js +43 -0
  18. package/build/exe.js.map +1 -0
  19. package/build/index.d.ts +1 -1
  20. package/build/index.js +81 -78
  21. package/build/index.js.map +1 -1
  22. package/build/ip.d.ts +2 -2
  23. package/build/ip.js +17 -17
  24. package/build/ip.js.map +1 -1
  25. package/build/linq.d.ts +3 -3
  26. package/build/linq.js +5 -5
  27. package/build/net.d.ts +3 -0
  28. package/build/net.js +47 -0
  29. package/build/net.js.map +1 -0
  30. package/build/poe.d.ts +4 -3
  31. package/build/poe.js +28 -23
  32. package/build/poe.js.map +1 -1
  33. package/build/reboot.d.ts +1 -0
  34. package/build/reboot.js +16 -0
  35. package/build/reboot.js.map +1 -0
  36. package/build/site.d.ts +2 -1
  37. package/build/site.js +18 -13
  38. package/build/site.js.map +1 -1
  39. package/build/stress.d.ts +1 -0
  40. package/build/stress.js +23 -0
  41. package/build/stress.js.map +1 -0
  42. package/build/unix.d.ts +1 -1
  43. package/build/unix.js +13 -13
  44. package/build/unix.js.map +1 -1
  45. package/build/update.d.ts +1 -1
  46. package/build/update.js +82 -82
  47. package/build/update.js.map +1 -1
  48. package/jest.config.js +6 -6
  49. package/package.json +3 -3
  50. package/src/about.ts +47 -13
  51. package/src/cloud.ts +55 -16
  52. package/src/exe.ts +54 -0
  53. package/src/index.ts +95 -89
  54. package/src/net.ts +68 -0
  55. package/src/stress.ts +30 -0
  56. package/src/{update.ts → update.ts.bak} +98 -98
  57. package/tsconfig.json +29 -29
  58. package/tsconfig.lib.json +8 -8
  59. package/tsconfig.lib.tsbuildinfo +1 -1
  60. package/src/common.ts +0 -63
  61. package/src/confirmDevice.ts +0 -51
  62. package/src/dhcp.ts +0 -6
  63. package/src/ip.ts +0 -14
  64. package/src/linq.ts +0 -9
  65. package/src/poe.ts +0 -22
  66. package/src/site.ts +0 -10
  67. package/src/unix.ts +0 -10
package/src/net.ts ADDED
@@ -0,0 +1,68 @@
1
+ import Linq, { log } from "@altronix/device";
2
+ import {
3
+ concat,
4
+ finalize,
5
+ firstValueFrom,
6
+ lastValueFrom,
7
+ map,
8
+ switchMap,
9
+ take,
10
+ } from "rxjs";
11
+ import { ResponseBody, ResponseMeta } from "@altronix/device";
12
+ import { NetIp } from "@altronix/netway";
13
+
14
+ export async function getNet(): Promise<void> {
15
+ const linq = new Linq();
16
+ const path = "/api/v1/net/ip";
17
+ const obs = linq.connections().pipe(
18
+ take(1),
19
+ switchMap(({ about }) => linq.get<ResponseBody>(about.sid, path)),
20
+ map((resp) => NetIp.fromCbor(resp.body)),
21
+ finalize(() => linq.shutdown())
22
+ );
23
+ return firstValueFrom(obs).then((net) => {
24
+ log.info(`request complete`, { ...net.toJson() });
25
+ });
26
+ }
27
+
28
+ export async function setNet(
29
+ ip: string,
30
+ sn: string,
31
+ gw: string
32
+ ): Promise<void> {
33
+ const linq = new Linq();
34
+ const path = "/api/v1/net/ip";
35
+ const save = "/api/v1/exe/saveAndReboot";
36
+ const body = new NetIp({ ip, sn, gw, dhcp: false });
37
+ const obs = linq.connections().pipe(
38
+ take(1),
39
+ switchMap(({ about }) => {
40
+ const o0 = linq.put<ResponseMeta>(about.sid, path, body);
41
+ const o1 = linq.get<ResponseMeta>(about.sid, save);
42
+ return concat(o0, o1);
43
+ }),
44
+ finalize(() => linq.shutdown())
45
+ );
46
+ return lastValueFrom(obs).then(({ meta }) => {
47
+ log.info(`request complete`, { code: meta.code, message: meta.mesg });
48
+ });
49
+ }
50
+
51
+ export async function setDhcp(): Promise<void> {
52
+ const linq = new Linq();
53
+ const path = "/api/v1/net/ip";
54
+ const save = "/api/v1/exe/saveAndReboot";
55
+ const body = new NetIp({ dhcp: true });
56
+ const obs = linq.connections().pipe(
57
+ take(1),
58
+ switchMap(({ about }) => {
59
+ const o0 = linq.put<ResponseMeta>(about.sid, path, body);
60
+ const o1 = linq.get<ResponseMeta>(about.sid, save);
61
+ return concat(o0, o1);
62
+ }),
63
+ finalize(() => linq.shutdown())
64
+ );
65
+ return lastValueFrom(obs).then(({ meta }) => {
66
+ log.info(`request complete`, { code: meta.code, message: meta.mesg });
67
+ });
68
+ }
package/src/stress.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { About } from "@altronix/wasm/zdk";
2
+ import Linq, { log } from "@altronix/device";
3
+ import { lastValueFrom, map, repeat, switchScan, take, tap } from "rxjs";
4
+ import { ResponseBody } from "@altronix/device";
5
+
6
+ export async function stress(count: number): Promise<void> {
7
+ const linq = new Linq();
8
+ const path = "/api/v1/about";
9
+ const obs = linq.connections().pipe(
10
+ take(1),
11
+ switchScan(
12
+ (acc, { about }) =>
13
+ linq.get<ResponseBody>(about.sid, path).pipe(
14
+ map((resp) => ({
15
+ ...About.fromCbor(resp.body).toJson(),
16
+ count: acc.count++,
17
+ })),
18
+ repeat(count)
19
+ ),
20
+ { count: 0 }
21
+ ),
22
+ tap({
23
+ next: (about) => log.info("response", { ...about }),
24
+ finalize: () => linq.shutdown(),
25
+ })
26
+ );
27
+ return lastValueFrom(obs).then(() => {
28
+ log.info(`stress test complete`);
29
+ });
30
+ }
@@ -1,98 +1,98 @@
1
- /*
2
- * This example will listen for the first connected device and make a get
3
- * request for the about data and log the about data to the console.
4
- */
5
- import {
6
- ConnectedEvent,
7
- installDebugLogger,
8
- getLogger,
9
- CONNECTED,
10
- } from "@altronix/device";
11
- import { About, Update } from "@altronix/cbor";
12
- import { from, concat, defer } from "rxjs";
13
- import { take, filter, switchMap, concatMap, map, tap } from "rxjs/operators";
14
- import linq from "./linq";
15
- import fs from "fs";
16
-
17
- function chunks(data: Uint8Array, size: number): Uint8Array[] {
18
- let arr = [];
19
- let remainder = data.length % size;
20
- function slicer(n: number) {
21
- for (let i = 0; i < n; i++) {
22
- let idx = i * size;
23
- arr.push(data.slice(idx, idx + size));
24
- }
25
- }
26
- if (remainder == 0) {
27
- slicer(data.length / size);
28
- } else {
29
- let n = Math.ceil(data.length / size);
30
- let end = size * (n - 1);
31
- slicer(n - 1);
32
- let last = new Uint8Array(size);
33
- last.set(data.slice(end));
34
- arr.push(last);
35
- }
36
- return arr;
37
- }
38
-
39
- installDebugLogger();
40
- const logger = getLogger();
41
-
42
- // Reduce a blob of binary data and convert into an Update[]
43
- function updateReducer(arr: Update[], data: Uint8Array, idx: number) {
44
- let update = new Update({ data, offset: idx * 512 });
45
- // NOTE: Have to initialize the Uint8Array across binding this way
46
- // https://gitlab.altronix.com/software-engineering/sdk/atx-zdk/-/issues/1
47
- update.data = data;
48
- return arr.concat(update);
49
- }
50
-
51
- export function runUpdate(file: string): Promise<void> {
52
- return new Promise((resolve, reject) => {
53
- const sub = linq
54
- .listen()
55
- .pipe(
56
- filter((ev): ev is ConnectedEvent => ev.type == CONNECTED),
57
- take(1),
58
- switchMap(({ device }) => linq.get(device.about.sid, "/api/v1/about")),
59
- map(About.fromCbor),
60
- switchMap(({ sid: serial, verPrj }) => {
61
- logger.info("found device", { serial, version: verPrj });
62
- logger.info("sending update :", { file });
63
- return from(fs.promises.readFile(file)).pipe(
64
- switchMap((update) => {
65
- // Chunk up the update file into packets and send update to device
66
- const packets = chunks(update, 512).reduce(updateReducer, []);
67
- const length = packets.length;
68
- const urlStart = "/api/v1/update/start";
69
- const urlTransfer = "/api/v1/update/transfer";
70
- const urlFinish = "/api/v1/update/finish";
71
- let sent = 0;
72
- const start$ = defer(() => linq.get(serial, urlStart));
73
- const transfer$ = from(packets).pipe(
74
- concatMap((u) => linq.put(serial, urlTransfer, u.cbor())),
75
- map((meta) => ({ code: meta.json().code, sent, length })),
76
- tap(() => sent++)
77
- );
78
- const finished$ = defer(() => linq.get(serial, urlFinish));
79
- return concat(start$, transfer$, finished$);
80
- })
81
- );
82
- })
83
- )
84
- .subscribe({
85
- next: async (mesg) => {
86
- logger.info("<-", { ...mesg });
87
- resolve();
88
- },
89
- error: async (error) => (await linq.shutdown(), reject(error)),
90
- complete: async () => (await linq.shutdown(), resolve()),
91
- });
92
-
93
- process.on("SIGINT", async () => {
94
- await linq.shutdown();
95
- sub.unsubscribe();
96
- });
97
- });
98
- }
1
+ /*
2
+ * This example will listen for the first connected device and make a get
3
+ * request for the about data and log the about data to the console.
4
+ */
5
+ import {
6
+ ConnectedEvent,
7
+ installDebugLogger,
8
+ getLogger,
9
+ CONNECTED,
10
+ } from "@altronix/device";
11
+ import { About, Update } from "@altronix/wasm/zdk";
12
+ import { from, concat, defer } from "rxjs";
13
+ import { take, filter, switchMap, concatMap, map, tap } from "rxjs/operators";
14
+ import linq from "./linq";
15
+ import fs from "fs";
16
+
17
+ function chunks(data: Uint8Array, size: number): Uint8Array[] {
18
+ let arr = [];
19
+ let remainder = data.length % size;
20
+ function slicer(n: number) {
21
+ for (let i = 0; i < n; i++) {
22
+ let idx = i * size;
23
+ arr.push(data.slice(idx, idx + size));
24
+ }
25
+ }
26
+ if (remainder == 0) {
27
+ slicer(data.length / size);
28
+ } else {
29
+ let n = Math.ceil(data.length / size);
30
+ let end = size * (n - 1);
31
+ slicer(n - 1);
32
+ let last = new Uint8Array(size);
33
+ last.set(data.slice(end));
34
+ arr.push(last);
35
+ }
36
+ return arr;
37
+ }
38
+
39
+ installDebugLogger();
40
+ const logger = getLogger();
41
+
42
+ // Reduce a blob of binary data and convert into an Update[]
43
+ function updateReducer(arr: Update[], data: Uint8Array, idx: number) {
44
+ let update = new Update({ data, offset: idx * 512 });
45
+ // NOTE: Have to initialize the Uint8Array across binding this way
46
+ // https://gitlab.altronix.com/software-engineering/sdk/atx-zdk/-/issues/1
47
+ update.data = data;
48
+ return arr.concat(update);
49
+ }
50
+
51
+ export function runUpdate(file: string): Promise<void> {
52
+ return new Promise((resolve, reject) => {
53
+ const sub = linq
54
+ .listen()
55
+ .pipe(
56
+ filter((ev): ev is ConnectedEvent => ev.type == CONNECTED),
57
+ take(1),
58
+ switchMap(({ device }) => linq.get(device.about.sid, "/api/v1/about")),
59
+ map(About.fromCbor),
60
+ switchMap(({ sid: serial, verPrj }) => {
61
+ logger.info("found device", { serial, version: verPrj });
62
+ logger.info("sending update :", { file });
63
+ return from(fs.promises.readFile(file)).pipe(
64
+ switchMap((update) => {
65
+ // Chunk up the update file into packets and send update to device
66
+ const packets = chunks(update, 512).reduce(updateReducer, []);
67
+ const length = packets.length;
68
+ const urlStart = "/api/v1/update/start";
69
+ const urlTransfer = "/api/v1/update/transfer";
70
+ const urlFinish = "/api/v1/update/finish";
71
+ let sent = 0;
72
+ const start$ = defer(() => linq.get(serial, urlStart));
73
+ const transfer$ = from(packets).pipe(
74
+ concatMap((u) => linq.put(serial, urlTransfer, u.cbor())),
75
+ map((meta) => ({ code: meta.json().code, sent, length })),
76
+ tap(() => sent++)
77
+ );
78
+ const finished$ = defer(() => linq.get(serial, urlFinish));
79
+ return concat(start$, transfer$, finished$);
80
+ })
81
+ );
82
+ })
83
+ )
84
+ .subscribe({
85
+ next: async (mesg) => {
86
+ logger.info("<-", { ...mesg });
87
+ resolve();
88
+ },
89
+ error: async (error) => (await linq.shutdown(), reject(error)),
90
+ complete: async () => (await linq.shutdown(), resolve()),
91
+ });
92
+
93
+ process.on("SIGINT", async () => {
94
+ await linq.shutdown();
95
+ sub.unsubscribe();
96
+ });
97
+ });
98
+ }
package/tsconfig.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "Node16",
5
- "lib": ["ES2022"],
6
- "moduleResolution": "Node16",
7
- "declaration": true,
8
- "composite": true,
9
- "isolatedModules": true,
10
- "allowSyntheticDefaultImports": true,
11
- "importHelpers": true,
12
- "alwaysStrict": true,
13
- "sourceMap": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "noFallthroughCasesInSwitch": true,
16
- "noImplicitReturns": true,
17
- "noUnusedLocals": true,
18
- "noUnusedParameters": true,
19
- "noImplicitAny": false,
20
- "noImplicitThis": false,
21
- "strictNullChecks": false,
22
- "paths":{
23
- "@altronix/cbor": ["../cbor"]
24
- }
25
- },
26
- "references":[
27
- {"path": "tsconfig.lib.json"}
28
- ]
29
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "Node16",
5
+ "lib": ["ES2022"],
6
+ "moduleResolution": "Node16",
7
+ "declaration": true,
8
+ "composite": true,
9
+ "isolatedModules": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "importHelpers": true,
12
+ "alwaysStrict": true,
13
+ "sourceMap": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "noFallthroughCasesInSwitch": true,
16
+ "noImplicitReturns": true,
17
+ "noUnusedLocals": true,
18
+ "noUnusedParameters": true,
19
+ "noImplicitAny": false,
20
+ "noImplicitThis": false,
21
+ "strictNullChecks": false,
22
+ "paths":{
23
+ "@altronix/wasm/zdk": ["../wasm/zdk"]
24
+ }
25
+ },
26
+ "references":[
27
+ {"path": "tsconfig.lib.json"}
28
+ ]
29
+ }
package/tsconfig.lib.json CHANGED
@@ -1,8 +1,8 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "build",
5
- "rootDir": "src"
6
- },
7
- "include": ["src/**/*"]
8
- }
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "build",
5
+ "rootDir": "src"
6
+ },
7
+ "include": ["src/**/*"]
8
+ }