tinybase 5.4.0-beta.1 → 5.4.0-beta.2

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 (274) hide show
  1. package/@types/synchronizers/synchronizer-ws-server/index.d.cts +1 -0
  2. package/@types/synchronizers/synchronizer-ws-server/index.d.ts +1 -0
  3. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +1 -0
  4. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +1 -0
  5. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +62 -0
  6. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.ts +62 -0
  7. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +62 -0
  8. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.ts +62 -0
  9. package/cjs/es6/index.cjs +5 -5
  10. package/cjs/es6/mergeable-store/index.cjs +5 -5
  11. package/cjs/es6/mergeable-store/with-schemas/index.cjs +5 -5
  12. package/cjs/es6/min/index.cjs +1 -1
  13. package/cjs/es6/min/index.cjs.gz +0 -0
  14. package/cjs/es6/min/mergeable-store/index.cjs +1 -1
  15. package/cjs/es6/min/mergeable-store/index.cjs.gz +0 -0
  16. package/cjs/es6/min/mergeable-store/with-schemas/index.cjs +1 -1
  17. package/cjs/es6/min/mergeable-store/with-schemas/index.cjs.gz +0 -0
  18. package/cjs/es6/min/store/index.cjs +1 -1
  19. package/cjs/es6/min/store/index.cjs.gz +0 -0
  20. package/cjs/es6/min/store/with-schemas/index.cjs +1 -1
  21. package/cjs/es6/min/store/with-schemas/index.cjs.gz +0 -0
  22. package/cjs/es6/min/synchronizers/synchronizer-ws-client/index.cjs +1 -1
  23. package/cjs/es6/min/synchronizers/synchronizer-ws-client/index.cjs.gz +0 -0
  24. package/cjs/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +1 -1
  25. package/cjs/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs.gz +0 -0
  26. package/cjs/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.cjs +1 -0
  27. package/cjs/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.cjs.gz +0 -0
  28. package/cjs/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs +1 -0
  29. package/cjs/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs.gz +0 -0
  30. package/cjs/es6/min/synchronizers/synchronizer-ws-server-simple/index.cjs +1 -1
  31. package/cjs/es6/min/synchronizers/synchronizer-ws-server-simple/index.cjs.gz +0 -0
  32. package/cjs/es6/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.cjs +1 -1
  33. package/cjs/es6/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.cjs.gz +0 -0
  34. package/cjs/es6/min/ui-react-inspector/index.cjs +1 -1
  35. package/cjs/es6/min/ui-react-inspector/index.cjs.gz +0 -0
  36. package/cjs/es6/min/ui-react-inspector/with-schemas/index.cjs +1 -1
  37. package/cjs/es6/min/ui-react-inspector/with-schemas/index.cjs.gz +0 -0
  38. package/cjs/es6/min/with-schemas/index.cjs +1 -1
  39. package/cjs/es6/min/with-schemas/index.cjs.gz +0 -0
  40. package/cjs/es6/store/index.cjs +5 -5
  41. package/cjs/es6/store/with-schemas/index.cjs +5 -5
  42. package/cjs/es6/synchronizers/synchronizer-ws-client/index.cjs +2 -2
  43. package/cjs/es6/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +2 -2
  44. package/cjs/es6/synchronizers/synchronizer-ws-server/index.cjs +9 -11
  45. package/cjs/es6/synchronizers/synchronizer-ws-server/with-schemas/index.cjs +9 -11
  46. package/cjs/es6/synchronizers/synchronizer-ws-server-durable-object/index.cjs +116 -0
  47. package/cjs/es6/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs +116 -0
  48. package/cjs/es6/synchronizers/synchronizer-ws-server-simple/index.cjs +11 -12
  49. package/cjs/es6/synchronizers/synchronizer-ws-server-simple/with-schemas/index.cjs +11 -12
  50. package/cjs/es6/ui-react-inspector/index.cjs +5 -5
  51. package/cjs/es6/ui-react-inspector/with-schemas/index.cjs +5 -5
  52. package/cjs/es6/with-schemas/index.cjs +5 -5
  53. package/cjs/index.cjs +5 -5
  54. package/cjs/mergeable-store/index.cjs +5 -5
  55. package/cjs/mergeable-store/with-schemas/index.cjs +5 -5
  56. package/cjs/min/index.cjs +1 -1
  57. package/cjs/min/index.cjs.gz +0 -0
  58. package/cjs/min/mergeable-store/index.cjs +1 -1
  59. package/cjs/min/mergeable-store/index.cjs.gz +0 -0
  60. package/cjs/min/mergeable-store/with-schemas/index.cjs +1 -1
  61. package/cjs/min/mergeable-store/with-schemas/index.cjs.gz +0 -0
  62. package/cjs/min/store/index.cjs +1 -1
  63. package/cjs/min/store/index.cjs.gz +0 -0
  64. package/cjs/min/store/with-schemas/index.cjs +1 -1
  65. package/cjs/min/store/with-schemas/index.cjs.gz +0 -0
  66. package/cjs/min/synchronizers/synchronizer-ws-client/index.cjs +1 -1
  67. package/cjs/min/synchronizers/synchronizer-ws-client/index.cjs.gz +0 -0
  68. package/cjs/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +1 -1
  69. package/cjs/min/synchronizers/synchronizer-ws-client/with-schemas/index.cjs.gz +0 -0
  70. package/cjs/min/synchronizers/synchronizer-ws-server-durable-object/index.cjs +1 -0
  71. package/cjs/min/synchronizers/synchronizer-ws-server-durable-object/index.cjs.gz +0 -0
  72. package/cjs/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs +1 -0
  73. package/cjs/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs.gz +0 -0
  74. package/cjs/min/synchronizers/synchronizer-ws-server-simple/index.cjs +1 -1
  75. package/cjs/min/synchronizers/synchronizer-ws-server-simple/index.cjs.gz +0 -0
  76. package/cjs/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.cjs +1 -1
  77. package/cjs/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.cjs.gz +0 -0
  78. package/cjs/min/ui-react-inspector/index.cjs +1 -1
  79. package/cjs/min/ui-react-inspector/index.cjs.gz +0 -0
  80. package/cjs/min/ui-react-inspector/with-schemas/index.cjs +1 -1
  81. package/cjs/min/ui-react-inspector/with-schemas/index.cjs.gz +0 -0
  82. package/cjs/min/with-schemas/index.cjs +1 -1
  83. package/cjs/min/with-schemas/index.cjs.gz +0 -0
  84. package/cjs/store/index.cjs +5 -5
  85. package/cjs/store/with-schemas/index.cjs +5 -5
  86. package/cjs/synchronizers/synchronizer-ws-client/index.cjs +2 -2
  87. package/cjs/synchronizers/synchronizer-ws-client/with-schemas/index.cjs +2 -2
  88. package/cjs/synchronizers/synchronizer-ws-server/index.cjs +9 -11
  89. package/cjs/synchronizers/synchronizer-ws-server/with-schemas/index.cjs +9 -11
  90. package/cjs/synchronizers/synchronizer-ws-server-durable-object/index.cjs +102 -0
  91. package/cjs/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.cjs +102 -0
  92. package/cjs/synchronizers/synchronizer-ws-server-simple/index.cjs +11 -12
  93. package/cjs/synchronizers/synchronizer-ws-server-simple/with-schemas/index.cjs +11 -12
  94. package/cjs/ui-react-inspector/index.cjs +5 -5
  95. package/cjs/ui-react-inspector/with-schemas/index.cjs +5 -5
  96. package/cjs/with-schemas/index.cjs +5 -5
  97. package/es6/index.js +5 -5
  98. package/es6/mergeable-store/index.js +5 -5
  99. package/es6/mergeable-store/with-schemas/index.js +5 -5
  100. package/es6/min/index.js +1 -1
  101. package/es6/min/index.js.gz +0 -0
  102. package/es6/min/mergeable-store/index.js +1 -1
  103. package/es6/min/mergeable-store/index.js.gz +0 -0
  104. package/es6/min/mergeable-store/with-schemas/index.js +1 -1
  105. package/es6/min/mergeable-store/with-schemas/index.js.gz +0 -0
  106. package/es6/min/store/index.js +1 -1
  107. package/es6/min/store/index.js.gz +0 -0
  108. package/es6/min/store/with-schemas/index.js +1 -1
  109. package/es6/min/store/with-schemas/index.js.gz +0 -0
  110. package/es6/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  111. package/es6/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  112. package/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  113. package/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  114. package/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -0
  115. package/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
  116. package/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -0
  117. package/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
  118. package/es6/min/synchronizers/synchronizer-ws-server-simple/index.js +1 -1
  119. package/es6/min/synchronizers/synchronizer-ws-server-simple/index.js.gz +0 -0
  120. package/es6/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +1 -1
  121. package/es6/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js.gz +0 -0
  122. package/es6/min/ui-react-inspector/index.js +1 -1
  123. package/es6/min/ui-react-inspector/index.js.gz +0 -0
  124. package/es6/min/ui-react-inspector/with-schemas/index.js +1 -1
  125. package/es6/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  126. package/es6/min/with-schemas/index.js +1 -1
  127. package/es6/min/with-schemas/index.js.gz +0 -0
  128. package/es6/store/index.js +5 -5
  129. package/es6/store/with-schemas/index.js +5 -5
  130. package/es6/synchronizers/synchronizer-ws-client/index.js +2 -2
  131. package/es6/synchronizers/synchronizer-ws-client/with-schemas/index.js +2 -2
  132. package/es6/synchronizers/synchronizer-ws-server/index.js +9 -11
  133. package/es6/synchronizers/synchronizer-ws-server/with-schemas/index.js +9 -11
  134. package/es6/synchronizers/synchronizer-ws-server-durable-object/index.js +113 -0
  135. package/es6/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +113 -0
  136. package/es6/synchronizers/synchronizer-ws-server-simple/index.js +11 -12
  137. package/es6/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +11 -12
  138. package/es6/ui-react-inspector/index.js +5 -5
  139. package/es6/ui-react-inspector/with-schemas/index.js +5 -5
  140. package/es6/with-schemas/index.js +5 -5
  141. package/index.js +5 -5
  142. package/mergeable-store/index.js +5 -5
  143. package/mergeable-store/with-schemas/index.js +5 -5
  144. package/min/index.js +1 -1
  145. package/min/index.js.gz +0 -0
  146. package/min/mergeable-store/index.js +1 -1
  147. package/min/mergeable-store/index.js.gz +0 -0
  148. package/min/mergeable-store/with-schemas/index.js +1 -1
  149. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  150. package/min/store/index.js +1 -1
  151. package/min/store/index.js.gz +0 -0
  152. package/min/store/with-schemas/index.js +1 -1
  153. package/min/store/with-schemas/index.js.gz +0 -0
  154. package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  155. package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  156. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  157. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  158. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -0
  159. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
  160. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -0
  161. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
  162. package/min/synchronizers/synchronizer-ws-server-simple/index.js +1 -1
  163. package/min/synchronizers/synchronizer-ws-server-simple/index.js.gz +0 -0
  164. package/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +1 -1
  165. package/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js.gz +0 -0
  166. package/min/ui-react-inspector/index.js +1 -1
  167. package/min/ui-react-inspector/index.js.gz +0 -0
  168. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  169. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  170. package/min/with-schemas/index.js +1 -1
  171. package/min/with-schemas/index.js.gz +0 -0
  172. package/package.json +110 -2
  173. package/readme.md +1 -1
  174. package/store/index.js +5 -5
  175. package/store/with-schemas/index.js +5 -5
  176. package/synchronizers/synchronizer-ws-client/index.js +2 -2
  177. package/synchronizers/synchronizer-ws-client/with-schemas/index.js +2 -2
  178. package/synchronizers/synchronizer-ws-server/index.js +9 -11
  179. package/synchronizers/synchronizer-ws-server/with-schemas/index.js +9 -11
  180. package/synchronizers/synchronizer-ws-server-durable-object/index.js +99 -0
  181. package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +99 -0
  182. package/synchronizers/synchronizer-ws-server-simple/index.js +11 -12
  183. package/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +11 -12
  184. package/ui-react-inspector/index.js +5 -5
  185. package/ui-react-inspector/with-schemas/index.js +5 -5
  186. package/umd/es6/index.js +5 -5
  187. package/umd/es6/mergeable-store/index.js +5 -5
  188. package/umd/es6/mergeable-store/with-schemas/index.js +5 -5
  189. package/umd/es6/min/index.js +1 -1
  190. package/umd/es6/min/index.js.gz +0 -0
  191. package/umd/es6/min/mergeable-store/index.js +1 -1
  192. package/umd/es6/min/mergeable-store/index.js.gz +0 -0
  193. package/umd/es6/min/mergeable-store/with-schemas/index.js +1 -1
  194. package/umd/es6/min/mergeable-store/with-schemas/index.js.gz +0 -0
  195. package/umd/es6/min/store/index.js +1 -1
  196. package/umd/es6/min/store/index.js.gz +0 -0
  197. package/umd/es6/min/store/with-schemas/index.js +1 -1
  198. package/umd/es6/min/store/with-schemas/index.js.gz +0 -0
  199. package/umd/es6/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  200. package/umd/es6/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  201. package/umd/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  202. package/umd/es6/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  203. package/umd/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -0
  204. package/umd/es6/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
  205. package/umd/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -0
  206. package/umd/es6/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
  207. package/umd/es6/min/synchronizers/synchronizer-ws-server-simple/index.js +1 -1
  208. package/umd/es6/min/synchronizers/synchronizer-ws-server-simple/index.js.gz +0 -0
  209. package/umd/es6/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +1 -1
  210. package/umd/es6/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js.gz +0 -0
  211. package/umd/es6/min/ui-react-inspector/index.js +1 -1
  212. package/umd/es6/min/ui-react-inspector/index.js.gz +0 -0
  213. package/umd/es6/min/ui-react-inspector/with-schemas/index.js +1 -1
  214. package/umd/es6/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  215. package/umd/es6/min/with-schemas/index.js +1 -1
  216. package/umd/es6/min/with-schemas/index.js.gz +0 -0
  217. package/umd/es6/store/index.js +5 -5
  218. package/umd/es6/store/with-schemas/index.js +5 -5
  219. package/umd/es6/synchronizers/synchronizer-ws-client/index.js +2 -2
  220. package/umd/es6/synchronizers/synchronizer-ws-client/with-schemas/index.js +2 -2
  221. package/umd/es6/synchronizers/synchronizer-ws-server/index.js +9 -11
  222. package/umd/es6/synchronizers/synchronizer-ws-server/with-schemas/index.js +9 -11
  223. package/umd/es6/synchronizers/synchronizer-ws-server-durable-object/index.js +131 -0
  224. package/umd/es6/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +131 -0
  225. package/umd/es6/synchronizers/synchronizer-ws-server-simple/index.js +11 -12
  226. package/umd/es6/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +11 -12
  227. package/umd/es6/ui-react-inspector/index.js +5 -5
  228. package/umd/es6/ui-react-inspector/with-schemas/index.js +5 -5
  229. package/umd/es6/with-schemas/index.js +5 -5
  230. package/umd/index.js +5 -5
  231. package/umd/mergeable-store/index.js +5 -5
  232. package/umd/mergeable-store/with-schemas/index.js +5 -5
  233. package/umd/min/index.js +1 -1
  234. package/umd/min/index.js.gz +0 -0
  235. package/umd/min/mergeable-store/index.js +1 -1
  236. package/umd/min/mergeable-store/index.js.gz +0 -0
  237. package/umd/min/mergeable-store/with-schemas/index.js +1 -1
  238. package/umd/min/mergeable-store/with-schemas/index.js.gz +0 -0
  239. package/umd/min/store/index.js +1 -1
  240. package/umd/min/store/index.js.gz +0 -0
  241. package/umd/min/store/with-schemas/index.js +1 -1
  242. package/umd/min/store/with-schemas/index.js.gz +0 -0
  243. package/umd/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  244. package/umd/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  245. package/umd/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  246. package/umd/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  247. package/umd/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -0
  248. package/umd/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
  249. package/umd/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -0
  250. package/umd/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
  251. package/umd/min/synchronizers/synchronizer-ws-server-simple/index.js +1 -1
  252. package/umd/min/synchronizers/synchronizer-ws-server-simple/index.js.gz +0 -0
  253. package/umd/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +1 -1
  254. package/umd/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js.gz +0 -0
  255. package/umd/min/ui-react-inspector/index.js +1 -1
  256. package/umd/min/ui-react-inspector/index.js.gz +0 -0
  257. package/umd/min/ui-react-inspector/with-schemas/index.js +1 -1
  258. package/umd/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  259. package/umd/min/with-schemas/index.js +1 -1
  260. package/umd/min/with-schemas/index.js.gz +0 -0
  261. package/umd/store/index.js +5 -5
  262. package/umd/store/with-schemas/index.js +5 -5
  263. package/umd/synchronizers/synchronizer-ws-client/index.js +2 -2
  264. package/umd/synchronizers/synchronizer-ws-client/with-schemas/index.js +2 -2
  265. package/umd/synchronizers/synchronizer-ws-server/index.js +9 -11
  266. package/umd/synchronizers/synchronizer-ws-server/with-schemas/index.js +9 -11
  267. package/umd/synchronizers/synchronizer-ws-server-durable-object/index.js +113 -0
  268. package/umd/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +113 -0
  269. package/umd/synchronizers/synchronizer-ws-server-simple/index.js +11 -12
  270. package/umd/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +11 -12
  271. package/umd/ui-react-inspector/index.js +5 -5
  272. package/umd/ui-react-inspector/with-schemas/index.js +5 -5
  273. package/umd/with-schemas/index.js +5 -5
  274. package/with-schemas/index.js +5 -5
