@servicenow/sdk-build-core 3.0.2 → 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 -77
- 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 -92
- 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,332 +0,0 @@
|
|
|
1
|
-
import { SupportedNode } from '@servicenow/sdk-project'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Actions indicate what should take place in the database when the XML file
|
|
5
|
-
* is loaded. The platform understands these three actions: insert/update,
|
|
6
|
-
* delete, and delete multiple.
|
|
7
|
-
*/
|
|
8
|
-
export type Action = 'INSERT_OR_UPDATE' | 'DELETE' | 'delete_multiple'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Utility type for data passed to XML extractors for processing.
|
|
12
|
-
*/
|
|
13
|
-
export type Xml = {
|
|
14
|
-
filePath: string
|
|
15
|
-
data: any
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Utility type to represent a simple object structure with primitive values.
|
|
20
|
-
*/
|
|
21
|
-
export type PrimitiveData = {
|
|
22
|
-
[x: string]: PrimitiveData | PrimitiveData[] | string | number | boolean | undefined
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* XML data is data from XML files (such as the parsed content of a record_update)
|
|
27
|
-
* which is not associated with any AST node.
|
|
28
|
-
*/
|
|
29
|
-
export class XmlData<D extends PrimitiveData = PrimitiveData> {
|
|
30
|
-
constructor(
|
|
31
|
-
public data: D,
|
|
32
|
-
readonly filePath: string,
|
|
33
|
-
readonly kind: string,
|
|
34
|
-
readonly action: Action = 'INSERT_OR_UPDATE'
|
|
35
|
-
) {}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type WrappedData<D> = {
|
|
39
|
-
[K in keyof D]: D[K] extends string
|
|
40
|
-
? StringData<D[K]>
|
|
41
|
-
: D[K] extends number
|
|
42
|
-
? NumberData<D[K]>
|
|
43
|
-
: D[K] extends boolean
|
|
44
|
-
? BooleanData<D[K]>
|
|
45
|
-
: D[K] extends Array<unknown>
|
|
46
|
-
? ArrayData<D[K]>
|
|
47
|
-
: D[K] extends Record<string, unknown>
|
|
48
|
-
? ObjectData<D[K]>
|
|
49
|
-
: Data<D[K]>
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export type TypeName = 'string' | 'number' | 'boolean' | 'array' | 'object' | 'entity'
|
|
53
|
-
export type Type<T extends TypeName> = T extends 'string'
|
|
54
|
-
? StringData
|
|
55
|
-
: T extends 'number'
|
|
56
|
-
? NumberData
|
|
57
|
-
: T extends 'boolean'
|
|
58
|
-
? BooleanData
|
|
59
|
-
: T extends 'array'
|
|
60
|
-
? ArrayData
|
|
61
|
-
: T extends 'object'
|
|
62
|
-
? ObjectData
|
|
63
|
-
: T extends 'entity'
|
|
64
|
-
? EntityData
|
|
65
|
-
: never
|
|
66
|
-
|
|
67
|
-
function getClassFromTypeName(type: TypeName) {
|
|
68
|
-
switch (type) {
|
|
69
|
-
case 'string':
|
|
70
|
-
return StringData
|
|
71
|
-
case 'number':
|
|
72
|
-
return NumberData
|
|
73
|
-
case 'boolean':
|
|
74
|
-
return BooleanData
|
|
75
|
-
case 'array':
|
|
76
|
-
return ArrayData
|
|
77
|
-
case 'object':
|
|
78
|
-
return ObjectData
|
|
79
|
-
case 'entity':
|
|
80
|
-
return EntityData
|
|
81
|
-
default:
|
|
82
|
-
throw new Error(`Unrecognized type name: ${type}`)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export abstract class Data<D = unknown> {
|
|
87
|
-
constructor(private readonly node: SupportedNode) {}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @deprecated Using this for an array or object is bad practice because all of the elements/properties
|
|
91
|
-
* will be assigned the same node as the array/object itself. This makes it difficult to bidrectionally
|
|
92
|
-
* sync data created this way because you don't have the granularity required to know where each of the
|
|
93
|
-
* element/property values (and any nested values) came from.
|
|
94
|
-
*/
|
|
95
|
-
static fromValue<const D>(value: D, node: SupportedNode): Data<D> {
|
|
96
|
-
if (value === undefined || value === null) {
|
|
97
|
-
return new UndefinedData(node) as Data<D> // TODO: How can we avoid this silly cast?
|
|
98
|
-
} else if (typeof value === 'string') {
|
|
99
|
-
return new StringData(value, node)
|
|
100
|
-
} else if (typeof value === 'number') {
|
|
101
|
-
return new NumberData(value, node)
|
|
102
|
-
} else if (typeof value === 'boolean') {
|
|
103
|
-
return new BooleanData(value, node)
|
|
104
|
-
} else if (Array.isArray(value)) {
|
|
105
|
-
return ArrayData.fromArrayValue(value, node)
|
|
106
|
-
} else if (!!value && typeof value === 'object') {
|
|
107
|
-
const obj = Object.fromEntries(Object.entries(value).filter(([key]) => typeof key === 'string'))
|
|
108
|
-
return ObjectData.fromObjectValue(obj as typeof obj & D, node)
|
|
109
|
-
} else {
|
|
110
|
-
throw new Error(
|
|
111
|
-
`Unsupported data type: ${value} (Type: ${typeof value}, Class: ${value?.constructor?.name})`
|
|
112
|
-
)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
static isUndefined(data?: unknown): data is UndefinedData {
|
|
117
|
-
return data instanceof UndefinedData
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
static isString(data?: unknown): data is StringData {
|
|
121
|
-
return data instanceof StringData
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
static isNumber(data?: unknown): data is NumberData {
|
|
125
|
-
return data instanceof NumberData
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
static isBoolean(data?: unknown): data is BooleanData {
|
|
129
|
-
return data instanceof BooleanData
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
static isArray(data?: unknown): data is ArrayData {
|
|
133
|
-
return data instanceof ArrayData
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
static isObject(data?: unknown): data is ObjectData {
|
|
137
|
-
return data instanceof ObjectData
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
static isEntity(data?: unknown): data is EntityData {
|
|
141
|
-
return data instanceof EntityData
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
abstract getValue(resolveReferences?: boolean): D
|
|
145
|
-
|
|
146
|
-
getNode(): SupportedNode {
|
|
147
|
-
return this.node
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
needsCDATATag(): boolean {
|
|
151
|
-
return false
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export class UndefinedData extends Data<undefined> {
|
|
156
|
-
constructor(node: SupportedNode) {
|
|
157
|
-
super(node)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
getValue() {
|
|
161
|
-
return undefined
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export class StringData<const D extends string = string> extends Data<D> {
|
|
166
|
-
constructor(
|
|
167
|
-
private readonly value: D,
|
|
168
|
-
node: SupportedNode,
|
|
169
|
-
private options: {
|
|
170
|
-
needsCDATA: boolean
|
|
171
|
-
} = { needsCDATA: false }
|
|
172
|
-
) {
|
|
173
|
-
super(node)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
getValue() {
|
|
177
|
-
return this.value
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
override needsCDATATag() {
|
|
181
|
-
return this.options.needsCDATA
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export class NumberData<const D extends number = number> extends Data<D> {
|
|
186
|
-
constructor(
|
|
187
|
-
private readonly value: D,
|
|
188
|
-
node: SupportedNode
|
|
189
|
-
) {
|
|
190
|
-
super(node)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
getValue() {
|
|
194
|
-
return this.value
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export class BooleanData<const D extends boolean = boolean> extends Data<D> {
|
|
199
|
-
constructor(
|
|
200
|
-
private readonly value: D,
|
|
201
|
-
node: SupportedNode
|
|
202
|
-
) {
|
|
203
|
-
super(node)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
getValue() {
|
|
207
|
-
return this.value
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export class ArrayData<const D extends unknown[] = unknown[]> extends Data<D> {
|
|
212
|
-
constructor(
|
|
213
|
-
private readonly elements: WrappedData<D>,
|
|
214
|
-
node: SupportedNode
|
|
215
|
-
) {
|
|
216
|
-
super(node)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @deprecated Using this for arrays is bad practice because all of the array elements will be
|
|
221
|
-
* assigned the same node as the array itself. This makes it difficult to bidrectionally sync
|
|
222
|
-
* data created this way because you don't have the granularity required to know where each of
|
|
223
|
-
* the element values (and any nested values) came from.
|
|
224
|
-
*/
|
|
225
|
-
static fromArrayValue<const D extends unknown[]>(value: D, node: SupportedNode): ArrayData<D> {
|
|
226
|
-
const elements = value.map((value) => Data.fromValue(value, node)) as WrappedData<D>
|
|
227
|
-
|
|
228
|
-
return new ArrayData(elements, node)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
getValue(resolveReferences = false) {
|
|
232
|
-
return this.elements.map((element) =>
|
|
233
|
-
!resolveReferences && Data.isEntity(element) ? element.getGuid() : element.getValue()
|
|
234
|
-
) as D
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
getElements() {
|
|
238
|
-
return this.elements
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export class ObjectData<const D extends Record<string, unknown> = Record<string, unknown>> extends Data<D> {
|
|
243
|
-
constructor(
|
|
244
|
-
private readonly properties: WrappedData<D>,
|
|
245
|
-
node: SupportedNode
|
|
246
|
-
) {
|
|
247
|
-
super(node)
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* @deprecated Using this for objects is bad practice because all of the object properties will
|
|
252
|
-
* be assigned the same node as the object itself. This makes it difficult to bidrectionally sync
|
|
253
|
-
* data created this way because you don't have the granularity required to know where each of
|
|
254
|
-
* the property values (and any nested values) came from.
|
|
255
|
-
*/
|
|
256
|
-
static fromObjectValue<const D extends Record<string, unknown>>(value: D, node: SupportedNode): ObjectData<D> {
|
|
257
|
-
const properties = Object.fromEntries(
|
|
258
|
-
Object.entries(value).map(([key, value]) => [key, Data.fromValue(value, node)])
|
|
259
|
-
) as WrappedData<D>
|
|
260
|
-
|
|
261
|
-
return new ObjectData(properties, node)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
getValue(resolveReferences = false) {
|
|
265
|
-
return Object.fromEntries(
|
|
266
|
-
Object.entries(this.properties).map(([key, value]) => [
|
|
267
|
-
key,
|
|
268
|
-
!resolveReferences && Data.isEntity(value) ? value.getGuid() : value.getValue(),
|
|
269
|
-
])
|
|
270
|
-
) as D
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
getProperty<const K extends keyof D, const T extends TypeName>(
|
|
274
|
-
name: K,
|
|
275
|
-
type?: T
|
|
276
|
-
): TypeName extends T ? WrappedData<D>[K] : Type<T> | undefined {
|
|
277
|
-
const property = this.properties[name]
|
|
278
|
-
if (type) {
|
|
279
|
-
const expectedClass = getClassFromTypeName(type)
|
|
280
|
-
if (!(property instanceof expectedClass)) {
|
|
281
|
-
return undefined as any
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return property as any
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
getPropertyOrThrow<const K extends keyof D, const T extends TypeName>(
|
|
289
|
-
name: K,
|
|
290
|
-
type?: T
|
|
291
|
-
): TypeName extends T ? NonNullable<WrappedData<D>[K]> : Type<T> {
|
|
292
|
-
const property = this.getProperty(name, type)
|
|
293
|
-
if (!property) {
|
|
294
|
-
throw new Error(`Property "${name.toString()}" not found on object`)
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return property as any
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
getProperties() {
|
|
301
|
-
return this.properties
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export class EntityData<const D extends Record<string, unknown> = Record<string, unknown>> extends ObjectData<D> {
|
|
306
|
-
constructor(
|
|
307
|
-
private readonly kind: string,
|
|
308
|
-
private readonly guid: string,
|
|
309
|
-
entity: ObjectData<D>,
|
|
310
|
-
node: SupportedNode,
|
|
311
|
-
private installMethod?: string,
|
|
312
|
-
private explicitIds?: string[]
|
|
313
|
-
) {
|
|
314
|
-
super(entity.getProperties(), node)
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
getInstallMethod() {
|
|
318
|
-
return this.installMethod
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
getKind() {
|
|
322
|
-
return this.kind
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
getGuid() {
|
|
326
|
-
return this.guid
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
getExplicitIds() {
|
|
330
|
-
return this.explicitIds ?? []
|
|
331
|
-
}
|
|
332
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { SupportedKindName, SupportedNodeByKindName } from '@servicenow/sdk-project'
|
|
2
|
-
import { Data, EntityData, Xml, XmlData } from './Data'
|
|
3
|
-
import { Context } from '../../Context'
|
|
4
|
-
import { FluentDiagnostic } from '../../Diagnostic'
|
|
5
|
-
|
|
6
|
-
export type ExtractionResult<D extends Data = Data> =
|
|
7
|
-
| {
|
|
8
|
-
handled: false
|
|
9
|
-
}
|
|
10
|
-
| {
|
|
11
|
-
handled: true
|
|
12
|
-
data?: D | undefined
|
|
13
|
-
diagnostics: FluentDiagnostic[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* An XML extractor function accepts an {@linkcode Xml} object and returns one or
|
|
18
|
-
* more pieces of {@linkcode XmlData} extracted from that object. The function may
|
|
19
|
-
* also return undefined to indicate that it did not handle the object.
|
|
20
|
-
*/
|
|
21
|
-
export type XmlExtractorFunction = (xml: Xml, context: Context) => XmlData | XmlData[] | undefined
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A raw extractor function accepts an AST node and returns one or more pieces of
|
|
25
|
-
* {@linkcode Data} extracted from that node which cannot be composed into documents
|
|
26
|
-
* on their own but could be part of an entity.
|
|
27
|
-
*/
|
|
28
|
-
export type RawExtractorFunction<N extends SupportedKindName | 'any' = SupportedKindName> = (
|
|
29
|
-
node: N extends SupportedKindName ? SupportedNodeByKindName<N> : any,
|
|
30
|
-
context: Context
|
|
31
|
-
) => ExtractionResult<Data>
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* An entity extractor function accepts an AST node and returns one or more pieces
|
|
35
|
-
* of {@linkcode EntityData} extracted from that node which can then be composed
|
|
36
|
-
* into documents.
|
|
37
|
-
*/
|
|
38
|
-
export type EntityExtractorFunction<N extends SupportedKindName | 'any' = SupportedKindName> = (
|
|
39
|
-
node: N extends SupportedKindName ? SupportedNodeByKindName<N> : any,
|
|
40
|
-
context: Context
|
|
41
|
-
) => ExtractionResult<EntityData>
|
|
42
|
-
|
|
43
|
-
// This is only imported so it can be referenced in the JS doc below
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
|
-
import type { Plugin } from '../../Plugin'
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @see {@linkcode Plugin#extractors}
|
|
49
|
-
*/
|
|
50
|
-
export type Extractors<
|
|
51
|
-
FluentRawNodeKinds extends SupportedKindName | 'any',
|
|
52
|
-
ModuleRawNodeKinds extends SupportedKindName | 'any',
|
|
53
|
-
JsonRawNodeKinds extends SupportedKindName | 'any',
|
|
54
|
-
AnyRawNodeKinds extends SupportedKindName | 'any',
|
|
55
|
-
FluentEntityNodeKinds extends SupportedKindName | 'any',
|
|
56
|
-
ModuleEntityNodeKinds extends SupportedKindName | 'any',
|
|
57
|
-
JsonEntityNodeKinds extends SupportedKindName | 'any',
|
|
58
|
-
AnyEntityNodeKinds extends SupportedKindName | 'any',
|
|
59
|
-
> = {
|
|
60
|
-
xml?: XmlExtractorFunction
|
|
61
|
-
raw?: {
|
|
62
|
-
fluent?: { [K in FluentRawNodeKinds]: RawExtractorFunction<K> }
|
|
63
|
-
module?: { [K in ModuleRawNodeKinds]: RawExtractorFunction<K> }
|
|
64
|
-
json?: { [K in JsonRawNodeKinds]: RawExtractorFunction<K> }
|
|
65
|
-
any?: { [K in AnyRawNodeKinds]: RawExtractorFunction<K> }
|
|
66
|
-
}
|
|
67
|
-
entity?: {
|
|
68
|
-
fluent?: { [K in FluentEntityNodeKinds]: EntityExtractorFunction<K> }
|
|
69
|
-
module?: { [K in ModuleEntityNodeKinds]: EntityExtractorFunction<K> }
|
|
70
|
-
json?: { [K in JsonEntityNodeKinds]: EntityExtractorFunction<K> }
|
|
71
|
-
any?: { [K in AnyEntityNodeKinds]: EntityExtractorFunction<K> }
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './extractors'
|
|
2
|
-
export * from './Composer'
|
|
3
|
-
export * from './Arranger'
|
|
4
|
-
export * from './Serializer'
|
|
5
|
-
export * from './Generator'
|
|
6
|
-
export * from './Transformer'
|
|
7
|
-
export * from './PostProcessor'
|
|
8
|
-
export * from './Diagnostics'
|
|
9
|
-
export * from './OwnedTables'
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { ts } from '@servicenow/sdk-project'
|
|
2
|
-
import { Context } from '../Context'
|
|
3
|
-
import { EntityData, ExtractionResult, ObjectData } from '../behaviors'
|
|
4
|
-
import { FluentDiagnostic } from '../Diagnostic'
|
|
5
|
-
|
|
6
|
-
export function getCallExpressionName(node: ts.CallExpression) {
|
|
7
|
-
const expression = node.getExpression()
|
|
8
|
-
if (ts.Node.isIdentifier(expression)) {
|
|
9
|
-
return expression.getText()
|
|
10
|
-
} else if (ts.Node.isPropertyAccessExpression(expression)) {
|
|
11
|
-
return expression.getName()
|
|
12
|
-
} else {
|
|
13
|
-
throw `CallExpression does not have an identifier: ${expression.getText()}`
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function extractCallExpression<
|
|
18
|
-
const A extends unknown[],
|
|
19
|
-
const E extends A extends [infer T extends Record<string, unknown>] ? T : never,
|
|
20
|
-
const K extends string,
|
|
21
|
-
>(
|
|
22
|
-
fn: (...args: A) => E,
|
|
23
|
-
kind: K,
|
|
24
|
-
node: ts.CallExpression,
|
|
25
|
-
context: Context,
|
|
26
|
-
guid: (entity: E) => string,
|
|
27
|
-
validate: (entity: unknown) => entity is E = (_): _ is E => true
|
|
28
|
-
): ExtractionResult<EntityData<E>> {
|
|
29
|
-
let name = ''
|
|
30
|
-
try {
|
|
31
|
-
name = getCallExpressionName(node)
|
|
32
|
-
} catch (e) {
|
|
33
|
-
return {
|
|
34
|
-
handled: true,
|
|
35
|
-
diagnostics: [new FluentDiagnostic(node, 'Unsupported call expression')],
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (name !== fn.name) {
|
|
40
|
-
return { handled: false }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const diagnostics: FluentDiagnostic[] = []
|
|
44
|
-
const args = node
|
|
45
|
-
.getArguments()
|
|
46
|
-
.map((a) => {
|
|
47
|
-
const result = context.extractAst(a)
|
|
48
|
-
if (!result.handled) {
|
|
49
|
-
diagnostics.push(new FluentDiagnostic(a, `Unsupported argument in ${fn.name} call`))
|
|
50
|
-
return undefined
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
diagnostics.push(...result.diagnostics)
|
|
54
|
-
if (!result.data) {
|
|
55
|
-
diagnostics.push(new FluentDiagnostic(a, `Unsupported argument in ${fn.name} call`))
|
|
56
|
-
return undefined
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return result.data
|
|
60
|
-
})
|
|
61
|
-
.filter((a) => a !== undefined)
|
|
62
|
-
|
|
63
|
-
if (!(0 in args) || args.length !== 1) {
|
|
64
|
-
return {
|
|
65
|
-
handled: true,
|
|
66
|
-
diagnostics: [
|
|
67
|
-
...diagnostics,
|
|
68
|
-
new FluentDiagnostic(node, `Expected ${fn.name} call to have exactly one argument`),
|
|
69
|
-
],
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const entity = args[0] as ObjectData<E>
|
|
74
|
-
const entityValue = entity.getValue()
|
|
75
|
-
if (!validate(entityValue)) {
|
|
76
|
-
return {
|
|
77
|
-
handled: true,
|
|
78
|
-
diagnostics: [...diagnostics, new FluentDiagnostic(node, `Invalid ${fn.name} call argument`)],
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
handled: true,
|
|
84
|
-
diagnostics,
|
|
85
|
-
data: new EntityData(
|
|
86
|
-
kind,
|
|
87
|
-
guid(entityValue),
|
|
88
|
-
entity,
|
|
89
|
-
node,
|
|
90
|
-
extractInstallMethod(entity),
|
|
91
|
-
extractExplicitId(entity)
|
|
92
|
-
),
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function extractInstallMethod<const D extends Record<string, unknown>>(entity: ObjectData<D>) {
|
|
97
|
-
const $meta = entity.getProperty('$meta')
|
|
98
|
-
if (!$meta) {
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
return $meta.getValue()['installMethod']
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function extractExplicitId<const D extends Record<string, unknown>>(entity: ObjectData<D>) {
|
|
105
|
-
const $id = entity.getProperty('$id')
|
|
106
|
-
if (!$id) {
|
|
107
|
-
return []
|
|
108
|
-
}
|
|
109
|
-
return [`${$id.getValue()}`]
|
|
110
|
-
}
|