tinybase 5.0.0-beta.27 → 5.0.0-beta.28

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 (249) hide show
  1. package/@types/_internal/ui-react/with-schemas/index.d.cts +274 -0
  2. package/@types/_internal/ui-react/with-schemas/index.d.ts +274 -0
  3. package/@types/checkpoints/index.d.cts +30 -1
  4. package/@types/checkpoints/index.d.ts +30 -1
  5. package/@types/checkpoints/with-schemas/index.d.cts +30 -1
  6. package/@types/checkpoints/with-schemas/index.d.ts +30 -1
  7. package/@types/common/index.d.cts +9 -0
  8. package/@types/common/index.d.ts +9 -0
  9. package/@types/common/with-schemas/index.d.cts +9 -0
  10. package/@types/common/with-schemas/index.d.ts +9 -0
  11. package/@types/index.d.cts +1 -0
  12. package/@types/index.d.ts +1 -0
  13. package/@types/indexes/index.d.cts +32 -1
  14. package/@types/indexes/index.d.ts +32 -1
  15. package/@types/indexes/with-schemas/index.d.cts +32 -1
  16. package/@types/indexes/with-schemas/index.d.ts +32 -1
  17. package/@types/mergeable-store/index.d.cts +0 -2
  18. package/@types/mergeable-store/index.d.ts +0 -2
  19. package/@types/mergeable-store/with-schemas/index.d.cts +2 -2
  20. package/@types/mergeable-store/with-schemas/index.d.ts +2 -2
  21. package/@types/metrics/index.d.cts +30 -4
  22. package/@types/metrics/index.d.ts +30 -4
  23. package/@types/metrics/with-schemas/index.d.cts +30 -4
  24. package/@types/metrics/with-schemas/index.d.ts +30 -4
  25. package/@types/persisters/index.d.cts +87 -25
  26. package/@types/persisters/index.d.ts +87 -25
  27. package/@types/persisters/persister-automerge/index.d.cts +4 -4
  28. package/@types/persisters/persister-automerge/index.d.ts +4 -4
  29. package/@types/persisters/persister-automerge/with-schemas/index.d.cts +4 -4
  30. package/@types/persisters/persister-automerge/with-schemas/index.d.ts +4 -4
  31. package/@types/persisters/persister-browser/index.d.cts +7 -4
  32. package/@types/persisters/persister-browser/index.d.ts +7 -4
  33. package/@types/persisters/persister-browser/with-schemas/index.d.cts +7 -4
  34. package/@types/persisters/persister-browser/with-schemas/index.d.ts +7 -4
  35. package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +4 -4
  36. package/@types/persisters/persister-cr-sqlite-wasm/index.d.ts +4 -4
  37. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +4 -4
  38. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.ts +4 -4
  39. package/@types/persisters/persister-electric-sql/index.d.cts +4 -4
  40. package/@types/persisters/persister-electric-sql/index.d.ts +4 -4
  41. package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +4 -4
  42. package/@types/persisters/persister-electric-sql/with-schemas/index.d.ts +4 -4
  43. package/@types/persisters/persister-expo-sqlite/index.d.cts +4 -4
  44. package/@types/persisters/persister-expo-sqlite/index.d.ts +4 -4
  45. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +4 -4
  46. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.ts +4 -4
  47. package/@types/persisters/persister-file/index.d.cts +6 -4
  48. package/@types/persisters/persister-file/index.d.ts +6 -4
  49. package/@types/persisters/persister-file/with-schemas/index.d.cts +6 -4
  50. package/@types/persisters/persister-file/with-schemas/index.d.ts +6 -4
  51. package/@types/persisters/persister-indexed-db/index.d.cts +5 -4
  52. package/@types/persisters/persister-indexed-db/index.d.ts +5 -4
  53. package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +5 -4
  54. package/@types/persisters/persister-indexed-db/with-schemas/index.d.ts +5 -4
  55. package/@types/persisters/persister-libsql/index.d.cts +5 -4
  56. package/@types/persisters/persister-libsql/index.d.ts +5 -4
  57. package/@types/persisters/persister-libsql/with-schemas/index.d.cts +5 -4
  58. package/@types/persisters/persister-libsql/with-schemas/index.d.ts +5 -4
  59. package/@types/persisters/persister-partykit-client/index.d.cts +12 -6
  60. package/@types/persisters/persister-partykit-client/index.d.ts +12 -6
  61. package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +12 -6
  62. package/@types/persisters/persister-partykit-client/with-schemas/index.d.ts +12 -6
  63. package/@types/persisters/persister-partykit-server/index.d.cts +11 -3
  64. package/@types/persisters/persister-partykit-server/index.d.ts +11 -3
  65. package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +11 -3
  66. package/@types/persisters/persister-partykit-server/with-schemas/index.d.ts +11 -3
  67. package/@types/persisters/persister-powersync/index.d.cts +5 -4
  68. package/@types/persisters/persister-powersync/index.d.ts +5 -4
  69. package/@types/persisters/persister-powersync/with-schemas/index.d.cts +5 -4
  70. package/@types/persisters/persister-powersync/with-schemas/index.d.ts +5 -4
  71. package/@types/persisters/persister-remote/index.d.cts +6 -4
  72. package/@types/persisters/persister-remote/index.d.ts +6 -4
  73. package/@types/persisters/persister-remote/with-schemas/index.d.cts +6 -4
  74. package/@types/persisters/persister-remote/with-schemas/index.d.ts +6 -4
  75. package/@types/persisters/persister-sqlite-wasm/index.d.cts +4 -4
  76. package/@types/persisters/persister-sqlite-wasm/index.d.ts +4 -4
  77. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +4 -4
  78. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.ts +4 -4
  79. package/@types/persisters/persister-sqlite3/index.d.cts +4 -4
  80. package/@types/persisters/persister-sqlite3/index.d.ts +4 -4
  81. package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +4 -4
  82. package/@types/persisters/persister-sqlite3/with-schemas/index.d.ts +4 -4
  83. package/@types/persisters/persister-yjs/index.d.cts +4 -4
  84. package/@types/persisters/persister-yjs/index.d.ts +4 -4
  85. package/@types/persisters/persister-yjs/with-schemas/index.d.cts +4 -4
  86. package/@types/persisters/persister-yjs/with-schemas/index.d.ts +4 -4
  87. package/@types/persisters/with-schemas/index.d.cts +87 -25
  88. package/@types/persisters/with-schemas/index.d.ts +87 -25
  89. package/@types/queries/index.d.cts +64 -4
  90. package/@types/queries/index.d.ts +64 -4
  91. package/@types/queries/with-schemas/index.d.cts +64 -4
  92. package/@types/queries/with-schemas/index.d.ts +64 -4
  93. package/@types/relationships/index.d.cts +34 -1
  94. package/@types/relationships/index.d.ts +34 -1
  95. package/@types/relationships/with-schemas/index.d.cts +34 -1
  96. package/@types/relationships/with-schemas/index.d.ts +34 -1
  97. package/@types/store/index.d.cts +125 -0
  98. package/@types/store/index.d.ts +125 -0
  99. package/@types/store/with-schemas/index.d.cts +125 -0
  100. package/@types/store/with-schemas/index.d.ts +125 -0
  101. package/@types/synchronizers/index.d.cts +32 -10
  102. package/@types/synchronizers/index.d.ts +32 -10
  103. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +114 -0
  104. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.ts +114 -0
  105. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +128 -0
  106. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.ts +128 -0
  107. package/@types/synchronizers/synchronizer-local/index.d.cts +16 -17
  108. package/@types/synchronizers/synchronizer-local/index.d.ts +16 -17
  109. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +16 -17
  110. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.ts +16 -17
  111. package/@types/synchronizers/synchronizer-ws-client/index.d.cts +66 -6
  112. package/@types/synchronizers/synchronizer-ws-client/index.d.ts +66 -6
  113. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +77 -6
  114. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.ts +77 -6
  115. package/@types/synchronizers/synchronizer-ws-server/index.d.cts +486 -7
  116. package/@types/synchronizers/synchronizer-ws-server/index.d.ts +486 -7
  117. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +486 -7
  118. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +486 -7
  119. package/@types/synchronizers/with-schemas/index.d.cts +29 -11
  120. package/@types/synchronizers/with-schemas/index.d.ts +29 -11
  121. package/@types/tools/index.d.cts +22 -0
  122. package/@types/tools/index.d.ts +22 -0
  123. package/@types/tools/with-schemas/index.d.cts +22 -0
  124. package/@types/tools/with-schemas/index.d.ts +22 -0
  125. package/@types/ui-react/index.d.cts +375 -1
  126. package/@types/ui-react/index.d.ts +375 -1
  127. package/@types/ui-react/with-schemas/index.d.cts +100 -1
  128. package/@types/ui-react/with-schemas/index.d.ts +100 -1
  129. package/@types/ui-react-dom/index.d.cts +112 -0
  130. package/@types/ui-react-dom/index.d.ts +112 -0
  131. package/@types/ui-react-dom/with-schemas/index.d.cts +112 -0
  132. package/@types/ui-react-dom/with-schemas/index.d.ts +112 -0
  133. package/@types/ui-react-inspector/index.d.cts +6 -2
  134. package/@types/ui-react-inspector/index.d.ts +6 -2
  135. package/@types/ui-react-inspector/with-schemas/index.d.cts +118 -2
  136. package/@types/ui-react-inspector/with-schemas/index.d.ts +118 -2
  137. package/@types/with-schemas/index.d.cts +1 -0
  138. package/@types/with-schemas/index.d.ts +1 -0
  139. package/cjs/es6/index.cjs +2 -2
  140. package/cjs/es6/min/synchronizers/synchronizer-broadcast-channel/index.cjs +1 -0
  141. package/cjs/es6/min/synchronizers/synchronizer-broadcast-channel/index.cjs.gz +0 -0
  142. package/cjs/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs +1 -0
  143. package/cjs/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs.gz +0 -0
  144. package/cjs/es6/min/synchronizers/synchronizer-ws-client/index.cjs +1 -1
  145. package/cjs/es6/min/synchronizers/synchronizer-ws-client/index.cjs.gz +0 -0
  146. package/cjs/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +1 -1
  147. package/cjs/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs.gz +0 -0
  148. package/cjs/es6/synchronizers/index.cjs +2 -2
  149. package/cjs/es6/synchronizers/synchronizer-broadcast-channel/index.cjs +628 -0
  150. package/cjs/es6/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs +628 -0
  151. package/cjs/es6/synchronizers/synchronizer-local/index.cjs +4 -4
  152. package/cjs/es6/synchronizers/synchronizer-local/with-schemas/index.cjs +4 -4
  153. package/cjs/es6/synchronizers/synchronizer-ws-client/index.cjs +15 -21
  154. package/cjs/es6/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +15 -21
  155. package/cjs/es6/synchronizers/with-schemas/index.cjs +2 -2
  156. package/cjs/es6/with-schemas/index.cjs +2 -2
  157. package/cjs/index.cjs +2 -2
  158. package/cjs/min/synchronizers/synchronizer-broadcast-channel/index.cjs +1 -0
  159. package/cjs/min/synchronizers/synchronizer-broadcast-channel/index.cjs.gz +0 -0
  160. package/cjs/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs +1 -0
  161. package/cjs/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs.gz +0 -0
  162. package/cjs/min/synchronizers/synchronizer-ws-client/index.cjs +1 -1
  163. package/cjs/min/synchronizers/synchronizer-ws-client/index.cjs.gz +0 -0
  164. package/cjs/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +1 -1
  165. package/cjs/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs.gz +0 -0
  166. package/cjs/synchronizers/index.cjs +2 -2
  167. package/cjs/synchronizers/synchronizer-broadcast-channel/index.cjs +500 -0
  168. package/cjs/synchronizers/synchronizer-broadcast-channel/with-schemas/index.cjs +500 -0
  169. package/cjs/synchronizers/synchronizer-local/index.cjs +4 -4
  170. package/cjs/synchronizers/synchronizer-local/with-schemas/index.cjs +4 -4
  171. package/cjs/synchronizers/synchronizer-ws-client/index.cjs +15 -21
  172. package/cjs/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +15 -21
  173. package/cjs/synchronizers/with-schemas/index.cjs +2 -2
  174. package/cjs/with-schemas/index.cjs +2 -2
  175. package/es6/index.js +2 -2
  176. package/es6/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -0
  177. package/es6/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
  178. package/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -0
  179. package/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
  180. package/es6/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  181. package/es6/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  182. package/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  183. package/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  184. package/es6/synchronizers/index.js +2 -2
  185. package/es6/synchronizers/synchronizer-broadcast-channel/index.js +626 -0
  186. package/es6/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +626 -0
  187. package/es6/synchronizers/synchronizer-local/index.js +4 -4
  188. package/es6/synchronizers/synchronizer-local/with-schemas/index.js +4 -4
  189. package/es6/synchronizers/synchronizer-ws-client/index.js +15 -21
  190. package/es6/synchronizers/synchronizer-ws-client/with-schemas/index.js +15 -21
  191. package/es6/synchronizers/with-schemas/index.js +2 -2
  192. package/es6/with-schemas/index.js +2 -2
  193. package/index.js +2 -2
  194. package/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -0
  195. package/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
  196. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -0
  197. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
  198. package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  199. package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  200. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  201. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  202. package/package.json +105 -1
  203. package/readme.md +9 -9
  204. package/releases.md +4 -4
  205. package/synchronizers/index.js +2 -2
  206. package/synchronizers/synchronizer-broadcast-channel/index.js +498 -0
  207. package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +498 -0
  208. package/synchronizers/synchronizer-local/index.js +4 -4
  209. package/synchronizers/synchronizer-local/with-schemas/index.js +4 -4
  210. package/synchronizers/synchronizer-ws-client/index.js +15 -21
  211. package/synchronizers/synchronizer-ws-client/with-schemas/index.js +15 -21
  212. package/synchronizers/with-schemas/index.js +2 -2
  213. package/umd/es6/index.js +2 -2
  214. package/umd/es6/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -0
  215. package/umd/es6/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
  216. package/umd/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -0
  217. package/umd/es6/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
  218. package/umd/es6/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  219. package/umd/es6/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  220. package/umd/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  221. package/umd/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  222. package/umd/es6/synchronizers/index.js +2 -2
  223. package/umd/es6/synchronizers/synchronizer-broadcast-channel/index.js +654 -0
  224. package/umd/es6/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +654 -0
  225. package/umd/es6/synchronizers/synchronizer-local/index.js +4 -4
  226. package/umd/es6/synchronizers/synchronizer-local/with-schemas/index.js +4 -4
  227. package/umd/es6/synchronizers/synchronizer-ws-client/index.js +15 -21
  228. package/umd/es6/synchronizers/synchronizer-ws-client/with-schemas/index.js +15 -21
  229. package/umd/es6/synchronizers/with-schemas/index.js +2 -2
  230. package/umd/es6/with-schemas/index.js +2 -2
  231. package/umd/index.js +2 -2
  232. package/umd/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -0
  233. package/umd/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
  234. package/umd/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -0
  235. package/umd/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
  236. package/umd/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  237. package/umd/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  238. package/umd/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  239. package/umd/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  240. package/umd/synchronizers/index.js +2 -2
  241. package/umd/synchronizers/synchronizer-broadcast-channel/index.js +516 -0
  242. package/umd/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +516 -0
  243. package/umd/synchronizers/synchronizer-local/index.js +4 -4
  244. package/umd/synchronizers/synchronizer-local/with-schemas/index.js +4 -4
  245. package/umd/synchronizers/synchronizer-ws-client/index.js +15 -21
  246. package/umd/synchronizers/synchronizer-ws-client/with-schemas/index.js +15 -21
  247. package/umd/synchronizers/with-schemas/index.js +2 -2
  248. package/umd/with-schemas/index.js +2 -2
  249. package/with-schemas/index.js +2 -2
