dexie-cloud-addon 4.0.1-beta.46 → 4.0.1-beta.48

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 (264) hide show
  1. package/dist/{types → modern}/DexieCloudAPI.d.ts +3 -0
  2. package/dist/{types → modern}/DexieCloudOptions.d.ts +1 -0
  3. package/dist/modern/InvalidLicenseError.d.ts +5 -0
  4. package/dist/{types → modern}/TSON.d.ts +1 -1
  5. package/dist/modern/authentication/TokenErrorResponseError.d.ts +10 -0
  6. package/dist/{types → modern}/authentication/authenticate.d.ts +3 -3
  7. package/dist/{types → modern}/authentication/interactWithUser.d.ts +3 -0
  8. package/dist/modern/authentication/logout.d.ts +5 -0
  9. package/dist/modern/authentication/waitUntil.d.ts +3 -0
  10. package/dist/{types → modern}/currentUserEmitter.d.ts +1 -1
  11. package/dist/{types → modern}/db/entities/UserLogin.d.ts +6 -0
  12. package/dist/modern/default-ui/LoginDialog.d.ts +3 -0
  13. package/dist/modern/dexie-cloud-addon.d.ts +3 -0
  14. package/dist/modern/dexie-cloud-addon.js +488 -367
  15. package/dist/modern/dexie-cloud-addon.js.map +1 -1
  16. package/dist/modern/dexie-cloud-addon.min.js +2 -2
  17. package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
  18. package/dist/{types → modern}/dexie-cloud-client.d.ts +2 -0
  19. package/dist/modern/helpers/resolveText.d.ts +16 -0
  20. package/dist/modern/isEagerSyncDisabled.d.ts +2 -0
  21. package/dist/{types → modern}/middlewares/createMutationTrackingMiddleware.d.ts +1 -1
  22. package/dist/modern/prodLog.d.ts +9 -0
  23. package/dist/modern/service-worker.js +2027 -268
  24. package/dist/modern/service-worker.js.map +1 -1
  25. package/dist/modern/service-worker.min.js +2 -2
  26. package/dist/modern/service-worker.min.js.map +1 -1
  27. package/dist/modern/sync/performGuardedJob.d.ts +2 -0
  28. package/dist/modern/sync/ratelimit.d.ts +3 -0
  29. package/dist/{types → modern}/sync/sync.d.ts +0 -1
  30. package/dist/{types → modern}/types/DXCAlert.d.ts +1 -1
  31. package/dist/{types → modern}/types/DXCUserInteraction.d.ts +40 -2
  32. package/dist/{types → modern}/types/SyncState.d.ts +1 -0
  33. package/dist/umd/DISABLE_SERVICEWORKER_STRATEGY.d.ts +1 -0
  34. package/dist/umd/DXCWebSocketStatus.d.ts +1 -0
  35. package/dist/umd/DexieCloudAPI.d.ts +72 -0
  36. package/dist/umd/DexieCloudOptions.d.ts +22 -0
  37. package/dist/umd/DexieCloudSyncOptions.d.ts +4 -0
  38. package/dist/umd/DexieCloudTable.d.ts +18 -0
  39. package/dist/umd/InvalidLicenseError.d.ts +5 -0
  40. package/dist/umd/Invite.d.ts +8 -0
  41. package/dist/umd/PermissionChecker.d.ts +15 -0
  42. package/dist/umd/TSON.d.ts +17 -0
  43. package/dist/umd/WSObservable.d.ts +68 -0
  44. package/dist/umd/associate.d.ts +1 -0
  45. package/dist/umd/authentication/AuthPersistedContext.d.ts +9 -0
  46. package/dist/umd/authentication/TokenErrorResponseError.d.ts +10 -0
  47. package/dist/umd/authentication/TokenExpiredError.d.ts +3 -0
  48. package/dist/umd/authentication/UNAUTHORIZED_USER.d.ts +2 -0
  49. package/dist/umd/authentication/authenticate.d.ts +20 -0
  50. package/dist/umd/authentication/currentUserObservable.d.ts +1 -0
  51. package/dist/umd/authentication/interactWithUser.d.ts +21 -0
  52. package/dist/umd/authentication/login.d.ts +6 -0
  53. package/dist/umd/authentication/logout.d.ts +5 -0
  54. package/dist/umd/authentication/otpFetchTokenCallback.d.ts +3 -0
  55. package/dist/umd/authentication/setCurrentUser.d.ts +14 -0
  56. package/dist/umd/authentication/waitUntil.d.ts +3 -0
  57. package/dist/umd/computeSyncState.d.ts +4 -0
  58. package/dist/umd/createSharedValueObservable.d.ts +3 -0
  59. package/dist/umd/currentUserEmitter.d.ts +3 -0
  60. package/dist/umd/db/DexieCloudDB.d.ts +59 -0
  61. package/dist/umd/db/entities/BaseRevisionMapEntry.d.ts +5 -0
  62. package/dist/umd/db/entities/EntityCommon.d.ts +5 -0
  63. package/dist/umd/db/entities/GuardedJob.d.ts +5 -0
  64. package/dist/umd/db/entities/Member.d.ts +19 -0
  65. package/dist/umd/db/entities/PersistedSyncState.d.ts +14 -0
  66. package/dist/umd/db/entities/Realm.d.ts +16 -0
  67. package/dist/umd/db/entities/Role.d.ts +11 -0
  68. package/dist/umd/db/entities/UserLogin.d.ts +22 -0
  69. package/dist/umd/default-ui/Dialog.d.ts +5 -0
  70. package/dist/umd/default-ui/LoginDialog.d.ts +3 -0
  71. package/dist/umd/default-ui/Styles.d.ts +3 -0
  72. package/dist/umd/default-ui/index.d.ts +24 -0
  73. package/dist/umd/dexie-cloud-addon.d.ts +3 -0
  74. package/dist/umd/dexie-cloud-addon.js +505 -388
  75. package/dist/umd/dexie-cloud-addon.js.map +1 -1
  76. package/dist/umd/dexie-cloud-client.d.ts +13 -0
  77. package/dist/umd/errors/HttpError.d.ts +5 -0
  78. package/dist/umd/extend-dexie-interface.d.ts +23 -0
  79. package/dist/umd/getGlobalRolesObservable.d.ts +5 -0
  80. package/dist/umd/getInternalAccessControlObservable.d.ts +12 -0
  81. package/dist/umd/getInvitesObservable.d.ts +23 -0
  82. package/dist/umd/getPermissionsLookupObservable.d.ts +16 -0
  83. package/dist/umd/getTiedRealmId.d.ts +2 -0
  84. package/dist/umd/helpers/BroadcastedAndLocalEvent.d.ts +8 -0
  85. package/dist/umd/helpers/CancelToken.d.ts +4 -0
  86. package/dist/umd/helpers/IS_SERVICE_WORKER.d.ts +1 -0
  87. package/dist/umd/helpers/SWBroadcastChannel.d.ts +12 -0
  88. package/dist/umd/helpers/allSettled.d.ts +1 -0
  89. package/dist/umd/helpers/bulkUpdate.d.ts +4 -0
  90. package/dist/umd/helpers/computeRealmSetHash.d.ts +2 -0
  91. package/dist/umd/helpers/date-constants.d.ts +5 -0
  92. package/dist/umd/helpers/dbOnClosed.d.ts +2 -0
  93. package/dist/umd/helpers/flatten.d.ts +1 -0
  94. package/dist/umd/helpers/getMutationTable.d.ts +1 -0
  95. package/dist/umd/helpers/getSyncableTables.d.ts +4 -0
  96. package/dist/umd/helpers/getTableFromMutationTable.d.ts +1 -0
  97. package/dist/umd/helpers/makeArray.d.ts +1 -0
  98. package/dist/umd/helpers/randomString.d.ts +1 -0
  99. package/dist/umd/helpers/resolveText.d.ts +16 -0
  100. package/dist/umd/helpers/throwVersionIncrementNeeded.d.ts +1 -0
  101. package/dist/umd/helpers/visibilityState.d.ts +1 -0
  102. package/dist/umd/isEagerSyncDisabled.d.ts +2 -0
  103. package/dist/umd/isFirefox.d.ts +1 -0
  104. package/dist/umd/isSafari.d.ts +2 -0
  105. package/dist/umd/mapValueObservable.d.ts +5 -0
  106. package/dist/umd/mergePermissions.d.ts +2 -0
  107. package/dist/umd/middleware-helpers/guardedTable.d.ts +11 -0
  108. package/dist/umd/middleware-helpers/idGenerationHelpers.d.ts +18 -0
  109. package/dist/umd/middlewares/createIdGenerationMiddleware.d.ts +3 -0
  110. package/dist/umd/middlewares/createImplicitPropSetterMiddleware.d.ts +3 -0
  111. package/dist/umd/middlewares/createMutationTrackingMiddleware.d.ts +17 -0
  112. package/dist/umd/middlewares/outstandingTransaction.d.ts +4 -0
  113. package/dist/umd/overrideParseStoresSpec.d.ts +4 -0
  114. package/dist/umd/performInitialSync.d.ts +4 -0
  115. package/dist/umd/permissions.d.ts +9 -0
  116. package/dist/umd/prodLog.d.ts +9 -0
  117. package/dist/umd/service-worker.d.ts +1 -0
  118. package/dist/umd/service-worker.js +2078 -322
  119. package/dist/umd/service-worker.js.map +1 -1
  120. package/dist/umd/sync/LocalSyncWorker.d.ts +7 -0
  121. package/dist/umd/sync/SyncRequiredError.d.ts +3 -0
  122. package/dist/umd/sync/applyServerChanges.d.ts +3 -0
  123. package/dist/umd/sync/connectWebSocket.d.ts +2 -0
  124. package/dist/umd/sync/encodeIdsForServer.d.ts +4 -0
  125. package/dist/umd/sync/extractRealm.d.ts +2 -0
  126. package/dist/umd/sync/getLatestRevisionsPerTable.d.ts +6 -0
  127. package/dist/umd/sync/getTablesToSyncify.d.ts +3 -0
  128. package/dist/umd/sync/isOnline.d.ts +1 -0
  129. package/dist/umd/sync/isSyncNeeded.d.ts +2 -0
  130. package/dist/umd/sync/listClientChanges.d.ts +9 -0
  131. package/dist/umd/sync/listSyncifiedChanges.d.ts +5 -0
  132. package/dist/umd/sync/messageConsumerIsReady.d.ts +2 -0
  133. package/dist/umd/sync/messagesFromServerQueue.d.ts +8 -0
  134. package/dist/umd/sync/modifyLocalObjectsWithNewUserId.d.ts +4 -0
  135. package/dist/umd/sync/myId.d.ts +1 -0
  136. package/dist/umd/sync/numUnsyncedMutations.d.ts +2 -0
  137. package/dist/umd/sync/old_startSyncingClientChanges.d.ts +39 -0
  138. package/dist/umd/sync/performGuardedJob.d.ts +2 -0
  139. package/dist/umd/sync/ratelimit.d.ts +3 -0
  140. package/dist/umd/sync/registerSyncEvent.d.ts +3 -0
  141. package/dist/umd/sync/sync.d.ts +15 -0
  142. package/dist/umd/sync/syncIfPossible.d.ts +5 -0
  143. package/dist/umd/sync/syncWithServer.d.ts +6 -0
  144. package/dist/umd/sync/triggerSync.d.ts +2 -0
  145. package/dist/umd/sync/updateBaseRevs.d.ts +5 -0
  146. package/dist/umd/types/DXCAlert.d.ts +25 -0
  147. package/dist/umd/types/DXCInputField.d.ts +11 -0
  148. package/dist/umd/types/DXCUserInteraction.d.ts +93 -0
  149. package/dist/umd/types/NewIdOptions.d.ts +3 -0
  150. package/dist/umd/types/SWMessageEvent.d.ts +3 -0
  151. package/dist/umd/types/SWSyncEvent.d.ts +4 -0
  152. package/dist/umd/types/SyncState.d.ts +9 -0
  153. package/dist/umd/types/TXExpandos.d.ts +11 -0
  154. package/dist/umd/updateSchemaFromOptions.d.ts +3 -0
  155. package/dist/umd/userIsActive.d.ts +7 -0
  156. package/dist/umd/verifyConfig.d.ts +2 -0
  157. package/dist/umd/verifySchema.d.ts +2 -0
  158. package/package.json +14 -48
  159. package/LICENSE +0 -202
  160. package/copydts.sh +0 -5
  161. package/dist/types/default-ui/LoginDialog.d.ts +0 -6
  162. package/dist/types/helpers/resolveText.d.ts +0 -2
  163. package/dist/types/sync/performGuardedJob.d.ts +0 -4
  164. package/dist/umd/dexie-cloud-addon.min.js +0 -2
  165. package/dist/umd/dexie-cloud-addon.min.js.map +0 -1
  166. package/dist/umd/service-worker.min.js +0 -2
  167. package/dist/umd/service-worker.min.js.map +0 -1
  168. /package/dist/{types → modern}/DISABLE_SERVICEWORKER_STRATEGY.d.ts +0 -0
  169. /package/dist/{types → modern}/DXCWebSocketStatus.d.ts +0 -0
  170. /package/dist/{types → modern}/DexieCloudSyncOptions.d.ts +0 -0
  171. /package/dist/{types → modern}/DexieCloudTable.d.ts +0 -0
  172. /package/dist/{types → modern}/Invite.d.ts +0 -0
  173. /package/dist/{types → modern}/PermissionChecker.d.ts +0 -0
  174. /package/dist/{types → modern}/WSObservable.d.ts +0 -0
  175. /package/dist/{types → modern}/associate.d.ts +0 -0
  176. /package/dist/{types → modern}/authentication/AuthPersistedContext.d.ts +0 -0
  177. /package/dist/{types → modern}/authentication/TokenExpiredError.d.ts +0 -0
  178. /package/dist/{types → modern}/authentication/UNAUTHORIZED_USER.d.ts +0 -0
  179. /package/dist/{types → modern}/authentication/currentUserObservable.d.ts +0 -0
  180. /package/dist/{types → modern}/authentication/login.d.ts +0 -0
  181. /package/dist/{types → modern}/authentication/otpFetchTokenCallback.d.ts +0 -0
  182. /package/dist/{types → modern}/authentication/setCurrentUser.d.ts +0 -0
  183. /package/dist/{types → modern}/computeSyncState.d.ts +0 -0
  184. /package/dist/{types → modern}/createSharedValueObservable.d.ts +0 -0
  185. /package/dist/{types → modern}/db/DexieCloudDB.d.ts +0 -0
  186. /package/dist/{types → modern}/db/entities/BaseRevisionMapEntry.d.ts +0 -0
  187. /package/dist/{types → modern}/db/entities/EntityCommon.d.ts +0 -0
  188. /package/dist/{types → modern}/db/entities/GuardedJob.d.ts +0 -0
  189. /package/dist/{types → modern}/db/entities/Member.d.ts +0 -0
  190. /package/dist/{types → modern}/db/entities/PersistedSyncState.d.ts +0 -0
  191. /package/dist/{types → modern}/db/entities/Realm.d.ts +0 -0
  192. /package/dist/{types → modern}/db/entities/Role.d.ts +0 -0
  193. /package/dist/{types → modern}/default-ui/Dialog.d.ts +0 -0
  194. /package/dist/{types → modern}/default-ui/Styles.d.ts +0 -0
  195. /package/dist/{types → modern}/default-ui/index.d.ts +0 -0
  196. /package/dist/{types → modern}/errors/HttpError.d.ts +0 -0
  197. /package/dist/{types → modern}/extend-dexie-interface.d.ts +0 -0
  198. /package/dist/{types → modern}/getGlobalRolesObservable.d.ts +0 -0
  199. /package/dist/{types → modern}/getInternalAccessControlObservable.d.ts +0 -0
  200. /package/dist/{types → modern}/getInvitesObservable.d.ts +0 -0
  201. /package/dist/{types → modern}/getPermissionsLookupObservable.d.ts +0 -0
  202. /package/dist/{types → modern}/getTiedRealmId.d.ts +0 -0
  203. /package/dist/{types → modern}/helpers/BroadcastedAndLocalEvent.d.ts +0 -0
  204. /package/dist/{types → modern}/helpers/CancelToken.d.ts +0 -0
  205. /package/dist/{types → modern}/helpers/IS_SERVICE_WORKER.d.ts +0 -0
  206. /package/dist/{types → modern}/helpers/SWBroadcastChannel.d.ts +0 -0
  207. /package/dist/{types → modern}/helpers/allSettled.d.ts +0 -0
  208. /package/dist/{types → modern}/helpers/bulkUpdate.d.ts +0 -0
  209. /package/dist/{types → modern}/helpers/computeRealmSetHash.d.ts +0 -0
  210. /package/dist/{types → modern}/helpers/date-constants.d.ts +0 -0
  211. /package/dist/{types → modern}/helpers/dbOnClosed.d.ts +0 -0
  212. /package/dist/{types → modern}/helpers/flatten.d.ts +0 -0
  213. /package/dist/{types → modern}/helpers/getMutationTable.d.ts +0 -0
  214. /package/dist/{types → modern}/helpers/getSyncableTables.d.ts +0 -0
  215. /package/dist/{types → modern}/helpers/getTableFromMutationTable.d.ts +0 -0
  216. /package/dist/{types → modern}/helpers/makeArray.d.ts +0 -0
  217. /package/dist/{types → modern}/helpers/randomString.d.ts +0 -0
  218. /package/dist/{types → modern}/helpers/throwVersionIncrementNeeded.d.ts +0 -0
  219. /package/dist/{types → modern}/helpers/visibilityState.d.ts +0 -0
  220. /package/dist/{types → modern}/isFirefox.d.ts +0 -0
  221. /package/dist/{types → modern}/isSafari.d.ts +0 -0
  222. /package/dist/{types → modern}/mapValueObservable.d.ts +0 -0
  223. /package/dist/{types → modern}/mergePermissions.d.ts +0 -0
  224. /package/dist/{types → modern}/middleware-helpers/guardedTable.d.ts +0 -0
  225. /package/dist/{types → modern}/middleware-helpers/idGenerationHelpers.d.ts +0 -0
  226. /package/dist/{types → modern}/middlewares/createIdGenerationMiddleware.d.ts +0 -0
  227. /package/dist/{types → modern}/middlewares/createImplicitPropSetterMiddleware.d.ts +0 -0
  228. /package/dist/{types → modern}/middlewares/outstandingTransaction.d.ts +0 -0
  229. /package/dist/{types → modern}/overrideParseStoresSpec.d.ts +0 -0
  230. /package/dist/{types → modern}/performInitialSync.d.ts +0 -0
  231. /package/dist/{types → modern}/permissions.d.ts +0 -0
  232. /package/dist/{types → modern}/service-worker.d.ts +0 -0
  233. /package/dist/{types → modern}/sync/LocalSyncWorker.d.ts +0 -0
  234. /package/dist/{types → modern}/sync/SyncRequiredError.d.ts +0 -0
  235. /package/dist/{types → modern}/sync/applyServerChanges.d.ts +0 -0
  236. /package/dist/{types → modern}/sync/connectWebSocket.d.ts +0 -0
  237. /package/dist/{types → modern}/sync/encodeIdsForServer.d.ts +0 -0
  238. /package/dist/{types → modern}/sync/extractRealm.d.ts +0 -0
  239. /package/dist/{types → modern}/sync/getLatestRevisionsPerTable.d.ts +0 -0
  240. /package/dist/{types → modern}/sync/getTablesToSyncify.d.ts +0 -0
  241. /package/dist/{types → modern}/sync/isOnline.d.ts +0 -0
  242. /package/dist/{types → modern}/sync/isSyncNeeded.d.ts +0 -0
  243. /package/dist/{types → modern}/sync/listClientChanges.d.ts +0 -0
  244. /package/dist/{types → modern}/sync/listSyncifiedChanges.d.ts +0 -0
  245. /package/dist/{types → modern}/sync/messageConsumerIsReady.d.ts +0 -0
  246. /package/dist/{types → modern}/sync/messagesFromServerQueue.d.ts +0 -0
  247. /package/dist/{types → modern}/sync/modifyLocalObjectsWithNewUserId.d.ts +0 -0
  248. /package/dist/{types → modern}/sync/myId.d.ts +0 -0
  249. /package/dist/{types → modern}/sync/numUnsyncedMutations.d.ts +0 -0
  250. /package/dist/{types → modern}/sync/old_startSyncingClientChanges.d.ts +0 -0
  251. /package/dist/{types → modern}/sync/registerSyncEvent.d.ts +0 -0
  252. /package/dist/{types → modern}/sync/syncIfPossible.d.ts +0 -0
  253. /package/dist/{types → modern}/sync/syncWithServer.d.ts +0 -0
  254. /package/dist/{types → modern}/sync/triggerSync.d.ts +0 -0
  255. /package/dist/{types → modern}/sync/updateBaseRevs.d.ts +0 -0
  256. /package/dist/{types → modern}/types/DXCInputField.d.ts +0 -0
  257. /package/dist/{types → modern}/types/NewIdOptions.d.ts +0 -0
  258. /package/dist/{types → modern}/types/SWMessageEvent.d.ts +0 -0
  259. /package/dist/{types → modern}/types/SWSyncEvent.d.ts +0 -0
  260. /package/dist/{types → modern}/types/TXExpandos.d.ts +0 -0
  261. /package/dist/{types → modern}/updateSchemaFromOptions.d.ts +0 -0
  262. /package/dist/{types → modern}/userIsActive.d.ts +0 -0
  263. /package/dist/{types → modern}/verifyConfig.d.ts +0 -0
  264. /package/dist/{types → modern}/verifySchema.d.ts +0 -0
