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