@servicenow/sdk-build-plugins 2.1.4 → 2.2.2
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/AttachmentPlugin.d.ts +6 -7
- package/dist/AttachmentPlugin.js +8 -6
- package/dist/AttachmentPlugin.js.map +1 -1
- package/dist/BusinessRulePlugin.d.ts +5 -5
- package/dist/BusinessRulePlugin.js +4 -4
- package/dist/BusinessRulePlugin.js.map +1 -1
- package/dist/CrossScopePrivilegePlugin.d.ts +5 -5
- package/dist/CrossScopePrivilegePlugin.js +1 -2
- package/dist/CrossScopePrivilegePlugin.js.map +1 -1
- package/dist/DefaultPlugin.d.ts +19 -11
- package/dist/DefaultPlugin.js +23 -51
- package/dist/DefaultPlugin.js.map +1 -1
- package/dist/HtmlTemplatePlugin.d.ts +2 -2
- package/dist/HtmlTemplatePlugin.js +3 -26
- package/dist/HtmlTemplatePlugin.js.map +1 -1
- package/dist/IdPlugin.d.ts +5 -4
- package/dist/IdPlugin.js +5 -9
- package/dist/IdPlugin.js.map +1 -1
- package/dist/JsonPlugin.d.ts +8 -3
- package/dist/JsonPlugin.js +6 -11
- package/dist/JsonPlugin.js.map +1 -1
- package/dist/ListPlugin.d.ts +6 -7
- package/dist/ListPlugin.js +17 -19
- package/dist/ListPlugin.js.map +1 -1
- package/dist/NowConfigPlugin.d.ts +1 -1
- package/dist/NowConfigPlugin.js +5 -31
- package/dist/NowConfigPlugin.js.map +1 -1
- package/dist/PackageJsonPlugin.d.ts +1 -1
- package/dist/PackageJsonPlugin.js +1 -1
- package/dist/PackageJsonPlugin.js.map +1 -1
- package/dist/PropertyPlugin.d.ts +5 -66
- package/dist/PropertyPlugin.js +6 -12
- package/dist/PropertyPlugin.js.map +1 -1
- package/dist/ScriptTemplatePlugin.d.ts +1 -1
- package/dist/ScriptTemplatePlugin.js +5 -5
- package/dist/ScriptTemplatePlugin.js.map +1 -1
- package/dist/ServerModulePlugin.d.ts +5 -6
- package/dist/ServerModulePlugin.js +10 -39
- package/dist/ServerModulePlugin.js.map +1 -1
- package/dist/UserPreferencePlugin.d.ts +1 -1
- package/dist/aclAndRole/AclPlugin.d.ts +44 -28
- package/dist/aclAndRole/AclPlugin.js +30 -33
- package/dist/aclAndRole/AclPlugin.js.map +1 -1
- package/dist/aclAndRole/RolePlugin.d.ts +5 -6
- package/dist/aclAndRole/RolePlugin.js +6 -7
- package/dist/aclAndRole/RolePlugin.js.map +1 -1
- package/dist/aclAndRole/Util.js +7 -30
- package/dist/aclAndRole/Util.js.map +1 -1
- package/dist/app/ApplicationMenuPlugin.d.ts +5 -5
- package/dist/app/ApplicationMenuPlugin.js +2 -3
- package/dist/app/ApplicationMenuPlugin.js.map +1 -1
- package/dist/atf/TestPlugin.d.ts +3 -3
- package/dist/atf/TestPlugin.js +1 -1
- package/dist/atf/TestPlugin.js.map +1 -1
- package/dist/db/ColumnPlugins.d.ts +85 -85
- package/dist/db/ColumnPlugins.js +17 -19
- package/dist/db/ColumnPlugins.js.map +1 -1
- package/dist/db/DocumentationPlugin.d.ts +6 -6
- package/dist/db/DocumentationPlugin.js +17 -49
- package/dist/db/DocumentationPlugin.js.map +1 -1
- package/dist/db/RecordPlugin.d.ts +7 -101
- package/dist/db/RecordPlugin.js +25 -24
- package/dist/db/RecordPlugin.js.map +1 -1
- package/dist/db/TablePlugin.d.ts +9 -610
- package/dist/db/TablePlugin.js +185 -84
- package/dist/db/TablePlugin.js.map +1 -1
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.d.ts +0 -2
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js +17 -18
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js.map +1 -1
- package/dist/scriptedRESTAPI/RESTSerializationUtils.d.ts +1 -3
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js +0 -1
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js.map +1 -1
- package/dist/scriptedRESTAPI/RestApiPlugin.d.ts +3 -4
- package/dist/scriptedRESTAPI/RestApiPlugin.js +7 -33
- package/dist/scriptedRESTAPI/RestApiPlugin.js.map +1 -1
- package/dist/scriptedRESTAPI/RestUtils.d.ts +1 -10
- package/dist/scriptedRESTAPI/RestUtils.js +11 -35
- package/dist/scriptedRESTAPI/RestUtils.js.map +1 -1
- package/dist/scripts/ClientScriptPlugin.d.ts +3 -4
- package/dist/scripts/ClientScriptPlugin.js +11 -37
- package/dist/scripts/ClientScriptPlugin.js.map +1 -1
- package/dist/uxf/ExperiencePlugin.d.ts +2 -2
- package/dist/uxf/RoutesPlugin.d.ts +2 -2
- package/dist/uxf/RoutesPlugin.js +2 -3
- package/dist/uxf/RoutesPlugin.js.map +1 -1
- package/dist/uxf/tectonicIdGenerator.d.ts +1 -1
- package/dist/uxf/tectonicIdGenerator.js +5 -28
- package/dist/uxf/tectonicIdGenerator.js.map +1 -1
- package/package.json +6 -8
- package/src/AttachmentPlugin.ts +5 -7
- package/src/BusinessRulePlugin.ts +12 -6
- package/src/CrossScopePrivilegePlugin.ts +2 -3
- package/src/DefaultPlugin.ts +22 -26
- package/src/HtmlTemplatePlugin.ts +2 -2
- package/src/IdPlugin.ts +6 -10
- package/src/JsonPlugin.ts +7 -12
- package/src/ListPlugin.ts +20 -22
- package/src/NowConfigPlugin.ts +10 -13
- package/src/PackageJsonPlugin.ts +1 -1
- package/src/PropertyPlugin.ts +8 -14
- package/src/ScriptTemplatePlugin.ts +1 -1
- package/src/ServerModulePlugin.ts +15 -20
- package/src/aclAndRole/AclPlugin.ts +37 -6
- package/src/aclAndRole/RolePlugin.ts +7 -9
- package/src/aclAndRole/Util.ts +2 -2
- package/src/app/ApplicationMenuPlugin.ts +3 -4
- package/src/atf/TestPlugin.ts +3 -3
- package/src/db/ColumnPlugins.ts +20 -22
- package/src/db/DocumentationPlugin.ts +7 -41
- package/src/db/RecordPlugin.ts +23 -26
- package/src/db/TablePlugin.ts +222 -115
- package/src/scriptedRESTAPI/RESTDeserializationUtils.ts +18 -19
- package/src/scriptedRESTAPI/RESTSerializationUtils.ts +1 -1
- package/src/scriptedRESTAPI/RestApiPlugin.ts +15 -18
- package/src/scriptedRESTAPI/RestUtils.ts +7 -7
- package/src/scripts/ClientScriptPlugin.ts +10 -12
- package/src/uxf/RoutesPlugin.ts +2 -3
- package/src/uxf/tectonicIdGenerator.ts +3 -6
package/dist/db/TablePlugin.js
CHANGED
|
@@ -23,24 +23,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.dynamic_value_mapping = exports.ColumnSchemaBootstrapAttributes = exports.TableSchemaBootstrapAttributes = exports.SysDocumentation = exports.TableSchemaBootstrap = exports.TableSchemaFull = exports.callerAccess = void 0;
|
|
27
|
-
exports.transformColumnData = transformColumnData;
|
|
28
|
-
exports.SysNumber = SysNumber;
|
|
29
26
|
exports.generateColumnExpression = generateColumnExpression;
|
|
30
27
|
exports.createObjectExpression = createObjectExpression;
|
|
31
|
-
exports.factoryCreateValue = factoryCreateValue;
|
|
32
|
-
exports.getCallExpressionFromType = getCallExpressionFromType;
|
|
33
28
|
const db_1 = require("@servicenow/sdk-core/runtime/db");
|
|
34
29
|
const sdk_build_core_1 = require("@servicenow/sdk-build-core");
|
|
35
30
|
const xmlbuilder2_1 = require("xmlbuilder2");
|
|
36
31
|
const lodash_1 = require("lodash");
|
|
37
32
|
const zod_1 = require("zod");
|
|
38
33
|
const RecordPlugin_1 = require("./RecordPlugin");
|
|
39
|
-
const ts_morph_1 = require("ts-morph");
|
|
40
34
|
const sdk_project_1 = require("@servicenow/sdk-project");
|
|
41
35
|
const ScriptTemplatePlugin_1 = require("../ScriptTemplatePlugin");
|
|
42
36
|
const os = __importStar(require("os"));
|
|
43
|
-
const path = __importStar(require("path"));
|
|
44
37
|
const DBUtils_1 = require("./DBUtils");
|
|
45
38
|
const ServerModulePlugin_1 = require("../ServerModulePlugin");
|
|
46
39
|
/**
|
|
@@ -51,9 +44,9 @@ const ServerModulePlugin_1 = require("../ServerModulePlugin");
|
|
|
51
44
|
* - `restricted`: 2
|
|
52
45
|
*
|
|
53
46
|
*/
|
|
54
|
-
|
|
47
|
+
const callerAccess = ['none', 'tracking', 'restricted'];
|
|
55
48
|
// Basic info needed for table references
|
|
56
|
-
|
|
49
|
+
const TableSchemaFull = zod_1.z.object({
|
|
57
50
|
/** lowercase, one word name. Numbers, letters and underscores only */
|
|
58
51
|
name: zod_1.z.string(),
|
|
59
52
|
/** Object literal of column names with <type>Column() calls as values.
|
|
@@ -85,7 +78,7 @@ exports.TableSchemaFull = zod_1.z.object({
|
|
|
85
78
|
.union([zod_1.z.literal('package_private'), zod_1.z.literal('public')])
|
|
86
79
|
.optional()
|
|
87
80
|
.default('public'),
|
|
88
|
-
caller_access: zod_1.z.enum(
|
|
81
|
+
caller_access: zod_1.z.enum(callerAccess).optional(),
|
|
89
82
|
/** Array of read, update, create, delete actions (['read', 'update',...])*/
|
|
90
83
|
actions: zod_1.z
|
|
91
84
|
.array(zod_1.z.union([zod_1.z.literal('read'), zod_1.z.literal('update'), zod_1.z.literal('delete'), zod_1.z.literal('create')]))
|
|
@@ -105,7 +98,10 @@ exports.TableSchemaFull = zod_1.z.object({
|
|
|
105
98
|
.array(zod_1.z.object({
|
|
106
99
|
name: zod_1.z.string(),
|
|
107
100
|
unique: zod_1.z.boolean(),
|
|
108
|
-
element: zod_1.z
|
|
101
|
+
element: zod_1.z
|
|
102
|
+
.string()
|
|
103
|
+
.or(zod_1.z.array(zod_1.z.string()))
|
|
104
|
+
.transform((el) => ((0, lodash_1.isArray)(el) ? el : [el])),
|
|
109
105
|
}))
|
|
110
106
|
.optional(),
|
|
111
107
|
});
|
|
@@ -160,7 +156,7 @@ const DBObjectIncomingAttributes = zod_1.z.object({
|
|
|
160
156
|
caller_access: RecordPlugin_1.TextNumberSchema.or(IntFromString)
|
|
161
157
|
.transform((val) => {
|
|
162
158
|
if (val) {
|
|
163
|
-
return
|
|
159
|
+
return callerAccess[val];
|
|
164
160
|
}
|
|
165
161
|
return;
|
|
166
162
|
})
|
|
@@ -174,7 +170,7 @@ const DBObjectIncomingAttributes = zod_1.z.object({
|
|
|
174
170
|
access: RecordPlugin_1.TextStringSchema.or(zod_1.z.string()).optional(),
|
|
175
171
|
});
|
|
176
172
|
// Attributes in the element='collection' tag of bootstrap xml
|
|
177
|
-
|
|
173
|
+
const TableSchemaBootstrap = zod_1.z.object({
|
|
178
174
|
name: zod_1.z.string(),
|
|
179
175
|
extends: zod_1.z.string().optional(),
|
|
180
176
|
label: zod_1.z.string().max(80, 'Cannot exceed 80 characters').or(zod_1.z.array(zod_1.z.any())).optional(),
|
|
@@ -194,7 +190,7 @@ exports.TableSchemaBootstrap = zod_1.z.object({
|
|
|
194
190
|
.union([zod_1.z.literal('public'), zod_1.z.literal('package_private')])
|
|
195
191
|
.optional()
|
|
196
192
|
.default('public'),
|
|
197
|
-
caller_access: zod_1.z.enum(
|
|
193
|
+
caller_access: zod_1.z.enum(callerAccess).default('none').optional(),
|
|
198
194
|
actions: zod_1.z
|
|
199
195
|
.array(zod_1.z.union([zod_1.z.literal('read'), zod_1.z.literal('update'), zod_1.z.literal('delete'), zod_1.z.literal('create')]))
|
|
200
196
|
.default(['read'])
|
|
@@ -212,12 +208,12 @@ exports.TableSchemaBootstrap = zod_1.z.object({
|
|
|
212
208
|
.default({})
|
|
213
209
|
.optional(),
|
|
214
210
|
});
|
|
215
|
-
const TableSchemaBootstrapIncoming =
|
|
211
|
+
const TableSchemaBootstrapIncoming = TableSchemaBootstrap.omit({ actions: true }).extend({
|
|
216
212
|
caller_access: zod_1.z
|
|
217
213
|
.union([zod_1.z.literal(0), zod_1.z.literal(1), zod_1.z.literal(2)])
|
|
218
214
|
.transform((val) => {
|
|
219
215
|
if (val) {
|
|
220
|
-
return
|
|
216
|
+
return callerAccess[val];
|
|
221
217
|
}
|
|
222
218
|
return;
|
|
223
219
|
})
|
|
@@ -239,7 +235,7 @@ const DBObjectIncoming = zod_1.z.object({
|
|
|
239
235
|
'@_table': zod_1.z.literal('sys_db_object'),
|
|
240
236
|
sys_db_object: zod_1.z.record(zod_1.z.any()),
|
|
241
237
|
});
|
|
242
|
-
|
|
238
|
+
const SysDocumentation = zod_1.z.object({
|
|
243
239
|
sys_documentation: zod_1.z.object({
|
|
244
240
|
element: RecordPlugin_1.TextStringSchema.optional(),
|
|
245
241
|
label: RecordPlugin_1.TextStringSchema.optional(),
|
|
@@ -254,7 +250,7 @@ exports.SysDocumentation = zod_1.z.object({
|
|
|
254
250
|
}),
|
|
255
251
|
});
|
|
256
252
|
// Attributes from element=table in bootstrap.xml
|
|
257
|
-
|
|
253
|
+
const TableSchemaBootstrapAttributes = zod_1.z
|
|
258
254
|
.object({
|
|
259
255
|
'@_name': zod_1.z.string(),
|
|
260
256
|
'@_extends': zod_1.z.string().optional(),
|
|
@@ -302,11 +298,19 @@ exports.TableSchemaBootstrapAttributes = zod_1.z
|
|
|
302
298
|
const IndexSchemaBootstrapAttributes = zod_1.z.object({
|
|
303
299
|
'@_name': zod_1.z.string(),
|
|
304
300
|
'@_unique': BooleanFromString,
|
|
305
|
-
element: zod_1.z
|
|
301
|
+
element: zod_1.z
|
|
302
|
+
.object({ '@_name': zod_1.z.string() })
|
|
303
|
+
.or(zod_1.z.array(zod_1.z.object({
|
|
306
304
|
'@_name': zod_1.z.string(),
|
|
305
|
+
})))
|
|
306
|
+
.transform((val) => {
|
|
307
|
+
if ((0, lodash_1.isArray)(val)) {
|
|
308
|
+
return val;
|
|
309
|
+
}
|
|
310
|
+
return [val];
|
|
307
311
|
}),
|
|
308
312
|
});
|
|
309
|
-
|
|
313
|
+
const ColumnSchemaBootstrapAttributes = TableSchemaBootstrapAttributes.omit({ '@_extends': true })
|
|
310
314
|
.extend({
|
|
311
315
|
'@_choice': zod_1.z.coerce.number().optional(),
|
|
312
316
|
'@_active': BooleanFromString,
|
|
@@ -346,10 +350,10 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
346
350
|
// TODO: Cast to `any` is temporary workaround for the circular nature of Table entities
|
|
347
351
|
CallExpression: (node, context) => {
|
|
348
352
|
const result = (0, sdk_build_core_1.extractCallExpression)(db_1.Table, 'table', node, context, (table) => table.name);
|
|
349
|
-
if (!result.handled || !
|
|
353
|
+
if (!result.handled || !result.data) {
|
|
350
354
|
return result;
|
|
351
355
|
}
|
|
352
|
-
const data = result.data
|
|
356
|
+
const data = result.data;
|
|
353
357
|
const diagnostics = result.diagnostics;
|
|
354
358
|
const scopeName = context.app.config.scope;
|
|
355
359
|
const scopeRegex = new RegExp(`^${scopeName}_`);
|
|
@@ -362,7 +366,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
362
366
|
diagnostics.push(new sdk_build_core_1.FluentDiagnostic(tableName.getNode(), `Table name must only contain lowercase letters, numbers, and underscores and end with a letter or number`));
|
|
363
367
|
}
|
|
364
368
|
if (!scopeMatches) {
|
|
365
|
-
const nameNode = tableName.getNode().asKindOrThrow(
|
|
369
|
+
const nameNode = tableName.getNode().asKindOrThrow(sdk_project_1.ts.SyntaxKind.StringLiteral);
|
|
366
370
|
if (nameNode.getParent().getKindName() !== 'AsExpression') {
|
|
367
371
|
diagnostics.push(new sdk_build_core_1.FluentDiagnostic(tableName.getNode(), `'name' property must start with scope prefix '${scopeName}'`));
|
|
368
372
|
}
|
|
@@ -371,7 +375,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
371
375
|
}
|
|
372
376
|
}
|
|
373
377
|
const schema = data.getProperty('schema');
|
|
374
|
-
const schemaNode = schema.getNode().asKindOrThrow(
|
|
378
|
+
const schemaNode = schema.getNode().asKindOrThrow(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression);
|
|
375
379
|
for (const columnName in schema.getValue()) {
|
|
376
380
|
const columnNode = schemaNode.getPropertyOrThrow(columnName);
|
|
377
381
|
if (!ignoreColumnNameCheck &&
|
|
@@ -384,7 +388,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
384
388
|
diagnostics.push(new sdk_build_core_1.FluentDiagnostic(columnNode, `Column name must only contain lowercase letters, numbers, and underscores`));
|
|
385
389
|
}
|
|
386
390
|
}
|
|
387
|
-
const declaration = node.getParentIfKind(
|
|
391
|
+
const declaration = node.getParentIfKind(sdk_project_1.ts.SyntaxKind.VariableDeclaration);
|
|
388
392
|
if (!declaration ||
|
|
389
393
|
!declaration.isExported() ||
|
|
390
394
|
!declaration.isNamedExport() ||
|
|
@@ -392,7 +396,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
392
396
|
diagnostics.push(new sdk_build_core_1.FluentDiagnostic(node, `Table definition should be exported as a named export with the name '${tableName.getValue()}'`, { level: sdk_project_1.Diagnostic.Level.Warn }));
|
|
393
397
|
}
|
|
394
398
|
diagnostics.push(...(0, DBUtils_1.getLabelDiagnostics)(data));
|
|
395
|
-
return { handled: true, data
|
|
399
|
+
return { handled: true, data, diagnostics };
|
|
396
400
|
},
|
|
397
401
|
},
|
|
398
402
|
},
|
|
@@ -401,7 +405,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
401
405
|
let dbObjectData = {};
|
|
402
406
|
const bootstrapDatabaseXML = BootstrapDatabaseElement.safeParse(xml.data['database']);
|
|
403
407
|
if (bootstrapDatabaseXML.success) {
|
|
404
|
-
const data =
|
|
408
|
+
const data = TableSchemaBootstrapAttributes.parse(bootstrapDatabaseXML.data.element);
|
|
405
409
|
Object.entries(data).forEach(([key, value]) => {
|
|
406
410
|
if (key.startsWith('@_')) {
|
|
407
411
|
bootstrapData[key.substring(2)] = value;
|
|
@@ -429,7 +433,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
429
433
|
return;
|
|
430
434
|
}
|
|
431
435
|
if (table === 'sys_documentation') {
|
|
432
|
-
const data =
|
|
436
|
+
const data = SysDocumentation.parse(record_update[table]).sys_documentation;
|
|
433
437
|
return new sdk_build_core_1.XmlData({
|
|
434
438
|
table: table,
|
|
435
439
|
id: record_update[table][table]['sys_id']?.['#text'] ?? (0, sdk_build_core_1.GUID)(),
|
|
@@ -446,7 +450,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
446
450
|
if (bootstrapDatabaseXML.success && bootstrapDatabaseXML.data.element['element']) {
|
|
447
451
|
const element = bootstrapDatabaseXML.data.element['element'];
|
|
448
452
|
const elementsArray = (0, lodash_1.isArray)(element) ? element : [element];
|
|
449
|
-
columns.push(...zod_1.z.array(
|
|
453
|
+
columns.push(...zod_1.z.array(ColumnSchemaBootstrapAttributes).parse(elementsArray));
|
|
450
454
|
columns.forEach((element) => {
|
|
451
455
|
if (element.choice && !(0, lodash_1.isEmpty)(element.choice)) {
|
|
452
456
|
element['choice_elements'] = {};
|
|
@@ -472,7 +476,10 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
472
476
|
if (idxData.success) {
|
|
473
477
|
idxElements.push({
|
|
474
478
|
name: idxData.data['@_name'],
|
|
475
|
-
element: idxData.data.element
|
|
479
|
+
element: idxData.data.element.reduce((arr, curr) => {
|
|
480
|
+
arr.push(curr['@_name']);
|
|
481
|
+
return arr;
|
|
482
|
+
}, []),
|
|
476
483
|
unique: idxData.data['@_unique'] ?? false,
|
|
477
484
|
});
|
|
478
485
|
}
|
|
@@ -487,7 +494,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
487
494
|
table(entity, context) {
|
|
488
495
|
const node = entity.getNode();
|
|
489
496
|
const data = entity.getValue();
|
|
490
|
-
const table =
|
|
497
|
+
const table = TableSchemaFull.parse(data);
|
|
491
498
|
const composeData = compose(table);
|
|
492
499
|
const { columnData, documentation } = composeColumns(table.schema, context, table.name, table.display);
|
|
493
500
|
composeData['columns'] = columnData;
|
|
@@ -554,11 +561,10 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
554
561
|
sourceFile: (0, sdk_build_core_1.getOrCreateEntitySourceFile)(context, parsedBoostrapData.data.name),
|
|
555
562
|
moduleSpecifier: '@servicenow/sdk/core',
|
|
556
563
|
exportName: parsedBoostrapData.data.name,
|
|
557
|
-
}, db_1.Table, {}).getInitializerIfKindOrThrow(
|
|
564
|
+
}, db_1.Table, {}).getInitializerIfKindOrThrow(sdk_project_1.ts.SyntaxKind.CallExpression));
|
|
558
565
|
},
|
|
559
566
|
record(document, context) {
|
|
560
|
-
if (document.data?.['table'] !== 'sys_documentation'
|
|
561
|
-
document.data?.['table'] !== 'ua_table_licensing_config') {
|
|
567
|
+
if (document.data?.['table'] !== 'sys_documentation') {
|
|
562
568
|
return;
|
|
563
569
|
}
|
|
564
570
|
return (0, sdk_build_core_1.linkDocument)(document, (0, sdk_build_core_1.generateCallExpression)(context, (0, sdk_build_core_1.getOrCreateEntitySourceFile)(context, `${document.data?.['data'].name}`), '@servicenow/sdk/core', db_1.Record, { $id: document.guid }));
|
|
@@ -598,7 +604,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
598
604
|
return false;
|
|
599
605
|
}
|
|
600
606
|
const [args] = document.node.getArguments();
|
|
601
|
-
if (!
|
|
607
|
+
if (!sdk_project_1.ts.Node.isObjectLiteralExpression(args)) {
|
|
602
608
|
return false;
|
|
603
609
|
}
|
|
604
610
|
if (document.action === 'DELETE') {
|
|
@@ -626,33 +632,20 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
626
632
|
rest['extends'] = ext;
|
|
627
633
|
}
|
|
628
634
|
if (caller_access) {
|
|
629
|
-
rest['caller_access'] =
|
|
635
|
+
rest['caller_access'] = callerAccess[caller_access];
|
|
630
636
|
}
|
|
631
637
|
if (!(0, lodash_1.isEmpty)(db_data)) {
|
|
632
|
-
|
|
633
|
-
if (actions.length > 0) {
|
|
634
|
-
(0, sdk_build_core_1.writeCustomProperty)(args, 'actions', '[]', (0, sdk_build_core_1.stringify)(actions));
|
|
635
|
-
}
|
|
636
|
-
else {
|
|
637
|
-
const actionsProp = (0, sdk_build_core_1.getOrCreatePropertyAssignment)(args, 'actions', '[]');
|
|
638
|
-
actionsProp.remove();
|
|
639
|
-
}
|
|
638
|
+
rest.actions = getActionsArray(xmlData.dbObjectData);
|
|
640
639
|
}
|
|
641
640
|
if (!rest.attributes) {
|
|
642
641
|
delete rest.attributes;
|
|
643
642
|
}
|
|
644
|
-
if (xmlData.bootstrapData && xmlData.bootstrapData.index) {
|
|
645
|
-
const indexProp = (0, sdk_build_core_1.getOrCreatePropertyAssignment)(args, 'index', '[]');
|
|
646
|
-
indexProp.setInitializer((0, sdk_build_core_1.stringify)(xmlData.bootstrapData.index));
|
|
647
|
-
if (xmlData.bootstrapData.index.length === 0) {
|
|
648
|
-
indexProp.remove();
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
643
|
(0, sdk_build_core_1.transformFunctionArguments)(document.node, db_1.Table, rest);
|
|
652
644
|
// Handle columns
|
|
653
645
|
const incomingColumns = xmlData.bootstrapData ? xmlData.bootstrapData.columns : undefined;
|
|
654
646
|
updateDisplayValue(document.node, columns, incomingColumns);
|
|
655
|
-
transformColumns(incomingColumns, args);
|
|
647
|
+
transformColumns(columns, incomingColumns, args);
|
|
648
|
+
transformIndexes(xmlData, args);
|
|
656
649
|
return true;
|
|
657
650
|
},
|
|
658
651
|
},
|
|
@@ -688,7 +681,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
688
681
|
type: interfaceType,
|
|
689
682
|
});
|
|
690
683
|
}
|
|
691
|
-
const filePath =
|
|
684
|
+
const filePath = table.getNode().getSourceFile().getFilePath();
|
|
692
685
|
const resolvedModuleSpecifier = generatedTableFile?.getRelativePathAsModuleSpecifierTo(filePath);
|
|
693
686
|
const importExists = context.compiler.importExistsInGlobalDeclaration(tableName);
|
|
694
687
|
if (!importExists) {
|
|
@@ -725,6 +718,25 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
725
718
|
},
|
|
726
719
|
},
|
|
727
720
|
});
|
|
721
|
+
function transformIndexes(xmlData, args) {
|
|
722
|
+
if (xmlData.bootstrapData?.index?.length > 0) {
|
|
723
|
+
// find the correct object literal
|
|
724
|
+
const indexProp = (0, sdk_build_core_1.getPropertyAssignment)(args, 'index');
|
|
725
|
+
if (indexProp) {
|
|
726
|
+
(0, sdk_build_core_1.mergeDataIntoObjectLiteralArray)(indexProp.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.ArrayLiteralExpression), Object.values(xmlData.bootstrapData?.index), 'name');
|
|
727
|
+
}
|
|
728
|
+
else {
|
|
729
|
+
const newIndexProp = (0, sdk_build_core_1.getOrCreatePropertyAssignment)(args, 'index', '[]');
|
|
730
|
+
newIndexProp.setInitializer((0, sdk_build_core_1.stringify)(xmlData.bootstrapData.index));
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
const indexProp = (0, sdk_build_core_1.getPropertyAssignment)(args, 'index');
|
|
735
|
+
if (indexProp) {
|
|
736
|
+
indexProp.remove();
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
728
740
|
function generateCallExpressionExportForDocument(context, info, fn, ...args) {
|
|
729
741
|
const { sourceFile, moduleSpecifier } = info;
|
|
730
742
|
return (0, sdk_build_core_1.generateCallExpressionExport)(context, sourceFile, moduleSpecifier, info.exportName, fn, ...args);
|
|
@@ -848,7 +860,7 @@ function compose(bootstrapData) {
|
|
|
848
860
|
read_only: bootstrapData.read_only,
|
|
849
861
|
audit: bootstrapData.audit,
|
|
850
862
|
access: bootstrapData.accessible_from,
|
|
851
|
-
caller_access:
|
|
863
|
+
caller_access: callerAccess.indexOf(bootstrapData.caller_access ?? 'none'),
|
|
852
864
|
read_access: bootstrapData.actions?.includes('read'),
|
|
853
865
|
update_access: bootstrapData.actions?.includes('update'),
|
|
854
866
|
create_access: bootstrapData.actions?.includes('create'),
|
|
@@ -881,36 +893,118 @@ function mapNames(schema) {
|
|
|
881
893
|
return schema;
|
|
882
894
|
}
|
|
883
895
|
let schemaPosition = 4;
|
|
884
|
-
function transformColumns(
|
|
896
|
+
function transformColumns(columns, incomingSchema, args) {
|
|
885
897
|
const schemaProperty = (0, sdk_build_core_1.getOrCreatePropertyAssignment)(args, 'schema', '{}');
|
|
886
|
-
const schemaLiteral = schemaProperty.getChildrenOfKind(
|
|
898
|
+
const schemaLiteral = schemaProperty.getChildrenOfKind(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression)[0];
|
|
887
899
|
if (!schemaLiteral) {
|
|
888
900
|
return;
|
|
889
901
|
}
|
|
890
|
-
const keys = Object.keys(
|
|
902
|
+
const keys = Object.keys(columns ?? {});
|
|
891
903
|
if (keys.length === 0) {
|
|
892
904
|
return;
|
|
893
905
|
}
|
|
894
906
|
//TODO:: need to come up with a way to format script more accurately
|
|
895
907
|
schemaPosition = schemaLiteral.getSourceFile().getLineAndColumnAtPos(schemaLiteral.getStart()).column;
|
|
896
|
-
const
|
|
908
|
+
const existingColumns = {};
|
|
909
|
+
schemaLiteral.getProperties().forEach((property) => {
|
|
910
|
+
const propertyAssignment = property.asKindOrThrow(sdk_project_1.ts.SyntaxKind.PropertyAssignment);
|
|
911
|
+
const name = propertyAssignment.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.Identifier).getText();
|
|
912
|
+
const callExp = propertyAssignment.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.CallExpression);
|
|
913
|
+
const callExpType = callExp.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.Identifier).getText();
|
|
914
|
+
const objectLiteral = callExp.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression);
|
|
915
|
+
existingColumns[name] = {
|
|
916
|
+
node: propertyAssignment,
|
|
917
|
+
type: callExpType,
|
|
918
|
+
objectLiteral,
|
|
919
|
+
};
|
|
920
|
+
if (!incomingSchema[name]) {
|
|
921
|
+
// Full bootstrap.xml does not have this existing column so remove it
|
|
922
|
+
(0, sdk_build_core_1.removeNode)(propertyAssignment);
|
|
923
|
+
}
|
|
924
|
+
});
|
|
897
925
|
keys.forEach((key) => {
|
|
898
|
-
const
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
926
|
+
const partialData = columns[key];
|
|
927
|
+
if (!existingColumns[key]) {
|
|
928
|
+
// This column doesn't exist so let's make it
|
|
929
|
+
const callExpFromType = getCallExpressionFromType(partialData.type);
|
|
930
|
+
createNewColumn(schemaLiteral, callExpFromType.name, partialData);
|
|
931
|
+
}
|
|
932
|
+
else {
|
|
933
|
+
const existingColumn = existingColumns[key];
|
|
934
|
+
if (partialData.type && existingColumn.type !== partialData.type) {
|
|
935
|
+
// Switching the column type so regenerate the CallExpression and add all incoming data
|
|
936
|
+
(0, sdk_build_core_1.removeNode)(existingColumn.node);
|
|
937
|
+
const callExpFromType = getCallExpressionFromType(partialData.type);
|
|
938
|
+
createNewColumn(schemaLiteral, callExpFromType.name, incomingSchema[key]);
|
|
939
|
+
}
|
|
940
|
+
else {
|
|
941
|
+
// Update the existing column with changed data only
|
|
942
|
+
const transformedColumnData = transformColumnData(partialData, existingColumn.type);
|
|
943
|
+
(0, sdk_build_core_1.mergeDataIntoObjectLiteral)(existingColumn.objectLiteral, {
|
|
944
|
+
...transformedColumnData,
|
|
945
|
+
choices: partialData.choice_elements,
|
|
946
|
+
});
|
|
947
|
+
removeChoicesIfNecessary(existingColumn, incomingSchema[key]);
|
|
948
|
+
removeAttributesIfNecessary(existingColumn, incomingSchema[key]);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
function removeChoicesIfNecessary(existingColumn, columnFromBootstrap) {
|
|
954
|
+
const existingProperties = existingColumn.objectLiteral
|
|
955
|
+
.getProperties()
|
|
956
|
+
.reduce((a, v) => ({ ...a, [v.getName()]: v }), {});
|
|
957
|
+
if (!existingProperties['choices']) {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
if (!columnFromBootstrap['choice_elements']) {
|
|
961
|
+
(0, sdk_build_core_1.removeNode)(existingProperties['choices']);
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
const choicesFromBootstrap = Object.keys(columnFromBootstrap['choice_elements']);
|
|
965
|
+
const existingChoices = existingProperties['choices']
|
|
966
|
+
.getFirstChildByKind(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression)
|
|
967
|
+
.getProperties()
|
|
968
|
+
.reduce((a, v) => ({ ...a, [v.getName()]: v }), {});
|
|
969
|
+
Object.keys(existingChoices).forEach((choice) => {
|
|
970
|
+
if (!choicesFromBootstrap.includes(choice)) {
|
|
971
|
+
(0, sdk_build_core_1.removeNode)(existingChoices[choice]);
|
|
972
|
+
}
|
|
906
973
|
});
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
974
|
+
}
|
|
975
|
+
function removeAttributesIfNecessary(existingColumn, columnFromBootstrap) {
|
|
976
|
+
const existingProperties = existingColumn.objectLiteral
|
|
977
|
+
.getProperties()
|
|
978
|
+
.reduce((a, v) => ({ ...a, [v.getName()]: v }), {});
|
|
979
|
+
if (!existingProperties['attributes']) {
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
if (!columnFromBootstrap['attributes']) {
|
|
983
|
+
(0, sdk_build_core_1.removeNode)(existingProperties['attributes']);
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
const attributesFromBootstrap = Object.keys(columnFromBootstrap['attributes']);
|
|
987
|
+
const existingChoices = existingProperties['attributes']
|
|
988
|
+
.getFirstChildByKind(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression)
|
|
989
|
+
.getProperties()
|
|
990
|
+
.reduce((a, v) => ({ ...a, [v.getName()]: v }), {});
|
|
991
|
+
Object.keys(existingChoices).forEach((choice) => {
|
|
992
|
+
if (!(choice in attributesFromBootstrap)) {
|
|
993
|
+
(0, sdk_build_core_1.removeNode)(existingChoices[choice]);
|
|
910
994
|
}
|
|
911
|
-
return traversal.currentNode;
|
|
912
995
|
});
|
|
913
996
|
}
|
|
997
|
+
function createNewColumn(schemaLiteral, callExpName, data) {
|
|
998
|
+
const propertyAssignment = schemaLiteral.addPropertyAssignment({
|
|
999
|
+
name: data.name,
|
|
1000
|
+
initializer: `${callExpName}({})`,
|
|
1001
|
+
});
|
|
1002
|
+
const objectLiteral = propertyAssignment
|
|
1003
|
+
.getInitializer()
|
|
1004
|
+
.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression);
|
|
1005
|
+
const transformedColumnData = transformColumnData(data, callExpName);
|
|
1006
|
+
(0, sdk_build_core_1.mergeDataIntoObjectLiteral)(objectLiteral, { ...transformedColumnData, choices: data.choice_elements });
|
|
1007
|
+
}
|
|
914
1008
|
function getActionsArray(data) {
|
|
915
1009
|
const actions = [];
|
|
916
1010
|
if (data.read_access) {
|
|
@@ -931,12 +1025,19 @@ function getDynamicDefault(val) {
|
|
|
931
1025
|
if (!val) {
|
|
932
1026
|
return;
|
|
933
1027
|
}
|
|
934
|
-
return val.startsWith('javascript:') ? val : `javascript:${
|
|
1028
|
+
return val.startsWith('javascript:') ? val : `javascript:${dynamic_value_mapping[val]}`;
|
|
935
1029
|
}
|
|
936
1030
|
function buildIndexes(indexes = [], collection) {
|
|
937
1031
|
indexes.forEach((index) => {
|
|
938
1032
|
const indexElement = collection.ele('index', { name: index.name, unique: index.unique });
|
|
939
|
-
|
|
1033
|
+
if ((0, lodash_1.isArray)(index.element)) {
|
|
1034
|
+
index.element.forEach((element) => {
|
|
1035
|
+
indexElement.ele('element', { name: element });
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
indexElement.ele('element', { name: index.element });
|
|
1040
|
+
}
|
|
940
1041
|
});
|
|
941
1042
|
}
|
|
942
1043
|
function buildChoices(column, element) {
|
|
@@ -974,9 +1075,9 @@ function buildChoices(column, element) {
|
|
|
974
1075
|
function transformColumnData(col, callExpFromType) {
|
|
975
1076
|
const { type: internal_type, choice, name, virtual, display, choice_table, choice_field, use_dependent_field, dependent, calculation, use_dynamic_default, default_value, choice_elements, table, default: def, max_length, reference, reference_cascade_rule, function_field, ...column } = col;
|
|
976
1077
|
if (max_length !== undefined) {
|
|
977
|
-
column.maxLength = max_length;
|
|
1078
|
+
column.maxLength = (0, lodash_1.parseInt)(max_length, 10);
|
|
978
1079
|
}
|
|
979
|
-
if (internal_type &&
|
|
1080
|
+
if (internal_type && callExpFromType === 'GenericColumn') {
|
|
980
1081
|
column.column_type = internal_type;
|
|
981
1082
|
}
|
|
982
1083
|
if (choice !== undefined) {
|
|
@@ -1057,7 +1158,7 @@ function SysNumber(category, maximum_digits, number, prefix) {
|
|
|
1057
1158
|
});
|
|
1058
1159
|
}
|
|
1059
1160
|
// TODO should this reference sys_filter_option_dynamic instead?
|
|
1060
|
-
|
|
1161
|
+
const dynamic_value_mapping = {
|
|
1061
1162
|
'Current Name': `current.name`,
|
|
1062
1163
|
'Next ECC Sequence Number': `GlideCounter.next('ecc:sequence');`,
|
|
1063
1164
|
'Get Module View': `var viewDefault='';if(current.device_type=='mobile') viewDefault='Mobile';else if(!current.application.nil() && current.application.device_type=='mobile' && current.device_type.nil()) viewDefault='Mobile';viewDefault`,
|
|
@@ -1086,28 +1187,28 @@ function generateColumnExpression(expression, args, argsSetIfDefined) {
|
|
|
1086
1187
|
}
|
|
1087
1188
|
});
|
|
1088
1189
|
}
|
|
1089
|
-
return
|
|
1190
|
+
return sdk_project_1.tsc.factory.createCallExpression(sdk_project_1.tsc.factory.createIdentifier(expression.name), undefined, [
|
|
1090
1191
|
createObjectExpression(setArgs),
|
|
1091
1192
|
]);
|
|
1092
1193
|
}
|
|
1093
1194
|
function createObjectExpression(firstArg) {
|
|
1094
|
-
return
|
|
1195
|
+
return sdk_project_1.tsc.factory.createObjectLiteralExpression(Object.entries(firstArg)
|
|
1095
1196
|
.filter(([_key, value]) => value !== undefined)
|
|
1096
1197
|
.map(([key, value]) => {
|
|
1097
1198
|
if (key === 'referenceTable') {
|
|
1098
|
-
return
|
|
1199
|
+
return sdk_project_1.tsc.factory.createPropertyAssignment(sdk_project_1.tsc.factory.createIdentifier('referenceTable'), sdk_project_1.tsc.factory.createStringLiteral(value));
|
|
1099
1200
|
}
|
|
1100
1201
|
else if (key === 'calculated_value') {
|
|
1101
1202
|
const calVal = `${os.EOL}${(0, ScriptTemplatePlugin_1.formatScript)(value, schemaPosition)}`;
|
|
1102
|
-
return
|
|
1203
|
+
return sdk_project_1.tsc.factory.createPropertyAssignment(sdk_project_1.tsc.factory.createIdentifier(key), sdk_project_1.tsc.factory.createTaggedTemplateExpression(sdk_project_1.tsc.factory.createIdentifier('script'), undefined, sdk_project_1.tsc.factory.createNoSubstitutionTemplateLiteral(calVal, calVal)));
|
|
1103
1204
|
}
|
|
1104
1205
|
else if (key === 'maxLength') {
|
|
1105
1206
|
if (isNaN(+value)) {
|
|
1106
|
-
return
|
|
1207
|
+
return sdk_project_1.tsc.factory.createPropertyAssignment(sdk_project_1.tsc.factory.createIdentifier(key), sdk_project_1.tsc.factory.createAsExpression(sdk_project_1.tsc.factory.createStringLiteral(value), sdk_project_1.tsc.factory.createKeywordTypeNode(sdk_project_1.ts.SyntaxKind.AnyKeyword)));
|
|
1107
1208
|
}
|
|
1108
|
-
return
|
|
1209
|
+
return sdk_project_1.tsc.factory.createPropertyAssignment(sdk_project_1.tsc.factory.createIdentifier(key), sdk_project_1.tsc.factory.createNumericLiteral(value));
|
|
1109
1210
|
}
|
|
1110
|
-
return
|
|
1211
|
+
return sdk_project_1.tsc.factory.createPropertyAssignment((0, sdk_build_core_1.createPropertyIdentifier)(key), factoryCreateValue(value, sdk_project_1.tsc.factory));
|
|
1111
1212
|
}));
|
|
1112
1213
|
}
|
|
1113
1214
|
function factoryCreateValue(value, factory) {
|
|
@@ -1119,7 +1220,7 @@ function factoryCreateValue(value, factory) {
|
|
|
1119
1220
|
return factory.createNumericLiteral(value);
|
|
1120
1221
|
}
|
|
1121
1222
|
else {
|
|
1122
|
-
return factory.createPrefixUnaryExpression(
|
|
1223
|
+
return factory.createPrefixUnaryExpression(sdk_project_1.tsc.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
|
|
1123
1224
|
}
|
|
1124
1225
|
}
|
|
1125
1226
|
if (typeof value === 'boolean') {
|
|
@@ -1136,7 +1237,7 @@ function factoryCreateValue(value, factory) {
|
|
|
1136
1237
|
});
|
|
1137
1238
|
return factory.createArrayLiteralExpression(newvals);
|
|
1138
1239
|
}
|
|
1139
|
-
else if (
|
|
1240
|
+
else if (sdk_project_1.ts.Structure.isImportSpecifier(value)) {
|
|
1140
1241
|
return factory.createIdentifier(value['name']);
|
|
1141
1242
|
}
|
|
1142
1243
|
else {
|