@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
@@ -0,0 +1,729 @@
1
+ import {
2
+ ArrayShape,
3
+ BooleanShape,
4
+ NumberShape,
5
+ ObjectShape,
6
+ Plugin,
7
+ Shape,
8
+ UndefinedShape,
9
+ SourceFileShape,
10
+ IdentifierShape,
11
+ ts,
12
+ isUndefined,
13
+ getValueDeclaration,
14
+ VariableStatementShape,
15
+ ElementAccessExpressionShape,
16
+ TemplateExpressionShape,
17
+ TemplateSpanShape,
18
+ TaggedTemplateExpressionShape,
19
+ StringLiteralShape,
20
+ PropertyAccessShape,
21
+ NOW_FILE_EXTENSION,
22
+ DeletedShape,
23
+ removeReferences,
24
+ remove,
25
+ isFluentFile,
26
+ } from '@servicenow/sdk-build-core'
27
+
28
+ export const BasicSyntaxPlugin = Plugin.create({
29
+ name: 'BasicSyntaxPlugin',
30
+ files: [
31
+ {
32
+ entryPoint: true,
33
+ matcher: RegExp(`${NOW_FILE_EXTENSION}$`),
34
+ },
35
+ ],
36
+ shapes: [
37
+ {
38
+ shape: DeletedShape,
39
+ commit(_, target) {
40
+ removeReferences(target)
41
+ remove(target)
42
+ return { success: true }
43
+ },
44
+ },
45
+ {
46
+ shape: UndefinedShape,
47
+ commit(_, target) {
48
+ if (!isUndefined(target)) {
49
+ target.replaceWithText('undefined')
50
+ }
51
+
52
+ return { success: true }
53
+ },
54
+ },
55
+ {
56
+ shape: TemplateExpressionShape,
57
+ async commit(shape, target, { commit }) {
58
+ if (
59
+ !ts.Node.isTemplateExpression(target) &&
60
+ !ts.Node.isTaggedTemplateExpression(target) &&
61
+ !ts.Node.isNoSubstitutionTemplateLiteral(target)
62
+ ) {
63
+ target.replaceWithText(shape.getCode())
64
+ return { success: true }
65
+ }
66
+
67
+ const template = ts.Node.isTaggedTemplateExpression(target) ? target.removeTag() : target
68
+ const targetSpans = ts.Node.isTemplateExpression(template) ? template.getTemplateSpans() : []
69
+ const shapeSpans = shape.getSpans()
70
+
71
+ if (shapeSpans.length !== targetSpans.length) {
72
+ template.replaceWithText(shape.getCode())
73
+ return { success: true }
74
+ }
75
+
76
+ for (const [i, targetSpan] of targetSpans.entries()) {
77
+ const shapeSpan = shapeSpans[i]
78
+ if (!shapeSpan) {
79
+ throw new Error(`Expected shape to have a span at index ${i}`)
80
+ }
81
+
82
+ await commit(shapeSpan, targetSpan)
83
+ }
84
+
85
+ return { success: true }
86
+ },
87
+ },
88
+ {
89
+ shape: TemplateSpanShape,
90
+ async commit(shape, target, { commit }) {
91
+ if (!ts.Node.isTemplateSpan(target)) {
92
+ target.replaceWithText(shape.getCode())
93
+ return { success: true }
94
+ }
95
+
96
+ const literal = target.getLiteral()
97
+ if (shape.getLiteralText() !== literal.getLiteralText()) {
98
+ if (literal.isKind(ts.SyntaxKind.TemplateMiddle)) {
99
+ literal.replaceWithText(`}${shape.getLiteralText()}\${`)
100
+ } else if (literal.isKind(ts.SyntaxKind.TemplateTail)) {
101
+ literal.replaceWithText(`}${shape.getLiteralText()}\``)
102
+ }
103
+ }
104
+
105
+ await commit(shape.getExpression(), target.getExpression())
106
+ return { success: true }
107
+ },
108
+ },
109
+ {
110
+ shape: StringLiteralShape,
111
+ async commit(shape, target, { commit }) {
112
+ const coerced = (() => {
113
+ try {
114
+ if (ts.Node.isTrueLiteral(target) || ts.Node.isFalseLiteral(target)) {
115
+ return shape.toBoolean()
116
+ } else if (ts.Node.isNumericLiteral(target)) {
117
+ const number = shape.toNumber()
118
+
119
+ // Turn the number back into a string and compare with the original string to avoid
120
+ // lossy conversions due to floating point precision or other factors
121
+ return number.getValue().toString() === shape.getValue() ? number : undefined
122
+ } else {
123
+ return undefined
124
+ }
125
+ } catch {
126
+ return undefined
127
+ }
128
+ })()
129
+
130
+ if (coerced) {
131
+ await commit(coerced, target)
132
+ return { success: true }
133
+ }
134
+
135
+ if (ts.Node.isTaggedTemplateExpression(target)) {
136
+ // Preserve tags when updating
137
+ target.getTemplate().replaceWithText(
138
+ new TemplateExpressionShape({
139
+ source: shape,
140
+ literalText: shape,
141
+ }).getCode()
142
+ )
143
+ } else {
144
+ target.replaceWithText(shape.getCode())
145
+ }
146
+
147
+ return { success: true }
148
+ },
149
+ },
150
+ {
151
+ shape: NumberShape,
152
+ commit(shape, target) {
153
+ if (ts.Node.isNumericLiteral(target) && target.getLiteralValue() === shape.getValue()) {
154
+ return { success: true }
155
+ }
156
+
157
+ target.replaceWithText(shape.getValue().toString())
158
+ return { success: true }
159
+ },
160
+ },
161
+ {
162
+ shape: BooleanShape,
163
+ commit(shape, target) {
164
+ if (
165
+ (ts.Node.isTrueLiteral(target) || ts.Node.isFalseLiteral(target)) &&
166
+ target.getLiteralValue() === shape.getValue()
167
+ ) {
168
+ return { success: true }
169
+ }
170
+
171
+ target.replaceWithText(shape.getValue().toString())
172
+ return { success: true }
173
+ },
174
+ },
175
+ {
176
+ shape: ArrayShape,
177
+ async commit(shape, target, { commit }) {
178
+ if (!ts.Node.isArrayLiteralExpression(target)) {
179
+ target.replaceWithText(shape.getCode())
180
+ return { success: true }
181
+ }
182
+
183
+ // Trim any excess elements
184
+ const targetElements = target.getElements()
185
+ const shapeElements = shape.getElements(false)
186
+ const excess = targetElements.length - shapeElements.length
187
+ for (let i = 1; i <= excess; i++) {
188
+ target.removeElement(targetElements.length - i)
189
+ }
190
+
191
+ // Commit existing elements in the trimmed array
192
+ for (const [i, targetElement] of target.getElements().entries()) {
193
+ await commit(shape.getElement(i, false), targetElement)
194
+ }
195
+
196
+ // Add new elements all at once, and we're done
197
+ const elementsToAdd = shapeElements.slice(target.getElements().length).map((e) => e.getCode())
198
+ if (elementsToAdd.length > 0) {
199
+ target.addElements(elementsToAdd)
200
+ }
201
+
202
+ return { success: true }
203
+ },
204
+ },
205
+ {
206
+ shape: ObjectShape,
207
+ async commit(shape, target, { commit }) {
208
+ if (!ts.Node.isObjectLiteralExpression(target)) {
209
+ target.replaceWithText(shape.getCode())
210
+ return { success: true }
211
+ }
212
+
213
+ const existingNames: Map<string, ts.Expression> = target
214
+ .getProperties()
215
+ .filter((p) => p.isKind(ts.SyntaxKind.PropertyAssignment))
216
+ .reduce(
217
+ (map, p) => map.set(getName(p), p.getInitializerOrThrow()),
218
+ new Map<string, ts.Expression>()
219
+ )
220
+
221
+ const propsToRetain = new Set<string>(['$meta'])
222
+ const propsToAdd: ts.PropertyAssignmentStructure[] = []
223
+ for (const [name, value] of shape.entries({ resolve: false })) {
224
+ const existingPropKey = [...shape.getAliases(name), name].find((aliasedKey) =>
225
+ existingNames.has(aliasedKey)
226
+ )
227
+ if (existingPropKey) {
228
+ if (existingPropKey !== name) {
229
+ target
230
+ .getPropertyOrThrow(existingPropKey)
231
+ .asKindOrThrow(ts.SyntaxKind.PropertyAssignment)
232
+ .getNameNode()
233
+ .replaceWithText(name)
234
+ }
235
+ await commit(value, existingNames.get(existingPropKey) as ts.Expression)
236
+ } else if (!value.equals(shape.getDefault(name))) {
237
+ propsToAdd.push({
238
+ name: ObjectShape.quotePropertyNameIfNeeded(name),
239
+ initializer: value.getCode(),
240
+ kind: ts.StructureKind.PropertyAssignment,
241
+ })
242
+ }
243
+ propsToRetain.add(name)
244
+ }
245
+
246
+ // Add all missing props at once to improve performance
247
+ if (propsToAdd.length > 0) {
248
+ target.addPropertyAssignments(propsToAdd)
249
+ }
250
+
251
+ const propsToRemove = [...existingNames.keys()].filter((key) => !propsToRetain.has(key))
252
+ propsToRemove.forEach((prop) => {
253
+ target.getProperty(prop)?.asKindOrThrow(ts.SyntaxKind.PropertyAssignment).remove()
254
+ })
255
+
256
+ return { success: true }
257
+ },
258
+ },
259
+ {
260
+ shape: IdentifierShape,
261
+ commit(shape, target) {
262
+ if (ts.Node.isIdentifier(target) && target.getText() === shape.getName()) {
263
+ return { success: true }
264
+ }
265
+
266
+ target.replaceWithText(shape.getName())
267
+ return { success: true }
268
+ },
269
+ },
270
+ {
271
+ shape: VariableStatementShape,
272
+ async commit(shape, target, { commit }) {
273
+ if (!ts.Node.isVariableStatement(target)) {
274
+ target.replaceWithText(shape.getCode())
275
+ return { success: true }
276
+ }
277
+
278
+ if (target.isExported() !== shape.isExported()) {
279
+ target.setIsExported(shape.isExported())
280
+ }
281
+
282
+ const [declaration, otherDeclaration] = target.getDeclarations()
283
+ if (!declaration) {
284
+ throw new Error(`Variable statement is missing a declaration: ${target.getFullText()}`)
285
+ }
286
+
287
+ if (otherDeclaration) {
288
+ removeReferences(otherDeclaration)
289
+ remove(otherDeclaration)
290
+ }
291
+
292
+ const variableName = shape.getVariableName()
293
+ if (declaration.getName() !== variableName.getName()) {
294
+ await commit(variableName, declaration.getNameNode())
295
+ }
296
+
297
+ await commit(shape.getInitializer(), declaration.getInitializerOrThrow())
298
+ return { success: true }
299
+ },
300
+ },
301
+ ],
302
+ nodes: [
303
+ {
304
+ node: 'SourceFile',
305
+ async toShape(file, { diagnostics, transform }) {
306
+ if (isFluentFile(file)) {
307
+ const syntaxList = file.getChildSyntaxList()
308
+ if (!syntaxList) {
309
+ diagnostics.error(file, 'Fluent source file contains no meaningful content.')
310
+ return { success: false }
311
+ }
312
+
313
+ for (const child of syntaxList.getChildren()) {
314
+ if (ts.Node.isCommentNode(child)) {
315
+ continue
316
+ }
317
+
318
+ const result = await transform.toShape(child)
319
+ if (!result.success) {
320
+ diagnostics.error(child, 'Unsupported statement in Fluent source file.')
321
+ return { success: false }
322
+ }
323
+ }
324
+ }
325
+
326
+ return {
327
+ success: true,
328
+ value: new SourceFileShape({ file }),
329
+ }
330
+ },
331
+ },
332
+ {
333
+ node: 'StringLiteral',
334
+ toShape(node) {
335
+ return {
336
+ success: true,
337
+ value: new StringLiteralShape({ source: node, literalText: node.getLiteralValue() }),
338
+ }
339
+ },
340
+ },
341
+ {
342
+ node: 'NoSubstitutionTemplateLiteral',
343
+ toShape(node) {
344
+ return {
345
+ success: true,
346
+ value: new TemplateExpressionShape({ source: node, literalText: node.getLiteralValue() }),
347
+ }
348
+ },
349
+ },
350
+ {
351
+ node: 'NumericLiteral',
352
+ toShape(node) {
353
+ return {
354
+ success: true,
355
+ value: new NumberShape({ source: node, value: node.getLiteralValue() }),
356
+ }
357
+ },
358
+ },
359
+ {
360
+ node: 'NullKeyword',
361
+ toShape(node) {
362
+ return {
363
+ success: true,
364
+ value: new UndefinedShape({ source: node }),
365
+ }
366
+ },
367
+ },
368
+ {
369
+ node: 'TrueKeyword',
370
+ toShape(node) {
371
+ return {
372
+ success: true,
373
+ value: new BooleanShape({ source: node, value: true }),
374
+ }
375
+ },
376
+ },
377
+ {
378
+ node: 'FalseKeyword',
379
+ toShape(node) {
380
+ return {
381
+ success: true,
382
+ value: new BooleanShape({ source: node, value: false }),
383
+ }
384
+ },
385
+ },
386
+ {
387
+ node: 'AsExpression',
388
+ toShape(node, { transform }) {
389
+ return transform.toShape(node.getExpression())
390
+ },
391
+ },
392
+ {
393
+ node: 'ExportAssignment',
394
+ toShape(node, { transform }) {
395
+ return transform.toShape(node.getExpression())
396
+ },
397
+ },
398
+ {
399
+ node: 'ComputedPropertyName',
400
+ toShape(node, { transform }) {
401
+ return transform.toShape(node.getExpression())
402
+ },
403
+ },
404
+ {
405
+ node: 'PropertyAccessExpression',
406
+ async toShape(node, { transform, diagnostics }) {
407
+ const lastElementNode = node.getNameNode()
408
+ const lastElement = await transform.toShape(lastElementNode)
409
+ if (!lastElement.success || !lastElement.value.isIdentifier()) {
410
+ diagnostics.error(lastElementNode, 'Last element of property access expression is unsupported')
411
+ return { success: false }
412
+ }
413
+
414
+ const expressionNode = node.getExpression()
415
+ const expression = await transform.toShape(expressionNode)
416
+ if (!expression.success || !expression.value.is([IdentifierShape, PropertyAccessShape])) {
417
+ diagnostics.error(expressionNode, 'Left side of property access expression is unsupported')
418
+ return { success: false }
419
+ }
420
+
421
+ const elements = expression.value.isIdentifier()
422
+ ? ([expression.value, lastElement.value] as const)
423
+ : ([...expression.value.getElements(), lastElement.value] as const)
424
+
425
+ return {
426
+ success: true,
427
+ value: new PropertyAccessShape({ source: node, elements }),
428
+ }
429
+ },
430
+ },
431
+ {
432
+ node: 'ExpressionStatement',
433
+ toShape(node, { transform }) {
434
+ return transform.toShape(node.getExpression())
435
+ },
436
+ },
437
+ {
438
+ node: 'Identifier',
439
+ async toShape(node, { transform }) {
440
+ if (isUndefined(node)) {
441
+ return {
442
+ success: true,
443
+ value: new UndefinedShape({ source: node }),
444
+ }
445
+ }
446
+
447
+ const name = node.getSymbol()?.getName() ?? node.getText()
448
+ const valueDeclaration = getValueDeclaration(node)
449
+ const valueResult = valueDeclaration && (await transform.toShape(valueDeclaration))
450
+
451
+ return {
452
+ success: true,
453
+ value: valueResult?.success
454
+ ? new IdentifierShape({ source: node, name, value: valueResult.value })
455
+ : new IdentifierShape({ source: node, name }),
456
+ }
457
+ },
458
+ },
459
+ {
460
+ node: 'Parameter',
461
+ toShape(node) {
462
+ return {
463
+ success: true,
464
+ value: new IdentifierShape({
465
+ source: node,
466
+ name: node.getName(),
467
+ }),
468
+ }
469
+ },
470
+ },
471
+ {
472
+ node: 'VariableStatement',
473
+ async toShape(node, { transform, diagnostics }) {
474
+ const kind = node.getDeclarationKind()
475
+ if (kind !== ts.VariableDeclarationKind.Const) {
476
+ diagnostics.error(
477
+ node.getDeclarationKindKeywords()[0] ?? node,
478
+ `Declaration kind "${kind}" is not supported. Only const variables are supported.`
479
+ )
480
+
481
+ return { success: false }
482
+ }
483
+
484
+ const defaultKeyword = node.getDefaultKeyword()
485
+ if (defaultKeyword) {
486
+ diagnostics.error(defaultKeyword, 'Default exports are not supported')
487
+ return { success: false }
488
+ }
489
+
490
+ const [declaration, otherDeclaration] = node.getDeclarations()
491
+ if (!declaration) {
492
+ diagnostics.error(node, 'Missing declaration in variable statement')
493
+ return { success: false }
494
+ }
495
+
496
+ if (otherDeclaration) {
497
+ diagnostics.error(
498
+ otherDeclaration,
499
+ 'Additional declarations in variable statements are not supported'
500
+ )
501
+ return { success: false }
502
+ }
503
+
504
+ const initializer = declaration.getInitializerOrThrow()
505
+ const initializerResult = await transform.toShape(initializer)
506
+ if (!initializerResult.success) {
507
+ diagnostics.error(initializer, 'Unsupported variable initializer')
508
+ return { success: false }
509
+ }
510
+
511
+ return {
512
+ success: true,
513
+ value: new VariableStatementShape({
514
+ source: node,
515
+ variableName: new IdentifierShape({ source: node, name: declaration.getName() }),
516
+ initializer: initializerResult.value,
517
+ isExported: node.isExported(),
518
+ }),
519
+ }
520
+ },
521
+ },
522
+ {
523
+ node: 'VariableDeclaration',
524
+ toShape(node, { transform }) {
525
+ const initializer = node.getInitializer()
526
+ return initializer
527
+ ? transform.toShape(initializer)
528
+ : {
529
+ success: true,
530
+ value: new UndefinedShape({ source: node }),
531
+ }
532
+ },
533
+ },
534
+ {
535
+ node: 'ArrayLiteralExpression',
536
+ async toShape(node, { transform }) {
537
+ const elements: Shape[] = []
538
+ for (const element of node.getElements()) {
539
+ const result = await transform.toShape(element)
540
+ if (!result.success) {
541
+ return { success: false }
542
+ }
543
+
544
+ elements.push(result.value)
545
+ }
546
+
547
+ return {
548
+ success: true,
549
+ value: new ArrayShape({ source: node, elements }),
550
+ }
551
+ },
552
+ },
553
+ {
554
+ node: 'PropertyAssignment',
555
+ toShape(node, { transform, diagnostics }) {
556
+ const initializer = node.getInitializer()
557
+ if (!initializer) {
558
+ diagnostics.error(node, 'Property must have an initializer')
559
+ return { success: false }
560
+ }
561
+
562
+ return transform.toShape(initializer)
563
+ },
564
+ },
565
+ {
566
+ node: 'ObjectLiteralExpression',
567
+ async toShape(node, { transform, diagnostics }) {
568
+ const properties: Record<string, Shape> = {}
569
+ for (const property of node.getProperties()) {
570
+ if (!ts.Node.isPropertyAssignment(property)) {
571
+ diagnostics.error(property, 'Only property assignments are allowed')
572
+ continue
573
+ }
574
+
575
+ const result = await transform.toShape(property)
576
+ if (!result.success) {
577
+ diagnostics.error(property, 'Failed to parse property')
578
+ return { success: false }
579
+ }
580
+
581
+ const nameNode = property.getNameNode()
582
+ const name = ts.Node.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : property.getName()
583
+
584
+ properties[name] = result.value
585
+ }
586
+
587
+ return {
588
+ success: true,
589
+ value: new ObjectShape({ source: node, properties }),
590
+ }
591
+ },
592
+ },
593
+ {
594
+ node: 'TemplateSpan',
595
+ async toShape(span, { transform, diagnostics }) {
596
+ const expression = await transform.toShape(span.getExpression())
597
+ if (!expression.success) {
598
+ diagnostics.error(span, 'Unsupported expression in template')
599
+ return { success: false }
600
+ }
601
+
602
+ return {
603
+ success: true,
604
+ value: new TemplateSpanShape({
605
+ source: span,
606
+ expression: expression.value,
607
+ literalText: span.getLiteral().getLiteralText(),
608
+ }),
609
+ }
610
+ },
611
+ },
612
+ {
613
+ node: 'TemplateExpression',
614
+ async toShape(node, { transform, diagnostics }) {
615
+ const spans: TemplateSpanShape[] = []
616
+ for (const span of node.getTemplateSpans()) {
617
+ const result = await transform.toShape(span)
618
+ if (!result.success || !result.value.is(TemplateSpanShape)) {
619
+ diagnostics.error(span, 'Unsupported span in template expression')
620
+ return { success: false }
621
+ }
622
+
623
+ spans.push(result.value)
624
+ }
625
+
626
+ return {
627
+ success: true,
628
+ value: new TemplateExpressionShape({
629
+ source: node,
630
+ literalText: node.getHead().getLiteralText(),
631
+ spans,
632
+ }),
633
+ }
634
+ },
635
+ },
636
+ {
637
+ node: 'TaggedTemplateExpression',
638
+ async toShape(node, { transform, diagnostics }) {
639
+ const template = node.getTemplate()
640
+ const templateResult = await transform.toShape(template)
641
+ if (!templateResult.success || !templateResult.value.is(TemplateExpressionShape)) {
642
+ diagnostics.error(template, 'Unsupported template in tagged template expression')
643
+ return { success: false }
644
+ }
645
+
646
+ return {
647
+ success: true,
648
+ value: new TaggedTemplateExpressionShape({
649
+ source: node,
650
+ tag: node.getTag().getText(),
651
+ template: templateResult.value,
652
+ }),
653
+ }
654
+ },
655
+ },
656
+ {
657
+ node: 'PrefixUnaryExpression',
658
+ toShape(node, { diagnostics }) {
659
+ if (
660
+ !ts.Node.isNumericLiteral(node.getOperand()) ||
661
+ node.getOperatorToken() !== ts.SyntaxKind.MinusToken
662
+ ) {
663
+ diagnostics.error(node, 'Unsupported prefix unary expression')
664
+ return { success: false }
665
+ }
666
+
667
+ return {
668
+ success: true,
669
+ value: new NumberShape({
670
+ source: node,
671
+ value: -node.getOperand().asKindOrThrow(ts.SyntaxKind.NumericLiteral).getLiteralValue(),
672
+ }),
673
+ }
674
+ },
675
+ },
676
+ {
677
+ node: 'ElementAccessExpression',
678
+ async toShape(node, { transform, diagnostics }) {
679
+ const argumentExpression = node.getArgumentExpression()
680
+ if (!argumentExpression) {
681
+ diagnostics.error(node, 'Element access expression must have an argument')
682
+ return { success: false }
683
+ }
684
+
685
+ const argumentShape = await transform.toShape(argumentExpression)
686
+ if (!argumentShape.success) {
687
+ diagnostics.error(node, 'Unsupported element access expression argument')
688
+ return { success: false }
689
+ }
690
+
691
+ return {
692
+ success: true,
693
+ value: new ElementAccessExpressionShape({
694
+ source: node,
695
+ callee: node.getExpression().getText(),
696
+ arg: argumentShape.value,
697
+ }),
698
+ }
699
+ },
700
+ },
701
+ {
702
+ node: 'ImportDeclaration',
703
+ toShape(node) {
704
+ // TODO: This is just to prevent diagnostic errors. We should return a meaningful shape here.
705
+ return {
706
+ success: true,
707
+ value: Shape.noOp(node),
708
+ }
709
+ },
710
+ },
711
+ {
712
+ node: 'ExportDeclaration',
713
+ toShape(node) {
714
+ // TODO: This is just to prevent diagnostic errors. We should return a meaningful shape here.
715
+ return {
716
+ success: true,
717
+ value: Shape.noOp(node),
718
+ }
719
+ },
720
+ },
721
+ ],
722
+ })
723
+
724
+ function getName(node: ts.PropertyAssignment): string {
725
+ const nameNode = node.getNameNode()
726
+ return ts.Node.isStringLiteral(nameNode) || ts.Node.isNoSubstitutionTemplateLiteral(nameNode)
727
+ ? nameNode.getLiteralValue()
728
+ : nameNode.getText()
729
+ }