state-machine-cat 10.1.6 → 10.1.7

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 (79) hide show
  1. package/bin/smcat.mjs +5 -4
  2. package/dist/commonjs/bundle.js +67 -67
  3. package/{src → dist/esm}/cli/actions.mjs +24 -40
  4. package/dist/esm/cli/attributes-parser.mjs +981 -0
  5. package/dist/esm/cli/file-name-to-stream.mjs +13 -0
  6. package/dist/esm/cli/make-description.mjs +21 -0
  7. package/dist/esm/cli/normalize.mjs +95 -0
  8. package/dist/esm/cli/validations.mjs +70 -0
  9. package/dist/esm/index-node.mjs +16 -0
  10. package/dist/esm/index.mjs +19 -0
  11. package/dist/esm/options.mjs +61 -0
  12. package/dist/esm/parse/index.mjs +27 -0
  13. package/dist/esm/parse/parser-helpers.mjs +175 -0
  14. package/dist/esm/parse/scxml/index.mjs +136 -0
  15. package/dist/esm/parse/scxml/normalize-machine.mjs +44 -0
  16. package/dist/esm/parse/smcat/smcat-parser.mjs +2924 -0
  17. package/dist/esm/parse/smcat-ast.schema.mjs +170 -0
  18. package/dist/esm/render/dot/attributebuilder.mjs +51 -0
  19. package/dist/esm/render/dot/counter.mjs +16 -0
  20. package/dist/esm/render/dot/dot.states.template.js +26 -0
  21. package/dist/esm/render/dot/dot.template.js +14 -0
  22. package/dist/esm/render/dot/index.mjs +106 -0
  23. package/dist/esm/render/dot/render-dot-from-ast.js +29 -0
  24. package/dist/esm/render/dot/state-transformers.mjs +113 -0
  25. package/dist/esm/render/dot/transition-transformers.mjs +49 -0
  26. package/dist/esm/render/dot/utl.mjs +29 -0
  27. package/dist/esm/render/index-node.mjs +28 -0
  28. package/dist/esm/render/index.mjs +20 -0
  29. package/dist/esm/render/scjson/index.mjs +121 -0
  30. package/dist/esm/render/scjson/make-valid-event-names.mjs +27 -0
  31. package/dist/esm/render/scjson/make-valid-xml-name.mjs +19 -0
  32. package/dist/esm/render/scxml/index.mjs +4 -0
  33. package/dist/esm/render/scxml/render-from-scjson.js +9 -0
  34. package/dist/esm/render/scxml/scxml.states.template.js +14 -0
  35. package/dist/esm/render/scxml/scxml.template.js +6 -0
  36. package/dist/esm/render/smcat/index.js +63 -0
  37. package/dist/esm/render/smcat/smcat.template.js +13 -0
  38. package/dist/esm/render/vector/dot-to-vector-native.mjs +35 -0
  39. package/dist/esm/render/vector/vector-native-dot-with-fallback.mjs +37 -0
  40. package/dist/esm/render/vector/vector-with-viz-js.mjs +13 -0
  41. package/dist/esm/state-machine-model.mjs +58 -0
  42. package/dist/esm/transform/desugar.mjs +77 -0
  43. package/dist/esm/transform/utl.mjs +16 -0
  44. package/dist/esm/version.mjs +1 -0
  45. package/package.json +32 -41
  46. package/src/render/dot/dot.states.template.js +1 -1
  47. package/src/render/dot/index.mjs +14 -14
  48. package/types/state-machine-cat.d.ts +4 -4
  49. package/src/cli/file-name-to-stream.mjs +0 -25
  50. package/src/cli/make-description.mjs +0 -45
  51. package/src/cli/normalize.mjs +0 -204
  52. package/src/cli/validations.mjs +0 -140
  53. package/src/index-node.mjs +0 -55
  54. package/src/index.mjs +0 -58
  55. package/src/options.mjs +0 -78
  56. package/src/parse/index.mjs +0 -47
  57. package/src/parse/parser-helpers.mjs +0 -297
  58. package/src/parse/scxml/normalize-machine.mjs +0 -73
  59. package/src/parse/smcat-ast.schema.mjs +0 -187
  60. package/src/render/dot/attributebuilder.mjs +0 -68
  61. package/src/render/dot/counter.mjs +0 -33
  62. package/src/render/dot/render-dot-from-ast.js +0 -70
  63. package/src/render/dot/state-transformers.mjs +0 -128
  64. package/src/render/dot/transition-transformers.mjs +0 -52
  65. package/src/render/dot/utl.mjs +0 -56
  66. package/src/render/index-node.mjs +0 -36
  67. package/src/render/index.mjs +0 -22
  68. package/src/render/scjson/index.mjs +0 -175
  69. package/src/render/scjson/make-valid-event-names.mjs +0 -71
  70. package/src/render/scjson/make-valid-xml-name.mjs +0 -70
  71. package/src/render/scxml/index.mjs +0 -8
  72. package/src/render/smcat/index.js +0 -129
  73. package/src/render/vector/dot-to-vector-native.mjs +0 -60
  74. package/src/render/vector/vector-native-dot-with-fallback.mjs +0 -55
  75. package/src/render/vector/vector-with-viz-js.mjs +0 -18
  76. package/src/state-machine-model.mjs +0 -124
  77. package/src/transform/desugar.mjs +0 -222
  78. package/src/transform/utl.mjs +0 -26
  79. package/src/version.mjs +0 -2
