@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,106 @@
|
|
|
1
|
+
import { Logger } from '@servicenow/sdk-project';
|
|
2
|
+
import { CallExpression } from 'ts-morph';
|
|
3
|
+
import { Context } from '../Context';
|
|
4
|
+
import { EntityData } from '../behaviors';
|
|
5
|
+
export type ConfigEntity = {
|
|
6
|
+
inputObject: InputObject;
|
|
7
|
+
configEntries: ConfigEntries;
|
|
8
|
+
};
|
|
9
|
+
export type InputObject = {
|
|
10
|
+
$id: string | number;
|
|
11
|
+
[name: string]: any;
|
|
12
|
+
};
|
|
13
|
+
export type ConfigEntries = {
|
|
14
|
+
[index: `${number}`]: ConfigEntry;
|
|
15
|
+
};
|
|
16
|
+
export type ConfigEntry = {
|
|
17
|
+
name: string;
|
|
18
|
+
info: {
|
|
19
|
+
[name: string]: any;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type ComposerClass = {
|
|
23
|
+
prototype: any;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
};
|
|
26
|
+
export declare class ConfigurationFunctionEntityData extends EntityData {
|
|
27
|
+
private readonly config;
|
|
28
|
+
constructor(config: ConfigEntity, node: CallExpression);
|
|
29
|
+
getValue(): ConfigEntity;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* This is an extractor used to extract configuration functions.
|
|
33
|
+
* This is an example of a configuration function:
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { table } from 'place'
|
|
36
|
+
* PlaceHolderFunction('Unique ID', (param) => {
|
|
37
|
+
* param.foo({arg1: 'hey', arg2: table});
|
|
38
|
+
* const output = param.bar({placeholder: 'value'});
|
|
39
|
+
* param.baz({arg1: output.value1})
|
|
40
|
+
* })
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class ConfigurationFunctionExtractor {
|
|
44
|
+
private rootNode;
|
|
45
|
+
private context;
|
|
46
|
+
private composerClass;
|
|
47
|
+
private identifiers;
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param rootNode rootNode of AST where extraction begins
|
|
51
|
+
* @param context context from the plugin this is called in
|
|
52
|
+
* @param composerClass A class whose prototype will be used to validate the allowed functions within the configuration function
|
|
53
|
+
*/
|
|
54
|
+
constructor(rootNode: CallExpression, context: Context, composerClass: ComposerClass);
|
|
55
|
+
/**
|
|
56
|
+
* Grabs the property access expression chain of a call expression, and protects against accidentally grabbing property access expressions in arguments of the call expression
|
|
57
|
+
*/
|
|
58
|
+
private getPropChain;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the first element of a property access chain
|
|
61
|
+
* v
|
|
62
|
+
* a.b.c.d({})
|
|
63
|
+
*/
|
|
64
|
+
private getFirstProp;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the last element of a property access chain
|
|
67
|
+
*
|
|
68
|
+
* v
|
|
69
|
+
* a.b.c.d({})
|
|
70
|
+
*/
|
|
71
|
+
private getLastProp;
|
|
72
|
+
/**
|
|
73
|
+
* Validates that a call expression is valid. Will error if the call expression is inappropriately constructed for the configuration function
|
|
74
|
+
* @param ce
|
|
75
|
+
* @param parameterName
|
|
76
|
+
*/
|
|
77
|
+
private isValidCallExpression;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the step number of the step containing a identifier which matches the type of the queried identfier
|
|
80
|
+
*
|
|
81
|
+
* If it cannot find the identifier, it returns -1
|
|
82
|
+
* @param identifier
|
|
83
|
+
* @param data
|
|
84
|
+
*/
|
|
85
|
+
private findReferencedIdentifier;
|
|
86
|
+
private getRootIdentifier;
|
|
87
|
+
private parseValue;
|
|
88
|
+
private getKVPair;
|
|
89
|
+
private objNodeToJSON;
|
|
90
|
+
private getName;
|
|
91
|
+
private getConfigFunctionComponents;
|
|
92
|
+
private extractCallExpression;
|
|
93
|
+
extractConfigFunction(kind: string, // Name of function for now
|
|
94
|
+
logger: Logger): EntityData | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Returns a single entity of the kind specified which contains all data of nodes within the configuration function
|
|
97
|
+
*
|
|
98
|
+
* Will attempt to generalize this for use by flow team
|
|
99
|
+
* @param kind
|
|
100
|
+
* @param node
|
|
101
|
+
* @param context
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
extractConfigFunctionUnsafe(kind: string, // Name of function for now,
|
|
105
|
+
logger: Logger): EntityData | undefined;
|
|
106
|
+
}
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigurationFunctionExtractor = exports.ConfigurationFunctionEntityData = void 0;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const behaviors_1 = require("../behaviors");
|
|
6
|
+
const CallExpression_1 = require("./CallExpression");
|
|
7
|
+
// TODO: Just created this to avoid refactoring all of the ATF stuff. Should be removed
|
|
8
|
+
// and the EntityData class should be used instead, if possible.
|
|
9
|
+
class ConfigurationFunctionEntityData extends behaviors_1.EntityData {
|
|
10
|
+
config;
|
|
11
|
+
constructor(config, node) {
|
|
12
|
+
super('test', 'NO_GUID_GENERATED', // TODO: Generate GUID?
|
|
13
|
+
new behaviors_1.ObjectData({}, node), node);
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
getValue() {
|
|
17
|
+
return this.config;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ConfigurationFunctionEntityData = ConfigurationFunctionEntityData;
|
|
21
|
+
/**
|
|
22
|
+
* This is an extractor used to extract configuration functions.
|
|
23
|
+
* This is an example of a configuration function:
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { table } from 'place'
|
|
26
|
+
* PlaceHolderFunction('Unique ID', (param) => {
|
|
27
|
+
* param.foo({arg1: 'hey', arg2: table});
|
|
28
|
+
* const output = param.bar({placeholder: 'value'});
|
|
29
|
+
* param.baz({arg1: output.value1})
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
class ConfigurationFunctionExtractor {
|
|
34
|
+
rootNode;
|
|
35
|
+
context;
|
|
36
|
+
composerClass;
|
|
37
|
+
identifiers;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param rootNode rootNode of AST where extraction begins
|
|
41
|
+
* @param context context from the plugin this is called in
|
|
42
|
+
* @param composerClass A class whose prototype will be used to validate the allowed functions within the configuration function
|
|
43
|
+
*/
|
|
44
|
+
constructor(rootNode, context, composerClass) {
|
|
45
|
+
this.rootNode = rootNode;
|
|
46
|
+
this.context = context;
|
|
47
|
+
this.composerClass = composerClass;
|
|
48
|
+
this.identifiers = [];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Grabs the property access expression chain of a call expression, and protects against accidentally grabbing property access expressions in arguments of the call expression
|
|
52
|
+
*/
|
|
53
|
+
getPropChain(ce) {
|
|
54
|
+
// Do this to ensure we are only considering property access expressions that are apart of the chain and not potentially in the arguments of the function
|
|
55
|
+
const props = [ce.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression)];
|
|
56
|
+
const childProps = props[0].getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
57
|
+
if (childProps.length > 0) {
|
|
58
|
+
props.push(...childProps);
|
|
59
|
+
}
|
|
60
|
+
return props;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns the first element of a property access chain
|
|
64
|
+
* v
|
|
65
|
+
* a.b.c.d({})
|
|
66
|
+
*/
|
|
67
|
+
getFirstProp(ce) {
|
|
68
|
+
// Need to use this instead of just grabbing descendents cause the arguments of the call expression can also potentially have property access expressions which we don't want to consider
|
|
69
|
+
const props = this.getPropChain(ce);
|
|
70
|
+
if (props.length === 1) {
|
|
71
|
+
const ids = props[0]?.getChildrenOfKind(ts_morph_1.SyntaxKind.Identifier);
|
|
72
|
+
return ids[0];
|
|
73
|
+
}
|
|
74
|
+
const lastProp = props[props.length - 1];
|
|
75
|
+
return lastProp.getChildrenOfKind(ts_morph_1.SyntaxKind.Identifier)[0];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the last element of a property access chain
|
|
79
|
+
*
|
|
80
|
+
* v
|
|
81
|
+
* a.b.c.d({})
|
|
82
|
+
*/
|
|
83
|
+
getLastProp(ce) {
|
|
84
|
+
// Do not need special chain handling here like in getFirstProp cause we are always grabbing the property access expression from the top level regardless of chain length
|
|
85
|
+
const props = ce.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
86
|
+
const ids = props.getChildrenOfKind(ts_morph_1.SyntaxKind.Identifier);
|
|
87
|
+
return ids[ids.length - 1]; // Identifier is either the only one present or is the last of 2 so this should fetch it in either scenario
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Validates that a call expression is valid. Will error if the call expression is inappropriately constructed for the configuration function
|
|
91
|
+
* @param ce
|
|
92
|
+
* @param parameterName
|
|
93
|
+
*/
|
|
94
|
+
isValidCallExpression(ce, paramId) {
|
|
95
|
+
if (!paramId) {
|
|
96
|
+
throw Error('No parameter provided to configuration function');
|
|
97
|
+
}
|
|
98
|
+
// Ensure the line of the function call starts with the argument of the configuration function
|
|
99
|
+
const firstId = this.getFirstProp(ce);
|
|
100
|
+
if (firstId?.getText() !== paramId?.getText()) {
|
|
101
|
+
throw Error(`Call expression does not begin with "${paramId.getText()}", instead began with "${firstId.getText()}"`);
|
|
102
|
+
}
|
|
103
|
+
// Verify that the function call is actually a valid function call based on the composer class this will be used with
|
|
104
|
+
const lastId = this.getLastProp(ce);
|
|
105
|
+
const functionName = lastId.getText();
|
|
106
|
+
const nameIsValid = Object.getOwnPropertyNames(this.composerClass.prototype).some((funcName) => {
|
|
107
|
+
return funcName != 'constructor' && functionName.startsWith(funcName);
|
|
108
|
+
});
|
|
109
|
+
if (!nameIsValid) {
|
|
110
|
+
throw Error(`Call expression function does not exist on the object ${paramId.getText()}`);
|
|
111
|
+
}
|
|
112
|
+
// Verify that call expression has the expected number of arguments
|
|
113
|
+
const funcArgs = ce.getFirstDescendantByKind(ts_morph_1.SyntaxKind.SyntaxList)?.getChildren();
|
|
114
|
+
if (!funcArgs) {
|
|
115
|
+
throw Error('Call expression had no arguments at all');
|
|
116
|
+
}
|
|
117
|
+
if (funcArgs.length != 1) {
|
|
118
|
+
throw Error('Call expressions only support a single argument');
|
|
119
|
+
}
|
|
120
|
+
if (funcArgs[0].getKind() != ts_morph_1.SyntaxKind.ObjectLiteralExpression) {
|
|
121
|
+
throw Error('Call expression must have an object as its argument');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns the step number of the step containing a identifier which matches the type of the queried identfier
|
|
126
|
+
*
|
|
127
|
+
* If it cannot find the identifier, it returns -1
|
|
128
|
+
* @param identifier
|
|
129
|
+
* @param data
|
|
130
|
+
*/
|
|
131
|
+
findReferencedIdentifier(identifier) {
|
|
132
|
+
const idName = identifier.getSymbol()?.getName();
|
|
133
|
+
// Identifier index lines up with step index, removed from step object so identifiers are not returned in extracted object
|
|
134
|
+
for (let i = 0; i < this.identifiers.length; i++) {
|
|
135
|
+
const identifier = this.identifiers[i];
|
|
136
|
+
// Maybe there's another way to more accurately identify but this should be fine?
|
|
137
|
+
const name = identifier?.getSymbol()?.getName();
|
|
138
|
+
if (name && idName && name == idName) {
|
|
139
|
+
return i;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return -1;
|
|
143
|
+
}
|
|
144
|
+
getRootIdentifier(prop) {
|
|
145
|
+
const children = prop.getChildrenOfKind(ts_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
146
|
+
if (children.length == 0) {
|
|
147
|
+
const id = prop.getFirstChildByKind(ts_morph_1.SyntaxKind.Identifier);
|
|
148
|
+
if (!id) {
|
|
149
|
+
throw Error('Could not find identifier in property access expression');
|
|
150
|
+
}
|
|
151
|
+
return id;
|
|
152
|
+
}
|
|
153
|
+
return this.getRootIdentifier(children[0]);
|
|
154
|
+
}
|
|
155
|
+
parseValue(valueNode) {
|
|
156
|
+
if (valueNode.getKind() == ts_morph_1.SyntaxKind.ArrayLiteralExpression) {
|
|
157
|
+
const values = [];
|
|
158
|
+
const syntaxList = valueNode.getFirstDescendantByKind(ts_morph_1.SyntaxKind.SyntaxList);
|
|
159
|
+
if (!syntaxList) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const children = syntaxList.getChildren();
|
|
163
|
+
for (const child of children) {
|
|
164
|
+
if (child.getKind() == ts_morph_1.SyntaxKind.CommaToken) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const value = this.parseValue(child);
|
|
168
|
+
values.push(value);
|
|
169
|
+
}
|
|
170
|
+
return values;
|
|
171
|
+
}
|
|
172
|
+
if (valueNode.getKind() == ts_morph_1.SyntaxKind.ObjectLiteralExpression) {
|
|
173
|
+
const objNode = valueNode;
|
|
174
|
+
return this.objNodeToJSON(objNode);
|
|
175
|
+
}
|
|
176
|
+
if (valueNode.getKind() == ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
177
|
+
const propNode = valueNode;
|
|
178
|
+
const identifier = this.getRootIdentifier(propNode);
|
|
179
|
+
const refIdentifierIndex = this.findReferencedIdentifier(identifier);
|
|
180
|
+
if (refIdentifierIndex == -1) {
|
|
181
|
+
throw Error('Step corresponding to property access expression could not be found');
|
|
182
|
+
}
|
|
183
|
+
const parsedValue = valueNode.getText().split('.');
|
|
184
|
+
// Replace it just with a string here. Parsing into a real value will happen in the composer
|
|
185
|
+
return { __references: refIdentifierIndex, __value: parsedValue[parsedValue.length - 1] };
|
|
186
|
+
}
|
|
187
|
+
if (valueNode.getKind() == ts_morph_1.SyntaxKind.TemplateExpression) {
|
|
188
|
+
// console.info(`literal: ${(valueNode as TemplateExpression).getVal}`)
|
|
189
|
+
const templateNode = valueNode;
|
|
190
|
+
const templateValue = [templateNode.getHead().getLiteralText()];
|
|
191
|
+
templateNode.getTemplateSpans().forEach((s) => {
|
|
192
|
+
templateValue.push(this.parseValue(s.getExpression()));
|
|
193
|
+
templateValue.push(s.getLiteral().getLiteralText());
|
|
194
|
+
});
|
|
195
|
+
return { __template: templateValue };
|
|
196
|
+
}
|
|
197
|
+
// A variety of Identifiers. Will be handled here
|
|
198
|
+
// TODO: This is swallowing diagnostics and not handling the case where no data was extracted
|
|
199
|
+
return this.context.extractAst(valueNode)['data'][0]?.getValue();
|
|
200
|
+
}
|
|
201
|
+
getKVPair(prop) {
|
|
202
|
+
const props = prop.getChildren();
|
|
203
|
+
const keyNode = props[0];
|
|
204
|
+
const valueNode = props[2];
|
|
205
|
+
const key = keyNode.getLiteralValue ? keyNode.getLiteralValue() : keyNode.getText();
|
|
206
|
+
const value = this.parseValue(valueNode);
|
|
207
|
+
if (typeof key !== 'undefined' && typeof value !== 'undefined') {
|
|
208
|
+
return { key, value };
|
|
209
|
+
}
|
|
210
|
+
return { key: undefined, value: undefined };
|
|
211
|
+
}
|
|
212
|
+
objNodeToJSON(obj) {
|
|
213
|
+
if (!obj) {
|
|
214
|
+
throw Error('objNodeToJSON received an undefined object node');
|
|
215
|
+
}
|
|
216
|
+
const syntaxList = obj.getFirstDescendantByKind(ts_morph_1.SyntaxKind.SyntaxList);
|
|
217
|
+
if (!syntaxList) {
|
|
218
|
+
throw Error('objNodeToJSON could not find a syntax list in the ObjectLiteralExpression');
|
|
219
|
+
}
|
|
220
|
+
const json = {};
|
|
221
|
+
syntaxList.getChildrenOfKind(ts_morph_1.SyntaxKind.PropertyAssignment).forEach((arg) => {
|
|
222
|
+
const propArg = arg;
|
|
223
|
+
const { key, value } = this.getKVPair(propArg);
|
|
224
|
+
// TODO: What if the value is actually undefined?
|
|
225
|
+
if (key !== undefined && value !== undefined) {
|
|
226
|
+
json[key] = value;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return json;
|
|
230
|
+
}
|
|
231
|
+
getName(node) {
|
|
232
|
+
// This may not be robust but should be a good enough
|
|
233
|
+
const lastProp = this.getLastProp(node);
|
|
234
|
+
return lastProp.getText();
|
|
235
|
+
}
|
|
236
|
+
getConfigFunctionComponents(kind, node) {
|
|
237
|
+
kind;
|
|
238
|
+
const configArgs = node.getArguments();
|
|
239
|
+
if (configArgs.length != 2) {
|
|
240
|
+
throw Error('The plugin must have exactly 2 arguments');
|
|
241
|
+
}
|
|
242
|
+
if (configArgs[0].getKind() != ts_morph_1.SyntaxKind.ObjectLiteralExpression) {
|
|
243
|
+
throw Error("The plugin's first argument was not an object");
|
|
244
|
+
}
|
|
245
|
+
if (configArgs[1].getKind() != ts_morph_1.SyntaxKind.ArrowFunction &&
|
|
246
|
+
configArgs[1].getKind() != ts_morph_1.SyntaxKind.FunctionExpression) {
|
|
247
|
+
throw Error("The plugin's second argument was not a function");
|
|
248
|
+
}
|
|
249
|
+
const objectArg = configArgs[0];
|
|
250
|
+
const configFunction = configArgs[1];
|
|
251
|
+
// TODO: This is swallowing diagnostics and not handling the case where no data was extracted
|
|
252
|
+
const objectArgValue = this.context.extractAst(objectArg)['data'][0]?.getValue();
|
|
253
|
+
if (!('$id' in objectArgValue)) {
|
|
254
|
+
throw Error('No $id defined in first argument');
|
|
255
|
+
}
|
|
256
|
+
const parameters = configFunction.getParameters();
|
|
257
|
+
// Checking the type is parameter is probably redundant but can not hurt
|
|
258
|
+
if (parameters.length != 1 || !parameters[0] || parameters[0].getKind() != ts_morph_1.SyntaxKind.Parameter) {
|
|
259
|
+
throw Error('Configuration function must have an parameter as its only argument');
|
|
260
|
+
}
|
|
261
|
+
const paramId = parameters[0].getChildrenOfKind(ts_morph_1.SyntaxKind.Identifier)[0];
|
|
262
|
+
const block = configFunction.getFirstChildByKind(ts_morph_1.SyntaxKind.Block);
|
|
263
|
+
if (!block) {
|
|
264
|
+
throw Error(`Failed to find block in configuration function`);
|
|
265
|
+
}
|
|
266
|
+
const syntaxList = block.getFirstChildByKind(ts_morph_1.SyntaxKind.SyntaxList);
|
|
267
|
+
if (!syntaxList) {
|
|
268
|
+
throw Error(`Failed to find syntax list in configuration function`);
|
|
269
|
+
}
|
|
270
|
+
return { paramId, syntaxList, objectArgValue };
|
|
271
|
+
}
|
|
272
|
+
extractCallExpression(node, paramId) {
|
|
273
|
+
const callExpressions = node.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
274
|
+
if (callExpressions.length == 0) {
|
|
275
|
+
throw Error(`Expression statement did not have any call expression`);
|
|
276
|
+
}
|
|
277
|
+
if (callExpressions.length > 1) {
|
|
278
|
+
throw Error(`Found more than one call expression inside of an expression statement`);
|
|
279
|
+
}
|
|
280
|
+
const callExpression = callExpressions[0];
|
|
281
|
+
this.isValidCallExpression(callExpression, paramId);
|
|
282
|
+
return callExpression;
|
|
283
|
+
}
|
|
284
|
+
extractConfigFunction(kind, // Name of function for now
|
|
285
|
+
logger) {
|
|
286
|
+
try {
|
|
287
|
+
return this.extractConfigFunctionUnsafe(kind, logger);
|
|
288
|
+
}
|
|
289
|
+
catch (e) {
|
|
290
|
+
console.error('Could not extract configuration function: ', e);
|
|
291
|
+
// swallows error, maybe fully re-echo but probably should just swallow silently to behave as expected
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Returns a single entity of the kind specified which contains all data of nodes within the configuration function
|
|
297
|
+
*
|
|
298
|
+
* Will attempt to generalize this for use by flow team
|
|
299
|
+
* @param kind
|
|
300
|
+
* @param node
|
|
301
|
+
* @param context
|
|
302
|
+
* @returns
|
|
303
|
+
*/
|
|
304
|
+
extractConfigFunctionUnsafe(kind, // Name of function for now,
|
|
305
|
+
logger) {
|
|
306
|
+
// If this node is not the correct kind, return undefined. Some other extractor will handle it
|
|
307
|
+
const name = (0, CallExpression_1.getCallExpressionName)(this.rootNode).toLowerCase();
|
|
308
|
+
if (name !== kind) {
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
// Below here we assume anything that makes it this far is being extracted by the right type of extractor so failing to get any other part will result in an error stopping compilation instead
|
|
312
|
+
const { paramId, syntaxList, objectArgValue } = this.getConfigFunctionComponents(kind, this.rootNode);
|
|
313
|
+
const config = { inputObject: objectArgValue, configEntries: {} };
|
|
314
|
+
const data = config.configEntries;
|
|
315
|
+
let stepNumber = 0;
|
|
316
|
+
syntaxList.getChildren().forEach((statement) => {
|
|
317
|
+
try {
|
|
318
|
+
switch (statement.getKind()) {
|
|
319
|
+
case ts_morph_1.SyntaxKind.ExpressionStatement: {
|
|
320
|
+
/**
|
|
321
|
+
* (param) => {
|
|
322
|
+
* param.foo({arg: 'value'}) <- Expression statement
|
|
323
|
+
* }
|
|
324
|
+
*/
|
|
325
|
+
// This formatting of casting is used throughout the class. Try to keep casting close to where the value is determined and then save it to a cast variable and use
|
|
326
|
+
// that below. This prevents accidentally using a variable as multiple different types by forgetting to cast and also keeps casting near where type is determined
|
|
327
|
+
// so its more clear why it is being cast
|
|
328
|
+
const ce = this.extractCallExpression(statement, paramId);
|
|
329
|
+
data[stepNumber++] = {
|
|
330
|
+
name: this.getName(ce),
|
|
331
|
+
info: this.objNodeToJSON(ce.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)),
|
|
332
|
+
};
|
|
333
|
+
this.identifiers.push(null);
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
case ts_morph_1.SyntaxKind.VariableStatement: {
|
|
337
|
+
/**
|
|
338
|
+
* (param) => {
|
|
339
|
+
* const output = param.foo({arg: 'value'}) <- Variable statement
|
|
340
|
+
* }
|
|
341
|
+
*/
|
|
342
|
+
const ce = this.extractCallExpression(statement, paramId);
|
|
343
|
+
const variableDeclaration = statement.getFirstDescendantByKind(ts_morph_1.SyntaxKind.VariableDeclaration);
|
|
344
|
+
if (!variableDeclaration) {
|
|
345
|
+
throw Error('Could not find variable declaration in variable statement');
|
|
346
|
+
}
|
|
347
|
+
const assignment = variableDeclaration.getChildren(); // Format: identifier, =, value
|
|
348
|
+
const identifier = assignment[0];
|
|
349
|
+
const value = assignment[2]; // Already been validated above to be a valid call expression
|
|
350
|
+
data[stepNumber++] = {
|
|
351
|
+
name: this.getName(ce),
|
|
352
|
+
info: this.objNodeToJSON(value.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)),
|
|
353
|
+
};
|
|
354
|
+
this.identifiers.push(identifier);
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
case ts_morph_1.SyntaxKind.MultiLineCommentTrivia:
|
|
358
|
+
/** This is a multiline comment */
|
|
359
|
+
break;
|
|
360
|
+
case ts_morph_1.SyntaxKind.SingleLineCommentTrivia:
|
|
361
|
+
// This is a single line comment
|
|
362
|
+
break;
|
|
363
|
+
default:
|
|
364
|
+
throw Error(`Found an invalid node in the configuration function block, found: ${statement?.getKindName() ? statement.getKindName() : 'Kind name undefined'}`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
catch (e) {
|
|
368
|
+
// Provides easy context w/o having to worry about having blah.getText() in all errors
|
|
369
|
+
logger.error(`Encountered an error while parsing statement: ${statement.getText()}`);
|
|
370
|
+
throw e;
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
return new ConfigurationFunctionEntityData(config, this.rootNode);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
exports.ConfigurationFunctionExtractor = ConfigurationFunctionExtractor;
|
|
377
|
+
//# sourceMappingURL=ConfigurationFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigurationFunction.js","sourceRoot":"","sources":["../../../src/plugins/util/ConfigurationFunction.ts"],"names":[],"mappings":";;;AACA,uCAYiB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,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAe,CAAA;wBAC9C,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAmB,CAAA,CAAC,6DAA6D;wBAE3G,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG;4BACjB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;4BACtB,IAAI,EAAE,IAAI,CAAC,aAAa,CACpB,KAAK,CAAC,wBAAwB,CAAC,qBAAU,CAAC,uBAAuB,CAAC,CACrE;yBACJ,CAAA;wBACD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;wBACjC,MAAK;oBACT,CAAC;oBACD,KAAK,qBAAU,CAAC,sBAAsB;wBAClC,kCAAkC;wBAClC,MAAK;oBACT,KAAK,qBAAU,CAAC,uBAAuB;wBACnC,gCAAgC;wBAChC,MAAK;oBACT;wBACI,MAAM,KAAK,CACP,qEACI,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,qBACzD,EAAE,CACL,CAAA;gBACT,CAAC;YACL,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,sFAAsF;gBACtF,MAAM,CAAC,KAAK,CAAC,iDAAiD,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;gBACpF,MAAM,CAAC,CAAA;YACX,CAAC;QACL,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,+BAA+B,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IACrE,CAAC;CACJ;AAlZD,wEAkZC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as ts from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the property assignment with the specified name and subpath from the given node.
|
|
4
|
+
* @param node - The node to search for the property assignment.
|
|
5
|
+
* @param property - The name of the property assignment to retrieve.
|
|
6
|
+
* @param subPath - Optional subpath to navigate within the property assignment.
|
|
7
|
+
* @returns The property assignment node if found, otherwise undefined.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getPropertyAssignment(node: ts.Node | undefined, property: string, ...subPath: string[]): ts.PropertyAssignment | undefined;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getPropertyAssignment = getPropertyAssignment;
|
|
27
|
+
const ts = __importStar(require("ts-morph"));
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the property assignment with the specified name and subpath from the given node.
|
|
30
|
+
* @param node - The node to search for the property assignment.
|
|
31
|
+
* @param property - The name of the property assignment to retrieve.
|
|
32
|
+
* @param subPath - Optional subpath to navigate within the property assignment.
|
|
33
|
+
* @returns The property assignment node if found, otherwise undefined.
|
|
34
|
+
*/
|
|
35
|
+
function getPropertyAssignment(node, property, ...subPath) {
|
|
36
|
+
let current = node
|
|
37
|
+
?.asKind(ts.SyntaxKind.ObjectLiteralExpression)
|
|
38
|
+
// get the property assignment with the specified name
|
|
39
|
+
?.getProperty((p) => hasPropertyAssignment(p, property))
|
|
40
|
+
?.asKind(ts.SyntaxKind.PropertyAssignment);
|
|
41
|
+
for (const pathPart of subPath) {
|
|
42
|
+
current = current
|
|
43
|
+
?.getInitializerIfKind(ts.SyntaxKind.ObjectLiteralExpression)
|
|
44
|
+
// get the property assignment with the specified name
|
|
45
|
+
?.getProperty((p) => hasPropertyAssignment(p, pathPart))
|
|
46
|
+
?.asKind(ts.SyntaxKind.PropertyAssignment);
|
|
47
|
+
}
|
|
48
|
+
return current;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Checks if the given property assignment has the specified path.
|
|
52
|
+
* @param property - The property assignment to check.
|
|
53
|
+
* @param path - The path to compare against.
|
|
54
|
+
* @returns True if the property assignment has the specified path, otherwise false.
|
|
55
|
+
*/
|
|
56
|
+
function hasPropertyAssignment(property, path) {
|
|
57
|
+
const child = property?.getChildren().find((c) => ts.Node.isStringLiteral(c) || ts.Node.isIdentifier(c));
|
|
58
|
+
return child?.getSymbol()?.getEscapedName() === path;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=ObjectLiteral.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectLiteral.js","sourceRoot":"","sources":["../../../src/plugins/util/ObjectLiteral.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AASA,sDAgBC;AAzBD,6CAA8B;AAE9B;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,IAAyB,EAAE,QAAgB,EAAE,GAAG,OAAiB;IACnG,IAAI,OAAO,GAAG,IAAI;QACd,EAAE,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,uBAAuB,CAAC;QAC/C,sDAAsD;QACtD,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAqB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QACxD,EAAE,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAA;IAE9C,KAAK,MAAM,QAAQ,IAAI,OAAO,EAAE,CAAC;QAC7B,OAAO,GAAG,OAAO;YACb,EAAE,oBAAoB,CAAC,EAAE,CAAC,UAAU,CAAC,uBAAuB,CAAC;YAC7D,sDAAsD;YACtD,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAqB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;YACxD,EAAE,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAA;IAClD,CAAC;IAED,OAAO,OAAO,CAAA;AAClB,CAAC;AAED;;;;;GAKG;AACH,SAAS,qBAAqB,CAAC,QAAiD,EAAE,IAAY;IAC1F,MAAM,KAAK,GAAG,QAAQ,EAAE,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;IACxG,OAAO,KAAK,EAAE,SAAS,EAAE,EAAE,cAAc,EAAE,KAAK,IAAI,CAAA;AACxD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./CallExpression"), exports);
|
|
18
|
+
__exportStar(require("./CodeTransformation"), exports);
|
|
19
|
+
__exportStar(require("./ObjectLiteral"), exports);
|
|
20
|
+
__exportStar(require("./ConfigurationFunction"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,uDAAoC;AACpC,kDAA+B;AAC/B,0DAAuC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Data, Document, File } from '../plugins/behaviors';
|
|
2
|
+
import { Logger } from '@servicenow/sdk-project';
|
|
3
|
+
export declare function inspect(val: unknown, depth?: number): string;
|
|
4
|
+
export declare function debugData(data: ({
|
|
5
|
+
data: unknown;
|
|
6
|
+
} | Data)[], logger: Logger, message?: string): void;
|
|
7
|
+
export declare function debugDocuments(documents: Document[], logger: Logger, message?: string): void;
|
|
8
|
+
export declare function debugFiles(files: File[], logger: Logger, message?: string): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inspect = inspect;
|
|
4
|
+
exports.debugData = debugData;
|
|
5
|
+
exports.debugDocuments = debugDocuments;
|
|
6
|
+
exports.debugFiles = debugFiles;
|
|
7
|
+
const util_1 = require("util");
|
|
8
|
+
const behaviors_1 = require("../plugins/behaviors");
|
|
9
|
+
function inspect(val, depth = 2) {
|
|
10
|
+
return (0, util_1.inspect)(val, {
|
|
11
|
+
colors: true,
|
|
12
|
+
compact: false,
|
|
13
|
+
depth,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function debugData(data, logger, message = 'DATA:') {
|
|
17
|
+
logger.info(message);
|
|
18
|
+
logger.info(inspect(data.map((d) => {
|
|
19
|
+
if (d instanceof behaviors_1.Data) {
|
|
20
|
+
return d.getValue();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return d;
|
|
24
|
+
}
|
|
25
|
+
}), 5));
|
|
26
|
+
}
|
|
27
|
+
function debugDocuments(documents, logger, message = 'DOCUMENTS:') {
|
|
28
|
+
logger.info(message);
|
|
29
|
+
logger.info(inspect(documents.map((d) => {
|
|
30
|
+
const { node, ...rest } = d;
|
|
31
|
+
node;
|
|
32
|
+
return rest;
|
|
33
|
+
}), 5));
|
|
34
|
+
}
|
|
35
|
+
function debugFiles(files, logger, message = 'FILES:') {
|
|
36
|
+
logger.info(message);
|
|
37
|
+
logger.info(inspect(files, 5));
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=Debug.js.map
|