@@ -140,8 +140,8 @@
140
140
  );
141
141
  const createPayload = (toClientId, ...args) =>
142
142
  createRawPayload(toClientId ?? EMPTY_STRING, jsonStringWithUndefined(args));
143
- const createRawPayload = (toClientId, remainder) =>
144
- toClientId + MESSAGE_SEPARATOR + remainder;
143
+ const createRawPayload = (clientId, remainder) =>
144
+ clientId + MESSAGE_SEPARATOR + remainder;
145
145
 
146
146
  const newStamp = (value, time) => (time ? [value, time] : [value]);
147
147
  const getLatestTime = (time1, time2) =>
@@ -719,10 +719,8 @@
719
719
  if (clientId !== SERVER_CLIENT_ID) {
720
720
  serverClient[3 /* Send */]?.(forwardedPayload);
721
721
  }
722
- mapForEach(clients, (otherClientId, otherWebSocket) =>
723
- otherClientId !== clientId
724
- ? otherWebSocket.send(forwardedPayload)
725
- : 0,
722
+ mapForEach(clients, (otherClientId, otherClient) =>
723
+ otherClientId !== clientId ? otherClient.send(forwardedPayload) : 0,
726
724
  );
727
725
  } else if (toClientId === SERVER_CLIENT_ID) {
728
726
  serverClient[3 /* Send */]?.(forwardedPayload);
@@ -730,7 +728,7 @@
730
728
  mapGet(clients, toClientId)?.send(forwardedPayload);
731
729
  }
