@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.
Files changed (118) hide show
  1. package/dist/AttachmentPlugin.d.ts +6 -7
  2. package/dist/AttachmentPlugin.js +8 -6
  3. package/dist/AttachmentPlugin.js.map +1 -1
  4. package/dist/BusinessRulePlugin.d.ts +5 -5
  5. package/dist/BusinessRulePlugin.js +4 -4
  6. package/dist/BusinessRulePlugin.js.map +1 -1
  7. package/dist/CrossScopePrivilegePlugin.d.ts +5 -5
  8. package/dist/CrossScopePrivilegePlugin.js +1 -2
  9. package/dist/CrossScopePrivilegePlugin.js.map +1 -1
  10. package/dist/DefaultPlugin.d.ts +19 -11
  11. package/dist/DefaultPlugin.js +23 -51
  12. package/dist/DefaultPlugin.js.map +1 -1
  13. package/dist/HtmlTemplatePlugin.d.ts +2 -2
  14. package/dist/HtmlTemplatePlugin.js +3 -26
  15. package/dist/HtmlTemplatePlugin.js.map +1 -1
  16. package/dist/IdPlugin.d.ts +5 -4
  17. package/dist/IdPlugin.js +5 -9
  18. package/dist/IdPlugin.js.map +1 -1
  19. package/dist/JsonPlugin.d.ts +8 -3
  20. package/dist/JsonPlugin.js +6 -11
  21. package/dist/JsonPlugin.js.map +1 -1
  22. package/dist/ListPlugin.d.ts +6 -7
  23. package/dist/ListPlugin.js +17 -19
  24. package/dist/ListPlugin.js.map +1 -1
  25. package/dist/NowConfigPlugin.d.ts +1 -1
  26. package/dist/NowConfigPlugin.js +5 -31
  27. package/dist/NowConfigPlugin.js.map +1 -1
  28. package/dist/PackageJsonPlugin.d.ts +1 -1
  29. package/dist/PackageJsonPlugin.js +1 -1
  30. package/dist/PackageJsonPlugin.js.map +1 -1
  31. package/dist/PropertyPlugin.d.ts +5 -66
  32. package/dist/PropertyPlugin.js +6 -12
  33. package/dist/PropertyPlugin.js.map +1 -1
  34. package/dist/ScriptTemplatePlugin.d.ts +1 -1
  35. package/dist/ScriptTemplatePlugin.js +5 -5
  36. package/dist/ScriptTemplatePlugin.js.map +1 -1
  37. package/dist/ServerModulePlugin.d.ts +5 -6
  38. package/dist/ServerModulePlugin.js +10 -39
  39. package/dist/ServerModulePlugin.js.map +1 -1
  40. package/dist/UserPreferencePlugin.d.ts +1 -1
  41. package/dist/aclAndRole/AclPlugin.d.ts +44 -28
  42. package/dist/aclAndRole/AclPlugin.js +30 -33
  43. package/dist/aclAndRole/AclPlugin.js.map +1 -1
  44. package/dist/aclAndRole/RolePlugin.d.ts +5 -6
  45. package/dist/aclAndRole/RolePlugin.js +6 -7
  46. package/dist/aclAndRole/RolePlugin.js.map +1 -1
  47. package/dist/aclAndRole/Util.js +7 -30
  48. package/dist/aclAndRole/Util.js.map +1 -1
  49. package/dist/app/ApplicationMenuPlugin.d.ts +5 -5
  50. package/dist/app/ApplicationMenuPlugin.js +2 -3
  51. package/dist/app/ApplicationMenuPlugin.js.map +1 -1
  52. package/dist/atf/TestPlugin.d.ts +3 -3
  53. package/dist/atf/TestPlugin.js +1 -1
  54. package/dist/atf/TestPlugin.js.map +1 -1
  55. package/dist/db/ColumnPlugins.d.ts +85 -85
  56. package/dist/db/ColumnPlugins.js +17 -19
  57. package/dist/db/ColumnPlugins.js.map +1 -1
  58. package/dist/db/DocumentationPlugin.d.ts +6 -6
  59. package/dist/db/DocumentationPlugin.js +17 -49
  60. package/dist/db/DocumentationPlugin.js.map +1 -1
  61. package/dist/db/RecordPlugin.d.ts +7 -101
  62. package/dist/db/RecordPlugin.js +25 -24
  63. package/dist/db/RecordPlugin.js.map +1 -1
  64. package/dist/db/TablePlugin.d.ts +9 -610
  65. package/dist/db/TablePlugin.js +185 -84
  66. package/dist/db/TablePlugin.js.map +1 -1
  67. package/dist/scriptedRESTAPI/RESTDeserializationUtils.d.ts +0 -2
  68. package/dist/scriptedRESTAPI/RESTDeserializationUtils.js +17 -18
  69. package/dist/scriptedRESTAPI/RESTDeserializationUtils.js.map +1 -1
  70. package/dist/scriptedRESTAPI/RESTSerializationUtils.d.ts +1 -3
  71. package/dist/scriptedRESTAPI/RESTSerializationUtils.js +0 -1
  72. package/dist/scriptedRESTAPI/RESTSerializationUtils.js.map +1 -1
  73. package/dist/scriptedRESTAPI/RestApiPlugin.d.ts +3 -4
  74. package/dist/scriptedRESTAPI/RestApiPlugin.js +7 -33
  75. package/dist/scriptedRESTAPI/RestApiPlugin.js.map +1 -1
  76. package/dist/scriptedRESTAPI/RestUtils.d.ts +1 -10
  77. package/dist/scriptedRESTAPI/RestUtils.js +11 -35
  78. package/dist/scriptedRESTAPI/RestUtils.js.map +1 -1
  79. package/dist/scripts/ClientScriptPlugin.d.ts +3 -4
  80. package/dist/scripts/ClientScriptPlugin.js +11 -37
  81. package/dist/scripts/ClientScriptPlugin.js.map +1 -1
  82. package/dist/uxf/ExperiencePlugin.d.ts +2 -2
  83. package/dist/uxf/RoutesPlugin.d.ts +2 -2
  84. package/dist/uxf/RoutesPlugin.js +2 -3
  85. package/dist/uxf/RoutesPlugin.js.map +1 -1
  86. package/dist/uxf/tectonicIdGenerator.d.ts +1 -1
  87. package/dist/uxf/tectonicIdGenerator.js +5 -28
  88. package/dist/uxf/tectonicIdGenerator.js.map +1 -1
  89. package/package.json +6 -8
  90. package/src/AttachmentPlugin.ts +5 -7
  91. package/src/BusinessRulePlugin.ts +12 -6
  92. package/src/CrossScopePrivilegePlugin.ts +2 -3
  93. package/src/DefaultPlugin.ts +22 -26
  94. package/src/HtmlTemplatePlugin.ts +2 -2
  95. package/src/IdPlugin.ts +6 -10
  96. package/src/JsonPlugin.ts +7 -12
  97. package/src/ListPlugin.ts +20 -22
  98. package/src/NowConfigPlugin.ts +10 -13
  99. package/src/PackageJsonPlugin.ts +1 -1
  100. package/src/PropertyPlugin.ts +8 -14
  101. package/src/ScriptTemplatePlugin.ts +1 -1
  102. package/src/ServerModulePlugin.ts +15 -20
  103. package/src/aclAndRole/AclPlugin.ts +37 -6
  104. package/src/aclAndRole/RolePlugin.ts +7 -9
  105. package/src/aclAndRole/Util.ts +2 -2
  106. package/src/app/ApplicationMenuPlugin.ts +3 -4
  107. package/src/atf/TestPlugin.ts +3 -3
  108. package/src/db/ColumnPlugins.ts +20 -22
  109. package/src/db/DocumentationPlugin.ts +7 -41
  110. package/src/db/RecordPlugin.ts +23 -26
  111. package/src/db/TablePlugin.ts +222 -115
  112. package/src/scriptedRESTAPI/RESTDeserializationUtils.ts +18 -19
  113. package/src/scriptedRESTAPI/RESTSerializationUtils.ts +1 -1
  114. package/src/scriptedRESTAPI/RestApiPlugin.ts +15 -18
  115. package/src/scriptedRESTAPI/RestUtils.ts +7 -7
  116. package/src/scripts/ClientScriptPlugin.ts +10 -12
  117. package/src/uxf/RoutesPlugin.ts +2 -3
  118. package/src/uxf/tectonicIdGenerator.ts +3 -6
