@servicenow/sdk-build-core 2.0.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/dist/BuildOptions.d.ts +50 -0
- package/dist/BuildOptions.js +46 -0
- package/dist/BuildOptions.js.map +1 -0
- package/dist/GUID.d.ts +2 -0
- package/dist/GUID.js +48 -0
- package/dist/GUID.js.map +1 -0
- package/dist/Keys.d.ts +29 -0
- package/dist/Keys.js +258 -0
- package/dist/Keys.js.map +1 -0
- package/dist/TypeScript.d.ts +5 -0
- package/dist/TypeScript.js +81 -0
- package/dist/TypeScript.js.map +1 -0
- package/dist/XML.d.ts +25 -0
- package/dist/XML.js +72 -0
- package/dist/XML.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/Context.d.ts +198 -0
- package/dist/plugins/Context.js +3 -0
- package/dist/plugins/Context.js.map +1 -0
- package/dist/plugins/Diagnostic.d.ts +10 -0
- package/dist/plugins/Diagnostic.js +52 -0
- package/dist/plugins/Diagnostic.js.map +1 -0
- package/dist/plugins/Plugin.d.ts +175 -0
- package/dist/plugins/Plugin.js +15 -0
- package/dist/plugins/Plugin.js.map +1 -0
- package/dist/plugins/behaviors/Arranger.d.ts +26 -0
- package/dist/plugins/behaviors/Arranger.js +3 -0
- package/dist/plugins/behaviors/Arranger.js.map +1 -0
- package/dist/plugins/behaviors/Composer.d.ts +101 -0
- package/dist/plugins/behaviors/Composer.js +15 -0
- package/dist/plugins/behaviors/Composer.js.map +1 -0
- package/dist/plugins/behaviors/Diagnostics.d.ts +8 -0
- package/dist/plugins/behaviors/Diagnostics.js +3 -0
- package/dist/plugins/behaviors/Diagnostics.js.map +1 -0
- package/dist/plugins/behaviors/Generator.d.ts +21 -0
- package/dist/plugins/behaviors/Generator.js +3 -0
- package/dist/plugins/behaviors/Generator.js.map +1 -0
- package/dist/plugins/behaviors/OwnedTables.d.ts +6 -0
- package/dist/plugins/behaviors/OwnedTables.js +3 -0
- package/dist/plugins/behaviors/OwnedTables.js.map +1 -0
- package/dist/plugins/behaviors/PostProcessor.d.ts +5 -0
- package/dist/plugins/behaviors/PostProcessor.js +3 -0
- package/dist/plugins/behaviors/PostProcessor.js.map +1 -0
- package/dist/plugins/behaviors/Serializer.d.ts +29 -0
- package/dist/plugins/behaviors/Serializer.js +3 -0
- package/dist/plugins/behaviors/Serializer.js.map +1 -0
- package/dist/plugins/behaviors/Transformer.d.ts +23 -0
- package/dist/plugins/behaviors/Transformer.js +3 -0
- package/dist/plugins/behaviors/Transformer.js.map +1 -0
- package/dist/plugins/behaviors/extractors/Data.d.ts +107 -0
- package/dist/plugins/behaviors/extractors/Data.js +191 -0
- package/dist/plugins/behaviors/extractors/Data.js.map +1 -0
- package/dist/plugins/behaviors/extractors/Extractors.d.ts +41 -0
- package/dist/plugins/behaviors/extractors/Extractors.js +3 -0
- package/dist/plugins/behaviors/extractors/Extractors.js.map +1 -0
- package/dist/plugins/behaviors/extractors/index.d.ts +2 -0
- package/dist/plugins/behaviors/extractors/index.js +19 -0
- package/dist/plugins/behaviors/extractors/index.js.map +1 -0
- package/dist/plugins/behaviors/index.d.ts +9 -0
- package/dist/plugins/behaviors/index.js +26 -0
- package/dist/plugins/behaviors/index.js.map +1 -0
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.js +23 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/util/CallExpression.d.ts +6 -0
- package/dist/plugins/util/CallExpression.js +93 -0
- package/dist/plugins/util/CallExpression.js.map +1 -0
- package/dist/plugins/util/CodeTransformation.d.ts +74 -0
- package/dist/plugins/util/CodeTransformation.js +421 -0
- package/dist/plugins/util/CodeTransformation.js.map +1 -0
- package/dist/plugins/util/ConfigurationFunction.d.ts +106 -0
- package/dist/plugins/util/ConfigurationFunction.js +377 -0
- package/dist/plugins/util/ConfigurationFunction.js.map +1 -0
- package/dist/plugins/util/ObjectLiteral.d.ts +9 -0
- package/dist/plugins/util/ObjectLiteral.js +60 -0
- package/dist/plugins/util/ObjectLiteral.js.map +1 -0
- package/dist/plugins/util/index.d.ts +4 -0
- package/dist/plugins/util/index.js +21 -0
- package/dist/plugins/util/index.js.map +1 -0
- package/dist/util/Debug.d.ts +8 -0
- package/dist/util/Debug.js +39 -0
- package/dist/util/Debug.js.map +1 -0
- package/dist/util/Util.d.ts +4 -0
- package/dist/util/Util.js +41 -0
- package/dist/util/Util.js.map +1 -0
- package/dist/util/XMLJsonBuilder.d.ts +18 -0
- package/dist/util/XMLJsonBuilder.js +59 -0
- package/dist/util/XMLJsonBuilder.js.map +1 -0
- package/dist/util/XMLUploadParser.d.ts +22 -0
- package/dist/util/XMLUploadParser.js +67 -0
- package/dist/util/XMLUploadParser.js.map +1 -0
- package/dist/util/index.d.ts +4 -0
- package/dist/util/index.js +21 -0
- package/dist/util/index.js.map +1 -0
- package/license +9 -0
- package/package.json +42 -0
- package/src/BuildOptions.ts +27 -0
- package/src/GUID.ts +26 -0
- package/src/Keys.ts +287 -0
- package/src/TypeScript.ts +65 -0
- package/src/XML.ts +85 -0
- package/src/index.ts +8 -0
- package/src/plugins/Context.ts +249 -0
- package/src/plugins/Diagnostic.ts +31 -0
- package/src/plugins/Plugin.ts +246 -0
- package/src/plugins/behaviors/Arranger.ts +42 -0
- package/src/plugins/behaviors/Composer.ts +124 -0
- package/src/plugins/behaviors/Diagnostics.ts +13 -0
- package/src/plugins/behaviors/Generator.ts +31 -0
- package/src/plugins/behaviors/OwnedTables.ts +5 -0
- package/src/plugins/behaviors/PostProcessor.ts +6 -0
- package/src/plugins/behaviors/Serializer.ts +39 -0
- package/src/plugins/behaviors/Transformer.ts +32 -0
- package/src/plugins/behaviors/extractors/Data.ts +247 -0
- package/src/plugins/behaviors/extractors/Extractors.ts +57 -0
- package/src/plugins/behaviors/extractors/index.ts +2 -0
- package/src/plugins/behaviors/index.ts +9 -0
- package/src/plugins/index.ts +5 -0
- package/src/plugins/util/CallExpression.ts +83 -0
- package/src/plugins/util/CodeTransformation.ts +500 -0
- package/src/plugins/util/ConfigurationFunction.ts +477 -0
- package/src/plugins/util/ObjectLiteral.ts +37 -0
- package/src/plugins/util/index.ts +4 -0
- package/src/util/Debug.ts +46 -0
- package/src/util/Util.ts +21 -0
- package/src/util/XMLJsonBuilder.ts +64 -0
- package/src/util/XMLUploadParser.ts +90 -0
- package/src/util/index.ts +4 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { XMLParser } from 'fast-xml-parser'
|
|
2
|
+
|
|
3
|
+
enum Action {
|
|
4
|
+
INSERT_OR_UPDATE = 'INSERT_OR_UPDATE',
|
|
5
|
+
DELETE = 'DELETE',
|
|
6
|
+
DELETE_MULTIPLE = 'delete_multiple',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type Record = {
|
|
10
|
+
table: string
|
|
11
|
+
action: Action
|
|
12
|
+
id: string
|
|
13
|
+
data: { [element: string]: string | undefined | boolean | number }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class XMLUnloadParser {
|
|
17
|
+
readonly records: Record[] = []
|
|
18
|
+
|
|
19
|
+
static parse = (xml: string) => {
|
|
20
|
+
const parser = new XMLUnloadParser()
|
|
21
|
+
parser.parse(xml)
|
|
22
|
+
|
|
23
|
+
return parser
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private parse = (xml: string) => {
|
|
27
|
+
const parsed = new XMLParser({
|
|
28
|
+
ignoreAttributes: false,
|
|
29
|
+
alwaysCreateTextNode: false,
|
|
30
|
+
ignoreDeclaration: true,
|
|
31
|
+
}).parse(xml, true)
|
|
32
|
+
|
|
33
|
+
this.processResult(parsed)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
private processResult(result: RecordUpdateXmlJson | RecordUpdateXmlJson[]) {
|
|
38
|
+
const recordUpdate = result['record_update']
|
|
39
|
+
|
|
40
|
+
for (const tag in recordUpdate) {
|
|
41
|
+
if (!tag.startsWith('@') && typeof recordUpdate[tag] === 'object') {
|
|
42
|
+
const records = recordUpdate[tag]
|
|
43
|
+
if (Array.isArray(records)) {
|
|
44
|
+
for (const record of records) {
|
|
45
|
+
this.parseRecord(tag, record)
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
this.parseRecord(tag, recordUpdate[tag])
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private parseRecord(table: string, record: RecordXmlJson[string]) {
|
|
55
|
+
const { '@_action': action, sys_id, ...data } = record
|
|
56
|
+
|
|
57
|
+
const parsedAction = this.parseAction(action)
|
|
58
|
+
|
|
59
|
+
this.records.push({
|
|
60
|
+
table,
|
|
61
|
+
action: parsedAction,
|
|
62
|
+
id: (sys_id as string) || 'unknown',
|
|
63
|
+
data,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private parseAction(actionStr: string): Action {
|
|
68
|
+
switch (actionStr) {
|
|
69
|
+
case 'INSERT_OR_UPDATE':
|
|
70
|
+
return Action.INSERT_OR_UPDATE
|
|
71
|
+
case 'DELETE':
|
|
72
|
+
return Action.DELETE
|
|
73
|
+
case 'delete_multiple':
|
|
74
|
+
return Action.DELETE_MULTIPLE
|
|
75
|
+
default:
|
|
76
|
+
throw new Error(`Invalid action string: ${actionStr}`)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
type RecordUpdateXmlJson = {
|
|
82
|
+
record_update: RecordXmlJson | RecordXmlJson[]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type RecordXmlJson = {
|
|
86
|
+
[table: string]: {
|
|
87
|
+
'@_action': string
|
|
88
|
+
[field: string]: string | undefined | boolean | number
|
|
89
|
+
}
|
|
90
|
+
}
|