@@ -1,204 +0,0 @@
1
- // @ts-check
2
- /* eslint-disable security/detect-object-injection, no-inline-comments */
3
- import path from "node:path";
4
- import options from "../options.mjs";
5
- import { parse as parseAttributes } from "./attributes-parser.mjs";
6
-
7
- /**
8
- * @typedef {{[extension: string]: string}} DictionaryType
9
- */
10
-
11
- const INPUT_EXTENSIONS = {
12
- ".smcat": "smcat",
13
- ".scxml": "scxml",
14
- ".xml": "scxml",
15
- ".json": "json",
16
- ".ast": "json",
17
- };
18
-
19
- const OUTPUT_EXTENSIONS = {
20
- ".ast": "json",
21
- ".dot": "dot",
22
- ".eps": "eps",
23
- ".json": "json",
24
- ".pdf": "pdf",
25
- ".png": "png",
26
- ".ps": "ps",
27
- ".ps2": "ps2",
28
- ".scjson": "scjson",
29
- ".scxml": "scxml",
30
- ".smcat": "smcat",
31
- ".svg": "svg",
32
- };
33
-
34
- /**
35
- * Given a filename in pString, returns what language is probably
36
- * contained in that file, judging from the extension (the last dot
37
- * in the string to end-of-string)
38
- *
39
- * When in doubt returns pDefault
40
- *
41
- * @param {string} pString - filename
42
- * @param {DictionaryType} pExtensionMap - a dictionary with
43
- * extension : classification pairs
44
- * @param {string} pDefault - the default to return when the extension
45
- * does not occur in the extension map
46
- * @return {string} - language. Possible values: LHS of the passed
47
- * extension map.
48
- */
49
- function classifyExtension(pString, pExtensionMap, pDefault) {
50
- return pExtensionMap[path.extname(pString)] || pDefault;
51
- }
52
-
53
- /**
54
- * @param {import("../..").OutputType} pOutputType
55
- * @returns {import("../..").OutputType}
56
- */
57
- function outputType2Extension(pOutputType) {
58
- const lExceptions = {
59
- oldeps: "eps",
60
- oldps: "ps",
61
- oldps2: "ps",
62
- oldsvg: "svg",
63
- ps2: "ps",
64
- };
65
- return lExceptions[pOutputType] || pOutputType;
66
- }
67
-
68
- /**
69
- * @param {string} pInputFrom
70
- * @param {import("../..").OutputType} pOutputType
71
- * @returns {string}
72
- */
73
- function deriveOutputFromInput(pInputFrom, pOutputType) {
74
- const lExtension = outputType2Extension(pOutputType);
75
-
76
- if (!pInputFrom || "-" === pInputFrom) {
77
- return "-";
78
- }
79
- return path
80
- .join(
81
- path.dirname(pInputFrom),
82
- path.basename(pInputFrom, path.extname(pInputFrom))
83
- )
84
- .concat(".")
85
- .concat(lExtension);
86
- }
87
-
88
- /**
89
- * @param {string|undefined} pOutputTo
90
- * @param {string} pInputFrom
91
- * @param {import("../..").OutputType} pOutputType
92
- * @returns {string}
93
- */
94
- function determineOutputTo(pOutputTo, pInputFrom, pOutputType) {
95
- return pOutputTo ? pOutputTo : deriveOutputFromInput(pInputFrom, pOutputType);
96
- }
97
-
98
- /**
99
- * @param {string} pInputFrom
100
- * @param {import("../..").InputType} [pInputType]
101
- * @returns {import("../..").InputType}
102
- */
103
- function determineInputType(pInputFrom, pInputType) {
104
- if (pInputType) {
105
- return pInputType;
106
- }
107
- // @ts-expect-error we can safely cast this to InputType. classifyExtension
108
- // can probably use treatment with a generic, but with jsdoc annotations
109
- // if at all possible would likely be awkward.
110
- return classifyExtension(
111
- pInputFrom,
112
- INPUT_EXTENSIONS,
113
- options.getAllowedValues().inputType.default
114
- );
115
- }
116
- /**
117
- *
118
- * @param {string} [pOutputTo]
119
- * @param {import("../..").OutputType} [pOutputType]
120
- * @returns {import("../..").OutputType}
121
- */
122
- function determineOutputType(pOutputTo, pOutputType) {
123
- if (pOutputType) {
124
- return pOutputType;
125
- }
126
- if (pOutputTo) {
127
- // @ts-expect-error we can safely cast this to OutputType. classifyExtension
128
- // can probably use treatment with a generic, but with jsdoc annotations
129
- // if at all possible would likely be awkward.
130
- return classifyExtension(
131
- pOutputTo,
132
- OUTPUT_EXTENSIONS,
133
- options.getAllowedValues().outputType.default
134
- );
135
- }
136
- // @ts-expect-error cast to OutputType is safe - see above
137
- return options.getAllowedValues().outputType.default;
138
- }
139
- /**
140
- *
141
- * @param {import("./cli").ILooseCLIRenderOptions} pOptions
142
- * @param {string} pParameter
143
- * @returns string
144
- */
145
- function determineParameter(pOptions, pParameter) {
146
- return Object.prototype.hasOwnProperty.call(pOptions, pParameter)
147
- ? pOptions[pParameter]
148
- : options.getAllowedValues()[pParameter].default;
149
- }
150
-
151
- /**
152
- * @param {Partial<import("./cli").ILooseCLIRenderOptions>} pOptions
153
- * @param {keyof import("./cli").ILooseCLIRenderOptions} pDotAttributes
154
- * @returns {import("../..").dotAttributesType}
155
- */
156
- function determineDotAttributes(pOptions, pDotAttributes) {
157
- return Boolean(pOptions?.[pDotAttributes]) &&
158
- typeof pOptions[pDotAttributes] === "string"
159
- ? // @ts-expect-error parseAttributes expects a string - which we can guarantee (see above) - but tsc can't/ doesn't see it
160
- parseAttributes(pOptions[pDotAttributes])
161
- : [];
162
- }
163
-
164
- /**
165
- * transforms the given argument and options to a uniform format
166
- *
167
- * - guesses the input type when not given
168
- * - guesses the output type when not given
169
- * - guesses the filename to output to when not given
170
- * - translates parserOutput to a regular output type
171
- *
172
- * @param {string} pArgument an argument (containing the filename to parse)
173
- * @param {import("./cli").ILooseCLIRenderOptions} pLooseOptions
174
- * @return {import("./cli").ICLIRenderOptions}
175
- * the passed options object, but normalized
176
- */
177
- export default function normalize(pArgument = "-", pLooseOptions = {}) {
178
- const lNormalizedInputFrom = pArgument || "-";
179
- const lNormalizedInputType = determineInputType(
180
- lNormalizedInputFrom,
181
- pLooseOptions.inputType
182
- );
183
- const lNormalizedOutputType = determineOutputType(
184
- pLooseOptions.outputTo,
185
- pLooseOptions.outputType
186
- );
187
-
188
- return {
189
- inputFrom: lNormalizedInputFrom,
190
- inputType: lNormalizedInputType,
191
- outputType: lNormalizedOutputType,
192
- outputTo: determineOutputTo(
193
- pLooseOptions.outputTo,
194
- lNormalizedInputFrom,
195
- lNormalizedOutputType
196
- ),
197
- engine: determineParameter(pLooseOptions, "engine"),
198
- direction: determineParameter(pLooseOptions, "direction"),
199
- dotGraphAttrs: determineDotAttributes(pLooseOptions, "dotGraphAttrs"),
200
- dotNodeAttrs: determineDotAttributes(pLooseOptions, "dotNodeAttrs"),
201
- dotEdgeAttrs: determineDotAttributes(pLooseOptions, "dotEdgeAttrs"),
202
- desugar: pLooseOptions?.desugar ?? false,
203
- };
204
- }
@@ -1,140 +0,0 @@
1
- // @ts-check
2
- import fs from "node:fs";
3
- import smcat from "../index-node.mjs";
4
- import { parse as parseAttributes } from "./attributes-parser.mjs";
5
-
6
- const allowedValues = smcat.getAllowedValues();
7
-
8
- /**
9
- * @param {{name: string}} pValue
10
- * @returns {string}
11
- */
12
- function getName(pValue) {
13
- return pValue.name;
14
- }
15
-
16
- const VALID_OUTPUT_TYPES = allowedValues.outputType.values.map(getName);
17
- const VALID_INPUT_TYPES = allowedValues.inputType.values.map(getName);
18
- const VALID_ENGINES = allowedValues.engine.values.map(getName);
19
- const VALID_DIRECTIONS = allowedValues.direction.values.map(getName);
20
-
21
- /**
22
- * @param {string} pFilename
23
- * @returns {boolean}
24
- */
25
- function isStdout(pFilename) {
26
- return "-" === pFilename;
27
- }
28
-
29
- /**
30
- * @param {string} pFilename
31
- * @returns {boolean}
32
- */
33
- function fileExists(pFilename) {
34
- try {
35
- if (!isStdout(pFilename)) {
36
- fs.accessSync(pFilename, fs.constants.R_OK);
37
- }
38
- return true;
39
- } catch (pError) {
40
- return false;
41
- }
42
- }
43
-
44
- /**
45
- * This function is shaped so it can serve as a validation function in a
46
- * commander option.
47
- *
48
- * @param {keyof import("../../types/state-machine-cat").IRenderOptions} pOption
49
- * @param {string[]} pValidValues
50
- * @param {string} pError
51
- * @returns {never|keyof import("../../types/state-machine-cat").IRenderOptions}
52
- */
53
- function validOption(pOption, pValidValues, pError) {
54
- if (pValidValues.includes(pOption)) {
55
- return pOption;
56
- }
57
-
58
- throw new Error(pError);
59
- }
60
-
61
- export default {
62
- validOutputType: (pType) =>
63
- validOption(
64
- pType,
65
- VALID_OUTPUT_TYPES,
66
- `\n error: '${pType}' is not a valid output type. smcat can emit:` +
67
- `\n ${VALID_OUTPUT_TYPES.join(", ")}\n\n`
68
- ),
69
-
70
- validInputType: (pType) =>
71
- validOption(
72
- pType,
73
- VALID_INPUT_TYPES,
74
- `\n error: '${pType}' is not a valid input type.` +
75
- `\n smcat can read ${VALID_INPUT_TYPES.join(", ")}\n\n`
76
- ),
77
-
78
- validEngine: (pEngine) =>
79
- validOption(
80
- pEngine,
81
- VALID_ENGINES,
82
- `\n error: '${pEngine}' is not a valid input type.` +
83
- `\n you can choose from ${VALID_ENGINES.join(", ")}\n\n`
84
- ),
85
-
86
- validDirection: (pDirection) =>
87
- validOption(
88
- pDirection,
89
- VALID_DIRECTIONS,
90
- `\n error: '${pDirection}' is not a valid direction.` +
91
- `\n you can choose from ${VALID_DIRECTIONS.join(", ")}\n\n`
92
- ),
93
-
94
- validDotAttrs: (pDotAttributes) => {
95
- try {
96
- parseAttributes(pDotAttributes);
97
- return pDotAttributes;
98
- } catch (pError) {
99
- throw new Error(`Invalid dot attributes: ${pError.message}`);
100
- }
101
- },
102
-
103
- /**
104
- * @param {import("./cli").ICLIRenderOptions} pOptions
105
- * @returns {never|import("./cli").ICLIRenderOptions}
106
- */
107
- validateArguments(pOptions) {
108
- if (!pOptions.inputFrom) {
109
- throw new Error(`\n error: Please specify an input file.\n\n`);
110
- }
111
-
112
- if (!pOptions.outputTo) {
113
- throw new Error(`\n error: Please specify an output file.\n\n`);
114
- }
115
-
116
- if (!fileExists(pOptions.inputFrom)) {
117
- throw new Error(
118
- `\n error: Failed to open input file '${pOptions.inputFrom}'\n\n`
119
- );
120
- }
121
-
122
- return pOptions;
123
- },
124
-
125
- validOutputTypeRE: VALID_OUTPUT_TYPES.join("|"),
126
-
127
- defaultOutputType: allowedValues.outputType.default,
128
-
129
- validInputTypeRE: VALID_INPUT_TYPES.join("|"),
130
-
131
- defaultInputType: allowedValues.inputType.default,
132
-
133
- validEngineRE: VALID_ENGINES.join("|"),
134
-
135
- defaultEngine: allowedValues.engine.default,
136
-
137
- validDirectionRE: VALID_DIRECTIONS.join("|"),
138
-
139
- defaultDirection: allowedValues.direction.default,
140
- };
@@ -1,55 +0,0 @@
1
- // @ts-check
2
- import options from "./options.mjs";
3
- import parse from "./parse/index.mjs";
4
- import desugar from "./transform/desugar.mjs";
5
- import getRenderFunction from "./render/index-node.mjs";
6
- import { version } from "./version.mjs";
7
-
8
- export default {
9
- /**
10
- * Translates the input script to an output-script.
11
- *
12
- * @param {string|import("../types/state-machine-cat").IStateMachine} pScript
13
- * The script to translate
14
- * @param {import("../types/state-machine-cat").IRenderOptions} pOptions
15
- * options influencing parsing & rendering.
16
- * @throws {Error} if an error occurred and no callback
17
- * function was passed: the error
18
- *
19
- * Options: see https://github.com/sverweij/state-machine-cat/docs/api.md
20
- *
21
- */
22
- render(pScript, pOptions) {
23
- const lStateMachine = parse.getAST(pScript, pOptions);
24
- const lDesugar = options.getOptionValue(pOptions, "desugar");
25
-
26
- // @ts-expect-error should be cast to OutputTypeType - or the getOptionValue
27
- // function should be refactored to be more explicit in type it returns
28
- // when we ask for outputType
29
- return getRenderFunction(options.getOptionValue(pOptions, "outputType"))(
30
- lDesugar ? desugar(lStateMachine) : lStateMachine,
31
- pOptions
32
- );
33
- },
34
-
35
- /**
36
- * The current (semver compliant) version number string of
37
- * state machine cat
38
- *
39
- * @type {string}
40
- */
41
- version,
42
-
43
- /**
44
- * Returns an object with each of the options you can pass to
45
- * the render function
46
- * - the default value
47
- * - the possible values in an array of objects, each of which
48
- * has the properties:
49
- * - name: the value
50
- * @returns {import("../types/state-machine-cat").IAllowedValues}
51
- */
52
- getAllowedValues() {
53
- return options.getAllowedValues();
54
- },
55
- };
package/src/index.mjs DELETED
@@ -1,58 +0,0 @@
1
- // @ts-check
2
- /* eslint-disable budapestian/global-constant-pattern */
3
- import options from "./options.mjs";
4
- import parse from "./parse/index.mjs";
5
- import desugar from "./transform/desugar.mjs";
6
- import getRenderFunction from "./render/index.mjs";
7
- import { version as _version } from "./version.mjs";
8
-
9
- /**
10
- * Translates the input script to an output-script.
11
- *
12
- * @param {string|import("../types/state-machine-cat").IStateMachine} pScript
13
- * The script to translate
14
- * @param {import("../types/state-machine-cat").IRenderOptions} pOptions
15
- * options influencing parsing & rendering.
16
- * @return {string}
17
- * @throws {Error} if an error occurred and no callback
18
- * function was passed: the error
19
- *
20
- * Options: see https://github.com/sverweij/state-machine-cat/docs/api.md
21
- *
22
- */
23
- export function render(pScript, pOptions) {
24
- const lStateMachine = parse.getAST(pScript, pOptions);
25
- const lDesugar = options.getOptionValue(pOptions, "desugar");
26
-
27
- return getRenderFunction(options.getOptionValue(pOptions, "outputType"))(
28
- lDesugar ? desugar(lStateMachine) : lStateMachine,
29
- pOptions
30
- );
31
- }
32
-
33
- /**
34
- * The current (semver compliant) version number string of
35
- * state machine cat
36
- *
37
- * @type {string}
38
- */
39
- export const version = _version;
40
-
41
- /**
42
- * Returns an object with each of the options you can pass to
43
- * the render function
44
- * - the default value
45
- * - the possible values in an array of objects, each of which
46
- * has the properties:
47
- * - name: the value
48
- * @returns {import("../types/state-machine-cat").IAllowedValues}
49
- */
50
- export function getAllowedValues() {
51
- return options.getAllowedValues();
52
- }
53
-
54
- export default {
55
- render,
56
- version,
57
- getAllowedValues,
58
- };
package/src/options.mjs DELETED
@@ -1,78 +0,0 @@
1
- // @ts-check
2
- /** @type {import("../types/state-machine-cat").IAllowedValues} */
3
- const ALLOWED_VALUES = Object.freeze({
4
- inputType: {
5
- default: "smcat",
6
- values: [{ name: "smcat" }, { name: "json" }, { name: "scxml" }],
7
- },
8
- outputType: {
9
- default: "svg",
10
- values: [
11
- { name: "ast" },
12
- { name: "dot" },
13
- { name: "eps" },
14
- { name: "json" },
15
- { name: "oldeps" },
16
- { name: "oldps" },
17
- { name: "oldps2" },
18
- { name: "oldsvg" },
19
- { name: "pdf" },
20
- { name: "png" },
21
- { name: "ps" },
22
- { name: "ps2" },
23
- { name: "scjson" },
24
- { name: "scxml" },
25
- { name: "smcat" },
26
- { name: "svg" },
27
- ],
28
- },
29
- engine: {
30
- default: "dot",
31
- values: [
32
- { name: "dot" },
33
- { name: "circo" },
34
- { name: "fdp" },
35
- { name: "neato" },
36
- { name: "osage" },
37
- { name: "twopi" },
38
- ],
39
- },
40
- direction: {
41
- default: "top-down",
42
- values: [
43
- { name: "top-down" },
44
- { name: "bottom-top" },
45
- { name: "left-right" },
46
- { name: "right-left" },
47
- ],
48
- },
49
- desugar: {
50
- default: false,
51
- values: [{ name: true }, { name: false }],
52
- },
53
- });
54
-
55
- /**
56
- * Returns the value for the option in the pOption object, and the default
57
- * for that option in all other cases
58
- *
59
- * @param {import("../types/state-machine-cat").IRenderOptions} pOptions - the options as passed in the api `render` function
60
- * @param {keyof import("../types/state-machine-cat").IRenderOptions} pOptionName - the name of the option
61
- * @return {string|boolean} value
62
- */
63
- function getOptionValue(pOptions, pOptionName) {
64
- // eslint-disable-next-line security/detect-object-injection
65
- return pOptions?.[pOptionName] ?? ALLOWED_VALUES[pOptionName].default;
66
- }
67
-
68
- /**
69
- * @returns {import("../types/state-machine-cat").IAllowedValues}
70
- */
71
- function getAllowedValues() {
72
- return ALLOWED_VALUES;
73
- }
74
-
75
- export default {
76
- getAllowedValues,
77
- getOptionValue,
78
- };
@@ -1,47 +0,0 @@
1
- // @ts-check
2
- import Ajv from "ajv";
3
- import options from "../options.mjs";
4
- import { parse as parseSmCat } from "./smcat/smcat-parser.mjs";
5
- import { parse as parseSCXML } from "./scxml/index.mjs";
6
- import $schema from "./smcat-ast.schema.mjs";
7
-
8
- const ajv = new Ajv();
9
-
10
- /**
11
- * @param {typeof $schema} pSchema
12
- * @param {any} pObject
13
- * @throws {Error}
14
- */
15
- function validateAgainstSchema(pSchema, pObject) {
16
- if (!ajv.validate(pSchema, pObject)) {
17
- throw new Error(
18
- `The provided JSON is not a valid state-machine-cat AST: ${ajv.errorsText()}.\n`
19
- );
20
- }
21
- }
22
-
23
- export default {
24
- /**
25
- * @param {string|import("../../types/state-machine-cat").IStateMachine} pScript
26
- * @param {import("../../types/state-machine-cat").IRenderOptions} pOptions
27
- * @returns {import("../../types/state-machine-cat").IStateMachine}
28
- */
29
- getAST(pScript, pOptions) {
30
- let lReturnValue = pScript;
31
-
32
- if (options.getOptionValue(pOptions, "inputType") === "smcat") {
33
- lReturnValue = parseSmCat(pScript);
34
- } else if (options.getOptionValue(pOptions, "inputType") === "scxml") {
35
- // @ts-expect-error inputType scxml => it's a string
36
- lReturnValue = parseSCXML(pScript);
37
- } else if (typeof pScript === "string") {
38
- // json
39
- lReturnValue = JSON.parse(pScript);
40
- }
41
-
42
- validateAgainstSchema($schema, lReturnValue);
43
-
44
- // @ts-expect-error by here lReturnValue is bound to be an IStateMachine
45
- return lReturnValue;
46
- },
47
- };