@sme.up/kokos-sdk-node 0.0.3 → 0.0.6

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 (82) hide show
  1. package/README.md +1 -1
  2. package/docs/assets/highlight.css +0 -56
  3. package/docs/assets/main.js +4 -3
  4. package/docs/assets/navigation.js +1 -0
  5. package/docs/assets/search.js +1 -1
  6. package/docs/assets/style.css +95 -39
  7. package/docs/classes/ErrorWithStatus.html +13 -0
  8. package/docs/classes/ExecuteFunPayload.html +5 -108
  9. package/docs/classes/ExecutionContext.html +4 -101
  10. package/docs/classes/Fun.html +14 -171
  11. package/docs/classes/FunObject.html +6 -115
  12. package/docs/classes/SmeupDataStructureWriter.html +22 -0
  13. package/docs/classes/User.html +7 -122
  14. package/docs/enums/Format.html +3 -0
  15. package/docs/enums/Level.html +4 -0
  16. package/docs/enums/SmeupDataStructureType.html +8 -95
  17. package/docs/functions/clearLoggerContext.html +1 -0
  18. package/docs/functions/configureLogger.html +1 -0
  19. package/docs/functions/createLoggerContext.html +1 -0
  20. package/docs/functions/getSmeupDataStructureType.html +1 -0
  21. package/docs/functions/parseKeyValueBetweenBrackets.html +2 -0
  22. package/docs/functions/startServer.html +1 -0
  23. package/docs/functions/startServerWithCustomConfig.html +1 -0
  24. package/docs/index.html +3 -92
  25. package/docs/interfaces/DebugInfo.html +4 -0
  26. package/docs/interfaces/KokosService.html +3 -88
  27. package/docs/interfaces/KokosServiceMethods.html +2 -83
  28. package/docs/interfaces/KokosServiceModule.html +3 -88
  29. package/docs/interfaces/LoggerContext.html +5 -0
  30. package/docs/interfaces/MicroExecutorConfiguration.html +4 -0
  31. package/docs/interfaces/SmeupCell.html +7 -106
  32. package/docs/interfaces/SmeupColumn.html +26 -204
  33. package/docs/interfaces/SmeupDataStructure.html +5 -91
  34. package/docs/interfaces/SmeupFeedback.html +5 -0
  35. package/docs/interfaces/SmeupMessage.html +5 -102
  36. package/docs/interfaces/SmeupObject.html +18 -153
  37. package/docs/interfaces/SmeupRow.html +3 -93
  38. package/docs/interfaces/SmeupTable.html +7 -105
  39. package/docs/interfaces/SmeupTree.html +8 -112
  40. package/docs/interfaces/SmeupTreeNode.html +6 -109
  41. package/docs/modules.html +37 -93
  42. package/docs/variables/LOGGER.html +1 -0
  43. package/docs/variables/SMEUP_MESSAGE_GRAVITY.html +2 -72
  44. package/docs/variables/SMEUP_MESSAGE_MODE.html +2 -0
  45. package/lib/caller/serviceCaller.d.ts +3 -2
  46. package/lib/caller/serviceCaller.js +50 -21
  47. package/lib/configuration/configuration.d.ts +8 -0
  48. package/lib/configuration/configuration.js +29 -0
  49. package/lib/entrypoint/restapi/index.js +2 -110
  50. package/lib/entrypoint/restapi/restapi.d.ts +3 -0
  51. package/lib/entrypoint/restapi/restapi.js +149 -0
  52. package/lib/index.d.ts +8 -3
  53. package/lib/index.js +8 -3
  54. package/lib/logger/logger.d.ts +26 -0
  55. package/lib/logger/logger.js +87 -0
  56. package/lib/services/JS_00_01.js +42 -75
  57. package/lib/types/data-structures/smeupDataStructure.d.ts +27 -2
  58. package/lib/types/data-structures/smeupDataStructure.js +22 -1
  59. package/lib/types/data-structures/smeupObject.d.ts +2 -2
  60. package/lib/types/data-structures/smeupTree.d.ts +1 -1
  61. package/lib/types/general.d.ts +19 -2
  62. package/lib/types/general.js +7 -0
  63. package/lib/utils/fun.d.ts +3 -0
  64. package/lib/utils/fun.js +6 -0
  65. package/lib/utils/path.js +1 -1
  66. package/lib/utils/regex.d.ts +9 -0
  67. package/lib/utils/regex.js +53 -0
  68. package/lib/utils/smeupDataStructureWriter.d.ts +29 -0
  69. package/lib/utils/smeupDataStructureWriter.js +158 -0
  70. package/package.json +13 -14
  71. package/tsconfig.json +1 -0
  72. package/bin/kokos.js +0 -26
  73. package/docker/restapi/Dockerfile +0 -14
  74. package/docs/types/SmeupMessageGravity.html +0 -61
  75. package/init/JS_00_01.txt +0 -88
  76. package/lib/types/exceptions/execution.d.ts +0 -7
  77. package/lib/types/exceptions/execution.js +0 -10
  78. package/scripts/build.js +0 -26
  79. package/scripts/init.js +0 -95
  80. package/scripts/restapi/build-image-restapi.js +0 -60
  81. package/scripts/restapi/dev.js +0 -30
  82. package/scripts/restapi/start.js +0 -14
