@webda/core 4.0.0-beta.1 → 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 (431) hide show
  1. package/lib/application.d.ts +20 -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 +14 -11
  10. package/lib/core.d.ts.map +1 -0
  11. package/lib/core.js +101 -77
  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 -2
  26. package/lib/index.d.ts.map +1 -0
  27. package/lib/index.js +6 -2
  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 +10 -1
  38. package/lib/models/coremodel.d.ts.map +1 -0
  39. package/lib/models/coremodel.js +33 -27
  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 +3 -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 -85
  152. package/lib/services/binary.d.ts.map +1 -0
  153. package/lib/services/binary.js +38 -407
  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 -750
  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 +222 -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 +132 -119
  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 +16 -1
  270. package/lib/services/resource.d.ts.map +1 -0
  271. package/lib/services/resource.js +17 -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 +2 -1
  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 +1 -0
  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 +117 -182
  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 +3 -144
  318. package/lib/stores/store.d.ts.map +1 -0
  319. package/lib/stores/store.js +53 -653
  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 +89 -258
  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 +10 -2
  330. package/lib/unpackedapplication.d.ts.map +1 -0
  331. package/lib/unpackedapplication.js +81 -30
  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 +48 -41
  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 +25 -14
  348. package/lib/utils/context.spec.js.map +1 -1
  349. package/lib/utils/cookie.d.ts +3 -2
  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 +1 -0
  374. package/lib/utils/serializers.d.ts.map +1 -0
  375. package/lib/utils/serializers.js +8 -8
  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 +6 -8
  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 +2 -2
  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 +658 -408
  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/test/config-file-missing-file-no-default.json +0 -44
  419. package/test/config-file-missing-file.json +0 -55
  420. package/test/config-file-no-reload.json +0 -69
  421. package/test/config-file-reload.json +0 -68
  422. package/test/config-invitation.json +0 -63
  423. package/test/config-kube-reload.json +0 -68
  424. package/test/config-reload.json +0 -66
  425. package/test/config.old.json +0 -152
  426. package/test/moddas/annotatedservice.js +0 -23
  427. package/test/moddas/debugmailer.js +0 -13
  428. package/test/moddas/fakeservice.js +0 -4
  429. package/test/moddas/voidstore.js +0 -66
  430. package/test/models/ident.js +0 -36
  431. package/test/models/task.js +0 -42
