@lcap/nasl 3.3.0-alpha.1 → 3.3.0-alpha.3

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 (380) hide show
  1. package/out/automate/upgrader/2.20.js.map +1 -1
  2. package/out/bak/translator.js +52 -1
  3. package/out/bak/translator.js.map +1 -1
  4. package/out/breakpoint/shared/utils.js +0 -2
  5. package/out/breakpoint/shared/utils.js.map +1 -1
  6. package/out/common/Command.d.ts +1 -0
  7. package/out/common/Command.js +9 -1
  8. package/out/common/Command.js.map +1 -1
  9. package/out/concepts/Abort__.js +2 -1
  10. package/out/concepts/Abort__.js.map +1 -1
  11. package/out/concepts/Anchor__.js +1 -1
  12. package/out/concepts/Anchor__.js.map +1 -1
  13. package/out/concepts/AnonymousFunction__.js +2 -2
  14. package/out/concepts/AnonymousFunction__.js.map +1 -1
  15. package/out/concepts/Argument__.js +1 -1
  16. package/out/concepts/Argument__.js.map +1 -1
  17. package/out/concepts/Assignee__.js.map +1 -1
  18. package/out/concepts/AssignmentLine__.js +1 -1
  19. package/out/concepts/AssignmentLine__.js.map +1 -1
  20. package/out/concepts/Assignment__.js +2 -2
  21. package/out/concepts/Assignment__.js.map +1 -1
  22. package/out/concepts/BackendVariable__.js +1 -1
  23. package/out/concepts/BackendVariable__.js.map +1 -1
  24. package/out/concepts/Backend__.js +1 -1
  25. package/out/concepts/Backend__.js.map +1 -1
  26. package/out/concepts/BatchAssignment__.js +2 -2
  27. package/out/concepts/BatchAssignment__.js.map +1 -1
  28. package/out/concepts/BinaryExpression__.js +2 -2
  29. package/out/concepts/BinaryExpression__.js.map +1 -1
  30. package/out/concepts/BindAttribute__.d.ts +2 -0
  31. package/out/concepts/BindAttribute__.js +79 -4
  32. package/out/concepts/BindAttribute__.js.map +1 -1
  33. package/out/concepts/BindDirective__.js +1 -1
  34. package/out/concepts/BindDirective__.js.map +1 -1
  35. package/out/concepts/BindEvent__.d.ts +2 -1
  36. package/out/concepts/BindEvent__.js +44 -37
  37. package/out/concepts/BindEvent__.js.map +1 -1
  38. package/out/concepts/BindStyle__.js +1 -1
  39. package/out/concepts/BindStyle__.js.map +1 -1
  40. package/out/concepts/BooleanLiteral__.js +1 -1
  41. package/out/concepts/BooleanLiteral__.js.map +1 -1
  42. package/out/concepts/CallAuthInterface__.js +1 -1
  43. package/out/concepts/CallAuthInterface__.js.map +1 -1
  44. package/out/concepts/CallConnector__.js +1 -1
  45. package/out/concepts/CallConnector__.js.map +1 -1
  46. package/out/concepts/CallFunction__.js +2 -2
  47. package/out/concepts/CallFunction__.js.map +1 -1
  48. package/out/concepts/CallInterface__.js +2 -2
  49. package/out/concepts/CallInterface__.js.map +1 -1
  50. package/out/concepts/CallLogic__.js +69 -12
  51. package/out/concepts/CallLogic__.js.map +1 -1
  52. package/out/concepts/CallQueryComponent__.d.ts +1 -1
  53. package/out/concepts/CallQueryComponent__.js +1 -1
  54. package/out/concepts/CallQueryComponent__.js.map +1 -1
  55. package/out/concepts/Comment__.js +1 -1
  56. package/out/concepts/Comment__.js.map +1 -1
  57. package/out/concepts/ConfigProperty__.js +1 -1
  58. package/out/concepts/ConfigProperty__.js.map +1 -1
  59. package/out/concepts/Connection__.js +9 -10
  60. package/out/concepts/Connection__.js.map +1 -1
  61. package/out/concepts/Constant__.js +1 -1
  62. package/out/concepts/Constant__.js.map +1 -1
  63. package/out/concepts/DataSource__.js +1 -1
  64. package/out/concepts/DataSource__.js.map +1 -1
  65. package/out/concepts/Destination__.js +2 -2
  66. package/out/concepts/Destination__.js.map +1 -1
  67. package/out/concepts/End__.js +1 -1
  68. package/out/concepts/End__.js.map +1 -1
  69. package/out/concepts/EntityIndex__.js +1 -1
  70. package/out/concepts/EntityIndex__.js.map +1 -1
  71. package/out/concepts/EntityProperty__.js +2 -2
  72. package/out/concepts/EntityProperty__.js.map +1 -1
  73. package/out/concepts/Entity__.js +2 -2
  74. package/out/concepts/Entity__.js.map +1 -1
  75. package/out/concepts/EnumItem__.js +2 -2
  76. package/out/concepts/EnumItem__.js.map +1 -1
  77. package/out/concepts/Enum__.js +2 -2
  78. package/out/concepts/Enum__.js.map +1 -1
  79. package/out/concepts/ForEachStatement__.js +27 -37
  80. package/out/concepts/ForEachStatement__.js.map +1 -1
  81. package/out/concepts/Frontend__.js +1 -1
  82. package/out/concepts/Frontend__.js.map +1 -1
  83. package/out/concepts/Function__.js +2 -2
  84. package/out/concepts/Function__.js.map +1 -1
  85. package/out/concepts/Identifier__.js +1 -1
  86. package/out/concepts/Identifier__.js.map +1 -1
  87. package/out/concepts/IfStatement__.js +2 -2
  88. package/out/concepts/IfStatement__.js.map +1 -1
  89. package/out/concepts/Interface__.js +1 -1
  90. package/out/concepts/Interface__.js.map +1 -1
  91. package/out/concepts/JSBlock__.js +1 -1
  92. package/out/concepts/JSBlock__.js.map +1 -1
  93. package/out/concepts/JavaLogic__.js +1 -1
  94. package/out/concepts/JavaLogic__.js.map +1 -1
  95. package/out/concepts/LogicItem__.js +3 -2
  96. package/out/concepts/LogicItem__.js.map +1 -1
  97. package/out/concepts/Logic__.js +2 -1
  98. package/out/concepts/Logic__.js.map +1 -1
  99. package/out/concepts/MatchCase__.js +1 -1
  100. package/out/concepts/MatchCase__.js.map +1 -1
  101. package/out/concepts/Match__.js +2 -2
  102. package/out/concepts/Match__.js.map +1 -1
  103. package/out/concepts/MemberExpression__.d.ts +1 -0
  104. package/out/concepts/MemberExpression__.js +117 -2
  105. package/out/concepts/MemberExpression__.js.map +1 -1
  106. package/out/concepts/Module__.d.ts +1 -1
  107. package/out/concepts/Module__.js +34 -35
  108. package/out/concepts/Module__.js.map +1 -1
  109. package/out/concepts/NewComposite__.js +2 -2
  110. package/out/concepts/NewComposite__.js.map +1 -1
  111. package/out/concepts/NewList__.js +2 -2
  112. package/out/concepts/NewList__.js.map +1 -1
  113. package/out/concepts/NewMap__.js +2 -2
  114. package/out/concepts/NewMap__.js.map +1 -1
  115. package/out/concepts/New__.js +1 -1
  116. package/out/concepts/New__.js.map +1 -1
  117. package/out/concepts/NullLiteral__.js +1 -1
  118. package/out/concepts/NullLiteral__.js.map +1 -1
  119. package/out/concepts/NumericLiteral__.js +1 -1
  120. package/out/concepts/NumericLiteral__.js.map +1 -1
  121. package/out/concepts/OqlQueryComponent__.js +2 -2
  122. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  123. package/out/concepts/Param__.js +1 -1
  124. package/out/concepts/Param__.js.map +1 -1
  125. package/out/concepts/ProcessElement__.js +1 -1
  126. package/out/concepts/ProcessElement__.js.map +1 -1
  127. package/out/concepts/ProcessOutcome__.js +1 -1
  128. package/out/concepts/ProcessOutcome__.js.map +1 -1
  129. package/out/concepts/ProcessOutcomes__.js +1 -1
  130. package/out/concepts/ProcessOutcomes__.js.map +1 -1
  131. package/out/concepts/Process__.js +1 -1
  132. package/out/concepts/Process__.js.map +1 -1
  133. package/out/concepts/QueryAggregateExpression__.js +1 -1
  134. package/out/concepts/QueryAggregateExpression__.js.map +1 -1
  135. package/out/concepts/QueryFieldExpression__.js +1 -1
  136. package/out/concepts/QueryFieldExpression__.js.map +1 -1
  137. package/out/concepts/QueryFromExpression__.js +1 -1
  138. package/out/concepts/QueryFromExpression__.js.map +1 -1
  139. package/out/concepts/QueryJoinExpression__.js +1 -1
  140. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  141. package/out/concepts/QueryLimitExpression__.js +1 -1
  142. package/out/concepts/QueryLimitExpression__.js.map +1 -1
  143. package/out/concepts/QueryOrderByExpression__.js +1 -1
  144. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  145. package/out/concepts/Return__.js +2 -2
  146. package/out/concepts/Return__.js.map +1 -1
  147. package/out/concepts/Role__.js +1 -1
  148. package/out/concepts/Role__.js.map +1 -1
  149. package/out/concepts/SelectMembers__.js +1 -1
  150. package/out/concepts/SelectMembers__.js.map +1 -1
  151. package/out/concepts/SqlQueryComponent__.js +2 -2
  152. package/out/concepts/SqlQueryComponent__.js.map +1 -1
  153. package/out/concepts/Start__.js +1 -1
  154. package/out/concepts/Start__.js.map +1 -1
  155. package/out/concepts/StringInterpolation__.js +2 -2
  156. package/out/concepts/StringInterpolation__.js.map +1 -1
  157. package/out/concepts/StringLiteral__.js +1 -1
  158. package/out/concepts/StringLiteral__.js.map +1 -1
  159. package/out/concepts/StructureProperty__.js +2 -2
  160. package/out/concepts/StructureProperty__.js.map +1 -1
  161. package/out/concepts/Structure__.js +2 -2
  162. package/out/concepts/Structure__.js.map +1 -1
  163. package/out/concepts/SwitchCase__.js +1 -1
  164. package/out/concepts/SwitchCase__.js.map +1 -1
  165. package/out/concepts/SwitchStatement__.js +2 -2
  166. package/out/concepts/SwitchStatement__.js.map +1 -1
  167. package/out/concepts/TriggerLauncher__.js +1 -1
  168. package/out/concepts/TriggerLauncher__.js.map +1 -1
  169. package/out/concepts/TypeAnnotation__.d.ts +4 -3
  170. package/out/concepts/TypeAnnotation__.js +116 -75
  171. package/out/concepts/TypeAnnotation__.js.map +1 -1
  172. package/out/concepts/TypeParam__.js +1 -1
  173. package/out/concepts/TypeParam__.js.map +1 -1
  174. package/out/concepts/UnaryExpression__.js +2 -2
  175. package/out/concepts/UnaryExpression__.js.map +1 -1
  176. package/out/concepts/ValidationRule__.d.ts +14 -14
  177. package/out/concepts/ValidationRule__.js +28 -24
  178. package/out/concepts/ValidationRule__.js.map +1 -1
  179. package/out/concepts/Variable__.js +2 -2
  180. package/out/concepts/Variable__.js.map +1 -1
  181. package/out/concepts/ViewElement__.d.ts +88 -87
  182. package/out/concepts/ViewElement__.js +268 -204
  183. package/out/concepts/ViewElement__.js.map +1 -1
  184. package/out/concepts/View__.d.ts +6 -0
  185. package/out/concepts/View__.js +254 -11
  186. package/out/concepts/View__.js.map +1 -1
  187. package/out/concepts/WhileStatement__.js +2 -2
  188. package/out/concepts/WhileStatement__.js.map +1 -1
  189. package/out/concepts/basics/stdlib/nasl.browser.js +1 -0
  190. package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
  191. package/out/concepts/basics/stdlib/nasl.event.js +2 -0
  192. package/out/concepts/basics/stdlib/nasl.event.js.map +1 -1
  193. package/out/generator/genBundleFiles.js +90 -1
  194. package/out/generator/genBundleFiles.js.map +1 -1
  195. package/out/generator/genReleaseBody.js +1 -1
  196. package/out/generator/genReleaseBody.js.map +1 -1
  197. package/out/generator/permission.js +3 -3
  198. package/out/generator/permission.js.map +1 -1
  199. package/out/index.d.ts +1 -0
  200. package/out/index.js +1 -0
  201. package/out/index.js.map +1 -1
  202. package/out/natural/genNaturalTS.js +7 -3
  203. package/out/natural/genNaturalTS.js.map +1 -1
  204. package/out/natural/knowledgeMap.js +12 -12
  205. package/out/natural/knowledgeMap.js.map +1 -1
  206. package/out/natural/transformTSCode.d.ts +1 -1
  207. package/out/natural/transformTSCode.js +115 -141
  208. package/out/natural/transformTSCode.js.map +1 -1
  209. package/out/server/extendBaseNode.js +69 -44
  210. package/out/server/extendBaseNode.js.map +1 -1
  211. package/out/server/formatTsUtils.js +72 -63
  212. package/out/server/formatTsUtils.js.map +1 -1
  213. package/out/server/getLogics.js +20 -23
  214. package/out/server/getLogics.js.map +1 -1
  215. package/out/server/getMemberIdentifier.d.ts +1 -0
  216. package/out/server/getMemberIdentifier.js +149 -1
  217. package/out/server/getMemberIdentifier.js.map +1 -1
  218. package/out/server/naslServer.d.ts +3 -3
  219. package/out/server/naslServer.js +182 -132
  220. package/out/server/naslServer.js.map +1 -1
  221. package/out/server/translator.js +43 -33
  222. package/out/server/translator.js.map +1 -1
  223. package/out/service/defaultErrorMessage.json +6 -6
  224. package/out/service/storage/init.js +16 -0
  225. package/out/service/storage/init.js.map +1 -1
  226. package/out/templator/genCreateBlock.js +5 -3
  227. package/out/templator/genCreateBlock.js.map +1 -1
  228. package/out/templator/genCurdEditMultipleKeyBlock.js +12 -8
  229. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  230. package/out/templator/genCurdMultipleKeyBlock.js +8 -7
  231. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  232. package/out/templator/genEditTableBlock.d.ts +1 -1
  233. package/out/templator/genEditTableBlock.js +12 -6
  234. package/out/templator/genEditTableBlock.js.map +1 -1
  235. package/out/templator/genEnumSelectBlock.js +2 -2
  236. package/out/templator/genEnumSelectBlock.js.map +1 -1
  237. package/out/templator/genGetBlock.js +1 -1
  238. package/out/templator/genGetBlock.js.map +1 -1
  239. package/out/templator/genGridViewBlock.d.ts +2 -2
  240. package/out/templator/genGridViewBlock.js +20 -7
  241. package/out/templator/genGridViewBlock.js.map +1 -1
  242. package/out/templator/genListViewBlock.d.ts +2 -2
  243. package/out/templator/genListViewBlock.js +13 -5
  244. package/out/templator/genListViewBlock.js.map +1 -1
  245. package/out/templator/genSelectBlock.d.ts +2 -2
  246. package/out/templator/genSelectBlock.js +8 -6
  247. package/out/templator/genSelectBlock.js.map +1 -1
  248. package/out/templator/genTableBlock.d.ts +1 -1
  249. package/out/templator/genTableBlock.js +10 -5
  250. package/out/templator/genTableBlock.js.map +1 -1
  251. package/out/templator/genUpdateBlock.js +5 -3
  252. package/out/templator/genUpdateBlock.js.map +1 -1
  253. package/package.json +3 -1
  254. package/sandbox/stdlib/nasl.auth.ts +40 -44
  255. package/sandbox/stdlib/nasl.core.ts +8 -1
  256. package/sandbox/stdlib/nasl.http.ts +22 -22
  257. package/sandbox-natural/stdlib/nasl.util.ts +74 -15
  258. package/src/automate/upgrader/2.20.js +17 -13
  259. package/src/bak/translator.js +50 -1
  260. package/src/breakpoint/shared/utils.ts +0 -2
  261. package/src/common/Command.ts +8 -0
  262. package/src/concepts/Abort__.ts +2 -2
  263. package/src/concepts/Anchor__.ts +2 -2
  264. package/src/concepts/AnonymousFunction__.ts +3 -3
  265. package/src/concepts/Argument__.ts +2 -2
  266. package/src/concepts/Assignee__.ts +1 -1
  267. package/src/concepts/AssignmentLine__.ts +2 -2
  268. package/src/concepts/Assignment__.ts +3 -3
  269. package/src/concepts/BackendVariable__.ts +2 -2
  270. package/src/concepts/Backend__.ts +1 -1
  271. package/src/concepts/BatchAssignment__.ts +3 -3
  272. package/src/concepts/BinaryExpression__.ts +3 -3
  273. package/src/concepts/BindAttribute__.ts +69 -4
  274. package/src/concepts/BindDirective__.ts +2 -2
  275. package/src/concepts/BindEvent__.ts +44 -64
  276. package/src/concepts/BindStyle__.ts +2 -2
  277. package/src/concepts/BooleanLiteral__.ts +2 -2
  278. package/src/concepts/CallAuthInterface__.ts +2 -2
  279. package/src/concepts/CallConnector__.ts +2 -2
  280. package/src/concepts/CallFunction__.ts +3 -3
  281. package/src/concepts/CallInterface__.ts +3 -3
  282. package/src/concepts/CallLogic__.ts +69 -13
  283. package/src/concepts/CallQueryComponent__.ts +2 -2
  284. package/src/concepts/Comment__.ts +2 -2
  285. package/src/concepts/ConfigProperty__.ts +2 -2
  286. package/src/concepts/Connection__.ts +15 -21
  287. package/src/concepts/Constant__.ts +2 -2
  288. package/src/concepts/DataSource__.ts +1 -1
  289. package/src/concepts/Destination__.ts +3 -3
  290. package/src/concepts/End__.ts +2 -2
  291. package/src/concepts/EntityIndex__.ts +2 -2
  292. package/src/concepts/EntityProperty__.ts +3 -3
  293. package/src/concepts/Entity__.ts +2 -2
  294. package/src/concepts/EnumItem__.ts +3 -3
  295. package/src/concepts/Enum__.ts +2 -2
  296. package/src/concepts/ForEachStatement__.ts +35 -46
  297. package/src/concepts/Frontend__.ts +1 -1
  298. package/src/concepts/Function__.ts +3 -3
  299. package/src/concepts/Identifier__.ts +2 -2
  300. package/src/concepts/IfStatement__.ts +3 -3
  301. package/src/concepts/Interface__.ts +1 -1
  302. package/src/concepts/JSBlock__.ts +2 -2
  303. package/src/concepts/JavaLogic__.ts +2 -2
  304. package/src/concepts/LogicItem__.ts +3 -3
  305. package/src/concepts/Logic__.ts +2 -1
  306. package/src/concepts/MatchCase__.ts +2 -2
  307. package/src/concepts/Match__.ts +3 -3
  308. package/src/concepts/MemberExpression__.ts +112 -4
  309. package/src/concepts/Module__.ts +41 -58
  310. package/src/concepts/NewComposite__.ts +3 -3
  311. package/src/concepts/NewList__.ts +3 -3
  312. package/src/concepts/NewMap__.ts +3 -3
  313. package/src/concepts/New__.ts +2 -2
  314. package/src/concepts/NullLiteral__.ts +2 -2
  315. package/src/concepts/NumericLiteral__.ts +2 -2
  316. package/src/concepts/OqlQueryComponent__.ts +3 -3
  317. package/src/concepts/Param__.ts +2 -2
  318. package/src/concepts/ProcessElement__.ts +2 -2
  319. package/src/concepts/ProcessOutcome__.ts +2 -2
  320. package/src/concepts/ProcessOutcomes__.ts +2 -2
  321. package/src/concepts/Process__.ts +1 -1
  322. package/src/concepts/QueryAggregateExpression__.ts +2 -2
  323. package/src/concepts/QueryFieldExpression__.ts +2 -2
  324. package/src/concepts/QueryFromExpression__.ts +2 -2
  325. package/src/concepts/QueryJoinExpression__.ts +2 -2
  326. package/src/concepts/QueryLimitExpression__.ts +2 -2
  327. package/src/concepts/QueryOrderByExpression__.ts +2 -2
  328. package/src/concepts/Return__.ts +3 -3
  329. package/src/concepts/Role__.ts +1 -1
  330. package/src/concepts/SelectMembers__.ts +2 -2
  331. package/src/concepts/SqlQueryComponent__.ts +3 -3
  332. package/src/concepts/Start__.ts +2 -2
  333. package/src/concepts/StringInterpolation__.ts +3 -3
  334. package/src/concepts/StringLiteral__.ts +2 -2
  335. package/src/concepts/StructureProperty__.ts +3 -3
  336. package/src/concepts/Structure__.ts +2 -2
  337. package/src/concepts/SwitchCase__.ts +2 -2
  338. package/src/concepts/SwitchStatement__.ts +3 -3
  339. package/src/concepts/TriggerLauncher__.ts +1 -1
  340. package/src/concepts/TypeAnnotation__.ts +145 -125
  341. package/src/concepts/TypeParam__.ts +2 -2
  342. package/src/concepts/UnaryExpression__.ts +3 -3
  343. package/src/concepts/ValidationRule__.ts +554 -524
  344. package/src/concepts/Variable__.ts +3 -3
  345. package/src/concepts/ViewElement__.ts +2445 -2498
  346. package/src/concepts/View__.ts +258 -10
  347. package/src/concepts/WhileStatement__.ts +3 -3
  348. package/src/concepts/basics/stdlib/nasl.browser.ts +1 -0
  349. package/src/concepts/basics/stdlib/nasl.event.ts +2 -0
  350. package/src/generator/genBundleFiles.ts +91 -1
  351. package/src/generator/genReleaseBody.ts +1 -1
  352. package/src/generator/permission.ts +3 -3
  353. package/src/index.ts +1 -0
  354. package/src/natural/genNaturalTS.ts +8 -4
  355. package/src/natural/knowledgeMap.ts +12 -12
  356. package/src/natural/transformTSCode.ts +139 -151
  357. package/src/server/extendBaseNode.ts +71 -45
  358. package/src/server/formatTsUtils.ts +64 -64
  359. package/src/server/getLogics.ts +23 -30
  360. package/src/server/getMemberIdentifier.ts +143 -0
  361. package/src/server/naslServer.ts +174 -148
  362. package/src/server/translator.ts +40 -39
  363. package/src/service/defaultErrorMessage.json +6 -6
  364. package/src/service/storage/init.ts +17 -0
  365. package/src/templator/genCreateBlock.ts +5 -3
  366. package/src/templator/genCurdEditMultipleKeyBlock.ts +12 -8
  367. package/src/templator/genCurdMultipleKeyBlock.ts +8 -7
  368. package/src/templator/genEditTableBlock.ts +12 -7
  369. package/src/templator/genEnumSelectBlock.ts +2 -2
  370. package/src/templator/genGetBlock.ts +6 -6
  371. package/src/templator/genGridViewBlock.ts +22 -9
  372. package/src/templator/genListViewBlock.ts +14 -5
  373. package/src/templator/genSelectBlock.ts +8 -6
  374. package/src/templator/genTableBlock.ts +10 -9
  375. package/src/templator/genUpdateBlock.ts +5 -3
  376. package/test/concepts/validation-rule/__snapshots__/toEmbeddedTS.spec.ts.snap +11 -0
  377. package/test/concepts/validation-rule/__snapshots__/toJS.spec.ts.snap +10 -0
  378. package/test/concepts/validation-rule/fixtures/argument-without-keyword.json +34 -0
  379. package/test/concepts/validation-rule/fixtures/empty-rule.json +9 -0
  380. package/test/concepts/validation-rule/validation-rule.spec.ts +15 -0
