@servicenow/sdk-build-plugins 3.0.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (359) hide show
  1. package/dist/acl-plugin.d.ts +19 -0
  2. package/dist/acl-plugin.js +210 -0
  3. package/dist/acl-plugin.js.map +1 -0
  4. package/dist/application-menu-plugin.d.ts +18 -0
  5. package/dist/application-menu-plugin.js +104 -0
  6. package/dist/application-menu-plugin.js.map +1 -0
  7. package/dist/arrow-function-plugin.d.ts +16 -0
  8. package/dist/arrow-function-plugin.js +107 -0
  9. package/dist/arrow-function-plugin.js.map +1 -0
  10. package/dist/atf/step-configs.d.ts +37 -0
  11. package/dist/atf/step-configs.js +2236 -0
  12. package/dist/atf/step-configs.js.map +1 -0
  13. package/dist/atf/test-plugin.d.ts +4 -0
  14. package/dist/atf/test-plugin.js +591 -0
  15. package/dist/atf/test-plugin.js.map +1 -0
  16. package/dist/basic-syntax-plugin.d.ts +2 -0
  17. package/dist/basic-syntax-plugin.js +636 -0
  18. package/dist/basic-syntax-plugin.js.map +1 -0
  19. package/dist/business-rule-plugin.d.ts +3 -0
  20. package/dist/business-rule-plugin.js +205 -0
  21. package/dist/business-rule-plugin.js.map +1 -0
  22. package/dist/call-expression-plugin.d.ts +2 -0
  23. package/dist/call-expression-plugin.js +175 -0
  24. package/dist/call-expression-plugin.js.map +1 -0
  25. package/dist/client-script-plugin.d.ts +29 -0
  26. package/dist/client-script-plugin.js +157 -0
  27. package/dist/client-script-plugin.js.map +1 -0
  28. package/dist/column/column-helper.d.ts +12 -0
  29. package/dist/column/column-helper.js +84 -0
  30. package/dist/column/column-helper.js.map +1 -0
  31. package/dist/column/column-to-record.d.ts +3 -0
  32. package/dist/column/column-to-record.js +105 -0
  33. package/dist/column/column-to-record.js.map +1 -0
  34. package/dist/column-plugin.d.ts +8 -0
  35. package/dist/column-plugin.js +453 -0
  36. package/dist/column-plugin.js.map +1 -0
  37. package/dist/cross-scope-privilege-plugin.d.ts +15 -0
  38. package/dist/cross-scope-privilege-plugin.js +82 -0
  39. package/dist/cross-scope-privilege-plugin.js.map +1 -0
  40. package/dist/html-import-plugin.d.ts +2 -0
  41. package/dist/html-import-plugin.js +72 -0
  42. package/dist/html-import-plugin.js.map +1 -0
  43. package/dist/index.d.ts +37 -21
  44. package/dist/index.js +40 -45
  45. package/dist/index.js.map +1 -1
  46. package/dist/json-plugin.d.ts +15 -0
  47. package/dist/json-plugin.js +104 -0
  48. package/dist/json-plugin.js.map +1 -0
  49. package/dist/list-plugin.d.ts +2 -0
  50. package/dist/list-plugin.js +191 -0
  51. package/dist/list-plugin.js.map +1 -0
  52. package/dist/now-config-plugin.d.ts +4 -0
  53. package/dist/now-config-plugin.js +154 -0
  54. package/dist/now-config-plugin.js.map +1 -0
  55. package/dist/now-id-plugin.d.ts +11 -0
  56. package/dist/now-id-plugin.js +71 -0
  57. package/dist/now-id-plugin.js.map +1 -0
  58. package/dist/now-include-plugin.d.ts +16 -0
  59. package/dist/now-include-plugin.js +118 -0
  60. package/dist/now-include-plugin.js.map +1 -0
  61. package/dist/now-ref-plugin.d.ts +2 -0
  62. package/dist/now-ref-plugin.js +43 -0
  63. package/dist/now-ref-plugin.js.map +1 -0
  64. package/dist/now-unresolved-plugin.d.ts +2 -0
  65. package/dist/now-unresolved-plugin.js +32 -0
  66. package/dist/now-unresolved-plugin.js.map +1 -0
  67. package/dist/package-json-plugin.d.ts +2 -0
  68. package/dist/package-json-plugin.js +70 -0
  69. package/dist/package-json-plugin.js.map +1 -0
  70. package/dist/property-plugin.d.ts +2 -0
  71. package/dist/property-plugin.js +105 -0
  72. package/dist/property-plugin.js.map +1 -0
  73. package/dist/record-plugin.d.ts +43 -0
  74. package/dist/record-plugin.js +147 -0
  75. package/dist/record-plugin.js.map +1 -0
  76. package/dist/repack/index.d.ts +1 -0
  77. package/dist/repack/index.js +10 -2
  78. package/dist/repack/index.js.map +1 -1
  79. package/dist/repack/lint/Rules.d.ts +1 -1
  80. package/dist/repack/lint/Rules.js +7 -3
  81. package/dist/repack/lint/Rules.js.map +1 -1
  82. package/dist/repack/lint/index.js +1 -1
  83. package/dist/rest-api-plugin.d.ts +2 -0
  84. package/dist/rest-api-plugin.js +469 -0
  85. package/dist/rest-api-plugin.js.map +1 -0
  86. package/dist/role-plugin.d.ts +2 -0
  87. package/dist/role-plugin.js +117 -0
  88. package/dist/role-plugin.js.map +1 -0
  89. package/dist/script-action-plugin.d.ts +2 -0
  90. package/dist/script-action-plugin.js +62 -0
  91. package/dist/script-action-plugin.js.map +1 -0
  92. package/dist/script-include-plugin.d.ts +2 -0
  93. package/dist/script-include-plugin.js +102 -0
  94. package/dist/script-include-plugin.js.map +1 -0
  95. package/dist/server-module-plugin/index.d.ts +14 -0
  96. package/dist/server-module-plugin/index.js +378 -0
  97. package/dist/server-module-plugin/index.js.map +1 -0
  98. package/dist/server-module-plugin/sbom-builder.d.ts +45 -0
  99. package/dist/server-module-plugin/sbom-builder.js +179 -0
  100. package/dist/server-module-plugin/sbom-builder.js.map +1 -0
  101. package/dist/service-portal/angular-provider-plugin.d.ts +2 -0
  102. package/dist/service-portal/angular-provider-plugin.js +78 -0
  103. package/dist/service-portal/angular-provider-plugin.js.map +1 -0
  104. package/dist/service-portal/dependency-plugin.d.ts +2 -0
  105. package/dist/service-portal/dependency-plugin.js +235 -0
  106. package/dist/service-portal/dependency-plugin.js.map +1 -0
  107. package/dist/service-portal/widget-plugin.d.ts +6 -0
  108. package/dist/service-portal/widget-plugin.js +230 -0
  109. package/dist/service-portal/widget-plugin.js.map +1 -0
  110. package/dist/static-content-plugin.d.ts +2 -0
  111. package/dist/static-content-plugin.js +272 -0
  112. package/dist/static-content-plugin.js.map +1 -0
  113. package/dist/table-plugin.d.ts +3 -0
  114. package/dist/table-plugin.js +1324 -0
  115. package/dist/table-plugin.js.map +1 -0
  116. package/dist/ui-action-plugin.d.ts +2 -0
  117. package/dist/ui-action-plugin.js +291 -0
  118. package/dist/ui-action-plugin.js.map +1 -0
  119. package/dist/ui-page-plugin.d.ts +2 -0
  120. package/dist/ui-page-plugin.js +165 -0
  121. package/dist/ui-page-plugin.js.map +1 -0
  122. package/dist/user-preference-plugin.d.ts +15 -0
  123. package/dist/user-preference-plugin.js +63 -0
  124. package/dist/user-preference-plugin.js.map +1 -0
  125. package/dist/utils.d.ts +17 -0
  126. package/dist/utils.js +72 -0
  127. package/dist/utils.js.map +1 -0
  128. package/dist/view-plugin.d.ts +2 -0
  129. package/dist/view-plugin.js +45 -0
  130. package/dist/view-plugin.js.map +1 -0
  131. package/package.json +17 -13
  132. package/src/acl-plugin.ts +256 -0
  133. package/src/application-menu-plugin.ts +109 -0
  134. package/src/arrow-function-plugin.ts +127 -0
  135. package/src/atf/step-configs.ts +2284 -0
  136. package/src/atf/test-plugin.ts +728 -0
  137. package/src/basic-syntax-plugin.ts +729 -0
  138. package/src/business-rule-plugin.ts +266 -0
  139. package/src/call-expression-plugin.ts +202 -0
  140. package/src/client-script-plugin.ts +170 -0
  141. package/src/column/column-helper.ts +119 -0
  142. package/src/column/column-to-record.ts +131 -0
  143. package/src/column-plugin.ts +506 -0
  144. package/src/cross-scope-privilege-plugin.ts +82 -0
  145. package/src/html-import-plugin.ts +79 -0
  146. package/src/index.ts +39 -21
  147. package/src/json-plugin.ts +128 -0
  148. package/src/list-plugin.ts +222 -0
  149. package/src/now-config-plugin.ts +194 -0
  150. package/src/now-id-plugin.ts +78 -0
  151. package/src/now-include-plugin.ts +140 -0
  152. package/src/now-ref-plugin.ts +48 -0
  153. package/src/now-unresolved-plugin.ts +30 -0
  154. package/src/package-json-plugin.ts +87 -0
  155. package/src/property-plugin.ts +118 -0
  156. package/src/record-plugin.ts +171 -0
  157. package/src/repack/index.ts +10 -1
  158. package/src/repack/lint/Rules.ts +5 -4
  159. package/src/repack/lint/index.ts +1 -1
  160. package/src/rest-api-plugin.ts +651 -0
  161. package/src/role-plugin.ts +128 -0
  162. package/src/script-action-plugin.ts +63 -0
  163. package/src/script-include-plugin.ts +110 -0
  164. package/src/server-module-plugin/index.ts +470 -0
  165. package/src/server-module-plugin/sbom-builder.ts +183 -0
  166. package/src/service-portal/angular-provider-plugin.ts +83 -0
  167. package/src/service-portal/dependency-plugin.ts +284 -0
  168. package/src/service-portal/widget-plugin.ts +263 -0
  169. package/src/static-content-plugin.ts +254 -0
  170. package/src/table-plugin.ts +1698 -0
  171. package/src/ui-action-plugin.ts +324 -0
  172. package/src/ui-page-plugin.ts +168 -0
  173. package/src/user-preference-plugin.ts +62 -0
  174. package/src/utils.ts +69 -0
  175. package/src/view-plugin.ts +46 -0
  176. package/dist/AttachmentPlugin.d.ts +0 -254
  177. package/dist/AttachmentPlugin.js +0 -220
  178. package/dist/AttachmentPlugin.js.map +0 -1
  179. package/dist/BusinessRulePlugin.d.ts +0 -30
  180. package/dist/BusinessRulePlugin.js +0 -149
  181. package/dist/BusinessRulePlugin.js.map +0 -1
  182. package/dist/CrossScopePrivilegePlugin.d.ts +0 -35
  183. package/dist/CrossScopePrivilegePlugin.js +0 -80
  184. package/dist/CrossScopePrivilegePlugin.js.map +0 -1
  185. package/dist/DefaultPlugin.d.ts +0 -86
  186. package/dist/DefaultPlugin.js +0 -226
  187. package/dist/DefaultPlugin.js.map +0 -1
  188. package/dist/HtmlTemplatePlugin.d.ts +0 -21
  189. package/dist/HtmlTemplatePlugin.js +0 -29
  190. package/dist/HtmlTemplatePlugin.js.map +0 -1
  191. package/dist/IdPlugin.d.ts +0 -28
  192. package/dist/IdPlugin.js +0 -68
  193. package/dist/IdPlugin.js.map +0 -1
  194. package/dist/IncludePlugin.d.ts +0 -34
  195. package/dist/IncludePlugin.js +0 -155
  196. package/dist/IncludePlugin.js.map +0 -1
  197. package/dist/JsonPlugin.d.ts +0 -28
  198. package/dist/JsonPlugin.js +0 -69
  199. package/dist/JsonPlugin.js.map +0 -1
  200. package/dist/ListPlugin.d.ts +0 -93
  201. package/dist/ListPlugin.js +0 -456
  202. package/dist/ListPlugin.js.map +0 -1
  203. package/dist/NowConfigPlugin.d.ts +0 -45
  204. package/dist/NowConfigPlugin.js +0 -64
  205. package/dist/NowConfigPlugin.js.map +0 -1
  206. package/dist/PackageJsonPlugin.d.ts +0 -34
  207. package/dist/PackageJsonPlugin.js +0 -63
  208. package/dist/PackageJsonPlugin.js.map +0 -1
  209. package/dist/PropertyPlugin.d.ts +0 -51
  210. package/dist/PropertyPlugin.js +0 -181
  211. package/dist/PropertyPlugin.js.map +0 -1
  212. package/dist/ScriptTemplatePlugin.d.ts +0 -13
  213. package/dist/ScriptTemplatePlugin.js +0 -55
  214. package/dist/ScriptTemplatePlugin.js.map +0 -1
  215. package/dist/ServerModulePlugin.d.ts +0 -75
  216. package/dist/ServerModulePlugin.js +0 -368
  217. package/dist/ServerModulePlugin.js.map +0 -1
  218. package/dist/UserPreferencePlugin.d.ts +0 -19
  219. package/dist/UserPreferencePlugin.js +0 -32
  220. package/dist/UserPreferencePlugin.js.map +0 -1
  221. package/dist/aclAndRole/AclPlugin.d.ts +0 -82
  222. package/dist/aclAndRole/AclPlugin.js +0 -262
  223. package/dist/aclAndRole/AclPlugin.js.map +0 -1
  224. package/dist/aclAndRole/RolePlugin.d.ts +0 -66
  225. package/dist/aclAndRole/RolePlugin.js +0 -179
  226. package/dist/aclAndRole/RolePlugin.js.map +0 -1
  227. package/dist/aclAndRole/Util.d.ts +0 -3
  228. package/dist/aclAndRole/Util.js +0 -90
  229. package/dist/aclAndRole/Util.js.map +0 -1
  230. package/dist/app/ApplicationMenuPlugin.d.ts +0 -34
  231. package/dist/app/ApplicationMenuPlugin.js +0 -112
  232. package/dist/app/ApplicationMenuPlugin.js.map +0 -1
  233. package/dist/db/ColumnPlugins.d.ts +0 -750
  234. package/dist/db/ColumnPlugins.js +0 -114
  235. package/dist/db/ColumnPlugins.js.map +0 -1
  236. package/dist/db/DBUtils.d.ts +0 -2
  237. package/dist/db/DBUtils.js +0 -27
  238. package/dist/db/DBUtils.js.map +0 -1
  239. package/dist/db/DocumentationPlugin.d.ts +0 -67
  240. package/dist/db/DocumentationPlugin.js +0 -258
  241. package/dist/db/DocumentationPlugin.js.map +0 -1
  242. package/dist/db/LicensingPlugin.d.ts +0 -60
  243. package/dist/db/LicensingPlugin.js +0 -117
  244. package/dist/db/LicensingPlugin.js.map +0 -1
  245. package/dist/db/RecordPlugin.d.ts +0 -133
  246. package/dist/db/RecordPlugin.js +0 -337
  247. package/dist/db/RecordPlugin.js.map +0 -1
  248. package/dist/db/TablePlugin.d.ts +0 -231
  249. package/dist/db/TablePlugin.js +0 -1628
  250. package/dist/db/TablePlugin.js.map +0 -1
  251. package/dist/db/index.d.ts +0 -6
  252. package/dist/db/index.js +0 -32
  253. package/dist/db/index.js.map +0 -1
  254. package/dist/scriptedRESTAPI/RESTDeserializationUtils.d.ts +0 -10
  255. package/dist/scriptedRESTAPI/RESTDeserializationUtils.js +0 -373
  256. package/dist/scriptedRESTAPI/RESTDeserializationUtils.js.map +0 -1
  257. package/dist/scriptedRESTAPI/RESTSerializationUtils.d.ts +0 -13
  258. package/dist/scriptedRESTAPI/RESTSerializationUtils.js +0 -177
  259. package/dist/scriptedRESTAPI/RESTSerializationUtils.js.map +0 -1
  260. package/dist/scriptedRESTAPI/RestApiPlugin.d.ts +0 -81
  261. package/dist/scriptedRESTAPI/RestApiPlugin.js +0 -345
  262. package/dist/scriptedRESTAPI/RestApiPlugin.js.map +0 -1
  263. package/dist/scriptedRESTAPI/RestSchemaUtils.d.ts +0 -190
  264. package/dist/scriptedRESTAPI/RestSchemaUtils.js +0 -53
  265. package/dist/scriptedRESTAPI/RestSchemaUtils.js.map +0 -1
  266. package/dist/scriptedRESTAPI/RestUtils.d.ts +0 -69
  267. package/dist/scriptedRESTAPI/RestUtils.js +0 -497
  268. package/dist/scriptedRESTAPI/RestUtils.js.map +0 -1
  269. package/dist/scripts/ClientScriptPlugin.d.ts +0 -64
  270. package/dist/scripts/ClientScriptPlugin.js +0 -170
  271. package/dist/scripts/ClientScriptPlugin.js.map +0 -1
  272. package/dist/scripts/scriptUtils.d.ts +0 -1
  273. package/dist/scripts/scriptUtils.js +0 -9
  274. package/dist/scripts/scriptUtils.js.map +0 -1
  275. package/dist/uxf/ExperiencePlugin.d.ts +0 -45
  276. package/dist/uxf/ExperiencePlugin.js +0 -61
  277. package/dist/uxf/ExperiencePlugin.js.map +0 -1
  278. package/dist/uxf/RoutesPlugin.d.ts +0 -29
  279. package/dist/uxf/RoutesPlugin.js +0 -181
  280. package/dist/uxf/RoutesPlugin.js.map +0 -1
  281. package/dist/uxf/UxfFormulaParser/cleanUxValue.d.ts +0 -4
  282. package/dist/uxf/UxfFormulaParser/cleanUxValue.js +0 -65
  283. package/dist/uxf/UxfFormulaParser/cleanUxValue.js.map +0 -1
  284. package/dist/uxf/UxfFormulaParser/grammerParser/api.d.ts +0 -189
  285. package/dist/uxf/UxfFormulaParser/grammerParser/api.js +0 -158
  286. package/dist/uxf/UxfFormulaParser/grammerParser/api.js.map +0 -1
  287. package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.d.ts +0 -13
  288. package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +0 -604
  289. package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js.map +0 -1
  290. package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.d.ts +0 -12
  291. package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js +0 -551
  292. package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js.map +0 -1
  293. package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.d.ts +0 -31
  294. package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +0 -64
  295. package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js.map +0 -1
  296. package/dist/uxf/UxfFormulaParser/index.d.ts +0 -3
  297. package/dist/uxf/UxfFormulaParser/index.js +0 -11
  298. package/dist/uxf/UxfFormulaParser/index.js.map +0 -1
  299. package/dist/uxf/UxfFormulaParser/parser.d.ts +0 -8
  300. package/dist/uxf/UxfFormulaParser/parser.js +0 -87
  301. package/dist/uxf/UxfFormulaParser/parser.js.map +0 -1
  302. package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.d.ts +0 -8
  303. package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js +0 -17
  304. package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js.map +0 -1
  305. package/dist/uxf/constants.d.ts +0 -2
  306. package/dist/uxf/constants.js +0 -8
  307. package/dist/uxf/constants.js.map +0 -1
  308. package/dist/uxf/index.d.ts +0 -2
  309. package/dist/uxf/index.js +0 -11
  310. package/dist/uxf/index.js.map +0 -1
  311. package/dist/uxf/tectonicIdGenerator.d.ts +0 -12
  312. package/dist/uxf/tectonicIdGenerator.js +0 -79
  313. package/dist/uxf/tectonicIdGenerator.js.map +0 -1
  314. package/src/AttachmentPlugin.ts +0 -268
  315. package/src/BusinessRulePlugin.ts +0 -238
  316. package/src/CrossScopePrivilegePlugin.ts +0 -115
  317. package/src/DefaultPlugin.ts +0 -288
  318. package/src/HtmlTemplatePlugin.ts +0 -31
  319. package/src/IdPlugin.ts +0 -74
  320. package/src/IncludePlugin.ts +0 -206
  321. package/src/JsonPlugin.ts +0 -76
  322. package/src/ListPlugin.ts +0 -570
  323. package/src/NowConfigPlugin.ts +0 -69
  324. package/src/PackageJsonPlugin.ts +0 -68
  325. package/src/PropertyPlugin.ts +0 -237
  326. package/src/ScriptTemplatePlugin.ts +0 -53
  327. package/src/ServerModulePlugin.ts +0 -480
  328. package/src/UserPreferencePlugin.ts +0 -45
  329. package/src/aclAndRole/AclPlugin.ts +0 -420
  330. package/src/aclAndRole/RolePlugin.ts +0 -254
  331. package/src/aclAndRole/Util.ts +0 -113
  332. package/src/app/ApplicationMenuPlugin.ts +0 -165
  333. package/src/db/ColumnPlugins.ts +0 -114
  334. package/src/db/DBUtils.ts +0 -36
  335. package/src/db/DocumentationPlugin.ts +0 -316
  336. package/src/db/LicensingPlugin.ts +0 -138
  337. package/src/db/RecordPlugin.ts +0 -459
  338. package/src/db/TablePlugin.ts +0 -2070
  339. package/src/db/index.ts +0 -6
  340. package/src/scriptedRESTAPI/RESTDeserializationUtils.ts +0 -419
  341. package/src/scriptedRESTAPI/RESTSerializationUtils.ts +0 -228
  342. package/src/scriptedRESTAPI/RestApiPlugin.ts +0 -469
  343. package/src/scriptedRESTAPI/RestSchemaUtils.ts +0 -72
  344. package/src/scriptedRESTAPI/RestUtils.ts +0 -569
  345. package/src/scripts/ClientScriptPlugin.ts +0 -257
  346. package/src/scripts/scriptUtils.ts +0 -5
  347. package/src/uxf/ExperiencePlugin.ts +0 -67
  348. package/src/uxf/RoutesPlugin.ts +0 -211
  349. package/src/uxf/UxfFormulaParser/cleanUxValue.ts +0 -73
  350. package/src/uxf/UxfFormulaParser/grammerParser/api.js +0 -166
  351. package/src/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +0 -606
  352. package/src/uxf/UxfFormulaParser/grammerParser/grammarParser.js +0 -551
  353. package/src/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +0 -65
  354. package/src/uxf/UxfFormulaParser/index.ts +0 -4
  355. package/src/uxf/UxfFormulaParser/parser.ts +0 -64
  356. package/src/uxf/UxfFormulaParser/utils/getErrorMsg.ts +0 -13
  357. package/src/uxf/constants.ts +0 -4
  358. package/src/uxf/index.ts +0 -2
  359. package/src/uxf/tectonicIdGenerator.ts +0 -78
