@webda/core 4.0.0-beta.1 → 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 (675) 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/application/unpackedapplication.d.ts +104 -0
  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 -49
  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 +45 -19
  63. package/lib/contexts/httpcontext.d.ts.map +1 -0
  64. package/lib/{utils → contexts}/httpcontext.js +102 -34
  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 +84 -51
  119. package/lib/index.d.ts.map +1 -0
  120. package/lib/index.js +82 -59
  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 +21 -77
  155. package/lib/models/aclmodel.d.ts.map +1 -0
  156. package/lib/models/aclmodel.js +27 -204
  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 +2 -1
  167. package/lib/models/deployment.d.ts.map +1 -0
  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.model.js +53 -0
  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.service.d.ts +72 -0
  197. package/lib/queues/memoryqueue.service.d.ts.map +1 -0
  198. package/lib/queues/memoryqueue.service.js +136 -0
  199. package/lib/queues/memoryqueue.service.js.map +1 -0
  200. package/lib/queues/pubsubservice.d.ts +9 -6
  201. package/lib/queues/pubsubservice.d.ts.map +1 -0
  202. package/lib/queues/pubsubservice.js +5 -4
  203. package/lib/queues/pubsubservice.js.map +1 -1
  204. package/lib/queues/queueservice.d.ts +10 -11
  205. package/lib/queues/queueservice.d.ts.map +1 -0
  206. package/lib/queues/queueservice.js +48 -20
  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 -58
  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 +19 -13
  245. package/lib/services/cloudbinary.d.ts.map +1 -0
  246. package/lib/services/cloudbinary.js +24 -18
  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} +77 -142
  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.service.js +66 -0
  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 -10
  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 +58 -31
  297. package/lib/services/oauth.d.ts.map +1 -0
  298. package/lib/services/oauth.js +365 -251
  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 -11
  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.service.d.ts +121 -0
  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 +88 -189
  313. package/lib/services/service.d.ts.map +1 -0
  314. package/lib/services/service.js +407 -432
  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 -18
  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 +127 -768
  345. package/lib/stores/store.d.ts.map +1 -0
  346. package/lib/stores/store.js +258 -1718
  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 +5 -2
  377. package/lib/utils/abstractdeployer.d.ts.map +1 -0
  378. package/lib/utils/abstractdeployer.js +3 -0
  379. package/lib/utils/abstractdeployer.js.map +1 -1
  380. package/package.json +85 -56
  381. package/test/cachedapp/webda.config.json +1 -5
  382. package/test/config-cached.json +1 -5
  383. package/test/config.json +6 -99
  384. package/test/data/.env +1 -0
  385. package/test/my-cnf.json +9 -0
  386. package/webda.module.json +3462 -2231
  387. package/lib/application.d.ts +0 -876
  388. package/lib/application.js +0 -741
  389. package/lib/application.js.map +0 -1
  390. package/lib/application.spec.d.ts +0 -1
  391. package/lib/application.spec.js +0 -234
  392. package/lib/application.spec.js.map +0 -1
  393. package/lib/core.d.ts +0 -740
  394. package/lib/core.js +0 -1310
  395. package/lib/core.js.map +0 -1
  396. package/lib/core.spec.d.ts +0 -1
  397. package/lib/core.spec.js +0 -761
  398. package/lib/core.spec.js.map +0 -1
  399. package/lib/errors.d.ts +0 -65
  400. package/lib/errors.js +0 -113
  401. package/lib/errors.js.map +0 -1
  402. package/lib/errors.spec.d.ts +0 -1
  403. package/lib/errors.spec.js +0 -33
  404. package/lib/errors.spec.js.map +0 -1
  405. package/lib/models/aclmodel.spec.d.ts +0 -1
  406. package/lib/models/aclmodel.spec.js +0 -187
  407. package/lib/models/aclmodel.spec.js.map +0 -1
  408. package/lib/models/coremodel.d.ts +0 -887
  409. package/lib/models/coremodel.js +0 -1208
  410. package/lib/models/coremodel.js.map +0 -1
  411. package/lib/models/coremodel.spec.d.ts +0 -1
  412. package/lib/models/coremodel.spec.js +0 -462
  413. package/lib/models/coremodel.spec.js.map +0 -1
  414. package/lib/models/ident.d.ts +0 -53
  415. package/lib/models/ident.js +0 -40
  416. package/lib/models/ident.js.map +0 -1
  417. package/lib/models/ident.spec.d.ts +0 -1
  418. package/lib/models/ident.spec.js +0 -43
  419. package/lib/models/ident.spec.js.map +0 -1
  420. package/lib/models/ownermodel.d.ts +0 -50
  421. package/lib/models/ownermodel.js +0 -65
  422. package/lib/models/ownermodel.js.map +0 -1
  423. package/lib/models/ownermodel.spec.d.ts +0 -1
  424. package/lib/models/ownermodel.spec.js +0 -191
  425. package/lib/models/ownermodel.spec.js.map +0 -1
  426. package/lib/models/relations.d.ts +0 -181
  427. package/lib/models/relations.js +0 -157
  428. package/lib/models/relations.js.map +0 -1
  429. package/lib/models/relations.spec.d.ts +0 -12
  430. package/lib/models/relations.spec.js +0 -224
  431. package/lib/models/relations.spec.js.map +0 -1
  432. package/lib/models/rolemodel.d.ts +0 -10
  433. package/lib/models/rolemodel.js +0 -35
  434. package/lib/models/rolemodel.js.map +0 -1
  435. package/lib/models/rolemodel.spec.d.ts +0 -1
  436. package/lib/models/rolemodel.spec.js +0 -86
  437. package/lib/models/rolemodel.spec.js.map +0 -1
  438. package/lib/models/user.d.ts +0 -100
  439. package/lib/models/user.js +0 -157
  440. package/lib/models/user.js.map +0 -1
  441. package/lib/models/user.spec.d.ts +0 -1
  442. package/lib/models/user.spec.js +0 -88
  443. package/lib/models/user.spec.js.map +0 -1
  444. package/lib/queues/filequeue.d.ts +0 -58
  445. package/lib/queues/filequeue.js +0 -131
  446. package/lib/queues/filequeue.js.map +0 -1
  447. package/lib/queues/filequeue.spec.d.ts +0 -1
  448. package/lib/queues/filequeue.spec.js +0 -78
  449. package/lib/queues/filequeue.spec.js.map +0 -1
  450. package/lib/queues/memoryqueue.d.ts +0 -45
  451. package/lib/queues/memoryqueue.js +0 -81
  452. package/lib/queues/memoryqueue.js.map +0 -1
  453. package/lib/queues/memoryqueue.spec.d.ts +0 -1
  454. package/lib/queues/memoryqueue.spec.js +0 -192
  455. package/lib/queues/memoryqueue.spec.js.map +0 -1
  456. package/lib/queues/queue.spec.d.ts +0 -5
  457. package/lib/queues/queue.spec.js +0 -55
  458. package/lib/queues/queue.spec.js.map +0 -1
  459. package/lib/router.d.ts +0 -172
  460. package/lib/router.js +0 -419
  461. package/lib/router.js.map +0 -1
  462. package/lib/router.spec.d.ts +0 -1
  463. package/lib/router.spec.js +0 -229
  464. package/lib/router.spec.js.map +0 -1
  465. package/lib/services/asyncevents.d.ts +0 -151
  466. package/lib/services/asyncevents.js +0 -217
  467. package/lib/services/asyncevents.js.map +0 -1
  468. package/lib/services/asyncevents.spec.d.ts +0 -1
  469. package/lib/services/asyncevents.spec.js +0 -118
  470. package/lib/services/asyncevents.spec.js.map +0 -1
  471. package/lib/services/authentication.js +0 -772
  472. package/lib/services/authentication.js.map +0 -1
  473. package/lib/services/authentication.spec.d.ts +0 -1
  474. package/lib/services/authentication.spec.js +0 -458
  475. package/lib/services/authentication.spec.js.map +0 -1
  476. package/lib/services/binary.d.ts +0 -549
  477. package/lib/services/binary.js +0 -986
  478. package/lib/services/binary.js.map +0 -1
  479. package/lib/services/binary.spec.d.ts +0 -44
  480. package/lib/services/binary.spec.js +0 -438
  481. package/lib/services/binary.spec.js.map +0 -1
  482. package/lib/services/cloudbinary.spec.d.ts +0 -13
  483. package/lib/services/cloudbinary.spec.js +0 -192
  484. package/lib/services/cloudbinary.spec.js.map +0 -1
  485. package/lib/services/configuration.js +0 -178
  486. package/lib/services/configuration.js.map +0 -1
  487. package/lib/services/configuration.spec.d.ts +0 -1
  488. package/lib/services/configuration.spec.js +0 -87
  489. package/lib/services/configuration.spec.js.map +0 -1
  490. package/lib/services/cron.d.ts +0 -73
  491. package/lib/services/cron.js +0 -141
  492. package/lib/services/cron.js.map +0 -1
  493. package/lib/services/cron.spec.d.ts +0 -1
  494. package/lib/services/cron.spec.js +0 -76
  495. package/lib/services/cron.spec.js.map +0 -1
  496. package/lib/services/cryptoservice.js +0 -434
  497. package/lib/services/cryptoservice.js.map +0 -1
  498. package/lib/services/cryptoservice.spec.d.ts +0 -1
  499. package/lib/services/cryptoservice.spec.js +0 -177
  500. package/lib/services/cryptoservice.spec.js.map +0 -1
  501. package/lib/services/debugmailer.d.ts +0 -36
  502. package/lib/services/debugmailer.js +0 -52
  503. package/lib/services/debugmailer.js.map +0 -1
  504. package/lib/services/debugmailer.spec.d.ts +0 -1
  505. package/lib/services/debugmailer.spec.js +0 -29
  506. package/lib/services/debugmailer.spec.js.map +0 -1
  507. package/lib/services/domainservice.d.ts +0 -152
  508. package/lib/services/domainservice.js +0 -881
  509. package/lib/services/domainservice.js.map +0 -1
  510. package/lib/services/domainservice.spec.d.ts +0 -1
  511. package/lib/services/domainservice.spec.js +0 -401
  512. package/lib/services/domainservice.spec.js.map +0 -1
  513. package/lib/services/filebinary.d.ts +0 -133
  514. package/lib/services/filebinary.js +0 -371
  515. package/lib/services/filebinary.js.map +0 -1
  516. package/lib/services/filebinary.spec.d.ts +0 -21
  517. package/lib/services/filebinary.spec.js +0 -415
  518. package/lib/services/filebinary.spec.js.map +0 -1
  519. package/lib/services/fileconfiguration.d.ts +0 -22
  520. package/lib/services/fileconfiguration.js +0 -48
  521. package/lib/services/fileconfiguration.js.map +0 -1
  522. package/lib/services/fileconfiguration.spec.d.ts +0 -1
  523. package/lib/services/fileconfiguration.spec.js +0 -177
  524. package/lib/services/fileconfiguration.spec.js.map +0 -1
  525. package/lib/services/invitationservice.d.ts +0 -222
  526. package/lib/services/invitationservice.js +0 -526
  527. package/lib/services/invitationservice.js.map +0 -1
  528. package/lib/services/invitationservice.spec.d.ts +0 -1
  529. package/lib/services/invitationservice.spec.js +0 -516
  530. package/lib/services/invitationservice.spec.js.map +0 -1
  531. package/lib/services/kubernetesconfiguration.d.ts +0 -26
  532. package/lib/services/kubernetesconfiguration.js +0 -54
  533. package/lib/services/kubernetesconfiguration.js.map +0 -1
  534. package/lib/services/kubernetesconfiguration.spec.d.ts +0 -1
  535. package/lib/services/kubernetesconfiguration.spec.js +0 -147
  536. package/lib/services/kubernetesconfiguration.spec.js.map +0 -1
  537. package/lib/services/mailer.d.ts +0 -165
  538. package/lib/services/mailer.js +0 -176
  539. package/lib/services/mailer.js.map +0 -1
  540. package/lib/services/mailer.spec.d.ts +0 -1
  541. package/lib/services/mailer.spec.js +0 -144
  542. package/lib/services/mailer.spec.js.map +0 -1
  543. package/lib/services/notificationservice.js.map +0 -1
  544. package/lib/services/notificationservice.spec.d.ts +0 -1
  545. package/lib/services/notificationservice.spec.js +0 -78
  546. package/lib/services/notificationservice.spec.js.map +0 -1
  547. package/lib/services/oauth.spec.d.ts +0 -1
  548. package/lib/services/oauth.spec.js +0 -184
  549. package/lib/services/oauth.spec.js.map +0 -1
  550. package/lib/services/prometheus.js +0 -160
  551. package/lib/services/prometheus.js.map +0 -1
  552. package/lib/services/prometheus.spec.d.ts +0 -1
  553. package/lib/services/prometheus.spec.js +0 -57
  554. package/lib/services/prometheus.spec.js.map +0 -1
  555. package/lib/services/resource.d.ts +0 -87
  556. package/lib/services/resource.js +0 -156
  557. package/lib/services/resource.js.map +0 -1
  558. package/lib/services/resource.spec.d.ts +0 -1
  559. package/lib/services/resource.spec.js +0 -122
  560. package/lib/services/resource.spec.js.map +0 -1
  561. package/lib/services/service.spec.d.ts +0 -1
  562. package/lib/services/service.spec.js +0 -268
  563. package/lib/services/service.spec.js.map +0 -1
  564. package/lib/stores/aggregator.d.ts +0 -41
  565. package/lib/stores/aggregator.js +0 -80
  566. package/lib/stores/aggregator.js.map +0 -1
  567. package/lib/stores/aliasstore.d.ts +0 -108
  568. package/lib/stores/aliasstore.js +0 -168
  569. package/lib/stores/aliasstore.js.map +0 -1
  570. package/lib/stores/aliasstore.spec.d.ts +0 -11
  571. package/lib/stores/aliasstore.spec.js +0 -89
  572. package/lib/stores/aliasstore.spec.js.map +0 -1
  573. package/lib/stores/file.d.ts +0 -107
  574. package/lib/stores/file.js +0 -188
  575. package/lib/stores/file.js.map +0 -1
  576. package/lib/stores/file.spec.d.ts +0 -19
  577. package/lib/stores/file.spec.js +0 -232
  578. package/lib/stores/file.spec.js.map +0 -1
  579. package/lib/stores/mapper.d.ts +0 -149
  580. package/lib/stores/mapper.js +0 -293
  581. package/lib/stores/mapper.js.map +0 -1
  582. package/lib/stores/mapper.spec.d.ts +0 -1
  583. package/lib/stores/mapper.spec.js +0 -160
  584. package/lib/stores/mapper.spec.js.map +0 -1
  585. package/lib/stores/memory.d.ts +0 -151
  586. package/lib/stores/memory.js +0 -371
  587. package/lib/stores/memory.js.map +0 -1
  588. package/lib/stores/memory.spec.d.ts +0 -20
  589. package/lib/stores/memory.spec.js +0 -328
  590. package/lib/stores/memory.spec.js.map +0 -1
  591. package/lib/stores/modelmapper.d.ts +0 -61
  592. package/lib/stores/modelmapper.js +0 -199
  593. package/lib/stores/modelmapper.js.map +0 -1
  594. package/lib/stores/store.spec.d.ts +0 -65
  595. package/lib/stores/store.spec.js +0 -906
  596. package/lib/stores/store.spec.js.map +0 -1
  597. package/lib/test.d.ts +0 -162
  598. package/lib/test.js +0 -399
  599. package/lib/test.js.map +0 -1
  600. package/lib/unpackedapplication.d.ts +0 -76
  601. package/lib/unpackedapplication.js +0 -299
  602. package/lib/unpackedapplication.js.map +0 -1
  603. package/lib/utils/abstractdeployer.spec.d.ts +0 -1
  604. package/lib/utils/abstractdeployer.spec.js +0 -21
  605. package/lib/utils/abstractdeployer.spec.js.map +0 -1
  606. package/lib/utils/case.d.ts +0 -7
  607. package/lib/utils/case.js +0 -43
  608. package/lib/utils/case.js.map +0 -1
  609. package/lib/utils/case.spec.d.ts +0 -1
  610. package/lib/utils/case.spec.js +0 -50
  611. package/lib/utils/case.spec.js.map +0 -1
  612. package/lib/utils/context.d.ts +0 -462
  613. package/lib/utils/context.js +0 -732
  614. package/lib/utils/context.js.map +0 -1
  615. package/lib/utils/context.spec.d.ts +0 -9
  616. package/lib/utils/context.spec.js +0 -372
  617. package/lib/utils/context.spec.js.map +0 -1
  618. package/lib/utils/cookie.js.map +0 -1
  619. package/lib/utils/cookie.spec.d.ts +0 -1
  620. package/lib/utils/cookie.spec.js +0 -78
  621. package/lib/utils/cookie.spec.js.map +0 -1
  622. package/lib/utils/esm.d.ts +0 -13
  623. package/lib/utils/esm.js +0 -19
  624. package/lib/utils/esm.js.map +0 -1
  625. package/lib/utils/httpcontext.js.map +0 -1
  626. package/lib/utils/httpcontext.spec.d.ts +0 -4
  627. package/lib/utils/httpcontext.spec.js +0 -77
  628. package/lib/utils/httpcontext.spec.js.map +0 -1
  629. package/lib/utils/logger.d.ts +0 -91
  630. package/lib/utils/logger.js +0 -121
  631. package/lib/utils/logger.js.map +0 -1
  632. package/lib/utils/logger.spec.d.ts +0 -1
  633. package/lib/utils/logger.spec.js +0 -48
  634. package/lib/utils/logger.spec.js.map +0 -1
  635. package/lib/utils/serializers.d.ts +0 -161
  636. package/lib/utils/serializers.js +0 -420
  637. package/lib/utils/serializers.js.map +0 -1
  638. package/lib/utils/serializers.spec.d.ts +0 -1
  639. package/lib/utils/serializers.spec.js +0 -313
  640. package/lib/utils/serializers.spec.js.map +0 -1
  641. package/lib/utils/session.d.ts +0 -126
  642. package/lib/utils/session.js +0 -166
  643. package/lib/utils/session.js.map +0 -1
  644. package/lib/utils/session.spec.d.ts +0 -1
  645. package/lib/utils/session.spec.js +0 -71
  646. package/lib/utils/session.spec.js.map +0 -1
  647. package/lib/utils/throttler.d.ts +0 -102
  648. package/lib/utils/throttler.js +0 -168
  649. package/lib/utils/throttler.js.map +0 -1
  650. package/lib/utils/throttler.spec.d.ts +0 -1
  651. package/lib/utils/throttler.spec.js +0 -55
  652. package/lib/utils/throttler.spec.js.map +0 -1
  653. package/lib/utils/waiter.d.ts +0 -93
  654. package/lib/utils/waiter.js +0 -148
  655. package/lib/utils/waiter.js.map +0 -1
  656. package/lib/utils/waiter.spec.d.ts +0 -1
  657. package/lib/utils/waiter.spec.js +0 -98
  658. package/lib/utils/waiter.spec.js.map +0 -1
  659. package/test/config-file-missing-file-no-default.json +0 -44
  660. package/test/config-file-missing-file.json +0 -55
  661. package/test/config-file-no-reload.json +0 -69
  662. package/test/config-file-reload.json +0 -68
  663. package/test/config-invitation.json +0 -63
  664. package/test/config-kube-reload.json +0 -68
  665. package/test/config-reload.json +0 -66
  666. package/test/config.old.json +0 -152
  667. package/test/jsonutils/mdocs.yaml +0 -56
  668. package/test/jsonutils/test.json +0 -3
  669. package/test/jsonutils/test.yml +0 -5
  670. package/test/moddas/annotatedservice.js +0 -23
  671. package/test/moddas/debugmailer.js +0 -13
  672. package/test/moddas/fakeservice.js +0 -4
  673. package/test/moddas/voidstore.js +0 -66
  674. package/test/models/ident.js +0 -36
  675. package/test/models/task.js +0 -42
