pm-manifest 1.5.21 → 1.5.30
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/package.json +1 -1
- package/src/io/2-mani-output/1-convert-to-xml.ts +34 -0
- package/src/io/2-mani-output/2-to-mani-file-format.ts +69 -0
- package/src/io/2-mani-output/{0-all.ts → 7-all.ts} +13 -13
- package/src/io/2-mani-output/8-filter-empty-values.ts +13 -0
- package/src/io/2-mani-output/index.ts +5 -2
- /package/src/io/2-mani-output/{1-make-new-manifest-for-xml.ts → 8-make-new-manifest-for-xml.ts} +0 -0
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Mani, type FileMani, type CatalogFile } from "../../all-types";
|
|
2
|
+
import { convertJsToXml } from "./7-all";
|
|
3
|
+
import { prepareNewFc4Xml, prepareNewMani4Xml } from "./8-make-new-manifest-for-xml";
|
|
4
|
+
|
|
5
|
+
export function convertToXmlString(params: { mani?: FileMani.Manifest, fc?: CatalogFile.Root; }): ConvertToXmlStringResult {
|
|
6
|
+
try {
|
|
7
|
+
let objForXml: object | undefined;
|
|
8
|
+
|
|
9
|
+
if (params.mani) {
|
|
10
|
+
objForXml = prepareNewMani4Xml(params.mani as Mani.Manifest);
|
|
11
|
+
} else if (params.fc) {
|
|
12
|
+
objForXml = prepareNewFc4Xml(params.fc);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!objForXml) {
|
|
16
|
+
return { error: 'failed to convert' };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const xml = convertJsToXml(objForXml) || '';
|
|
20
|
+
return { xml };
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return { error: 'Failed to convert' + error };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ConvertToXmlStringResult =
|
|
27
|
+
| {
|
|
28
|
+
error: string;
|
|
29
|
+
xml?: undefined;
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
xml: string;
|
|
33
|
+
error?: undefined;
|
|
34
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type Mani, type FileMani, FormIdx } from "../../all-types";
|
|
2
|
+
import { filterOneLevelEmptyValues } from "./8-filter-empty-values";
|
|
3
|
+
|
|
4
|
+
//TODO: order is wrong
|
|
5
|
+
|
|
6
|
+
export function toManiFileFormat(newMani: Partial<Mani.Manifest>): FileMani.Manifest {
|
|
7
|
+
const rv: FileMani.Manifest = {
|
|
8
|
+
descriptor: newMani.descriptor!,
|
|
9
|
+
options: newMani.options,
|
|
10
|
+
forms: newMani.forms?.map(convertForm).filter(Boolean),
|
|
11
|
+
};
|
|
12
|
+
return rv;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function convertForm(form: Mani.Form, idx: number): FileMani.Form {
|
|
16
|
+
let rv: FileMani.Form = {
|
|
17
|
+
fcontext: idx === FormIdx.cpass ? { type: 'pchange', name: '1', } : undefined,
|
|
18
|
+
detection: convertFormDetection(form.detection),
|
|
19
|
+
options: convertFormOptions(form.options),
|
|
20
|
+
fields: form.fields.map(convertField),
|
|
21
|
+
};
|
|
22
|
+
rv = filterOneLevelEmptyValues(rv)!;
|
|
23
|
+
return rv;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function convertFormDetection(detection: Mani.Detection): FileMani.Detection {
|
|
27
|
+
let rv: FileMani.Detection = {
|
|
28
|
+
...detection as FileMani.Detection,
|
|
29
|
+
...(detection.web_checkurl && { web_checkurl: '1' }),
|
|
30
|
+
};
|
|
31
|
+
rv = filterOneLevelEmptyValues(rv)!;
|
|
32
|
+
return rv;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function convertFormOptions(options: Mani.Options): FileMani.Options {
|
|
36
|
+
const rv: FileMani.Options = {
|
|
37
|
+
...options as FileMani.Options,
|
|
38
|
+
...(options.submittype && { submittype: options.submittype as 'dosubmit' | `nosubmit` }),
|
|
39
|
+
...(options.autoprompt && { autoprompt: '1' }),
|
|
40
|
+
};
|
|
41
|
+
if (rv.balooncount === '3') {
|
|
42
|
+
delete rv.balooncount;
|
|
43
|
+
}
|
|
44
|
+
return filterOneLevelEmptyValues(rv)!;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function convertField(field: Mani.Field): FileMani.Field {
|
|
48
|
+
let rv: FileMani.Field = {
|
|
49
|
+
...field as FileMani.Field,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
convertNumbersToString(rv);
|
|
53
|
+
|
|
54
|
+
rv = filterOneLevelEmptyValues(rv)!;
|
|
55
|
+
return rv;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function convertNumbersToString(field: FileMani.Field) {
|
|
59
|
+
if (!!field.rfieldindex && (field.rfieldindex as any) === -1) { // mani.rfieldindex defined as string in manifest but in editor it is number
|
|
60
|
+
field.rfieldindex = '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!!field.rfieldform && (field.rfieldform as any) === -1) { // mani.rfieldform defined as string in manifest but in editor it is number
|
|
64
|
+
field.rfieldform = '';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
field.rfieldindex = field.rfieldindex && `${field.rfieldindex}`;
|
|
68
|
+
field.rfieldform = field.rfieldform && `${field.rfieldform}`;
|
|
69
|
+
}
|
|
@@ -3,6 +3,19 @@ import { showError } from "../8-mani-show-error";
|
|
|
3
3
|
import { TransformEncoding } from "../../transforms";
|
|
4
4
|
import { J2xParser } from "../../utils/2-json2xml";
|
|
5
5
|
|
|
6
|
+
export function convertJsToXml(obj: object | undefined): string | undefined {
|
|
7
|
+
//const rv = mani && makeNewManifest4Xml(mani);
|
|
8
|
+
if (obj) {
|
|
9
|
+
try {
|
|
10
|
+
const j2xParser = new J2xParser(parseOptionsWrite);
|
|
11
|
+
const xml = j2xParser.parse(obj);
|
|
12
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n${xml}`;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
showError(error);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
6
19
|
export const parseOptionsWrite = {
|
|
7
20
|
...parseOptionsRead,
|
|
8
21
|
format: true,
|
|
@@ -19,17 +32,4 @@ export const parseOptionsWrite = {
|
|
|
19
32
|
}
|
|
20
33
|
};
|
|
21
34
|
|
|
22
|
-
export function convertJsToXml(obj: object | undefined): string | undefined {
|
|
23
|
-
//const rv = mani && makeNewManifest4Xml(mani);
|
|
24
|
-
if (obj) {
|
|
25
|
-
try {
|
|
26
|
-
const j2xParser = new J2xParser(parseOptionsWrite);
|
|
27
|
-
const xml = j2xParser.parse(obj);
|
|
28
|
-
return `<?xml version="1.0" encoding="UTF-8"?>\n${xml}`;
|
|
29
|
-
} catch (error) {
|
|
30
|
-
showError(error);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
35
|
//TODO: parseOptionsWrite.attrValueProcessor(): convert value life and skip '=== undefined'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter empty values from the object at the top level.
|
|
3
|
+
* If the object is empty, return undefined.
|
|
4
|
+
*
|
|
5
|
+
* TODO: This will break order of fields
|
|
6
|
+
*/
|
|
7
|
+
export function filterOneLevelEmptyValues<T extends Record<string, any>>(obj: T): T | undefined {
|
|
8
|
+
const entries = Object
|
|
9
|
+
.entries(obj)
|
|
10
|
+
.filter(([key, value]) => !!value);
|
|
11
|
+
|
|
12
|
+
return entries.length ? Object.fromEntries(entries) as T : undefined;
|
|
13
|
+
}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./1-convert-to-xml";
|
|
2
|
+
export * from "./2-to-mani-file-format";
|
|
3
|
+
export * from "./7-all";
|
|
4
|
+
export * from "./8-filter-empty-values";
|
|
5
|
+
export * from "./8-make-new-manifest-for-xml";
|
/package/src/io/2-mani-output/{1-make-new-manifest-for-xml.ts → 8-make-new-manifest-for-xml.ts}
RENAMED
|
File without changes
|