@@ -1,128 +1,5 @@
1
- import { Core, JSONUtils, Service, ServiceParameters } 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,624 +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 = q ? ` AND (${q})` : "";
327
- if (injectAttribute) {
328
- query = ` AND ${injectAttribute} = "${context.getPathParameters()[parentId]}"` + query;
329
- }
330
- if (args[0] !== 0) {
331
- query = `__types CONTAINS "${model.getIdentifier()}"` + query;
332
- }
333
- else if (query.startsWith(" AND ")) {
334
- query = query.substring(5);
335
- }
336
- if (context.getHttpContext().getMethod() === "GET") {
337
- context.getParameters().q = query;
338
- }
339
- else {
340
- input.q = query;
341
- }
342
- this.log("TRACE", `Query modified to '${query}' from '${q}' ${args[0]}`);
343
- }
344
- // Complete the uuid if needed
345
- if (context.getParameters().uuid) {
346
- context.getParameters().uuid = model.completeUid(context.getParameters().uuid);
347
- }
348
- await service[method](context, ...args);
349
- };
350
- };
351
- // Update prefix
352
- const prefix = (context.prefix || (this.parameters.url.endsWith("/") ? this.parameters.url : this.parameters.url + "/")) +
353
- this.transformName(name);
354
- context.prefix = prefix + `/{pid.${depth}}/`;
355
- // Register the model url
356
- this.getWebda().getRouter().registerModelUrl(app.getModelName(model), prefix);
357
- let openapi = {
358
- [this.parameters.queryMethod.toLowerCase()]: {
359
- tags: [name],
360
- summary: `Query ${name}`,
361
- operationId: `query${name}`,
362
- requestBody: this.parameters.queryMethod === "GET"
363
- ? undefined
364
- : {
365
- content: {
366
- "application/json": {
367
- schema: {
368
- properties: {
369
- q: {
370
- type: "string"
371
- }
372
- }
373
- }
374
- }
375
- }
376
- },
377
- parameters: this.parameters.queryMethod === "GET"
378
- ? [
379
- {
380
- name: "q",
381
- in: "query",
382
- description: "Query to execute",
383
- schema: {
384
- type: "string"
385
- }
386
- }
387
- ]
388
- : [],
389
- responses: {
390
- "200": {
391
- description: "Operation success",
392
- content: {
393
- "application/json": {
394
- schema: {
395
- properties: {
396
- continuationToken: {
397
- type: "string"
398
- },
399
- results: {
400
- type: "array",
401
- items: {
402
- $ref: `#/components/schemas/${model.getIdentifier()}`
403
- }
404
- }
405
- }
406
- }
407
- }
408
- }
409
- },
410
- "400": {
411
- description: "Query is invalid"
412
- },
413
- "403": {
414
- description: "You don't have permissions"
415
- }
416
- }
237
+ // Add default schemas - used for operation parameters
238
+ for (const i in ModelsOperationsService.schemas) {
239
+ if (app.hasSchema(i)) {
240
+ continue;
417
241
  }
418
- };
419
- model.Expose.restrict.query ||
420
- this.addRoute(`${prefix}${this.parameters.queryMethod === "GET" ? "{?q?}" : ""}`, [this.parameters.queryMethod], injector(model.store(), "httpQuery", "QUERY", model.store().handleModel(model)), openapi);
421
- openapi = {
422
- post: {
423
- tags: [name],
424
- summary: `Create ${name}`,
425
- operationId: `create${name}`,
426
- requestBody: {
427
- content: {
428
- "application/json": {
429
- schema: {
430
- $ref: `#/components/schemas/${model.getIdentifier()}`
431
- }
432
- }
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
433
272
  }
434
- },
435
- responses: {
436
- "200": {
437
- description: "Operation success",
438
- content: {
439
- "application/json": {
440
- schema: {
441
- $ref: `#/components/schemas/${model.getIdentifier()}`
442
- }
443
- }
444
- }
445
- },
446
- "400": {
447
- description: "Invalid input"
448
- },
449
- "403": {
450
- description: "You don't have permissions"
451
- },
452
- "409": {
453
- 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
454
287
  }
288
+ };
289
+ if (k === "Get") {
290
+ info.output = modelSchema;
455
291
  }
456
- }
457
- };
458
- model.Expose.restrict.create ||
459
- this.addRoute(`${prefix}`, ["POST"], injector(model.store(), "operationCreate", "SET", model.getIdentifier()), openapi);
460
- openapi = {
461
- delete: {
462
- tags: [name],
463
- operationId: `delete${name}`,
464
- description: `Delete ${name} if the permissions allow`,
465
- summary: `Delete a ${name}`,
466
- responses: {
467
- "204": {
468
- description: "Operation success"
469
- },
470
- "403": {
471
- description: "You don't have permissions"
472
- },
473
- "404": {
474
- 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
475
302
  }
476
- }
303
+ });
477
304
  }
478
- };
479
- model.Expose.restrict.delete ||
480
- this.addRoute(`${prefix}/{uuid}`, ["DELETE"], injector(model.store(), "httpDelete", "DELETE"), openapi);
481
- let openapiInfo = {
482
- tags: [name],
483
- operationId: `update${name}`,
484
- description: `Update ${name} if the permissions allow`,
485
- summary: `Update a ${name}`,
486
- requestBody: {
487
- content: {
488
- "application/json": {
489
- schema: {
490
- $ref: `#/components/schemas/${model.getIdentifier()}`
491
- }
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
492
315
  }
493
- }
494
- },
495
- responses: {
496
- "204": {
497
- 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)
498
349
  },
499
- "400": {
500
- 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"
501
362
  },
502
- "403": {
503
- 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"
504
376
  },
505
- "404": {
506
- description: "Unknown object"
507
- }
508
- }
509
- };
510
- openapi = {
511
- put: openapiInfo,
512
- patch: openapiInfo
513
- };
514
- model.Expose.restrict.update ||
515
- this.addRoute(`${prefix}/{uuid}`, ["PUT", "PATCH"], injector(model.store(), "httpUpdate", "SET"), openapi);
516
- openapi = {
517
- get: {
518
- tags: [name],
519
- description: `Retrieve ${name} model if permissions allow`,
520
- summary: `Retrieve a ${name}`,
521
- operationId: `get${name}`,
522
- responses: {
523
- "200": {
524
- content: {
525
- "application/json": {
526
- schema: {
527
- $ref: `#/components/schemas/${model.getIdentifier()}`
528
- }
529
- }
530
- }
531
- },
532
- "400": {
533
- description: "Object is invalid"
534
- },
535
- "403": {
536
- description: "You don't have permissions"
537
- },
538
- "404": {
539
- description: "Unknown object"
540
- }
541
- }
542
- }
543
- };
544
- model.Expose.restrict.get ||
545
- this.addRoute(`${prefix}/{uuid}`, ["GET"], injector(model.store(), "httpGet", "GET"), openapi);
546
- // Add all actions
547
- // Actions cannot be restricted as its purpose is to be exposed
548
- let actions = model.getActions();
549
- Object.keys(actions).forEach(actionName => {
550
- let action = actions[actionName];
551
- openapi = {
552
- ...action.openapi
553
- };
554
- (action.methods || ["PUT"]).forEach(method => {
555
- openapi[method.toLowerCase()] = {
556
- tags: [name],
557
- ...(action.openapi?.[method.toLowerCase()] ?? {})
558
- };
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"
559
397
  });
560
- if (app.hasSchema(`${model.getIdentifier(false)}.${actionName}.input`)) {
561
- Object.keys(openapi)
562
- .filter(k => ["get", "post", "put", "patch", "delete"].includes(k))
563
- .forEach(k => {
564
- openapi[k].requestBody = {
565
- content: {
566
- "application/json": {
567
- schema: {
568
- $ref: `#/components/schemas/${model.getIdentifier(false)}.${actionName}.input`
569
- }
570
- }
571
- }
572
- };
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
573
484
  });
574
485
  }
575
- if (app.hasSchema(`${model.getIdentifier(false)}.${actionName}.output`)) {
576
- Object.keys(openapi)
577
- .filter(k => ["get", "post", "put", "patch", "delete"].includes(k))
578
- .forEach(k => {
579
- var _a, _b;
580
- (_a = openapi[k]).responses ?? (_a.responses = {});
581
- (_b = openapi[k].responses)["200"] ?? (_b["200"] = {});
582
- openapi[k].responses["200"].content = {
583
- "application/json": {
584
- schema: {
585
- $ref: `#/components/schemas/${model.getIdentifier(false)}.${actionName}.output`
586
- }
587
- }
588
- };
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);
589
498
  });
590
499
  }
591
- this.addRoute(action.global ? `${prefix}/${actionName}` : `${prefix}/{uuid}/${actionName}`, action.methods || ["PUT"], async (ctx) => {
592
- if (action.global) {
593
- return model.store().httpGlobalAction(ctx, model);
594
- }
595
- else {
596
- ctx.getParameters().uuid = model.completeUid(ctx.getParameters().uuid);
597
- return model.store().httpAction(ctx, action.method);
598
- }
599
- }, openapi);
600
- });
601
- /*
602
- Binaries should expose several methods
603
- If cardinality is ONE
604
- GET to download the binary
605
- POST to upload a binary directly
606
- PUT to upload a binary with challenge
607
- DELETE /{hash} to delete a binary
608
- PUT /{hash} to update metadata
609
- GET /url to get a signed url
610
-
611
- If cardinality is MANY
612
- GET /{index} to download the binary
613
- GET /{index}/url to get a signed url
614
- POST to upload a binary directly
615
- PUT to upload a binary with challenge
616
- DELETE /{index}/{hash} to delete a binary
617
- PUT /{index}/{hash} to update metadata
618
- */
619
- (relations.binaries || []).forEach(binary => {
620
- const store = Core.get().getBinaryStore(model, binary.attribute);
621
- const modelInjector = async (ctx) => {
622
- ctx.getParameters().model = model.getIdentifier();
623
- ctx.getParameters().property = binary.attribute;
624
- await store.httpRoute(ctx);
625
- };
626
- const modelInjectorChallenge = async (ctx) => {
627
- ctx.getParameters().model = model.getIdentifier();
628
- ctx.getParameters().property = binary.attribute;
629
- await store.httpChallenge(ctx);
630
- };
631
- const modelInjectorGet = async (ctx) => {
632
- ctx.getParameters().model = model.getIdentifier();
633
- ctx.getParameters().property = binary.attribute;
634
- await store.httpGet(ctx);
635
- };
636
- openapi = {
637
- put: {
638
- tags: [name],
639
- summary: `Upload ${binary.attribute} of ${name} after challenge`,
640
- 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`,
641
- operationId: `upload${name}${binary.attribute}`,
642
- requestBody: {
643
- content: {
644
- "application/octet-stream": {
645
- schema: {
646
- type: "object",
647
- required: ["hash", "challenge"],
648
- properties: {
649
- hash: {
650
- type: "string",
651
- description: "md5(data)"
652
- },
653
- challenge: {
654
- type: "string",
655
- description: "md5('Webda' + data)"
656
- },
657
- size: {
658
- type: "number",
659
- description: "Size of the data"
660
- },
661
- name: {
662
- type: "string",
663
- description: "Name of the file"
664
- },
665
- mimetype: {
666
- type: "string",
667
- description: "Mimetype of the file"
668
- },
669
- metadata: {
670
- type: "object",
671
- description: "Metadata to add to the binary"
672
- }
673
- }
674
- }
675
- }
676
- }
677
- },
678
- responses: {
679
- "200": {
680
- description: "Operation success",
681
- content: {
682
- "application/octet-stream": {
683
- schema: {
684
- type: "object",
685
- properties: {
686
- done: {
687
- type: "boolean"
688
- },
689
- url: {
690
- type: "string"
691
- },
692
- method: {
693
- type: "string"
694
- },
695
- md5: {
696
- type: "string",
697
- 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'"
698
- }
699
- }
700
- }
701
- }
702
- }
703
- },
704
- "403": {
705
- description: "You don't have permissions"
706
- },
707
- "404": {
708
- description: "Unknown object"
709
- }
710
- }
711
- }
712
- };
713
- this.addRoute(`${prefix}/{uuid}/${binary.attribute}`, ["PUT"], modelInjectorChallenge, openapi);
714
- openapi = {
715
- post: {
716
- tags: [name],
717
- summary: `Upload ${binary.attribute} of ${name} directly`,
718
- 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`,
719
- operationId: `upload${name}${binary.attribute}`,
720
- requestBody: {
721
- content: {
722
- "application/octet-stream": {
723
- schema: {
724
- type: "string",
725
- format: "binary"
726
- }
727
- }
728
- }
729
- },
730
- responses: {
731
- "204": {
732
- description: ""
733
- },
734
- "403": {
735
- description: "You don't have permissions"
736
- },
737
- "404": {
738
- description: "Object does not exist or attachment does not exist"
739
- }
740
- }
741
- }
742
- };
743
- this.addRoute(`${prefix}/{uuid}/${binary.attribute}`, ["POST"], modelInjector, openapi);
744
- let rootUrl = `${prefix}/{uuid}/${binary.attribute}`;
745
- if (binary.cardinality === "MANY") {
746
- 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");
747
538
  }
748
- openapi = {
749
- get: {
750
- tags: [name],
751
- summary: `Download ${binary.attribute} of ${name}`,
752
- operationId: `download${name}${binary.attribute}`,
753
- responses: {
754
- "200": {
755
- description: "Operation success",
756
- content: {
757
- "application/octet-stream": {
758
- schema: {
759
- type: "string",
760
- format: "binary"
761
- }
762
- }
763
- }
764
- },
765
- "302": {
766
- description: "Redirect to the binary"
767
- },
768
- "403": {
769
- description: "You don't have permissions"
770
- },
771
- "404": {
772
- description: "Unknown object"
773
- }
774
- }
775
- }
776
- };
777
- this.addRoute(`${rootUrl}`, ["GET"], modelInjectorGet, openapi);
778
- openapi = {
779
- delete: {
780
- tags: [name],
781
- summary: `Delete ${binary.attribute} of ${name}`,
782
- responses: {
783
- "204": {
784
- description: ""
785
- },
786
- "403": {
787
- description: "You don't have permissions"
788
- },
789
- "404": {
790
- description: "Object does not exist or attachment does not exist"
791
- },
792
- "412": {
793
- description: "Provided hash does not match"
794
- }
795
- }
796
- }
797
- };
798
- this.addRoute(`${rootUrl}/{hash}`, ["DELETE"], modelInjector, openapi);
799
- openapi = {
800
- put: {
801
- tags: [name],
802
- summary: `Update metadata of ${binary.attribute} of ${name}`,
803
- operationId: `update${name}${binary.attribute}`,
804
- requestBody: {
805
- content: {
806
- "application/json": {
807
- schema: {
808
- type: "object",
809
- description: "Metadata to add to the binary",
810
- additionalProperties: true
811
- }
812
- }
813
- }
814
- },
815
- responses: {
816
- "204": {
817
- description: ""
818
- },
819
- "400": {
820
- description: "Invalid input: metadata are limited to 4kb"
821
- },
822
- "403": {
823
- description: "You don't have permissions"
824
- },
825
- "404": {
826
- description: "Object does not exist or attachment does not exist"
827
- },
828
- "412": {
829
- description: "Provided hash does not match"
830
- }
831
- }
832
- }
833
- };
834
- this.addRoute(`${rootUrl}/{hash}`, ["PUT"], modelInjector, openapi);
835
- openapi = {
836
- get: {
837
- tags: [name],
838
- summary: `Get a signed url to download ${binary.attribute} of ${name} with a limited lifetime`,
839
- responses: {
840
- "200": {
841
- description: "Operation success",
842
- content: {
843
- "application/json": {
844
- schema: {
845
- type: "object",
846
- properties: {
847
- Location: {
848
- type: "string",
849
- description: "Signed url to download the binary"
850
- },
851
- Map: {
852
- $ref: "#/components/schemas/BinaryMap"
853
- }
854
- }
855
- }
856
- }
857
- }
858
- },
859
- "403": {
860
- description: "You don't have permissions"
861
- },
862
- "404": {
863
- description: "Object does not exist or attachment does not exist"
864
- }
865
- }
866
- }
867
- };
868
- this.addRoute(`${rootUrl}/url`, ["GET"], modelInjectorGet, openapi);
869
- });
870
- 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);
871
643
  }
872
644
  /**
873
- * Serve the openapi with the swagger-ui
874
- * @param ctx
645
+ * Do nothing here
875
646
  */
876
- async openapi(ctx) {
877
- this.openapiContent ?? (this.openapiContent = swagger.replace("{{OPENAPI}}", JSON.stringify(this.getWebda().exportOpenAPI(true))));
878
- ctx.write(this.openapiContent);
647
+ handleModel(model, name, context) {
648
+ return true;
879
649
  }
880
650
  }
881
651
  //# sourceMappingURL=domainservice.js.map