@webda/core 3.16.4 → 4.0.0-beta.2

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 (452) hide show
  1. package/lib/application.d.ts +29 -8
  2. package/lib/application.d.ts.map +1 -0
  3. package/lib/application.js +65 -38
  4. package/lib/application.js.map +1 -1
  5. package/lib/application.spec.d.ts +1 -0
  6. package/lib/application.spec.d.ts.map +1 -0
  7. package/lib/application.spec.js +57 -43
  8. package/lib/application.spec.js.map +1 -1
  9. package/lib/core.d.ts +16 -12
  10. package/lib/core.d.ts.map +1 -0
  11. package/lib/core.js +105 -80
  12. package/lib/core.js.map +1 -1
  13. package/lib/core.spec.d.ts +1 -0
  14. package/lib/core.spec.d.ts.map +1 -0
  15. package/lib/core.spec.js +96 -67
  16. package/lib/core.spec.js.map +1 -1
  17. package/lib/errors.d.ts +59 -60
  18. package/lib/errors.d.ts.map +1 -0
  19. package/lib/errors.js +92 -108
  20. package/lib/errors.js.map +1 -1
  21. package/lib/errors.spec.d.ts +1 -0
  22. package/lib/errors.spec.d.ts.map +1 -0
  23. package/lib/errors.spec.js +1 -1
  24. package/lib/errors.spec.js.map +1 -1
  25. package/lib/index.d.ts +6 -3
  26. package/lib/index.d.ts.map +1 -0
  27. package/lib/index.js +6 -3
  28. package/lib/index.js.map +1 -1
  29. package/lib/models/aclmodel.d.ts +2 -2
  30. package/lib/models/aclmodel.d.ts.map +1 -0
  31. package/lib/models/aclmodel.js +8 -9
  32. package/lib/models/aclmodel.js.map +1 -1
  33. package/lib/models/aclmodel.spec.d.ts +1 -0
  34. package/lib/models/aclmodel.spec.d.ts.map +1 -0
  35. package/lib/models/aclmodel.spec.js +3 -3
  36. package/lib/models/aclmodel.spec.js.map +1 -1
  37. package/lib/models/coremodel.d.ts +15 -0
  38. package/lib/models/coremodel.d.ts.map +1 -0
  39. package/lib/models/coremodel.js +35 -28
  40. package/lib/models/coremodel.js.map +1 -1
  41. package/lib/models/coremodel.spec.d.ts +1 -0
  42. package/lib/models/coremodel.spec.d.ts.map +1 -0
  43. package/lib/models/coremodel.spec.js +33 -31
  44. package/lib/models/coremodel.spec.js.map +1 -1
  45. package/lib/models/deployment.d.ts +1 -0
  46. package/lib/models/deployment.d.ts.map +1 -0
  47. package/lib/models/ident.d.ts +17 -2
  48. package/lib/models/ident.d.ts.map +1 -0
  49. package/lib/models/ident.js +0 -14
  50. package/lib/models/ident.js.map +1 -1
  51. package/lib/models/ident.spec.d.ts +1 -0
  52. package/lib/models/ident.spec.d.ts.map +1 -0
  53. package/lib/models/ident.spec.js +1 -20
  54. package/lib/models/ident.spec.js.map +1 -1
  55. package/lib/models/ownermodel.d.ts +1 -0
  56. package/lib/models/ownermodel.d.ts.map +1 -0
  57. package/lib/models/ownermodel.spec.d.ts +1 -0
  58. package/lib/models/ownermodel.spec.d.ts.map +1 -0
  59. package/lib/models/ownermodel.spec.js +57 -33
  60. package/lib/models/ownermodel.spec.js.map +1 -1
  61. package/lib/models/relations.d.ts +1 -0
  62. package/lib/models/relations.d.ts.map +1 -0
  63. package/lib/models/relations.js +3 -3
  64. package/lib/models/relations.js.map +1 -1
  65. package/lib/models/relations.spec.d.ts +2 -0
  66. package/lib/models/relations.spec.d.ts.map +1 -0
  67. package/lib/models/relations.spec.js +10 -17
  68. package/lib/models/relations.spec.js.map +1 -1
  69. package/lib/models/rolemodel.d.ts +1 -0
  70. package/lib/models/rolemodel.d.ts.map +1 -0
  71. package/lib/models/rolemodel.js +2 -2
  72. package/lib/models/rolemodel.js.map +1 -1
  73. package/lib/models/rolemodel.spec.d.ts +1 -0
  74. package/lib/models/rolemodel.spec.d.ts.map +1 -0
  75. package/lib/models/rolemodel.spec.js +5 -1
  76. package/lib/models/rolemodel.spec.js.map +1 -1
  77. package/lib/models/simpleuser.d.ts +47 -0
  78. package/lib/models/simpleuser.d.ts.map +1 -0
  79. package/lib/models/simpleuser.js +84 -0
  80. package/lib/models/simpleuser.js.map +1 -0
  81. package/lib/models/test.d.ts +11 -0
  82. package/lib/models/test.d.ts.map +1 -0
  83. package/lib/models/test.js +7 -0
  84. package/lib/models/test.js.map +1 -0
  85. package/lib/models/user.d.ts +2 -35
  86. package/lib/models/user.d.ts.map +1 -0
  87. package/lib/models/user.js +3 -74
  88. package/lib/models/user.js.map +1 -1
  89. package/lib/models/user.spec.d.ts +1 -0
  90. package/lib/models/user.spec.d.ts.map +1 -0
  91. package/lib/models/user.spec.js +7 -6
  92. package/lib/models/user.spec.js.map +1 -1
  93. package/lib/queues/filequeue.d.ts +1 -0
  94. package/lib/queues/filequeue.d.ts.map +1 -0
  95. package/lib/queues/filequeue.js +5 -5
  96. package/lib/queues/filequeue.js.map +1 -1
  97. package/lib/queues/filequeue.spec.d.ts +1 -0
  98. package/lib/queues/filequeue.spec.d.ts.map +1 -0
  99. package/lib/queues/filequeue.spec.js +11 -5
  100. package/lib/queues/filequeue.spec.js.map +1 -1
  101. package/lib/queues/memoryqueue.d.ts +14 -0
  102. package/lib/queues/memoryqueue.d.ts.map +1 -0
  103. package/lib/queues/memoryqueue.js +38 -7
  104. package/lib/queues/memoryqueue.js.map +1 -1
  105. package/lib/queues/memoryqueue.spec.d.ts +1 -0
  106. package/lib/queues/memoryqueue.spec.d.ts.map +1 -0
  107. package/lib/queues/memoryqueue.spec.js +18 -7
  108. package/lib/queues/memoryqueue.spec.js.map +1 -1
  109. package/lib/queues/pubsubservice.d.ts +1 -0
  110. package/lib/queues/pubsubservice.d.ts.map +1 -0
  111. package/lib/queues/queue.spec.d.ts +3 -2
  112. package/lib/queues/queue.spec.d.ts.map +1 -0
  113. package/lib/queues/queue.spec.js +5 -3
  114. package/lib/queues/queue.spec.js.map +1 -1
  115. package/lib/queues/queueservice.d.ts +1 -0
  116. package/lib/queues/queueservice.d.ts.map +1 -0
  117. package/lib/queues/queueservice.js +7 -7
  118. package/lib/queues/queueservice.js.map +1 -1
  119. package/lib/rest/restdomainservice.d.ts +63 -0
  120. package/lib/rest/restdomainservice.d.ts.map +1 -0
  121. package/lib/rest/restdomainservice.js +687 -0
  122. package/lib/rest/restdomainservice.js.map +1 -0
  123. package/lib/rest/restdomainservice.spec.d.ts +2 -0
  124. package/lib/rest/restdomainservice.spec.d.ts.map +1 -0
  125. package/lib/rest/restdomainservice.spec.js +124 -0
  126. package/lib/rest/restdomainservice.spec.js.map +1 -0
  127. package/lib/{router.d.ts → rest/router.d.ts} +6 -4
  128. package/lib/rest/router.d.ts.map +1 -0
  129. package/lib/{router.js → rest/router.js} +33 -23
  130. package/lib/rest/router.js.map +1 -0
  131. package/lib/rest/router.spec.d.ts +2 -0
  132. package/lib/rest/router.spec.d.ts.map +1 -0
  133. package/lib/{router.spec.js → rest/router.spec.js} +54 -28
  134. package/lib/rest/router.spec.js.map +1 -0
  135. package/lib/services/asyncevents.d.ts +1 -0
  136. package/lib/services/asyncevents.d.ts.map +1 -0
  137. package/lib/services/asyncevents.js +4 -4
  138. package/lib/services/asyncevents.js.map +1 -1
  139. package/lib/services/asyncevents.spec.d.ts +1 -0
  140. package/lib/services/asyncevents.spec.d.ts.map +1 -0
  141. package/lib/services/asyncevents.spec.js +10 -10
  142. package/lib/services/asyncevents.spec.js.map +1 -1
  143. package/lib/services/authentication.d.ts +2 -1
  144. package/lib/services/authentication.d.ts.map +1 -0
  145. package/lib/services/authentication.js +26 -25
  146. package/lib/services/authentication.js.map +1 -1
  147. package/lib/services/authentication.spec.d.ts +1 -0
  148. package/lib/services/authentication.spec.d.ts.map +1 -0
  149. package/lib/services/authentication.spec.js +24 -24
  150. package/lib/services/authentication.spec.js.map +1 -1
  151. package/lib/services/binary.d.ts +13 -87
  152. package/lib/services/binary.d.ts.map +1 -0
  153. package/lib/services/binary.js +39 -421
  154. package/lib/services/binary.js.map +1 -1
  155. package/lib/services/binary.spec.d.ts +19 -22
  156. package/lib/services/binary.spec.d.ts.map +1 -0
  157. package/lib/services/binary.spec.js +87 -374
  158. package/lib/services/binary.spec.js.map +1 -1
  159. package/lib/services/cloudbinary.d.ts +3 -2
  160. package/lib/services/cloudbinary.d.ts.map +1 -0
  161. package/lib/services/cloudbinary.js +1 -1
  162. package/lib/services/cloudbinary.js.map +1 -1
  163. package/lib/services/cloudbinary.spec.d.ts +1 -8
  164. package/lib/services/cloudbinary.spec.d.ts.map +1 -0
  165. package/lib/services/cloudbinary.spec.js +4 -130
  166. package/lib/services/cloudbinary.spec.js.map +1 -1
  167. package/lib/services/configuration.d.ts +10 -1
  168. package/lib/services/configuration.d.ts.map +1 -0
  169. package/lib/services/configuration.js +22 -7
  170. package/lib/services/configuration.js.map +1 -1
  171. package/lib/services/configuration.spec.d.ts +1 -0
  172. package/lib/services/configuration.spec.d.ts.map +1 -0
  173. package/lib/services/configuration.spec.js +60 -17
  174. package/lib/services/configuration.spec.js.map +1 -1
  175. package/lib/services/cron.d.ts +2 -1
  176. package/lib/services/cron.d.ts.map +1 -0
  177. package/lib/services/cron.js +10 -10
  178. package/lib/services/cron.js.map +1 -1
  179. package/lib/services/cron.spec.d.ts +1 -0
  180. package/lib/services/cron.spec.d.ts.map +1 -0
  181. package/lib/services/cron.spec.js +2 -2
  182. package/lib/services/cron.spec.js.map +1 -1
  183. package/lib/services/cryptoservice.d.ts +3 -2
  184. package/lib/services/cryptoservice.d.ts.map +1 -0
  185. package/lib/services/cryptoservice.js +29 -30
  186. package/lib/services/cryptoservice.js.map +1 -1
  187. package/lib/services/cryptoservice.spec.d.ts +1 -0
  188. package/lib/services/cryptoservice.spec.d.ts.map +1 -0
  189. package/lib/services/cryptoservice.spec.js +17 -17
  190. package/lib/services/cryptoservice.spec.js.map +1 -1
  191. package/lib/services/debugmailer.d.ts +2 -2
  192. package/lib/services/debugmailer.d.ts.map +1 -0
  193. package/lib/services/debugmailer.js +1 -2
  194. package/lib/services/debugmailer.js.map +1 -1
  195. package/lib/services/debugmailer.spec.d.ts +1 -0
  196. package/lib/services/debugmailer.spec.d.ts.map +1 -0
  197. package/lib/services/debugmailer.spec.js +6 -3
  198. package/lib/services/debugmailer.spec.js.map +1 -1
  199. package/lib/services/domainservice.d.ts +167 -47
  200. package/lib/services/domainservice.d.ts.map +1 -0
  201. package/lib/services/domainservice.js +520 -753
  202. package/lib/services/domainservice.js.map +1 -1
  203. package/lib/services/domainservice.spec.d.ts +1 -0
  204. package/lib/services/domainservice.spec.d.ts.map +1 -0
  205. package/lib/services/domainservice.spec.js +201 -31
  206. package/lib/services/domainservice.spec.js.map +1 -1
  207. package/lib/services/filebinary.d.ts +8 -5
  208. package/lib/services/filebinary.d.ts.map +1 -0
  209. package/lib/services/filebinary.js +34 -32
  210. package/lib/services/filebinary.js.map +1 -1
  211. package/lib/services/filebinary.spec.d.ts +12 -8
  212. package/lib/services/filebinary.spec.d.ts.map +1 -0
  213. package/lib/services/filebinary.spec.js +135 -122
  214. package/lib/services/filebinary.spec.js.map +1 -1
  215. package/lib/services/fileconfiguration.d.ts +2 -1
  216. package/lib/services/fileconfiguration.d.ts.map +1 -0
  217. package/lib/services/fileconfiguration.js +1 -1
  218. package/lib/services/fileconfiguration.js.map +1 -1
  219. package/lib/services/fileconfiguration.spec.d.ts +1 -0
  220. package/lib/services/fileconfiguration.spec.d.ts.map +1 -0
  221. package/lib/services/fileconfiguration.spec.js +65 -27
  222. package/lib/services/fileconfiguration.spec.js.map +1 -1
  223. package/lib/services/invitationservice.d.ts +2 -1
  224. package/lib/services/invitationservice.d.ts.map +1 -0
  225. package/lib/services/invitationservice.js +19 -16
  226. package/lib/services/invitationservice.js.map +1 -1
  227. package/lib/services/invitationservice.spec.d.ts +1 -0
  228. package/lib/services/invitationservice.spec.d.ts.map +1 -0
  229. package/lib/services/invitationservice.spec.js +73 -22
  230. package/lib/services/invitationservice.spec.js.map +1 -1
  231. package/lib/services/kubernetesconfiguration.d.ts +1 -0
  232. package/lib/services/kubernetesconfiguration.d.ts.map +1 -0
  233. package/lib/services/kubernetesconfiguration.js +0 -2
  234. package/lib/services/kubernetesconfiguration.js.map +1 -1
  235. package/lib/services/kubernetesconfiguration.spec.d.ts +1 -0
  236. package/lib/services/kubernetesconfiguration.spec.d.ts.map +1 -0
  237. package/lib/services/kubernetesconfiguration.spec.js +67 -8
  238. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  239. package/lib/services/mailer.d.ts +1 -0
  240. package/lib/services/mailer.d.ts.map +1 -0
  241. package/lib/services/mailer.js +3 -3
  242. package/lib/services/mailer.js.map +1 -1
  243. package/lib/services/mailer.spec.d.ts +1 -0
  244. package/lib/services/mailer.spec.d.ts.map +1 -0
  245. package/lib/services/mailer.spec.js +18 -4
  246. package/lib/services/mailer.spec.js.map +1 -1
  247. package/lib/services/notificationservice.d.ts +1 -0
  248. package/lib/services/notificationservice.d.ts.map +1 -0
  249. package/lib/services/notificationservice.js +1 -1
  250. package/lib/services/notificationservice.js.map +1 -1
  251. package/lib/services/notificationservice.spec.d.ts +1 -0
  252. package/lib/services/notificationservice.spec.d.ts.map +1 -0
  253. package/lib/services/notificationservice.spec.js +8 -3
  254. package/lib/services/notificationservice.spec.js.map +1 -1
  255. package/lib/services/oauth.d.ts +6 -3
  256. package/lib/services/oauth.d.ts.map +1 -0
  257. package/lib/services/oauth.js +11 -8
  258. package/lib/services/oauth.js.map +1 -1
  259. package/lib/services/oauth.spec.d.ts +1 -0
  260. package/lib/services/oauth.spec.d.ts.map +1 -0
  261. package/lib/services/oauth.spec.js +39 -15
  262. package/lib/services/oauth.spec.js.map +1 -1
  263. package/lib/services/prometheus.d.ts +1 -0
  264. package/lib/services/prometheus.d.ts.map +1 -0
  265. package/lib/services/prometheus.spec.d.ts +1 -0
  266. package/lib/services/prometheus.spec.d.ts.map +1 -0
  267. package/lib/services/prometheus.spec.js +38 -19
  268. package/lib/services/prometheus.spec.js.map +1 -1
  269. package/lib/services/resource.d.ts +21 -1
  270. package/lib/services/resource.d.ts.map +1 -0
  271. package/lib/services/resource.js +20 -3
  272. package/lib/services/resource.js.map +1 -1
  273. package/lib/services/resource.spec.d.ts +1 -0
  274. package/lib/services/resource.spec.d.ts.map +1 -0
  275. package/lib/services/resource.spec.js +38 -20
  276. package/lib/services/resource.spec.js.map +1 -1
  277. package/lib/services/service.d.ts +2 -2
  278. package/lib/services/service.d.ts.map +1 -0
  279. package/lib/services/service.js +13 -23
  280. package/lib/services/service.js.map +1 -1
  281. package/lib/services/service.spec.d.ts +1 -0
  282. package/lib/services/service.spec.d.ts.map +1 -0
  283. package/lib/services/service.spec.js +58 -40
  284. package/lib/services/service.spec.js.map +1 -1
  285. package/lib/stores/aggregator.d.ts +10 -3
  286. package/lib/stores/aggregator.d.ts.map +1 -0
  287. package/lib/stores/aggregator.js +6 -6
  288. package/lib/stores/aggregator.js.map +1 -1
  289. package/lib/stores/file.d.ts +3 -2
  290. package/lib/stores/file.d.ts.map +1 -0
  291. package/lib/stores/file.js +13 -13
  292. package/lib/stores/file.js.map +1 -1
  293. package/lib/stores/file.spec.d.ts +5 -11
  294. package/lib/stores/file.spec.d.ts.map +1 -0
  295. package/lib/stores/file.spec.js +20 -114
  296. package/lib/stores/file.spec.js.map +1 -1
  297. package/lib/stores/mapper.d.ts +2 -1
  298. package/lib/stores/mapper.d.ts.map +1 -0
  299. package/lib/stores/mapper.js +12 -12
  300. package/lib/stores/mapper.js.map +1 -1
  301. package/lib/stores/mapper.spec.d.ts +1 -0
  302. package/lib/stores/mapper.spec.d.ts.map +1 -0
  303. package/lib/stores/mapper.spec.js +24 -17
  304. package/lib/stores/mapper.spec.js.map +1 -1
  305. package/lib/stores/memory.d.ts +2 -1
  306. package/lib/stores/memory.d.ts.map +1 -0
  307. package/lib/stores/memory.js +15 -15
  308. package/lib/stores/memory.js.map +1 -1
  309. package/lib/stores/memory.spec.d.ts +7 -13
  310. package/lib/stores/memory.spec.d.ts.map +1 -0
  311. package/lib/stores/memory.spec.js +118 -183
  312. package/lib/stores/memory.spec.js.map +1 -1
  313. package/lib/stores/modelmapper.d.ts +1 -0
  314. package/lib/stores/modelmapper.d.ts.map +1 -0
  315. package/lib/stores/modelmapper.js +8 -10
  316. package/lib/stores/modelmapper.js.map +1 -1
  317. package/lib/stores/store.d.ts +4 -145
  318. package/lib/stores/store.d.ts.map +1 -0
  319. package/lib/stores/store.js +54 -654
  320. package/lib/stores/store.js.map +1 -1
  321. package/lib/stores/store.spec.d.ts +11 -19
  322. package/lib/stores/store.spec.d.ts.map +1 -0
  323. package/lib/stores/store.spec.js +99 -268
  324. package/lib/stores/store.spec.js.map +1 -1
  325. package/lib/test.d.ts +109 -6
  326. package/lib/test.d.ts.map +1 -0
  327. package/lib/test.js +245 -22
  328. package/lib/test.js.map +1 -1
  329. package/lib/unpackedapplication.d.ts +3 -2
  330. package/lib/unpackedapplication.d.ts.map +1 -0
  331. package/lib/unpackedapplication.js +29 -16
  332. package/lib/unpackedapplication.js.map +1 -1
  333. package/lib/utils/abstractdeployer.d.ts +1 -0
  334. package/lib/utils/abstractdeployer.d.ts.map +1 -0
  335. package/lib/utils/abstractdeployer.spec.d.ts +1 -0
  336. package/lib/utils/abstractdeployer.spec.d.ts.map +1 -0
  337. package/lib/utils/case.d.ts +1 -0
  338. package/lib/utils/case.d.ts.map +1 -0
  339. package/lib/utils/case.spec.d.ts +1 -0
  340. package/lib/utils/case.spec.d.ts.map +1 -0
  341. package/lib/utils/context.d.ts +37 -17
  342. package/lib/utils/context.d.ts.map +1 -0
  343. package/lib/utils/context.js +53 -42
  344. package/lib/utils/context.js.map +1 -1
  345. package/lib/utils/context.spec.d.ts +1 -0
  346. package/lib/utils/context.spec.d.ts.map +1 -0
  347. package/lib/utils/context.spec.js +21 -14
  348. package/lib/utils/context.spec.js.map +1 -1
  349. package/lib/utils/cookie.d.ts +1 -0
  350. package/lib/utils/cookie.d.ts.map +1 -0
  351. package/lib/utils/cookie.js +2 -2
  352. package/lib/utils/cookie.js.map +1 -1
  353. package/lib/utils/cookie.spec.d.ts +1 -0
  354. package/lib/utils/cookie.spec.d.ts.map +1 -0
  355. package/lib/utils/cookie.spec.js +20 -10
  356. package/lib/utils/cookie.spec.js.map +1 -1
  357. package/lib/utils/esm.d.ts +1 -0
  358. package/lib/utils/esm.d.ts.map +1 -0
  359. package/lib/utils/httpcontext.d.ts +1 -0
  360. package/lib/utils/httpcontext.d.ts.map +1 -0
  361. package/lib/utils/httpcontext.js +7 -7
  362. package/lib/utils/httpcontext.js.map +1 -1
  363. package/lib/utils/httpcontext.spec.d.ts +1 -0
  364. package/lib/utils/httpcontext.spec.d.ts.map +1 -0
  365. package/lib/utils/httpcontext.spec.js +7 -7
  366. package/lib/utils/httpcontext.spec.js.map +1 -1
  367. package/lib/utils/logger.d.ts +1 -0
  368. package/lib/utils/logger.d.ts.map +1 -0
  369. package/lib/utils/logger.spec.d.ts +1 -0
  370. package/lib/utils/logger.spec.d.ts.map +1 -0
  371. package/lib/utils/logger.spec.js +5 -5
  372. package/lib/utils/logger.spec.js.map +1 -1
  373. package/lib/utils/serializers.d.ts +6 -4
  374. package/lib/utils/serializers.d.ts.map +1 -0
  375. package/lib/utils/serializers.js +30 -27
  376. package/lib/utils/serializers.js.map +1 -1
  377. package/lib/utils/serializers.spec.d.ts +1 -0
  378. package/lib/utils/serializers.spec.d.ts.map +1 -0
  379. package/lib/utils/serializers.spec.js +12 -14
  380. package/lib/utils/serializers.spec.js.map +1 -1
  381. package/lib/utils/session.d.ts +2 -5
  382. package/lib/utils/session.d.ts.map +1 -0
  383. package/lib/utils/session.js +1 -11
  384. package/lib/utils/session.js.map +1 -1
  385. package/lib/utils/session.spec.d.ts +1 -0
  386. package/lib/utils/session.spec.d.ts.map +1 -0
  387. package/lib/utils/session.spec.js +22 -12
  388. package/lib/utils/session.spec.js.map +1 -1
  389. package/lib/utils/throttler.d.ts +1 -4
  390. package/lib/utils/throttler.d.ts.map +1 -0
  391. package/lib/utils/throttler.js +1 -9
  392. package/lib/utils/throttler.js.map +1 -1
  393. package/lib/utils/throttler.spec.d.ts +1 -0
  394. package/lib/utils/throttler.spec.d.ts.map +1 -0
  395. package/lib/utils/throttler.spec.js +4 -6
  396. package/lib/utils/throttler.spec.js.map +1 -1
  397. package/lib/utils/waiter.d.ts +1 -0
  398. package/lib/utils/waiter.d.ts.map +1 -0
  399. package/lib/utils/waiter.js +3 -3
  400. package/lib/utils/waiter.js.map +1 -1
  401. package/lib/utils/waiter.spec.d.ts +1 -0
  402. package/lib/utils/waiter.spec.d.ts.map +1 -0
  403. package/lib/utils/waiter.spec.js +6 -6
  404. package/lib/utils/waiter.spec.js.map +1 -1
  405. package/package.json +20 -16
  406. package/test/config.json +6 -90
  407. package/test/data/.env +1 -0
  408. package/webda.module.json +607 -377
  409. package/lib/router.js.map +0 -1
  410. package/lib/router.spec.d.ts +0 -1
  411. package/lib/router.spec.js.map +0 -1
  412. package/lib/stores/aliasstore.d.ts +0 -108
  413. package/lib/stores/aliasstore.js +0 -168
  414. package/lib/stores/aliasstore.js.map +0 -1
  415. package/lib/stores/aliasstore.spec.d.ts +0 -11
  416. package/lib/stores/aliasstore.spec.js +0 -89
  417. package/lib/stores/aliasstore.spec.js.map +0 -1
  418. package/lib/stores/webdaql/WebdaQLLexer.d.ts +0 -54
  419. package/lib/stores/webdaql/WebdaQLLexer.js +0 -295
  420. package/lib/stores/webdaql/WebdaQLLexer.js.map +0 -1
  421. package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +0 -54
  422. package/lib/stores/webdaql/WebdaQLParserLexer.js +0 -295
  423. package/lib/stores/webdaql/WebdaQLParserLexer.js.map +0 -1
  424. package/lib/stores/webdaql/WebdaQLParserListener.d.ts +0 -296
  425. package/lib/stores/webdaql/WebdaQLParserListener.js +0 -3
  426. package/lib/stores/webdaql/WebdaQLParserListener.js.map +0 -1
  427. package/lib/stores/webdaql/WebdaQLParserParser.d.ts +0 -311
  428. package/lib/stores/webdaql/WebdaQLParserParser.js +0 -1807
  429. package/lib/stores/webdaql/WebdaQLParserParser.js.map +0 -1
  430. package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +0 -181
  431. package/lib/stores/webdaql/WebdaQLParserVisitor.js +0 -3
  432. package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +0 -1
  433. package/lib/stores/webdaql/query.d.ts +0 -390
  434. package/lib/stores/webdaql/query.js +0 -702
  435. package/lib/stores/webdaql/query.js.map +0 -1
  436. package/lib/stores/webdaql/query.spec.d.ts +0 -1
  437. package/lib/stores/webdaql/query.spec.js +0 -206
  438. package/lib/stores/webdaql/query.spec.js.map +0 -1
  439. package/test/config-file-missing-file-no-default.json +0 -44
  440. package/test/config-file-missing-file.json +0 -55
  441. package/test/config-file-no-reload.json +0 -69
  442. package/test/config-file-reload.json +0 -68
  443. package/test/config-invitation.json +0 -63
  444. package/test/config-kube-reload.json +0 -68
  445. package/test/config-reload.json +0 -66
  446. package/test/config.old.json +0 -152
  447. package/test/moddas/annotatedservice.js +0 -23
  448. package/test/moddas/debugmailer.js +0 -13
  449. package/test/moddas/fakeservice.js +0 -4
  450. package/test/moddas/voidstore.js +0 -66
  451. package/test/models/ident.js +0 -36
  452. package/test/models/task.js +0 -42