@@ -1,1628 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultMaxLength = getDefaultMaxLength;
4
- exports.generateColumnExpression = generateColumnExpression;
5
- exports.createObjectExpression = createObjectExpression;
6
- const db_1 = require("@servicenow/sdk-core/runtime/db");
7
- const sdk_build_core_1 = require("@servicenow/sdk-build-core");
8
- const xmlbuilder2_1 = require("xmlbuilder2");
9
- const lodash_1 = require("lodash");
10
- const zod_1 = require("zod");
11
- const RecordPlugin_1 = require("./RecordPlugin");
12
- const sdk_project_1 = require("@servicenow/sdk-project");
13
- const DBUtils_1 = require("./DBUtils");
14
- const ServerModulePlugin_1 = require("../ServerModulePlugin");
15
- /**
16
- * The access levels are mapped to the following values on the platform
17
- *
18
- * - `none`: 0
19
- * - `tracking`: 1
20
- * - `restricted`: 2
21
- *
22
- */
23
- const callerAccess = ['none', 'tracking', 'restricted'];
24
- // Basic info needed for table references
25
- const TableSchemaFull = zod_1.z.object({
26
- /** lowercase, one word name. Numbers, letters and underscores only */
27
- name: zod_1.z.string(),
28
- /** Object literal of column names with <type>Column() calls as values.
29
- * Ex. { column_name_1: StringColumn({...args}), column_name_2: IntegerColumn({...args}), }
30
- * Import column definitions from `@servicenow/sdk-core/db`
31
- */
32
- schema: zod_1.z.record(zod_1.z.record(zod_1.z.any())).default({}),
33
- /** Table as a string, this table will inherit schema from extends table.
34
- * Escape with `` (import from `@servicenow/sdk-core/global`)
35
- * if table definition not present locally */
36
- extends: zod_1.z.string().optional(),
37
- /** Will match name if not provided */
38
- label: zod_1.z.string().or(zod_1.z.array(zod_1.z.any())).optional(),
39
- /** Must match column name */
40
- display: zod_1.z.string().optional(),
41
- // Controls
42
- extensible: zod_1.z.boolean().optional().default(false),
43
- live_feed: zod_1.z.boolean().optional().default(false),
44
- /** sys_number to create auto prefixing. Specify as Object literal */
45
- auto_number: zod_1.z
46
- .object({
47
- prefix: zod_1.z.string().default('pre').optional(),
48
- number: zod_1.z.number().default(1000).optional(),
49
- number_of_digits: zod_1.z.number().default(7).optional(),
50
- })
51
- .optional(),
52
- // Application Access
53
- accessible_from: zod_1.z
54
- .union([zod_1.z.literal('package_private'), zod_1.z.literal('public')])
55
- .optional()
56
- .default('public'),
57
- caller_access: zod_1.z.enum(callerAccess).optional(),
58
- /** Array of read, update, create, delete actions (['read', 'update',...])*/
59
- actions: zod_1.z
60
- .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')]))
61
- .optional(),
62
- allow_web_service_access: zod_1.z.boolean().optional().default(false),
63
- allow_new_fields: zod_1.z.boolean().optional().default(false),
64
- allow_ui_actions: zod_1.z.boolean().optional().default(false),
65
- allow_client_scripts: zod_1.z.boolean().optional().default(false),
66
- // From sys_dictionary
67
- audit: zod_1.z.boolean().optional().default(false),
68
- read_only: zod_1.z.boolean().optional().default(false),
69
- text_index: zod_1.z.boolean().optional().default(false),
70
- /** Object literal of key value pairs corresponding to attributes */
71
- attributes: zod_1.z.record(zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean()])).optional(),
72
- /** Array of objects [{ { name: <columnName>, element: ...,}...}] */
73
- index: zod_1.z
74
- .array(zod_1.z.object({
75
- name: zod_1.z.string(),
76
- unique: zod_1.z.boolean(),
77
- element: zod_1.z
78
- .string()
79
- .or(zod_1.z.array(zod_1.z.string()))
80
- .transform((el) => ((0, lodash_1.isArray)(el) ? el : [el])),
81
- }))
82
- .optional(),
83
- licensing_config: zod_1.z.record(zod_1.z.any()).optional(),
84
- scriptable_table: zod_1.z.boolean().default(false),
85
- });
86
- const componentTables = ['sys_dictionary', 'sys_choice', 'sys_documentation', 'ua_table_licensing_config'];
87
- const ColumnSchema = zod_1.z.object({
88
- entityKind: zod_1.z.string().optional(),
89
- column_type: zod_1.z.string().optional(),
90
- audit: zod_1.z.boolean().optional().default(false),
91
- label: zod_1.z.string().or(zod_1.z.array(zod_1.z.any())).optional(),
92
- maxLength: zod_1.z.number().optional(),
93
- mandatory: zod_1.z.boolean().optional().default(false),
94
- read_only: zod_1.z.boolean().optional().default(false),
95
- default: zod_1.z.any().optional(),
96
- attributes: zod_1.z.record(zod_1.z.string(), zod_1.z.union([zod_1.z.string(), zod_1.z.boolean(), zod_1.z.number()])).optional(),
97
- referenceTable: zod_1.z.string().optional(),
98
- cascadeRule: zod_1.z.string().optional(),
99
- dropdown: zod_1.z.enum(db_1.choiceDropdown).default('none').optional(),
100
- choices: zod_1.z.record(zod_1.z.any()).or(zod_1.z.array(zod_1.z.any())).optional(),
101
- choice_elements: zod_1.z.record(zod_1.z.any()).or(zod_1.z.array(zod_1.z.any())).optional(),
102
- display: zod_1.z.boolean().default(false).optional(),
103
- function_definition: zod_1.z.string().optional(),
104
- dynamic_value_definitions: zod_1.z
105
- .object({
106
- type: zod_1.z.union([
107
- zod_1.z.literal('dynamic_default'),
108
- zod_1.z.literal('choices_from_other_table'),
109
- zod_1.z.literal('calculated_value'),
110
- zod_1.z.literal('dependent_field'),
111
- ]),
112
- })
113
- .and(zod_1.z.any())
114
- .optional(),
115
- plural: zod_1.z.string().optional(),
116
- hint: zod_1.z.string().optional(),
117
- help: zod_1.z.string().optional(),
118
- widget: zod_1.z.string().optional(),
119
- table_reference: zod_1.z.boolean().optional(),
120
- reference_floats: zod_1.z.boolean().optional(),
121
- dynamic_creation: zod_1.z.boolean().optional(),
122
- dynamic_creation_script: zod_1.z.string().optional(),
123
- element_reference: zod_1.z.boolean().optional(),
124
- spell_check: zod_1.z.boolean().optional(),
125
- xml_view: zod_1.z.boolean().optional(),
126
- array: zod_1.z.boolean().optional(),
127
- text_index: zod_1.z.boolean().optional(),
128
- primary: zod_1.z.boolean().optional(),
129
- unique: zod_1.z.boolean().optional(),
130
- reference_key: zod_1.z.string().optional(),
131
- reference_qual: zod_1.z.string().optional(),
132
- });
133
- const BooleanFromString = zod_1.z
134
- .string()
135
- .transform((str) => str === 'true')
136
- .or(zod_1.z.boolean())
137
- .optional();
138
- const IntFromString = zod_1.z
139
- .string()
140
- .transform((str) => (0, lodash_1.parseInt)(str))
141
- .or(zod_1.z.number())
142
- .optional();
143
- // These fields transform from sys_db_object only, not bootstrap. (Except name, which is needed to match)
144
- const DBObjectIncomingAttributes = zod_1.z.object({
145
- name: RecordPlugin_1.TextStringSchema.or(zod_1.z.string()).optional(),
146
- read_access: RecordPlugin_1.TextBooleanSchema.or(BooleanFromString).optional(),
147
- create_access: RecordPlugin_1.TextBooleanSchema.or(BooleanFromString).optional(),
148
- update_access: RecordPlugin_1.TextBooleanSchema.or(BooleanFromString).optional(),
149
- delete_access: RecordPlugin_1.TextBooleanSchema.or(BooleanFromString).optional(),
150
- ws_access: RecordPlugin_1.TextBooleanSchema.or(BooleanFromString).optional(),
151
- caller_access: RecordPlugin_1.TextNumberSchema.or(IntFromString)
152
- .transform((val) => {
153
- if (val) {
154
- return callerAccess[val];
155
- }
156
- return;
157
- })
158
- .optional(),
159
- alter_access: RecordPlugin_1.TextBooleanSchema.or(BooleanFromString).optional(),
160
- client_scripts_access: RecordPlugin_1.TextBooleanSchema.or(BooleanFromString).optional(),
161
- actions_access: RecordPlugin_1.TextBooleanSchema.or(BooleanFromString).optional(),
162
- //configuration_access: TextBooleanSchema.or(BooleanFromString).optional().default(false),
163
- is_extendable: RecordPlugin_1.TextBooleanSchema.or(BooleanFromString).optional(),
164
- // live_feed_enabled: TextBooleanSchema.or(BooleanFromString).optional().default(false),
165
- access: RecordPlugin_1.TextStringSchema.or(zod_1.z.string()).optional(),
166
- scriptable_table: RecordPlugin_1.TextBooleanSchema.or(BooleanFromString).optional(),
167
- });
168
- // Attributes in the element='collection' tag of bootstrap xml
169
- const TableSchemaBootstrap = zod_1.z.object({
170
- name: zod_1.z.string(),
171
- extends: zod_1.z.string().optional(),
172
- label: zod_1.z.string().or(zod_1.z.array(zod_1.z.any())).optional(),
173
- // Controls
174
- extensible: zod_1.z.boolean().optional().default(false),
175
- live_feed: zod_1.z.boolean().optional().default(false),
176
- auto_number: zod_1.z
177
- .object({
178
- prefix: zod_1.z.string().default('pre').optional(),
179
- number: zod_1.z.number().default(1000).optional(),
180
- number_of_digits: zod_1.z.number().default(7).optional(),
181
- })
182
- .optional(),
183
- number_ref: zod_1.z.any().optional(),
184
- // Application Access
185
- accessible_from: zod_1.z
186
- .union([zod_1.z.literal('public'), zod_1.z.literal('package_private')])
187
- .optional()
188
- .default('public'),
189
- caller_access: zod_1.z.enum(callerAccess).default('none').optional(),
190
- actions: zod_1.z
191
- .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')]))
192
- .default(['read'])
193
- .optional(),
194
- allow_web_service_access: zod_1.z.boolean().optional().default(true),
195
- allow_new_fields: zod_1.z.boolean().optional().default(false),
196
- allow_ui_actions: zod_1.z.boolean().optional().default(false),
197
- allow_client_scripts: zod_1.z.boolean().optional().default(false),
198
- // From sys_dictionary
199
- audit: zod_1.z.boolean().optional().default(false),
200
- read_only: zod_1.z.boolean().optional().default(false),
201
- text_index: zod_1.z.boolean().optional().default(false),
202
- scriptable_table: zod_1.z.boolean().optional().default(false),
203
- attributes: zod_1.z
204
- .record(zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean()]))
205
- .default({})
206
- .optional(),
207
- });
208
- const TableSchemaBootstrapIncoming = TableSchemaBootstrap.omit({ actions: true }).extend({
209
- caller_access: zod_1.z
210
- .union([zod_1.z.literal(0), zod_1.z.literal(1), zod_1.z.literal(2)])
211
- .transform((val) => {
212
- if (val) {
213
- return callerAccess[val];
214
- }
215
- return;
216
- })
217
- .optional(),
218
- accessible_from: zod_1.z.union([zod_1.z.literal('public'), zod_1.z.literal('package_private')]).optional(),
219
- extends: zod_1.z
220
- .string()
221
- .or(zod_1.z.object({ name: zod_1.z.string() }).transform((obj) => obj.name))
222
- .optional(),
223
- live_feed: zod_1.z.boolean().optional().default(false),
224
- index: zod_1.z.any().optional(),
225
- columns: zod_1.z.any().optional(),
226
- });
227
- // Everything in side <database> in boostrap.xml
228
- const BootstrapDatabaseElement = zod_1.z.object({
229
- element: zod_1.z.record(zod_1.z.any()),
230
- });
231
- const DBObjectIncoming = zod_1.z.object({
232
- '@_table': zod_1.z.literal('sys_db_object'),
233
- sys_db_object: zod_1.z.record(zod_1.z.any()),
234
- });
235
- const SysDocumentation = zod_1.z.object({
236
- sys_documentation: zod_1.z.object({
237
- element: RecordPlugin_1.TextStringSchema.optional(),
238
- label: RecordPlugin_1.TextStringSchema.optional(),
239
- language: RecordPlugin_1.TextStringSchema.optional(),
240
- hint: RecordPlugin_1.TextStringSchema.optional(),
241
- help: RecordPlugin_1.TextStringSchema.optional(),
242
- name: RecordPlugin_1.TextStringSchema.optional(),
243
- plural: RecordPlugin_1.TextStringSchema.optional(),
244
- sys_id: RecordPlugin_1.TextStringSchema.optional(),
245
- url: RecordPlugin_1.TextStringSchema.optional(),
246
- url_target: RecordPlugin_1.TextStringSchema.optional(),
247
- }),
248
- });
249
- const LicensingConfig = zod_1.z.object({
250
- ua_table_licensing_config: zod_1.z.object({
251
- name: RecordPlugin_1.TextStringSchema.optional(),
252
- op_insert: RecordPlugin_1.TextBooleanSchema.optional(),
253
- op_update: RecordPlugin_1.TextBooleanSchema.optional(),
254
- op_delete: RecordPlugin_1.TextBooleanSchema.optional(),
255
- is_fulfillment: RecordPlugin_1.TextBooleanSchema.optional(),
256
- license_model: RecordPlugin_1.TextStringSchema.optional(),
257
- owner_condition: RecordPlugin_1.TextStringSchema.optional(),
258
- license_condition: RecordPlugin_1.TextStringSchema.optional(),
259
- license_roles: RecordPlugin_1.TextStringSchema.optional(),
260
- }),
261
- });
262
- // Attributes from element=table in bootstrap.xml
263
- const TableSchemaBootstrapAttributes = zod_1.z
264
- .object({
265
- '@_name': zod_1.z.string(),
266
- '@_extends': zod_1.z.string().optional(),
267
- '@_label': zod_1.z.string().optional(),
268
- '@_max_length': zod_1.z.any().optional(),
269
- // From sys_dictionary/sys_db_object
270
- '@_audit': BooleanFromString,
271
- '@_read_only': BooleanFromString,
272
- '@_text_index': BooleanFromString,
273
- '@_client_scripts_access': BooleanFromString,
274
- '@_ws_access': BooleanFromString,
275
- '@_alter_access': BooleanFromString,
276
- '@_create_access': BooleanFromString,
277
- '@_delete_access': BooleanFromString,
278
- '@_update_access': BooleanFromString,
279
- '@_query_access': BooleanFromString,
280
- '@_actions_access': BooleanFromString,
281
- '@_read_access': BooleanFromString,
282
- '@_is_extendable': BooleanFromString,
283
- '@_caller_access': IntFromString,
284
- '@_scriptable_table': BooleanFromString,
285
- '@_attributes': zod_1.z
286
- .string()
287
- .transform((values) => {
288
- const ret = {};
289
- if (values === '') {
290
- return undefined;
291
- }
292
- const entries = values.split(',');
293
- entries.forEach((attr) => {
294
- const s = attr.split('=');
295
- if (s.length === 2 && s[0] && s[1]) {
296
- try {
297
- ret[s[0]] = JSON.parse(s[1]);
298
- }
299
- catch (err) {
300
- ret[s[0]] = s[1];
301
- }
302
- }
303
- });
304
- return ret;
305
- })
306
- .optional(),
307
- })
308
- .catchall(zod_1.z.any());
309
- const DictionaryXmlSchema = zod_1.z.object({
310
- sys_dictionary: zod_1.z
311
- .object({
312
- '@_action': zod_1.z.union([zod_1.z.literal('INSERT_OR_UPDATE'), zod_1.z.literal('DELETE'), zod_1.z.literal('delete_multiple')]),
313
- sys_id: zod_1.z
314
- .object({
315
- '#text': zod_1.z.string().min(32).max(32).or(zod_1.z.number()),
316
- })
317
- .transform((val) => val['#text'])
318
- .optional(),
319
- '@_element': zod_1.z.string(),
320
- '@_table': zod_1.z.string(),
321
- })
322
- .catchall(zod_1.z
323
- .object({
324
- '#text': zod_1.z.union([zod_1.z.string(), zod_1.z.boolean(), zod_1.z.number(), zod_1.z.undefined()]),
325
- })
326
- .transform((val) => val['#text'])),
327
- });
328
- const IndexSchemaBootstrapAttributes = zod_1.z.object({
329
- '@_name': zod_1.z.string(),
330
- '@_unique': BooleanFromString,
331
- element: zod_1.z.object({ '@_name': zod_1.z.string() }).or(zod_1.z.array(zod_1.z.object({
332
- '@_name': zod_1.z.string(),
333
- }))),
334
- });
335
- const ColumnSchemaBootstrapAttributes = TableSchemaBootstrapAttributes.omit({ '@_extends': true })
336
- .extend({
337
- '@_choice': zod_1.z.coerce.number().optional(),
338
- '@_active': BooleanFromString,
339
- '@_mandatory': BooleanFromString,
340
- '@_display': BooleanFromString,
341
- '@_type': zod_1.z.string().optional(),
342
- '@_use_dependent_field': BooleanFromString,
343
- '@_use_dynamic_default': BooleanFromString,
344
- '@_reference': zod_1.z.string().optional(),
345
- '@_virtual': BooleanFromString,
346
- '@_default': zod_1.z.string().optional(),
347
- '@_calculation': zod_1.z.string().optional(),
348
- '@_choice_field': zod_1.z.string().optional(),
349
- '@_function_definition': zod_1.z.string().optional(),
350
- '@_reference_floats': BooleanFromString,
351
- '@_reference_key': zod_1.z.string().optional(),
352
- '@_dynamic_creation_script': zod_1.z.string().optional(),
353
- '@_dynamic_creation': BooleanFromString,
354
- '@_plural': zod_1.z.string().optional(),
355
- '@_hint': zod_1.z.string().optional(),
356
- '@_help': zod_1.z.string().optional(),
357
- '@_widget': zod_1.z.string().optional(),
358
- '@_table_reference': BooleanFromString,
359
- '@_element_reference': BooleanFromString,
360
- '@_unique': BooleanFromString,
361
- '@_spell_check': BooleanFromString,
362
- '@_xml_view': BooleanFromString,
363
- '@_array': BooleanFromString,
364
- '@_text_index': BooleanFromString,
365
- '@_primary': BooleanFromString,
366
- '@_reference_qual': zod_1.z.string().optional(),
367
- choice: zod_1.z.object({ element: zod_1.z.array(zod_1.z.any()).or(zod_1.z.record(zod_1.z.any())).optional() }).optional(),
368
- '@_attributes': zod_1.z
369
- .string()
370
- .transform((values) => {
371
- const ret = {};
372
- if (values === '') {
373
- return undefined;
374
- }
375
- const entries = values.split(',');
376
- entries.forEach((attr) => {
377
- const s = attr.split('=');
378
- if (s.length === 2 && s[0] && s[1]) {
379
- try {
380
- ret[s[0]] = JSON.parse(s[1]);
381
- }
382
- catch (err) {
383
- ret[s[0]] = s[1];
384
- }
385
- }
386
- });
387
- return ret;
388
- })
389
- .optional(),
390
- })
391
- .catchall(zod_1.z.any());
392
- const ChoiceSchema = zod_1.z.object({
393
- label: zod_1.z.string().optional(),
394
- value: zod_1.z.string().optional(),
395
- sequence: zod_1.z.coerce.number().optional(),
396
- dependent_value: zod_1.z.coerce.number().or(zod_1.z.string()).optional(),
397
- hint: zod_1.z.string().optional(),
398
- inactive: BooleanFromString.default(false).optional(),
399
- inactive_on_update: BooleanFromString.default(false).optional(),
400
- language: zod_1.z.string().optional(),
401
- });
402
- const ChoiceSchemaIncoming = ChoiceSchema.omit({ value: true });
403
- function composeLicenseConfig(tableName, config, node) {
404
- return {
405
- kind: 'ua_table_licensing_config',
406
- guid: `${tableName}_license`,
407
- data: {
408
- table: 'ua_table_licensing_config',
409
- $id: tableName,
410
- data: {
411
- name: tableName,
412
- op_insert: config.op_insert ?? true,
413
- op_update: config.op_update ?? true,
414
- op_delete: config.op_delete ?? true,
415
- is_fulfillment: config.is_fulfillment ?? false,
416
- license_model: config.license_model ?? 'none',
417
- owner_condition: config.owner_condition ?? '',
418
- license_condition: config.license_condition ?? '',
419
- license_roles: config.license_roles ? config.license_roles.join(',') : '',
420
- },
421
- },
422
- node,
423
- };
424
- }
425
- const tableNameRegex = new RegExp(`^[a-z_][a-z0-9_]*[a-z0-9]$`);
426
- exports.default = (0, sdk_build_core_1.Plugin)({
427
- name: 'Table',
428
- ownedTables: {
429
- sys_db_object: { diagnosticLevel: sdk_project_1.Diagnostic.Level.Warn },
430
- },
431
- extractors: {
432
- entity: {
433
- fluent: {
434
- // TODO: Cast to `any` is temporary workaround for the circular nature of Table entities
435
- CallExpression: (node, context) => {
436
- const result = (0, sdk_build_core_1.extractCallExpression)(db_1.Table, 'table', node, context, (table) => table.name);
437
- if (!result.handled || !result.data) {
438
- return result;
439
- }
440
- const data = result.data;
441
- const diagnostics = result.diagnostics;
442
- const scopeName = context.app.config.scope;
443
- const scopeRegex = new RegExp(`^${scopeName}_`);
444
- const columnNameRegex = new RegExp(`^[a-z_][a-z0-9_]*$`);
445
- const tableName = data.getProperty('name');
446
- const scopeMatches = tableName.getValue().match(scopeRegex);
447
- let ignoreColumnNameCheck = false;
448
- if (!tableName.getValue().match(tableNameRegex)) {
449
- 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`));
450
- }
451
- if (!scopeMatches) {
452
- const nameNode = tableName.getNode().asKindOrThrow(sdk_project_1.ts.SyntaxKind.StringLiteral);
453
- if (nameNode.getParent().getKindName() !== 'AsExpression') {
454
- diagnostics.push(new sdk_build_core_1.FluentDiagnostic(tableName.getNode(), `'name' property must start with scope prefix '${scopeName}'`));
455
- }
456
- else {
457
- ignoreColumnNameCheck = true;
458
- }
459
- }
460
- const schema = data.getProperty('schema');
461
- const schemaNode = schema.getNode().asKindOrThrow(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression);
462
- for (const columnName in schema.getValue()) {
463
- const columnNode = schemaNode.getPropertyOrThrow(columnName);
464
- if (!ignoreColumnNameCheck &&
465
- !scopeMatches &&
466
- !(0, sdk_build_core_1.isSNScope)(scopeName) &&
467
- !columnName.match(scopeRegex)) {
468
- diagnostics.push(new sdk_build_core_1.FluentDiagnostic(columnNode, `Column name must be prefixed with scope '${scopeName}' if table name does not contain prefix`));
469
- }
470
- if (!columnName.match(columnNameRegex)) {
471
- diagnostics.push(new sdk_build_core_1.FluentDiagnostic(columnNode, `Column name must only contain lowercase letters, numbers, and underscores`));
472
- }
473
- }
474
- const declaration = node.getParentIfKind(sdk_project_1.ts.SyntaxKind.VariableDeclaration);
475
- if (!declaration ||
476
- !declaration.isExported() ||
477
- !declaration.isNamedExport() ||
478
- declaration.getName() !== tableName.getValue()) {
479
- 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 }));
480
- }
481
- diagnostics.push(...(0, DBUtils_1.getLabelDiagnostics)(data));
482
- const entityData = new sdk_build_core_1.EntityData('table', tableName.getValue(), new sdk_build_core_1.ObjectData(data.getProperties(), data.getNode()), data.getNode(), data.getInstallMethod(), [tableName.getValue()]);
483
- return { handled: true, data: entityData, diagnostics };
484
- },
485
- },
486
- },
487
- xml(xml, context) {
488
- const bootstrapData = {};
489
- let dbObjectData = {};
490
- const bootstrapDatabaseXML = BootstrapDatabaseElement.safeParse(xml.data['database']);
491
- if (bootstrapDatabaseXML.success) {
492
- const data = TableSchemaBootstrapAttributes.parse(bootstrapDatabaseXML.data.element);
493
- Object.entries(data).forEach(([key, value]) => {
494
- if (key.startsWith('@_')) {
495
- bootstrapData[key.substring(2)] = value;
496
- }
497
- else if (key === 'element') {
498
- //
499
- }
500
- else {
501
- bootstrapData[key] = value;
502
- }
503
- });
504
- context.updateHandledXMLs(xml.filePath, 'handled');
505
- }
506
- const db_object_inc = DBObjectIncoming.safeParse(xml.data['record_update']);
507
- if (db_object_inc.success) {
508
- dbObjectData = DBObjectIncomingAttributes.parse(db_object_inc.data.sys_db_object);
509
- context.updateHandledXMLs(xml.filePath, 'handled');
510
- return new sdk_build_core_1.XmlData(dbObjectData, xml.filePath, 'sys_db_object', db_object_inc.data.sys_db_object['@_action']);
511
- }
512
- else if (!bootstrapDatabaseXML.success) {
513
- const record_update = xml.data['record_update'];
514
- if (record_update) {
515
- const table = Object.keys(record_update)[0];
516
- if (!table || !componentTables.includes(table)) {
517
- return;
518
- }
519
- if (table === 'sys_documentation') {
520
- const data = SysDocumentation.parse(record_update[table]).sys_documentation;
521
- return new sdk_build_core_1.XmlData({
522
- table: table,
523
- id: record_update[table][table]['sys_id']?.['#text'] ?? (0, sdk_build_core_1.GUID)(),
524
- data,
525
- }, xml.filePath, 'sys_documentation', record_update[table]['@_action']);
526
- }
527
- if (table === 'ua_table_licensing_config') {
528
- const data = LicensingConfig.parse(record_update).ua_table_licensing_config;
529
- return new sdk_build_core_1.XmlData({
530
- table: table,
531
- id: record_update[table]['sys_id']?.['#text'] ?? (0, sdk_build_core_1.GUID)(),
532
- data,
533
- }, xml.filePath, 'ua_table_licensing_config', record_update[table]['@_action']);
534
- }
535
- const data = DictionaryXmlSchema.safeParse(record_update);
536
- if (data.success) {
537
- const { '@_action': action, '@_element': element, '@_table': dictTable, sys_id, ...dict } = data.data.sys_dictionary;
538
- return new sdk_build_core_1.XmlData({
539
- table: table,
540
- id: sys_id ?? `${dict['name']}_${dict['element'] !== '' ? dict['element'] : '_null'}`,
541
- data: dict,
542
- }, xml.filePath, 'sys_dictionary', action);
543
- }
544
- context.updateHandledXMLs(xml.filePath, 'ignored');
545
- return;
546
- }
547
- }
548
- // Columns and Indexes
549
- const columns = [];
550
- const idxElements = [];
551
- if (bootstrapDatabaseXML.success && bootstrapDatabaseXML.data.element['element']) {
552
- const element = bootstrapDatabaseXML.data.element['element'];
553
- const elementsArray = (0, lodash_1.isArray)(element) ? element : [element];
554
- columns.push(...zod_1.z.array(ColumnSchemaBootstrapAttributes).parse(elementsArray));
555
- columns.forEach((element) => {
556
- if (element.choice && !(0, lodash_1.isEmpty)(element.choice)) {
557
- element['choice_elements'] = {};
558
- const choices = (0, lodash_1.isArray)(element.choice.element)
559
- ? element.choice.element
560
- : [element.choice.element];
561
- choices.forEach((choice) => {
562
- const obj = removeAttributeTag(choice);
563
- const choiceData = ChoiceSchemaIncoming.parse(obj);
564
- if (!choiceData.label) {
565
- choiceData.label = obj.value;
566
- }
567
- element['choice_elements'][obj.value] = choiceData;
568
- });
569
- }
570
- element = removeAttributeTag(element);
571
- });
572
- bootstrapData['columns'] = columns.reduce((map, obj) => ((map[obj['name']] = obj), map), {});
573
- let elements = bootstrapDatabaseXML.data.element['index'];
574
- elements = (0, lodash_1.isArray)(elements) ? elements : [elements];
575
- elements.forEach((element) => {
576
- const idxData = IndexSchemaBootstrapAttributes.safeParse(element);
577
- if (idxData.success) {
578
- idxElements.push({
579
- name: idxData.data['@_name'],
580
- element: (0, lodash_1.isArray)(idxData.data.element)
581
- ? idxData.data.element.reduce((arr, curr) => {
582
- arr.push(curr['@_name']);
583
- return arr;
584
- }, [])
585
- : idxData.data.element['@_name'],
586
- unique: idxData.data['@_unique'] ?? false,
587
- });
588
- }
589
- });
590
- bootstrapData['index'] = idxElements;
591
- }
592
- return new sdk_build_core_1.XmlData(bootstrapData, xml.filePath, 'bootstrap');
593
- },
594
- },
595
- composers: {
596
- entity: {
597
- async table(entity, context) {
598
- const node = entity.getNode();
599
- const data = entity.getValue();
600
- const table = TableSchemaFull.parse(data);
601
- const composeData = compose(table);
602
- const { columnData, documentation } = composeColumns(table.schema, context, table.name, table.display);
603
- composeData['columns'] = columnData;
604
- const entities = [];
605
- if (table.auto_number) {
606
- const data = table.auto_number;
607
- const numberRecord = SysNumber(table.name, data.number_of_digits, data.number, data.prefix);
608
- const composedNumber = await RecordPlugin_1.RecordPlugin.composers.entity.record(new sdk_build_core_1.EntityData('record', context.registerExplicitId(numberRecord.table, numberRecord.$id), sdk_build_core_1.ObjectData.fromObjectValue(numberRecord, node), node), context);
609
- entities.push(composedNumber);
610
- composeData['number_ref'] = composedNumber.guid;
611
- }
612
- documentation.forEach((doc) => {
613
- entities.push({
614
- kind: 'sys_documentation',
615
- node: node,
616
- data: doc,
617
- guid: doc.$id,
618
- });
619
- });
620
- const docs = composeDocumentation('', table.name, table.label);
621
- docs.forEach((doc) => {
622
- entities.push({
623
- kind: 'sys_documentation',
624
- node: node,
625
- data: doc,
626
- guid: doc.$id,
627
- });
628
- });
629
- composeData['index'] = table.index;
630
- if (table.licensing_config) {
631
- entities.push(composeLicenseConfig(composeData.name, table.licensing_config, node));
632
- }
633
- entities.push({
634
- kind: 'bootstrap',
635
- node,
636
- guid: composeData.name,
637
- data: { data: { bootstrapData: composeData, dbObjectData: composeData } },
638
- });
639
- return entities;
640
- },
641
- },
642
- xml: {
643
- bootstrap(xml) {
644
- return {
645
- kind: xml.kind,
646
- guid: xml.data['name'],
647
- data: { data: { bootstrapData: xml.data } },
648
- };
649
- },
650
- sys_db_object(xml) {
651
- return {
652
- kind: 'bootstrap',
653
- guid: `${xml.data['name']}`,
654
- data: { data: { dbObjectData: xml.data } },
655
- action: xml.action,
656
- };
657
- },
658
- sys_dictionary(xml) {
659
- const data = xml.data['data'];
660
- return {
661
- kind: 'sys_dictionary',
662
- guid: xml.data['id'] ??
663
- `${data['name']}_${data['element'] !== '' ? data['element'] : '_null'}`,
664
- data: xml.data,
665
- action: xml.action,
666
- };
667
- },
668
- },
669
- },
670
- arrangers: {
671
- bootstrap(_document) {
672
- return { handled: false };
673
- },
674
- sys_dictionary(document) {
675
- if (document.data.table !== 'sys_dictionary') {
676
- return { handled: false };
677
- }
678
- const tableName = document.data.data.name;
679
- return {
680
- handled: true,
681
- result: tableName ? { kind: 'bootstrap', guid: tableName } : undefined,
682
- };
683
- },
684
- },
685
- generators: {
686
- bootstrap(document, context) {
687
- const parsedBoostrapData = TableSchemaBootstrapIncoming.safeParse(document.data.data.bootstrapData);
688
- if (!parsedBoostrapData.success) {
689
- return undefined;
690
- }
691
- return (0, sdk_build_core_1.linkDocument)(document, generateNamedCallExpressionExportForDocument(context, {
692
- sourceFile: (0, sdk_build_core_1.getOrCreateEntitySourceFile)(context, parsedBoostrapData.data.name),
693
- moduleSpecifier: '@servicenow/sdk/core',
694
- exportName: parsedBoostrapData.data.name,
695
- }, db_1.Table, {}).getInitializerIfKindOrThrow(sdk_project_1.ts.SyntaxKind.CallExpression));
696
- },
697
- sys_dictionary(document, context, linkedDocuments) {
698
- const data = document.data.data;
699
- const updateName = data.sys_update_name;
700
- const table = linkedDocuments.find((doc) => doc.guid === data.name);
701
- return table && table.node
702
- ? { ...document, node: table.node }
703
- : (0, sdk_build_core_1.linkDocument)(document, (0, sdk_build_core_1.generateCallExpressionExportForDocument)(context, {
704
- sourceFile: (0, sdk_build_core_1.getOrCreateEntitySourceFile)(context, updateName ?? `sys_dictionary_${document.guid}`),
705
- moduleSpecifier: '@servicenow/sdk/core',
706
- }, db_1.Record, { $id: document.guid }).getExpressionIfKindOrThrow(sdk_project_1.ts.SyntaxKind.CallExpression));
707
- },
708
- record(document, context) {
709
- if (document.data?.['table'] !== 'sys_documentation' &&
710
- document.data?.['table'] !== 'ua_table_licensing_config') {
711
- return;
712
- }
713
- 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 }));
714
- },
715
- },
716
- serializers: {
717
- bootstrap(document) {
718
- const composedData = document.data.data;
719
- const { columns, index, attributes, ...bootstrapData } = composedData.bootstrapData;
720
- if (bootstrapData.live_feed) {
721
- // live_feed needs to be a table sys_dictionary attribute so it can be synced to sys_db_object by a startup process
722
- attributes['live_feed'] = true;
723
- }
724
- const root = (0, xmlbuilder2_1.create)({ version: '1.0' }).ele('database');
725
- const composedAttributes = composeAttributes(attributes);
726
- const collection = root.ele('element', { ...bootstrapData, attributes: composedAttributes });
727
- for (const column of Object.values(columns)) {
728
- const { choice_elements, attributes, ...parsedColumn } = column;
729
- const columnAttributes = composeAttributes(attributes);
730
- const element = collection.ele('element', { ...parsedColumn, attributes: columnAttributes });
731
- buildChoices(column, element);
732
- }
733
- buildIndexes(index, collection);
734
- return {
735
- name: `${bootstrapData.name}.xml`,
736
- directory: 'dictionary',
737
- content: root.end({ prettyPrint: true }),
738
- usedIds: [],
739
- };
740
- },
741
- sys_dictionary(_document) {
742
- // Don't serialize
743
- return undefined;
744
- },
745
- },
746
- transformers: {
747
- bootstrap: {
748
- CallExpression(document, context) {
749
- return transformTable(document, context);
750
- },
751
- },
752
- sys_dictionary: {
753
- CallExpression(document, context) {
754
- if ((0, sdk_build_core_1.getCallExpressionName)(document.node) !== db_1.Table.name) {
755
- return RecordPlugin_1.RecordPlugin.transformers.record.CallExpression(document, context);
756
- }
757
- context.logger.info(`Deferring handling of sys_dictionary '${document.guid}' values to values in bootstrap.xml '${document.parent.guid}'`);
758
- return true;
759
- },
760
- },
761
- },
762
- postProcessors: {
763
- entities(entities, context) {
764
- const { interfaces, properties, imports, namedImports } = {
765
- interfaces: [],
766
- properties: [],
767
- imports: {},
768
- namedImports: [],
769
- };
770
- const generatedTableFile = context.compiler.getGeneratedTableFile();
771
- entities
772
- .filter((entity) => entity.getKind() === 'table')
773
- .forEach((table) => {
774
- const tableName = table.getProperty('name').getValue();
775
- const extendsTable = table.getProperty('extends')?.getValue();
776
- if (tableName && tableName.trim().length > 0 && tableName.match(tableNameRegex)) {
777
- if (!context.compiler.interfaceExistsInGlobalDeclaration(tableName)) {
778
- interfaces.push({
779
- name: tableName,
780
- extends: [`Helper<typeof ${tableName}>`],
781
- });
782
- }
783
- if (!context.compiler.propertyExistsInGlobalDeclaration(tableName)) {
784
- let interfaceType = `Table<TableSchemas.${tableName}>`;
785
- if (extendsTable) {
786
- interfaceType = `Table<TableSchemas.${tableName}, "${extendsTable}">`;
787
- }
788
- properties.push({
789
- name: tableName,
790
- type: interfaceType,
791
- });
792
- }
793
- const filePath = table.getNode().getSourceFile().getFilePath();
794
- const resolvedModuleSpecifier = generatedTableFile?.getRelativePathAsModuleSpecifierTo(filePath);
795
- const importExists = context.compiler.importExistsInGlobalDeclaration(resolvedModuleSpecifier);
796
- if (!importExists) {
797
- if (imports[filePath]) {
798
- ;
799
- imports[filePath].namedImports.push(tableName);
800
- }
801
- else {
802
- imports[filePath] = {
803
- namedImports: [tableName],
804
- moduleSpecifier: resolvedModuleSpecifier,
805
- };
806
- }
807
- }
808
- else {
809
- const namedImportExists = importExists
810
- ?.getNamedImports()
811
- .find((value) => value.getName() === tableName);
812
- if (!namedImportExists) {
813
- namedImports.push({
814
- existingImport: importExists,
815
- name: tableName,
816
- });
817
- }
818
- }
819
- }
820
- });
821
- context.compiler.addTableInterfacesToGlobalDeclaration({
822
- interfaces,
823
- properties,
824
- imports,
825
- namedImports,
826
- });
827
- },
828
- },
829
- });
830
- function transformTable(document, context) {
831
- const expressionName = (0, sdk_build_core_1.getCallExpressionName)(document.node);
832
- if (expressionName !== db_1.Table.name) {
833
- return false;
834
- }
835
- const [args] = document.node.getArguments();
836
- if (!sdk_project_1.ts.Node.isObjectLiteralExpression(args)) {
837
- return false;
838
- }
839
- if (document.action === 'DELETE') {
840
- (0, sdk_build_core_1.removeNode)(document.node);
841
- return true;
842
- }
843
- if (!document.changedData) {
844
- return true;
845
- }
846
- const composedData = document.changedData.data;
847
- const xmlData = document.xmlData.data;
848
- let bootstrap_data = {};
849
- let db_data = {};
850
- if (!(0, lodash_1.isEmpty)(composedData.bootstrapData)) {
851
- // sys_db_object or node without bootstrap.xml. Mark as handled and ignore
852
- bootstrap_data = TableSchemaBootstrapIncoming.partial().parse(composedData.bootstrapData);
853
- }
854
- if (!(0, lodash_1.isEmpty)(composedData.dbObjectData)) {
855
- db_data = DBObjectIncomingAttributes.partial().parse(composedData.dbObjectData);
856
- }
857
- const { auto_number, number_ref, extends: ext, index, columns, ...bootstrap_rest } = mapNames(bootstrap_data);
858
- const { create_access, delete_access, update_access, read_access, caller_access, ...db_rest } = mapNames(db_data);
859
- const rest = { ...bootstrap_rest, ...db_rest };
860
- if (ext) {
861
- rest['extends'] = ext;
862
- }
863
- if (caller_access) {
864
- rest['caller_access'] = callerAccess[caller_access];
865
- }
866
- if (!(0, lodash_1.isEmpty)(db_data)) {
867
- rest.actions = getActionsArray(xmlData.dbObjectData);
868
- }
869
- if (!rest.attributes) {
870
- delete rest.attributes;
871
- }
872
- (0, sdk_build_core_1.transformFunctionArguments)(document.node, db_1.Table, rest);
873
- // Handle columns
874
- const incomingColumns = xmlData.bootstrapData ? xmlData.bootstrapData.columns : undefined;
875
- updateDisplayValue(document.node, columns, incomingColumns);
876
- transformColumns(columns, incomingColumns, args, context);
877
- transformIndexes(xmlData, args);
878
- return true;
879
- }
880
- function transformIndexes(xmlData, args) {
881
- if (xmlData.bootstrapData?.index?.length > 0) {
882
- // find the correct object literal
883
- const indexProp = (0, sdk_build_core_1.getPropertyAssignment)(args, 'index');
884
- if (indexProp) {
885
- (0, sdk_build_core_1.mergeDataIntoObjectLiteralArray)(indexProp.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.ArrayLiteralExpression), Object.values(xmlData.bootstrapData?.index), 'name');
886
- }
887
- else {
888
- const newIndexProp = (0, sdk_build_core_1.getOrCreatePropertyAssignment)(args, 'index', '[]');
889
- newIndexProp.setInitializer((0, sdk_build_core_1.stringify)(xmlData.bootstrapData.index));
890
- }
891
- }
892
- else if (xmlData.bootstrapData) {
893
- const indexProp = (0, sdk_build_core_1.getPropertyAssignment)(args, 'index');
894
- if (indexProp) {
895
- indexProp.remove();
896
- }
897
- }
898
- }
899
- function composeAttributes(attributes) {
900
- if (!attributes) {
901
- return '';
902
- }
903
- return Object.entries(attributes)
904
- .map(([key, value]) => `${key}=${value}`)
905
- .join(',');
906
- }
907
- function updateDisplayValue(node, columns, incomingColumns) {
908
- const display = Object.values(columns ?? {}).filter((col) => col.display);
909
- if (display) {
910
- const displayName = Object.values(incomingColumns ?? {}).find((c) => c.display);
911
- if (displayName) {
912
- (0, sdk_build_core_1.transformFunctionArguments)(node, db_1.Table, { display: displayName.name });
913
- }
914
- }
915
- }
916
- function composeDocumentation(columnName, tableName, labels) {
917
- const labelData = [];
918
- if (!labels || !(0, lodash_1.isArray)(labels)) {
919
- return labelData;
920
- }
921
- labels.forEach((label) => {
922
- const labelValue = label.label ?? columnName !== '' ? columnName : tableName;
923
- labelData.push((0, db_1.Record)({
924
- table: 'sys_documentation',
925
- $id: `${tableName}_${columnName ? columnName + '_' : ''}${label.language}`,
926
- data: { label: labelValue, element: columnName, name: tableName, ...label },
927
- }));
928
- });
929
- return labelData;
930
- }
931
- function getLabel(label) {
932
- if (!label || (0, lodash_1.isArray)(label)) {
933
- // use column name if no label specified
934
- return;
935
- }
936
- // label is an explicit string value
937
- return label;
938
- }
939
- function getDefaultMaxLength(column) {
940
- switch (column.entityKind) {
941
- case 'conditions':
942
- case 'glide_list':
943
- return 4000;
944
- case 'decimal':
945
- return 20;
946
- case 'domain_id':
947
- case 'document_id':
948
- case 'reference':
949
- return 32;
950
- case 'domain_path':
951
- case 'user_roles':
952
- return 255;
953
- case 'script':
954
- return 8000;
955
- case 'table_name':
956
- case 'field_name':
957
- return 80;
958
- default:
959
- /**
960
- * For types mentioned below it default to 40 on instance
961
- * boolean | integer | image | choice | radio | sys_class_name | translated_field | translated_text | version | glide_date | glide_date_time | calendar_date_time
962
- * datetime | due_date | integer_date | schedule_date_time | date | generic
963
- *
964
- * TODO::We need to request max_length from user for string column type because its mandatory on instance.
965
- */
966
- return 40;
967
- }
968
- }
969
- function composeColumns(columns, _context, tableName, display) {
970
- const composedColumns = {};
971
- const documentation = [];
972
- for (const [columnName, columnData] of Object.entries(columns)) {
973
- const { maxLength, ...rest } = columnData;
974
- const column = ColumnSchema.parse(rest);
975
- const requiresDropdown = column.dynamic_value_definitions || column.choices;
976
- const element = {
977
- name: columnName,
978
- type: column.entityKind === 'generic' ? column.column_type : column.entityKind,
979
- attributes: column.attributes ?? undefined,
980
- reference: column.referenceTable,
981
- reference_cascade_rule: column.referenceTable ? column.cascadeRule : undefined,
982
- audit: column.audit,
983
- label: getLabel(column.label) ?? columnName,
984
- max_length: maxLength ?? getDefaultMaxLength(column),
985
- mandatory: column.mandatory,
986
- read_only: column.read_only,
987
- choice: db_1.choiceDropdown.indexOf(column.dropdown ?? (requiresDropdown ? 'dropdown_with_none' : 'none')),
988
- display: display ? display === columnName : false,
989
- // dynamic values
990
- virtual: column.dynamic_value_definitions?.type === 'calculated_value' ? true : undefined,
991
- calculation: column.dynamic_value_definitions?.type === 'calculated_value'
992
- ? ServerModulePlugin_1.ModuleFunctionData.getGlueCode(column.dynamic_value_definitions['calculated_value'], (n) => `${n}(current)`)
993
- : undefined,
994
- choice_table: column.dynamic_value_definitions?.type === 'choices_from_other_table'
995
- ? column.dynamic_value_definitions.table
996
- : undefined,
997
- choice_field: column.dynamic_value_definitions?.type === 'choices_from_other_table'
998
- ? column.dynamic_value_definitions.field
999
- : undefined,
1000
- use_dependent_field: column.dynamic_value_definitions?.type === 'dependent_field' || undefined,
1001
- dependent: column.dynamic_value_definitions?.type === 'dependent_field'
1002
- ? column.dynamic_value_definitions['column_name']
1003
- : undefined,
1004
- default: column.default,
1005
- function_definition: column.function_definition,
1006
- function_field: column.function_definition ? true : false,
1007
- plural: column.plural,
1008
- hint: column.hint,
1009
- help: column.help,
1010
- widget: column.widget,
1011
- table_reference: column.table_reference,
1012
- element_reference: column.element_reference,
1013
- reference_key: column.reference_key,
1014
- spell_check: column.spell_check,
1015
- xml_view: column.xml_view,
1016
- reference_floats: column.reference_floats,
1017
- dynamic_creation: column.dynamic_creation,
1018
- dynamic_creation_script: column.dynamic_creation_script,
1019
- array: column.array,
1020
- text_index: column.text_index,
1021
- primary: column.primary,
1022
- unique: column.unique,
1023
- reference_qual: column.reference_qual,
1024
- };
1025
- documentation.push(...composeDocumentation(columnName, tableName, column.label));
1026
- if (column.choices) {
1027
- Object.keys(column.choices).forEach((key) => {
1028
- if ((0, lodash_1.isObject)(column.choices[key])) {
1029
- column.choices[key] = { value: key, ...column.choices[key] };
1030
- }
1031
- else {
1032
- column.choices[key] = { value: key, label: column.choices[key] };
1033
- }
1034
- });
1035
- element['choice_elements'] = zod_1.z.record(ChoiceSchema).parse(column.choices);
1036
- }
1037
- composedColumns[columnName] = element;
1038
- }
1039
- return { columnData: composedColumns, documentation };
1040
- }
1041
- function compose(bootstrapData) {
1042
- if (bootstrapData.live_feed) {
1043
- bootstrapData.attributes = {
1044
- // live_feed needs to be a table sys_dictionary attribute so it can be synced to sys_db_object by a startup process
1045
- ...bootstrapData.attributes,
1046
- live_feed: true,
1047
- };
1048
- }
1049
- const composedData = {
1050
- // Generic data
1051
- name: bootstrapData.name,
1052
- type: 'collection',
1053
- extends: bootstrapData.extends,
1054
- label: getLabel(bootstrapData.label) ?? bootstrapData.name,
1055
- // Controls
1056
- is_extendable: bootstrapData.extensible,
1057
- text_index: bootstrapData.text_index,
1058
- read_only: bootstrapData.read_only,
1059
- audit: bootstrapData.audit,
1060
- access: bootstrapData.accessible_from,
1061
- caller_access: callerAccess.indexOf(bootstrapData.caller_access ?? 'none'),
1062
- read_access: bootstrapData.actions?.includes('read'),
1063
- update_access: bootstrapData.actions?.includes('update'),
1064
- create_access: bootstrapData.actions?.includes('create'),
1065
- delete_access: bootstrapData.actions?.includes('delete'),
1066
- ws_access: bootstrapData.allow_web_service_access,
1067
- alter_access: bootstrapData.allow_new_fields,
1068
- actions_access: bootstrapData.allow_ui_actions,
1069
- client_scripts_access: bootstrapData.allow_client_scripts,
1070
- scriptable_table: bootstrapData.scriptable_table,
1071
- attributes: bootstrapData.attributes,
1072
- };
1073
- return composedData;
1074
- }
1075
- // API properties that are different in the bootstrap/sys_db_object file
1076
- const property_name_mapping = {
1077
- client_scripts_access: 'allow_client_scripts',
1078
- alter_access: 'allow_new_fields',
1079
- actions_access: 'allow_ui_actions',
1080
- ws_access: 'allow_web_service_access',
1081
- is_extendable: 'extensible',
1082
- access: 'accessible_from',
1083
- live_feed_enabled: 'live_feed',
1084
- };
1085
- function mapNames(schema) {
1086
- Object.keys(schema).forEach((key) => {
1087
- if (property_name_mapping[key]) {
1088
- schema[property_name_mapping[key]] = schema[key];
1089
- delete schema[key];
1090
- }
1091
- });
1092
- return schema;
1093
- }
1094
- function transformColumns(columns, incomingSchema, args, context) {
1095
- const schemaProperty = (0, sdk_build_core_1.getOrCreatePropertyAssignment)(args, 'schema', '{}');
1096
- if (!incomingSchema) {
1097
- return;
1098
- }
1099
- const schemaLiteral = schemaProperty.getChildrenOfKind(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression)[0];
1100
- if (!schemaLiteral) {
1101
- return;
1102
- }
1103
- const existingColumns = {};
1104
- schemaLiteral.getProperties().forEach((property) => {
1105
- const propertyAssignment = property.asKindOrThrow(sdk_project_1.ts.SyntaxKind.PropertyAssignment);
1106
- const name = propertyAssignment.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.Identifier).getText();
1107
- const callExp = propertyAssignment.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.CallExpression);
1108
- const callExpType = callExp.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.Identifier).getText();
1109
- const objectLiteral = callExp.getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression);
1110
- existingColumns[name] = {
1111
- node: propertyAssignment,
1112
- type: callExpType,
1113
- objectLiteral,
1114
- };
1115
- if (!incomingSchema[name]) {
1116
- // Full bootstrap.xml does not have this existing column so remove it
1117
- (0, sdk_build_core_1.removeNode)(propertyAssignment);
1118
- }
1119
- });
1120
- if (!columns || (0, lodash_1.isEmpty)(columns)) {
1121
- return;
1122
- }
1123
- Object.keys(incomingSchema).forEach((key) => {
1124
- const partialData = columns[key];
1125
- if (!existingColumns[key]) {
1126
- // This column doesn't exist so let's make it
1127
- const callExpFromType = getCallExpressionFromType(partialData.type);
1128
- createNewColumn(schemaLiteral, callExpFromType.name, partialData, context);
1129
- }
1130
- else {
1131
- const existingColumn = existingColumns[key];
1132
- if (partialData) {
1133
- if (partialData.type && existingColumn.type !== partialData.type) {
1134
- // Switching the column type so regenerate the CallExpression and add all incoming data
1135
- (0, sdk_build_core_1.removeNode)(existingColumn.node);
1136
- const callExpFromType = getCallExpressionFromType(partialData.type);
1137
- createNewColumn(schemaLiteral, callExpFromType.name, incomingSchema[key], context);
1138
- }
1139
- else {
1140
- // Update the existing column with changed data only
1141
- const transformedColumnData = transformColumnData(partialData, existingColumn.type);
1142
- (0, sdk_build_core_1.mergeDataIntoObjectLiteral)(existingColumn.objectLiteral, {
1143
- ...transformedColumnData,
1144
- choices: partialData.choice_elements,
1145
- });
1146
- }
1147
- }
1148
- if (existingColumn.node && !existingColumn.node.wasForgotten()) {
1149
- removeChoicesIfNecessary(existingColumn, incomingSchema[key]);
1150
- removeAttributesIfNecessary(existingColumn, incomingSchema[key]);
1151
- }
1152
- }
1153
- });
1154
- }
1155
- function removeChoicesIfNecessary(existingColumn, columnFromBootstrap) {
1156
- const existingProperties = existingColumn.objectLiteral
1157
- .getProperties()
1158
- .reduce((a, v) => ({ ...a, [(0, sdk_build_core_1.getObjectPropertyAssignmentName)(v)]: v }), {});
1159
- if (!existingProperties['choices']) {
1160
- return;
1161
- }
1162
- if (!columnFromBootstrap['choice_elements']) {
1163
- (0, sdk_build_core_1.removeNode)(existingProperties['choices']);
1164
- return;
1165
- }
1166
- const choicesFromBootstrap = Object.keys(columnFromBootstrap['choice_elements']);
1167
- const existingChoices = existingProperties['choices']
1168
- .getFirstChildByKind(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression)
1169
- .getProperties()
1170
- .reduce((a, v) => {
1171
- return {
1172
- ...a,
1173
- [(0, sdk_build_core_1.getObjectPropertyAssignmentName)(v)]: v,
1174
- };
1175
- }, {});
1176
- Object.keys(existingChoices).forEach((choice) => {
1177
- if (!choicesFromBootstrap.includes(choice)) {
1178
- (0, sdk_build_core_1.removeNode)(existingChoices[choice]);
1179
- }
1180
- });
1181
- }
1182
- function removeAttributesIfNecessary(existingColumn, columnFromBootstrap) {
1183
- const existingProperties = existingColumn.objectLiteral
1184
- .getProperties()
1185
- .reduce((a, v) => ({ ...a, [(0, sdk_build_core_1.getObjectPropertyAssignmentName)(v)]: v }), {});
1186
- if (!existingProperties['attributes']) {
1187
- return;
1188
- }
1189
- if (!columnFromBootstrap['attributes']) {
1190
- (0, sdk_build_core_1.removeNode)(existingProperties['attributes']);
1191
- return;
1192
- }
1193
- const existingAttributes = existingProperties['attributes']
1194
- .getFirstChildByKind(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression)
1195
- .getProperties()
1196
- .reduce((a, v) => ({ ...a, [(0, sdk_build_core_1.getObjectPropertyAssignmentName)(v)]: v }), {});
1197
- Object.keys(existingAttributes).forEach((attr) => {
1198
- if (!(attr in columnFromBootstrap['attributes'])) {
1199
- (0, sdk_build_core_1.removeNode)(existingAttributes[attr]);
1200
- }
1201
- });
1202
- }
1203
- function generateNamedCallExpressionExportForDocument(context, info, fn, ...args) {
1204
- const { sourceFile, moduleSpecifier } = info;
1205
- return (0, sdk_build_core_1.generateCallExpressionExport)(context, sourceFile, moduleSpecifier, info.exportName, fn, ...args);
1206
- }
1207
- function createNewColumn(schemaLiteral, callExpName, data, context) {
1208
- const propertyAssignment = schemaLiteral.addPropertyAssignment({
1209
- name: data.name,
1210
- initializer: `${callExpName}({})`,
1211
- });
1212
- const objectLiteral = propertyAssignment
1213
- .getInitializer()
1214
- .getFirstChildByKindOrThrow(sdk_project_1.ts.SyntaxKind.ObjectLiteralExpression);
1215
- const transformedColumnData = transformColumnData(data, callExpName);
1216
- (0, sdk_build_core_1.mergeDataIntoObjectLiteral)(objectLiteral, { ...transformedColumnData, choices: data.choice_elements });
1217
- (0, sdk_build_core_1.addNamedImportIfAbsent)(context, schemaLiteral.getSourceFile(), '@servicenow/sdk/core', {
1218
- name: callExpName,
1219
- });
1220
- }
1221
- function getActionsArray(data) {
1222
- const actions = [];
1223
- if (data.read_access) {
1224
- actions.push('read');
1225
- }
1226
- if (data.update_access) {
1227
- actions.push('update');
1228
- }
1229
- if (data.delete_access) {
1230
- actions.push('delete');
1231
- }
1232
- if (data.create_access) {
1233
- actions.push('create');
1234
- }
1235
- return actions;
1236
- }
1237
- function buildIndexes(indexes = [], collection) {
1238
- indexes.forEach((index) => {
1239
- const indexElement = collection.ele('index', { name: index.name, unique: index.unique });
1240
- if ((0, lodash_1.isArray)(index.element)) {
1241
- index.element.forEach((element) => {
1242
- indexElement.ele('element', { name: element });
1243
- });
1244
- }
1245
- else {
1246
- indexElement.ele('element', { name: index.element });
1247
- }
1248
- });
1249
- }
1250
- function buildChoices(column, element) {
1251
- if (!column.choice_elements) {
1252
- return;
1253
- }
1254
- const choices = element.ele('choice');
1255
- if (Array.isArray(column.choices) && column.choices.length > 0) {
1256
- // Formatted - choices: [1, 2, 3, 4]
1257
- for (const choice in column.choices) {
1258
- choices.ele('element', {
1259
- value: column.choices[choice],
1260
- label: column.choices[choice],
1261
- });
1262
- }
1263
- }
1264
- else {
1265
- // Formatted - choices: { 1: { label: 'label' }, 2: { lable: label 2}, ...}
1266
- Object.entries(column.choice_elements).forEach((value) => {
1267
- if ((0, lodash_1.isObject)(value[1])) {
1268
- choices.ele('element', {
1269
- value: value[0],
1270
- ...value[1],
1271
- });
1272
- }
1273
- else {
1274
- choices.ele('element', {
1275
- value: value[1],
1276
- label: value[0],
1277
- });
1278
- }
1279
- });
1280
- }
1281
- }
1282
- function transformColumnData(col, callExpFromType) {
1283
- 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, reference_qual_condition, ...column } = col;
1284
- if (max_length !== undefined) {
1285
- column.maxLength = (0, lodash_1.parseInt)(max_length, 10);
1286
- }
1287
- if (internal_type && callExpFromType === 'GenericColumn') {
1288
- column.column_type = internal_type;
1289
- }
1290
- if (choice !== undefined) {
1291
- column.dropdown = db_1.choiceDropdown[choice];
1292
- }
1293
- if (reference) {
1294
- column.referenceTable = reference;
1295
- }
1296
- if (reference_cascade_rule) {
1297
- column.cascadeRule = reference_cascade_rule;
1298
- }
1299
- // Handle dynamic values
1300
- if (calculation) {
1301
- column.dynamic_value_definitions = {
1302
- type: 'calculated_value',
1303
- calculated_value: calculation,
1304
- };
1305
- }
1306
- else if (choice_table || choice_field) {
1307
- column.dynamic_value_definitions = {
1308
- type: 'choices_from_other_table',
1309
- table: choice_table,
1310
- field: choice_field,
1311
- };
1312
- }
1313
- else if (dependent) {
1314
- column.dynamic_value_definitions = {
1315
- type: 'dependent_field',
1316
- column_name: dependent,
1317
- };
1318
- }
1319
- else if (def) {
1320
- column.default = def;
1321
- }
1322
- else if (default_value) {
1323
- column.default = default_value;
1324
- }
1325
- if (column.label && column.label === name) {
1326
- delete column.label;
1327
- }
1328
- if ((0, lodash_1.isEmpty)(column.attributes)) {
1329
- delete column.attributes;
1330
- }
1331
- else if (isDefaultEdgeEncryptionAttribute(column.attributes)) {
1332
- delete column.attributes;
1333
- }
1334
- return column;
1335
- }
1336
- // The instance will sometimes add edge_encryption_enabled=true, this is a default so don't write it if it is the only one
1337
- function isDefaultEdgeEncryptionAttribute(attributes) {
1338
- return (attributes &&
1339
- Object.entries(attributes).length === 1 &&
1340
- attributes.edge_encryption_enabled !== undefined &&
1341
- attributes.edge_encryption_enabled);
1342
- }
1343
- function removeAttributeTag(obj) {
1344
- Object.entries(obj).forEach(([key, value]) => {
1345
- if (key.startsWith('@_')) {
1346
- obj[key.substring(2)] = value;
1347
- delete obj[key];
1348
- }
1349
- });
1350
- return obj;
1351
- }
1352
- function SysNumber(category, maximum_digits, number, prefix) {
1353
- return (0, db_1.Record)({
1354
- table: 'sys_number',
1355
- $id: `${category}_${prefix}`,
1356
- data: {
1357
- category,
1358
- maximum_digits: maximum_digits ?? 1000,
1359
- number: number ?? 7,
1360
- prefix: prefix ?? 'PRE',
1361
- },
1362
- });
1363
- }
1364
- function generateColumnExpression(expression, args, argsSetIfDefined) {
1365
- const setArgs = { ...args };
1366
- if (argsSetIfDefined) {
1367
- Object.keys(argsSetIfDefined).forEach((key) => {
1368
- if (argsSetIfDefined[key] !== undefined) {
1369
- setArgs[key] = argsSetIfDefined[key];
1370
- }
1371
- });
1372
- }
1373
- return sdk_project_1.tsc.factory.createCallExpression(sdk_project_1.tsc.factory.createIdentifier(expression.name), undefined, [
1374
- createObjectExpression(setArgs),
1375
- ]);
1376
- }
1377
- function createObjectExpression(firstArg) {
1378
- return sdk_project_1.tsc.factory.createObjectLiteralExpression(Object.entries(firstArg)
1379
- .filter(([_key, value]) => value !== undefined)
1380
- .map(([key, value]) => {
1381
- if (key === 'referenceTable') {
1382
- return sdk_project_1.tsc.factory.createPropertyAssignment(sdk_project_1.tsc.factory.createIdentifier('referenceTable'), sdk_project_1.tsc.factory.createStringLiteral(value));
1383
- }
1384
- else if (key === 'calculated_value') {
1385
- 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(value, value)));
1386
- }
1387
- else if (key === 'maxLength') {
1388
- if (isNaN(+value)) {
1389
- 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)));
1390
- }
1391
- return sdk_project_1.tsc.factory.createPropertyAssignment(sdk_project_1.tsc.factory.createIdentifier(key), sdk_project_1.tsc.factory.createNumericLiteral(value));
1392
- }
1393
- return sdk_project_1.tsc.factory.createPropertyAssignment((0, sdk_build_core_1.createPropertyIdentifier)(key), factoryCreateValue(value, sdk_project_1.tsc.factory));
1394
- }));
1395
- }
1396
- function factoryCreateValue(value, factory) {
1397
- if (typeof value === 'string') {
1398
- return factory.createStringLiteral(value);
1399
- }
1400
- if (typeof value === 'number') {
1401
- if (value >= 0) {
1402
- return factory.createNumericLiteral(value);
1403
- }
1404
- else {
1405
- return factory.createPrefixUnaryExpression(sdk_project_1.tsc.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
1406
- }
1407
- }
1408
- if (typeof value === 'boolean') {
1409
- return value ? factory.createTrue() : factory.createFalse();
1410
- }
1411
- if (typeof value === 'object') {
1412
- if (value === null) {
1413
- return factory.createNull();
1414
- }
1415
- if ((0, lodash_1.isArray)(value)) {
1416
- const newvals = [];
1417
- Object.values(value).forEach((v) => {
1418
- newvals.push(factoryCreateValue(v, factory));
1419
- });
1420
- return factory.createArrayLiteralExpression(newvals);
1421
- }
1422
- else if (sdk_project_1.ts.Structure.isImportSpecifier(value)) {
1423
- return factory.createIdentifier(value['name']);
1424
- }
1425
- else {
1426
- return createObjectExpression(value);
1427
- }
1428
- }
1429
- return factory.createNull();
1430
- // throw new Error(`Unsupported value type: ${typeof value}`)
1431
- }
1432
- function getCallExpressionFromType(internal_type) {
1433
- switch (internal_type) {
1434
- case undefined:
1435
- case 'string':
1436
- return db_1.StringColumn;
1437
- case 'boolean':
1438
- return db_1.BooleanColumn;
1439
- case 'choice':
1440
- return db_1.ChoiceColumn;
1441
- case 'conditions':
1442
- return db_1.ConditionsColumn;
1443
- case 'date':
1444
- return db_1.OtherDateColumn;
1445
- case 'calendar_date_time':
1446
- return db_1.CalendarDateTimeColumn;
1447
- case 'datetime':
1448
- return db_1.BasicDateTimeColumn;
1449
- case 'due_date':
1450
- return db_1.DueDateColumn;
1451
- case 'glide_date':
1452
- return db_1.DateColumn;
1453
- case 'glide_date_time':
1454
- return db_1.DateTimeColumn;
1455
- case 'integer_date':
1456
- return db_1.IntegerDateColumn;
1457
- case 'schedule_date_time':
1458
- return db_1.ScheduleDateTimeColumn;
1459
- case 'decimal':
1460
- return db_1.DecimalColumn;
1461
- case 'document_id':
1462
- return db_1.DocumentIdColumn;
1463
- case 'domain_id':
1464
- return db_1.DomainIdColumn;
1465
- case 'domain_path':
1466
- return db_1.DomainPathColumn;
1467
- case 'field_name':
1468
- return db_1.FieldNameColumn;
1469
- case 'integer':
1470
- return db_1.IntegerColumn;
1471
- case 'radio':
1472
- return db_1.RadioColumn;
1473
- case 'reference':
1474
- return db_1.ReferenceColumn;
1475
- case 'script':
1476
- return db_1.ScriptColumn;
1477
- case 'sys_class_name':
1478
- return db_1.SystemClassNameColumn;
1479
- case 'table_name':
1480
- return db_1.TableNameColumn;
1481
- case 'translated_field':
1482
- return db_1.TranslatedFieldColumn;
1483
- case 'translated_text':
1484
- return db_1.TranslatedTextColumn;
1485
- case 'user_roles':
1486
- return db_1.UserRolesColumn;
1487
- case 'version':
1488
- return db_1.VersionColumn;
1489
- case 'glide_list':
1490
- return db_1.ListColumn;
1491
- case 'image':
1492
- return db_1.BasicImageColumn;
1493
- case 'int':
1494
- case 'string_types':
1495
- case 'approval_rules':
1496
- case 'audio':
1497
- case 'auto_increment':
1498
- case 'auto_number':
1499
- case 'bootstrap_color':
1500
- case 'breakdown_element':
1501
- case 'catalog_preview':
1502
- case 'char':
1503
- case 'collection':
1504
- case 'color':
1505
- case 'color_display':
1506
- case 'composite_field':
1507
- case 'composite_name':
1508
- case 'compressed':
1509
- case 'condition_string':
1510
- case 'counter':
1511
- case 'css':
1512
- case 'currency':
1513
- case 'currency2':
1514
- case 'data_array':
1515
- case 'data_object':
1516
- case 'data_structure':
1517
- case 'days_of_week':
1518
- case 'day_of_week':
1519
- case 'documentation_field':
1520
- case 'dynamic_json':
1521
- case 'email':
1522
- case 'email_script':
1523
- case 'expression':
1524
- case 'external_names':
1525
- case 'field_list':
1526
- case 'file_attachment':
1527
- case 'float':
1528
- case 'formula':
1529
- case 'geo_point':
1530
- case 'glide_action_list':
1531
- case 'glide_duration':
1532
- case 'glide_precise_time':
1533
- case 'glide_time':
1534
- case 'glide_utc_time':
1535
- case 'glide_var':
1536
- case 'glyphicon':
1537
- case 'graphql_schema':
1538
- case 'GUID':
1539
- case 'html':
1540
- case 'html_script':
1541
- case 'html_template':
1542
- case 'icon':
1543
- case 'index_name':
1544
- case 'insert_timestamp':
1545
- case 'integer_time':
1546
- case 'internal_type':
1547
- case 'ip_addr':
1548
- case 'ip_address':
1549
- case 'journal':
1550
- case 'journal_input':
1551
- case 'journal_list':
1552
- case 'json':
1553
- case 'json_translations':
1554
- case 'language':
1555
- case 'long':
1556
- case 'longint':
1557
- case 'mask_code':
1558
- case 'metric_absolute':
1559
- case 'metric_counter':
1560
- case 'metric_derive':
1561
- case 'metric_gauge':
1562
- case 'mid_config':
1563
- case 'month_of_year':
1564
- case 'multi_small':
1565
- case 'multi_two_lines':
1566
- case 'name_values':
1567
- case 'nds_icon':
1568
- case 'nl_task_int1':
1569
- case 'order_index':
1570
- case 'password':
1571
- case 'password2':
1572
- case 'percent_complete':
1573
- case 'phone_number':
1574
- case 'phone_number_e164':
1575
- case 'ph_number':
1576
- case 'price':
1577
- case 'properties':
1578
- case 'records':
1579
- case 'reference_name':
1580
- case 'related_tags':
1581
- case 'reminder_field_name':
1582
- case 'repeat_count':
1583
- case 'repeat_type':
1584
- case 'replication_payload':
1585
- case 'schedule_interval_count':
1586
- case 'script_client':
1587
- case 'script_plain':
1588
- case 'script_server':
1589
- case 'short_field_name':
1590
- case 'short_table_name':
1591
- case 'simple_name_values':
1592
- case 'slushbucket':
1593
- case 'snapshot_template_value':
1594
- case 'source_id':
1595
- case 'source_name':
1596
- case 'source_table':
1597
- case 'string_boolean':
1598
- case 'string_full_utf8':
1599
- case 'structure':
1600
- case 'sysevent_name':
1601
- case 'sysrule_field_name':
1602
- case 'sys_class_path':
1603
- case 'template_value':
1604
- case 'time':
1605
- case 'timer':
1606
- case 'translated':
1607
- case 'translated_html':
1608
- case 'tree_code':
1609
- case 'tree_path':
1610
- case 'url':
1611
- case 'user_image':
1612
- case 'user_input':
1613
- case 'variables':
1614
- case 'variable_conditions':
1615
- case 'variable_template_value':
1616
- case 'video':
1617
- case 'week_of_month':
1618
- case 'wide_text':
1619
- case 'wiki_text':
1620
- case 'wms_job':
1621
- case 'workflow':
1622
- case 'workflow_conditions':
1623
- case 'xml':
1624
- default:
1625
- return db_1.GenericColumn;
1626
- }
1627
- }
1628
- //# sourceMappingURL=TablePlugin.js.map