@webda/core 4.0.0-beta.2 → 4.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (756) hide show
  1. package/README.md +252 -0
  2. package/lib/application/application.d.ts +437 -0
  3. package/lib/application/application.d.ts.map +1 -0
  4. package/lib/application/application.js +792 -0
  5. package/lib/application/application.js.map +1 -0
  6. package/lib/application/hooks.d.ts +34 -0
  7. package/lib/application/hooks.d.ts.map +1 -0
  8. package/lib/application/hooks.js +57 -0
  9. package/lib/application/hooks.js.map +1 -0
  10. package/lib/application/iapplication.d.ts +43 -0
  11. package/lib/application/iapplication.d.ts.map +1 -0
  12. package/lib/application/iapplication.js +2 -0
  13. package/lib/application/iapplication.js.map +1 -0
  14. package/lib/application/iconfiguration.d.ts +176 -0
  15. package/lib/application/iconfiguration.d.ts.map +1 -0
  16. package/lib/application/iconfiguration.js +8 -0
  17. package/lib/application/iconfiguration.js.map +1 -0
  18. package/lib/application/runner.d.ts +8 -0
  19. package/lib/application/runner.d.ts.map +1 -0
  20. package/lib/application/runner.js +26 -0
  21. package/lib/application/runner.js.map +1 -0
  22. package/lib/{unpackedapplication.d.ts → application/unpackedapplication.d.ts} +43 -23
  23. package/lib/application/unpackedapplication.d.ts.map +1 -0
  24. package/lib/application/unpackedapplication.js +492 -0
  25. package/lib/application/unpackedapplication.js.map +1 -0
  26. package/lib/bin/cli-phase.d.ts +28 -0
  27. package/lib/bin/cli-phase.d.ts.map +1 -0
  28. package/lib/bin/cli-phase.js +44 -0
  29. package/lib/bin/cli-phase.js.map +1 -0
  30. package/lib/bin/cli.d.ts +161 -0
  31. package/lib/bin/cli.d.ts.map +1 -0
  32. package/lib/bin/cli.js +828 -0
  33. package/lib/bin/cli.js.map +1 -0
  34. package/lib/bin/launcher.d.ts +3 -0
  35. package/lib/bin/launcher.d.ts.map +1 -0
  36. package/lib/bin/launcher.js +50 -0
  37. package/lib/bin/launcher.js.map +1 -0
  38. package/lib/cache/cache.d.ts +33 -0
  39. package/lib/cache/cache.d.ts.map +1 -0
  40. package/lib/cache/cache.js +8 -0
  41. package/lib/cache/cache.js.map +1 -0
  42. package/lib/{services/configuration.d.ts → configurations/configuration.service.d.ts} +58 -58
  43. package/lib/configurations/configuration.service.d.ts.map +1 -0
  44. package/lib/configurations/configuration.service.js +248 -0
  45. package/lib/configurations/configuration.service.js.map +1 -0
  46. package/lib/configurations/fileconfiguration.service.d.ts +30 -0
  47. package/lib/configurations/fileconfiguration.service.d.ts.map +1 -0
  48. package/lib/configurations/fileconfiguration.service.js +65 -0
  49. package/lib/configurations/fileconfiguration.service.js.map +1 -0
  50. package/lib/configurations/kubernetesconfiguration.service.d.ts +43 -0
  51. package/lib/configurations/kubernetesconfiguration.service.d.ts.map +1 -0
  52. package/lib/configurations/kubernetesconfiguration.service.js +83 -0
  53. package/lib/configurations/kubernetesconfiguration.service.js.map +1 -0
  54. package/lib/contexts/execution.d.ts +33 -0
  55. package/lib/contexts/execution.d.ts.map +1 -0
  56. package/lib/contexts/execution.js +73 -0
  57. package/lib/contexts/execution.js.map +1 -0
  58. package/lib/contexts/globalcontext.d.ts +29 -0
  59. package/lib/contexts/globalcontext.d.ts.map +1 -0
  60. package/lib/contexts/globalcontext.js +38 -0
  61. package/lib/contexts/globalcontext.js.map +1 -0
  62. package/lib/{utils → contexts}/httpcontext.d.ts +44 -19
  63. package/lib/contexts/httpcontext.d.ts.map +1 -0
  64. package/lib/{utils → contexts}/httpcontext.js +95 -27
  65. package/lib/contexts/httpcontext.js.map +1 -0
  66. package/lib/contexts/icontext.d.ts +236 -0
  67. package/lib/contexts/icontext.d.ts.map +1 -0
  68. package/lib/contexts/icontext.js +230 -0
  69. package/lib/contexts/icontext.js.map +1 -0
  70. package/lib/contexts/operationcontext.d.ts +179 -0
  71. package/lib/contexts/operationcontext.d.ts.map +1 -0
  72. package/lib/contexts/operationcontext.js +358 -0
  73. package/lib/contexts/operationcontext.js.map +1 -0
  74. package/lib/contexts/simplecontext.d.ts +31 -0
  75. package/lib/contexts/simplecontext.d.ts.map +1 -0
  76. package/lib/contexts/simplecontext.js +45 -0
  77. package/lib/contexts/simplecontext.js.map +1 -0
  78. package/lib/contexts/webcontext.d.ts +218 -0
  79. package/lib/contexts/webcontext.d.ts.map +1 -0
  80. package/lib/contexts/webcontext.js +389 -0
  81. package/lib/contexts/webcontext.js.map +1 -0
  82. package/lib/core/authorizer.d.ts +23 -0
  83. package/lib/core/authorizer.d.ts.map +1 -0
  84. package/lib/core/authorizer.js +17 -0
  85. package/lib/core/authorizer.js.map +1 -0
  86. package/lib/core/core.d.ts +225 -0
  87. package/lib/core/core.d.ts.map +1 -0
  88. package/lib/core/core.js +576 -0
  89. package/lib/core/core.js.map +1 -0
  90. package/lib/core/hooks.d.ts +72 -0
  91. package/lib/core/hooks.d.ts.map +1 -0
  92. package/lib/core/hooks.js +73 -0
  93. package/lib/core/hooks.js.map +1 -0
  94. package/lib/core/icore.d.ts +249 -0
  95. package/lib/core/icore.d.ts.map +1 -0
  96. package/lib/core/icore.js +15 -0
  97. package/lib/core/icore.js.map +1 -0
  98. package/lib/core/instancestorage.d.ts +61 -0
  99. package/lib/core/instancestorage.d.ts.map +1 -0
  100. package/lib/core/instancestorage.js +75 -0
  101. package/lib/core/instancestorage.js.map +1 -0
  102. package/lib/core/operations.d.ts +181 -0
  103. package/lib/core/operations.d.ts.map +1 -0
  104. package/lib/core/operations.js +559 -0
  105. package/lib/core/operations.js.map +1 -0
  106. package/lib/errors/errors.d.ts +126 -0
  107. package/lib/errors/errors.d.ts.map +1 -0
  108. package/lib/errors/errors.js +165 -0
  109. package/lib/errors/errors.js.map +1 -0
  110. package/lib/events/asynceventemitter.d.ts +159 -0
  111. package/lib/events/asynceventemitter.d.ts.map +1 -0
  112. package/lib/events/asynceventemitter.js +152 -0
  113. package/lib/events/asynceventemitter.js.map +1 -0
  114. package/lib/events/events.d.ts +112 -0
  115. package/lib/events/events.d.ts.map +1 -0
  116. package/lib/events/events.js +45 -0
  117. package/lib/events/events.js.map +1 -0
  118. package/lib/index.d.ts +82 -53
  119. package/lib/index.d.ts.map +1 -1
  120. package/lib/index.js +81 -62
  121. package/lib/index.js.map +1 -1
  122. package/lib/loggers/console.service.d.ts +24 -0
  123. package/lib/loggers/console.service.d.ts.map +1 -0
  124. package/lib/loggers/console.service.js +30 -0
  125. package/lib/loggers/console.service.js.map +1 -0
  126. package/lib/loggers/file.service.d.ts +25 -0
  127. package/lib/loggers/file.service.d.ts.map +1 -0
  128. package/lib/loggers/file.service.js +33 -0
  129. package/lib/loggers/file.service.js.map +1 -0
  130. package/lib/loggers/hooks.d.ts +20 -0
  131. package/lib/loggers/hooks.d.ts.map +1 -0
  132. package/lib/loggers/hooks.js +40 -0
  133. package/lib/loggers/hooks.js.map +1 -0
  134. package/lib/loggers/ilogger.d.ts +76 -0
  135. package/lib/loggers/ilogger.d.ts.map +1 -0
  136. package/lib/loggers/ilogger.js +108 -0
  137. package/lib/loggers/ilogger.js.map +1 -0
  138. package/lib/loggers/logger.d.ts +13 -0
  139. package/lib/loggers/logger.d.ts.map +1 -0
  140. package/lib/loggers/logger.js +18 -0
  141. package/lib/loggers/logger.js.map +1 -0
  142. package/lib/loggers/memory.service.d.ts +18 -0
  143. package/lib/loggers/memory.service.d.ts.map +1 -0
  144. package/lib/loggers/memory.service.js +21 -0
  145. package/lib/loggers/memory.service.js.map +1 -0
  146. package/lib/loggers/params.d.ts +47 -0
  147. package/lib/loggers/params.d.ts.map +1 -0
  148. package/lib/loggers/params.js +56 -0
  149. package/lib/loggers/params.js.map +1 -0
  150. package/lib/metrics/metrics.d.ts +25 -0
  151. package/lib/metrics/metrics.d.ts.map +1 -0
  152. package/lib/metrics/metrics.js +51 -0
  153. package/lib/metrics/metrics.js.map +1 -0
  154. package/lib/models/aclmodel.d.ts +20 -76
  155. package/lib/models/aclmodel.d.ts.map +1 -1
  156. package/lib/models/aclmodel.js +27 -203
  157. package/lib/models/aclmodel.js.map +1 -1
  158. package/lib/models/coremodel.model.d.ts +5 -0
  159. package/lib/models/coremodel.model.d.ts.map +1 -0
  160. package/lib/models/coremodel.model.js +5 -0
  161. package/lib/models/coremodel.model.js.map +1 -0
  162. package/lib/models/decorator.d.ts +63 -0
  163. package/lib/models/decorator.d.ts.map +1 -0
  164. package/lib/models/decorator.js +63 -0
  165. package/lib/models/decorator.js.map +1 -0
  166. package/lib/models/deployment.d.ts +1 -1
  167. package/lib/models/deployment.d.ts.map +1 -1
  168. package/lib/models/ident.model.d.ts +89 -0
  169. package/lib/models/ident.model.d.ts.map +1 -0
  170. package/lib/models/ident.model.js +115 -0
  171. package/lib/models/ident.model.js.map +1 -0
  172. package/lib/models/ownermodel.model.d.ts +68 -0
  173. package/lib/models/ownermodel.model.d.ts.map +1 -0
  174. package/lib/models/ownermodel.model.js +112 -0
  175. package/lib/models/ownermodel.model.js.map +1 -0
  176. package/lib/models/registry.model.d.ts +76 -0
  177. package/lib/models/registry.model.d.ts.map +1 -0
  178. package/lib/models/registry.model.js +104 -0
  179. package/lib/models/registry.model.js.map +1 -0
  180. package/lib/models/rolemodel.model.d.ts +28 -0
  181. package/lib/models/rolemodel.model.d.ts.map +1 -0
  182. package/lib/models/{rolemodel.js → rolemodel.model.js} +23 -5
  183. package/lib/models/rolemodel.model.js.map +1 -0
  184. package/lib/models/simpleuser.model.d.ts +78 -0
  185. package/lib/models/simpleuser.model.d.ts.map +1 -0
  186. package/lib/models/simpleuser.model.js +123 -0
  187. package/lib/models/simpleuser.model.js.map +1 -0
  188. package/lib/models/types.d.ts +113 -0
  189. package/lib/models/types.d.ts.map +1 -0
  190. package/lib/models/types.js +2 -0
  191. package/lib/models/types.js.map +1 -0
  192. package/lib/models/user.model.d.ts +103 -0
  193. package/lib/models/user.model.d.ts.map +1 -0
  194. package/lib/models/user.model.js +125 -0
  195. package/lib/models/user.model.js.map +1 -0
  196. package/lib/queues/{memoryqueue.d.ts → memoryqueue.service.d.ts} +26 -13
  197. package/lib/queues/memoryqueue.service.d.ts.map +1 -0
  198. package/lib/queues/{memoryqueue.js → memoryqueue.service.js} +55 -31
  199. package/lib/queues/memoryqueue.service.js.map +1 -0
  200. package/lib/queues/pubsubservice.d.ts +8 -6
  201. package/lib/queues/pubsubservice.d.ts.map +1 -1
  202. package/lib/queues/pubsubservice.js +5 -4
  203. package/lib/queues/pubsubservice.js.map +1 -1
  204. package/lib/queues/queueservice.d.ts +9 -11
  205. package/lib/queues/queueservice.d.ts.map +1 -1
  206. package/lib/queues/queueservice.js +41 -13
  207. package/lib/queues/queueservice.js.map +1 -1
  208. package/lib/rest/hooks.d.ts +8 -0
  209. package/lib/rest/hooks.d.ts.map +1 -0
  210. package/lib/rest/hooks.js +10 -0
  211. package/lib/rest/hooks.js.map +1 -0
  212. package/lib/rest/irest.d.ts +212 -0
  213. package/lib/rest/irest.d.ts.map +1 -0
  214. package/lib/rest/irest.js +39 -0
  215. package/lib/rest/irest.js.map +1 -0
  216. package/lib/rest/originfilter.d.ts +38 -0
  217. package/lib/rest/originfilter.d.ts.map +1 -0
  218. package/lib/rest/originfilter.js +61 -0
  219. package/lib/rest/originfilter.js.map +1 -0
  220. package/lib/rest/restoperationstransport.service.d.ts +193 -0
  221. package/lib/rest/restoperationstransport.service.d.ts.map +1 -0
  222. package/lib/rest/restoperationstransport.service.js +780 -0
  223. package/lib/rest/restoperationstransport.service.js.map +1 -0
  224. package/lib/rest/router.service.d.ts +244 -0
  225. package/lib/rest/router.service.d.ts.map +1 -0
  226. package/lib/rest/router.service.js +843 -0
  227. package/lib/rest/router.service.js.map +1 -0
  228. package/lib/schemas/hooks.d.ts +48 -0
  229. package/lib/schemas/hooks.d.ts.map +1 -0
  230. package/lib/schemas/hooks.js +152 -0
  231. package/lib/schemas/hooks.js.map +1 -0
  232. package/lib/services/audit.model.d.ts +208 -0
  233. package/lib/services/audit.model.d.ts.map +1 -0
  234. package/lib/services/audit.model.js +431 -0
  235. package/lib/services/audit.model.js.map +1 -0
  236. package/lib/services/{authentication.d.ts → authentication.service.d.ts} +140 -59
  237. package/lib/services/authentication.service.d.ts.map +1 -0
  238. package/lib/services/authentication.service.js +932 -0
  239. package/lib/services/authentication.service.js.map +1 -0
  240. package/lib/services/binary.service.d.ts +808 -0
  241. package/lib/services/binary.service.d.ts.map +1 -0
  242. package/lib/services/binary.service.js +1365 -0
  243. package/lib/services/binary.service.js.map +1 -0
  244. package/lib/services/cloudbinary.d.ts +17 -12
  245. package/lib/services/cloudbinary.d.ts.map +1 -1
  246. package/lib/services/cloudbinary.js +23 -17
  247. package/lib/services/cloudbinary.js.map +1 -1
  248. package/lib/services/command.d.ts +118 -0
  249. package/lib/services/command.d.ts.map +1 -0
  250. package/lib/services/command.js +97 -0
  251. package/lib/services/command.js.map +1 -0
  252. package/lib/services/cron.service.d.ts +142 -0
  253. package/lib/services/cron.service.d.ts.map +1 -0
  254. package/lib/services/cron.service.js +291 -0
  255. package/lib/services/cron.service.js.map +1 -0
  256. package/lib/services/{cryptoservice.d.ts → cryptoservice.service.d.ts} +75 -141
  257. package/lib/services/cryptoservice.service.d.ts.map +1 -0
  258. package/lib/services/cryptoservice.service.js +527 -0
  259. package/lib/services/cryptoservice.service.js.map +1 -0
  260. package/lib/services/debugmailer.service.d.ts +49 -0
  261. package/lib/services/debugmailer.service.d.ts.map +1 -0
  262. package/lib/services/{debugmailer.js → debugmailer.service.js} +25 -10
  263. package/lib/services/debugmailer.service.js.map +1 -0
  264. package/lib/services/domainservice.service.d.ts +203 -0
  265. package/lib/services/domainservice.service.d.ts.map +1 -0
  266. package/lib/services/domainservice.service.js +600 -0
  267. package/lib/services/domainservice.service.js.map +1 -0
  268. package/lib/services/httpserver.service.d.ts +248 -0
  269. package/lib/services/httpserver.service.d.ts.map +1 -0
  270. package/lib/services/httpserver.service.js +673 -0
  271. package/lib/services/httpserver.service.js.map +1 -0
  272. package/lib/services/iauthentication.d.ts +9 -0
  273. package/lib/services/iauthentication.d.ts.map +1 -0
  274. package/lib/services/iauthentication.js +2 -0
  275. package/lib/services/iauthentication.js.map +1 -0
  276. package/lib/services/icryptoservice.d.ts +127 -0
  277. package/lib/services/icryptoservice.d.ts.map +1 -0
  278. package/lib/services/icryptoservice.js +68 -0
  279. package/lib/services/icryptoservice.js.map +1 -0
  280. package/lib/services/imailer.d.ts +17 -0
  281. package/lib/services/imailer.d.ts.map +1 -0
  282. package/lib/services/imailer.js +2 -0
  283. package/lib/services/imailer.js.map +1 -0
  284. package/lib/services/iservice.d.ts +104 -0
  285. package/lib/services/iservice.d.ts.map +1 -0
  286. package/lib/services/iservice.js +63 -0
  287. package/lib/services/iservice.js.map +1 -0
  288. package/lib/services/mailer.service.d.ts +220 -0
  289. package/lib/services/mailer.service.d.ts.map +1 -0
  290. package/lib/services/mailer.service.js +251 -0
  291. package/lib/services/mailer.service.js.map +1 -0
  292. package/lib/services/{notificationservice.d.ts → notificationservice.service.d.ts} +10 -11
  293. package/lib/services/notificationservice.service.d.ts.map +1 -0
  294. package/lib/services/{notificationservice.js → notificationservice.service.js} +24 -12
  295. package/lib/services/notificationservice.service.js.map +1 -0
  296. package/lib/services/oauth.d.ts +52 -28
  297. package/lib/services/oauth.d.ts.map +1 -1
  298. package/lib/services/oauth.js +365 -254
  299. package/lib/services/oauth.js.map +1 -1
  300. package/lib/services/operationstransport.d.ts +65 -0
  301. package/lib/services/operationstransport.d.ts.map +1 -0
  302. package/lib/services/operationstransport.js +103 -0
  303. package/lib/services/operationstransport.js.map +1 -0
  304. package/lib/services/{prometheus.d.ts → prometheus.service.d.ts} +13 -12
  305. package/lib/services/prometheus.service.d.ts.map +1 -0
  306. package/lib/services/prometheus.service.js +203 -0
  307. package/lib/services/prometheus.service.js.map +1 -0
  308. package/lib/services/{resource.d.ts → resource.service.d.ts} +34 -15
  309. package/lib/services/resource.service.d.ts.map +1 -0
  310. package/lib/services/resource.service.js +301 -0
  311. package/lib/services/resource.service.js.map +1 -0
  312. package/lib/services/service.d.ts +87 -188
  313. package/lib/services/service.d.ts.map +1 -1
  314. package/lib/services/service.js +407 -422
  315. package/lib/services/service.js.map +1 -1
  316. package/lib/services/servicecommands.d.ts +99 -0
  317. package/lib/services/servicecommands.d.ts.map +1 -0
  318. package/lib/services/servicecommands.js +165 -0
  319. package/lib/services/servicecommands.js.map +1 -0
  320. package/lib/services/serviceparameters.d.ts +33 -0
  321. package/lib/services/serviceparameters.d.ts.map +1 -0
  322. package/lib/services/serviceparameters.js +79 -0
  323. package/lib/services/serviceparameters.js.map +1 -0
  324. package/lib/{utils → session}/cookie.d.ts +32 -19
  325. package/lib/session/cookie.d.ts.map +1 -0
  326. package/lib/{utils → session}/cookie.js +76 -23
  327. package/lib/session/cookie.js.map +1 -0
  328. package/lib/session/manager.model.d.ts +71 -0
  329. package/lib/session/manager.model.d.ts.map +1 -0
  330. package/lib/session/manager.model.js +155 -0
  331. package/lib/session/manager.model.js.map +1 -0
  332. package/lib/session/session.d.ts +57 -0
  333. package/lib/session/session.d.ts.map +1 -0
  334. package/lib/session/session.js +126 -0
  335. package/lib/session/session.js.map +1 -0
  336. package/lib/stores/istore.d.ts +99 -0
  337. package/lib/stores/istore.d.ts.map +1 -0
  338. package/lib/stores/istore.js +26 -0
  339. package/lib/stores/istore.js.map +1 -0
  340. package/lib/stores/memory.service.d.ts +114 -0
  341. package/lib/stores/memory.service.d.ts.map +1 -0
  342. package/lib/stores/memory.service.js +343 -0
  343. package/lib/stores/memory.service.js.map +1 -0
  344. package/lib/stores/store.d.ts +126 -626
  345. package/lib/stores/store.d.ts.map +1 -1
  346. package/lib/stores/store.js +257 -1117
  347. package/lib/stores/store.js.map +1 -1
  348. package/lib/templates/templates.d.ts +39 -0
  349. package/lib/templates/templates.d.ts.map +1 -0
  350. package/lib/templates/templates.js +92 -0
  351. package/lib/templates/templates.js.map +1 -0
  352. package/lib/test/application.d.ts +174 -0
  353. package/lib/test/application.d.ts.map +1 -0
  354. package/lib/test/application.js +288 -0
  355. package/lib/test/application.js.map +1 -0
  356. package/lib/test/asyncstorage.d.ts +16 -0
  357. package/lib/test/asyncstorage.d.ts.map +1 -0
  358. package/lib/test/asyncstorage.js +32 -0
  359. package/lib/test/asyncstorage.js.map +1 -0
  360. package/lib/test/core.d.ts +63 -0
  361. package/lib/test/core.d.ts.map +1 -0
  362. package/lib/test/core.js +190 -0
  363. package/lib/test/core.js.map +1 -0
  364. package/lib/test/index.d.ts +7 -0
  365. package/lib/test/index.d.ts.map +1 -0
  366. package/lib/test/index.js +8 -0
  367. package/lib/test/index.js.map +1 -0
  368. package/lib/test/internal.d.ts +34 -0
  369. package/lib/test/internal.d.ts.map +1 -0
  370. package/lib/test/internal.js +156 -0
  371. package/lib/test/internal.js.map +1 -0
  372. package/lib/test/objects.d.ts +318 -0
  373. package/lib/test/objects.d.ts.map +1 -0
  374. package/lib/test/objects.js +443 -0
  375. package/lib/test/objects.js.map +1 -0
  376. package/lib/utils/abstractdeployer.d.ts +4 -2
  377. package/lib/utils/abstractdeployer.d.ts.map +1 -1
  378. package/lib/utils/abstractdeployer.js +3 -0
  379. package/lib/utils/abstractdeployer.js.map +1 -1
  380. package/package.json +85 -60
  381. package/test/cachedapp/webda.config.json +1 -5
  382. package/test/config-cached.json +1 -5
  383. package/test/config.json +0 -9
  384. package/test/my-cnf.json +9 -0
  385. package/webda.module.json +3463 -2482
  386. package/lib/application.d.ts +0 -888
  387. package/lib/application.d.ts.map +0 -1
  388. package/lib/application.js +0 -768
  389. package/lib/application.js.map +0 -1
  390. package/lib/application.spec.d.ts +0 -2
  391. package/lib/application.spec.d.ts.map +0 -1
  392. package/lib/application.spec.js +0 -248
  393. package/lib/application.spec.js.map +0 -1
  394. package/lib/core.d.ts +0 -743
  395. package/lib/core.d.ts.map +0 -1
  396. package/lib/core.js +0 -1334
  397. package/lib/core.js.map +0 -1
  398. package/lib/core.spec.d.ts +0 -2
  399. package/lib/core.spec.d.ts.map +0 -1
  400. package/lib/core.spec.js +0 -790
  401. package/lib/core.spec.js.map +0 -1
  402. package/lib/errors.d.ts +0 -64
  403. package/lib/errors.d.ts.map +0 -1
  404. package/lib/errors.js +0 -97
  405. package/lib/errors.js.map +0 -1
  406. package/lib/errors.spec.d.ts +0 -2
  407. package/lib/errors.spec.d.ts.map +0 -1
  408. package/lib/errors.spec.js +0 -33
  409. package/lib/errors.spec.js.map +0 -1
  410. package/lib/models/aclmodel.spec.d.ts +0 -2
  411. package/lib/models/aclmodel.spec.d.ts.map +0 -1
  412. package/lib/models/aclmodel.spec.js +0 -187
  413. package/lib/models/aclmodel.spec.js.map +0 -1
  414. package/lib/models/coremodel.d.ts +0 -896
  415. package/lib/models/coremodel.d.ts.map +0 -1
  416. package/lib/models/coremodel.js +0 -1214
  417. package/lib/models/coremodel.js.map +0 -1
  418. package/lib/models/coremodel.spec.d.ts +0 -2
  419. package/lib/models/coremodel.spec.d.ts.map +0 -1
  420. package/lib/models/coremodel.spec.js +0 -464
  421. package/lib/models/coremodel.spec.js.map +0 -1
  422. package/lib/models/ident.d.ts +0 -68
  423. package/lib/models/ident.d.ts.map +0 -1
  424. package/lib/models/ident.js +0 -26
  425. package/lib/models/ident.js.map +0 -1
  426. package/lib/models/ident.spec.d.ts +0 -2
  427. package/lib/models/ident.spec.d.ts.map +0 -1
  428. package/lib/models/ident.spec.js +0 -24
  429. package/lib/models/ident.spec.js.map +0 -1
  430. package/lib/models/ownermodel.d.ts +0 -51
  431. package/lib/models/ownermodel.d.ts.map +0 -1
  432. package/lib/models/ownermodel.js +0 -65
  433. package/lib/models/ownermodel.js.map +0 -1
  434. package/lib/models/ownermodel.spec.d.ts +0 -2
  435. package/lib/models/ownermodel.spec.d.ts.map +0 -1
  436. package/lib/models/ownermodel.spec.js +0 -215
  437. package/lib/models/ownermodel.spec.js.map +0 -1
  438. package/lib/models/relations.d.ts +0 -182
  439. package/lib/models/relations.d.ts.map +0 -1
  440. package/lib/models/relations.js +0 -157
  441. package/lib/models/relations.js.map +0 -1
  442. package/lib/models/relations.spec.d.ts +0 -14
  443. package/lib/models/relations.spec.d.ts.map +0 -1
  444. package/lib/models/relations.spec.js +0 -217
  445. package/lib/models/relations.spec.js.map +0 -1
  446. package/lib/models/rolemodel.d.ts +0 -11
  447. package/lib/models/rolemodel.d.ts.map +0 -1
  448. package/lib/models/rolemodel.js.map +0 -1
  449. package/lib/models/rolemodel.spec.d.ts +0 -2
  450. package/lib/models/rolemodel.spec.d.ts.map +0 -1
  451. package/lib/models/rolemodel.spec.js +0 -90
  452. package/lib/models/rolemodel.spec.js.map +0 -1
  453. package/lib/models/simpleuser.d.ts +0 -47
  454. package/lib/models/simpleuser.d.ts.map +0 -1
  455. package/lib/models/simpleuser.js +0 -84
  456. package/lib/models/simpleuser.js.map +0 -1
  457. package/lib/models/test.d.ts +0 -11
  458. package/lib/models/test.d.ts.map +0 -1
  459. package/lib/models/test.js +0 -7
  460. package/lib/models/test.js.map +0 -1
  461. package/lib/models/user.d.ts +0 -67
  462. package/lib/models/user.d.ts.map +0 -1
  463. package/lib/models/user.js +0 -86
  464. package/lib/models/user.js.map +0 -1
  465. package/lib/models/user.spec.d.ts +0 -2
  466. package/lib/models/user.spec.d.ts.map +0 -1
  467. package/lib/models/user.spec.js +0 -89
  468. package/lib/models/user.spec.js.map +0 -1
  469. package/lib/queues/filequeue.d.ts +0 -59
  470. package/lib/queues/filequeue.d.ts.map +0 -1
  471. package/lib/queues/filequeue.js +0 -131
  472. package/lib/queues/filequeue.js.map +0 -1
  473. package/lib/queues/filequeue.spec.d.ts +0 -2
  474. package/lib/queues/filequeue.spec.d.ts.map +0 -1
  475. package/lib/queues/filequeue.spec.js +0 -84
  476. package/lib/queues/filequeue.spec.js.map +0 -1
  477. package/lib/queues/memoryqueue.d.ts.map +0 -1
  478. package/lib/queues/memoryqueue.js.map +0 -1
  479. package/lib/queues/memoryqueue.spec.d.ts +0 -2
  480. package/lib/queues/memoryqueue.spec.d.ts.map +0 -1
  481. package/lib/queues/memoryqueue.spec.js +0 -203
  482. package/lib/queues/memoryqueue.spec.js.map +0 -1
  483. package/lib/queues/queue.spec.d.ts +0 -6
  484. package/lib/queues/queue.spec.d.ts.map +0 -1
  485. package/lib/queues/queue.spec.js +0 -55
  486. package/lib/queues/queue.spec.js.map +0 -1
  487. package/lib/rest/restdomainservice.d.ts +0 -63
  488. package/lib/rest/restdomainservice.d.ts.map +0 -1
  489. package/lib/rest/restdomainservice.js +0 -687
  490. package/lib/rest/restdomainservice.js.map +0 -1
  491. package/lib/rest/restdomainservice.spec.d.ts +0 -2
  492. package/lib/rest/restdomainservice.spec.d.ts.map +0 -1
  493. package/lib/rest/restdomainservice.spec.js +0 -124
  494. package/lib/rest/restdomainservice.spec.js.map +0 -1
  495. package/lib/rest/router.d.ts +0 -174
  496. package/lib/rest/router.d.ts.map +0 -1
  497. package/lib/rest/router.js +0 -429
  498. package/lib/rest/router.js.map +0 -1
  499. package/lib/rest/router.spec.d.ts +0 -2
  500. package/lib/rest/router.spec.d.ts.map +0 -1
  501. package/lib/rest/router.spec.js +0 -255
  502. package/lib/rest/router.spec.js.map +0 -1
  503. package/lib/services/asyncevents.d.ts +0 -152
  504. package/lib/services/asyncevents.d.ts.map +0 -1
  505. package/lib/services/asyncevents.js +0 -217
  506. package/lib/services/asyncevents.js.map +0 -1
  507. package/lib/services/asyncevents.spec.d.ts +0 -2
  508. package/lib/services/asyncevents.spec.d.ts.map +0 -1
  509. package/lib/services/asyncevents.spec.js +0 -118
  510. package/lib/services/asyncevents.spec.js.map +0 -1
  511. package/lib/services/authentication.d.ts.map +0 -1
  512. package/lib/services/authentication.js +0 -773
  513. package/lib/services/authentication.js.map +0 -1
  514. package/lib/services/authentication.spec.d.ts +0 -2
  515. package/lib/services/authentication.spec.d.ts.map +0 -1
  516. package/lib/services/authentication.spec.js +0 -458
  517. package/lib/services/authentication.spec.js.map +0 -1
  518. package/lib/services/binary.d.ts +0 -477
  519. package/lib/services/binary.d.ts.map +0 -1
  520. package/lib/services/binary.js +0 -617
  521. package/lib/services/binary.js.map +0 -1
  522. package/lib/services/binary.spec.d.ts +0 -41
  523. package/lib/services/binary.spec.d.ts.map +0 -1
  524. package/lib/services/binary.spec.js +0 -151
  525. package/lib/services/binary.spec.js.map +0 -1
  526. package/lib/services/cloudbinary.spec.d.ts +0 -6
  527. package/lib/services/cloudbinary.spec.d.ts.map +0 -1
  528. package/lib/services/cloudbinary.spec.js +0 -66
  529. package/lib/services/cloudbinary.spec.js.map +0 -1
  530. package/lib/services/configuration.d.ts.map +0 -1
  531. package/lib/services/configuration.js +0 -193
  532. package/lib/services/configuration.js.map +0 -1
  533. package/lib/services/configuration.spec.d.ts +0 -2
  534. package/lib/services/configuration.spec.d.ts.map +0 -1
  535. package/lib/services/configuration.spec.js +0 -130
  536. package/lib/services/configuration.spec.js.map +0 -1
  537. package/lib/services/cron.d.ts +0 -74
  538. package/lib/services/cron.d.ts.map +0 -1
  539. package/lib/services/cron.js +0 -141
  540. package/lib/services/cron.js.map +0 -1
  541. package/lib/services/cron.spec.d.ts +0 -2
  542. package/lib/services/cron.spec.d.ts.map +0 -1
  543. package/lib/services/cron.spec.js +0 -76
  544. package/lib/services/cron.spec.js.map +0 -1
  545. package/lib/services/cryptoservice.d.ts.map +0 -1
  546. package/lib/services/cryptoservice.js +0 -433
  547. package/lib/services/cryptoservice.js.map +0 -1
  548. package/lib/services/cryptoservice.spec.d.ts +0 -2
  549. package/lib/services/cryptoservice.spec.d.ts.map +0 -1
  550. package/lib/services/cryptoservice.spec.js +0 -177
  551. package/lib/services/cryptoservice.spec.js.map +0 -1
  552. package/lib/services/debugmailer.d.ts +0 -36
  553. package/lib/services/debugmailer.d.ts.map +0 -1
  554. package/lib/services/debugmailer.js.map +0 -1
  555. package/lib/services/debugmailer.spec.d.ts +0 -2
  556. package/lib/services/debugmailer.spec.d.ts.map +0 -1
  557. package/lib/services/debugmailer.spec.js +0 -32
  558. package/lib/services/debugmailer.spec.js.map +0 -1
  559. package/lib/services/domainservice.d.ts +0 -272
  560. package/lib/services/domainservice.d.ts.map +0 -1
  561. package/lib/services/domainservice.js +0 -651
  562. package/lib/services/domainservice.js.map +0 -1
  563. package/lib/services/domainservice.spec.d.ts +0 -2
  564. package/lib/services/domainservice.spec.d.ts.map +0 -1
  565. package/lib/services/domainservice.spec.js +0 -592
  566. package/lib/services/domainservice.spec.js.map +0 -1
  567. package/lib/services/filebinary.d.ts +0 -136
  568. package/lib/services/filebinary.d.ts.map +0 -1
  569. package/lib/services/filebinary.js +0 -373
  570. package/lib/services/filebinary.js.map +0 -1
  571. package/lib/services/filebinary.spec.d.ts +0 -25
  572. package/lib/services/filebinary.spec.d.ts.map +0 -1
  573. package/lib/services/filebinary.spec.js +0 -428
  574. package/lib/services/filebinary.spec.js.map +0 -1
  575. package/lib/services/fileconfiguration.d.ts +0 -23
  576. package/lib/services/fileconfiguration.d.ts.map +0 -1
  577. package/lib/services/fileconfiguration.js +0 -48
  578. package/lib/services/fileconfiguration.js.map +0 -1
  579. package/lib/services/fileconfiguration.spec.d.ts +0 -2
  580. package/lib/services/fileconfiguration.spec.d.ts.map +0 -1
  581. package/lib/services/fileconfiguration.spec.js +0 -215
  582. package/lib/services/fileconfiguration.spec.js.map +0 -1
  583. package/lib/services/invitationservice.d.ts +0 -223
  584. package/lib/services/invitationservice.d.ts.map +0 -1
  585. package/lib/services/invitationservice.js +0 -529
  586. package/lib/services/invitationservice.js.map +0 -1
  587. package/lib/services/invitationservice.spec.d.ts +0 -2
  588. package/lib/services/invitationservice.spec.d.ts.map +0 -1
  589. package/lib/services/invitationservice.spec.js +0 -567
  590. package/lib/services/invitationservice.spec.js.map +0 -1
  591. package/lib/services/kubernetesconfiguration.d.ts +0 -27
  592. package/lib/services/kubernetesconfiguration.d.ts.map +0 -1
  593. package/lib/services/kubernetesconfiguration.js +0 -52
  594. package/lib/services/kubernetesconfiguration.js.map +0 -1
  595. package/lib/services/kubernetesconfiguration.spec.d.ts +0 -2
  596. package/lib/services/kubernetesconfiguration.spec.d.ts.map +0 -1
  597. package/lib/services/kubernetesconfiguration.spec.js +0 -206
  598. package/lib/services/kubernetesconfiguration.spec.js.map +0 -1
  599. package/lib/services/mailer.d.ts +0 -166
  600. package/lib/services/mailer.d.ts.map +0 -1
  601. package/lib/services/mailer.js +0 -176
  602. package/lib/services/mailer.js.map +0 -1
  603. package/lib/services/mailer.spec.d.ts +0 -2
  604. package/lib/services/mailer.spec.d.ts.map +0 -1
  605. package/lib/services/mailer.spec.js +0 -158
  606. package/lib/services/mailer.spec.js.map +0 -1
  607. package/lib/services/notificationservice.d.ts.map +0 -1
  608. package/lib/services/notificationservice.js.map +0 -1
  609. package/lib/services/notificationservice.spec.d.ts +0 -2
  610. package/lib/services/notificationservice.spec.d.ts.map +0 -1
  611. package/lib/services/notificationservice.spec.js +0 -83
  612. package/lib/services/notificationservice.spec.js.map +0 -1
  613. package/lib/services/oauth.spec.d.ts +0 -2
  614. package/lib/services/oauth.spec.d.ts.map +0 -1
  615. package/lib/services/oauth.spec.js +0 -208
  616. package/lib/services/oauth.spec.js.map +0 -1
  617. package/lib/services/prometheus.d.ts.map +0 -1
  618. package/lib/services/prometheus.js +0 -160
  619. package/lib/services/prometheus.js.map +0 -1
  620. package/lib/services/prometheus.spec.d.ts +0 -2
  621. package/lib/services/prometheus.spec.d.ts.map +0 -1
  622. package/lib/services/prometheus.spec.js +0 -76
  623. package/lib/services/prometheus.spec.js.map +0 -1
  624. package/lib/services/resource.d.ts.map +0 -1
  625. package/lib/services/resource.js +0 -170
  626. package/lib/services/resource.js.map +0 -1
  627. package/lib/services/resource.spec.d.ts +0 -2
  628. package/lib/services/resource.spec.d.ts.map +0 -1
  629. package/lib/services/resource.spec.js +0 -140
  630. package/lib/services/resource.spec.js.map +0 -1
  631. package/lib/services/service.spec.d.ts +0 -2
  632. package/lib/services/service.spec.d.ts.map +0 -1
  633. package/lib/services/service.spec.js +0 -286
  634. package/lib/services/service.spec.js.map +0 -1
  635. package/lib/stores/aggregator.d.ts +0 -48
  636. package/lib/stores/aggregator.d.ts.map +0 -1
  637. package/lib/stores/aggregator.js +0 -80
  638. package/lib/stores/aggregator.js.map +0 -1
  639. package/lib/stores/file.d.ts +0 -108
  640. package/lib/stores/file.d.ts.map +0 -1
  641. package/lib/stores/file.js +0 -188
  642. package/lib/stores/file.js.map +0 -1
  643. package/lib/stores/file.spec.d.ts +0 -13
  644. package/lib/stores/file.spec.d.ts.map +0 -1
  645. package/lib/stores/file.spec.js +0 -138
  646. package/lib/stores/file.spec.js.map +0 -1
  647. package/lib/stores/mapper.d.ts +0 -150
  648. package/lib/stores/mapper.d.ts.map +0 -1
  649. package/lib/stores/mapper.js +0 -293
  650. package/lib/stores/mapper.js.map +0 -1
  651. package/lib/stores/mapper.spec.d.ts +0 -2
  652. package/lib/stores/mapper.spec.d.ts.map +0 -1
  653. package/lib/stores/mapper.spec.js +0 -167
  654. package/lib/stores/mapper.spec.js.map +0 -1
  655. package/lib/stores/memory.d.ts +0 -152
  656. package/lib/stores/memory.d.ts.map +0 -1
  657. package/lib/stores/memory.js +0 -371
  658. package/lib/stores/memory.js.map +0 -1
  659. package/lib/stores/memory.spec.d.ts +0 -14
  660. package/lib/stores/memory.spec.d.ts.map +0 -1
  661. package/lib/stores/memory.spec.js +0 -263
  662. package/lib/stores/memory.spec.js.map +0 -1
  663. package/lib/stores/modelmapper.d.ts +0 -62
  664. package/lib/stores/modelmapper.d.ts.map +0 -1
  665. package/lib/stores/modelmapper.js +0 -197
  666. package/lib/stores/modelmapper.js.map +0 -1
  667. package/lib/stores/store.spec.d.ts +0 -57
  668. package/lib/stores/store.spec.d.ts.map +0 -1
  669. package/lib/stores/store.spec.js +0 -737
  670. package/lib/stores/store.spec.js.map +0 -1
  671. package/lib/test.d.ts +0 -265
  672. package/lib/test.d.ts.map +0 -1
  673. package/lib/test.js +0 -622
  674. package/lib/test.js.map +0 -1
  675. package/lib/unpackedapplication.d.ts.map +0 -1
  676. package/lib/unpackedapplication.js +0 -350
  677. package/lib/unpackedapplication.js.map +0 -1
  678. package/lib/utils/abstractdeployer.spec.d.ts +0 -2
  679. package/lib/utils/abstractdeployer.spec.d.ts.map +0 -1
  680. package/lib/utils/abstractdeployer.spec.js +0 -21
  681. package/lib/utils/abstractdeployer.spec.js.map +0 -1
  682. package/lib/utils/case.d.ts +0 -8
  683. package/lib/utils/case.d.ts.map +0 -1
  684. package/lib/utils/case.js +0 -43
  685. package/lib/utils/case.js.map +0 -1
  686. package/lib/utils/case.spec.d.ts +0 -2
  687. package/lib/utils/case.spec.d.ts.map +0 -1
  688. package/lib/utils/case.spec.js +0 -50
  689. package/lib/utils/case.spec.js.map +0 -1
  690. package/lib/utils/context.d.ts +0 -482
  691. package/lib/utils/context.d.ts.map +0 -1
  692. package/lib/utils/context.js +0 -739
  693. package/lib/utils/context.js.map +0 -1
  694. package/lib/utils/context.spec.d.ts +0 -10
  695. package/lib/utils/context.spec.d.ts.map +0 -1
  696. package/lib/utils/context.spec.js +0 -383
  697. package/lib/utils/context.spec.js.map +0 -1
  698. package/lib/utils/cookie.d.ts.map +0 -1
  699. package/lib/utils/cookie.js.map +0 -1
  700. package/lib/utils/cookie.spec.d.ts +0 -2
  701. package/lib/utils/cookie.spec.d.ts.map +0 -1
  702. package/lib/utils/cookie.spec.js +0 -88
  703. package/lib/utils/cookie.spec.js.map +0 -1
  704. package/lib/utils/esm.d.ts +0 -14
  705. package/lib/utils/esm.d.ts.map +0 -1
  706. package/lib/utils/esm.js +0 -19
  707. package/lib/utils/esm.js.map +0 -1
  708. package/lib/utils/httpcontext.d.ts.map +0 -1
  709. package/lib/utils/httpcontext.js.map +0 -1
  710. package/lib/utils/httpcontext.spec.d.ts +0 -5
  711. package/lib/utils/httpcontext.spec.d.ts.map +0 -1
  712. package/lib/utils/httpcontext.spec.js +0 -77
  713. package/lib/utils/httpcontext.spec.js.map +0 -1
  714. package/lib/utils/logger.d.ts +0 -92
  715. package/lib/utils/logger.d.ts.map +0 -1
  716. package/lib/utils/logger.js +0 -121
  717. package/lib/utils/logger.js.map +0 -1
  718. package/lib/utils/logger.spec.d.ts +0 -2
  719. package/lib/utils/logger.spec.d.ts.map +0 -1
  720. package/lib/utils/logger.spec.js +0 -48
  721. package/lib/utils/logger.spec.js.map +0 -1
  722. package/lib/utils/serializers.d.ts +0 -162
  723. package/lib/utils/serializers.d.ts.map +0 -1
  724. package/lib/utils/serializers.js +0 -420
  725. package/lib/utils/serializers.js.map +0 -1
  726. package/lib/utils/serializers.spec.d.ts +0 -2
  727. package/lib/utils/serializers.spec.d.ts.map +0 -1
  728. package/lib/utils/serializers.spec.js +0 -311
  729. package/lib/utils/serializers.spec.js.map +0 -1
  730. package/lib/utils/session.d.ts +0 -123
  731. package/lib/utils/session.d.ts.map +0 -1
  732. package/lib/utils/session.js +0 -156
  733. package/lib/utils/session.js.map +0 -1
  734. package/lib/utils/session.spec.d.ts +0 -2
  735. package/lib/utils/session.spec.d.ts.map +0 -1
  736. package/lib/utils/session.spec.js +0 -81
  737. package/lib/utils/session.spec.js.map +0 -1
  738. package/lib/utils/throttler.d.ts +0 -99
  739. package/lib/utils/throttler.d.ts.map +0 -1
  740. package/lib/utils/throttler.js +0 -160
  741. package/lib/utils/throttler.js.map +0 -1
  742. package/lib/utils/throttler.spec.d.ts +0 -2
  743. package/lib/utils/throttler.spec.d.ts.map +0 -1
  744. package/lib/utils/throttler.spec.js +0 -53
  745. package/lib/utils/throttler.spec.js.map +0 -1
  746. package/lib/utils/waiter.d.ts +0 -94
  747. package/lib/utils/waiter.d.ts.map +0 -1
  748. package/lib/utils/waiter.js +0 -148
  749. package/lib/utils/waiter.js.map +0 -1
  750. package/lib/utils/waiter.spec.d.ts +0 -2
  751. package/lib/utils/waiter.spec.d.ts.map +0 -1
  752. package/lib/utils/waiter.spec.js +0 -98
  753. package/lib/utils/waiter.spec.js.map +0 -1
  754. package/test/jsonutils/mdocs.yaml +0 -56
  755. package/test/jsonutils/test.json +0 -3
  756. package/test/jsonutils/test.yml +0 -5
