scjson 0.2.1 → 0.3.1
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 +189 -3
- package/bin/scjson.js +1 -1
- package/dist/browser.cjs +12 -0
- package/dist/browser.d.cts +2 -0
- package/dist/browser.d.mts +6 -0
- package/dist/browser.mjs +12 -0
- package/dist/converters.d.ts +230 -0
- package/dist/converters.js +1372 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +236 -0
- package/{types → dist}/scjsonProps.d.ts +92 -226
- package/dist/scjsonProps.js +309 -0
- package/package.json +31 -56
- package/scjson.schema.json +160 -13
- package/browser.cjs +0 -243
- package/browser.mjs +0 -92
- package/index.js +0 -243
- package/scjsonProps.ts +0 -721
- package/tests/cli.test.js +0 -172
- package/types/scjson-browser.d.ts +0 -25
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This directory contains the JavaScript implementation of **scjson**, a format for representing SCXML state machines in JSON. The package provides a command line interface to convert between `.scxml` and `.scjson` files and to validate documents against the project's schema.
|
|
4
4
|
|
|
5
|
+
For details on how SCXML elements are inferred during conversion see [INFERENCE.md](https://github.com/SoftOboros/scjson/blob/main/INFERENCE.md).
|
|
6
|
+
|
|
5
7
|
The package includes typescript types for the functions and default functions to return each.
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
@@ -74,6 +76,14 @@ const { xmlToJson, jsonToXml } = require('scjson');
|
|
|
74
76
|
import { xmlToJson, jsonToXml }from "scjson/browser"
|
|
75
77
|
```
|
|
76
78
|
|
|
79
|
+
## Shared Converters
|
|
80
|
+
Both the Node and browser builds use the same conversion logic exposed in
|
|
81
|
+
`scjson/converters`. You can import these helpers directly if you need access to
|
|
82
|
+
the utility functions used by the CLI and browser modules.
|
|
83
|
+
```js
|
|
84
|
+
import { xmlToJson, jsonToXml } from 'scjson/converters';
|
|
85
|
+
```
|
|
86
|
+
|
|
77
87
|
## Axios Endpoint Example
|
|
78
88
|
```typescript
|
|
79
89
|
import axios from "axios"
|
|
@@ -122,6 +132,177 @@ export const sendNewScxml = () => {
|
|
|
122
132
|
|
|
123
133
|
```
|
|
124
134
|
|
|
135
|
+
## Known Issues
|
|
136
|
+
None at this time.
|
|
137
|
+
|
|
138
|
+
Operational conformance testing is performed via [uber_test.py](https://github.com/SoftOboros/scjson/blob/engine/py/uber_test.py)
|
|
139
|
+
```bash
|
|
140
|
+
/py# python uber_test.py -l javascript 2>&1 | tee test.log
|
|
141
|
+
```
|
|
142
|
+
Note: [uber_test.py](https://github.com/SoftOboros/scjson/blob/main/py/uber_test.py) applies all scxml files in [Zhornyak's ScxmlEditor-Tutorial](https://alexzhornyak.github.io/ScxmlEditor-Tutorial/) which provides a robest set of scxml test vectors useful for standard compliance verification. This is the only file in the test suite which fails to verify round-trip.
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### `scjson/props`
|
|
146
|
+
|
|
147
|
+
### Enums
|
|
148
|
+
|
|
149
|
+
Each enumeration represents a restricted string set used by SCXML. The values
|
|
150
|
+
shown below mirror those defined in the SCJSON schema.
|
|
151
|
+
|
|
152
|
+
enums use this pattern to all static and dynamic portions to be treated separately,
|
|
153
|
+
but mapped to the same name.
|
|
154
|
+
```typescript
|
|
155
|
+
export const BooleanDatatypeProps = {
|
|
156
|
+
False: "false",
|
|
157
|
+
True: "true",
|
|
158
|
+
} as const;
|
|
159
|
+
|
|
160
|
+
export type BooleanDatatypeProps = typeof BooleanDatatypeProps[keyof typeof BooleanDatatypeProps];
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
- `AssignTypeDatatypeProps` – how the `<assign>` element manipulates the datamodel.
|
|
164
|
+
Values: `replacechildren`, `firstchild`, `lastchild`, `previoussibling`,
|
|
165
|
+
`nextsibling`, `replace`, `delete`, `addattribute`.
|
|
166
|
+
- `BindingDatatypeProps` – determines if datamodel variables are bound `early` or
|
|
167
|
+
`late` during execution.
|
|
168
|
+
- `BooleanDatatypeProps` – boolean attribute values `true` or `false`.
|
|
169
|
+
- `ExmodeDatatypeProps` – processor execution mode, either `lax` or `strict`.
|
|
170
|
+
- `HistoryTypeDatatypeProps` – type of `<history>` state: `shallow` or `deep`.
|
|
171
|
+
- `TransitionTypeDatatypeProps` – whether a `<transition>` is `internal` or
|
|
172
|
+
`external`.
|
|
173
|
+
|
|
174
|
+
### Common Types
|
|
175
|
+
|
|
176
|
+
Several generated classes share generic helper fields:
|
|
177
|
+
|
|
178
|
+
- `other_attributes`: `Record<str, str>` capturing additional XML attributes from
|
|
179
|
+
foreign namespaces.
|
|
180
|
+
- `other_element`: `list[object]` allowing untyped child nodes from other
|
|
181
|
+
namespaces to be preserved.
|
|
182
|
+
- `content`: `list[object]` used when elements permit mixed or wildcard
|
|
183
|
+
content.
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
### Document / Object Types
|
|
187
|
+
Plain typescript types without runtime validation.
|
|
188
|
+
|
|
189
|
+
- `AssignProps` `AssignArray` – update a datamodel location with an expression or value.
|
|
190
|
+
- `CancelProps` `CancelArray` – cancel a pending `<send>` operation.
|
|
191
|
+
- `ContentProps` `ContentArray` – inline payload used by `<send>` and `<invoke>`.
|
|
192
|
+
- `DataProps` `DataArray` – represents a single datamodel variable.
|
|
193
|
+
- `DatamodelProps` `DatamodelArray` – container for one or more `<data>` elements.
|
|
194
|
+
- `DonedataProps` `DonedataArray` – payload returned when a `<final>` state is reached.
|
|
195
|
+
- `ElseProps` – fallback branch for `<if>` conditions.
|
|
196
|
+
- `ElseifProps` – conditional branch following an `<if>`.
|
|
197
|
+
- `FinalProps` `FinalArray` – marks a terminal state in the machine.
|
|
198
|
+
- `FinalizeProps` `FinalizeArray` – executed after an `<invoke>` completes.
|
|
199
|
+
- `ForeachProps` `ForeachArray` – iterate over items within executable content.
|
|
200
|
+
- `HistoryProps` `HistoryArray` – pseudostate remembering previous active children.
|
|
201
|
+
- `IfProps` `IfArray` – conditional execution block.
|
|
202
|
+
- `InitialProps` `InitialArray` – starting state within a compound state.
|
|
203
|
+
- `InvokeProps` `InvokeArray` – run an external process or machine.
|
|
204
|
+
- `LogProps` `LogArray` – diagnostic output statement.
|
|
205
|
+
- `OnentryProps` `OnentryArray` – actions performed when entering a state.
|
|
206
|
+
- `OnexitProps` `OnexitArray` – actions performed when leaving a state.
|
|
207
|
+
- `ParallelProps` `ParallelArray` – coordinates concurrent regions.
|
|
208
|
+
- `ParamProps` `ParamArray` – parameter passed to `<invoke>` or `<send>`.
|
|
209
|
+
- `RaiseProps` `RaiseArray` – raise an internal event.
|
|
210
|
+
- `ScriptProps` `ScriptArray` – inline executable script.
|
|
211
|
+
- `ScxmlProps` – root element of an SCJSON document.
|
|
212
|
+
- `SendProps` `SendArray` – dispatch an external event.
|
|
213
|
+
- `StateProps` `StateArray` – basic state node.
|
|
214
|
+
- `TransitionProps` `TransitionArray` – edge between states triggered by events.
|
|
215
|
+
|
|
216
|
+
### Object Management
|
|
217
|
+
- Kind - unique marker for each of the types.
|
|
218
|
+
```typescript
|
|
219
|
+
export type Kind = "number" | "string" | "record<string, object>" | "number[]" | "string[]"
|
|
220
|
+
| "record<string, object>[]" | "assign" | "assigntypedatatype" | "bindingdatatype" | "booleandatatype"
|
|
221
|
+
| "cancel" | "content" | "data" | "datamodel" | "donedata" | "else" | "elseif"
|
|
222
|
+
| "exmodedatatype" | "final" | "finalize" | "foreach" | "history" | "historytypedatatype" | "if"
|
|
223
|
+
| "initial" | "invoke" | "log" | "onentry" | "onexit" | "parallel" | "param" | "raise"
|
|
224
|
+
| "script" | "scxml" | "send" | "state" | "transition" | "transitiontypedatatype"
|
|
225
|
+
| "assignarray" | "cancelarray" | "contentarray" | "dataarray" | "datamodelarray"
|
|
226
|
+
| "donedataarray" | "finalarray" | "finalizearray" | "foreacharray" | "historyarray" | "ifarray"
|
|
227
|
+
| "initialarray" | "invokearray" | "logarray" | "onentryarray" | "onexitarray" | "parallelarray"
|
|
228
|
+
| "paramarray" | "raisearray" | "scriptarray" | "sendarray" | "statearray" | "transitionarray";
|
|
229
|
+
```
|
|
230
|
+
- PropsUnion - a union of the types used in the scxml data model
|
|
231
|
+
```typescript
|
|
232
|
+
export type PropsUnion = null | string | number | Record<string, object> | string[] | number[]
|
|
233
|
+
| Record<string, object>[] | AssignProps | AssignTypeDatatypeProps | BindingDatatypeProps
|
|
234
|
+
| BooleanDatatypeProps | CancelProps | ContentProps | DataProps | DatamodelProps | DonedataProps
|
|
235
|
+
| ElseProps | ElseifProps | ExmodeDatatypeProps | FinalProps | FinalizeProps | ForeachProps
|
|
236
|
+
| HistoryProps | HistoryTypeDatatypeProps | IfProps | InitialProps | InvokeProps | LogProps
|
|
237
|
+
| OnentryProps | OnexitProps | ParallelProps | ParamProps | RaiseProps | ScriptProps
|
|
238
|
+
| ScxmlProps | SendProps | StateProps | TransitionProps | TransitionTypeDatatypeProps
|
|
239
|
+
| AssignArray | CancelArray | ContentArray | DataArray | DatamodelArray | DonedataArray
|
|
240
|
+
| FinalArray | FinalizeArray | ForeachArray | HistoryArray | IfArray | InitialArray
|
|
241
|
+
| InvokeArray | LogArray | OnentryArray | OnexitArray | ParallelArray | ParamArray
|
|
242
|
+
| RaiseArray | ScriptArray | SendArray | StateArray | TransitionArray;
|
|
243
|
+
```
|
|
244
|
+
- KindMap - maps string name to type for the objects used in the scxml data model
|
|
245
|
+
```typescript
|
|
246
|
+
export type KindMap = {
|
|
247
|
+
assign: AssignProps
|
|
248
|
+
assignarray: AssignArray
|
|
249
|
+
assigntypedatatype: AssignTypeDatatypeProps
|
|
250
|
+
bindingdatatype: BindingDatatypeProps
|
|
251
|
+
booleandatatype: BooleanDatatypeProps
|
|
252
|
+
cancel: CancelProps
|
|
253
|
+
cancelarray: CancelArray
|
|
254
|
+
content: ContentProps
|
|
255
|
+
contentarray: ContentArray
|
|
256
|
+
data: DataProps
|
|
257
|
+
dataarray: DataArray
|
|
258
|
+
datamodel: DatamodelProps
|
|
259
|
+
datamodelarray: DatamodelArray
|
|
260
|
+
donedata: DonedataProps
|
|
261
|
+
donedataarray: DonedataArray
|
|
262
|
+
else: ElseProps
|
|
263
|
+
elseif: ElseifProps
|
|
264
|
+
exmodedatatype: ExmodeDatatypeProps
|
|
265
|
+
final: FinalProps
|
|
266
|
+
finalarray: FinalArray
|
|
267
|
+
finalize: FinalizeProps
|
|
268
|
+
finalizearray: FinalizeArray
|
|
269
|
+
foreach: ForeachProps
|
|
270
|
+
foreacharray: ForeachArray
|
|
271
|
+
history: HistoryProps
|
|
272
|
+
historyarray: HistoryArray
|
|
273
|
+
historytypedatatype: HistoryTypeDatatypeProps
|
|
274
|
+
if: IfProps
|
|
275
|
+
ifarray: IfArray
|
|
276
|
+
initial: InitialProps
|
|
277
|
+
initialarray: InitialArray
|
|
278
|
+
invoke: InvokeProps
|
|
279
|
+
invokearray: InvokeArray
|
|
280
|
+
log: LogProps
|
|
281
|
+
logarray: LogArray
|
|
282
|
+
onentry: OnentryProps
|
|
283
|
+
onentryarray: OnentryArray
|
|
284
|
+
onexit: OnexitProps
|
|
285
|
+
onexitarray: OnexitArray
|
|
286
|
+
parallel: ParallelProps
|
|
287
|
+
parallelarray: ParallelArray
|
|
288
|
+
param: ParamProps
|
|
289
|
+
paramarray: ParamArray
|
|
290
|
+
raise: RaiseProps
|
|
291
|
+
raisearray: RaiseArray
|
|
292
|
+
script: ScriptProps
|
|
293
|
+
scriptarray: ScriptArray
|
|
294
|
+
scxml: ScxmlProps
|
|
295
|
+
send: SendProps
|
|
296
|
+
sendarray: SendArray
|
|
297
|
+
state: StateProps
|
|
298
|
+
statearray: StateArray
|
|
299
|
+
transition: TransitionProps
|
|
300
|
+
transitionarray: TransitionArray
|
|
301
|
+
transitiontypedatatype: TransitionTypeDatatypeProps
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
|
|
125
306
|
### Other Resources
|
|
126
307
|
github: [https://github.com/SoftOboros/scjson]
|
|
127
308
|
```bash
|
|
@@ -132,9 +313,14 @@ git clone git@github.com:SoftOboros/scjson.git
|
|
|
132
313
|
gh repo clone SoftOboros/scjson
|
|
133
314
|
```
|
|
134
315
|
|
|
135
|
-
pypi: [https://
|
|
316
|
+
pypi: [https://pypi.org/project/scjson/]
|
|
136
317
|
```bash
|
|
137
|
-
|
|
318
|
+
pip install scjson
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
cargo: [https://crates.io/crates/scjson]
|
|
322
|
+
```bash
|
|
323
|
+
cargo install scjson
|
|
138
324
|
```
|
|
139
325
|
|
|
140
326
|
dockerhub: [https://hub.docker.com/r/iraa/scjson]
|
|
@@ -144,4 +330,4 @@ docker pull iraa/scjson:latest
|
|
|
144
330
|
```
|
|
145
331
|
|
|
146
332
|
|
|
147
|
-
All source code in this directory is released under the BSD\u00A01-Clause license. See
|
|
333
|
+
All source code in this directory is released under the BSD\u00A01-Clause license. See [LICENSE](./LICENSE) and [LEGAL.md](./LEGAL.md) for details.
|
package/bin/scjson.js
CHANGED
package/dist/browser.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent Name: js-browser-cjs
|
|
4
|
+
*
|
|
5
|
+
* Part of the scjson project.
|
|
6
|
+
* Developed by Softoboros Technology Inc.
|
|
7
|
+
* Licensed under the BSD 1-Clause License.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @file CommonJS wrapper exporting the core converters.
|
|
11
|
+
*/
|
|
12
|
+
module.exports = require('./converters.js');
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const xmlToJson: typeof core.xmlToJson;
|
|
2
|
+
export const jsonToXml: typeof core.jsonToXml;
|
|
3
|
+
export const removeEmpty: typeof core.removeEmpty;
|
|
4
|
+
export const normaliseKeys: typeof core.normaliseKeys;
|
|
5
|
+
export const ensureArrays: typeof core.ensureArrays;
|
|
6
|
+
import core from './converters.js';
|
package/dist/browser.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Name: js-browser
|
|
3
|
+
*
|
|
4
|
+
* Part of the scjson project.
|
|
5
|
+
* Developed by Softoboros Technology Inc.
|
|
6
|
+
* Licensed under the BSD 1-Clause License.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @file Browser friendly utilities re-exporting the core converters.
|
|
10
|
+
*/
|
|
11
|
+
import core from './converters.js';
|
|
12
|
+
export const { xmlToJson, jsonToXml, removeEmpty, normaliseKeys, ensureArrays } = core;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
export function xmlToJson(xmlStr: any, omitEmpty?: boolean): {
|
|
2
|
+
result: string;
|
|
3
|
+
valid: any;
|
|
4
|
+
errors: any;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Convert a scjson string to SCXML.
|
|
8
|
+
*
|
|
9
|
+
* Removes empty objects so that the generated XML does not include spurious
|
|
10
|
+
* `<content/>` elements. Nested SCXML documents are also normalised after
|
|
11
|
+
* restoring attribute names to ensure no stray wrapper nodes remain. The
|
|
12
|
+
* function validates the input against the SCJSON schema before conversion.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} jsonStr - JSON input.
|
|
15
|
+
* @returns {{result: string, valid: boolean, errors: object[]|null}} Conversion outcome.
|
|
16
|
+
*/
|
|
17
|
+
export function jsonToXml(jsonStr: string): {
|
|
18
|
+
result: string;
|
|
19
|
+
valid: boolean;
|
|
20
|
+
errors: object[] | null;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Remove nulls and empty containers from values recursively.
|
|
24
|
+
*
|
|
25
|
+
* Certain keys like ``final`` must always be preserved even when they
|
|
26
|
+
* would otherwise be considered empty. The caller provides the key so we
|
|
27
|
+
* can decide whether to keep an empty object.
|
|
28
|
+
*
|
|
29
|
+
* @param {*} value - Candidate value.
|
|
30
|
+
* @param {string} [key] - Key name associated with ``value`` in the parent.
|
|
31
|
+
* @returns {*} Sanitised value.
|
|
32
|
+
*/
|
|
33
|
+
export function removeEmpty(value: any, key?: string): any;
|
|
34
|
+
/**
|
|
35
|
+
* Recursively rename XML parser keys to match the scjson schema.
|
|
36
|
+
*
|
|
37
|
+
* - Attribute names prefixed with ``@_`` are stripped of the prefix.
|
|
38
|
+
* - Text content keys ``#text`` are converted to a ``content`` array.
|
|
39
|
+
*
|
|
40
|
+
* @param {object|Array} value - Parsed value to normalise.
|
|
41
|
+
* @returns {object|Array} Normalised value.
|
|
42
|
+
*/
|
|
43
|
+
export function normaliseKeys(value: object | any[]): object | any[];
|
|
44
|
+
/**
|
|
45
|
+
* Recursively normalise values that should be arrays.
|
|
46
|
+
*
|
|
47
|
+
* @param {object} obj - Parsed object to adjust in place.
|
|
48
|
+
*/
|
|
49
|
+
export function ensureArrays(obj: object, parent: any): void;
|
|
50
|
+
/**
|
|
51
|
+
* Normalise script elements after parsing.
|
|
52
|
+
*
|
|
53
|
+
* Ensures that each ``script`` entry is an object with a ``content`` array
|
|
54
|
+
* as required by the schema.
|
|
55
|
+
*
|
|
56
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
57
|
+
*/
|
|
58
|
+
export function fixScripts(value: object | any[]): void;
|
|
59
|
+
/**
|
|
60
|
+
* Normalise nested SCXML documents within invoke content.
|
|
61
|
+
*
|
|
62
|
+
* XML parser output represents nested ``<scxml>`` elements as a key
|
|
63
|
+
* named ``scxml`` inside the ``content`` element. The reference
|
|
64
|
+
* Python implementation instead stores the nested machine under a
|
|
65
|
+
* ``content`` array. This helper replicates that behaviour.
|
|
66
|
+
*
|
|
67
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
68
|
+
*/
|
|
69
|
+
export function fixNestedScxml(value: object | any[]): void;
|
|
70
|
+
/**
|
|
71
|
+
* Apply default values for assign elements.
|
|
72
|
+
*
|
|
73
|
+
* The scjson schema expects ``assign`` elements to include a
|
|
74
|
+
* ``type_value`` attribute with a default of ``replacechildren``.
|
|
75
|
+
* This helper ensures the attribute is present when not specified in
|
|
76
|
+
* the original XML.
|
|
77
|
+
*
|
|
78
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
79
|
+
*/
|
|
80
|
+
export function fixAssignDefaults(value: object | any[]): void;
|
|
81
|
+
/**
|
|
82
|
+
* Apply default values for send elements.
|
|
83
|
+
*
|
|
84
|
+
* The SCXML specification defines ``type="scxml"`` and ``delay="0s"``
|
|
85
|
+
* as defaults. This mirrors the behaviour of the Python converter so
|
|
86
|
+
* round-trip conversions remain consistent.
|
|
87
|
+
*
|
|
88
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
89
|
+
*/
|
|
90
|
+
export function fixSendDefaults(value: object | any[]): void;
|
|
91
|
+
/**
|
|
92
|
+
* Normalise inline content elements under ``send``.
|
|
93
|
+
*
|
|
94
|
+
* ``<content>`` children inside ``<send>`` should always be objects with a
|
|
95
|
+
* ``content`` array according to the scjson schema. The fast-xml-parser library
|
|
96
|
+
* collapses simple text nodes to strings which leads to mismatches when
|
|
97
|
+
* compared with the Python implementation. This helper wraps such strings in an
|
|
98
|
+
* object structure.
|
|
99
|
+
*
|
|
100
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
101
|
+
*/
|
|
102
|
+
export function fixSendContent(value: object | any[]): void;
|
|
103
|
+
/**
|
|
104
|
+
* Normalise inline content elements under ``donedata``.
|
|
105
|
+
*
|
|
106
|
+
* ``<content>`` children inside ``<donedata>`` should always be objects with a
|
|
107
|
+
* ``content`` array so that round-trips match the reference Python
|
|
108
|
+
* implementation. Strings are wrapped in an object accordingly.
|
|
109
|
+
*
|
|
110
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
111
|
+
*/
|
|
112
|
+
export function fixDonedataContent(value: object | any[]): void;
|
|
113
|
+
export function fixOtherAttributes(value: any): void;
|
|
114
|
+
/**
|
|
115
|
+
* Decode HTML entities in string values.
|
|
116
|
+
*
|
|
117
|
+
* Fast XML parser leaves character references intact. This helper matches the
|
|
118
|
+
* Python implementation by converting entities like ``
`` to their literal
|
|
119
|
+
* characters.
|
|
120
|
+
*
|
|
121
|
+
* @param {object|Array|string} value - Parsed value to normalise.
|
|
122
|
+
* @returns {object|Array|string} Normalised value.
|
|
123
|
+
*/
|
|
124
|
+
export function decodeEntities(value: object | any[] | string): object | any[] | string;
|
|
125
|
+
/**
|
|
126
|
+
* Convert a canonical content object back into XML element format.
|
|
127
|
+
*
|
|
128
|
+
* ``jsonToXml`` relies on this helper to rebuild inline XML stored under
|
|
129
|
+
* ``<data>`` elements. Objects with ``qname``, ``attributes``, and ``children``
|
|
130
|
+
* fields are translated to the structure expected by ``fast-xml-parser``.
|
|
131
|
+
*
|
|
132
|
+
* @param {object} node - Canonical content object.
|
|
133
|
+
* @returns {object} XML builder structure keyed by element name.
|
|
134
|
+
*/
|
|
135
|
+
export function restoreDataNode(node: object): object;
|
|
136
|
+
/**
|
|
137
|
+
* Collapse nested ``content`` wrappers created during parsing.
|
|
138
|
+
*
|
|
139
|
+
* A ``content`` array may contain a single object with its own
|
|
140
|
+
* ``content`` array when the original XML element only held text.
|
|
141
|
+
* This helper flattens that structure so that round-tripping through
|
|
142
|
+
* XML does not introduce spurious elements.
|
|
143
|
+
*
|
|
144
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
145
|
+
*/
|
|
146
|
+
export function flattenContent(value: object | any[]): void;
|
|
147
|
+
/**
|
|
148
|
+
* Split whitespace-separated token attributes.
|
|
149
|
+
*
|
|
150
|
+
* Attributes such as ``initial`` and ``target`` can contain multiple
|
|
151
|
+
* identifiers separated by spaces. This function mirrors the Python
|
|
152
|
+
* implementation by splitting those values into arrays before further
|
|
153
|
+
* normalisation.
|
|
154
|
+
*
|
|
155
|
+
* @param {object|Array} value - Parsed value to adjust in place.
|
|
156
|
+
*/
|
|
157
|
+
export function splitTokenAttrs(value: object | any[], parent: any): void;
|
|
158
|
+
/**
|
|
159
|
+
* Convert ``else`` elements to the ``else_value`` schema key.
|
|
160
|
+
*
|
|
161
|
+
* Empty ``<else/>`` tags become an object literal so they survive
|
|
162
|
+
* subsequent calls to :func:`removeEmpty`.
|
|
163
|
+
*
|
|
164
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
165
|
+
*/
|
|
166
|
+
export function fixEmptyElse(value: object | any[]): void;
|
|
167
|
+
/**
|
|
168
|
+
* Normalise empty ``onentry`` and ``onexit`` elements.
|
|
169
|
+
*
|
|
170
|
+
* The XML parser represents empty tags as an empty string. The Python
|
|
171
|
+
* reference output preserves these elements as empty objects so they
|
|
172
|
+
* survive subsequent cleaning steps. This helper mirrors that behaviour.
|
|
173
|
+
*
|
|
174
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
175
|
+
*/
|
|
176
|
+
export function fixEmptyOnentry(value: object | any[]): void;
|
|
177
|
+
/**
|
|
178
|
+
* Remove transition elements directly under the <scxml> root.
|
|
179
|
+
*
|
|
180
|
+
* The reference Python implementation ignores these top level
|
|
181
|
+
* transitions entirely. To maintain parity we drop them during
|
|
182
|
+
* conversion.
|
|
183
|
+
*
|
|
184
|
+
* @param {object} obj - Parsed SCXML object.
|
|
185
|
+
*/
|
|
186
|
+
export function stripRootTransitions(obj: object): void;
|
|
187
|
+
/**
|
|
188
|
+
* Remove namespace URIs from ``qname`` fields.
|
|
189
|
+
*
|
|
190
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
191
|
+
*/
|
|
192
|
+
export function stripQnameNs(value: object | any[]): void;
|
|
193
|
+
/**
|
|
194
|
+
* Reorder SCXML object keys to match canonical output.
|
|
195
|
+
*
|
|
196
|
+
* ``datamodel`` elements and the attributes ``version`` and
|
|
197
|
+
* ``datamodel_attribute`` are appended to the end of their
|
|
198
|
+
* respective objects so that JSON generated by this converter
|
|
199
|
+
* matches the reference Python implementation.
|
|
200
|
+
*
|
|
201
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
202
|
+
*/
|
|
203
|
+
export function reorderScxml(value: object | any[]): void;
|
|
204
|
+
/**
|
|
205
|
+
* Convert an SCXML string to scjson.
|
|
206
|
+
*
|
|
207
|
+
* @param {string} xmlStr - XML input.
|
|
208
|
+
* @param {boolean} [omitEmpty=true] - Remove empty values when true.
|
|
209
|
+
* @returns {{result: string, valid: boolean, errors: object[]|null}} Conversion outcome.
|
|
210
|
+
*
|
|
211
|
+
* Removes the XML namespace attribute and injects default values
|
|
212
|
+
* expected by the schema.
|
|
213
|
+
*/
|
|
214
|
+
/**
|
|
215
|
+
* Recursively strip default attributes from nested data nodes.
|
|
216
|
+
*
|
|
217
|
+
* Any object with a ``qname`` property other than ``scxml`` may have
|
|
218
|
+
* ``version`` or ``datamodel_attribute`` inserted during validation.
|
|
219
|
+
* This helper removes those keys so that nested structures match the
|
|
220
|
+
* canonical Python output.
|
|
221
|
+
*
|
|
222
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
223
|
+
*/
|
|
224
|
+
export function stripNestedDataAttrs(value: object | any[]): void;
|
|
225
|
+
/**
|
|
226
|
+
* Recursively remove ``xmlns`` attributes from nested objects.
|
|
227
|
+
*
|
|
228
|
+
* @param {object|Array} value - Parsed object to adjust in place.
|
|
229
|
+
*/
|
|
230
|
+
export function stripXmlns(value: object | any[]): void;
|