@@ -0,0 +1,654 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined'
3
+ ? factory(exports)
4
+ : typeof define === 'function' && define.amd
5
+ ? define(['exports'], factory)
6
+ : ((global =
7
+ typeof globalThis !== 'undefined' ? globalThis : global || self),
8
+ factory((global.TinyBaseSynchronizerBroadcastChannel = {})));
9
+ })(this, function (exports) {
10
+ 'use strict';
11
+
12
+ const EMPTY_STRING = '';
13
+
14
+ const promise = Promise;
15
+ const GLOBAL = globalThis;
16
+ const math = Math;
17
+ const mathFloor = math.floor;
18
+ const isUndefined = (thing) => thing == void 0;
19
+ const ifNotUndefined = (value, then, otherwise) =>
20
+ isUndefined(value)
21
+ ? otherwise == null
22
+ ? void 0
23
+ : otherwise()
24
+ : then(value);
25
+ const isArray = (thing) => Array.isArray(thing);
26
+ const size = (arrayOrString) => arrayOrString.length;
27
+ const promiseNew = (resolver) => new promise(resolver);
28
+ const errorNew = (message) => {
29
+ throw new Error(message);
30
+ };
31
+
32
+ const arrayForEach = (array, cb) => array.forEach(cb);
33
+ const arrayMap = (array, cb) => array.map(cb);
34
+ const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
35
+ const arrayPush = (array, ...values) => array.push(...values);
36
+ const arrayShift = (array) => array.shift();
37
+
38
+ const object = Object;
39
+ const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
40
+ const objEntries = object.entries;
41
+ const isObject = (obj) =>
42
+ !isUndefined(obj) &&
43
+ ifNotUndefined(
44
+ getPrototypeOf(obj),
45
+ (objPrototype) =>
46
+ objPrototype == object.prototype ||
47
+ isUndefined(getPrototypeOf(objPrototype)),
48
+
49
+ /* istanbul ignore next */
50
+ () => true,
51
+ );
52
+ const objIds = object.keys;
53
+ const objFreeze = object.freeze;
54
+ const objNew = (entries = []) => object.fromEntries(entries);
55
+ const objHas = (obj, id) => id in obj;
56
+ const objForEach = (obj, cb) =>
57
+ arrayForEach(objEntries(obj), ([id, value]) => cb(value, id));
58
+ const objSize = (obj) => size(objIds(obj));
59
+ const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
60
+ const objEnsure = (obj, id, getDefaultValue) => {
61
+ if (!objHas(obj, id)) {
62
+ obj[id] = getDefaultValue();
63
+ }
64
+ return obj[id];
65
+ };
66
+
67
+ const collHas = (coll, keyOrValue) => {
68
+ var _a;
69
+ return (_a = coll == null ? void 0 : coll.has(keyOrValue)) != null
70
+ ? _a
71
+ : false;
72
+ };
73
+ const collDel = (coll, keyOrValue) =>
74
+ coll == null ? void 0 : coll.delete(keyOrValue);
75
+
76
+ const mapNew = (entries) => new Map(entries);
77
+ const mapGet = (map, key) => (map == null ? void 0 : map.get(key));
78
+ const mapSet = (map, key, value) =>
79
+ isUndefined(value)
80
+ ? (collDel(map, key), map)
81
+ : map == null
82
+ ? void 0
83
+ : map.set(key, value);
84
+ const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
85
+ if (!collHas(map, key)) {
86
+ mapSet(map, key, getDefaultValue());
87
+ }
88
+ return mapGet(map, key);
89
+ };
90
+
91
+ var __defProp$1 = Object.defineProperty;
92
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
93
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
94
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
95
+ var __defNormalProp$1 = (obj, key, value) =>
96
+ key in obj
97
+ ? __defProp$1(obj, key, {
98
+ enumerable: true,
99
+ configurable: true,
100
+ writable: true,
101
+ value,
102
+ })
103
+ : (obj[key] = value);
104
+ var __spreadValues$1 = (a, b) => {
105
+ for (var prop in b || (b = {}))
106
+ if (__hasOwnProp$1.call(b, prop)) __defNormalProp$1(a, prop, b[prop]);
107
+ if (__getOwnPropSymbols$1)
108
+ for (var prop of __getOwnPropSymbols$1(b)) {
109
+ if (__propIsEnum$1.call(b, prop)) __defNormalProp$1(a, prop, b[prop]);
110
+ }
111
+ return a;
112
+ };
113
+ var __async$1 = (__this, __arguments, generator) => {
114
+ return new Promise((resolve, reject) => {
115
+ var fulfilled = (value) => {
116
+ try {
117
+ step(generator.next(value));
118
+ } catch (e) {
119
+ reject(e);
120
+ }
121
+ };
122
+ var rejected = (value) => {
123
+ try {
124
+ step(generator.throw(value));
125
+ } catch (e) {
126
+ reject(e);
127
+ }
128
+ };
129
+ var step = (x) =>
130
+ x.done
131
+ ? resolve(x.value)
132
+ : Promise.resolve(x.value).then(fulfilled, rejected);
133
+ step((generator = generator.apply(__this, __arguments)).next());
134
+ });
135
+ };
136
+ const Persists = {
137
+ StoreOnly: 1,
138
+ MergeableStoreOnly: 2,
139
+ StoreOrMergeableStore: 3,
140
+ };
141
+ const scheduleRunning = mapNew();
142
+ const scheduleActions = mapNew();
143
+ const getStoreFunctions = (persist = Persists.StoreOnly, store) =>
144
+ persist != Persists.StoreOnly && store.isMergeable()
145
+ ? [
146
+ 1,
147
+ store.getMergeableContent,
148
+ store.getTransactionMergeableChanges,
149
+ ([[changedTables], [changedValues]]) =>
150
+ !objIsEmpty(changedTables) || !objIsEmpty(changedValues),
151
+ store.setDefaultContent,
152
+ ]
153
+ : persist != Persists.MergeableStoreOnly
154
+ ? [
155
+ 0,
156
+ store.getContent,
157
+ store.getTransactionChanges,
158
+ ([changedTables, changedValues]) =>
159
+ !objIsEmpty(changedTables) || !objIsEmpty(changedValues),
160
+ store.setContent,
161
+ ]
162
+ : errorNew('Store type not supported by this Persister');
163
+ const createCustomPersister = (
164
+ store,
165
+ getPersisted,
166
+ setPersisted,
167
+ addPersisterListener,
168
+ delPersisterListener,
169
+ onIgnoredError,
170
+ persist,
171
+ extra = {},
172
+ scheduleId = [],
173
+ ) => {
174
+ let loadSave = 0;
175
+ let loads = 0;
176
+ let saves = 0;
177
+ let action;
178
+ let autoLoadHandle;
179
+ let autoSaveListenerId;
180
+ mapEnsure(scheduleRunning, scheduleId, () => 0);
181
+ mapEnsure(scheduleActions, scheduleId, () => []);
182
+ const [
183
+ isMergeableStore,
184
+ getContent,
185
+ getChanges,
186
+ hasChanges,
187
+ setDefaultContent,
188
+ ] = getStoreFunctions(persist, store);
189
+ const run = () =>
190
+ __async$1(void 0, null, function* () {
191
+ /* istanbul ignore else */
192
+ if (!mapGet(scheduleRunning, scheduleId)) {
193
+ mapSet(scheduleRunning, scheduleId, 1);
194
+ while (
195
+ !isUndefined(
196
+ (action = arrayShift(mapGet(scheduleActions, scheduleId))),
197
+ )
198
+ ) {
199
+ try {
200
+ yield action();
201
+ } catch (error) {
202
+ /* istanbul ignore next */
203
+ onIgnoredError == null ? void 0 : onIgnoredError(error);
204
+ }
205
+ }
206
+ mapSet(scheduleRunning, scheduleId, 0);
207
+ }
208
+ });
209
+ const setContentOrChanges = (contentOrChanges) => {
210
+ (isMergeableStore &&
211
+ isArray(contentOrChanges == null ? void 0 : contentOrChanges[0])
212
+ ? (contentOrChanges == null ? void 0 : contentOrChanges[2]) === 1
213
+ ? store.applyMergeableChanges
214
+ : store.setMergeableContent
215
+ : (contentOrChanges == null ? void 0 : contentOrChanges[2]) === 1
216
+ ? store.applyChanges
217
+ : store.setContent)(contentOrChanges);
218
+ };
219
+ const load = (initialContent) =>
220
+ __async$1(void 0, null, function* () {
221
+ /* istanbul ignore else */
222
+ if (loadSave != 2) {
223
+ loadSave = 1;
224
+ loads++;
225
+ yield schedule(() =>
226
+ __async$1(void 0, null, function* () {
227
+ try {
228
+ setContentOrChanges(yield getPersisted());
229
+ } catch (error) {
230
+ onIgnoredError == null ? void 0 : onIgnoredError(error);
231
+ if (initialContent) {
232
+ setDefaultContent(initialContent);
233
+ }
234
+ }
235
+ loadSave = 0;
236
+ }),
237
+ );
238
+ }
239
+ return persister;
240
+ });
241
+ const startAutoLoad = (initialContent) =>
242
+ __async$1(void 0, null, function* () {
243
+ yield stopAutoLoad().load(initialContent);
244
+ autoLoadHandle = addPersisterListener((content, changes) =>
245
+ __async$1(void 0, null, function* () {
246
+ if (changes || content) {
247
+ /* istanbul ignore else */
248
+ if (loadSave != 2) {
249
+ loadSave = 1;
250
+ loads++;
251
+ setContentOrChanges(changes != null ? changes : content);
252
+ loadSave = 0;
253
+ }
254
+ } else {
255
+ yield load();
256
+ }
257
+ }),
258
+ );
259
+ return persister;
260
+ });
261
+ const stopAutoLoad = () => {
262
+ if (autoLoadHandle) {
263
+ delPersisterListener(autoLoadHandle);
264
+ autoLoadHandle = void 0;
265
+ }
266
+ return persister;
267
+ };
268
+ const isAutoLoading = () => !isUndefined(autoLoadHandle);
269
+ const save = (changes) =>
270
+ __async$1(void 0, null, function* () {
271
+ /* istanbul ignore else */
272
+ if (loadSave != 1) {
273
+ loadSave = 2;
274
+ saves++;
275
+ yield schedule(() =>
276
+ __async$1(void 0, null, function* () {
277
+ try {
278
+ yield setPersisted(getContent, changes);
279
+ } catch (error) {
280
+ /* istanbul ignore next */
281
+ onIgnoredError == null ? void 0 : onIgnoredError(error);
282
+ }
283
+ loadSave = 0;
284
+ }),
285
+ );
286
+ }
287
+ return persister;
288
+ });
289
+ const startAutoSave = () =>
290
+ __async$1(void 0, null, function* () {
291
+ yield stopAutoSave().save();
292
+ autoSaveListenerId = store.addDidFinishTransactionListener(() => {
293
+ const changes = getChanges();
294
+ if (hasChanges(changes)) {
295
+ save(changes);
296
+ }
297
+ });
298
+ return persister;
299
+ });
300
+ const stopAutoSave = () => {
301
+ ifNotUndefined(autoSaveListenerId, store.delListener);
302
+ autoSaveListenerId = void 0;
303
+ return persister;
304
+ };
305
+ const isAutoSaving = () => !isUndefined(autoSaveListenerId);
306
+ const schedule = (...actions) =>
307
+ __async$1(void 0, null, function* () {
308
+ arrayPush(mapGet(scheduleActions, scheduleId), ...actions);
309
+ yield run();
310
+ return persister;
311
+ });
312
+ const getStore = () => store;
313
+ const destroy = () => stopAutoLoad().stopAutoSave();
314
+ const getStats = () => ({loads, saves});
315
+ const persister = __spreadValues$1(
316
+ {
317
+ load,
318
+ startAutoLoad,
319
+ stopAutoLoad,
320
+ isAutoLoading,
321
+ save,
322
+ startAutoSave,
323
+ stopAutoSave,
324
+ isAutoSaving,
325
+ schedule,
326
+ getStore,
327
+ destroy,
328
+ getStats,
329
+ },
330
+ extra,
331
+ );
332
+ return objFreeze(persister);
333
+ };
334
+
335
+ new GLOBAL.TextEncoder();
336
+
337
+ const newStamp = (value, time) => (time ? [value, time] : [value]);
338
+ const getLatestTime = (time1, time2) => {
339
+ var _a;
340
+ return (_a =
341
+ (time1 != null ? time1 : '') > (time2 != null ? time2 : '')
342
+ ? time1
343
+ : time2) != null
344
+ ? _a
345
+ : '';
346
+ };
347
+ const stampNewObj = (time = EMPTY_STRING) => newStamp(objNew(), time);
348
+
349
+ const MASK6 = 63;
350
+ const ENCODE =
351
+ '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'.split(
352
+ EMPTY_STRING,
353
+ );
354
+ mapNew(arrayMap(ENCODE, (char, index) => [char, index]));
355
+ const encode = (num) => ENCODE[num & MASK6];
356
+
357
+ const getRandomValues = GLOBAL.crypto
358
+ ? (array) => GLOBAL.crypto.getRandomValues(array)
359
+ : /* istanbul ignore next */
360
+ (array) => arrayMap(array, () => mathFloor(math.random() * 256));
361
+ const getUniqueId = (length = 16) =>
362
+ arrayReduce(
363
+ getRandomValues(new Uint8Array(length)),
364
+ (uniqueId, number) => uniqueId + encode(number),
365
+ '',
366
+ );
367
+
368
+ var __defProp = Object.defineProperty;
369
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
370
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
371
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
372
+ var __defNormalProp = (obj, key, value) =>
373
+ key in obj
374
+ ? __defProp(obj, key, {
375
+ enumerable: true,
376
+ configurable: true,
377
+ writable: true,
378
+ value,
379
+ })
380
+ : (obj[key] = value);
381
+ var __spreadValues = (a, b) => {
382
+ for (var prop in b || (b = {}))
383
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
384
+ if (__getOwnPropSymbols)
385
+ for (var prop of __getOwnPropSymbols(b)) {
386
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
387
+ }
388
+ return a;
389
+ };
390
+ var __async = (__this, __arguments, generator) => {
391
+ return new Promise((resolve, reject) => {
392
+ var fulfilled = (value) => {
393
+ try {
394
+ step(generator.next(value));
395
+ } catch (e) {
396
+ reject(e);
397
+ }
398
+ };
399
+ var rejected = (value) => {
400
+ try {
401
+ step(generator.throw(value));
402
+ } catch (e) {
403
+ reject(e);
404
+ }
405
+ };
406
+ var step = (x) =>
407
+ x.done
408
+ ? resolve(x.value)
409
+ : Promise.resolve(x.value).then(fulfilled, rejected);
410
+ step((generator = generator.apply(__this, __arguments)).next());
411
+ });
412
+ };
413
+ const Message = {
414
+ Response: 0,
415
+ GetContentHashes: 1,
416
+ ContentHashes: 2,
417
+ ContentDiff: 3,
418
+ GetTableDiff: 4,
419
+ GetRowDiff: 5,
420
+ GetCellDiff: 6,
421
+ GetValueDiff: 7,
422
+ };
423
+ const createCustomSynchronizer = (
424
+ store,
425
+ send,
426
+ registerReceive,
427
+ destroyImpl,
428
+ requestTimeoutSeconds,
429
+ onIgnoredError,
430
+ extra = {},
431
+ ) => {
432
+ let persisterListener;
433
+ let sends = 0;
434
+ let receives = 0;
435
+ const pendingRequests = mapNew();
436
+ registerReceive((fromClientId, requestId, message, body) => {
437
+ receives++;
438
+ if (message == Message.Response) {
439
+ ifNotUndefined(
440
+ mapGet(pendingRequests, requestId),
441
+ ([toClientId, handleResponse]) =>
442
+ isUndefined(toClientId) || toClientId == fromClientId
443
+ ? handleResponse(body, fromClientId)
444
+ : /* istanbul ignore next */
445
+ 0,
446
+ );
447
+ } else if (
448
+ message == Message.ContentHashes &&
449
+ persister.isAutoLoading()
450
+ ) {
451
+ getChangesFromOtherStore(fromClientId, body).then((changes) => {
452
+ persisterListener == null
453
+ ? void 0
454
+ : persisterListener(void 0, changes);
455
+ });
456
+ } else if (message == Message.ContentDiff && persister.isAutoLoading()) {
457
+ persisterListener == null ? void 0 : persisterListener(void 0, body);
458
+ } else {
459
+ ifNotUndefined(
460
+ message == Message.GetContentHashes && persister.isAutoSaving()
461
+ ? store.getMergeableContentHashes()
462
+ : message == Message.GetTableDiff
463
+ ? store.getMergeableTableDiff(body)
464
+ : message == Message.GetRowDiff
465
+ ? store.getMergeableRowDiff(body)
466
+ : message == Message.GetCellDiff
467
+ ? store.getMergeableCellDiff(body)
468
+ : message == Message.GetValueDiff
469
+ ? store.getMergeableValueDiff(body)
470
+ : void 0,
471
+ (response) => {
472
+ sends++;
473
+ send(fromClientId, requestId, Message.Response, response);
474
+ },
475
+ );
476
+ }
477
+ });
478
+ const request = (_0, _1, ..._2) =>
479
+ __async(
480
+ void 0,
481
+ [_0, _1, ..._2],
482
+ function* (toClientId, message, body = EMPTY_STRING) {
483
+ return promiseNew((resolve, reject) => {
484
+ const requestId = getUniqueId();
485
+ const timeout = setTimeout(() => {
486
+ collDel(pendingRequests, requestId);
487
+ reject(
488
+ `No response from ${toClientId != null ? toClientId : 'anyone'} to '${message}'`,
489
+ );
490
+ }, requestTimeoutSeconds * 1e3);
491
+ mapSet(pendingRequests, requestId, [
492
+ toClientId,
493
+ (response, fromClientId) => {
494
+ clearTimeout(timeout);
495
+ collDel(pendingRequests, requestId);
496
+ resolve([response, fromClientId]);
497
+ },
498
+ ]);
499
+ sends++;
500
+ send(toClientId, requestId, message, body);
501
+ });
502
+ },
503
+ );
504
+ const mergeTablesStamps = (tablesStamp, [tableStamps2, tablesTime2]) => {
505
+ objForEach(tableStamps2, ([rowStamps2, tableTime2], tableId) => {
506
+ const tableStamp = objEnsure(tablesStamp[0], tableId, stampNewObj);
507
+ objForEach(rowStamps2, ([cellStamps2, rowTime2], rowId) => {
508
+ const rowStamp = objEnsure(tableStamp[0], rowId, stampNewObj);
509
+ objForEach(
510
+ cellStamps2,
511
+ ([cell2, cellTime2], cellId) =>
512
+ (rowStamp[0][cellId] = newStamp(cell2, cellTime2)),
513
+ );
514
+ rowStamp[1] = getLatestTime(rowStamp[1], rowTime2);
515
+ });
516
+ tableStamp[1] = getLatestTime(tableStamp[1], tableTime2);
517
+ });
518
+ tablesStamp[1] = getLatestTime(tablesStamp[1], tablesTime2);
519
+ };
520
+ const getChangesFromOtherStore = (
521
+ otherClientId = null,
522
+ otherContentHashes,
523
+ ) =>
524
+ __async(void 0, null, function* () {
525
+ if (isUndefined(otherContentHashes)) {
526
+ [otherContentHashes, otherClientId] = yield request(
527
+ otherClientId,
528
+ Message.GetContentHashes,
529
+ );
530
+ }
531
+ const [otherTablesHash, otherValuesHash] = otherContentHashes;
532
+ const [tablesHash, valuesHash] = store.getMergeableContentHashes();
533
+ let tablesChanges = stampNewObj();
534
+ if (tablesHash != otherTablesHash) {
535
+ const [newTables, differentTableHashes] = (yield request(
536
+ otherClientId,
537
+ Message.GetTableDiff,
538
+ store.getMergeableTableHashes(),
539
+ ))[0];
540
+ tablesChanges = newTables;
541
+ if (!objIsEmpty(differentTableHashes)) {
542
+ const [newRows, differentRowHashes] = (yield request(
543
+ otherClientId,
544
+ Message.GetRowDiff,
545
+ store.getMergeableRowHashes(differentTableHashes),
546
+ ))[0];
547
+ mergeTablesStamps(tablesChanges, newRows);
548
+ if (!objIsEmpty(differentRowHashes)) {
549
+ const newCells = (yield request(
550
+ otherClientId,
551
+ Message.GetCellDiff,
552
+ store.getMergeableCellHashes(differentRowHashes),
553
+ ))[0];
554
+ mergeTablesStamps(tablesChanges, newCells);
555
+ }
556
+ }
557
+ }
558
+ return [
559
+ tablesChanges,
560
+ valuesHash == otherValuesHash
561
+ ? stampNewObj()
562
+ : (yield request(
563
+ otherClientId,
564
+ Message.GetValueDiff,
565
+ store.getMergeableValueHashes(),
566
+ ))[0],
567
+ 1,
568
+ ];
569
+ });
570
+ const getPersisted = () =>
571
+ __async(void 0, null, function* () {
572
+ const changes = yield getChangesFromOtherStore();
573
+ return !objIsEmpty(changes[0][0]) || !objIsEmpty(changes[1][0])
574
+ ? changes
575
+ : void 0;
576
+ });
577
+ const setPersisted = (_getContent, changes) =>
578
+ __async(void 0, null, function* () {
579
+ sends++;
580
+ if (changes) {
581
+ send(null, null, Message.ContentDiff, changes);
582
+ } else {
583
+ send(
584
+ null,
585
+ null,
586
+ Message.ContentHashes,
587
+ store.getMergeableContentHashes(),
588
+ );
589
+ }
590
+ });
591
+ const addPersisterListener = (listener) => (persisterListener = listener);
592
+ const delPersisterListener = () => (persisterListener = void 0);
593
+ const startSync = (initialContent) =>
594
+ __async(void 0, null, function* () {
595
+ return yield (yield persister.startAutoLoad(
596
+ initialContent,
597
+ )).startAutoSave();
598
+ });
599
+ const stopSync = () => persister.stopAutoLoad().stopAutoSave();
600
+ const destroy = () => {
601
+ destroyImpl();
602
+ return persister.stopSync();
603
+ };
604
+ const getSynchronizerStats = () => ({sends, receives});
605
+ const persister = createCustomPersister(
606
+ store,
607
+ getPersisted,
608
+ setPersisted,
609
+ addPersisterListener,
610
+ delPersisterListener,
611
+ onIgnoredError,
612
+ Persists.MergeableStoreOnly,
613
+ __spreadValues(
614
+ {startSync, stopSync, destroy, getSynchronizerStats},
615
+ extra,
616
+ ),
617
+ );
618
+ return persister;
619
+ };
620
+
621
+ const createBroadcastChannelSynchronizer = (
622
+ store,
623
+ channelName,
624
+ onIgnoredError,
625
+ ) => {
626
+ const clientId = getUniqueId();
627
+ const channel = new BroadcastChannel(channelName);
628
+ const send = (toClientId, requestId, message, body) =>
629
+ channel.postMessage([clientId, toClientId, requestId, message, body]);
630
+ const registerReceive = (receive) => {
631
+ channel.onmessage = ({
632
+ data: [fromClientId, toClientId, requestId, message, body],
633
+ }) =>
634
+ isUndefined(toClientId) || toClientId == clientId
635
+ ? receive(fromClientId, requestId, message, body)
636
+ : 0;
637
+ };
638
+ const destroy = () => {
639
+ channel.close();
640
+ };
641
+ return createCustomSynchronizer(
642
+ store,
643
+ send,
644
+ registerReceive,
645
+ destroy,
646
+ 0.01,
647
+ onIgnoredError,
648
+ {getChannelName: () => channelName},
649
+ );
650
+ };
651
+
652
+ exports.createBroadcastChannelSynchronizer =
653
+ createBroadcastChannelSynchronizer;
654
+ });