@servicenow/sdk-build-core 3.0.3 → 4.0.0
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/app.d.ts +25 -0
- package/dist/app.js +8 -0
- package/dist/app.js.map +1 -0
- package/dist/compiler.d.ts +60 -0
- package/dist/compiler.js +320 -0
- package/dist/compiler.js.map +1 -0
- package/dist/compression.d.ts +7 -0
- package/dist/compression.js +79 -0
- package/dist/compression.js.map +1 -0
- package/dist/crypto.d.ts +1 -0
- package/dist/crypto.js +9 -0
- package/dist/crypto.js.map +1 -0
- package/dist/diagnostic.d.ts +41 -0
- package/dist/diagnostic.js +130 -0
- package/dist/diagnostic.js.map +1 -0
- package/dist/{plugins/Diagnostic.d.ts → fluent-diagnostic.d.ts} +3 -2
- package/dist/fluent-diagnostic.js +23 -0
- package/dist/fluent-diagnostic.js.map +1 -0
- package/dist/fluent-directive.d.ts +8 -0
- package/dist/fluent-directive.js +54 -0
- package/dist/fluent-directive.js.map +1 -0
- package/dist/fluent-file.d.ts +5 -0
- package/dist/fluent-file.js +15 -0
- package/dist/fluent-file.js.map +1 -0
- package/dist/formatter.d.ts +11 -0
- package/dist/formatter.js +77 -0
- package/dist/formatter.js.map +1 -0
- package/dist/fs.d.ts +174 -0
- package/dist/fs.js +313 -0
- package/dist/fs.js.map +1 -0
- package/dist/guid.d.ts +2 -0
- package/dist/{GUID.js → guid.js} +3 -6
- package/dist/guid.js.map +1 -0
- package/dist/index.d.ts +19 -5
- package/dist/index.js +19 -5
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts +5 -0
- package/dist/json.js +43 -0
- package/dist/json.js.map +1 -0
- package/dist/keys-registry.d.ts +64 -0
- package/dist/keys-registry.js +339 -0
- package/dist/keys-registry.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +17 -0
- package/dist/logger.js.map +1 -0
- package/dist/now-config.d.ts +348 -0
- package/dist/now-config.js +283 -0
- package/dist/now-config.js.map +1 -0
- package/dist/path.d.ts +3 -0
- package/dist/path.js +12 -0
- package/dist/path.js.map +1 -0
- package/dist/plugins/cache.d.ts +20 -0
- package/dist/plugins/cache.js +46 -0
- package/dist/plugins/cache.js.map +1 -0
- package/dist/plugins/context.d.ts +85 -0
- package/dist/plugins/{Context.js → context.js} +1 -1
- package/dist/plugins/context.js.map +1 -0
- package/dist/plugins/database.d.ts +27 -0
- package/dist/plugins/database.js +102 -0
- package/dist/plugins/database.js.map +1 -0
- package/dist/plugins/file.d.ts +10 -0
- package/dist/plugins/{behaviors/Arranger.js → file.js} +1 -1
- package/dist/plugins/file.js.map +1 -0
- package/dist/plugins/index.d.ts +9 -5
- package/dist/plugins/index.js +9 -6
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/plugin.d.ts +478 -0
- package/dist/plugins/plugin.js +533 -0
- package/dist/plugins/plugin.js.map +1 -0
- package/dist/plugins/product.d.ts +15 -0
- package/dist/plugins/product.js +38 -0
- package/dist/plugins/product.js.map +1 -0
- package/dist/plugins/project.d.ts +25 -0
- package/dist/plugins/{behaviors/Generator.js → project.js} +1 -1
- package/dist/plugins/project.js.map +1 -0
- package/dist/plugins/shape.d.ts +424 -0
- package/dist/plugins/shape.js +1181 -0
- package/dist/plugins/shape.js.map +1 -0
- package/dist/plugins/time.d.ts +12 -0
- package/dist/plugins/time.js +84 -0
- package/dist/plugins/time.js.map +1 -0
- package/dist/plugins/usage.d.ts +11 -0
- package/dist/plugins/usage.js +26 -0
- package/dist/plugins/usage.js.map +1 -0
- package/dist/prettier/config-loader.d.ts +13 -0
- package/dist/prettier/config-loader.js +105 -0
- package/dist/prettier/config-loader.js.map +1 -0
- package/dist/telemetry/index.d.ts +25 -0
- package/dist/telemetry/index.js +18 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/typescript.d.ts +293 -0
- package/dist/typescript.js +454 -0
- package/dist/typescript.js.map +1 -0
- package/dist/util/get-file-type.d.ts +2 -0
- package/dist/util/get-file-type.js +13 -0
- package/dist/util/get-file-type.js.map +1 -0
- package/dist/util/index.d.ts +2 -6
- package/dist/util/index.js +2 -6
- package/dist/util/index.js.map +1 -1
- package/dist/util/{Scope.js → is-sn-scope.js} +1 -1
- package/dist/util/is-sn-scope.js.map +1 -0
- package/dist/xml.d.ts +24 -0
- package/dist/xml.js +71 -0
- package/dist/xml.js.map +1 -0
- package/now.config.schema.json +336 -0
- package/package.json +22 -12
- package/src/app.ts +33 -0
- package/src/compiler.ts +384 -0
- package/src/compression.ts +93 -0
- package/src/crypto.ts +5 -0
- package/src/diagnostic.ts +108 -0
- package/src/{plugins/Diagnostic.ts → fluent-diagnostic.ts} +3 -10
- package/src/fluent-directive.ts +63 -0
- package/src/fluent-file.ts +13 -0
- package/src/formatter.ts +58 -0
- package/src/fs.ts +438 -0
- package/src/{GUID.ts → guid.ts} +2 -6
- package/src/index.ts +19 -5
- package/src/json.ts +20 -0
- package/src/keys-registry.ts +384 -0
- package/src/logger.ts +20 -0
- package/src/now-config.ts +337 -0
- package/src/path.ts +9 -0
- package/src/plugins/cache.ts +45 -0
- package/src/plugins/context.ts +93 -0
- package/src/plugins/database.ts +121 -0
- package/src/plugins/file.ts +19 -0
- package/src/plugins/index.ts +9 -5
- package/src/plugins/plugin.ts +995 -0
- package/src/plugins/product.ts +44 -0
- package/src/plugins/project.ts +39 -0
- package/src/plugins/shape.ts +1532 -0
- package/src/plugins/time.ts +108 -0
- package/src/plugins/usage.ts +26 -0
- package/src/prettier/config-loader.ts +130 -0
- package/src/telemetry/index.ts +27 -0
- package/src/typescript.ts +502 -0
- package/src/util/get-file-type.ts +11 -0
- package/src/util/index.ts +2 -6
- package/src/xml.ts +86 -0
- package/dist/GUID.d.ts +0 -2
- package/dist/GUID.js.map +0 -1
- package/dist/IncludePaths.d.ts +0 -25
- package/dist/IncludePaths.js +0 -97
- package/dist/IncludePaths.js.map +0 -1
- package/dist/Keys.d.ts +0 -32
- package/dist/Keys.js +0 -245
- package/dist/Keys.js.map +0 -1
- package/dist/TypeScript.d.ts +0 -5
- package/dist/TypeScript.js +0 -58
- package/dist/TypeScript.js.map +0 -1
- package/dist/XML.d.ts +0 -32
- package/dist/XML.js +0 -83
- package/dist/XML.js.map +0 -1
- package/dist/plugins/Context.d.ts +0 -190
- package/dist/plugins/Context.js.map +0 -1
- package/dist/plugins/Diagnostic.js +0 -28
- package/dist/plugins/Diagnostic.js.map +0 -1
- package/dist/plugins/Plugin.d.ts +0 -175
- package/dist/plugins/Plugin.js +0 -15
- package/dist/plugins/Plugin.js.map +0 -1
- package/dist/plugins/behaviors/Arranger.d.ts +0 -26
- package/dist/plugins/behaviors/Arranger.js.map +0 -1
- package/dist/plugins/behaviors/Composer.d.ts +0 -102
- package/dist/plugins/behaviors/Composer.js +0 -15
- package/dist/plugins/behaviors/Composer.js.map +0 -1
- package/dist/plugins/behaviors/Diagnostics.d.ts +0 -7
- package/dist/plugins/behaviors/Diagnostics.js +0 -3
- package/dist/plugins/behaviors/Diagnostics.js.map +0 -1
- package/dist/plugins/behaviors/Generator.d.ts +0 -21
- package/dist/plugins/behaviors/Generator.js.map +0 -1
- package/dist/plugins/behaviors/OwnedTables.d.ts +0 -6
- package/dist/plugins/behaviors/OwnedTables.js +0 -3
- package/dist/plugins/behaviors/OwnedTables.js.map +0 -1
- package/dist/plugins/behaviors/PostProcessor.d.ts +0 -5
- package/dist/plugins/behaviors/PostProcessor.js +0 -3
- package/dist/plugins/behaviors/PostProcessor.js.map +0 -1
- package/dist/plugins/behaviors/Serializer.d.ts +0 -30
- package/dist/plugins/behaviors/Serializer.js +0 -3
- package/dist/plugins/behaviors/Serializer.js.map +0 -1
- package/dist/plugins/behaviors/Transformer.d.ts +0 -23
- package/dist/plugins/behaviors/Transformer.js +0 -3
- package/dist/plugins/behaviors/Transformer.js.map +0 -1
- package/dist/plugins/behaviors/extractors/Data.d.ts +0 -119
- package/dist/plugins/behaviors/extractors/Data.js +0 -244
- package/dist/plugins/behaviors/extractors/Data.js.map +0 -1
- package/dist/plugins/behaviors/extractors/Extractors.d.ts +0 -63
- package/dist/plugins/behaviors/extractors/Extractors.js +0 -3
- package/dist/plugins/behaviors/extractors/Extractors.js.map +0 -1
- package/dist/plugins/behaviors/extractors/index.d.ts +0 -2
- package/dist/plugins/behaviors/extractors/index.js +0 -19
- package/dist/plugins/behaviors/extractors/index.js.map +0 -1
- package/dist/plugins/behaviors/index.d.ts +0 -9
- package/dist/plugins/behaviors/index.js +0 -26
- package/dist/plugins/behaviors/index.js.map +0 -1
- package/dist/plugins/util/CallExpression.d.ts +0 -5
- package/dist/plugins/util/CallExpression.js +0 -88
- package/dist/plugins/util/CallExpression.js.map +0 -1
- package/dist/plugins/util/CodeTransformation.d.ts +0 -95
- package/dist/plugins/util/CodeTransformation.js +0 -624
- package/dist/plugins/util/CodeTransformation.js.map +0 -1
- package/dist/plugins/util/ObjectLiteral.d.ts +0 -9
- package/dist/plugins/util/ObjectLiteral.js +0 -37
- package/dist/plugins/util/ObjectLiteral.js.map +0 -1
- package/dist/plugins/util/index.d.ts +0 -3
- package/dist/plugins/util/index.js +0 -20
- package/dist/plugins/util/index.js.map +0 -1
- package/dist/util/Debug.d.ts +0 -4
- package/dist/util/Debug.js +0 -20
- package/dist/util/Debug.js.map +0 -1
- package/dist/util/Directive.d.ts +0 -16
- package/dist/util/Directive.js +0 -107
- package/dist/util/Directive.js.map +0 -1
- package/dist/util/RuntimeTableSchema.d.ts +0 -5
- package/dist/util/RuntimeTableSchema.js +0 -58
- package/dist/util/RuntimeTableSchema.js.map +0 -1
- package/dist/util/Scope.js.map +0 -1
- package/dist/util/Util.d.ts +0 -1
- package/dist/util/Util.js +0 -12
- package/dist/util/Util.js.map +0 -1
- package/dist/util/XMLUploadParser.d.ts +0 -22
- package/dist/util/XMLUploadParser.js +0 -67
- package/dist/util/XMLUploadParser.js.map +0 -1
- package/src/IncludePaths.ts +0 -122
- package/src/Keys.ts +0 -274
- package/src/TypeScript.ts +0 -65
- package/src/XML.ts +0 -98
- package/src/plugins/Context.ts +0 -239
- package/src/plugins/Plugin.ts +0 -278
- package/src/plugins/behaviors/Arranger.ts +0 -42
- package/src/plugins/behaviors/Composer.ts +0 -125
- package/src/plugins/behaviors/Diagnostics.ts +0 -12
- package/src/plugins/behaviors/Generator.ts +0 -31
- package/src/plugins/behaviors/OwnedTables.ts +0 -5
- package/src/plugins/behaviors/PostProcessor.ts +0 -6
- package/src/plugins/behaviors/Serializer.ts +0 -40
- package/src/plugins/behaviors/Transformer.ts +0 -32
- package/src/plugins/behaviors/extractors/Data.ts +0 -332
- package/src/plugins/behaviors/extractors/Extractors.ts +0 -73
- package/src/plugins/behaviors/extractors/index.ts +0 -2
- package/src/plugins/behaviors/index.ts +0 -9
- package/src/plugins/util/CallExpression.ts +0 -110
- package/src/plugins/util/CodeTransformation.ts +0 -731
- package/src/plugins/util/ObjectLiteral.ts +0 -37
- package/src/plugins/util/index.ts +0 -3
- package/src/util/Debug.ts +0 -24
- package/src/util/Directive.ts +0 -123
- package/src/util/RuntimeTableSchema.ts +0 -44
- package/src/util/Util.ts +0 -7
- package/src/util/XMLUploadParser.ts +0 -90
- /package/dist/util/{Scope.d.ts → is-sn-scope.d.ts} +0 -0
- /package/src/util/{Scope.ts → is-sn-scope.ts} +0 -0
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ts } from '@servicenow/sdk-project'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Retrieves the property assignment with the specified name and subpath from the given node.
|
|
5
|
-
* @param node - The node to search for the property assignment.
|
|
6
|
-
* @param property - The name of the property assignment to retrieve.
|
|
7
|
-
* @param subPath - Optional subpath to navigate within the property assignment.
|
|
8
|
-
* @returns The property assignment node if found, otherwise undefined.
|
|
9
|
-
*/
|
|
10
|
-
export function getPropertyAssignment(node: ts.Node | undefined, property: string, ...subPath: string[]) {
|
|
11
|
-
let current = node
|
|
12
|
-
?.asKind(ts.SyntaxKind.ObjectLiteralExpression)
|
|
13
|
-
// get the property assignment with the specified name
|
|
14
|
-
?.getProperty((p) => hasPropertyAssignment(p, property))
|
|
15
|
-
?.asKind(ts.SyntaxKind.PropertyAssignment)
|
|
16
|
-
|
|
17
|
-
for (const pathPart of subPath) {
|
|
18
|
-
current = current
|
|
19
|
-
?.getInitializerIfKind(ts.SyntaxKind.ObjectLiteralExpression)
|
|
20
|
-
// get the property assignment with the specified name
|
|
21
|
-
?.getProperty((p) => hasPropertyAssignment(p, pathPart))
|
|
22
|
-
?.asKind(ts.SyntaxKind.PropertyAssignment)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return current
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Checks if the given property assignment has the specified path.
|
|
30
|
-
* @param property - The property assignment to check.
|
|
31
|
-
* @param path - The path to compare against.
|
|
32
|
-
* @returns True if the property assignment has the specified path, otherwise false.
|
|
33
|
-
*/
|
|
34
|
-
function hasPropertyAssignment(property: ts.ObjectLiteralElementLike | undefined, path: string): boolean {
|
|
35
|
-
const child = property?.getChildren().find((c) => ts.Node.isStringLiteral(c) || ts.Node.isIdentifier(c))
|
|
36
|
-
return child?.getSymbol()?.getEscapedName() === path
|
|
37
|
-
}
|
package/src/util/Debug.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { inspect as nodeInspect } from 'util'
|
|
2
|
-
import { Document } from '../plugins/behaviors'
|
|
3
|
-
import { Logger } from '@servicenow/sdk-project'
|
|
4
|
-
|
|
5
|
-
export function inspect(val: unknown, depth = 2) {
|
|
6
|
-
return nodeInspect(val, {
|
|
7
|
-
colors: true,
|
|
8
|
-
compact: false,
|
|
9
|
-
depth,
|
|
10
|
-
})
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function debugDocuments(documents: Document[], logger: Logger, message = 'DOCUMENTS:') {
|
|
14
|
-
logger.debug(
|
|
15
|
-
`${message} ${inspect(
|
|
16
|
-
documents.map((d) => {
|
|
17
|
-
const { node, ...rest } = d
|
|
18
|
-
node
|
|
19
|
-
return rest
|
|
20
|
-
}),
|
|
21
|
-
5
|
|
22
|
-
)}`
|
|
23
|
-
)
|
|
24
|
-
}
|
package/src/util/Directive.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { ts, tsc, Diagnostic } from '@servicenow/sdk-project'
|
|
2
|
-
import { Context } from '../plugins/Context'
|
|
3
|
-
import { FluentDiagnostic } from '../plugins'
|
|
4
|
-
|
|
5
|
-
const FluentDisableSyncDirective = '@fluent-disable-sync'
|
|
6
|
-
const FluentDisableSyncForFileDirective = '@fluent-disable-sync-for-file'
|
|
7
|
-
const fluentCommentDirectiveRegEx = /^\/\/\/?\s*@fluent-ignore\b/
|
|
8
|
-
|
|
9
|
-
enum FluentDirectiveType {
|
|
10
|
-
Ignore = 'ignore',
|
|
11
|
-
}
|
|
12
|
-
export type FluentDirective = {
|
|
13
|
-
filePath: string
|
|
14
|
-
start: number
|
|
15
|
-
type: FluentDirectiveType
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function getDirectiveFromCommentText(text: string) {
|
|
19
|
-
const directiveRegex = /^.*(\/{2,}|\/\*{1,})*\s*(@fluent-[-_a-zA-Z0-9]+).*$/m
|
|
20
|
-
return text.match(directiveRegex)?.[2]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getDirectivesFromAncestors(node: ts.Node) {
|
|
24
|
-
return [node].concat(node.getAncestors()).flatMap(
|
|
25
|
-
(ancestor) =>
|
|
26
|
-
ancestor
|
|
27
|
-
.getLeadingCommentRanges()
|
|
28
|
-
.map((comment) => getDirectiveFromCommentText(comment.getText()))
|
|
29
|
-
.filter((directive) => directive) as string[]
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function isFluentDirective(text: string, kind: tsc.CommentKind) {
|
|
34
|
-
text = text.trim()
|
|
35
|
-
if (kind === tsc.SyntaxKind.SingleLineCommentTrivia) {
|
|
36
|
-
return fluentCommentDirectiveRegEx.test(text)
|
|
37
|
-
}
|
|
38
|
-
text = text.substring(2, text.length - 2).trim()
|
|
39
|
-
return /^@fluent-ignore\b/.test(text)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function parseFluentDirectives(filePath: string, context: Context) {
|
|
43
|
-
const fluentDirectives: FluentDirective[] = []
|
|
44
|
-
const visitedRange = new Set<number>()
|
|
45
|
-
const sourceFile = context.compiler.getSourceFile(filePath)
|
|
46
|
-
if (sourceFile) {
|
|
47
|
-
const sourceCode = sourceFile.getFullText()
|
|
48
|
-
context.compiler.visitNodeTree(sourceFile, (node) => {
|
|
49
|
-
;[
|
|
50
|
-
...(tsc.getLeadingCommentRanges(sourceCode, node.getFullStart()) ?? []),
|
|
51
|
-
...(tsc.getTrailingCommentRanges(sourceCode, node.getFullStart()) ?? []),
|
|
52
|
-
].forEach((range) => {
|
|
53
|
-
if (
|
|
54
|
-
!visitedRange.has(range.pos) &&
|
|
55
|
-
isFluentDirective(sourceCode.substring(range.pos, range.end), range.kind)
|
|
56
|
-
) {
|
|
57
|
-
fluentDirectives.push({
|
|
58
|
-
filePath,
|
|
59
|
-
start: range.pos,
|
|
60
|
-
type: FluentDirectiveType.Ignore,
|
|
61
|
-
})
|
|
62
|
-
visitedRange.add(range.pos)
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
return fluentDirectives
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function syncDisabledForNode(node: ts.Node) {
|
|
71
|
-
return getDirectivesFromAncestors(node).some((directive) => directive === FluentDisableSyncDirective)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function syncDisabledForFile(sourceFile: ts.SourceFile) {
|
|
75
|
-
return sourceFile
|
|
76
|
-
.getStatements()?.[0]
|
|
77
|
-
?.getLeadingCommentRanges()
|
|
78
|
-
.map((comment) => getDirectiveFromCommentText(comment.getText()))
|
|
79
|
-
.some((directive) => directive === FluentDisableSyncForFileDirective)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function applyFluentDirectives(context: Context, diagnostics: Diagnostic[]) {
|
|
83
|
-
const directiveCache = new Map<string, FluentDirective[]>()
|
|
84
|
-
const filteredDiagnostics = diagnostics.filter((diagnostic) => {
|
|
85
|
-
const filePath = diagnostic.file.getFilePath()
|
|
86
|
-
let fluentDirectives = directiveCache.get(filePath)
|
|
87
|
-
if (!fluentDirectives) {
|
|
88
|
-
fluentDirectives = parseFluentDirectives(filePath, context)
|
|
89
|
-
directiveCache.set(filePath, fluentDirectives)
|
|
90
|
-
}
|
|
91
|
-
let allowDiagnostic = true
|
|
92
|
-
for (const directive of fluentDirectives) {
|
|
93
|
-
const { line: direcLine } = diagnostic.file.getLineAndColumnAtPos(directive.start)
|
|
94
|
-
const { line: diagLine } = diagnostic.file.getLineAndColumnAtPos(diagnostic.position.start)
|
|
95
|
-
if (direcLine + 1 === diagLine) {
|
|
96
|
-
allowDiagnostic = false
|
|
97
|
-
break
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return allowDiagnostic
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
return filteredDiagnostics
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function getDirectiveDiagnostics(node: ts.Node): FluentDiagnostic[] {
|
|
107
|
-
// Currently, the @fluent-disable-sync directive is only allowed before a CallExpression
|
|
108
|
-
// If we see it, within one (say, in a PropertyAssignment), we should flag it
|
|
109
|
-
if (node.isKind(ts.SyntaxKind.CallExpression)) {
|
|
110
|
-
return node
|
|
111
|
-
.getDescendantsOfKind(ts.SyntaxKind.SingleLineCommentTrivia)
|
|
112
|
-
.filter((commentNode) => getDirectiveFromCommentText(commentNode.getText()) === FluentDisableSyncDirective)
|
|
113
|
-
.map((n) => {
|
|
114
|
-
return new FluentDiagnostic(
|
|
115
|
-
n,
|
|
116
|
-
`${FluentDisableSyncDirective} directive only allowed before a call expression`,
|
|
117
|
-
{ level: Diagnostic.Level.Warn }
|
|
118
|
-
)
|
|
119
|
-
})
|
|
120
|
-
} else {
|
|
121
|
-
return []
|
|
122
|
-
}
|
|
123
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import * as tables from '@servicenow/sdk-core/runtime/fluent'
|
|
2
|
-
import { Document } from '../plugins'
|
|
3
|
-
|
|
4
|
-
type Tag = 'html' | 'script' | 'css' | 'xml'
|
|
5
|
-
|
|
6
|
-
export type FieldToTagMap = Record<string, Tag>
|
|
7
|
-
|
|
8
|
-
const internalTypeToScriptTag: FieldToTagMap = {
|
|
9
|
-
html: 'html',
|
|
10
|
-
translated_html: 'html',
|
|
11
|
-
html_template: 'html',
|
|
12
|
-
message_html: 'html',
|
|
13
|
-
html_script: 'html',
|
|
14
|
-
script: 'script',
|
|
15
|
-
script_plain: 'script',
|
|
16
|
-
xml: 'xml',
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function maybeGetFieldToTagMap(table: string, documents: Document[]): FieldToTagMap {
|
|
20
|
-
return getTagsForColumnsFromSystemTables(table) || getTagsForColumnsFromBootstrapDocs(table, documents) || {}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getTagsForColumnsFromSystemTables(table: string): FieldToTagMap | undefined {
|
|
24
|
-
const schema = (tables as any)[table]?.schema
|
|
25
|
-
return (
|
|
26
|
-
schema &&
|
|
27
|
-
Object.entries(schema)
|
|
28
|
-
.filter(([_, schema]) => internalTypeToScriptTag[(schema as any).column_type])
|
|
29
|
-
.map(([field, schema]) => ({ [field]: internalTypeToScriptTag[(schema as any).column_type] }))
|
|
30
|
-
.reduce((acc, val) => ({ ...acc, ...val }), {})
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getTagsForColumnsFromBootstrapDocs(table: string, documents: Document[]): FieldToTagMap | undefined {
|
|
35
|
-
const bootstrapDoc = documents.find((doc) => doc.kind === 'bootstrap' && doc.guid === table)
|
|
36
|
-
const columns = bootstrapDoc?.data?.['data']?.bootstrapData.columns
|
|
37
|
-
return (
|
|
38
|
-
columns &&
|
|
39
|
-
Object.entries(columns)
|
|
40
|
-
.filter(([, column]) => internalTypeToScriptTag[(column as any).type])
|
|
41
|
-
.map(([field, column]) => ({ [field]: internalTypeToScriptTag[(column as any).type] }))
|
|
42
|
-
.reduce((acc, val) => ({ ...acc, ...val }), {})
|
|
43
|
-
)
|
|
44
|
-
}
|
package/src/util/Util.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
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
|
-
}
|
|
File without changes
|
|
File without changes
|