@@ -1,128 +1,5 @@
1
- import { Core, JSONUtils, Service, ServiceParameters, WebdaError, WebdaQL } from "../index.js";
1
+ import { Core, JSONUtils, Service, ServiceParameters, WebdaError } from "../index.js";
2
2
  import { TransformCase } from "../utils/case.js";
3
- /**
4
- * @WebdaModda
5
- */
6
- export class ModelsOperationsService extends Service {
7
- /**
8
- * Add operations for all exposed models
9
- * @returns
10
- */
11
- initOperations() {
12
- super.initOperations();
13
- const app = this.getWebda().getApplication();
14
- // Add default schemas
15
- if (!app.hasSchema("uuidRequest")) {
16
- app.registerSchema("uuidRequest", {
17
- type: "object",
18
- properties: {
19
- uuid: {
20
- type: "string"
21
- }
22
- },
23
- required: ["uuid"]
24
- });
25
- }
26
- if (!app.hasSchema("searchRequest")) {
27
- app.registerSchema("searchRequest", {
28
- type: "object",
29
- properties: {
30
- query: {
31
- type: "string"
32
- }
33
- }
34
- });
35
- }
36
- const getSchema = (id, input, params) => {
37
- const schema = {
38
- type: "object",
39
- properties: {},
40
- required: []
41
- };
42
- if (input && app.hasSchema(input)) {
43
- schema.properties["input"] = app.getSchema(input);
44
- schema.required.push("input");
45
- }
46
- if (params) {
47
- schema.properties["params"] = app.getSchema(params);
48
- schema.required.push("params");
49
- }
50
- app.registerSchema(id, schema);
51
- return id;
52
- };
53
- const models = app.getModels();
54
- for (let modelKey in models) {
55
- const model = models[modelKey];
56
- const expose = model.Expose;
57
- if (!expose) {
58
- continue;
59
- }
60
- const prefix = modelKey.split("/").pop();
61
- const modelSchema = modelKey;
62
- ["create", "update"]
63
- .filter(k => !expose.restrict[k])
64
- .forEach(k => {
65
- k = k.substring(0, 1).toUpperCase() + k.substring(1);
66
- const id = `${prefix}.${k}`;
67
- this.getWebda().registerOperation(id, {
68
- service: this.getName(),
69
- method: k === "Create" ? "httpCreate" : "operationUpdate",
70
- id,
71
- input: getSchema(id, modelSchema, k === "Update" ? "uuidRequest" : undefined),
72
- output: modelSchema
73
- });
74
- });
75
- ["delete", "get"]
76
- .filter(k => !expose.restrict[k])
77
- .forEach(k => {
78
- k = k.substring(0, 1).toUpperCase() + k.substring(1);
79
- const id = `${prefix}.${k}`;
80
- const info = {
81
- service: this.getName(),
82
- method: `http${k}`,
83
- id,
84
- input: getSchema(id, undefined, "uuidRequest")
85
- };
86
- if (k === "Get") {
87
- info.output = modelSchema;
88
- }
89
- this.getWebda().registerOperation(id, info);
90
- });
91
- if (!expose.restrict.query) {
92
- const id = `${prefix}.Query`;
93
- this.getWebda().registerOperation(id, {
94
- service: this.getName(),
95
- method: "httpQuery",
96
- id,
97
- input: getSchema(id, undefined, "searchRequest")
98
- });
99
- }
100
- // Add patch
101
- if (!expose.restrict.update) {
102
- const id = `${prefix}.Patch`;
103
- this.getWebda().registerOperation(id, {
104
- service: this.getName(),
105
- method: "operationPatch",
106
- id,
107
- input: getSchema(id, modelSchema + "?", "uuidRequest")
108
- });
109
- }
110
- // Add all operations for Actions
111
- let actions = model.getActions();
112
- Object.keys(actions).forEach(name => {
113
- const id = `${prefix}.${name.substring(0, 1).toUpperCase() + name.substring(1)}`;
114
- const info = {
115
- service: this.getName(),
116
- method: `action${name}`,
117
- id
118
- };
119
- info.input = getSchema(id, `${modelKey}.${name}.input`, "uuidRequest");
120
- info.output = `${modelKey}.${name}.output`;
121
- this.getWebda().registerOperation(id, info);
122
- });
123
- }
124
- }
125
- }
126
3
  export class DomainServiceParameters extends ServiceParameters {
127
4
  constructor(params) {
128
5
  super(params);
@@ -154,48 +31,6 @@ export class DomainServiceParameters extends ServiceParameters {
154
31
  return this.excludedModels.includes(model);
155
32
  }
156
33
  }
157
- /**
158
- * Swagger static html
159
- */
160
- const swagger = `
161
- <html>
162
- <head>
163
- <meta charset="UTF-8">
164
- <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui.css" >
165
- <style>
166
- .topbar {
167
- display: none;
168
- }
169
- </style>
170
- </head>
171
-
172
- <body>
173
- <div id="swagger-ui"></div>
174
- <script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui-bundle.js"> </script>
175
- <script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui-standalone-preset.js"> </script>
176
- <script>
177
- const spec = {{OPENAPI}};
178
- window.onload = function() {
179
- const ui = SwaggerUIBundle({
180
- spec: spec,
181
- dom_id: '#swagger-ui',
182
- deepLinking: true,
183
- presets: [
184
- SwaggerUIBundle.presets.apis,
185
- SwaggerUIStandalonePreset
186
- ],
187
- plugins: [
188
- SwaggerUIBundle.plugins.DownloadUrl
189
- ],
190
- layout: "StandaloneLayout"
191
- })
192
-
193
- window.ui = ui
194
- }
195
- </script>
196
- </body>
197
- </html>
198
- `;
199
34
  /**
200
35
  * Domain Service expose all the models as Route and Operations
201
36
  *
@@ -230,6 +65,11 @@ export class DomainService extends Service {
230
65
  if (!model.Expose || (model.getIdentifier && !this.parameters.isIncluded(model.getIdentifier()))) {
231
66
  return;
232
67
  }
68
+ const shortId = model.getIdentifier(true);
69
+ // Overlap object are hidden by design
70
+ if (shortId.includes("/")) {
71
+ return;
72
+ }
233
73
  const context = JSONUtils.duplicate(modelContext);
234
74
  context.depth = depth;
235
75
  if (!this.handleModel(model, name, context)) {
@@ -258,627 +98,554 @@ export class DomainService extends Service {
258
98
  });
259
99
  return this;
260
100
  }
261
- }
262
- /**
263
- *
264
- */
265
- export class RESTDomainServiceParameters extends DomainServiceParameters {
266
101
  /**
267
- * Set default url to /
268
- * @param params
102
+ *
103
+ * @param model
104
+ * @param uuid
269
105
  */
270
- constructor(params) {
271
- super(params);
272
- this.url ?? (this.url = "/");
106
+ async getModel(context) {
107
+ const { model } = context.getExtension("operationContext");
108
+ const { uuid } = context.getParameters();
109
+ const object = await model.ref(uuid).get();
110
+ if (object === undefined || object.isDeleted()) {
111
+ await this.emitSync("Store.WebNotFound", {
112
+ context,
113
+ uuid
114
+ });
115
+ throw new WebdaError.NotFound("Object not found");
116
+ }
117
+ return object;
273
118
  }
274
- }
275
- /**
276
- * Expose all models via a REST API
277
- * @WebdaModda
278
- */
279
- export class RESTDomainService extends DomainService {
280
119
  /**
281
- * Override to fallback on isDebug for exposeOpenAPI
282
- * @returns
120
+ * Create a model operation implementation
121
+ * @param context
283
122
  */
284
- resolve() {
285
- var _a;
286
- (_a = this.parameters).exposeOpenAPI ?? (_a.exposeOpenAPI = this.getWebda().isDebug());
287
- super.resolve();
288
- if (this.parameters.exposeOpenAPI) {
289
- this.addRoute(".", ["GET"], this.openapi, { hidden: true });
123
+ async modelCreate(context) {
124
+ const { model } = context.getExtension("operationContext");
125
+ const object = model.factory(await context.getInput(), context);
126
+ await object.checkAct(context, "create");
127
+ // Enforce the UUID
128
+ object.setUuid(object.generateUid());
129
+ // Check for conflict
130
+ // await object.validate(context, {});
131
+ if (await model.ref(object.getUuid()).exists()) {
132
+ throw new WebdaError.Conflict("Object already exists");
290
133
  }
291
- return this;
134
+ await object.save();
135
+ // Set the location header to only uuid for now
136
+ context.setHeader("Location", object.getUuid());
137
+ context.write(object);
292
138
  }
293
139
  /**
294
- * @override
140
+ * Update a model operation implementation
141
+ * @param context
295
142
  */
296
- loadParameters(params) {
297
- return new RESTDomainServiceParameters(params);
143
+ async modelUpdate(context) {
144
+ const object = await this.getModel(context);
145
+ const input = await context.getInput();
146
+ await object.checkAct(context, "update");
147
+ object.load(input);
148
+ await object.save(true);
149
+ context.write(object);
298
150
  }
299
151
  /**
300
- * Handle one model and expose it based on the service
301
- * @param model
302
- * @param name
152
+ * Get a model operation implementation
153
+ * @param context
154
+ */
155
+ async modelGet(context) {
156
+ const object = await this.getModel(context);
157
+ await object.checkAct(context, "get");
158
+ const evt = {
159
+ context,
160
+ object: object
161
+ };
162
+ //
163
+ await Promise.all([this.emitSync("Store.WebGet", evt), object.__class.emitSync("Store.WebGet", evt)]);
164
+ context.write(object);
165
+ }
166
+ /**
167
+ * Delete a model operation implementation
168
+ * @param context
169
+ */
170
+ async modelDelete(context) {
171
+ const object = await this.getModel(context);
172
+ if (!object) {
173
+ throw new WebdaError.NotFound("Object not found");
174
+ }
175
+ await object.checkAct(context, "delete");
176
+ // Object can decide to not delete but mark as deleted
177
+ await object.delete();
178
+ }
179
+ /**
180
+ * Query models
181
+ * @param context
182
+ */
183
+ async modelQuery(context) {
184
+ const { model } = context.getExtension("operationContext");
185
+ const { query } = context.getParameters();
186
+ try {
187
+ context.write(await model.query(query, true, context));
188
+ }
189
+ catch (err) {
190
+ if (err instanceof SyntaxError) {
191
+ this.log("INFO", "Query syntax error");
192
+ throw new WebdaError.BadRequest("Query syntax error");
193
+ }
194
+ throw err;
195
+ }
196
+ }
197
+ /**
198
+ * Patch a model
199
+ * @param context
200
+ */
201
+ async modelPatch(context) {
202
+ const object = await this.getModel(context);
203
+ const input = await context.getInput();
204
+ await object.checkAct(context, "update");
205
+ await object.patch(input);
206
+ context.write(object);
207
+ }
208
+ /**
209
+ * Action on a model
303
210
  * @param context
211
+ */
212
+ async modelAction(context) {
213
+ const { model, action } = context.getExtension("operationContext");
214
+ if (!action.global) {
215
+ const object = await model.ref(context.getParameters().uuid).get();
216
+ if (!object || object.isDeleted()) {
217
+ throw new WebdaError.NotFound("Object not found");
218
+ }
219
+ await object.checkAct(context, action.name);
220
+ const output = await object[action.name](context);
221
+ context.write(output);
222
+ }
223
+ else {
224
+ model[action.name](context);
225
+ }
226
+ }
227
+ /**
228
+ * Add operations for all exposed models
304
229
  * @returns
305
230
  */
306
- handleModel(model, name, context) {
307
- const depth = context.depth || 0;
308
- const relations = model.getRelations();
309
- const injectAttribute = relations?.parent?.attribute;
231
+ initOperations() {
232
+ super.initOperations();
233
+ if (!this.parameters.operations) {
234
+ return;
235
+ }
310
236
  const app = this.getWebda().getApplication();
311
- const injector = (service, method, type, ...args) => {
312
- return async (context) => {
313
- let parentId = `pid.${depth - 1}`;
314
- if (type === "SET" && injectAttribute && depth > 0) {
315
- (await context.getInput())[injectAttribute] = context.getPathParameters()[parentId];
316
- }
317
- else if (type === "QUERY") {
318
- let input = await context.getInput({ defaultValue: { q: "" } });
319
- let q;
320
- if (context.getHttpContext().getMethod() === "GET") {
321
- q = context.getParameters().q;
322
- }
323
- else {
324
- q = input.q;
325
- }
326
- let query;
327
- try {
328
- query = new WebdaQL.QueryValidator(q);
329
- }
330
- catch (err) {
331
- throw new WebdaError.BadRequest("Invalid query " + q);
332
- }
333
- if (injectAttribute) {
334
- query.merge(`${injectAttribute} = "${context.getPathParameters()[parentId]}"`);
335
- }
336
- if (args[0] !== 0) {
337
- query.merge(`__types CONTAINS "${model.getIdentifier()}"`);
338
- }
339
- if (context.getHttpContext().getMethod() === "GET") {
340
- context.getParameters().q = query.toString();
341
- }
342
- else {
343
- input.q = query.toString();
344
- }
345
- this.log("TRACE", `Query modified to '${query.toString()}' from '${q}' ${args[0]}`);
346
- }
347
- // Complete the uuid if needed
348
- if (context.getParameters().uuid) {
349
- context.getParameters().uuid = model.completeUid(context.getParameters().uuid);
350
- }
351
- await service[method](context, ...args);
352
- };
353
- };
354
- // Update prefix
355
- const prefix = (context.prefix || (this.parameters.url.endsWith("/") ? this.parameters.url : this.parameters.url + "/")) +
356
- this.transformName(name);
357
- context.prefix = prefix + `/{pid.${depth}}/`;
358
- // Register the model url
359
- this.getWebda().getRouter().registerModelUrl(app.getModelName(model), prefix);
360
- let openapi = {
361
- [this.parameters.queryMethod.toLowerCase()]: {
362
- tags: [name],
363
- summary: `Query ${name}`,
364
- operationId: `query${name}`,
365
- requestBody: this.parameters.queryMethod === "GET"
366
- ? undefined
367
- : {
368
- content: {
369
- "application/json": {
370
- schema: {
371
- properties: {
372
- q: {
373
- type: "string"
374
- }
375
- }
376
- }
377
- }
378
- }
379
- },
380
- parameters: this.parameters.queryMethod === "GET"
381
- ? [
382
- {
383
- name: "q",
384
- in: "query",
385
- description: "Query to execute",
386
- schema: {
387
- type: "string"
388
- }
389
- }
390
- ]
391
- : [],
392
- responses: {
393
- "200": {
394
- description: "Operation success",
395
- content: {
396
- "application/json": {
397
- schema: {
398
- properties: {
399
- continuationToken: {
400
- type: "string"
401
- },
402
- results: {
403
- type: "array",
404
- items: {
405
- $ref: `#/components/schemas/${model.getIdentifier()}`
406
- }
407
- }
408
- }
409
- }
410
- }
411
- }
412
- },
413
- "400": {
414
- description: "Query is invalid"
415
- },
416
- "403": {
417
- description: "You don't have permissions"
418
- }
419
- }
237
+ // Add default schemas - used for operation parameters
238
+ for (const i in ModelsOperationsService.schemas) {
239
+ if (app.hasSchema(i)) {
240
+ continue;
420
241
  }
421
- };
422
- model.Expose.restrict.query ||
423
- this.addRoute(`${prefix}${this.parameters.queryMethod === "GET" ? "{?q?}" : ""}`, [this.parameters.queryMethod], injector(model.store(), "httpQuery", "QUERY", model.store().handleModel(model)), openapi);
424
- openapi = {
425
- post: {
426
- tags: [name],
427
- summary: `Create ${name}`,
428
- operationId: `create${name}`,
429
- requestBody: {
430
- content: {
431
- "application/json": {
432
- schema: {
433
- $ref: `#/components/schemas/${model.getIdentifier()}`
434
- }
435
- }
242
+ app.registerSchema(i, ModelsOperationsService.schemas[i]);
243
+ }
244
+ const models = app.getModels();
245
+ for (const modelKey in models) {
246
+ const model = models[modelKey];
247
+ const expose = model.Expose;
248
+ // Skip if not exposed or not included
249
+ if (!expose || !this.parameters.isIncluded(model.getIdentifier())) {
250
+ continue;
251
+ }
252
+ const shortId = model.getIdentifier(true);
253
+ // Overlap object are hidden by design
254
+ if (shortId.includes("/")) {
255
+ continue;
256
+ }
257
+ const plurial = app.getModelPlural(model.getIdentifier(false));
258
+ const modelSchema = modelKey;
259
+ ["create", "update"]
260
+ .filter(k => !expose.restrict[k])
261
+ .forEach(k => {
262
+ k = k.substring(0, 1).toUpperCase() + k.substring(1);
263
+ const id = `${shortId}.${k}`;
264
+ this.getWebda().registerOperation(id, {
265
+ service: this.getName(),
266
+ method: k === "Create" ? "modelCreate" : "modelUpdate",
267
+ input: modelSchema,
268
+ output: modelSchema,
269
+ parameters: k === "Create" ? undefined : "uuidRequest",
270
+ context: {
271
+ model
436
272
  }
437
- },
438
- responses: {
439
- "200": {
440
- description: "Operation success",
441
- content: {
442
- "application/json": {
443
- schema: {
444
- $ref: `#/components/schemas/${model.getIdentifier()}`
445
- }
446
- }
447
- }
448
- },
449
- "400": {
450
- description: "Invalid input"
451
- },
452
- "403": {
453
- description: "You don't have permissions"
454
- },
455
- "409": {
456
- description: "Object already exists"
273
+ });
274
+ });
275
+ ["delete", "get"]
276
+ .filter(k => !expose.restrict[k])
277
+ .forEach(k => {
278
+ k = k.substring(0, 1).toUpperCase() + k.substring(1);
279
+ const id = `${shortId}.${k}`;
280
+ const info = {
281
+ service: this.getName(),
282
+ method: `model${k}`,
283
+ id,
284
+ parameters: "uuidRequest",
285
+ context: {
286
+ model
457
287
  }
288
+ };
289
+ if (k === "Get") {
290
+ info.output = modelSchema;
458
291
  }
459
- }
460
- };
461
- model.Expose.restrict.create ||
462
- this.addRoute(`${prefix}`, ["POST"], injector(model.store(), "operationCreate", "SET", model.getIdentifier()), openapi);
463
- openapi = {
464
- delete: {
465
- tags: [name],
466
- operationId: `delete${name}`,
467
- description: `Delete ${name} if the permissions allow`,
468
- summary: `Delete a ${name}`,
469
- responses: {
470
- "204": {
471
- description: "Operation success"
472
- },
473
- "403": {
474
- description: "You don't have permissions"
475
- },
476
- "404": {
477
- description: "Unknown object"
292
+ this.getWebda().registerOperation(id, info);
293
+ });
294
+ if (!expose.restrict.query) {
295
+ const id = `${plurial}.Query`;
296
+ this.getWebda().registerOperation(id, {
297
+ service: this.getName(),
298
+ method: "modelQuery",
299
+ parameters: "searchRequest",
300
+ context: {
301
+ model
478
302
  }
479
- }
303
+ });
480
304
  }
481
- };
482
- model.Expose.restrict.delete ||
483
- this.addRoute(`${prefix}/{uuid}`, ["DELETE"], injector(model.store(), "httpDelete", "DELETE"), openapi);
484
- let openapiInfo = {
485
- tags: [name],
486
- operationId: `update${name}`,
487
- description: `Update ${name} if the permissions allow`,
488
- summary: `Update a ${name}`,
489
- requestBody: {
490
- content: {
491
- "application/json": {
492
- schema: {
493
- $ref: `#/components/schemas/${model.getIdentifier()}`
494
- }
305
+ // Add patch
306
+ if (!expose.restrict.update) {
307
+ const id = `${shortId}.Patch`;
308
+ this.getWebda().registerOperation(id, {
309
+ service: this.getName(),
310
+ method: "modelPatch",
311
+ input: modelSchema + "?",
312
+ parameters: "uuidRequest",
313
+ context: {
314
+ model
495
315
  }
496
- }
497
- },
498
- responses: {
499
- "204": {
500
- description: "Operation success"
316
+ });
317
+ }
318
+ // Add all operations for Actions
319
+ const actions = model.getActions();
320
+ Object.keys(actions).forEach(name => {
321
+ const id = `${shortId}.${name.substring(0, 1).toUpperCase() + name.substring(1)}`;
322
+ const info = {
323
+ service: this.getName(),
324
+ method: `modelAction`,
325
+ id
326
+ };
327
+ info.input = `${modelKey}.${name}.input`;
328
+ info.output = `${modelKey}.${name}.output`;
329
+ info.parameters = actions[name].global ? undefined : "uuidRequest";
330
+ info.context = {
331
+ model,
332
+ action: { ...actions[name], name }
333
+ };
334
+ this.getWebda().registerOperation(id, info);
335
+ });
336
+ this.addBinaryOperations(model, shortId);
337
+ }
338
+ }
339
+ addBinaryOperations(model, name) {
340
+ (model.getRelations().binaries || []).forEach(binary => {
341
+ const webda = Core.get();
342
+ const attribute = binary.attribute.substring(0, 1).toUpperCase() + binary.attribute.substring(1);
343
+ const info = {
344
+ service: this.getName(),
345
+ context: {
346
+ model,
347
+ binary,
348
+ binaryStore: this.getWebda().getBinaryStore(model, binary.attribute)
501
349
  },
502
- "400": {
503
- description: "Invalid input"
350
+ parameters: "uuidRequest"
351
+ };
352
+ webda.registerOperation(`${name}.${attribute}.AttachChallenge`, {
353
+ ...info,
354
+ method: "binaryChallenge",
355
+ input: "binaryChallengeRequest"
356
+ });
357
+ webda.registerOperation(`${name}.${attribute}.Attach`, {
358
+ ...info,
359
+ context: {
360
+ ...info.context,
361
+ action: "create"
504
362
  },
505
- "403": {
506
- description: "You don't have permissions"
363
+ method: "binaryPut",
364
+ parameters: "binaryAttachParameters"
365
+ });
366
+ webda.registerOperation(`${name}.${attribute}.Get`, {
367
+ ...info,
368
+ method: "binaryGet",
369
+ parameters: binary.cardinality === "ONE" ? "uuidRequest" : "binaryGetRequest"
370
+ });
371
+ webda.registerOperation(`${name}.${attribute}.Delete`, {
372
+ ...info,
373
+ context: {
374
+ ...info.context,
375
+ action: "delete"
507
376
  },
508
- "404": {
509
- description: "Unknown object"
510
- }
511
- }
512
- };
513
- openapi = {
514
- put: openapiInfo,
515
- patch: openapiInfo
516
- };
517
- model.Expose.restrict.update ||
518
- this.addRoute(`${prefix}/{uuid}`, ["PUT", "PATCH"], injector(model.store(), "httpUpdate", "SET"), openapi);
519
- openapi = {
520
- get: {
521
- tags: [name],
522
- description: `Retrieve ${name} model if permissions allow`,
523
- summary: `Retrieve a ${name}`,
524
- operationId: `get${name}`,
525
- responses: {
526
- "200": {
527
- content: {
528
- "application/json": {
529
- schema: {
530
- $ref: `#/components/schemas/${model.getIdentifier()}`
531
- }
532
- }
533
- }
534
- },
535
- "400": {
536
- description: "Object is invalid"
537
- },
538
- "403": {
539
- description: "You don't have permissions"
540
- },
541
- "404": {
542
- description: "Unknown object"
543
- }
544
- }
545
- }
546
- };
547
- model.Expose.restrict.get ||
548
- this.addRoute(`${prefix}/{uuid}`, ["GET"], injector(model.store(), "httpGet", "GET"), openapi);
549
- // Add all actions
550
- // Actions cannot be restricted as its purpose is to be exposed
551
- let actions = model.getActions();
552
- Object.keys(actions).forEach(actionName => {
553
- let action = actions[actionName];
554
- openapi = {
555
- ...action.openapi
556
- };
557
- (action.methods || ["PUT"]).forEach(method => {
558
- openapi[method.toLowerCase()] = {
559
- tags: [name],
560
- ...(action.openapi?.[method.toLowerCase()] ?? {})
561
- };
377
+ method: "binaryAction",
378
+ parameters: binary.cardinality === "ONE" ? "binaryHashRequest" : "binaryIndexHashRequest"
379
+ });
380
+ webda.registerOperation(`${name}.${attribute}.SetMetadata`, {
381
+ ...info,
382
+ context: {
383
+ ...info.context,
384
+ action: "metadata"
385
+ },
386
+ method: "binaryAction",
387
+ parameters: binary.cardinality === "ONE" ? "binaryHashRequest" : "binaryIndexHashRequest"
388
+ });
389
+ webda.registerOperation(`${name}.${attribute}.GetUrl`, {
390
+ ...info,
391
+ context: {
392
+ ...info.context,
393
+ returnUrl: true
394
+ },
395
+ method: "binaryGet",
396
+ parameters: binary.cardinality === "ONE" ? "uuidRequest" : "binaryGetRequest"
562
397
  });
563
- if (app.hasSchema(`${model.getIdentifier(false)}.${actionName}.input`)) {
564
- Object.keys(openapi)
565
- .filter(k => ["get", "post", "put", "patch", "delete"].includes(k))
566
- .forEach(k => {
567
- openapi[k].requestBody = {
568
- content: {
569
- "application/json": {
570
- schema: {
571
- $ref: `#/components/schemas/${model.getIdentifier(false)}.${actionName}.input`
572
- }
573
- }
574
- }
575
- };
398
+ });
399
+ }
400
+ /**
401
+ * Implement the binary challenge operation
402
+ * @param context
403
+ */
404
+ async binaryChallenge(context) {
405
+ const body = await context.getInput();
406
+ const { model, binaryStore, binary } = context.getExtension("operationContext");
407
+ // First verify if map exist
408
+ const object = await model.ref(context.parameter("uuid")).get();
409
+ if (object === undefined || object.isDeleted()) {
410
+ throw new WebdaError.NotFound("Object does not exist");
411
+ }
412
+ if (this.checkBinaryAlreadyLinked(object[binary.attribute], body.hash)) {
413
+ return;
414
+ }
415
+ await object.checkAct(context, "attach_binary");
416
+ const url = await binaryStore.putRedirectUrl(object, binary.attribute, body, context);
417
+ const base64String = Buffer.from(body.hash, "hex").toString("base64");
418
+ context.write({
419
+ ...url,
420
+ done: url === undefined,
421
+ md5: base64String
422
+ });
423
+ }
424
+ /**
425
+ *
426
+ * @param property
427
+ * @param hash
428
+ * @returns
429
+ */
430
+ checkBinaryAlreadyLinked(property, hash) {
431
+ if (Array.isArray(property)) {
432
+ return property.find(f => f.hash === hash) !== undefined;
433
+ }
434
+ return property && property.hash === hash;
435
+ }
436
+ /**
437
+ * Set the binary content
438
+ * @param context
439
+ */
440
+ async binaryPut(context) {
441
+ const { model, binaryStore, binary } = context.getExtension("operationContext");
442
+ // First verify if map exist
443
+ const object = await model.ref(context.parameter("uuid")).get();
444
+ if (object === undefined || object.isDeleted()) {
445
+ throw new WebdaError.NotFound("Object does not exist");
446
+ }
447
+ const file = await binaryStore.getFile(context);
448
+ const { hash } = await file.getHashes();
449
+ if (this.checkBinaryAlreadyLinked(object[binary.attribute], hash)) {
450
+ return;
451
+ }
452
+ await object.checkAct(context, "attach_binary");
453
+ await binaryStore.store(object, binary.attribute, file);
454
+ }
455
+ /**
456
+ * Get the binary content
457
+ * @param context
458
+ */
459
+ async binaryGet(context) {
460
+ const { model, returnUrl, binaryStore, binary } = context.getExtension("operationContext");
461
+ const { index, uuid } = context.getParameters();
462
+ // First verify if map exist
463
+ const object = await model.ref(uuid).get();
464
+ if (object === undefined || object.isDeleted()) {
465
+ throw new WebdaError.NotFound("Object does not exist");
466
+ }
467
+ const property = binary.attribute;
468
+ if (!object || (Array.isArray(object[property]) && object[property].length <= index)) {
469
+ throw new WebdaError.NotFound("Object does not exist or attachment does not exist");
470
+ }
471
+ await object.checkAct(context, "get_binary");
472
+ const file = Array.isArray(object[property]) ? object[property][index] : object[property];
473
+ const url = await binaryStore.getRedirectUrlFromObject(file, context);
474
+ // No url, we return the file
475
+ if (url === null) {
476
+ if (returnUrl) {
477
+ // Redirect to same url without /url
478
+ context.write({
479
+ Location: context
480
+ .getHttpContext()
481
+ .getAbsoluteUrl()
482
+ .replace(/\/url$/, ""),
483
+ Map: file
576
484
  });
577
485
  }
578
- if (app.hasSchema(`${model.getIdentifier(false)}.${actionName}.output`)) {
579
- Object.keys(openapi)
580
- .filter(k => ["get", "post", "put", "patch", "delete"].includes(k))
581
- .forEach(k => {
582
- var _a, _b;
583
- (_a = openapi[k]).responses ?? (_a.responses = {});
584
- (_b = openapi[k].responses)["200"] ?? (_b["200"] = {});
585
- openapi[k].responses["200"].content = {
586
- "application/json": {
587
- schema: {
588
- $ref: `#/components/schemas/${model.getIdentifier(false)}.${actionName}.output`
589
- }
590
- }
591
- };
486
+ else {
487
+ // Output
488
+ context.writeHead(200, {
489
+ "Content-Type": file.mimetype === undefined ? "application/octet-steam" : file.mimetype,
490
+ "Content-Length": file.size
491
+ });
492
+ const readStream = await binaryStore.get(file);
493
+ await new Promise((resolve, reject) => {
494
+ // We replaced all the event handlers with a simple call to readStream.pipe()
495
+ context._stream.on("finish", resolve);
496
+ context._stream.on("error", reject);
497
+ readStream.pipe(context._stream);
592
498
  });
593
499
  }
594
- this.addRoute(action.global ? `${prefix}/${actionName}` : `${prefix}/{uuid}/${actionName}`, action.methods || ["PUT"], async (ctx) => {
595
- if (action.global) {
596
- return model.store().httpGlobalAction(ctx, model);
597
- }
598
- else {
599
- ctx.getParameters().uuid = model.completeUid(ctx.getParameters().uuid);
600
- return model.store().httpAction(ctx, action.method);
601
- }
602
- }, openapi);
603
- });
604
- /*
605
- Binaries should expose several methods
606
- If cardinality is ONE
607
- GET to download the binary
608
- POST to upload a binary directly
609
- PUT to upload a binary with challenge
610
- DELETE /{hash} to delete a binary
611
- PUT /{hash} to update metadata
612
- GET /url to get a signed url
613
-
614
- If cardinality is MANY
615
- GET /{index} to download the binary
616
- GET /{index}/url to get a signed url
617
- POST to upload a binary directly
618
- PUT to upload a binary with challenge
619
- DELETE /{index}/{hash} to delete a binary
620
- PUT /{index}/{hash} to update metadata
621
- */
622
- (relations.binaries || []).forEach(binary => {
623
- const store = Core.get().getBinaryStore(model, binary.attribute);
624
- const modelInjector = async (ctx) => {
625
- ctx.getParameters().model = model.getIdentifier();
626
- ctx.getParameters().property = binary.attribute;
627
- await store.httpRoute(ctx);
628
- };
629
- const modelInjectorChallenge = async (ctx) => {
630
- ctx.getParameters().model = model.getIdentifier();
631
- ctx.getParameters().property = binary.attribute;
632
- await store.httpChallenge(ctx);
633
- };
634
- const modelInjectorGet = async (ctx) => {
635
- ctx.getParameters().model = model.getIdentifier();
636
- ctx.getParameters().property = binary.attribute;
637
- await store.httpGet(ctx);
638
- };
639
- openapi = {
640
- put: {
641
- tags: [name],
642
- summary: `Upload ${binary.attribute} of ${name} after challenge`,
643
- description: `You will need to call the challenge method first to get a signed url to upload the content\nIf the data is already known then done is returned`,
644
- operationId: `upload${name}${binary.attribute}`,
645
- requestBody: {
646
- content: {
647
- "application/octet-stream": {
648
- schema: {
649
- type: "object",
650
- required: ["hash", "challenge"],
651
- properties: {
652
- hash: {
653
- type: "string",
654
- description: "md5(data)"
655
- },
656
- challenge: {
657
- type: "string",
658
- description: "md5('Webda' + data)"
659
- },
660
- size: {
661
- type: "number",
662
- description: "Size of the data"
663
- },
664
- name: {
665
- type: "string",
666
- description: "Name of the file"
667
- },
668
- mimetype: {
669
- type: "string",
670
- description: "Mimetype of the file"
671
- },
672
- metadata: {
673
- type: "object",
674
- description: "Metadata to add to the binary"
675
- }
676
- }
677
- }
678
- }
679
- }
680
- },
681
- responses: {
682
- "200": {
683
- description: "Operation success",
684
- content: {
685
- "application/octet-stream": {
686
- schema: {
687
- type: "object",
688
- properties: {
689
- done: {
690
- type: "boolean"
691
- },
692
- url: {
693
- type: "string"
694
- },
695
- method: {
696
- type: "string"
697
- },
698
- md5: {
699
- type: "string",
700
- description: "base64 md5 of the data\nThe next request requires Content-MD5 to be added with this one along with Content-Type: 'application/octet-stream'"
701
- }
702
- }
703
- }
704
- }
705
- }
706
- },
707
- "403": {
708
- description: "You don't have permissions"
709
- },
710
- "404": {
711
- description: "Unknown object"
712
- }
713
- }
714
- }
715
- };
716
- this.addRoute(`${prefix}/{uuid}/${binary.attribute}`, ["PUT"], modelInjectorChallenge, openapi);
717
- openapi = {
718
- post: {
719
- tags: [name],
720
- summary: `Upload ${binary.attribute} of ${name} directly`,
721
- description: `You can upload the content directly to the server\nThis is not the recommended way as it wont be able to optimize network traffic`,
722
- operationId: `upload${name}${binary.attribute}`,
723
- requestBody: {
724
- content: {
725
- "application/octet-stream": {
726
- schema: {
727
- type: "string",
728
- format: "binary"
729
- }
730
- }
731
- }
732
- },
733
- responses: {
734
- "204": {
735
- description: ""
736
- },
737
- "403": {
738
- description: "You don't have permissions"
739
- },
740
- "404": {
741
- description: "Object does not exist or attachment does not exist"
742
- }
743
- }
744
- }
745
- };
746
- this.addRoute(`${prefix}/{uuid}/${binary.attribute}`, ["POST"], modelInjector, openapi);
747
- let rootUrl = `${prefix}/{uuid}/${binary.attribute}`;
748
- if (binary.cardinality === "MANY") {
749
- rootUrl += "/{index}";
500
+ }
501
+ else if (returnUrl) {
502
+ context.write({ Location: url, Map: file });
503
+ }
504
+ else {
505
+ context.writeHead(302, {
506
+ Location: url
507
+ });
508
+ }
509
+ }
510
+ async binaryAction(context) {
511
+ const { model, binaryStore, binary, action } = context.getExtension("operationContext");
512
+ const { index, uuid, hash } = context.getParameters();
513
+ // First verify if map exist
514
+ const object = await model.ref(uuid).get();
515
+ if (object === undefined || object.isDeleted()) {
516
+ throw new WebdaError.NotFound("Object does not exist");
517
+ }
518
+ if (action === "create") {
519
+ await object.checkAct(context, "attach_binary");
520
+ await binaryStore.store(object, binary.attribute, await binaryStore.getFile(context));
521
+ return;
522
+ }
523
+ // Current file - would be empty on creation
524
+ const file = Array.isArray(object[binary.attribute]) ? object[binary.attribute][index] : object[binary.attribute];
525
+ if (!file || file?.hash !== hash) {
526
+ throw new WebdaError.BadRequest("Hash does not match");
527
+ }
528
+ if (action === "delete") {
529
+ await object.checkAct(context, "detach_binary");
530
+ await binaryStore.delete(object, binary.attribute, index);
531
+ }
532
+ else if (action === "metadata") {
533
+ await object.checkAct(context, "update_binary_metadata");
534
+ const metadata = await context.getInput();
535
+ // Limit metadata to 4kb
536
+ if (JSON.stringify(metadata).length >= 4096) {
537
+ throw new WebdaError.BadRequest("Metadata is too big: 4kb max");
750
538
  }
751
- openapi = {
752
- get: {
753
- tags: [name],
754
- summary: `Download ${binary.attribute} of ${name}`,
755
- operationId: `download${name}${binary.attribute}`,
756
- responses: {
757
- "200": {
758
- description: "Operation success",
759
- content: {
760
- "application/octet-stream": {
761
- schema: {
762
- type: "string",
763
- format: "binary"
764
- }
765
- }
766
- }
767
- },
768
- "302": {
769
- description: "Redirect to the binary"
770
- },
771
- "403": {
772
- description: "You don't have permissions"
773
- },
774
- "404": {
775
- description: "Unknown object"
776
- }
777
- }
778
- }
779
- };
780
- this.addRoute(`${rootUrl}`, ["GET"], modelInjectorGet, openapi);
781
- openapi = {
782
- delete: {
783
- tags: [name],
784
- summary: `Delete ${binary.attribute} of ${name}`,
785
- responses: {
786
- "204": {
787
- description: ""
788
- },
789
- "403": {
790
- description: "You don't have permissions"
791
- },
792
- "404": {
793
- description: "Object does not exist or attachment does not exist"
794
- },
795
- "412": {
796
- description: "Provided hash does not match"
797
- }
798
- }
799
- }
800
- };
801
- this.addRoute(`${rootUrl}/{hash}`, ["DELETE"], modelInjector, openapi);
802
- openapi = {
803
- put: {
804
- tags: [name],
805
- summary: `Update metadata of ${binary.attribute} of ${name}`,
806
- operationId: `update${name}${binary.attribute}`,
807
- requestBody: {
808
- content: {
809
- "application/json": {
810
- schema: {
811
- type: "object",
812
- description: "Metadata to add to the binary",
813
- additionalProperties: true
814
- }
815
- }
816
- }
817
- },
818
- responses: {
819
- "204": {
820
- description: ""
821
- },
822
- "400": {
823
- description: "Invalid input: metadata are limited to 4kb"
824
- },
825
- "403": {
826
- description: "You don't have permissions"
827
- },
828
- "404": {
829
- description: "Object does not exist or attachment does not exist"
830
- },
831
- "412": {
832
- description: "Provided hash does not match"
833
- }
834
- }
835
- }
836
- };
837
- this.addRoute(`${rootUrl}/{hash}`, ["PUT"], modelInjector, openapi);
838
- openapi = {
839
- get: {
840
- tags: [name],
841
- summary: `Get a signed url to download ${binary.attribute} of ${name} with a limited lifetime`,
842
- responses: {
843
- "200": {
844
- description: "Operation success",
845
- content: {
846
- "application/json": {
847
- schema: {
848
- type: "object",
849
- properties: {
850
- Location: {
851
- type: "string",
852
- description: "Signed url to download the binary"
853
- },
854
- Map: {
855
- $ref: "#/components/schemas/BinaryMap"
856
- }
857
- }
858
- }
859
- }
860
- }
861
- },
862
- "403": {
863
- description: "You don't have permissions"
864
- },
865
- "404": {
866
- description: "Object does not exist or attachment does not exist"
867
- }
868
- }
869
- }
870
- };
871
- this.addRoute(`${rootUrl}/url`, ["GET"], modelInjectorGet, openapi);
872
- });
873
- return true;
539
+ file.metadata = metadata;
540
+ await object.patch({
541
+ [binary.attribute]: object[binary.attribute]
542
+ });
543
+ }
544
+ }
545
+ }
546
+ DomainService.schemas = {
547
+ uuidRequest: {
548
+ type: "object",
549
+ properties: {
550
+ uuid: {
551
+ type: "string"
552
+ }
553
+ },
554
+ required: ["uuid"]
555
+ },
556
+ binaryGetRequest: {
557
+ type: "object",
558
+ properties: {
559
+ uuid: {
560
+ type: "string"
561
+ },
562
+ index: {
563
+ type: "number"
564
+ }
565
+ },
566
+ required: ["uuid", "index"]
567
+ },
568
+ binaryHashRequest: {
569
+ type: "object",
570
+ properties: {
571
+ uuid: {
572
+ type: "string"
573
+ },
574
+ hash: {
575
+ type: "string"
576
+ }
577
+ },
578
+ required: ["uuid", "hash"]
579
+ },
580
+ binaryIndexHashRequest: {
581
+ type: "object",
582
+ properties: {
583
+ uuid: {
584
+ type: "string"
585
+ },
586
+ index: {
587
+ type: "number"
588
+ },
589
+ hash: {
590
+ type: "string"
591
+ }
592
+ },
593
+ required: ["uuid", "index", "hash"]
594
+ },
595
+ binaryAttachParameters: {
596
+ type: "object",
597
+ properties: {
598
+ filename: {
599
+ type: "string"
600
+ },
601
+ size: {
602
+ type: "number"
603
+ },
604
+ mimetype: {
605
+ type: "string"
606
+ },
607
+ uuid: {
608
+ type: "string"
609
+ }
610
+ },
611
+ required: ["uuid"]
612
+ },
613
+ binaryChallengeRequest: {
614
+ type: "object",
615
+ properties: {
616
+ hash: {
617
+ type: "string"
618
+ },
619
+ challenge: {
620
+ type: "string"
621
+ }
622
+ },
623
+ required: ["hash", "challenge"]
624
+ },
625
+ searchRequest: {
626
+ type: "object",
627
+ properties: {
628
+ query: {
629
+ type: "string"
630
+ }
631
+ }
632
+ }
633
+ };
634
+ /**
635
+ * @WebdaModda
636
+ */
637
+ export class ModelsOperationsService extends DomainService {
638
+ /**
639
+ * Default domain
640
+ */
641
+ loadParameters(params) {
642
+ return new DomainServiceParameters(params);
874
643
  }
875
644
  /**
876
- * Serve the openapi with the swagger-ui
877
- * @param ctx
645
+ * Do nothing here
878
646
  */
879
- async openapi(ctx) {
880
- this.openapiContent ?? (this.openapiContent = swagger.replace("{{OPENAPI}}", JSON.stringify(this.getWebda().exportOpenAPI(true))));
881
- ctx.write(this.openapiContent);
647
+ handleModel(model, name, context) {
648
+ return true;
882
649
  }
883
650
  }
884
651
  //# sourceMappingURL=domainservice.js.map