@flarehr/apollo-super-selection 1.3.54543 → 1.3.54570

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 (253) hide show
  1. package/dist/lib/apollo-super-selection/apollo-super-selection.css +1 -0
  2. package/dist/lib/apollo-super-selection/apollo-super-selection.esm.js +1 -0
  3. package/dist/lib/apollo-super-selection/apollo-super-selection.js +130 -0
  4. package/dist/lib/apollo-super-selection/assets/icon-exclamation.svg +3 -0
  5. package/dist/lib/apollo-super-selection/assets/icon-information-circle.svg +3 -0
  6. package/dist/lib/apollo-super-selection/index.esm.js +0 -0
  7. package/dist/lib/apollo-super-selection/p-02f24922.system.entry.js +1 -0
  8. package/dist/lib/apollo-super-selection/p-071b8545.entry.js +1 -0
  9. package/dist/lib/apollo-super-selection/p-14885f78.system.js +15 -0
  10. package/dist/lib/apollo-super-selection/p-15f0e5eb.system.js +1 -0
  11. package/dist/lib/apollo-super-selection/p-23cfdd82.entry.js +1 -0
  12. package/dist/lib/apollo-super-selection/p-29c11183.js +15 -0
  13. package/dist/lib/apollo-super-selection/p-44bec843.system.js +1 -0
  14. package/dist/lib/apollo-super-selection/p-50ea2036.system.js +1 -0
  15. package/dist/lib/apollo-super-selection/p-51aefdb1.system.entry.js +1 -0
  16. package/dist/lib/apollo-super-selection/p-51c6dd08.js +1 -0
  17. package/dist/lib/apollo-super-selection/p-6ac8791e.system.entry.js +1 -0
  18. package/dist/lib/apollo-super-selection/p-7a89efaf.js +1 -0
  19. package/dist/lib/apollo-super-selection/p-80178f87.system.js +1 -0
  20. package/dist/lib/apollo-super-selection/p-86e3e03f.js +1 -0
  21. package/dist/lib/apollo-super-selection/p-9c855634.entry.js +1 -0
  22. package/dist/lib/apollo-super-selection/p-b89b68db.entry.js +1 -0
  23. package/dist/lib/apollo-super-selection/p-bdcfc026.system.js +1 -0
  24. package/dist/lib/apollo-super-selection/p-c9bb6b7d.system.entry.js +69 -0
  25. package/dist/lib/apollo-super-selection/p-e869dc87.entry.js +14 -0
  26. package/dist/lib/apollo-super-selection/p-ef3afa00.system.entry.js +1 -0
  27. package/dist/lib/apollo-super-selection/p-f29066b9.system.entry.js +1 -0
  28. package/dist/lib/apollo-super-selection/p-fcb4050d.entry.js +1 -0
  29. package/dist/lib/cjs/active-router-1f555f75.js +75 -0
  30. package/dist/lib/cjs/apollo-super-selection.cjs.js +22 -0
  31. package/dist/lib/cjs/app-globals-b1125d8c.js +25 -0
  32. package/dist/lib/cjs/context-consumer.cjs.entry.js +29 -0
  33. package/dist/lib/cjs/datorama-akita-6c9cb8fb.js +3641 -0
  34. package/dist/lib/cjs/index-eb4f212f.js +1766 -0
  35. package/dist/lib/cjs/index.cjs.js +2 -0
  36. package/dist/lib/cjs/loader.cjs.js +24 -0
  37. package/dist/lib/cjs/sss-button_31.cjs.entry.js +17977 -0
  38. package/dist/lib/cjs/stencil-async-content.cjs.entry.js +32 -0
  39. package/dist/lib/cjs/stencil-route-title.cjs.entry.js +32 -0
  40. package/dist/lib/cjs/stencil-router-prompt.cjs.entry.js +59 -0
  41. package/dist/lib/cjs/stencil-router-redirect.cjs.entry.js +32 -0
  42. package/dist/lib/collection/apollo-super-selection.css +1 -0
  43. package/dist/lib/collection/collection-manifest.json +95 -0
  44. package/dist/lib/collection/components/app-host/loading-page.js +9 -0
  45. package/dist/lib/collection/components/app-host/services/app-configuration.query.js +18 -0
  46. package/dist/lib/collection/components/app-host/services/app-configuration.service.js +25 -0
  47. package/dist/lib/collection/components/app-host/services/app-parameters.query.js +13 -0
  48. package/dist/lib/collection/components/app-host/services/app-parameters.service.js +14 -0
  49. package/dist/lib/collection/components/app-host/services/appinsights.service.js +46 -0
  50. package/dist/lib/collection/components/app-host/services/authentication.query.js +21 -0
  51. package/dist/lib/collection/components/app-host/services/authentication.service.js +50 -0
  52. package/dist/lib/collection/components/app-host/services/interop/host-interop.service.js +31 -0
  53. package/dist/lib/collection/components/app-host/services/interop/iframe-interop.service.js +30 -0
  54. package/dist/lib/collection/components/app-host/services/interop/react-native-interop.service.js +20 -0
  55. package/dist/lib/collection/components/app-host/services/interop.query.js +26 -0
  56. package/dist/lib/collection/components/app-host/services/session.store.js +38 -0
  57. package/dist/lib/collection/components/app-host/super-selection-app-host.css +24 -0
  58. package/dist/lib/collection/components/app-host/super-selection-app-host.js +87 -0
  59. package/dist/lib/collection/components/external-loading-page/external-loading-page.js +29 -0
  60. package/dist/lib/collection/components/super-campaign/super-campaign-types.js +6 -0
  61. package/dist/lib/collection/components/super-campaign/super-campaign.js +361 -0
  62. package/dist/lib/collection/components/super-selection-app/api/api-client.js +14 -0
  63. package/dist/lib/collection/components/super-selection-app/api/event-tracking.api.js +9 -0
  64. package/dist/lib/collection/components/super-selection-app/api/super-campaign-errors-api.js +9 -0
  65. package/dist/lib/collection/components/super-selection-app/api/super-campaign-errors.api.dtos.js +1 -0
  66. package/dist/lib/collection/components/super-selection-app/api/super-selection-events.model.js +16 -0
  67. package/dist/lib/collection/components/super-selection-app/api/super-selection.api.dto.js +179 -0
  68. package/dist/lib/collection/components/super-selection-app/api/super-selection.api.js +69 -0
  69. package/dist/lib/collection/components/super-selection-app/app-state-pages/success.js +36 -0
  70. package/dist/lib/collection/components/super-selection-app/assets/icon-exclamation.svg +3 -0
  71. package/dist/lib/collection/components/super-selection-app/assets/icon-information-circle.svg +3 -0
  72. package/dist/lib/collection/components/super-selection-app/existing-choice/existing-choice.js +163 -0
  73. package/dist/lib/collection/components/super-selection-app/footer-section/footer-section.js +39 -0
  74. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/api/custom-fund-choice.api.dto.js +1 -0
  75. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/api/custom-fund-choice.api.js +50 -0
  76. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/custom-fund.js +86 -0
  77. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/custom-fund.store.js +53 -0
  78. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/default-fund/default-fund.js +114 -0
  79. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/member-name-input.js +162 -0
  80. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/my-own-fund/my-own-fund-inputs.js +143 -0
  81. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/my-own-fund/my-own-fund.js +118 -0
  82. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/self-managed-fund/abn-validation.js +11 -0
  83. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/self-managed-fund/bankBsbNumbers.js +111 -0
  84. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund-inputs.js +253 -0
  85. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund.form.js +1 -0
  86. package/dist/lib/collection/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund.js +121 -0
  87. package/dist/lib/collection/components/super-selection-app/funds/promoted-fund/api/promoted-fund-choice.api.dto.js +1 -0
  88. package/dist/lib/collection/components/super-selection-app/funds/promoted-fund/api/promoted-fund-choice.api.js +31 -0
  89. package/dist/lib/collection/components/super-selection-app/funds/slate-super/api/slate-choice.api.dto.js +1 -0
  90. package/dist/lib/collection/components/super-selection-app/funds/slate-super/api/slate-choice.api.js +13 -0
  91. package/dist/lib/collection/components/super-selection-app/funds/slate-super/api/slate.js +4 -0
  92. package/dist/lib/collection/components/super-selection-app/header-section/header-section.js +53 -0
  93. package/dist/lib/collection/components/super-selection-app/misc/button.js +195 -0
  94. package/dist/lib/collection/components/super-selection-app/misc/dropdown-async.css +7 -0
  95. package/dist/lib/collection/components/super-selection-app/misc/dropdown-async.js +390 -0
  96. package/dist/lib/collection/components/super-selection-app/misc/loading-indicator.js +52 -0
  97. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-common.js +22 -0
  98. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-display-field.js +42 -0
  99. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-error-box.js +66 -0
  100. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-invalid-my-own-fund.js +121 -0
  101. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-invalid-smsf.js +145 -0
  102. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-my-own-fund.js +223 -0
  103. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-smsf.js +398 -0
  104. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-types.js +288 -0
  105. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill-warning-box.js +37 -0
  106. package/dist/lib/collection/components/super-selection-app/prefill-fund/prefill.js +81 -0
  107. package/dist/lib/collection/components/super-selection-app/services/australian-fund-lookup.service.js +15 -0
  108. package/dist/lib/collection/components/super-selection-app/services/event-tracking.service.js +97 -0
  109. package/dist/lib/collection/components/super-selection-app/services/existing-super-choice-info.service.js +134 -0
  110. package/dist/lib/collection/components/super-selection-app/services/misc.service.js +7 -0
  111. package/dist/lib/collection/components/super-selection-app/services/navigation.service.js +31 -0
  112. package/dist/lib/collection/components/super-selection-app/services/super-selection-app.routes.js +32 -0
  113. package/dist/lib/collection/components/super-selection-app/services/super-selection-app.service.js +146 -0
  114. package/dist/lib/collection/components/super-selection-app/services/super-selection.store.js +42 -0
  115. package/dist/lib/collection/components/super-selection-app/standard-choice/standard-choice-form.js +155 -0
  116. package/dist/lib/collection/components/super-selection-app/standard-choice/standard-choice-form.store.js +11 -0
  117. package/dist/lib/collection/components/super-selection-app/super-selection-app.css +27 -0
  118. package/dist/lib/collection/components/super-selection-app/super-selection-app.js +291 -0
  119. package/dist/lib/collection/global/init-host.js +25 -0
  120. package/dist/lib/collection/global/main.dev.js +29 -0
  121. package/dist/lib/collection/global/main.js +11 -0
  122. package/dist/lib/collection/global/stencil-router-workaround.js +12 -0
  123. package/dist/lib/collection/index.js +2 -0
  124. package/dist/lib/collection/utils/config.js +2 -0
  125. package/dist/lib/collection/utils/gtm.js +5 -0
  126. package/dist/lib/collection/utils/iframe.js +33 -0
  127. package/dist/lib/collection/utils/index.js +11 -0
  128. package/dist/lib/collection/utils/lazy.js +29 -0
  129. package/dist/lib/collection/utils/storage.js +5 -0
  130. package/dist/lib/esm/active-router-5e40c0f8.js +73 -0
  131. package/dist/lib/esm/apollo-super-selection.js +20 -0
  132. package/dist/lib/esm/app-globals-c1f89805.js +23 -0
  133. package/dist/lib/esm/context-consumer.entry.js +25 -0
  134. package/dist/lib/esm/datorama-akita-127aea91.js +3624 -0
  135. package/dist/lib/esm/index-189b2180.js +1732 -0
  136. package/dist/lib/esm/index.js +1 -0
  137. package/dist/lib/esm/loader.js +20 -0
  138. package/dist/lib/esm/polyfills/core-js.js +11 -0
  139. package/dist/lib/esm/polyfills/css-shim.js +1 -0
  140. package/dist/lib/esm/polyfills/dom.js +79 -0
  141. package/dist/lib/esm/polyfills/es5-html-element.js +1 -0
  142. package/dist/lib/esm/polyfills/index.js +34 -0
  143. package/dist/lib/esm/polyfills/system.js +6 -0
  144. package/dist/lib/esm/sss-button_31.entry.js +17923 -0
  145. package/dist/lib/esm/stencil-async-content.entry.js +28 -0
  146. package/dist/lib/esm/stencil-route-title.entry.js +28 -0
  147. package/dist/lib/esm/stencil-router-prompt.entry.js +55 -0
  148. package/dist/lib/esm/stencil-router-redirect.entry.js +28 -0
  149. package/dist/lib/esm-es5/active-router-5e40c0f8.js +1 -0
  150. package/dist/lib/esm-es5/apollo-super-selection.js +1 -0
  151. package/dist/lib/esm-es5/app-globals-c1f89805.js +1 -0
  152. package/dist/lib/esm-es5/context-consumer.entry.js +1 -0
  153. package/dist/lib/esm-es5/datorama-akita-127aea91.js +15 -0
  154. package/dist/lib/esm-es5/index-189b2180.js +1 -0
  155. package/dist/lib/esm-es5/index.js +0 -0
  156. package/dist/lib/esm-es5/loader.js +1 -0
  157. package/dist/lib/esm-es5/sss-button_31.entry.js +69 -0
  158. package/dist/lib/esm-es5/stencil-async-content.entry.js +1 -0
  159. package/dist/lib/esm-es5/stencil-route-title.entry.js +1 -0
  160. package/dist/lib/esm-es5/stencil-router-prompt.entry.js +1 -0
  161. package/dist/lib/esm-es5/stencil-router-redirect.entry.js +1 -0
  162. package/dist/lib/index.cjs.js +1 -0
  163. package/dist/lib/index.js +1 -0
  164. package/dist/lib/loader/cdn.js +3 -0
  165. package/dist/lib/loader/index.cjs.js +3 -0
  166. package/dist/lib/loader/index.d.ts +13 -0
  167. package/dist/lib/loader/index.es2017.js +3 -0
  168. package/dist/lib/loader/index.js +4 -0
  169. package/dist/lib/loader/package.json +10 -0
  170. package/dist/lib/node_modules/@stencil/router/dist/collection/components/route/route.css +3 -0
  171. package/dist/lib/types/components/app-host/loading-page.d.ts +3 -0
  172. package/dist/lib/types/components/app-host/services/app-configuration.query.d.ts +11 -0
  173. package/dist/lib/types/components/app-host/services/app-configuration.service.d.ts +9 -0
  174. package/dist/lib/types/components/app-host/services/app-parameters.query.d.ts +10 -0
  175. package/dist/lib/types/components/app-host/services/app-parameters.service.d.ts +6 -0
  176. package/dist/lib/types/components/app-host/services/appinsights.service.d.ts +15 -0
  177. package/dist/lib/types/components/app-host/services/authentication.query.d.ts +13 -0
  178. package/dist/lib/types/components/app-host/services/authentication.service.d.ts +9 -0
  179. package/dist/lib/types/components/app-host/services/interop/host-interop.service.d.ts +7 -0
  180. package/dist/lib/types/components/app-host/services/interop/iframe-interop.service.d.ts +5 -0
  181. package/dist/lib/types/components/app-host/services/interop/react-native-interop.service.d.ts +7 -0
  182. package/dist/lib/types/components/app-host/services/interop.query.d.ts +11 -0
  183. package/dist/lib/types/components/app-host/services/session.store.d.ts +31 -0
  184. package/dist/lib/types/components/app-host/super-selection-app-host.d.ts +15 -0
  185. package/dist/lib/types/components/super-campaign/super-campaign-types.d.ts +96 -0
  186. package/dist/lib/types/components/super-campaign/super-campaign.d.ts +37 -0
  187. package/dist/lib/types/components/super-selection-app/api/api-client.d.ts +2 -0
  188. package/dist/lib/types/components/super-selection-app/api/event-tracking.api.d.ts +6 -0
  189. package/dist/lib/types/components/super-selection-app/api/super-campaign-errors-api.d.ts +6 -0
  190. package/dist/lib/types/components/super-selection-app/api/super-campaign-errors.api.dtos.d.ts +7 -0
  191. package/dist/lib/types/components/super-selection-app/api/super-selection-events.model.d.ts +149 -0
  192. package/dist/lib/types/components/super-selection-app/api/super-selection.api.d.ts +16 -0
  193. package/dist/lib/types/components/super-selection-app/api/super-selection.api.dto.d.ts +233 -0
  194. package/dist/lib/types/components/super-selection-app/app-state-pages/success.d.ts +7 -0
  195. package/dist/lib/types/components/super-selection-app/existing-choice/existing-choice.d.ts +12 -0
  196. package/dist/lib/types/components/super-selection-app/footer-section/footer-section.d.ts +5 -0
  197. package/dist/lib/types/components/super-selection-app/funds/custom-fund/api/custom-fund-choice.api.d.ts +10 -0
  198. package/dist/lib/types/components/super-selection-app/funds/custom-fund/api/custom-fund-choice.api.dto.d.ts +43 -0
  199. package/dist/lib/types/components/super-selection-app/funds/custom-fund/custom-fund.d.ts +9 -0
  200. package/dist/lib/types/components/super-selection-app/funds/custom-fund/custom-fund.store.d.ts +30 -0
  201. package/dist/lib/types/components/super-selection-app/funds/custom-fund/default-fund/default-fund.d.ts +13 -0
  202. package/dist/lib/types/components/super-selection-app/funds/custom-fund/member-name-input.d.ts +14 -0
  203. package/dist/lib/types/components/super-selection-app/funds/custom-fund/my-own-fund/my-own-fund-inputs.d.ts +16 -0
  204. package/dist/lib/types/components/super-selection-app/funds/custom-fund/my-own-fund/my-own-fund.d.ts +13 -0
  205. package/dist/lib/types/components/super-selection-app/funds/custom-fund/self-managed-fund/abn-validation.d.ts +1 -0
  206. package/dist/lib/types/components/super-selection-app/funds/custom-fund/self-managed-fund/bankBsbNumbers.d.ts +112 -0
  207. package/dist/lib/types/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund-inputs.d.ts +29 -0
  208. package/dist/lib/types/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund.d.ts +14 -0
  209. package/dist/lib/types/components/super-selection-app/funds/custom-fund/self-managed-fund/self-managed-fund.form.d.ts +15 -0
  210. package/dist/lib/types/components/super-selection-app/funds/promoted-fund/api/promoted-fund-choice.api.d.ts +8 -0
  211. package/dist/lib/types/components/super-selection-app/funds/promoted-fund/api/promoted-fund-choice.api.dto.d.ts +25 -0
  212. package/dist/lib/types/components/super-selection-app/funds/slate-super/api/slate-choice.api.d.ts +6 -0
  213. package/dist/lib/types/components/super-selection-app/funds/slate-super/api/slate-choice.api.dto.d.ts +8 -0
  214. package/dist/lib/types/components/super-selection-app/funds/slate-super/api/slate.d.ts +4 -0
  215. package/dist/lib/types/components/super-selection-app/header-section/header-section.d.ts +4 -0
  216. package/dist/lib/types/components/super-selection-app/misc/button.d.ts +14 -0
  217. package/dist/lib/types/components/super-selection-app/misc/dropdown-async.d.ts +52 -0
  218. package/dist/lib/types/components/super-selection-app/misc/loading-indicator.d.ts +5 -0
  219. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-common.d.ts +9 -0
  220. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-display-field.d.ts +5 -0
  221. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-error-box.d.ts +5 -0
  222. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-invalid-my-own-fund.d.ts +18 -0
  223. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-invalid-smsf.d.ts +28 -0
  224. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-my-own-fund.d.ts +30 -0
  225. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-smsf.d.ts +52 -0
  226. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-types.d.ts +95 -0
  227. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill-warning-box.d.ts +4 -0
  228. package/dist/lib/types/components/super-selection-app/prefill-fund/prefill.d.ts +14 -0
  229. package/dist/lib/types/components/super-selection-app/services/australian-fund-lookup.service.d.ts +8 -0
  230. package/dist/lib/types/components/super-selection-app/services/event-tracking.service.d.ts +21 -0
  231. package/dist/lib/types/components/super-selection-app/services/existing-super-choice-info.service.d.ts +75 -0
  232. package/dist/lib/types/components/super-selection-app/services/misc.service.d.ts +6 -0
  233. package/dist/lib/types/components/super-selection-app/services/navigation.service.d.ts +17 -0
  234. package/dist/lib/types/components/super-selection-app/services/super-selection-app.routes.d.ts +16 -0
  235. package/dist/lib/types/components/super-selection-app/services/super-selection-app.service.d.ts +38 -0
  236. package/dist/lib/types/components/super-selection-app/services/super-selection.store.d.ts +34 -0
  237. package/dist/lib/types/components/super-selection-app/standard-choice/standard-choice-form.d.ts +16 -0
  238. package/dist/lib/types/components/super-selection-app/standard-choice/standard-choice-form.store.d.ts +42 -0
  239. package/dist/lib/types/components/super-selection-app/super-selection-app.d.ts +27 -0
  240. package/dist/lib/types/components.d.ts +503 -0
  241. package/dist/lib/types/global/init-host.d.ts +1 -0
  242. package/dist/lib/types/global/main.d.ts +1 -0
  243. package/dist/lib/types/global/main.dev.d.ts +1 -0
  244. package/dist/lib/types/global/stencil-router-workaround.d.ts +1 -0
  245. package/dist/lib/types/index.d.ts +2 -0
  246. package/dist/lib/types/stencil-public-runtime.d.ts +1555 -0
  247. package/dist/lib/types/utils/config.d.ts +2 -0
  248. package/dist/lib/types/utils/gtm.d.ts +7 -0
  249. package/dist/lib/types/utils/iframe.d.ts +13 -0
  250. package/dist/lib/types/utils/index.d.ts +4 -0
  251. package/dist/lib/types/utils/lazy.d.ts +12 -0
  252. package/dist/lib/types/utils/storage.d.ts +4 -0
  253. package/package.json +1 -1