package/lib/core.js DELETED
@@ -1,1334 +0,0 @@
1
- import Ajv from "ajv";
2
- import addFormats from "ajv-formats";
3
- import { deepmerge } from "deepmerge-ts";
4
- import * as events from "events";
5
- import jsonpath from "jsonpath";
6
- import pkg from "node-machine-id";
7
- import { Counter, Gauge, Histogram, register } from "prom-client";
8
- import { randomUUID } from "crypto";
9
- import { BinaryService, GlobalContext, Logger, OperationContext, RegExpValidator, Store, UnpackedApplication, WebContext, WebdaError } from "./index.js";
10
- import * as WebdaQL from "@webda/ql";
11
- import { CoreModel } from "./models/coremodel.js";
12
- import { Router } from "./rest/router.js";
13
- import { JSONUtils } from "./utils/serializers.js";
14
- const { machineIdSync } = pkg;
15
- export class EventEmitterUtils {
16
- static emit(eventEmitter, event, data) {
17
- for (const listener of eventEmitter.listeners(event)) {
18
- const start = Date.now();
19
- listener(data);
20
- this.elapse(start);
21
- }
22
- return true;
23
- }
24
- static async emitSync(eventEmitter, event, data) {
25
- const promises = [];
26
- for (const listener of eventEmitter.listeners(event)) {
27
- const start = Date.now();
28
- const result = listener(data);
29
- if (result instanceof Promise) {
30
- promises.push(result
31
- .catch(err => {
32
- Core.get().log("ERROR", "Listener error", err);
33
- })
34
- .then(() => {
35
- this.elapse(start);
36
- }));
37
- }
38
- else {
39
- this.elapse(start);
40
- }
41
- }
42
- return Promise.all(promises);
43
- }
44
- /**
45
- * Display a message if the listener takes too long
46
- * @param start
47
- */
48
- static elapse(start) {
49
- const elapsed = Date.now() - start;
50
- if (elapsed > 100) {
51
- Core.get().log("INFO", "Long listener", elapsed, "ms");
52
- }
53
- }
54
- }
55
- /**
56
- * Copy from https://github.com/ajv-validator/ajv/blob/master/lib/runtime/validation_error.ts
57
- * It is not exported by ajv
58
- */
59
- export class ValidationError extends Error {
60
- constructor(errors) {
61
- super(`validation failed: ${errors.map(e => e.message).join("; ")}`);
62
- this.errors = errors;
63
- this.ajv = this.validation = true;
64
- }
65
- }
66
- /**
67
- * Filter request based on their origin
68
- *
69
- * @category CoreFeatures
70
- */
71
- export class OriginFilter {
72
- constructor(origins) {
73
- this.regexs = new RegExpValidator(origins);
74
- }
75
- /**
76
- *
77
- * @param context
78
- * @returns
79
- */
80
- async checkRequest(context) {
81
- const httpContext = context.getHttpContext();
82
- return this.regexs.validate(httpContext.hostname) || this.regexs.validate(httpContext.origin);
83
- }
84
- }
85
- /**
86
- * Authorize requests based on the website
87
- */
88
- export class WebsiteOriginFilter {
89
- constructor(website) {
90
- this.websites = [];
91
- if (!Array.isArray(website)) {
92
- if (typeof website === "object") {
93
- this.websites.push(website.url);
94
- }
95
- else {
96
- this.websites.push(website);
97
- }
98
- }
99
- else {
100
- this.websites = [...website];
101
- }
102
- }
103
- async checkRequest(context) {
104
- const httpContext = context.getHttpContext();
105
- if (this.websites.indexOf(httpContext.origin) >= 0 ||
106
- this.websites.indexOf(httpContext.host) >= 0 ||
107
- this.websites.indexOf("*") >= 0) {
108
- return true;
109
- }
110
- return false;
111
- }
112
- }
113
- // @Bean to declare as a Singleton service
114
- export function Bean(constructor) {
115
- const name = constructor.name;
116
- // @ts-ignore
117
- process.webdaBeans ?? (process.webdaBeans = {});
118
- // @ts-ignore
119
- const beans = process.webdaBeans;
120
- beans[name] ?? (beans[name] = constructor);
121
- }
122
- /**
123
- * This is the main class of the framework, it handles the routing, the services initialization and resolution
124
- *
125
- * @class Core
126
- * @category CoreFeatures
127
- */
128
- export class Core extends events.EventEmitter {
129
- /**
130
- * @params {Object} config - The configuration Object, if undefined will load the configuration file
131
- */
132
- constructor(application) {
133
- var _a, _b, _c, _d, _e, _f, _g, _h;
134
- /** @ignore */
135
- super();
136
- /**
137
- * Webda Services
138
- * @hidden
139
- */
140
- this.services = {};
141
- /**
142
- * Router that will route http request in
143
- */
144
- this.router = new Router(this);
145
- /**
146
- * If Core is already initiated
147
- */
148
- this._initiated = false;
149
- /**
150
- * Services who failed to create or initialize
151
- */
152
- this.failedServices = {};
153
- /**
154
- * Request Filter registry
155
- *
156
- * Added via [[Webda.registerRequestFilter]]
157
- * See [[CorsFilter]]
158
- */
159
- this._requestFilters = [];
160
- /**
161
- * CORS Filter registry
162
- *
163
- * Added via [[Webda.registerCORSRequestFilter]]
164
- * See [[CorsFilter]]
165
- */
166
- this._requestCORSFilters = [];
167
- /**
168
- * Contains all operations defined by services
169
- */
170
- this.operations = {};
171
- /**
172
- * Cache for model to store resolution
173
- */
174
- this._modelStoresCache = new Map();
175
- /**
176
- * Cache for model to store resolution
177
- */
178
- this._modelBinariesCache = new Map();
179
- /**
180
- * True if the dual import warning has been sent
181
- */
182
- this._dualImportWarn = false;
183
- /**
184
- * Registered context providers
185
- */
186
- this._contextProviders = [
187
- {
188
- getContext: (info) => {
189
- // If http is defined, return a WebContext
190
- if (info.http) {
191
- return new WebContext(this, info.http, info.stream);
192
- }
193
- return new OperationContext(this, info.stream);
194
- }
195
- }
196
- ];
197
- /**
198
- *
199
- */
200
- this.interuptables = [];
201
- // Store WebdaCore in process to avoid conflict with import
202
- // @ts-ignore
203
- Core.singleton = process.webda = this;
204
- /**
205
- * SIGINT handler
206
- */
207
- process.on("SIGINT", async () => {
208
- if (Core.get()?.interuptables.length > 0) {
209
- console.log("Received SIGINT. Cancelling all interuptables.");
210
- await Promise.all(Core.get().interuptables.map(i => i.cancel()));
211
- }
212
- process.exit(0);
213
- });
214
- this.workerOutput = application.getWorkerOutput();
215
- this.logger = new Logger(this.workerOutput, "@webda/core/lib/core.js");
216
- this.application = application || new UnpackedApplication(".");
217
- this._initTime = new Date().getTime();
218
- // Schema validations
219
- this._ajv = new Ajv();
220
- this._ajv.addKeyword("$generated");
221
- addFormats(this._ajv);
222
- this._ajvSchemas = {};
223
- // Load the configuration and migrate
224
- this.configuration = this.application.getCurrentConfiguration();
225
- // Init default values for configuration
226
- (_a = this.configuration).parameters ?? (_a.parameters = {});
227
- (_b = this.configuration.parameters).apiUrl ?? (_b.apiUrl = "http://localhost:18080");
228
- (_c = this.configuration.parameters).defaultStore ?? (_c.defaultStore = "Registry");
229
- (_d = this.configuration.parameters).metrics ?? (_d.metrics = {});
230
- if (this.configuration.parameters.metrics) {
231
- (_e = this.configuration.parameters.metrics).labels ?? (_e.labels = {});
232
- (_f = this.configuration.parameters.metrics).config ?? (_f.config = {});
233
- (_g = this.configuration.parameters.metrics).prefix ?? (_g.prefix = "");
234
- }
235
- (_h = this.configuration).services ?? (_h.services = {});
236
- // Add CSRF origins filtering
237
- if (this.configuration.parameters.csrfOrigins) {
238
- this.registerCORSFilter(new OriginFilter(this.configuration.parameters.csrfOrigins));
239
- }
240
- // Add CSRF website filtering
241
- if (this.configuration.parameters.website) {
242
- this.registerCORSFilter(new WebsiteOriginFilter(this.configuration.parameters.website));
243
- }
244
- this.setGlobalContext(new GlobalContext(this));
245
- }
246
- /**
247
- * Register a cancelable process
248
- * @param interuptable
249
- */
250
- static registerInteruptableProcess(interuptable) {
251
- Core.get()?.interuptables.push(interuptable);
252
- }
253
- /**
254
- * Unregister a cancelable process
255
- * @param interuptable
256
- */
257
- static unregisterInteruptableProcess(interuptable) {
258
- let id = Core.get()?.interuptables.findIndex(i => i === interuptable);
259
- id ?? (id = -1);
260
- if (id >= 0) {
261
- Core.get().interuptables.splice(id, 1);
262
- }
263
- }
264
- /**
265
- * Get the current script location
266
- * @returns
267
- */
268
- getScriptUrl() {
269
- return import.meta.url;
270
- }
271
- /**
272
- * Return information on the singleton import and version
273
- * @param singleton
274
- * @returns
275
- */
276
- static getSingletonInfo(singleton) {
277
- let res = `- `;
278
- if (singleton.getScriptUrl) {
279
- res += singleton.getScriptUrl();
280
- }
281
- res += " / " + singleton.getVersion();
282
- return res;
283
- }
284
- /**
285
- * Get the singleton of Webda Core
286
- * @returns
287
- */
288
- static get() {
289
- // @ts-ignore
290
- const singleton = process.webda;
291
- if (Core.singleton !== singleton &&
292
- !singleton._dualImportWarn &&
293
- Core.singleton !== undefined &&
294
- singleton !== undefined) {
295
- singleton._dualImportWarn = true;
296
- singleton.log("ERROR", `Several import version of WebdaCore has been identified.\n\tIt can impact your models.\n\t- ${this.getSingletonInfo(singleton)}\n\t- ${this.getSingletonInfo(Core.singleton)}`);
297
- //process.exit(1);
298
- }
299
- // Store WebdaCore in process to avoid conflict with import
300
- return singleton;
301
- }
302
- /**
303
- * Enforce a specific store for a model
304
- *
305
- * Useful in some specific case when you want to update store dynamically
306
- *
307
- * @param model
308
- * @param store
309
- */
310
- setModelStore(model, store) {
311
- this._modelStoresCache.set(model, store);
312
- }
313
- /**
314
- * Get the store assigned to this model
315
- * @param model
316
- * @returns
317
- */
318
- getModelStore(modelOrConstructor) {
319
- const model = ((modelOrConstructor instanceof CoreModel ? modelOrConstructor.__class : modelOrConstructor));
320
- if (this._modelStoresCache.has(model)) {
321
- return this._modelStoresCache.get(model);
322
- }
323
- const setCache = store => {
324
- this._modelStoresCache.set(model, store);
325
- };
326
- const stores = this.getStores();
327
- let actualScore;
328
- let actualStore = this.getService(this.parameter("defaultStore") || "Registry");
329
- for (const store in stores) {
330
- const score = stores[store].handleModel(model);
331
- // As 0 mean exact match we stop there
332
- if (score === 0) {
333
- setCache(stores[store]);
334
- return stores[store];
335
- }
336
- else if (score > 0 && (actualScore === undefined || actualScore > score)) {
337
- actualScore = score;
338
- actualStore = stores[store];
339
- }
340
- }
341
- setCache(actualStore);
342
- return actualStore;
343
- }
344
- /**
345
- * Get the service that manage a model
346
- * @param modelOrConstructor
347
- * @param attribute
348
- * @returns
349
- */
350
- getBinaryStore(modelOrConstructor, attribute) {
351
- const binaries = this.getServicesOfType(BinaryService);
352
- const model = this.application.getModelName(modelOrConstructor);
353
- let actualScore = -1;
354
- let actualService;
355
- const setCache = store => {
356
- this._modelBinariesCache.set(model, store);
357
- };
358
- for (const binary in binaries) {
359
- const score = binaries[binary].handleBinary(model, attribute);
360
- // As 0 mean exact match we stop there
361
- if (score === 2) {
362
- setCache(binaries[binary]);
363
- return binaries[binary];
364
- }
365
- else if (score >= 0 && (actualService === undefined || actualScore > score)) {
366
- actualScore = score;
367
- actualService = binaries[binary];
368
- }
369
- }
370
- if (!actualService) {
371
- throw new Error("No binary store found for " + model + " " + attribute);
372
- }
373
- setCache(actualService);
374
- return actualService;
375
- }
376
- /**
377
- * Return Core instance id
378
- *
379
- * It is a random generated string
380
- */
381
- getInstanceId() {
382
- this.instanceId ?? (this.instanceId = this.getUuid());
383
- return this.instanceId;
384
- }
385
- /**
386
- * Get absolute url with subpath
387
- * @param subpath
388
- */
389
- getApiUrl(subpath = "") {
390
- if (subpath.length > 0 && !subpath.startsWith("/")) {
391
- subpath = "/" + subpath;
392
- }
393
- return this.configuration.parameters.apiUrl + subpath;
394
- }
395
- /**
396
- * Return application path with subpath
397
- *
398
- * Helper that redirect to this.application.getAppPath
399
- *
400
- * @param subpath
401
- * @returns
402
- */
403
- getAppPath(subpath = "") {
404
- return this.application.getAppPath(subpath);
405
- }
406
- /**
407
- * Retrieve all detected modules definition
408
- */
409
- getModules() {
410
- return this.application.getModules();
411
- }
412
- /**
413
- * Return application definition
414
- */
415
- getApplication() {
416
- return this.application;
417
- }
418
- /**
419
- * Get WorkerOutput
420
- */
421
- getWorkerOutput() {
422
- return this.workerOutput;
423
- }
424
- /**
425
- * Init one service
426
- * @param service
427
- */
428
- async initService(service) {
429
- try {
430
- this.log("TRACE", "Initializing service", service);
431
- this.services[service]._initTime = Date.now();
432
- await this.services[service].init();
433
- }
434
- catch (err) {
435
- this.services[service]._initException = err;
436
- this.failedServices[service] = { _initException: err };
437
- this.log("ERROR", "Init service " + service + " failed: " + err.message);
438
- this.log("TRACE", err.stack);
439
- }
440
- }
441
- /**
442
- * Get an object from the application based on its full uuid
443
- * @param fullUuid
444
- * @param partials
445
- */
446
- async getModelObject(fullUuid, partials) {
447
- return CoreModel.fromFullUuid(fullUuid, this, partials);
448
- }
449
- /**
450
- * Init Webda
451
- *
452
- * It will resolve Services init method and autolink
453
- */
454
- async init() {
455
- if (this._init) {
456
- return this._init;
457
- }
458
- if (this.configuration.parameters.configurationService) {
459
- try {
460
- this.log("INFO", `Using ConfigurationService '${this.configuration.parameters.configurationService}'`);
461
- // Create the configuration service
462
- this.createService(this.configuration.services, this.configuration.parameters.configurationService);
463
- const cfg = await this.getService(this.configuration.parameters.configurationService).initConfiguration();
464
- if (cfg) {
465
- this.configuration.parameters = deepmerge(this.configuration.parameters, cfg.parameters);
466
- // Ensure beans are known too
467
- Object.keys(this.getBeans())
468
- .filter(i => !(Array.isArray(this.configuration.parameters.ignoreBeans)
469
- ? this.configuration.parameters.ignoreBeans.includes(i)
470
- : this.configuration.parameters.ignoreBeans))
471
- .forEach(bean => {
472
- var _a;
473
- (_a = this.configuration.services)[bean] ?? (_a[bean] = {
474
- type: `Beans/${bean}`
475
- });
476
- });
477
- // Merge services - for security reason we cannot add new services from configuration
478
- for (const i in this.configuration.services) {
479
- this.configuration.services[i] = {
480
- ...deepmerge(this.configuration.services[i], cfg.services[i] || {}),
481
- type: this.configuration.services[i].type
482
- };
483
- }
484
- }
485
- await this.getService(this.configuration.parameters.configurationService).init();
486
- }
487
- catch (err) {
488
- this.log("ERROR", "Cannot use ConfigurationService", this.configuration.parameters.configurationService, err);
489
- this.services = {};
490
- }
491
- }
492
- // Init the other services
493
- this.initStatics();
494
- // Reset the model cache
495
- this._modelStoresCache.clear();
496
- this._modelBinariesCache.clear();
497
- this.log("TRACE", "Create Webda init promise");
498
- this._init = (async () => {
499
- await this.initService("Registry");
500
- await this.initService("CryptoService");
501
- // Init services
502
- let service;
503
- const inits = [];
504
- for (service in this.services) {
505
- if (this.services[service].init !== undefined &&
506
- !this.services[service]._createException &&
507
- !this.services[service]._initTime) {
508
- inits.push(this.initService(service));
509
- }
510
- }
511
- await Promise.all(inits);
512
- await this.emitSync("Webda.Init.Services", this.services);
513
- })();
514
- return this._init;
515
- }
516
- /**
517
- * Pause for time ms
518
- *
519
- * @param time ms
520
- */
521
- static async sleep(time) {
522
- return new Promise(resolve => {
523
- setTimeout(resolve, time);
524
- });
525
- }
526
- /**
527
- * Check if an operation can be executed with the current context
528
- * Not checking the input use `checkOperation` instead to check everything
529
- * @param context
530
- * @param operationId
531
- * @throws OperationError if operation is unknown
532
- * @returns true if operation can be executed
533
- */
534
- checkOperationPermission(context, operationId) {
535
- var _a;
536
- if (!this.operations[operationId]) {
537
- throw new WebdaError.NotFound(`${operationId} Unknown`);
538
- }
539
- if (this.operations[operationId].permission) {
540
- (_a = this.operations[operationId]).permissionQuery ?? (_a.permissionQuery = new WebdaQL.QueryValidator(this.operations[operationId].permission));
541
- return this.operations[operationId].permissionQuery.eval(context.getSession());
542
- }
543
- return true;
544
- }
545
- /**
546
- * Check if an operation can be executed with the current context
547
- * @param context
548
- * @param operationId
549
- */
550
- async checkOperation(context, operationId) {
551
- if (!this.checkOperationPermission(context, operationId)) {
552
- throw new WebdaError.Forbidden(`${operationId} PermissionDenied`);
553
- }
554
- try {
555
- if (this.operations[operationId].input) {
556
- const input = await context.getInput();
557
- if (input === undefined || this.validateSchema(this.operations[operationId].input, input) !== true) {
558
- throw new WebdaError.BadRequest(`${operationId} InvalidInput Empty input`);
559
- }
560
- }
561
- }
562
- catch (err) {
563
- if (err instanceof ValidationError) {
564
- throw new WebdaError.BadRequest(`${operationId} InvalidInput ${err.errors.map(e => e.message).join("; ")}`);
565
- }
566
- throw err;
567
- }
568
- try {
569
- if (this.operations[operationId].parameters) {
570
- this.validateSchema(this.operations[operationId].parameters, context.getParameters());
571
- }
572
- }
573
- catch (err) {
574
- if (err instanceof ValidationError) {
575
- throw new WebdaError.BadRequest(`${operationId} InvalidParameters ${err.errors.map(e => e.message).join("; ")}`);
576
- }
577
- throw err;
578
- }
579
- }
580
- /**
581
- * Call an operation within the framework
582
- */
583
- async callOperation(context, operationId) {
584
- context.setExtension("operation", operationId);
585
- await this.checkOperation(context, operationId);
586
- context.setExtension("operationContext", this.operations[operationId].context || {});
587
- return this.getService(this.operations[operationId].service)[this.operations[operationId].method](context);
588
- }
589
- /**
590
- * Get available operations
591
- * @returns
592
- */
593
- listOperations() {
594
- const list = {};
595
- Object.keys(this.operations).forEach(o => {
596
- list[o] = {
597
- ...this.operations[o]
598
- };
599
- delete list[o].service;
600
- delete list[o].method;
601
- });
602
- return list;
603
- }
604
- /**
605
- * Register a new operation within the app
606
- * @param operationId
607
- * @param definition
608
- */
609
- registerOperation(operationId, definition) {
610
- // Check operation naming convention
611
- if (!operationId.match(/^([A-Z][A-Za-z0-9]*\.)*([A-Z][a-zA-Z0-9]*)$/)) {
612
- throw new Error(`OperationId ${operationId} must match ^([A-Z][A-Za-z0-9]*.)*([A-Z][a-zA-Z0-9]*)$`);
613
- }
614
- // Check if service and method exist
615
- if (!this.getService(definition.service) ||
616
- typeof this.getService(definition.service)[definition.method] !== "function") {
617
- throw new Error(`Operation ${operationId} service ${definition.service} method ${definition.method} not found`);
618
- }
619
- // Add the operation
620
- // We will want to cache operations for faster startup
621
- this.operations[operationId] = { ...definition, id: operationId };
622
- ["input", "output"]
623
- .filter(key => this.operations[operationId][key])
624
- .forEach(key => {
625
- if (!this.getApplication().hasSchema(this.operations[operationId][key])) {
626
- delete this.operations[operationId][key];
627
- }
628
- });
629
- }
630
- /**
631
- * Register a request filtering
632
- *
633
- * Will apply to all requests regardless of the devMode
634
- * @param filter
635
- */
636
- registerRequestFilter(filter) {
637
- this._requestFilters.push(filter);
638
- }
639
- /**
640
- * Register a CORS request filtering
641
- *
642
- * Does not apply in devMode
643
- * @param filter
644
- */
645
- registerCORSFilter(filter) {
646
- this._requestCORSFilters.push(filter);
647
- }
648
- /**
649
- * Register a new context provider
650
- * @param provider
651
- */
652
- registerContextProvider(provider) {
653
- this._contextProviders.unshift(provider);
654
- }
655
- /**
656
- * Validate the object with schema
657
- *
658
- * @param schema path to use
659
- * @param object to validate
660
- */
661
- validateSchema(webdaObject, object, ignoreRequired) {
662
- let name = typeof webdaObject === "string" ? webdaObject : this.application.getModelFromInstance(webdaObject);
663
- let cacheName = name;
664
- if (name?.endsWith("?")) {
665
- name = name.substring(0, name.length - 1);
666
- ignoreRequired = true;
667
- }
668
- if (ignoreRequired) {
669
- cacheName += "_noRequired";
670
- }
671
- if (!this._ajvSchemas[cacheName]) {
672
- let schema = this.application.getSchema(name);
673
- if (!schema) {
674
- return null;
675
- }
676
- if (ignoreRequired) {
677
- schema = JSONUtils.duplicate(schema);
678
- schema.required = [];
679
- }
680
- this.log("TRACE", "Add schema for", name);
681
- this._ajv.addSchema(schema, cacheName);
682
- this._ajvSchemas[cacheName] = true;
683
- }
684
- if (this._ajv.validate(cacheName, object)) {
685
- return true;
686
- }
687
- throw new ValidationError(this._ajv.errors);
688
- }
689
- /**
690
- * Return webda current version
691
- *
692
- * @returns package version
693
- * @since 0.4.0
694
- */
695
- getVersion() {
696
- return this.getApplication().getWebdaVersion();
697
- }
698
- /**
699
- * To define the locales just add a locales: ['en-GB', 'fr-FR'] in your host global configuration
700
- *
701
- * @return The configured locales or "en-GB" if none are defined
702
- */
703
- getLocales() {
704
- if (!this.configuration || !this.configuration.parameters.locales) {
705
- return ["en-GB"];
706
- }
707
- return this.configuration.parameters.locales;
708
- }
709
- /**
710
- * Get a Logger for a class
711
- * @param clazz
712
- */
713
- getLogger(clazz) {
714
- let className = clazz;
715
- if (typeof clazz !== "string") {
716
- const definitions = this.application.getModdas();
717
- for (const i in definitions) {
718
- if (definitions[i] === clazz.constructor) {
719
- className = i.replace(/\//g, ".");
720
- break;
721
- }
722
- }
723
- }
724
- return new Logger(this.workerOutput, className);
725
- }
726
- /**
727
- * Add a route dynamicaly
728
- *
729
- * @param {String} url of the route can contains dynamic part like {uuid}
730
- * @param {Object} info the type of executor
731
- */
732
- addRoute(url, info) {
733
- this.router.addRoute(url, info);
734
- }
735
- /**
736
- * Remove a route dynamicly
737
- *
738
- * @param {String} url to remove
739
- */
740
- removeRoute(url) {
741
- this.router.removeRoute(url);
742
- }
743
- /**
744
- * Return current Router object
745
- */
746
- getRouter() {
747
- return this.router;
748
- }
749
- /**
750
- * Check for a service name and return the wanted singleton or undefined if none found
751
- *
752
- * @param {String} name The service name to retrieve
753
- */
754
- getService(name = "") {
755
- return this.services[name];
756
- }
757
- /**
758
- * Return a map of defined services
759
- * @returns {{}}
760
- */
761
- getServices() {
762
- return this.services;
763
- }
764
- /**
765
- * Return a map of services that extends type
766
- * @param type The type of implementation
767
- * @returns {{}}
768
- */
769
- getServicesOfType(type = undefined) {
770
- const result = {};
771
- for (const i in this.services) {
772
- const service = this.services[i];
773
- if (!type || service instanceof type) {
774
- result[i] = service;
775
- }
776
- }
777
- return result;
778
- }
779
- getConfiguration() {
780
- return this.configuration;
781
- }
782
- /**
783
- * Return a map of defined stores
784
- * @returns {{}}
785
- */
786
- getStores() {
787
- return this.getServicesOfType(Store);
788
- }
789
- /**
790
- * Return a map of defined models
791
- * @returns {{}}
792
- */
793
- getModels() {
794
- return this.application.getModels();
795
- }
796
- /**
797
- * Check for a model name and return the wanted class or throw exception if none found
798
- *
799
- * @param {String} name The model name to retrieve
800
- */
801
- getModel(name) {
802
- return this.application.getModel(name);
803
- }
804
- /**
805
- * Add to context information and executor based on the http context
806
- */
807
- updateContextWithRoute(ctx) {
808
- const http = ctx.getHttpContext();
809
- // Check mapping
810
- const route = this.router.getRouteFromUrl(ctx, http.getMethod(), http.getRelativeUri());
811
- if (route === undefined) {
812
- return false;
813
- }
814
- ctx.setRoute({ ...this.configuration, ...route });
815
- ctx.setExecutor(this.getService(route.executor));
816
- this.emit("Webda.UpdateContextRoute", { context: ctx });
817
- return true;
818
- }
819
- /**
820
- * Flush the headers to the response, no more header modification is possible after that
821
- *
822
- * This method should set the `context.setFlushedHeaders()` and use of `context.hasFlushedHeaders()`
823
- *
824
- * @abstract
825
- */
826
- flushHeaders(_context) {
827
- // Should be overriden by implementation
828
- }
829
- /**
830
- * Flush the entire response to the client
831
- */
832
- flush(_context) {
833
- // Should be overriden by implementation
834
- }
835
- /**
836
- * Return if Webda is in debug mode
837
- */
838
- isDebug() {
839
- return false;
840
- }
841
- /**
842
- * Return the global parameters of a domain
843
- */
844
- getGlobalParams() {
845
- return this.configuration.parameters || {};
846
- }
847
- /**
848
- * Get the system context
849
- * @returns
850
- */
851
- getGlobalContext() {
852
- return this.globalContext;
853
- }
854
- /**
855
- * Set the system context
856
- * @param context
857
- */
858
- setGlobalContext(context) {
859
- this.globalContext = context;
860
- }
861
- /**
862
- * Reinit one service
863
- * @param service
864
- */
865
- async reinitService(service) {
866
- try {
867
- this.log("TRACE", "Re-Initializing service", service);
868
- const serviceBean = this.services[service];
869
- await serviceBean.reinit(this.getServiceParams(serviceBean.getName()));
870
- }
871
- catch (err) {
872
- this.log("ERROR", "Re-Init service " + service + " failed", err);
873
- this.log("TRACE", err.stack);
874
- }
875
- }
876
- /**
877
- * Reinit all services with updated parameters
878
- * @param updates
879
- * @returns
880
- */
881
- async reinit(updates) {
882
- const configuration = JSON.parse(JSON.stringify(this.configuration.services));
883
- for (const service in updates) {
884
- jsonpath.value(configuration, service, updates[service]);
885
- }
886
- if (JSON.stringify(Object.keys(configuration)) !== JSON.stringify(Object.keys(this.configuration.services))) {
887
- this.log("ERROR", "Configuration update cannot modify services");
888
- throw new WebdaError.CodeError("REINIT_SERVICE_INJECTION", "Configuration is not designed to add dynamically services");
889
- }
890
- this.configuration.services = configuration;
891
- const inits = [];
892
- for (const service in this.services) {
893
- inits.push(this.reinitService(service));
894
- }
895
- await Promise.all(inits);
896
- }
897
- /**
898
- * Get a full resolved service parameter
899
- *
900
- * @param service
901
- * @param configuration
902
- * @returns
903
- */
904
- getServiceParams(service, configuration = { parameters: {}, services: {} }) {
905
- var _a;
906
- configuration.parameters ?? (configuration.parameters = {});
907
- configuration.services ?? (configuration.services = {});
908
- (_a = configuration.services)[service] ?? (_a[service] = {});
909
- const params = deepmerge(this.configuration.parameters || {}, configuration.parameters || {}, this.configuration.services[service] || {}, configuration.services[service] || {});
910
- delete params.require;
911
- return params;
912
- }
913
- createService(services, service) {
914
- let type = services[service]?.type;
915
- if (type === undefined) {
916
- type = service;
917
- }
918
- let serviceConstructor = undefined;
919
- try {
920
- serviceConstructor = this.application.getModda(type);
921
- }
922
- catch (ex) {
923
- this.log("ERROR", `Create service ${service}(${type}) failed ${ex.message}`);
924
- this.log("TRACE", ex.stack);
925
- return;
926
- }
927
- try {
928
- this.log("TRACE", "Constructing service", service);
929
- this.services[service] = new serviceConstructor(this, service, this.getServiceParams(service));
930
- }
931
- catch (err) {
932
- this.log("ERROR", "Cannot create service", service, err);
933
- // @ts-ignore
934
- this.failedServices[service] = { _createException: err };
935
- }
936
- }
937
- getBeans() {
938
- // @ts-ignore
939
- return process.webdaBeans || {};
940
- }
941
- /**
942
- * @hidden
943
- *
944
- */
945
- createServices(excludes = []) {
946
- const services = this.configuration.services;
947
- let beans = this.getBeans();
948
- if (this.configuration.parameters.ignoreBeans) {
949
- if (Array.isArray(this.configuration.parameters.ignoreBeans)) {
950
- this.configuration.parameters.ignoreBeans.forEach(bean => {
951
- delete beans[bean];
952
- });
953
- }
954
- else {
955
- beans = {};
956
- }
957
- }
958
- this.log("DEBUG", "BEANS", beans, "IGNORING", this.configuration.parameters.ignoreBeans);
959
- for (const i in beans) {
960
- const name = beans[i].name;
961
- if (!services[name]) {
962
- services[name] = {};
963
- }
964
- // Force type to Bean
965
- services[name].type = `Beans/${name}`;
966
- // Register the type
967
- this.application.addService(`Beans/${name}`, beans[i]);
968
- }
969
- // Construct services
970
- for (const service in services) {
971
- if (excludes.indexOf(service) >= 0) {
972
- continue;
973
- }
974
- this.createService(services, service);
975
- }
976
- // Call resolve on all services
977
- Object.keys(this.services)
978
- .filter(s => !excludes.includes(s))
979
- .forEach(s => {
980
- try {
981
- this.services[s].resolve();
982
- }
983
- catch (err) {
984
- this.log("ERROR", `Service(${s})`, err);
985
- }
986
- });
987
- this.emit("Webda.Create.Services", this.services);
988
- }
989
- /**
990
- * A registry is a predefined store
991
- * @returns
992
- */
993
- getRegistry() {
994
- return this.registry;
995
- }
996
- /**
997
- * Return the crypto service
998
- * @returns
999
- */
1000
- getCrypto() {
1001
- return this.cryptoService;
1002
- }
1003
- /**
1004
- * Stop all services
1005
- */
1006
- async stop() {
1007
- const services = this.getServices();
1008
- await Promise.all(Object.keys(services).map(async (s) => {
1009
- try {
1010
- await services[s].stop();
1011
- }
1012
- catch (err) {
1013
- this.log("ERROR", `Cannot stop service ${s}`, err);
1014
- }
1015
- }));
1016
- }
1017
- jsonFilter(key, value) {
1018
- if (key[0] === "_")
1019
- return undefined;
1020
- return value;
1021
- }
1022
- static getMachineId() {
1023
- try {
1024
- return process.env["WEBDA_MACHINE_ID"] || machineIdSync();
1025
- /* c8 ignore next 4 */
1026
- }
1027
- catch (err) {
1028
- // Useful in k8s pod
1029
- return process.env["HOSTNAME"];
1030
- }
1031
- }
1032
- /**
1033
- * Init services and Beans along with Routes
1034
- */
1035
- initStatics() {
1036
- var _a, _b, _c;
1037
- // Init the registry
1038
- const autoRegistry = this.configuration.services["Registry"] === undefined;
1039
- (_a = this.configuration.services)["Registry"] ?? (_a["Registry"] = {
1040
- type: "Webda/MemoryStore",
1041
- persistence: {
1042
- path: ".registry",
1043
- key: Core.getMachineId()
1044
- }
1045
- });
1046
- this.createService(this.configuration.services, "Registry");
1047
- this.registry = this.getService("Registry").resolve();
1048
- // Init the key service
1049
- (_b = this.configuration.services)["CryptoService"] ?? (_b["CryptoService"] = {
1050
- type: "Webda/CryptoService",
1051
- autoRotate: autoRegistry ? 30 : undefined,
1052
- autoCreate: true
1053
- });
1054
- this.createService(this.configuration.services, "CryptoService");
1055
- this.cryptoService = this.getService("CryptoService").resolve();
1056
- // Session Manager
1057
- (_c = this.configuration.services)["SessionManager"] ?? (_c["SessionManager"] = {
1058
- type: "Webda/CookieSessionManager"
1059
- });
1060
- if (this.configuration.services !== undefined) {
1061
- const excludes = ["Registry", "CryptoService"];
1062
- if (this.configuration.parameters.configurationService) {
1063
- excludes.push(this.configuration.parameters.configurationService);
1064
- }
1065
- // Do not recreate the configuration services
1066
- this.createServices(excludes);
1067
- }
1068
- this.router.remapRoutes();
1069
- this._initiated = true;
1070
- this.emit("Webda.Init", this.configuration);
1071
- }
1072
- /**
1073
- * Get a context based on the info
1074
- * @param info
1075
- * @returns
1076
- */
1077
- async newContext(info, noInit = false) {
1078
- let context;
1079
- this._contextProviders.find(provider => (context = provider.getContext(info)) !== undefined);
1080
- if (!noInit) {
1081
- await context.init();
1082
- }
1083
- await this.emitSync("Webda.NewContext", { context, info });
1084
- return context;
1085
- }
1086
- /**
1087
- * Create a new context for a request
1088
- *
1089
- * @class Service
1090
- * @param httpContext THe HTTP request context
1091
- * @param stream - The request output stream if any
1092
- * @return A new context object to pass along
1093
- */
1094
- async newWebContext(httpContext, stream = undefined, noInit = false) {
1095
- return await this.newContext({ http: httpContext, stream: stream });
1096
- }
1097
- /**
1098
- * Convert an object to JSON using the Webda json filter
1099
- *
1100
- * @class Service
1101
- * @param {Object} object - The object to export
1102
- * @return {String} The export of the strip object ( removed all attribute with _ )
1103
- */
1104
- toPublicJSON(object) {
1105
- return JSON.stringify(object, this.jsonFilter);
1106
- }
1107
- /**
1108
- * Return a UUID
1109
- *
1110
- * @param format to return different type of format
1111
- * Plan to implement base64 and maybe base85
1112
- */
1113
- getUuid(format = "uuid") {
1114
- const uid = randomUUID();
1115
- if (format === "uuid") {
1116
- return uid;
1117
- }
1118
- const buffer = Buffer.from(uid.replace(/-/g, ""), "hex");
1119
- if (format === "base64") {
1120
- // Remove useless = we won't transfer back to original value or could just add ==
1121
- // https://datatracker.ietf.org/doc/html/rfc4648#page-7
1122
- return buffer.toString(format).replace(/=/g, "").replace(/\//g, "_").replace(/\+/g, "-");
1123
- }
1124
- return buffer.toString(format);
1125
- }
1126
- /**
1127
- * @override
1128
- */
1129
- emit(eventType, event, ...data) {
1130
- return super.emit(eventType, event, ...data);
1131
- }
1132
- /**
1133
- * Emit the event with data and wait for Promise to finish if listener returned a Promise
1134
- */
1135
- emitSync(eventType, event, ...data) {
1136
- let result;
1137
- const promises = [];
1138
- const listeners = this.listeners(eventType);
1139
- for (const listener of listeners) {
1140
- result = listener(event, ...data);
1141
- if (result instanceof Promise) {
1142
- promises.push(result);
1143
- }
1144
- }
1145
- return Promise.all(promises);
1146
- }
1147
- /**
1148
- * Type the listener part
1149
- * @param event
1150
- * @param listener
1151
- * @param queue
1152
- * @returns
1153
- */
1154
- on(event, listener) {
1155
- super.on(event, listener);
1156
- return this;
1157
- }
1158
- /**
1159
- * Logs
1160
- * @param level
1161
- * @param args
1162
- */
1163
- log(level, ...args) {
1164
- this.logger.log(level, ...args);
1165
- }
1166
- /**
1167
- * Retrieve a global parameter
1168
- */
1169
- parameter(name) {
1170
- return this.getGlobalParams()[name];
1171
- }
1172
- /**
1173
- * Verify if a request can be done
1174
- *
1175
- * @param context Context of the request
1176
- */
1177
- async checkRequest(ctx) {
1178
- // Do not need to filter on OPTIONS as CORS is for that
1179
- if (ctx.getHttpContext().getMethod() === "OPTIONS" || this._requestFilters.length === 0) {
1180
- return true;
1181
- }
1182
- return (await Promise.all(this._requestFilters.map(filter => filter.checkRequest(ctx, "AUTH")))).some(v => v);
1183
- }
1184
- /**
1185
- * Verify if an origin is allowed to do request on the API
1186
- *
1187
- * @param context Context of the request
1188
- */
1189
- async checkCORSRequest(ctx) {
1190
- return (await Promise.all(this._requestCORSFilters.map(filter => filter.checkRequest(ctx, "CORS")))).some(v => v);
1191
- }
1192
- /**
1193
- * Export OpenAPI
1194
- * @param skipHidden
1195
- * @returns
1196
- */
1197
- exportOpenAPI(skipHidden = true) {
1198
- var _a, _b, _c;
1199
- const packageInfo = this.application.getPackageDescription();
1200
- let contact;
1201
- if (typeof packageInfo.author === "string") {
1202
- contact = {
1203
- name: packageInfo.author
1204
- };
1205
- }
1206
- else if (packageInfo.author) {
1207
- contact = packageInfo.author;
1208
- }
1209
- let license;
1210
- if (typeof packageInfo.license === "string") {
1211
- license = {
1212
- name: packageInfo.license
1213
- };
1214
- }
1215
- else if (packageInfo.license) {
1216
- license = packageInfo.license;
1217
- }
1218
- const openapi = deepmerge({
1219
- openapi: "3.0.3",
1220
- info: {
1221
- description: packageInfo.description,
1222
- version: packageInfo.version || "0.0.0",
1223
- title: packageInfo.title || "Webda-based application",
1224
- termsOfService: packageInfo.termsOfService,
1225
- contact,
1226
- license
1227
- },
1228
- components: {
1229
- schemas: {
1230
- Object: {
1231
- type: "object"
1232
- }
1233
- }
1234
- },
1235
- paths: {},
1236
- tags: []
1237
- }, this.application.getConfiguration().openapi || {});
1238
- const models = this.application.getModels();
1239
- const schemas = this.application.getSchemas();
1240
- // Copy all input/output from actions
1241
- for (const i in schemas) {
1242
- if (!(i.endsWith(".input") || i.endsWith(".output"))) {
1243
- continue;
1244
- }
1245
- // @ts-ignore
1246
- (_a = openapi.components.schemas)[i] ?? (_a[i] = schemas[i]);
1247
- // Not sure how to test following
1248
- /* c8 ignore next 5 */
1249
- for (const j in schemas[i].definitions) {
1250
- // @ts-ignore
1251
- (_b = openapi.components.schemas)[j] ?? (_b[j] = schemas[i].definitions[j]);
1252
- }
1253
- }
1254
- for (const i in models) {
1255
- const model = models[i];
1256
- let desc = {
1257
- type: "object"
1258
- };
1259
- const modelName = model.name || i.split("/").pop();
1260
- const schema = this.application.getSchema(i);
1261
- if (schema) {
1262
- for (const j in schema.definitions) {
1263
- // @ts-ignore
1264
- (_c = openapi.components.schemas)[j] ?? (_c[j] = schema.definitions[j]);
1265
- }
1266
- delete schema.definitions;
1267
- desc = schema;
1268
- }
1269
- // Remove empty required as openapi does not like that
1270
- // Our compiler is not generating this anymore but it is additional protection
1271
- /* c8 ignore next 3 */
1272
- if (desc.required && desc.required.length === 0) {
1273
- delete desc.required;
1274
- }
1275
- // Remove $schema
1276
- delete desc.$schema;
1277
- // Rename all #/definitions/ by #/components/schemas/
1278
- openapi.components.schemas[modelName] = JSON.parse(JSON.stringify(desc).replace(/#\/definitions\//g, "#/components/schemas/"));
1279
- }
1280
- this.router.completeOpenAPI(openapi, skipHidden);
1281
- openapi.tags.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
1282
- const paths = {};
1283
- Object.keys(openapi.paths)
1284
- .sort()
1285
- .forEach(i => (paths[i] = openapi.paths[i]));
1286
- openapi.paths = paths;
1287
- return openapi;
1288
- }
1289
- /**
1290
- * Get a metric object
1291
- *
1292
- * Use the Service.getMetric method if possible
1293
- *
1294
- * This is map from prometheus 3 types of metrics
1295
- * Our hope is that we can adapt them to export to other
1296
- * metrics system if needed
1297
- *
1298
- * @param type
1299
- * @param configuration
1300
- * @returns
1301
- */
1302
- getMetric(type, configuration) {
1303
- const metrics = this.getGlobalParams().metrics;
1304
- if (metrics === false) {
1305
- // Return a mock
1306
- return {
1307
- inc: () => { },
1308
- reset: () => { },
1309
- labels: () => undefined,
1310
- remove: () => { },
1311
- observe: () => { },
1312
- startTimer: () => {
1313
- return () => 0;
1314
- },
1315
- zero: () => { },
1316
- dec: () => { },
1317
- setToCurrentTime: () => { },
1318
- set: () => { }
1319
- };
1320
- }
1321
- const name = `${metrics.prefix}webda_${configuration.name}`;
1322
- const labelNames = [...(configuration.labelNames || []), ...Object.keys(metrics.labels)];
1323
- // Will probably need to override with a staticLabels property
1324
- return (register.getSingleMetric(name) ||
1325
- new type({
1326
- ...configuration,
1327
- ...metrics.config[configuration.name],
1328
- name,
1329
- labelNames
1330
- }));
1331
- }
1332
- }
1333
- export { Counter, Gauge, Histogram };
1334
- //# sourceMappingURL=core.js.map