@@ -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
- exports.callerAccess = ['none', 'tracking', 'restricted'];
47
+ const callerAccess = ['none', 'tracking', 'restricted'];
55
48
  // Basic info needed for table references
56
- exports.TableSchemaFull = zod_1.z.object({
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(exports.callerAccess).optional(),
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.string(),
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 exports.callerAccess[val];
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
- exports.TableSchemaBootstrap = zod_1.z.object({
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(exports.callerAccess).default('none').optional(),
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 = exports.TableSchemaBootstrap.omit({ actions: true }).extend({
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 exports.callerAccess[val];
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
- exports.SysDocumentation = zod_1.z.object({
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
- exports.TableSchemaBootstrapAttributes = zod_1.z
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.object({
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
- exports.ColumnSchemaBootstrapAttributes = exports.TableSchemaBootstrapAttributes.omit({ '@_extends': true })
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 || !(0 in result.data)) {
353
+ if (!result.handled || !result.data) {
350
354
  return result;
351
355
  }
352
- const data = result.data[0];
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(ts_morph_1.SyntaxKind.StringLiteral);
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(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
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(ts_morph_1.SyntaxKind.VariableDeclaration);
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: [data], diagnostics };
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 = exports.TableSchemaBootstrapAttributes.parse(bootstrapDatabaseXML.data.element);
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 = exports.SysDocumentation.parse(record_update[table]).sys_documentation;
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(exports.ColumnSchemaBootstrapAttributes).parse(elementsArray));
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['@_name'],
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 = exports.TableSchemaFull.parse(data);
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(ts_morph_1.SyntaxKind.CallExpression));
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 (!ts_morph_1.Node.isObjectLiteralExpression(args)) {
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'] = exports.callerAccess[caller_access];
635
+ rest['caller_access'] = callerAccess[caller_access];
630
636
  }
631
637
  if (!(0, lodash_1.isEmpty)(db_data)) {
632
- const actions = getActionsArray({ create_access, delete_access, update_access, read_access });
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 = path.normalize(table.getNode().getSourceFile().getFilePath());
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: exports.callerAccess.indexOf(bootstrapData.caller_access ?? 'none'),
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(incoming_schema, args) {
896
+ function transformColumns(columns, incomingSchema, args) {
885
897
  const schemaProperty = (0, sdk_build_core_1.getOrCreatePropertyAssignment)(args, 'schema', '{}');
886
- const schemaLiteral = schemaProperty.getChildrenOfKind(ts_morph_1.ts.SyntaxKind.ObjectLiteralExpression)[0];
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(incoming_schema ?? {});
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 assignments = [];
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 data = incoming_schema[key];
899
- const callExpFromType = getCallExpressionFromType(data.type);
900
- const transformedColumn = transformColumnData(data, callExpFromType);
901
- const callExp = generateColumnExpression(callExpFromType, {
902
- ...transformedColumn,
903
- choices: data.choice_elements,
904
- });
905
- assignments.push(ts_morph_1.ts.factory.createPropertyAssignment((0, sdk_build_core_1.createPropertyIdentifier)(data.name), callExp));
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
- schemaLiteral.transform((traversal) => {
908
- if (ts_morph_1.ts.isObjectLiteralExpression(traversal.currentNode)) {
909
- return traversal.factory.updateObjectLiteralExpression(traversal.currentNode, assignments);
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:${exports.dynamic_value_mapping[val]}`;
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
- indexElement.ele('element', { name: index.element });
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 && (callExpFromType.entityKind === 'generic' || callExpFromType.name === 'GenericColumn')) {
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
- exports.dynamic_value_mapping = {
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 ts_morph_1.ts.factory.createCallExpression(ts_morph_1.ts.factory.createIdentifier(expression.name), undefined, [
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 ts_morph_1.ts.factory.createObjectLiteralExpression(Object.entries(firstArg)
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 ts_morph_1.ts.factory.createPropertyAssignment(ts_morph_1.ts.factory.createIdentifier('referenceTable'), ts_morph_1.ts.factory.createStringLiteral(value));
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 ts_morph_1.ts.factory.createPropertyAssignment(ts_morph_1.ts.factory.createIdentifier(key), ts_morph_1.ts.factory.createTaggedTemplateExpression(ts_morph_1.ts.factory.createIdentifier('script'), undefined, ts_morph_1.ts.factory.createNoSubstitutionTemplateLiteral(calVal, calVal)));
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 ts_morph_1.ts.factory.createPropertyAssignment(ts_morph_1.ts.factory.createIdentifier(key), ts_morph_1.ts.factory.createAsExpression(ts_morph_1.ts.factory.createStringLiteral(value), ts_morph_1.ts.factory.createKeywordTypeNode(ts_morph_1.ts.SyntaxKind.AnyKeyword)));
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 ts_morph_1.ts.factory.createPropertyAssignment(ts_morph_1.ts.factory.createIdentifier(key), ts_morph_1.ts.factory.createNumericLiteral(value));
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 ts_morph_1.ts.factory.createPropertyAssignment((0, sdk_build_core_1.createPropertyIdentifier)(key), factoryCreateValue(value, ts_morph_1.ts.factory));
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(ts_morph_1.ts.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
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 (ts_morph_1.Structure.isImportSpecifier(value)) {
1240
+ else if (sdk_project_1.ts.Structure.isImportSpecifier(value)) {
1140
1241
  return factory.createIdentifier(value['name']);
1141
1242
  }
1142
1243
  else {