@@ -0,0 +1,3624 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+
16
+ function __rest(s, e) {
17
+ var t = {};
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
19
+ t[p] = s[p];
20
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
21
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
22
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
23
+ t[p[i]] = s[p[i]];
24
+ }
25
+ return t;
26
+ }
27
+
28
+ function __decorate(decorators, target, key, desc) {
29
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
30
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31
+ 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;
32
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
33
+ }
34
+
35
+ function __metadata(metadataKey, metadataValue) {
36
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
37
+ }
38
+
39
+ function isFunction(x) {
40
+ return typeof x === 'function';
41
+ }
42
+
43
+ let _enable_super_gross_mode_that_will_cause_bad_things = false;
44
+ const config = {
45
+ Promise: undefined,
46
+ set useDeprecatedSynchronousErrorHandling(value) {
47
+ if (value) {
48
+ const error = new Error();
49
+ console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack);
50
+ }
51
+ else if (_enable_super_gross_mode_that_will_cause_bad_things) {
52
+ console.log('RxJS: Back to a better error behavior. Thank you. <3');
53
+ }
54
+ _enable_super_gross_mode_that_will_cause_bad_things = value;
55
+ },
56
+ get useDeprecatedSynchronousErrorHandling() {
57
+ return _enable_super_gross_mode_that_will_cause_bad_things;
58
+ },
59
+ };
60
+
61
+ function hostReportError(err) {
62
+ setTimeout(() => { throw err; }, 0);
63
+ }
64
+
65
+ const empty = {
66
+ closed: true,
67
+ next(value) { },
68
+ error(err) {
69
+ if (config.useDeprecatedSynchronousErrorHandling) {
70
+ throw err;
71
+ }
72
+ else {
73
+ hostReportError(err);
74
+ }
75
+ },
76
+ complete() { }
77
+ };
78
+
79
+ const isArray = (() => Array.isArray || ((x) => x && typeof x.length === 'number'))();
80
+
81
+ function isObject(x) {
82
+ return x !== null && typeof x === 'object';
83
+ }
84
+
85
+ const UnsubscriptionErrorImpl = (() => {
86
+ function UnsubscriptionErrorImpl(errors) {
87
+ Error.call(this);
88
+ this.message = errors ?
89
+ `${errors.length} errors occurred during unsubscription:
90
+ ${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n ')}` : '';
91
+ this.name = 'UnsubscriptionError';
92
+ this.errors = errors;
93
+ return this;
94
+ }
95
+ UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype);
96
+ return UnsubscriptionErrorImpl;
97
+ })();
98
+ const UnsubscriptionError = UnsubscriptionErrorImpl;
99
+
100
+ class Subscription {
101
+ constructor(unsubscribe) {
102
+ this.closed = false;
103
+ this._parentOrParents = null;
104
+ this._subscriptions = null;
105
+ if (unsubscribe) {
106
+ this._ctorUnsubscribe = true;
107
+ this._unsubscribe = unsubscribe;
108
+ }
109
+ }
110
+ unsubscribe() {
111
+ let errors;
112
+ if (this.closed) {
113
+ return;
114
+ }
115
+ let { _parentOrParents, _ctorUnsubscribe, _unsubscribe, _subscriptions } = this;
116
+ this.closed = true;
117
+ this._parentOrParents = null;
118
+ this._subscriptions = null;
119
+ if (_parentOrParents instanceof Subscription) {
120
+ _parentOrParents.remove(this);
121
+ }
122
+ else if (_parentOrParents !== null) {
123
+ for (let index = 0; index < _parentOrParents.length; ++index) {
124
+ const parent = _parentOrParents[index];
125
+ parent.remove(this);
126
+ }
127
+ }
128
+ if (isFunction(_unsubscribe)) {
129
+ if (_ctorUnsubscribe) {
130
+ this._unsubscribe = undefined;
131
+ }
132
+ try {
133
+ _unsubscribe.call(this);
134
+ }
135
+ catch (e) {
136
+ errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];
137
+ }
138
+ }
139
+ if (isArray(_subscriptions)) {
140
+ let index = -1;
141
+ let len = _subscriptions.length;
142
+ while (++index < len) {
143
+ const sub = _subscriptions[index];
144
+ if (isObject(sub)) {
145
+ try {
146
+ sub.unsubscribe();
147
+ }
148
+ catch (e) {
149
+ errors = errors || [];
150
+ if (e instanceof UnsubscriptionError) {
151
+ errors = errors.concat(flattenUnsubscriptionErrors(e.errors));
152
+ }
153
+ else {
154
+ errors.push(e);
155
+ }
156
+ }
157
+ }
158
+ }
159
+ }
160
+ if (errors) {
161
+ throw new UnsubscriptionError(errors);
162
+ }
163
+ }
164
+ add(teardown) {
165
+ let subscription = teardown;
166
+ if (!teardown) {
167
+ return Subscription.EMPTY;
168
+ }
169
+ switch (typeof teardown) {
170
+ case 'function':
171
+ subscription = new Subscription(teardown);
172
+ case 'object':
173
+ if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {
174
+ return subscription;
175
+ }
176
+ else if (this.closed) {
177
+ subscription.unsubscribe();
178
+ return subscription;
179
+ }
180
+ else if (!(subscription instanceof Subscription)) {
181
+ const tmp = subscription;
182
+ subscription = new Subscription();
183
+ subscription._subscriptions = [tmp];
184
+ }
185
+ break;
186
+ default: {
187
+ throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
188
+ }
189
+ }
190
+ let { _parentOrParents } = subscription;
191
+ if (_parentOrParents === null) {
192
+ subscription._parentOrParents = this;
193
+ }
194
+ else if (_parentOrParents instanceof Subscription) {
195
+ if (_parentOrParents === this) {
196
+ return subscription;
197
+ }
198
+ subscription._parentOrParents = [_parentOrParents, this];
199
+ }
200
+ else if (_parentOrParents.indexOf(this) === -1) {
201
+ _parentOrParents.push(this);
202
+ }
203
+ else {
204
+ return subscription;
205
+ }
206
+ const subscriptions = this._subscriptions;
207
+ if (subscriptions === null) {
208
+ this._subscriptions = [subscription];
209
+ }
210
+ else {
211
+ subscriptions.push(subscription);
212
+ }
213
+ return subscription;
214
+ }
215
+ remove(subscription) {
216
+ const subscriptions = this._subscriptions;
217
+ if (subscriptions) {
218
+ const subscriptionIndex = subscriptions.indexOf(subscription);
219
+ if (subscriptionIndex !== -1) {
220
+ subscriptions.splice(subscriptionIndex, 1);
221
+ }
222
+ }
223
+ }
224
+ }
225
+ Subscription.EMPTY = (function (empty) {
226
+ empty.closed = true;
227
+ return empty;
228
+ }(new Subscription()));
229
+ function flattenUnsubscriptionErrors(errors) {
230
+ return errors.reduce((errs, err) => errs.concat((err instanceof UnsubscriptionError) ? err.errors : err), []);
231
+ }
232
+
233
+ const rxSubscriber = (() => typeof Symbol === 'function'
234
+ ? Symbol('rxSubscriber')
235
+ : '@@rxSubscriber_' + Math.random())();
236
+
237
+ class Subscriber extends Subscription {
238
+ constructor(destinationOrNext, error, complete) {
239
+ super();
240
+ this.syncErrorValue = null;
241
+ this.syncErrorThrown = false;
242
+ this.syncErrorThrowable = false;
243
+ this.isStopped = false;
244
+ switch (arguments.length) {
245
+ case 0:
246
+ this.destination = empty;
247
+ break;
248
+ case 1:
249
+ if (!destinationOrNext) {
250
+ this.destination = empty;
251
+ break;
252
+ }
253
+ if (typeof destinationOrNext === 'object') {
254
+ if (destinationOrNext instanceof Subscriber) {
255
+ this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
256
+ this.destination = destinationOrNext;
257
+ destinationOrNext.add(this);
258
+ }
259
+ else {
260
+ this.syncErrorThrowable = true;
261
+ this.destination = new SafeSubscriber(this, destinationOrNext);
262
+ }
263
+ break;
264
+ }
265
+ default:
266
+ this.syncErrorThrowable = true;
267
+ this.destination = new SafeSubscriber(this, destinationOrNext, error, complete);
268
+ break;
269
+ }
270
+ }
271
+ [rxSubscriber]() { return this; }
272
+ static create(next, error, complete) {
273
+ const subscriber = new Subscriber(next, error, complete);
274
+ subscriber.syncErrorThrowable = false;
275
+ return subscriber;
276
+ }
277
+ next(value) {
278
+ if (!this.isStopped) {
279
+ this._next(value);
280
+ }
281
+ }
282
+ error(err) {
283
+ if (!this.isStopped) {
284
+ this.isStopped = true;
285
+ this._error(err);
286
+ }
287
+ }
288
+ complete() {
289
+ if (!this.isStopped) {
290
+ this.isStopped = true;
291
+ this._complete();
292
+ }
293
+ }
294
+ unsubscribe() {
295
+ if (this.closed) {
296
+ return;
297
+ }
298
+ this.isStopped = true;
299
+ super.unsubscribe();
300
+ }
301
+ _next(value) {
302
+ this.destination.next(value);
303
+ }
304
+ _error(err) {
305
+ this.destination.error(err);
306
+ this.unsubscribe();
307
+ }
308
+ _complete() {
309
+ this.destination.complete();
310
+ this.unsubscribe();
311
+ }
312
+ _unsubscribeAndRecycle() {
313
+ const { _parentOrParents } = this;
314
+ this._parentOrParents = null;
315
+ this.unsubscribe();
316
+ this.closed = false;
317
+ this.isStopped = false;
318
+ this._parentOrParents = _parentOrParents;
319
+ return this;
320
+ }
321
+ }
322
+ class SafeSubscriber extends Subscriber {
323
+ constructor(_parentSubscriber, observerOrNext, error, complete) {
324
+ super();
325
+ this._parentSubscriber = _parentSubscriber;
326
+ let next;
327
+ let context = this;
328
+ if (isFunction(observerOrNext)) {
329
+ next = observerOrNext;
330
+ }
331
+ else if (observerOrNext) {
332
+ next = observerOrNext.next;
333
+ error = observerOrNext.error;
334
+ complete = observerOrNext.complete;
335
+ if (observerOrNext !== empty) {
336
+ context = Object.create(observerOrNext);
337
+ if (isFunction(context.unsubscribe)) {
338
+ this.add(context.unsubscribe.bind(context));
339
+ }
340
+ context.unsubscribe = this.unsubscribe.bind(this);
341
+ }
342
+ }
343
+ this._context = context;
344
+ this._next = next;
345
+ this._error = error;
346
+ this._complete = complete;
347
+ }
348
+ next(value) {
349
+ if (!this.isStopped && this._next) {
350
+ const { _parentSubscriber } = this;
351
+ if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
352
+ this.__tryOrUnsub(this._next, value);
353
+ }
354
+ else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
355
+ this.unsubscribe();
356
+ }
357
+ }
358
+ }
359
+ error(err) {
360
+ if (!this.isStopped) {
361
+ const { _parentSubscriber } = this;
362
+ const { useDeprecatedSynchronousErrorHandling } = config;
363
+ if (this._error) {
364
+ if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
365
+ this.__tryOrUnsub(this._error, err);
366
+ this.unsubscribe();
367
+ }
368
+ else {
369
+ this.__tryOrSetError(_parentSubscriber, this._error, err);
370
+ this.unsubscribe();
371
+ }
372
+ }
373
+ else if (!_parentSubscriber.syncErrorThrowable) {
374
+ this.unsubscribe();
375
+ if (useDeprecatedSynchronousErrorHandling) {
376
+ throw err;
377
+ }
378
+ hostReportError(err);
379
+ }
380
+ else {
381
+ if (useDeprecatedSynchronousErrorHandling) {
382
+ _parentSubscriber.syncErrorValue = err;
383
+ _parentSubscriber.syncErrorThrown = true;
384
+ }
385
+ else {
386
+ hostReportError(err);
387
+ }
388
+ this.unsubscribe();
389
+ }
390
+ }
391
+ }
392
+ complete() {
393
+ if (!this.isStopped) {
394
+ const { _parentSubscriber } = this;
395
+ if (this._complete) {
396
+ const wrappedComplete = () => this._complete.call(this._context);
397
+ if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
398
+ this.__tryOrUnsub(wrappedComplete);
399
+ this.unsubscribe();
400
+ }
401
+ else {
402
+ this.__tryOrSetError(_parentSubscriber, wrappedComplete);
403
+ this.unsubscribe();
404
+ }
405
+ }
406
+ else {
407
+ this.unsubscribe();
408
+ }
409
+ }
410
+ }
411
+ __tryOrUnsub(fn, value) {
412
+ try {
413
+ fn.call(this._context, value);
414
+ }
415
+ catch (err) {
416
+ this.unsubscribe();
417
+ if (config.useDeprecatedSynchronousErrorHandling) {
418
+ throw err;
419
+ }
420
+ else {
421
+ hostReportError(err);
422
+ }
423
+ }
424
+ }
425
+ __tryOrSetError(parent, fn, value) {
426
+ if (!config.useDeprecatedSynchronousErrorHandling) {
427
+ throw new Error('bad call');
428
+ }
429
+ try {
430
+ fn.call(this._context, value);
431
+ }
432
+ catch (err) {
433
+ if (config.useDeprecatedSynchronousErrorHandling) {
434
+ parent.syncErrorValue = err;
435
+ parent.syncErrorThrown = true;
436
+ return true;
437
+ }
438
+ else {
439
+ hostReportError(err);
440
+ return true;
441
+ }
442
+ }
443
+ return false;
444
+ }
445
+ _unsubscribe() {
446
+ const { _parentSubscriber } = this;
447
+ this._context = null;
448
+ this._parentSubscriber = null;
449
+ _parentSubscriber.unsubscribe();
450
+ }
451
+ }
452
+
453
+ function canReportError(observer) {
454
+ while (observer) {
455
+ const { closed, destination, isStopped } = observer;
456
+ if (closed || isStopped) {
457
+ return false;
458
+ }
459
+ else if (destination && destination instanceof Subscriber) {
460
+ observer = destination;
461
+ }
462
+ else {
463
+ observer = null;
464
+ }
465
+ }
466
+ return true;
467
+ }
468
+
469
+ function toSubscriber(nextOrObserver, error, complete) {
470
+ if (nextOrObserver) {
471
+ if (nextOrObserver instanceof Subscriber) {
472
+ return nextOrObserver;
473
+ }
474
+ if (nextOrObserver[rxSubscriber]) {
475
+ return nextOrObserver[rxSubscriber]();
476
+ }
477
+ }
478
+ if (!nextOrObserver && !error && !complete) {
479
+ return new Subscriber(empty);
480
+ }
481
+ return new Subscriber(nextOrObserver, error, complete);
482
+ }
483
+
484
+ const observable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
485
+
486
+ function identity(x) {
487
+ return x;
488
+ }
489
+
490
+ function pipeFromArray(fns) {
491
+ if (fns.length === 0) {
492
+ return identity;
493
+ }
494
+ if (fns.length === 1) {
495
+ return fns[0];
496
+ }
497
+ return function piped(input) {
498
+ return fns.reduce((prev, fn) => fn(prev), input);
499
+ };
500
+ }
501
+
502
+ class Observable {
503
+ constructor(subscribe) {
504
+ this._isScalar = false;
505
+ if (subscribe) {
506
+ this._subscribe = subscribe;
507
+ }
508
+ }
509
+ lift(operator) {
510
+ const observable = new Observable();
511
+ observable.source = this;
512
+ observable.operator = operator;
513
+ return observable;
514
+ }
515
+ subscribe(observerOrNext, error, complete) {
516
+ const { operator } = this;
517
+ const sink = toSubscriber(observerOrNext, error, complete);
518
+ if (operator) {
519
+ sink.add(operator.call(sink, this.source));
520
+ }
521
+ else {
522
+ sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
523
+ this._subscribe(sink) :
524
+ this._trySubscribe(sink));
525
+ }
526
+ if (config.useDeprecatedSynchronousErrorHandling) {
527
+ if (sink.syncErrorThrowable) {
528
+ sink.syncErrorThrowable = false;
529
+ if (sink.syncErrorThrown) {
530
+ throw sink.syncErrorValue;
531
+ }
532
+ }
533
+ }
534
+ return sink;
535
+ }
536
+ _trySubscribe(sink) {
537
+ try {
538
+ return this._subscribe(sink);
539
+ }
540
+ catch (err) {
541
+ if (config.useDeprecatedSynchronousErrorHandling) {
542
+ sink.syncErrorThrown = true;
543
+ sink.syncErrorValue = err;
544
+ }
545
+ if (canReportError(sink)) {
546
+ sink.error(err);
547
+ }
548
+ else {
549
+ console.warn(err);
550
+ }
551
+ }
552
+ }
553
+ forEach(next, promiseCtor) {
554
+ promiseCtor = getPromiseCtor(promiseCtor);
555
+ return new promiseCtor((resolve, reject) => {
556
+ let subscription;
557
+ subscription = this.subscribe((value) => {
558
+ try {
559
+ next(value);
560
+ }
561
+ catch (err) {
562
+ reject(err);
563
+ if (subscription) {
564
+ subscription.unsubscribe();
565
+ }
566
+ }
567
+ }, reject, resolve);
568
+ });
569
+ }
570
+ _subscribe(subscriber) {
571
+ const { source } = this;
572
+ return source && source.subscribe(subscriber);
573
+ }
574
+ [observable]() {
575
+ return this;
576
+ }
577
+ pipe(...operations) {
578
+ if (operations.length === 0) {
579
+ return this;
580
+ }
581
+ return pipeFromArray(operations)(this);
582
+ }
583
+ toPromise(promiseCtor) {
584
+ promiseCtor = getPromiseCtor(promiseCtor);
585
+ return new promiseCtor((resolve, reject) => {
586
+ let value;
587
+ this.subscribe((x) => value = x, (err) => reject(err), () => resolve(value));
588
+ });
589
+ }
590
+ }
591
+ Observable.create = (subscribe) => {
592
+ return new Observable(subscribe);
593
+ };
594
+ function getPromiseCtor(promiseCtor) {
595
+ if (!promiseCtor) {
596
+ promiseCtor = Promise;
597
+ }
598
+ if (!promiseCtor) {
599
+ throw new Error('no Promise impl found');
600
+ }
601
+ return promiseCtor;
602
+ }
603
+
604
+ const ObjectUnsubscribedErrorImpl = (() => {
605
+ function ObjectUnsubscribedErrorImpl() {
606
+ Error.call(this);
607
+ this.message = 'object unsubscribed';
608
+ this.name = 'ObjectUnsubscribedError';
609
+ return this;
610
+ }
611
+ ObjectUnsubscribedErrorImpl.prototype = Object.create(Error.prototype);
612
+ return ObjectUnsubscribedErrorImpl;
613
+ })();
614
+ const ObjectUnsubscribedError = ObjectUnsubscribedErrorImpl;
615
+
616
+ class SubjectSubscription extends Subscription {
617
+ constructor(subject, subscriber) {
618
+ super();
619
+ this.subject = subject;
620
+ this.subscriber = subscriber;
621
+ this.closed = false;
622
+ }
623
+ unsubscribe() {
624
+ if (this.closed) {
625
+ return;
626
+ }
627
+ this.closed = true;
628
+ const subject = this.subject;
629
+ const observers = subject.observers;
630
+ this.subject = null;
631
+ if (!observers || observers.length === 0 || subject.isStopped || subject.closed) {
632
+ return;
633
+ }
634
+ const subscriberIndex = observers.indexOf(this.subscriber);
635
+ if (subscriberIndex !== -1) {
636
+ observers.splice(subscriberIndex, 1);
637
+ }
638
+ }
639
+ }
640
+
641
+ class SubjectSubscriber extends Subscriber {
642
+ constructor(destination) {
643
+ super(destination);
644
+ this.destination = destination;
645
+ }
646
+ }
647
+ class Subject extends Observable {
648
+ constructor() {
649
+ super();
650
+ this.observers = [];
651
+ this.closed = false;
652
+ this.isStopped = false;
653
+ this.hasError = false;
654
+ this.thrownError = null;
655
+ }
656
+ [rxSubscriber]() {
657
+ return new SubjectSubscriber(this);
658
+ }
659
+ lift(operator) {
660
+ const subject = new AnonymousSubject(this, this);
661
+ subject.operator = operator;
662
+ return subject;
663
+ }
664
+ next(value) {
665
+ if (this.closed) {
666
+ throw new ObjectUnsubscribedError();
667
+ }
668
+ if (!this.isStopped) {
669
+ const { observers } = this;
670
+ const len = observers.length;
671
+ const copy = observers.slice();
672
+ for (let i = 0; i < len; i++) {
673
+ copy[i].next(value);
674
+ }
675
+ }
676
+ }
677
+ error(err) {
678
+ if (this.closed) {
679
+ throw new ObjectUnsubscribedError();
680
+ }
681
+ this.hasError = true;
682
+ this.thrownError = err;
683
+ this.isStopped = true;
684
+ const { observers } = this;
685
+ const len = observers.length;
686
+ const copy = observers.slice();
687
+ for (let i = 0; i < len; i++) {
688
+ copy[i].error(err);
689
+ }
690
+ this.observers.length = 0;
691
+ }
692
+ complete() {
693
+ if (this.closed) {
694
+ throw new ObjectUnsubscribedError();
695
+ }
696
+ this.isStopped = true;
697
+ const { observers } = this;
698
+ const len = observers.length;
699
+ const copy = observers.slice();
700
+ for (let i = 0; i < len; i++) {
701
+ copy[i].complete();
702
+ }
703
+ this.observers.length = 0;
704
+ }
705
+ unsubscribe() {
706
+ this.isStopped = true;
707
+ this.closed = true;
708
+ this.observers = null;
709
+ }
710
+ _trySubscribe(subscriber) {
711
+ if (this.closed) {
712
+ throw new ObjectUnsubscribedError();
713
+ }
714
+ else {
715
+ return super._trySubscribe(subscriber);
716
+ }
717
+ }
718
+ _subscribe(subscriber) {
719
+ if (this.closed) {
720
+ throw new ObjectUnsubscribedError();
721
+ }
722
+ else if (this.hasError) {
723
+ subscriber.error(this.thrownError);
724
+ return Subscription.EMPTY;
725
+ }
726
+ else if (this.isStopped) {
727
+ subscriber.complete();
728
+ return Subscription.EMPTY;
729
+ }
730
+ else {
731
+ this.observers.push(subscriber);
732
+ return new SubjectSubscription(this, subscriber);
733
+ }
734
+ }
735
+ asObservable() {
736
+ const observable = new Observable();
737
+ observable.source = this;
738
+ return observable;
739
+ }
740
+ }
741
+ Subject.create = (destination, source) => {
742
+ return new AnonymousSubject(destination, source);
743
+ };
744
+ class AnonymousSubject extends Subject {
745
+ constructor(destination, source) {
746
+ super();
747
+ this.destination = destination;
748
+ this.source = source;
749
+ }
750
+ next(value) {
751
+ const { destination } = this;
752
+ if (destination && destination.next) {
753
+ destination.next(value);
754
+ }
755
+ }
756
+ error(err) {
757
+ const { destination } = this;
758
+ if (destination && destination.error) {
759
+ this.destination.error(err);
760
+ }
761
+ }
762
+ complete() {
763
+ const { destination } = this;
764
+ if (destination && destination.complete) {
765
+ this.destination.complete();
766
+ }
767
+ }
768
+ _subscribe(subscriber) {
769
+ const { source } = this;
770
+ if (source) {
771
+ return this.source.subscribe(subscriber);
772
+ }
773
+ else {
774
+ return Subscription.EMPTY;
775
+ }
776
+ }
777
+ }
778
+
779
+ class BehaviorSubject extends Subject {
780
+ constructor(_value) {
781
+ super();
782
+ this._value = _value;
783
+ }
784
+ get value() {
785
+ return this.getValue();
786
+ }
787
+ _subscribe(subscriber) {
788
+ const subscription = super._subscribe(subscriber);
789
+ if (subscription && !subscription.closed) {
790
+ subscriber.next(this._value);
791
+ }
792
+ return subscription;
793
+ }
794
+ getValue() {
795
+ if (this.hasError) {
796
+ throw this.thrownError;
797
+ }
798
+ else if (this.closed) {
799
+ throw new ObjectUnsubscribedError();
800
+ }
801
+ else {
802
+ return this._value;
803
+ }
804
+ }
805
+ next(value) {
806
+ super.next(this._value = value);
807
+ }
808
+ }
809
+
810
+ class Action extends Subscription {
811
+ constructor(scheduler, work) {
812
+ super();
813
+ }
814
+ schedule(state, delay = 0) {
815
+ return this;
816
+ }
817
+ }
818
+
819
+ class AsyncAction extends Action {
820
+ constructor(scheduler, work) {
821
+ super(scheduler, work);
822
+ this.scheduler = scheduler;
823
+ this.work = work;
824
+ this.pending = false;
825
+ }
826
+ schedule(state, delay = 0) {
827
+ if (this.closed) {
828
+ return this;
829
+ }
830
+ this.state = state;
831
+ const id = this.id;
832
+ const scheduler = this.scheduler;
833
+ if (id != null) {
834
+ this.id = this.recycleAsyncId(scheduler, id, delay);
835
+ }
836
+ this.pending = true;
837
+ this.delay = delay;
838
+ this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
839
+ return this;
840
+ }
841
+ requestAsyncId(scheduler, id, delay = 0) {
842
+ return setInterval(scheduler.flush.bind(scheduler, this), delay);
843
+ }
844
+ recycleAsyncId(scheduler, id, delay = 0) {
845
+ if (delay !== null && this.delay === delay && this.pending === false) {
846
+ return id;
847
+ }
848
+ clearInterval(id);
849
+ return undefined;
850
+ }
851
+ execute(state, delay) {
852
+ if (this.closed) {
853
+ return new Error('executing a cancelled action');
854
+ }
855
+ this.pending = false;
856
+ const error = this._execute(state, delay);
857
+ if (error) {
858
+ return error;
859
+ }
860
+ else if (this.pending === false && this.id != null) {
861
+ this.id = this.recycleAsyncId(this.scheduler, this.id, null);
862
+ }
863
+ }
864
+ _execute(state, delay) {
865
+ let errored = false;
866
+ let errorValue = undefined;
867
+ try {
868
+ this.work(state);
869
+ }
870
+ catch (e) {
871
+ errored = true;
872
+ errorValue = !!e && e || new Error(e);
873
+ }
874
+ if (errored) {
875
+ this.unsubscribe();
876
+ return errorValue;
877
+ }
878
+ }
879
+ _unsubscribe() {
880
+ const id = this.id;
881
+ const scheduler = this.scheduler;
882
+ const actions = scheduler.actions;
883
+ const index = actions.indexOf(this);
884
+ this.work = null;
885
+ this.state = null;
886
+ this.pending = false;
887
+ this.scheduler = null;
888
+ if (index !== -1) {
889
+ actions.splice(index, 1);
890
+ }
891
+ if (id != null) {
892
+ this.id = this.recycleAsyncId(scheduler, id, null);
893
+ }
894
+ this.delay = null;
895
+ }
896
+ }
897
+
898
+ class QueueAction extends AsyncAction {
899
+ constructor(scheduler, work) {
900
+ super(scheduler, work);
901
+ this.scheduler = scheduler;
902
+ this.work = work;
903
+ }
904
+ schedule(state, delay = 0) {
905
+ if (delay > 0) {
906
+ return super.schedule(state, delay);
907
+ }
908
+ this.delay = delay;
909
+ this.state = state;
910
+ this.scheduler.flush(this);
911
+ return this;
912
+ }
913
+ execute(state, delay) {
914
+ return (delay > 0 || this.closed) ?
915
+ super.execute(state, delay) :
916
+ this._execute(state, delay);
917
+ }
918
+ requestAsyncId(scheduler, id, delay = 0) {
919
+ if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
920
+ return super.requestAsyncId(scheduler, id, delay);
921
+ }
922
+ return scheduler.flush(this);
923
+ }
924
+ }
925
+
926
+ class Scheduler {
927
+ constructor(SchedulerAction, now = Scheduler.now) {
928
+ this.SchedulerAction = SchedulerAction;
929
+ this.now = now;
930
+ }
931
+ schedule(work, delay = 0, state) {
932
+ return new this.SchedulerAction(this, work).schedule(state, delay);
933
+ }
934
+ }
935
+ Scheduler.now = () => Date.now();
936
+
937
+ class AsyncScheduler extends Scheduler {
938
+ constructor(SchedulerAction, now = Scheduler.now) {
939
+ super(SchedulerAction, () => {
940
+ if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
941
+ return AsyncScheduler.delegate.now();
942
+ }
943
+ else {
944
+ return now();
945
+ }
946
+ });
947
+ this.actions = [];
948
+ this.active = false;
949
+ this.scheduled = undefined;
950
+ }
951
+ schedule(work, delay = 0, state) {
952
+ if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
953
+ return AsyncScheduler.delegate.schedule(work, delay, state);
954
+ }
955
+ else {
956
+ return super.schedule(work, delay, state);
957
+ }
958
+ }
959
+ flush(action) {
960
+ const { actions } = this;
961
+ if (this.active) {
962
+ actions.push(action);
963
+ return;
964
+ }
965
+ let error;
966
+ this.active = true;
967
+ do {
968
+ if (error = action.execute(action.state, action.delay)) {
969
+ break;
970
+ }
971
+ } while (action = actions.shift());
972
+ this.active = false;
973
+ if (error) {
974
+ while (action = actions.shift()) {
975
+ action.unsubscribe();
976
+ }
977
+ throw error;
978
+ }
979
+ }
980
+ }
981
+
982
+ class QueueScheduler extends AsyncScheduler {
983
+ }
984
+
985
+ const queueScheduler = new QueueScheduler(QueueAction);
986
+ const queue = queueScheduler;
987
+
988
+ const EMPTY = new Observable(subscriber => subscriber.complete());
989
+ function empty$1(scheduler) {
990
+ return scheduler ? emptyScheduled(scheduler) : EMPTY;
991
+ }
992
+ function emptyScheduled(scheduler) {
993
+ return new Observable(subscriber => scheduler.schedule(() => subscriber.complete()));
994
+ }
995
+
996
+ function isScheduler(value) {
997
+ return value && typeof value.schedule === 'function';
998
+ }
999
+
1000
+ const subscribeToArray = (array) => (subscriber) => {
1001
+ for (let i = 0, len = array.length; i < len && !subscriber.closed; i++) {
1002
+ subscriber.next(array[i]);
1003
+ }
1004
+ subscriber.complete();
1005
+ };
1006
+
1007
+ function scheduleArray(input, scheduler) {
1008
+ return new Observable(subscriber => {
1009
+ const sub = new Subscription();
1010
+ let i = 0;
1011
+ sub.add(scheduler.schedule(function () {
1012
+ if (i === input.length) {
1013
+ subscriber.complete();
1014
+ return;
1015
+ }
1016
+ subscriber.next(input[i++]);
1017
+ if (!subscriber.closed) {
1018
+ sub.add(this.schedule());
1019
+ }
1020
+ }));
1021
+ return sub;
1022
+ });
1023
+ }
1024
+
1025
+ function fromArray(input, scheduler) {
1026
+ if (!scheduler) {
1027
+ return new Observable(subscribeToArray(input));
1028
+ }
1029
+ else {
1030
+ return scheduleArray(input, scheduler);
1031
+ }
1032
+ }
1033
+
1034
+ function of(...args) {
1035
+ let scheduler = args[args.length - 1];
1036
+ if (isScheduler(scheduler)) {
1037
+ args.pop();
1038
+ return scheduleArray(args, scheduler);
1039
+ }
1040
+ else {
1041
+ return fromArray(args);
1042
+ }
1043
+ }
1044
+
1045
+ function throwError(error, scheduler) {
1046
+ if (!scheduler) {
1047
+ return new Observable(subscriber => subscriber.error(error));
1048
+ }
1049
+ else {
1050
+ return new Observable(subscriber => scheduler.schedule(dispatch, 0, { error, subscriber }));
1051
+ }
1052
+ }
1053
+ function dispatch({ error, subscriber }) {
1054
+ subscriber.error(error);
1055
+ }
1056
+
1057
+ var NotificationKind;
1058
+ (function (NotificationKind) {
1059
+ NotificationKind["NEXT"] = "N";
1060
+ NotificationKind["ERROR"] = "E";
1061
+ NotificationKind["COMPLETE"] = "C";
1062
+ })(NotificationKind || (NotificationKind = {}));
1063
+ class Notification {
1064
+ constructor(kind, value, error) {
1065
+ this.kind = kind;
1066
+ this.value = value;
1067
+ this.error = error;
1068
+ this.hasValue = kind === 'N';
1069
+ }
1070
+ observe(observer) {
1071
+ switch (this.kind) {
1072
+ case 'N':
1073
+ return observer.next && observer.next(this.value);
1074
+ case 'E':
1075
+ return observer.error && observer.error(this.error);
1076
+ case 'C':
1077
+ return observer.complete && observer.complete();
1078
+ }
1079
+ }
1080
+ do(next, error, complete) {
1081
+ const kind = this.kind;
1082
+ switch (kind) {
1083
+ case 'N':
1084
+ return next && next(this.value);
1085
+ case 'E':
1086
+ return error && error(this.error);
1087
+ case 'C':
1088
+ return complete && complete();
1089
+ }
1090
+ }
1091
+ accept(nextOrObserver, error, complete) {
1092
+ if (nextOrObserver && typeof nextOrObserver.next === 'function') {
1093
+ return this.observe(nextOrObserver);
1094
+ }
1095
+ else {
1096
+ return this.do(nextOrObserver, error, complete);
1097
+ }
1098
+ }
1099
+ toObservable() {
1100
+ const kind = this.kind;
1101
+ switch (kind) {
1102
+ case 'N':
1103
+ return of(this.value);
1104
+ case 'E':
1105
+ return throwError(this.error);
1106
+ case 'C':
1107
+ return empty$1();
1108
+ }
1109
+ throw new Error('unexpected notification kind value');
1110
+ }
1111
+ static createNext(value) {
1112
+ if (typeof value !== 'undefined') {
1113
+ return new Notification('N', value);
1114
+ }
1115
+ return Notification.undefinedValueNotification;
1116
+ }
1117
+ static createError(err) {
1118
+ return new Notification('E', undefined, err);
1119
+ }
1120
+ static createComplete() {
1121
+ return Notification.completeNotification;
1122
+ }
1123
+ }
1124
+ Notification.completeNotification = new Notification('C');
1125
+ Notification.undefinedValueNotification = new Notification('N', undefined);
1126
+
1127
+ class ObserveOnSubscriber extends Subscriber {
1128
+ constructor(destination, scheduler, delay = 0) {
1129
+ super(destination);
1130
+ this.scheduler = scheduler;
1131
+ this.delay = delay;
1132
+ }
1133
+ static dispatch(arg) {
1134
+ const { notification, destination } = arg;
1135
+ notification.observe(destination);
1136
+ this.unsubscribe();
1137
+ }
1138
+ scheduleMessage(notification) {
1139
+ const destination = this.destination;
1140
+ destination.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination)));
1141
+ }
1142
+ _next(value) {
1143
+ this.scheduleMessage(Notification.createNext(value));
1144
+ }
1145
+ _error(err) {
1146
+ this.scheduleMessage(Notification.createError(err));
1147
+ this.unsubscribe();
1148
+ }
1149
+ _complete() {
1150
+ this.scheduleMessage(Notification.createComplete());
1151
+ this.unsubscribe();
1152
+ }
1153
+ }
1154
+ class ObserveOnMessage {
1155
+ constructor(notification, destination) {
1156
+ this.notification = notification;
1157
+ this.destination = destination;
1158
+ }
1159
+ }
1160
+
1161
+ class ReplaySubject extends Subject {
1162
+ constructor(bufferSize = Number.POSITIVE_INFINITY, windowTime = Number.POSITIVE_INFINITY, scheduler) {
1163
+ super();
1164
+ this.scheduler = scheduler;
1165
+ this._events = [];
1166
+ this._infiniteTimeWindow = false;
1167
+ this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
1168
+ this._windowTime = windowTime < 1 ? 1 : windowTime;
1169
+ if (windowTime === Number.POSITIVE_INFINITY) {
1170
+ this._infiniteTimeWindow = true;
1171
+ this.next = this.nextInfiniteTimeWindow;
1172
+ }
1173
+ else {
1174
+ this.next = this.nextTimeWindow;
1175
+ }
1176
+ }
1177
+ nextInfiniteTimeWindow(value) {
1178
+ if (!this.isStopped) {
1179
+ const _events = this._events;
1180
+ _events.push(value);
1181
+ if (_events.length > this._bufferSize) {
1182
+ _events.shift();
1183
+ }
1184
+ }
1185
+ super.next(value);
1186
+ }
1187
+ nextTimeWindow(value) {
1188
+ if (!this.isStopped) {
1189
+ this._events.push(new ReplayEvent(this._getNow(), value));
1190
+ this._trimBufferThenGetEvents();
1191
+ }
1192
+ super.next(value);
1193
+ }
1194
+ _subscribe(subscriber) {
1195
+ const _infiniteTimeWindow = this._infiniteTimeWindow;
1196
+ const _events = _infiniteTimeWindow ? this._events : this._trimBufferThenGetEvents();
1197
+ const scheduler = this.scheduler;
1198
+ const len = _events.length;
1199
+ let subscription;
1200
+ if (this.closed) {
1201
+ throw new ObjectUnsubscribedError();
1202
+ }
1203
+ else if (this.isStopped || this.hasError) {
1204
+ subscription = Subscription.EMPTY;
1205
+ }
1206
+ else {
1207
+ this.observers.push(subscriber);
1208
+ subscription = new SubjectSubscription(this, subscriber);
1209
+ }
1210
+ if (scheduler) {
1211
+ subscriber.add(subscriber = new ObserveOnSubscriber(subscriber, scheduler));
1212
+ }
1213
+ if (_infiniteTimeWindow) {
1214
+ for (let i = 0; i < len && !subscriber.closed; i++) {
1215
+ subscriber.next(_events[i]);
1216
+ }
1217
+ }
1218
+ else {
1219
+ for (let i = 0; i < len && !subscriber.closed; i++) {
1220
+ subscriber.next(_events[i].value);
1221
+ }
1222
+ }
1223
+ if (this.hasError) {
1224
+ subscriber.error(this.thrownError);
1225
+ }
1226
+ else if (this.isStopped) {
1227
+ subscriber.complete();
1228
+ }
1229
+ return subscription;
1230
+ }
1231
+ _getNow() {
1232
+ return (this.scheduler || queue).now();
1233
+ }
1234
+ _trimBufferThenGetEvents() {
1235
+ const now = this._getNow();
1236
+ const _bufferSize = this._bufferSize;
1237
+ const _windowTime = this._windowTime;
1238
+ const _events = this._events;
1239
+ const eventsCount = _events.length;
1240
+ let spliceCount = 0;
1241
+ while (spliceCount < eventsCount) {
1242
+ if ((now - _events[spliceCount].time) < _windowTime) {
1243
+ break;
1244
+ }
1245
+ spliceCount++;
1246
+ }
1247
+ if (eventsCount > _bufferSize) {
1248
+ spliceCount = Math.max(spliceCount, eventsCount - _bufferSize);
1249
+ }
1250
+ if (spliceCount > 0) {
1251
+ _events.splice(0, spliceCount);
1252
+ }
1253
+ return _events;
1254
+ }
1255
+ }
1256
+ class ReplayEvent {
1257
+ constructor(time, value) {
1258
+ this.time = time;
1259
+ this.value = value;
1260
+ }
1261
+ }
1262
+
1263
+ const asyncScheduler = new AsyncScheduler(AsyncAction);
1264
+ const async = asyncScheduler;
1265
+
1266
+ function isObservable(obj) {
1267
+ return !!obj && (obj instanceof Observable || (typeof obj.lift === 'function' && typeof obj.subscribe === 'function'));
1268
+ }
1269
+
1270
+ const ArgumentOutOfRangeErrorImpl = (() => {
1271
+ function ArgumentOutOfRangeErrorImpl() {
1272
+ Error.call(this);
1273
+ this.message = 'argument out of range';
1274
+ this.name = 'ArgumentOutOfRangeError';
1275
+ return this;
1276
+ }
1277
+ ArgumentOutOfRangeErrorImpl.prototype = Object.create(Error.prototype);
1278
+ return ArgumentOutOfRangeErrorImpl;
1279
+ })();
1280
+ const ArgumentOutOfRangeError = ArgumentOutOfRangeErrorImpl;
1281
+
1282
+ function map(project, thisArg) {
1283
+ return function mapOperation(source) {
1284
+ if (typeof project !== 'function') {
1285
+ throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
1286
+ }
1287
+ return source.lift(new MapOperator(project, thisArg));
1288
+ };
1289
+ }
1290
+ class MapOperator {
1291
+ constructor(project, thisArg) {
1292
+ this.project = project;
1293
+ this.thisArg = thisArg;
1294
+ }
1295
+ call(subscriber, source) {
1296
+ return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));
1297
+ }
1298
+ }
1299
+ class MapSubscriber extends Subscriber {
1300
+ constructor(destination, project, thisArg) {
1301
+ super(destination);
1302
+ this.project = project;
1303
+ this.count = 0;
1304
+ this.thisArg = thisArg || this;
1305
+ }
1306
+ _next(value) {
1307
+ let result;
1308
+ try {
1309
+ result = this.project.call(this.thisArg, value, this.count++);
1310
+ }
1311
+ catch (err) {
1312
+ this.destination.error(err);
1313
+ return;
1314
+ }
1315
+ this.destination.next(result);
1316
+ }
1317
+ }
1318
+
1319
+ const subscribeToPromise = (promise) => (subscriber) => {
1320
+ promise.then((value) => {
1321
+ if (!subscriber.closed) {
1322
+ subscriber.next(value);
1323
+ subscriber.complete();
1324
+ }
1325
+ }, (err) => subscriber.error(err))
1326
+ .then(null, hostReportError);
1327
+ return subscriber;
1328
+ };
1329
+
1330
+ function getSymbolIterator() {
1331
+ if (typeof Symbol !== 'function' || !Symbol.iterator) {
1332
+ return '@@iterator';
1333
+ }
1334
+ return Symbol.iterator;
1335
+ }
1336
+ const iterator = getSymbolIterator();
1337
+
1338
+ const subscribeToIterable = (iterable) => (subscriber) => {
1339
+ const iterator$1 = iterable[iterator]();
1340
+ do {
1341
+ let item;
1342
+ try {
1343
+ item = iterator$1.next();
1344
+ }
1345
+ catch (err) {
1346
+ subscriber.error(err);
1347
+ return subscriber;
1348
+ }
1349
+ if (item.done) {
1350
+ subscriber.complete();
1351
+ break;
1352
+ }
1353
+ subscriber.next(item.value);
1354
+ if (subscriber.closed) {
1355
+ break;
1356
+ }
1357
+ } while (true);
1358
+ if (typeof iterator$1.return === 'function') {
1359
+ subscriber.add(() => {
1360
+ if (iterator$1.return) {
1361
+ iterator$1.return();
1362
+ }
1363
+ });
1364
+ }
1365
+ return subscriber;
1366
+ };
1367
+
1368
+ const subscribeToObservable = (obj) => (subscriber) => {
1369
+ const obs = obj[observable]();
1370
+ if (typeof obs.subscribe !== 'function') {
1371
+ throw new TypeError('Provided object does not correctly implement Symbol.observable');
1372
+ }
1373
+ else {
1374
+ return obs.subscribe(subscriber);
1375
+ }
1376
+ };
1377
+
1378
+ const isArrayLike = ((x) => x && typeof x.length === 'number' && typeof x !== 'function');
1379
+
1380
+ function isPromise(value) {
1381
+ return !!value && typeof value.subscribe !== 'function' && typeof value.then === 'function';
1382
+ }
1383
+
1384
+ const subscribeTo = (result) => {
1385
+ if (!!result && typeof result[observable] === 'function') {
1386
+ return subscribeToObservable(result);
1387
+ }
1388
+ else if (isArrayLike(result)) {
1389
+ return subscribeToArray(result);
1390
+ }
1391
+ else if (isPromise(result)) {
1392
+ return subscribeToPromise(result);
1393
+ }
1394
+ else if (!!result && typeof result[iterator] === 'function') {
1395
+ return subscribeToIterable(result);
1396
+ }
1397
+ else {
1398
+ const value = isObject(result) ? 'an invalid object' : `'${result}'`;
1399
+ const msg = `You provided ${value} where a stream was expected.`
1400
+ + ' You can provide an Observable, Promise, Array, or Iterable.';
1401
+ throw new TypeError(msg);
1402
+ }
1403
+ };
1404
+
1405
+ function scheduleObservable(input, scheduler) {
1406
+ return new Observable(subscriber => {
1407
+ const sub = new Subscription();
1408
+ sub.add(scheduler.schedule(() => {
1409
+ const observable$1 = input[observable]();
1410
+ sub.add(observable$1.subscribe({
1411
+ next(value) { sub.add(scheduler.schedule(() => subscriber.next(value))); },
1412
+ error(err) { sub.add(scheduler.schedule(() => subscriber.error(err))); },
1413
+ complete() { sub.add(scheduler.schedule(() => subscriber.complete())); },
1414
+ }));
1415
+ }));
1416
+ return sub;
1417
+ });
1418
+ }
1419
+
1420
+ function schedulePromise(input, scheduler) {
1421
+ return new Observable(subscriber => {
1422
+ const sub = new Subscription();
1423
+ sub.add(scheduler.schedule(() => input.then(value => {
1424
+ sub.add(scheduler.schedule(() => {
1425
+ subscriber.next(value);
1426
+ sub.add(scheduler.schedule(() => subscriber.complete()));
1427
+ }));
1428
+ }, err => {
1429
+ sub.add(scheduler.schedule(() => subscriber.error(err)));
1430
+ })));
1431
+ return sub;
1432
+ });
1433
+ }
1434
+
1435
+ function scheduleIterable(input, scheduler) {
1436
+ if (!input) {
1437
+ throw new Error('Iterable cannot be null');
1438
+ }
1439
+ return new Observable(subscriber => {
1440
+ const sub = new Subscription();
1441
+ let iterator$1;
1442
+ sub.add(() => {
1443
+ if (iterator$1 && typeof iterator$1.return === 'function') {
1444
+ iterator$1.return();
1445
+ }
1446
+ });
1447
+ sub.add(scheduler.schedule(() => {
1448
+ iterator$1 = input[iterator]();
1449
+ sub.add(scheduler.schedule(function () {
1450
+ if (subscriber.closed) {
1451
+ return;
1452
+ }
1453
+ let value;
1454
+ let done;
1455
+ try {
1456
+ const result = iterator$1.next();
1457
+ value = result.value;
1458
+ done = result.done;
1459
+ }
1460
+ catch (err) {
1461
+ subscriber.error(err);
1462
+ return;
1463
+ }
1464
+ if (done) {
1465
+ subscriber.complete();
1466
+ }
1467
+ else {
1468
+ subscriber.next(value);
1469
+ this.schedule();
1470
+ }
1471
+ }));
1472
+ }));
1473
+ return sub;
1474
+ });
1475
+ }
1476
+
1477
+ function isInteropObservable(input) {
1478
+ return input && typeof input[observable] === 'function';
1479
+ }
1480
+
1481
+ function isIterable(input) {
1482
+ return input && typeof input[iterator] === 'function';
1483
+ }
1484
+
1485
+ function scheduled(input, scheduler) {
1486
+ if (input != null) {
1487
+ if (isInteropObservable(input)) {
1488
+ return scheduleObservable(input, scheduler);
1489
+ }
1490
+ else if (isPromise(input)) {
1491
+ return schedulePromise(input, scheduler);
1492
+ }
1493
+ else if (isArrayLike(input)) {
1494
+ return scheduleArray(input, scheduler);
1495
+ }
1496
+ else if (isIterable(input) || typeof input === 'string') {
1497
+ return scheduleIterable(input, scheduler);
1498
+ }
1499
+ }
1500
+ throw new TypeError((input !== null && typeof input || input) + ' is not observable');
1501
+ }
1502
+
1503
+ function from(input, scheduler) {
1504
+ if (!scheduler) {
1505
+ if (input instanceof Observable) {
1506
+ return input;
1507
+ }
1508
+ return new Observable(subscribeTo(input));
1509
+ }
1510
+ else {
1511
+ return scheduled(input, scheduler);
1512
+ }
1513
+ }
1514
+
1515
+ class SimpleInnerSubscriber extends Subscriber {
1516
+ constructor(parent) {
1517
+ super();
1518
+ this.parent = parent;
1519
+ }
1520
+ _next(value) {
1521
+ this.parent.notifyNext(value);
1522
+ }
1523
+ _error(error) {
1524
+ this.parent.notifyError(error);
1525
+ this.unsubscribe();
1526
+ }
1527
+ _complete() {
1528
+ this.parent.notifyComplete();
1529
+ this.unsubscribe();
1530
+ }
1531
+ }
1532
+ class SimpleOuterSubscriber extends Subscriber {
1533
+ notifyNext(innerValue) {
1534
+ this.destination.next(innerValue);
1535
+ }
1536
+ notifyError(err) {
1537
+ this.destination.error(err);
1538
+ }
1539
+ notifyComplete() {
1540
+ this.destination.complete();
1541
+ }
1542
+ }
1543
+ function innerSubscribe(result, innerSubscriber) {
1544
+ if (innerSubscriber.closed) {
1545
+ return undefined;
1546
+ }
1547
+ if (result instanceof Observable) {
1548
+ return result.subscribe(innerSubscriber);
1549
+ }
1550
+ return subscribeTo(result)(innerSubscriber);
1551
+ }
1552
+
1553
+ function filter(predicate, thisArg) {
1554
+ return function filterOperatorFunction(source) {
1555
+ return source.lift(new FilterOperator(predicate, thisArg));
1556
+ };
1557
+ }
1558
+ class FilterOperator {
1559
+ constructor(predicate, thisArg) {
1560
+ this.predicate = predicate;
1561
+ this.thisArg = thisArg;
1562
+ }
1563
+ call(subscriber, source) {
1564
+ return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
1565
+ }
1566
+ }
1567
+ class FilterSubscriber extends Subscriber {
1568
+ constructor(destination, predicate, thisArg) {
1569
+ super(destination);
1570
+ this.predicate = predicate;
1571
+ this.thisArg = thisArg;
1572
+ this.count = 0;
1573
+ }
1574
+ _next(value) {
1575
+ let result;
1576
+ try {
1577
+ result = this.predicate.call(this.thisArg, value, this.count++);
1578
+ }
1579
+ catch (err) {
1580
+ this.destination.error(err);
1581
+ return;
1582
+ }
1583
+ if (result) {
1584
+ this.destination.next(value);
1585
+ }
1586
+ }
1587
+ }
1588
+
1589
+ function isDate(value) {
1590
+ return value instanceof Date && !isNaN(+value);
1591
+ }
1592
+
1593
+ function delay(delay, scheduler = async) {
1594
+ const absoluteDelay = isDate(delay);
1595
+ const delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay);
1596
+ return (source) => source.lift(new DelayOperator(delayFor, scheduler));
1597
+ }
1598
+ class DelayOperator {
1599
+ constructor(delay, scheduler) {
1600
+ this.delay = delay;
1601
+ this.scheduler = scheduler;
1602
+ }
1603
+ call(subscriber, source) {
1604
+ return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
1605
+ }
1606
+ }
1607
+ class DelaySubscriber extends Subscriber {
1608
+ constructor(destination, delay, scheduler) {
1609
+ super(destination);
1610
+ this.delay = delay;
1611
+ this.scheduler = scheduler;
1612
+ this.queue = [];
1613
+ this.active = false;
1614
+ this.errored = false;
1615
+ }
1616
+ static dispatch(state) {
1617
+ const source = state.source;
1618
+ const queue = source.queue;
1619
+ const scheduler = state.scheduler;
1620
+ const destination = state.destination;
1621
+ while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) {
1622
+ queue.shift().notification.observe(destination);
1623
+ }
1624
+ if (queue.length > 0) {
1625
+ const delay = Math.max(0, queue[0].time - scheduler.now());
1626
+ this.schedule(state, delay);
1627
+ }
1628
+ else {
1629
+ this.unsubscribe();
1630
+ source.active = false;
1631
+ }
1632
+ }
1633
+ _schedule(scheduler) {
1634
+ this.active = true;
1635
+ const destination = this.destination;
1636
+ destination.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
1637
+ source: this, destination: this.destination, scheduler: scheduler
1638
+ }));
1639
+ }
1640
+ scheduleNotification(notification) {
1641
+ if (this.errored === true) {
1642
+ return;
1643
+ }
1644
+ const scheduler = this.scheduler;
1645
+ const message = new DelayMessage(scheduler.now() + this.delay, notification);
1646
+ this.queue.push(message);
1647
+ if (this.active === false) {
1648
+ this._schedule(scheduler);
1649
+ }
1650
+ }
1651
+ _next(value) {
1652
+ this.scheduleNotification(Notification.createNext(value));
1653
+ }
1654
+ _error(err) {
1655
+ this.errored = true;
1656
+ this.queue = [];
1657
+ this.destination.error(err);
1658
+ this.unsubscribe();
1659
+ }
1660
+ _complete() {
1661
+ this.scheduleNotification(Notification.createComplete());
1662
+ this.unsubscribe();
1663
+ }
1664
+ }
1665
+ class DelayMessage {
1666
+ constructor(time, notification) {
1667
+ this.time = time;
1668
+ this.notification = notification;
1669
+ }
1670
+ }
1671
+
1672
+ function distinctUntilChanged(compare, keySelector) {
1673
+ return (source) => source.lift(new DistinctUntilChangedOperator(compare, keySelector));
1674
+ }
1675
+ class DistinctUntilChangedOperator {
1676
+ constructor(compare, keySelector) {
1677
+ this.compare = compare;
1678
+ this.keySelector = keySelector;
1679
+ }
1680
+ call(subscriber, source) {
1681
+ return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
1682
+ }
1683
+ }
1684
+ class DistinctUntilChangedSubscriber extends Subscriber {
1685
+ constructor(destination, compare, keySelector) {
1686
+ super(destination);
1687
+ this.keySelector = keySelector;
1688
+ this.hasKey = false;
1689
+ if (typeof compare === 'function') {
1690
+ this.compare = compare;
1691
+ }
1692
+ }
1693
+ compare(x, y) {
1694
+ return x === y;
1695
+ }
1696
+ _next(value) {
1697
+ let key;
1698
+ try {
1699
+ const { keySelector } = this;
1700
+ key = keySelector ? keySelector(value) : value;
1701
+ }
1702
+ catch (err) {
1703
+ return this.destination.error(err);
1704
+ }
1705
+ let result = false;
1706
+ if (this.hasKey) {
1707
+ try {
1708
+ const { compare } = this;
1709
+ result = compare(this.key, key);
1710
+ }
1711
+ catch (err) {
1712
+ return this.destination.error(err);
1713
+ }
1714
+ }
1715
+ else {
1716
+ this.hasKey = true;
1717
+ }
1718
+ if (!result) {
1719
+ this.key = key;
1720
+ this.destination.next(value);
1721
+ }
1722
+ }
1723
+ }
1724
+
1725
+ function take(count) {
1726
+ return (source) => {
1727
+ if (count === 0) {
1728
+ return empty$1();
1729
+ }
1730
+ else {
1731
+ return source.lift(new TakeOperator(count));
1732
+ }
1733
+ };
1734
+ }
1735
+ class TakeOperator {
1736
+ constructor(total) {
1737
+ this.total = total;
1738
+ if (this.total < 0) {
1739
+ throw new ArgumentOutOfRangeError;
1740
+ }
1741
+ }
1742
+ call(subscriber, source) {
1743
+ return source.subscribe(new TakeSubscriber(subscriber, this.total));
1744
+ }
1745
+ }
1746
+ class TakeSubscriber extends Subscriber {
1747
+ constructor(destination, total) {
1748
+ super(destination);
1749
+ this.total = total;
1750
+ this.count = 0;
1751
+ }
1752
+ _next(value) {
1753
+ const total = this.total;
1754
+ const count = ++this.count;
1755
+ if (count <= total) {
1756
+ this.destination.next(value);
1757
+ if (count === total) {
1758
+ this.destination.complete();
1759
+ this.unsubscribe();
1760
+ }
1761
+ }
1762
+ }
1763
+ }
1764
+
1765
+ function switchMap(project, resultSelector) {
1766
+ if (typeof resultSelector === 'function') {
1767
+ return (source) => source.pipe(switchMap((a, i) => from(project(a, i)).pipe(map((b, ii) => resultSelector(a, b, i, ii)))));
1768
+ }
1769
+ return (source) => source.lift(new SwitchMapOperator(project));
1770
+ }
1771
+ class SwitchMapOperator {
1772
+ constructor(project) {
1773
+ this.project = project;
1774
+ }
1775
+ call(subscriber, source) {
1776
+ return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
1777
+ }
1778
+ }
1779
+ class SwitchMapSubscriber extends SimpleOuterSubscriber {
1780
+ constructor(destination, project) {
1781
+ super(destination);
1782
+ this.project = project;
1783
+ this.index = 0;
1784
+ }
1785
+ _next(value) {
1786
+ let result;
1787
+ const index = this.index++;
1788
+ try {
1789
+ result = this.project(value, index);
1790
+ }
1791
+ catch (error) {
1792
+ this.destination.error(error);
1793
+ return;
1794
+ }
1795
+ this._innerSub(result);
1796
+ }
1797
+ _innerSub(result) {
1798
+ const innerSubscription = this.innerSubscription;
1799
+ if (innerSubscription) {
1800
+ innerSubscription.unsubscribe();
1801
+ }
1802
+ const innerSubscriber = new SimpleInnerSubscriber(this);
1803
+ const destination = this.destination;
1804
+ destination.add(innerSubscriber);
1805
+ this.innerSubscription = innerSubscribe(result, innerSubscriber);
1806
+ if (this.innerSubscription !== innerSubscriber) {
1807
+ destination.add(this.innerSubscription);
1808
+ }
1809
+ }
1810
+ _complete() {
1811
+ const { innerSubscription } = this;
1812
+ if (!innerSubscription || innerSubscription.closed) {
1813
+ super._complete();
1814
+ }
1815
+ this.unsubscribe();
1816
+ }
1817
+ _unsubscribe() {
1818
+ this.innerSubscription = undefined;
1819
+ }
1820
+ notifyComplete() {
1821
+ this.innerSubscription = undefined;
1822
+ if (this.isStopped) {
1823
+ super._complete();
1824
+ }
1825
+ }
1826
+ notifyNext(innerValue) {
1827
+ this.destination.next(innerValue);
1828
+ }
1829
+ }
1830
+
1831
+ const currentAction = {
1832
+ type: null,
1833
+ entityIds: null,
1834
+ skip: false,
1835
+ };
1836
+ let customActionActive = false;
1837
+ function resetCustomAction() {
1838
+ customActionActive = false;
1839
+ }
1840
+ // public API for custom actions. Custom action always wins
1841
+ function logAction(type, entityIds) {
1842
+ setAction(type, entityIds);
1843
+ customActionActive = true;
1844
+ }
1845
+ function setAction(type, entityIds) {
1846
+ if (customActionActive === false) {
1847
+ currentAction.type = type;
1848
+ currentAction.entityIds = entityIds;
1849
+ }
1850
+ }
1851
+ function action(action, entityIds) {
1852
+ return function (target, propertyKey, descriptor) {
1853
+ const originalMethod = descriptor.value;
1854
+ descriptor.value = function (...args) {
1855
+ logAction(action, entityIds);
1856
+ return originalMethod.apply(this, args);
1857
+ };
1858
+ return descriptor;
1859
+ };
1860
+ }
1861
+
1862
+ // @internal
1863
+ function hasEntity(entities, id) {
1864
+ return entities.hasOwnProperty(id);
1865
+ }
1866
+
1867
+ // @internal
1868
+ function addEntities({ state, entities, idKey, options = {}, preAddEntity }) {
1869
+ let newEntities = {};
1870
+ let newIds = [];
1871
+ let hasNewEntities = false;
1872
+ for (const entity of entities) {
1873
+ if (hasEntity(state.entities, entity[idKey]) === false) {
1874
+ // evaluate the middleware first to support dynamic ids
1875
+ const current = preAddEntity(entity);
1876
+ const entityId = current[idKey];
1877
+ newEntities[entityId] = current;
1878
+ if (options.prepend)
1879
+ newIds.unshift(entityId);
1880
+ else
1881
+ newIds.push(entityId);
1882
+ hasNewEntities = true;
1883
+ }
1884
+ }
1885
+ return hasNewEntities
1886
+ ? {
1887
+ newState: Object.assign({}, state, { entities: Object.assign({}, state.entities, newEntities), ids: options.prepend ? [...newIds, ...state.ids] : [...state.ids, ...newIds] }),
1888
+ newIds
1889
+ }
1890
+ : null;
1891
+ }
1892
+
1893
+ // @internal
1894
+ function isNil(v) {
1895
+ return v === null || v === undefined;
1896
+ }
1897
+
1898
+ // @internal
1899
+ function coerceArray(value) {
1900
+ if (isNil(value)) {
1901
+ return [];
1902
+ }
1903
+ return Array.isArray(value) ? value : [value];
1904
+ }
1905
+
1906
+ const DEFAULT_ID_KEY = 'id';
1907
+
1908
+ var EntityActions;
1909
+ (function (EntityActions) {
1910
+ EntityActions["Set"] = "Set";
1911
+ EntityActions["Add"] = "Add";
1912
+ EntityActions["Update"] = "Update";
1913
+ EntityActions["Remove"] = "Remove";
1914
+ })(EntityActions || (EntityActions = {}));
1915
+
1916
+ const isBrowser = typeof window !== 'undefined';
1917
+
1918
+ let __DEV__ = true;
1919
+ function enableAkitaProdMode() {
1920
+ __DEV__ = false;
1921
+ if (isBrowser) {
1922
+ delete window.$$stores;
1923
+ delete window.$$queries;
1924
+ }
1925
+ }
1926
+ // @internal
1927
+ function isDev() {
1928
+ return __DEV__;
1929
+ }
1930
+
1931
+ // @internal
1932
+ function isObject$1(value) {
1933
+ const type = typeof value;
1934
+ return value != null && (type == 'object' || type == 'function');
1935
+ }
1936
+
1937
+ // @internal
1938
+ function isArray$1(value) {
1939
+ return Array.isArray(value);
1940
+ }
1941
+
1942
+ // @internal
1943
+ function getActiveEntities(idOrOptions, ids, currentActive) {
1944
+ let result;
1945
+ if (isArray$1(idOrOptions)) {
1946
+ result = idOrOptions;
1947
+ }
1948
+ else {
1949
+ if (isObject$1(idOrOptions)) {
1950
+ if (isNil(currentActive))
1951
+ return;
1952
+ idOrOptions = Object.assign({ wrap: true }, idOrOptions);
1953
+ const currentIdIndex = ids.indexOf(currentActive);
1954
+ if (idOrOptions.prev) {
1955
+ const isFirst = currentIdIndex === 0;
1956
+ if (isFirst && !idOrOptions.wrap)
1957
+ return;
1958
+ result = isFirst ? ids[ids.length - 1] : ids[currentIdIndex - 1];
1959
+ }
1960
+ else if (idOrOptions.next) {
1961
+ const isLast = ids.length === currentIdIndex + 1;
1962
+ if (isLast && !idOrOptions.wrap)
1963
+ return;
1964
+ result = isLast ? ids[0] : ids[currentIdIndex + 1];
1965
+ }
1966
+ }
1967
+ else {
1968
+ if (idOrOptions === currentActive)
1969
+ return;
1970
+ result = idOrOptions;
1971
+ }
1972
+ }
1973
+ return result;
1974
+ }
1975
+
1976
+ // @internal
1977
+ const getInitialEntitiesState = () => ({
1978
+ entities: {},
1979
+ ids: [],
1980
+ loading: true,
1981
+ error: null
1982
+ });
1983
+
1984
+ // @internal
1985
+ function isDefined(val) {
1986
+ return isNil(val) === false;
1987
+ }
1988
+
1989
+ // @internal
1990
+ function isEmpty(arr) {
1991
+ if (isArray$1(arr)) {
1992
+ return arr.length === 0;
1993
+ }
1994
+ return false;
1995
+ }
1996
+
1997
+ // @internal
1998
+ function isFunction$1(value) {
1999
+ return typeof value === 'function';
2000
+ }
2001
+
2002
+ // @internal
2003
+ function isUndefined(value) {
2004
+ return value === undefined;
2005
+ }
2006
+
2007
+ // @internal
2008
+ function hasActiveState(state) {
2009
+ return state.hasOwnProperty('active');
2010
+ }
2011
+ // @internal
2012
+ function isMultiActiveState(active) {
2013
+ return isArray$1(active);
2014
+ }
2015
+ // @internal
2016
+ function resolveActiveEntity({ active, ids, entities }) {
2017
+ if (isMultiActiveState(active)) {
2018
+ return getExitingActives(active, ids);
2019
+ }
2020
+ if (hasEntity(entities, active) === false) {
2021
+ return null;
2022
+ }
2023
+ return active;
2024
+ }
2025
+ // @internal
2026
+ function getExitingActives(currentActivesIds, newIds) {
2027
+ const filtered = currentActivesIds.filter(id => newIds.indexOf(id) > -1);
2028
+ /** Return the same reference if nothing has changed */
2029
+ if (filtered.length === currentActivesIds.length) {
2030
+ return currentActivesIds;
2031
+ }
2032
+ return filtered;
2033
+ }
2034
+
2035
+ // @internal
2036
+ function removeEntities({ state, ids }) {
2037
+ if (isNil(ids))
2038
+ return removeAllEntities(state);
2039
+ const entities = state.entities;
2040
+ let newEntities = {};
2041
+ for (const id of state.ids) {
2042
+ if (ids.includes(id) === false) {
2043
+ newEntities[id] = entities[id];
2044
+ }
2045
+ }
2046
+ const newState = Object.assign({}, state, { entities: newEntities, ids: state.ids.filter(current => ids.includes(current) === false) });
2047
+ if (hasActiveState(state)) {
2048
+ newState.active = resolveActiveEntity(newState);
2049
+ }
2050
+ return newState;
2051
+ }
2052
+ // @internal
2053
+ function removeAllEntities(state) {
2054
+ return Object.assign({}, state, { entities: {}, ids: [], active: isMultiActiveState(state.active) ? [] : null });
2055
+ }
2056
+
2057
+ // @internal
2058
+ function toEntitiesObject(entities, idKey, preAddEntity) {
2059
+ const acc = {
2060
+ entities: {},
2061
+ ids: []
2062
+ };
2063
+ for (const entity of entities) {
2064
+ // evaluate the middleware first to support dynamic ids
2065
+ const current = preAddEntity(entity);
2066
+ acc.entities[current[idKey]] = current;
2067
+ acc.ids.push(current[idKey]);
2068
+ }
2069
+ return acc;
2070
+ }
2071
+
2072
+ // @internal
2073
+ function isEntityState(state) {
2074
+ return state.entities && state.ids;
2075
+ }
2076
+ // @internal
2077
+ function applyMiddleware(entities, preAddEntity) {
2078
+ let mapped = {};
2079
+ for (const id of Object.keys(entities)) {
2080
+ mapped[id] = preAddEntity(entities[id]);
2081
+ }
2082
+ return mapped;
2083
+ }
2084
+ // @internal
2085
+ function setEntities({ state, entities, idKey, preAddEntity, isNativePreAdd }) {
2086
+ let newEntities;
2087
+ let newIds;
2088
+ if (isArray$1(entities)) {
2089
+ const resolve = toEntitiesObject(entities, idKey, preAddEntity);
2090
+ newEntities = resolve.entities;
2091
+ newIds = resolve.ids;
2092
+ }
2093
+ else if (isEntityState(entities)) {
2094
+ newEntities = isNativePreAdd ? entities.entities : applyMiddleware(entities.entities, preAddEntity);
2095
+ newIds = entities.ids;
2096
+ }
2097
+ else {
2098
+ // it's an object
2099
+ newEntities = isNativePreAdd ? entities : applyMiddleware(entities, preAddEntity);
2100
+ newIds = Object.keys(newEntities).map(id => (isNaN(id) ? id : Number(id)));
2101
+ }
2102
+ const newState = Object.assign({}, state, { entities: newEntities, ids: newIds, loading: false });
2103
+ if (hasActiveState(state)) {
2104
+ newState.active = resolveActiveEntity(newState);
2105
+ }
2106
+ return newState;
2107
+ }
2108
+
2109
+ let CONFIG = {
2110
+ resettable: false,
2111
+ ttl: null,
2112
+ producerFn: undefined
2113
+ };
2114
+ // @internal
2115
+ function getAkitaConfig() {
2116
+ return CONFIG;
2117
+ }
2118
+ function getGlobalProducerFn() {
2119
+ return CONFIG.producerFn;
2120
+ }
2121
+
2122
+ // @internal
2123
+ function deepFreeze(o) {
2124
+ Object.freeze(o);
2125
+ const oIsFunction = typeof o === 'function';
2126
+ const hasOwnProp = Object.prototype.hasOwnProperty;
2127
+ Object.getOwnPropertyNames(o).forEach(function (prop) {
2128
+ if (hasOwnProp.call(o, prop) &&
2129
+ (oIsFunction ? prop !== 'caller' && prop !== 'callee' && prop !== 'arguments' : true) &&
2130
+ o[prop] !== null &&
2131
+ (typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
2132
+ !Object.isFrozen(o[prop])) {
2133
+ deepFreeze(o[prop]);
2134
+ }
2135
+ });
2136
+ return o;
2137
+ }
2138
+
2139
+ // @internal
2140
+ const $$deleteStore = new Subject();
2141
+ // @internal
2142
+ const $$addStore = new ReplaySubject(50, 5000);
2143
+ // @internal
2144
+ const $$updateStore = new Subject();
2145
+ // @internal
2146
+ function dispatchDeleted(storeName) {
2147
+ $$deleteStore.next(storeName);
2148
+ }
2149
+ // @internal
2150
+ function dispatchAdded(storeName) {
2151
+ $$addStore.next(storeName);
2152
+ }
2153
+ // @internal
2154
+ function dispatchUpdate(storeName, action) {
2155
+ $$updateStore.next({ storeName, action });
2156
+ }
2157
+ // @internal
2158
+ function assertStoreHasName(name, className) {
2159
+ if (!name) {
2160
+ console.error(`@StoreConfig({ name }) is missing in ${className}`);
2161
+ }
2162
+ }
2163
+
2164
+ // @internal
2165
+ function toBoolean(value) {
2166
+ return value != null && `${value}` !== 'false';
2167
+ }
2168
+
2169
+ // @internal
2170
+ function isPlainObject(value) {
2171
+ return toBoolean(value) && value.constructor.name === 'Object';
2172
+ }
2173
+
2174
+ const configKey = 'akitaConfig';
2175
+ function StoreConfig(metadata) {
2176
+ return function (constructor) {
2177
+ constructor[configKey] = { idKey: 'id' };
2178
+ for (let i = 0, keys = Object.keys(metadata); i < keys.length; i++) {
2179
+ const key = keys[i];
2180
+ /* name is preserved read only key */
2181
+ if (key === 'name') {
2182
+ constructor[configKey]['storeName'] = metadata[key];
2183
+ }
2184
+ else {
2185
+ constructor[configKey][key] = metadata[key];
2186
+ }
2187
+ }
2188
+ };
2189
+ }
2190
+
2191
+ // @internal
2192
+ const __stores__ = {};
2193
+ // @internal
2194
+ const __queries__ = {};
2195
+ if (isBrowser) {
2196
+ window.$$stores = __stores__;
2197
+ window.$$queries = __queries__;
2198
+ }
2199
+
2200
+ // @internal
2201
+ const transactionFinished = new Subject();
2202
+ // @internal
2203
+ const transactionInProcess = new BehaviorSubject(false);
2204
+ // @internal
2205
+ const transactionManager = {
2206
+ activeTransactions: 0,
2207
+ batchTransaction: null
2208
+ };
2209
+ // @internal
2210
+ function startBatch() {
2211
+ if (!isTransactionInProcess()) {
2212
+ transactionManager.batchTransaction = new Subject();
2213
+ }
2214
+ transactionManager.activeTransactions++;
2215
+ transactionInProcess.next(true);
2216
+ }
2217
+ // @internal
2218
+ function endBatch() {
2219
+ if (--transactionManager.activeTransactions === 0) {
2220
+ transactionManager.batchTransaction.next(true);
2221
+ transactionManager.batchTransaction.complete();
2222
+ transactionInProcess.next(false);
2223
+ transactionFinished.next(true);
2224
+ }
2225
+ }
2226
+ // @internal
2227
+ function isTransactionInProcess() {
2228
+ return transactionManager.activeTransactions > 0;
2229
+ }
2230
+ // @internal
2231
+ function commit() {
2232
+ return transactionManager.batchTransaction ? transactionManager.batchTransaction.asObservable() : of(true);
2233
+ }
2234
+ /**
2235
+ * A logical transaction.
2236
+ * Use this transaction to optimize the dispatch of all the stores.
2237
+ * The following code will update the store, BUT emits only once
2238
+ *
2239
+ * @example
2240
+ * applyTransaction(() => {
2241
+ * this.todosStore.add(new Todo(1, title));
2242
+ * this.todosStore.add(new Todo(2, title));
2243
+ * });
2244
+ *
2245
+ */
2246
+ function applyTransaction(action, thisArg = undefined) {
2247
+ startBatch();
2248
+ try {
2249
+ return action.apply(thisArg);
2250
+ }
2251
+ finally {
2252
+ logAction('@Transaction');
2253
+ endBatch();
2254
+ }
2255
+ }
2256
+ /**
2257
+ * A logical transaction.
2258
+ * Use this transaction to optimize the dispatch of all the stores.
2259
+ *
2260
+ * The following code will update the store, BUT emits only once.
2261
+ *
2262
+ * @example
2263
+ * @transaction
2264
+ * addTodos() {
2265
+ * this.todosStore.add(new Todo(1, title));
2266
+ * this.todosStore.add(new Todo(2, title));
2267
+ * }
2268
+ *
2269
+ *
2270
+ */
2271
+ function transaction() {
2272
+ return function (target, propertyKey, descriptor) {
2273
+ const originalMethod = descriptor.value;
2274
+ descriptor.value = function (...args) {
2275
+ return applyTransaction(() => {
2276
+ return originalMethod.apply(this, args);
2277
+ }, this);
2278
+ };
2279
+ return descriptor;
2280
+ };
2281
+ }
2282
+
2283
+ /**
2284
+ *
2285
+ * Store for managing any type of data
2286
+ *
2287
+ * @example
2288
+ *
2289
+ * export interface SessionState {
2290
+ * token: string;
2291
+ * userDetails: UserDetails
2292
+ * }
2293
+ *
2294
+ * export function createInitialState(): SessionState {
2295
+ * return {
2296
+ * token: '',
2297
+ * userDetails: null
2298
+ * };
2299
+ * }
2300
+ *
2301
+ * @StoreConfig({ name: 'session' })
2302
+ * export class SessionStore extends Store<SessionState> {
2303
+ * constructor() {
2304
+ * super(createInitialState());
2305
+ * }
2306
+ * }
2307
+ */
2308
+ class Store {
2309
+ constructor(initialState, options = {}) {
2310
+ this.options = options;
2311
+ this.inTransaction = false;
2312
+ this.cache = {
2313
+ active: new BehaviorSubject(false),
2314
+ ttl: null,
2315
+ };
2316
+ this.onInit(initialState);
2317
+ }
2318
+ /**
2319
+ * Set the loading state
2320
+ *
2321
+ * @example
2322
+ *
2323
+ * store.setLoading(true)
2324
+ *
2325
+ */
2326
+ setLoading(loading = false) {
2327
+ if (loading !== this._value().loading) {
2328
+ isDev() && setAction('Set Loading');
2329
+ this._setState((state) => (Object.assign({}, state, { loading })));
2330
+ }
2331
+ }
2332
+ /**
2333
+ *
2334
+ * Set whether the data is cached
2335
+ *
2336
+ * @example
2337
+ *
2338
+ * store.setHasCache(true)
2339
+ * store.setHasCache(false)
2340
+ * store.setHasCache(true, { restartTTL: true })
2341
+ *
2342
+ */
2343
+ setHasCache(hasCache, options = { restartTTL: false }) {
2344
+ if (hasCache !== this.cache.active.value) {
2345
+ this.cache.active.next(hasCache);
2346
+ }
2347
+ if (options.restartTTL) {
2348
+ const ttlConfig = this.getCacheTTL();
2349
+ if (ttlConfig) {
2350
+ if (this.cache.ttl !== null) {
2351
+ clearTimeout(this.cache.ttl);
2352
+ }
2353
+ this.cache.ttl = setTimeout(() => this.setHasCache(false), ttlConfig);
2354
+ }
2355
+ }
2356
+ }
2357
+ /**
2358
+ *
2359
+ * Sometimes we need to access the store value from a store
2360
+ *
2361
+ * @example middleware
2362
+ *
2363
+ */
2364
+ getValue() {
2365
+ return this.storeValue;
2366
+ }
2367
+ /**
2368
+ * Set the error state
2369
+ *
2370
+ * @example
2371
+ *
2372
+ * store.setError({text: 'unable to load data' })
2373
+ *
2374
+ */
2375
+ setError(error) {
2376
+ if (error !== this._value().error) {
2377
+ isDev() && setAction('Set Error');
2378
+ this._setState((state) => (Object.assign({}, state, { error })));
2379
+ }
2380
+ }
2381
+ // @internal
2382
+ _select(project) {
2383
+ return this.store.asObservable().pipe(map((snapshot) => project(snapshot.state)), distinctUntilChanged());
2384
+ }
2385
+ // @internal
2386
+ _value() {
2387
+ return this.storeValue;
2388
+ }
2389
+ // @internal
2390
+ _cache() {
2391
+ return this.cache.active;
2392
+ }
2393
+ // @internal
2394
+ get config() {
2395
+ return this.constructor[configKey] || {};
2396
+ }
2397
+ // @internal
2398
+ get storeName() {
2399
+ return this.config.storeName || this.options.storeName || this.options.name;
2400
+ }
2401
+ // @internal
2402
+ get deepFreeze() {
2403
+ return this.config.deepFreezeFn || this.options.deepFreezeFn || deepFreeze;
2404
+ }
2405
+ // @internal
2406
+ get cacheConfig() {
2407
+ return this.config.cache || this.options.cache;
2408
+ }
2409
+ get _producerFn() {
2410
+ return this.config.producerFn || this.options.producerFn || getGlobalProducerFn();
2411
+ }
2412
+ // @internal
2413
+ get resettable() {
2414
+ return isDefined(this.config.resettable) ? this.config.resettable : this.options.resettable;
2415
+ }
2416
+ // @internal
2417
+ _setState(newState, _dispatchAction = true) {
2418
+ if (isFunction$1(newState)) {
2419
+ const _newState = newState(this._value());
2420
+ this.storeValue = __DEV__ ? this.deepFreeze(_newState) : _newState;
2421
+ }
2422
+ else {
2423
+ this.storeValue = newState;
2424
+ }
2425
+ if (!this.store) {
2426
+ this.store = new BehaviorSubject({ state: this.storeValue });
2427
+ if (isDev()) {
2428
+ this.store.subscribe(({ action }) => {
2429
+ if (action) {
2430
+ dispatchUpdate(this.storeName, action);
2431
+ }
2432
+ });
2433
+ }
2434
+ return;
2435
+ }
2436
+ if (isTransactionInProcess()) {
2437
+ this.handleTransaction();
2438
+ return;
2439
+ }
2440
+ this.dispatch(this.storeValue, _dispatchAction);
2441
+ }
2442
+ /**
2443
+ *
2444
+ * Reset the current store back to the initial value
2445
+ *
2446
+ * @example
2447
+ *
2448
+ * store.reset()
2449
+ *
2450
+ */
2451
+ reset() {
2452
+ if (this.isResettable()) {
2453
+ isDev() && setAction('Reset');
2454
+ this._setState(() => Object.assign({}, this._initialState));
2455
+ this.setHasCache(false);
2456
+ }
2457
+ else {
2458
+ isDev() && console.warn(`You need to enable the reset functionality`);
2459
+ }
2460
+ }
2461
+ update(stateOrCallback) {
2462
+ isDev() && setAction('Update');
2463
+ let newState;
2464
+ const currentState = this._value();
2465
+ if (isFunction$1(stateOrCallback)) {
2466
+ newState = isFunction$1(this._producerFn) ? this._producerFn(currentState, stateOrCallback) : stateOrCallback(currentState);
2467
+ }
2468
+ else {
2469
+ newState = stateOrCallback;
2470
+ }
2471
+ const withHook = this.akitaPreUpdate(currentState, Object.assign({}, currentState, newState));
2472
+ const resolved = isPlainObject(currentState) ? withHook : new currentState.constructor(withHook);
2473
+ this._setState(resolved);
2474
+ }
2475
+ updateStoreConfig(newOptions) {
2476
+ this.options = Object.assign({}, this.options, newOptions);
2477
+ }
2478
+ // @internal
2479
+ akitaPreUpdate(_, nextState) {
2480
+ return nextState;
2481
+ }
2482
+ ngOnDestroy() {
2483
+ this.destroy();
2484
+ }
2485
+ /**
2486
+ *
2487
+ * Destroy the store
2488
+ *
2489
+ * @example
2490
+ *
2491
+ * store.destroy()
2492
+ *
2493
+ */
2494
+ destroy() {
2495
+ const hmrEnabled = isBrowser ? window.hmrEnabled : false;
2496
+ if (!hmrEnabled && this === __stores__[this.storeName]) {
2497
+ delete __stores__[this.storeName];
2498
+ dispatchDeleted(this.storeName);
2499
+ this.setHasCache(false);
2500
+ this.cache.active.complete();
2501
+ this.store.complete();
2502
+ }
2503
+ }
2504
+ onInit(initialState) {
2505
+ __stores__[this.storeName] = this;
2506
+ this._setState(() => initialState);
2507
+ dispatchAdded(this.storeName);
2508
+ if (this.isResettable()) {
2509
+ this._initialState = initialState;
2510
+ }
2511
+ isDev() && assertStoreHasName(this.storeName, this.constructor.name);
2512
+ }
2513
+ dispatch(state, _dispatchAction = true) {
2514
+ let action = undefined;
2515
+ if (_dispatchAction) {
2516
+ action = currentAction;
2517
+ resetCustomAction();
2518
+ }
2519
+ this.store.next({ state, action });
2520
+ }
2521
+ watchTransaction() {
2522
+ commit().subscribe(() => {
2523
+ this.inTransaction = false;
2524
+ this.dispatch(this._value());
2525
+ });
2526
+ }
2527
+ isResettable() {
2528
+ if (this.resettable === false) {
2529
+ return false;
2530
+ }
2531
+ return this.resettable || getAkitaConfig().resettable;
2532
+ }
2533
+ handleTransaction() {
2534
+ if (!this.inTransaction) {
2535
+ this.watchTransaction();
2536
+ this.inTransaction = true;
2537
+ }
2538
+ }
2539
+ getCacheTTL() {
2540
+ return (this.cacheConfig && this.cacheConfig.ttl) || getAkitaConfig().ttl;
2541
+ }
2542
+ }
2543
+
2544
+ // @internal
2545
+ function updateEntities({ state, ids, idKey, newStateOrFn, preUpdateEntity, producerFn, onEntityIdChanges }) {
2546
+ const updatedEntities = {};
2547
+ let isUpdatingIdKey = false;
2548
+ let idToUpdate;
2549
+ for (const id of ids) {
2550
+ // if the entity doesn't exist don't do anything
2551
+ if (hasEntity(state.entities, id) === false) {
2552
+ continue;
2553
+ }
2554
+ const oldEntity = state.entities[id];
2555
+ let newState;
2556
+ if (isFunction$1(newStateOrFn)) {
2557
+ newState = isFunction$1(producerFn) ? producerFn(oldEntity, newStateOrFn) : newStateOrFn(oldEntity);
2558
+ }
2559
+ else {
2560
+ newState = newStateOrFn;
2561
+ }
2562
+ const isIdChanged = newState.hasOwnProperty(idKey) && newState[idKey] !== oldEntity[idKey];
2563
+ let newEntity;
2564
+ idToUpdate = id;
2565
+ if (isIdChanged) {
2566
+ isUpdatingIdKey = true;
2567
+ idToUpdate = newState[idKey];
2568
+ }
2569
+ const merged = Object.assign({}, oldEntity, newState);
2570
+ if (isPlainObject(oldEntity)) {
2571
+ newEntity = merged;
2572
+ }
2573
+ else {
2574
+ /**
2575
+ * In case that new state is class of it's own, there's
2576
+ * a possibility that it will be different than the old
2577
+ * class.
2578
+ * For example, Old state is an instance of animal class
2579
+ * and new state is instance of person class.
2580
+ * To avoid run over new person class with the old animal
2581
+ * class we check if the new state is a class of it's own.
2582
+ * If so, use it. Otherwise, use the old state class
2583
+ */
2584
+ if (isPlainObject(newState)) {
2585
+ newEntity = new oldEntity.constructor(merged);
2586
+ }
2587
+ else {
2588
+ newEntity = new newState.constructor(merged);
2589
+ }
2590
+ }
2591
+ updatedEntities[idToUpdate] = preUpdateEntity(oldEntity, newEntity);
2592
+ }
2593
+ let updatedIds = state.ids;
2594
+ let stateEntities = state.entities;
2595
+ if (isUpdatingIdKey) {
2596
+ const [id] = ids;
2597
+ const _a = state.entities, _b = id, rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
2598
+ stateEntities = rest;
2599
+ updatedIds = state.ids.map((current) => (current === id ? idToUpdate : current));
2600
+ onEntityIdChanges(id, idToUpdate);
2601
+ }
2602
+ return Object.assign({}, state, { entities: Object.assign({}, stateEntities, updatedEntities), ids: updatedIds });
2603
+ }
2604
+
2605
+ var _b;
2606
+ /**
2607
+ *
2608
+ * Store for managing a collection of entities
2609
+ *
2610
+ * @example
2611
+ *
2612
+ * export interface WidgetsState extends EntityState<Widget> { }
2613
+ *
2614
+ * @StoreConfig({ name: 'widgets' })
2615
+ * export class WidgetsStore extends EntityStore<WidgetsState> {
2616
+ * constructor() {
2617
+ * super();
2618
+ * }
2619
+ * }
2620
+ *
2621
+ *
2622
+ */
2623
+ class EntityStore extends Store {
2624
+ constructor(initialState = {}, options = {}) {
2625
+ super(Object.assign({}, getInitialEntitiesState(), initialState), options);
2626
+ this.options = options;
2627
+ this.entityActions = new Subject();
2628
+ this.entityIdChanges = new Subject();
2629
+ }
2630
+ // @internal
2631
+ get selectEntityAction$() {
2632
+ return this.entityActions.asObservable();
2633
+ }
2634
+ // @internal
2635
+ get selectEntityIdChanges$() {
2636
+ return this.entityIdChanges.asObservable();
2637
+ }
2638
+ // @internal
2639
+ get idKey() {
2640
+ return this.config.idKey || this.options.idKey || DEFAULT_ID_KEY;
2641
+ }
2642
+ /**
2643
+ *
2644
+ * Replace current collection with provided collection
2645
+ *
2646
+ * @example
2647
+ *
2648
+ * this.store.set([Entity, Entity])
2649
+ * this.store.set({ids: [], entities: {}})
2650
+ * this.store.set({ 1: {}, 2: {}})
2651
+ *
2652
+ */
2653
+ set(entities, options = {}) {
2654
+ if (isNil(entities))
2655
+ return;
2656
+ isDev() && setAction('Set Entity');
2657
+ const isNativePreAdd = this.akitaPreAddEntity === EntityStore.prototype.akitaPreAddEntity;
2658
+ this.setHasCache(true, { restartTTL: true });
2659
+ this._setState((state) => {
2660
+ const newState = setEntities({
2661
+ state,
2662
+ entities,
2663
+ idKey: this.idKey,
2664
+ preAddEntity: this.akitaPreAddEntity,
2665
+ isNativePreAdd,
2666
+ });
2667
+ if (isUndefined(options.activeId) === false) {
2668
+ newState.active = options.activeId;
2669
+ }
2670
+ return newState;
2671
+ });
2672
+ if (this.hasInitialUIState()) {
2673
+ this.handleUICreation();
2674
+ }
2675
+ this.entityActions.next({ type: EntityActions.Set, ids: this.ids });
2676
+ }
2677
+ /**
2678
+ * Add entities
2679
+ *
2680
+ * @example
2681
+ *
2682
+ * this.store.add([Entity, Entity])
2683
+ * this.store.add(Entity)
2684
+ * this.store.add(Entity, { prepend: true })
2685
+ *
2686
+ * this.store.add(Entity, { loading: false })
2687
+ */
2688
+ add(entities, options = { loading: false }) {
2689
+ const collection = coerceArray(entities);
2690
+ if (isEmpty(collection))
2691
+ return;
2692
+ const data = addEntities({
2693
+ state: this._value(),
2694
+ preAddEntity: this.akitaPreAddEntity,
2695
+ entities: collection,
2696
+ idKey: this.idKey,
2697
+ options,
2698
+ });
2699
+ if (data) {
2700
+ isDev() && setAction('Add Entity');
2701
+ data.newState.loading = options.loading;
2702
+ this._setState(() => data.newState);
2703
+ if (this.hasInitialUIState()) {
2704
+ this.handleUICreation(true);
2705
+ }
2706
+ this.entityActions.next({ type: EntityActions.Add, ids: data.newIds });
2707
+ }
2708
+ }
2709
+ update(idsOrFnOrState, newStateOrFn) {
2710
+ if (isUndefined(newStateOrFn)) {
2711
+ super.update(idsOrFnOrState);
2712
+ return;
2713
+ }
2714
+ let ids = [];
2715
+ if (isFunction$1(idsOrFnOrState)) {
2716
+ // We need to filter according the predicate function
2717
+ ids = this.ids.filter((id) => idsOrFnOrState(this.entities[id]));
2718
+ }
2719
+ else {
2720
+ // If it's nil we want all of them
2721
+ ids = isNil(idsOrFnOrState) ? this.ids : coerceArray(idsOrFnOrState);
2722
+ }
2723
+ if (isEmpty(ids))
2724
+ return;
2725
+ isDev() && setAction('Update Entity', ids);
2726
+ let entityIdChanged;
2727
+ this._setState((state) => updateEntities({
2728
+ idKey: this.idKey,
2729
+ ids,
2730
+ preUpdateEntity: this.akitaPreUpdateEntity,
2731
+ state,
2732
+ newStateOrFn,
2733
+ producerFn: this._producerFn,
2734
+ onEntityIdChanges: (oldId, newId) => {
2735
+ entityIdChanged = { oldId, newId };
2736
+ this.entityIdChanges.next(Object.assign({}, entityIdChanged, { pending: true }));
2737
+ },
2738
+ }));
2739
+ if (entityIdChanged) {
2740
+ this.entityIdChanges.next(Object.assign({}, entityIdChanged, { pending: false }));
2741
+ }
2742
+ this.entityActions.next({ type: EntityActions.Update, ids });
2743
+ }
2744
+ upsert(ids, newState, onCreate, options = {}) {
2745
+ const toArray = coerceArray(ids);
2746
+ const predicate = (isUpdate) => (id) => hasEntity(this.entities, id) === isUpdate;
2747
+ const baseClass = isFunction$1(onCreate) ? options.baseClass : onCreate ? onCreate.baseClass : undefined;
2748
+ const isClassBased = isFunction$1(baseClass);
2749
+ const updateIds = toArray.filter(predicate(true));
2750
+ const newEntities = toArray.filter(predicate(false)).map((id) => {
2751
+ const newStateObj = typeof newState === 'function' ? newState({}) : newState;
2752
+ const entity = isFunction$1(onCreate) ? onCreate(id, newStateObj) : newStateObj;
2753
+ const withId = Object.assign({}, entity, { [this.idKey]: id });
2754
+ if (isClassBased) {
2755
+ return new baseClass(withId);
2756
+ }
2757
+ return withId;
2758
+ });
2759
+ // it can be any of the three types
2760
+ this.update(updateIds, newState);
2761
+ this.add(newEntities);
2762
+ isDev() && logAction('Upsert Entity');
2763
+ }
2764
+ /**
2765
+ *
2766
+ * Upsert entity collection (idKey must be present)
2767
+ *
2768
+ * @example
2769
+ *
2770
+ * store.upsertMany([ { id: 1 }, { id: 2 }]);
2771
+ *
2772
+ * store.upsertMany([ { id: 1 }, { id: 2 }], { loading: true });
2773
+ * store.upsertMany([ { id: 1 }, { id: 2 }], { baseClass: Todo });
2774
+ *
2775
+ */
2776
+ upsertMany(entities, options = {}) {
2777
+ const addedIds = [];
2778
+ const updatedIds = [];
2779
+ const updatedEntities = {};
2780
+ // Update the state directly to optimize performance
2781
+ for (const entity of entities) {
2782
+ const withPreCheckHook = this.akitaPreCheckEntity(entity);
2783
+ const id = withPreCheckHook[this.idKey];
2784
+ if (hasEntity(this.entities, id)) {
2785
+ const prev = this._value().entities[id];
2786
+ const merged = Object.assign({}, this._value().entities[id], withPreCheckHook);
2787
+ const next = options.baseClass ? new options.baseClass(merged) : merged;
2788
+ const withHook = this.akitaPreUpdateEntity(prev, next);
2789
+ const nextId = withHook[this.idKey];
2790
+ updatedEntities[nextId] = withHook;
2791
+ updatedIds.push(nextId);
2792
+ }
2793
+ else {
2794
+ const newEntity = options.baseClass ? new options.baseClass(withPreCheckHook) : withPreCheckHook;
2795
+ const withHook = this.akitaPreAddEntity(newEntity);
2796
+ const nextId = withHook[this.idKey];
2797
+ addedIds.push(nextId);
2798
+ updatedEntities[nextId] = withHook;
2799
+ }
2800
+ }
2801
+ isDev() && logAction('Upsert Many');
2802
+ this._setState((state) => (Object.assign({}, state, { ids: addedIds.length ? [...state.ids, ...addedIds] : state.ids, entities: Object.assign({}, state.entities, updatedEntities), loading: !!options.loading })));
2803
+ updatedIds.length && this.entityActions.next({ type: EntityActions.Update, ids: updatedIds });
2804
+ addedIds.length && this.entityActions.next({ type: EntityActions.Add, ids: addedIds });
2805
+ if (addedIds.length && this.hasUIStore()) {
2806
+ this.handleUICreation(true);
2807
+ }
2808
+ }
2809
+ /**
2810
+ *
2811
+ * Replace one or more entities (except the id property)
2812
+ *
2813
+ *
2814
+ * @example
2815
+ *
2816
+ * this.store.replace(5, newEntity)
2817
+ * this.store.replace([1,2,3], newEntity)
2818
+ */
2819
+ replace(ids, newState) {
2820
+ const toArray = coerceArray(ids);
2821
+ if (isEmpty(toArray))
2822
+ return;
2823
+ let replaced = {};
2824
+ for (const id of toArray) {
2825
+ newState[this.idKey] = id;
2826
+ replaced[id] = newState;
2827
+ }
2828
+ isDev() && setAction('Replace Entity', ids);
2829
+ this._setState((state) => (Object.assign({}, state, { entities: Object.assign({}, state.entities, replaced) })));
2830
+ }
2831
+ /**
2832
+ *
2833
+ * Move entity inside the collection
2834
+ *
2835
+ *
2836
+ * @example
2837
+ *
2838
+ * this.store.move(fromIndex, toIndex)
2839
+ */
2840
+ move(from, to) {
2841
+ const ids = this.ids.slice();
2842
+ ids.splice(to < 0 ? ids.length + to : to, 0, ids.splice(from, 1)[0]);
2843
+ isDev() && setAction('Move Entity');
2844
+ this._setState((state) => (Object.assign({}, state, {
2845
+ // Change the entities reference so that selectAll emit
2846
+ entities: Object.assign({}, state.entities), ids })));
2847
+ }
2848
+ remove(idsOrFn) {
2849
+ if (isEmpty(this.ids))
2850
+ return;
2851
+ const idPassed = isDefined(idsOrFn);
2852
+ // null means remove all
2853
+ let ids = [];
2854
+ if (isFunction$1(idsOrFn)) {
2855
+ ids = this.ids.filter((entityId) => idsOrFn(this.entities[entityId]));
2856
+ }
2857
+ else {
2858
+ ids = idPassed ? coerceArray(idsOrFn) : this.ids;
2859
+ }
2860
+ if (isEmpty(ids))
2861
+ return;
2862
+ isDev() && setAction('Remove Entity', ids);
2863
+ this._setState((state) => removeEntities({ state, ids }));
2864
+ if (!idPassed) {
2865
+ this.setHasCache(false);
2866
+ }
2867
+ this.handleUIRemove(ids);
2868
+ this.entityActions.next({ type: EntityActions.Remove, ids });
2869
+ }
2870
+ /**
2871
+ *
2872
+ * Update the active entity
2873
+ *
2874
+ * @example
2875
+ *
2876
+ * this.store.updateActive({ completed: true })
2877
+ * this.store.updateActive(active => {
2878
+ * return {
2879
+ * config: {
2880
+ * ..active.config,
2881
+ * date
2882
+ * }
2883
+ * }
2884
+ * })
2885
+ */
2886
+ updateActive(newStateOrCallback) {
2887
+ const ids = coerceArray(this.active);
2888
+ isDev() && setAction('Update Active', ids);
2889
+ this.update(ids, newStateOrCallback);
2890
+ }
2891
+ setActive(idOrOptions) {
2892
+ const active = getActiveEntities(idOrOptions, this.ids, this.active);
2893
+ if (active === undefined) {
2894
+ return;
2895
+ }
2896
+ isDev() && setAction('Set Active', active);
2897
+ this._setActive(active);
2898
+ }
2899
+ /**
2900
+ * Add active entities
2901
+ *
2902
+ * @example
2903
+ *
2904
+ * store.addActive(2);
2905
+ * store.addActive([3, 4, 5]);
2906
+ */
2907
+ addActive(ids) {
2908
+ const toArray = coerceArray(ids);
2909
+ if (isEmpty(toArray))
2910
+ return;
2911
+ const everyExist = toArray.every((id) => this.active.indexOf(id) > -1);
2912
+ if (everyExist)
2913
+ return;
2914
+ isDev() && setAction('Add Active', ids);
2915
+ this._setState((state) => {
2916
+ /** Protect against case that one of the items in the array exist */
2917
+ const uniques = Array.from(new Set([...state.active, ...toArray]));
2918
+ return Object.assign({}, state, { active: uniques });
2919
+ });
2920
+ }
2921
+ /**
2922
+ * Remove active entities
2923
+ *
2924
+ * @example
2925
+ *
2926
+ * store.removeActive(2)
2927
+ * store.removeActive([3, 4, 5])
2928
+ */
2929
+ removeActive(ids) {
2930
+ const toArray = coerceArray(ids);
2931
+ if (isEmpty(toArray))
2932
+ return;
2933
+ const someExist = toArray.some((id) => this.active.indexOf(id) > -1);
2934
+ if (!someExist)
2935
+ return;
2936
+ isDev() && setAction('Remove Active', ids);
2937
+ this._setState((state) => {
2938
+ return Object.assign({}, state, { active: Array.isArray(state.active) ? state.active.filter((currentId) => toArray.indexOf(currentId) === -1) : null });
2939
+ });
2940
+ }
2941
+ /**
2942
+ * Toggle active entities
2943
+ *
2944
+ * @example
2945
+ *
2946
+ * store.toggle(2)
2947
+ * store.toggle([3, 4, 5])
2948
+ */
2949
+ toggleActive(ids) {
2950
+ const toArray = coerceArray(ids);
2951
+ const filterExists = (remove) => (id) => this.active.includes(id) === remove;
2952
+ const remove = toArray.filter(filterExists(true));
2953
+ const add = toArray.filter(filterExists(false));
2954
+ this.removeActive(remove);
2955
+ this.addActive(add);
2956
+ isDev() && logAction('Toggle Active');
2957
+ }
2958
+ /**
2959
+ *
2960
+ * Create sub UI store for managing Entity's UI state
2961
+ *
2962
+ * @example
2963
+ *
2964
+ * export type ProductUI = {
2965
+ * isLoading: boolean;
2966
+ * isOpen: boolean
2967
+ * }
2968
+ *
2969
+ * interface ProductsUIState extends EntityState<ProductUI> {}
2970
+ *
2971
+ * export class ProductsStore EntityStore<ProductsState, Product> {
2972
+ * ui: EntityUIStore<ProductsUIState, ProductUI>;
2973
+ *
2974
+ * constructor() {
2975
+ * super();
2976
+ * this.createUIStore();
2977
+ * }
2978
+ *
2979
+ * }
2980
+ */
2981
+ createUIStore(initialState = {}, storeConfig = {}) {
2982
+ const defaults = { name: `UI/${this.storeName}`, idKey: this.idKey };
2983
+ this.ui = new EntityUIStore(initialState, Object.assign({}, defaults, storeConfig));
2984
+ return this.ui;
2985
+ }
2986
+ // @internal
2987
+ destroy() {
2988
+ super.destroy();
2989
+ if (this.ui instanceof EntityStore) {
2990
+ this.ui.destroy();
2991
+ }
2992
+ this.entityActions.complete();
2993
+ }
2994
+ // @internal
2995
+ akitaPreUpdateEntity(_, nextEntity) {
2996
+ return nextEntity;
2997
+ }
2998
+ // @internal
2999
+ akitaPreAddEntity(newEntity) {
3000
+ return newEntity;
3001
+ }
3002
+ // @internal
3003
+ akitaPreCheckEntity(newEntity) {
3004
+ return newEntity;
3005
+ }
3006
+ get ids() {
3007
+ return this._value().ids;
3008
+ }
3009
+ get entities() {
3010
+ return this._value().entities;
3011
+ }
3012
+ get active() {
3013
+ return this._value().active;
3014
+ }
3015
+ _setActive(ids) {
3016
+ this._setState((state) => {
3017
+ return Object.assign({}, state, { active: ids });
3018
+ });
3019
+ }
3020
+ handleUICreation(add = false) {
3021
+ const ids = this.ids;
3022
+ const isFunc = isFunction$1(this.ui._akitaCreateEntityFn);
3023
+ let uiEntities;
3024
+ const createFn = (id) => {
3025
+ const current = this.entities[id];
3026
+ const ui = isFunc ? this.ui._akitaCreateEntityFn(current) : this.ui._akitaCreateEntityFn;
3027
+ return Object.assign({ [this.idKey]: current[this.idKey] }, ui);
3028
+ };
3029
+ if (add) {
3030
+ uiEntities = this.ids.filter((id) => isUndefined(this.ui.entities[id])).map(createFn);
3031
+ }
3032
+ else {
3033
+ uiEntities = ids.map(createFn);
3034
+ }
3035
+ add ? this.ui.add(uiEntities) : this.ui.set(uiEntities);
3036
+ }
3037
+ hasInitialUIState() {
3038
+ return this.hasUIStore() && isUndefined(this.ui._akitaCreateEntityFn) === false;
3039
+ }
3040
+ handleUIRemove(ids) {
3041
+ if (this.hasUIStore()) {
3042
+ this.ui.remove(ids);
3043
+ }
3044
+ }
3045
+ hasUIStore() {
3046
+ return this.ui instanceof EntityUIStore;
3047
+ }
3048
+ }
3049
+ __decorate([
3050
+ transaction(),
3051
+ __metadata("design:type", Function),
3052
+ __metadata("design:paramtypes", [Object, Object, Object, Object]),
3053
+ __metadata("design:returntype", void 0)
3054
+ ], EntityStore.prototype, "upsert", null);
3055
+ __decorate([
3056
+ transaction(),
3057
+ __metadata("design:type", Function),
3058
+ __metadata("design:paramtypes", [typeof (_b = typeof T !== "undefined" && T) === "function" ? _b : Object]),
3059
+ __metadata("design:returntype", void 0)
3060
+ ], EntityStore.prototype, "toggleActive", null);
3061
+ // @internal
3062
+ class EntityUIStore extends EntityStore {
3063
+ constructor(initialState = {}, storeConfig = {}) {
3064
+ super(initialState, storeConfig);
3065
+ }
3066
+ /**
3067
+ *
3068
+ * Set the initial UI entity state. This function will determine the entity's
3069
+ * initial state when we call `set()` or `add()`.
3070
+ *
3071
+ * @example
3072
+ *
3073
+ * constructor() {
3074
+ * super();
3075
+ * this.createUIStore().setInitialEntityState(entity => ({ isLoading: false, isOpen: true }));
3076
+ * this.createUIStore().setInitialEntityState({ isLoading: false, isOpen: true });
3077
+ * }
3078
+ *
3079
+ */
3080
+ setInitialEntityState(createFn) {
3081
+ this._akitaCreateEntityFn = createFn;
3082
+ }
3083
+ }
3084
+
3085
+ var Order;
3086
+ (function (Order) {
3087
+ Order["ASC"] = "asc";
3088
+ Order["DESC"] = "desc";
3089
+ })(Order || (Order = {}));
3090
+
3091
+ // @internal
3092
+ function isString(value) {
3093
+ return typeof value === 'string';
3094
+ }
3095
+
3096
+ const queryConfigKey = 'akitaQueryConfig';
3097
+
3098
+ function compareKeys(keysOrFuncs) {
3099
+ return function (prevState, currState) {
3100
+ const isFns = isFunction$1(keysOrFuncs[0]);
3101
+ // Return when they are NOT changed
3102
+ return keysOrFuncs.some(keyOrFunc => {
3103
+ if (isFns) {
3104
+ return keyOrFunc(prevState) !== keyOrFunc(currState);
3105
+ }
3106
+ return prevState[keyOrFunc] !== currState[keyOrFunc];
3107
+ }) === false;
3108
+ };
3109
+ }
3110
+
3111
+ class Query {
3112
+ constructor(store) {
3113
+ this.store = store;
3114
+ this.__store__ = store;
3115
+ if (isDev()) {
3116
+ // @internal
3117
+ __queries__[store.storeName] = this;
3118
+ }
3119
+ }
3120
+ select(project) {
3121
+ let mapFn;
3122
+ if (isFunction$1(project)) {
3123
+ mapFn = project;
3124
+ }
3125
+ else if (isString(project)) {
3126
+ mapFn = state => state[project];
3127
+ }
3128
+ else if (Array.isArray(project)) {
3129
+ return this.store
3130
+ ._select(state => state)
3131
+ .pipe(distinctUntilChanged(compareKeys(project)), map(state => {
3132
+ if (isFunction$1(project[0])) {
3133
+ return project.map(func => func(state));
3134
+ }
3135
+ return project.reduce((acc, k) => {
3136
+ acc[k] = state[k];
3137
+ return acc;
3138
+ }, {});
3139
+ }));
3140
+ }
3141
+ else {
3142
+ mapFn = state => state;
3143
+ }
3144
+ return this.store._select(mapFn);
3145
+ }
3146
+ /**
3147
+ * Select the loading state
3148
+ *
3149
+ * @example
3150
+ *
3151
+ * this.query.selectLoading().subscribe(isLoading => {})
3152
+ */
3153
+ selectLoading() {
3154
+ return this.select(state => state.loading);
3155
+ }
3156
+ /**
3157
+ * Select the error state
3158
+ *
3159
+ * @example
3160
+ *
3161
+ * this.query.selectError().subscribe(error => {})
3162
+ */
3163
+ selectError() {
3164
+ return this.select(state => state.error);
3165
+ }
3166
+ /**
3167
+ * Get the store's value
3168
+ *
3169
+ * @example
3170
+ *
3171
+ * this.query.getValue()
3172
+ *
3173
+ */
3174
+ getValue() {
3175
+ return this.store._value();
3176
+ }
3177
+ /**
3178
+ * Select the cache state
3179
+ *
3180
+ * @example
3181
+ *
3182
+ * this.query.selectHasCache().pipe(
3183
+ * switchMap(hasCache => {
3184
+ * return hasCache ? of() : http().pipe(res => store.set(res))
3185
+ * })
3186
+ * )
3187
+ */
3188
+ selectHasCache() {
3189
+ return this.store._cache().asObservable();
3190
+ }
3191
+ /**
3192
+ * Whether we've cached data
3193
+ *
3194
+ * @example
3195
+ *
3196
+ * this.query.getHasCache()
3197
+ *
3198
+ */
3199
+ getHasCache() {
3200
+ return this.store._cache().value;
3201
+ }
3202
+ // @internal
3203
+ get config() {
3204
+ return this.constructor[queryConfigKey];
3205
+ }
3206
+ }
3207
+
3208
+ /**
3209
+ * @example
3210
+ *
3211
+ * query.selectEntity(2).pipe(filterNil)
3212
+ */
3213
+ const filterNil = (source) => source.pipe(filter((value) => value !== null && typeof value !== 'undefined'));
3214
+
3215
+ /**
3216
+ * @internal
3217
+ *
3218
+ * @example
3219
+ *
3220
+ * getValue(state, 'todos.ui')
3221
+ *
3222
+ */
3223
+ function getValue(obj, prop) {
3224
+ /** return the whole state */
3225
+ if (prop.split('.').length === 1) {
3226
+ return obj;
3227
+ }
3228
+ const removeStoreName = prop
3229
+ .split('.')
3230
+ .slice(1)
3231
+ .join('.');
3232
+ return removeStoreName.split('.').reduce((acc, part) => acc && acc[part], obj);
3233
+ }
3234
+
3235
+ /**
3236
+ * @internal
3237
+ *
3238
+ * @example
3239
+ * setValue(state, 'todos.ui', { filter: {} })
3240
+ */
3241
+ function setValue(obj, prop, val) {
3242
+ const split = prop.split('.');
3243
+ if (split.length === 1) {
3244
+ return Object.assign({}, obj, val);
3245
+ }
3246
+ obj = Object.assign({}, obj);
3247
+ const lastIndex = split.length - 2;
3248
+ const removeStoreName = prop.split('.').slice(1);
3249
+ removeStoreName.reduce((acc, part, index) => {
3250
+ if (index !== lastIndex) {
3251
+ acc[part] = Object.assign({}, acc[part]);
3252
+ return acc && acc[part];
3253
+ }
3254
+ acc[part] = Array.isArray(acc[part]) || !isObject$1(acc[part]) ? val : Object.assign({}, acc[part], val);
3255
+ return acc && acc[part];
3256
+ }, obj);
3257
+ return obj;
3258
+ }
3259
+ const _persistStateInit = new ReplaySubject(1);
3260
+
3261
+ class AkitaPlugin {
3262
+ constructor(query, config) {
3263
+ this.query = query;
3264
+ if (config && config.resetFn) {
3265
+ if (getAkitaConfig().resettable) {
3266
+ this.onReset(config.resetFn);
3267
+ }
3268
+ }
3269
+ }
3270
+ /** This method is responsible for getting access to the query. */
3271
+ getQuery() {
3272
+ return this.query;
3273
+ }
3274
+ /** This method is responsible for getting access to the store. */
3275
+ getStore() {
3276
+ return this.getQuery().__store__;
3277
+ }
3278
+ /** This method is responsible tells whether the plugin is entityBased or not. */
3279
+ isEntityBased(entityId) {
3280
+ return toBoolean(entityId);
3281
+ }
3282
+ /** This method is responsible for selecting the source; it can be the whole store or one entity. */
3283
+ selectSource(entityId, property) {
3284
+ if (this.isEntityBased(entityId)) {
3285
+ return this.getQuery().selectEntity(entityId).pipe(filterNil);
3286
+ }
3287
+ if (property) {
3288
+ return this.getQuery().select(state => getValue(state, this.withStoreName(property)));
3289
+ }
3290
+ return this.getQuery().select();
3291
+ }
3292
+ getSource(entityId, property) {
3293
+ if (this.isEntityBased(entityId)) {
3294
+ return this.getQuery().getEntity(entityId);
3295
+ }
3296
+ const state = this.getQuery().getValue();
3297
+ if (property) {
3298
+ return getValue(state, this.withStoreName(property));
3299
+ }
3300
+ return state;
3301
+ }
3302
+ withStoreName(prop) {
3303
+ return `${this.storeName}.${prop}`;
3304
+ }
3305
+ get storeName() {
3306
+ return this.getStore().storeName;
3307
+ }
3308
+ /** This method is responsible for updating the store or one entity; it can be the whole store or one entity. */
3309
+ updateStore(newState, entityId, property) {
3310
+ if (this.isEntityBased(entityId)) {
3311
+ this.getStore().update(entityId, newState);
3312
+ }
3313
+ else {
3314
+ if (property) {
3315
+ this.getStore()._setState(state => {
3316
+ return setValue(state, this.withStoreName(property), newState);
3317
+ });
3318
+ return;
3319
+ }
3320
+ this.getStore()._setState(state => (Object.assign({}, state, newState)));
3321
+ }
3322
+ }
3323
+ /**
3324
+ * Function to invoke upon reset
3325
+ */
3326
+ onReset(fn) {
3327
+ const original = this.getStore().reset;
3328
+ this.getStore().reset = (...params) => {
3329
+ /** It should run after the plugin destroy method */
3330
+ setTimeout(() => {
3331
+ original.apply(this.getStore(), params);
3332
+ fn();
3333
+ });
3334
+ };
3335
+ }
3336
+ }
3337
+
3338
+ const paginatorDefaults = {
3339
+ pagesControls: false,
3340
+ range: false,
3341
+ startWith: 1,
3342
+ cacheTimeout: undefined,
3343
+ clearStoreWithCache: true
3344
+ };
3345
+ class PaginatorPlugin extends AkitaPlugin {
3346
+ constructor(query, config = {}) {
3347
+ super(query, {
3348
+ resetFn: () => {
3349
+ this.initial = false;
3350
+ this.destroy({ clearCache: true, currentPage: 1 });
3351
+ }
3352
+ });
3353
+ this.query = query;
3354
+ this.config = config;
3355
+ /** Save current filters, sorting, etc. in cache */
3356
+ this.metadata = new Map();
3357
+ this.pages = new Map();
3358
+ this.pagination = {
3359
+ currentPage: 1,
3360
+ perPage: 0,
3361
+ total: 0,
3362
+ lastPage: 0,
3363
+ data: []
3364
+ };
3365
+ /**
3366
+ * When the user navigates to a different page and return
3367
+ * we don't want to call `clearCache` on first time.
3368
+ */
3369
+ this.initial = true;
3370
+ /**
3371
+ * Proxy to the query loading
3372
+ */
3373
+ this.isLoading$ = this.query.selectLoading().pipe(delay(0));
3374
+ this.config = Object.assign(paginatorDefaults, config);
3375
+ const { startWith, cacheTimeout } = this.config;
3376
+ this.page = new BehaviorSubject(startWith);
3377
+ if (isObservable(cacheTimeout)) {
3378
+ this.clearCacheSubscription = cacheTimeout.subscribe(() => this.clearCache());
3379
+ }
3380
+ }
3381
+ /**
3382
+ * Listen to page changes
3383
+ */
3384
+ get pageChanges() {
3385
+ return this.page.asObservable();
3386
+ }
3387
+ /**
3388
+ * Get the current page number
3389
+ */
3390
+ get currentPage() {
3391
+ return this.pagination.currentPage;
3392
+ }
3393
+ /**
3394
+ * Check if current page is the first one
3395
+ */
3396
+ get isFirst() {
3397
+ return this.currentPage === 1;
3398
+ }
3399
+ /**
3400
+ * Check if current page is the last one
3401
+ */
3402
+ get isLast() {
3403
+ return this.currentPage === this.pagination.lastPage;
3404
+ }
3405
+ /**
3406
+ * Whether to generate an array of pages for *ngFor
3407
+ * [1, 2, 3, 4]
3408
+ */
3409
+ withControls() {
3410
+ this.config.pagesControls = true;
3411
+ return this;
3412
+ }
3413
+ /**
3414
+ * Whether to generate the `from` and `to` keys
3415
+ * [1, 2, 3, 4]
3416
+ */
3417
+ withRange() {
3418
+ this.config.range = true;
3419
+ return this;
3420
+ }
3421
+ /**
3422
+ * Set the loading state
3423
+ */
3424
+ setLoading(value = true) {
3425
+ this.getStore().setLoading(value);
3426
+ }
3427
+ /**
3428
+ * Update the pagination object and add the page
3429
+ */
3430
+ update(response) {
3431
+ this.pagination = response;
3432
+ this.addPage(response.data);
3433
+ }
3434
+ /**
3435
+ *
3436
+ * Set the ids and add the page to store
3437
+ */
3438
+ addPage(data) {
3439
+ this.pages.set(this.currentPage, { ids: data.map(entity => entity[this.getStore().idKey]) });
3440
+ this.getStore().upsertMany(data);
3441
+ }
3442
+ /**
3443
+ * Clear the cache.
3444
+ */
3445
+ clearCache(options = {}) {
3446
+ if (!this.initial) {
3447
+ logAction('@Pagination - Clear Cache');
3448
+ if (options.clearStore !== false && (this.config.clearStoreWithCache || options.clearStore)) {
3449
+ this.getStore().remove();
3450
+ }
3451
+ this.pages = new Map();
3452
+ this.metadata = new Map();
3453
+ }
3454
+ this.initial = false;
3455
+ }
3456
+ clearPage(page) {
3457
+ this.pages.delete(page);
3458
+ }
3459
+ /**
3460
+ * Clear the cache timeout and optionally the pages
3461
+ */
3462
+ destroy({ clearCache, currentPage } = {}) {
3463
+ if (this.clearCacheSubscription) {
3464
+ this.clearCacheSubscription.unsubscribe();
3465
+ }
3466
+ if (clearCache) {
3467
+ this.clearCache();
3468
+ }
3469
+ if (!isUndefined(currentPage)) {
3470
+ this.setPage(currentPage);
3471
+ }
3472
+ this.initial = true;
3473
+ }
3474
+ /**
3475
+ * Whether the provided page is active
3476
+ */
3477
+ isPageActive(page) {
3478
+ return this.currentPage === page;
3479
+ }
3480
+ /**
3481
+ * Set the current page
3482
+ */
3483
+ setPage(page) {
3484
+ if (page !== this.currentPage || !this.hasPage(page)) {
3485
+ this.page.next((this.pagination.currentPage = page));
3486
+ }
3487
+ }
3488
+ /**
3489
+ * Increment current page
3490
+ */
3491
+ nextPage() {
3492
+ if (this.currentPage !== this.pagination.lastPage) {
3493
+ this.setPage(this.pagination.currentPage + 1);
3494
+ }
3495
+ }
3496
+ /**
3497
+ * Decrement current page
3498
+ */
3499
+ prevPage() {
3500
+ if (this.pagination.currentPage > 1) {
3501
+ this.setPage(this.pagination.currentPage - 1);
3502
+ }
3503
+ }
3504
+ /**
3505
+ * Set current page to last
3506
+ */
3507
+ setLastPage() {
3508
+ this.setPage(this.pagination.lastPage);
3509
+ }
3510
+ /**
3511
+ * Set current page to first
3512
+ */
3513
+ setFirstPage() {
3514
+ this.setPage(1);
3515
+ }
3516
+ /**
3517
+ * Check if page exists in cache
3518
+ */
3519
+ hasPage(page) {
3520
+ return this.pages.has(page);
3521
+ }
3522
+ /**
3523
+ * Get the current page if it's in cache, otherwise invoke the request
3524
+ */
3525
+ getPage(req) {
3526
+ let page = this.pagination.currentPage;
3527
+ if (this.hasPage(page)) {
3528
+ return this.selectPage(page);
3529
+ }
3530
+ else {
3531
+ this.setLoading(true);
3532
+ return from(req()).pipe(switchMap((config) => {
3533
+ page = config.currentPage;
3534
+ applyTransaction(() => {
3535
+ this.setLoading(false);
3536
+ this.update(config);
3537
+ });
3538
+ return this.selectPage(page);
3539
+ }));
3540
+ }
3541
+ }
3542
+ getQuery() {
3543
+ return this.query;
3544
+ }
3545
+ refreshCurrentPage() {
3546
+ if (isNil(this.currentPage) === false) {
3547
+ this.clearPage(this.currentPage);
3548
+ this.setPage(this.currentPage);
3549
+ }
3550
+ }
3551
+ getFrom() {
3552
+ if (this.isFirst) {
3553
+ return 1;
3554
+ }
3555
+ return (this.currentPage - 1) * this.pagination.perPage + 1;
3556
+ }
3557
+ getTo() {
3558
+ if (this.isLast) {
3559
+ return this.pagination.total;
3560
+ }
3561
+ return this.currentPage * this.pagination.perPage;
3562
+ }
3563
+ /**
3564
+ * Select the page
3565
+ */
3566
+ selectPage(page) {
3567
+ return this.query.selectAll({ asObject: true }).pipe(take(1), map(entities => {
3568
+ let response = Object.assign({}, this.pagination, { data: this.pages.get(page).ids.map(id => entities[id]) });
3569
+ const { range, pagesControls } = this.config;
3570
+ /** If no total - calc it */
3571
+ if (isNaN(this.pagination.total)) {
3572
+ if (response.lastPage === 1) {
3573
+ response.total = response.data ? response.data.length : 0;
3574
+ }
3575
+ else {
3576
+ response.total = response.perPage * response.lastPage;
3577
+ }
3578
+ this.pagination.total = response.total;
3579
+ }
3580
+ if (range) {
3581
+ response.from = this.getFrom();
3582
+ response.to = this.getTo();
3583
+ }
3584
+ if (pagesControls) {
3585
+ response.pageControls = generatePages(this.pagination.total, this.pagination.perPage);
3586
+ }
3587
+ return response;
3588
+ }));
3589
+ }
3590
+ }
3591
+ __decorate([
3592
+ action('@Pagination - New Page'),
3593
+ __metadata("design:type", Function),
3594
+ __metadata("design:paramtypes", [Object]),
3595
+ __metadata("design:returntype", void 0)
3596
+ ], PaginatorPlugin.prototype, "update", null);
3597
+ /**
3598
+ * Generate an array so we can ngFor them to navigate between pages
3599
+ */
3600
+ function generatePages(total, perPage) {
3601
+ const len = Math.ceil(total / perPage);
3602
+ let arr = [];
3603
+ for (let i = 0; i < len; i++) {
3604
+ arr.push(i + 1);
3605
+ }
3606
+ return arr;
3607
+ }
3608
+
3609
+ var StoreAction;
3610
+ (function (StoreAction) {
3611
+ StoreAction["Update"] = "UPDATE";
3612
+ })(StoreAction || (StoreAction = {}));
3613
+ var EntityStoreAction;
3614
+ (function (EntityStoreAction) {
3615
+ EntityStoreAction["Update"] = "UPDATE";
3616
+ EntityStoreAction["AddEntities"] = "ADD_ENTITIES";
3617
+ EntityStoreAction["SetEntities"] = "SET_ENTITIES";
3618
+ EntityStoreAction["UpdateEntities"] = "UPDATE_ENTITIES";
3619
+ EntityStoreAction["RemoveEntities"] = "REMOVE_ENTITIES";
3620
+ EntityStoreAction["UpsertEntities"] = "UPSERT_ENTITIES";
3621
+ EntityStoreAction["UpsertManyEntities"] = "UPSERT_MANY_ENTITIES";
3622
+ })(EntityStoreAction || (EntityStoreAction = {}));
3623
+
3624
+ export { Observable as O, Query as Q, SimpleOuterSubscriber as S, SimpleInnerSubscriber as a, isArray as b, isFunction as c, async as d, enableAkitaProdMode as e, from as f, Subscriber as g, distinctUntilChanged as h, innerSubscribe as i, filter as j, StoreConfig as k, Store as l, map as m };