@@ -0,0 +1,149 @@
1
+ import express from "express";
2
+ import bodyParser from "body-parser";
3
+ import { plainToInstance } from "class-transformer";
4
+ import { validate } from "class-validator";
5
+ import { ValidationException } from "../../types/exceptions/validation.js";
6
+ import { ExecuteFunPayload, } from "../../types/general.js";
7
+ import { serviceCaller } from "../../caller/serviceCaller.js";
8
+ import { fileURLToPath } from "url";
9
+ import { dirname, normalize } from "path";
10
+ import stream from "stream";
11
+ import { SMEUP_MESSAGE_GRAVITY, SMEUP_MESSAGE_MODE, } from "../../types/data-structures/smeupDataStructure.js";
12
+ import { init } from "../../configuration/configuration.js";
13
+ import { Format, LOGGER, Level, configureLogger } from "../../logger/logger.js";
14
+ // constant
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+ export function startServer(microExecutorId) {
18
+ startServerWithCustomConfig(microExecutorId, {
19
+ server: {
20
+ port: 8011,
21
+ },
22
+ logger: {
23
+ format: Format.TXT,
24
+ level: Level.DEBUG,
25
+ },
26
+ });
27
+ }
28
+ export function startServerWithCustomConfig(microExecutorId, defaultConfigurationClass, callback) {
29
+ // load config
30
+ const configuration = init(microExecutorId, defaultConfigurationClass);
31
+ if (callback) {
32
+ // call callback
33
+ callback(configuration);
34
+ }
35
+ configureLogger(configuration.logger?.level, configuration.logger?.format);
36
+ // create server
37
+ const app = express();
38
+ // body parse middleware
39
+ app.use(bodyParser.json());
40
+ // swagger
41
+ const swaggerPath = normalize(`${__dirname}/../../../swagger`);
42
+ app.use("/swagger", express.static(swaggerPath));
43
+ // docs
44
+ const docsPath = normalize(`${__dirname}/../../../docs`);
45
+ app.use("/docs", express.static(docsPath));
46
+ /**
47
+ * REST API Entrypoint
48
+ */
49
+ /**
50
+ * EXECUTION API
51
+ */
52
+ /**
53
+ * /executeFun API
54
+ */
55
+ app.use("/api/v1/executeFun", validationMiddleware(ExecuteFunPayload), (req, res, next) => {
56
+ // get body
57
+ const { fun, context } = req.body;
58
+ // set status
59
+ res.status(200);
60
+ res.setHeader("Content-Type", "application/json");
61
+ // create stream
62
+ const out = new stream.Writable({
63
+ write(chunk, encoding, callback) {
64
+ res.write(chunk, encoding);
65
+ callback();
66
+ },
67
+ });
68
+ // call service caller
69
+ serviceCaller(fun, context, out)
70
+ .then(() => {
71
+ res.end();
72
+ })
73
+ .catch((err) => {
74
+ next(err);
75
+ });
76
+ });
77
+ /**
78
+ * MONITORING API
79
+ */
80
+ /**
81
+ * /livez API
82
+ */
83
+ app.use("/api/v1/livez", async (req, res) => {
84
+ res.status(200).send({
85
+ status: "ok",
86
+ });
87
+ });
88
+ /**
89
+ * /readyz API
90
+ */
91
+ app.use("/api/v1/readyz", async (req, res) => {
92
+ res.status(200).send({
93
+ status: "ok",
94
+ });
95
+ });
96
+ // error middleware
97
+ app.use(errorMiddleware);
98
+ // start server
99
+ const PORT = configuration.server.port || 3000;
100
+ app.listen(PORT, () => {
101
+ LOGGER.info(`App listening on the port ${PORT}`);
102
+ });
103
+ /**
104
+ * MIDDLEWARES
105
+ */
106
+ /**
107
+ * Validation Middleware
108
+ * Validate request body
109
+ * @param type
110
+ * @param skipMissingProperties
111
+ * @returns
112
+ */
113
+ function validationMiddleware(type) {
114
+ return (req, res, next) => {
115
+ validate(plainToInstance(type, req.body)).then((errors) => {
116
+ if (errors.length > 0) {
117
+ const message = errors
118
+ .map((error) => error.constraints && Object.values(error.constraints))
119
+ .join(", ");
120
+ next(new ValidationException(message));
121
+ }
122
+ else {
123
+ next();
124
+ }
125
+ });
126
+ };
127
+ }
128
+ /**
129
+ * Error Middleware
130
+ * Handle all application error
131
+ * @param error
132
+ * @param request
133
+ * @param response
134
+ */
135
+ function errorMiddleware(error, _request, response, _next) {
136
+ const status = error.status || 500;
137
+ const message = error.message || "Something went wrong";
138
+ LOGGER.error(error);
139
+ response.status(status).json({
140
+ messages: [
141
+ {
142
+ gravity: SMEUP_MESSAGE_GRAVITY.ERROR,
143
+ message: message,
144
+ mode: SMEUP_MESSAGE_MODE.PN,
145
+ },
146
+ ],
147
+ });
148
+ }
149
+ }
package/lib/index.d.ts CHANGED
@@ -1,9 +1,14 @@
1
- /**
2
- * TYPES
3
- */
1
+ /** TYPES */
4
2
  export * from "./types/general.js";
