@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,1324 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TablePlugin = void 0;
7
+ exports.isDefaultLicenseConfig = isDefaultLicenseConfig;
8
+ const sdk_build_core_1 = require("@servicenow/sdk-build-core");
9
+ const fast_xml_parser_1 = require("fast-xml-parser");
10
+ const zod_1 = require("zod");
11
+ const column_plugin_1 = require("./column-plugin");
12
+ const xmlbuilder2_1 = require("xmlbuilder2");
13
+ const column_helper_1 = require("./column/column-helper");
14
+ const utils_1 = require("./utils");
15
+ const isEqual_1 = __importDefault(require("lodash/isEqual"));
16
+ // Bootstrap XML schema
17
+ const BooleanFromString = zod_1.z
18
+ .string()
19
+ .transform((str) => str === 'true')
20
+ .or(zod_1.z.boolean())
21
+ .optional();
22
+ const ChoiceElementSchema = zod_1.z.object({
23
+ '@_label': zod_1.z.string().optional(),
24
+ '@_value': zod_1.z.string().optional(),
25
+ '@_sequence': zod_1.z.coerce.number().optional(),
26
+ '@_dependent_value': zod_1.z.coerce.number().or(zod_1.z.string()).optional(),
27
+ '@_hint': zod_1.z.string().optional(),
28
+ '@_inactive': BooleanFromString.optional(),
29
+ '@_inactive_on_update': BooleanFromString.optional(),
30
+ '@_language': zod_1.z.string().optional(),
31
+ });
32
+ const IndexElementSchema = zod_1.z.object({
33
+ '@_name': zod_1.z.string(),
34
+ });
35
+ const IndexSchema = zod_1.z.object({
36
+ '@_name': zod_1.z.string(),
37
+ '@_unique': BooleanFromString.optional(),
38
+ element: zod_1.z.array(IndexElementSchema).or(IndexElementSchema),
39
+ });
40
+ const ColumnSchema = zod_1.z
41
+ .object({
42
+ '@_name': zod_1.z.string(),
43
+ '@_type': zod_1.z.string().optional(),
44
+ '@_internal_type': zod_1.z.string().optional(),
45
+ '@_default': zod_1.z.string().optional(),
46
+ '@_default_value': zod_1.z.string().optional(),
47
+ '@_max_length': zod_1.z.coerce.number().or(zod_1.z.string()).optional(),
48
+ '@_mandatory': BooleanFromString.optional(),
49
+ '@_read_only': BooleanFromString.optional(),
50
+ '@_reference_table': zod_1.z.string().optional(),
51
+ '@_reference_qual': zod_1.z.string().optional(),
52
+ '@_label': zod_1.z.string().optional(),
53
+ '@_choice': zod_1.z.coerce.number().optional(),
54
+ '@_active': BooleanFromString.optional(),
55
+ '@_display': BooleanFromString.optional(),
56
+ '@_use_dependent_field': BooleanFromString.optional(),
57
+ '@_use_dynamic_default': BooleanFromString.optional(),
58
+ '@_reference': zod_1.z.string().optional(),
59
+ '@_virtual': BooleanFromString.optional(),
60
+ '@_calculation': zod_1.z.string().optional(),
61
+ '@_choice_field': zod_1.z.string().optional(),
62
+ '@_function_definition': zod_1.z.string().optional(),
63
+ '@_reference_floats': BooleanFromString.optional(),
64
+ '@_reference_key': zod_1.z.string().optional(),
65
+ '@_dynamic_creation_script': zod_1.z.string().optional(),
66
+ '@_dynamic_creation': BooleanFromString.optional(),
67
+ '@_plural': zod_1.z.string().optional(),
68
+ '@_hint': zod_1.z.string().optional(),
69
+ '@_help': zod_1.z.string().optional(),
70
+ '@_widget': zod_1.z.string().optional(),
71
+ '@_table_reference': BooleanFromString.optional(),
72
+ '@_element_reference': BooleanFromString.optional(),
73
+ '@_unique': BooleanFromString.optional(),
74
+ '@_spell_check': BooleanFromString.optional(),
75
+ '@_xml_view': BooleanFromString.optional(),
76
+ '@_array': BooleanFromString.optional(),
77
+ '@_text_index': BooleanFromString.optional(),
78
+ '@_primary': BooleanFromString.optional(),
79
+ '@_attributes': zod_1.z.string().optional(),
80
+ '@_audit': BooleanFromString.optional(),
81
+ choice: zod_1.z
82
+ .object({
83
+ element: zod_1.z.array(ChoiceElementSchema).or(ChoiceElementSchema).optional(),
84
+ })
85
+ .optional(),
86
+ })
87
+ .catchall(zod_1.z.any());
88
+ const TableSchema = zod_1.z
89
+ .object({
90
+ '@_name': zod_1.z.string(),
91
+ '@_extends': zod_1.z.string().optional(),
92
+ '@_label': zod_1.z.string().optional(),
93
+ '@_plural': zod_1.z.string().optional(),
94
+ '@_audit': BooleanFromString.optional(),
95
+ '@_read_only': BooleanFromString.optional(),
96
+ '@_text_index': BooleanFromString.optional(),
97
+ '@_client_scripts_access': BooleanFromString.optional().default(true),
98
+ '@_ws_access': BooleanFromString.optional().default(true),
99
+ '@_alter_access': BooleanFromString.optional().default(true),
100
+ '@_create_access': BooleanFromString.optional().default(true),
101
+ '@_delete_access': BooleanFromString.optional().default(false),
102
+ '@_update_access': BooleanFromString.optional().default(true),
103
+ '@_actions_access': BooleanFromString.optional().default(true),
104
+ '@_read_access': BooleanFromString.optional().default(true),
105
+ '@_is_extendable': BooleanFromString.optional().default(false),
106
+ '@_scriptable_table': BooleanFromString.optional().default(false),
107
+ '@_attributes': zod_1.z.string().optional(),
108
+ element: zod_1.z.array(ColumnSchema).or(ColumnSchema).optional(),
109
+ index: zod_1.z.array(IndexSchema).or(IndexSchema).optional(),
110
+ })
111
+ .catchall(zod_1.z.any());
112
+ const BootstrapDatabaseSchema = zod_1.z.object({
113
+ element: TableSchema,
114
+ });
115
+ /**
116
+ * The access levels are mapped to the following values on the platform
117
+ *
118
+ * - `none`: 0
119
+ * - `tracking`: 1
120
+ * - `restricted`: 2
121
+ *
122
+ */
123
+ const callerAccessLevels = ['none', 'tracking', 'restricted'];
124
+ const tableNameRegex = /^[a-z_][a-z0-9_]*[a-z0-9]$/;
125
+ const columnNameRegex = /^[a-z_][a-z0-9_]*$/;
126
+ const tableAliases = {
127
+ readOnly: ['read_only'],
128
+ textIndex: ['text_index'],
129
+ allowWebServiceAccess: ['allow_web_service_access'],
130
+ allowNewFields: ['allow_new_fields'],
131
+ allowUiActions: ['allow_ui_actions'],
132
+ allowClientScripts: ['allow_client_scripts'],
133
+ licensingConfig: ['licensing_config'],
134
+ liveFeed: ['live_feed'],
135
+ accessibleFrom: ['accessible_from'],
136
+ callerAccess: ['caller_access'],
137
+ scriptableTable: ['scriptable_table'],
138
+ autoNumber: ['auto_number'],
139
+ };
140
+ const documentationAliases = {
141
+ urlTarget: ['url_target'],
142
+ };
143
+ const autoNumberAliases = {
144
+ numberOfDigits: ['number_of_digits'],
145
+ };
146
+ const licensingAliases = {
147
+ licenseModel: ['license_model'],
148
+ ownerCondition: ['owner_condition'],
149
+ licenseCondition: ['license_condition'],
150
+ isFulfillment: ['is_fulfillment'],
151
+ opDelete: ['op_delete'],
152
+ opUpdate: ['op_update'],
153
+ opInsert: ['op_insert'],
154
+ licenseRoles: ['license_roles'],
155
+ };
156
+ exports.TablePlugin = sdk_build_core_1.Plugin.create({
157
+ name: 'TablePlugin',
158
+ files: [
159
+ {
160
+ matcher: /\.xml$/,
161
+ toRecord(file, { factory }) {
162
+ const xml = new fast_xml_parser_1.XMLParser({
163
+ ignoreAttributes: false,
164
+ alwaysCreateTextNode: true,
165
+ htmlEntities: true,
166
+ }).parse(file.content).database;
167
+ if (!xml) {
168
+ return { success: false };
169
+ }
170
+ const tableDef = parseTableBootstrapXml(xml);
171
+ if (!tableDef) {
172
+ return { success: false };
173
+ }
174
+ const recordDefs = tableDefToRecordProperties(tableDef);
175
+ const [sysDbRecord, ...relatedRecords] = [
176
+ ['sysDbObject', 'sys_db_object'],
177
+ ['sysDictionary', 'sys_dictionary'],
178
+ ['sysChoice', 'sys_choice'],
179
+ ['sysIndex', 'sys_index'],
180
+ ['sysDocumentation', 'sys_documentation'],
181
+ ].flatMap(([key, table]) => {
182
+ return [recordDefs[key]].flat().map((rec) => factory.createRecord({
183
+ source: file,
184
+ table,
185
+ properties: filterUndefinedProperties(rec),
186
+ }));
187
+ });
188
+ return {
189
+ success: true,
190
+ value: sysDbRecord.with(...relatedRecords),
191
+ };
192
+ },
193
+ },
194
+ ],
195
+ records: {
196
+ sys_db_object: {
197
+ coalesce: ['name'],
198
+ relationships: {
199
+ sys_dictionary: {
200
+ via: { name: 'name' },
201
+ descendant: true,
202
+ relationships: {
203
+ sys_documentation: {
204
+ descendant: true,
205
+ via: {
206
+ name: 'name',
207
+ element: 'element',
208
+ },
209
+ },
210
+ sys_choice: {
211
+ descendant: true,
212
+ via: {
213
+ name: 'name',
214
+ element: 'element',
215
+ },
216
+ },
217
+ sys_choice_set: {
218
+ descendant: true,
219
+ via: {
220
+ name: 'name',
221
+ element: 'element',
222
+ },
223
+ },
224
+ },
225
+ },
226
+ ua_table_licensing_config: {
227
+ descendant: true,
228
+ via: { name: 'name' },
229
+ },
230
+ sys_documentation: {
231
+ descendant: true,
232
+ via: { name: 'name' },
233
+ },
234
+ sys_number: {
235
+ descendant: true,
236
+ via: { category: 'name' },
237
+ },
238
+ sys_index: {
239
+ descendant: true,
240
+ via: { logical_table_name: 'name' },
241
+ },
242
+ sys_db_object: {
243
+ descendant: false,
244
+ via: 'super_class',
245
+ },
246
+ },
247
+ toShape(record, { descendants }) {
248
+ const schema = {};
249
+ let displayColumn;
250
+ const columns = descendants.query('sys_dictionary');
251
+ let collectionRecord;
252
+ const choices = descendants.query('sys_choice');
253
+ const documentation = descendants.query('sys_documentation');
254
+ for (const column of columns) {
255
+ if (column.get('internal_type').getValue() === 'collection') {
256
+ // 'collection' sys_dictionary record only has table properties
257
+ collectionRecord = column;
258
+ continue;
259
+ }
260
+ const columnName = column.get('element').asString().getValue();
261
+ schema[columnName] = (0, column_plugin_1.columnToCallExpression)(column, {
262
+ choices: choices.filter((choice) => choice.get('element').asString().getValue() === columnName),
263
+ documentation: documentation.filter((d) => d.get('element').ifString()?.getValue() === columnName),
264
+ });
265
+ if (column.get('display').ifDefined()?.toBoolean().getValue()) {
266
+ displayColumn = columnName;
267
+ }
268
+ }
269
+ const tableDocumentation = documentation.filter((d) => !d.get('element').getValue());
270
+ const licensing = descendants.query('ua_table_licensing_config');
271
+ const autoNumber = descendants.query('sys_number');
272
+ const indexes = descendants.query('sys_index');
273
+ const originalSource = record.getOriginalSource();
274
+ // Avoid replacing call expressions with variable statements
275
+ const writeAsCallExpression = sdk_build_core_1.ts.Node.isNode(originalSource) && originalSource.isKind(sdk_build_core_1.ts.SyntaxKind.CallExpression);
276
+ const callExpression = new sdk_build_core_1.CallExpressionShape({
277
+ source: record,
278
+ callee: 'Table',
279
+ args: [
280
+ record
281
+ .transform(({ $ }) => ({
282
+ accessibleFrom: $.from('access')
283
+ .map((access) => (access.ifString()?.getValue() === '' ? undefined : access))
284
+ .def('public'),
285
+ actions: $.from('read_access', 'update_access', 'delete_access', 'create_access')
286
+ .map((readAccess, updateAccess, deleteAccess, createAccess) => {
287
+ // TODO Add framework solution so these don't come in as strings
288
+ const isTrueString = (value) => value === 'true';
289
+ const actions = [];
290
+ if (readAccess.ifBoolean()?.getValue() ||
291
+ isTrueString(readAccess.ifString()?.getValue())) {
292
+ actions.push('read');
293
+ }
294
+ if (updateAccess.ifBoolean()?.getValue() ||
295
+ isTrueString(updateAccess.ifString()?.getValue())) {
296
+ actions.push('update');
297
+ }
298
+ if (deleteAccess.ifBoolean()?.getValue() ||
299
+ isTrueString(deleteAccess.ifString()?.getValue())) {
300
+ actions.push('delete');
301
+ }
302
+ if (createAccess.ifBoolean()?.getValue() ||
303
+ isTrueString(createAccess.ifString()?.getValue())) {
304
+ actions.push('create');
305
+ }
306
+ return actions.length ? actions : undefined;
307
+ })
308
+ .def(['read']),
309
+ allowClientScripts: $.from('client_scripts_access').toBoolean().def(false),
310
+ allowNewFields: $.from('alter_access').toBoolean().def(false),
311
+ allowUiActions: $.from('actions_access').toBoolean().def(false),
312
+ allowWebServiceAccess: $.from('ws_access').toBoolean().def(false),
313
+ attributes: $.val((() => {
314
+ const attributes = collectionRecord?.get('attributes');
315
+ if (!attributes?.isString()) {
316
+ return undefined;
317
+ }
318
+ const result = {};
319
+ attributes
320
+ .toString()
321
+ .getValue()
322
+ .split(',')
323
+ .forEach((attr) => {
324
+ if (attr === '') {
325
+ return;
326
+ }
327
+ const [key, value] = attr.split('=').map((s) => s.trim());
328
+ if (value === 'true') {
329
+ result[key] = true;
330
+ }
331
+ else if (value === 'false') {
332
+ result[key] = false;
333
+ }
334
+ else {
335
+ result[key] = value;
336
+ }
337
+ });
338
+ return result;
339
+ })()).def({ edgeEncryptionEnabled: true }),
340
+ audit: $.val(collectionRecord?.get('audit')).toBoolean().def(false),
341
+ autoNumber: $.val(autoNumber[0]
342
+ ?.transform(({ $ }) => ({
343
+ number: $.toNumber().def(1000),
344
+ numberOfDigits: $.from('maximum_digits').toNumber().def(7),
345
+ prefix: $.def('PRE'),
346
+ }))
347
+ .withAliasedKeys(autoNumberAliases)),
348
+ callerAccess: $.from('caller_access')
349
+ .map((callerAccess) => {
350
+ if (callerAccess.isNumber()) {
351
+ return callerAccessLevels[callerAccess.getValue()];
352
+ }
353
+ if (callerAccess.isString()) {
354
+ const callerAccessString = callerAccess.getValue();
355
+ if (!isNaN(Number(callerAccessString))) {
356
+ return callerAccessLevels[Number(callerAccessString)];
357
+ }
358
+ }
359
+ return 'none';
360
+ })
361
+ .def('none'),
362
+ display: displayColumn ? $.val(displayColumn) : undefined,
363
+ extends: $.from('super_class').def(''),
364
+ extensible: $.from('is_extendable').toBoolean().def(false),
365
+ index: $.val(indexes.map((idx) => {
366
+ return idx.transform(({ $ }) => ({
367
+ // TODO Find actual home of 'index_name' instead of using a fake property here
368
+ name: $.from('index_name'),
369
+ unique: $.from('unique_index').map((uniqueIndex) => uniqueIndex.ifBoolean() ?? false),
370
+ element: $.from('col_name_string').map((colNamesString) => {
371
+ const colNames = colNamesString.asString().getValue().split(',');
372
+ return colNames.length > 1 ? colNames : colNames[0];
373
+ }),
374
+ }));
375
+ })).def([]),
376
+ label: $.map((label) => label.ifString() ??
377
+ (tableDocumentation.length && !(0, column_plugin_1.isDefaultDocumentation)('', tableDocumentation)
378
+ ? tableDocumentation.map((doc) => doc
379
+ .transform(({ $ }) => ({
380
+ label: $.def(''),
381
+ help: $.def(''),
382
+ hint: $.def(''),
383
+ language: $.def(''),
384
+ plural: $.def(''),
385
+ url: $.def(''),
386
+ urlTarget: $.from('url_target').def(''),
387
+ }))
388
+ .withAliasedKeys(documentationAliases))
389
+ : undefined)),
390
+ licensingConfig: licensing.length
391
+ ? $.val(licensing[0]
392
+ .transform(({ $ }) => ({
393
+ licenseModel: $.from('license_model').def('none'),
394
+ ownerCondition: $.from('owner_condition').def(''),
395
+ licenseCondition: $.from('license_condition').def(''),
396
+ isFulfillment: $.from('is_fulfillment').toBoolean().def(false),
397
+ opDelete: $.from('op_delete').toBoolean().def(true),
398
+ opUpdate: $.from('op_update').toBoolean().def(true),
399
+ opInsert: $.from('op_insert').toBoolean().def(true),
400
+ licenseRoles: $.from('license_roles')
401
+ .map((v) => {
402
+ return v.isString() && !v.isEmpty()
403
+ ? v
404
+ .asString()
405
+ .getValue()
406
+ .split(',')
407
+ .map((role) => role.trim())
408
+ : [];
409
+ })
410
+ .def([]),
411
+ }))
412
+ .withAliasedKeys(licensingAliases)).def({
413
+ licenseModel: 'none',
414
+ ownerCondition: '',
415
+ licenseCondition: '',
416
+ isFulfillment: false,
417
+ opDelete: true,
418
+ opUpdate: true,
419
+ opInsert: true,
420
+ licenseRoles: [],
421
+ })
422
+ : undefined,
423
+ liveFeed: $.from('live_feed_enabled').toBoolean().def(false),
424
+ name: $,
425
+ readOnly: $.val(collectionRecord?.get('read_only')).toBoolean().def(false),
426
+ schema: $.val(schema),
427
+ scriptableTable: $.from('scriptable_table').toBoolean().def(false),
428
+ textIndex: $.val(collectionRecord?.get('text_index')).toBoolean().def(false),
429
+ }))
430
+ .withAliasedKeys(tableAliases),
431
+ ],
432
+ });
433
+ return {
434
+ success: true,
435
+ value: writeAsCallExpression
436
+ ? callExpression
437
+ : new sdk_build_core_1.VariableStatementShape({
438
+ source: record,
439
+ isExported: true,
440
+ variableName: new sdk_build_core_1.IdentifierShape({
441
+ source: record,
442
+ name: record.get('name').asString().getValue(),
443
+ }),
444
+ initializer: callExpression,
445
+ }),
446
+ };
447
+ },
448
+ toFile(record, { descendants, config }) {
449
+ if (config.tableOutputFormat !== 'bootstrap' || record.isDeleted()) {
450
+ // Defer to record plugin
451
+ return { success: false };
452
+ }
453
+ const tableName = record.get('name').asString().getValue();
454
+ const columns = descendants.query('sys_dictionary');
455
+ const choices = descendants.query('sys_choice');
456
+ const indexes = descendants.query('sys_index');
457
+ const documentation = descendants.query('sys_documentation');
458
+ const licensing = descendants.query('ua_table_licensing_config');
459
+ const autoNumber = descendants.query('sys_number');
460
+ let collectionRecord;
461
+ let displayColumn;
462
+ const elements = [];
463
+ for (const column of columns) {
464
+ const displayValue = column.get('display').ifBoolean()?.getValue();
465
+ if (displayValue) {
466
+ displayColumn = column.get('element').asString().getValue();
467
+ }
468
+ if (column.get('internal_type').asString().getValue() === 'collection') {
469
+ // collection element has only table properties
470
+ collectionRecord = column;
471
+ continue;
472
+ }
473
+ const defaultValue = column.get('default_value');
474
+ const maxLength = column.get('max_length');
475
+ const dependentOnField = column.get('dependent_on_field').ifString();
476
+ const columnAttributes = [
477
+ ['name', column.get('element').asString().getValue()],
478
+ ['type', column.get('internal_type').asString().getValue()],
479
+ ['active', column.get('active').ifBoolean()?.getValue().toString()],
480
+ ['array', column.get('array').ifBoolean()?.getValue().toString()],
481
+ ['audit', column.get('audit').ifBoolean()?.getValue().toString()],
482
+ [
483
+ 'default_value',
484
+ defaultValue.ifString()?.getValue() ??
485
+ defaultValue.ifNumber()?.toString().getValue() ??
486
+ defaultValue.ifBoolean()?.toString().getValue() ??
487
+ defaultValue
488
+ .ifArray()
489
+ ?.getElements()
490
+ .map((v) => v.asString().getValue())
491
+ .join(', '),
492
+ ],
493
+ ['unique', column.get('unique').ifBoolean()?.getValue().toString()],
494
+ ['label', column.get('column_label').ifString()?.getValue()],
495
+ ['max_length', maxLength.ifNumber()?.getValue().toString() ?? maxLength.ifString()?.getValue()],
496
+ ['mandatory', column.get('mandatory').ifBoolean()?.getValue().toString()],
497
+ ['read_only', column.get('read_only').ifBoolean()?.getValue().toString()],
498
+ ['reference_cascade_rule', column.get('reference_cascade_rule').ifString()?.getValue()],
499
+ ['calculation', column.get('calculation').ifString()?.getValue()],
500
+ ['choice', column.get('choice').ifNumber()?.getValue().toString()],
501
+ ['choice_table', column.get('choice_table').ifString()?.getValue()],
502
+ ['choice_field', column.get('choice_field').ifString()?.getValue()],
503
+ ['display', displayValue?.toString()],
504
+ ['function_field', column.get('function_field').ifBoolean()?.getValue().toString()],
505
+ ['attributes', column.get('attributes').ifString()?.getValue()],
506
+ ['inactive', column.get('inactive').ifBoolean()?.getValue().toString()],
507
+ ['dynamic_default', column.get('dynamic_default').ifString()?.getValue()],
508
+ ['spell_check', column.get('spell_check').ifBoolean()?.getValue().toString()],
509
+ ['xml_view', column.get('xml_view').ifBoolean()?.getValue().toString()],
510
+ ['table_reference', column.get('table_reference').ifBoolean()?.getValue().toString()],
511
+ ['text_index', column?.get('text_index').ifBoolean()?.getValue().toString()],
512
+ ['element_reference', column.get('element_reference').ifBoolean()?.getValue().toString()],
513
+ ['primary', column.get('primary').ifBoolean()?.getValue().toString()],
514
+ ['dependent', column.get('dependent').ifString()?.getValue().toString()],
515
+ ['dependent_on_field', dependentOnField?.getValue()],
516
+ [
517
+ 'use_dependent_field',
518
+ dependentOnField ? (!!dependentOnField.getValue()).toString() : undefined,
519
+ ],
520
+ ['use_dynamic_default', column.get('use_dynamic_default').ifBoolean()?.getValue().toString()],
521
+ ['reference', column.get('reference').ifString()?.getValue()],
522
+ ['function_definition', column.get('function_definition').ifString()?.getValue()],
523
+ ['reference_floats', column.get('reference_floats').ifBoolean()?.getValue().toString()],
524
+ ['reference_key', column.get('reference_key').ifString()?.getValue()],
525
+ ['dynamic_creation_script', column.get('dynamic_creation_script').ifString()?.getValue()],
526
+ ['dynamic_creation', column.get('dynamic_creation').ifBoolean()?.getValue().toString()],
527
+ ['plural', column.get('plural').ifString()?.getValue()],
528
+ ['hint', column.get('hint').ifString()?.getValue()],
529
+ ['help', column.get('help').ifString()?.getValue()],
530
+ ['virtual', column.get('virtual').ifBoolean()?.getValue().toString()],
531
+ ['widget', column.get('widget').ifString()?.getValue()],
532
+ ['reference_qual', column.get('reference_qual').ifString()?.getValue()],
533
+ ['reference_qual_condition', column.get('reference_qual_condition').ifString()?.getValue()],
534
+ ];
535
+ const choiceElements = choices
536
+ .filter((choice) => choice.get('element').asString().getValue() ===
537
+ column.get('element').asString().getValue())
538
+ .map((choice) => createElement('element', filterUndefinedAttributes([
539
+ ['value', choice.get('value').ifString()?.getValue()],
540
+ ['label', choice.get('label').ifString()?.getValue()],
541
+ [
542
+ 'dependent_value',
543
+ choice.get('dependent_value').ifNumber()?.getValue().toString() ??
544
+ choice.get('dependent_value').ifString()?.asString().getValue(),
545
+ ],
546
+ ['inactive', choice.get('inactive').ifBoolean()?.getValue().toString()],
547
+ [
548
+ 'inactive_on_update',
549
+ choice.get('inactive_on_update').ifBoolean()?.getValue().toString(),
550
+ ],
551
+ ['sequence', choice.get('sequence').ifNumber()?.getValue().toString()],
552
+ ])));
553
+ elements.push(createElement('element', filterUndefinedAttributes(columnAttributes), choiceElements.length ? [createElement('choice', [], choiceElements)] : []));
554
+ }
555
+ const indexElements = indexes.map((index) => {
556
+ const indexAttributes = [
557
+ ['name', index.get('index_name').ifString()?.getValue()],
558
+ ['unique', index.get('unique_index').ifBoolean()?.getValue().toString()],
559
+ ];
560
+ const indexColumns = index
561
+ .get('col_name_string')
562
+ .asString()
563
+ .getValue()
564
+ .split(',')
565
+ .map((col) => createElement('element', [['name', col.trim()]]));
566
+ return createElement('index', filterUndefinedAttributes(indexAttributes), indexColumns);
567
+ });
568
+ const tableAttributes = [
569
+ ['name', tableName],
570
+ ['type', 'collection'],
571
+ ['label', record.get('label').ifString()?.getValue()],
572
+ ['extends', record.get('super_class').ifRecordId()?.getPrimaryKey()],
573
+ ['is_extendable', record.get('is_extendable').ifBoolean()?.getValue().toString()],
574
+ ['text_index', collectionRecord?.get('text_index').ifBoolean()?.getValue().toString()],
575
+ ['read_only', collectionRecord?.get('read_only').ifBoolean()?.getValue().toString()],
576
+ ['audit', collectionRecord?.get('audit').ifBoolean()?.getValue().toString()],
577
+ ['display', displayColumn],
578
+ ['access', record.get('access').ifString()?.getValue()],
579
+ ['caller_access', record.get('caller_access').ifNumber()?.getValue().toString()],
580
+ ['ws_access', record.get('ws_access').ifBoolean()?.getValue().toString()],
581
+ ['read_access', record.get('read_access').ifBoolean()?.getValue().toString()],
582
+ ['alter_access', record.get('alter_access').ifBoolean()?.getValue().toString()],
583
+ ['create_access', record.get('create_access').ifBoolean()?.getValue().toString()],
584
+ ['update_access', record.get('update_access').ifBoolean()?.getValue().toString()],
585
+ ['delete_access', record.get('delete_access').ifBoolean()?.getValue().toString()],
586
+ ['actions_access', record.get('actions_access').ifBoolean()?.getValue().toString()],
587
+ ['client_scripts_access', record.get('client_scripts_access').ifBoolean()?.getValue().toString()],
588
+ ['scriptable_table', record.get('scriptable_table').ifBoolean()?.getValue().toString()],
589
+ ['attributes', collectionRecord?.get('attributes').ifString()?.getValue()],
590
+ ];
591
+ const tableXml = createElement('database', [], [
592
+ createElement('element', filterUndefinedAttributes(tableAttributes), [
593
+ ...elements,
594
+ ...indexElements,
595
+ ]),
596
+ ]).end({ prettyPrint: true });
597
+ const documentationFiles = generateRecordXml(documentation.filter((doc) => !(0, column_plugin_1.isDefaultDocumentation)(doc.get('element')?.toString().getValue(), [doc])), config, (doc) => `sys_documentation_${tableName}${doc.get('element').isDefined() ? `_${doc.get('element').asString().getValue()}` : ''}_${doc.get('language').isDefined() ? doc.get('language').asString().getValue() : 'en'}.xml`);
598
+ const licensingFiles = generateRecordXml(licensing.filter((licensing) => !isDefaultLicenseConfig(tableName, licensing)), config, (record) => `ua_table_licensing_config_${record.getId().getValue()}.xml`);
599
+ const autoNumberFiles = generateRecordXml(autoNumber, config, (record) => `sys_number_${record.getId().getValue()}.xml`);
600
+ return {
601
+ success: true,
602
+ value: [
603
+ {
604
+ name: `${tableName}.xml`,
605
+ category: 'dictionary',
606
+ content: tableXml,
607
+ },
608
+ ...documentationFiles,
609
+ ...licensingFiles,
610
+ ...autoNumberFiles,
611
+ ],
612
+ };
613
+ },
614
+ },
615
+ sys_dictionary: {
616
+ coalesce: ['name', 'element'],
617
+ },
618
+ sys_documentation: {
619
+ coalesce: ['name', 'element', 'language'],
620
+ },
621
+ ua_table_licensing_config: {
622
+ coalesce: ['name'],
623
+ },
624
+ sys_index: {
625
+ coalesce: ['logical_table_name', 'col_name_string'],
626
+ },
627
+ sys_number: {
628
+ coalesce: ['category', 'prefix'],
629
+ },
630
+ },
631
+ shapes: [
632
+ {
633
+ shape: sdk_build_core_1.CallExpressionShape,
634
+ fileTypes: ['fluent'],
635
+ async toRecord(callExpression, { config, factory, transform, diagnostics, compiler }) {
636
+ if (callExpression.getCallee() !== 'Table') {
637
+ return { success: false };
638
+ }
639
+ const statement = callExpression
640
+ .getOriginalNode()
641
+ .getFirstAncestorByKind(sdk_build_core_1.ts.SyntaxKind.VariableStatement);
642
+ const table = callExpression.getArgument(0).asObject().withAliasedKeys(tableAliases);
643
+ (0, utils_1.generateDeprecatedDiagnostics)(table, diagnostics);
644
+ const relatedRecords = [];
645
+ const tableName = table.get('name').asString();
646
+ if (!tableName.getValue().match(tableNameRegex)) {
647
+ diagnostics.error(table.get('name'), 'Table name must only contain lowercase letters, numbers, and underscores and end with a letter or number');
648
+ }
649
+ let ignoreColumnNameCheck = false;
650
+ const scopeName = config.scope;
651
+ const scopeRegex = new RegExp(`^${scopeName}_`);
652
+ const tableNameMatch = tableName.getValue().match(scopeRegex);
653
+ if (!tableNameMatch && !(0, sdk_build_core_1.isSNScope)(scopeName) && scopeName !== 'global') {
654
+ const nameNode = tableName.getOriginalNode();
655
+ if (nameNode && !nameNode.isKind(sdk_build_core_1.ts.SyntaxKind.AsExpression)) {
656
+ // 'sn' and 'now' scoped apps ignore this validation
657
+ diagnostics.error(table.get('name'), `'name' property should start with scope prefix '${scopeName}_'`);
658
+ }
659
+ else {
660
+ ignoreColumnNameCheck = true;
661
+ }
662
+ }
663
+ const declaration = callExpression.getOriginalNode().getParent();
664
+ const exportedByName = declaration?.isKind(sdk_build_core_1.ts.SyntaxKind.VariableDeclaration) &&
665
+ declaration.isNamedExport() &&
666
+ declaration.getName() === tableName.getValue();
667
+ if (!exportedByName) {
668
+ diagnostics.error(callExpression, `Table definition should be exported as a named export with the name '${tableName.getValue()}'`);
669
+ }
670
+ // sys_dictionary
671
+ const schema = table.get('schema').asObject();
672
+ for (const [name, column] of schema.entries()) {
673
+ if (!name.match(columnNameRegex)) {
674
+ diagnostics.error(column.getOriginalNode().getParentIfKind(sdk_build_core_1.ts.SyntaxKind.PropertyAssignment) ?? column, 'Column name must only contain lowercase letters, numbers, and underscores');
675
+ }
676
+ if (!ignoreColumnNameCheck &&
677
+ !tableNameMatch &&
678
+ !(0, sdk_build_core_1.isSNScope)(scopeName) &&
679
+ scopeName !== 'global' &&
680
+ !name.match(scopeRegex)) {
681
+ // 'sn' and 'now' scoped apps ignore this validation
682
+ diagnostics.error(column.getOriginalNode().getParentIfKind(sdk_build_core_1.ts.SyntaxKind.PropertyAssignment) ?? column, `Column name should be prefixed with scope '${scopeName}_' if table name does not contain prefix`);
683
+ }
684
+ const display = table.get('display').ifString()?.getValue() === name;
685
+ const result = await transform.toRecord((0, column_helper_1.addFieldsToColumn)({ name, table: tableName.getValue(), display }, column.as(sdk_build_core_1.CallExpressionShape)));
686
+ if (!result.success) {
687
+ diagnostics.error(column, 'Invalid column in table schema');
688
+ return { success: false };
689
+ }
690
+ relatedRecords.push(result.value);
691
+ }
692
+ // sys_index
693
+ if (table.get('index').isArray()) {
694
+ for (const index of table.get('index').asArray().getElements()) {
695
+ const indexObject = index.asObject().getValue();
696
+ const colNames = Array.isArray(indexObject['element'])
697
+ ? indexObject['element'].join(',')
698
+ : indexObject['element'];
699
+ relatedRecords.push(factory.createRecord({
700
+ source: statement ?? callExpression,
701
+ table: 'sys_index',
702
+ properties: {
703
+ index_name: indexObject['name'],
704
+ col_name_string: colNames,
705
+ unique_index: indexObject['unique'] === true,
706
+ logical_table_name: table.get('name').asString().getValue(),
707
+ },
708
+ }));
709
+ }
710
+ }
711
+ // ua_table_licensing_config
712
+ if (table.get('licensingConfig').isObject()) {
713
+ const licenseObj = table.get('licensingConfig').asObject().withAliasedKeys(licensingAliases);
714
+ (0, utils_1.generateDeprecatedDiagnostics)(licenseObj, diagnostics);
715
+ const licenseRecord = factory.createRecord({
716
+ source: statement ?? callExpression,
717
+ table: 'ua_table_licensing_config',
718
+ properties: licenseObj.transform(({ $ }) => ({
719
+ name: $.val(table.get('name')),
720
+ license_model: $.from('licenseModel').def('none'),
721
+ owner_condition: $.from('ownerCondition'),
722
+ license_condition: $.from('licenseCondition'),
723
+ is_fulfillment: $.from('isFulfillment').def(false),
724
+ op_delete: $.from('opDelete').def(true),
725
+ op_update: $.from('opUpdate').def(true),
726
+ license_roles: $.from('licenseRoles')
727
+ .map((licenseRoles) => {
728
+ return (licenseRoles
729
+ .ifArray()
730
+ ?.getElements()
731
+ .map((e) => e.asString().getValue())
732
+ .join(',') ?? []);
733
+ })
734
+ .def([]),
735
+ op_insert: $.from('opInsert').def(true),
736
+ })),
737
+ });
738
+ relatedRecords.push(licenseRecord);
739
+ }
740
+ else {
741
+ relatedRecords.push(factory.createRecord({
742
+ source: statement ?? callExpression,
743
+ table: 'ua_table_licensing_config',
744
+ properties: {
745
+ name: tableName,
746
+ license_model: 'none',
747
+ is_fulfillment: false,
748
+ op_delete: true,
749
+ op_insert: true,
750
+ op_update: true,
751
+ },
752
+ }));
753
+ }
754
+ // sys_documentation
755
+ if (table.get('label').isArray()) {
756
+ const documentation = table.get('label').asArray().getElements();
757
+ const languages = new Set();
758
+ for (const doc of documentation) {
759
+ const docObject = doc.asObject().withAliasedKeys(documentationAliases);
760
+ (0, utils_1.generateDeprecatedDiagnostics)(docObject, diagnostics);
761
+ const language = docObject.get('language').ifString()?.getValue();
762
+ if (language) {
763
+ if (language.length !== 2) {
764
+ diagnostics.error(doc.getOriginalNode(), `'language' must be a 2 character identifier (Ex. 'en', 'es')`);
765
+ }
766
+ if (languages.has(language)) {
767
+ diagnostics.error(doc.getOriginalNode(), `'language' must be unique per table/column`);
768
+ }
769
+ languages.add(language);
770
+ }
771
+ relatedRecords.push(factory.createRecord({
772
+ source: statement ?? callExpression,
773
+ table: 'sys_documentation',
774
+ properties: docObject.transform(({ $ }) => ({
775
+ name: $.val(table.get('name').asString().getValue()),
776
+ element: $.val(undefined),
777
+ label: $,
778
+ help: $,
779
+ hint: $,
780
+ language: $,
781
+ plural: $,
782
+ url: $,
783
+ url_target: $.from('urlTarget'),
784
+ })),
785
+ }));
786
+ }
787
+ }
788
+ else {
789
+ relatedRecords.push(factory.createRecord({
790
+ source: statement ?? callExpression,
791
+ table: 'sys_documentation',
792
+ properties: {
793
+ name: tableName,
794
+ element: undefined,
795
+ language: 'en',
796
+ label: table.get('label').ifString() ?? tableName,
797
+ plural: (0, column_plugin_1.generatePlural)(table.get('label')?.ifString()?.getValue() ?? tableName.getValue()),
798
+ },
799
+ }));
800
+ }
801
+ // sys-number
802
+ let numberRef;
803
+ if (table.get('autoNumber').isObject()) {
804
+ const autoNumber = table.get('autoNumber').asObject().withAliasedKeys(autoNumberAliases);
805
+ const sysNumberRecord = factory.createRecord({
806
+ source: statement ?? callExpression,
807
+ table: 'sys_number',
808
+ properties: autoNumber.transform(({ $ }) => ({
809
+ category: $.val(table.get('name').getValue()),
810
+ maximum_digits: $.from('numberOfDigits').toNumber().def(7),
811
+ number: $.def(1000),
812
+ prefix: $.from('prefix').def('PRE'),
813
+ })),
814
+ });
815
+ numberRef = sysNumberRecord.getId();
816
+ relatedRecords.push(sysNumberRecord);
817
+ }
818
+ // sys_dictionary (collection)
819
+ relatedRecords.push(factory.createRecord({
820
+ source: statement ?? callExpression,
821
+ table: 'sys_dictionary',
822
+ properties: table.transform(({ $ }) => ({
823
+ name: $,
824
+ element: $.val(undefined),
825
+ internal_type: $.def('collection'),
826
+ attributes: $.map((attributes) => {
827
+ if (!attributes.isObject()) {
828
+ return undefined;
829
+ }
830
+ const attributesObj = attributes.asObject().getValue();
831
+ return Object.entries(attributesObj)
832
+ .map(([key, value]) => `${key}=${value}`)
833
+ .join(',');
834
+ }).def(''),
835
+ audit: $.def(false),
836
+ read_only: $.from('readOnly').def(false),
837
+ text_index: $.from('textIndex').def(false),
838
+ })),
839
+ }));
840
+ const hasAction = (actionName, actions) => {
841
+ return actions
842
+ .ifArray()
843
+ ?.getElements()
844
+ .some((action) => action.isString() && action.getValue() === actionName);
845
+ };
846
+ // sys_db_object
847
+ const tableRecord = factory.createRecord({
848
+ source: statement ?? callExpression,
849
+ table: 'sys_db_object',
850
+ properties: table.transform(({ $ }) => ({
851
+ client_scripts_access: $.from('allowClientScripts').toBoolean().def(false),
852
+ alter_access: $.from('allowNewFields').toBoolean().def(false),
853
+ actions_access: $.from('allowUiActions').toBoolean().def(false),
854
+ ws_access: $.from('allowWebServiceAccess').toBoolean().def(false),
855
+ number_ref: $.val(numberRef),
856
+ access: $.from('accessibleFrom').def('public'),
857
+ caller_access: $.from('callerAccess').map((callerAccess) => callerAccessLevels.indexOf((callerAccess.ifString()?.getValue() ?? 'none'))),
858
+ super_class: $.from('extends').map((v) => v.ifString()?.pipe((parent) => factory.createReference({
859
+ source: parent,
860
+ table: 'sys_db_object',
861
+ keys: { name: parent.getValue() },
862
+ })) ?? v.ifDefined()?.toRecordId()),
863
+ read_access: $.from('actions')
864
+ .map((actions) => hasAction('read', actions))
865
+ .def(true),
866
+ update_access: $.from('actions')
867
+ .map((actions) => hasAction('update', actions))
868
+ .def(false),
869
+ delete_access: $.from('actions')
870
+ .map((actions) => hasAction('delete', actions))
871
+ .def(false),
872
+ create_access: $.from('actions')
873
+ .map((actions) => hasAction('create', actions))
874
+ .def(false),
875
+ is_extendable: $.from('extensible').toBoolean().def(false),
876
+ label: $.map((label) => (label.isString() ? label.asString() : undefined)),
877
+ live_feed_enabled: $.from('liveFeed').toBoolean().def(false),
878
+ name: $,
879
+ scriptable_table: $.from('scriptableTable').toBoolean().def(false),
880
+ })),
881
+ });
882
+ if (exportedByName) {
883
+ addTableToGlobalGeneratedFile(table, callExpression.getOriginalFilePath(), compiler);
884
+ }
885
+ return {
886
+ success: true,
887
+ value: tableRecord.with(...relatedRecords),
888
+ };
889
+ },
890
+ },
891
+ ],
892
+ nodes: [
893
+ {
894
+ node: 'VariableStatement',
895
+ fileTypes: ['fluent'],
896
+ entryPoint: true,
897
+ },
898
+ {
899
+ node: 'ExportAssignment',
900
+ fileTypes: ['fluent'],
901
+ entryPoint: true,
902
+ toShape(node, { diagnostics }) {
903
+ const expression = node.getExpression().asKind(sdk_build_core_1.ts.SyntaxKind.CallExpression)?.getExpression();
904
+ if (expression && expression.getText() === 'Table') {
905
+ diagnostics.error(expression, 'Export assignments are not supported for Table definitions');
906
+ }
907
+ return { success: false };
908
+ },
909
+ },
910
+ ],
911
+ });
912
+ function parseTableBootstrapXml(xml) {
913
+ const parsedXml = BootstrapDatabaseSchema.safeParse(xml);
914
+ if (!parsedXml.success) {
915
+ return null;
916
+ }
917
+ const table = parsedXml.data.element;
918
+ const columns = [];
919
+ if (table.element) {
920
+ const mapColumnToDefinition = (column) => ({
921
+ name: column['@_name'],
922
+ type: column['@_internal_type'] ?? column['@_type'],
923
+ defaultValue: column['@_default'] ?? column['@_default_value'],
924
+ audit: column['@_audit'],
925
+ maxLength: column['@_max_length'],
926
+ isMandatory: column['@_mandatory'],
927
+ isReadOnly: column['@_read_only'],
928
+ referenceTable: column['@_reference_table'],
929
+ referenceQual: column['@_reference_qual'],
930
+ columnLabel: column['@_label'],
931
+ choices: column.choice?.element
932
+ ? Array.isArray(column.choice.element)
933
+ ? column.choice.element.map((choice) => ({
934
+ label: choice['@_label'],
935
+ value: choice['@_value'] ?? '',
936
+ sequence: choice['@_sequence'],
937
+ dependentValue: choice['@_dependent_value'],
938
+ hint: choice['@_hint'],
939
+ inactive: choice['@_inactive'],
940
+ inactiveOnUpdate: choice['@_inactive_on_update'],
941
+ language: choice['@_language'],
942
+ }))
943
+ : [
944
+ {
945
+ label: column.choice.element['@_label'],
946
+ value: column.choice.element['@_value'] ?? '',
947
+ sequence: column.choice.element['@_sequence'],
948
+ dependentValue: column.choice.element['@_dependent_value'],
949
+ hint: column.choice.element['@_hint'],
950
+ inactive: column.choice.element['@_inactive'],
951
+ inactiveOnUpdate: column.choice.element['@_inactive_on_update'],
952
+ language: column.choice.element['@_language'],
953
+ },
954
+ ]
955
+ : undefined,
956
+ isActive: column['@_active'],
957
+ display: column['@_display'],
958
+ useDependentField: column['@_use_dependent_field'],
959
+ useDynamicDefault: column['@_use_dynamic_default'],
960
+ reference: column['@_reference'],
961
+ isVirtual: column['@_virtual'],
962
+ calculation: column['@_calculation'],
963
+ choiceField: column['@_choice_field'],
964
+ functionDefinition: column['@_function_definition'],
965
+ referenceFloats: column['@_reference_floats'],
966
+ referenceKey: column['@_reference_key'],
967
+ dynamicCreationScript: column['@_dynamic_creation_script'],
968
+ dynamicCreation: column['@_dynamic_creation'],
969
+ plural: column['@_plural'],
970
+ hint: column['@_hint'],
971
+ help: column['@_help'],
972
+ widget: column['@_widget'],
973
+ tableReference: column['@_table_reference'],
974
+ elementReference: column['@_element_reference'],
975
+ unique: column['@_unique'],
976
+ spellCheck: column['@_spell_check'],
977
+ xmlView: column['@_xml_view'],
978
+ isArray: column['@_array'],
979
+ textIndex: column['@_text_index'],
980
+ isPrimary: column['@_primary'],
981
+ attributes: column['@_attributes'],
982
+ referenceCascadeRule: column['@_reference_cascade_rule'],
983
+ choiceValue: column['@_choice'],
984
+ choiceTable: column['@_choice_table'],
985
+ dependent: column['@_dependent'],
986
+ });
987
+ if (Array.isArray(table.element)) {
988
+ columns.push(...table.element.map(mapColumnToDefinition));
989
+ }
990
+ else {
991
+ columns.push(mapColumnToDefinition(table.element));
992
+ }
993
+ }
994
+ const indexes = [];
995
+ if (table.index) {
996
+ const mapIndexToDefinition = (index) => ({
997
+ name: index['@_name'],
998
+ unique: index['@_unique'],
999
+ columns: index.element
1000
+ ? Array.isArray(index.element)
1001
+ ? index.element.map((element) => element['@_name'])
1002
+ : [index.element['@_name']]
1003
+ : [],
1004
+ });
1005
+ if (Array.isArray(table.index)) {
1006
+ indexes.push(...table.index.map(mapIndexToDefinition));
1007
+ }
1008
+ else {
1009
+ indexes.push(mapIndexToDefinition(table.index));
1010
+ }
1011
+ }
1012
+ return {
1013
+ name: table['@_name'],
1014
+ label: table['@_label'],
1015
+ plural: table['@_plural'],
1016
+ extends: table['@_extends'],
1017
+ columns,
1018
+ indexes,
1019
+ audit: table['@_audit'],
1020
+ readOnly: table['@_read_only'],
1021
+ textIndex: table['@_text_index'],
1022
+ clientScriptsAccess: table['@_client_scripts_access'],
1023
+ wsAccess: table['@_ws_access'],
1024
+ display: table['@_display'],
1025
+ alterAccess: table['@_alter_access'],
1026
+ createAccess: table['@_create_access'],
1027
+ deleteAccess: table['@_delete_access'],
1028
+ updateAccess: table['@_update_access'],
1029
+ callerAccess: table['@_caller_access'],
1030
+ actionsAccess: table['@_actions_access'],
1031
+ readAccess: table['@_read_access'],
1032
+ isExtendable: table['@_is_extendable'],
1033
+ scriptableTable: table['@_scriptable_table'],
1034
+ attributes: table['@_attributes'],
1035
+ };
1036
+ }
1037
+ function tableDefToRecordProperties(tableDef) {
1038
+ const sysDbObject = {
1039
+ name: tableDef.name,
1040
+ label: tableDef.label,
1041
+ super_class: tableDef.extends,
1042
+ is_extendable: tableDef.isExtendable,
1043
+ scriptable_table: tableDef.scriptableTable,
1044
+ client_scripts_access: tableDef.clientScriptsAccess,
1045
+ ws_access: tableDef.wsAccess,
1046
+ alter_access: tableDef.alterAccess,
1047
+ create_access: tableDef.createAccess,
1048
+ delete_access: tableDef.deleteAccess,
1049
+ update_access: tableDef.updateAccess,
1050
+ caller_access: tableDef.callerAccess,
1051
+ actions_access: tableDef.actionsAccess,
1052
+ read_access: tableDef.readAccess,
1053
+ };
1054
+ const sysDictionary = [];
1055
+ const sysChoice = [];
1056
+ const sysDocumentation = [];
1057
+ // table documentation
1058
+ if (tableDef.label && tableDef.plural) {
1059
+ sysDocumentation.push({
1060
+ name: tableDef.name,
1061
+ element: undefined,
1062
+ label: tableDef.label,
1063
+ plural: tableDef.plural,
1064
+ language: 'en',
1065
+ hint: undefined,
1066
+ help: undefined,
1067
+ });
1068
+ }
1069
+ for (const column of tableDef.columns) {
1070
+ sysDictionary.push({
1071
+ name: tableDef.name,
1072
+ element: column.name,
1073
+ internal_type: column.type || 'string',
1074
+ default_value: column.defaultValue,
1075
+ max_length: column.maxLength,
1076
+ mandatory: column.isMandatory,
1077
+ read_only: column.isReadOnly,
1078
+ reference_table: column.referenceTable,
1079
+ reference_qual: column.referenceQual,
1080
+ column_label: column.columnLabel,
1081
+ active: column.isActive,
1082
+ display: tableDef.display === column.name || column.display,
1083
+ use_dependent_field: column.useDependentField,
1084
+ use_dynamic_default: column.useDynamicDefault,
1085
+ reference: column.reference,
1086
+ virtual: column.isVirtual,
1087
+ default: column.defaultValue,
1088
+ calculation: column.calculation,
1089
+ choice_field: column.choiceField,
1090
+ function_definition: column.functionDefinition,
1091
+ reference_floats: column.referenceFloats,
1092
+ reference_key: column.referenceKey,
1093
+ dynamic_creation_script: column.dynamicCreationScript,
1094
+ dynamic_creation: column.dynamicCreation,
1095
+ plural: column.plural,
1096
+ hint: column.hint,
1097
+ help: column.help,
1098
+ widget: column.widget,
1099
+ table_reference: column.tableReference,
1100
+ element_reference: column.elementReference,
1101
+ unique: column.unique,
1102
+ spell_check: column.spellCheck,
1103
+ xml_view: column.xmlView,
1104
+ array: column.isArray,
1105
+ text_index: column.textIndex,
1106
+ primary: column.isPrimary,
1107
+ attributes: column.attributes,
1108
+ reference_cascade_rule: column.referenceCascadeRule,
1109
+ choice: column.choiceValue,
1110
+ choice_table: column.choiceTable,
1111
+ dependent: column.dependent,
1112
+ function_field: column.functionDefinition ? true : undefined,
1113
+ audit: column.audit,
1114
+ });
1115
+ if (column.choices?.length) {
1116
+ for (const choice of column.choices) {
1117
+ sysChoice.push({
1118
+ name: tableDef.name,
1119
+ element: column.name,
1120
+ label: choice.label || choice.value,
1121
+ value: choice.value,
1122
+ sequence: choice.sequence,
1123
+ dependent_value: choice.dependentValue,
1124
+ hint: choice.hint,
1125
+ inactive: choice.inactive,
1126
+ inactive_on_update: choice.inactiveOnUpdate,
1127
+ language: choice.language,
1128
+ });
1129
+ }
1130
+ }
1131
+ // Add column documentation
1132
+ sysDocumentation.push({
1133
+ name: tableDef.name,
1134
+ element: column.name,
1135
+ label: column.columnLabel || column.name,
1136
+ plural: column.plural || (0, column_plugin_1.generatePlural)(column.columnLabel || column.name),
1137
+ language: 'en',
1138
+ hint: column.hint,
1139
+ help: column.help,
1140
+ });
1141
+ }
1142
+ // sys_dictionary collection record
1143
+ sysDictionary.push({
1144
+ name: tableDef.name,
1145
+ internal_type: 'collection',
1146
+ // table properties
1147
+ attributes: tableDef.attributes,
1148
+ audit: tableDef.audit,
1149
+ text_index: tableDef.textIndex,
1150
+ read_only: tableDef.readOnly,
1151
+ // column properties left undefined
1152
+ element: undefined,
1153
+ default_value: undefined,
1154
+ max_length: undefined,
1155
+ mandatory: undefined,
1156
+ reference_table: undefined,
1157
+ reference_qual: undefined,
1158
+ column_label: undefined,
1159
+ active: undefined,
1160
+ display: undefined,
1161
+ use_dependent_field: undefined,
1162
+ use_dynamic_default: undefined,
1163
+ reference: undefined,
1164
+ virtual: undefined,
1165
+ default: undefined,
1166
+ calculation: undefined,
1167
+ choice_field: undefined,
1168
+ function_definition: undefined,
1169
+ reference_floats: undefined,
1170
+ reference_key: undefined,
1171
+ dynamic_creation_script: undefined,
1172
+ dynamic_creation: undefined,
1173
+ plural: undefined,
1174
+ hint: undefined,
1175
+ help: undefined,
1176
+ widget: undefined,
1177
+ table_reference: undefined,
1178
+ element_reference: undefined,
1179
+ unique: undefined,
1180
+ spell_check: undefined,
1181
+ xml_view: undefined,
1182
+ array: undefined,
1183
+ primary: undefined,
1184
+ reference_cascade_rule: undefined,
1185
+ choice: undefined,
1186
+ choice_table: undefined,
1187
+ dependent: undefined,
1188
+ function_field: undefined,
1189
+ });
1190
+ const sysIndex = [];
1191
+ for (const index of tableDef.indexes) {
1192
+ sysIndex.push({
1193
+ index_name: index.name,
1194
+ col_name_string: index.columns.join(','),
1195
+ unique_index: index.unique,
1196
+ logical_table_name: tableDef.name,
1197
+ });
1198
+ }
1199
+ return {
1200
+ sysDbObject,
1201
+ sysDictionary,
1202
+ sysChoice,
1203
+ sysIndex,
1204
+ sysDocumentation,
1205
+ };
1206
+ }
1207
+ function addTableToGlobalGeneratedFile(tableArg, sourceFilePath, compiler) {
1208
+ const { interfaces, properties, imports, namedImports } = {
1209
+ interfaces: [],
1210
+ properties: [],
1211
+ imports: {},
1212
+ namedImports: [],
1213
+ };
1214
+ const generatedTableFile = compiler.getGeneratedTableFile();
1215
+ const tableName = tableArg.get('name').asString().getValue();
1216
+ if (!(tableName.trim().length > 0 && tableName.match(tableNameRegex))) {
1217
+ return;
1218
+ }
1219
+ const extendsTable = tableArg.get('extends').ifString()?.getValue();
1220
+ if (!compiler.interfaceExistsInGlobalDeclaration(tableName)) {
1221
+ interfaces.push({
1222
+ name: tableName,
1223
+ extends: [`Helper<typeof ${tableName}>`],
1224
+ });
1225
+ }
1226
+ if (!compiler.propertyExistsInGlobalDeclaration(tableName)) {
1227
+ const interfaceType = extendsTable
1228
+ ? `Table<TableSchemas.${tableName}, "${extendsTable}">`
1229
+ : `Table<TableSchemas.${tableName}>`;
1230
+ properties.push({
1231
+ name: tableName,
1232
+ type: interfaceType,
1233
+ });
1234
+ }
1235
+ if (generatedTableFile) {
1236
+ const resolvedModuleSpecifier = generatedTableFile.getRelativePathAsModuleSpecifierTo(sourceFilePath);
1237
+ if (resolvedModuleSpecifier) {
1238
+ const importExists = compiler.importExistsInGlobalDeclaration(resolvedModuleSpecifier);
1239
+ if (!importExists) {
1240
+ if (imports[sourceFilePath]) {
1241
+ const existingImport = imports[sourceFilePath];
1242
+ if (Array.isArray(existingImport.namedImports)) {
1243
+ ;
1244
+ existingImport.namedImports.push(tableName);
1245
+ }
1246
+ }
1247
+ else {
1248
+ imports[sourceFilePath] = {
1249
+ namedImports: [tableName],
1250
+ moduleSpecifier: resolvedModuleSpecifier,
1251
+ };
1252
+ }
1253
+ }
1254
+ else {
1255
+ const namedImportExists = importExists?.getNamedImports().some((value) => value.getName() === tableName);
1256
+ if (!namedImportExists) {
1257
+ namedImports.push({
1258
+ existingImport: importExists,
1259
+ name: tableName,
1260
+ });
1261
+ }
1262
+ }
1263
+ }
1264
+ }
1265
+ if (interfaces.length > 0 || properties.length > 0 || Object.keys(imports).length > 0 || namedImports.length > 0) {
1266
+ compiler.addTableInterfacesToGlobalDeclaration({
1267
+ interfaces,
1268
+ properties,
1269
+ imports,
1270
+ namedImports,
1271
+ });
1272
+ }
1273
+ }
1274
+ function filterUndefinedProperties(obj) {
1275
+ return Object.fromEntries(Object.entries(obj).filter(([_, value]) => value !== undefined));
1276
+ }
1277
+ function filterUndefinedAttributes(attributes) {
1278
+ return attributes.filter((pair) => pair[1] !== undefined);
1279
+ }
1280
+ function createElement(name, attributes = [], children = []) {
1281
+ const element = (0, xmlbuilder2_1.create)().ele(name);
1282
+ for (const [key, value] of attributes) {
1283
+ const sanitizedValue = value.replaceAll('\n', '&#10;').replaceAll('\r', '&#13;');
1284
+ element.att(key, sanitizedValue);
1285
+ }
1286
+ for (const child of children) {
1287
+ element.import(child);
1288
+ }
1289
+ return element;
1290
+ }
1291
+ function generateRecordXml(records, config, getFileName) {
1292
+ return records.map((record) => {
1293
+ const recordBuilder = (0, sdk_build_core_1.unloadBuilder)({ scope: config.scope, scopeId: config.scopeId });
1294
+ const builder = recordBuilder.record(record);
1295
+ record
1296
+ .entries()
1297
+ .sort(([a], [b]) => a.localeCompare(b))
1298
+ .forEach(([prop, shape]) => builder.field(prop, shape));
1299
+ return {
1300
+ name: getFileName(record),
1301
+ category: record.getInstallCategory(),
1302
+ content: recordBuilder.end(),
1303
+ };
1304
+ });
1305
+ }
1306
+ function isDefaultLicenseConfig(tableName, licenseRecord) {
1307
+ const license = licenseRecord.asObject().getValue();
1308
+ const defaultRecord = {
1309
+ name: tableName,
1310
+ license_model: 'none',
1311
+ is_fulfillment: false,
1312
+ op_delete: true,
1313
+ op_insert: true,
1314
+ op_update: true,
1315
+ };
1316
+ const optionalFields = ['owner_condition', 'license_condition', 'license_roles'];
1317
+ optionalFields.forEach((field) => {
1318
+ if (field in license) {
1319
+ defaultRecord[field] = '';
1320
+ }
1321
+ });
1322
+ return (0, isEqual_1.default)(defaultRecord, license);
1323
+ }
1324
+ //# sourceMappingURL=table-plugin.js.map