732
730
  });
733
- webSocketServer.on('connection', (webSocket, request) =>
731
+ webSocketServer.on('connection', (client, request) =>
734
732
  ifNotUndefined(strMatch(request.url, PATH_REGEX), ([, pathId]) =>
735
733
  ifNotUndefined(
736
734
  request.headers['sec-websocket-key'],
@@ -748,9 +746,9 @@
748
746
  callListeners(pathIdListeners, void 0, pathId, 1);
749
747
  await configureServerClient(serverClient, pathId, clients);
750
748
  }
751
- mapSet(clients, clientId, webSocket);
749
+ mapSet(clients, clientId, client);
752
750
  callListeners(clientIdListeners, [pathId], clientId, 1);
753
- webSocket.on('message', (data) => {
751
+ client.on('message', (data) => {
754
752
  const payload = data.toString(UTF8);
755
753
  if (serverClient[0 /* State */] == 0 /* Ready */) {
756
754
  messageHandler(payload);
@@ -763,7 +761,7 @@
763
761
  arrayForEach(serverClient[4 /* Buffer */], messageHandler);
764
762
  serverClient[4 /* Buffer */] = [];
765
763
  }
766
- webSocket.on('close', () => {
764
+ client.on('close', () => {
767
765
  collDel(clients, clientId);
768
766
  callListeners(clientIdListeners, [pathId], clientId, -1);
769
767
  if (collIsEmpty(clients)) {
@@ -779,7 +777,7 @@
779
777
  );
780
778
  const getWebSocketServer = () => webSocketServer;
781
779
  const getPathIds = () => mapKeys(clientsByPath);
782
- const getClientIds = (path) => mapKeys(mapGet(clientsByPath, path));
780
+ const getClientIds = (pathId) => mapKeys(mapGet(clientsByPath, pathId));
783
781
  const addPathIdsListener = (listener) =>
784
782
  addListener(listener, pathIdListeners);
785
783
  const addClientIdsListener = (pathId, listener) =>
@@ -140,8 +140,8 @@
140
140
  );
141
141
  const createPayload = (toClientId, ...args) =>
142
142
  createRawPayload(toClientId ?? EMPTY_STRING, jsonStringWithUndefined(args));
143
- const createRawPayload = (toClientId, remainder) =>
144
- toClientId + MESSAGE_SEPARATOR + remainder;
143
+ const createRawPayload = (clientId, remainder) =>
144
+ clientId + MESSAGE_SEPARATOR + remainder;
145
145
 
146
146
  const newStamp = (value, time) => (time ? [value, time] : [value]);
147
147
  const getLatestTime = (time1, time2) =>
@@ -719,10 +719,8 @@
719
719
  if (clientId !== SERVER_CLIENT_ID) {
720
720
  serverClient[3 /* Send */]?.(forwardedPayload);
721
721
  }
722
- mapForEach(clients, (otherClientId, otherWebSocket) =>
723
- otherClientId !== clientId
724
- ? otherWebSocket.send(forwardedPayload)
725
- : 0,
722
+ mapForEach(clients, (otherClientId, otherClient) =>
723
+ otherClientId !== clientId ? otherClient.send(forwardedPayload) : 0,
726
724
  );
727
725
  } else if (toClientId === SERVER_CLIENT_ID) {
728
726
  serverClient[3 /* Send */]?.(forwardedPayload);
@@ -730,7 +728,7 @@
730
728
  mapGet(clients, toClientId)?.send(forwardedPayload);
731
729
  }
732
730
  });
733
- webSocketServer.on('connection', (webSocket, request) =>
731
+ webSocketServer.on('connection', (client, request) =>
734
732
  ifNotUndefined(strMatch(request.url, PATH_REGEX), ([, pathId]) =>
735
733
  ifNotUndefined(
736
734
  request.headers['sec-websocket-key'],
@@ -748,9 +746,9 @@
748
746
  callListeners(pathIdListeners, void 0, pathId, 1);
749
747
  await configureServerClient(serverClient, pathId, clients);
750
748
  }
751
- mapSet(clients, clientId, webSocket);
749
+ mapSet(clients, clientId, client);
752
750
  callListeners(clientIdListeners, [pathId], clientId, 1);
753
- webSocket.on('message', (data) => {
751
+ client.on('message', (data) => {
754
752
  const payload = data.toString(UTF8);
755
753
  if (serverClient[0 /* State */] == 0 /* Ready */) {
756
754
  messageHandler(payload);
@@ -763,7 +761,7 @@
763
761
  arrayForEach(serverClient[4 /* Buffer */], messageHandler);
764
762
  serverClient[4 /* Buffer */] = [];
765
763
  }
766
- webSocket.on('close', () => {
764
+ client.on('close', () => {
767
765
  collDel(clients, clientId);
768
766
  callListeners(clientIdListeners, [pathId], clientId, -1);
769
767
  if (collIsEmpty(clients)) {
@@ -779,7 +777,7 @@
779
777
  );
780
778
  const getWebSocketServer = () => webSocketServer;
781
779
  const getPathIds = () => mapKeys(clientsByPath);
782
- const getClientIds = (path) => mapKeys(mapGet(clientsByPath, path));
780
+ const getClientIds = (pathId) => mapKeys(mapGet(clientsByPath, pathId));
783
781
  const addPathIdsListener = (listener) =>
784
782
  addListener(listener, pathIdListeners);
785
783
  const addClientIdsListener = (pathId, listener) =>
@@ -0,0 +1,113 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined'
3
+ ? factory(exports, require('cloudflare:workers'))
4
+ : typeof define === 'function' && define.amd
5
+ ? define(['exports', 'cloudflare:workers'], factory)
6
+ : ((global =
7
+ typeof globalThis !== 'undefined' ? globalThis : global || self),
8
+ factory(
9
+ (global.TinyBaseSynchronizerWsServerDurableObject = {}),
10
+ global.cloudflare_workers,
11
+ ));
12
+ })(this, function (exports, cloudflare_workers) {
13
+ 'use strict';
14
+
15
+ const EMPTY_STRING = '';
16
+ const strMatch = (str, regex) => str?.match(regex);
17
+
18
+ const isUndefined = (thing) => thing == void 0;
19
+ const ifNotUndefined = (value, then, otherwise) =>
20
+ isUndefined(value) ? otherwise?.() : then(value);
21
+ const slice = (arrayOrString, start, end) => arrayOrString.slice(start, end);
22
+ const size = (arrayOrString) => arrayOrString.length;
23
+
24
+ const arrayForEach = (array, cb) => array.forEach(cb);
25
+ const arrayMap = (array, cb) => array.map(cb);
26
+ const arrayIsEmpty = (array) => size(array) == 0;
27
+
28
+ const object = Object;
29
+ const objValues = (obj) => object.values(obj);
30
+
31
+ const MESSAGE_SEPARATOR = '\n';
32
+ const ifPayloadValid = (payload, then) => {
33
+ const splitAt = payload.indexOf(MESSAGE_SEPARATOR);
34
+ if (splitAt !== -1) {
35
+ then(slice(payload, 0, splitAt), slice(payload, splitAt + 1));
36
+ }
37
+ };
38
+ const createRawPayload = (clientId, remainder) =>
39
+ clientId + MESSAGE_SEPARATOR + remainder;
40
+
41
+ const PATH_REGEX = /\/([^?]*)/;
42
+ const getPathId = (request) =>
43
+ strMatch(new URL(request.url).pathname, PATH_REGEX)?.[1] ?? EMPTY_STRING;
44
+ const getClientId = (request) =>
45
+ request.headers.get('upgrade')?.toLowerCase() == 'websocket'
46
+ ? request.headers.get('sec-websocket-key')
47
+ : null;
48
+ const createResponse = (status, webSocket = null, body = null) =>
49
+ new Response(body, {status, webSocket});
50
+ const createUpgradeRequiredResponse = () =>
51
+ createResponse(426, null, 'Upgrade required');
52
+ class WsServerDurableObject extends cloudflare_workers.DurableObject {
53
+ constructor(ctx, env) {
54
+ super(ctx, env);
55
+ }
56
+ fetch(request) {
57
+ const pathId = getPathId(request);
58
+ return ifNotUndefined(
59
+ getClientId(request),
60
+ (clientId) => {
61
+ const [webSocket, client] = objValues(new WebSocketPair());
62
+ client.serializeAttachment({pathId});
63
+ if (arrayIsEmpty(this.ctx.getWebSockets())) {
64
+ this.onPathId(pathId, 1);
65
+ }
66
+ this.ctx.acceptWebSocket(client, [clientId]);
67
+ this.onClientId(pathId, clientId, 1);
68
+ return createResponse(101, webSocket);
69
+ },
70
+ createUpgradeRequiredResponse,
71
+ );
72
+ }
73
+ webSocketMessage(client, message) {
74
+ ifNotUndefined(this.ctx.getTags(client)[0], (clientId) =>
75
+ ifPayloadValid(message.toString(), (toClientId, remainder) => {
76
+ const forwardedPayload = createRawPayload(clientId, remainder);
77
+ if (toClientId === EMPTY_STRING) {
78
+ arrayForEach(this.ctx.getWebSockets(), (otherClient) =>
79
+ otherClient !== client ? otherClient.send(forwardedPayload) : 0,
80
+ );
81
+ } else {
82
+ this.ctx.getWebSockets(toClientId)[0]?.send(forwardedPayload);
83
+ }
84
+ }),
85
+ );
86
+ }
87
+ webSocketClose(client) {
88
+ const {pathId} = client.deserializeAttachment();
89
+ this.onClientId(pathId, this.ctx.getTags(client)[0], -1);
90
+ if (size(this.ctx.getWebSockets()) == 1) {
91
+ this.onPathId(pathId, -1);
92
+ }
93
+ }
94
+ // --
95
+ getClientIds(_pathId) {
96
+ return arrayMap(
97
+ this.ctx.getWebSockets(),
98
+ (client) => this.ctx.getTags(client)[0],
99
+ );
100
+ }
101
+ onPathId(_pathId, _addedOrRemoved) {}
102
+ onClientId(_pathId, _clientId, _addedOrRemoved) {}
103
+ }
104
+ const getWsServerDurableObjectFetch = (namespace) => (request, env) =>
105
+ getClientId(request)
106
+ ? env[namespace]
107
+ .get(env[namespace].idFromName(getPathId(request)))
108
+ .fetch(request)
109
+ : createUpgradeRequiredResponse();
110
+
111
+ exports.WsServerDurableObject = WsServerDurableObject;
112
+ exports.getWsServerDurableObjectFetch = getWsServerDurableObjectFetch;
113
+ });
@@ -0,0 +1,113 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined'
3
+ ? factory(exports, require('cloudflare:workers'))
4
+ : typeof define === 'function' && define.amd
5
+ ? define(['exports', 'cloudflare:workers'], factory)
6
+ : ((global =
7
+ typeof globalThis !== 'undefined' ? globalThis : global || self),
8
+ factory(
9
+ (global.TinyBaseSynchronizerWsServerDurableObject = {}),
10
+ global.cloudflare_workers,
11
+ ));
12
+ })(this, function (exports, cloudflare_workers) {
13
+ 'use strict';
14
+
15
+ const EMPTY_STRING = '';
16
+ const strMatch = (str, regex) => str?.match(regex);
17
+
18
+ const isUndefined = (thing) => thing == void 0;
19
+ const ifNotUndefined = (value, then, otherwise) =>
20
+ isUndefined(value) ? otherwise?.() : then(value);
21
+ const slice = (arrayOrString, start, end) => arrayOrString.slice(start, end);
22
+ const size = (arrayOrString) => arrayOrString.length;
23
+
24
+ const arrayForEach = (array, cb) => array.forEach(cb);
25
+ const arrayMap = (array, cb) => array.map(cb);
26
+ const arrayIsEmpty = (array) => size(array) == 0;
27
+
28
+ const object = Object;
29
+ const objValues = (obj) => object.values(obj);
30
+
31
+ const MESSAGE_SEPARATOR = '\n';
32
+ const ifPayloadValid = (payload, then) => {
33
+ const splitAt = payload.indexOf(MESSAGE_SEPARATOR);
34
+ if (splitAt !== -1) {
35
+ then(slice(payload, 0, splitAt), slice(payload, splitAt + 1));
36
+ }
37
+ };
38
+ const createRawPayload = (clientId, remainder) =>
39
+ clientId + MESSAGE_SEPARATOR + remainder;
40
+
41
+ const PATH_REGEX = /\/([^?]*)/;
42
+ const getPathId = (request) =>
43
+ strMatch(new URL(request.url).pathname, PATH_REGEX)?.[1] ?? EMPTY_STRING;
44
+ const getClientId = (request) =>
45
+ request.headers.get('upgrade')?.toLowerCase() == 'websocket'
46
+ ? request.headers.get('sec-websocket-key')
47
+ : null;
48
+ const createResponse = (status, webSocket = null, body = null) =>
49
+ new Response(body, {status, webSocket});
50
+ const createUpgradeRequiredResponse = () =>
51
+ createResponse(426, null, 'Upgrade required');
52
+ class WsServerDurableObject extends cloudflare_workers.DurableObject {
53
+ constructor(ctx, env) {
54
+ super(ctx, env);
55
+ }
56
+ fetch(request) {
57
+ const pathId = getPathId(request);
58
+ return ifNotUndefined(
59
+ getClientId(request),
60
+ (clientId) => {
61
+ const [webSocket, client] = objValues(new WebSocketPair());
62
+ client.serializeAttachment({pathId});
63
+ if (arrayIsEmpty(this.ctx.getWebSockets())) {
64
+ this.onPathId(pathId, 1);
65
+ }
66
+ this.ctx.acceptWebSocket(client, [clientId]);
67
+ this.onClientId(pathId, clientId, 1);
68
+ return createResponse(101, webSocket);
69
+ },
70
+ createUpgradeRequiredResponse,
71
+ );
72
+ }
73
+ webSocketMessage(client, message) {
74
+ ifNotUndefined(this.ctx.getTags(client)[0], (clientId) =>
75
+ ifPayloadValid(message.toString(), (toClientId, remainder) => {
76
+ const forwardedPayload = createRawPayload(clientId, remainder);
77
+ if (toClientId === EMPTY_STRING) {
78
+ arrayForEach(this.ctx.getWebSockets(), (otherClient) =>
79
+ otherClient !== client ? otherClient.send(forwardedPayload) : 0,
80
+ );
81
+ } else {
82
+ this.ctx.getWebSockets(toClientId)[0]?.send(forwardedPayload);
83
+ }
84
+ }),
85
+ );
86
+ }
87
+ webSocketClose(client) {
88
+ const {pathId} = client.deserializeAttachment();
89
+ this.onClientId(pathId, this.ctx.getTags(client)[0], -1);
90
+ if (size(this.ctx.getWebSockets()) == 1) {
91
+ this.onPathId(pathId, -1);
92
+ }
93
+ }
94
+ // --
95
+ getClientIds(_pathId) {
96
+ return arrayMap(
97
+ this.ctx.getWebSockets(),
98
+ (client) => this.ctx.getTags(client)[0],
99
+ );
100
+ }
101
+ onPathId(_pathId, _addedOrRemoved) {}
102
+ onClientId(_pathId, _clientId, _addedOrRemoved) {}
103
+ }
104
+ const getWsServerDurableObjectFetch = (namespace) => (request, env) =>
105
+ getClientId(request)
106
+ ? env[namespace]
107
+ .get(env[namespace].idFromName(getPathId(request)))
108
+ .fetch(request)
109
+ : createUpgradeRequiredResponse();
110
+
111
+ exports.WsServerDurableObject = WsServerDurableObject;
112
+ exports.getWsServerDurableObjectFetch = getWsServerDurableObjectFetch;
113
+ });
@@ -48,35 +48,34 @@
48
48
  then(slice(payload, 0, splitAt), slice(payload, splitAt + 1));
49
49
  }
50
50
  };
51
- const createRawPayload = (toClientId, remainder) =>
52
- toClientId + MESSAGE_SEPARATOR + remainder;
51
+ const createRawPayload = (clientId, remainder) =>
52
+ clientId + MESSAGE_SEPARATOR + remainder;
53
53
 
54
54
  const PATH_REGEX = /\/([^?]*)/;
55
55
  const createWsServerSimple = (webSocketServer) => {
56
56
  const clientsByPath = mapNew();
57
- webSocketServer.on('connection', (webSocket, request) =>
57
+ webSocketServer.on('connection', (client, request) =>
58
58
  ifNotUndefined(strMatch(request.url, PATH_REGEX), ([, pathId]) =>
59
59
  ifNotUndefined(
60
60
  request.headers['sec-websocket-key'],
61
61
  async (clientId) => {
62
62
  const clients = mapEnsure(clientsByPath, pathId, mapNew);
63
- mapSet(clients, clientId, webSocket);
64
- webSocket.on('message', (data) => {
65
- const payload = data.toString(UTF8);
66
- ifPayloadValid(payload, (toClientId, remainder) => {
63
+ mapSet(clients, clientId, client);
64
+ client.on('message', (data) =>
65
+ ifPayloadValid(data.toString(UTF8), (toClientId, remainder) => {
67
66
  const forwardedPayload = createRawPayload(clientId, remainder);
68
67
  if (toClientId === EMPTY_STRING) {
69
- mapForEach(clients, (otherClientId, otherWebSocket) =>
68
+ mapForEach(clients, (otherClientId, otherClient) =>
70
69
  otherClientId !== clientId
71
- ? otherWebSocket.send(forwardedPayload)
70
+ ? otherClient.send(forwardedPayload)
72
71
  : 0,
73
72
  );
74
73
  } else {
75
74
  mapGet(clients, toClientId)?.send(forwardedPayload);
76
75
  }
77
- });
78
- });
79
- webSocket.on('close', () => {
76
+ }),
77
+ );
78
+ client.on('close', () => {
80
79
  collDel(clients, clientId);
81
80
  if (collIsEmpty(clients)) {
82
81
  collDel(clientsByPath, pathId);
@@ -48,35 +48,34 @@
48
48
  then(slice(payload, 0, splitAt), slice(payload, splitAt + 1));
49
49
  }
50
50
  };
51
- const createRawPayload = (toClientId, remainder) =>
52
- toClientId + MESSAGE_SEPARATOR + remainder;
51
+ const createRawPayload = (clientId, remainder) =>
52
+ clientId + MESSAGE_SEPARATOR + remainder;
53
53
 
54
54
  const PATH_REGEX = /\/([^?]*)/;
55
55
  const createWsServerSimple = (webSocketServer) => {
56
56
  const clientsByPath = mapNew();
57
- webSocketServer.on('connection', (webSocket, request) =>
57
+ webSocketServer.on('connection', (client, request) =>
58
58
  ifNotUndefined(strMatch(request.url, PATH_REGEX), ([, pathId]) =>
59
59
  ifNotUndefined(
60
60
  request.headers['sec-websocket-key'],
61
61
  async (clientId) => {
62
62
  const clients = mapEnsure(clientsByPath, pathId, mapNew);
63
- mapSet(clients, clientId, webSocket);
64
- webSocket.on('message', (data) => {
65
- const payload = data.toString(UTF8);
66
- ifPayloadValid(payload, (toClientId, remainder) => {
63
+ mapSet(clients, clientId, client);
64
+ client.on('message', (data) =>
65
+ ifPayloadValid(data.toString(UTF8), (toClientId, remainder) => {
67
66
  const forwardedPayload = createRawPayload(clientId, remainder);
68
67
  if (toClientId === EMPTY_STRING) {
69
- mapForEach(clients, (otherClientId, otherWebSocket) =>
68
+ mapForEach(clients, (otherClientId, otherClient) =>
70
69
  otherClientId !== clientId
71
- ? otherWebSocket.send(forwardedPayload)
70
+ ? otherClient.send(forwardedPayload)
72
71
  : 0,
73
72
  );
74
73
  } else {
75
74
  mapGet(clients, toClientId)?.send(forwardedPayload);
76
75
  }
77
- });
78
- });
79
- webSocket.on('close', () => {
76
+ }),
77
+ );
78
+ client.on('close', () => {
80
79
  collDel(clients, clientId);
81
80
  if (collIsEmpty(clients)) {
82
81
  collDel(clientsByPath, pathId);
@@ -2301,11 +2301,11 @@
2301
2301
  };
2302
2302
  const getNewRowId = (tableId, reuse) => {
2303
2303
  const [getId] = mapGet(tablePoolFunctions, tableId);
2304
- const rowId = getId(reuse);
2305
- if (!collHas(mapGet(tablesMap, tableId), rowId)) {
2306
- return rowId;
2307
- }
2308
- return getNewRowId(tableId, reuse);
2304
+ let rowId;
2305
+ do {
2306
+ rowId = getId(reuse);
2307
+ } while (collHas(mapGet(tablesMap, tableId), rowId));
2308
+ return rowId;
2309
2309
  };
2310
2310
  const getOrCreateTable = (tableId) =>
2311
2311
  mapGet(tablesMap, tableId) ?? setValidTable(tableId, {});
@@ -2301,11 +2301,11 @@
2301
2301
  };
2302
2302
  const getNewRowId = (tableId, reuse) => {
2303
2303
  const [getId] = mapGet(tablePoolFunctions, tableId);
2304
- const rowId = getId(reuse);
2305
- if (!collHas(mapGet(tablesMap, tableId), rowId)) {
2306
- return rowId;
2307
- }
2308
- return getNewRowId(tableId, reuse);
2304
+ let rowId;
2305
+ do {
2306
+ rowId = getId(reuse);
2307
+ } while (collHas(mapGet(tablesMap, tableId), rowId));
2308
+ return rowId;
2309
2309
  };
2310
2310
  const getOrCreateTable = (tableId) =>
2311
2311
  mapGet(tablesMap, tableId) ?? setValidTable(tableId, {});
@@ -2207,11 +2207,11 @@
2207
2207
  };
2208
2208
  const getNewRowId = (tableId, reuse) => {
2209
2209
  const [getId] = mapGet(tablePoolFunctions, tableId);
2210
- const rowId = getId(reuse);
2211
- if (!collHas(mapGet(tablesMap, tableId), rowId)) {
2212
- return rowId;
2213
- }
2214
- return getNewRowId(tableId, reuse);
2210
+ let rowId;
2211
+ do {
2212
+ rowId = getId(reuse);
2213
+ } while (collHas(mapGet(tablesMap, tableId), rowId));
2214
+ return rowId;
2215
2215
  };
2216
2216
  const getOrCreateTable = (tableId) =>
2217
2217
  mapGet(tablesMap, tableId) ?? setValidTable(tableId, {});
@@ -2155,11 +2155,11 @@ const createStore = () => {
2155
2155
  };
2156
2156
  const getNewRowId = (tableId, reuse) => {
2157
2157
  const [getId] = mapGet(tablePoolFunctions, tableId);
2158
- const rowId = getId(reuse);
2159
- if (!collHas(mapGet(tablesMap, tableId), rowId)) {
2160
- return rowId;
2161
- }
2162
- return getNewRowId(tableId, reuse);
2158
+ let rowId;
2159
+ do {
2160
+ rowId = getId(reuse);
2161
+ } while (collHas(mapGet(tablesMap, tableId), rowId));
2162
+ return rowId;
2163
2163
  };
2164
2164
  const getOrCreateTable = (tableId) =>
2165
2165
  mapGet(tablesMap, tableId) ?? setValidTable(tableId, {});