5
3
  /** DATA STRUCTURES */
6
4
  export * from "./types/data-structures/smeupDataStructure.js";
7
5
  export * from "./types/data-structures/smeupObject.js";
8
6
  export * from "./types/data-structures/smeupTable.js";
9
7
  export * from "./types/data-structures/smeupTree.js";
8
+ /** ENTRYPOINT */
9
+ export * from "./entrypoint/restapi/restapi.js";
10
+ /** LOGGER */
11
+ export * from "./logger/logger.js";
12
+ /** UTILS */
13
+ export * from "./utils/smeupDataStructureWriter.js";
14
+ export * from "./utils/regex.js";
package/lib/index.js CHANGED
@@ -1,9 +1,14 @@
1
- /**
2
- * TYPES
3
- */
1
+ /** TYPES */
4
2
  export * from "./types/general.js";
5
3
  /** DATA STRUCTURES */
6
4
  export * from "./types/data-structures/smeupDataStructure.js";
7
5
  export * from "./types/data-structures/smeupObject.js";
8
6
  export * from "./types/data-structures/smeupTable.js";
9
7
  export * from "./types/data-structures/smeupTree.js";
8
+ /** ENTRYPOINT */
9
+ export * from "./entrypoint/restapi/restapi.js";
10
+ /** LOGGER */
11
+ export * from "./logger/logger.js";
12
+ /** UTILS */
13
+ export * from "./utils/smeupDataStructureWriter.js";
14
+ export * from "./utils/regex.js";
@@ -0,0 +1,26 @@
1
+ export interface LoggerContext {
2
+ fun: string;
3
+ sessionId: string;
4
+ user: string;
5
+ environment: string;
6
+ }
7
+ export declare enum Level {
8
+ INFO = "INFO",
9
+ DEBUG = "DEBUG",
10
+ ERROR = "ERROR"
11
+ }
12
+ export declare enum Format {
13
+ JSON = "JSON",
14
+ TXT = "TXT"
15
+ }
16
+ export declare const configureLogger: (level?: Level, format?: Format) => void;
17
+ export declare const createLoggerContext: (context: LoggerContext) => void;
18
+ export declare const clearLoggerContext: () => void;
19
+ declare class Logger {
20
+ info(message: string): void;
21
+ debug(message: string): void;
22
+ error(error: Error): void;
23
+ private _log;
24
+ }
25
+ export declare const LOGGER: Logger;
26
+ export {};
@@ -0,0 +1,87 @@
1
+ import async_hooks from "async_hooks";
2
+ export var Level;
3
+ (function (Level) {
4
+ Level["INFO"] = "INFO";
5
+ Level["DEBUG"] = "DEBUG";
6
+ Level["ERROR"] = "ERROR";
7
+ })(Level || (Level = {}));
8
+ export var Format;
9
+ (function (Format) {
10
+ Format["JSON"] = "JSON";
11
+ Format["TXT"] = "TXT";
12
+ })(Format || (Format = {}));
13
+ const LOGGER_SETTING = {
14
+ level: Level.DEBUG,
15
+ format: Format.TXT,
16
+ };
17
+ const LOGGER_CONTEXT_MAP = {};
18
+ export const configureLogger = (level, format) => {
19
+ LOGGER_SETTING.level = level ? level : Level.DEBUG;
20
+ LOGGER_SETTING.format = format ? format : Format.TXT;
21
+ };
22
+ export const createLoggerContext = (context) => {
23
+ // get the async execution id
24
+ const id = async_hooks.executionAsyncId();
25
+ // save to context map
26
+ LOGGER_CONTEXT_MAP[id] = context;
27
+ };
28
+ export const clearLoggerContext = () => {
29
+ // get the async execution id
30
+ const id = async_hooks.executionAsyncId();
31
+ // delete from context map
32
+ delete LOGGER_CONTEXT_MAP[id];
33
+ };
34
+ class Logger {
35
+ info(message) {
36
+ this._log(Level.INFO, message);
37
+ }
38
+ debug(message) {
39
+ this._log(Level.DEBUG, message);
40
+ }
41
+ error(error) {
42
+ this._log(Level.ERROR, error.message, error);
43
+ }
44
+ _log(level, message, error) {
45
+ // logger level
46
+ if (LOGGER_SETTING.level == Level.INFO && level == Level.DEBUG) {
47
+ return;
48
+ }
49
+ // get the async execution id
50
+ const id = async_hooks.executionAsyncId();
51
+ // get context
52
+ const context = LOGGER_CONTEXT_MAP[id];
53
+ // create log record
54
+ const record = {
55
+ ...context,
56
+ timestamp: new Date().toISOString(),
57
+ applicationId: "",
58
+ message: message,
59
+ level: level.toString(),
60
+ applicationReserved: {
61
+ executionId: id.toString(),
62
+ stackTrace: error && error.stack ? error.stack : "",
63
+ },
64
+ };
65
+ let stringRecord = "";
66
+ if (LOGGER_SETTING.format == Format.JSON) {
67
+ stringRecord = JSON.stringify(record);
68
+ }
69
+ else {
70
+ stringRecord = `${record.timestamp} ${record.applicationReserved.executionId} ${record.level} - ${record.message} ${record.applicationReserved.stackTrace
71
+ ? record.applicationReserved.stackTrace
72
+ : ""}`;
73
+ }
74
+ switch (level) {
75
+ case Level.INFO:
76
+ console.info(stringRecord);
77
+ break;
78
+ case Level.DEBUG:
79
+ console.debug(stringRecord);
80
+ break;
81
+ case Level.ERROR:
82
+ console.error(stringRecord);
83
+ break;
84
+ }
85
+ }
86
+ }
87
+ export const LOGGER = new Logger();
@@ -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(fun, context) {
9
- const tree = {
10
- type: SmeupDataStructureType.SmeupTree,
11
- messages: [
12
- {
13
- gravity: "INFO",
14
- message: "Info message. CN;COL;PIPPO",
15
- mode: "TN",
16
- }
17
- ],
18
- children: [
19
- {
20
- children: [],
21
- content: {
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
- return tree;
31
- }
32
- async function getTable(fun, context) {
33
- const table = {
34
- type: SmeupDataStructureType.SmeupTable,
35
- messages: [
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
- return table;
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
- export type SmeupMessageGravity = typeof SMEUP_MESSAGE_GRAVITY[keyof typeof SMEUP_MESSAGE_GRAVITY];
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
+ };
@@ -3,9 +3,9 @@
3
3
  */
4
4
  export interface SmeupObject {
5
5
  /** type (T) */
6
- tipo: string;
6
+ tipo?: string;
7
7
  /** parameter (P) */
8
- parametro: string;
8
+ parametro?: string;
9
9
  /** code (K) */
10
10
  codice: string;
11
11
  /** text (D) */
@@ -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: SmeupTreeNode[];
17
+ children?: SmeupTreeNode[];
18
18
  content: SmeupObject;
19
19
  columns?: SmeupColumn[];
20
20
  row?: SmeupRow;
@@ -1,4 +1,21 @@
1
- import { SmeupDataStructure } from "./data-structures/smeupDataStructure.js";
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<SmeupDataStructure>;
81
+ [key: string]: (fun: Fun, context: ExecutionContext, printer: SmeupDataStructureWriter) => Promise<void>;
65
82
  }
@@ -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
  */
@@ -0,0 +1,3 @@
1
+ import { Fun, FunObject } from "../types/general";
2
+ export declare function funToString(fun: Fun): string;
3
+ export declare function funObjectToString(obj: FunObject): string;
@@ -0,0 +1,6 @@
1
+ export function funToString(fun) {
2
+ return `F(${fun.component};${fun.service};${fun.function}) ${fun.obj1 && "1(" + funObjectToString(fun.obj1) + ")"} ${fun.obj2 && "2(" + funObjectToString(fun.obj2) + ")"} ${fun.obj3 && "3(" + funObjectToString(fun.obj3) + ")"} ${fun.obj4 && "4(" + funObjectToString(fun.obj4) + ")"} ${fun.obj5 && "5(" + funObjectToString(fun.obj5) + ")"} ${fun.obj6 && "6(" + funObjectToString(fun.obj6) + ")"} ${fun.P && "P(" + fun.P + ")"} ${fun.INPUT && "INPUT(" + fun.INPUT + ")"}`;
3
+ }
4
+ export function funObjectToString(obj) {
5
+ return `${obj.t ? obj.t : ""};${obj.p ? obj.p : ""};${obj.k ? obj.k : ""}`;
6
+ }
package/lib/utils/path.js CHANGED
@@ -10,7 +10,7 @@ export function getProjectRoot() {
10
10
  const parentDir = path.dirname(dir);
11
11
  if (dir === parentDir) {
12
12
  // Reached the root directory without finding package.json
13
- return null;
13
+ return "";
14
14
  }
15
15
  dir = parentDir;
16
16
  }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Parse key(value) expression NB. Nested brackets must be even
3
+ *
4
+ * @param expression
5
+ * @return
6
+ */
7
+ export declare function parseKeyValueBetweenBrackets(expression: string): {
8
+ [key: string]: string;
9
+ };
@@ -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
+ }