@sme.up/kokos-sdk-node 0.0.3 → 0.0.5
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/README.md +1 -1
- package/lib/caller/serviceCaller.d.ts +3 -2
- package/lib/caller/serviceCaller.js +46 -12
- package/lib/configuration/configuration.d.ts +8 -0
- package/lib/configuration/configuration.js +29 -0
- package/lib/entrypoint/restapi/index.js +2 -110
- package/lib/entrypoint/restapi/restapi.d.ts +3 -0
- package/lib/entrypoint/restapi/restapi.js +145 -0
- package/lib/index.d.ts +8 -3
- package/lib/index.js +8 -3
- package/lib/logger/logger.d.ts +25 -0
- package/lib/logger/logger.js +84 -0
- package/lib/services/JS_00_01.js +42 -75
- package/lib/types/data-structures/smeupDataStructure.d.ts +27 -2
- package/lib/types/data-structures/smeupDataStructure.js +22 -1
- package/lib/types/data-structures/smeupObject.d.ts +2 -2
- package/lib/types/data-structures/smeupTree.d.ts +1 -1
- package/lib/types/general.d.ts +19 -2
- package/lib/types/general.js +7 -0
- package/lib/utils/path.js +1 -1
- package/lib/utils/regex.d.ts +9 -0
- package/lib/utils/regex.js +53 -0
- package/lib/utils/smeupDataStructureWriter.d.ts +29 -0
- package/lib/utils/smeupDataStructureWriter.js +158 -0
- package/package.json +6 -7
- package/tsconfig.json +1 -0
- package/bin/kokos.js +0 -26
- package/docker/restapi/Dockerfile +0 -14
- package/init/JS_00_01.txt +0 -88
- package/lib/types/exceptions/execution.d.ts +0 -7
- package/lib/types/exceptions/execution.js +0 -10
- package/scripts/build.js +0 -26
- package/scripts/init.js +0 -95
- package/scripts/restapi/build-image-restapi.js +0 -60
- package/scripts/restapi/dev.js +0 -30
- package/scripts/restapi/start.js +0 -14
package/lib/services/JS_00_01.js
CHANGED
|
@@ -1,91 +1,58 @@
|
|
|
1
|
-
import { SmeupDataStructureType } from "../types/data-structures/smeupDataStructure.js";
|
|
2
1
|
const JS_00_01 = {
|
|
3
2
|
methods: {
|
|
4
3
|
"GET.TRE": getTree,
|
|
5
4
|
"GET.EXB": getTable,
|
|
5
|
+
"THR.ERR": throwError,
|
|
6
6
|
},
|
|
7
7
|
};
|
|
8
|
-
async function getTree(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
async function getTree(_fun, _context, printer) {
|
|
9
|
+
printer.writeTreeNode({
|
|
10
|
+
children: [],
|
|
11
|
+
content: {
|
|
12
|
+
tipo: "CN",
|
|
13
|
+
parametro: "COL",
|
|
14
|
+
codice: "PIPPO",
|
|
15
|
+
testo: "Pippo",
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async function getTable(_fun, _context, printer) {
|
|
20
|
+
printer.writeColumns([
|
|
21
|
+
{
|
|
22
|
+
code: "COL1",
|
|
23
|
+
text: "Column 1",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
code: "COL2",
|
|
27
|
+
text: "Column 2",
|
|
28
|
+
},
|
|
29
|
+
]);
|
|
30
|
+
printer.writeRow({
|
|
31
|
+
fields: {
|
|
32
|
+
COL1: {
|
|
33
|
+
name: "COL1",
|
|
34
|
+
tooltip: false,
|
|
35
|
+
smeupObject: {
|
|
22
36
|
tipo: "CN",
|
|
23
37
|
parametro: "COL",
|
|
24
38
|
codice: "PIPPO",
|
|
25
39
|
testo: "Pippo",
|
|
26
40
|
},
|
|
27
41
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
gravity: "INFO",
|
|
38
|
-
message: "Info message. CN;COL;PIPPO",
|
|
39
|
-
mode: "TN",
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
gravity: "WARNING",
|
|
43
|
-
message: "Warning message. CN;COL;PLUTO",
|
|
44
|
-
mode: "PM",
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
gravity: "ERROR",
|
|
48
|
-
message: "Error message.",
|
|
49
|
-
mode: "PN",
|
|
50
|
-
}
|
|
51
|
-
],
|
|
52
|
-
columns: [
|
|
53
|
-
{
|
|
54
|
-
code: "COL1",
|
|
55
|
-
text: "Column 1",
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
code: "COL2",
|
|
59
|
-
text: "Column 2",
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
rows: [
|
|
63
|
-
{
|
|
64
|
-
fields: {
|
|
65
|
-
COL1: {
|
|
66
|
-
name: "COL1",
|
|
67
|
-
tooltip: false,
|
|
68
|
-
smeupObject: {
|
|
69
|
-
tipo: "CN",
|
|
70
|
-
parametro: "COL",
|
|
71
|
-
codice: "PIPPO",
|
|
72
|
-
testo: "Pippo",
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
COL2: {
|
|
76
|
-
name: "COL2",
|
|
77
|
-
tooltip: false,
|
|
78
|
-
smeupObject: {
|
|
79
|
-
tipo: "CN",
|
|
80
|
-
parametro: "COL",
|
|
81
|
-
codice: "PLUTO",
|
|
82
|
-
testo: "Pluto",
|
|
83
|
-
},
|
|
84
|
-
},
|
|
42
|
+
COL2: {
|
|
43
|
+
name: "COL2",
|
|
44
|
+
tooltip: false,
|
|
45
|
+
smeupObject: {
|
|
46
|
+
tipo: "CN",
|
|
47
|
+
parametro: "COL",
|
|
48
|
+
codice: "PLUTO",
|
|
49
|
+
testo: "Pluto",
|
|
85
50
|
},
|
|
86
51
|
},
|
|
87
|
-
|
|
88
|
-
};
|
|
89
|
-
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function throwError(_fun, _context, _printer) {
|
|
56
|
+
throw new Error("Dummy error");
|
|
90
57
|
}
|
|
91
58
|
export default JS_00_01;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { Fun } from "../general.js";
|
|
1
2
|
/**
|
|
2
3
|
* Smeup data structure
|
|
3
4
|
*/
|
|
4
5
|
export interface SmeupDataStructure {
|
|
5
6
|
type: SmeupDataStructureType;
|
|
6
7
|
messages: SmeupMessage[];
|
|
8
|
+
debugInfo: DebugInfo;
|
|
7
9
|
}
|
|
8
10
|
/**
|
|
9
11
|
* SmeupDataStructure types
|
|
@@ -12,7 +14,16 @@ export declare enum SmeupDataStructureType {
|
|
|
12
14
|
/** Smeup table (EXB) */
|
|
13
15
|
SmeupTable = "SmeupTable",
|
|
14
16
|
/** Smeup tree node (TRE) */
|
|
15
|
-
SmeupTree = "SmeupTreeNode"
|
|
17
|
+
SmeupTree = "SmeupTreeNode",
|
|
18
|
+
/** Smeup feedback (FBK) */
|
|
19
|
+
SmeupFeedback = "SmeupFeedback"
|
|
20
|
+
}
|
|
21
|
+
export declare function getSmeupDataStructureType(fun: Fun): SmeupDataStructureType;
|
|
22
|
+
/**
|
|
23
|
+
* Smeup data structure
|
|
24
|
+
*/
|
|
25
|
+
export interface SmeupFeedback extends SmeupDataStructure {
|
|
26
|
+
type: SmeupDataStructureType.SmeupFeedback;
|
|
16
27
|
}
|
|
17
28
|
/**
|
|
18
29
|
* SmeupMessage type
|
|
@@ -30,4 +41,18 @@ export declare const SMEUP_MESSAGE_GRAVITY: {
|
|
|
30
41
|
readonly ERROR: "ERROR";
|
|
31
42
|
readonly WARNING: "WARNING";
|
|
32
43
|
};
|
|
33
|
-
|
|
44
|
+
type SmeupMessageGravity = (typeof SMEUP_MESSAGE_GRAVITY)[keyof typeof SMEUP_MESSAGE_GRAVITY];
|
|
45
|
+
/**
|
|
46
|
+
* SmeupMessage Mode
|
|
47
|
+
*/
|
|
48
|
+
export declare const SMEUP_MESSAGE_MODE: {
|
|
49
|
+
readonly PM: "PM";
|
|
50
|
+
readonly PN: "PN";
|
|
51
|
+
readonly TN: "TN";
|
|
52
|
+
};
|
|
53
|
+
export interface DebugInfo {
|
|
54
|
+
executionTime_ms: number;
|
|
55
|
+
initialTimestamp: string;
|
|
56
|
+
finalTimestamp: string;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -7,8 +7,21 @@ export var SmeupDataStructureType;
|
|
|
7
7
|
SmeupDataStructureType["SmeupTable"] = "SmeupTable";
|
|
8
8
|
/** Smeup tree node (TRE) */
|
|
9
9
|
SmeupDataStructureType["SmeupTree"] = "SmeupTreeNode";
|
|
10
|
+
/** Smeup feedback (FBK) */
|
|
11
|
+
SmeupDataStructureType["SmeupFeedback"] = "SmeupFeedback";
|
|
10
12
|
})(SmeupDataStructureType || (SmeupDataStructureType = {}));
|
|
11
|
-
|
|
13
|
+
export function getSmeupDataStructureType(fun) {
|
|
14
|
+
switch (fun.component) {
|
|
15
|
+
case "TRE":
|
|
16
|
+
return SmeupDataStructureType.SmeupTree;
|
|
17
|
+
case "EXB":
|
|
18
|
+
return SmeupDataStructureType.SmeupTable;
|
|
19
|
+
case "FBK":
|
|
20
|
+
return SmeupDataStructureType.SmeupFeedback;
|
|
21
|
+
default:
|
|
22
|
+
throw new Error(`${fun.component} not correspond to a valid SmeupDataStrcuture type`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
12
25
|
/**
|
|
13
26
|
* SmeupMessage Gravity
|
|
14
27
|
*/
|
|
@@ -17,3 +30,11 @@ export const SMEUP_MESSAGE_GRAVITY = {
|
|
|
17
30
|
ERROR: "ERROR",
|
|
18
31
|
WARNING: "WARNING",
|
|
19
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* SmeupMessage Mode
|
|
35
|
+
*/
|
|
36
|
+
export const SMEUP_MESSAGE_MODE = {
|
|
37
|
+
PM: "PM",
|
|
38
|
+
PN: "PN",
|
|
39
|
+
TN: "TN",
|
|
40
|
+
};
|
|
@@ -14,7 +14,7 @@ export interface SmeupTree extends SmeupDataStructure {
|
|
|
14
14
|
* Smeup Tree Node (child node)
|
|
15
15
|
*/
|
|
16
16
|
export interface SmeupTreeNode {
|
|
17
|
-
children
|
|
17
|
+
children?: SmeupTreeNode[];
|
|
18
18
|
content: SmeupObject;
|
|
19
19
|
columns?: SmeupColumn[];
|
|
20
20
|
row?: SmeupRow;
|
package/lib/types/general.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SmeupDataStructureWriter } from "../utils/smeupDataStructureWriter.js";
|
|
2
|
+
import { Format, Level } from "../logger/logger.js";
|
|
3
|
+
export declare class ErrorWithStatus extends Error {
|
|
4
|
+
status: number;
|
|
5
|
+
constructor(message: string, status: number);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Micro Executor base config. To personalize the configuration you can extend this interface
|
|
9
|
+
*/
|
|
10
|
+
export interface MicroExecutorConfiguration {
|
|
11
|
+
server: {
|
|
12
|
+
port: 8011 | number;
|
|
13
|
+
};
|
|
14
|
+
logger?: {
|
|
15
|
+
format: Format;
|
|
16
|
+
level: Level;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
2
19
|
/**
|
|
3
20
|
* Fun Object
|
|
4
21
|
*/
|
|
@@ -61,5 +78,5 @@ export interface KokosService {
|
|
|
61
78
|
* Kokos Service Method
|
|
62
79
|
*/
|
|
63
80
|
export interface KokosServiceMethods {
|
|
64
|
-
[key: string]: (fun: Fun, context: ExecutionContext) => Promise<
|
|
81
|
+
[key: string]: (fun: Fun, context: ExecutionContext, printer: SmeupDataStructureWriter) => Promise<void>;
|
|
65
82
|
}
|
package/lib/types/general.js
CHANGED
|
@@ -8,6 +8,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { IsObject, IsOptional, IsString, ValidateNested, } from "class-validator";
|
|
11
|
+
export class ErrorWithStatus extends Error {
|
|
12
|
+
status = 500;
|
|
13
|
+
constructor(message, status) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
11
18
|
/**
|
|
12
19
|
* Fun Object
|
|
13
20
|
*/
|
package/lib/utils/path.js
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse key(value) expression NB. Nested brackets must be even
|
|
3
|
+
*
|
|
4
|
+
* @param expression
|
|
5
|
+
* @return
|
|
6
|
+
*/
|
|
7
|
+
export function parseKeyValueBetweenBrackets(expression) {
|
|
8
|
+
const map = {};
|
|
9
|
+
let key = "";
|
|
10
|
+
let value = "";
|
|
11
|
+
let bracketsCount = 0;
|
|
12
|
+
let isKey = true;
|
|
13
|
+
for (const c of expression) {
|
|
14
|
+
if (isKey && c !== "(" && c !== ")") {
|
|
15
|
+
// Check and accumulate key
|
|
16
|
+
key += c;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
if (c === "(") {
|
|
20
|
+
if (bracketsCount === 0) {
|
|
21
|
+
// Start value expression
|
|
22
|
+
isKey = false;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// Continue accumulating value expression
|
|
26
|
+
value += c;
|
|
27
|
+
}
|
|
28
|
+
bracketsCount++;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (c === ")") {
|
|
32
|
+
if (bracketsCount === 1) {
|
|
33
|
+
// End value expression
|
|
34
|
+
map[key.trim()] = value;
|
|
35
|
+
isKey = true;
|
|
36
|
+
key = "";
|
|
37
|
+
value = "";
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Continue accumulating value expression
|
|
41
|
+
value += c;
|
|
42
|
+
}
|
|
43
|
+
bracketsCount--;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Continue accumulating value expression
|
|
47
|
+
value += c;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return map;
|
|
53
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import stream from "stream";
|
|
3
|
+
import { SmeupMessage } from "../types/data-structures/smeupDataStructure.js";
|
|
4
|
+
import { SmeupColumn, SmeupRow } from "../types/data-structures/smeupTable.js";
|
|
5
|
+
import { SmeupTreeNode } from "../types/data-structures/smeupTree.js";
|
|
6
|
+
import { Fun } from "../types/general.js";
|
|
7
|
+
export declare class SmeupDataStructureWriter {
|
|
8
|
+
private out;
|
|
9
|
+
private initalTimestamp;
|
|
10
|
+
private messages;
|
|
11
|
+
private columns;
|
|
12
|
+
private firstElement;
|
|
13
|
+
private lastElementWritten;
|
|
14
|
+
private isInitializationWritten;
|
|
15
|
+
private isFinalizationWritten;
|
|
16
|
+
private isColumnWritten;
|
|
17
|
+
private isRowWritten;
|
|
18
|
+
private isNodeWritten;
|
|
19
|
+
constructor(out: stream.Writable);
|
|
20
|
+
writeDataStructureInitialization(fun: Fun): void;
|
|
21
|
+
writeDataStructureFinalization(fun: Fun): void;
|
|
22
|
+
writeTreeNode(node: SmeupTreeNode): void;
|
|
23
|
+
writeColumns(columns: SmeupColumn[]): void;
|
|
24
|
+
writeColumn(col: SmeupColumn): void;
|
|
25
|
+
writeRow(row: SmeupRow): void;
|
|
26
|
+
writeMessage(message: SmeupMessage): void;
|
|
27
|
+
getColumns(): SmeupColumn[];
|
|
28
|
+
getMessages(): SmeupMessage[];
|
|
29
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { SmeupDataStructureType, getSmeupDataStructureType, } from "../types/data-structures/smeupDataStructure.js";
|
|
2
|
+
var DATA_TYPE;
|
|
3
|
+
(function (DATA_TYPE) {
|
|
4
|
+
DATA_TYPE["COLUMN"] = "COLUMN";
|
|
5
|
+
DATA_TYPE["ROW"] = "ROW";
|
|
6
|
+
DATA_TYPE["NODE"] = "NODE";
|
|
7
|
+
})(DATA_TYPE || (DATA_TYPE = {}));
|
|
8
|
+
export class SmeupDataStructureWriter {
|
|
9
|
+
out;
|
|
10
|
+
initalTimestamp;
|
|
11
|
+
messages = [];
|
|
12
|
+
columns = [];
|
|
13
|
+
firstElement = true;
|
|
14
|
+
lastElementWritten;
|
|
15
|
+
isInitializationWritten = false;
|
|
16
|
+
isFinalizationWritten = false;
|
|
17
|
+
isColumnWritten = false;
|
|
18
|
+
isRowWritten = false;
|
|
19
|
+
isNodeWritten = false;
|
|
20
|
+
constructor(out) {
|
|
21
|
+
this.initalTimestamp = new Date();
|
|
22
|
+
this.out = out;
|
|
23
|
+
}
|
|
24
|
+
writeDataStructureInitialization(fun) {
|
|
25
|
+
if (!this.isInitializationWritten) {
|
|
26
|
+
this.initalTimestamp = new Date();
|
|
27
|
+
const type = getSmeupDataStructureType(fun);
|
|
28
|
+
this.out.write(utf8Encode("{"));
|
|
29
|
+
this.out.write(utf8Encode(`"type": "${type}"`));
|
|
30
|
+
this.isInitializationWritten = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
writeDataStructureFinalization(fun) {
|
|
34
|
+
if (!this.isFinalizationWritten) {
|
|
35
|
+
const type = getSmeupDataStructureType(fun);
|
|
36
|
+
switch (type) {
|
|
37
|
+
case SmeupDataStructureType.SmeupTree:
|
|
38
|
+
if (this.lastElementWritten != null) {
|
|
39
|
+
// close rows, columns or messages
|
|
40
|
+
this.out.write(utf8Encode("]"));
|
|
41
|
+
}
|
|
42
|
+
if (!this.isNodeWritten) {
|
|
43
|
+
this.out.write(utf8Encode(`,"children":[]`));
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case SmeupDataStructureType.SmeupTable:
|
|
47
|
+
// close rows or messages
|
|
48
|
+
if (this.lastElementWritten != null) {
|
|
49
|
+
// close rows, columns
|
|
50
|
+
this.out.write(utf8Encode("]"));
|
|
51
|
+
}
|
|
52
|
+
if (!this.isColumnWritten) {
|
|
53
|
+
this.out.write(utf8Encode(`,"columns":[]`));
|
|
54
|
+
}
|
|
55
|
+
if (!this.isRowWritten) {
|
|
56
|
+
this.out.write(utf8Encode(`,"rows":[]`));
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
// messages
|
|
61
|
+
this.out.write(utf8Encode(`,"messages":${JSON.stringify(this.getMessages())}`));
|
|
62
|
+
// debug info
|
|
63
|
+
const finalTimestamp = new Date();
|
|
64
|
+
const debugInfo = {
|
|
65
|
+
initialTimestamp: this.initalTimestamp.toISOString(),
|
|
66
|
+
finalTimestamp: finalTimestamp.toISOString(),
|
|
67
|
+
executionTime_ms: finalTimestamp.getTime() - this.initalTimestamp.getTime(),
|
|
68
|
+
};
|
|
69
|
+
this.out.write(utf8Encode(`,"debugInfo":${JSON.stringify(debugInfo)}`));
|
|
70
|
+
this.out.write(utf8Encode("}"));
|
|
71
|
+
this.out.end();
|
|
72
|
+
this.isFinalizationWritten = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
writeTreeNode(node) {
|
|
76
|
+
if (this.lastElementWritten != null) {
|
|
77
|
+
if (this.lastElementWritten != DATA_TYPE.NODE) {
|
|
78
|
+
// close columns/messages/actions... array
|
|
79
|
+
this.out.write(utf8Encode("]"));
|
|
80
|
+
// children init
|
|
81
|
+
this.out.write(utf8Encode(`,"children": [`));
|
|
82
|
+
this.firstElement = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// children init
|
|
87
|
+
this.out.write(utf8Encode(`,"children": [`));
|
|
88
|
+
this.firstElement = true;
|
|
89
|
+
}
|
|
90
|
+
// handle comma
|
|
91
|
+
if (!this.firstElement) {
|
|
92
|
+
this.out.write(utf8Encode(","));
|
|
93
|
+
}
|
|
94
|
+
this.out.write(utf8Encode(JSON.stringify(node)));
|
|
95
|
+
this.firstElement = false;
|
|
96
|
+
this.lastElementWritten = DATA_TYPE.NODE;
|
|
97
|
+
this.isNodeWritten = true;
|
|
98
|
+
}
|
|
99
|
+
writeColumns(columns) {
|
|
100
|
+
columns.forEach((col) => {
|
|
101
|
+
this.writeColumn(col);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
writeColumn(col) {
|
|
105
|
+
if (this.lastElementWritten == null) {
|
|
106
|
+
// column init
|
|
107
|
+
this.out.write(utf8Encode(',"columns": ['));
|
|
108
|
+
this.firstElement = true;
|
|
109
|
+
}
|
|
110
|
+
// handle comma
|
|
111
|
+
if (!this.firstElement) {
|
|
112
|
+
this.out.write(utf8Encode(","));
|
|
113
|
+
}
|
|
114
|
+
this.out.write(utf8Encode(JSON.stringify(col)));
|
|
115
|
+
this.firstElement = false;
|
|
116
|
+
this.lastElementWritten = DATA_TYPE.COLUMN;
|
|
117
|
+
this.isColumnWritten = true;
|
|
118
|
+
// add to arraylist
|
|
119
|
+
this.columns.push(col);
|
|
120
|
+
}
|
|
121
|
+
writeRow(row) {
|
|
122
|
+
if (this.lastElementWritten != null) {
|
|
123
|
+
if (this.lastElementWritten != DATA_TYPE.ROW) {
|
|
124
|
+
// close columns/messages/actions... array
|
|
125
|
+
this.out.write(utf8Encode("]"));
|
|
126
|
+
// rows init
|
|
127
|
+
this.out.write(utf8Encode(`,"rows": [`));
|
|
128
|
+
this.firstElement = true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// rows init
|
|
133
|
+
this.out.write(utf8Encode(`,"rows": [`));
|
|
134
|
+
this.firstElement = true;
|
|
135
|
+
}
|
|
136
|
+
// handle comma
|
|
137
|
+
if (!this.firstElement) {
|
|
138
|
+
this.out.write(utf8Encode(","));
|
|
139
|
+
}
|
|
140
|
+
// write row
|
|
141
|
+
this.out.write(utf8Encode(JSON.stringify(row)));
|
|
142
|
+
this.firstElement = false;
|
|
143
|
+
this.lastElementWritten = DATA_TYPE.ROW;
|
|
144
|
+
this.isRowWritten = true;
|
|
145
|
+
}
|
|
146
|
+
writeMessage(message) {
|
|
147
|
+
this.messages.push(message);
|
|
148
|
+
}
|
|
149
|
+
getColumns() {
|
|
150
|
+
return this.columns;
|
|
151
|
+
}
|
|
152
|
+
getMessages() {
|
|
153
|
+
return this.messages;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function utf8Encode(s) {
|
|
157
|
+
return Buffer.from(s, "utf-8");
|
|
158
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sme.up/kokos-sdk-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Kokos SDK Node.js",
|
|
5
5
|
"author": "Smeup LAB <info@smeup.com> (https://www.smeup.com/)",
|
|
6
6
|
"type": "module",
|
|
@@ -18,15 +18,12 @@
|
|
|
18
18
|
"package.json",
|
|
19
19
|
"tsconfig.json"
|
|
20
20
|
],
|
|
21
|
-
"bin": {
|
|
22
|
-
"kokos": "./bin/kokos.js"
|
|
23
|
-
},
|
|
24
21
|
"scripts": {
|
|
25
22
|
"clean": "rimraf lib",
|
|
26
23
|
"test": "NODE_ENV=test jest",
|
|
27
24
|
"build": "npm run clean && tsc",
|
|
28
|
-
"start
|
|
29
|
-
"dev
|
|
25
|
+
"start": "NODE_ENV=production node ./lib/entrypoint/restapi/index.js",
|
|
26
|
+
"dev": "NODE_ENV=development nodemon --watch './**/*.ts' --exec node --experimental-specifier-resolution=node --loader ts-node/esm ./src/entrypoint/restapi/index.ts"
|
|
30
27
|
},
|
|
31
28
|
"repository": {
|
|
32
29
|
"type": "git",
|
|
@@ -42,7 +39,8 @@
|
|
|
42
39
|
"class-transformer": "^0.5.1",
|
|
43
40
|
"class-validator": "^0.14.0",
|
|
44
41
|
"express": "^4.18.2",
|
|
45
|
-
"
|
|
42
|
+
"js-yaml": "^4.1.0",
|
|
43
|
+
"nodemon": "^3.0.1",
|
|
46
44
|
"rimraf": "^4.4.1",
|
|
47
45
|
"ts-node": "^10.9.1",
|
|
48
46
|
"typescript": "^4.9.4"
|
|
@@ -50,6 +48,7 @@
|
|
|
50
48
|
"devDependencies": {
|
|
51
49
|
"@types/express": "^4.17.17",
|
|
52
50
|
"@types/jest": "^29.5.0",
|
|
51
|
+
"@types/js-yaml": "^4.0.9",
|
|
53
52
|
"axios": "^1.3.4",
|
|
54
53
|
"jest": "^29.5.0",
|
|
55
54
|
"ts-jest": "^29.0.5"
|
package/tsconfig.json
CHANGED
package/bin/kokos.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// get argument
|
|
4
|
-
const action = process.argv[2];
|
|
5
|
-
|
|
6
|
-
switch (action) {
|
|
7
|
-
// generic actions
|
|
8
|
-
case "init":
|
|
9
|
-
import("../scripts/init.js");
|
|
10
|
-
break;
|
|
11
|
-
case "build":
|
|
12
|
-
import("../scripts/build.js");
|
|
13
|
-
break;
|
|
14
|
-
// rest api actions
|
|
15
|
-
case "dev:restapi":
|
|
16
|
-
import("../scripts/restapi/dev.js");
|
|
17
|
-
break;
|
|
18
|
-
case "start:restapi":
|
|
19
|
-
import("../scripts/restapi/start.js");
|
|
20
|
-
break;
|
|
21
|
-
case "build-image:restapi":
|
|
22
|
-
import("../scripts/restapi/build-image-restapi.js");
|
|
23
|
-
break;
|
|
24
|
-
default:
|
|
25
|
-
console.error("Operation not permitted");
|
|
26
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
FROM node:18-slim AS builder
|
|
2
|
-
WORKDIR /app
|
|
3
|
-
COPY package*.json ./
|
|
4
|
-
RUN npm install
|
|
5
|
-
COPY . .
|
|
6
|
-
RUN npm run build
|
|
7
|
-
|
|
8
|
-
FROM node:18-slim AS server
|
|
9
|
-
WORKDIR /app
|
|
10
|
-
COPY package* ./
|
|
11
|
-
RUN npm install
|
|
12
|
-
COPY --from=builder ./app/lib ./lib
|
|
13
|
-
EXPOSE 3000
|
|
14
|
-
CMD ["npm", "run", "start:restapi"]
|