@@ -1,15 +1,15 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
- import { TranslatorState, shiftState, withSourceMap, indent } from '../translator';
2
+ import { TranslatorState, shiftState, withSourceMap, indent, createCompilerState } from '../translator';
3
3
  import Function from './Function__';
4
4
  import { ElementToVueOptions } from './ViewElement__';
5
5
  import { getValidationInFunction } from '../server/getFunctions';
6
- import defaultErrorMessage from '../service/defaultErrorMessage.json';
6
+ import defaultErrorMessage = require('../service/defaultErrorMessage.json');
7
7
  import BindAttribute from './BindAttribute__';
8
8
 
9
- //= ===============================================================================
9
+ //================================================================================
10
10
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
11
11
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
12
- //= ===============================================================================
12
+ //================================================================================
13
13
  import { EventPayload, Params } from '../common/EventEmitter';
14
14
  import { concept, excludedInJSON, property } from '../decorators';
15
15
 
@@ -24,548 +24,578 @@ import LogicItem from './LogicItem__';
24
24
  */
25
25
  @concept('验证规则')
26
26
  export class ValidationRule extends LogicItem {
27
- /**
28
- * 产品概念
29
- */
30
- @property()
31
- concept: 'ValidationRule' = 'ValidationRule';
32
-
33
- /**
34
- * 验证规则标题
35
- */
36
- @property()
37
- label: string = '验证规则';
38
-
39
- /**
40
- * calleeNamespace
41
- */
42
- @property()
43
- calleeNamespace: string = undefined;
44
-
45
- /**
46
- * calleeName
47
- */
48
- @property()
49
- calleeName: string = undefined;
50
-
51
- /**
52
- * 实际参数
53
- */
54
- @property('Argument')
55
- arguments: Array<Argument> = [];
56
-
57
- /**
58
- * 错误信息
59
- */
60
- @property('LogicItem')
61
- errorMessage: LogicItem = undefined;
62
-
63
- /**
64
- * 验证对象
65
- */
66
- @property('LogicItem')
67
- target: LogicItem = undefined;
68
-
69
- /**
70
- * 是否启用服务端验证
71
- */
72
- @property()
73
- enableServerValidation: boolean = true;
74
-
75
- /**
76
- * @param source 需要合并的部分参数
77
- */
78
- constructor(source?: Partial<ValidationRule>) {
79
- // @ts-ignore
80
- // @ts-ignore
81
- source = { ...ValidationRule.getDefaultOptions(), ...source };
82
- super(source);
83
- super.subConstructor(source);
84
- }
85
-
86
- getClassName() {
87
- return 'ValidationRule';
88
- }
89
-
90
- static from(source: any, parentNode?: any, parentKey?: string): ValidationRule {
91
- return super.from(source, parentNode, parentKey) as ValidationRule;
92
- }
93
-
94
- /**
95
- * 设置错误信息
96
- */
97
- setErrorMessage(errorMessage: LogicItem) {
98
- errorMessage._delete();
99
- const relationOptions = { parentNode: this, parentKey: 'errorMessage' };
100
- Object.assign(errorMessage, relationOptions);
101
- const object = {
102
- errorMessage,
103
- };
104
- this.update({
105
- ...object,
106
- });
107
- }
108
-
109
- /**
110
- * 设置验证对象
111
- */
112
- setTarget(target: LogicItem) {
113
- target._delete();
114
- const relationOptions = { parentNode: this, parentKey: 'target' };
115
- Object.assign(target, relationOptions);
116
- const object = {
117
- target,
118
- };
119
- this.update({
120
- ...object,
121
- });
122
- }
123
-
124
- /**
125
- * 设置是否启用服务端验证
126
- */
127
- setEnableServerValidation(enableServerValidation: boolean) {
128
- const object = {
129
- enableServerValidation,
130
- };
131
- this.update({
132
- ...object,
133
- });
134
- }
135
-
136
- /**
137
- * 插入实际参数
138
- * @internal
139
- * @param argumentOptions 实际参数参数
140
- */
141
- _insertArgumentAt(argumentOptions: Partial<Argument>, index: number): Argument;
142
-
143
- /**
144
- * 插入实际参数
145
- * @internal
146
- * @param argument 已有的实际参数实例
147
- */
148
- _insertArgumentAt(argument: Argument, index: number): Argument;
149
-
150
- _insertArgumentAt(options: Partial<Argument> | Argument, index: number) {
151
- const argumentOptions: any = {};
152
- const relationOptions = { parentNode: this, parentKey: 'arguments' };
153
- let argument: Argument;
154
- if (options instanceof Argument) {
155
- options.ensureDelete(); // 同一实例不支持多处存在
156
- argument = options;
157
- Object.assign(argument, relationOptions);
158
- } else {
159
- argument = Argument.from(
160
- {
161
- ...argumentOptions,
162
- ...options,
163
- },
164
- this,
165
- 'arguments'
166
- );
27
+ /**
28
+ * 产品概念
29
+ */
30
+ @property()
31
+ concept: 'ValidationRule' = 'ValidationRule';
32
+
33
+ /**
34
+ * 验证规则标题
35
+ */
36
+ @property()
37
+ label: string = '验证规则';
38
+
39
+ /**
40
+ * calleeNamespace
41
+ */
42
+ @property()
43
+ calleeNamespace: string = undefined;
44
+
45
+ /**
46
+ * calleeName
47
+ */
48
+ @property()
49
+ calleeName: string = undefined;
50
+
51
+ /**
52
+ * 实际参数
53
+ */
54
+ @property('Argument')
55
+ arguments: Array<Argument> = [];
56
+
57
+ /**
58
+ * 错误信息
59
+ */
60
+ @property('LogicItem')
61
+ errorMessage: LogicItem = undefined;
62
+
63
+ /**
64
+ * 验证对象
65
+ */
66
+ @property('LogicItem')
67
+ target: LogicItem = undefined;
68
+
69
+ /**
70
+ * 是否启用服务端验证
71
+ */
72
+ @property()
73
+ enableServerValidation: boolean = true;
74
+
75
+
76
+
77
+ /**
78
+ * @param source 需要合并的部分参数
79
+ */
80
+ constructor(source?: Partial<ValidationRule>) {
81
+ source = Object.assign({}, ValidationRule.getDefaultOptions(), source);
82
+ super(source);
83
+ super.subConstructor(source);
167
84
  }
168
- this.arguments.splice(index, 0, argument);
169
- return argument;
170
- }
171
-
172
- /**
173
- * 插入实际参数
174
- * @param argumentOptions 实际参数参数
175
- */
176
- insertArgumentAt(argumentOptions: Partial<Argument>, index: number): Argument;
177
-
178
- /**
179
- * 插入实际参数
180
- * @param argument 已有的实际参数实例
181
- */
182
- insertArgumentAt(argument: Argument, index: number): Argument;
183
-
184
- insertArgumentAt(options: Partial<Argument> | Argument, index: number) {
185
- const node = this._insertArgumentAt(options as any, index);
186
- node.create({
187
- index,
188
- parentNode: this,
189
- parentKey: 'arguments',
190
- });
191
- return node;
192
- }
193
-
194
- /**
195
- * 添加实际参数
196
- * @internal
197
- * @param argumentOptions 实际参数参数
198
- */
199
- _addArgument(argumentOptions: Partial<Argument>): Argument;
200
-
201
- /**
202
- * 添加实际参数
203
- * @internal
204
- * @param argument 已有的实际参数实例
205
- */
206
- _addArgument(argument: Argument): Argument;
207
-
208
- _addArgument(options?: Partial<Argument> | Argument) {
209
- const index = this.arguments.length;
210
- return this._insertArgumentAt(options as any, index);
211
- }
212
-
213
- /**
214
- * 添加实际参数
215
- * @param argumentOptions 实际参数参数
216
- */
217
- addArgument(argumentOptions: Partial<Argument>): Argument;
218
-
219
- /**
220
- * 添加实际参数
221
- * @param argument 已有的实际参数实例
222
- */
223
- addArgument(argument: Argument): Argument;
224
-
225
- addArgument(options?: Partial<Argument> | Argument) {
226
- const node = this._addArgument(options as any);
227
- const index = this.arguments.indexOf(node);
228
- node.create({
229
- index,
230
- parentNode: this,
231
- parentKey: 'arguments',
232
- });
233
- return node;
234
- }
235
-
236
- /**
237
- * 删除实际参数
238
- * @param argument 已有的实际参数实例
239
- */
240
- removeArgumentInArguments(argument: Argument): void;
241
-
242
- removeArgumentInArguments(options: Argument) {
243
- const argument: Argument = options;
244
- return argument.delete();
245
- }
246
-
247
- /**
248
- * 删除逻辑项
249
- * @param name 逻辑项名称
250
- */
251
- removeErrorMessage(name: string): void;
252
-
253
- /**
254
- * 删除逻辑项
255
- * @param errorMessage 已有的逻辑项实例
256
- */
257
- removeErrorMessage(errorMessage: LogicItem): void;
258
-
259
- removeErrorMessage(options: string | LogicItem) {
260
- let errorMessage: LogicItem;
261
- if (typeof options === 'string') {
262
- errorMessage = this.errorMessage;
263
- if (!errorMessage) {
264
- throw new Error(`找不到逻辑项 ${options}`);
265
- }
266
- } else {
267
- errorMessage = options;
85
+ getClassName() {
86
+ return 'ValidationRule';
268
87
  }
269
- return errorMessage.delete();
270
- }
271
-
272
- /**
273
- * 删除逻辑项
274
- * @param name 逻辑项名称
275
- */
276
- removeTarget(name: string): void;
277
-
278
- /**
279
- * 删除逻辑项
280
- * @param target 已有的逻辑项实例
281
- */
282
- removeTarget(target: LogicItem): void;
283
-
284
- removeTarget(options: string | LogicItem) {
285
- let target: LogicItem;
286
- if (typeof options === 'string') {
287
- target = this.target;
288
- if (!target) {
289
- throw new Error(`找不到逻辑项 ${options}`);
290
- }
291
- } else {
292
- target = options;
88
+
89
+ static from(source: any, parentNode?: any, parentKey?: string): ValidationRule {
90
+ return super.from(source, parentNode, parentKey) as ValidationRule;
293
91
  }
294
- return target.delete();
295
- }
296
-
297
- __removeLogicItem(logicItem: LogicItem) {
298
- const { parentKey } = logicItem;
299
- const params: Params = {
300
- parentNode: this,
301
- parentKey,
302
- index: -1,
303
- object: null,
304
- oldObject: logicItem,
305
- };
306
- if (parentKey) {
307
- params.parentKey = parentKey;
308
- if (Array.isArray((this as any)[parentKey])) {
309
- const index = (this as any)[parentKey].indexOf(logicItem);
310
- ~index && (this as any)[parentKey].splice(index, 1);
311
- params.index = index;
312
- } else if ((this as any)[parentKey] === logicItem) {
313
- params.index = 0;
314
- (this as any)[parentKey] = undefined;
315
- }
92
+
93
+
94
+ /**
95
+ * 设置错误信息
96
+ */
97
+ setErrorMessage(errorMessage: LogicItem) {
98
+ errorMessage._delete();
99
+ const relationOptions = { parentNode: this, parentKey: 'errorMessage' };
100
+ Object.assign(errorMessage, relationOptions);
101
+ const object = {
102
+ errorMessage,
103
+ };
104
+ this.update({
105
+ ...object,
106
+ });
316
107
  }
317
- return params;
318
- }
319
-
320
- //= ===============================================================================
321
- // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
322
- // 自动生成的代码已结束。下面可以手动编写。
323
- //= ===============================================================================
324
-
325
- public static getDefaultOptions() {
326
- return {
327
- target: {
328
- concept: 'Identifier',
329
- name: '',
330
- },
331
- };
332
- }
333
-
334
- toInViewMethod() {
335
- let code = '{';
336
- // 兼容就得简写模式
337
- if (this.calleeName && this.calleeName.includes('(')) {
338
- return `'${this.calleeName}'`;
108
+
109
+ /**
110
+ * 设置验证对象
111
+ */
112
+ setTarget(target: LogicItem) {
113
+ target._delete();
114
+ const relationOptions = { parentNode: this, parentKey: 'target' };
115
+ Object.assign(target, relationOptions);
116
+ const object = {
117
+ target,
118
+ };
119
+ this.update({
120
+ ...object,
121
+ });
339
122
  }
340
- if (this.calleeName === 'unique') {
341
- code += `validate: 'excluded',`;
342
- } else if (this.calleeName === 'confirmed') {
343
- code += `validate: 'is',`;
344
- } else {
345
- code += `validate: '${this.calleeName}',`;
123
+
124
+ /**
125
+ * 设置是否启用服务端验证
126
+ */
127
+ setEnableServerValidation(enableServerValidation: boolean) {
128
+ const object = {
129
+ enableServerValidation,
130
+ };
131
+ this.update({
132
+ ...object,
133
+ });
346
134
  }
347
- if (this.arguments.length) {
348
- let args = '[';
349
- this.arguments?.forEach((arg, index) => {
350
- args += arg?.toJS();
351
- if (index !== this.arguments?.length - 1) args += ', ';
352
- });
353
- args += ']';
354
- code += `args: ${args} ,`;
135
+
136
+
137
+
138
+
139
+
140
+ /**
141
+ * 插入实际参数
142
+ * @internal
143
+ * @param argumentOptions 实际参数参数
144
+ */
145
+ _insertArgumentAt(argumentOptions: Partial<Argument>, index: number): Argument;
146
+
147
+ /**
148
+ * 插入实际参数
149
+ * @internal
150
+ * @param argument 已有的实际参数实例
151
+ */
152
+ _insertArgumentAt(argument: Argument, index: number): Argument;
153
+
154
+ _insertArgumentAt(options: Partial<Argument> | Argument, index: number) {
155
+ const argumentOptions: any = {};
156
+ const relationOptions = { parentNode: this, parentKey: 'arguments' };
157
+ let argument: Argument;
158
+ if (options instanceof Argument) {
159
+ options.ensureDelete(); // 同一实例不支持多处存在
160
+ argument = options;
161
+ Object.assign(argument, relationOptions);
162
+ } else {
163
+ argument = Argument.from({
164
+ ...argumentOptions,
165
+ ...options,
166
+ }, this, 'arguments');
167
+ }
168
+ this.arguments.splice(index, 0, argument);
169
+ return argument;
355
170
  }
356
- if (this.errorMessage) {
357
- code += `message: ${this.errorMessage?.toJS()},`;
358
- } else {
359
- let defaultError = (defaultErrorMessage as Record<string, string>)[this.calleeName];
360
- let index = 0;
361
- while (defaultError && defaultError.indexOf(`{args}`) !== -1) {
362
- defaultError = defaultError.replace(`{args}`, `\${${this.arguments[index]?.toJS()}}`);
363
- index++;
364
- }
365
- const itemTitle = (this?.parentNode as any)?.parentNode?.bindAttrs?.find((item: BindAttribute) => item.name === 'label');
366
- let labelName;
367
- if (itemTitle?.expression?.toJS()) {
368
- labelName = `\${${itemTitle?.expression?.toJS()}}`;
369
- } else {
370
- labelName = itemTitle?.value || '表单项';
371
- }
372
- defaultError = defaultError && defaultError.replace(`{label}`, labelName);
373
- code += `message: \`${defaultError}\`,`;
171
+
172
+
173
+
174
+ /**
175
+ * 插入实际参数
176
+ * @param argumentOptions 实际参数参数
177
+ */
178
+ insertArgumentAt(argumentOptions: Partial<Argument>, index: number): Argument;
179
+
180
+ /**
181
+ * 插入实际参数
182
+ * @param argument 已有的实际参数实例
183
+ */
184
+ insertArgumentAt(argument: Argument, index: number): Argument;
185
+
186
+ insertArgumentAt(options: Partial<Argument> | Argument, index: number) {
187
+ const node = this._insertArgumentAt(options as any, index);
188
+ node.create({
189
+ index,
190
+ parentNode: this,
191
+ parentKey: 'arguments',
192
+ });
193
+ return node;
374
194
  }
375
- code += `trigger: 'input+blur'`;
376
- if (['required', 'filled', 'notEmpty'].includes(this.calleeName)) {
377
- code += ',required: true';
195
+
196
+
197
+
198
+ /**
199
+ * 添加实际参数
200
+ * @internal
201
+ * @param argumentOptions 实际参数参数
202
+ */
203
+ _addArgument(argumentOptions: Partial<Argument>): Argument;
204
+
205
+ /**
206
+ * 添加实际参数
207
+ * @internal
208
+ * @param argument 已有的实际参数实例
209
+ */
210
+ _addArgument(argument: Argument): Argument;
211
+
212
+ _addArgument(options?: Partial<Argument> | Argument) {
213
+ const index = this.arguments.length;
214
+ return this._insertArgumentAt(options as any, index);
378
215
  }
379
- code += '}';
380
- return code;
381
- }
382
-
383
- toVue(options?: ElementToVueOptions) {
384
- let code = '{';
385
- // 兼容就得简写模式
386
- if (this.calleeName && this.calleeName.includes('(')) {
387
- return `'${this.calleeName}'`;
216
+
217
+
218
+
219
+ /**
220
+ * 添加实际参数
221
+ * @param argumentOptions 实际参数参数
222
+ */
223
+ addArgument(argumentOptions: Partial<Argument>): Argument;
224
+
225
+ /**
226
+ * 添加实际参数
227
+ * @param argument 已有的实际参数实例
228
+ */
229
+ addArgument(argument: Argument): Argument;
230
+
231
+ addArgument(options?: Partial<Argument> | Argument) {
232
+ const node = this._addArgument(options as any);
233
+ const index = this.arguments.indexOf(node);
234
+ node.create({
235
+ index,
236
+ parentNode: this,
237
+ parentKey: 'arguments',
238
+ });
239
+ return node;
388
240
  }
389
- if (this.calleeName === 'unique') {
390
- code += `validate: 'excluded',`;
391
- } else if (this.calleeName === 'confirmed') {
392
- code += `validate: 'is',`;
393
- } else {
394
- code += `validate: '${this.calleeName}',`;
241
+
242
+
243
+
244
+
245
+ /**
246
+ * 删除实际参数
247
+ * @param argument 已有的实际参数实例
248
+ */
249
+ removeArgumentInArguments(argument: Argument): void;
250
+
251
+ removeArgumentInArguments(options: Argument) {
252
+ let argument: Argument = options;
253
+ return argument.delete();
395
254
  }
396
- if (this.arguments.length) {
397
- let args = '[';
398
- this.arguments?.forEach((arg, index) => {
399
- args += arg?.toVue(options);
400
- if (index !== this.arguments?.length - 1) args += ', ';
401
- });
402
- args += ']';
403
- code += `args: ${args} ,`;
255
+
256
+
257
+
258
+ /**
259
+ * 删除逻辑项
260
+ * @param name 逻辑项名称
261
+ */
262
+ removeErrorMessage(name: string): void;
263
+
264
+ /**
265
+ * 删除逻辑项
266
+ * @param errorMessage 已有的逻辑项实例
267
+ */
268
+ removeErrorMessage(errorMessage: LogicItem): void;
269
+
270
+ removeErrorMessage(options: string | LogicItem) {
271
+ let errorMessage: LogicItem;
272
+ if (typeof options === 'string') {
273
+ errorMessage = this.errorMessage;
274
+ if (!errorMessage) {
275
+ throw new Error('找不到逻辑项 ' + options);
276
+ }
277
+ } else {
278
+ errorMessage = options;
279
+ }
280
+ return errorMessage.delete();
404
281
  }
405
- if (this.errorMessage) {
406
- code += `message: ${this.errorMessage?.toVue(options)},`;
407
- } else {
408
- let defaultError = (defaultErrorMessage as Record<string, string>)[this.calleeName];
409
- let index = 0;
410
- while (defaultError && defaultError.indexOf(`{args}`) !== -1) {
411
- defaultError = defaultError.replace(`{args}`, `\${${this.arguments[index]?.toVue(options)}}`);
412
- index++;
413
- }
414
- const itemTitle = (this?.parentNode as any)?.parentNode?.bindAttrs?.find((item: BindAttribute) => item.name === 'label');
415
- let labelName;
416
- if (itemTitle?.expression?.toVue()) {
417
- labelName = `\${${itemTitle?.expression?.toVue()}}`;
418
- } else {
419
- labelName = itemTitle?.value || '表单项';
420
- }
421
- defaultError = defaultError && defaultError.replace(`{label}`, labelName);
422
- code += `message: \`${defaultError}\`,`;
282
+
283
+
284
+
285
+ /**
286
+ * 删除逻辑项
287
+ * @param name 逻辑项名称
288
+ */
289
+ removeTarget(name: string): void;
290
+
291
+ /**
292
+ * 删除逻辑项
293
+ * @param target 已有的逻辑项实例
294
+ */
295
+ removeTarget(target: LogicItem): void;
296
+
297
+ removeTarget(options: string | LogicItem) {
298
+ let target: LogicItem;
299
+ if (typeof options === 'string') {
300
+ target = this.target;
301
+ if (!target) {
302
+ throw new Error('找不到逻辑项 ' + options);
303
+ }
304
+ } else {
305
+ target = options;
306
+ }
307
+ return target.delete();
423
308
  }
424
- code += `trigger: 'input+blur'`;
425
- if (['required', 'filled', 'notEmpty'].includes(this.calleeName)) {
426
- code += ',required: true';
309
+
310
+ __removeLogicItem(logicItem: LogicItem) {
311
+ const parentKey = logicItem.parentKey;
312
+ const params: Params = {
313
+ parentNode: this,
314
+ parentKey,
315
+ index: -1,
316
+ object: null,
317
+ oldObject: logicItem,
318
+ };
319
+ if (parentKey) {
320
+ params.parentKey = parentKey;
321
+ if (Array.isArray((this as any)[parentKey])) {
322
+ const index = (this as any)[parentKey].indexOf(logicItem);
323
+ ~index && (this as any)[parentKey].splice(index, 1);
324
+ params.index = index;
325
+ } else if ((this as any)[parentKey] === logicItem) {
326
+ params.index = 0;
327
+ (this as any)[parentKey] = undefined;
328
+ }
329
+ }
330
+ return params;
427
331
  }
428
- code += '}';
429
- return code;
430
- }
431
-
432
- toUI(state?: TranslatorState): string {
433
- let code = this.calleeName;
434
- if (this.arguments?.length) {
435
- code += '(';
436
- this.arguments?.forEach((arg, index) => {
437
- code += arg?.toUI(shiftState(state, code));
438
- if (index !== this.arguments?.length - 1) code += ', ';
439
- });
440
- code += ')';
332
+
333
+ //================================================================================
334
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
335
+ // 自动生成的代码已结束。下面可以手动编写。
336
+ //================================================================================
337
+
338
+ public static getDefaultOptions() {
339
+ return {
340
+ target: {
341
+ concept: 'Identifier',
342
+ name: '',
343
+ },
344
+ };
441
345
  }
442
- return code;
443
- }
444
-
445
- toJS(state?: TranslatorState): string {
446
- let code = '{';
447
- code += `validate: '${this.calleeName}',`;
448
- if (this.arguments.length) {
449
- let args = '[';
450
- this.arguments?.forEach((arg, index) => {
451
- args += arg?.toJS(shiftState(state, code));
452
- if (index !== this.arguments?.length - 1) args += ', ';
453
- });
454
- args += ']';
455
- code += `args: ${args},`;
346
+
347
+ toInViewMethod() {
348
+ let code = '{';
349
+ // 兼容就得简写模式
350
+ if (this.calleeName && this.calleeName.includes('(')) {
351
+ return `'${this.calleeName}'`;
352
+ } else if (this.calleeName === 'unique') {
353
+ code += `validate: 'excluded',`;
354
+ } else if (this.calleeName === 'confirmed') {
355
+ code += `validate: 'is',`;
356
+ } else {
357
+ code += `validate: '${this.calleeName}',`;
358
+ }
359
+ if (this.arguments.length) {
360
+ let args = '[';
361
+ this.arguments?.forEach((arg, index) => {
362
+ args += arg?.toJS();
363
+ if (index !== this.arguments?.length - 1)
364
+ args += ', ';
365
+ });
366
+ args += ']';
367
+ code += `args: ${args} ,`;
368
+ }
369
+ if (this.errorMessage) {
370
+ code += `message: ${this.errorMessage?.toJS()},`;
371
+ } else {
372
+ let defaultError = (defaultErrorMessage as Record<string, string>)[this.calleeName];
373
+ let index = 0;
374
+ while (defaultError && defaultError.indexOf(`{args}`) !== -1) {
375
+ defaultError = defaultError.replace(`{args}`, `\${${this.arguments[index]?.toJS()}}`);
376
+ index++;
377
+ }
378
+ const itemTitle = (this?.parentNode as any)?.parentNode?.bindAttrs?.find((item: BindAttribute) => item.name === 'label');
379
+ let labelName;
380
+ if (itemTitle?.expression?.toJS()) {
381
+ labelName = `\${${itemTitle?.expression?.toJS()}}`;
382
+ } else {
383
+ labelName = itemTitle?.value || '表单项';
384
+ }
385
+ defaultError = defaultError && defaultError.replace(`{label}`, labelName);
386
+ code += `message: \`${defaultError}\`,`;
387
+ }
388
+ code += `trigger: 'input+blur'`;
389
+ if (['required', 'filled', 'notEmpty'].includes(this.calleeName)) {
390
+ code += ',required: true';
391
+ }
392
+ code += '}';
393
+ return code;
456
394
  }
457
- code += `trigger: 'input+blur',`;
458
- code += `message: ${this.errorMessage?.toJS(shiftState(state, code))}`;
459
- code += '}';
460
- return code;
461
- }
462
-
463
- @withSourceMap()
464
- toEmbeddedTS(state?: TranslatorState): string {
465
- let code = '';
466
-
467
- const { calleeName, target, calleeKey, arguments: args, errorMessage, view } = this;
468
-
469
- if (calleeName) {
470
- // 调用逻辑时绑定的验证器
471
- if (this.getAncestor('CallLogic') || !view) {
472
- code += target.toEmbeddedTS(shiftState(state, code));
473
- code += ';\n';
474
- }
475
-
476
- if (args.length > 0) {
477
- const validationInFunction = getValidationInFunction(calleeName);
478
- code += calleeKey;
479
- code += '(';
480
- args.forEach((arg, index) => {
481
- // 如果找到函数而且有参数,就用参数的必填非必填
482
- if (validationInFunction && validationInFunction.params[index]) {
483
- code += arg.toEmbeddedTS(shiftState(state, code), validationInFunction.params[index].required, false);
484
- } else {
485
- // 如果没有就默认不必填
486
- code += arg.toEmbeddedTS(shiftState(state, code), false, false);
487
- }
488
- if (index !== args.length - 1) code += ', ';
395
+
396
+ toVue(options?: ElementToVueOptions) {
397
+ let code = '{';
398
+ // 兼容就得简写模式
399
+ if (this.calleeName && this.calleeName.includes('(')) {
400
+ return `'${this.calleeName}'`;
401
+ } else if (this.calleeName === 'unique') {
402
+ code += `validate: 'excluded',`;
403
+ } else if (this.calleeName === 'confirmed') {
404
+ code += `validate: 'is',`;
405
+ } else {
406
+ code += `validate: '${this.calleeName}',`;
407
+ }
408
+ if (this.arguments.length) {
409
+ let args = '[';
410
+ this.arguments?.forEach((arg, index) => {
411
+ args += arg?.toVue(options);
412
+ if (index !== this.arguments?.length - 1)
413
+ args += ', ';
414
+ });
415
+ args += ']';
416
+ code += `args: ${args} ,`;
417
+ }
418
+ if (this.errorMessage) {
419
+ code += `message: ${this.errorMessage?.toVue(options)},`;
420
+ } else {
421
+ let defaultError = (defaultErrorMessage as Record<string, string>)[this.calleeName];
422
+ let index = 0;
423
+ while (defaultError && defaultError.indexOf(`{args}`) !== -1) {
424
+ defaultError = defaultError.replace(`{args}`, `\${${this.arguments[index]?.toVue(options)}}`);
425
+ index++;
426
+ }
427
+ const itemTitle = (this?.parentNode as any)?.parentNode?.bindAttrs?.find((item: BindAttribute) => item.name === 'label');
428
+ let labelName;
429
+ if (itemTitle?.expression?.toVue()) {
430
+ labelName = `\${${itemTitle?.expression?.toVue()}}`;
431
+ } else {
432
+ labelName = itemTitle?.value || '表单项';
433
+ }
434
+ defaultError = defaultError && defaultError.replace(`{label}`, labelName);
435
+ code += `message: \`${defaultError}\`,`;
436
+ }
437
+ code += `trigger: 'input+blur'`;
438
+ if (['required', 'filled', 'notEmpty'].includes(this.calleeName)) {
439
+ code += ',required: true';
440
+ }
441
+ code += '}';
442
+ return code;
443
+ }
444
+
445
+ toUI(state?: TranslatorState): string {
446
+ let code = this.calleeName;
447
+ if (this.arguments?.length) {
448
+ code += '(';
449
+ this.arguments?.forEach((arg, index) => {
450
+ code += arg?.toUI(shiftState(state, code));
451
+ if (index !== this.arguments?.length - 1)
452
+ code += ', ';
453
+ });
454
+ code += ')';
455
+ }
456
+ return code;
457
+ }
458
+
459
+ toJS(state?: TranslatorState): string {
460
+ let code = '{';
461
+ code += `validate: '${this.calleeName}',`;
462
+ if (this.arguments.length) {
463
+ let args = '[';
464
+ this.arguments?.forEach((arg, index) => {
465
+ args += arg?.toJS(shiftState(state, code));
466
+ if (index !== this.arguments?.length - 1)
467
+ args += ', ';
468
+ });
469
+ args += ']';
470
+ code += `args: ${args},`;
471
+ }
472
+ code += `trigger: 'input+blur',`;
473
+ code += `message: ${this.errorMessage?.toJS(shiftState(state, code))}`;
474
+ code += '}';
475
+ return code;
476
+ }
477
+
478
+ @withSourceMap()
479
+ toEmbeddedTS(state?: TranslatorState): string {
480
+ let code = '';
481
+
482
+ const {
483
+ calleeName,
484
+ target,
485
+ calleeKey,
486
+ arguments: args,
487
+ errorMessage,
488
+ view,
489
+ } = this;
490
+
491
+ if (calleeName) {
492
+ // 调用逻辑时绑定的验证器
493
+ if (this.getAncestor('CallLogic') || !view) {
494
+ code += target.toEmbeddedTS(shiftState(state, code));
495
+ code += ';\n';
496
+ }
497
+
498
+ if (args.length > 0) {
499
+ const validationInFunction = getValidationInFunction(calleeName);
500
+ code += calleeKey;
501
+ code += '(';
502
+ args.forEach((arg, index) => {
503
+ const param = validationInFunction?.params?.[index];
504
+
505
+ // 当前参数缺失 keyword,且原始形参中有名称,则补充参数
506
+ if (!arg.keyword && param.name) {
507
+ arg.keyword = param.name;
508
+ }
509
+
510
+ // 如果找到函数而且有参数,就用参数的必填非必填
511
+ if (validationInFunction && param) {
512
+ code += arg.toEmbeddedTS(shiftState(state, code), param.required, false);
513
+ }
514
+ // 如果没有就默认不必填
515
+ else {
516
+ code += arg.toEmbeddedTS(shiftState(state, code), false, false);
517
+ }
518
+
519
+ if (index !== args.length - 1) {
520
+ code += ', ';
521
+ }
522
+ });
523
+ code += ');';
524
+ }
525
+
526
+ if (errorMessage) {
527
+ code += 'nasl.validation.errorMessage(';
528
+ code += errorMessage.toEmbeddedTS(shiftState(state, code));
529
+ code += ')';
530
+ }
531
+ } else {
532
+ code += '__ValidationRule__';
533
+ }
534
+ return code;
535
+ }
536
+
537
+ toBrief(): string {
538
+ return this.arguments.map((a) => a.toBrief()).join('<br />');
539
+ }
540
+
541
+ get calleeKey(): string {
542
+ return `${this.calleeNamespace}.${this.calleeName}`;
543
+ }
544
+
545
+ _setCallee(func: Function) {
546
+ this.calleeNamespace = func.getNamespace();
547
+ this.calleeName = func.name;
548
+ this.arguments = [];
549
+ func.params.forEach((param) => {
550
+ this._addArgument(undefined);
489
551
  });
490
- code += ');';
491
- }
492
-
493
- if (errorMessage) {
494
- code += 'nasl.validation.errorMessage(';
495
- code += errorMessage.toEmbeddedTS(shiftState(state, code));
496
- code += ')';
497
- }
498
- } else {
499
- code += '__IDENTIFIER__';
500
552
  }
501
- return code;
502
- }
503
-
504
- toBrief(): string {
505
- return this.arguments.map((a) => a.toBrief()).join('<br />');
506
- }
507
-
508
- get calleeKey(): string {
509
- return `${this.calleeNamespace}.${this.calleeName}`;
510
- }
511
-
512
- _setCallee(func: Function) {
513
- this.calleeNamespace = func.getNamespace();
514
- this.calleeName = func.name;
515
- this.arguments = [];
516
- func.params.forEach((param) => {
517
- this._addArgument(undefined);
518
- });
519
- }
520
-
521
- setCallee(func: Function) {
522
- const calleeNamespace = func.getNamespace();
523
- const calleeName = func.name;
524
- const params = func.params.map((param) => {
525
- const relationOptions = { parentNode: this, parentKey: 'arguments' };
526
- const argument = Argument.from(
527
- {
528
- keyword: param.name,
529
- },
530
- this
531
- );
532
- Object.assign(argument, relationOptions);
533
- return argument;
534
- });
535
- if (this.app) {
536
- this.app.emit('collect:start', {
537
- actionMsg: `切换调用逻辑`,
538
- });
539
- const { parentNode } = this;
540
- this.update({
541
- calleeNamespace,
542
- calleeName,
543
- arguments: params,
544
- folded: false,
545
- });
546
- if (parentNode.concept === 'MemberExpression' && 'firstMemberExpressionNode' in parentNode) {
547
- const topNode = parentNode.firstMemberExpressionNode();
548
- topNode.replaceNode(this);
549
- }
550
- this.app.emit('collect:end');
551
- } else {
552
- this.update({
553
- calleeNamespace,
554
- calleeName,
555
- arguments: params,
556
- folded: false,
557
- });
553
+
554
+ setCallee(func: Function) {
555
+ const calleeNamespace = func.getNamespace();
556
+ const calleeName = func.name;
557
+ const params = func.params.map((param) => {
558
+ const relationOptions = { parentNode: this, parentKey: 'arguments' };
559
+ const argument = Argument.from({
560
+ keyword: param.name,
561
+ }, this);
562
+ Object.assign(argument, relationOptions);
563
+ return argument;
564
+ });
565
+ if (this.app) {
566
+ this.app.emit('collect:start', {
567
+ actionMsg: `切换调用逻辑`,
568
+ });
569
+ const parentNode: any = this.parentNode;
570
+ this.update({
571
+ calleeNamespace,
572
+ calleeName,
573
+ arguments: params,
574
+ folded: false,
575
+ });
576
+ if (parentNode.concept === 'MemberExpression') {
577
+ const topNode = parentNode.firstMemberExpressionNode();
578
+ topNode.replaceNode(this);
579
+ }
580
+ this.app.emit('collect:end');
581
+ } else {
582
+ this.update({
583
+ calleeNamespace,
584
+ calleeName,
585
+ arguments: params,
586
+ folded: false,
587
+ });
588
+ }
558
589
  }
559
- }
560
- //= ===============================================================================
561
- // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
562
- // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
563
- //= ===============================================================================
590
+ //================================================================================
591
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
592
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
593
+ //================================================================================
564
594
  }
565
595
 
566
596
  classMap.ValidationRule = ValidationRule;
567
597
  export default ValidationRule;
568
- //= ===============================================================================
598
+ //================================================================================
569
599
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
570
600
  // 自动生成的代码已结束。下面可以手动编写。
571
- //= ===============================================================================
601
+ //================================================================================