@kogeet/sagent-plugin-dataset 0.1.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.
@@ -0,0 +1,9 @@
1
+ import StepContext from "scapin-core-agent/bin/core/step.context.js";
2
+ export default class DatasetLib {
3
+ static entryPoints: Map<string, typeof DatasetLib.addRow>;
4
+ static addRow(stepCtx: StepContext): Promise<boolean>;
5
+ static deleteRow(stepCtx: StepContext): Promise<boolean>;
6
+ static getHandle(stepCtx: StepContext): Promise<boolean>;
7
+ static getData(stepCtx: StepContext): Promise<boolean>;
8
+ static updateData(stepCtx: StepContext): Promise<boolean>;
9
+ }
@@ -0,0 +1,162 @@
1
+ import { report, context } from "scapin-core-agent/bin/index.js";
2
+ import wSocketIo from "scapin-core-agent/bin/core/wsocket.io.js";
3
+ const emptyData = {
4
+ data0: null,
5
+ data1: null,
6
+ data2: null,
7
+ data3: null,
8
+ data4: null,
9
+ data5: null,
10
+ data6: null,
11
+ data7: null,
12
+ data8: null,
13
+ data9: null
14
+ };
15
+ export default class DatasetLib {
16
+ static entryPoints = new Map([
17
+ ['addRow', DatasetLib.addRow],
18
+ ['deleteRow', DatasetLib.deleteRow],
19
+ ['getHandle', DatasetLib.getHandle],
20
+ ['getData', DatasetLib.getData],
21
+ ['updateData', DatasetLib.updateData]
22
+ ]);
23
+ static async addRow(stepCtx) {
24
+ try {
25
+ if (stepCtx.toolid) {
26
+ const rep = await datasetEmit('dataset-addrow', { toolid: stepCtx.toolid, ...buildData(stepCtx, 0) });
27
+ if (rep.status) {
28
+ return true;
29
+ }
30
+ else {
31
+ report.warning(rep.data);
32
+ return false;
33
+ }
34
+ }
35
+ else {
36
+ report.error('Not a dataset');
37
+ return false;
38
+ }
39
+ }
40
+ catch (e) {
41
+ report.warning(`Dataset error : ${e.message}`);
42
+ return false;
43
+ }
44
+ }
45
+ static async deleteRow(stepCtx) {
46
+ try {
47
+ const handle = stepCtx.getParam('0');
48
+ const rep = await datasetEmit('dataset-delete', handle);
49
+ if (rep.status) {
50
+ return true;
51
+ }
52
+ else {
53
+ report.warning(rep.data);
54
+ return false;
55
+ }
56
+ }
57
+ catch (e) {
58
+ report.warning(`Dataset error : ${e.message}`);
59
+ return false;
60
+ }
61
+ }
62
+ static async getHandle(stepCtx) {
63
+ try {
64
+ if (stepCtx.toolid) {
65
+ const rep = await datasetEmit('dataset-gethandle', { toolid: stepCtx.toolid, ...buildData(stepCtx, 1) });
66
+ if (rep.status) {
67
+ context.setVariable(stepCtx.getStringParam('0'), rep.data);
68
+ return true;
69
+ }
70
+ else {
71
+ report.error(rep.data);
72
+ return false;
73
+ }
74
+ }
75
+ else {
76
+ report.error('Not a dataset');
77
+ return false;
78
+ }
79
+ }
80
+ catch (e) {
81
+ report.warning(`Dataset error : ${e.message}`);
82
+ return false;
83
+ }
84
+ }
85
+ static async getData(stepCtx) {
86
+ try {
87
+ const handle = stepCtx.getParam('0');
88
+ const colname = stepCtx.getParam('1');
89
+ const column = cols(stepCtx).findIndex(v => v === colname);
90
+ if (column >= 0) {
91
+ const rep = await datasetEmit('dataset-getdata', { handle, column });
92
+ if (rep.status) {
93
+ context.setVariable(stepCtx.getParam('2'), rep.data);
94
+ return true;
95
+ }
96
+ else {
97
+ report.warning(rep.data);
98
+ return false;
99
+ }
100
+ }
101
+ else {
102
+ report.warning(`Unknow column name '${colname}'`);
103
+ return false;
104
+ }
105
+ }
106
+ catch (e) {
107
+ report.warning(`Dataset error : ${e.message}`);
108
+ return false;
109
+ }
110
+ }
111
+ static async updateData(stepCtx) {
112
+ try {
113
+ const handle = stepCtx.getParam('0');
114
+ const colname = stepCtx.getParam('1');
115
+ const data = stepCtx.getParam('2');
116
+ const column = cols(stepCtx).findIndex(v => v === colname);
117
+ if (column >= 0) {
118
+ const rep = await datasetEmit('dataset-update', { handle, column, data });
119
+ if (rep.status) {
120
+ return true;
121
+ }
122
+ else {
123
+ report.warning(rep.data);
124
+ return false;
125
+ }
126
+ }
127
+ else {
128
+ report.warning(`Unknow column name '${colname}'`);
129
+ return false;
130
+ }
131
+ }
132
+ catch (e) {
133
+ report.warning(`Dataset error : ${e.message}`);
134
+ return false;
135
+ }
136
+ }
137
+ }
138
+ const datasetEmit = (ev, data) => {
139
+ return new Promise((resolve, reject) => {
140
+ console.log(`Emit '${ev}' whith data:`, data);
141
+ if (wSocketIo.ioClient) {
142
+ wSocketIo.ioClient.emit(ev, data, function (rep) {
143
+ resolve(rep);
144
+ });
145
+ }
146
+ else {
147
+ reject({ status: false, data: 'Not connected' });
148
+ }
149
+ });
150
+ };
151
+ const buildData = (sctx, from) => {
152
+ const dataset = {};
153
+ for (let key = from; key < from + cols(sctx).length; key++) {
154
+ const val = sctx.getParam(key.toString());
155
+ if (typeof val === 'string' && val.length > 0) {
156
+ dataset[`data${key - from}`] = val;
157
+ }
158
+ }
159
+ return dataset;
160
+ };
161
+ // Tableau des noms de colonnes
162
+ const cols = (sctx) => sctx.getConfig('0').split('|').map(c => c.trim());
package/bin/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import DatasetLib from "./DatasetLib.js";
2
+ declare const DatasetEntryPoints: Map<string, typeof DatasetLib.addRow>;
3
+ export default DatasetEntryPoints;
package/bin/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import DatasetLib from "./DatasetLib.js";
2
+ const DatasetEntryPoints = DatasetLib.entryPoints;
3
+ export default DatasetEntryPoints;
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@kogeet/sagent-plugin-dataset",
3
+ "version": "0.1.0",
4
+ "description": "Scapin Agent Dataset Plugin ",
5
+ "main": "bin/index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "engines": {
10
+ "node": "^18.17.1"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc --sourceMap false --declaration true",
14
+ "np": "np --no-tests --message=dataset-plugin-%s"
15
+ },
16
+ "author": "Loïc Griveau",
17
+ "license": "MIT",
18
+ "devDependencies": {
19
+ "@types/selenium-webdriver": "^4.1.18",
20
+ "@typescript-eslint/eslint-plugin": "^6.8.0",
21
+ "@typescript-eslint/parser": "^6.8.0",
22
+ "eslint": "^8.51.0",
23
+ "typescript": "^5.2.2"
24
+ },
25
+ "type": "module",
26
+ "dependencies": {
27
+ "@kogeet/scapin-core-agent": "^0.1.2"
28
+ }
29
+ }