@servicenow/sdk-build-plugins 3.0.3 → 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 -1630
  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 -2072
  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,569 +0,0 @@
1
- /* eslint-disable no-case-declarations */
2
- import { ts, tsc } from '@servicenow/sdk-project'
3
- import {
4
- Context,
5
- Document,
6
- Result,
7
- DocumentPointer,
8
- removeNode,
9
- getCallExpressionName,
10
- Arranged,
11
- UnlinkedDocument,
12
- getNodeId,
13
- EntityData,
14
- ObjectData,
15
- Data,
16
- } from '@servicenow/sdk-build-core'
17
- import { isEqual } from 'lodash'
18
- import { RestApi } from '@servicenow/sdk-core/runtime/rest'
19
- import { RecordPlugin } from '../db/RecordPlugin'
20
- import { SupportedNode } from '@servicenow/sdk-project'
21
-
22
- export const restTables = [
23
- 'sys_ws_definition',
24
- 'sys_ws_operation',
25
- 'sys_ws_version',
26
- 'sys_ws_header',
27
- 'sys_ws_query_parameter',
28
- 'sys_ws_header_map',
29
- 'sys_ws_query_parameter_map',
30
- ]
31
-
32
- let restDocumentMap: any = undefined
33
-
34
- /** checks if a given query_parameter or header doc is consumed by the given rest or not in current transformation*/
35
- const isConsumedByRest = (restId: string, restDocMap: any, document: Document) => {
36
- if (restDocMap[restId] && restDocMap[restId].route_attrs_map) {
37
- const found = Object.values(restDocMap[restId].route_attrs_map).find(
38
- (doc: any) =>
39
- doc.data['data'].web_service_query_parameter === document.guid ||
40
- doc.data['data'].web_service_header === document.guid
41
- )
42
- return found ? true : false
43
- }
44
- return false
45
- }
46
-
47
- export function getRouteAttrMapResult(document: Document, restDocMap: any): Result<DocumentPointer | undefined> {
48
- if (document.action === 'DELETE') {
49
- return { handled: false }
50
- }
51
- /**
52
- * if the given attribute map record references query parameter or routes record
53
- * not part of the current app we make it a record call.
54
- */
55
- const isUnHandled = restDocMap['unHandled_records'].find((doc) => doc.guid === document.guid)
56
- if (isUnHandled) {
57
- return { handled: false }
58
- }
59
-
60
- const routeId = document.data!['data']['web_service_operation']
61
- const paramField =
62
- document.data!['table'] === 'sys_ws_header_map' ? 'web_service_header' : 'web_service_query_parameter'
63
- potentialRecordCallRouteParams.delete(document.data!['data'][paramField])
64
- /** if the attribute map record is consumed by any rest then associated appropriate parent */
65
- return { handled: true, result: { kind: 'record', guid: routeId } }
66
- }
67
-
68
- /** utility function to get the args node of a call expression node*/
69
- export const getArgs = (document: Document) => {
70
- const node = document.node!.asKindOrThrow(ts.SyntaxKind.CallExpression)
71
- return node.getArguments()[0]!.asKindOrThrow(ts.SyntaxKind.ObjectLiteralExpression)
72
- }
73
-
74
- /**
75
- * utility function that iterates over all the headers or parameters of all routes
76
- * inside a rest api and calls the provided callback function.
77
- */
78
- function iterateAllRouteAttrNode(
79
- document: Document,
80
- eleAttrName: string,
81
- callback: (
82
- expression: ts.ArrayLiteralExpression,
83
- element: ts.Expression,
84
- compositeKey: { attr: string; route: string; rest: string }
85
- ) => void
86
- ) {
87
- const argsNode = getArgs(document)
88
- const restId = getNodeId(argsNode)!
89
- argsNode
90
- .getProperty('routes')
91
- ?.asKind(tsc.SyntaxKind.PropertyAssignment)
92
- ?.getInitializerIfKindOrThrow(tsc.SyntaxKind.ArrayLiteralExpression)
93
- ?.getElements()
94
- .forEach((element) => {
95
- const routeId = getNodeId(element.asKindOrThrow(ts.SyntaxKind.ObjectLiteralExpression))!
96
- const arrayExpression = element
97
- .asKind(tsc.SyntaxKind.ObjectLiteralExpression)
98
- ?.getProperty(eleAttrName)
99
- ?.asKind(tsc.SyntaxKind.PropertyAssignment)
100
- ?.getInitializerIfKindOrThrow(tsc.SyntaxKind.ArrayLiteralExpression)
101
-
102
- arrayExpression?.getElements().forEach((element) => {
103
- const attrId = getNodeId(element.asKindOrThrow(ts.SyntaxKind.ObjectLiteralExpression))!
104
- callback(arrayExpression, element, {
105
- attr: attrId,
106
- route: routeId,
107
- rest: restId,
108
- })
109
- })
110
- })
111
- }
112
-
113
- /**
114
- * keeps track of all those params records associated with a rest node,
115
- * so if some m2m records removes all its associations then we would create record call.
116
- */
117
- export const potentialRecordCallRouteParams = new Set<string>()
118
- /**
119
- * There are some of the completely unassociated param records generated when an
120
- * m2m record swtiches from one rest to another rest entity. we track them to generate records calls
121
- * if required.
122
- */
123
- export const completelyUnassociatedParamIds = new Set<string>()
124
- /**
125
- * Ids of records which are going to be a record call so need not handle them in rest generator.
126
- */
127
- export const unHandledIds: string[] = []
128
-
129
- /** Based on the result it adds the document id to unHandledIds which is later on used by generator
130
- * to avoid generating nodes for them since it's expected to be handled by record plugin.
131
- */
132
- export function handleAndReturnResult(result: Result<DocumentPointer | undefined>, document: Document) {
133
- if (!result.handled) {
134
- unHandledIds.push(document.guid)
135
- }
136
- return result
137
- }
138
-
139
- /**
140
- * Performs the following operations:
141
- * 1. If the documents associated rest node is the same as the referenced rest in data, let the rest node handle it.
142
- * 2. If it refernces a different rest node, then clean up the current rest node and its keys. If the referenced rest node
143
- * has a mapping record to consume this parameter or header let it handle, else make it a record call.
144
- */
145
- export function getRouteAttrWithRestNodeResult(
146
- document: Document,
147
- context: Context,
148
- restDocMap: any
149
- ): Result<DocumentPointer | undefined> {
150
- const restId = document.data!['data']['web_service_definition']
151
- const nodeId = getNodeId(getArgs(document))!
152
- const nodeRestId = context.keys.explicit[nodeId]!.id
153
- if (document.action === 'DELETE') {
154
- return { handled: true, result: { kind: 'record', guid: nodeRestId } }
155
- }
156
- if (restId === nodeRestId) {
157
- /**
158
- * Handles the case where the attribute associated with the rest node is not consumed by any m2m record.
159
- * Probabal cause is it's being removed from the rest node and needs a separate record call.
160
- */
161
- if (!isConsumedByRest(restId, restDocMap, document)) {
162
- deleteDocNode(document, context)
163
- document['changedData'] = { data: document.data!['data'] }
164
- const expKey = context.keys.findExplicitKeyById(document.guid)
165
- if (expKey) {
166
- delete context.keys.explicit[expKey]
167
- }
168
- potentialRecordCallRouteParams.delete(document.guid)
169
- return { handled: false }
170
- }
171
- return { handled: true, result: { kind: 'record', guid: restId } }
172
- }
173
- const attrName = document.data!['table'] === 'sys_ws_header' ? 'headers' : 'parameters'
174
- let deleteAttrKey: string | undefined = undefined
175
- iterateAllRouteAttrNode(document, attrName, (arrayExp, element, compKey) => {
176
- const attrSysId = context.keys.explicit[compKey.attr]!.id
177
- if (attrSysId === document.guid) {
178
- deleteAttrKey = compKey.attr
179
- const idx = context.keys.composite.findIndex((k) => isEqual(k.key, compKey))
180
- if (idx !== -1) {
181
- context.keys.composite.splice(idx, 1)
182
- }
183
- arrayExp.removeElement(element)
184
- }
185
- })
186
- if (deleteAttrKey) {
187
- delete context.keys.explicit[deleteAttrKey]
188
- }
189
- potentialRecordCallRouteParams.delete(document.guid)
190
- deleteDocNode(document, context)
191
- document['changedData'] = { data: document.data!['data'] }
192
- if (!isConsumed(document, restDocMap)) {
193
- return { handled: false }
194
- }
195
- return { handled: true, result: { kind: 'record', guid: restId } }
196
- }
197
-
198
- function isConsumed(document: Document, restDocMap: any) {
199
- const restId = document.data!['data']['web_service_definition']
200
- const isUnHandled = restDocMap['unHandled_records'].find((doc) => doc.guid === document.guid)
201
- if (isUnHandled) {
202
- return false
203
- }
204
-
205
- return isConsumedByRest(restId, restDocMap, document)
206
- }
207
-
208
- /**
209
- * Deletes node reference from document and updates in context docs as well to keep it updated.
210
- */
211
- const deleteDocNode = (document: Document, context: Context) => {
212
- const foundDoc = context.getAllDocuments().find((doc) => doc.guid === document.guid)
213
- delete foundDoc?.node
214
- delete document.node
215
- }
216
-
217
- /**
218
- * checks to see if the document is consumed by any rest api. If consumed then
219
- * remove that record call expression and its associated keys and let rest handle
220
- * it, else update the record call.
221
- */
222
- export function getRouteAttrWithRecordNodeResult(
223
- document: Document,
224
- context: Context,
225
- restDocMap: any
226
- ): Result<DocumentPointer | undefined> {
227
- if (document.action === 'DELETE') {
228
- return { handled: false }
229
- }
230
- if (!isConsumed(document, restDocMap)) {
231
- return { handled: false }
232
- }
233
- const recordId = getNodeId(getArgs(document))!
234
- removeNodeAndCleanUpExport(document.node!)
235
- deleteDocNode(document, context)
236
- delete context.keys.explicit[recordId]
237
- document['changedData'] = { data: document.data!['data'] }
238
- return { handled: true, result: { kind: 'record', guid: document.data!['data']['web_service_definition'] } }
239
- }
240
-
241
- /** Gets the rest id for the given route id.*/
242
- const getRestIdForRoute = (routeId: string, restDocMap: any) => {
243
- let restId: string | undefined = undefined
244
- Object.keys(restDocMap)
245
- .filter((key) => key !== 'unHanlded_records' && key !== 'delete_records')
246
- .forEach((key) => {
247
- if (restDocMap[key].routes) {
248
- const foundRoute = Object.values(restDocMap[key].routes).find(
249
- (doc) => (doc as Document).guid === routeId
250
- )
251
- if (foundRoute) {
252
- restId = key
253
- }
254
- }
255
- })
256
- return restId
257
- }
258
-
259
- /** cleans the mapping node from given array and keys file*/
260
- const cleanMapDocInNode = (
261
- arrayExp: ts.ArrayLiteralExpression,
262
- element: ts.Expression,
263
- compKey: { attr: string; route: string; rest: string },
264
- context: Context,
265
- document: Document
266
- ) => {
267
- const idx = context.keys.composite.findIndex((k) => isEqual(k.key, compKey))
268
- if (idx !== -1) {
269
- const compObj = context.keys.composite[idx]
270
- if (compObj?.id === document.guid) {
271
- arrayExp.removeElement(element)
272
- context.keys.composite.splice(idx, 1)
273
- return context.keys.explicit[compKey.attr]?.id
274
- }
275
- }
276
- return undefined
277
- }
278
-
279
- /**
280
- * Performs the following operations:
281
- * 1. If the mapping record references a differnt route or query param not part of the app
282
- * then clean its presence from current rest node and create a record call for it.
283
- * 2. If if references a different route and query param in same app, the clean current rest
284
- * and update the new rest node.
285
- * 3. If references same rest then update it.
286
- *
287
- * In addition to that, it also tracks the params unassociated to create record call if needed.
288
- */
289
- export function getRouteAttrMapWithRestNodeResult(
290
- document: Document,
291
- context: Context,
292
- restDocMap: any
293
- ): Result<DocumentPointer | undefined> {
294
- const restNodeId = getNodeId(getArgs(document))
295
- const restNodeSysId = context.keys.explicit[restNodeId!]!.id
296
- const routeId = document.data!['data']['web_service_operation']
297
- if (document.action === 'DELETE') {
298
- return { handled: true, result: { kind: 'record', guid: routeId } }
299
- }
300
- const isUnHandled = restDocMap['unHandled_records'].find((doc: Document) => doc.guid === document.guid)
301
- const attrName = document.data!['table'] === 'sys_ws_header_map' ? 'headers' : 'parameters'
302
- if (isUnHandled) {
303
- let unAssociatedId: string | undefined = undefined
304
- document['changedData'] = { data: document.data!['data'] }
305
- iterateAllRouteAttrNode(document, attrName, (arrayExp, element, compKey) => {
306
- unAssociatedId = unAssociatedId ?? cleanMapDocInNode(arrayExp, element, compKey, context, document)
307
- })
308
- if (unAssociatedId) {
309
- if (!isParamAssociated(document, attrName, context, unAssociatedId)) {
310
- completelyUnassociatedParamIds.add(unAssociatedId)
311
- }
312
- }
313
- deleteDocNode(document, context)
314
- return { handled: false }
315
- }
316
- const paramField =
317
- document.data!['table'] === 'sys_ws_header_map' ? 'web_service_header' : 'web_service_query_parameter'
318
- potentialRecordCallRouteParams.delete(document.data!['data'][paramField])
319
- const restId = getRestIdForRoute(routeId, restDocMap)!
320
- if (restId !== restNodeSysId) {
321
- let unAssociatedId: string | undefined = undefined
322
- document['changedData'] = { data: document.data!['data'] }
323
- iterateAllRouteAttrNode(document, attrName, (arrayExp, element, compKey) => {
324
- unAssociatedId = unAssociatedId ?? cleanMapDocInNode(arrayExp, element, compKey, context, document)
325
- })
326
- if (unAssociatedId) {
327
- if (!isParamAssociated(document, attrName, context, unAssociatedId)) {
328
- completelyUnassociatedParamIds.add(unAssociatedId)
329
- }
330
- }
331
- deleteDocNode(document, context)
332
- }
333
- return { handled: true, result: { kind: 'record', guid: routeId } }
334
- }
335
-
336
- /**
337
- * Performs following operation
338
- * 1. If given mapping record references some routes or param not in app update the record call.
339
- * 2. If references some existing route and param, then remove the current record call and its keys.
340
- * Update the new rest node.
341
- */
342
- export function getRouteAttrMapWithRecordNodeResult(
343
- document: Document,
344
- context: Context,
345
- restDocMap: any
346
- ): Result<DocumentPointer | undefined> {
347
- if (document.action === 'DELETE') {
348
- return { handled: false }
349
- }
350
- const routeId = document.data!['data']['web_service_operation']
351
- const isUnHandled = restDocMap['unHandled_records'].find((doc: Document) => doc.guid === document.guid)
352
- if (isUnHandled) {
353
- return { handled: false }
354
- }
355
- document['changedData'] = { data: document.data!['data'] }
356
- const recordId = getNodeId(getArgs(document))!
357
- const paramField =
358
- document.data!['table'] === 'sys_ws_header_map' ? 'web_service_header' : 'web_service_query_parameter'
359
- potentialRecordCallRouteParams.delete(document.data!['data'][paramField])
360
- removeNodeAndCleanUpExport(document.node!)
361
- deleteDocNode(document, context)
362
- delete context.keys.explicit[recordId]
363
- return { handled: true, result: { kind: 'record', guid: routeId } }
364
- }
365
-
366
- /**
367
- * If the incoming parameter or header record is consumed by rest associated it to the rest node, else make it a record call.
368
- */
369
- export function getRouteAttrResult(document: Document, restDocMap: any): Result<DocumentPointer | undefined> {
370
- if (document.action === 'DELETE') {
371
- return { handled: false }
372
- }
373
- const restId = document.data!['data']['web_service_definition']
374
- if (isConsumedByRest(restId, restDocMap, document)) {
375
- return { handled: true, result: { kind: 'record', guid: restId } }
376
- }
377
- return { handled: false }
378
- }
379
-
380
- const findRecInDocs = (docs: Document[], id: string, table: string) => {
381
- return docs?.find((doc) => doc.data!['table'] === table && doc.guid == id)
382
- }
383
-
384
- export function getRestDocumentMap(context: Context) {
385
- if (restDocumentMap) {
386
- return restDocumentMap
387
- }
388
- /**gets all rest related docs */
389
- const allRestDocs = context.getAllDocuments().filter((doc) => restTables.includes(doc.data!['table']))
390
- allRestDocs.sort((doc1, doc2) => {
391
- const doc1Table = doc1.data!['table']
392
- const doc2Table = doc2.data!['table']
393
- return restTables.indexOf(doc1Table) - restTables.indexOf(doc2Table)
394
- })
395
- const unHandledDocs: Document[] = []
396
- /** filters and gets all delete records and insert_or_update records */
397
- const delRestDocs = allRestDocs.filter((doc) => doc.action === 'DELETE')
398
- const existingDocs = allRestDocs.filter((doc) => doc.action !== 'DELETE')
399
- existingDocs.map((doc) => {
400
- const table = doc.data!['table']
401
- if (
402
- (table === 'sys_ws_query_parameter' || table === 'sys_ws_header') &&
403
- doc.node &&
404
- getCallExpressionName(doc.node as ts.CallExpression) === RestApi.name
405
- ) {
406
- potentialRecordCallRouteParams.add(doc.guid)
407
- }
408
- })
409
- /**
410
- * Generates the rest document map with insert or udpate records
411
- * and includes only mapping records that are being transformed (this is needed to determine if an
412
- * parameter or header record will be consumed by rest in current transformation)
413
- */
414
- restDocumentMap = existingDocs.reduce((docMap, doc) => {
415
- switch (doc.data!['table']) {
416
- case 'sys_ws_definition':
417
- docMap[doc.guid] = {
418
- restDef: doc,
419
- }
420
- break
421
- case 'sys_ws_operation':
422
- const op_restId = doc.data!['data']['web_service_definition']
423
- if (docMap[op_restId]) {
424
- ;(docMap[op_restId].routes ??= {})[doc.guid] = doc
425
- }
426
- break
427
- case 'sys_ws_version':
428
- const v_restId = doc.data!['data']['web_service_definition']
429
- if (docMap[v_restId]) {
430
- ;(docMap[v_restId].versions ??= {})[doc.guid] = doc
431
- }
432
- break
433
- case 'sys_ws_query_parameter':
434
- case 'sys_ws_header':
435
- const qp_restId = doc.data!['data']['web_service_definition']
436
- if (docMap[qp_restId]) {
437
- ;(docMap[qp_restId].route_attrs ??= {})[doc.guid] = doc
438
- } else {
439
- //throw error if the transforming doc references a deleted record
440
- if (doc.changedData) {
441
- const found = findRecInDocs(delRestDocs, qp_restId, 'sys_ws_definition')
442
- if (found) {
443
- throw Error(
444
- `Found invalid rest route param record: ${doc.guid} referencing deleted rest record: ${qp_restId}`
445
- )
446
- }
447
- unHandledDocs.push(doc)
448
- }
449
- }
450
- break
451
- case 'sys_ws_query_parameter_map':
452
- case 'sys_ws_header_map':
453
- if (!doc.changedData) {
454
- break
455
- }
456
- const attrTable =
457
- doc.data!['table'] === 'sys_ws_header_map' ? 'sys_ws_header' : 'sys_ws_query_parameter'
458
- const attr =
459
- doc.data!['table'] === 'sys_ws_header_map' ? 'web_service_header' : 'web_service_query_parameter'
460
- const qpm_routeId = doc.data!['data']['web_service_operation']
461
- const qpm_paramId = doc.data!['data'][attr]
462
- const delOperationFound = findRecInDocs(delRestDocs, qpm_routeId, 'sys_ws_operation')
463
- const delParamFound = findRecInDocs(delRestDocs, qpm_paramId, attrTable)
464
- if (delOperationFound || delParamFound) {
465
- throw Error(
466
- `Found invalid rest map record: ${doc.guid} referencing deleted record: ${
467
- delOperationFound ? delOperationFound : delParamFound
468
- }`
469
- )
470
- }
471
- const routeRec = findRecInDocs(existingDocs, qpm_routeId, 'sys_ws_operation')
472
- const paramRec = findRecInDocs(existingDocs, qpm_paramId, attrTable)
473
- /**if both route and parameter are part of same rest then it will be consumed by rest */
474
- if (routeRec && paramRec) {
475
- const routeRestId = routeRec.data!['data']['web_service_definition']
476
- const paramRestId = paramRec.data!['data']['web_service_definition']
477
- if (routeRestId !== paramRestId) {
478
- throw Error(
479
- `Found invalid rest mapping record: ${doc.guid} which has param: ${qpm_paramId} and route: ${qpm_routeId} pointing to different rest definition`
480
- )
481
- }
482
- ;(docMap[routeRestId].route_attrs_map ??= {})[doc.guid] = doc
483
- } else if (paramRec) {
484
- const paramRestId = paramRec.data!['data']['web_service_definition']
485
- const foundRestRec = findRecInDocs(existingDocs, paramRestId, 'sys_ws_definition')
486
- /**In mapping records resources and paramter should point to same rest*/
487
- if (foundRestRec) {
488
- throw Error(
489
- `Found invalid rest mapping record: ${doc.guid} where the resource references different rest entity than the rest attr.`
490
- )
491
- }
492
- unHandledDocs.push(doc)
493
- } else {
494
- unHandledDocs.push(doc)
495
- }
496
- }
497
- return docMap
498
- }, {})
499
- restDocumentMap['delete_records'] = delRestDocs ?? []
500
- restDocumentMap['unHandled_records'] = unHandledDocs ?? []
501
- return restDocumentMap
502
- }
503
-
504
- export function isParamAssociated(document: Document, eleAttrName: string, context: Context, paramSysId: string) {
505
- let isAssociated = false
506
- iterateAllRouteAttrNode(document, eleAttrName, (_expression, _element, compKey) => {
507
- if (context.keys.explicit[compKey.attr]?.id === paramSysId) {
508
- isAssociated = true
509
- }
510
- })
511
- return isAssociated
512
- }
513
-
514
- /**
515
- * Helper function that creates a record call for the document passed.
516
- */
517
- export function createRecordCall(paramSysId: string, context: Context) {
518
- const paramKey = context.keys.findExplicitKeyById(paramSysId)
519
- if (paramKey) {
520
- delete context.keys.explicit[paramKey]
521
- }
522
- const document = context.getDocument(paramSysId)!
523
- document['changedData'] = { data: document.data!['data'] }
524
- delete document?.node
525
- const linkedDoc = RecordPlugin.generators.record(document as UnlinkedDocument<'record'> & Arranged, context)
526
- RecordPlugin.transformers.record.CallExpression(linkedDoc, context)
527
- }
528
-
529
- export function removeNodeAndCleanUpExport(node: SupportedNode) {
530
- const sourceFile = node.getSourceFile()
531
- removeNode(node)
532
- sourceFile
533
- .getDefaultExportSymbol()
534
- ?.getDeclarations()
535
- .forEach((declaration) => {
536
- if (
537
- declaration?.isKind(ts.SyntaxKind.ExportAssignment) &&
538
- declaration.getExpression()?.getText() === 'undefined'
539
- ) {
540
- declaration.remove()
541
- }
542
- })
543
- }
544
-
545
- const extractId = (data: EntityData | ObjectData): string[] => {
546
- return data.getProperty('$id')?.getValue() ? [data.getProperty('$id')?.getValue() as string] : []
547
- }
548
-
549
- const extractIdFromArray = (data: Data<unknown>): string[] => {
550
- const ids: string[] = []
551
- if (data && Data.isArray(data)) {
552
- data.getElements()
553
- .filter(Data.isObject)
554
- .forEach((element) => {
555
- ids.push(...extractId(element))
556
- })
557
- }
558
- return ids
559
- }
560
-
561
- export function extractNestedIds(entity: EntityData): string[] {
562
- const ids: string[] = []
563
- if (entity.getKind() === 'restApi') {
564
- ids.push(...extractId(entity))
565
- ids.push(...extractIdFromArray(entity.getProperty('routes')))
566
- ids.push(...extractIdFromArray(entity.getProperty('versions')))
567
- }
568
- return ids
569
- }