@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.
Files changed (36) hide show
  1. package/README.md +1 -1
  2. package/lib/caller/serviceCaller.d.ts +3 -2
  3. package/lib/caller/serviceCaller.js +46 -12
  4. package/lib/configuration/configuration.d.ts +8 -0
  5. package/lib/configuration/configuration.js +29 -0
  6. package/lib/entrypoint/restapi/index.js +2 -110
  7. package/lib/entrypoint/restapi/restapi.d.ts +3 -0
  8. package/lib/entrypoint/restapi/restapi.js +145 -0
  9. package/lib/index.d.ts +8 -3
  10. package/lib/index.js +8 -3
  11. package/lib/logger/logger.d.ts +25 -0
  12. package/lib/logger/logger.js +84 -0
  13. package/lib/services/JS_00_01.js +42 -75
  14. package/lib/types/data-structures/smeupDataStructure.d.ts +27 -2
  15. package/lib/types/data-structures/smeupDataStructure.js +22 -1
  16. package/lib/types/data-structures/smeupObject.d.ts +2 -2
  17. package/lib/types/data-structures/smeupTree.d.ts +1 -1
  18. package/lib/types/general.d.ts +19 -2
  19. package/lib/types/general.js +7 -0
  20. package/lib/utils/path.js +1 -1
  21. package/lib/utils/regex.d.ts +9 -0
  22. package/lib/utils/regex.js +53 -0
  23. package/lib/utils/smeupDataStructureWriter.d.ts +29 -0
  24. package/lib/utils/smeupDataStructureWriter.js +158 -0
  25. package/package.json +6 -7
  26. package/tsconfig.json +1 -0
  27. package/bin/kokos.js +0 -26
  28. package/docker/restapi/Dockerfile +0 -14
  29. package/init/JS_00_01.txt +0 -88
  30. package/lib/types/exceptions/execution.d.ts +0 -7
  31. package/lib/types/exceptions/execution.js +0 -10
  32. package/scripts/build.js +0 -26
  33. package/scripts/init.js +0 -95
  34. package/scripts/restapi/build-image-restapi.js +0 -60
  35. package/scripts/restapi/dev.js +0 -30
  36. package/scripts/restapi/start.js +0 -14