@@ -1,1208 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { EventEmitter } from "events";
8
- import util from "util";
9
- import { Core, EventEmitterUtils } from "../core.js";
10
- import { WebdaError } from "../errors.js";
11
- import { BinariesImpl, Binary } from "../services/binary.js";
12
- import * as WebdaQL from "@webda/ql";
13
- import { Throttler } from "../utils/throttler.js";
14
- import { ModelLinksArray, ModelLinksSimpleArray, ModelMapLoaderImplementation, createModelLinksMap } from "./relations.js";
15
- /**
16
- * Expose the model through API or GraphQL if it exists
17
- * The model will be exposed using its class name + 's'
18
- * If you need to have a specific plural, use the annotation WebdaPlural
19
- * to define the plural name
20
- *
21
- * @returns
22
- */
23
- export function Expose(params = {}) {
24
- return function (target) {
25
- params.restrict ?? (params.restrict = {});
26
- target.Expose = params;
27
- };
28
- }
29
- /**
30
- *
31
- */
32
- export class CoreModelQuery {
33
- constructor(type, model, attribute) {
34
- this.attribute = attribute;
35
- this.type = type;
36
- this.model = model;
37
- }
38
- /**
39
- * Retrieve target model definition
40
- * @returns
41
- */
42
- getTargetModel() {
43
- this.targetModel ?? (this.targetModel = Core.get().getModel(this.type));
44
- return this.targetModel;
45
- }
46
- /**
47
- * Query the object
48
- * @param query
49
- * @returns
50
- */
51
- query(query, context) {
52
- return this.getTargetModel().query(this.completeQuery(query), true, context);
53
- }
54
- /**
55
- * Complete the query with condition
56
- * @param query
57
- * @returns
58
- */
59
- completeQuery(query) {
60
- return WebdaQL.PrependCondition(query, `${this.attribute} = '${this.model.getUuid()}'`);
61
- }
62
- /**
63
- *
64
- * @param callback
65
- * @param context
66
- */
67
- async forEach(callback, query, context, parallelism = 3) {
68
- const throttler = new Throttler();
69
- throttler.setConcurrency(parallelism);
70
- for await (const model of this.iterate(query, context)) {
71
- throttler.execute(() => callback(model));
72
- }
73
- return throttler.wait();
74
- }
75
- /**
76
- * Iterate through all
77
- * @param context
78
- * @returns
79
- */
80
- iterate(query, context) {
81
- return Core.get().getModelStore(this.getTargetModel()).iterate(this.completeQuery(query), context);
82
- }
83
- /**
84
- * Get all the objects
85
- * @returns
86
- */
87
- async getAll(context) {
88
- let res = [];
89
- for await (const item of this.iterate(this.completeQuery(), context)) {
90
- res.push(item);
91
- }
92
- return res;
93
- }
94
- }
95
- __decorate([
96
- NotEnumerable
97
- ], CoreModelQuery.prototype, "type", void 0);
98
- __decorate([
99
- NotEnumerable
100
- ], CoreModelQuery.prototype, "model", void 0);
101
- __decorate([
102
- NotEnumerable
103
- ], CoreModelQuery.prototype, "attribute", void 0);
104
- __decorate([
105
- NotEnumerable
106
- ], CoreModelQuery.prototype, "targetModel", void 0);
107
- /**
108
- * Make a property hidden from json and schema
109
- *
110
- * This property will not be saved in the store
111
- * Nor it will be exposed in the API
112
- *
113
- * @param target
114
- * @param propertyKey
115
- */
116
- export function NotEnumerable(target, propertyKey) {
117
- Object.defineProperty(target, propertyKey, {
118
- set(value) {
119
- Object.defineProperty(this, propertyKey, {
120
- value,
121
- writable: true,
122
- configurable: true
123
- });
124
- },
125
- configurable: true
126
- });
127
- }
128
- const ActionsAnnotated = new Map();
129
- /**
130
- * Define an object method as an action
131
- * @param target
132
- * @param propertyKey
133
- */
134
- export function Action(options = {}) {
135
- return function (target, propertyKey) {
136
- let custom = target;
137
- const global = typeof target === "function";
138
- if (!global) {
139
- custom = target.constructor;
140
- }
141
- if (!ActionsAnnotated.has(custom)) {
142
- ActionsAnnotated.set(custom, {});
143
- }
144
- const actions = ActionsAnnotated.get(custom);
145
- actions[options.name || propertyKey] = {
146
- ...options,
147
- global,
148
- method: propertyKey
149
- };
150
- };
151
- }
152
- export class ModelRef {
153
- constructor(uuid, model, parent) {
154
- this.uuid = uuid;
155
- this.model = model;
156
- this.uuid = uuid === "" ? undefined : model.completeUid(uuid);
157
- this.store = Core.get().getModelStore(model);
158
- }
159
- async get(context) {
160
- return (await this.store.get(this.uuid))?.setContext(context || this.parent?.getContext());
161
- }
162
- set(id) {
163
- this.uuid = id instanceof CoreModel ? id.getUuid() : id;
164
- this.parent?.__dirty.add(Object.keys(this.parent).find(k => this.parent[k] === this));
165
- }
166
- toString() {
167
- return this.uuid;
168
- }
169
- toJSON() {
170
- return this.uuid;
171
- }
172
- getUuid() {
173
- return this.uuid;
174
- }
175
- async deleteItemFromCollection(prop, index, itemWriteCondition, itemWriteConditionField) {
176
- const updateDate = await this.store.deleteItemFromCollection(this.uuid, prop, index, itemWriteCondition, itemWriteConditionField);
177
- await this.model.emitSync("Store.PartialUpdated", {
178
- object_id: this.uuid,
179
- store: this.store,
180
- updateDate,
181
- partial_update: {
182
- deleteItem: {
183
- property: prop,
184
- index: index
185
- }
186
- }
187
- });
188
- return this;
189
- }
190
- async upsertItemToCollection(prop, item, index, itemWriteCondition, itemWriteConditionField) {
191
- const updateDate = await this.store.upsertItemToCollection(this.uuid, prop, item, index, itemWriteCondition, itemWriteConditionField);
192
- await this.model.emitSync("Store.PartialUpdated", {
193
- object_id: this.uuid,
194
- store: this.store,
195
- updateDate,
196
- partial_update: {
197
- addItem: {
198
- value: item,
199
- property: prop,
200
- index: index
201
- }
202
- }
203
- });
204
- return this;
205
- }
206
- exists() {
207
- return this.store.exists(this.uuid);
208
- }
209
- delete() {
210
- return this.store.delete(this.uuid);
211
- }
212
- conditionalPatch(updates, conditionField, condition) {
213
- return this.store.conditionalPatch(this.uuid, updates, conditionField, condition);
214
- }
215
- patch(updates) {
216
- return this.store.conditionalPatch(this.uuid, updates, null, undefined);
217
- }
218
- async setAttribute(attribute, value) {
219
- await this.store.setAttribute(this.uuid, attribute, value);
220
- return this;
221
- }
222
- async removeAttribute(attribute, itemWriteCondition, itemWriteConditionField) {
223
- await this.store.removeAttribute(this.uuid, attribute, itemWriteCondition, itemWriteConditionField);
224
- await this.model?.emitSync("Store.PartialUpdated", {
225
- object_id: this.uuid,
226
- store: this.store,
227
- partial_update: {
228
- deleteAttribute: attribute
229
- }
230
- });
231
- return this;
232
- }
233
- async incrementAttributes(info) {
234
- const updateDate = await this.store.incrementAttributes(this.uuid, info);
235
- await this.model.emitSync("Store.PartialUpdated", {
236
- object_id: this.uuid,
237
- store: this.store,
238
- updateDate,
239
- partial_update: {
240
- increments: info
241
- }
242
- });
243
- return this;
244
- }
245
- }
246
- __decorate([
247
- NotEnumerable
248
- ], ModelRef.prototype, "store", void 0);
249
- __decorate([
250
- NotEnumerable
251
- ], ModelRef.prototype, "model", void 0);
252
- __decorate([
253
- NotEnumerable
254
- ], ModelRef.prototype, "parent", void 0);
255
- export class ModelRefWithCreate extends ModelRef {
256
- /**
257
- * Allow to create a model
258
- * @param defaultValue
259
- * @param context
260
- * @param withSave
261
- * @returns
262
- */
263
- async create(defaultValue, context, withSave = true) {
264
- let result = new this.model().setContext(context).load(defaultValue, true).setUuid(this.uuid);
265
- if (withSave) {
266
- await result.save();
267
- }
268
- return result;
269
- }
270
- /**
271
- * Load a model from the known store
272
- *
273
- * @param this the class from which the static is called
274
- * @param id of the object to load
275
- * @param defaultValue if object not found return a default object
276
- * @param context to set on the object
277
- * @returns
278
- */
279
- async getOrCreate(defaultValue, context, withSave = true) {
280
- return (await this.get()) || this.create(defaultValue, context, withSave);
281
- }
282
- }
283
- export class ModelRefCustom extends ModelRef {
284
- constructor(uuid, model, data, parent) {
285
- super(uuid, model, parent);
286
- this.uuid = uuid;
287
- Object.assign(this, data);
288
- }
289
- toJSON() {
290
- return this;
291
- }
292
- getUuid() {
293
- return this.uuid;
294
- }
295
- }
296
- export const Emitters = new WeakMap();
297
- /**
298
- * Basic Object in Webda
299
- *
300
- * It is used to define a data stored
301
- * Any variable starting with _ can only be set by the server
302
- * Any variable starting with __ won't be exported outside of the server
303
- *
304
- * @class
305
- * @WebdaModel
306
- */
307
- class CoreModel {
308
- constructor() {
309
- this.__dirty = new Set();
310
- this.__class = new.target;
311
- // Get the store automatically now
312
- this.__store = Core.get()?.getModelStore(new.target);
313
- // Get the type automatically now
314
- this.__type = process.env.WEBDA_V2_COMPATIBLE
315
- ? Core.get()?.getApplication().getModelFromInstance(this)
316
- : Core.get()
317
- ?.getApplication()
318
- .getShortId(Core.get()?.getApplication().getModelFromInstance(this));
319
- }
320
- /**
321
- * Listen to events on the model
322
- * @param event
323
- * @param listener
324
- * @param async
325
- */
326
- static on(event, listener, async = false) {
327
- if (!Emitters.has(this)) {
328
- Emitters.set(this, new EventEmitter());
329
- }
330
- // TODO Manage async
331
- if (async) {
332
- Core.get()
333
- .getService("AsyncEvents")
334
- .bindAsyncListener(this, event, listener);
335
- }
336
- else {
337
- Emitters.get(this).on(event, listener);
338
- }
339
- return this;
340
- }
341
- /**
342
- * Emit an event for this class
343
- * @param this
344
- * @param event
345
- * @param evt
346
- */
347
- static emit(event, evt) {
348
- let clazz = this;
349
- // @ts-ignore
350
- while (clazz) {
351
- // Emit for all parent class
352
- if (Emitters.has(clazz)) {
353
- EventEmitterUtils.emit(Emitters.get(clazz), event, evt);
354
- }
355
- // @ts-ignore
356
- if (clazz === CoreModel) {
357
- break;
358
- }
359
- clazz = Object.getPrototypeOf(clazz);
360
- }
361
- }
362
- /**
363
- * Emit an event for this class and wait for all listeners to finish
364
- * @param this
365
- * @param event
366
- * @param evt
367
- */
368
- static async emitSync(event, evt) {
369
- let clazz = this;
370
- let p = [];
371
- // @ts-ignore
372
- while (clazz) {
373
- // Emit for all parent class
374
- if (Emitters.has(clazz)) {
375
- p.push(EventEmitterUtils.emitSync(Emitters.get(clazz), event, evt));
376
- }
377
- // @ts-ignore
378
- if (clazz === CoreModel) {
379
- break;
380
- }
381
- clazz = Object.getPrototypeOf(clazz);
382
- }
383
- await Promise.all(p);
384
- }
385
- /**
386
- * Listen to events on the model asynchronously
387
- * @param event
388
- * @param listener
389
- */
390
- static onAsync(event, listener, queue) {
391
- return this.on(event, listener, true);
392
- }
393
- /**
394
- *
395
- * @param event
396
- * @param listener
397
- * @returns
398
- */
399
- static addListener(event, listener) {
400
- return this.on(event, listener);
401
- }
402
- static emitter(method, ...args) {
403
- if (!Emitters.has(this)) {
404
- Emitters.set(this, new EventEmitter());
405
- }
406
- // @ts-ignore
407
- return Emitters.get(this)[method](...args);
408
- }
409
- static removeListener(...args) {
410
- return this.emitter("removeListener", ...args);
411
- }
412
- static off(...args) {
413
- return this.emitter("off", ...args);
414
- }
415
- static once(...args) {
416
- return this.emitter("once", ...args);
417
- }
418
- static removeAllListeners(...args) {
419
- return this.emitter("removeAllListeners", ...args);
420
- }
421
- static setMaxListeners(...args) {
422
- return this.emitter("setMaxListeners", ...args);
423
- }
424
- static getMaxListeners(...args) {
425
- return this.emitter("getMaxListeners", ...args);
426
- }
427
- static listeners(...args) {
428
- return this.emitter("listeners", ...args);
429
- }
430
- static rawListeners(...args) {
431
- return this.emitter("rawListeners", ...args);
432
- }
433
- static listenerCount(...args) {
434
- return this.emitter("listenerCount", ...args);
435
- }
436
- static prependListener(...args) {
437
- return this.emitter("prependListener", ...args);
438
- }
439
- static prependOnceListener(...args) {
440
- return this.emitter("prependOnceListener", ...args);
441
- }
442
- static eventNames(...args) {
443
- return this.emitter("eventNames", ...args);
444
- }
445
- /**
446
- *
447
- * @returns
448
- */
449
- static getRelations() {
450
- return Core.get()?.getApplication().getRelations(this);
451
- }
452
- /**
453
- * Do not declare any public events by default
454
- * @returns
455
- */
456
- static getClientEvents() {
457
- return [];
458
- }
459
- /**
460
- * Does not allow any event by default
461
- * @param _event
462
- * @param _context
463
- * @returns
464
- */
465
- static authorizeClientEvent(_event, _context, _model) {
466
- return false;
467
- }
468
- /**
469
- * Get Store for this model
470
- * @param this
471
- * @returns
472
- */
473
- static store() {
474
- if (!Core.get()) {
475
- throw new Error("Webda not initialized");
476
- }
477
- return Core.get().getModelStore(this);
478
- }
479
- /**
480
- * Complete the uid with prefix if any
481
- *
482
- * Useful when object are stored with a prefix for full uuid
483
- * @param uid
484
- * @returns
485
- */
486
- static completeUid(uid) {
487
- return uid;
488
- }
489
- /**
490
- * Return the known schema
491
- * @returns
492
- */
493
- static getSchema() {
494
- const app = Core.get()?.getApplication();
495
- return app?.getSchema(app.getModelFromConstructor(this));
496
- }
497
- /**
498
- * Get a reference to a model
499
- * @param this
500
- * @param uid
501
- * @returns
502
- */
503
- static ref(uid) {
504
- return new ModelRefWithCreate(uid, this);
505
- }
506
- /**
507
- * Get a reference to a model
508
- * @param this
509
- * @param uid
510
- * @returns
511
- */
512
- static create(data) {
513
- return new this().load(data, true).save();
514
- }
515
- /**
516
- * Get identifier for this model
517
- * @returns
518
- */
519
- static getIdentifier(short = true) {
520
- const res = Core.get().getApplication().getModelName(this);
521
- if (short) {
522
- return Core.get().getApplication().getShortId(res);
523
- }
524
- else {
525
- return res;
526
- }
527
- }
528
- /**
529
- * Get the model hierarchy
530
- *
531
- * Ancestors will contain every model it inherits from
532
- * Children will contain every model that inherits from this model in a tree structure
533
- */
534
- static getHierarchy() {
535
- return Core.get().getApplication().getModelHierarchy(this);
536
- }
537
- /**
538
- * Unflat an object
539
- * @param data
540
- * @param split
541
- * @returns
542
- */
543
- static unflat(data, split = "#") {
544
- const res = {};
545
- for (let i in data) {
546
- const attrs = i.split(split);
547
- let attr = attrs.shift();
548
- let cur = res;
549
- while (attr) {
550
- if (attrs.length) {
551
- cur[attr] ?? (cur[attr] = {});
552
- cur = cur[attr];
553
- }
554
- else {
555
- cur[attr] = data[i];
556
- }
557
- attr = attrs.shift();
558
- }
559
- }
560
- return res;
561
- }
562
- /**
563
- * Create subobject for a model
564
- *
565
- * Useful for counters
566
- *
567
- * @param split
568
- * @returns
569
- */
570
- unflat(split = "#") {
571
- return CoreModel.unflat(this, split);
572
- }
573
- /**
574
- * Flat an object into another
575
- *
576
- * {
577
- * a: {
578
- * b: 1
579
- * },
580
- * c: 1
581
- * }
582
- *
583
- * become
584
- *
585
- * {
586
- * "a#b": 1
587
- * "c": 1
588
- * }
589
- *
590
- * @param target
591
- * @param data
592
- * @param split
593
- * @param prefix
594
- */
595
- static flat(target, data, split = "#", prefix = "") {
596
- for (let i in data) {
597
- if (typeof data[i] === "object") {
598
- CoreModel.flat(target, data[i], split, i + split);
599
- }
600
- else {
601
- target[prefix + i] = data[i];
602
- }
603
- }
604
- }
605
- /**
606
- * Complete the query with __type/__types
607
- * @param query
608
- * @param includeSubclass
609
- * @returns
610
- */
611
- static completeQuery(query, includeSubclass = true) {
612
- if (!query.includes("__type")) {
613
- let condition;
614
- const app = Core.get().getApplication();
615
- const name = app.getShortId(app.getModelName(this));
616
- if (includeSubclass) {
617
- condition = `__types CONTAINS "${name}"`;
618
- }
619
- else {
620
- condition = `__type = "${name}"`;
621
- }
622
- return WebdaQL.PrependCondition(query, condition);
623
- }
624
- return query;
625
- }
626
- /**
627
- * Iterate through the model
628
- *
629
- * How to use a iterator is:
630
- *
631
- * ```
632
- * for await (const model of CoreModel.iterate()) {
633
- * // Do something with my model
634
- * }
635
- * ```
636
- *
637
- * @param this
638
- * @param query
639
- * @param includeSubclass
640
- * @param context
641
- * @returns
642
- */
643
- static iterate(query = "", includeSubclass = true, context) {
644
- // @ts-ignore
645
- return this.store().iterate(this.completeQuery(query, includeSubclass), context);
646
- }
647
- /**
648
- * Query for models
649
- * @param this
650
- * @param id
651
- * @returns
652
- */
653
- static async query(query = "", includeSubclass = true, context) {
654
- // @ts-ignore
655
- return this.store().query(this.completeQuery(query, includeSubclass), context);
656
- }
657
- /**
658
- * Return a proxy to the object to detect if dirty
659
- * @returns
660
- */
661
- getProxy() {
662
- const subProxier = prop => {
663
- return {
664
- set: (target, p, value) => {
665
- this.__dirty.add(prop);
666
- target[p] = value;
667
- return true;
668
- },
669
- get: (target, p) => {
670
- if (Array.isArray(target[p]) || target[p] instanceof Object) {
671
- return new Proxy(target[p], subProxier(prop));
672
- }
673
- return target[p];
674
- },
675
- deleteProperty: (t, property) => {
676
- delete t[property];
677
- this.__dirty.add(prop);
678
- return true;
679
- }
680
- };
681
- };
682
- const proxier = {
683
- deleteProperty: (t, property) => {
684
- delete t[property];
685
- this.__dirty.add(property);
686
- return true;
687
- },
688
- set: (target, p, value) => {
689
- if (p !== "__dirty") {
690
- target.__dirty.add(p);
691
- }
692
- target[p] = value;
693
- return true;
694
- },
695
- get: (target, p) => {
696
- if (typeof p === "string" && p.startsWith("__")) {
697
- return target[p];
698
- }
699
- if (Array.isArray(target[p]) || target[p] instanceof Object) {
700
- return new Proxy(target[p], subProxier(p));
701
- }
702
- return target[p];
703
- }
704
- };
705
- return new Proxy(this, proxier);
706
- }
707
- /**
708
- * Return true if needs a save
709
- * @returns
710
- */
711
- isDirty() {
712
- return this.__dirty.size > 0;
713
- }
714
- /**
715
- *
716
- * @returns the uuid of the object
717
- */
718
- getUuid() {
719
- // @ts-ignore
720
- return this[this.__class.getUuidField()];
721
- }
722
- /**
723
- *
724
- * @param uuid
725
- * @param target
726
- */
727
- setUuid(uuid, target = this) {
728
- target[this.__class.getUuidField()] = uuid;
729
- return target;
730
- }
731
- /**
732
- * Get actions callable on an object
733
- *
734
- * This will expose them by the Store with /storeUrl/{uuid}/{action}
735
- */
736
- static getActions() {
737
- const actions = [];
738
- // Explore all parent classes to collect all known actions
739
- let clazz = this;
740
- // @ts-ignore
741
- while (clazz !== CoreModel) {
742
- if (ActionsAnnotated.has(clazz)) {
743
- actions.push(ActionsAnnotated.get(clazz));
744
- }
745
- clazz = Object.getPrototypeOf(clazz);
746
- }
747
- // Reduce right to give priority to the last class:
748
- return actions.reduceRight((v, c) => ({ ...v, ...c }), {});
749
- }
750
- /**
751
- * Return the expressable query for permission
752
- *
753
- * @param context of the query
754
- * @returns
755
- */
756
- static getPermissionQuery(_ctx) {
757
- return null;
758
- }
759
- async checkAct(context, action) {
760
- let msg = await this.canAct(context, action);
761
- if (msg !== true) {
762
- throw new WebdaError.Forbidden(msg === false ? "No permission" : msg);
763
- }
764
- }
765
- /**
766
- * By default nothing is permitted on a CoreModel
767
- * @returns
768
- */
769
- async canAct(_context, _action) {
770
- return "This model does not support any action: override canAct";
771
- }
772
- /**
773
- * Get the UUID property
774
- */
775
- static getUuidField() {
776
- return "uuid";
777
- }
778
- /**
779
- * Create an object
780
- * @returns
781
- */
782
- static factory(object, context) {
783
- return object instanceof this ? object : new this().setContext(context).load(object, context === undefined);
784
- }
785
- /**
786
- * Detect what looks like a CoreModel but can be from different version
787
- * @param object
788
- * @returns
789
- */
790
- static instanceOf(object) {
791
- return (typeof object.toStoredJSON === "function" && object.__class && object.__class.factory && object.__class.instanceOf);
792
- }
793
- /**
794
- * Return a unique reference within the application to the object
795
- *
796
- * It contains the Store containing it
797
- * @returns
798
- */
799
- getFullUuid() {
800
- return `${this.__type.replace(/\//, "-")}$${this.getUuid()}`;
801
- }
802
- /**
803
- * Get an object from the full uuid
804
- * @param core
805
- * @param fullUuid
806
- * @param partials
807
- * @returns
808
- */
809
- static async fromFullUuid(fullUuid, core = Core.get(), partials) {
810
- const [model, uuid] = fullUuid.split("$");
811
- let modelObject = core.getApplication().getModel(model.replace("-", "/"));
812
- if (partials) {
813
- return new modelObject().load(partials, true).setUuid(uuid);
814
- }
815
- return new modelObject().setUuid(uuid).get();
816
- }
817
- /**
818
- * Allow to define custom permission per attribute
819
- *
820
- * This method allows you to do permission based attribute
821
- * But also a mask destructive attribute
822
- *
823
- * @param key
824
- * @param value
825
- * @param mode
826
- * @param context
827
- * @returns updated value
828
- */
829
- attributePermission(key, value, mode, context) {
830
- if (mode === "WRITE") {
831
- return key.startsWith("_") ? undefined : value;
832
- }
833
- else {
834
- return !key.startsWith("__") ? value : undefined;
835
- }
836
- }
837
- /**
838
- * Load an object from RAW
839
- *
840
- * @param raw data
841
- * @param secure if false will ignore any _ variable
842
- */
843
- load(raw, secure = false, relations = true) {
844
- // Object assign with filter
845
- for (let prop in raw) {
846
- let val = raw[prop];
847
- if (!secure) {
848
- val = this.attributePermission(prop, raw[prop], "WRITE");
849
- if (val === undefined) {
850
- continue;
851
- }
852
- }
853
- // @ts-ignore
854
- this[prop] = val;
855
- }
856
- if (this._creationDate) {
857
- this._creationDate = new Date(this._creationDate);
858
- }
859
- if (this._lastUpdate) {
860
- this._lastUpdate = new Date(this._lastUpdate);
861
- }
862
- if (!this.getUuid()) {
863
- this.setUuid(this.generateUid(raw));
864
- }
865
- if (relations) {
866
- this.handleRelations();
867
- }
868
- return this;
869
- }
870
- /**
871
- * Patch every attribute that is based on a relation
872
- * to add all the helpers
873
- */
874
- handleRelations() {
875
- var _a, _b;
876
- const rel = Core.get()
877
- ?.getApplication()
878
- ?.getRelations(this) || {};
879
- for (let link of rel.links || []) {
880
- const model = Core.get().getModel(link.model);
881
- if (link.type === "LINK") {
882
- this[_a = link.attribute] ?? (this[_a] = "");
883
- if (typeof this[link.attribute] === "string") {
884
- this[link.attribute] = new ModelRef(this[link.attribute], model, this);
885
- }
886
- }
887
- else if (link.type === "LINKS_ARRAY") {
888
- this[link.attribute] = new ModelLinksArray(model, this[link.attribute], this);
889
- }
890
- else if (link.type === "LINKS_SIMPLE_ARRAY") {
891
- this[link.attribute] = new ModelLinksSimpleArray(model, this[link.attribute], this);
892
- }
893
- else if (link.type === "LINKS_MAP") {
894
- this[link.attribute] = createModelLinksMap(model, this[link.attribute], this);
895
- }
896
- }
897
- for (let link of rel.maps || []) {
898
- this[link.attribute] = (this[link.attribute] || []).map(el => new ModelMapLoaderImplementation(Core.get().getModel(link.model), el, this));
899
- }
900
- for (let query of rel.queries || []) {
901
- this[query.attribute] = new CoreModelQuery(query.model, this, query.targetAttribute);
902
- }
903
- if (rel.parent) {
904
- this[_b = rel.parent.attribute] ?? (this[_b] = "");
905
- if (typeof this[rel.parent.attribute] === "string") {
906
- this[rel.parent.attribute] = new ModelRef(this[rel.parent.attribute], Core.get().getModel(rel.parent.model), this);
907
- }
908
- }
909
- for (let binary of rel.binaries || []) {
910
- if (binary.cardinality === "ONE") {
911
- this[binary.attribute] = new Binary(binary.attribute, this);
912
- }
913
- else {
914
- this[binary.attribute] = new BinariesImpl().assign(this, binary.attribute);
915
- }
916
- }
917
- }
918
- /**
919
- * Context of the request
920
- */
921
- setContext(ctx) {
922
- this.__ctx = ctx;
923
- return this;
924
- }
925
- /**
926
- * Get object context
927
- *
928
- * Global object does not belong to a request
929
- */
930
- getContext() {
931
- return this.__ctx || Core.get().getGlobalContext();
932
- }
933
- /**
934
- * Return the object registered store
935
- */
936
- getStore() {
937
- return this.__store;
938
- }
939
- /**
940
- * Get the object
941
- * @returns
942
- */
943
- async get() {
944
- return this.refresh();
945
- }
946
- /**
947
- * Get the object again
948
- *
949
- * @throws Error if the object is not coming from a store
950
- */
951
- async refresh() {
952
- let obj = await this.__store.get(this.getUuid());
953
- if (obj) {
954
- Object.assign(this, obj);
955
- for (let i in this) {
956
- // @ts-ignore
957
- if (obj[i] !== this[i]) {
958
- delete this[i];
959
- }
960
- }
961
- this.handleRelations();
962
- }
963
- return this;
964
- }
965
- /**
966
- * Delete this object
967
- *
968
- * @throws Error if the object is not coming from a store
969
- */
970
- async delete() {
971
- return this.__store.delete(this);
972
- }
973
- /**
974
- * Patch current object with this update
975
- * @param obj
976
- * @param conditionField if null no condition used otherwise fallback to lastUpdate
977
- * @param conditionValue
978
- */
979
- async patch(obj, conditionField, conditionValue) {
980
- await this.__store.patch({ [this.__class.getUuidField()]: this.getUuid(), ...obj }, true, conditionField, conditionValue);
981
- Object.assign(this, obj);
982
- }
983
- /**
984
- * Save this object
985
- *
986
- * @throws Error if the object is not coming from a store
987
- */
988
- async save(full, ...args) {
989
- // If proxy is not used and not field specified call save
990
- if ((!util.types.isProxy(this) && full === undefined) || full === true) {
991
- if (!this._creationDate || !this._lastUpdate) {
992
- await this.__store.create(this, this.getContext());
993
- }
994
- else {
995
- await this.__store.update(this);
996
- }
997
- return this;
998
- }
999
- const patch = {
1000
- [this.__class.getUuidField()]: this.getUuid()
1001
- };
1002
- if (typeof full === "string") {
1003
- [full, ...args].forEach(k => {
1004
- patch[k] = this[k];
1005
- });
1006
- }
1007
- else {
1008
- for (let entry of this.__dirty.entries()) {
1009
- patch[entry[0]] = this[entry[0]];
1010
- }
1011
- }
1012
- await this.__store.patch(patch);
1013
- this.__dirty.clear();
1014
- return this;
1015
- }
1016
- /**
1017
- * Validate objet modification
1018
- *
1019
- * @param ctx
1020
- * @param updates
1021
- */
1022
- async validate(ctx, updates, ignoreRequired = false) {
1023
- ctx.getWebda().validateSchema(this, updates, ignoreRequired);
1024
- return true;
1025
- }
1026
- /**
1027
- * Generate uuid for the object
1028
- *
1029
- * @param object
1030
- * @returns
1031
- */
1032
- generateUid(_object = undefined) {
1033
- return Core.get().getUuid();
1034
- }
1035
- /**
1036
- * Return the object to be serialized without the __store
1037
- *
1038
- * @param stringify
1039
- * @returns
1040
- */
1041
- toStoredJSON(stringify = false) {
1042
- let obj = this._toJSON(true);
1043
- if (stringify) {
1044
- return JSON.stringify(obj);
1045
- }
1046
- return obj;
1047
- }
1048
- /**
1049
- * Get a pre typed service
1050
- *
1051
- * @param service to retrieve
1052
- * WARNING: Only object attached to a store can retrieve service
1053
- */
1054
- getService(service) {
1055
- return this.__store.getService(service);
1056
- }
1057
- /**
1058
- * Remove the specific attributes if not secure
1059
- *
1060
- *
1061
- *
1062
- * @param secure serialize server fields also
1063
- * @returns filtered object to be serialized
1064
- */
1065
- _toJSON(secure) {
1066
- let obj = {};
1067
- for (let i in this) {
1068
- let value = this[i];
1069
- if (!secure) {
1070
- value = this.attributePermission(i, value, "READ");
1071
- }
1072
- if (value === undefined)
1073
- continue;
1074
- if (value instanceof ModelRef) {
1075
- obj[i] = value.toString();
1076
- }
1077
- else if (value instanceof Binary) {
1078
- obj[i] = value.toJSON();
1079
- }
1080
- else {
1081
- obj[i] = value;
1082
- }
1083
- }
1084
- return obj;
1085
- }
1086
- /**
1087
- * Return the object without sensitive attributes
1088
- *
1089
- * @returns Object to serialize
1090
- */
1091
- toJSON() {
1092
- return this._toJSON(false);
1093
- }
1094
- /**
1095
- * Called when object is about to be deleted
1096
- */
1097
- async _onDelete() {
1098
- // Empty to be overriden
1099
- }
1100
- /**
1101
- * Called when object has been deleted
1102
- */
1103
- async _onDeleted() {
1104
- // Empty to be overriden
1105
- }
1106
- /**
1107
- * Called when object is retrieved
1108
- */
1109
- async _onGet() {
1110
- // Empty to be overriden
1111
- }
1112
- /**
1113
- * Called when object is about to be saved
1114
- */
1115
- async _onSave() {
1116
- // Empty to be overriden
1117
- }
1118
- /**
1119
- * Called when object is saved
1120
- */
1121
- async _onSaved() {
1122
- // Empty to be overriden
1123
- }
1124
- /**
1125
- * Called when object is about to be updates
1126
- *
1127
- * @param updates to be send
1128
- */
1129
- async _onUpdate(_updates) {
1130
- // Empty to be overriden
1131
- }
1132
- /**
1133
- * Called when object is updated
1134
- */
1135
- async _onUpdated() {
1136
- // Empty to be overriden
1137
- }
1138
- /**
1139
- * Set attribute on the object and database
1140
- * @param property
1141
- * @param value
1142
- */
1143
- async setAttribute(property, value) {
1144
- await this.getRef().setAttribute(property, value);
1145
- this[property] = value;
1146
- }
1147
- /**
1148
- * Remove attribute from both the object and db
1149
- * @param property
1150
- */
1151
- async removeAttribute(property) {
1152
- await this.getRef().removeAttribute(property);
1153
- delete this[property];
1154
- }
1155
- /**
1156
- * Increment an attribute both in store and object
1157
- * @param property
1158
- * @param value
1159
- */
1160
- async incrementAttribute(property, value) {
1161
- return this.incrementAttributes([{ property, value }]);
1162
- }
1163
- /**
1164
- * Return a model ref
1165
- * @returns
1166
- */
1167
- getRef() {
1168
- return new ModelRef(this.getUuid(), this.__class);
1169
- }
1170
- /**
1171
- * Increment a attributes both in store and object
1172
- * @param info
1173
- */
1174
- async incrementAttributes(info) {
1175
- var _a;
1176
- await this.getRef().incrementAttributes(info);
1177
- for (let inc of info) {
1178
- this[_a = inc.property] ?? (this[_a] = 0);
1179
- this[inc.property] += inc.value;
1180
- }
1181
- }
1182
- }
1183
- __decorate([
1184
- NotEnumerable
1185
- ], CoreModel.prototype, "__class", void 0);
1186
- __decorate([
1187
- NotEnumerable
1188
- ], CoreModel.prototype, "__ctx", void 0);
1189
- __decorate([
1190
- NotEnumerable
1191
- ], CoreModel.prototype, "__store", void 0);
1192
- __decorate([
1193
- NotEnumerable
1194
- ], CoreModel.prototype, "__dirty", void 0);
1195
- /**
1196
- * CoreModel with a uuid
1197
- */
1198
- class UuidModel extends CoreModel {
1199
- /**
1200
- * @override
1201
- */
1202
- validate(ctx, updates, ignoreRequired) {
1203
- updates.uuid ?? (updates.uuid = this.generateUid());
1204
- return super.validate(ctx, updates, ignoreRequired);
1205
- }
1206
- }
1207
- export { CoreModel, UuidModel };
1208
- //# sourceMappingURL=coremodel.js.map