package/LICENSE DELETED
@@ -1,202 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "{}"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright {yyyy} {name of copyright owner}
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
202
-
package/copydts.sh DELETED
@@ -1,5 +0,0 @@
1
- #!/bin/bash -e
2
- rm -rf dist/types
3
- mkdir dist/types
4
- cd tools/tmp/modern
5
- find . -name '*.d.ts' | cpio -pdm ../../../dist/types/
@@ -1,6 +0,0 @@
1
- import { h } from 'preact';
2
- import { DXCGenericUserInteraction } from '../types/DXCUserInteraction';
3
- import { DXCInputField } from '../types/DXCInputField';
4
- export declare function LoginDialog({ title, alerts, fields, onCancel, onSubmit, }: DXCGenericUserInteraction<string, {
5
- [name: string]: DXCInputField;
6
- }>): h.JSX.Element;
@@ -1,2 +0,0 @@
1
- import { DXCAlert } from "../types/DXCAlert";
2
- export declare function resolveText({ message, messageCode, messageParams }: DXCAlert): string;
@@ -1,4 +0,0 @@
1
- import { DexieCloudDB } from '../db/DexieCloudDB';
2
- export declare function performGuardedJob(db: DexieCloudDB, jobName: string, jobsTableName: string, job: () => Promise<any>, { awaitRemoteJob }?: {
3
- awaitRemoteJob?: boolean;
4
- }): Promise<void>;
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("dexie"),require("rxjs")):"function"==typeof define&&define.amd?define(["exports","dexie","rxjs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).DexieCloud={},e.Dexie,e.rxjs)}(this,(function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t),i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},i(e,t)};function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function a(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}function c(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function l(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function u(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function d(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function f(e){return this instanceof f?(this.v=e,this):new f(e)}function p(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(e,t||[]),i=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(e){o[e]&&(r[e]=function(t){return new Promise((function(n,r){i.push([e,t,n,r])>1||a(e,t)}))})}function a(e,t){try{!function(e){e.value instanceof f?Promise.resolve(e.value.v).then(c,l):u(i[0][2],e)}(o[e](t))}catch(e){u(i[0][3],e)}}function c(e){a("next",e)}function l(e){a("throw",e)}function u(e,t){e(t),i.shift(),i.length&&a(i[0][0],i[0][1])}}function h(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=l(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise((function(r,o){(function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)})(r,o,(t=e[n](t)).done,t.value)}))}}}function y(e){if(!e)throw new Error("Assertion Failed")}const v={}.hasOwnProperty;function b(e,t,n){if(e&&void 0!==t&&(!("isFrozen"in Object)||!Object.isFrozen(e)))if("string"!=typeof t&&"length"in t){y("string"!=typeof n&&"length"in n);for(var r=0,o=t.length;r<o;++r)b(e,t[r],n[r])}else{var i=t.indexOf(".");if(-1!==i){var s=t.substr(0,i),a=t.substr(i+1);if(""===a)void 0===n?Array.isArray(e)?isNaN(parseInt(s))||e.splice(parseInt(s),1):delete e[s]:e[s]=n;else{var c=e[s];c&&function(e,t){return v.call(e,t)}(e,s)||(c=e[s]={}),b(c,a,n)}}else void 0===n?Array.isArray(e)&&!isNaN(parseInt(t))?e.splice(t,1):delete e[t]:e[t]=n}}const m="undefined"!=typeof self&&"undefined"!=typeof crypto?(e,t=crypto.getRandomValues.bind(crypto))=>{const n=new Uint8Array(e);return t(n),self.btoa(String.fromCharCode.apply(null,n))}:"undefined"!=typeof Buffer?(e,t=g)=>{const n=Buffer.alloc(e);return t(n),n.toString("base64")}:()=>{throw new Error("No implementation of randomString was found")};function g(e){for(let t=0;t<e.length;++t)e[t]=Math.floor(256*Math.random())}function _(e){return"string"==typeof e||!!(Array.isArray(e)&&e.some((e=>_(e)))&&e.every(w))}function w(e){return"string"==typeof e||"number"==typeof e||Array.isArray(e)&&e.every(w)}function S(e,t,n){const r=e[t]||(e[t]={}),o=n.keys.map((e=>"string"==typeof e?e:JSON.stringify(e)));switch(n.type){case"insert":case"upsert":o.forEach(((e,t)=>{r[e]={type:"ups",val:n.values[t]}}));break;case"update":case"modify":o.forEach(((e,t)=>{const o="update"===n.type?n.changeSpecs[t]:n.changeSpec,i=r[e];if(i)switch(i.type){case"ups":for(const[e,t]of Object.entries(o))b(i.val,e,t);break;case"del":break;case"upd":Object.assign(i.mod,o)}else r[e]={type:"upd",mod:o}}));break;case"delete":o.forEach((e=>{r[e]={type:"del"}}))}return e}function k(e,t){for(const{table:n,muts:r}of t)for(const t of r)S(e,n,t)}function x(e){return"function"==typeof e}function I(e){return function(t){if(function(e){return x(null==e?void 0:e.lift)}(t))return t.lift((function(t){try{return e(t,this)}catch(e){this.error(e)}}));throw new TypeError("Unable to lift unknown Observable type")}}var E=function(e){return e&&"number"==typeof e.length&&"function"!=typeof e};function O(e){return x(null==e?void 0:e.then)}function T(e){var t=e((function(e){Error.call(e),e.stack=(new Error).stack}));return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var C=T((function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map((function(e,t){return t+1+") "+e.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}}));function A(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var j=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=l(i),a=s.next();!a.done;a=s.next()){a.value.remove(this)}}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var c=this.initialTeardown;if(x(c))try{c()}catch(e){o=e instanceof C?e.errors:[e]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var p=l(f),h=p.next();!h.done;h=p.next()){var y=h.value;try{U(y)}catch(e){o=null!=o?o:[],e instanceof C?o=d(d([],u(o)),u(e.errors)):o.push(e)}}}catch(e){n={error:e}}finally{try{h&&!h.done&&(r=p.return)&&r.call(p)}finally{if(n)throw n.error}}}if(o)throw new C(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)U(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&A(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&A(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}();function P(e){return e instanceof j||e&&"closed"in e&&x(e.remove)&&x(e.add)&&x(e.unsubscribe)}function U(e){x(e)?e():e.unsubscribe()}j.EMPTY;var $={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},D={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=D.delegate;return(null==o?void 0:o.setTimeout)?o.setTimeout.apply(o,d([e,t],u(n))):setTimeout.apply(void 0,d([e,t],u(n)))},clearTimeout:function(e){var t=D.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function N(e){D.setTimeout((function(){var t=$.onUnhandledError;if(!t)throw e;t(e)}))}function R(){}var L=B("C",void 0,void 0);function B(e,t,n){return{kind:e,value:t,error:n}}var W=null;var M=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,P(t)&&t.add(n)):n.destination=J,n}return s(t,e),t.create=function(e,t,n){return new V(e,t,n)},t.prototype.next=function(e){this.isStopped?q(function(e){return B("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?q(B("E",void 0,e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?q(L,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(j),F=Function.prototype.bind;function H(e,t){return F.call(e,t)}var K=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){z(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){z(e)}else z(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){z(e)}},e}(),V=function(e){function t(t,n,r){var o,i,s=e.call(this)||this;x(t)||!t?o={next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:s&&$.useDeprecatedNextContext?((i=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},o={next:t.next&&H(t.next,i),error:t.error&&H(t.error,i),complete:t.complete&&H(t.complete,i)}):o=t;return s.destination=new K(o),s}return s(t,e),t}(M);function z(e){N(e)}function q(e,t){var n=$.onStoppedNotification;n&&D.setTimeout((function(){return n(e,t)}))}var J={closed:!0,next:R,error:function(e){throw e},complete:R},G="function"==typeof Symbol&&Symbol.observable||"@@observable";function Y(e){return e}function Q(e){return 0===e.length?Y:1===e.length?e[0]:function(t){return e.reduce((function(e,t){return t(e)}),t)}}var Z=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof M||function(e){return e&&x(e.next)&&x(e.error)&&x(e.complete)}(r)&&P(r)?e:new V(e,t,n);return function(e){if($.useDeprecatedSynchronousErrorHandling){var t=!W;if(t&&(W={errorThrown:!1,error:null}),e(),t){var n=W,r=n.errorThrown,o=n.error;if(W=null,r)throw o}}else e()}((function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))})),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=X(t))((function(t,r){var o=new V({next:function(t){try{e(t)}catch(e){r(e),o.unsubscribe()}},error:r,complete:t});n.subscribe(o)}))},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[G]=function(){return this},e.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Q(e)(this)},e.prototype.toPromise=function(e){var t=this;return new(e=X(e))((function(e,n){var r;t.subscribe((function(e){return r=e}),(function(e){return n(e)}),(function(){return e(r)}))}))},e.create=function(t){return new e(t)},e}();function X(e){var t;return null!==(t=null!=e?e:$.Promise)&&void 0!==t?t:Promise}function ee(e){return x(e[G])}function te(e){return Symbol.asyncIterator&&x(null==e?void 0:e[Symbol.asyncIterator])}function ne(e){return new TypeError("You provided "+(null!==e&&"object"==typeof e?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var re="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function oe(e){return x(null==e?void 0:e[re])}function ie(e){return p(this,arguments,(function(){var t,n,r;return c(this,(function(o){switch(o.label){case 0:t=e.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,f(t.read())];case 3:return n=o.sent(),r=n.value,n.done?[4,f(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,f(r)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}}))}))}function se(e){return x(null==e?void 0:e.getReader)}function ae(e){if(e instanceof Z)return e;if(null!=e){if(ee(e))return o=e,new Z((function(e){var t=o[G]();if(x(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(E(e))return r=e,new Z((function(e){for(var t=0;t<r.length&&!e.closed;t++)e.next(r[t]);e.complete()}));if(O(e))return n=e,new Z((function(e){n.then((function(t){e.closed||(e.next(t),e.complete())}),(function(t){return e.error(t)})).then(null,N)}));if(te(e))return ce(e);if(oe(e))return t=e,new Z((function(e){var n,r;try{for(var o=l(t),i=o.next();!i.done;i=o.next()){var s=i.value;if(e.next(s),e.closed)return}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}e.complete()}));if(se(e))return ce(ie(e))}var t,n,r,o;throw ne(e)}function ce(e){return new Z((function(t){(function(e,t){var n,r,o,i;return a(this,void 0,void 0,(function(){var s,a;return c(this,(function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),n=h(e),c.label=1;case 1:return[4,n.next()];case 2:if((r=c.sent()).done)return[3,4];if(s=r.value,t.next(s),t.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),o={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),r&&!r.done&&(i=n.return)?[4,i.call(n)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}}))}))})(e,t).catch((function(e){return t.error(e)}))}))}function le(e,t,n,r,o){return new ue(e,t,n,r,o)}var ue=function(e){function t(t,n,r,o,i,s){var a=e.call(this,t)||this;return a.onFinalize=i,a.shouldUnsubscribe=s,a._next=n?function(e){try{n(e)}catch(e){t.error(e)}}:e.prototype._next,a._error=o?function(e){try{o(e)}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._error,a._complete=r?function(){try{r()}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,a}return s(t,e),t.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;e.prototype.unsubscribe.call(this),!n&&(null===(t=this.onFinalize)||void 0===t||t.call(this))}},t}(M),de=function(e){function t(t,n){return e.call(this)||this}return s(t,e),t.prototype.schedule=function(e,t){return this},t}(j),fe={setInterval:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=fe.delegate;return(null==o?void 0:o.setInterval)?o.setInterval.apply(o,d([e,t],u(n))):setInterval.apply(void 0,d([e,t],u(n)))},clearInterval:function(e){var t=fe.delegate;return((null==t?void 0:t.clearInterval)||clearInterval)(e)},delegate:void 0},pe=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.scheduler=t,r.work=n,r.pending=!1,r}return s(t,e),t.prototype.schedule=function(e,t){if(void 0===t&&(t=0),this.closed)return this;this.state=e;var n=this.id,r=this.scheduler;return null!=n&&(this.id=this.recycleAsyncId(r,n,t)),this.pending=!0,this.delay=t,this.id=this.id||this.requestAsyncId(r,this.id,t),this},t.prototype.requestAsyncId=function(e,t,n){return void 0===n&&(n=0),fe.setInterval(e.flush.bind(e,this),n)},t.prototype.recycleAsyncId=function(e,t,n){if(void 0===n&&(n=0),null!=n&&this.delay===n&&!1===this.pending)return t;fe.clearInterval(t)},t.prototype.execute=function(e,t){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var n=this._execute(e,t);if(n)return n;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,t){var n,r=!1;try{this.work(e)}catch(e){r=!0,n=e||new Error("Scheduled action threw falsy error")}if(r)return this.unsubscribe(),n},t.prototype.unsubscribe=function(){if(!this.closed){var t=this.id,n=this.scheduler,r=n.actions;this.work=this.state=this.scheduler=null,this.pending=!1,A(r,this),null!=t&&(this.id=this.recycleAsyncId(n,t,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t}(de),he={now:function(){return(he.delegate||Date).now()},delegate:void 0},ye=function(){function e(t,n){void 0===n&&(n=e.now),this.schedulerActionCtor=t,this.now=n}return e.prototype.schedule=function(e,t,n){return void 0===t&&(t=0),new this.schedulerActionCtor(this,e).schedule(n,t)},e.now=he.now,e}(),ve=new(function(e){function t(t,n){void 0===n&&(n=ye.now);var r=e.call(this,t,n)||this;return r.actions=[],r._active=!1,r._scheduled=void 0,r}return s(t,e),t.prototype.flush=function(e){var t=this.actions;if(this._active)t.push(e);else{var n;this._active=!0;do{if(n=e.execute(e.state,e.delay))break}while(e=t.shift());if(this._active=!1,n){for(;e=t.shift();)e.unsubscribe();throw n}}},t}(ye))(pe),be=ve;function me(e){return e&&x(e.schedule)}function ge(e){return e instanceof Date&&!isNaN(e)}function _e(e){return me((t=e)[t.length-1])?e.pop():void 0;var t}function we(e,t,n,r,o){void 0===r&&(r=0),void 0===o&&(o=!1);var i=t.schedule((function(){n(),o?e.add(this.schedule(null,r)):this.unsubscribe()}),r);if(e.add(i),!o)return i}function Se(e){return I((function(t,n){var r,o=null,i=!1;o=t.subscribe(le(n,void 0,void 0,(function(s){r=ae(e(s,Se(e)(t))),o?(o.unsubscribe(),o=null,r.subscribe(n)):i=!0}))),i&&(o.unsubscribe(),o=null,r.subscribe(n))}))}function ke(e,t){return void 0===t&&(t=0),I((function(n,r){n.subscribe(le(r,(function(n){return we(r,e,(function(){return r.next(n)}),t)}),(function(){return we(r,e,(function(){return r.complete()}),t)}),(function(n){return we(r,e,(function(){return r.error(n)}),t)})))}))}function xe(e,t){return void 0===t&&(t=0),I((function(n,r){r.add(e.schedule((function(){return n.subscribe(r)}),t))}))}function Ie(e,t){if(!e)throw new Error("Iterable cannot be null");return new Z((function(n){we(n,t,(function(){var r=e[Symbol.asyncIterator]();we(n,t,(function(){r.next().then((function(e){e.done?n.complete():n.next(e.value)}))}),0,!0)}))}))}function Ee(e,t){if(null!=e){if(ee(e))return function(e,t){return ae(e).pipe(xe(t),ke(t))}(e,t);if(E(e))return function(e,t){return new Z((function(n){var r=0;return t.schedule((function(){r===e.length?n.complete():(n.next(e[r++]),n.closed||this.schedule())}))}))}(e,t);if(O(e))return function(e,t){return ae(e).pipe(xe(t),ke(t))}(e,t);if(te(e))return Ie(e,t);if(oe(e))return function(e,t){return new Z((function(n){var r;return we(n,t,(function(){r=e[re](),we(n,t,(function(){var e,t,o;try{t=(e=r.next()).value,o=e.done}catch(e){return void n.error(e)}o?n.complete():n.next(t)}),0,!0)})),function(){return x(null==r?void 0:r.return)&&r.return()}}))}(e,t);if(se(e))return function(e,t){return Ie(ie(e),t)}(e,t)}throw ne(e)}function Oe(e,t){return t?Ee(e,t):ae(e)}function Te(e,t){return I((function(n,r){var o=0;n.subscribe(le(r,(function(n){r.next(e.call(t,n,o++))})))}))}function Ce(e,t,n){return void 0===n&&(n=1/0),x(t)?Ce((function(n,r){return Te((function(e,o){return t(n,e,r,o)}))(ae(e(n,r)))}),n):("number"==typeof t&&(n=t),I((function(t,r){return function(e,t,n,r,o,i,s,a){var c=[],l=0,u=0,d=!1,f=function(){!d||c.length||l||t.complete()},p=function(e){return l<r?h(e):c.push(e)},h=function(e){i&&t.next(e),l++;var a=!1;ae(n(e,u++)).subscribe(le(t,(function(e){null==o||o(e),i?p(e):t.next(e)}),(function(){a=!0}),void 0,(function(){if(a)try{l--;for(var e=function(){var e=c.shift();s?we(t,s,(function(){return h(e)})):h(e)};c.length&&l<r;)e();f()}catch(e){t.error(e)}})))};return e.subscribe(le(t,p,(function(){d=!0,f()}))),function(){null==a||a()}}(t,r,e,n)})))}function Ae(){return void 0===(e=1)&&(e=1/0),Ce(Y,e);var e}function je(e,t){return void 0===t&&(t=ve),I((function(n,r){var o=null,i=null,s=null,a=function(){if(o){o.unsubscribe(),o=null;var e=i;i=null,r.next(e)}};function c(){var n=s+e,i=t.now();if(i<n)return o=this.schedule(void 0,n-i),void r.add(o);a()}n.subscribe(le(r,(function(n){i=n,s=t.now(),o||(o=t.schedule(c,e),r.add(o))}),(function(){a(),r.complete()}),void 0,(function(){i=o=null})))}))}function Pe(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ae()(Oe(e,_e(e)))}var Ue=new Z((function(e){return e.complete()}));function $e(e){return e<=0?function(){return Ue}:I((function(t,n){var r=0;t.subscribe(le(n,(function(t){++r<=e&&(n.next(t),e<=r&&n.complete())})))}))}function De(e,t){return t?function(n){return Pe(t.pipe($e(1),I((function(e,t){e.subscribe(le(t,R))}))),n.pipe(De(e)))}:Ce((function(t,n){return e(t,n).pipe($e(1),function(e){return Te((function(){return e}))}(t))}))}function Ne(e,t){void 0===t&&(t=ve);var n=function(e,t,n){void 0===e&&(e=0),void 0===n&&(n=be);var r=-1;return null!=t&&(me(t)?n=t:r=t),new Z((function(t){var o=ge(e)?+e-n.now():e;o<0&&(o=0);var i=0;return n.schedule((function(){t.closed||(t.next(i++),0<=r?this.schedule(void 0,r):t.complete())}),o)}))}(e,t);return De((function(){return n}))}function Re(e,t){return void 0===t&&(t=Y),e=null!=e?e:Le,I((function(n,r){var o,i=!0;n.subscribe(le(r,(function(n){var s=t(n);!i&&e(o,s)||(i=!1,o=s,r.next(n))})))}))}function Le(e,t){return e===t}function Be(e,t){return I((function(n,r){var o=0;n.subscribe(le(r,(function(n){return e.call(t,n,o++)&&r.next(n)})))}))}function We(e){return Be((function(t,n){return e<=n}))}function Me(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=_e(e);return I((function(t,r){(n?Pe(e,t,n):Pe(e,t)).subscribe(r)}))}function Fe(e,t){return I((function(n,r){var o=null,i=0,s=!1,a=function(){return s&&!o&&r.complete()};n.subscribe(le(r,(function(n){null==o||o.unsubscribe();var s=0,c=i++;ae(e(n,c)).subscribe(o=le(r,(function(e){return r.next(t?t(n,e,c,s++):e)}),(function(){o=null,a()})))}),(function(){s=!0,a()})))}))}function He(e,t,n){var r=x(e)||t||n?{next:e,error:t,complete:n}:e;return r?I((function(e,t){var n;null===(n=r.subscribe)||void 0===n||n.call(r);var o=!0;e.subscribe(le(t,(function(e){var n;null===(n=r.next)||void 0===n||n.call(r,e),t.next(e)}),(function(){var e;o=!1,null===(e=r.complete)||void 0===e||e.call(r),t.complete()}),(function(e){var n;o=!1,null===(n=r.error)||void 0===n||n.call(r,e),t.error(e)}),(function(){var e,t;o&&(null===(e=r.unsubscribe)||void 0===e||e.call(r)),null===(t=r.finalize)||void 0===t||t.call(r)})))})):Y}var Ke=T((function(e){return function(t){void 0===t&&(t=null),e(this),this.message="Timeout has occurred",this.name="TimeoutError",this.info=t}}));function Ve(e){throw new Ke(e)}let ze=!1;function qe(e,t){return a(this,void 0,void 0,(function*(){try{const n=yield navigator.serviceWorker.ready;if("push"===t&&n.sync&&(yield n.sync.register(`dexie-cloud:${e.name}`)),!n.active)throw new Error("Failed to trigger sync - there's no active service worker");return void n.active.postMessage({type:"dexie-cloud-sync",dbName:e.name,purpose:t})}catch(e){ze||(console.debug("Dexie Cloud: Could not register sync event",e),ze=!0)}}))}function Je(e,t){e.cloud.usingServiceWorker?qe(e,t):e.localSyncEvent.next({purpose:t})}const Ge="undefined"!=typeof Buffer?e=>Buffer.from(e,"base64"):e=>{const t=atob(e),n=t.length,r=new Uint8Array(n);for(var o=0;o<n;o++)r[o]=t.charCodeAt(o);return r},Ye="undefined"!=typeof Buffer?e=>ArrayBuffer.isView(e)?Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"):Buffer.from(e).toString("base64"):e=>btoa(String.fromCharCode.apply(null,ArrayBuffer.isView(e)?e:new Uint8Array(e)));function Qe(e,t){return new Promise(((n,r)=>{const i=Object.assign(Object.assign({},t),{onSubmit:t=>{e.next(void 0),n(t)},onCancel:()=>{e.next(void 0),r(new o.default.AbortError("User cancelled"))}});e.next(i)}))}function Ze(e,t,...n){return Qe(e,{type:"message-alert",title:t,alerts:n,fields:{}})}function Xe(e,t,n){return a(this,void 0,void 0,(function*(){let r=n||"";for(;!r||!/^[\w-\.]+@([\w-]+\.)+[\w-]{2,10}$/.test(r);)r=(yield Qe(e,{type:"email",title:t,alerts:r?[{type:"error",messageCode:"INVALID_EMAIL",message:"Please enter a valid email address",messageParams:{}}]:[],fields:{email:{type:"email",placeholder:"you@somedomain.com"}}})).email;return r}))}function et(e,t,n){return a(this,void 0,void 0,(function*(){const r=[{type:"info",messageCode:"OTP_SENT",message:"A One-Time password has been sent to {email}",messageParams:{email:t}}];n&&r.push(n);const{otp:o}=yield Qe(e,{type:"otp",title:"Enter OTP",alerts:r,fields:{otp:{type:"otp",label:"OTP",placeholder:"Paste OTP here"}}});return o}))}function tt(e,t,n,r,o){return a(this,void 0,void 0,(function*(){return t.accessToken&&t.accessTokenExpiration.getTime()>Date.now()?t:t.refreshToken&&(!t.refreshTokenExpiration||t.refreshTokenExpiration.getTime()>Date.now())?yield nt(e,t):yield function(e,t,n,r){return a(this,void 0,void 0,(function*(){if(!crypto.subtle)throw"undefined"!=typeof location&&"http:"===location.protocol?new Error("Dexie Cloud Addon needs to use WebCrypto, but your browser has disabled it due to being served from an insecure location. Please serve it from https or http://localhost:<port> (See https://stackoverflow.com/questions/46670556/how-to-enable-crypto-subtle-for-unsecure-origins-in-chrome/46671627#46671627)"):new Error("This browser does not support WebCrypto.");const{privateKey:o,publicKey:i}=yield crypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!1,["sign","verify"]);if(!o||!i)throw new Error("Could not generate RSA keypair");e.nonExportablePrivateKey=o;const s=function(e){const t=Ye(e);return function(e){let t="-----BEGIN PUBLIC KEY-----\n";for(;e.length>0;)t+=e.substring(0,64)+"\n",e=e.substring(64);return t+="-----END PUBLIC KEY-----",t}(t)}(yield crypto.subtle.exportKey("spki",i));e.publicKey=i;try{const o=yield t({public_key:s,hints:r});if("tokens"!==o.type)throw new Error(`Unexpected response type from token endpoint: ${o.type}`);return e.accessToken=o.accessToken,e.accessTokenExpiration=new Date(o.accessTokenExpiration),e.refreshToken=o.refreshToken,o.refreshTokenExpiration&&(e.refreshTokenExpiration=new Date(o.refreshTokenExpiration)),e.userId=o.claims.sub,e.email=o.claims.email,e.name=o.claims.name,e.claims=o.claims,o.alerts&&o.alerts.length>0&&(yield Qe(n,{type:"message-alert",title:"Authentication Alert",fields:{},alerts:o.alerts})),e}catch(e){throw yield Ze(n,"Authentication Failed",{type:"error",messageCode:"GENERIC_ERROR",message:"We're having a problem authenticating right now.",messageParams:{}}).catch((()=>{})),e}}))}(t,n,r,o)}))}function nt(e,t){return a(this,void 0,void 0,(function*(){if(!t.refreshToken)throw new Error("Cannot refresh token - refresh token is missing.");if(!t.nonExportablePrivateKey)throw new Error("login.nonExportablePrivateKey is missing - cannot sign refresh token without a private key.");const n=Date.now(),r="RSASSA-PKCS1-v1_5",o=(new TextEncoder).encode(t.refreshToken+n),i=yield crypto.subtle.sign(r,t.nonExportablePrivateKey,o),s=Ye(i),a={grant_type:"refresh_token",refresh_token:t.refreshToken,scopes:["ACCESS_DB"],signature:s,signing_algorithm:r,time_stamp:n},c=yield fetch(`${e}/token`,{body:JSON.stringify(a),method:"post",headers:{"Content-Type":"application/json"},mode:"cors"});if(200!==c.status)throw new Error(`RefreshToken: Status ${c.status} from ${e}/token`);const l=yield c.json();return t.accessToken=l.accessToken,t.accessTokenExpiration=l.accessTokenExpiration?new Date(l.accessTokenExpiration):void 0,t}))}const rt=new WeakMap;class ot{constructor(e,t){rt.set(this,e),Object.assign(this,t)}static load(e,t){return e.table("$logins").get(t).then((n=>new ot(e,n||{userId:t,claims:{sub:t},lastLogin:new Date(0)})))}save(){return a(this,void 0,void 0,(function*(){rt.get(this).table("$logins").put(this)}))}}class it extends Error{constructor(e,t){super(t||`${e.status} ${e.statusText}`),this.httpStatus=e.status}get name(){return"HttpError"}}function st(e,t){return a(this,void 0,void 0,(function*(){if((yield e.getCurrentUser()).isLoggedIn){if(t){if(t.email&&e.cloud.currentUser.value.email!==t.email)throw new Error("Must logout before changing user");if(t.userId&&e.cloud.currentUserId!==t.userId)throw new Error("Must logout before changing user")}return!1}const n=new ot(e,{claims:{},lastLogin:new Date(0)});yield tt(e.cloud.options.databaseUrl,n,e.cloud.options.fetchTokens||function(e){const{userInteraction:t}=e.cloud;return function({public_key:n,hints:r}){var o;return a(this,void 0,void 0,(function*(){let i;const s=null===(o=e.cloud.options)||void 0===o?void 0:o.databaseUrl;if(!s)throw new Error("No database URL given.");i="demo"===(null==r?void 0:r.grant_type)?{demo_user:yield Xe(t,"Enter a demo user email",(null==r?void 0:r.email)||(null==r?void 0:r.userId)),grant_type:"demo",scopes:["ACCESS_DB"],public_key:n}:{email:yield Xe(t,"Enter email address",null==r?void 0:r.email),grant_type:"otp",scopes:["ACCESS_DB"],public_key:n};const a=yield fetch(`${s}/token`,{body:JSON.stringify(i),method:"post",headers:{"Content-Type":"application/json",mode:"cors"}});if(200!==a.status){const e=yield a.text();throw yield Ze(t,"Token request failed",{type:"error",messageCode:"GENERIC_ERROR",message:e,messageParams:{}}).catch((()=>{})),new it(a,e)}const c=yield a.json();if("tokens"===c.type)return c;if("otp"===i.grant_type){if("otp-sent"!==c.type)throw new Error(`Unexpected response from ${s}/token`);const e=yield et(t,i.email);i.otp=e||"",i.otp_id=c.otp_id;let n=yield fetch(`${s}/token`,{body:JSON.stringify(i),method:"post",headers:{"Content-Type":"application/json"},mode:"cors"});for(;401===n.status;){const e=yield n.text();i.otp=yield et(t,i.email,{type:"error",messageCode:"INVALID_OTP",message:e,messageParams:{}}),n=yield fetch(`${s}/token`,{body:JSON.stringify(i),method:"post",headers:{"Content-Type":"application/json"},mode:"cors"})}if(200!==n.status){const e=yield n.text();throw yield Ze(t,"OTP Authentication Failed",{type:"error",messageCode:"GENERIC_ERROR",message:e,messageParams:{}}).catch((()=>{})),new it(n,e)}return yield n.json()}throw new Error(`Unexpected response from ${s}/token`)}))}}(e),e.cloud.userInteraction,t);try{yield n.save()}catch(e){try{"DataCloneError"===e.name&&(console.debug("Login context property names:",Object.keys(n)),console.debug("Login context:",n),console.debug("Login context JSON:",JSON.stringify(n)))}catch(e){}throw e}return yield function(e,t){return a(this,void 0,void 0,(function*(){if(t.userId===e.cloud.currentUserId)return;const n=e.table("$logins");yield e.transaction("rw",n,(e=>a(this,void 0,void 0,(function*(){const e=yield n.toArray();yield Promise.all(e.filter((e=>e.userId!==t.userId&&e.isLoggedIn)).map((e=>(e.isLoggedIn=!1,n.put(e))))),t.isLoggedIn=!0,t.lastLogin=new Date,yield t.save(),console.debug("Saved new user",t.email)})))),yield new Promise((n=>{if(e.cloud.currentUserId===t.userId)n(null);else{const r=e.cloud.currentUser.subscribe((e=>{e.userId===t.userId&&(r.unsubscribe(),n(null))}))}}))}))}(e,n),Je(e,"pull"),!0}))}const at={userId:"unauthorized",name:"Unauthorized",claims:{sub:"unauthorized"},lastLogin:new Date(0)};try{Object.freeze(at),Object.freeze(at.claims)}catch(e){}const ct={},lt="undefined"!=typeof self&&self.document&&"undefined"!=typeof navigator&&navigator.serviceWorker;lt&&lt.ready.then((e=>ct.registration=e)),"undefined"!=typeof self&&"clients"in self&&!self.document&&addEventListener("message",(e=>{var t,n;(null===(n=null===(t=e.data)||void 0===t?void 0:t.type)||void 0===n?void 0:n.startsWith("sw-broadcast-"))&&[...self.clients.matchAll({includeUncontrolled:!0})].forEach((t=>{var n;return t.id!==(null===(n=e.source)||void 0===n?void 0:n.id)&&t.postMessage(e.data)}))}));class ut{constructor(e){this.name=e}subscribe(e){if(!lt)return()=>{};const t=t=>{var n;(null===(n=t.data)||void 0===n?void 0:n.type)===`sw-broadcast-${this.name}`&&e(t.data.message)};return lt.addEventListener("message",t),()=>lt.removeEventListener("message",t)}postMessage(e){var t;"object"==typeof self.clients?[...self.clients.matchAll({includeUncontrolled:!0})].forEach((t=>t.postMessage({type:`sw-broadcast-${this.name}`,message:e}))):ct.registration&&(null===(t=ct.registration.active)||void 0===t||t.postMessage({type:`sw-broadcast-${this.name}`,message:e}))}}const dt=globalThis["lbc-events"]||(globalThis["lbc-events"]=new Map);class ft extends n.Observable{constructor(e){const t="undefined"==typeof BroadcastChannel?new ut(e):new BroadcastChannel(e);super((n=>{function r(e){n.next(e.detail)}function o(e){console.debug("BroadcastedAndLocalEvent: onMessageEvent",e),n.next(e.data)}let i;!function(e,t){dt.has(e)?dt.get(e).push(t):dt.set(e,[t])}(`lbc-${e}`,r);try{t instanceof ut?i=t.subscribe((e=>n.next(e))):(console.debug("BroadcastedAndLocalEvent: bc.addEventListener()",e,"bc is a",t),t.addEventListener("message",o))}catch(e){console.warn("Failed to subscribe to broadcast channel",e)}return()=>{!function(e,t){const n=dt.get(e);if(n){const e=n.indexOf(t);-1!==e&&n.splice(e,1)}}(`lbc-${e}`,r),t instanceof ut?i():t.removeEventListener("message",o)}})),this.name=e,this.bc=t}next(e){console.debug("BroadcastedAndLocalEvent: bc.postMessage()",Object.assign({},e),"bc is a",this.bc),this.bc.postMessage(e);!function(e){const t=dt.get(e.type);t&&t.forEach((t=>{try{t(e)}catch(e){}}))}(new CustomEvent(`lbc-${this.name}`,{detail:e}))}}function pt({realms:e,inviteRealms:t}){return a(this,void 0,void 0,(function*(){const n=JSON.stringify([...e.map((e=>({realmId:e,accepted:!0}))),...t.map((e=>({realmId:e,accepted:!1})))].sort(((e,t)=>e.realmId<t.realmId?-1:e.realmId>t.realmId?1:0))),r=(new TextEncoder).encode(n),o=yield crypto.subtle.digest("SHA-1",r);return Ye(o)}))}function ht(e){return Object.entries(e.cloud.schema||{}).filter((([,{markedForSync:e}])=>e)).map((([t])=>e.tables.filter((({name:e})=>e===t))[0])).filter((e=>e))}function yt(e){return`$${e}_mutations`}function vt(e){var t;const n=null===(t=/^\$(.*)_mutations$/.exec(e))||void 0===t?void 0:t[1];if(!n)throw new Error(`Given mutationTable ${e} is not correct`);return n}const bt=[].concat;function mt(e){return bt.apply([],e)}function gt(e,t,{since:n={},limit:r=1/0}={}){return a(this,void 0,void 0,(function*(){const t=mt(yield Promise.all(e.map((e=>a(this,void 0,void 0,(function*(){const t=vt(e.name),o=n[t];let i=o?e.where("rev").above(o):e;r<1/0&&(i=i.limit(r));return(yield i.toArray()).map((e=>({table:t,mut:e})))})))))).sort(((e,t)=>e.mut.txid===t.mut.txid?e.mut.opNo-t.mut.opNo:e.mut.ts-t.mut.ts)),o=[];let i=null,s=null;for(const{table:e,mut:n}of t)i&&i.table===e&&s===n.txid?i.muts.push(n):(i={table:e,muts:[n]},s=n.txid,o.push(i));return o}))}function _t(e){const t=new Uint8Array(e);if("undefined"!=typeof crypto)crypto.getRandomValues(t);else for(let n=0;n<e;n++)t[n]=Math.floor(256*Math.random());if("undefined"!=typeof Buffer&&Buffer.from)return Buffer.from(t).toString("base64");if("undefined"!=typeof btoa)return btoa(String.fromCharCode.apply(null,t));throw new Error("No btoa or Buffer available")}const{toString:wt}={};const St={replace:function(e){const t=Object.keys(e);let n=null;for(let e=0,r=t.length;e<r;++e)"$"===t[e][0]&&(n=n||[],n.push(t[e]));if(!n)return e;const r={...e};for(const e of n)delete r[e];for(const t of n)r["$"+t]=e[t];return r}};function kt(...e){const t=e.reduce(((e,t)=>({...e,...t})),e.reduce(((e,t)=>({...t,...e})),{})),n=new WeakMap;return{stringify(e,r,o){const i=JSON.stringify(e,(function(e){const o=this[e],i=function(e){const r=typeof e;switch(typeof e){case"object":case"function":{if(null===e)return null;const r=Object.getPrototypeOf(e);if(!r)return St;let i=n.get(r);if(void 0!==i)return i;const s=(o=e,wt.call(o).slice(8,-1)),a=Object.entries(t).find((([t,n])=>{var r,o;return null!==(o=null===(r=null==n?void 0:n.test)||void 0===r?void 0:r.call(n,e,s))&&void 0!==o?o:t===s}));return i=null==a?void 0:a[1],i||(i=Array.isArray(e)?null:"function"==typeof e?t.function||null:St),n.set(r,i),i}default:return t[r]}var o}(o);return i?i.replace(o,r,t):o}),o);return i},parse(e,n){const r=[];return JSON.parse(e,(function(e,o){const i=null==o?void 0:o.$t;if(i){const e=t[i];o=e?e.revive(o,n,t):o}let s=r[r.length-1];if(s&&s[0]===o){o={...o};for(const e of s[1])delete o[e];for(const[e,t]of Object.entries(s[2]))o[e]=t;r.pop()}if(void 0===o||"$"===e[0]&&"$t"!==e){let t,n;s=r[r.length-1],s&&s[0]===this?(t=s[1],n=s[2]):r.push([this,t=[],n={}]),"$"===e[0]&&"$t"!==e?(t.push(e),n[e.substr(1)]=o):n[e]=void 0}return o}))}}}const xt={Blob:{test:(e,t)=>"Blob"===t,replace:(e,t)=>{const n=t.length;return t.push(e),{$t:"Blob",mimeType:e.type,i:n}},revive:({i:e,mimeType:t},n)=>new Blob([n[e]],{type:t})}};var It={number:{replace:e=>{switch(!0){case isNaN(e):return{$t:"number",v:"NaN"};case e===1/0:return{$t:"number",v:"Infinity"};case e===-1/0:return{$t:"number",v:"-Infinity"};default:return e}},revive:({v:e})=>Number(e)}};const Et={bigint:{replace:e=>({$t:"bigint",v:""+e}),revive:e=>BigInt(e.v)}};var Ot={Date:{replace:e=>({$t:"Date",v:isNaN(e.getTime())?"NaN":e.toISOString()}),revive:({v:e})=>new Date("NaN"===e?NaN:Date.parse(e))}},Tt={Set:{replace:e=>({$t:"Set",v:Array.from(e.entries())}),revive:({v:e})=>new Set(e)}},Ct={Map:{replace:e=>({$t:"Map",v:Array.from(e.entries())}),revive:({v:e})=>new Map(e)}};const At="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"==typeof global?global:void 0;var jt=["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","DataView","BigInt64Array","BigUint64Array"].reduce(((e,t)=>({...e,[t]:{replace:(e,n,r)=>({$t:t,v:r.ArrayBuffer.replace(0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),n,r).v}),revive:({v:e},n,r)=>{const o=At[t];return o&&new o(r.ArrayBuffer.revive({v:e},n,r))}}})),{});function Pt(e){return function(e){for(var t="",n=0,r=e.length;n<r;n++)t+=Dt[e[n]];return t}(Ye(e))}function Ut(e){return Ge(function(e){if("string"!=typeof e)throw new Error("invalid decoder input: "+e);for(var t="",n=0,r=e.length;n<r;n++)t+=$t[e[n]];return t}(e))}const $t={"-":"=",0:"A",1:"B",2:"C",3:"D",4:"E",5:"F",6:"G",7:"H",8:"I",9:"J",A:"K",B:"L",C:"M",D:"N",E:"O",F:"P",G:"Q",H:"R",I:"S",J:"T",K:"U",L:"V",M:"W",N:"X",O:"Y",P:"Z",Q:"a",R:"b",S:"c",T:"d",U:"e",V:"f",W:"g",X:"h",Y:"i",Z:"j",_:"k",a:"l",b:"m",c:"n",d:"o",e:"p",f:"q",g:"r",h:"s",i:"t",j:"u",k:"v",l:"w",m:"x",n:"y",o:"z",p:"0",q:"1",r:"2",s:"3",t:"4",u:"5",v:"6",w:"7",x:"8",y:"9",z:"+","|":"/"},Dt={};for(const e of Object.keys($t))Dt[$t[e]]=e;var Nt={ArrayBuffer:{replace:e=>({$t:"ArrayBuffer",v:Pt(e)}),revive:({v:e})=>{const t=Ut(e);return t.buffer.byteLength===t.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}}};class Rt{constructor(e,t){this.buf=e,this.type=t}}function Lt(e){const t=new XMLHttpRequest;if(t.overrideMimeType("text/plain; charset=x-user-defined"),t.open("GET",URL.createObjectURL(e),!1),t.send(),200!==t.status&&0!==t.status)throw new Error("Bad Blob access: "+t.status);return t.responseText}function Bt(e){const t=new Uint8Array(e.length);for(let n=0;n<e.length;++n)t[n]=e.charCodeAt(n);return t.buffer}var Wt={Blob:{test:(e,t)=>"Blob"===t||e instanceof Rt,replace:e=>({$t:"Blob",v:Ye(e instanceof Rt?e.buf:Bt(Lt(e))),type:e.type}),revive:({type:e,v:t})=>{const n=Ge(t);return void 0!==typeof Blob?new Blob([n]):new Rt(n.buffer,e)}}};const Mt={...It,...Et,...Ot,...Tt,...Ct,...jt,...Nt,...Wt};function Ft(e){return new Promise(((t,n)=>{const r=new FileReader;r.onabort=e=>n(new Error("file read aborted")),r.onerror=e=>n(e.target.error),r.onload=e=>t(e.target.result),r.readAsArrayBuffer(e)}))}var Ht={undefined:{replace:()=>({$t:"undefined"}),revive:()=>{}}};const Kt="function"==typeof BigInt&&"bigint"==typeof BigInt(0);class Vt{toString(){return this.v}constructor(e){this.v=e}}const zt=Object.assign(Object.assign({},Ht),Kt?{}:{bigint:{test:e=>e instanceof Vt,replace:e=>Object.assign({$t:"bigint"},e),revive:({v:e})=>new Vt(e)}}),qt=kt(Mt,zt),Jt=function(...e){const t=kt(Mt,xt,...e);return{toBinary(e){const[t,n]=this.stringify(e),r=new ArrayBuffer(4);return new DataView(r).setUint32(0,t.size),new Blob([r,t,n])},stringify(e){const n=[],r=t.stringify(e,n),o=new Blob(n.map((e=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,"byteLength"in e?e.byteLength:e.size),new Blob([t,e])})));return[o,r]},async parse(e,n){let r=0;const o=[],i=await Ft(n),s=new DataView(i);for(;r<i.byteLength;){const e=s.getUint32(r);r+=4;const t=i.slice(r,r+e);r+=e,o.push(t)}return t.parse(e,o)},async fromBinary(e){const t=new DataView(await Ft(e.slice(0,4))).getUint32(0),n=e.slice(4,t+4),r=await function(e){return new Promise(((t,n)=>{const r=new FileReader;r.onabort=e=>n(new Error("file read aborted")),r.onerror=e=>n(e.target.error),r.onload=e=>t(e.target.result),r.readAsText(e)}))}(e.slice(t+4));return await this.parse(r,n)}}}(zt);function Gt(e,t,n){const r=[];for(let i of n){const{table:n,muts:s}=i,a=e.tables.find((e=>e.name===n));if(!a)throw new Error(`Internal error: table ${n} not found in DBCore schema`);const{primaryKey:c}=a;let l=i;s.forEach(((e,n)=>{const r=!c.outbound&&("upsert"===e.type||"insert"===e.type);e.keys.forEach(((e,s)=>{if(Array.isArray(e)){l===i&&(l=Yt(i,r));const t=l.muts[n],o=JSON.stringify(e);t.keys[s]=o}else if("#"===e[0]){l===i&&(l=Yt(i,r));const a=l.muts[n];if(!t.isLoggedIn)throw new Error("Internal error: Cannot sync private IDs before authenticated");const u=`${e}:${t.userId}`;a.keys[s]=u,r&&o.default.setByKeyPath(a.values[s],c.keyPath,u)}}))})),r.push(l)}return r}function Yt(e,t){return Object.assign(Object.assign({},e),{muts:t?e.muts.map((e=>"insert"!==e.type&&"upsert"!==e.type||!e.values?Object.assign(Object.assign({},e),{keys:e.keys.slice()}):Object.assign(Object.assign({},e),{keys:e.keys.slice(),values:e.values.slice()}))):e.muts.map((e=>Object.assign(Object.assign({},e),{keys:e.keys.slice()})))})}function Qt(e,t,n,r,o,i,s,c){return a(this,void 0,void 0,(function*(){const l={Accept:"application/json, application/x-bison, application/x-bison-stream","Content-Type":"application/tson"},u=yield function(e){var t,n;return a(this,void 0,void 0,(function*(){const r=yield e.getCurrentUser(),{accessToken:o,accessTokenExpiration:i,refreshToken:s,refreshTokenExpiration:a,claims:c}=r;if(!o)return;if((null!==(t=null==i?void 0:i.getTime())&&void 0!==t?t:1/0)>Date.now())return o;if(!s)throw new Error("Refresh token missing");if((null!==(n=null==a?void 0:a.getTime())&&void 0!==n?n:1/0)<=Date.now())throw new Error("Refresh token has expired");const l=yield nt(e.cloud.options.databaseUrl,r);return yield e.table("$logins").update(c.sub,{accessToken:l.accessToken,accessTokenExpiration:l.accessTokenExpiration}),l.accessToken}))}(r);u&&(l.Authorization=`Bearer ${u}`);const d={v:2,dbID:null==t?void 0:t.remoteDbId,clientIdentity:s,schema:i||{},lastPull:t?{serverRevision:t.serverRevision,realms:t.realms,inviteRealms:t.inviteRealms}:void 0,baseRevs:n,changes:Gt(r.dx.core.schema,c,e)};console.debug("Sync request",d),r.syncStateChangedEvent.next({phase:"pushing"});const f=yield fetch(`${o}/sync`,{method:"post",headers:l,body:qt.stringify(d)});if(r.syncStateChangedEvent.next({phase:"pulling"}),!f.ok)throw new it(f);if("application/x-bison"===f.headers.get("content-type"))return Jt.fromBinary(yield f.blob());{const e=yield f.text();return qt.parse(e)}}))}function Zt(e){if(null==e?void 0:e.cancelled)throw new o.default.AbortError("Operation was cancelled")}let Xt=!1;function en(e,t,n,r){return a(this,void 0,void 0,(function*(){yield e.$baseRevs.bulkPut(Object.keys(t).filter((e=>t[e].markedForSync)).map((e=>({tableName:e,clientRev:(n[e]||0)+1,serverRev:r}))))}))}function tn(e,t={}){for(const{table:n,muts:r}of e){const e=r.length>0?r[r.length-1].rev:null;t[n]=e||t[n]||0}return t}function nn(e,n,r){return a(this,void 0,void 0,(function*(){const i=yield e.bulkGet(n),s=[],a=[];n.forEach(((n,c)=>{const l=i[c];if(l){for(const[i,s]of Object.entries(r[c]))if(i===e.schema.primKey.keyPath){if(0!==t.cmp(s,n))throw new Error("Cannot change primary key")}else o.default.setByKeyPath(l,i,s);s.push(n),a.push(l)}})),yield null==e.schema.primKey.keyPath?e.bulkPut(a,s):e.bulkPut(a)}))}function rn(e,t){return a(this,void 0,void 0,(function*(){console.debug("Applying server changes",e,o.default.currentTransaction);for(const{table:n,muts:r}of e){const e=t.table(n);if(!e)continue;const{primaryKey:i}=e.core.schema,s=e=>{switch(e[0]){case"[":if(e.endsWith("]"))try{return JSON.parse(e)}catch(e){}return e;case"#":return e.endsWith(":"+t.cloud.currentUserId)?e.substr(0,e.length-t.cloud.currentUserId.length-1):e;default:return e}};for(const t of r){const n=t.keys.map(s);switch(t.type){case"insert":i.outbound?yield e.bulkAdd(t.values,n):(n.forEach(((e,n)=>{o.default.setByKeyPath(t.values[n],i.keyPath,e)})),yield e.bulkAdd(t.values));break;case"upsert":i.outbound?yield e.bulkPut(t.values,n):(n.forEach(((e,n)=>{o.default.setByKeyPath(t.values[n],i.keyPath,e)})),yield e.bulkPut(t.values));break;case"modify":1===n.length?yield e.update(n[0],t.changeSpec):yield e.where(":id").anyOf(n).modify(t.changeSpec);break;case"update":yield nn(e,n,t.changeSpecs);break;case"delete":yield e.bulkDelete(n)}}}}))}"undefined"!=typeof self&&"undefined"!=typeof navigator&&(Xt=navigator.onLine,self.addEventListener("online",(()=>Xt=!0)),self.addEventListener("offline",(()=>Xt=!1)));function on(e,t,n,r){return sn.apply(this,arguments).then((()=>{(null==r?void 0:r.justCheckIfNeeded)||e.syncStateChangedEvent.next({phase:"in-sync"})})).catch((o=>a(this,void 0,void 0,(function*(){return(null==r?void 0:r.justCheckIfNeeded)?Promise.reject(o):(console.debug("Error from _sync",{isOnline:Xt,syncOptions:r,error:o}),Xt&&(null==r?void 0:r.retryImmediatelyOnFetchError)&&"TypeError"===(null==o?void 0:o.name)&&/fetch/.test(null==o?void 0:o.message)?(e.syncStateChangedEvent.next({phase:"error",error:o}),yield new Promise((e=>setTimeout(e,500))),yield on(e,t,n,Object.assign(Object.assign({},r),{retryImmediatelyOnFetchError:!1}))):(yield e.$syncState.update("syncState",{timestamp:new Date,error:""+o}),e.syncStateChangedEvent.next({phase:Xt?"error":"offline",error:new Error(""+(null==o?void 0:o.message)||o)}),Promise.reject(o)))}))))}function sn(e,t,n,{isInitialSync:r,cancelToken:o,justCheckIfNeeded:i,purpose:s}={isInitialSync:!1}){var c;return a(this,void 0,void 0,(function*(){if(i||console.debug("SYNC STARTED",{isInitialSync:r,purpose:s}),!(null===(c=e.cloud.options)||void 0===c?void 0:c.databaseUrl))throw new Error("Internal error: sync must not be called when no databaseUrl is configured");const{databaseUrl:l}=t,u=yield e.getCurrentUser(),d=u.isLoggedIn?ht(e):[],f=d.map((t=>e.table(yt(t.name)))),p=yield e.getPersistedSyncState(),h=!r&&u.isLoggedIn,y=h?function(e,t){const n=(null==t?void 0:t.syncedTables)||[];return ht(e).filter((e=>!n.includes(e.name)))}(e,p):[];Zt(o);const v=y.length>0;if(v){if(i)return!0;yield e.transaction("rw",y,(e=>a(this,void 0,void 0,(function*(){e.idbtrans.disableChangeTracking=!0,e.idbtrans.disableAccessControl=!0,yield function(e,t,n){return a(this,void 0,void 0,(function*(){const r=new Set(n||[]);for(const n of e)"members"===n.name?yield n.toCollection().modify((e=>{r.has(e.realmId)||e.userId&&e.userId!==at.userId||(e.userId=t.userId)})):"roles"===n.name||("realms"===n.name?yield n.toCollection().modify((e=>{r.has(e.realmId)||void 0!==e.owner&&e.owner!==at.userId||(e.owner=t.userId)})):yield n.toCollection().modify((e=>{e.realmId&&r.has(e.realmId)||(e.owner&&e.owner!==at.userId||(e.owner=t.userId),e.realmId&&e.realmId!==at.userId||(e.realmId=t.userId))})))}))}(y,u,null==p?void 0:p.realms)})))),Zt(o)}const[b,g,w]=yield e.transaction("r",e.tables,(()=>a(this,void 0,void 0,(function*(){const t=yield e.getPersistedSyncState(),r=yield e.$baseRevs.toArray();let i=yield gt(f);if(Zt(o),v){const e=[...(null==p?void 0:p.realms)||[],...(null==p?void 0:p.inviteRealms)||[]],s=yield function(e,t,n,r){return a(this,void 0,void 0,(function*(){const o=`upload-${_t(8)}`;if(t.isLoggedIn&&e.length>0){const i=new Set(r||[]);return(yield Promise.all(e.map((e=>a(this,void 0,void 0,(function*(){const{extractKey:r}=e.core.schema.primaryKey;if(!r)return{table:e.name,muts:[]};const s=n[e.name],a=(null==s?void 0:s.generatedGlobalId)?e.filter((e=>{return r(e),!i.has(e.realmId||"")&&(t=r(e),!(n=null==s?void 0:s.idPrefix)||"string"==typeof t&&t.startsWith(n));var t,n})):e.filter((e=>{const t=r(e);return!i.has(e.realmId||"")&&_(t)})),c=yield a.toArray();if(c.length>0){const n={type:"upsert",values:c,keys:c.map(r),userId:t.userId,txid:o};return{table:e.name,muts:[n]}}return{table:e.name,muts:[]}})))))).filter((e=>e.muts.length>0))}return[]}))}(y,u,n,e);return Zt(o),i=i.concat(s),[i,t,r]}return[i,t,r]})))),S=b.some((e=>e.muts.some((e=>e.keys.length>0))));if(i)return console.debug("Sync is needed:",S),S;if("push"===s&&!S)return!1;const k=tn(b,null==g?void 0:g.latestRevisions),x=(null==g?void 0:g.clientIdentity)||m(16);Zt(o);const I=yield Qt(b,g,w,e,l,n,x,u);console.debug("Sync response",I);const E=yield e.transaction("rw",e.tables,(t=>a(this,void 0,void 0,(function*(){t.idbtrans.disableChangeTracking=!0,t.idbtrans.disableAccessControl=!0;for(const e of Object.keys(n))I.schema[e]&&(n[e]=I.schema[e]);yield e.$syncState.put(n,"schema");const r=yield gt(f,0,{since:k});for(const t of f){const n=vt(t.name);if(r.some((e=>e.table===n&&e.muts.length>0))){if(k[n]){const r=k[n]||0;yield Promise.all([t.where("rev").belowOrEqual(r).delete(),e.$baseRevs.where(":id").between([n,-1/0],[n,r+1],!0,!0).reverse().offset(1).delete()])}}else yield Promise.all([t.clear(),e.$baseRevs.where({tableName:n}).delete()])}tn(r,k),yield en(e,n,k,I.serverRevision);const o=yield e.getPersistedSyncState();yield function(e,t,n){return a(this,void 0,void 0,(function*(){const r=new Set,o=new Set,i=n?n.realms:[],s=n?n.inviteRealms:[],a=new Set(t.realms),c=new Set(t.realms.concat(t.inviteRealms));for(const e of i)a.has(e)||(o.add(e),c.has(e)||r.add(e));for(const e of s.concat(i))c.has(e)||r.add(e);if(r.size>0||o.size>0){const t=ht(e);for(const e of t){let t=["realms","members","roles"].includes(e.name)?r:o;0!==t.size&&(e.schema.indexes.some((e=>"realmId"===e.keyPath||Array.isArray(e.keyPath)&&"realmId"===e.keyPath[0]))?yield e.where("realmId").anyOf([...t]).delete():yield e.filter((e=>!!(null==e?void 0:e.realmId)&&t.has(e.realmId))).delete())}}}))}(e,I,o);const i=o||{syncedTables:[],latestRevisions:{},realms:[],inviteRealms:[],clientIdentity:x};h&&(i.syncedTables=d.map((e=>e.name)).concat(y.map((e=>e.name)))),i.latestRevisions=k,i.remoteDbId=I.dbId,i.initiallySynced=!0,i.realms=I.realms,i.inviteRealms=I.inviteRealms,i.serverRevision=I.serverRevision,i.timestamp=new Date,delete i.error;const s=an(I.changes,r);return yield rn(s,e),e.$syncState.put(i,"syncState"),0===r.length}))));return E?(console.debug("SYNC DONE",{isInitialSync:r}),e.syncCompleteEvent.next(),!1):(console.debug("MORE SYNC NEEDED. Go for it again!"),yield sn(e,t,n,{isInitialSync:r,cancelToken:o}))}))}function an(e,t){const n={};k(n,e);const r={};return k(r,t),function(e,t){var n,r,o;for(const[i,s]of Object.entries(t))for(const[t,a]of Object.entries(s))switch(a.type){case"ups":{const r=null===(n=e[i])||void 0===n?void 0:n[t];if(r)switch(r.type){case"ups":case"upd":delete e[i][t]}}break;case"del":null===(r=e[i])||void 0===r||delete r[t];break;case"upd":{const n=null===(o=e[i])||void 0===o?void 0:o[t];if(n)switch(n.type){case"ups":for(const[e,t]of Object.entries(a.mod))b(n.val,e,t);break;case"del":break;case"upd":for(const e of Object.keys(a.mod))delete n.mod[e]}break}}}(n,r),function(e,t=""){t||(t=m(16));const n={};for(const[t,r]of Object.entries(e))for(const[e,o]of Object.entries(r)){const r=n[t]||(n[t]={});(r[o.type]||(r[o.type]=[])).push(Object.assign({key:e},o))}const r=[];for(const[e,o]of Object.entries(n)){const n={table:e,muts:[]};for(const[e,r]of Object.entries(o))switch(e){case"ups":{const e={type:"upsert",keys:r.map((e=>e.key)),values:r.map((e=>e.val)),txid:t};n.muts.push(e);break}case"upd":{const e={type:"update",keys:r.map((e=>e.key)),changeSpecs:r.map((e=>e.mod)),txid:t};n.muts.push(e);break}case"del":{const e={type:"delete",keys:r.map((e=>e.key)),txid:t};n.muts.push(e);break}}r.push(n)}return r}(n)}function cn(e){const t=[],r=new n.BehaviorSubject(!0),i=new n.BehaviorSubject(null);let s=!1,c=0,l=[0,0,0,0,0,0,0,0,0,Date.now()];return i.subscribe((()=>a(this,void 0,void 0,(function*(){if(!s&&t.length>0){s=!0,l.shift(),l.push(Date.now()),r.next(!1);try{yield function(){var n,r,i,s,c,l;return a(this,void 0,void 0,(function*(){for(;t.length>0;){const u=t.shift();try{yield e.cloud.syncState.pipe(Be((({phase:e})=>"in-sync"===e||"error"===e)),$e(1)).toPromise(),console.debug("processing msg",u);const t=e.cloud.persistedSyncState.value;if(!u)continue;switch(u.type){case"token-expired":console.debug("WebSocket observable: Token expired. Refreshing token...");const d=e.cloud.currentUser.value,f=yield nt(e.cloud.options.databaseUrl,d);yield e.table("$logins").update(d.userId,{accessToken:f.accessToken,accessTokenExpiration:f.accessTokenExpiration});break;case"realm-added":(null===(n=null==t?void 0:t.realms)||void 0===n?void 0:n.includes(u.realm))||(null===(r=null==t?void 0:t.inviteRealms)||void 0===r?void 0:r.includes(u.realm))||(yield e.cloud.sync({purpose:"pull",wait:!0}));break;case"realm-accepted":(null===(i=null==t?void 0:t.realms)||void 0===i?void 0:i.includes(u.realm))||(yield e.cloud.sync({purpose:"pull",wait:!0}));break;case"realm-removed":((null===(s=null==t?void 0:t.realms)||void 0===s?void 0:s.includes(u.realm))||(null===(c=null==t?void 0:t.inviteRealms)||void 0===c?void 0:c.includes(u.realm)))&&(yield e.cloud.sync({purpose:"pull",wait:!0}));break;case"realms-changed":yield e.cloud.sync({purpose:"pull",wait:!0});break;case"changes":if(console.debug("changes"),"error"===(null===(l=e.cloud.syncState.value)||void 0===l?void 0:l.phase)){Je(e,"pull");break}yield e.transaction("rw",e.dx.tables,(t=>a(this,void 0,void 0,(function*(){t.idbtrans.disableChangeTracking=!0,t.idbtrans.disableAccessControl=!0;const[n,r,i]=yield Promise.all([e.getSchema(),e.getPersistedSyncState(),e.getCurrentUser()]);if(console.debug("ws message queue: in transaction"),!r||!n||!i)return void console.debug("required vars not present",{syncState:r,schema:n,currentUser:i});if(u.baseRev!==r.serverRevision)return console.debug(`baseRev (${u.baseRev}) differs from our serverRevision in syncState (${r.serverRevision})`),void("string"!=typeof u.baseRev||"bigint"!=typeof r.serverRevision&&"object"!=typeof r.serverRevision||Je(e,"pull"));const s=yield o.default.waitFor(pt(r));if(console.debug("ourRealmSetHash",s),s!==u.realmSetHash)return console.debug("not same realmSetHash",u.realmSetHash),void Je(e,"pull");let a=[];if(i.isLoggedIn){const t=ht(e).map((t=>e.table(yt(t.name))));a=yield gt(t),console.debug("msg queue: client changes",a)}if(u.changes.length>0){const t=an(u.changes,a);console.debug("applying filtered server changes",t),yield rn(t,e)}r.latestRevisions=tn(a,r.latestRevisions),r.serverRevision=u.newRev,console.debug("Updating baseRefs",r.latestRevisions),yield en(e,n,r.latestRevisions,u.newRev),console.debug("Updating syncState",r),yield e.$syncState.put(r,"syncState")})))),console.debug("msg queue: done with rw transaction")}}catch(e){console.error("Error in msg queue",e)}}}))}()}finally{l[l.length-1]-l[0]<1e4&&(Date.now()-c<5e3?(console.warn("Slowing down websocket loop for one minute"),c=Date.now()+6e4,yield new Promise((e=>setTimeout(e,6e4)))):(console.warn("Slowing down websocket loop for 10 seconds"),c=Date.now()+1e4,yield new Promise((e=>setTimeout(e,1e4))))),s=!1,r.next(!0)}}})))),{enqueue:function(e){t.push(e),i.next(null)},readyToServe:r}}const ln=new WeakMap,un={members:"@id, [userId+realmId], [email+realmId], realmId",roles:"[realmId+name]",realms:"@realmId",$jobs:"",$syncState:"",$baseRevs:"[tableName+clientRev]",$logins:"claims.sub, lastLogin"};let dn=0;function fn(e){"vip"in e&&(e=e.vip);let t=ln.get(e.cloud);if(!t){const r=new n.Subject;let o=new ft(`syncstatechanged-${e.name}`),i=new ft(`synccomplete-${e.name}`);r.id=++dn;let s=!1;t={get name(){return e.name},close:()=>e.close(),transaction:e.transaction.bind(e),table:e.table.bind(e),get tables(){return e.tables},cloud:e.cloud,get $jobs(){return e.table("$jobs")},get $syncState(){return e.table("$syncState")},get $baseRevs(){return e.table("$baseRevs")},get $logins(){return e.table("$logins")},get realms(){return e.realms},get members(){return e.members},get roles(){return e.roles},get initiallySynced(){return s},localSyncEvent:r,get syncStateChangedEvent(){return o},get syncCompleteEvent(){return i},dx:e};const a={getCurrentUser:()=>t.$logins.toArray().then((e=>e.find((e=>e.isLoggedIn))||at)),getPersistedSyncState:()=>t.$syncState.get("syncState"),getSchema:()=>t.$syncState.get("schema").then((e=>{if(e)for(const r of t.tables)r.schema.primKey&&r.schema.primKey.keyPath&&e[r.name]&&(e[r.name].primaryKey="string"==typeof(n=r.schema.primKey.keyPath)?n:n?"["+[].join.call(n,"+")+"]":"");var n;return e})),getOptions:()=>t.$syncState.get("options"),setInitiallySynced(e){s=e},reconfigure(){o=new ft(`syncstatechanged-${e.name}`),i=new ft(`synccomplete-${e.name}`)}};Object.assign(t,a),t.messageConsumer=cn(t),ln.set(e.cloud,t)}return t}const pn="undefined"!=typeof InstallTrigger,hn="undefined"!=typeof navigator&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\/|Edge\//.test(navigator.userAgent),yn=hn?[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]:NaN,vn=hn&&yn<=605||pn;const bn="undefined"!=typeof self&&"clients"in self&&!self.document;function mn(){throw new o.default.SchemaError("Version increment needed to allow dexie-cloud change tracking")}const{toString:gn}={};function _n(e){return gn.call(e).slice(8,-1)}function wn(e,t){var n;return"delete"===t.type?t.keys:(null===(n=t.keys)||void 0===n?void 0:n.slice())||t.values.map(e.extractKey)}const Sn=/b|c|d|f|g|h|j|k|l|m|n|p|q|r|s|t|v|x|y|z/i;let kn=0;function xn(e,t){const n=new Uint8Array(18),r=new Uint8Array(n.buffer,0,6),o=Date.now();kn>=o?++kn:kn=o,r[0]=kn/1099511627776,r[1]=kn/4294967296,r[2]=kn/16777216,r[3]=kn/65536,r[4]=kn/256,r[5]=kn;const i=new Uint8Array(n.buffer,6);crypto.getRandomValues(i);return e+Pt(new Uint8Array(n.buffer))+(t||"")}function In(e){return{stack:"dbcore",name:"idGenerationMiddleware",level:1,create:t=>Object.assign(Object.assign({},t),{table:n=>{const r=t.table(n);return Object.assign(Object.assign({},r),{mutate:t=>{var i,s;if(t.trans.disableChangeTracking)return r.mutate(t);if("add"===t.type||"put"===t.type){const a=null===(i=e.cloud.schema)||void 0===i?void 0:i[n];if(null==a?void 0:a.generatedGlobalId){if((null===(s=e.cloud.options)||void 0===s?void 0:s.databaseUrl)&&!e.initiallySynced){const e=wn(r.schema.primaryKey,t);return r.getMany({keys:e,trans:t.trans,cache:"immutable"}).then((n=>{if(n.length<e.length)throw new Error("Unable to create new objects without an initial sync having been performed.");return r.mutate(t)}))}return function(t,i){let s=null;const a=wn(r.schema.primaryKey,t);return a.forEach(((c,l)=>{if(void 0===c){const n=t.values[l].realmId||e.cloud.currentUserId,c=n.substr(n.length-3);a[l]=xn(i,c),r.schema.primaryKey.outbound||(s||(s=t.values.slice()),s[l]=o.default.deepClone(s[l]),o.default.setByKeyPath(s[l],r.schema.primaryKey.keyPath,a[l]))}else if("string"!=typeof c||!c.startsWith(i)&&!c.startsWith("#"+i))throw new o.default.ConstraintError(`The ID "${c}" is not valid for table "${n}". Primary '@' keys requires the key to be prefixed with "${i}" (or "#${i}).\nIf you want to generate IDs programmatically, remove '@' from the schema to get rid of this constraint. Dexie Cloud supports custom IDs as long as they are random and globally unique.`)})),r.mutate(Object.assign(Object.assign({},t),{keys:a,values:s||t.values}))}(t,a.idPrefix)}if(null==a?void 0:a.markedForSync){wn(r.schema.primaryKey,t).forEach(((e,t)=>{if(!_(e)){const t=Array.isArray(e)?e.map(_n).join(","):_n(e);throw new o.default.ConstraintError(`Invalid primary key type ${t} for table ${n}. Tables marked for sync has primary keys of type string or Array of string (and optional numbers)`)}}))}}return r.mutate(t)}})}})}}let En=0;function On(e,t){return function(n){const{readers:r,writers:o}=n.trans[t]||(n.trans[t]={writers:[],readers:[]}),i=o.length,s=(i>0?o[i-1].then((()=>e(n)),(()=>e(n))):e(n)).finally((()=>r.splice(r.indexOf(s))));return r.push(s),s}}function Tn(e,t){return function(n){const{readers:r,writers:o}=n.trans[t]||(n.trans[t]={writers:[],readers:[]});let i=(o.length>0?o[o.length-1].then((()=>e(n)),(()=>e(n))):r.length>0?(s=r,new Promise((e=>{0===s.length&&e([]);let t=s.length;const n=new Array(t);s.forEach(((r,o)=>Promise.resolve(r).then((e=>n[o]={status:"fulfilled",value:e}),(e=>n[o]={status:"rejected",reason:e})).then((()=>--t||e(n)))))}))).then((()=>e(n))):e(n)).finally((()=>o.shift()));var s;return o.push(i),i}}const Cn=new n.BehaviorSubject(new Set);function An({currentUserObservable:e,db:t}){return{stack:"dbcore",name:"MutationTrackingMiddleware",level:1,create:n=>{const r=n.schema.tables.filter((e=>!/^\$/.test(e.name)));let o;try{o=new Map(r.map((e=>[e.name,n.table(`$${e.name}_mutations`)])))}catch(e){mn()}return Object.assign(Object.assign({},n),{transaction:(r,o)=>{let i;if("readwrite"===o){const e=r.filter((e=>{var n,r;return null===(r=null===(n=t.cloud.schema)||void 0===n?void 0:n[e])||void 0===r?void 0:r.markedForSync})).map((e=>yt(e)));i=n.transaction([...r,...e],o)}else i=n.transaction(r,o);if("readwrite"===o){i.txid=_t(16),i.opCount=0,i.currentUser=e.value,Cn.value.add(i),Cn.next(Cn.value);const n=()=>{i.removeEventListener("complete",r),i.removeEventListener("error",n),i.removeEventListener("abort",n),Cn.value.delete(i),Cn.next(Cn.value)},r=()=>{var e;i.mutationsAdded&&(null===(e=t.cloud.options)||void 0===e?void 0:e.databaseUrl)&&(t.cloud.usingServiceWorker?(console.debug("registering sync event"),qe(t,"push")):t.localSyncEvent.next({purpose:"push"})),n()};i.addEventListener("complete",r),i.addEventListener("error",n),i.addEventListener("abort",n)}return i},table:e=>{const r=n.table(e);if(/^\$/.test(e))return e.endsWith("_mutations")?Object.assign(Object.assign({},r),{mutate:e=>("add"!==e.type&&"put"!==e.type||(e.trans.mutationsAdded=!0),r.mutate(e))}):"$logins"===e?Object.assign(Object.assign({},r),{mutate:e=>r.mutate(e).then((t=>(e.trans.mutationsAdded=!0,t))).catch((e=>(console.debug("Failed mutation $logins",e),Promise.reject(e))))}):r;const{schema:i}=r,s=o.get(e);return function(e){const t="$lock"+ ++En;return Object.assign(Object.assign({},e),{count:On(e.count,t),get:On(e.get,t),getMany:On(e.getMany,t),openCursor:On(e.openCursor,t),query:On(e.query,t),mutate:Tn(e.mutate,t)})}(Object.assign(Object.assign({},r),{mutate:n=>{var o,s,c;const l=n.trans;return l.txid?l.disableChangeTracking?r.mutate(n):(null===(s=null===(o=t.cloud.schema)||void 0===o?void 0:o[e])||void 0===s?void 0:s.markedForSync)&&(null===(c=l.currentUser)||void 0===c?void 0:c.isLoggedIn)?"deleteRange"===n.type?r.query({query:{range:n.range,index:i.primaryKey},trans:n.trans,values:!1}).then((e=>a({type:"delete",keys:e.result,trans:n.trans,criteria:{index:null,range:n.range}}))):a(n):r.mutate(n):r.mutate(n)}}));function a(e){const t=e.trans;t.mutationsAdded=!0;const{txid:n,currentUser:{userId:o}}=t,{type:i}=e,a=++t.opCount;return r.mutate(e).then((r=>{const{numFailures:c,failures:l}=r;let u="delete"===i?e.keys:r.results,d="values"in e?e.values:[],f="updates"in e&&e.updates;c&&(u=u.filter(((e,t)=>!l[t])),d=d.filter(((e,t)=>!l[t])));const p=Date.now(),h="delete"===e.type?{type:"delete",ts:p,opNo:a,keys:u,criteria:e.criteria,txid:n,userId:o}:"add"===e.type?{type:"insert",ts:p,opNo:a,keys:u,txid:n,userId:o,values:d}:e.criteria&&e.changeSpec?{type:"modify",ts:p,opNo:a,keys:u,criteria:e.criteria,changeSpec:e.changeSpec,txid:n,userId:o}:f?{type:"update",ts:p,opNo:a,keys:f.keys,changeSpecs:f.changeSpecs,txid:n,userId:o}:{type:"upsert",ts:p,opNo:a,keys:u,values:d,txid:n,userId:o};return u.length>0||"criteria"in e&&e.criteria?s.mutate({type:"add",trans:t,values:[h]}).then((()=>r)):r}))}}})}}}function jn(e,t){return function(n,r){const o=Object.assign(Object.assign({},un),n);Object.keys(un).forEach((e=>{const t=o[e];if(null==t)throw new Error(`Cannot delete table ${e} as it is needed for access control of Dexie Cloud`);if(!n[e])return;const r=t.split(",").map((e=>e.trim())),i=un[e].split(",").map((e=>e.trim())),s=new Set(r.map((e=>e.replace(/([&*]|\+\+)/g,""))));if(r[0]!==i[0])throw new Error(`Cannot override primary key of table ${e}. Please declare it as {${e}: ${JSON.stringify(un[e])}`);for(let t=1;t<i.length;++t){const n=i[t];s.has(n.replace(/([&*]|\+\+)/g,""))||(o[e]+=`,${n}`)}}));const i=t.cloud.schema||(t.cloud.schema={}),s=new Set;Object.keys(o).forEach((e=>{const t=o[e],n=i[e]||(i[e]={});null!=t?(/^\@/.test(t)&&(o[e]=o[e].substr(1),n.generatedGlobalId=!0,n.idPrefix=function(e,t){let n=e[0].toLocaleLowerCase();for(let t=1,o=e.length;t<o&&n.length<3;++t)(Sn.test(e[t])||(r=e[t])>="A"&&r<="Z")&&(n+=e[t].toLowerCase());for(var r,o,i;t.has(n);){if(/\d/g.test(n)){if(n=n.substr(0,n.length-1)+(n[n.length-1]+1),!(n.length>3))continue;n=n.substr(0,3)}else if(n.length<3){n+="2";continue}let e=1,r=n;for(;t.has(r)&&e<8;)o=n,r=(1&(i=e)?o[0].toUpperCase():o[0].toLowerCase())+(2&i?o[1].toUpperCase():o[1].toLowerCase())+(4&i?o[2].toUpperCase():o[2].toLowerCase()),++e;if(e<8)n=r;else{let e=n.charCodeAt(2)+1&127;n=n.substr(0,2)+String.fromCharCode(e)}}return n}(e,s),s.add(n.idPrefix)),/^\$/.test(e)||(o[`$${e}_mutations`]="++rev",n.markedForSync=!0),n.deleted&&(n.deleted=!1)):(n.deleted=!0,n.markedForSync=!1,o[`$${e}_mutations`]=null)}));return e.call(this,o,r)}}const Pn=new n.BehaviorSubject(!0),Un=new n.BehaviorSubject(!0);Pn.pipe(Fe((e=>e?n.of(!0):n.of(!1).pipe(Ne(2e4)))),Re()).subscribe(Un);const $n="undefined"!=typeof document?n.fromEvent(document,"visibilitychange"):n.of({}),Dn=$n.pipe(Be((()=>"hidden"===document.visibilityState))),Nn=$n.pipe(Be((()=>"visible"===document.visibilityState))),Rn="undefined"!=typeof window?n.merge(Nn,n.fromEvent(window,"mousedown"),n.fromEvent(window,"mousemove"),n.fromEvent(window,"keydown"),n.fromEvent(window,"wheel"),n.fromEvent(window,"touchmove")):n.of({});"undefined"!=typeof document&&n.merge(n.of(!0),Dn,Rn).pipe(Te((()=>"visible"===document.visibilityState)),He((e=>{Pn.value!==e&&Pn.next(e)})),Fe((e=>e?n.of(0).pipe(Ne(16e4),He((()=>Pn.next(!1)))):n.of(0)))).subscribe((()=>{}));class Ln extends Error{constructor(){super(...arguments),this.name="TokenExpiredError"}}class Bn extends n.Observable{constructor(e,t,n,r,o,i,s,a){super((c=>new Mn(e,t,n,r,s,a,c,o,i)))}}let Wn=0;class Mn extends n.Subscription{constructor(e,t,n,r,o,i,s,a,c){super((()=>this.teardown())),this.id=++Wn,this.reconnecting=!1,console.debug("New WebSocket Connection",this.id,o?"authorized":"unauthorized"),this.databaseUrl=e,this.rev=t,this.realmSetHash=n,this.clientIdentity=r,this.token=o,this.tokenExpiration=i,this.subscriber=s,this.lastUserActivity=new Date,this.messageProducer=a,this.messageProducerSubscription=null,this.webSocketStatus=c,this.connect()}teardown(){console.debug("Teardown WebSocket Connection",this.id),this.disconnect()}disconnect(){if(this.webSocketStatus.next("disconnected"),this.pinger&&(clearInterval(this.pinger),this.pinger=null),this.ws)try{this.ws.close()}catch(e){}this.ws=null,this.messageProducerSubscription&&(this.messageProducerSubscription.unsubscribe(),this.messageProducerSubscription=null)}reconnect(){if(!this.reconnecting){this.reconnecting=!0;try{this.disconnect()}catch(e){}this.connect().catch((()=>{})).then((()=>this.reconnecting=!1))}}connect(){return a(this,void 0,void 0,(function*(){if(this.lastServerActivity=new Date,this.pauseUntil&&this.pauseUntil>new Date)return void console.debug("WS not reconnecting just yet",{id:this.id,pauseUntil:this.pauseUntil});if(this.ws)throw new Error("Called connect() when a connection is already open");if(!this.databaseUrl)throw new Error("Cannot connect without a database URL");if(this.closed)return;if(this.tokenExpiration&&this.tokenExpiration<new Date)return void this.subscriber.error(new Ln);this.webSocketStatus.next("connecting"),this.pinger=setInterval((()=>a(this,void 0,void 0,(function*(){if(this.closed)return console.debug("pinger check",this.id,"CLOSED."),void this.teardown();if(this.ws)try{this.ws.send(JSON.stringify({type:"ping"})),setTimeout((()=>{if(console.debug("pinger setTimeout",this.id,this.pinger?"alive":"dead"),this.pinger)return this.closed?(console.debug("pinger setTimeout",this.id,"subscription is closed"),void this.teardown()):void(this.lastServerActivity<new Date(Date.now()-2e4)?(console.debug("pinger: server is inactive"),console.debug("pinger reconnecting"),this.reconnect()):console.debug("pinger: server still active"))}),2e4)}catch(e){console.debug("pinger catch error",this.id,"reconnecting"),this.reconnect()}else console.debug("pinger",this.id,"reconnecting"),this.reconnect()}))),3e4);const e=new URL(this.databaseUrl);e.protocol="http:"===e.protocol?"ws":"wss";const t=new URLSearchParams;if(this.subscriber.closed)return;t.set("v","2"),t.set("rev",this.rev),t.set("realmsHash",this.realmSetHash),t.set("clientId",this.clientIdentity),this.token&&t.set("token",this.token),console.debug("dexie-cloud WebSocket create");const n=this.ws=new WebSocket(`${e}/changes?${t}`);n.onclose=e=>{this.pinger&&(console.debug("dexie-cloud WebSocket onclosed",this.id),this.reconnect())},n.onmessage=e=>{if(this.pinger){console.debug("dexie-cloud WebSocket onmessage",e.data),this.lastServerActivity=new Date;try{const t=qt.parse(e.data);if("error"===t.type)throw new Error(`Error message from dexie-cloud: ${t.error}`);"rev"===t.type&&(this.rev=t.rev),"pong"!==t.type&&this.subscriber.next(t)}catch(e){this.subscriber.error(e)}}};try{let e=!1;yield new Promise(((t,r)=>{n.onopen=n=>{console.debug("dexie-cloud WebSocket onopen"),e=!0,t(null)},n.onerror=t=>{if(e)this.reconnect();else{const e=t.error||new Error("WebSocket Error");this.subscriber.error(e),this.webSocketStatus.next("error"),r(e)}}})),this.messageProducerSubscription=this.messageProducer.subscribe((e=>{var t;this.closed||("ready"===e.type&&"connected"!==this.webSocketStatus.value&&this.webSocketStatus.next("connected"),null===(t=this.ws)||void 0===t||t.send(qt.stringify(e)))}))}catch(e){this.pauseUntil=new Date(Date.now()+6e4)}}))}}function Fn(e){return a(this,void 0,void 0,(function*(){var t;console.error("WebSocket observable: error but revive when user does some active thing...",e),yield(t=3e3,new Promise((e=>setTimeout(e,t)))),console.debug("waiting for someone to do something"),yield Rn.pipe($e(1)).toPromise(),console.debug("someone did something!")}))}function Hn(e){var t;return a(this,void 0,void 0,(function*(){return!(!(null===(t=e.cloud.options)||void 0===t?void 0:t.databaseUrl)||!e.cloud.schema)&&(yield on(e,e.cloud.options,e.cloud.schema,{justCheckIfNeeded:!0}))}))}const Kn=_t(16);function Vn(e,r,o,i,{awaitRemoteJob:s}={}){return a(this,void 0,void 0,(function*(){const c=e.table(o);if(yield function i(){return a(this,void 0,void 0,(function*(){if(yield e.transaction("rw!",o,(()=>a(this,void 0,void 0,(function*(){const e=yield c.get(r);return e?e.heartbeat.getTime()<Date.now()-6e4&&(console.warn(`Latest ${r} worker seem to have died.\n`,"The dead job started:",e.started,"\n","Last heart beat was:",e.heartbeat,"\n","We're now taking over!"),yield c.put({nodeId:Kn,started:new Date,heartbeat:new Date},r),!0):(yield c.add({nodeId:Kn,started:new Date,heartbeat:new Date},r),!0)})))))return!0;if(s)try{const e=n.from(t.liveQuery((()=>c.get(r)))).pipe(function(e,t){var n=ge(e)?{first:e}:"number"==typeof e?{each:e}:e,r=n.first,o=n.each,i=n.with,s=void 0===i?Ve:i,a=n.scheduler,c=void 0===a?null!=t?t:ve:a,l=n.meta,u=void 0===l?null:l;if(null==r&&null==o)throw new TypeError("No timeout provided.");return I((function(e,t){var n,i,a=null,l=0,d=function(e){i=we(t,c,(function(){try{n.unsubscribe(),ae(s({meta:u,lastValue:a,seen:l})).subscribe(t)}catch(e){t.error(e)}}),e)};n=e.subscribe(le(t,(function(e){null==i||i.unsubscribe(),l++,t.next(a=e),o>0&&d(o)}),void 0,void 0,(function(){(null==i?void 0:i.closed)||null==i||i.unsubscribe(),a=null}))),!l&&d(null!=r?"number"==typeof r?r:+r-c.now():o)}))}(6e4),Be((e=>!e)));return yield e.toPromise(),!1}catch(e){if("TimeoutError"!==e.name)throw e;return yield i()}return!1}))}()){const t=setInterval((()=>{c.update(r,(e=>{e.nodeId===Kn&&(e.heartbeat=new Date)}))}),1e3);try{return yield i()}finally{clearInterval(t),yield e.transaction("rw!",o,(()=>a(this,void 0,void 0,(function*(){const e=yield c.get(r);e&&e.nodeId===Kn&&(yield c.delete(r))}))))}}}))}const zn=new WeakMap;function qn(e,t,n,r){const o=zn.get(e);if(o){if(o.pull||"push"===(null==r?void 0:r.purpose))return console.debug("syncIfPossible(): returning the ongoing sync promise."),o.promise;{let i=!1;const s=e.cloud.syncState.subscribe((e=>{"pulling"===e.phase&&(i=!0)}));return o.promise.then((()=>{s.unsubscribe()})).catch((e=>(s.unsubscribe(),Promise.reject(e)))).then((()=>{if(!i)return qn(e,t,n,r)}))}}const i=function(){return a(this,void 0,void 0,(function*(){try{if(e.cloud.isServiceWorkerDB)yield on(e,t,n,r);else{if(e.cloud.usingServiceWorker)throw y(!1),new Error("Internal _syncIfPossible() - invalid precondition - should not have been called.");yield Vn(e,"currentSyncWorker","$jobs",(()=>on(e,t,n,r)))}zn.delete(e),console.debug("Done sync")}catch(t){throw zn.delete(e),console.error("Failed to sync client changes",t),t}}))}();return zn.set(e,{promise:i,pull:"push"!==(null==r?void 0:r.purpose)}),i}function Jn(e,t,n){let r=null,o={cancelled:!1};function i(r,a=1){setTimeout((()=>{qn(e,t,n,{cancelToken:o,retryImmediatelyOnFetchError:!0,purpose:r}).catch((e=>{console.error("error in syncIfPossible()",e),o.cancelled?s():a<3&&setTimeout((()=>i(r,a+1)),6e4*[0,5,15][a])}))}),0)}const s=()=>{console.debug("Stopping LocalSyncWorker"),o.cancelled=!0,r&&r.unsubscribe()};return{start:()=>{console.debug("Starting LocalSyncWorker",e.localSyncEvent.id),r=e.localSyncEvent.subscribe((({purpose:e})=>{try{i(e||"pull")}catch(e){console.error("What-the....",e)}}))},stop:s}}function Gn(e,t){if(e&&t&&t.unsyncedTables)for(const n of t.unsyncedTables)e[n]&&(e[n].markedForSync=!1)}var Yn,Qn,Zn,Xn,er,tr={},nr=[],rr=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function or(e,t){for(var n in t)e[n]=t[n];return e}function ir(e){var t=e.parentNode;t&&t.removeChild(e)}function sr(e,t,n){var r,o,i,s={};for(i in t)"key"==i?r=t[i]:"ref"==i?o=t[i]:s[i]=t[i];if(arguments.length>2&&(s.children=arguments.length>3?Yn.call(arguments,2):n),"function"==typeof e&&null!=e.defaultProps)for(i in e.defaultProps)void 0===s[i]&&(s[i]=e.defaultProps[i]);return ar(e,s,r,o,null)}function ar(e,t,n,r,o){var i={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==o?++Zn:o};return null==o&&null!=Qn.vnode&&Qn.vnode(i),i}function cr(e){return e.children}function lr(e,t){this.props=e,this.context=t}function ur(e,t){if(null==t)return e.__?ur(e.__,e.__.__k.indexOf(e)+1):null;for(var n;t<e.__k.length;t++)if(null!=(n=e.__k[t])&&null!=n.__e)return n.__e;return"function"==typeof e.type?ur(e):null}function dr(e){var t,n;if(null!=(e=e.__)&&null!=e.__c){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if(null!=(n=e.__k[t])&&null!=n.__e){e.__e=e.__c.base=n.__e;break}return dr(e)}}function fr(e){(!e.__d&&(e.__d=!0)&&Xn.push(e)&&!pr.__r++||er!==Qn.debounceRendering)&&((er=Qn.debounceRendering)||setTimeout)(pr)}function pr(){for(var e;pr.__r=Xn.length;)e=Xn.sort((function(e,t){return e.__v.__b-t.__v.__b})),Xn=[],e.some((function(e){var t,n,r,o,i,s;e.__d&&(i=(o=(t=e).__v).__e,(s=t.__P)&&(n=[],(r=or({},o)).__v=o.__v+1,wr(s,o,r,t.__n,void 0!==s.ownerSVGElement,null!=o.__h?[i]:null,n,null==i?ur(o):i,o.__h),Sr(n,o),o.__e!=i&&dr(o)))}))}function hr(e,t,n,r,o,i,s,a,c,l){var u,d,f,p,h,y,v,b=r&&r.__k||nr,m=b.length;for(n.__k=[],u=0;u<t.length;u++)if(null!=(p=n.__k[u]=null==(p=t[u])||"boolean"==typeof p?null:"string"==typeof p||"number"==typeof p||"bigint"==typeof p?ar(null,p,null,null,p):Array.isArray(p)?ar(cr,{children:p},null,null,null):p.__b>0?ar(p.type,p.props,p.key,null,p.__v):p)){if(p.__=n,p.__b=n.__b+1,null===(f=b[u])||f&&p.key==f.key&&p.type===f.type)b[u]=void 0;else for(d=0;d<m;d++){if((f=b[d])&&p.key==f.key&&p.type===f.type){b[d]=void 0;break}f=null}wr(e,p,f=f||tr,o,i,s,a,c,l),h=p.__e,(d=p.ref)&&f.ref!=d&&(v||(v=[]),f.ref&&v.push(f.ref,null,p),v.push(d,p.__c||h,p)),null!=h?(null==y&&(y=h),"function"==typeof p.type&&p.__k===f.__k?p.__d=c=yr(p,c,e):c=vr(e,p,f,b,h,c),"function"==typeof n.type&&(n.__d=c)):c&&f.__e==c&&c.parentNode!=e&&(c=ur(f))}for(n.__e=y,u=m;u--;)null!=b[u]&&("function"==typeof n.type&&null!=b[u].__e&&b[u].__e==n.__d&&(n.__d=ur(r,u+1)),Ir(b[u],b[u]));if(v)for(u=0;u<v.length;u++)xr(v[u],v[++u],v[++u])}function yr(e,t,n){for(var r,o=e.__k,i=0;o&&i<o.length;i++)(r=o[i])&&(r.__=e,t="function"==typeof r.type?yr(r,t,n):vr(n,r,r,o,r.__e,t));return t}function vr(e,t,n,r,o,i){var s,a,c;if(void 0!==t.__d)s=t.__d,t.__d=void 0;else if(null==n||o!=i||null==o.parentNode)e:if(null==i||i.parentNode!==e)e.appendChild(o),s=null;else{for(a=i,c=0;(a=a.nextSibling)&&c<r.length;c+=2)if(a==o)break e;e.insertBefore(o,i),s=i}return void 0!==s?s:o.nextSibling}function br(e,t,n){"-"===t[0]?e.setProperty(t,n):e[t]=null==n?"":"number"!=typeof n||rr.test(t)?n:n+"px"}function mr(e,t,n,r,o){var i;e:if("style"===t)if("string"==typeof n)e.style.cssText=n;else{if("string"==typeof r&&(e.style.cssText=r=""),r)for(t in r)n&&t in n||br(e.style,t,"");if(n)for(t in n)r&&n[t]===r[t]||br(e.style,t,n[t])}else if("o"===t[0]&&"n"===t[1])i=t!==(t=t.replace(/Capture$/,"")),t=t.toLowerCase()in e?t.toLowerCase().slice(2):t.slice(2),e.l||(e.l={}),e.l[t+i]=n,n?r||e.addEventListener(t,i?_r:gr,i):e.removeEventListener(t,i?_r:gr,i);else if("dangerouslySetInnerHTML"!==t){if(o)t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("href"!==t&&"list"!==t&&"form"!==t&&"tabIndex"!==t&&"download"!==t&&t in e)try{e[t]=null==n?"":n;break e}catch(e){}"function"==typeof n||(null!=n&&(!1!==n||"a"===t[0]&&"r"===t[1])?e.setAttribute(t,n):e.removeAttribute(t))}}function gr(e){this.l[e.type+!1](Qn.event?Qn.event(e):e)}function _r(e){this.l[e.type+!0](Qn.event?Qn.event(e):e)}function wr(e,t,n,r,o,i,s,a,c){var l,u,d,f,p,h,y,v,b,m,g,_,w,S=t.type;if(void 0!==t.constructor)return null;null!=n.__h&&(c=n.__h,a=t.__e=n.__e,t.__h=null,i=[a]),(l=Qn.__b)&&l(t);try{e:if("function"==typeof S){if(v=t.props,b=(l=S.contextType)&&r[l.__c],m=l?b?b.props.value:l.__:r,n.__c?y=(u=t.__c=n.__c).__=u.__E:("prototype"in S&&S.prototype.render?t.__c=u=new S(v,m):(t.__c=u=new lr(v,m),u.constructor=S,u.render=Er),b&&b.sub(u),u.props=v,u.state||(u.state={}),u.context=m,u.__n=r,d=u.__d=!0,u.__h=[]),null==u.__s&&(u.__s=u.state),null!=S.getDerivedStateFromProps&&(u.__s==u.state&&(u.__s=or({},u.__s)),or(u.__s,S.getDerivedStateFromProps(v,u.__s))),f=u.props,p=u.state,d)null==S.getDerivedStateFromProps&&null!=u.componentWillMount&&u.componentWillMount(),null!=u.componentDidMount&&u.__h.push(u.componentDidMount);else{if(null==S.getDerivedStateFromProps&&v!==f&&null!=u.componentWillReceiveProps&&u.componentWillReceiveProps(v,m),!u.__e&&null!=u.shouldComponentUpdate&&!1===u.shouldComponentUpdate(v,u.__s,m)||t.__v===n.__v){u.props=v,u.state=u.__s,t.__v!==n.__v&&(u.__d=!1),u.__v=t,t.__e=n.__e,t.__k=n.__k,t.__k.forEach((function(e){e&&(e.__=t)})),u.__h.length&&s.push(u);break e}null!=u.componentWillUpdate&&u.componentWillUpdate(v,u.__s,m),null!=u.componentDidUpdate&&u.__h.push((function(){u.componentDidUpdate(f,p,h)}))}if(u.context=m,u.props=v,u.__v=t,u.__P=e,g=Qn.__r,_=0,"prototype"in S&&S.prototype.render)u.state=u.__s,u.__d=!1,g&&g(t),l=u.render(u.props,u.state,u.context);else do{u.__d=!1,g&&g(t),l=u.render(u.props,u.state,u.context),u.state=u.__s}while(u.__d&&++_<25);u.state=u.__s,null!=u.getChildContext&&(r=or(or({},r),u.getChildContext())),d||null==u.getSnapshotBeforeUpdate||(h=u.getSnapshotBeforeUpdate(f,p)),w=null!=l&&l.type===cr&&null==l.key?l.props.children:l,hr(e,Array.isArray(w)?w:[w],t,n,r,o,i,s,a,c),u.base=t.__e,t.__h=null,u.__h.length&&s.push(u),y&&(u.__E=u.__=null),u.__e=!1}else null==i&&t.__v===n.__v?(t.__k=n.__k,t.__e=n.__e):t.__e=kr(n.__e,t,n,r,o,i,s,c);(l=Qn.diffed)&&l(t)}catch(e){t.__v=null,(c||null!=i)&&(t.__e=a,t.__h=!!c,i[i.indexOf(a)]=null),Qn.__e(e,t,n)}}function Sr(e,t){Qn.__c&&Qn.__c(t,e),e.some((function(t){try{e=t.__h,t.__h=[],e.some((function(e){e.call(t)}))}catch(e){Qn.__e(e,t.__v)}}))}function kr(e,t,n,r,o,i,s,a){var c,l,u,d=n.props,f=t.props,p=t.type,h=0;if("svg"===p&&(o=!0),null!=i)for(;h<i.length;h++)if((c=i[h])&&"setAttribute"in c==!!p&&(p?c.localName===p:3===c.nodeType)){e=c,i[h]=null;break}if(null==e){if(null===p)return document.createTextNode(f);e=o?document.createElementNS("http://www.w3.org/2000/svg",p):document.createElement(p,f.is&&f),i=null,a=!1}if(null===p)d===f||a&&e.data===f||(e.data=f);else{if(i=i&&Yn.call(e.childNodes),l=(d=n.props||tr).dangerouslySetInnerHTML,u=f.dangerouslySetInnerHTML,!a){if(null!=i)for(d={},h=0;h<e.attributes.length;h++)d[e.attributes[h].name]=e.attributes[h].value;(u||l)&&(u&&(l&&u.__html==l.__html||u.__html===e.innerHTML)||(e.innerHTML=u&&u.__html||""))}if(function(e,t,n,r,o){var i;for(i in n)"children"===i||"key"===i||i in t||mr(e,i,null,n[i],r);for(i in t)o&&"function"!=typeof t[i]||"children"===i||"key"===i||"value"===i||"checked"===i||n[i]===t[i]||mr(e,i,t[i],n[i],r)}(e,f,d,o,a),u)t.__k=[];else if(h=t.props.children,hr(e,Array.isArray(h)?h:[h],t,n,r,o&&"foreignObject"!==p,i,s,i?i[0]:n.__k&&ur(n,0),a),null!=i)for(h=i.length;h--;)null!=i[h]&&ir(i[h]);a||("value"in f&&void 0!==(h=f.value)&&(h!==e.value||"progress"===p&&!h||"option"===p&&h!==d.value)&&mr(e,"value",h,d.value,!1),"checked"in f&&void 0!==(h=f.checked)&&h!==e.checked&&mr(e,"checked",h,d.checked,!1))}return e}function xr(e,t,n){try{"function"==typeof e?e(t):e.current=t}catch(e){Qn.__e(e,n)}}function Ir(e,t,n){var r,o;if(Qn.unmount&&Qn.unmount(e),(r=e.ref)&&(r.current&&r.current!==e.__e||xr(r,null,t)),null!=(r=e.__c)){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){Qn.__e(e,t)}r.base=r.__P=null}if(r=e.__k)for(o=0;o<r.length;o++)r[o]&&Ir(r[o],t,"function"!=typeof e.type);n||null==e.__e||ir(e.__e),e.__e=e.__d=void 0}function Er(e,t,n){return this.constructor(e,n)}function Or(e,t,n){var r,o,i;Qn.__&&Qn.__(e,t),o=(r="function"==typeof n)?null:n&&n.__k||t.__k,i=[],wr(t,e=(!r&&n||t).__k=sr(cr,null,[e]),o||tr,tr,void 0!==t.ownerSVGElement,!r&&n?[n]:o?null:t.firstChild?Yn.call(t.childNodes):null,i,!r&&n?n:o?o.__e:t.firstChild,r),Sr(i,e)}Yn=nr.slice,Qn={__e:function(e,t,n,r){for(var o,i,s;t=t.__;)if((o=t.__c)&&!o.__)try{if((i=o.constructor)&&null!=i.getDerivedStateFromError&&(o.setState(i.getDerivedStateFromError(e)),s=o.__d),null!=o.componentDidCatch&&(o.componentDidCatch(e,r||{}),s=o.__d),s)return o.__E=o}catch(t){e=t}throw e}},Zn=0,lr.prototype.setState=function(e,t){var n;n=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=or({},this.state),"function"==typeof e&&(e=e(or({},n),this.props)),e&&or(n,e),null!=e&&this.__v&&(t&&this.__h.push(t),fr(this))},lr.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),fr(this))},lr.prototype.render=cr,Xn=[],pr.__r=0;const Tr={Error:{color:"red"},Alert:{error:{color:"red"},warning:{color:"yellow"},info:{color:"black"}},Darken:{position:"fixed",top:0,left:0,opacity:.5,backgroundColor:"#000",width:"100vw",height:"100vh",zIndex:150,webkitBackdropFilter:"blur(2px)",backdropFilter:"blur(2px)"},DialogOuter:{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",zIndex:150,alignItems:"center",display:"flex",justifyContent:"center"},DialogInner:{position:"relative",color:"#222",backgroundColor:"#fff",padding:"30px",marginBottom:"2em",maxWidth:"90%",maxHeight:"90%",overflowY:"auto",border:"3px solid #3d3d5d",borderRadius:"8px",boxShadow:"0 0 80px 10px #666",width:"auto"},Input:{height:"35px",width:"17em",borderColor:"#ccf4",outline:"none",fontSize:"17pt",padding:"8px"}};function Cr({children:e,className:t}){return sr("div",{className:t},sr("div",{style:Tr.Darken}),sr("div",{style:Tr.DialogOuter},sr("div",{style:Tr.DialogInner},e)))}var Ar,jr,Pr,Ur,$r=0,Dr=[],Nr=[],Rr=Qn.__b,Lr=Qn.__r,Br=Qn.diffed,Wr=Qn.__c,Mr=Qn.unmount;function Fr(e,t){Qn.__h&&Qn.__h(jr,e,$r||t),$r=0;var n=jr.__H||(jr.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({__V:Nr}),n.__[e]}function Hr(e){return $r=1,function(e,t,n){var r=Fr(Ar++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Yr(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);t!==n&&(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=jr,!jr.u)){jr.u=!0;var o=jr.shouldComponentUpdate;jr.shouldComponentUpdate=function(e,t,n){if(!r.__c.__H)return!0;var i=r.__c.__H.__.filter((function(e){return e.__c}));if(i.every((function(e){return!e.__N})))return!o||o.call(this,e,t,n);var s=!1;return i.forEach((function(e){if(e.__N){var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(s=!0)}})),!!s&&(!o||o.call(this,e,t,n))}}return r.__N||r.__}(Yr,e)}function Kr(e){return $r=5,function(e,t){var n=Fr(Ar++,7);return Gr(n.__H,t)?(n.__V=e(),n.i=t,n.__h=e,n.__V):n.__}((function(){return{current:e}}),[])}function Vr(){for(var e;e=Dr.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(qr),e.__H.__h.forEach(Jr),e.__H.__h=[]}catch(t){e.__H.__h=[],Qn.__e(t,e.__v)}}Qn.__b=function(e){jr=null,Rr&&Rr(e)},Qn.__r=function(e){Lr&&Lr(e),Ar=0;var t=(jr=e.__c).__H;t&&(Pr===jr?(t.__h=[],jr.__h=[],t.__.forEach((function(e){e.__N&&(e.__=e.__N),e.__V=Nr,e.__N=e.i=void 0}))):(t.__h.forEach(qr),t.__h.forEach(Jr),t.__h=[])),Pr=jr},Qn.diffed=function(e){Br&&Br(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(1!==Dr.push(t)&&Ur===Qn.requestAnimationFrame||((Ur=Qn.requestAnimationFrame)||function(e){var t,n=function(){clearTimeout(r),zr&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,100);zr&&(t=requestAnimationFrame(n))})(Vr)),t.__H.__.forEach((function(e){e.i&&(e.__H=e.i),e.__V!==Nr&&(e.__=e.__V),e.i=void 0,e.__V=Nr}))),Pr=jr=null},Qn.__c=function(e,t){t.some((function(e){try{e.__h.forEach(qr),e.__h=e.__h.filter((function(e){return!e.__||Jr(e)}))}catch(n){t.some((function(e){e.__h&&(e.__h=[])})),t=[],Qn.__e(n,e.__v)}})),Wr&&Wr(e,t)},Qn.unmount=function(e){Mr&&Mr(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach((function(e){try{qr(e)}catch(e){t=e}})),t&&Qn.__e(t,n.__v))};var zr="function"==typeof requestAnimationFrame;function qr(e){var t=jr,n=e.__c;"function"==typeof n&&(e.__c=void 0,n()),jr=t}function Jr(e){var t=jr;e.__c=e.__(),jr=t}function Gr(e,t){return!e||e.length!==t.length||t.some((function(t,n){return t!==e[n]}))}function Yr(e,t){return"function"==typeof t?t(e):t}function Qr({title:e,alerts:t,fields:n,onCancel:r,onSubmit:o}){const[i,s]=Hr({}),a=Kr(null);return function(e,t){var n=Fr(Ar++,4);!Qn.__s&&Gr(n.__H,t)&&(n.__=e,n.i=t,jr.__h.push(n))}((()=>{var e;return null===(e=a.current)||void 0===e?void 0:e.focus()}),[]),sr(Cr,{className:"dxc-login-dlg"},sr(cr,null,sr("h3",{style:Tr.WindowHeader},e),t.map((e=>sr("p",{style:Tr.Alert[e.type]},function({message:e,messageCode:t,messageParams:n}){return e.replace(/\{\w+\}/gi,(e=>n[e.substr(1,e.length-2)]))}(e)))),sr("form",{onSubmit:e=>{e.preventDefault(),o(i)}},Object.entries(n).map((([e,{type:t,label:n,placeholder:r}],o)=>sr("label",{style:Tr.Label},n?`${n}: `:"",sr("input",{ref:0===o?a:void 0,type:t,name:e,autoComplete:"on",style:Tr.Input,autoFocus:!0,placeholder:r,value:i[e]||"",onInput:n=>{var r;return s(Object.assign(Object.assign({},i),{[e]:Zr(t,null===(r=n.target)||void 0===r?void 0:r.value)}))}})))))),sr("div",{style:Tr.ButtonsDiv},sr("button",{type:"submit",style:Tr.Button,onClick:()=>o(i)},"Submit"),sr("button",{style:Tr.Button,onClick:r},"Cancel")))}function Zr(e,t){switch(e){case"email":return t.toLowerCase();case"otp":return t.toUpperCase();default:return t}}class Xr extends lr{constructor(e){super(e),this.observer=e=>this.setState({userInteraction:e}),this.state={userInteraction:void 0}}componentDidMount(){this.subscription=n.from(this.props.db.cloud.userInteraction).subscribe(this.observer)}componentWillUnmount(){this.subscription&&(this.subscription.unsubscribe(),delete this.subscription)}render(e,{userInteraction:t}){return t?sr(Qr,Object.assign({},t)):null}}function eo(e){const t=new WeakMap;return n=>{let r=t.get(n);return r||(r=e(n),t.set(n,r)),r}}function to(e,t){let r=t,o=n.from(e).pipe(n.map((e=>r=e)),n.share({resetOnRefCountZero:()=>n.timer(1e3)}));const i=new n.Observable((e=>{let t=!1;const n=o.subscribe({next(n){t=!0,e.next(n)},error(t){e.error(t)},complete(){e.complete()}});return t||n.closed||e.next(r),n}));return i.getValue=()=>r,i}const no=eo((e=>to(t.liveQuery((()=>e.roles.where({realmId:"rlm-public"}).toArray().then((e=>{const t={};for(const n of e.slice().sort(((e,t)=>(e.sortOrder||0)-(t.sortOrder||0))))t[n.name]=n;return t})))),{}))),ro=eo((e=>new n.BehaviorSubject(at))),oo=eo((e=>to(ro(e._novip).pipe(Fe((n=>t.liveQuery((()=>e.transaction("r","realms","members",(()=>Promise.all([e.members.where({userId:n.userId}).toArray(),e.realms.toArray(),n.userId]).then((([e,t,n])=>({selfMembers:e,realms:t,userId:n})))))))))),{selfMembers:[],realms:[],get userId(){return e.cloud.currentUserId}})));function io(...e){if(0===e.length)return{};const t=e.reduce(((e,t)=>{const n=Object.assign({},e);for(const[e,r]of Object.entries(t))if(e in n&&n[e]){if("*"===n[e])continue;if("*"===r)n[e]="*";else if(Array.isArray(r)&&Array.isArray(n[e])){const t=n,o=t[e];t[e]=[...new Set([...o,...r])]}else if("object"==typeof r&&r&&"object"==typeof n[e]){const t=n[e];for(const[e,n]of Object.entries(r))"*"!==t[e]&&("*"===n?t[e]="*":Array.isArray(t[e])&&Array.isArray(n)&&(t[e]=[...new Set([...t[e],...n])]))}}else n[e]=t[e];return n}));return t}const so=eo((e=>function(e,t){let r;const o=e.pipe(n.map((e=>r=t(e))));return o.getValue=()=>void 0!==r?r:r=t(e.getValue()),o}(to(n.combineLatest([oo(e._novip),no(e._novip)]).pipe(Te((([{selfMembers:e,realms:t,userId:n},r])=>({selfMembers:e,realms:t,userId:n,globalRoles:r})))),{selfMembers:[],realms:[],userId:at.userId,globalRoles:{}}),(({selfMembers:e,realms:t,userId:n,globalRoles:r})=>{const o=t.map((t=>{const o=e.filter((e=>e.realmId===t.realmId)),i=o.map((e=>e.permissions)).filter((e=>e)),s=mt(o.map((e=>e.roles)).filter((e=>e))).map((e=>r[e])).filter((e=>e)).map((e=>e.permissions));return Object.assign(Object.assign({},t),{permissions:t.owner===n?{manage:"*"}:io(...i,...s)})})).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.realmId]:t})),{[n]:{realmId:n,owner:n,name:n,permissions:{manage:"*"}}});return o}))));class ao{constructor(e,t,n){this.permissions=e||{},this.tableName=t,this.isOwner=n}add(...e){var t;return"*"===this.permissions.manage||(!!(null===(t=this.permissions.manage)||void 0===t?void 0:t.includes(this.tableName))||("*"===this.permissions.add||!!e.every((e=>{var t;return null===(t=this.permissions.add)||void 0===t?void 0:t.includes(e)}))))}update(...e){var t,n;if(this.isOwner||"*"===this.permissions.manage)return!0;if(null===(t=this.permissions.manage)||void 0===t?void 0:t.includes(this.tableName))return!0;if("*"===this.permissions.update)return e.every((e=>"owner"!==e));const r=null===(n=this.permissions.update)||void 0===n?void 0:n[this.tableName];return"*"===r?e.every((e=>"owner"!==e)):e.every((e=>null==r?void 0:r.some((t=>t===e||"*"===t&&"owner"!==e))))}delete(){var e;return!(!this.isOwner&&"*"!==this.permissions.manage)||!!(null===(e=this.permissions.manage)||void 0===e?void 0:e.includes(this.tableName))}}const co=eo((e=>{const r=ro(e._novip).pipe(Fe((n=>t.liveQuery((()=>e.members.where({email:n.email||""}).toArray()))))),o=so(e._novip),i=oo(e._novip);return to(n.combineLatest([r,i,o]).pipe(Te((([t,n,r])=>{const o=(e,t)=>Object.assign(Object.assign({},e),{[t.id]:Object.assign(Object.assign({},t),{realm:r[t.realmId]})}),i=t.reduce(o,{}),s=n.selfMembers.reduce(o,i);return Object.values(s).filter((e=>!e.accepted)).map((t=>Object.assign(Object.assign({},t),{accept(){return a(this,void 0,void 0,(function*(){yield e.members.update(t.id,{accepted:new Date})}))},reject(){return a(this,void 0,void 0,(function*(){yield e.members.update(t.id,{rejected:new Date})}))}})))}))),[])}));const lo={nameSuffix:!0};function uo(e){const r=e.name,i=ro(e),s=[];let c=!1,l=null;e.on("ready",(e=>a(this,void 0,void 0,(function*(){try{yield function(e){var r,p,h,y,v,b,m;return a(this,void 0,void 0,(function*(){u=!1;const g=fn(e);"undefined"!=typeof window&&"undefined"!=typeof document&&((null===(r=g.cloud.options)||void 0===r?void 0:r.customLoginGui)||s.push(function(e){let t=!1;const n=document.createElement("div");return document.body?(document.body.appendChild(n),Or(sr(Xr,{db:e.vip}),n)):addEventListener("DOMContentLoaded",(()=>{t||(document.body.appendChild(n),Or(sr(Xr,{db:e.vip}),n))})),{unsubscribe(){try{n.remove()}catch(e){}t=!0},get closed(){return t}}}(e))),g.cloud.isServiceWorkerDB||s.push(function(e){let t=e.cloud.webSocketStatus.value;const r=e.cloud.webSocketStatus.pipe(Fe((e=>{const r=t;t=e;const o=n.of(e);switch(e){case"disconnected":return Pn.value?o.pipe(je(500)):o;case"connecting":return"not-started"===r||"error"===r?o:o.pipe(je(4e3));default:return o}})));return n.combineLatest([r,e.syncStateChangedEvent.pipe(Me({phase:"initial"})),Un]).pipe(Te((([t,n,r])=>{let{phase:o,error:i,progress:s}=n,a=t;return"error"===o&&(a="error"),"not-started"===t&&("pushing"!==o&&"pulling"!==o||(a="connecting")),"error"!==e.cloud.syncState.value.phase||"pushing"!==n.phase&&"pulling"!==n.phase||(a="connecting"),r||(a="disconnected"),{phase:o,error:i,progress:s,status:Xt?a:"offline"}})))}(g).subscribe(e.cloud.syncState)),s.push(g.syncCompleteEvent.subscribe(f)),g.tables.every((e=>e.core))||mn();const _="serviceWorker"in navigator?yield navigator.serviceWorker.getRegistrations():[],w=yield g.transaction("rw",g.$syncState,(()=>a(this,void 0,void 0,(function*(){var e,t;const{options:n,schema:r}=g.cloud,[o,i,s]=yield Promise.all([g.getOptions(),g.getSchema(),g.getPersistedSyncState()]);if(c){if(!o||JSON.stringify(o)!==JSON.stringify(n)){if(!n)throw new Error("Internal error");const e=Object.assign({},n);delete e.fetchTokens,yield g.$syncState.put(e,"options")}}else g.cloud.options=o||null;if((null===(e=g.cloud.options)||void 0===e?void 0:e.tryUseServiceWorker)&&"serviceWorker"in navigator&&_.length>0&&!vn?(console.debug("Dexie Cloud Addon: Using service worker"),g.cloud.usingServiceWorker=!0):((null===(t=g.cloud.options)||void 0===t?void 0:t.tryUseServiceWorker)&&!g.cloud.isServiceWorkerDB&&console.debug("dexie-cloud-addon: Not using service worker.",0===_.length?"No SW registrations found.":"serviceWorker"in navigator&&vn?"Avoiding SW background sync and SW periodic bg sync for this browser due to browser bugs.":"navigator.serviceWorker not present"),g.cloud.usingServiceWorker=!1),Gn(r,g.cloud.options),Gn(i,g.cloud.options),r){if(!i||JSON.stringify(i)!==JSON.stringify(r)){const e=i||{};for(const[t,n]of Object.entries(r)){const r=e[t];r?(r.markedForSync=n.markedForSync,n.deleted=r.deleted,r.generatedGlobalId=n.generatedGlobalId):e[t]=Object.assign({},n)}yield g.$syncState.put(e,"schema"),Object.assign(r,e)}}else g.cloud.schema=i||null;return null==s?void 0:s.initiallySynced}))));w&&g.setInitiallySynced(!0),function(e){var t,n;for(const r of e.tables)if(null===(n=null===(t=e.cloud.schema)||void 0===t?void 0:t[r.name])||void 0===n?void 0:n.markedForSync){if(r.schema.primKey.auto)throw new o.default.SchemaError(`Table ${r.name} is both autoIncremented and synced. Use db.cloud.configure({unsyncedTables: [${JSON.stringify(r.name)}]}) to blacklist it from sync`);if(!r.schema.primKey.keyPath)throw new o.default.SchemaError(`Table ${r.name} cannot be both synced and outbound. Use db.cloud.configure({unsyncedTables: [${JSON.stringify(r.name)}]}) to blacklist it from sync`)}}(g),(null===(p=g.cloud.options)||void 0===p?void 0:p.databaseUrl)&&!w&&(yield function(e,t,n){return a(this,void 0,void 0,(function*(){console.debug("Performing initial sync"),yield on(e,t,n,{isInitialSync:!0}),console.debug("Done initial sync")}))}(g,g.cloud.options,g.cloud.schema),g.setInitiallySynced(!0)),d(),g.cloud.isServiceWorkerDB||(s.push(t.liveQuery((()=>g.getCurrentUser())).subscribe(i)),s.push(t.liveQuery((()=>g.getPersistedSyncState())).subscribe(g.cloud.persistedSyncState)),yield n.combineLatest([i.pipe(We(1),$e(1)),g.cloud.persistedSyncState.pipe(We(1),$e(1))]).toPromise());let S=!1;(null===(h=g.cloud.options)||void 0===h?void 0:h.requireAuth)&&(S=yield st(g)),l&&l.stop(),l=null,d(),g.cloud.usingServiceWorker&&(null===(y=g.cloud.options)||void 0===y?void 0:y.databaseUrl)?(qe(g,S?"pull":"push").catch((()=>{})),function(e){var t;return a(this,void 0,void 0,(function*(){try{const{periodicSync:n}=yield navigator.serviceWorker.ready;if(n)try{yield n.register(`dexie-cloud:${e.name}`,null===(t=e.cloud.options)||void 0===t?void 0:t.periodicSync),console.debug(`Dexie Cloud: Successfully registered periodicsync event for ${e.name}`)}catch(e){console.debug("Dexie Cloud: Failed to register periodic sync. Your PWA must be installed to allow background sync.",e)}else console.debug("Dexie Cloud: periodicSync not supported.")}catch(t){console.debug(`Dexie Cloud: Could not register periodicSync for ${e.name}`,t)}}))}(g).catch((()=>{}))):(null===(v=g.cloud.options)||void 0===v?void 0:v.databaseUrl)&&g.cloud.schema&&!g.cloud.isServiceWorkerDB&&(l=Jn(g,g.cloud.options,g.cloud.schema),l.start(),Je(g,S?"pull":"push")),d(),g.cloud.isServiceWorkerDB||s.push(n.fromEvent(self,"online").subscribe((()=>{console.debug("online!"),g.syncStateChangedEvent.next({phase:"not-in-sync"}),Je(g,"push")})),n.fromEvent(self,"offline").subscribe((()=>{console.debug("offline!"),g.syncStateChangedEvent.next({phase:"offline"})}))),!(null===(b=g.cloud.options)||void 0===b?void 0:b.databaseUrl)||(null===(m=g.cloud.options)||void 0===m?void 0:m.disableWebSocket)||bn||s.push(function(e){var t;if(!(null===(t=e.cloud.options)||void 0===t?void 0:t.databaseUrl))throw new Error("No database URL to connect WebSocket to");const r=e.messageConsumer.readyToServe.pipe(Be((e=>e)),Fe((()=>e.getPersistedSyncState())),Be((e=>e&&e.serverRevision)),Fe((e=>a(this,void 0,void 0,(function*(){return{type:"ready",rev:e.serverRevision,realmSetHash:yield pt(e)}})))));return function t(){return e.cloud.persistedSyncState.pipe(Be((e=>null==e?void 0:e.serverRevision)),$e(1),Fe((t=>e.cloud.currentUser.pipe(Te((e=>[e,t]))))),Fe((([e,t])=>Un.pipe(Te((n=>[n?e:null,t]))))),Fe((([t,r])=>(null==t?void 0:t.isLoggedIn)&&!(null==r?void 0:r.realms.includes(t.userId))?e.cloud.persistedSyncState.pipe(Be((e=>(null==e?void 0:e.realms.includes(t.userId))||!1)),$e(1),Te((e=>[t,e]))):new n.BehaviorSubject([t,r]))),Fe((([e,t])=>a(this,void 0,void 0,(function*(){return[e,yield pt(t)]})))),Re((([e,t],[n,r])=>e===n&&t===r)),Fe((([t,o])=>t?new Bn(e.cloud.options.databaseUrl,e.cloud.persistedSyncState.value.serverRevision,o,e.cloud.persistedSyncState.value.clientIdentity,r,e.cloud.webSocketStatus,t.accessToken,t.accessTokenExpiration):n.from([]))),Se((r=>"TokenExpiredError"===(null==r?void 0:r.name)?(console.debug("WebSocket observable: Token expired. Refreshing token..."),n.of(!0).pipe(Fe((()=>a(this,void 0,void 0,(function*(){const t=yield e.getCurrentUser(),n=yield nt(e.cloud.options.databaseUrl,t);yield e.table("$logins").update(t.userId,{accessToken:n.accessToken,accessTokenExpiration:n.accessTokenExpiration})})))),Fe((()=>t())))):n.throwError(r))),Se((r=>(e.cloud.webSocketStatus.next("error"),n.from(Fn(r)).pipe(Fe((()=>t())))))))}().subscribe({next:t=>{t&&(console.debug("WS got message",t),e.messageConsumer.enqueue(t))},error:e=>{console.error("WS got error",e)},complete:()=>{console.debug("WS observable completed")}})}(g))}))}(e)}catch(e){console.error(e)}}))),!0);let u=!1;function d(){if(u)throw new o.default.DatabaseClosedError}!function(e,t){e.on.close.subscribe(t);const n=e._close;e._close=function(){n.call(this),t()}}(e,(()=>{s.forEach((e=>e.unsubscribe())),u=!0,l&&l.stop(),l=null,i.next(at)}));const f=new n.Subject;var p;e.cloud={version:"4.0.1-beta.46",options:Object.assign({},lo),schema:null,get currentUserId(){return i.value.userId||at.userId},currentUser:i,syncState:new n.BehaviorSubject({phase:"initial",status:"not-started"}),events:{syncComplete:f},persistedSyncState:new n.BehaviorSubject(void 0),userInteraction:new n.BehaviorSubject(void 0),webSocketStatus:new n.BehaviorSubject("not-started"),login(t){return a(this,void 0,void 0,(function*(){const n=fn(e);yield n.cloud.sync(),yield st(n,t)}))},invites:co(e),roles:no(e),configure(t){t=e.cloud.options=Object.assign(Object.assign({},e.cloud.options),t),c=!0,t.databaseUrl&&t.nameSuffix&&(e.name=`${r}-${function(e){const t=new URL(e);return"/"===t.pathname?t.hostname.split(".")[0]:t.pathname.split("/")[1]}(t.databaseUrl)}`,fn(e).reconfigure()),Gn(e.cloud.schema,e.cloud.options)},sync({wait:r,purpose:o}={wait:!0,purpose:"push"}){return a(this,void 0,void 0,(function*(){void 0===r&&(r=!0);const i=fn(e);if("pull"===o){const e=i.cloud.persistedSyncState.value;if(Je(i,o),r){const t=yield i.cloud.persistedSyncState.pipe(Be((t=>null!=(null==t?void 0:t.timestamp)&&(!e||t.timestamp>e.timestamp))),$e(1)).toPromise();if(null==t?void 0:t.error)throw new Error("Sync error: "+t.error)}}else if(yield Hn(i)){const e=i.cloud.persistedSyncState.value;Je(i,o),r&&(console.debug("db.cloud.login() is waiting for sync completion..."),yield n.from(t.liveQuery((()=>a(this,void 0,void 0,(function*(){const t=yield Hn(i),n=yield i.getPersistedSyncState();if((null==n?void 0:n.timestamp)!==(null==e?void 0:e.timestamp)&&(null==n?void 0:n.error))throw new Error("Sync error: "+n.error);return t}))))).pipe(Be((e=>!e)),$e(1)).toPromise(),console.debug("Done waiting for sync completion because we have nothing to push anymore"))}}))},permissions:(t,n)=>function(e,t,n){if(!t)throw new TypeError("Cannot check permissions of undefined or null. A Dexie Cloud object with realmId and owner expected.");const{owner:r,realmId:o}=t;if(!n){if("function"!=typeof t.table)throw new TypeError("Missing 'table' argument to permissions and table could not be extracted from entity");n=t.table()}const i=so(e),s=t=>{const i=t[o||e.cloud.currentUserId];return i?new ao(i.permissions,n,o===e.cloud.currentUserId||r===e.cloud.currentUserId):new ao({},n,!r||r===e.cloud.currentUserId)},a=i.pipe(Te(s));return a.getValue=()=>s(i.getValue()),a}(e._novip,t,n)},e.Version.prototype._parseStoresSpec=o.default.override(e.Version.prototype._parseStoresSpec,(t=>jn(t,e))),e.Table.prototype.newId=function({colocateWith:t}={}){const n=t&&t.substr(t.length-3);return xn(e.cloud.schema[this.name].idPrefix||"",n)},e.Table.prototype.idPrefix=function(){var e,t;return(null===(t=null===(e=this.db.cloud.schema)||void 0===e?void 0:e[this.name])||void 0===t?void 0:t.idPrefix)||""},e.use(An({currentUserObservable:e.cloud.currentUser,db:fn(e)})),e.use((p=fn(e),{stack:"dbcore",name:"implicitPropSetterMiddleware",level:1,create:e=>Object.assign(Object.assign({},e),{table:t=>{const n=e.table(t);return Object.assign(Object.assign({},n),{mutate:e=>{var r,o,i,s;if(e.trans.disableChangeTracking)return n.mutate(e);const a=e.trans;if((null===(o=null===(r=p.cloud.schema)||void 0===r?void 0:r[t])||void 0===o?void 0:o.markedForSync)&&("add"===e.type||"put"===e.type))for(const t of e.values){t.owner||(t.owner=a.currentUser.userId),t.realmId||(t.realmId=a.currentUser.userId);const r=null===(s=(i=n.schema.primaryKey).extractKey)||void 0===s?void 0:s.call(i,t);"string"==typeof r&&"#"===r[0]&&"put"===e.type&&(delete e.criteria,delete e.changeSpec,delete e.updates,t.$ts=Date.now())}return n.mutate(e)}})}})})),e.use(In(fn(e)))}uo.version="4.0.1-beta.46",o.default.Cloud=uo,e.default=uo,e.dexieCloud=uo,e.getTiedObjectId=function(e){return e.startsWith("rlm~")?e.substr(4):null},e.getTiedRealmId=function(e){return"rlm~"+e},Object.defineProperty(e,"__esModule",{value:!0})}));
2
- //# sourceMappingURL=dexie-cloud-addon.min.js.map