package/init/JS_00_01.txt DELETED
@@ -1,88 +0,0 @@
1
- import {
2
- ExecutionContext,
3
- Fun,
4
- KokosService,
5
- SmeupTree,
6
- SmeupTable,
7
- SmeupDataStructureType,
8
- } from "@sme.up/kokos-sdk-node";
9
-
10
- const JS_00_01: KokosService = {
11
- methods: {
12
- "GET.TRE": getTree,
13
- "GET.EXB": getTable,
14
- },
15
- };
16
-
17
- async function getTree(fun: Fun, context: ExecutionContext): Promise<SmeupTree> {
18
- const tree: SmeupTree = {
19
- type: SmeupDataStructureType.SmeupTree,
20
- messages: [
21
- {
22
- gravity: "INFO",
23
- message: "Info message. CN;COL;PIPPO",
24
- mode: "TN",
25
- }
26
- ],
27
- children: [
28
- {
29
- children: [],
30
- content: {
31
- tipo: "",
32
- parametro: "",
33
- codice: "",
34
- testo: "Hello World",
35
- },
36
- },
37
- ],
38
- };
39
- return tree;
40
- }
41
-
42
- async function getTable(fun: Fun, context: ExecutionContext): Promise<SmeupTable> {
43
- const table: SmeupTable = {
44
- type: SmeupDataStructureType.SmeupTable,
45
- messages: [
46
- {
47
- gravity: "INFO",
48
- message: "Info message. CN;COL;PIPPO",
49
- mode: "TN",
50
- },
51
- {
52
- gravity: "WARNING",
53
- message: "Warning message. CN;COL;PLUTO",
54
- mode: "PM",
55
- },
56
- {
57
- gravity: "ERROR",
58
- message: "Error message.",
59
- mode: "PN",
60
- }
61
- ],
62
- columns: [
63
- {
64
- code: "COL",
65
- text: "Column",
66
- },
67
- ],
68
- rows: [
69
- {
70
- fields: {
71
- COL: {
72
- name: "COL",
73
- tooltip: false,
74
- smeupObject: {
75
- tipo: "",
76
- parametro: "",
77
- codice: "Hello World",
78
- testo: "Hello World",
79
- },
80
- }
81
- },
82
- },
83
- ],
84
- };
85
- return table;
86
- }
87
-
88
- export default JS_00_01;
@@ -1,7 +0,0 @@
1
- import { ApplicationException } from "./application.js";
2
- /**
3
- * Execution Exception
4
- */
5
- export declare class ExecutionException extends ApplicationException {
6
- constructor(message: string, error?: Error);
7
- }
@@ -1,10 +0,0 @@
1
- import { ApplicationException } from "./application.js";
2
- /**
3
- * Execution Exception
4
- */
5
- export class ExecutionException extends ApplicationException {
6
- constructor(message, error) {
7
- const errorMessage = error ? " - " + error.message : "";
8
- super(500, message + errorMessage);
9
- }
10
- }
package/scripts/build.js DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { exec } from "child_process";
4
-
5
- /**
6
- * BUILD
7
- */
8
-
9
- // start production mode
10
- console.log("Start building");
11
-
12
- // build project with typescript compiler
13
- const build = exec("rimraf lib && tsc");
14
-
15
- // redirect build stdout to standard output
16
- build.stdout.pipe(process.stdout);
17
- // redirect build stderr to standard output
18
- build.stderr.pipe(process.stderr);
19
-
20
- if (build.pid) {
21
- console.log(`Building...\nPress CTRL+C to exit\nPID: ${build.pid}`);
22
- }
23
-
24
- build.on("exit", function () {
25
- console.log("Build successfull");
26
- });
package/scripts/init.js DELETED
@@ -1,95 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import path from "path";
4
- import fs from "fs";
5
- import url from "url";
6
-
7
- /**
8
- * INITIALIZER SCRIPT
9
- *
10
- * syntax: npx @sme.up/kokos-template-node init [PROJECT_NAME]
11
- *
12
- * - create package.json
13
- * - create tsconfig.json
14
- * - create src/service/JS_00_01 example service
15
- */
16
-
17
- // constant
18
- const __filename = url.fileURLToPath(import.meta.url);
19
- const __dirname = path.dirname(__filename);
20
-
21
- try {
22
- // root path
23
- const rootPath = process.cwd();
24
-
25
- const projectName = process.argv[3];
26
- if (!projectName) {
27
- console.error(
28
- "Error: project name not defined \nSyntax: npx @sme.up/kokos-sdk-node init [PROJECT_NAME]"
29
- );
30
- process.exit();
31
- }
32
-
33
- const projectPath = path.resolve(rootPath, projectName);
34
-
35
- // create folder named as projecName
36
- fs.mkdirSync(projectPath);
37
-
38
- // read package.json, tsconfig.json, README.md
39
- const packageJson = JSON.parse(
40
- fs.readFileSync(path.resolve(__dirname, "../package.json"))
41
- );
42
- const tsconfigJson = JSON.parse(fs.readFileSync(
43
- path.resolve(__dirname, "../tsconfig.json")
44
- ));
45
- const readme = fs.readFileSync(path.resolve(__dirname, "../README.md"));
46
-
47
- // create package json
48
- const projectPackageJson = {
49
- name: projectName,
50
- version: "0.0.1",
51
- description: "Kokos Micro Executor Node.js",
52
- type: "module",
53
- scripts: {
54
- build: "kokos build",
55
- "build-image:restapi": "kokos build-image:restapi",
56
- "dev:restapi": "kokos dev:restapi",
57
- "start:restapi": "kokos start:restapi",
58
- },
59
- dependencies: {
60
- "@sme.up/kokos-template-node": packageJson.version,
61
- },
62
- };
63
- // create package.json
64
- const packageJsonStream = fs.createWriteStream(
65
- path.resolve(projectPath, "package.json")
66
- );
67
- packageJsonStream.write(JSON.stringify(projectPackageJson, null, "\t"));
68
- packageJsonStream.end();
69
- // create tsconfig.json
70
- const tsconfigStream = fs.createWriteStream(
71
- path.resolve(projectPath, "tsconfig.json")
72
- );
73
- tsconfigStream.write(JSON.stringify(tsconfigJson, null, "\t"));
74
- tsconfigStream.end();
75
- // create README.md file
76
- const readmeStream = fs.createWriteStream(
77
- path.resolve(projectPath, "README.md")
78
- );
79
- readmeStream.write(readme);
80
- readmeStream.end();
81
-
82
- // create src folder
83
- const srcFolder = path.resolve(projectPath, "src");
84
- fs.mkdirSync(srcFolder);
85
- // create services folder
86
- const serviceFolder = path.resolve(srcFolder, "services");
87
- fs.mkdirSync(serviceFolder);
88
- // load content from JS_00_01.txt
89
- // Copy /init/JS_00_01.txt file to [ROOT]/src/services/JS_00_01.ts
90
- const txtFile = path.resolve(__dirname, "../init/JS_00_01.txt");
91
- const tsFile = path.resolve(serviceFolder, "JS_00_01.ts");
92
- fs.copyFileSync(txtFile, tsFile);
93
- } catch (err) {
94
- console.error(err);
95
- }
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { exec } from "child_process";
4
- import { getProjectRoot } from "../../lib/utils/path.js";
5
- import { readFile } from "fs/promises";
6
- import path from "path";
7
- import fs from "fs";
8
-
9
- /**
10
- * BUILD IMAGE FOR REST API
11
- */
12
-
13
- try {
14
- // dockerfile path
15
- const dockerfilePath = path.resolve(
16
- `${getProjectRoot()}/node_modules/@sme.up/kokos-sdk-node/docker/restapi/Dockerfile`
17
- );
18
- const destinationDockerfilePath = `${getProjectRoot()}/Dockerfile`;
19
-
20
- // copy dockerfile to project root
21
- fs.copyFileSync(dockerfilePath, destinationDockerfilePath);
22
-
23
- // load package json
24
- const packageJson = JSON.parse(
25
- await readFile(new URL(getProjectRoot() + "/package.json", import.meta.url))
26
- );
27
-
28
- // get image name based on project name
29
- let imageName;
30
- if (packageJson.name.includes("@")) {
31
- imageName = packageJson.name.substring(packageJson.name.indexOf("/") + 1);
32
- } else {
33
- imageName = packageJson.name;
34
- }
35
-
36
- // start production mode
37
- console.log(`Start build image for REST API: ${imageName}`);
38
-
39
- // build project with typescript compiler
40
- const dockerBuild = exec(`docker build -t ${imageName} .`);
41
-
42
- // redirect docker build stdout to standard output
43
- dockerBuild.stdout.pipe(process.stdout);
44
- // redirect docker build stderr to standard output
45
- dockerBuild.stderr.pipe(process.stderr);
46
-
47
- if (dockerBuild.pid) {
48
- console.log(
49
- `Building image...\nPress CTRL+C to exit\nPID: ${dockerBuild.pid}`
50
- );
51
- }
52
-
53
- dockerBuild.on("exit", function () {
54
- // delete dockerfile from project root
55
- fs.unlinkSync(destinationDockerfilePath);
56
- console.log("Image build successfull");
57
- });
58
- } catch (err) {
59
- console.error(err);
60
- }
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { exec } from "child_process";
4
-
5
- /**
6
- * DEVELOPMENT MODE
7
- */
8
-
9
- // set environment variables
10
- process.env.NODE_ENV = "development";
11
-
12
- // start nodemon
13
- const devServer = exec(
14
- "NODE_ENV=development nodemon --watch src/**/* -e ts,js --exec node --experimental-specifier-resolution=node --loader ts-node/esm node_modules/@sme.up/kokos-sdk-node/lib/entrypoint/restapi/index.js"
15
- );
16
-
17
- // redirect docker build stdout to standard output
18
- devServer.stdout.pipe(process.stdout);
19
- // redirect docker build stderr to standard output
20
- devServer.stderr.pipe(process.stderr);
21
-
22
- if (!devServer.pid) {
23
- console.log(
24
- `Development mode active \nPress CTRL+C to exit\nPID: ${devServer.pid}`
25
- );
26
- }
27
-
28
- devServer.on("exit", function () {
29
- console.log("Development server terminated");
30
- });
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * PRODUCTION MODE
5
- */
6
-
7
- // start production mode
8
- console.log("Start production mode");
9
-
10
- // set environment variables
11
- process.env.NODE_ENV = "production";
12
-
13
- // start rest api entrypoint
14
- import("../../lib/entrypoint/restapi/index.js");